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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
a160e08b22d4041f49aecbd6ced76f02cf860dda
| 17,297
|
agda
|
Agda
|
src/GenericElim/Desc.agda
|
larrytheliquid/generic-elim
|
832383d7adf37aa2364213fb0aeb67e9f61a248f
|
[
"MIT"
] | 11
|
2015-06-02T14:05:20.000Z
|
2021-09-09T08:46:42.000Z
|
src/GenericElim/Desc.agda
|
larrytheliquid/generic-elim
|
832383d7adf37aa2364213fb0aeb67e9f61a248f
|
[
"MIT"
] | null | null | null |
src/GenericElim/Desc.agda
|
larrytheliquid/generic-elim
|
832383d7adf37aa2364213fb0aeb67e9f61a248f
|
[
"MIT"
] | 2
|
2016-05-02T08:56:15.000Z
|
2022-03-12T11:31:22.000Z
|
{-# OPTIONS --type-in-type #-}
open import Data.Unit
open import Data.Product hiding ( curry ; uncurry )
open import Data.List hiding ( concat )
open import Data.String
open import Relation.Binary.PropositionalEquality
open import Function
module GenericElim.Desc where
----------------------------------------------------------------------
Label : Set
Label = String
Enum : Set
Enum = List Label
data Tag : Enum → Set where
here : ∀{l E} → Tag (l ∷ E)
there : ∀{l E} → Tag E → Tag (l ∷ E)
Branches : (E : Enum) (P : Tag E → Set) → Set
Branches [] P = ⊤
Branches (l ∷ E) P = P here × Branches E (λ t → P (there t))
case : {E : Enum} (P : Tag E → Set) (cs : Branches E P) (t : Tag E) → P t
case P (c , cs) here = c
case P (c , cs) (there t) = case (λ t → P (there t)) cs t
UncurriedBranches : (E : Enum) (P : Tag E → Set) (X : Set)
→ Set
UncurriedBranches E P X = Branches E P → X
CurriedBranches : (E : Enum) (P : Tag E → Set) (X : Set)
→ Set
CurriedBranches [] P X = X
CurriedBranches (l ∷ E) P X = P here → CurriedBranches E (λ t → P (there t)) X
curryBranches : {E : Enum} {P : Tag E → Set} {X : Set}
→ UncurriedBranches E P X → CurriedBranches E P X
curryBranches {[]} f = f tt
curryBranches {l ∷ E} f = λ c → curryBranches (λ cs → f (c , cs))
uncurryBranches : {E : Enum} {P : Tag E → Set} {X : Set}
→ CurriedBranches E P X → UncurriedBranches E P X
uncurryBranches {[]} x tt = x
uncurryBranches {l ∷ E} f (c , cs) = uncurryBranches (f c) cs
----------------------------------------------------------------------
data Desc (I : Set) : Set₁ where
End : (i : I) → Desc I
Rec : (i : I) (D : Desc I) → Desc I
Arg : (A : Set) (B : A → Desc I) → Desc I
ISet : Set → Set₁
ISet I = I → Set
El : {I : Set} (D : Desc I) → ISet I → ISet I
El (End j) X i = j ≡ i
El (Rec j D) X i = X j × El D X i
El (Arg A B) X i = Σ A (λ a → El (B a) X i)
Hyps : {I : Set} (D : Desc I) (X : ISet I) (P : (i : I) → X i → Set) (i : I) (xs : El D X i) → Set
Hyps (End j) X P i q = ⊤
Hyps (Rec j D) X P i (x , xs) = P j x × Hyps D X P i xs
Hyps (Arg A B) X P i (a , b) = Hyps (B a) X P i b
----------------------------------------------------------------------
BranchesD : (I : Set) (E : Enum) → Set
BranchesD I E = Branches E (λ _ → Desc I)
caseD : {I : Set} {E : Enum} (cs : BranchesD I E) (t : Tag E) → Desc I
caseD = case (λ _ → Desc _)
----------------------------------------------------------------------
UncurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set
UncurriedEl D X = ∀{i} → El D X i → X i
CurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set
CurriedEl (End i) X = X i
CurriedEl (Rec i D) X = (x : X i) → CurriedEl D X
CurriedEl (Arg A B) X = (a : A) → CurriedEl (B a) X
CurriedEl' : {I : Set} (D : Desc I) (X : ISet I) (i : I) → Set
CurriedEl' (End j) X i = j ≡ i → X i
CurriedEl' (Rec j D) X i = (x : X j) → CurriedEl' D X i
CurriedEl' (Arg A B) X i = (a : A) → CurriedEl' (B a) X i
curryEl : {I : Set} (D : Desc I) (X : ISet I)
→ UncurriedEl D X → CurriedEl D X
curryEl (End i) X cn = cn refl
curryEl (Rec i D) X cn = λ x → curryEl D X (λ xs → cn (x , xs))
curryEl (Arg A B) X cn = λ a → curryEl (B a) X (λ xs → cn (a , xs))
uncurryEl : {I : Set} (D : Desc I) (X : ISet I)
→ CurriedEl D X → UncurriedEl D X
uncurryEl (End i) X cn refl = cn
uncurryEl (Rec i D) X cn (x , xs) = uncurryEl D X (cn x) xs
uncurryEl (Arg A B) X cn (a , xs) = uncurryEl (B a) X (cn a) xs
----------------------------------------------------------------------
UncurriedHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ Set
UncurriedHyps D X P cn =
∀ i (xs : El D X i) (ihs : Hyps D X P i xs) → P i (cn xs)
CurriedHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ Set
CurriedHyps (End i) X P cn =
P i (cn refl)
CurriedHyps (Rec i D) X P cn =
(x : X i) → P i x → CurriedHyps D X P (λ xs → cn (x , xs))
CurriedHyps (Arg A B) X P cn =
(a : A) → CurriedHyps (B a) X P (λ xs → cn (a , xs))
CurriedHyps' : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(i : I)
(cn : El D X i → X i)
→ Set
CurriedHyps' (End j) X P i cn = (q : j ≡ i) → P i (cn q)
CurriedHyps' (Rec j D) X P i cn =
(x : X j) → P j x → CurriedHyps' D X P i (λ xs → cn (x , xs))
CurriedHyps' (Arg A B) X P i cn =
(a : A) → CurriedHyps' (B a) X P i (λ xs → cn (a , xs))
curryHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ UncurriedHyps D X P cn
→ CurriedHyps D X P cn
curryHyps (End i) X P cn pf =
pf i refl tt
curryHyps (Rec i D) X P cn pf =
λ x ih → curryHyps D X P (λ xs → cn (x , xs)) (λ i xs ihs → pf i (x , xs) (ih , ihs))
curryHyps (Arg A B) X P cn pf =
λ a → curryHyps (B a) X P (λ xs → cn (a , xs)) (λ i xs ihs → pf i (a , xs) ihs)
uncurryHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ CurriedHyps D X P cn
→ UncurriedHyps D X P cn
uncurryHyps (End .i) X P cn pf i refl tt =
pf
uncurryHyps (Rec j D) X P cn pf i (x , xs) (ih , ihs) =
uncurryHyps D X P (λ ys → cn (x , ys)) (pf x ih) i xs ihs
uncurryHyps (Arg A B) X P cn pf i (a , xs) ihs =
uncurryHyps (B a) X P (λ ys → cn (a , ys)) (pf a) i xs ihs
----------------------------------------------------------------------
data μ {I : Set} (D : Desc I) : ISet I where
init : UncurriedEl D (μ D)
inj : {I : Set} (D : Desc I) → CurriedEl D (μ D)
inj D = curryEl D (μ D) init
----------------------------------------------------------------------
ind :
{I : Set}
(D : Desc I)
(P : (i : I) → μ D i → Set)
(α : UncurriedHyps D (μ D) P init)
(i : I)
(x : μ D i)
→ P i x
hyps :
{I : Set}
(D₁ : Desc I)
(P : (i : I) → μ D₁ i → Set)
(α : UncurriedHyps D₁ (μ D₁) P init)
(D₂ : Desc I)
(i : I)
(xs : El D₂ (μ D₁) i)
→ Hyps D₂ (μ D₁) P i xs
ind D P α i (init xs) = α i xs (hyps D P α D i xs)
hyps D P α (End j) i q = tt
hyps D P α (Rec j A) i (x , xs) = ind D P α j x , hyps D P α A i xs
hyps D P α (Arg A B) i (a , b) = hyps D P α (B a) i b
----------------------------------------------------------------------
indCurried : {I : Set} (D : Desc I)
(P : (i : I) → μ D i → Set)
(f : CurriedHyps D (μ D) P init)
(i : I)
(x : μ D i)
→ P i x
indCurried D P f i x = ind D P (uncurryHyps D (μ D) P init f) i x
Summer : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(X : ISet I) (cn : UncurriedEl D X)
(P : (i : I) → X i → Set)
→ Tag E → Set
Summer E C X cn P t =
let D = Arg (Tag E) C in
CurriedHyps (C t) X P (λ xs → cn (t , xs))
SumCurriedHyps : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
→ Tag E → Set
SumCurriedHyps E C P t =
let D = Arg (Tag E) C in
Summer E C (μ D) init P t
elimUncurried : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
→ Branches E (SumCurriedHyps E C P)
→ (i : I) (x : μ D i) → P i x
elimUncurried E C P cs i x =
let D = Arg (Tag E) C in
indCurried D P
(case (SumCurriedHyps E C P) cs)
i x
elim : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
→ CurriedBranches E
(SumCurriedHyps E C P)
((i : I) (x : μ D i) → P i x)
elim E C P = curryBranches (elimUncurried E C P)
----------------------------------------------------------------------
Soundness : Set₁
Soundness = {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
(cs : Branches E (SumCurriedHyps E C P))
(i : I) (x : μ D i)
→ ∃ λ α
→ elimUncurried E C P cs i x ≡ ind D P α i x
sound : Soundness
sound E C P cs i x =
let D = Arg (Tag E) C in
(uncurryHyps D (μ D) P init (case (SumCurriedHyps E C P) cs)) , refl
Completeness : Set₁
Completeness = {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
(α : UncurriedHyps D (μ D) P init)
(i : I) (x : μ D i)
→ ∃ λ cs
→ ind D P α i x ≡ elimUncurried E C P cs i x
uncurryHypsIdent : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
(α : UncurriedHyps D X P cn)
(i : I) (xs : El D X i) (ihs : Hyps D X P i xs)
→ α i xs ihs ≡ uncurryHyps D X P cn (curryHyps D X P cn α) i xs ihs
uncurryHypsIdent (End .i) X P cn α i refl tt = refl
uncurryHypsIdent (Rec j D) X P cn α i (x , xs) (p , ps) =
uncurryHypsIdent D X P (λ xs → cn (x , xs)) (λ k ys rs → α k (x , ys) (p , rs)) i xs ps
uncurryHypsIdent (Arg A B) X P cn α i (a , xs) ps =
uncurryHypsIdent (B a) X P (λ xs → cn (a , xs)) (λ j ys → α j (a , ys)) i xs ps
postulate
ext3 : {A : Set} {B : A → Set} {C : (a : A) → B a → Set} {Z : (a : A) (b : B a) → C a b → Set}
(f g : (a : A) (b : B a) (c : C a b) → Z a b c)
→ ((a : A) (b : B a) (c : C a b) → f a b c ≡ g a b c)
→ f ≡ g
toBranches : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(X : ISet I) (cn : UncurriedEl D X)
(P : (i : I) → X i → Set)
(α : UncurriedHyps D X P cn)
→ Branches E (Summer E C X cn P)
toBranches [] C X cn P α = tt
toBranches (l ∷ E) C X cn P α =
curryHyps (C here) X P (λ xs → cn (here , xs)) (λ i xs → α i (here , xs))
, toBranches E (λ t → C (there t)) X
(λ xs → cn (there (proj₁ xs) , proj₂ xs))
P (λ i xs ih → α i (there (proj₁ xs) , proj₂ xs) ih)
ToBranches : {I : Set} {E : Enum} (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(X : ISet I) (cn : UncurriedEl D X)
(P : (i : I) → X i → Set)
(α : UncurriedHyps D X P cn)
(t : Tag E)
→ let β = toBranches E C X cn P α in
case (Summer E C X cn P) β t ≡ curryHyps D X P cn α t
ToBranches C X cn P α here = refl
ToBranches C X cn P α (there t)
with ToBranches (λ t → C (there t)) X
(λ xs → cn (there (proj₁ xs) , proj₂ xs))
P (λ i xs ih → α i (there (proj₁ xs) , proj₂ xs) ih) t
... | ih rewrite ih = refl
completeα : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
(α : UncurriedHyps D (μ D) P init)
(i : I) (xs : El D (μ D) i) (ihs : Hyps D (μ D) P i xs)
→ let β = toBranches E C (μ D) init P α in
α i xs ihs ≡ uncurryHyps D (μ D) P init (case (SumCurriedHyps E C P) β) i xs ihs
completeα E C P α i (t , xs) ihs
with ToBranches C (μ D) init P α t where D = Arg (Tag E) C
... | q rewrite q = uncurryHypsIdent D (μ D) P init α i (t , xs) ihs where D = Arg (Tag E) C
complete' : {I : Set} (E : Enum) (C : Tag E → Desc I)
→ let D = Arg (Tag E) C in
(P : (i : I) → μ D i → Set)
(α : UncurriedHyps D (μ D) P init)
(i : I) (x : μ D i)
→ let β = toBranches E C (μ D) init P α in
ind D P α i x ≡ elimUncurried E C P β i x
complete' E C P α i (init (t , xs)) = cong
(λ f → ind D P f i (init (t , xs)))
(ext3 α
(uncurryHyps D (μ D) P init (case (SumCurriedHyps E C P) β))
(completeα E C P α))
where
D = Arg (Tag E) C
β = toBranches E C (μ D) init P α
complete : Completeness
complete E C P α i x =
let D = Arg (Tag E) C in
toBranches E C (μ D) init P α
, complete' E C P α i x
----------------------------------------------------------------------
ℕE : Enum
ℕE = "zero" ∷ "suc" ∷ []
VecE : Enum
VecE = "nil" ∷ "cons" ∷ []
ℕT : Set
ℕT = Tag ℕE
VecT : Set
VecT = Tag VecE
zeroT : ℕT
zeroT = here
sucT : ℕT
sucT = there here
nilT : VecT
nilT = here
consT : VecT
consT = there here
ℕC : ℕT → Desc ⊤
ℕC = caseD $
End tt
, Rec tt (End tt)
, tt
ℕD : Desc ⊤
ℕD = Arg ℕT ℕC
ℕ : ⊤ → Set
ℕ = μ ℕD
zero : ℕ tt
zero = init (zeroT , refl)
suc : ℕ tt → ℕ tt
suc n = init (sucT , n , refl)
VecC : (A : Set) → VecT → Desc (ℕ tt)
VecC A = caseD $
End zero
, Arg (ℕ tt) (λ n → Arg A λ _ → Rec n (End (suc n)))
, tt
nilD : (A : Set) → Desc (ℕ tt)
nilD A = End zero
consD : (A : Set) → Desc (ℕ tt)
consD A = Arg (ℕ tt) (λ n → Arg A (λ _ → Rec n (End (suc n))))
VecD : (A : Set) → Desc (ℕ tt)
VecD A = Arg VecT (VecC A)
Vec : (A : Set) → ℕ tt → Set
Vec A = μ (VecD A)
NilEl : (A : Set) (n : ℕ tt) → Set
NilEl A n = El (nilD A) (Vec A) n
ConsEl : (A : Set) → ℕ tt → Set
ConsEl A n = El (consD A) (Vec A) n
VecEl : (A : Set) → ℕ tt → Set
VecEl A n = El (VecD A) (Vec A) n
NilHyps : (A : Set) (P : (n : ℕ tt) → Vec A n → Set) (n : ℕ tt) (xs : NilEl A n) → Set
NilHyps A P n xs = Hyps (nilD A) (Vec A) P n xs
ConsHyps : (A : Set) (P : (n : ℕ tt) → Vec A n → Set) (n : ℕ tt) (xs : ConsEl A n) → Set
ConsHyps A P n xs = Hyps (consD A) (Vec A) P n xs
VecHyps : (A : Set) (P : (n : ℕ tt) → Vec A n → Set) (n : ℕ tt) (xs : VecEl A n) → Set
VecHyps A P n xs = Hyps (VecD A) (Vec A) P n xs
ConsUncurriedHyps : (A : Set)
(P : (n : ℕ tt) → Vec A n → Set)
(cn : UncurriedEl (consD A) (Vec A)) → Set
ConsUncurriedHyps A P cn = UncurriedHyps (consD A) (Vec A) P cn
nil : (A : Set) → Vec A zero
nil A = init (nilT , refl)
cons : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons A n x xs = init (consT , n , x , xs , refl)
nil2 : (A : Set) → Vec A zero
nil2 A = inj (VecD A) nilT
cons2 : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons2 A = inj (VecD A) consT
----------------------------------------------------------------------
module Induction where
add : ℕ tt → ℕ tt → ℕ tt
add = ind ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ u t,c → case
(λ t → (c : El (ℕC t) ℕ u)
(ih : Hyps ℕD ℕ (λ u n → ℕ u → ℕ u) u (t , c))
→ ℕ u → ℕ u
)
( (λ q ih n → n)
, (λ m,q ih,tt n → suc (proj₁ ih,tt n))
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
tt
mult : ℕ tt → ℕ tt → ℕ tt
mult = ind ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ u t,c → case
(λ t → (c : El (ℕC t) ℕ u)
(ih : Hyps ℕD ℕ (λ u n → ℕ u → ℕ u) u (t , c))
→ ℕ u → ℕ u
)
( (λ q ih n → zero)
, (λ m,q ih,tt n → add n (proj₁ ih,tt n))
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
tt
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = ind (VecD A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ m t,c → case
(λ t → (c : El (VecC A t) (Vec A) m)
(ih : Hyps (VecD A) (Vec A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)) m (t , c))
(n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
)
( (λ q ih n ys → subst (λ m → Vec A (add m n)) q ys)
, (λ m',x,xs,q ih,tt n ys →
let m' = proj₁ m',x,xs,q
x = proj₁ (proj₂ m',x,xs,q)
q = proj₂ (proj₂ (proj₂ m',x,xs,q))
ih = proj₁ ih,tt
in
subst (λ m → Vec A (add m n)) q (cons A (add m' n) x (ih n ys))
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
Concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Set
Concat A m n xss = Vec A (mult n m)
ConsBranch : (A : Set) (m : ℕ tt)
→ Set
ConsBranch A m = UncurriedHyps (consD (Vec A m)) (Vec (Vec A m)) (Concat A m)
(λ xs → init (consT , xs))
ConsElimBranch : (A : Set) (m : ℕ tt)
→ Set
ConsElimBranch A m = CurriedHyps (consD (Vec A m)) (Vec (Vec A m)) (Concat A m)
(λ xs → init (consT , xs))
ElimBranch : (t : VecT) (A : Set) (m : ℕ tt)
→ Set
ElimBranch t A m = SumCurriedHyps VecE (VecC (Vec A m)) (Concat A m) t
nilBranch : (A : Set) (m n : ℕ tt)
(xss : NilEl (Vec A m) n)
(ihs : NilHyps (Vec A m) (Concat A m) n xss)
→ Vec A (mult n m)
nilBranch A m n q u = subst
(λ n → Vec A (mult n m))
q (nil A)
consBranch : (A : Set) (m : ℕ tt) → ConsBranch A m
consBranch A m n n',xs,xss,q ih,u =
let n' = proj₁ n',xs,xss,q
xs = proj₁ (proj₂ n',xs,xss,q)
q = proj₂ (proj₂ (proj₂ n',xs,xss,q))
ih = proj₁ ih,u
in subst
(λ n → Vec A (mult n m))
q (append A m xs (mult n' m) ih)
ConcatConvoy : (A : Set) (m n : ℕ tt) (t : VecT) → Set
ConcatConvoy A m n t =
(xss : El (VecC (Vec A m) t) (Vec (Vec A m)) n)
(ihs : VecHyps (Vec A m) (Concat A m) n (t , xss))
→ Vec A (mult n m)
concatα : (A : Set) (m n : ℕ tt)
(xss : VecEl (Vec A m) n)
(ihs : VecHyps (Vec A m) (Concat A m) n xss)
→ Vec A (mult n m)
concatα A m n xss = case (ConcatConvoy A m n)
(nilBranch A m n , consBranch A m n , tt)
(proj₁ xss)
(proj₂ xss)
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Concat A m n xss
concat A m = ind
(VecD (Vec A m))
(Concat A m)
(concatα A m)
----------------------------------------------------------------------
module GenericElim where
add : ℕ tt → ℕ tt → ℕ tt
add = elim ℕE ℕC _
(λ n → n)
(λ m ih n → suc (ih n))
tt
mult : ℕ tt → ℕ tt → ℕ tt
mult = elim ℕE ℕC _
(λ n → zero)
(λ m ih n → add n (ih n))
tt
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = elim VecE (VecC A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ n ys → ys)
(λ m x xs ih n ys → cons A (add m n) x (ih n ys))
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = elim VecE (VecC (Vec A m)) (λ n xss → Vec A (mult n m))
(nil A)
(λ n xs xss ih → append A m xs (mult n m) ih)
----------------------------------------------------------------------
| 29.719931
| 106
| 0.485576
|
299da8dcde60772bc2d13a6465631fa15279f1e3
| 402
|
agda
|
Agda
|
test/Succeed/ForcingRelevance.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/ForcingRelevance.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/ForcingRelevance.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
data Ix : Set where
ix : .(i : Nat) (n : Nat) → Ix
data D : Ix → Set where
mkD : ∀ n → D (ix n n)
data ΣD : Set where
_,_ : ∀ i → D i → ΣD
foo : ΣD → Nat
foo (i , mkD n) = n
d : ΣD
d = ix 0 6 , mkD 6
-- Check that we pick the right (the non-irrelevant) `n` when binding
-- the forced argument.
check : foo d ≡ 6
check = refl
| 16.75
| 69
| 0.597015
|
0b944ed04c922615fe8dd3aac8174b9727919fb5
| 2,684
|
agda
|
Agda
|
src/fot/FOTC/Data/Nat/Induction/Acc/WF-ATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Data/Nat/Induction/Acc/WF-ATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Data/Nat/Induction/Acc/WF-ATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Well-founded induction on the natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- N.B This module does not contain combined proofs, but it imports
-- modules which contain combined proofs.
module FOTC.Data.Nat.Induction.Acc.WF-ATP where
open import FOTC.Base
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesATP
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.Type
open import FOTC.Induction.WF
------------------------------------------------------------------------------
-- The relation _<_ is well-founded.
module <-WF where
<-wf : WellFounded _<_
<-wf Nn = acc (helper Nn)
where
-- N.B. The helper function is the same that the function used by
-- FOTC.Data.Nat.Induction.NonAcc.WellFoundedInductionATP.
helper : ∀ {n m} → N n → N m → m < n → Acc N _<_ m
helper nzero Nm m<0 = ⊥-elim (x<0→⊥ Nm m<0)
helper (nsucc _) nzero 0<Sn = acc (λ Nm' m'<0 → ⊥-elim (x<0→⊥ Nm' m'<0))
helper (nsucc {n} Nn) (nsucc {m} Nm) Sm<Sn =
acc (λ {m'} Nm' m'<Sm →
let m<n : m < n
m<n = Sx<Sy→x<y Sm<Sn
m'<n : m' < n
m'<n = case (λ m'<m → <-trans Nm' Nm Nn m'<m m<n)
(λ m'≡m → x≡y→y<z→x<z m'≡m m<n)
(x<Sy→x<y∨x≡y Nm' Nm m'<Sm)
in helper Nn Nm' m'<n
)
-- Well-founded induction on the natural numbers.
<-wfind : (A : D → Set) →
(∀ {n} → N n → (∀ {m} → N m → m < n → A m) → A n) →
∀ {n} → N n → A n
<-wfind A = WellFoundedInduction <-wf
------------------------------------------------------------------------------
-- The relation _<_ is well-founded (a different proof).
module <-WF' where
<-wf : WellFounded {N} _<_
<-wf nzero = acc (λ Nm m<0 → ⊥-elim (x<0→⊥ Nm m<0))
<-wf (nsucc Nn) = acc (λ Nm m<Sn → helper Nm Nn (<-wf Nn)
(x<Sy→x≤y Nm Nn m<Sn))
where
helper : ∀ {n m} → N n → N m → Acc N _<_ m → n ≤ m → Acc N _<_ n
helper {n} {m} Nn Nm (acc h) n≤m = case (λ n<m → h Nn n<m)
(λ n≡m → helper₁ (sym n≡m) (acc h))
(x≤y→x<y∨x≡y Nn Nm n≤m)
where
helper₁ : ∀ {a b} → a ≡ b → Acc N _<_ a → Acc N _<_ b
helper₁ refl h = h
| 39.470588
| 79
| 0.445976
|
2f46aa74083bd01110c1e48ccaafc03a244fb599
| 674
|
agda
|
Agda
|
test/Succeed/TerminationSubExpression.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/TerminationSubExpression.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/TerminationSubExpression.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v term:20 #-}
-- Andreas, 2011-04-19 (Agda list post by Leonard Rodriguez)
module TerminationSubExpression where
infixr 3 _⇨_
data Type : Set where
int : Type
_⇨_ : Type → Type → Type
test : Type → Type
test int = int
test (φ ⇨ int) = test φ
test (φ ⇨ (φ′ ⇨ φ″)) = test (φ′ ⇨ φ″)
-- this should terminate since rec. call on subterm
test' : Type → Type
test' int = int
test' (φ ⇨ int) = test' φ
test' (φ ⇨ φ′) = test' φ′
-- This no longer checks after the fix to issue 59, since the fact
-- that we case on φ′ in particular is lost.
-- ok : Type → Type
-- ok int = int
-- ok (φ ⇨ φ′) with φ′
-- ... | int = ok φ
-- ... | (φ″ ⇨ φ‴) = ok (φ″ ⇨ φ‴)
| 23.241379
| 66
| 0.58457
|
4d43d3caf85031b156ab1e156935a3b8106cd268
| 299
|
agda
|
Agda
|
lambda/vec.agda
|
Lapin0t/lambda
|
09a231d9b3057d57b864070188ed9fe14a07eda2
|
[
"Apache-2.0"
] | null | null | null |
lambda/vec.agda
|
Lapin0t/lambda
|
09a231d9b3057d57b864070188ed9fe14a07eda2
|
[
"Apache-2.0"
] | null | null | null |
lambda/vec.agda
|
Lapin0t/lambda
|
09a231d9b3057d57b864070188ed9fe14a07eda2
|
[
"Apache-2.0"
] | null | null | null |
module lambda.vec where
open import Data.Nat
open import Data.Fin hiding (_+_)
infixr 40 _▸_
data vec (T : Set) : ℕ → Set where
ε : vec T 0
_▸_ : ∀ {n} → vec T n → T → vec T (suc n)
lookup : ∀ {n} → {T : Set} → Fin n → vec T n → T
lookup zero (Γ ▸ x) = x
lookup (suc i) (Γ ▸ x) = lookup i Γ
| 19.933333
| 48
| 0.565217
|
4da1da58ca51e7c042d6b37505626648115ae5b2
| 4,586
|
agda
|
Agda
|
Structure/Operator/Vector/LinearMap.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Operator/Vector/LinearMap.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Operator/Vector/LinearMap.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Operator.Vector.LinearMap where
open import Functional
open import Logic
open import Logic.Predicate
open import Logic.Propositional
import Lvl
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Multi
open import Structure.Operator
open import Structure.Operator.Field.VectorSpace
open import Structure.Operator.Properties using (Distributivityₗ ; Distributivityᵣ)
open import Structure.Operator.Vector
open import Structure.Setoid
open import Type
open import Syntax.Function
open import Syntax.Transitivity
private variable ℓ ℓᵥ ℓᵥₗ ℓᵥᵣ ℓₛ ℓᵥₑ ℓᵥₑₗ ℓᵥₑᵣ ℓᵥₑ₁ ℓᵥₑ₂ ℓᵥₑ₃ ℓₛₑ : Lvl.Level
private variable V Vₗ Vᵣ V₁ V₂ V₃ S : Type{ℓ}
private variable _+ᵥ_ _+ᵥₗ_ _+ᵥᵣ_ _+ᵥ₁_ _+ᵥ₂_ _+ᵥ₃_ : V → V → V
private variable _⋅ₛᵥ_ _⋅ₛᵥₗ_ _⋅ₛᵥᵣ_ _⋅ₛᵥ₁_ _⋅ₛᵥ₂_ _⋅ₛᵥ₃_ : S → V → V
private variable _+ₛ_ _⋅ₛ_ : S → S → S
module _
⦃ equiv-Vₗ : Equiv{ℓᵥₑₗ}(Vₗ) ⦄
⦃ equiv-Vᵣ : Equiv{ℓᵥₑᵣ}(Vᵣ) ⦄
⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(vectorSpaceₗ : VectorSpace{V = Vₗ}{S = S}(_+ᵥₗ_)(_⋅ₛᵥₗ_)(_+ₛ_)(_⋅ₛ_))
(vectorSpaceᵣ : VectorSpace{V = Vᵣ}{S = S}(_+ᵥᵣ_)(_⋅ₛᵥᵣ_)(_+ₛ_)(_⋅ₛ_))
(f : Vₗ → Vᵣ)
where
record LinearMap : Type{Lvl.of(Vₗ) Lvl.⊔ ℓᵥₑₗ Lvl.⊔ ℓᵥₑᵣ Lvl.⊔ Lvl.of(S)} where
constructor intro
field
⦃ function ⦄ : Function(f)
⦃ preserves-[+ᵥ] ⦄ : Preserving₂(f)(_+ᵥₗ_)(_+ᵥᵣ_)
⦃ preserves-[⋅ₛᵥ] ⦄ : ∀{s} → Preserving₁(f)(s ⋅ₛᵥₗ_)(s ⋅ₛᵥᵣ_)
_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_ : ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄ → VectorSpaceVObject{ℓᵥ = ℓᵥₗ}{ℓᵥₑ = ℓᵥₑₗ}{S = S}(_+ₛ_)(_⋅ₛ_) → VectorSpaceVObject{ℓᵥ = ℓᵥᵣ}{ℓᵥₑ = ℓᵥₑᵣ}{S = S}(_+ₛ_)(_⋅ₛ_) → Stmt
V₁ →ˡⁱⁿᵉᵃʳᵐᵃᵖ V₂ = ∃(LinearMap(VectorSpaceVObject.vectorSpace(V₁)) (VectorSpaceVObject.vectorSpace(V₂)))
_↔ˡⁱⁿᵉᵃʳᵐᵃᵖ_ : ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄ → VectorSpaceVObject{ℓᵥ = ℓᵥₗ}{ℓᵥₑ = ℓᵥₑₗ}{S = S}(_+ₛ_)(_⋅ₛ_) → VectorSpaceVObject{ℓᵥ = ℓᵥᵣ}{ℓᵥₑ = ℓᵥₑᵣ}{S = S}(_+ₛ_)(_⋅ₛ_) → Stmt
V₁ ↔ˡⁱⁿᵉᵃʳᵐᵃᵖ V₂ = ∃(f ↦ Invertible(f) ∧ LinearMap(VectorSpaceVObject.vectorSpace(V₁)) (VectorSpaceVObject.vectorSpace(V₂))(f))
module _
⦃ equiv-V : Equiv{ℓᵥₑ}(V) ⦄
⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(vectorSpace : VectorSpace{V = V}{S = S}(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_))
(f : V → V)
where
LinearOperator = LinearMap(vectorSpace)(vectorSpace) (f)
module _
⦃ equiv-V : Equiv{ℓᵥₑ}(V) ⦄
⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(vectorSpace : VectorSpace{V = V}{S = S}(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_))
(f : V → S)
where
LinearFunctional = LinearMap(vectorSpace)(fieldVectorSpace(VectorSpace.scalarField(vectorSpace))) (f)
module _
⦃ equiv-V₁ : Equiv{ℓᵥₑ₁}(V₁) ⦄
⦃ equiv-V₂ : Equiv{ℓᵥₑ₂}(V₂) ⦄
⦃ equiv-V₃ : Equiv{ℓᵥₑ₃}(V₃) ⦄
⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(vectorSpace₁ : VectorSpace{V = V₁}{S = S}(_+ᵥ₁_)(_⋅ₛᵥ₁_)(_+ₛ_)(_⋅ₛ_))
(vectorSpace₂ : VectorSpace{V = V₂}{S = S}(_+ᵥ₂_)(_⋅ₛᵥ₂_)(_+ₛ_)(_⋅ₛ_))
(vectorSpace₃ : VectorSpace{V = V₃}{S = S}(_+ᵥ₃_)(_⋅ₛᵥ₃_)(_+ₛ_)(_⋅ₛ_))
(f : V₁ → V₂ → V₃)
where
record BilinearMap : Type{Lvl.of(V₁) Lvl.⊔ Lvl.of(V₂) Lvl.⊔ ℓᵥₑ₁ Lvl.⊔ ℓᵥₑ₂ Lvl.⊔ ℓᵥₑ₃ Lvl.⊔ Lvl.of(S)} where
constructor intro
field
⦃ linearMap₁ ⦄ : ∀{y} → LinearMap vectorSpace₁ vectorSpace₃ (x ↦ f(x)(y))
⦃ linearMap₂ ⦄ : ∀{x} → LinearMap vectorSpace₂ vectorSpace₃ (y ↦ f(x)(y))
open module LinearMapₗ{y} = LinearMap(linearMap₁{y}) renaming (function to functionₗ ; preserves-[+ᵥ] to preserves-[+ᵥ]ₗ ; preserves-[⋅ₛᵥ] to preserves-[⋅ₛᵥ]ₗ) public
open module LinearMapᵣ{x} = LinearMap(linearMap₂{x}) renaming (function to functionᵣ ; preserves-[+ᵥ] to preserves-[+ᵥ]ᵣ ; preserves-[⋅ₛᵥ] to preserves-[⋅ₛᵥ]ᵣ) public
binaryOperator : BinaryOperator(f)
binaryOperator = functions-to-binaryOperator(f) ⦃ functionₗ ⦄ ⦃ functionᵣ ⦄
module _
⦃ equiv-V : Equiv{ℓᵥₑ}(V) ⦄
⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(vectorSpace : VectorSpace{V = V}{S = S}(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_))
(_▫_ : V → V → V)
where
BilinearOperator = BilinearMap(vectorSpace)(vectorSpace)(vectorSpace) (_▫_)
module BilinearOperator(bilinearOper : BilinearOperator) where
-- TODO: Move the proof for distributivity from preserving
[+ᵥ]-distributivityₗ : Distributivityₗ(_▫_)(_+ᵥ_)
Distributivityₗ.proof [+ᵥ]-distributivityₗ {x}{y}{z} =
x ▫ (y +ᵥ z) 🝖[ _≡_ ]-[ preserving₂(x ▫_)(_+ᵥ_)(_+ᵥ_) ⦃ LinearMap.preserves-[+ᵥ] (BilinearMap.linearMap₂ bilinearOper) ⦄ ]
(x ▫ y) +ᵥ (x ▫ z) 🝖-end
[+ᵥ]-distributivityᵣ : Distributivityᵣ(_▫_)(_+ᵥ_)
Distributivityᵣ.proof [+ᵥ]-distributivityᵣ {x}{y}{z} =
(x +ᵥ y) ▫ z 🝖[ _≡_ ]-[ preserving₂(_▫ z)(_+ᵥ_)(_+ᵥ_) ⦃ LinearMap.preserves-[+ᵥ] (BilinearMap.linearMap₁ bilinearOper) ⦄ ]
(x ▫ z) +ᵥ (y ▫ z) 🝖-end
| 42.462963
| 173
| 0.656782
|
1c593d6d6378f8c02fb35a84789ca6020d8c26be
| 3,371
|
agda
|
Agda
|
src/TemporalOps/Common/Compare.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | 4
|
2018-05-31T20:37:04.000Z
|
2022-01-04T09:33:48.000Z
|
src/TemporalOps/Common/Compare.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
src/TemporalOps/Common/Compare.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
{- Comparison view and associated lemmas -}
module TemporalOps.Common.Compare where
open import CategoryTheory.Categories
open import Relation.Binary.PropositionalEquality as ≡
open import Relation.Binary.HeterogeneousEquality as ≅
open import Data.Nat.Properties using (+-identityʳ ; +-assoc ; +-suc)
open import Data.Nat using (ℕ ; zero ; suc ; _+_) public
-- (Very verbose) comparison view
-- Like 'compare', but only distinguishes ≤ or >.
data LeqOrdering : ℕ -> ℕ -> Set where
snd==[_+_] : ∀ k l → LeqOrdering k (k + l)
fst==suc[_+_] : ∀ k l → LeqOrdering (k + suc l) k
-- Auxiliary function to compareLeq
compareLeq-suc : ∀ n k -> LeqOrdering n k -> LeqOrdering (suc n) (suc k)
compareLeq-suc n .(n + l) snd==[ .n + l ] = snd==[ suc n + l ]
compareLeq-suc .(k + suc l) k fst==suc[ .k + l ] = fst==suc[ suc k + l ]
compareLeq : ∀ n k -> LeqOrdering n k
compareLeq zero k = snd==[ zero + k ]
compareLeq (suc n) zero = fst==suc[ zero + n ]
compareLeq (suc n) (suc k) = compareLeq-suc n k (compareLeq n k)
-- Lemmas for compareLeq
-- Comparing n and (n + k) always gives snd==[ n + k ]
compare-snd : ∀ (n k : ℕ) -> compareLeq n (n + k) ≡ snd==[ n + k ]
compare-snd zero k = refl
compare-snd (suc n) k rewrite compare-snd n k = refl
-- If n ≤ n + k, then l + n ≤ (l + n) + k
compare-snd-+ : ∀ (n k l : ℕ) -> compareLeq n (n + k) ≡ snd==[ n + k ]
-> compareLeq (l + n) ((l + n) + k) ≡ snd==[ (l + n) + k ]
compare-snd-+ n k zero pf = pf
compare-snd-+ zero k (suc l) pf rewrite +-identityʳ l = compare-snd (suc l) k
compare-snd-+ (suc n) k (suc l) pf
rewrite +-suc l n | compare-snd (l + n) k = refl
-- Heterogeneous version of compare-snd-+ with associativity
compare-snd-+-assoc : ∀ (n k l : ℕ) -> compareLeq n (n + k) ≡ snd==[ n + k ]
-> compareLeq (l + n) (l + (n + k)) ≅ snd==[ (l + n) + k ]
compare-snd-+-assoc n k l pf =
begin
compareLeq (l + n) (l + (n + k))
≅⟨ ≅.cong (λ x → compareLeq (l + n) x) (≡-to-≅ (≡.sym (+-assoc l n k))) ⟩
compareLeq (l + n) ((l + n) + k)
≅⟨ ≡-to-≅ (compare-snd-+ n k l pf) ⟩
snd==[ (l + n) + k ]
∎
where
open ≅.≅-Reasoning
-- Comparing (n + suc k and n always gives fst==suc[ n + k ]
compare-fst : ∀ (n k : ℕ) -> compareLeq (n + suc k) n ≡ fst==suc[ n + k ]
compare-fst zero k = refl
compare-fst (suc n) k rewrite compare-fst n k = refl
-- If n + suc k > n, then (l + n) + suc k > l + n
compare-fst-+ : ∀ (n k l : ℕ) -> compareLeq (n + suc k) n ≡ fst==suc[ n + k ]
-> compareLeq ((l + n) + suc k) (l + n) ≡ fst==suc[ (l + n) + k ]
compare-fst-+ n k zero pf = pf
compare-fst-+ zero k (suc l) pf rewrite +-identityʳ l = compare-fst (suc l) k
compare-fst-+ (suc n) k (suc l) pf
rewrite +-suc l n | compare-fst (l + n) k = refl
-- Heterogeneous version of compare-fst-+ with associativity
compare-fst-+-assoc : ∀ (n k l : ℕ) -> compareLeq (n + suc k) n ≡ fst==suc[ n + k ]
-> compareLeq (l + (n + suc k)) (l + n) ≅ fst==suc[ (l + n) + k ]
compare-fst-+-assoc n k l pf =
begin
compareLeq (l + (n + suc k)) (l + n)
≅⟨ ≅.cong (λ x → compareLeq x (l + n)) (≡-to-≅ (≡.sym (+-assoc l n (suc k)))) ⟩
compareLeq ((l + n) + suc k) (l + n)
≅⟨ ≡-to-≅ (compare-fst-+ n k l pf) ⟩
fst==suc[ (l + n) + k ]
∎
where
open ≅.≅-Reasoning
| 41.109756
| 84
| 0.545832
|
2fadf9a4840cd810a8e5b1b595764be7069440ac
| 8,055
|
agda
|
Agda
|
theorems/cohomology/MayerVietorisExact.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
theorems/cohomology/MayerVietorisExact.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/cohomology/MayerVietorisExact.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.PtdAdjoint
open import homotopy.SuspAdjointLoop
open import cohomology.Exactness
open import cohomology.FunctionOver
open import cohomology.MayerVietoris
open import cohomology.Theory
{- Standard Mayer-Vietoris exact sequence (algebraic) derived from
- the result in cohomology.MayerVietoris (topological).
- This is a whole bunch of algebra which is not very interesting.
-}
module cohomology.MayerVietorisExact {i} (CT : CohomologyTheory i)
(n : ℤ) (ps : ⊙Span {i} {i} {i}) where
open MayerVietorisFunctions ps
module MV = MayerVietoris ps
open ⊙Span ps
open CohomologyTheory CT
open import cohomology.BaseIndependence CT
open import cohomology.Functor CT
open import cohomology.InverseInSusp CT
open import cohomology.LongExactSequence CT n ⊙reglue
open import cohomology.Wedge CT
mayer-vietoris-seq : HomSequence _ _
mayer-vietoris-seq =
C n (⊙Pushout ps)
⟨ ×ᴳ-hom-in (CF-hom n (⊙left ps)) (CF-hom n (⊙right ps)) ⟩→
C n X ×ᴳ C n Y
⟨ ×ᴳ-sum-hom (C-abelian _ _) (CF-hom n f)
(inv-hom _ (C-abelian _ _) ∘ᴳ (CF-hom n g)) ⟩→
C n Z
⟨ CF-hom (succ n) ⊙ext-glue ∘ᴳ fst ((C-Susp n Z)⁻¹ᴳ) ⟩→
C (succ n) (⊙Pushout ps)
⟨ ×ᴳ-hom-in (CF-hom _ (⊙left ps)) (CF-hom _ (⊙right ps)) ⟩→
C (succ n) X ×ᴳ C (succ n) Y ⊣|
mayer-vietoris-exact : is-exact-seq mayer-vietoris-seq
mayer-vietoris-exact =
transport (λ {(r , s) → is-exact-seq s})
(pair= _ $ sequence= _ _ $
idp
∥⟨ ↓-over-×-in _→ᴳ_ idp (CWedge.⊙wedge-rec-over n X Y _ _) ⟩∥
CWedge.path n X Y
∥⟨ ↓-over-×-in' _→ᴳ_
(ap↓ (λ φ → φ ∘ᴳ fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ))
(CF-↓cod= (succ n) MV.ext-over)
∙ᵈ codomain-over-iso {χ = diff'} (codomain-over-equiv _ _))
(CWedge.wedge-hom-η n X Y _
▹ ap2 (×ᴳ-sum-hom (C-abelian n Z)) inl-lemma inr-lemma) ⟩∥
ap (C (succ n)) MV.⊙path ∙ group-ua (C-Susp n Z)
∥⟨ ↓-over-×-in _→ᴳ_
(CF-↓dom= (succ n) MV.cfcod-over
∙ᵈ domain-over-iso
(! (ap (λ h → CF _ ⊙ext-glue ∘ h)
(λ= (is-equiv.g-f (snd (C-Susp n Z)))))
◃ domain-over-equiv _ _))
idp ⟩∥
idp
∥⟨ ↓-over-×-in _→ᴳ_ idp (CWedge.⊙wedge-rec-over (succ n) X Y _ _) ⟩∥
CWedge.path (succ n) X Y ∥⊣|)
long-cofiber-exact
where
{- shorthand -}
diff' = fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff
∘ᴳ fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)
{- Variations on suspension axiom naturality -}
natural-lemma₁ : {X Y : Ptd i} (n : ℤ) (f : fst (X ⊙→ Y))
→ (fst (C-Susp n X) ∘ᴳ CF-hom _ (⊙susp-fmap f)) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)
== CF-hom n f
natural-lemma₁ {X} {Y} n f =
ap (λ φ → φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (C-SuspF n f)
∙ hom= _ _ (λ= (ap (CF n f) ∘ is-equiv.f-g (snd (C-Susp n Y))))
natural-lemma₂ : {X Y : Ptd i} (n : ℤ) (f : fst (X ⊙→ Y))
→ CF-hom _ (⊙susp-fmap f) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)
== fst (C-Susp n X ⁻¹ᴳ) ∘ᴳ CF-hom n f
natural-lemma₂ {X} {Y} n f =
hom= _ _ (λ= (! ∘ is-equiv.g-f (snd (C-Susp n X))
∘ CF _ (⊙susp-fmap f)
∘ GroupHom.f (fst (C-Susp n Y ⁻¹ᴳ))))
∙ ap (λ φ → fst (C-Susp n X ⁻¹ᴳ) ∘ᴳ φ) (natural-lemma₁ n f)
{- Associativity lemmas -}
assoc-lemma : ∀ {i} {G H K L J : Group i}
(φ : L →ᴳ J) (ψ : K →ᴳ L) (χ : H →ᴳ K) (ξ : G →ᴳ H)
→ (φ ∘ᴳ ψ) ∘ᴳ χ ∘ᴳ ξ == φ ∘ᴳ ((ψ ∘ᴳ χ) ∘ᴳ ξ)
assoc-lemma _ _ _ _ = hom= _ _ idp
assoc-lemma₂ : ∀ {i} {G H K L J : Group i}
(φ : L →ᴳ J) (ψ : K →ᴳ L) (χ : H →ᴳ K) (ξ : G →ᴳ H)
→ (φ ∘ᴳ ψ ∘ᴳ χ) ∘ᴳ ξ == φ ∘ᴳ ψ ∘ᴳ χ ∘ᴳ ξ
assoc-lemma₂ _ _ _ _ = hom= _ _ idp
inl-lemma : diff' ∘ᴳ CF-hom n (⊙projl X Y) == CF-hom n f
inl-lemma =
assoc-lemma₂
(fst (C-Susp n Z)) (CF-hom (succ n) MV.⊙mv-diff)
(fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-hom n (⊙projl X Y))
∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ φ)
(! (natural-lemma₂ n (⊙projl X Y)))
∙ ! (assoc-lemma₂
(fst (C-Susp n Z)) (CF-hom _ MV.⊙mv-diff)
(CF-hom _ (⊙susp-fmap (⊙projl X Y)))
(fst (C-Susp n X ⁻¹ᴳ)))
∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n X ⁻¹ᴳ))
(! (CF-comp _ (⊙susp-fmap (⊙projl X Y)) MV.⊙mv-diff))
∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n X ⁻¹ᴳ))
(CF-λ= (succ n) projl-mv-diff)
∙ natural-lemma₁ n f
where
{- Compute the left projection of mv-diff -}
projl-mv-diff : (σz : fst (⊙Susp Z))
→ susp-fmap (projl X Y) (MV.mv-diff σz)
== susp-fmap (fst f) σz
projl-mv-diff = Suspension-elim _ idp (merid _ (snd X)) $
↓-='-from-square ∘ λ z →
(ap-∘ (susp-fmap (projl X Y)) MV.mv-diff (merid _ z)
∙ ap (ap (susp-fmap (projl X Y))) (MV.MVDiff.glue-β z)
∙ ap-∙ (susp-fmap (projl X Y))
(merid _ (winl (fst f z))) (! (merid _ (winr (fst g z))))
∙ (SuspFmap.glue-β (projl X Y) (winl (fst f z))
∙2 (ap-! (susp-fmap _) (merid _ (winr (fst g z)))
∙ ap ! (SuspFmap.glue-β (projl X Y) (winr (fst g z))))))
∙v⊡ (vid-square {p = merid _ (fst f z)}
⊡h rt-square (merid _ (snd X)))
⊡v∙ (∙-unit-r _ ∙ ! (SuspFmap.glue-β (fst f) z))
inr-lemma : diff' ∘ᴳ CF-hom n (⊙projr X Y)
== inv-hom _ (C-abelian n Z) ∘ᴳ CF-hom n g
inr-lemma =
assoc-lemma₂
(fst (C-Susp n Z)) (CF-hom (succ n) MV.⊙mv-diff)
(fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-hom n (⊙projr X Y))
∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ φ)
(! (natural-lemma₂ n (⊙projr X Y)))
∙ ! (assoc-lemma₂
(fst (C-Susp n Z)) (CF-hom _ MV.⊙mv-diff)
(CF-hom _ (⊙susp-fmap (⊙projr X Y)))
(fst (C-Susp n Y ⁻¹ᴳ)))
∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))
(! (CF-comp _ (⊙susp-fmap (⊙projr X Y)) MV.⊙mv-diff))
∙ ∘ᴳ-assoc (fst (C-Susp n Z))
(CF-hom _ (⊙susp-fmap (⊙projr X Y) ⊙∘ MV.⊙mv-diff))
(fst (C-Susp n Y ⁻¹ᴳ))
∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))
(CF-λ= (succ n) projr-mv-diff)
∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))
(CF-comp _ (⊙susp-fmap g) (⊙flip-susp Z))
∙ ! (assoc-lemma (fst (C-Susp n Z)) (CF-hom _ (⊙flip-susp Z))
(CF-hom _ (⊙susp-fmap g)) (fst (C-Susp n Y ⁻¹ᴳ)))
∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ)
∘ᴳ CF-hom _ (⊙susp-fmap g) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))
(C-flip-susp-is-inv (succ n))
∙ ap (λ φ → φ ∘ᴳ CF-hom _ (⊙susp-fmap g) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))
(inv-hom-natural (C-abelian _ _) (C-abelian _ _)
(fst (C-Susp n Z)))
∙ assoc-lemma (inv-hom _ (C-abelian n Z)) (fst (C-Susp n Z))
(CF-hom _ (⊙susp-fmap g)) (fst (C-Susp n Y ⁻¹ᴳ))
∙ ap (λ φ → inv-hom _ (C-abelian n Z) ∘ᴳ φ) (natural-lemma₁ n g)
where
{- Compute the right projection of mv-diff -}
projr-mv-diff : (σz : fst (⊙Susp Z))
→ susp-fmap (projr X Y) (MV.mv-diff σz)
== susp-fmap (fst g) (flip-susp σz)
projr-mv-diff = Suspension-elim _ (merid _ (snd Y)) idp $
↓-='-from-square ∘ λ z →
(ap-∘ (susp-fmap (projr X Y)) MV.mv-diff (merid _ z)
∙ ap (ap (susp-fmap (projr X Y))) (MV.MVDiff.glue-β z)
∙ ap-∙ (susp-fmap (projr X Y))
(merid _ (winl (fst f z))) (! (merid _ (winr (fst g z))))
∙ (SuspFmap.glue-β (projr X Y) (winl (fst f z))
∙2 (ap-! (susp-fmap (projr X Y))
(merid _ (winr (fst g z)))
∙ ap ! (SuspFmap.glue-β (projr X Y) (winr (fst g z))))))
∙v⊡ ((lt-square (merid _ (snd Y))
⊡h vid-square {p = ! (merid _ (fst g z))}))
⊡v∙ ! (ap-∘ (susp-fmap (fst g)) flip-susp (merid _ z)
∙ ap (ap (susp-fmap (fst g))) (FlipSusp.glue-β z)
∙ ap-! (susp-fmap (fst g)) (merid _ z)
∙ ap ! (SuspFmap.glue-β (fst g) z))
| 42.845745
| 76
| 0.503662
|
06f83433c237edf265a52384f6f40afe5e58d592
| 114
|
agda
|
Agda
|
test/interaction/SplitOnHidden.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/SplitOnHidden.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/SplitOnHidden.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
data Nat : Set where
zero : Nat
suc : Nat → Nat
test : ∀{N M : Nat} → Nat → Nat → Nat
test N M = {!.N N .M!}
| 16.285714
| 37
| 0.508772
|
1d86e62d1a65e142f36961f9512eb77a13c29e16
| 602
|
agda
|
Agda
|
test/Fail/Issue610-module-alias.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue610-module-alias.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue610-module-alias.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-02-11, bug reported by sanzhiyan
{-# OPTIONS --irrelevant-projections #-}
module Issue610-module-alias where
import Common.Level
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
data A : Set₁ where
set : .Set → A
module M .(x : Set) where
.out : _
out = x
.ack : A → Set
ack (set x) = M.out x
hah : set ⊤ ≡ set ⊥
hah = refl
.moo' : ⊥
moo' = subst (λ x → x) (cong ack hah) _
-- Expected error:
-- .(⊥) !=< ⊥ of type Set
-- when checking that the expression subst (λ x → x) (cong ack hah) _ has type ⊥
baa : .⊥ → ⊥
baa ()
yoink : ⊥
yoink = baa moo'
| 15.435897
| 80
| 0.607973
|
065897a587baad93a728e064a9f9cae033d8b2d0
| 8,031
|
agda
|
Agda
|
Definition/LogicalRelation/Substitution/Irrelevance.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Substitution/Irrelevance.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Substitution/Irrelevance.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Irrelevance {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.LogicalRelation
import Definition.LogicalRelation.Irrelevance as LR
open import Definition.LogicalRelation.Substitution
open import Tools.Product
open import Tools.Unit
import Tools.PropositionalEquality as PE
-- Irrelevance of valid substitutions with different derivations of contexts
irrelevanceSubst : ∀ {σ Γ Δ}
([Γ] [Γ]′ : ⊩ᵛ Γ)
(⊢Δ ⊢Δ′ : ⊢ Δ)
→ Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ
→ Δ ⊩ˢ σ ∷ Γ / [Γ]′ / ⊢Δ′
irrelevanceSubst ε ε ⊢Δ ⊢Δ′ [σ] = tt
irrelevanceSubst ([Γ] ∙ [A]) ([Γ]′ ∙ [A]′) ⊢Δ ⊢Δ′ ([tailσ] , [headσ]) =
let [tailσ]′ = irrelevanceSubst [Γ] [Γ]′ ⊢Δ ⊢Δ′ [tailσ]
in [tailσ]′
, LR.irrelevanceTerm (proj₁ ([A] ⊢Δ [tailσ]))
(proj₁ ([A]′ ⊢Δ′ [tailσ]′))
[headσ]
-- Irrelevance of valid substitutions with different contexts
-- that are propositionally equal
irrelevanceSubst′ : ∀ {σ Γ Δ Δ′}
(eq : Δ PE.≡ Δ′)
([Γ] [Γ]′ : ⊩ᵛ Γ)
(⊢Δ : ⊢ Δ)
(⊢Δ′ : ⊢ Δ′)
→ Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ
→ Δ′ ⊩ˢ σ ∷ Γ / [Γ]′ / ⊢Δ′
irrelevanceSubst′ PE.refl [Γ] [Γ]′ ⊢Δ ⊢Δ′ [σ] = irrelevanceSubst [Γ] [Γ]′ ⊢Δ ⊢Δ′ [σ]
-- Irrelevance of valid substitution equality
-- with different derivations of contexts
irrelevanceSubstEq : ∀ {σ σ′ Γ Δ}
([Γ] [Γ]′ : ⊩ᵛ Γ)
(⊢Δ ⊢Δ′ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ]′ : Δ ⊩ˢ σ ∷ Γ / [Γ]′ / ⊢Δ′)
→ Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]
→ Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ]′ / ⊢Δ′ / [σ]′
irrelevanceSubstEq ε ε ⊢Δ ⊢Δ′ [σ] [σ]′ [σ≡σ′] = tt
irrelevanceSubstEq ([Γ] ∙ [A]) ([Γ]′ ∙ [A]′) ⊢Δ ⊢Δ′ [σ] [σ]′ [σ≡σ′] =
irrelevanceSubstEq [Γ] [Γ]′ ⊢Δ ⊢Δ′ (proj₁ [σ]) (proj₁ [σ]′) (proj₁ [σ≡σ′])
, LR.irrelevanceEqTerm (proj₁ ([A] ⊢Δ (proj₁ [σ])))
(proj₁ ([A]′ ⊢Δ′ (proj₁ [σ]′)))
(proj₂ [σ≡σ′])
-- Irrelevance of valid types with different derivations of contexts
irrelevance : ∀ {l A Γ}
([Γ] [Γ]′ : ⊩ᵛ Γ)
→ Γ ⊩ᵛ⟨ l ⟩ A / [Γ]
→ Γ ⊩ᵛ⟨ l ⟩ A / [Γ]′
irrelevance [Γ] [Γ]′ [A] ⊢Δ [σ] =
let [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]
in proj₁ ([A] ⊢Δ [σ]′)
, λ [σ′] [σ≡σ′] → proj₂ ([A] ⊢Δ [σ]′)
(irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ′])
(irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] [σ]′ [σ≡σ′])
open import Definition.LogicalRelation.Properties
-- Irrelevance of valid types with different derivations of contexts
-- with lifting of eqaul types
irrelevanceLift : ∀ {l A F H Γ}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([H] : Γ ⊩ᵛ⟨ l ⟩ H / [Γ])
([F≡H] : Γ ⊩ᵛ⟨ l ⟩ F ≡ H / [Γ] / [F])
→ Γ ∙ F ⊩ᵛ⟨ l ⟩ A / [Γ] ∙ [F]
→ Γ ∙ H ⊩ᵛ⟨ l ⟩ A / [Γ] ∙ [H]
irrelevanceLift [Γ] [F] [H] [F≡H] [A] ⊢Δ ([tailσ] , [headσ]) =
let [σ]′ = [tailσ] , convTerm₂ (proj₁ ([F] ⊢Δ [tailσ]))
(proj₁ ([H] ⊢Δ [tailσ]))
([F≡H] ⊢Δ [tailσ]) [headσ]
in proj₁ ([A] ⊢Δ [σ]′)
, (λ [σ′] x →
let [σ′]′ = proj₁ [σ′] , convTerm₂ (proj₁ ([F] ⊢Δ (proj₁ [σ′])))
(proj₁ ([H] ⊢Δ (proj₁ [σ′])))
([F≡H] ⊢Δ (proj₁ [σ′]))
(proj₂ [σ′])
[tailσ′] = proj₁ [σ′]
in proj₂ ([A] ⊢Δ [σ]′) [σ′]′
(proj₁ x , convEqTerm₂ (proj₁ ([F] ⊢Δ [tailσ]))
(proj₁ ([H] ⊢Δ [tailσ]))
([F≡H] ⊢Δ [tailσ])
(proj₂ x)))
-- Irrelevance of valid type equality with different derivations of
-- contexts and types
irrelevanceEq : ∀ {l l′ A B Γ}
([Γ] [Γ]′ : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([A]′ : Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ]′)
→ Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A]
→ Γ ⊩ᵛ⟨ l′ ⟩ A ≡ B / [Γ]′ / [A]′
irrelevanceEq [Γ] [Γ]′ [A] [A]′ [A≡B] ⊢Δ [σ] =
let [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]
in LR.irrelevanceEq (proj₁ ([A] ⊢Δ [σ]′))
(proj₁ ([A]′ ⊢Δ [σ]))
([A≡B] ⊢Δ [σ]′)
-- Irrelevance of valid terms with different derivations of contexts and types
irrelevanceTerm : ∀ {l l′ A t Γ}
([Γ] [Γ]′ : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([A]′ : Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ]′)
→ Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A]
→ Γ ⊩ᵛ⟨ l′ ⟩ t ∷ A / [Γ]′ / [A]′
irrelevanceTerm [Γ] [Γ]′ [A] [A]′ [t] ⊢Δ [σ]′ =
let [σ] = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]′
[σA] = proj₁ ([A] ⊢Δ [σ])
[σA]′ = proj₁ ([A]′ ⊢Δ [σ]′)
in LR.irrelevanceTerm [σA] [σA]′ (proj₁ ([t] ⊢Δ [σ]))
, (λ [σ′] x → LR.irrelevanceEqTerm [σA] [σA]′ ((proj₂ ([t] ⊢Δ [σ]))
(irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ′])
(irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]′ [σ] x)))
-- Irrelevance of valid terms with different derivations of
-- contexts and types which are propositionally equal
irrelevanceTerm′ : ∀ {l l′ A A′ t Γ}
(eq : A PE.≡ A′)
([Γ] [Γ]′ : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([A′] : Γ ⊩ᵛ⟨ l′ ⟩ A′ / [Γ]′)
→ Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A]
→ Γ ⊩ᵛ⟨ l′ ⟩ t ∷ A′ / [Γ]′ / [A′]
irrelevanceTerm′ {A = A} {t = t} PE.refl [Γ] [Γ]′ [A] [A]′ [t] =
irrelevanceTerm {A = A} {t = t} [Γ] [Γ]′ [A] [A]′ [t]
-- Irrelevance of valid terms with different derivations of
-- contexts and types with a lifting of equal types
irrelevanceTermLift : ∀ {l A F H t Γ}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([H] : Γ ⊩ᵛ⟨ l ⟩ H / [Γ])
([F≡H] : Γ ⊩ᵛ⟨ l ⟩ F ≡ H / [Γ] / [F])
([A] : Γ ∙ F ⊩ᵛ⟨ l ⟩ A / [Γ] ∙ [F])
→ Γ ∙ F ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] ∙ [F] / [A]
→ Γ ∙ H ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] ∙ [H]
/ irrelevanceLift {A = A} {F = F} {H = H}
[Γ] [F] [H] [F≡H] [A]
irrelevanceTermLift [Γ] [F] [H] [F≡H] [A] [t] ⊢Δ ([tailσ] , [headσ]) =
let [σ]′ = [tailσ] , convTerm₂ (proj₁ ([F] ⊢Δ [tailσ]))
(proj₁ ([H] ⊢Δ [tailσ]))
([F≡H] ⊢Δ [tailσ]) [headσ]
in proj₁ ([t] ⊢Δ [σ]′)
, (λ [σ′] x →
let [σ′]′ = proj₁ [σ′] , convTerm₂ (proj₁ ([F] ⊢Δ (proj₁ [σ′])))
(proj₁ ([H] ⊢Δ (proj₁ [σ′])))
([F≡H] ⊢Δ (proj₁ [σ′]))
(proj₂ [σ′])
[tailσ′] = proj₁ [σ′]
in proj₂ ([t] ⊢Δ [σ]′) [σ′]′
(proj₁ x , convEqTerm₂ (proj₁ ([F] ⊢Δ [tailσ]))
(proj₁ ([H] ⊢Δ [tailσ]))
([F≡H] ⊢Δ [tailσ])
(proj₂ x)))
-- Irrelevance of valid term equality with different derivations of
-- contexts and types
irrelevanceEqTerm : ∀ {l l′ A t u Γ}
([Γ] [Γ]′ : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([A]′ : Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ]′)
→ Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A]
→ Γ ⊩ᵛ⟨ l′ ⟩ t ≡ u ∷ A / [Γ]′ / [A]′
irrelevanceEqTerm {A = A} {t = t} {u = u} [Γ] [Γ]′ [A] [A]′ [t≡u] ⊢Δ [σ] =
let [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]
in LR.irrelevanceEqTerm (proj₁ ([A] ⊢Δ [σ]′))
(proj₁ ([A]′ ⊢Δ [σ]))
([t≡u] ⊢Δ [σ]′)
| 43.646739
| 85
| 0.382144
|
599b9ca688f61742380e796b404d3d2af04adb9c
| 144
|
agda
|
Agda
|
test/fail/Issue476d.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/fail/Issue476d.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/Issue476d.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- Private signatures
module Issue476d where
module M where
private
record R : Set₁
record R where
field X : Set
Q : Set₁
Q = M.R
| 12
| 22
| 0.666667
|
1d0da00332ca25a66879dae26a5f612419ac450b
| 3,406
|
agda
|
Agda
|
src/JVM/Model.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 6
|
2020-10-07T14:07:17.000Z
|
2021-02-28T21:49:08.000Z
|
src/JVM/Model.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | null | null | null |
src/JVM/Model.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.Model {ℓ} (T : Set ℓ) where
open import Level hiding (Lift)
open import Data.Product
open import Data.Unit
open import Data.List
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Construct.Empty T public
open import Relation.Ternary.Construct.Duplicate T public
open import Data.List.Relation.Binary.Permutation.Propositional
using ()
renaming (_↭_ to _≈_)
open import Data.List.Relation.Binary.Permutation.Propositional.Properties
using (++-isMonoid)
instance ++-monoid-instance = ++-isMonoid
module Disjoint where
open import Relation.Ternary.Construct.Bag empty-rel tt public
open IsPartialSemigroup bags-isSemigroup public
open IsPartialMonoid bags-isMonoid public
open IsCommutative bags-isCommutative public
module Overlap where
open import Relation.Ternary.Construct.Bag duplicate tt public
open IsPartialSemigroup bags-isSemigroup public
open IsPartialMonoid bags-isMonoid public
open IsCommutative bags-isCommutative public
open IsTotal bags-isTotal public
open Disjoint using (bag-emptiness) renaming
( empty-unique to empty-bag-unique
; singleton-unique to singleton-bag-unique)
public
open Rel₃ Disjoint.bags using ()
renaming (_∙_≣_ to _⊕_≣_; _✴_ to _⊕_; _─✴_ to _─⊕_; _∙⟨_⟩_ to _⊕⟨_⟩_) public
open Rel₃ Overlap.bags using ()
renaming (_∙_≣_ to _⊗_≣_; _✴_ to _⊗_; _─✴_ to _─⊗_; _∙⟨_⟩_ to _⊗⟨_⟩_) public
open import Relation.Ternary.Construct.Bag.Properties
open import Data.List.Relation.Binary.Permutation.Propositional
open CrossSplittable {{div₁ = duplicate}} {{empty-rel}} (λ _ ())
abstract
private
m₁ : IsPartialMonoid _↭_ Disjoint.bags []
m₁ = Disjoint.bags-isMonoid
m₂ : IsPartialMonoid _↭_ Overlap.bags []
m₂ = Overlap.bags-isMonoid
p₁ : IsPositiveWithZero 0ℓ _↭_ Disjoint.bags []
p₁ = Disjoint.bags-isPositive-w/0
p₂ : IsPositiveWithZero 0ℓ _↭_ Overlap.bags []
p₂ = Overlap.bags-isPositive-w/0
c₁ : IsCommutative Disjoint.bags
c₁ = Disjoint.bags-isCommutative
c₂ : IsCommutative Overlap.bags
c₂ = Overlap.bags-isCommutative
x : CrossSplit Overlap.bags Disjoint.bags
x = xsplit
ux : Uncross Disjoint.bags Overlap.bags
ux = uncrossover (unxcross λ ())
open import Relation.Ternary.Construct.Exchange
{A = List T}
{{m₁}} {{m₂}} {{p₁}} {{p₂}} {{empty-bag-unique}} {{c₁}} {{c₂}}
{{Disjoint.bags-isTotal}}
{{Overlap.bags-isTotal}}
{{++-isMonoid}}
x ux
public
renaming
(Account to Intf
; _≈_ to _≈intf≈_
; exchange-rel to intf-rel
; exchange-emptiness to intf-emptiness
; exchange-isSemigroup to intf-isSemigroup
; exchange-isCommutative to intf-isCommutative
; exchange-isMonoid to intf-isMonoid
; exchange-isTotal to intf-isTotal)
open DownIntuitive {{Overlap.bags-isContractive}} public
module Syntax where
open Rel₃ intf-rel public
open Emptiness intf-emptiness public
open IsPartialSemigroup intf-isSemigroup public
open IsPartialMonoid intf-isMonoid public
open IsCommutative intf-isCommutative public
open CommutativeSemigroupOps {{intf-isSemigroup}} {{intf-isCommutative}} public
-- module _ {P} where
-- open IsIntuitionistic (intf-isIntuitive {P}) w public
open Syntax
| 31.247706
| 81
| 0.724604
|
293113a79d6ac77a984c275487a8634e93bc9f7c
| 11,350
|
agda
|
Agda
|
Definition/LogicalRelation/Properties/Neutral.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Properties/Neutral.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Properties/Neutral.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Neutral {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
import Definition.Typed.Weakening as Wk
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties.Reflexivity
open import Definition.LogicalRelation.Properties.Escape
open import Definition.LogicalRelation.Properties.Symmetry
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Neutral reflexive types are reducible.
neu : ∀ {l Γ A} (neA : Neutral A)
→ Γ ⊢ A
→ Γ ⊢ A ~ A ∷ U
→ Γ ⊩⟨ l ⟩ A
neu neA A A~A = ne′ _ (idRed:*: A) neA A~A
-- Helper function for reducible neutral equality of a specific type of derivation.
neuEq′ : ∀ {l Γ A B} ([A] : Γ ⊩⟨ l ⟩ne A)
(neA : Neutral A)
(neB : Neutral B)
→ Γ ⊢ A → Γ ⊢ B
→ Γ ⊢ A ~ B ∷ U
→ Γ ⊩⟨ l ⟩ A ≡ B / ne-intr [A]
neuEq′ (noemb (ne K [ ⊢A , ⊢B , D ] neK K≡K)) neA neB A B A~B =
let A≡K = whnfRed* D (ne neA)
in ne₌ _ (idRed:*: B) neB (PE.subst (λ x → _ ⊢ x ~ _ ∷ _) A≡K A~B)
neuEq′ (emb 0<1 x) neB A:≡:B = neuEq′ x neB A:≡:B
-- Neutrally equal types are of reducible equality.
neuEq : ∀ {l Γ A B} ([A] : Γ ⊩⟨ l ⟩ A)
(neA : Neutral A)
(neB : Neutral B)
→ Γ ⊢ A → Γ ⊢ B
→ Γ ⊢ A ~ B ∷ U
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
neuEq [A] neA neB A B A~B =
irrelevanceEq (ne-intr (ne-elim neA [A]))
[A]
(neuEq′ (ne-elim neA [A]) neA neB A B A~B)
mutual
-- Neutral reflexive terms are reducible.
neuTerm : ∀ {l Γ A n} ([A] : Γ ⊩⟨ l ⟩ A) (neN : Neutral n)
→ Γ ⊢ n ∷ A
→ Γ ⊢ n ~ n ∷ A
→ Γ ⊩⟨ l ⟩ n ∷ A / [A]
neuTerm (Uᵣ′ .⁰ 0<1 ⊢Γ) neN n n~n =
Uₜ _ (idRedTerm:*: n) (ne neN) (~-to-≅ₜ n~n) (neu neN (univ n) n~n)
neuTerm (ℕᵣ [ ⊢A , ⊢B , D ]) neN n n~n =
let A≡ℕ = subset* D
n~n′ = ~-conv n~n A≡ℕ
n≡n = ~-to-≅ₜ n~n′
in ℕₜ _ (idRedTerm:*: (conv n A≡ℕ)) n≡n (ne (neNfₜ neN (conv n A≡ℕ) n~n′))
neuTerm (Emptyᵣ [ ⊢A , ⊢B , D ]) neN n n~n =
let A≡Empty = subset* D
n~n′ = ~-conv n~n A≡Empty
n≡n = ~-to-≅ₜ n~n′
in Emptyₜ _ (idRedTerm:*: (conv n A≡Empty)) n≡n (ne (neNfₜ neN (conv n A≡Empty) n~n′))
neuTerm (Unitᵣ [ ⊢A , ⊢B , D ]) neN n n~n =
let A≡Unit = subset* D
n~n′ = ~-conv n~n A≡Unit
in Unitₜ _ (idRedTerm:*: (conv n A≡Unit)) (ne neN)
neuTerm (ne′ K [ ⊢A , ⊢B , D ] neK K≡K) neN n n~n =
let A≡K = subset* D
in neₜ _ (idRedTerm:*: (conv n A≡K)) (neNfₜ neN (conv n A≡K)
(~-conv n~n A≡K))
neuTerm (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n =
let A≡ΠFG = subset* (red D)
in Πₜ _ (idRedTerm:*: (conv n A≡ΠFG)) (ne neN) (~-to-≅ₜ (~-conv n~n A≡ΠFG))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let A≡ΠFG = subset* (red D)
ρA≡ρΠFG = Wk.wkEq [ρ] ⊢Δ (subset* (red D))
G[a]≡G[b] = escapeEq ([G] [ρ] ⊢Δ [b])
(symEq ([G] [ρ] ⊢Δ [a]) ([G] [ρ] ⊢Δ [b])
(G-ext [ρ] ⊢Δ [a] [b] [a≡b]))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
b = escapeTerm ([F] [ρ] ⊢Δ) [b]
a≡b = escapeTermEq ([F] [ρ] ⊢Δ) [a≡b]
ρn = conv (Wk.wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG
neN∘a = ∘ₙ (wkNeutral ρ neN)
neN∘b = ∘ₙ (wkNeutral ρ neN)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∘a neN∘b
(ρn ∘ⱼ a)
(conv (ρn ∘ⱼ b) (≅-eq G[a]≡G[b]))
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡b))
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = Wk.wkEq [ρ] ⊢Δ (subset* (red D))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ) (reflEqTerm ([F] [ρ] ⊢Δ) [a])
in neuTerm ([G] [ρ] ⊢Δ [a]) (∘ₙ (wkNeutral ρ neN))
(conv (Wk.wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡a))
neuTerm (Σᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN ⊢n n~n =
let A≡ΣFG = subset* (red D)
⊢Γ = wf ⊢F
⊢n = conv ⊢n A≡ΣFG
n~n = ~-conv n~n A≡ΣFG
[F] = [F] Wk.id ⊢Γ
[fst] = neuTerm [F] (fstₙ neN)
(PE.subst
(λ x → _ ⊢ fst _ ∷ x)
(PE.sym (wk-id F))
(fstⱼ ⊢F ⊢G ⊢n))
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n~n))
[Gfst] = [G] Wk.id ⊢Γ [fst]
[snd] = neuTerm [Gfst] (sndₙ neN)
(PE.subst
(λ x → _ ⊢ snd _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(sndⱼ ⊢F ⊢G ⊢n))
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(~-snd ⊢F ⊢G n~n))
in Σₜ _ (idRedTerm:*: ⊢n) (ne neN) (~-to-≅ₜ n~n)
[fst]
[snd]
neuTerm (emb 0<1 x) neN n = neuTerm x neN n
-- Neutrally equal terms are of reducible equality.
neuEqTerm : ∀ {l Γ A n n′} ([A] : Γ ⊩⟨ l ⟩ A)
(neN : Neutral n) (neN′ : Neutral n′)
→ Γ ⊢ n ∷ A
→ Γ ⊢ n′ ∷ A
→ Γ ⊢ n ~ n′ ∷ A
→ Γ ⊩⟨ l ⟩ n ≡ n′ ∷ A / [A]
neuEqTerm (Uᵣ′ .⁰ 0<1 ⊢Γ) neN neN′ n n′ n~n′ =
let [n] = neu neN (univ n) (~-trans n~n′ (~-sym n~n′))
[n′] = neu neN′ (univ n′) (~-trans (~-sym n~n′) n~n′)
in Uₜ₌ _ _ (idRedTerm:*: n) (idRedTerm:*: n′) (ne neN) (ne neN′)
(~-to-≅ₜ n~n′) [n] [n′] (neuEq [n] neN neN′ (univ n) (univ n′) n~n′)
neuEqTerm (ℕᵣ [ ⊢A , ⊢B , D ]) neN neN′ n n′ n~n′ =
let A≡ℕ = subset* D
n~n′₁ = ~-conv n~n′ A≡ℕ
n≡n′ = ~-to-≅ₜ n~n′₁
in ℕₜ₌ _ _ (idRedTerm:*: (conv n A≡ℕ)) (idRedTerm:*: (conv n′ A≡ℕ))
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm (Emptyᵣ [ ⊢A , ⊢B , D ]) neN neN′ n n′ n~n′ =
let A≡Empty = subset* D
n~n′₁ = ~-conv n~n′ A≡Empty
n≡n′ = ~-to-≅ₜ n~n′₁
in Emptyₜ₌ _ _ (idRedTerm:*: (conv n A≡Empty)) (idRedTerm:*: (conv n′ A≡Empty))
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm (Unitᵣ [ ⊢A , ⊢B , D ]) neN neN′ n n′ n~n′ =
let A≡Unit = subset* D
in Unitₜ₌ (conv n A≡Unit) (conv n′ A≡Unit)
neuEqTerm (ne (ne K [ ⊢A , ⊢B , D ] neK K≡K)) neN neN′ n n′ n~n′ =
let A≡K = subset* D
in neₜ₌ _ _ (idRedTerm:*: (conv n A≡K)) (idRedTerm:*: (conv n′ A≡K))
(neNfₜ₌ neN neN′ (~-conv n~n′ A≡K))
neuEqTerm (Πᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let [ΠFG] = Πᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΠFG = subset* D
n~n′₁ = ~-conv n~n′ A≡ΠFG
n≡n′ = ~-to-≅ₜ n~n′₁
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
in Πₜ₌ _ _ (idRedTerm:*: (conv n A≡ΠFG)) (idRedTerm:*: (conv n′ A≡ΠFG))
(ne neN) (ne neN′) n≡n′
(neuTerm [ΠFG] neN n n~n) (neuTerm [ΠFG] neN′ n′ n′~n′)
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = Wk.wkEq [ρ] ⊢Δ A≡ΠFG
ρn = Wk.wkTerm [ρ] ⊢Δ n
ρn′ = Wk.wkTerm [ρ] ⊢Δ n′
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ)
(reflEqTerm ([F] [ρ] ⊢Δ) [a])
neN∙a = ∘ₙ (wkNeutral ρ neN)
neN′∙a′ = ∘ₙ (wkNeutral ρ neN′)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∙a neN′∙a′
(conv ρn ρA≡ρΠFG ∘ⱼ a)
(conv ρn′ ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ n~n′₁) a≡a))
neuEqTerm (Σᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ ⊢n ⊢n′ n~n′ =
let [ΣFG] = Σᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΣFG = subset* D
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
⊢Γ = wf ⊢F
⊢nΣ = conv ⊢n A≡ΣFG
⊢n′Σ = conv ⊢n′ A≡ΣFG
n~n′Σ = ~-conv n~n′ A≡ΣFG
n~nΣ = ~-conv n~n A≡ΣFG
n′~n′Σ = ~-conv n′~n′ A≡ΣFG
[F] = [F] Wk.id ⊢Γ
⊢fstnΣ = (PE.subst
(λ x → _ ⊢ fst _ ∷ x)
(PE.sym (wk-id F))
(fstⱼ ⊢F ⊢G ⊢nΣ))
⊢fstn′Σ = (PE.subst
(λ x → _ ⊢ fst _ ∷ x)
(PE.sym (wk-id F))
(fstⱼ ⊢F ⊢G ⊢n′Σ))
[fstn] = neuTerm [F] (fstₙ neN)
⊢fstnΣ
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n~nΣ))
[fstn′] = neuTerm [F] (fstₙ neN′)
⊢fstn′Σ
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n′~n′Σ))
[fstn≡fstn′] = neuEqTerm [F] (fstₙ neN) (fstₙ neN′)
⊢fstnΣ
⊢fstn′Σ
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n~n′Σ))
[Gfstn] = [G] Wk.id ⊢Γ [fstn]
[Gfstn′] = PE.subst (λ x → _ ⊩⟨ _ ⟩ x [ fst _ ]) (wk-lift-id G) ([G] Wk.id ⊢Γ [fstn′])
[fstn′≡fstn] = symEqTerm [F] [fstn≡fstn′]
[Gfstn′≡Gfstn] = irrelevanceEq″
(PE.cong (λ x → x [ fst _ ]) (wk-lift-id G))
(PE.cong (λ x → x [ fst _ ]) (wk-lift-id G))
([G] Wk.id ⊢Γ [fstn′]) [Gfstn′]
(G-ext Wk.id ⊢Γ [fstn′] [fstn] [fstn′≡fstn])
Gfstn′≡Gfstn = ≅-eq (escapeEq [Gfstn′] [Gfstn′≡Gfstn])
[sndn≡sndn′] = neuEqTerm [Gfstn] (sndₙ neN) (sndₙ neN′)
(PE.subst
(λ x → _ ⊢ snd _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(sndⱼ ⊢F ⊢G ⊢nΣ))
(PE.subst
(λ x → _ ⊢ snd _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(conv (sndⱼ ⊢F ⊢G ⊢n′Σ) Gfstn′≡Gfstn))
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(~-snd ⊢F ⊢G n~n′Σ))
in Σₜ₌ _ _ (idRedTerm:*: ⊢nΣ) (idRedTerm:*: ⊢n′Σ)
(ne neN) (ne neN′) (~-to-≅ₜ n~n′Σ)
(neuTerm [ΣFG] neN ⊢n n~n) (neuTerm [ΣFG] neN′ ⊢n′ n′~n′)
[fstn] [fstn′] [fstn≡fstn′] [sndn≡sndn′]
neuEqTerm (emb 0<1 x) neN neN′ n:≡:n′ = neuEqTerm x neN neN′ n:≡:n′
| 43.822394
| 94
| 0.396035
|
4a1be14b8dce45405e39c629c53d2a04ec39c723
| 1,698
|
agda
|
Agda
|
src/cedille-main.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 328
|
2018-09-14T20:06:09.000Z
|
2022-03-26T10:33:07.000Z
|
src/cedille-main.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 123
|
2018-09-17T10:53:20.000Z
|
2022-01-12T03:51:28.000Z
|
src/cedille-main.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 34
|
2018-09-17T11:51:36.000Z
|
2022-02-20T18:33:16.000Z
|
module cedille-main where
import parse
open import ial
open import cedille-types
import cedille
module parsem = parse cedille.gratr2-nt ptr
open parsem
open parsem.pnoderiv cedille.rrs cedille.cedille-rtn
open import run ptr
open noderiv {- from run.agda -}
process-start : start → string
process-start s = ""
process : Run → string
process (ParseTree (parsed-start p) :: []) = process-start p
process r = "Parsing failure (run with -" ^ "-showParsed).\n"
putStrRunIf : 𝔹 → Run → IO ⊤
putStrRunIf tt r = putStr (Run-to-string r) >> putStr "\n"
putStrRunIf ff r = return triv
processArgs : (showRun : 𝔹) → (showParsed : 𝔹) → 𝕃 string → IO ⊤
processArgs showRun showParsed (input-filename :: []) = (readFiniteFile input-filename) >>= processText
where processText : string → IO ⊤
processText x with runRtn (string-to-𝕃char x)
processText x | s with s
processText x | s | inj₁ cs = putStr "Characters left before failure : " >> putStr (𝕃char-to-string cs) >> putStr "\nCannot proceed to parsing.\n"
processText x | s | inj₂ r with putStrRunIf showRun r | rewriteRun r
processText x | s | inj₂ r | sr | r' with putStrRunIf showParsed r'
processText x | s | inj₂ r | sr | r' | sr' = sr >> sr' >> putStr (process r')
processArgs showRun showParsed ("--showRun" :: xs) = processArgs tt showParsed xs
processArgs showRun showParsed ("--showParsed" :: xs) = processArgs showRun tt xs
processArgs showRun showParsed (x :: xs) = putStr ("Unknown option " ^ x ^ "\n")
processArgs showRun showParsed [] = putStr "Please run with the name of a file to process.\n"
main : IO ⊤
main = getArgs >>= processArgs ff ff
| 39.488372
| 154
| 0.671378
|
31bd4f69806cda96d8e8ece059555713c524f94b
| 198
|
agda
|
Agda
|
sets/empty.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 27
|
2015-04-14T15:47:03.000Z
|
2022-01-09T07:26:57.000Z
|
sets/empty.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 2
|
2015-02-11T11:14:59.000Z
|
2015-02-11T15:20:34.000Z
|
sets/empty.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 4
|
2015-04-11T17:19:12.000Z
|
2019-02-26T06:17:38.000Z
|
{-# OPTIONS --without-K #-}
module sets.empty where
open import level using ()
data ⊥ : Set where
⊥-elim : ∀ {i}{A : Set i} → ⊥ → A
⊥-elim ()
¬_ : ∀ {i} → Set i → Set i
¬ X = X → ⊥
infix 3 ¬_
| 13.2
| 33
| 0.510101
|
2feaf49122a033e1989506ece4d770f4f50faa30
| 223
|
agda
|
Agda
|
test/Succeed/Issue4909.agda
|
LaloHao/agda
|
7de768bb7bc65dbe1efa35c699cfa8b8f9510573
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4909.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4909.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
{-# OPTIONS --no-fast-reduce #-}
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
data A : Set where
a b : A
postulate rew : a ≡ b
{-# REWRITE rew #-}
test : a ≡ b
test = refl
| 14.866667
| 33
| 0.600897
|
0bafaf7510289f635524659f3a1769538e04448c
| 2,388
|
agda
|
Agda
|
preservation.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | 1
|
2019-12-19T23:42:31.000Z
|
2019-12-19T23:42:31.000Z
|
preservation.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
preservation.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import List
open import contexts
open import core
open import lemmas-env
module preservation where
preservation : ∀{⛽ Δ Σ' Γ E e r k τ} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ e :: τ →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ k →
Δ , Σ' ⊢ r ·: τ
preservation ctxcons ta EFix = TAFix ctxcons ta
preservation ctxcons (TAVar tah) (EVar h) with env-all-Γ ctxcons tah
... | π3 , π4 , π5 rewrite ctxunicity h π4 = π5
preservation ctxcons (TAHole h) EHole = TAHole h ctxcons
preservation ctxcons TAUnit EUnit = TAUnit
preservation ctxcons (TAPair _ ta1 ta2) (EPair eval1 eval2)
= TAPair (preservation ctxcons ta1 eval1 ) (preservation ctxcons ta2 eval2)
preservation ctxcons (TACtor h1 h2 ta) (ECtor eval) = TACtor h1 h2 (preservation ctxcons ta eval)
preservation ctxcons (TAApp _ ta-f ta-arg) (EAppFix _ h eval1 eval2 eval-ef)
rewrite h
with preservation ctxcons ta-f eval1
... | TAFix ctxcons-Ef (TAFix ta-ef) =
preservation (EnvInd (EnvInd ctxcons-Ef (preservation ctxcons ta-f eval1)) (preservation ctxcons ta-arg eval2)) ta-ef eval-ef
preservation ctxcons (TAApp _ ta1 ta2) (EAppUnfinished eval1 _ eval2) =
TAApp (preservation ctxcons ta1 eval1) (preservation ctxcons ta2 eval2)
preservation ctxcons (TAFst ta) (EFst eval)
with preservation ctxcons ta eval
... | TAPair ta1 ta2 = ta1
preservation ctxcons (TAFst ta) (EFstUnfinished eval x)
= TAFst (preservation ctxcons ta eval)
preservation ctxcons (TASnd ta) (ESnd eval)
with preservation ctxcons ta eval
... | TAPair ta1 ta2 = ta2
preservation ctxcons (TASnd ta) (ESndUnfinished eval x)
= TASnd (preservation ctxcons ta eval)
preservation {Σ' = Σ'} ctxcons (TACase d∈Σ' ta h1 h2) (EMatch _ form eval-e eval-ec) with h2 form
... | _ , _ , _ , c∈cctx2 , ta-ec with preservation ctxcons ta eval-e
... | TACtor {cctx = cctx} d∈Σ'2 c∈cctx ta' with ctxunicity {Γ = π1 Σ'} d∈Σ' d∈Σ'2
... | refl with ctxunicity {Γ = cctx} c∈cctx c∈cctx2
... | refl = preservation (EnvInd ctxcons ta') ta-ec eval-ec
preservation ctxcons (TACase d∈Σ' ta h1 h2) (EMatchUnfinished eval h) =
TACase d∈Σ' ctxcons (preservation ctxcons ta eval) h1 λ form' →
let _ , _ , _ , p2 , p3 = h2 form' in
_ , p2 , p3
preservation ctxcons (TAAsrt _ ta1 ta2) (EAsrt eval1 eval2 _) = TAUnit
| 46.823529
| 129
| 0.664992
|
573c8b7125689eb0891f09d6a658c17f7e1aad2e
| 1,372
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Symmetry/ToSym.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Symmetry/ToSym.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/Symmetry/ToSym.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Symmetry
module Oscar.Class.Symmetry.ToSym where
private
test-class :
⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class _∼_ ⦄
→ ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class _∼_
test-class = !
test-class' :
∀ {𝔬} {𝔒 : Ø 𝔬} {x : 𝔒} {𝔯} {F : (𝔒 → 𝔒 → Ø 𝔯) → 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : ∀ {S : 𝔒 → 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class (F (S x)) ⦄
→ ∀ {S : 𝔒 → 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class (F (S x))
test-class' ⦃ ⌶ ⦄ {S} = ⌶ {S} -- FIXME _S _x ≟ _S' _x
test-class'' :
∀ {𝔬} {𝔒 : Ø 𝔬} {x : 𝔒} {𝔯} {F : (𝔒 → 𝔒 → 𝔒 → Ø 𝔯) → 𝔒 → 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : ∀ {S : 𝔒 → 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class (F S x) ⦄
→ ∀ {S : 𝔒 → 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class (F S x)
test-class'' = !
test-class''' :
∀ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {F : (𝔒 → 𝔒 → 𝔒 → Ø 𝔯) → 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : ∀ {S : 𝔒 → 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class (F S) ⦄
→ ∀ {S : 𝔒 → 𝔒 → 𝔒 → Ø 𝔯} → Symmetry.class (F S)
test-class''' = !
test-method-sym : ∀
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : Symmetry.class _∼_ ⦄
→ _
test-method-sym {_∼_ = _∼_} = λ {x} {y} → Symmetry.method _∼_ {x} {y}
test-method-symmetry : ∀
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : Symmetry.class _∼_ ⦄
→ _
test-method-symmetry {_∼_ = _∼_} = λ {x} {y} → symmetry[ _∼_ ] {x} {y}
| 29.826087
| 73
| 0.433673
|
31996c0bc9dc6bd6dd2ca6ae0410a1d511dd82d3
| 2,732
|
agda
|
Agda
|
Cubical/Algebra/Ring/Ideal.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring/Ideal.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring/Ideal.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Ring.Ideal where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Algebra.Ring.Base
open import Cubical.Algebra.Ring.Properties
private
variable
ℓ : Level
module _ (R' : Ring {ℓ}) where
open RingStr (snd R')
private R = ⟨ R' ⟩
{- by default, 'ideal' means two-sided ideal -}
record isIdeal (I : R → hProp ℓ) : Type ℓ where
field
+-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I
-closed : {x : R} → x ∈ I → - x ∈ I
0r-closed : 0r ∈ I
·-closedLeft : {x : R} → (r : R) → x ∈ I → r · x ∈ I
·-closedRight : {x : R} → (r : R) → x ∈ I → x · r ∈ I
Ideal : Type _
Ideal = Σ[ I ∈ (R → hProp ℓ) ] isIdeal I
record isLeftIdeal (I : R → hProp ℓ) : Type ℓ where
field
+-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I
-closed : {x : R} → x ∈ I → - x ∈ I
0r-closed : 0r ∈ I
·-closedLeft : {x : R} → (r : R) → x ∈ I → r · x ∈ I
record isRightIdeal (I : R → hProp ℓ) : Type ℓ where
field
+-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I
-closed : {x : R} → x ∈ I → - x ∈ I
0r-closed : 0r ∈ I
·-closedRight : {x : R} → (r : R) → x ∈ I → x · r ∈ I
{- Examples of ideals -}
zeroSubset : (x : R) → hProp ℓ
zeroSubset x = (x ≡ 0r) , isSetRing R' _ _
open Theory R'
isIdealZeroIdeal : isIdeal zeroSubset
isIdealZeroIdeal = record
{ +-closed = λ x≡0 y≡0 → _ + _ ≡⟨ cong (λ u → u + _) x≡0 ⟩
0r + _ ≡⟨ +Lid _ ⟩
_ ≡⟨ y≡0 ⟩
0r ∎
; -closed = λ x≡0 → - _ ≡⟨ cong (λ u → - u) x≡0 ⟩
- 0r ≡⟨ 0Selfinverse ⟩
0r ∎
; 0r-closed = refl
; ·-closedLeft = λ r x≡0 → r · _ ≡⟨ cong (λ u → r · u) x≡0 ⟩
r · 0r ≡⟨ 0RightAnnihilates r ⟩
0r ∎
; ·-closedRight = λ r x≡0 → _ · r ≡⟨ cong (λ u → u · r) x≡0 ⟩
0r · r ≡⟨ 0LeftAnnihilates r ⟩
0r ∎
}
zeroIdeal : Ideal
zeroIdeal = zeroSubset , isIdealZeroIdeal
IdealsIn : (R : Ring {ℓ}) → Type _
IdealsIn {ℓ} R = Σ[ I ∈ (⟨ R ⟩ → hProp ℓ) ] isIdeal R I
| 34.582278
| 84
| 0.421669
|
d043833bfd028add2f70e28671d8cf0b0f69aa85
| 4,087
|
agda
|
Agda
|
MuNu.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | 1
|
2021-02-13T14:48:45.000Z
|
2021-02-13T14:48:45.000Z
|
MuNu.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
MuNu.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- An investigation of nested fixpoints of the form μX.νY.… in Agda
------------------------------------------------------------------------
module MuNu where
open import Codata.Musical.Notation
import Codata.Musical.Colist as Colist
open import Codata.Musical.Stream
open import Data.Digit
open import Data.Empty
open import Data.List using (List; _∷_; [])
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (¬_)
-- Christophe Raffalli discusses (essentially) the type μO. νZ. Z + O
-- in his thesis. If Z is read as zero and O as one, then this type
-- contains bit sequences of the form (0^⋆1)^⋆0^ω.
-- It is interesting to note that currently it is not possible to
-- encode this type directly in Agda. One might believe that the
-- following definition should work. First we define the inner
-- greatest fixpoint:
data Z (O : Set) : Set where
[0] : ∞ (Z O) → Z O
[1] : O → Z O
-- Then we define the outer least fixpoint:
data O : Set where
↓ : Z O → O
-- However, it is still possible to define values of the form (01)^ω:
01^ω : O
01^ω = ↓ ([0] (♯ [1] 01^ω))
-- The reason is the way the termination/productivity checker works:
-- it accepts definitions by guarded corecursion as long as the guard
-- contains at least one occurrence of ♯_, no matter how the types
-- involved are defined. In effect ∞ has global reach. The mistake
-- done above was believing that O is defined to be a least fixpoint.
-- The type O really corresponds to νZ. μO. Z + O, i.e. (1^⋆0)^ω:
data O′ : Set where
[0] : ∞ O′ → O′
[1] : O′ → O′
mutual
O→O′ : O → O′
O→O′ (↓ z) = ZO→O′ z
ZO→O′ : Z O → O′
ZO→O′ ([0] z) = [0] (♯ ZO→O′ (♭ z))
ZO→O′ ([1] o) = [1] (O→O′ o)
mutual
O′→O : O′ → O
O′→O o = ↓ (O′→ZO o)
O′→ZO : O′ → Z O
O′→ZO ([0] o) = [0] (♯ O′→ZO (♭ o))
O′→ZO ([1] o) = [1] (O′→O o)
-- If O had actually encoded the type μO. νZ. Z + O, then we could
-- have proved the following theorem:
mutual
⟦_⟧O : O → Stream Bit
⟦ ↓ z ⟧O = ⟦ z ⟧Z
⟦_⟧Z : Z O → Stream Bit
⟦ [0] z ⟧Z = 0b ∷ ♯ ⟦ ♭ z ⟧Z
⟦ [1] o ⟧Z = 1b ∷ ♯ ⟦ o ⟧O
Theorem : Set
Theorem = ∀ o → ¬ (head ⟦ o ⟧O ≡ 0b × head (tail ⟦ o ⟧O) ≡ 1b ×
tail (tail ⟦ o ⟧O) ≈ ⟦ o ⟧O)
-- This would have been unfortunate, though:
inconsistency : Theorem → ⊥
inconsistency theorem = theorem 01^ω (refl , refl , proof)
where
proof : tail (tail ⟦ 01^ω ⟧O) ≈ ⟦ 01^ω ⟧O
proof = refl ∷ ♯ (refl ∷ ♯ proof)
-- Using the following elimination principle we can prove the theorem:
data ⇑ {O} (P : O → Set) : Z O → Set where
[0] : ∀ {z} → ∞ (⇑ P (♭ z)) → ⇑ P ([0] z)
[1] : ∀ {o} → P o → ⇑ P ([1] o)
O-Elim : Set₁
O-Elim = (P : O → Set) → (∀ {z} → ⇑ P z → P (↓ z)) → (o : O) → P o
theorem : O-Elim → Theorem
theorem O-elim = O-elim P helper
where
P : O → Set
P o = ¬ (head ⟦ o ⟧O ≡ 0b × head (tail ⟦ o ⟧O) ≡ 1b ×
tail (tail ⟦ o ⟧O) ≈ ⟦ o ⟧O)
helper : ∀ {z} → ⇑ P z → P (↓ z)
helper ([1] p) (() , eq₂ , eq₃)
helper ([0] p) (refl , eq₂ , eq₃) =
hlp _ eq₂ (head-cong eq₃) (tail-cong eq₃) (♭ p)
where
hlp : ∀ z → head ⟦ z ⟧Z ≡ 1b →
head (tail ⟦ z ⟧Z) ≡ 0b →
tail (tail ⟦ z ⟧Z) ≈ ⟦ z ⟧Z →
⇑ P z → ⊥
hlp .([0] _) () eq₂ eq₃ ([0] p)
hlp .([1] _) eq₁ eq₂ eq₃ ([1] p) =
p (eq₂ , head-cong eq₃ , tail-cong eq₃)
-- Fortunately it appears as if we cannot prove this elimination
-- principle. The following code is not accepted by the termination
-- checker:
{-
mutual
O-elim : O-Elim
O-elim P hyp (↓ z) = hyp (Z-elim P hyp z)
Z-elim : (P : O → Set) →
(∀ {z} → ⇑ P z → P (↓ z)) →
(z : Z O) → ⇑ P z
Z-elim P hyp ([0] z) = [0] (♯ Z-elim P hyp (♭ z))
Z-elim P hyp ([1] o) = [1] (O-elim P hyp o)
-}
-- If hyp were known to be contractive, then the code above would be
-- correct (if not accepted by the termination checker). This is not
-- the case in theorem above.
| 28.78169
| 72
| 0.537069
|
cbbefe66809fca43551aaf7033dc5657c03d9537
| 4,420
|
agda
|
Agda
|
Syntax/Transitivity.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Syntax/Transitivity.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Syntax/Transitivity.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Syntax.Transitivity where
import Lvl
open import Logic
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Type
private variable ℓ₁ ℓ₂ ℓ₃ : Lvl.Level
private variable T : Type{ℓ₁}
-- The transitivity operator
infixl 1000 _🝖_
_🝖_ : ∀{_▫_ : T → T → Stmt{ℓ₂}} → ⦃ _ : Transitivity(_▫_) ⦄ → Names.Transitivity(_▫_)
_🝖_ {_▫_ = _▫_} = transitivity(_▫_)
_🝖-subₗ_ : ∀{_▫₁_ : T → T → Stmt{ℓ₂}}{_▫₂_ : T → T → Stmt{ℓ₃}} → ⦃ _ : Subtransitivityₗ(_▫₁_)(_▫₂_) ⦄ → Names.Subtransitivityₗ(_▫₁_)(_▫₂_)
_🝖-subₗ_ {_▫₁_ = _▫₁_} {_▫₂_ = _▫₂_} = subtransitivityₗ(_▫₁_)(_▫₂_)
_🝖-subᵣ_ : ∀{_▫₁_ : T → T → Stmt{ℓ₂}}{_▫₂_ : T → T → Stmt{ℓ₃}} → ⦃ _ : Subtransitivityᵣ(_▫₁_)(_▫₂_) ⦄ → Names.Subtransitivityᵣ(_▫₁_)(_▫₂_)
_🝖-subᵣ_ {_▫₁_ = _▫₁_} {_▫₂_ = _▫₂_} = subtransitivityᵣ(_▫₁_)(_▫₂_)
-- Syntax for "equational reasoning" for reflexive-transitive relation
infixr 1 _🝖[_]-[_]_
_🝖[_]-[_]_ : (x : T) → ∀{y z : T} → (_▫_ : T → T → Stmt{ℓ₂}) → ⦃ _ : Transitivity(_▫_) ⦄ → (x ▫ y) → (y ▫ z) → (x ▫ z)
_🝖[_]-[_]_ (_)(_▫_) = transitivity(_▫_)
infixr 1 _🝖[_]-[_]-sym_
_🝖[_]-[_]-sym_ : (x : T) → ∀{y z : T} → (_▫_ : T → T → Stmt{ℓ₂}) → ⦃ _ : Transitivity(_▫_) ⦄ → ⦃ _ : Symmetry(_▫_) ⦄ → (y ▫ x) → (y ▫ z) → (x ▫ z)
_🝖[_]-[_]-sym_ (_)(_▫_) yx yz = transitivity(_▫_) (symmetry(_▫_) yx) (yz)
infixr 1 _🝖[_]-[_]-sub_
_🝖[_]-[_]-sub_ : (x : T) → ∀{y z : T}{_▫₁_ : T → T → Stmt{ℓ₂}} (_▫₂_ : T → T → Stmt{ℓ₃}) → ⦃ _ : Subtransitivityₗ(_▫₁_)(_▫₂_) ⦄ → (x ▫₂ y) → (y ▫₁ z) → (x ▫₁ z)
_🝖[_]-[_]-sub_ (_) {_▫₁_ = _▫₁_} (_▫₂_) = subtransitivityₗ(_▫₁_)(_▫₂_)
infixr 1 _🝖[_]-[_]-super_
_🝖[_]-[_]-super_ : (x : T) → ∀{y z : T} (_▫₁_ : T → T → Stmt{ℓ₂}) {_▫₂_ : T → T → Stmt{ℓ₃}} → ⦃ _ : Subtransitivityᵣ(_▫₁_)(_▫₂_) ⦄ → (x ▫₁ y) → (y ▫₂ z) → (x ▫₁ z)
_🝖[_]-[_]-super_ (_) (_▫₁_) {_▫₂_ = _▫₂_} = subtransitivityᵣ(_▫₁_)(_▫₂_)
infixr 1 _🝖[_]-[]_
_🝖[_]-[]_ : (x : T) → ∀{y : T} → (_▫_ : T → T → Stmt{ℓ₂}) → (x ▫ y) → (x ▫ y)
_🝖[_]-[]_ (_)(_▫_) xy = xy
infixr 2 _🝖-semiend_🝖[_]-end-from-[_]
_🝖-semiend_🝖[_]-end-from-[_] : (x y : T) → (_▫_ : T → T → Stmt{ℓ₂}) → ⦃ _ : Transitivity(_▫_) ⦄ → (x ▫ y) → (x ▫ y)
_🝖-semiend_🝖[_]-end-from-[_] _ _ (_▫_) xy = xy
infixr 2 _🝖[_]-end
_🝖[_]-end : (x : T) → (_▫_ : T → T → Stmt{ℓ₂}) → ⦃ _ : Reflexivity(_▫_) ⦄ → (x ▫ x)
_🝖[_]-end (_)(_▫_) = reflexivity(_▫_)
-- Syntax for "equational reasoning" for reflexive-transitive relations.
-- Example:
-- import Lvl
-- open import Logic
-- open import Structure.Relator.Properties
-- open import Type
-- postulate ℓ₁ ℓ₂ : Lvl.Level
-- postulate T : Type{ℓ₁}
-- postulate _▫_ : T → T → Stmt{ℓ₂}
-- instance postulate trans : Transitivity(_▫_)
-- instance postulate sym : Symmetry (_▫_)
-- instance postulate refl : Reflexivity (_▫_)
-- postulate a b c e : T
-- d = c
-- postulate ab : (a ▫ b)
-- postulate cb : (c ▫ b)
-- postulate de : (d ▫ e)
--
-- ac : (a ▫ e)
-- ac =
-- a 🝖-[ ab ]
-- b 🝖-[ cb ]-sym
-- c 🝖-[]
-- d 🝖-[ de ]
-- e 🝖-end
infixr 1 _🝖-[_]_
_🝖-[_]_ : (x : T) → ∀{y z : T}{_▫_ : T → T → Stmt{ℓ₂}} → ⦃ _ : Transitivity(_▫_) ⦄ → (x ▫ y) → (y ▫ z) → (x ▫ z)
_🝖-[_]_ (_) {_▫_ = _▫_} = transitivity(_▫_)
infixr 1 _🝖-[_]-sym_
_🝖-[_]-sym_ : (x : T) → ∀{y z : T}{_▫_ : T → T → Stmt{ℓ₂}} → ⦃ _ : Transitivity(_▫_) ⦄ → ⦃ _ : Symmetry(_▫_) ⦄ → (y ▫ x) → (y ▫ z) → (x ▫ z)
_🝖-[_]-sym_ (_) {_▫_ = _▫_} yx yz = transitivity(_▫_) (symmetry(_▫_) yx) (yz)
infixr 1 _🝖-[_]-sub_
_🝖-[_]-sub_ : (x : T) → ∀{y z : T}{_▫₁_ : T → T → Stmt{ℓ₂}}{_▫₂_ : T → T → Stmt{ℓ₃}} → ⦃ _ : Subtransitivityₗ(_▫₁_)(_▫₂_) ⦄ → (x ▫₂ y) → (y ▫₁ z) → (x ▫₁ z)
_🝖-[_]-sub_ (_) {_▫₁_ = _▫₁_} {_▫₂_ = _▫₂_} = subtransitivityₗ(_▫₁_)(_▫₂_)
infixr 1 _🝖-[_]-super_
_🝖-[_]-super_ : (x : T) → ∀{y z : T}{_▫₁_ : T → T → Stmt{ℓ₂}}{_▫₂_ : T → T → Stmt{ℓ₃}} → ⦃ _ : Subtransitivityᵣ(_▫₁_)(_▫₂_) ⦄ → (x ▫₁ y) → (y ▫₂ z) → (x ▫₁ z)
_🝖-[_]-super_ (_) {_▫₁_ = _▫₁_} {_▫₂_ = _▫₂_} = subtransitivityᵣ(_▫₁_)(_▫₂_)
infixr 1 _🝖-[]_
_🝖-[]_ : (x : T) → ∀{y : T}{_▫_ : T → T → Stmt{ℓ₂}} → (x ▫ y) → (x ▫ y)
_🝖-[]_ (_) xy = xy
infixr 2 _🝖-semiend_🝖-end-from-[_]
_🝖-semiend_🝖-end-from-[_] : (x y : T) → ∀{_▫_ : T → T → Stmt{ℓ₂}} → ⦃ _ : Transitivity(_▫_) ⦄ → (x ▫ y) → (x ▫ y)
_🝖-semiend_🝖-end-from-[_] _ _ {_▫_ = _▫_} xy = xy
infixr 2 _🝖-end
_🝖-end : (x : T) → ∀{_▫_ : T → T → Stmt{ℓ₂}} → ⦃ _ : Reflexivity(_▫_) ⦄ → (x ▫ x)
_🝖-end x {_▫_} = reflexivity(_▫_)
-- syntax _🝖-[]_ a {b} ab = a 🝖-[ ab ]-end b
| 39.464286
| 163
| 0.505204
|
2958e237b58ba940b6a2a79eba57e977c054eabb
| 3,809
|
agda
|
Agda
|
src/lift.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 328
|
2018-09-14T20:06:09.000Z
|
2022-03-26T10:33:07.000Z
|
src/lift.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 123
|
2018-09-17T10:53:20.000Z
|
2022-01-12T03:51:28.000Z
|
src/lift.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 34
|
2018-09-17T11:51:36.000Z
|
2022-02-20T18:33:16.000Z
|
{- functions related to lift types. The main function is do-lift, which
is called from hnf -}
module lift where
open import ial
open import cedille-types
open import ctxt
open import syntax-util
open import subst
open import erase
liftingType-to-kind : liftingType → kind
liftingType-to-kind (LiftArrow l1 l2) = KndArrow (liftingType-to-kind l1) (liftingType-to-kind l2)
liftingType-to-kind (LiftStar _) = star
liftingType-to-kind (LiftParens _ l _) = liftingType-to-kind l
liftingType-to-kind (LiftTpArrow tp l) = KndTpArrow tp (liftingType-to-kind l)
liftingType-to-kind (LiftPi _ x tp l) = KndPi posinfo-gen posinfo-gen x (Tkt tp) (liftingType-to-kind l)
liftingType-to-type : var → liftingType → type
liftingType-to-type X (LiftArrow l1 l2) = TpArrow (liftingType-to-type X l1) NotErased (liftingType-to-type X l2)
liftingType-to-type X (LiftTpArrow tp l) = TpArrow tp NotErased (liftingType-to-type X l)
liftingType-to-type X (LiftStar _) = TpVar posinfo-gen X
liftingType-to-type X (LiftParens _ l _) = liftingType-to-type X l
liftingType-to-type X (LiftPi _ x tp l) = Abs posinfo-gen Pi posinfo-gen x (Tkt tp) (liftingType-to-type X l)
{- create a type-level redex of the form
(↑ X . (λ xs . t) : ls → l) xs
where xs and ls are packaged as the input list of tuples, l is the
input liftingType, and t is the input term. -}
lift-freeze : var → 𝕃 (var × liftingType) → liftingType → term → type
lift-freeze X tobind l t =
let xs = map fst tobind in
TpApp* (Lft posinfo-gen posinfo-gen X (Lam* xs t) (LiftArrow* (map snd tobind) l))
(map (λ p → TpVar posinfo-gen (fst p)) tobind)
do-liftargs : ctxt → type → liftingType → 𝕃 term → var → 𝕃 (var × liftingType) → type
do-liftargs Γ tp (LiftArrow l1 l2) (arg :: args) X tobind =
do-liftargs Γ (TpApp tp (lift-freeze X tobind l1 arg)) l2 args X tobind
do-liftargs Γ tp (LiftTpArrow l1 l2) (arg :: args) X tobind =
do-liftargs Γ (TpAppt tp arg) l2 args X tobind
do-liftargs Γ tp (LiftPi _ x _ l) (arg :: args) X tobind =
do-liftargs Γ (TpAppt tp arg) (subst Γ arg x l) args X tobind
do-liftargs Γ tp (LiftParens _ l _) args X tobind = do-liftargs Γ tp l args X tobind
do-liftargs Γ tp _ _ _ _ = tp
-- tobind are the variables we have seen going through the lifting type (they are also mapped by the trie)
do-lifth : ctxt → trie liftingType →
𝕃 (var × liftingType) → type → var → liftingType →
(term → term) → -- function to put terms in hnf
term →
type
do-lifth Γ m tobind origtp X (LiftParens _ l _) hnf t = do-lifth Γ m tobind origtp X l hnf t
do-lifth Γ m tobind origtp X (LiftArrow l1 l2) hnf (Lam _ _ _ x _ t) =
do-lifth Γ (trie-insert m x l1) ((x , l1) :: tobind) origtp X l2 hnf t
do-lifth Γ m tobind origtp X (LiftTpArrow tp l2) hnf (Lam _ _ _ x _ t) =
TpLambda posinfo-gen posinfo-gen x (Tkt tp) (do-lifth Γ m tobind origtp X l2 hnf t)
do-lifth Γ m tobind origtp X l hnf t with decompose-apps (hnf t)
do-lifth Γ m tobind origtp X l hnf t | (Var _ x) , args with trie-lookup m x
do-lifth Γ m tobind origtp X l hnf t | (Var _ x) , args | nothing = origtp -- the term being lifted is not headed by one of the bound vars
do-lifth Γ m tobind origtp X l hnf t | (Var _ x) , args | just l' =
rebind tobind (do-liftargs Γ (TpVar posinfo-gen x) l' (erase-term-args args) X tobind)
where rebind : 𝕃 (var × liftingType) → type → type
rebind ((x , l'):: xs) tp = rebind xs (TpLambda posinfo-gen posinfo-gen x (Tkk (liftingType-to-kind l')) tp)
rebind [] tp = tp
do-lifth Γ m tobind origtp X l hnf t | _ , args = origtp
-- lift a term to a type at the given liftingType, if possible.
do-lift : ctxt → type → var → liftingType → (term → term) {- hnf -} → term → type
do-lift Γ origtp X l hnf t = do-lifth Γ empty-trie [] origtp X l hnf t
| 52.178082
| 138
| 0.683381
|
41757fc04fbf25d90f09318e92b2f2a35e17c9cb
| 5,880
|
agda
|
Agda
|
Cubical/Homotopy/Group/S3.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Group/S3.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Group/S3.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.S3 where
{-
This file contains a summary of what remains for π₄S³≅ℤ/2 to be proved.
See the module π₄S³ at the end of this file.
-}
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Data.Nat
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.Int
renaming (_·_ to _·ℤ_ ; _+_ to _+ℤ_)
open import Cubical.Homotopy.Group.Base
open import Cubical.Homotopy.HopfInvariant.Base
open import Cubical.Homotopy.HopfInvariant.Homomorphism
open import Cubical.Homotopy.HopfInvariant.HopfMap
open import Cubical.Homotopy.Whitehead
open import Cubical.Algebra.Group.Instances.IntMod
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.Sn
open import Cubical.HITs.SetTruncation
open import Cubical.Algebra.Group
renaming (ℤ to ℤGroup ; Bool to BoolGroup ; Unit to UnitGroup)
open import Cubical.Algebra.Group.ZAction
[_]× : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ π' (suc n) X × π' (suc m) X → π' (suc (n + m)) X
[_]× (f , g) = [ f ∣ g ]π'
-- Some type abbreviations (unproved results)
π₃S²-gen : Type
π₃S²-gen = gen₁-by (π'Gr 2 (S₊∙ 2)) ∣ HopfMap ∣₂
π₄S³≅ℤ/something : GroupEquiv ℤGroup (π'Gr 2 (S₊∙ 2))
→ Type
π₄S³≅ℤ/something eq =
GroupIso (π'Gr 3 (S₊∙ 3))
(ℤ/ abs (invEq (fst eq)
[ ∣ idfun∙ _ ∣₂ , ∣ idfun∙ _ ∣₂ ]×))
miniLem₁ : Type
miniLem₁ = (g : ℤ) → gen₁-by ℤGroup g → (g ≡ 1) ⊎ (g ≡ -1)
miniLem₂ : Type
miniLem₂ = (ϕ : GroupEquiv ℤGroup ℤGroup) (g : ℤ)
→ (abs g ≡ abs (fst (fst ϕ) g))
-- some minor group lemmas
groupLem-help : miniLem₁ → (g : ℤ) →
gen₁-by ℤGroup g →
(ϕ : GroupHom ℤGroup ℤGroup) →
(fst ϕ g ≡ pos 1) ⊎ (fst ϕ g ≡ negsuc 0)
→ isEquiv (fst ϕ)
groupLem-help grlem1 g gen ϕ = main (grlem1 g gen)
where
isEquiv- : isEquiv (-_)
isEquiv- = isoToIsEquiv (iso -_ -_ -Involutive -Involutive)
lem : fst ϕ (pos 1) ≡ pos 1 → fst ϕ ≡ idfun _
lem p = funExt lem2
where
lem₁ : (x₁ : ℕ) → fst ϕ (pos x₁) ≡ idfun ℤ (pos x₁)
lem₁ zero = IsGroupHom.pres1 (snd ϕ)
lem₁ (suc zero) = p
lem₁ (suc (suc n)) =
IsGroupHom.pres· (snd ϕ) (pos (suc n)) 1
∙ cong₂ _+ℤ_ (lem₁ (suc n)) p
lem2 : (x₁ : ℤ) → fst ϕ x₁ ≡ idfun ℤ x₁
lem2 (pos n) = lem₁ n
lem2 (negsuc zero) =
IsGroupHom.presinv (snd ϕ) 1 ∙ cong (λ x → pos 0 - x) p
lem2 (negsuc (suc n)) =
(cong (fst ϕ) (sym (+Comm (pos 0) (negsuc (suc n))))
∙ IsGroupHom.presinv (snd ϕ) (pos (suc (suc n))))
∙∙ +Comm (pos 0) _
∙∙ cong (-_) (lem₁ (suc (suc n)))
lem₂ : fst ϕ (negsuc 0) ≡ pos 1 → fst ϕ ≡ -_
lem₂ p = funExt lem2
where
s = IsGroupHom.presinv (snd ϕ) (negsuc 0)
∙∙ +Comm (pos 0) _
∙∙ cong -_ p
lem2 : (n : ℤ) → fst ϕ n ≡ - n
lem2 (pos zero) = IsGroupHom.pres1 (snd ϕ)
lem2 (pos (suc zero)) = s
lem2 (pos (suc (suc n))) =
IsGroupHom.pres· (snd ϕ) (pos (suc n)) 1
∙ cong₂ _+ℤ_ (lem2 (pos (suc n))) s
lem2 (negsuc zero) = p
lem2 (negsuc (suc n)) =
IsGroupHom.pres· (snd ϕ) (negsuc n) (negsuc 0)
∙ cong₂ _+ℤ_ (lem2 (negsuc n)) p
main : (g ≡ pos 1) ⊎ (g ≡ negsuc 0)
→ (fst ϕ g ≡ pos 1) ⊎ (fst ϕ g ≡ negsuc 0)
→ isEquiv (fst ϕ)
main (inl p) =
J (λ g p → (fst ϕ g ≡ pos 1)
⊎ (fst ϕ g ≡ negsuc 0) → isEquiv (fst ϕ))
(λ { (inl x) → subst isEquiv (sym (lem x)) (snd (idEquiv _))
; (inr x) → subst isEquiv
(sym (lem₂ (IsGroupHom.presinv (snd ϕ) (pos 1)
∙ (cong (λ x → pos 0 - x) x))))
isEquiv- })
(sym p)
main (inr p) =
J (λ g p → (fst ϕ g ≡ pos 1)
⊎ (fst ϕ g ≡ negsuc 0) → isEquiv (fst ϕ))
(λ { (inl x) → subst isEquiv (sym (lem₂ x)) isEquiv-
; (inr x) → subst isEquiv
(sym (lem (
IsGroupHom.presinv (snd ϕ) (negsuc 0)
∙ cong (λ x → pos 0 - x) x)))
(snd (idEquiv _))})
(sym p)
groupLem : {G : Group₀}
→ miniLem₁
→ GroupEquiv ℤGroup G
→ (g : fst G)
→ gen₁-by G g
→ (ϕ : GroupHom G ℤGroup)
→ (fst ϕ g ≡ 1) ⊎ (fst ϕ g ≡ -1)
→ isEquiv (fst ϕ)
groupLem {G = G} s =
GroupEquivJ
(λ G _ → (g : fst G)
→ gen₁-by G g
→ (ϕ : GroupHom G ℤGroup)
→ (fst ϕ g ≡ 1) ⊎ (fst ϕ g ≡ -1)
→ isEquiv (fst ϕ))
(groupLem-help s)
-- summary
module π₄S³
(mini-lem₁ : miniLem₁)
(mini-lem₂ : miniLem₂)
(ℤ≅π₃S² : GroupEquiv ℤGroup (π'Gr 2 (S₊∙ 2)))
(gen-by-HopfMap : π₃S²-gen)
(π₄S³≅ℤ/whitehead : π₄S³≅ℤ/something ℤ≅π₃S²)
(hopfWhitehead :
abs (HopfInvariant-π' 0
([ (∣ idfun∙ _ ∣₂ , ∣ idfun∙ _ ∣₂) ]×))
≡ 2)
where
π₄S³ = π'Gr 3 (S₊∙ 3)
hopfInvariantEquiv : GroupEquiv (π'Gr 2 (S₊∙ 2)) ℤGroup
fst (fst hopfInvariantEquiv) = HopfInvariant-π' 0
snd (fst hopfInvariantEquiv) =
groupLem mini-lem₁ ℤ≅π₃S² ∣ HopfMap ∣₂
gen-by-HopfMap
(GroupHom-HopfInvariant-π' 0)
(abs→⊎ _ _ HopfInvariant-HopfMap)
snd hopfInvariantEquiv = snd (GroupHom-HopfInvariant-π' 0)
lem : ∀ {G : Group₀} (ϕ ψ : GroupEquiv ℤGroup G) (g : fst G)
→ abs (invEq (fst ϕ) g) ≡ abs (invEq (fst ψ) g)
lem =
GroupEquivJ
(λ G ϕ → (ψ : GroupEquiv ℤGroup G) (g : fst G)
→ abs (invEq (fst ϕ) g) ≡ abs (invEq (fst ψ) g))
λ ψ → mini-lem₂ (invGroupEquiv ψ)
main : GroupIso π₄S³ (ℤ/ 2)
main = subst (GroupIso π₄S³)
(cong (ℤ/_) (lem ℤ≅π₃S² (invGroupEquiv (hopfInvariantEquiv)) _
∙ hopfWhitehead))
π₄S³≅ℤ/whitehead
| 32.131148
| 77
| 0.553061
|
4d0a72b9091f9b5703fc6f7922d01707015af67f
| 12,631
|
agda
|
Agda
|
LP/Terms.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
LP/Terms.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
LP/Terms.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
open import Signature
-- | In this module, we construct the free monad and the free completely
-- iterative monad over a signature Σ (see Aczel, Adamek, Milius and Velebil).
-- The first assigns to a set V of variables the set TV of finite terms over Σ
-- (that is, finite trees labelled with symbols in f ∈ ∥Σ∥ and ar(f) branching).
-- The second extends this to also allow for infinite trees, the set of those
-- is then denoted by T∞(V).
-- Categorically, T(V) is the initial (Σ + V)-algebra, whereas T∞(V) is the
-- final (Σ + V)-coalgebra.
module Terms (Σ : Sig) where
open import Function
open import Data.Empty
open import Data.Unit hiding (_≤_)
open import Data.Product as Prod renaming (Σ to ⨿)
open import Data.Nat as Nat
open import Data.Sum as Sum
open import Relation.Binary.PropositionalEquality hiding ([_])
open ≡-Reasoning
open import Relation.Binary hiding (_⇒_)
open import Relation.Unary hiding (_⇒_)
import Streams as Str
open import Streams hiding (corec)
-- | Natural transformations
Nat : (Set → Set) → (Set → Set) → Set₁
Nat F G = ∀{X} → F X → G X
Id : Set → Set
Id = id
least : {X : Set} (_⊑_ : Rel X _) (P : X → Set) → X → Set
least _⊑_ P x = (P x) × (∀ {y} → P y → x ⊑ y)
least-unique : {X : Set} {_⊑_ : Rel X _} → (IsTotalOrder _≡_ _⊑_) →
{P : X → Set} → (x y : X) → least _⊑_ P x → least _⊑_ P y → x ≡ y
least-unique isTO x y (p , l₁) (q , l₂) with IsTotalOrder.total isTO x y
least-unique isTO x y (p , l₁) (q , l₂) | inj₁ x⊑y =
IsTotalOrder.antisym isTO x⊑y (l₂ p)
least-unique isTO x y (p , l₁) (q , l₂) | inj₂ y⊑x =
IsTotalOrder.antisym isTO (l₁ q) y⊑x
infixr 1 _⇒_
_⇒_ = Nat
data T (V : Set) : Set where
sup : ⟪ Σ ⟫ (T V) ⊎ V → T V
rec : ∀{V X} → (f : ⟪ Σ ⟫ X ⊎ V → X) → T V → X
rec f (sup (inj₁ (s , α))) = f (inj₁ (s , λ i → rec f (α i)))
rec f (sup (inj₂ y)) = f (inj₂ y)
rec-hom : ∀{V X} → (f : ⟪ Σ ⟫ X ⊎ V → X) (u : ⟪ Σ ⟫ (T V) ⊎ V) →
rec f (sup u) ≡ f (Sum.map (⟪ Σ ⟫₁ (rec f)) id u)
rec-hom f (inj₁ (s , α)) = cong (λ u → f (inj₁ (s , u))) refl
rec-hom f (inj₂ v) = refl
-- | Functor T, on morphisms
T₁ : ∀ {V W} → (V → W) → T V → T W
T₁ f = rec (sup ∘ Sum.map id f)
η : Id ⇒ T
η = sup ∘ inj₂
μ : T ∘ T ⇒ T
μ {V} = rec f
where
f : ⟪ Σ ⟫ (T V) ⊎ T V → T V
f = [ sup ∘ inj₁ , id ]
-- | First monad law
postulate unitᵣ : ∀{V} {t : T V} → μ (T₁ η t) ≡ t
{-
unitᵣ {V} {t} =
begin
μ (T₁ η t)
≡⟨ {!!} ⟩
t
∎
-}
-- | T is free over Σ with inclusion
ι : ⟪ Σ ⟫ ⇒ T
ι = sup ∘ inj₁ ∘ ⟪ Σ ⟫₁ η
postulate T₁-top-sym : ∀{V W} (f : V → W) (s : ∥ Σ ∥) (α : ar Σ s → T V) →
T₁ f (μ (ι (s , α))) ≡ μ (ι (s , T₁ f ∘ α))
-- T₁-top-sym = {!!}
-- | Kleisli morphsims for T∞ V
Subst : Set → Set → Set
Subst V W = V → T W
infixr 9 _•_
-- | Kleisli composition
_•_ : ∀ {U V W} → Subst V W → Subst U V → Subst U W
τ • σ = μ ∘ T₁ τ ∘ σ
-- | Application of substitutions to infinite terms
app : ∀ {V W} → Subst V W → T V → T W
app σ = μ ∘ T₁ σ
infixl 1 _≡ₛ_
_≡ₛ_ : ∀{V W} → Rel (Subst V W) _
σ ≡ₛ τ = ∀ {v} → σ v ≡ τ v
-- | Order on subsitutions
_⊑_ : ∀{V W} → Rel (Subst V W) _
σ₁ ⊑ σ₂ = ∃ λ σ → σ • σ₁ ≡ₛ σ₂
matches : ∀{V W} → T V → T W → Subst V W → Set
matches t s σ = app σ t ≡ s
-- | Most general matcher
mgm : ∀{V W} → T V → T W → Subst V W → Set
mgm t s = least _⊑_ (matches t s)
η-mgm : ∀{V} (t : T V) → mgm t t η
η-mgm {V} t = m , min t
where
m : matches t t η
m =
begin
app η t
≡⟨ refl ⟩
μ (T₁ η t)
≡⟨ unitᵣ ⟩
t
∎
min : {σ : Subst V V} (t : T V) → matches t t σ → η ⊑ σ
min {σ} t m with app σ t
min {σ} (sup (inj₁ y)) refl | sup (inj₁ .y) = σ , refl
min (sup (inj₁ x)) () | sup (inj₂ w)
min (sup (inj₂ v)) () | sup (inj₁ y)
min {σ} (sup (inj₂ v)) refl | sup (inj₂ .v) = σ , refl
unifies : ∀{V W} → T V → T V → Subst V W → Set
unifies t s σ = app σ t ≡ app σ s
-- | Most general unifier
mgu : ∀{V W} → T V → T V → Subst V W → Set
mgu t s = least _⊑_ (unifies t s)
-- | Free variables
fv : ∀{V} → T V → Pred V _
fv (sup (inj₁ (s , α))) v = ⨿ (Sig.ar Σ s) λ i → (fv (α i) v)
fv (sup (inj₂ v₁)) v = v₁ ≡ v
isCons : ∀{V} → Pred (T V) _
isCons (sup (inj₁ x)) = ⊤
isCons (sup (inj₂ y)) = ⊥
isVar : ∀{V} → Pred (T V) _
isVar (sup (inj₁ x)) = ⊥
isVar (sup (inj₂ y)) = ⊤
record T∞ (V : Set) : Set where
coinductive
field out : ⟪ Σ ⟫ (T∞ V) ⊎ V
open T∞ public
sum-lift : {A B : Set} (R₁ : A → A → Set) (R₂ : B → B → Set) (x y : A ⊎ B) → Set
sum-lift R₁ R₂ (inj₁ x) (inj₁ y) = R₁ x y
sum-lift R₁ R₂ (inj₁ x) (inj₂ y) = ⊥
sum-lift R₁ R₂ (inj₂ x) (inj₁ y) = ⊥
sum-lift R₁ R₂ (inj₂ x) (inj₂ y) = R₂ x y
~-data : ∀{V} (R : T∞ V → T∞ V → Set) (u w : ⟪ Σ ⟫ (T∞ V) ⊎ V) → Set
~-data R = sum-lift (sig-lift R) _≡_
record _~_ {V : Set} (t s : T∞ V) : Set where
coinductive
field out~ : ~-data _~_ (out t) (out s)
open _~_ public
corec : ∀{V X} → (f : X → ⟪ Σ ⟫ X ⊎ V) → X → T∞ V
out (corec f x) with f x
... | inj₁ (s , α) = inj₁ (s , (λ i → corec f (α i)))
... | inj₂ v = inj₂ v
prim-corec : ∀{V X} → (f : X → ⟪ Σ ⟫ X ⊎ V ⊎ T∞ V) → X → T∞ V
out (prim-corec {V} {X} f x) with f x
... | inj₁ (s , α) = inj₁ (s , (λ i → prim-corec f (α i)))
... | inj₂ (inj₁ v) = inj₂ v
... | inj₂ (inj₂ t) = out t
sup∞ : ∀{V} → ⟪ Σ ⟫ (T∞ V) ⊎ V → T∞ V
out (sup∞ (inj₁ u)) = inj₁ u
out (sup∞ (inj₂ v)) = inj₂ v
-- | Functor T∞, on morphisms
T∞₁ : ∀ {V W} → (V → W) → T∞ V → T∞ W
T∞₁ f = corec (Sum.map id f ∘ out)
η∞ : Id ⇒ T∞
η∞ = sup∞ ∘ inj₂
μ∞ : T∞ ∘ T∞ ⇒ T∞
μ∞ {V} = corec f
where
g : T∞ V → ⟪ Σ ⟫ (T∞ (T∞ V)) ⊎ V
g = Sum.map (⟪ Σ ⟫₁ η∞) id ∘ out
f : T∞ (T∞ V) → ⟪ Σ ⟫ (T∞ (T∞ V)) ⊎ V
f = [ inj₁ , g ] ∘ out
ι∞ : ⟪ Σ ⟫ ⇒ T∞
ι∞ {V} = g ∘ inj₁
where
g : ⟪ Σ ⟫ V ⊎ T∞ V → T∞ V
g = prim-corec [ inj₁ ∘ ⟪ Σ ⟫₁ (inj₂ ∘ η∞) , inj₂ ∘ inj₂ ]
-- | T is a submonad of T∞
χ : T ⇒ T∞
χ = rec sup∞
-- | Kleisli morphsims for T∞ V
Subst∞ : Set → Set → Set
Subst∞ V W = V → T∞ W
infixl 1 _≡ₛ∞_
_≡ₛ∞_ : ∀{V W} → Rel (Subst∞ V W) _
σ ≡ₛ∞ τ = ∀ {v} → σ v ~ τ v
infixr 9 _•∞_
-- | Kleisli composition
_•∞_ : ∀ {U V W} → Subst∞ V W → Subst∞ U V → Subst∞ U W
τ •∞ σ = μ∞ ∘ T∞₁ τ ∘ σ
-- | Application of substitutions to infinite terms
app∞ : ∀ {V W} → Subst∞ V W → T∞ V → T∞ W
app∞ σ = μ∞ ∘ T∞₁ σ
isVar∞ : ∀{V} → Pred (T∞ V) _
isVar∞ t with out t
isVar∞ t | inj₁ x = ⊥
isVar∞ t | inj₂ v = ⊤
varNowOrLater : ∀{V} → (T∞ V → Pred V _) → T∞ V → Pred V _
varNowOrLater R t v with out t
... | inj₁ (f , α) = ∃ (λ i → R (α i) v)
... | inj₂ v₁ = v ≡ v₁
record fv∞ {V : Set} (t : T∞ V) (v : V) : Set where
coinductive
field isFv∞ : varNowOrLater fv∞ t v
root-matches : ∀{V} → T V → ∥ Σ ∥ → Set
root-matches (sup (inj₁ (g , _))) f = g ≡ f
root-matches (sup (inj₂ y)) f = ⊥
record RootsMatch {V : Set} (s : Stream (T V)) (f : ∥ Σ ∥) : Set where
coinductive
field
hd-match : root-matches (hd s) f
tl-match : RootsMatch (tl s) f
open RootsMatch
-- | Nasty hack: assume that RootsMatch is propositional
postulate
RootsMatch-unique : ∀{V} {s : Stream (T V)} {f : ∥ Σ ∥}
(p q : RootsMatch s f) → p ≡ q
split : {V : Set} (s : Stream (T V)) (f : ∥ Σ ∥) → RootsMatch s f →
ar Σ f → Stream (T V)
hd (split s f p i) with hd s | hd-match p
hd (split s f p i) | sup (inj₁ (.f , α)) | refl = α i
hd (split s f p i) | sup (inj₂ y) | ()
tl (split s f p i) = split (tl s) f (tl-match p) i
root-matches∞ : ∀{V} → T∞ V → ∥ Σ ∥ → Set
root-matches∞ t f with out t
root-matches∞ t f | inj₁ (g , _) = f ≡ g
root-matches∞ t f | inj₂ v = ⊥
split∞ : {V : Set} → (t : T∞ V) (f : ∥ Σ ∥) → root-matches∞ t f →
ar Σ f → T∞ V
split∞ t f p i with out t
split∞ t f refl i | inj₁ (.f , α) = α i
split∞ t f () i | inj₂ y
data AnyRootMatch {V : Set} (s : Stream (T V)) (f : ∥ Σ ∥) : Stream (T V) → Set where
match-hd : root-matches (hd s) f → AnyRootMatch s f s
match-tl : AnyRootMatch (tl s) f (tl s) → AnyRootMatch s f (tl s)
first-root-match : ∀{V} → Stream (T V) → ∥ Σ ∥ → ℕ → Set
first-root-match s f = least _≤_ (λ k → root-matches (s at k) f)
conv-branch : {V : Set} (R : Stream (T V) → T∞ V → Set) →
Stream (T V) → T∞ V → T V → ⟪ Σ ⟫ (T∞ V) ⊎ V → Set
conv-branch R s t (sup (inj₁ (f , α))) (inj₁ (g , β)) =
⨿ (f ≡ g) λ p →
⨿ (RootsMatch (tl s) f) λ q →
∀ i → R (split (tl s) f q i) (β (subst (ar Σ) p i))
conv-branch R s t (sup (inj₁ (f , α))) (inj₂ v) = ⊥
conv-branch R s t (sup (inj₂ v)) (inj₁ (f , α)) =
∃ λ s' → AnyRootMatch s f s' × R s' t
conv-branch R s t (sup (inj₂ v)) (inj₂ w) = v ≡ w × R (tl s) t
-- | A sequence s of finite terms converges to a possibly infinite term,
-- if for all i, sᵢ₊₁ = sᵢ[σ] for some substitution σ : V → T V and t = sᵢ[τ]
-- for some τ : V → T∞ V.
-- Note that this coincides with convergence in the prefix metric.
record _→∞_ {V : Set} (s : Stream (T V)) (t : T∞ V) : Set where
coinductive
field
conv-out : conv-branch _→∞_ s t (hd s) (out t)
open _→∞_ public
{-
unique-conv : ∀{V} (s : Stream (T V)) (t₁ t₂ : T∞ V) →
s →∞ t₁ → s →∞ t₂ → t₁ ~ t₂
-}
ProperlyRefining : ∀{V} → T V → Pred (Subst V V) _
ProperlyRefining t σ = ∀ v → v ∈ fv t → isCons (σ v)
record ProperlyRefiningSeq {V : Set} (t : T V) : Set where
coinductive
field
hd-ref : Subst V V
hd-is-ref : hd-ref ∈ ProperlyRefining t
tl-ref : ProperlyRefiningSeq (app hd-ref t)
open ProperlyRefiningSeq public
{-
refining-on-subterms : ∀{V f α} (t : T V) → t ≡ sup (inj₁ (f , α)) →
ProperlyRefiningSeq t →
(i : ar Σ f) → ProperlyRefiningSeq (α i)
hd-ref (refining-on-subterms ._ refl p i) = hd-ref p
hd-is-ref (refining-on-subterms ._ refl p i) = {!!}
tl-ref (refining-on-subterms ._ refl p i) = {!!} -- refining-on-subterms {!!} {!!} {!!} {!!}
-- | A non-trivial substitution is a substitution σ, such that, for all v ∈ V
-- we have that either σ(v) is a non-trivial term or if it is a variable w, then
-- w = v.
-- This allows us to stop substituting the first time we hit a variable.
NonTrivSubst : Set → Set
NonTrivSubst V = ⨿ (Subst V V) λ σ → (∀ v → isVar (σ v) → σ v ≡ η v)
term-seq-from-subst-seq : ∀{V} (t : T V) → ProperlyRefiningSeq t → Stream (T V)
hd (term-seq-from-subst-seq t Δ) = t
tl (term-seq-from-subst-seq t Δ) =
term-seq-from-subst-seq (app (hd-ref Δ) t) (tl-ref Δ)
var-app-lem : ∀{V} → (σ : Subst V V) → ∀ v → app σ (η v) ≡ σ v
var-app-lem = {!!}
∞term-from-subst-seq : ∀{V} (t : T V) → ProperlyRefiningSeq t → T∞ V
out (∞term-from-subst-seq {V} (sup (inj₁ (f , α))) Δ) = inj₁ (f , β)
where
β : ar Σ f → T∞ V
β i = ∞term-from-subst-seq
(α i)
(refining-on-subterms (sup (inj₁ (f , α))) refl Δ i)
out (∞term-from-subst-seq {V} (sup (inj₂ v)) Δ) = {!!}
-- with fv (sup (inj₂ v)) v | hd-ref Δ v | hd-is-ref Δ v refl
where
g : ∀{σ} → σ ∈ ProperlyRefining (sup (inj₂ v)) → ⟪ Σ ⟫ (T∞ V)
g {σ} p with σ v | p v refl
g p | sup (inj₁ (f , α)) | tt = f , β
where
β : ar Σ f → T∞ V
β i = ∞term-from-subst-seq
(α i)
(refining-on-subterms (sup (inj₁ (f , α)))
refl
{!!}
i)
g p | sup (inj₂ w) | ()
-}
{-
out (∞term-from-subst-seq {V} (sup (inj₂ v)) Δ) | p | sup (inj₁ (f , α)) | tt =
inj₁ (f , β {!refl!})
where
foo : hd-ref Δ v ≡ sup (inj₁ (f , α)) → app (hd-ref Δ) (sup (inj₂ v)) ≡ sup (inj₁ (f , α))
foo p =
begin
app (hd-ref Δ) (sup (inj₂ v))
≡⟨ {!!} ⟩
hd-ref Δ v
≡⟨ {!refl!} ⟩
sup (inj₁ (f , α))
∎
β : hd-ref Δ v ≡ sup (inj₁ (f , α)) → ar Σ f → T∞ V
β p i = ∞term-from-subst-seq
(α i)
(refining-on-subterms (sup (inj₁ (f , α)))
refl
(subst ProperlyRefiningSeq {!!} (tl-ref Δ))
i)
-- (app (hd-ref Δ) (η v)) (var-app-lem {!!} v)
out (∞term-from-subst-seq (sup (inj₂ v)) Δ) | p | sup (inj₂ y) | ()
-}
{-
∞term-from-subst-seq : ∀{V} → Stream (NonTrivSubst V) → T V → T∞ V
out (∞term-from-subst-seq Δ (sup (inj₁ (s , α)))) =
inj₁ (s , (λ i → ∞term-from-subst-seq Δ (α i)))
out (∞term-from-subst-seq Δ (sup (inj₂ v))) with proj₁ (hd Δ) v | proj₂ (hd Δ) v
... | sup (inj₁ (s , α)) | f =
inj₁ (s , (λ i → ∞term-from-subst-seq (tl Δ) (α i)))
... | sup (inj₂ v₁) | f with f tt
out (∞term-from-subst-seq Δ (sup (inj₂ v))) | sup (inj₂ .v) | f | refl =
inj₂ v
-}
{-
∞term-from-subst-seq-converges :
∀{V} → (Δ : Stream (NonTrivSubst V)) → (t : T V) →
term-seq-from-subst-seq Δ t →∞ ∞term-from-subst-seq Δ t
-}
| 29.790094
| 95
| 0.510253
|
4de1f3af998e6a211f94992e2cc7bd22a6308aae
| 1,648
|
agda
|
Agda
|
vendor/stdlib/src/Algebra/Props/Ring.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Algebra/Props/Ring.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Algebra/Props/Ring.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Some derivable properties
------------------------------------------------------------------------
open import Algebra
module Algebra.Props.Ring (r : Ring) where
open Ring r
import Relation.Binary.EqReasoning as EqR; open EqR setoid
open import Data.Function
open import Data.Product
-‿*-distribˡ : ∀ x y → - x * y ≈ - (x * y)
-‿*-distribˡ x y = begin
- x * y ≈⟨ sym $ proj₂ +-identity _ ⟩
- x * y + 0# ≈⟨ refl ⟨ +-pres-≈ ⟩ sym (proj₂ -‿inverse _) ⟩
- x * y + (x * y + - (x * y)) ≈⟨ sym $ +-assoc _ _ _ ⟩
- x * y + x * y + - (x * y) ≈⟨ sym (proj₂ distrib _ _ _) ⟨ +-pres-≈ ⟩ refl ⟩
(- x + x) * y + - (x * y) ≈⟨ (proj₁ -‿inverse _ ⟨ *-pres-≈ ⟩ refl)
⟨ +-pres-≈ ⟩
refl ⟩
0# * y + - (x * y) ≈⟨ proj₁ zero _ ⟨ +-pres-≈ ⟩ refl ⟩
0# + - (x * y) ≈⟨ proj₁ +-identity _ ⟩
- (x * y) ∎
-‿*-distribʳ : ∀ x y → x * - y ≈ - (x * y)
-‿*-distribʳ x y = begin
x * - y ≈⟨ sym $ proj₁ +-identity _ ⟩
0# + x * - y ≈⟨ sym (proj₁ -‿inverse _) ⟨ +-pres-≈ ⟩ refl ⟩
- (x * y) + x * y + x * - y ≈⟨ +-assoc _ _ _ ⟩
- (x * y) + (x * y + x * - y) ≈⟨ refl ⟨ +-pres-≈ ⟩ sym (proj₁ distrib _ _ _) ⟩
- (x * y) + x * (y + - y) ≈⟨ refl ⟨ +-pres-≈ ⟩ (refl ⟨ *-pres-≈ ⟩ proj₂ -‿inverse _) ⟩
- (x * y) + x * 0# ≈⟨ refl ⟨ +-pres-≈ ⟩ proj₂ zero _ ⟩
- (x * y) + 0# ≈⟨ proj₂ +-identity _ ⟩
- (x * y) ∎
| 44.540541
| 93
| 0.34466
|
1cdcf9ee56470703548729fe19980a847ad4c6c8
| 168
|
agda
|
Agda
|
data/declaration/Import.agda
|
msuperdock/agda-unused
|
f327f9aab8dcb07022b857736d8201906bba02e9
|
[
"MIT"
] | 6
|
2020-10-29T09:38:43.000Z
|
2022-03-01T16:38:05.000Z
|
data/declaration/Import.agda
|
msuperdock/agda-unused
|
f327f9aab8dcb07022b857736d8201906bba02e9
|
[
"MIT"
] | null | null | null |
data/declaration/Import.agda
|
msuperdock/agda-unused
|
f327f9aab8dcb07022b857736d8201906bba02e9
|
[
"MIT"
] | 1
|
2022-03-01T16:38:14.000Z
|
2022-03-01T16:38:14.000Z
|
module Import where
import Agda.Builtin.Bool
as _
open import Agda.Builtin.Nat
as _
import Agda.Builtin.Unit
using (⊤; tt)
A
: Set
A
= Agda.Builtin.Unit.⊤
| 11.2
| 28
| 0.690476
|
39fa0bff8bee8963a5ade5207290f887c1f28014
| 1,100
|
agda
|
Agda
|
examples/Lookup.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/Lookup.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/Lookup.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Lookup where
data Bool : Set where
false : Bool
true : Bool
data IsTrue : Bool -> Set where
isTrue : IsTrue true
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
module Map
(Key : Set)
(_==_ : Key -> Key -> Bool)
(Code : Set)
(Val : Code -> Set) where
infixr 40 _⟼_,_
infix 20 _∈_
data Map : List Code -> Set where
ε : Map []
_⟼_,_ : forall {c cs} ->
Key -> Val c -> Map cs -> Map (c :: cs)
_∈_ : forall {cs} -> Key -> Map cs -> Bool
k ∈ ε = false
k ∈ (k' ⟼ _ , m) with k == k'
... | true = true
... | false = k ∈ m
Lookup : forall {cs} -> (k : Key)(m : Map cs) -> IsTrue (k ∈ m) -> Set
Lookup k ε ()
Lookup k (_⟼_,_ {c} k' _ m) p with k == k'
... | true = Val c
... | false = Lookup k m p
lookup : {cs : List Code}(k : Key)(m : Map cs)(p : IsTrue (k ∈ m)) ->
Lookup k m p
lookup k ε ()
lookup k (k' ⟼ v , m) p with k == k'
... | true = v
... | false = lookup k m p
| 22
| 72
| 0.459091
|
31e2bb130aa20fa3e9f74fd2f0fcd0821761530e
| 11,112
|
agda
|
Agda
|
benchmark/cwf/Setoid.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
benchmark/cwf/Setoid.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
benchmark/cwf/Setoid.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
{-# OPTIONS --no-positivity-check
--no-termination-check
#-}
-- A universe setoids
module Setoid where
import Chain
record True : Set where
data False : Set where
Rel : Set -> Set1
Rel A = A -> A -> Set
Pred : Set -> Set1
Pred A = A -> Set
Resp : {A : Set} -> Rel A -> {B : Set} -> Rel B -> Pred (A -> B)
Resp _R_ _S_ f = forall x y -> x R y -> f x S f y
mutual
infixr 10 _,_
infix 40 _=El=_ _=S=_ _=Fam=_
infix 60 _!_
data Setoid : Set where
nat : Setoid
Π : (A : Setoid)(F : Fam A) -> Setoid
Σ : (A : Setoid)(F : Fam A) -> Setoid
data Fam (A : Setoid) : Set where
fam : (F : El A -> Setoid) ->
Resp _=El=_ _=S=_ F -> Fam A
data El : Setoid -> Set where
zero : El nat
suc : El nat -> El nat
ƛ : {A : Setoid}{F : Fam A}
(f : (x : El A) -> El (F ! x)) ->
((x y : El A) -> x =El= y -> f x =El= f y) -> El (Π A F)
_,_ : {A : Setoid}{F : Fam A}(x : El A) -> El (F ! x) -> El (Σ A F)
data _=S=_ : (A B : Setoid) -> Set where
eqNat : nat =S= nat
eqΠ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} ->
A₂ =S= A₁ -> F₁ =Fam= F₂ -> Π A₁ F₁ =S= Π A₂ F₂
eqΣ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} ->
A₁ =S= A₂ -> F₁ =Fam= F₂ -> Σ A₁ F₁ =S= Σ A₂ F₂
data _=El=_ : {A B : Setoid} -> El A -> El B -> Set where
eqInNat : {n : El nat} -> n =El= n
eqInΠ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂}
{f₁ : (x : El A₁) -> El (F₁ ! x)}
{pf₁ : (x y : El A₁) -> x =El= y -> f₁ x =El= f₁ y}
{f₂ : (x : El A₂) -> El (F₂ ! x)} ->
{pf₂ : (x y : El A₂) -> x =El= y -> f₂ x =El= f₂ y} ->
A₂ =S= A₁ ->
((x : El A₁)(y : El A₂) -> x =El= y -> f₁ x =El= f₂ y) ->
ƛ f₁ pf₁ =El= ƛ f₂ pf₂
eqInΣ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂}
{x₁ : El A₁}{y₁ : El (F₁ ! x₁)}
{x₂ : El A₂}{y₂ : El (F₂ ! x₂)} ->
F₁ =Fam= F₂ -> x₁ =El= x₂ -> y₁ =El= y₂ -> (x₁ , y₁) =El= (x₂ , y₂)
data _=Fam=_ {A B : Setoid}(F : Fam A)(G : Fam B) : Set where
eqFam : B =S= A -> (forall x y -> x =El= y -> F ! x =S= G ! y) -> F =Fam= G
_!_ : {A : Setoid} -> Fam A -> El A -> Setoid
fam F _ ! x = F x
-- Inversions
famEqDom : {A B : Setoid}{F : Fam A}{G : Fam B} -> F =Fam= G -> B =S= A
famEqDom (eqFam p _) = p
famEqCodom : {A B : Setoid}{F : Fam A}{G : Fam B} -> F =Fam= G ->
(x : El A)(y : El B) -> x =El= y -> F ! x =S= G ! y
famEqCodom (eqFam _ p) = p
eqΠ-inv₁ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} ->
Π A₁ F₁ =S= Π A₂ F₂ -> A₂ =S= A₁
eqΠ-inv₁ (eqΠ p _) = p
eqΠ-inv₂ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} ->
Π A₁ F₁ =S= Π A₂ F₂ -> F₁ =Fam= F₂
eqΠ-inv₂ (eqΠ _ p) = p
eqΣ-inv₁ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} ->
Σ A₁ F₁ =S= Σ A₂ F₂ -> A₁ =S= A₂
eqΣ-inv₁ (eqΣ p _) = p
eqΣ-inv₂ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} ->
Σ A₁ F₁ =S= Σ A₂ F₂ -> F₁ =Fam= F₂
eqΣ-inv₂ (eqΣ _ p) = p
-- Equivalence proofs and casts
mutual
-- _=Fam=_ is an equivalence
=Fam=-refl : {A : Setoid}{F : Fam A} -> F =Fam= F
=Fam=-refl {F = fam _ p} = eqFam =S=-refl p
=Fam=-sym : {A B : Setoid}{F : Fam A}{G : Fam B} -> F =Fam= G -> G =Fam= F
=Fam=-sym (eqFam B=A F=G) = eqFam (=S=-sym B=A) \x y x=y -> =S=-sym (F=G _ _ (=El=-sym x=y))
=Fam=-trans : {A B C : Setoid}{F : Fam A}{G : Fam B}{H : Fam C} ->
F =Fam= G -> G =Fam= H -> F =Fam= H
=Fam=-trans (eqFam B=A F=G) (eqFam C=B G=H) =
eqFam (=S=-trans C=B B=A) \x y x=y ->
=S=-trans (F=G x (B=A << x) (cast-id _))
(G=H _ y (=El=-trans (=El=-sym (cast-id _)) x=y))
-- _=S=_ is an equivalence
=S=-refl : {A : Setoid} -> A =S= A
=S=-refl {nat} = eqNat
=S=-refl {Π A F} = eqΠ =S=-refl =Fam=-refl
=S=-refl {Σ A F} = eqΣ =S=-refl =Fam=-refl
=S=-sym : {A B : Setoid} -> A =S= B -> B =S= A
=S=-sym eqNat = eqNat
=S=-sym (eqΠ pA pF) = eqΠ (=S=-sym pA) (=Fam=-sym pF)
=S=-sym (eqΣ pA pF) = eqΣ (=S=-sym pA) (=Fam=-sym pF)
=S=-trans : {A B C : Setoid} -> A =S= B -> B =S= C -> A =S= C
=S=-trans eqNat eqNat = eqNat
=S=-trans (eqΠ B=A F=G) (eqΠ C=B G=H) = eqΠ (=S=-trans C=B B=A) (=Fam=-trans F=G G=H)
=S=-trans (eqΣ A=B F=G) (eqΣ B=C G=H) = eqΣ (=S=-trans A=B B=C) (=Fam=-trans F=G G=H)
-- _=El=_ is an equivalence
=El=-refl : {A : Setoid}{x : El A} -> x =El= x
=El=-refl {nat} = eqInNat
=El=-refl {Π A F}{ƛ f pf} = eqInΠ =S=-refl pf
=El=-refl {Σ A F}{x , y} = eqInΣ =Fam=-refl =El=-refl =El=-refl
=El=-sym : {A B : Setoid}{x : El A}{y : El B} -> x =El= y -> y =El= x
=El=-sym eqInNat = eqInNat
=El=-sym (eqInΠ B=A p) = eqInΠ (=S=-sym B=A) \x y x=y -> =El=-sym (p y x (=El=-sym x=y))
=El=-sym (eqInΣ pF px py) = eqInΣ (=Fam=-sym pF) (=El=-sym px) (=El=-sym py)
=El=-trans : {A B C : Setoid}{x : El A}{y : El B}{z : El C} ->
x =El= y -> y =El= z -> x =El= z
=El=-trans eqInNat eqInNat = eqInNat
=El=-trans (eqInΠ B=A f=g) (eqInΠ C=B g=h) =
eqInΠ (=S=-trans C=B B=A) \x y x=y ->
=El=-trans (f=g x (B=A << x) (cast-id _))
(g=h _ y (=El=-trans (=El=-sym (cast-id _)) x=y))
=El=-trans (eqInΣ F₁=F₂ x₁=x₂ y₁=y₂) (eqInΣ F₂=F₃ x₂=x₃ y₂=y₃) =
eqInΣ (=Fam=-trans F₁=F₂ F₂=F₃) (=El=-trans x₁=x₂ x₂=x₃) (=El=-trans y₁=y₂ y₂=y₃)
-- Casting. Important: don't look at the proof!
infix 50 _<<_ _>>_
_<<_ : {A B : Setoid} -> A =S= B -> El B -> El A
_<<_ {nat}{Π _ _} () _
_<<_ {nat}{Σ _ _} () _
_<<_ {Π _ _}{nat} () _
_<<_ {Π _ _}{Σ _ _} () _
_<<_ {Σ _ _}{nat} () _
_<<_ {Σ _ _}{Π _ _} () _
_<<_ {nat}{nat} p x = x
_<<_ {Π A₁ F₁}{Π A₂ F₂} p (ƛ f pf) = ƛ g pg
where
g : (x : El A₁) -> El (F₁ ! x)
g x = let A₂=A₁ = eqΠ-inv₁ p
F₁=F₂ = famEqCodom (eqΠ-inv₂ p) x _ (cast-id _)
in F₁=F₂ << f (A₂=A₁ << x)
pg : (x y : El A₁) -> x =El= y -> g x =El= g y
pg x y x=y = cast-irr _ _ (pf _ _ (cast-irr _ _ x=y))
_<<_ {Σ A₁ F₁}{Σ A₂ F₂} p (x , y) = eqΣ-inv₁ p << x , F₁=F₂ << y
where
F₁=F₂ : F₁ ! (eqΣ-inv₁ p << x) =S= F₂ ! x
F₁=F₂ = famEqCodom (eqΣ-inv₂ p) _ _ (=El=-sym (cast-id _))
_>>_ : {A B : Setoid} -> Fam A -> A =S= B -> Fam B
fam F pF >> A=B = fam G pG
where
G : El _ -> Setoid
G y = F (A=B << y)
pG : forall x y -> x =El= y -> G x =S= G y
pG x y x=y = pF _ _ (cast-irr _ _ x=y)
cast-id : {A B : Setoid}{x : El A}(p : B =S= A) -> x =El= p << x
cast-id eqNat = eqInNat
cast-id {x = x , y } (eqΣ A=B F=G) = eqInΣ (=Fam=-sym F=G) (cast-id _) (cast-id _)
cast-id {x = ƛ f pf} (eqΠ B=A F=G) =
eqInΠ (=S=-sym B=A) \x y x=y ->
proof f x
≡ f (_ << y) by pf _ _ (=El=-trans x=y (cast-id _))
≡ _ << f (_ << y) by cast-id _
qed
where
open Chain El _=El=_ (\x -> =El=-refl) (\x y z -> =El=-trans)
cast-irr : {A₁ A₂ B₁ B₂ : Setoid}{x : El A₁}{y : El A₂}
(p₁ : B₁ =S= A₁)(p₂ : B₂ =S= A₂) -> x =El= y -> p₁ << x =El= p₂ << y
cast-irr {x = x}{y = y} p q x=y =
proof p << x
≡ x by =El=-sym (cast-id _)
≡ y by x=y
≡ q << y by cast-id _
qed
where
open Chain El _=El=_ (\x -> =El=-refl) (\x y z -> =El=-trans)
-- Let's do some overloading
data EqFam : Set -> Set where
el : EqFam Setoid
setoid : EqFam True
fam : EqFam Setoid
[_] : {I : Set} -> EqFam I -> I -> Set
[ el ] A = El A
[ setoid ] _ = Setoid
[ fam ] A = Fam A
infix 5 _==_
_==_ : {I : Set}{eqf : EqFam I}{i j : I} -> [ eqf ] i -> [ eqf ] j -> Set
_==_ {eqf = el } x y = x =El= y
_==_ {eqf = setoid} A B = A =S= B
_==_ {eqf = fam } F G = F =Fam= G
refl : {I : Set}{eqf : EqFam I}{i : I}{x : [ eqf ] i} -> x == x
refl {eqf = el} = =El=-refl
refl {eqf = setoid} = =S=-refl
refl {eqf = fam} = =Fam=-refl
sym : {I : Set}{eqf : EqFam I}{i j : I}{x : [ eqf ] i}{y : [ eqf ] j} -> x == y -> y == x
sym {eqf = el} = =El=-sym
sym {eqf = setoid} = =S=-sym
sym {eqf = fam} = =Fam=-sym
trans : {I : Set}{eqf : EqFam I}{i j k : I}{x : [ eqf ] i}{y : [ eqf ] j}{z : [ eqf ] k} ->
x == y -> y == z -> x == z
trans {eqf = el} = =El=-trans
trans {eqf = setoid} = =S=-trans
trans {eqf = fam} = =Fam=-trans
open module EqChain {I : Set}{eqf : EqFam I} =
Chain ([ eqf ]) _==_ (\x -> refl) (\x y z -> trans)
homo : {A B : Setoid}{x : El A}{y : El B} -> x == y -> A == B
homo eqInNat = eqNat
homo (eqInΠ B=A p) = eqΠ B=A (eqFam B=A \x y x=y -> homo (p x y x=y))
homo (eqInΣ F=G p q) = eqΣ (homo p) F=G
cast-id' : {A B C : Setoid}{x : El A}{y : El B}(p : C == B) -> x == y -> x == p << y
cast-id' C=B x=y = trans x=y (cast-id _)
-- Some helper stuff
K : {A : Setoid} -> Setoid -> Fam A
K B = fam (\_ -> B) (\_ _ _ -> refl)
infixr 20 _==>_
infixl 70 _·_ _∘_ _○_
infixl 90 _#_
!-cong : {A B : Setoid}(F : Fam A)(G : Fam B){x : El A}{y : El B} ->
F == G -> x == y -> F ! x == G ! y
!-cong F G (eqFam B=A F=G) x=y = F=G _ _ x=y
!-cong-R : {A : Setoid}(F : Fam A){x y : El A} ->
x == y -> F ! x == F ! y
!-cong-R F x=y = !-cong F F refl x=y
_==>_ : Setoid -> Setoid -> Setoid
A ==> B = Π A (K B)
_#_ : {A : Setoid}{F : Fam A} -> El (Π A F) -> (x : El A) -> El (F ! x)
ƛ f _ # x = f x
#-cong : {A B : Setoid}{F : Fam A}{G : Fam B}
(f : El (Π A F))(g : El (Π B G)){x : El A}{y : El B} ->
f == g -> x == y -> f # x == g # y
#-cong ._ ._ (eqInΠ _ f=g) x=y = f=g _ _ x=y
#-cong-R : {A : Setoid}{F : Fam A}(f : El (Π A F)){x y : El A} ->
x == y -> f # x == f # y
#-cong-R f p = #-cong f f refl p
id : {A : Setoid} -> El (A ==> A)
id = ƛ (\x -> x) (\_ _ p -> p)
-- Family composition
_○_ : {A B : Setoid} -> Fam A -> El (B ==> A) -> Fam B
F ○ f = fam (\x -> F ! (f # x)) (\x y x=y -> !-cong-R F (#-cong-R f x=y))
lem-○-id : {A : Setoid}{F : Fam A} -> F ○ id == F
lem-○-id {F = F} = eqFam refl \x y x=y -> !-cong-R F x=y
_∘_ : {A B : Setoid}{F : Fam B} -> El (Π B F) -> (g : El (A ==> B)) -> El (Π A (F ○ g))
f ∘ g = ƛ (\x -> f # (g # x)) \x y x=y -> #-cong-R f (#-cong-R g x=y)
lem-∘-id : {A : Setoid}{F : Fam A}(f : El (Π A F)) -> f ∘ id == f
lem-∘-id (ƛ f pf) = eqInΠ refl pf
lem-id-∘ : {A B : Setoid}(f : El (A ==> B)) -> id ∘ f == f
lem-id-∘ (ƛ f pf) = eqInΠ refl pf
-- Simply type composition (not quite a special case of ∘ because of proof relevance)
_·_ : {A B C : Setoid} -> El (B ==> C) -> El (A ==> B) -> El (A ==> C)
f · g = eqΠ refl (eqFam refl \_ _ _ -> refl) << f ∘ g
fst : {A : Setoid}{F : Fam A} -> El (Σ A F) -> El A
fst (x , y) = x
snd : {A : Setoid}{F : Fam A}(p : El (Σ A F)) -> El (F ! fst p)
snd (x , y) = y
fst-eq : {A B : Setoid}{F : Fam A}{G : Fam B}
{x : El (Σ A F)}{y : El (Σ B G)} -> x == y -> fst x == fst y
fst-eq (eqInΣ _ x₁=x₂ _) = x₁=x₂
snd-eq : {A B : Setoid}{F : Fam A}{G : Fam B}
{x : El (Σ A F)}{y : El (Σ B G)} -> x == y -> snd x == snd y
snd-eq (eqInΣ _ _ y₁=y₂) = y₁=y₂
η : {A : Setoid}{F : Fam A}(f : El (Π A F)){pf : (x y : El A) -> x == y -> f # x == f # y} ->
f == ƛ {F = F} (_#_ f) pf
η (ƛ f pf) = eqInΠ refl pf
| 34.08589
| 94
| 0.448614
|
061bff43af312fe2d77bf1e22b128f27e81c616d
| 458
|
agda
|
Agda
|
test/Fail/Issue653.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue653.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue653.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2013-02-27
module Issue653 where
postulate
P : {A : Set} → (A → Set) → Set
mutual
{-# NON_TERMINATING #-}
A : Set
A = P B -- note A = P {A} B is non-terminating
data B : A → Set where
c : (a : A) → B a
-- This caused a stack overflow due to infinite reduction
-- in the positivity checker.
-- Now functions that do not pass the termination checker are not unfolded
-- any more.
-- So, it should report positivity violation now.
| 22.9
| 74
| 0.652838
|
23bae51ac87e49520d795994f36ebf05490fc7a5
| 696
|
agda
|
Agda
|
test/interaction/Issue2466.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue2466.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue2466.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2017-03-21, issue #2466
-- The unifier should not turn user-written variable patterns into
-- dot patterns.
-- {-# OPTIONS -v reify.implicit:100 -v interaction.case:100 #-}
-- {-# OPTIONS -v tc.lhs.unify:40 #-}
postulate
A B : Set
module Explicit where
data D : A → B → Set where
c : ∀ p {p'} x → D p' x → D p x
test : ∀ p x → D p x → D p x
test .p _ (c p x pp) = {!p'!}
where
y = x
-- Expected: test .p _ (c p {p'} x pp) = ?
module Implicit where
data D : A → B → Set where
c : ∀ {p p' x} → D p' x → D p x
test : ∀ p {x} → D p x → D p x
test .p (c {p} {x = x} pp) = {!p'!}
where
y = x
-- Expected: test .p (c {p} {p'} {x} pp) = ?
| 19.885714
| 66
| 0.510057
|
c5262ec7cd33f3941acd848db7f1410d80aff130
| 7,518
|
agda
|
Agda
|
CP/Session2.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | 2
|
2020-08-25T07:34:40.000Z
|
2020-08-25T14:05:01.000Z
|
CP/Session2.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
CP/Session2.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
open import Relation.Binary using (Decidable; DecSetoid)
open import Level
module CP.Session2 {a} (ChanSetoid : DecSetoid zero a) (Type : Set) where
Chan : Set
Chan = DecSetoid.Carrier ChanSetoid
_≟Chan_ = DecSetoid._≟_ ChanSetoid
_≈Chan_ = DecSetoid._≈_ ChanSetoid
_≉Chan_ = DecSetoid._≉_ ChanSetoid
infixl 5 _,_∶_
data Session : Set a where
_,_∶_ : Session → Chan → Type → Session
_++_ : Session → Session → Session
∅ : Session
-- open import Data.Bool hiding (_≟_)
-- open import Data.Empty
-- open import Data.Unit
open import Relation.Nullary
open import Relation.Nullary.Decidable
-- open import Relation.Binary.PropositionalEquality
infix 4 _∋_
data _∋_ : (Γ : Session) → (x : Chan) → Set a where
here : ∀ {Γ x y A} → x ≈Chan y → Γ , y ∶ A ∋ x
there : ∀ {Γ x y A} → Γ ∋ x → Γ , y ∶ A ∋ x
left : ∀ {Γ Δ x} → Γ ∋ x → Γ ++ Δ ∋ x
right : ∀ {Γ Δ x} → Δ ∋ x → Γ ++ Δ ∋ x
infix 4 _∋?_
_∋?_ : (Γ : Session) → (x : Chan) → Dec (Γ ∋ x)
Γ , y ∶ A ∋? x with x ≟Chan y
... | yes x≈y = yes (here x≈y)
... | no ¬x≈y with Γ ∋? x
... | yes Γ∋x = yes (there Γ∋x)
... | no ¬Γ∋x = no (λ where (here x≈y) → ¬x≈y x≈y
(there Γ∋x) → ¬Γ∋x Γ∋x)
(Γ ++ Δ) ∋? x with Γ ∋? x
... | yes Γ∋x = yes (left Γ∋x)
... | no ¬Γ∋x with Δ ∋? x
... | yes Δ∋x = yes (right Δ∋x)
... | no ¬Δ∋x = no (λ where (left Γ∋x) → ¬Γ∋x Γ∋x
(right Δ∋x) → ¬Δ∋x Δ∋x)
∅ ∋? x = no (λ ())
open import Data.Product
open import Data.Empty using (⊥-elim)
infix 4 _≈_
_≈_ : Session → Session → Set a
Γ ≈ Δ = (∀ x → Γ ∋ x → Δ ∋ x) × (∀ x → Δ ∋ x → Γ ∋ x)
∅∌x : ∀ {x} → ¬ ∅ ∋ x
∅∌x ()
open DecSetoid ChanSetoid hiding (_≈_)
∅-empty : ∀ {Δ x A} → ¬ ∅ ≈ Δ , x ∶ A
∅-empty {Δ} {x} (P , Q) = ∅∌x (Q x (here refl))
<<<<<<< HEAD
swap : ∀ {Γ x y A B} → Γ , x ∶ A , y ∶ B ≈ Γ , y ∶ B , x ∶ A
swap {Γ} {x} {y} {A} {B} = to , from
where
to : ∀ v → Γ , x ∶ A , y ∶ B ∋ v → Γ , y ∶ B , x ∶ A ∋ v
to v (here P) = there (here P)
to v (there (here P)) = here P
to v (there (there P)) = there (there P)
from : ∀ v → Γ , y ∶ B , x ∶ A ∋ v → Γ , x ∶ A , y ∶ B ∋ v
from v (here P) = there (here P)
from v (there (here P)) = here P
from v (there (there P)) = there (there P)
-- contract : ∀ {Γ x y A B} → → Γ , x ∶ A ≈ Γ
-- contract
-- strengthen : ∀ {Γ x A v} → Γ , x ∶ A ∋ v → x ≉ v → Γ ∋ v
-- strengthen (here x≈v) x≉v = ⊥-elim (x≉v (sym x≈v))
-- strengthen (there P) x≉v = P
=======
>>>>>>> 40f82fd098a0c30c87ea0056baa48152aefae1f6
lookup : (Γ : Session) (x : Chan) → Dec (∃[ Δ ] ∃[ A ] (Γ ≈ (Δ , x ∶ A)))
lookup (Γ , y ∶ A) x with x ≟Chan y
... | yes x≈y = yes (Γ , A , (λ where v (here v≈y) → here (trans v≈y (sym x≈y))
v (there Γ∷y∋v) → there Γ∷y∋v)
, λ where v (here v≈x) → here (trans v≈x x≈y)
v (there Γ∷x∋v) → there Γ∷x∋v)
... | no ¬x≈y with lookup Γ x
... | yes (Δ , B , Γ≈Δ,x∶B) = yes (Δ , y ∶ A , B , (λ where v (here v≈y) → there (here v≈y)
<<<<<<< HEAD
v (there Γ∋v) → proj₁ swap v (there (proj₁ Γ≈Δ,x∶B v Γ∋v)))
, λ where v (here v≈x) → there (proj₂ Γ≈Δ,x∶B v (here v≈x))
v (there (here v≈y)) → here v≈y
v (there (there Δ∋v)) → there (proj₂ Γ≈Δ,x∶B v (there Δ∋v)))
... | no ¬P = no (λ (Δ , B , Q) → ¬P (Δ , B , {! !}))
-- (λ where v P → proj₁ Q v (there P))
-- , (λ where v P → {! proj₂ Q v P !})))
=======
v (there Γ∋v) → {! !}) , {! !})
... | no P = {! !}
>>>>>>> 40f82fd098a0c30c87ea0056baa48152aefae1f6
lookup (Γ ++ Δ) x = {! !}
lookup ∅ x = no (λ where (Δ , A , P) → ∅-empty P)
-- ... | yes x≈y = yes (Γ , A , λ v → (λ where (here v≈y) → here (trans v≈y (sym x≈y))
-- (there Γ∋v) → there Γ∋v) -- (λ v≈x → v≉y (trans v≈x x≈y))
-- , λ where (here v≈x) → here (trans v≈x x≈y)
-- (there Γ∋v) → there Γ∋v) -- (λ v≈y → v≉x (trans v≈y (sym x≈y)))
-- ... | no ¬x≈y with lookup Γ x
-- ... | yes (Δ , B , Γ≈Δ,x∶B) = yes (Δ , y ∶ A , B , λ v → (λ where (here v≈y) → there (here v≈y) -- (λ v≈x → ¬x≈y (trans (sym v≈x) v≈y))
-- (there Γ∋v) → lemma-1 (proj₁ (Γ≈Δ,x∶B v) Γ∋v))
-- , λ where (here v≈x) → there (proj₂ (Γ≈Δ,x∶B v) (here v≈x)) -- (λ v≈y → ¬x≈y (trans (sym v≈x) v≈y))
-- (there Δ,y∶A∋y) → ,-weakening y A (proj₂ (Γ≈Δ,x∶B v)) (lemma-1 Δ,y∶A∋y))
-- where
-- lemma-1 : ∀ {Γ x y z A B} → Γ , x ∶ A ∋ z → Γ , y ∶ B , x ∶ A ∋ z
-- lemma-1 (here z≈x) = here z≈x
-- lemma-1 (there Γ∋z) = there (there Γ∋z)
-- ,-weakening : ∀ {Γ Δ v} x A → (Γ ∋ v → Δ ∋ v) → (Γ , x ∶ A ∋ v → Δ , x ∶ A ∋ v)
-- ,-weakening x A f (here v≈x) = here v≈x
-- ,-weakening x A f (there Γ∋v) = there (f Γ∋v)
-- ... | no ¬P = no λ Q → {! !}
-- -- GOAL : Γ , y ∶ A ≉ CTX , x ∶ TYPE
-- -- ¬P Γ ≉ CTX , x : TYPE
-- -- no (λ (Δ , B , Q) → ¬P (Δ , B , {! Q !}))
-- -- λ v → (λ Γ∋v → proj₁ (Q v) (there Γ∋v))
-- -- , (λ Δ,x∶B∋v → {! proj₂ (Q v) Δ,x∶B∋v !})))
-- -- → (λ Γ∋v → proj₁ (Q v) (there Γ∋v))
-- -- , λ Δ,x∶B∋v → {! (proj₂ (Q v) Δ,x∶B∋v) !}))
-- -- where
-- -- (here P) → strengthen (proj₂ (Q v) (here P)) (λ y≈v → ¬x≈y (sym (trans y≈v P)))
-- -- (there P) → {! !}))
-- where
-- -- GOAL : Δ , x ∶ B → Γ
-- -- Q v : Δ , x ∶ B <≈> Γ , y ∶ A
-- -- -- ¬P Δ A = Γ <=> Δ , x ∶ A
-- -- (x₁ : Carrier) →
-- -- Σ (Γ ∋ x₁ → Δ₁ , x ∶ A₁ ∋ x₁) (λ x₂ → Δ₁ , x ∶ A₁ ∋ x₁ → Γ ∋ x₁)))
-- strengthen : ∀ {Γ x A v} → Γ , x ∶ A ∋ v → x ≉ v → Γ ∋ v
-- strengthen (here x≈v) x≉v = ⊥-elim (x≉v (sym x≈v))
-- strengthen (there P) x≉v = P
-- temp : ∀ Δ B v → (Δ ∋ v) → (f : Δ , x ∶ B ∋ v → Γ , y ∶ A ∋ v) → Γ ∋ v
-- temp Δ B v Δ∋v f with v ≟Chan x
-- ... | yes v≈x = strengthen (f (here v≈x)) (λ y≈v → ¬x≈y (sym (trans y≈v v≈x)))
-- ... | no ¬v≈x with y ≟Chan v
-- ... | yes y≈v = {! !}
-- ... | no ¬y≈v = strengthen (f (there Δ∋v)) ¬y≈v
-- -- strengthen (f (there Δ∈v)) λ y≈v → {! !}
-- -- lemma : G
-- lookup (Γ ++ Δ) x = {! !}
-- lookup ∅ x = no (λ where (Δ , A , P) → ∅-empty P)
-- -- _≈?_ : (Γ Δ : Session) → Dec (Γ ≈ Δ)
-- -- Γ ≈? Δ = {! !}
-- -- empty : ∀ {Γ x A} → ¬ (∅ ≈ (Γ , x ∶ A))
-- -- empty {Γ} {x} {A} P with x ≟ x
-- -- ... | no ¬p = {! !}
-- -- ... | yes p = {! !}
-- -- lookup : (Γ : Session) (x : Chan) → Dec (∃[ Δ ] ∃[ A ] (Γ ≈ (Δ , x ∶ A)))
-- -- lookup (Γ , y ∶ A) x = {! !}
-- -- lookup (Γ ++ Δ) x with lookup Γ x
-- -- ... | yes p = {! !}
-- -- ... | no ¬p = {! !}
-- -- lookup ∅ x = no (λ where (Γ , A , P) → {! P x !})
| 39.777778
| 158
| 0.373371
|
5777aca1d40fcc4b83fabb9272db3cf395fca365
| 3,401
|
agda
|
Agda
|
src/Auto/Counting.agda
|
wenkokke/AutoInAgda
|
f384b5c236645fcf8ab93179723a7355383a8716
|
[
"MIT"
] | 22
|
2017-07-18T18:14:09.000Z
|
2021-03-20T15:04:47.000Z
|
src/Auto/Counting.agda
|
wenkokke/AutoInAgda
|
f384b5c236645fcf8ab93179723a7355383a8716
|
[
"MIT"
] | 1
|
2017-11-03T09:46:19.000Z
|
2017-11-06T16:49:27.000Z
|
src/Auto/Counting.agda
|
wenkokke/AutoInAgda
|
f384b5c236645fcf8ab93179723a7355383a8716
|
[
"MIT"
] | 2
|
2018-07-10T10:47:30.000Z
|
2019-07-07T07:37:07.000Z
|
open import Auto.Core using (Rule; RuleName; _≟-RuleName_; name2rule; IsHintDB)
open import Level using (zero)
open import Function using (id; _∘_)
open import Category.Functor using (module RawFunctor)
open import Data.Bool as Bool using (if_then_else_)
open import Data.List as List using (List; _++_; []; [_])
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Nat as Nat using (ℕ; pred)
open import Data.Product as Prod using (∃; _,_; proj₂)
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂)
open import Data.Unit as Unit using (⊤)
open import Reflection using (Name)
open import Relation.Nullary.Decidable using (⌊_⌋)
module Auto.Counting where
--------------------------------------------------------------------------------
-- Define a 'counting' hint database which, upon selection of a rule will --
-- decrement an associated 'count' value, and upon reaching 0 will delete --
-- the hint from the hint database. --
-- --
-- The count values can either be natural numbers, in which case they --
-- will be decremented as expected, or the value ⊤, in which case they --
-- will not be decremented, effectively inserting infinite copies of the --
-- rule into the hint database. --
--------------------------------------------------------------------------------
module CountingHintDB where
open RawFunctor (Maybe.functor {zero}) using (_<$>_)
Count : Set
Count = ℕ ⊎ ⊤
record Hint (k : ℕ) : Set where
constructor mkHint
field
rule : Rule k
count : Count
ruleName : RuleName
ruleName = Rule.name rule
HintDB : Set
HintDB = List (∃ Hint)
decrCount : ∀ {k} → Hint k → Maybe (Hint k)
decrCount {k} (mkHint r c) = mkHint r <$> decrCount′ c
where
decrCount′ : Count → Maybe Count
decrCount′ (inj₁ 0) = nothing
decrCount′ (inj₁ 1) = nothing
decrCount′ (inj₁ x) = just (inj₁ (pred x))
decrCount′ (inj₂ _) = just (inj₂ _)
getTr : ∀ {k} → Hint k → (HintDB → HintDB)
getTr h₁ = List.concatMap (List.fromMaybe ∘ mdecr₁)
where
mdecr₁ : ∃ Hint → Maybe (∃ Hint)
mdecr₁ (_ , h₂) =
if ⌊ Hint.ruleName h₁ ≟-RuleName Hint.ruleName h₂ ⌋
then (_,_ _) <$> decrCount h₂
else just (_ , h₂)
countingHintDB : IsHintDB
countingHintDB = record
{ HintDB = HintDB
; Hint = Hint
; getHints = id
; getRule = Hint.rule
; getTr = getTr
; ε = []
; _∙_ = _++_
; return = λ r → [ _ , mkHint r (inj₂ _) ]
}
open CountingHintDB using (mkHint; countingHintDB)
open import Auto.Extensible countingHintDB public
--------------------------------------------------------------------------------
-- Define some new syntax in order to insert rules with limited usage. --
--------------------------------------------------------------------------------
infixl 5 _<<[_]_
_<<[_]_ : HintDB → ℕ → Name → HintDB
db <<[ 0 ] _ = db
db <<[ x ] n with (name2rule n)
db <<[ x ] n | inj₁ msg = db
db <<[ x ] n | inj₂ (k , r) = db ∙ [ k , mkHint r (inj₁ x) ]
| 35.061856
| 96
| 0.510438
|
c5c2f015237a55ed44ef244f3f7567f21d91fc0f
| 1,854
|
agda
|
Agda
|
Cubical/HITs/TypeQuotients/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/HITs/TypeQuotients/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/HITs/TypeQuotients/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
{-
Type quotients:
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.TypeQuotients.Properties where
open import Cubical.HITs.TypeQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥ ; ∣_∣ ; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂ ; ∣_∣₂ ; squash₂
; setTruncIsSet)
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ'
B : A /ₜ R → Type ℓ''
C : A /ₜ R → A /ₜ R → Type ℓ''
elim : (f : (a : A) → (B [ a ]))
→ ((a b : A) (r : R a b) → PathP (λ i → B (eq/ a b r i)) (f a) (f b))
------------------------------------------------------------------------
→ (x : A /ₜ R) → B x
elim f feq [ a ] = f a
elim f feq (eq/ a b r i) = feq a b r i
rec : {X : Type ℓ''}
→ (f : A → X)
→ (∀ (a b : A) → R a b → f a ≡ f b)
-------------------------------------
→ A /ₜ R → X
rec f feq [ a ] = f a
rec f feq (eq/ a b r i) = feq a b r i
elimProp : ((x : A /ₜ R ) → isProp (B x))
→ ((a : A) → B ( [ a ]))
---------------------------------
→ (x : A /ₜ R) → B x
elimProp Bprop f [ a ] = f a
elimProp Bprop f (eq/ a b r i) = isOfHLevel→isOfHLevelDep 1 Bprop (f a) (f b) (eq/ a b r) i
elimProp2 : ((x y : A /ₜ R ) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
--------------------------------------
→ (x y : A /ₜ R) → C x y
elimProp2 Cprop f = elimProp (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp (λ y → Cprop [ x ] y) (f x))
| 30.393443
| 91
| 0.468177
|
292c24a52c189729d15dfa928064f311ca54fd21
| 141
|
agda
|
Agda
|
test/Compiler/simple/Issue728.agda
|
MxmUrw/agda
|
6ede01fa854c5472e54f7d1799ca2c08ed316129
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Issue728.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/Issue728.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --guardedness #-}
module Issue728 where
open import Common.MAlonzo using () renaming (main to mainDefault)
main = mainDefault
| 17.625
| 66
| 0.744681
|
234dfc973426944a9a57e4345c8f5f2d5f630a00
| 15,161
|
agda
|
Agda
|
Definition/Typed/Weakening.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/Typed/Weakening.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/Typed/Weakening.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Weakening where
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
import Tools.PropositionalEquality as PE
-- Weakening type
data _∷_⊆_ : Wk → Con Term → Con Term → Set where
id : ∀ {Γ} → id ∷ Γ ⊆ Γ
step : ∀ {Γ Δ A ρ} → ρ ∷ Δ ⊆ Γ → step ρ ∷ Δ ∙ A ⊆ Γ
lift : ∀ {Γ Δ A ρ} → ρ ∷ Δ ⊆ Γ → lift ρ ∷ Δ ∙ U.wk ρ A ⊆ Γ ∙ A
-- -- Weakening composition
_•ₜ_ : ∀ {ρ ρ′ Γ Δ Δ′} → ρ ∷ Γ ⊆ Δ → ρ′ ∷ Δ ⊆ Δ′ → ρ • ρ′ ∷ Γ ⊆ Δ′
id •ₜ η′ = η′
step η •ₜ η′ = step (η •ₜ η′)
lift η •ₜ id = lift η
lift η •ₜ step η′ = step (η •ₜ η′)
_•ₜ_ {lift ρ} {lift ρ′} {Δ′ = Δ′ ∙ A} (lift η) (lift η′) =
PE.subst (λ x → lift (ρ • ρ′) ∷ x ⊆ Δ′ ∙ A)
(PE.cong₂ _∙_ PE.refl (PE.sym (wk-comp ρ ρ′ A)))
(lift (η •ₜ η′))
-- Weakening of judgements
wkIndex : ∀ {Γ Δ n A ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρn = wkVar ρ n
in ⊢ Δ → n ∷ A ∈ Γ → ρn ∷ ρA ∈ Δ
wkIndex id ⊢Δ i = PE.subst (λ x → _ ∷ x ∈ _) (PE.sym (wk-id _)) i
wkIndex (step ρ) (⊢Δ ∙ A) i = PE.subst (λ x → _ ∷ x ∈ _)
(wk1-wk _ _)
(there (wkIndex ρ ⊢Δ i))
wkIndex (lift ρ) (⊢Δ ∙ A) (there i) = PE.subst (λ x → _ ∷ x ∈ _)
(wk1-wk≡lift-wk1 _ _)
(there (wkIndex ρ ⊢Δ i))
wkIndex (lift ρ) ⊢Δ here =
let G = _
n = _
in PE.subst (λ x → n ∷ x ∈ G)
(wk1-wk≡lift-wk1 _ _)
here
mutual
wk : ∀ {Γ Δ A ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
in ⊢ Δ → Γ ⊢ A → Δ ⊢ ρA
wk ρ ⊢Δ (ℕⱼ ⊢Γ) = ℕⱼ ⊢Δ
wk ρ ⊢Δ (Emptyⱼ ⊢Γ) = Emptyⱼ ⊢Δ
wk ρ ⊢Δ (Unitⱼ ⊢Γ) = Unitⱼ ⊢Δ
wk ρ ⊢Δ (Uⱼ ⊢Γ) = Uⱼ ⊢Δ
wk ρ ⊢Δ (Πⱼ F ▹ G) = let ρF = wk ρ ⊢Δ F
in Πⱼ ρF ▹ (wk (lift ρ) (⊢Δ ∙ ρF) G)
wk ρ ⊢Δ (Σⱼ F ▹ G) = let ρF = wk ρ ⊢Δ F
in Σⱼ ρF ▹ (wk (lift ρ) (⊢Δ ∙ ρF) G)
wk ρ ⊢Δ (univ A) = univ (wkTerm ρ ⊢Δ A)
wkTerm : ∀ {Γ Δ A t ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
in ⊢ Δ → Γ ⊢ t ∷ A → Δ ⊢ ρt ∷ ρA
wkTerm ρ ⊢Δ (ℕⱼ ⊢Γ) = ℕⱼ ⊢Δ
wkTerm ρ ⊢Δ (Emptyⱼ ⊢Γ) = Emptyⱼ ⊢Δ
wkTerm ρ ⊢Δ (Unitⱼ ⊢Γ) = Unitⱼ ⊢Δ
wkTerm ρ ⊢Δ (Πⱼ F ▹ G) = let ρF = wkTerm ρ ⊢Δ F
in Πⱼ ρF ▹ (wkTerm (lift ρ) (⊢Δ ∙ univ ρF) G)
wkTerm ρ ⊢Δ (Σⱼ F ▹ G) = let ρF = wkTerm ρ ⊢Δ F
in Σⱼ ρF ▹ (wkTerm (lift ρ) (⊢Δ ∙ univ ρF) G)
wkTerm ρ ⊢Δ (var ⊢Γ x) = var ⊢Δ (wkIndex ρ ⊢Δ x)
wkTerm ρ ⊢Δ (lamⱼ F t) = let ρF = wk ρ ⊢Δ F
in lamⱼ ρF (wkTerm (lift ρ) (⊢Δ ∙ ρF) t)
wkTerm ρ ⊢Δ (_∘ⱼ_ {G = G} g a) = PE.subst (λ x → _ ⊢ _ ∷ x)
(PE.sym (wk-β G))
(wkTerm ρ ⊢Δ g ∘ⱼ wkTerm ρ ⊢Δ a)
wkTerm ρ ⊢Δ (prodⱼ {G = G} ⊢F ⊢G t u) =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm ρ ⊢Δ t
ρu = wkTerm ρ ⊢Δ u
ρu = PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) ρu
in prodⱼ ρF ρG ρt ρu
wkTerm ρ ⊢Δ (fstⱼ {G = G} ⊢F ⊢G t) =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm ρ ⊢Δ t
in fstⱼ ρF ρG ρt
wkTerm ρ ⊢Δ (sndⱼ {G = G} ⊢F ⊢G t) =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm ρ ⊢Δ t
in PE.subst (λ x → _ ⊢ snd _ ∷ x) (PE.sym (wk-β G)) (sndⱼ ρF ρG ρt)
wkTerm ρ ⊢Δ (zeroⱼ ⊢Γ) = zeroⱼ ⊢Δ
wkTerm ρ ⊢Δ (sucⱼ n) = sucⱼ (wkTerm ρ ⊢Δ n)
wkTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrecⱼ {G = G} {s = s} ⊢G ⊢z ⊢s ⊢n) =
PE.subst (λ x → _ ⊢ natrec _ _ _ _ ∷ x) (PE.sym (wk-β G))
(natrecⱼ (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢G)
(PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) (wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec ρ G)
(wkTerm [ρ] ⊢Δ ⊢s))
(wkTerm [ρ] ⊢Δ ⊢n))
wkTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (Emptyrecⱼ {A = A} {e = e} ⊢A ⊢e) =
(Emptyrecⱼ (wk [ρ] ⊢Δ ⊢A) (wkTerm [ρ] ⊢Δ ⊢e))
wkTerm ρ ⊢Δ (starⱼ ⊢Γ) = starⱼ ⊢Δ
wkTerm ρ ⊢Δ (conv t A≡B) = conv (wkTerm ρ ⊢Δ t) (wkEq ρ ⊢Δ A≡B)
wkEq : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A ≡ B → Δ ⊢ ρA ≡ ρB
wkEq ρ ⊢Δ (univ A≡B) = univ (wkEqTerm ρ ⊢Δ A≡B)
wkEq ρ ⊢Δ (refl A) = refl (wk ρ ⊢Δ A)
wkEq ρ ⊢Δ (sym A≡B) = sym (wkEq ρ ⊢Δ A≡B)
wkEq ρ ⊢Δ (trans A≡B B≡C) = trans (wkEq ρ ⊢Δ A≡B) (wkEq ρ ⊢Δ B≡C)
wkEq ρ ⊢Δ (Π-cong F F≡H G≡E) = let ρF = wk ρ ⊢Δ F
in Π-cong ρF (wkEq ρ ⊢Δ F≡H)
(wkEq (lift ρ) (⊢Δ ∙ ρF) G≡E)
wkEq ρ ⊢Δ (Σ-cong F F≡H G≡E) = let ρF = wk ρ ⊢Δ F
in Σ-cong ρF (wkEq ρ ⊢Δ F≡H)
(wkEq (lift ρ) (⊢Δ ∙ ρF) G≡E)
wkEqTerm : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t ≡ u ∷ A → Δ ⊢ ρt ≡ ρu ∷ ρA
wkEqTerm ρ ⊢Δ (refl t) = refl (wkTerm ρ ⊢Δ t)
wkEqTerm ρ ⊢Δ (sym t≡u) = sym (wkEqTerm ρ ⊢Δ t≡u)
wkEqTerm ρ ⊢Δ (trans t≡u u≡r) = trans (wkEqTerm ρ ⊢Δ t≡u) (wkEqTerm ρ ⊢Δ u≡r)
wkEqTerm ρ ⊢Δ (conv t≡u A≡B) = conv (wkEqTerm ρ ⊢Δ t≡u) (wkEq ρ ⊢Δ A≡B)
wkEqTerm ρ ⊢Δ (Π-cong F F≡H G≡E) =
let ρF = wk ρ ⊢Δ F
in Π-cong ρF (wkEqTerm ρ ⊢Δ F≡H)
(wkEqTerm (lift ρ) (⊢Δ ∙ ρF) G≡E)
wkEqTerm ρ ⊢Δ (Σ-cong F F≡H G≡E) =
let ρF = wk ρ ⊢Δ F
in Σ-cong ρF (wkEqTerm ρ ⊢Δ F≡H)
(wkEqTerm (lift ρ) (⊢Δ ∙ ρF) G≡E)
wkEqTerm ρ ⊢Δ (app-cong {G = G} f≡g a≡b) =
PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x)
(PE.sym (wk-β G))
(app-cong (wkEqTerm ρ ⊢Δ f≡g) (wkEqTerm ρ ⊢Δ a≡b))
wkEqTerm ρ ⊢Δ (β-red {a = a} {t = t} {G = G} F ⊢t ⊢a) =
let ρF = wk ρ ⊢Δ F
in PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x)
(PE.sym (wk-β G))
(PE.subst (λ x → _ ⊢ U.wk _ ((lam t) ∘ a) ≡ x ∷ _)
(PE.sym (wk-β t))
(β-red ρF (wkTerm (lift ρ) (⊢Δ ∙ ρF) ⊢t)
(wkTerm ρ ⊢Δ ⊢a)))
wkEqTerm ρ ⊢Δ (η-eq F f g f0≡g0) =
let ρF = wk ρ ⊢Δ F
in η-eq ρF (wkTerm ρ ⊢Δ f)
(wkTerm ρ ⊢Δ g)
(PE.subst (λ t → _ ⊢ t ∘ _ ≡ _ ∷ _)
(PE.sym (wk1-wk≡lift-wk1 _ _))
(PE.subst (λ t → _ ⊢ _ ≡ t ∘ _ ∷ _)
(PE.sym (wk1-wk≡lift-wk1 _ _))
(wkEqTerm (lift ρ) (⊢Δ ∙ ρF) f0≡g0)))
wkEqTerm ρ ⊢Δ (fst-cong ⊢F ⊢G t≡t') =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
in fst-cong ρF ρG (wkEqTerm ρ ⊢Δ t≡t')
wkEqTerm ρ ⊢Δ (snd-cong {G = G} ⊢F ⊢G t≡t') =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρt≡t' = wkEqTerm ρ ⊢Δ t≡t'
in PE.subst (λ x → _ ⊢ snd _ ≡ snd _ ∷ x) (PE.sym (wk-β G))
(snd-cong ρF ρG ρt≡t')
wkEqTerm ρ ⊢Δ (Σ-η {G = G} ⊢F ⊢G ⊢p ⊢r fst≡ snd≡) =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρp = wkTerm ρ ⊢Δ ⊢p
ρr = wkTerm ρ ⊢Δ ⊢r
ρfst≡ = wkEqTerm ρ ⊢Δ fst≡
ρsnd≡ = wkEqTerm ρ ⊢Δ snd≡
ρsnd≡ = PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x)
(wk-β G)
ρsnd≡
in Σ-η ρF ρG ρp ρr ρfst≡ ρsnd≡
wkEqTerm {ρ = ρ} [ρ] ⊢Δ (Σ-β₁ {G = G} ⊢F ⊢G t u) =
let ρF = wk [ρ] ⊢Δ ⊢F
ρG = wk (lift [ρ]) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm [ρ] ⊢Δ t
ρu = wkTerm [ρ] ⊢Δ u
ρu = PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) ρu
in Σ-β₁ ρF ρG ρt ρu
wkEqTerm {ρ = ρ} [ρ] ⊢Δ (Σ-β₂ {G = G} ⊢F ⊢G t u) =
let ρF = wk [ρ] ⊢Δ ⊢F
ρG = wk (lift [ρ]) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm [ρ] ⊢Δ t
ρu = wkTerm [ρ] ⊢Δ u
ρu = PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) ρu
in PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x) (PE.sym (wk-β G))
(Σ-β₂ ρF ρG ρt ρu)
wkEqTerm ρ ⊢Δ (suc-cong m≡n) = suc-cong (wkEqTerm ρ ⊢Δ m≡n)
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-cong {s = s} {s′ = s′} {F = F}
F≡F′ z≡z′ s≡s′ n≡n′) =
PE.subst (λ x → Δ ⊢ natrec _ _ _ _ ≡ _ ∷ x) (PE.sym (wk-β F))
(natrec-cong (wkEq (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) F≡F′)
(PE.subst (λ x → Δ ⊢ _ ≡ _ ∷ x) (wk-β F)
(wkEqTerm [ρ] ⊢Δ z≡z′))
(PE.subst (λ x → Δ ⊢ U.wk ρ s
≡ U.wk ρ s′ ∷ x)
(wk-β-natrec _ F)
(wkEqTerm [ρ] ⊢Δ s≡s′))
(wkEqTerm [ρ] ⊢Δ n≡n′))
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-zero {z} {s} {F} ⊢F ⊢z ⊢s) =
PE.subst (λ x → Δ ⊢ natrec (U.wk (lift _) F) _ _ _ ≡ _ ∷ x)
(PE.sym (wk-β F))
(natrec-zero (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → Δ ⊢ U.wk ρ z ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec _ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-suc {n} {z} {s} {F} ⊢n ⊢F ⊢z ⊢s) =
PE.subst (λ x → Δ ⊢ natrec (U.wk (lift _) F) _ _ _
≡ _ ∘ (natrec _ _ _ _) ∷ x)
(PE.sym (wk-β F))
(natrec-suc (wkTerm [ρ] ⊢Δ ⊢n)
(wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → Δ ⊢ U.wk ρ z ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec _ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (Emptyrec-cong {A = A} {A' = A'} {e = e} {e' = e'}
A≡A' e≡e') =
(Emptyrec-cong (wkEq [ρ] ⊢Δ A≡A')
(wkEqTerm [ρ] ⊢Δ e≡e'))
wkEqTerm ρ ⊢Δ (η-unit e e') = η-unit (wkTerm ρ ⊢Δ e) (wkTerm ρ ⊢Δ e')
mutual
wkRed : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A ⇒ B → Δ ⊢ ρA ⇒ ρB
wkRed ρ ⊢Δ (univ A⇒B) = univ (wkRedTerm ρ ⊢Δ A⇒B)
wkRedTerm : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t ⇒ u ∷ A → Δ ⊢ ρt ⇒ ρu ∷ ρA
wkRedTerm ρ ⊢Δ (conv t⇒u A≡B) = conv (wkRedTerm ρ ⊢Δ t⇒u) (wkEq ρ ⊢Δ A≡B)
wkRedTerm ρ ⊢Δ (app-subst {B = B} t⇒u a) =
PE.subst (λ x → _ ⊢ _ ⇒ _ ∷ x) (PE.sym (wk-β B))
(app-subst (wkRedTerm ρ ⊢Δ t⇒u) (wkTerm ρ ⊢Δ a))
wkRedTerm ρ ⊢Δ (β-red {A} {B} {a} {t} ⊢A ⊢t ⊢a) =
let ⊢ρA = wk ρ ⊢Δ ⊢A
in PE.subst (λ x → _ ⊢ _ ⇒ _ ∷ x) (PE.sym (wk-β B))
(PE.subst (λ x → _ ⊢ U.wk _ ((lam t) ∘ a) ⇒ x ∷ _)
(PE.sym (wk-β t))
(β-red ⊢ρA (wkTerm (lift ρ) (⊢Δ ∙ ⊢ρA) ⊢t)
(wkTerm ρ ⊢Δ ⊢a)))
wkRedTerm ρ ⊢Δ (fst-subst ⊢F ⊢G t⇒) =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρt⇒ = wkRedTerm ρ ⊢Δ t⇒
in fst-subst ρF ρG ρt⇒
wkRedTerm ρ ⊢Δ (snd-subst {G = G} ⊢F ⊢G t⇒) =
let ρF = wk ρ ⊢Δ ⊢F
ρG = wk (lift ρ) (⊢Δ ∙ ρF) ⊢G
ρt⇒ = wkRedTerm ρ ⊢Δ t⇒
in PE.subst (λ x → _ ⊢ snd _ ⇒ snd _ ∷ x) (PE.sym (wk-β G))
(snd-subst ρF ρG ρt⇒)
wkRedTerm {ρ = ρ} [ρ] ⊢Δ (Σ-β₁ {G = G} ⊢F ⊢G t u) =
let ρF = wk [ρ] ⊢Δ ⊢F
ρG = wk (lift [ρ]) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm [ρ] ⊢Δ t
ρu = wkTerm [ρ] ⊢Δ u
ρu = PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) ρu
in Σ-β₁ ρF ρG ρt ρu
wkRedTerm {ρ = ρ} [ρ] ⊢Δ (Σ-β₂ {G = G} ⊢F ⊢G t u) =
let ρF = wk [ρ] ⊢Δ ⊢F
ρG = wk (lift [ρ]) (⊢Δ ∙ ρF) ⊢G
ρt = wkTerm [ρ] ⊢Δ t
ρu = wkTerm [ρ] ⊢Δ u
ρu = PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) ρu
in PE.subst (λ x → _ ⊢ _ ⇒ _ ∷ x) (PE.sym (wk-β G))
(Σ-β₂ ρF ρG ρt ρu)
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-subst {s = s} {F = F} ⊢F ⊢z ⊢s n⇒n′) =
PE.subst (λ x → _ ⊢ natrec _ _ _ _ ⇒ _ ∷ x) (PE.sym (wk-β F))
(natrec-subst (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec _ F)
(wkTerm [ρ] ⊢Δ ⊢s))
(wkRedTerm [ρ] ⊢Δ n⇒n′))
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-zero {s = s} {F = F} ⊢F ⊢z ⊢s) =
PE.subst (λ x → _ ⊢ natrec (U.wk (lift ρ) F) _ _ _ ⇒ _ ∷ x)
(PE.sym (wk-β F))
(natrec-zero (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → _ ⊢ _ ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec ρ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-suc {s = s} {F = F} ⊢n ⊢F ⊢z ⊢s) =
PE.subst (λ x → _ ⊢ natrec _ _ _ _ ⇒ _ ∘ natrec _ _ _ _ ∷ x)
(PE.sym (wk-β F))
(natrec-suc (wkTerm [ρ] ⊢Δ ⊢n)
(wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → _ ⊢ _ ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec ρ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (Emptyrec-subst {A = A} ⊢A n⇒n′) =
(Emptyrec-subst (wk [ρ] ⊢Δ ⊢A)
(wkRedTerm [ρ] ⊢Δ n⇒n′))
wkRed* : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A ⇒* B → Δ ⊢ ρA ⇒* ρB
wkRed* ρ ⊢Δ (id A) = id (wk ρ ⊢Δ A)
wkRed* ρ ⊢Δ (A⇒A′ ⇨ A′⇒*B) = wkRed ρ ⊢Δ A⇒A′ ⇨ wkRed* ρ ⊢Δ A′⇒*B
wkRed*Term : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t ⇒* u ∷ A → Δ ⊢ ρt ⇒* ρu ∷ ρA
wkRed*Term ρ ⊢Δ (id t) = id (wkTerm ρ ⊢Δ t)
wkRed*Term ρ ⊢Δ (t⇒t′ ⇨ t′⇒*u) = wkRedTerm ρ ⊢Δ t⇒t′ ⇨ wkRed*Term ρ ⊢Δ t′⇒*u
wkRed:*: : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A :⇒*: B → Δ ⊢ ρA :⇒*: ρB
wkRed:*: ρ ⊢Δ [ ⊢A , ⊢B , D ] = [ wk ρ ⊢Δ ⊢A , wk ρ ⊢Δ ⊢B , wkRed* ρ ⊢Δ D ]
wkRed:*:Term : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t :⇒*: u ∷ A → Δ ⊢ ρt :⇒*: ρu ∷ ρA
wkRed:*:Term ρ ⊢Δ [ ⊢t , ⊢u , d ] =
[ wkTerm ρ ⊢Δ ⊢t , wkTerm ρ ⊢Δ ⊢u , wkRed*Term ρ ⊢Δ d ]
| 42.587079
| 84
| 0.369501
|
cba1fa9dbd68d565381e97c46eed596ce5ac9d38
| 398
|
agda
|
Agda
|
Nat.agda
|
divipp/agda-intro-prezi
|
a8902e36ed2037de9008e061d54517d4d7d99f0f
|
[
"BSD-3-Clause"
] | 2
|
2018-11-27T02:50:48.000Z
|
2020-01-21T14:53:25.000Z
|
Nat.agda
|
divipp/agda-intro-prezi
|
a8902e36ed2037de9008e061d54517d4d7d99f0f
|
[
"BSD-3-Clause"
] | null | null | null |
Nat.agda
|
divipp/agda-intro-prezi
|
a8902e36ed2037de9008e061d54517d4d7d99f0f
|
[
"BSD-3-Clause"
] | null | null | null |
module Nat where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
_+_ : ℕ → ℕ → ℕ
zero + a = a
suc a + b = suc (a + b)
data _≡_ {A : Set} : A → A → Set where
refl : {a : A} → a ≡ a
infix 4 _≡_
cong : {A B : Set} {a b : A} (f : A → B) → a ≡ b → f a ≡ f b
cong f refl = refl
+-assoc : (a b c : ℕ) → (a + b) + c ≡ a + (b + c)
+-assoc zero b c = refl
+-assoc (suc a) b c = cong suc (+-assoc a b c)
| 18.090909
| 60
| 0.462312
|
1dd786b98dec4a0fbd57f028c21054090a0789eb
| 8,390
|
agda
|
Agda
|
src/fot/FOTC/Program/SortList/Properties/MiscellaneousI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/SortList/Properties/MiscellaneousI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/SortList/Properties/MiscellaneousI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Miscellaneous properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.Properties.MiscellaneousI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool
open import FOTC.Data.Bool.PropertiesI
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.List.PropertiesI
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesI
open import FOTC.Program.SortList.Properties.Totality.BoolI
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
-- This is a weird result but recall that "the relation ≤ between
-- lists is only an ordering if nil is excluded" (Burstall 1969,
-- p. 46).
-- xs≤[] : ∀ {is} → ListN is → OrdList is → LE-Lists is []
-- xs≤[] lnnil _ = ≤-Lists-[] []
-- xs≤[] (lncons {i} {is} Ni LNis) LOconsL =
-- begin
-- ≤-Lists (i ∷ is) []
-- ≡⟨ ≤-Lists-∷ i is [] ⟩
-- ≤-ItemList i [] && ≤-Lists is []
-- ≡⟨ subst (λ t → ≤-ItemList i [] && ≤-Lists is [] ≡ t && ≤-Lists is [])
-- (≤-ItemList-[] i)
-- refl
-- ⟩
-- true && ≤-Lists is []
-- ≡⟨ subst (λ t → true && ≤-Lists is [] ≡ true && t)
-- (xs≤[] LNis (subList-OrdList Ni LNis LOconsL))
-- refl
-- ⟩
-- true && true
-- ≡⟨ &&-tt ⟩
-- true
-- ∎
x≤ys++zs→x≤zs : ∀ {i js ks} → N i → ListN js → ListN ks →
≤-ItemList i (js ++ ks) → ≤-ItemList i ks
x≤ys++zs→x≤zs {i} {ks = ks} Ni lnnil LNks i≤[]++ks =
subst (≤-ItemList i) (++-leftIdentity ks) i≤[]++ks
x≤ys++zs→x≤zs {i} {ks = ks} Ni (lncons {j} {js} Nj LNjs) LNks i≤j∷js++ks =
x≤ys++zs→x≤zs Ni LNjs LNks lemma₂
where
lemma₁ : le i j && le-ItemList i (js ++ ks) ≡ true
lemma₁ =
le i j && le-ItemList i (js ++ ks)
≡⟨ sym (le-ItemList-∷ i j (js ++ ks)) ⟩
le-ItemList i (j ∷ (js ++ ks))
≡⟨ subst (λ t → le-ItemList i (j ∷ (js ++ ks)) ≡ le-ItemList i t)
(sym (++-∷ j js ks))
refl
⟩
le-ItemList i ((j ∷ js) ++ ks) ≡⟨ i≤j∷js++ks ⟩
true ∎
lemma₂ : ≤-ItemList i (js ++ ks)
lemma₂ = &&-list₂-t₂ (le-Bool Ni Nj)
(le-ItemList-Bool Ni (++-ListN LNjs LNks))
lemma₁
xs++ys-OrdList→xs≤ys : ∀ {is js} → ListN is → ListN js →
OrdList (is ++ js) → ≤-Lists is js
xs++ys-OrdList→xs≤ys {js = js} lnnil LNjs OLis++js = le-Lists-[] js
xs++ys-OrdList→xs≤ys {js = js} (lncons {i} {is} Ni LNis) LNjs OLis++js =
le-Lists (i ∷ is) js
≡⟨ le-Lists-∷ i is js ⟩
le-ItemList i js && le-Lists is js
≡⟨ subst (λ t → le-ItemList i js && le-Lists is js ≡
t && le-Lists is js)
(x≤ys++zs→x≤zs Ni LNis LNjs lemma₁)
refl
⟩
true && le-Lists is js
≡⟨ subst (λ t → true && le-Lists is js ≡ true && t)
(xs++ys-OrdList→xs≤ys LNis LNjs lemma₂) --IH.
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
where
lemma₀ : le-ItemList i (is ++ js) && ordList (is ++ js) ≡ true
lemma₀ = trans (sym (ordList-∷ i (is ++ js)))
(trans (subst (λ t → ordList (i ∷ is ++ js) ≡ ordList t)
(sym (++-∷ i is js))
refl)
OLis++js)
helper₁ : Bool (le-ItemList i (is ++ js))
helper₁ = le-ItemList-Bool Ni (++-ListN LNis LNjs)
helper₂ : Bool (ordList (is ++ js))
helper₂ = ordList-Bool (++-ListN LNis LNjs)
lemma₁ : le-ItemList i (is ++ js) ≡ true
lemma₁ = &&-list₂-t₁ helper₁ helper₂ lemma₀
lemma₂ : ordList (is ++ js) ≡ true
lemma₂ = &&-list₂-t₂ helper₁ helper₂ lemma₀
x≤ys→x≤zs→x≤ys++zs : ∀ {i js ks} → N i → ListN js → ListN ks →
≤-ItemList i js →
≤-ItemList i ks →
≤-ItemList i (js ++ ks)
x≤ys→x≤zs→x≤ys++zs {i} {ks = ks} Ni lnnil LNks _ i≤k =
subst (≤-ItemList i) (sym (++-leftIdentity ks)) i≤k
x≤ys→x≤zs→x≤ys++zs {i} {ks = ks} Ni (lncons {j} {js} Nj LNjs) LNks i≤j∷js i≤k =
le-ItemList i ((j ∷ js) ++ ks)
≡⟨ subst (λ t → le-ItemList i ((j ∷ js) ++ ks) ≡
le-ItemList i t)
(++-∷ j js ks)
refl
⟩
le-ItemList i (j ∷ (js ++ ks))
≡⟨ le-ItemList-∷ i j (js ++ ks) ⟩
le i j && le-ItemList i (js ++ ks)
≡⟨ subst₂ (λ t₁ t₂ → le i j && le-ItemList i (js ++ ks) ≡ t₁ && t₂)
(&&-list₂-t₁ helper₁ helper₂ helper₃)
(x≤ys→x≤zs→x≤ys++zs Ni LNjs LNks
(&&-list₂-t₂ helper₁ helper₂ helper₃)
i≤k)
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
where
helper₁ : Bool (le i j)
helper₁ = le-Bool Ni Nj
helper₂ : Bool (le-ItemList i js)
helper₂ = le-ItemList-Bool Ni LNjs
helper₃ : le i j && (le-ItemList i js) ≡ true
helper₃ = trans (sym (le-ItemList-∷ i j js)) i≤j∷js
xs≤ys→xs≤zs→xs≤ys++zs : ∀ {is js ks} → ListN is → ListN js → ListN ks →
≤-Lists is js →
≤-Lists is ks →
≤-Lists is (js ++ ks)
xs≤ys→xs≤zs→xs≤ys++zs lnnil LNjs LNks _ _ = le-Lists-[] _
xs≤ys→xs≤zs→xs≤ys++zs {js = js} {ks} (lncons {i} {is} Ni LNis)
LNjs LNks i∷is≤js i∷is≤ks =
le-Lists (i ∷ is) (js ++ ks)
≡⟨ le-Lists-∷ i is (js ++ ks) ⟩
le-ItemList i (js ++ ks) && le-Lists is (js ++ ks)
≡⟨ subst (λ t → le-ItemList i (js ++ ks) && le-Lists is (js ++ ks) ≡
t && le-Lists is (js ++ ks))
(x≤ys→x≤zs→x≤ys++zs Ni LNjs LNks
(&&-list₂-t₁ helper₁ helper₂ helper₃)
(&&-list₂-t₁ helper₄ helper₅ helper₆))
refl
⟩
true && le-Lists is (js ++ ks)
≡⟨ subst (λ t → true && le-Lists is (js ++ ks) ≡ true && t)
(xs≤ys→xs≤zs→xs≤ys++zs LNis LNjs LNks
(&&-list₂-t₂ helper₁ helper₂ helper₃)
(&&-list₂-t₂ helper₄ helper₅ helper₆))
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
where
helper₁ = le-ItemList-Bool Ni LNjs
helper₂ = le-Lists-Bool LNis LNjs
helper₃ = trans (sym (le-Lists-∷ i is js)) i∷is≤js
helper₄ = le-ItemList-Bool Ni LNks
helper₅ = le-Lists-Bool LNis LNks
helper₆ = trans (sym (le-Lists-∷ i is ks)) i∷is≤ks
xs≤zs→ys≤zs→xs++ys≤zs : ∀ {is js ks} → ListN is → ListN js → ListN ks →
≤-Lists is ks →
≤-Lists js ks →
≤-Lists (is ++ js) ks
xs≤zs→ys≤zs→xs++ys≤zs {js = js} {ks} lnnil LNjs LNks is≤ks js≤ks =
subst (λ t → ≤-Lists t ks)
(sym (++-leftIdentity js))
js≤ks
xs≤zs→ys≤zs→xs++ys≤zs {js = js} {ks}
(lncons {i} {is} Ni LNis) LNjs LNks i∷is≤ks js≤ks =
le-Lists ((i ∷ is) ++ js) ks
≡⟨ subst (λ t → le-Lists ((i ∷ is) ++ js) ks ≡ le-Lists t ks)
(++-∷ i is js)
refl
⟩
le-Lists (i ∷ (is ++ js)) ks
≡⟨ le-Lists-∷ i (is ++ js) ks ⟩
le-ItemList i ks && le-Lists (is ++ js) ks
≡⟨ subst₂ (λ x y → le-ItemList i ks && le-Lists (is ++ js) ks ≡ x && y)
≤-ItemList-i-ks
≤-Lists-is++js-ks
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
where
helper₁ = le-ItemList-Bool Ni LNks
helper₂ = le-Lists-Bool LNis LNks
helper₃ = trans (sym (le-Lists-∷ i is ks)) i∷is≤ks
≤-ItemList-i-ks : ≤-ItemList i ks
≤-ItemList-i-ks = &&-list₂-t₁ helper₁ helper₂ helper₃
≤-Lists-is++js-ks : ≤-Lists (is ++ js) ks
≤-Lists-is++js-ks =
xs≤zs→ys≤zs→xs++ys≤zs LNis LNjs LNks
(&&-list₂-t₂ helper₁ helper₂ helper₃)
js≤ks
------------------------------------------------------------------------------
-- References
--
-- Burstall, R. M. (1969). Proving properties of programs by
-- structural induction. The Computer Journal 12.1, pp. 41–48.
| 36.008584
| 79
| 0.474851
|
4a3d747c0b5042bb5b4d2044473d1c144eb0f055
| 571
|
agda
|
Agda
|
test/Succeed/Issue3309.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3309.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3309.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2018-10-23, issue #3309 reported by G. Brunerie
--
-- Check that we can use irrelevant record fields in copattern matching.
--
-- (A refactoring broke the correct relevances of pattern variables
-- after matching on an irrelevant projection pattern.)
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
.snd : B fst
open Σ
pair : {A : Set} {B : A → Set} (a : A) .(b : B a) → Σ A B
pair a b .fst = a
pair a b .snd = b
f : {A : Set} {B : A → Set} (a : A) .(b : B a) → Σ A B
fst (f a b) = a
snd (f a b) = b
-- Should work.
| 23.791667
| 72
| 0.597198
|
4173bdc37c29eda3fe4c67d4f57dc868b8120592
| 1,648
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Container.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/Data/Container.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Container.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Containers, based on the work of Abbott and others
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Data.Container where
open import Level using (_⊔_)
open import Codata.M hiding (map)
open import Data.W
open import Size
------------------------------------------------------------------------
-- Re-exporting content to maintain backwards compatibility
open import Data.Container.Core public
open import Data.Container.Relation.Unary.Any
using (◇) renaming (map to ◇-map) public
open import Data.Container.Relation.Unary.All
using (□) renaming (map to □-map) public
open import Data.Container.Membership
using (_∈_) public
open import Data.Container.Relation.Binary.Pointwise
using () renaming (Pointwise to Eq) public
open import Data.Container.Relation.Binary.Pointwise.Properties
using (refl; sym; trans) public
open import Data.Container.Relation.Binary.Equality.Setoid
using (isEquivalence; setoid) public
open import Data.Container.Properties
using () renaming (map-identity to identity; map-compose to composition) public
open import Data.Container.Related public
module Morphism where
open import Data.Container.Morphism.Properties
using (Natural; NT; natural; complete; id-correct; ∘-correct) public
open import Data.Container.Morphism
using (id; _∘_) public
-- The least and greatest fixpoints of a container.
μ : ∀ {s p} → Container s p → Set (s ⊔ p)
μ = W
ν : ∀ {s p} → Container s p → Set (s ⊔ p)
ν C = M C ∞
| 32.313725
| 81
| 0.646238
|
c560b08a1f9582c1a6e0bf953dc1269c85ff6199
| 701
|
agda
|
Agda
|
test/Succeed/Issue1596.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1596.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1596.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-06-28
-- {-# OPTIONS -v tc.polarity:20 #-}
{-# OPTIONS --sized-types #-}
open import Common.Size
-- List should be monotone in both arguments
-- (even as phantom type).
data List (i : Size) (A : Set) : Set where
[] : List i A
castL : ∀{i A} → List i A → List ∞ A
castL x = x
castLL : ∀{i A} → List i (List i A) → List ∞ (List ∞ A)
castLL x = x
-- Stream should be antitone in the first and monotone in the second argument
-- (even with field `tail' missing).
record Stream (i : Size) (A : Set) : Set where
coinductive
field
head : A
castS : ∀{i A} → Stream ∞ A → Stream i A
castS x = x
castSS : ∀{i A} → Stream ∞ (Stream ∞ A) → Stream i (Stream i A)
castSS x = x
| 21.242424
| 77
| 0.606277
|
061da231777db5bd1355e1662709cf8f9557e7b0
| 334
|
agda
|
Agda
|
src/Examples/Sorting/Sequential/Comparable.agda
|
jonsterling/agda-calf
|
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
|
[
"Apache-2.0"
] | 29
|
2021-07-14T03:18:28.000Z
|
2022-03-22T20:35:11.000Z
|
src/Examples/Sorting/Sequential/Comparable.agda
|
jonsterling/agda-calf
|
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
|
[
"Apache-2.0"
] | null | null | null |
src/Examples/Sorting/Sequential/Comparable.agda
|
jonsterling/agda-calf
|
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
|
[
"Apache-2.0"
] | 2
|
2021-10-06T10:28:24.000Z
|
2022-01-29T08:12:01.000Z
|
{-# OPTIONS --prop --rewriting #-}
module Examples.Sorting.Sequential.Comparable where
open import Calf.CostMonoid
open import Calf.CostMonoids
costMonoid = ℕ-CostMonoid
open import Data.Nat using (ℕ)
open CostMonoid costMonoid using (ℂ)
fromℕ : ℕ → ℂ
fromℕ n = n
open import Examples.Sorting.Comparable costMonoid fromℕ public
| 19.647059
| 63
| 0.775449
|
410fc1fba380510879efdb75d6548fd019c45a12
| 765
|
agda
|
Agda
|
part1/lists/reverse-involution.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | 1
|
2020-07-07T09:42:22.000Z
|
2020-07-07T09:42:22.000Z
|
part1/lists/reverse-involution.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
part1/lists/reverse-involution.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
module reverse-involution where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; cong)
open Eq.≡-Reasoning
open import lists using (List; []; _∷_; [_]; _++_; reverse)
open import reverse-++-distrib using (reverse-++-distrib)
-- reverseが対合(involution)である事の証明
reverse-involution : {A : Set} → (xs : List A)
→ reverse (reverse xs) ≡ xs
reverse-involution [] =
begin
reverse (reverse [])
≡⟨⟩
reverse []
≡⟨⟩
[]
∎
reverse-involution (x ∷ xs) =
begin
reverse (reverse (x ∷ xs))
≡⟨⟩
reverse ((reverse xs) ++ [ x ])
≡⟨ reverse-++-distrib (reverse xs) [ x ] ⟩
(reverse [ x ]) ++ (reverse (reverse xs))
≡⟨⟩
[ x ] ++ reverse (reverse xs)
≡⟨ cong (x ∷_) (reverse-involution xs) ⟩
x ∷ xs
∎
| 23.90625
| 59
| 0.6
|
0b770b23d6b49038c99f1e4ee4673d0edef3e434
| 160
|
agda
|
Agda
|
test/interaction/Issue619.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/interaction/Issue619.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/interaction/Issue619.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
open import Common.Reflect
open import Common.Prelude
data Z : Set where
zero : Z
foo : QName → Bool → Bool
foo (quote Nat.zero) b = {!b!}
foo _ _ = false
| 14.545455
| 30
| 0.66875
|
1d8a07eba8b2e69f7fc305589a6001685beb4462
| 2,029
|
agda
|
Agda
|
Definition/Typed/EqRelInstance.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/Typed/EqRelInstance.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/Typed/EqRelInstance.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
module Definition.Typed.EqRelInstance where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening
open import Definition.Typed.Properties
open import Definition.Typed.Reduction
open import Definition.Typed.EqualityRelation
open import Tools.Function
Urefl : ∀ {r l Γ} → ⊢ Γ → Γ ⊢ (Univ r l) ≡ (Univ r l) ^ [ ! , next l ]
Urefl {l = ⁰} ⊢Γ = refl (univ (univ 0<1 ⊢Γ))
Urefl {l = ¹} ⊢Γ = refl (Uⱼ ⊢Γ)
instance eqRelInstance : EqRelSet
eqRelInstance = eqRel _⊢_≡_^_ _⊢_≡_∷_^_ _⊢_≡_∷_^_
idᶠ idᶠ idᶠ univ un-univ≡
sym genSym genSym trans genTrans genTrans
conv conv wkEq wkEqTerm wkEqTerm
reduction reductionₜ
Urefl (refl ∘ᶠ univ 0<1) (refl ∘ᶠ ℕⱼ) (refl ∘ᶠ Emptyⱼ)
Π-cong ∃-cong (refl ∘ᶠ zeroⱼ) suc-cong
(λ lF lG x x₁ x₂ x₃ x₄ x₅ → η-eq lF lG x x₁ x₂ x₅)
genVar app-cong natrec-cong Emptyrec-cong
Id-cong
(λ ⊢Γ → Id-cong (refl (ℕⱼ ⊢Γ)))
(λ ⊢Γ → Id-cong (refl (ℕⱼ ⊢Γ)) (refl (zeroⱼ ⊢Γ)))
(λ ⊢Γ t → Id-cong (refl (ℕⱼ ⊢Γ)) (suc-cong t))
(λ ⊢Γ → Id-cong (refl (univ 0<1 ⊢Γ)))
(λ ⊢Γ → Id-cong (refl (univ 0<1 ⊢Γ)) (refl (ℕⱼ ⊢Γ)))
(λ ⊢A B → Id-cong (refl (univ 0<1 (wfEq (univ ⊢A)))) ⊢A B)
cast-cong
(λ ⊢Γ → cast-cong (refl (ℕⱼ ⊢Γ)))
(λ ⊢Γ → cast-cong (refl (ℕⱼ ⊢Γ)) (refl (ℕⱼ ⊢Γ)))
cast-cong
(λ ⊢A ⊢P P → cast-cong (refl (ℕⱼ (wf (univ ⊢A)))) P)
(λ ⊢A ⊢P P → cast-cong P (refl (ℕⱼ (wf (univ ⊢A)))))
(λ ⊢A ⊢P P ⊢A' ⊢P' P' → cast-cong P P')
(λ ⊢A ⊢P P ⊢A' ⊢P' P' → cast-cong P P')
proof-irrelevance
| 45.088889
| 81
| 0.473632
|
4a4d646da79ae4a7a226bf686946374cced664d9
| 2,479
|
agda
|
Agda
|
agda-stdlib/src/Data/List/NonEmpty/Categorical.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/Categorical.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/NonEmpty/Categorical.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A categorical view of List⁺
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.NonEmpty.Categorical where
open import Agda.Builtin.List
import Data.List.Categorical as List
open import Data.List.NonEmpty
open import Data.Product using (uncurry)
open import Category.Functor
open import Category.Applicative
open import Category.Monad
open import Category.Comonad
open import Function
------------------------------------------------------------------------
-- List⁺ applicative functor
functor : ∀ {f} → RawFunctor {f} List⁺
functor = record
{ _<$>_ = map
}
applicative : ∀ {f} → RawApplicative {f} List⁺
applicative = record
{ pure = [_]
; _⊛_ = λ fs as → concatMap (λ f → map f as) fs
}
------------------------------------------------------------------------
-- List⁺ monad
monad : ∀ {f} → RawMonad {f} List⁺
monad = record
{ return = [_]
; _>>=_ = flip concatMap
}
------------------------------------------------------------------------
-- List⁺ comonad
comonad : ∀ {f} → RawComonad {f} List⁺
comonad = record
{ extract = head
; extend = λ f → uncurry (extend f) ∘′ uncons
} where
extend : ∀ {A B} → (List⁺ A → B) → A → List A → List⁺ B
extend f x xs@[] = f (x ∷ xs) ∷ []
extend f x xs@(y ∷ ys) = f (x ∷ xs) ∷⁺ extend f y ys
------------------------------------------------------------------------
-- Get access to other monadic functions
module TraversableA {f F} (App : RawApplicative {f} F) where
open RawApplicative App
sequenceA : ∀ {A} → List⁺ (F A) → F (List⁺ A)
sequenceA (x ∷ xs) = _∷_ <$> x ⊛ List.TraversableA.sequenceA App xs
mapA : ∀ {a} {A : Set a} {B} → (A → F B) → List⁺ A → F (List⁺ B)
mapA f = sequenceA ∘ map f
forA : ∀ {a} {A : Set a} {B} → List⁺ A → (A → F B) → F (List⁺ B)
forA = flip mapA
module TraversableM {m M} (Mon : RawMonad {m} M) where
open RawMonad Mon
open TraversableA rawIApplicative public
renaming
( sequenceA to sequenceM
; mapA to mapM
; forA to forM
)
------------------------------------------------------------------------
-- List⁺ monad transformer
monadT : ∀ {f} → RawMonadT {f} (_∘′ List⁺)
monadT M = record
{ return = pure ∘′ [_]
; _>>=_ = λ mas f → mas >>= λ as → concat <$> mapM f as
} where open RawMonad M; open TraversableM M
| 26.655914
| 72
| 0.486083
|
0b5986de697c1d0508f8b24d4ded49cc3d7faac9
| 2,176
|
agda
|
Agda
|
Categories/Morphism/Properties.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Morphism/Properties.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Morphism/Properties.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Morphism.Properties {o ℓ e} (𝒞 : Category o ℓ e) where
open import Data.Product using (_,_; _×_)
open Category 𝒞
open HomReasoning
import Categories.Morphism as M
open M 𝒞
open import Categories.Morphism.Reasoning 𝒞
private
variable
A B C D : Obj
f g h i : A ⇒ B
module _ (iso : Iso f g) where
open Iso iso
Iso-resp-≈ : f ≈ h → g ≈ i → Iso h i
Iso-resp-≈ {h = h} {i = i} eq₁ eq₂ = record
{ isoˡ = begin
i ∘ h ≈˘⟨ eq₂ ⟩∘⟨ eq₁ ⟩
g ∘ f ≈⟨ isoˡ ⟩
id ∎
; isoʳ = begin
h ∘ i ≈˘⟨ eq₁ ⟩∘⟨ eq₂ ⟩
f ∘ g ≈⟨ isoʳ ⟩
id ∎
}
Iso-swap : Iso g f
Iso-swap = record
{ isoˡ = isoʳ
; isoʳ = isoˡ
}
Iso⇒Mono : Mono f
Iso⇒Mono h i eq = begin
h ≈⟨ introˡ isoˡ ⟩
(g ∘ f) ∘ h ≈⟨ pullʳ eq ⟩
g ∘ f ∘ i ≈⟨ cancelˡ isoˡ ⟩
i ∎
Iso⇒Epi : Epi f
Iso⇒Epi h i eq = begin
h ≈⟨ introʳ isoʳ ⟩
h ∘ f ∘ g ≈⟨ pullˡ eq ⟩
(i ∘ f) ∘ g ≈⟨ cancelʳ isoʳ ⟩
i ∎
Iso-∘ : Iso f g → Iso h i → Iso (h ∘ f) (g ∘ i)
Iso-∘ {f = f} {g = g} {h = h} {i = i} iso iso′ = record
{ isoˡ = begin
(g ∘ i) ∘ h ∘ f ≈⟨ cancelInner (isoˡ iso′) ⟩
g ∘ f ≈⟨ isoˡ iso ⟩
id ∎
; isoʳ = begin
(h ∘ f) ∘ g ∘ i ≈⟨ cancelInner (isoʳ iso) ⟩
h ∘ i ≈⟨ isoʳ iso′ ⟩
id ∎
}
where open Iso
Iso-≈ : f ≈ h → Iso f g → Iso h i → g ≈ i
Iso-≈ {f = f} {h = h} {g = g} {i = i} eq iso iso′ = begin
g ≈⟨ introˡ (isoˡ iso′) ⟩
(i ∘ h) ∘ g ≈˘⟨ (refl ⟩∘⟨ eq) ⟩∘⟨refl ⟩
(i ∘ f) ∘ g ≈⟨ cancelʳ (isoʳ iso) ⟩
i ∎
where open Iso
module _ where
open _≅_
isos×≈⇒≈ : ∀ {f g : A ⇒ B} → h ≈ i → (iso₁ : A ≅ C) → (iso₂ : B ≅ D) →
CommutativeSquare f (from iso₁) (from iso₂) h →
CommutativeSquare g (from iso₁) (from iso₂) i →
f ≈ g
isos×≈⇒≈ {h = h} {i = i} {f = f} {g = g} eq iso₁ iso₂ sq₁ sq₂ = begin
f ≈⟨ switch-fromtoˡ iso₂ sq₁ ⟩
to iso₂ ∘ h ∘ from iso₁ ≈⟨ refl⟩∘⟨ (eq ⟩∘⟨refl ) ⟩
to iso₂ ∘ i ∘ from iso₁ ≈˘⟨ switch-fromtoˡ iso₂ sq₂ ⟩
g ∎
| 24.449438
| 72
| 0.463235
|
0be2bf4cbaae8e6e9858d063887dba29c1fdd228
| 134
|
agda
|
Agda
|
archive/agda-1/HasNeitherNor.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/HasNeitherNor.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/HasNeitherNor.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module HasNeitherNor where
record HasNeitherNor (A : Set) : Set
where
field
_⊗_ : A → A → A
open HasNeitherNor ⦃ … ⦄ public
| 13.4
| 36
| 0.656716
|
293d6a26a10231b985030ce434a7032b4c224c6f
| 599
|
agda
|
Agda
|
examples/outdated-and-incorrect/univ/tmp.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/outdated-and-incorrect/univ/tmp.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/univ/tmp.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module tmp where
open import univ
open import cwf
open import Base
open import Nat
open import help
open import proofs
{- TODO: Prove
w = ƛ ((w // wk) ∙ vz) (η)
ƛ v // σ = ƛ (v // (σ ∘ wk ,, vz))
w ∙ u // σ = (w // σ) ∙ (u // σ)
-}
{-
lem-tmp : {Γ : Con}{A : Type Γ}(B : Type (Γ , A)) ->
Π A B =Ty Π A (B / (wk ∘ wk ,, castElem ? vz) / [ vz ])
lem-tmp B = ?
lem-η : {Γ : Con}{A : Type Γ}{B : Type (Γ , A)}(w : Elem Γ (Π A B)) ->
w =El castElem (lem-tmp B)
(ƛ {A = A}
(castElem (symTy (lem-Π/ B wk)) (w // wk {A = A}) ∙ vz)
)
lem-η (elem (el < w , pw >)) = ?
-}
| 18.71875
| 70
| 0.462437
|
127fd24d80eec13e858c02c085dfba927ef5bd94
| 20,635
|
agda
|
Agda
|
agda/Esterel/Lang/CanFunction/MergePotentialRuleTheta.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/Esterel/Lang/CanFunction/MergePotentialRuleTheta.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/Esterel/Lang/CanFunction/MergePotentialRuleTheta.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
{-
The equivalent "goodness" of can-θ w.r.t. the rmerge reduction.
The main properties of the Can function proved in this file are:
canθₛ-mergeˡ : ∀ {E θ' r p BV FV} sigs θ →
CorrectBinding p BV FV →
p ≐ E ⟦ ρ θ' · r ⟧e →
∀ S' →
Signal.unwrap S' ∉ SigMap.keys (Env.sig θ') →
Signal.unwrap S' ∈ Canθₛ (SigMap.union sigs (Env.sig θ')) 0 (E ⟦ r ⟧e) θ →
Signal.unwrap S' ∈ Canθₛ sigs 0 p θ
canθₛ-mergeʳ : ∀ sigs θ' r θ →
distinct' (proj₁ (Dom θ)) (SigMap.keys sigs) →
∀ S' →
Signal.unwrap S' ∈ Canθₛ (SigMap.union sigs (Env.sig θ')) 0 r θ →
Signal.unwrap S' ∈ Canθₛ (Env.sig θ') 0 r θ
and their corresponding counterparts for the shared variables.
-}
module Esterel.Lang.CanFunction.MergePotentialRuleTheta where
open import utility
renaming (_U̬_ to _∪_ ; _|̌_ to _-_)
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Base
open import Esterel.Lang.CanFunction.CanThetaContinuation
open import Esterel.Lang.CanFunction.MergePotentialRuleLeftInductive
open import Esterel.Lang.CanFunction.NonMergePotentialRules
open import Esterel.Context
using (EvaluationContext1 ; EvaluationContext ; _⟦_⟧e ; _≐_⟦_⟧e)
open import Esterel.Context.Properties
using (plug ; unplug)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open EvaluationContext1
open _≐_⟦_⟧e
open import Data.Bool
using (Bool ; not ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; [] ; _∷_ ; _++_ ; map ; concatMap ; foldr)
open import Data.List.Properties
using (map-id)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _≟_ ; _+_)
open import Data.Nat.Properties.Simple
using (+-comm)
open import Data.Product
using (Σ ; proj₁ ; proj₂ ; ∃ ; _,_ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; _≢_ ; refl ; trans ; sym ; cong ; subst ; module ≡-Reasoning)
open ListSet Data.Nat._≟_
using (set-subtract ; set-subtract-[] ; set-subtract-split ; set-subtract-merge
; set-subtract-notin
; set-remove ; set-remove-mono-∈ ; set-remove-removed ; set-remove-not-removed
; set-subtract-[a]≡set-remove)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ≡-Reasoning
canθₖ-mergeˡ : ∀ {E θ' r p BV FV A} sigs θ →
CorrectBinding p BV FV →
p ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e →
∀ k →
k ∈ Canθₖ (SigMap.union sigs (Env.sig θ')) 0 (E ⟦ r ⟧e) θ →
k ∈ Canθₖ sigs 0 p θ
canθₖ-mergeˡ {E} {θ'} {r} {A = A} sigs θ cb p≐E⟦ρθ'r⟧ k k∈canθ-sigs←θ'-E⟦r⟧-θ
rewrite sym (unplug p≐E⟦ρθ'r⟧)
with binding-extract cb (((E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ∋ plug refl)
... | (BVp , FVp) , (BVp⊆BV , FVp⊆FV) , cbρθ'r@(CBρ cbp)
with binding-subst cb (((E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ∋ plug refl) cbρθ'r
((λ _ ()) ,′ (λ _ ()) ,′ (λ _ ()))
((λ _ ()) ,′ (λ _ ()) ,′ (λ _ ()))
CBnothing
... | (BV' , FV') , (BVnothin⊆BV , FVnothin⊆FV) , cbnothin
rewrite canθ'-←-distribute sigs (Env.sig θ') 0 (E ⟦ r ⟧e) θ =
canθₖ-mergeˡ-sigs-induction sigs 0 (Env.sig θ') (Env.shr θ') (Env.var θ') r θ
((E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e) ∋ plug refl) cbnothin
(distinct'-sym
(dist'++ˡ
(distinct'-sym
(proj₁
(distinct-term-context-help (ρ⟨ θ' , A ⟩· r) E cb cbρθ'r BVp⊆BV cbnothin)))))
k k∈canθ-sigs←θ'-E⟦r⟧-θ
canθₛ-mergeˡ : ∀ {E θ' r p BV FV A} sigs θ →
CorrectBinding p BV FV →
p ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e →
∀ S' →
Signal.unwrap S' ∉ SigMap.keys (Env.sig θ') →
Signal.unwrap S' ∈ Canθₛ (SigMap.union sigs (Env.sig θ')) 0 (E ⟦ r ⟧e) θ →
Signal.unwrap S' ∈ Canθₛ sigs 0 p θ
canθₛ-mergeˡ {E} {θ'} {r} {A = A} sigs θ cb p≐E⟦ρθ'r⟧ S' S'∉Domθ' S'∈canθ-sigs←θ'-E⟦r⟧-θ
rewrite sym (unplug p≐E⟦ρθ'r⟧)
with binding-extract cb (((E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ∋ plug refl)
... | (BVp , FVp) , (BVp⊆BV , FVp⊆FV) , cbρθ'r@(CBρ cbp)
with binding-subst cb (((E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ∋ plug refl) cbρθ'r
((λ _ ()) ,′ (λ _ ()) ,′ (λ _ ()))
((λ _ ()) ,′ (λ _ ()) ,′ (λ _ ()))
CBnothing
... | (BV' , FV') , (BVnothin⊆BV , FVnothin⊆FV) , cbnothin
rewrite canθ'-←-distribute sigs (Env.sig θ') 0 (E ⟦ r ⟧e) θ =
canθₛ-mergeˡ-sigs-induction sigs 0 (Env.sig θ') (Env.shr θ') (Env.var θ') r θ
((E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e) ∋ plug refl) cbnothin
(distinct'-sym
(dist'++ˡ
(distinct'-sym
(proj₁
(distinct-term-context-help (ρ⟨ θ' , A ⟩· r) E cb cbρθ'r BVp⊆BV cbnothin)))))
(Signal.unwrap S')
S'∉Domθ' S'∈canθ-sigs←θ'-E⟦r⟧-θ
canθₛₕ-mergeˡ : ∀ {E θ' r p BV FV A} sigs θ →
CorrectBinding p BV FV →
p ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e →
∀ s' →
SharedVar.unwrap s' ∉ ShrMap.keys (Env.shr θ') →
SharedVar.unwrap s' ∈ Canθₛₕ (SigMap.union sigs (Env.sig θ')) 0 (E ⟦ r ⟧e) θ →
SharedVar.unwrap s' ∈ Canθₛₕ sigs 0 p θ
canθₛₕ-mergeˡ {E} {θ'} {r} {A = A} sigs θ cb p≐E⟦ρθ'r⟧ s' s'∉Domθ' s'∈canθ-sigs←θ'-E⟦r⟧-θ
rewrite sym (unplug p≐E⟦ρθ'r⟧)
with binding-extract cb (((E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ∋ plug refl)
... | (BVp , FVp) , (BVp⊆BV , FVp⊆FV) , cbρθ'r@(CBρ cbp)
with binding-subst cb (((E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ≐ E ⟦ ρ⟨ θ' , A ⟩· r ⟧e) ∋ plug refl) cbρθ'r
((λ _ ()) ,′ (λ _ ()) ,′ (λ _ ()))
((λ _ ()) ,′ (λ _ ()) ,′ (λ _ ()))
CBnothing
... | (BV' , FV') , (BVnothin⊆BV , FVnothin⊆FV) , cbnothin
rewrite canθ'-←-distribute sigs (Env.sig θ') 0 (E ⟦ r ⟧e) θ =
canθₛₕ-mergeˡ-sigs-induction sigs 0 (Env.sig θ') (Env.shr θ') (Env.var θ') r θ
((E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e) ∋ plug refl) cbnothin
(distinct'-sym
(dist'++ˡ
(distinct'-sym
(proj₁
(distinct-term-context-help (ρ⟨ θ' , A ⟩· r) E cb cbρθ'r BVp⊆BV cbnothin)))))
(SharedVar.unwrap s')
s'∉Domθ' s'∈canθ-sigs←θ'-E⟦r⟧-θ
canθₛ-mergeʳ-add-sig-notin : ∀ sigs' r θ S status →
S ∉ proj₁ (Dom θ) →
S ∉ SigMap.keys sigs' →
∀ S'' →
S'' ∈ Canθₛ sigs' 0 r (θ ← [ (S ₛ) ↦ status ]) →
S'' ∈ Canθₛ sigs' 0 r θ
canθₛ-mergeʳ-add-sig-notin sigs' r θ S status S∉Domθ S∉sigs'
S'' S''∈canθ-sigs'-r-θ←[S]
rewrite canθ-is-unknown-lemma sigs' 0 r θ (S ₛ) S∉Domθ
(subst (S ∉_)
(sym (map-id (SigMap.keys sigs')))
S∉sigs')
= canθₛ-add-sig-monotonic sigs' 0 r θ (S ₛ) status
S'' S''∈canθ-sigs'-r-θ←[S]
canθₛ-mergeʳ-sigs-induction : ∀ sigs S sigs' r θ →
distinct' (proj₁ (Dom θ)) (map (_+_ S) (SigMap.keys sigs)) →
∀ S'' →
S'' ∈ proj₁ (Canθ' sigs S (Canθ sigs' 0 r) θ) →
S'' ∈ proj₁ (Canθ sigs' 0 r θ)
canθₛ-mergeʳ-sigs-induction [] S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
= S''∈canθ'-sigs-canθ-sigs'-r-θ
canθₛ-mergeʳ-sigs-induction (nothing ∷ sigs) S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
rewrite map-+-compose-suc S (SigMap.keys sigs)
= canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
canθₛ-mergeʳ-sigs-induction (just Signal.present ∷ sigs) S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.present θ S∈sigs'
= canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛ-mergeʳ-add-sig-notin sigs' r θ S Signal.present
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' S''
(canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env-present (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.present S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env-present (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛ-mergeʳ-sigs-induction (just Signal.absent ∷ sigs) S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.absent θ S∈sigs'
= canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛ-mergeʳ-add-sig-notin sigs' r θ S Signal.absent
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' S''
(canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env-absent (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.absent S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env-absent (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛ-mergeʳ-sigs-induction (just Signal.unknown ∷ sigs) S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
with any (_≟_ S) (proj₁ (Canθ' sigs (suc S) (Canθ sigs' 0 r) (θ ← [S]-env (S ₛ))))
canθₛ-mergeʳ-sigs-induction (just Signal.unknown ∷ sigs) S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
| yes S∈canθ'-sigs-canθ-sigs'-r-θ←[S]
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.unknown θ S∈sigs'
= canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛ-mergeʳ-add-sig-notin sigs' r θ S Signal.unknown
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' S''
(canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.unknown S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛ-mergeʳ-sigs-induction (just Signal.unknown ∷ sigs) S sigs' r θ θ≠sigs
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
| no S∉canθ'-sigs-canθ-sigs'-r-θ←[S]
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.absent θ S∈sigs'
= canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) S'' S''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛ-mergeʳ-add-sig-notin sigs' r θ S Signal.absent
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' S''
(canθₛ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env-absent (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.absent S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env-absent (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
S'' S''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛ-mergeʳ : ∀ sigs θ' r θ →
distinct' (proj₁ (Dom θ)) (SigMap.keys sigs) →
∀ S' →
Signal.unwrap S' ∈ Canθₛ (SigMap.union sigs (Env.sig θ')) 0 r θ →
Signal.unwrap S' ∈ Canθₛ (Env.sig θ') 0 r θ
canθₛ-mergeʳ sigs θ' r θ θ≠sigs S' S'∈canθ-sigs←θ'-r-θ
rewrite canθ'-←-distribute sigs (Env.sig θ') 0 r θ
= canθₛ-mergeʳ-sigs-induction sigs 0 (Env.sig θ') r θ
(subst (distinct' _) (sym (map-id (SigMap.keys sigs))) θ≠sigs)
(Signal.unwrap S') S'∈canθ-sigs←θ'-r-θ
canθₛₕ-mergeʳ-add-sig-notin : ∀ sigs' r θ S status →
S ∉ proj₁ (Dom θ) →
S ∉ SigMap.keys sigs' →
∀ s'' →
s'' ∈ Canθₛₕ sigs' 0 r (θ ← [ (S ₛ) ↦ status ]) →
s'' ∈ Canθₛₕ sigs' 0 r θ
canθₛₕ-mergeʳ-add-sig-notin sigs' r θ S status S∉Domθ S∉sigs'
s'' s''∈canθ-sigs'-r-θ←[S]
rewrite canθ-is-unknown-lemma sigs' 0 r θ (S ₛ) S∉Domθ
(subst (S ∉_)
(sym (map-id (SigMap.keys sigs')))
S∉sigs')
= canθₛₕ-add-sig-monotonic sigs' 0 r θ (S ₛ) status
s'' s''∈canθ-sigs'-r-θ←[S]
canθₛₕ-mergeʳ-sigs-induction : ∀ sigs S sigs' r θ →
distinct' (proj₁ (Dom θ)) (map (_+_ S) (SigMap.keys sigs)) →
∀ s'' →
s'' ∈ proj₂ (proj₂ (Canθ' sigs S (Canθ sigs' 0 r) θ)) →
s'' ∈ proj₂ (proj₂ (Canθ sigs' 0 r θ))
canθₛₕ-mergeʳ-sigs-induction [] S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
= s''∈canθ'-sigs-canθ-sigs'-r-θ
canθₛₕ-mergeʳ-sigs-induction (nothing ∷ sigs) S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
rewrite map-+-compose-suc S (SigMap.keys sigs)
= canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
canθₛₕ-mergeʳ-sigs-induction (just Signal.present ∷ sigs) S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.present θ S∈sigs'
= canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛₕ-mergeʳ-add-sig-notin sigs' r θ S Signal.present
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' s''
(canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env-present (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.present S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env-present (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛₕ-mergeʳ-sigs-induction (just Signal.absent ∷ sigs) S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.absent θ S∈sigs'
= canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛₕ-mergeʳ-add-sig-notin sigs' r θ S Signal.absent
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' s''
(canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env-absent (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.absent S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env-absent (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛₕ-mergeʳ-sigs-induction (just Signal.unknown ∷ sigs) S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
with any (_≟_ S) (proj₁ (Canθ' sigs (suc S) (Canθ sigs' 0 r) (θ ← [S]-env (S ₛ))))
canθₛₕ-mergeʳ-sigs-induction (just Signal.unknown ∷ sigs) S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
| yes S∈canθ'-sigs-canθ-sigs'-r-θ←[S]
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.unknown θ S∈sigs'
= canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛₕ-mergeʳ-add-sig-notin sigs' r θ S Signal.unknown
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' s''
(canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.unknown S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛₕ-mergeʳ-sigs-induction (just Signal.unknown ∷ sigs) S sigs' r θ θ≠sigs
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
| no S∉canθ'-sigs-canθ-sigs'-r-θ←[S]
rewrite map-+-compose-suc S (SigMap.keys sigs)
with any (_≟_ S) (SigMap.keys sigs')
... | yes S∈sigs'
rewrite canθ'-inner-shadowing-irr sigs (suc S) sigs' r S Signal.absent θ S∈sigs'
= canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r θ
(dist'++ʳ {V2 = S + 0 ∷ []} θ≠sigs) s'' s''∈canθ'-sigs-canθ-sigs'-r-θ
... | no S∉sigs'
rewrite +-comm S 0
= canθₛₕ-mergeʳ-add-sig-notin sigs' r θ S Signal.absent
(λ S∈Domθ → θ≠sigs S S∈Domθ (here refl)) S∉sigs' s''
(canθₛₕ-mergeʳ-sigs-induction sigs (suc S) sigs' r (θ ← [S]-env-absent (S ₛ))
(λ S'' S''∈Domθ←[S] S''∈map-+-suc-S-sigs → -- TODO: should make this a function
Data.Sum.[ (λ S''∈Domθ → θ≠sigs S'' S''∈Domθ (there S''∈map-+-suc-S-sigs)) ,
(λ S''∈[S] →
subst (_∉ _)
(sym (Env.sig-single-∈-eq (S'' ₛ) (S ₛ) Signal.absent S''∈[S]))
(n∉map-suc-n-+ S (SigMap.keys sigs))
S''∈map-+-suc-S-sigs) ]
(Env.sig-←⁻ {θ} {[S]-env-absent (S ₛ)} (S'' ₛ) S''∈Domθ←[S]))
s'' s''∈canθ'-sigs-canθ-sigs'-r-θ)
canθₛₕ-mergeʳ : ∀ sigs θ' r θ →
distinct' (proj₁ (Dom θ)) (SigMap.keys sigs) →
∀ s' →
SharedVar.unwrap s' ∈ Canθₛₕ (SigMap.union sigs (Env.sig θ')) 0 r θ →
SharedVar.unwrap s' ∈ Canθₛₕ (Env.sig θ') 0 r θ
canθₛₕ-mergeʳ sigs θ' r θ θ≠sigs s' s'∈canθ-sigs←θ'-r-θ
rewrite canθ'-←-distribute sigs (Env.sig θ') 0 r θ
= canθₛₕ-mergeʳ-sigs-induction sigs 0 (Env.sig θ') r θ
(subst (distinct' _) (sym (map-id (SigMap.keys sigs))) θ≠sigs)
(SharedVar.unwrap s') s'∈canθ-sigs←θ'-r-θ
| 45.957684
| 97
| 0.551054
|
59f4c0896c60a4b6bcd0b1e5bb9cc252a5888852
| 8,572
|
agda
|
Agda
|
Cubical/Algebra/Semilattice/Base.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semilattice/Base.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semilattice/Base.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-
following Johnstone's book "Stone Spaces" we define semilattices
to be commutative monoids such that every element is idempotent.
In particular, we take every semilattice to have a neutral element
that is either the maximal or minimal element depending on whether
we have a join or meet semilattice.
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Semilattice.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.CommMonoid
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Reflection.RecordEquiv
open Iso
private
variable
ℓ ℓ' : Level
record IsSemilattice {A : Type ℓ} (ε : A) (_·_ : A → A → A) : Type ℓ where
constructor issemilattice
field
isCommMonoid : IsCommMonoid ε _·_
idem : (x : A) → x · x ≡ x
open IsCommMonoid isCommMonoid public
unquoteDecl IsSemilatticeIsoΣ = declareRecordIsoΣ IsSemilatticeIsoΣ (quote IsSemilattice)
record SemilatticeStr (A : Type ℓ) : Type ℓ where
constructor semilatticestr
field
ε : A
_·_ : A → A → A
isSemilattice : IsSemilattice ε _·_
infixl 7 _·_
open IsSemilattice isSemilattice public
Semilattice : ∀ ℓ → Type (ℓ-suc ℓ)
Semilattice ℓ = TypeWithStr ℓ SemilatticeStr
semilattice : (A : Type ℓ) (ε : A) (_·_ : A → A → A) (h : IsSemilattice ε _·_) → Semilattice ℓ
semilattice A ε _·_ h = A , semilatticestr ε _·_ h
-- Easier to use constructors
makeIsSemilattice : {L : Type ℓ} {ε : L} {_·_ : L → L → L}
(is-setL : isSet L)
(assoc : (x y z : L) → x · (y · z) ≡ (x · y) · z)
(rid : (x : L) → x · ε ≡ x)
(lid : (x : L) → ε · x ≡ x)
(comm : (x y : L) → x · y ≡ y · x)
(idem : (x : L) → x · x ≡ x)
→ IsSemilattice ε _·_
IsSemilattice.isCommMonoid (makeIsSemilattice is-setL assoc rid lid comm idem) =
makeIsCommMonoid is-setL assoc rid comm
IsSemilattice.idem (makeIsSemilattice is-setL assoc rid lid comm idem) = idem
makeSemilattice : {L : Type ℓ} (ε : L) (_·_ : L → L → L)
(is-setL : isSet L)
(assoc : (x y z : L) → x · (y · z) ≡ (x · y) · z)
(rid : (x : L) → x · ε ≡ x)
(lid : (x : L) → ε · x ≡ x)
(comm : (x y : L) → x · y ≡ y · x)
(idem : (x : L) → x · x ≡ x)
→ Semilattice ℓ
makeSemilattice ε _·_ is-setL assoc rid lid comm idem =
semilattice _ ε _·_ (makeIsSemilattice is-setL assoc rid lid comm idem)
SemilatticeStr→MonoidStr : {A : Type ℓ} → SemilatticeStr A → MonoidStr A
SemilatticeStr→MonoidStr (semilatticestr _ _ H) =
monoidstr _ _ (H .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid)
Semilattice→Monoid : Semilattice ℓ → Monoid ℓ
Semilattice→Monoid (_ , semilatticestr _ _ H) =
_ , monoidstr _ _ (H .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid)
Semilattice→CommMonoid : Semilattice ℓ → CommMonoid ℓ
Semilattice→CommMonoid (_ , semilatticestr _ _ H) =
_ , commmonoidstr _ _ (H .IsSemilattice.isCommMonoid)
SemilatticeHom : (L : Semilattice ℓ) (M : Semilattice ℓ') → Type (ℓ-max ℓ ℓ')
SemilatticeHom L M = MonoidHom (Semilattice→Monoid L) (Semilattice→Monoid M)
IsSemilatticeEquiv : {A : Type ℓ} {B : Type ℓ'}
(M : SemilatticeStr A) (e : A ≃ B) (N : SemilatticeStr B) → Type (ℓ-max ℓ ℓ')
IsSemilatticeEquiv M e N =
IsMonoidHom (SemilatticeStr→MonoidStr M) (e .fst) (SemilatticeStr→MonoidStr N)
SemilatticeEquiv : (M : Semilattice ℓ) (N : Semilattice ℓ') → Type (ℓ-max ℓ ℓ')
SemilatticeEquiv M N = Σ[ e ∈ (M .fst ≃ N .fst) ] IsSemilatticeEquiv (M .snd) e (N .snd)
isPropIsSemilattice : {L : Type ℓ} (ε : L) (_·_ : L → L → L)
→ isProp (IsSemilattice ε _·_)
isPropIsSemilattice ε _·_ (issemilattice LL LC) (issemilattice SL SC) =
λ i → issemilattice (isPropIsCommMonoid _ _ LL SL i) (isPropIdem LC SC i)
where
isSetL : isSet _
isSetL = LL .IsCommMonoid.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropIdem : isProp ((x : _) → x · x ≡ x)
isPropIdem = isPropΠ λ _ → isSetL _ _
𝒮ᴰ-Semilattice : DUARel (𝒮-Univ ℓ) SemilatticeStr ℓ
𝒮ᴰ-Semilattice =
𝒮ᴰ-Record (𝒮-Univ _) IsSemilatticeEquiv
(fields:
data[ ε ∣ autoDUARel _ _ ∣ presε ]
data[ _·_ ∣ autoDUARel _ _ ∣ pres· ]
prop[ isSemilattice ∣ (λ _ _ → isPropIsSemilattice _ _) ])
where
open SemilatticeStr
open IsMonoidHom
SemilatticePath : (L K : Semilattice ℓ) → SemilatticeEquiv L K ≃ (L ≡ K)
SemilatticePath = ∫ 𝒮ᴰ-Semilattice .UARel.ua
-- TODO: decide if that's the right approach
module JoinSemilattice (L' : Semilattice ℓ) where
private L = fst L'
open SemilatticeStr (snd L') renaming (_·_ to _∨l_ ; ε to 1l)
open CommMonoidTheory (Semilattice→CommMonoid L')
_≤_ : L → L → Type ℓ
x ≤ y = x ∨l y ≡ y
infix 4 _≤_
IndPoset : Poset ℓ ℓ
fst IndPoset = L
PosetStr._≤_ (snd IndPoset) = _≤_
IsPoset.is-set (PosetStr.isPoset (snd IndPoset)) = is-set
IsPoset.is-prop-valued (PosetStr.isPoset (snd IndPoset)) = λ _ _ → is-set _ _
IsPoset.is-refl (PosetStr.isPoset (snd IndPoset)) = idem
IsPoset.is-trans (PosetStr.isPoset (snd IndPoset)) = path
where
path : (a b c : L) → a ∨l b ≡ b → b ∨l c ≡ c → a ∨l c ≡ c
path a b c a∨b≡b b∨c≡c = a ∨l c ≡⟨ cong (a ∨l_) (sym b∨c≡c) ⟩
a ∨l (b ∨l c) ≡⟨ ·Assoc _ _ _ ⟩
(a ∨l b) ∨l c ≡⟨ cong (_∨l c) a∨b≡b ⟩
b ∨l c ≡⟨ b∨c≡c ⟩
c ∎
IsPoset.is-antisym (PosetStr.isPoset (snd IndPoset)) =
λ _ _ a∨b≡b b∨a≡a → sym b∨a≡a ∙∙ ·Comm _ _ ∙∙ a∨b≡b
∨lIsMax : ∀ x y z → x ≤ z → y ≤ z → x ∨l y ≤ z
∨lIsMax x y z x≤z y≤z = cong ((x ∨l y) ∨l_) (sym (idem z)) ∙ commAssocSwap x y z z
∙ cong₂ (_∨l_) x≤z y≤z
∙ idem z
∨≤LCancel : ∀ x y → y ≤ x ∨l y
∨≤LCancel x y = commAssocl y x y ∙ cong (x ∨l_) (idem y)
∨≤RCancel : ∀ x y → x ≤ x ∨l y
∨≤RCancel x y = ·Assoc _ _ _ ∙ cong (_∨l y) (idem x)
≤-∨Pres : ∀ x y u w → x ≤ y → u ≤ w → x ∨l u ≤ y ∨l w
≤-∨Pres x y u w x≤y u≤w = commAssocSwap x u y w ∙ cong₂ (_∨l_) x≤y u≤w
≤-∨LPres : ∀ x y z → x ≤ y → z ∨l x ≤ z ∨l y
≤-∨LPres x y z x≤y = ≤-∨Pres _ _ _ _ (idem z) x≤y
module MeetSemilattice (L' : Semilattice ℓ) where
private L = fst L'
open SemilatticeStr (snd L') renaming (_·_ to _∧l_ ; ε to 0l)
open CommMonoidTheory (Semilattice→CommMonoid L')
_≤_ : L → L → Type ℓ
x ≤ y = x ∧l y ≡ x
infix 4 _≤_
IndPoset : Poset ℓ ℓ
fst IndPoset = L
PosetStr._≤_ (snd IndPoset) = _≤_
IsPoset.is-set (PosetStr.isPoset (snd IndPoset)) = is-set
IsPoset.is-prop-valued (PosetStr.isPoset (snd IndPoset)) = λ _ _ → is-set _ _
IsPoset.is-refl (PosetStr.isPoset (snd IndPoset)) = idem
IsPoset.is-trans (PosetStr.isPoset (snd IndPoset)) = path
where
path : (a b c : L) → a ∧l b ≡ a → b ∧l c ≡ b → a ∧l c ≡ a
path a b c a∧b≡a b∧c≡b = a ∧l c ≡⟨ cong (_∧l c) (sym a∧b≡a) ⟩
(a ∧l b) ∧l c ≡⟨ sym (·Assoc _ _ _) ⟩
a ∧l (b ∧l c) ≡⟨ cong (a ∧l_) b∧c≡b ⟩
a ∧l b ≡⟨ a∧b≡a ⟩
a ∎
IsPoset.is-antisym (PosetStr.isPoset (snd IndPoset)) =
λ _ _ a∧b≡a b∧a≡b → sym a∧b≡a ∙∙ ·Comm _ _ ∙∙ b∧a≡b
≤-∧LPres : ∀ x y z → x ≤ y → z ∧l x ≤ z ∧l y
≤-∧LPres x y z x≤y = commAssocSwap z x z y ∙∙ cong (_∧l (x ∧l y)) (idem z) ∙∙ cong (z ∧l_) x≤y
∧≤LCancel : ∀ x y → x ∧l y ≤ y
∧≤LCancel x y = sym (·Assoc _ _ _) ∙ cong (x ∧l_) (idem y)
∧≤RCancel : ∀ x y → x ∧l y ≤ x
∧≤RCancel x y = commAssocr x y x ∙ cong (_∧l y) (idem x)
∧lIsMin : ∀ x y z → z ≤ x → z ≤ y → z ≤ x ∧l y
∧lIsMin x y z z≤x z≤y = cong (_∧l (x ∧l y)) (sym (idem z)) ∙ commAssocSwap z z x y
∙ cong₂ (_∧l_) z≤x z≤y
∙ idem z
| 36.632479
| 97
| 0.587611
|
cbf3c499cf61a0e656cc639c47dbdfd9cc1f3027
| 546
|
agda
|
Agda
|
test/Succeed/Erased-cubical.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Erased-cubical.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Erased-cubical.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --safe --erased-cubical #-}
module Erased-cubical where
-- Modules that use --cubical can be imported.
open import Erased-cubical.Cubical-again
-- Code from such modules that was originally defined in modules using
-- --without-K or --erased-cubical can be used without restrictions.
_ : {A : Set} → A → ∥ A ∥ᴱ
_ = ∣_∣
_ : D
_ = c
-- Matching on an erased constructor that was defined in a module that
-- uses --cubical is fine, and makes it possible to use erased
-- definitions in the right-hand side.
f : D′ → D′
f c′ = c′
| 22.75
| 70
| 0.688645
|
4d4f398b48bdc760383fa906f75dd623678c5814
| 932
|
agda
|
Agda
|
test/Fail/Issue1994.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1994.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1994.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{- Example by Andrew Pitts, 2016-05-23 -}
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Builtin.Equality public
infix 6 I─_
postulate
𝕀 : Set
O : 𝕀
I : 𝕀
I─_ : 𝕀 → 𝕀
{-# BUILTIN REWRITE _≡_ #-}
postulate
I─O≡I : I─ O ≡ I
{-# REWRITE I─O≡I #-}
data Pth (A : Set) : A → A → Set where
path : (f : 𝕀 → A) → Pth A (f O) (f I)
infix 6 _at_
_at_ : {A : Set}{x y : A} → Pth A x y → 𝕀 → A
path f at i = f i
record Path (A : Set)(x y : A) : Set where
field
pth : Pth A x y
feq : pth at O ≡ x
seq : pth at I ≡ y
open Path public
{-# REWRITE feq #-}
{-# REWRITE seq #-}
infix 6 _′_
_′_ : {A : Set}{x y : A} → Path A x y → 𝕀 → A
p ′ i = pth p at i
fun2path : {A : Set}(f : 𝕀 → A) → Path A (f O) (f I)
pth (fun2path f) = path f
feq (fun2path f) = refl
seq (fun2path f) = refl
inv : {A : Set}{x y : A} → Path A x y → Path A y x
inv p = fun2path (λ i → p ′ (I─ i))
| 18.64
| 52
| 0.508584
|
2f32d81ec06dedf414621f6d77dbb7c78715bc43
| 7,944
|
agda
|
Agda
|
Cubical/Experiments/Brunerie.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/Brunerie.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/Brunerie.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Experiments.Brunerie where
open import Cubical.Foundations.Everything
open import Cubical.Data.Bool
open import Cubical.Data.Nat
open import Cubical.Data.Int
open import Cubical.HITs.S1
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.HITs.Join
open import Cubical.HITs.SetTruncation as SetTrunc
open import Cubical.HITs.GroupoidTruncation as GroupoidTrunc
open import Cubical.HITs.2GroupoidTruncation as 2GroupoidTrunc
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Hopf
open S¹Hopf
-- This code is adapted from examples/brunerie3.ctt on the pi4s3_nobug branch of cubicaltt
Bool∙ S¹∙ S³∙ : Pointed₀
Bool∙ = (Bool , true)
S¹∙ = (S¹ , base)
S³∙ = (S³ , base)
∥_∥₃∙ ∥_∥₄∙ : Pointed₀ → Pointed₀
∥ A , a ∥₃∙ = ∥ A ∥₃ , ∣ a ∣₃
∥ A , a ∥₄∙ = ∥ A ∥₄ , ∣ a ∣₄
join∙ : Pointed₀ → Type₀ → Pointed₀
join∙ (A , a) B = join A B , inl a
Ω² Ω³ : Pointed₀ → Pointed₀
Ω² = Ω^ 2
Ω³ = Ω^ 3
mapΩrefl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω A .fst → Ω (B , f (pt A)) .fst
mapΩrefl f p i = f (p i)
mapΩ²refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω² A .fst → Ω² (B , f (pt A)) .fst
mapΩ²refl f p i j = f (p i j)
mapΩ³refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω³ A .fst → Ω³ (B , f (pt A)) .fst
mapΩ³refl f p i j k = f (p i j k)
meridS² : S¹ → Path S² base base
meridS² base _ = base
meridS² (loop i) j = surf i j
alpha : join S¹ S¹ → S²
alpha (inl x) = base
alpha (inr y) = base
alpha (push x y i) = (meridS² y ∙ meridS² x) i
connectionBoth : {A : Type₀} {a : A} (p : Path A a a) → PathP (λ i → Path A (p i) (p i)) p p
connectionBoth {a = a} p i j =
hcomp
(λ k → λ
{ (i = i0) → p (j ∨ ~ k)
; (i = i1) → p (j ∧ k)
; (j = i0) → p (i ∨ ~ k)
; (j = i1) → p (i ∧ k)
})
a
data PostTotalHopf : Type₀ where
base : S¹ → PostTotalHopf
loop : (x : S¹) → PathP (λ i → Path PostTotalHopf (base x) (base (rotLoop x (~ i)))) refl refl
tee12 : (x : S²) → HopfS² x → PostTotalHopf
tee12 base y = base y
tee12 (surf i j) y =
hcomp
(λ k → λ
{ (i = i0) → base y
; (i = i1) → base y
; (j = i0) → base y
; (j = i1) → base (rotLoopInv y (~ i) k)
})
(loop (unglue (i ∨ ~ i ∨ j ∨ ~ j) y) i j)
tee34 : PostTotalHopf → join S¹ S¹
tee34 (base x) = inl x
tee34 (loop x i j) =
hcomp
(λ k → λ
{ (i = i0) → push x x (j ∧ ~ k)
; (i = i1) → push x x (j ∧ ~ k)
; (j = i0) → inl x
; (j = i1) → push (rotLoop x (~ i)) x (~ k)
})
(push x x j)
tee : (x : S²) → HopfS² x → join S¹ S¹
tee x y = tee34 (tee12 x y)
fibΩ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω B .fst → Type₀
fibΩ P f p = PathP (λ i → P (p i)) f f
fibΩ² : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω² B .fst → Type₀
fibΩ² P f = fibΩ (fibΩ P f) refl
fibΩ³ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω³ B .fst → Type₀
fibΩ³ P f = fibΩ² (fibΩ P f) refl
Ω³Hopf : Ω³ S²∙ .fst → Type₀
Ω³Hopf = fibΩ³ HopfS² base
fibContrΩ³Hopf : ∀ p → Ω³Hopf p
fibContrΩ³Hopf p i j k =
hcomp
(λ m → λ
{ (i = i0) → base
; (i = i1) → base
; (j = i0) → base
; (j = i1) → base
; (k = i0) → base
; (k = i1) →
isSetΩS¹ refl refl
(λ i j → transp (λ n → HopfS² (p i j n)) (i ∨ ~ i ∨ j ∨ ~ j) base)
(λ _ _ → base)
m i j
})
(transp (λ n → HopfS² (p i j (k ∧ n))) (i ∨ ~ i ∨ j ∨ ~ j ∨ ~ k) base)
h : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
h p i j k = tee (p i j k) (fibContrΩ³Hopf p i j k)
multTwoAux : (x : S²) → Path (Path ∥ S² ∥₄ ∣ x ∣₄ ∣ x ∣₄) refl refl
multTwoAux base i j = ∣ surf i j ∣₄
multTwoAux (surf k l) i j =
hcomp
(λ m → λ
{ (i = i0) → ∣ surf k l ∣₄
; (i = i1) → ∣ surf k l ∣₄
; (j = i0) → ∣ surf k l ∣₄
; (j = i1) → ∣ surf k l ∣₄
; (k = i0) → ∣ surf i j ∣₄
; (k = i1) → ∣ surf i j ∣₄
; (l = i0) → ∣ surf i j ∣₄
; (l = i1) → squash₄ _ _ _ _ _ _ (λ k i j → step₁ k i j) refl m k i j
})
(step₁ k i j)
where
step₁ : I → I → I → ∥ S² ∥₄
step₁ k i j =
hcomp {A = ∥ S² ∥₄}
(λ m → λ
{ (i = i0) → ∣ surf k (l ∧ m) ∣₄
; (i = i1) → ∣ surf k (l ∧ m) ∣₄
; (j = i0) → ∣ surf k (l ∧ m) ∣₄
; (j = i1) → ∣ surf k (l ∧ m) ∣₄
; (k = i0) → ∣ surf i j ∣₄
; (k = i1) → ∣ surf i j ∣₄
; (l = i0) → ∣ surf i j ∣₄
})
∣ surf i j ∣₄
multTwoTildeAux : (t : ∥ S² ∥₄) → Path (Path ∥ S² ∥₄ t t) refl refl
multTwoTildeAux ∣ x ∣₄ = multTwoAux x
multTwoTildeAux (squash₄ _ _ _ _ _ _ t u k l m n) i j =
squash₄ _ _ _ _ _ _
(λ k l m → multTwoTildeAux (t k l m) i j)
(λ k l m → multTwoTildeAux (u k l m) i j)
k l m n
multTwoEquivAux : Path (Path (∥ S² ∥₄ ≃ ∥ S² ∥₄) (idEquiv _) (idEquiv _)) refl refl
multTwoEquivAux i j =
( f i j
, hcomp
(λ l → λ
{ (i = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (i = i1) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (j = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (j = i1) →
isPropIsEquiv _
(transp (λ k → isEquiv (f i k)) (i ∨ ~ i) (idIsEquiv _))
(idIsEquiv _)
l
})
(transp (λ k → isEquiv (f i (j ∧ k))) (i ∨ ~ i ∨ ~ j) (idIsEquiv _))
)
where
f : I → I → ∥ S² ∥₄ → ∥ S² ∥₄
f i j t = multTwoTildeAux t i j
tHopf³ : S³ → Type₀
tHopf³ base = ∥ S² ∥₄
tHopf³ (surf i j k) =
Glue ∥ S² ∥₄
(λ { (i = i0) → (∥ S² ∥₄ , idEquiv _)
; (i = i1) → (∥ S² ∥₄ , idEquiv _)
; (j = i0) → (∥ S² ∥₄ , idEquiv _)
; (j = i1) → (∥ S² ∥₄ , idEquiv _)
; (k = i0) → (∥ S² ∥₄ , multTwoEquivAux i j)
; (k = i1) → (∥ S² ∥₄ , idEquiv _)
})
π₃S³ : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst
π₃S³ p i j = transp (λ k → tHopf³ (p j k i)) i0 ∣ base ∣₄
codeS² : S² → hGroupoid _
codeS² s = ∥ HopfS² s ∥₃ , squash₃
codeTruncS² : ∥ S² ∥₄ → hGroupoid _
codeTruncS² = 2GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 3) codeS²
encodeTruncS² : Ω ∥ S²∙ ∥₄∙ .fst → ∥ S¹ ∥₃
encodeTruncS² p = transp (λ i → codeTruncS² (p i) .fst) i0 ∣ base ∣₃
codeS¹ : S¹ → hSet _
codeS¹ s = ∥ helix s ∥₂ , squash₂
codeTruncS¹ : ∥ S¹ ∥₃ → hSet _
codeTruncS¹ = GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 2) codeS¹
encodeTruncS¹ : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂
encodeTruncS¹ p = transp (λ i → codeTruncS¹ (p i) .fst) i0 ∣ pos zero ∣₂
-- THE BIG GAME
f3 : Ω³ S³∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
f3 = mapΩ³refl S³→joinS¹S¹
f4 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S²∙ .fst
f4 = mapΩ³refl alpha
f5 : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
f5 = h
f6 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S³∙ .fst
f6 = mapΩ³refl joinS¹S¹→S³
f7 : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst
f7 = π₃S³
g8 : Ω² ∥ S²∙ ∥₄∙ .fst → Ω ∥ S¹∙ ∥₃∙ .fst
g8 = mapΩrefl encodeTruncS²
g9 : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂
g9 = encodeTruncS¹
g10 : ∥ ℤ ∥₂ → ℤ
g10 = SetTrunc.rec isSetℤ (idfun ℤ)
-- don't run me
brunerie : ℤ
brunerie = g10 (g9 (g8 (f7 (f6 (f5 (f4 (f3 (λ i j k → surf i j k))))))))
-- simpler tests
test63 : ℕ → ℤ
test63 n = g10 (g9 (g8 (f7 (63n n))))
where
63n : ℕ → Ω³ S³∙ .fst
63n zero i j k = surf i j k
63n (suc n) = f6 (f3 (63n n))
foo : Ω³ S²∙ .fst
foo i j k =
hcomp
(λ l → λ
{ (i = i0) → surf l l
; (i = i1) → surf l l
; (j = i0) → surf l l
; (j = i1) → surf l l
; (k = i0) → surf l l
; (k = i1) → surf l l
})
base
sorghum : Ω³ S²∙ .fst
sorghum i j k =
hcomp
(λ l → λ
{ (i = i0) → surf j l
; (i = i1) → surf k (~ l)
; (j = i0) → surf k (i ∧ ~ l)
; (j = i1) → surf k (i ∧ ~ l)
; (k = i0) → surf j (i ∨ l)
; (k = i1) → surf j (i ∨ l)
})
(hcomp
(λ l → λ
{ (i = i0) → base
; (i = i1) → surf j l
; (j = i0) → surf k i
; (j = i1) → surf k i
; (k = i0) → surf j (i ∧ l)
; (k = i1) → surf j (i ∧ l)
})
(surf k i))
goo : Ω³ S²∙ .fst → ℤ
goo x = g10 (g9 (g8 (f7 (f6 (f5 x)))))
| 26.657718
| 96
| 0.502014
|
2f50bed5137b5d0dfd1a7b2d82967e711d1d3a12
| 13,379
|
agda
|
Agda
|
Vectors.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Vectors.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Vectors.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Semirings.Definition
open import Orders.Total.Definition
open import Lists.Lists
module Vectors where
data Vec {a : _} (X : Set a) : ℕ -> Set a where
[] : Vec X zero
_,-_ : {n : ℕ} -> X -> Vec X n -> Vec X (succ n)
infixr 10 _,-_
vecLen : {a : _} {X : Set a} {n : ℕ} → Vec X n → ℕ
vecLen {a} {X} {n} v = n
vecHead : {a : _} {X : Set a} {n : ℕ} → Vec X (succ n) → X
vecHead (x ,- xs) = x
vecTail : {a : _} {X : Set a} {n : ℕ} → Vec X (succ n) → Vec X n
vecTail (x ,- xs) = xs
vecIsHeadPlusTail : {a : _} {X : Set a} {n : ℕ} → (xs : Vec X (succ n)) → (vecHead xs ,- vecTail xs) ≡ xs
vecIsHeadPlusTail (x ,- xs) = refl
_+V_ : {a : _} {X : Set a} {m n : ℕ} → Vec X m → Vec X n → Vec X (m +N n)
[] +V ys = ys
(x ,- xs) +V ys = (x ,- (xs +V ys))
vecIndex : {a : _} {X : Set a} {m : ℕ} → Vec X m → (i : ℕ) → .(i <N m) → X
vecIndex [] zero ()
vecIndex (x ,- vec) zero i<m = x
vecIndex [] (succ i) ()
vecIndex (x ,- vec) (succ i) i<m = vecIndex vec i (canRemoveSuccFrom<N i<m)
vecLast : {a : _} {X : Set a} {m : ℕ} → Vec X m → (0 <N m) → X
vecLast {a} {X} {zero} v ()
vecLast {a} {X} {succ zero} (x ,- []) _ = x
vecLast {a} {X} {succ (succ m)} (x ,- v) _ = vecLast v (succIsPositive m)
vecLast' : {a : _} {X : Set a} {m : ℕ} → Vec X (succ m) → X
vecLast' {m = m} v = vecLast v (le m (applyEquality succ (Semiring.sumZeroRight ℕSemiring m)))
vecAppend : {a : _} {X : Set a} {m : ℕ} → Vec X m → (x : X) → Vec X (succ m)
vecAppend {a} {X} {zero} [] x = x ,- []
vecAppend {a} {X} {succ m} (y ,- v) x = y ,- vecAppend v x
vecAppendIsNowLast : {a : _} {X : Set a} {m : ℕ} → (x : X) → (v : Vec X m) → (vecLast (vecAppend v x) (succIsPositive m)) ≡ x
vecAppendIsNowLast {a} {X} {zero} x [] = refl
vecAppendIsNowLast {a} {X} {succ m} x (y ,- v) = vecAppendIsNowLast x v
vecRev : {a : _} {X : Set a} {m : ℕ} → Vec X m → Vec X m
vecRev {a} {X} {zero} [] = []
vecRev {a} {X} {succ m} (x ,- v) = vecAppend (vecRev v) x
vecMoveAppend : {a : _} {X : Set a} {m : ℕ} → (x : X) → (v : Vec X m) → vecRev (vecAppend v x) ≡ x ,- vecRev v
vecMoveAppend {a} {X} {.0} x [] = refl
vecMoveAppend {a} {X} {.(succ _)} x (y ,- v) rewrite vecMoveAppend x v = refl
vecRevRevIsId : {a : _} {X : Set a} {m : ℕ} → (v : Vec X m) → (vecRev (vecRev v)) ≡ v
vecRevRevIsId {a} {X} {zero} [] = refl
vecRevRevIsId {a} {X} {succ m} (x ,- v) rewrite vecMoveAppend x (vecRev v) = applyEquality (λ i → x ,- i) (vecRevRevIsId v)
record vecContains {a : _} {X : Set a} {m : ℕ} (vec : Vec X m) (x : X) : Set a where
field
index : ℕ
index<m : index <N m
isHere : vecIndex vec index index<m ≡ x
vecSolelyContains : {a : _} {X : Set a} → {m : X} → (n : X) → (vecContains (m ,- []) n) → m ≡ n
vecSolelyContains {m} n record { index = zero ; index<m = _ ; isHere = isHere } = isHere
vecSolelyContains {m} n record { index = (succ index) ; index<m = (le x proof) ; isHere = isHere } = exFalso (f {x} {index} proof)
where
f : {x index : ℕ} → succ (x +N succ index) ≡ 1 → False
f {x} {index} pr rewrite Semiring.commutative ℕSemiring x (succ index) = naughtE (equalityCommutative (succInjective pr))
vecChop : {a : _} {X : Set a} (m : ℕ) {n : ℕ} → Vec X (m +N n) → Vec X m && Vec X n
_&&_.fst (vecChop zero xs) = []
_&&_.fst (vecChop (succ m) (x ,- xs)) = (x ,- _&&_.fst (vecChop m xs))
_&&_.snd (vecChop zero xs) = xs
_&&_.snd (vecChop (succ m) (x ,- xs)) = _&&_.snd (vecChop m xs)
{-
vecIsChopThenAppend : {a : _} {X : Set a} {m n : ℕ} (xs : Vec X m) (ys : Vec X n) → vecChop m (xs +V ys) ≡ record { fst = xs ; snd = ys }
vecIsChopThenAppend {a} {X} {m} xs ys with vecChop m (xs +V ys)
vecIsChopThenAppend {a} {X} {zero} [] ys | record { fst = [] ; snd = snd } = {!!}
vecIsChopThenAppend {a} {X} {succ m} xs ys | bl = {!!}
-}
vecMap : {a b : _} {X : Set a} {Y : Set b} → (X → Y) → {n : ℕ} → Vec X n → Vec Y n
vecMap f [] = []
vecMap f (x ,- vec) = f x ,- (vecMap f vec)
vecMapCommutesWithAppend : {a b : _} {X : Set a} {Y : Set b} → (f : X → Y) → {n : ℕ} → (x : X) → (v : Vec X n) → (vecMap f (vecAppend v x) ≡ vecAppend (vecMap f v) (f x))
vecMapCommutesWithAppend f {.0} x [] = refl
vecMapCommutesWithAppend f {.(succ _)} x (y ,- v) = applyEquality (λ i → (f y ,- i)) (vecMapCommutesWithAppend f x v)
vecMapCommutesWithRev : {a b : _} {X : Set a} {Y : Set b} → (f : X → Y) → {n : ℕ} → (v : Vec X n) → (vecMap f (vecRev v) ≡ vecRev (vecMap f v))
vecMapCommutesWithRev {a} {b} {X} {Y} f {.0} [] = refl
vecMapCommutesWithRev {a} {b} {X} {Y} f {.(succ _)} (x ,- v) rewrite vecMapCommutesWithAppend f x (vecRev v) = applyEquality (λ i → vecAppend i (f x)) (vecMapCommutesWithRev f v)
vecIndex0AndAppend : {a : _} {X : Set a} {n : ℕ} → (v : Vec X n) → (0<n : 0 <N n) → (x : X) → vecIndex (vecAppend v x) 0 (succIsPositive n) ≡ vecIndex v 0 0<n
vecIndex0AndAppend [] () x
vecIndex0AndAppend (a ,- v) 0<n x = refl
vecIndexMAndAppend : {a : _} {X : Set a} {n : ℕ} → (v : Vec X n) → (x : X) → (m : ℕ) → (m<n : m <N n) → (pr : m <N succ n) → vecIndex (vecAppend v x) m pr ≡ vecIndex v m m<n
vecIndexMAndAppend {n = .(succ _)} (v ,- vs) x zero m<n pr = refl
vecIndexMAndAppend [] x (succ m) ()
vecIndexMAndAppend {n = n} (y ,- v) x (succ m) m<n pr = vecIndexMAndAppend v x m (canRemoveSuccFrom<N m<n) (canRemoveSuccFrom<N pr)
vecMapCompose : {a b c : _} {X : Set a} {Y : Set b} {Z : Set c} → (f : X → Y) → (g : Y → Z) → {n : ℕ} → (v : Vec X n) → (vecMap g (vecMap f v)) ≡ vecMap (λ i → g (f i)) v
vecMapCompose f g [] = refl
vecMapCompose f g (x ,- v) = applyEquality (λ w → (g (f x) ,- w)) (vecMapCompose f g v)
vecMapIdFact : {a : _} {X : Set a} {f : X → X} (feq : (x : X) → f x ≡ x) {n : ℕ} (xs : Vec X n) → vecMap f xs ≡ xs
vecMapIdFact feq [] = refl
vecMapIdFact feq (x ,- xs) rewrite (feq x) | vecMapIdFact feq xs = refl
vecMapCompositionFact : {a b c : _} {X : Set a} {Y : Set b} {Z : Set c} {f : Y → Z} {g : X → Y} {h : X → Z} (heq : (x : X) → f (g x) ≡ h x) → {n : ℕ} (xs : Vec X n) → vecMap f (vecMap g xs) ≡ vecMap h xs
vecMapCompositionFact heq [] = refl
vecMapCompositionFact {a} {b} {c} {X} {Y} {Z} {f} {g} {h} heq (x ,- xs) rewrite heq x | vecMapCompositionFact {a} {b} {c} {X} {Y} {Z} {f} {g} {h} heq xs = refl
vecMapIsNatural : {a b : _} {X : Set a} {Y : Set b} (f : X → Y) → {m n : ℕ} (xs : Vec X m) (xs' : Vec X n) → vecMap f (xs +V xs') ≡ (vecMap f xs +V vecMap f xs')
vecMapIsNatural f [] xs' = refl
vecMapIsNatural f (x ,- xs) xs' rewrite vecMapIsNatural f xs xs' = refl
vecMapAndIndex : {n : ℕ} {a b : _} {A : Set a} {B : Set b} (v : Vec A n) (f : A → B) → {a : ℕ} → (a<n : a <N n) → vecIndex (vecMap f v) a a<n ≡ f (vecIndex v a a<n)
vecMapAndIndex (x ,- v) f {zero} a<n = refl
vecMapAndIndex (x ,- v) f {succ a} a<n = vecMapAndIndex v f (canRemoveSuccFrom<N a<n)
vecPure : {a : _} {X : Set a} → X → {n : ℕ} → Vec X n
vecPure x {zero} = []
vecPure x {succ n} = x ,- vecPure x {n}
vecAllTrue : {a b : _} {X : Set a} (f : X → Set b) → {n : ℕ} (v : Vec X n) → Set b
vecAllTrue f [] = True'
vecAllTrue f (x ,- v) = f x && vecAllTrue f v
vecFold : {a b : _} {X : Set a} {S : Set b} (f : X → S → S) (s : S) {n : ℕ} (v : Vec X n) → S
vecFold f s [] = s
vecFold f s (x ,- v) = vecFold f (f x s) v
private
succLess1 : (i : ℕ) → .(succ i <N 1) → False
succLess1 zero pr with <NProp pr
... | le zero ()
... | le (succ x) ()
succLess1 (succ i) pr with <NProp pr
... | le zero ()
... | le (succ x) ()
vecDelete : {a : _} {X : Set a} {n : ℕ} (index : ℕ) .(pr : index <N succ n) → Vec X (succ n) → Vec X n
vecDelete zero _ (x ,- v) = v
vecDelete (succ i) p (x ,- []) = exFalso (succLess1 i p)
vecDelete (succ i) pr (x ,- (y ,- v)) = x ,- vecDelete i (canRemoveSuccFrom<N pr) (y ,- v)
_$V_ : {a b : _} {X : Set a} {Y : Set b} {n : ℕ} → Vec (X → Y) n → Vec X n → Vec Y n
[] $V [] = []
(f ,- fs) $V (x ,- xs) = f x ,- (fs $V xs)
infixl 3 _$V_
vec : {a b : _} {X : Set a} {Y : Set b} → (X → Y) → {n : ℕ} → Vec X n → Vec Y n
vec f xs = (vecPure f) $V xs
vecZip : {a b : _} {X : Set a} {Y : Set b} {n : ℕ} → Vec X n → Vec Y n → Vec (X && Y) n
vecZip [] [] = []
vecZip (x ,- xs) (x₁ ,- ys) = record { fst = x ; snd = x₁ } ,- vecZip xs ys
vecIdentity : {a : _} {X : Set a} {f : X → X} (feq : (x : X) → f x ≡ x) → {n : ℕ} (xs : Vec X n) → (vecPure f $V xs) ≡ xs
vecIdentity feq [] = refl
vecIdentity feq (x ,- xs) rewrite feq x | vecIdentity feq xs = refl
vecHom : {a b : _} {X : Set a} {Y : Set b} (f : X → Y) (x : X) → {n : ℕ} → (vecPure f $V vecPure x) ≡ vecPure (f x) {n}
vecHom f x {zero} = refl
vecHom f x {succ n} rewrite vecHom f x {n} = refl
vecInterchange : {a b : _} {X : Set a} {Y : Set b} {n : ℕ} (fs : Vec (X → Y) n) (x : X) → (fs $V vecPure x) ≡ (vecPure (λ f → f x) $V fs)
vecInterchange [] x = refl
vecInterchange (f ,- fs) x rewrite vecInterchange fs x = refl
vecComposition : {a b c : _} {X : Set a} {Y : Set b} {Z : Set c} {n : ℕ} (fs : Vec (Y → Z) n) (gs : Vec (X → Y) n) (xs : Vec X n) → (vecPure (λ i j x → i (j x)) $V fs $V gs $V xs) ≡ (fs $V (gs $V xs))
vecComposition [] [] [] = refl
vecComposition (f ,- fs) (g ,- gs) (x ,- xs) rewrite vecComposition fs gs xs = refl
vecToList : {a : _} {A : Set a} {n : ℕ} → (v : Vec A n) → List A
vecToList [] = []
vecToList (x ,- v) = x :: vecToList v
listToVec : {a : _} {A : Set a} (l : List A) → Vec A (length l)
listToVec [] = []
listToVec (x :: l) = x ,- listToVec l
------------
data _<=_ : ℕ → ℕ → Set where
oz : zero <= zero
os : {n m : ℕ} → n <= m → succ n <= succ m
o' : {n m : ℕ} → n <= m → n <= succ m
all0<=4 : Vec (0 <= 4) 1
all0<=4 = o' (o' (o' (o' oz))) ,- []
all1<=4 : Vec (1 <= 4) 4
all1<=4 = (o' ((o' (o' (os oz))))) ,- ((o' (o' (os (o' oz)))) ,- ((o' (os (o' (o' oz)))) ,- ((os (o' (o' (o' oz)))) ,- [])))
all2<=4 : Vec (2 <= 4) 6
all2<=4 = os (os (o' (o' oz))) ,- (os (o' (os (o' oz))) ,- (os (o' (o' (os oz))) ,- (o' (o' (os (os oz))) ,- (o' (os (o' (os oz))) ,- (o' (os (os (o' oz))) ,- [])))))
all3<=4 : Vec (3 <= 4) 4
all3<=4 = os (os (os (o' oz))) ,- (os (os (o' (os oz))) ,- (os (o' (os (os oz))) ,- (o' (os (os (os oz))) ,- [])))
all4<=4 : Vec (4 <= 4) 1
all4<=4 = os (os (os (os oz))) ,- []
<=Is≤N : {n m : ℕ} → (n <= m) → n ≤N m
<=Is≤N {n} {m} thm with TotalOrder.totality ℕTotalOrder n m
<=Is≤N {n} {m} thm | inl (inl n<m) = inl n<m
<=Is≤N {n} {.n} thm | inr refl = inr refl
<=Is≤N {zero} {zero} thm | inl (inr m<n) = inl m<n
<=Is≤N {zero} {succ m} thm | inl (inr m<n) = inl (succIsPositive m)
<=Is≤N {succ n} {zero} () | inl (inr m<n)
<=Is≤N {succ n} {succ m} (os thm) | inl (inr m<n) with <=Is≤N thm
<=Is≤N {succ n} {succ m} (os thm) | inl (inr m<n) | inl x = inl (succPreservesInequality x)
<=Is≤N {succ n} {succ m} (os thm) | inl (inr m<n) | inr x rewrite x = inr refl
<=Is≤N {succ n} {succ m} (o' thm) | inl (inr m<n) with <=Is≤N thm
<=Is≤N {succ n} {succ m} (o' thm) | inl (inr m<n) | inl x with a<SuccA m
... | m<sm = inl (lessTransitive x m<sm)
<=Is≤N {succ n} {succ m} (o' thm) | inl (inr m<n) | inr x rewrite x = inl (a<SuccA m)
succIsNotEqual : {n : ℕ} → (succ n ≡ n) → False
succIsNotEqual {zero} pr = naughtE (equalityCommutative pr)
succIsNotEqual {succ n} pr = succIsNotEqual (succInjective pr)
succIsNotLess : {n : ℕ} → (succ n <N n) → False
succIsNotLess {zero} (le x proof) = naughtE (equalityCommutative proof)
succIsNotLess {succ n} pr = succIsNotLess (canRemoveSuccFrom<N pr)
noSN<=N : {n : ℕ} → (succ n) <= n → False
noSN<=N {n} thm with <=Is≤N thm
noSN<=N {n} thm | inl x = succIsNotLess x
noSN<=N {n} thm | inr x = succIsNotEqual x
no5<=4 : 5 <= 4 → False
no5<=4 th = noSN<=N {4} th
_<?=_ : {a : _} {X : Set a} {n m : ℕ} → (n <= m) → Vec X m → Vec X n
oz <?= xs = xs
os th <?= (x ,- xs) = x ,- (th <?= xs)
o' th <?= (x ,- xs) = th <?= xs
vMap<?=Fact : {a b : _} {X : Set a} {Y : Set b} (f : X → Y) {n m : ℕ} (th : n <= m) (xs : Vec X m) → vecMap f (th <?= xs) ≡ (th <?= vecMap f xs)
vMap<?=Fact f oz xs = refl
vMap<?=Fact f (os th) (x ,- xs) rewrite vMap<?=Fact f th xs = refl
vMap<?=Fact f (o' th) (x ,- xs) rewrite vMap<?=Fact f th xs = refl
oi : {n : ℕ} → n <= n
oi {zero} = oz
oi {succ n} = os oi
oe : {n : ℕ} → 0 <= n
oe {zero} = oz
oe {succ n} = o' oe
oeUnique : {n : ℕ} (th : 0 <= n) → th ≡ oe
oeUnique oz = refl
oeUnique (o' i) rewrite oeUnique i = refl
oTooBig : {n m : ℕ} → m ≤N n → succ n <= m → False
oTooBig {n} {m} m<=n th with <=Is≤N th
oTooBig {n} {m} (inl m<n) th | inl x = succIsNotLess (lessTransitive x m<n)
oTooBig {n} {m} (inr m=n) th | inl x rewrite m=n = succIsNotLess x
oTooBig {n} {m} (inl m<n) th | inr x rewrite (equalityCommutative x) = succIsNotLess m<n
oTooBig {n} {m} (inr m=n) th | inr x rewrite m=n = succIsNotEqual x
oiUnique : {n : ℕ} (th : n <= n) → (th ≡ oi)
oiUnique oz = refl
oiUnique (os th) rewrite oiUnique th = refl
oiUnique {succ n} (o' th) with oTooBig {n} {n} (inr refl) th
... | bl = exFalso bl
id-<?= : {a : _} {X : Set a} {n : ℕ} (xs : Vec X n) → (oi <?= xs) ≡ xs
id-<?= [] = refl
id-<?= (x ,- xs) rewrite id-<?= xs = refl
_o>>_ : {p n m : ℕ} → p <= n → n <= m → p <= m
oz o>> th' = th'
os th o>> os th' = os (th o>> th')
os th o>> o' th' = os (o' th o>> th')
o' th o>> os th' = o' (th o>> th')
o' th o>> o' th' = o' (o' th o>> th')
eqHelper : {a : _} {X : Set a} (x : X) {n : ℕ} {r s : Vec X n} (pr : r ≡ s) → (x ,- r) ≡ (x ,- s)
eqHelper x pr rewrite pr = refl
| 44.745819
| 203
| 0.530458
|
2f9afd2d15da51cba9474f1fc15745fb23eb1163
| 1,288
|
agda
|
Agda
|
agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Properties.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Properties.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Properties.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.Relation.Unary.All.Properties where
open import Prelude hiding (⊥; ⊤)
open import Algebra.Construct.Free.Semilattice.Eliminators
open import Algebra.Construct.Free.Semilattice.Definition
open import Cubical.Foundations.HLevels
open import Data.Empty.UniversePolymorphic
open import HITs.PropositionalTruncation.Sugar
open import HITs.PropositionalTruncation.Properties
open import HITs.PropositionalTruncation
open import Data.Unit.UniversePolymorphic
open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Def
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Membership
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Nullary.Decidable.Properties
open import Relation.Nullary.Decidable.Logic
private
variable p : Level
P∈◇ : ∀ {p} {P : A → Type p} → ∀ x xs → x ∈ xs → ◻ P xs → ∥ P x ∥
P∈◇ {A = A} {P = P} = λ x → ∥ P∈◇′ x ∥⇓
where
P∈◇′ : (x : A) → xs ∈𝒦 A ⇒∥ (x ∈ xs → ◻ P xs → ∥ P x ∥) ∥
∥ P∈◇′ x ∥-prop p q i x∈xs ◻Pxs = squash (p x∈xs ◻Pxs) (q x∈xs ◻Pxs) i
∥ P∈◇′ x ∥[] ()
∥ P∈◇′ x ∥ y ∷ ys ⟨ Pys ⟩ x∈xs ◻Pxs =
x∈xs >>=
either′
(λ y≡x → subst (∥_∥ ∘ P) y≡x (◻Pxs .fst))
(λ x∈ys → Pys x∈ys (◻Pxs .snd))
| 36.8
| 77
| 0.682453
|
06780fc7b336fa314db7d3deff51f176f945277d
| 17
|
agda
|
Agda
|
test/interaction/Issue4516.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue4516.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue4516.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Set where
| 8.5
| 16
| 0.823529
|
1c9cf87b8d3319b99a75df42729daa902197b64c
| 4,472
|
agda
|
Agda
|
src/Categories/Adjoint/Instance/PosetCore.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 1
|
2021-04-18T18:21:47.000Z
|
2021-04-18T18:21:47.000Z
|
src/Categories/Adjoint/Instance/PosetCore.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
src/Categories/Adjoint/Instance/PosetCore.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Instance.PosetCore where
-- The adjunction between the "forgetful" functor from Posets to
-- Setoids and the core functor for posets.
open import Level using (_⊔_)
import Function
open import Function.Equality using (Π; _⟶_)
open import Relation.Binary using (Setoid; Poset)
open import Categories.Adjoint using (_⊣_)
import Categories.Adjoint.Instance.0-Truncation as Setd
import Categories.Adjoint.Instance.01-Truncation as Pos
open import Categories.Category using (Category)
open import Categories.Category.Construction.Thin
open import Categories.Category.Instance.Posets using (Posets; _⇒-Poset_; ⇒-Poset-∘; ⇒-Poset-helper)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Functor.Instance.Core using () renaming (Core to CatCore)
import Categories.Functor.Instance.Core as Cat
open import Categories.Functor using (Functor; _∘F_; id)
import Categories.Morphism as Morphism
open import Categories.Morphism.IsoEquiv using (⌞_⌟)
open import Categories.NaturalTransformation using (ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (_≃_; niHelper)
open Π
open _⇒-Poset_
-- The "forgetful" functor from Setoids to Posets (forgetting symmetry).
Forgetful : ∀ {c ℓ} → Functor (Setoids c ℓ) (Posets c ℓ ℓ)
Forgetful = record
{ F₀ = Forgetful₀
; F₁ = λ f → ⇒-Poset-helper (f ⟨$⟩_) (cong f)
; identity = λ {S} → refl S
; homomorphism = λ {_ _ S} → refl S
; F-resp-≈ = λ {S _} f≗g → f≗g (refl S)
}
where
Forgetful₀ : ∀ {c ℓ} → Setoid c ℓ → Poset c ℓ ℓ
Forgetful₀ S = record
{ _≈_ = _≈_
; _≤_ = _≈_
; isPartialOrder = record
{ isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = Function.id
; trans = trans
}
; antisym = Function.const
}
}
where open Setoid S
open Setoid
-- The "core" functor from Posets to Setoids.
--
-- This functor simply forgets the _≤_ relation, mapping a Poset to
-- the Setoid over which it is defined. This Setoid is the "core" of
-- the Poset in the sense that the "equality" _≈_ associated with the
-- Poset is really an equivalence, and antisymmetry ensures that this
-- equivalence is equivalent to the symmetric core of _≤_.
Core : ∀ {c ℓ₁ ℓ₂} → Functor (Posets c ℓ₁ ℓ₂) (Setoids c ℓ₁)
Core = record
{ F₀ = λ A → record { isEquivalence = isEquivalence A }
; F₁ = λ f → record { _⟨$⟩_ = fun f ; cong = cong f }
; identity = Function.id
; homomorphism = λ {_ _ _ f g} → cong (⇒-Poset-∘ g f)
; F-resp-≈ = λ {_ B} {f _} f≗g x≈y → Eq.trans B (cong f x≈y) f≗g
}
where open Poset
-- Core is right-adjoint to the forgetful functor
CoreAdj : ∀ {o ℓ} → Forgetful ⊣ Core {o} {ℓ} {ℓ}
CoreAdj = record
{ unit = ntHelper record { η = unit ; commute = cong }
; counit = ntHelper record { η = counit ; commute = λ {_ B} _ → Eq.refl B }
; zig = λ {S} → Setoid.refl S
; zag = Function.id
}
where
open Poset
open Functor Core using () renaming (F₀ to Core₀; F₁ to Core₁)
open Functor Forgetful using () renaming (F₀ to U₀ ; F₁ to U₁)
unit : ∀ S → S ⟶ Core₀ (U₀ S)
unit S = record { _⟨$⟩_ = Function.id ; cong = Function.id }
counit : ∀ A → U₀ (Core₀ A) ⇒-Poset A
counit C = ⇒-Poset-helper Function.id (reflexive C)
-- The core functor commutes with inclusion, i.e. the core of a thin
-- category is the 0-Groupoid generated by the associated equivalence.
--
-- Note that the core functor does not commute with truncation,
-- because the latter forgets too much (there are many more isos in
-- the (0,1)-truncated category).
Core-commutes : ∀ {c ℓ} e → Setd.Inclusion e ∘F Core ≃
Cat.Core ∘F Pos.Inclusion {c} {ℓ ⊔ e} {ℓ} e
Core-commutes e = niHelper record
{ η = λ A → record { F₀ = Function.id ; F₁ = EqIsIso.≈⇒≅ e A }
; η⁻¹ = λ A → record { F₀ = Function.id ; F₁ = EqIsIso.≅⇒≈ e A }
; commute = λ {A B} f →
let open Morphism (Thin e B)
in niHelper record { η = λ _ → ≅.refl ; η⁻¹ = λ _ → ≅.refl }
; iso = λ A →
let open Poset A
open Morphism (Thin e A)
in record
{ isoˡ = niHelper record { η = λ _ → Eq.refl ; η⁻¹ = λ _ → Eq.refl }
; isoʳ = niHelper record { η = λ _ → ≅.refl ; η⁻¹ = λ _ → ≅.refl }
}
}
| 36.958678
| 100
| 0.628578
|
59dd2127ce11275befe80fc76abd1cbd6778c070
| 7,943
|
agda
|
Agda
|
algebra/DecidableFreeGroupIsReducedWord.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
algebra/DecidableFreeGroupIsReducedWord.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
algebra/DecidableFreeGroupIsReducedWord.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT hiding (_::_)
module algebra.DecidableFreeGroupIsReducedWord {i} (A : Type i) (dec : has-dec-eq A) where
open import algebra.Word A
open import algebra.ReducedWord A dec
-- Some helper functions.
tail-is-reduced : (x : A) (w : Word) → is-reduced (x :: w) → is-reduced w
tail-is-reduced x nil red = lift unit
tail-is-reduced x (y :: w) red = red
tail-is-reduced x (y inv:: w) red = snd red
tail'-is-reduced : (x : A) (w : Word) → is-reduced (x inv:: w) → is-reduced w
tail'-is-reduced x nil red = lift unit
tail'-is-reduced x (y :: w) red = snd red
tail'-is-reduced x (y inv:: w) red = red
-- Conversion function.
ReducedWord⇒FreeGroup : ReducedWord → FreeGroup A
ReducedWord⇒FreeGroup (w , red) = f w red
where
f : (w : Word) → is-reduced w → FreeGroup A
f nil _ = fg-nil
f (x :: w) r = x fg:: f w (tail-is-reduced x w r)
f (x inv:: w) r = x fg-inv:: f w (tail'-is-reduced x w r)
infixr 60 _rw::_ _rw-inv::_
_rw::_ : A → ReducedWord → ReducedWord
x rw:: (nil , red) = ((x :: nil) , lift unit)
x rw:: ((y :: w) , red) = ((x :: y :: w) , red)
x rw:: ((y inv:: w) , red) with dec x y
x rw:: ((y inv:: w) , red) | inl x=y = (w , tail'-is-reduced y w red)
x rw:: ((y inv:: w) , red) | inr x≠y = ((x :: y inv:: w) , (x≠y , red))
_rw-inv::_ : A → ReducedWord → ReducedWord
x rw-inv:: (nil , red) = ((x inv:: nil) , lift unit)
x rw-inv:: ((y inv:: w) , red) = ((x inv:: y inv:: w) , red)
x rw-inv:: ((y :: w) , red) with dec x y
x rw-inv:: ((y :: w) , red) | inl eq = (w , tail-is-reduced y w red)
x rw-inv:: ((y :: w) , red) | inr neq = ((x inv:: y :: w) , (neq , red))
abstract
rw-inv-r : ∀ x w → x rw:: x rw-inv:: w == w
rw-inv-r x (nil , red) with dec x x
rw-inv-r x (nil , red) | inl x=x = idp
rw-inv-r x (nil , red) | inr x≠x = ⊥-rec (x≠x idp)
rw-inv-r x ((y :: w) , red) with dec x y
rw-inv-r x ((y :: nil) , red) | inl x=y = x=y |in-ctx _
rw-inv-r x ((y :: z :: w) , red) | inl x=y = x=y |in-ctx _
rw-inv-r x ((y :: z inv:: w) , red) | inl x=y with dec x z
rw-inv-r x ((y :: z inv:: w) , red) | inl x=y | inl x=z = ⊥-rec (fst red (! x=y ∙ x=z))
rw-inv-r x ((y :: z inv:: w) , red) | inl x=y | inr x≠z = ReducedWord=-in (x=y |in-ctx _)
rw-inv-r x ((y :: w) , red) | inr x≠y with dec x x
rw-inv-r x ((y :: w) , red) | inr x≠y | inl x=x = idp
rw-inv-r x ((y :: w) , red) | inr x≠y | inr x≠x = ⊥-rec (x≠x idp)
rw-inv-r x ((y inv:: w) , red) with dec x x
rw-inv-r x ((y inv:: w) , red) | inl x=x = idp
rw-inv-r x ((y inv:: w) , red) | inr x≠x = ⊥-rec (x≠x idp)
abstract
rw-inv-l : ∀ x w → x rw-inv:: x rw:: w == w
rw-inv-l x (nil , red) with dec x x
rw-inv-l x (nil , red) | inl x=x = idp
rw-inv-l x (nil , red) | inr x≠x = ⊥-rec (x≠x idp)
rw-inv-l x ((y inv:: w) , red) with dec x y
rw-inv-l x ((y inv:: nil) , red) | inl x=y = x=y |in-ctx _
rw-inv-l x ((y inv:: z inv:: w) , red) | inl x=y = x=y |in-ctx _
rw-inv-l x ((y inv:: z :: w) , red) | inl x=y with dec x z
rw-inv-l x ((y inv:: z :: w) , red) | inl x=y | inl x=z = ⊥-rec (fst red (! x=y ∙ x=z))
rw-inv-l x ((y inv:: z :: w) , red) | inl x=y | inr x≠z = ReducedWord=-in (x=y |in-ctx _)
rw-inv-l x ((y inv:: w) , red) | inr x≠y with dec x x
rw-inv-l x ((y inv:: w) , red) | inr x≠y | inl x=x = idp
rw-inv-l x ((y inv:: w) , red) | inr x≠y | inr x≠x = ⊥-rec (x≠x idp)
rw-inv-l x ((y :: w) , red) with dec x x
rw-inv-l x ((y :: w) , red) | inl x=x = idp
rw-inv-l x ((y :: w) , red) | inr x≠x = ⊥-rec (x≠x idp)
FreeGroup⇒ReducedWord : FreeGroup A → ReducedWord
FreeGroup⇒ReducedWord = FreeGroup-rec ReducedWord-is-set
(nil , lift unit)
(λ x _ rw → x rw:: rw)
(λ x _ rw → x rw-inv:: rw)
(λ x {_} rw → rw-inv-l x rw)
(λ x {_} rw → rw-inv-r x rw)
abstract
rw::-reduced : ∀ x w (red : is-reduced (x :: w))
→ x rw:: (w , tail-is-reduced x w red) == ((x :: w) , red)
rw::-reduced x nil red = idp
rw::-reduced x (y :: w) red = idp
rw::-reduced x (y inv:: w) red with dec x y
rw::-reduced x (y inv:: w) red | inl x=y = ⊥-rec (fst red x=y)
rw::-reduced x (y inv:: w) red | inr x≠y = ReducedWord=-in idp
abstract
rw-inv::-reduced : ∀ x w (red : is-reduced (x inv:: w))
→ x rw-inv:: (w , tail'-is-reduced x w red) == ((x inv:: w) , red)
rw-inv::-reduced x nil red = idp
rw-inv::-reduced x (y inv:: w) red = idp
rw-inv::-reduced x (y :: w) red with dec x y
rw-inv::-reduced x (y :: w) red | inl x=y = ⊥-rec (fst red x=y)
rw-inv::-reduced x (y :: w) red | inr x≠y = ReducedWord=-in idp
ReducedWord⇒FreeGroup⇒ReducedWord :
∀ w → FreeGroup⇒ReducedWord (ReducedWord⇒FreeGroup w) == w
ReducedWord⇒FreeGroup⇒ReducedWord (w , red) = f w red
where
f : ∀ w red → FreeGroup⇒ReducedWord (ReducedWord⇒FreeGroup (w , red)) == w , red
f nil _ = idp
f (x :: w) red =
x rw:: FreeGroup⇒ReducedWord (ReducedWord⇒FreeGroup (w , tail-is-reduced x w red))
=⟨ f w (tail-is-reduced x w red) |in-ctx (λ w → x rw:: w) ⟩
x rw:: (w , tail-is-reduced x w red)
=⟨ rw::-reduced x w red ⟩
(x :: w) , red
∎
f (x inv:: w) red =
x rw-inv:: FreeGroup⇒ReducedWord (ReducedWord⇒FreeGroup (w , tail'-is-reduced x w red))
=⟨ f w (tail'-is-reduced x w red) |in-ctx (λ w → x rw-inv:: w) ⟩
x rw-inv:: (w , tail'-is-reduced x w red)
=⟨ rw-inv::-reduced x w red ⟩
(x inv:: w) , red
∎
ReducedWord⇒FreeGroup-rw:: : ∀ x w
→ ReducedWord⇒FreeGroup (x rw:: w) == x fg:: ReducedWord⇒FreeGroup w
ReducedWord⇒FreeGroup-rw:: x (nil , red) = idp
ReducedWord⇒FreeGroup-rw:: x ((y :: w) , red) = idp
ReducedWord⇒FreeGroup-rw:: x ((y inv:: w) , red) with dec x y
ReducedWord⇒FreeGroup-rw:: x ((.x inv:: w) , red) | inl idp =
! (fg-inv-r x (ReducedWord⇒FreeGroup (w , tail'-is-reduced x w red)))
ReducedWord⇒FreeGroup-rw:: x ((y inv:: w) , red) | inr x≠y = idp
ReducedWord⇒FreeGroup-rw-inv:: : ∀ x w
→ ReducedWord⇒FreeGroup (x rw-inv:: w) == x fg-inv:: ReducedWord⇒FreeGroup w
ReducedWord⇒FreeGroup-rw-inv:: x (nil , red) = idp
ReducedWord⇒FreeGroup-rw-inv:: x ((y inv:: w) , red) = idp
ReducedWord⇒FreeGroup-rw-inv:: x ((y :: w) , red) with dec x y
ReducedWord⇒FreeGroup-rw-inv:: x ((.x :: w) , red) | inl idp =
! (fg-inv-l x (ReducedWord⇒FreeGroup (w , tail-is-reduced x w red)))
ReducedWord⇒FreeGroup-rw-inv:: x ((y :: w) , red) | inr x≠y = idp
FreeGroup⇒ReducedWord⇒FreeGroup : ∀ fg
→ ReducedWord⇒FreeGroup (FreeGroup⇒ReducedWord fg) == fg
FreeGroup⇒ReducedWord⇒FreeGroup = FreeGroup-elim
(λ _ → =-preserves-set FreeGroup-is-set)
idp
(λ x {fg} fg* →
ReducedWord⇒FreeGroup (x rw:: FreeGroup⇒ReducedWord fg)
=⟨ ReducedWord⇒FreeGroup-rw:: x (FreeGroup⇒ReducedWord fg) ⟩
x fg:: ReducedWord⇒FreeGroup (FreeGroup⇒ReducedWord fg)
=⟨ fg* |in-ctx (_fg::_ x) ⟩
x fg:: fg
∎)
(λ x {fg} fg* →
ReducedWord⇒FreeGroup (x rw-inv:: FreeGroup⇒ReducedWord fg)
=⟨ ReducedWord⇒FreeGroup-rw-inv:: x (FreeGroup⇒ReducedWord fg) ⟩
x fg-inv:: ReducedWord⇒FreeGroup (FreeGroup⇒ReducedWord fg)
=⟨ fg* |in-ctx (_fg-inv::_ x) ⟩
x fg-inv:: fg
∎)
(λ x {fg} fg* → prop-has-all-paths-↓ (FreeGroup-is-set _ _))
(λ x {fg} fg* → prop-has-all-paths-↓ (FreeGroup-is-set _ _))
FreeGroup≃ReducedWord : FreeGroup A ≃ ReducedWord
FreeGroup≃ReducedWord = FreeGroup⇒ReducedWord ,
is-eq
_
ReducedWord⇒FreeGroup
ReducedWord⇒FreeGroup⇒ReducedWord
FreeGroup⇒ReducedWord⇒FreeGroup
| 44.623596
| 96
| 0.529397
|
101e4eb4864a0eb2ce871bbddf11a1d3c40f4460
| 405
|
agda
|
Agda
|
test/Compiler/simple/Erased-constructors.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
test/Compiler/simple/Erased-constructors.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
test/Compiler/simple/Erased-constructors.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
-- Partly based on code due to Andrea Vezzosi.
open import Common.Prelude
data D : Set where
run-time : Bool → D
@0 compile-time : Bool → D
f : D → @0 D → Bool
f (run-time x) _ = x
f (compile-time x) (run-time y) = x
f (compile-time x) (compile-time y) = y
main : IO Unit
main =
putStrLn (if f (run-time true) (compile-time false)
then "ok" else "bad")
| 22.5
| 53
| 0.57284
|
0b5318cab5dae8e5c4faf160a80379bec15b3971
| 6,172
|
agda
|
Agda
|
src/NumberTheory/ModularArithmetic.agda
|
Taneb/antlion
|
8c3a4235a16f66a94267aada287bd8ee7d054ead
|
[
"MIT"
] | null | null | null |
src/NumberTheory/ModularArithmetic.agda
|
Taneb/antlion
|
8c3a4235a16f66a94267aada287bd8ee7d054ead
|
[
"MIT"
] | null | null | null |
src/NumberTheory/ModularArithmetic.agda
|
Taneb/antlion
|
8c3a4235a16f66a94267aada287bd8ee7d054ead
|
[
"MIT"
] | null | null | null |
import Data.Integer as Integer
open Integer using (ℤ)
module NumberTheory.ModularArithmetic (m : ℤ) where
open import Algebra.Structures
open Integer hiding (+_; _-_) -- using (_+_; _*_; -_; +0)
open import Data.Integer.GCD
open import Data.Integer.Properties hiding (*-1-isMonoid; *-1-isCommutativeMonoid; +-*-isCommutativeRing)
open import Data.Integer.Tactic.RingSolver
open import Data.Product
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
_≈_ : Rel ℤ _
x ≈ y = ∃ λ k → k * m + x ≡ y
refl : Reflexive _≈_
refl {x} = +0 , (begin
+0 * m + x
≡⟨ ≡.cong (_+ x) (*-zeroˡ m) ⟩
+0 + x
≡⟨ +-identityˡ x ⟩
x
∎)
where
open ≡.≡-Reasoning
sym : Symmetric _≈_
sym {x} {y} (k , p) = (- k) , (begin
- k * m + y
≡˘⟨ ≡.cong₂ _+_ (neg-distribˡ-* k m) (neg-involutive y) ⟩
- (k * m) + - - y
≡˘⟨ neg-distrib-+ (k * m) (- y) ⟩
- (k * m + - y)
≡⟨ ≡.cong -_ (begin
k * m + - y
≡˘⟨ +-identityʳ _ ⟩
k * m + - y + +0
≡˘⟨ ≡.cong (k * m + - y +_) (+-inverseʳ x) ⟩
k * m + - y + (x + - x)
≡˘⟨ +-assoc (k * m + - y) x (- x) ⟩
k * m + - y + x + - x
≡⟨ ≡.cong (_+ - x) (begin
k * m + - y + x
≡⟨ +-assoc (k * m) (- y) x ⟩
k * m + (- y + x)
≡⟨ ≡.cong (k * m +_) (+-comm (- y) x) ⟩
k * m + (x + - y)
≡˘⟨ +-assoc (k * m) x (- y) ⟩
k * m + x + - y
≡⟨ ≡.cong (_+ - y) p ⟩
y + - y
≡⟨ +-inverseʳ y ⟩
+0
∎) ⟩
+0 + - x
≡⟨ +-identityˡ (- x) ⟩
- x
∎) ⟩
- - x
≡⟨ neg-involutive x ⟩
x
∎)
where
open ≡.≡-Reasoning
trans : Transitive _≈_
trans {x} {y} {z} (j , p) (k , q) = k + j , (begin
(k + j) * m + x
≡⟨ ≡.cong (_+ x) (*-distribʳ-+ (m) k j) ⟩
k * m + j * m + x
≡⟨ +-assoc (k * m) (j * m) x ⟩
k * m + (j * m + x)
≡⟨ ≡.cong (_+_ (k * m)) p ⟩
k * m + y
≡⟨ q ⟩
z
∎)
where
open ≡.≡-Reasoning
≈-isEquivalence : IsEquivalence _≈_
≈-isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
open IsEquivalence ≈-isEquivalence public using (reflexive)
setoid : Setoid _ _
setoid = record { isEquivalence = ≈-isEquivalence }
open import Algebra.Definitions _≈_
+-cong : Congruent₂ _+_
+-cong {x} {y} {u} {v} (j , p) (k , q) = j + k , (begin
(j + k) * m + (x + u)
≡⟨ ≡.cong (_+ (x + u)) (*-distribʳ-+ m j k) ⟩
j * m + k * m + (x + u)
≡˘⟨ +-assoc (j * m + k * m) x u ⟩
j * m + k * m + x + u
≡⟨ ≡.cong (_+ u) (begin
j * m + k * m + x
≡⟨ +-assoc (j * m) (k * m) x ⟩
j * m + (k * m + x)
≡⟨ ≡.cong (j * m +_) (+-comm (k * m) x) ⟩
j * m + (x + k * m)
≡˘⟨ +-assoc (j * m) x (k * m) ⟩
j * m + x + k * m
∎) ⟩
j * m + x + k * m + u
≡⟨ +-assoc (j * m + x) (k * m) u ⟩
j * m + x + (k * m + u)
≡⟨ ≡.cong₂ _+_ p q ⟩
y + v
∎)
where
open ≡.≡-Reasoning
*-cong : Congruent₂ _*_
*-cong {x} {y} {u} {v} (j , p) (k , q) = j * m * k + j * u + x * k , (begin
(j * m * k + j * u + x * k) * m + x * u
≡⟨ ≡.cong (_+ x * u) (begin
(j * m * k + j * u + x * k) * m
≡⟨ *-distribʳ-+ m (j * m * k + j * u) (x * k) ⟩
(j * m * k + j * u) * m + (x * k) * m
≡⟨ ≡.cong₂ _+_ (*-distribʳ-+ m (j * m * k) (j * u)) (*-assoc x k m) ⟩
j * m * k * m + j * u * m + x * (k * m)
≡⟨ ≡.cong (_+ x * (k * m)) (begin
j * m * k * m + (j * u) * m
≡⟨ ≡.cong (_+ j * u * m) (*-assoc (j * m) k m) ⟩
j * m * (k * m) + j * u * m
≡⟨ ≡.cong (j * m * (k * m) +_) (begin
j * u * m
≡⟨ *-assoc j u m ⟩
j * (u * m)
≡⟨ ≡.cong (j *_) (*-comm u m) ⟩
j * (m * u)
≡˘⟨ *-assoc j m u ⟩
j * m * u
∎) ⟩
(j * m) * (k * m) + (j * m) * u
∎) ⟩
j * m * (k * m) + j * m * u + x * (k * m)
∎) ⟩
(j * m) * (k * m) + (j * m) * u + x * (k * m) + x * u
≡⟨ +-assoc ((j * m) * (k * m) + (j * m) * u) (x * (k * m)) (x * u) ⟩
(j * m) * (k * m) + (j * m) * u + (x * (k * m) + x * u)
≡˘⟨ ≡.cong₂ _+_ (*-distribˡ-+ (j * m) (k * m) u) (*-distribˡ-+ x (k * m) u) ⟩
(j * m) * (k * m + u) + x * (k * m + u)
≡˘⟨ *-distribʳ-+ (k * m + u) (j * m) x ⟩
(j * m + x) * (k * m + u)
≡⟨ ≡.cong₂ _*_ p q ⟩
y * v
∎)
where
open ≡.≡-Reasoning
neg-cong : Congruent₁ -_
neg-cong {x} {y} (k , p) = - k , (begin
- k * m + - x
≡˘⟨ ≡.cong (_+ - x) (neg-distribˡ-* k m) ⟩
- (k * m) + - x
≡˘⟨ neg-distrib-+ (k * m) x ⟩
- (k * m + x)
≡⟨ ≡.cong -_ p ⟩
- y
∎)
where
open ≡.≡-Reasoning
+-0-isAbelianGroup : IsAbelianGroup _≈_ _+_ +0 -_
+-0-isAbelianGroup = record
{ isGroup = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≈-isEquivalence
; ∙-cong = +-cong
}
; assoc = λ x y z → reflexive (+-assoc x y z)
}
; identity = (λ x → reflexive (+-identityˡ x)) , λ x → reflexive (+-identityʳ x)
}
; inverse = (λ x → reflexive (+-inverseˡ x)) , λ x → reflexive(+-inverseʳ x)
; ⁻¹-cong = neg-cong
}
; comm = λ x y → reflexive (+-comm x y)
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _≈_ _*_ (Integer.+ 1)
*-1-isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≈-isEquivalence
; ∙-cong = *-cong
}
; assoc = λ x y z → reflexive (*-assoc x y z)
}
; identity = (λ x → reflexive (*-identityˡ x)) , λ x → reflexive (*-identityʳ x )
}
; comm = λ x y → reflexive (*-comm x y)
}
open IsCommutativeMonoid *-1-isCommutativeMonoid using () renaming (isMonoid to *-1-isMonoid)
+-*-isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ +0 (Integer.+ 1)
+-*-isCommutativeRing = record
{ isRing = record
{ +-isAbelianGroup = +-0-isAbelianGroup
; *-isMonoid = *-1-isMonoid
; distrib = (λ x y z → reflexive (*-distribˡ-+ x y z)) , λ x y z → reflexive (*-distribʳ-+ x y z)
; zero = (λ x → reflexive (*-zeroˡ x)) , λ x → reflexive (*-zeroʳ x)
}
; *-comm = λ x y → reflexive (*-comm x y)
}
| 27.801802
| 105
| 0.423364
|
fb793932d4f9672abe5a6ff865895bbda6678870
| 1,099
|
agda
|
Agda
|
test/Succeed/Issue1110.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1110.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1110.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --allow-unsolved-metas #-}
-- Andreas, 2014-05-17 reported by Fabien Renaud
open import Common.Equality
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
data List {a} (A : Set a) : Set a where
[] : List A
_∷_ : A → List A → List A
length : ∀{a}{A : Set a} → List A → Nat
length [] = zero
length (x ∷ xs) = suc (length xs)
foldr : ∀{a b}{A : Set a}{B : Set b} → (A → B → B) → B → List A → B
foldr c n [] = n
foldr c n (x ∷ xs) = c x (foldr c n xs)
length-cons : ∀{b} {B : Set b} (L : List B) x → length (x ∷ L) ≡ suc (length L)
length-cons [] _ = refl
length-cons (x ∷ L) _ = refl
suc-foldr-eq : ∀{b} {c} {B : Set b} {C : Set c} (LL : List B) (LA : List C)
→ suc (foldr (λ _ → suc) 0 LL) ≡
suc (foldr (λ _ → suc) 0 LA)
→ length LL ≡
length LA
suc-foldr-eq [] [] Eq = refl
suc-foldr-eq [] (x ∷ LA) ()
suc-foldr-eq (x ∷ LL) [] ()
suc-foldr-eq (x ∷ LL) (y ∷ LA) Eq rewrite length-cons LL x = {!!}
-- WAS:
-- Failed to infer the value of dotted pattern
-- when checking that the pattern ._ has type Nat
-- NOW: unsolved meta
| 23.382979
| 79
| 0.55414
|
50cf5e3403bbe0f6e8f11ac20fa2ec15c7c7fc69
| 1,177
|
agda
|
Agda
|
test/Succeed/Issue2322.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2322.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2322.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --guardedness #-}
open import Agda.Builtin.Coinduction
open import Agda.Builtin.Equality
record Reveal_·_is_ {A : Set} {B : A → Set}
(f : (x : A) → B x) (x : A) (y : B x) :
Set where
constructor [_]
field eq : f x ≡ y
inspect : {A : Set} {B : A → Set}
(f : (x : A) → B x) (x : A) → Reveal f · x is f x
inspect f x = [ refl ]
infixr 5 _∷_
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
infix 4 _≈_
data _≈_ {A} : Stream A → Stream A → Set where
_∷_ : ∀ {x y xs ys}
(x≡ : x ≡ y) (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ y ∷ ys
map : ∀ {A B} → (A → B) → Stream A → Stream B
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
map₂ : ∀ {A B} → (A → B) → Stream A → Stream B
map₂ f (x ∷ xs) with ♭ xs
map₂ f (x ∷ xs) | y ∷ ys = f x ∷ ♯ (f y ∷ ♯ map₂ f (♭ ys))
map≈map₂ : ∀ {A B} →
(f : A → B) → (xs : Stream A) → map f xs ≈ map₂ f xs
map≈map₂ {A} f (x ∷ xs) with ♭ xs | inspect ♭ xs
map≈map₂ {A} f (x ∷ xs) | y ∷ ys | [ eq ] = refl ∷ ♯ helper eq
where
map-f-y∷ys = _
helper : ∀ {xs} → xs ≡ y ∷ ys → map f xs ≈ map-f-y∷ys
helper refl = refl ∷ ♯ map≈map₂ f (♭ ys)
| 27.372093
| 63
| 0.468139
|
2f4c4bf8fcef6752ddbf7bc465460636a3630121
| 394
|
agda
|
Agda
|
test/Succeed/Issue1523b.agda
|
MxmUrw/agda
|
6ede01fa854c5472e54f7d1799ca2c08ed316129
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1523b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1523b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS --copatterns #-}
-- {-# OPTIONS -v tc.lhs:20 #-}
{-# OPTIONS --sized-types #-}
open import Common.Size
record Stream (i : Size) (A : Set) : Set where
coinductive
constructor _::_
field
head : A
tail : ∀ {j : Size< i} → Stream j A
open Stream public
-- size forgetful cons
cons : ∀ i {A} → A → Stream i A → Stream (↑ i) A
cons i a as = a :: as
-- Should work
| 18.761905
| 48
| 0.576142
|
1d2ae4d857f10898eec54863e616755066cf35c7
| 3,128
|
agda
|
Agda
|
Base/Syntax/Context.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 10
|
2015-03-04T06:09:20.000Z
|
2019-07-19T07:06:59.000Z
|
Base/Syntax/Context.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 6
|
2015-07-01T18:09:31.000Z
|
2017-05-04T13:53:59.000Z
|
Base/Syntax/Context.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 1
|
2016-02-18T12:26:44.000Z
|
2016-02-18T12:26:44.000Z
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Variables and contexts
--
-- This module defines the syntax of contexts and subcontexts,
-- together with variables and properties of these notions.
--
-- This module is parametric in the syntax of types, so it
-- can be reused for different calculi.
------------------------------------------------------------------------
module Base.Syntax.Context
(Type : Set)
where
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
-- Typing Contexts
-- ===============
import Data.List as List
open import Base.Data.ContextList public
Context : Set
Context = List.List Type
-- Variables
-- =========
--
-- Here it is clear that we are using de Bruijn indices,
-- encoded as natural numbers, more or less.
data Var : Context → Type → Set where
this : ∀ {Γ τ} → Var (τ • Γ) τ
that : ∀ {Γ σ τ} → (x : Var Γ τ) → Var (σ • Γ) τ
-- Weakening
-- =========
--
-- We define weakening based on subcontext relationship.
-- Subcontexts
-- -----------
--
-- Useful as a reified weakening operation,
-- and for making theorems strong enough to prove by induction.
--
-- The contents of this module are currently exported at the end
-- of this file.
-- This handling of contexts is recommended by [this
-- email](https://lists.chalmers.se/pipermail/agda/2011/003423.html) and
-- attributed to Conor McBride.
--
-- The associated thread discusses a few alternatives solutions, including one
-- where beta-reduction can handle associativity of ++.
module Subcontexts where
infix 4 _≼_
data _≼_ : (Γ₁ Γ₂ : Context) → Set where
∅ : ∅ ≼ ∅
keep_•_ : ∀ {Γ₁ Γ₂} →
(τ : Type) →
Γ₁ ≼ Γ₂ →
τ • Γ₁ ≼ τ • Γ₂
drop_•_ : ∀ {Γ₁ Γ₂} →
(τ : Type) →
Γ₁ ≼ Γ₂ →
Γ₁ ≼ τ • Γ₂
-- Properties
∅≼Γ : ∀ {Γ} → ∅ ≼ Γ
∅≼Γ {∅} = ∅
∅≼Γ {τ • Γ} = drop τ • ∅≼Γ
≼-refl : Reflexive _≼_
≼-refl {∅} = ∅
≼-refl {τ • Γ} = keep τ • ≼-refl
≼-reflexive : ∀ {Γ₁ Γ₂} → Γ₁ ≡ Γ₂ → Γ₁ ≼ Γ₂
≼-reflexive refl = ≼-refl
≼-trans : Transitive _≼_
≼-trans ≼₁ ∅ = ≼₁
≼-trans (keep .τ • ≼₁) (keep τ • ≼₂) = keep τ • ≼-trans ≼₁ ≼₂
≼-trans (drop .τ • ≼₁) (keep τ • ≼₂) = drop τ • ≼-trans ≼₁ ≼₂
≼-trans ≼₁ (drop τ • ≼₂) = drop τ • ≼-trans ≼₁ ≼₂
≼-isPreorder : IsPreorder _≡_ _≼_
≼-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ≼-reflexive
; trans = ≼-trans
}
≼-preorder : Preorder _ _ _
≼-preorder = record
{ Carrier = Context
; _≈_ = _≡_
; _∼_ = _≼_
; isPreorder = ≼-isPreorder
}
module ≼-Reasoning where
open import Relation.Binary.PreorderReasoning ≼-preorder public
renaming
( _≈⟨_⟩_ to _≡⟨_⟩_
; _∼⟨_⟩_ to _≼⟨_⟩_
; _≈⟨⟩_ to _≡⟨⟩_
)
-- Lift a variable to a super context
weaken-var : ∀ {Γ₁ Γ₂ τ} → Γ₁ ≼ Γ₂ → Var Γ₁ τ → Var Γ₂ τ
weaken-var (keep τ • ≼₁) this = this
weaken-var (keep τ • ≼₁) (that x) = that (weaken-var ≼₁ x)
weaken-var (drop τ • ≼₁) x = that (weaken-var ≼₁ x)
-- Currently, we export the subcontext relation.
open Subcontexts public
| 25.024
| 78
| 0.568414
|
a162e56c4fd08370ec22b9563ecca9ee1184cca5
| 2,498
|
agda
|
Agda
|
Cubical/HITs/Rationals/QuoQ/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Rationals/QuoQ/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/Rationals/QuoQ/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Rationals.QuoQ.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Data.Nat as ℕ using (discreteℕ)
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Sigma
open import Cubical.HITs.Ints.QuoInt
open import Cubical.HITs.SetQuotients as SetQuotient
using ([_]; eq/; discreteSetQuotients) renaming (_/_ to _//_) public
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open BinaryRelation
ℕ₊₁→ℤ : ℕ₊₁ → ℤ
ℕ₊₁→ℤ n = pos (ℕ₊₁→ℕ n)
private
ℕ₊₁→ℤ-hom : ∀ m n → ℕ₊₁→ℤ (m ·₊₁ n) ≡ ℕ₊₁→ℤ m · ℕ₊₁→ℤ n
ℕ₊₁→ℤ-hom _ _ = refl
-- ℚ as a set quotient of ℤ × ℕ₊₁ (as in the HoTT book)
_∼_ : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → Type₀
(a , b) ∼ (c , d) = a · ℕ₊₁→ℤ d ≡ c · ℕ₊₁→ℤ b
ℚ : Type₀
ℚ = (ℤ × ℕ₊₁) // _∼_
isSetℚ : isSet ℚ
isSetℚ = SetQuotient.squash/
[_/_] : ℤ → ℕ₊₁ → ℚ
[ a / b ] = [ a , b ]
isEquivRel∼ : isEquivRel _∼_
isEquivRel.reflexive isEquivRel∼ (a , b) = refl
isEquivRel.symmetric isEquivRel∼ (a , b) (c , d) = sym
isEquivRel.transitive isEquivRel∼ (a , b) (c , d) (e , f) p q = ·-injʳ _ _ _ r
where r = (a · ℕ₊₁→ℤ f) · ℕ₊₁→ℤ d ≡[ i ]⟨ ·-comm a (ℕ₊₁→ℤ f) i · ℕ₊₁→ℤ d ⟩
(ℕ₊₁→ℤ f · a) · ℕ₊₁→ℤ d ≡⟨ sym (·-assoc (ℕ₊₁→ℤ f) a (ℕ₊₁→ℤ d)) ⟩
ℕ₊₁→ℤ f · (a · ℕ₊₁→ℤ d) ≡[ i ]⟨ ℕ₊₁→ℤ f · p i ⟩
ℕ₊₁→ℤ f · (c · ℕ₊₁→ℤ b) ≡⟨ ·-assoc (ℕ₊₁→ℤ f) c (ℕ₊₁→ℤ b) ⟩
(ℕ₊₁→ℤ f · c) · ℕ₊₁→ℤ b ≡[ i ]⟨ ·-comm (ℕ₊₁→ℤ f) c i · ℕ₊₁→ℤ b ⟩
(c · ℕ₊₁→ℤ f) · ℕ₊₁→ℤ b ≡[ i ]⟨ q i · ℕ₊₁→ℤ b ⟩
(e · ℕ₊₁→ℤ d) · ℕ₊₁→ℤ b ≡⟨ sym (·-assoc e (ℕ₊₁→ℤ d) (ℕ₊₁→ℤ b)) ⟩
e · (ℕ₊₁→ℤ d · ℕ₊₁→ℤ b) ≡[ i ]⟨ e · ·-comm (ℕ₊₁→ℤ d) (ℕ₊₁→ℤ b) i ⟩
e · (ℕ₊₁→ℤ b · ℕ₊₁→ℤ d) ≡⟨ ·-assoc e (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ d) ⟩
(e · ℕ₊₁→ℤ b) · ℕ₊₁→ℤ d ∎
eq/⁻¹ : ∀ x y → Path ℚ [ x ] [ y ] → x ∼ y
eq/⁻¹ = SetQuotient.effective (λ _ _ → isSetℤ _ _) isEquivRel∼
discreteℚ : Discrete ℚ
discreteℚ = discreteSetQuotients (discreteΣ discreteℤ (λ _ → subst Discrete 1+Path discreteℕ))
(λ _ _ → isSetℤ _ _) isEquivRel∼ (λ _ _ → discreteℤ _ _)
-- 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 ] }
| 32.441558
| 94
| 0.556045
|
41d0d317e6790ad8101fb3da9aebf84f650d0670
| 1,463
|
agda
|
Agda
|
src/exercices/Commerce.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | 2
|
2021-03-12T18:31:14.000Z
|
2021-05-04T09:35:36.000Z
|
src/exercices/Commerce.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | null | null | null |
src/exercices/Commerce.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | null | null | null |
--
-- Created by Dependently-Typed Lambda Calculus on 2020-09-23
-- Commerce
-- Author: dplaindoux
--
{-# OPTIONS --without-K --safe #-}
module Commerce where
open import Relation.Nullary using (Reflects; Dec; yes; no)
open import Data.Bool using (Bool; true; false)
open import Data.Nat using (ℕ; _+_; _≥?_; _≥_)
open import Agda.Builtin.Nat using (_-_)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎; step-≡)
module Customer where
record Account : Set where
field
balance : ℕ
account : ℕ -> Account
account n = record { balance = n }
_↑_ : Account → ℕ → Account
c ↑ n = account (Account.balance c + n)
_↓_ : Account → ℕ → Account
c ↓ n = account (Account.balance c - n )
infixl 50 _↑_
infixl 50 _↓_
module Product where
record Item : Set where
field
price : ℕ
data Basket : Set where
∅ : Basket
_then_ : Item → Basket → Basket
total : Basket → ℕ
total ∅ = 0
total (a then b) = Item.price a + total b
module Payment where
open Customer
open Product
pay : (c : Account) → (p : Basket) → {Account.balance c ≥ total p} → Account
pay c p = c ↓ total p
module Front where
pay? : Account → Basket → Account
pay? c p with Account.balance c ≥? total p
... | yes proof = pay c p {proof}
... | no _ = c
| 23.983607
| 80
| 0.597403
|
d06ccf83e04074488e927c138f78301a1668726a
| 2,984
|
agda
|
Agda
|
Categories/Category/Construction/EnrichedFunctors.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Construction/EnrichedFunctors.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Construction/EnrichedFunctors.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using () renaming (Category to Setoid-Category)
open import Categories.Category.Monoidal
module Categories.Category.Construction.EnrichedFunctors
{o ℓ e} {V : Setoid-Category o ℓ e} (M : Monoidal V) where
-- The (enriched) functor category for a given pair of V-enriched categories
open import Level
open import Data.Product using (_,_; uncurry′)
open import Categories.Enriched.Category M
open import Categories.Enriched.Functor M renaming (id to idF)
open import Categories.Enriched.NaturalTransformation M renaming (id to idNT)
open import Categories.Functor.Bifunctor using (Bifunctor)
open NaturalTransformation using (_[_])
EnrichedFunctors : ∀ {c d} (C : Category c) (D : Category d) →
Setoid-Category (ℓ ⊔ e ⊔ c ⊔ d) (ℓ ⊔ e ⊔ c) (e ⊔ c)
EnrichedFunctors C D = record
{ Obj = Functor C D
; _⇒_ = NaturalTransformation
; _≈_ = λ α β → ∀ {X} → α [ X ] ≈ β [ X ]
; id = idNT
; _∘_ = _∘ᵥ_
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = Equiv.refl
; sym = λ α≈β → Equiv.sym α≈β
; trans = λ α≈β β≈γ → Equiv.trans α≈β β≈γ
}
; ∘-resp-≈ = λ α₁≈β₁ α₂≈β₂ → ∘-resp-≈ α₁≈β₁ α₂≈β₂
}
where open Underlying D
-- Horizontal composition of natural transformations (aka the Godement
-- product) induces a composition functor over functor categories.
--
-- Note that all the equational reasoning happens in the underlying
-- (ordinary) categories!
⊚ : ∀ {c d e} {C : Category c} {D : Category d} {E : Category e} →
Bifunctor (EnrichedFunctors D E) (EnrichedFunctors C D) (EnrichedFunctors C E)
⊚ {_} {_} {_} {_} {D} {E} = record
{ F₀ = uncurry′ _∘F_
; F₁ = uncurry′ _∘ₕ_
; identity = λ{ {F , G} {X} →
begin
(F $₁ D.id) ∘ E.id ≈⟨ identityʳ ⟩
F $₁ D.id ≈⟨ identity F ⟩
E.id ∎ }
; homomorphism = λ{ {_ , F₂} {G₁ , G₂} {H₁ , _} {α₁ , α₂} {β₁ , β₂} {X} →
begin
H₁ $₁ (β₂ [ X ] D.∘ α₂ [ X ]) ∘ β₁ [ F₂ $₀ X ] ∘ α₁ [ F₂ $₀ X ]
≈⟨ homomorphism H₁ ⟩∘⟨refl ⟩
(H₁ $₁ β₂ [ X ] ∘ H₁ $₁ α₂ [ X ]) ∘ β₁ [ F₂ $₀ X ] ∘ α₁ [ F₂ $₀ X ]
≈⟨ ⟺ assoc ○ ∘-resp-≈ˡ assoc ⟩
(H₁ $₁ β₂ [ X ] ∘ (H₁ $₁ α₂ [ X ] ∘ β₁ [ F₂ $₀ X ])) ∘ α₁ [ F₂ $₀ X ]
≈˘⟨ (refl⟩∘⟨ commute β₁ (α₂ [ X ])) ⟩∘⟨refl ⟩
(H₁ $₁ β₂ [ X ] ∘ (β₁ [ G₂ $₀ X ] ∘ G₁ $₁ α₂ [ X ])) ∘ α₁ [ F₂ $₀ X ]
≈˘⟨ ⟺ assoc ○ ∘-resp-≈ˡ assoc ⟩
(H₁ $₁ β₂ [ X ] ∘ β₁ [ G₂ $₀ X ]) ∘ G₁ $₁ α₂ [ X ] ∘ α₁ [ F₂ $₀ X ]
∎ }
; F-resp-≈ = λ{ {_} {F , _} (eq₁ , eq₂) → ∘-resp-≈ (F-resp-≈ F eq₂) eq₁ }
}
where
module D = Underlying D
module E = Underlying E
open E hiding (id)
open HomReasoning
open UnderlyingFunctor hiding (F₀; F₁)
open UnderlyingNT
-- Aliases used to shorten some proof expressions
infixr 14 _$₀_ _$₁_
_$₀_ = UnderlyingFunctor.F₀
_$₁_ = UnderlyingFunctor.F₁
| 34.697674
| 82
| 0.577078
|
59cd4169829d53ac64aedd0ec5c285c77b1d3ee2
| 9,296
|
agda
|
Agda
|
Cubical/HITs/SmashProduct/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/SmashProduct/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/SmashProduct/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.HITs.SmashProduct.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.Pushout.Base
open import Cubical.Data.Unit
open import Cubical.Data.Prod
open import Cubical.HITs.Wedge
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
data Smash {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') : Type (ℓ-max ℓ ℓ') where
basel : Smash A B
baser : Smash A B
proj : (x : typ A) → (y : typ B) → Smash A B
gluel : (a : typ A) → proj a (pt B) ≡ basel
gluer : (b : typ B) → proj (pt A) b ≡ baser
private
variable
ℓ ℓ' : Level
A B C D : Pointed ℓ
Smash-map : (f : A →∙ C) (g : B →∙ D) → Smash A B → Smash C D
Smash-map f g basel = basel
Smash-map f g baser = baser
Smash-map (f , fpt) (g , gpt) (proj x y) = proj (f x) (g y)
Smash-map (f , fpt) (g , gpt) (gluel a i) = ((λ j → proj (f a) (gpt j)) ∙ gluel (f a)) i
Smash-map (f , fpt) (g , gpt) (gluer b i) = ((λ j → proj (fpt j) (g b)) ∙ gluer (g b)) i
-- Commutativity
comm : Smash A B → Smash B A
comm basel = baser
comm baser = basel
comm (proj x y) = proj y x
comm (gluel a i) = gluer a i
comm (gluer b i) = gluel b i
commK : (x : Smash A B) → comm (comm x) ≡ x
commK basel = refl
commK baser = refl
commK (proj x y) = refl
commK (gluel a x) = refl
commK (gluer b x) = refl
-- WIP below
SmashPt : (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
SmashPt A B = (Smash A B , basel)
SmashPtProj : (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
SmashPtProj A B = Smash A B , (proj (snd A) (snd B))
--- Alternative definition
i∧ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} → A ⋁ B → (typ A) × (typ B)
i∧ {A = A , ptA} {B = B , ptB} (inl x) = x , ptB
i∧ {A = A , ptA} {B = B , ptB} (inr x) = ptA , x
i∧ {A = A , ptA} {B = B , ptB} (push tt i) = ptA , ptB
_⋀_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Type (ℓ-max ℓ ℓ')
A ⋀ B = Pushout {A = (A ⋁ B)} (λ _ → tt) i∧
_⋀∙_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Pointed (ℓ-max ℓ ℓ')
A ⋀∙ B = Pushout {A = (A ⋁ B)} (λ _ → tt) i∧ , (inl tt)
_⋀→_ : (f : A →∙ C) (g : B →∙ D) → A ⋀ B → C ⋀ D
(f ⋀→ g) (inl tt) = inl tt
((f , fpt) ⋀→ (g , gpt)) (inr (x , x₁)) = inr (f x , g x₁)
_⋀→_ {B = B} {D = D} (f , fpt) (b , gpt) (push (inl x) i) = (push (inl (f x)) ∙ (λ i → inr (f x , gpt (~ i)))) i
_⋀→_ (f , fpt) (g , gpt) (push (inr x) i) = (push (inr (g x)) ∙ (λ i → inr (fpt (~ i) , g x))) i
_⋀→_ {A = A} {C = C} {B = B} {D = D} (f , fpt) (g , gpt) (push (push tt j) i) =
hcomp (λ k → λ { (i = i0) → inl tt
; (i = i1) → inr (fpt (~ k) , gpt (~ k))
; (j = i0) → compPath-filler (push (inl (fpt (~ k))))
((λ i → inr (fpt (~ k) , gpt (~ i)))) k i
; (j = i1) → compPath-filler (push (inr (gpt (~ k))))
((λ i → inr (fpt (~ i) , gpt (~ k)))) k i})
(push (push tt j) i)
⋀→Smash : A ⋀ B → Smash A B
⋀→Smash (inl x) = basel
⋀→Smash (inr (x , x₁)) = proj x x₁
⋀→Smash (push (inl x) i) = gluel x (~ i)
⋀→Smash {A = A} {B = B} (push (inr x) i) = (sym (gluel (snd A)) ∙∙ gluer (snd B) ∙∙ sym (gluer x)) i
⋀→Smash {A = A} {B = B} (push (push a j) i) =
hcomp (λ k → λ { (i = i0) → gluel (snd A) (k ∨ ~ j)
; (i = i1) → gluer (snd B) (~ k ∧ j)
; (j = i0) → gluel (snd A) (~ i)})
(invSides-filler (gluel (snd A)) (gluer (snd B)) j (~ i))
Smash→⋀ : Smash A B → A ⋀ B
Smash→⋀ basel = inl tt
Smash→⋀ baser = inl tt
Smash→⋀ (proj x y) = inr (x , y)
Smash→⋀ (gluel a i) = push (inl a) (~ i)
Smash→⋀ (gluer b i) = push (inr b) (~ i)
{- associativity maps for smash produts. Proof pretty much direcly translated from https://github.com/ecavallo/redtt/blob/master/library/pointed/smash.red -}
private
pivotl : (b b' : typ B)
→ Path (Smash A B) (proj (snd A) b) (proj (snd A) b')
pivotl b b' i = (gluer b ∙ sym (gluer b')) i
pivotr : (a a' : typ A)
→ Path (Smash A B) (proj a (snd B)) (proj a' (snd B))
pivotr a a' i = (gluel a ∙ sym (gluel a')) i
pivotlrId : {A : Pointed ℓ} {B : Pointed ℓ'} → _
pivotlrId {A = A} {B = B} = rCancel (gluer (snd B)) ∙ sym (rCancel (gluel (snd A)))
rearrange-proj : (c : fst C)
→ (Smash A B) → Smash (SmashPtProj C B) A
rearrange-proj c basel = baser
rearrange-proj c baser = basel
rearrange-proj c (proj x y) = proj (proj c y) x
rearrange-proj {C = C} c (gluel a i) =
hcomp (λ k → λ { (i = i0) → proj (pivotr (snd C) c k) a
; (i = i1) → baser})
(gluer a i)
rearrange-proj c (gluer b i) = gluel (proj c b) i
rearrange-gluel : (s : Smash A B)
→ Path (Smash (SmashPtProj C B) A) basel (rearrange-proj (snd C) s)
rearrange-gluel {A = A} {B = B} {C = C} basel = sym (gluel (proj (snd C) (snd B))) ∙
gluer (snd A)
rearrange-gluel baser = refl
rearrange-gluel {A = A} {B = B} {C = C} (proj a b) i =
hcomp (λ k → λ { (i = i0) → (sym (gluel (proj (snd C) (snd B))) ∙
gluer (snd A)) (~ k)
; (i = i1) → proj (pivotl (snd B) b k) a})
(gluer a (~ i))
rearrange-gluel {A = A} {B = B} {C = C} (gluel a i) j =
hcomp (λ k → λ { (i = i1) → ((λ i₁ → gluel (proj (snd C) (snd B)) (~ i₁)) ∙
gluer (snd A)) (~ k ∨ j)
; (j = i0) → ((λ i₁ → gluel (proj (snd C) (snd B)) (~ i₁)) ∙
gluer (snd A)) (~ k)
; (j = i1) → top-filler i k})
(gluer a (i ∨ ~ j))
where
top-filler : I → I → Smash (SmashPtProj C B) A
top-filler i j =
hcomp (λ k → λ { (i = i0) → side-filler k j
; (i = i1) → gluer a (j ∨ k)
; (j = i0) → gluer a (i ∧ k)})
(gluer a (i ∧ j))
where
side-filler : I → I → Smash (SmashPtProj C B) A
side-filler i j =
hcomp (λ k → λ { (i = i0) → proj (proj (snd C) (snd B)) a
; (i = i1) → proj ((rCancel (gluel (snd C)) ∙ sym (rCancel (gluer (snd B)))) k j) a
; (j = i0) → proj (proj (snd C) (snd B)) a
; (j = i1) → (proj ((gluel (snd C) ∙ sym (gluel (snd C))) i) a)})
(proj ((gluel (snd C) ∙ sym (gluel (snd C))) (j ∧ i)) a)
rearrange-gluel {A = A} {B = B} {C = C} (gluer b i) j =
hcomp (λ k → λ {(i = i1) → ((sym (gluel (proj (snd C) (snd B)))) ∙ gluer (snd A)) (~ k)
; (j = i0) → ((sym (gluel (proj (snd C) (snd B)))) ∙ gluer (snd A)) (~ k)
; (j = i1) → top-filler1 i k})
(gluer (snd A) (i ∨ (~ j)))
where
top-filler1 : I → I → Smash (SmashPtProj C B) A
top-filler1 i j =
hcomp (λ k → λ { (i = i0) → congFunct (λ x → proj x (snd A)) (gluer (snd B)) (sym (gluer b)) (~ k) j
; (i = i1) → (sym (gluel (proj (snd C) (snd B))) ∙ gluer (snd A)) (~ j)
; (j = i0) → gluer (snd A) i
; (j = i1) → gluel (proj (snd C) b) i})
(top-filler2 i j)
where
top-filler2 : I → I → Smash (SmashPtProj C B) A
top-filler2 i j =
hcomp (λ k → λ { (j = i0) → gluer (snd A) (i ∧ k)
; (j = i1) → gluel (gluer b (~ k)) i})
(hcomp (λ k → λ { (j = i0) → gluel (gluer (snd B) i0) (~ k ∧ (~ i))
; (j = i1) → gluel (baser) (~ k ∨ i)
; (i = i0) → gluel (gluer (snd B) j) (~ k)
; (i = i1) → gluel (proj (snd C) (snd B)) j })
(gluel (proj (snd C) (snd B)) (j ∨ (~ i))))
rearrange : Smash (SmashPtProj A B) C → Smash (SmashPtProj C B) A
rearrange basel = basel
rearrange baser = baser
rearrange (proj x y) = rearrange-proj y x
rearrange (gluel a i) = rearrange-gluel a (~ i)
rearrange {A = A} {B = B} {C = C} (gluer b i) = ((λ j → proj (pivotr b (snd C) j) (snd A)) ∙
gluer (snd A)) i
⋀∙→SmashPtProj : (A ⋀∙ B) →∙ SmashPtProj A B
⋀∙→SmashPtProj {A = A} {B = B} = fun , refl
where
fun : (A ⋀ B) → Smash A B
fun (inl x) = proj (snd A) (snd B)
fun (inr (x , x₁)) = proj x x₁
fun (push (inl x) i) = pivotr (snd A) x i
fun (push (inr x) i) = pivotl (snd B) x i
fun (push (push a j) i) = pivotlrId (~ j) i
SmashPtProj→⋀∙ : (SmashPtProj A B) →∙ (A ⋀∙ B)
SmashPtProj→⋀∙ {A = A} {B = B} = Smash→⋀ , sym (push (inr (snd B)))
SmashAssociate : Smash (SmashPtProj A B) C → Smash A (SmashPtProj B C)
SmashAssociate = comm ∘ Smash-map (comm , refl) (idfun∙ _) ∘ rearrange
SmashAssociate⁻ : Smash A (SmashPtProj B C) → Smash (SmashPtProj A B) C
SmashAssociate⁻ = rearrange ∘ comm ∘ Smash-map (idfun∙ _) (comm , refl)
⋀-associate : (A ⋀∙ B) ⋀ C → A ⋀ (B ⋀∙ C)
⋀-associate = (idfun∙ _ ⋀→ SmashPtProj→⋀∙) ∘ Smash→⋀ ∘ SmashAssociate ∘ ⋀→Smash ∘ (⋀∙→SmashPtProj ⋀→ idfun∙ _)
⋀-associate⁻ : A ⋀ (B ⋀∙ C) → (A ⋀∙ B) ⋀ C
⋀-associate⁻ = (SmashPtProj→⋀∙ ⋀→ idfun∙ _) ∘ Smash→⋀ ∘ SmashAssociate⁻ ∘ ⋀→Smash ∘ (idfun∙ _ ⋀→ ⋀∙→SmashPtProj)
| 43.439252
| 157
| 0.472569
|
cbbb62e0b4d17cf6949a48db0015ff7d289c709d
| 702
|
agda
|
Agda
|
test/Fail/Issue2423.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/Issue2423.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue2423.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2017-01-21, issue #2423 overloading inherited projections
-- {-# OPTIONS -v tc.lhs.split:30 #-}
-- {-# OPTIONS -v tc.proj.amb:100 #-}
-- {-# OPTIONS -v tc.mod.apply:100 #-}
postulate
A : Set
record R : Set where
field f : A
record S : Set where
field r : R
open R r public
-- The inherited projection (in the eyes of the scope checker) S.f
-- is actually a composition of projections R.f ∘ S.r
-- s .S.f = s .S.r .R.f
open S
open R
test : S → S
test s .f = s .f
-- Error WAS:
-- Cannot eliminate type S with pattern .f (did you supply too many arguments?)
-- NOW:
-- Cannot eliminate type S with projection R.f
-- Shows the chosen disambiguation in error message.
| 21.272727
| 79
| 0.648148
|
2f224718319f3af18b3f7256165a1ece5e693df2
| 327
|
agda
|
Agda
|
test/features/matrixShapedTerminationOrder/TerminationMixingTupledCurried.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/features/matrixShapedTerminationOrder/TerminationMixingTupledCurried.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/features/matrixShapedTerminationOrder/TerminationMixingTupledCurried.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module TerminationMixingTupledCurried where
data Nat : Set where
zero : Nat
succ : Nat -> Nat
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
good : Nat × Nat -> Nat -> Nat
good (succ x , y) z = good (x , succ y) (succ z)
good (x , succ y) z = good (x , y) x
good xy (succ z) = good xy z
good _ _ = zero
| 20.4375
| 48
| 0.568807
|
41612992a09ef931bf695b50a5aab21844047612
| 603
|
agda
|
Agda
|
plutus-metatheory/test/IntegerOverflow.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 1,299
|
2018-10-02T13:41:39.000Z
|
2022-03-28T01:10:02.000Z
|
plutus-metatheory/test/IntegerOverflow.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 2,493
|
2018-09-28T19:28:17.000Z
|
2022-03-31T15:31:31.000Z
|
plutus-metatheory/test/IntegerOverflow.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 399
|
2018-10-05T09:36:10.000Z
|
2022-03-31T11:18:25.000Z
|
module test.IntegerOverflow where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
open import Agda.Builtin.Sigma
open import Data.Integer
open import Data.Nat
open import Data.Empty
-- plutus/plutus-core/test/data/integerOverflow.plc
-- This term is impossible as terms are intrinsically sized
-- completeting this definition requires an element of the empty type
{-
intOverflow : ∀{Γ} → Γ ⊢ con integer (size⋆ 1)
intOverflow = con (integer 1 (ℤ.pos 128) (-≤+ Σ., +≤+ (gen _ _ {!!})))
-}
| 26.217391
| 70
| 0.74461
|
39adb41fccd4bdeb128a43a422a764d7a987ebd5
| 3,946
|
agda
|
Agda
|
src/fot/FOTC/Program/GCD/Total/TotalityI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/GCD/Total/TotalityI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/GCD/Total/TotalityI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Totality properties of the gcd
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.GCD.Total.TotalityI where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Induction.NonAcc.LexicographicI
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesI
open import FOTC.Data.Nat.Inequalities.PropertiesI
open import FOTC.Data.Nat.PropertiesI
open import FOTC.Program.GCD.Total.ConversionRulesI
open import FOTC.Program.GCD.Total.Definitions
open import FOTC.Program.GCD.Total.GCD
------------------------------------------------------------------------------
-- gcd 0 0 is total.
gcd-00-N : N (gcd zero zero)
gcd-00-N = subst N (sym (gcd-00)) nzero
------------------------------------------------------------------------------
-- gcd 0 (succ n) is total.
gcd-0S-N : ∀ {n} → N n → N (gcd zero (succ₁ n))
gcd-0S-N {n} Nn = subst N (sym (gcd-0S n)) (nsucc Nn)
------------------------------------------------------------------------------
-- gcd (succ₁ n) 0 is total.
gcd-S0-N : ∀ {n} → N n → N (gcd (succ₁ n) zero)
gcd-S0-N {n} Nn = subst N (sym (gcd-S0 n)) (nsucc Nn)
------------------------------------------------------------------------------
-- gcd (succ₁ m) (succ₁ n) when succ₁ m > succ₁ n is total.
gcd-S>S-N : ∀ {m n} → N m → N n →
N (gcd (succ₁ m ∸ succ₁ n) (succ₁ n)) →
succ₁ m > succ₁ n →
N (gcd (succ₁ m) (succ₁ n))
gcd-S>S-N {m} {n} Nm Nn ih Sm>Sn = subst N (sym (gcd-S>S m n Sm>Sn)) ih
------------------------------------------------------------------------------
-- gcd (succ₁ m) (succ₁ n) when succ₁ m ≯ succ₁ n is total.
gcd-S≯S-N : ∀ {m n} → N m → N n →
N (gcd (succ₁ m) (succ₁ n ∸ succ₁ m)) →
succ₁ m ≯ succ₁ n →
N (gcd (succ₁ m) (succ₁ n))
gcd-S≯S-N {m} {n} Nm Nn ih Sm≯Sn = subst N (sym (gcd-S≯S m n Sm≯Sn)) ih
------------------------------------------------------------------------------
-- gcd m n when m > n is total.
gcd-x>y-N :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → N (gcd o p)) →
m > n →
N (gcd m n)
gcd-x>y-N nzero Nn _ 0>n = ⊥-elim (0>x→⊥ Nn 0>n)
gcd-x>y-N (nsucc Nm) nzero _ _ = gcd-S0-N Nm
gcd-x>y-N (nsucc {m} Nm) (nsucc {n} Nn) ah Sm>Sn = gcd-S>S-N Nm Nn ih Sm>Sn
where
-- Inductive hypothesis.
ih : N (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))
ih = ah {succ₁ m ∸ succ₁ n}
{succ₁ n}
(∸-N (nsucc Nm) (nsucc Nn))
(nsucc Nn)
([Sx∸Sy,Sy]<[Sx,Sy] Nm Nn)
------------------------------------------------------------------------------
-- gcd m n when m ≯ n is total.
gcd-x≯y-N :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → N (gcd o p)) →
m ≯ n →
N (gcd m n)
gcd-x≯y-N nzero nzero _ _ = gcd-00-N
gcd-x≯y-N nzero (nsucc Nn) _ _ = gcd-0S-N Nn
gcd-x≯y-N (nsucc _) nzero _ Sm≯0 = ⊥-elim (S≯0→⊥ Sm≯0)
gcd-x≯y-N (nsucc {m} Nm) (nsucc {n} Nn) ah Sm≯Sn = gcd-S≯S-N Nm Nn ih Sm≯Sn
where
-- Inductive hypothesis.
ih : N (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))
ih = ah {succ₁ m}
{succ₁ n ∸ succ₁ m}
(nsucc Nm)
(∸-N (nsucc Nn) (nsucc Nm))
([Sx,Sy∸Sx]<[Sx,Sy] Nm Nn)
------------------------------------------------------------------------------
-- gcd m n is total.
gcd-N : ∀ {m n} → N m → N n → N (gcd m n)
gcd-N = Lexi-wfind A h
where
A : D → D → Set
A i j = N (gcd i j)
h : ∀ {i j} → N i → N j → (∀ {k l} → N k → N l → Lexi k l i j → A k l) →
A i j
h Ni Nj ah = case (gcd-x>y-N Ni Nj ah) (gcd-x≯y-N Ni Nj ah) (x>y∨x≯y Ni Nj)
| 37.942308
| 78
| 0.424734
|
57bd54d8f0a7a9559025bed0c822d205a945b5b0
| 52
|
agda
|
Agda
|
test/Fail/Unknown-name-in-polarity-pragma.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Unknown-name-in-polarity-pragma.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Unknown-name-in-polarity-pragma.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --warning=error #-}
{-# POLARITY F #-}
| 13
| 31
| 0.538462
|
41185121bbdac32d2b512e85df6cd485bb4fcd20
| 2,131
|
agda
|
Agda
|
BasicIPC/Syntax/HilbertSequential.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIPC/Syntax/HilbertSequential.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIPC/Syntax/HilbertSequential.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Basic intuitionistic propositional calculus, without ∨ or ⊥.
-- Hilbert-style formalisation of syntax.
-- Sequences of terms.
module BasicIPC.Syntax.HilbertSequential where
open import BasicIPC.Syntax.Common public
-- Derivations.
infix 3 _⊦⊢_
data _⊦⊢_ (Γ : Cx Ty) : Cx Ty → Set where
nil : Γ ⊦⊢ ∅
var : ∀ {Ξ A} → A ∈ Γ → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , A
mp : ∀ {Ξ A B} → A ▻ B ∈ Ξ → A ∈ Ξ → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , B
ci : ∀ {Ξ A} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , A ▻ A
ck : ∀ {Ξ A B} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , A ▻ B ▻ A
cs : ∀ {Ξ A B C} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cpair : ∀ {Ξ A B} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , A ▻ B ▻ A ∧ B
cfst : ∀ {Ξ A B} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , A ∧ B ▻ A
csnd : ∀ {Ξ A B} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , A ∧ B ▻ B
unit : ∀ {Ξ} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ , ⊤
infix 3 _⊢_
_⊢_ : Cx Ty → Ty → Set
Γ ⊢ A = ∃ (λ Ξ → Γ ⊦⊢ Ξ , A)
-- Monotonicity with respect to context inclusion.
mono⊦⊢ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊦⊢ Ξ → Γ′ ⊦⊢ Ξ
mono⊦⊢ η nil = nil
mono⊦⊢ η (var i ts) = var (mono∈ η i) (mono⊦⊢ η ts)
mono⊦⊢ η (mp i j ts) = mp i j (mono⊦⊢ η ts)
mono⊦⊢ η (ci ts) = ci (mono⊦⊢ η ts)
mono⊦⊢ η (ck ts) = ck (mono⊦⊢ η ts)
mono⊦⊢ η (cs ts) = cs (mono⊦⊢ η ts)
mono⊦⊢ η (cpair ts) = cpair (mono⊦⊢ η ts)
mono⊦⊢ η (cfst ts) = cfst (mono⊦⊢ η ts)
mono⊦⊢ η (csnd ts) = csnd (mono⊦⊢ η ts)
mono⊦⊢ η (unit ts) = unit (mono⊦⊢ η ts)
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (Ξ , ts) = Ξ , mono⊦⊢ η ts
-- Concatenation of derivations.
_⧺⊦_ : ∀ {Γ Ξ Ξ′} → Γ ⊦⊢ Ξ → Γ ⊦⊢ Ξ′ → Γ ⊦⊢ Ξ ⧺ Ξ′
us ⧺⊦ nil = us
us ⧺⊦ var i ts = var i (us ⧺⊦ ts)
us ⧺⊦ mp i j ts = mp (mono∈ weak⊆⧺₂ i) (mono∈ weak⊆⧺₂ j) (us ⧺⊦ ts)
us ⧺⊦ ci ts = ci (us ⧺⊦ ts)
us ⧺⊦ ck ts = ck (us ⧺⊦ ts)
us ⧺⊦ cs ts = cs (us ⧺⊦ ts)
us ⧺⊦ cpair ts = cpair (us ⧺⊦ ts)
us ⧺⊦ cfst ts = cfst (us ⧺⊦ ts)
us ⧺⊦ csnd ts = csnd (us ⧺⊦ ts)
us ⧺⊦ unit ts = unit (us ⧺⊦ ts)
-- Modus ponens in expanded form.
app : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
app {A} {B} (Ξ , ts) (Ξ′ , us) = Ξ″ , vs
where Ξ″ = (Ξ′ , A) ⧺ (Ξ , A ▻ B)
vs = mp top (mono∈ (weak⊆⧺₁ (Ξ , A ▻ B)) top) (us ⧺⊦ ts)
| 30.884058
| 71
| 0.441107
|
57e28d61cf14efa360d9df34533431ab8f6ea0e8
| 3,621
|
agda
|
Agda
|
src/Categories/Enriched/Functor.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Enriched/Functor.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Enriched/Functor.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (module Commutation) renaming (Category to Setoid-Category)
open import Categories.Category.Monoidal using (Monoidal)
module Categories.Enriched.Functor {o ℓ e} {V : Setoid-Category o ℓ e}
(M : Monoidal V) where
open import Level
open import Categories.Enriched.Category M
open import Categories.Enriched.Category.Underlying M
open import Categories.Functor using () renaming (Functor to Setoid-Functor)
open import Categories.Morphism.Reasoning V
open import Categories.Category.Monoidal.Reasoning M using (⊗-distrib-over-∘)
open Setoid-Category V renaming (Obj to ObjV; id to idV)
open Commutation V
open HomReasoning
open Monoidal M
record Functor {c d} (C : Category c) (D : Category d) : Set (ℓ ⊔ e ⊔ c ⊔ d) where
eta-equality
private
module C = Category C
module D = Category D
field
map₀ : C.Obj → D.Obj
map₁ : ∀ {X Y} → C [ X , Y ] ⇒ D [ map₀ X , map₀ Y ]
identity : ∀ {X} → map₁ ∘ C.id ≈ D.id {map₀ X}
homomorphism : ∀ {X Y Z} →
[ C [ Y , Z ] ⊗₀ C [ X , Y ] ⇒ D [ map₀ X , map₀ Z ] ]⟨
C.⊚ ⇒⟨ C [ X , Z ] ⟩ map₁
≈ map₁ ⊗₁ map₁ ⇒⟨ D [ _ , _ ] ⊗₀ D [ _ , _ ] ⟩ D.⊚
⟩
-- We don't need an analogue of F-resp-≈ because |hom A B| is not
-- a hom-Setoid but a hom-object (in V) and the functorial action
-- is not a Setoid-map but a V-morphism. Whether V-objects have a
-- notion of equality, and whether such equalities are preserved
-- by V-morphisms, depends entirely on V.
-- Shorthands for the functorial actions that work well as
-- post-projections.
₀ = map₀
₁ = map₁
Endofunctor : ∀ {c} → Category c → Set (ℓ ⊔ e ⊔ c)
Endofunctor C = Functor C C
id : ∀ {c} {C : Category c} → Endofunctor C
id {_} {C} = record
{ map₀ = λ X → X
; map₁ = idV
; identity = identityˡ
; homomorphism = id-comm-sym ○ ∘-resp-≈ʳ (⟺ ⊗.identity)
}
where
open Category C
infixr 9 _∘F_
_∘F_ : ∀ {c d e} {C : Category c} {D : Category d} {E : Category e} →
Functor D E → Functor C D → Functor C E
_∘F_ {_} {_} {_} {C} {D} {E} G F = record
{ map₀ = λ X → G.₀ (F.₀ X)
; map₁ = G.₁ ∘ F.₁
; identity = begin
(G.₁ ∘ F.₁) ∘ C.id ≈⟨ pullʳ F.identity ⟩
G.₁ ∘ D.id ≈⟨ G.identity ⟩
E.id ∎
; homomorphism = begin
(G.₁ ∘ F.₁) ∘ C.⊚ ≈⟨ pullʳ F.homomorphism ⟩
G.₁ ∘ (D.⊚ ∘ F.₁ ⊗₁ F.₁) ≈⟨ pullˡ G.homomorphism ⟩
(E.⊚ ∘ G.₁ ⊗₁ G.₁) ∘ F.₁ ⊗₁ F.₁ ≈˘⟨ pushʳ ⊗-distrib-over-∘ ⟩
E.⊚ ∘ (G.₁ ∘ F.₁) ⊗₁ (G.₁ ∘ F.₁) ∎
}
where
module C = Category C
module D = Category D
module E = Category E
module F = Functor F
module G = Functor G
-- A V-enriched functor induces an ordinary functor on the underlying
-- categories.
module _ {c d} {C : Category c} {D : Category d} where
UnderlyingFunctor : Functor C D → Setoid-Functor (Underlying C) (Underlying D)
UnderlyingFunctor F = record
{ F₀ = F.₀
; F₁ = F.₁ ∘_
; identity = F.identity
; homomorphism = λ {_} {_} {_} {f} {g} → begin
F.₁ ∘ C.⊚ ∘ g ⊗₁ f ∘ λ⇐ ≈⟨ pullˡ F.homomorphism ⟩
(D.⊚ ∘ F.₁ ⊗₁ F.₁) ∘ g ⊗₁ f ∘ λ⇐ ≈˘⟨ pushʳ (pushˡ ⊗-distrib-over-∘) ⟩
D.⊚ ∘ (F.₁ ∘ g) ⊗₁ (F.₁ ∘ f) ∘ λ⇐ ∎
; F-resp-≈ = ∘-resp-≈ʳ
}
where
module C = Category C
module D = Category D
module F = Functor F
λ⇐ = unitorˡ.to
module UnderlyingFunctor F = Setoid-Functor (UnderlyingFunctor F)
| 32.330357
| 97
| 0.5562
|
314adc4507da08e8aafe6fb0d8a935cd6346bc1e
| 1,217
|
agda
|
Agda
|
Categories/Functor/Diagonal.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Functor/Diagonal.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Functor/Diagonal.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Functor.Diagonal where
open import Data.Product
open import Categories.Category
open import Categories.Functor
open import Categories.Product
open import Categories.FunctorCategory
open import Categories.Functor.Constant
import Categories.Power as Power
Δ : ∀ {o ℓ e} → (C : Category o ℓ e) → Functor C (Product C C)
Δ C = record
{ F₀ = λ x → x , x
; F₁ = λ f → f , f
; identity = refl , refl
; homomorphism = refl , refl
; F-resp-≡ = λ x → x , x
}
where
open Category C
open Equiv
Δ′ : ∀ {o ℓ e} → (I : Set) → (C : Category o ℓ e) → Functor C (Power.Exp C I)
Δ′ I C = record
{ F₀ = λ x _ → x
; F₁ = λ f _ → f
; identity = λ _ → refl
; homomorphism = λ _ → refl
; F-resp-≡ = λ x _ → x
}
where
open Power C
open Category C
open Equiv
ΔF : ∀ {o ℓ e o₁ ℓ₁ e₁} {C : Category o ℓ e} (I : Category o₁ ℓ₁ e₁) → Functor C (Functors I C)
ΔF {C = C} I = record
{ F₀ = λ c → Constant c
; F₁ = λ f → record { η = λ X → f; commute = λ g → trans C.identityʳ (sym C.identityˡ) }
; identity = refl
; homomorphism = refl
; F-resp-≡ = λ x → x
}
where
module C = Category C
open C.Equiv
module I = Category I
| 23.862745
| 95
| 0.608053
|
590d71a4bbe28c2e4b13265c021b28180f6dfdf2
| 406
|
agda
|
Agda
|
test/succeed/InstanceGuessesMeta.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/succeed/InstanceGuessesMeta.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/InstanceGuessesMeta.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- Andreas, 2012-01-10
-- {-# OPTIONS -v tc.constr.findInScope:50 #-}
module InstanceGuessesMeta where
data Bool : Set where
true false : Bool
postulate
D : Bool -> Set
E : Bool -> Set
d : {x : Bool} -> D x
f : {x : Bool}{{ dx : D x }} -> E x
b : E true
b = f -- should succeed
-- Agda is now allowed to solve hidden x in type of d by unification,
-- when searching for inhabitant of D x
| 23.882353
| 70
| 0.618227
|
df363ebc3bcd49fc593f5ceef4702fec3c8d605a
| 5,260
|
agda
|
Agda
|
Cubical/Data/Queue/Untruncated2List.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Data/Queue/Untruncated2List.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Data/Queue/Untruncated2List.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --no-exact-split --safe #-}
module Cubical.Data.Queue.Untruncated2List where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.SIP
open import Cubical.Structures.Queue
open import Cubical.Data.Maybe
open import Cubical.Data.List
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Queue.1List
module Untruncated2List {ℓ} (A : Type ℓ) (Aset : isSet A) where
open Queues-on A Aset
-- Untruncated 2Lists
data Q : Type ℓ where
Q⟨_,_⟩ : (xs ys : List A) → Q
tilt : ∀ xs ys z → Q⟨ xs ++ [ z ] , ys ⟩ ≡ Q⟨ xs , ys ++ [ z ] ⟩
-- enq into the first list, deq from the second if possible
flushEq' : (xs ys : List A) → Q⟨ xs ++ ys , [] ⟩ ≡ Q⟨ xs , rev ys ⟩
flushEq' xs [] = cong Q⟨_, [] ⟩ (++-unit-r xs)
flushEq' xs (z ∷ ys) j =
hcomp
(λ i → λ
{ (j = i0) → Q⟨ ++-assoc xs [ z ] ys i , [] ⟩
; (j = i1) → tilt xs (rev ys) z i
})
(flushEq' (xs ++ [ z ]) ys j)
flushEq : (xs ys : List A) → Q⟨ xs ++ rev ys , [] ⟩ ≡ Q⟨ xs , ys ⟩
flushEq xs ys = flushEq' xs (rev ys) ∙ cong Q⟨ xs ,_⟩ (rev-rev ys)
emp : Q
emp = Q⟨ [] , [] ⟩
enq : A → Q → Q
enq a Q⟨ xs , ys ⟩ = Q⟨ a ∷ xs , ys ⟩
enq a (tilt xs ys z i) = tilt (a ∷ xs) ys z i
deqFlush : List A → Maybe (Q × A)
deqFlush [] = nothing
deqFlush (x ∷ xs) = just (Q⟨ [] , xs ⟩ , x)
deq : Q → Maybe (Q × A)
deq Q⟨ xs , [] ⟩ = deqFlush (rev xs)
deq Q⟨ xs , y ∷ ys ⟩ = just (Q⟨ xs , ys ⟩ , y)
deq (tilt xs [] z i) = path i
where
path : deqFlush (rev (xs ++ [ z ])) ≡ just (Q⟨ xs , [] ⟩ , z)
path =
cong deqFlush (rev-snoc xs z)
∙ cong (λ q → just (q , z)) (sym (flushEq' [] xs))
deq (tilt xs (y ∷ ys) z i) = just (tilt xs ys z i , y)
Raw : RawQueue
Raw = (Q , emp , enq , deq)
-- We construct an equivalence Q₁≃Q and prove that this is an equivalence of queue structures
private
module One = 1List A Aset
open One renaming (Q to Q₁; emp to emp₁; enq to enq₁; deq to deq₁) using ()
quot : Q₁ → Q
quot xs = Q⟨ xs , [] ⟩
eval : Q → Q₁
eval Q⟨ xs , ys ⟩ = xs ++ rev ys
eval (tilt xs ys z i) =
hcomp
(λ j → λ
{ (i = i0) → (xs ++ [ z ]) ++ rev ys
; (i = i1) → xs ++ rev-snoc ys z (~ j)
})
(++-assoc xs [ z ] (rev ys) i)
quot∘eval : ∀ q → quot (eval q) ≡ q
quot∘eval Q⟨ xs , ys ⟩ = flushEq xs ys
quot∘eval (tilt xs ys z i) j =
hcomp
(λ k → λ
{ (i = i0) →
compPath-filler (flushEq' (xs ++ [ z ]) (rev ys)) (cong Q⟨ xs ++ [ z ] ,_⟩ (rev-rev ys)) k j
; (i = i1) → helper k
; (j = i0) →
Q⟨ compPath-filler (++-assoc xs [ z ] (rev ys)) (cong (xs ++_) (sym (rev-snoc ys z))) k i , [] ⟩
; (j = i1) → tilt xs (rev-rev ys k) z i
})
flushEq'-filler
where
flushEq'-filler : Q
flushEq'-filler =
hfill
(λ i → λ
{ (j = i0) → Q⟨ ++-assoc xs [ z ] (rev ys) i , [] ⟩
; (j = i1) → tilt xs (rev (rev ys)) z i
})
(inS (flushEq' (xs ++ [ z ]) (rev ys) j))
i
helper : I → Q
helper k =
hcomp
(λ l → λ
{ (j = i0) → Q⟨ xs ++ rev-snoc ys z (l ∧ ~ k) , [] ⟩
; (j = i1) → Q⟨ xs , rev-rev-snoc ys z l k ⟩
; (k = i0) → flushEq' xs (rev-snoc ys z l) j
; (k = i1) → flushEq xs (ys ++ [ z ]) j
})
(compPath-filler (flushEq' xs (rev (ys ++ [ z ]))) (cong Q⟨ xs ,_⟩ (rev-rev (ys ++ [ z ]))) k j)
eval∘quot : ∀ xs → eval (quot xs) ≡ xs
eval∘quot = ++-unit-r
-- We get our desired equivalence
quotEquiv : Q₁ ≃ Q
quotEquiv = isoToEquiv (iso quot eval quot∘eval eval∘quot)
-- Now it only remains to prove that this is an equivalence of queue structures
quot∘emp : quot emp₁ ≡ emp
quot∘emp = refl
quot∘enq : ∀ x xs → quot (enq₁ x xs) ≡ enq x (quot xs)
quot∘enq x xs = refl
quot∘deq : ∀ xs → deqMap quot (deq₁ xs) ≡ deq (quot xs)
quot∘deq [] = refl
quot∘deq (x ∷ []) = refl
quot∘deq (x ∷ x' ∷ xs) =
deqMap-∘ quot (enq₁ x) (deq₁ (x' ∷ xs))
∙ sym (deqMap-∘ (enq x) quot (deq₁ (x' ∷ xs)))
∙ cong (deqMap (enq x)) (quot∘deq (x' ∷ xs))
∙ lemma x x' (rev xs)
where
lemma : ∀ x x' ys
→ deqMap (enq x) (deqFlush (ys ++ [ x' ]))
≡ deqFlush ((ys ++ [ x' ]) ++ [ x ])
lemma x x' [] i = just (tilt [] [] x i , x')
lemma x x' (y ∷ ys) i = just (tilt [] (ys ++ [ x' ]) x i , y)
quotEquivHasQueueEquivStr : RawQueueEquivStr One.Raw Raw quotEquiv
quotEquivHasQueueEquivStr = quot∘emp , quot∘enq , quot∘deq
-- And we get a path between the raw 1Lists and 2Lists
Raw-1≡2 : One.Raw ≡ Raw
Raw-1≡2 = sip rawQueueUnivalentStr _ _ (quotEquiv , quotEquivHasQueueEquivStr)
-- We derive the axioms for 2List from those for 1List
WithLaws : Queue
WithLaws = Q , str Raw , subst (uncurry QueueAxioms) Raw-1≡2 (snd (str One.WithLaws))
-- In particular, the untruncated queue type is a set
isSetQ : isSet Q
isSetQ = str WithLaws .snd .fst
WithLaws-1≡2 : One.WithLaws ≡ WithLaws
WithLaws-1≡2 = sip queueUnivalentStr _ _ (quotEquiv , quotEquivHasQueueEquivStr)
Finite : FiniteQueue
Finite = Q , str WithLaws , subst (uncurry FiniteQueueAxioms) WithLaws-1≡2 (snd (str One.Finite))
| 30.941176
| 105
| 0.552091
|
202d89a5a3778c0b674cf9dc1fcd8c934fa14057
| 588
|
agda
|
Agda
|
HoTT.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
HoTT.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
HoTT.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
module HoTT where
open import lib.Basics public
open import lib.types.Types public
open import lib.groups.Groups public
open import lib.cubical.Cubical public
open import lib.NType2 public
open import lib.Equivalences2 public
open import lib.NConnected public
{-
To use coinduction in the form of [∞], [♭] and [♯] you can do:
open import HoTT
open Coinduction
You can also use coinductive records and copatterns instead, that’s prettier
(see experimental/GlobularTypes.agda for an example)
-}
module Coinduction where
open import lib.Coinduction public
| 24.5
| 76
| 0.784014
|
0e0c75ef5cc8ddf159320baf6f11e9abfd963ed4
| 46,435
|
agda
|
Agda
|
Agda/07-finite-sets.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/07-finite-sets.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/07-finite-sets.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split --safe #-}
module 07-finite-sets where
import 06-universes
open 06-universes public
--------------------------------------------------------------------------------
{- Section 7.1 The congruence relations -}
{- Definition 7.1.1 -}
-- We introduce the divisibility relation. --
div-ℕ : ℕ → ℕ → UU lzero
div-ℕ m n = Σ ℕ (λ k → Id (mul-ℕ k m) n)
{- Proposition 7.1.2 -}
{- In the following three constructions we show that if any two of the three
numbers x, y, and x + y, is divisible by d, then so is the third. -}
div-add-ℕ :
(d x y : ℕ) → div-ℕ d x → div-ℕ d y → div-ℕ d (add-ℕ x y)
div-add-ℕ d x y (pair n p) (pair m q) =
pair
( add-ℕ n m)
( ( right-distributive-mul-add-ℕ n m d) ∙
( ap-add-ℕ p q))
div-left-summand-ℕ :
(d x y : ℕ) → div-ℕ d y → div-ℕ d (add-ℕ x y) → div-ℕ d x
div-left-summand-ℕ zero-ℕ x y (pair m q) (pair n p) =
pair zero-ℕ
( ( inv (right-zero-law-mul-ℕ n)) ∙
( p ∙ (ap (add-ℕ x) ((inv q) ∙ (right-zero-law-mul-ℕ m)))))
div-left-summand-ℕ (succ-ℕ d) x y (pair m q) (pair n p) =
pair
( dist-ℕ m n)
( is-injective-add-ℕ (mul-ℕ m (succ-ℕ d)) (mul-ℕ (dist-ℕ m n) (succ-ℕ d)) x
( ( inv
( ( right-distributive-mul-add-ℕ m (dist-ℕ m n) (succ-ℕ d)) ∙
( commutative-add-ℕ
( mul-ℕ m (succ-ℕ d))
( mul-ℕ (dist-ℕ m n) (succ-ℕ d))))) ∙
( ( ap
( mul-ℕ' (succ-ℕ d))
( leq-dist-ℕ m n
( leq-leq-mul-ℕ' m n d
( concatenate-eq-leq-eq-ℕ q
( leq-add-ℕ' y x)
( inv p))))) ∙
( p ∙ (ap (add-ℕ x) (inv q))))))
div-right-summand-ℕ :
(d x y : ℕ) → div-ℕ d x → div-ℕ d (add-ℕ x y) → div-ℕ d y
div-right-summand-ℕ d x y H1 H2 =
div-left-summand-ℕ d y x H1 (tr (div-ℕ d) (commutative-add-ℕ x y) H2)
{- Definition 7.1.3 -}
{- We define the congruence relation on ℕ and we do some bureaucracy that will
help us in calculations involving the congruence relations. -}
cong-ℕ :
ℕ → ℕ → ℕ → UU lzero
cong-ℕ k x y = div-ℕ k (dist-ℕ x y)
_≡_mod_ : ℕ → ℕ → ℕ → UU lzero
x ≡ y mod k = cong-ℕ k x y
concatenate-eq-cong-eq-ℕ :
(k : ℕ) {x1 x2 x3 x4 : ℕ} →
Id x1 x2 → cong-ℕ k x2 x3 → Id x3 x4 → cong-ℕ k x1 x4
concatenate-eq-cong-eq-ℕ k refl H refl = H
concatenate-eq-cong-ℕ :
(k : ℕ) {x1 x2 x3 : ℕ} →
Id x1 x2 → cong-ℕ k x2 x3 → cong-ℕ k x1 x3
concatenate-eq-cong-ℕ k refl H = H
concatenate-cong-eq-ℕ :
(k : ℕ) {x1 x2 x3 : ℕ} →
cong-ℕ k x1 x2 → Id x2 x3 → cong-ℕ k x1 x3
concatenate-cong-eq-ℕ k H refl = H
{- Proposition 7.1.4 -}
-- We show that cong-ℕ is an equivalence relation.
reflexive-cong-ℕ :
(k x : ℕ) → cong-ℕ k x x
reflexive-cong-ℕ k x =
pair zero-ℕ ((left-zero-law-mul-ℕ (succ-ℕ k)) ∙ (dist-eq-ℕ x x refl))
cong-identification-ℕ :
(k : ℕ) {x y : ℕ} → Id x y → cong-ℕ k x y
cong-identification-ℕ k {x} refl = reflexive-cong-ℕ k x
symmetric-cong-ℕ :
(k x y : ℕ) → cong-ℕ k x y → cong-ℕ k y x
symmetric-cong-ℕ k x y (pair d p) =
pair d (p ∙ (symmetric-dist-ℕ x y))
{- Before we show that cong-ℕ is transitive, we give some lemmas that will help
us showing that cong is an equivalence relation. They are basically
bureaucracy, manipulating already known facts. -}
-- Three elements can be ordered in 6 possible ways
cases-order-three-elements-ℕ :
(x y z : ℕ) → UU lzero
cases-order-three-elements-ℕ x y z =
coprod
( coprod ((leq-ℕ x y) × (leq-ℕ y z)) ((leq-ℕ x z) × (leq-ℕ z y)))
( coprod
( coprod ((leq-ℕ y z) × (leq-ℕ z x)) ((leq-ℕ y x) × (leq-ℕ x z)))
( coprod ((leq-ℕ z x) × (leq-ℕ x y)) ((leq-ℕ z y) × (leq-ℕ y x))))
order-three-elements-ℕ :
(x y z : ℕ) → cases-order-three-elements-ℕ x y z
order-three-elements-ℕ zero-ℕ zero-ℕ zero-ℕ = inl (inl (pair star star))
order-three-elements-ℕ zero-ℕ zero-ℕ (succ-ℕ z) = inl (inl (pair star star))
order-three-elements-ℕ zero-ℕ (succ-ℕ y) zero-ℕ = inl (inr (pair star star))
order-three-elements-ℕ zero-ℕ (succ-ℕ y) (succ-ℕ z) =
inl (functor-coprod (pair star) (pair star) (decide-leq-ℕ y z))
order-three-elements-ℕ (succ-ℕ x) zero-ℕ zero-ℕ =
inr (inl (inl (pair star star)))
order-three-elements-ℕ (succ-ℕ x) zero-ℕ (succ-ℕ z) =
inr (inl (functor-coprod (pair star) (pair star) (decide-leq-ℕ z x)))
order-three-elements-ℕ (succ-ℕ x) (succ-ℕ y) zero-ℕ =
inr (inr (functor-coprod (pair star) (pair star) (decide-leq-ℕ x y)))
order-three-elements-ℕ (succ-ℕ x) (succ-ℕ y) (succ-ℕ z) =
order-three-elements-ℕ x y z
{- We show that the distances of any three elements always add up, when they
are added up in the right way :) -}
cases-dist-ℕ :
(x y z : ℕ) → UU lzero
cases-dist-ℕ x y z =
coprod
( Id (add-ℕ (dist-ℕ x y) (dist-ℕ y z)) (dist-ℕ x z))
( coprod
( Id (add-ℕ (dist-ℕ y z) (dist-ℕ x z)) (dist-ℕ x y))
( Id (add-ℕ (dist-ℕ x z) (dist-ℕ x y)) (dist-ℕ y z)))
is-total-dist-ℕ :
(x y z : ℕ) → cases-dist-ℕ x y z
is-total-dist-ℕ x y z with order-three-elements-ℕ x y z
is-total-dist-ℕ x y z | inl (inl (pair H1 H2)) =
inl (triangle-equality-dist-ℕ x y z H1 H2)
is-total-dist-ℕ x y z | inl (inr (pair H1 H2)) =
inr
( inl
( ( commutative-add-ℕ (dist-ℕ y z) (dist-ℕ x z)) ∙
( ( ap (add-ℕ (dist-ℕ x z)) (symmetric-dist-ℕ y z)) ∙
( triangle-equality-dist-ℕ x z y H1 H2))))
is-total-dist-ℕ x y z | inr (inl (inl (pair H1 H2))) =
inr
( inl
( ( ap (add-ℕ (dist-ℕ y z)) (symmetric-dist-ℕ x z)) ∙
( ( triangle-equality-dist-ℕ y z x H1 H2) ∙
( symmetric-dist-ℕ y x))))
is-total-dist-ℕ x y z | inr (inl (inr (pair H1 H2))) =
inr
( inr
( ( ap (add-ℕ (dist-ℕ x z)) (symmetric-dist-ℕ x y)) ∙
( ( commutative-add-ℕ (dist-ℕ x z) (dist-ℕ y x)) ∙
( triangle-equality-dist-ℕ y x z H1 H2))))
is-total-dist-ℕ x y z | inr (inr (inl (pair H1 H2))) =
inr
( inr
( ( ap (add-ℕ' (dist-ℕ x y)) (symmetric-dist-ℕ x z)) ∙
( ( triangle-equality-dist-ℕ z x y H1 H2) ∙
( symmetric-dist-ℕ z y))))
is-total-dist-ℕ x y z | inr (inr (inr (pair H1 H2))) =
inl
( ( ap-add-ℕ (symmetric-dist-ℕ x y) (symmetric-dist-ℕ y z)) ∙
( ( commutative-add-ℕ (dist-ℕ y x) (dist-ℕ z y)) ∙
( ( triangle-equality-dist-ℕ z y x H1 H2) ∙
( symmetric-dist-ℕ z x))))
-- Finally, we show that cong-ℕ is transitive.
transitive-cong-ℕ :
(k x y z : ℕ) →
cong-ℕ k x y → cong-ℕ k y z → cong-ℕ k x z
transitive-cong-ℕ k x y z d e with is-total-dist-ℕ x y z
transitive-cong-ℕ k x y z d e | inl α =
tr (div-ℕ k) α (div-add-ℕ k (dist-ℕ x y) (dist-ℕ y z) d e)
transitive-cong-ℕ k x y z d e | inr (inl α) =
div-right-summand-ℕ k (dist-ℕ y z) (dist-ℕ x z) e (tr (div-ℕ k) (inv α) d)
transitive-cong-ℕ k x y z d e | inr (inr α) =
div-left-summand-ℕ k (dist-ℕ x z) (dist-ℕ x y) d (tr (div-ℕ k) (inv α) e)
concatenate-cong-eq-cong-ℕ :
{k x1 x2 x3 x4 : ℕ} →
cong-ℕ k x1 x2 → Id x2 x3 → cong-ℕ k x3 x4 → cong-ℕ k x1 x4
concatenate-cong-eq-cong-ℕ {k} {x} {y} {.y} {z} H refl K =
transitive-cong-ℕ k x y z H K
concatenate-eq-cong-eq-cong-eq-ℕ :
(k : ℕ) {x1 x2 x3 x4 x5 x6 : ℕ} →
Id x1 x2 → cong-ℕ k x2 x3 → Id x3 x4 →
cong-ℕ k x4 x5 → Id x5 x6 → cong-ℕ k x1 x6
concatenate-eq-cong-eq-cong-eq-ℕ k {x} {.x} {y} {.y} {z} {.z} refl H refl K refl =
transitive-cong-ℕ k x y z H K
{- Remark 7.1.6 (this is also Exercise 7.2) -}
-- We show that cong-ℕ one-ℕ is the indiscrete equivalence relation --
div-one-ℕ :
(x : ℕ) → div-ℕ one-ℕ x
div-one-ℕ x = pair x (right-unit-law-mul-ℕ x)
is-indiscrete-cong-one-ℕ :
(x y : ℕ) → cong-ℕ one-ℕ x y
is-indiscrete-cong-one-ℕ x y = div-one-ℕ (dist-ℕ x y)
-- We show that the congruence relation modulo 0 is discrete
div-zero-ℕ :
(k : ℕ) → div-ℕ k zero-ℕ
div-zero-ℕ k = pair zero-ℕ (left-zero-law-mul-ℕ k)
is-discrete-cong-zero-ℕ :
(x y : ℕ) → cong-ℕ zero-ℕ x y → Id x y
is-discrete-cong-zero-ℕ x y (pair k p) =
eq-dist-ℕ x y ((inv (right-zero-law-mul-ℕ k)) ∙ p)
-- We show that d | 1 if and only if d = 1.
-- We show that 0 | x if and only if x = 0.
-- We show that zero-ℕ is congruent to n modulo n.
cong-zero-ℕ :
(k : ℕ) → cong-ℕ k k zero-ℕ
cong-zero-ℕ k =
pair one-ℕ ((left-unit-law-mul-ℕ k) ∙ (inv (right-zero-law-dist-ℕ k)))
cong-zero-ℕ' :
(k : ℕ) → cong-ℕ k zero-ℕ k
cong-zero-ℕ' k =
symmetric-cong-ℕ k k zero-ℕ (cong-zero-ℕ k)
--------------------------------------------------------------------------------
{- Section 7.2 The finite types -}
{- Definition 7.2.1 -}
-- We introduce the finite types as a family indexed by ℕ.
Fin : ℕ → UU lzero
Fin zero-ℕ = empty
Fin (succ-ℕ k) = coprod (Fin k) unit
inl-Fin :
(k : ℕ) → Fin k → Fin (succ-ℕ k)
inl-Fin k = inl
neg-one-Fin : {k : ℕ} → Fin (succ-ℕ k)
neg-one-Fin {k} = inr star
{- Definition 7.2.4 -}
-- We define the inclusion of Fin k into ℕ.
nat-Fin : {k : ℕ} → Fin k → ℕ
nat-Fin {succ-ℕ k} (inl x) = nat-Fin x
nat-Fin {succ-ℕ k} (inr x) = k
{- Lemma 7.2.5 -}
-- We show that nat-Fin is bounded
strict-upper-bound-nat-Fin : {k : ℕ} (x : Fin k) → le-ℕ (nat-Fin x) k
strict-upper-bound-nat-Fin {succ-ℕ k} (inl x) =
transitive-le-ℕ
( nat-Fin x)
( k)
( succ-ℕ k)
( strict-upper-bound-nat-Fin x)
( succ-le-ℕ k)
strict-upper-bound-nat-Fin {succ-ℕ k} (inr star) =
succ-le-ℕ k
-- We also give a non-strict upper bound for convenience
upper-bound-nat-Fin : {k : ℕ} (x : Fin (succ-ℕ k)) → leq-ℕ (nat-Fin x) k
upper-bound-nat-Fin {zero-ℕ} (inr star) = star
upper-bound-nat-Fin {succ-ℕ k} (inl x) =
preserves-leq-succ-ℕ (nat-Fin x) k (upper-bound-nat-Fin x)
upper-bound-nat-Fin {succ-ℕ k} (inr star) = reflexive-leq-ℕ (succ-ℕ k)
{- Proposition 7.2.6 -}
-- We show that nat-Fin is an injective function
neq-le-ℕ : {x y : ℕ} → le-ℕ x y → ¬ (Id x y)
neq-le-ℕ {zero-ℕ} {succ-ℕ y} H = Peano-8 y
neq-le-ℕ {succ-ℕ x} {succ-ℕ y} H p = neq-le-ℕ H (is-injective-succ-ℕ x y p)
is-injective-nat-Fin : {k : ℕ} {x y : Fin k} →
Id (nat-Fin x) (nat-Fin y) → Id x y
is-injective-nat-Fin {succ-ℕ k} {inl x} {inl y} p =
ap inl (is-injective-nat-Fin p)
is-injective-nat-Fin {succ-ℕ k} {inl x} {inr star} p =
ex-falso (neq-le-ℕ (strict-upper-bound-nat-Fin x) p)
is-injective-nat-Fin {succ-ℕ k} {inr star} {inl y} p =
ex-falso (neq-le-ℕ (strict-upper-bound-nat-Fin y) (inv p))
is-injective-nat-Fin {succ-ℕ k} {inr star} {inr star} p =
refl
{- Definition 7.2.7 -}
-- We define the zero element of Fin k.
zero-Fin : {k : ℕ} → Fin (succ-ℕ k)
zero-Fin {zero-ℕ} = inr star
zero-Fin {succ-ℕ k} = inl zero-Fin
-- We define a function skip-zero-Fin in order to define succ-Fin.
skip-zero-Fin : {k : ℕ} → Fin k → Fin (succ-ℕ k)
skip-zero-Fin {succ-ℕ k} (inl x) = inl (skip-zero-Fin x)
skip-zero-Fin {succ-ℕ k} (inr star) = inr star
-- We define the successor function on Fin k.
succ-Fin : {k : ℕ} → Fin k → Fin k
succ-Fin {succ-ℕ k} (inl x) = skip-zero-Fin x
succ-Fin {succ-ℕ k} (inr star) = zero-Fin
{- Definition 7.2.8 -}
-- We define the negative two element of Fin k.
neg-two-Fin :
{k : ℕ} → Fin (succ-ℕ k)
neg-two-Fin {zero-ℕ} = inr star
neg-two-Fin {succ-ℕ k} = inl (inr star)
-- We define a function skip-neg-two-Fin in order to define pred-Fin.
skip-neg-two-Fin :
{k : ℕ} → Fin k → Fin (succ-ℕ k)
skip-neg-two-Fin {succ-ℕ k} (inl x) = inl (inl x)
skip-neg-two-Fin {succ-ℕ k} (inr x) = neg-one-Fin {succ-ℕ k}
-- We define the predecessor function on Fin k.
pred-Fin : {k : ℕ} → Fin k → Fin k
pred-Fin {succ-ℕ k} (inl x) = skip-neg-two-Fin (pred-Fin x)
pred-Fin {succ-ℕ k} (inr x) = neg-two-Fin
{- Definition 7.2.9 -}
-- We define the modulo function
mod-succ-ℕ : (k : ℕ) → ℕ → Fin (succ-ℕ k)
mod-succ-ℕ k zero-ℕ = zero-Fin
mod-succ-ℕ k (succ-ℕ n) = succ-Fin (mod-succ-ℕ k n)
mod-two-ℕ : ℕ → Fin two-ℕ
mod-two-ℕ = mod-succ-ℕ one-ℕ
mod-three-ℕ : ℕ → Fin three-ℕ
mod-three-ℕ = mod-succ-ℕ two-ℕ
{- Lemma 7.2.10 -}
successor-law-mod-succ-ℕ :
(k x : ℕ) → leq-ℕ x k →
Id (mod-succ-ℕ (succ-ℕ k) x) (inl (mod-succ-ℕ k x))
successor-law-mod-succ-ℕ k zero-ℕ star = refl
successor-law-mod-succ-ℕ (succ-ℕ k) (succ-ℕ x) p =
( ( ap succ-Fin
( successor-law-mod-succ-ℕ (succ-ℕ k) x
( preserves-leq-succ-ℕ x k p))) ∙
( ap succ-Fin (ap inl (successor-law-mod-succ-ℕ k x p)))) ∙
( ap inl (ap succ-Fin (inv (successor-law-mod-succ-ℕ k x p))))
{- Corollary 7.2.11 -}
neg-one-law-mod-succ-ℕ :
(k : ℕ) → Id (mod-succ-ℕ k k) neg-one-Fin
neg-one-law-mod-succ-ℕ zero-ℕ = refl
neg-one-law-mod-succ-ℕ (succ-ℕ k) =
ap succ-Fin
( ( successor-law-mod-succ-ℕ k k (reflexive-leq-ℕ k)) ∙
( ap inl (neg-one-law-mod-succ-ℕ k)))
base-case-is-periodic-mod-succ-ℕ :
(k : ℕ) → Id (mod-succ-ℕ k (succ-ℕ k)) zero-Fin
base-case-is-periodic-mod-succ-ℕ zero-ℕ = refl
base-case-is-periodic-mod-succ-ℕ (succ-ℕ k) =
ap succ-Fin (neg-one-law-mod-succ-ℕ (succ-ℕ k))
{- Theorem 7.2.12 -}
-- Now we show that Fin (succ-ℕ k) is a retract of ℕ
issec-nat-Fin : (k : ℕ) (x : Fin (succ-ℕ k)) → Id (mod-succ-ℕ k (nat-Fin x)) x
issec-nat-Fin zero-ℕ (inr star) = refl
issec-nat-Fin (succ-ℕ k) (inl x) =
( successor-law-mod-succ-ℕ k (nat-Fin x) (upper-bound-nat-Fin x)) ∙
( ap inl (issec-nat-Fin k x))
issec-nat-Fin (succ-ℕ k) (inr star) = neg-one-law-mod-succ-ℕ (succ-ℕ k)
--------------------------------------------------------------------------------
{- Section 7.3 The effectiveness theorem of modular arithmetic -}
{- Lemma 7.3.1 -}
-- We prove three things to help calculating with nat-Fin.
nat-zero-Fin :
{k : ℕ} → Id (nat-Fin (zero-Fin {k})) zero-ℕ
nat-zero-Fin {zero-ℕ} = refl
nat-zero-Fin {succ-ℕ k} = nat-zero-Fin {k}
nat-skip-zero-Fin :
{k : ℕ} (x : Fin k) → Id (nat-Fin (skip-zero-Fin x)) (succ-ℕ (nat-Fin x))
nat-skip-zero-Fin {succ-ℕ k} (inl x) = nat-skip-zero-Fin x
nat-skip-zero-Fin {succ-ℕ k} (inr star) = refl
cong-nat-succ-Fin :
(k : ℕ) (x : Fin k) → cong-ℕ k (nat-Fin (succ-Fin x)) (succ-ℕ (nat-Fin x))
cong-nat-succ-Fin (succ-ℕ k) (inl x) =
cong-identification-ℕ
( succ-ℕ k)
{ nat-Fin (succ-Fin (inl x))}
{ succ-ℕ (nat-Fin x)}
( nat-skip-zero-Fin x)
cong-nat-succ-Fin (succ-ℕ k) (inr star) =
concatenate-eq-cong-ℕ
( succ-ℕ k)
{ nat-Fin {succ-ℕ k} zero-Fin}
{ zero-ℕ}
{ succ-ℕ k}
( nat-zero-Fin {k})
( cong-zero-ℕ' (succ-ℕ k))
{- Corollary 7.3.2 -}
-- We show that (nat-Fin (mod-succ-ℕ n x)) is congruent to x modulo n+1. --
cong-nat-mod-succ-ℕ :
(k x : ℕ) → cong-ℕ (succ-ℕ k) (nat-Fin (mod-succ-ℕ k x)) x
cong-nat-mod-succ-ℕ k zero-ℕ =
cong-identification-ℕ (succ-ℕ k) (nat-zero-Fin {k})
cong-nat-mod-succ-ℕ k (succ-ℕ x) =
transitive-cong-ℕ
( succ-ℕ k)
( nat-Fin (mod-succ-ℕ k (succ-ℕ x)))
( succ-ℕ (nat-Fin (mod-succ-ℕ k x)))
( succ-ℕ x)
( cong-nat-succ-Fin (succ-ℕ k) (mod-succ-ℕ k x) )
( cong-nat-mod-succ-ℕ k x)
{- Proposition 7.3.4 -}
contradiction-leq-ℕ :
(x y : ℕ) → leq-ℕ x y → leq-ℕ (succ-ℕ y) x → empty
contradiction-leq-ℕ (succ-ℕ x) (succ-ℕ y) H K = contradiction-leq-ℕ x y H K
eq-zero-div-ℕ :
(d x : ℕ) → leq-ℕ x d → div-ℕ (succ-ℕ d) x → Id x zero-ℕ
eq-zero-div-ℕ d zero-ℕ H D = refl
eq-zero-div-ℕ d (succ-ℕ x) H (pair (succ-ℕ k) p) =
ex-falso
( contradiction-leq-ℕ d x
( concatenate-eq-leq-eq-ℕ
{ x1 = succ-ℕ d}
{ x2 = succ-ℕ d}
{ x3 = succ-ℕ (add-ℕ (mul-ℕ k (succ-ℕ d)) d)}
{ x4 = succ-ℕ x}
( refl)
( leq-add-ℕ' d (mul-ℕ k (succ-ℕ d)))
( p)) H)
{- Theorem 7.3.5 -}
{- We show that if mod-succ-ℕ k x = mod-succ-ℕ k y, then x and y must be
congruent modulo succ-ℕ n. This is the forward direction of the theorm. -}
cong-eq-ℕ :
(k x y : ℕ) → Id (mod-succ-ℕ k x) (mod-succ-ℕ k y) → cong-ℕ (succ-ℕ k) x y
cong-eq-ℕ k x y p =
concatenate-cong-eq-cong-ℕ {succ-ℕ k} {x}
( symmetric-cong-ℕ (succ-ℕ k) (nat-Fin (mod-succ-ℕ k x)) x
( cong-nat-mod-succ-ℕ k x))
( ap nat-Fin p)
( cong-nat-mod-succ-ℕ k y)
eq-cong-nat-Fin :
(k : ℕ) (x y : Fin k) → cong-ℕ k (nat-Fin x) (nat-Fin y) → Id x y
eq-cong-nat-Fin (succ-ℕ k) x y H =
is-injective-nat-Fin
( eq-dist-ℕ
( nat-Fin x)
( nat-Fin y)
( inv
( eq-zero-div-ℕ k
( dist-ℕ (nat-Fin x) (nat-Fin y))
( upper-bound-dist-ℕ k
( nat-Fin x)
( nat-Fin y)
( upper-bound-nat-Fin x)
( upper-bound-nat-Fin y))
( H))))
eq-cong-ℕ :
(k x y : ℕ) → cong-ℕ (succ-ℕ k) x y → Id (mod-succ-ℕ k x) (mod-succ-ℕ k y)
eq-cong-ℕ k x y H =
eq-cong-nat-Fin
( succ-ℕ k)
( mod-succ-ℕ k x)
( mod-succ-ℕ k y)
( transitive-cong-ℕ
( succ-ℕ k)
( nat-Fin (mod-succ-ℕ k x))
( x)
( nat-Fin (mod-succ-ℕ k y))
( cong-nat-mod-succ-ℕ k x)
( transitive-cong-ℕ (succ-ℕ k) x y (nat-Fin (mod-succ-ℕ k y)) H
( symmetric-cong-ℕ (succ-ℕ k) (nat-Fin (mod-succ-ℕ k y)) y
( cong-nat-mod-succ-ℕ k y))))
--------------------------------------------------------------------------------
{- Section 7.4 The cyclic group structure on the finite types -}
{- Definition 7.4.1 -}
-- Addition on finite sets --
add-Fin : {k : ℕ} → Fin k → Fin k → Fin k
add-Fin {succ-ℕ k} x y = mod-succ-ℕ k (add-ℕ (nat-Fin x) (nat-Fin y))
add-Fin' : {k : ℕ} → Fin k → Fin k → Fin k
add-Fin' x y = add-Fin y x
-- We define an action on paths of add-Fin on the two arguments at once.
ap-add-Fin :
{k : ℕ} {x y x' y' : Fin k} →
Id x x' → Id y y' → Id (add-Fin x y) (add-Fin x' y')
ap-add-Fin refl refl = refl
-- The negative of an element of Fin k --
neg-Fin :
{k : ℕ} → Fin k → Fin k
neg-Fin {succ-ℕ k} x =
mod-succ-ℕ k (dist-ℕ (nat-Fin x) (succ-ℕ k))
{- Remark 7.4.2 -}
cong-nat-zero-Fin :
{k : ℕ} → cong-ℕ (succ-ℕ k) (nat-Fin (zero-Fin {k})) zero-ℕ
cong-nat-zero-Fin {k} = cong-nat-mod-succ-ℕ k zero-ℕ
cong-add-Fin :
{k : ℕ} (x y : Fin k) →
cong-ℕ k (nat-Fin (add-Fin x y)) (add-ℕ (nat-Fin x) (nat-Fin y))
cong-add-Fin {succ-ℕ k} x y =
cong-nat-mod-succ-ℕ k (add-ℕ (nat-Fin x) (nat-Fin y))
cong-neg-Fin :
{k : ℕ} (x : Fin k) →
cong-ℕ k (nat-Fin (neg-Fin x)) (dist-ℕ (nat-Fin x) k)
cong-neg-Fin {succ-ℕ k} x =
cong-nat-mod-succ-ℕ k (dist-ℕ (nat-Fin x) (succ-ℕ k))
{- Proposition 7.4.3 -}
-- We show that congruence is translation invariant --
translation-invariant-cong-ℕ :
(k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (add-ℕ z x) (add-ℕ z y)
translation-invariant-cong-ℕ k x y z (pair d p) =
pair d (p ∙ inv (translation-invariant-dist-ℕ z x y))
translation-invariant-cong-ℕ' :
(k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (add-ℕ x z) (add-ℕ y z)
translation-invariant-cong-ℕ' k x y z H =
concatenate-eq-cong-eq-ℕ k
( commutative-add-ℕ x z)
( translation-invariant-cong-ℕ k x y z H)
( commutative-add-ℕ z y)
step-invariant-cong-ℕ :
(k x y : ℕ) → cong-ℕ k x y → cong-ℕ k (succ-ℕ x) (succ-ℕ y)
step-invariant-cong-ℕ k x y = translation-invariant-cong-ℕ' k x y one-ℕ
-- We show that addition respects the congruence relation --
congruence-add-ℕ :
(k : ℕ) {x y x' y' : ℕ} →
cong-ℕ k x x' → cong-ℕ k y y' → cong-ℕ k (add-ℕ x y) (add-ℕ x' y')
congruence-add-ℕ k {x} {y} {x'} {y'} H K =
transitive-cong-ℕ k (add-ℕ x y) (add-ℕ x y') (add-ℕ x' y')
( translation-invariant-cong-ℕ k y y' x K)
( translation-invariant-cong-ℕ' k x x' y' H)
{- Theorem 7.4.4 -}
-- We show that addition is commutative --
commutative-add-Fin : {k : ℕ} (x y : Fin k) → Id (add-Fin x y) (add-Fin y x)
commutative-add-Fin {succ-ℕ k} x y =
ap (mod-succ-ℕ k) (commutative-add-ℕ (nat-Fin x) (nat-Fin y))
-- We show that addition is associative --
associative-add-Fin :
{k : ℕ} (x y z : Fin k) →
Id (add-Fin (add-Fin x y) z) (add-Fin x (add-Fin y z))
associative-add-Fin {succ-ℕ k} x y z =
eq-cong-ℕ k
( add-ℕ (nat-Fin (add-Fin x y)) (nat-Fin z))
( add-ℕ (nat-Fin x) (nat-Fin (add-Fin y z)))
( concatenate-cong-eq-cong-ℕ
{ x1 = add-ℕ (nat-Fin (add-Fin x y)) (nat-Fin z)}
{ x2 = add-ℕ (add-ℕ (nat-Fin x) (nat-Fin y)) (nat-Fin z)}
{ x3 = add-ℕ (nat-Fin x) (add-ℕ (nat-Fin y) (nat-Fin z))}
{ x4 = add-ℕ (nat-Fin x) (nat-Fin (add-Fin y z))}
( congruence-add-ℕ
( succ-ℕ k)
{ x = nat-Fin (add-Fin x y)}
{ y = nat-Fin z}
{ x' = add-ℕ (nat-Fin x) (nat-Fin y)}
{ y' = nat-Fin z}
( cong-add-Fin x y)
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin z)))
( associative-add-ℕ (nat-Fin x) (nat-Fin y) (nat-Fin z))
( congruence-add-ℕ
( succ-ℕ k)
{ x = nat-Fin x}
{ y = add-ℕ (nat-Fin y) (nat-Fin z)}
{ x' = nat-Fin x}
{ y' = nat-Fin (add-Fin y z)}
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin x))
( symmetric-cong-ℕ
( succ-ℕ k)
( nat-Fin (add-Fin y z))
( add-ℕ (nat-Fin y) (nat-Fin z))
( cong-add-Fin y z))))
-- We show that addition satisfies the right unit law --
right-unit-law-add-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (add-Fin x zero-Fin) x
right-unit-law-add-Fin {k} x =
( eq-cong-ℕ k
( add-ℕ (nat-Fin x) (nat-Fin {succ-ℕ k} zero-Fin))
( add-ℕ (nat-Fin x) zero-ℕ)
( congruence-add-ℕ
( succ-ℕ k)
{ x = nat-Fin {succ-ℕ k} x}
{ y = nat-Fin {succ-ℕ k} zero-Fin}
{ x' = nat-Fin x}
{ y' = zero-ℕ}
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin {succ-ℕ k} x))
( cong-nat-zero-Fin {k}))) ∙
( issec-nat-Fin k x)
left-unit-law-add-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (add-Fin zero-Fin x) x
left-unit-law-add-Fin {k} x =
( commutative-add-Fin zero-Fin x) ∙
( right-unit-law-add-Fin x)
-- We show that addition satisfies the left inverse law --
left-inverse-law-add-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (add-Fin (neg-Fin x) x) zero-Fin
left-inverse-law-add-Fin {k} x =
eq-cong-ℕ k (add-ℕ (nat-Fin (neg-Fin x)) (nat-Fin x)) zero-ℕ
( concatenate-cong-eq-cong-ℕ
{ succ-ℕ k}
{ x1 = add-ℕ (nat-Fin (neg-Fin x)) (nat-Fin x)}
{ x2 = add-ℕ (dist-ℕ (nat-Fin x) (succ-ℕ k)) (nat-Fin x)}
{ x3 = succ-ℕ k}
{ x4 = zero-ℕ}
( congruence-add-ℕ
( succ-ℕ k)
{ x = nat-Fin (neg-Fin x)}
{ y = nat-Fin x}
( cong-neg-Fin x)
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin x)))
( ( ap ( add-ℕ (dist-ℕ (nat-Fin x) (succ-ℕ k)))
( inv (left-zero-law-dist-ℕ (nat-Fin x)))) ∙
( ( commutative-add-ℕ
( dist-ℕ (nat-Fin x) (succ-ℕ k))
( dist-ℕ zero-ℕ (nat-Fin x))) ∙
( triangle-equality-dist-ℕ zero-ℕ (nat-Fin x) (succ-ℕ k) star
( preserves-leq-succ-ℕ (nat-Fin x) k (upper-bound-nat-Fin x)))))
( symmetric-cong-ℕ
( succ-ℕ k)
( zero-ℕ)
( succ-ℕ k)
( cong-zero-ℕ (succ-ℕ k))))
right-inverse-law-add-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (add-Fin x (neg-Fin x)) zero-Fin
right-inverse-law-add-Fin x =
( commutative-add-Fin x (neg-Fin x)) ∙ (left-inverse-law-add-Fin x)
--------------------------------------------------------------------------------
{- Exercises -}
{- Exercise 7.1 -}
-- See Proposition 7.1.2
{- Exercise 7.2 -}
{- Exercise 7.3 -}
{- Exercise 7.4 -}
{- Exercise 7.5 -}
{- Exercise 7.6 -}
{- Exercise 7.7 -}
pred-zero-Fin :
{k : ℕ} → Id (pred-Fin {succ-ℕ k} zero-Fin) neg-one-Fin
pred-zero-Fin {zero-ℕ} = refl
pred-zero-Fin {succ-ℕ k} = ap skip-neg-two-Fin (pred-zero-Fin {k})
succ-skip-neg-two-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) →
Id (succ-Fin (skip-neg-two-Fin x)) (inl (succ-Fin x))
succ-skip-neg-two-Fin {zero-ℕ} (inr star) = refl
succ-skip-neg-two-Fin {succ-ℕ k} (inl x) = refl
succ-skip-neg-two-Fin {succ-ℕ k} (inr star) = refl
succ-pred-Fin :
{k : ℕ} (x : Fin k) → Id (succ-Fin (pred-Fin x)) x
succ-pred-Fin {succ-ℕ zero-ℕ} (inr star) = refl
succ-pred-Fin {succ-ℕ (succ-ℕ k)} (inl x) =
succ-skip-neg-two-Fin (pred-Fin x) ∙ ap inl (succ-pred-Fin x)
succ-pred-Fin {succ-ℕ (succ-ℕ k)} (inr star) = refl
pred-succ-Fin :
{k : ℕ} (x : Fin k) → Id (pred-Fin (succ-Fin x)) x
pred-succ-Fin {succ-ℕ zero-ℕ} (inr star) = refl
pred-succ-Fin {succ-ℕ (succ-ℕ k)} (inl (inl x)) =
ap skip-neg-two-Fin (pred-succ-Fin (inl x))
pred-succ-Fin {succ-ℕ (succ-ℕ k)} (inl (inr star)) = refl
pred-succ-Fin {succ-ℕ (succ-ℕ k)} (inr star) = pred-zero-Fin
{- Exercise 7.8 -}
{- Exercise 7.9 -}
reverse-Fin : {k : ℕ} → Fin k → Fin k
reverse-Fin {succ-ℕ k} (inl x) = skip-zero-Fin (reverse-Fin x)
reverse-Fin {succ-ℕ k} (inr x) = zero-Fin
reverse-skip-zero-Fin :
{k : ℕ} (x : Fin k) →
Id (reverse-Fin (skip-zero-Fin x)) (inl-Fin k (reverse-Fin x))
reverse-skip-zero-Fin {succ-ℕ k} (inl x) =
ap skip-zero-Fin (reverse-skip-zero-Fin x)
reverse-skip-zero-Fin {succ-ℕ k} (inr star) = refl
reverse-neg-one-Fin :
{k : ℕ} → Id (reverse-Fin (neg-one-Fin {k})) (zero-Fin {k})
reverse-neg-one-Fin {k} = refl
reverse-zero-Fin :
{k : ℕ} → Id (reverse-Fin (zero-Fin {k})) (neg-one-Fin {k})
reverse-zero-Fin {zero-ℕ} = refl
reverse-zero-Fin {succ-ℕ k} = ap skip-zero-Fin (reverse-zero-Fin {k})
reverse-reverse-Fin :
{k : ℕ} (x : Fin k) → Id (reverse-Fin (reverse-Fin x)) x
reverse-reverse-Fin {succ-ℕ k} (inl x) =
( reverse-skip-zero-Fin (reverse-Fin x)) ∙
( ap inl (reverse-reverse-Fin x))
reverse-reverse-Fin {succ-ℕ k} (inr star) = reverse-zero-Fin
{- Exercise 7.10 -}
-- We show that congruence is invariant under scalar multiplication --
scalar-invariant-cong-ℕ :
(k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (mul-ℕ z x) (mul-ℕ z y)
scalar-invariant-cong-ℕ k x y z (pair d p) =
pair
( mul-ℕ z d)
( ( associative-mul-ℕ z d k) ∙
( ( ap (mul-ℕ z) p) ∙
( inv (linear-dist-ℕ x y z))))
scalar-invariant-cong-ℕ' :
(k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (mul-ℕ x z) (mul-ℕ y z)
scalar-invariant-cong-ℕ' k x y z H =
concatenate-eq-cong-eq-ℕ k
( commutative-mul-ℕ x z)
( scalar-invariant-cong-ℕ k x y z H)
( commutative-mul-ℕ z y)
-- We show that multiplication respects the congruence relation --
congruence-mul-ℕ :
(k : ℕ) {x y x' y' : ℕ} →
cong-ℕ k x x' → cong-ℕ k y y' → cong-ℕ k (mul-ℕ x y) (mul-ℕ x' y')
congruence-mul-ℕ k {x} {y} {x'} {y'} H K =
transitive-cong-ℕ k (mul-ℕ x y) (mul-ℕ x y') (mul-ℕ x' y')
( scalar-invariant-cong-ℕ k y y' x K)
( scalar-invariant-cong-ℕ' k x x' y' H)
{- We define the multiplication on the types Fin k. -}
mul-Fin :
{k : ℕ} → Fin k → Fin k → Fin k
mul-Fin {succ-ℕ k} x y = mod-succ-ℕ k (mul-ℕ (nat-Fin x) (nat-Fin y))
ap-mul-Fin :
{k : ℕ} {x y x' y' : Fin k} →
Id x x' → Id y y' → Id (mul-Fin x y) (mul-Fin x' y')
ap-mul-Fin refl refl = refl
cong-mul-Fin :
{k : ℕ} (x y : Fin k) →
cong-ℕ k (nat-Fin (mul-Fin x y)) (mul-ℕ (nat-Fin x) (nat-Fin y))
cong-mul-Fin {succ-ℕ k} x y =
cong-nat-mod-succ-ℕ k (mul-ℕ (nat-Fin x) (nat-Fin y))
associative-mul-Fin :
{k : ℕ} (x y z : Fin k) →
Id (mul-Fin (mul-Fin x y) z) (mul-Fin x (mul-Fin y z))
associative-mul-Fin {succ-ℕ k} x y z =
eq-cong-ℕ k
( mul-ℕ (nat-Fin (mul-Fin x y)) (nat-Fin z))
( mul-ℕ (nat-Fin x) (nat-Fin (mul-Fin y z)))
( concatenate-cong-eq-cong-ℕ
{ x1 = mul-ℕ (nat-Fin (mul-Fin x y)) (nat-Fin z)}
{ x2 = mul-ℕ (mul-ℕ (nat-Fin x) (nat-Fin y)) (nat-Fin z)}
{ x3 = mul-ℕ (nat-Fin x) (mul-ℕ (nat-Fin y) (nat-Fin z))}
{ x4 = mul-ℕ (nat-Fin x) (nat-Fin (mul-Fin y z))}
( congruence-mul-ℕ
( succ-ℕ k)
{ x = nat-Fin (mul-Fin x y)}
{ y = nat-Fin z}
( cong-mul-Fin x y)
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin z)))
( associative-mul-ℕ (nat-Fin x) (nat-Fin y) (nat-Fin z))
( symmetric-cong-ℕ
( succ-ℕ k)
( mul-ℕ (nat-Fin x) (nat-Fin (mul-Fin y z)))
( mul-ℕ (nat-Fin x) (mul-ℕ (nat-Fin y) (nat-Fin z)))
( congruence-mul-ℕ
( succ-ℕ k)
{ x = nat-Fin x}
{ y = nat-Fin (mul-Fin y z)}
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin x))
( cong-mul-Fin y z))))
commutative-mul-Fin :
{k : ℕ} (x y : Fin k) → Id (mul-Fin x y) (mul-Fin y x)
commutative-mul-Fin {succ-ℕ k} x y =
eq-cong-ℕ k
( mul-ℕ (nat-Fin x) (nat-Fin y))
( mul-ℕ (nat-Fin y) (nat-Fin x))
( cong-identification-ℕ
( succ-ℕ k)
( commutative-mul-ℕ (nat-Fin x) (nat-Fin y)))
one-Fin : {k : ℕ} → Fin (succ-ℕ k)
one-Fin {k} = mod-succ-ℕ k one-ℕ
nat-one-Fin : {k : ℕ} → Id (nat-Fin (one-Fin {succ-ℕ k})) one-ℕ
nat-one-Fin {zero-ℕ} = refl
nat-one-Fin {succ-ℕ k} = nat-one-Fin {k}
left-unit-law-mul-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (mul-Fin one-Fin x) x
left-unit-law-mul-Fin {zero-ℕ} (inr star) = refl
left-unit-law-mul-Fin {succ-ℕ k} x =
( eq-cong-ℕ (succ-ℕ k)
( mul-ℕ (nat-Fin (one-Fin {succ-ℕ k})) (nat-Fin x))
( nat-Fin x)
( cong-identification-ℕ
( succ-ℕ (succ-ℕ k))
( ( ap ( mul-ℕ' (nat-Fin x))
( nat-one-Fin {k})) ∙
( left-unit-law-mul-ℕ (nat-Fin x))))) ∙
( issec-nat-Fin (succ-ℕ k) x)
right-unit-law-mul-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (mul-Fin x one-Fin) x
right-unit-law-mul-Fin x =
( commutative-mul-Fin x one-Fin) ∙
( left-unit-law-mul-Fin x)
left-distributive-mul-add-Fin :
{k : ℕ} (x y z : Fin k) →
Id (mul-Fin x (add-Fin y z)) (add-Fin (mul-Fin x y) (mul-Fin x z))
left-distributive-mul-add-Fin {succ-ℕ k} x y z =
eq-cong-ℕ k
( mul-ℕ (nat-Fin x) (nat-Fin (add-Fin y z)))
( add-ℕ (nat-Fin (mul-Fin x y)) (nat-Fin (mul-Fin x z)))
( concatenate-cong-eq-cong-ℕ
{ k = succ-ℕ k}
{ x1 = mul-ℕ ( nat-Fin x) (nat-Fin (add-Fin y z))}
{ x2 = mul-ℕ ( nat-Fin x) (add-ℕ (nat-Fin y) (nat-Fin z))}
{ x3 = add-ℕ ( mul-ℕ (nat-Fin x) (nat-Fin y))
( mul-ℕ (nat-Fin x) (nat-Fin z))}
{ x4 = add-ℕ (nat-Fin (mul-Fin x y)) (nat-Fin (mul-Fin x z))}
( congruence-mul-ℕ
( succ-ℕ k)
{ x = nat-Fin x}
{ y = nat-Fin (add-Fin y z)}
{ x' = nat-Fin x}
{ y' = add-ℕ (nat-Fin y) (nat-Fin z)}
( reflexive-cong-ℕ (succ-ℕ k) (nat-Fin x))
( cong-add-Fin y z))
( left-distributive-mul-add-ℕ (nat-Fin x) (nat-Fin y) (nat-Fin z))
( symmetric-cong-ℕ (succ-ℕ k)
( add-ℕ ( nat-Fin (mul-Fin x y))
( nat-Fin (mul-Fin x z)))
( add-ℕ ( mul-ℕ (nat-Fin x) (nat-Fin y))
( mul-ℕ (nat-Fin x) (nat-Fin z)))
( congruence-add-ℕ
( succ-ℕ k)
{ x = nat-Fin (mul-Fin x y)}
{ y = nat-Fin (mul-Fin x z)}
{ x' = mul-ℕ (nat-Fin x) (nat-Fin y)}
{ y' = mul-ℕ (nat-Fin x) (nat-Fin z)}
( cong-mul-Fin x y)
( cong-mul-Fin x z))))
right-distributive-mul-add-Fin :
{k : ℕ} (x y z : Fin k) →
Id (mul-Fin (add-Fin x y) z) (add-Fin (mul-Fin x z) (mul-Fin y z))
right-distributive-mul-add-Fin {k} x y z =
( commutative-mul-Fin (add-Fin x y) z) ∙
( ( left-distributive-mul-add-Fin z x y) ∙
( ap-add-Fin (commutative-mul-Fin z x) (commutative-mul-Fin z y)))
{- Exercise 7.11 -}
{- Exercise 7.12 -}
-- We introduce the observational equality on finite sets.
Eq-Fin : (k : ℕ) → Fin k → Fin k → UU lzero
Eq-Fin (succ-ℕ k) (inl x) (inl y) = Eq-Fin k x y
Eq-Fin (succ-ℕ k) (inl x) (inr y) = empty
Eq-Fin (succ-ℕ k) (inr x) (inl y) = empty
Eq-Fin (succ-ℕ k) (inr x) (inr y) = unit
-- Exercise 7.12 (a)
refl-Eq-Fin : {k : ℕ} (x : Fin k) → Eq-Fin k x x
refl-Eq-Fin {succ-ℕ k} (inl x) = refl-Eq-Fin x
refl-Eq-Fin {succ-ℕ k} (inr x) = star
Eq-Fin-eq : {k : ℕ} {x y : Fin k} → Id x y → Eq-Fin k x y
Eq-Fin-eq {k} refl = refl-Eq-Fin {k} _
eq-Eq-Fin :
{k : ℕ} {x y : Fin k} → Eq-Fin k x y → Id x y
eq-Eq-Fin {succ-ℕ k} {inl x} {inl y} e = ap inl (eq-Eq-Fin e)
eq-Eq-Fin {succ-ℕ k} {inr star} {inr star} star = refl
-- Exercise 7.12 (b)
is-injective-inl-Fin :
{k : ℕ} {x y : Fin k} → Id (inl-Fin k x) (inl-Fin k y) → Id x y
is-injective-inl-Fin p = eq-Eq-Fin (Eq-Fin-eq p)
-- Exercise 7.12 (c)
neq-zero-succ-Fin :
{k : ℕ} {x : Fin k} → ¬ (Id (succ-Fin (inl-Fin k x)) zero-Fin)
neq-zero-succ-Fin {succ-ℕ k} {inl x} p =
neq-zero-succ-Fin (is-injective-inl-Fin p)
neq-zero-succ-Fin {succ-ℕ k} {inr star} p =
Eq-Fin-eq {succ-ℕ (succ-ℕ k)} {inr star} {zero-Fin} p
-- Exercise 7.12 (d)
is-injective-skip-zero-Fin :
{k : ℕ} {x y : Fin k} → Id (skip-zero-Fin x) (skip-zero-Fin y) → Id x y
is-injective-skip-zero-Fin {succ-ℕ k} {inl x} {inl y} p =
ap inl (is-injective-skip-zero-Fin (is-injective-inl-Fin p))
is-injective-skip-zero-Fin {succ-ℕ k} {inl x} {inr star} p =
ex-falso (Eq-Fin-eq p)
is-injective-skip-zero-Fin {succ-ℕ k} {inr star} {inl y} p =
ex-falso (Eq-Fin-eq p)
is-injective-skip-zero-Fin {succ-ℕ k} {inr star} {inr star} p = refl
is-injective-succ-Fin :
{k : ℕ} {x y : Fin k} → Id (succ-Fin x) (succ-Fin y) → Id x y
is-injective-succ-Fin {succ-ℕ k} {inl x} {inl y} p =
ap inl (is-injective-skip-zero-Fin {k} {x} {y} p)
is-injective-succ-Fin {succ-ℕ k} {inl x} {inr star} p =
ex-falso (neq-zero-succ-Fin {succ-ℕ k} {inl x} (ap inl p))
is-injective-succ-Fin {succ-ℕ k} {inr star} {inl y} p =
ex-falso (neq-zero-succ-Fin {succ-ℕ k} {inl y} (ap inl (inv p)))
is-injective-succ-Fin {succ-ℕ k} {inr star} {inr star} p = refl
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
{- Section 7.2 Decidability -}
{- Definition 7.2.1 -}
is-decidable : {l : Level} (A : UU l) → UU l
is-decidable A = coprod A (¬ A)
{- Example 7.2.2 -}
is-decidable-unit : is-decidable unit
is-decidable-unit = inl star
is-decidable-empty : is-decidable empty
is-decidable-empty = inr id
{- Definition 7.2.3 -}
{- We say that a type has decidable equality if we can decide whether
x = y holds for any x, y : A. -}
has-decidable-equality : {l : Level} (A : UU l) → UU l
has-decidable-equality A = (x y : A) → is-decidable (Id x y)
{- Lemma 7.2.5 -}
is-decidable-iff :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
(A → B) → (B → A) → is-decidable A → is-decidable B
is-decidable-iff f g =
functor-coprod f (functor-neg g)
{- Proposition 7.2.6 -}
{- The type ℕ is an example of a type with decidable equality. -}
is-decidable-Eq-ℕ :
(m n : ℕ) → is-decidable (Eq-ℕ m n)
is-decidable-Eq-ℕ zero-ℕ zero-ℕ = inl star
is-decidable-Eq-ℕ zero-ℕ (succ-ℕ n) = inr id
is-decidable-Eq-ℕ (succ-ℕ m) zero-ℕ = inr id
is-decidable-Eq-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-Eq-ℕ m n
has-decidable-equality-ℕ : has-decidable-equality ℕ
has-decidable-equality-ℕ x y =
is-decidable-iff (eq-Eq-ℕ x y) Eq-ℕ-eq (is-decidable-Eq-ℕ x y)
{- Proposition 7.2.9 -}
{- We show that Fin k has decidable equality, for each n : ℕ. -}
is-decidable-Eq-Fin :
(k : ℕ) (x y : Fin k) → is-decidable (Eq-Fin k x y)
is-decidable-Eq-Fin (succ-ℕ k) (inl x) (inl y) = is-decidable-Eq-Fin k x y
is-decidable-Eq-Fin (succ-ℕ k) (inl x) (inr y) = inr id
is-decidable-Eq-Fin (succ-ℕ k) (inr x) (inl y) = inr id
is-decidable-Eq-Fin (succ-ℕ k) (inr x) (inr y) = inl star
is-decidable-eq-Fin :
(k : ℕ) (x y : Fin k) → is-decidable (Id x y)
is-decidable-eq-Fin k x y =
functor-coprod eq-Eq-Fin (functor-neg Eq-Fin-eq) (is-decidable-Eq-Fin k x y)
{- Section 7.3 Definitions by case analysis -}
{- We define an alternative definition of the predecessor function with manual
with-abstraction. -}
cases-pred-Fin-2 :
{k : ℕ} (x : Fin (succ-ℕ k))
(d : is-decidable (Eq-Fin (succ-ℕ k) x zero-Fin)) → Fin (succ-ℕ k)
cases-pred-Fin-2 {zero-ℕ} (inr star) d = zero-Fin
cases-pred-Fin-2 {succ-ℕ k} (inl x) (inl e) = neg-one-Fin
cases-pred-Fin-2 {succ-ℕ k} (inl x) (inr f) =
inl (cases-pred-Fin-2 {k} x (inr f))
cases-pred-Fin-2 {succ-ℕ k} (inr star) (inr f) = inl neg-one-Fin
pred-Fin-2 : {k : ℕ} → Fin k → Fin k
pred-Fin-2 {succ-ℕ k} x =
cases-pred-Fin-2 {k} x (is-decidable-Eq-Fin (succ-ℕ k) x zero-Fin)
{- We give a solution to the exercise for the alternative definition of the
predecessor function, using with-abstraction. -}
pred-zero-Fin-2 :
{k : ℕ} → Id (pred-Fin-2 {succ-ℕ k} zero-Fin) neg-one-Fin
pred-zero-Fin-2 {k} with is-decidable-Eq-Fin (succ-ℕ k) zero-Fin zero-Fin
pred-zero-Fin-2 {zero-ℕ} | d = refl
pred-zero-Fin-2 {succ-ℕ k} | inl e = refl
pred-zero-Fin-2 {succ-ℕ k} | inr f =
ex-falso (f (refl-Eq-Fin {succ-ℕ k} zero-Fin))
cases-succ-pred-Fin-2 :
{k : ℕ} (x : Fin (succ-ℕ k))
(d : is-decidable (Eq-Fin (succ-ℕ k) x zero-Fin)) →
Id (succ-Fin (cases-pred-Fin-2 x d)) x
cases-succ-pred-Fin-2 {zero-ℕ} (inr star) d =
refl
cases-succ-pred-Fin-2 {succ-ℕ k} (inl x) (inl e) =
inv (eq-Eq-Fin e)
cases-succ-pred-Fin-2 {succ-ℕ zero-ℕ} (inl (inr x)) (inr f) =
ex-falso (f star)
cases-succ-pred-Fin-2 {succ-ℕ (succ-ℕ k)} (inl (inl x)) (inr f) =
ap inl (cases-succ-pred-Fin-2 (inl x) (inr f))
cases-succ-pred-Fin-2 {succ-ℕ (succ-ℕ k)} (inl (inr star)) (inr f) =
refl
cases-succ-pred-Fin-2 {succ-ℕ k} (inr star) (inr f) =
refl
succ-pred-Fin-2 :
{k : ℕ} (x : Fin k) → Id (succ-Fin (pred-Fin-2 x)) x
succ-pred-Fin-2 {succ-ℕ k} x =
cases-succ-pred-Fin-2 x (is-decidable-Eq-Fin (succ-ℕ k) x zero-Fin)
pred-inl-Fin-2 :
{k : ℕ} (x : Fin (succ-ℕ k)) (f : ¬ (Eq-Fin (succ-ℕ k) x zero-Fin)) →
Id (pred-Fin-2 (inl x)) (inl (pred-Fin-2 x))
pred-inl-Fin-2 {k} x f with is-decidable-Eq-Fin (succ-ℕ k) x zero-Fin
... | inl e = ex-falso (f e)
... | inr f' = refl
nEq-zero-succ-Fin :
{k : ℕ} (x : Fin (succ-ℕ k)) →
¬ (Eq-Fin (succ-ℕ (succ-ℕ k)) (succ-Fin (inl x)) zero-Fin)
nEq-zero-succ-Fin {succ-ℕ k} (inl (inl x)) e = nEq-zero-succ-Fin (inl x) e
nEq-zero-succ-Fin {succ-ℕ k} (inl (inr star)) ()
nEq-zero-succ-Fin {succ-ℕ k} (inr star) ()
pred-succ-Fin-2 :
{k : ℕ} (x : Fin (succ-ℕ k)) → Id (pred-Fin-2 (succ-Fin x)) x
pred-succ-Fin-2 {zero-ℕ} (inr star) = refl
pred-succ-Fin-2 {succ-ℕ zero-ℕ} (inl (inr star)) = refl
pred-succ-Fin-2 {succ-ℕ zero-ℕ} (inr star) = refl
pred-succ-Fin-2 {succ-ℕ (succ-ℕ k)} (inl (inl (inl x))) =
( pred-inl-Fin-2 (inl (succ-Fin (inl x))) (nEq-zero-succ-Fin (inl x))) ∙
( ( ap inl (pred-inl-Fin-2 (succ-Fin (inl x)) (nEq-zero-succ-Fin (inl x)))) ∙
( ap (inl ∘ inl) (pred-succ-Fin-2 (inl x))))
pred-succ-Fin-2 {succ-ℕ (succ-ℕ k)} (inl (inl (inr star))) = refl
pred-succ-Fin-2 {succ-ℕ (succ-ℕ k)} (inl (inr star)) = refl
pred-succ-Fin-2 {succ-ℕ (succ-ℕ k)} (inr star) = pred-zero-Fin-2
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
dist-ℤ : ℤ → ℤ → ℕ
dist-ℤ (inl x) (inl y) = dist-ℕ x y
dist-ℤ (inl x) (inr (inl star)) = succ-ℕ x
dist-ℤ (inl x) (inr (inr y)) = succ-ℕ (succ-ℕ (add-ℕ x y))
dist-ℤ (inr (inl star)) (inl y) = succ-ℕ y
dist-ℤ (inr (inr x)) (inl y) = succ-ℕ (succ-ℕ (add-ℕ x y))
dist-ℤ (inr (inl star)) (inr (inl star)) = zero-ℕ
dist-ℤ (inr (inl star)) (inr (inr y)) = succ-ℕ y
dist-ℤ (inr (inr x)) (inr (inl star)) = succ-ℕ x
dist-ℤ (inr (inr x)) (inr (inr y)) = dist-ℕ x y
dist-ℤ' : ℤ → ℤ → ℕ
dist-ℤ' x y = dist-ℤ y x
ap-dist-ℤ :
{x y x' y' : ℤ} → Id x x' → Id y y' → Id (dist-ℤ x y) (dist-ℤ x' y')
ap-dist-ℤ refl refl = refl
eq-dist-ℤ :
(x y : ℤ) → Id zero-ℕ (dist-ℤ x y) → Id x y
eq-dist-ℤ (inl x) (inl y) p = ap inl (eq-dist-ℕ x y p)
eq-dist-ℤ (inl x) (inr (inl star)) p = ex-falso (Peano-8 x p)
eq-dist-ℤ (inr (inl star)) (inl y) p = ex-falso (Peano-8 y p)
eq-dist-ℤ (inr (inl star)) (inr (inl star)) p = refl
eq-dist-ℤ (inr (inl star)) (inr (inr y)) p = ex-falso (Peano-8 y p)
eq-dist-ℤ (inr (inr x)) (inr (inl star)) p = ex-falso (Peano-8 x p)
eq-dist-ℤ (inr (inr x)) (inr (inr y)) p = ap (inr ∘ inr) (eq-dist-ℕ x y p)
dist-eq-ℤ' :
(x : ℤ) → Id zero-ℕ (dist-ℤ x x)
dist-eq-ℤ' (inl x) = dist-eq-ℕ' x
dist-eq-ℤ' (inr (inl star)) = refl
dist-eq-ℤ' (inr (inr x)) = dist-eq-ℕ' x
dist-eq-ℤ :
(x y : ℤ) → Id x y → Id zero-ℕ (dist-ℤ x y)
dist-eq-ℤ x .x refl = dist-eq-ℤ' x
{- The distance function on ℤ is symmetric. -}
symmetric-dist-ℤ :
(x y : ℤ) → Id (dist-ℤ x y) (dist-ℤ y x)
symmetric-dist-ℤ (inl x) (inl y) = symmetric-dist-ℕ x y
symmetric-dist-ℤ (inl x) (inr (inl star)) = refl
symmetric-dist-ℤ (inl x) (inr (inr y)) =
ap (succ-ℕ ∘ succ-ℕ) (commutative-add-ℕ x y)
symmetric-dist-ℤ (inr (inl star)) (inl y) = refl
symmetric-dist-ℤ (inr (inr x)) (inl y) =
ap (succ-ℕ ∘ succ-ℕ) (commutative-add-ℕ x y)
symmetric-dist-ℤ (inr (inl star)) (inr (inl star)) = refl
symmetric-dist-ℤ (inr (inl star)) (inr (inr y)) = refl
symmetric-dist-ℤ (inr (inr x)) (inr (inl star)) = refl
symmetric-dist-ℤ (inr (inr x)) (inr (inr y)) = symmetric-dist-ℕ x y
-- We compute the distance from zero --
left-zero-law-dist-ℤ :
(x : ℤ) → Id (dist-ℤ zero-ℤ x) (abs-ℤ x)
left-zero-law-dist-ℤ (inl x) = refl
left-zero-law-dist-ℤ (inr (inl star)) = refl
left-zero-law-dist-ℤ (inr (inr x)) = refl
right-zero-law-dist-ℤ :
(x : ℤ) → Id (dist-ℤ x zero-ℤ) (abs-ℤ x)
right-zero-law-dist-ℤ (inl x) = refl
right-zero-law-dist-ℤ (inr (inl star)) = refl
right-zero-law-dist-ℤ (inr (inr x)) = refl
-- We prove the triangle inequality --
{-
triangle-inequality-dist-ℤ :
(x y z : ℤ) → leq-ℕ (dist-ℤ x y) (add-ℕ (dist-ℤ x z) (dist-ℤ z y))
triangle-inequality-dist-ℤ (inl x) (inl y) (inl z) =
triangle-inequality-dist-ℕ x y z
triangle-inequality-dist-ℤ (inl x) (inl y) (inr (inl star)) =
triangle-inequality-dist-ℕ (succ-ℕ x) (succ-ℕ y) zero-ℕ
triangle-inequality-dist-ℤ (inl x) (inl y) (inr (inr z)) = {!!}
triangle-inequality-dist-ℤ (inl x) (inr y) (inl z) = {!!}
triangle-inequality-dist-ℤ (inl x) (inr y) (inr z) = {!!}
triangle-inequality-dist-ℤ (inr x) (inl y) (inl z) = {!!}
triangle-inequality-dist-ℤ (inr x) (inl y) (inr z) = {!!}
triangle-inequality-dist-ℤ (inr x) (inr y) (inl z) = {!!}
triangle-inequality-dist-ℤ (inr x) (inr y) (inr z) = {!!}
-}
{-
triangle-inequality-dist-ℕ :
(m n k : ℕ) → leq-ℕ (dist-ℕ m n) (add-ℕ (dist-ℕ m k) (dist-ℕ k n))
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = star
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = star
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ =
tr ( leq-ℕ (succ-ℕ n))
( inv (left-unit-law-add-ℕ (succ-ℕ n)))
( reflexive-leq-ℕ (succ-ℕ n))
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (left-zero-law-dist-ℕ n)))
( triangle-inequality-dist-ℕ zero-ℕ n k)
( ( ap (succ-ℕ ∘ (add-ℕ' (dist-ℕ k n))) (left-zero-law-dist-ℕ k)) ∙
( inv (left-successor-law-add-ℕ k (dist-ℕ k n))))
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = reflexive-leq-ℕ (succ-ℕ m)
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (right-zero-law-dist-ℕ m)))
( triangle-inequality-dist-ℕ m zero-ℕ k)
( ap (succ-ℕ ∘ (add-ℕ (dist-ℕ m k))) (right-zero-law-dist-ℕ k))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ =
concatenate-leq-eq-ℕ
( dist-ℕ m n)
( transitive-leq-ℕ
( dist-ℕ m n)
( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))
( succ-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))
( transitive-leq-ℕ
( dist-ℕ m n)
( add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))
( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))
( triangle-inequality-dist-ℕ m n zero-ℕ)
( succ-leq-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))
( succ-leq-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))))
( ( ap (succ-ℕ ∘ succ-ℕ)
( ap-add-ℕ (right-zero-law-dist-ℕ m) (left-zero-law-dist-ℕ n))) ∙
( inv (left-successor-law-add-ℕ m (succ-ℕ n))))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
triangle-inequality-dist-ℕ m n k
-- We show that dist-ℕ x y is a solution to a simple equation.
leq-dist-ℕ :
(x y : ℕ) → leq-ℕ x y → Id (add-ℕ x (dist-ℕ x y)) y
leq-dist-ℕ zero-ℕ zero-ℕ H = refl
leq-dist-ℕ zero-ℕ (succ-ℕ y) star = left-unit-law-add-ℕ (succ-ℕ y)
leq-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
( left-successor-law-add-ℕ x (dist-ℕ x y)) ∙
( ap succ-ℕ (leq-dist-ℕ x y H))
rewrite-left-add-dist-ℕ :
(x y z : ℕ) → Id (add-ℕ x y) z → Id x (dist-ℕ y z)
rewrite-left-add-dist-ℕ zero-ℕ zero-ℕ .zero-ℕ refl = refl
rewrite-left-add-dist-ℕ zero-ℕ (succ-ℕ y) .(succ-ℕ (add-ℕ zero-ℕ y)) refl =
( dist-eq-ℕ' y) ∙
( inv (ap (dist-ℕ (succ-ℕ y)) (left-unit-law-add-ℕ (succ-ℕ y))))
rewrite-left-add-dist-ℕ (succ-ℕ x) zero-ℕ .(succ-ℕ x) refl = refl
rewrite-left-add-dist-ℕ
(succ-ℕ x) (succ-ℕ y) .(succ-ℕ (add-ℕ (succ-ℕ x) y)) refl =
rewrite-left-add-dist-ℕ (succ-ℕ x) y (add-ℕ (succ-ℕ x) y) refl
rewrite-left-dist-add-ℕ :
(x y z : ℕ) → leq-ℕ y z → Id x (dist-ℕ y z) → Id (add-ℕ x y) z
rewrite-left-dist-add-ℕ .(dist-ℕ y z) y z H refl =
( commutative-add-ℕ (dist-ℕ y z) y) ∙
( leq-dist-ℕ y z H)
rewrite-right-add-dist-ℕ :
(x y z : ℕ) → Id (add-ℕ x y) z → Id y (dist-ℕ x z)
rewrite-right-add-dist-ℕ x y z p =
rewrite-left-add-dist-ℕ y x z (commutative-add-ℕ y x ∙ p)
rewrite-right-dist-add-ℕ :
(x y z : ℕ) → leq-ℕ x z → Id y (dist-ℕ x z) → Id (add-ℕ x y) z
rewrite-right-dist-add-ℕ x .(dist-ℕ x z) z H refl =
leq-dist-ℕ x z H
-- We show that dist-ℕ is translation invariant
translation-invariant-dist-ℕ :
(k m n : ℕ) → Id (dist-ℕ (add-ℕ k m) (add-ℕ k n)) (dist-ℕ m n)
translation-invariant-dist-ℕ zero-ℕ m n =
ap-dist-ℕ (left-unit-law-add-ℕ m) (left-unit-law-add-ℕ n)
translation-invariant-dist-ℕ (succ-ℕ k) m n =
( ap-dist-ℕ (left-successor-law-add-ℕ k m) (left-successor-law-add-ℕ k n)) ∙
( translation-invariant-dist-ℕ k m n)
-- We show that dist-ℕ is linear with respect to scalar multiplication
linear-dist-ℕ :
(m n k : ℕ) → Id (dist-ℕ (mul-ℕ k m) (mul-ℕ k n)) (mul-ℕ k (dist-ℕ m n))
linear-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = refl
linear-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = linear-dist-ℕ zero-ℕ zero-ℕ k
linear-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ = refl
linear-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
ap (dist-ℕ' (mul-ℕ (succ-ℕ k) (succ-ℕ n))) (right-zero-law-mul-ℕ (succ-ℕ k))
linear-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = refl
linear-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
ap (dist-ℕ (mul-ℕ (succ-ℕ k) (succ-ℕ m))) (right-zero-law-mul-ℕ (succ-ℕ k))
linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ = refl
linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
( ap-dist-ℕ
( right-successor-law-mul-ℕ (succ-ℕ k) m)
( right-successor-law-mul-ℕ (succ-ℕ k) n)) ∙
( ( translation-invariant-dist-ℕ
( succ-ℕ k)
( mul-ℕ (succ-ℕ k) m)
( mul-ℕ (succ-ℕ k) n)) ∙
( linear-dist-ℕ m n (succ-ℕ k)))
-}
| 33.215308
| 82
| 0.563562
|
39b2850b3005cf04adbab228a64c8570768bd3d7
| 15,011
|
agda
|
Agda
|
Lambda/Closure/Functional/Alternative.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | 1
|
2021-02-13T14:48:45.000Z
|
2021-02-13T14:48:45.000Z
|
Lambda/Closure/Functional/Alternative.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
Lambda/Closure/Functional/Alternative.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Alternative functional semantics for an untyped λ-calculus with
-- constants
------------------------------------------------------------------------
-- I noted that the compiler correctness proof in
-- Lambda.Closure.Functional might be easier if the semantics was
-- defined using continuation-passing style, so I decided to try this
-- out. The proof at the end of this module /is/ slightly shorter, but
-- the continuation-passing definition of the semantics is quite
-- awkward (due to the limitations imposed by Agda). Furthermore it
-- seemed to me as if the soundness proofs in
-- Lambda.Closure.Equivalence would be harder to prove using this
-- formulation of the semantics.
module Lambda.Closure.Functional.Alternative where
open import Category.Monad
open import Category.Monad.Partiality as Partiality
using (_⊥; never; Kind; OtherKind)
open import Codata.Musical.Notation
open import Data.List hiding (lookup)
open import Data.Maybe
import Data.Maybe.Categorical as Maybe
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Function
open import Level
open import Relation.Binary using (module Preorder)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open Partiality._⊥
open Partiality.Kind
private
open module E {A : Set} = Partiality.Equality (_≡_ {A = A})
open module R {A : Set} =
Partiality.Reasoning (P.isEquivalence {A = A})
open import Lambda.Syntax
open Closure Tm
open import Lambda.VirtualMachine
open Functional
private
module VM = Closure Code
------------------------------------------------------------------------
-- A monad with partiality and failure
PF : RawMonad {f = zero} (_⊥ ∘ Maybe)
PF = Maybe.monadT Partiality.monad
module PF where
open RawMonad PF public
fail : {A : Set} → Maybe A ⊥
fail = now nothing
open PF
------------------------------------------------------------------------
-- Semantics
module Workaround₁ where
-- This module provides a workaround for the limitations of
-- guardedness.
mutual
data Maybe_⊥P (A : Set) : Set where
⌈_⌉ : (x : Maybe A ⊥) → Maybe A ⊥P
later : (x : ∞ (Maybe A ⊥P)) → Maybe A ⊥P
⟦_⟧P : ∀ {n} (t : Tm n) (ρ : Env n) (k : Value → Maybe A ⊥W) →
Maybe A ⊥P
data Maybe_⊥W (A : Set) : Set where
⌈_⌉ : (x : Maybe A ⊥) → Maybe A ⊥W
later : (x : Maybe A ⊥P) → Maybe A ⊥W
mutual
-- The semantics, in slightly scrambled form.
infix 5 _∙W_
⟦_⟧W : ∀ {A n} → Tm n → Env n → (Value → Maybe A ⊥W) → Maybe A ⊥W
⟦ con i ⟧W ρ k = k (con i)
⟦ var x ⟧W ρ k = k (lookup ρ x)
⟦ ƛ t ⟧W ρ k = k (ƛ t ρ)
⟦ t₁ · t₂ ⟧W ρ k = ⟦ t₁ ⟧W ρ (λ v₁ →
⟦ t₂ ⟧W ρ (λ v₂ →
(v₁ ∙W v₂) k))
_∙W_ : ∀ {A} → Value → Value → (Value → Maybe A ⊥W) → Maybe A ⊥W
(con i ∙W v₂) k = ⌈ fail ⌉
(ƛ t₁ ρ ∙W v₂) k = later (⟦ t₁ ⟧P (v₂ ∷ ρ) k)
-- Interpretation of the definitions above.
whnf : ∀ {A} → Maybe A ⊥P → Maybe A ⊥W
whnf ⌈ x ⌉ = ⌈ x ⌉
whnf (later x) = later (♭ x)
whnf (⟦ t ⟧P ρ k) = ⟦ t ⟧W ρ k
mutual
⟪_⟫W : ∀ {A} → Maybe A ⊥W → Maybe A ⊥
⟪ ⌈ x ⌉ ⟫W = x
⟪ later x ⟫W = later (♯ ⟪ x ⟫P)
⟪_⟫P : ∀ {A} → Maybe A ⊥P → Maybe A ⊥
⟪ x ⟫P = ⟪ whnf x ⟫W
-- The actual semantics. Note that this definition gives us
-- determinism "for free".
infix 5 _∙_
⟦_⟧ : ∀ {A n} → Tm n → Env n → (Value → Maybe A ⊥) → Maybe A ⊥
⟦ t ⟧ ρ k = ⟪ ⟦ t ⟧P ρ (λ v → ⌈ k v ⌉) ⟫P
where open Workaround₁
_∙_ : ∀ {A} → Value → Value → (Value → Maybe A ⊥) → Maybe A ⊥
(v₁ ∙ v₂) k = ⟪ (v₁ ∙W v₂) (λ v → ⌈ k v ⌉) ⟫W
where open Workaround₁
-- ⟦_⟧ and _∙_ preserve equality of their continuations.
module Workaround₂ {k : Kind} where
open Workaround₁
mutual
infix 4 _≈P_ _≈W_
data _≈P_ {A : Set} : Maybe A ⊥ → Maybe A ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel k x y) → x ≈P y
later : ∀ {x y} (x≈y : ∞ (♭ x ≈P ♭ y)) → later x ≈P later y
⟦_⟧W-congP : ∀ {n} t (ρ : Env n) {k₁ k₂ : Value → Maybe A ⊥W}
(k₁≈k₂ : ∀ v → ⟪ k₁ v ⟫W ≈W ⟪ k₂ v ⟫W) →
⟪ ⟦ t ⟧W ρ k₁ ⟫W ≈P ⟪ ⟦ t ⟧W ρ k₂ ⟫W
data _≈W_ {A : Set} : Maybe A ⊥ → Maybe A ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel k x y) → x ≈W y
later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y
mutual
⟦_⟧W-congW : ∀ {A n} t (ρ : Env n) {k₁ k₂ : Value → Maybe A ⊥W} →
(∀ v → ⟪ k₁ v ⟫W ≈W ⟪ k₂ v ⟫W) →
⟪ ⟦ t ⟧W ρ k₁ ⟫W ≈W ⟪ ⟦ t ⟧W ρ k₂ ⟫W
⟦ con i ⟧W-congW ρ k₁≈k₂ = k₁≈k₂ (con i)
⟦ var x ⟧W-congW ρ k₁≈k₂ = k₁≈k₂ (lookup ρ x)
⟦ ƛ t ⟧W-congW ρ k₁≈k₂ = k₁≈k₂ (ƛ t ρ)
⟦ t₁ · t₂ ⟧W-congW ρ k₁≈k₂ = ⟦ t₁ ⟧W-congW ρ (λ v₁ →
⟦ t₂ ⟧W-congW ρ (λ v₂ →
(v₁ ∙W v₂ -congW) k₁≈k₂))
_∙W_-congW : ∀ {A} v₁ v₂ {k₁ k₂ : Value → Maybe A ⊥W} →
(∀ v → ⟪ k₁ v ⟫W ≈W ⟪ k₂ v ⟫W) →
⟪ (v₁ ∙W v₂) k₁ ⟫W ≈W ⟪ (v₁ ∙W v₂) k₂ ⟫W
(con i ∙W v₂ -congW) k₁≈k₂ = ⌈ fail ∎ ⌉
(ƛ t₁ ρ ∙W v₂ -congW) k₁≈k₂ = later (⟦ t₁ ⟧W-congP (v₂ ∷ ρ) k₁≈k₂)
whnf≈ : ∀ {A} {x y : Maybe A ⊥} → x ≈P y → x ≈W y
whnf≈ ⌈ x≈y ⌉ = ⌈ x≈y ⌉
whnf≈ (later x≈y) = later (♭ x≈y)
whnf≈ (⟦ t ⟧W-congP ρ k₁≈k₂) = ⟦ t ⟧W-congW ρ k₁≈k₂
mutual
soundW : ∀ {A} {x y : Maybe A ⊥} → x ≈W y → Rel k x y
soundW ⌈ x≈y ⌉ = x≈y
soundW (later x≈y) = later (♯ soundP x≈y)
soundP : ∀ {A} {x y : Maybe A ⊥} → x ≈P y → Rel k x y
soundP x≈y = soundW (whnf≈ x≈y)
⟦_⟧-cong : ∀ {k A n} t (ρ : Env n) {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → Rel k (k₁ v) (k₂ v)) →
Rel k (⟦ t ⟧ ρ k₁) (⟦ t ⟧ ρ k₂)
⟦ t ⟧-cong ρ k₁≈k₂ = soundW (⟦ t ⟧W-congW ρ (λ v → ⌈ k₁≈k₂ v ⌉))
where open Workaround₂
_∙_-cong : ∀ {k A} v₁ v₂ {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → Rel k (k₁ v) (k₂ v)) →
Rel k ((v₁ ∙ v₂) k₁) ((v₁ ∙ v₂) k₂)
(v₁ ∙ v₂ -cong) k₁≈k₂ = soundW ((v₁ ∙W v₂ -congW) (λ v → ⌈ k₁≈k₂ v ⌉))
where open Workaround₂
-- ⟦_⟧ and _∙_ satisfy their intended defining equations.
sem-con : ∀ {A n} i {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ con i ⟧ ρ k ≅ k (con i)
sem-con i {k = k} = k (con i) ∎
sem-var : ∀ {A n} x {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ var x ⟧ ρ k ≅ k (lookup ρ x)
sem-var x {ρ} {k} = k (lookup ρ x) ∎
sem-ƛ : ∀ {A n} t {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ ƛ t ⟧ ρ k ≅ k (ƛ t ρ)
sem-ƛ t {ρ} {k} = k (ƛ t ρ) ∎
sem-· : ∀ {A n} t₁ t₂ {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ t₁ · t₂ ⟧ ρ k ≅ (⟦ t₁ ⟧ ρ λ v₁ → ⟦ t₂ ⟧ ρ λ v₂ → (v₁ ∙ v₂) k)
sem-· t₁ t₂ {ρ} {k} = soundW $
⟦ t₁ ⟧W-congW ρ λ v₁ →
⟦ t₂ ⟧W-congW ρ λ v₂ →
⌈ (v₁ ∙ v₂) k ∎ ⌉
where open Workaround₂
app-con : ∀ {A} i v₂ {k : Value → Maybe A ⊥} →
(con i ∙ v₂) k ≅ fail
app-con i v₂ = fail ∎
app-ƛ : ∀ {A n} t₁ (ρ : Env n) v₂ {k : Value → Maybe A ⊥} →
(ƛ t₁ ρ ∙ v₂) k ≅ later (♯ ⟦ t₁ ⟧ (v₂ ∷ ρ) k)
app-ƛ t₁ ρ v₂ {k} = later (♯ (⟦ t₁ ⟧ (v₂ ∷ ρ) k ∎))
-- ⟦_⟧ and _∙_ are the unique solutions to the system of equations
-- which is intended to define them. I have stated this result using
-- strong equality, which is (more or less) the kind of equality you
-- get from a definition. I tried using weak equality instead, but
-- this turned out to make the proof tricky (due to the lack of
-- transitivity).
module Unique
{A : Set}
(⟪_⟫ : ∀ {n} t (ρ : Env n) (k : Value → Maybe A ⊥) → Maybe A ⊥)
(_○_ : Value → Value → (Value → Maybe A ⊥) → Maybe A ⊥)
(⟪con⟫ : ∀ {n} i {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ con i ⟫ ρ k ≅ k (con i))
(⟪var⟫ : ∀ {n} x {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ var x ⟫ ρ k ≅ k (lookup ρ x))
(⟪ƛ⟫ : ∀ {n} t {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ ƛ t ⟫ ρ k ≅ k (ƛ t ρ))
(⟪·⟫ : ∀ {n} t₁ t₂ {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ t₁ · t₂ ⟫ ρ k ≅ (⟪ t₁ ⟫ ρ λ v₁ → ⟪ t₂ ⟫ ρ λ v₂ → (v₁ ○ v₂) k))
(con○ : ∀ i v₂ {k : Value → Maybe A ⊥} →
(con i ○ v₂) k ≅ fail)
(ƛ○ : ∀ {n} t₁ (ρ : Env n) v₂ {k : Value → Maybe A ⊥} →
(ƛ t₁ ρ ○ v₂) k ≅ later (♯ ⟪ t₁ ⟫ (v₂ ∷ ρ) k))
where
infix 4 _≅P_ _≅W_
infixr 2 _≅⟨_⟩P_ _≅⟨_⟩W_ _≅⟪_⟫P_ _≅⟪_⟫W_
mutual
data _≅P_ : Maybe A ⊥ → Maybe A ⊥ → Set where
_≅⟨_⟩P_ : ∀ x {y z} (x≅y : x ≅ y) (y≅z : y ≅P z) → x ≅P z
_≅⟪_⟫P_ : ∀ x {y z} (x≅y : x ≅P y) (y≅z : y ≅ z) → x ≅P z
semP : ∀ {n} t {ρ : Env n} {k₁ k₂ : Value → Maybe A ⊥} →
(k₁≅k₂ : ∀ v → k₁ v ≅W k₂ v) →
⟪ t ⟫ ρ k₁ ≅P ⟦ t ⟧ ρ k₂
data _≅W_ : Maybe A ⊥ → Maybe A ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≅y : x ≅ y) → x ≅W y
later : ∀ {x y} (x≅y : ♭ x ≅P ♭ y) → later x ≅W later y
_≅⟨_⟩W_ : ∀ x {y z} → x ≅ y → y ≅W z → x ≅W z
_ ≅⟨ x≅y ⟩W ⌈ y≅z ⌉ = ⌈ _ ≅⟨ x≅y ⟩ y≅z ⌉
._ ≅⟨ later x≅y ⟩W later y≅z = later (_ ≅⟨ ♭ x≅y ⟩P y≅z)
_≅⟪_⟫W_ : ∀ x {y z} → x ≅W y → y ≅ z → x ≅W z
_ ≅⟪ ⌈ x≅y ⌉ ⟫W y≅z = ⌈ _ ≅⟨ x≅y ⟩ y≅z ⌉
._ ≅⟪ later x≅y ⟫W later y≅z = later (_ ≅⟪ x≅y ⟫P ♭ y≅z)
mutual
semW : ∀ {n} t {ρ : Env n} {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → k₁ v ≅W k₂ v) → ⟪ t ⟫ ρ k₁ ≅W ⟦ t ⟧ ρ k₂
semW (con i) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ con i ⟫ ρ k₁ ≅⟨ ⟪con⟫ i ⟩W
k₁ (con i) ≅⟪ k₁≅k₂ _ ⟫W
k₂ (con i) ∎
semW (var x) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ var x ⟫ ρ k₁ ≅⟨ ⟪var⟫ x ⟩W
k₁ (lookup ρ x) ≅⟪ k₁≅k₂ _ ⟫W
k₂ (lookup ρ x) ∎
semW (ƛ t) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ ƛ t ⟫ ρ k₁ ≅⟨ ⟪ƛ⟫ t ⟩W
k₁ (ƛ t ρ) ≅⟪ k₁≅k₂ _ ⟫W
k₂ (ƛ t ρ) ∎
semW (t₁ · t₂) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ t₁ · t₂ ⟫ ρ k₁ ≅⟨ ⟪·⟫ t₁ t₂ ⟩W
(⟪ t₁ ⟫ ρ λ v₁ → ⟪ t₂ ⟫ ρ λ v₂ → (v₁ ○ v₂) k₁) ≅⟪ semW t₁ (λ v₁ → semW t₂ (λ v₂ → appW v₁ v₂ k₁≅k₂)) ⟫W
(⟦ t₁ ⟧ ρ λ v₁ → ⟦ t₂ ⟧ ρ λ v₂ → (v₁ ∙ v₂) k₂) ≅⟨ sym $ sem-· t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ k₂ ∎
appW : ∀ v₁ v₂ {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → k₁ v ≅W k₂ v) → (v₁ ○ v₂) k₁ ≅W (v₁ ∙ v₂) k₂
appW (con i) v₂ {k₁} {k₂} k₁≅k₂ =
⌈ (con i ○ v₂) k₁ ≅⟨ con○ i v₂ ⟩
fail ∎ ⌉
appW (ƛ t₁ ρ) v₂ {k₁} {k₂} k₁≅k₂ =
(ƛ t₁ ρ ○ v₂) k₁ ≅⟨ ƛ○ t₁ ρ v₂ ⟩W
later _ ≅⟪ later (semP t₁ k₁≅k₂) ⟫W
(ƛ t₁ ρ ∙ v₂) k₂ ∎
whnf : ∀ {x y} → x ≅P y → x ≅W y
whnf (x ≅⟨ x≅y ⟩P y≅z) = x ≅⟨ x≅y ⟩W whnf y≅z
whnf (x ≅⟪ x≅y ⟫P y≅z) = x ≅⟪ whnf x≅y ⟫W y≅z
whnf (semP t k₁≅k₂) = semW t k₁≅k₂
mutual
soundW : ∀ {x y} → x ≅W y → x ≅ y
soundW ⌈ x≅y ⌉ = x≅y
soundW (later x≅y) = later (♯ soundP x≅y)
soundP : ∀ {x y} → x ≅P y → x ≅ y
soundP x≅y = soundW (whnf x≅y)
sem : ∀ {n} t {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ t ⟫ ρ k ≅ ⟦ t ⟧ ρ k
sem t {k = k} = soundW (semW t (λ v → ⌈ k v ∎ ⌉))
dot : ∀ v₁ v₂ {k : Value → Maybe A ⊥} →
(v₁ ○ v₂) k ≅ (v₁ ∙ v₂) k
dot v₁ v₂ {k} = soundW (appW v₁ v₂ (λ v → ⌈ k v ∎ ⌉))
------------------------------------------------------------------------
-- Example
Ω-loops : ⟦ Ω ⟧ [] return ≈ never
Ω-loops = later (♯ Ω-loops)
------------------------------------------------------------------------
-- Compiler correctness
module Correctness {k : OtherKind} where
infix 4 _≈P_ _≈W_
infixr 2 _≡⟨_⟩W_ _≈⟨_⟩P_ _≈⟨_⟩W_
mutual
data _≈P_ : Maybe VM.Value ⊥ → Maybe VM.Value ⊥ → Set where
_≈⟨_⟩P_ : ∀ x {y z} (x≈y : x ≈P y) (y≅z : y ≅ z) → x ≈P z
correct :
∀ {n} t {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(hyp : ∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩
≈W k v) →
exec ⟨ comp t c , s , comp-env ρ ⟩ ≈P ⟦ t ⟧ ρ k
data _≈W_ : Maybe VM.Value ⊥ → Maybe VM.Value ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel (other k) x y) → x ≈W y
later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y
laterˡ : ∀ {x y} (x≈y : ♭ x ≈W y) → later x ≈W y
_≡⟨_⟩W_ : ∀ x {y z} → x ≡ y → y ≈W z → x ≈W z
_ ≡⟨ P.refl ⟩W y≈z = y≈z
_≈⟨_⟩W_ : ∀ x {y z} → x ≈W y → y ≅ z → x ≈W z
._ ≈⟨ later x≈y ⟩W later y≅z = later (_ ≈⟨ x≈y ⟩P ♭ y≅z)
._ ≈⟨ laterˡ x≈y ⟩W y≅z = laterˡ (_ ≈⟨ x≈y ⟩W y≅z)
_ ≈⟨ ⌈ x≈y ⌉ ⟩W y≅z = ⌈ trans x≈y (Partiality.≅⇒ y≅z) ⌉
where trans = Preorder.trans (Partiality.preorder P.isPreorder _)
mutual
correctW :
∀ {n} t {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈W k v) →
exec ⟨ comp t c , s , comp-env ρ ⟩ ≈W ⟦ t ⟧ ρ k
correctW (con i) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (Lambda.Syntax.Closure.con i) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (con i) ⟩W
k (con i) ∎)
correctW (var x) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → exec ⟨ c , val v ∷ s , comp-env ρ ⟩) $ lookup-hom x ρ ⟩W
exec ⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (lookup ρ x) ⟩W
k (lookup ρ x) ∎)
correctW (ƛ t) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (ƛ t ρ) ⟩W
k (ƛ t ρ) ∎)
correctW (t₁ · t₂) {ρ} {c} {s} {k} hyp =
exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≈⟨ correctW t₁ (λ v₁ → correctW t₂ (λ v₂ → ∙-correctW v₁ v₂ hyp)) ⟩W
(⟦ t₁ ⟧ ρ λ v₁ → ⟦ t₂ ⟧ ρ λ v₂ → (v₁ ∙ v₂) k) ≅⟨ sym $ sem-· t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ k ∎
∙-correctW :
∀ {n} v₁ v₂ {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈W k v) →
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , comp-env ρ ⟩ ≈W
(v₁ ∙ v₂) k
∙-correctW (con i) v₂ _ = ⌈ fail ∎ ⌉
∙-correctW (ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp =
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ≈⟨ later (
exec ⟨ comp t₁ [ ret ] , ret c (comp-env ρ) ∷ s , comp-env (v₂ ∷ ρ₁) ⟩ ≈⟨ correct t₁ (λ v → laterˡ (hyp v)) ⟩P
(⟦ t₁ ⟧ (v₂ ∷ ρ₁) k) ∎) ⟩W
(ƛ t₁ ρ₁ ∙ v₂) k ∎
whnf : ∀ {x y} → x ≈P y → x ≈W y
whnf (x ≈⟨ x≈y ⟩P y≅z) = x ≈⟨ whnf x≈y ⟩W y≅z
whnf (correct t hyp) = correctW t hyp
mutual
soundW : ∀ {x y} → x ≈W y → Rel (other k) x y
soundW ⌈ x≈y ⌉ = x≈y
soundW (later x≈y) = later (♯ soundP x≈y)
soundW (laterˡ x≈y) = laterˡ (soundW x≈y)
soundP : ∀ {x y} → x ≈P y → Rel (other k) x y
soundP x≈y = soundW (whnf x≈y)
correct : ∀ t →
exec ⟨ comp t [] , [] , [] ⟩ ≈
⟦ t ⟧ [] (λ v → return (comp-val v))
correct t =
soundP $ Correctness.correct t (λ v → ⌈ return (comp-val v) ∎ ⌉)
where open Correctness
| 35.825776
| 138
| 0.44594
|
50976c29b6da15636c5b9aa2f84f0f7f64e6a4d1
| 713
|
agda
|
Agda
|
Logic/IntroInstances.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Logic/IntroInstances.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Logic/IntroInstances.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Logic.IntroInstances where
import Data.Tuple as Tuple
import Lvl
open import Logic.Predicate
open import Logic.Propositional
open import Type
private variable ℓ : Lvl.Level
private variable A B Obj : Type{ℓ}
private variable P : Obj → Type{ℓ}
private variable x : Obj
instance
[∧]-intro-instance : ⦃ _ : A ⦄ → ⦃ _ : B ⦄ → (A ∧ B)
[∧]-intro-instance ⦃ a ⦄ ⦃ b ⦄ = [∧]-intro a b
instance
[∨]-introₗ-instance : ⦃ _ : A ⦄ → (A ∨ B)
[∨]-introₗ-instance ⦃ a ⦄ = [∨]-introₗ a
instance
[∨]-introᵣ-instance : ⦃ _ : B ⦄ → (A ∨ B)
[∨]-introᵣ-instance ⦃ b ⦄ = [∨]-introᵣ b
instance
[∃]-intro-instance : ⦃ _ : P(x) ⦄ → ∃(P)
[∃]-intro-instance {x = x} ⦃ proof ⦄ = [∃]-intro (x) ⦃ proof ⦄
| 24.586207
| 64
| 0.58906
|
dcf69e784c577b62f9dd1d735761ad05dfe987a9
| 27,502
|
agda
|
Agda
|
Agda/05-identity-types.agda
|
jonsterling/HoTT-Intro
|
7457d00fbd2c0a993b01cd2b3dbc4f259213845e
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/05-identity-types.agda
|
jonsterling/HoTT-Intro
|
7457d00fbd2c0a993b01cd2b3dbc4f259213845e
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/05-identity-types.agda
|
jonsterling/HoTT-Intro
|
7457d00fbd2c0a993b01cd2b3dbc4f259213845e
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split #-}
module 05-identity-types where
import 04-inductive-types
open 04-inductive-types public
-- Section 5.1
-- Definition 5.1.1
{- We introduce the identity type. -}
data Id {i : Level} {A : UU i} (x : A) : A → UU i where
refl : Id x x
{- In the following definition we give a construction of path induction.
However, in the development of this library we will mostly use Agda's
built-in methods to give constructions by path induction. -}
ind-Id :
{i j : Level} {A : UU i} (x : A) (B : (y : A) (p : Id x y) → UU j) →
(B x refl) → (y : A) (p : Id x y) → B y p
ind-Id x B b y refl = b
-- Section 5.2 The groupoid structure of types
-- Definition 5.2.1
_∙_ :
{i : Level} {A : UU i} {x y z : A} → Id x y → Id y z → Id x z
refl ∙ q = q
concat :
{i : Level} {A : UU i} {x y : A} → Id x y → (z : A) → Id y z → Id x z
concat p z q = p ∙ q
-- Definition 5.2.2
inv :
{i : Level} {A : UU i} {x y : A} → Id x y → Id y x
inv refl = refl
-- Definition 5.2.3
assoc :
{i : Level} {A : UU i} {x y z w : A} (p : Id x y) (q : Id y z)
(r : Id z w) → Id ((p ∙ q) ∙ r) (p ∙ (q ∙ r))
assoc refl q r = refl
-- Definition 5.2.4
left-unit :
{i : Level} {A : UU i} {x y : A} {p : Id x y} → Id (refl ∙ p) p
left-unit = refl
right-unit :
{i : Level} {A : UU i} {x y : A} {p : Id x y} → Id (p ∙ refl) p
right-unit {p = refl} = refl
-- Definition 5.2.5
left-inv :
{i : Level} {A : UU i} {x y : A} (p : Id x y) →
Id ((inv p) ∙ p) refl
left-inv refl = refl
right-inv :
{i : Level} {A : UU i} {x y : A} (p : Id x y) →
Id (p ∙ (inv p)) refl
right-inv refl = refl
-- Section 5.3 The action on paths of functions
-- Definition 5.3.1
ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y : A} (p : Id x y) →
Id (f x) (f y)
ap f refl = refl
ap-id :
{i : Level} {A : UU i} {x y : A} (p : Id x y) → Id (ap id p) p
ap-id refl = refl
ap-comp :
{i j k : Level} {A : UU i} {B : UU j} {C : UU k} (g : B → C)
(f : A → B) {x y : A} (p : Id x y) → Id (ap (g ∘ f) p) (ap g (ap f p))
ap-comp g f refl = refl
-- Definition 5.3.2
ap-refl :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x : A) →
Id (ap f (refl {_} {_} {x})) refl
ap-refl f x = refl
ap-concat :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y z : A}
(p : Id x y) (q : Id y z) → Id (ap f (p ∙ q)) ((ap f p) ∙ (ap f q))
ap-concat f refl q = refl
ap-inv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y : A}
(p : Id x y) → Id (ap f (inv p)) (inv (ap f p))
ap-inv f refl = refl
-- Section 5.4 Transport
-- Definition 5.4.1
tr :
{i j : Level} {A : UU i} (B : A → UU j) {x y : A} (p : Id x y) → B x → B y
tr B refl b = b
-- Definition 5.4.2
apd :
{i j : Level} {A : UU i} {B : A → UU j} (f : (x : A) → B x) {x y : A}
(p : Id x y) → Id (tr B p (f x)) (f y)
apd f refl = refl
path-over :
{i j : Level} {A : UU i} (B : A → UU j) {x x' : A} (p : Id x x') →
B x → B x' → UU j
path-over B p y y' = Id (tr B p y) y'
refl-path-over :
{i j : Level} {A : UU i} (B : A → UU j) (x : A) (y : B x) →
path-over B refl y y
refl-path-over B x y = refl
-- Exercises
-- Exercise 5.1
-- Exercise 5.2
distributive-inv-concat :
{i : Level} {A : UU i} {x y : A} (p : Id x y) {z : A}
(q : Id y z) → Id (inv (p ∙ q)) ((inv q) ∙ (inv p))
distributive-inv-concat refl refl = refl
-- Exercise 5.3
inv-con :
{i : Level} {A : UU i} {x y : A} (p : Id x y) {z : A} (q : Id y z)
(r : Id x z) → (Id (p ∙ q) r) → Id q ((inv p) ∙ r)
inv-con refl q r = id
con-inv :
{i : Level} {A : UU i} {x y : A} (p : Id x y) {z : A} (q : Id y z)
(r : Id x z) → (Id (p ∙ q) r) → Id p (r ∙ (inv q))
con-inv p refl r =
( λ α → α ∙ (inv right-unit)) ∘ (concat (inv right-unit) r)
-- Exercise 5.4
lift :
{i j : Level} {A : UU i} {B : A → UU j} {x y : A} (p : Id x y)
(b : B x) → Id (pair x b) (pair y (tr B p b))
lift refl b = refl
-- Exercise 5.5
-- Exercise 5.5(a)
abstract
right-unit-law-add-ℕ :
(x : ℕ) → Id (add-ℕ x zero-ℕ) x
right-unit-law-add-ℕ x = refl
left-unit-law-add-ℕ :
(x : ℕ) → Id (add-ℕ zero-ℕ x) x
left-unit-law-add-ℕ zero-ℕ = refl
left-unit-law-add-ℕ (succ-ℕ x) = ap succ-ℕ (left-unit-law-add-ℕ x)
left-successor-law-add-ℕ :
(x y : ℕ) → Id (add-ℕ (succ-ℕ x) y) (succ-ℕ (add-ℕ x y))
left-successor-law-add-ℕ x zero-ℕ = refl
left-successor-law-add-ℕ x (succ-ℕ y) =
ap succ-ℕ (left-successor-law-add-ℕ x y)
right-successor-law-add-ℕ :
(x y : ℕ) → Id (add-ℕ x (succ-ℕ y)) (succ-ℕ (add-ℕ x y))
right-successor-law-add-ℕ x y = refl
-- Exercise 5.5(b)
abstract
associative-add-ℕ :
(x y z : ℕ) → Id (add-ℕ (add-ℕ x y) z) (add-ℕ x (add-ℕ y z))
associative-add-ℕ x y zero-ℕ = refl
associative-add-ℕ x y (succ-ℕ z) = ap succ-ℕ (associative-add-ℕ x y z)
abstract
commutative-add-ℕ : (x y : ℕ) → Id (add-ℕ x y) (add-ℕ y x)
commutative-add-ℕ zero-ℕ y = left-unit-law-add-ℕ y
commutative-add-ℕ (succ-ℕ x) y =
(left-successor-law-add-ℕ x y) ∙ (ap succ-ℕ (commutative-add-ℕ x y))
-- Exercise 5.5(c)
abstract
left-zero-law-mul-ℕ :
(x : ℕ) → Id (mul-ℕ zero-ℕ x) zero-ℕ
left-zero-law-mul-ℕ x = refl
right-zero-law-mul-ℕ :
(x : ℕ) → Id (mul-ℕ x zero-ℕ) zero-ℕ
right-zero-law-mul-ℕ zero-ℕ = refl
right-zero-law-mul-ℕ (succ-ℕ x) =
( right-unit-law-add-ℕ (mul-ℕ x zero-ℕ)) ∙ (right-zero-law-mul-ℕ x)
abstract
right-unit-law-mul-ℕ :
(x : ℕ) → Id (mul-ℕ x one-ℕ) x
right-unit-law-mul-ℕ zero-ℕ = refl
right-unit-law-mul-ℕ (succ-ℕ x) = ap succ-ℕ (right-unit-law-mul-ℕ x)
left-unit-law-mul-ℕ :
(x : ℕ) → Id (mul-ℕ one-ℕ x) x
left-unit-law-mul-ℕ zero-ℕ = refl
left-unit-law-mul-ℕ (succ-ℕ x) = ap succ-ℕ (left-unit-law-mul-ℕ x)
abstract
left-successor-law-mul-ℕ :
(x y : ℕ) → Id (mul-ℕ (succ-ℕ x) y) (add-ℕ (mul-ℕ x y) y)
left-successor-law-mul-ℕ x y = refl
right-successor-law-mul-ℕ :
(x y : ℕ) → Id (mul-ℕ x (succ-ℕ y)) (add-ℕ x (mul-ℕ x y))
right-successor-law-mul-ℕ zero-ℕ y = refl
right-successor-law-mul-ℕ (succ-ℕ x) y =
( ( ap (λ t → succ-ℕ (add-ℕ t y)) (right-successor-law-mul-ℕ x y)) ∙
( ap succ-ℕ (associative-add-ℕ x (mul-ℕ x y) y))) ∙
( inv (left-successor-law-add-ℕ x (add-ℕ (mul-ℕ x y) y)))
-- Exercise 5.5(d)
abstract
commutative-mul-ℕ :
(x y : ℕ) → Id (mul-ℕ x y) (mul-ℕ y x)
commutative-mul-ℕ zero-ℕ y = inv (right-zero-law-mul-ℕ y)
commutative-mul-ℕ (succ-ℕ x) y =
( commutative-add-ℕ (mul-ℕ x y) y) ∙
( ( ap (add-ℕ y) (commutative-mul-ℕ x y)) ∙
( inv (right-successor-law-mul-ℕ y x)))
-- Exercise 5.5(e)
abstract
left-distributive-mul-add-ℕ :
(x y z : ℕ) → Id (mul-ℕ x (add-ℕ y z)) (add-ℕ (mul-ℕ x y) (mul-ℕ x z))
left-distributive-mul-add-ℕ zero-ℕ y z = refl
left-distributive-mul-add-ℕ (succ-ℕ x) y z =
( left-successor-law-mul-ℕ x (add-ℕ y z)) ∙
( ( ap (λ t → add-ℕ t (add-ℕ y z)) (left-distributive-mul-add-ℕ x y z)) ∙
( ( associative-add-ℕ (mul-ℕ x y) (mul-ℕ x z) (add-ℕ y z)) ∙
( ( ap ( add-ℕ (mul-ℕ x y))
( ( inv (associative-add-ℕ (mul-ℕ x z) y z)) ∙
( ( ap (λ t → add-ℕ t z) (commutative-add-ℕ (mul-ℕ x z) y)) ∙
( associative-add-ℕ y (mul-ℕ x z) z)))) ∙
( inv (associative-add-ℕ (mul-ℕ x y) y (add-ℕ (mul-ℕ x z) z))))))
abstract
right-distributive-mul-add-ℕ :
(x y z : ℕ) → Id (mul-ℕ (add-ℕ x y) z) (add-ℕ (mul-ℕ x z) (mul-ℕ y z))
right-distributive-mul-add-ℕ x y z =
( commutative-mul-ℕ (add-ℕ x y) z) ∙
( ( left-distributive-mul-add-ℕ z x y) ∙
( ( ap (λ t → add-ℕ t (mul-ℕ z y)) (commutative-mul-ℕ z x)) ∙
( ap (λ t → add-ℕ (mul-ℕ x z) t) (commutative-mul-ℕ z y))))
-- Exercise 5.5(f)
abstract
associative-mul-ℕ :
(x y z : ℕ) → Id (mul-ℕ (mul-ℕ x y) z) (mul-ℕ x (mul-ℕ y z))
associative-mul-ℕ zero-ℕ y z = refl
associative-mul-ℕ (succ-ℕ x) y z =
( right-distributive-mul-add-ℕ (mul-ℕ x y) y z) ∙
( ap (λ t → add-ℕ t (mul-ℕ y z)) (associative-mul-ℕ x y z))
-- Exercise 5.6
Mac-Lane-pentagon :
{i : Level} {A : UU i} {a b c d e : A}
(p : Id a b) (q : Id b c) (r : Id c d) (s : Id d e) →
let α₁ = (ap (λ t → t ∙ s) (assoc p q r))
α₂ = (assoc p (q ∙ r) s)
α₃ = (ap (λ t → p ∙ t) (assoc q r s))
α₄ = (assoc (p ∙ q) r s)
α₅ = (assoc p q (r ∙ s))
in
Id ((α₁ ∙ α₂) ∙ α₃) (α₄ ∙ α₅)
Mac-Lane-pentagon refl refl refl refl = refl
{- The following code is an experiment that shows that constructions in an
abstract environment do remember the specific definitions of previous
definitions in abstract environments. -}
abstract
abstract-concat :
{l : Level} {A : UU l} {x y z : A} → Id x y → Id y z → Id x z
abstract-concat refl q = q
abstract-left-unit-law :
{l : Level} {A : UU l} {x y : A} (q : Id x y) → Id (abstract-concat refl q) q
abstract-left-unit-law q = refl
{- We just make some random definition to make sure that we are not in the
same abstract envirnoment anymore. -}
one : ℕ
one = succ-ℕ zero-ℕ
abstract
abstract-right-unit-law :
{l : Level} {A : UU l} {x y : A} (p : Id x y) →
Id (abstract-concat p refl) p
abstract-right-unit-law refl = refl
{- The term refl should not be accepted if the definition of abstract-concat
were forgotten. A definition that would work under all circumstances is
abstract-left-unit refl. -}
-- The ring axioms for ℤ
abstract
left-inverse-pred-ℤ :
(k : ℤ) → Id (pred-ℤ (succ-ℤ k)) k
left-inverse-pred-ℤ (inl zero-ℕ) = refl
left-inverse-pred-ℤ (inl (succ-ℕ x)) = refl
left-inverse-pred-ℤ (inr (inl star)) = refl
left-inverse-pred-ℤ (inr (inr zero-ℕ)) = refl
left-inverse-pred-ℤ (inr (inr (succ-ℕ x))) = refl
right-inverse-pred-ℤ :
(k : ℤ) → Id (succ-ℤ (pred-ℤ k)) k
right-inverse-pred-ℤ (inl zero-ℕ) = refl
right-inverse-pred-ℤ (inl (succ-ℕ x)) = refl
right-inverse-pred-ℤ (inr (inl star)) = refl
right-inverse-pred-ℤ (inr (inr zero-ℕ)) = refl
right-inverse-pred-ℤ (inr (inr (succ-ℕ x))) = refl
{- Exercise 6.12 (a) simply asks to prove the unit laws. The left unit law
holds by judgmental equality. -}
abstract
left-unit-law-add-ℤ :
(k : ℤ) → Id (add-ℤ zero-ℤ k) k
left-unit-law-add-ℤ k = refl
right-unit-law-add-ℤ :
(k : ℤ) → Id (add-ℤ k zero-ℤ) k
right-unit-law-add-ℤ (inl zero-ℕ) = refl
right-unit-law-add-ℤ (inl (succ-ℕ x)) =
ap pred-ℤ (right-unit-law-add-ℤ (inl x))
right-unit-law-add-ℤ (inr (inl star)) = refl
right-unit-law-add-ℤ (inr (inr zero-ℕ)) = refl
right-unit-law-add-ℤ (inr (inr (succ-ℕ x))) =
ap succ-ℤ (right-unit-law-add-ℤ (inr (inr x)))
{- Exercise 6.12 (b) asks to show the left and right predecessor and successor
laws. These are helpful to give proofs of associativity and commutativity.
-}
abstract
left-predecessor-law-add-ℤ :
(x y : ℤ) → Id (add-ℤ (pred-ℤ x) y) (pred-ℤ (add-ℤ x y))
left-predecessor-law-add-ℤ (inl n) y = refl
left-predecessor-law-add-ℤ (inr (inl star)) y = refl
left-predecessor-law-add-ℤ (inr (inr zero-ℕ)) y =
( ap (λ t → add-ℤ t y) (left-inverse-pred-ℤ zero-ℤ)) ∙
( inv (left-inverse-pred-ℤ y))
left-predecessor-law-add-ℤ (inr (inr (succ-ℕ x))) y =
( ap (λ t → (add-ℤ t y)) (left-inverse-pred-ℤ (inr (inr x)))) ∙
( inv (left-inverse-pred-ℤ (add-ℤ (inr (inr x)) y)))
right-predecessor-law-add-ℤ :
(x y : ℤ) → Id (add-ℤ x (pred-ℤ y)) (pred-ℤ (add-ℤ x y))
right-predecessor-law-add-ℤ (inl zero-ℕ) n = refl
right-predecessor-law-add-ℤ (inl (succ-ℕ m)) n =
ap pred-ℤ (right-predecessor-law-add-ℤ (inl m) n)
right-predecessor-law-add-ℤ (inr (inl star)) n = refl
right-predecessor-law-add-ℤ (inr (inr zero-ℕ)) n =
(right-inverse-pred-ℤ n) ∙ (inv (left-inverse-pred-ℤ n))
right-predecessor-law-add-ℤ (inr (inr (succ-ℕ x))) n =
( ap succ-ℤ (right-predecessor-law-add-ℤ (inr (inr x)) n)) ∙
( ( right-inverse-pred-ℤ (add-ℤ (inr (inr x)) n)) ∙
( inv (left-inverse-pred-ℤ (add-ℤ (inr (inr x)) n))))
abstract
left-successor-law-add-ℤ :
(x y : ℤ) → Id (add-ℤ (succ-ℤ x) y) (succ-ℤ (add-ℤ x y))
left-successor-law-add-ℤ (inl zero-ℕ) y =
( ap (λ t → add-ℤ t y) (right-inverse-pred-ℤ zero-ℤ)) ∙
( inv (right-inverse-pred-ℤ y))
left-successor-law-add-ℤ (inl (succ-ℕ x)) y =
( inv (right-inverse-pred-ℤ (add-ℤ (inl x) y))) ∙
( ap succ-ℤ (inv (left-predecessor-law-add-ℤ (inl x) y)))
left-successor-law-add-ℤ (inr (inl star)) y = refl
left-successor-law-add-ℤ (inr (inr x)) y = refl
right-successor-law-add-ℤ :
(x y : ℤ) → Id (add-ℤ x (succ-ℤ y)) (succ-ℤ (add-ℤ x y))
right-successor-law-add-ℤ (inl zero-ℕ) y =
(left-inverse-pred-ℤ y) ∙ (inv (right-inverse-pred-ℤ y))
right-successor-law-add-ℤ (inl (succ-ℕ x)) y =
( ap pred-ℤ (right-successor-law-add-ℤ (inl x) y)) ∙
( ( left-inverse-pred-ℤ (add-ℤ (inl x) y)) ∙
( inv (right-inverse-pred-ℤ (add-ℤ (inl x) y))))
right-successor-law-add-ℤ (inr (inl star)) y = refl
right-successor-law-add-ℤ (inr (inr zero-ℕ)) y = refl
right-successor-law-add-ℤ (inr (inr (succ-ℕ x))) y =
ap succ-ℤ (right-successor-law-add-ℤ (inr (inr x)) y)
{- Exercise 6.12 (c) asks to prove associativity and commutativity. Note that
we avoid an unwieldy amount of cases by only using induction on the first
argument. The resulting proof term is fairly short, and we don't have to
present ℤ as a certain quotient of ℕ × ℕ. -}
abstract
associative-add-ℤ :
(x y z : ℤ) → Id (add-ℤ (add-ℤ x y) z) (add-ℤ x (add-ℤ y z))
associative-add-ℤ (inl zero-ℕ) y z =
( ap (λ t → add-ℤ t z) (left-predecessor-law-add-ℤ zero-ℤ y)) ∙
( ( left-predecessor-law-add-ℤ y z) ∙
( inv (left-predecessor-law-add-ℤ zero-ℤ (add-ℤ y z))))
associative-add-ℤ (inl (succ-ℕ x)) y z =
( ap (λ t → add-ℤ t z) (left-predecessor-law-add-ℤ (inl x) y)) ∙
( ( left-predecessor-law-add-ℤ (add-ℤ (inl x) y) z) ∙
( ( ap pred-ℤ (associative-add-ℤ (inl x) y z)) ∙
( inv (left-predecessor-law-add-ℤ (inl x) (add-ℤ y z)))))
associative-add-ℤ (inr (inl star)) y z = refl
associative-add-ℤ (inr (inr zero-ℕ)) y z =
( ap (λ t → add-ℤ t z) (left-successor-law-add-ℤ zero-ℤ y)) ∙
( ( left-successor-law-add-ℤ y z) ∙
( inv (left-successor-law-add-ℤ zero-ℤ (add-ℤ y z))))
associative-add-ℤ (inr (inr (succ-ℕ x))) y z =
( ap (λ t → add-ℤ t z) (left-successor-law-add-ℤ (inr (inr x)) y)) ∙
( ( left-successor-law-add-ℤ (add-ℤ (inr (inr x)) y) z) ∙
( ( ap succ-ℤ (associative-add-ℤ (inr (inr x)) y z)) ∙
( inv (left-successor-law-add-ℤ (inr (inr x)) (add-ℤ y z)))))
abstract
commutative-add-ℤ :
(x y : ℤ) → Id (add-ℤ x y) (add-ℤ y x)
commutative-add-ℤ (inl zero-ℕ) y =
( left-predecessor-law-add-ℤ zero-ℤ y) ∙
( inv
( ( right-predecessor-law-add-ℤ y zero-ℤ) ∙
( ap pred-ℤ (right-unit-law-add-ℤ y))))
commutative-add-ℤ (inl (succ-ℕ x)) y =
( ap pred-ℤ (commutative-add-ℤ (inl x) y)) ∙
( inv (right-predecessor-law-add-ℤ y (inl x)))
commutative-add-ℤ (inr (inl star)) y = inv (right-unit-law-add-ℤ y)
commutative-add-ℤ (inr (inr zero-ℕ)) y =
inv
( ( right-successor-law-add-ℤ y zero-ℤ) ∙
( ap succ-ℤ (right-unit-law-add-ℤ y)))
commutative-add-ℤ (inr (inr (succ-ℕ x))) y =
( ap succ-ℤ (commutative-add-ℤ (inr (inr x)) y)) ∙
( inv (right-successor-law-add-ℤ y (inr (inr x))))
{- Exercise 6.12 (d) finally asks to show the inverse laws, completing the
verification of the group laws. Combined with associativity and
commutativity we conclude that (add-ℤ x) and (λ x → add-ℤ x y) are
equivalences, for every x : ℤ and y : ℤ, respectively. -}
abstract
left-inverse-law-add-ℤ :
(x : ℤ) → Id (add-ℤ (neg-ℤ x) x) zero-ℤ
left-inverse-law-add-ℤ (inl zero-ℕ) = refl
left-inverse-law-add-ℤ (inl (succ-ℕ x)) =
( ap succ-ℤ (right-predecessor-law-add-ℤ (inr (inr x)) (inl x))) ∙
( ( right-inverse-pred-ℤ (add-ℤ (inr (inr x)) (inl x))) ∙
( left-inverse-law-add-ℤ (inl x)))
left-inverse-law-add-ℤ (inr (inl star)) = refl
left-inverse-law-add-ℤ (inr (inr x)) =
( commutative-add-ℤ (inl x) (inr (inr x))) ∙
( left-inverse-law-add-ℤ (inl x))
right-inverse-law-add-ℤ :
(x : ℤ) → Id (add-ℤ x (neg-ℤ x)) zero-ℤ
right-inverse-law-add-ℤ x =
( commutative-add-ℤ x (neg-ℤ x)) ∙ (left-inverse-law-add-ℤ x)
-- Similar for multiplication on ℤ
neg-neg-ℤ : (k : ℤ) → Id (neg-ℤ (neg-ℤ k)) k
neg-neg-ℤ (inl n) = refl
neg-neg-ℤ (inr (inl star)) = refl
neg-neg-ℤ (inr (inr n)) = refl
neg-pred-ℤ :
(k : ℤ) → Id (neg-ℤ (pred-ℤ k)) (succ-ℤ (neg-ℤ k))
neg-pred-ℤ (inl x) = refl
neg-pred-ℤ (inr (inl star)) = refl
neg-pred-ℤ (inr (inr zero-ℕ)) = refl
neg-pred-ℤ (inr (inr (succ-ℕ x))) = refl
pred-neg-ℤ :
(k : ℤ) → Id (pred-ℤ (neg-ℤ k)) (neg-ℤ (succ-ℤ k))
pred-neg-ℤ (inl zero-ℕ) = refl
pred-neg-ℤ (inl (succ-ℕ x)) = refl
pred-neg-ℤ (inr (inl star)) = refl
pred-neg-ℤ (inr (inr x)) = refl
right-negative-law-add-ℤ :
(k l : ℤ) → Id (add-ℤ k (neg-ℤ l)) (neg-ℤ (add-ℤ (neg-ℤ k) l))
right-negative-law-add-ℤ (inl zero-ℕ) l =
( left-predecessor-law-add-ℤ zero-ℤ (neg-ℤ l)) ∙
( pred-neg-ℤ l)
right-negative-law-add-ℤ (inl (succ-ℕ x)) l =
( left-predecessor-law-add-ℤ (inl x) (neg-ℤ l)) ∙
( ( ap pred-ℤ (right-negative-law-add-ℤ (inl x) l)) ∙
( pred-neg-ℤ (add-ℤ (inr (inr x)) l)))
right-negative-law-add-ℤ (inr (inl star)) l = refl
right-negative-law-add-ℤ (inr (inr zero-ℕ)) l = inv (neg-pred-ℤ l)
right-negative-law-add-ℤ (inr (inr (succ-ℕ n))) l =
( left-successor-law-add-ℤ (in-pos n) (neg-ℤ l)) ∙
( ( ap succ-ℤ (right-negative-law-add-ℤ (inr (inr n)) l)) ∙
( inv (neg-pred-ℤ (add-ℤ (inl n) l))))
distributive-neg-add-ℤ :
(k l : ℤ) → Id (neg-ℤ (add-ℤ k l)) (add-ℤ (neg-ℤ k) (neg-ℤ l))
distributive-neg-add-ℤ (inl zero-ℕ) l =
( ap neg-ℤ (left-predecessor-law-add-ℤ zero-ℤ l)) ∙
( neg-pred-ℤ l)
distributive-neg-add-ℤ (inl (succ-ℕ n)) l =
( neg-pred-ℤ (add-ℤ (inl n) l)) ∙
( ( ap succ-ℤ (distributive-neg-add-ℤ (inl n) l)) ∙
( ap (λ t → add-ℤ t (neg-ℤ l)) (inv (neg-pred-ℤ (inl n)))))
distributive-neg-add-ℤ (inr (inl star)) l = refl
distributive-neg-add-ℤ (inr (inr zero-ℕ)) l = inv (pred-neg-ℤ l)
distributive-neg-add-ℤ (inr (inr (succ-ℕ n))) l =
( inv (pred-neg-ℤ (add-ℤ (in-pos n) l))) ∙
( ap pred-ℤ (distributive-neg-add-ℤ (inr (inr n)) l))
left-zero-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ zero-ℤ k) zero-ℤ
left-zero-law-mul-ℤ k = refl
right-zero-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ k zero-ℤ) zero-ℤ
right-zero-law-mul-ℤ (inl zero-ℕ) = refl
right-zero-law-mul-ℤ (inl (succ-ℕ n)) =
right-zero-law-mul-ℤ (inl n)
right-zero-law-mul-ℤ (inr (inl star)) = refl
right-zero-law-mul-ℤ (inr (inr zero-ℕ)) = refl
right-zero-law-mul-ℤ (inr (inr (succ-ℕ n))) =
right-zero-law-mul-ℤ (inr (inr n))
left-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ one-ℤ k) k
left-unit-law-mul-ℤ k = refl
right-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ k one-ℤ) k
right-unit-law-mul-ℤ (inl zero-ℕ) = refl
right-unit-law-mul-ℤ (inl (succ-ℕ n)) =
ap (add-ℤ (neg-one-ℤ)) (right-unit-law-mul-ℤ (inl n))
right-unit-law-mul-ℤ (inr (inl star)) = refl
right-unit-law-mul-ℤ (inr (inr zero-ℕ)) = refl
right-unit-law-mul-ℤ (inr (inr (succ-ℕ n))) =
ap (add-ℤ one-ℤ) (right-unit-law-mul-ℤ (inr (inr n)))
left-neg-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ neg-one-ℤ k) (neg-ℤ k)
left-neg-unit-law-mul-ℤ k = refl
right-neg-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ k neg-one-ℤ) (neg-ℤ k)
right-neg-unit-law-mul-ℤ (inl zero-ℕ) = refl
right-neg-unit-law-mul-ℤ (inl (succ-ℕ n)) =
ap (add-ℤ one-ℤ) (right-neg-unit-law-mul-ℤ (inl n))
right-neg-unit-law-mul-ℤ (inr (inl star)) = refl
right-neg-unit-law-mul-ℤ (inr (inr zero-ℕ)) = refl
right-neg-unit-law-mul-ℤ (inr (inr (succ-ℕ n))) =
ap (add-ℤ neg-one-ℤ) (right-neg-unit-law-mul-ℤ (inr (inr n)))
left-successor-law-mul-ℤ :
(k l : ℤ) → Id (mul-ℤ (succ-ℤ k) l) (add-ℤ l (mul-ℤ k l))
left-successor-law-mul-ℤ (inl zero-ℕ) l =
inv (right-inverse-law-add-ℤ l)
left-successor-law-mul-ℤ (inl (succ-ℕ n)) l =
( ( inv (left-unit-law-add-ℤ (mul-ℤ (inl n) l))) ∙
( ap
( λ x → add-ℤ x (mul-ℤ (inl n) l))
( inv (right-inverse-law-add-ℤ l)))) ∙
( associative-add-ℤ l (neg-ℤ l) (mul-ℤ (inl n) l))
left-successor-law-mul-ℤ (inr (inl star)) l =
inv (right-unit-law-add-ℤ l)
left-successor-law-mul-ℤ (inr (inr n)) l = refl
left-predecessor-law-mul-ℤ :
(k l : ℤ) → Id (mul-ℤ (pred-ℤ k) l) (add-ℤ (neg-ℤ l) (mul-ℤ k l))
left-predecessor-law-mul-ℤ (inl n) l = refl
left-predecessor-law-mul-ℤ (inr (inl star)) l =
( left-neg-unit-law-mul-ℤ l) ∙
( inv (right-unit-law-add-ℤ (neg-ℤ l)))
left-predecessor-law-mul-ℤ (inr (inr zero-ℕ)) l =
inv (left-inverse-law-add-ℤ l)
left-predecessor-law-mul-ℤ (inr (inr (succ-ℕ x))) l =
( ap
( λ t → add-ℤ t (mul-ℤ (in-pos x) l))
( inv (left-inverse-law-add-ℤ l))) ∙
( associative-add-ℤ (neg-ℤ l) l (mul-ℤ (in-pos x) l))
right-successor-law-mul-ℤ :
(k l : ℤ) → Id (mul-ℤ k (succ-ℤ l)) (add-ℤ k (mul-ℤ k l))
right-successor-law-mul-ℤ (inl zero-ℕ) l = inv (pred-neg-ℤ l)
right-successor-law-mul-ℤ (inl (succ-ℕ n)) l =
( left-predecessor-law-mul-ℤ (inl n) (succ-ℤ l)) ∙
( ( ap (add-ℤ (neg-ℤ (succ-ℤ l))) (right-successor-law-mul-ℤ (inl n) l)) ∙
( ( inv (associative-add-ℤ (neg-ℤ (succ-ℤ l)) (inl n) (mul-ℤ (inl n) l))) ∙
( ( ap
( λ t → add-ℤ t (mul-ℤ (inl n) l))
{ x = add-ℤ (neg-ℤ (succ-ℤ l)) (inl n)}
{ y = add-ℤ (inl (succ-ℕ n)) (neg-ℤ l)}
( ( right-successor-law-add-ℤ (neg-ℤ (succ-ℤ l)) (inl (succ-ℕ n))) ∙
( ( ap succ-ℤ
( commutative-add-ℤ (neg-ℤ (succ-ℤ l)) (inl (succ-ℕ n)))) ∙
( ( inv
( right-successor-law-add-ℤ
( inl (succ-ℕ n))
( neg-ℤ (succ-ℤ l)))) ∙
( ap
( add-ℤ (inl (succ-ℕ n)))
( ( ap succ-ℤ (inv (pred-neg-ℤ l))) ∙
( right-inverse-pred-ℤ (neg-ℤ l)))))))) ∙
( associative-add-ℤ (inl (succ-ℕ n)) (neg-ℤ l) (mul-ℤ (inl n) l)))))
right-successor-law-mul-ℤ (inr (inl star)) l = refl
right-successor-law-mul-ℤ (inr (inr zero-ℕ)) l = refl
right-successor-law-mul-ℤ (inr (inr (succ-ℕ n))) l =
( left-successor-law-mul-ℤ (in-pos n) (succ-ℤ l)) ∙
( ( ap (add-ℤ (succ-ℤ l)) (right-successor-law-mul-ℤ (inr (inr n)) l)) ∙
( ( inv (associative-add-ℤ (succ-ℤ l) (in-pos n) (mul-ℤ (in-pos n) l))) ∙
( ( ap
( λ t → add-ℤ t (mul-ℤ (in-pos n) l))
{ x = add-ℤ (succ-ℤ l) (in-pos n)}
{ y = add-ℤ (in-pos (succ-ℕ n)) l}
( ( left-successor-law-add-ℤ l (in-pos n)) ∙
( ( ap succ-ℤ (commutative-add-ℤ l (in-pos n))) ∙
( inv (left-successor-law-add-ℤ (in-pos n) l))))) ∙
( associative-add-ℤ (inr (inr (succ-ℕ n))) l (mul-ℤ (inr (inr n)) l)))))
right-predecessor-law-mul-ℤ :
(k l : ℤ) → Id (mul-ℤ k (pred-ℤ l)) (add-ℤ (neg-ℤ k) (mul-ℤ k l))
right-predecessor-law-mul-ℤ (inl zero-ℕ) l =
( left-neg-unit-law-mul-ℤ (pred-ℤ l)) ∙
( neg-pred-ℤ l)
right-predecessor-law-mul-ℤ (inl (succ-ℕ n)) l =
( left-predecessor-law-mul-ℤ (inl n) (pred-ℤ l)) ∙
( ( ap (add-ℤ (neg-ℤ (pred-ℤ l))) (right-predecessor-law-mul-ℤ (inl n) l)) ∙
( ( inv
( associative-add-ℤ (neg-ℤ (pred-ℤ l)) (in-pos n) (mul-ℤ (inl n) l))) ∙
( ( ap
( λ t → add-ℤ t (mul-ℤ (inl n) l))
{ x = add-ℤ (neg-ℤ (pred-ℤ l)) (inr (inr n))}
{ y = add-ℤ (neg-ℤ (inl (succ-ℕ n))) (neg-ℤ l)}
( ( ap (λ t → add-ℤ t (in-pos n)) (neg-pred-ℤ l)) ∙
( ( left-successor-law-add-ℤ (neg-ℤ l) (in-pos n)) ∙
( ( ap succ-ℤ (commutative-add-ℤ (neg-ℤ l) (in-pos n))) ∙
( inv (left-successor-law-add-ℤ (in-pos n) (neg-ℤ l))))))) ∙
( associative-add-ℤ (in-pos (succ-ℕ n)) (neg-ℤ l) (mul-ℤ (inl n) l)))))
right-predecessor-law-mul-ℤ (inr (inl star)) l = refl
right-predecessor-law-mul-ℤ (inr (inr zero-ℕ)) l = refl
right-predecessor-law-mul-ℤ (inr (inr (succ-ℕ n))) l =
( left-successor-law-mul-ℤ (in-pos n) (pred-ℤ l)) ∙
( ( ap (add-ℤ (pred-ℤ l)) (right-predecessor-law-mul-ℤ (inr (inr n)) l)) ∙
( ( inv (associative-add-ℤ (pred-ℤ l) (inl n) (mul-ℤ (inr (inr n)) l))) ∙
( ( ap
( λ t → add-ℤ t (mul-ℤ (in-pos n) l))
{ x = add-ℤ (pred-ℤ l) (inl n)}
{ y = add-ℤ (neg-ℤ (in-pos (succ-ℕ n))) l}
( ( left-predecessor-law-add-ℤ l (inl n)) ∙
( ( ap pred-ℤ (commutative-add-ℤ l (inl n))) ∙
( inv (left-predecessor-law-add-ℤ (inl n) l))))) ∙
( associative-add-ℤ (inl (succ-ℕ n)) l (mul-ℤ (inr (inr n)) l)))))
right-distributive-mul-add-ℤ :
(k l m : ℤ) → Id (mul-ℤ (add-ℤ k l) m) (add-ℤ (mul-ℤ k m) (mul-ℤ l m))
right-distributive-mul-add-ℤ (inl zero-ℕ) l m =
( left-predecessor-law-mul-ℤ l m) ∙
( ap
( λ t → add-ℤ t (mul-ℤ l m))
( inv
( ( left-predecessor-law-mul-ℤ zero-ℤ m) ∙
( right-unit-law-add-ℤ (neg-ℤ m)))))
right-distributive-mul-add-ℤ (inl (succ-ℕ x)) l m =
( left-predecessor-law-mul-ℤ (add-ℤ (inl x) l) m) ∙
( ( ap (add-ℤ (neg-ℤ m)) (right-distributive-mul-add-ℤ (inl x) l m)) ∙
( inv (associative-add-ℤ (neg-ℤ m) (mul-ℤ (inl x) m) (mul-ℤ l m))))
right-distributive-mul-add-ℤ (inr (inl star)) l m = refl
right-distributive-mul-add-ℤ (inr (inr zero-ℕ)) l m =
left-successor-law-mul-ℤ l m
right-distributive-mul-add-ℤ (inr (inr (succ-ℕ n))) l m =
( left-successor-law-mul-ℤ (add-ℤ (in-pos n) l) m) ∙
( ( ap (add-ℤ m) (right-distributive-mul-add-ℤ (inr (inr n)) l m)) ∙
( inv (associative-add-ℤ m (mul-ℤ (in-pos n) m) (mul-ℤ l m))))
left-negative-law-mul-ℤ :
(k l : ℤ) → Id (mul-ℤ (neg-ℤ k) l) (neg-ℤ (mul-ℤ k l))
left-negative-law-mul-ℤ (inl zero-ℕ) l =
( left-unit-law-mul-ℤ l) ∙
( inv (neg-neg-ℤ l))
left-negative-law-mul-ℤ (inl (succ-ℕ n)) l =
( ap (λ t → mul-ℤ t l) (neg-pred-ℤ (inl n))) ∙
( ( left-successor-law-mul-ℤ (neg-ℤ (inl n)) l) ∙
( ( ap (add-ℤ l) (left-negative-law-mul-ℤ (inl n) l)) ∙
( right-negative-law-add-ℤ l (mul-ℤ (inl n) l))))
left-negative-law-mul-ℤ (inr (inl star)) l = refl
left-negative-law-mul-ℤ (inr (inr zero-ℕ)) l = refl
left-negative-law-mul-ℤ (inr (inr (succ-ℕ n))) l =
( left-predecessor-law-mul-ℤ (inl n) l) ∙
( ( ap (add-ℤ (neg-ℤ l)) (left-negative-law-mul-ℤ (inr (inr n)) l)) ∙
( inv (distributive-neg-add-ℤ l (mul-ℤ (in-pos n) l))))
associative-mul-ℤ :
(k l m : ℤ) → Id (mul-ℤ (mul-ℤ k l) m) (mul-ℤ k (mul-ℤ l m))
associative-mul-ℤ (inl zero-ℕ) l m =
left-negative-law-mul-ℤ l m
associative-mul-ℤ (inl (succ-ℕ n)) l m =
( right-distributive-mul-add-ℤ (neg-ℤ l) (mul-ℤ (inl n) l) m) ∙
( ( ap (add-ℤ (mul-ℤ (neg-ℤ l) m)) (associative-mul-ℤ (inl n) l m)) ∙
( ap
( λ t → add-ℤ t (mul-ℤ (inl n) (mul-ℤ l m)))
( left-negative-law-mul-ℤ l m)))
associative-mul-ℤ (inr (inl star)) l m = refl
associative-mul-ℤ (inr (inr zero-ℕ)) l m = refl
associative-mul-ℤ (inr (inr (succ-ℕ n))) l m =
( right-distributive-mul-add-ℤ l (mul-ℤ (in-pos n) l) m) ∙
( ap (add-ℤ (mul-ℤ l m)) (associative-mul-ℤ (inr (inr n)) l m))
commutative-mul-ℤ :
(k l : ℤ) → Id (mul-ℤ k l) (mul-ℤ l k)
commutative-mul-ℤ (inl zero-ℕ) l = inv (right-neg-unit-law-mul-ℤ l)
commutative-mul-ℤ (inl (succ-ℕ n)) l =
( ap (add-ℤ (neg-ℤ l)) (commutative-mul-ℤ (inl n) l)) ∙
( inv (right-predecessor-law-mul-ℤ l (inl n)))
commutative-mul-ℤ (inr (inl star)) l = inv (right-zero-law-mul-ℤ l)
commutative-mul-ℤ (inr (inr zero-ℕ)) l = inv (right-unit-law-mul-ℤ l)
commutative-mul-ℤ (inr (inr (succ-ℕ n))) l =
( ap (add-ℤ l) (commutative-mul-ℤ (inr (inr n)) l)) ∙
( inv (right-successor-law-mul-ℤ l (in-pos n)))
| 37.014805
| 81
| 0.561995
|
50dc0cd6f8297945ae40a6f9f3636be8b46ed53a
| 3,417
|
agda
|
Agda
|
Categories/Agda.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Agda.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Agda.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Agda where
open import Level
import Relation.Binary
import Function.Equality
import Categories.Support.Equivalence
import Categories.Support.SetoidFunctions
open import Categories.Support.PropositionalEquality
open import Categories.Category
open import Categories.Functor using (Functor)
Sets : ∀ o → Category _ _ _
Sets o = record
{ Obj = Set o
; _⇒_ = λ d c → d → c
; _≡_ = λ f g → ∀ {x} → f x ≣ g x
; _∘_ = λ f g x → f (g x)
; id = λ x → x
; assoc = ≣-refl
; identityˡ = ≣-refl
; identityʳ = ≣-refl
; equiv = record { refl = ≣-refl; sym = s; trans = t }
; ∘-resp-≡ = ∘-resp-≡′
}
where
s : {A B : Set o} → {i j : A → B} → ({x : A} → i x ≣ j x) → {x : A} → j x ≣ i x
s f {x} rewrite f {x} = ≣-refl
t : {A B : Set o} {i j k : A → B} → ({x : A} → i x ≣ j x) → ({x : A} → j x ≣ k x) → {x : A} → i x ≣ k x
t f g {x} rewrite f {x} | g {x} = ≣-refl
∘-resp-≡′ : {A B C : Set o} {f h : B → C} {g i : A → B} →
(∀ {x} → f x ≣ h x) →
(∀ {x} → g x ≣ i x) →
(∀ {x} → f (g x) ≣ h (i x))
∘-resp-≡′ {g = g} f≡h g≡i {x} rewrite f≡h {g x} | g≡i {x} = ≣-refl
-- use standard library setoids here, not our special irrelevant ones
Setoids : ∀ c ℓ → Category (suc (ℓ ⊔ c)) (ℓ ⊔ c) (ℓ ⊔ c)
Setoids c ℓ = record
{ Obj = Setoid c ℓ
; _⇒_ = _⟶_
; _≡_ = λ {X} {Y} → _≡′_ {X} {Y}
; _∘_ = _∘′_
; id = id′
; assoc = λ {_} {_} {_} {D} → Setoid.refl D
; identityˡ = λ {_} {B} → Setoid.refl B
; identityʳ = λ {_} {B} → Setoid.refl B
; equiv = λ {A} {B} → record
{ refl = Setoid.refl B
; sym = λ f → Setoid.sym B f
; trans = λ f g → Setoid.trans B f g
}
; ∘-resp-≡ = λ {A} {B} {C} {f} {h} {g} {i} → ∘-resp-≡′ {A} {B} {C} {f} {h} {g} {i}
}
where
infix 4 _≡′_
open Function.Equality using (_⟨$⟩_; cong; _⟶_) renaming (_∘_ to _∘′_; id to id′)
open Relation.Binary using (Setoid; module Setoid; Rel)
_≡′_ : ∀ {X Y} → Rel (X ⟶ Y) _
_≡′_ {X} {Y} f g = ∀ {x} → Setoid._≈_ Y (f ⟨$⟩ x) (g ⟨$⟩ x)
.∘-resp-≡′ : ∀ {A B C} {f h : B ⟶ C} {g i : A ⟶ B} → f ≡′ h → g ≡′ i → f ∘′ g ≡′ h ∘′ i
∘-resp-≡′ {C = C} {h = h} f≡h g≡i {x} = Setoid.trans C f≡h (cong h g≡i)
-- setoids with irrelevant equality
ISetoids : ∀ c ℓ → Category (suc (ℓ ⊔ c)) (ℓ ⊔ c) (ℓ ⊔ c)
ISetoids c ℓ = record
{ Obj = Setoid c ℓ
; _⇒_ = _⟶_
; _≡_ = λ {A B} → Setoid._≈_ (A ⇨ B)
; _∘_ = _∙_
; id = id′
; assoc = λ {A B C D} {f g h} →
cong (h ∙ g ∙ f)
; identityˡ = λ {A B f} → cong f
; identityʳ = λ {A B f} → cong f
; equiv = λ {A B} → Setoid.isEquivalence (A ⇨ B)
; ∘-resp-≡ = λ f≡h g≡i x≡y → f≡h (g≡i x≡y)
}
where
open Relation.Binary using (Rel)
open Categories.Support.Equivalence
open Categories.Support.SetoidFunctions renaming (id to id′)
Lift-IS : ∀ {c ℓ} a b → Functor (ISetoids c ℓ) (ISetoids (c ⊔ a) (ℓ ⊔ b))
Lift-IS {c} {ℓ} a b = record {
F₀ = Lift-setoid {c} {ℓ} {a} {b};
F₁ = λ f → record { _⟨$⟩_ = λ x → lift (f ⟨$⟩ (lower x)); cong = λ eq → lift (cong f (lower eq)) };
identity = λ x → x;
homomorphism = λ {_} {_} {_} {f} {g} eq → lift (cong g (cong f (lower eq)));
F-resp-≡ = λ eq₀ eq₁ → lift (eq₀ (lower eq₁)) }
where
open import Categories.Support.Equivalence
open Categories.Support.SetoidFunctions renaming (id to id′)
| 32.855769
| 118
| 0.494586
|
2f525621f0df691630df89448ecc7ed6793f53f7
| 958
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Nullary/Construct/Add/Extrema.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/Nullary/Construct/Add/Extrema.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Nullary/Construct/Add/Extrema.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Notation for freely adding extrema to any set
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Construct.Add.Extrema where
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Relation.Nullary.Construct.Add.Infimum as Infimum using (_₋)
open import Relation.Nullary.Construct.Add.Supremum as Supremum using (_⁺)
------------------------------------------------------------------------
-- Definition
_± : ∀ {a} → Set a → Set a
A ± = A ₋ ⁺
pattern ⊥± = Supremum.[ Infimum.⊥₋ ]
pattern [_] k = Supremum.[ Infimum.[ k ] ]
pattern ⊤± = Supremum.⊤⁺
------------------------------------------------------------------------
-- Properties
[_]-injective : ∀ {a} {A : Set a} {k l : A} → [ k ] ≡ [ l ] → k ≡ l
[_]-injective refl = refl
| 31.933333
| 74
| 0.454071
|
12457290036376d25e45faa2b1952ab9a96c4573
| 88
|
agda
|
Agda
|
agda/Data/Pi.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
agda/Data/Pi.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/Pi.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Data.Pi where
open import Data.Pi.Base public
| 14.666667
| 32
| 0.693182
|
dc3f7dcc30133c17d5f5bd3a44e5346d93748f04
| 2,234
|
agda
|
Agda
|
LC/stash/STLC.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | 2
|
2020-08-25T07:34:40.000Z
|
2020-08-25T14:05:01.000Z
|
LC/stash/STLC.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
LC/stash/STLC.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
module STLC where
open import Data.Nat
open import Data.Empty
open import Relation.Binary.PropositionalEquality
-- infix 4 _⊢_
-- infix 4 _∋_∶_
-- infixl 5 _,_
infixr 7 _⟶_
infix 5 ƛ_
infixl 7 _∙_
-- infix 9 `_
infixl 10 _∶_
-- infix 5 μ_
-- infix 8 `suc_
-- infix 9 S_
-- infix 9 #_
data Type : Set where
_⟶_ : Type → Type → Type
⊤ : Type
data Context : Set
data Term : Set
infix 4 _∋_∶_
data _∋_∶_ : Context → Term → Type → Set
infixl 10 _,_∶_
data Context where
∅ : Context
_,_∶_ : Context → Term → Type → Context
data Term where
‵_ : ∀ {Γ x A} → Γ ∋ x ∶ A → Term
ƛ_ : Term → Term
_∙_ : Term → Term → Term
_∶_ : Term → Type → Term
tt : Term
data _∋_∶_ where
Z : ∀ {Γ x A}
---------
→ Γ , x ∶ A ∋ x ∶ A
S_ : ∀ {Γ x A y B}
→ Γ ∋ x ∶ A
---------
→ Γ , y ∶ B ∋ x ∶ A
-- lookup : Context → ℕ → Type
-- lookup (Γ , A) zero = A
-- lookup (Γ , _) (suc n) = lookup Γ n
-- lookup ∅ _ = ⊥-elim impossible
-- where postulate impossible : ⊥
-- count : ∀ {Γ} → (n : ℕ) → Γ ∋ lookup Γ n
-- count {Γ , _} zero = Z
-- count {Γ , _} (suc n) = S (count n)
-- count {∅} _ = ⊥-elim impossible
-- where postulate impossible : ⊥
-- -- #_ : ∀ {Γ} → (n : ℕ) → Γ ⊢ lookup Γ n
-- -- # n = ` count n
-- a = {! !}
infix 4 _⊢_⇐_
infix 4 _⊢_⇒_
data _⊢_⇐_ : Context → Term → Type → Set
data _⊢_⇒_ : Context → Term → Type → Set
variable
Γ : Context
x e f : Term
A B : Type
data _⊢_⇒_ where
Var :
Γ ∋ x ∶ A
----------------------------
→ Γ ⊢ x ⇒ A
Anno :
Γ ⊢ e ⇐ A
----------------------------
→ Γ ⊢ (e ∶ A) ⇒ A
⟶E :
Γ ⊢ f ⇒ (A ⟶ B)
→ Γ ⊢ e ⇐ A
----------------------------
→ Γ ⊢ f ∙ e ⇒ B
data _⊢_⇐_ where
Sub :
Γ ∋ e ∶ A
→ A ≡ B
----------------------------
→ Γ ⊢ e ⇐ B
⊤I : ∀ {Γ}
----------------------------
→ Γ ⊢ tt ⇐ ⊤
⟶I :
(Γ , x ∶ A) ⊢ e ⇐ B
----------------------------
→ Γ ⊢ ƛ e ⇐ A ⟶ B
4-4-Synth : ∅ , x ∶ A ⊢ x ⇒ A
4-4-Synth = Var Z
4-4-Check : ∅ , x ∶ A ⊢ x ⇐ A
4-4-Check = Sub Z refl
4-4-Sym→Elim : ∅ , f ∶ (A ⟶ B) , x ∶ A ⊢ (f ∙ x) ⇒ B
4-4-Sym→Elim = ⟶E (Var (S Z)) (Sub Z refl)
| 16.071942
| 52
| 0.416294
|
4daa53efb5ecf31690be20a9d0f0ada553b10361
| 2,719
|
agda
|
Agda
|
theorems/cohomology/LongExactSequence.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/cohomology/LongExactSequence.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/cohomology/LongExactSequence.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 HoTT
open import cohomology.Theory
open import groups.ExactSequence
open import groups.HomSequence
open import homotopy.CofiberSequence
module cohomology.LongExactSequence {i} (CT : CohomologyTheory i)
{X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y) where
open CohomologyTheory CT
open import cohomology.PtdMapSequence CT
co∂ : C n X →ᴳ C (succ n) (⊙Cofiber f)
co∂ = record {f = CEl-fmap (succ n) ⊙extract-glue ∘ GroupIso.g (C-Susp n X); pres-comp = lemma} where
abstract lemma = ∘-pres-comp (C-fmap (succ n) ⊙extract-glue) (GroupIso.g-hom (C-Susp n X))
C-cofiber-seq : HomSequence (C n Y) (C (succ n) X)
C-cofiber-seq =
C n Y →⟨ C-fmap n f ⟩ᴳ
C n X →⟨ co∂ ⟩ᴳ
C (succ n) (⊙Cofiber f) →⟨ C-fmap (succ n) (⊙cfcod' f) ⟩ᴳ
C (succ n) Y →⟨ C-fmap (succ n) f ⟩ᴳ
C (succ n) X ⊣|ᴳ
private
C-iterated-cofiber-seq = C-seq (succ n) (iterated-cofiber-seq f)
C-iterated-cofiber-seq-is-exact : is-exact-seq C-iterated-cofiber-seq
C-iterated-cofiber-seq-is-exact =
C-exact (succ n) (⊙cfcod²' f) , C-exact (succ n) (⊙cfcod' f) , C-exact (succ n) f , lift tt
-- An intermediate sequence for proving exactness of [C-cofiber-seq].
C-cofiber-seq' = C-seq (succ n) (cyclic-cofiber-seq f)
C-cofiber-seq'-is-exact : is-exact-seq C-cofiber-seq'
C-cofiber-seq'-is-exact =
seq-equiv-preserves'-exact
(C-seq-emap (succ n) (iterated-equiv-cyclic f))
C-iterated-cofiber-seq-is-exact
-- Now the final sequence
C-cofiber-seq'-to-C-cofiber-seq :
HomSeqMap C-cofiber-seq' C-cofiber-seq
(GroupIso.f-hom (C-Susp n Y)) (idhom _)
C-cofiber-seq'-to-C-cofiber-seq =
GroupIso.f-hom (C-Susp n Y) ↓⟨ C-Susp-fmap n f ⟩ᴳ
GroupIso.f-hom (C-Susp n X) ↓⟨ comm-sqrᴳ (λ x → ap (CEl-fmap (succ n) ⊙extract-glue) (! $ GroupIso.g-f (C-Susp n X) x)) ⟩ᴳ
idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ
idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ
idhom _ ↓|ᴳ
C-cofiber-seq'-equiv-C-cofiber-seq :
HomSeqEquiv C-cofiber-seq' C-cofiber-seq
(GroupIso.f-hom (C-Susp n Y)) (idhom _)
C-cofiber-seq'-equiv-C-cofiber-seq =
C-cofiber-seq'-to-C-cofiber-seq ,
(GroupIso.f-is-equiv (C-Susp n Y) , GroupIso.f-is-equiv (C-Susp n X) , idf-is-equiv _ , idf-is-equiv _ , idf-is-equiv _)
abstract
C-cofiber-seq-is-exact : is-exact-seq C-cofiber-seq
C-cofiber-seq-is-exact = seq-equiv-preserves-exact
C-cofiber-seq'-equiv-C-cofiber-seq C-cofiber-seq'-is-exact
C-cofiber-exact-seq : ExactSequence (C n Y) (C (succ n) X)
C-cofiber-exact-seq = C-cofiber-seq , C-cofiber-seq-is-exact
| 39.985294
| 126
| 0.613093
|
d08ca99a2258f57dc222ad2fa643095efa5a90e8
| 878
|
agda
|
Agda
|
AnyBoolean.agda
|
larrytheliquid/bahug-april2010
|
60f71d369015b83b9ef5fabc75a70f367d20ac97
|
[
"MIT"
] | null | null | null |
AnyBoolean.agda
|
larrytheliquid/bahug-april2010
|
60f71d369015b83b9ef5fabc75a70f367d20ac97
|
[
"MIT"
] | null | null | null |
AnyBoolean.agda
|
larrytheliquid/bahug-april2010
|
60f71d369015b83b9ef5fabc75a70f367d20ac97
|
[
"MIT"
] | 1
|
2022-03-12T12:03:09.000Z
|
2022-03-12T12:03:09.000Z
|
module AnyBoolean where
open import Data.Bool
open import Data.Nat
open import Data.List hiding (any)
open import Relation.Binary.PropositionalEquality
even : ℕ → Bool
even zero = true
even (suc zero) = false
even (suc (suc n)) = even n
test-6-even : even 6 ≡ true
test-6-even = refl
odd : ℕ → Bool
odd zero = false
odd (suc zero) = true
odd (suc (suc n)) = odd n
test-5-odd : odd 5 ≡ true
test-5-odd = refl
any : {A : Set} → (A → Bool) → List A → Bool
any _ [] = false
any p (x ∷ xs) with p x
... | true = true
... | false = any p xs
test-any-even-true :
any even (3 ∷ 6 ∷ 9 ∷ []) ≡ true
test-any-even-true = refl
test-any-even-false :
any even (3 ∷ 7 ∷ 9 ∷ []) ≡ false
test-any-even-false = refl
test-any-odd-true :
any odd (4 ∷ 7 ∷ 10 ∷ []) ≡ true
test-any-odd-true = refl
test-any-odd-false :
any odd (4 ∷ 8 ∷ 10 ∷ []) ≡ false
test-any-odd-false = refl
| 19.954545
| 49
| 0.61959
|
0633a6ac1e97e1b950ef87073eb65d92d2bf83f3
| 7,854
|
agda
|
Agda
|
Cubical/HITs/Ints/BiInvInt/Properties.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/BiInvInt/Properties.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/BiInvInt/Properties.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Ints.BiInvInt.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
import Cubical.Data.Int as Int
open import Cubical.Data.Bool
open import Cubical.HITs.Ints.BiInvInt.Base
infixl 6 _+_ _-_
infixl 7 _·_
-- To prove a property P about BiInvInt, we need to show:
-- * P zero
-- * If P n, then P (suc n)
-- * If P n, then P (pred n)
BiInvInt-ind-prop :
∀ {ℓ} {P : BiInvInt → Type ℓ} → (∀ n → isProp (P n)) →
P zero → (∀ n → P n → P (suc n)) → (∀ n → P n → P (pred n)) →
(n : BiInvInt) → P n
BiInvInt-ind-prop {P = P} P-isProp P-zero P-suc P-pred = φ
where
P-predr : ∀ n → P n → P (predr n)
P-predr n x = subst P (predl≡predr n) (P-pred n x)
P-predl : ∀ n → P n → P (predl n)
P-predl = P-pred
P-isProp' : {a b : BiInvInt} (p : a ≡ b) (x : P a) (y : P b) → PathP (λ i → P (p i)) x y
P-isProp' _ _ _ = toPathP (P-isProp _ _ _)
φ : (n : BiInvInt) → P n
φ zero = P-zero
φ (suc n) = P-suc n (φ n)
φ (predr n) = P-predr n (φ n)
φ (suc-predr n i) = P-isProp' (suc-predr n) (P-suc (predr n) (P-predr n (φ n))) (φ n) i
φ (predl n) = P-predl n (φ n)
φ (predl-suc n i) = P-isProp' (predl-suc n) (P-predl (suc n) (P-suc n (φ n))) (φ n) i
-- To define a function BiInvInt → A, we need:
-- · a point z : A for zero
-- · an equivalence s : A ≃ A for suc/pred
BiInvInt-rec : ∀ {ℓ} {A : Type ℓ} → A → A ≃ A → BiInvInt → A
BiInvInt-rec {A = A} z e = φ
where
e-Iso : Iso A A
e-Iso = equivToIso e
φ : BiInvInt → A
φ zero = z
φ (suc n) = Iso.fun e-Iso (φ n)
φ (predr n) = Iso.inv e-Iso (φ n)
φ (suc-predr n i) = Iso.rightInv e-Iso (φ n) i
φ (predl n) = Iso.inv e-Iso (φ n)
φ (predl-suc n i) = Iso.leftInv e-Iso (φ n) i
sucIso : Iso BiInvInt BiInvInt
Iso.fun sucIso = suc
Iso.inv sucIso = pred
Iso.rightInv sucIso = suc-predl
Iso.leftInv sucIso = predl-suc
sucEquiv : BiInvInt ≃ BiInvInt
sucEquiv = isoToEquiv sucIso
-- addition
-- the following equalities hold definitionally:
-- zero + n ≡ n
-- suc m + n ≡ suc (m + n)
-- pred m + n ≡ pred (m + n)
_+_ : BiInvInt → BiInvInt → BiInvInt
_+_ = BiInvInt-rec (idfun BiInvInt) (postCompEquiv sucEquiv)
-- properties of addition
+-zero : ∀ n → n + zero ≡ n
+-zero = BiInvInt-ind-prop (λ _ → isSetBiInvInt _ _) refl (λ n p → cong suc p) (λ n p → cong pred p)
+-suc : ∀ m n → m + suc n ≡ suc (m + n)
+-suc = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ m → refl)
(λ m p n → cong suc (p n))
(λ m p n → cong pred (p n) ∙ predl-suc (m + n) ∙ sym (suc-predl (m + n)))
+-pred : ∀ m n → m + pred n ≡ pred (m + n)
+-pred = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ m → refl)
(λ m p n → cong suc (p n) ∙ suc-predl (m + n) ∙ sym (predl-suc (m + n)))
(λ m p n → cong pred (p n))
+-comm : ∀ m n → m + n ≡ n + m
+-comm m n = +-comm' n m
where
+-comm' : ∀ n m → m + n ≡ n + m
+-comm' = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
+-zero
(λ n p m → +-suc m n ∙ cong suc (p m))
(λ n p m → +-pred m n ∙ cong pred (p m))
+-assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o
+-assoc = BiInvInt-ind-prop (λ _ → isPropΠ2 λ _ _ → isSetBiInvInt _ _)
(λ n o → refl)
(λ m p n o → cong suc (p n o))
(λ m p n o → cong pred (p n o))
-- negation / subtraction
-- the following equalities hold definitionally:
-- - zero ≡ zero
-- - (suc m) ≡ pred m
-- - (pred m) ≡ suc m
-_ : BiInvInt → BiInvInt
-_ = BiInvInt-rec zero (invEquiv sucEquiv)
_-_ : BiInvInt → BiInvInt → BiInvInt
m - n = m + (- n)
+-invˡ : ∀ n → (- n) + n ≡ zero
+-invˡ = BiInvInt-ind-prop (λ _ → isSetBiInvInt _ _)
refl
(λ n p → cong pred (+-suc (- n) n) ∙ predl-suc _ ∙ p)
(λ n p → cong suc (+-pred (- n) n) ∙ suc-predl _ ∙ p)
+-invʳ : ∀ n → n + (- n) ≡ zero
+-invʳ = BiInvInt-ind-prop (λ _ → isSetBiInvInt _ _)
refl
(λ n p → cong suc (+-pred n (- n)) ∙ suc-predl _ ∙ p)
(λ n p → cong pred (+-suc n (- n)) ∙ predl-suc _ ∙ p)
inv-hom : ∀ m n → - (m + n) ≡ (- m) + (- n)
inv-hom = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ n → refl)
(λ m p n → cong pred (p n))
(λ m p n → cong suc (p n))
-- natural injections from ℕ
pos : ℕ → BiInvInt
pos ℕ.zero = zero
pos (ℕ.suc n) = suc (pos n)
neg : ℕ → BiInvInt
neg ℕ.zero = zero
neg (ℕ.suc n) = pred (neg n)
-- absolute value and sign
-- (Note that there doesn't appear to be any way around using
-- bwd here! Any direct proof ends up doing the same work...)
abs : BiInvInt → ℕ
abs n = Int.abs (bwd n)
sgn : BiInvInt → Bool
sgn n = Int.sgn (bwd n)
Iso-n+ : (n : BiInvInt) → Iso BiInvInt BiInvInt
Iso.fun (Iso-n+ n) = n +_
Iso.inv (Iso-n+ n) = - n +_
Iso.rightInv (Iso-n+ n) m = +-assoc n (- n) m ∙ cong (_+ m) (+-invʳ n)
Iso.leftInv (Iso-n+ n) m = +-assoc (- n) n m ∙ cong (_+ m) (+-invˡ n)
isEquiv-n+ : ∀ n → isEquiv (n +_)
isEquiv-n+ n = isoToIsEquiv (Iso-n+ n)
-- multiplication
-- the following equalities hold definitionally:
-- zero · n ≡ zero
-- suc m · n ≡ n + m · n
-- pred m · n ≡ (- n) + m · n
_·_ : BiInvInt → BiInvInt → BiInvInt
m · n = BiInvInt-rec zero (n +_ , isEquiv-n+ n) m
-- properties of multiplication
·-zero : ∀ n → n · zero ≡ zero
·-zero = BiInvInt-ind-prop (λ _ → isSetBiInvInt _ _) refl (λ n p → p) (λ n p → p)
·-suc : ∀ m n → m · suc n ≡ m + m · n
·-suc = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ n → refl)
(λ m p n → cong suc
(cong (n +_) (p n) ∙ +-assoc n m (m · n) ∙
cong (_+ m · n) (+-comm n m) ∙ sym (+-assoc m n (m · n))))
(λ m p n → cong pred
(cong (- n +_) (p n) ∙ +-assoc (- n) m (m · n) ∙
cong (_+ m · n) (+-comm (- n) m) ∙ sym (+-assoc m (- n) (m · n))))
·-pred : ∀ m n → m · pred n ≡ (- m) + m · n
·-pred = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ n → refl)
(λ m p n → cong pred
(cong (n +_) (p n) ∙ +-assoc n (- m) (m · n) ∙
cong (_+ m · n) (+-comm n (- m)) ∙ sym (+-assoc (- m) n (m · n))))
(λ m p n → cong suc
(cong (- n +_) (p n) ∙ +-assoc (- n) (- m) (m · n) ∙
cong (_+ m · n) (+-comm (- n) (- m)) ∙ sym (+-assoc (- m) (- n) (m · n))))
·-comm : ∀ m n → m · n ≡ n · m
·-comm = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ n → sym (·-zero n))
(λ m p n → cong (n +_) (p n) ∙ sym (·-suc n m))
(λ m p n → cong (- n +_) (p n) ∙ sym (·-pred n m))
·-identityˡ : ∀ m → suc zero · m ≡ m
·-identityˡ = +-zero
·-identityʳ : ∀ m → m · suc zero ≡ m
·-identityʳ m = ·-comm m (suc zero) ∙ ·-identityˡ m
·-distribʳ : ∀ m n o → (m · o) + (n · o) ≡ (m + n) · o
·-distribʳ = BiInvInt-ind-prop (λ _ → isPropΠ2 λ _ _ → isSetBiInvInt _ _)
(λ n o → refl)
(λ m p n o → sym (+-assoc o (m · o) (n · o)) ∙ cong (o +_) (p n o))
(λ m p n o → sym (+-assoc (- o) (m · o) (n · o)) ∙ cong (- o +_) (p n o))
·-distribˡ : ∀ o m n → (o · m) + (o · n) ≡ o · (m + n)
·-distribˡ o m n =
cong (_+ o · n) (·-comm o m) ∙ cong (m · o +_) (·-comm o n) ∙
·-distribʳ m n o ∙ ·-comm (m + n) o
·-inv : ∀ m n → m · (- n) ≡ - (m · n)
·-inv = BiInvInt-ind-prop (λ _ → isPropΠ λ _ → isSetBiInvInt _ _)
(λ n → refl)
(λ m p n → cong (- n +_) (p n) ∙ sym (inv-hom n (m · n)))
(λ m p n → cong (- (- n) +_) (p n) ∙ sym (inv-hom (- n) (m · n)))
inv-· : ∀ m n → (- m) · n ≡ - (m · n)
inv-· m n = ·-comm (- m) n ∙ ·-inv n m ∙ cong (-_) (·-comm n m)
·-assoc : ∀ m n o → m · (n · o) ≡ (m · n) · o
·-assoc = BiInvInt-ind-prop (λ _ → isPropΠ2 λ _ _ → isSetBiInvInt _ _)
(λ n o → refl)
(λ m p n o →
cong (n · o +_) (p n o) ∙ ·-distribʳ n (m · n) o)
(λ m p n o →
cong (- (n · o) +_) (p n o) ∙ cong (_+ m · n · o) (sym (inv-· n o)) ∙
·-distribʳ (- n) (m · n) o)
| 31.542169
| 100
| 0.535523
|
57c5847ec68766c394f3d59972450e6dadca26a0
| 4,210
|
agda
|
Agda
|
Cubical/Algebra/Group/Instances/Bool.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/Instances/Bool.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/Instances/Bool.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Instances.Bool where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Relation.Nullary
open import Cubical.Data.Bool
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sum hiding (map ; rec)
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Semigroup
open GroupStr
open IsGroup
open IsMonoid
open IsSemigroup
BoolGroup : Group₀
fst BoolGroup = Bool
1g (snd BoolGroup) = true
(snd BoolGroup · false) false = true
(snd BoolGroup · false) true = false
(snd BoolGroup · true) y = y
inv (snd BoolGroup) x = x
is-set (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) = isSetBool
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) false false false = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) false false true = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) false true false = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) false true true = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) true false false = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) true false true = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) true true false = refl
·Assoc (isSemigroup (isMonoid (isGroup (snd BoolGroup)))) true true true = refl
·IdR (isMonoid (isGroup (snd BoolGroup))) false = refl
·IdR (isMonoid (isGroup (snd BoolGroup))) true = refl
·IdL (isMonoid (isGroup (snd BoolGroup))) false = refl
·IdL (isMonoid (isGroup (snd BoolGroup))) true = refl
·InvR (isGroup (snd BoolGroup)) false = refl
·InvR (isGroup (snd BoolGroup)) true = refl
·InvL (isGroup (snd BoolGroup)) false = refl
·InvL (isGroup (snd BoolGroup)) true = refl
-- Proof that any Group equivalent to Bool as types is also isomorphic to Bool as groups.
open GroupStr renaming (·Assoc to ·AssocG)
module _ {ℓ : Level} {A : Group ℓ} (e : Iso (fst A) Bool) where
private
discreteA : Discrete (typ A)
discreteA = isoPresDiscrete (invIso e) _≟_
_·A_ = GroupStr._·_ (snd A)
-A_ = GroupStr.inv (snd A)
IsoABool : Iso Bool (typ A)
IsoABool with (Iso.fun e (1g (snd A))) ≟ true
... | yes p = invIso e
... | no p = compIso notIso (invIso e)
true→1 : Iso.fun IsoABool true ≡ 1g (snd A)
true→1 with (Iso.fun e (1g (snd A))) ≟ true
... | yes p = sym (cong (Iso.inv e) p) ∙ Iso.leftInv e _
... | no p = sym (cong (Iso.inv e) (¬true→false (Iso.fun e (1g (snd A))) p))
∙ Iso.leftInv e (1g (snd A))
decA : (x : typ A) → (x ≡ 1g (snd A)) ⊎ (x ≡ Iso.fun IsoABool false)
decA x with (Iso.inv IsoABool x) ≟ false | discreteA x (1g (snd A))
... | yes p | yes q = inl q
... | yes p | no q = inr (sym (Iso.rightInv IsoABool x) ∙ cong (Iso.fun (IsoABool)) p)
... | no p | no q = inr (⊥.rec (q (sym (Iso.rightInv IsoABool x)
∙∙ cong (Iso.fun IsoABool) (¬false→true _ p)
∙∙ true→1)))
... | no p | yes q = inl q
≅Bool : GroupIso BoolGroup A
≅Bool .fst = IsoABool
≅Bool .snd = makeIsGroupHom homHelp
where
homHelp : _
homHelp false false with discreteA (Iso.fun IsoABool false) (1g (snd A))
| (decA ((Iso.fun IsoABool false) ·A Iso.fun IsoABool false))
... | yes p | _ = true→1 ∙∙ sym (GroupStr.·IdR (snd A) (1g (snd A))) ∙∙ cong₂ (_·A_) (sym p) (sym p)
... | no p | inl x = true→1 ∙ sym x
... | no p | inr x = true→1 ∙∙ sym (helper _ x) ∙∙ sym x
where
helper : (x : typ A) → x ·A x ≡ x → x ≡ (1g (snd A))
helper x p = sym (GroupStr.·IdR (snd A) x)
∙∙ cong (x ·A_) (sym ((snd A) .·InvR x))
∙∙ ·AssocG (snd A) x x (-A x) ∙∙ cong (_·A (-A x)) p
∙∙ (snd A) .·InvR x
homHelp false true = sym (GroupStr.·IdR (snd A) _) ∙ cong (Iso.fun IsoABool false ·A_) (sym true→1)
homHelp true y = sym (GroupStr.·IdL (snd A) _) ∙ cong (_·A (Iso.fun IsoABool y)) (sym true→1)
| 41.683168
| 108
| 0.631116
|
063eea785d09782acd63a212a2e792276d4aec13
| 2,280
|
agda
|
Agda
|
complexity-drafts/Translation2.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 2
|
2016-04-26T20:22:22.000Z
|
2019-08-08T12:27:18.000Z
|
complexity-drafts/Translation2.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 1
|
2020-03-23T08:39:04.000Z
|
2020-05-12T00:32:45.000Z
|
complexity-drafts/Translation2.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | null | null | null |
--NEW TRANSLATION FILE
open import Preliminaries
open import Source2
open import Comp2
module Translation2 where
-- translation from source types to complexity types
mutual
⟨⟨_⟩⟩ : Tp → CTp
⟨⟨ unit ⟩⟩ = unit
⟨⟨ nat ⟩⟩ = nat
⟨⟨ susp A ⟩⟩ = || A ||
⟨⟨ A ->s B ⟩⟩ = ⟨⟨ A ⟩⟩ ->c || B ||
⟨⟨ A ×s B ⟩⟩ = ⟨⟨ A ⟩⟩ ×c ⟨⟨ B ⟩⟩
⟨⟨ list A ⟩⟩ = list ⟨⟨ A ⟩⟩
⟨⟨ bool ⟩⟩ = bool
||_|| : Tp → CTp
|| τ || = C ×c ⟨⟨ τ ⟩⟩
⟨⟨_⟩⟩c : Source2.Ctx → Comp2.Ctx
⟨⟨ [] ⟩⟩c = []
⟨⟨ x :: Γ ⟩⟩c = ⟨⟨ x ⟩⟩ :: ⟨⟨ Γ ⟩⟩c
-- translate source Cost types to complexity costs
interp-Cost : ∀{Γ} → Cost → Γ Comp2.|- C
interp-Cost 0c = 0C
interp-Cost 1c = 1C
interp-Cost (m +c n) = plusC (interp-Cost m) (interp-Cost n)
-- need to fill this out
postulate lookup : ∀{Γ τ} → τ Source2.∈ Γ → ⟨⟨ τ ⟩⟩ Comp2.∈ ⟨⟨ Γ ⟩⟩c
-- translation from source expressions to complexity expressions
||_||e : ∀{Γ τ} → Γ Source2.|- τ → ⟨⟨ Γ ⟩⟩c Comp2.|- || τ ||
|| unit ||e = prod 0C unit
|| var x ||e = prod 0C (var (lookup x))
|| z ||e = prod 0C z
|| suc e ||e = prod (l-proj (|| e ||e)) (suc (r-proj (|| e ||e)))
|| rec e e0 e1 ||e = (l-proj (|| e ||e)) +C (rec (r-proj || e ||e) (1C +C || e0 ||e) (1C +C || e1 ||e))
|| lam e ||e = prod 0C (lam || e ||e)
|| app e1 e2 ||e = prod (plusC (plusC (l-proj (|| e1 ||e)) (l-proj (|| e2 ||e))) (l-proj (app (r-proj (|| e1 ||e)) (r-proj (|| e2 ||e)))))
(r-proj (app (r-proj (|| e1 ||e)) (r-proj (|| e2 ||e))))
|| prod e1 e2 ||e = prod (plusC (l-proj (|| e1 ||e)) (l-proj (|| e2 ||e))) (prod (r-proj (|| e1 ||e)) (r-proj (|| e2 ||e)))
|| delay e ||e = prod 0C (|| e ||e)
|| force e ||e = prod (plusC (l-proj (|| e ||e)) (l-proj (r-proj || e ||e))) (r-proj (r-proj (|| e ||e)))
|| split e0 e1 ||e = prod (plusC (l-proj (|| e0 ||e)) (l-proj E1)) (r-proj E1)
where E1 = (Comp2.subst || e1 ||e (Comp2.lem4 (l-proj (r-proj || e0 ||e)) (r-proj (r-proj || e0 ||e))))
|| nil ||e = prod 0C nil
|| e ::s e₁ ||e = prod (plusC (l-proj || e ||e) (l-proj || e₁ ||e)) ((r-proj || e ||e) ::c (r-proj || e₁ ||e))
|| listrec e e₁ e₂ ||e = l-proj || e ||e +C listrec (r-proj || e ||e) (1C +C || e₁ ||e) (1C +C || e₂ ||e)
|| true ||e = prod 0C true
|| false ||e = prod 0C false
| 40
| 140
| 0.463596
|
23b885835d11ce4b6f841f69f86c60c163125035
| 19,533
|
agda
|
Agda
|
Definition/Conversion/EqRelInstance.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/Conversion/EqRelInstance.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/Conversion/EqRelInstance.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
module Definition.Conversion.EqRelInstance where
open import Definition.Untyped
open import Definition.Untyped.Properties using (wkSingleSubstId)
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening using (_∷_⊆_; wkEq; step; id)
open import Definition.Conversion
open import Definition.Conversion.Reduction
open import Definition.Conversion.Universe
open import Definition.Conversion.Stability
open import Definition.Conversion.Soundness
open import Definition.Conversion.Lift
open import Definition.Conversion.Conversion
open import Definition.Conversion.Transitivity
open import Definition.Conversion.Weakening
open import Definition.Conversion.Whnf
open import Definition.Typed.EqualityRelation
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Substitution
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Equality
open import Definition.Typed.Consequences.Reduction
open import Definition.Conversion.Symmetry
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
open import Tools.Function
-- Algorithmic equality of neutrals with injected conversion.
data _⊢_~_∷_^_ (Γ : Con Term) (k l A : Term) (r : TypeInfo) : Set where
↑ : ∀ {B} → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ↑ B ^ r → Γ ⊢ k ~ l ∷ A ^ r
-- Properties of algorithmic equality of neutrals with injected conversion.
~-var : ∀ {x A r Γ} → Γ ⊢ var x ∷ A ^ r → Γ ⊢ var x ~ var x ∷ A ^ r
~-var x =
let ⊢A = syntacticTerm x
in ↑ (refl ⊢A) (var-refl′ x)
~-app : ∀ {f g a b F G Γ rF lF lG lΠ}
→ Γ ⊢ f ~ g ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ ! , ι lΠ ]
→ Γ ⊢ a [genconv↑] b ∷ F ^ [ rF , ι lF ]
→ Γ ⊢ f ∘ a ^ lΠ ~ g ∘ b ^ lΠ ∷ G [ a ] ^ [ ! , ι lG ]
~-app {rF = !} (↑ A≡B (~↑! x)) x₁ =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ΠFG≡B′ = trans A≡B (subset* (red D))
H , E , B≡ΠHE = Π≡A ΠFG≡B′ whnfB′
F≡H , _ , _ , _ , G≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) B≡ΠHE ΠFG≡B′)
_ , ⊢f , _ = syntacticEqTerm (soundnessConv↑Term x₁)
in ↑ (substTypeEq G≡E (refl ⊢f))
(app-cong′ (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _)
B≡ΠHE ([~] _ (red D) whnfB′ x))
(convConvTerm x₁ F≡H))
~-app {rF = %} (↑ A≡B (~↑! x)) x₁ =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ΠFG≡B′ = trans A≡B (subset* (red D))
H , E , B≡ΠHE = Π≡A ΠFG≡B′ whnfB′
F≡H , _ , _ , _ , G≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) B≡ΠHE ΠFG≡B′)
_ , ⊢f , _ = syntacticEqTerm (proj₂ (proj₂ (soundness~↑% x₁)))
in ↑ (substTypeEq G≡E (genRefl ⊢f))
(app-cong′ (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _)
B≡ΠHE ([~] _ (red D) whnfB′ x))
(conv~↑% x₁ F≡H))
~-natrec : ∀ {z z′ s s′ n n′ F F′ Γ lF}
→ (Γ ∙ ℕ ^ [ ! , ι ⁰ ]) ⊢ F [conv↑] F′ ^ [ ! , ι lF ] →
Γ ⊢ z [conv↑] z′ ∷ (F [ zero ]) ^ ι lF →
Γ ⊢ s [conv↑] s′ ∷ (Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF) ° lF ° lF) ^ ι lF →
Γ ⊢ n ~ n′ ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ natrec lF F z s n ~ natrec lF F′ z′ s′ n′ ∷ (F [ n ]) ^ [ ! , ι lF ]
~-natrec {n = n} {n′ = n′} x x₁ x₂ (↑ A≡B (~↑! x₄)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
k~l′ = PE.subst (λ x → _ ⊢ n ~ n′ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x₄)
⊢F , _ = syntacticEq (soundnessConv↑ x)
_ , ⊢n , _ = syntacticEqTerm (soundness~↓! k~l′)
in ↑ (refl (substType ⊢F ⊢n)) (natrec-cong′ x x₁ x₂ k~l′)
~-Emptyrec : ∀ {e e' F F′ Γ l lEmpty}
→ Γ ⊢ F [conv↑] F′ ^ [ ! , ι l ] →
Γ ⊢ e ∷ Empty lEmpty ^ [ % , ι lEmpty ] →
Γ ⊢ e' ∷ Empty lEmpty ^ [ % , ι lEmpty ] →
Γ ⊢ Emptyrec l lEmpty F e ~ Emptyrec l lEmpty F′ e' ∷ F ^ [ ! , ι l ]
~-Emptyrec {e = e} {e' = e'} x ⊢e ⊢e' =
let k~l′ = %~↑ ⊢e ⊢e'
⊢F , _ = syntacticEq (soundnessConv↑ x)
in ↑ (refl ⊢F) (Emptyrec-cong′ x k~l′)
~-IdCong : ∀ {A A' : Term} {l : Level} {t t' u u' : Term} {Γ : Con Term} →
Γ ⊢ A ~ A' ∷ Univ ! l ^ [ ! , next l ] →
Γ ⊢ t [conv↑] t' ∷ A ^ ι l →
Γ ⊢ u [conv↑] u' ∷ A ^ ι l →
Γ ⊢ Id A t u ~ Id A' t' u' ∷ SProp l ^ [ ! , next l ]
~-IdCong (↑ A≡B (~↑! x)) t~t' u~u' =
let ⊢Γ = wfEqTerm (soundnessConv↑Term t~t')
_ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
A~A′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-cong A~A′ t~t' u~u'))
~-Idℕ : ∀ {t t' u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ u [genconv↑] u' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ Id ℕ t u ~ Id ℕ t' u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-Idℕ ⊢Γ (↑ A≡B (~↑! x)) u~u' =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕ t~t′ u~u'))
~-Idℕ0 : ∀ {u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ Id ℕ zero u ~ Id ℕ zero u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-Idℕ0 ⊢Γ (↑ A≡B (~↑! x)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕ0 t~t′))
~-IdℕS : ∀ {t t' u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ Id ℕ (suc t) u ~ Id ℕ (suc t') u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-IdℕS ⊢Γ X (↑ A≡B (~↑! x)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕS X t~t′))
~-IdU : ∀ {t t' u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t ~ t' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ u [genconv↑] u' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) t' u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdU ⊢Γ (↑ A≡B (~↑! x)) X =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-U t~t′ X))
~-IdUℕ : ∀ {u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) ℕ u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdUℕ ⊢Γ (↑ A≡B (~↑! x)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-Uℕ t~t′))
~-IdUΠ : ∀ {A : Term} {rA : Relevance} {B A' B' u u' : Term}
{Γ : Con Term} →
Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~
Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰) u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdUΠ X (↑ A≡B (~↑! x)) =
let ⊢Γ = wfEqTerm (soundnessConv↑Term X)
_ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-UΠ X t~t′))
~-castcong : ∀ {A A' B B' e e' t t' : Term} {Γ : Con Term} →
Γ ⊢ A ~ A' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B [genconv↑] B' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ A ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) A B ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) A' B' ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ A B e t ~ cast ⁰ A' B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castcong (↑ A≡B (~↑! x)) X Y ⊢e ⊢e' =
let _ , ⊢B , _ = syntacticEqTerm (soundnessConv↑Term X)
_ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (univ ⊢B)) (~↑! (cast-cong t~t′ X Y ⊢e ⊢e'))
~-castℕ : ∀ {B B' e e' t t' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) ℕ B ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) ℕ B' ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ ℕ B e t ~ cast ⁰ ℕ B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castℕ ⊢Γ (↑ A≡B (~↑! x)) X ⊢e ⊢e' =
let _ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
_ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)
in ↑ (refl (univ ⊢B)) (~↑! (cast-ℕ t~t′ X ⊢e ⊢e'))
~-castℕℕ : ∀ {e e' t t' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]
~-castℕℕ ⊢Γ (↑ A≡B (~↑! x)) ⊢e ⊢e' =
let _ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
_ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)
in ↑ (refl (univ (ℕⱼ ⊢Γ))) (~↑! (cast-ℕℕ t~t′ ⊢e ⊢e'))
~-castΠ : ∀ {A A' : Term} {rA : Relevance} {P P' B B' e e' t t' : Term}
{Γ : Con Term} →
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) B' ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B e t ~ cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castΠ X (↑ A≡B (~↑! x)) Y ⊢e ⊢e' =
let _ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
_ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)
in ↑ (refl (univ ⊢B)) (~↑! (cast-Π X t~t′ Y ⊢e ⊢e'))
~-castℕΠ : ∀ {A A' : Term} {rA : Relevance} {P P' e e' t t' : Term}
{Γ : Con Term} →
Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ rA , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) e' t' ∷
Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castℕΠ ⊢A ⊢P X Y ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢A ▹ ⊢P))) (~↑! (cast-ℕΠ X Y ⊢e ⊢e'))
~-castΠℕ : ∀ {A A' : Term} {rA : Relevance} {P P' e e' t t' : Term}
{Γ : Con Term} →
Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ rA , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰
∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ e t ~
cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]
~-castΠℕ ⊢A ⊢P X Y ⊢e ⊢e' = ↑ (refl (univ (ℕⱼ (wfTerm ⊢A)))) (~↑! (cast-Πℕ X Y ⊢e ⊢e'))
~-castΠΠ%! : ∀ {A A' P P' B B' Q Q' e e' t t' : Term} {Γ : Con Term} →
Γ ⊢ A ∷ Univ % ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ % , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B ∷ Univ ! ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ B ^ [ ! , ι ⁰ ]) ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ [genconv↑] Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~
cast ⁰ (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castΠΠ%! ⊢A ⊢P X ⊢B ⊢Q Y t~t' ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢B ▹ ⊢Q)))
(~↑! (cast-ΠΠ%! X Y t~t' ⊢e ⊢e'))
~-castΠΠ!% : ∀ {A A' P P' B B' Q Q' e e' t t' : Term} {Γ : Con Term} →
Γ ⊢ A ∷ Univ ! ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ ! , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B ∷ Univ % ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ B ^ [ % , ι ⁰ ]) ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ [genconv↑] Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~
cast ⁰ (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castΠΠ!% ⊢A ⊢P X ⊢B ⊢Q Y t~t' ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢B ▹ ⊢Q)))
(~↑! (cast-ΠΠ!% X Y t~t' ⊢e ⊢e'))
~-sym : {k l A : Term} {r : TypeInfo} {Γ : Con Term} → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ k ∷ A ^ r
~-sym (↑ A≡B x) =
let ⊢Γ = wfEq A≡B
B , A≡B′ , l~k = sym~↑ (reflConEq ⊢Γ) x
in ↑ (trans A≡B A≡B′) l~k
~-trans : {k l m A : Term} {r : TypeInfo} {Γ : Con Term}
→ Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ m ∷ A ^ r
→ Γ ⊢ k ~ m ∷ A ^ r
~-trans (↑ x (~↑! x₁)) (↑ x₂ (~↑! x₃)) =
let ⊢Γ = wfEq x
k~m , _ = trans~↑! PE.refl (reflConEq ⊢Γ) x₁ x₃
in ↑ x (~↑! k~m)
~-trans (↑ x (~↑% x₁)) (↑ x₂ (~↑% x₃)) =
let ⊢Γ = wfEq x
k~m = trans~↑% (reflConEq ⊢Γ) x₁ (conv~↑% x₃ (trans (sym x₂) x))
in ↑ x (~↑% k~m)
~-wk : {k l A : Term} {r : TypeInfo} {ρ : Wk} {Γ Δ : Con Term} →
ρ ∷ Δ ⊆ Γ →
⊢ Δ → Γ ⊢ k ~ l ∷ A ^ r → Δ ⊢ wk ρ k ~ wk ρ l ∷ wk ρ A ^ r
~-wk x x₁ (↑ x₂ x₃) = ↑ (wkEq x x₁ x₂) (wk~↑ x x₁ x₃)
~-conv : {k l A B : Term} {r : TypeInfo} {Γ : Con Term} →
Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ∷ B ^ r
~-conv (↑ x x₁) x₂ = ↑ (trans (sym x₂) x) x₁
~-to-conv : {k l A : Term} {Γ : Con Term} {r : TypeInfo} →
Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ k [genconv↑] l ∷ A ^ r
~-to-conv {r = [ ! , ll ]} (↑ x x₁) = convConvTerm (lift~toConv↑ x₁) (sym x)
~-to-conv {r = [ % , ll ]} (↑ x (~↑% x₁)) = conv~↑% x₁ (sym x)
un-univConv : ∀ {A B : Term} {r : Relevance} {l : Level} {Γ : Con Term} →
Γ ⊢ A [conv↑] B ^ [ r , ι l ] →
Γ ⊢ A [conv↑] B ∷ Univ r l ^ next l
un-univConv {A} {B} {r} {l} ([↑] A′ B′ D D′ whnfA′ whnfB′ (univ x)) =
let ⊢Γ = wfEqTerm (soundnessConv↓Term x)
in [↑]ₜ (Univ r l) A′ B′ (id (Ugenⱼ ⊢Γ)) (un-univ⇒* D) (un-univ⇒* D′) Uₙ whnfA′ whnfB′ x
Πₜ-cong : ∀ {F G H E rF rG lF lG lΠ Γ}
→ lF ≤ lΠ
→ lG ≤ lΠ
→ Γ ⊢ F ^ [ rF , ι lF ]
→ Γ ⊢ F [conv↑] H ∷ Univ rF lF ^ next lF
→ Γ ∙ F ^ [ rF , ι lF ] ⊢ G [conv↑] E ∷ Univ rG lG ^ next lG
→ Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ [conv↑] Π H ^ rF ° lF ▹ E ° lG ° lΠ ∷ Univ rG lΠ ^ next lΠ
Πₜ-cong lF< lG< x x₁ x₂ = liftConvTerm (Π-cong PE.refl PE.refl PE.refl PE.refl lF< lG< x x₁ x₂)
~-irrelevance : {k l A : Term} {Γ : Con Term} {ll : TypeLevel}
→ Γ ⊢ k ∷ A ^ [ % , ll ]
→ Γ ⊢ l ∷ A ^ [ % , ll ]
→ Γ ⊢ k ~ l ∷ A ^ [ % , ll ]
~-irrelevance ⊢k ⊢l =
let X = ~↑% (%~↑ ⊢k ⊢l)
⊢A = syntacticTerm ⊢k
in ↑ (refl ⊢A) X
soundnessgenConv : ∀ {a b A r Γ} → Γ ⊢ a [genconv↑] b ∷ A ^ r → Γ ⊢ a ≡ b ∷ A ^ r
soundnessgenConv {r = [ ! , l ]} = soundnessConv↑Term
soundnessgenConv {r = [ % , l ]} x = proj₂ (proj₂ (soundness~↑% x))
symgenConv : ∀ {t u A r Γ} → Γ ⊢ t [genconv↑] u ∷ A ^ r → Γ ⊢ u [genconv↑] t ∷ A ^ r
symgenConv {r = [ ! , l ]} = symConvTerm
symgenConv {r = [ % , l ]} t<>u = let ⊢Γ = wfEqTerm (proj₂ (proj₂ (soundness~↑% t<>u)))
in sym~↑% (reflConEq ⊢Γ) t<>u
wkgenConv↑Term : ∀ {ρ t u A Γ r Δ} ([ρ] : ρ ∷ Δ ⊆ Γ) → ⊢ Δ
→ Γ ⊢ t [genconv↑] u ∷ A ^ r
→ Δ ⊢ wk ρ t [genconv↑] wk ρ u ∷ wk ρ A ^ r
wkgenConv↑Term {r = [ ! , l ]} = wkConv↑Term
wkgenConv↑Term {r = [ % , l ]} = wk~↑%
convgenconv : ∀ {t u A B : Term} {r : TypeInfo} {Γ : Con Term} →
Γ ⊢ t [genconv↑] u ∷ A ^ r →
Γ ⊢ A ≡ B ^ r → Γ ⊢ t [genconv↑] u ∷ B ^ r
convgenconv {r = [ ! , l ]} = convConvTerm
convgenconv {r = [ % , l ]} = conv~↑%
transgenConv : ∀ {t u v A : Term} {r : TypeInfo} {Γ : Con Term} →
Γ ⊢ t [genconv↑] u ∷ A ^ r →
Γ ⊢ u [genconv↑] v ∷ A ^ r → Γ ⊢ t [genconv↑] v ∷ A ^ r
transgenConv {r = [ ! , l ]} = transConvTerm
transgenConv {r = [ % , l ]} = trans~↑!Term
-- Algorithmic equality instance of the generic equality relation.
instance eqRelInstance : EqRelSet
eqRelInstance = eqRel _⊢_[conv↑]_^_ _⊢_[genconv↑]_∷_^_ _⊢_~_∷_^_
~-to-conv soundnessConv↑ soundnessgenConv
univConv↑ un-univConv
symConv symgenConv ~-sym
transConv transgenConv ~-trans
convgenconv ~-conv
wkConv↑ wkgenConv↑Term ~-wk
reductionConv↑ reductionConv↑Term
(liftConv ∘ᶠ (U-refl PE.refl)) ( liftConvTerm ∘ᶠ (U-refl PE.refl))
(liftConvTerm ∘ᶠ ℕ-refl)
(liftConvTerm ∘ᶠ (Empty-refl PE.refl))
Πₜ-cong
(λ x x₁ x₂ → liftConvTerm (∃-cong PE.refl x x₁ x₂))
(liftConvTerm ∘ᶠ zero-refl)
(liftConvTerm ∘ᶠ suc-cong)
(λ l< l<' x x₁ x₂ x₃ x₄ x₅ → liftConvTerm (η-eq l< l<' x x₁ x₂ x₃ x₄ x₅))
~-var ~-app ~-natrec ~-Emptyrec
~-IdCong ~-Idℕ ~-Idℕ0 ~-IdℕS ~-IdU ~-IdUℕ ~-IdUΠ
~-castcong ~-castℕ ~-castℕℕ ~-castΠ ~-castℕΠ ~-castΠℕ ~-castΠΠ%! ~-castΠΠ!%
~-irrelevance
| 45.425581
| 116
| 0.410638
|
1872a9c5ed4ff860e6507e3be921b3726159c928
| 8,728
|
agda
|
Agda
|
Cubical/Functions/Logic.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Logic.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Logic.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
-- Various functions for manipulating hProps.
--
-- This file used to be part of Foundations, but it turned out to be
-- not very useful so moved here. Feel free to upstream content.
--
-- Note that it is often a bad idea to use hProp instead of having the
-- isProp proof separate. The reason is that Agda can rarely infer
-- isProp proofs making it easier to just give them explicitly instead
-- of having them bundled up with the type.
--
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Functions.Logic where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Function
open import Cubical.Foundations.Univalence using (hPropExt)
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sum as ⊎ using (_⊎_)
open import Cubical.Data.Unit
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as PropTrunc
open import Cubical.Relation.Nullary hiding (¬_)
--------------------------------------------------------------------------------
-- The type hProp of mere propositions
-- the definition hProp is given in Foundations.HLevels
-- hProp ℓ = Σ (Type ℓ) isProp
private
variable
ℓ ℓ' ℓ'' : Level
P Q R : hProp ℓ
A B C : Type ℓ
infix 10 ¬_
infixr 8 _⊔_
infixr 8 _⊔′_
infixr 8 _⊓_
infixr 8 _⊓′_
infixr 6 _⇒_
infixr 4 _⇔_
infix 30 _≡ₚ_
infix 30 _≢ₚ_
infix 2 ∃[]-syntax
infix 2 ∃[∶]-syntax
infix 2 ∀[∶]-syntax
infix 2 ∀[]-syntax
infix 2 ⇒∶_⇐∶_
infix 2 ⇐∶_⇒∶_
∥_∥ₚ : Type ℓ → hProp ℓ
∥ A ∥ₚ = ∥ A ∥ , propTruncIsProp
_≡ₚ_ : (x y : A) → hProp _
x ≡ₚ y = ∥ x ≡ y ∥ₚ
hProp≡ : ⟨ P ⟩ ≡ ⟨ Q ⟩ → P ≡ Q
hProp≡ = TypeOfHLevel≡ 1
isProp⟨⟩ : (A : hProp ℓ) → isProp ⟨ A ⟩
isProp⟨⟩ = snd
--------------------------------------------------------------------------------
-- Logical implication of mere propositions
_⇒_ : (A : hProp ℓ) → (B : hProp ℓ') → hProp _
A ⇒ B = (⟨ A ⟩ → ⟨ B ⟩) , isPropΠ λ _ → isProp⟨⟩ B
⇔toPath : ⟨ P ⇒ Q ⟩ → ⟨ Q ⇒ P ⟩ → P ≡ Q
⇔toPath {P = P} {Q = Q} P⇒Q Q⇒P = hProp≡ (hPropExt (isProp⟨⟩ P) (isProp⟨⟩ Q) P⇒Q Q⇒P)
pathTo⇒ : P ≡ Q → ⟨ P ⇒ Q ⟩
pathTo⇒ p x = subst fst p x
pathTo⇐ : P ≡ Q → ⟨ Q ⇒ P ⟩
pathTo⇐ p x = subst fst (sym p) x
substₚ : {x y : A} (B : A → hProp ℓ) → ⟨ x ≡ₚ y ⇒ B x ⇒ B y ⟩
substₚ {x = x} {y = y} B = PropTrunc.elim (λ _ → isPropΠ λ _ → isProp⟨⟩ (B y)) (subst (fst ∘ B))
--------------------------------------------------------------------------------
-- Mixfix notations for ⇔-toPath
-- see ⊔-identityˡ and ⊔-identityʳ for the difference
⇒∶_⇐∶_ : ⟨ P ⇒ Q ⟩ → ⟨ Q ⇒ P ⟩ → P ≡ Q
⇒∶_⇐∶_ = ⇔toPath
⇐∶_⇒∶_ : ⟨ Q ⇒ P ⟩ → ⟨ P ⇒ Q ⟩ → P ≡ Q
⇐∶ g ⇒∶ f = ⇔toPath f g
--------------------------------------------------------------------------------
-- False and True
⊥ : hProp _
⊥ = ⊥.⊥ , λ ()
⊤ : hProp _
⊤ = Unit , (λ _ _ _ → tt)
--------------------------------------------------------------------------------
-- Pseudo-complement of mere propositions
¬_ : hProp ℓ → hProp _
¬ A = (⟨ A ⟩ → ⊥.⊥) , isPropΠ λ _ → ⊥.isProp⊥
_≢ₚ_ : (x y : A) → hProp _
x ≢ₚ y = ¬ x ≡ₚ y
--------------------------------------------------------------------------------
-- Disjunction of mere propositions
_⊔′_ : Type ℓ → Type ℓ' → Type _
A ⊔′ B = ∥ A ⊎ B ∥
_⊔_ : hProp ℓ → hProp ℓ' → hProp _
P ⊔ Q = ∥ ⟨ P ⟩ ⊎ ⟨ Q ⟩ ∥ₚ
inl : A → A ⊔′ B
inl x = ∣ ⊎.inl x ∣
inr : B → A ⊔′ B
inr x = ∣ ⊎.inr x ∣
⊔-elim : (P : hProp ℓ) (Q : hProp ℓ') (R : ⟨ P ⊔ Q ⟩ → hProp ℓ'')
→ (∀ x → ⟨ R (inl x) ⟩) → (∀ y → ⟨ R (inr y) ⟩) → (∀ z → ⟨ R z ⟩)
⊔-elim _ _ R P⇒R Q⇒R = PropTrunc.elim (snd ∘ R) (⊎.elim P⇒R Q⇒R)
--------------------------------------------------------------------------------
-- Conjunction of mere propositions
_⊓′_ : Type ℓ → Type ℓ' → Type _
A ⊓′ B = A × B
_⊓_ : hProp ℓ → hProp ℓ' → hProp _
A ⊓ B = ⟨ A ⟩ ⊓′ ⟨ B ⟩ , isOfHLevelΣ 1 (isProp⟨⟩ A) (\ _ → isProp⟨⟩ B)
⊓-intro : (P : hProp ℓ) (Q : ⟨ P ⟩ → hProp ℓ') (R : ⟨ P ⟩ → hProp ℓ'')
→ (∀ a → ⟨ Q a ⟩) → (∀ a → ⟨ R a ⟩) → (∀ (a : ⟨ P ⟩) → ⟨ Q a ⊓ R a ⟩ )
⊓-intro _ _ _ = \ f g a → f a , g a
--------------------------------------------------------------------------------
-- Logical bi-implication of mere propositions
_⇔_ : hProp ℓ → hProp ℓ' → hProp _
A ⇔ B = (A ⇒ B) ⊓ (B ⇒ A)
--------------------------------------------------------------------------------
-- Universal Quantifier
∀[∶]-syntax : (A → hProp ℓ) → hProp _
∀[∶]-syntax {A = A} P = (∀ x → ⟨ P x ⟩) , isPropΠ (isProp⟨⟩ ∘ P)
∀[]-syntax : (A → hProp ℓ) → hProp _
∀[]-syntax {A = A} P = (∀ x → ⟨ P x ⟩) , isPropΠ (isProp⟨⟩ ∘ P)
syntax ∀[∶]-syntax {A = A} (λ a → P) = ∀[ a ∶ A ] P
syntax ∀[]-syntax (λ a → P) = ∀[ a ] P
--------------------------------------------------------------------------------
-- Existential Quantifier
∃[]-syntax : (A → hProp ℓ) → hProp _
∃[]-syntax {A = A} P = ∥ Σ A (⟨_⟩ ∘ P) ∥ₚ
∃[∶]-syntax : (A → hProp ℓ) → hProp _
∃[∶]-syntax {A = A} P = ∥ Σ A (⟨_⟩ ∘ P) ∥ₚ
syntax ∃[∶]-syntax {A = A} (λ x → P) = ∃[ x ∶ A ] P
syntax ∃[]-syntax (λ x → P) = ∃[ x ] P
--------------------------------------------------------------------------------
-- Decidable mere proposition
Decₚ : (P : hProp ℓ) → hProp ℓ
Decₚ P = Dec ⟨ P ⟩ , isPropDec (isProp⟨⟩ P)
--------------------------------------------------------------------------------
-- Negation commutes with truncation
∥¬A∥≡¬∥A∥ : (A : Type ℓ) → ∥ (A → ⊥.⊥) ∥ₚ ≡ (¬ ∥ A ∥ₚ)
∥¬A∥≡¬∥A∥ _ =
⇒∶ (λ ¬A A → PropTrunc.elim (λ _ → ⊥.isProp⊥)
(PropTrunc.elim (λ _ → isPropΠ λ _ → ⊥.isProp⊥) (λ ¬p p → ¬p p) ¬A) A)
⇐∶ λ ¬p → ∣ (λ p → ¬p ∣ p ∣) ∣
--------------------------------------------------------------------------------
-- (hProp, ⊔, ⊥) is a bounded ⊔-semilattice
⊔-assoc : (P : hProp ℓ) (Q : hProp ℓ') (R : hProp ℓ'')
→ P ⊔ (Q ⊔ R) ≡ (P ⊔ Q) ⊔ R
⊔-assoc P Q R =
⇒∶ ⊔-elim P (Q ⊔ R) (λ _ → (P ⊔ Q) ⊔ R)
(inl ∘ inl)
(⊔-elim Q R (λ _ → (P ⊔ Q) ⊔ R) (inl ∘ inr) inr)
⇐∶ assoc2
where
assoc2 : (A ⊔′ B) ⊔′ C → A ⊔′ (B ⊔′ C)
assoc2 ∣ ⊎.inr a ∣ = ∣ ⊎.inr ∣ ⊎.inr a ∣ ∣
assoc2 ∣ ⊎.inl ∣ ⊎.inr b ∣ ∣ = ∣ ⊎.inr ∣ ⊎.inl b ∣ ∣
assoc2 ∣ ⊎.inl ∣ ⊎.inl c ∣ ∣ = ∣ ⊎.inl c ∣
assoc2 ∣ ⊎.inl (squash x y i) ∣ = propTruncIsProp (assoc2 ∣ ⊎.inl x ∣) (assoc2 ∣ ⊎.inl y ∣) i
assoc2 (squash x y i) = propTruncIsProp (assoc2 x) (assoc2 y) i
⊔-idem : (P : hProp ℓ) → P ⊔ P ≡ P
⊔-idem P =
⇒∶ (⊔-elim P P (\ _ → P) (\ x → x) (\ x → x))
⇐∶ inl
⊔-comm : (P : hProp ℓ) (Q : hProp ℓ') → P ⊔ Q ≡ Q ⊔ P
⊔-comm P Q =
⇒∶ (⊔-elim P Q (\ _ → (Q ⊔ P)) inr inl)
⇐∶ (⊔-elim Q P (\ _ → (P ⊔ Q)) inr inl)
⊔-identityˡ : (P : hProp ℓ) → ⊥ ⊔ P ≡ P
⊔-identityˡ P =
⇒∶ (⊔-elim ⊥ P (λ _ → P) (λ ()) (λ x → x))
⇐∶ inr
⊔-identityʳ : (P : hProp ℓ) → P ⊔ ⊥ ≡ P
⊔-identityʳ P = ⇔toPath (⊔-elim P ⊥ (λ _ → P) (λ x → x) λ ()) inl
--------------------------------------------------------------------------------
-- (hProp, ⊓, ⊤) is a bounded ⊓-lattice
⊓-assoc : (P : hProp ℓ) (Q : hProp ℓ') (R : hProp ℓ'')
→ P ⊓ Q ⊓ R ≡ (P ⊓ Q) ⊓ R
⊓-assoc _ _ _ =
⇒∶ (λ {(x , (y , z)) → (x , y) , z})
⇐∶ (λ {((x , y) , z) → x , (y , z) })
⊓-comm : (P : hProp ℓ) (Q : hProp ℓ') → P ⊓ Q ≡ Q ⊓ P
⊓-comm _ _ = ⇔toPath (\ p → p .snd , p .fst) (\ p → p .snd , p .fst)
⊓-idem : (P : hProp ℓ) → P ⊓ P ≡ P
⊓-idem _ = ⇔toPath fst (λ x → x , x)
⊓-identityˡ : (P : hProp ℓ) → ⊤ ⊓ P ≡ P
⊓-identityˡ _ = ⇔toPath snd λ x → tt , x
⊓-identityʳ : (P : hProp ℓ) → P ⊓ ⊤ ≡ P
⊓-identityʳ _ = ⇔toPath fst λ x → x , tt
--------------------------------------------------------------------------------
-- Distributive laws
⇒-⊓-distrib : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'')
→ P ⇒ (Q ⊓ R) ≡ (P ⇒ Q) ⊓ (P ⇒ R)
⇒-⊓-distrib _ _ _ =
⇒∶ (λ f → (fst ∘ f) , (snd ∘ f))
⇐∶ (λ { (f , g) x → f x , g x})
⊓-⊔-distribˡ : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'')
→ P ⊓ (Q ⊔ R) ≡ (P ⊓ Q) ⊔ (P ⊓ R)
⊓-⊔-distribˡ P Q R =
⇒∶ (λ { (x , a) → ⊔-elim Q R (λ _ → (P ⊓ Q) ⊔ (P ⊓ R))
(λ y → ∣ ⊎.inl (x , y) ∣ )
(λ z → ∣ ⊎.inr (x , z) ∣ ) a })
⇐∶ ⊔-elim (P ⊓ Q) (P ⊓ R) (λ _ → P ⊓ Q ⊔ R)
(λ y → fst y , inl (snd y))
(λ z → fst z , inr (snd z))
⊔-⊓-distribˡ : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'')
→ P ⊔ (Q ⊓ R) ≡ (P ⊔ Q) ⊓ (P ⊔ R)
⊔-⊓-distribˡ P Q R =
⇒∶ ⊔-elim P (Q ⊓ R) (λ _ → (P ⊔ Q) ⊓ (P ⊔ R) )
(\ x → inl x , inl x) (\ p → inr (p .fst) , inr (p .snd))
⇐∶ (λ { (x , y) → ⊔-elim P R (λ _ → P ⊔ Q ⊓ R) inl
(λ z → ⊔-elim P Q (λ _ → P ⊔ Q ⊓ R) inl (λ y → inr (y , z)) x) y })
⊓-∀-distrib : (P : A → hProp ℓ) (Q : A → hProp ℓ')
→ (∀[ a ∶ A ] P a) ⊓ (∀[ a ∶ A ] Q a) ≡ (∀[ a ∶ A ] (P a ⊓ Q a))
⊓-∀-distrib P Q =
⇒∶ (λ {(p , q) a → p a , q a})
⇐∶ λ pq → (fst ∘ pq ) , (snd ∘ pq)
| 30.305556
| 97
| 0.421173
|
20038931de22af6fa5969c81c558b28ec514bd53
| 13,903
|
agda
|
Agda
|
src/fot/Agsy/McCarthy91/Arithmetic.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/Agsy/McCarthy91/Arithmetic.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/Agsy/McCarthy91/Arithmetic.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Testing Agsy arithmetic properties used by the McCarthy 91 function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Tested with the development version of the Agda standard library on
-- 02 February 2012.
module Agsy.McCarthy91.Arithmetic where
open import Data.Nat
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------------
91≡[100+11∸10]∸10 : (100 + 11 ∸ 10) ∸ 10 ≡ 91
91≡[100+11∸10]∸10 = refl
20>19 : 20 > 19 -- via Agsy
20>19 = s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))))))))))))))))
50>49 : 50 > 49 -- via Agsy {-t 30}
50>49 = s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
z≤n)))))))))))))))))))))))))))))))))))))))))))))))))
75>74 : 75 > 74 -- via Agsy {-t 180}
75>74 = s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
z≤n))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
101>100 : 101 > 100 -- via Agsy {-t 600}
101>100 = s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
(s≤s
z≤n))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
| 51.302583
| 213
| 0.067324
|
41e6912b0c4054e9580615d48fd887dd9f411b0d
| 776
|
agda
|
Agda
|
Lang/Instance.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Lang/Instance.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Lang/Instance.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Lang.Instance where
import Lvl
open import Type
private variable ℓ : Lvl.Level
private variable T X Y Z : Type{ℓ}
-- Infers/resolves/(searches for) an instance/proof of the specified type/statement
resolve : (T : Type{ℓ}) → ⦃ _ : T ⦄ → T
resolve (_) ⦃ x ⦄ = x
-- Infers/resolves/(searches for) an instance/proof of an inferred type/statement
infer : ⦃ _ : T ⦄ → T
infer ⦃ x ⦄ = x
inst-fn : (X → Y) → (⦃ inst : X ⦄ → Y)
inst-fn P ⦃ x ⦄ = P(x)
inst-fn₂ : (X → Y → Z) → (⦃ inst₁ : X ⦄ → ⦃ inst₂ : Y ⦄ → Z)
inst-fn₂ P ⦃ x ⦄ ⦃ y ⦄ = P(x)(y)
inst-fnᵢ : ({_ : X} → Y → Z) → ({_ : X} → ⦃ _ : Y ⦄ → Z)
inst-fnᵢ P {x} ⦃ y ⦄ = P{x}(y)
impl-to-expl : ({ _ : X} → Y) → (X → Y)
impl-to-expl f(x) = f{x}
expl-to-impl : (X → Y) → ({ _ : X} → Y)
expl-to-impl f{x} = f(x)
| 25.032258
| 83
| 0.533505
|
dc910eb4db889c24ee89fe92aa902bab5e02cf1d
| 1,373
|
agda
|
Agda
|
LibraBFT/Yasm/Yasm.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Yasm/Yasm.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Yasm/Yasm.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Base as LYB
-- This module provides a single import for all Yasm modules
module LibraBFT.Yasm.Yasm
(ℓ-EC : Level)
(EpochConfig : Set ℓ-EC)
(epochId : EpochConfig → EpochId)
(authorsN : EpochConfig → ℕ)
(parms : LYB.SystemParameters ℓ-EC EpochConfig epochId authorsN)
(senderPKOK : (ec : EpochConfig) → PK → LYB.SystemParameters.PeerId parms → Set)
where
open LYB.SystemParameters parms
open import LibraBFT.Yasm.AvailableEpochs PeerId ℓ-EC EpochConfig epochId authorsN
using (AvailableEpochs) renaming (lookup' to EC-lookup; lookup'' to EC-lookup') public
open import LibraBFT.Yasm.Base ℓ-EC EpochConfig epochId authorsN public
open import LibraBFT.Yasm.System ℓ-EC EpochConfig epochId authorsN parms public
open import LibraBFT.Yasm.Properties ℓ-EC EpochConfig epochId authorsN parms senderPKOK public
open import Util.FunctionOverride PeerId _≟PeerId_ public
| 49.035714
| 111
| 0.708667
|
0eddd9fe0565b854e53c1f0ab82a46a20a5936ae
| 3,027
|
agda
|
Agda
|
prototyping/Properties/Step.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | 1
|
2022-02-11T21:30:17.000Z
|
2022-02-11T21:30:17.000Z
|
prototyping/Properties/Step.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | null | null | null |
prototyping/Properties/Step.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | null | null | null |
module Properties.Step where
open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.Maybe using (just; nothing)
open import Luau.Heap using (Heap; lookup; alloc; ok; function_⟨_⟩_end)
open import Luau.Syntax using (Block; Expr; nil; var; addr; function⟨_⟩_end; block_is_end; _$_; local_←_; function_⟨_⟩_end; return; done; _∙_)
open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; app ; beta; function; block; return; done; local; subst)
open import Luau.RuntimeError using (RuntimeErrorᴱ; RuntimeErrorᴮ; NilIsNotAFunction; UnboundVariable; SEGV; app; block; local; return)
open import Luau.Substitution using (_[_/_]ᴮ)
open import Luau.Value using (nil; addr; val)
open import Properties.Remember using (remember; _,_)
data StepResultᴮ (H : Heap) (B : Block) : Set
data StepResultᴱ (H : Heap) (M : Expr) : Set
data StepResultᴮ H B where
step : ∀ H′ B′ → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → StepResultᴮ H B
return : ∀ V {B′} → (B ≡ (return (val V) ∙ B′)) → StepResultᴮ H B
done : (B ≡ done) → StepResultᴮ H B
error : (RuntimeErrorᴮ H B) → StepResultᴮ H B
data StepResultᴱ H M where
step : ∀ H′ M′ → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → StepResultᴱ H M
value : ∀ V → (M ≡ val V) → StepResultᴱ H M
error : (RuntimeErrorᴱ H M) → StepResultᴱ H M
stepᴱ : ∀ H M → StepResultᴱ H M
stepᴮ : ∀ H B → StepResultᴮ H B
stepᴱ H nil = value nil refl
stepᴱ H (var x) = error (UnboundVariable x)
stepᴱ H (addr a) = value (addr a) refl
stepᴱ H (M $ N) with stepᴱ H M
stepᴱ H (M $ N) | step H′ M′ D = step H′ (M′ $ N) (app D)
stepᴱ H (nil $ N) | value nil refl = error NilIsNotAFunction
stepᴱ H (addr a $ N) | value (addr a) refl with remember (lookup H a)
stepᴱ H (addr a $ N) | value (addr a) refl | (nothing , p) = error (app (SEGV a p))
stepᴱ H (addr a $ N) | value (addr a) refl | (just(function f ⟨ x ⟩ B end) , p) = step H (block f is local x ← N ∙ B end) (beta p)
stepᴱ H (M $ N) | error E = error (app E)
stepᴱ H (function⟨ x ⟩ B end) with alloc H (function "anon" ⟨ x ⟩ B end)
stepᴱ H (function⟨ x ⟩ B end) | ok a H′ p = step H′ (addr a) (function p)
stepᴱ H (block b is B end) with stepᴮ H B
stepᴱ H (block b is B end) | step H′ B′ D = step H′ (block b is B′ end) (block D)
stepᴱ H (block b is (return _ ∙ B′) end) | return V refl = step H (val V) return
stepᴱ H (block b is done end) | done refl = step H nil done
stepᴱ H (block b is B end) | error E = error (block b E)
stepᴮ H (function f ⟨ x ⟩ C end ∙ B) with alloc H (function f ⟨ x ⟩ C end)
stepᴮ H (function f ⟨ x ⟩ C end ∙ B) | ok a H′ p = step H′ (B [ addr a / f ]ᴮ) (function p)
stepᴮ H (local x ← M ∙ B) with stepᴱ H M
stepᴮ H (local x ← M ∙ B) | step H′ M′ D = step H′ (local x ← M′ ∙ B) (local D)
stepᴮ H (local x ← _ ∙ B) | value V refl = step H (B [ V / x ]ᴮ) subst
stepᴮ H (local x ← M ∙ B) | error E = error (local x E)
stepᴮ H (return M ∙ B) with stepᴱ H M
stepᴮ H (return M ∙ B) | step H′ M′ D = step H′ (return M′ ∙ B) (return D)
stepᴮ H (return _ ∙ B) | value V refl = return V refl
stepᴮ H (return M ∙ B) | error E = error (return E)
stepᴮ H done = done refl
| 51.305085
| 142
| 0.635282
|
290d1ebeadc3a03fd0778c9e50239eee7e8a5e96
| 1,829
|
agda
|
Agda
|
src/Category/Profunctor.agda
|
crisoagf/agda-optics
|
308afeeaa905870dbf1a995fa82e8825dfaf2d74
|
[
"BSD-3-Clause"
] | null | null | null |
src/Category/Profunctor.agda
|
crisoagf/agda-optics
|
308afeeaa905870dbf1a995fa82e8825dfaf2d74
|
[
"BSD-3-Clause"
] | null | null | null |
src/Category/Profunctor.agda
|
crisoagf/agda-optics
|
308afeeaa905870dbf1a995fa82e8825dfaf2d74
|
[
"BSD-3-Clause"
] | null | null | null |
module Category.Profunctor where
open import Agda.Primitive using (Level; _⊔_; lsuc)
open import Data.Product using (_,_; _×_)
open import Function using (id)
open import Relation.Binary.PropositionalEquality using (_≡_)
Dimap : ∀ {a b} (p : Set a → Set a → Set b) → Set (lsuc a ⊔ b)
Lmap : ∀ {a b} (p : Set a → Set a → Set b) → Set (lsuc a ⊔ b)
Rmap : ∀ {a b} (p : Set a → Set a → Set b) → Set (lsuc a ⊔ b)
Dimap p = ∀ {x y z w} → (f : x -> y) -> (h : z -> w) -> (g : p y z) → p x w
Lmap p = ∀ {x y w} → (f : x -> y) -> (g : p y w) → p x w
Rmap p = ∀ {x z w} → (h : z -> w) -> (g : p x z) → p x w
record ProfunctorImp {a b : Level} (p : Set a → Set a → Set b) : Set (lsuc (a ⊔ b)) where
field
dimap : Dimap p
lmap : Lmap p
rmap : Rmap p
dimapFromLmapRmap : ∀ {a b} {p : Set a → Set a → Set b} (lmap : Lmap p) (rmap : Rmap p) → Dimap p
dimapFromLmapRmap lmap rmap f h g = rmap h (lmap f g)
lmapRmapFromDimap : ∀ {a b} {p : Set a → Set a → Set b} (dimap : Dimap p) → (Lmap p × Rmap p)
lmapRmapFromDimap dimap = (λ f → dimap f id) , dimap id
module Profunctor {a b : Level} {p : Set a → Set a → Set b} (isProfunctor : ProfunctorImp p) where
open ProfunctorImp isProfunctor public
record LawfulProfunctorImp {a b} {p : Set a → Set a → Set b} (isProfunctor : ProfunctorImp p) : Set (lsuc (a ⊔ b)) where
open Profunctor isProfunctor
field
lmapId : ∀ {a b} {g : p a b} → lmap id g ≡ g
rmapId : ∀ {a b} {g : p a b} → rmap id g ≡ g
dimapLmapRmap : ∀ {a b c d} {f : a → b} {g : p b c} {h : c → d} → dimap f h g ≡ lmap f (rmap h g)
module LawfulProfunctor {a b} {p : Set a → Set a → Set b} {isProfunctor : ProfunctorImp p} (isLawful : LawfulProfunctorImp isProfunctor) where
open Profunctor isProfunctor public
open LawfulProfunctorImp isLawful public
| 44.609756
| 142
| 0.583926
|
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.