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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
41288fc9e1b077fc458a78de43f0972e387be303
| 827
|
agda
|
Agda
|
notes/FOT/FOTC/Program/McCarthy91/WF-Relation/Induction/NonAcc/TerminationCheckIssue.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Program/McCarthy91/WF-Relation/Induction/NonAcc/TerminationCheckIssue.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Program/McCarthy91/WF-Relation/Induction/NonAcc/TerminationCheckIssue.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.McCarthy91.WF-Relation.Induction.NonAcc.TerminationCheckIssue
where
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
postulate someℕ : ℕ
{-# TERMINATING #-}
foo : ℕ → ℕ → ℕ
foo n zero = 10
foo zero (succ m) = foo zero someℕ
foo (succ n) (succ m) = foo n (succ m)
{-# TERMINATING #-}
bar : ℕ → ℕ → ℕ
bar n zero = 10
bar zero (succ m) = bar m someℕ
bar (succ n) (succ m) = bar n (succ m)
{-# TERMINATING #-}
foobar : ℕ → ℕ → ℕ
foobar n zero = 10
foobar zero (succ m) with someℕ
... | zero = 10
... | succ o = foobar m (succ o)
foobar (succ n) (succ m) = foobar n (succ m)
| 22.972222
| 85
| 0.563482
|
3d9b0414b3f7ba452b6e424a0663d16058b70067
| 169
|
agda
|
Agda
|
Tools/List.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Tools/List.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Tools/List.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
{-# OPTIONS --without-K --safe #-}
module Tools.List where
open import Data.List.Base public using (List; []; _∷_)
module L where
open import Data.List.Base public
| 18.777778
| 55
| 0.698225
|
1dae28e114ea3e1410b9547e941c525934905378
| 10,900
|
agda
|
Agda
|
core/lib/groups/Isomorphism.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/groups/Isomorphism.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/groups/Isomorphism.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.Equivalence2
open import lib.Function2
open import lib.NType2
open import lib.types.Group
open import lib.types.Pi
open import lib.types.Subtype
open import lib.types.Truncation
open import lib.groups.Homomorphism
open import lib.groups.SubgroupProp
module lib.groups.Isomorphism where
GroupStructureIso : ∀ {i j} {GEl : Type i} {HEl : Type j}
(GS : GroupStructure GEl) (HS : GroupStructure HEl) → Type (lmax i j)
GroupStructureIso GS HS = Σ (GroupStructureHom GS HS) (λ φ → is-equiv (GroupStructureHom.f φ))
infix 30 _≃ᴳˢ_ -- [ˢ] for structures
_≃ᴳˢ_ = GroupStructureIso
GroupIso : ∀ {i j} (G : Group i) (H : Group j) → Type (lmax i j)
GroupIso G H = Σ (G →ᴳ H) (λ φ → is-equiv (GroupHom.f φ))
infix 30 _≃ᴳ_
_≃ᴳ_ = GroupIso
≃ᴳˢ-to-≃ᴳ : ∀ {i j} {G : Group i} {H : Group j}
→ (Group.group-struct G ≃ᴳˢ Group.group-struct H) → (G ≃ᴳ H)
≃ᴳˢ-to-≃ᴳ (φ , φ-is-equiv) = →ᴳˢ-to-→ᴳ φ , φ-is-equiv
≃-to-≃ᴳ : ∀ {i j} {G : Group i} {H : Group j} (e : Group.El G ≃ Group.El H)
→ preserves-comp (Group.comp G) (Group.comp H) (–> e) → G ≃ᴳ H
≃-to-≃ᴳ (f , f-is-equiv) pres-comp = group-hom f pres-comp , f-is-equiv
≃-to-≃ᴳˢ : ∀ {i j} {GEl : Type i} {HEl : Type j}
{GS : GroupStructure GEl} {HS : GroupStructure HEl} (e : GEl ≃ HEl)
→ preserves-comp (GroupStructure.comp GS) (GroupStructure.comp HS) (–> e)
→ GS ≃ᴳˢ HS
≃-to-≃ᴳˢ (f , f-is-equiv) pres-comp = group-structure-hom f pres-comp , f-is-equiv
private
inverse-preserves-comp : ∀ {i j} {A : Type i} {B : Type j}
(A-comp : A → A → A) (B-comp : B → B → B) {f : A → B} (f-ie : is-equiv f)
→ preserves-comp A-comp B-comp f
→ preserves-comp B-comp A-comp (is-equiv.g f-ie)
inverse-preserves-comp Ac Bc ie pc b₁ b₂ = let open is-equiv ie in
ap2 (λ w₁ w₂ → g (Bc w₁ w₂)) (! (f-g b₁)) (! (f-g b₂))
∙ ! (ap g (pc (g b₁) (g b₂)))
∙ g-f (Ac (g b₁) (g b₂))
module GroupIso {i j} {G : Group i} {H : Group j} (iso : GroupIso G H) where
f-hom : G →ᴳ H
f-hom = fst iso
open GroupHom {G = G} {H = H} f-hom public
f-is-equiv : is-equiv f
f-is-equiv = snd iso
open is-equiv f-is-equiv public
f-equiv : Group.El G ≃ Group.El H
f-equiv = f , f-is-equiv
g-hom : H →ᴳ G
g-hom = group-hom g (inverse-preserves-comp (Group.comp G) (Group.comp H) f-is-equiv pres-comp)
g-is-equiv : is-equiv g
g-is-equiv = is-equiv-inverse f-is-equiv
g-equiv : Group.El H ≃ Group.El G
g-equiv = g , g-is-equiv
idiso : ∀ {i} (G : Group i) → (G ≃ᴳ G)
idiso G = idhom G , idf-is-equiv _
{- equality of isomomorphisms -}
abstract
group-hom=-to-iso= : ∀ {i j} {G : Group i} {H : Group j} {φ ψ : G ≃ᴳ H}
→ GroupIso.f-hom φ == GroupIso.f-hom ψ → φ == ψ
group-hom=-to-iso= = Subtype=-out (is-equiv-prop ∘sub GroupHom.f)
group-iso= : ∀ {i j} {G : Group i} {H : Group j} {φ ψ : G ≃ᴳ H}
→ GroupIso.f φ == GroupIso.f ψ → φ == ψ
group-iso= {H = H} p = group-hom=-to-iso= $ group-hom= p
{- compositions -}
infixr 80 _∘eᴳ_
_∘eᴳ_ : ∀ {i j k} {G : Group i} {H : Group j} {K : Group k}
→ H ≃ᴳ K → G ≃ᴳ H → G ≃ᴳ K
(φ₂ , ie₂) ∘eᴳ (φ₁ , ie₁) = (φ₂ ∘ᴳ φ₁ , ie₂ ∘ise ie₁)
infixr 10 _≃ᴳ⟨_⟩_
infix 15 _≃ᴳ∎
_≃ᴳ⟨_⟩_ : ∀ {i j k} (G : Group i) {H : Group j} {K : Group k}
→ G ≃ᴳ H → H ≃ᴳ K → G ≃ᴳ K
G ≃ᴳ⟨ e₁ ⟩ e₂ = e₂ ∘eᴳ e₁
_≃ᴳ∎ : ∀ {i} (G : Group i) → (G ≃ᴳ G)
_≃ᴳ∎ = idiso
infixl 120 _⁻¹ᴳ
_⁻¹ᴳ : ∀ {i j} {G : Group i} {H : Group j} → G ≃ᴳ H → H ≃ᴳ G
_⁻¹ᴳ {G = G} {H = H} (φ , ie) = GroupIso.g-hom (φ , ie) , is-equiv-inverse ie
{- mimicking notations for equivalences -}
–>ᴳ : ∀ {i j} {G : Group i} {H : Group j} → (G ≃ᴳ H) → (G →ᴳ H)
–>ᴳ = GroupIso.f-hom
<–ᴳ : ∀ {i j} {G : Group i} {H : Group j} → (G ≃ᴳ H) → (H →ᴳ G)
<–ᴳ = GroupIso.g-hom
{- univalence -}
module _ {i} {G H : Group i} (iso : GroupIso G H) where
private
module G = Group G
module H = Group H
open module φ = GroupIso {G = G} {H = H} iso
El= = ua f-equiv
private
ap3-lemma : ∀ {i j k l} {C : Type i} {D : C → Type j} {E : C → Type k}
{F : Type l} {c₁ c₂ : C} {d₁ : D c₁} {d₂ : D c₂} {e₁ : E c₁} {e₂ : E c₂}
(f : (c : C) → D c → E c → F) (p : c₁ == c₂)
→ (d₁ == d₂ [ D ↓ p ]) → (e₁ == e₂ [ E ↓ p ])
→ (f c₁ d₁ e₁ == f c₂ d₂ e₂)
ap3-lemma f idp idp idp = idp
ap3-lemma-El : ∀ {i} {G H : Group i}
(p : Group.El G == Group.El H)
(q : Group.El-level G == Group.El-level H [ _ ↓ p ])
(r : Group.group-struct G == Group.group-struct H [ _ ↓ p ])
→ ap Group.El (ap3-lemma group p q r) == p
ap3-lemma-El idp idp idp = idp
{- a homomorphism which is an equivalence gives a path between groups -}
abstract
uaᴳ : G == H
uaᴳ =
ap3-lemma group
El=
(prop-has-all-paths-↓ has-level-is-prop)
(↓-group-structure= (G.El-level) El= ident= inv= comp=)
where
ident= : G.ident == H.ident [ (λ C → C) ↓ El= ]
ident= = ↓-idf-ua-in _ pres-ident
inv= : G.inv == H.inv [ (λ C → C → C) ↓ El= ]
inv= =
↓-→-from-transp $ λ= λ a →
transport (λ C → C) El= (G.inv a)
=⟨ to-transp (↓-idf-ua-in _ idp) ⟩
f (G.inv a)
=⟨ pres-inv a ⟩
H.inv (f a)
=⟨ ap H.inv (! (to-transp (↓-idf-ua-in _ idp))) ⟩
H.inv (transport (λ C → C) El= a) =∎
comp=' : (a : G.El)
→ G.comp a == H.comp (f a) [ (λ C → C → C) ↓ El= ]
comp=' a =
↓-→-from-transp $ λ= λ b →
transport (λ C → C) El= (G.comp a b)
=⟨ to-transp (↓-idf-ua-in _ idp) ⟩
f (G.comp a b)
=⟨ pres-comp a b ⟩
H.comp (f a) (f b)
=⟨ ! (to-transp (↓-idf-ua-in _ idp))
|in-ctx (λ w → H.comp (f a) w) ⟩
H.comp (f a) (transport (λ C → C) El= b) =∎
comp= : G.comp == H.comp [ (λ C → C → C → C) ↓ El= ]
comp= =
↓-→-from-transp $ λ= λ a →
transport (λ C → C → C) El= (G.comp a)
=⟨ to-transp (comp=' a) ⟩
H.comp (f a)
=⟨ ! (to-transp (↓-idf-ua-in _ idp)) |in-ctx (λ w → H.comp w) ⟩
H.comp (transport (λ C → C) El= a) =∎
-- XXX This stretches the naming convention a little bit.
El=-β : ap Group.El uaᴳ == El=
El=-β = ap3-lemma-El El= _ _
{- homomorphism from equality of groups -}
abstract
transp-El-pres-comp : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ preserves-comp (Group.comp (B a₁)) (Group.comp (B a₂)) (transport (Group.El ∘ B) p)
transp-El-pres-comp B idp g₁ g₂ = idp
transp!-El-pres-comp : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ preserves-comp (Group.comp (B a₂)) (Group.comp (B a₁)) (transport! (Group.El ∘ B) p)
transp!-El-pres-comp B idp h₁ h₂ = idp
transportᴳ : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ (B a₁ →ᴳ B a₂)
transportᴳ B p = record {f = transport (Group.El ∘ B) p; pres-comp = transp-El-pres-comp B p}
transport!ᴳ : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ (B a₂ →ᴳ B a₁)
transport!ᴳ B p = record {f = transport! (Group.El ∘ B) p; pres-comp = transp!-El-pres-comp B p}
abstract
transpᴳ-is-iso : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ is-equiv (GroupHom.f (transportᴳ B p))
transpᴳ-is-iso B idp = idf-is-equiv _
transp!ᴳ-is-iso : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ is-equiv (GroupHom.f (transport!ᴳ B p))
transp!ᴳ-is-iso B idp = idf-is-equiv _
transportᴳ-iso : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ B a₁ ≃ᴳ B a₂
transportᴳ-iso B p = transportᴳ B p , transpᴳ-is-iso B p
transport!ᴳ-iso : ∀ {i j} {A : Type i} (B : A → Group j) {a₁ a₂ : A} (p : a₁ == a₂)
→ B a₂ ≃ᴳ B a₁
transport!ᴳ-iso B p = transport!ᴳ B p , transp!ᴳ-is-iso B p
coeᴳ : ∀ {i} {G H : Group i} → G == H → (G →ᴳ H)
coeᴳ = transportᴳ (idf _)
coe!ᴳ : ∀ {i} {G H : Group i} → G == H → (H →ᴳ G)
coe!ᴳ = transport!ᴳ (idf _)
coeᴳ-iso : ∀ {i} {G H : Group i} → G == H → G ≃ᴳ H
coeᴳ-iso = transportᴳ-iso (idf _)
coe!ᴳ-iso : ∀ {i} {G H : Group i} → G == H → H ≃ᴳ G
coe!ᴳ-iso = transport!ᴳ-iso (idf _)
abstract
coeᴳ-β : ∀ {i} {G H : Group i} (iso : G ≃ᴳ H)
→ coeᴳ (uaᴳ iso) == GroupIso.f-hom iso
coeᴳ-β iso = group-hom= $
ap coe (El=-β iso)
∙ λ= (coe-β (GroupIso.f-equiv iso))
-- triviality
iso-preserves-trivial : ∀ {i j} {G : Group i} {H : Group j}
→ G ≃ᴳ H → is-trivialᴳ G → is-trivialᴳ H
iso-preserves-trivial iso G-is-trivial h =
! (GroupIso.f-g iso h)
∙ ap (GroupIso.f iso) (G-is-trivial _)
∙ GroupIso.pres-ident iso
iso-preserves'-trivial : ∀ {i j} {G : Group i} {H : Group j}
→ G ≃ᴳ H → is-trivialᴳ H → is-trivialᴳ G
iso-preserves'-trivial iso H-is-trivial g =
! (GroupIso.g-f iso g)
∙ ap (GroupIso.g iso) (H-is-trivial _)
∙ GroupHom.pres-ident (GroupIso.g-hom iso)
-- a surjective and injective homomorphism is an isomorphism
module _ {i j} {G : Group i} {H : Group j} (φ : G →ᴳ H)
(surj : is-surjᴳ φ) (inj : is-injᴳ φ) where
private
module G = Group G
module H = Group H
module φ = GroupHom φ
image-prop : (h : H.El) → is-prop (hfiber φ.f h)
image-prop h = all-paths-is-prop $ λ {(g₁ , p₁) (g₂ , p₂) →
pair= (inj g₁ g₂ (p₁ ∙ ! p₂)) (prop-has-all-paths-↓ (H.El-level _ _))}
surjᴳ-and-injᴳ-is-equiv : is-equiv φ.f
surjᴳ-and-injᴳ-is-equiv = contr-map-is-equiv
(λ h → let (g₁ , p₁) = Trunc-rec (image-prop h) (idf _) (surj h) in
((g₁ , p₁) , (λ {(g₂ , p₂) →
pair= (inj g₁ g₂ (p₁ ∙ ! p₂))
(prop-has-all-paths-↓ (H.El-level _ _))})))
surjᴳ-and-injᴳ-iso : G ≃ᴳ H
surjᴳ-and-injᴳ-iso = φ , surjᴳ-and-injᴳ-is-equiv
-- isomorphisms preserve abelianess.
module _ {i} {G H : Group i} (iso : G ≃ᴳ H) (G-abelian : is-abelian G) where
private
module G = Group G
module H = Group H
open GroupIso iso
abstract
iso-preserves-abelian : is-abelian H
iso-preserves-abelian h₁ h₂ =
H.comp h₁ h₂
=⟨ ap2 H.comp (! $ f-g h₁) (! $ f-g h₂) ⟩
H.comp (f (g h₁)) (f (g h₂))
=⟨ ! $ pres-comp (g h₁) (g h₂) ⟩
f (G.comp (g h₁) (g h₂))
=⟨ G-abelian (g h₁) (g h₂) |in-ctx f ⟩
f (G.comp (g h₂) (g h₁))
=⟨ pres-comp (g h₂) (g h₁) ⟩
H.comp (f (g h₂)) (f (g h₁))
=⟨ ap2 H.comp (f-g h₂) (f-g h₁) ⟩
H.comp h₂ h₁
=∎
pre∘ᴳ-iso : ∀ {i j k} {G : Group i} {H : Group j} (K : AbGroup k)
→ (G ≃ᴳ H) → (hom-group H K ≃ᴳ hom-group G K)
pre∘ᴳ-iso K iso = ≃-to-≃ᴳ (equiv to from to-from from-to) to-pres-comp where
to = GroupHom.f (pre∘ᴳ-hom K (–>ᴳ iso))
to-pres-comp = GroupHom.pres-comp (pre∘ᴳ-hom K (–>ᴳ iso))
from = GroupHom.f (pre∘ᴳ-hom K (<–ᴳ iso))
abstract
to-from : ∀ φ → to (from φ) == φ
to-from φ = group-hom= $ λ= λ g → ap (GroupHom.f φ) (GroupIso.g-f iso g)
from-to : ∀ φ → from (to φ) == φ
from-to φ = group-hom= $ λ= λ h → ap (GroupHom.f φ) (GroupIso.f-g iso h)
| 33.74613
| 97
| 0.535321
|
411320c8e95a335abf466a9d4bc5ea54ad79d20b
| 13,226
|
agda
|
Agda
|
deBruijn/Substitution/Data/Application/Application21.agda
|
nad/dependently-typed-syntax
|
498f8aefc570f7815fd1d6616508eeb92c52abce
|
[
"MIT"
] | 5
|
2020-04-16T12:14:44.000Z
|
2020-07-08T22:51:36.000Z
|
deBruijn/Substitution/Data/Application/Application21.agda
|
nad/dependently-typed-syntax
|
498f8aefc570f7815fd1d6616508eeb92c52abce
|
[
"MIT"
] | null | null | null |
deBruijn/Substitution/Data/Application/Application21.agda
|
nad/dependently-typed-syntax
|
498f8aefc570f7815fd1d6616508eeb92c52abce
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Lemmas related to application of substitutions
------------------------------------------------------------------------
-- The record below allows the application operation to be
-- "heterogeneous", applying substitutions containing one kind of term
-- to another kind of term. TODO: This results in some extra
-- complication—is it worth it?
open import Data.Universe.Indexed
module deBruijn.Substitution.Data.Application.Application21
{i u e} {Uni : IndexedUniverse i u e} where
import deBruijn.Context; open deBruijn.Context Uni
open import deBruijn.Substitution.Data.Application.Application
open import deBruijn.Substitution.Data.Basics
open import deBruijn.Substitution.Data.Map
open import deBruijn.Substitution.Data.Simple
open import Function using (_$_)
open import Level using (_⊔_)
import Relation.Binary.PropositionalEquality as P
open P.≡-Reasoning
-- Lemmas and definitions related to application.
record Application₂₁
{t₁} {T₁ : Term-like t₁}
{t₂} {T₂ : Term-like t₂}
-- Simple substitutions for the first kind of terms.
(simple₁ : Simple T₁)
-- Simple substitutions for the second kind of terms.
(simple₂ : Simple T₂)
-- A translation from the first to the second kind of terms.
(trans : [ T₁ ⟶⁼ T₂ ])
: Set (i ⊔ u ⊔ e ⊔ t₁ ⊔ t₂) where
open Term-like T₁ using () renaming (_⊢_ to _⊢₁_; _≅-⊢_ to _≅-⊢₁_)
open Term-like T₂ using ([_]) renaming (_⊢_ to _⊢₂_; _≅-⊢_ to _≅-⊢₂_)
open Simple simple₁
using ()
renaming ( id to id₁; sub to sub₁; var to var₁
; weaken[_] to weaken₁[_]; wk to wk₁
; wk-subst to wk-subst₁; wk-subst[_] to wk-subst₁[_]
; _↑ to _↑₁; _↑_ to _↑₁_; _↑⁺_ to _↑⁺₁_; _↑₊_ to _↑₊₁_
; _↑⋆_ to _↑⋆₁_; _↑⁺⋆_ to _↑⁺⋆₁_; _↑₊⋆_ to _↑₊⋆₁_
)
open Simple simple₂
using ()
renaming ( id to id₂; id[_] to id₂[_]; var to var₂
; weaken to weaken₂; weaken[_] to weaken₂[_]; wk to wk₂
; wk-subst to wk-subst₂; wk-subst[_] to wk-subst₂[_]
; _↑ to _↑₂; _↑_ to _↑₂_
)
field
application : Application T₁ T₂
open Application application
field
-- The two weakening functions coincide.
trans-weaken : ∀ {Γ σ τ} (t : Γ ⊢₁ τ) →
trans · (weaken₁[ σ ] · t) ≅-⊢₂
weaken₂[ σ ] · (trans · t)
-- The two variable inclusion functions coincide.
trans-var : ∀ {Γ σ} (x : Γ ∋ σ) → trans · (var₁ · x) ≅-⊢₂ var₂ · x
-- _/⊢_ and _/∋₁_ coincide for variables.
var-/⊢ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ σ) (ρ : Sub T₁ ρ̂) →
var₂ · x /⊢ ρ ≅-⊢₂ trans · (x /∋ ρ)
-- Application of multiple substitutions to variables.
--
-- TODO: Remove?
app∋⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T₁ ρ̂ → [ Var ⟶ T₂ ] ρ̂
app∋⋆ ε = var₂
app∋⋆ (ε ▻ ρ) = trans [∘] app∋ ρ
app∋⋆ (ρs ▻ ρ) = app ρ [∘] app∋⋆ ρs
infixl 8 _/∋⋆_
_/∋⋆_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} → Γ ∋ σ → Subs T₁ ρ̂ → Δ ⊢₂ σ /̂ ρ̂
x /∋⋆ ρs = app∋⋆ ρs · x
-- Composition of multiple substitutions.
--
-- TODO: Remove?
∘⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T₁ ρ̂ → Sub T₂ ρ̂
∘⋆ ε = id₂
∘⋆ (ρs ▻ ρ) = ∘⋆ ρs ∘ ρ
-- Some congruence lemmas.
trans-cong : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢₁ σ₁}
{Γ₂ σ₂} {t₂ : Γ₂ ⊢₁ σ₂} →
t₁ ≅-⊢₁ t₂ → trans · t₁ ≅-⊢₂ trans · t₂
trans-cong P.refl = P.refl
app∋⋆-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T₁ ρ̂₁}
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T₁ ρ̂₂} →
ρs₁ ≅-⇨⋆ ρs₂ → app∋⋆ ρs₁ ≅-⟶ app∋⋆ ρs₂
app∋⋆-cong P.refl = [ P.refl ]
/∋⋆-cong :
∀ {Γ₁ Δ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T₁ ρ̂₁}
{Γ₂ Δ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T₁ ρ̂₂} →
x₁ ≅-∋ x₂ → ρs₁ ≅-⇨⋆ ρs₂ → x₁ /∋⋆ ρs₁ ≅-⊢₂ x₂ /∋⋆ ρs₂
/∋⋆-cong P.refl P.refl = P.refl
∘⋆-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T₁ ρ̂₁}
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T₁ ρ̂₂} →
ρs₁ ≅-⇨⋆ ρs₂ → ∘⋆ ρs₁ ≅-⇨ ∘⋆ ρs₂
∘⋆-cong P.refl = P.refl
abstract
-- Applying a composed substitution to a variable is equivalent to
-- applying all the substitutions one after another.
--
-- TODO: Remove this lemma?
/∋-∘⋆ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ σ) (ρs : Subs T₁ ρ̂) →
x /∋ ∘⋆ ρs ≅-⊢₂ var₂ · x /⊢⋆ ρs
/∋-∘⋆ x ε = begin
[ x /∋ id₂ ] ≡⟨ Simple./∋-id simple₂ x ⟩
[ var₂ · x ] ∎
/∋-∘⋆ x (ρs ▻ ρ) = begin
[ x /∋ ∘⋆ ρs ∘ ρ ] ≡⟨ /∋-∘ x (∘⋆ ρs) ρ ⟩
[ x /∋ ∘⋆ ρs /⊢ ρ ] ≡⟨ /⊢-cong (/∋-∘⋆ x ρs) P.refl ⟩
[ var₂ · x /⊢⋆ ρs /⊢ ρ ] ∎
-- x /∋⋆ ρs is synonymous with var₂ · x /⊢⋆ ρs.
--
-- TODO: Remove?
var-/⊢⋆ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ σ) (ρs : Subs T₁ ρ̂) →
var₂ · x /⊢⋆ ρs ≅-⊢₂ x /∋⋆ ρs
var-/⊢⋆ x ε = P.refl
var-/⊢⋆ x (ε ▻ ρ) = begin
[ var₂ · x /⊢ ρ ] ≡⟨ var-/⊢ x ρ ⟩
[ trans · (x /∋ ρ) ] ∎
var-/⊢⋆ x (ρs ▻ ρ₁ ▻ ρ₂) = begin
[ var₂ · x /⊢⋆ (ρs ▻ ρ₁) /⊢ ρ₂ ] ≡⟨ /⊢-cong (var-/⊢⋆ x (ρs ▻ ρ₁)) P.refl ⟩
[ x /∋⋆ (ρs ▻ ρ₁) /⊢ ρ₂ ] ∎
-- A helper lemma.
/∋-≅-⊢-var : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ}
(x : Γ ∋ σ) (ρ : Sub T₁ ρ̂) {y : Δ ∋ σ / ρ} →
x /∋ ρ ≅-⊢₁ var₁ · y →
var₂ · x /⊢ ρ ≅-⊢₂ var₂ · y
/∋-≅-⊢-var x ρ {y} hyp = begin
[ var₂ · x /⊢ ρ ] ≡⟨ var-/⊢ x ρ ⟩
[ trans · (x /∋ ρ) ] ≡⟨ trans-cong hyp ⟩
[ trans · (var₁ · y) ] ≡⟨ trans-var y ⟩
[ var₂ · y ] ∎
-- A variant of /∋-id.
var-/⊢-id : ∀ {Γ σ} (x : Γ ∋ σ) → var₂ · x /⊢ id₁ ≅-⊢₂ var₂ · x
var-/⊢-id x = /∋-≅-⊢-var x id₁ (Simple./∋-id simple₁ x)
-- A variant of /∋-wk-↑⁺.
var-/⊢-wk-↑⁺ : ∀ {Γ σ} Γ⁺ {τ} (x : Γ ++⁺ Γ⁺ ∋ τ) →
var₂ · x /⊢ wk₁ {σ = σ} ↑⁺₁ Γ⁺ ≅-⊢₂
var₂ · (lift weaken∋[ σ ] Γ⁺ · x)
var-/⊢-wk-↑⁺ Γ⁺ x =
/∋-≅-⊢-var x (wk₁ ↑⁺₁ Γ⁺) (Simple./∋-wk-↑⁺ simple₁ Γ⁺ x)
-- A variant of /∋-wk-↑⁺-↑⁺.
var-/⊢-wk-↑⁺-↑⁺ : ∀ {Γ σ} Γ⁺ Γ⁺⁺ {τ} (x : Γ ++⁺ Γ⁺ ++⁺ Γ⁺⁺ ∋ τ) →
var₂ · x /⊢ wk₁ {σ = σ} ↑⁺₁ Γ⁺ ↑⁺₁ Γ⁺⁺ ≅-⊢₂
var₂ · (lift (lift weaken∋[ σ ] Γ⁺) Γ⁺⁺ · x)
var-/⊢-wk-↑⁺-↑⁺ Γ⁺ Γ⁺⁺ x =
/∋-≅-⊢-var x (wk₁ ↑⁺₁ Γ⁺ ↑⁺₁ Γ⁺⁺)
(Simple./∋-wk-↑⁺-↑⁺ simple₁ Γ⁺ Γ⁺⁺ x)
-- Variants of zero-/∋-↑.
zero-/⊢-↑ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} σ (ρ : Sub T₁ ρ̂) →
var₂ · zero /⊢ ρ ↑₁ σ ≅-⊢₂ var₂ · zero[ σ / ρ ]
zero-/⊢-↑ σ ρ =
/∋-≅-⊢-var zero (ρ ↑₁ σ) (Simple.zero-/∋-↑ simple₁ σ ρ)
zero-/⊢⋆-↑⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} σ (ρs : Subs T₁ ρ̂) →
var₂ · zero /⊢⋆ ρs ↑⋆₁ σ ≅-⊢₂
var₂ · zero[ σ /⋆ ρs ]
zero-/⊢⋆-↑⋆ σ ε = P.refl
zero-/⊢⋆-↑⋆ σ (ρs ▻ ρ) = begin
[ var₂ · zero /⊢⋆ ρs ↑⋆₁ σ /⊢ ρ ↑₁ ] ≡⟨ /⊢-cong (zero-/⊢⋆-↑⋆ σ ρs) (P.refl {x = [ ρ ↑₁ (σ /⋆ ρs) ]}) ⟩
[ var₂ · zero /⊢ ρ ↑₁ (σ /⋆ ρs) ] ≡⟨ zero-/⊢-↑ (σ /⋆ ρs) ρ ⟩
[ var₂ · zero ] ∎
-- Corollaries of ε-↑⁺⋆ and ε-↑₊⋆.
/⊢⋆-ε-↑⁺⋆ : ∀ {Γ} Γ⁺ {σ} (t : Γ ++⁺ Γ⁺ ⊢₂ σ) →
t /⊢⋆ ε ↑⁺⋆₁ Γ⁺ ≅-⊢₂ t
/⊢⋆-ε-↑⁺⋆ Γ⁺ t = begin
[ t /⊢⋆ ε ↑⁺⋆₁ Γ⁺ ] ≡⟨ /⊢⋆-cong (P.refl {x = [ t ]}) (Simple.ε-↑⁺⋆ simple₁ Γ⁺) ⟩
[ t /⊢⋆ ε ] ≡⟨ P.refl ⟩
[ t ] ∎
/⊢⋆-ε-↑₊⋆ : ∀ {Γ} Γ₊ {σ} (t : Γ ++₊ Γ₊ ⊢₂ σ) →
t /⊢⋆ ε ↑₊⋆₁ Γ₊ ≅-⊢₂ t
/⊢⋆-ε-↑₊⋆ Γ₊ t = begin
[ t /⊢⋆ ε ↑₊⋆₁ Γ₊ ] ≡⟨ /⊢⋆-cong (P.refl {x = [ t ]}) (Simple.ε-↑₊⋆ simple₁ Γ₊) ⟩
[ t /⊢⋆ ε ] ≡⟨ P.refl ⟩
[ t ] ∎
-- Corollaries of ▻-↑⁺⋆ and ▻-↑₊⋆.
/⊢⋆-▻-↑⁺⋆ :
∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} Γ⁺ {σ}
(t : Γ ++⁺ Γ⁺ ⊢₂ σ) (ρs : Subs T₁ ρ̂₁) (ρ : Sub T₁ ρ̂₂) →
t /⊢⋆ (ρs ▻ ρ) ↑⁺⋆₁ Γ⁺ ≅-⊢₂ t /⊢⋆ ρs ↑⁺⋆₁ Γ⁺ /⊢ ρ ↑⁺₁ (Γ⁺ /⁺⋆ ρs)
/⊢⋆-▻-↑⁺⋆ Γ⁺ t ρs ρ =
/⊢⋆-cong (P.refl {x = [ t ]}) (Simple.▻-↑⁺⋆ simple₁ ρs ρ Γ⁺)
/⊢⋆-▻-↑₊⋆ :
∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} Γ₊ {σ}
(t : Γ ++₊ Γ₊ ⊢₂ σ) (ρs : Subs T₁ ρ̂₁) (ρ : Sub T₁ ρ̂₂) →
t /⊢⋆ (ρs ▻ ρ) ↑₊⋆₁ Γ₊ ≅-⊢₂ t /⊢⋆ ρs ↑₊⋆₁ Γ₊ /⊢ ρ ↑₊₁ (Γ₊ /₊⋆ ρs)
/⊢⋆-▻-↑₊⋆ Γ₊ t ρs ρ =
/⊢⋆-cong (P.refl {x = [ t ]}) (Simple.▻-↑₊⋆ simple₁ ρs ρ Γ₊)
-- Corollaries of ε-↑⁺⋆/ε-↑₊⋆ and ▻-↑⁺⋆/▻-↑₊⋆.
/⊢⋆-ε-▻-↑⁺⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} Γ⁺ {σ}
(t : Γ ++⁺ Γ⁺ ⊢₂ σ) (ρ : Sub T₁ ρ̂) →
t /⊢⋆ (ε ▻ ρ) ↑⁺⋆₁ Γ⁺ ≅-⊢₂ t /⊢ ρ ↑⁺₁ Γ⁺
/⊢⋆-ε-▻-↑⁺⋆ Γ⁺ t ρ = begin
[ t /⊢⋆ (ε ▻ ρ) ↑⁺⋆₁ Γ⁺ ] ≡⟨ /⊢⋆-cong (P.refl {x = [ t ]}) (Simple.▻-↑⁺⋆ simple₁ ε ρ Γ⁺) ⟩
[ t /⊢⋆ ε ↑⁺⋆₁ Γ⁺ /⊢ ρ ↑⁺₁ (Γ⁺ /̂⁺ îd) ] ≡⟨ /⊢-cong (/⊢⋆-ε-↑⁺⋆ Γ⁺ t) (Simple.↑⁺-cong simple₁ P.refl (/̂⁺-îd Γ⁺)) ⟩
[ t /⊢ ρ ↑⁺₁ Γ⁺ ] ∎
/⊢⋆-ε-▻-▻-↑⁺⋆ :
∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} Γ⁺ {σ}
(t : Γ ++⁺ Γ⁺ ⊢₂ σ) (ρ₁ : Sub T₁ ρ̂₁) (ρ₂ : Sub T₁ ρ̂₂) →
t /⊢⋆ (ε ▻ ρ₁ ▻ ρ₂) ↑⁺⋆₁ Γ⁺ ≅-⊢₂
t /⊢ ρ₁ ↑⁺₁ Γ⁺ /⊢ ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁)
/⊢⋆-ε-▻-▻-↑⁺⋆ Γ⁺ t ρ₁ ρ₂ = begin
[ t /⊢⋆ (ε ▻ ρ₁ ▻ ρ₂) ↑⁺⋆₁ Γ⁺ ] ≡⟨ /⊢⋆-cong (P.refl {x = [ t ]}) (Simple.▻-↑⁺⋆ simple₁ (ε ▻ ρ₁) ρ₂ Γ⁺) ⟩
[ t /⊢⋆ (ε ▻ ρ₁) ↑⁺⋆₁ Γ⁺ /⊢ ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁) ] ≡⟨ /⊢-cong (/⊢⋆-ε-▻-↑⁺⋆ Γ⁺ t ρ₁) P.refl ⟩
[ t /⊢ ρ₁ ↑⁺₁ Γ⁺ /⊢ ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁) ] ∎
/⊢⋆-ε-▻-↑₊⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} Γ₊ {σ}
(t : Γ ++₊ Γ₊ ⊢₂ σ) (ρ : Sub T₁ ρ̂) →
t /⊢⋆ (ε ▻ ρ) ↑₊⋆₁ Γ₊ ≅-⊢₂ t /⊢ ρ ↑₊₁ Γ₊
/⊢⋆-ε-▻-↑₊⋆ Γ₊ t ρ = begin
[ t /⊢⋆ (ε ▻ ρ) ↑₊⋆₁ Γ₊ ] ≡⟨ /⊢⋆-cong (P.refl {x = [ t ]}) (Simple.▻-↑₊⋆ simple₁ ε ρ Γ₊) ⟩
[ t /⊢⋆ ε ↑₊⋆₁ Γ₊ /⊢ ρ ↑₊₁ (Γ₊ /̂₊ îd) ] ≡⟨ /⊢-cong (/⊢⋆-ε-↑₊⋆ Γ₊ t) (Simple.↑₊-cong simple₁ P.refl (/̂₊-îd Γ₊)) ⟩
[ t /⊢ ρ ↑₊₁ Γ₊ ] ∎
/⊢⋆-ε-▻-▻-↑₊⋆ :
∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} Γ₊ {σ}
(t : Γ ++₊ Γ₊ ⊢₂ σ) (ρ₁ : Sub T₁ ρ̂₁) (ρ₂ : Sub T₁ ρ̂₂) →
t /⊢⋆ (ε ▻ ρ₁ ▻ ρ₂) ↑₊⋆₁ Γ₊ ≅-⊢₂
t /⊢ ρ₁ ↑₊₁ Γ₊ /⊢ ρ₂ ↑₊₁ (Γ₊ /₊ ρ₁)
/⊢⋆-ε-▻-▻-↑₊⋆ Γ₊ t ρ₁ ρ₂ = begin
[ t /⊢⋆ (ε ▻ ρ₁ ▻ ρ₂) ↑₊⋆₁ Γ₊ ] ≡⟨ /⊢⋆-cong (P.refl {x = [ t ]}) (Simple.▻-↑₊⋆ simple₁ (ε ▻ ρ₁) ρ₂ Γ₊) ⟩
[ t /⊢⋆ (ε ▻ ρ₁) ↑₊⋆₁ Γ₊ /⊢ ρ₂ ↑₊₁ (Γ₊ /₊ ρ₁) ] ≡⟨ /⊢-cong (/⊢⋆-ε-▻-↑₊⋆ Γ₊ t ρ₁) P.refl ⟩
[ t /⊢ ρ₁ ↑₊₁ Γ₊ /⊢ ρ₂ ↑₊₁ (Γ₊ /₊ ρ₁) ] ∎
-- Application of sub cancels one occurrence of suc.
suc-/⊢-sub : ∀ {Γ σ τ} (x : Γ ∋ σ) (t : Γ ⊢₁ τ) →
var₂ · suc x /⊢ sub₁ t ≅-⊢₂ var₂ · x
suc-/⊢-sub x t = begin
[ var₂ · suc x /⊢ sub₁ t ] ≡⟨ var-/⊢ (suc x) (sub₁ t) ⟩
[ trans · (suc x /∋ sub₁ t) ] ≡⟨ P.refl ⟩
[ trans · (x /∋ id₁) ] ≡⟨ trans-cong (Simple./∋-id simple₁ x) ⟩
[ trans · (var₁ · x) ] ≡⟨ trans-var x ⟩
[ var₂ · x ] ∎
-- First weakening and then substituting something for the first
-- variable is equivalent to doing nothing.
wk-∘-sub : ∀ {Γ σ} (t : Γ ⊢₁ σ) → wk₂ ∘ sub₁ t ≅-⇨ id₂[ Γ ]
wk-∘-sub t = extensionality P.refl λ x → begin
[ x /∋ wk₂ ∘ sub₁ t ] ≡⟨ /∋-∘ x wk₂ (sub₁ t) ⟩
[ x /∋ wk₂ /⊢ sub₁ t ] ≡⟨ /⊢-cong (Simple./∋-wk simple₂ x) P.refl ⟩
[ var₂ · suc x /⊢ sub₁ t ] ≡⟨ suc-/⊢-sub x t ⟩
[ var₂ · x ] ≡⟨ P.sym $ Simple./∋-id simple₂ x ⟩
[ x /∋ id₂ ] ∎
-- id is a left identity of _∘_ (more or less).
id-∘ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T₁ ρ̂) → id₂ ∘ ρ ≅-⇨ map trans ρ
id-∘ ρ = extensionality P.refl λ x → begin
[ x /∋ id₂ ∘ ρ ] ≡⟨ /∋-∘ x id₂ ρ ⟩
[ x /∋ id₂ /⊢ ρ ] ≡⟨ /⊢-cong (Simple./∋-id simple₂ x) (P.refl {x = [ ρ ]}) ⟩
[ var₂ · x /⊢ ρ ] ≡⟨ var-/⊢ x ρ ⟩
[ trans · (x /∋ ρ) ] ≡⟨ P.sym $ /∋-map x trans ρ ⟩
[ x /∋ map trans ρ ] ∎
-- One can translate a substitution either before or after
-- weakening it.
map-trans-wk-subst : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T₁ ρ̂) →
map trans (wk-subst₁[ σ ] ρ) ≅-⇨
wk-subst₂[ σ ] (map trans ρ)
map-trans-wk-subst {σ = σ} ρ = begin
[ map trans (wk-subst₁[ σ ] ρ) ] ≡⟨ P.sym $ map-[∘] trans weaken₁[ σ ] ρ ⟩
[ map (trans [∘] weaken₁[ σ ]) ρ ] ≡⟨ map-cong-ext₁ P.refl trans-weaken (P.refl {x = [ ρ ]}) ⟩
[ map (weaken₂ [∘] trans) ρ ] ≡⟨ map-[∘] weaken₂ trans ρ ⟩
[ wk-subst₂ (map trans ρ) ] ∎
-- One can translate a substitution either before or after lifting
-- it.
map-trans-↑ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T₁ ρ̂) →
map trans (ρ ↑₁ σ) ≅-⇨ map trans ρ ↑₂ σ
map-trans-↑ {σ = σ} ρ = begin
[ map trans (ρ ↑₁ σ) ] ≡⟨ map-cong (trans ∎-⟶) (Simple.unfold-↑ simple₁ ρ) ⟩
[ map trans (wk-subst₁[ σ / ρ ] ρ ▻ var₁ · zero) ] ≡⟨ map-▻ trans (wk-subst₁ ρ) _ ⟩
[ map trans (wk-subst₁[ σ / ρ ] ρ) ▻ trans · (var₁ · zero) ] ≡⟨ ▻⇨-cong P.refl (map-trans-wk-subst ρ) (trans-var zero) ⟩
[ wk-subst₂ (map trans ρ) ▻ var₂ · zero ] ≡⟨ P.sym $ Simple.unfold-↑ simple₂ (map trans ρ) ⟩
[ map trans ρ ↑₂ ] ∎
open Application application public
| 39.957704
| 127
| 0.397097
|
3dddaeeaf88e449ee8e1032cbf8e95a39b865662
| 9,193
|
agda
|
Agda
|
Univalence/TypeEquiv.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/TypeEquiv.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/TypeEquiv.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module TypeEquiv where
import Level using (zero; suc)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; proj₁; proj₂; _,_)
open import Algebra using (CommutativeSemiring)
open import Algebra.Structures
using (IsSemigroup; IsCommutativeMonoid; IsCommutativeSemiring)
open import Function renaming (_∘_ to _○_)
open import Relation.Binary.PropositionalEquality using (refl)
open import Equiv
using (_∼_; refl∼; _≃_; id≃; sym≃; ≃IsEquiv; qinv; _⊎≃_; _×≃_)
------------------------------------------------------------------------------
-- Type Equivalences
-- for each type combinator, define two functions that are inverses, and
-- establish an equivalence. These are all in the 'semantic space' with
-- respect to Pi combinators.
-- swap₊
swap₊ : {A B : Set} → A ⊎ B → B ⊎ A
swap₊ (inj₁ a) = inj₂ a
swap₊ (inj₂ b) = inj₁ b
abstract
swapswap₊ : {A B : Set} → swap₊ ○ swap₊ {A} {B} ∼ id
swapswap₊ (inj₁ a) = refl
swapswap₊ (inj₂ b) = refl
swap₊equiv : {A B : Set} → (A ⊎ B) ≃ (B ⊎ A)
swap₊equiv = (swap₊ , qinv swap₊ swapswap₊ swapswap₊)
-- unite₊ and uniti₊
unite₊ : {A : Set} → ⊥ ⊎ A → A
unite₊ (inj₁ ())
unite₊ (inj₂ y) = y
uniti₊ : {A : Set} → A → ⊥ ⊎ A
uniti₊ a = inj₂ a
abstract
uniti₊∘unite₊ : {A : Set} → uniti₊ ○ unite₊ ∼ id {A = ⊥ ⊎ A}
uniti₊∘unite₊ (inj₁ ())
uniti₊∘unite₊ (inj₂ y) = refl
-- this is so easy, Agda can figure it out by itself (see below)
unite₊∘uniti₊ : {A : Set} → unite₊ ○ uniti₊ ∼ id {A = A}
unite₊∘uniti₊ _ = refl
unite₊equiv : {A : Set} → (⊥ ⊎ A) ≃ A
unite₊equiv = (unite₊ , qinv uniti₊ unite₊∘uniti₊ uniti₊∘unite₊)
uniti₊equiv : {A : Set} → A ≃ (⊥ ⊎ A)
uniti₊equiv = sym≃ unite₊equiv
-- unite₊′ and uniti₊′
unite₊′ : {A : Set} → A ⊎ ⊥ → A
unite₊′ (inj₁ x) = x
unite₊′ (inj₂ ())
uniti₊′ : {A : Set} → A → A ⊎ ⊥
uniti₊′ a = inj₁ a
abstract
uniti₊′∘unite₊′ : {A : Set} → uniti₊′ ○ unite₊′ ∼ id {A = A ⊎ ⊥}
uniti₊′∘unite₊′ (inj₁ _) = refl
uniti₊′∘unite₊′ (inj₂ ())
-- this is so easy, Agda can figure it out by itself (see below)
unite₊′∘uniti₊′ : {A : Set} → unite₊′ ○ uniti₊′ ∼ id {A = A}
unite₊′∘uniti₊′ _ = refl
unite₊′equiv : {A : Set} → (A ⊎ ⊥) ≃ A
unite₊′equiv = (unite₊′ , qinv uniti₊′ refl∼ uniti₊′∘unite₊′)
uniti₊′equiv : {A : Set} → A ≃ (A ⊎ ⊥)
uniti₊′equiv = sym≃ unite₊′equiv
-- unite⋆ and uniti⋆
unite⋆ : {A : Set} → ⊤ × A → A
unite⋆ (tt , x) = x
uniti⋆ : {A : Set} → A → ⊤ × A
uniti⋆ x = tt , x
abstract
uniti⋆∘unite⋆ : {A : Set} → uniti⋆ ○ unite⋆ ∼ id {A = ⊤ × A}
uniti⋆∘unite⋆ (tt , x) = refl
unite⋆equiv : {A : Set} → (⊤ × A) ≃ A
unite⋆equiv = unite⋆ , qinv uniti⋆ refl∼ uniti⋆∘unite⋆
uniti⋆equiv : {A : Set} → A ≃ (⊤ × A)
uniti⋆equiv = sym≃ unite⋆equiv
-- unite⋆′ and uniti⋆′
unite⋆′ : {A : Set} → A × ⊤ → A
unite⋆′ (x , tt) = x
uniti⋆′ : {A : Set} → A → A × ⊤
uniti⋆′ x = x , tt
abstract
uniti⋆′∘unite⋆′ : {A : Set} → uniti⋆′ ○ unite⋆′ ∼ id {A = A × ⊤}
uniti⋆′∘unite⋆′ (x , tt) = refl
unite⋆′equiv : {A : Set} → (A × ⊤) ≃ A
unite⋆′equiv = unite⋆′ , qinv uniti⋆′ refl∼ uniti⋆′∘unite⋆′
uniti⋆′equiv : {A : Set} → A ≃ (A × ⊤)
uniti⋆′equiv = sym≃ unite⋆′equiv
-- swap⋆
swap⋆ : {A B : Set} → A × B → B × A
swap⋆ (a , b) = (b , a)
abstract
swapswap⋆ : {A B : Set} → swap⋆ ○ swap⋆ ∼ id {A = A × B}
swapswap⋆ (a , b) = refl
swap⋆equiv : {A B : Set} → (A × B) ≃ (B × A)
swap⋆equiv = swap⋆ , qinv swap⋆ swapswap⋆ swapswap⋆
-- assocl₊ and assocr₊
assocl₊ : {A B C : Set} → (A ⊎ (B ⊎ C)) → ((A ⊎ B) ⊎ C)
assocl₊ (inj₁ a) = inj₁ (inj₁ a)
assocl₊ (inj₂ (inj₁ b)) = inj₁ (inj₂ b)
assocl₊ (inj₂ (inj₂ c)) = inj₂ c
assocr₊ : {A B C : Set} → ((A ⊎ B) ⊎ C) → (A ⊎ (B ⊎ C))
assocr₊ (inj₁ (inj₁ a)) = inj₁ a
assocr₊ (inj₁ (inj₂ b)) = inj₂ (inj₁ b)
assocr₊ (inj₂ c) = inj₂ (inj₂ c)
abstract
assocl₊∘assocr₊ : {A B C : Set} → assocl₊ ○ assocr₊ ∼ id {A = ((A ⊎ B) ⊎ C)}
assocl₊∘assocr₊ (inj₁ (inj₁ a)) = refl
assocl₊∘assocr₊ (inj₁ (inj₂ b)) = refl
assocl₊∘assocr₊ (inj₂ c) = refl
assocr₊∘assocl₊ : {A B C : Set} → assocr₊ ○ assocl₊ ∼ id {A = (A ⊎ (B ⊎ C))}
assocr₊∘assocl₊ (inj₁ a) = refl
assocr₊∘assocl₊ (inj₂ (inj₁ b)) = refl
assocr₊∘assocl₊ (inj₂ (inj₂ c)) = refl
assocr₊equiv : {A B C : Set} → ((A ⊎ B) ⊎ C) ≃ (A ⊎ (B ⊎ C))
assocr₊equiv =
assocr₊ , qinv assocl₊ assocr₊∘assocl₊ assocl₊∘assocr₊
assocl₊equiv : {A B C : Set} → (A ⊎ (B ⊎ C)) ≃ ((A ⊎ B) ⊎ C)
assocl₊equiv = sym≃ assocr₊equiv
-- assocl⋆ and assocr⋆
assocl⋆ : {A B C : Set} → (A × (B × C)) → ((A × B) × C)
assocl⋆ (a , (b , c)) = ((a , b) , c)
assocr⋆ : {A B C : Set} → ((A × B) × C) → (A × (B × C))
assocr⋆ ((a , b) , c) = (a , (b , c))
abstract
assocl⋆∘assocr⋆ : {A B C : Set} → assocl⋆ ○ assocr⋆ ∼ id {A = ((A × B) × C)}
assocl⋆∘assocr⋆ = refl∼
assocr⋆∘assocl⋆ : {A B C : Set} → assocr⋆ ○ assocl⋆ ∼ id {A = (A × (B × C))}
assocr⋆∘assocl⋆ = refl∼
assocl⋆equiv : {A B C : Set} → (A × (B × C)) ≃ ((A × B) × C)
assocl⋆equiv =
assocl⋆ , qinv assocr⋆ assocl⋆∘assocr⋆ assocr⋆∘assocl⋆
assocr⋆equiv : {A B C : Set} → ((A × B) × C) ≃ (A × (B × C))
assocr⋆equiv = sym≃ assocl⋆equiv
-- distz and factorz, on left
distz : { A : Set} → (⊥ × A) → ⊥
distz = proj₁
factorz : {A : Set} → ⊥ → (⊥ × A)
factorz ()
abstract
distz∘factorz : {A : Set} → distz ○ factorz {A} ∼ id
distz∘factorz ()
factorz∘distz : {A : Set} → factorz {A} ○ distz ∼ id
factorz∘distz (() , proj₂)
distzequiv : {A : Set} → (⊥ × A) ≃ ⊥
distzequiv {A} =
distz , qinv factorz (distz∘factorz {A}) factorz∘distz
factorzequiv : {A : Set} → ⊥ ≃ (⊥ × A)
factorzequiv {A} = sym≃ distzequiv
-- distz and factorz, on right
distzr : { A : Set} → (A × ⊥) → ⊥
distzr = proj₂
factorzr : {A : Set} → ⊥ → (A × ⊥)
factorzr ()
abstract
distzr∘factorzr : {A : Set} → distzr ○ factorzr {A} ∼ id
distzr∘factorzr ()
factorzr∘distzr : {A : Set} → factorzr {A} ○ distzr ∼ id
factorzr∘distzr (_ , ())
distzrequiv : {A : Set} → (A × ⊥) ≃ ⊥
distzrequiv {A} =
distzr , qinv factorzr (distzr∘factorzr {A}) factorzr∘distzr
factorzrequiv : {A : Set} → ⊥ ≃ (A × ⊥)
factorzrequiv {A} = sym≃ distzrequiv
-- dist and factor, on right
dist : {A B C : Set} → ((A ⊎ B) × C) → (A × C) ⊎ (B × C)
dist (inj₁ x , c) = inj₁ (x , c)
dist (inj₂ y , c) = inj₂ (y , c)
factor : {A B C : Set} → (A × C) ⊎ (B × C) → ((A ⊎ B) × C)
factor (inj₁ (a , c)) = inj₁ a , c
factor (inj₂ (b , c)) = inj₂ b , c
abstract
dist∘factor : {A B C : Set} → dist {A} {B} {C} ○ factor ∼ id
dist∘factor (inj₁ x) = refl
dist∘factor (inj₂ y) = refl
factor∘dist : {A B C : Set} → factor {A} {B} {C} ○ dist ∼ id
factor∘dist (inj₁ x , c) = refl
factor∘dist (inj₂ y , c) = refl
distequiv : {A B C : Set} → ((A ⊎ B) × C) ≃ ((A × C) ⊎ (B × C))
distequiv = dist , qinv factor dist∘factor factor∘dist
factorequiv : {A B C : Set} → ((A × C) ⊎ (B × C)) ≃ ((A ⊎ B) × C)
factorequiv = sym≃ distequiv
-- dist and factor, on left
distl : {A B C : Set} → A × (B ⊎ C) → (A × B) ⊎ (A × C)
distl (x , inj₁ x₁) = inj₁ (x , x₁)
distl (x , inj₂ y) = inj₂ (x , y)
factorl : {A B C : Set} → (A × B) ⊎ (A × C) → A × (B ⊎ C)
factorl (inj₁ (x , y)) = x , inj₁ y
factorl (inj₂ (x , y)) = x , inj₂ y
abstract
distl∘factorl : {A B C : Set} → distl {A} {B} {C} ○ factorl ∼ id
distl∘factorl (inj₁ (x , y)) = refl
distl∘factorl (inj₂ (x , y)) = refl
factorl∘distl : {A B C : Set} → factorl {A} {B} {C} ○ distl ∼ id
factorl∘distl (a , inj₁ x) = refl
factorl∘distl (a , inj₂ y) = refl
distlequiv : {A B C : Set} → (A × (B ⊎ C)) ≃ ((A × B) ⊎ (A × C))
distlequiv = distl , qinv factorl distl∘factorl factorl∘distl
factorlequiv : {A B C : Set} → ((A × B) ⊎ (A × C)) ≃ (A × (B ⊎ C))
factorlequiv = sym≃ distlequiv
------------------------------------------------------------------------------
-- Commutative semiring structure
typesPlusIsSG : IsSemigroup {Level.suc Level.zero} {Level.zero} {Set} _≃_ _⊎_
typesPlusIsSG = record {
isMagma = record {
isEquivalence = ≃IsEquiv ;
∙-cong = _⊎≃_ }
; assoc = λ t₁ t₂ t₃ → assocr₊equiv {t₁} {t₂} {t₃}
}
typesTimesIsSG : IsSemigroup {Level.suc Level.zero} {Level.zero} {Set} _≃_ _×_
typesTimesIsSG = record {
isMagma = record {
isEquivalence = ≃IsEquiv
; ∙-cong = _×≃_
}
; assoc = λ t₁ t₂ t₃ → assocr⋆equiv {t₁} {t₂} {t₃}
}
typesPlusIsCM : IsCommutativeMonoid _≃_ _⊎_ ⊥
typesPlusIsCM = record {
isSemigroup = typesPlusIsSG ;
identityˡ = λ t → unite₊equiv {t} ;
comm = λ t₁ t₂ → swap₊equiv {t₁} {t₂}
}
typesTimesIsCM : IsCommutativeMonoid _≃_ _×_ ⊤
typesTimesIsCM = record {
isSemigroup = typesTimesIsSG ;
identityˡ = λ t → unite⋆equiv {t} ;
comm = λ t₁ t₂ → swap⋆equiv {t₁} {t₂}
}
typesIsCSR : IsCommutativeSemiring _≃_ _⊎_ _×_ ⊥ ⊤
typesIsCSR = record {
+-isCommutativeMonoid = typesPlusIsCM ;
*-isCommutativeMonoid = typesTimesIsCM ;
distribʳ = λ t₁ t₂ t₃ → distequiv {t₂} {t₃} {t₁} ;
zeroˡ = λ t → distzequiv {t}
}
typesCSR : CommutativeSemiring (Level.suc Level.zero) Level.zero
typesCSR = record {
Carrier = Set ;
_≈_ = _≃_ ;
_+_ = _⊎_ ;
_*_ = _×_ ;
0# = ⊥ ;
1# = ⊤ ;
isCommutativeSemiring = typesIsCSR
}
------------------------------------------------------------------------------
| 26.042493
| 78
| 0.540955
|
c7436bbf155fe40dbbfb45f502551b5556324dd8
| 29,837
|
agda
|
Agda
|
Cubical/ZCohomology/RingStructure/RingLaws.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/ZCohomology/RingStructure/RingLaws.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/RingStructure/RingLaws.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.RingStructure.RingLaws where
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.GroupoidLaws hiding (assoc)
open import Cubical.Data.Nat
open import Cubical.Data.Int
renaming (_+_ to _ℤ+_ ; _·_ to _ℤ∙_ ; +Comm to +ℤ-comm ; ·Comm to ∙-comm ; +Assoc to ℤ+-assoc ; -_ to -ℤ_)
hiding (_+'_ ; +'≡+)
open import Cubical.Data.Sigma
open import Cubical.HITs.SetTruncation as ST
open import Cubical.HITs.Truncation as T
open import Cubical.HITs.S1 hiding (_·_)
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.Homotopy.Loopspace
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.RingStructure.CupProduct
private
variable
ℓ : Level
-- Some boring lemmas
·₀≡·ℤ : (x y : ℤ) → _·₀_ {n = zero} x y ≡ x ℤ∙ y
·₀≡·ℤ (pos zero) y = refl
·₀≡·ℤ (pos (suc n)) y = cong (y ℤ+_) (·₀≡·ℤ (pos n) y)
·₀≡·ℤ (negsuc zero) (pos zero) = refl
·₀≡·ℤ (negsuc zero) (pos (suc n)) = -AntiComm 0 (pos (suc n))
·₀≡·ℤ (negsuc zero) (negsuc n) = -AntiComm 0 (negsuc n)
·₀≡·ℤ (negsuc (suc n)) (pos m) =
(cong ((_ℤ+ (pos 0 - pos m))) (·₀≡·ℤ (negsuc n) (pos m))
∙ cong ((negsuc n ℤ∙ (pos m)) ℤ+_)
(-AntiComm 0 (pos m) ∙ cong (-ℤ_) (help m)))
∙ sym (+ℤ-comm (-ℤ (pos m)) (negsuc n ℤ∙ (pos m)))
where
help : (m : ℕ) → (pos m - 0) ≡ pos m
help zero = refl
help (suc m) = refl
·₀≡·ℤ (negsuc (suc n)) (negsuc m) =
+ℤ-comm (_·₀_{n = zero} (negsuc n) (negsuc m)) (pos 0 - (negsuc m))
∙∙ cong ((pos 0 - negsuc m) ℤ+_) (·₀≡·ℤ (negsuc n) (negsuc m))
∙∙ cong (_ℤ+ (negsuc n ℤ∙ negsuc m)) (help m)
where
help : (m : ℕ) → (pos 0 - negsuc m) ≡ pos (suc m)
help zero = refl
help (suc n) = cong sucℤ (help n)
comm-·₀ : (x y : ℤ) → _·₀_ {n = 0} x y ≡ y ·₀ x
comm-·₀ x y = ·₀≡·ℤ x y ∙∙ ∙-comm x y ∙∙ sym (·₀≡·ℤ y x)
+'-assoc : (n m l : ℕ) → (n +' (m +' l)) ≡ ((n +' m) +' l)
+'-assoc n m l =
(λ i → +'≡+ n (+'≡+ m l i) i)
∙∙ +-assoc n m l
∙∙ (λ i → +'≡+ (+'≡+ n m (~ i)) l (~ i))
-- Zero multiplication
⌣ₖ-0ₖ : (n m : ℕ) → (x : coHomK n)
→ x ⌣ₖ (0ₖ _) ≡ 0ₖ _
⌣ₖ-0ₖ n m x = snd (⌣ₖ∙ n m x)
0ₖ-⌣ₖ : (n m : ℕ) → (x : coHomK m) →
(0ₖ _) ⌣ₖ x ≡ 0ₖ _
0ₖ-⌣ₖ n m = funExt⁻ (cong fst (snd (⌣ₖ∙∙ n m)))
⌣ₖ-0ₖ≡0ₖ-⌣ₖ : (n m : ℕ) → ⌣ₖ-0ₖ n m (0ₖ _) ≡ 0ₖ-⌣ₖ n m (0ₖ _)
⌣ₖ-0ₖ≡0ₖ-⌣ₖ zero zero = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ zero (suc m) = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc n) zero = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc zero) (suc m) = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc (suc n)) (suc m) = refl
-- Left distributivity
private
⌣ₖ-distrFun : -- z ⌣ₖ (x +ₖ y)
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (m +' n)
fst (⌣ₖ-distrFun n m x y) z =
z ⌣ₖ (x +ₖ y)
snd (⌣ₖ-distrFun n m x y) =
0ₖ-⌣ₖ m n (x +ₖ y)
⌣ₖ-distrFun2 : -- z ⌣ₖ x +ₖ z ⌣ₖ y
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (m +' n)
fst (⌣ₖ-distrFun2 n m x y) z =
z ⌣ₖ x +ₖ z ⌣ₖ y
snd (⌣ₖ-distrFun2 n m x y) =
cong₂ _+ₖ_ (0ₖ-⌣ₖ m n x) (0ₖ-⌣ₖ m n y) ∙ rUnitₖ _ _
leftDistr-⌣ₖ· : (n m : ℕ) (x y : coHomK (suc n))
→ ⌣ₖ-distrFun (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2 (suc n) (suc m) x y
leftDistr-⌣ₖ· n m =
T.elim2 (λ _ _ → isOfHLevelSuc (2 + n) (hLevHelp n m _ _))
main
where
hLevHelp : (n m : ℕ) (x y : _)
→ isOfHLevel (2 + n) ( ⌣ₖ-distrFun (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2 (suc n) (suc m) x y)
hLevHelp n m x y =
(subst (isOfHLevel (3 + n))
(λ i → (coHomK-ptd (suc m) →∙ coHomK-ptd (suc (suc (+-comm n m i)))))
(isOfHLevel↑∙ (suc n) m)) _ _
left-fst : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ x ∣) ≡
fst (⌣ₖ-distrFun2 (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ x ∣)
left-fst zero y =
(funExt (λ z → sym (lUnitₖ _ (z ⌣ₖ ∣ y ∣)) ∙ λ i → ⌣ₖ-0ₖ _ _ z (~ i) +ₖ z ⌣ₖ ∣ y ∣))
left-fst (suc n) y =
(funExt (λ z → sym (lUnitₖ _ (z ⌣ₖ ∣ y ∣)) ∙ λ i → ⌣ₖ-0ₖ _ _ z (~ i) +ₖ z ⌣ₖ ∣ y ∣))
right-fst : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun (suc n) (suc m) ∣ x ∣ (0ₖ _)) ≡
fst (⌣ₖ-distrFun2 (suc n) (suc m) ∣ x ∣ (0ₖ _))
right-fst n x = funExt (λ z → (cong (z ⌣ₖ_) (rUnitₖ _ ∣ x ∣) ∙∙ sym (rUnitₖ _ _) ∙∙ λ i → z ⌣ₖ ∣ x ∣ +ₖ ⌣ₖ-0ₖ _ (suc n) z (~ i)))
helper : (n : ℕ) (x : coHomK (suc n)) (p : 0ₖ _ ≡ x)
→ sym (lUnitₖ _ x) ∙ cong (_+ₖ x) p ≡ sym (rUnitₖ _ x) ∙ cong (x +ₖ_) p
helper n x = J (λ x p → sym (lUnitₖ _ x) ∙ cong (_+ₖ x) p ≡ sym (rUnitₖ _ x) ∙ cong (x +ₖ_) p)
(helper' n)
where
helper' : (n : ℕ) → (λ i → lUnitₖ (suc n) (0ₖ (suc n)) (~ i)) ∙
(λ i → 0ₖ (suc n) +ₖ 0ₖ (suc n))
≡
(λ i → rUnitₖ (suc n) (0ₖ (suc n)) (~ i)) ∙
(λ i → 0ₖ (suc n) +ₖ 0ₖ (suc n))
helper' zero = refl
helper' (suc n) = refl
left-fst≡right-fst : (n : ℕ) → left-fst n (ptSn _) ≡ right-fst n (ptSn _)
left-fst≡right-fst zero i j z = helper _ (z ⌣ₖ ∣ base ∣) (sym (⌣ₖ-0ₖ _ _ z)) i j
left-fst≡right-fst (suc n) i j z = helper _ (z ⌣ₖ ∣ north ∣) (sym (⌣ₖ-0ₖ _ (suc (suc n)) z)) i j
main : (a b : S₊ (suc n)) →
⌣ₖ-distrFun (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ ≡
⌣ₖ-distrFun2 (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ
main =
wedgeconFun n n
(λ x y → subst (λ l → isOfHLevel l ((⌣ₖ-distrFun (suc n) (suc m) ∣ x ∣ ∣ y ∣)
≡ ⌣ₖ-distrFun2 (suc n) (suc m) ∣ x ∣ ∣ y ∣))
(+-suc n (suc n))
(isOfHLevelPlus {n = 2 + n} n (hLevHelp n m ∣ x ∣ ∣ y ∣)))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (left-fst n x))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (right-fst n x))
(cong (→∙Homogeneous≡ (isHomogeneousKn _)) (sym (left-fst≡right-fst n)))
-- Distributivity for 0 dimensional cases
leftDistr₀n : (n : ℕ) → (z : coHomK 0) (x y : coHomK n)
→ z ·₀ (x +[ n ]ₖ y) ≡ z ·₀ x +[ n ]ₖ (z ·₀ y)
leftDistr₀n n (pos zero) x y = sym (rUnitₖ n (0ₖ _))
leftDistr₀n n (pos (suc z)) x y =
cong ((x +ₖ y) +ₖ_) (leftDistr₀n n (pos z) x y)
∙∙ sym (assocₖ n x y (pos z ·₀ x +[ n ]ₖ (pos z ·₀ y)))
∙∙ cong (x +ₖ_) (assocₖ n y (pos z ·₀ x) (pos z ·₀ y)
∙∙ cong (_+ₖ (pos z ·₀ y)) (commₖ n y (pos z ·₀ x))
∙∙ sym (assocₖ n (pos z ·₀ x) y (pos z ·₀ y)))
∙ assocₖ n x _ _
leftDistr₀n n (negsuc zero) x y = -distrₖ n x y
leftDistr₀n n (negsuc (suc z)) x y =
cong₂ (_+ₖ_) (leftDistr₀n n (negsuc z) x y) (-distrₖ n x y)
∙∙ assocₖ n ((negsuc z ·₀ x) +ₖ (negsuc z ·₀ y)) (-ₖ x) (-ₖ y)
∙∙ cong (_-ₖ y) (sym (assocₖ n (negsuc z ·₀ x) (negsuc z ·₀ y) (-ₖ x))
∙∙ cong ((negsuc z ·₀ x) +ₖ_) (commₖ n (negsuc z ·₀ y) (-ₖ x))
∙∙ assocₖ n (negsuc z ·₀ x) (-ₖ x) (negsuc z ·₀ y))
∙ sym (assocₖ n (negsuc (suc z) ·₀ x) _ _)
leftDistrn₀ : (n : ℕ) → (z : coHomK n) (x y : coHomK 0)
→ (x ℤ+ y) ·₀ z ≡ x ·₀ z +[ n ]ₖ (y ·₀ z)
leftDistrn₀ n z x (pos zero) = sym (rUnitₖ n (x ·₀ z))
leftDistrn₀ n z x (pos (suc y)) =
lem (x +pos y)
∙∙ cong (z +ₖ_) (leftDistrn₀ n z x (pos y) ∙ commₖ n _ _)
∙∙ assocₖ n z _ _
∙ commₖ n _ _
where
lem : (a : ℤ) → (sucℤ a) ·₀ z ≡ z +ₖ (a ·₀ z)
lem (pos zero) = refl
lem (pos (suc a)) = cong (z +ₖ_) (lem (pos a))
lem (negsuc zero) = sym (rCancelₖ n z)
lem (negsuc (suc a)) = sym (-cancelLₖ n z (negsuc a ·₀ z)) ∙ sym (assocₖ n z (negsuc a ·₀ z) (-ₖ z))
leftDistrn₀ n z x (negsuc y) = main y
where
help : (x : ℤ) → predℤ x ·₀ z ≡ (x ·₀ z -ₖ z)
help (pos zero) = sym (lUnitₖ n (-ₖ z))
help (pos (suc x)) = sym (-cancelLₖ n z (pos x ·₀ z))
help (negsuc x) = refl
main : (y : _) → (x ℤ+ negsuc y) ·₀ z ≡ (x ·₀ z) +ₖ (negsuc y ·₀ z)
main zero = help x
main (suc y) =
help (x +negsuc y)
∙∙ cong (_-ₖ z) (main y)
∙∙ sym (assocₖ n _ _ _)
leftDistr-⌣ₖ : (n m : ℕ) (z : coHomK n) (x y : coHomK m)
→ z ⌣ₖ (x +ₖ y) ≡ (z ⌣ₖ x +ₖ z ⌣ₖ y)
leftDistr-⌣ₖ zero m z x y = leftDistr₀n m z x y
leftDistr-⌣ₖ (suc n) zero z x y = leftDistrn₀ (suc n) z x y
leftDistr-⌣ₖ (suc n) (suc m) z x y = funExt⁻ (cong fst (leftDistr-⌣ₖ· m n x y)) z
-- Right distributivity
private
⌣ₖ-distrFun-r : -- (x +ₖ y) ⌣ₖ z
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (n +' m)
fst (⌣ₖ-distrFun-r n m x y) z =
(x +ₖ y) ⌣ₖ z
snd (⌣ₖ-distrFun-r n m x y) =
⌣ₖ-0ₖ n m (x +ₖ y) -- ⌣ₖ-0ₖ m n (x +ₖ y)
⌣ₖ-distrFun2-r :
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (n +' m)
fst (⌣ₖ-distrFun2-r n m x y) z =
x ⌣ₖ z +ₖ y ⌣ₖ z
snd (⌣ₖ-distrFun2-r n m x y) =
cong₂ _+ₖ_ (⌣ₖ-0ₖ n m x) (⌣ₖ-0ₖ n m y) ∙ rUnitₖ _ _
rightDistr-⌣ₖ· : (n m : ℕ) (x y : coHomK (suc n))
→ ⌣ₖ-distrFun-r (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2-r (suc n) (suc m) x y
rightDistr-⌣ₖ· n m =
T.elim2 (λ _ _ → isOfHLevelPath (3 + n) (isOfHLevel↑∙ (suc n) m) _ _)
main
where
fst-left : (n : ℕ) (y : S₊ (suc n)) →
fst (⌣ₖ-distrFun-r (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ y ∣) ≡
fst (⌣ₖ-distrFun2-r (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ y ∣)
fst-left n y =
funExt (λ z
→ cong (_⌣ₖ z) (lUnitₖ _ ∣ y ∣)
∙∙ sym (lUnitₖ _ (∣ y ∣ ⌣ₖ z))
∙∙ cong (_+ₖ (∣ y ∣ ⌣ₖ z)) (sym (0ₖ-⌣ₖ _ _ z)))
fst-right : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun-r (suc n) (suc m) ∣ x ∣ ∣ ptSn (suc n) ∣) ≡
fst (⌣ₖ-distrFun2-r (suc n) (suc m) ∣ x ∣ ∣ ptSn (suc n) ∣)
fst-right n x =
funExt λ z
→ cong (_⌣ₖ z) (rUnitₖ _ ∣ x ∣)
∙∙ sym (rUnitₖ _ _)
∙∙ cong (∣ x ∣ ⌣ₖ z +ₖ_) (sym (0ₖ-⌣ₖ _ _ z))
left≡right : (n : ℕ) → fst-left n (ptSn (suc n)) ≡ fst-right n (ptSn (suc n))
left≡right zero = refl
left≡right (suc n) = refl
main : (a b : S₊ (suc n)) →
⌣ₖ-distrFun-r (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ ≡
⌣ₖ-distrFun2-r (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ
main =
wedgeconFun n n
(λ x y → subst (λ l → isOfHLevel l ((⌣ₖ-distrFun-r (suc n) (suc m) ∣ x ∣ ∣ y ∣)
≡ ⌣ₖ-distrFun2-r (suc n) (suc m) ∣ x ∣ ∣ y ∣))
(+-suc n (suc n))
(isOfHLevelPlus {n = 2 + n} n (isOfHLevel↑∙ (suc n) m _ _)))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (fst-left n x))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (fst-right n x))
(cong (→∙Homogeneous≡ (isHomogeneousKn _)) (sym (left≡right n)))
rightDistr-⌣ₖ : (n m : ℕ) (x y : coHomK n) (z : coHomK m)
→ (x +ₖ y) ⌣ₖ z ≡ (x ⌣ₖ z +ₖ y ⌣ₖ z)
rightDistr-⌣ₖ zero zero x y z =
comm-·₀ (x ℤ+ y) z
∙∙ leftDistr-⌣ₖ zero zero z x y
∙∙ cong₂ _+ₖ_ (sym (comm-·₀ x z)) (sym (comm-·₀ y z))
rightDistr-⌣ₖ zero (suc m) x y z = leftDistr-⌣ₖ _ zero z x y
rightDistr-⌣ₖ (suc n) zero x y z = leftDistr-⌣ₖ zero (suc n) z x y
rightDistr-⌣ₖ (suc n) (suc m) x y z = (funExt⁻ (cong fst (rightDistr-⌣ₖ· n m x y))) z
-- Associativity
private
-- We need to give the two associators as (doubly) pointed functions
assocer : (n m k : ℕ) → coHomK (suc n)
→ coHomK-ptd (suc m)
→∙ (coHomK-ptd (suc k)
→∙ coHomK-ptd ((suc n) +' ((suc m) +' (suc k))) ∙)
fst (fst (assocer n m k x) y) z = x ⌣ₖ (y ⌣ₖ z)
snd (fst (assocer n m k x) y) = cong (x ⌣ₖ_) (⌣ₖ-0ₖ _ (suc k) y) ∙ ⌣ₖ-0ₖ _ _ x
snd (assocer n m k x) =
ΣPathP (funExt (λ z → cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) z) ∙ ⌣ₖ-0ₖ (suc n) _ x)
, help)
where
h : (n m k : ℕ) (x : coHomK (suc n)) → cong (_⌣ₖ_ x) (⌣ₖ-0ₖ (suc m) (suc k) (0ₖ _)) ≡
(λ i → x ⌣ₖ 0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _) i)
h zero zero k x = refl
h zero (suc m) k x = refl
h (suc n) zero k x = refl
h (suc n) (suc m) k x = refl
help : PathP (λ i → (cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) i ≡ 0ₖ _)
(cong (x ⌣ₖ_) (⌣ₖ-0ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) refl
help = compPathR→PathP
(cong (_∙ ⌣ₖ-0ₖ (suc n) ((suc m) +' (suc k)) x) (h n m k x)
∙∙ rUnit _
∙∙ cong ((cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) ∙_) (rUnit refl))
assoc2-sub : (n m k : ℕ) → _ → _
assoc2-sub n m k = subst coHomK (sym (+'-assoc n m k))
assoc2-sub-0 : (n m k : ℕ) → assoc2-sub n m k (0ₖ _) ≡ 0ₖ _
assoc2-sub-0 zero zero zero = refl
assoc2-sub-0 zero zero (suc zero) = refl
assoc2-sub-0 zero zero (suc (suc k)) = refl
assoc2-sub-0 zero (suc zero) zero = refl
assoc2-sub-0 zero (suc zero) (suc k) = refl
assoc2-sub-0 zero (suc (suc m)) zero = refl
assoc2-sub-0 zero (suc (suc m)) (suc k) = refl
assoc2-sub-0 (suc zero) zero zero = refl
assoc2-sub-0 (suc zero) zero (suc k) = refl
assoc2-sub-0 (suc (suc n)) zero zero = refl
assoc2-sub-0 (suc (suc n)) zero (suc k) = refl
assoc2-sub-0 (suc zero) (suc m) zero = refl
assoc2-sub-0 (suc (suc n)) (suc m) zero = refl
assoc2-sub-0 (suc zero) (suc m) (suc k) = refl
assoc2-sub-0 (suc (suc n)) (suc m) (suc k) = refl
assocer2 : (n m k : ℕ)
→ coHomK (suc n)
→ coHomK-ptd (suc m) →∙ (coHomK-ptd (suc k) →∙ coHomK-ptd ((suc n) +' ((suc m) +' (suc k))) ∙)
fst (fst (assocer2 n m k x) y) z =
subst coHomK (sym (+'-assoc (suc n) (suc m) (suc k))) ((x ⌣ₖ y) ⌣ₖ z) --
snd (fst (assocer2 zero m k x) y) =
cong (subst coHomK (sym (+'-assoc 1 (suc m) (suc k)))) (⌣ₖ-0ₖ _ _ (x ⌣ₖ y))
snd (fst (assocer2 (suc n) m k x) y) =
cong (subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k)))) (⌣ₖ-0ₖ _ _ (x ⌣ₖ y))
fst (snd (assocer2 zero m k x) i) z =
subst coHomK (sym (+'-assoc (suc zero) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ x i ⌣ₖ z)
snd (snd (assocer2 zero m k x) i) j =
subst coHomK (sym (+'-assoc (suc zero) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ (⌣ₖ-0ₖ _ _ x i) j)
fst (snd (assocer2 (suc n) m k x) i) z =
subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ x i ⌣ₖ z)
snd (snd (assocer2 (suc n) m k x) i) j =
subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ (⌣ₖ-0ₖ _ _ x i) j)
assocer-helpFun : (n m : ℕ) → coHomK (suc n) → coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m)))
fst (assocer-helpFun n m a) b = Kn→ΩKn+1 _ (a ⌣ₖ b)
snd (assocer-helpFun n m a) = cong (Kn→ΩKn+1 _) (⌣ₖ-0ₖ (suc n) (suc m) a) ∙ Kn→ΩKn+10ₖ _
assocer-helpFun2 : (n m : ℕ) → coHomK (suc n) → coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m)))
fst (assocer-helpFun2 n m a) b i = (Kn→ΩKn+1 _ a i) ⌣ₖ b
snd (assocer-helpFun2 n m a) i j = ⌣ₖ-0ₖ _ (suc m) (Kn→ΩKn+1 _ a j) i
-- Key lemma for associativity
assocer-helpFun≡ : (n m : ℕ) → (x : coHomK (suc n)) → assocer-helpFun n m x ≡ assocer-helpFun2 n m x
assocer-helpFun≡ n m =
T.elim (λ _ → isOfHLevelPath (3 + n) (hLev-assocer-helpFun n m) _ _)
λ a → →∙Homogeneous≡ (subst isHomogeneous Kn≃ΩKn+1∙ (isHomogeneousKn _))
(funExt (main n a))
where
hLev-assocer-helpFun : (n m : ℕ) → isOfHLevel (3 + n) (coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m))))
hLev-assocer-helpFun n m =
subst (isOfHLevel (3 + n)) (cong (coHomK-ptd (suc m) →∙_)
(Kn≃ΩKn+1∙))
(isOfHLevel↑∙ (suc n) m)
main : (n : ℕ) (a : S₊ (suc n)) (b : _)
→ fst (assocer-helpFun n m ∣ a ∣) b ≡ fst (assocer-helpFun2 n m ∣ a ∣) b
main zero a b k i =
hcomp
(λ r → λ {(i = i0) → 0ₖ _
; (i = i1) → ∣ rCancel (merid north) r (~ k) ∣
; (k = i0) → Kn→ΩKn+1 _ (∣ a ∣ ⌣ₖ b) i
; (k = i1) → (Kn→ΩKn+1 _ ∣ a ∣ i) ⌣ₖ b})
(∣ compPath-filler (merid a) (sym (merid base)) k i ∣ ⌣ₖ b)
main (suc n) a b k i =
hcomp
(λ r → λ {(i = i0) → 0ₖ _
; (i = i1) → ∣ rCancel (merid north) r (~ k) ∣
; (k = i0) → Kn→ΩKn+1 _ (∣ a ∣ ⌣ₖ b) i
; (k = i1) → (Kn→ΩKn+1 _ ∣ a ∣ i) ⌣ₖ b})
(∣ compPath-filler (merid a) (sym (merid north)) k i ∣ ⌣ₖ b)
assoc-helper : (n m : ℕ) (x : coHomK (suc n)) (y : coHomK (suc m))
→ Kn→ΩKn+1 _ (x ⌣ₖ y) ≡ λ i → (Kn→ΩKn+1 _ x i) ⌣ₖ y
assoc-helper n m x y = funExt⁻ (cong fst (assocer-helpFun≡ n m x)) y
assoc-⌣ₖ· : (n m k : ℕ) → (x : coHomK (suc n)) → assocer n m k x ≡ assocer2 n m k x
assoc-⌣ₖ· n m k =
T.elim (λ _ → isOfHLevelPath (3 + n)
(transport (λ i → isOfHLevel (3 + n)
(coHomK-ptd (suc m) →∙ (coHomK-ptd (suc k) →∙ coHomK-ptd (h (~ i)) ∙)))
(isOfHLevel↑∙∙ m k (suc n))) _ _)
λ a → →∙Homogeneous≡ (isHomogeneous→∙ (isHomogeneousKn _))
(funExt λ b → →∙Homogeneous≡ (isHomogeneousKn _)
(funExt (main n m k a b)))
where
h : (suc n) +' ((suc m) +' (suc k)) ≡ suc (suc (suc n + m + k))
h = cong (2 +_) (+-suc n (m + k)) ∙ λ i → suc (suc (suc (+-assoc n m k i)))
main : (n m k : ℕ) (a : S₊ (suc n)) (b : coHomK (suc m)) (c : coHomK (suc k))
→ ∣ a ∣ ⌣ₖ b ⌣ₖ c ≡
(subst coHomK (λ i → +'-assoc (suc n) (suc m) (suc k) (~ i))
((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
main zero m k a b c = goal a ∙ sym (funExt⁻ t ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
where
t : subst coHomK (λ i → +'-assoc 1 (suc m) (suc k) (~ i)) ≡ idfun _
t = cong (subst coHomK) (isSetℕ _ _ (+'-assoc 1 (suc m) (suc k)) refl) ∙ funExt transportRefl
goal : (a : _) → ∣ a ∣ ⌣ₖ b ⌣ₖ c ≡ (∣ a ∣ ⌣ₖ b) ⌣ₖ c
goal base = refl
goal (loop i) j = assoc-helper m k b c j i
main (suc n) m k north b c = refl
main (suc n) m k south b c = refl
main (suc n) m k (merid a i) b c j = help2 j i
where
transpLem : (n m : ℕ) (p : n ≡ m) → subst coHomK p (0ₖ _) ≡ 0ₖ _
transpLem zero m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem (suc zero) m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem (suc (suc n)) m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem-refl : transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) ≡ refl
transpLem-refl = transportRefl refl
moveTransports : (n m : ℕ) (x : coHomK n) (p : n ≡ m) (q : (suc n) ≡ suc m)
→ PathP (λ i → transpLem _ _ q (~ i) ≡ transpLem _ _ q (~ i))
(Kn→ΩKn+1 _ (subst coHomK p x))
(cong (subst coHomK q) (Kn→ΩKn+1 _ x))
moveTransports n m x =
J (λ m p → (q : (suc n) ≡ suc m)
→ PathP (λ i → transpLem _ _ q (~ i) ≡ transpLem _ _ q (~ i))
(Kn→ΩKn+1 _ (subst coHomK p x))
(cong (subst coHomK q) (Kn→ΩKn+1 _ x)))
λ q → transport (λ j → PathP (λ i → transpLem (suc n) (suc n) (isSetℕ _ _ refl q j) (~ i)
≡ transpLem (suc n) (suc n) (isSetℕ _ _ refl q j) (~ i))
(Kn→ΩKn+1 _ (subst coHomK refl x))
(cong (subst coHomK (isSetℕ _ _ refl q j)) (Kn→ΩKn+1 _ x)))
(h2 n x)
where
h2 : (n : ℕ) (x : _)
→ PathP (λ i₁ →
transpLem (suc n) (suc n) (λ _ → suc n) (~ i₁) ≡
transpLem (suc n) (suc n) (λ _ → suc n) (~ i₁))
(Kn→ΩKn+1 n (subst coHomK (λ _ → n) x))
(λ i₁ → subst coHomK (λ _ → suc n) (Kn→ΩKn+1 n x i₁))
h2 zero x k i =
hcomp (λ j → λ {(i = i0) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (i = i1) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (k = i0) → Kn→ΩKn+1 _ (transportRefl x j) i
; (k = i1) → transportRefl (Kn→ΩKn+1 _ x i) (~ j)})
(Kn→ΩKn+1 _ x i)
h2 (suc n) x k i =
hcomp (λ j → λ {(i = i0) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (i = i1) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (k = i0) → Kn→ΩKn+1 _ (transport refl x) i
; (k = i1) → transportRefl (Kn→ΩKn+1 _ x i) (~ j)})
(Kn→ΩKn+1 _ (transportRefl x k) i)
finalTransp : (n : ℕ) (a : _) → Kn→ΩKn+1 _ (subst coHomK (λ i₁ → +'-assoc (suc n) (suc m) (suc k) (~ i₁)) ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
≡ cong (subst coHomK (λ i₁ → +'-assoc (2 + n) (suc m) (suc k) (~ i₁))) (Kn→ΩKn+1 _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
finalTransp n a =
rUnit _
∙∙ (λ i → (λ j → transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) (i ∧ j))
∙∙ moveTransports _ _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c)
(sym (+'-assoc (suc n) (suc m) (suc k)))
(sym (+'-assoc (2 + n) (suc m) (suc k))) i
∙∙ λ j → transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) (i ∧ ~ j))
∙∙ (λ i → transportRefl refl i
∙∙ cong (subst coHomK (λ i₁ → +'-assoc (2 + n) (suc m) (suc k) (~ i₁))) (Kn→ΩKn+1 _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
∙∙ transportRefl refl i)
∙ sym (rUnit _)
help2 : cong (λ x → (∣ x ∣) ⌣ₖ (b ⌣ₖ c)) (merid a) ≡ cong (assoc2-sub (2 + n) (suc m) (suc k)) (cong (λ x → (∣ x ∣ ⌣ₖ b) ⌣ₖ c) (merid a))
help2 = ((λ r → Kn→ΩKn+1 _ (main n m k a b c r)))
∙∙ finalTransp n a
∙∙ λ r i → subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (assoc-helper _ _ (∣ a ∣ ⌣ₖ b) c r i)
-- Some key distributivity lemmas
-Distₗ : (n m : ℕ) (x : coHomK n) (y : coHomK m) → (-ₖ (x ⌣ₖ y)) ≡ (-ₖ x) ⌣ₖ y
-Distₗ n m x y =
sym (rUnitₖ _ (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ (x ⌣ₖ y)) +ₖ_) (sym (rCancelₖ _ (x ⌣ₖ y)))
∙∙ assocₖ _ (-ₖ (x ⌣ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y))
∙∙ cong (_-ₖ (x ⌣ₖ y)) help
∙∙ sym (assocₖ _ ((-ₖ x) ⌣ₖ y) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ x) ⌣ₖ y +ₖ_) (rCancelₖ _ (x ⌣ₖ y))
∙∙ rUnitₖ _ ((-ₖ x) ⌣ₖ y)
where
help : (-ₖ (x ⌣ₖ y)) +ₖ (x ⌣ₖ y) ≡ (-ₖ x) ⌣ₖ y +ₖ (x ⌣ₖ y)
help = lCancelₖ _ _
∙∙ sym (0ₖ-⌣ₖ _ _ y)
∙ cong (_⌣ₖ y) (sym (lCancelₖ _ x))
∙∙ rightDistr-⌣ₖ _ _ (-ₖ x) x y
-Distᵣ : (n m : ℕ) (x : coHomK n) (y : coHomK m) → (-ₖ (x ⌣ₖ y)) ≡ x ⌣ₖ (-ₖ y)
-Distᵣ n m x y =
sym (rUnitₖ _ (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ (x ⌣ₖ y)) +ₖ_) (sym (rCancelₖ _ (x ⌣ₖ y)))
∙∙ assocₖ _ (-ₖ (x ⌣ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y))
∙∙ cong (_-ₖ (x ⌣ₖ y)) help
∙∙ sym (assocₖ _ (x ⌣ₖ (-ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y)))
∙∙ cong (x ⌣ₖ (-ₖ y) +ₖ_) (rCancelₖ _ (x ⌣ₖ y))
∙∙ rUnitₖ _ (x ⌣ₖ (-ₖ y))
where
help : (-ₖ (x ⌣ₖ y)) +ₖ (x ⌣ₖ y) ≡ x ⌣ₖ (-ₖ y) +ₖ (x ⌣ₖ y)
help = lCancelₖ _ _
∙∙ sym (⌣ₖ-0ₖ _ _ x)
∙∙ cong (x ⌣ₖ_) (sym (lCancelₖ _ y))
∙ leftDistr-⌣ₖ _ _ x (-ₖ y) y
assoc₀ : (m k : ℕ) (x : ℤ) (y : coHomK m) (z : coHomK k) → _⌣ₖ_{n = zero} x (y ⌣ₖ z) ≡ (_⌣ₖ_{n = zero} {m = m} x y) ⌣ₖ z
assoc₀ m k x y z = main x
where
h : subst coHomK (sym (+'-assoc zero m k)) ≡ idfun _
h = cong (subst coHomK) (isSetℕ _ _ _ refl) ∙ funExt transportRefl
mainPos : (x : ℕ) → _⌣ₖ_ {n = zero} (pos x) (y ⌣ₖ z) ≡ ((_⌣ₖ_ {n = zero} {m = m} (pos x) y) ⌣ₖ z)
mainPos zero = sym (0ₖ-⌣ₖ _ _ z) ∙ cong (_⌣ₖ z) (sym (0ₖ-⌣ₖ _ _ y))
mainPos (suc n) =
cong (y ⌣ₖ z +ₖ_) (mainPos n)
∙∙ sym (rightDistr-⌣ₖ _ _ y (_⌣ₖ_ {n = zero} {m = m} (pos n) y) z)
∙∙ (λ i → (y +ₖ (_⌣ₖ_ {n = zero} {m = m} (pos n) y)) ⌣ₖ z)
main : (x : ℤ) → x ⌣ₖ y ⌣ₖ z ≡ ((_⌣ₖ_ {n = zero} {m = m} x y) ⌣ₖ z)
main (pos n) = mainPos n
main (negsuc n) =
(λ i → _⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 i) (y ⌣ₖ z))
∙∙ sym (-Distₗ zero _ (pos (suc n)) (y ⌣ₖ z))
∙ cong (-ₖ_) (mainPos (suc n))
∙∙ -Distₗ _ _ (pos (suc n) ⌣ₖ y) z
∙∙ cong (_⌣ₖ z) ((-Distₗ zero _ (pos (suc n)) y))
∙∙ λ i → (_⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 (~ i)) y) ⌣ₖ z
assoc-⌣ₖ : (n m k : ℕ) (x : coHomK n) (y : coHomK m) (z : coHomK k)
→ x ⌣ₖ y ⌣ₖ z ≡ subst coHomK (sym (+'-assoc n m k)) ((x ⌣ₖ y) ⌣ₖ z)
assoc-⌣ₖ zero m k x y z = assoc₀ _ _ x y z ∙ sym (funExt⁻ h ((x ⌣ₖ y) ⌣ₖ z))
where
h : subst coHomK (sym (+'-assoc zero m k)) ≡ idfun _
h = cong (subst coHomK) (isSetℕ _ _ _ refl) ∙ funExt transportRefl
assoc-⌣ₖ (suc n) zero k x y z =
help y
∙∙ sym (transportRefl ((x ⌣ₖ y) ⌣ₖ z))
∙∙ λ i → transport (λ j → coHomK ((isSetℕ _ _ ((sym (+'-assoc (suc n) zero k))) refl (~ i) j)))
((_⌣ₖ_ {m = zero} x y) ⌣ₖ z)
where
helpPos : (y : ℕ) → x ⌣ₖ (_⌣ₖ_ {n = zero} (pos y) z) ≡
((_⌣ₖ_ {m = zero} x (pos y)) ⌣ₖ z)
helpPos zero =
(⌣ₖ-0ₖ _ _ x)
∙∙ (sym (0ₖ-⌣ₖ _ _ z))
∙∙ cong (_⌣ₖ z) (sym (⌣ₖ-0ₖ _ _ x))
helpPos (suc y) =
leftDistr-⌣ₖ _ _ x z (_⌣ₖ_{n = zero} (pos y) z)
∙∙ cong ((x ⌣ₖ z) +ₖ_) (helpPos y)
∙∙ sym (rightDistr-⌣ₖ _ _ x (_⌣ₖ_{n = zero} (pos y) x) z)
help : (y : ℤ) → x ⌣ₖ (_⌣ₖ_ {n = zero} y z) ≡
((_⌣ₖ_ {m = zero} x y) ⌣ₖ z)
help (pos n) = helpPos n
help (negsuc n) =
(λ i → x ⌣ₖ (_⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 i) z))
∙∙ cong (x ⌣ₖ_) (sym (-Distₗ zero _ (pos (suc n)) z))
∙∙ sym (-Distᵣ _ _ x _)
∙∙ cong -ₖ_ (helpPos (suc n))
∙∙ -Distₗ _ _ _ z
∙∙ cong (_⌣ₖ z) (-Distᵣ _ zero x (pos (suc n)))
∙∙ λ i → (_⌣ₖ_ {m = zero} x (+ℤ-comm (negsuc n) 0 (~ i))) ⌣ₖ z
assoc-⌣ₖ (suc n) (suc m) zero x y z =
(assoc-⌣ₖ (suc n) zero (suc m) x z y)
∙∙ cong (subst coHomK (sym (+'-assoc (suc n) zero (suc m))))
(sym (assoc₀ _ _ z x y))
∙∙ (funExt⁻ (sym h) (_⌣ₖ_ {n = zero} z (x ⌣ₖ y)))
where
h : subst coHomK (sym (+'-assoc (suc n) (suc m) zero))
≡ subst coHomK (λ i → +'-assoc (suc n) zero (suc m) (~ i))
h = cong (subst coHomK) (isSetℕ _ _ _ _)
assoc-⌣ₖ (suc n) (suc m) (suc k) x y z =
funExt⁻ (cong fst (funExt⁻ (cong fst (assoc-⌣ₖ· n m k x)) y)) z
-- Ring laws for ⌣
module _ {A : Type ℓ} (n m : ℕ) where
⌣-0ₕ : (f : coHom n A) → (f ⌣ 0ₕ m) ≡ 0ₕ _
⌣-0ₕ = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → ⌣ₖ-0ₖ n m (f x))
0ₕ-⌣ : (f : coHom m A) → (0ₕ n ⌣ f) ≡ 0ₕ _
0ₕ-⌣ = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → 0ₖ-⌣ₖ n m (f x))
leftDistr-⌣ : (f : coHom n A) (g h : coHom m A)
→ f ⌣ (g +ₕ h) ≡ f ⌣ g +ₕ f ⌣ h
leftDistr-⌣ =
ST.elim (λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → ST.elim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ g h → cong ∣_∣₂ (funExt λ x → leftDistr-⌣ₖ n m (f x) (g x) (h x))
rightDistr-⌣ : (g h : coHom n A) (f : coHom m A) → (g +ₕ h) ⌣ f ≡ g ⌣ f +ₕ h ⌣ f
rightDistr-⌣ =
ST.elim2 (λ _ _ → isSetΠ (λ _ → isOfHLevelPath 2 squash₂ _ _))
λ g h → ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → rightDistr-⌣ₖ n m (g x) (h x) (f x))
assoc-⌣ : (l : ℕ) (f : coHom n A) (g : coHom m A) (h : coHom l A)
→ f ⌣ g ⌣ h ≡ subst (λ x → coHom x A) (sym (+'-assoc n m l)) ((f ⌣ g) ⌣ h)
assoc-⌣ l =
ST.elim (λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → ST.elim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g → ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _) λ h →
cong ∣_∣₂ ((funExt (λ x → assoc-⌣ₖ n m l (f x) (g x) (h x)
∙ cong (subst coHomK (sym (+'-assoc n m l)))
λ i → (f (transportRefl x (~ i)) ⌣ₖ g (transportRefl x (~ i)))
⌣ₖ (h (transportRefl x (~ i))))))
-- Additive unit(s)
0⌣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ) (x : coHom n A)
→ x ⌣ (0ₕ m) ≡ 0ₕ _
0⌣ n m = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → ⌣ₖ-0ₖ n m (f x))
⌣0 : ∀ {ℓ} {A : Type ℓ} (n m : ℕ) (x : coHom n A)
→ (0ₕ m) ⌣ x ≡ 0ₕ _
⌣0 n m = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → 0ₖ-⌣ₖ m n (f x))
-- Multiplicative unit
1⌣ : ∀ {ℓ} {A : Type ℓ} → coHom 0 A
1⌣ = ∣ (λ _ → 1) ∣₂
n+'0 : (n : ℕ) → n +' 0 ≡ n
n+'0 zero = refl
n+'0 (suc n) = refl
lUnit⌣ₖ : (n : ℕ) (x : coHomK n) → _⌣ₖ_ {n = 0} (pos 1) x ≡ x
lUnit⌣ₖ zero = λ _ → refl
lUnit⌣ₖ (suc n) x = rUnitₖ _ x
lUnit⌣ : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (x : coHom n A)
→ x ⌣ 1⌣ ≡ subst (λ n → coHom n A) (sym (n+'0 n)) x
lUnit⌣ zero = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt (λ x → comm-·₀ (f x) (pos 1))) ∙ sym (transportRefl ∣ f ∣₂)
lUnit⌣ (suc n) =
ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) (0ₖ-⌣ₖ zero _ (f x)) ∙ rUnitₖ _ (f x)))
∙ sym (transportRefl ∣ f ∣₂)
rUnit⌣ : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (x : coHom n A)
→ 1⌣ ⌣ x ≡ x
rUnit⌣ zero = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → refl
rUnit⌣ (suc n) =
ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → rUnitₖ _ (f x))
-ₕDistᵣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ (x ⌣ y)) ≡ x ⌣ (-ₕ y)
-ₕDistᵣ n m =
ST.elim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → cong ∣_∣₂ (funExt λ x → -Distᵣ n m (f x) (g x))
-ₕDistₗ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ (x ⌣ y)) ≡ (-ₕ x) ⌣ y
-ₕDistₗ n m =
ST.elim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → cong ∣_∣₂ (funExt λ x → -Distₗ n m (f x) (g x))
-ₕDistₗᵣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ x) ⌣ (-ₕ y) ≡ x ⌣ y
-ₕDistₗᵣ n m x y =
sym (-ₕDistₗ n m x (-ₕ y))
∙∙ cong -ₕ_ (sym (-ₕDistᵣ n m x y))
∙∙ ST.elim2 {C = λ x y → (-ₕ (-ₕ (x ⌣ y))) ≡ x ⌣ y}
(λ _ _ → isSetPathImplicit)
(λ f g → cong ∣_∣₂ (funExt λ _ → -ₖ^2 _)) x y
-- TODO : Graded ring structure
| 43.054834
| 143
| 0.477763
|
4143716d5cbefb0ac3aa85a7fc9bbeda3776ba79
| 423
|
agda
|
Agda
|
function/overloading.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 27
|
2015-04-14T15:47:03.000Z
|
2022-01-09T07:26:57.000Z
|
src/function/overloading.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
function/overloading.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 4
|
2015-04-11T17:19:12.000Z
|
2019-02-26T06:17:38.000Z
|
{-# OPTIONS --without-K #-}
module function.overloading {i j}{X : Set i}{Y : Set j} where
open import level
open import sum
open import overloading.core
fun-is-fun : Coercion (X → Y) (X → Y)
fun-is-fun = coerce-self _
private
module fun-methods {k}{Source : Set k}
⦃ c : Coercion Source (X → Y) ⦄ where
open Coercion c public using ()
renaming (coerce to apply)
open fun-methods public
| 23.5
| 61
| 0.638298
|
2e4a5934a02b7f4f31cffdd0c2852f9bae093e51
| 10,259
|
agda
|
Agda
|
Cubical/ZCohomology/Groups/Torus.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Groups/Torus.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Groups/Torus.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.ZCohomology.Groups.Torus where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.Groups.Connected
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.Groups.Prelims
open import Cubical.ZCohomology.KcompPrelims
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma
open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +-comm to +ℤ-comm ; +-assoc to +ℤ-assoc)
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
open import Cubical.HITs.Pushout
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2) hiding (map)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim2 to pElim2 ; ∣_∣ to ∣_∣₁) hiding (map)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Truncation renaming (elim to trElim ; elim2 to trElim2 ; map to trMap ; rec to trRec)
open GroupHom
open GroupIso
private
module congLemma (key : Unit') where
module K = lockedCohom key
main : (n : ℕ) (p : Path (coHomK n) (0ₖ n) (0ₖ n))
→ Path (K.+K n (0ₖ n) (0ₖ n) ≡ K.+K n (0ₖ n) (0ₖ n))
(cong (K.+K n (0ₖ n)) p) (cong (λ x → K.+K n x (0ₖ n)) p)
main n = congIdLeft≡congIdRight (K.+K n) (K.-K n) (0ₖ n) (K.rUnitK n) (K.lUnitK n) (rUnitlUnit0K key n)
--------- H⁰(T²) ------------
H⁰-T²≅ℤ : GroupIso (coHomGr 0 (S₊ 1 × S₊ 1)) intGroup
H⁰-T²≅ℤ =
H⁰-connected (base , base)
λ (a , b) → pRec propTruncIsProp
(λ id1 → pRec propTruncIsProp
(λ id2 → ∣ ΣPathP (id1 , id2) ∣₁)
(Sn-connected 0 b) )
(Sn-connected 0 a)
--------- H¹(T²) -------------------------------
H¹-T²≅ℤ×ℤ : GroupIso (coHomGr 1 ((S₊ 1) × (S₊ 1))) (dirProd intGroup intGroup)
H¹-T²≅ℤ×ℤ = theIso □ dirProdGroupIso (invGroupIso (Hⁿ-Sⁿ≅ℤ 0)) (H⁰-Sⁿ≅ℤ 0)
where
helper : (x : hLevelTrunc 3 (S₊ 1)) → ∣ (S¹map x) ∣ ≡ x
helper = trElim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _)
λ a → refl
typIso : Iso _ _
typIso = setTruncIso (curryIso ⋄ codomainIso S1→K₁≡S1×Int ⋄ toProdIso)
⋄ setTruncOfProdIso
theIso : GroupIso _ _
fun (map theIso) = Iso.fun (typIso)
isHom (map theIso) =
sElim2 (λ _ _ → isOfHLevelPath 2 (isOfHLevelΣ 2 setTruncIsSet (λ _ → setTruncIsSet)) _ _)
λ f g → ΣPathP ((cong ∣_∣₂
(funExt (λ x → helper (f (x , base) +ₖ g (x , base))
∙ sym (cong₂ (λ x y → x +ₖ y)
(helper (f (x , base)))
(helper (g (x , base))))))) ,
(cong ∣_∣₂
(funExt
(toPropElim
(λ _ → isSetInt _ _)
(cong winding
(basechange-lemma2
(λ x → f (base , x))
(λ x → g (base , x))
λ x → S¹map x)
∙∙ winding-hom
(basechange2⁻
(S¹map (f (base , base)))
(λ i → S¹map (f (base , (loop i)))))
(basechange2⁻
(S¹map (g (base , base)))
(λ i → S¹map (g (base , (loop i)))))
∙∙ sym (addLemma
(winding
(basechange2⁻
(S¹map (f (base , base)))
(λ i → S¹map (f (base , (loop i))))))
(winding
(basechange2⁻
(S¹map (g (base , base)))
(λ i → S¹map (g (base , (loop i))))))))))))
inv theIso = Iso.inv typIso
rightInv theIso = Iso.rightInv typIso
leftInv theIso = Iso.leftInv typIso
----------------------- H²(T²) ------------------------------
open import Cubical.Foundations.Equiv
H²-T²≅ℤ : GroupIso (coHomGr 2 (S₊ 1 × S₊ 1)) intGroup
H²-T²≅ℤ = invGroupIso (ℤ≅H²-T² unlock)
where
module _ (key : Unit') where
module K = lockedCohom key
private
_+K_ : {n : ℕ} → coHomK n → coHomK n → coHomK n
_+K_ {n = n} = K.+K n
-K_ : {n : ℕ} → coHomK n → coHomK n
-K_ {n = n} = K.-K n
-H_ : {A : Type₀} {n : ℕ} → coHom n A → coHom n A
-H_ {n = n} = K.-H n
_+H_ : {A : Type₀} {n : ℕ} → coHom n A → coHom n A → coHom n A
_+H_ {n = n} = K.+H n
typIso : Iso _ _
typIso = helper
⋄ (invIso (prodIso (GroupIso→Iso (Hⁿ-S¹≅0 0))
(invIso (GroupIso→Iso (Hⁿ-Sⁿ≅ℤ 0))))
⋄ ((invIso setTruncOfProdIso)
⋄ (invIso (setTruncIso (curryIso
⋄ codomainIso (S1→K2≡K2×K1' key)
⋄ toProdIso)))))
where
helper : Iso Int (Unit × Int)
Iso.inv helper = snd
Iso.fun helper x = tt , x
Iso.leftInv helper _ = refl
Iso.rightInv helper _ = refl
mapIsHom : (x y : Int)
→ Iso.fun typIso (x +ℤ y) ≡ ((Iso.fun typIso x) +H Iso.fun typIso y)
mapIsHom a b =
(cong f ((GroupHom.isHom (GroupIso.map (invGroupIso (dirProdGroupIso (Hⁿ-S¹≅0 0) (invGroupIso (Hⁿ-Sⁿ≅ℤ 0)))))
(_ , a) (_ , b))
∙ λ i → guyId i , +H≡+ₕ key _ (~ i) (g a) (g b)))
∙∙ helper (g a) (g b)
∙∙ cong₂ (_+H_) (λ i → f (guyId2 (~ i) , g a)) λ i → f (guyId2 (~ i) , g b)
where
f = Iso.fun (((invIso setTruncOfProdIso ⋄ invIso (setTruncIso (curryIso ⋄ codomainIso (S1→K2≡K2×K1' key) ⋄ toProdIso)))))
g = GroupIso.inv (invGroupIso (Hⁿ-Sⁿ≅ℤ 0))
isPropH²-S¹ : isProp (coHom 2 (S₊ 1))
isPropH²-S¹ = isPropRetract (fun (map (Hⁿ-S¹≅0 0)))
(inv (Hⁿ-S¹≅0 0))
(leftInv (Hⁿ-S¹≅0 0))
isPropUnit
guyId : ∣ _ ∣₂ ≡ 0ₕ 2
guyId = isPropH²-S¹ _ _
guyId2 : ∣ _ ∣₂ ≡ 0ₕ 2
guyId2 = isPropH²-S¹ _ _
helper : (x y : ∥ ((S₊ 1) → (hLevelTrunc 3 (S₊ 1) )) ∥₂) →
f ((0ₕ 2) , (x +H y)) ≡ f ((0ₕ 2) , x) +H f (0ₕ 2 , y)
helper =
sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f g i → ∣ (λ x → helper2 (f (fst x)) (g (fst x)) (snd x) i) ∣₂
where
helper2 : (x y : coHomK 1) (s : S₊ 1)
→ Iso.inv (S1→K2≡K2×K1' key) (0ₖ 2 , x +K y) s ≡ (Iso.inv (S1→K2≡K2×K1' key) (0ₖ 2 , x)) s +K (Iso.inv (S1→K2≡K2×K1' key) (0ₖ 2 , y)) s
helper2 =
trElim2 (λ _ _ → isOfHLevelΠ 3 λ _ → isOfHLevelTrunc 4 _ _)
λ a b → λ {base → cong₂ (_+K_) (sym (K.lUnitK _ 0₂)) (sym (K.lUnitK _ 0₂))
; (loop i) j → hcomp (λ k → λ{ (i = i0) → cong₂ (_+K_) (sym (K.lUnitK _ 0₂)) (sym (K.lUnitK _ 0₂)) (j ∧ k)
; (i = i1) → cong₂ (_+K_) (sym (K.lUnitK _ 0₂)) (sym (K.lUnitK _ 0₂)) (j ∧ k)
; (j = i0) → 0₂ +K (Kn→ΩKn+1 1 (∣ a ∣ +K ∣ b ∣) i)
; (j = i1) → cong₂ (_+K_) (sym (K.lUnitK _ (Kn→ΩKn+1 1 ∣ a ∣ i)))
(sym (K.lUnitK _ (Kn→ΩKn+1 1 ∣ b ∣ i))) k})
(helper3 ∣ a ∣ ∣ b ∣ j i)}
where
helper3 : (a b : coHomK 1) → cong (0₂ +K_) (Kn→ΩKn+1 1 (a +K b)) ≡ cong₂ (_+K_) (Kn→ΩKn+1 1 a) (Kn→ΩKn+1 1 b)
helper3 a b = cong (cong (0₂ +K_)) (+K→∙ key 1 a b)
∙ (congFunct (0₂ +K_) (Kn→ΩKn+1 1 a) (Kn→ΩKn+1 1 b)
∙∙ (λ i → congLemma.main key 2 (Kn→ΩKn+1 1 a) i ∙ cong (_+K_ ∣ north ∣) (λ i → Kn→ΩKn+1 1 b i))
∙∙ sym (cong₂Funct (_+K_) (Kn→ΩKn+1 1 a) (Kn→ΩKn+1 1 b)))
ℤ≅H²-T² : GroupIso intGroup (coHomGr 2 (S₊ 1 × S₊ 1))
fun (map ℤ≅H²-T²) = Iso.fun typIso
isHom (map ℤ≅H²-T²) = pm key mapIsHom
where
pm : (t : Unit')
→ ((x y : Int)
→ Iso.fun typIso (x +ℤ y) ≡ (lockedCohom.+H t _ (Iso.fun typIso x) (Iso.fun typIso y)))
→ isGroupHom intGroup (coHomGr 2 (S₊ 1 × S₊ 1)) (Iso.fun typIso)
pm unlock p = p
inv ℤ≅H²-T² = Iso.inv typIso
rightInv ℤ≅H²-T² = Iso.rightInv typIso
leftInv ℤ≅H²-T² = Iso.leftInv typIso
private
to₂ : coHom 2 (S₊ 1 × S₊ 1) → Int
to₂ = fun (map H²-T²≅ℤ)
from₂ : Int → coHom 2 (S₊ 1 × S₊ 1)
from₂ = inv H²-T²≅ℤ
to₁ : coHom 1 (S₊ 1 × S₊ 1) → Int × Int
to₁ = fun (map H¹-T²≅ℤ×ℤ)
from₁ : Int × Int → coHom 1 (S₊ 1 × S₊ 1)
from₁ = inv H¹-T²≅ℤ×ℤ
to₀ : coHom 0 (S₊ 1 × S₊ 1) → Int
to₀ = fun (map H⁰-T²≅ℤ)
from₀ : Int → coHom 0 (S₊ 1 × S₊ 1)
from₀ = inv H⁰-T²≅ℤ
{-
-- Compute fast:
test : to₁ (from₁ (0 , 1) +ₕ from₁ (1 , 0)) ≡ (1 , 1)
test = refl
test2 : to₁ (from₁ (5 , 1) +ₕ from₁ (-2 , 3)) ≡ (3 , 4)
test2 = refl
-- Will not compute:
test3 : to₂ (from₂ 0) ≡ 0
test3 = refl
-}
| 42.745833
| 152
| 0.45716
|
c710fa4c6b51730268ad49fe9eb0f0e5f60540a6
| 118
|
agda
|
Agda
|
test/Succeed/Issue4265b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4265b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4265b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --no-syntactic-equality #-}
open import Agda.Primitive
variable
ℓ : Level
A : Set ℓ
P : A → Set ℓ
| 13.111111
| 39
| 0.627119
|
1aacfe459e80044753bd6c2d508a53ed3dbe8a8a
| 916
|
agda
|
Agda
|
test/Succeed/Issue2455.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue2455.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2455.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2017-02-14 issue #2455 reported by mechvel
-- Test case by Andrea
-- Seem that the fix for issue #44 was not complete.
-- When inserting module parameters for a definition,
-- we need to respect polarities!
-- {-# OPTIONS -v tc.decl:10 -v tc.polarity:70 -v tc.sig.inst:30 #-}
module Issue2455 where
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
data Unit : Set where
unit : Unit
postulate
A : Set
P : A → Set
p : ∀ {e} → P e
module M (e : A) (f : Unit) where
aux : Unit → P e
aux unit = p
-- se does not depent on f
-- se gets type (e : A) (f :{UnusedArg} Unit) -> A
se = e
-- aux' should not depend on f
-- For this to work, the module parameters for se must be
-- respecting UnusedArg.
aux' : Unit → P se
aux' unit = p
works : ∀ x y e → M.aux e x ≡ M.aux e y
works _ _ _ = refl
fails : ∀ x y e → M.aux' e x ≡ M.aux' e y
fails _ _ _ = refl
| 20.818182
| 68
| 0.59607
|
589e52b9eaf50e9636a0e2082e038d3fb49e5ac8
| 505
|
agda
|
Agda
|
theorems/homotopy/3x3/Commutes.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/homotopy/3x3/Commutes.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/homotopy/3x3/Commutes.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
import homotopy.3x3.To as To
import homotopy.3x3.From as From
open import homotopy.3x3.Common
module homotopy.3x3.Commutes {i} (d : Span^2 {i}) where
open Span^2 d
open M using (Pushout^2)
open To d
open From d
open import homotopy.3x3.FromTo
open import homotopy.3x3.ToFrom
abstract
theorem : Pushout^2 d ≃ Pushout^2 (transpose d)
theorem = equiv to from (to-from d) (from-to d)
| 21.956522
| 55
| 0.744554
|
1a6a677c7450952bd5cbc8b96e922ecc10fbc0fe
| 14,643
|
agda
|
Agda
|
LibraBFT/ImplShared/Util/HashCollisions.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/ImplShared/Util/HashCollisions.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/ImplShared/Util/HashCollisions.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.ByteString
open import LibraBFT.Base.PKCS
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Impl.Consensus.BlockStorage.BlockStore
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.Prelude
open import LibraBFT.Yasm.Base
open import LibraBFT.Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms
open import Optics.All
-- This module contains the machinery we use for tracking hash collisions for the hash function
-- postulated in LibraBFT.ImplShared.Util.Crypto. (Note that, although we call it sha256 to remind
-- ourselves that this *represents* a real hash function, in fact it is just postulated and could
-- represent any hash function.) We prove our correctness conditions modulo hash collisions of this
-- function, which is used to derive IDs for Blocks. Therefore, how we model and reason about such
-- collisions is critical to the validity of our proofs.
--
-- A common approach is to simply assume (e.g., postulate or state as an axiom) that the function is
-- injective. While this is a reasonable pragmatic approach, it does raise an important issue.
-- Because practical hash functions have unbounded domains and finite codomains, they are not
-- injective. Therefore, assuming that the function represented by the postulated one is injective
-- amounts to making an unsatisfiable assumption, from which anything can be proved (false implies
-- anything). For this reason, it is not sufficient to show that the desired property holds unless
-- a hash collision *exists*. Instead, we must construct evidence of a *specific* hash collision
-- (i.e., two values and evidence that their hashes are the same but the values themselves are
-- different). Such evidence is captured by the type NonInjective-≡ sha256. Below we elaborate on
-- some subtleties and tradeoffs with what we prove in which contexts.
--
-- First, when we are dealing with *abstract* Records (as in the Abstract and Concrete modules), it
-- is trivial to construct an injectivity failure of Block IDs, simply by constructing two different
-- abstract Blocks that have the same ID. In that context, it is important that we prove our
-- correctness conditions modulo injectivity failures between Blocks that are actually represented
-- in the specific ReachableSystemState about which we're reasoning (because that allows the
-- injectivity failure of IDs of the *abstract* Blocks to be related back to concrete blocks whose
-- IDs are derived using the hash function).
--
-- In contrast, it is far from trivial to construct a specific collision for the *postulated*
-- sha256-cr function. It would be possible to prove that *some* collision *exists* by using a
-- pigeonhole principle counting argument. In principle, one could then construct a specific
-- collision by generating 2 ^ 256 + 1 distinct Records (in case the postulated hash function is
-- assumed to produce 256-bit hashes), and asking for each pair of them whether they hash to the
-- same value. We could eliminate the possibility that none of these pairs provides a collision
-- using the counting argument.
--
-- One could not do this "accidentally" (as could potentially occur with Abstract records), and
-- furthermore, by examining all proofs that use meta-no-collision, it is not difficult to see that
-- the specific collisions are all produced from Records introduced by the proof obligations (i.e.,
-- Records that are in the ReachableSystemState under consideration). Therefore, we do not consider
-- it necessary to explicitly associate any collisions for the postulated hash function with the
-- ReachableSystemState.
--
-- Having received feedback from some people who were uncomfortable with this argument, we have put
-- some effort into explicitly tying each collision to data "in the system" in the
-- ReachableSystemState in question. Our exploration convinces us that it's possible, but
-- reinforces our view that it is not worthwhile; we elaborate on this in comments below.
--
-- Our current position is to keep for illustrative purposes our work so far on explicitly tying
-- some hash collisions to particular Records in the system for some cases, but to continue to
-- simply construct the evidence of the collision in other cases. The two approaches can coexist
-- because proofs can "bail out" when finding a hash collision between Records the proof is
-- considering by invoking either of the postulated functions below (meta-no-collision-in-sys and
-- meta-no-collsion). Both state that there is no collision, so providing evidence of a specific
-- collision is sufficient to bail out of the proof of a condition that might not hold in case of a
-- collision. The first requires the specific elements contributing to the collision to be
-- precisely located within the current ReachableSystemState, while the second requires only
-- evidence of the collision's existence, without specific information about where its elements came
-- from. Below we explain our initial approach for meta-no-collision-in-sys, overview some examples
-- demonstrating the additional proof burden it creates, and also discuss what would be needed to
-- complete this effort, if it were deemed worthwhile.
module LibraBFT.ImplShared.Util.HashCollisions
(iiah : SystemInitAndHandlers ℓ-RoundManager ConcSysParms)
where
open WithInitAndHandlers iiah
-- By placing the constructs below within a module that takes a ReachableSystemState as a module
-- parameter, we ensure that a proof that wants to "bail out" due to a hash collision must specify
-- a ReachableSystemState and show that the specific collision is between elements represented in
-- that state.
module PerReachableState {st} (r : ReachableSystemState st) where
-- The following datatypes are used in the definition of HashCollisionFound below to enumerate
-- the ways in which hash collisions that would undermine correctness can arise in the given
-- state st. Note that we do not need to capture all ways in which a ByteString might be
-- represented, only those for which our proofs require injectivity properties. Our initial
-- work requires capturing hash collisions only for Block IDs.
data _∈Block_ : BSL → Block → Set where
inB : ∀ {b} → blockData-bsl (b ^∙ bBlockData) ∈Block b
open _∈Block_
data _∈ProposalMsg_ (bsl : BSL) (pm : ProposalMsg) : Set where
inPM : bsl ∈Block (pm ^∙ pmProposal) → bsl ∈ProposalMsg pm
open _∈ProposalMsg_
data _∈nm (bsl : BSL) : Set where
inP : ∀ {sndr pm} → (sndr , P pm) ∈ msgPool st → bsl ∈ProposalMsg pm → bsl ∈nm
open _∈nm
-- We could refine this further (∈BlockTree, ∈btIdToBlock), but I don't think we need to.
data _∈BS_ (bsl : BSL) (bs : BlockStore) : Set where
inBS : ∀ {eb} → (getBlock (hashBSL bsl) bs ≡ just eb) → bsl ∈Block (eb ^∙ ebBlock) → bsl ∈BS bs
data _∈RM_ (bsl : BSL) (rm : RoundManager) : Set where
inRM : bsl ∈BS (rm ^∙ lBlockStore) → bsl ∈RM rm
-- So far, HashCollisionFound includes two constructors, one (msgRmHC) for a collision between a
-- ByteString represented in a message that has been sent (∈nm) and one represented in the
-- RoundManager of some peer. The other (msgmsgHC) is unused so far, but would be needed if we
-- were to take this work further; it is for cases in which there is a collision between two
-- elements in messages that have been sent.
data HashCollisionFound : Set where
msgRmHC : ∀ {bs1 bs2 pid}
→ bs1 ∈nm
→ initialised st pid ≡ initd
→ bs2 ∈RM (peerStates st pid)
→ hashBSL bs1 ≡ hashBSL bs2
→ bs1 ≢ bs2
→ HashCollisionFound
msgmsgHC : ∀ {bs1 bs2}
→ bs1 ∈nm
→ bs2 ∈nm
→ hashBSL bs1 ≡ hashBSL bs2
→ bs1 ≢ bs2
→ HashCollisionFound
-- By postulating the lack of existence of HashCollisionFound, we enable any proof to "bail out"
-- only if it can construct a *specific* hash collision that is "in the system" represented by
-- the specific ReachableSystemState, according to the specific notions thereof captured by the
-- constructors for this type.
postulate -- Valid assumption: there are no hash collisions among values found in the system
meta-no-collision-in-sys : ¬ HashCollisionFound
-- Discussion
--
-- As noted above, we have applied this approach to some proofs but not others. In particular,
-- there are still a number of proofs that use meta-no-collision (below), which does not require
-- the constructed collision to be explicitly placed in context of the ReachableSystemState.
--
-- We have used meta-no-collision-in-sys for the case of a peer handling a proposal. The
-- proposal contains a Block which has an ID, which is supposed to be the hash of some parts of
-- the proposal. This condition is verified when the proposal message is first received (see
-- verifyWellFormed in LibraBFT.Impl.Consensus.ConsensusTypes.Block), and the knowledge that it
-- verified correctly is needed all the way down the stack when the receiving peer inserts the
-- block into its BlockTree. If an ExecutedBlock is found in the BlockTree associated with the
-- ID of the new Block, then the algorithm assumes it's the same Block (because both the new
-- Block and the one inserted previously in the BlockTree have been verified as hashing to the
-- same ID). If there were a collision (i.e., these two Blocks that hash to the same ID
-- actually have different bits that are hashed to derive the ID), then incorrect behaviour
-- would be possible.
--
-- To use meta-no-collision-in-sys, we need to construct a value of HashCollisionFound in
-- context of the ReachableSystemState under consideration (but see note below). This requires
-- carrying the fact that the hash of the newly proposed Block matches its ID from the
-- above-mentioned verification all the way down the stack, where it is needed to invoke an
-- assumption about the lack of collisions between the new Block and one previously stored when
-- proving the Contract for insertBlockESpec. (This is the NOHC1 argument given to the blocks≈
-- field insertBlockESpec.ContrackOk.) Then, each Contract up the stack must receive a similar
-- argument enabling it to invoke the Contract of the next function down the stack. See, for
-- example, the ebBlock≈ field of executeAndInsertBlockESpec.ContractOk, the voteAttemptCorrect
-- field of processProposalMsgMSpec.Contract (and others in the same file), and similarly for
-- handleProposalSpec.Contract. Then this argument must be provided by higher level properties
-- that wish to invoke the lower-level contracts. Because the higher-level properties are in
-- context of a specific ReachableSystemState, they can construct a proof of the absence of the
-- potential collision by using meta-no-collision-in-sys for that ReachableSystemState.
--
-- As can be seen, connecting a potential hash collision to a specific ReachableSystemState is a
-- fair amount of work, which complicates proofs. As explained above, we do not think it is
-- worthwhile to continue this effort, just to show that we can. One issue we would want to
-- address if taking this work further would be to *ensure* that the ReachableSystemState
-- for which a potential collision is considered is the same one about which we're proving the
-- given property. This already is the case in our proofs, but our conditions don't *ensure*
-- that it is because, in principle, when calling nohc to use meta-no-collision-in-sys to
-- eliminate an assumed collision, we could provide *any* ReachableSystemState. To require it
-- to be the same ReachableSystemState, we would need to explicitly express for each relevant
-- property that it holds unless there is collision in *that state*. So, for example, the
-- conclusion of the IncreasingRoundObligation property would have to become something like the
-- following (where pre is the state about which IncreasingRoundObligation is proved):
--
-- HashCollisionFound pre
-- ⊎ v' ^∙ vRound < v ^∙ vRound
-- ⊎ VoteForRound∈ pk (v ^∙ vRound) (v ^∙ vEpoch) (v ^∙ vProposedId) (msgPool pre)
--
-- The first disjunct is not currently necessary because there is no requirement to place the
-- HashCollisionFound in the same ReachableSystemState. We would then need to propagate those
-- disjuncts from one proof to another, making even more work and complicating proofs and
-- properties further. Importantly, doing so would provide no additional benefit over what we
-- have done already, exactly because it is not practical to construct a collision for the
-- postulated hash function anyway (and we could not do so "accidentally"): giving ourselves the
-- freedom to associate it with a diffferent ReachabeSystemState does not change that. This
-- underlines the point that requiring the collision to be associated with a
-- ReachableSystemState creates quite a bit of work, and provides little benefit.
postulate -- valid assumption. Note that this does *not* say that no collisions *exist*; it
-- says a proof cannot escape its obligations unless it can provide specfic evidence
-- of a collision; as explained above, doing so other than from Records presented to
-- the proof (because they are in the system state under consideration) is
-- impractical and impossible to do "accidentally"
meta-no-collision : ¬ (NonInjective-≡ sha256)
sameSig⇒sameVoteDataNoCol : ∀ {v1 v2 : Vote} {pk}
→ WithVerSig pk v1
→ WithVerSig pk v2
→ v1 ^∙ vSignature ≡ v2 ^∙ vSignature
→ v2 ^∙ vVoteData ≡ v1 ^∙ vVoteData
sameSig⇒sameVoteDataNoCol {v1} {v2} wvs1 wvs2 refl
with sameSig⇒sameVoteData {v1} {v2} wvs1 wvs2 refl
...| inj₁ hb = ⊥-elim (meta-no-collision hb)
...| inj₂ x = x
| 65.663677
| 111
| 0.731476
|
0be7e6cfb78741b7de7514bd85e04290384751ac
| 15,369
|
agda
|
Agda
|
Cubical/Data/Int/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/Data/Int/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/Data/Int/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
{-
This file defines
sucPred : ∀ (i : Int) → sucInt (predInt i) ≡ i
predSuc : ∀ (i : Int) → predInt (sucInt i) ≡ i
discreteInt : discrete Int
isSetInt : isSet Int
addition of Int is defined _+_ : Int → Int → Int
as well as its commutativity and associativity
+-comm : ∀ (m n : Int) → m + n ≡ n + m
+-assoc : ∀ (m n o : Int) → m + (n + o) ≡ (m + n) + o
An alternate definition of _+_ is defined via ua,
namely _+'_, which helps us to easily prove
isEquivAddInt : (m : Int) → isEquiv (λ n → n + m)
-}
module Cubical.Data.Int.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Empty
open import Cubical.Data.Nat hiding (+-assoc ; +-comm) renaming (_·_ to _·ℕ_; _+_ to _+ℕ_)
open import Cubical.Data.Bool
open import Cubical.Data.Sum
open import Cubical.Data.Int.Base
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
abs : Int → ℕ
abs (pos n) = n
abs (negsuc n) = suc n
sgn : Int → Bool
sgn (pos n) = true
sgn (negsuc n) = false
sucPred : ∀ i → sucInt (predInt i) ≡ i
sucPred (pos zero) = refl
sucPred (pos (suc n)) = refl
sucPred (negsuc n) = refl
predSuc : ∀ i → predInt (sucInt i) ≡ i
predSuc (pos n) = refl
predSuc (negsuc zero) = refl
predSuc (negsuc (suc n)) = refl
-- TODO: define multiplication
injPos : ∀ {a b : ℕ} → pos a ≡ pos b → a ≡ b
injPos {a} h = subst T h refl
where
T : Int → Type₀
T (pos x) = a ≡ x
T (negsuc _) = ⊥
injNegsuc : ∀ {a b : ℕ} → negsuc a ≡ negsuc b → a ≡ b
injNegsuc {a} h = subst T h refl
where
T : Int → Type₀
T (pos _) = ⊥
T (negsuc x) = a ≡ x
posNotnegsuc : ∀ (a b : ℕ) → ¬ (pos a ≡ negsuc b)
posNotnegsuc a b h = subst T h 0
where
T : Int → Type₀
T (pos _) = ℕ
T (negsuc _) = ⊥
negsucNotpos : ∀ (a b : ℕ) → ¬ (negsuc a ≡ pos b)
negsucNotpos a b h = subst T h 0
where
T : Int → Type₀
T (pos _) = ⊥
T (negsuc _) = ℕ
discreteInt : Discrete Int
discreteInt (pos n) (pos m) with discreteℕ n m
... | yes p = yes (cong pos p)
... | no p = no (λ x → p (injPos x))
discreteInt (pos n) (negsuc m) = no (posNotnegsuc n m)
discreteInt (negsuc n) (pos m) = no (negsucNotpos n m)
discreteInt (negsuc n) (negsuc m) with discreteℕ n m
... | yes p = yes (cong negsuc p)
... | no p = no (λ x → p (injNegsuc x))
isSetInt : isSet Int
isSetInt = Discrete→isSet discreteInt
isEven : Int → Bool
isEven (pos zero) = true
isEven (pos (suc zero)) = false
isEven (pos (suc (suc n))) = isEven (pos n)
isEven (negsuc zero) = false
isEven (negsuc (suc n)) = isEven (pos n)
_ℕ-_ : ℕ → ℕ → Int
a ℕ- 0 = pos a
0 ℕ- suc b = negsuc b
suc a ℕ- suc b = a ℕ- b
_+pos_ : Int → ℕ → Int
z +pos 0 = z
z +pos (suc n) = sucInt (z +pos n)
_+negsuc_ : Int → ℕ → Int
z +negsuc 0 = predInt z
z +negsuc (suc n) = predInt (z +negsuc n)
_+_ : Int → Int → Int
m + pos n = m +pos n
m + negsuc n = m +negsuc n
-_ : Int → Int
- pos zero = pos zero
- pos (suc n) = negsuc n
- negsuc n = pos (suc n)
_-_ : Int → Int → Int
m - n = m + (- n)
-pos : ∀ n → - (pos n) ≡ neg n
-pos zero = refl
-pos (suc n) = refl
-neg : ∀ n → - (neg n) ≡ pos n
-neg zero = refl
-neg (suc n) = refl
-Involutive : ∀ z → - (- z) ≡ z
-Involutive (pos n) = (- (- pos n)) ≡⟨ cong -_ (-pos n) ⟩
- (neg n) ≡⟨ -neg n ⟩
pos n ∎
-Involutive (negsuc n) = refl
sucInt+pos : ∀ n m → sucInt (m +pos n) ≡ (sucInt m) +pos n
sucInt+pos zero m = refl
sucInt+pos (suc n) m = cong sucInt (sucInt+pos n m)
predInt+negsuc : ∀ n m → predInt (m +negsuc n) ≡ (predInt m) +negsuc n
predInt+negsuc zero m = refl
predInt+negsuc (suc n) m = cong predInt (predInt+negsuc n m)
sucInt+negsuc : ∀ n m → sucInt (m +negsuc n) ≡ (sucInt m) +negsuc n
sucInt+negsuc zero m = (sucPred _) ∙ (sym (predSuc _))
sucInt+negsuc (suc n) m = _ ≡⟨ sucPred _ ⟩
m +negsuc n ≡[ i ]⟨ predSuc m (~ i) +negsuc n ⟩
(predInt (sucInt m)) +negsuc n ≡⟨ sym (predInt+negsuc n (sucInt m)) ⟩
predInt (sucInt m +negsuc n) ∎
predInt+pos : ∀ n m → predInt (m +pos n) ≡ (predInt m) +pos n
predInt+pos zero m = refl
predInt+pos (suc n) m = _ ≡⟨ predSuc _ ⟩
m +pos n ≡[ i ]⟨ sucPred m (~ i) + pos n ⟩
(sucInt (predInt m)) +pos n ≡⟨ sym (sucInt+pos n (predInt m))⟩
(predInt m) +pos (suc n) ∎
predInt-pos : ∀ n → predInt(- (pos n)) ≡ negsuc n
predInt-pos zero = refl
predInt-pos (suc n) = refl
predInt+ : ∀ m n → predInt (m + n) ≡ (predInt m) + n
predInt+ m (pos n) = predInt+pos n m
predInt+ m (negsuc n) = predInt+negsuc n m
+predInt : ∀ m n → predInt (m + n) ≡ m + (predInt n)
+predInt m (pos zero) = refl
+predInt m (pos (suc n)) = (predSuc (m + pos n)) ∙ (cong (_+_ m) (sym (predSuc (pos n))))
+predInt m (negsuc n) = refl
sucInt+ : ∀ m n → sucInt (m + n) ≡ (sucInt m) + n
sucInt+ m (pos n) = sucInt+pos n m
sucInt+ m (negsuc n) = sucInt+negsuc n m
+sucInt : ∀ m n → sucInt (m + n) ≡ m + (sucInt n)
+sucInt m (pos n) = refl
+sucInt m (negsuc zero) = sucPred _
+sucInt m (negsuc (suc n)) = (sucPred (m +negsuc n)) ∙ (cong (_+_ m) (sym (sucPred (negsuc n))))
pos0+ : ∀ z → z ≡ pos 0 + z
pos0+ (pos zero) = refl
pos0+ (pos (suc n)) = cong sucInt (pos0+ (pos n))
pos0+ (negsuc zero) = refl
pos0+ (negsuc (suc n)) = cong predInt (pos0+ (negsuc n))
negsuc0+ : ∀ z → predInt z ≡ negsuc 0 + z
negsuc0+ (pos zero) = refl
negsuc0+ (pos (suc n)) = (sym (sucPred (pos n))) ∙ (cong sucInt (negsuc0+ _))
negsuc0+ (negsuc zero) = refl
negsuc0+ (negsuc (suc n)) = cong predInt (negsuc0+ (negsuc n))
ind-comm : {A : Type₀} (_∙_ : A → A → A) (f : ℕ → A) (g : A → A)
(p : ∀ {n} → f (suc n) ≡ g (f n))
(g∙ : ∀ a b → g (a ∙ b) ≡ g a ∙ b)
(∙g : ∀ a b → g (a ∙ b) ≡ a ∙ g b)
(base : ∀ z → z ∙ f 0 ≡ f 0 ∙ z)
→ ∀ z n → z ∙ f n ≡ f n ∙ z
ind-comm _∙_ f g p g∙ ∙g base z 0 = base z
ind-comm _∙_ f g p g∙ ∙g base z (suc n) =
z ∙ f (suc n) ≡[ i ]⟨ z ∙ p {n} i ⟩
z ∙ g (f n) ≡⟨ sym ( ∙g z (f n)) ⟩
g (z ∙ f n) ≡⟨ cong g IH ⟩
g (f n ∙ z) ≡⟨ g∙ (f n) z ⟩
g (f n) ∙ z ≡[ i ]⟨ p {n} (~ i) ∙ z ⟩
f (suc n) ∙ z ∎
where
IH = ind-comm _∙_ f g p g∙ ∙g base z n
ind-assoc : {A : Type₀} (_·_ : A → A → A) (f : ℕ → A)
(g : A → A) (p : ∀ a b → g (a · b) ≡ a · (g b))
(q : ∀ {c} → f (suc c) ≡ g (f c))
(base : ∀ m n → (m · n) · (f 0) ≡ m · (n · (f 0)))
(m n : A) (o : ℕ)
→ m · (n · (f o)) ≡ (m · n) · (f o)
ind-assoc _·_ f g p q base m n 0 = sym (base m n)
ind-assoc _·_ f g p q base m n (suc o) =
m · (n · (f (suc o))) ≡[ i ]⟨ m · (n · q {o} i) ⟩
m · (n · (g (f o))) ≡[ i ]⟨ m · (p n (f o) (~ i)) ⟩
m · (g (n · (f o))) ≡⟨ sym (p m (n · (f o)))⟩
g (m · (n · (f o))) ≡⟨ cong g IH ⟩
g ((m · n) · (f o)) ≡⟨ p (m · n) (f o) ⟩
(m · n) · (g (f o)) ≡[ i ]⟨ (m · n) · q {o} (~ i) ⟩
(m · n) · (f (suc o)) ∎
where
IH = ind-assoc _·_ f g p q base m n o
+-comm : ∀ m n → m + n ≡ n + m
+-comm m (pos n) = ind-comm _+_ pos sucInt refl sucInt+ +sucInt pos0+ m n
+-comm m (negsuc n) = ind-comm _+_ negsuc predInt refl predInt+ +predInt negsuc0+ m n
+-assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o
+-assoc m n (pos o) = ind-assoc _+_ pos sucInt +sucInt refl (λ _ _ → refl) m n o
+-assoc m n (negsuc o) = ind-assoc _+_ negsuc predInt +predInt refl +predInt m n o
-- Compose sucPathInt with itself n times. Transporting along this
-- will be addition, transporting with it backwards will be subtraction.
-- Use this to define _+'_ for which is easier to prove
-- isEquiv (λ n → n +' m) since _+'_ is defined by transport
sucPathInt : Int ≡ Int
sucPathInt = ua (sucInt , isoToIsEquiv (iso sucInt predInt sucPred predSuc))
addEq : ℕ → Int ≡ Int
addEq zero = refl
addEq (suc n) = (addEq n) ∙ sucPathInt
predPathInt : Int ≡ Int
predPathInt = ua (predInt , isoToIsEquiv (iso predInt sucInt predSuc sucPred))
subEq : ℕ → Int ≡ Int
subEq zero = refl
subEq (suc n) = (subEq n) ∙ predPathInt
_+'_ : Int → Int → Int
m +' pos n = transport (addEq n) m
m +' negsuc n = transport (subEq (suc n)) m
+'≡+ : _+'_ ≡ _+_
+'≡+ i m (pos zero) = m
+'≡+ i m (pos (suc n)) = sucInt (+'≡+ i m (pos n))
+'≡+ i m (negsuc zero) = predInt m
+'≡+ i m (negsuc (suc n)) = predInt (+'≡+ i m (negsuc n)) --
-- compPath (λ i → (+'≡+ i (predInt m) (negsuc n))) (sym (predInt+negsuc n m)) i
isEquivAddInt' : (m : Int) → isEquiv (λ n → n +' m)
isEquivAddInt' (pos n) = isEquivTransport (addEq n)
isEquivAddInt' (negsuc n) = isEquivTransport (subEq (suc n))
isEquivAddInt : (m : Int) → isEquiv (λ n → n + m)
isEquivAddInt = subst (λ add → (m : Int) → isEquiv (λ n → add n m)) +'≡+ isEquivAddInt'
-- below is an alternate proof of isEquivAddInt for comparison
-- We also have two useful lemma here.
minusPlus : ∀ m n → (n - m) + m ≡ n
minusPlus (pos zero) n = refl
minusPlus (pos 1) = sucPred
minusPlus (pos (suc (suc m))) n =
sucInt ((n +negsuc (suc m)) +pos (suc m)) ≡⟨ sucInt+pos (suc m) _ ⟩
sucInt (n +negsuc (suc m)) +pos (suc m) ≡[ i ]⟨ sucPred (n +negsuc m) i +pos (suc m) ⟩
(n - pos (suc m)) +pos (suc m) ≡⟨ minusPlus (pos (suc m)) n ⟩
n ∎
minusPlus (negsuc zero) = predSuc
minusPlus (negsuc (suc m)) n =
predInt (sucInt (sucInt (n +pos m)) +negsuc m) ≡⟨ predInt+negsuc m _ ⟩
predInt (sucInt (sucInt (n +pos m))) +negsuc m ≡[ i ]⟨ predSuc (sucInt (n +pos m)) i +negsuc m ⟩
sucInt (n +pos m) +negsuc m ≡⟨ minusPlus (negsuc m) n ⟩
n ∎
plusMinus : ∀ m n → (n + m) - m ≡ n
plusMinus (pos zero) n = refl
plusMinus (pos (suc m)) = minusPlus (negsuc m)
plusMinus (negsuc m) = minusPlus (pos (suc m))
private
alternateProof : (m : Int) → isEquiv (λ n → n + m)
alternateProof m = isoToIsEquiv (iso (λ n → n + m)
(λ n → n - m)
(minusPlus m)
(plusMinus m))
-Cancel : ∀ z → z - z ≡ pos zero
-Cancel z = z - z ≡⟨ cong (_- z) (pos0+ z) ⟩
(pos zero + z) - z ≡⟨ plusMinus z (pos zero) ⟩
pos zero ∎
pos+ : ∀ m n → pos (m +ℕ n) ≡ pos m + pos n
pos+ zero zero = refl
pos+ zero (suc n) =
pos (zero +ℕ suc n) ≡⟨ +-comm (pos (suc n)) (pos zero) ⟩
pos zero + pos (suc n) ∎
pos+ (suc m) zero =
pos (suc (m +ℕ zero)) ≡⟨ cong pos (cong suc (+-zero m)) ⟩
pos (suc m) + pos zero ∎
pos+ (suc m) (suc n) =
pos (suc m +ℕ suc n) ≡⟨ cong pos (cong suc (+-suc m n)) ⟩
sucInt (pos (suc (m +ℕ n))) ≡⟨ cong sucInt (cong sucInt (pos+ m n)) ⟩
sucInt (sucInt (pos m + pos n)) ≡⟨ sucInt+ (pos m) (sucInt (pos n)) ⟩
pos (suc m) + pos (suc n) ∎
negsuc+ : ∀ m n → negsuc (m +ℕ n) ≡ negsuc m - pos n
negsuc+ zero zero = refl
negsuc+ zero (suc n) =
negsuc (zero +ℕ suc n) ≡⟨ negsuc0+ (negsuc n) ⟩
negsuc zero + negsuc n ≡⟨ cong (negsuc zero +_) (-pos (suc n)) ⟩
negsuc zero - pos (suc n) ∎
negsuc+ (suc m) zero =
negsuc (suc m +ℕ zero) ≡⟨ cong negsuc (cong suc (+-zero m)) ⟩
negsuc (suc m) - pos zero ∎
negsuc+ (suc m) (suc n) =
negsuc (suc m +ℕ suc n) ≡⟨ cong negsuc (sym (+-suc m (suc n))) ⟩
negsuc (m +ℕ suc (suc n)) ≡⟨ negsuc+ m (suc (suc n)) ⟩
negsuc m - pos (suc (suc n)) ≡⟨ sym (+predInt (negsuc m) (negsuc n)) ⟩
predInt (negsuc m + negsuc n ) ≡⟨ predInt+ (negsuc m) (negsuc n) ⟩
negsuc (suc m) - pos (suc n) ∎
neg+ : ∀ m n → neg (m +ℕ n) ≡ neg m + neg n
neg+ zero zero = refl
neg+ zero (suc n) = neg (zero +ℕ suc n) ≡⟨ +-comm (neg (suc n)) (pos zero) ⟩
neg zero + neg (suc n) ∎
neg+ (suc m) zero = neg (suc (m +ℕ zero)) ≡⟨ cong neg (cong suc (+-zero m)) ⟩
neg (suc m) + neg zero ∎
neg+ (suc m) (suc n) = neg (suc m +ℕ suc n) ≡⟨ negsuc+ m (suc n) ⟩
neg (suc m) + neg (suc n) ∎
ℕ-AntiComm : ∀ m n → m ℕ- n ≡ - (n ℕ- m)
ℕ-AntiComm zero zero = refl
ℕ-AntiComm zero (suc n) = refl
ℕ-AntiComm (suc m) zero = refl
ℕ-AntiComm (suc m) (suc n) = suc m ℕ- suc n ≡⟨ ℕ-AntiComm m n ⟩
- (suc n ℕ- suc m) ∎
pos- : ∀ m n → m ℕ- n ≡ pos m - pos n
pos- zero zero = refl
pos- zero (suc n) = zero ℕ- suc n ≡⟨ +-comm (negsuc n) (pos zero) ⟩
pos zero - pos (suc n) ∎
pos- (suc m) zero = refl
pos- (suc m) (suc n) =
suc m ℕ- suc n ≡⟨ pos- m n ⟩
pos m - pos n ≡⟨ sym (sucPred (pos m - pos n)) ⟩
sucInt (predInt (pos m - pos n)) ≡⟨ cong sucInt (+predInt (pos m) (- pos n)) ⟩
sucInt (pos m + predInt (- (pos n))) ≡⟨ cong sucInt (cong (pos m +_) (predInt-pos n)) ⟩
sucInt (pos m + negsuc n) ≡⟨ sucInt+negsuc n (pos m) ⟩
pos (suc m) - pos (suc n) ∎
-AntiComm : ∀ m n → m - n ≡ - (n - m)
-AntiComm (pos n) (pos m) = pos n - pos m ≡⟨ sym (pos- n m) ⟩
n ℕ- m ≡⟨ ℕ-AntiComm n m ⟩
- (m ℕ- n) ≡⟨ cong -_ (pos- m n) ⟩
- (pos m - pos n) ∎
-AntiComm (pos n) (negsuc m) =
pos n - negsuc m ≡⟨ +-comm (pos n) (pos (suc m)) ⟩
pos (suc m) + pos n ≡⟨ sym (pos+ (suc m) n) ⟩
pos (suc m +ℕ n) ≡⟨ sym (-neg (suc m +ℕ n)) ⟩
- neg (suc m +ℕ n) ≡⟨ cong -_ (neg+ (suc m) n) ⟩
- (neg (suc m) + neg n) ≡⟨ cong -_ (cong (negsuc m +_) (sym (-pos n))) ⟩
- (negsuc m - pos n) ∎
-AntiComm (negsuc n) (pos m) =
negsuc n - pos m ≡⟨ sym (negsuc+ n m) ⟩
negsuc (n +ℕ m) ≡⟨ cong -_ (pos+ (suc n) m) ⟩
- (pos (suc n) + pos m) ≡⟨ cong -_ (+-comm (pos (suc n)) (pos m)) ⟩
- (pos m - negsuc n) ∎
-AntiComm (negsuc n) (negsuc m) =
negsuc n - negsuc m ≡⟨ +-comm (negsuc n) (pos (suc m)) ⟩
pos (suc m) + negsuc n ≡⟨ sym (pos- (suc m) (suc n)) ⟩
suc m ℕ- suc n ≡⟨ ℕ-AntiComm (suc m) (suc n) ⟩
- (suc n ℕ- suc m) ≡⟨ cong -_ (pos- (suc n) (suc m)) ⟩
- (pos (suc n) - pos (suc m)) ≡⟨ cong -_ (+-comm (pos (suc n)) (negsuc m)) ⟩
- (negsuc m - negsuc n) ∎
-Dist+ : ∀ m n → - (m + n) ≡ (- m) + (- n)
-Dist+ (pos n) (pos m) =
- (pos n + pos m) ≡⟨ cong -_ (sym (pos+ n m)) ⟩
- pos (n +ℕ m) ≡⟨ -pos (n +ℕ m) ⟩
neg (n +ℕ m) ≡⟨ neg+ n m ⟩
neg n + neg m ≡⟨ cong (neg n +_) (sym (-pos m)) ⟩
neg n + (- pos m) ≡⟨ cong (_+ (- pos m)) (sym (-pos n)) ⟩
(- pos n) + (- pos m) ∎
-Dist+ (pos n) (negsuc m) =
- (pos n + negsuc m) ≡⟨ sym (-AntiComm (pos (suc m)) (pos n)) ⟩
pos (suc m) - pos n ≡⟨ +-comm (pos (suc m)) (- pos n) ⟩
(- pos n) + (- negsuc m) ∎
-Dist+ (negsuc n) (pos m) =
- (negsuc n + pos m) ≡⟨ cong -_ (+-comm (negsuc n) (pos m)) ⟩
- (pos m + negsuc n) ≡⟨ sym (-AntiComm (- negsuc n) (pos m)) ⟩
(- negsuc n) + (- pos m) ∎
-Dist+ (negsuc n) (negsuc m) =
- (negsuc n + negsuc m) ≡⟨ cong -_ (sym (neg+ (suc n) (suc m))) ⟩
- neg (suc n +ℕ suc m) ≡⟨ pos+ (suc n) (suc m) ⟩
(- negsuc n) + (- negsuc m) ∎
_·_ : Int → Int → Int
pos zero · m = pos zero
pos (suc n) · m = m + (pos n · m)
negsuc zero · m = (- m)
negsuc (suc n) · m = (- m) + ((negsuc n) · m)
| 35.412442
| 98
| 0.51682
|
1ac4acdfef0d29b2bad86ea26b880e15282a604b
| 998
|
agda
|
Agda
|
Path.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Path.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Path.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Path where
open import Cubical.Foundations.Everything
using ( _≡_
; sym
; refl
; subst
; transport
; Path
; PathP
; I
; i0
; i1
; funExt
; cong
; toPathP
; cong₂
; ~_
; _∧_
; _∨_
; hcomp
; transp
; J
)
renaming (_∙_ to _;_; subst2 to subst₂)
public
open import Data.Empty using (¬_)
open import Level
infix 4 _≢_
_≢_ : {A : Type a} → A → A → Type a
x ≢ y = ¬ (x ≡ y)
infix 4 PathP-syntax
PathP-syntax = PathP
{-# DISPLAY PathP-syntax = PathP #-}
syntax PathP-syntax (λ i → Ty) lhs rhs = lhs ≡[ i ≔ Ty ]≡ rhs
import Agda.Builtin.Equality as MLTT
builtin-eq-to-path : {A : Type a} {x y : A} → x MLTT.≡ y → x ≡ y
builtin-eq-to-path {x = x} MLTT.refl i = x
path-to-builtin-eq : {A : Type a} {x y : A} → x ≡ y → x MLTT.≡ y
path-to-builtin-eq {x = x} x≡y = subst (x MLTT.≡_) x≡y MLTT.refl
| 19.96
| 64
| 0.508016
|
fbc8ea7e669430b3d7b67852c7ad5023e9440d53
| 92
|
agda
|
Agda
|
agda/Data/List.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 4
|
2021-01-05T14:07:44.000Z
|
2021-01-05T15:32:14.000Z
|
agda/Data/List.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/List.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 1
|
2021-01-05T14:05:30.000Z
|
2021-01-05T14:05:30.000Z
|
{-# OPTIONS --cubical --safe #-}
module Data.List where
open import Data.List.Base public
| 15.333333
| 33
| 0.706522
|
c76a60199d8aaddcd62d8479fdc47a385a946ffa
| 487
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/EquivalenceClosure.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/EquivalenceClosure.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/EquivalenceClosure.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Equivalence closures of binary relations
--
-- This module is DEPRECATED. Please use the
-- Relation.Binary.Construct.Closure.Equivalence module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.EquivalenceClosure where
open import Relation.Binary.Construct.Closure.Equivalence public
| 32.466667
| 72
| 0.546201
|
1d8cc41368f37ee6f6c1a57647297fe345ad5e7d
| 334
|
agda
|
Agda
|
test/Fail/WithoutK-PatternMatchingLambdas1.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/WithoutK-PatternMatchingLambdas1.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/WithoutK-PatternMatchingLambdas1.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K #-}
module WithoutK-PatternMatchingLambdas1 where
-- Equality defined with one index.
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
-- The --without-K option works with pattern matching lambdas.
K : (A : Set) (x : A) (P : x ≡ x → Set) → P refl → (p : x ≡ x ) → P p
K = λ { A x P pr refl → pr }
| 27.833333
| 70
| 0.583832
|
1d54600bc516cda28d1b494c3b69e2879a406bae
| 1,045
|
agda
|
Agda
|
test/interaction/Issue1963.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue1963.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue1963.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, May-July 2016, implementing postfix projections
{-# OPTIONS --postfix-projections #-}
open import Common.Product
open import Common.Bool
pair : ∀{A : Set}(a : A) → A × A
pair a = {!!} -- C-c C-c here outputs postfix projections
record BoolFun : Set where
field out : Bool → Bool
open BoolFun
neg : BoolFun
neg .out x = {!x!} -- splitting here should preserve postfix proj
neg2 : BoolFun
out neg2 x = {!x!} -- splitting here should preserve prefix proj
module ExtendedLambda where
neg3 : BoolFun
neg3 = λ{ .out → {!!} }
pair2 : ∀{A : Set}(a : A) → A × A
pair2 = λ{ a → {!!} }
neg4 : BoolFun
neg4 = λ{ .out b → {!b!} }
-- DOES NOT WORK DUE TO ISSUE #2020
-- module LambdaWhere where
-- neg3 : BoolFun
-- neg3 = λ where
-- .out → {!!} -- splitting on result here crashes
-- pair2 : ∀{A : Set}(a : A) → A × A
-- pair2 = λ where
-- a → {!!}
-- extlam-where : Bool → Bool
-- extlam-where = λ where
-- b → {!b!}
-- -- extlam : Bool → Bool
-- -- extlam = λ
-- -- { b → {!b!}
-- -- }
| 20.096154
| 65
| 0.571292
|
41e8c42d615dfce97b5718c02f9d84dd18c20261
| 31,652
|
agda
|
Agda
|
agda/book/Programming_Language_Foundations_in_Agda/x02induction.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/Programming_Language_Foundations_in_Agda/x02induction.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/Programming_Language_Foundations_in_Agda/x02induction.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module x02induction where
-- prove properties of inductive naturals and operations on them via induction
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_)
{-
------------------------------------------------------------------------------
## Properties of operators : identity, associativity, commutativity, distributivity
* _Identity_. left/right/both; sometimes called _unit_
* _Associativity_. e.g., `(m + n) + p ≡ m + (n + p)`
* _Commutativity_. e.g., `m + n ≡ n + m`
* _Distributivity_. e.g., from the left `(m + n) * p ≡ (m * p) + (n * p)`
from the right `m * (p + q) ≡ (m * p) + (m * q)`
#### Exercise `operators` (practice) {name=operators} TODO : ops with different properties - no proofs
pair of operators
- have an identity
- are associative, commutative, and distribute over one another
(do not prove)
operator
- has identity
- is associative
- not commutative
(do not prove)
-}
{-
HC not associative; right identity
-}
_ =
begin
(3 ∸ 1) ∸ 1 ∸ 0 ≡⟨⟩
2 ∸ 1 ∸ 0 ≡⟨⟩
1 ∸ 0 ≡⟨⟩
1 ∸ 0
∎
{-
------------------------------------------------------------------------------
## ASSOCIATIVITY of ADDITION : (m + n) + p ≡ m + (n + p)
-}
_ : (3 + 4) + 5 ≡ 3 + (4 + 5)
_ =
begin
(3 + 4) + 5 ≡⟨⟩
7 + 5 ≡⟨⟩
12 ≡⟨⟩
3 + 9 ≡⟨⟩
3 + (4 + 5)
∎
{-
useful to read chains like above
- from top down until reaching simplest term (i.e., `12`)
- from bottom up until reaching the same term
Why should `7 + 5` be the same as `3 + 9`?
Perhaps gather more evidence, testing the proposition by choosing other numbers.
But infinite naturals so testing can never be complete.
## PROOF BY INDUCTION
natural definition has
- base case
- inductive case
inductive proof follows structure of definition: prove two cases
- _base case_ : show property holds for `zero`
- _inductive case_ :
- assume property holds for an arbitrary natural `m` (the _inductive hypothesis_)
- then show that the property holds for `suc m`
------
P zero
P m
---------
P (suc m)
- initially, no properties are known.
- base case : `P zero` holds : add it to set of known properties
-- On the first day, one property is known.
P zero
- inductive case tells us that if `P m` holds
-- On the second day, two properties are known.
P zero
P (suc zero)
then `P (suc m)` also holds
-- On the third day, three properties are known.
P zero
P (suc zero)
P (suc (suc zero))
-- On the fourth day, four properties are known.
P zero
P (suc zero)
P (suc (suc zero))
P (suc (suc (suc zero)))
the process continues: property `P n` first appears on day _n+1_
------------------------------------------------------------------------------
## PROVE ASSOCIATIVITY of ADDITION
take `P m` to be the property:
(m + n) + p ≡ m + (n + p)
`n` and `p` are arbitrary natural numbers
show the equation holds for all `m` it will also hold for all `n` and `p`
-------------------------------
(zero + n) + p ≡ zero + (n + p)
(m + n) + p ≡ m + (n + p)
---------------------------------
(suc m + n) + p ≡ suc m + (n + p)
demonstrate both of above, then associativity of addition follows by induction
-}
-- signature says providing evidence for proposition
+-assoc : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
-- Evidence is a function that
-- - takes three natural numbers, binds them to `m`, `n`, and `p`
-- - returns evidence for the corresponding instance of the equation
-- base case : show: (zero + n) + p
-- ≡ zero + (n + p)
+-assoc zero n p =
begin
(zero + n) + p ≡⟨⟩ -- _+_ base case
n + p ≡⟨⟩
zero + (n + p)
∎
-- inductive case : show: (suc m + n) + p
-- ≡ suc m + (n + p)
+-assoc (suc m) n p =
begin
(suc m + n) + p ≡⟨⟩ -- _+_ inductive case (left to right)
suc (m + n) + p ≡⟨⟩
suc ((m + n) + p) ≡⟨ cong suc (+-assoc m n p) ⟩
-- simplifying both sides : suc ((m + n) + p) ≡ suc (m + (n + p))
-- follows by prefacing `suc` to both sides of the induction hypothesis:
-- (m + n) + p ≡ m + (n + p)
suc (m + (n + p)) ≡⟨⟩ -- _+_ inductive case (right to left)
suc m + (n + p)
∎
-- HC minimal version
+-assoc' : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
+-assoc' zero n p = refl
+-assoc' (suc m) n p = cong suc (+-assoc m n p)
{-
identifiers can have any characters NOT including spaces or the characters @.(){};_
the "middle" equation, does not follow from applying _+_ (i.e., "simplification") alone
- `_≡⟨_⟩_` : called "chain reasoning"
- justification for equation given in angle brackets:
- empty means "simplification", or
- something more, e.g.,:
⟨ cong suc (+-assoc m n p) ⟩
recursive invocation `+-assoc m n p`
- has type of the induction hypothesis
- `cong suc` prefaces `suc` to each side of inductive hypothesis
A relation is a CONGRUENCE for a given function
if the relation is preserved by applying the function.
if `e` is evidence that `x ≡ y`, then `cong f e` is evidence `f x ≡ f y`, for any `f`
here the inductive hypothesis is not assumed
instead, proved by recursive invocation of the function being defined, `+-assoc m n p`
WELL FOUNDED : associativity of larger numbers is proved in of associativity of smaller numbers.
e.g., `assoc (suc m) n p` is proved using `assoc m n p`.
------------------------------------------------------------------------------
## Induction as recursion
Concrete example of how induction corresponds to recursion : instantiate `m` to `2`
-}
+-assoc-2 : ∀ (n p : ℕ)
→ (2 + n) + p
≡ 2 + (n + p)
+-assoc-2 n p =
begin
(2 + n) + p ≡⟨⟩
suc (1 + n) + p ≡⟨⟩
suc ((1 + n) + p) ≡⟨ cong suc (+-assoc-1 n p) ⟩
suc (1 + (n + p)) ≡⟨⟩
2 + (n + p)
∎
where
+-assoc-1 : ∀ (n p : ℕ) → (1 + n) + p ≡ 1 + (n + p)
+-assoc-1 n p =
begin
(1 + n) + p ≡⟨⟩
suc (0 + n) + p ≡⟨⟩
suc ((0 + n) + p) ≡⟨ cong suc (+-assoc-0 n p) ⟩
suc (0 + (n + p)) ≡⟨⟩
1 + (n + p)
∎
where
+-assoc-0 : ∀ (n p : ℕ) → (0 + n) + p ≡ 0 + (n + p)
+-assoc-0 n p =
begin
(0 + n) + p ≡⟨⟩
n + p ≡⟨⟩
0 + (n + p)
∎
{-
------------------------------------------------------------------------------
## Terminology and notation
Evidence for a universal quantifier is a function. The notations
+-assoc : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
and
+-assoc : ∀ (m : ℕ)
→ ∀ (n : ℕ)
→ ∀ (p : ℕ)
→ (m + n) + p
≡ m + (n + p)
are equivalent.
differ from function type such as `ℕ → ℕ → ℕ`
- variables are associated with each argument type
- the result type may mention (or depend upon) these variables
- hence called _DEPENDENT functions_
------------------------------------------------------------------------------
## COMMUTATIVITY of ADDITION : m + n ≡ n + m
two lemmas used in proof
### first lemma
The base case of the definition of addition states that zero is a left-identity:
zero + n ≡ n
First lemma states that zero is also a right-identity:
-}
-- proof by induction on `m`
+-identityʳ : ∀ (m : ℕ)
→ m + zero
≡ m
-- base case : show:
-- zero + zero
-- ≡ zero
+-identityʳ zero =
begin
zero + zero ≡⟨⟩ -- _+_ base
zero
∎
-- inductive case : show:
-- (suc m) + zero
-- = suc m
+-identityʳ (suc m) =
begin
suc m + zero ≡⟨⟩ -- _+_ inductive
suc (m + zero) ≡⟨ cong suc (+-identityʳ m) ⟩
-- recursive invocation `+-identityʳ m`
-- has type of induction hypothesis
-- m + zero ≡ m
-- `cong suc` prefaces `suc` to each side of that type, yielding
-- suc (m + zero) ≡ suc m
suc m
∎
{-
### second lemma
inductive case of _+_ pushes `suc` on 1st arg to the outside:
suc m + n ≡ suc (m + n)
second lemma does same for `suc` on 2nd arg:
m + suc n ≡ suc (m + n)
-}
-- signature states defining `+-suc` which provides evidence for the proposition/type
+-suc : ∀ (m n : ℕ)
→ m + suc n
≡ suc (m + n)
-- evidence is fun that takes two nats, binds to `m` and `n`
-- returns evidence for the corresponding instance of the equation
-- proof is by induction on `m`
-- base case
+-suc zero n =
begin
zero + suc n ≡⟨⟩ -- _+_ base
suc n ≡⟨⟩ -- _+_ base
suc (zero + n)
∎
-- inductive case : show: suc m + suc n
-- ≡ suc (suc m + n)
+-suc (suc m) n =
begin
suc m + suc n ≡⟨⟩ -- _+_ inductive
suc (m + suc n) ≡⟨ cong suc (+-suc m n) ⟩ -- induction
suc (suc (m + n)) ≡⟨⟩ -- _+_ inductive
suc (suc m + n)
∎
-------------------------
+-comm : ∀ (m n : ℕ)
→ m + n
≡ n + m
+-comm m zero =
begin
m + zero ≡⟨ +-identityʳ m ⟩
m ≡⟨⟩
zero + m
∎
+-comm m (suc n) =
begin
m + suc n ≡⟨ +-suc m n ⟩
suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩ -- congruence and induction hypothesis
suc (n + m) ≡⟨⟩ -- _+_ inductive
suc n + m
∎
{-
definition required BEFORE using them
------------------------------------------------------------------------------
## COROLLARY: REARRANGING : apply associativity to rearrange parentheses (SYM; sections)
-}
+-rearrange : ∀ (m n p q : ℕ)
→ (m + n) + (p + q)
≡ m + (n + p) + q
+-rearrange m n p q =
begin
(m + n) + (p + q) ≡⟨ +-assoc m n (p + q) ⟩
m + (n + (p + q)) ≡⟨ cong (m +_) (sym (+-assoc n p q)) ⟩
m + ((n + p) + q) ≡⟨ sym (+-assoc m (n + p) q) ⟩
(m + (n + p)) + q ≡⟨⟩
m + (n + p) + q
∎
{-
no induction is required
NOTE:
addition is left associative : m + (n + p) + q
= (m + (n + p)) + q
SYM : interchange sides of an equation, e.g.,
- `+-assoc n p q` shifts parens right to left:
(n + p) + q ≡ n + (p + q)
`sym (+-assoc n p q)`: to shift them left-to-right
n + (p + q) ≡ (n + p) + q
general
- if `e` provides evidence for `x ≡ y`
- then `sym e` provides evidence for `y ≡ x`
SECTION NOTATION (introduced by Richard Bird) : `(x +_)` `(_+ x)`
------------------------------------------------------------------------------
## Creation, one last time
base case : `(zero + n) + p ≡ zero + (n + p)`
inductive case :
- if `(m + n) + p ≡ m + (n + p)` then
`(suc m + n) + p ≡ suc m + (n + p)`
using base case, associativity of zero on left:
(0 + 0) + 0 ≡ 0 + (0 + 0) ... (0 + 4) + 5 ≡ 0 + (4 + 5) ...
using inductive case
(1 + 0) + 0 ≡ 1 + (0 + 0) ... (1 + 4) + 5 ≡ 1 + (4 + 5) ...
(2 + 0) + 0 ≡ 2 + (0 + 0) ... (2 + 4) + 5 ≡ 2 + (4 + 5) ...
(3 + 0) + 0 ≡ 3 + (0 + 0) ... (3 + 4) + 5 ≡ 3 + (4 + 5) ...
...
there is a finite approach to generating the same equations (following exercise)
------------------------------------------------------------------------------
#### Exercise `finite-|-assoc` (stretch) {name=finite-plus-assoc} TODO - first four days of creation - description, not proof
Write out what is known about associativity of addition on each of the
first four days using a finite story of creation, as
[earlier](/Naturals/#finite-creation).
------------------------------------------------------------------------------
## proof of ASSOCIATIVITY using `rewrite` (rather than chains of equations)
avoids chains of equations and the need to invoke `cong`
-}
+-assoc′ : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
-- base
-- show: (zero + n) + p ≡ zero + (n + p)
-- _+_ base applied "invisibly", then terms equal/refl
+-assoc′ zero n p = refl
-- inductive
-- show: (suc m + n) + p ≡ suc m + (n + p)
-- _+_ inductive applied "invisibly" giving: suc ((m + n) + p) ≡ suc (m + (n + p))
-- rewrite with the inductive hypothesis
-- then terms are equal/refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = refl
{-
rewriting by a given equation
- indicated by keyword `rewrite`
- followed by a proof of that equation
------------------------------------------------------------------------------
## COMMUTATIVITY with rewrite
-}
+-suc′ : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc′ zero n = refl
+-suc′ (suc m) n rewrite +-suc′ m n = refl
+-comm′ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm′ m zero rewrite +-identityʳ m = refl
-- rewriting with two equations indicated by separating the two proofs
-- of the relevant equations by a vertical bar
-- left rewrite performed before right
+-comm′ m (suc n) -- m + suc n ≡ suc n + m
-- m + suc n ≡ suc (n + m) -- def/eq
rewrite
+-suc′ m n -- suc (m + n) ≡ suc (n + m)
| +-comm′ m n -- suc (n + m) ≡ suc (n + m)
= refl
+-comm′′ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm′′ m zero rewrite +-identityʳ m = refl
+-comm′′ m (suc n) =
begin
m + suc n ≡⟨ +-suc′ m n ⟩
suc (m + n) ≡⟨ cong suc (+-comm′′ m n) ⟩
suc (n + m) ≡⟨⟩ -- def/eq
suc n + m
∎
{-
------------------------------------------------------------------------------
HC
-}
*0 : ∀ (m : ℕ) → m * 0 ≡ 0
*0 zero = refl
*0 (suc m) = *0 m
0* : ∀ (m : ℕ) → 0 * m ≡ 0
0* m = refl
*1 : ∀ (n : ℕ) → n * 1 ≡ n
*1 zero = refl
*1 (suc n) rewrite *1 n = refl
1* : ∀ (n : ℕ) → 1 * n ≡ n
1* zero = refl
1* (suc n) rewrite 1* n = refl
{-
------------------------------------------------------------------------------
## Building proofs interactively
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ m n p = ?
C-c C-l
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ m n p = { }0
new window at the bottom:
?0 : ((m + n) + p) ≡ (m + (n + p))
indicates hole 0 needs to be filled with a proof of the stated judgment
to prove the proposition by induction on `m`
move cursor into hole
C-c C-c
prompt: pattern variables to case (empty for split on result):
type `m` to case split on that variable
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = { }0
+-assoc′ (suc m) n p = { }1
There are now two holes, and the window at the bottom tells you what
each is required to prove:
?0 : ((zero + n) + p) ≡ (zero + (n + p))
?1 : ((suc m + n) + p) ≡ (suc m + (n + p))
goto hole 0
C-c C-,
Goal: (n + p) ≡ (n + p)
————————————————————————————————————————————————————————————
p : ℕ
n : ℕ
indicates that after simplification the goal for hole 0 is as stated,
and that variables `p` and `n` of the stated types are available to use in the proof.
the proof of the given goal is simple
goto goal
C-c C-r
fills in with refl
C-c C-l renumbers remaining hole to 0:
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p = { }0
goto hole 0
C-c C-,
Goal: suc ((m + n) + p) ≡ suc (m + (n + p))
————————————————————————————————————————————————————————————
p : ℕ
n : ℕ
m : ℕ
gives simplified goal and available variables
need to rewrite by the induction hypothesis
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = { }0
goto hole
C-c C-,
Goal: suc (m + (n + p)) ≡ suc (m + (n + p))
————————————————————————————————————————————————————————————
p : ℕ
n : ℕ
m : ℕ
goto goal
C-c C-r
fills in, completing proof
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = refl
------------------------------------------------------------------------------
#### Exercise `+-swap` (recommended) {name=plus-swap}
Show
m + (n + p) ≡ n + (m + p)
for all naturals `m`, `n`, and `p`
- no induction
- use associativity and commutativity of addtion
-}
+-swap : ∀ (m n p : ℕ)
→ m + (n + p)
≡ n + (m + p)
+-swap m n p =
begin
m + (n + p) ≡⟨ sym (+-assoc m n p) ⟩
(m + n) + p ≡⟨ cong (_+ p) (sym (+-comm n m)) ⟩
(n + m) + p ≡⟨ +-assoc n m p ⟩
n + (m + p)
∎
{-
------------------------------------------------------------------------------
#### Exercise `*-distrib-+` (recommended) {name=times-distrib-plus} (m + n) * p ≡ m * p + n * p
-}
*-distrib-+r : ∀ (m n p : ℕ)
→ (m + n) * p
≡ m * p + n * p
*-distrib-+r zero y z = refl
*-distrib-+r (suc x) y z -- (suc x + y) * z ≡ suc x * z + y * z
-- z + (x + y) * z ≡ z + x * z + y * z
rewrite
*-distrib-+r x y z -- z + (x * z + y * z) ≡ z + x * z + y * z
| sym (+-assoc z (x * z) (y * z)) -- z + x * z + y * z ≡ z + x * z + y * z
= refl
{- TODO: agda loops on this : *-distrib-+r done with chain reasoning
*-distrib-+r' : ∀ (m n p : ℕ)
→ (m + n) * p
≡ m * p + n * p
*-distrib-+r' zero y z = refl
*-distrib-+r' (suc x) y z
begin
(suc x + y) * z ≡⟨⟩
z + (x + y) * z ≡⟨ *-distrib-+r' x y z ⟩
z + (x * z + y * z) ≡⟨ sym (+-assoc z (x * z) (y * z)) ⟩
z + x * z + y * z ≡⟨⟩
suc x * z + y * z
∎
-}
{-
------------------------------------------------------------------------------
#### Exercise `*-assoc` (recommended) {name=times-assoc} (m * n) * p ≡ m * (n * p)
-}
*-assoc : ∀ (m n p : ℕ)
→ (m * n) * p
≡ m * (n * p)
-- base case : show: (zero * n) * p
-- ≡ zero * (n * p)
*-assoc zero n p = refl -- zero * n * p ≡ zero * (n * p)
-- zero ≡ zero -- def/eq
-- inductive case : show: (suc m * n) * p
-- ≡ suc m * (n * p)
*-assoc (suc m) n p -- suc m * n * p ≡ suc m * (n * p)
-- (n + m * n) * p ≡ n * p + m * (n * p)
rewrite
*-distrib-+r n (m * n) p -- n * p + m * n * p ≡ n * p + m * (n * p)
| *-assoc m n p -- n * p + m * (n * p) ≡ n * p + m * (n * p)
= refl
{-
------------------------------------------------------------------------------
#### Exercise `*-comm` (practice) {name=times-comm} MULTIPLICATION is COMMUTATIVE : m * n ≡ n * m
-}
*-suc : ∀ (x y : ℕ) → x * (suc y) ≡ x + (x * y)
*-suc zero y = refl
*-suc (suc x) y -- suc x * suc y ≡ suc x + suc x * y
-- suc (y + x * suc y) ≡ suc (x + (y + x * y))
rewrite
+-comm y (x * suc y) -- suc (x * suc y + y) ≡ suc (x + (y + x * y))
| *-suc x y -- suc (x + x * y + y) ≡ suc (x + (y + x * y))
| +-comm y (x * y) -- suc (x + x * y + y) ≡ suc (x + (x * y + y))
| sym (+-assoc x (x * y) y) -- suc (x + x * y + y) ≡ suc (x + x * y + y)
= refl
*-comm : ∀ (m n : ℕ) → m * n ≡ n * m
*-comm m zero rewrite *0 m = refl
*-comm m (suc n) -- m * suc n ≡ suc n * m
-- m * suc n ≡ m + n * m
rewrite
*-suc m n -- m + m * n ≡ m + n * m
| *-comm m n -- m + n * m ≡ m + n * m
= refl
{-
------------------------------------------------------------------------------
#### Exercise `0∸n≡0` (practice) {name=zero-monus} : Show zero ∸ n ≡ zero
for all naturals `n`. Did your proof require induction?
-}
0∸n≡0 : ∀ (n : ℕ) → 0 ∸ n ≡ 0
0∸n≡0 zero = refl
0∸n≡0 (suc n) = refl
{-
------------------------------------------------------------------------------
#### Exercise `∸-|-assoc` (practice) {name=monus-plus-assoc} : m ∸ n ∸ p ≡ m ∸ (n + p)
show that monus associates with addition
-}
∸-|-assoc : ∀ (m n p : ℕ) → m ∸ n ∸ p ≡ m ∸ (n + p)
∸-|-assoc m n zero -- m ∸ n ∸ zero ≡ m ∸ (n + zero)
-- m ∸ n ≡ m ∸ (n + zero)
rewrite +-identityʳ n = refl -- m ∸ n ≡ m ∸ n
∸-|-assoc m zero (suc p) -- m ∸ zero ∸ suc p ≡ m ∸ (zero + suc p)
= refl -- m ∸ suc p ≡ m ∸ suc p
∸-|-assoc zero (suc n) (suc p) -- zero ∸ suc n ∸ suc p ≡ zero ∸ (suc n + suc p)
= refl -- zero ≡ zero
∸-|-assoc (suc m) (suc n) (suc p) -- suc m ∸ suc n ∸ suc p ≡ suc m ∸ (suc n + suc p)
-- m ∸ n ∸ suc p ≡ m ∸ (n + suc p)
rewrite
∸-|-assoc m n (suc p) -- m ∸ (n + suc p) ≡ m ∸ (n + suc p)
= refl
{-
------------------------------------------------------------------------------
#### Exercise `+*^` (stretch)
m ^ (n + p) ≡ (m ^ n) * (m ^ p) (^-distribˡ-|-*)
(m * n) ^ p ≡ (m ^ p) * (n ^ p) (^-distribʳ-*)
(m ^ n) ^ p ≡ m ^ (n * p) (^-*-assoc)
-}
-------------------------
-- this can be shortened
^-distribˡ-|-* : ∀ (m n p : ℕ)
→ m ^ (n + p)
≡ (m ^ n) * (m ^ p)
^-distribˡ-|-* m n zero -- (m ^ (n + zero)) ≡ (m ^ n) * (m ^ zero)
-- (m ^ (n + zero)) ≡ (m ^ n) * 1
rewrite
+-identityʳ n -- (m ^ n) ≡ (m ^ n) * 1
| *1 (m ^ n) -- (m ^ n) ≡ (m ^ n)
= refl
^-distribˡ-|-* m n (suc p) -- (m ^ (n + suc p)) ≡ (m ^ n) * (m ^ suc p)
-- (m ^ (n + suc p)) ≡ (m ^ n) * (m * (m ^ p))
rewrite
*-comm m (m ^ p) -- (m ^ (n + suc p)) ≡ (m ^ n) * ((m ^ p) * m)
| sym (*-assoc (m ^ n) (m ^ p) m) -- (m ^ (n + suc p)) ≡ (m ^ n) * (m ^ p) * m
| +-comm n (suc p) -- (m ^ suc (p + n)) ≡ (m ^ n) * (m ^ p) * m
-- m * (m ^ (p + n)) ≡ (m ^ n) * (m ^ p) * m
| *-comm ((m ^ n) * (m ^ p)) m -- m * (m ^ (p + n)) ≡ m * ((m ^ n) * (m ^ p))
| sym (*-assoc m (m ^ n) (m ^ p)) -- m * (m ^ (p + n)) ≡ m * (m ^ n) * (m ^ p)
| ^-distribˡ-|-* m p n -- m * ((m ^ p) * (m ^ n)) ≡ m * (m ^ n) * (m ^ p)
| sym (*-comm (m ^ n) (m ^ p)) -- m * ((m ^ n) * (m ^ p)) ≡ m * (m ^ n) * (m ^ p)
| *-assoc m (m ^ n) (m ^ p) -- m * ((m ^ n) * (m ^ p)) ≡ m * ((m ^ n) * (m ^ p))
= refl
-------------------------
^-distribʳ-* : ∀ (m n p : ℕ)
→ (m * n) ^ p
≡ (m ^ p) * (n ^ p)
^-distribʳ-* m n zero = refl
^-distribʳ-* m n (suc p) -- ((m * n) ^ suc p) ≡(m ^ suc p) * (n ^ suc p)
-- m * n * ((m * n) ^ p) ≡ m * (m ^ p) * (n * (n ^ p))
rewrite
^-distribʳ-* m n p -- m * n * ((m ^ p) * (n ^ p)) ≡ m * (m ^ p) * (n * (n ^ p))
| *-comm (m * (m ^ p)) (n * (n ^ p))
-- m * n * ((m ^ p) * (n ^ p)) ≡ n * (n ^ p) * (m * (m ^ p))
| *-assoc m n ((m ^ p) * (n ^ p)) -- m *(n * ((m ^ p) * (n ^ p)))≡ n * (n ^ p) * (m * (m ^ p))
| *-comm m (n * ((m ^ p) * (n ^ p)))
-- n *((m ^ p) * (n ^ p))* m ≡ n * (n ^ p) * (m * (m ^ p))
| *-comm (m ^ p) (n ^ p) -- n *((n ^ p) * (m ^ p))* m ≡ n * (n ^ p) * (m * (m ^ p))
| sym (*-assoc n (n ^ p) (m ^ p)) -- n * (n ^ p) * (m ^ p) * m ≡ n * (n ^ p) * (m * (m ^ p))
| *-assoc n (n ^ p) (m * (m ^ p)) -- n * (n ^ p) * (m ^ p) * m ≡ n *((n ^ p) * (m * (m ^ p)))
| *-comm m (m ^ p) -- n * (n ^ p) * (m ^ p) * m ≡ n *((n ^ p) * ((m ^ p) * m))
| *-assoc n (n ^ p) (m ^ p) -- n *((n ^ p) * (m ^ p))* m ≡ n *((n ^ p) * ((m ^ p) * m))
| *-assoc n ((n ^ p) * (m ^ p)) m -- n *((n ^ p) * (m ^ p) * m) ≡ n *((n ^ p) * ((m ^ p) * m))
| *-assoc (n ^ p) (m ^ p) m -- n *((n ^ p) *((m ^ p) * m))≡ n *((n ^ p) * ((m ^ p) * m))
= refl
-------------------------
^-*-assoc : ∀ (m n p : ℕ)
→ (m ^ n) ^ p
≡ m ^ (n * p)
^-*-assoc m n zero -- ((m ^ n) ^ zero) ≡ (m ^ (n * zero))
-- 1 ≡ (m ^ (n * zero))
rewrite *0 n -- 1 ≡ (m ^ 0)
-- 1 ≡ 1
= refl
^-*-assoc m n (suc p) -- ((m ^ n) ^ suc p) ≡ (m ^ (n * suc p))
-- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ (n * suc p))
rewrite
*-suc n p -- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ (n + n * p))
| ^-distribˡ-|-* m n (n * p) -- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ n) * (m ^ (n * p))
| sym (^-*-assoc m n p) -- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ n) * ((m ^ n) ^ p)
= refl
{-
------------------------------------------------------------------------------
#### Exercise `Bin-laws` (stretch) {name=Bin-laws}
Recall that
Exercise [Bin](/Naturals/#Bin)
defines a datatype `Bin` of bitstrings representing natural numbers,
and asks you to define functions
-}
-- begin duplicated from x01 (can't import because of "duplicate" pragma)
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (b O) = b I
inc (b I) = (inc b) O
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
-- end duplicated
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc m) = suc (suc (dbl m))
to : ℕ → Bin
to zero = ⟨⟩ O
to (suc m) = inc (to m)
-- THIS IS THE CRITICAL STEP : defining in terms of 'dbl'
-- Got hint from : https://cs.uwaterloo.ca/~plragde/842/
from : Bin → ℕ
from ⟨⟩ = 0
from (b O) = dbl (from b)
from (b I) = suc (dbl (from b))
_ : to 6 ≡ ⟨⟩ I I O
_ = refl
_ : from (⟨⟩ I I O) ≡ 6
_ = refl
{-
Consider the following laws, where `n` ranges over naturals and `b`
over bitstrings:
from (inc b) ≡ suc (from b)
to (from b) ≡ b
from (to n) ≡ n
For each law: if it holds, prove; if not, give a counterexample.
-}
-------------------------
-- fromInc≡sucFrom
+1 : ∀ (x : ℕ) → x + 1 ≡ suc x
+1 zero = refl
+1 (suc n) rewrite +1 n = refl
fromInc≡sucFrom : ∀ (b : Bin)
→ from (inc b) ≡ suc (from b)
fromInc≡sucFrom ⟨⟩ -- from (inc ⟨⟩) ≡ suc (from ⟨⟩)
-- 1 ≡ 1
= refl
fromInc≡sucFrom (⟨⟩ I) -- from (inc (⟨⟩ I)) ≡ suc (from (⟨⟩ I))
-- 2 ≡ 2
= refl
fromInc≡sucFrom (b O) -- from (inc (b O)) ≡ suc (from (b O))
-- dbl (from b) + 1 ≡ suc (dbl (from b))
rewrite
+1 (dbl (from b)) -- suc (dbl (from b)) ≡ suc (dbl (from b))
= refl
fromInc≡sucFrom (b I) -- from (inc (b I)) ≡ suc (from (b I))
-- dbl (from (inc b)) ≡ suc (dbl (from b) + 1)
rewrite
+1 (dbl (from b)) -- dbl (from (inc b)) ≡ suc (suc (dbl (from b)))
| fromInc≡sucFrom b -- dbl (suc (from b)) ≡ suc (suc (dbl (from b)))
-- suc (suc (dbl (from b))) ≡ suc (suc (dbl (from b)))
= refl
-------------------------
-- to-from≡b -- cannot be proved because there are TWO representations of ZERO
-- NOT USED
xx : ∀ (b : Bin)
→ (dbl (from b)) ≡ from (b O)
xx ⟨⟩ -- dbl (from ⟨⟩) ≡ from (⟨⟩ O)
-- zero ≡ zero
= refl
xx (b O) -- dbl (from (b O)) ≡ from ((b O) O)
-- dbl (dbl (from b)) ≡ dbl (dbl (from b))
= refl
xx (b I) -- dbl (from (b I)) ≡ from ((b I) O)
-- suc (suc (dbl (dbl (from b)))) ≡ suc (suc (dbl (dbl (from b))))
= refl
-- CANNOT BE PROVED BECAUSE TWO REPRESENTATIONS OF ZERO : (⟨⟩) and (⟨⟩ O)
yy : ∀ (b : Bin)
→ to (dbl (from b)) ≡ (b O)
yy ⟨⟩ -- to (dbl (from ⟨⟩)) ≡ (⟨⟩ O)
-- (⟨⟩ O) ≡ (⟨⟩ O)
= refl
yy (b O) -- to (dbl (from (b O))) ≡ ((b O) O)
-- to (dbl (dbl (from b))) ≡ ((b O) O)
rewrite
yy b
= {!!}
yy (b I) -- to (dbl (from (b I))) ≡ ((b I) O)
-- inc (inc (to (dbl (dbl (from b))))) ≡ ((b I) O)
= {!!}
to-from : ∀ (b : Bin)
→ to (from b) ≡ b
to-from ⟨⟩ -- to (from ⟨⟩) ≡ ⟨⟩
-- (⟨⟩ O) ≡ ⟨⟩ -- *****
= {!!}
to-from (⟨⟩ I) -- to (from (⟨⟩ I)) ≡ (⟨⟩ I)
-- (⟨⟩ I) ≡ (⟨⟩ I)
= refl
to-from (b O) -- to (from (b O)) ≡ (b O)
-- to (dbl (from b)) ≡ (b O)
rewrite
yy b -- (b O) ≡ (b O)
= refl
to-from (b I) -- to (from (b I)) ≡ (b I)
-- inc (to (dbl (from b))) ≡ (b I)
rewrite
yy b -- (b I) ≡ (b I)
= refl
-------------------------
-- https://github.com/billyang98/plfa/blob/master/plfa/Induction.agda
from-inc≡suc-from : ∀ x → from (inc x) ≡ suc (from x)
from-inc≡suc-from ⟨⟩ = refl
from-inc≡suc-from (x O) = refl
from-inc≡suc-from (x I) -- from (inc (x I)) ≡ suc (from (x I))
-- dbl (from (inc x)) ≡ suc (suc (dbl (from x)))
rewrite
from-inc≡suc-from x -- suc (suc (dbl (from x))) ≡ suc (suc (dbl (from x)))
= refl
from-to : ∀ n → from (to n) ≡ n
from-to zero = refl
from-to (suc n) -- from (to (suc n)) ≡ suc n
-- from (inc (to n)) ≡ suc n
rewrite
from-inc≡suc-from (to n) -- suc (from (to n)) ≡ suc n
| cong suc (from-to n) -- suc n ≡ suc n
= refl
{-
------------------------------------------------------------------------------
## Standard library
Definitions similar to those in this chapter can be found in the standard library:
```
import Data.Nat.Properties using (+-assoc; +-identityʳ; +-suc; +-comm)
```
------------------------------------------------------------------------------
## Unicode
This chapter uses the following unicode:
∀ U+2200 FOR ALL (\forall, \all)
ʳ U+02B3 MODIFIER LETTER SMALL R (\^r)
′ U+2032 PRIME (\')
″ U+2033 DOUBLE PRIME (\')
‴ U+2034 TRIPLE PRIME (\')
⁗ U+2057 QUADRUPLE PRIME (\')
Similar to `\r`, the command `\^r` gives access to a variety of
superscript rightward arrows, and also a superscript letter `r`.
The command `\'` gives access to a range of primes (`′ ″ ‴ ⁗`).
-}
-- ============================================================================
-- this is here to ensure the Bin/in/from/to does not get broken if changed above
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
_ : inc (⟨⟩ O) ≡ ⟨⟩ I
_ = refl
_ : inc (⟨⟩ I) ≡ ⟨⟩ I O
_ = refl
_ : inc (⟨⟩ I O) ≡ ⟨⟩ I I
_ = refl
_ : inc (⟨⟩ I I) ≡ ⟨⟩ I O O
_ = refl
_ : inc (⟨⟩ I O O) ≡ ⟨⟩ I O I
_ = refl
_ : from (⟨⟩ O) ≡ 0
_ = refl
_ : from (⟨⟩ I) ≡ 1
_ = refl
_ : from (⟨⟩ I O) ≡ 2
_ = refl
_ : from (⟨⟩ I I) ≡ 3
_ = refl
_ : from (⟨⟩ I O O) ≡ 4
_ = refl
_ : to 0 ≡ (⟨⟩ O)
_ = refl
_ : to 1 ≡ (⟨⟩ I)
_ = refl
_ : to 2 ≡ (⟨⟩ I O)
_ = refl
_ : to 3 ≡ (⟨⟩ I I)
_ = refl
_ : to 4 ≡ (⟨⟩ I O O)
_ = refl
_ : from (to 12) ≡ 12
_ = refl
_ : to (from (⟨⟩ I I O O)) ≡ ⟨⟩ I I O O
_ = refl
| 30.640852
| 125
| 0.405314
|
069054f486ba356bde500a8c0b441790b204a41f
| 12,782
|
agda
|
Agda
|
CaTT/Fullness.agda
|
ThiBen/catt-formalization
|
ed45935b38d6a86fa662f561866140122ee3dcef
|
[
"MIT"
] | 2
|
2020-05-01T08:26:53.000Z
|
2020-05-20T00:41:09.000Z
|
CaTT/Fullness.agda
|
ThiBen/catt-formalization
|
ed45935b38d6a86fa662f561866140122ee3dcef
|
[
"MIT"
] | null | null | null |
CaTT/Fullness.agda
|
ThiBen/catt-formalization
|
ed45935b38d6a86fa662f561866140122ee3dcef
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import Prelude
open import GSeTT.Syntax
open import GSeTT.Rules
open import GSeTT.Disks
open import CaTT.Ps-contexts
open import CaTT.Uniqueness-Derivations-Ps
open import Sets ℕ eqdecℕ
module CaTT.Fullness where
data Ty : Set₁
data Tm : Set₁
data Sub : Set₁
data _is-full-in_ : Ty → ps-ctx → Set₁
data Ty where
∗ : Ty
_⇒[_]_ : Tm → Ty → Tm → Ty
data Tm where
v : ℕ → Tm
coh : (Γ : ps-ctx) → (A : Ty) → A is-full-in Γ → Sub → Tm
data Sub where
<> : Sub
<_,_↦_> : Sub → ℕ → Tm → Sub
infix 50 _⇒[_]_
=⇒Ty : ∀ {A A' : Ty} {t t' u u' : Tm} → _==_ {A = Ty} (t ⇒[ A ] u) (t' ⇒[ A' ] u') → ((A == A' × t == t') × u == u')
=⇒Ty idp = (idp , idp) , idp
coh= : ∀ {Γ Γ' A A' Afull A'full γ γ'} → coh Γ A Afull γ == coh Γ' A' A'full γ' → ((Γ == Γ' × A == A') × γ == γ')
coh= idp = (idp , idp) , idp
<>= : ∀ {γ γ' x x' t t'} → < γ , x ↦ t > == < γ' , x' ↦ t' > → ((γ == γ' × x == x') × t == t')
<>= idp = (idp , idp) , idp
{- Set of variables -}
varC : Pre-Ctx → set
varC nil = Ø
varC (Γ :: (x , _)) = (varC Γ) ∪-set (singleton x)
varT : Ty → set
vart : Tm → set
varS : Sub → set
varT ∗ = Ø
varT (t ⇒[ A ] u) = (varT A) ∪-set ((vart t) ∪-set (vart u))
vart (v x) = singleton x
vart (coh Γ A Afull γ) = varS γ
varS <> = Ø
varS < γ , x ↦ t > = (varS γ) ∪-set (vart t)
{- fullness condition -}
data _is-full-in_ where
side-cond₁ : ∀ Γ A t u → (src-var Γ) ≗ ((varT A) ∪-set (vart t)) → (tgt-var Γ) ≗ ((varT A) ∪-set (vart u)) → (t ⇒[ A ] u) is-full-in Γ
side-cond₂ : ∀ Γ A → (varC (fst Γ)) ≗ (varT A) → A is-full-in Γ
∈-drop : ∀ {A : Set} {a : A} {l : list A} → a ∈-list drop l → a ∈-list l
∈-drop {A} {a} {l :: a₁} x = inl x
l∉∂⁻ : ∀ {Γ i x A y} → (Γ⊢ps : Γ ⊢ps x # A) → length Γ ≤ y → ¬ (y ∈-list (srcᵢ-var i Γ⊢ps))
l∉∂⁻ {i = i} pss lΓ≤y y∈ with eqdecℕ i O
... | inl _ = y∈
l∉∂⁻ {i = i} pss lΓ≤y (inr idp) | inr _ = Sn≰n _ lΓ≤y
l∉∂⁻ (psd Γ⊢ps) lΓ≤y y∈ = l∉∂⁻ Γ⊢ps lΓ≤y y∈
l∉∂⁻ {i = i} (pse {A = A} Γ⊢ps idp idp idp idp idp) SSl≤y y∈ with dec-≤ i (S (dim A))
... | inl _ = l∉∂⁻ Γ⊢ps (Sn≤m→n≤m (Sn≤m→n≤m SSl≤y)) y∈
l∉∂⁻ {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inl (inl y∈)) | inr _ = l∉∂⁻ Γ⊢ps (Sn≤m→n≤m (Sn≤m→n≤m SSl≤y)) y∈
l∉∂⁻ {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inl (inr idp)) | inr _ = Sn≰n _ (n≤m→n≤Sm SSl≤y)
l∉∂⁻ {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inr idp) | inr _ = Sn≰n _ SSl≤y
l∉∂⁺ : ∀ {Γ i x A y} → (Γ⊢ps : Γ ⊢ps x # A) → length Γ ≤ y → ¬ (y ∈-list (tgtᵢ-var i Γ⊢ps))
l∉∂⁺ {i = i} pss lΓ≤y y∈ with eqdecℕ i O
... | inl _ = y∈
l∉∂⁺ {i = i} pss lΓ≤y (inr idp) | inr _ = Sn≰n _ lΓ≤y
l∉∂⁺ (psd Γ⊢ps) lΓ≤y y∈ = l∉∂⁺ Γ⊢ps lΓ≤y y∈
l∉∂⁺ {i = i} (pse {A = A} Γ⊢ps idp idp idp idp idp) SSl≤y y∈ with dec-≤ i (S (dim A))
l∉∂⁺ {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inl (inl y∈)) | inr _ = l∉∂⁺ Γ⊢ps (Sn≤m→n≤m (Sn≤m→n≤m SSl≤y)) y∈
l∉∂⁺ {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inl (inr idp)) | inr _ = Sn≰n _ (n≤m→n≤Sm SSl≤y)
l∉∂⁺ {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inr idp) | inr x = Sn≰n _ SSl≤y
... | inl _ with eqdecℕ i (S (dim A))
l∉∂⁺ {i = .(S (dim _))} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inl y∈drop) | inl _ | inl idp = l∉∂⁺ Γ⊢ps (Sn≤m→n≤m (Sn≤m→n≤m SSl≤y)) (∈-drop y∈drop)
l∉∂⁺ {i = .(S (dim _))} (pse {A = _} Γ⊢ps idp idp idp idp idp) SSl≤y (inr idp) | inl _ | inl idp = Sn≰n _ (n≤m→n≤Sm SSl≤y)
... | inr _ = l∉∂⁺ Γ⊢ps (Sn≤m→n≤m (Sn≤m→n≤m SSl≤y)) y∈
∂⁻ᵢ-var : ∀ {Γ x A y B i} → (Γ⊢ps : Γ ⊢ps x # A) → Γ ⊢t (Var y) # B → i ≤ dim B → ¬ (y ∈-list (srcᵢ-var i Γ⊢ps))
∂⁻ᵢ-var pss (var x (inr (idp , idp))) (0≤ .0) ()
∂⁻ᵢ-var (psd Γ⊢ps) Γ⊢y i≤B y∈∂⁻ = ∂⁻ᵢ-var Γ⊢ps Γ⊢y i≤B y∈∂⁻
∂⁻ᵢ-var {i = i} (pse {A = A} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B y∈∂⁻ with dec-≤ i (S (dim A))
... | inl _ = ∂⁻ᵢ-var Γ⊢ps (var (psv Γ⊢ps) y∈Γ) i≤B y∈∂⁻
∂⁻ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inl (inl y∈∂⁻)) | inr _ = ∂⁻ᵢ-var Γ⊢ps (var (psv Γ⊢ps) y∈Γ) i≤B y∈∂⁻
∂⁻ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inl (inr idp)) | inr _ = x∉ (psv Γ⊢ps) (n≤n _) (var (psv Γ⊢ps) y∈Γ)
∂⁻ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inr idp) | inr _ = x∉ (psv Γ⊢ps) (n≤Sn _) (var (psv Γ⊢ps) y∈Γ)
∂⁻ᵢ-var {i = i} (pse {A = B} Γ⊢ps idp idp idp idp idp) (var _ (inl (inr (idp , idp)))) i≤B y∈∂⁻ with dec-≤ i (S (dim B))
... | inl _ = l∉∂⁻ Γ⊢ps (n≤n _) y∈∂⁻
... | inr i≰SB = i≰SB (n≤m→n≤Sm i≤B)
∂⁻ᵢ-var {i = i} (pse {A = A} Γ⊢ps idp idp idp idp idp) (var _ (inr (idp , idp))) i≤SA y∈∂⁻ with dec-≤ i (S (dim A))
... | inl _ = l∉∂⁻ Γ⊢ps (n≤Sn _) y∈∂⁻
... | inr i≰SA = i≰SA i≤SA
∂⁺ᵢ-var : ∀ {Γ x A y B i} → (Γ⊢ps : Γ ⊢ps x # A) → Γ ⊢t (Var y) # B → i ≤ dim B → ¬ (y ∈-list (tgtᵢ-var i Γ⊢ps))
∂⁺ᵢ-var pss (var x (inr (idp , idp))) (0≤ .0) ()
∂⁺ᵢ-var (psd Γ⊢ps) Γ⊢y i≤B y∈∂⁺ = ∂⁺ᵢ-var Γ⊢ps Γ⊢y i≤B y∈∂⁺
∂⁺ᵢ-var {i = i} (pse {A = A} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B y∈∂⁺ with dec-≤ i (S (dim A))
... | inl i≤SdimA with eqdecℕ i (S (dim A))
... | inr _ = ∂⁺ᵢ-var Γ⊢ps (var (psv Γ⊢ps) y∈Γ) i≤B y∈∂⁺
∂⁺ᵢ-var {i = .(S (dim _))} (pse {A = A} Γ⊢ps idp idp idp idp idp) (var {x = y} _ (inl (inl y∈Γ))) i≤B (inl y∈drop) | inl i≤SdimA | inl idp = ∂⁺ᵢ-var Γ⊢ps (var (psv Γ⊢ps) y∈Γ) i≤B (∈-drop y∈drop)
∂⁺ᵢ-var {i = .(S (dim _))} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inr idp) | inl i≤SdimA | inl idp = lΓ∉Γ (psv Γ⊢ps) y∈Γ
∂⁺ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inl (inl y∈∂⁻)) | inr _ = ∂⁺ᵢ-var Γ⊢ps (var (psv Γ⊢ps) y∈Γ) i≤B y∈∂⁻
∂⁺ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inl (inr idp)) | inr _ = x∉ (psv Γ⊢ps) (n≤n _) (var (psv Γ⊢ps) y∈Γ)
∂⁺ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inl (inl y∈Γ))) i≤B (inr idp) | inr _ = x∉ (psv Γ⊢ps) (n≤Sn _) (var (psv Γ⊢ps) y∈Γ)
∂⁺ᵢ-var {i = i} (pse {A = B} Γ⊢ps idp idp idp idp idp) (var _ (inl (inr (idp , idp)))) i≤B y∈∂⁺ with dec-≤ i (S (dim B))
... | inr i≰SB = i≰SB (n≤m→n≤Sm i≤B)
... | inl _ with eqdecℕ i (S (dim B))
... | inr _ = l∉∂⁺ Γ⊢ps (n≤n _) y∈∂⁺
∂⁺ᵢ-var (pse Γ⊢ps idp idp idp idp idp) (var _ (inl (inr (idp , idp)))) i≤B (inl l∈drop) | inl _ | inl _ = l∉∂⁺ Γ⊢ps (n≤n _) (∈-drop l∈drop)
∂⁺ᵢ-var (pse Γ⊢ps idp idp idp idp idp) (var _ (inl (inr (idp , idp)))) i≤B (inr p) | inl _ | inl idp = Sn≰n _ i≤B
∂⁺ᵢ-var {i = i} (pse {A = A} Γ⊢ps idp idp idp idp idp) (var _ (inr (idp , idp))) i≤SA y∈∂⁺ with dec-≤ i (S (dim A))
... | inr i≰SA = i≰SA i≤SA
... | inl _ with eqdecℕ i (S (dim A))
... | inr _ = l∉∂⁺ Γ⊢ps (n≤Sn _) y∈∂⁺
∂⁺ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inr (idp , idp))) i≤SA (inl Sl∈drop) | inl _ | inl _ = l∉∂⁺ Γ⊢ps (n≤Sn _) (∈-drop Sl∈drop)
∂⁺ᵢ-var {i = i} (pse {A = _} Γ⊢ps idp idp idp idp idp) (var _ (inr (idp , idp))) i≤SA (inr Sl=l) | inl _ | inl _ = Sn≠n _ Sl=l
∈-varC : ∀ {Γ x A} → x # A ∈ Γ → x ∈-set (varC Γ)
∈-varC {Γ :: (y , B)} {x} {A} (inl x∈Γ) = ∈-∪₁ {A = varC Γ} {B = singleton y} (∈-varC x∈Γ)
∈-varC {Γ :: (y , B)} {x} {A} (inr (idp , _)) = ∈-∪₂ {A = varC Γ} {B = singleton y} (∈-singleton y)
max-var-def : Pre-Ctx → ℕ × Pre-Ty
max-var-def nil = 0 , ∗
max-var-def (Γ :: (y , B)) with dec-≤ (dimC Γ) (dim B)
... | inr _ = max-var-def Γ
... | inl _ = y , B
max-var-is-max : ∀ {Γ} → Γ ≠ nil → Γ ⊢C → let (x , A) = max-var-def Γ in ((x # A ∈ Γ) × (dimC Γ == dim A))
max-var-is-max {nil} Γ≠nil _ = ⊥-elim (Γ≠nil idp)
max-var-is-max {Γ :: (y , B)} _ Γ⊢ with dec-≤ (dimC Γ) (dim B)
... | inl _ = inr (idp , idp) , idp
... | inr _ with Γ
max-var-is-max {Γ :: (y , B)} _ (cc Γ⊢ Γ⊢B idp) | inr _ | Δ :: (x , A) = let (x∈ , dimA) = max-var-is-max (λ{()}) Γ⊢ in inl x∈ , dimA
max-var-is-max {Γ :: (.0 , .∗)} _ (cc Γ⊢ (ob _) idp) | inr _ | nil = inr (idp , idp) , idp
max-var-is-max {Γ :: (.0 , _)} _ (cc Γ⊢ (ar _ _ _) idp) | inr dΓ≤dB | nil = ⊥-elim (dΓ≤dB (0≤ _))
psx-nonul : ∀ {Γ x A} → Γ ⊢ps x # A → Γ ≠ nil
psx-nonul (psd x) idp = psx-nonul x idp
ps-nonul : ∀ {Γ} → Γ ⊢ps → Γ ≠ nil
ps-nonul (ps Γ⊢ps) = psx-nonul Γ⊢ps
max-var : ∀ {Γ} → Γ ⊢ps → Σ (ℕ × Pre-Ty) λ {(x , A) → (x # A ∈ Γ) × (dimC Γ == dim A)}
max-var {Γ} Γ⊢ps@(ps Γ⊢psx) = max-var-def Γ , max-var-is-max (ps-nonul Γ⊢ps) (psv Γ⊢psx)
∂Γ-not-full : ∀ Γ → ¬ (varC (fst Γ) ⊂ ((src-var Γ) ∪-set (tgt-var Γ)))
∂Γ-not-full (Γ , Γ⊢ps@(ps Γ⊢psx)) vΓ⊂∂ = let ((x , A) , (x∈Γ , dimA)) = max-var Γ⊢ps in
∉-∪ {set-of-list (srcᵢ-var (dimC Γ) Γ⊢psx)} {set-of-list (tgtᵢ-var (dimC Γ) Γ⊢psx)} {x}
(λ x∈∂⁻ → ∂⁻ᵢ-var Γ⊢psx (var (psv Γ⊢psx) x∈Γ) (≤-= (n≤n _) dimA) (∈-set-∈-list _ _ x∈∂⁻))
(λ x∈∂⁺ → ∂⁺ᵢ-var Γ⊢psx (var (psv Γ⊢psx) x∈Γ) (≤-= (n≤n _) dimA) (∈-set-∈-list _ _ x∈∂⁺))
(vΓ⊂∂ x (∈-varC x∈Γ))
disjoint-cond : ∀ Γ A t u → (src-var Γ) ≗ ((varT A) ∪-set (vart t)) → (tgt-var Γ) ≗ ((varT A) ∪-set (vart u)) → ¬ (varC (fst Γ) ≗ varT (t ⇒[ A ] u))
disjoint-cond Γ A t u (_ , A⊂∂⁻) (_ , A⊂∂⁺) (Γ⊂A , _) =
let vA = varT A in let vt = vart t in let vu = vart u in
let sr = src-var Γ in let tg = tgt-var Γ in
∂Γ-not-full Γ
(⊂-trans {varC (fst Γ)} {vA ∪-set (vt ∪-set vu)} {sr ∪-set tg} Γ⊂A
(≗-⊂ {vA ∪-set (vt ∪-set vu)} {(vA ∪-set vt) ∪-set (vA ∪-set vu)} {sr ∪-set tg} (∪-factor (varT A) (vart t) (vart u))
(⊂-∪ {vA ∪-set vt} {sr} {vA ∪-set vu} {tg} A⊂∂⁻ A⊂∂⁺)))
side-cond₁= : ∀ Γ A t u ∂⁻-full₁ ∂⁻-full₂ ∂⁺-full₁ ∂⁺-full₂ → ∂⁻-full₁ == ∂⁻-full₂ → ∂⁺-full₁ == ∂⁺-full₂ → side-cond₁ Γ A t u ∂⁻-full₁ ∂⁺-full₁ == side-cond₁ Γ A t u ∂⁻-full₂ ∂⁺-full₂
side-cond₁= Γ A t u ∂⁻-full₁ .∂⁻-full₁ ∂⁺-full₁ .∂⁺-full₁ idp idp = idp
has-all-paths-is-full : ∀ Γ A → has-all-paths (A is-full-in Γ)
has-all-paths-is-full Γ .(t ⇒[ A ] u) (side-cond₁ .Γ A t u x x₁) (side-cond₁ .Γ .A .t .u x₂ x₃) = ap² (λ ∂⁻ → λ ∂⁺ → side-cond₁ Γ A t u ∂⁻ ∂⁺) (is-prop-has-all-paths (is-prop-≗ (src-var Γ) (varT A ∪-set vart t)) x x₂) (is-prop-has-all-paths (is-prop-≗ (tgt-var Γ) (varT A ∪-set vart u)) x₁ x₃)
has-all-paths-is-full Γ .(t ⇒[ A ] u) (side-cond₁ .Γ A t u ∂⁻ ∂⁺) (side-cond₂ .Γ .(t ⇒[ A ] u) full) = ⊥-elim (disjoint-cond Γ A t u ∂⁻ ∂⁺ full)
has-all-paths-is-full Γ .(t ⇒[ A ] u) (side-cond₂ .Γ .(t ⇒[ A ] u) full) (side-cond₁ .Γ A t u ∂⁻ ∂⁺) = ⊥-elim (disjoint-cond Γ A t u ∂⁻ ∂⁺ full)
has-all-paths-is-full Γ A (side-cond₂ .Γ .A x) (side-cond₂ .Γ .A x₁) = ap (side-cond₂ Γ A) (is-prop-has-all-paths (is-prop-≗ (varC (fst Γ)) (varT A)) x x₁)
is-prop-full : ∀ Γ A → is-prop (A is-full-in Γ)
is-prop-full Γ A = has-all-paths-is-prop (has-all-paths-is-full Γ A)
eqdec-Ty : eqdec Ty
eqdec-Tm : eqdec Tm
eqdec-Sub : eqdec Sub
eqdec-Ty ∗ ∗ = inl idp
eqdec-Ty ∗ (_ ⇒[ _ ] _) = inr λ{()}
eqdec-Ty (_ ⇒[ _ ] _) ∗ = inr λ{()}
eqdec-Ty (t ⇒[ A ] u) (t' ⇒[ A' ] u') with eqdec-Ty A A' | eqdec-Tm t t' | eqdec-Tm u u'
... | inl idp | inl idp | inl idp = inl idp
... | inr A≠A' | _ | _ = inr λ {idp → A≠A' idp}
... | inl idp | inr t≠t' | _ = inr λ p → t≠t' (snd (fst (=⇒Ty p)))
... | inl idp | inl idp | inr u≠u' = inr λ p → u≠u' (snd (=⇒Ty p))
eqdec-Tm (v x) (v y) with eqdecℕ x y
... | inl idp = inl idp
... | inr x≠y = inr λ{idp → x≠y idp}
eqdec-Tm (v _) (coh _ _ _ _) = inr λ{()}
eqdec-Tm (coh _ _ _ _) (v _) = inr λ{()}
eqdec-Tm (coh Γ A Afull γ) (coh Γ' A' A'full γ') with eqdec-ps Γ Γ' | eqdec-Ty A A' | eqdec-Sub γ γ'
... | inl idp | inl idp | inl idp = inl (ap (λ X → coh Γ A X γ) (is-prop-has-all-paths (is-prop-full Γ A) Afull A'full))
... | inr Γ≠Γ' | _ | _ = inr λ {idp → Γ≠Γ' idp}
... | inl idp | inr A≠A' | _ = inr λ p → A≠A' (snd (fst (coh= p)))
... | inl idp | inl idp | inr γ≠γ' = inr λ p → γ≠γ' (snd (coh= p))
eqdec-Sub <> <> = inl idp
eqdec-Sub <> < _ , _ ↦ _ > = inr λ{()}
eqdec-Sub < _ , _ ↦ _ > <> = inr λ{()}
eqdec-Sub < γ , x ↦ t > < γ' , x' ↦ t' > with eqdec-Sub γ γ' | eqdecℕ x x' | eqdec-Tm t t'
... | inl idp | inl idp | inl idp = inl idp
... | inr γ≠γ' | _ | _ = inr λ {idp → γ≠γ' idp}
... | inl idp | inr x≠x' | _ = inr λ p → x≠x' (snd (fst (<>= p)))
... | inl idp | inl idp | inr t≠t' = inr λ p → t≠t' (snd (<>= p))
| 58.365297
| 295
| 0.46143
|
cb2b4ffb9806d2092d198145f331c371c1848110
| 538
|
agda
|
Agda
|
test/Fail/Issue1129b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1129b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1129b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
postulate
M : Set → Set
_>>=_ : ∀{A B : Set} → M A → (A → M B) → M B
infixr 1 bind
bind : _
bind = _>>=_
infix 0 id
id : ∀{A : Set} → A → A
id = λ x → x
syntax id x = act x
syntax bind ma (λ x → f) = x ← ma , f
swapM′ : ∀ {A B} → M (A × B) → M (B × A)
swapM′ mAB =
act
(a , b) ← mAB
, return $ b , a
-- Was:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error:
-- src/full/Agda/TypeChecking/Monad/Base.hs:1793
| 17.933333
| 63
| 0.509294
|
57bdbdb0f1ec97ea65754e1b80c1e52f1140e7e1
| 1,400
|
agda
|
Agda
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-sorted-list.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-sorted-list.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-sorted-list.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
{-# OPTIONS --allow-unsolved-metas #-}
open import bool
open import bool-thms2
open import eq
open import maybe
open import product
open import product-thms
open import bool-relations using (transitive ; total)
module z05-01-hc-sorted-list
(A : Set) -- type of elements
(_≤A_ : A → A → 𝔹) -- ordering function
(≤A-trans : transitive _≤A_) -- proof of transitivity of given ordering
(≤A-total : total _≤A_) -- proof of totality of given ordering
where
open import bool-relations _≤A_ hiding (transitive ; total)
open import minmax _≤A_ ≤A-trans ≤A-total
data slist : A → A → Set where
snil : ∀ {l u : A}
→ l ≤A u ≡ tt
→ slist l u
scons : ∀ {l u : A}
→ (d : A) -- value stored at head
→ slist l u -- elements to the right ≥ stored value
→ d ≤A l ≡ tt
→ slist (min d l) (max d u)
slist-insert : ∀ {l u : A}
→ (d : A) -- insert 'd'
→ slist l u -- into this 'bst'
→ d ≤A l ≡ tt
→ slist (min d l) (max d u) -- type might change
slist-insert d (snil l≤Au) d≤Al≡tt = scons d (snil l≤Au) d≤Al≡tt
slist-insert d (scons d' xs d'≤Al≡tt) d≤Al≡tt with keep (d ≤A d')
slist-insert d L@(scons d' xs d'≤Al≡tt) d≤Al≡tt | tt , p = scons d L d≤Al≡tt
slist-insert d L@(scons d' xs d'≤Al≡tt) d≤Al≡tt | ff , p = {!!}
| 32.55814
| 76
| 0.549286
|
228a7bd4c7426eeb1f8c2bb0d79dd633d99b761e
| 988
|
agda
|
Agda
|
Categories/Category/Instance/Simplex.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Instance/Simplex.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Instance/Simplex.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Instance.Simplex where
open import Level
open import Data.Product
open import Data.Fin
open import Data.Nat using (ℕ)
open import Function renaming (id to idF; _∘_ to _∙_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
Δ : Category 0ℓ 0ℓ 0ℓ
Δ = record
{ Obj = ℕ
; _⇒_ = λ m n → Σ (Fin m → Fin n) (λ f → _≤_ =[ f ]⇒ _≤_)
; _≈_ = λ { (f , mf) (g , mg) → ∀ x → f x ≡ g x }
; id = idF , idF
; _∘_ = λ { (f , mf) (g , mg) → f ∙ g , mf ∙ mg }
; assoc = λ _ → refl
; sym-assoc = λ _ → refl
; identityˡ = λ _ → refl
; identityʳ = λ _ → refl
; identity² = λ _ → refl
; equiv = record
{ refl = λ _ → refl
; sym = λ eq x → sym (eq x)
; trans = λ eq₁ eq₂ x → trans (eq₁ x) (eq₂ x)
}
; ∘-resp-≈ = λ {_ _ _ f g h i} eq₁ eq₂ x → trans (cong (λ t → proj₁ f t) (eq₂ x)) (eq₁ (proj₁ i x))
}
| 28.228571
| 102
| 0.546559
|
c5a84f1f78221fe46c40a31cc975e0cb82a51a33
| 4,893
|
agda
|
Agda
|
Cubical/Algebra/Monoid/Construct/Free.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Monoid/Construct/Free.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Monoid/Construct/Free.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.HLevels
module Cubical.Algebra.Monoid.Construct.Free {ℓ} (Aˢ : hSet ℓ) where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Path
open import Cubical.Algebra.Monoid
open import Cubical.Data.Empty.Polymorphic
open import Cubical.Data.Prod
open import Cubical.Relation.Binary.Reasoning.Equality
private
A = ⟨ Aˢ ⟩
isSetA = Aˢ .snd
------------------------------------------------------------------------
-- The direct free monoid type
data FreeM : Type ℓ where
inj : A → FreeM
_•_ : Op₂ FreeM
ε : FreeM
•-assoc : Associative _•_
ε-identityˡ : LeftIdentity ε _•_
ε-identityʳ : RightIdentity ε _•_
squash : isSet FreeM
ε-identity : Identity ε _•_
ε-identity = ε-identityˡ , ε-identityʳ
elim : ∀ {ℓ′} {B : FreeM → Type ℓ′} →
(∀ x → isSet (B x)) →
(∀ x → B (inj x)) →
(op : ∀ {x y} → B x → B y → B (x • y)) →
(e : B ε) →
(∀ {x y z} (a : B x) (b : B y) (c : B z) → PathP (λ i → B (•-assoc x y z i)) (op (op a b) c) (op a (op b c))) →
(∀ {x} (a : B x) → PathP (λ i → B (ε-identityˡ x i)) (op e a) a) →
(∀ {x} (a : B x) → PathP (λ i → B (ε-identityʳ x i)) (op a e) a) →
(x : FreeM) → B x
elim isSetB f op e assc idˡ idʳ (inj x) = f x
elim isSetB f op e assc idˡ idʳ (x • y) = op (elim isSetB f op e assc idˡ idʳ x) (elim isSetB f op e assc idˡ idʳ y)
elim isSetB f op e assc idˡ idʳ ε = e
elim isSetB f op e assc idˡ idʳ (•-assoc x y z i) = assc (elim isSetB f op e assc idˡ idʳ x)
(elim isSetB f op e assc idˡ idʳ y)
(elim isSetB f op e assc idˡ idʳ z) i
elim isSetB f op e assc idˡ idʳ (ε-identityˡ x i) = idˡ (elim isSetB f op e assc idˡ idʳ x) i
elim isSetB f op e assc idˡ idʳ (ε-identityʳ x i) = idʳ (elim isSetB f op e assc idˡ idʳ x) i
elim isSetB f op e assc idˡ idʳ (squash x y p q i j) =
isOfHLevel→isOfHLevelDep 2 isSetB
(elim isSetB f op e assc idˡ idʳ x) (elim isSetB f op e assc idˡ idʳ y)
(cong (elim isSetB f op e assc idˡ idʳ) p) (cong (elim isSetB f op e assc idˡ idʳ) q) (squash x y p q) i j
------------------------------------------------------------------------
-- The simplified free monoid type
-- Defined in Cubical.Data.List
open import Cubical.Data.List
open Structures isSetA public
------------------------------------------------------------------------
-- Proving the two types are equivalent
List→FreeM : List A → FreeM
List→FreeM [] = ε
List→FreeM (x ∷ xs) = inj x • List→FreeM xs
FreeM→List : FreeM → List A
FreeM→List = elim (λ _ → isOfHLevelList 0 isSetA) [_] _++_ [] ++-assoc ++-identityˡ ++-identityʳ
++-hom : Homomorphic₂ List→FreeM _++_ _•_
++-hom [] ys = sym (ε-identityˡ _)
++-hom (x ∷ xs) ys = cong (inj x •_) (++-hom xs ys) ∙ sym (•-assoc (inj x) (List→FreeM xs) (List→FreeM ys))
List→FreeM→List : retract List→FreeM FreeM→List
List→FreeM→List [] = refl
List→FreeM→List (x ∷ xs) = cong (x ∷_) (List→FreeM→List xs)
FreeM→List→FreeM : section List→FreeM FreeM→List
FreeM→List→FreeM = elim (λ _ → isSet→isGroupoid squash _ _) (λ _ → ε-identityʳ _) sectionOp refl
(λ _ _ _ → isOfHLevelPathP' 0 (squash _ _) _ _ .fst)
(λ _ → isOfHLevelPathP' 0 (squash _ _) _ _ .fst)
(λ _ → isOfHLevelPathP' 0 (squash _ _) _ _ .fst)
where
sectionOp : ∀ {x y} → List→FreeM (FreeM→List x) ≡ x →
List→FreeM (FreeM→List y) ≡ y →
List→FreeM (FreeM→List (x • y)) ≡ (x • y)
sectionOp {x} {y} p q =
List→FreeM (FreeM→List (x • y)) ≡⟨⟩
List→FreeM (FreeM→List x ++ FreeM→List y) ≡⟨ ++-hom (FreeM→List x) (FreeM→List y) ⟩
List→FreeM (FreeM→List x) • List→FreeM (FreeM→List y) ≡⟨ cong₂ _•_ p q ⟩
x • y ∎
List≃FreeM : List A ≃ FreeM
List≃FreeM = isoToEquiv (iso List→FreeM FreeM→List FreeM→List→FreeM List→FreeM→List)
List≡FreeM : List A ≡ FreeM
List≡FreeM = ua List≃FreeM
------------------------------------------------------------------------
-- Monoid structure
FreeM-isMonoid : IsMonoid FreeM _•_ ε
FreeM-isMonoid = record
{ isSemigroup = record
{ isMagma = record { is-set = squash }
; assoc = •-assoc
}
; identity = ε-identity
}
FreeMonoid : Monoid ℓ
FreeMonoid = record { isMonoid = FreeM-isMonoid }
EquivFreeM : MonoidEquiv ListMonoid FreeMonoid
EquivFreeM = record
{ eq = List≃FreeM
; isHom = record
{ preservesOp = ++-hom
; preservesId = refl
}
}
FreeMonoid≡ : ListMonoid ≡ FreeMonoid
FreeMonoid≡ = uaMonoid EquivFreeM
| 35.456522
| 119
| 0.557736
|
c7fdd710454f970c2a86f1ddb361aff68a8f3f43
| 320
|
agda
|
Agda
|
LC/Base.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | 2
|
2020-08-25T07:34:40.000Z
|
2020-08-25T14:05:01.000Z
|
LC/Base.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
LC/Base.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
module LC.Base where
open import Data.Nat
--------------------------------------------------------------------------------
-- de Bruijn indexed lambda calculus
infix 5 ƛ_
infixl 7 _∙_
infix 9 var_
data Term : Set where
var_ : (x : ℕ) → Term
ƛ_ : (M : Term) → Term
_∙_ : (M : Term) → (N : Term) → Term
| 20
| 80
| 0.446875
|
06d6a32d14f432e7755593a2e2da4b2dbe2090a7
| 77
|
agda
|
Agda
|
Type/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Type/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Type/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Type.Proofs where
open import Logic
import Lvl
open import Type
| 12.833333
| 24
| 0.766234
|
58d75b6bec6ef57052224f17c24f5ad4b02de611
| 293
|
agda
|
Agda
|
Cubical/Algebra.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra where
open import Cubical.Algebra.Base public
open import Cubical.Algebra.Definitions public
open import Cubical.Algebra.Structures public
open import Cubical.Algebra.Bundles public
open import Cubical.Classes public
| 29.3
| 50
| 0.812287
|
0b558b53e194f7b89ed4453f44b44973a8cb2333
| 1,953
|
agda
|
Agda
|
Mixfix/Fixity.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
Mixfix/Fixity.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
Mixfix/Fixity.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Fixity and associativity
------------------------------------------------------------------------
module Mixfix.Fixity where
open import Data.Fin using (Fin; zero; suc; #_)
open import Data.Fin.Properties using (eq?)
open import Function.LeftInverse
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as Eq
data Associativity : Set where
left : Associativity
right : Associativity
non : Associativity
-- A combination of fixity and associativity. Only infix operators
-- have associativity.
-- Note that infix is a reserved word.
data Fixity : Set where
prefx : Fixity
infx : (assoc : Associativity) → Fixity
postfx : Fixity
closed : Fixity
Fixity-is-finite : LeftInverse (Eq.setoid Fixity) (Eq.setoid (Fin 6))
Fixity-is-finite = record
{ from = Eq.→-to-⟶ from
; to = Eq.→-to-⟶ to
; left-inverse-of = left-inverse-of
}
where
to : Fixity → Fin 6
to prefx = # 0
to (infx left) = # 1
to (infx right) = # 2
to (infx non) = # 3
to postfx = # 4
to closed = # 5
from : Fin 6 → Fixity
from zero = prefx
from (suc zero) = infx left
from (suc (suc zero)) = infx right
from (suc (suc (suc zero))) = infx non
from (suc (suc (suc (suc zero)))) = postfx
from (suc (suc (suc (suc (suc zero))))) = closed
from (suc (suc (suc (suc (suc (suc ()))))))
left-inverse-of : Eq.→-to-⟶ from LeftInverseOf Eq.→-to-⟶ to
left-inverse-of prefx = refl
left-inverse-of (infx left) = refl
left-inverse-of (infx right) = refl
left-inverse-of (infx non) = refl
left-inverse-of postfx = refl
left-inverse-of closed = refl
_≟_ : Decidable (_≡_ {A = Fixity})
_≟_ = eq? injection
where open LeftInverse Fixity-is-finite
| 30.515625
| 72
| 0.554531
|
3d2ceb9531aa957a9c29133fc1c2fa26b5c4e398
| 1,963
|
agda
|
Agda
|
Mask.agda
|
pigworker/InteriorDesign
|
454cdd18f56db0b0d1643a1fcf36951b5ece395c
|
[
"BSD-3-Clause"
] | 6
|
2018-06-18T15:25:39.000Z
|
2018-07-31T02:00:13.000Z
|
Mask.agda
|
pigworker/InteriorDesign
|
454cdd18f56db0b0d1643a1fcf36951b5ece395c
|
[
"BSD-3-Clause"
] | null | null | null |
Mask.agda
|
pigworker/InteriorDesign
|
454cdd18f56db0b0d1643a1fcf36951b5ece395c
|
[
"BSD-3-Clause"
] | null | null | null |
module Mask where
open import Basics
open import Ix
open import All
open import Cutting
open import Splitting
open import Perm
open import Interior
open import Recutter
module MASK {I}(C : I |> I) where
open _|>_
open INTERIOR C
open RECUTTER C
module CHOP {P}(pc : CutKit P)(rec : Recutter) where
glue : (is : List I) -> (d : Subs is) ->
All (Interior P) (subCollect is d) -> All (Interior P) is
glue [] <> <> = <>
glue (i ,- is) (inl <> , ds) (p , ps) = p , glue is ds ps
glue (i ,- is) (inr c , ds) ps with isRiffle (slrs (inners C c) (subCollect is ds)) ps
glue (i ,- is) (inr c , ds) .(riffle (slrs (inners C c) (subCollect is ds)) lp rp)
| mkRiffle lp rp = < c 8>< lp > , glue is ds rp
chop : (i : I)(c c' : Cuts C i) ->
All (Interior P) (inners C c) -> All (Interior P) (inners C c')
chops : (is : List I) -> All (Interior P) is -> (d : Subs is) ->
All (Interior P) (subCollect is d)
chop i c c' ps with rec i c c'
... | d , d' , m with chops (inners C c) ps d
... | qs = glue (inners C c') d' (permute m qs)
chops [] <> <> = <>
chops (i ,- is) (p , ps) (inl <> , ds) = p , chops is ps ds
chops (i ,- is) (tile p , ps) (inr c' , ds) =
cat (inners C c') (subCollect is ds) (all (\ _ -> tile) _ (pc i c' p)) (chops is ps ds)
chops (i ,- is) (< c 8>< ps' > , ps) (inr c' , ds) =
cat (inners C c') (subCollect is ds) (chop i c c' ps') (chops is ps ds)
mask : forall {O Q} -> [ O -:> Interior P -:> Interior Q ]
-> [ Interior O -:> Interior P -:> Interior Q ]
mask {O}{Q} f = ifold f help where
help : [ Cutting C (Interior P -:> Interior Q) -:> Interior P -:> Interior Q ]
help i (c' 8>< fs) (tile p) with pc i c' p
... | ps = < c' 8>< allAp (inners C c') fs (all (\ _ -> tile) _ ps) >
help i (c' 8>< fs) < c 8>< ps > = < c' 8>< allAp (inners C c') fs (chop i c c' ps) >
| 40.061224
| 93
| 0.516556
|
cbe32c4ec982b9fc110d1ff852861ac63600c976
| 984
|
agda
|
Agda
|
src/Magma/Definitions.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | 2
|
2021-08-15T06:16:13.000Z
|
2021-08-17T09:14:03.000Z
|
src/Magma/Definitions.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | 2
|
2021-10-04T05:30:30.000Z
|
2021-10-09T08:24:56.000Z
|
src/Magma/Definitions.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Magma.Definitions
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality
where
open import Algebra.Core
open import Data.Product
Alternativeˡ : Op₂ A → Set _
Alternativeˡ _∙_ = ∀ x y → ((x ∙ x) ∙ y) ≈ (x ∙ (y ∙ y))
Alternativeʳ : Op₂ A → Set _
Alternativeʳ _∙_ = ∀ x y → (x ∙ (y ∙ y)) ≈ ((x ∙ y) ∙ y)
Alternative : Op₂ A → Set _
Alternative _∙_ = (Alternativeˡ _∙_ ) × ( Alternativeʳ _∙_)
Flexible : Op₂ A → Set _
Flexible _∙_ = ∀ x y → ((x ∙ y) ∙ x) ≈ (x ∙ (y ∙ x))
Medial : Op₂ A → Set _
Medial _∙_ = ∀ x y u z → ((x ∙ y) ∙ (u ∙ z)) ≈ ((x ∙ u) ∙ (y ∙ z))
LeftSemimedial : Op₂ A → Set _
LeftSemimedial _∙_ = ∀ x y z → ((x ∙ x) ∙ (y ∙ z)) ≈ ((x ∙ y) ∙ (x ∙ z))
RightSemimedial : Op₂ A → Set _
RightSemimedial _∙_ = ∀ x y z → ((y ∙ z) ∙ (x ∙ x)) ≈ ((y ∙ x) ∙ (z ∙ x))
Semimedial : Op₂ A → Set _
Semimedial _∙_ = (LeftSemimedial _∙_) × (RightSemimedial _∙_)
| 27.333333
| 73
| 0.550813
|
2e8dbffc63d97204273bc14515d7c5f011256cef
| 205
|
agda
|
Agda
|
test/fail/ATPBadConjecture2.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
test/fail/ATPBadConjecture2.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | null | null | null |
test/fail/ATPBadConjecture2.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- An ATP conjecture must be used with postulates.
-- This error is detected by TypeChecking.Rules.Decl.
module ATPBadConjecture2 where
data Bool : Set where
false true : Bool
{-# ATP prove Bool #-}
| 18.636364
| 53
| 0.731707
|
22c7cf0530dcafca5c006ae3cbb6e866ef07a575
| 746
|
agda
|
Agda
|
test/Succeed/Issue2484-7.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2484-7.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2484-7.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --sized-types #-}
module _ (_ : Set) where
open import Agda.Builtin.Size
postulate
I : Set
record ∃ (B : I → Set) : Set where
constructor _,_
field
proj₁ : I
proj₂ : B proj₁
module M (_ : Set₁) where
mutual
data P (i : Size) (x y : I) : Set where
⟨_⟩ : ∃ (Q i x) → P i x y
record Q (i : Size) (x y : I) : Set where
coinductive
field
force : {j : Size< i} → P j x y
open M Set
postulate
map : (B : I → Set) → (∀ x → B x → B x) → ∃ B → ∃ B
lemma : ∀ x y i → Q i x y → Q i x y
p : ∀ x i → P i x x
q′ : ∀ x i → ∃ λ y → Q i x y
q : ∀ x i → Q i x x
p x i = ⟨ map _ (λ y → lemma x y _) (q′ x _) ⟩
Q.force (q x i) {j} = p _ _
q′ x i = x , q x i
| 18.195122
| 60
| 0.458445
|
1a922d95e2d0425f8c13260d0f95f1d062048152
| 1,692
|
agda
|
Agda
|
Cubical/Foundations/Surjection.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Surjection.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Surjection.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Surjection where
open import Cubical.Core.Everything
open import Cubical.Data.Prod
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Embedding
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation as PropTrunc
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
f : A → B
isSurjection : (A → B) → Type _
isSurjection f = ∀ b → ∥ fiber f b ∥
section→isSurjection : {g : B → A} → section f g → isSurjection f
section→isSurjection {g = g} s b = ∣ g b , s b ∣
isSurjectionIsProp : isProp (isSurjection f)
isSurjectionIsProp = isPropPi λ _ → squash
isEquiv→isSurjection : isEquiv f → isSurjection f
isEquiv→isSurjection e b = ∣ fst (equiv-proof e b) ∣
isEquiv→isEmbedding×isSurjection : isEquiv f → isEmbedding f × isSurjection f
isEquiv→isEmbedding×isSurjection e = isEquiv→isEmbedding e , isEquiv→isSurjection e
isEmbedding×isSurjection→isEquiv : isEmbedding f × isSurjection f → isEquiv f
equiv-proof (isEmbedding×isSurjection→isEquiv {f = f} (emb , sur)) b =
inhProp→isContr (PropTrunc.rec fib' (λ x → x) fib) fib'
where
hpf : hasPropFibers f
hpf = isEmbedding→hasPropFibers emb
fib : ∥ fiber f b ∥
fib = sur b
fib' : isProp (fiber f b)
fib' = hpf b
isEquiv≃isEmbedding×isSurjection : isEquiv f ≃ isEmbedding f × isSurjection f
isEquiv≃isEmbedding×isSurjection = isoToEquiv (iso
isEquiv→isEmbedding×isSurjection
isEmbedding×isSurjection→isEquiv
(λ _ → isOfHLevelProd 1 isEmbeddingIsProp isSurjectionIsProp _ _)
(λ _ → isPropIsEquiv _ _ _))
| 31.333333
| 83
| 0.741726
|
29859de970e59b793aefa26560a53ca0e2056297
| 2,591
|
agda
|
Agda
|
test/interaction/Issue1353.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue1353.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue1353.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --show-implicit #-}
{-# OPTIONS -v tc.interaction:20 #-}
------------------------------------------------------------------------
-- Library
id : ∀ {X : Set} → X → X
id x = x
infixr 9 _∘_
_∘_ : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
record Σ (X : Set) (Y : X → Set) : Set where
constructor _,_
field
proj₁ : X
proj₂ : Y proj₁
open Σ public
syntax Σ X (λ x → Y) = Σ[ x ∈ X ] Y
data _≡_ {X : Set} (x : X) : X → Set where
refl : x ≡ x
subst : ∀ {A} (P : A → Set) {x y} → x ≡ y → P x → P y
subst P refl p = p
record _▷_ (I O : Set) : Set₁ where
constructor _◃_/_
field
Parameter : (o : O) → Set
Arity : ∀ {o} (p : Parameter o) → Set
input : ∀ {o} (p : Parameter o) (a : Arity p) → I
open _▷_ public
Pow : Set → Set₁
Pow X = X → Set
infix 4 _⊆_
_⊆_ : ∀ {X} → Pow X → Pow X → Set
P ⊆ Q = ∀ {x} → P x → Q x
⟦_⟧ : ∀ {I O} → I ▷ O → (Pow I → Pow O)
⟦ P ◃ A / s ⟧ X o = Σ[ p ∈ P o ] ((a : A p) → X (s p a))
Alg : ∀ {O} → O ▷ O → Pow O → Set
Alg Σ X = ⟦ Σ ⟧ X ⊆ X
module _ {I₁ I₂ O₁ O₂} where
record ContainerMorphism
(C₁ : I₁ ▷ O₁) (C₂ : I₂ ▷ O₂)
(f : I₁ → I₂) (g : O₁ → O₂)
(_∼_ : I₂ → I₂ → Set) (_≈_ : Set → Set → Set)
(_·_ : ∀ {A B} → A ≈ B → A → B) :
Set where
field
parameter : Parameter C₁ ⊆ Parameter C₂ ∘ g
arity : ∀ {o} {p₁ : Parameter C₁ o} →
Arity C₂ (parameter p₁) ≈ Arity C₁ p₁
coherent : ∀ {o} {p₁ : Parameter C₁ o} {a₂ : Arity C₂ (parameter p₁)} →
f (input C₁ p₁ (arity · a₂)) ∼ input C₂ (parameter p₁) a₂
open ContainerMorphism public
_⇒[_/_]_ : I₁ ▷ O₁ → (I₁ → I₂) → (O₁ → O₂) →
I₂ ▷ O₂ → Set
C₁ ⇒[ f / g ] C₂ = ContainerMorphism C₁ C₂ f g _≡_ (λ R₂ R₁ → R₂ → R₁)
(λ f x → f x)
⟪_⟫ : ∀ {I} {C₁ C₂ : I ▷ I} →
C₁ ⇒[ id / id ] C₂ → (X : Pow I) → ⟦ C₁ ⟧ X ⊆ ⟦ C₂ ⟧ X
⟪ m ⟫ X (c , k) = parameter m c , λ a₂ →
subst X (coherent m) (k (arity m a₂))
------------------------------------------------------------------------
-- Example
weaken : ∀ {I} {Ω : I ▷ I} {Ψ : I ▷ I} {X : Pow I} →
Alg Ψ X → Ω ⇒[ id / id ] Ψ → Alg Ω X
weaken {I}{Ω}{Ψ}{X = X} φ m {i} (p , k) = φ {x = i} (⟪ m ⟫ {!X!} (p , k))
weaken2 : ∀ {I} {Ω : I ▷ I} {Ψ : I ▷ I} {X : Pow I} →
Alg Ψ X → Ω ⇒[ id / id ] Ψ → Alg Ω X
weaken2 {I}{Ω}{Ψ}{X = X} φ m {i} (p , k) = φ {i} (⟪ m ⟫ X (p , k))
| 27.56383
| 79
| 0.394056
|
0648cf18a99799e0f8dca98d435725eb9c894067
| 363
|
agda
|
Agda
|
test/fail/TrustMe.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/fail/TrustMe.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | null | null | null |
test/fail/TrustMe.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module TrustMe where
open import Common.Equality
primitive
primTrustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y
postulate
A : Set
x y : A
eq : x ≡ y
eq = primTrustMe
sym : ∀ {a} {A : Set a} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
does-not-evaluate-to-refl : sym (sym eq) ≡ eq
does-not-evaluate-to-refl = refl
| 16.5
| 51
| 0.595041
|
419685bffe03440cc43656f5dda72e44ea1a6c52
| 7,822
|
agda
|
Agda
|
Cubical/Algebra/CommAlgebra/Base.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommAlgebra/Base.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommAlgebra/Base.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.Algebra.CommAlgebra.Base 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.Equiv.HalfAdjoint
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Algebra.Semigroup hiding (⟨_⟩)
open import Cubical.Algebra.Monoid hiding (⟨_⟩)
open import Cubical.Algebra.CommRing renaming (⟨_⟩ to ⟨_⟩r)
open import Cubical.Algebra.Ring hiding (⟨_⟩)
open import Cubical.Algebra.Algebra hiding (⟨_⟩)
private
variable
ℓ ℓ′ : Level
record IsCommAlgebra (R : CommRing {ℓ}) {A : Type ℓ}
(0a : A) (1a : A)
(_+_ : A → A → A) (_·_ : A → A → A) (-_ : A → A)
(_⋆_ : ⟨ R ⟩r → A → A) : Type ℓ where
constructor iscommalgebra
field
isAlgebra : IsAlgebra (CommRing→Ring R) 0a 1a _+_ _·_ -_ _⋆_
·-comm : (x y : A) → x · y ≡ y · x
open IsAlgebra isAlgebra public
record CommAlgebra (R : CommRing {ℓ}) : Type (ℓ-suc ℓ) where
constructor commalgebra
field
Carrier : Type ℓ
0a : Carrier
1a : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
_⋆_ : ⟨ R ⟩r → Carrier → Carrier
isCommAlgebra : IsCommAlgebra R 0a 1a _+_ _·_ -_ _⋆_
open IsCommAlgebra isCommAlgebra public
module _ {R : CommRing {ℓ}} where
open CommRing R using (1r) renaming (_+_ to _+r_; _·_ to _·s_)
⟨_⟩ : CommAlgebra R → Type ℓ
⟨_⟩ = CommAlgebra.Carrier
CommAlgebra→Algebra : (A : CommAlgebra R) → Algebra (CommRing→Ring R)
CommAlgebra→Algebra (commalgebra Carrier _ _ _ _ _ _ (iscommalgebra isAlgebra ·-comm)) =
algebra Carrier _ _ _ _ _ _ isAlgebra
CommAlgebra→CommRing : (A : CommAlgebra R) → CommRing {ℓ}
CommAlgebra→CommRing (commalgebra Carrier _ _ _ _ _ _
(iscommalgebra isAlgebra ·-comm)) =
commring Carrier _ _ _ _ _ (iscommring (IsAlgebra.isRing isAlgebra) ·-comm)
CommAlgebraEquiv : (R S : CommAlgebra R) → Type ℓ
CommAlgebraEquiv R S = AlgebraEquiv (CommAlgebra→Algebra R) (CommAlgebra→Algebra S)
makeIsCommAlgebra : {A : Type ℓ} {0a 1a : A}
{_+_ _·_ : A → A → A} { -_ : A → A} {_⋆_ : ⟨ R ⟩r → A → A}
(isSet-A : isSet A)
(+-assoc : (x y z : A) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : A) → x + 0a ≡ x)
(+-rinv : (x : A) → x + (- x) ≡ 0a)
(+-comm : (x y : A) → x + y ≡ y + x)
(·-assoc : (x y z : A) → x · (y · z) ≡ (x · y) · z)
(·-lid : (x : A) → 1a · x ≡ x)
(·-ldist-+ : (x y z : A) → (x + y) · z ≡ (x · z) + (y · z))
(·-comm : (x y : A) → x · y ≡ y · x)
(⋆-assoc : (r s : ⟨ R ⟩r) (x : A) → (r ·s s) ⋆ x ≡ r ⋆ (s ⋆ x))
(⋆-ldist : (r s : ⟨ R ⟩r) (x : A) → (r +r s) ⋆ x ≡ (r ⋆ x) + (s ⋆ x))
(⋆-rdist : (r : ⟨ R ⟩r) (x y : A) → r ⋆ (x + y) ≡ (r ⋆ x) + (r ⋆ y))
(⋆-lid : (x : A) → 1r ⋆ x ≡ x)
(⋆-lassoc : (r : ⟨ R ⟩r) (x y : A) → (r ⋆ x) · y ≡ r ⋆ (x · y))
→ IsCommAlgebra R 0a 1a _+_ _·_ -_ _⋆_
makeIsCommAlgebra {A} {0a} {1a} {_+_} {_·_} { -_} {_⋆_} isSet-A
+-assoc +-rid +-rinv +-comm
·-assoc ·-lid ·-ldist-+ ·-comm
⋆-assoc ⋆-ldist ⋆-rdist ⋆-lid ⋆-lassoc
= iscommalgebra
(makeIsAlgebra
isSet-A
+-assoc +-rid +-rinv +-comm
·-assoc
(λ x → x · 1a ≡⟨ ·-comm _ _ ⟩ 1a · x ≡⟨ ·-lid _ ⟩ x ∎)
·-lid
(λ x y z → x · (y + z) ≡⟨ ·-comm _ _ ⟩
(y + z) · x ≡⟨ ·-ldist-+ _ _ _ ⟩
(y · x) + (z · x) ≡⟨ cong (λ u → (y · x) + u) (·-comm _ _) ⟩
(y · x) + (x · z) ≡⟨ cong (λ u → u + (x · z)) (·-comm _ _) ⟩
(x · y) + (x · z) ∎)
·-ldist-+
⋆-assoc
⋆-ldist
⋆-rdist
⋆-lid
⋆-lassoc
λ r x y → r ⋆ (x · y) ≡⟨ cong (λ u → r ⋆ u) (·-comm _ _) ⟩
r ⋆ (y · x) ≡⟨ sym (⋆-lassoc _ _ _) ⟩
(r ⋆ y) · x ≡⟨ ·-comm _ _ ⟩
x · (r ⋆ y) ∎)
·-comm
module CommAlgebraΣTheory (R : CommRing {ℓ}) where
open AlgebraΣTheory (CommRing→Ring R)
CommAlgebraAxioms : (A : Type ℓ) (s : RawAlgebraStructure A) → Type ℓ
CommAlgebraAxioms A (_+_ , _·_ , 1a , _⋆_) = AlgebraAxioms A (_+_ , _·_ , 1a , _⋆_)
× ((x y : A) → x · y ≡ y · x)
CommAlgebraStructure : Type ℓ → Type ℓ
CommAlgebraStructure = AxiomsStructure RawAlgebraStructure CommAlgebraAxioms
CommAlgebraΣ : Type (ℓ-suc ℓ)
CommAlgebraΣ = TypeWithStr ℓ CommAlgebraStructure
CommAlgebraEquivStr : StrEquiv CommAlgebraStructure ℓ
CommAlgebraEquivStr = AxiomsEquivStr RawAlgebraEquivStr CommAlgebraAxioms
isPropCommAlgebraAxioms : (A : Type ℓ) (s : RawAlgebraStructure A)
→ isProp (CommAlgebraAxioms A s)
isPropCommAlgebraAxioms A (_+_ , _·_ , 1a , _⋆_) =
isPropΣ (isPropAlgebraAxioms A (_+_ , _·_ , 1a , _⋆_))
λ isAlgebra → isPropΠ2 λ _ _ → (isSetAlgebraΣ (A , _ , isAlgebra)) _ _
CommAlgebra→CommAlgebraΣ : CommAlgebra R → CommAlgebraΣ
CommAlgebra→CommAlgebraΣ (commalgebra _ _ _ _ _ _ _ (iscommalgebra G C)) =
_ , _ , Algebra→AlgebraΣ (algebra _ _ _ _ _ _ _ G) .snd .snd , C
CommAlgebraΣ→CommAlgebra : CommAlgebraΣ → CommAlgebra R
CommAlgebraΣ→CommAlgebra (_ , _ , G , C) =
commalgebra _ _ _ _ _ _ _ (iscommalgebra (AlgebraΣ→Algebra (_ , _ , G) .Algebra.isAlgebra) C)
CommAlgebraIsoCommAlgebraΣ : Iso (CommAlgebra R) CommAlgebraΣ
CommAlgebraIsoCommAlgebraΣ =
iso CommAlgebra→CommAlgebraΣ CommAlgebraΣ→CommAlgebra (λ _ → refl) helper
where
open import Cubical.Algebra.Group.Base hiding (⟨_⟩)
open CommAlgebra
open IsAlgebra
open IsCommAlgebra
algebra-helper : retract Algebra→AlgebraΣ AlgebraΣ→Algebra
algebra-helper = Iso.leftInv AlgebraIsoAlgebraΣ
helper : retract CommAlgebra→CommAlgebraΣ CommAlgebraΣ→CommAlgebra
Carrier (helper a i) = Carrier a
0a (helper a i) = 0a a
1a (helper a i) = 1a a
_+_ (helper a i) = _+_ a
_·_ (helper a i) = _·_ a
- helper a i = -_ a
_⋆_ (helper a i) = _⋆_ a
isAlgebra (isCommAlgebra (helper a i)) =
Algebra.isAlgebra (algebra-helper (algebra _ _ _ _ _ _ _ (isAlgebra (isCommAlgebra a))) i)
·-comm (isCommAlgebra (helper a i)) = ·-comm (isCommAlgebra a)
commAlgebraUnivalentStr : UnivalentStr CommAlgebraStructure CommAlgebraEquivStr
commAlgebraUnivalentStr = axiomsUnivalentStr _ isPropCommAlgebraAxioms rawAlgebraUnivalentStr
CommAlgebraΣPath : (A B : CommAlgebraΣ) → (A ≃[ CommAlgebraEquivStr ] B) ≃ (A ≡ B)
CommAlgebraΣPath = SIP commAlgebraUnivalentStr
CommAlgebraEquivΣ : (A B : CommAlgebra R) → Type ℓ
CommAlgebraEquivΣ A B = CommAlgebra→CommAlgebraΣ A ≃[ CommAlgebraEquivStr ] CommAlgebra→CommAlgebraΣ B
CommAlgebraPath : (A B : CommAlgebra R) → (CommAlgebraEquiv A B) ≃ (A ≡ B)
CommAlgebraPath A B =
CommAlgebraEquiv A B ≃⟨ isoToEquiv AlgebraEquivΣPath ⟩
CommAlgebraEquivΣ A B ≃⟨ CommAlgebraΣPath _ _ ⟩
CommAlgebra→CommAlgebraΣ A ≡ CommAlgebra→CommAlgebraΣ B
≃⟨ isoToEquiv (invIso (congIso CommAlgebraIsoCommAlgebraΣ)) ⟩
A ≡ B ■
CommAlgebraPath : (R : CommRing {ℓ}) → (A B : CommAlgebra R) → (CommAlgebraEquiv A B) ≃ (A ≡ B)
CommAlgebraPath = CommAlgebraΣTheory.CommAlgebraPath
| 41.168421
| 104
| 0.558041
|
2fbf335265cef3f7c847844831182196abf73436
| 452
|
agda
|
Agda
|
test/Fail/Issue2369.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2369.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2369.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-12-30 test case for #2369
-- {-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v scope.import:20 #-}
module Issue2369 where
import Issue2369.OpenIP
-- Error is:
-- Module cannot be imported since it has open interaction points
-- (consider adding {-# OPTIONS --allow-unsolved-metas #-} to this
-- module)
-- when scope checking the declaration
-- import Issue2369.OpenIP
-- Error could be better, or this could just work.
| 23.789474
| 66
| 0.701327
|
507634655e1824a8990cc242fe9c7caf11f12c84
| 1,391
|
agda
|
Agda
|
test/Succeed/Issue3518.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3518.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3518.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
record ∃ {A : Set} (B : A → Set) : Set where
field
fst : A
snd : B fst
data ⊥ : Set where
infix 3 ¬_
¬_ : Set → Set
¬ P = P → ⊥
infixr 1 _⊎_
data _⊎_ (A B : Set) : Set where
inj₁ : A → A ⊎ B
inj₂ : B → A ⊎ B
⊎-map : ∀ {A₁ A₂ B₁ B₂ : Set} →
(A₁ → A₂) → (B₁ → B₂) → A₁ ⊎ B₁ → A₂ ⊎ B₂
⊎-map f g (inj₁ x) = inj₁ (f x)
⊎-map f g (inj₂ y) = inj₂ (g y)
record Raw-monad (M : Set → Set) : Set₁ where
constructor mk
infixl 5 _>>=_
field
return : ∀ {A} → A → M A
_>>=_ : ∀ {A B} → M A → (A → M B) → M B
map : ∀ {A B} → (A → B) → M A → M B
map f x = x >>= λ x → return (f x)
open Raw-monad ⦃ … ⦄
-- Id is included in order to make run overloaded.
record Id (A : Set) : Set where
field
run : A
open Id
infix 3 ¬¬_
record ¬¬_ (A : Set) : Set where
field
run : ¬ ¬ A
open ¬¬_
instance
double-negation-monad : Raw-monad ¬¬_
run (Raw-monad.return double-negation-monad x) = λ f → f x
run (Raw-monad._>>=_ double-negation-monad x f) =
λ ¬b → run x (λ a → run (f a) ¬b)
excluded-middle : {A : Set} → ¬¬ (A ⊎ ¬ A)
run excluded-middle ¬[a⊎¬a] = ¬[a⊎¬a] (inj₂ λ a → ¬[a⊎¬a] (inj₁ a))
postulate
A : Set
P : Set → Set
_⇓_ : P A → A → Set
_⇑ : P A → Set
¬⇓→⇑ : {x : P A} → ¬ (∃ λ y → x ⇓ y) → x ⇑
¬¬[⇓⊎⇑] : (x : P A) → ¬ ¬ ((∃ λ y → x ⇓ y) ⊎ x ⇑)
¬¬[⇓⊎⇑] x = run (map (⊎-map (λ x → x) ¬⇓→⇑) excluded-middle)
| 19.054795
| 67
| 0.472322
|
570538491bd225e206048cb645be0f39e33f0fcf
| 701
|
agda
|
Agda
|
Cubical/Experiments/Everything.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/Everything.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/Everything.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
-- Export only the experiments that are expected to compile (without
-- any holes)
module Cubical.Experiments.Everything where
open import Cubical.Experiments.Brunerie public
open import Cubical.Experiments.EscardoSIP public
open import Cubical.Experiments.Generic public
open import Cubical.Experiments.NatMinusTwo
open import Cubical.Experiments.IsoInt
open import Cubical.Experiments.HAEquivInt
open import Cubical.Experiments.Problem
open import Cubical.Experiments.FunExtFromUA public
open import Cubical.Experiments.HoTT-UF
open import Cubical.Experiments.ZCohomologyOld.Base
open import Cubical.Experiments.ZCohomologyOld.KcompPrelims
open import Cubical.Experiments.ZCohomologyOld.Properties
| 41.235294
| 68
| 0.865906
|
29f8e9810eab9bc3dcb59a5353cd74d2f7e5e733
| 1,271
|
agda
|
Agda
|
Univalence/Circuits.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/Circuits.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/Circuits.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module Circuits where
open import PiLevel0
using (U; ZERO; ONE; PLUS; TIMES; BOOL; BOOL²;
_⟷_;
unite₊; uniti₊; swap₊; assocl₊; assocr₊;
unite⋆; uniti⋆; swap⋆; assocl⋆; assocr⋆;
absorbr; absorbl; factorzr; factorzl; dist; factor;
id⟷; _◎_; _⊕_; _⊗_;
_⟷⟨_⟩_; _□;
NOT; CNOT; TOFFOLI)
------------------------------------------------------------------------------
SWAP : BOOL² ⟷ BOOL²
SWAP = swap⋆
CONTROL : {t : U} → (t ⟷ t) → (TIMES BOOL t ⟷ TIMES BOOL t)
CONTROL {t} f = TIMES BOOL t
⟷⟨ id⟷ ⟩
TIMES (PLUS x y) t
⟷⟨ dist ⟩
PLUS (TIMES x t) (TIMES y t)
⟷⟨ id⟷ ⊕ (id⟷ ⊗ f) ⟩
PLUS (TIMES x t) (TIMES y t)
⟷⟨ factor ⟩
TIMES (PLUS x y) t
⟷⟨ id⟷ ⟩
TIMES BOOL t □
where x = ONE; y = ONE
FREDKIN : TIMES BOOL BOOL² ⟷ TIMES BOOL BOOL²
FREDKIN = CONTROL SWAP
------------------------------------------------------------------------------
-- Fig. 4 in http://arxiv.org/pdf/1110.2574v2.pdf
-- (e) cycles
-- (c) reversible truth table
------------------------------------------------------------------------------
| 27.630435
| 78
| 0.387097
|
1d68ce359e50bcedfea29569464fb859e9a223e5
| 4,758
|
agda
|
Agda
|
slides/ClosedTheory2.agda
|
larrytheliquid/generic-elim
|
832383d7adf37aa2364213fb0aeb67e9f61a248f
|
[
"MIT"
] | 11
|
2015-06-02T14:05:20.000Z
|
2021-09-09T08:46:42.000Z
|
slides/ClosedTheory2.agda
|
larrytheliquid/generic-elim
|
832383d7adf37aa2364213fb0aeb67e9f61a248f
|
[
"MIT"
] | null | null | null |
slides/ClosedTheory2.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.Empty
open import Data.Unit
open import Data.Bool hiding ( T )
open import Data.Product hiding ( curry ; uncurry )
open import Data.Nat
open import Data.String
open import Relation.Binary.PropositionalEquality using ( refl ; _≢_ ; _≡_ )
open import Function
module ClosedTheory2 where
----------------------------------------------------------------------
data Tel : Set₁ where
Emp : Tel
Ext : (A : Set) (B : A → Tel) → Tel
Scope : Tel → Set
Scope Emp = ⊤
Scope (Ext A B) = Σ A λ a → Scope (B a)
----------------------------------------------------------------------
UncurriedScope : (T : Tel) (X : Scope T → Set) → Set
UncurriedScope T X = (xs : Scope T) → X xs
CurriedScope : (T : Tel) (X : Scope T → Set) → Set
CurriedScope Emp X = X tt
CurriedScope (Ext A B) X = (a : A) → CurriedScope (B a) (λ b → X (a , b))
curryScope : (T : Tel) (X : Scope T → Set) → UncurriedScope T X → CurriedScope T X
curryScope Emp X f = f tt
curryScope (Ext A B) X f a = curryScope (B a) (λ b → X (a , b)) (λ b → f (a , b))
----------------------------------------------------------------------
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)
data μ {I : Set} (D : Desc I) (i : I) : Set where
init : El D (μ D) i → μ D i
----------------------------------------------------------------------
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
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))
----------------------------------------------------------------------
record Data : Set₁ where
field
E : Set
P : Tel
I : Scope P → Tel
C : (p : Scope P) (t : E) → Desc (Scope (I p))
----------------------------------------------------------------------
UncurriedFormer : Set
UncurriedFormer =
UncurriedScope P λ p
→ UncurriedScope (I p) λ i
→ Set
FormUncurried : UncurriedFormer
FormUncurried p = μ (Arg E (C p))
Former : Set
Former = CurriedScope P λ p → CurriedScope (I p) λ i → Set
Form : Former
Form =
curryScope P (λ p → CurriedScope (I p) λ i → Set) λ p →
curryScope (I p) (λ i → Set) λ i →
FormUncurried p i
----------------------------------------------------------------------
InjUncurried : E → Set
InjUncurried t = UncurriedScope P λ p → CurriedEl (C p t ) (FormUncurried p)
injUncurried : (t : E) → InjUncurried t
injUncurried t p = curryEl (C p t)
(FormUncurried p)
(λ xs → init (t , xs))
Inj : E → Set
Inj t = CurriedScope P λ p → CurriedEl (C p t) (FormUncurried p)
inj : (t : E) → Inj t
inj t = curryScope P
(λ p → CurriedEl (C p t) (FormUncurried p))
(injUncurried t)
----------------------------------------------------------------------
open Data using ( Former ; Form ; Inj ; inj )
----------------------------------------------------------------------
data VecT : Set where
nilT consT : VecT
VecR : Data
VecR = record {
E = VecT
; P = Ext Set λ _ → Emp
; I = λ _ → Ext ℕ λ _ → Emp
; C = λ { (A , tt) → λ
{ nilT → End (zero , tt)
; consT → Arg ℕ λ n → Arg A λ _
→ Rec (n , tt)
$ End (suc n , tt)
} }
}
Vec : (A : Set) → ℕ → Set
Vec = Form VecR
nil : (A : Set) → Vec A zero
nil = inj VecR nilT
cons : (A : Set) (n : ℕ) (x : A) (xs : Vec A n) → Vec A (suc n)
cons = inj VecR consT
----------------------------------------------------------------------
data TreeT : Set where
leaf₁T leaf₂T branchT : TreeT
TreeR : Data
TreeR = record {
E = TreeT
; P = Ext Set λ _ → Ext Set λ _ → Emp
; I = λ _ → Ext ℕ λ _ → Ext ℕ λ _ → Emp
; C = λ { (A , B , tt) → λ
{ leaf₁T → Arg A λ _ → End (suc zero , zero , tt)
; leaf₂T → Arg B λ _ → End (zero , suc zero , tt)
; branchT
→ Arg ℕ λ m → Arg ℕ λ n
→ Arg ℕ λ x → Arg ℕ λ y
→ Rec (m , n , tt) $ Rec (x , y , tt)
$ End (m + x , n + y , tt)
} }
}
Tree : (A B : Set) (m n : ℕ) → Set
Tree = Form TreeR
leaf₁ : (A B : Set) → A → Tree A B (suc zero) zero
leaf₁ = inj TreeR leaf₁T
----------------------------------------------------------------------
| 27.188571
| 82
| 0.461118
|
c79852e0eba60947d23ab066a4a6e9dabc58cee9
| 1,428
|
agda
|
Agda
|
agda/SNat/Log.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/SNat/Log.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/SNat/Log.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --sized-types #-}
module SNat.Log where
open import Size
open import SNat
open import SNat.Order
open import SNat.Order.Properties
open import SNat.Properties
open import SNat.Sum
lemma-≅-log : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≅ n → log₂ m ≅ log₂ n
lemma-≅-log z≅z = z≅z
lemma-≅-log (s≅s z≅z) = z≅z
lemma-≅-log (s≅s (s≅s m≅n)) = s≅s (lemma-≅-log (s≅s (lemma-≅-/2 m≅n)))
mutual
lemma-logn≤′logsn : {ι : Size}(n : SNat {ι}) → log₂ n ≤′ log₂ (succ n)
lemma-logn≤′logsn zero = ≤′-eq z≅z
lemma-logn≤′logsn (succ zero) = ≤′-step (≤′-eq z≅z)
lemma-logn≤′logsn (succ (succ n)) = lemma-s≤′s (lemma-≤′-log (lemma-s≤′s (lemma-n/2≤′sn/2 n)))
lemma-≤′-log : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤′ n → log₂ m ≤′ log₂ n
lemma-≤′-log (≤′-eq m≅n) = ≤′-eq (lemma-≅-log m≅n)
lemma-≤′-log (≤′-step {n = n} m≤′n) = trans≤′ (lemma-≤′-log m≤′n) (lemma-logn≤′logsn n)
lemma-1+logn≤′log2n : (n : SNat) → succ (log₂ (succ n)) ≤′ log₂ (succ n + succ n)
lemma-1+logn≤′log2n zero = refl≤′
lemma-1+logn≤′log2n (succ n) rewrite +-assoc-succ (succ (succ n)) (succ n) | +-assoc-succ n (succ n) | +-assoc-succ n n = lemma-s≤′s (lemma-≤′-log (lemma-s≤′s (lemma-n+1≤′2n+2/2 n)))
lemma-log2n≤′1+logn : (n : SNat) → log₂ (n + n) ≤′ succ (log₂ n)
lemma-log2n≤′1+logn zero = ≤′-step refl≤′
lemma-log2n≤′1+logn (succ n) rewrite +-assoc-succ (succ n) n = lemma-s≤′s (lemma-≤′-log (lemma-s≤′s (lemma-2n/2≤′n n)))
| 42
| 182
| 0.579132
|
a1f090286614174154855fa705bab23fc19b63c9
| 1,607
|
agda
|
Agda
|
Algebra/Group/Group.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | 1
|
2019-10-07T17:36:42.000Z
|
2019-10-07T17:36:42.000Z
|
Algebra/Group/Group.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
Algebra/Group/Group.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <esz@posteo.de>
module Algebra.Group.Group where
open import Algebra.Category
open import Algebra.Group.Monoid
open import Algebra.Group.Semigroup
open import Core
-- A group is a monoid where every element has an inverse.
record IsGroup {a r} (S : Semigroup {a} {r}) : Set (a ⊔ r) where
open Semigroup S
field isMonoid : IsMonoid S
open IsMonoid isMonoid
field iso : ∀ x → Iso x
inv : A → A
inv x = Iso.inv (iso x)
field inv-cong : ∀ {x y} → x ≈ y → inv x ≈ inv y
groupoid : Groupoid
groupoid =
record {
category = category;
iso = iso;
inv-cong = inv-cong
}
open Groupoid groupoid public
using (inv-invol)
record Group {a r} : Set (lsuc (a ⊔ r)) where
field semigroup : Semigroup {a} {r}
open Semigroup semigroup public
field isGroup : IsGroup semigroup
open IsGroup isGroup public
monoid : Monoid
monoid =
record {
semigroup = semigroup;
isMonoid = isMonoid
}
-- A group morphism is a function that maps the elements of one group to
-- another while preserving the compositional structure, the identity
-- and all inverses.
record GroupMorphism
{ga gr ha hr}
(G : Group {ga} {gr})
(H : Group {ha} {hr})
: Set (ga ⊔ gr ⊔ ha ⊔ hr)
where
private
module G = Group G
module H = Group H
field monoidMorphism : MonoidMorphism G.monoid H.monoid
open MonoidMorphism monoidMorphism public
field inv-preserving : ∀ x → map (G.inv x) H.≈ H.inv (map x)
| 21.716216
| 72
| 0.645302
|
12c5b4efb8bd04eabb4ce3ea7409e70a7fe45fa1
| 12,453
|
agda
|
Agda
|
Cubical/ZCohomology/CohomologyRings/Coproduct.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/CohomologyRings/Coproduct.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/CohomologyRings/Coproduct.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.CohomologyRings.Coproduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_ ; snotz to nsnotz)
open import Cubical.Data.Sigma
open import Cubical.Data.Sum
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.DirProd
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.DirectProd
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
open import Cubical.HITs.SetTruncation as ST
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Coproduct
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.CohomologyRing
private variable
ℓ ℓ' : Level
module Equiv-Coproduct-Properties
{X : Type ℓ}
{Y : Type ℓ'}
where
open Iso
open IsGroupHom
open GroupStr
open PlusBis
open RingStr (snd (H*R X)) using ()
renaming
( 0r to 0H*X
; 1r to 1H*X
; _+_ to _+H*X_
; -_ to -H*X_
; _·_ to _cupX_
; +Assoc to +H*XAssoc
; +IdL to +H*XIdL
; +IdR to +H*XIdR
; +Comm to +H*XComm
; ·Assoc to ·H*XAssoc
; ·IdL to ·H*XIdL
; ·IdR to ·H*XIdR
; is-set to isSetH*X )
open RingStr (snd (H*R Y)) using ()
renaming
( 0r to 0H*Y
; 1r to 1H*Y
; _+_ to _+H*Y_
; -_ to -H*Y_
; _·_ to _cupY_
; +Assoc to +H*YAssoc
; +IdL to +H*YIdL
; +IdR to +H*YIdR
; +Comm to +H*YComm
; ·Assoc to ·H*YAssoc
; ·IdL to ·H*YIdL
; ·IdR to ·H*YIdR
; is-set to isSetH*Y )
-- warning this does not open H*(X×Y) !
-- This just a notation shorter and pratical
open RingStr (snd (DirectProd-Ring (H*R X) (H*R Y))) using ()
renaming
( 0r to 0H*X×Y
; 1r to 1H*X×Y
; _+_ to _+H*X×Y_
; -_ to -H*X×Y_
; _·_ to _cupX×Y_
; +Assoc to +H*X×YAssoc
; +IdL to +H*X×YIdL
; +IdR to +H*X×YIdR
; +Comm to +H*X×YComm
; ·Assoc to ·H*X×YAssoc
; ·IdL to ·H*X×YIdL
; ·IdR to ·H*X×YIdR
; is-set to isSetH*X×Y )
open RingStr (snd (H*R (X ⊎ Y))) using ()
renaming
( 0r to 0H*X⊎Y
; 1r to 1H*X⊎Y
; _+_ to _+H*X⊎Y_
; -_ to -H*X⊎Y_
; _·_ to _cupX⊎Y_
; +Assoc to +H*X⊎YAssoc
; +IdL to +H*X⊎YIdL
; +IdR to +H*X⊎YIdR
; +Comm to +H*X⊎YComm
; ·Assoc to ·H*X⊎YAssoc
; ·IdL to ·H*X⊎YIdL
; ·IdR to ·H*X⊎YIdR
; is-set to isSetH*X⊎Y )
-----------------------------------------------------------------------------
-- Notation needed for type checking
-- indeed several base coexists and two cannot be inferef without implicit argument
-- it is clearer to add a notation
baseX : (n : ℕ) → (x : coHom n X) → H* X
baseX n x = base n x
baseY : (n : ℕ) → (x : coHom n Y) → H* Y
baseY n x = base n x
-----------------------------------------------------------------------------
-- Direct Sens
H*-X⊎Y→H*-X×H*-Y : H* (X ⊎ Y) → (H* X) × (H* Y)
H*-X⊎Y→H*-X×H*-Y =
DS-Rec-Set.f _ _ _ _
isSetH*X×Y
(0H*X , 0H*Y)
(λ n a → (base n (fst (fun (fst Equiv-Coproduct-CoHom) a))) , (base n (snd (fun (fst Equiv-Coproduct-CoHom) a))))
_+H*X×Y_
+H*X×YAssoc
+H*X×YIdR
+H*X×YComm
(λ n → ≡-× ((cong (λ A → baseX n (fst A)) (pres1 (snd Equiv-Coproduct-CoHom))) ∙ base-neutral n)
(((cong (λ B → baseY n (snd B)) (pres1 (snd Equiv-Coproduct-CoHom))) ∙ base-neutral n)))
λ n a b → sym (≡-× (cong (λ A → baseX n (fst A)) (pres· (snd Equiv-Coproduct-CoHom) a b)
∙ cong (base n) (helper1 _ _ _)
∙ sym (base-add n _ _))
(cong (λ B → baseY n (snd B)) (pres· (snd Equiv-Coproduct-CoHom) a b)
∙ cong (base n) (helper2 _ _ _)
∙ sym (base-add n _ _)))
where
helper1 : (n : ℕ) → (x y : coHom n X × coHom n Y)
→ fst ((DirProd (coHomGr n X) (coHomGr n Y) .snd GroupStr.· x) y) ≡ ((fst x) +ₕ (fst y))
helper1 n (fst₁ , snd₁) (fst₂ , snd₂) = refl
helper2 : (n : ℕ) → (x y : coHom n X × coHom n Y)
→ snd ((DirProd (coHomGr n X) (coHomGr n Y) .snd GroupStr.· x) y) ≡ ((snd x) +ₕ (snd y))
helper2 n (fst₁ , snd₁) (fst₂ , snd₂) = refl
-----------------------------------------------------------------------------
-- Converse Sens
-- One need to convert seperatly the X an Y
-- Otherwise the traduction fails in the case base n a , 0
-- because one need then to lift x + 0 ≡ 0
-- which doesn't work because the + being lifted is on H*(Y) and not H*(X)×H*(Y)
H*-X→H*-X⊎Y : H*(X) → H*(X ⊎ Y)
H*-X→H*-X⊎Y = DS-Rec-Set.f _ _ _ _ isSetH*X⊎Y
0H*X⊎Y
(λ n a → base n (inv (fst Equiv-Coproduct-CoHom) (a , (0ₕ n))))
_+H*X⊎Y_
+H*X⊎YAssoc
+H*X⊎YIdR
+H*X⊎YComm
(λ n → cong (base n) (pres1 (snd (invGroupIso Equiv-Coproduct-CoHom))) ∙ base-neutral n)
λ n a a' → base-add _ _ _
∙ cong (base n) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) _ _))
∙ cong (base n) (cong (inv (fst Equiv-Coproduct-CoHom))
(≡-× refl (AbGroupStr.+IdL (snd (coHomGroup n Y)) (0ₕ n))))
H*-Y→H*-X⊎Y : H*(Y) → H*(X ⊎ Y)
H*-Y→H*-X⊎Y = DS-Rec-Set.f _ _ _ _ isSetH*X⊎Y
0H*X⊎Y
(λ m b → base m (inv (fst Equiv-Coproduct-CoHom) (0ₕ m , b)))
_+H*X⊎Y_
+H*X⊎YAssoc
+H*X⊎YIdR
+H*X⊎YComm
(λ m → cong (base m) (pres1 (snd (invGroupIso Equiv-Coproduct-CoHom))) ∙ base-neutral m)
λ m b b' → base-add _ _ _
∙ cong (base m) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) (0ₕ m , b) (0ₕ m , b')))
∙ cong (base m) (cong (inv (fst Equiv-Coproduct-CoHom)) (≡-× (AbGroupStr.+IdL (snd (coHomGroup m X)) (0ₕ m)) refl))
H*-X×H*-Y→H*-X⊎Y : H*(X) × H*(Y) → H*(X ⊎ Y)
H*-X×H*-Y→H*-X⊎Y (x , y) = (H*-X→H*-X⊎Y x) +H*X⊎Y (H*-Y→H*-X⊎Y y)
H*-X×H*-Y→H*-X⊎Y-pres+ : (x y : H*(X) × H*(Y)) → H*-X×H*-Y→H*-X⊎Y (x +H*X×Y y) ≡ ((H*-X×H*-Y→H*-X⊎Y x) +H*X⊎Y (H*-X×H*-Y→H*-X⊎Y y))
H*-X×H*-Y→H*-X⊎Y-pres+ (x , y) (x' , y') = RingTheory.+ShufflePairs (H*R (X ⊎ Y)) _ _ _ _
-----------------------------------------------------------------------------
-- Section Sens
e-sectX : (x : H* X) → H*-X⊎Y→H*-X×H*-Y (H*-X→H*-X⊎Y x) ≡ (x , 0H*Y)
e-sectX = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)
refl
(λ n a → ≡-× (cong (base n) (cong fst (rightInv (fst Equiv-Coproduct-CoHom) (a , 0ₕ n))))
(cong (base n) (cong snd (rightInv (fst Equiv-Coproduct-CoHom) (a , 0ₕ n))))
∙ ≡-× refl (base-neutral n))
λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V ∙ ≡-× refl (+H*YIdR _)
e-sectY : (y : H* Y) → (H*-X⊎Y→H*-X×H*-Y (H*-Y→H*-X⊎Y y)) ≡ (0H*X , y)
e-sectY = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)
refl
(λ m b → ≡-× (cong (base m) (cong fst (rightInv (fst Equiv-Coproduct-CoHom) (0ₕ m , b))))
(cong (base m) (cong snd (rightInv (fst Equiv-Coproduct-CoHom) (0ₕ m , b))))
∙ ≡-× (base-neutral m) refl)
λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V ∙ ≡-× (+H*XIdR _) refl
e-sect : (z : H*(X) × H*(Y)) → H*-X⊎Y→H*-X×H*-Y (H*-X×H*-Y→H*-X⊎Y z) ≡ z
e-sect (x , y) = cong₂ _+H*X×Y_ (e-sectX x) (e-sectY y) ∙ ≡-× (+H*XIdR x) (+H*YIdL y)
-----------------------------------------------------------------------------
-- Retraction Sens
e-retr : (x : H*(X ⊎ Y)) → H*-X×H*-Y→H*-X⊎Y (H*-X⊎Y→H*-X×H*-Y x) ≡ x
e-retr = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X⊎Y _ _)
(+H*X⊎YIdR _)
(λ n a → ((base n (T⁻ ((fst (T a)) , 0ₕ n))) +H*X⊎Y (base n (T⁻ (0ₕ n , snd (T a)))))
≡⟨ base-add n _ _ ⟩
base n ((T⁻ ((fst (T a)) , 0ₕ n)) +ₕ (T⁻ (0ₕ n , snd (T a))))
≡⟨ cong (base n) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) ((fst (T a)) , 0ₕ n) (0ₕ n , snd (T a)))) ⟩
base n (T⁻ ( fst (T a) +ₕ 0ₕ n , 0ₕ n +ₕ snd (T a)))
≡⟨ cong (base n) (cong T⁻ (≡-× (rUnitₕ n (fst (T a))) (lUnitₕ n (snd (T a))))) ⟩
base n (T⁻ ( fst (T a) , snd (T a)))
≡⟨ cong (base n) (cong T⁻ (helper1 _ _ (T a))) ⟩
base n (T⁻ (T a))
≡⟨ cong (base n) (leftInv (fst Equiv-Coproduct-CoHom) a) ⟩
base n a ∎)
λ {U V} ind-U ind-V → (H*-X×H*-Y→H*-X⊎Y-pres+ _ _) ∙ (cong₂ _+H*X⊎Y_ ind-U ind-V)
where
T : {n : ℕ} → coHom n (X ⊎ Y) → coHom n X × coHom n Y
T {n} = fun (fst (Equiv-Coproduct-CoHom))
T⁻ : {n : ℕ} → coHom n X × coHom n Y → coHom n (X ⊎ Y)
T⁻ {n} = inv (fst (Equiv-Coproduct-CoHom))
helper1 : (A : Type ℓ) → (B : Type ℓ') → (x : A × B) → (fst x , snd x) ≡ x
helper1 A B (fst₁ , snd₁) = refl
-----------------------------------------------------------------------------
-- Ring Equiv-Coproduct-CoHomphism
H*-X⊎Y→H*-X×H*-Y-pres1 : H*-X⊎Y→H*-X×H*-Y 1H*X⊎Y ≡ (1H*X , 1H*Y)
H*-X⊎Y→H*-X×H*-Y-pres1 = refl
H*-X⊎Y→H*-X×H*-Y-pres+ : (x y : H* (X ⊎ Y)) →
H*-X⊎Y→H*-X×H*-Y ( x +H*X⊎Y y)
≡ H*-X⊎Y→H*-X×H*-Y x +H*X×Y H*-X⊎Y→H*-X×H*-Y y
H*-X⊎Y→H*-X×H*-Y-pres+ x y = refl
H*-X⊎Y→H*-X×H*-Y-pres· : (x y : H* (X ⊎ Y)) →
H*-X⊎Y→H*-X×H*-Y ( x cupX⊎Y y)
≡ H*-X⊎Y→H*-X×H*-Y x cupX×Y H*-X⊎Y→H*-X×H*-Y y
H*-X⊎Y→H*-X×H*-Y-pres· = DS-Ind-Prop.f _ _ _ _ (λ x p q i y → isSetH*X×Y _ _ (p y) (q y) i)
(λ y → refl)
(λ n a → DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)
refl
(λ m b → (base (n +' m) (fst (T (a ⌣ b)))) , base (n +' m) (snd (T (a ⌣ b)))
≡⟨ ≡-× (cong (base (n +' m)) (helperX a b))
(cong (base (n +' m)) (helperY a b)) ⟩
(base (n +' m) ((fst (T a)) ⌣ (fst (T b)))) , base (n +' m) ((snd (T a)) ⌣ (snd (T b))) ∎ )
λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V)
(λ {U V} ind-U ind-V y → cong₂ _+H*X×Y_ (ind-U y) (ind-V y))
where
T : {n : ℕ} → coHom n (X ⊎ Y) → coHom n X × coHom n Y
T {n} = fun (fst (Equiv-Coproduct-CoHom))
helperX : {n : ℕ} → {m : ℕ} → (a : coHom n (X ⊎ Y)) → (b : coHom m (X ⊎ Y))
→ fst (T (a ⌣ b)) ≡ (fst (T a)) ⌣ (fst (T b))
helperX = ST.elim (λ x → isProp→isSet λ u v i y → squash₂ _ _ (u y) (v y) i )
λ g → ST.elim (λ _ → isProp→isSet (squash₂ _ _))
(λ h → refl)
helperY : {n : ℕ} → {m : ℕ} → (a : coHom n (X ⊎ Y)) → (b : coHom m (X ⊎ Y))
→ snd (T (a ⌣ b)) ≡ (snd (T a)) ⌣ (snd (T b))
helperY = ST.elim (λ x → isProp→isSet λ u v i y → squash₂ _ _ (u y) (v y) i )
λ g → ST.elim (λ _ → isProp→isSet (squash₂ _ _))
(λ h → refl)
-----------------------------------------------------------------------------
-- Computation of the Cohomology Ring
module _
(X : Type ℓ)
(Y : Type ℓ')
where
open Equiv-Coproduct-Properties
open Iso
open RingEquivs
CohomologyRing-Coproduct : RingEquiv (H*R(X ⊎ Y)) (DirectProd-Ring (H*R X) (H*R Y))
fst (CohomologyRing-Coproduct) = isoToEquiv is
where
is : Iso (H* (X ⊎ Y)) (H* X × H* Y)
fun is = H*-X⊎Y→H*-X×H*-Y
inv is = H*-X×H*-Y→H*-X⊎Y
rightInv is = e-sect
leftInv is = e-retr
snd (CohomologyRing-Coproduct) = makeIsRingHom
H*-X⊎Y→H*-X×H*-Y-pres1
H*-X⊎Y→H*-X×H*-Y-pres+
H*-X⊎Y→H*-X×H*-Y-pres·
| 39.785942
| 141
| 0.45483
|
222e4655c4d6a46f92aa762b4649477c2cdc122b
| 32,168
|
agda
|
Agda
|
agda/paper/2008-Ulf_Norell_and_Chapman-Dependently_Typed_Programming_in_Agda/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/paper/2008-Ulf_Norell_and_Chapman-Dependently_Typed_Programming_in_Agda/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/paper/2008-Ulf_Norell_and_Chapman-Dependently_Typed_Programming_in_Agda/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module z where
-- http://www.cse.chalmers.se/~ulfn/papers/afp08/tutorial.pdf
{-
Dependently Typed Programming in Agda
Ulf Norell1 : Chalmers University, Gothenburg : ulfn@chalmers.se
James Chapman : Institute of Cybernetics, Tallinn : james@cs.ioc.ee
------------------------------------------------------------------------------
1 Introduction
In Hindley-Milner languages (Haskell, ML) : separation between types and values.
Dependently typed : types can contain (depend on) arbitrary values and
appear as arguments and results of ordinary functions
Dependent types enables types to talk about values,
so can encode properties of values as types
whose elements are proofs that the property is true.
So dependently typed programming language can be used as a logic.
To be consistent programs must be total.
------------------------------------------------------------------------------
2 BASICS
based on intuitionistic type theory[4]
--------------------------------------------------
2.1 DATATYPES AND PATTERN MATCHING
-}
data Bool : Set where
true : Bool
false : Bool
{-
type of Bool is
- Set, the type of small types
- There is hierarchy of increasingly large types
- type of Set is Set1, whose type is Set2, ...
-}
not : Bool → Bool
not true = false
not false = true
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat → Nat → Nat
zero + m = m
suc n + m = suc (n + m)
infixl 40 _+_
_*_ : Nat → Nat → Nat
zero * m = zero
suc n * m = m + n * m
infixl 60 _*_
{-
functions must not crash and must terminate
recursive calls have to be made on structurally smaller arguments
mixfix via _ : args where the underscores are
-}
_or_ : Bool → Bool → Bool
false or x = x
true or _ = true -- uses wildcard pattern on "don't care" args
infixr 20 _or_
-- polymorphic function over type A
if_then_else_ : {A : Set} → Bool → A → A → A
if true then x else y = x
if false then x else y = y
infix 5 if_then_else_
-- types parameterize by other types
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
infixr 40 _::_
-- liberal naming policy enables naming above
data _⋆ (α : Set) : Set where
ε : α ⋆
_C_ : α → α ⋆ → α ⋆
{-
whitespace important
--------------------------------------------------
2.2 DEPENDENT FUNCTIONS
result type depends on VALUE of an arg
(x : A) → B for the
type of functions
- given : arg x of type A
- returns : result of type B
- where x may appear in B
special case is when x itself is a type, e.g.,
-}
identity : (A : Set) → A → A
identity A x = x
zero’ : Nat
zero’ = identity Nat zero
{-
identity is a dependent function
- given
- a type argument A and
- an element of A
- returns
- the element
This is how polymorphic functions are encoded in Agda.
example : function which takes a dependent function and applies it to an argument:
-}
apply : (A : Set) (B : A → Set) → ((x : A) → B x) → (a : A) → B a
apply A B f a = f a
{-
shorthand for dependent function types:
(x : A) (y : B) → C
for (x : A) → (y : B) → C
(x y : A) → B
for (x : A) (y : A) → B
elements of dependent function types are lambda terms which may carry explicit type info
alternative ways to identity
identity function above are:
-}
identity2 : (A : Set) → A → A
identity2 = \A x → x
identity3 : (A : Set) → A → A
identity3 = \(A : Set) (x : A) → x
identity4 : (A : Set) → A → A
identity4 = \(A : Set) x → x
{-
--------------------------------------------------
2.3 IMPLICIT ARGUMENTS
Previous section showed how dependent functions taking types as
arguments used to model polymorphic types.
But it is not necessary to say at which point it is applied - that can be inferred.
The identity functions above explicitly provide the type argument.
Avoid explicit type arg via implicit arguments using {}
-}
id : {A : Set} → A → A
id x = x
true’ : Bool
true’ = id true
{-
No restrictions on what arguments can be made implicit.
Not guarantees that an implicit argument can be inferred.
E.g., make 2nd arg of identity function implicit as well:
-}
silly : {A : Set} {x : A} → A -- but type checker cannot figure out 2nd arg
silly {_} {x} = x
false’ : Bool
false’ = silly {x = false} -- must provide via named implicit application syntax f {v}
-- must use name if not in order
-- type checker fills in term
-- will not search, only looks at typing constraints and performs unification
one : Nat
one = identity _ (suc zero)
-- example of inferring the typing constraints
_◦_ : {A : Set}{B : A → Set}{C : (x : A) → B x → Set}
(f : {x : A}(y : B x) → C x y)(g : (x : A) → B x)
(x : A) → C x (g x)
(f ◦ g) x = f (g x)
plus-two = suc ◦ suc
-- other functions
map : {A B : Set} → (A → B) → List A → List B
map f [] = []
map f (x :: xs) = f x :: map f xs
_++_ : {A : Set} → List A → List A → List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
{-
--------------------------------------------------
-- 2.4 DATATYPE FAMILIES
So far, only used dependent types is to represent polymorphism
-}
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
_::_ : {n : Nat} → A → Vec A n → Vec A (suc n)
{-
type of Vec A is Nat → Set
- means that Vec A is a family of types indexed by natural numbers
- for each Nat n, Vec A n is a type
- [] constructs an element in Vec A zero
- _::_ constructs an element in Vec A (suc n) for some n
distinction between parameters and indices of a datatype
- parameterised by type A
- indexed over Nat
type of _::_ is a dependent function type
- 1st arg is an implicit Nat n
- returns type that depends on n 'suc n'
same constructor names for Vec as for List
- constructor names are not required to be distinct between different datatypes
-}
-- safe head
head : {A : Set} {n : Nat} → Vec A (suc n) → A
head (x :: xs) = x
tail : {A : Set} {n : Nat} → Vec A (suc n) → Vec A n
tail (x :: xs) = xs
{-
rule for when to include a particular case is:
if it is type correct you have to include it
-}
--------------------------------------------------
-- DOT PATTERNS : indicate value of an arg deduced by type checking, not pattern matching
vmap : {A B : Set} {n : Nat} → (A → B) → Vec A n → Vec B n
vmap f [] = []
vmap f (x :: xs) = f x :: vmap f xs
{-
map on Vec is exactly the same map on List
only change is the type
behind the scenes, what happens with the length argument when pattern matching
to see, define new versions of Vec and vmap with fewer implicit arguments:
-}
data Vec2 (A : Set) : Nat → Set where
nil : Vec2 A zero
cons : (n : Nat) → A → Vec2 A n → Vec2 A (suc n)
vmap2 : {A B : Set} (n : Nat) → (A → B) → Vec2 A n → Vec2 B n
vmap2 .zero f nil = nil
vmap2 .(suc n) f (cons n x xs) = cons n (f x) (vmap2 n f xs)
{-
pattern matching on list argument reveals its length
- if nil then zero
- if cons then suc n
to indicate value of an arg deduced by type checking,
rather than observed by pattern matching,
it is prefixed by a dot (.)
could choose to define vmap by first pattern matching on the length rather than on the list
-}
vmap3 : {A B : Set} (n : Nat) → (A → B) → Vec2 A n → Vec2 B n
vmap3 zero f nil = nil
vmap3 (suc n) f (cons .n x xs) = cons n (f x) (vmap3 n f xs)
{-
rule for when arg should be dotted:
- if there is a unique type correct value for the argument it should be dotted
above, the terms under the dots were valid patterns
- in general they can be arbitrary terms
e.g.,
-}
data Image_el_ {A B : Set}(f : A → B) : B → Set where
im : (x : A) → Image f el f x
{-
only way to construct an element in the image of f
is to pick an argument x and apply f to x
knowing that a particular y is in the image of f enables computing the inverse of f on y:
-}
inv : {A B : Set} (f : A → B) (y : B) → Image f el y → A
inv f .(f x) (im x) = x
{-
--------------------------------------------------
ABSURD PATTERNS
-}
-- family of numbers smaller than a given natural number
data Fin : Nat → Set where
fzero : {n : Nat} → Fin (suc n) -- smaller than suc n for any n
fsuc : {n : Nat} → Fin n → Fin (suc n) -- if i smaller than n then fsuc i is smaller than suc n
-- Now way to construct a Fin smaller than zero.
-- When no possible constructor patterns for a given argument
-- then pattern match with absurd pattern ()
magic : {A : Set} → Fin zero → A
magic ()
{-
Using absurd pattern means no need to give a right hand side,
since no way anyting could given as an arg that would match.
Seems the clause not needed, that checker could tell.
But a case can only be omitted if no type correct way of writing it.
'magic a' has a type correct left hand side
absurd pattern can only be used if there are no valid constructor patterns for the arg.
It is not enough that there are no closed inhabitants of the type.
E.g.,
-}
data Empty : Set where
empty : Fin zero → Empty
{-
Args of type Empty cannot be matched with absurd pattern,
since there is a valid constructor pattern: 'empty x'
So must write:
-}
magic’ : {A : Set} → Empty → A
magic’ (empty ()) -- magic’ () -- not accepted
-- Extract ith element of the list (starting from 0):
-- Turns a list into a function from indices to elements.
_!_ : {n : Nat} {A : Set} → Vec A n → Fin n → A
[] ! ()
(x :: xs) ! fzero = x
(x :: xs) ! (fsuc i) = xs ! i
{-
types ensure no danger of indexing outside the list
reflected in use of absurd in empty case : no possible values for the index
-}
-- constructing a list given a function from indices to elements
tabulate : {n : Nat} {A : Set} → (Fin n → A) → Vec A n
tabulate {zero} f = []
tabulate {suc n} f = f fzero :: tabulate (f ◦ fsuc) -- recursive call implicitly gets 'n'
{-
tabulate is defined by recursion over the length of the result list,
even though it is an implicit argument.
In general, no correspondance between implicit data and computationally irrelevant data.
------------------------------------------------------------------------------
-- 2.5 PROGRAMS AS PROOFS
Type system can represent propositions as types whose elements are proofs of the proposition.
-}
data False : Set where -- datatype with no constructors
record True : Set where -- record type with no fields
-- has a single element : the empty record
{-
Could have defined True as datatype with a single element.
But using record def lets checker know there is a unique element of True
and will fill in any implicit arguments of type True with this element.
exploited in trivial:
-}
trivial : True
trivial = _
trivial' : True
trivial' = record {}
{-
where right hand is underscore,
instead of explicitly writing 'record {}'
The 'False' and 'True' propositions enable working with decidable propositions.
Can model decidable propositions as booleans and define
-}
-- takes a VALUE of type Bool
-- returns a Set (i.e., a TYPE)
isTrue : Bool → Set
isTrue true = True
isTrue false = False
isFalse : Bool → Set
isFalse x = isTrue (not x)
{-
isTrue b is the type of proofs that b equals true.
This technique enables defining safe list lookup function in a different way,
working on simply typed lists and numbers.
-}
-- takes Nat VALUES
-- returns Bool VALUES
_<_ : Nat → Nat → Bool
_ < zero = false
zero < suc n = true
suc m < suc n = m < n
length : {A : Set} → List A → Nat
length [] = zero
length (x :: xs) = suc (length xs)
-- |
-- v
lookup : {A : Set} (xs : List A) (n : Nat) → isTrue (n < length xs) → A
lookup [] n ()
lookup (x :: xs) zero p = x
lookup (x :: xs) (suc n) p = lookup xs n p
{-
Rather than there being no index into the empty list,
there is no proof that a number n is smaller than zero.
In this example, using indexed types to capture the precondition,
as done in '_!_' above, is a little bit nicer,
since do not have to pass an explicit proof object
as done in 'lookup' above.
When properties cannot be easily captured by indexed types, this is a useful alternative.
--------------------------------------------------
DEFINE PROPOSITIONS USING DATATYPE FAMILIES
-}
-- family of proofs of “being equal to x”
-- specify the type by giving it two args
-- type can only be constructed when the two args reduce to the same thing
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x -- only inhabited at index x where the single proof is refl
-- another exampla
-- compare to def of '_<_' above
data _≤_ : Nat → Nat → Set where
leq-zero : {n : Nat} → zero ≤ n
leq-suc : {m n : Nat} → m ≤ n → suc m ≤ suc n
{-
advantage of this approach
- PATTERN MATCH ON PROOF OBJECT
- makes proving properties of _≤_ easier
- e.g.,
-}
leq-trans : {l m n : Nat} → l ≤ m → m ≤ n → l ≤ n
leq-trans leq-zero _ = leq-zero
leq-trans (leq-suc p) (leq-suc q) = leq-suc (leq-trans p q)
{-
------------------------------------------------------------------------------
-- 2.6 WITH : PATTERN MATCH ON RESULT OF INTERMEDIATE COMPUTATION
Haskell : done on right hand side using case
when matching expression in dependently typed language, learn
- shape of expression
- things about other expressions
- e.g., matching 'Vec A n' reveals info about n
- not captured by usual case expression
to pattern match on an expression e in the def of fun f
- abstract f over value of e
- effectively adding another argument to f
- can then be matched on in usual way
-}
min : Nat → Nat → Nat
min x y with x < y
min x y | true = x
min x y | false = y
{-
Can abstract over multiple expressions at same time, separated by vertical bars.
Can nest with abstractions.
When matching on arg using WITH, no need to match on args again:
- use ...
-}
filter : {A : Set} → (A → Bool) → List A → List A
filter p [] = []
filter p (x :: xs) with p x
... | true = x :: filter p xs
... | false = filter p xs
{-
Example of revealing info via matching.
Compare numbers for equality.
Instead of returning boolean,
return proof of equality or
explanation of why they are not equal.
-}
data _≠_ : Nat → Nat → Set where
z≠s : {n : Nat} → zero ≠ suc n -- different if one is zero and other suc
s≠z : {n : Nat} → suc n ≠ zero -- vice versa
s≠s : {m n : Nat} → m ≠ n → suc m ≠ suc n -- both suc but their predecessors are different
data Equal? (n m : Nat) : Set where
eq : n ≡ m → Equal? n m
neq : n ≠ m → Equal? n m
-- now function that returns the explanation
equal? : (n m : Nat) → Equal? n m
-- Equal? zero zero
-- zero ≡ zero
equal? zero zero = eq refl
equal? zero (suc _) = neq z≠s
equal? (suc _) zero = neq s≠z
equal? (suc n) (suc m) with equal? n m -- matching on proof reveals if predecessors are equal
equal? (suc _) (suc _) | eq refl = eq refl
-- Equal? (suc n) (suc m)
-- suc n ≠ suc m
-- n ≠ m
equal? (suc _) (suc _) | neq p = neq (s≠s p)
{-
using WITH : expression is abstracted from entire context
means that if expression occurs in type of arg to function or in result type,
occurrence is replaced by the with-argument on the left hand side.
e.g., prove 'filter' only removes some elements
-}
-- to make a sublist, each element can either be dropped or kept
infix 20 _⊆_
data _⊆_ {A : Set} : List A → List A → Set where
stop : [] ⊆ []
drop : forall {xs y ys} → xs ⊆ ys → xs ⊆ y :: ys
keep : forall {x xs ys} → xs ⊆ ys → x :: xs ⊆ x :: ys
{-
When checker can infer type of an arg in fun type, then can use forall:
– forall {x y} a b → A shorthand for {x : _} {y : _} (a : _) (b : _) → A
-}
-- proof that filter computes a sublist of its argument:
lem-filter : {A : Set} (p : A → Bool) (xs : List A)
→ filter p xs ⊆ xs
lem-filter p [] = stop
lem-filter p (x :: xs) with p x
... | true = keep (lem-filter p xs)
... | false = drop (lem-filter p xs)
{-
to prove lem-filter p (x :: xs)
need to prove : (filter p (x :: xs) | p x) ⊆ x :: xs
when abstracting over p x it will be abstracted from goal type, giving
lem-filter p (x :: xs) with p x
... | px = ?
where p x has been replaced by px in the goal type
(filter p (x :: xs) | px) ⊆ x :: xs
match px reduce call to filter
lem-filter p (x :: xs) with p x
... | true = ? {- x :: filter p xs ⊆ x :: xs -}
... | false = ? {- filter p xs ⊆ x :: xs -}
Sometimes WITH useful to abstract over expr that will not be matched,
e.g., expect expr to be instantiated by matching on something else
-}
lem-plus-zero : (n : Nat) → n + zero ≡ n
lem-plus-zero zero = refl
lem-plus-zero (suc n) with n + zero | lem-plus-zero n
... | _ | refl = refl -- suc n ≡ suc n
{-
In suc ("step" case) : match on induction hypothesis : n + zero ≡ n
to prove suc n + zero ≡ suc n
but n + zero does not unify with n
so abstract over n + zero, calling it _,
left with the induction hypothesis m ≡ n and goal suc m ≡ suc n
Now match on induction hypothesis, instantiating _ to n
--------------------------------------------------
-- 2.7 Modules TODO
--------------------------------------------------
-- 2.8 Records
-}
record Point : Set where
field
x : Nat
y : Nat
mkPoint : Nat → Nat → Point
mkPoint a b = record { x = a; y = b }
{-
field projections via module of the same name.
- parameterised by element of record type
- contains projection functions for the fields
- i.e.,
module Point (p : Point) where
x : Nat
y : Nat
- can be used as is or instantiated to a particular record
-}
getX : Point → Nat
getX = Point.x
abs2 : Point → Nat
abs2 p = let open Point p in x * x + y * y
-- TODO pattern match on records
-- can add functions to the module of a record
record Monad (M : Set → Set) : Set1 where
field
return : {A : Set} → A → M A
_>>=_ : {A B : Set} → M A → (A → M B) → M B
mapM : {A B : Set} → (A → M B) → List A → M (List B)
mapM f [] = return []
mapM f (x :: xs) = f x >>= \y →
mapM f xs >>= \ys →
return (y :: ys)
mapM’ : {M : Set → Set}
→ Monad M
→ {A B : Set}
→ (A → M B)
→ List A
→ M (List B)
mapM’ Mon f xs = Monad.mapM Mon f xs
--------------------------------------------------
-- 2.9 Exercises
-------------------------
-- Exercise 2.1. Matrix transposition
-- inner vectors are rows
Matrix : Set → Nat → Nat → Set
Matrix A n m = Vec (Vec A n) m
-- (a) function to compute vector containing n copies of element x
vec : {n : Nat} {A : Set} → A → Vec A n
vec {zero} x = []
vec {suc n} x = x :: vec {n} x
vecTest : Vec Nat 3
vecTest = vec zero
-- (b) point-wise application of vector of functions to vector of arguments
infixl 90 _$_
_$_ : {n : Nat} {A B : Set} → Vec (A → B) n → Vec A n → Vec B n
_$_ [] [] = []
_$_ (f :: fs) (x :: xs) = f x :: fs $ xs
$TestInputFs : Vec (Nat → Nat) 2
$TestInputFs = (_+ 1) :: (_* 2) :: []
$TestInputXs : Vec Nat 2
$TestInputXs = 0 :: 2 :: []
$TestOutput : Vec Nat 2
$TestOutput = 1 :: 4 :: []
$Test : $TestInputFs $ $TestInputXs ≡ $TestOutput
$Test = refl
-- (c) matrix transposition in terms of 'vec' and _$_
transpose : forall {A n m} → Matrix A n m → Matrix A m n
transpose [] = vec []
transpose (xs :: xss) = (vmap _::_ xs) $ (transpose xss)
transposeTestInput : Matrix Nat 2 3
transposeTestInput = r1 :: r2 :: r3 :: []
where
r1 = 1 :: 2 :: []
r2 = 3 :: 4 :: []
r3 = 5 :: 6 :: []
transposeTestOuput : Matrix Nat 3 2
transposeTestOuput = r1 :: r2 :: []
where
r1 = 1 :: 3 :: 5 :: []
r2 = 2 :: 4 :: 6 :: []
transposeTest : transpose transposeTestInput ≡ transposeTestOuput
transposeTest = refl
-------------------------
-- Exercise 2.2. Vector lookup
-- function composition
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘ f) x = g (f x)
-- prove 'tabulate' and '!' are each other’s inverses
-- (a) relatively easy
lem-!-tab : ∀ {A n}
→ (f : Fin n → A) → (i : Fin n)
→ ((tabulate f) ! i) ≡ f i
lem-!-tab f fzero = refl -- (tabulate f ! fzero) ≡ f fzero
lem-!-tab f (fsuc i) = lem-!-tab (f ∘ fsuc) i -- (tabulate f ! fsuc i) ≡ f (fsuc i)
-- (b) trickier
lem-tab-! : forall {A n}
→ (xs : Vec A n)
→ tabulate (xs !_) ≡ xs
lem-tab-! [] = refl
lem-tab-! (x :: xs) -- tabulate (_!_ (x :: xs)) ≡ (x :: xs)
with tabulate (xs !_) | lem-tab-! xs
... | _y | refl = refl -- (x :: _y) ≡ (x :: xs)
-- ^ ^
-- Vec A n _y ≡ xs
-------------------------
-- Exercise 2.3. Sublists (see def above)
-- (a) prove reflexivity and transitivity of ⊆
-- need to name implicits since the interesting one does not come first
⊆-refl : {A : Set} {xs : List A}
→ xs ⊆ xs
⊆-refl {xs = []} = stop
⊆-refl {xs = x :: xss} = keep (⊆-refl { xs = xss })
{-
[] [] []
[] [] [z]
[] [z] [z]
[z] [z] [z]
[z] [z] [z,z]
[z] [z,z] [z,z]
[z,z] [z,z] [z,z]
-}
⊆-trans : {A : Set} {xs ys zs : List A}
→ xs ⊆ ys
→ ys ⊆ zs
→ xs ⊆ zs
-- [] [] []
⊆-trans stop stop = stop
-- [] [] [z]
-- [z] [z] [z,z]
⊆-trans xy (drop yz) = drop (⊆-trans xy yz)
-- [] [z] [z]
-- [z] [z,z] [z,z]
⊆-trans (drop xy) (keep yz) = drop (⊆-trans xy yz)
-- [z] [z] [z]
⊆-trans (keep xy) (keep yz) = keep (⊆-trans xy yz)
⊆-trans' : {A : Set} {xs ys zs : List A}
→ xs ⊆ ys
→ ys ⊆ zs
→ xs ⊆ zs
⊆-trans' stop stop = stop
⊆-trans' stop (drop yz) = drop (⊆-trans' stop yz)
⊆-trans' (drop xy) (drop yz) = drop (⊆-trans' (drop xy) yz)
⊆-trans' (drop xy) (keep yz) = drop (⊆-trans' xy yz)
⊆-trans' (keep xy) (drop yz) = drop (⊆-trans' (keep xy) yz)
⊆-trans' (keep xy) (keep yz) = keep (⊆-trans' xy yz)
-- sublist TYPE of a specific list (compare to existing sublist RELATION above)
infixr 30 _:::_
data SubList {A : Set} : List A → Set where
[] : SubList []
_:::_ : forall x {xs} → SubList xs → SubList (x :: xs)
skip : forall {x xs} → SubList xs → SubList (x :: xs)
-- (b) extract list corresponding to a sublist
forget : {A : Set} {xs : List A}
→ SubList xs
→ List A
forget [] = []
forget (x ::: s) = x :: forget s
forget (skip s) = forget s
-- (c) prove SubList is a sublist in the sense of ⊆
lem-forget : {A : Set} {xs : List A}
→ (zs : SubList xs)
→ forget zs ⊆ xs
lem-forget [] = stop
lem-forget (x ::: zs) = keep (lem-forget zs)
lem-forget (skip zs) = drop (lem-forget zs)
-- (d) alternative def of filter : satisfies sublist property by construction
filter' : {A : Set}
→ (A → Bool) → (xs : List A)
→ SubList xs
filter' p [] = []
filter' p (x :: xs) with p x
... | true = x ::: filter' p xs
... | false = skip (filter' p xs)
-- (e) complement of a sublist
complement : {A : Set} {xs : List A}
→ SubList xs
→ SubList xs
complement [] = []
complement (x ::: xs) = skip (complement xs)
complement (skip {x} xs) = x ::: complement xs
module ComplementTest where
ll : List Nat
ll = 1 :: 2 :: 3 :: 4 :: []
p1 : Nat → Bool
p1 2 = true
p1 3 = true
p1 4 = true
p1 _ = false
p2 : Nat → Bool
p2 2 = true
p2 4 = true
p2 _ = false
sl1 : SubList ll
sl1 = filter' p1 ll
sl2 : SubList ll
sl2 = filter' p2 ll
sl1Test : sl1 ≡ skip (2 ::: 3 ::: 4 ::: [])
sl1Test = refl
sl2Test : sl2 ≡ skip (2 ::: skip (4 ::: []))
sl2Test = refl
c1 : SubList ll
c1 = complement sl1
c2 : SubList ll
c2 = complement sl2
cTest1 : c1 ≡ 1 ::: skip (skip (skip []))
cTest1 = refl
cTest2 : c2 ≡ 1 ::: skip (3 ::: skip [])
cTest2 = refl
-- https://medium.com/@angerman/powersets-in-haskell-1df9684db52a
-- (f) compute all sublists of a given list
sublists : {A : Set}
→ (xs : List A)
→ List (SubList xs)
sublists [] = [] :: []
sublists (x :: xs) = map (x :::_) (sublists xs) ++ (map skip (sublists xs))
-- 2^3 elements - expected output MUST be in same element ORDER as function result
sublistsTest : sublists (1 :: 2 :: 3 :: []) ≡
(1 ::: 2 ::: 3 ::: []) ::
(1 ::: 2 ::: skip []) ::
(1 ::: skip (3 ::: [])) ::
(1 ::: skip (skip [])) ::
skip (2 ::: 3 ::: []) ::
skip (2 ::: skip []) ::
skip (skip (3 ::: [])) ::
skip (skip (skip [])) ::
[]
sublistsTest = refl
{-
------------------------------------------------------------------------------
3 Programming Techniques : VIEWS and UNIVERSE constructions
--------------------------------------------------
3.1 VIEWS
matching can reveal info about term being matched AND terms INSIDE the type matched term
VIEW[5]: datatypes whose purpose is to reveal info about its indices
to use a view, define a view function
- computes an element of the view for arbitrary indices
-}
-- view datatype expressing
-- any Nat can be expressed as 2k or 2k + 1 for some k
-- element of Parity n says if n is even or odd and what k is
data Parity : Nat → Set where
even : (k : Nat) → Parity (k * 2)
odd : (k : Nat) → Parity (1 + k * 2)
parity : (n : Nat) → Parity n
parity zero = even zero
parity (suc n) with parity n
... | even k = odd k
... | odd k = even (suc k)
{-
parity (suc .(k * 2)) | even k = odd k
parity (suc .(1 + k * 2)) | odd k = even (suc k)
-}
half : Nat → Nat
half n with parity n
... | even k = k
... | odd k = k
{-
-- Note that k is bound in the pattern for the view,
-- not in the dotted pattern for the natural number.
half .(k * 2) | even k = k
half .(1 + k * 2) | odd k = k
-}
-------------------------
-- FINDING AN ELEMENT IN A LIST
-- given predicate and list
-- returns if P holds for all elements
-- A proof of All P xs is a list of proofs of P x for each element x of xs.
-- P does not have to be a decidable predicate.
infixr 30 _:all:_
data All {A : Set} (P : A → Set) : List A → Set where
all[] : All P []
_:all:_ : forall {x xs} → P x → All P xs → All P (x :: xs)
-- to turn a decidable predicate into a general predicate, define:
satisfies : {A : Set} → (A → Bool) → A → Set
satisfies p x = isTrue (p x)
-------------------------
-- exercise : use All to prove 2nd part of correctness of filter
-- - all elements of result satisfies the predicate
-- All (satisfies p) (filter p xs)
-- https://www.javaer101.com/en/article/18631037.html
{-
open import Relation.Binary.PropositionalEquality
filter-lem-b : {A : Set} → (p : A → Bool) → (xs : List A) → All (satisfies p) (filter p xs)
filter-lem-b p [] = vacuo
filter-lem-b p (x :: xs) with p x | inspect p x
... | true | [ eq ] = holds _ _ (subst isTrue (sym eq) _) (filter-lem-b p xs)
... | false | [ eq ] = filter-lem-b p xs
-}
-- https://stackoverflow.com/questions/38572464/agda-type-isnt-simplified-in-with-block
lem-all-filter : {A : Set}
→ (p : A → Bool) → (xs : List A)
→ All (satisfies p) (filter p xs)
lem-all-filter p [] = all[]
-- isTrue (p x)
lem-all-filter p (x :: xs) with p x | λ (y : satisfies p x) → y :all: lem-all-filter p xs
-- onTrue : (y : True) → All (λ x₁ → isTrue (p x₁)) (x :: filter p xs)
... | true | onTrue = onTrue _
... | false | _ = lem-all-filter p xs
-------------------------
-- VIEWS ON LISTS
-- given : decidable predicate on elements of list
-- find element in list that satisfies predicate,
-- or else all elements satifies negation of the predicate
data Find {A : Set} (p : A → Bool) : List A → Set where
-- does NOT specify which element to use as a witness in the found case.
-- (If the view was always to return first (or last) matching element,
-- force elements of xs (or ys) to satisfy the negation of p.)
found : (xs : List A) → (y : A) → satisfies p y → (ys : List A)
→ Find p (xs ++ y :: ys)
not-found : forall {xs} → All (satisfies (not ◦ p)) xs
→ Find p xs
-- view function computing an element of Find p xs for any p and xs
-- 1st attempt
{-
find1 : {A : Set} (p : A → Bool) (xs : List A) → Find p xs
find1 p [] = not-found all[]
find1 p (x :: xs) with p x
-- Need to return found on first match.
-- ({ }) is isTrue (p x), even though already matched on p x and found out that it was true.
-- Problem : when abstracting over p x did not know that needed to use the found constructor,
-- so there were no p x to abstract over.
-- WITH does not remember connection between the with-term and the pattern.
... | true = found [] x {! !} xs
... | false = {! !}
-}
{-
A solution : make this connection explicit with a proof object.
Do NOT abstract over the term itself
- instead rather over arbitrary term of same type
AND a proof that it is equal to the original term
-}
-- type of elements of type A AND proofs they are equal to some given x in A
data Inspect {A : Set} (x : A) : Set where
it : (y : A) → x ≡ y → Inspect x
-- construct an element of Inspect x by picking x as thing which is equal to x.
inspect : {A : Set} → (x : A) → Inspect x
inspect x = it x refl
-- lemmas
trueIsTrue : {x : Bool} → x ≡ true → isTrue x
falseIsFalse : {x : Bool} → x ≡ false → isFalse x
trueIsTrue refl = _
falseIsFalse refl = _
{-
now define find by abstracting over inspect (p x) rather than p x
provide either a proof of p x == true or a proof of p x == false
- can be use in args to 'found' and 'not-found
-}
find : {A : Set}
→ (p : A → Bool) → (xs : List A)
→ Find p xs
find p [] = not-found all[]
find p (x :: xs) with inspect (p x)
-- When p x is true, inspect (p x) matches 'it true prf' where prf : p x == true.
-- Use lemma to turn into proof of isTrue (p x) needed by 3rd arg of 'found'
... | it true prf = found [] x (trueIsTrue prf) xs
... | it false prf with find p xs
find p (x :: ._) | it false _ | found xs y py ys = found (x :: xs) y py ys
-- p x is false : use lemma
find p (x :: xs) | it false prf | not-found npxs = not-found (falseIsFalse prf :all: npxs)
-------------------------
-- INDEXING INTO A LIST
{-
Previously showed two ways of safely indexing into a list.
Both cases used type system to guarantee the index didn’t point outside the list.
In situations where there is no control over value of index (i.e., it might be outside)
a solution is to wrap result of lookup in MAYBE, but MAYBE provides no info.
-}
-- type of proofs that an element x is in a list xs.
data _∈_ {A : Set} (x : A) : List A → Set where
hd : forall {xs} → x ∈ x :: xs -- 1st el is a member
tl : forall {y xs} → x ∈ xs → x ∈ y :: xs -- any el in tail is member
-- Given proof of x ∈ xs, compute index where x occurs.
-- Count number of tls in proof.
index : forall {A} {x : A} {xs} → x ∈ xs → Nat
index hd = zero
index (tl p) = suc (index p)
-- view on Nat with respect to list
data Lookup {A : Set} (xs : List A) : Nat → Set where
inside : (x : A) → (p : x ∈ xs) → Lookup xs (index p)
outside : (m : Nat) → Lookup xs (length xs + m)
{-
When n is valid, get element at that position and guarantee that element is returned.
No way for 'lookup' to cheat.
When n is outside, get out-of-bounds proof showing by how much.
-}
-- now, guaranteed 'lookup' function
_!'_ : {A : Set}
→ (xs : List A) → (n : Nat)
→ Lookup xs n
[] !' n = outside n
(x :: xs) !' zero = inside x hd
(x :: xs) !' suc n with xs !' n
... | inside y p = inside y (tl p)
(x :: xs) !' suc .(length xs + n) | outside n = outside n
{-
(x :: xs) !' suc .(index p) | inside y p = inside y (tl p)
(x :: xs) !' suc .(length xs + n) | outside n = outside n
-}
--------------------------------------------------
-- TYPE CHECKER FOR λ-CALCULUS
| 28.568384
| 98
| 0.575665
|
58ff8b2eeff5fc46e7ba67f1157ed45146733138
| 266
|
agda
|
Agda
|
test/Fail/CopatternWithoutFieldName.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/fail/CopatternWithoutFieldName.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/CopatternWithoutFieldName.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- 2011-11-24 Andreas, James
{-# OPTIONS --copatterns #-}
module CopatternWithoutFieldName where
record R : Set2 where
field
f : Set1
open R
test : (f : R -> Set1) -> R
test f = bla where
bla : R
f bla = Set
-- not a copattern, since f not a field name
| 16.625
| 44
| 0.642857
|
57119ee0b5bf2c0cee612da09b1832809832d86a
| 475
|
agda
|
Agda
|
test/Fail/Issue1209-4-2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1209-4-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1209-4-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Showing that destroy-guardedness in Issue1209-4 indeed does
-- destroy guardedness
{-# OPTIONS --safe --guardedness --no-sized-types #-}
record Stream (A : Set) : Set where
coinductive
field
head : A
tail : Stream A
open Stream
destroy-guardedness : ∀ {A} → Stream A → Stream A
destroy-guardedness xs .head = xs .head
destroy-guardedness xs .tail = xs .tail
repeat : ∀ {A} → A → Stream A
repeat x .head = x
repeat x .tail = destroy-guardedness (repeat x)
| 22.619048
| 62
| 0.684211
|
2009ff54798b7f4277f8f910ede7df1b769279ea
| 3,280
|
agda
|
Agda
|
src/CategoryTheory/Instances/Sets.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | 4
|
2018-05-31T20:37:04.000Z
|
2022-01-04T09:33:48.000Z
|
src/CategoryTheory/Instances/Sets.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
src/CategoryTheory/Instances/Sets.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
{- Category of sets -}
module CategoryTheory.Instances.Sets where
open import CategoryTheory.Categories
open import CategoryTheory.BCCCs
import Function as F using (_∘_)
open import Data.Unit using () renaming (⊤ to top) public
open import Data.Product public
open import Data.Empty using (⊥-elim) renaming (⊥ to bot) public
open import Data.Sum
-- Category of sets.
𝕊et : Category lzero
𝕊et = record
{ obj = Set
; _~>_ = λ a b -> (a -> b)
; id = λ a -> a
; _∘_ = λ g f a -> g (f a)
; _≈_ = λ f g -> ∀ {a} -> f a ≡ g a
; id-left = refl
; id-right = refl
; ∘-assoc = refl
; ≈-equiv = record { refl = refl
; sym = λ p → sym p
; trans = λ p q → trans p q }
; ≈-cong = ≈-cong-𝕊
}
where
≈-cong-𝕊 : ∀{A B C : Set} {f f′ : A -> B} {g g′ : B -> C}
-> (∀ {a} -> f a ≡ f′ a)
-> (∀ {b} -> g b ≡ g′ b)
-> (∀ {a} -> g (f a) ≡ g′ (f′ a))
≈-cong-𝕊 {f′ = f′} fe ge {a′} rewrite fe {a′} | ge {f′ a′} = refl
-- Bicartesian closed structure
𝕊et-BCCC : BicartesianClosed 𝕊et
𝕊et-BCCC = record
{ cart = record
{ term = record
{ ⊤ = top
; ! = λ {A} _ → top.tt
; !-unique = λ m → refl
}
; prod = λ A B → record
{ A⊗B = A × B
; π₁ = proj₁
; π₂ = proj₂
; ⟨_,_⟩ = <_,_>
; π₁-comm = refl
; π₂-comm = refl
; ⊗-unique = λ pr1 pr2 → unique-cart (ext λ x → pr1 {x}) (ext λ x → pr2 {x})
}
}
; cocart = record
{ init = record
{ ⊥ = bot
; ¡ = ⊥-elim
; ¡-unique = λ {A} m → λ {}
}
; sum = λ A B → record
{ A⊕B = A ⊎ B
; ι₁ = inj₁
; ι₂ = inj₂
; [_⁏_] = [_,_]
; ι₁-comm = λ {S} {i₁} {i₂} {a} → refl
; ι₂-comm = λ {S} {i₁} {i₂} {a} → refl
; ⊕-unique = λ {S} {i₁} {i₂} {m} pr1 pr2
-> unique-cocart {m = m} (ext λ x → pr1 {x}) (ext λ x → pr2 {x})
}
}
; closed = record
{ exp = λ A B → record
{ A⇒B = A -> B
; eval = λ fa → proj₁ fa (proj₂ fa)
; Λ = λ f a b → f (a , b)
; Λ-comm = refl
; Λ-unique = λ pr → λ {a} -> unique-closed (ext λ x → pr {x})
; Λ-cong = λ pr → ext (λ _ → pr)
}
}
}
where
unique-cart : ∀{A B P : Set}{a}
-> {p₁ : P -> A} {p₂ : P -> B} {m : P -> A × B}
-> proj₁ F.∘ m ≡ p₁ -> proj₂ F.∘ m ≡ p₂
-> < p₁ , p₂ > a ≡ m a
unique-cart refl refl = refl
unique-cocart : ∀{A B S : Set}{a}
-> {i₁ : A -> S} {i₂ : B -> S} {m : A ⊎ B -> S}
-> m F.∘ inj₁ ≡ i₁ -> m F.∘ inj₂ ≡ i₂
-> [ i₁ , i₂ ] a ≡ m a
unique-cocart {a = inj₁ x} refl refl = refl
unique-cocart {a = inj₂ y} refl refl = refl
open Category 𝕊et
unique-closed : ∀{A B E : Set}{a}
-> {e : E × A -> B} {m : E -> (A -> B)}
-> (λ fa → proj₁ fa (proj₂ fa)) ∘ < m ∘ proj₁ , proj₂ > ≡ e
-> (λ b → e (a , b)) ≡ m a
unique-closed refl = refl
| 32.156863
| 88
| 0.386585
|
dc84e610cb9ad064c6efc346c0c7372184093270
| 393
|
agda
|
Agda
|
test/Fail/Issue3289.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue3289.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue3289.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
record R : Set where
field
x : Nat
open R {{...}}
f₁ f₂ : R
-- This is fine.
x ⦃ f₁ ⦄ = 0
-- WAS: THIS WORKS BUT MAKES NO SENSE!!!
f₂ ⦃ .x ⦄ = 0
-- Error:
-- Cannot eliminate type R with pattern ⦃ .x ⦄ (suggestion: write .(x)
-- for a dot pattern, or remove the braces for a postfix projection)
-- when checking the clause left hand side
-- f₂ ⦃ .x ⦄
| 17.086957
| 70
| 0.620865
|
104feb59cdacc31b1c29909fd9684ec8f482b7a4
| 477
|
agda
|
Agda
|
test/Succeed/fol-theorems/NonTopLevelModuleName.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Succeed/fol-theorems/NonTopLevelModuleName.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Succeed/fol-theorems/NonTopLevelModuleName.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
------------------------------------------------------------------------------
-- Testing anonymous module
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- No top-level module
postulate
D : Set
_≡_ : D → D → Set
postulate foo : ∀ t → t ≡ t
{-# ATP prove foo #-}
| 26.5
| 78
| 0.343816
|
58b9053b91a4522262cb0a108653e96e73c69ec2
| 29,321
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Localisation/InvertingElements.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Localisation/InvertingElements.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Localisation/InvertingElements.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
-- In this file we consider the special of localising at a single
-- element f : R (or rather the set of powers of f). This is also
-- known as inverting f.
-- We then prove that localising first at an element f and at an element
-- g (or rather the image g/1) is the same as localising at the product f·g
-- This fact has an important application in algebraic geometry where it's
-- used to define the structure sheaf of a commutative ring.
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Localisation.InvertingElements where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.RadicalIdeal
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
module InvertingElementsBase (R' : CommRing ℓ) where
open isMultClosedSubset
private R = fst R'
open CommRingStr (snd R')
open Exponentiation R'
open RingTheory (CommRing→Ring R')
[_ⁿ|n≥0] : R → ℙ R
[ f ⁿ|n≥0] g = (∃[ n ∈ ℕ ] g ≡ f ^ n) , isPropPropTrunc
-- Σ[ n ∈ ℕ ] (s ≡ f ^ n) × (∀ m → s ≡ f ^ m → n ≤ m) maybe better, this isProp:
-- (n,s≡fⁿ,p) (m,s≡fᵐ,q) then n≤m by p and m≤n by q => n≡m
powersFormMultClosedSubset : (f : R) → isMultClosedSubset R' [ f ⁿ|n≥0]
powersFormMultClosedSubset f .containsOne = PT.∣ zero , refl ∣₁
powersFormMultClosedSubset f .multClosed =
PT.map2 λ (m , p) (n , q) → (m +ℕ n) , (λ i → (p i) · (q i)) ∙ ·-of-^-is-^-of-+ f m n
R[1/_] : R → Type ℓ
R[1/ f ] = Loc.S⁻¹R R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
-- a quick fact
isContrR[1/0] : isContr R[1/ 0r ]
fst isContrR[1/0] = [ 1r , 0r , ∣ 1 , sym (·IdR 0r) ∣₁ ] -- everything is equal to 1/0
snd isContrR[1/0] = elimProp (λ _ → squash/ _ _)
λ _ → eq/ _ _ ((0r , ∣ 1 , sym (·IdR 0r) ∣₁) , useSolver _ _)
where
useSolver : ∀ s r → 0r · 1r · s ≡ 0r · r · 0r
useSolver = solve R'
R[1/_]AsCommRing : R → CommRing ℓ
R[1/ f ]AsCommRing = Loc.S⁻¹RAsCommRing R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
-- A useful lemma: (gⁿ/1)≡(g/1)ⁿ in R[1/f]
^-respects-/1 : {f g : R} (n : ℕ) → [ (g ^ n) , 1r , PT.∣ 0 , (λ _ → 1r) ∣₁ ] ≡
Exponentiation._^_ R[1/ f ]AsCommRing [ g , 1r , powersFormMultClosedSubset _ .containsOne ] n
^-respects-/1 zero = refl
^-respects-/1 {f} {g} (suc n) = eq/ _ _ ( (1r , powersFormMultClosedSubset f .containsOne)
, cong (1r · (g · (g ^ n)) ·_) (·IdL 1r))
∙ cong (CommRingStr._·_ (R[1/ f ]AsCommRing .snd)
[ g , 1r , powersFormMultClosedSubset f .containsOne ]) (^-respects-/1 n)
-- A slight improvement for eliminating into propositions
invElPropElim : {f : R} {P : R[1/ f ] → Type ℓ'}
→ (∀ x → isProp (P x))
→ (∀ (r : R) (n : ℕ) → P [ r , (f ^ n) , PT.∣ n , refl ∣₁ ]) -- ∀ r n → P (r/fⁿ)
----------------------------------------------------------
→ ∀ x → P x
invElPropElim {f = f} {P = P} PisProp base = elimProp (λ _ → PisProp _) []-case
where
S[f] = Loc.S R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
[]-case : (a : R × S[f]) → P [ a ]
[]-case (r , s , s∈S[f]) = PT.rec (PisProp _) Σhelper s∈S[f]
where
Σhelper : Σ[ n ∈ ℕ ] s ≡ f ^ n → P [ r , s , s∈S[f] ]
Σhelper (n , p) = subst P (cong [_] (≡-× refl (Σ≡Prop (λ _ → isPropPropTrunc) (sym p)))) (base r n)
invElPropElim2 : {f g : R} {P : R[1/ f ] → R[1/ g ] → Type ℓ'}
→ (∀ x y → isProp (P x y))
→ (∀ (r s : R) (n : ℕ) → P [ r , (f ^ n) , PT.∣ n , refl ∣₁ ]
[ s , (g ^ n) , PT.∣ n , refl ∣₁ ])
----------------------------------------------------------
→ ∀ x y → P x y
invElPropElim2 {f = f} {g = g} {P = P} PisProp base =
invElPropElim (λ _ → isPropΠ (λ _ → PisProp _ _)) reduce1
where
reduce1 : ∀ (r : R) (n : ℕ) (y : R[1/ g ]) → P [ r , f ^ n , ∣ n , refl ∣₁ ] y
reduce1 r n = invElPropElim (λ _ → PisProp _ _) reduce2
where
reduce2 : (s : R) (m : ℕ) → P [ r , f ^ n , ∣ n , refl ∣₁ ] [ s , g ^ m , ∣ m , refl ∣₁ ]
reduce2 s m = subst2 P p q (base _ _ l)
where
l = max m n
x : R[1/ f ]
x = [ r , f ^ n , ∣ n , refl ∣₁ ]
y : R[1/ g ]
y = [ s , g ^ m , ∣ m , refl ∣₁ ]
x' : R[1/ f ]
x' = [ r · f ^ (l ∸ n) , f ^ l , ∣ l , refl ∣₁ ]
y' : R[1/ g ]
y' = [ s · g ^ (l ∸ m) , g ^ l , ∣ l , refl ∣₁ ]
p : x' ≡ x
p = eq/ _ _ ((1r , ∣ 0 , refl ∣₁) , path)
where
useSolver1 : ∀ a b c → 1r · (a · b) · c ≡ a · (b · c)
useSolver1 = solve R'
useSolver2 : ∀ a b → a · b ≡ 1r · a · b
useSolver2 = solve R'
path : 1r · (r · f ^ (l ∸ n)) · f ^ n ≡ 1r · r · f ^ l
path = 1r · (r · f ^ (l ∸ n)) · f ^ n ≡⟨ useSolver1 _ _ _ ⟩
r · (f ^ (l ∸ n) · f ^ n) ≡⟨ cong (r ·_) (·-of-^-is-^-of-+ _ _ _) ⟩
r · f ^ (l ∸ n +ℕ n) ≡⟨ cong (λ k → r · f ^ k) (≤-∸-+-cancel right-≤-max) ⟩
r · f ^ l ≡⟨ useSolver2 _ _ ⟩
1r · r · f ^ l ∎
q : y' ≡ y
q = eq/ _ _ ((1r , ∣ 0 , refl ∣₁) , path)
where
useSolver1 : ∀ a b c → 1r · (a · b) · c ≡ a · (b · c)
useSolver1 = solve R'
useSolver2 : ∀ a b → a · b ≡ 1r · a · b
useSolver2 = solve R'
path : 1r · (s · g ^ (l ∸ m)) · g ^ m ≡ 1r · s · g ^ l
path = 1r · (s · g ^ (l ∸ m)) · g ^ m ≡⟨ useSolver1 _ _ _ ⟩
s · (g ^ (l ∸ m) · g ^ m) ≡⟨ cong (s ·_) (·-of-^-is-^-of-+ _ _ _) ⟩
s · g ^ (l ∸ m +ℕ m) ≡⟨ cong (λ k → s · g ^ k) (≤-∸-+-cancel left-≤-max) ⟩
s · g ^ l ≡⟨ useSolver2 _ _ ⟩
1r · s · g ^ l ∎
-- For predicates over the set of powers
powersPropElim : {f : R} {P : R → Type ℓ'}
→ (∀ x → isProp (P x))
→ (∀ n → P (f ^ n))
------------------------------
→ ∀ s → s ∈ [ f ⁿ|n≥0] → P s
powersPropElim {f = f} {P = P} PisProp base s =
PT.rec (PisProp s) λ (n , p) → subst P (sym p) (base n)
module RadicalLemma (R' : CommRing ℓ) (f g : (fst R')) where
open IsRingHom
open isMultClosedSubset
open CommRingTheory R'
open RingTheory (CommRing→Ring R')
open CommIdeal R' hiding (subst-∈) renaming (_∈_ to _∈ᵢ_)
open RadicalIdeal R'
open Exponentiation R'
open InvertingElementsBase R'
open S⁻¹RUniversalProp R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
hiding (S⁻¹RHasUniversalProp)
open S⁻¹RUniversalProp R' [ g ⁿ|n≥0] (powersFormMultClosedSubset g)
hiding (_/1 ; /1AsCommRingHom)
open CommRingStr (R' .snd)
private
R = R' .fst
⟨_⟩ : R → CommIdeal
⟨ f ⟩ = ⟨ replicateFinVec 1 f ⟩[ R' ]
unitHelper : f ∈ᵢ √ ⟨ g ⟩ → (g /1) ∈ R[1/ f ]AsCommRing ˣ
unitHelper = PT.rec isPropGoal (uncurry ℕhelper)
where
isPropGoal = Units.inverseUniqueness _ (g /1)
ℕhelper : (n : ℕ) → f ^ n ∈ᵢ ⟨ g ⟩ → (g /1) ∈ R[1/ f ]AsCommRing ˣ
ℕhelper n = PT.rec isPropGoal -- fⁿ≡αg → g⁻¹≡α/fⁿ
λ (α , p) → [ (α zero) , (f ^ n) , ∣ n , refl ∣₁ ]
, eq/ _ _ ((1r , powersFormMultClosedSubset f .containsOne)
, useSolver1 _ _ ∙ sym p ∙ useSolver2 _)
where
useSolver1 : ∀ x y → 1r · (x · y) · 1r ≡ y · x + 0r
useSolver1 = solve R'
useSolver2 : ∀ x → x ≡ 1r · 1r · (1r · x)
useSolver2 = solve R'
toUnit : f ∈ᵢ √ ⟨ g ⟩
→ ∀ s → s ∈ [ g ⁿ|n≥0] → (s /1) ∈ R[1/ f ]AsCommRing ˣ
toUnit f∈√⟨g⟩ = powersPropElim (λ x → Units.inverseUniqueness _ (x /1))
λ n → subst-∈ (R[1/ f ]AsCommRing ˣ) (sym (^-respects-/1 n))
(Exponentiation.^-presUnit _ _ n (unitHelper f∈√⟨g⟩))
module DoubleLoc (R' : CommRing ℓ) (f g : (fst R')) where
open isMultClosedSubset
open CommRingStr (snd R')
open CommRingTheory R'
open Exponentiation R'
open InvertingElementsBase
open RingTheory (CommRing→Ring R')
open CommRingStr (snd (R[1/_]AsCommRing R' f)) renaming ( _·_ to _·ᶠ_ ; 1r to 1ᶠ
; _+_ to _+ᶠ_ ; 0r to 0ᶠ
; ·IdL to ·ᶠ-lid ; ·IdR to ·ᶠ-rid
; ·Assoc to ·ᶠ-assoc ; ·Comm to ·ᶠ-comm)
open IsRingHom
private
R = fst R'
R[1/f] = R[1/_] R' f
R[1/f]AsCommRing = R[1/_]AsCommRing R' f
R[1/fg] = R[1/_] R' (f · g)
R[1/fg]AsCommRing = R[1/_]AsCommRing R' (f · g)
R[1/f][1/g] = R[1/_] (R[1/_]AsCommRing R' f)
[ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
R[1/f][1/g]AsCommRing = R[1/_]AsCommRing (R[1/_]AsCommRing R' f)
[ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
R[1/f][1/g]ˣ = R[1/f][1/g]AsCommRing ˣ
_/1/1 : R → R[1/f][1/g]
r /1/1 = [ [ r , 1r , PT.∣ 0 , refl ∣₁ ] , 1ᶠ , PT.∣ 0 , refl ∣₁ ]
/1/1AsCommRingHom : CommRingHom R' R[1/f][1/g]AsCommRing
fst /1/1AsCommRingHom = _/1/1
snd /1/1AsCommRingHom = makeIsRingHom refl lem+ lem·
where
lem+ : _
lem+ r r' =
cong [_]
(≡-×
(cong [_]
(≡-×
(cong₂ _+_
(sym (·IdR _) ∙ (λ i → (·IdR r (~ i)) · (·IdR 1r (~ i))))
(sym (·IdR _) ∙ (λ i → (·IdR r' (~ i)) · (·IdR 1r (~ i)))))
(Σ≡Prop (λ _ → isPropPropTrunc)
(sym (·IdL _) ∙ (λ i → (·IdL 1r (~ i)) · (·IdL 1r (~ i)))))))
(Σ≡Prop (λ _ → isPropPropTrunc) (sym (·ᶠ-lid 1ᶠ))))
lem· : _
lem· r r' =
cong [_]
(≡-×
(cong [_] (≡-× refl (Σ≡Prop (λ _ → isPropPropTrunc) (sym (·IdL _)))))
(Σ≡Prop (λ _ → isPropPropTrunc) (sym (·ᶠ-lid 1ᶠ))))
-- this will give us a map R[1/fg] → R[1/f][1/g] by the universal property of localisation
fⁿgⁿ/1/1∈R[1/f][1/g]ˣ : (s : R) → s ∈ ([_ⁿ|n≥0] R' (f · g)) → s /1/1 ∈ R[1/f][1/g]ˣ
fⁿgⁿ/1/1∈R[1/f][1/g]ˣ = powersPropElim R' (λ s → R[1/f][1/g]ˣ (s /1/1) .snd) ℕcase
where
ℕcase : (n : ℕ) → ((f · g) ^ n) /1/1 ∈ R[1/f][1/g]ˣ
ℕcase n = [ [ 1r , (f ^ n) , PT.∣ n , refl ∣₁ ]
, [ (g ^ n) , 1r , PT.∣ 0 , refl ∣₁ ] --denominator
, PT.∣ n , ^-respects-/1 _ n ∣₁ ]
, eq/ _ _ ((1ᶠ , powersFormMultClosedSubset _ _ .containsOne)
, eq/ _ _ ((1r , powersFormMultClosedSubset _ _ .containsOne) , path))
where
eq1 : ∀ x → 1r · (1r · (x · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡ x
eq1 = solve R'
eq2 : ∀ x y → x · y ≡ 1r · (1r · 1r · (1r · y)) · (1r · (1r · x) · 1r)
eq2 = solve R'
path : 1r · (1r · ((f · g) ^ n · 1r) · 1r) · (1r · 1r · (1r · 1r))
≡ 1r · (1r · 1r · (1r · g ^ n)) · (1r · (1r · f ^ n) · 1r)
path = 1r · (1r · ((f · g) ^ n · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡⟨ eq1 ((f · g) ^ n) ⟩
(f · g) ^ n ≡⟨ ^-ldist-· _ _ _ ⟩
f ^ n · g ^ n ≡⟨ eq2 (f ^ n) (g ^ n) ⟩
1r · (1r · 1r · (1r · g ^ n)) · (1r · (1r · f ^ n) · 1r) ∎
open PathToS⁻¹R
pathtoR[1/fg] : PathToS⁻¹R R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
R[1/f][1/g]AsCommRing /1/1AsCommRingHom
φS⊆Aˣ pathtoR[1/fg] = fⁿgⁿ/1/1∈R[1/f][1/g]ˣ
kerφ⊆annS pathtoR[1/fg] r p = toGoal helperR[1/f]
where
open RingTheory (CommRing→Ring R[1/f]AsCommRing) renaming ( 0RightAnnihilates to 0ᶠRightAnnihilates
; 0LeftAnnihilates to 0ᶠ-leftNullifies)
open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^ᶠ_)
hiding (·-of-^-is-^-of-+ ; ^-ldist-·)
S[f] = Loc.S R' ([_ⁿ|n≥0] R' f) (powersFormMultClosedSubset R' f)
S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
g/1 : R[1/_] R' f
g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
S[g/1] = Loc.S R[1/f]AsCommRing
([_ⁿ|n≥0] R[1/f]AsCommRing g/1)
(powersFormMultClosedSubset R[1/f]AsCommRing g/1)
r/1 : R[1/_] R' f
r/1 = [ r , 1r , powersFormMultClosedSubset R' f .containsOne ]
-- this is the crucial step, modulo truncation we can take p to be generated
-- by the quotienting relation of localisation. Note that we wouldn't be able
-- to prove our goal if kerφ⊆annS was formulated with a Σ instead of a ∃
∥r/1,1/1≈0/1,1/1∥ : ∃[ u ∈ S[g/1] ] fst u ·ᶠ r/1 ·ᶠ 1ᶠ ≡ fst u ·ᶠ 0ᶠ ·ᶠ 1ᶠ
∥r/1,1/1≈0/1,1/1∥ = Iso.fun (SQ.isEquivRel→TruncIso (Loc.locIsEquivRel _ _ _) _ _) p
helperR[1/f] : ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣₁ ] ≡ 0ᶠ
helperR[1/f] = PT.rec isPropPropTrunc
(uncurry (uncurry (powersPropElim R[1/f]AsCommRing
(λ _ → isPropΠ (λ _ → isPropPropTrunc)) baseCase)))
∥r/1,1/1≈0/1,1/1∥
where
baseCase : ∀ n → g/1 ^ᶠ n ·ᶠ r/1 ·ᶠ 1ᶠ ≡ g/1 ^ᶠ n ·ᶠ 0ᶠ ·ᶠ 1ᶠ
→ ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣₁ ] ≡ 0ᶠ
baseCase n q = PT.∣ n , path ∣₁
where
path : [ g ^ n · r , 1r , PT.∣ 0 , refl ∣₁ ] ≡ 0ᶠ
path = [ g ^ n · r , 1r , PT.∣ 0 , refl ∣₁ ]
≡⟨ cong [_] (≡-× refl (Σ≡Prop (λ _ → isPropPropTrunc) (sym (·IdR _)))) ⟩
[ g ^ n , 1r , PT.∣ 0 , refl ∣₁ ] ·ᶠ r/1
≡⟨ cong (_·ᶠ r/1) (^-respects-/1 _ n) ⟩
g/1 ^ᶠ n ·ᶠ r/1
≡⟨ sym (·ᶠ-rid _) ⟩
g/1 ^ᶠ n ·ᶠ r/1 ·ᶠ 1ᶠ
≡⟨ q ⟩
g/1 ^ᶠ n ·ᶠ 0ᶠ ·ᶠ 1ᶠ
≡⟨ cong (_·ᶠ 1ᶠ) (0ᶠRightAnnihilates _) ∙ 0ᶠ-leftNullifies 1ᶠ ⟩
0ᶠ ∎
toGoal : ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣₁ ] ≡ 0ᶠ
→ ∃[ u ∈ S[fg] ] fst u · r ≡ 0r
toGoal = PT.rec isPropPropTrunc Σhelper
where
Σhelper : Σ[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣₁ ] ≡ 0ᶠ
→ ∃[ u ∈ S[fg] ] fst u · r ≡ 0r
Σhelper (n , q) = PT.map Σhelper2 helperR
where
-- now, repeat the above strategy with q
∥gⁿr≈0∥ : ∃[ u ∈ S[f] ] fst u · (g ^ n · r) · 1r ≡ fst u · 0r · 1r
∥gⁿr≈0∥ = Iso.fun (SQ.isEquivRel→TruncIso (Loc.locIsEquivRel _ _ _) _ _) q
helperR : ∃[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r
helperR = PT.rec isPropPropTrunc
(uncurry (uncurry (powersPropElim R'
(λ _ → isPropΠ (λ _ → isPropPropTrunc)) baseCase)))
∥gⁿr≈0∥
where
baseCase : (m : ℕ) → f ^ m · (g ^ n · r) · 1r ≡ f ^ m · 0r · 1r
→ ∃[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r
baseCase m q' = PT.∣ m , path ∣₁
where
path : f ^ m · g ^ n · r ≡ 0r
path = (λ i → ·IdR (·Assoc (f ^ m) (g ^ n) r (~ i)) (~ i))
∙∙ q' ∙∙ (λ i → ·IdR (0RightAnnihilates (f ^ m) i) i)
Σhelper2 : Σ[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r
→ Σ[ u ∈ S[fg] ] fst u · r ≡ 0r
Σhelper2 (m , q') = (((f · g) ^ l) , PT.∣ l , refl ∣₁) , path
where
l = max m n
path : (f · g) ^ l · r ≡ 0r
path = (f · g) ^ l · r
≡⟨ cong (_· r) (^-ldist-· _ _ _) ⟩
f ^ l · g ^ l · r
≡⟨ cong₂ (λ x y → f ^ x · g ^ y · r) (sym (≤-∸-+-cancel {m = m} left-≤-max))
(sym (≤-∸-+-cancel {m = n} right-≤-max)) ⟩
f ^ (l ∸ m +ℕ m) · g ^ (l ∸ n +ℕ n) · r
≡⟨ cong₂ (λ x y → x · y · r) (sym (·-of-^-is-^-of-+ _ _ _))
(sym (·-of-^-is-^-of-+ _ _ _)) ⟩
f ^ (l ∸ m) · f ^ m · (g ^ (l ∸ n) · g ^ n) · r
≡⟨ cong (_· r) (·CommAssocSwap _ _ _ _) ⟩
f ^ (l ∸ m) · g ^ (l ∸ n) · (f ^ m · g ^ n) · r
≡⟨ sym (·Assoc _ _ _) ⟩
f ^ (l ∸ m) · g ^ (l ∸ n) · (f ^ m · g ^ n · r)
≡⟨ cong (f ^ (l ∸ m) · g ^ (l ∸ n) ·_) q' ⟩
f ^ (l ∸ m) · g ^ (l ∸ n) · 0r
≡⟨ 0RightAnnihilates _ ⟩
0r ∎
surχ pathtoR[1/fg] = invElPropElim _ (λ _ → isPropPropTrunc) toGoal
where
open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^ᶠ_)
hiding (·-of-^-is-^-of-+ ; ^-ldist-·)
open CommRingStr (snd R[1/f][1/g]AsCommRing) renaming (_·_ to _·R[1/f][1/g]_)
hiding (1r ; ·IdL ; ·IdR ; ·Assoc)
open Units R[1/f][1/g]AsCommRing
g/1 : R[1/_] R' f
g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
baseCase : (r : R) (m n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1)
≡ [ [ r , f ^ m , PT.∣ m , refl ∣₁ ]
, [ g ^ n , 1r , PT.∣ 0 , refl ∣₁ ] , PT.∣ n , ^-respects-/1 _ n ∣₁ ]
·R[1/f][1/g] (x .snd .fst /1/1)
baseCase r m n = PT.∣ ((r · f ^ (l ∸ m) · g ^ (l ∸ n)) -- x .fst
, (f · g) ^ l , PT.∣ l , refl ∣₁) -- x .snd
, eq/ _ _ ((1ᶠ , PT.∣ 0 , refl ∣₁) , eq/ _ _ ((1r , PT.∣ 0 , refl ∣₁) , path)) ∣₁
-- reduce equality of double fractions into equality in R
where
eq1 : ∀ r flm gln gn fm
→ 1r · (1r · (r · flm · gln) · (gn · 1r)) · (1r · (fm · 1r) · 1r)
≡ r · flm · (gln · gn) · fm
eq1 = solve R'
eq2 : ∀ r flm gl fm → r · flm · gl · fm ≡ r · (flm · fm ) · gl
eq2 = solve R'
eq3 : ∀ r fgl → r · fgl ≡ 1r · (1r · (r · fgl) · 1r) · (1r · 1r · (1r · 1r))
eq3 = solve R'
l = max m n
path : 1r · (1r · (r · f ^ (l ∸ m) · g ^ (l ∸ n)) · (g ^ n · 1r)) · (1r · (f ^ m · 1r) · 1r)
≡ 1r · (1r · (r · (f · g) ^ l) · 1r) · (1r · 1r · (1r · 1r))
path = 1r · (1r · (r · f ^ (l ∸ m) · g ^ (l ∸ n)) · (g ^ n · 1r)) · (1r · (f ^ m · 1r) · 1r)
≡⟨ eq1 r (f ^ (l ∸ m)) (g ^ (l ∸ n)) (g ^ n) (f ^ m) ⟩
r · f ^ (l ∸ m) · (g ^ (l ∸ n) · g ^ n) · f ^ m
≡⟨ cong (λ x → r · f ^ (l ∸ m) · x · f ^ m) (·-of-^-is-^-of-+ _ _ _) ⟩
r · f ^ (l ∸ m) · g ^ (l ∸ n +ℕ n) · f ^ m
≡⟨ cong (λ x → r · f ^ (l ∸ m) · g ^ x · f ^ m) (≤-∸-+-cancel right-≤-max) ⟩
r · f ^ (l ∸ m) · g ^ l · f ^ m
≡⟨ eq2 r (f ^ (l ∸ m)) (g ^ l) (f ^ m) ⟩
r · (f ^ (l ∸ m) · f ^ m) · g ^ l
≡⟨ cong (λ x → r · x · g ^ l) (·-of-^-is-^-of-+ _ _ _) ⟩
r · f ^ (l ∸ m +ℕ m) · g ^ l
≡⟨ cong (λ x → r · f ^ x · g ^ l) (≤-∸-+-cancel left-≤-max) ⟩
r · f ^ l · g ^ l
≡⟨ sym (·Assoc _ _ _) ⟩
r · (f ^ l · g ^ l)
≡⟨ cong (r ·_) (sym (^-ldist-· _ _ _)) ⟩
r · (f · g) ^ l
≡⟨ eq3 r ((f · g) ^ l) ⟩
1r · (1r · (r · (f · g) ^ l) · 1r) · (1r · 1r · (1r · 1r)) ∎
base-^ᶠ-helper : (r : R) (m n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1)
≡ [ [ r , f ^ m , PT.∣ m , refl ∣₁ ]
, g/1 ^ᶠ n , PT.∣ n , refl ∣₁ ] ·R[1/f][1/g] (x .snd .fst /1/1)
base-^ᶠ-helper r m n = subst (λ y → ∃[ x ∈ R × S[fg] ] (x .fst /1/1)
≡ [ [ r , f ^ m , PT.∣ m , refl ∣₁ ] , y ] ·R[1/f][1/g] (x .snd .fst /1/1))
(Σ≡Prop (λ _ → isPropPropTrunc) (^-respects-/1 _ n)) (baseCase r m n)
indStep : (r : R[1/_] R' f) (n : ℕ) → ∃[ x ∈ R × S[fg] ]
(x .fst /1/1) ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣₁ ] ·R[1/f][1/g] (x .snd .fst /1/1)
indStep = invElPropElim _ (λ _ → isPropΠ λ _ → isPropPropTrunc) base-^ᶠ-helper
toGoal : (r : R[1/_] R' f) (n : ℕ) → ∃[ x ∈ R × S[fg] ]
(x .fst /1/1) ·R[1/f][1/g]
((x .snd .fst /1/1) ⁻¹) ⦃ φS⊆Aˣ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) ⦄
≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣₁ ]
toGoal r n = PT.map Σhelper (indStep r n)
where
Σhelper : Σ[ x ∈ R × S[fg] ]
(x .fst /1/1) ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣₁ ] ·R[1/f][1/g] (x .snd .fst /1/1)
→ Σ[ x ∈ R × S[fg] ]
(x .fst /1/1) ·R[1/f][1/g] ((x .snd .fst /1/1) ⁻¹)
⦃ φS⊆Aˣ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) ⦄
≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣₁ ]
Σhelper ((r' , s , s∈S[fg]) , p) = (r' , s , s∈S[fg])
, ⁻¹-eq-elim ⦃ φS⊆Aˣ pathtoR[1/fg] s s∈S[fg] ⦄ p
-- the main result: localising at one element and then at another is
-- the same as localising at the product.
-- takes forever to compute without experimental lossy unification
R[1/fg]≡R[1/f][1/g] : R[1/fg]AsCommRing ≡ R[1/f][1/g]AsCommRing
R[1/fg]≡R[1/f][1/g] = S⁻¹RChar R' ([_ⁿ|n≥0] R' (f · g))
(powersFormMultClosedSubset R' (f · g)) _ /1/1AsCommRingHom pathtoR[1/fg]
-- In this module we construct the map R[1/fg]→R[1/f][1/g] directly
-- and show that it is equal (although not judgementally) to the map induced
-- by the universal property of localisation, i.e. transporting along the path
-- constructed above. Given that this is the easier direction, we can see that
-- it is pretty cumbersome to prove R[1/fg]≡R[1/f][1/g] directly,
-- which illustrates the usefulness of S⁻¹RChar quite well.
private
module check where
φ : R[1/fg] → R[1/f][1/g]
φ = SQ.rec squash/ ϕ ϕcoh
where
S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
curriedϕΣ : (r s : R) → Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n → R[1/f][1/g]
curriedϕΣ r s (n , s≡fg^n) = [ [ r , (f ^ n) , PT.∣ n , refl ∣₁ ]
, [ (g ^ n) , 1r , PT.∣ 0 , refl ∣₁ ] --denominator
, PT.∣ n , ^-respects-/1 R' n ∣₁ ]
curriedϕ : (r s : R) → ∃[ n ∈ ℕ ] s ≡ (f · g) ^ n → R[1/f][1/g]
curriedϕ r s = elim→Set (λ _ → squash/) (curriedϕΣ r s) coh
where
coh : (x y : Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n) → curriedϕΣ r s x ≡ curriedϕΣ r s y
coh (n , s≡fg^n) (m , s≡fg^m) = eq/ _ _ ((1ᶠ , PT.∣ 0 , refl ∣₁) ,
eq/ _ _ ( (1r , powersFormMultClosedSubset R' f .containsOne)
, path))
where
eq1 : ∀ r gm fm → 1r · (1r · r · gm) · (1r · fm · 1r) ≡ r · (gm · fm)
eq1 = solve R'
path : 1r · (1r · r · (g ^ m)) · (1r · (f ^ m) · 1r)
≡ 1r · (1r · r · (g ^ n)) · (1r · (f ^ n) · 1r)
path = 1r · (1r · r · (g ^ m)) · (1r · (f ^ m) · 1r)
≡⟨ eq1 r (g ^ m) (f ^ m) ⟩
r · (g ^ m · f ^ m)
≡⟨ cong (r ·_) (sym (^-ldist-· g f m)) ⟩
r · ((g · f) ^ m)
≡⟨ cong (λ x → r · (x ^ m)) (·Comm _ _) ⟩
r · ((f · g) ^ m)
≡⟨ cong (r ·_) ((sym s≡fg^m) ∙ s≡fg^n) ⟩
r · ((f · g) ^ n)
≡⟨ cong (λ x → r · (x ^ n)) (·Comm _ _) ⟩
r · ((g · f) ^ n)
≡⟨ cong (r ·_) (^-ldist-· g f n) ⟩
r · (g ^ n · f ^ n)
≡⟨ sym (eq1 r (g ^ n) (f ^ n)) ⟩
1r · (1r · r · (g ^ n)) · (1r · (f ^ n) · 1r) ∎
ϕ : R × S[fg] → R[1/f][1/g]
ϕ = uncurry2 curriedϕ -- λ (r / (fg)ⁿ) → ((r / fⁿ) / gⁿ)
curriedϕcohΣ : (r s r' s' u : R) → (p : u · r · s' ≡ u · r' · s)
→ (α : Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n)
→ (β : Σ[ m ∈ ℕ ] s' ≡ (f · g) ^ m)
→ (γ : Σ[ l ∈ ℕ ] u ≡ (f · g) ^ l)
→ ϕ (r , s , PT.∣ α ∣₁) ≡ ϕ (r' , s' , PT.∣ β ∣₁)
curriedϕcohΣ r s r' s' u p (n , s≡fgⁿ) (m , s'≡fgᵐ) (l , u≡fgˡ) =
eq/ _ _ ( ( [ (g ^ l) , 1r , powersFormMultClosedSubset R' f .containsOne ]
, PT.∣ l , ^-respects-/1 R' l ∣₁)
, eq/ _ _ ((f ^ l , PT.∣ l , refl ∣₁) , path))
where
eq1 : ∀ fl gl r gm fm
→ fl · (gl · r · gm) · (1r · fm · 1r) ≡ fl · gl · r · (gm · fm)
eq1 = solve R'
path : f ^ l · (g ^ l · transp (λ i → R) i0 r · transp (λ i → R) i0 (g ^ m))
· (1r · transp (λ i → R) i0 (f ^ m) · transp (λ i → R) i0 1r)
≡ f ^ l · (g ^ l · transp (λ i → R) i0 r' · transp (λ i → R) i0 (g ^ n))
· (1r · transp (λ i → R) i0 (f ^ n) · transp (λ i → R) i0 1r)
path = f ^ l · (g ^ l · transp (λ i → R) i0 r · transp (λ i → R) i0 (g ^ m))
· (1r · transp (λ i → R) i0 (f ^ m) · transp (λ i → R) i0 1r)
≡⟨ (λ i → f ^ l · (g ^ l · transportRefl r i · transportRefl (g ^ m) i)
· (1r · transportRefl (f ^ m) i · transportRefl 1r i)) ⟩
f ^ l · (g ^ l · r · g ^ m) · (1r · f ^ m · 1r)
≡⟨ eq1 (f ^ l) (g ^ l) r (g ^ m) (f ^ m) ⟩
f ^ l · g ^ l · r · (g ^ m · f ^ m)
≡⟨ (λ i → ^-ldist-· f g l (~ i) · r · ^-ldist-· g f m (~ i)) ⟩
(f · g) ^ l · r · (g · f) ^ m
≡⟨ cong (λ x → (f · g) ^ l · r · x ^ m) (·Comm _ _) ⟩
(f · g) ^ l · r · (f · g) ^ m
≡⟨ (λ i → u≡fgˡ (~ i) · r · s'≡fgᵐ (~ i)) ⟩
u · r · s'
≡⟨ p ⟩
u · r' · s
≡⟨ (λ i → u≡fgˡ i · r' · s≡fgⁿ i) ⟩
(f · g) ^ l · r' · (f · g) ^ n
≡⟨ cong (λ x → (f · g) ^ l · r' · x ^ n) (·Comm _ _) ⟩
(f · g) ^ l · r' · (g · f) ^ n
≡⟨ (λ i → ^-ldist-· f g l i · r' · ^-ldist-· g f n i) ⟩
f ^ l · g ^ l · r' · (g ^ n · f ^ n)
≡⟨ sym (eq1 (f ^ l) (g ^ l) r' (g ^ n) (f ^ n)) ⟩
f ^ l · (g ^ l · r' · g ^ n) · (1r · f ^ n · 1r)
≡⟨ (λ i → f ^ l · (g ^ l · transportRefl r' (~ i) · transportRefl (g ^ n) (~ i))
· (1r · transportRefl (f ^ n) (~ i) · transportRefl 1r (~ i))) ⟩
f ^ l · (g ^ l · transp (λ i → R) i0 r' · transp (λ i → R) i0 (g ^ n))
· (1r · transp (λ i → R) i0 (f ^ n) · transp (λ i → R) i0 1r) ∎
curriedϕcoh : (r s r' s' u : R) → (p : u · r · s' ≡ u · r' · s)
→ (α : ∃[ n ∈ ℕ ] s ≡ (f · g) ^ n)
→ (β : ∃[ m ∈ ℕ ] s' ≡ (f · g) ^ m)
→ (γ : ∃[ l ∈ ℕ ] u ≡ (f · g) ^ l)
→ ϕ (r , s , α) ≡ ϕ (r' , s' , β)
curriedϕcoh r s r' s' u p = PT.elim (λ _ → isPropΠ2 (λ _ _ → squash/ _ _))
λ α → PT.elim (λ _ → isPropΠ (λ _ → squash/ _ _))
λ β → PT.rec (squash/ _ _)
λ γ → curriedϕcohΣ r s r' s' u p α β γ
ϕcoh : (a b : R × S[fg])
→ Loc._≈_ R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) a b
→ ϕ a ≡ ϕ b
ϕcoh (r , s , α) (r' , s' , β) ((u , γ) , p) = curriedϕcoh r s r' s' u p α β γ
-- the map induced by the universal property
open S⁻¹RUniversalProp R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
χ : R[1/fg] → R[1/f][1/g]
χ = S⁻¹RHasUniversalProp R[1/f][1/g]AsCommRing /1/1AsCommRingHom fⁿgⁿ/1/1∈R[1/f][1/g]ˣ .fst .fst .fst
-- the sanity check:
-- both maps send a fraction r/(fg)ⁿ to a double fraction,
-- where numerator and denominator are almost the same fraction respectively.
-- unfortunately the proofs that the denominators are powers are quite different for
-- the two maps, but of course we can ignore them.
-- The definition of χ introduces a lot of (1r ·_). Perhaps most surprisingly,
-- we have to give the path eq1 for the equality of the numerator of the numerator.
φ≡χ : ∀ r → φ r ≡ χ r
φ≡χ = invElPropElim _ (λ _ → squash/ _ _) ℕcase
where
ℕcase : (r : R) (n : ℕ)
→ φ [ r , (f · g) ^ n , PT.∣ n , refl ∣₁ ] ≡ χ [ r , (f · g) ^ n , PT.∣ n , refl ∣₁ ]
ℕcase r n = cong [_] (ΣPathP --look into the components of the double-fractions
( cong [_] (ΣPathP (eq1 , Σ≡Prop (λ x → S'[f] x .snd) (sym (·IdL _))))
, Σ≡Prop (λ x → S'[f][g] x .snd) --ignore proof that denominator is power of g/1
( cong [_] (ΣPathP (sym (·IdL _) , Σ≡Prop (λ x → S'[f] x .snd) (sym (·IdL _)))))))
where
S'[f] = ([_ⁿ|n≥0] R' f)
S'[f][g] = ([_ⁿ|n≥0] R[1/f]AsCommRing [ g , 1r , powersFormMultClosedSubset R' f .containsOne ])
eq1 : transp (λ i → fst R') i0 r ≡ r · transp (λ i → fst R') i0 1r
eq1 = transportRefl r ∙∙ sym (·IdR r) ∙∙ cong (r ·_) (sym (transportRefl 1r))
| 40.78025
| 104
| 0.442754
|
41aded02493931cc30dcbfac387ad894a7d6a1a2
| 224
|
agda
|
Agda
|
test/Succeed/Issue2641.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2641.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2641.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.FromNat
open import Agda.Builtin.Unit
instance
NumberNat : Number Nat
Number.Constraint NumberNat _ = ⊤
fromNat {{NumberNat}} n = n
open import Issue2641.Import
| 18.666667
| 35
| 0.767857
|
fbcbec8852ad905a798640ae00a0299b4d40225a
| 6,905
|
agda
|
Agda
|
core/lib/groups/HomotopyGroup.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/groups/HomotopyGroup.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/groups/HomotopyGroup.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Empty
open import lib.types.Group
open import lib.types.LoopSpace
open import lib.types.Nat
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.TLevel
open import lib.types.Truncation
open import lib.groups.GroupProduct
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
open import lib.groups.LoopSpace
open import lib.groups.TruncationGroup
open import lib.groups.Unit
module lib.groups.HomotopyGroup where
{- Higher homotopy groups -}
module _ {i} where
πS : (n : ℕ) (X : Ptd i) → Group i
πS n X = Trunc-group (Ω^S-group-structure n X)
π'S : (n : ℕ) (X : Ptd i) → Group i
π'S n X = Trunc-group (Ω^'S-group-structure n X)
fundamental-group : (X : Ptd i) → Group i
fundamental-group X = πS 0 X
module _ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} where
πS-fmap : X ⊙→ Y → (πS n X →ᴳ πS n Y)
πS-fmap F = Trunc-group-fmap (Ω^S-group-structure-fmap n F)
π'S-fmap : X ⊙→ Y → (π'S n X →ᴳ π'S n Y)
π'S-fmap F = Trunc-group-fmap (Ω^'S-group-structure-fmap n F)
πS-emap : (X ⊙≃ Y) → (πS n X ≃ᴳ πS n Y)
πS-emap e = Trunc-group-emap (Ω^S-group-structure-emap n e)
π'S-emap : (X ⊙≃ Y) → (π'S n X ≃ᴳ π'S n Y)
π'S-emap e = Trunc-group-emap (Ω^'S-group-structure-emap n e)
{- π_(n+1) of a space is π_n of its loop space -}
abstract
πS-Ω-split-iso : ∀ {i} (n : ℕ) (X : Ptd i)
→ πS (S n) X ≃ᴳ πS n (⊙Ω X)
πS-Ω-split-iso n X =
group-hom
(Trunc-fmap (Ω^-Ω-split (S n) X))
(Trunc-elim
(λ p → Trunc-elim
(λ q → ap [_] (Ω^S-Ω-split-∙ n X p q)))) ,
Trunc-isemap {n = 0} (Ω^-Ω-split-is-equiv (S n) X)
{- We can shift the truncation inside the loop in the definition of π -}
module _ {i} where
private
record Ω^STruncPreIso (n : ℕ) (m : ℕ₋₂) (k : ℕ₋₂) (X : Ptd i)
: Type i where
field
F : ⊙Ω^ (S n) (⊙Trunc k X) ⊙→ ⊙Trunc m (⊙Ω^ (S n) X)
pres-comp : ∀ (p q : Ω^ (S n) (⊙Trunc k X))
→ fst F (Ω^S-∙ n p q) == Trunc-fmap2 (Ω^S-∙ n) (fst F p) (fst F q)
e : is-equiv (fst F)
Ω^S-Trunc-preiso : (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ Ω^STruncPreIso n m (⟨ S n ⟩₋₂ +2+ m) X
Ω^S-Trunc-preiso O m X =
record { F = ⊙–> (⊙Ω-⊙Trunc-comm m X);
pres-comp = –>-=ₜ-equiv-pres-∙;
e = snd (⊙Ω-⊙Trunc-comm m X) }
Ω^S-Trunc-preiso (S n) m X =
let
r : Ω^STruncPreIso n (S m) (⟨ S n ⟩₋₂ +2+ S m) X
r = Ω^S-Trunc-preiso n (S m) X
H = ⊙–> (⊙Ω-⊙Trunc-comm m (⊙Ω^ (S n) X))
G = ⊙Ω-fmap (Ω^STruncPreIso.F r)
in
transport (λ k → Ω^STruncPreIso (S n) m k X)
(+2+-βr ⟨ S n ⟩₋₂ m)
(record {
F = H ⊙∘ G;
pres-comp = λ p q →
ap (fst H) (Ω^S-fmap-∙ 0 (Ω^STruncPreIso.F r) p q)
∙ (–>-=ₜ-equiv-pres-∙ (fst G p) (fst G q));
e = snd (⊙≃-to-≃ (⊙Ω-⊙Trunc-comm m (⊙Ω^ (S n) X))
∘e Ω^-emap 1 (Ω^STruncPreIso.F r , Ω^STruncPreIso.e r))})
Ω^S-group-Trunc-fuse-diag-iso : (n : ℕ) (X : Ptd i)
→ Ω^S-group n (⊙Trunc ⟨ S n ⟩ X) ≃ᴳ πS n X
Ω^S-group-Trunc-fuse-diag-iso n X = group-hom (fst F) pres-comp , e
where
r = transport (λ k → Ω^STruncPreIso n 0 k X)
(+2+0 ⟨ S n ⟩₋₂) (Ω^S-Trunc-preiso n 0 X)
open Ω^STruncPreIso r
{- favonia: the same lemma for the alternative homotopy groups is trivial. -}
Ω^'S-group-Trunc-fuse-diag-iso : (n : ℕ) (X : Ptd i)
→ Ω^'S-group n (⊙Trunc ⟨ S n ⟩ X) ≃ᴳ π'S n X
Ω^'S-group-Trunc-fuse-diag-iso O X =
≃-to-≃ᴳ (=ₜ-equiv [ pt X ] [ pt X ]) –>-=ₜ-equiv-pres-∙
Ω^'S-group-Trunc-fuse-diag-iso (S n) X =
Ω^'S-group-Trunc-fuse-diag-iso n (⊙Ω X)
∘eᴳ Ω^'S-group-emap n {X = ⊙Ω (⊙Trunc ⟨ S (S n) ⟩ X)} (≃-to-⊙≃ (=ₜ-equiv [ pt X ] [ pt X ]) idp)
abstract
πS-Trunc-fuse-≤-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (⟨ S n ⟩ ≤T m) → πS n (⊙Trunc m X) ≃ᴳ πS n X
πS-Trunc-fuse-≤-iso n m X Sn≤m =
πS n (⊙Trunc m X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ Ω^S-group-emap n (≃-to-⊙≃ (Trunc-fuse-≤ (de⊙ X) Sn≤m) idp) ⟩
Ω^S-group n (⊙Trunc ⟨ S n ⟩ X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso n X ⟩
πS n X
≃ᴳ∎
π'S-Trunc-fuse-≤-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (⟨ S n ⟩ ≤T m) → π'S n (⊙Trunc m X) ≃ᴳ π'S n X
π'S-Trunc-fuse-≤-iso n m X Sn≤m =
π'S n (⊙Trunc m X)
≃ᴳ⟨ Ω^'S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^'S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ Ω^'S-group-emap n (≃-to-⊙≃ (Trunc-fuse-≤ (de⊙ X) Sn≤m) idp) ⟩
Ω^'S-group n (⊙Trunc ⟨ S n ⟩ X)
≃ᴳ⟨ Ω^'S-group-Trunc-fuse-diag-iso n X ⟩
π'S n X
≃ᴳ∎
πS-Trunc-fuse->-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → πS n (⊙Trunc m X) ≃ᴳ 0ᴳ
πS-Trunc-fuse->-iso n m X m<n =
πS n (⊙Trunc m X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ contr-iso-0ᴳ _ $ inhab-prop-is-contr
(Group.ident (Ω^S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))))
{{Ω^-level -1 (S n) _ $ Trunc-preserves-level ⟨ S n ⟩ $
raise-level-≤T
(transport (λ k → m ≤T k) (+2+-comm -1 ⟨ S n ⟩₋₂) (<T-to-≤T m<n))
(Trunc-level {n = m})}} ⟩
0ᴳ ≃ᴳ∎
π'S-Trunc-fuse->-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → π'S n (⊙Trunc m X) ≃ᴳ 0ᴳ
π'S-Trunc-fuse->-iso n m X m<n =
π'S n (⊙Trunc m X)
≃ᴳ⟨ Ω^'S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^'S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ contr-iso-0ᴳ _ $ inhab-prop-is-contr
(Group.ident (Ω^'S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))))
{{Ω^'-is-prop (S n) _ $ Trunc-preserves-level ⟨ S n ⟩ $
raise-level-≤T (<T-to-≤T m<n) (Trunc-level {n = m})}} ⟩
0ᴳ ≃ᴳ∎
-- XXX Naming conventions?
πS->level-econv : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → {{_ : has-level m (de⊙ X)}}
→ πS n X ≃ᴳ 0ᴳ
πS->level-econv n m X lt =
πS n X
≃ᴳ⟨ πS-emap n (⊙unTrunc-equiv X ⊙⁻¹) ⟩
πS n (⊙Trunc m X)
≃ᴳ⟨ πS-Trunc-fuse->-iso n m X lt ⟩
0ᴳ
≃ᴳ∎
π'S->level-econv : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → {{_ : has-level m (de⊙ X)}}
→ π'S n X ≃ᴳ 0ᴳ
π'S->level-econv n m X lt =
π'S n X
≃ᴳ⟨ π'S-emap n (⊙unTrunc-equiv X ⊙⁻¹) ⟩
π'S n (⊙Trunc m X)
≃ᴳ⟨ π'S-Trunc-fuse->-iso n m X lt ⟩
0ᴳ
≃ᴳ∎
{- πₙ(X × Y) == πₙ(X) × πₙ(Y) -}
module _ {i j} (n : ℕ) (X : Ptd i) (Y : Ptd j) where
πS-× : πS n (X ⊙× Y) ≃ᴳ πS n X ×ᴳ πS n Y
πS-× = Trunc-group-× _ _ ∘eᴳ Trunc-group-emap (Ω^S-group-structure-× n X Y)
π'S-× : π'S n (X ⊙× Y) ≃ᴳ π'S n X ×ᴳ π'S n Y
π'S-× = Trunc-group-× _ _ ∘eᴳ Trunc-group-emap (Ω^'S-group-structure-× n X Y)
| 35.050761
| 100
| 0.5063
|
22b7d4360a8e93b7eb8b78d9f7ba633d0aaa7001
| 186
|
agda
|
Agda
|
test/interaction/Issue3441.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3441.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3441.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Primitive
f : ∀ {a b c} → Set a → Set b → Set c → Set {!!} -- WAS solution: (a ⊔ (b ⊔ c))
f A B C = A → B → C -- NOW: (a ⊔ b ⊔ c)
| 37.2
| 79
| 0.370968
|
1a6cce7713a3d1d7868e382fc1e035b832c6f6ca
| 247
|
agda
|
Agda
|
Cubical/Algebra/Ring.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Ring where
open import Cubical.Algebra.Ring.Base public
open import Cubical.Algebra.Ring.Properties public
open import Cubical.Algebra.Ring.Ideal public
open import Cubical.Algebra.Ring.Kernel public
| 30.875
| 50
| 0.813765
|
297e660fc4e9728c57ad6f0cf16ccb9d77cd66d9
| 1,514
|
agda
|
Agda
|
notes/thesis/report/FOTC/Twice.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/thesis/report/FOTC/Twice.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/thesis/report/FOTC/Twice.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Twice funcion
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Twice where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
------------------------------------------------------------------------------
module HigherOrder where
-- We cannot translate this function as a definition because it is
-- higher-order.
twice : (D → D) → D → D
twice f x = f (f x)
-- {-# ATP definition twice #-}
postulate twice-succ : ∀ n → twice succ₁ n ≡ succ₁ (succ₁ n)
-- {-# ATP prove twice-succ #-}
module FirstOrderAxiom where
postulate
twice : D → D → D
twice-eq : ∀ f x → twice f x ≡ f · (f · x)
{-# ATP axiom twice-eq #-}
twice-succI : ∀ n → twice succ n ≡ succ · (succ · n)
twice-succI n = twice succ n ≡⟨ twice-eq succ n ⟩
succ · (succ · n) ∎
postulate twice-succATP : ∀ n → twice succ n ≡ succ · (succ · n)
{-# ATP prove twice-succATP #-}
module FirstOrderDefinition where
twice : D → D → D
twice f x = f · (f · x)
{-# ATP definition twice #-}
twice-succI : ∀ n → twice succ n ≡ succ · (succ · n)
twice-succI n = refl
postulate twice-succATP : ∀ n → twice succ n ≡ succ · (succ · n)
{-# ATP prove twice-succATP #-}
| 28.037037
| 78
| 0.48745
|
223294d7ff296fe288da395276f5ff52efa22649
| 11,217
|
agda
|
Agda
|
src/fot/LTC-PCF/Data/Nat/Properties.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/LTC-PCF/Data/Nat/Properties.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/LTC-PCF/Data/Nat/Properties.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Arithmetic properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.Properties where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Rec
open import LTC-PCF.Data.Nat.Rec.ConversionRules
open import LTC-PCF.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
-- Congruence properties
+-leftCong : ∀ {m n o} → m ≡ n → m + o ≡ n + o
+-leftCong refl = refl
+-rightCong : ∀ {m n o} → n ≡ o → m + n ≡ m + o
+-rightCong refl = refl
∸-leftCong : ∀ {m n o} → m ≡ n → m ∸ o ≡ n ∸ o
∸-leftCong refl = refl
∸-rightCong : ∀ {m n o} → n ≡ o → m ∸ n ≡ m ∸ o
∸-rightCong refl = refl
*-leftCong : ∀ {m n o} → m ≡ n → m * o ≡ n * o
*-leftCong refl = refl
*-rightCong : ∀ {m n o} → n ≡ o → m * n ≡ m * o
*-rightCong refl = refl
------------------------------------------------------------------------------
-- Conversion rules
+-0x : ∀ n → zero + n ≡ n
+-0x n = rec zero n _ ≡⟨ rec-0 n ⟩
n ∎
+-Sx : ∀ m n → succ₁ m + n ≡ succ₁ (m + n)
+-Sx m n =
rec (succ₁ m) n (lam (λ _ → lam succ₁))
≡⟨ rec-S m n (lam (λ _ → lam succ₁)) ⟩
(lam (λ _ → lam succ₁)) · m · (m + n)
≡⟨ ·-leftCong (beta (λ _ → lam succ₁) m) ⟩
lam succ₁ · (m + n)
≡⟨ beta succ₁ (m + n) ⟩
succ₁ (m + n) ∎
∸-x0 : ∀ n → n ∸ zero ≡ n
∸-x0 n = rec zero n _ ≡⟨ rec-0 n ⟩
n ∎
∸-xS : ∀ m n → m ∸ succ₁ n ≡ pred₁ (m ∸ n)
∸-xS m n =
rec (succ₁ n) m (lam (λ _ → lam pred₁))
≡⟨ rec-S n m (lam (λ _ → lam pred₁)) ⟩
lam (λ x → lam pred₁) · n · (m ∸ n)
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) n) ⟩
lam pred₁ · (m ∸ n)
≡⟨ beta pred₁ (m ∸ n) ⟩
pred₁ (m ∸ n) ∎
*-0x : ∀ n → zero * n ≡ zero
*-0x n = rec zero zero (lam (λ _ → lam (_+_ n))) ≡⟨ rec-0 zero ⟩
zero ∎
*-Sx : ∀ m n → succ₁ m * n ≡ n + m * n
*-Sx m n =
rec (succ₁ m) zero (lam (λ _ → lam (_+_ n)))
≡⟨ rec-S m zero (lam (λ _ → lam (_+_ n))) ⟩
(lam (λ _ → lam (_+_ n))) · m · (m * n)
≡⟨ ·-leftCong (beta (λ _ → lam (_+_ n)) m) ⟩
lam (_+_ n) · (m * n)
≡⟨ beta (_+_ n) (m * n) ⟩
n + (m * n) ∎
------------------------------------------------------------------------------
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity = +-0x
+-rightIdentity : ∀ {n} → N n → n + zero ≡ n
+-rightIdentity nzero = +-leftIdentity zero
+-rightIdentity (nsucc {n} Nn) =
trans (+-Sx n zero) (succCong (+-rightIdentity Nn))
pred-N : ∀ {n} → N n → N (pred₁ n)
pred-N nzero = subst N (sym pred-0) nzero
pred-N (nsucc {n} Nn) = subst N (sym (pred-S n)) Nn
+-N : ∀ {m n} → N m → N n → N (m + n)
+-N {n = n} nzero Nn = subst N (sym (+-leftIdentity n)) Nn
+-N {n = n} (nsucc {m} Nm) Nn = subst N (sym (+-Sx m n)) (nsucc (+-N Nm Nn))
∸-N : ∀ {m n} → N m → N n → N (m ∸ n)
∸-N {m} Nm nzero = subst N (sym (∸-x0 m)) Nm
∸-N {m} Nm (nsucc {n} Nn) = subst N (sym (∸-xS m n)) (pred-N (∸-N Nm Nn))
+-assoc : ∀ {m} → N m → ∀ n o → m + n + o ≡ m + (n + o)
+-assoc nzero n o =
zero + n + o ≡⟨ +-leftCong (+-leftIdentity n) ⟩
n + o ≡⟨ sym (+-leftIdentity (n + o)) ⟩
zero + (n + o) ∎
+-assoc (nsucc {m} Nm) n o =
succ₁ m + n + o ≡⟨ +-leftCong (+-Sx m n) ⟩
succ₁ (m + n) + o ≡⟨ +-Sx (m + n) o ⟩
succ₁ (m + n + o) ≡⟨ succCong (+-assoc Nm n o) ⟩
succ₁ (m + (n + o)) ≡⟨ sym (+-Sx m (n + o)) ⟩
succ₁ m + (n + o) ∎
x+Sy≡S[x+y] : ∀ {m} → N m → ∀ n → m + succ₁ n ≡ succ₁ (m + n)
x+Sy≡S[x+y] nzero n =
zero + succ₁ n ≡⟨ +-leftIdentity (succ₁ n) ⟩
succ₁ n ≡⟨ succCong (sym (+-leftIdentity n)) ⟩
succ₁ (zero + n) ∎
x+Sy≡S[x+y] (nsucc {m} Nm) n =
succ₁ m + succ₁ n ≡⟨ +-Sx m (succ₁ n) ⟩
succ₁ (m + succ₁ n) ≡⟨ succCong (x+Sy≡S[x+y] Nm n) ⟩
succ₁ (succ₁ (m + n)) ≡⟨ succCong (sym (+-Sx m n)) ⟩
succ₁ (succ₁ m + n) ∎
0∸x : ∀ {n} → N n → zero ∸ n ≡ zero
0∸x nzero = ∸-x0 zero
0∸x (nsucc {n} Nn) =
zero ∸ succ₁ n ≡⟨ ∸-xS zero n ⟩
pred₁ (zero ∸ n) ≡⟨ predCong (0∸x Nn) ⟩
pred₁ zero ≡⟨ pred-0 ⟩
zero ∎
S∸S : ∀ {m n} → N m → N n → succ₁ m ∸ succ₁ n ≡ m ∸ n
S∸S {m} _ nzero =
succ₁ m ∸ [1] ≡⟨ ∸-xS (succ₁ m) zero ⟩
pred₁ (succ₁ m ∸ zero) ≡⟨ predCong (∸-x0 (succ₁ m)) ⟩
pred₁ (succ₁ m) ≡⟨ pred-S m ⟩
m ≡⟨ sym (∸-x0 m) ⟩
m ∸ zero ∎
S∸S nzero (nsucc {n} Nn) =
[1] ∸ succ₁ (succ₁ n) ≡⟨ ∸-xS [1] (succ₁ n) ⟩
pred₁ ([1] ∸ succ₁ n) ≡⟨ predCong (S∸S nzero Nn) ⟩
pred₁ (zero ∸ n) ≡⟨ predCong (0∸x Nn) ⟩
pred₁ zero ≡⟨ pred-0 ⟩
zero ≡⟨ sym (0∸x (nsucc Nn)) ⟩
zero ∸ succ₁ n ∎
S∸S (nsucc {m} Nm) (nsucc {n} Nn) =
succ₁ (succ₁ m) ∸ succ₁ (succ₁ n) ≡⟨ ∸-xS (succ₁ (succ₁ m)) (succ₁ n) ⟩
pred₁ (succ₁ (succ₁ m) ∸ succ₁ n) ≡⟨ predCong (S∸S (nsucc Nm) Nn) ⟩
pred₁ (succ₁ m ∸ n) ≡⟨ sym (∸-xS (succ₁ m) n) ⟩
succ₁ m ∸ succ₁ n ∎
[x+y]∸[x+z]≡y∸z : ∀ {m n o} → N m → N n → N o → (m + n) ∸ (m + o) ≡ n ∸ o
[x+y]∸[x+z]≡y∸z {n = n} {o} nzero _ _ =
(zero + n) ∸ (zero + o) ≡⟨ ∸-leftCong (+-leftIdentity n) ⟩
n ∸ (zero + o) ≡⟨ ∸-rightCong (+-leftIdentity o) ⟩
n ∸ o ∎
[x+y]∸[x+z]≡y∸z {n = n} {o} (nsucc {m} Nm) Nn No =
(succ₁ m + n) ∸ (succ₁ m + o) ≡⟨ ∸-leftCong (+-Sx m n) ⟩
succ₁ (m + n) ∸ (succ₁ m + o) ≡⟨ ∸-rightCong (+-Sx m o) ⟩
succ₁ (m + n) ∸ succ₁ (m + o) ≡⟨ S∸S (+-N Nm Nn) (+-N Nm No) ⟩
(m + n) ∸ (m + o) ≡⟨ [x+y]∸[x+z]≡y∸z Nm Nn No ⟩
n ∸ o ∎
+-comm : ∀ {m n} → N m → N n → m + n ≡ n + m
+-comm {n = n} nzero Nn =
zero + n ≡⟨ +-leftIdentity n ⟩
n ≡⟨ sym (+-rightIdentity Nn) ⟩
n + zero ∎
+-comm {n = n} (nsucc {m} Nm) Nn =
succ₁ m + n ≡⟨ +-Sx m n ⟩
succ₁ (m + n) ≡⟨ succCong (+-comm Nm Nn) ⟩
succ₁ (n + m) ≡⟨ sym (x+Sy≡S[x+y] Nn m) ⟩
n + succ₁ m ∎
*-leftZero : ∀ n → zero * n ≡ zero
*-leftZero = *-0x
*-rightZero : ∀ {n} → N n → n * zero ≡ zero
*-rightZero nzero = *-leftZero zero
*-rightZero (nsucc {n} Nn) =
trans (*-Sx n zero)
(trans (+-leftIdentity (n * zero)) (*-rightZero Nn))
*-N : ∀ {m n} → N m → N n → N (m * n)
*-N {n = n} nzero _ = subst N (sym (*-leftZero n)) nzero
*-N {n = n} (nsucc {m} Nm) Nn = subst N (sym (*-Sx m n)) (+-N Nn (*-N Nm Nn))
*-leftIdentity : ∀ {n} → N n → [1] * n ≡ n
*-leftIdentity {n} Nn =
[1] * n ≡⟨ *-Sx zero n ⟩
n + zero * n ≡⟨ +-rightCong (*-leftZero n) ⟩
n + zero ≡⟨ +-rightIdentity Nn ⟩
n ∎
x*Sy≡x+xy : ∀ {m n} → N m → N n → m * succ₁ n ≡ m + m * n
x*Sy≡x+xy {n = n} nzero Nn = sym
(
zero + zero * n ≡⟨ +-rightCong (*-leftZero n) ⟩
zero + zero ≡⟨ +-leftIdentity zero ⟩
zero ≡⟨ sym (*-leftZero (succ₁ n)) ⟩
zero * succ₁ n ∎
)
x*Sy≡x+xy {n = n} (nsucc {m} Nm) Nn =
succ₁ m * succ₁ n
≡⟨ *-Sx m (succ₁ n) ⟩
succ₁ n + m * succ₁ n
≡⟨ +-rightCong (x*Sy≡x+xy Nm Nn) ⟩
succ₁ n + (m + m * n)
≡⟨ +-Sx n (m + m * n) ⟩
succ₁ (n + (m + m * n))
≡⟨ succCong (sym (+-assoc Nn m (m * n))) ⟩
succ₁ (n + m + m * n)
≡⟨ succCong (+-leftCong (+-comm Nn Nm)) ⟩
succ₁ (m + n + m * n)
≡⟨ succCong (+-assoc Nm n (m * n)) ⟩
succ₁ (m + (n + m * n))
≡⟨ sym (+-Sx m (n + m * n)) ⟩
succ₁ m + (n + m * n)
≡⟨ +-rightCong (sym (*-Sx m n)) ⟩
succ₁ m + succ₁ m * n ∎
*-comm : ∀ {m n} → N m → N n → m * n ≡ n * m
*-comm {n = n} nzero Nn = trans (*-leftZero n) (sym (*-rightZero Nn))
*-comm {n = n} (nsucc {m} Nm) Nn =
succ₁ m * n ≡⟨ *-Sx m n ⟩
n + m * n ≡⟨ +-rightCong (*-comm Nm Nn) ⟩
n + n * m ≡⟨ sym (x*Sy≡x+xy Nn Nm) ⟩
n * succ₁ m ∎
*∸-leftDistributive : ∀ {m n o} → N m → N n → N o → (m ∸ n) * o ≡ m * o ∸ n * o
*∸-leftDistributive {m} {o = o} _ nzero _ =
(m ∸ zero) * o ≡⟨ *-leftCong (∸-x0 m) ⟩
m * o ≡⟨ sym (∸-x0 (m * o)) ⟩
m * o ∸ zero ≡⟨ ∸-rightCong (sym (*-leftZero o)) ⟩
m * o ∸ zero * o ∎
*∸-leftDistributive {o = o} nzero (nsucc {n} Nn) No =
(zero ∸ succ₁ n) * o ≡⟨ *-leftCong (0∸x (nsucc Nn)) ⟩
zero * o ≡⟨ *-leftZero o ⟩
zero ≡⟨ sym (0∸x (*-N (nsucc Nn) No)) ⟩
zero ∸ succ₁ n * o ≡⟨ ∸-leftCong (sym (*-leftZero o)) ⟩
zero * o ∸ succ₁ n * o ∎
*∸-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) nzero =
(succ₁ m ∸ succ₁ n) * zero
≡⟨ *-comm (∸-N (nsucc Nm) (nsucc Nn)) nzero ⟩
zero * (succ₁ m ∸ succ₁ n)
≡⟨ *-leftZero (succ₁ m ∸ succ₁ n) ⟩
zero
≡⟨ sym (0∸x (*-N (nsucc Nn) nzero)) ⟩
zero ∸ succ₁ n * zero
≡⟨ ∸-leftCong (sym (*-leftZero (succ₁ m))) ⟩
zero * succ₁ m ∸ succ₁ n * zero
≡⟨ ∸-leftCong (*-comm nzero (nsucc Nm)) ⟩
succ₁ m * zero ∸ succ₁ n * zero ∎
*∸-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) =
(succ₁ m ∸ succ₁ n) * succ₁ o
≡⟨ *-leftCong (S∸S Nm Nn) ⟩
(m ∸ n) * succ₁ o
≡⟨ *∸-leftDistributive Nm Nn (nsucc No) ⟩
m * succ₁ o ∸ n * succ₁ o
≡⟨ sym ([x+y]∸[x+z]≡y∸z (nsucc No) (*-N Nm (nsucc No)) (*-N Nn (nsucc No))) ⟩
(succ₁ o + m * succ₁ o) ∸ (succ₁ o + n * succ₁ o)
≡⟨ ∸-leftCong (sym (*-Sx m (succ₁ o))) ⟩
(succ₁ m * succ₁ o) ∸ (succ₁ o + n * succ₁ o)
≡⟨ ∸-rightCong (sym (*-Sx n (succ₁ o))) ⟩
(succ₁ m * succ₁ o) ∸ (succ₁ n * succ₁ o) ∎
*+-leftDistributive : ∀ {m n o} → N m → N n → N o → (m + n) * o ≡ m * o + n * o
*+-leftDistributive {m} {n} Nm Nn nzero =
(m + n) * zero
≡⟨ *-comm (+-N Nm Nn) nzero ⟩
zero * (m + n)
≡⟨ *-leftZero (m + n) ⟩
zero
≡⟨ sym (*-leftZero m) ⟩
zero * m
≡⟨ *-comm nzero Nm ⟩
m * zero
≡⟨ sym (+-rightIdentity (*-N Nm nzero)) ⟩
m * zero + zero
≡⟨ +-rightCong (trans (sym (*-leftZero n)) (*-comm nzero Nn)) ⟩
m * zero + n * zero ∎
*+-leftDistributive {n = n} nzero Nn (nsucc {o} No) =
(zero + n) * succ₁ o ≡⟨ *-leftCong (+-leftIdentity n) ⟩
n * succ₁ o ≡⟨ sym (+-leftIdentity (n * succ₁ o)) ⟩
zero + n * succ₁ o ≡⟨ +-leftCong (sym (*-leftZero (succ₁ o))) ⟩
zero * succ₁ o + n * succ₁ o ∎
*+-leftDistributive (nsucc {m} Nm) nzero (nsucc {o} No) =
(succ₁ m + zero) * succ₁ o
≡⟨ *-leftCong (+-rightIdentity (nsucc Nm)) ⟩
succ₁ m * succ₁ o
≡⟨ sym (+-rightIdentity (*-N (nsucc Nm) (nsucc No))) ⟩
succ₁ m * succ₁ o + zero
≡⟨ +-rightCong (sym (*-leftZero (succ₁ o))) ⟩
succ₁ m * succ₁ o + zero * succ₁ o ∎
*+-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) =
(succ₁ m + succ₁ n) * succ₁ o
≡⟨ *-leftCong (+-Sx m (succ₁ n)) ⟩
succ₁ (m + succ₁ n) * succ₁ o
≡⟨ *-Sx (m + succ₁ n) (succ₁ o) ⟩
succ₁ o + (m + succ₁ n) * succ₁ o
≡⟨ +-rightCong (*+-leftDistributive Nm (nsucc Nn) (nsucc No)) ⟩
succ₁ o + (m * succ₁ o + succ₁ n * succ₁ o)
≡⟨ sym (+-assoc (nsucc No) (m * succ₁ o) (succ₁ n * succ₁ o)) ⟩
succ₁ o + m * succ₁ o + succ₁ n * succ₁ o
≡⟨ +-leftCong (sym (*-Sx m (succ₁ o))) ⟩
succ₁ m * succ₁ o + succ₁ n * succ₁ o ∎
| 34.198171
| 81
| 0.449496
|
1d26dfcb13e0c514cd08dfbdbda8de28cc3fa023
| 145
|
agda
|
Agda
|
test/Succeed/Issue5731.agda
|
sseefried/agda
|
6b13364d36eeb60d8ec15eaf8effe23c73401900
|
[
"BSD-2-Clause"
] | 1
|
2022-02-05T01:21:48.000Z
|
2022-02-05T01:21:48.000Z
|
test/Succeed/Issue5731.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Succeed/Issue5731.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | null | null | null |
-- This file just tests that the options --no-save-metas and
-- --save-metas are parsed correctly.
{-# OPTIONS --no-save-metas --save-metas #-}
| 29
| 60
| 0.682759
|
223bfc496df89aa07d5109d08cc9b8fc3cccdd14
| 206
|
agda
|
Agda
|
Cubical/HITs/S2/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S2/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S2/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.S2.Base where
open import Cubical.Foundations.Prelude
data S² : Type₀ where
base : S²
surf : PathP (λ i → base ≡ base) refl refl
| 22.888889
| 50
| 0.694175
|
414684629c5acb4cf8d942d5eba8253fe8da358c
| 221
|
agda
|
Agda
|
test/Fail/NotStrictlyPositive.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/NotStrictlyPositive.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/NotStrictlyPositive.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module NotStrictlyPositive where
data False : Set where
data Not (A : Set) : Set where
not : (A -> False) -> Not A
data Neg (A : Set) : Set where
neg : Not A -> Neg A
data Bad : Set where
bad : Neg Bad -> Bad
| 14.733333
| 32
| 0.615385
|
5732a40ace6430d9dfbaeb7b4d68cff2f318b054
| 1,478
|
agda
|
Agda
|
test/Succeed/Issue480.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue480.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue480.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2016-02-02 added Ambiguous
module Issue480 where
module Simple where
data Q : Set where
a : Q
f : _ → Q
f a = a
postulate helper : ∀ {T : Set} → (T → T) → Q
test₁ : Q → Q
test₁ = λ { a → a }
test₂ : Q
test₂ = helper test₁
-- Same as test₂ and test₁, but stuck together.
test₃ : Q
test₃ = helper λ { a → a } -- this says "Type mismatch when checking that the pattern a has type _45"
module Ambiguous where
data Q : Set where
a : Q
data Overlap : Set where
a : Overlap
postulate helper : ∀ {T : Set} → (T → T) → T -- result type needs to be propagated
test₁ : Q → Q
test₁ = λ { a → a }
test₃ : Q
test₃ = helper λ { a → a }
_$_ : ∀ {T : Set} → (T → T) → T → T
f $ x = f x
test : Q
test = (λ { a → a }) $ a
test₂ : _
test₂ = (λ { a → a }) $ Q.a
module Example where
infixr 5 _∷_
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
data List : Set₁ where
[] : List
_∷_ : Set → List → List
data Tree (L : Set) : List → Set₁ where
tip : Tree L []
node : ∀ {T Ts} → (cs : T → Tree L Ts) → Tree L (T ∷ Ts)
data Q (n : ℕ) : Set where
a : Q n
b : Q n
test₁ : Q zero → Tree ℕ (Q zero ∷ [])
test₁ = λ
{ a → node λ { a → tip ; b → tip }
; b → node λ { a → tip ; b → tip }
}
test₂ = node test₁
test₃ : Tree ℕ (Q zero ∷ Q zero ∷ [])
test₃ = node λ
{ a → node λ { a → tip ; b → tip }
; b → node λ { a → tip ; b → tip }
}
| 17.595238
| 103
| 0.499323
|
3db7e2a811133b1f4c389a015dd8c88600a135f5
| 282
|
agda
|
Agda
|
Algebra/Category.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | 1
|
2019-10-07T17:36:42.000Z
|
2019-10-07T17:36:42.000Z
|
Algebra/Category.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
Algebra/Category.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <esz@posteo.de>
module Algebra.Category where
open import Algebra.Category.Category public
open import Algebra.Category.Groupoid public
open import Algebra.Category.Semigroupoid public
| 28.2
| 48
| 0.797872
|
1abd86ae5996eb556e0475a845fb4967a92b7605
| 11,715
|
agda
|
Agda
|
agda/PLRTree/Insert/Permutation.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/PLRTree/Insert/Permutation.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/PLRTree/Insert/Permutation.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module PLRTree.Insert.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.List
open import Data.Product renaming (_×_ to _∧_)
open import Data.Sum
open import List.Permutation.Base A
open import List.Permutation.Base.Concatenation A
open import List.Permutation.Base.Equivalence A
open import PLRTree {A}
open import PLRTree.Complete {A}
open import PLRTree.Compound {A}
open import PLRTree.Insert _≤_ tot≤
open import PLRTree.Insert.Properties _≤_ tot≤
mutual
lemma-insert-/ : {t : PLRTree}(x : A) → Complete t → ∃ (λ xs → flatten (insert x t) / x ⟶ xs ∧ xs ∼ flatten t)
lemma-insert-/ x leaf = [] , /head , ∼[]
lemma-insert-/ x (perfect {l} {r} y cl _ l≃r)
with tot≤ x y | l | r | l≃r
... | inj₁ x≤y | leaf | leaf | _ = y ∷ [] , /head , refl∼
... | inj₁ x≤y | leaf | node _ _ _ _ | ()
... | inj₁ x≤y | node perfect _ _ _ | leaf | ()
... | inj₁ x≤y | node perfect y' l' r' | node perfect y'' l'' r'' | _ =
let _l = node perfect y' l' r' ;
_r = node perfect y'' l'' r'' ;
flᵢfr∼yflfr = lemma++∼r (lemma-insert-∼ y cl)
in flatten (insert y _l) ++ flatten _r , /head , flᵢfr∼yflfr
... | inj₁ x≤y | node perfect _ _ _ | node left _ _ _ | ()
... | inj₁ x≤y | node perfect _ _ _ | node right _ _ _ | ()
... | inj₁ x≤y | node left _ _ _ | _ | ()
... | inj₁ x≤y | node right _ _ _ | _ | ()
... | inj₂ y≤x | leaf | leaf | _ = y ∷ [] , /tail /head , refl∼
... | inj₂ y≤x | leaf | node _ _ _ _ | ()
... | inj₂ y≤x | node perfect _ _ _ | leaf | ()
... | inj₂ y≤x | node perfect y' l' r' | node perfect y'' l'' r'' | _
with lemma-insert-/ x cl
... | xs , flᵢ/x⟶xs , xs∼fl =
let _l = node perfect y' l' r' ;
_r = node perfect y'' l'' r'' ;
yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)
in y ∷ xs ++ flatten _r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr
lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node left _ _ _ | ()
lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node right _ _ _ | ()
lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node left _ _ _ | _ | ()
lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node right _ _ _ | _ | ()
lemma-insert-/ x (left {l} {r} y cl _ _)
with tot≤ x y
... | inj₁ x≤y
with insert y l | lemma-insert-∼ y cl | lemma-insert-compound y l
... | node perfect y' l' r' | flᵢ∼yfl | compound =
let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl
in flatten (node perfect y' l' r') ++ flatten r , /head , flᵢfr∼yflfr
... | node left y' l' r' | flᵢ∼yfl | compound =
let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl
in flatten (node left y' l' r') ++ flatten r , /head , flᵢfr∼yflfr
... | node right y' l' r' | flᵢ∼yfl | compound =
let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl
in flatten (node right y' l' r') ++ flatten r , /head , flᵢfr∼yflfr
lemma-insert-/ x (left {l} {r} y cl _ _) | inj₂ y≤x
with insert x l | lemma-insert-/ x cl | lemma-insert-compound x l
... | node perfect _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)
in y ∷ xs ++ flatten r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr
... | node left _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)
in y ∷ xs ++ flatten r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr
... | node right _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)
in y ∷ xs ++ flatten r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr
lemma-insert-/ x (right {l} {r} y _ cr _)
with tot≤ x y
... | inj₁ x≤y
with insert y r | lemma-insert-∼ y cr | lemma-insert-compound y r
... | node perfect y' l' r' | frᵢ∼yfr | compound =
let flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;
flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;
flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr
in flatten l ++ flatten (node perfect y' l' r') , /head , flfrᵢ∼yflfr
... | node left y' l' r' | frᵢ∼yfr | compound =
let flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;
flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;
flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr
in flatten l ++ flatten (node left y' l' r') , /head , flfrᵢ∼yflfr
... | node right y' l' r' | frᵢ∼yfr | compound =
let flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;
flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;
flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr
in flatten l ++ flatten (node right y' l' r') , /head , flfrᵢ∼yflfr
lemma-insert-/ x (right {l} {r} y _ cr _) | inj₂ y≤x
with insert x r | lemma-insert-/ x cr | lemma-insert-compound x r
... | node perfect y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound =
let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;
yflfrᵢ∼yflxs = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)
in y ∷ flatten l ++ xs , yflfrᵢ/x⟶yflxs , yflfrᵢ∼yflxs
... | node left y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound =
let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;
yflfrᵢ∼yflxs = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)
in y ∷ flatten l ++ xs , yflfrᵢ/x⟶yflxs , yflfrᵢ∼yflxs
... | node right y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound =
let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;
yflfrᵢ∼yflxs = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)
in y ∷ flatten l ++ xs , yflfrᵢ/x⟶yflxs , yflfrᵢ∼yflxs
lemma-insert-∼ : {t : PLRTree}(x : A) → Complete t → flatten (insert x t) ∼ (x ∷ flatten t)
lemma-insert-∼ x leaf = ∼x /head /head ∼[]
lemma-insert-∼ x (perfect {l} {r} y cl _ l≃r)
with tot≤ x y | l | r | l≃r
... | inj₁ x≤y | leaf | leaf | _ = ∼x /head /head (∼x /head /head ∼[])
... | inj₁ x≤y | leaf | node _ _ _ _ | ()
... | inj₁ x≤y | node perfect _ _ _ | leaf | ()
... | inj₁ x≤y | node perfect _ _ _ | node perfect _ _ _ | _ =
let flᵢfr∼yflfr = lemma++∼r (lemma-insert-∼ y cl)
in ∼x /head /head flᵢfr∼yflfr
... | inj₁ x≤y | node perfect _ _ _ | node left _ _ _ | ()
... | inj₁ x≤y | node perfect _ _ _ | node right _ _ _ | ()
... | inj₁ x≤y | node left _ _ _ | _ | ()
... | inj₁ x≤y | node right _ _ _ | _ | ()
... | inj₂ y≤x | leaf | leaf | _ = ∼x /head (/tail /head) (∼x /head /head ∼[])
... | inj₂ y≤x | leaf | node _ _ _ _ | ()
... | inj₂ y≤x | node perfect _ _ _ | leaf | ()
... | inj₂ y≤x | node perfect _ _ _ | node perfect _ _ _ | _
with lemma-insert-/ x cl
... | xs , flᵢ/x⟶xs , xs∼fl =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)
in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr
lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node left _ _ _ | ()
lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node right _ _ _ | ()
lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node left _ _ _ | _ | ()
lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node right _ _ _ | _ | ()
lemma-insert-∼ x (left {l} {r} y cl _ _)
with tot≤ x y
... | inj₁ x≤y
with insert y l | lemma-insert-∼ y cl | lemma-insert-compound y l
... | node perfect _ _ _ | flᵢ∼yfl | compound =
let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl
in ∼x /head /head flᵢfr∼yflfr
... | node left _ _ _ | flᵢ∼yfl | compound =
let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl
in ∼x /head /head flᵢfr∼yflfr
... | node right _ _ _ | flᵢ∼yfl | compound =
let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl
in ∼x /head /head flᵢfr∼yflfr
lemma-insert-∼ x (left {l} {r} y cl _ _) | inj₂ y≤x
with insert x l | lemma-insert-/ x cl | lemma-insert-compound x l
... | node perfect _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)
in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr
... | node left _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)
in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr
... | node right _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound =
let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;
yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)
in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr
lemma-insert-∼ x (right {l} {r} y _ cr _)
with tot≤ x y
... | inj₁ x≤y
with insert y r | lemma-insert-∼ y cr | lemma-insert-compound y r
... | node perfect _ _ _ | frᵢ∼yfr | compound =
let flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;
flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;
flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr
in ∼x /head /head flfrᵢ∼yflfr
... | node left _ _ _ | frᵢ∼yfr | compound =
let flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;
flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;
flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr
in ∼x /head /head flfrᵢ∼yflfr
... | node right _ _ _ | frᵢ∼yfr | compound =
let flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;
flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;
flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr
in ∼x /head /head flfrᵢ∼yflfr
lemma-insert-∼ x (right {l} {r} y _ cr _) | inj₂ y≤x
with insert x r | lemma-insert-/ x cr | lemma-insert-compound x r
... | node perfect y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound =
let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;
yflxs∼yflfr = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)
in ∼x yflfrᵢ/x⟶yflxs /head yflxs∼yflfr
... | node left y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound =
let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;
yflxs∼yflfr = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)
in ∼x yflfrᵢ/x⟶yflxs /head yflxs∼yflfr
... | node right y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound =
let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;
yflxs∼yflfr = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)
in ∼x yflfrᵢ/x⟶yflxs /head yflxs∼yflfr
| 58.575
| 112
| 0.497738
|
12cc971a4528c03e002967bf350ffb1acc28098d
| 108
|
agda
|
Agda
|
test/Fail/IUnivNoHComp.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/IUnivNoHComp.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/IUnivNoHComp.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Primitive.Cubical
test : (J : IUniv) → J → J
test J j = primHComp {φ = i0} (λ k → λ ()) j
| 21.6
| 44
| 0.592593
|
2292e6815c2a3851a5644767dffc83ef89f4f409
| 24
|
agda
|
Agda
|
test/interaction/Issue591/M.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue591/M.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue591/M.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue591.M where
| 12
| 23
| 0.833333
|
3108d2f26c546343047a2a713bd86a2c3abc76f5
| 8,192
|
agda
|
Agda
|
Cubical/HITs/SequentialColimit/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/HITs/SequentialColimit/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SequentialColimit/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Eliminators of direct limit, especially an index-shifting version;
- Connectivity of inclusion maps.
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.SequentialColimit.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Data.Nat hiding (elim)
open import Cubical.HITs.SequentialColimit.Base
open import Cubical.Homotopy.Connected
private
variable
ℓ ℓ' : Level
module _
(X : Sequence ℓ) where
open Sequence
private
inl∞ : (n : ℕ) → X .space n → Lim→ X
inl∞ n = inl {n = n}
record ElimData (P : Lim→ X → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
finl : {k : ℕ}(x : X .space k) → P (inl x)
fpush : {k : ℕ}(x : X .space k) → PathP (λ i → P (push x i)) (finl x) (finl (X .map x))
record ElimShiftData (n : ℕ)(P : Lim→ X → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
finl : {k : ℕ}(x : X .space (k + n)) → P (inl x)
fpush : {k : ℕ}(x : X .space (k + n)) → PathP (λ i → P (push x i)) (finl x) (finl (X .map x))
open ElimData
open ElimShiftData
ElimData→ElimShiftData : (n : ℕ)(P : Lim→ X → Type ℓ')
→ ElimData P → ElimShiftData n P
ElimData→ElimShiftData n P datum .finl = datum .finl
ElimData→ElimShiftData n P datum .fpush = datum .fpush
-- Preliminary lemmas
-- The difficulty is mainly due to natural numbers having no strict +-commutativity
private
alg-path : (a b : ℕ) → a + (1 + b) ≡ 1 + (a + b)
alg-path a b = +-assoc a 1 b ∙ (λ i → +-comm a 1 i + b)
module _
(P : Lim→ X → Type ℓ')
(datum : ElimShiftData 0 P) where
+-zero-0 : refl ≡ +-zero 0
+-zero-0 i j = isSet→SquareP (λ i j → isSetℕ) refl refl refl (+-zero 0) j i
finl'-filler : (k : ℕ) → (i : I) → (x : X .space (+-zero k i)) → P (inl x)
finl'-filler k i = transport-filler (λ i → (x : X .space (+-zero k i)) → P (inl x)) (datum .finl) i
finl' : (k : ℕ) → (x : X .space k) → P (inl x)
finl' k = finl'-filler k i1
finl'-0-eq : datum .finl ≡ finl' 0
finl'-0-eq = sym (transportRefl _)
∙ (λ j → transport (λ i → (x : X .space (+-zero-0 j i)) → P (inl x)) (datum .finl {k = 0}))
fpush' : (k : ℕ)
→ (x : X .space k)
→ PathP (λ i → P (push x i)) (finl' k x) (finl' (1 + k) (X .map x))
fpush' k = transport
(λ i → (x : X .space (+-zero k i)) →
PathP (λ i → P (push x i)) (finl'-filler k i x) (finl'-filler (1 + k) i (X .map x))) (datum .fpush)
ElimShiftData0→ElimData : ElimData P
ElimShiftData0→ElimData .finl = finl' _
ElimShiftData0→ElimData .fpush = fpush' _
module _
(n : ℕ)(P : Lim→ X → Type ℓ')
(datum : ElimShiftData (1 + n) P) where
alg-path-0 : (b : ℕ) → refl ≡ alg-path 0 b
alg-path-0 b i j = isSet→SquareP (λ i j → isSetℕ) refl refl refl (alg-path 0 b) j i
finl-n-filler : (k : ℕ) → (i : I) → ((x : X .space (alg-path k n i)) → P (inl x))
finl-n-filler k i = transport-filler (λ i → (x : X .space (alg-path k n i)) → P (inl x)) (datum .finl) i
finl-n : (k : ℕ) → (x : X .space ((1 + k) + n)) → P (inl x)
finl-n k = finl-n-filler k i1
fpush-n : (k : ℕ)
→ (x : X .space ((1 + k) + n))
→ PathP (λ i → P (push x i)) (finl-n k x) (finl-n (1 + k) (X .map x))
fpush-n k =
transport
(λ i → (x : X .space (alg-path k n i)) →
PathP (λ i → P (push x i)) (finl-n-filler k i x) (finl-n-filler (1 + k) i (X .map x))) (datum .fpush)
finl-0-filler : (x : X .space n) → (i : I) → P (push x i)
finl-0-filler x i = transport-filler (λ i → P (push x (~ i))) (datum .finl {k = 0} (X .map x)) (~ i)
finl-0 : (x : X .space n) → P (inl x)
finl-0 x = finl-0-filler x i0
finl-0-eq : datum .finl {k = 0} ≡ finl-n 0
finl-0-eq = sym (transportRefl _)
∙ (λ j → transport (λ i → (x : X .space (alg-path-0 n j i)) → P (inl x)) (datum .finl {k = 0}))
fpush-0 :
(x : X .space n)
→ PathP (λ i → P (push x i)) (finl-0 x) (finl-n 0 (X .map x))
fpush-0 x i =
hcomp (λ j → λ
{ (i = i0) → finl-0 x
; (i = i1) → finl-0-eq j (X .map x) })
(finl-0-filler x i)
elimShiftDataSuc : ElimShiftData n P
elimShiftDataSuc .finl {k = 0} = finl-0
elimShiftDataSuc .finl {k = suc k} = finl-n k
elimShiftDataSuc .fpush {k = 0} = fpush-0
elimShiftDataSuc .fpush {k = suc k} = fpush-n k
-- The eliminators
elim :
(P : Lim→ X → Type ℓ')
→ ElimData P
→ (x : Lim→ X) → P x
elim P datum (inl x) = datum .finl x
elim P datum (push x i) = datum .fpush x i
elimShift : (n : ℕ)
→ (P : Lim→ X → Type ℓ')
→ ElimShiftData n P
→ (x : Lim→ X) → P x
elimShift 0 _ datum = elim _ (ElimShiftData0→ElimData _ datum)
elimShift (suc n) _ datum = elimShift n _ (elimShiftDataSuc _ _ datum)
elimShiftβ : (n : ℕ)(k : ℕ)
→ (P : Lim→ X → Type ℓ')
→ (datum : ElimShiftData n P)
→ elimShift _ _ datum ∘ inl∞ (k + n) ≡ datum .finl
elimShiftβ 0 0 _ datum = sym (finl'-0-eq _ datum)
elimShiftβ 0 (suc k) P datum =
transport (λ i → elimShift _ _ datum ∘ inl∞ (+-zero (suc k) (~ i))
≡ finl'-filler P datum (suc k) (~ i)) refl
elimShiftβ (suc n) 0 _ datum =
elimShiftβ n _ _ (elimShiftDataSuc _ _ datum)
∙ sym (finl-0-eq _ _ datum)
elimShiftβ (suc n) (suc k) P datum =
transport (λ i → elimShift _ _ datum ∘ inl∞ (alg-path (suc k) n (~ i))
≡ finl-n-filler n P datum (suc k) (~ i))
(elimShiftβ n (suc (suc k)) P (elimShiftDataSuc _ _ datum))
-- Lemma to lift sections
open Iso
private
transpSec :
(n : ℕ)(Y : Lim→ X → Type ℓ')
(sec : (x : X .space n) → Y (inl x))
→ (x : X .space n) → Y (inl (X .map x))
transpSec n Y sec x = transport (λ i → Y (push x i)) (sec x)
module _
(d : ℕ)(n : ℕ)
(conn : isConnectedFun d (X .map {n = n}))
(Y : Lim→ X → TypeOfHLevel ℓ' d) where
module _
(sec : (x : X .space n) → Y (inl (X .map x)) .fst) where
lift-iso = elim.isIsoPrecompose _ d (Y ∘ inl) conn
liftSec' : (x : X .space (1 + n)) → Y (inl x) .fst
liftSec' = lift-iso .inv sec
liftSecPath' : (x : X .space n) → sec x ≡ liftSec' (X .map x)
liftSecPath' x i = lift-iso .rightInv sec (~ i) x
module _
(sec : (x : X .space n) → Y (inl x) .fst) where
liftSec : (x : X .space (1 + n)) → Y (inl x) .fst
liftSec = liftSec' (transpSec n (λ x → Y x .fst) sec)
liftSecPath :
(x : X .space n)
→ PathP (λ i → Y (push x i) .fst) (sec x) (liftSec (X .map x))
liftSecPath x i =
hcomp (λ j → λ
{ (i = i0) → sec x
; (i = i1) → liftSecPath'
(transpSec n (λ x → Y x .fst) sec) x j })
(transport-filler (λ i → Y (push x i) .fst) (sec x) i)
module _
(d : ℕ)(n : ℕ)
(conn : (k : ℕ) → isConnectedFun d (X .map {n = k + n})) where
private
module _
(Y : Lim→ X → TypeOfHLevel ℓ' d) where
lifting : (k : ℕ)(sec : (x : X .space n) → Y (inl x) .fst)
→ (x : X .space (k + n)) → Y (inl x) .fst
lifting 0 sec = sec
lifting (suc k) sec = liftSec d _ (conn _) Y (lifting k sec)
liftingPath : (k : ℕ)(sec : (x : X .space n) → Y (inl x) .fst)
→ (x : X .space (k + n))
→ PathP (λ i → Y (push x i) .fst) (lifting k sec x) (lifting (1 + k) sec (X .map x))
liftingPath k sec = liftSecPath d _ (conn _) Y (lifting k sec)
liftingData : ((x : X .space n) → Y (inl x) .fst) → ElimShiftData n (λ x → Y x .fst)
liftingData sec .finl = lifting _ sec
liftingData sec .fpush = liftingPath _ sec
hasSectionInl∘ : hasSection (λ (sec : (x : Lim→ X) → Y x .fst) → sec ∘ inl {n = n})
hasSectionInl∘ .fst sec = elimShift _ _ (liftingData sec)
hasSectionInl∘ .snd sec = elimShiftβ _ _ _ (liftingData sec)
-- Connectivity of inclusion map
isConnectedInl∞ : isConnectedFun d (inl∞ n)
isConnectedInl∞ = elim.isConnectedPrecompose _ _ hasSectionInl∘
| 34.420168
| 111
| 0.537231
|
fbd108bb73a5a6f2879648d3ed0cab41afc55c56
| 45,911
|
agda
|
Agda
|
Agda/17-cubical-diagrams.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/17-cubical-diagrams.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/17-cubical-diagrams.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --allow-unsolved-metas --exact-split #-}
module 17-cubical-diagrams where
import 16-pushouts
open 16-pushouts public
-- Section 15.1 Commuting cubes
-- Cubes
{-
We specify the type of the homotopy witnessing that a cube commutes.
Imagine that the cube is presented as a lattice
*
/ | \
/ | \
/ | \
* * *
|\ / \ /|
| \ / |
|/ \ / \|
* * *
\ | /
\ | /
\ | /
*
with all maps pointing in the downwards direction. Presented in this way, a
cube of maps has a top face, a back-left face, a back-right face, a
front-left face, a front-right face, and a bottom face, all of which are
homotopies.
A term of type coherence-cube is a homotopy filling the cube.
-}
coherence-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
UU _
coherence-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(((h ·l back-left) ∙h (front-left ·r f')) ∙h (hD ·l top)) ~
((bottom ·r hA) ∙h ((k ·l back-right) ∙h (front-right ·r g')))
coherence-hexagon :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) → UU l
coherence-hexagon α β γ δ ε ζ = Id ((α ∙ β) ∙ γ) (δ ∙ (ε ∙ ζ))
hexagon-rotate-120 :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon (inv ε) (inv δ) α ζ (inv γ) (inv β)
hexagon-rotate-120 refl refl refl refl refl .refl refl = refl
hexagon-rotate-240 :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon γ (inv ζ) (inv ε) (inv β) (inv α) δ
hexagon-rotate-240 refl refl refl refl refl .refl refl = refl
hexagon-mirror-A :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon ε ζ (inv γ) (inv δ) α β
hexagon-mirror-A refl refl refl refl refl .refl refl = refl
hexagon-mirror-B :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon (inv α) δ ε β γ (inv ζ)
hexagon-mirror-B refl refl refl refl refl .refl refl = refl
hexagon-mirror-C :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon (inv γ) (inv β) (inv α) (inv ζ) (inv ε) (inv δ)
hexagon-mirror-C refl refl refl refl refl .refl refl = refl
{- Since the specification of a cube is rather lengthy, we use Agda's
parametrized module system in order to avoid having to specify the same
variables multiple times.
-}
module Cubes
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))
(c : coherence-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)
where
{-
The symmetry group D_3 acts on a cube. However, the coherence filling a
a cube needs to be modified to show that the rotated/reflected cube again
commutes. In the following definitions we provide the homotopies witnessing
that the rotated/reflected cubes again commute.
Note: although in principle it ought to be enough to show this for the
generators of the symmetry group D_3, in practice it is more
straightforward to just do the work for each of the symmetries separately.
One reason is that some of the homotopies witnessing that the faces
commute will be inverted as the result of an application of a symmetry.
Inverting a homotopy twice results in a new homotopy that is only
homotopic to the original homotopy.
We first provide some constructions involving homotopies that will help us
manipulating coherences of cubes.
-}
-- We show that a rotation of a commuting cube again commutes.
coherence-cube-rotate-120 :
coherence-cube
hC k' k hD hA f' f hB g' g h' h
back-left
(htpy-inv back-right) (htpy-inv top)
(htpy-inv bottom) (htpy-inv front-left)
front-right
coherence-cube-rotate-120 a' =
( ap (λ t → t ∙ (ap h (back-left a')))
( ap (λ t' → t' ∙ inv (bottom (hA a')))
( ap-inv k (back-right a')))) ∙
( ( hexagon-rotate-120
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a')) ∙
( inv
( ap (λ t → (front-right (g' a')) ∙ t)
( ap (λ t' → t' ∙ inv (front-left (f' a')))
( ap-inv hD (top a'))))))
coherence-cube-rotate-240 :
coherence-cube
h' hB hD h g' hA hC g f' k' f k
(htpy-inv back-right)
top (htpy-inv back-left)
(htpy-inv front-right) bottom
(htpy-inv front-left)
coherence-cube-rotate-240 a' =
( ap (λ t → _ ∙ t) (ap-inv k (back-right a'))) ∙
( ( hexagon-rotate-240
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a')) ∙
( inv
( ap
( λ t → inv (front-left (f' a')) ∙ t)
( ap (λ t' → t' ∙ _) (ap-inv h (back-left a'))))))
{-
We show that a reflection through the plane spanned by the vertices
A', A, and D of a commuting cube again commutes.
Note: Since the vertices A' and D must always be fixed, the vertex A
determines the mirror symmetry.
-}
coherence-cube-mirror-A :
coherence-cube g f k h g' f' k' h' hA hC hB hD
(htpy-inv top) back-right back-left front-right front-left (htpy-inv bottom)
coherence-cube-mirror-A a' =
( ap (λ t → _ ∙ t) (ap-inv hD (top a'))) ∙
( hexagon-mirror-A
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a'))
coherence-cube-mirror-B :
coherence-cube hB h' h hD hA g' g hC f' f k' k
back-right (htpy-inv back-left) top bottom (htpy-inv front-right) front-left
coherence-cube-mirror-B a' =
( ap (λ t → t ∙ (ap k (back-right a')))
( ap (λ t → t ∙ _) (ap-inv h (back-left a')))) ∙
( hexagon-mirror-B
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a'))
coherence-cube-mirror-C :
coherence-cube k' hC hD k f' hA hB f g' h' g h
(htpy-inv back-left) (htpy-inv top) (htpy-inv back-right)
(htpy-inv front-left) (htpy-inv bottom) (htpy-inv front-right)
coherence-cube-mirror-C a' =
( ap
( λ t → (t ∙ inv (front-left (f' a'))) ∙ (ap h (inv (back-left a'))))
( ap-inv hD (top a'))) ∙
( ( ap (λ t → _ ∙ t) (ap-inv h (back-left a'))) ∙
( ( hexagon-mirror-C
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a')) ∙
( inv
( ap
( λ t → inv (front-right (g' a')) ∙ t)
( ap (λ t' → t' ∙ _) (ap-inv k (back-right a')))))))
open Cubes public
rectangle-back-left-front-left-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((h ∘ f) ∘ hA) ~ (hD ∘ (h' ∘ f'))
rectangle-back-left-front-left-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(h ·l back-left) ∙h (front-left ·r f')
rectangle-back-right-front-right-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((k ∘ g) ∘ hA) ~ (hD ∘ (k' ∘ g'))
rectangle-back-right-front-right-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(k ·l back-right) ∙h (front-right ·r g')
coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
coherence-htpy-square
( bottom)
( htpy-refl' hD)
( pair hA
( pair
( h' ∘ f')
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair hA
( pair
( k' ∘ g')
( rectangle-back-right-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( htpy-refl' hA)
( top)
coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c =
( λ a' →
( ap
( concat
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom a')
( hD (k' (g' a'))))
( right-unit))) ∙h
( c)
rectangle-top-front-left-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((h ∘ hB) ∘ f') ~ ((hD ∘ k') ∘ g')
rectangle-top-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(front-left ·r f') ∙h (hD ·l top)
rectangle-back-right-bottom-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((h ∘ f) ∘ hA) ~ ((k ∘ hC) ∘ g')
rectangle-back-right-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
( bottom ·r hA) ∙h (k ·l back-right)
{-
coherence-htpy-square-rectangle-top-fl-rectangle-br-bot-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
coherence-htpy-square
( htpy-inv front-right)
( htpy-refl' h)
( pair g' (pair (hB ∘ f')
( htpy-inv (rectangle-top-front-left-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))))
( pair g' (pair (f ∘ hA)
( htpy-inv
( rectangle-back-right-bottom-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))))
( htpy-refl' g')
( htpy-inv back-left)
coherence-htpy-square-rectangle-top-fl-rectangle-br-bot-cube = {!!}
-}
rectangle-top-front-right-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((hD ∘ h') ∘ f') ~ ((k ∘ hC) ∘ g')
rectangle-top-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(hD ·l top) ∙h (htpy-inv (front-right) ·r g')
rectangle-back-left-bottom-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))→
((h ∘ hB) ∘ f') ~ ((k ∘ g) ∘ hA)
rectangle-back-left-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(h ·l (htpy-inv back-left)) ∙h (bottom ·r hA)
is-pullback-back-left-is-pullback-back-right-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f : A → B} {g : A → C} {h : B → D} {k : C → D}
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
{f' : A' → B'} {g' : A' → C'} {h' : B' → D'} {k' : C' → D'}
{hA : A' → A} {hB : B' → B} {hC : C' → C} {hD : D' → D}
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-pullback h hD (pair hB (pair h' front-left)) →
is-pullback k hD (pair hC (pair k' front-right)) →
is-pullback g hC (pair hA (pair g' back-right)) →
is-pullback f hB (pair hA (pair f' back-left))
is-pullback-back-left-is-pullback-back-right-cube
{f = f} {g} {h} {k} {f' = f'} {g'} {h'} {k'} {hA = hA} {hB} {hC} {hD}
top back-left back-right front-left front-right bottom c
is-pb-front-left is-pb-front-right is-pb-back-right =
is-pullback-left-square-is-pullback-rectangle f h hD
( pair hB (pair h' front-left))
( pair hA (pair f' back-left))
( is-pb-front-left)
( is-pullback-htpy
{ f = h ∘ f}
( k ∘ g)
( bottom)
{ g = hD}
( hD)
( htpy-refl)
{ c = pair hA (pair (h' ∘ f')
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))}
( pair hA (pair (k' ∘ g')
( rectangle-back-right-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair
( htpy-refl)
( pair top
( coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)))
( is-pullback-rectangle-is-pullback-left-square g k hD
( pair hC (pair k' front-right))
( pair hA (pair g' back-right))
( is-pb-front-right)
( is-pb-back-right)))
is-pullback-back-right-is-pullback-back-left-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f : A → B} {g : A → C} {h : B → D} {k : C → D}
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
{f' : A' → B'} {g' : A' → C'} {h' : B' → D'} {k' : C' → D'}
{hA : A' → A} {hB : B' → B} {hC : C' → C} {hD : D' → D}
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-pullback h hD (pair hB (pair h' front-left)) →
is-pullback k hD (pair hC (pair k' front-right)) →
is-pullback f hB (pair hA (pair f' back-left)) →
is-pullback g hC (pair hA (pair g' back-right))
is-pullback-back-right-is-pullback-back-left-cube
{f = f} {g} {h} {k} {f' = f'} {g'} {h'} {k'} {hA = hA} {hB} {hC} {hD}
top back-left back-right front-left front-right bottom c
is-pb-front-left is-pb-front-right is-pb-back-left =
is-pullback-left-square-is-pullback-rectangle g k hD
( pair hC (pair k' front-right))
( pair hA (pair g' back-right))
( is-pb-front-right)
( is-pullback-htpy'
( h ∘ f)
{ f' = k ∘ g}
( bottom)
( hD)
{ g' = hD}
( htpy-refl)
( pair hA (pair (h' ∘ f')
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
{ c' = pair hA (pair (k' ∘ g')
( rectangle-back-right-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))}
( pair
( htpy-refl)
( pair top
( coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)))
( is-pullback-rectangle-is-pullback-left-square f h hD
( pair hB (pair h' front-left))
( pair hA (pair f' back-left))
( is-pb-front-left)
( is-pb-back-left)))
descent-is-equiv :
{l1 l2 l3 l4 l5 l6 : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6}
(i : X → Y) (j : Y → Z) (h : C → Z)
(c : cone j h B) (d : cone i (pr1 c) A) →
is-equiv i → is-equiv (pr1 (pr2 d)) →
is-pullback (j ∘ i) h (cone-comp-horizontal i j h c d) →
is-pullback j h c
descent-is-equiv i j h c d
is-equiv-i is-equiv-k is-pb-rectangle =
is-pullback-is-fiberwise-equiv-fib-square j h c
( ind-is-equiv
( λ y → is-equiv (fib-square j h c y))
( i)
( is-equiv-i)
( λ x → is-equiv-left-factor
( fib-square (j ∘ i) h
( cone-comp-horizontal i j h c d) x)
( fib-square j h c (i x))
( fib-square i (pr1 c) d x)
( fib-square-comp-horizontal i j h c d x)
( is-fiberwise-equiv-fib-square-is-pullback (j ∘ i) h
( cone-comp-horizontal i j h c d)
( is-pb-rectangle)
( x))
( is-fiberwise-equiv-fib-square-is-pullback i (pr1 c) d
( is-pullback-is-equiv' i (pr1 c) d is-equiv-i is-equiv-k) x)))
coherence-htpy-square-is-pullback-bottom-is-pullback-top-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
coherence-htpy-square
( front-left)
( htpy-refl' k)
( pair f'
( pair
( g ∘ hA)
( rectangle-back-left-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair f'
( pair
( hC ∘ g')
( rectangle-top-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( htpy-refl' f')
( back-right)
coherence-htpy-square-is-pullback-bottom-is-pullback-top-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c =
( htpy-inv
( htpy-inv
( htpy-assoc
( h ·l (htpy-inv back-left))
( bottom ·r hA)
( (k ·l back-right) ∙h (htpy-refl' (k ∘ (hC ∘ g'))))))) ∙h
( ( htpy-ap-concat'
( h ·l (htpy-inv back-left))
( htpy-inv (h ·l back-left))
( _)
( htpy-left-whisk-htpy-inv h back-left)) ∙h
( htpy-inv (htpy-inv-con (h ·l back-left) _ _
( ( ( htpy-inv (htpy-assoc (h ·l back-left) (front-left ·r f') _)) ∙h
( ( htpy-inv
( htpy-assoc
( (h ·l back-left) ∙h (front-left ·r f'))
( hD ·l top)
( (htpy-inv front-right) ·r g'))) ∙h
htpy-inv
( htpy-con-inv _ (front-right ·r g') _
( (htpy-assoc (bottom ·r hA) _ _) ∙h (htpy-inv (c)))))) ∙h
( htpy-inv
( htpy-ap-concat (bottom ·r hA) _ _ htpy-right-unit))))))
is-pullback-bottom-is-pullback-top-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv hA → is-equiv hB → is-equiv hC → is-equiv hD →
is-pullback h' k' (pair f' (pair g' top)) →
is-pullback h k (pair f (pair g bottom))
is-pullback-bottom-is-pullback-top-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-hA is-equiv-hB is-equiv-hC is-equiv-hD is-pb-top =
descent-is-equiv hB h k
( pair f (pair g bottom))
( pair f' (pair hA (htpy-inv (back-left))))
( is-equiv-hB)
( is-equiv-hA)
( is-pullback-htpy
{f = h ∘ hB}
( hD ∘ h')
( front-left)
{g = k}
( k)
( htpy-refl' k)
{ c = pair f'
( pair
( g ∘ hA)
( rectangle-back-left-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))}
( pair
( f')
( pair
( hC ∘ g')
( rectangle-top-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair
( htpy-refl' f')
( pair
( back-right)
( coherence-htpy-square-is-pullback-bottom-is-pullback-top-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)))
( is-pullback-rectangle-is-pullback-left-square
( h')
( hD)
( k)
( pair k' (pair hC (htpy-inv front-right)))
( pair f' (pair g' top))
( is-pullback-is-equiv' hD k
( pair k' (pair hC (htpy-inv front-right)))
( is-equiv-hD)
( is-equiv-hC))
( is-pb-top)))
is-pullback-top-is-pullback-bottom-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv hA → is-equiv hB → is-equiv hC → is-equiv hD →
is-pullback h k (pair f (pair g bottom)) →
is-pullback h' k' (pair f' (pair g' top))
is-pullback-top-is-pullback-bottom-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-hA is-equiv-hB is-equiv-hC is-equiv-hD is-pb-bottom =
is-pullback-top-is-pullback-rectangle h hD k'
( pair hB (pair h' front-left))
( pair f' (pair g' top))
( is-pullback-is-equiv h hD
( pair hB (pair h' front-left))
is-equiv-hD is-equiv-hB)
( is-pullback-htpy' h htpy-refl (k ∘ hC) front-right
( cone-comp-vertical h k hC
( pair f (pair g bottom))
( pair hA (pair g' back-right)))
{ c' = cone-comp-vertical h hD k'
( pair hB (pair h' front-left))
( pair f' (pair g' top))}
( pair back-left
( pair
( htpy-refl)
( ( ( ( htpy-assoc
( bottom ·r hA) (k ·l back-right) (front-right ·r g')) ∙h
( htpy-inv c)) ∙h
( htpy-assoc
( h ·l back-left) (front-left ·r f') (hD ·l top))) ∙h
( htpy-ap-concat'
( h ·l back-left)
( (h ·l back-left) ∙h htpy-refl)
( (front-left ·r f') ∙h (hD ·l top))
( htpy-inv htpy-right-unit)))))
( is-pullback-rectangle-is-pullback-top h k hC
( pair f (pair g bottom))
( pair hA (pair g' back-right))
( is-pb-bottom)
( is-pullback-is-equiv g hC
( pair hA (pair g' back-right))
is-equiv-hC is-equiv-hA)))
is-pullback-front-left-is-pullback-back-right-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv f' → is-equiv f → is-equiv k' → is-equiv k →
is-pullback g hC (pair hA (pair g' back-right)) →
is-pullback h hD (pair hB (pair h' front-left))
is-pullback-front-left-is-pullback-back-right-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-f' is-equiv-f is-equiv-k' is-equiv-k is-pb-back-right =
is-pullback-bottom-is-pullback-top-cube-is-equiv
hB h' h hD hA g' g hC f' f k' k
back-right (htpy-inv back-left) top bottom (htpy-inv front-right) front-left
( coherence-cube-mirror-B f g h k f' g' h' k' hA hB hC hD top
back-left back-right front-left front-right bottom c)
is-equiv-f' is-equiv-f is-equiv-k' is-equiv-k is-pb-back-right
is-pullback-front-right-is-pullback-back-left-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv g' → is-equiv h' → is-equiv g → is-equiv h →
is-pullback f hB (pair hA (pair f' back-left)) →
is-pullback k hD (pair hC (pair k' front-right))
is-pullback-front-right-is-pullback-back-left-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-g' is-equiv-h' is-equiv-g is-equiv-h is-pb-back-left =
is-pullback-bottom-is-pullback-top-cube-is-equiv
hC k' k hD hA f' f hB g' g h' h
back-left (htpy-inv back-right) (htpy-inv top)
( htpy-inv bottom) (htpy-inv front-left) front-right
( coherence-cube-rotate-120 f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)
is-equiv-g' is-equiv-g is-equiv-h' is-equiv-h is-pb-back-left
-- Section 15.2 Fiberwise pullbacks.
{- We show that if we have a square of families, such that the base square is
a pullback square, then each square of fibers is a pullback square if and
only if the square of total spaces is a pullback square. -}
cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
cone f g C → (C → UU l8) → UU (l4 ⊔ (l5 ⊔ (l6 ⊔ (l7 ⊔ l8))))
cone-family {C = C} PX f' g' c PC =
(x : C) →
cone ((tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x))) (g' (pr1 (pr2 c) x)) (PC x)
htpy-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4)
{f f' : A → B} (H : f ~ f') (g : (x : A) → P x → Q (f x)) {g' : (x : A) → P x → Q (f' x)} (K : (x : A) → ((tr Q (H x)) ∘ (g x)) ~ (g' x)) →
(toto Q f g) ~ (toto Q f' g')
htpy-toto Q H g K t = eq-pair (H (pr1 t)) (K (pr1 t) (pr2 t))
tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) → cone-family PX f' g' c PC →
cone (toto PX f f') (toto PX g g') (Σ C PC)
tot-cone-cone-family PX f' g' c c' =
pair
( toto _ (pr1 c) (λ x → pr1 (c' x)))
( pair
( toto _ (pr1 (pr2 c)) (λ x → (pr1 (pr2 (c' x)))))
( htpy-toto PX
( pr2 (pr2 c))
( λ z → (f' (pr1 c z)) ∘ (pr1 (c' z)))
( λ z → pr2 (pr2 (c' z)))))
map-canpb-tot-cone-cone-fam-right-factor :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
Σ ( canonical-pullback f g)
( λ t → canonical-pullback ((tr PX (π₃ t)) ∘ (f' (π₁ t))) (g' (π₂ t))) →
Σ ( Σ A PA)
( λ aa' → Σ (Σ B (λ b → Id (f (pr1 aa')) (g b)))
( λ bα → Σ (PB (pr1 bα))
( λ b' → Id
( tr PX (pr2 bα) (f' (pr1 aa') (pr2 aa')))
( g' (pr1 bα) b'))))
map-canpb-tot-cone-cone-fam-right-factor
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' =
swap-total-Eq-structure
( λ a → Σ B (λ b → Id (f a) (g b)))
( PA)
( λ a bα a' → Σ (PB (pr1 bα))
( λ b' → Id (tr PX (pr2 bα) (f' a a')) (g' (pr1 bα) b')))
map-canpb-tot-cone-cone-fam-left-factor :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) → (aa' : Σ A PA) →
Σ (Σ B (λ b → Id (f (pr1 aa')) (g b)))
( λ bα → Σ (PB (pr1 bα))
( λ b' → Id
( tr PX (pr2 bα) (f' (pr1 aa') (pr2 aa')))
( g' (pr1 bα) b'))) →
Σ ( Σ B PB)
( λ bb' → Σ (Id (f (pr1 aa')) (g (pr1 bb')))
( λ α → Id (tr PX α (f' (pr1 aa') (pr2 aa'))) (g' (pr1 bb') (pr2 bb'))))
map-canpb-tot-cone-cone-fam-left-factor
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' aa' =
( swap-total-Eq-structure
( λ b → Id (f (pr1 aa')) (g b))
( PB)
( λ b α b' → Id (tr PX α (f' (pr1 aa') (pr2 aa'))) (g' b b')))
map-canonical-pullback-tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
Σ ( canonical-pullback f g)
( λ t → canonical-pullback ((tr PX (π₃ t)) ∘ (f' (π₁ t))) (g' (π₂ t))) →
canonical-pullback (toto PX f f') (toto PX g g')
map-canonical-pullback-tot-cone-cone-family
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' =
( tot (λ aa' →
( tot (λ bb' → eq-pair')) ∘
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa'))) ∘
( map-canpb-tot-cone-cone-fam-right-factor PX f' g' c c')
is-equiv-map-canonical-pullback-tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
is-equiv (map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
is-equiv-map-canonical-pullback-tot-cone-cone-family
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' =
is-equiv-comp
( map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( tot (λ aa' →
( tot (λ bb' → eq-pair')) ∘
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa')))
( map-canpb-tot-cone-cone-fam-right-factor PX f' g' c c')
( htpy-refl)
( is-equiv-swap-total-Eq-structure
( λ a → Σ B (λ b → Id (f a) (g b)))
( PA)
( λ a bα a' → Σ (PB (pr1 bα))
( λ b' → Id (tr PX (pr2 bα) (f' a a')) (g' (pr1 bα) b'))))
( is-equiv-tot-is-fiberwise-equiv (λ aa' → is-equiv-comp
( ( tot (λ bb' → eq-pair')) ∘
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa'))
( tot (λ bb' → eq-pair'))
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa')
( htpy-refl)
( is-equiv-swap-total-Eq-structure _ _ _)
( is-equiv-tot-is-fiberwise-equiv (λ bb' → is-equiv-eq-pair
( pair (f (pr1 aa')) (f' (pr1 aa') (pr2 aa')))
( pair (g (pr1 bb')) (g' (pr1 bb') (pr2 bb')))))))
triangle-canonical-pullback-tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
( gap (toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c')) ~
( ( map-canonical-pullback-tot-cone-cone-family PX f' g' c c') ∘
( toto _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x))))
triangle-canonical-pullback-tot-cone-cone-family PX f' g' c c' (pair x y) =
refl
is-pullback-family-is-pullback-tot :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
is-pullback f g c →
is-pullback
(toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c') →
(x : C) →
is-pullback
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)
is-pullback-family-is-pullback-tot
PX {PA} {PB} {PC} {f} {g} f' g' c c' is-pb-c is-pb-tot =
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x))
( is-pb-c)
( is-equiv-right-factor
( gap (toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c'))
( map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( toto _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)))
( triangle-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( is-equiv-map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( is-pb-tot))
is-pullback-tot-is-pullback-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
is-pullback f g c →
( (x : C) →
is-pullback
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)) →
is-pullback
(toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c')
is-pullback-tot-is-pullback-family
PX {PA} {PB} {PC} {f} {g} f' g' c c' is-pb-c is-pb-c' =
is-equiv-comp
( gap (toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c'))
( map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( toto _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)))
( triangle-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x))
( is-pb-c)
( is-pb-c'))
( is-equiv-map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
{- We show that identity types commute with pullbacks. -}
cone-ap :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4}
(f : A → X) (g : B → X) (c : cone f g C) (c1 c2 : C) →
let p = pr1 c
q = pr1 (pr2 c)
H = pr2 (pr2 c)
in
cone
( λ (α : Id (p c1) (p c2)) → (ap f α) ∙ (H c2))
( λ (β : Id (q c1) (q c2)) → (H c1) ∙ (ap g β))
( Id c1 c2)
cone-ap f g (pair p (pair q H)) c1 c2 =
pair
( ap p)
( pair
( ap q)
( λ γ →
( ap (λ t → t ∙ (H c2)) (inv (ap-comp f p γ))) ∙
( ( inv (htpy-nat H γ)) ∙
( ap (λ t → (H c1) ∙ t) (ap-comp g q γ)))))
tr-id-right :
{l1 : Level} {A : UU l1} {a b c : A} (q : Id b c) (p : Id a b) →
Id (tr (λ y → Id a y) q p) (p ∙ q)
tr-id-right refl refl = refl
cone-ap' :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4}
(f : A → X) (g : B → X) (c : cone f g C) (c1 c2 : C) →
let p = pr1 c
q = pr1 (pr2 c)
H = pr2 (pr2 c)
in
cone
( λ (α : Id (p c1) (p c2)) → tr (λ t → Id (f (p c1)) t) (H c2) (ap f α))
( λ (β : Id (q c1) (q c2)) → (H c1) ∙ (ap g β))
( Id c1 c2)
cone-ap' f g (pair p (pair q H)) c1 c2 =
pair
( ap p)
( pair
( ap q)
( λ γ →
( tr-id-right (H c2) (ap f (ap p γ))) ∙
( ( ap (λ t → t ∙ (H c2)) (inv (ap-comp f p γ))) ∙
( ( inv (htpy-nat H γ)) ∙
( ap (λ t → (H c1) ∙ t) (ap-comp g q γ))))))
is-pullback-cone-ap :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4}
(f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c →
(c1 c2 : C) →
let p = pr1 c
q = pr1 (pr2 c)
H = pr2 (pr2 c)
in
is-pullback
( λ (α : Id (p c1) (p c2)) → (ap f α) ∙ (H c2))
( λ (β : Id (q c1) (q c2)) → (H c1) ∙ (ap g β))
( cone-ap f g c c1 c2)
is-pullback-cone-ap f g (pair p (pair q H)) is-pb-c c1 c2 =
is-pullback-htpy'
( λ α → tr (λ x → Id (f (p c1)) x) (H c2) (ap f α))
( λ α → tr-id-right (H c2) (ap f α))
( λ β → (H c1) ∙ (ap g β))
( htpy-refl)
( cone-ap' f g (pair p (pair q H)) c1 c2)
{ c' = cone-ap f g (pair p (pair q H)) c1 c2}
( pair htpy-refl (pair htpy-refl htpy-right-unit))
( is-pullback-family-is-pullback-tot
( λ x → Id (f (p c1)) x)
( λ a → ap f {x = p c1} {y = a})
( λ b β → (H c1) ∙ (ap g β))
( pair p (pair q H))
( cone-ap' f g (pair p (pair q H)) c1)
( is-pb-c)
( is-pullback-is-equiv
( toto _ f (λ a α → ap f α))
( toto _ g (λ b β → (H c1) ∙ (ap g β)))
( tot-cone-cone-family
( Id (f (p c1)))
( λ a → ap f)
( λ b β → (H c1) ∙ (ap g β))
( pair p (pair q H))
( cone-ap' f g (pair p (pair q H)) c1))
( is-equiv-is-contr _
( is-contr-total-path (q c1))
( is-contr-total-path (f (p c1))))
( is-equiv-is-contr _
( is-contr-total-path c1)
( is-contr-total-path (p c1))))
( c2))
{- Next we show that for any commuting cube, if the bottom and top squares are
pullback squares, then so is the square of fibers of the vertical maps in
cube. -}
{-
square-fib-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
(a : A) →
( ( tot (λ d' p → p ∙ (bottom a)) ∘
( fib-square h hD (pair hB (pair h' front-left)) (f a))) ∘
( fib-square f hB (pair hA (pair f' back-left)) a)) ~
( ( fib-square k hD (pair hC (pair k' front-right)) (g a)) ∘
( fib-square g hC (pair hA (pair g' back-right)) a))
square-fib-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
.(hA a') (pair a' refl) =
eq-pair
( pair
( top a')
( ( tr-id-left-subst
( top a')
( k (g (hA a')))
( ( ( inv (front-left (f' a'))) ∙
( ap h ((inv (back-left a')) ∙ refl))) ∙
( bottom (hA a')))) ∙
( ( ( assoc (inv (ap hD (top a'))) _ (bottom (hA a'))) ∙
{!!}) ∙
( distributive-inv-concat (ap k (back-right a')) (front-right (g' a')) ∙
( ( ap
( concat (inv (front-right (g' a'))) ?)
( inv (ap-inv k (back-right a')))) ∙
( ap
( concat (inv (front-right (g' a'))) ?)
( ap (ap k) (inv right-unit))))))))
-}
| 38.61312
| 141
| 0.482303
|
12b37d9c29d3ed147e74cbf6e28996aee663280e
| 10,535
|
agda
|
Agda
|
Cubical/Talks/EPA2020.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Talks/EPA2020.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Talks/EPA2020.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-
Cubical Agda - A Dependently Typed PL with Univalence and HITs
==============================================================
Anders Mörtberg
Every Proof Assistant - September 17, 2020
Link to slides: https://staff.math.su.se/anders.mortberg/slides/EPA2020.pdf
Link to video: https://vimeo.com/459020971
-}
-- To make Agda cubical add the following options
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Talks.EPA2020 where
-- The "Foundations" package contain a lot of important results (in
-- particular the univalence theorem)
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Int
open import Cubical.Data.Prod.Base
-- The interval in Cubical Agda is written I and the endpoints i0 and i1.
apply0 : (A : Type) (p : I → A) → A
apply0 A p = p i0
-- We omit the universe level ℓ for simplicity in this talk. In the
-- library everything is maximally universe polymorphic.
-- We can write functions out of the interval using λ-abstraction:
refl' : {A : Type} (x : A) → x ≡ x
refl' x = λ i → x
-- In fact, x ≡ y is short for PathP (λ _ → A) x y
refl'' : {A : Type} (x : A) → PathP (λ _ → A) x x
refl'' x = λ _ → x
-- In general PathP A x y has A : I → Type, x : A i0 and y : A i1
-- PathP = Dependent paths (Path over a Path)
-- We cannot pattern-match on interval variables as I is not inductively defined
-- foo : {A : Type} → I → A
-- foo r = {!r!} -- Try typing C-c C-c
-- cong has a direct proof
cong' : {A B : Type} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y
cong' f p i = f (p i)
-- function extensionality also has a direct proof.
-- It also has computational content: swap the arguments.
funExt' : {A B : Type} {f g : A → B} (p : (x : A) → f x ≡ g x) → f ≡ g
funExt' p i x = p x i
-- Transport is more complex as ≡ isn't inductively defined (so we
-- can't define it by pattern-matching on p)
transport' : {A B : Type} → A ≡ B → A → B
transport' p a = transp (λ i → p i) i0 a
-- This lets us define subst (which is called "transport" in the HoTT book)
subst' : {A : Type} (P : A → Type) {x y : A} (p : x ≡ y) → P x → P y
subst' P p pa = transport (λ i → P (p i)) pa
-- The transp operation reduces differently for different types
-- formers. For paths it reduces to another primitive operation called
-- hcomp.
-- We can also define the J eliminator (aka path induction)
J' : {A : Type} {B : A → Type} {x : A}
(P : (z : A) → x ≡ z → Type)
(d : P x refl) {y : A} (p : x ≡ y) → P y p
J' P d p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
-- So J is provable, but it doesn't satisfy computation rule
-- definitionally. This is almost never a problem in practice as the
-- cubical primitives satisfy many new definitional equalities.
-- Another key concept in HoTT/UF is the Univalence Axiom. In Cubical
-- Agda this is provable, we hence refer to it as the Univalence
-- Theorem.
-- The univalence theorem: equivalences of types give paths of types
ua' : {A B : Type} → A ≃ B → A ≡ B
ua' = ua
-- Any isomorphism of types gives rise to an equivalence
isoToEquiv' : {A B : Type} → Iso A B → A ≃ B
isoToEquiv' = isoToEquiv
-- And hence to a path
isoToPath' : {A B : Type} → Iso A B → A ≡ B
isoToPath' e = ua' (isoToEquiv' e)
-- ua satisfies the following computation rule
-- This suffices to be able to prove the standard formulation of univalence.
uaβ' : {A B : Type} (e : A ≃ B) (x : A)
→ transport (ua' e) x ≡ fst e x
uaβ' e x = transportRefl (equivFun e x)
-- Time for an example!
-- Booleans
data Bool : Type where
false true : Bool
not : Bool → Bool
not false = true
not true = false
notPath : Bool ≡ Bool
notPath = isoToPath' (iso not not rem rem)
where
rem : (b : Bool) → not (not b) ≡ b
rem false = refl
rem true = refl
_ : transport notPath true ≡ false
_ = refl
-- Another example, integers:
sucPath : Int ≡ Int
sucPath = isoToPath' (iso sucInt predInt sucPred predSuc)
_ : transport sucPath (pos 0) ≡ pos 1
_ = refl
_ : transport (sucPath ∙ sucPath) (pos 0) ≡ pos 2
_ = refl
_ : transport (sym sucPath) (pos 0) ≡ negsuc 0
_ = refl
-----------------------------------------------------------------------------
-- Higher inductive types
-- The following definition of finite multisets is due to Vikraman
-- Choudhury and Marcelo Fiore.
infixr 5 _∷_
data FMSet (A : Type) : Type where
[] : FMSet A
_∷_ : (x : A) → (xs : FMSet A) → FMSet A
comm : (x y : A) (xs : FMSet A) → x ∷ y ∷ xs ≡ y ∷ x ∷ xs
-- trunc : (xs ys : FMSet A) (p q : xs ≡ ys) → p ≡ q
-- We need to add the trunc constructor for FMSets to be sets, omitted
-- here for simplicity.
_++_ : ∀ {A : Type} (xs ys : FMSet A) → FMSet A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ xs ++ ys
comm x y xs i ++ ys = comm x y (xs ++ ys) i
-- trunc xs zs p q i j ++ ys =
-- trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j
unitr-++ : {A : Type} (xs : FMSet A) → xs ++ [] ≡ xs
unitr-++ [] = refl
unitr-++ (x ∷ xs) = cong (x ∷_) (unitr-++ xs)
unitr-++ (comm x y xs i) j = comm x y (unitr-++ xs j) i
-- unitr-++ (trunc xs ys x y i j) = {!!}
-- This is a special case of set quotients! Very useful for
-- programming and set level mathematics
data _/_ (A : Type) (R : A → A → Type) : Type where
[_] : A → A / R
eq/ : (a b : A) → R a b → [ a ] ≡ [ b ]
trunc : (a b : A / R) (p q : a ≡ b) → p ≡ q
-- Proving that they are effective ((a b : A) → [ a ] ≡ [ b ] → R a b)
-- requires univalence for propositions.
-------------------------------------------------------------------------
-- Topological examples of things that are not sets
-- We can define the circle as the following simple data declaration:
data S¹ : Type where
base : S¹
loop : base ≡ base
-- We can write functions on S¹ using pattern-matching equations:
double : S¹ → S¹
double base = base
double (loop i) = (loop ∙ loop) i
helix : S¹ → Type
helix base = Int
helix (loop i) = sucPathInt i
ΩS¹ : Type
ΩS¹ = base ≡ base
winding : ΩS¹ → Int
winding p = subst helix p (pos 0)
_ : winding (λ i → double ((loop ∙ loop) i)) ≡ pos 4
_ = refl
-- We can define the Torus as:
data Torus : Type where
point : Torus
line1 : point ≡ point
line2 : point ≡ point
square : PathP (λ i → line1 i ≡ line1 i) line2 line2
-- And prove that it is equivalent to two circle:
t2c : Torus → S¹ × S¹
t2c point = (base , base)
t2c (line1 i) = (loop i , base)
t2c (line2 j) = (base , loop j)
t2c (square i j) = (loop i , loop j)
c2t : S¹ × S¹ → Torus
c2t (base , base) = point
c2t (loop i , base) = line1 i
c2t (base , loop j) = line2 j
c2t (loop i , loop j) = square i j
c2t-t2c : (t : Torus) → c2t (t2c t) ≡ t
c2t-t2c point = refl
c2t-t2c (line1 _) = refl
c2t-t2c (line2 _) = refl
c2t-t2c (square _ _) = refl
t2c-c2t : (p : S¹ × S¹) → t2c (c2t p) ≡ p
t2c-c2t (base , base) = refl
t2c-c2t (base , loop _) = refl
t2c-c2t (loop _ , base) = refl
t2c-c2t (loop _ , loop _) = refl
-- Using univalence we get the following equality:
Torus≡S¹×S¹ : Torus ≡ S¹ × S¹
Torus≡S¹×S¹ = isoToPath' (iso t2c c2t t2c-c2t c2t-t2c)
windingTorus : point ≡ point → Int × Int
windingTorus l = ( winding (λ i → proj₁ (t2c (l i)))
, winding (λ i → proj₂ (t2c (l i))))
_ : windingTorus (line1 ∙ sym line2) ≡ (pos 1 , negsuc 0)
_ = refl
-- We have many more topological examples, including Klein bottle, RP^n,
-- higher spheres, suspensions, join, wedges, smash product:
open import Cubical.HITs.KleinBottle
open import Cubical.HITs.RPn
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.HITs.Susp
open import Cubical.HITs.Join
open import Cubical.HITs.Wedge
open import Cubical.HITs.SmashProduct
-- There's also a proof of the "3x3 lemma" for pushouts in less than
-- 200LOC. In HoTT-Agda this took about 3000LOC. For details see:
-- https://github.com/HoTT/HoTT-Agda/tree/master/theorems/homotopy/3x3
open import Cubical.HITs.Pushout
-- We also defined the Hopf fibration and proved that its total space
-- is S³ in about 300LOC:
open import Cubical.HITs.Hopf
-- There is also some integer cohomology:
open import Cubical.ZCohomology.Everything
-- To compute cohomology groups of various spaces we need a bunch of
-- interesting theorems: Freudenthal suspension theorem,
-- Mayer-Vietoris sequence...
open import Cubical.Homotopy.Freudenthal
open import Cubical.ZCohomology.MayerVietorisUnreduced
-------------------------------------------------------------------------
-- The structure identity principle
-- A more efficient version of finite multisets based on association lists
open import Cubical.HITs.AssocList.Base
-- data AssocList (A : Type) : Type where
-- ⟨⟩ : AssocList A
-- ⟨_,_⟩∷_ : (a : A) (n : ℕ) (xs : AssocList A) → AssocList A
-- per : (a b : A) (m n : ℕ) (xs : AssocList A)
-- → ⟨ a , m ⟩∷ ⟨ b , n ⟩∷ xs ≡ ⟨ b , n ⟩∷ ⟨ a , m ⟩∷ xs
-- agg : (a : A) (m n : ℕ) (xs : AssocList A)
-- → ⟨ a , m ⟩∷ ⟨ a , n ⟩∷ xs ≡ ⟨ a , m + n ⟩∷ xs
-- del : (a : A) (xs : AssocList A) → ⟨ a , 0 ⟩∷ xs ≡ xs
-- trunc : (xs ys : AssocList A) (p q : xs ≡ ys) → p ≡ q
-- Programming and proving is more complicated with AssocList compared
-- to FMSet. This kind of example occurs everywhere in programming and
-- mathematics: one representation is easier to work with, but not
-- efficient, while another is efficient but difficult to work with.
-- Solution: substitute using univalence
substIso : {A B : Type} (P : Type → Type) (e : Iso A B) → P A → P B
substIso P e = subst P (isoToPath e)
-- Can transport for example Monoid structure from FMSet to AssocList
-- this way, but the achieved Monoid structure is not very efficient
-- to work with. A better solution is to prove that FMSet and
-- AssocList are equal *as monoids*, but how to do this?
-- Solution: structure identity principle (SIP)
-- This is a very useful consequence of univalence
open import Cubical.Foundations.SIP
sip' : {ℓ : Level} {S : Type ℓ → Type ℓ} {ι : StrEquiv S ℓ}
(θ : UnivalentStr S ι) (A B : TypeWithStr ℓ S) → A ≃[ ι ] B → A ≡ B
sip' = sip
-- The tricky thing is to prove that (S,ι) is a univalent structure.
-- Luckily we provide automation for this in the library, see for example:
open import Cubical.Algebra.Monoid.Base
-- Another cool application of the SIP: matrices represented as
-- functions out of pairs of Fin's and vectors are equal as abelian
-- groups:
open import Cubical.Algebra.Matrix
-- The end, back to slides!
| 30.804094
| 80
| 0.628761
|
29455105466e2c0710751d67a7c71130f1da17c3
| 2,005
|
agda
|
Agda
|
src/parse-test.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/parse-test.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/parse-test.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
module parse-test where
import parse
open import lib
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
parse-specific-nt : cedille.gratr2-nt → ℕ → (lc : 𝕃 char) → 𝕃 char ⊎ Run
parse-specific-nt nt starting-char-position lc with parse-filter lc lc [] [] (cedille.cedille-start nt) inj₁
...| inj₁ left = inj₁ left
...| inj₂ run = inj₂ (re-to-run starting-char-position (reverse run))
processArgs : (showRun : 𝔹) → (showParsed : 𝔹) → 𝕃 string → IO ⊤
processArgs showRun showParsed (input-filename :: []) = (readFiniteFile input-filename) >>= processText
where processText : string → IO ⊤
processText x with parse-specific-nt cedille._type 10 (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
| 41.770833
| 154
| 0.675312
|
2264bf341c01cdbea16439a39a0dfe442543fbc4
| 323
|
agda
|
Agda
|
Base/Core.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
Base/Core.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
Base/Core.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
module M-types.Base.Core where
open import Agda.Primitive public using (Level) renaming
(
lzero to ℓ-zero ;
lsuc to ℓ-suc ;
_⊔_ to ℓ-max
)
variable
ℓ ℓ₀ ℓ₁ ℓ₂ : Level
Ty : (ℓ : Level) → Set (ℓ-suc ℓ)
Ty ℓ = Set ℓ
| 17
| 60
| 0.495356
|
a19764406c331675c9e58b0335dbcfb8042fedb3
| 1,866
|
agda
|
Agda
|
test/Succeed/Erasure-succeed-Issue3855.agda
|
hborum/agda
|
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Erasure-succeed-Issue3855.agda
|
hborum/agda
|
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Erasure-succeed-Issue3855.agda
|
hborum/agda
|
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
|
[
"BSD-3-Clause"
] | 1
|
2021-04-01T18:30:09.000Z
|
2021-04-01T18:30:09.000Z
|
-- Andreas, 2019-06-18, LAIM 2019, issue #3855:
-- Successful tests for the erasure (@0) modality.
module _ where
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Coinduction
open import Common.IO
module WhereInErasedDeclaration where
@0 n : Nat
n = 4711
@0 m : Nat
m = n'
where
n' = n
module ErasedDeclarationInWhere where
F : (G : @0 Set → Set) (@0 A : Set) → Set
F G A = G B
where
@0 B : Set
B = A
module FlatErasure where
@0 resurrect-λ : (A : Set) (@0 x : A) → A
resurrect-λ A = λ x → x
@0 resurrect-λ-where : (A : Set) (@0 x : A) → A
resurrect-λ-where A = λ where x → x
@0 resurrect-app : (A : Set) (@0 x : A) → A
resurrect-app A x = x
module ErasedEquality where
-- Should maybe not work --without-K
-- should definitely not work in --cubical
cast : ∀{A B : Set} → @0 A ≡ B → A → B
cast refl x = x
J : ∀{A : Set} {a : A} (P : (x : A) → a ≡ x → Set) {b : A}
(@0 eq : a ≡ b) → P a refl → P b eq
J P refl p = p
module ParametersAreErased where
test : (@0 A : Set) → A ≡ A
test A = refl {x = _} -- TODO: A instead of _
module Records where
record R (A : Set) : Set where
field
el : A
Par : Set
Par = A -- record module parameters are NOT erased, so, this should be accepted
proj : (A : Set) → R A → A -- TODO: @0 A instead of A
proj A r = R.el {A = _} r
MyPar : (A : Set) → R A → Set
MyPar A = R.Par {A = A}
record RB (b : Bool) : Set where
bPar : Bool
bPar = b
myBPar : (b : Bool) → RB b → Bool
myBPar b r = RB.bPar {b = b} r
module CoinductionWithErasure (A : Set) where
data Stream : Set where
cons : (x : A) (xs : ∞ Stream) → Stream
@0 repeat : (@0 a : A) → Stream
repeat a = cons a (♯ (repeat a))
main = putStrLn "Hello, world!"
| 20.966292
| 86
| 0.571811
|
c74cfbe9477a23d35887b5d00786da5c0353a369
| 3,934
|
agda
|
Agda
|
src/Data/Graph/Path/Search.agda
|
kcsmnt0/graph
|
0196cf8a136a4933cd6358e4c9692aaf919ca603
|
[
"MIT"
] | null | null | null |
src/Data/Graph/Path/Search.agda
|
kcsmnt0/graph
|
0196cf8a136a4933cd6358e4c9692aaf919ca603
|
[
"MIT"
] | null | null | null |
src/Data/Graph/Path/Search.agda
|
kcsmnt0/graph
|
0196cf8a136a4933cd6358e4c9692aaf919ca603
|
[
"MIT"
] | null | null | null |
open import Data.Graph
module Data.Graph.Path.Search {ℓᵥ ℓₑ} (g : FiniteGraph ℓᵥ ℓₑ) where
open import Data.Graph.Path.Cut g
open import Data.Graph.Path.Finite g
open import Data.Product as Σ
open import Data.Sum as ⊎
open import Data.Vec as Vec
open import Finite
open import Function
open import Level
open import Relation.Binary
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary hiding (module Dec)
open import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Negation as ¬
open FiniteGraph g
open IsFinite
pathSearchFrom : ∀ {ℓ} {P : Vertex → Set ℓ} →
(∀ b → Dec (P b)) → ∀ a → Dec (∃ λ b → P b × ∃ (Path a b))
pathSearchFrom P? a =
case ∃? (Path≤-finite (size vertexFinite) a) (P? ∘ proj₁) of λ where
(yes ((_ , _ , _ , p) , pb)) → yes (-, pb , (-, p))
(no ¬p) → no λ where (_ , pb , _ , p) → ¬p ((-, shortEnoughPath p) , pb)
pathSearchAcyclicFrom : ∀ {ℓ} {P : Vertex → Set ℓ} →
(∀ b → Dec (P b)) → ∀ a →
Dec (∃ λ b → P b × ∃₂ λ n (p : Path a b n) → Acyclic p)
pathSearchAcyclicFrom P? a =
case ∃? (Path≤-finite (size vertexFinite) a) (P? ∘ proj₁) of λ where
(yes ((_ , _ , _ , p) , pb)) →
let (x , x≤n , p′) , ¬r′ = acyclicPath p in
yes (-, pb , (-, (p′ , ¬r′)))
(no ¬p) → no λ where (_ , pb , _ , p , r) → ¬p ((-, shortEnoughPath p) , pb)
pathSearchBetween : ∀ a b → Dec (∃ (Path a b))
pathSearchBetween a b =
case pathSearchFrom (decEqVertex b) a of λ where
(yes (_ , refl , p)) → yes p
(no ¬p) → no λ where (n , p) → ¬p (-, refl , -, p)
searchFrom : ∀ {ℓ} {P : Vertex → Set ℓ} →
(∀ b → Dec (P b)) →
∀ a → Dec (∃ λ b → P b × Star Edge a b)
searchFrom P? a =
Dec.map′
(Σ.map₂ (Σ.map₂ (toStar ∘ proj₂)))
(Σ.map₂ (Σ.map₂ (-,_ ∘ fromStar)))
(pathSearchFrom P? a)
searchBetween : ∀ a b → Dec (Star Edge a b)
searchBetween a b = Dec.map′ (toStar ∘ proj₂) (-,_ ∘ fromStar) (pathSearchBetween a b)
module _
{ℓ ℓ≈ ℓ<}
{P : Vertex → Set ℓ} (P? : ∀ a → Dec (P a))
{_≈_ : ∀ {a} → Rel (∃ (Star Edge a)) ℓ≈}
{_<_ : ∀ {a} → Rel (∃ (Star Edge a)) ℓ<}
(<-po : ∀ {a} → IsDecStrictPartialOrder (_≈_ {a}) _<_)
where
record MaximalPath a : Set (ℓ ⊔ ℓᵥ ⊔ ℓₑ ⊔ ℓ<) where
field
destination : Vertex
predicate : P destination
path : Star Edge a destination
acyclic : Acyclic (fromStar path)
isMax : ∀
{b} (p : Star Edge a b) (pb : P b) → Acyclic (fromStar p) →
¬ ((-, path) < (-, p))
searchMaximalFrom : ∀ a → Dec (MaximalPath a)
searchMaximalFrom a =
case max of λ where
(inj₁ ¬p) →
no λ mp →
let open MaximalPath mp in
¬p ((-, path , fromWitness acyclic) , fromWitness predicate)
(inj₂ (((b , p , acp) , pb) , isMax)) →
yes record
{ destination = b
; predicate = toWitness pb
; path = p
; acyclic = toWitness acp
; isMax = λ q pb acq → isMax ((-, q , fromWitness acq) , fromWitness pb)
}
where
module DPO = IsDecStrictPartialOrder <-po
_≈′_ = _≈_ on λ where ((b , p , acp) , pb) → b , p
_<′_ = _<_ on λ where ((b , p , acp) , pb) → b , p
<′-IsDecStrictPartialOrder : IsDecStrictPartialOrder _≈′_ _<′_
<′-IsDecStrictPartialOrder = record
{ isStrictPartialOrder = record
{ isEquivalence = record
{ refl = IsEquivalence.refl DPO.isEquivalence
; sym = IsEquivalence.sym DPO.isEquivalence
; trans = IsEquivalence.trans DPO.isEquivalence
}
; irrefl = DPO.irrefl
; trans = DPO.trans
; <-resp-≈ = proj₁ DPO.<-resp-≈ , proj₂ DPO.<-resp-≈
}
; _≟_ = λ _ _ → _ DPO.≟ _
; _<?_ = λ _ _ → _ DPO.<? _
}
acyclicPaths = filter (AcyclicStar-finite a) (P? ∘ proj₁)
open Ordered acyclicPaths <′-IsDecStrictPartialOrder
| 33.623932
| 86
| 0.562023
|
d08b4abb76e3ba1061ba10698fbda63be2a97dbd
| 2,897
|
agda
|
Agda
|
examples/outdated-and-incorrect/Termination/comb.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/Termination/comb.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/Termination/comb.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module comb where
infixr 50 _⟶_
data Ty : Set where
ι : Ty
_⟶_ : Ty -> Ty -> Ty
data Tm : Ty -> Set where
K : {σ τ : Ty} -> Tm (σ ⟶ τ ⟶ σ)
S : {σ τ ρ : Ty} -> Tm ((σ ⟶ τ ⟶ ρ) ⟶ (σ ⟶ τ) ⟶ σ ⟶ ρ)
_$_ : {σ τ : Ty} -> Tm (σ ⟶ τ) -> Tm σ -> Tm τ
data Nf : Ty -> Set where
Kⁿ : {σ τ : Ty} -> Nf (σ ⟶ τ ⟶ σ)
Kⁿ¹ : {σ τ : Ty} -> Nf σ -> Nf (τ ⟶ σ)
Sⁿ : {σ τ ρ : Ty} -> Nf ((σ ⟶ τ ⟶ ρ) ⟶ (σ ⟶ τ) ⟶ σ ⟶ ρ)
Sⁿ¹ : {σ τ ρ : Ty} -> Nf (σ ⟶ τ ⟶ ρ) -> Nf ((σ ⟶ τ) ⟶ σ ⟶ ρ)
Sⁿ² : {σ τ ρ : Ty} -> Nf (σ ⟶ τ ⟶ ρ) -> Nf (σ ⟶ τ) -> Nf (σ ⟶ ρ)
_$$_ : {σ τ : Ty} -> Nf (σ ⟶ τ) -> Nf σ -> Nf τ
Kⁿ $$ x = Kⁿ¹ x
Kⁿ¹ x $$ y = x
Sⁿ $$ x = Sⁿ¹ x
Sⁿ¹ x $$ y = Sⁿ² x y
Sⁿ² x y $$ z = (x $$ z) $$ (y $$ z)
nf : {σ : Ty} -> Tm σ -> Nf σ
nf K = Kⁿ
nf S = Sⁿ
nf (t $ u) = nf t $$ nf u
data _$ⁿ_⇓_ : {σ τ : Ty} -> Nf (σ ⟶ τ) -> Nf σ -> Nf τ -> Set where
rKⁿ : {σ τ : Ty} -> {x : Nf σ} -> Kⁿ {σ} {τ} $ⁿ x ⇓ Kⁿ¹ x
rKⁿ¹ : {σ τ : Ty} -> {x : Nf σ} -> {y : Nf τ} -> Kⁿ¹ x $ⁿ y ⇓ x
rSⁿ : {σ τ ρ : Ty} -> {x : Nf (σ ⟶ τ ⟶ ρ)} -> Sⁿ $ⁿ x ⇓ Sⁿ¹ x
rSⁿ¹ : {σ τ ρ : Ty} -> {x : Nf (σ ⟶ τ ⟶ ρ)} -> {y : Nf (σ ⟶ τ)} ->
Sⁿ¹ x $ⁿ y ⇓ Sⁿ² x y
rSⁿ² : {σ τ ρ : Ty} -> {x : Nf (σ ⟶ τ ⟶ ρ)} -> {y : Nf (σ ⟶ τ)} ->
{z : Nf σ} -> {u : Nf (τ ⟶ ρ)} -> x $ⁿ z ⇓ u -> {v : Nf τ} ->
y $ⁿ z ⇓ v -> {w : Nf ρ} -> u $ⁿ v ⇓ w -> Sⁿ² x y $ⁿ z ⇓ w
data _⇓_ : {σ : Ty} -> Tm σ -> Nf σ -> Set where
rK : {σ τ : Ty} -> K {σ} {τ} ⇓ Kⁿ
rS : {σ τ ρ : Ty} -> S {σ} {τ} {ρ} ⇓ Sⁿ
r$ : {σ τ : Ty} -> {t : Tm (σ ⟶ τ)} -> {f : Nf (σ ⟶ τ)} -> t ⇓ f ->
{u : Tm σ} -> {a : Nf σ} -> u ⇓ a -> {v : Nf τ} -> f $ⁿ a ⇓ v ->
t $ u ⇓ v
data _==_ {A : Set}(a : A) : {B : Set} -> (b : B) -> Set where
refl : a == a
data Σ {A : Set}(B : A -> Set) : Set where
sig : (a : A) -> (b : B a) -> Σ B
σ₀ : {A : Set} -> {B : A -> Set} -> Σ B -> A
σ₀ (sig x _) = x
σ₁ : {A : Set} -> {B : A -> Set} -> (s : Σ B) -> B (σ₀ s)
σ₁ (sig _ y) = y
_$$⁼_&_ : {σ τ : Ty} -> (f : Nf (σ ⟶ τ)) -> (a : Nf σ) -> {n : Nf τ} ->
f $ⁿ a ⇓ n -> Σ \(n' : Nf τ) -> n' == n
Kⁿ $$⁼ x & rKⁿ = sig (Kⁿ¹ x) refl
Kⁿ¹ x $$⁼ y & rKⁿ¹ = sig x refl
Sⁿ $$⁼ x & rSⁿ = sig (Sⁿ¹ x) refl
Sⁿ¹ x $$⁼ y & rSⁿ¹ = sig (Sⁿ² x y) refl
Sⁿ² x y $$⁼ z & (rSⁿ² p q r) with x $$⁼ z & p | y $$⁼ z & q
Sⁿ² x y $$⁼ z & (rSⁿ² p q r) | sig u refl | sig v refl with u $$⁼ v & r
Sⁿ² x y $$⁼ z & (rSⁿ² p q r) | sig u refl | sig v refl | sig w refl =
sig w refl
nf⁼ : {σ : Ty} -> (t : Tm σ) -> {n : Nf σ} -> t ⇓ n ->
Σ \(n' : Nf σ) -> n' == n
nf⁼ K rK = sig Kⁿ refl
nf⁼ S rS = sig Sⁿ refl
nf⁼ (t $ u) (r$ p q r) with nf⁼ t p | nf⁼ u q
nf⁼ (t $ u) (r$ p q r) | sig f refl | sig a refl with f $$⁼ a & r
nf⁼ (t $ u) (r$ p q r) | sig f refl | sig a refl | sig v refl =
sig v refl
proof : {σ : Ty} -> (t : Tm σ) -> Σ \(n : Nf σ) -> t ⇓ n
proof = {! !}
nf⇓ : {σ : Ty} -> Tm σ -> Nf σ
nf⇓ t = σ₀ (nf⁼ t (σ₁ (proof t)))
| 32.550562
| 76
| 0.369693
|
316e4ebe8e0851c869709208307c12bed232a1ea
| 11,855
|
agda
|
Agda
|
Cubical/Foundations/Logic.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Logic.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Logic.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Logic where
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.Foundations.Prelude as FP
open import Cubical.Functions.Embedding
open import Cubical.Functions.Fibration as Fib
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation as PropTrunc
open import Cubical.Foundations.HLevels using (hProp; isPropΠ; isPropΠ2; isSetΠ; isSetHProp; isOfHLevelΣ; isPropΣ) public
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Univalence using (ua)
open import Cubical.Relation.Nullary hiding (¬_)
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 ⇐∶_⇒∶_
--------------------------------------------------------------------------------
-- 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 ℓ
[_] : hProp ℓ → Type ℓ
[_] = fst
isProp[] : (A : hProp ℓ) → isProp [ A ]
isProp[] = snd
∥_∥ₚ : Type ℓ → hProp ℓ
∥ A ∥ₚ = ∥ A ∥ , propTruncIsProp
_≡ₚ_ : (x y : A) → hProp _
x ≡ₚ y = ∥ x ≡ y ∥ₚ
hProp≡ : [ P ] ≡ [ Q ] → P ≡ Q
hProp≡ p = Σ≡Prop (\ _ → isPropIsProp) p
--------------------------------------------------------------------------------
-- 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≡ (isoToPath
(iso P⇒Q Q⇒P (λ b → isProp[] Q (P⇒Q (Q⇒P b)) b) λ a → isProp[] P (Q⇒P (P⇒Q a)) a))
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)
--------------------------------------------------------------------------------
-- Introduce the "powerset" of a type in the style of Escardó's lecture notes:
-- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#propositionalextensionality
ℙ : ∀ {ℓ} → Type ℓ → Type (ℓ-suc ℓ)
ℙ {ℓ} X = X → hProp ℓ
infix 5 _∈_
_∈_ : {X : Type ℓ} → X → ℙ X → Type ℓ
x ∈ A = [ A x ]
_⊆_ : {X : Type ℓ} → ℙ X → ℙ X → Type ℓ
A ⊆ B = ∀ x → x ∈ A → x ∈ B
∈-isProp : {X : Type ℓ} (A : ℙ X) (x : X) → isProp (x ∈ A)
∈-isProp A = isProp[] ∘ A
⊆-isProp : {X : Type ℓ} (A B : ℙ X) → isProp (A ⊆ B)
⊆-isProp A B = isPropΠ2 (λ x _ → ∈-isProp B x)
⊆-refl : {X : Type ℓ} (A : ℙ X) → A ⊆ A
⊆-refl A x = idfun (x ∈ A)
⊆-refl-consequence : {X : Type ℓ} (A B : ℙ X)
→ A ≡ B → (A ⊆ B) × (B ⊆ A)
⊆-refl-consequence {X} A B p = subst (λ B → (A ⊆ B)) p (⊆-refl A) , subst (λ A → (B ⊆ A)) (sym p) (⊆-refl B)
⊆-extensionality : {X : Type ℓ} (A B : ℙ X)
→ (A ⊆ B) × (B ⊆ A) → A ≡ B
⊆-extensionality A B (φ , ψ) i x = ⇔toPath {P = (A x)} {Q = (B x)} (φ x) (ψ x) i
powersets-are-sets : {X : Type ℓ} → isSet (ℙ X)
powersets-are-sets {X = X} = isSetΠ (λ _ → isSetHProp)
⊆-extensionalityEquiv : {X : Type ℓ} (A B : ℙ X)
→ (A ⊆ B) × (B ⊆ A) ≃ (A ≡ B)
⊆-extensionalityEquiv A B = isoToEquiv (iso (⊆-extensionality A B)
(⊆-refl-consequence A B)
(λ _ → powersets-are-sets A B _ _)
(λ _ → isPropΣ (⊆-isProp A B) (λ _ → ⊆-isProp B A) _ _))
-- We show that the powerset is the subtype classifier
-- i.e. ℙ X ≃ Σ[A ∈ Type ℓ] (A ↪ X)
Embedding→Subset : {X : Type ℓ} → Σ[ A ∈ Type ℓ ] (A ↪ X) → ℙ X
Embedding→Subset (_ , f , isPropFiber) x = fiber f x , isPropFiber x
Subset→Embedding : {X : Type ℓ} → ℙ X → Σ[ A ∈ Type ℓ ] (A ↪ X)
Subset→Embedding {X = X} A = D , f , ψ
where
D = Σ[ x ∈ X ] x ∈ A
f : D → X
f d = d .fst
ψ : hasPropFibers f
ψ x ((y , y∈A) , y≡x) ((z , z∈A) , z≡x) = ΣPathP (r , q)
where
p : y ≡ z
p = y≡x ∙ sym z≡x
r : (y , y∈A) ≡ (z , z∈A)
r = Σ≡Prop (∈-isProp A) p
q : PathP (λ i → p i ≡ x) y≡x z≡x
q i j = hcomp (λ k → λ { (j = i1) → x
; (i = i0) → y≡x j
; (i = i1) → z≡x (~ k ∨ j) })
(y≡x (i ∨ j))
Subset→Embedding→Subset : {X : Type ℓ} → section (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Subset→Embedding→Subset _ = funExt λ x → Σ≡Prop (λ _ → FP.isPropIsProp) (ua (Fib.FiberIso.fiberEquiv _ x))
Embedding→Subset→Embedding : {X : Type ℓ} → retract (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Embedding→Subset→Embedding {ℓ = ℓ} {X = X} (A , f , ψ) = cong (Σ-assoc-≃ .fst) p
where
χ = Subset→Embedding (Embedding→Subset (A , f , ψ)) .snd .snd
p : (((Σ[ x ∈ X ] fiber f x) , fst) , χ) ≡ ((A , f) , ψ)
p = Σ≡Prop (λ _ → hasPropFibersIsProp) ((equivToIso (Fib.fibrationEquiv X ℓ)) .Iso.leftInv (A , f))
Subset≃Embedding : {X : Type ℓ} → ℙ X ≃ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≃Embedding = isoToEquiv (iso Subset→Embedding Embedding→Subset Embedding→Subset→Embedding Subset→Embedding→Subset)
Subset≡Embedding : {X : Type ℓ} → ℙ X ≡ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≡Embedding = ua Subset≃Embedding
| 31.445623
| 121
| 0.431717
|
22e8a27442c92ee48072d4de492520c077fe99e1
| 30,588
|
agda
|
Agda
|
src/Container/Indexed/Variant.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Container/Indexed/Variant.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Container/Indexed/Variant.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Another definition of indexed containers
------------------------------------------------------------------------
-- Partly based on "Indexed containers" by Altenkirch, Ghani, Hancock,
-- McBride and Morris, and partly based on "Non-wellfounded trees in
-- Homotopy Type Theory" by Ahrens, Capriotti and Spadotti.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Container.Indexed.Variant
{e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
import Bijection eq as B
open import Container.Indexed eq as C
using (_⇾_; id⇾; _∘⇾_; Shape; Position; index)
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq as F hiding (id; _∘_)
open import H-level.Closure eq
open import Tactic.Sigma-cong eq
open import Univalence-axiom eq
private
variable
a ℓ p p₁ p₂ p′ q : Level
A I O : Type a
P Q R : A → Type p
ext f i k o s : A
------------------------------------------------------------------------
-- Containers
-- Doubly indexed containers.
record Container₂
(I : Type i) (O : Type o) s p :
Type (i ⊔ o ⊔ lsuc (s ⊔ p)) where
constructor _◁_
field
Shape : O → Type s
Position : ∀ {o} → Shape o → I → Type p
open Container₂ public
-- Singly indexed containers.
Container : Type i → ∀ s p → Type (i ⊔ lsuc (s ⊔ p))
Container I = Container₂ I I
private
variable
C : Container₂ I O s p
-- Container₂ can be expressed as a Σ-type.
Container≃Σ :
Container₂ I O s p ≃
(∃ λ (S : O → Type s) → ∀ {o} → S o → I → Type p)
Container≃Σ = Eq.↔→≃ (λ (S ◁ P) → S , P) (uncurry _◁_) refl refl
------------------------------------------------------------------------
-- Polynomial functors
-- The polynomial functor associated to a container.
⟦_⟧ :
{I : Type i} {O : Type o} →
Container₂ I O s p → (I → Type ℓ) → O → Type (ℓ ⊔ i ⊔ s ⊔ p)
⟦ S ◁ P ⟧ Q o = ∃ λ (s : S o) → P s ⇾ Q
-- A map function.
map : (C : Container₂ I O s p) → P ⇾ Q → ⟦ C ⟧ P ⇾ ⟦ C ⟧ Q
map C f _ (s , g) = s , f ∘⇾ g
-- Functor laws.
map-id : map C (id⇾ {P = P}) ≡ id⇾
map-id = refl _
map-∘ :
(f : Q ⇾ R) (g : P ⇾ Q) →
map C (f ∘⇾ g) ≡ map C f ∘⇾ map C g
map-∘ _ _ = refl _
-- A preservation lemma.
⟦⟧-cong :
{I : Type i} {P₁ : I → Type p₁} {P₂ : I → Type p₂} →
Extensionality? k (i ⊔ p) (p ⊔ p₁ ⊔ p₂) →
(C : Container₂ I O s p) →
(∀ i → P₁ i ↝[ k ] P₂ i) →
(∀ o → ⟦ C ⟧ P₁ o ↝[ k ] ⟦ C ⟧ P₂ o)
⟦⟧-cong {i = i} {k = k} {p = p} {P₁ = Q₁} {P₂ = Q₂}
ext (S ◁ P) Q₁↝Q₂ o =
(∃ λ (s : S o) → P s ⇾ Q₁) ↝⟨ (∃-cong λ _ →
∀-cong (lower-extensionality? k p lzero ext) λ _ →
∀-cong (lower-extensionality? k i p ext) λ _ →
Q₁↝Q₂ _) ⟩□
(∃ λ (s : S o) → P s ⇾ Q₂) □
-- The forward direction of ⟦⟧-cong is an instance of map (at least
-- when k is equivalence).
_ : _≃_.to (⟦⟧-cong ext C f o) ≡ map C (_≃_.to ∘ f) o
_ = refl _
-- The shapes of a container are pointwise equivalent to the
-- polynomial functor of the container applied to the constant
-- function yielding the unit type.
--
-- (This lemma was suggested to me by an anonymous reviewer of a
-- paper.)
Shape≃⟦⟧⊤ :
(C : Container₂ I O s p) →
Shape C o ≃ ⟦ C ⟧ (λ _ → ⊤) o
Shape≃⟦⟧⊤ {o = o} (S ◁ P) =
S o ↔⟨ inverse $ drop-⊤-right (λ _ → →-right-zero F.∘ inverse currying) ⟩□
(∃ λ (s : S o) → ∀ i → P s i → ⊤) □
------------------------------------------------------------------------
-- Coalgebras
-- The type of coalgebras for a (singly indexed) container.
Coalgebra : {I : Type i} → Container I s p → Type (lsuc (i ⊔ s ⊔ p))
Coalgebra {i = i} {s = s} {p = p} {I = I} C =
∃ λ (P : I → Type (i ⊔ s ⊔ p)) → P ⇾ ⟦ C ⟧ P
-- Coalgebra morphisms.
infix 4 _⇨_
_⇨_ :
{I : Type i} {C : Container I s p} →
Coalgebra C → Coalgebra C → Type (i ⊔ s ⊔ p)
(P , f) ⇨ (Q , g) = ∃ λ (h : P ⇾ Q) → g ∘⇾ h ≡ map _ h ∘⇾ f
private
variable
X Y Z : Coalgebra C
-- An identity morphism.
id⇨ : X ⇨ X
id⇨ = id⇾ , refl _
-- Composition for _⇨_.
infix 9 [_]_∘⇨_
[_]_∘⇨_ : ∀ Z → Y ⇨ Z → X ⇨ Y → X ⇨ Z
[_]_∘⇨_ {Y = _ , g} {X = _ , f} (_ , h) (f₁ , eq₁) (f₂ , eq₂) =
f₁ ∘⇾ f₂
, (h ∘⇾ (f₁ ∘⇾ f₂) ≡⟨⟩
(h ∘⇾ f₁) ∘⇾ f₂ ≡⟨ cong (_∘⇾ f₂) eq₁ ⟩
(map _ f₁ ∘⇾ g) ∘⇾ f₂ ≡⟨⟩
map _ f₁ ∘⇾ (g ∘⇾ f₂) ≡⟨ cong (map _ f₁ ∘⇾_) eq₂ ⟩
map _ f₁ ∘⇾ (map _ f₂ ∘⇾ f) ≡⟨⟩
map _ (f₁ ∘⇾ f₂) ∘⇾ f ∎)
-- The property of being a final coalgebra.
Final :
{I : Type i} {C : Container I s p} →
Coalgebra C → Type (lsuc (i ⊔ s ⊔ p))
Final X = ∀ Y → Contractible (Y ⇨ X)
-- A perhaps more traditional definition of what it means to be final.
Final′ :
{I : Type i} {C : Container I s p} →
Coalgebra C → Type (lsuc (i ⊔ s ⊔ p))
Final′ X =
∀ Y → ∃ λ (m : Y ⇨ X) → (m′ : Y ⇨ X) → proj₁ m ≡ proj₁ m′
-- Final X implies Final′ X.
Final→Final′ : (X : Coalgebra C) → Final X → Final′ X
Final→Final′ _ =
∀-cong _ λ _ → ∃-cong λ _ → ∀-cong _ λ _ → cong proj₁
-- Final is pointwise propositional (assumption extensionality).
Final-propositional :
{I : Type i} {C : Container I s p} →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
(X : Coalgebra C) →
Is-proposition (Final X)
Final-propositional ext _ =
Π-closure ext 1 λ _ →
Contractible-propositional (lower-extensionality _ lzero ext)
-- Final coalgebras.
Final-coalgebra :
{I : Type i} →
Container I s p → Type (lsuc (i ⊔ s ⊔ p))
Final-coalgebra C = ∃ λ (X : Coalgebra C) → Final X
-- Final coalgebras, defined using Final′.
Final-coalgebra′ :
{I : Type i} →
Container I s p → Type (lsuc (i ⊔ s ⊔ p))
Final-coalgebra′ C = ∃ λ (X : Coalgebra C) → Final′ X
-- Final-coalgebra C implies Final-coalgebra′ C.
Final-coalgebra→Final-coalgebra′ :
Final-coalgebra C → Final-coalgebra′ C
Final-coalgebra→Final-coalgebra′ =
∃-cong Final→Final′
-- Carriers of final coalgebras (defined using Final′) for a given
-- container are pointwise equivalent.
carriers-of-final-coalgebras-equivalent′ :
(((P₁ , _) , _) ((P₂ , _) , _) : Final-coalgebra′ C) →
∀ i → P₁ i ≃ P₂ i
carriers-of-final-coalgebras-equivalent′ (X₁ , final₁) (X₂ , final₂) i =
Eq.↔→≃ (proj₁ to i) (proj₁ from i) to∘from from∘to
where
to : X₁ ⇨ X₂
to = proj₁ (final₂ X₁)
from : X₂ ⇨ X₁
from = proj₁ (final₁ X₂)
to∘from : ∀ x → proj₁ ([ X₂ ] to ∘⇨ from) i x ≡ x
to∘from x =
proj₁ ([ X₂ ] to ∘⇨ from) i x ≡⟨ cong (λ f → f i x) $ sym $ proj₂ (final₂ X₂) $ [ X₂ ] to ∘⇨ from ⟩
proj₁ (proj₁ (final₂ X₂)) i x ≡⟨ cong (λ f → f i x) $ proj₂ (final₂ X₂) id⇨ ⟩
proj₁ (id⇨ {X = X₂}) i x ≡⟨⟩
x ∎
from∘to : ∀ x → proj₁ ([ X₁ ] from ∘⇨ to) i x ≡ x
from∘to x =
proj₁ ([ X₁ ] from ∘⇨ to) i x ≡⟨ cong (λ f → f i x) $ sym $ proj₂ (final₁ X₁) $ [ X₁ ] from ∘⇨ to ⟩
proj₁ (proj₁ (final₁ X₁)) i x ≡⟨ cong (λ f → f i x) $ proj₂ (final₁ X₁) id⇨ ⟩
proj₁ (id⇨ {X = X₁}) i x ≡⟨⟩
x ∎
-- The previous lemma relates the "out" functions of the two final
-- coalgebras in a certain way.
out-related′ :
{C : Container I s p}
(F₁@((_ , out₁) , _) F₂@((_ , out₂) , _) : Final-coalgebra′ C) →
map C (_≃_.to ∘ carriers-of-final-coalgebras-equivalent′ F₁ F₂) ∘⇾
out₁
≡
out₂ ∘⇾ (_≃_.to ∘ carriers-of-final-coalgebras-equivalent′ F₁ F₂)
out-related′ (X₁ , _) (_ , final₂) =
sym $ proj₂ (proj₁ (final₂ X₁))
-- Carriers of final coalgebras for a given container are pointwise
-- equivalent.
carriers-of-final-coalgebras-equivalent :
(((P₁ , _) , _) ((P₂ , _) , _) : Final-coalgebra C) →
∀ i → P₁ i ≃ P₂ i
carriers-of-final-coalgebras-equivalent =
carriers-of-final-coalgebras-equivalent′ on
Final-coalgebra→Final-coalgebra′
-- The previous lemma relates the "out" functions of the two final
-- coalgebras in a certain way.
out-related :
{C : Container I s p}
(F₁@((_ , out₁) , _) F₂@((_ , out₂) , _) : Final-coalgebra C) →
map C (_≃_.to ∘ carriers-of-final-coalgebras-equivalent F₁ F₂) ∘⇾ out₁
≡
out₂ ∘⇾ (_≃_.to ∘ carriers-of-final-coalgebras-equivalent F₁ F₂)
out-related = out-related′ on Final-coalgebra→Final-coalgebra′
-- If X and Y are final coalgebras (with finality defined using
-- Final′), then—assuming extensionality—finality of X (defined using
-- Final) is equivalent to finality of Y.
Final′→Final≃Final :
{I : Type i} {C : Container I s p}
((X , _) (Y , _) : Final-coalgebra′ C) →
Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p) →
Final X ↝[ lsuc (i ⊔ s ⊔ p) ∣ i ⊔ s ⊔ p ] Final Y
Final′→Final≃Final {i = i} {s = s} {p = p} {C = C}
((X₁ , out₁) , final₁) ((X₂ , out₂) , final₂) ext {k = k} ext′ =
∀-cong ext′ λ Y@(_ , f) →
H-level-cong
(lower-extensionality? k _ lzero ext′)
0
(Σ-cong (lemma₂ Y) λ g →
out₁ ∘⇾ g ≡ map C g ∘⇾ f ↝⟨ inverse $ Eq.≃-≡ (lemma₃ Y) ⟩
_≃_.to (lemma₃ Y) (out₁ ∘⇾ g) ≡
_≃_.to (lemma₃ Y) (map C g ∘⇾ f) ↔⟨⟩
map C (_≃_.to ∘ lemma₁) ∘⇾ out₁ ∘⇾ g ≡
map C (_≃_.to ∘ lemma₁) ∘⇾ map C g ∘⇾ f ↝⟨ ≡⇒↝ _ $ cong (λ h → h ∘⇾ g ≡ map C (_≃_.to ∘ lemma₁) ∘⇾ map C g ∘⇾ f) $
out-related′ ((X₁ , out₁) , final₁) ((X₂ , out₂) , final₂) ⟩
out₂ ∘⇾ (_≃_.to ∘ lemma₁) ∘⇾ g ≡
map C (_≃_.to ∘ lemma₁) ∘⇾ map C g ∘⇾ f ↔⟨⟩
out₂ ∘⇾ _≃_.to (lemma₂ Y) g ≡
map C (_≃_.to (lemma₂ Y) g) ∘⇾ f □)
where
ext₁ = lower-extensionality (s ⊔ p) lzero ext
ext₂ = lower-extensionality (i ⊔ s) lzero ext
lemma₁ : ∀ i → X₁ i ≃ X₂ i
lemma₁ =
carriers-of-final-coalgebras-equivalent′
((X₁ , out₁) , final₁)
((X₂ , out₂) , final₂)
lemma₂ : ((Y , _) : Coalgebra C) → (Y ⇾ X₁) ≃ (Y ⇾ X₂)
lemma₂ _ =
∀-cong ext₁ λ _ →
∀-cong ext λ _ →
lemma₁ _
lemma₃ : ((Y , _) : Coalgebra C) → (Y ⇾ ⟦ C ⟧ X₁) ≃ (Y ⇾ ⟦ C ⟧ X₂)
lemma₃ _ =
∀-cong ext₁ λ _ →
∀-cong ext λ _ →
⟦⟧-cong ext₂ C lemma₁ _
-- If there is a final C-coalgebra, and we have Final′ X for some
-- C-coalgebra X, then we also have Final X (assuming extensionality).
Final′→Final :
{I : Type i} {C : Container I s p} →
Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p) →
Final-coalgebra C →
((X , _) : Final-coalgebra′ C) →
Final X
Final′→Final ext F₁@(_ , final₁) F₂ =
Final′→Final≃Final
(Final-coalgebra→Final-coalgebra′ F₁) F₂
ext _ final₁
-- Final-coalgebra is pointwise propositional, assuming extensionality
-- and univalence.
--
-- This is a variant of Lemma 5 from "Non-wellfounded trees in
-- Homotopy Type Theory".
Final-coalgebra-propositional :
{I : Type i} {C : Container I s p} →
Extensionality (lsuc (i ⊔ s ⊔ p)) (lsuc (i ⊔ s ⊔ p)) →
Univalence (i ⊔ s ⊔ p) →
Is-proposition (Final-coalgebra C)
Final-coalgebra-propositional {I = I} {C = C@(S ◁ P)}
ext univ F₁@((P₁ , out₁) , _) F₂@(X₂@(P₂ , out₂) , _) =
block λ b →
Σ-≡,≡→≡ (Σ-≡,≡→≡ (lemma₁ b) (lemma₂ b))
(Final-propositional (lower-extensionality lzero _ ext) X₂ _ _)
where
ext₁′ = lower-extensionality _ lzero ext
ext₁ = Eq.good-ext ext₁′
lemma₀ : Block "lemma₀" → ∀ i → P₁ i ≃ P₂ i
lemma₀ ⊠ = carriers-of-final-coalgebras-equivalent F₁ F₂
lemma₀-lemma :
∀ b x →
map C (_≃_.to ∘ lemma₀ b) i (out₁ i (_≃_.from (lemma₀ b i) x)) ≡
out₂ i x
lemma₀-lemma {i = i} ⊠ x =
map C (_≃_.to ∘ lemma₀ ⊠) i (out₁ i (_≃_.from (lemma₀ ⊠ i) x)) ≡⟨ cong (λ f → f _ (_≃_.from (lemma₀ ⊠ i) x)) $
out-related F₁ F₂ ⟩
out₂ i (_≃_.to (lemma₀ ⊠ i) (_≃_.from (lemma₀ ⊠ i) x)) ≡⟨ cong (out₂ _) $
_≃_.right-inverse-of (lemma₀ ⊠ i) _ ⟩∎
out₂ i x ∎
lemma₁ : Block "lemma₀" → P₁ ≡ P₂
lemma₁ b =
apply-ext ext₁ λ i →
≃⇒≡ univ (lemma₀ b i)
lemma₁-lemma₁ = λ b i →
sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (subst-const _) ≡⟨ cong sym Σ-≡,≡→≡-subst-const-refl ⟩
sym $ cong₂ _,_ (sym (lemma₁ b)) (refl _) ≡⟨ sym cong₂-sym ⟩
cong₂ _,_ (sym (sym (lemma₁ b))) (sym (refl _)) ≡⟨ cong₂ (cong₂ _) (sym-sym _) sym-refl ⟩
cong₂ _,_ (lemma₁ b) (refl i) ≡⟨ cong₂-reflʳ _ ⟩∎
cong (_, i) (lemma₁ b) ∎
lemma₁-lemma₂ = λ b i x →
subst (_$ i) (sym (lemma₁ b)) x ≡⟨⟩
subst (_$ i) (sym (apply-ext ext₁ λ i → ≃⇒≡ univ (lemma₀ b i))) x ≡⟨ cong (flip (subst (_$ i)) _) $ sym $
Eq.good-ext-sym ext₁′ _ ⟩
subst (_$ i) (apply-ext ext₁ λ i → sym (≃⇒≡ univ (lemma₀ b i))) x ≡⟨ Eq.subst-good-ext ext₁′ _ _ ⟩
subst id (sym (≃⇒≡ univ (lemma₀ b i))) x ≡⟨ subst-id-in-terms-of-inverse∘≡⇒↝ equivalence ⟩
_≃_.from (≡⇒≃ (≃⇒≡ univ (lemma₀ b i))) x ≡⟨ cong (λ eq → _≃_.from eq _) $
_≃_.right-inverse-of (≡≃≃ univ) _ ⟩∎
_≃_.from (lemma₀ b i) x ∎
lemma₁-lemma₃ : ∀ b (f : P s ⇾ P₁) i p → _ ≡ _
lemma₁-lemma₃ b f i p =
subst (_$ i) (lemma₁ b) (f i p) ≡⟨⟩
subst (_$ i) (apply-ext ext₁ λ i → ≃⇒≡ univ (lemma₀ b i)) (f i p) ≡⟨ Eq.subst-good-ext ext₁′ _ _ ⟩
subst id (≃⇒≡ univ (lemma₀ b i)) (f i p) ≡⟨ subst-id-in-terms-of-≡⇒↝ equivalence ⟩
≡⇒→ (≃⇒≡ univ (lemma₀ b i)) (f i p) ≡⟨ cong (λ eq → _≃_.to eq _) $
_≃_.right-inverse-of (≡≃≃ univ) _ ⟩∎
_≃_.to (lemma₀ b i) (f i p) ∎
lemma₂ = λ b →
apply-ext (lower-extensionality _ _ ext) λ i →
apply-ext (lower-extensionality _ _ ext) λ x →
subst (λ P → P ⇾ ⟦ C ⟧ P) (lemma₁ b) out₁ i x ≡⟨⟩
subst (λ P → ∀ i → P i → ⟦ C ⟧ P i) (lemma₁ b) out₁ i x ≡⟨ cong (_$ x) subst-∀ ⟩
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (refl _))
(out₁ (subst (λ _ → I) (sym (lemma₁ b)) i)) x ≡⟨ elim¹
(λ {i′} eq →
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (refl _))
(out₁ (subst (λ _ → I) (sym (lemma₁ b)) i)) x ≡
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) eq)
(out₁ i′) x)
(refl _)
_ ⟩
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (subst-const _))
(out₁ i) x ≡⟨ cong (λ eq → subst (uncurry λ P i → P i → ⟦ C ⟧ P i) eq _ _) $
lemma₁-lemma₁ b i ⟩
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(cong (_, _) (lemma₁ b))
(out₁ i) x ≡⟨ cong (_$ x) $ sym $ subst-∘ _ _ _ ⟩
subst (λ P → P i → ⟦ C ⟧ P i) (lemma₁ b) (out₁ i) x ≡⟨ subst-→ ⟩
subst (λ P → ⟦ C ⟧ P i) (lemma₁ b)
(out₁ i (subst (_$ i) (sym (lemma₁ b)) x)) ≡⟨ cong (subst (λ P → ⟦ C ⟧ P i) _) $ cong (out₁ _) $
lemma₁-lemma₂ b i x ⟩
subst (λ P → ⟦ C ⟧ P i) (lemma₁ b)
(out₁ i (_≃_.from (lemma₀ b i) x)) ≡⟨⟩
subst (λ Q → ∃ λ (s : S i) → P s ⇾ Q) (lemma₁ b)
(out₁ i (_≃_.from (lemma₀ b i) x)) ≡⟨ push-subst-pair-× _ _ ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , subst (λ Q → P s ⇾ Q) (lemma₁ b) f) ≡⟨ (let s , _ = out₁ i (_≃_.from (lemma₀ b i) x) in
cong (s ,_) $
apply-ext (lower-extensionality _ _ ext) λ _ → sym $
push-subst-application _ _) ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , λ i → subst (λ Q → P s i → Q i) (lemma₁ b) (f i)) ≡⟨ (let s , _ = out₁ i (_≃_.from (lemma₀ b i) x) in
cong (s ,_) $
apply-ext (lower-extensionality _ _ ext) λ _ →
apply-ext (lower-extensionality _ _ ext) λ _ → sym $
push-subst-application _ _) ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , λ i p → subst (_$ i) (lemma₁ b) (f i p)) ≡⟨ (let _ , f = out₁ i (_≃_.from (lemma₀ b i) x) in
cong (_ ,_) $
apply-ext (lower-extensionality _ _ ext) λ i →
apply-ext (lower-extensionality _ _ ext) $
lemma₁-lemma₃ b f i) ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , λ i p → _≃_.to (lemma₀ b i) (f i p)) ≡⟨⟩
map C (_≃_.to ∘ lemma₀ b) i (out₁ i (_≃_.from (lemma₀ b i) x)) ≡⟨ lemma₀-lemma b x ⟩∎
out₂ i x ∎
------------------------------------------------------------------------
-- Conversion lemmas
-- A conversion lemma for Container. Note that the last index is not
-- unrestricted.
Container⇔Container :
∀ {I : Type i} {O : Type o} p →
Container₂ I O s (i ⊔ p) ⇔ C.Container₂ I O s (i ⊔ p)
Container⇔Container {i = iℓ} {s = s} {I = I} {O = O} p =
Container₂ I O s (iℓ ⊔ p) ↔⟨ Container≃Σ ⟩
(∃ λ (S : O → Type s) →
∀ {o} → S o → I → Type (iℓ ⊔ p)) ↔⟨ (∃-cong λ _ →
B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) → I → Type (iℓ ⊔ p)) ↝⟨ (∃-cong λ _ → ∀-cong _ λ _ → ∀-cong _ λ _ →
Pow⇔Fam p) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) →
∃ λ (P : Type (iℓ ⊔ p)) → P → I) ↝⟨ (∃-cong λ _ →
from-bijection ΠΣ-comm F.∘
∀-cong _ λ _ → from-bijection ΠΣ-comm) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ o → S o → Type (iℓ ⊔ p)) →
∀ o (s : S o) → P o s → I) ↝⟨ (∃-cong λ _ → inverse $
Σ-cong-refl {k₂ = logical-equivalence} B.implicit-Π↔Π λ _ →
(∀-cong _ λ _ →
from-bijection B.implicit-Π↔Π) F.∘
from-bijection B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ {o} → S o → Type (iℓ ⊔ p)) →
∀ {o} {s : S o} → P s → I) ↔⟨ inverse C.Container≃Σ ⟩□
C.Container₂ I O s (iℓ ⊔ p) □
-- Another conversion lemma for Container.
Container≃Container :
∀ {I : Type i} {O : Type o} p →
Extensionality (i ⊔ o ⊔ s) (lsuc i ⊔ s ⊔ lsuc p) →
Univalence (i ⊔ p) →
Container₂ I O s (i ⊔ p) ≃ C.Container₂ I O s (i ⊔ p)
Container≃Container {i = i} {o = o} {s = s} {I = I} {O = O} p ext univ =
Container₂ I O s (i ⊔ p) ↝⟨ Container≃Σ ⟩
(∃ λ (S : O → Type s) →
∀ {o} → S o → I → Type (i ⊔ p)) ↔⟨ (∃-cong λ _ →
B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) → I → Type (i ⊔ p)) ↔⟨ (∃-cong λ _ →
∀-cong (lower-extensionality l r ext) λ _ →
∀-cong (lower-extensionality l r ext) λ _ →
Pow↔Fam p (lower-extensionality l r ext) univ) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) →
∃ λ (P : Type (i ⊔ p)) → P → I) ↔⟨ (∃-cong λ _ →
ΠΣ-comm F.∘
∀-cong (lower-extensionality l r ext) λ _ → ΠΣ-comm) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ o → S o → Type (i ⊔ p)) →
∀ o (s : S o) → P o s → I) ↝⟨ (∃-cong λ _ → inverse $
Σ-cong-refl {k₂ = logical-equivalence} B.implicit-Π↔Π λ _ →
(∀-cong _ λ _ →
from-bijection B.implicit-Π↔Π) F.∘
from-bijection B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ {o} → S o → Type (i ⊔ p)) →
∀ {o} {s : S o} → P s → I) ↝⟨ inverse C.Container≃Σ ⟩□
C.Container₂ I O s (i ⊔ p) □
where
l = i ⊔ o ⊔ s
r = lsuc i ⊔ s ⊔ lsuc p
-- The two conversion lemmas for Container are related.
_ :
{I : Type i} {univ : Univalence (i ⊔ p)} →
_≃_.logical-equivalence
(Container≃Container {I = I} {O = O} p ext univ) ≡
Container⇔Container p
_ = refl _
-- A conversion lemma for ⟦_⟧.
⟦⟧≃⟦⟧ :
∀ p →
{I : Type i} (C : Container₂ I O s (i ⊔ p)) {P : I → Type ℓ} →
∀ o →
C.⟦ _⇔_.to (Container⇔Container p) C ⟧ P o ≃ ⟦ C ⟧ P o
⟦⟧≃⟦⟧ _ {I = I} C {P = P} o =
(∃ λ (s : Shape C o) → ((i , _) : Σ I (Position C s)) → P i) ↔⟨ (∃-cong λ _ → currying) ⟩□
(∃ λ (s : Shape C o) → (i : I) → Position C s i → P i) □
-- Another conversion lemma for ⟦_⟧.
⟦⟧≃⟦⟧′ :
∀ p →
{I : Type i} (C : C.Container₂ I O s (i ⊔ p)) {P : I → Type ℓ} →
∀ o →
⟦ _⇔_.from (Container⇔Container p) C ⟧ P o ↝[ i ⊔ p ∣ i ⊔ p ⊔ ℓ ]
C.⟦ C ⟧ P o
⟦⟧≃⟦⟧′ {i = i} {ℓ = ℓ} p {I = I} C {P = P} _ {k = k} ext =
∃-cong λ s →
((i : I) → (∃ λ (p : C .Position s) → C .index p ≡ i) → P i) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
from-bijection currying) ⟩
((i : I) (p : C .Position s) → C .index p ≡ i → P i) ↔⟨ Π-comm ⟩
((p : C .Position s) (i : I) → C .index p ≡ i → P i) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
∀-cong (lower-extensionality? k l r ext) λ _ →
∀-cong (lower-extensionality? k l r ext) λ eq →
≡⇒↝ _ $ cong P (sym eq)) ⟩
((p : C .Position s) (i : I) → C .index p ≡ i → P (C .index p)) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
from-bijection $ inverse currying) ⟩
((p : C .Position s) → (∃ λ (i : I) → C .index p ≡ i) →
P (C .index p)) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
drop-⊤-left-Π (lower-extensionality? k l r ext) $
_⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩□
((p : C .Position s) → P (C .index p)) □
where
l = i ⊔ p
r = i ⊔ p ⊔ ℓ
-- The map functions commute with ⟦⟧≃⟦⟧ (in a certain sense).
_ :
map C f ∘⇾ (_≃_.to ∘ ⟦⟧≃⟦⟧ p C) ≡
(_≃_.to ∘ ⟦⟧≃⟦⟧ p C) ∘⇾ C.map (_⇔_.to (Container⇔Container p) C) f
_ = refl _
-- The map functions commute with ⟦⟧≃⟦⟧′ (in a certain sense, assuming
-- extensionality).
map≡map′ :
{I : Type i} {O : Type o} {P : I → Type p} {Q : I → Type q} →
∀ p′ →
Extensionality (i ⊔ o ⊔ p ⊔ s ⊔ p′) (i ⊔ p ⊔ q ⊔ s ⊔ p′) →
(C : C.Container₂ I O s (i ⊔ p′)) {f : P ⇾ Q} →
C.map C f ∘⇾ (λ o → ⟦⟧≃⟦⟧′ p′ C o _) ≡
(λ o → ⟦⟧≃⟦⟧′ p′ C o _) ∘⇾ map (_⇔_.from (Container⇔Container p′) C) f
map≡map′ {i = i} {o = o} {p = p} {q = q} {s = s} {P = P} {Q = Q}
p′ ext C {f = f} =
apply-ext (lower-extensionality l r ext) λ _ →
apply-ext (lower-extensionality l r ext) λ (_ , g) →
cong (_ ,_) $
apply-ext (lower-extensionality l r ext) λ p →
let i = C .index p in
f i (≡⇒↝ _ (cong P (sym (refl _))) (g i (p , refl _))) ≡⟨ cong (λ eq → f i (≡⇒↝ _ eq (g i (p , refl _)))) $
trans (cong (cong P) sym-refl) $
cong-refl _ ⟩
f i (≡⇒↝ _ (refl _) (g i (p , refl _))) ≡⟨ cong (f i) $ cong (_$ g i (p , refl _))
≡⇒↝-refl ⟩
f i (g i (p , refl _)) ≡⟨ cong (_$ f i (g i (p , refl _))) $ sym
≡⇒↝-refl ⟩
≡⇒↝ _ (refl _) (f i (g i (p , refl _))) ≡⟨ cong (λ eq → ≡⇒↝ _ eq (f i (g i (p , refl _)))) $ sym $
trans (cong (cong Q) sym-refl) $
cong-refl _ ⟩∎
≡⇒↝ _ (cong Q (sym (refl _))) (f i (g i (p , refl _))) ∎
where
l = i ⊔ o ⊔ p ⊔ s ⊔ p′
r = i ⊔ p ⊔ q ⊔ s ⊔ p′
-- A conversion lemma for Coalgebra.
Coalgebra≃Coalgebra :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Coalgebra C ↝[ i ⊔ s ⊔ p ∣ i ⊔ s ⊔ p ]
C.Coalgebra (_⇔_.to (Container⇔Container p) C)
Coalgebra≃Coalgebra {s = s} p C {k = k} ext =
(∃ λ P → P ⇾ ⟦ C ⟧ P) ↝⟨ (∃-cong λ _ →
∀-cong (lower-extensionality? k (s ⊔ p) lzero ext) λ _ →
∀-cong ext λ _ →
from-equivalence $ inverse $ ⟦⟧≃⟦⟧ p C _) ⟩□
(∃ λ P → P ⇾ C.⟦ _⇔_.to (Container⇔Container p) C ⟧ P) □
-- A conversion lemma for _⇨_.
⇨≃⇨ :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p) →
(X Y : Coalgebra C) →
(X ⇨ Y) ≃
(Coalgebra≃Coalgebra p C _ X C.⇨ Coalgebra≃Coalgebra p C _ Y)
⇨≃⇨ {s = s} p C ext (P , f) (Q , g) =
(∃ λ (h : P ⇾ Q) → g ∘⇾ h ≡ map _ h ∘⇾ f) ↝⟨ (∃-cong λ h → inverse $ Eq.≃-≡ $
∀-cong (lower-extensionality (s ⊔ p) lzero ext) λ _ →
∀-cong ext λ _ →
inverse $ ⟦⟧≃⟦⟧ p C _) ⟩□
(∃ λ (h : P ⇾ Q) →
((Σ-map id uncurry ∘_) ∘ g) ∘⇾ h ≡
C.map _ h ∘⇾ ((Σ-map id uncurry ∘_) ∘ f)) □
-- A conversion lemma for Final.
Final≃Final :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
(ext : Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p))
(X : Coalgebra C) →
Final X ≃ C.Final (_≃_.to (Coalgebra≃Coalgebra p C ext) X)
Final≃Final p C ext′ ext X =
(∀ Y → Contractible (Y ⇨ X)) ↝⟨ (Π-cong ext′ (Coalgebra≃Coalgebra p C {k = equivalence} ext) λ Y →
H-level-cong ext 0 $
⇨≃⇨ p C ext Y X) ⟩□
(∀ Y → Contractible (Y C.⇨ Coalgebra≃Coalgebra p C _ X)) □
-- A conversion lemma for Final′.
Final′≃Final′ :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
(ext : Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p))
(X : Coalgebra C) →
Final′ X ≃ C.Final′ (_≃_.to (Coalgebra≃Coalgebra p C ext) X)
Final′≃Final′ p C ext′ ext X =
(∀ Y → ∃ λ (m : Y ⇨ X ) → (m′ : Y ⇨ X ) → proj₁ m ≡ proj₁ m′) ↝⟨ (Π-cong ext′ (Coalgebra≃Coalgebra p C {k = equivalence} ext) λ Y →
Σ-cong (⇨≃⇨ p C ext Y X) λ _ →
Π-cong ext (⇨≃⇨ p C ext Y X) λ _ →
F.id) ⟩□
(∀ Y → ∃ λ (m : Y C.⇨ X′) → (m′ : Y C.⇨ X′) → proj₁ m ≡ proj₁ m′) □
where
X′ = _≃_.to (Coalgebra≃Coalgebra p C ext) X
-- A conversion lemma for Final-coalgebra.
Final-coalgebra≃Final-coalgebra :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
Final-coalgebra C ≃
C.Final-coalgebra (_⇔_.to (Container⇔Container p) C)
Final-coalgebra≃Final-coalgebra p C ext =
(∃ λ (X : Coalgebra C ) → Final X) ↝⟨ Σ-cong {k₁ = equivalence}
(Coalgebra≃Coalgebra p C ext′)
(Final≃Final p C ext ext′) ⟩□
(∃ λ (X : C.Coalgebra C′) → C.Final X) □
where
C′ = _⇔_.to (Container⇔Container p) C
ext′ = lower-extensionality _ lzero ext
-- A conversion lemma for Final-coalgebra′.
Final-coalgebra′≃Final-coalgebra′ :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
Final-coalgebra′ C ≃
C.Final-coalgebra′ (_⇔_.to (Container⇔Container p) C)
Final-coalgebra′≃Final-coalgebra′ p C ext =
(∃ λ (X : Coalgebra C ) → Final′ X) ↝⟨ Σ-cong {k₁ = equivalence}
(Coalgebra≃Coalgebra p C ext′)
(Final′≃Final′ p C ext ext′) ⟩□
(∃ λ (X : C.Coalgebra C′) → C.Final′ X) □
where
C′ = _⇔_.to (Container⇔Container p) C
ext′ = lower-extensionality _ lzero ext
| 41.335135
| 138
| 0.422486
|
cb192eab5daae544a3fcbd5ab29bbc048cf81a94
| 187
|
agda
|
Agda
|
examples/Introduction/Universes.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/Introduction/Universes.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/Introduction/Universes.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Introduction.Universes where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
postulate IsEven : Nat -> Prop
data Even : Set where
even : (n : Nat) -> IsEven n -> Even
| 14.384615
| 38
| 0.641711
|
58077c8bb8215218aae3538fcfd38bb4a9bae40d
| 8,834
|
agda
|
Agda
|
old/Homotopy/TruncatedHIT.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
old/Homotopy/TruncatedHIT.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
old/Homotopy/TruncatedHIT.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K #-}
{-
Truncated higher inductive types look like higher inductive types except that
they are truncated down to some fixed truncation level.
This allow to define truncations (obviously) but also free algebras for
algebraic theories, Eilenberg-MacLane spaces, etc.
The idea is that to get an n-truncated higher inductive type, you just have to
add the following two constructors, where [I] is the HIT you are defining.
top : (f : Sⁿ n → I) → I
rays : (f : Sⁿ n → I) (x : Sⁿ n) → top f ≡ f x
In this file, I prove whatever is needed to go from the usual elimination rules
generated by the previous constructors to the elimination rules that we expect
from truncated higher inductive types.
We have to note that the previous definition does not work for [n = 0], because
this only adds a point to I instead of turning it into a contractible space.
0-truncated higher inductive types are not really interesting but handling
truncations is easier when 0 is not special
Hence I’m adding the following path constructor
hack-prop : (p : n ≡ 0) (x y : τ) → (x ≡ y)
This will force [I] to be a prop (hence contractible because [top] of the empty
function is of type [I]) and does not change anything when [n] is not 0.
I may use the following syntax for [n]-truncated higher inductive types:
(n)data I : Set i where
…
-}
module Homotopy.TruncatedHIT where
open import Base
open import Spaces.Spheres public
open import Spaces.Suspension public
_+1 : ℕ₋₂ → ℕ
⟨-2⟩ +1 = 0
(S ⟨-2⟩) +1 = 0
(S n) +1 = S (n +1)
-- [hSⁿ n] is what is supposed to be filled to get something n-truncated
hSⁿ : ℕ₋₂ → Set
hSⁿ ⟨-2⟩ = ⊥
hSⁿ n = Sⁿ (n +1)
-- Type of fillings of a sphere
filling : ∀ {i} (n : ℕ₋₂) {A : Set i} (f : hSⁿ n → A) → Set i
filling {i} n {A} f = Σ A (λ t → ((x : hSⁿ n) → t ≡ f x))
-- Type of dependent fillings of a sphere above a ball
filling-dep : ∀ {i j} (n : ℕ₋₂) {A : Set i} (P : A → Set j) (f : hSⁿ n → A)
(fill : filling n f) (p : (x : hSⁿ n) → P (f x)) → Set j
filling-dep {i} {j} n {A} P f fill p =
Σ (P (π₁ fill)) (λ t → ((x : hSⁿ n) → transport P (π₂ fill x) t ≡ p x))
-- [has-n-spheres-filled n A] is inhabited iff every n-sphere in [A] can be
-- filled with an (n+1)-ball.
-- We will show that this is equivalent to being n-truncated, *for n > 0*
-- (for n = 0, having 0-spheres filled only means that A is inhabited)
has-spheres-filled : ∀ {i} (n : ℕ₋₂) (A : Set i) → Set i
has-spheres-filled n A = (f : hSⁿ n → A) → filling n f
-- [has-n-spheres-filled] satisfy the same inductive property
-- than [is-truncated]
fill-paths : ∀ {i} (n : ℕ₋₂) (A : Set i) (t : has-spheres-filled (S n) A)
→ (n ≡ ⟨-2⟩ → is-contr A) → ((x y : A) → has-spheres-filled n (x ≡ y))
fill-paths ⟨-2⟩ A t contr x y f =
(contr-has-all-paths (contr refl) x y , abort)
fill-paths (S n) A t _ x y f =
((! (π₂ u (north _)) ∘ π₂ u (south _))
, (λ z → ! (lemma (paths _ z)) ∘ suspension-β-paths-nondep _ _ _ _ f _)) where
-- [f] is a map from [hSⁿ (S n)] to [x ≡ y], we can build from it a map
-- from [hSⁿ (S n)] to [A]
newf : hSⁿ (S (S n)) → A
newf = suspension-rec-nondep _ _ x y f
u : filling (S (S n)) newf
u = t newf
-- I’ve got a filling
-- Every path in the sphere is equal (in A) to the canonical path going
-- through the center of the filled sphere
lemma : {p q : hSⁿ (S (S n))} (l : p ≡ q)
→ ap newf l ≡ ! (π₂ u p) ∘ π₂ u q
lemma {p = a} refl = ! (opposite-left-inverse (π₂ u a))
-- We first prove that if n-spheres are filled, then the type is n-truncated,
-- we have to prove it for n = -1, and then use the previous lemma
abstract
spheres-filled-is-truncated : ∀ {i} (n : ℕ₋₂) (A : Set i)
→ ((n ≡ ⟨-2⟩ → is-contr A) → has-spheres-filled n A → is-truncated n A)
spheres-filled-is-truncated ⟨-2⟩ A contr t = contr refl
spheres-filled-is-truncated (S ⟨-2⟩) A _ t =
all-paths-is-prop (λ x y → ! (π₂ (t (f x y)) true) ∘ π₂ (t (f x y)) false)
where
f : (x y : A) → bool {zero} → A
f x y true = x
f x y false = y
spheres-filled-is-truncated (S (S n)) A _ t = λ x y →
spheres-filled-is-truncated (S n) (x ≡ y) (λ ())
(fill-paths (S n) A t (λ ()) x y)
-- We now prove the converse
abstract
truncated-has-spheres-filled : ∀ {i} (n : ℕ₋₂) (A : Set i)
(t : is-truncated n A) → has-spheres-filled n A
truncated-has-spheres-filled ⟨-2⟩ A t f = (π₁ t , abort)
truncated-has-spheres-filled (S ⟨-2⟩) A t f =
(f true , (λ {true → refl ; false → π₁ (t (f true) (f false))}))
truncated-has-spheres-filled (S (S n)) A t f =
(f (north _)
, (suspension-rec _ _ refl (ap f (paths _ (⋆Sⁿ _)))
(λ x → trans-cst≡app (f (north _)) f (paths _ _) _
∘ (! (π₂ filled-newf x) ∘ π₂ filled-newf (⋆Sⁿ _))))) where
newf : hSⁿ (S n) → (f (north _) ≡ f (south _))
newf x = ap f (paths _ x)
filled-newf : filling (S n) newf
filled-newf = truncated-has-spheres-filled (S n) _ (t _ _) newf
-- I prove that if [A] has [S n]-spheres filled, then the type of fillings
-- of [n]-spheres is a proposition. The idea is that two fillings of
-- an [n]-sphere define an [S n]-sphere, which is then filled.
filling-has-all-paths : ∀ {i} (n : ℕ₋₂) (A : Set i)
⦃ fill : has-spheres-filled (S n) A ⦄ (f : hSⁿ n → A)
→ has-all-paths (filling n f)
filling-has-all-paths ⟨-2⟩ A ⦃ fill ⦄ f fill₁ fill₂ =
Σ-eq (! (π₂ big-map-filled true) ∘ π₂ big-map-filled false) (funext abort)
where
big-map : hSⁿ ⟨-1⟩ → A
big-map true = π₁ fill₁
big-map false = π₁ fill₂
big-map-filled : filling ⟨-1⟩ big-map
big-map-filled = fill big-map
filling-has-all-paths (S n) A ⦃ fill ⦄ f fill₁ fill₂ =
Σ-eq (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _))
(funext (λ x →
trans-Π2 _ (λ t x₁ → t ≡ f x₁)
(! (π₂ big-map-filled (north _)) ∘
π₂ big-map-filled (south _))
(π₂ fill₁) x
∘ (trans-id≡cst
(! (π₂ big-map-filled (north _)) ∘
π₂ big-map-filled (south _))
(π₂ fill₁ x)
∘ move!-right-on-left
(! (π₂ big-map-filled (north _)) ∘
π₂ big-map-filled (south _))
_ _
(move-left-on-right _
(! (π₂ big-map-filled (north _)) ∘
π₂ big-map-filled (south _))
_
(! (suspension-β-paths-nondep _ _ _ _ g x)
∘ lemma (paths _ x)))))) where
g : hSⁿ (S n) → (π₁ fill₁ ≡ π₁ fill₂)
g x = π₂ fill₁ x ∘ ! (π₂ fill₂ x)
big-map : hSⁿ (S (S n)) → A
big-map = suspension-rec-nondep _ _ (π₁ fill₁) (π₁ fill₂) g
big-map-filled : filling (S (S n)) big-map
big-map-filled = fill big-map
lemma : {u v : hSⁿ (S (S n))} (p : u ≡ v)
→ ap big-map p ≡ (! (π₂ big-map-filled u) ∘ π₂ big-map-filled v)
lemma {u = a} refl = ! (opposite-left-inverse (π₂ big-map-filled a))
abstract
truncated-has-filling-dep : ∀ {i j} (A : Set i) (P : A → Set j) (n : ℕ₋₂)
⦃ trunc : (x : A) → is-truncated n (P x) ⦄
(contr : n ≡ ⟨-2⟩ → is-contr A)
(fill : has-spheres-filled n A) (f : hSⁿ n → A) (p : (x : hSⁿ n) → P (f x))
→ filling-dep n P f (fill f) p
truncated-has-filling-dep A P ⟨-2⟩ ⦃ trunc ⦄ contr fill f p =
(π₁ (trunc (π₁ (fill f))) , abort)
truncated-has-filling-dep A P (S n) ⦃ trunc ⦄ contr fill f p =
transport (λ t → filling-dep (S n) P f t p) eq fill-dep where
-- Combining [f] and [p] we have a sphere in the total space of [P]
newf : hSⁿ (S n) → Σ A P
newf x = (f x , p x)
-- But this total space is (S n)-truncated
ΣAP-truncated : is-truncated (S n) (Σ A P)
ΣAP-truncated =
Σ-is-truncated (S n) (spheres-filled-is-truncated (S n) A contr fill)
trunc
-- Hence the sphere is filled
tot-fill : filling (S n) newf
tot-fill = truncated-has-spheres-filled (S n) (Σ A P) ΣAP-truncated newf
-- We can split this filling as a filling of [f] in [A] …
new-fill : filling (S n) f
new-fill = (π₁ (π₁ tot-fill) , (λ x → base-path (π₂ tot-fill x)))
-- and a dependent filling above the previous filling of [f], along [p]
fill-dep : filling-dep (S n) P f new-fill p
fill-dep = (π₂ (π₁ tot-fill) , (λ x → fiber-path (π₂ tot-fill x)))
A-has-spheres-filled-S : has-spheres-filled (S (S n)) A
A-has-spheres-filled-S =
truncated-has-spheres-filled (S (S n)) A
(truncated-is-truncated-S (S n)
(spheres-filled-is-truncated (S n) A contr fill))
-- But both the new and the old fillings of [f] are equal, hence we will
-- have a dependent filling above the old one
eq : new-fill ≡ fill f
eq = filling-has-all-paths (S n) A f new-fill (fill f)
| 38.9163
| 80
| 0.579918
|
2ec414a915d402bb92f8c52659213f24b803e273
| 651
|
agda
|
Agda
|
Cubical/Categories/Limits/Terminal.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Limits/Terminal.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Limits/Terminal.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.Limits.Terminal where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
-- open import Cubical.Categories.Limits.Base
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
private
variable
ℓ ℓ' : Level
module _ (C : Precategory ℓ ℓ') where
open Precategory C
isInitial : (x : ob) → Type (ℓ-max ℓ ℓ')
isInitial x = ∀ (y : ob) → isContr (C [ x , y ])
isFinal : (x : ob) → Type (ℓ-max ℓ ℓ')
isFinal x = ∀ (y : ob) → isContr (C [ y , x ])
hasFinalOb : Type (ℓ-max ℓ ℓ')
hasFinalOb = Σ[ x ∈ ob ] isFinal x
| 25.038462
| 50
| 0.663594
|
3d6880ba534d710984b2f0b5e49bde6961b3061b
| 13,925
|
agda
|
Agda
|
Cubical/HITs/S1/Base.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S1/Base.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S1/Base.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-
Definition of the circle as a HIT with a proof that Ω(S¹) ≡ ℤ
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.S1.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Nat
hiding (_+_ ; _*_ ; +-assoc ; +-comm)
open import Cubical.Data.Int
data S¹ : Type₀ where
base : S¹
loop : base ≡ base
-- Check that transp is the identity function for S¹
module _ where
transpS¹ : ∀ (φ : I) (u0 : S¹) → transp (λ _ → S¹) φ u0 ≡ u0
transpS¹ φ u0 = refl
compS1 : ∀ (φ : I) (u : ∀ i → Partial φ S¹) (u0 : S¹ [ φ ↦ u i0 ]) →
comp (λ _ → S¹) u (outS u0) ≡ hcomp u (outS u0)
compS1 φ u u0 = refl
helix : S¹ → Type₀
helix base = Int
helix (loop i) = sucPathInt i
ΩS¹ : Type₀
ΩS¹ = base ≡ base
encode : ∀ x → base ≡ x → helix x
encode x p = subst helix p (pos zero)
winding : ΩS¹ → Int
winding = encode base
intLoop : Int → ΩS¹
intLoop (pos zero) = refl
intLoop (pos (suc n)) = intLoop (pos n) ∙ loop
intLoop (negsuc zero) = sym loop
intLoop (negsuc (suc n)) = intLoop (negsuc n) ∙ sym loop
decodeSquare : (n : Int) → PathP (λ i → base ≡ loop i) (intLoop (predInt n)) (intLoop n)
decodeSquare (pos zero) i j = loop (i ∨ ~ j)
decodeSquare (pos (suc n)) i j = hfill (λ k → λ { (j = i0) → base
; (j = i1) → loop k } )
(inS (intLoop (pos n) j)) i
decodeSquare (negsuc n) i j = hcomp (λ k → λ { (i = i1) → intLoop (negsuc n) j
; (j = i0) → base
; (j = i1) → loop (i ∨ ~ k) })
(intLoop (negsuc n) j)
decode : (x : S¹) → helix x → base ≡ x
decode base = intLoop
decode (loop i) y j =
let n : Int
n = unglue (i ∨ ~ i) y
in hcomp (λ k → λ { (i = i0) → intLoop (predSuc y k) j
; (i = i1) → intLoop y j
; (j = i0) → base
; (j = i1) → loop i })
(decodeSquare n i j)
decodeEncode : (x : S¹) (p : base ≡ x) → decode x (encode x p) ≡ p
decodeEncode x p = J (λ y q → decode y (encode y q) ≡ q) (λ _ → refl) p
isSetΩS¹ : isSet ΩS¹
isSetΩS¹ p q r s j i =
hcomp (λ k → λ { (i = i0) → decodeEncode base p k
; (i = i1) → decodeEncode base q k
; (j = i0) → decodeEncode base (r i) k
; (j = i1) → decodeEncode base (s i) k })
(decode base (isSetInt (winding p) (winding q) (cong winding r) (cong winding s) j i))
-- This proof does not rely on rewriting hcomp with empty systems in
-- Int as ghcomp has been implemented!
windingIntLoop : (n : Int) → winding (intLoop n) ≡ n
windingIntLoop (pos zero) = refl
windingIntLoop (pos (suc n)) = cong sucInt (windingIntLoop (pos n))
windingIntLoop (negsuc zero) = refl
windingIntLoop (negsuc (suc n)) = cong predInt (windingIntLoop (negsuc n))
ΩS¹≡Int : ΩS¹ ≡ Int
ΩS¹≡Int = isoToPath (iso winding intLoop windingIntLoop (decodeEncode base))
-- intLoop and winding are group homomorphisms
private
intLoop-sucInt : (z : Int) → intLoop (sucInt z) ≡ intLoop z ∙ loop
intLoop-sucInt (pos n) = refl
intLoop-sucInt (negsuc zero) = sym (lCancel loop)
intLoop-sucInt (negsuc (suc n)) =
rUnit (intLoop (negsuc n))
∙ (λ i → intLoop (negsuc n) ∙ lCancel loop (~ i))
∙ assoc (intLoop (negsuc n)) (sym loop) loop
intLoop-predInt : (z : Int) → intLoop (predInt z) ≡ intLoop z ∙ sym loop
intLoop-predInt (pos zero) = lUnit (sym loop)
intLoop-predInt (pos (suc n)) =
rUnit (intLoop (pos n))
∙ (λ i → intLoop (pos n) ∙ (rCancel loop (~ i)))
∙ assoc (intLoop (pos n)) loop (sym loop)
intLoop-predInt (negsuc n) = refl
intLoop-hom : (a b : Int) → (intLoop a) ∙ (intLoop b) ≡ intLoop (a + b)
intLoop-hom a (pos zero) = sym (rUnit (intLoop a))
intLoop-hom a (pos (suc n)) =
assoc (intLoop a) (intLoop (pos n)) loop
∙ (λ i → (intLoop-hom a (pos n) i) ∙ loop)
∙ sym (intLoop-sucInt (a + pos n))
intLoop-hom a (negsuc zero) = sym (intLoop-predInt a)
intLoop-hom a (negsuc (suc n)) =
assoc (intLoop a) (intLoop (negsuc n)) (sym loop)
∙ (λ i → (intLoop-hom a (negsuc n) i) ∙ (sym loop))
∙ sym (intLoop-predInt (a + negsuc n))
winding-hom : (a b : ΩS¹) → winding (a ∙ b) ≡ (winding a) + (winding b)
winding-hom a b i =
hcomp (λ t → λ { (i = i0) → winding (decodeEncode base a t ∙ decodeEncode base b t)
; (i = i1) → windingIntLoop (winding a + winding b) t })
(winding (intLoop-hom (winding a) (winding b) i))
-- Based homotopy group
basedΩS¹ : (x : S¹) → Type₀
basedΩS¹ x = x ≡ x
-- Proof that the homotopy group is actually independent on the basepoint
-- first, give a quasi-inverse to the basechange basedΩS¹→ΩS¹ for any loop i
-- (which does *not* match at endpoints)
private
ΩS¹→basedΩS¹-filler : I → I → ΩS¹ → I → S¹
ΩS¹→basedΩS¹-filler l i x j =
hfill (λ t → λ { (j = i0) → loop (i ∧ t)
; (j = i1) → loop (i ∧ t) })
(inS (x j)) l
basedΩS¹→ΩS¹-filler : (_ i : I) → basedΩS¹ (loop i) → I → S¹
basedΩS¹→ΩS¹-filler l i x j =
hfill (λ t → λ { (j = i0) → loop (i ∧ (~ t))
; (j = i1) → loop (i ∧ (~ t)) })
(inS (x j)) l
ΩS¹→basedΩS¹ : (i : I) → ΩS¹ → basedΩS¹ (loop i)
ΩS¹→basedΩS¹ i x j = ΩS¹→basedΩS¹-filler i1 i x j
basedΩS¹→ΩS¹ : (i : I) → basedΩS¹ (loop i) → ΩS¹
basedΩS¹→ΩS¹ i x j = basedΩS¹→ΩS¹-filler i1 i x j
basedΩS¹→ΩS¹→basedΩS¹ : (i : I) → (x : basedΩS¹ (loop i))
→ ΩS¹→basedΩS¹ i (basedΩS¹→ΩS¹ i x) ≡ x
basedΩS¹→ΩS¹→basedΩS¹ i x j k =
hcomp (λ t → λ { (j = i1) → basedΩS¹→ΩS¹-filler (~ t) i x k
; (j = i0) → ΩS¹→basedΩS¹ i (basedΩS¹→ΩS¹ i x) k
; (k = i0) → loop (i ∧ (t ∨ (~ j)))
; (k = i1) → loop (i ∧ (t ∨ (~ j))) })
(ΩS¹→basedΩS¹-filler (~ j) i (basedΩS¹→ΩS¹ i x) k)
ΩS¹→basedΩS¹→ΩS¹ : (i : I) → (x : ΩS¹)
→ basedΩS¹→ΩS¹ i (ΩS¹→basedΩS¹ i x) ≡ x
ΩS¹→basedΩS¹→ΩS¹ i x j k =
hcomp (λ t → λ { (j = i1) → ΩS¹→basedΩS¹-filler (~ t) i x k
; (j = i0) → basedΩS¹→ΩS¹ i (ΩS¹→basedΩS¹ i x) k
; (k = i0) → loop (i ∧ ((~ t) ∧ j))
; (k = i1) → loop (i ∧ ((~ t) ∧ j)) })
(basedΩS¹→ΩS¹-filler (~ j) i (ΩS¹→basedΩS¹ i x) k)
-- from the existence of our quasi-inverse, we deduce that the basechange is an equivalence
-- for all loop i
basedΩS¹→ΩS¹-isequiv : (i : I) → isEquiv (basedΩS¹→ΩS¹ i)
basedΩS¹→ΩS¹-isequiv i = isoToIsEquiv (iso (basedΩS¹→ΩS¹ i) (ΩS¹→basedΩS¹ i)
(ΩS¹→basedΩS¹→ΩS¹ i) (basedΩS¹→ΩS¹→basedΩS¹ i))
-- now extend the basechange so that both ends match
-- (and therefore we get a basechange for any x : S¹)
private
loop-conjugation : basedΩS¹→ΩS¹ i1 ≡ λ x → x
loop-conjugation i x =
let p = (doubleCompPath-elim loop x (sym loop))
∙ (λ i → (lUnit loop i ∙ x) ∙ sym loop)
in
((sym (decodeEncode base (basedΩS¹→ΩS¹ i1 x)))
∙ (λ t → intLoop (winding (p t)))
∙ (λ t → intLoop (winding-hom (intLoop (pos (suc zero)) ∙ x)
(intLoop (negsuc zero)) t))
∙ (λ t → intLoop ((winding-hom (intLoop (pos (suc zero))) x t)
+ (windingIntLoop (negsuc zero) t)))
∙ (λ t → intLoop (((windingIntLoop (pos (suc zero)) t) + (winding x)) + (negsuc zero)))
∙ (λ t → intLoop ((+-comm (pos (suc zero)) (winding x) t) + (negsuc zero)))
∙ (λ t → intLoop (+-assoc (winding x) (pos (suc zero)) (negsuc zero) (~ t)))
∙ (decodeEncode base x)) i
refl-conjugation : basedΩS¹→ΩS¹ i0 ≡ λ x → x
refl-conjugation i x j =
hfill (λ t → λ { (j = i0) → base
; (j = i1) → base })
(inS (x j)) (~ i)
basechange : (x : S¹) → basedΩS¹ x → ΩS¹
basechange base y = y
basechange (loop i) y =
hcomp (λ t → λ { (i = i0) → refl-conjugation t y
; (i = i1) → loop-conjugation t y })
(basedΩS¹→ΩS¹ i y)
-- for any loop i, the old basechange is equal to the new one
basedΩS¹→ΩS¹≡basechange : (i : I) → basedΩS¹→ΩS¹ i ≡ basechange (loop i)
basedΩS¹→ΩS¹≡basechange i j y =
hfill (λ t → λ { (i = i0) → refl-conjugation t y
; (i = i1) → loop-conjugation t y })
(inS (basedΩS¹→ΩS¹ i y)) j
-- so for any loop i, the extended basechange is an equivalence
basechange-isequiv-aux : (i : I) → isEquiv (basechange (loop i))
basechange-isequiv-aux i =
transport (λ j → isEquiv (basedΩS¹→ΩS¹≡basechange i j)) (basedΩS¹→ΩS¹-isequiv i)
-- as being an equivalence is contractible, basechange is an equivalence for all x : S¹
basechange-isequiv : (x : S¹) → isEquiv (basechange x)
basechange-isequiv base = basechange-isequiv-aux i0
basechange-isequiv (loop i) =
hcomp (λ t → λ { (i = i0) → basechange-isequiv-aux i0
; (i = i1) → isPropIsEquiv (basechange base) (basechange-isequiv-aux i1)
(basechange-isequiv-aux i0) t })
(basechange-isequiv-aux i)
basedΩS¹≡ΩS¹ : (x : S¹) → basedΩS¹ x ≡ ΩS¹
basedΩS¹≡ΩS¹ x = ua (basechange x , basechange-isequiv x)
basedΩS¹≡Int : (x : S¹) → basedΩS¹ x ≡ Int
basedΩS¹≡Int x = (basedΩS¹≡ΩS¹ x) ∙ ΩS¹≡Int
-- Some tests
module _ where
private
test-winding-pos : winding (intLoop (pos 5)) ≡ pos 5
test-winding-pos = refl
test-winding-neg : winding (intLoop (negsuc 5)) ≡ negsuc 5
test-winding-neg = refl
-- the inverse when S¹ is seen as a group
inv : S¹ → S¹
inv base = base
inv (loop i) = loop (~ i)
invInvolutive : section inv inv
invInvolutive base = refl
invInvolutive (loop i) = refl
invS¹Equiv : S¹ ≃ S¹
invS¹Equiv = isoToEquiv (iso inv inv invInvolutive invInvolutive)
invS¹Path : S¹ ≡ S¹
invS¹Path = ua invS¹Equiv
-- rot, used in the Hopf fibration
rotLoop : (a : S¹) → a ≡ a
rotLoop base = loop
rotLoop (loop i) j =
hcomp (λ k → λ { (i = i0) → loop (j ∨ ~ k)
; (i = i1) → loop (j ∧ k)
; (j = i0) → loop (i ∨ ~ k)
; (j = i1) → loop (i ∧ k)}) base
rot : S¹ → S¹ → S¹
rot base x = x
rot (loop i) x = rotLoop x i
_*_ : S¹ → S¹ → S¹
a * b = rot a b
infixl 30 _*_
-- rot i j = filler-rot i j i1
filler-rot : I → I → I → S¹
filler-rot i j = hfill (λ k → λ { (i = i0) → loop (j ∨ ~ k)
; (i = i1) → loop (j ∧ k)
; (j = i0) → loop (i ∨ ~ k)
; (j = i1) → loop (i ∧ k) }) (inS base)
isPropFamS¹ : ∀ {ℓ} (P : S¹ → Type ℓ) (pP : (x : S¹) → isProp (P x)) (b0 : P base) →
PathP (λ i → P (loop i)) b0 b0
isPropFamS¹ P pP b0 i = pP (loop i) (transp (λ j → P (loop (i ∧ j))) (~ i) b0)
(transp (λ j → P (loop (i ∨ ~ j))) i b0) i
rotIsEquiv : (a : S¹) → isEquiv (rot a)
rotIsEquiv base = idIsEquiv S¹
rotIsEquiv (loop i) = isPropFamS¹ (λ x → isEquiv (rot x))
(λ x → isPropIsEquiv (rot x))
(idIsEquiv _) i
-- more direct definition of the rot (loop i) equivalence
rotLoopInv : (a : S¹) → PathP (λ i → rotLoop (rotLoop a (~ i)) i ≡ a) refl refl
rotLoopInv a i j = homotopySymInv rotLoop a j i
rotLoopEquiv : (i : I) → S¹ ≃ S¹
rotLoopEquiv i =
isoToEquiv
(iso (λ a → rotLoop a i)
(λ a → rotLoop a (~ i))
(λ a → rotLoopInv a i)
(λ a → rotLoopInv a (~ i)))
-- some cancellation laws, used in the Hopf fibration
private
rotInv-aux-1 : I → I → I → I → S¹
rotInv-aux-1 j k i =
hfill (λ l → λ { (k = i0) → (loop (i ∧ ~ l)) * loop j
; (k = i1) → loop j
; (i = i0) → (loop k * loop j) * loop (~ k)
; (i = i1) → loop (~ k ∧ ~ l) * loop j })
(inS ((loop (k ∨ i) * loop j) * loop (~ k)))
rotInv-aux-2 : I → I → I → S¹
rotInv-aux-2 i j k =
hcomp (λ l → λ { (k = i0) → inv (filler-rot (~ i) (~ j) l)
; (k = i1) → loop (j ∧ l)
; (i = i0) → filler-rot k j l
; (i = i1) → loop (j ∧ l)
; (j = i0) → loop (i ∨ k ∨ (~ l))
; (j = i1) → loop ((i ∨ k) ∧ l) })
(base)
rotInv-aux-3 : I → I → I → I → S¹
rotInv-aux-3 j k i =
hfill (λ l → λ { (k = i0) → rotInv-aux-2 i j l
; (k = i1) → loop j
; (i = i0) → loop (k ∨ l) * loop j
; (i = i1) → loop k * (inv (loop (~ j) * loop k)) })
(inS (loop k * (inv (loop (~ j) * loop (k ∨ ~ i)))))
rotInv-aux-4 : I → I → I → I → S¹
rotInv-aux-4 j k i =
hfill (λ l → λ { (k = i0) → rotInv-aux-2 i j l
; (k = i1) → loop j
; (i = i0) → loop j * loop (k ∨ l)
; (i = i1) → (inv (loop (~ j) * loop k)) * loop k })
(inS ((inv (loop (~ j) * loop (k ∨ ~ i))) * loop k))
rotInv-1 : (a b : S¹) → b * a * inv b ≡ a
rotInv-1 base base i = base
rotInv-1 base (loop k) i = rotInv-aux-1 i0 k i i1
rotInv-1 (loop j) base i = loop j
rotInv-1 (loop j) (loop k) i = rotInv-aux-1 j k i i1
rotInv-2 : (a b : S¹) → inv b * a * b ≡ a
rotInv-2 base base i = base
rotInv-2 base (loop k) i = rotInv-aux-1 i0 (~ k) i i1
rotInv-2 (loop j) base i = loop j
rotInv-2 (loop j) (loop k) i = rotInv-aux-1 j (~ k) i i1
rotInv-3 : (a b : S¹) → b * (inv (inv a * b)) ≡ a
rotInv-3 base base i = base
rotInv-3 base (loop k) i = rotInv-aux-3 i0 k (~ i) i1
rotInv-3 (loop j) base i = loop j
rotInv-3 (loop j) (loop k) i = rotInv-aux-3 j k (~ i) i1
rotInv-4 : (a b : S¹) → inv (b * inv a) * b ≡ a
rotInv-4 base base i = base
rotInv-4 base (loop k) i = rotInv-aux-4 i0 k (~ i) i1
rotInv-4 (loop j) base i = loop j
rotInv-4 (loop j) (loop k) i = rotInv-aux-4 j k (~ i) i1
| 36.548556
| 94
| 0.533573
|
599b55f2c579fd64a6831a1b72a236df4594798e
| 6,013
|
agda
|
Agda
|
Numbers/Integers/Order.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Numbers/Integers/Order.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Numbers/Integers/Order.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Integers.RingStructure.Ring
open import Semirings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Orders.Total.Definition
open import Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
module Numbers.Integers.Order where
infix 5 _<Z_
record _<Z_ (a : ℤ) (b : ℤ) : Set where
constructor le
field
x : ℕ
proof : (nonneg (succ x)) +Z a ≡ b
lessLemma : (a x : ℕ) → succ x +N a ≡ a → False
lessLemma zero x pr = naughtE (equalityCommutative pr)
lessLemma (succ a) x pr = lessLemma a x q
where
q : succ x +N a ≡ a
q rewrite Semiring.commutative ℕSemiring a (succ x) | Semiring.commutative ℕSemiring x a | Semiring.commutative ℕSemiring (succ a) x = succInjective pr
irreflexive : (x : ℤ) → x <Z x → False
irreflexive (nonneg x) record { x = y ; proof = proof } = lessLemma x y (nonnegInjective proof)
irreflexive (negSucc a) record { x = x ; proof = proof } = naughtE (equalityCommutative q)
where
pr' : nonneg (succ x) +Z (negSucc a +Z nonneg (succ a)) ≡ negSucc a +Z nonneg (succ a)
pr' rewrite +ZAssociative (nonneg (succ x)) (negSucc a) (nonneg (succ a)) = applyEquality (λ t → t +Z nonneg (succ a)) proof
pr'' : nonneg (succ x) +Z nonneg 0 ≡ nonneg 0
pr'' rewrite equalityCommutative (additiveInverseExists a) = identityOfIndiscernablesLeft _≡_ pr' q
where
q : nonneg (succ x) +Z (negSucc a +Z nonneg (succ a)) ≡ nonneg (succ (x +N 0))
q rewrite Semiring.commutative ℕSemiring x 0 | additiveInverseExists a | Semiring.commutative ℕSemiring x 0 = refl
pr''' : succ x +N 0 ≡ 0
pr''' = nonnegInjective pr''
q : succ x ≡ 0
q rewrite Semiring.commutative ℕSemiring 0 (succ x) = pr'''
lessZTransitive : {a b c : ℤ} → (a <Z b) → (b <Z c) → (a <Z c)
lessZTransitive {a} {b} {c} (le d1 pr1) (le d2 pr2) rewrite equalityCommutative pr1 = le (d1 +N succ d2) pr
where
pr : nonneg (succ (d1 +N succ d2)) +Z a ≡ c
pr rewrite +ZAssociative (nonneg (succ d2)) (nonneg (succ d1)) a | Semiring.commutative ℕSemiring (succ d2) (succ d1) = pr2
lessInherits : {a b : ℕ} → (a <N b) → ((nonneg a) <Z (nonneg b))
_<Z_.x (lessInherits {a} {b} (le x proof)) = x
_<Z_.proof (lessInherits {a} {.(succ (x +N a))} (le x refl)) = refl
lessInheritsNegsucc : {a b : ℕ} → (a <N b) → ((negSucc b) <Z negSucc a)
_<Z_.x (lessInheritsNegsucc {a} {b} (le x proof)) = x
_<Z_.proof (lessInheritsNegsucc {a} {b} (le x proof)) rewrite equalityCommutative proof = transitivity (transitivity (+ZCommutative (nonneg x) (negSucc (x +N a))) (applyEquality (λ i → negSucc i +Z nonneg x) (Semiring.commutative ℕSemiring x a))) (equalityCommutative (negSucc+Nonneg a x))
lessNegsuccNonneg : {a b : ℕ} → (negSucc a <Z nonneg b)
_<Z_.x (lessNegsuccNonneg {a} {b}) = a +N b
_<Z_.proof (lessNegsuccNonneg {zero} {b}) = refl
_<Z_.proof (lessNegsuccNonneg {succ a} {b}) = _<Z_.proof (lessNegsuccNonneg {a} {b})
lessThanTotalZ : {a b : ℤ} → ((a <Z b) || (b <Z a)) || (a ≡ b)
lessThanTotalZ {nonneg a} {nonneg b} with TotalOrder.totality ℕTotalOrder a b
lessThanTotalZ {nonneg a} {nonneg b} | inl (inl a<b) = inl (inl (lessInherits a<b))
lessThanTotalZ {nonneg a} {nonneg b} | inl (inr b<a) = inl (inr (lessInherits b<a))
lessThanTotalZ {nonneg a} {nonneg b} | inr a=b = inr (applyEquality nonneg a=b)
lessThanTotalZ {nonneg a} {negSucc b} = inl (inr (lessNegsuccNonneg {b} {a}))
lessThanTotalZ {negSucc a} {nonneg x} = inl (inl (lessNegsuccNonneg {a} {x}))
lessThanTotalZ {negSucc a} {negSucc b} with TotalOrder.totality ℕTotalOrder a b
... | inl (inl a<b) = inl (inr (lessInheritsNegsucc a<b))
... | inl (inr b<a) = inl (inl (lessInheritsNegsucc b<a))
lessThanTotalZ {negSucc a} {negSucc .a} | inr refl = inr refl
ℤOrder : TotalOrder ℤ
PartialOrder._<_ (TotalOrder.order ℤOrder) = _<Z_
PartialOrder.irreflexive (TotalOrder.order ℤOrder) {a} = irreflexive a
PartialOrder.<Transitive (TotalOrder.order ℤOrder) = lessZTransitive
TotalOrder.totality ℤOrder a b = lessThanTotalZ {a} {b}
orderRespectsAddition : (a b : ℤ) → a <Z b → (c : ℤ) → a +Z c <Z b +Z c
orderRespectsAddition (nonneg a) (nonneg b) (le x proof) (nonneg c) = le x (transitivity (+ZAssociative (nonneg (succ x)) (nonneg a) (nonneg c)) (applyEquality (_+Z nonneg c) proof))
orderRespectsAddition (nonneg a) (nonneg b) (le x proof) (negSucc c) = le x (transitivity (+ZAssociative (nonneg (succ x)) (nonneg a) (negSucc c)) (applyEquality (_+Z negSucc c) proof))
orderRespectsAddition (negSucc a) (nonneg b) (le x proof) (nonneg c) = le x (transitivity (+ZAssociative (nonneg (succ x)) (negSucc a) (nonneg c)) (applyEquality (_+Z nonneg c) proof))
orderRespectsAddition (negSucc a) (nonneg b) (le x proof) (negSucc c) = le x (transitivity (+ZAssociative (nonneg (succ x)) (negSucc a) (negSucc c)) (applyEquality (_+Z negSucc c) proof))
orderRespectsAddition (negSucc a) (negSucc b) (le x proof) (nonneg c) = le x (transitivity (+ZAssociative (nonneg (succ x)) (negSucc a) (nonneg c)) (applyEquality (_+Z nonneg c) proof))
orderRespectsAddition (negSucc a) (negSucc b) (le x proof) (negSucc c) = le x (transitivity (+ZAssociative (nonneg (succ x)) (negSucc a) (negSucc c)) (applyEquality (_+Z negSucc c) proof))
orderRespectsMultiplication : (a b : ℤ) → nonneg 0 <Z a → nonneg 0 <Z b → nonneg 0 <Z a *Z b
orderRespectsMultiplication (nonneg (succ a)) (nonneg (succ b)) 0<a 0<b = lessInherits (succIsPositive (b +N a *N succ b))
ℤPOrderedRing : PartiallyOrderedRing ℤRing (SetoidTotalOrder.partial (totalOrderToSetoidTotalOrder ℤOrder))
PartiallyOrderedRing.orderRespectsAddition ℤPOrderedRing {a} {b} = orderRespectsAddition a b
PartiallyOrderedRing.orderRespectsMultiplication ℤPOrderedRing {a} {b} = orderRespectsMultiplication a b
ℤOrderedRing : TotallyOrderedRing ℤPOrderedRing
TotallyOrderedRing.total ℤOrderedRing = totalOrderToSetoidTotalOrder ℤOrder
| 60.13
| 289
| 0.699152
|
2ee549468110be39c995b1a121777a1bbda0d23d
| 1,328
|
agda
|
Agda
|
test/Succeed/Issue2328.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue2328.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2328.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{- Examples by Twan van Laarhoven -}
{-# OPTIONS --rewriting #-}
module _ where
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
const : ∀ {a b} {A : Set a} {B : Set b} → A → B → A
const x _ = x
_∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c}
→ (f : ∀ {x} (y : B x) → C y) (g : (x : A) → B x)
→ (x : A) → C (g x)
(f ∘ g) x = f (g x)
postulate M : Set → Set
postulate pure : ∀ {A} → A → M A
postulate _>>=_ : ∀ {A B} → M A → (A → M B) → M B
postulate bind-assoc : ∀ {A B C mx} {my : A → M B} {mz : B → M C} → (mx >>= my) >>= mz ≡ mx >>= \x → my x >>= mz
{-# REWRITE bind-assoc #-}
_<*>_ : ∀ {A B} → M (A → B) → M A → M B
mf <*> mx = mf >>= \f → mx >>= (pure ∘ f)
-- Agda was comparing inferred relevances here, causing the rewrite rule
-- to fail.
shouldWork : ∀ {A B} (mx : M A) (my : M B)
→ (mx >>= (pure ∘ const)) <*> my
≡ (mx >>= (pure ∘ const)) >>= (\f → my >>= (pure ∘ f))
shouldWork mx my = refl
shouldAlsoWork : ∀ {A B} (mx : M A) (my : M B)
→ (mx >>= (pure ∘ const)) <*> my
≡ (mx >>= (pure ∘ \x _ → x)) >>= (\f → my >>= (pure ∘ f))
shouldAlsoWork mx my = refl
shouldAlsoWork2 : ∀ {A B} (mx : M A) (my : M B)
→ (mx >>= (pure ∘ const)) >>= (\f → my >>= (pure ∘ f))
≡ (mx >>= (pure ∘ \x _ → x)) >>= (\f → my >>= (pure ∘ f))
shouldAlsoWork2 mx my = refl
| 31.619048
| 114
| 0.46009
|
3dcbe7dd3386a3c21b79cceb2d381b1a16a4f075
| 883
|
agda
|
Agda
|
src/Web/Semantic/DL/Concept.agda
|
agda/agda-web-semantic
|
8ddbe83965a616bff6fc7a237191fa261fa78bab
|
[
"MIT"
] | 9
|
2015-09-13T17:46:41.000Z
|
2020-03-14T14:21:08.000Z
|
src/Web/Semantic/DL/Concept.agda
|
agda/agda-web-semantic
|
8ddbe83965a616bff6fc7a237191fa261fa78bab
|
[
"MIT"
] | 4
|
2018-11-14T02:32:28.000Z
|
2021-01-04T20:57:19.000Z
|
src/Web/Semantic/DL/Concept.agda
|
agda/agda-web-semantic
|
8ddbe83965a616bff6fc7a237191fa261fa78bab
|
[
"MIT"
] | 3
|
2017-12-03T14:52:09.000Z
|
2022-03-12T11:40:03.000Z
|
open import Web.Semantic.DL.Role using ( Role )
open import Web.Semantic.DL.Signature using ( Signature ; CN ; RN )
module Web.Semantic.DL.Concept where
infixr 9 ∀[_]_
infixr 8 ∃⟨_⟩_
infixl 7 _⊓_
infixl 6 _⊔_
data Concept (Σ : Signature) : Set where
⟨_⟩ : (c : CN Σ) → Concept Σ
¬⟨_⟩ : (c : CN Σ) → Concept Σ
⊤ : Concept Σ
⊥ : Concept Σ
_⊓_ : (C D : Concept Σ) → Concept Σ
_⊔_ : (C D : Concept Σ) → Concept Σ
∀[_]_ : (R : Role Σ) (C : Concept Σ) → Concept Σ
∃⟨_⟩_ : (R : Role Σ) (C : Concept Σ) → Concept Σ
≤1 : (R : Role Σ) → Concept Σ
>1 : (R : Role Σ) → Concept Σ
neg : ∀ {Σ} (C : Concept Σ) → Concept Σ
neg ⟨ c ⟩ = ¬⟨ c ⟩
neg ¬⟨ c ⟩ = ⟨ c ⟩
neg ⊤ = ⊥
neg ⊥ = ⊤
neg (C ⊓ D) = neg C ⊔ neg D
neg (C ⊔ D) = neg C ⊓ neg D
neg (∀[ R ] C) = ∃⟨ R ⟩ neg C
neg (∃⟨ R ⟩ C) = ∀[ R ] neg C
neg (≤1 R) = >1 R
neg (>1 R) = ≤1 R
| 25.970588
| 67
| 0.499434
|
22c42bec315e8ed9711b5f3d3b70a604bd06658b
| 8,578
|
agda
|
Agda
|
src/fot/FOTC/Program/SortList/Properties/Totality/OrdList/FlattenATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/SortList/Properties/Totality/OrdList/FlattenATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/SortList/Properties/Totality/OrdList/FlattenATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Totality properties respect to OrdList (flatten-OrdList-helper)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.Properties.Totality.OrdList.FlattenATP where
open import FOTC.Base
open import FOTC.Data.Bool.PropertiesATP
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.Type
open import FOTC.Program.SortList.Properties.Totality.BoolATP
open import FOTC.Program.SortList.Properties.Totality.ListN-ATP
open import FOTC.Program.SortList.Properties.Totality.OrdTreeATP
open import FOTC.Program.SortList.Properties.MiscellaneousATP
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
flatten-OrdList-helper : ∀ {t₁ i t₂} → Tree t₁ → N i → Tree t₂ →
OrdTree (node t₁ i t₂) →
≤-Lists (flatten t₁) (flatten t₂)
flatten-OrdList-helper {t₂ = t₂} tnil Ni Tt₂ OTt =
subst (λ t → ≤-Lists t (flatten t₂))
(sym (flatten-nil))
(le-Lists-[] (flatten t₂))
flatten-OrdList-helper (ttip {i₁} Ni₁) Tt₁ tnil OTt = prf
where postulate prf : ≤-Lists (flatten (tip i₁)) (flatten nil)
{-# ATP prove prf #-}
flatten-OrdList-helper {i = i} (ttip {i₁} Ni₁) Ni (ttip {i₂} Ni₂) OTt = prf
where
postulate lemma : i₁ ≤ i₂
{-# ATP prove lemma ≤-trans &&-list₄-t le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool #-}
postulate prf : ≤-Lists (flatten (tip i₁)) (flatten (tip i₂))
{-# ATP prove prf lemma #-}
flatten-OrdList-helper {i = i} (ttip {i₁} Ni₁) Ni
(tnode {t₂₁} {i₂} {t₂₂} Tt₂₁ Ni₂ Tt₂₂) OTt = prf
where
-- Helper terms to get the conjuncts from OTt.
helper₁ = ordTree-Bool (ttip Ni₁)
helper₂ = ordTree-Bool (tnode Tt₂₁ Ni₂ Tt₂₂)
helper₃ = le-TreeItem-Bool (ttip Ni₁) Ni
helper₄ = le-ItemTree-Bool Ni (tnode Tt₂₁ Ni₂ Tt₂₂)
helper₅ = trans (sym (ordTree-node (tip i₁) i (node t₂₁ i₂ t₂₂))) OTt
-- Helper terms to get the conjuncts from the fourth conjunct of OTt
helper₆ = le-ItemTree-Bool Ni Tt₂₁
helper₇ = le-ItemTree-Bool Ni Tt₂₂
helper₈ = trans (sym (le-ItemTree-node i t₂₁ i₂ t₂₂))
(&&-list₄-t₄ helper₁ helper₂ helper₃ helper₄ helper₅)
-- Common terms for the lemma₁ and lemma₂.
-- The ATPs could not figure out them.
OrdTree-tip-i₁ : OrdTree (tip i₁)
OrdTree-tip-i₁ = &&-list₄-t₁ helper₁ helper₂ helper₃ helper₄ helper₅
≤-TreeItem-tip-i₁-i : ≤-TreeItem (tip i₁) i
≤-TreeItem-tip-i₁-i = &&-list₄-t₃ helper₁ helper₂ helper₃ helper₄ helper₅
lemma₁ : ≤-Lists (flatten (tip i₁)) (flatten t₂₁)
lemma₁ = flatten-OrdList-helper (ttip Ni₁) Ni Tt₂₁ OT
where
-- The ATPs could not figure these terms.
OrdTree-t₂₁ : OrdTree t₂₁
OrdTree-t₂₁ =
leftSubTree-OrdTree Tt₂₁ Ni₂ Tt₂₂
(&&-list₄-t₂ helper₁ helper₂ helper₃ helper₄ helper₅)
≤-ItemTree-i-t₂₁ : ≤-ItemTree i t₂₁
≤-ItemTree-i-t₂₁ = &&-list₂-t₁ helper₆ helper₇ helper₈
postulate OT : OrdTree (node (tip i₁) i t₂₁)
{-# ATP prove OT ≤-TreeItem-tip-i₁-i ≤-ItemTree-i-t₂₁ OrdTree-tip-i₁ OrdTree-t₂₁ #-}
lemma₂ : ≤-Lists (flatten (tip i₁)) (flatten t₂₂)
lemma₂ = flatten-OrdList-helper (ttip Ni₁) Ni Tt₂₂ OT
where
-- The ATPs could not figure these terms.
OrdTree-t₂₂ : OrdTree t₂₂
OrdTree-t₂₂ =
rightSubTree-OrdTree Tt₂₁ Ni₂ Tt₂₂
(&&-list₄-t₂ helper₁ helper₂ helper₃ helper₄ helper₅)
≤-ItemTree-i-t₂₂ : ≤-ItemTree i t₂₂
≤-ItemTree-i-t₂₂ = &&-list₂-t₂ helper₆ helper₇ helper₈
postulate OT : OrdTree (node (tip i₁) i t₂₂)
{-# ATP prove OT ≤-TreeItem-tip-i₁-i ≤-ItemTree-i-t₂₂ OrdTree-tip-i₁ OrdTree-t₂₂ #-}
postulate prf : ≤-Lists (flatten (tip i₁)) (flatten (node t₂₁ i₂ t₂₂))
{-# ATP prove prf xs≤ys→xs≤zs→xs≤ys++zs flatten-ListN lemma₁ lemma₂ #-}
flatten-OrdList-helper {i = i} (tnode {t₁₁} {i₁} {t₁₂} Tt₁₁ Ni₁ Tt₁₂)
Ni tnil OTt = prf
where
-- Helper terms to get the conjuncts from OTt.
helper₁ = ordTree-Bool (tnode Tt₁₁ Ni₁ Tt₁₂)
helper₂ = ordTree-Bool tnil
helper₃ = le-TreeItem-Bool (tnode Tt₁₁ Ni₁ Tt₁₂) Ni
helper₄ = le-ItemTree-Bool Ni tnil
helper₅ = trans (sym (ordTree-node (node t₁₁ i₁ t₁₂) i nil)) OTt
-- Helper terms to get the conjuncts from the third conjunct of OTt.
helper₆ = le-TreeItem-Bool Tt₁₁ Ni
helper₇ = le-TreeItem-Bool Tt₁₂ Ni
helper₈ = trans (sym (le-TreeItem-node t₁₁ i₁ t₁₂ i))
(&&-list₄-t₃ helper₁ helper₂ helper₃ helper₄ helper₅)
lemma₁ : ≤-Lists (flatten t₁₁) (flatten nil)
lemma₁ = flatten-OrdList-helper Tt₁₁ Ni tnil OT
where
postulate OT : OrdTree (node t₁₁ i nil)
{-# ATP prove OT leftSubTree-OrdTree &&-list₂-t &&-list₄-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ helper₇ helper₈ #-}
lemma₂ : ≤-Lists (flatten t₁₂) (flatten nil)
lemma₂ = flatten-OrdList-helper Tt₁₂ Ni tnil OT
where
postulate OT : OrdTree (node t₁₂ i nil)
{-# ATP prove OT rightSubTree-OrdTree &&-list₄-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ helper₇ helper₈ #-}
postulate prf : ≤-Lists (flatten (node t₁₁ i₁ t₁₂)) (flatten nil)
{-# ATP prove prf xs≤zs→ys≤zs→xs++ys≤zs flatten-ListN lemma₁ lemma₂ #-}
flatten-OrdList-helper {i = i} (tnode {t₁₁} {i₁} {t₁₂} Tt₁₁ Ni₁ Tt₁₂) Ni
(ttip {i₂} Ni₂) OTt = prf
where
-- Helper terms to get the conjuncts from OTt.
helper₁ = ordTree-Bool (tnode Tt₁₁ Ni₁ Tt₁₂)
helper₂ = ordTree-Bool (ttip Ni₂)
helper₃ = le-TreeItem-Bool (tnode Tt₁₁ Ni₁ Tt₁₂) Ni
helper₄ = le-ItemTree-Bool Ni (ttip Ni₂)
helper₅ = trans (sym (ordTree-node (node t₁₁ i₁ t₁₂) i (tip i₂))) OTt
-- Helper terms to get the conjuncts from the third conjunct of OTt.
helper₆ = le-TreeItem-Bool Tt₁₁ Ni
helper₇ = le-TreeItem-Bool Tt₁₂ Ni
helper₈ = trans (sym (le-TreeItem-node t₁₁ i₁ t₁₂ i))
(&&-list₄-t₃ helper₁ helper₂ helper₃ helper₄ helper₅)
lemma₁ : ≤-Lists (flatten t₁₁) (flatten (tip i₂))
lemma₁ = flatten-OrdList-helper Tt₁₁ Ni (ttip Ni₂) OT
where
postulate OT : OrdTree (node t₁₁ i (tip i₂))
{-# ATP prove OT leftSubTree-OrdTree &&-list₂-t &&-list₄-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ helper₇ helper₈ #-}
lemma₂ : ≤-Lists (flatten t₁₂) (flatten (tip i₂))
lemma₂ = flatten-OrdList-helper Tt₁₂ Ni (ttip Ni₂) OT
where
postulate OT : OrdTree (node t₁₂ i (tip i₂))
{-# ATP prove OT rightSubTree-OrdTree &&-list₂-t &&-list₄-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ helper₇ helper₈ #-}
postulate prf : ≤-Lists (flatten (node t₁₁ i₁ t₁₂)) (flatten (tip i₂))
{-# ATP prove prf xs≤zs→ys≤zs→xs++ys≤zs flatten-ListN lemma₁ lemma₂ #-}
flatten-OrdList-helper {i = i} (tnode {t₁₁} {i₁} {t₁₂} Tt₁₁ Ni₁ Tt₁₂) Ni
(tnode {t₂₁} {i₂} {t₂₂} Tt₂₁ Ni₂ Tt₂₂) OTt = prf
where
-- Helper terms to get the conjuncts from OTt.
helper₁ = ordTree-Bool (tnode Tt₁₁ Ni₁ Tt₁₂)
helper₂ = ordTree-Bool (tnode Tt₂₁ Ni₂ Tt₂₂)
helper₃ = le-TreeItem-Bool (tnode Tt₁₁ Ni₁ Tt₁₂) Ni
helper₄ = le-ItemTree-Bool Ni (tnode Tt₂₁ Ni₂ Tt₂₂)
helper₅ = trans (sym (ordTree-node (node t₁₁ i₁ t₁₂) i (node t₂₁ i₂ t₂₂)))
OTt
-- Helper terms to get the conjuncts from the third conjunct of OTt.
helper₆ = le-TreeItem-Bool Tt₁₁ Ni
helper₇ = le-TreeItem-Bool Tt₁₂ Ni
helper₈ = trans (sym (le-TreeItem-node t₁₁ i₁ t₁₂ i))
(&&-list₄-t₃ helper₁ helper₂ helper₃ helper₄ helper₅)
lemma₁ : ≤-Lists (flatten t₁₁) (flatten (node t₂₁ i₂ t₂₂))
lemma₁ = flatten-OrdList-helper Tt₁₁ Ni (tnode Tt₂₁ Ni₂ Tt₂₂) OT
where
postulate OT : OrdTree (node t₁₁ i (node t₂₁ i₂ t₂₂))
{-# ATP prove OT leftSubTree-OrdTree &&-list₂-t &&-list₄-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ helper₇ helper₈ #-}
lemma₂ : ≤-Lists (flatten t₁₂) (flatten (node t₂₁ i₂ t₂₂))
lemma₂ = flatten-OrdList-helper Tt₁₂ Ni (tnode Tt₂₁ Ni₂ Tt₂₂) OT
where
postulate OT : OrdTree (node t₁₂ i (node t₂₁ i₂ t₂₂))
{-# ATP prove OT rightSubTree-OrdTree &&-list₂-t &&-list₄-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ helper₇ helper₈ #-}
postulate prf : ≤-Lists (flatten (node t₁₁ i₁ t₁₂))
(flatten (node t₂₁ i₂ t₂₂))
{-# ATP prove prf xs≤zs→ys≤zs→xs++ys≤zs flatten-ListN lemma₁ lemma₂ #-}
| 43.543147
| 131
| 0.648636
|
cb5c25de34ce01155c94ffdd03dd5fb66b789091
| 1,808
|
agda
|
Agda
|
Cubical/Functions/Surjection.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Surjection.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Surjection.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Functions.Surjection where
open import Cubical.Core.Everything
open import Cubical.Data.Sigma
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Functions.Embedding
open import Cubical.HITs.PropositionalTruncation as PropTrunc
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
f : A → B
isSurjection : (A → B) → Type _
isSurjection f = ∀ b → ∥ fiber f b ∥
section→isSurjection : {g : B → A} → section f g → isSurjection f
section→isSurjection {g = g} s b = ∣ g b , s b ∣
isSurjectionIsProp : isProp (isSurjection f)
isSurjectionIsProp = isPropΠ λ _ → squash
isEquiv→isSurjection : isEquiv f → isSurjection f
isEquiv→isSurjection e b = ∣ fst (equiv-proof e b) ∣
isEquiv→isEmbedding×isSurjection : isEquiv f → isEmbedding f × isSurjection f
isEquiv→isEmbedding×isSurjection e = isEquiv→isEmbedding e , isEquiv→isSurjection e
isEmbedding×isSurjection→isEquiv : isEmbedding f × isSurjection f → isEquiv f
equiv-proof (isEmbedding×isSurjection→isEquiv {f = f} (emb , sur)) b =
inhProp→isContr (PropTrunc.rec fib' (λ x → x) fib) fib'
where
hpf : hasPropFibers f
hpf = isEmbedding→hasPropFibers emb
fib : ∥ fiber f b ∥
fib = sur b
fib' : isProp (fiber f b)
fib' = hpf b
isEquiv≃isEmbedding×isSurjection : isEquiv f ≃ isEmbedding f × isSurjection f
isEquiv≃isEmbedding×isSurjection = isoToEquiv (iso
isEquiv→isEmbedding×isSurjection
isEmbedding×isSurjection→isEquiv
(λ _ → isOfHLevelΣ 1 isEmbeddingIsProp (\ _ → isSurjectionIsProp) _ _)
(λ _ → isPropIsEquiv _ _ _))
isPropIsSurjection : isProp (isSurjection f)
isPropIsSurjection = isPropΠ λ _ → propTruncIsProp
| 31.719298
| 83
| 0.741704
|
394574739d493bd03a6c3f6c040e62b35acb35d5
| 2,109
|
agda
|
Agda
|
doc/icfp20/code/MidiEvent.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 28
|
2017-04-21T09:08:52.000Z
|
2022-03-04T18:04:07.000Z
|
doc/icfp20/code/MidiEvent.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 1
|
2020-11-13T01:26:20.000Z
|
2020-11-17T00:58:55.000Z
|
doc/icfp20/code/MidiEvent.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 3
|
2019-01-12T17:02:36.000Z
|
2020-11-10T04:04:40.000Z
|
{-# OPTIONS --without-K #-}
module MidiEvent where
open import Data.Fin using (Fin; #_)
open import Data.List using (List; _∷_; []; concat; map)
open import Data.Nat using (ℕ; _+_; _⊔_)
open import Data.Product using (_×_; _,_; proj₁)
open import Data.String using (String)
open import Data.Vec using (toList)
open import Function using (_∘_)
open import Music using (Melody; melody; Counterpoint; cp; Harmony; melody→notes; harmony→counterpoint)
open import Note using (Note; tone; rest; duration)
open import Pitch using (Pitch)
-- General MIDI instrument numbers range from 1 to 128,
-- so this is the actual instrument number minus 1.
InstrumentNumber-1 : Set
InstrumentNumber-1 = Fin 128
Tick : Set
Tick = ℕ
Velocity : Set
Velocity = Fin 128
defaultVelocity : Velocity
defaultVelocity = # 60
-- percussion is channel 10, so 9 as Channel-1
Channel-1 : Set
Channel-1 = Fin 16
-- in bpm
Tempo : Set
Tempo = ℕ
record MidiEvent : Set where
constructor midiEvent
field
pitch : Pitch -- Pitch was defined to correspond to MIDI pitch
start : Tick
stop : Tick
velocity : Velocity
record MidiTrack : Set where
constructor track
field
trackName : String
instrumentNumber : InstrumentNumber-1
channel : Channel-1
tempo : Tempo -- initial tempo
events : List MidiEvent
notes→events : Velocity → List Note → List MidiEvent
notes→events v ns = me 0 ns where
me : Tick → List Note → List MidiEvent
me t [] = []
me t (tone (duration d) p ∷ ns) = midiEvent p t (t + d) v ∷ me (t + d) ns
me t (rest (duration d) ∷ ns) = me (t + d) ns
melody→events : {n : ℕ} → Velocity → Melody n → List MidiEvent
melody→events v = notes→events v ∘ melody→notes
counterpoint→events : {v d : ℕ} → Velocity → Counterpoint v d → List MidiEvent
counterpoint→events v (cp ms) = concat (map (melody→events v) (toList ms))
harmony→events : {v d : ℕ} → Velocity → Harmony v d → List MidiEvent
harmony→events v = counterpoint→events v ∘ harmony→counterpoint
| 29.704225
| 110
| 0.65908
|
3178f22185ab1c2035e1a7dd129a26bbfe224bfb
| 494
|
agda
|
Agda
|
BCK.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
BCK.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
BCK.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module BCK where
open import Prelude hiding (B; C)
infixl 4 _$$_
data BCK : Type where
_$$_ : BCK → BCK → BCK
B C K : BCK
open import Data.List
stack : BCK → Maybe BCK
stack xs = go xs []
where
go : BCK → List BCK → Maybe BCK
go (f $$ x) xs = go f (x ∷ xs)
go B (f ∷ g ∷ x ∷ xs) = just (foldl _$$_ (f $$ (g $$ x)) xs)
go C (f ∷ x ∷ y ∷ xs) = just (foldl _$$_ (f $$ y $$ x) xs)
go K (x ∷ y ∷ xs) = just (foldl _$$_ x xs)
go _ _ = nothing
| 20.583333
| 62
| 0.52834
|
5758da81a50989bcd18048f8ad90c4e1808e530d
| 595
|
agda
|
Agda
|
presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/main.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/main.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/main.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module main where
{- unsized Versions omitted in talk -}
import interactiveProgramsAgdaUnsized
import objectsInAgdaUnsized
{- end unsized Versions omitted in talk -}
import interactiveProgramsAgda
import objectsInAgda
{- Probably omit because of time -}
import interfaceExtensionAndDelegation
{- End Probably omit because of time -}
{- Omit later parts about proofs -}
import stateDependentObjects
{- End Omit later parts about proofs -}
import stateDependentIO
import drawingProgram
import objectOrientedGui
import spaceShipSimpleVar
import spaceShipCell
import spaceShipAdvanced
| 18.030303
| 42
| 0.815126
|
0e59f45e7353f3e1daec2736d1ca0699d38e5319
| 1,938
|
agda
|
Agda
|
core/lib/types/Types.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Types.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Types.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
module lib.types.Types where
open import lib.Basics
open import lib.types.BigWedge public
open import lib.types.Bool public
open import lib.types.Choice public
open import lib.types.Circle public
open import lib.types.Cofiber public
open import lib.types.CommutingSquare public
open import lib.types.Coproduct public
open import lib.types.Cospan public
open import lib.types.Cover public
open import lib.types.EilenbergMacLane1 public
open import lib.types.Empty public
open import lib.types.Group public
open import lib.types.GroupSet public
open import lib.types.Groupoid public
open import lib.types.HList public
open import lib.types.Int public
open import lib.types.IteratedSuspension public
open import lib.types.Join public
open import lib.types.Lift public
open import lib.types.List public
open import lib.types.LoopSpace public
open import lib.types.Nat public
open import lib.types.NatColim public
open import lib.types.PathSeq public
open import lib.types.PathSet public
open import lib.types.Paths public
open import lib.types.Pi public
open import lib.types.Pointed public
open import lib.types.Pullback public
open import lib.types.Pushout public
open import lib.types.PushoutFlattening public
open import lib.types.PushoutFlip public
open import lib.types.PushoutFmap public
open import lib.types.SetQuotient public
open import lib.types.Sigma public
open import lib.types.Smash public
open import lib.types.Span public
open import lib.types.Subtype public
open import lib.types.Suspension public
open import lib.types.TLevel public
open import lib.types.Torus public
open import lib.types.Truncation public
open import lib.types.Unit public
open import lib.types.Wedge public
open import lib.types.Word public
-- This should probably not be exported
-- module Generic1HIT {i j} (A : Type i) (B : Type j) (f g : B → A) where
-- open import lib.types.Generic1HIT A B f g public
| 35.236364
| 73
| 0.816305
|
4dc3787469a3c7b69c0022807fdd10853201c31c
| 5,094
|
agda
|
Agda
|
Structure/Signature.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Signature.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Signature.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Signature where
open import Data.Tuple.Raise
open import Data.Tuple.Raiseᵣ.Functions
import Lvl
open import Numeral.Natural
open import Structure.Function
open import Structure.Setoid
open import Structure.Relator
open import Type
private variable ℓ ℓᵢ ℓᵢ₁ ℓᵢ₂ ℓᵢ₃ ℓd ℓd₁ ℓd₂ ℓᵣ ℓᵣ₁ ℓᵣ₂ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level
private variable n : ℕ
-- A signature consists of a countable family of sets of function and relation symbols.
-- `functions(n)` and `relations(n)` should be interpreted as the indices for functions/relations of arity `n`.
record Signature : Type{Lvl.𝐒(ℓᵢ₁ Lvl.⊔ ℓᵢ₂)} where
field
functions : ℕ → Type{ℓᵢ₁}
relations : ℕ → Type{ℓᵢ₂}
private variable s : Signature{ℓᵢ₁}{ℓᵢ₂}
import Data.Tuple.Equiv as Tuple
-- A structure with a signature `s` consists of a domain and interpretations of the function/relation symbols in `s`.
record Structure (s : Signature{ℓᵢ₁}{ℓᵢ₂}) : Type{Lvl.𝐒(ℓₑ Lvl.⊔ ℓd Lvl.⊔ ℓᵣ) Lvl.⊔ ℓᵢ₁ Lvl.⊔ ℓᵢ₂} where
open Signature(s)
field
domain : Type{ℓd}
⦃ equiv ⦄ : ∀{n} → Equiv{ℓₑ}(domain ^ n)
⦃ ext ⦄ : ∀{n} → Tuple.Extensionality(equiv{𝐒(𝐒 n)})
function : functions(n) → ((domain ^ n) → domain)
⦃ function-func ⦄ : ∀{fi} → Function(function{n} fi)
relation : relations(n) → ((domain ^ n) → Type{ℓᵣ})
⦃ relation-func ⦄ : ∀{ri} → UnaryRelator(relation{n} ri)
open Structure public using() renaming (domain to dom ; function to fn ; relation to rel)
open import Logic.Predicate
module _ {s : Signature{ℓᵢ₁}{ℓᵢ₂}} where
private variable A B C S : Structure{ℓd = ℓd}{ℓᵣ = ℓᵣ}(s)
private variable fi : Signature.functions s n
private variable ri : Signature.relations s n
private variable xs : dom(S) ^ n
record Homomorphism
(A : Structure{ℓₑ = ℓₑ₁}{ℓd = ℓd₁}{ℓᵣ = ℓᵣ₁}(s))
(B : Structure{ℓₑ = ℓₑ₂}{ℓd = ℓd₂}{ℓᵣ = ℓᵣ₂}(s))
(f : dom(A) → dom(B))
: Type{ℓₑ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓd₁ Lvl.⊔ ℓd₂ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₂ Lvl.⊔ Lvl.ofType(Type.of s)}
where
field
⦃ function ⦄ : Function(f)
preserve-functions : ∀{xs : dom(A) ^ n} → (f(fn(A) fi xs) ≡ fn(B) fi (map f xs))
preserve-relations : ∀{xs : dom(A) ^ n} → (rel(A) ri xs) → (rel(B) ri (map f xs))
_→ₛₜᵣᵤ_ : Structure{ℓₑ = ℓₑ₁}{ℓd = ℓd₁}{ℓᵣ = ℓᵣ₁}(s) → Structure{ℓₑ = ℓₑ₂}{ℓd = ℓd₂}{ℓᵣ = ℓᵣ₂}(s) → Type
A →ₛₜᵣᵤ B = ∃(Homomorphism A B)
open import Data
open import Data.Tuple as Tuple using (_,_)
open import Data.Tuple.Raiseᵣ.Proofs
open import Functional
open import Function.Proofs
open import Lang.Instance
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
idₛₜᵣᵤ : A →ₛₜᵣᵤ A
∃.witness idₛₜᵣᵤ = id
Homomorphism.preserve-functions (∃.proof (idₛₜᵣᵤ {A = A})) {n} {fi} {xs} = congruence₁(fn A fi) (symmetry(Equiv._≡_ (Structure.equiv A)) ⦃ Equiv.symmetry infer ⦄ map-id)
Homomorphism.preserve-relations (∃.proof (idₛₜᵣᵤ {A = A})) {n} {ri} {xs} = substitute₁ₗ(rel A ri) map-id
_∘ₛₜᵣᵤ_ : let _ = A , B , C in (B →ₛₜᵣᵤ C) → (A →ₛₜᵣᵤ B) → (A →ₛₜᵣᵤ C)
∃.witness (([∃]-intro f) ∘ₛₜᵣᵤ ([∃]-intro g)) = f ∘ g
Homomorphism.function (∃.proof ([∃]-intro f ∘ₛₜᵣᵤ [∃]-intro g)) = [∘]-function {f = f}{g = g}
Homomorphism.preserve-functions (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {fi = fi} = transitivity(_≡_) ⦃ Equiv.transitivity infer ⦄ (transitivity(_≡_) ⦃ Equiv.transitivity infer ⦄ (congruence₁(f) (Homomorphism.preserve-functions hom-g)) (Homomorphism.preserve-functions hom-f)) (congruence₁(fn C fi) (symmetry(Equiv._≡_ (Structure.equiv C)) ⦃ Equiv.symmetry infer ⦄ (map-[∘] {f = f}{g = g})))
Homomorphism.preserve-relations (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {ri = ri} = substitute₁ₗ (rel C ri) map-[∘] ∘ Homomorphism.preserve-relations hom-f ∘ Homomorphism.preserve-relations hom-g
open import Function.Equals
open import Function.Equals.Proofs
open import Logic.Predicate.Equiv
open import Structure.Category
open import Structure.Categorical.Properties
Structure-Homomorphism-category : Category(_→ₛₜᵣᵤ_ {ℓₑ}{ℓd}{ℓᵣ})
Category._∘_ Structure-Homomorphism-category = _∘ₛₜᵣᵤ_
Category.id Structure-Homomorphism-category = idₛₜᵣᵤ
BinaryOperator.congruence (Category.binaryOperator Structure-Homomorphism-category) = [⊜][∘]-binaryOperator-raw
_⊜_.proof (Morphism.Associativity.proof (Category.associativity Structure-Homomorphism-category) {_} {_} {_} {_} {[∃]-intro f} {[∃]-intro g} {[∃]-intro h}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(g(h(x)))}
_⊜_.proof (Morphism.Identityₗ.proof (Tuple.left (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(x)}
_⊜_.proof (Morphism.Identityᵣ.proof (Tuple.right (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(x)}
module _ (s : Signature{ℓᵢ₁}{ℓᵢ₂}) where
data Term : Type{ℓᵢ₁} where
var : ℕ → Term
func : (Signature.functions s n) → (Term ^ n) → Term
| 49.941176
| 445
| 0.66863
|
1d3b53b038626f851b43c2dbbd8b2c21db6764af
| 5,144
|
agda
|
Agda
|
Agda/free-group.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/free-group.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/free-group.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split #-}
module free-group where
import 15-groups
open 15-groups public
{- We state the universal property of the free group on a set X -}
precomp-universal-property-free-group :
{l1 l2 l3 : Level} (X : UU-Set l1) (F : Group l2) (G : Group l3)
(f : type-hom-Set X (set-Group F)) →
hom-Group F G → type-hom-Set X (set-Group G)
precomp-universal-property-free-group X F G f g = (map-hom-Group F G g) ∘ f
universal-property-free-group :
(l : Level) {l1 l2 : Level} (X : UU-Set l1) (F : Group l2)
(f : type-hom-Set X (set-Group F)) → UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-free-group l X F f =
(G : Group l) → is-equiv (precomp-universal-property-free-group X F G f)
{- We state the universal property of the initial set equipped with a point
and an automorphism for each x : X. -}
universal-property-initial-pset-with-automorphisms :
(l : Level) {l1 l2 : Level} (X : UU-Set l1) (Y : UU-Set l2)
(pt-Y : type-Set Y) (f : type-Set X → (type-Set Y ≃ type-Set Y)) →
UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-initial-pset-with-automorphisms l X Y pt-Y f =
(Z : UU-Set l) (pt-Z : type-Set Z) (g : type-Set X → (type-Set Z ≃ type-Set Z)) →
is-contr
( Σ ( type-hom-Set Y Z)
( λ h →
( Id (h pt-Y) pt-Z) ×
( (x : type-Set X) (y : type-Set Y) →
Id (h (map-equiv (f x) y)) (map-equiv (g x) (h y)))))
map-initial-pset-with-automorphisms :
{ l1 l2 l3 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)
( f : type-Set X → (type-Set Y ≃ type-Set Y)) →
( {l : Level} →
universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →
( Z : UU-Set l3) (pt-Z : type-Set Z)
( g : type-Set X → (type-Set Z ≃ type-Set Z)) →
type-hom-Set Y Z
map-initial-pset-with-automorphisms
X Y pt-Y f up-Y Z pt-Z g = pr1 (center (up-Y Z pt-Z g))
preserves-point-map-initial-pset-with-automorphisms :
{ l1 l2 l3 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)
( f : type-Set X → (type-Set Y ≃ type-Set Y)) →
( up-Y : {l : Level} →
universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →
( Z : UU-Set l3) (pt-Z : type-Set Z)
( g : type-Set X → (type-Set Z ≃ type-Set Z)) →
Id (map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g pt-Y) pt-Z
preserves-point-map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g =
pr1 (pr2 (center (up-Y Z pt-Z g)))
htpy-map-initial-pset-with-automorphisms :
{ l1 l2 l3 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)
( f : type-Set X → (type-Set Y ≃ type-Set Y)) →
( up-Y : {l : Level} →
universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →
( Z : UU-Set l3) (pt-Z : type-Set Z)
( g : type-Set X → (type-Set Z ≃ type-Set Z)) →
( x : type-Set X) (y : type-Set Y) →
Id ( map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g
( map-equiv (f x) y))
( map-equiv (g x)
( map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g y))
htpy-map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g =
pr2 (pr2 (center (up-Y Z pt-Z g)))
{- We show a dependent elimination property for the initial pointed set with
an automorphism for each x : X. -}
dependent-up-initial-pset-with-automorphisms :
{ l1 l2 l3 l4 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)
( f : type-Set X → (type-Set Y ≃ type-Set Y)) →
( up-Y : {l : Level} →
universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →
( Z : UU-Set l3) (pt-Z : type-Set Z)
( g : type-Set X → (type-Set Z ≃ type-Set Z)) →
( P : type-Set Z → UU-Set l4)
( p : type-Set (P pt-Z))
( e : (x : type-Set X) (z : type-Set Z) →
type-Set (P z) ≃ type-Set (P (map-equiv (g x) z))) →
( y : type-Set Y) →
type-Set (P (map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g y))
dependent-up-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g P p e =
{!!}
{- We show that the initial set equipped with a point and an automorphism for
each x : X is a group. -}
mul-initial-pset-with-automorphisms :
{l1 l2 : Level} (X : UU-Set l1) (Y : UU-Set l2)
(pt-Y : type-Set Y) (f : type-Set X → (type-Set Y ≃ type-Set Y)) →
( {l : Level} →
universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →
type-Set Y → type-Set Y → type-Set Y
mul-initial-pset-with-automorphisms {l1} {l2} X Y pt-Y f up-Y =
map-initial-pset-with-automorphisms
X Y pt-Y f up-Y (hom-Set Y Y) id
( λ x → equiv-postcomp (type-Set Y) (f x))
associative-mul-initial-pset-with-automorphisms :
{l1 l2 : Level} (X : UU-Set l1) (Y : UU-Set l2)
(pt-Y : type-Set Y) (f : type-Set X → (type-Set Y ≃ type-Set Y)) →
( up-Y : {l : Level} →
universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →
( x y z : type-Set Y) →
Id ( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y
( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y x y) z)
( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y x
( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y y z))
associative-mul-initial-pset-with-automorphisms X Y pt-Y f up-Y x y z = {!refl!}
| 42.866667
| 83
| 0.606921
|
41dde7d2d35259c4cbe18ff829272c4a1ca337fb
| 5,124
|
agda
|
Agda
|
Categories/Category.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Categories/Category.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Categories/Category.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Vectors
open import Semirings.Definition
open import Categories.Definition
open import Orders
open import Categories.Functor.Definition
open import Categories.Examples
module Categories.Category where
postulate
extensionality : {a b : _} {S : Set a} {T : S → Set b} {f g : (x : S) → T x} → ((x : S) → f x ≡ g x) → f ≡ g
≡Unique : {a : _} {X : Set a} → {a b : X} → (p1 p2 : a ≡ b) → (p1 ≡ p2)
≡Unique refl refl = refl
NatPreorder : Category {lzero} {lzero}
NatPreorder = record { objects = ℕ ; arrows = λ m n → m ≤N n ; id = λ x → inr refl ; _∘_ = λ f g → leqTransitive g f ; rightId = λ x<y → leqUnique (leqTransitive x<y (inr refl)) x<y ; leftId = λ x<y → leqUnique (leqTransitive (inr refl) x<y) x<y ; associative = λ z<=w y<=z x<=y → leqUnique (leqTransitive (leqTransitive x<=y y<=z) z<=w) (leqTransitive x<=y (leqTransitive y<=z z<=w)) }
where
leqTransitive : {a b c : ℕ} → (a ≤N b) → (b ≤N c) → (a ≤N c)
leqTransitive (inl a<b) (inl b<c) = inl (TotalOrder.<Transitive ℕTotalOrder a<b b<c)
leqTransitive (inl a<b) (inr b=c) rewrite b=c = inl a<b
leqTransitive (inr a=b) (inl b<c) rewrite a=b = inl b<c
leqTransitive (inr a=b) (inr b=c) rewrite a=b | b=c = inr refl
<Nunique : {a b : ℕ} → (p1 p2 : a <N b) → p1 ≡ p2
<Nunique {a} {b} (le a-b pr1) (le a-b2 pr2) = go a-b pr1 a-b2 pr2 p'
where
p : a-b2 +N a ≡ a-b +N a
p rewrite equalityCommutative pr1 = succInjective pr2
p' : a-b2 ≡ a-b
p' = canSubtractFromEqualityRight p
go : (a-b : ℕ) (pr1 : succ (a-b +N a) ≡ b) (a-b2 : ℕ) (pr2 : succ (a-b2 +N a) ≡ b) (p : a-b2 ≡ a-b) → (le a-b pr1) ≡ (le a-b2 pr2)
go a-b pr1 a-b2 pr2 eq rewrite eq = applyEquality (λ i → le a-b i) (≡Unique pr1 pr2)
leqUnique : {a b : ℕ} → (p1 : a ≤N b) → (p2 : a ≤N b) → p1 ≡ p2
leqUnique (inl a<b) (inl a<b2) = applyEquality inl (<Nunique a<b a<b2)
leqUnique (inl a<b) (inr a=b) rewrite a=b = exFalso (lessIrreflexive a<b)
leqUnique (inr a=b) (inl a<b) rewrite a=b = exFalso (lessIrreflexive a<b)
leqUnique (inr a=b1) (inr a=b2) rewrite a=b1 | a=b2 = refl
NatMonoid : Category {lzero} {lzero}
NatMonoid = record { objects = True ; arrows = λ _ _ → ℕ ; id = λ x → 0 ; _∘_ = λ f g → f +N g ; rightId = λ f → refl ; leftId = λ f → Semiring.sumZeroRight ℕSemiring f ; associative = λ a b c → Semiring.+Associative ℕSemiring a b c }
typeCastCat : {a b c d : _} {C : Category {a} {b}} {D : Category {c} {d}} (F : Functor C D) (G : Functor C D) (S T : Category.objects C) (pr : Functor.onObj F ≡ Functor.onObj G) → Category.arrows D (Functor.onObj G S) (Functor.onObj G T) ≡ Category.arrows D (Functor.onObj F S) (Functor.onObj F T)
typeCastCat F G S T pr rewrite pr = refl
equalityFunctionsEqual : {a b : _} {A : Set a} {B : Set b} (f : A → (B ≡ B)) → (g : A → (B ≡ B)) → (f ≡ g)
equalityFunctionsEqual f g = extensionality λ x → ≡Unique (f x) (g x)
equalityFunctionsEqual' : {a b : _} {A : Set a} {B : Set b} (f : A → (B ≡ B)) → (g : A → (B ≡ B)) → (f ≡ g)
equalityFunctionsEqual' f g = extensionality λ x → ≡Unique (f x) (g x)
functorsEqual' : {a b c d : _} {C : Category {a} {b}} {D : Category {c} {d}} (F : Functor C D) (G : Functor C D) (objEq : (Functor.onObj F) ≡ Functor.onObj G) (arrEq : ∀ {S T : Category.objects C} → {f : Category.arrows C S T} → (Functor.onArrow F {S} {T} f ≡ (typeCast (Functor.onArrow G {S} {T} f) (typeCastCat F G S T objEq)))) → F ≡ G
functorsEqual' record { onObj = onObjF ; onArrow = onArrowF ; mapId = mapIdF ; mapCompose = mapComposeF } record { onObj = onObjG ; onArrow = onArrowG ; mapId = mapIdG ; mapCompose = mapComposeG } prObj prArr rewrite prObj = {!!}
VEC : {a : _} → ℕ → Functor (SET {a}) (SET {a})
VEC {a} n = record { onObj = λ X → Vec X n ; onArrow = λ f → λ v → vecMap f v ; mapId = extensionality mapId' ; mapCompose = λ f g → extensionality λ vec → help f g vec }
where
vecMapLemma : {a : _} {T : Set a} {n : ℕ} (v : Vec T n) → vecMap (Category.id SET T) v ≡ v
vecMapLemma {a} v with inspect (SET {a})
vecMapLemma {a} v | y with≡ SetCopy = vecMapIdFact (λ i → refl) v
mapId' : {a : _} {T : Set a} {n : ℕ} → (v : Vec T n) → vecMap (Category.id SET T) v ≡ Category.id SET (Vec T n) v
mapId' v rewrite vecMapLemma v = refl
help : ∀ {a n} {X Y Z : Category.objects (SET {a})} (f : X → Y) (g : Y → Z) (vec : Vec X n) → vecMap (λ x → g (f x)) vec ≡ vecMap g (vecMap f vec)
help f g vec = equalityCommutative (vecMapCompositionFact (λ x → refl) vec)
CATEGORY : {a b : _} → Category {lsuc b ⊔ lsuc a} {b ⊔ a}
CATEGORY {a} {b} = record { objects = Category {a} {b} ; arrows = λ C D → Functor C D ; _∘_ = λ F G → functorCompose F G ; id = λ C → idFunctor C ; rightId = λ F → {!!} ; leftId = λ F → {!!} ; associative = {!!} }
where
rightIdFact : {a b c d : _} → {C : Category {a} {b}} {D : Category {c} {d}} (F : Functor C D) → functorCompose (idFunctor D) F ≡ F
rightIdFact {C = C} {D} F = {!!}
| 65.692308
| 386
| 0.595238
|
2e3752dc3fed438710e561ba0075c5ee7992bd67
| 2,940
|
agda
|
Agda
|
Data/Collection/Inclusion.agda
|
banacorn/lambda-calculus
|
f81b116473582ab7956adc4bf1d7ebf1ae2a213a
|
[
"MIT"
] | null | null | null |
Data/Collection/Inclusion.agda
|
banacorn/lambda-calculus
|
f81b116473582ab7956adc4bf1d7ebf1ae2a213a
|
[
"MIT"
] | null | null | null |
Data/Collection/Inclusion.agda
|
banacorn/lambda-calculus
|
f81b116473582ab7956adc4bf1d7ebf1ae2a213a
|
[
"MIT"
] | null | null | null |
module Data.Collection.Inclusion where
open import Data.Collection.Equivalence
open import Data.Collection.Core
open import Function using (id; _∘_)
open import Function.Equivalence using (equivalence)
open import Level using (Level; suc; zero)
open import Relation.Unary hiding (_⇒_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
≋⇒⊆ : _≋_ ⇒ _⊆_
≋⇒⊆ P≋Q ∈P = nach P≋Q ∈P
⊆-Transitive : ∀ {a ℓ} {A : Set a} → Transitive {_} {_} {Pred A ℓ} _⊆_
⊆-Transitive P⊆Q Q⊆R = Q⊆R ∘ P⊆Q
⊆-IsPreorder : IsPreorder _≋_ _⊆_
⊆-IsPreorder = record
{ isEquivalence = ≋-IsEquivalence
; reflexive = ≋⇒⊆
; trans = ⊆-Transitive
}
⊆-Preorder : Preorder _ _ _
⊆-Preorder = record
{ Carrier = Pred String zero
; _≈_ = _≋_
; _∼_ = _⊆_
; isPreorder = ⊆-IsPreorder
}
⊆-Antisymmetric : Antisymmetric _≋_ _⊆_
⊆-Antisymmetric P⊆Q Q⊆P = equivalence P⊆Q Q⊆P
⊆-IsPartialOrder : IsPartialOrder _≋_ _⊆_
⊆-IsPartialOrder = record
{ isPreorder = ⊆-IsPreorder
; antisym = ⊆-Antisymmetric
}
⊆-Poset : Poset _ _ _
⊆-Poset = record
{ Carrier = Pred String zero
; _≈_ = _≋_
; _≤_ = _⊆_
; isPartialOrder = ⊆-IsPartialOrder
}
--------------------------------------------------------------------------------
-- Conditional Inclusion
--------------------------------------------------------------------------------
_⊆[_]_ : ∀ {a ℓ₀ ℓ₁ ℓ₂} {A : Set a} → Pred A ℓ₀ → Pred A ℓ₁ → Pred A ℓ₂ → Set _
A ⊆[ P ] B = ∀ {x} → x ∈ P → x ∈ A → x ∈ B
_⊈[_]_ : ∀ {a ℓ₀ ℓ₁ ℓ₂} {A : Set a} → Pred A ℓ₀ → Pred A ℓ₁ → Pred A ℓ₂ → Set _
A ⊈[ P ] B = ∀ {x} → x ∈ P → x ∉ A → x ∉ B
-- prefix version of _⊆[_]_, with the predicate being the first argument
[_]⊆ : ∀ {a ℓ₀ ℓ₁ ℓ₂} {A : Set a} → Pred A ℓ₁ → Pred A ℓ₀ → Pred A ℓ₂ → Set _
[ P ]⊆ A B = A ⊆[ P ] B
≋[]⇒⊆[] : ∀ {a} {P : Pred Element a} → [ P ]≋ ⇒ [ P ]⊆
≋[]⇒⊆[] A≋B = nach ∘ A≋B
⊆[]-Transitive : ∀ {a ℓ} {P : Pred Element a} → Transitive {_} {_} {Pred String ℓ} [ P ]⊆
⊆[]-Transitive A⊆B B⊆C ∈P = B⊆C ∈P ∘ A⊆B ∈P
⊆[]-IsPreorder : ∀ {a} {P : Pred Element a} → IsPreorder [ P ]≋ [ P ]⊆
⊆[]-IsPreorder = record
{ isEquivalence = ≋[]-IsEquivalence
; reflexive = ≋[]⇒⊆[]
; trans = ⊆[]-Transitive
}
⊆[]-Preorder : ∀ {a} {P : Pred Element a} → Preorder _ _ _
⊆[]-Preorder {_} {P} = record
{ Carrier = Pred String zero
; _≈_ = [ P ]≋
; _∼_ = [ P ]⊆
; isPreorder = ⊆[]-IsPreorder
}
⊆[]-Antisymmetric : ∀ {a} {P : Pred Element a} → Antisymmetric [ P ]≋ [ P ]⊆
⊆[]-Antisymmetric P⊆Q Q⊆P ∈P = equivalence (P⊆Q ∈P) (Q⊆P ∈P)
⊆[]-IsPartialOrder : ∀ {a} {P : Pred Element a} → IsPartialOrder [ P ]≋ [ P ]⊆
⊆[]-IsPartialOrder = record
{ isPreorder = ⊆[]-IsPreorder
; antisym = ⊆[]-Antisymmetric
}
⊆[]-Poset : ∀ {a} {P : Pred Element a} → Poset _ _ _
⊆[]-Poset {_} {P} = record
{ Carrier = Pred String zero
; _≈_ = [ P ]≋
; _≤_ = [ P ]⊆
; isPartialOrder = ⊆[]-IsPartialOrder
}
| 28.543689
| 89
| 0.531973
|
0e68a9807136c62d136197088e1604bbb5f28d89
| 701
|
agda
|
Agda
|
examples/outdated-and-incorrect/fileIO/IO.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/outdated-and-incorrect/fileIO/IO.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/fileIO/IO.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module IO where
open import Base
postulate
IO : Set -> Set
getLine : IO String
putStrLn : String -> IO Unit
mapM₋ : {A : Set} -> (A -> IO Unit) -> List A -> IO Unit
bindIO : {A B : Set} -> IO A -> (A -> IO B) -> IO B
returnIO : {A : Set} -> A -> IO A
{-# COMPILED putStrLn putStrLn #-}
{-# COMPILED mapM₋ (\_ -> mapM_ :: (a -> IO ()) -> [a] -> IO ()) #-}
-- we need to throw away the type argument to mapM_
-- and resolve the overloading explicitly (since Alonzo
-- output is sprinkled with unsafeCoerce#).
{-# COMPILED bindIO (\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-}
{-# COMPILED returnIO (\_ -> return :: a -> IO a) #-}
{-# COMPILED getLine getLine #-}
| 31.863636
| 70
| 0.544936
|
1a2a09e996b976d19aa195b12d74b2e4573290f1
| 9,829
|
agda
|
Agda
|
src/Test.agda
|
cspollard/diff
|
78c3dec24834ffeca5e74cb75578e9b210a5be62
|
[
"CC0-1.0"
] | null | null | null |
src/Test.agda
|
cspollard/diff
|
78c3dec24834ffeca5e74cb75578e9b210a5be62
|
[
"CC0-1.0"
] | null | null | null |
src/Test.agda
|
cspollard/diff
|
78c3dec24834ffeca5e74cb75578e9b210a5be62
|
[
"CC0-1.0"
] | null | null | null |
module Test where
open import Algebra using (CommutativeRing; IsCommutativeRing)
open import Assume using (assume)
import Data.Nat as ℕ
open ℕ using (ℕ; zero; suc)
import Data.Fin as F
open F using (Fin)
open import Relation.Binary using (Rel; Setoid; _Preserves_⟶_)
open import Function using (Inverse; _on_; _∘_; _|>_; id; flip)
open import Algebra.Module using (Module)
module Mod = Module
open import Data.Product using (_,_; proj₂; _×_)
open import Algebra.Module.Construct.DirectProduct using () renaming (⟨module⟩ to ×-module)
open import Level using (_⊔_; Level; 0ℓ; Lift)
open import Data.Vec.Recursive
open import Algebra.Module.Vec.Recursive
module _
{r ℓ} {CR : CommutativeRing r ℓ}
where
-- D B k is the solution to
-- (A → X) → A ^ suc k → B
-- i.e. D B k ~ A ^ k → B
open Module
D : ∀ {m ℓm} (M : Module CR m ℓm) → ℕ → Set _
D {m = m} M k = ∀ {X : Set m} → X ^ suc k → Carrierᴹ M
const
: ∀ {m ℓm} {{M : Module CR m ℓm}}
→ ∀ {k} → Carrierᴹ M → D M k
const {k = zero} c x = c
const {{M}} {k = suc k} c v = 0ᴹ M
double
: ∀ {m ℓm} {{M : Module CR m ℓm}}
→ ∀ {k} → D M k → D M k
double {{M}} x y = let x' = x y in _+ᴹ_ M x' x'
-- D : Level → ∀ {n ℓn} (N : Module CR n ℓn) → ℕ → Set _
-- D m N k = {M : Set m} → M → M ^ k → Carrierᴹ N
-- compose
-- : ∀ {x} {X : Set x}
-- → ∀ {n ℓn} {N : Module CR n ℓn}
-- → ∀ {o ℓo} {O : Module CR o ℓo}
-- → ∀ {k} → (f : X → D N k) → (g : Carrierᴹ N → D O k)
-- → X → D O k
-- compose = ?
-- _th-derivative_ : ∀ k → (D k → D k) → M.Carrierᴹ → N.Carrierᴹ
-- k th-derivative f = {! !}
-- TODO
-- can we use M → D N k everywhere?!
-- data D : ℕ → Set (m ⊔ n) where
-- z : N.Carrierᴹ → D zero
-- d : ∀ {k} → (fx : N.Carrierᴹ) → (dfx : M.Carrierᴹ → D k) → D (suc k)
-- module _
-- {r ℓ} {CR : CommutativeRing r ℓ}
-- {m ℓm} {M : Module CR m ℓm}
-- {n ℓn} {N : Module CR n ℓn}
-- where
-- private
-- module CR = CommutativeRing CR
-- module M = Module M
-- module N = Module N
-- private
-- module dmod where
-- Carrierᴹ : ∀ {k : ℕ} → Set (m ⊔ n)
-- Carrierᴹ {k} = D M N k
-- _≈ᴹ_ : ∀ {k} → Rel (D M N k) (m ⊔ ℓn)
-- _≈ᴹ_ (z x) (z y) = Lift (m ⊔ ℓn) (x N.≈ᴹ y)
-- _≈ᴹ_ (d fx dfx) (d fy dfy) = (fx N.≈ᴹ fy) × (∀ v → dfx v ≈ᴹ dfy v)
-- _+ᴹ_ : ∀ {k} → (x y : D M N k) → D M N k
-- _+ᴹ_ (z x) (z y) = z (x N.+ᴹ y)
-- _+ᴹ_ (d fx dfx) (d fy dfy) = d (fx N.+ᴹ fy) λ v → dfx v +ᴹ dfy v
-- _*ₗ_ : ∀ {k} → (s : CR.Carrier) (x : D M N k) → D M N k
-- _*ₗ_ s (z x) = z (s N.*ₗ x)
-- _*ₗ_ s (d fx dfx) = d (s N.*ₗ fx) λ v → s *ₗ dfx v
-- _*ᵣ_ : ∀ {k} → (x : D M N k) (s : CR.Carrier) → D M N k
-- _*ᵣ_ = flip _*ₗ_
-- 0ᴹ : ∀ {k} → D M N k
-- 0ᴹ {zero} = z N.0ᴹ
-- 0ᴹ {suc k} = d N.0ᴹ λ v → 0ᴹ
-- -ᴹ_ : ∀ {k} → D M N k → D M N k
-- -ᴹ_ (z x) = z (N.-ᴹ x)
-- -ᴹ_ (d fx dfx) = d (N.-ᴹ fx) λ v → -ᴹ dfx v
-- instance
-- D-module : ∀ {k : ℕ} → Module CR _ _
-- D-module {k} =
-- record
-- { Carrierᴹ = dmod.Carrierᴹ {k}
-- ; isModule = assume
-- ; dmod
-- }
-- private variable k : ℕ
-- run : D M N k → N.Carrierᴹ
-- run (z x) = x
-- run (d x _) = x
-- extract : D M N zero → N.Carrierᴹ
-- extract = run
-- diff : M.Carrierᴹ → D M N (suc k) → D M N k
-- diff v (d _ x) = x v
-- konst _# : ∀ (c : N.Carrierᴹ) → D M N k
-- konst {k = zero} c = z c
-- konst {k = suc k} c = d c (λ v → konst N.0ᴹ)
-- x # = konst x
-- jacobian : (df : D M N 1) (v : M.Carrierᴹ) → N.Carrierᴹ
-- jacobian df v = df |> diff v |> extract
-- hessian : (df : D M N 2) (v v' : M.Carrierᴹ) → N.Carrierᴹ
-- hessian df v v' = df |> diff v |> diff v' |> extract
-- hack : ∀ {l} → D M N (suc l) → D M N l
-- hack {zero} (d fx dfx) = z fx
-- hack {suc l} (d fx dfx) = d fx λ v → hack {l} (dfx v)
module _ where
import Real as ℝ
open ℝ using (ℝ)
open import Data.Vec.Recursive
ℝ-isCommutativeRing : IsCommutativeRing ℝ._≈_ ℝ._+_ ℝ._*_ ℝ.-_ 0.0 1.0
ℝ-isCommutativeRing = assume
instance
ℝ-commutativeRing : CommutativeRing 0ℓ 0ℓ
ℝ-commutativeRing = record { isCommutativeRing = ℝ-isCommutativeRing }
ℝ-cr : CommutativeRing 0ℓ 0ℓ
ℝ-cr = ℝ-commutativeRing
private
ℝ-mod' : Module ℝ-commutativeRing 0ℓ 0ℓ
ℝ-mod' = U.⟨module⟩
where import Algebra.Module.Construct.TensorUnit as U
ℝ^ : ∀ n → Module ℝ-commutativeRing 0ℓ 0ℓ
ℝ^ n = ℝ-mod' ^ᴹ n
ℝ-mod : Module ℝ-commutativeRing 0ℓ 0ℓ
ℝ-mod = ℝ^ 1
exp : ∀ {k} → D ℝ-mod k → D ℝ-mod k
exp {0} f x = ℝ.e^ f x
exp {1} f' xdx = let (fx , f'x) = f xdx in {! (ℝ.e^ fx) ℝ.* f'x !}
exp {k} f y = {! !}
-- -- TODO
-- -- is this really the identity?
-- var : ∀ {rank k} (c : Mod.Carrierᴹ (ℝ^ rank)) → D (ℝ^ rank) (ℝ^ rank) k
-- var {rank} {zero} c = z c
-- var {rank} {suc n} c = d c (λ v → konst (replicate rank 1.0))
-- instance
-- ℝ^n : ∀ {n} → Module ℝ-cr 0ℓ 0ℓ
-- ℝ^n {n} = ℝ^ n
-- infixl 6 _+_ _-_
-- infixl 7 _*_
-- -- linear and bilinear forms
-- _*_
-- : ∀ {m ℓm} {M : Module ℝ-cr m ℓm} {k rank}
-- → (x y : D M (ℝ^ rank) k)
-- → D M (ℝ^ rank) k
-- open Module {{...}}
-- _+_ _-_
-- : ∀ {r ℓ} {CR : CommutativeRing r ℓ} {m ℓm} {{M : Module CR m ℓm}} (x y : Mod.Carrierᴹ M)
-- → Mod.Carrierᴹ M
-- x + y = x +ᴹ y
-- x - y = x +ᴹ (-ᴹ y)
-- _*_ {rank = rank} (z x) (z y) = z (zipWith ℝ._*_ rank x y)
-- _*_ {rank = rank} dfx@(d fx f'x) dgx@(d gx g'x) =
-- d (zipWith ℝ._*_ rank fx gx) (λ v → hack dfx * g'x v + hack dgx * f'x v)
-- -- convenience function
-- _>-<_
-- : ∀ {k}
-- → (f : ℝ → ℝ) (f' : ∀ {l} → D ℝ-mod ℝ-mod l → D ℝ-mod ℝ-mod l)
-- → D ℝ-mod ℝ-mod k → D ℝ-mod ℝ-mod k
-- (f >-< _) (z x) = z (f x)
-- (f >-< f') dfx@(d x dx) = d (f x) λ v → dx v * f' (hack dfx)
-- ε : ∀ {rank} → Fin rank → ℝ ^ rank
-- ε {zero} n = _
-- ε {suc zero} _ = 1.0
-- ε {2+ rank} F.zero = 1.0 , Mod.0ᴹ (ℝ^ (suc rank))
-- ε {2+ rank} (F.suc n) = Mod.0ᴹ ℝ-mod , ε n
-- ∇_ grad : ∀ {rank} → D (ℝ^ rank) (ℝ^ 1) 1 → ℝ ^ rank
-- ∇_ {rank = rank} f = map (jacobian f) rank unitvecs
-- where
-- unitvecs : (ℝ ^ rank) ^ rank
-- unitvecs = map ε rank (tabulate rank id)
-- grad = ∇_
-- infixl 8 _**_
-- infixr 9 -_
-- infixr 9 e^_
-- -_
-- : ∀ {r ℓ} {CR : CommutativeRing r ℓ} {m ℓm} {{M : Module CR m ℓm}} (x : Mod.Carrierᴹ M)
-- → Mod.Carrierᴹ M
-- -_ x = -ᴹ x
-- ℝ-sgn : ℝ → ℝ
-- ℝ-sgn x = if does (0.0 ℝ.≤? x) then 1.0 else ℝ.- 1.0
-- where
-- open import Data.Bool using (if_then_else_)
-- open import Relation.Nullary using (does)
-- ℝ-abs : ℝ → ℝ
-- ℝ-abs x = x ℝ.* ℝ-sgn x
-- -- the first is the zero-order
-- poly : ∀ {rank k} → ℝ ^ suc rank → D ℝ-mod ℝ-mod k → D ℝ-mod ℝ-mod k
-- poly {rank = zero} cs x = konst cs
-- poly {rank = suc rank} (c , cs) x = konst c + x * poly cs x
-- pow : ℕ → ∀ {k} → D ℝ-mod ℝ-mod k → D ℝ-mod ℝ-mod k
-- pow 0 x = konst 1.0
-- pow 1 x = x
-- pow (suc n) dx = dx * pow n dx
-- log e^_ recip abs sgn : ∀ {k} → D ℝ-mod ℝ-mod k → D ℝ-mod ℝ-mod k
-- log = ℝ.log >-< recip ∘ abs
-- recip (z x) = z (1.0 ℝ.÷ x)
-- recip dfx@(d fx f'x) = d (1.0 ℝ.÷ fx) λ x → - (f'x x * tmp * tmp)
-- where
-- tmp = recip (hack dfx)
-- abs = ℝ-abs >-< sgn
-- sgn = ℝ-sgn >-< λ _ → 0ᴹ
-- e^ z x = z (ℝ.e^ x)
-- e^ dfx@(d fx f'x) = d (run tmp) λ v → f'x v * tmp
-- where
-- tmp = e^ hack dfx
-- infixl 7 _÷_
-- _÷_ _**_ : ∀ {k} (x y : D ℝ-mod ℝ-mod k) → D ℝ-mod ℝ-mod k
-- x ÷ y = x * recip x
-- x ** y = e^ y * log x
-- _! : ℕ → ℕ
-- 0 ! = 1
-- 1 ! = 1
-- sucn@(suc n) ! = sucn ℕ.* (n !)
-- sterling : ∀ {k} → ℕ → D ℝ-mod ℝ-mod k
-- sterling {k} m = m' * log m' - m'
-- where
-- m' : D ℝ-mod ℝ-mod k
-- m' = ℝ.fromℕ m #
-- -- without the constant denominator term
-- logPoisson' : ∀ {n} → ℕ → D ℝ-mod ℝ-mod n → D ℝ-mod ℝ-mod n
-- logPoisson' k λ' = k' * log λ' - λ'
-- where k' = ℝ.fromℕ k #
-- logPoisson : ∀ {n} → ℕ → D ℝ-mod ℝ-mod n → D ℝ-mod ℝ-mod n
-- logPoisson k λ' = logPoisson' k λ' - sterling k
-- -- descend : ∀ {rank} (f : D (ℝ^ rank) 1 → D ℝ-mod 1) (steps : ℕ) (start : ℝ ^ rank) → ℝ ^ rank
-- -- descend f zero start = start
-- -- descend f (suc steps) start = {! !}
-- module _ where
-- open import Relation.Binary.PropositionalEquality using (refl)
-- _ : (∇ (var 1.0 * var 1.0)) ℝ.≈ 2.0
-- _ = refl
-- -- -- -- _ : run e^_ 2.0 ℝ.≈ (ℝ.e^ 2.0)
-- -- -- -- _ = refl
-- -- -- -- testpoly : ∀ {n} → D ℝ-mod n → D ℝ-mod n
-- -- -- -- testpoly = poly (1.0 , 2.0 , 3.0)
-- -- -- -- _ : run testpoly 2.0 ℝ.≈ (1.0 + 4.0 + 12.0)
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ testpoly [ 2.0 ] ℝ.≈ (0.0 + 2.0 + 3.0 ℝ.* 2.0 ℝ.* 2.0)
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ testpoly [ 7.0 ] ℝ.≈ (0.0 + 2.0 + 2.0 ℝ.* 3.0 ℝ.* 7.0)
-- -- -- -- _ = refl
-- -- -- -- _ : hessian e^_ 1.0 1.0 0.0 ℝ.≈ (ℝ.e^ 1.0)
-- -- -- -- _ = refl
-- -- -- -- asdf : D ℝ-mod 2
-- -- -- -- asdf = e^ var (2.0 , 1.0 , 0.0)
-- -- -- -- _ : hessian (poly (1.0 , 2.0 , 3.0)) 1.0 1.0 0.0 ℝ.≈ (2.0 ℝ.* 3.0)
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ log [ 1.0 ] ℝ.≈ 1.0
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ log [ -ᴹ 1.0 ] ℝ.≈ 1.0
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ sgn [ 2.0 ] ℝ.≈ 0.0
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ abs [ 2.0 ] ℝ.≈ 1.0
-- -- -- -- _ = refl
-- -- -- -- _ : run abs (- 2.0) ℝ.≈ 2.0
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ abs [ - 1.0 ] ℝ.≈ (- 1.0)
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ recip [ - 2.0 ] ℝ.≈ (- 0.25)
-- -- -- -- _ = refl
-- -- -- -- _ : ∇ log [ 2.0 ] ℝ.≈ 0.5
-- -- -- -- _ = refl
| 26.071618
| 100
| 0.457015
|
22890c07fa7e61fc0b43a7b360bb456506df736c
| 14,223
|
agda
|
Agda
|
LC/stash/STLC2.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | 2
|
2020-08-25T07:34:40.000Z
|
2020-08-25T14:05:01.000Z
|
LC/stash/STLC2.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
LC/stash/STLC2.agda
|
banacorn/bidirectional
|
0c9a6e79c23192b28ddb07315b200a94ee900ca6
|
[
"MIT"
] | null | null | null |
module STLC2 where
open import Data.Nat
-- open import Data.List
open import Data.Empty using (⊥-elim)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; cong₂; subst)
open import Relation.Nullary
open import Data.Product
-- de Bruijn indexed lambda calculus
infix 5 ƛ_
infixl 7 _∙_
infix 9 var_
data Term : Set where
var_ : ℕ → Term
ƛ_ : Term → Term
_∙_ : Term → Term → Term
-- only "shift" the variable when
-- 1. it's free
-- 2. it will be captured after substitution
-- free <= x && x < subst-depth
shift : ℕ → ℕ → Term → Term
shift free subst-depth (var x) with free >? x
shift free subst-depth (var x) | yes p = var x -- bound
shift free subst-depth (var x) | no ¬p with subst-depth >? x -- free
shift free subst-depth (var x) | no ¬p | yes q = var (suc x) -- will be captured, should increment
shift free subst-depth (var x) | no ¬p | no ¬q = var x
shift free subst-depth (ƛ M) = ƛ (shift (suc free) (suc subst-depth) M)
shift free subst-depth (M ∙ N) = shift free subst-depth M ∙ shift free subst-depth N
infixl 10 _[_/_]
_[_/_] : Term → Term → ℕ → Term
(var x) [ N / n ] with x ≟ n
(var x) [ N / n ] | yes p = N
(var x) [ N / n ] | no ¬p = var x
(ƛ M) [ N / n ] = ƛ ((M [ shift 0 (suc n) N / suc n ]))
(L ∙ M) [ N / n ] = L [ N / n ] ∙ M [ N / n ]
-- substitution
infixl 10 _[_]
_[_] : Term → Term → Term
M [ N ] = M [ N / zero ]
-- β reduction
infix 3 _β→_
data _β→_ : Term → Term → Set where
β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ])
β-ƛ : ∀ {M N} → M β→ N → ƛ M β→ ƛ N
β-∙-l : ∀ {L M N} → M β→ N → M ∙ L β→ N ∙ L
β-∙-r : ∀ {L M N} → M β→ N → L ∙ M β→ L ∙ N
-- the reflexive and transitive closure of _β→_
infix 2 _β→*_
infixr 2 _→*_
data _β→*_ : Term → Term → Set where
∎ : ∀ {M} → M β→* M
_→*_
: ∀ {L M N}
→ L β→ M
→ M β→* N
--------------
→ L β→* N
infixl 3 _<β>_
_<β>_ : ∀ {M N O} → M β→* N → N β→* O → M β→* O
_<β>_ {M} {.M} {O} ∎ N→O = N→O
_<β>_ {M} {N} {O} (L→M →* M→N) N→O = L→M →* M→N <β> N→O
-- infix 2 _-↠_
infixr 2 _→⟨_⟩_
_→⟨_⟩_
: ∀ {M N}
→ ∀ L
→ L β→ M
→ M β→* N
--------------
→ L β→* N
L →⟨ P ⟩ Q = P →* Q
infixr 2 _→*⟨_⟩_
_→*⟨_⟩_
: ∀ {M N}
→ ∀ L
→ L β→* M
→ M β→* N
--------------
→ L β→* N
L →*⟨ P ⟩ Q = P <β> Q
infix 3 _→∎
_→∎ : ∀ M → M β→* M
M →∎ = ∎
jump : ∀ {M N} → M β→ N → M β→* N
jump {M} {N} M→N = M→N →* ∎
-- the symmetric closure of _β→*_
infix 1 _β≡_
data _β≡_ : Term → Term → Set where
β-sym : ∀ {M N}
→ M β→* N
→ N β→* M
-------
→ M β≡ N
infixr 2 _=*⟨_⟩_
_=*⟨_⟩_
: ∀ {M N}
→ ∀ L
→ L β≡ M
→ M β≡ N
--------------
→ L β≡ N
L =*⟨ β-sym A B ⟩ β-sym C D = β-sym (A <β> C) (D <β> B)
infixr 2 _=*⟨⟩_
_=*⟨⟩_
: ∀ {N}
→ ∀ L
→ L β≡ N
--------------
→ L β≡ N
L =*⟨⟩ β-sym C D = β-sym C D
infix 3 _=∎
_=∎ : ∀ M → M β≡ M
M =∎ = β-sym ∎ ∎
forward : ∀ {M N} → M β≡ N → M β→* N
forward (β-sym A _) = A
backward : ∀ {M N} → M β≡ N → N β→* M
backward (β-sym _ B) = B
-- data Normal : Set where
Normal : Term → Set
Normal M = ¬ ∃ (λ N → M β→ N)
normal : ∀ {M N} → Normal M → M β→* N → M ≡ N
normal P ∎ = refl
normal P (M→L →* L→N) = ⊥-elim (P (_ , M→L))
normal-ƛ : ∀ {M} → Normal (ƛ M) → Normal M
normal-ƛ P (N , M→N) = P ((ƛ N) , (β-ƛ M→N))
normal-ƛ' : ∀ {M} → Normal M → Normal (ƛ M)
normal-ƛ' P (.(ƛ N) , β-ƛ {N = N} ƛM→N) = P (N , ƛM→N)
normal-∙-r : ∀ {M N} → Normal (M ∙ N) → Normal N
normal-∙-r {M} P (O , N→O) = P (M ∙ O , (β-∙-r N→O))
normal-∙-l : ∀ {M N} → Normal (M ∙ N) → Normal M
normal-∙-l {_} {N} P (O , M→O) = P (O ∙ N , (β-∙-l M→O))
cong-ƛ : ∀ {M N} → M β→* N → ƛ M β→* ƛ N
cong-ƛ ∎ = ∎
cong-ƛ (M→N →* N→O) = β-ƛ M→N →* cong-ƛ N→O
cong-∙-l : ∀ {L M N} → M β→* N → M ∙ L β→* N ∙ L
cong-∙-l ∎ = ∎
cong-∙-l (M→N →* N→O) = β-∙-l M→N →* cong-∙-l N→O
cong-∙-r : ∀ {L M N} → M β→* N → L ∙ M β→* L ∙ N
cong-∙-r ∎ = ∎
cong-∙-r (M→N →* N→O) = β-∙-r M→N →* cong-∙-r N→O
∙-dist-r : ∀ M N O → (ƛ (M ∙ N)) ∙ O β→* ((ƛ M) ∙ O) ∙ ((ƛ N) ∙ O)
∙-dist-r (var x) N O = {! !}
∙-dist-r (ƛ M) N O = {! !}
∙-dist-r (M ∙ L) N O = {! !}
∙-dist-r2 : ∀ M N O → (ƛ (M ∙ N)) ∙ O β≡ ((ƛ M) ∙ O) ∙ ((ƛ N) ∙ O)
∙-dist-r2 (var x) N O = {! !}
∙-dist-r2 (ƛ M) N O = {! !}
∙-dist-r2 (M ∙ L) (var x) O =
(ƛ (M ∙ L ∙ var x)) ∙ O
=*⟨ β-sym (β-ƛ-∙ →* ∎) {! !} ⟩
((M ∙ L ∙ var x) [ O ])
=*⟨ {! !} ⟩
{! !}
=*⟨ {! !} ⟩
(ƛ M ∙ L) ∙ O ∙ ((ƛ var x) ∙ O)
=∎
∙-dist-r2 (M ∙ L) (ƛ N) O = {! !}
∙-dist-r2 (M ∙ L) (N ∙ K) O = {! !}
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →∎
-- (ƛ M) [ N / n ] = ƛ ((M [ shift 0 (suc n) N / suc n ]))
cong-[]2 : ∀ {M N L n} → M β→ N → (M [ L / n ]) β→* (N [ L / n ])
cong-[]2 (β-ƛ-∙ {var x} {N}) = {! !}
cong-[]2 {_} {_} {L} {n} (β-ƛ-∙ {ƛ M} {N}) =
(ƛ (ƛ (M [ shift 0 (suc (suc n)) (shift 0 (suc n) L) / suc (suc n) ]))) ∙ (N [ L / n ])
→*⟨ jump β-ƛ-∙ ⟩
ƛ ((M [ shift 0 (suc (suc n)) (shift 0 (suc n) L) / suc (suc n) ]) [ shift 0 1 (N [ L / n ]) / 1 ])
→*⟨ cong-ƛ {! !} ⟩
ƛ {! !}
→*⟨ {! !} ⟩
{! !}
→*⟨ {! !} ⟩
ƛ ((M [ shift 0 1 N / 1 ]) [ shift 0 (suc n) L / suc n ])
→∎
cong-[]2 {_} {_} {L} {n} (β-ƛ-∙ {M ∙ K} {N}) =
(ƛ (M [ shift 0 (suc n) L / suc n ]) ∙ (K [ shift 0 (suc n) L / suc n ])) ∙ (N [ L / n ])
→*⟨ {! !} ⟩
-- →*⟨ forward (∙-dist-r2 (M [ shift zero (suc n) L / suc n ]) (K [ shift zero (suc n) L / suc n ]) (N [ L / n ])) ⟩
(ƛ (M [ shift zero (suc n) L / suc n ])) ∙ (N [ L / n ]) ∙ ((ƛ (K [ shift 0 (suc n) L / suc n ])) ∙ (N [ L / n ]))
→*⟨ cong-∙-l (cong-[]2 (β-ƛ-∙ {M} {N})) ⟩
((M [ N ]) [ L / n ]) ∙ ((ƛ (K [ shift 0 (suc n) L / suc n ])) ∙ (N [ L / n ]))
→*⟨ cong-∙-r (cong-[]2 (β-ƛ-∙ {K} {N})) ⟩
((M [ N ]) [ L / n ]) ∙ ((K [ N ]) [ L / n ])
→∎
cong-[]2 (β-ƛ M→N) = cong-ƛ (cong-[]2 M→N)
cong-[]2 (β-∙-l M→N) = cong-∙-l (cong-[]2 M→N)
cong-[]2 (β-∙-r M→N) = cong-∙-r (cong-[]2 M→N)
cong-∙-l' : ∀ {L M N} → M β→* N → M ∙ L ≡ N ∙ L
cong-∙-l' ∎ = refl
cong-∙-l' {L} {M} {O} (_→*_ {M = N} M→N N→O) = trans M∙L≡N∙L N∙L≡O∙L
where
M∙L≡N∙L : M ∙ L ≡ N ∙ L
M∙L≡N∙L = {! !}
N∙L≡O∙L : N ∙ L ≡ O ∙ L
N∙L≡O∙L = cong-∙-l' N→O
-- rans (cong-∙-l' (M→N →* ∎)) (cong-∙-l' N→O)
cong-[] : ∀ {M N L n} → M β→ N → (M [ L / n ]) ≡ (N [ L / n ])
cong-[] β-ƛ-∙ = {! !}
cong-[] (β-ƛ M→N) = {! !}
cong-[] (β-∙-l M→N) = cong-∙-l' {! cong-[] M→N !}
cong-[] (β-∙-r M→N) = {! !}
normal-unique' : ∀ {M N O} → Normal N → Normal O → M β→ N → M β→ O → N ≡ O
normal-unique' P Q β-ƛ-∙ β-ƛ-∙ = refl
normal-unique' P Q (β-ƛ-∙ {M} {L}) (β-∙-l {N = .(ƛ N)} (β-ƛ {N = N} M→N)) = {! !}
-- trans (normal P (cong-[]2 M→N)) N[L]≡ƛN∙L
-- trans (normal P (cong-[]2 M→N)) N[L]≡ƛN∙L
where
N[L]≡ƛN∙L : (N [ L ]) ≡ (ƛ N) ∙ L
N[L]≡ƛN∙L = sym (normal Q (jump β-ƛ-∙))
-- β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ])
normal-unique' P Q (β-ƛ-∙ {M} {L}) (β-∙-r {N = N} L→N) = {! sym (normal Q (jump β-ƛ-∙)) !}
-- sym (trans (normal Q (jump β-ƛ-∙)) (cong (λ x → M [ x ]) (sym (normal {! !} (jump N→O)))))
-- sym (trans (normal Q (jump β-ƛ-∙)) (cong (λ x → {! M [ x ] !}) {! !}))
-- sym (trans {! !} (normal {! P !} (jump β-ƛ-∙)))
normal-unique' P Q (β-ƛ M→N) (β-ƛ M→O) = cong ƛ_ (normal-unique' (normal-ƛ P) (normal-ƛ Q) M→N M→O)
normal-unique' P Q (β-∙-l M→N) β-ƛ-∙ = {!normal (normal-∙-l P) !}
normal-unique' P Q (β-∙-l {L} {N = N} M→N) (β-∙-l {N = O} M→O) =
cong (λ x → x ∙ L) (normal-unique' (normal-∙-l P) (normal-∙-l Q) M→N M→O)
normal-unique' P Q (β-∙-l M→N) (β-∙-r M→O) =
cong₂ _∙_ (sym (normal (normal-∙-l Q) (jump M→N))) (normal (normal-∙-r P) (jump M→O))
normal-unique' {O = O} P Q (β-∙-r {L} {N = N} M→N) M→O =
{! !}
normal-unique : ∀ {M N O} → Normal N → Normal O → M β→* N → M β→* O → N ≡ O
normal-unique P Q ∎ M→O = normal P M→O
normal-unique P Q M→N ∎ = sym (normal Q M→N)
normal-unique P Q (_→*_ {M = L} M→L L→N) (_→*_ {M = K} M→K K→O) = {! !}
-- rewrite (normal-unique' {! !} {! !} M→L M→K) = normal-unique P Q L→N {! K→O !}
-- where
-- postulate L≡K : L ≡ K
-- normal-unique' P Q {! !} {! !}
-- ... | U = {! !}
-- trans {! !} (normal-unique {! !} {! !} L→N {! !})
-- L≡K = {! !}
-- normal-unique P Q {! !} M→O
-- normal-unique P Q M→N ∎ = sym (normal Q M→N)
-- normal-unique P Q M→N (M→L →* L→O) = {! !}
-- β→*-confluent : ∀ {M N O} → (M β→* N) → (M β→* O) → ∃ (λ P → (N β→* P) × (O β→* P))
-- β→*-confluent {M} {.M} {O} ∎ M→O = O , M→O , ∎
-- β→*-confluent {M} {N} {.M} (M→L →* L→N) ∎ = N , ∎ , (M→L →* L→N)
-- β→*-confluent {M} {N} {O} (M→L →* L→N) (M→K →* K→O) = {! !}
-- lemma-0 : ∀ M N → M [ N ] β→* (ƛ M) ∙ N
-- lemma-0 (var zero) (var zero) = (var zero) →⟨ {! !} ⟩ {! !}
-- lemma-0 (var zero) (var suc y) = {! !}
-- lemma-0 (var suc x) (var y) = {! !}
-- lemma-0 (var x) (ƛ O) = {! !}
-- lemma-0 (var x) (O ∙ P) = {! !}
-- lemma-0 (ƛ M) O = {! !}
-- lemma-0 (M ∙ N) O = {! !}
-- lemma : ∀ M N O → ((ƛ M) ∙ N β→* O) → M [ N ] β→* O
-- lemma (var x) N .((ƛ var x) ∙ N) (.((ƛ var x) ∙ N) ∎) = {! !}
-- lemma (ƛ M) N .((ƛ (ƛ M)) ∙ N) (.((ƛ (ƛ M)) ∙ N) ∎) = {! !}
-- lemma (M ∙ M₁) N .((ƛ M ∙ M₁) ∙ N) (.((ƛ M ∙ M₁) ∙ N) ∎) = {! !}
-- lemma M N O (.((ƛ M) ∙ N) →⟨⟩ redex→O) = lemma M N O redex→O
-- lemma M N O (_→⟨_⟩_ .((ƛ M) ∙ N) {P} ƛM∙N→P P→O) = {! !}
-- -- lemma M N P (jump ƛM∙N→P) <β> P→O
-- lemma-1 : ∀ M N O P → (ƛ M β→* N) → (N ∙ O β→* P) → M [ O ] β→* P
-- lemma-1 M .(ƛ M) O P (.(ƛ M) ∎) N∙O→P = lemma M O P N∙O→P
-- lemma-1 M N O P (.(ƛ M) →⟨⟩ ƛM→N) N∙O→P = lemma-1 M N O P ƛM→N N∙O→P
-- lemma-1 M N O .(N ∙ O) (.(ƛ M) →⟨ x ⟩ ƛM→N) (.(N ∙ O) ∎) = {! !}
-- lemma-1 M N O P (.(ƛ M) →⟨ x ⟩ ƛM→N) (.(N ∙ O) →⟨⟩ N∙O→P) = {! !}
-- lemma-1 M N O P (.(ƛ M) →⟨ x ⟩ ƛM→N) (.(N ∙ O) →⟨ x₁ ⟩ N∙O→P) = {! !}
-- -- (M [ N ]) β→* O
-- -- M'→O : P ∙ N β→* O
-- -- L→M' : ƛ M β→ P
-- -- (M [ N ]) β→* O
-- -- M'→O : N₂ ∙ N β→* O
-- -- L→M' : ƛ M β→ N₂
-- -- M→N : (M [ N ]) β→* N₁
-- -- that diamond prop
-- --
-- -- M
-- -- N O
-- -- P
-- --
-- β→*-confluent : ∀ {M N O} → (M β→* N) → (M β→* O) → ∃ (λ P → (N β→* P) × (O β→* P))
-- β→*-confluent {O = O} (M ∎) M→O = O , M→O , (O ∎)
-- β→*-confluent (L →⟨⟩ M→N) M→O = β→*-confluent M→N M→O
-- β→*-confluent {N = N} (L →⟨ x ⟩ M→N) (.L ∎) = N , (N ∎) , (L →⟨ x ⟩ M→N)
-- β→*-confluent (L →⟨ x ⟩ M→N) (.L →⟨⟩ M→O) = β→*-confluent (L →⟨ x ⟩ M→N) M→O
-- β→*-confluent (.((ƛ _) ∙ _) →⟨ β-ƛ-∙ ⟩ M→N) (.((ƛ _) ∙ _) →⟨ β-ƛ-∙ ⟩ M'→O) = β→*-confluent M→N M'→O
-- β→*-confluent {N = N} {O} (.((ƛ M) ∙ N₁) →⟨ β-ƛ-∙ {M} {N₁} ⟩ M→N) (.((ƛ M) ∙ N₁) →⟨ β-∙-l {N = N₂} L→M' ⟩ M'→O) = β→*-confluent M→N (lemma-1 M N₂ N₁ O ((ƛ M) →⟨ L→M' ⟩ (N₂ ∎)) M'→O)
-- β→*-confluent (.((ƛ _) ∙ _) →⟨ β-ƛ-∙ ⟩ M→N) (.((ƛ _) ∙ _) →⟨ β-∙-r L→M' ⟩ M'→O) = {! !}
-- β→*-confluent (.(ƛ _) →⟨ β-ƛ L→M ⟩ M→N) (.(ƛ _) →⟨ L→M' ⟩ M'→O) = {! !}
-- β→*-confluent (.(_ ∙ _) →⟨ β-∙-l L→M ⟩ M→N) (.(_ ∙ _) →⟨ L→M' ⟩ M'→O) = {! !}
-- β→*-confluent (.(_ ∙ _) →⟨ β-∙-r L→M ⟩ M→N) (.(_ ∙ _) →⟨ L→M' ⟩ M'→O) = {! !}
-- L
-- M M'
-- N O
-- P
--
-- module Example where
-- S : Term
-- S = ƛ ƛ ƛ var 2 ∙ var 0 ∙ (var 1 ∙ var 0)
-- K : Term
-- K = ƛ ƛ var 1
-- I : Term
-- I = ƛ (var 0)
-- Z : Term
-- Z = ƛ ƛ var 0
-- SZ : Term
-- SZ = ƛ ƛ var 1 ∙ var 0
-- PLUS : Term
-- PLUS = ƛ ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)
-- test-0 : ƛ (ƛ ƛ var 1) ∙ var 0 β→* ƛ ƛ var 1
-- test-0 =
-- ƛ (ƛ ƛ var 1) ∙ var 0
-- →⟨ β-ƛ β-ƛ-∙ ⟩
-- ƛ (ƛ var 1) [ var 0 / 0 ]
-- →⟨⟩
-- ƛ ƛ ((var 1) [ shift 0 1 (var 0) / 1 ])
-- →⟨⟩
-- ƛ ƛ ((var 1) [ var 1 / 1 ])
-- →⟨⟩
-- ƛ (ƛ var 1)
-- ∎
-- test-2 : PLUS ∙ Z ∙ SZ β→* SZ
-- test-2 =
-- PLUS ∙ Z ∙ SZ
-- →⟨⟩
-- (ƛ (ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero))))) ∙ Z ∙ SZ
-- →⟨ β-∙-l β-ƛ-∙ ⟩
-- ((ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)))) [ Z ]) ∙ SZ
-- →⟨⟩
-- ((ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)))) [ Z / 0 ]) ∙ SZ
-- →⟨⟩
-- (ƛ ((ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero))) [ shift 0 1 Z / 1 ])) ∙ SZ
-- →⟨⟩
-- (ƛ ((ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero))) [ Z / 1 ])) ∙ SZ
-- →⟨⟩
-- (ƛ (ƛ ((ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ Z / 2 ]))) ∙ SZ
-- →⟨⟩
-- (ƛ (ƛ (ƛ ((var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ Z / 3 ])))) ∙ SZ
-- →⟨⟩
-- (ƛ ƛ ƛ Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) ∙ SZ
-- →⟨ β-ƛ-∙ ⟩
-- ((ƛ ƛ Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ SZ / 0 ])
-- →⟨⟩
-- ƛ ((ƛ Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ SZ / 1 ])
-- →⟨⟩
-- ƛ ƛ ((Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ SZ / 2 ])
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ (SZ ∙ var 1 ∙ var 0)
-- →⟨ β-ƛ (β-ƛ (β-∙-r (β-∙-l β-ƛ-∙))) ⟩
-- ƛ ƛ Z ∙ var 1 ∙ (((ƛ var 1 ∙ var 0) [ var 1 ]) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ (((ƛ var 1 ∙ var 0) [ var 1 / 0 ]) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((ƛ ((var 1 ∙ var 0) [ shift 0 1 (var 1) / 1 ])) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((ƛ ((var 1 ∙ var 0) [ var 1 / 1 ])) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((ƛ var 1 ∙ var 0) ∙ var 0)
-- →⟨ β-ƛ (β-ƛ (β-∙-r β-ƛ-∙)) ⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((var 1 ∙ var 0) [ var 0 / 0 ])
-- →⟨⟩
-- ƛ ƛ (ƛ ƛ var 0) ∙ var 1 ∙ (var 1 ∙ var 0)
-- →⟨ β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)) ⟩
-- ƛ ƛ ((ƛ var 0) [ var 1 / 0 ]) ∙ (var 1 ∙ var 0)
-- →⟨⟩
-- ƛ ƛ (ƛ ((var 0) [ var 1 / 1 ])) ∙ (var 1 ∙ var 0)
-- →⟨⟩
-- ƛ ƛ (ƛ var 0) ∙ (var 1 ∙ var 0)
-- →⟨ β-ƛ (β-ƛ β-ƛ-∙) ⟩
-- ƛ ƛ ((var 0) [ var 1 ∙ var 0 / 0 ])
-- →⟨⟩
-- SZ
-- ∎
| 30.852495
| 184
| 0.366378
|
1ade97167ba6feca9f5fa9d8ccc7bb5c6df8c255
| 690
|
agda
|
Agda
|
test/Succeed/AntiUnifyBug.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/AntiUnifyBug.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/AntiUnifyBug.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Jesper, 2019-07-27. Cut down this example from a latent bug in
-- @antiUnify@, which was using @unAbs@ instead of @absBody@.
{-# OPTIONS --double-check #-}
open import Agda.Primitive
postulate
I : Set
T : ∀ {p} → Set (lsuc p) → Set (lsuc p)
t : ∀ {p} → (B : Set (lsuc p)) → (I → I → Set) → B → T B
x0 : I
R0 : I → I → Set
P0 : ∀ p → R0 x0 x0 → Set p
d0 : R0 x0 x0
C : ∀ {p} (X : Set) (x : (T (X → Set p))) → Set
f : ∀ {p} (R : I → I → Set) (P : R x0 x0 → Set p)
→ {{_ : C (R x0 x0) (t (R x0 x0 → Set p) R P)}}
→ (d : R x0 x0) → P d
instance
iDP : ∀ {p} → C (R0 x0 x0) (t (R0 x0 x0 → Set p) R0 (P0 p))
fails : ∀ p → P0 p d0
fails p = f _ (P0 p) d0
| 23.793103
| 65
| 0.482609
|
5924a6094352f5b6551dc7129a26903f20b2d6ab
| 51,702
|
agda
|
Agda
|
src/elab-util.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 328
|
2018-09-14T20:06:09.000Z
|
2022-03-26T10:33:07.000Z
|
src/elab-util.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 123
|
2018-09-17T10:53:20.000Z
|
2022-01-12T03:51:28.000Z
|
src/elab-util.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 34
|
2018-09-17T11:51:36.000Z
|
2022-02-20T18:33:16.000Z
|
import cedille-options
module elab-util (options : cedille-options.options) where
open import general-util
open import cedille-types
open import syntax-util
open import type-util
open import ctxt
open import conversion (cedille-options.options.disable-conv options)
using (hnf ; unfold-all ; unfold-head ; unfold-head-elab ; conv-type)
open import constants
open import instances
open import subst
open import rename
open import rewriting
open import free-vars
open import toplevel-state options {IO}
open import datatype-util
open import bohm-out
rename-validify : string → string
rename-validify = 𝕃char-to-string ∘ (h ∘ string-to-𝕃char) where
validify-char : char → 𝕃 char
validify-char '/' = [ '-' ]
validify-char '.' = [ '-' ]
validify-char c with
(c =char 'a') ||
(c =char 'z') ||
(c =char 'A') ||
(c =char 'Z') ||
(c =char '\'') ||
(c =char '-') ||
(c =char '_') ||
is-digit c ||
(c =char qual-local-chr) ||
(('a' <char c) && (c <char 'z')) ||
(('A' <char c) && (c <char 'Z'))
...| tt = [ c ]
...| ff = 'Z' :: string-to-𝕃char (ℕ-to-string (toNat c)) ++ [ 'Z' ]
h : 𝕃 char → 𝕃 char
h [] = []
h (c :: cs) = validify-char c ++ h cs
-- Returns a fresh variable name by adding primes and replacing invalid characters
fresh-var' : string → (string → 𝔹) → string
fresh-var' x f = fresh-h f (rename-validify x)
rename-new_from_for_ : ∀ {X : Set} → var → ctxt → (var → X) → X
rename-new ignored-var from Γ for f = f $ fresh-var' "x" (ctxt-binds-var Γ)
rename-new x from Γ for f = f $ fresh-var' x (ctxt-binds-var Γ)
rename_from_for_ : ∀ {X : Set} → var → ctxt → (var → X) → X
rename ignored-var from Γ for f = f ignored-var
rename x from Γ for f = f $ fresh-var' x (ctxt-binds-var Γ)
get-renaming : renamectxt → var → var → var × renamectxt
get-renaming ρₓ xₒ x = let x' = fresh-var' x (renamectxt-in-field ρₓ) in x' , renamectxt-insert ρₓ xₒ x'
rename_-_from_for_ : ∀ {X : Set} → var → var → renamectxt → (var → renamectxt → X) → X
rename xₒ - ignored-var from ρₓ for f = f ignored-var ρₓ
rename xₒ - x from ρₓ for f = uncurry f $ get-renaming ρₓ xₒ x
rename_-_lookup_for_ : ∀ {X : Set} → var → var → renamectxt → (var → renamectxt → X) → X
rename xₒ - x lookup ρₓ for f with renamectxt-lookup ρₓ xₒ
...| nothing = rename xₒ - x from ρₓ for f
...| just x' = f x' ρₓ
rename_from_and_for_ : ∀ {X : Set} → var → ctxt → renamectxt → (var → ctxt → renamectxt → X) → X
rename ignored-var from Γ and ρ for f = f ignored-var Γ ρ
rename x from Γ and ρ for f =
let x' = fresh-var' x (λ x → ctxt-binds-var Γ x || renamectxt-in-field ρ x) in
f x' (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x')
module reindexing (Γ : ctxt) (D I mn : var) (isₒ : indices) (psₜ : params) where
rnm : Set
rnm = qualif × stringset
rnm-insert : rnm → var → var → rnm
rnm-insert (q , s) xₒ xₙ = trie-insert q xₒ (xₙ , []) , stringset-insert s xₙ
rnm-add : rnm → var → var → args → rnm
rnm-add (q , s) xₒ xₙ as = trie-insert q xₒ (xₙ , as) , stringset-insert s xₙ
rnm-binds : rnm → var → 𝔹
rnm-binds (q , s) x = trie-contains q x || trie-contains s x
reindex-fresh-var : rnm → trie indices → var → var
reindex-fresh-var ρₓ is ignored-var = ignored-var
reindex-fresh-var ρₓ is x =
fresh-h (λ x' → ctxt-binds-var Γ x' || trie-contains is x' || rnm-binds ρₓ x') x
rename-indices' : rnm → trie indices → indices
rename-indices' ρₓ is = foldr {B = renamectxt → rnm → indices}
(λ {(Index x atk) f r ρₓ →
let x' = reindex-fresh-var ρₓ is x in
Index x' (substh Γ r empty-trie -tk atk) :: f (renamectxt-insert r x x') (rnm-insert ρₓ x x')})
(λ r ρₓ → []) isₒ empty-renamectxt ρₓ
reindex-t : Set → Set
reindex-t X = rnm → trie indices → X → X
{-# TERMINATING #-}
reindex : ∀ {ed} → reindex-t ⟦ ed ⟧
rc-is : rnm → indices → rnm
rc-is = foldr λ {(Index x atk) ρₓ → rnm-insert ρₓ x x}
is-index-var : maybe tpkd → 𝔹
is-index-var (just (Tkt (TpVar x))) = x =string I
is-index-var _ = ff
reindex {TERM} ρₓ is (AppEr t (Var x)) with trie-lookup is x
...| nothing = AppEr (reindex ρₓ is t) $ reindex ρₓ is $ Var x
...| just is' = indices-to-apps is' $ reindex ρₓ is t
reindex {TERM} ρₓ is (App t t') =
App (reindex ρₓ is t) (reindex ρₓ is t')
reindex {TERM} ρₓ is (AppE t tT) =
AppE (reindex ρₓ is t) (reindex ρₓ is -tT tT)
reindex {TERM} ρₓ is (Beta t t') =
Beta (reindex ρₓ is t) (reindex ρₓ is t')
reindex {TERM} ρₓ is (Delta b? T t) =
Delta (b? >>=c λ t₁ t₂ → just (reindex ρₓ is t₁ , reindex ρₓ is t₂))
(reindex ρₓ is T) (reindex ρₓ is t)
reindex {TERM} ρₓ is (Hole pi) =
Hole pi
reindex {TERM} ρₓ is (IotaPair t₁ t₂ x Tₓ) =
let x' = reindex-fresh-var ρₓ is x in
IotaPair (reindex ρₓ is t₁) (reindex ρₓ is t₂) x'
(reindex (rnm-insert ρₓ x x') is Tₓ)
reindex {TERM} ρₓ is (IotaProj t n) =
IotaProj (reindex ρₓ is t) n
reindex {TERM} ρₓ is (Lam me x tk? t) with is-index-var tk?
...| ff = let x' = reindex-fresh-var ρₓ is x in
Lam me x' (reindex ρₓ is -tk_ <$> tk?) (reindex (rnm-insert ρₓ x x') is t)
...| tt with rename-indices' ρₓ is
...| isₙ = indices-to-lams isₙ $ reindex (rc-is ρₓ isₙ) (trie-insert is x isₙ) t
reindex {TERM} ρₓ is (LetTm me x T? t t') =
let x' = reindex-fresh-var ρₓ is x in
LetTm me x' (reindex ρₓ is <$> T?) (reindex ρₓ is t) (reindex (rnm-insert ρₓ x x') is t')
reindex {TERM} ρₓ is (LetTp x k T t) =
let x' = reindex-fresh-var ρₓ is x in
LetTp x' (reindex ρₓ is k) (reindex ρₓ is T) (reindex (rnm-insert ρₓ x x') is t)
reindex {TERM} ρₓ is (Phi t₌ t₁ t₂) =
Phi (reindex ρₓ is t₌) (reindex ρₓ is t₁) (reindex ρₓ is t₂)
reindex {TERM} ρₓ is (Rho t₌ x Tₓ t) =
let x' = reindex-fresh-var ρₓ is x in
Rho (reindex ρₓ is t) x' (reindex (rnm-insert ρₓ x x') is Tₓ) (reindex ρₓ is t)
reindex {TERM} ρₓ is (VarSigma t) =
VarSigma (reindex ρₓ is t)
reindex {TERM} ρₓ is (Var x) =
maybe-else' (trie-lookup (fst ρₓ) x) (Var x) (uncurry (apps-term ∘ Var))
reindex {TERM} ρₓ is (Mu μ t Tₘ? f~ cs) = Var "template-mu-not-allowed"
reindex {TERM} ρₓ is (Sigma μ t Tₘ? f~ cs) = Var "template-sigma-not-allowed"
reindex {TYPE} ρₓ is (TpAbs me x atk T) with is-index-var (just atk)
...| ff = let x' = reindex-fresh-var ρₓ is x in
TpAbs me x' (reindex ρₓ is -tk atk) (reindex (rnm-insert ρₓ x x') is T)
...| tt = let isₙ = rename-indices' ρₓ is in
indices-to-alls isₙ $ reindex (rc-is ρₓ isₙ) (trie-insert is x isₙ) T
reindex {TYPE} ρₓ is (TpEq t₁ t₂) =
TpEq (reindex ρₓ is t₁) (reindex ρₓ is t₂)
reindex {TYPE} ρₓ is (TpIota x T T') =
let x' = reindex-fresh-var ρₓ is x in
TpIota x' (reindex ρₓ is T) (reindex (rnm-insert ρₓ x x') is T')
reindex {TYPE} ρₓ is (TpAppTm T (Var x)) with trie-lookup is x
...| nothing = TpAppTm (reindex ρₓ is T) $ reindex ρₓ is $ Var x
...| just is' = indices-to-tpapps is' $ reindex ρₓ is T
reindex {TYPE} ρₓ is (TpApp T tT) =
TpApp (reindex ρₓ is T) (reindex ρₓ is -tT tT)
reindex {TYPE} ρₓ is (TpHole pi) =
TpHole pi
reindex {TYPE} ρₓ is (TpLam x atk T) with is-index-var (just atk)
...| ff = let x' = reindex-fresh-var ρₓ is x in
TpLam x' (reindex ρₓ is -tk atk) (reindex (rnm-insert ρₓ x x') is T)
...| tt = let isₙ = rename-indices' ρₓ is in
indices-to-tplams isₙ $ reindex (rc-is ρₓ isₙ) (trie-insert is x isₙ) T
reindex {TYPE} ρₓ is (TpVar x) =
maybe-else' (trie-lookup (fst ρₓ) x) (TpVar x) (uncurry (apps-type ∘ TpVar))
reindex {KIND} ρₓ is (KdAbs x atk k) with is-index-var (just atk)
...| ff = let x' = reindex-fresh-var ρₓ is x in
KdAbs x' (reindex ρₓ is -tk atk) (reindex (rnm-insert ρₓ x x') is k)
...| tt = let isₙ = rename-indices' ρₓ is in
indices-to-kind isₙ $ reindex (rc-is ρₓ isₙ) (trie-insert is x isₙ) k
reindex {KIND} ρₓ is (KdHole pi) =
KdHole pi
reindex {KIND} ρₓ is KdStar =
KdStar
reindex-cmd : rnm → trie indices → cmd → cmd × rnm
reindex-cmd ρₓ is (CmdImport (Import p? fp mnᵢ q? as)) =
CmdImport (Import p? fp mnᵢ q? (reindex ρₓ is -arg_ <$> as)) , ρₓ
reindex-cmd ρₓ is (CmdDefTerm x t) =
let x' = D ^ "/" ^ x in
CmdDefTerm x' (lam-expand-term psₜ $ reindex ρₓ is t) ,
rnm-add ρₓ (mn # x) (ctxt.mn Γ # x') (params-to-args psₜ)
reindex-cmd ρₓ is (CmdDefType x k T) =
let x' = D ^ "/" ^ x in
CmdDefType x' (abs-expand-kind psₜ $ reindex ρₓ is k)
(lam-expand-type psₜ $ reindex ρₓ is T) ,
rnm-add ρₓ (mn # x) (ctxt.mn Γ # x') (params-to-args psₜ)
reindex-cmd ρₓ is (CmdDefKind x ps k) =
CmdDefKind x ps k , ρₓ
reindex-cmd ρₓ is (CmdDefData es x ps k cs) =
CmdDefData es x ps k cs , ρₓ
reindex-cmds : cmds → cmds
reindex-cmds cs =
foldr {B = rnm → cmds}
(λ c rec ρₓ → elim reindex-cmd ρₓ empty-trie c for λ c ρₓ → c :: rec ρₓ)
(λ ρₓ → []) cs (empty-trie , empty-stringset)
{- we have to erase params to work around a situation like
data MyData (x : {β ≃ β}) : ★ =
| MyCtr : MyData.
erased-problem : ∀ x : {β ≃ β}. MyData x ➔ MyData β{λ x. x} =
Λ x. λ d. μ' d { MyCtr ➔ MyCtr β{λ x. x} }.
^----------------------------------------^
... because the indicated term would elaborate to something like
Λ x. λ d. FixInd x ·MyData d ...
^-^ ^
and "x" is bound by an erased lambda, but is an unerased arg to FixInd!
(similar situations arise with fix-in/fix-out and with module parameters)
-}
reindex-file : ctxt → (D I modname : var) → indices → params → cmds → cmds
reindex-file Γ D I mn is ps cs =
let ps' = params-set-erased Erased (ctxt.ps Γ ++ ps)
open reindexing (add-params-to-ctxt ps' Γ) D I mn is ps' in
reindex-cmds cs
mendler-elab-mu : ctxt → datatype-info → var → term → type → cases → term
mendler-elab-mu-pure : ctxt → datatype-info → var → term → cases → term
mendler-elab-sigma : ctxt → datatype-info → maybe term → term → type → cases → term
mendler-elab-sigma-pure : ctxt → datatype-info → maybe term → term → cases → term
-- Maps over expression, elaborating all mu-terms
{-# TERMINATING #-}
choose-mu : ∀ {ed} → ctxt → renamectxt → ⟦ ed ⟧ → ⟦ ed ⟧
choose-mu {TERM} Γ ρ (App tm tm') =
App (choose-mu Γ ρ tm) (choose-mu Γ ρ tm')
choose-mu {TERM} Γ ρ (AppE tm tT) =
AppE (choose-mu Γ ρ tm) (choose-mu Γ ρ -tT tT)
choose-mu {TERM} Γ ρ (Beta tm tm') =
Beta (choose-mu Γ ρ tm) (choose-mu Γ ρ tm')
choose-mu {TERM} Γ ρ (Delta b? tp tm) =
maybe-else' (b? >>=c λ t₁ t₂ →
make-contradiction
(hnf Γ unfold-all (choose-mu Γ ρ t₁))
(hnf Γ unfold-all (choose-mu Γ ρ t₂)))
(Delta nothing (choose-mu Γ ρ tp) (choose-mu Γ ρ tm)) λ f →
rename "x" from Γ and ρ for λ x' _ _ →
Delta (just (tt-term , ff-term)) (choose-mu Γ ρ tp)
(Rho (choose-mu Γ ρ tm) x' (TpEq (App f (Var x')) ff-term) (Beta ff-term id-term))
choose-mu {TERM} Γ ρ (Hole pi) =
Hole pi
choose-mu {TERM} Γ ρ (IotaPair tm₁ tm₂ x Tₓ) =
rename x from Γ and ρ for λ x' Γ' ρ' →
IotaPair (choose-mu Γ ρ tm₁) (choose-mu Γ ρ tm₂) x' (choose-mu Γ' ρ' Tₓ)
choose-mu {TERM} Γ ρ (IotaProj tm n) =
IotaProj (choose-mu Γ ρ tm) n
choose-mu {TERM} Γ ρ (Lam e x tk? tm) =
rename x from Γ and ρ for λ x' Γ' ρ' →
Lam e x' (choose-mu Γ ρ -tk_ <$> tk?) (choose-mu Γ' ρ' tm)
choose-mu {TERM} Γ ρ (LetTm e x tp? tm tm') =
rename x from Γ and ρ for λ x' Γ' ρ' →
LetTm e x' (choose-mu Γ ρ <$> tp?) (choose-mu Γ ρ tm) (choose-mu Γ' ρ' tm')
choose-mu {TERM} Γ ρ (LetTp x k T t) =
rename x from Γ and ρ for λ x' Γ' ρ' →
LetTp x' (choose-mu Γ ρ k) (choose-mu Γ ρ T) (choose-mu Γ' ρ' t)
choose-mu {TERM} Γ ρ (Phi tm₌ tm₁ tm₂) =
Phi (choose-mu Γ ρ tm₌) (choose-mu Γ ρ tm₁) (choose-mu Γ ρ tm₂)
choose-mu {TERM} Γ ρ (Rho tm₌ x Tₓ tm) =
rename x from Γ and ρ for λ x' Γ' ρ' →
Rho (choose-mu Γ ρ tm₌) x' (choose-mu Γ' ρ' Tₓ) (choose-mu Γ ρ tm)
choose-mu {TERM} Γ ρ (VarSigma tm) =
VarSigma (choose-mu Γ ρ tm)
choose-mu {TERM} Γ ρ (Mu x t tp? t~ ms) =
choose-mu Γ ρ
(maybe-else' tp?
(mendler-elab-mu-pure Γ t~ x t ms)
(λ tp → mendler-elab-mu Γ t~ x t tp ms))
choose-mu {TERM} Γ ρ (Sigma mt t tp? t~ ms) =
choose-mu Γ ρ
(maybe-else' tp?
(mendler-elab-sigma-pure Γ t~ mt t ms)
(λ tp → mendler-elab-sigma Γ t~ mt t tp ms))
choose-mu {TERM} Γ ρ (Var x) =
Var (renamectxt-rep ρ x)
choose-mu {TYPE} Γ ρ (TpAbs e x tk tp) =
rename x from Γ and ρ for λ x' Γ' ρ' →
TpAbs e x' (choose-mu Γ ρ -tk tk) (choose-mu Γ' ρ' tp)
choose-mu {TYPE} Γ ρ (TpIota x tp₁ tp₂) =
rename x from Γ and ρ for λ x' Γ' ρ' →
TpIota x' (choose-mu Γ ρ tp₁) (choose-mu Γ' ρ' tp₂)
choose-mu {TYPE} Γ ρ (TpApp tp tT) =
TpApp (choose-mu Γ ρ tp) (choose-mu Γ ρ -tT tT)
choose-mu {TYPE} Γ ρ (TpEq tmₗ tmᵣ) =
TpEq (choose-mu Γ ρ tmₗ) (choose-mu Γ ρ tmᵣ)
choose-mu {TYPE} Γ ρ (TpHole pi) =
TpHole pi
choose-mu {TYPE} Γ ρ (TpLam x tk tp) =
rename x from Γ and ρ for λ x' Γ' ρ' →
TpLam x' (choose-mu Γ ρ -tk tk) (choose-mu Γ' ρ' tp)
choose-mu {TYPE} Γ ρ (TpVar x) =
TpVar (renamectxt-rep ρ x)
choose-mu {KIND} Γ ρ (KdAbs x tk kd) =
rename x from Γ and ρ for λ x' Γ' ρ' →
KdAbs x' (choose-mu Γ ρ -tk tk) (choose-mu Γ' ρ' kd)
choose-mu {KIND} Γ ρ (KdHole pi) =
KdHole pi
choose-mu {KIND} Γ ρ KdStar =
KdStar
-- Adds all Dₓ's encoding defs to the ctxt
ctxt-open-encoding-defs : var → ctxt → maybe ctxt
ctxt-open-encoding-defs Dₓ Γ =
trie-lookup (ctxt.μ~ Γ) Dₓ >>=r λ xs →
let tmd = λ t → term-def nothing opacity-open (just t) (TpHole pi-gen)
tpd = λ T → type-def nothing opacity-open (just T) (KdHole pi-gen) in
record Γ {
i = foldr (uncurry λ x tT i →
trie-insert i x
(either-else' tT
(tmd ∘ hnf (record Γ {i = i}) unfold-head)
(tpd ∘ hnf (record Γ {i = i}) unfold-head-elab) ,
missing-location)) (ctxt.i Γ) xs
}
ctxt-open-all-encoding-defs : ctxt → ctxt
ctxt-open-all-encoding-defs Γ =
foldr (λ Dₓ Γ → maybe-else Γ id $ ctxt-open-encoding-defs Dₓ Γ)
Γ (trie-strings (ctxt.μ~ Γ))
mk-ctr-fmap-t : Set → Set
mk-ctr-fmap-t X = ctxt → (var × type × term) → X
{-# TERMINATING #-}
mk-ctr-fmap-η+ : mk-ctr-fmap-t (term → type → term)
mk-ctr-fmap-η- : mk-ctr-fmap-t (term → type → term)
mk-ctr-fmap-η? : 𝔹 → mk-ctr-fmap-t (term → type → term)
mk-ctr-fmap-η= : 𝔹 → mk-ctr-fmap-t (term → type → term)
mk-ctr-fmapₖ-η+ : mk-ctr-fmap-t (type → kind → type)
mk-ctr-fmapₖ-η- : mk-ctr-fmap-t (type → kind → type)
mk-ctr-fmapₖ-η? : 𝔹 → mk-ctr-fmap-t (type → kind → type)
-- TODO: Join fmap+ and fmap- into one function, to handle this for both strictly positive and strictly negative parameter occurrences in other datatypes
mk-ctr-fmap-η= f Γ x @ (Aₓ , Bₓ , castₓ) body T with decompose-ctr-type Γ T
...| TpVar x'' , as , rs =
maybe-else' (data-lookup (add-params-to-ctxt as Γ) x'' rs) ((if f then mk-ctr-fmap-η+ else mk-ctr-fmap-η-) Γ x body T) λ where
d @ (mk-data-info X _ asₚ asᵢ ps kᵢ k cs csₚₛ eds gds) →
params-to-lams (if f then as else (substh-params Γ empty-renamectxt (trie-single Aₓ (, Bₓ)) as)) $
let Γ' = add-params-to-ctxt as Γ
recₓ = fresh-var Γ' "fmap"
Γ' = ctxt-var-decl recₓ Γ'
is = kind-to-indices Γ k
uₓ = fresh-var (add-indices-to-ctxt is Γ') "u"
vₓ = fresh-var (add-indices-to-ctxt is Γ') "v"
Γ'' = ctxt-var-decl vₓ $ ctxt-var-decl uₓ $ add-indices-to-ctxt is Γ' in
LetTm tt uₓ nothing
(Mu recₓ
(foldl
(λ {(Param me x'' (Tkt T)) body →
(if me then AppEr body else App body) $
mk-ctr-fmap-η? (~ f) Γ' x (Var x'') T;
(Param _ x'' (Tkk k)) body →
AppTp body $ mk-ctr-fmapₖ-η? (~ f) Γ' x (TpVar x'') k})
body as)
(just (indices-to-tplams is $
TpLam uₓ (Tkt $ indices-to-tpapps is $ recompose-tpapps (args-to-tmtps asₚ) (TpVar X)) $
TpIota vₓ (subst Γ'' Bₓ Aₓ (recompose-tpapps (args-to-tmtps asₚ) (TpVar X)))
(TpEq (Var vₓ) (Var uₓ)))) d $
flip map (map-snd (rename-var Γ'' (mu-Type/ recₓ) X) <$> inst-ctrs Γ'' ps asₚ cs) $ uncurry λ cₓ T → case decompose-ctr-type Γ T of λ where
(Tₕ , as , rs) →
Case cₓ (map (λ {(Param me x tk) → CaseArg me x (just tk)}) as)
(let Xₚₛ = recompose-tpapps (args-to-tmtps asₚ) (TpVar X)
cg = mu-Type/ recₓ , Xₚₛ ,
(indices-to-lams is $ Lam ff vₓ (just (Tkt (indices-to-tpapps is (TpVar (mu-Type/ recₓ))))) (Phi (IotaProj (App (indices-to-apps is (Var recₓ)) (Var vₓ)) ι2) (IotaProj (App (indices-to-apps is (Var recₓ)) (Var vₓ)) ι1) (Var vₓ)))
t = foldl
(λ {(Param me x'' (Tkt T)) body →
(if me then AppEr body else App body) $
mk-ctr-fmap-η? f Γ' x (mk-ctr-fmap-η? ff Γ' cg (Var x'') T) (subst Γ'' Xₚₛ (mu-Type/ recₓ) T);
(Param _ x'' (Tkk k)) body →
AppTp body $ mk-ctr-fmapₖ-η? f Γ' x (mk-ctr-fmapₖ-η? ff Γ' cg (TpVar x'') k) (subst Γ'' Xₚₛ (mu-Type/ recₓ) k)})
(subst (add-params-to-ctxt as Γ) Bₓ Aₓ (recompose-apps asₚ (Var cₓ))) as
tₑ = erase t in
IotaPair t (Beta tₑ tₑ) vₓ (TpEq (Var vₓ) tₑ))
rs)
(Phi (IotaProj (Var uₓ) ι2) (IotaProj (Var uₓ) ι1) (erase (params-to-apps as body)))
-- maybe-else' (ctxt-open-encoding-defs x'' Γ) (f Γ x body T)
-- λ Γ → f Γ x body (hnf-ctr Γ (fst x) T)
...| _ = (if f then mk-ctr-fmap-η+ else mk-ctr-fmap-η-) Γ x body T
mk-ctr-fmap-η? f Γ x body T with is-free-in (fst x) T
...| tt = mk-ctr-fmap-η= f Γ x body T
...| ff = body
mk-ctr-fmapₖ-η? f Γ x body k with is-free-in (fst x) k
...| tt = (if f then mk-ctr-fmapₖ-η+ else mk-ctr-fmapₖ-η-) Γ x body k
...| ff = body
mk-ctr-fmap-η+ Γ x @ (Aₓ , Bₓ , _) body T with decompose-ctr-type Γ T
...| Tₕ , as , _ =
params-to-lams as $
let Γ' = add-params-to-ctxt as Γ
tₓ' = case Tₕ of λ where
(TpIota x'' T₁ T₂) body →
let t₁ = mk-ctr-fmap-η+ Γ' x (IotaProj body ι1) T₁
t₂ = mk-ctr-fmap-η+ Γ' x (IotaProj body ι2) (subst Γ' t₁ x'' T₂) in
IotaPair t₁ t₂ x'' T₂
_ body → body
in
tₓ' $ foldl
(λ {(Param me x'' (Tkt T)) body →
(if me then AppEr body else App body) $
mk-ctr-fmap-η? ff Γ' x (Var x'') T;
(Param _ x'' (Tkk k)) body →
AppTp body $ mk-ctr-fmapₖ-η? ff Γ' x (TpVar x'') k})
body as
mk-ctr-fmap-η- Γ xₒ @ (Aₓ , Bₓ , castₓ) body T with decompose-ctr-type Γ T
...| TpVar x'' , as , rs =
params-to-lams (substh-params Γ empty-renamectxt (trie-single Aₓ (, Bₓ)) as) $
let Γ' = add-params-to-ctxt as Γ in
if x'' =string Aₓ
then App (recompose-apps (tmtps-to-args Erased rs) castₓ)
else id $
foldl (λ {(Param me x'' (Tkt T)) body →
(if me then AppEr body else App body) $
mk-ctr-fmap-η? tt Γ' xₒ (Var x'') T;
(Param me x'' (Tkk k)) body →
AppTp body $ mk-ctr-fmapₖ-η? tt Γ' xₒ (TpVar x'') k}) body as
...| TpIota x'' T₁ T₂ , as , [] =
let Γ' = add-params-to-ctxt as Γ
tₒ = foldl (λ where
(Param me x'' (Tkt T)) body →
(if me then AppEr body else App body) $
mk-ctr-fmap-η? tt Γ' xₒ (Var x'') T
(Param me x'' (Tkk k)) body →
AppTp body $ mk-ctr-fmapₖ-η? tt Γ' xₒ (TpVar x'') k
) body as
t₁ = mk-ctr-fmap-η? ff Γ' xₒ (IotaProj tₒ ι1) T₁
t₂ = mk-ctr-fmap-η? ff Γ' xₒ (IotaProj tₒ ι2) ([ Γ' - t₁ / x'' ] T₂) in
params-to-lams (substh-params Γ empty-renamectxt (trie-single Aₓ (, Bₓ)) as) $
IotaPair t₁ t₂ x'' (subst (ctxt-var-decl x'' Γ') Bₓ Aₓ T₂)
...| Tₕ , as , rs = body
mk-ctr-fmapₖ-η+ Γ xₒ @ (Aₓ , Bₓ , castₓ) body k =
let is = kind-to-indices Γ k in
indices-to-tplams is $
let Γ' = add-indices-to-ctxt is Γ in
foldl
(λ {(Index x'' (Tkt T)) → flip TpAppTm $ mk-ctr-fmap-η? ff Γ' xₒ (Var x'') T;
(Index x'' (Tkk k)) → flip TpAppTp $ mk-ctr-fmapₖ-η? ff Γ' xₒ (TpVar x'') k})
body is
mk-ctr-fmapₖ-η- Γ xₒ @ (Aₓ , Bₓ , castₓ) body k with kind-to-indices Γ k
...| is =
indices-to-tplams is $
let Γ' = add-indices-to-ctxt is Γ in
foldl (λ {(Index x'' (Tkt T)) → flip TpAppTm $ mk-ctr-fmap-η? tt Γ' xₒ (Var x'') T;
(Index x'' (Tkk k)) → flip TpApp $ Ttp $ mk-ctr-fmapₖ-η? tt Γ' xₒ (TpVar x'') k})
body is
mk-def : term → term
mk-def t = Phi (Beta t id-term) t (erase t)
top-type : type
top-type = TpEq id-term id-term
-- Index telescoping parameter
pattern IdxTele Iₓ = Param tt Iₓ (Tkk KdStar) :: []
pattern EncArgIdx I = ArgTp I
pattern EncArgCast Cast = ArgTp Cast
pattern EncArgCastIn cast-in = Arg cast-in
pattern EncArgCastOut cast-out = Arg cast-out
pattern EncArgCastIs cast-is = Arg cast-is
pattern EncArgFunctor Functor = ArgTp Functor
pattern EncArgFunctorIn functor-in = Arg functor-in
pattern EncArgFunctorOut functor-out = Arg functor-out
pattern EncArgFix Fix = ArgTp Fix
pattern EncArgFixIn fix-in = Arg fix-in
pattern EncArgFixOut fix-out = Arg fix-out
pattern EncArgLambek1 lambek1 = Arg lambek1
pattern EncArgLambek2 lambek2 = Arg lambek2
pattern EncArgFixInd fix-ind = Arg fix-ind
pattern EncArgs I Cast cast-in cast-out cast-is Functor functor-in functor-out
Fix fix-in fix-out lambek1 lambek2 fix-ind =
EncArgIdx I ::
EncArgCast Cast ::
EncArgCastIn cast-in ::
EncArgCastOut cast-out ::
EncArgCastIs cast-is ::
EncArgFunctor Functor ::
EncArgFunctorIn functor-in ::
EncArgFunctorOut functor-out ::
EncArgFix Fix ::
EncArgFixIn fix-in ::
EncArgFixOut fix-out ::
EncArgLambek1 lambek1 ::
EncArgLambek2 lambek2 ::
EncArgFixInd fix-ind :: []
pattern EncImp fp I Cast cast-in cast-out cast-is Functor functor-in functor-out
Fix fix-in fix-out lambek1 lambek2 fix-ind =
CmdImport (Import _ fp _ _ (EncArgs
I Cast cast-in cast-out cast-is Functor functor-in functor-out
Fix fix-in fix-out lambek1 lambek2 fix-ind))
encode-datatype : ctxt → encoding-defs → datatype → encoding-defs
encode-datatype Γ eds @ (mk-enc-defs ecs _
Cast cast-in cast-out cast-is
Functor functor-in functor-out
Fix fix-in fix-out
lambek1 lambek2 fix-ind)
(Data Dₓ' ps is cs) =
record eds {gcs = [: TypeF-cmd ⌟ IndF-cmd ⌟ fmap-cmd ⌟
D-cmd ⌟ Is-cmd ⌟ is-cmd ⌟ to-cmd ⌟
map ctr-cmd cs~ :] }
where
Γₚₛ = ctxt.ps Γ
psₜ = params-set-erased Erased (Γₚₛ ++ ps)
app-ps = params-to-apps psₜ ∘ Var
tpapp-ps = params-to-tpapps psₜ ∘ TpVar
-- Cast = tpapp-ps Castₓ
-- cast-in = app-ps cast-inₓ
-- cast-out = app-ps cast-outₓ
-- cast-is = app-ps cast-isₓ
-- Functor = tpapp-ps Functorₓ
-- functor-in = app-ps functor-inₓ
-- functor-out = app-ps functor-outₓ
-- Fix = tpapp-ps Fixₓ
-- fix-in = app-ps fix-inₓ
-- fix-out = app-ps fix-outₓ
-- lambek1 = app-ps lambek1ₓ
-- lambek2 = app-ps lambek2ₓ
-- fix-ind = app-ps fix-indₓ
mn = ctxt.mn Γ
Γ' = add-params-to-ctxt psₜ Γ
Dₓ = mn # Dₓ'
cs~ = map-snd (subst Γ' (params-to-tpapps psₜ (TpVar Dₓ)) Dₓ) <$> cs
cs' = map-snd (rename-var Γ' Dₓ Dₓ') <$> cs
topᵢ = indices-to-kind is $ KdAbs ignored-var (Tkt top-type) KdStar
mk-ctr-eterm : params → ctr → term
mk-ctr-eterm ps (Ctr x _) =
let xs = erase-params ps in
Beta id-term $ foldr
mlam
(foldl (flip App ∘ Var) (Var x) xs)
(map fst cs)
mk-ctr-etype : ctxt → ctr → var → type
mk-ctr-etype Γ (Ctr x T) X with decompose-ctr-type (ctxt-var-decl X Γ) T
...| Tₕ , as , rs =
params-to-alls as $
let rs' = if length rs =ℕ length psₜ + length is then drop (length psₜ) rs else rs in
TpAppTm (recompose-tpapps rs' $ TpVar X) $ mk-ctr-eterm as (Ctr x T)
{-
for the datatype
data Dₓ (p₁ : P₁) (p₂ : P₂)... : Π i₁ : I₁. Π i₂ : I₂. ... ★ =
| c₁ : Π/∀ a₁ : A₁. Π/∀ a₂ : A₂. ... (Dₓ r₁ r₂...)
| c₂ : ... .
produce the functor type
∀ X : Π i₁ : I₁. Π i₂ : I₂. ... Π _ : Top. ★.
(Π/∀ a₁ : A₁. Π/∀ a₂ : A₂. ... (X r₁ r₂ β<λ x. x>{λ c₁. λ c₂. ... |c₁ a₁ a₂...|})) →
... →
X i₁ i₂... ιₓ
-}
mk-ftype2 : ctxt → (asᵢ : 𝕃 tmtp) → (ιₓ : var) → ctrs → type
mk-ftype2 Γ asᵢ ιₓ cs =
let Γ = ctxt-var-decl ιₓ Γ in
rename "X" from Γ for λ X →
TpAbs tt X (Tkk topᵢ) $
foldr
(λ c → TpAbs ff ignored-var $ Tkt $ mk-ctr-etype Γ c X)
(TpAppTm (recompose-tpapps asᵢ $ TpVar X) $ Var ιₓ)
cs
mk-ctr-fterm : ctxt → ctr → ctrs → (as : params) → (rs : 𝕃 tmtp) → term
mk-ctr-fterm Γ' (Ctr x' T) cs as rs =
let Γ' = add-params-to-ctxt as Γ' in
rename "X" from Γ' for λ Xₓ →
rename "x" from Γ' for λ xₓ →
let tkₓ = just (Tkk (indices-to-kind is (KdAbs ignored-var (Tkt top-type) KdStar)))
fₜ = λ x T → Lam ff x (just (Tkt (mk-ctr-etype (ctxt-var-decl Xₓ Γ') (Ctr x T) Xₓ)))
t = Lam tt Xₓ tkₓ (foldr (uncurry fₜ) (params-to-apps as (Var x')) cs) in
IotaPair (Beta id-term (erase t)) t xₓ (mk-ftype2 (ctxt-var-decl xₓ Γ') rs xₓ cs)
mk-ctr-ftype : ctxt → ctr → ctrs → var → type
mk-ctr-ftype Γ (Ctr x T) cs X with decompose-ctr-type (ctxt-var-decl X Γ) T
...| Tₕ , as , rs =
params-to-alls as $
TpAppTm (recompose-tpapps rs $ TpVar X) $ mk-ctr-fterm (ctxt-var-decl X Γ) (Ctr x T) cs as rs
Is/D = tpapp-ps (data-Is/ Dₓ)
is/D = app-ps (data-is/ Dₓ)
to/D = app-ps (data-to/ Dₓ)
TypeF/D = tpapp-ps (data-TypeF/ Dₓ)
IndF/D = tpapp-ps (data-IndF/ Dₓ)
fmap/D = app-ps (data-fmap/ Dₓ)
D = tpapp-ps Dₓ
kᵢ = indices-to-kind is KdStar
tkᵢ = Tkk kᵢ
jtkᵢ = just tkᵢ
decl-Γ : ctxt → 𝕃 var → ctxt
decl-Γ = foldr ctxt-var-decl
{-
λ p₁ : P₁. λ p₂ : P₂. ...
λ Dₓ : Π i₁ : I₁. Π i₂ : I₂. ... ★.
λ i₁ : I₁. λ i₂ : I₂. ...
ι ιₓ : Top. mk-ftype2 (ctxt-var-decl ιₓ Γ') ιₓ cs.
-}
TypeF-cmd = CmdDefType (data-TypeF/ Dₓ')
(params-to-kind psₜ $ KdAbs ignored-var tkᵢ kᵢ) $
let Γ' = add-indices-to-ctxt is Γ' in
rename "x" from Γ' for λ ιₓ →
params-to-tplams psₜ $
TpLam Dₓ' (Tkk $ indices-to-kind is KdStar) $
indices-to-tplams is $
TpIota ιₓ top-type $ mk-ftype2 (ctxt-var-decl ιₓ Γ') (indices-to-tmtps is) ιₓ cs'
fmap-cmd = CmdDefTerm (data-fmap/ Dₓ') $
let Γ' = add-indices-to-ctxt is Γ' in
rename "A" from Γ' for λ Aₓ →
rename "B" from Γ' for λ Bₓ →
rename "c" from Γ' for λ cₓ →
rename "x" from Γ' for λ xₓ →
rename "X" from Γ' for λ Xₓ →
params-to-lams psₜ $
let cs-a = map-snd (rename-var Γ' Dₓ Aₓ) <$> cs
cs-b = map-snd (rename-var Γ' Dₓ Bₓ) <$> cs in
AppEr (AppTp functor-in TypeF/D) $
Lam tt Aₓ jtkᵢ $
Lam tt Bₓ jtkᵢ $
Lam tt cₓ (just (Tkt (TpAppTp (TpAppTp Cast (TpVar Aₓ)) (TpVar Bₓ)))) $
AppEr (AppEr (AppTp (AppTp cast-in (TpAppTp TypeF/D (TpVar Aₓ)))
(TpAppTp TypeF/D (TpVar Bₓ)))
(indices-to-lams is $
Lam ff xₓ (just (Tkt (indices-to-tpapps is (TpAppTp TypeF/D (TpVar Aₓ))))) $
IotaPair (IotaProj (Var xₓ) ι1)
(Lam tt Xₓ (just (Tkk topᵢ)) $
flip (foldr $ uncurry λ x T → Lam ff x (just (Tkt
(mk-ctr-etype (decl-Γ Γ' [: Aₓ ⌟ Bₓ ⌟ cₓ ⌟ xₓ ⌟ Xₓ :]) (x , T) Xₓ)))) cs-b $
foldl
(flip App ∘ uncurry
(λ bodyₓ T →
mk-ctr-fmap-η?
tt
(decl-Γ Γ' [: Aₓ ⌟ Bₓ ⌟ cₓ ⌟ xₓ ⌟ Xₓ :])
(Aₓ , TpVar Bₓ , AppEr (AppTp (AppTp cast-out (TpVar Aₓ)) (TpVar Bₓ)) (Var cₓ))
(Var bodyₓ)
(hnf-ctr (decl-Γ Γ' [: Aₓ ⌟ Bₓ ⌟ cₓ ⌟ xₓ ⌟ Xₓ :]) Aₓ T)))
(AppTp (IotaProj (Var xₓ) ι2) (TpVar Xₓ)) cs-a)
xₓ (mk-ftype2 (decl-Γ Γ' [: Aₓ ⌟ Bₓ ⌟ cₓ ⌟ xₓ :]) (indices-to-tmtps is) xₓ cs-b)))
(Beta id-term id-term)
IndF-cmd = CmdDefTerm (data-IndF/ Dₓ') $
params-to-lams psₜ $
Lam tt Dₓ' jtkᵢ $
indices-to-lams is $
let Γ' = add-indices-to-ctxt is Γ' in
rename "x" from Γ' for λ xₓ →
rename "y" from Γ' for λ yₓ →
rename "e" from Γ' for λ eₓ →
rename "X" from Γ' for λ Xₓ →
let T = indices-to-tpapps is (TpAppTp TypeF/D (TpVar Dₓ'))
Γ' = ctxt-var-decl xₓ (ctxt-var-decl Xₓ Γ') in
Lam ff xₓ (just $ Tkt T) $
Lam tt Xₓ (just $ Tkk $ indices-to-kind is $ KdAbs ignored-var (Tkt T) KdStar) $
flip (foldr λ c → Lam ff (fst c) (just (Tkt (mk-ctr-ftype Γ' c cs' Xₓ)))) cs' $
flip AppEr (Beta (Var xₓ) id-term) $
flip AppEr (Var xₓ) $
let Γ' = decl-Γ Γ' [: xₓ ⌟ yₓ ⌟ eₓ ⌟ Xₓ :] in
flip (foldl $ uncurry λ x' T' →
case decompose-ctr-type Γ' T' of λ where
(Tₕ , as , rs) →
flip App $
params-to-lams as $
Lam tt yₓ (just (Tkt (recompose-tpapps rs (TpAppTp TypeF/D Tₕ)))) $
Lam tt eₓ (just (Tkt (TpEq (Var yₓ) (mk-ctr-eterm as (Ctr x' T'))))) $
params-to-apps as $
Var x') cs' $
AppTp (IotaProj (Var xₓ) ι2) $
indices-to-tplams is $
TpLam xₓ (Tkt top-type) $
TpAbs tt yₓ (Tkt T) $
TpAbs tt eₓ (Tkt $ TpEq (Var yₓ) (Var xₓ)) $
TpAppTm (indices-to-tpapps is $ TpVar Xₓ) $
Phi (Var eₓ) (Var yₓ) (Var xₓ)
D-cmd = CmdDefType Dₓ' (params-to-kind (Γₚₛ ++ ps) kᵢ) $
params-to-tplams (Γₚₛ ++ ps) $
TpAppTm (TpApp Fix (Ttp TypeF/D)) fmap/D
is-projn : ctxt → type → type → term → type
is-projn Γ Tₘ Tₙ t =
rename "i" from Γ for λ iₓ →
TpIota iₓ
(indices-to-alls is
(TpAbs ff ignored-var (Tkt (indices-to-tpapps is Tₘ))
(indices-to-tpapps is Tₙ)))
(TpEq (Var iₓ) t)
is-proj1 = λ Γ T → is-projn Γ T D id-term
is-proj2 = λ Γ T → is-projn Γ T (TpAppTp TypeF/D T) fix-out
is-proj' : ctxt → var → term → term
is-proj' Γ Xₓ mu =
rename "c" from Γ for λ cₓ →
rename "o" from Γ for λ oₓ →
let t = App (AppTp mu (is-proj1 (decl-Γ Γ (cₓ :: oₓ :: [])) (TpVar Xₓ)))
(Lam ff cₓ (just (Tkt (is-proj1 (decl-Γ Γ (cₓ :: oₓ :: [])) (TpVar Xₓ))))
(Lam ff oₓ (just (Tkt (is-proj2 (decl-Γ Γ (cₓ :: oₓ :: [])) (TpVar Xₓ))))
(Var cₓ))) in
Phi (IotaProj t ι2) (IotaProj t ι1) id-term
Is-cmd = CmdDefType (data-Is/ Dₓ') (params-to-kind (Γₚₛ ++ ps) $ KdAbs ignored-var tkᵢ KdStar) $
params-to-tplams (Γₚₛ ++ ps) $
rename "X" from Γ' for λ Xₓ →
rename "Y" from Γ' for λ Yₓ →
TpLam Xₓ tkᵢ $
TpAbs tt Yₓ (Tkk KdStar) $
TpAbs ff ignored-var
(Tkt (TpAbs ff ignored-var (Tkt (is-proj1 (decl-Γ Γ' (Xₓ :: Yₓ :: [])) (TpVar Xₓ))) $
TpAbs ff ignored-var (Tkt (is-proj2 (decl-Γ Γ' (Xₓ :: Yₓ :: [])) (TpVar Xₓ))) $
TpVar Yₓ))
(TpVar Yₓ)
is-cmd = CmdDefTerm (data-is/ Dₓ') $
params-to-lams (Γₚₛ ++ ps) $
rename "Y" from Γ' for λ Yₓ →
rename "f" from Γ' for λ fₓ →
rename "x" from Γ' for λ xₓ →
let pair = λ t → IotaPair t (Beta (erase t) (erase t)) xₓ (TpEq (Var xₓ) (erase t)) in
Lam tt Yₓ (just (Tkk KdStar)) $
Lam ff fₓ (just (Tkt (TpAbs ff ignored-var (Tkt (is-proj1 (ctxt-var-decl Yₓ Γ') D)) $
TpAbs ff ignored-var (Tkt (is-proj2 (ctxt-var-decl Yₓ Γ') D)) $
TpVar Yₓ))) $
App (App (Var fₓ) (pair (indices-to-lams is (Lam ff xₓ (just (Tkt (indices-to-tpapps is D))) (Var xₓ)))))
(pair (AppEr (AppTp fix-out TypeF/D) fmap/D))
to-cmd = CmdDefTerm (data-to/ Dₓ') $
rename "Y" from Γ' for λ Yₓ →
rename "mu" from Γ' for λ muₓ →
params-to-lams (Γₚₛ ++ ps) $
Lam tt Yₓ jtkᵢ $
Lam tt muₓ (just (Tkt (TpApp Is/D (Ttp (TpVar Yₓ))))) $
is-proj' (decl-Γ Γ' (Yₓ :: muₓ :: [])) Yₓ (Var muₓ)
ctr-cmd : ctr → cmd
ctr-cmd (Ctr x' T) with subst Γ' D Dₓ' T
...| T' with decompose-ctr-type Γ' T'
...| Tₕ , as , rs = CmdDefTerm x' $
let Γ' = add-params-to-ctxt as Γ'
rs = drop (length (Γₚₛ ++ ps)) rs in
params-to-lams (Γₚₛ ++ ps) $
params-to-lams as $
App (recompose-apps (tmtps-to-args tt rs) $
AppEr (AppTp fix-in TypeF/D) fmap/D) $
mk-ctr-fterm Γ' (Ctr x' T) cs~ as rs
init-encoding : ctxt → file → datatype → string ⊎ encoding-defs
init-encoding Γ (Module mn (IdxTele Iₓ) mcs) d @ (Data Dₓ ps is cs) =
case reverse (reindex-file Γ Dₓ Iₓ mn is ps mcs) of λ where
(EncImp fp Iₓ'
Cast cast-in cast-out cast-is
Functor functor-in functor-out
Fix fix-in fix-out
lambek1 lambek2 fix-ind :: mcs) →
err⊎-guard (~ conv-type Γ Iₓ' (TpVar Iₓ))
"Index telescoping argument to last import differs from the parameter" >>
return (encode-datatype Γ (mk-enc-defs (reverse mcs) []
Cast cast-in cast-out cast-is
Functor functor-in functor-out
Fix fix-in fix-out
lambek1 lambek2 fix-ind) d)
(CmdImport (Import p? fn mn q? as) :: mcsᵣ) →
inj₁ $ "Expected 14 import args, but got" ^ rope-to-string (strRun Γ (args-to-string as))
mcsᵣ →
inj₁ "Datatype encodings must end with import ~/.cedille/Template.ced"
where open import to-string options
init-encoding Γ (Module mn mps mcs) (Data Dₓ ps is cs) =
inj₁ $ "Datatype encodings must have a single module parameter of kind star, " ^
"for index telescoping"
mendler-elab-mu-pure Γ (mk-data-info _ _ _ _ _ _ _ _ _ eds ecs) xₒ t ms =
let fix-ind = erase (encoding-defs.fix-ind eds)
msf = λ t → foldl
(λ {(Case mₓ cas mₜ asₜₚ) t →
App t (case-args-to-lams cas mₜ)})
t ms in
rename xₒ from Γ for λ x →
rename "y" from Γ for λ yₓ →
let subst-msf = subst-renamectxt Γ
(renamectxt-insert* empty-renamectxt ((xₒ , x) :: (yₓ , yₓ) :: [])) ∘ msf in
App (App fix-ind t) (Lam ff x nothing $ Lam ff yₓ nothing $ subst-msf (Var yₓ))
mendler-elab-mu Γ (mk-data-info X Xₒ asₚ asᵢ ps kᵢ k cs csₚₛ (mk-enc-defs ecs gcs Cast cast-in cast-out cast-is Functor functor-in functor-out Fix fix-in fix-out lambek1 lambek2 fix-ind) (mk-encd-defs Is/Dₓ is/Dₓ to/Dₓ TypeF/Dₓ indF/Dₓ fmap/Dₓ)) x t Tₘ ms =
let is = kind-to-indices Γ k
Γᵢₛ = add-indices-to-ctxt is $ add-params-to-ctxt ps $ add-params-to-ctxt (ctxt.ps Γ) Γ
is/X? = unless (X =string Xₒ) (Var (mu-isType/' Xₒ))
app-ps = recompose-apps (args-set-erased tt asₚ) ∘ Var
tpapp-ps = recompose-tpapps (args-to-tmtps asₚ) ∘ TpVar
app-ps' = inst-term Γ ps asₚ
tpapp-ps' = inst-type Γ ps asₚ
fmap/D = app-ps fmap/Dₓ
TypeF/D = tpapp-ps TypeF/Dₓ
indF/D = app-ps indF/Dₓ
Cast = tpapp-ps' Cast
cast-out = app-ps' cast-out
Functor = tpapp-ps' Functor
functor-in = app-ps' functor-in
functor-out = app-ps' functor-out
Fix = tpapp-ps' Fix
fix-in = app-ps' fix-in
fix-out = app-ps' fix-out
lambek1 = app-ps' lambek1
fix-ind = app-ps' fix-ind
Xₜₚ = recompose-tpapps (args-to-tmtps asₚ) (TpVar X)
Xₒₜₚ = if Xₒ =string X then Xₜₚ else TpVar Xₒ
toₓ = rename "to" from Γᵢₛ for id
outₓ = rename "out" from Γᵢₛ for id
to-tp = λ R → TpAppTp (TpAppTp Cast R) Xₜₚ
out-tp = λ R → TpIota outₓ (indices-to-alls is (TpAbs ff ignored-var (Tkt (indices-to-tpapps is R)) (indices-to-tpapps is (TpAppTp TypeF/D R)))) (TpEq (Var outₓ) fix-out)
ms' : trie term
ms' = foldr (λ c σ → case c of λ {(Case x cas t asₜₚ) →
let Γ' = add-caseArgs-to-ctxt cas Γᵢₛ in
trie-insert σ x $
rename "y" from Γ' for λ yₓ →
rename "e" from Γ' for λ eₓ →
rename "x" from Γ' for λ xₓ →
case-args-to-lams cas $
Lam tt yₓ (just (Tkt (recompose-tpapps (drop (length asₚ) asₜₚ) Xₜₚ))) $
Lam tt eₓ (just (Tkt (TpEq (App fix-in (foldr (uncurry λ x T → Lam ff (snd (split-var x)) nothing) (foldl (λ ca t → case ca of λ {(CaseArg ff x _) → App t (Var (snd (split-var x))); _ → t}) (Var (snd (split-var x))) cas) cs)) (Var yₓ)))) $
Rho (VarSigma (Var eₓ)) xₓ (TpAppTm (recompose-tpapps (drop (length asₚ) asₜₚ) Tₘ) (Var xₓ)) t})
empty-trie ms
in-fix = λ is/X? T asᵢ t →
(App (recompose-apps asᵢ (AppEr (AppTp fix-in TypeF/D) fmap/D)) (maybe-else' is/X? t λ is/X →
App (recompose-apps asᵢ (AppEr (AppTp (AppTp cast-out (TpAppTp TypeF/D T)) (TpAppTp TypeF/D Xₜₚ)) (AppEr (AppTp (AppTp fmap/D T) Xₜₚ) (App (AppTp is/X (to-tp T)) (Lam ff "to" (just (Tkt (to-tp T))) $ Lam ff "out" (just (Tkt (out-tp T))) $ Var "to"))))) t))
app-lambek = λ is/X? t T asᵢ body → AppEr (AppEr body (in-fix is/X? T asᵢ t))
(App (recompose-apps asᵢ (AppEr (AppTp lambek1 TypeF/D) fmap/D)) (in-fix is/X? T asᵢ t)) in
rename "x" from Γᵢₛ for λ xₓ →
rename "y" from Γᵢₛ for λ yₓ →
rename "y'" from ctxt-var-decl yₓ Γᵢₛ for λ y'ₓ →
rename "z" from Γᵢₛ for λ zₓ →
rename "e" from Γᵢₛ for λ eₓ →
rename "X" from Γᵢₛ for λ Xₓ →
maybe-else (Var "1") id $
foldl {B = maybe (term → term)} -- Agda hangs without this implicit argument...?
(uncurry λ x Tₓ rec → rec >>= λ rec → trie-lookup ms' x >>= λ t →
just λ tₕ → App (rec tₕ) t) (just λ t → t) cs >>= λ msf →
maybe-else (just $ Var "2") just $
just
(let Rₓ = mu-Type/ x
isRₓ = mu-isType/ x
fcₜ = AppEr (AppTp (AppTp cast-out (TpAppTp TypeF/D (TpVar Rₓ))) (TpAppTp TypeF/D Xₜₚ))
(AppEr (AppTp (AppTp fmap/D (TpVar Rₓ)) Xₜₚ) (Var toₓ))
Tₘₐ = TpLam Rₓ (Tkk (indices-to-kind is KdStar)) Tₘ
Tₘ-fmap = rename "A" from Γᵢₛ for λ Aₓ →
rename "B" from Γᵢₛ for λ Bₓ →
rename "c" from Γᵢₛ for λ cₓ →
rename "d" from Γᵢₛ for λ dₓ →
rename "q" from Γᵢₛ for λ qₓ →
let Γ' = foldr ctxt-var-decl Γ (Aₓ :: Bₓ :: cₓ :: dₓ :: qₓ :: [])
Tₘₐ' = TpAppTm (indices-to-tpapps is (TpAppTp Tₘₐ (TpVar Aₓ))) (Var dₓ)
Tₘₐₕ = hnf-ctr Γ' Aₓ Tₘₐ' in
Lam tt Aₓ (just (Tkk k)) $
Lam tt Bₓ (just (Tkk k)) $
Lam tt cₓ (just (Tkt (TpAppTp (TpAppTp Cast (TpVar Aₓ)) (TpVar Bₓ)))) $
indices-to-lams is $
Lam tt dₓ (just (Tkt (indices-to-tpapps is Xₜₚ))) $
IotaPair (Lam ff qₓ (just (Tkt Tₘₐ')) (mk-ctr-fmap-η? ff Γ' (Aₓ , TpVar Bₓ , AppEr (AppTp (AppTp cast-out (TpVar Aₓ)) (TpVar Bₓ)) (Var cₓ)) (Var qₓ) Tₘₐₕ)) (Beta id-term id-term) qₓ (TpEq (Var qₓ) id-term)
in
App (AppEr (AppTp (App (recompose-apps (tmtps-to-args tt asᵢ) (AppEr (AppTp fix-ind TypeF/D) fmap/D)) t) Tₘₐ) Tₘ-fmap)
(Lam tt Rₓ (just (Tkk k)) $
Lam tt toₓ (just (Tkt (to-tp (TpVar Rₓ)))) $
Lam tt outₓ (just (Tkt (out-tp (TpVar Rₓ)))) $
Lam ff x (just (Tkt (indices-to-alls is (TpAbs ff xₓ (Tkt (indices-to-tpapps is (TpVar Rₓ))) (TpAppTm (indices-to-tpapps is Tₘ) (App (indices-to-apps is (AppEr (AppTp (AppTp cast-out (TpVar Rₓ)) Xₜₚ) (Var toₓ))) (Var xₓ))))))) $
indices-to-lams is $
Lam ff yₓ (just (Tkt (indices-to-tpapps is (TpAppTp TypeF/D (TpVar Rₓ))))) $
LetTm tt isRₓ nothing
(Lam tt Xₓ (just (Tkk KdStar)) $
Lam ff xₓ (just (Tkt (TpAbs ff ignored-var (Tkt (to-tp (TpVar Rₓ)))
(TpAbs ff ignored-var (Tkt (out-tp (TpVar Rₓ)))
(TpVar Xₓ))))) $
App (App (Var xₓ) (Var toₓ)) (Var outₓ))
(app-lambek (just $ Var isRₓ) (Var yₓ) (TpVar Rₓ) (indices-to-args is) $ msf
(AppTp (Phi (Beta (Var yₓ) id-term) (App (indices-to-apps is (AppTp indF/D (TpVar Rₓ))) (Var yₓ)) (Var yₓ))
(indices-to-tplams is $
TpLam yₓ (Tkt $ indices-to-tpapps is (TpAppTp TypeF/D (TpVar Rₓ))) $
TpAbs tt y'ₓ (Tkt $ indices-to-tpapps is Xₜₚ) $
TpAbs tt eₓ (Tkt $ TpEq (App fix-in (Var yₓ)) (Var y'ₓ)) $
TpAppTm (indices-to-tpapps is Tₘ) (Phi (Var eₓ)
(App (indices-to-apps is (AppEr (AppTp fix-in TypeF/D) fmap/D))
(App (indices-to-apps is fcₜ) (Var yₓ)))
(Var y'ₓ)))))))
mendler-elab-sigma-pure Γ (mk-data-info _ _ _ _ _ _ _ _ _ eds ecs) x? t ms =
let fix-out = erase (encoding-defs.fix-out eds)
msf = λ t → foldl
(λ {(Case mₓ cas mₜ asₜₚ) t →
App t (case-args-to-lams cas mₜ)})
t ms in
msf (App fix-out t)
mendler-elab-sigma Γ (mk-data-info X Xₒ asₚ asᵢ ps kᵢ k cs csₚₛ (mk-enc-defs ecs gcs Cast cast-in cast-out cast-is Functor functor-in functor-out Fix fix-in fix-out lambek1 lambek2 fix-ind) (mk-encd-defs Is/Dₓ is/Dₓ to/Dₓ TypeF/Dₓ indF/Dₓ fmap/Dₓ)) mt t Tₘ ms =
let is = kind-to-indices Γ k
Γᵢₛ = add-indices-to-ctxt is $ add-params-to-ctxt ps $ add-params-to-ctxt (ctxt.ps Γ) Γ
is/X? = mt
app-ps = recompose-apps (args-set-erased tt asₚ) ∘ Var
tpapp-ps = recompose-tpapps (args-to-tmtps asₚ) ∘ TpVar
app-ps' = inst-term Γ ps asₚ
tpapp-ps' = inst-type Γ ps asₚ
fmap/D = app-ps fmap/Dₓ
TypeF/D = tpapp-ps TypeF/Dₓ
to/D = recompose-apps asₚ (Var to/Dₓ)
indF/D = app-ps indF/Dₓ
Cast = tpapp-ps' Cast
cast-out = app-ps' cast-out
functor-out = app-ps' functor-out
Fix = tpapp-ps' Fix
fix-in = app-ps' fix-in
fix-out = app-ps' fix-out
lambek1 = app-ps' lambek1
Xₜₚ = recompose-tpapps (args-to-tmtps asₚ) (TpVar X)
Xₒₜₚ = if Xₒ =string X then Xₜₚ else TpVar Xₒ
toₓ = rename "to" from Γᵢₛ for id
outₓ = rename "out" from Γᵢₛ for id
to-tp = λ R → TpAppTp (TpAppTp Cast R) Xₜₚ
out-tp = λ R → TpIota outₓ (indices-to-alls is (TpAbs ff ignored-var (Tkt (indices-to-tpapps is R)) (indices-to-tpapps is (TpAppTp TypeF/D R)))) (TpEq (Var outₓ) fix-out)
ms' : trie term
ms' = foldr (λ c σ → case c of λ {(Case x cas t asₜₚ) →
let Γ' = add-caseArgs-to-ctxt cas Γᵢₛ in
trie-insert σ x $
rename "y" from Γ' for λ yₓ →
rename "e" from Γ' for λ eₓ →
rename "x" from Γ' for λ xₓ →
case-args-to-lams cas $
Lam tt yₓ (just (Tkt (recompose-tpapps (drop (length asₚ) asₜₚ) Xₜₚ))) $
Lam tt eₓ (just (Tkt (TpEq (App fix-in (foldr (uncurry λ x T → Lam ff (snd (split-var x)) nothing) (foldl (λ ca t → case ca of λ {(CaseArg ff x _) → App t (Var (snd (split-var x))); _ → t}) (Var (snd (split-var x))) cas) cs)) (Var yₓ)))) $
Rho (VarSigma (Var eₓ)) xₓ (TpAppTm (recompose-tpapps (drop (length asₚ) asₜₚ) Tₘ) (Var xₓ)) t})
empty-trie ms
in-fix = λ is/X? T asᵢ t →
(maybe-else' (is/X? ||-maybe mt) t λ is/X → App (recompose-apps asᵢ (AppEr (AppTp (AppTp cast-out T) Xₜₚ) (App (AppTp is/X (to-tp T)) (Lam ff "to" (just (Tkt (to-tp T))) $ Lam ff "out" (just (Tkt (out-tp T))) $ Var "to")))) t)
app-lambek = λ is/X? t T asᵢ body → AppEr (AppEr body (in-fix is/X? T asᵢ t))
(App (recompose-apps asᵢ (AppEr (AppTp lambek1 TypeF/D) fmap/D)) (in-fix is/X? T asᵢ t)) in
rename "x" from Γᵢₛ for λ xₓ →
rename "y" from Γᵢₛ for λ yₓ →
rename "y'" from ctxt-var-decl yₓ Γᵢₛ for λ y'ₓ →
rename "z" from Γᵢₛ for λ zₓ →
rename "e" from Γᵢₛ for λ eₓ →
rename "X" from Γᵢₛ for λ Xₓ →
maybe-else (Var "1") id $
foldl {B = maybe (term → term)} -- Agda hangs without this implicit argument...?
(uncurry λ x Tₓ rec → rec >>= λ rec → trie-lookup ms' x >>= λ t →
just λ tₕ → App (rec tₕ) t) (just λ t → t) cs >>= λ msf →
maybe-else (just $ Var "2") just $
just $
(app-lambek is/X? t Xₒₜₚ
(tmtps-to-args tt asᵢ) (msf
(let Tₛ = maybe-else' is/X? Xₜₚ λ _ → Xₒₜₚ
fcₜ = maybe-else' is/X? id λ is/X → App $ indices-to-apps is $
AppEr (AppTp (AppTp cast-out (TpAppTp TypeF/D Tₛ)) (TpAppTp TypeF/D Xₜₚ))
(AppEr (AppTp (AppTp (AppEr (AppTp functor-out TypeF/D) fmap/D) Tₛ) Xₜₚ) (App (AppTp is/X (to-tp Tₛ)) (Lam ff "to" (just (Tkt (to-tp Tₛ))) $ Lam ff "out" (just (Tkt (out-tp Tₛ))) $ Var "to")))
out = maybe-else' is/X? (AppEr (AppTp fix-out TypeF/D) fmap/D) λ is/X →
let i = App (AppTp is/X (TpIota xₓ (indices-to-alls is (TpAbs ff ignored-var (Tkt (indices-to-tpapps is Tₛ)) (indices-to-tpapps is (TpAppTp TypeF/D Tₛ)))) (TpEq (Var xₓ) fix-out))) (Lam ff "to" (just (Tkt (to-tp Tₛ))) $ Lam ff "out" (just (Tkt (out-tp Tₛ))) $ Var "out") in
Phi (IotaProj i ι2) (IotaProj i ι1) fix-out in
AppTp (App (recompose-apps (tmtps-to-args tt asᵢ) (AppTp indF/D Tₛ)) (App (recompose-apps (tmtps-to-args tt asᵢ) out) t))
(indices-to-tplams is $ TpLam yₓ (Tkt $ indices-to-tpapps is (TpAppTp TypeF/D Tₛ)) $
TpAbs tt y'ₓ (Tkt $ indices-to-tpapps is Xₜₚ) $
TpAbs tt eₓ (Tkt (TpEq (App fix-in (Var yₓ)) (Var y'ₓ))) $
TpAppTm (indices-to-tpapps is Tₘ) (Phi (Var eₓ)
(App (indices-to-apps is (AppEr (AppTp fix-in TypeF/D) fmap/D)) (fcₜ (Var yₓ))) (Var y'ₓ))))))
{- ################################ IO ################################ -}
-- set show-qualified-vars to tt to show if there are bugs in parameter code, because
-- they should always be captured by the scope and unqualified as a binder name
open import to-string (record options {during-elaboration = tt; show-qualified-vars = tt; erase-types = ff; pretty-print = tt})
{-# TERMINATING #-}
cmds-to-string : (newline-before-after : 𝔹) → params → cmds → strM
cmd-to-string : params → cmd → strM
cmd-to-string ps (CmdDefTerm x t) = strBreak 2
0 [ strVar x >>str strAdd " =" ]
2 [ to-stringh (lam-expand-term ps t) >>str strAdd "." ]
cmd-to-string ps (CmdDefType x k T) = strBreak 3
0 [ strVar x >>str strAdd " :" ]
(3 + string-length x) [ to-stringh (abs-expand-kind ps k) >>str strAdd " =" ]
2 [ to-stringh (lam-expand-type ps T) >>str strAdd "." ]
cmd-to-string ps (CmdDefKind x psₖ k) = strBreak 2
0 [ strVar x ]
2 [ params-to-string'' (ps ++ psₖ) (to-stringh k) >>str strAdd "." ]
cmd-to-string ps (CmdDefData eds x psₓ k cs) =
cmds-to-string ff ps (encoding-defs.ecs eds) >>str
strList 2
(strBreak 2
0 [ strAdd "data " >>str strVar x ]
(5 + string-length x) [ params-to-string'' (ps ++ psₓ)
(strAdd ": " >>str to-stringh k) ] ::
map (uncurry λ x T → strBreak 2
0 [ strAdd "| " >>str strVar x >>str strAdd " :" ]
(5 + string-length x) [ to-stringh T ]) cs) >>str strAdd "."
cmd-to-string ps (CmdImport (Import p? fp mn q? as)) =
strAdd "import " >>str
strAdd mn >>str
maybe-else' q? strEmpty (λ x → strAdd " as " >>str strAdd x) >>str
args-to-string as >>str
strAdd "."
cmds-to-string b-a ps =
let b-a-tt : cmd → strM → strM
b-a-tt = λ c cs → strLine >>str strLine >>str cmd-to-string ps c >>str cs
b-a-ff : cmd → strM → strM
b-a-ff = λ c cs → cmd-to-string ps c >>str cs >>str strLine >>str strLine in
foldr (if b-a then b-a-tt else b-a-ff) strEmpty
file-to-string : file → strM
file-to-string (Module mn ps cs) =
strAdd "module " >>str
strAdd mn >>str
strAdd "." >>str
cmds-to-string tt [] cs
--cmds-to-string tt ps cs
record elab-info : Set where
constructor mk-elab-info
field
τ : toplevel-state
ρ : renamectxt
φ : renamectxt × trie file
ν : trie stringset -- dependency mapping
new-elab-info : toplevel-state → elab-info
new-elab-info ts = mk-elab-info ts empty-renamectxt (empty-renamectxt , empty-trie) empty-trie
ts-def : toplevel-state → var → tmtp → toplevel-state
ts-def ts x tT =
let Γ = toplevel-state.Γ ts
i = ctxt.i Γ
d = either-else' tT
(λ t → term-def nothing opacity-open (just t) (TpHole pi-gen))
(λ T → type-def nothing opacity-open (just T) (KdHole pi-gen)) in
record ts { Γ = record Γ { i = trie-insert i x (d , missing-location) } }
add-dep : elab-info → var → elab-info
add-dep (mk-elab-info τ ρ φ ν) mnᵢ =
let fp = ctxt.fn (toplevel-state.Γ τ)
mnᵢ-is = stringset-strings (trie-lookup-else empty-trie ν mnᵢ)
mn-is = trie-lookup-else empty-trie ν fp in
mk-elab-info τ ρ φ (trie-insert ν fp (foldr (flip stringset-insert) (stringset-insert mn-is mnᵢ) mnᵢ-is))
set-fn : elab-info → filepath → elab-info
set-fn (mk-elab-info τ ρ φ ν) fn = mk-elab-info (record τ { Γ = record (toplevel-state.Γ τ) { fn = fn } }) ρ φ ν
set-mn : elab-info → var → elab-info
set-mn (mk-elab-info τ ρ φ ν) mn = mk-elab-info (record τ { Γ = record (toplevel-state.Γ τ) { mn = mn } }) ρ φ ν
get-fn : elab-info → filepath
get-fn = ctxt.fn ∘' toplevel-state.Γ ∘' elab-info.τ
get-mn : elab-info → var
get-mn = ctxt.mn ∘' toplevel-state.Γ ∘' elab-info.τ
get-deps : elab-info → filepath → file → file
get-deps (mk-elab-info τ ρ φ ν) fp (Module mn ps es) =
Module mn ps (foldr (λ x → CmdImport (Import ff x (renamectxt-rep (fst φ) x) nothing []) ::_) es (stringset-strings (trie-lookup-else empty-stringset ν fp)))
{-# TERMINATING #-}
elab-file : elab-info → filepath → elab-info × var
elab-cmds : elab-info → params → cmds → elab-info × cmds
elab-cmds ei ps [] = ei , []
elab-cmds ei@(mk-elab-info τ ρ φ ν) ps (CmdDefTerm x t :: csᵣ) =
rename (get-mn ei # x) - x from ρ for λ x' ρ' →
let t' = choose-mu (toplevel-state.Γ τ) ρ (params-to-lams ps t) in
elim elab-cmds (mk-elab-info (ts-def τ x' (Ttm t')) ρ' φ ν) ps csᵣ for λ ei csᵣ →
ei , CmdDefTerm x' t' :: csᵣ
elab-cmds ei@(mk-elab-info τ ρ φ ν) ps (CmdDefType x k T :: csᵣ) =
rename (get-mn ei # x) - x from ρ for λ x' ρ' →
let k' = choose-mu (toplevel-state.Γ τ) ρ (params-to-kind ps k)
T' = choose-mu (toplevel-state.Γ τ) ρ (params-to-tplams ps T) in
elim elab-cmds (mk-elab-info (ts-def τ x' (Ttp T')) ρ' φ ν) ps csᵣ for λ ei csᵣ →
ei , CmdDefType x' k' T' :: csᵣ
elab-cmds ei ps (CmdDefKind x psₖ k :: csᵣ) =
elab-cmds ei ps csᵣ
elab-cmds ei ps (CmdDefData es x psₓ k cs :: csᵣ) =
elim elab-cmds ei [] (encoding-defs.ecs es) for λ ei ecs →
elim elab-cmds ei [] (encoding-defs.gcs es) for λ ei gcs →
elim elab-cmds ei ps csᵣ for λ ei rcs →
ei , ecs ++ gcs ++ rcs
elab-cmds ei ps (CmdImport (Import p? fp mn' q? as) :: csᵣ) =
let fpₒ = get-fn ei; mnₒ = get-mn ei in
elim elab-file ei fp for λ ei mn'' →
elab-cmds (add-dep (set-mn (set-fn ei fpₒ) mnₒ) fp) ps csᵣ
elab-file ei @ (mk-elab-info τ ρ φ ν) fp with trie-contains (snd φ) fp
...| tt = ei , renamectxt-rep (fst φ) fp
...| ff with get-include-elt-if τ fp >>= include-elt.ast~
...| nothing = ei , "error"
...| just (Module mn ps es) =
let p = elab-cmds (record (set-mn (set-fn ei fp) mn) { ν = trie-insert (elab-info.ν ei) fp empty-trie }) ps es
(mk-elab-info τ ρ φ ν) = fst p
es' = snd p
τ = record τ { Γ = record (toplevel-state.Γ τ) { ps = ps } } in
rename fp - mn from fst φ for λ mn' φ' →
mk-elab-info τ ρ (φ' , trie-insert (snd φ) fp (Module mn' ps es')) ν , mn'
elab-write-all : elab-info → (to : filepath) → IO ⊤
elab-write-all ei@(mk-elab-info τ ρ φ ν) to =
let Γ = toplevel-state.Γ τ
print = strRun Γ ∘ file-to-string in
foldr'
(createDirectoryIfMissing ff to)
(uncurry λ fₒ fₛ io →
let fₘ = renamectxt-rep (fst φ) fₒ
fₙ = combineFileNames to (fₘ ^ ".cdle") in
io >> writeRopeToFile fₙ (print (get-deps ei fₒ fₛ)))
(trie-mappings (snd φ))
elab-all : toplevel-state → (from to : filepath) → IO ⊤
elab-all ts fm to =
elab-write-all (fst (elab-file (new-elab-info ts) fm)) to >>
putStrLn ("0")
| 44.958261
| 286
| 0.57462
|
59a17e28dcae0c46d0f3e9f7a8a058d1375325df
| 729
|
agda
|
Agda
|
test/Succeed/Issue2231sharp.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue2231sharp.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2231sharp.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2016-10-03, re issue #2231
-- Termination checking a corecursive definition in abstract mode.
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
abstract
data Functor : Set where
Id : Functor
_·_ : Functor → Set → Set
Id · A = A
data ν (F : Functor) : Set where
inn : ∞ (F · ν F) → ν F
-- Evaluation is required to see that Id · ν Id is a coinductive type.
foo : ∀ F → F · ν F
foo Id = inn (♯ foo Id)
-- The termination checker needs to treat the generated #-foo function
-- in abstract mode, to have constructor Id in scope.
| 22.78125
| 72
| 0.573388
|
5925c2476392ff67cae40b24e95200609d0beadd
| 127,794
|
agda
|
Agda
|
archive/agda-1/NaturalDeduction.monolithic.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/NaturalDeduction.monolithic.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/NaturalDeduction.monolithic.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
{-# OPTIONS --rewriting #-}
--{-# OPTIONS --exact-split #-}
--{-# OPTIONS --show-implicit #-}
module NaturalDeduction
where
module CustomPrelude where
open import Prelude public
renaming (_==_ to _≟_) -- TODO ask Agda to rename Eq._==_ to Eq._≟_
hiding (force) -- needed by ∞Delay
{-# BUILTIN REWRITE _≡_ #-}
{-# DISPLAY Eq._==_ _ = _≟_ #-}
open import Container.List renaming (_∈_ to _∈C_; lookup∈ to lookup∈C) public
_∈C?_ : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ (a : A) → (xs : List A) → Dec (a ∈C xs)
a ∈C? [] = no λ ()
a ∈C? (x ∷ xs) with a ≟ x
… | yes a≡x rewrite a≡x = yes (zero refl)
… | no a≢x with a ∈C? xs
… | yes a∈xs = yes (suc a∈xs)
… | no a∉xs = no (λ {(zero a≡x) → a≢x a≡x ; (suc a∈xs) → a∉xs a∈xs})
_≢_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
x ≢ y = ¬ (x ≡ y)
infix 0 _↔_
_↔_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
P ↔ Q = (P → Q) × (Q → P)
infix 0 _←⊗→_
_←⊗→_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
P ←⊗→ Q = (P → ¬ Q) × (Q → ¬ P)
∃ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
∃ = Σ _
∄ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
∄ = ¬_ ∘ ∃
infixl 4 _⊎_
_⊎_ = Either
{-# DISPLAY Either = _⊎_ #-}
--open import Agda.Builtin.Size public
open import Size public
open import Control.Monad.State public
open import Control.Monad.Identity public
open import Container.Traversable public
sequence : ∀ {a b} {A : Set a} {F : Set a → Set b} ⦃ _ : Applicative F ⦄ → List (F A) → F ⊤′
sequence [] = pure tt
sequence (x ∷ xs) = x *> sequence xs
open import Tactic.Nat public
open import Tactic.Deriving.Eq public
mutual
data Delay (i : Size) (A : Set) : Set where
now : A → Delay i A
later : ∞Delay i A → Delay i A
record ∞Delay (i : Size) (A : Set) : Set where
coinductive
field
force : {j : Size< i} → Delay j A
open ∞Delay public
module BindDelay
where
mutual
bindDelay : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B
bindDelay (now a) f = f a
bindDelay (later ∞a) f = later (bind∞Delay ∞a f)
bind∞Delay : ∀ {i A B} → ∞Delay i A → (A → Delay i B) → ∞Delay i B
force (bind∞Delay ∞a f) = bindDelay (force ∞a) f
module _
where
open BindDelay
open BindDelay public using () renaming (bind∞Delay to _∞>>=_)
instance FunctorDelay : {i : Size} → Functor (Delay i)
Functor.fmap FunctorDelay f x = bindDelay x $ now ∘ f
instance ApplicativeDelay : {i : Size} → Applicative (Delay i)
Applicative.pure ApplicativeDelay x = now x
Applicative._<*>_ ApplicativeDelay (now f) x = f <$> x
Applicative._<*>_ ApplicativeDelay (later ∞f) x = later ∘ bind∞Delay ∞f $ flip fmap x
Applicative.super ApplicativeDelay = FunctorDelay
instance MonadDelay : {i : Size} → Monad (Delay i)
Monad._>>=_ MonadDelay = bindDelay
Monad.super MonadDelay = ApplicativeDelay
{-# DISPLAY BindDelay.bindDelay x f = x >>= f #-}
mutual
data _∼_ {i : Size} {A : Set} : (a? b? : Delay ∞ A) → Set where
∼now : ∀ a → now a ∼ now a
∼later : ∀ {a∞ b∞} (eq : a∞ ∞∼⟨ i ⟩∼ b∞) → later a∞ ∼ later b∞
_∼⟨_⟩∼_ = λ {A} a? i b? → _∼_ {i}{A} a? b?
record _∞∼⟨_⟩∼_ {A} (a∞ : ∞Delay ∞ A) i (b∞ : ∞Delay ∞ A) : Set where
coinductive
field
∼force : {j : Size< i} → force a∞ ∼⟨ j ⟩∼ force b∞
open _∞∼⟨_⟩∼_ public
_∞∼_ = λ {i} {A} a∞ b∞ → _∞∼⟨_⟩∼_ {A} a∞ i b∞
mutual
∼refl : ∀{i A} (a? : Delay ∞ A) → a? ∼⟨ i ⟩∼ a?
∼refl (now a) = ∼now a
∼refl (later a∞) = ∼later (∞∼refl a∞)
∞∼refl : ∀{i A} (a∞ : ∞Delay ∞ A) → a∞ ∞∼⟨ i ⟩∼ a∞
∼force (∞∼refl a∞) = ∼refl (force a∞)
mutual
∼sym : ∀{i A}{a? b? : Delay ∞ A } → a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ a?
∼sym (∼now a) = ∼now a
∼sym (∼later eq) = ∼later (∞∼sym eq)
∞∼sym : ∀{i A}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ a∞
∼force (∞∼sym eq) = ∼sym (∼force eq)
mutual
∼trans : ∀{i A}{a? b? c? : Delay ∞ A} →
a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ c? → a? ∼⟨ i ⟩∼ c?
∼trans (∼now a) (∼now .a) = ∼now a
∼trans (∼later eq) (∼later eq′) = ∼later (∞∼trans eq eq′)
∞∼trans : ∀{i A}{a∞ b∞ c∞ : ∞Delay ∞ A} →
a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ c∞ → a∞ ∞∼⟨ i ⟩∼ c∞
∼force (∞∼trans eq eq′) = ∼trans (∼force eq) (∼force eq′)
--∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
--∞∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
mutual
bind-assoc : ∀{i A B C} (m : Delay ∞ A)
{k : A → Delay ∞ B} {l : B → Delay ∞ C} →
((m >>= k) >>= l) ∼⟨ i ⟩∼ (m >>= λ a → (k a >>= l))
bind-assoc (now a) = ∼refl _
bind-assoc (later a∞) = ∼later (∞bind-assoc a∞)
∞bind-assoc : ∀{i A B C} (a∞ : ∞Delay ∞ A)
{k : A → Delay ∞ B} {l : B → Delay ∞ C} →
((a∞ ∞>>= k) ∞>>= l) ∞∼⟨ i ⟩∼ (a∞ ∞>>= λ a → (k a >>= l))
∼force (∞bind-assoc a∞) = bind-assoc (force a∞)
mutual
bind-cong-l : ∀{i A B}{a? b? : Delay ∞ A} → a? ∼⟨ i ⟩∼ b? →
(k : A → Delay ∞ B) → (a? >>= k) ∼⟨ i ⟩∼ (b? >>= k)
bind-cong-l (∼now a) k = ∼refl _
bind-cong-l (∼later eq) k = ∼later (∞bind-cong-l eq k)
∞bind-cong-l : ∀{i A B}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ →
(k : A → Delay ∞ B) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (b∞ ∞>>= k)
∼force (∞bind-cong-l eq k) = bind-cong-l (∼force eq) k
mutual
bind-cong-r : ∀{i A B}(a? : Delay ∞ A){k l : A → Delay ∞ B} →
(∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a? >>= k) ∼⟨ i ⟩∼ (a? >>= l)
bind-cong-r (now a) h = h a
bind-cong-r (later a∞) h = ∼later (∞bind-cong-r a∞ h)
∞bind-cong-r : ∀{i A B}(a∞ : ∞Delay ∞ A){k l : A → Delay ∞ B} →
(∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (a∞ ∞>>= l)
∼force (∞bind-cong-r a∞ h) = bind-cong-r (force a∞) h
map-compose : ∀{i A B C} (a? : Delay ∞ A) {f : A → B} {g : B → C} →
(g <$> (f <$> a?)) ∼⟨ i ⟩∼ ((g ∘ f) <$> a?)
map-compose a? = bind-assoc a?
map-cong : ∀{i A B}{a? b? : Delay ∞ A} (f : A → B) →
a? ∼⟨ i ⟩∼ b? → (f <$> a?) ∼⟨ i ⟩∼ (f <$> b?)
map-cong f eq = bind-cong-l eq (now ∘ f)
data _⇓_ {A : Set} : (a? : Delay ∞ A) (a : A) → Set where
now⇓ : ∀{a} → now a ⇓ a
later⇓ : ∀{a} {a∞ : ∞Delay ∞ A} → force a∞ ⇓ a → later a∞ ⇓ a
_⇓ : {A : Set} (x : Delay ∞ A) → Set
x ⇓ = ∃ λ a → x ⇓ a
map⇓ : ∀{A B}{a : A}{a? : Delay ∞ A}(f : A → B) → a? ⇓ a → (f <$> a?) ⇓ f a
map⇓ f now⇓ = now⇓
map⇓ f (later⇓ a⇓) = later⇓ (map⇓ f a⇓)
bind⇓ : ∀{A B}(f : A → Delay ∞ B){?a : Delay ∞ A}{a : A}{b : B} →
?a ⇓ a → f a ⇓ b → (?a >>= f) ⇓ b
bind⇓ f now⇓ q = q
bind⇓ f (later⇓ p) q = later⇓ (bind⇓ f p q)
infixl 4 _>>=⇓_
_>>=⇓_ : ∀{A B}{f : A → Delay ∞ B}{?a : Delay ∞ A}{a : A}{b : B} →
?a ⇓ a → f a ⇓ b → (?a >>= f) ⇓ b
_>>=⇓_ = bind⇓ _
infixl 4 _⇓>>=⇓_
_⇓>>=⇓_ : ∀{A B}{f : A → Delay ∞ B}{?a : Delay ∞ A}{b : B} →
(?a⇓ : ?a ⇓) → f (fst ?a⇓) ⇓ b → (?a >>= f) ⇓ b
_⇓>>=⇓_ (_ , a⇓) = bind⇓ _ a⇓
_⇓Dec>>=⇓_else⇓_ : ∀{A B}{f-yes : A → Delay ∞ B}{f-no : ¬ A → Delay ∞ B}{?a : Delay ∞ (Dec A)}{b : B} →
(?a⇓ : ?a ⇓) →
((a : A) → f-yes a ⇓ b) →
((¬a : ¬ A) → f-no ¬a ⇓ b) →
((?a >>= (λ { (yes y) → f-yes y ; (no n) → f-no n }))) ⇓ b
(yes y , y⇓) ⇓Dec>>=⇓ fy⇓ else⇓ fn⇓ = y⇓ >>=⇓ fy⇓ y
(no n , n⇓) ⇓Dec>>=⇓ fy⇓ else⇓ fn⇓ = n⇓ >>=⇓ fn⇓ n
_⇓DecEq>>=⇓_else⇓_ : ∀{A : Set} {A₁ A₂ : A} {B}{f-yes : A₁ ≡ A₂ → Delay ∞ B}{f-no : A₁ ≢ A₂ → Delay ∞ B}{?a : Delay ∞ (Dec (A₁ ≡ A₂))}{b : B} →
(?a⇓ : ?a ⇓) →
((eq : A₁ ≡ A₂) → f-yes eq ⇓ b) →
((¬eq : A₁ ≢ A₂) → f-no ¬eq ⇓ b) →
((?a >>= (λ { (yes refl) → f-yes refl ; (no n) → f-no n }))) ⇓ b
(yes refl , y⇓) ⇓DecEq>>=⇓ fy⇓ else⇓ fn⇓ = y⇓ >>=⇓ fy⇓ refl
(no n , n⇓) ⇓DecEq>>=⇓ fy⇓ else⇓ fn⇓ = n⇓ >>=⇓ fn⇓ n
app⇓ : ∀{A}{B}{f? : Delay ∞ (A → B)}{f : A → B}{x? : Delay ∞ A}{x : A} → f? ⇓ f → x? ⇓ x → (f? <*> x?) ⇓ f x
app⇓ now⇓ now⇓ = now⇓
app⇓ now⇓ (later⇓ x?) = later⇓ $ map⇓ _ x?
app⇓ (later⇓ f?) now⇓ = later⇓ $ bind⇓ _ f? now⇓
app⇓ (later⇓ ⇓f) (later⇓ ⇓x) = later⇓ $ bind⇓ _ ⇓f $ later⇓ $ bind⇓ _ ⇓x now⇓
subst∼⇓ : ∀{A}{a? a?′ : Delay ∞ A}{a : A} → a? ⇓ a → a? ∼ a?′ → a?′ ⇓ a
subst∼⇓ now⇓ (∼now a) = now⇓
subst∼⇓ (later⇓ p) (∼later eq) = later⇓ (subst∼⇓ p (∼force eq))
{-
traverse⇓' : ∀{A}{B}{f? : A → Delay ∞ B}{T : Set → Set}⦃ _ : Traversable T ⦄{X : T A} → (∀ x → f? x ⇓) → ∀ (x : T A) → traverse f? x ⇓
traverse⇓' x₁ x₂ = {!!} , {!!}
-}
{-
traverse⇓ : ∀{A}{B}{f : A → B}{T : Set → Set}⦃ _ : Traversable T ⦄{X : T A} → (∀ x → f? x ⇓) → ∀ (x : T A) → traverse f x ⇓
traverse⇓ x₁ x₂ = {!!} , {!!}
-}
traverse-list⇓ : ∀{A}{B} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : List A) → traverse f? xs ⇓
traverse-list⇓ f? f?⇓ [] = [] , now⇓
traverse-list⇓ f? f?⇓ (x ∷ xs)
with f?⇓ x | traverse-list⇓ f? f?⇓ xs
… | y , y⇓ | ys , ys⇓ = y ∷ ys , app⇓ (map⇓ _ y⇓) ys⇓
{-
traverse-vec⇓' : ∀{A}{B}{𝑎} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : Vector A 𝑎) → traverse f? xs ⇓
traverse-vec⇓' f? f?⇓ [] = [] , now⇓
traverse-vec⇓' f? f?⇓ (x ∷ xs)
with f?⇓ x | traverse-vec⇓' f? f?⇓ xs
… | y , y⇓ | ys , ys⇓ = y ∷ ys , app⇓ (map⇓ _ y⇓) ys⇓
traverse-vec⇓ : ∀{A}{B}{𝑎} (f : A → B) → (xs : Vector (Delay ∞ A) 𝑎) → traverse {!f!} xs ⇓
traverse-vec⇓ = {!!}
-}
{-
traverse-vec⇓ : ∀{A}{B}{𝑎} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : Vec A 𝑎) → traverse {!f!} xs ⇓
-}
open CustomPrelude
record Successor {ℓᴬ} (A : Set ℓᴬ) {ℓᴮ} (B : Set ℓᴮ) : Set (ℓᴬ ⊔ ℓᴮ)
where
field
⊹ : A → B
open Successor ⦃ … ⦄
instance SuccessorNat : Successor Nat Nat
Successor.⊹ SuccessorNat = suc
instance SuccessorLevel : Successor Level Level
Successor.⊹ SuccessorLevel = lsuc
record Membership {ℓ} (m : Set ℓ) (M : Set ℓ) : Set (⊹ ℓ)
where
field
_∈_ : m → M → Set ℓ
_∉_ : m → M → Set ℓ
xor-membership : ∀ {x : m} {X : M} → x ∈ X ←⊗→ x ∉ X
open Membership ⦃ … ⦄
data _∈L_ {ℓ} {A : Set ℓ} (a : A) : List A → Set ℓ
where
zero : {as : List A} → a ∈L (a ∷ as)
suc : {x : A} {as : List A} → a ∈L as → a ∈L (x ∷ as)
instance Successor∈L : ∀ {ℓ} {A : Set ℓ} {a : A} {x : A} {as : List A} → Successor (a ∈L as) $ a ∈L (x ∷ as)
Successor.⊹ Successor∈L = suc
instance MembershipList : ∀ {ℓ} {A : Set ℓ} → Membership A $ List A
Membership._∈_ MembershipList = _∈L_
Membership._∉_ MembershipList x X = ¬ x ∈ X
Membership.xor-membership MembershipList = (λ x x₁ → x₁ x) , (λ x x₁ → x x₁)
record DecidableMembership {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set (⊹ ℓ)
where
field _∈?_ : (x : m) → (X : M) → Dec $ x ∈ X
field _∉?_ : (x : m) → (X : M) → Dec $ x ∉ X
open DecidableMembership ⦃ … ⦄
instance DecidableMembershipList : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → DecidableMembership A $ List A
DecidableMembership._∈?_ (DecidableMembershipList {ℓ} {A}) = _∈L?_
where
_∈L?_ : (a : A) → (xs : List A) → Dec (a ∈ xs)
a ∈L? [] = no λ ()
a ∈L? (x ∷ xs) with a ≟ x
… | yes a≡x rewrite a≡x = yes zero
… | no a≢x with a ∈L? xs
… | yes a∈xs = yes (⊹ a∈xs)
… | no a∉xs = no (λ {zero → a≢x refl ; (suc a∈xs) → a∉xs a∈xs})
DecidableMembership._∉?_ (DecidableMembershipList {ℓ} {A}) = {!!}
_⊆_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
_⊆_ {A = A} R S = ∀ {x : A} → x ∈ R → x ∈ S
record VariableName : Set
where
constructor ⟨_⟩
field
name : Nat
open VariableName
instance EqVariableName : Eq VariableName
Eq._==_ EqVariableName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
record FunctionName : Set
where
constructor ⟨_⟩
field
name : Nat
open FunctionName
instance EqFunctionName : Eq FunctionName
Eq._==_ EqFunctionName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
record PredicateName : Set
where
constructor ⟨_⟩
field
name : Nat
open PredicateName
instance EqPredicateName : Eq PredicateName
Eq._==_ EqPredicateName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
record Arity : Set
where
constructor ⟨_⟩
field
arity : Nat
open Arity
instance EqArity : Eq Arity
Eq._==_ EqArity _ = decEq₁ (cong arity) ∘ (_≟_ on arity $ _)
record Vector (A : Set) (𝑎 : Arity) : Set
where
constructor ⟨_⟩
field
vector : Vec A (arity 𝑎)
open Vector
instance EqVector : {A : Set} ⦃ _ : Eq A ⦄ {𝑎 : Arity} → Eq (Vector A 𝑎)
Eq._==_ EqVector _ = decEq₁ (cong vector) ∘ (_≟_ on vector $ _)
data ITerm : Nat → Set
where
variable : VariableName → ITerm zero
function : FunctionName → {arity : Nat} → (τs : Vec (Σ Nat ITerm) arity) → {n : Nat} → n ≡ sum (vecToList $ (fst <$> τs)) → ITerm (suc n)
mutual
eqITerm : ∀ {n} → (x y : ITerm n) → Dec (x ≡ y)
eqITerm = {!!}
{-
eqITerm : ∀ {n} → (x y : ITerm n) → Dec (x ≡ y)
eqITerm {.0} (variable x) (variable x₁) = {!!}
eqITerm {.(suc n)} (function x {arity = arity₁} τs {n = n} x₁) (function x₂ {arity = arity₂} τs₁ {n = .n} x₃) with x ≟ x₂ | arity₁ ≟ arity₂
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function .x {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) with eqITerms τs τs₁
eqITerm {.(suc n)} (function x₁ {arity₁} τs {n} x₄) (function .x₁ {.arity₁} .τs {.n} x₅) | yes refl | (yes refl) | (yes refl) rewrite x₄ | x₅ = yes refl
eqITerm {.(suc n)} (function x₁ {arity₁} τs {n} x₄) (function .x₁ {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) | (no x) = {!!}
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | yes x₁ | (no x₃) = {!!}
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (yes x₃) = {!!}
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (no x₃) = {!!}
-}
eqITerms : ∀ {n} → (x y : Vec (Σ Nat ITerm) n) → Dec (x ≡ y)
eqITerms {.0} [] [] = {!!}
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) with fst₁ ≟ fst₂
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl with eqITerm snd₁ snd₂
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | yes refl with eqITerms x₁ y
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | yes refl | yes refl = yes refl
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | yes refl | no ref = {!!}
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | no ref = {!!}
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | no ref = {!!}
instance EqITerm : ∀ {n} → Eq (ITerm n)
Eq._==_ EqITerm = eqITerm
{-
instance EqITerm : ∀ {n} → Eq (ITerm n)
Eq._==_ EqITerm (variable x) (variable x₁) = {!!}
Eq._==_ EqITerm (function x {arity = arity₁} τs {n = n} x₁) (function x₂ {arity = arity₂} τs₁ {n = .n} x₃) with x ≟ x₂ | arity₁ ≟ arity₂
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function .x {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) with τs ≟ τs₁
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function .x {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) | τs≡τs₁ = {!!}
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | yes x₁ | (no x₃) = {!!}
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (yes x₃) = {!!}
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (no x₃) = {!!}
-}
mutual
data Term : Set
where
variable : VariableName → Term
function : FunctionName → Terms → Term
record Terms : Set
where
constructor ⟨_⟩
inductive
field
{arity} : Arity
terms : Vector Term arity
open Terms
termVariable-inj : ∀ {𝑥₁ 𝑥₂} → Term.variable 𝑥₁ ≡ variable 𝑥₂ → 𝑥₁ ≡ 𝑥₂
termVariable-inj refl = refl
termFunction-inj₁ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → 𝑓₁ ≡ 𝑓₂
termFunction-inj₁ refl = refl
termFunction-inj₂ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → τ₁s ≡ τ₂s
termFunction-inj₂ refl = refl
terms-inj : ∀ {𝑎} → {τs₁ τs₂ : Vector Term 𝑎} → (τs₁≡τs₂ : (Terms.⟨_⟩ {𝑎} τs₁) ≡ ⟨ τs₂ ⟩) → τs₁ ≡ τs₂
terms-inj refl = refl
mutual
termToITerm : Term → Σ Nat ITerm
termToITerm (variable x) = _ , (variable x)
termToITerm (function x x₁) = {!!}
termsToVec : Terms → Σ Nat (λ arity → Σ (Vec (Σ Nat ITerm) arity) λ τs → Σ Nat λ n → n ≡ sum (vecToList $ (fst <$> τs)))
termsToVec (⟨_⟩ {arity = arity₁} ⟨ vector₁ ⟩) = {!!}
iTermToTerm : Σ Nat ITerm → Term
iTermToTerm = {!!}
eq-term-round : ∀ τ → iTermToTerm (termToITerm τ) ≡ τ
eq-term-round = {!!}
eq-iterm-round : ∀ τ → termToITerm (iTermToTerm τ) ≡ τ
eq-iterm-round = {!!}
instance EqTerm : Eq Term
Eq._==_ EqTerm x y with termToITerm x | graphAt termToITerm x | termToITerm y | graphAt termToITerm y
Eq._==_ EqTerm x y | ix | ingraph eqx | iy | ingraph eqy with ix ≟ iy
Eq._==_ EqTerm x y | ix | ingraph eqx | .ix | ingraph eqy | yes refl = yes $ ((cong iTermToTerm eqy ⟨≡⟩ʳ cong iTermToTerm eqx) ⟨≡⟩ eq-term-round x) ʳ⟨≡⟩ eq-term-round y
Eq._==_ EqTerm x y | ix | ingraph eqx | iy | ingraph eqy | no neq = {!!}
instance EqTerms : Eq Terms
EqTerms = {!!}
{-
module _ {i : Size}
where
mutual
EqTerm⇑ : (x y : Term) → Delay i ∘ Dec $ x ≡ y
EqTerm⇑ (variable _) (variable _) = now (decEq₁ termVariable-inj $ _≟_ _ _)
EqTerm⇑ (function 𝑓₁ τ₁s) (function 𝑓₂ τ₂s) =
{-
τ₁s≟τ₂s ← EqTerms⇑ τ₁s τ₂s -|
(now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s)
-}
EqTerms⇑ τ₁s τ₂s >>= λ
τ₁s≟τ₂s → now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s
EqTerm⇑ (variable _) (function _ _) = now $ no λ ()
EqTerm⇑ (function _ _) (variable _) = now $ no λ ()
EqTerms⇑ : (x y : Terms) → Delay i ∘ Dec $ x ≡ y
EqTerms⇑ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s)
with 𝑎₁ ≟ 𝑎₂
… | no 𝑎₁≢𝑎₂ = now $ no λ {τ₁≡τ₂ → 𝑎₁≢𝑎₂ (cong arity τ₁≡τ₂)}
… | yes refl =
EqVectorTerm⇑ τ₁s τ₂s >>= λ
{ (yes refl) → now $ yes refl
; (no τ₁s≢τ₂s) → now $ no (λ ⟨τ₁s⟩≡⟨τ₂s⟩ → τ₁s≢τ₂s (terms-inj ⟨τ₁s⟩≡⟨τ₂s⟩)) }
EqVectorTerm⇑ : ∀ {n} → (x y : Vector Term n) → Delay i ∘ Dec $ x ≡ y
EqVectorTerm⇑ ⟨ [] ⟩ ⟨ [] ⟩ = now (yes refl)
EqVectorTerm⇑ ⟨ τ₁ ∷ τ₁s ⟩ ⟨ τ₂ ∷ τ₂s ⟩ =
EqTerm⇑ τ₁ τ₂ >>= λ
{ (yes refl) → EqVectorTerm⇑ ⟨ τ₁s ⟩ ⟨ τ₂s ⟩ >>= λ
{ (yes refl) → now $ yes refl
; (no τ₁s≢τ₂s) → now $ no λ τ₁₁s≡τ₁₂s → τ₁s≢τ₂s $ cong ⟨_⟩ ((vcons-inj-tail (cong vector τ₁₁s≡τ₁₂s))) }
; (no τ₁≢τ₂) → now $ no λ τ₁₁s≡τ₂₂s → τ₁≢τ₂ $ vcons-inj-head (cong vector τ₁₁s≡τ₂₂s) }
EqVectorTerm⇓ : ∀ {n} → (x y : Vector Term n) → EqVectorTerm⇑ x y ⇓
EqVectorTerm⇓ ⟨ [] ⟩ ⟨ [] ⟩ = _ , now⇓
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable 𝑥₂ ∷ τ₂s ⟩
with 𝑥₁ ≟ 𝑥₂
… | yes refl with EqVectorTerm⇓ ⟨ τ₁s ⟩ ⟨ τ₂s ⟩
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable .𝑥₁ ∷ .τ₁s ⟩ | yes refl | (yes refl , snd₁) = _ , snd₁ >>=⇓ now⇓
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable .𝑥₁ ∷ τ₂s ⟩ | yes refl | (no x , snd₁) = _ , snd₁ >>=⇓ now⇓
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable 𝑥₂ ∷ τ₂s ⟩ | no 𝑥₁≢𝑥₂ = _ , now⇓
EqVectorTerm⇓ ⟨ variable x ∷ τ₁s ⟩ ⟨ function x₁ x₂ ∷ τ₂s ⟩ = _ , now⇓
EqVectorTerm⇓ ⟨ function x x₁ ∷ τ₁s ⟩ ⟨ variable x₂ ∷ τ₂s ⟩ = _ , now⇓
EqVectorTerm⇓ ⟨ function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s ⟩ ⟨ function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s ⟩
with 𝑎₁ ≟ 𝑎₂ | 𝑓₁ ≟ 𝑓₂
… | no 𝑎₁≢𝑎₂ | no 𝑓₁≢𝑓₂ = _ , now⇓
… | no 𝑎₁≢𝑎₂ | yes refl = _ , now⇓
… | yes refl | no 𝑓₁≢𝑓₂
with EqVectorTerm⇓ τ₁s τ₂s
… | (no τ₁s≢τ₂s , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
… | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
EqVectorTerm⇓ ⟨ function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s ⟩ ⟨ function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s ⟩ | yes refl | yes refl
with EqVectorTerm⇓ τ₁s τ₂s | EqVectorTerm⇓ ⟨ τ₁₂s ⟩ ⟨ τ₂₂s ⟩
… | (no τ₁s≢τ₂s , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
… | (yes refl , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓)
… | (no τ₁s≢τ₂s , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
… | (yes refl , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓)
EqTerms⇓ : (x y : Terms) → EqTerms⇑ x y ⇓
EqTerms⇓ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s)
with 𝑎₁ ≟ 𝑎₂
… | no 𝑎₁≢𝑎₂ = _ , now⇓
… | yes refl
with EqVectorTerm⇓ τ₁s τ₂s
… | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓
… | (no _ , τ⇓) = _ , τ⇓ >>=⇓ now⇓
EqTerm⇓ : (x y : Term) → EqTerm⇑ x y ⇓
EqTerm⇓ (variable x) (variable x₁) = _ , now⇓
EqTerm⇓ (function _ τ₁s) (function _ τ₂s)
with EqTerms⇓ τ₁s τ₂s
… | (_ , τ⇓) = _ , τ⇓ >>=⇓ now⇓
EqTerm⇓ (variable x) (function x₁ x₂) = _ , now⇓
EqTerm⇓ (function x x₁) (variable x₂) = _ , now⇓
instance EqTerm : Eq Term
EqTerm = record { _==_ = λ x y → fst (EqTerm⇓ x y) }
instance EqTerms : Eq Terms
Eq._==_ EqTerms x y = fst (EqTerms⇓ x y)
-}
record Unifiable (F : Set) (T : Set) (U₁ U₂ : Set) (σ : (T → F) → F → F) : Set₁ where
field
_≈u≈_ : (φ₁ φ₂ : F) → Set
unifier : (φ₁ φ₂ : F) → φ₁ ≈u≈ φ₂ → (F → F) × (F → F)
unifier-law : (φ₁ φ₂ : F) → (=u= : φ₁ ≈u≈ φ₂) → (let u = unifier φ₁ φ₂ =u=) → (fst u) φ₁ ≡ (snd u) φ₂
{-
{-# TERMINATING #-}
-- substitute 𝑥ₛ τₛ τ = τ, where all occurrences of 𝑥ₛ are replaced by τₛ
substitute : VariableName → Term → Term → Term
substitute 𝑥ₛ τₛ τ@(variable 𝑥) = ifYes 𝑥ₛ ≟ 𝑥 then τₛ else τ
substitute 𝑥ₛ τₛ (function 𝑓 ⟨ ⟨ τs ⟩ ⟩) = function 𝑓 ⟨ ⟨ substitute 𝑥ₛ τₛ <$> τs ⟩ ⟩
-}
mutual
substituteTerm⇑ : VariableName → Term → ∀ {i} → Term → Delay i Term
substituteTerm⇑ 𝑥ₛ τₛ τ@(variable 𝑥) = now $ ifYes 𝑥ₛ ≟ 𝑥 then τₛ else τ
substituteTerm⇑ 𝑥ₛ τₛ (function 𝑓 τs) =
substituteTerms⇑ 𝑥ₛ τₛ τs >>= λ τsₛ →
now $ function 𝑓 τsₛ
substituteTerms⇑ : VariableName → Term → ∀ {i} → Terms → Delay i Terms
substituteTerms⇑ 𝑥ₛ τₛ ⟨ ⟨ [] ⟩ ⟩ = now ⟨ ⟨ [] ⟩ ⟩
substituteTerms⇑ 𝑥ₛ τₛ ⟨ ⟨ τ ∷ τs ⟩ ⟩ =
let τs = substituteTerms⇑ 𝑥ₛ τₛ ⟨ ⟨ τs ⟩ ⟩
τ = substituteTerm⇑ 𝑥ₛ τₛ τ in
τs >>= λ { ⟨ ⟨ τs ⟩ ⟩ →
τ >>= λ { τ →
now $ ⟨ ⟨ τ ∷ τs ⟩ ⟩ } }
substituteTerms⇓ : (𝑥ₛ : VariableName) → (τₛ : Term) → (τs : Terms) → substituteTerms⇑ 𝑥ₛ τₛ τs ⇓
substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ [] ⟩ ⟩ = _ , now⇓
substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ (variable 𝑥) ∷ τs ⟩ ⟩ = _ , substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ now⇓
substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ (function 𝑓 τs₁) ∷ τs ⟩ ⟩ = _ , substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ ((substituteTerms⇓ 𝑥ₛ τₛ τs₁ ⇓>>=⇓ now⇓) >>=⇓ now⇓)
substituteTerm⇓ : (𝑥ₛ : VariableName) → (τₛ : Term) → (τ : Term) → substituteTerm⇑ 𝑥ₛ τₛ τ ⇓
substituteTerm⇓ 𝑥ₛ τₛ (variable 𝑥) = _ , now⇓
substituteTerm⇓ 𝑥ₛ τₛ (function 𝑓 τs) = _ , substituteTerms⇓ 𝑥ₛ τₛ τs ⇓>>=⇓ now⇓
substitute : VariableName → Term → Term → Term
substitute 𝑥ₛ τₛ τ = fst $ substituteTerm⇓ 𝑥ₛ τₛ τ
{-
record StructureSuitableForSubstitution : Set where
field
(∀ x xs → x ∈ xs → )
VariableConstructor : VariableName → Term
FunctionConstructor : FunctionName → (a : Nat) → (ts : Vec Term a) → Term
∀ v' → VariableConstructor v' ≡ τ → τₛ ≡ substitute 𝑥ₛ τₛ τ
∀ f' → FunctionConstructor f' ≡ τ → ∀ τ' → τ' ∈ τ → τₛ ≡ substitute 𝑥ₛ τₛ τ
constructor-bases : Vec Set #constructors
eq : ∀ x → x ∈ constructor-bases → Eq x
substitute : → constructor-base Structure → Structure
datatype-constructor₁ : constructor-base₁ → datatype
MEMBERSHIP : ELEMENT → STRUCTURE → Set
ELEMENT → MEMBERSHIP e s → Σ STRUCTURE
VariableConstructor → Term
FunctionConstructor → Term
substitute : VariableConstructor → Term → Term → Term
substitute
-}
instance MembershipTermTerms : Membership Term Terms
Membership._∈_ MembershipTermTerms = _ᵗ∈ᵗˢ_ where
data _ᵗ∈ᵗˢ_ (τ : Term) : Terms → Set
where
zero : τ ᵗ∈ᵗˢ ⟨ ⟨ τ ∷ [] ⟩ ⟩
suc : ∀ {τs} → τ ᵗ∈ᵗˢ τs → τ ᵗ∈ᵗˢ ⟨ ⟨ τ ∷ vector (terms τs) ⟩ ⟩
Membership._∉_ MembershipTermTerms x X = ¬ x ∈ X
fst (Membership.xor-membership MembershipTermTerms) x₁ x₂ = x₂ x₁
snd (Membership.xor-membership MembershipTermTerms) x₁ x₂ = x₁ x₂
instance MembershipVariableNameTerm : Membership VariableName Term
Membership._∈_ MembershipVariableNameTerm = _ᵛ∈ᵗ_ where
data _ᵛ∈ᵗ_ (𝑥 : VariableName) : Term → Set
where
variable : 𝑥 ᵛ∈ᵗ variable 𝑥
function : ∀ 𝑓 {τ : Term} {τs} → {_ : 𝑥 ∈ τ} → τ ∈ τs → 𝑥 ᵛ∈ᵗ function 𝑓 τs
Membership._∉_ MembershipVariableNameTerm x X = ¬ x ∈ X
fst (Membership.xor-membership MembershipVariableNameTerm) x₁ x₂ = x₂ x₁
snd (Membership.xor-membership MembershipVariableNameTerm) x₁ x₂ = x₁ x₂
data 𝕃 {𝑨} (𝐴 : Set 𝑨) : Set 𝑨
data _∉𝕃_ {𝑨} {𝐴 : Set 𝑨} (x : 𝐴) : 𝕃 𝐴 → Set 𝑨
data 𝕃 {𝑨} (𝐴 : Set 𝑨) where
∅ : 𝕃 𝐴
✓ : {x₀ : 𝐴} → {x₁s : 𝕃 𝐴} → x₀ ∉𝕃 x₁s → 𝕃 𝐴
instance Successor𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} → {x₀ : 𝐴} → {x₁s : 𝕃 𝐴} → Successor (x₀ ∉𝕃 x₁s) (𝕃 𝐴)
Successor.⊹ Successor𝕃 = ✓
data _∉𝕃_ {𝑨} {𝐴 : Set 𝑨} (𝔞 : 𝐴) where
∅ : 𝔞 ∉𝕃 ∅
● : ∀ {x₀} → 𝔞 ≢ x₀ → ∀ {x₁s} → 𝔞 ∉𝕃 x₁s → (x₀∉x₁s : x₀ ∉𝕃 x₁s) → 𝔞 ∉𝕃 ✓ x₀∉x₁s
data _∈𝕃_ {𝑨} {𝐴 : Set 𝑨} : (𝔞 : 𝐴) → 𝕃 𝐴 → Set {-𝑨-} where
here : (𝔞 : 𝐴) {xs : 𝕃 𝐴} (𝔞∉xs : 𝔞 ∉𝕃 xs) → 𝔞 ∈𝕃 (✓ 𝔞∉xs)
there : {x : 𝐴} {xs : 𝕃 𝐴} (x∉xs : x ∉𝕃 xs) {𝔞 : 𝐴} → 𝔞 ∈𝕃 xs → 𝔞 ∈𝕃 ✓ x∉xs
∈→¬∉ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → x ∈𝕃 xs → ¬ x ∉𝕃 xs
∈→¬∉ {𝑨} {𝐴} {.𝔞} {.(✓ {_} {_} {𝔞} {xs} 𝔞∉xs)} (here 𝔞 {xs = xs} 𝔞∉xs) (● {x₀ = .𝔞} x {x₁s = .xs} x₂ .𝔞∉xs) = x refl
∈→¬∉ {𝑨} {𝐴} {x₁} {.(✓ {_} {_} {x} {∅} ∅)} (there {x = x} {xs = .∅} ∅ {𝔞 = .x₁} ()) (● {x₀ = .x} x₃ {x₁s = .∅} ∅ .∅)
∈→¬∉ {𝑨} {𝐴} {.𝔞} {.(✓ {_} {_} {x} {✓ {_} {_} {𝔞} {x₁s} x∉xs} (● {_} {_} {_} {𝔞} x₁ {x₁s} x∉xs₁ x∉xs))} (there {x = x} {xs = .(✓ {_} {_} {𝔞} {x₁s} x∉xs)} (● {x₀ = .𝔞} x₁ {x₁s = x₁s} x∉xs₁ x∉xs) {𝔞 = .𝔞} (here 𝔞 {xs = .x₁s} .x∉xs)) (● {x₀ = .x} x₃ {x₁s = .(✓ {_} {_} {𝔞} {x₁s} x∉xs)} (● {x₀ = .𝔞} x₂ {x₁s = .x₁s} x₄ .x∉xs) .(● {_} {_} {_} {𝔞} x₁ {x₁s} x∉xs₁ x∉xs)) = x₂ refl
∈→¬∉ {𝑨} {𝐴} {x} {.(✓ {_} {_} {x₁} {✓ {_} {_} {x₀} {x₁s} x∉xs} (● {_} {_} {_} {x₀} x₂ {x₁s} x∉xs₁ x∉xs))} (there {x = x₁} {xs = .(✓ {_} {_} {x₀} {x₁s} x∉xs)} (● {x₀ = x₀} x₂ {x₁s = x₁s} x∉xs₁ x∉xs) {𝔞 = .x} (there {x = .x₀} {xs = .x₁s} .x∉xs {𝔞 = .x} x₃)) (● {x₀ = .x₁} x₄ {x₁s = .(✓ {_} {_} {x₀} {x₁s} x∉xs)} (● {x₀ = .x₀} x₅ {x₁s = .x₁s} x₆ .x∉xs) .(● {_} {_} {_} {x₀} x₂ {x₁s} x∉xs₁ x∉xs)) = ∈→¬∉ x₃ x₆
∉→¬∈ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → x ∉𝕃 xs → ¬ x ∈𝕃 xs
∉→¬∈ {𝑨} {𝐴} {x} {.∅} ∅ ()
∉→¬∈ {𝑨} {𝐴} {.𝔞} {.(✓ {_} {_} {𝔞} {x₁s} x₁)} (● {x₀ = .𝔞} x {x₁s = x₁s} x₂ x₁) (here 𝔞 {xs = .x₁s} .x₁) = x refl
∉→¬∈ {𝑨} {𝐴} {x} {.(✓ {_} {_} {x₀} {x₁s} x₁)} (● {x₀ = x₀} x₂ {x₁s = x₁s} x₃ x₁) (there {x = .x₀} {xs = .x₁s} .x₁ {𝔞 = .x} x₄) = ∉→¬∈ x₃ x₄
foo : ∀ {𝑨} {𝐴 : Set 𝑨} {x x₀ : 𝐴} (x₁ : _≡_ {𝑨} {𝐴} x x₀) (x₂ : _∈𝕃_ {𝑨} {𝐴} x (✓ {_} {_} {x₀} {∅} ∅) → ⊥) → ⊥
foo {𝑨} {𝐴} {x} {.x} refl x₂ = x₂ (here x ∅)
foo₂ : (𝑨 : Level)
(𝐴 : Set 𝑨 )
(x₀ : 𝐴 )
(x₁s : 𝕃 𝐴 )
(x₁ : x₀ ∉𝕃 x₁s )
(x : 𝐴 )
(x₂ : 𝐴 )
(x₃ : x₂ ≡ x₀ → ⊥ )
(x₄ : x₂ ∉𝕃 x₁s )
(x₅ : ¬ (x ∈𝕃 ✓ (● x₃ x₄ x₁)) )
(x₆ : x ≡ x₂) → ⊥
foo₂ 𝑨 𝐴 x₀ x₁s x₁ x .x x₃ x₄ x₅ refl = x₅ (here x (● x₃ x₄ x₁)) -- x₅ (here x (● x₃ x₄ x₁))
foo₃ : (𝑨 : Level)
(𝐴 : Set 𝑨 )
(x₀ : 𝐴 )
(x₁s : 𝕃 𝐴 )
(x₁ : x₀ ∉𝕃 x₁s )
(x : 𝐴 )
(x₂ : 𝐴 )
(x₃ : x₂ ≡ x₀ → ⊥ )
(x₄ : x₂ ∉𝕃 x₁s )
(x₅ : ¬ (x ∈𝕃 ✓ (● x₃ x₄ x₁)) )
(x₆ : x ≡ x₀)
→ ⊥
foo₃ 𝑨 𝐴 x₀ x₁s x₁ .x₀ x₂ x₃ x₄ x₅ refl = x₅ (there (● x₃ x₄ x₁) (here x₀ x₁))
¬∈→∉ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → ¬ x ∈𝕃 xs → x ∉𝕃 xs
¬∈→∉ {𝑨} {𝐴} {x} {∅} x₁ = ∅
¬∈→∉ {𝑨} {𝐴} {x} {✓ {x₀ = x₀} {x₁s = .∅} ∅} x₂ = ● (λ {x₁ → foo x₁ x₂}) ∅ ∅
¬∈→∉ {𝑨} {𝐴} {x} {✓ {x₀ = x₂} {x₁s = .(✓ {_} {_} {x₀} {x₁s} x₁)} (● {x₀ = x₀} x₃ {x₁s = x₁s} x₄ x₁)} x₅ = ● (λ {x₆ → foo₂ 𝑨 𝐴 x₀ x₁s x₁ x x₂ x₃ x₄ x₅ x₆}) (● (λ {x₆ → foo₃ 𝑨 𝐴 x₀ x₁s x₁ _ x₂ x₃ x₄ x₅ x₆}) (¬∈→∉ (λ z → x₅ (there (● x₃ x₄ x₁) (there x₁ z)))) x₁) (● x₃ x₄ x₁)
¬∉→∈ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → ¬ x ∉𝕃 xs → x ∈𝕃 xs
¬∉→∈ {𝑨} {𝐴} {x} {∅} x₁ = ⊥-elim (x₁ ∅)
¬∉→∈ {𝑨} {𝐴} {x} {✓ {x₀ = x₀} {x₁s = ∅} ∅} x₂ = {!⊥-elim!}
¬∉→∈ {𝑨} {𝐴} {x₁} {✓ {x₀ = x₂} {x₁s = ✓ {x₀ = x₀} {x₁s = x₁s} x} (● {x₀ = .x₀} x₃ {x₁s = .x₁s} x₄ .x)} x₅ = {!!}
pattern tail= x₁s = ✓ {x₁s = x₁s} _
pattern 𝕃⟦_⟧ x₀ = ✓ {x₀ = x₀} ∅
pattern _₀∷₁_∷⟦_⟧ x₀ x₁ x₂s = ✓ {x₀ = x₀} (● {x₁} _ {x₂s} _ _)
--{-# DISPLAY ✓ {x₀ = x₀} (● {x₁} _ {x₂s} _ _) = _₀∷₁_∷⟦_⟧ x₀ x₁ x₂s #-}
pattern _↶_↷_ x₀∉x₂s x₀≢x₁ x₁∉x₂s = ● x₀≢x₁ x₀∉x₂s x₁∉x₂s
pattern _₀∷₁⟦_⟧ x₀ x₁s = ● {x₀} _ {x₁s} _ _
instance Membership𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} → Membership 𝐴 (𝕃 𝐴)
Membership._∉_ Membership𝕃 x xs = x ∉𝕃 xs
Membership._∈_ Membership𝕃 x xs = ¬ x ∉𝕃 xs
fst (Membership.xor-membership Membership𝕃) x₁ x₂ = x₁ x₂
snd (Membership.xor-membership Membership𝕃) x₁ x₂ = x₂ x₁
{-# DISPLAY _∉𝕃_ = _∉_ #-}
add-1-preserves-∈𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} {x₀ : 𝐴} {x₁s : 𝕃 𝐴} (x₀∉x₁s : x₀ ∉ x₁s) {x : 𝐴} → x ∈ x₁s → x ∈ ✓ x₀∉x₁s
add-1-preserves-∈𝕃 x₀∉x₁s x₁ (● x₃ x₄ x₂) = x₁ x₄
--{-# DISPLAY #-}
_∉𝕃?_ : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ → (x : 𝐴) (xs : 𝕃 𝐴) → Dec (x ∉𝕃 xs)
_∉𝕃?_ x ∅ = yes ∅
_∉𝕃?_ x 𝕃⟦ x₀ ⟧ with x ≟ x₀
… | yes refl = no λ {(● x₂ _ .∅) → x₂ refl}
… | no x≢x₀ = yes (● x≢x₀ ∅ ∅)
_∉𝕃?_ x (✓ {x₀ = x₀} (● {x₁} x₀≢x₁ {x₂s} x₀∉x₂s x₁∉x₂s)) with x ≟ x₀
… | yes refl = no λ { (● x₃ _ _) → x₃ refl}
… | no x≢x₀ with x ≟ x₁
… | yes refl = no λ { ((_ ↶ x≢x ↷ _) ↶ _ ↷ _) → x≢x refl }
… | no x≢x₁ with x ∉𝕃? x₂s
_∉𝕃?_ x₁ (✓ {x₂} (● {x₀} x₃ {.∅} x₄ x₀∉x₁s)) | no x≢x₀ | (no x≢x₁) | (yes ∅) = yes (● x≢x₀ (● x≢x₁ ∅ x₀∉x₁s) (● _ _ x₀∉x₁s))
_∉𝕃?_ x₁ (✓ {x₄} (● {x₃} x₅ {.(✓ asdf)} x₆ x₀∉x₁s)) | no x≢x₀ | (no x≢x₁) | (yes (● x₂ asdf₁ asdf)) = yes (● x≢x₀ (● x≢x₁ (● x₂ asdf₁ asdf) x₀∉x₁s) (● x₅ x₆ x₀∉x₁s))
… | no x∈x₂s = no λ { (● {_} x₃ {.(✓ x₁∉x₂s)} (● x₄ x∉x₀s .x₁∉x₂s) .(● x₀≢x₁ x₀∉x₂s x₁∉x₂s)) → x∈x₂s x∉x₀s}
instance DecidableMembership𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ → DecidableMembership 𝐴 (𝕃 𝐴)
DecidableMembership._∉?_ DecidableMembership𝕃 = _∉𝕃?_
DecidableMembership._∈?_ DecidableMembership𝕃 x X with _∉𝕃?_ x X
… | yes x∉X = no (λ x₁ → x₁ x∉X)
… | no x∈X = yes x∈X
x∈singleton→x=singleton : ∀ {𝑨} {𝐴 : Set 𝑨} {x₀ : 𝐴} ⦃ _ : Eq 𝐴 ⦄ {x₀∉∅ : _∉_ ⦃ Membership𝕃 ⦄ x₀ 𝕃.∅} {x : 𝐴} → x ∈ ✓ x₀∉∅ → x ≡ x₀
x∈singleton→x=singleton {𝑨} {𝐴} {x₀} {∅} {x} x₁ with x ≟ x₀
x∈singleton→x=singleton {𝑨} {𝐴} {x₀} {∅} {x} x₁ | yes refl = refl
x∈singleton→x=singleton {𝑨} {𝐴} {x₀} {∅} {x} x∈x₀ | no x≢x₀ = ⊥-elim (x∈x₀ (● x≢x₀ ∅ ∅))
foo₄ : (𝑨 : Level )
(𝐴 : Set 𝑨 )
(x₁ : 𝐴 )
(x₂s : 𝕃 𝐴 )
(x₁∉x₂s : x₁ ∉ x₂s )
(x₀ : 𝐴 )
(x₀≢x₁ : x₀ ≡ x₁ → ⊥ )
(x₀∉x₂s : x₀ ∉ x₂s )
(x : 𝐴 )
(x∈x₀∉x₁s : x ∉ ✓ (● x₀≢x₁ x₀∉x₂s x₁∉x₂s) → ⊥ )
(x≢x₀ : x ≡ x₀ → ⊥ )
(x≢x₁ : x ≡ x₁ → ⊥ )
(x∉x₂s : x ∉ x₂s )
(x₂ : x ≡ x₀ ) → ⊥
foo₄ 𝑨 𝐴 x₁ x₂s x₁∉x₂s x₀ x₀≢x₁ x₀∉x₂s .x₀ x∈x₀∉x₁s x≢x₀ x≢x₁ x∉x₂s refl = x≢x₀ refl
if-diff-then-somewhere-else-∈𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ {x₀ : 𝐴} (x₁s : 𝕃 𝐴) {x₀∉x₁s : x₀ ∉ x₁s} {x : 𝐴} → x ∈ ✓ x₀∉x₁s → x ≢ x₀ → x ∈ x₁s
if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} ∅ {∅} {x} x∈x₀∉∅ x≢x₀ ∅ = x≢x₀ (x∈singleton→x=singleton x∈x₀∉∅)
if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} (✓ {x₀ = x₁} {x₁s = x₂s} x₁∉x₂s) {● x₀≢x₁ x₀∉x₂s ._} {x} x∈x₀∉x₁s x≢x₀ (● x≢x₁ x∉x₂s _) = x∈x₀∉x₁s (● (λ {x₂ → foo₄ 𝑨 𝐴 x₁ x₂s x₁∉x₂s x₀ x₀≢x₁ x₀∉x₂s _ x∈x₀∉x₁s x≢x₀ x≢x₁ x∉x₂s x₂}) (● x≢x₁ x∉x₂s x₁∉x₂s) (● x₀≢x₁ x₀∉x₂s x₁∉x₂s))
--if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} .∅ {x₀∉x₁s} {x} x∈x₀s x≢x₀ ∅ = {!!}
--if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} ._ {x₀∉x₁s} {x} x∈x₀s x≢x₀ (● {x₀ = x₁} x≢x₁ {x₁s = x₂s} x∉x₂s x₁∉x₂s) = {!!}
record TotalUnion {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set ℓ
where
field
union : M → M → M
unionLaw1 : ∀ {x : m} {X₁ X₂ : M} → x ∈ X₁ → x ∈ union X₁ X₂
unionLaw2 : ∀ {x : m} {X₁ X₂ : M} → x ∈ X₂ → x ∈ union X₁ X₂
unionLaw3 : ∀ {x : m} {X₁ X₂ : M} → x ∈ union X₁ X₂ → x ∈ X₁ ⊎ x ∈ X₂
open TotalUnion ⦃ … ⦄
{-# DISPLAY TotalUnion.union _ = union #-}
add1-then-∈𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ {x₀ : 𝐴} (x₁s : 𝕃 𝐴) {x₀∉x₁s : x₀ ∉ x₁s} → x₀ ∈ ✓ {x₀ = x₀} x₀∉x₁s
add1-then-∈𝕃 {𝑨} {𝐴} {{x}} {x₀} x₁s {.x₁} (● {x₀ = .x₀} x₂ {x₁s = .x₁s} x₃ x₁) = x₂ refl
module ModuleTotalUnion𝕃 {ℓ} (A : Set ℓ) ⦃ _ : Eq A ⦄ where
-- TODO aribtrarily moves from l₀s to r₀s, so a union of 10 and 2 elements takes longer than a union of 2 and 10 elements
totalUnion : 𝕃 A → 𝕃 A → 𝕃 A
totalUnion ∅ ∅ = ∅
totalUnion ∅ r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) = r₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) ∅ = l₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) with l₀ ∉? r₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) | no l₀∈r₀s = totalUnion l₁s r₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) | yes l₀∉r₀s = totalUnion l₁s (✓ l₀∉r₀s)
totalUnionLaw2 : ∀ {x : A} {X₁ X₂ : 𝕃 A} → x ∈ X₂ → x ∈ totalUnion X₁ X₂
totalUnionLaw2 {x₁} {∅} {∅} x₂ x₃ = x₂ x₃
totalUnionLaw2 {x₁} {∅} {✓ x₂} x₃ x₄ = x₃ x₄
totalUnionLaw2 {x₁} {✓ x₂} {∅} x₃ x₄ = x₃ ∅
totalUnionLaw2 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈r₀s x∉l₀s∪r₀s with l₀ ∉? r₀s
totalUnionLaw2 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈r₀s x∉l₀s∪r₀s | no l₀∈r₀s = totalUnionLaw2 {X₁ = l₁s} x∈r₀s $ x∉l₀s∪r₀s
totalUnionLaw2 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈r₀s x∉l₀s∪r₀s | yes l₀∉r₀s = (totalUnionLaw2 {X₁ = l₁s} $ add-1-preserves-∈𝕃 l₀∉r₀s x∈r₀s) $ x∉l₀s∪r₀s
totalUnionLaw1 : ∀ {x : A} {X₁ X₂ : 𝕃 A} → x ∈ X₁ → x ∈ totalUnion X₁ X₂
totalUnionLaw1 {x₁} {∅} {∅} x₂ x₃ = x₂ x₃
totalUnionLaw1 {x₁} {∅} {✓ {x₀ = x₀} {x₁s = X₂} x₂} x₃ x₄ = x₃ ∅
totalUnionLaw1 {x₁} {✓ {x₀ = x₀} {x₁s = X₁} x₂} {∅} x₃ x₄ = x₃ x₄
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s with l₀ ∉? r₀s
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | no l₀∈r₀s with x ≟ l₀
totalUnionLaw1 {.l₀} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | no l₀∈r₀s | yes refl = totalUnionLaw2 {X₁ = l₁s} l₀∈r₀s $ x∉l₀s∪r₀s
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | no l₀∈r₀s | no x≢l₀ = let x∈l₁s = if-diff-then-somewhere-else-∈𝕃 l₁s x∈l₀s x≢l₀ in totalUnionLaw1 x∈l₁s $ x∉l₀s∪r₀s
-- with x ≟ l₀
-- = {!!}
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | yes l₀∉r₀s with x ≟ l₀
--totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} l₀∈l₀s l₀∉l₀s∪r₀s | yes l₀∉r₀s | yes refl = {!l₀∉r₀s!}
totalUnionLaw1 {.l₀} {✓ {l₀} {l₁s} l₀∉l₁s} {✓ {r₀} {r₁s} r₀∉r₁s} l₀∈l₀s l₀∉l₁s∪l₀r₀s | yes (● l₀≢r₀ l₀∉r₁s .r₀∉r₁s) | (yes refl) =
let l₀∈l₀r₀s : l₀ ∈ (✓ (● l₀≢r₀ l₀∉r₁s r₀∉r₁s))
l₀∈l₀r₀s = add1-then-∈𝕃 (✓ r₀∉r₁s)
in totalUnionLaw2 {X₁ = l₁s} l₀∈l₀r₀s $ l₀∉l₁s∪l₀r₀s
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | yes l₀∉r₀s | no x≢l₀ = let x∈l₁s = if-diff-then-somewhere-else-∈𝕃 l₁s x∈l₀s x≢l₀ in totalUnionLaw1 x∈l₁s $ x∉l₀s∪r₀s
totalUnionLaw3 : ∀ {x : A} {X₁ X₂ : 𝕃 A} → x ∈ totalUnion X₁ X₂ → x ∈ X₁ ⊎ x ∈ X₂
totalUnionLaw3 = {!!}
instance TotalUnion𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ → TotalUnion 𝐴 (𝕃 𝐴)
TotalUnion.union TotalUnion𝕃 = ModuleTotalUnion𝕃.totalUnion _
TotalUnion.unionLaw1 TotalUnion𝕃 = ModuleTotalUnion𝕃.totalUnionLaw1 _
TotalUnion.unionLaw2 (TotalUnion𝕃 {𝑨} {𝐴} {{x}}) {x₁} {X₁} {X₂} x₂ x₃ = ModuleTotalUnion𝕃.totalUnionLaw2 𝐴 {X₁ = X₁} {X₂ = X₂} x₂ x₃
TotalUnion.unionLaw3 TotalUnion𝕃 = ModuleTotalUnion𝕃.totalUnionLaw3 _
mutual
data FTerm : 𝕃 VariableName → Set
where
variable : (𝑥 : VariableName) → FTerm (𝕃⟦ 𝑥 ⟧)
function : (𝑓 : FunctionName) → ..{𝑥s : 𝕃 VariableName} {arity : Nat} → (τs : FTerms 𝑥s arity) → FTerm 𝑥s
data FTerms : 𝕃 VariableName → Nat → Set
where
[] : FTerms ∅ zero
_∷_ : ∀ ..{𝑥s' 𝑥s : 𝕃 VariableName} → FTerm 𝑥s' → {n : Nat} → FTerms 𝑥s n → FTerms (union {m = VariableName} 𝑥s' 𝑥s) (⊹ n)
instance MembershipVariableNameFTerm : ∀ {𝑥s} → Membership VariableName (FTerm 𝑥s)
MembershipVariableNameFTerm = {!!}
record TotalIntersection {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set ℓ
where
field
intersection : M → M → M
intersectionLaw1 : ∀ {x : m} {X₁ X₂ : M} → x ∈ intersection X₁ X₂ → x ∈ X₁
intersectionLaw2 : ∀ {x : m} {X₁ X₂ : M} → x ∈ intersection X₁ X₂ → x ∈ X₂
intersectionLaw3 : ∀ {x : m} {X₁ X₂ : M} → x ∈ X₁ × x ∈ X₂ → x ∈ intersection X₁ X₂
open TotalIntersection ⦃ … ⦄
{-# DISPLAY TotalIntersection.intersection _ = intersection #-}
instance Intersection𝕃 : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → TotalIntersection A (𝕃 A)
Intersection𝕃 = {!!}
data HasUniqueValues (A : Set) : List A → Set
where
[] : HasUniqueValues A []
_∷_ : {x : A} → {xs : List A} → x ∉ xs → (uxs : HasUniqueValues A xs) → HasUniqueValues A (x ∷ xs)
record AList (A : Set) (B : Set) : Set
where
field
domain : List A
uniquedomain : HasUniqueValues A domain
range : ∀ {x : A} → x ∈ domain → B
open AList
mutual
subst : AList VariableName (∃ FTerm) → ∃ FTerm → ∃ FTerm
subst x t@(.(✓ ∅) , variable 𝑥) with 𝑥 ∈? domain x
… | yes x∈D = range x x∈D
… | no x∉D = t
subst x (fst₁ , function 𝑓 {𝑥s = 𝑥s} {arity = a} τs) with substs x a (𝑥s , τs)
subst x (fst₁ , function 𝑓 {.fst₁} {arity₁} τs) | fst₂ , snd₁ = fst₂ , (function 𝑓 snd₁)
substs : AList VariableName (∃ FTerm) → (a : Nat) → ∃ (flip FTerms a) → ∃ (flip FTerms a)
substs x .0 (.∅ , []) = ∅ , []
substs x .(suc _) (._ , (x₁ ∷ snd₁)) with {!subst x (_ , x₁)!}
substs x .(suc _) (._ , (x₁ ∷ snd₁)) | sb = {!!}
-- indexed by the number of function symbols contained
data DTerm : Nat → Set
where
variable : (𝑥 : VariableName) → DTerm zero
function : (𝑓 : FunctionName) → {arity : Nat} → (τs : Vec (∃ DTerm) arity) → DTerm (suc (sum (fst <$> vecToList τs)))
mutual
substD : VariableName → ∃ DTerm → {n : Nat} → DTerm n → ∃ DTerm
substD x x₁ (variable 𝑥) = ifYes 𝑥 ≟ x then x₁ else _ , variable 𝑥
substD x x₁ (function 𝑓 τs) with substsD x x₁ τs
substD x x₁ (function 𝑓 τs) | ss = suc (sum (fst <$> vecToList ss)) , function 𝑓 {_} ss
substsD : VariableName → ∃ DTerm → {n : Nat} → Vec (Σ Nat DTerm) n → Vec (Σ Nat DTerm) n
substsD x x₁ [] = []
substsD x x₁ (x₂ ∷ x₃) with substD x x₁ (snd x₂) | substsD x x₁ x₃
substsD x x₁ (x₂ ∷ x₃) | fst₁ , snd₁ | sss = (fst₁ , snd₁) ∷ sss
data HDTerm : Set where
⟨_⟩ : {n : Nat} → DTerm n → HDTerm
substituteD : (AList VariableName HDTerm) → HDTerm → HDTerm
substituteD = {!!}
amgu : HDTerm → HDTerm → (AList VariableName HDTerm) → Maybe (AList VariableName HDTerm)
amgu ⟨ variable 𝑥 ⟩ ⟨ variable 𝑥₁ ⟩ f = {!!}
amgu ⟨ variable 𝑥 ⟩ ⟨ function 𝑓 τs ⟩ f = {!!}
amgu ⟨ function 𝑓 τs ⟩ ⟨ variable 𝑥 ⟩ f = {!!}
amgu ⟨ function 𝑓 τs₁ ⟩ ⟨ function 𝑓₁ τs ⟩ f = {!!}
-- {-
-- data AList : 𝕃 VariableName → Set
-- where
-- [] : AList ∅
-- _∷_ :
-- -}
-- record JohnUnification {𝑥s₁} (τ₁ : FTerm 𝑥s₁) {𝑥s₂} (τ₂ : FTerm 𝑥s₂) (_ : intersection {m = VariableName} 𝑥s₁ 𝑥s₂ ≡ ∅) : Set where
-- field
-- u₁ u₂ : AList VariableName (∃ FTerm)
-- unification-law₁ : fst (subst u₁ (𝑥s₁ , τ₁)) ≡ fst (subst u₂ (𝑥s₂ , τ₂))
-- unification-law₂ : snd (subst u₁ (𝑥s₁ , τ₁)) ≡ transport FTerm (sym unification-law₁) (snd (subst u₂ (𝑥s₂ , τ₂)))
-- record UnificationEquation (𝑥s : 𝕃 VariableName) : Set
-- where
-- field
-- {lhs-terms} : 𝕃 VariableName
-- lhs : FTerm lhs-terms
-- {rhs-terms} : 𝕃 VariableName
-- rhs : FTerm rhs-terms
-- lhs∪rhs-terms : 𝑥s ≡ union {m = VariableName} lhs-terms rhs-terms
-- open UnificationEquation
-- number-of-variables-that-occur-more-than-once : ∀ {n-eqn} → Vec (∃ λ 𝑥s → UnificationEquation 𝑥s) n-eqn → Nat
-- number-of-variables-that-occur-more-than-once {zero} [] = 0
-- number-of-variables-that-occur-more-than-once {suc n-eqn} x = {!!}
-- number-of-function-symbols : ∀ {𝑥s} → FTerm 𝑥s → Nat
-- number-of-function-symbols = {!!}
-- record UnificationProblem (n-var n-lhs n-eqn : Nat) : Set
-- where
-- field
-- equations : Vec (∃ λ 𝑥s → UnificationEquation 𝑥s) n-eqn
-- n-var-law : number-of-variables-that-occur-more-than-once equations ≤ n-var
-- n-lhs-law : (sum ∘ vecToList $ number-of-function-symbols ∘ lhs ∘ snd <$> equations) ≤ n-lhs
-- instance MembershipUnificationEquationUnificationProblem : ∀ {n-var n-lhs n-eqn 𝑥s} → Membership (UnificationEquation 𝑥s) (UnificationProblem n-var n-lhs n-eqn)
-- MembershipUnificationEquationUnificationProblem = {!!}
-- instance MembershipVariableNameUnificationProblem : ∀ {n-var n-lhs n-eqn} → Membership VariableName (UnificationProblem n-var n-lhs n-eqn)
-- MembershipVariableNameUnificationProblem = {!!}
-- deletable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- deletable = {!!}
-- deletable? : ∀ {𝑥s} → (eq : UnificationEquation 𝑥s) → Dec (deletable eq)
-- deletable? = {!!}
-- u-deletable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → deletable εq × εq ∈ up)
-- u-deletable? {n-var} {n-lhs} {zero} up = no {!!}
-- u-deletable? {n-var} {n-lhs} {suc n-eqn} up = {!!}
-- deleteRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var n-lhs (suc n-eqn)} {𝑥s} {εq : UnificationEquation 𝑥s} → deletable εq → εq ∈ up → UnificationProblem n-var n-lhs n-eqn
-- deleteRule = {!!}
-- decomposable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- decomposable = {!!}
-- decomposable? : ∀ {𝑥s} → (eq : UnificationEquation 𝑥s) → Dec (decomposable eq)
-- decomposable? = {!!}
-- u-decomposable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var (suc n-lhs) n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → decomposable εq × εq ∈ up)
-- u-decomposable? = {!!}
-- decomposeRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var (suc n-lhs) n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → decomposable εq → εq ∈ up → UnificationProblem n-var n-lhs n-eqn
-- decomposeRule = {!!}
-- swapable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- swapable = {!!}
-- swapable? : ∀ {𝑥s} → (eq : UnificationEquation 𝑥s) → Dec (swapable eq)
-- swapable? = {!!}
-- u-swapable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var (suc n-lhs) n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → swapable εq × εq ∈ up)
-- u-swapable? = {!!}
-- swapRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var (suc n-lhs) n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → swapable εq → εq ∈ up → UnificationProblem n-var n-lhs n-eqn
-- swapRule = {!!}
-- eliminatable : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var n-lhs n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → (εq∈up : εq ∈ up) → Set
-- eliminatable = {!!}
-- u-eliminatable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem (suc n-var) n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → ∃ λ (εq∈up : εq ∈ up) → eliminatable {up = up} {εq = εq} εq∈up)
-- u-eliminatable? = {!!}
-- eliminateRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem (suc n-var) n-lhs n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → {εq∈up : εq ∈ up} → eliminatable {up = up} {εq = εq} εq∈up → UnificationProblem n-var n-lhs n-eqn
-- eliminateRule = {!!}
-- conflictable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- conflictable = {!!}
-- conflictable? : ∀ {𝑥s} → (εq : UnificationEquation 𝑥s) → Dec (conflictable εq)
-- conflictable? = {!!}
-- u-conflictable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → conflictable εq × εq ∈ up)
-- u-conflictable? = {!!}
-- checkable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- checkable = {!!}
-- checkable? : ∀ {𝑥s} → (εq : UnificationEquation 𝑥s) → Dec (checkable εq)
-- checkable? = {!!}
-- u-checkable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → checkable εq × εq ∈ up)
-- u-checkable? = {!!}
-- record HasNegation (A : Set) : Set
-- where
-- field
-- ~ : A → A
-- open HasNegation ⦃ … ⦄
-- {-# DISPLAY HasNegation.~ _ = ~ #-}
-- data Formula : Set
-- where
-- atomic : PredicateName → Terms → Formula
-- logical : Formula →
-- Formula →
-- Formula
-- quantified : VariableName → Formula → Formula
-- formulaAtomic-inj₁ : ∀ {𝑃₁ τs₁ 𝑃₂ τs₂} → Formula.atomic 𝑃₁ τs₁ ≡ atomic 𝑃₂ τs₂ → 𝑃₁ ≡ 𝑃₂
-- formulaAtomic-inj₁ refl = refl
-- formulaAtomic-inj₂ : ∀ {𝑃₁ τs₁ 𝑃₂ τs₂} → Formula.atomic 𝑃₁ τs₁ ≡ atomic 𝑃₂ τs₂ → τs₁ ≡ τs₂
-- formulaAtomic-inj₂ refl = refl
-- formulaLogical-inj₁ : ∀ {φ₁₁ φ₁₂ φ₂₁ φ₂₂} → Formula.logical φ₁₁ φ₁₂ ≡ logical φ₂₁ φ₂₂ → φ₁₁ ≡ φ₂₁
-- formulaLogical-inj₁ refl = refl
-- formulaLogical-inj₂ : ∀ {φ₁₁ φ₁₂ φ₂₁ φ₂₂} → Formula.logical φ₁₁ φ₁₂ ≡ logical φ₂₁ φ₂₂ → φ₁₂ ≡ φ₂₂
-- formulaLogical-inj₂ refl = refl
-- formulaQuantified-inj₁ : ∀ {𝑥₁ φ₁ 𝑥₂ φ₂} → Formula.quantified 𝑥₁ φ₁ ≡ quantified 𝑥₂ φ₂ → 𝑥₁ ≡ 𝑥₂
-- formulaQuantified-inj₁ refl = refl
-- formulaQuantified-inj₂ : ∀ {𝑥₁ φ₁ 𝑥₂ φ₂} → Formula.quantified 𝑥₁ φ₁ ≡ quantified 𝑥₂ φ₂ → φ₁ ≡ φ₂
-- formulaQuantified-inj₂ refl = refl
-- instance EqFormula : Eq Formula
-- Eq._==_ EqFormula (atomic 𝑃₁ τs₁)
-- (atomic 𝑃₂ τs₂)
-- = decEq₂ formulaAtomic-inj₁
-- formulaAtomic-inj₂
-- (𝑃₁ ≟ 𝑃₂)
-- (τs₁ ≟ τs₂)
-- Eq._==_ EqFormula (logical φ₁₁ φ₁₂)
-- (logical φ₂₁ φ₂₂)
-- = decEq₂ formulaLogical-inj₁ formulaLogical-inj₂ (φ₁₁ ≟ φ₂₁) (φ₁₂ ≟ φ₂₂)
-- Eq._==_ EqFormula (quantified 𝑥₁ φ₁) (quantified 𝑥₂ φ₂) = decEq₂ formulaQuantified-inj₁ formulaQuantified-inj₂ (𝑥₁ ≟ 𝑥₂) (φ₁ ≟ φ₂)
-- Eq._==_ EqFormula (atomic _ _) (logical _ _) = no λ ()
-- Eq._==_ EqFormula (atomic _ _) (quantified _ _) = no λ ()
-- Eq._==_ EqFormula (logical _ _) (atomic _ _) = no λ ()
-- Eq._==_ EqFormula (logical _ _) (quantified _ _) = no λ ()
-- Eq._==_ EqFormula (quantified _ _) (atomic _ _) = no λ ()
-- Eq._==_ EqFormula (quantified _ _) (logical _ _) = no λ ()
-- data IsFormula : Formula → Set
-- where
-- ⟨_⟩ : (φ : Formula) → IsFormula φ
-- record 𝓕ormula (Is𝓕ormula : Formula → Set) : Set
-- where
-- constructor ⟨_⟩
-- field
-- {formula} : Formula
-- is𝓕ormula : Is𝓕ormula formula
-- open 𝓕ormula
-- 𝑃[_♭_] : PredicateName → Terms → Formula
-- 𝑃[_♭_] = atomic
-- {-# DISPLAY atomic = 𝑃[_♭_] #-}
-- record HasNeitherNor (A : Set) : Set
-- where
-- field
-- _⊗_ : A → A → A
-- open HasNeitherNor ⦃ … ⦄
-- instance HasNeitherNorFormula : HasNeitherNor Formula
-- HasNeitherNor._⊗_ HasNeitherNorFormula = logical
-- {-# DISPLAY logical = _⊗_ #-}
-- instance HasNegationFormula : HasNegation Formula
-- HasNegation.~ HasNegationFormula φ = φ ⊗ φ
-- data IsLiteralFormula : Formula → Set
-- where
-- atomic : (𝑃 : PredicateName) → (τs : Terms) → IsLiteralFormula $ 𝑃[ 𝑃 ♭ τs ]
-- logical : (𝑃 : PredicateName) → (τs : Terms) → IsLiteralFormula ∘ ~ $ 𝑃[ 𝑃 ♭ τs ]
-- eqIsLiteralFormula : ∀ {φ} → (lf₁ lf₂ : IsLiteralFormula φ) → lf₁ ≡ lf₂
-- eqIsLiteralFormula (atomic _ _) (atomic _ _) = refl
-- eqIsLiteralFormula (logical _ _) (logical _ _) = refl
-- instance EqIsLiteralFormula : ∀ {φ} → Eq (IsLiteralFormula φ)
-- Eq._==_ EqIsLiteralFormula lf₁ lf₂ = yes $ eqIsLiteralFormula lf₁ lf₂
-- record LiteralFormula : Set
-- where
-- constructor ⟨_⟩
-- field
-- {formula} : Formula
-- isLiteralFormula : IsLiteralFormula formula
-- open LiteralFormula
-- instance EqLiteralFormula : Eq LiteralFormula
-- Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂)
-- with φ₁ ≟ φ₂
-- … | no φ₁≢φ₂ = no (λ {refl → φ₁≢φ₂ refl})
-- Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂) | yes refl = case (eqIsLiteralFormula lf₁ lf₂) of λ {refl → yes refl}
-- instance HasNegationLiteralFormula : HasNegation LiteralFormula
-- HasNegation.~ HasNegationLiteralFormula ⟨ atomic 𝑃 τs ⟩ = ⟨ logical 𝑃 τs ⟩
-- HasNegation.~ HasNegationLiteralFormula ⟨ logical 𝑃 τs ⟩ = ⟨ atomic 𝑃 τs ⟩
-- data IsPropositionalFormula : Formula → Set
-- where
-- atomic : (𝑃 : PredicateName) → (τs : Terms) → IsPropositionalFormula $ 𝑃[ 𝑃 ♭ τs ]
-- logical : {φ₁ : Formula} → IsPropositionalFormula φ₁ → {φ₂ : Formula} → IsPropositionalFormula φ₂ → IsPropositionalFormula (φ₁ ⊗ φ₂)
-- instance EqIsPropositionalFormula : ∀ {φ} → Eq (IsPropositionalFormula φ)
-- Eq._==_ EqIsPropositionalFormula (atomic _ _) (atomic _ _ ) = yes refl
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) with φ₁₁ ≟ φ₂₁ | φ₁₂ ≟ φ₂₂
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) | yes refl | yes refl = yes refl
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) | yes refl | no φ₁₂≢φ₂₂ = no λ {refl → φ₁₂≢φ₂₂ refl}
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) | no φ₁₁≢φ₂₁ | _ = no λ {refl → φ₁₁≢φ₂₁ refl}
-- {-
-- -- need to use coinduction to prove this
-- foo : ¬ ∃ λ φ → ∃ λ (p₁ : IsPropositionalFormula φ) → ∃ λ (p₂ : IsPropositionalFormula φ) → p₁ ≢ p₂
-- foo (atomic x x₁ , atomic .x .x₁ , atomic .x .x₁ , snd₁) = snd₁ refl
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical fst₅ fst₆ , snd₁) with fst₃ ≟ fst₅ | fst₄ ≟ fst₆
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical .fst₃ .fst₄ , snd₁) | yes refl | (yes refl) = snd₁ refl
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical .fst₃ fst₆ , snd₁) | yes refl | (no x₁) = foo (fst₂ , fst₄ , fst₆ , λ xs → x₁ xs)
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical fst₅ fst₆ , snd₁) | no x | (yes x₁) = {!!}
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical fst₅ fst₆ , snd₁) | no x | (no x₁) = {!!}
-- foo (quantified x fst₁ , () , fst₃ , snd₁)
-- -}
-- record PropositionalFormula : Set
-- where
-- constructor ⟨_⟩
-- field
-- {formula} : Formula
-- isPropositionalFormula : IsPropositionalFormula formula
-- open PropositionalFormula
-- instance HasNegationPropositionalFormula : HasNegation PropositionalFormula
-- HasNegation.~ HasNegationPropositionalFormula ⟨ φ ⟩ = ⟨ logical φ φ ⟩
-- instance HasNeitherNorPropositionalFormula : HasNeitherNor PropositionalFormula
-- HasNeitherNor._⊗_ HasNeitherNorPropositionalFormula ⟨ φ₁ ⟩ ⟨ φ₂ ⟩ = ⟨ logical φ₁ φ₂ ⟩
-- {-# DISPLAY IsPropositionalFormula.logical = _⊗_ #-}
-- record 𝓐ssertion (A : Set) : Set
-- where
-- no-eta-equality
-- instance 𝓐ssertionList : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ → 𝓐ssertion (List A)
-- 𝓐ssertionList = record {}
-- instance 𝓐ssertionFormula : 𝓐ssertion Formula
-- 𝓐ssertionFormula = record {}
-- instance 𝓐ssertionLiteralFormula : 𝓐ssertion LiteralFormula
-- 𝓐ssertionLiteralFormula = record {}
-- infix 15 _⊢_
-- record 𝓢equent (A : Set) ⦃ _ : 𝓐ssertion A ⦄ : Set
-- where
-- constructor _⊢_
-- field
-- antecedents : List A
-- consequents : List A
-- open 𝓢equent ⦃ … ⦄
-- instance Eq𝓢equent : {A : Set} ⦃ _ : Eq A ⦄ ⦃ _ : 𝓐ssertion A ⦄ → Eq (𝓢equent A)
-- Eq._==_ Eq𝓢equent (antecedents₁ ⊢ consequents₁) (antecedents₂ ⊢ consequents₂) = {!antecedents₁ ≟ antecedents₂!}
-- instance 𝓐ssertion𝓢equent : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ → 𝓐ssertion (𝓢equent A)
-- 𝓐ssertion𝓢equent = record {}
-- instance 𝓐ssertion𝓕ormula : {Is𝓕ormula : Formula → Set} → 𝓐ssertion (𝓕ormula Is𝓕ormula)
-- 𝓐ssertion𝓕ormula = record {}
-- infix 15 _╱_
-- record Sequent : Set
-- where
-- constructor _╱_
-- field
-- statement : Formula
-- suppositions : List Formula
-- open Sequent
-- instance EqSequent : Eq Sequent
-- Eq._==_ EqSequent ( φᵗ₁ ╱ φˢs₁ ) ( φᵗ₂ ╱ φˢs₂ ) = decEq₂ (cong statement) (cong suppositions) (φᵗ₁ ≟ φᵗ₂) (φˢs₁ ≟ φˢs₂)
-- instance HasNegationSequent : HasNegation Sequent
-- HasNegation.~ HasNegationSequent ( φᵗ ╱ φˢs ) = ~ φᵗ ╱ φˢs
-- record IsLiteralSequent (Φ : Sequent) : Set
-- where
-- constructor _╱_
-- field
-- isLiteralStatement : IsLiteralFormula (statement Φ)
-- isLiteralSuppositions : All IsLiteralFormula (suppositions Φ)
-- open IsLiteralSequent
-- instance EqIsLiteralSequent : ∀ {Φ} → Eq (IsLiteralSequent Φ)
-- Eq._==_ EqIsLiteralSequent ( φᵗ₁ ╱ φˢs₁ ) ( φᵗ₂ ╱ φˢs₂ ) = decEq₂ (cong isLiteralStatement) (cong isLiteralSuppositions) (φᵗ₁ ≟ φᵗ₂) (φˢs₁ ≟ φˢs₂)
-- record LiteralSequent : Set
-- where
-- constructor ⟨_⟩
-- field
-- {sequent} : Sequent
-- isLiteralSequent : IsLiteralSequent sequent
-- open LiteralSequent
-- pattern ⟪_,_⟫ h s = ⟨_⟩ {h} s
-- pattern ⟪_⟫ h = (⟨_⟩ {h} _)
-- instance EqLiteralSequent : Eq LiteralSequent
-- Eq._==_ EqLiteralSequent ⟪ Φ₁ ⟫ ⟪ Φ₂ ⟫ with Φ₁ ≟ Φ₂
-- Eq._==_ EqLiteralSequent ⟨ !Φ₁ ⟩ ⟨ !Φ₂ ⟩ | yes refl with !Φ₁ ≟ !Φ₂
-- Eq._==_ EqLiteralSequent _ _ | yes refl | yes refl = yes refl
-- Eq._==_ EqLiteralSequent ⟨ Φ₁ ⟩ ⟨ Φ₂ ⟩ | yes refl | no !Φ₁≢!Φ₂ = no λ {refl → !Φ₁≢!Φ₂ refl}
-- Eq._==_ EqLiteralSequent ⟨ Φ₁ ⟩ ⟨ Φ₂ ⟩ | no Φ₁≢Φ₂ = no λ {refl → Φ₁≢Φ₂ refl}
-- instance HasNegationLiteralSequent : HasNegation LiteralSequent
-- HasNegation.~ HasNegationLiteralSequent ⟨ atomic 𝑃 τs ╱ φˢs ⟩ = ⟨ logical 𝑃 τs ╱ φˢs ⟩
-- HasNegation.~ HasNegationLiteralSequent ⟨ logical 𝑃 τs ╱ φˢs ⟩ = ⟨ atomic 𝑃 τs ╱ φˢs ⟩
-- infix 13 _¶_
-- record Problem : Set
-- where
-- constructor _¶_
-- field
-- inferences : List Sequent
-- interest : Sequent
-- open Problem
-- instance EqProblem : Eq Problem
-- EqProblem = {!!}
-- record IsLiteralProblem (𝔓 : Problem) : Set
-- where
-- constructor _¶_
-- field
-- {problem} : Problem
-- isLiteralInferences : All IsLiteralSequent (inferences 𝔓)
-- isLiteralInterest : IsLiteralSequent (interest 𝔓)
-- open IsLiteralProblem
-- instance EqIsLiteralProblem : ∀ {𝔓} → Eq (IsLiteralProblem 𝔓)
-- EqIsLiteralProblem = {!!}
-- record LiteralProblem : Set
-- where
-- constructor ⟨_⟩
-- field
-- {problem} : Problem
-- isLiteralProblem : IsLiteralProblem problem
-- open LiteralProblem
-- instance EqLiteralProblem : Eq LiteralProblem
-- EqLiteralProblem = {!!}
-- record Element : Set
-- where
-- constructor ⟨_⟩
-- field
-- element : Nat
-- instance EqElement : Eq Element
-- Eq._==_ EqElement ⟨ ε₁ ⟩ ⟨ ε₂ ⟩ with ε₁ ≟ ε₂
-- Eq._==_ EqElement ⟨ _ ⟩ ⟨ _ ⟩ | yes refl = yes refl
-- Eq._==_ EqElement ⟨ _ ⟩ ⟨ _ ⟩ | no ε₁≢ε₂ = no λ {refl → ε₁≢ε₂ refl}
-- record Elements : Set
-- where
-- constructor ⟨_⟩
-- field
-- {arity} : Arity
-- elements : Vector Element arity
-- open Elements
-- instance EqElements : Eq Elements
-- Eq._==_ EqElements (⟨_⟩ {𝑎₁} εs₁) (⟨_⟩ {𝑎₂} εs₂)
-- with 𝑎₁ ≟ 𝑎₂
-- … | no 𝑎₁≢𝑎₂ = no λ {refl → 𝑎₁≢𝑎₂ refl}
-- … | yes refl
-- with εs₁ ≟ εs₂
-- … | yes refl = yes refl
-- … | no εs₁≢εs₂ = no λ {refl → εs₁≢εs₂ refl}
-- record TruthValue : Set
-- where
-- constructor ⟨_⟩
-- field
-- truthValue : Bool
-- record Interpretation : Set
-- where
-- field
-- μ⟦_⟧ : VariableName → Element
-- 𝑓⟦_⟧ : FunctionName → Elements → Element
-- 𝑃⟦_⟧ : PredicateName → Elements → TruthValue
-- open Interpretation
-- mutual
-- τ⇑⟦_⟧ : Interpretation → {i : Size} → Term → Delay i Element
-- τ⇑⟦ I ⟧ (variable 𝑥) = now $ μ⟦ I ⟧ 𝑥
-- τ⇑⟦ I ⟧ (function 𝑓 τs) = 𝑓⟦ I ⟧ 𝑓 ∘ ⟨_⟩ <$> τs⇑⟦ I ⟧ τs
-- τs⇑⟦_⟧ : Interpretation → {i : Size} → (τs : Terms) → Delay i (Vector Element (arity τs))
-- τs⇑⟦ I ⟧ ⟨ ⟨ [] ⟩ ⟩ = now ⟨ [] ⟩
-- τs⇑⟦ I ⟧ ⟨ ⟨ τ ∷ τs ⟩ ⟩ = τ⇑⟦ I ⟧ τ >>= (λ t → τs⇑⟦ I ⟧ ⟨ ⟨ τs ⟩ ⟩ >>= λ ts → now ⟨ t ∷ vector ts ⟩)
-- τs⇓⟦_⟧ : (I : Interpretation) → (τs : Terms) → τs⇑⟦ I ⟧ τs ⇓
-- τs⇓⟦ I ⟧ ⟨ ⟨ [] ⟩ ⟩ = _ , now⇓
-- τs⇓⟦ I ⟧ ⟨ ⟨ variable 𝑥 ∷ τs ⟩ ⟩ = _ , τs⇓⟦ I ⟧ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ now⇓
-- τs⇓⟦ I ⟧ ⟨ ⟨ function 𝑓₁ τs₁ ∷ τs₂ ⟩ ⟩ =
-- _ , τs⇓⟦ I ⟧ τs₁ ⇓>>=⇓ now⇓ >>=⇓ (τs⇓⟦ I ⟧ ⟨ ⟨ τs₂ ⟩ ⟩ ⇓>>=⇓ now⇓)
-- τ⇓⟦_⟧ : (I : Interpretation) → (τ : Term) → τ⇑⟦ I ⟧ τ ⇓
-- τ⇓⟦ I ⟧ (variable 𝑥) = _ , now⇓
-- τ⇓⟦ I ⟧ (function 𝑓 τs) = _ , τs⇓⟦ I ⟧ τs ⇓>>=⇓ now⇓
-- τ⟦_⟧ : (I : Interpretation) → {i : Size} → (τ : Term) → Element
-- τ⟦ I ⟧ τ = fst (τ⇓⟦ I ⟧ τ)
-- record HasSatisfaction (A : Set) ⦃ _ : 𝓐ssertion A ⦄ : Set₁
-- where
-- field
-- _⊨_ : Interpretation → A → Set
-- _⊭_ : Interpretation → A → Set
-- _⊭_ I = ¬_ ∘ I ⊨_
-- open HasSatisfaction ⦃ … ⦄
-- {-# DISPLAY HasSatisfaction._⊨_ _ = _⊨_ #-}
-- {-# DISPLAY HasSatisfaction._⊭_ _ = _⊭_ #-}
-- record _≞_/_ (𝓘 : Interpretation) (I : Interpretation) (𝑥 : VariableName) : Set
-- where
-- field
-- μEquality : {𝑥′ : VariableName} → 𝑥′ ≢ 𝑥 → μ⟦ 𝓘 ⟧ 𝑥 ≡ μ⟦ I ⟧ 𝑥′
-- 𝑓Equality : (𝑓 : FunctionName) (μs : Elements) → 𝑓⟦ 𝓘 ⟧ 𝑓 μs ≡ 𝑓⟦ I ⟧ 𝑓 μs
-- 𝑃Equality : (𝑃 : PredicateName) → (μs : Elements) → 𝑃⟦ 𝓘 ⟧ 𝑃 μs ≡ 𝑃⟦ I ⟧ 𝑃 μs
-- instance HasSatisfactionFormula : HasSatisfaction Formula
-- HasSatisfaction._⊨_ HasSatisfactionFormula I (atomic 𝑃 τs) = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ true ⟩
-- HasSatisfaction._⊨_ HasSatisfactionFormula I (logical φ₁ φ₂) = ¬ I ⊨ φ₁ × ¬ I ⊨ φ₂
-- HasSatisfaction._⊨_ HasSatisfactionFormula I (quantified 𝑥 φ) = (𝓘 : Interpretation) → 𝓘 ≞ I / 𝑥 → 𝓘 ⊨ φ
-- instance HasSatisfaction𝓕ormula : {Is𝓕ormula : Formula → Set} → HasSatisfaction (𝓕ormula Is𝓕ormula)
-- HasSatisfaction._⊨_ HasSatisfaction𝓕ormula I ⟪ φ ⟫ = I ⊨ φ
-- instance HasSatisfactionLiteralFormula : HasSatisfaction LiteralFormula
-- HasSatisfaction._⊨_ HasSatisfactionLiteralFormula I ⟨ atomic 𝑃 τs ⟩ = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ true ⟩
-- HasSatisfaction._⊨_ HasSatisfactionLiteralFormula I ⟨ logical 𝑃 τs ⟩ = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ false ⟩
-- instance HasSatisfactionList : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ → HasSatisfaction $ List A
-- HasSatisfaction._⊨_ HasSatisfactionList I [] = ⊤
-- HasSatisfaction._⊨_ HasSatisfactionList I (x ∷ xs) = I ⊨ x × I ⊨ xs
-- instance 𝓐ssertionSequent : 𝓐ssertion Sequent
-- 𝓐ssertionSequent = record {}
-- instance 𝓐ssertionLiteralSequent : 𝓐ssertion LiteralSequent
-- 𝓐ssertionLiteralSequent = record {}
-- instance 𝓐ssertionProblem : 𝓐ssertion Problem
-- 𝓐ssertionProblem = record {}
-- instance 𝓐ssertionLiteralProblem : 𝓐ssertion LiteralProblem
-- 𝓐ssertionLiteralProblem = record {}
-- instance HasSatisfactionSequent : HasSatisfaction Sequent
-- HasSatisfaction._⊨_ HasSatisfactionSequent I (φᵗ ╱ φˢs) = I ⊨ φˢs → I ⊨ φᵗ
-- instance HasSatisfactionLiteralSequent : HasSatisfaction LiteralSequent
-- HasSatisfaction._⊨_ HasSatisfactionLiteralSequent I Φ = I ⊨ sequent Φ
-- instance HasSatisfactionProblem : HasSatisfaction Problem
-- HasSatisfaction._⊨_ HasSatisfactionProblem I (Φ⁺s ¶ Φ⁻) = I ⊨ Φ⁺s → I ⊨ Φ⁻
-- instance HasSatisfactionLiteralProblem : HasSatisfaction LiteralProblem
-- HasSatisfaction._⊨_ HasSatisfactionLiteralProblem I 𝔓 = I ⊨ problem 𝔓
-- record HasDecidableSatisfaction (A : Set) ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ : Set₁
-- where
-- field
-- _⊨?_ : (I : Interpretation) → (x : A) → Dec (I ⊨ x)
-- open HasDecidableSatisfaction ⦃ … ⦄
-- {-# DISPLAY HasDecidableSatisfaction._⊨?_ _ = _⊨?_ #-}
-- instance HasDecidableSatisfactionFormula : HasDecidableSatisfaction Formula
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionFormula I (atomic 𝑃 τs) = {!!}
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionFormula I (logical φ₁ φ₂) = {!!}
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionFormula I (quantified 𝑥 φ) = {!!}
-- instance HasDecidableSatisfactionLiteralFormula : HasDecidableSatisfaction LiteralFormula
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionLiteralFormula
-- I ⟨ atomic 𝑃 τs ⟩
-- with 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩
-- … | ⟨ true ⟩ = yes refl
-- … | ⟨ false ⟩ = no λ ()
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionLiteralFormula
-- I ⟨ logical 𝑃 τs ⟩
-- with 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩
-- … | ⟨ true ⟩ = no λ ()
-- … | ⟨ false ⟩ = yes refl
-- module _ {A} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄
-- where
-- ⊨_ : A → Set
-- ⊨ x = (I : Interpretation) → I ⊨ x
-- ⊭_ : A → Set
-- ⊭_ = ¬_ ∘ ⊨_
-- record HasDecidableValidation (A : Set) ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ : Set₁
-- where
-- field
-- ⊨?_ : (x : A) → Dec $ ⊨ x
-- instance HasDecidableValidationFormula : HasDecidableValidation Formula
-- HasDecidableValidation.⊨?_ HasDecidableValidationFormula (atomic 𝑃 τs) = {!!}
-- HasDecidableValidation.⊨?_ HasDecidableValidationFormula (logical φ₁ φ₂) = {!!}
-- HasDecidableValidation.⊨?_ HasDecidableValidationFormula (quantified 𝑥 φ) = {!!}
-- instance HasDecidableValidationLiteralFormula : HasDecidableValidation LiteralFormula
-- HasDecidableValidationLiteralFormula = {!!}
-- instance HasDecidableValidationSequent : HasDecidableValidation Sequent
-- HasDecidableValidationSequent = {!!}
-- instance HasDecidableValidationLiteralSequent : HasDecidableValidation LiteralSequent
-- HasDecidableValidationLiteralSequent = {!!}
-- instance HasDecidableValidationProblem : HasDecidableValidation Problem
-- HasDecidableValidationProblem = {!!}
-- instance HasDecidableValidationLiteralProblem : HasDecidableValidation LiteralProblem
-- HasDecidableValidationLiteralProblem = {!!}
-- postulate
-- substituteFormula : (VariableName → Term) → Formula → Formula
-- record Unifier : Set
-- where
-- field
-- unifier-left unifier-right : VariableName → Term
-- open Unifier
-- record _Unifies_and_ (υ : Unifier) (φ₁ φ₂ : Formula) : Set
-- where
-- field
-- unification-law : substituteFormula (unifier-left υ) φ₁ ≡ substituteFormula (unifier-right υ) φ₂
-- record HasSubstantiveDischarge (+ : Set) (- : Set) : Set₁
-- where
-- field
-- _≽_ : + → - → Set
-- _⋡_ : + → - → Set
-- + ⋡ - = ¬ + ≽ -
-- open HasSubstantiveDischarge ⦃ … ⦄
-- {-# DISPLAY HasSubstantiveDischarge._≽_ _ = _≽_ #-}
-- instance HasSubstantiveDischargeList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ → HasSubstantiveDischarge (List A) A
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeList +s - = {!!} -- ∃ λ c → (c ∈ +s) × c ≽ -
-- instance HasSubstantiveDischargeListList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ → HasSubstantiveDischarge (List A) (List A)
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeListList +s -s = {!!} -- ∀ i → i ∈ -s → +s ≽ i
-- instance HasSubstantiveDischargeFormulaFormula : HasSubstantiveDischarge Formula Formula
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeFormulaFormula φ₁ φ₂ = ∃ λ υ → υ Unifies φ₁ and φ₂
-- instance HasSubstantiveDischargeSequentSequent : HasSubstantiveDischarge Sequent Sequent
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeSequentSequent (+ᵗ ╱ +ᵖs) (-ᵗ ╱ -ᵖs) = {!!} -- +ᵗ ≽ -ᵗ × +ᵖs ≽ -ᵖs -- use "unification into", from John's "Natural Deduction"
-- instance HasSubstantiveDischargeProblemProblem : HasSubstantiveDischarge Problem Problem
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeProblemProblem (+s ¶ +) (-s ¶ -) = {!!} -- + ≽ - × +s ≽ -s
-- record HasDecidableSubstantiveDischarge (+ : Set) (- : Set) ⦃ _ : HasSubstantiveDischarge (+) (-) ⦄ : Set₁
-- where
-- field
-- _≽?_ : (+ : +) → (- : -) → Dec $ + ≽ -
-- open HasDecidableSubstantiveDischarge ⦃ … ⦄
-- {-# DISPLAY HasDecidableSubstantiveDischarge._≽?_ _ = _≽?_ #-}
-- instance HasDecidableSubstantiveDischargeList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ ⦃ _ : HasDecidableSubstantiveDischarge A A ⦄ ⦃ _ : Eq A ⦄ → HasDecidableSubstantiveDischarge (List A) A
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeList +s - = {!!}
-- instance HasDecidableSubstantiveDischargeListList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ ⦃ _ : HasDecidableSubstantiveDischarge A A ⦄ ⦃ _ : Eq A ⦄ → HasDecidableSubstantiveDischarge (List A) (List A)
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeListList +s -s = {!!}
-- instance HasDecidableSubstantiveDischargeFormulaFormula : HasDecidableSubstantiveDischarge Formula Formula
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeFormulaFormula = {!!} -- _≟_
-- instance HasDecidableSubstantiveDischargeSequentSequent : HasDecidableSubstantiveDischarge Sequent Sequent
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeSequentSequent = {!!}
-- instance HasDecidableSubstantiveDischargeProblemProblem : HasDecidableSubstantiveDischarge Problem Problem
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeProblemProblem = {!!}
-- record SubstantiveDischargeIsConsistent (+ : Set) (- : Set) ⦃ _ : HasNegation (-) ⦄ ⦃ _ : HasSubstantiveDischarge (+) (-) ⦄ : Set₁
-- where
-- field
-- ≽-consistent : {+ : +} → { - : - } → + ≽ - → + ⋡ ~ -
-- open SubstantiveDischargeIsConsistent ⦃ … ⦄
-- {-# DISPLAY SubstantiveDischargeIsConsistent.≽-consistent _ = ≽-consistent #-}
-- record SubstantiveDischargeIsReflexive (A : Set) ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁
-- where
-- field
-- ≽-reflexive : (x : A) → x ≽ x
-- open SubstantiveDischargeIsReflexive ⦃ … ⦄
-- {-
-- record SubstantiveDischargeIsReflexive (A : Set) ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁
-- where
-- field
-- ≽-reflexive : {x : A} → x ≽ x
-- open SubstantiveDischargeIsReflexive ⦃ … ⦄
-- -}
-- {-# DISPLAY SubstantiveDischargeIsReflexive.≽-reflexive _ = ≽-reflexive #-}
-- record HasVacuousDischarge (A : Set) ⦃ _ : HasNegation A ⦄ ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁
-- where
-- ◁_ : List A → Set
-- ◁ +s = ∃ λ (s : A) → (+s ≽ s) × (+s ≽ ~ s)
-- ⋪_ : List A → Set
-- ⋪_ = ¬_ ∘ ◁_
-- open HasVacuousDischarge ⦃ … ⦄
-- {-# DISPLAY HasVacuousDischarge.◁_ _ = ◁_ #-}
-- {-# DISPLAY HasVacuousDischarge.⋪_ _ = ⋪_ #-}
-- infixr 1 ,_
-- pattern ,_ p = _ , p
-- pattern ◁pattern c₁∈xs c₁≽s c₂∈xs c₂≽~s = , (((, (c₁∈xs , c₁≽s)) , (, (c₂∈xs , c₂≽~s))))
-- record HasDecidableVacuousDischarge (A : Set)
-- ⦃ _ : HasNegation A ⦄
-- ⦃ _ : HasSubstantiveDischarge A A ⦄
-- ⦃ _ : HasVacuousDischarge A ⦄
-- --⦃ _ : HasDecidableSubstantiveDischarge A A ⦄
-- --⦃ _ : SubstantiveDischargeIsConsistent A A ⦄
-- --⦃ _ : SubstantiveDischargeIsReflexive A ⦄
-- ⦃ _ : Eq A ⦄
-- : Set₁
-- where
-- field
-- ◁?_ : (x : List A) → Dec $ ◁ x
-- instance HasDecidableVacuousDischarge𝓢equent : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : Eq A ⦄ ⦃ _ : HasNegation (𝓢equent A) ⦄ ⦃ _ : HasSubstantiveDischarge (𝓢equent A) (𝓢equent A) ⦄ ⦃ _ : HasVacuousDischarge (𝓢equent A) ⦄ → HasDecidableVacuousDischarge (𝓢equent A)
-- HasDecidableVacuousDischarge𝓢equent = {!!}
-- {-
-- instance
-- ◁? [] = no (λ { (_ , (_ , () , _) , _)})
-- ◁? (x ∷ xs) with xs ≽? ~ x
-- ◁? (x ∷ xs) | yes (, ~x!∈xs , ~x!≽~x) = yes $ , (((, (here xs , ≽-reflexive x)) , (, (there _ ~x!∈xs , ~x!≽~x))))
-- ◁? (x ∷ xs) | no xs⋡~x with ◁? xs
-- ◁? (x ∷ xs) | no xs⋡~x | yes (◁pattern c₁∈xs c₁≽s c₂∈xs c₂≽~s) = yes (◁pattern (there _ c₁∈xs) c₁≽s (there _ c₂∈xs) c₂≽~s)
-- ◁? (x ∷ xs) | no xs⋡~x | no ⋪xs = no λ
-- { (◁pattern (here .xs) x≽s (here .xs) c₂≽~s) → {!xs⋡~x!}
-- ; (◁pattern (here .xs) x≽s (there _ c₂∈xs) c₂≽~s) → {!xs⋡~x!}
-- ; (◁pattern (there _ c₁∈xs) c₁≽s c₂∈xxs c₂≽~s) → {!xs⋡~x!} }
-- -}
-- --{-⋪xs (◁pattern {!!} c₁≽s {!!} c₂≽~s)-}
-- open HasDecidableVacuousDischarge ⦃ … ⦄
-- {-# DISPLAY HasDecidableVacuousDischarge.◁?_ _ = ◁?_ #-}
-- instance HasDecidableVacuousDischargeFormula : HasDecidableVacuousDischarge Formula
-- HasDecidableVacuousDischarge.◁?_ HasDecidableVacuousDischargeFormula [] = {!!}
-- HasDecidableVacuousDischarge.◁?_ HasDecidableVacuousDischargeFormula (φ ∷ φs) = {!!}
-- record HasSalvation (A : Set) : Set₁
-- where
-- field
-- -- {isVacuouslyDischargable} : Set
-- -- ⦃ hasVacuousDischarge ⦄ : HasVacuousDischarge isVacuouslyDischargable
-- ▷_ : A → Set
-- open HasSalvation ⦃ … ⦄
-- instance
-- HasSalvation𝓢equent : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSubstantiveDischarge A A ⦄ ⦃ _ : HasNegation A ⦄ ⦃ _ : HasVacuousDischarge A ⦄ → HasSalvation $ 𝓢equent A
-- HasSalvation.▷_ HasSalvation𝓢equent (φᵖs ⊢ φᵗs) = (◁ φᵖs) ⊎ (φᵖs ≽ φᵗs)
-- {-# DISPLAY HasSalvation.▷_ _ = ▷_ #-}
-- record HasDecidableSalvation (A : Set) ⦃ _ : HasSalvation A ⦄ : Set₁
-- where
-- field
-- ▷?_ : (x : A) → Dec $ ▷_ x
-- open HasDecidableSalvation ⦃ … ⦄
-- {-# DISPLAY HasDecidableSalvation.▷?_ _ = ▷?_ #-}
-- ∀[_♭_] : VariableName → Formula → Formula
-- ∀[_♭_] = quantified
-- {-# DISPLAY quantified = ∀[_♭_] #-}
-- _∧_ : Formula → Formula → Formula
-- φ₁ ∧ φ₂ = ~ φ₁ ⊗ ~ φ₂
-- _∨_ : Formula → Formula → Formula
-- φ₁ ∨ φ₂ = ~ (φ₁ ⊗ φ₂)
-- _⊃_ : Formula → Formula → Formula
-- φ₁ ⊃ φ₂ = ~ φ₁ ∨ φ₂
-- _⟷_ : Formula → Formula → Formula
-- φ₁ ⟷ φ₂ = (φ₁ ⊗ (φ₂ ⊗ φ₂)) ⊗ ((φ₁ ⊗ φ₁) ⊗ φ₂) -- TODO check that this is logically equivalent to the more verbose, (φ₁ ⊃ φ₂) ∧ (φ₂ ⊃ φ₁)
-- data TermCode : Set
-- where
-- variable : VariableName → TermCode
-- function : FunctionName → Arity → TermCode
-- termCode-function-inj₁ : ∀ {𝑓₁ 𝑓₂ arity₁ arity₂} → TermCode.function 𝑓₁ arity₁ ≡ function 𝑓₂ arity₂ → 𝑓₁ ≡ 𝑓₂
-- termCode-function-inj₁ refl = refl
-- termCode-function-inj₂ : ∀ {𝑓₁ 𝑓₂ arity₁ arity₂} → TermCode.function 𝑓₁ arity₁ ≡ function 𝑓₂ arity₂ → arity₁ ≡ arity₂
-- termCode-function-inj₂ refl = refl
-- instance
-- EqTermCode : Eq TermCode
-- Eq._==_ EqTermCode (variable 𝑥₁) (variable 𝑥₂) with 𝑥₁ ≟ 𝑥₂
-- … | yes 𝑥₁≡𝑥₂ rewrite 𝑥₁≡𝑥₂ = yes refl
-- … | no 𝑥₁≢𝑥₂ = no (λ { refl → 𝑥₁≢𝑥₂ refl})
-- Eq._==_ EqTermCode (variable x) (function x₁ x₂) = no (λ ())
-- Eq._==_ EqTermCode (function x x₁) (variable x₂) = no (λ ())
-- Eq._==_ EqTermCode (function 𝑓₁ 𝑎₁) (function 𝑓₂ 𝑎₂) = decEq₂ termCode-function-inj₁ termCode-function-inj₂ (𝑓₁ ≟ 𝑓₂) (𝑎₁ ≟ 𝑎₂)
-- mutual
-- encodeTerm : Term → List TermCode
-- encodeTerm (variable 𝑥) = variable 𝑥 ∷ []
-- encodeTerm (function 𝑓 (⟨_⟩ {arity} τs)) = function 𝑓 arity ∷ encodeTerms τs
-- encodeTerms : {arity : Arity} → Vector Term arity → List TermCode
-- encodeTerms ⟨ [] ⟩ = []
-- encodeTerms ⟨ τ ∷ τs ⟩ = encodeTerm τ ++ encodeTerms ⟨ τs ⟩
-- mutual
-- decodeTerm : Nat → StateT (List TermCode) Maybe Term
-- decodeTerm zero = lift nothing
-- decodeTerm (suc n) = do
-- caseM get of λ
-- { [] → lift nothing
-- ; (variable 𝑥 ∷ _) →
-- modify (drop 1) ~|
-- return (variable 𝑥)
-- ; (function 𝑓 arity ∷ _) →
-- modify (drop 1) ~|
-- decodeFunction n 𝑓 arity }
-- decodeFunction : Nat → FunctionName → Arity → StateT (List TermCode) Maybe Term
-- decodeFunction n 𝑓 arity = do
-- τs ← decodeTerms n arity -|
-- return (function 𝑓 ⟨ τs ⟩)
-- decodeTerms : Nat → (arity : Arity) → StateT (List TermCode) Maybe (Vector Term arity)
-- decodeTerms n ⟨ zero ⟩ = return ⟨ [] ⟩
-- decodeTerms n ⟨ suc arity ⟩ = do
-- τ ← decodeTerm n -|
-- τs ← decodeTerms n ⟨ arity ⟩ -|
-- return ⟨ τ ∷ vector τs ⟩
-- .decode-is-inverse-of-encode : ∀ τ → runStateT (decodeTerm ∘ length $ encodeTerm τ) (encodeTerm τ) ≡ (just $ τ , [])
-- decode-is-inverse-of-encode (variable 𝑥) = refl
-- decode-is-inverse-of-encode (function 𝑓 ⟨ ⟨ [] ⟩ ⟩) = {!!}
-- decode-is-inverse-of-encode (function 𝑓 ⟨ ⟨ variable 𝑥 ∷ τs ⟩ ⟩) = {!!}
-- decode-is-inverse-of-encode (function 𝑓 ⟨ ⟨ function 𝑓' τs' ∷ τs ⟩ ⟩) = {!!}
-- module ExampleEncodeDecode where
-- example-Term : Term
-- example-Term =
-- (function ⟨ 2 ⟩
-- ⟨ ⟨ ( variable ⟨ 0 ⟩ ∷
-- function ⟨ 3 ⟩ ⟨ ⟨ variable ⟨ 2 ⟩ ∷ [] ⟩ ⟩ ∷
-- variable ⟨ 5 ⟩ ∷ [] )
-- ⟩ ⟩
-- )
-- -- function ⟨ 2 ⟩ ⟨ 3 ⟩ ∷ variable ⟨ 0 ⟩ ∷ function ⟨ 3 ⟩ ⟨ 1 ⟩ ∷ variable ⟨ 2 ⟩ ∷ variable ⟨ 5 ⟩ ∷ []
-- example-TermCodes : List TermCode
-- example-TermCodes = encodeTerm example-Term
-- example-TermDecode : Maybe (Term × List TermCode)
-- example-TermDecode = runStateT (decodeTerm (length example-TermCodes)) example-TermCodes
-- example-verified : example-TermDecode ≡ (just $ example-Term , [])
-- example-verified = refl
-- example-bad : runStateT (decodeTerm 2) (function ⟨ 2 ⟩ ⟨ 2 ⟩ ∷ variable ⟨ 0 ⟩ ∷ []) ≡ nothing
-- example-bad = refl
-- record TermNode : Set
-- where
-- inductive
-- field
-- children : List (TermCode × TermNode)
-- number : Nat
-- open TermNode
-- _child∈_ : TermCode → TermNode → Set
-- _child∈_ 𝔠 𝔫 = 𝔠 ∈ (fst <$> children 𝔫)
-- _child∉_ : TermCode → TermNode → Set
-- 𝔠 child∉ 𝔫 = ¬ (𝔠 child∈ 𝔫)
-- _child∈?_ : (𝔠 : TermCode) → (𝔫 : TermNode) → Dec $ 𝔠 child∈ 𝔫
-- c child∈? record { children = cs } = c ∈? (fst <$> cs)
-- getChild : {𝔠 : TermCode} → (𝔫 : TermNode) → 𝔠 child∈ 𝔫 → TermNode
-- getChild {𝔠} (record { children = [] ; number = number₁ }) ()
-- getChild {._} (record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }) zero = snd₁
-- getChild {𝔠} (𝔫@record { children = x ∷ children₁ ; number = number₁ }) (suc x₁) = getChild record 𝔫 { children = children₁ } x₁
-- addChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 child∉ 𝔫 → TermNode → TermNode
-- addChild {𝔠} 𝔫 𝔠∉𝔫 𝔫' =
-- record 𝔫 { children = (𝔠 , 𝔫') ∷ children 𝔫 }
-- setChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 child∈ 𝔫 → TermNode → TermNode
-- setChild {𝔠} record { children = [] ; number = number₁ } () 𝔫'
-- setChild 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } (zero) 𝔫' =
-- record 𝔫 { children = ((fst₁ , 𝔫') ∷ children₁) }
-- setChild {𝔠} 𝔫@record { children = (x ∷ children₁) ; number = number₁ } (suc 𝔠∈𝔫) 𝔫' =
-- record 𝔫 { children = (x ∷ children (setChild (record 𝔫 { children = children₁ }) 𝔠∈𝔫 𝔫')) }
-- setGet-ok : ∀ {𝔠} 𝔫 → (𝔠∈𝔫 : 𝔠 child∈ 𝔫) → setChild 𝔫 𝔠∈𝔫 (getChild 𝔫 𝔠∈𝔫) ≡ 𝔫
-- setGet-ok record { children = [] ; number = number₁ } ()
-- setGet-ok record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } (zero) = refl
-- setGet-ok record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } (suc 𝔠∈𝔫) rewrite setGet-ok (record { children = children₁ ; number = number₁ }) 𝔠∈𝔫 = refl
-- storeTermCodes : List TermCode → Nat → StateT TermNode Identity Nat
-- storeTermCodes [] 𝔑 = return 𝔑
-- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- 𝔫 ← get -|
-- case 𝔠 child∈? 𝔫 of λ
-- { (no 𝔠∉tests) →
-- let 𝔑' , 𝔫' = runIdentity $
-- runStateT
-- (storeTermCodes 𝔠s $ suc 𝔑)
-- (record
-- { children = []
-- ; number = suc 𝔑 }) in
-- put ((addChild 𝔫 𝔠∉tests 𝔫')) ~|
-- return 𝔑'
-- ; (yes 𝔠∈tests) →
-- let 𝔑' , 𝔫' = runIdentity $
-- runStateT
-- (storeTermCodes 𝔠s $ suc 𝔑)
-- ((getChild 𝔫 𝔠∈tests)) in
-- put ((setChild 𝔫 𝔠∈tests 𝔫')) ~|
-- return 𝔑' }
-- storeTermCodes[] : (𝔫 : TermNode) (𝔑 : Nat) → (runIdentity $ runStateT (storeTermCodes [] 𝔑) 𝔫) ≡ (𝔑 , 𝔫)
-- storeTermCodes[] 𝔫 𝔑 = refl
-- --{-# REWRITE storeTermCodes[] #-}
-- storeTermCodes' : List TermCode → StateT Nat (StateT TermNode Identity) ⊤
-- storeTermCodes' 𝔠s =
-- 𝔑 ← get -|
-- tn ← lift get -|
-- (let 𝔑' , tn' = runIdentity $ runStateT (storeTermCodes 𝔠s 𝔑) tn in
-- put 𝔑' ~| lift (put tn') ~| return tt)
-- mutual
-- storeTerm : Term → StateT Nat (StateT TermNode Identity) ⊤
-- storeTerm τ@(variable _) = storeTermCodes' (encodeTerm τ)
-- storeTerm τ@(function _ τs) = storeTermCodes' (encodeTerm τ) ~| storeTerms τs
-- storeTerms : Terms → StateT Nat (StateT TermNode Identity) ⊤
-- storeTerms ⟨ ⟨ [] ⟩ ⟩ = return tt
-- storeTerms ⟨ ⟨ τ ∷ τs ⟩ ⟩ = storeTerm τ ~| storeTerms ⟨ ⟨ τs ⟩ ⟩ ~| return tt
-- module ExampleStoreTerm where
-- example-Term₁ : Term
-- example-Term₁ =
-- (function ⟨ 2 ⟩
-- ⟨ ⟨ variable ⟨ 0 ⟩
-- ∷ function ⟨ 3 ⟩
-- ⟨ ⟨ variable ⟨ 2 ⟩ ∷ [] ⟩ ⟩
-- ∷ variable ⟨ 5 ⟩
-- ∷ []
-- ⟩ ⟩
-- )
-- example-Term₂ : Term
-- example-Term₂ =
-- (function ⟨ 2 ⟩
-- ⟨ ⟨ variable ⟨ 0 ⟩
-- ∷ variable ⟨ 2 ⟩
-- ∷ function ⟨ 3 ⟩
-- ⟨ ⟨ variable ⟨ 2 ⟩ ∷ [] ⟩ ⟩
-- ∷ variable ⟨ 5 ⟩
-- ∷ []
-- ⟩ ⟩
-- )
-- topNode : TermNode
-- topNode = record { children = [] ; number = 0 }
-- example-storeTerm : (⊤ × Nat) × TermNode
-- example-storeTerm = runIdentity $ runStateT (runStateT (storeTerm example-Term₁ >> storeTerm example-Term₂) 0) topNode
-- NodeStateT = StateT TermNode
-- TopNodeState = StateT Nat (NodeStateT Identity)
-- storeLiteralFormulaTerms : LiteralFormula → StateT Nat (StateT TermNode Identity) ⊤
-- storeLiteralFormulaTerms ⟨ atomic 𝑃 τs ⟩ = storeTerms τs
-- storeLiteralFormulaTerms ⟨ logical 𝑃 τs ⟩ = storeTerms τs
-- storeSequentLiteralFormulaTerms : 𝓢equent LiteralFormula → StateT Nat (StateT TermNode Identity) ⊤′
-- storeSequentLiteralFormulaTerms (φˢs ⊢ φᵗ) = sequence $ storeLiteralFormulaTerms <$> ({!φᵗ!} ∷ φˢs)
-- record FindTermNode (A : Set) : Set
-- where
-- field
-- findTermNode : A → TermNode → Maybe TermNode
-- open FindTermNode ⦃ … ⦄
-- instance
-- FindTermNodeTermCode : FindTermNode TermCode
-- FindTermNode.findTermNode FindTermNodeTermCode termCode record { children = [] ; number = number₁ } = nothing
-- FindTermNode.findTermNode FindTermNodeTermCode termCode 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } = ifYes fst₁ ≟ termCode then just snd₁ else findTermNode termCode record 𝔫 { children = children₁ }
-- FindTermNodeTermCodes : FindTermNode (List TermCode)
-- FindTermNode.findTermNode FindTermNodeTermCodes [] node = just node
-- FindTermNode.findTermNode FindTermNodeTermCodes (x ∷ termCodes) node = join $ findTermNode termCodes <$> findTermNode x node
-- FindTermNodeTerm : FindTermNode Term
-- FindTermNode.findTermNode FindTermNodeTerm term node = findTermNode (encodeTerm term) node
-- -- This is starting to get difficult. We need Agda to know that the Term is encoded in the TermNode. Then we can drop the Maybe
-- getInterpretationOfTerm : Term → TermNode → Maybe Element
-- getInterpretationOfTerm τ node = ⟨_⟩ ∘ number <$> findTermNode (encodeTerm τ) node
-- FindTermNodeTermCode-ok : ∀ {𝔠 𝔫} → 𝔠 child∈ 𝔫 → IsJust (findTermNode 𝔠 𝔫)
-- FindTermNodeTermCode-ok {𝔠} {record { children = [] ; number = number₁ }} ()
-- --FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ = case (fst₁ ≟_) 𝔠 , graphAt {B = λ 𝑐 → Dec (fst₁ ≡ 𝑐)} (fst₁ ≟_) 𝔠 of λ { (yes x , snd₂) → {!!} ; (no x , snd₂) → {!!}} --λ { ((yes ===) , (inspect s1)) → {!!} ; ((no =n=) , inspect s2) → {!!} }
-- --FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ = case fst₁ ≟ 𝔠 of λ { (yes refl) → {!!} ; (no x) → {!!}}
-- FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ with fst₁ ≟ 𝔠
-- FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ | yes eq2 = tt
-- FindTermNodeTermCode-ok {.fst₁} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} (zero) | no neq = ⊥-elim (neq refl)
-- FindTermNodeTermCode-ok {𝔠} {𝔫@record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} (suc x₁) | no neq = FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} x₁
-- Justified : ∀ {a} {A : Set a} → (m : Maybe A) → IsJust m → ∃ λ x → m ≡ just x
-- Justified nothing ()
-- Justified (just x) x₁ = _ , refl
-- storeTerm-ok : ∀ τ 𝔫 𝔑 → IsJust (findTermNode τ (snd (runIdentity (runStateT (runStateT (storeTerm τ) 𝔑) 𝔫))))
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 with variable 𝑥 child∈? 𝔫
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 | no x with TermCode.variable 𝑥 ≟ variable 𝑥
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 | no x | yes _ = tt
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 | no x | no variable𝑥≢variable𝑥 = ⊥-elim (variable𝑥≢variable𝑥 refl)
-- --storeTerm-ok (variable 𝑥) 𝔫 𝔑 | yes vx∈𝔫 rewrite setGet-ok 𝔫 vx∈𝔫 = {!𝔫!}
-- storeTerm-ok (variable 𝑥) record { children = [] ; number = number₁ } 𝔑 | yes ()
-- --storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 rewrite setGet-ok 𝔫 vx∈𝔫 = {!!}
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 rewrite setGet-ok 𝔫 vx∈𝔫 with fst₁ ≟ variable 𝑥
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | yes eq = tt
-- --… | no neq = case vx∈𝔫 of λ { (here .(map fst children₁)) → ⊥-elim (neq refl) ; (there .fst₁ asdf) → case graphAt FindTermNodeTermCode-ok asdf of λ { (ingraph sss) → {!!} } } -- storeTerm-ok x {!record 𝔫 { children = children₁ }!} 𝔑 -- x record 𝔫 { children = children₁ } 𝔑
-- --… | no neq = case vx∈𝔫 of λ { (here .(map fst children₁)) → ⊥-elim (neq refl) ; (there .fst₁ asdf) → case inspect $ FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} asdf of λ { (.(FindTermNodeTermCode-ok asdf) , ingraph refl) → {!!}} } -- storeTerm-ok x {!record 𝔫 { children = children₁ }!} 𝔑 -- x record 𝔫 { children = children₁ } 𝔑
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq with vx∈𝔫
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq | zero = ⊥-elim (neq refl)
-- --storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq | there dfdsf fdsdfs with FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} fdsdfs | graphAt (FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }}) fdsdfs
-- --… | frfrrf | ingraph tttttt = transport _ (snd $ Justified (FindTermNode.findTermNode FindTermNodeTermCode (variable 𝑥) (record { children = children₁ ; number = number₁ })) (FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} fdsdfs)) _
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq | suc fdsdfs rewrite (snd $ Justified (FindTermNode.findTermNode FindTermNodeTermCode (variable 𝑥) (record { children = children₁ ; number = number₁ })) (FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} fdsdfs)) = tt
-- storeTerm-ok (function 𝑥 𝑎) 𝔫 𝔑 with (function 𝑥 (arity 𝑎)) child∈? 𝔫
-- storeTerm-ok (function 𝑥 ⟨ ⟨ [] ⟩ ⟩) 𝔫 𝔑 | no x with Eq._==_ EqFunctionName ⟨ name 𝑥 ⟩ ⟨ name 𝑥 ⟩
-- storeTerm-ok (function 𝑥 ⟨ ⟨ [] ⟩ ⟩) 𝔫 𝔑 | no x | (yes refl) = tt
-- … | no neq = ⊥-elim (neq refl)
-- --storeTerm-ok τ₀@(function 𝑓 ⟨ τ₁ ∷ τ₂s ⟩) 𝔫 𝔑 | no 𝔠₁∉𝔫 = {!τ₁!}
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₁∉𝔫 with variable 𝑥 child∈? 𝔫
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) with 𝑓₀ ≟ 𝑓₀
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | yes refl with TermCode.variable 𝑥 ≟ variable 𝑥
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | yes refl | yes eq = tt
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | yes refl | no neq = ⊥-elim (neq refl)
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | no neq = ⊥-elim (neq refl)
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) with 𝑓₀ ≟ 𝑓₀
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | yes refl with TermCode.variable 𝑥₁ ≟ variable 𝑥₁
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | yes refl | yes 𝔠₁≡𝔠₁ = tt
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | yes refl | no 𝔠₁≢𝔠₁ = ⊥-elim (𝔠₁≢𝔠₁ refl)
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | no 𝑓₀≢𝑓₀ = ⊥-elim (𝑓₀≢𝑓₀ refl) -- rewrite setGet-ok 𝔫 𝔠₁∈𝔫
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ τ₂ ∷ τ₃s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 with variable 𝑥₁ child∈? 𝔫
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ τ₂ ∷ τ₃s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | yes 𝔠₁∈𝔫 = {!!}
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ τ₂ ∷ τ₃s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | no 𝔠₁∉𝔫 = {!!}
-- storeTerm-ok τ₀@(function 𝑓₀ ⟨ ⟨ function 𝑓₁ τ₁s ∷ τ₂s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₁∉𝔫 = {!!}
-- storeTerm-ok (function 𝑥 x₁) 𝔫 𝔑 | yes x = {!!}
-- mutual
-- storeTermVerifiably' : (τ : Term) → StateT Nat (StateT (Σ TermNode λ n → IsJust (findTermNode τ n)) Identity) ⊤
-- storeTermVerifiably' (variable x) = {!!}
-- storeTermVerifiably' (function x x₁) = {!!}
-- storeTermVerifiably : Term → StateT Nat (StateT TermNode Identity) ⊤
-- storeTermVerifiably τ@(variable _) = storeTermCodes' (encodeTerm τ)
-- storeTermVerifiably τ@(function _ τs) = storeTermCodes' (encodeTerm τ) ~| storeTermsVerifiably τs
-- storeTermsVerifiably : Terms → StateT Nat (StateT TermNode Identity) ⊤
-- storeTermsVerifiably ⟨ ⟨ [] ⟩ ⟩ = return tt
-- storeTermsVerifiably ⟨ ⟨ τ ∷ τs ⟩ ⟩ = storeTermVerifiably τ ~| storeTermsVerifiably ⟨ ⟨ τs ⟩ ⟩ ~| return tt
-- Theorem1 : {Φ : 𝓢equent (𝓢equent LiteralFormula)} → {!⊨!} Φ ↔ {!▷!} Φ
-- Theorem1 = {!!}
-- {-
-- Theorem1 {Φ@(χs ¶ ι)} = Theorem1a , Theorem1b
-- where
-- Theorem1a : ⊨ Φ → ▷ Φ
-- Theorem1a with ▷? Φ
-- … | yes ▷Φ = const ▷Φ
-- … | no ⋫Φ =
-- let I , I⊨χs , I⊭ι = Lemma1a in
-- λ I→I⊨cs→I⊨i → ⊥-elim $ I⊭ι $ I→I⊨cs→I⊨i I I⊨χs
-- where
-- Lemma1a : ∃ λ I → I ⊨ χs × I ⊭ ι
-- -- To construct the interpretation, consider a unique list, τ₀, τ₁, …, τₙ, of terms in ι ∷ χs. For each term, τ, we find <TODO> interpretations, 𝓘, such that for any I ∈ 𝓘, and any i ∈ 0, …, n, τ⟦ I ⟧ τᵢ = i. For each formula φ ∈ ι ∷ χs, we find <TODO> an interpretation I ∈ 𝓘 such that 𝑃⟦ I ⟧ φ = true when φ ∈ χs and 𝑃⟦ I ⟧ φ = false when φ = ι.
-- -- For all terms in ι ∷ χs, find a coding into Nat that uniquely determines each term. To do this, compute the maximum functional depth of terms, D, the maximal arity of terms, A, the maximal function name, F, and the maximal variable name, V. Each term can then be coded into Fin V + (D₀ = F + F * V + F * V ^ 2 + ... + F * V ^ A) + (D₀ ...
-- -- Encode each term in a discrimination network. Each new term stored is assigned a unique id
-- Lemma1a = {!!}
-- where
-- Theorem1b : ▷ Φ → ⊨ Φ
-- Theorem1b = {!!}
-- -}
-- negationEliminationRule : (I : Interpretation) (φ : Formula) → I ⊨ ~ (~ φ) → I ⊨ φ
-- negationEliminationRule I φ (¬[I⊭φ×I⊭φ] , _) with I ⊨? φ
-- … | yes I⊨φ = I⊨φ
-- … | no I⊭φ = ⊥-elim $ ¬[I⊭φ×I⊭φ] $ I⊭φ , I⊭φ
-- -- justifieds simplification and ... more?
-- simplificationRule₁ : (I : Interpretation) (φ₁ φ₂ : Formula) → I ⊨ Formula.logical φ₁ φ₂ → I ⊨ Formula.logical φ₁ φ₁
-- simplificationRule₁ I φ₁ φ₂ x = (fst x) , (fst x)
-- simplificationRule₂ : (I : Interpretation) (φ₁ φ₂ : Formula) → I ⊨ Formula.logical φ₁ φ₂ → I ⊨ Formula.logical φ₂ φ₂
-- simplificationRule₂ I φ₁ φ₂ x = snd x , snd x
-- -- logical (logical (logical p p) q) (logical (logical p p) q)
-- {-
-- conditionalizationRule : (I : Interpretation) (p q : Formula) → I ⊨ q → I ⊨ (p ⊃ q ╱ (p ∷ []) )
-- conditionalizationRule I p q ⊨q (_ , _) = let prf = λ { (_ , ⊭q) → ⊭q ⊨q} in prf , prf
-- --let ⊨p = {!-⊨p p (here [])!} in (λ { (x , ~q) → ~q ⊨q}) , (λ { (x , y) → y ⊨q})
-- -}
-- modusPonens : (I : Interpretation) (p q : Formula) → I ⊨ p → I ⊨ (p ⊃ q) → I ⊨ q
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) with I ⊨? q
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | yes x = x
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | no x = ⊥-elim (~[~p&~p&~q] ((λ { (x₁ , y) → y P}) , (λ x₁ → x x₁)))
-- -- -- -- -- -- data SkolemFormula {ι : Size} (α : Alphabet) : Set where
-- -- -- -- -- -- atomic : Predication α → SkolemFormula α
-- -- -- -- -- -- logical : {ι¹ : Size< ι} → SkolemFormula {ι¹} α → {ι² : Size< ι} → SkolemFormula {ι²} α → SkolemFormula {ι} α
-- -- -- -- -- -- record Alphabet₊ᵥ (α : Alphabet) : Set where
-- -- -- -- -- -- constructor α₊ᵥ⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- .one-variable-is-added : (number ∘ variables $ alphabet) ≡ suc (number ∘ variables $ α)
-- -- -- -- -- -- .there-are-no-functions-of-maximal-arity : number (functions alphabet) zero ≡ zero
-- -- -- -- -- -- .shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → number (functions alphabet) (suc ytira₁) ≡ number (functions α) ytira₀
-- -- -- -- -- -- open Alphabet₊ᵥ
-- -- -- -- -- -- record Alphabet₊ₛ (α : Alphabet) : Set where
-- -- -- -- -- -- constructor α₊ₛ⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- open Alphabet₊ₛ
-- -- -- -- -- -- {-
-- -- -- -- -- -- toSkolemFormula
-- -- -- -- -- -- ∀x(F x v₀ v₁) ⟿ F v₀ v₁ v₂
-- -- -- -- -- -- ∃x(F x v₀ v₁) ⟿ F (s₀͍₂ v₀ v₁) v₀ v₁
-- -- -- -- -- -- ∀x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F v₀ (s₀͍₂ v₁ v₂) v₂
-- -- -- -- -- -- ∃x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F (s₀͍₂ v₀ v₁) (s₁͍₂ v₁ v₂) v₂
-- -- -- -- -- -- F v₀ ⊗ G v₀ ⟿ F v₀ ⊗ G v₀
-- -- -- -- -- -- ∀x(F x v₀ v₁) ⊗ ∀x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₂ v₃ ⊗ G v₁ (s₀͍₂ v₀ v₃) v₃
-- -- -- -- -- -- ∀x(F x v₀ v₁) ⊗ ∃x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₁ v₂ ⊗ G (s₀͍₁ v₂) (s₁͍₂ (s₀͍₂ v₂) v₂) v₂
-- -- -- -- -- -- Φ₀ = ∃x(G x (s₀͍₂ x v₁) v₁) has alphabet of 2 variables, skolem functions: 0, 0, 1
-- -- -- -- -- -- this is existential {α₊ₛ} Φ₁, where
-- -- -- -- -- -- Φ₁ = G (s₀͍₂ v₀ v₁) (s₁͍₂ (s₀͍₂ v₀ v₁)) v₁
-- -- -- -- -- -- α₊ₛ = ⟨ 2 , 0 ∷ 0 ∷ 2 ∷ [] ⟩
-- -- -- -- -- -- maybe Φ₋₁ = ∀y∃x(G x (s₀͍₂ x v₀) v₀)
-- -- -- -- -- -- and Φ₋₂ = ∀z∀y∃x(G x (s₀͍₂ x z) z), finally having no free variables, but nevertheless having skolem functions! these are user-defined functions, so this notion of Alphabet is somehow wrong. we have also left out constants (i.e. user-defined skolem-functions of arity 0)
-- -- -- -- -- -- Instead, take the alphabet as defining
-- -- -- -- -- -- a stack of free variables
-- -- -- -- -- -- a matrix (triangle?) of skolem functions
-- -- -- -- -- -- Let's try to reverse Φ₁ from a Skolem to a 1st-order formula. Is there a unique way to do it?
-- -- -- -- -- -- Φ₀' = ∀x(G (s₀͍₂ x v₀) (s₁͍₂ (s₀͍₂ x v₀)) v₀
-- -- -- -- -- -- Nope!
-- -- -- -- -- -- toSkolemFormula of
-- -- -- -- -- -- -}
-- -- -- -- -- -- -- toSkolemFormula (logical Φ₁ Φ₂) ⟿
-- -- -- -- -- -- -- let α' , φ₁ = toSkolemFormula Φ₁
-- -- -- -- -- -- -- Φ₂' = transcodeToAugmentedAlphabet Φ₂ α'
-- -- -- -- -- -- -- α'' , φ₂' = toSkolemFormula Φ₂'
-- -- -- -- -- -- -- φ₁' = transcodeToAugmentedAlphabet φ₁ α''
-- -- -- -- -- -- {-
-- -- -- -- -- -- given Δv = #varibles α' - #variables α
-- -- -- -- -- -- for every variable v in α, v in Φ, v stays the same in Φ'
-- -- -- -- -- -- for the added variable v⁺ in α₊ - α, v⁺ in Φ, v⁺ ⟿ v⁺ + Δv in transcode (universal {α₊} Φ)
-- -- -- -- -- -- α'₊ = α' + 1 variable
-- -- -- -- -- -- -}
-- -- -- -- -- -- -- record AddVariable (A : Alphabet → Set) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- addVariableToAlphabet : {α : Alphabet} → A α → {α₊ : Alphabet} → Alphabet₊ᵥ α₊ → A α₊
-- -- -- -- -- -- -- instance
-- -- -- -- -- -- -- AddVariableFirstOrderFormula : AddVariable FirstOrderFormula
-- -- -- -- -- -- -- AddVariableFirstOrderFormula = {!!}
-- -- -- -- -- -- -- #variables = number ∘ variables
-- -- -- -- -- -- -- #functions_ofArity_ : Alphabet → Nat → Nat
-- -- -- -- -- -- -- #functions α⟨ V⟨ #variables ⟩ , S⟨ #functions ⟩ ⟩ ofArity arity = if′ lessNat arity (suc #variables) then #functions (natToFin arity) else 0
-- -- -- -- -- -- -- record _⊇_ (α' α : Alphabet) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- at-least-as-many-variables : #variables α' ≥ #variables α
-- -- -- -- -- -- -- at-least-as-many-functions : ∀ {arity} → arity < #variables α → #functions α' ofArity arity ≥ #functions α ofArity arity
-- -- -- -- -- -- -- record AddAlphabet (α-top α-bottom : Alphabet) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- record Transcodeable (A : Alphabet → Set) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- transcode : {α' α : Alphabet} → ⦃ _ : α' ⊇ α ⦄ → A α → A α'
-- -- -- -- -- -- -- open Transcodeable ⦃ … ⦄
-- -- -- -- -- -- -- record TransferAlphabet {α' α : Alphabet} (α'⊇α : α' ⊇ α) (α₊ : Alphabet₊ᵥ α) (Φ : FirstOrderFormula (alphabet α₊)) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- firstOrderFormula : FirstOrderFormula alphabet
-- -- -- -- -- -- -- instance
-- -- -- -- -- -- -- TranscodeablePredication : Transcodeable Predication
-- -- -- -- -- -- -- TranscodeablePredication = {!!}
-- -- -- -- -- -- -- TranscodeableAlphabet+Variable : Transcodeable Alphabet₊ᵥ
-- -- -- -- -- -- -- TranscodeableAlphabet+Variable = {!!}
-- -- -- -- -- -- -- TranscodeableSkolemFormula : Transcodeable SkolemFormula
-- -- -- -- -- -- -- TranscodeableSkolemFormula = {!!}
-- -- -- -- -- -- -- TranscodeableFirstOrderFormula : Transcodeable FirstOrderFormula
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (atomic p) = atomic (transcode p)
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (logical Φ₁ Φ₂) = logical (transcode Φ₁) (transcode Φ₂)
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula {α'} {α} ⦃ α'⊇α ⦄ (universal {α₊} Φ) = {!!} -- universal {_} {_} {transcode α₊} (transcode Φ)
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (existential Φ) = {!!}
-- -- -- -- -- -- -- --(α' α : Alphabet) (α'⊇α : α' ⊇ α) (α₊ : Alphabet+Variable α) (Φ : FirstOrderFormula (alphabet α₊)) → Σ _ λ (α''' : Alphabet) → FirstOrderFormula α'''
-- -- -- -- -- -- -- --FirstOrderFormula (alphabet α₊)
-- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- --transcodeIntoAugmentedAlphabet :
-- -- -- -- -- -- -- -- --toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- --record IsEquivalentFormulas {α₀ : Alphabet} (φ₀ : SkolemFormula α₀) {α₁ : Alphabet} (Φ₁ : FirstOrderFormula α₁) : Set where
-- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- .atomicCase : {p : Predication α₀} → φ₀ ≡ atomic p → Φ₁ ≡ atomic p
-- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- record Alphabet+Alphabet (α₀ α₁ α₂ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- alphabet :
-- -- -- -- -- -- -- -- -- -- ∀xφ₁(x) ⊗ φ₂ ⟿ ∀x(φ₁ ⊗ φ₂)
-- -- -- -- -- -- -- -- -- -- hasQuantifiers : FirstOrderFormula α → Bool
-- -- -- -- -- -- -- -- -- --record Skolemization {α : Alphabet} (φ : FirstOrderFormula α) : Set where
-- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- -- -- -- skolemization : SkolemFormula alphabet
-- -- -- -- -- -- -- -- -- record _IsAugmentationOf_ (α₁ α₀ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- record AugmentedAlphabet (α : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- constructor ⟨_⟩
-- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- -- -- ..laws : alphabet ≡ α
-- -- -- -- -- -- -- -- -- open AugmentedAlphabet
-- -- -- -- -- -- -- -- -- trivialAugmentation : (α : Alphabet) → AugmentedAlphabet α
-- -- -- -- -- -- -- -- -- trivialAugmentation = {!!}
-- -- -- -- -- -- -- -- -- record DisjointRelativeUnion {α : Alphabet} (α¹ α² : AugmentedAlphabet α) : Set where
-- -- -- -- -- -- -- -- -- constructor ⟨_⟩
-- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- augmentation : AugmentedAlphabet α
-- -- -- -- -- -- -- -- -- .laws : {!!}
-- -- -- -- -- -- -- -- -- open DisjointRelativeUnion
-- -- -- -- -- -- -- -- -- disjointRelativeUnion : {α : Alphabet} → (α¹ α² : AugmentedAlphabet α) → DisjointRelativeUnion α¹ α²
-- -- -- -- -- -- -- -- -- disjointRelativeUnion = {!!}
-- -- -- -- -- -- -- -- -- -- inAugmentedAlphabet : {α : Alphabet} → (α¹ : AugmentedAlphabet α) → SkolemFormula α → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- -- -- inAugmentedAlphabet = {!!}
-- -- -- -- -- -- -- -- -- -- toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (atomic 𝑃) = trivialAugmentation α₀ , atomic 𝑃
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) with toSkolemFormula φ₁ | toSkolemFormula φ₂
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) | α¹ , Φ₁ | α² , Φ₂ = augmentation (disjointRelativeUnion α¹ α²) , logical {!inAugmentedAlphabet (augmentation (disjointRelativeUnion α¹ α²)) Φ₁!} {!Φ₂!}
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (universal x) = {!!}
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (existential x) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- … | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- --VariableName = Fin ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- --FunctionArity = Fin ∘ suc ∘ size
-- -- -- -- -- -- -- -- -- -- -- -- -- --FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- |v| : Nat -- number of variables
-- -- -- -- -- -- -- -- -- -- -- -- -- -- |f| : Fin (suc |v|) → Nat -- number of functions of each arity, |v| through 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- open Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- VariableName = Fin ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionArity = Fin ∘ suc ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- variable : VariableName alphabet → Term alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {arity : FunctionArity alphabet} →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName alphabet (natToFin (|v| alphabet) - arity) →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀ {j : Size< i} → Vec (Term {j} alphabet) (finToNat arity) →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateArity = Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateName = Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a zeroth-order formula? (i.e. no quantifiers)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data NQFormula {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → NQFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → NQFormula {j} alphabet → {k : Size< i} → NQFormula {k} alphabet → NQFormula {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedByVariable (alphabet₀ alphabet₁ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one-variable-is-added : |v| alphabet₁ ≡ suc (|v| alphabet₀)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function-domain-is-zero-at-new-variable : |f| alphabet₁ zero ≡ 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → |f| alphabet₁ (suc ytira₁) ≡ |f| alphabet₀ ytira₀
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentVariables (alphabet₀ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet₁ : Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentation : AugmentedByVariable alphabet₀ alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- open AugmentVariables
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : (alphabet : Alphabet) → AugmentVariables alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables ⟨ |v| , |f| ⟩ =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- { alphabet₁ = ⟨ suc |v| , (λ { zero → zero ; (suc ytira) → |f| ytira}) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; augmentation =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- { one-variable-is-added = refl
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; function-domain-is-zero-at-new-variable = refl
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; shifted-function-matches = cong |f| ∘ finToNat-inj } }
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |f|₀ = |f|₀ + 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions ⟨ |v| , |f| ⟩ = ⟨ |v| , (λ { zero → suc (|f| zero) ; (suc ytira) → |f| (suc ytira) }) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data QFormula {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → QFormula {j} alphabet → {k : Size< i} → QFormula {k} alphabet → QFormula {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- universal : QFormula (alphabet₁ (augmentVariables alphabet)) → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- existential : QFormula (augmentFunctions alphabet) → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Assignment (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- μ : VariableName alphabet → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑓 : ∀ {arity} → FunctionName alphabet arity → Vec Domain (finToNat arity) → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm : ∀ {i alphabet} → Assignment alphabet → Term {i} alphabet → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm ⟨ μ , _ ⟩ (variable x) = μ x
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm 𝑎@(⟨ μ , 𝑓 ⟩) (function f x) = 𝑓 f (evaluateTerm 𝑎 <$> x)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Interpretation (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- open Assignment
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑎 : Assignment alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑃 : PredicateName → ∀ {arity} → Vec Domain arity → Bool
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula : ∀ {i alphabet} → Interpretation alphabet → NQFormula {i} alphabet → Bool
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula ⟨ 𝑎 , 𝑃 ⟩ (atomic name terms) = 𝑃 name $ evaluateTerm 𝑎 <$> terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula I (logical formula₁ formula₂) = not (evaluateNQFormula I formula₁) && not (evaluateNQFormula I formula₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- … | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record IsADisjointUnionOfNQFormulas
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {alphabet₁ alphabet₂ alphabet₁₊₂ : Alphabet}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁ : NQFormula alphabet₁)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₂ : NQFormula alphabet₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁₊₂ : NQFormula alphabet₁₊₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet-size : |v| alphabet₁₊₂ ≡ |v| alphabet₁ + |v| alphabet₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --|f| alphabet₁₊₂ ytira
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----record AlphabetSummed (alphabet₀ alphabet₁ : Alphabet)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets : Alphabet → Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets ⟨ |v|₁ , |f|₁ ⟩ ⟨ |v|₂ , |f|₂ ⟩ = ⟨ (|v|₁ + |v|₂) , (λ x → if′ finToNat x ≤? |v|₁ && finToNat x ≤? |v|₂ then {!!} else {!!}) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup : ∀ {alphabet₁} → Formula alphabet₁ → ∀ {alphabet₂} → Formula alphabet₂ → Σ _ λ alphabet₁₊₂ → Formula alphabet₁₊₂ × Formula alphabet₁₊₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup {⟨ |v|₁ , |a|₁ , |f|₁ ⟩} φ₁ {⟨ |v|₂ , |a|₂ , |f|₂ ⟩} φ₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf : ∀ {alphabet} → Formula alphabet → Σ _ λ alphabet+ → Formula₀ alphabet+
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --universal (P 0) = ∀ x → P x
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (∀ x ∃ y (P x y)) ∨ (∀ x ∃ y (P x y))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- P x₀ (s₀͍₁ x₀) ∨ P x₁ (s₁͍₁ x₁)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| : (arity : Arity) → Vec ℕ (suc |a|) → Vec ℕ (++arity (max arity |a|))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a variable to the alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN : ∀ {n} → Fin n → (Fin n → Nat) → Fin n → Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedFunctions {|a| : Arity} (arity : Arity) (|f| : Vec ℕ (++arity |a|)) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA : ℕ
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA-law : max arity |a| ≡ maxA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ++|f| : Vec ℕ maxA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- f-law : increaseTabulationAt arity (indexVec |f|)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- define
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ⊗ b ≡ False a and False b
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- now, we can define
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ¬a = a ⊗ a ≡ False a and False a
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∨ b = ¬(a ⊗ b) ≡ False (False a and False b) and False (False a and False b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∧ b = ¬(¬a ∨ ¬b) = ¬(¬(¬a ⊗ ¬b)) = ¬a ⊗ ¬b = False (False a and False a) and False (False b and False b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a → b = ¬a ∨ b = (a ⊗ a) ∨ b = ¬((a ⊗ a) ⊗ b) = ((a ⊗ a) ⊗ b) ⊗ ((a ⊗ a) ⊗ b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- conversion to prenex
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀xF ⊗ G ⟿ ∃x(F ⊗ wk(G))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∃xF ⊗ G ⟿ ∀x(F ⊗ wk(G))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∀xG ⟿ ∃x(wk(F) ⊗ G)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∃xG ⟿ ∀x(wk(F) ⊗ G)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ========================
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (a ⊗ ∀xB) ⊗ c ⟿ ∃x(wk(a) ⊗ B) ⊗ c ⟿ ∀x((wk(a) ⊗ B) ⊗ wk(c))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF : (arity : Arity) → ∀ {|a| : Arity} → Vec ℕ (++arity |a|) → Vec ℕ (++arity (max arity |a|))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- with decBool (lessNat |a| arity)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x with compare arity |a|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.(suc (k + arity))} |f| | yes x | less (diff k refl) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl with lessNat arity arity
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl | false = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF zero {.zero} |f| | yes true | equal refl | true = {!!} ∷ []
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF (suc arity) {.(suc arity)} |f| | yes true | equal refl | true = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x | greater gt = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x with decBool (lessNat arity |a|)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | yes x = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | no x = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- = case arity <? |a| of λ { false → {!!} ; true → {!!} }
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a function of a given arity to the alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Arity → Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions arity ⟨ |v| , |a| , |f| ⟩ = ⟨ |v| , max arity |a| , augmentF arity |f| ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data DomainSignifier : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- free : Nat → DomainSignifier
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartiallyAppliedFunction : Nat → Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constant : PartiallyAppliedFunction 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {n} → PartiallyAppliedFunction 0 → PartiallyAppliedFunction (suc n)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term = PartiallyAppliedFunction 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartialyAppliedPredicate : Nat → Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- statement : PartialyAppliedPredicate 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- partial : ∀
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Language : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Name = String
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Function : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- name : Name
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- number-of-arguments : Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Vec
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Function : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : Function →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Sentence : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- predication : Name →
-- -- -- -- -- -- {-
-- -- -- -- -- -- record Variables : Set where
-- -- -- -- -- -- constructor V⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- number : Nat
-- -- -- -- -- -- open Variables
-- -- -- -- -- -- record Functions (υ : Variables) : Set where
-- -- -- -- -- -- constructor S⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- number : Fin (suc (number υ)) → Nat
-- -- -- -- -- -- open Functions
-- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- constructor α⟨_,_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- variables : Variables
-- -- -- -- -- -- functions : Functions variables
-- -- -- -- -- -- open Alphabet
-- -- -- -- -- -- record Variable (α : Alphabet) : Set where
-- -- -- -- -- -- constructor v⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- name : Fin (number (variables α))
-- -- -- -- -- -- open Variable
-- -- -- -- -- -- record Function (α : Alphabet) : Set where
-- -- -- -- -- -- constructor s⟨_,_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- arity : Fin ∘ suc ∘ number ∘ variables $ α
-- -- -- -- -- -- name : Fin $ number (functions α) arity
-- -- -- -- -- -- open Function
-- -- -- -- -- -- data Term (𝑽 : Nat) : Set where
-- -- -- -- -- -- variable : Fin 𝑽 → Term 𝑽
-- -- -- -- -- -- function : (𝑓 : Function α) → {ι₋₁ : Size< ι₀} → Vec (Term {ι₋₁} α) (finToNat (arity 𝑓)) →
-- -- -- -- -- -- Term {ι₀} α
-- -- -- -- -- -- record Predication (alphabet : Alphabet) : Set where
-- -- -- -- -- -- constructor P⟨_,_,_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- name : Nat
-- -- -- -- -- -- arity : Nat
-- -- -- -- -- -- terms : Vec (Term alphabet) arity
-- -- -- -- -- -- open Predication
-- -- -- -- -- -- -}
-- -- module NotUsed where
-- -- -- thought it might be easier to use this
-- -- module UsingContainerList where
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : List (TermCode × TermNode)
-- -- number : Nat
-- -- open TermNode
-- -- _child∈_ : TermCode → TermNode → Set
-- -- _child∈_ 𝔠 𝔫 = Any ((𝔠 ≡_) ∘ fst) (children 𝔫)
-- -- -- this still has a lambda problem, albeit weirder
-- -- module RememberChildren where
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- tests : List TermCode
-- -- children : ∀ {𝔠} → 𝔠 ∈ tests → TermNode
-- -- number : Nat
-- -- open TermNode
-- -- addChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 ∉ tests 𝔫 → TermNode → TermNode
-- -- addChild {𝔠} 𝔫 𝔠∉tests𝔫 𝔫' =
-- -- record 𝔫
-- -- { tests = 𝔠 ∷ tests 𝔫
-- -- ; children = λ
-- -- { (here _) → 𝔫'
-- -- ; (there _ 𝔠'∈tests) → children 𝔫 𝔠'∈tests }}
-- -- setChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 ∈ tests 𝔫 → TermNode → TermNode
-- -- setChild {𝔠} 𝔫 𝔠∈tests𝔫 𝔫' =
-- -- record 𝔫
-- -- { children = λ {𝔠'} 𝔠'∈tests𝔫' → ifYes 𝔠' ≟ 𝔠 then 𝔫' else children 𝔫 𝔠'∈tests𝔫' }
-- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity Nat
-- -- storeTermCodes [] 𝔑 = return 𝔑
-- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case 𝔠 ∈? tests 𝔫 of λ
-- -- { (no 𝔠∉tests) →
-- -- let 𝔑' , 𝔫' = runIdentity $
-- -- runStateT
-- -- (storeTermCodes 𝔠s $ suc 𝔑)
-- -- (record
-- -- { tests = []
-- -- ; children = λ ()
-- -- ; number = suc 𝔑 }) in
-- -- put (addChild 𝔫 𝔠∉tests 𝔫') ~|
-- -- return 𝔑'
-- -- ; (yes 𝔠∈tests) →
-- -- let 𝔑' , 𝔫' = runIdentity $
-- -- runStateT
-- -- (storeTermCodes 𝔠s $ suc 𝔑)
-- -- (children 𝔫 𝔠∈tests) in
-- -- put (setChild 𝔫 𝔠∈tests 𝔫') ~|
-- -- return 𝔑' }
-- -- topNode : TermNode
-- -- topNode = record { tests = [] ; children = λ () ; number = 0 }
-- -- example-store : TermNode
-- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodes example-TermCodes 0) topNode
-- -- foo : TermNode × TermNode
-- -- foo =
-- -- {!example-store!} ,
-- -- {!snd ∘ runIdentity $ runStateT (storeTermCodes example-TermCodes 10) example-store!}
-- -- -- using a lambda for the children results in extra unnecessary structure when adding to an existing node; perhaps using an explicit mapping? or use another field to state what codes are present in the mapping?
-- -- module NoParents where
-- -- mutual
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : TermCode → Maybe TermNode -- Map TermCode TermNode
-- -- self : TermCode
-- -- number : Nat
-- -- record TopTermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : TermCode → Maybe TermNode
-- -- open TermNode
-- -- open TopTermNode
-- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity ⊤
-- -- storeTermCodes [] _ = return tt
-- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- storeTermCodesAtTop : List TermCode → Nat → StateT TopTermNode Identity ⊤
-- -- storeTermCodesAtTop [] _ = return tt
-- -- storeTermCodesAtTop (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- initialTopNode : TopTermNode
-- -- initialTopNode = record { children = const nothing }
-- -- example-store : TopTermNode
-- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 0) initialTopNode
-- -- foo : TopTermNode × TopTermNode
-- -- foo =
-- -- {!example-store!} ,
-- -- {!snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 10) example-store!}
-- -- -- it's tricky to keep the parents up to date when the children change (viz adolescence)
-- -- module FirstTryWithParent where
-- -- mutual
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- parent : TopTermNode ⊎ TermNode
-- -- self : TermCode
-- -- children : TermCode → Maybe TermNode -- Map TermCode TermNode
-- -- number : Nat
-- -- record TopTermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : TermCode → Maybe TermNode
-- -- open TermNode
-- -- open TopTermNode
-- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity ⊤
-- -- storeTermCodes [] _ = return tt
-- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { parent = right 𝔫
-- -- ; self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- storeTermCodesAtTop : List TermCode → Nat → StateT TopTermNode Identity ⊤
-- -- storeTermCodesAtTop [] _ = return tt
-- -- storeTermCodesAtTop (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { parent = left 𝔫
-- -- ; self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- initialTopNode : TopTermNode
-- -- initialTopNode = record { children = const nothing }
-- -- example-store : TopTermNode
-- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 0) initialTopNode
-- -- foo : TopTermNode
-- -- foo = {!example-store!}
-- --
-- --
-- -- _⟪_⟫_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
-- -- A → (A → B → C) → B → C
-- -- x ⟪ f ⟫ y = f x y
-- --
-- -- {-
-- -- infixr 9 _∘₂′_
-- -- _∘₂′_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
-- -- (C → D) → (A → B → C) → (A → B → D)
-- -- _∘₂′_ = _∘′_ ∘ _∘′_
-- -- {-# INLINE _∘₂′_ #-}
-- --
-- -- infixr 9 _∘₂′_
-- -- _∘₂′_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
-- -- (C → D) → (A → B → C) → (A → B → D)
-- -- _∘₂′_ = _∘′_ ∘ _∘′_
-- -- {-# INLINE _∘₂′_ #-}
-- -- -}
-- -- {-
-- -- infixr 9 _∘₂_
-- -- _∘₂_ : ∀ {a b c d} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c} {D : ∀ x → B x → C x
-- -- (f : ∀ {x} (y : B x) → C x y) (g : ∀ x → B x) →
-- -- ∀ x → C x (g x)
-- -- _∘₂_ = _∘′_ ∘ _∘′_
-- -- {-# INLINE _∘₂′_ #-}
-- -- -}
| 45.365282
| 405
| 0.508044
|
205707c4e9d237fa6a7cf17eba9555f550c3eb47
| 6,792
|
agda
|
Agda
|
src/JVM/Printer/Jasmin.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 6
|
2020-10-07T14:07:17.000Z
|
2021-02-28T21:49:08.000Z
|
src/JVM/Printer/Jasmin.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | null | null | null |
src/JVM/Printer/Jasmin.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.Printer.Jasmin where
open import Function
open import Data.Nat
open import Data.Integer
open import Data.Nat.Show as NatShow
open import Data.String as S using (String)
open import Data.List as List
open import JVM.Types
open import JVM.Builtins
sep : List (List String) → List String
sep = List.concat ∘ List.intersperse [ " " ]
Words = List String
abstract
Line = String
Lines = List String
unwords : Words → Line
unwords = S.unwords
line : String → Line
line = id
lines : List Line → Lines
lines = id
unlines : Lines → String
unlines = S.unlines
infixr 4 _<+_
_<+_ : Line → Lines → Lines
l <+ ls = l ∷ ls
infixl 6 _+>_
_+>_ : Lines → Line → Lines
ls +> l = ls ∷ʳ l
infixl 4 _<>_
_<>_ : Lines → Lines → Lines
ls <> js = ls ++ js
pars : List Lines → Lines
pars = concat
ident : Line → Line
ident = "\t" S.++_
indent : Lines → Lines
indent = List.map ident
record ClassSpec : Set where
constructor class
field
class_name : String
out : Line
out = unwords $ ".class" ∷ "public" ∷ class_name ∷ []
record SuperSpec : Set where
constructor super
field
class_name : String
out : Line
out = unwords $ ".super" ∷ class_name ∷ []
record Header : Set where
field
class_spec : ClassSpec
super_spec : SuperSpec
out : Lines
out = lines $ ClassSpec.out class_spec
∷ SuperSpec.out super_spec
∷ []
module Descriptor where
type-desc : Ty → String
type-desc boolean = "Z"
type-desc byte = "B"
type-desc short = "S"
type-desc int = "I"
type-desc long = "J"
type-desc char = "C"
type-desc (array t) = "[" S.++ type-desc t
type-desc (ref cls) = S.concat $ "L" ∷ cls ∷ ";" ∷ []
ret-desc : Ret → String
ret-desc void = "V"
ret-desc (ty t) = type-desc t
out : List Ty → Ret → String
out as r = args as S.++ ret-desc r
where
args : List Ty → String
args d = "(" S.++ (S.intersperse ";" (List.map type-desc d)) S.++ ")"
data Comparator : Set where
eq ne lt ge gt le : Comparator
icmpge icmpgt icmpeq icmpne icmplt icmple : Comparator
open import JVM.Types using (Fun)
module Comp where
out : Comparator → String
out eq = "eq"
out ne = "ne"
out lt = "lt"
out ge = "ge"
out gt = "gt"
out le = "le"
out icmpge = "_icmpge"
out icmpgt = "_icmpgt"
out icmpeq = "_icmpeq"
out icmpne = "_icmpne"
out icmplt = "_icmplt"
out icmple = "_icmple"
data Instr : Set where
nop pop dup swap ret : Instr
aconst_null : Instr
bipush sipush : ℤ → Instr
iconstm1 iconst0 iconst1 iconst2 : Instr
aaload aload iload : ℕ → Instr
aastore astore istore : ℕ → Instr
new : String → Instr
goto : String → Instr
if : Comparator → String → Instr
iadd isub imul idiv ixor : Instr
invokevirtual invokespecial invokestatic : Fun → Instr
module Funs where
out : Fun → String
out (c / m :⟨ as ⟩ r) = c S.++ "/" S.++ m S.++ Descriptor.out as r
module Instruction where
lbl : String → String
lbl x = "label_" S.++ x
showInt : ℤ → String
showInt (+ n) = NatShow.show n
showInt (-[1+ n ]) = "-" S.++ NatShow.show (ℕ.suc n)
out : Instr → Line
out nop = line "nop"
out pop = line "pop"
out dup = line "dup"
out swap = line "swap"
out ret = line "return"
out aconst_null = line "aconst_null"
out (bipush n) = unwords $ "sipush" ∷ showInt n ∷ []
out (sipush n) = unwords $ "bipush" ∷ showInt n ∷ []
out (aload n) = unwords $ "aload" ∷ NatShow.show n ∷ []
out (astore n) = unwords $ "astore" ∷ NatShow.show n ∷ []
out (iload n) = unwords $ "iload" ∷ NatShow.show n ∷ []
out (istore n) = unwords $ "istore" ∷ NatShow.show n ∷ []
out (aaload n) = unwords $ "aaload" ∷ NatShow.show n ∷ []
out (aastore n) = unwords $ "astore" ∷ NatShow.show n ∷ []
out iconstm1 = line "iconstm1"
out iconst0 = line "iconst_0"
out iconst1 = line "iconst_1"
out iconst2 = line "iconst_2"
out (goto l) = unwords $ "goto" ∷ lbl l ∷ []
out (if c l) = unwords $ ("if" S.++ Comp.out c) ∷ lbl l ∷ []
out iadd = line "iadd"
out isub = line "isub"
out imul = line "imul"
out idiv = line "idiv"
out ixor = line "ixor"
out (new c) = unwords $ "new" ∷ c ∷ []
out (invokespecial sf) = unwords $ "invokespecial" ∷ Funs.out sf ∷ []
out (invokestatic sf) = unwords $ "invokestatic" ∷ Funs.out sf ∷ []
out (invokevirtual sf) = unwords $ "invokevirtual" ∷ Funs.out sf ∷ []
data Stat : Set where
label : String → Stat
instr : Instr → Stat
module Statement where
out : Stat → Line
out (label x) = line $ Instruction.lbl x S.++ ":"
out (instr x) = Instruction.out x
record ClassField : Set where
constructor clsfield
field
name : String
access : List String
f_ty : Ty
out : Line
out = unwords
$ ".field"
∷ access
++ name
∷ Descriptor.type-desc f_ty
∷ []
record Method : Set where
constructor method
field
name : String
access : List String
locals : ℕ
stacksize : ℕ
m_args : List Ty
m_ret : Ret
body : List Stat
out : Lines
out = (unwords $ ".method" ∷ (S.unwords access) ∷ (name S.++ Descriptor.out m_args m_ret) ∷ [])
<+ (ident $ unwords $ ".limit locals" ∷ NatShow.show locals ∷ [])
<+ (ident $ unwords $ ".limit stack" ∷ NatShow.show stacksize ∷ [])
<+ (lines $ List.map (ident ∘ Statement.out) body)
+> (line $ ".end method")
record Jasmin : Set where
constructor jasmin
field
header : Header
fields : List ClassField
methods : List Method
out : Lines
out = Header.out header
<> lines (List.map ClassField.out fields)
<> pars (List.map Method.out methods)
module _ where
defaultInit : Method
defaultInit = method "<init>" [ "public" ] 1 1 [] void
( instr (aload 0)
∷ instr (invokespecial (Object / "<init>" :⟨ [] ⟩ void))
∷ instr ret
∷ []
)
procedure : (name : String) → ℕ → ℕ → List Stat → Jasmin
procedure name locals stack st =
jasmin
(record { class_spec = class name ; super_spec = super Object })
[]
( method "apply" ("public" ∷ "static" ∷ []) locals stack [] void (st ∷ʳ instr ret)
∷ defaultInit
∷ method "main" ("public" ∷ "static" ∷ []) 1 0 [ array (ref "java/lang/String") ] void
( instr (invokestatic (name / "apply" :⟨ [] ⟩ void))
∷ instr ret
∷ []
)
∷ []
)
| 24.698182
| 98
| 0.565518
|
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.