Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Instances.DiffInt where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Int.MoreInts.DiffInt renaming ( _+_ to _+ℤ_ ; _-_ to _-ℤ_)
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Semigroup.Base
open import Cubical.Algebra.Monoid.Base
open import Cubical.HITs.SetQuotients
open GroupStr
ℤ-isGroup : IsGroup {G = ℤ} ([ 0 , 0 ]) (_+ℤ_) (-ℤ_)
IsSemigroup.is-set (IsMonoid.isSemigroup (IsGroup.isMonoid ℤ-isGroup)) = ℤ-isSet
IsSemigroup.assoc (IsMonoid.isSemigroup (IsGroup.isMonoid ℤ-isGroup)) = +ℤ-assoc
IsMonoid.identity (IsGroup.isMonoid ℤ-isGroup) = λ x → (zero-identityʳ 0 x , zero-identityˡ 0 x)
IsGroup.inverse ℤ-isGroup = λ x → (-ℤ-invʳ x , -ℤ-invˡ x)
ℤGroup : Group₀
fst ℤGroup = ℤ
1g (snd ℤGroup) = [ 0 , 0 ]
_·_ (snd ℤGroup) = _+ℤ_
inv (snd ℤGroup) = -ℤ_
isGroup (snd ℤGroup) = ℤ-isGroup
| {
"alphanum_fraction": 0.7264573991,
"avg_line_length": 30.7586206897,
"ext": "agda",
"hexsha": "e5276df7ae733ecd827bd75a80b78751045ede3e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/Instances/DiffInt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/Instances/DiffInt.agda",
"max_line_length": 97,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/Instances/DiffInt.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 330,
"size": 892
} |
{-# OPTIONS --without-K --rewriting #-}
{- Remember to keep CodeBP.agda in sync. -}
open import HoTT
import homotopy.RelativelyConstantToSetExtendsViaSurjection as SurjExt
module homotopy.vankampen.CodeAP {i j k l}
(span : Span {i} {j} {k})
{D : Type l} (h : D → Span.C span) (h-is-surj : is-surj h) where
open Span span
data precodeAA (a₀ : A) : A → Type (lmax (lmax (lmax i j) k) l)
data precodeAB (a₀ : A) (b₁ : B) : Type (lmax (lmax (lmax i j) k) l)
data precodeAA a₀ where
pc-a : ∀ {a₁} (pA : a₀ =₀ a₁) → precodeAA a₀ a₁
pc-aba : ∀ d {a₁} (pc : precodeAB a₀ (g (h d))) (pA : f (h d) =₀ a₁) → precodeAA a₀ a₁
infix 66 pc-a
syntax pc-a p = ⟧a p
infixl 65 pc-aba
syntax pc-aba d pcAB pA = pcAB ab⟦ d ⟧a pA
data precodeAB a₀ b₁ where
pc-aab : ∀ d (pc : precodeAA a₀ (f (h d))) (pB : g (h d) =₀ b₁) → precodeAB a₀ b₁
infixl 65 pc-aab
syntax pc-aab d pcAA pB = pcAA aa⟦ d ⟧b pB
data precodeAA-rel {a₀ : A} : {a₁ : A}
→ precodeAA a₀ a₁ → precodeAA a₀ a₁ → Type (lmax (lmax (lmax i j) k) l)
data precodeAB-rel {a₀ : A} : {b₁ : B}
→ precodeAB a₀ b₁ → precodeAB a₀ b₁ → Type (lmax (lmax (lmax i j) k) l)
data precodeAA-rel {a₀} where
pcAAr-idp₀-idp₀ : ∀ {d} pcAA → precodeAA-rel (pcAA aa⟦ d ⟧b idp₀ ab⟦ d ⟧a idp₀) pcAA
pcAAr-cong : ∀ {d a₁ pcAB₁ pcAB₂} (r : precodeAB-rel pcAB₁ pcAB₂) (pA : f (h d) =₀ a₁)
→ precodeAA-rel (pcAB₁ ab⟦ d ⟧a pA) (pcAB₂ ab⟦ d ⟧a pA)
data precodeAB-rel {a₀} where
pcABr-idp₀-idp₀ : ∀ {d} pcAB → precodeAB-rel (pcAB ab⟦ d ⟧a idp₀ aa⟦ d ⟧b idp₀) pcAB
pcABr-switch : ∀ {d₀ d₁ : D} pcAB (pC : h d₀ =₀ h d₁)
→ precodeAB-rel (pcAB ab⟦ d₀ ⟧a ap₀ f pC aa⟦ d₁ ⟧b idp₀) (pcAB ab⟦ d₀ ⟧a idp₀ aa⟦ d₀ ⟧b ap₀ g pC)
pcABr-cong : ∀ {d b₁ pcAA₁ pcAA₂} (r : precodeAA-rel pcAA₁ pcAA₂) (pB : g (h d) =₀ b₁)
→ precodeAB-rel (pcAA₁ aa⟦ d ⟧b pB) (pcAA₂ aa⟦ d ⟧b pB)
codeAA : A → A → Type (lmax (lmax (lmax i j) k) l)
codeAA a₀ a₁ = SetQuot (precodeAA-rel {a₀} {a₁})
codeAB : A → B → Type (lmax (lmax (lmax i j) k) l)
codeAB a₀ b₁ = SetQuot (precodeAB-rel {a₀} {b₁})
c-aba : ∀ {a₀} d {a₁} (pc : codeAB a₀ (g (h d))) (pA : f (h d) =₀ a₁) → codeAA a₀ a₁
c-aba d {a₁} c pA = SetQuot-rec SetQuot-is-set
(λ pc → q[ pc-aba d pc pA ])
(λ r → quot-rel $ pcAAr-cong r pA) c
c-aab : ∀ {a₀} d {b₁} (pc : codeAA a₀ (f (h d))) (pB : g (h d) =₀ b₁) → codeAB a₀ b₁
c-aab d {a₁} c pB = SetQuot-rec SetQuot-is-set
(λ pc → q[ pc-aab d pc pB ])
(λ r → quot-rel $ pcABr-cong r pB) c
-- codeAP
abstract
pcAA-idp₀-idp₀-head : ∀ {d₀ a} (pA : f (h d₀) =₀ a)
→ q[ ⟧a idp₀ aa⟦ d₀ ⟧b idp₀ ab⟦ d₀ ⟧a pA ] == q[ ⟧a pA ] :> codeAA _ a
pcAA-idp₀-idp₀-head {d₀} = Trunc-elim (λ _ → =-preserves-set SetQuot-is-set) lemma where
lemma : ∀ {a} (pA : f (h d₀) == a)
→ q[ ⟧a idp₀ aa⟦ d₀ ⟧b idp₀ ab⟦ d₀ ⟧a [ pA ] ] == q[ ⟧a [ pA ] ] :> codeAA _ a
lemma idp = quot-rel $ pcAAr-idp₀-idp₀ (⟧a idp₀)
pcAA-prepend : ∀ {a₀} d₁ {a₂} → a₀ =₀ f (h d₁) → precodeAA (f (h d₁)) a₂ → precodeAA a₀ a₂
pcAB-prepend : ∀ {a₀} d₁ {b₂} → a₀ =₀ f (h d₁) → precodeAB (f (h d₁)) b₂ → precodeAB a₀ b₂
pcAA-prepend d₁ pA (pc-a pA₁) = pc-aba d₁ (pc-aab d₁ (pc-a pA) idp₀) pA₁
pcAA-prepend d₁ pA (pc-aba d pc pA₁) = pc-aba d (pcAB-prepend d₁ pA pc) pA₁
pcAB-prepend d₁ pA (pc-aab d pc pB) = pc-aab d (pcAA-prepend d₁ pA pc) pB
abstract
pcAA-prepend-idp₀ : ∀ {d₀ a₁} (pcAA : precodeAA (f (h d₀)) a₁)
→ q[ pcAA-prepend d₀ idp₀ pcAA ] == q[ pcAA ] :> codeAA (f (h d₀)) a₁
pcAB-prepend-idp₀ : ∀ {d₀ b₁} (pcAB : precodeAB (f (h d₀)) b₁)
→ q[ pcAB-prepend d₀ idp₀ pcAB ] == q[ pcAB ] :> codeAB (f (h d₀)) b₁
pcAA-prepend-idp₀ (pc-a pA) = pcAA-idp₀-idp₀-head pA
pcAA-prepend-idp₀ (pc-aba d pc pA) = pcAB-prepend-idp₀ pc |in-ctx λ c → c-aba d c pA
pcAB-prepend-idp₀ (pc-aab d pc pA) = pcAA-prepend-idp₀ pc |in-ctx λ c → c-aab d c pA
transp-cAA-l : ∀ d {a₀ a₁} (p : f (h d) == a₀) (pcAA : precodeAA (f (h d)) a₁)
→ transport (λ x → codeAA x a₁) p q[ pcAA ] == q[ pcAA-prepend d [ ! p ] pcAA ]
transp-cAA-l d idp pcAA = ! $ pcAA-prepend-idp₀ pcAA
transp-cAB-l : ∀ d {a₀ b₁} (p : f (h d) == a₀) (pcAB : precodeAB (f (h d)) b₁)
→ transport (λ x → codeAB x b₁) p q[ pcAB ] == q[ pcAB-prepend d [ ! p ] pcAB ]
transp-cAB-l d idp pcAB = ! $ pcAB-prepend-idp₀ pcAB
transp-cAA-r : ∀ d {a₀ a₁} (p : f (h d) == a₁) (pcAA : precodeAA a₀ (f (h d)))
→ transport (λ x → codeAA a₀ x) p q[ pcAA ] == q[ pcAA aa⟦ d ⟧b idp₀ ab⟦ d ⟧a [ p ] ]
transp-cAA-r d idp pcAA = ! $ quot-rel $ pcAAr-idp₀-idp₀ pcAA
transp-cAB-r : ∀ d {a₀ b₁} (p : g (h d) == b₁) (pcAB : precodeAB a₀ (g (h d)))
→ transport (λ x → codeAB a₀ x) p q[ pcAB ] == q[ pcAB ab⟦ d ⟧a idp₀ aa⟦ d ⟧b [ p ] ]
transp-cAB-r d idp pcAB = ! $ quot-rel $ pcABr-idp₀-idp₀ pcAB
module CodeAAEquivCodeAB (a₀ : A) where
eqv-on-image : (d : D) → codeAA a₀ (f (h d)) ≃ codeAB a₀ (g (h d))
eqv-on-image d = equiv to from to-from from-to where
to = λ c → c-aab d c idp₀
from = λ c → c-aba d c idp₀
abstract
from-to : ∀ cAA → from (to cAA) == cAA
from-to = SetQuot-elim
(λ _ → =-preserves-set SetQuot-is-set)
(λ pcAA → quot-rel (pcAAr-idp₀-idp₀ pcAA))
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))
to-from : ∀ cAB → to (from cAB) == cAB
to-from = SetQuot-elim
(λ _ → =-preserves-set SetQuot-is-set)
(λ pcAB → quot-rel (pcABr-idp₀-idp₀ pcAB))
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))
abstract
eqv-is-const : ∀ d₁ d₂ (p : h d₁ == h d₂)
→ eqv-on-image d₁ == eqv-on-image d₂
[ (λ c → codeAA a₀ (f c) ≃ codeAB a₀ (g c)) ↓ p ]
eqv-is-const d₁ d₂ p = ↓-Subtype-in (λ d → is-equiv-prop) $
↓-→-from-transp $ λ= $
SetQuot-elim (λ _ → =-preserves-set SetQuot-is-set)
(λ pcAA →
transport (λ c → codeAB a₀ (g c)) p q[ pcAA aa⟦ d₁ ⟧b idp₀ ]
=⟨ ap-∘ (codeAB a₀) g p |in-ctx (λ p → coe p q[ pcAA aa⟦ d₁ ⟧b idp₀ ]) ⟩
transport (codeAB a₀) (ap g p) q[ pcAA aa⟦ d₁ ⟧b idp₀ ]
=⟨ transp-cAB-r d₁ (ap g p) (pcAA aa⟦ d₁ ⟧b idp₀) ⟩
q[ pcAA aa⟦ d₁ ⟧b idp₀ ab⟦ d₁ ⟧a idp₀ aa⟦ d₁ ⟧b [ ap g p ] ]
=⟨ ! $ quot-rel $ pcABr-switch (pcAA aa⟦ d₁ ⟧b idp₀) [ p ] ⟩
q[ pcAA aa⟦ d₁ ⟧b idp₀ ab⟦ d₁ ⟧a [ ap f p ] aa⟦ d₂ ⟧b idp₀ ]
=⟨ ! $ transp-cAA-r d₁ (ap f p) pcAA |in-ctx (λ c → c-aab d₂ c idp₀) ⟩
c-aab d₂ (transport (codeAA a₀) (ap f p) q[ pcAA ]) idp₀
=⟨ ∘-ap (codeAA a₀) f p |in-ctx (λ p → coe p q[ pcAA ]) |in-ctx (λ c → c-aab d₂ c idp₀) ⟩
c-aab d₂ (transport (λ c → codeAA a₀ (f c)) p q[ pcAA ]) idp₀
=∎)
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))
module SE = SurjExt
(λ c → ≃-is-set SetQuot-is-set SetQuot-is-set)
h h-is-surj
eqv-on-image
eqv-is-const
abstract
eqv : ∀ c → codeAA a₀ (f c) ≃ codeAB a₀ (g c)
eqv = SE.ext
eqv-β : ∀ d → eqv (h d) == eqv-on-image d
eqv-β = SE.β
module CodeAP (a₀ : A) = PushoutRec (codeAA a₀) (codeAB a₀)
(ua ∘ CodeAAEquivCodeAB.eqv a₀)
codeAP : A → Pushout span → Type (lmax (lmax (lmax i j) k) l)
codeAP = CodeAP.f
abstract
codeAP-level : ∀ {a₀ p₁} → is-set (codeAP a₀ p₁)
codeAP-level {a₀} {p₁} = Pushout-elim
{P = λ p₁ → is-set (codeAP a₀ p₁)}
(λ a₁ → SetQuot-is-set)
(λ b₁ → SetQuot-is-set)
(λ c₁ → prop-has-all-paths-↓ is-set-is-prop)
p₁
codeAP-is-set = codeAP-level
abstract
transp-cAP-glue : ∀ {a₀} d₁ (pcAA : precodeAA a₀ (f (h d₁)))
→ transport (codeAP a₀) (glue (h d₁)) q[ pcAA ] == q[ pcAA aa⟦ d₁ ⟧b idp₀ ]
transp-cAP-glue {a₀} d₁ pcAA =
transport (codeAP a₀) (glue (h d₁)) q[ pcAA ]
=⟨ ap (λ e → coe e q[ pcAA ]) (CodeAP.glue-β a₀ (h d₁) ∙ ap ua (CodeAAEquivCodeAB.eqv-β a₀ d₁)) ⟩
coe (ua (CodeAAEquivCodeAB.eqv-on-image a₀ d₁)) q[ pcAA ]
=⟨ coe-β (CodeAAEquivCodeAB.eqv-on-image a₀ d₁) q[ pcAA ] ⟩
q[ pcAA aa⟦ d₁ ⟧b idp₀ ]
=∎
transp-cAP-!glue : ∀ {a₀} d₁ (pcAB : precodeAB a₀ (g (h d₁)))
→ transport (codeAP a₀) (! (glue (h d₁))) q[ pcAB ] == q[ pcAB ab⟦ d₁ ⟧a idp₀ ]
transp-cAP-!glue {a₀} d₁ pcAB =
transport (codeAP a₀) (! (glue (h d₁))) q[ pcAB ]
=⟨ ap (λ e → coe e q[ pcAB ]) (ap-! (codeAP a₀) (glue (h d₁)))
∙ coe-! (ap (codeAP a₀) (glue (h d₁))) q[ pcAB ] ⟩
transport! (codeAP a₀) (glue (h d₁)) q[ pcAB ]
=⟨ ap (λ e → coe! e q[ pcAB ]) (CodeAP.glue-β a₀ (h d₁) ∙ ap ua (CodeAAEquivCodeAB.eqv-β a₀ d₁)) ⟩
coe! (ua (CodeAAEquivCodeAB.eqv-on-image a₀ d₁)) q[ pcAB ]
=⟨ coe!-β (CodeAAEquivCodeAB.eqv-on-image a₀ d₁) q[ pcAB ] ⟩
q[ pcAB ab⟦ d₁ ⟧a idp₀ ]
=∎
-- code to path
pcAA-to-path : ∀ {a₀ a₁} → precodeAA a₀ a₁ → left a₀ =₀ left a₁ :> Pushout span
pcAB-to-path : ∀ {a₀ b₁} → precodeAB a₀ b₁ → left a₀ =₀ right b₁ :> Pushout span
pcAA-to-path (pc-a pA) = ap₀ left pA
pcAA-to-path (pc-aba d pc pA) = pcAB-to-path pc ∙₀' !₀ [ glue (h d) ] ∙₀' ap₀ left pA
pcAB-to-path (pc-aab d pc pB) = pcAA-to-path pc ∙₀' [ glue (h d) ] ∙₀' ap₀ right pB
abstract
pcAA-to-path-rel : ∀ {a₀ a₁} {pcAA₀ pcAA₁ : precodeAA a₀ a₁}
→ precodeAA-rel pcAA₀ pcAA₁ → pcAA-to-path pcAA₀ == pcAA-to-path pcAA₁
pcAB-to-path-rel : ∀ {a₀ b₁} {pcAB₀ pcAB₁ : precodeAB a₀ b₁}
→ precodeAB-rel pcAB₀ pcAB₁ → pcAB-to-path pcAB₀ == pcAB-to-path pcAB₁
pcAA-to-path-rel (pcAAr-idp₀-idp₀ pcAA) =
∙₀'-assoc (pcAA-to-path pcAA) [ glue (h _) ] [ ! (glue (h _)) ]
∙ ap (λ p → pcAA-to-path pcAA ∙₀' [ p ]) (!-inv'-r (glue (h _)))
∙ ∙₀'-unit-r (pcAA-to-path pcAA)
pcAA-to-path-rel (pcAAr-cong pcAB pA) = pcAB-to-path-rel pcAB |in-ctx _∙₀' !₀ [ glue (h _) ] ∙₀' ap₀ left pA
pcAB-to-path-rel (pcABr-idp₀-idp₀ pcAB) =
∙₀'-assoc (pcAB-to-path pcAB) [ ! (glue (h _)) ] [ glue (h _) ]
∙ ap (λ p → pcAB-to-path pcAB ∙₀' [ p ]) (!-inv'-l (glue (h _)))
∙ ∙₀'-unit-r (pcAB-to-path pcAB)
pcAB-to-path-rel (pcABr-switch pcAB pC) =
ap (_∙₀' [ glue (h _) ]) (! (∙₀'-assoc (pcAB-to-path pcAB) [ ! (glue (h _)) ] (ap₀ left (ap₀ f pC))))
∙ ∙₀'-assoc (pcAB-to-path pcAB ∙₀' [ ! (glue (h _)) ]) (ap₀ left (ap₀ f pC)) [ glue (h _) ]
∙ ap ((pcAB-to-path pcAB ∙₀' [ ! (glue (h _)) ]) ∙₀'_) (natural₀ pC)
where
natural : ∀ {c₀ c₁} (p : c₀ == c₁)
→ (ap left (ap f p) ∙' glue c₁) == (glue c₀ ∙' ap right (ap g p))
:> (left (f c₀) == right (g c₁) :> Pushout span)
natural idp = ∙'-unit-l (glue _)
natural₀ : ∀ {c₀ c₁} (p : c₀ =₀ c₁)
→ (ap₀ left (ap₀ f p) ∙₀' [ glue c₁ ]) == ([ glue c₀ ] ∙₀' ap₀ right (ap₀ g p))
:> (left (f c₀) =₀ right (g c₁) :> Pushout span)
natural₀ = Trunc-elim (λ _ → =-preserves-set Trunc-level) (ap [_] ∘ natural)
pcAB-to-path-rel (pcABr-cong pcAA pB) = pcAA-to-path-rel pcAA |in-ctx _∙₀' [ glue (h _) ] ∙₀' ap₀ right pB
decodeAA : ∀ {a₀ a₁} → codeAA a₀ a₁ → left a₀ =₀ left a₁ :> Pushout span
decodeAB : ∀ {a₀ b₁} → codeAB a₀ b₁ → left a₀ =₀ right b₁ :> Pushout span
decodeAA = SetQuot-rec Trunc-level pcAA-to-path pcAA-to-path-rel
decodeAB = SetQuot-rec Trunc-level pcAB-to-path pcAB-to-path-rel
abstract
decodeAA-is-decodeAB : ∀ {a₀} c₁ →
decodeAA {a₀} {f c₁} == decodeAB {a₀} {g c₁}
[ (λ p₁ → codeAP a₀ p₁ → left a₀ =₀ p₁) ↓ glue c₁ ]
decodeAA-is-decodeAB {a₀ = a₀} = SurjExt.ext
(λ _ → ↓-preserves-level $ Π-is-set λ _ → Trunc-level) h h-is-surj
(λ d₁ → ↓-→-from-transp $ λ= $ SetQuot-elim
{P = λ cAA → transport (left a₀ =₀_) (glue (h d₁)) (decodeAA cAA)
== decodeAB (transport (codeAP a₀) (glue (h d₁)) cAA)}
(λ _ → =-preserves-set Trunc-level)
(λ pcAA →
transport (left a₀ =₀_) (glue (h d₁)) (pcAA-to-path pcAA)
=⟨ transp₀-cst=₀idf [ glue (h d₁) ] (pcAA-to-path pcAA) ⟩
pcAA-to-path pcAA ∙₀' [ glue (h d₁) ]
=⟨ ! $ ap (λ e → decodeAB (–> e q[ pcAA ])) (CodeAAEquivCodeAB.eqv-β a₀ d₁) ⟩
decodeAB (–> (CodeAAEquivCodeAB.eqv a₀ (h d₁)) q[ pcAA ])
=⟨ ! $ ap decodeAB (coe-β (CodeAAEquivCodeAB.eqv a₀ (h d₁)) q[ pcAA ]) ⟩
decodeAB (coe (ua (CodeAAEquivCodeAB.eqv a₀ (h d₁))) q[ pcAA ])
=⟨ ! $ ap (λ p → decodeAB (coe p q[ pcAA ])) (CodeAP.glue-β a₀ (h d₁)) ⟩
decodeAB (transport (codeAP a₀) (glue (h d₁)) q[ pcAA ])
=∎)
(λ _ → prop-has-all-paths-↓ $ Trunc-level {n = 0} _ _))
(λ _ _ _ → prop-has-all-paths-↓ $ ↓-level $ Π-is-set λ _ → Trunc-level)
decodeAP : ∀ {a₀ p₁} → codeAP a₀ p₁ → left a₀ =₀ p₁
decodeAP {p₁ = p₁} = Pushout-elim
(λ a₁ → decodeAA) (λ b₁ → decodeAB)
decodeAA-is-decodeAB
p₁
| {
"alphanum_fraction": 0.5404271845,
"avg_line_length": 47.6851851852,
"ext": "agda",
"hexsha": "9131de1c9617bb44170c717ee9a533ef39130001",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/vankampen/CodeAP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/vankampen/CodeAP.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/vankampen/CodeAP.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5715,
"size": 12875
} |
{-# OPTIONS --without-K #-}
-- this is mostly reference for an unused intermediate step.
module Cauchy2 where
open import Data.Nat
open import Data.Vec renaming (map to mapV; _++_ to _++V_; concat to concatV)
open import Data.Fin using (Fin; inject+; raise; inject≤; fromℕ; toℕ)
open import Function using (id)
open import Relation.Binary.PropositionalEquality using (_≡_; subst)
open import VectorLemmas
open import LeqLemmas
open import Cauchy using (id+)
Cauchy : ℕ → ℕ → Set
Cauchy n₁ n₂ = Vec (Fin n₁) n₂
------------------------------------------------------------------------------
-- Elementary permutations in the Cauchy representation
emptycauchy : Cauchy 0 0
emptycauchy = []
idcauchy : (n : ℕ) → Cauchy n n
idcauchy = allFin
-- Sequential composition
scompcauchy : ∀ {n₀ n₁ n₂} → Cauchy n₁ n₀ → Cauchy n₂ n₁ → Cauchy n₂ n₀
scompcauchy {n} perm₁ perm₂ =
tabulate (λ i → lookup (lookup i perm₁) perm₂)
-- swap the first m elements with the last n elements
-- [ v₀ , v₁ , v₂ , ... , vm-1 , vm , vm₊₁ , ... , vm+n-1 ]
-- ==>
-- [ vm , vm₊₁ , ... , vm+n-1 , v₀ , v₁ , v₂ , ... , vm-1 ]
swap+cauchy : (m n : ℕ) → Cauchy (m + n) (n + m)
swap+cauchy m n = {!!} -- tabulate swapper
-- Parallel additive composition
-- append both permutations but adjust the indices in the second
-- permutation by the size of the first type so that it acts on the
-- second part of the vector
pcompcauchy : ∀ {m₁ n₁ m₂ n₂} → Cauchy m₁ m₂ → Cauchy n₁ n₂ → Cauchy (m₁ + n₁) (m₂ + n₂)
pcompcauchy {m} {n} α β = mapV (inject+ n) α ++V mapV (raise m) β
-- Tensor multiplicative composition
-- Transpositions in α correspond to swapping entire rows
-- Transpositions in β correspond to swapping entire columns
tcompcauchy : ∀ {m₁ n₁ m₂ n₂} → Cauchy m₁ m₂ → Cauchy n₁ n₂ → Cauchy (m₁ * n₁) (m₂ * n₂)
tcompcauchy {m} {n} α β =
concatV
(mapV
(λ b →
mapV (λ d → inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d)) β)
α)
-- swap⋆
--
-- This is essentially the classical problem of in-place matrix transpose:
-- "http://en.wikipedia.org/wiki/In-place_matrix_transposition"
-- Given m and n, the desired permutation in Cauchy representation is:
-- P(i) = m*n-1 if i=m*n-1
-- = m*i mod m*n-1 otherwise
transposeIndex : (m n : ℕ) →
(b : Fin m) → (d : Fin n) → Fin (n * m)
transposeIndex m n b d =
inject≤ (fromℕ (toℕ d * m + toℕ b))
(i*n+k≤m*n d b)
{- inject≤
(fromℕ (toℕ d * m + toℕ b))
(trans≤ (i*n+k≤m*n d b) (refl′ (*-comm n m))) -}
swap⋆cauchy : (m₁ n₁ m₂ n₂ : ℕ) → (meq : m₂ ≡ m₁) → (neq : n₂ ≡ n₁) → Cauchy (n₁ * m₁) (n₂ * m₂)
swap⋆cauchy m₁ n₁ m₂ n₂ meq neq =
concatV (mapV
(λ d → mapV (λ b → transposeIndex m₁ n₁ (subst Fin meq b) (subst Fin neq d)) (allFin m₂))
(allFin n₂))
| {
"alphanum_fraction": 0.6117945007,
"avg_line_length": 33.3012048193,
"ext": "agda",
"hexsha": "595a2bd1f4cf569782a017b6fc64f368110792bb",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/Cauchy2.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/Cauchy2.agda",
"max_line_length": 100,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/Cauchy2.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 1017,
"size": 2764
} |
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import lib.Basics
open import lib.types.Truncation
open import lib.types.Fin
open import lib.types.Nat
open import lib.types.Empty
open import lib.types.Unit
open import lib.types.Coproduct
open import lib.types.Sigma
open import lib.types.Paths
open import lib.NConnected
open import Util.Misc
open import Util.Finite
open import Util.Coproducts
open import Graphs.Definition
open import Graphs.Properties
open import Coequalizers.Definition
open import Coequalizers.PreserveEquivalence
open import Coequalizers.EdgeCoproduct
open import Coequalizers.Misc
open import Graphs.SubTrees
{- We show that graphs with finite vertex set have spanning trees. -}
module Graphs.SpanningTreeFinite {i : ULevel} where
module _ (E : Type i) (V : Type i) ⦃ gph : Graph E V ⦄ where
instance
noedges : {j : ULevel} {V : Type j} → Graph ⊥ V -- defines the trivial coequalizer V / ⊥
noedges = record { π₀ = ⊥-elim ; π₁ = ⊥-elim }
noedge-triv : {j : ULevel} {V : Type j} → V / ⊥ ≃ V
noedge-triv {V = V} = f , (record { g = c[_] ; f-g = f-g ; g-f = g-f ; adj = adj })
where
f : V / ⊥ → V
f = Coeq-rec (idf V) (λ _ → idp)
f-g : (v : V) → (f (c[ v ]) == v)
f-g v = idp
g-f : (z : V / ⊥) → (c[ (f z) ] == z)
g-f = Coeq-elim _ (λ _ → idp) ⊥-elim
adj : (z : V / ⊥) → ap f (g-f z) == idp
adj = Coeq-elim _ (λ _ → idp) ⊥-elim
{- A spanning tree is a subtree where the inclusion of vertex sets is an
equivalence and the inclusion of edge sets is complemented.
-}
record SpanningTree {j k l : ULevel} (E : Type i) (V : Type j) ⦃ gph : Graph E V ⦄
(E' : Type k) (V' : Type l) : Type (lmax (lmax i j) (lmax l k)) where
field
is-st : SubTree E V E' V'
open SubTree is-st public
field
all-vertices : is-equiv inU
is-complemented : E ≃ E' ⊔ Σ E (λ e → ¬ (hfiber inD e))
inD-comm : inD ∼ (<– is-complemented) ∘ inl
module ExtendSpanningTree {j k l : ULevel} (E : Type i) (V : Type j) ⦃ gph : Graph E V ⦄
(E' : Type k) (V' : Type l) (spantree : SpanningTree E V E' V') where
open SpanningTree spantree
¬E' = Σ E (λ e → ¬ (hfiber (SubTree.inD is-st) e))
instance
gph-coprod : Graph (E' ⊔ ¬E') V'
gph-coprod = record { π₀ = ⊔-rec π₀ λ e → is-equiv.g all-vertices (π₀ (<– is-complemented (inr e)))
; π₁ = ⊔-rec π₁ λ e → is-equiv.g all-vertices (π₁ (<– is-complemented (inr e))) }
inU-equiv : V' ≃ V
inU-equiv = (inU , all-vertices)
spantree-equiv : V / E ≃ V' / (E' ⊔ ¬E')
spantree-equiv = (Coeq-emap inU-equiv (is-complemented ⁻¹)
(λ { (inl e') → ! (comm₀ e') ∙ ap π₀ (inD-comm e') ; (inr x) → <–-inv-r inU-equiv _})
λ { (inl e') → ! (comm₁ e') ∙ ap π₁ (inD-comm e') ; (inr x) → <–-inv-r inU-equiv _}) ⁻¹
composepp : {j k l : ULevel} {E' : Type j} {E : Type k} {V : Type l} ( inc : E' → E ) ⦃ gph : Graph E V ⦄ → Graph E' V
composepp inc ⦃ gph = gph ⦄ = record { π₀ = P.π₀ ∘ inc ; π₁ = P.π₁ ∘ inc }
where
module P = Graph gph
Fin-equiv-Unit : Fin 1 ≃ ⊤
Fin-equiv-Unit =
Fin 1
≃⟨ Fin-equiv-Coprod ⟩
Fin 0 ⊔ ⊤
≃⟨ ⊔-emap Fin-equiv-Empty (ide ⊤) ⟩
⊥ ⊔ ⊤
≃⟨ ⊔₁-Empty ⊤ ⟩
⊤
≃∎
compose-equiv-subtree-l : {j k l m n : ULevel} {E : Type i} {V : Type j} ⦃ gph : Graph E V ⦄
(D : Type k) (U : Type l) (D' : Type m) (U' : Type n) → (D' ≃ D) → (U' ≃ U) →
SubTree E V D U → SubTree E V D' U'
compose-equiv-subtree-l D U D' U' equivD equivU (subtree inD inU D-inj U-inj U-dec comm₀ comm₁) =
subtree (inD ∘ –> equivD) (inU ∘ –> equivU) (∘-is-inj D-inj (–>-is-inj equivD)) (∘-is-inj U-inj (–>-is-inj equivU))
(λ v → ⊔-rec (λ {(u , p) → inl ((<– equivU u) , (ap inU (<–-inv-r equivU u) ∙ p))})
(λ f → inr (λ {(u , p) → f ((–> equivU u) , p) })) (U-dec v))
(λ d → comm₀ (–> equivD d) ∙ ap inU (! (<–-inv-r equivU _)))
(λ d → comm₁ (–> equivD d) ∙ ap inU (! (<–-inv-r equivU _)))
where
instance
gph' : Graph D' U'
gph' = record { π₀ = λ d → <– equivU (π₀ (–> equivD d)) ; π₁ = λ d → <– equivU (π₁ (–> equivD d)) }
c : is-contr (U' / D')
c = equiv-preserves-level ((Coeq-emap equivU equivD (λ d → <–-inv-r equivU _) λ d → <–-inv-r equivU _) ⁻¹)
{- Since the vertex set is finite, we can build the spanning tree up a step at a time. -}
build-spanning-tree : (E : Type i) (n : ℕ) ⦃ gph : Graph E (Fin (S n)) ⦄ ⦃ conn : gph-is-connected gph ⦄ →
(k : ℕ) → (k < S n) → ∥ SubTree E (Fin (S n)) (Fin k) (Fin (S k)) ∥
build-spanning-tree E n O l =
[ compose-equiv-subtree-l _ _ _ _ Fin-equiv-Empty Fin-equiv-Unit t ]
where
instance
ic : is-contr (⊤ / ⊥)
ic = equiv-preserves-level (noedge-triv ⁻¹)
t : SubTree E (Fin (S n)) ⊥ ⊤
t = subtree ⊥-elim (λ _ → 0 , l) ⊥-elim (λ {unit unit _ → idp}) (λ v → ⊔-fmap (λ p → unit , (! p)) (λ {f (unit , p) → f (! p)}) (Fin-has-dec-eq v (0 , l)))
⊥-elim ⊥-elim
build-spanning-tree E n (S k) l =
do
ih ← (build-spanning-tree E n k (<-trans ltS l))
let x = Fin-smaller-is-smaller l (SubTree.inU ih)
t ← (extend-subtree E (Fin (S n)) Fin-has-dec-eq ih (fst x) (snd x))
[ compose-equiv-subtree-l _ _ _ _ (⊔-sym ∘e Fin-equiv-Coprod) Fin-equiv-Coprod t ]
spanning-tree : (E : Type i) (Edec : has-dec-eq E) (n : ℕ) ⦃ gph : Graph E (Fin (S n)) ⦄ ⦃ conn : gph-is-connected gph ⦄ →
∥ SpanningTree E (Fin (S n)) (Fin n) (Fin (S n)) ∥
spanning-tree E Edec n = Trunc-fmap from-subtree (build-spanning-tree E _ _ ltS)
where
from-subtree : SubTree E (Fin (S n)) (Fin n) (Fin (S n)) → SpanningTree E (Fin (S n)) (Fin n) (Fin (S n))
from-subtree st@(subtree ⦃ gphDU ⦄ inD inU D-inj U-inj U-dec comm₀ comm₁) =
record
{ is-st = st
; all-vertices = Fin-inj-to-equiv inU U-inj
; is-complemented = dec-img-to-⊔ inD D-inj (Fin-hfiber-dec Edec inD) ⁻¹
; inD-comm = λ _ → idp
}
| {
"alphanum_fraction": 0.5599797537,
"avg_line_length": 37.5126582278,
"ext": "agda",
"hexsha": "62df9649813bea30b54cd2118c835a6868b8e928",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Graphs/SpanningTreeFinite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Graphs/SpanningTreeFinite.agda",
"max_line_length": 159,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Graphs/SpanningTreeFinite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2345,
"size": 5927
} |
{-# OPTIONS --universe-polymorphism #-}
module SortDependingOnIndex where
open import Imports.Level
data Bad : (l : Level) → Set l where
| {
"alphanum_fraction": 0.7338129496,
"avg_line_length": 19.8571428571,
"ext": "agda",
"hexsha": "6dfa7c6fdf28bdb96f8c3686dae0a15fa2f11614",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/fail/SortDependingOnIndex.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/fail/SortDependingOnIndex.agda",
"max_line_length": 39,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/SortDependingOnIndex.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 34,
"size": 139
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Orders.Total.Definition
open import Orders.Total.Lemmas
open import Maybe
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Vectors
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
module KeyValue.LinearStore.Implementation {a b c} (keySet : Set a) (valueSet : Set b) (keyOrder : TotalOrder {_} keySet {c}) where
record ReducedMap (min : keySet) : Set (a ⊔ b ⊔ c)
record ReducedMap min where
inductive
field
firstEntry : valueSet
next : Maybe (Sg keySet (λ nextKey → (ReducedMap nextKey) && (TotalOrder._<_ keyOrder min nextKey)))
addReducedMap : {min : keySet} → (k : keySet) → (v : valueSet) → (m : ReducedMap min) → ReducedMap (TotalOrder.min keyOrder min k)
addReducedMap {min} k v m with TotalOrder.totality keyOrder min k
addReducedMap {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) = record { firstEntry = firstEntry ; next = yes (k , (record { firstEntry = v ; next = no} ,, min<k))}
addReducedMap {min} k v record { firstEntry = minVal ; next = yes (nextKey , (m ,, pr)) } | inl (inl min<k) = record { firstEntry = minVal ; next = yes ((TotalOrder.min keyOrder nextKey k) , (addReducedMap {_} k v m ,, minFromBoth keyOrder pr min<k))}
addReducedMap {min} k v record { firstEntry = firstEntry ; next = next } | inl (inr k<min) = record { firstEntry = v ; next = yes (min , (record { firstEntry = firstEntry ; next = next } ,, k<min)) }
addReducedMap {min} k v record { firstEntry = firstEntry ; next = next } | inr min=k rewrite min=k = record { firstEntry = v ; next = next }
lookupReduced : {min : keySet} → (m : ReducedMap min) → (target : keySet) → Maybe valueSet
lookupReduced {min} m k with TotalOrder.totality keyOrder min k
lookupReduced {min} record { firstEntry = firstEntry ; next = no } k | inl (inl min<k) = no
lookupReduced {min} record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, _))) } k | inl (inl min<k) = lookupReduced {newMin} m k
lookupReduced {min} m k | inl (inr k<min) = no
lookupReduced {min} record { firstEntry = firstEntry ; next = next } k | inr min=k = yes firstEntry
countReduced : {min : keySet} → (m : ReducedMap min) → ℕ
countReduced record { firstEntry = firstEntry ; next = no } = 1
countReduced record { firstEntry = firstEntry ; next = (yes (key , (m ,, pr))) } = succ (countReduced m)
lookupReducedSucceedsAfterAdd : {min : keySet} → (k : keySet) → (v : valueSet) → (m : ReducedMap min) → (lookupReduced (addReducedMap k v m) k ≡ yes v)
lookupReducedSucceedsAfterAdd {min} k v m with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) with TotalOrder.totality keyOrder k k
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) | inr p = refl
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min))
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inr min=k rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder min<k)
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) | inl (inl _) = lookupReducedSucceedsAfterAdd k v m
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min))
lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) | inr min=k rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder min<k)
lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) with TotalOrder.totality keyOrder k k
lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) | inr p = refl
lookupReducedSucceedsAfterAdd {min} k v m | inr min=k with TotalOrder.totality keyOrder k k
lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inr p with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inr p | inl (inl min<k) rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder min<k)
lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inr p | inl (inr k<min) rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder k<min)
lookupReducedSucceedsAfterAdd {.k} k v record { firstEntry = firstEntry ; next = next } | inr refl | inr p | inr s = refl
lookupReducedSucceedsAfterUnrelatedAdd : {min : keySet} → (unrelatedK : keySet) → (unrelatedV : valueSet) → (k : keySet) → (v : valueSet) → ((TotalOrder._<_ keyOrder unrelatedK k) || (TotalOrder._<_ keyOrder k unrelatedK)) → (m : ReducedMap min) → (lookupReduced m k ≡ yes v) → lookupReduced (addReducedMap unrelatedK unrelatedV m) k ≡ yes v
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds with TotalOrder.totality keyOrder min k'
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inl min<k') with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr record { firstEntry = firstEntry ; next = no } () | inl (inl min<k') | inl (inl min<k)
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedSucceeds | inl (inl min<k') | inl (inl min<k) = lookupReducedSucceedsAfterUnrelatedAdd {a} k' v' k v pr fst lookupReducedSucceeds
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inl x) m lookupReducedSucceeds | inl (inl min<k') | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min (TotalOrder.<Transitive keyOrder min<k' x)))
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr k<k') m () | inl (inl min<k') | inl (inr k<min)
lookupReducedSucceedsAfterUnrelatedAdd {.min} k' v' min v (inl x) m lookupReducedSucceeds | inl (inl min<k') | inr refl = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder x min<k'))
lookupReducedSucceedsAfterUnrelatedAdd {.min} k' v' min v (inr x) record { firstEntry = v2 ; next = no } p | inl (inl min<k') | inr refl = applyEquality yes (yesInjective p)
lookupReducedSucceedsAfterUnrelatedAdd {.min} k' v' min v (inr x) record { firstEntry = .v ; next = (yes (a , b)) } refl | inl (inl min<k') | inr refl = applyEquality yes refl
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) with TotalOrder.totality keyOrder k' k
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) | inl (inl k'<k) with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) | inl (inl k'<k) | inl (inl min<k) = lookupReducedSucceeds
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m () | inl (inr k'<min) | inl (inl k'<k) | inl (inr k<min)
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) | inl (inl k'<k) | inr refl = lookupReducedSucceeds
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inl x) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder x k<k'))
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr x) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr _) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder x (TotalOrder.<Transitive keyOrder k<k' k'<min)))
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr _) m () | inl (inr k'<min) | inl (inr k<k') | inl (inr x)
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr _) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') | inr x rewrite x = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<k' k'<min))
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inl x) m lookupReducedSucceeds | inl (inr k'<min) | inr k'=k rewrite k'=k = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr x) m lookupReducedSucceeds | inl (inr k'<min) | inr k'=k rewrite k'=k = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inr refl with TotalOrder.totality keyOrder min k
lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inl _) record { firstEntry = firstEntry ; next = no } () | inr refl | inl (inl min<k)
lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inl _) record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedSucceeds | inr refl | inl (inl min<k) = lookupReducedSucceeds
lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inr x) m lookupReducedSucceeds | inr refl | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k x))
lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inl x) m () | inr refl | inl (inr k<min)
lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inr x) m () | inr refl | inl (inr k<min)
lookupReducedSucceedsAfterUnrelatedAdd {.min} .min v' min v (inl x) m lookupReducedSucceeds | inr refl | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedSucceedsAfterUnrelatedAdd {.min} .min v' min v (inr x) m lookupReducedSucceeds | inr refl | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd : {min : keySet} → (unrelatedK : keySet) → (unrelatedV : valueSet) → (k : keySet) → ((TotalOrder._<_ keyOrder unrelatedK k) || (TotalOrder._<_ keyOrder k unrelatedK)) → (m : ReducedMap min) → (lookupReduced m k ≡ no) → lookupReduced (addReducedMap unrelatedK unrelatedV m) k ≡ no
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails with TotalOrder.totality keyOrder min k'
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inl min<k') with TotalOrder.totality keyOrder min k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) with TotalOrder.totality keyOrder k' k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inl (inl x) = refl
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inl (inr x) = refl
lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inl x) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inr x) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedFails | inl (inl min<k') | inl (inl min<k) = lookupReducedFailsAfterUnrelatedAdd k' v' k pr fst lookupReducedFails
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inl min<k') | inl (inr k<min) = refl
lookupReducedFailsAfterUnrelatedAdd {.min} k' v' min pr m () | inl (inl min<k') | inr refl
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inr k'<min) with TotalOrder.totality keyOrder min k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) with TotalOrder.totality keyOrder k' k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) with TotalOrder.totality keyOrder min k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl x₁) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = refl
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl x₁) record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = lookupReducedFails
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inr x₁) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = refl
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inr x₁) record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = lookupReducedFails
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inr x) = refl
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder min<k)
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inr k<k') = refl
lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inl x) record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inr x) record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) with TotalOrder.totality keyOrder k' k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) with TotalOrder.totality keyOrder min k
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min min<k))
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) | inl (inr k<min') = refl
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder k<min)
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inr x) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k'<k x))
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inr k<k') = refl
lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inl x) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inr x) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x)
lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m () | inl (inr k'<min) | inr min=k
lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr m lookupReducedFails | inr refl with TotalOrder.totality keyOrder min k
lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inr refl | inl (inl min<k) = refl
lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedFails | inr refl | inl (inl min<k) = lookupReducedFails
lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr m lookupReducedFails | inr refl | inl (inr k<min) = refl
lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr m () | inr refl | inr min=k
countReducedBehavesWhenAddingNotPresent : {min : keySet} → (k : keySet) → (v : valueSet) → (m : ReducedMap min) → (lookupReduced m k ≡ no) → countReduced (addReducedMap k v m) ≡ succ (countReduced m)
countReducedBehavesWhenAddingNotPresent {min} k v m lookupReducedFails with TotalOrder.totality keyOrder k min
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) with TotalOrder.totality keyOrder min k
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min))
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) | inl (inr _) = refl
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder k<min)
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr min<k) with TotalOrder.totality keyOrder min k
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inr min<k) | inl (inl _) = refl
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedFails | inl (inr min<k) | inl (inl _) = applyEquality succ (countReducedBehavesWhenAddingNotPresent k v (_&&_.fst b) lookupReducedFails)
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr min<k) | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min))
countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder min<k)
countReducedBehavesWhenAddingNotPresent {min} k v m lookupReducedFails | inr refl with TotalOrder.totality keyOrder min min
countReducedBehavesWhenAddingNotPresent {k} k v m lookupReducedFails | inr refl | inl (inl min<min) = exFalso (TotalOrder.irreflexive keyOrder min<min)
countReducedBehavesWhenAddingNotPresent {k} k v m lookupReducedFails | inr refl | inl (inr min<min) = exFalso (TotalOrder.irreflexive keyOrder min<min)
countReducedBehavesWhenAddingNotPresent {k} k v record { firstEntry = firstEntry ; next = no } () | inr refl | inr p
countReducedBehavesWhenAddingNotPresent {k} k v record { firstEntry = firstEntry ; next = (yes x) } () | inr refl | inr p
countReducedBehavesWhenAddingPresent : {min : keySet} → (k : keySet) → (v v' : valueSet) → (m : ReducedMap min) → (lookupReduced m k ≡ yes v') → countReduced (addReducedMap k v m) ≡ countReduced m
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds with TotalOrder.totality keyOrder k min
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inl k<min) with TotalOrder.totality keyOrder min k
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inl k<min) | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min min<k))
countReducedBehavesWhenAddingPresent {min} k v v' m () | inl (inl k<min) | inl (inr _)
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inl k<min) | inr q = exFalso (TotalOrder.irreflexive keyOrder (identityOfIndiscernablesLeft (TotalOrder._<_ keyOrder) k<min (equalityCommutative q)))
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inr min<k) with TotalOrder.totality keyOrder min k
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } () | inl (inr min<k) | inl (inl _)
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedSucceeds | inl (inr min<k) | inl (inl _) = applyEquality succ (countReducedBehavesWhenAddingPresent k v v' fst lookupReducedSucceeds)
countReducedBehavesWhenAddingPresent {min} k v v' m () | inl (inr min<k) | inl (inr k<min)
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inr min<k) | inr q = exFalso (TotalOrder.irreflexive keyOrder (identityOfIndiscernablesLeft (λ a b → TotalOrder._<_ keyOrder a b) min<k q))
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inr q with TotalOrder.totality keyOrder min min
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inr q | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder x)
countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inr q | inl (inr x) = exFalso (TotalOrder.irreflexive keyOrder x)
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } lookupReducedSucceeds | inr _ | inr p with TotalOrder.totality keyOrder min k
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } () | inr _ | inr p | inl (inl x)
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } () | inr _ | inr p | inl (inr x`)
countReducedBehavesWhenAddingPresent {.k} k v v' record { firstEntry = firstEntry ; next = no } lookupReducedSucceeds | inr q | inr p | inr refl = refl
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedSucceeds | inr q | inr p with TotalOrder.totality keyOrder k k
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedSucceeds | inr q | inr p | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder x)
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedSucceeds | inr q | inr p | inl (inr x) = exFalso (TotalOrder.irreflexive keyOrder x)
countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , (m ,, pr))) } q | inr q1 | inr p | inr x with TotalOrder.totality keyOrder min k
countReducedBehavesWhenAddingPresent {.k} k v v' record { firstEntry = firstEntry ; next = (yes (a , (m ,, pr))) } q | inr refl | inr p | inr x | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder min<k)
countReducedBehavesWhenAddingPresent {.k} k v v' record { firstEntry = firstEntry ; next = (yes (a , (m ,, pr))) } q | inr q1 | inr p | inr x | inr refl = refl
data Map : Set (a ⊔ b ⊔ c) where
empty : Map
nonempty : {min : keySet} → ReducedMap min → Map
addMap : (m : Map) → (k : keySet) → (v : valueSet) → Map
addMap empty k v = nonempty {min = k} record { firstEntry = v ; next = no }
addMap (nonempty x) k v = nonempty (addReducedMap k v x)
lookup : (m : Map) → (target : keySet) → Maybe valueSet
lookup empty t = no
lookup (nonempty x) t = lookupReduced x t
count : (m : Map) → ℕ
count empty = 0
count (nonempty x) = countReduced x
keysReduced : {min : keySet} → (m : ReducedMap min) → Vec keySet (countReduced m)
keysReduced {min = min} record { firstEntry = firstEntry ; next = no } = min ,- []
keysReduced {min = min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } = min ,- (keysReduced fst)
keys : (m : Map) → Vec keySet (count m)
keys empty = []
keys (nonempty m) = keysReduced m
lookupReducedWhenLess : {min : keySet} → (m : ReducedMap min) → (k : keySet) → (TotalOrder._<_ keyOrder k min) → (lookupReduced m k ≡ no)
lookupReducedWhenLess {min} m k k<min with TotalOrder.totality keyOrder min k
lookupReducedWhenLess {min} m k k<min | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min min<k))
lookupReducedWhenLess {min} m k k<min | inl (inr _) = refl
lookupReducedWhenLess {min} m k k<min | inr min=k rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder k<min)
lookupCertainReduced : {min : keySet} → (m : ReducedMap min) → (k : keySet) → (vecContains (keysReduced m) k) → Sg valueSet (λ v → lookupReduced m k ≡ yes v)
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = no } k pr = firstEntry , q
where
t : min ≡ k
t = vecSolelyContains k pr
q : lookupReduced {min} (record { firstEntry = firstEntry ; next = no }) k ≡ yes firstEntry
q with TotalOrder.totality keyOrder k k
q | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
q | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k)
q | inr p with TotalOrder.totality keyOrder min k
q | inr p | inl (inl min<k) rewrite t = exFalso (TotalOrder.irreflexive keyOrder min<k)
q | inr p | inl (inr k<min) rewrite t = exFalso (TotalOrder.irreflexive keyOrder k<min)
q | inr p | inr x = refl
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k pr with TotalOrder.totality keyOrder min k
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = zero ; index<m = _ ; isHere = isHere } | inl (inl min<k) rewrite isHere = exFalso (TotalOrder.irreflexive keyOrder min<k)
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inl min<k) = lookupCertainReduced fst k record { index = index ; index<m = canRemoveSuccFrom<N index<m ; isHere = isHere }
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = zero ; index<m = _ ; isHere = isHere } | inl (inr k<min) rewrite isHere = exFalso (TotalOrder.irreflexive keyOrder k<min)
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) with TotalOrder.totality keyOrder a k
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) | inl (inl a<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min (TotalOrder.<Transitive keyOrder snd a<k)))
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) | inl (inr k<a) = exFalso h
where
f : Sg valueSet (λ v → lookupReduced fst k ≡ yes v)
f = lookupCertainReduced fst k record { index = index ; index<m = canRemoveSuccFrom<N index<m ; isHere = isHere }
g : lookupReduced fst k ≡ no
g = lookupReducedWhenLess fst k k<a
noIsNotYes : {a : _} → {A : Set a} → {b : A} → (no ≡ yes b) → False
noIsNotYes {a} {A} {b} ()
h : False
h with f
h | a , b rewrite g = noIsNotYes b
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder snd k<min))
lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k pr | inr min=k = firstEntry , refl
lookupCertain : (m : Map) → (k : keySet) → (vecContains (keys m) k) → Sg valueSet (λ v → lookup m k ≡ yes v)
lookupCertain empty k record { index = index ; index<m = (le x ()) ; isHere = isHere }
lookupCertain (nonempty {min} m) k pr = lookupCertainReduced {min} m k pr
| {
"alphanum_fraction": 0.7208856287,
"avg_line_length": 122.3004115226,
"ext": "agda",
"hexsha": "41c66894751d8b73f7078e995d22b4dd4fc529b4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "KeyValue/LinearStore/Implementation.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "KeyValue/LinearStore/Implementation.agda",
"max_line_length": 341,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "KeyValue/LinearStore/Implementation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 10176,
"size": 29719
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.PtdAdjoint
module homotopy.SuspAdjointLoop where
module Σ⊣Ω {i} where
SuspFunctor : PtdFunctor i i
SuspFunctor = record {
obj = ⊙Susp;
arr = ⊙susp-fmap;
id = ⊙susp-fmap-idf;
comp = ⊙susp-fmap-∘}
LoopFunctor : PtdFunctor i i
LoopFunctor = record {
obj = ⊙Ω;
arr = ⊙ap;
id = λ _ → ⊙ap-idf;
comp = ⊙ap-∘}
module _ (X : Ptd i) where
η : fst X → Ω (⊙Susp X)
η x = merid _ x ∙ ! (merid _ (snd X))
module E = SuspensionRec (Ω X) (snd X) (snd X) (idf _)
ε : fst (⊙Susp (⊙Ω X)) → fst X
ε = E.f
⊙η : fst (X ⊙→ ⊙Ω (⊙Susp X))
⊙η = (η , !-inv-r (merid _ (snd X)))
⊙ε : fst (⊙Susp (⊙Ω X) ⊙→ X)
⊙ε = (ε , idp)
η-natural : {X Y : Ptd i} (f : fst (X ⊙→ Y))
→ ⊙η Y ⊙∘ f == ⊙ap (⊙susp-fmap f) ⊙∘ ⊙η X
η-natural {X = X} (f , idp) = ⊙λ=
(λ x → ! $
ap-∙ (susp-fmap f) (merid _ x) (! (merid _ (snd X)))
∙ SuspFmap.glue-β f x
∙2 (ap-! (susp-fmap f) (merid _ (snd X))
∙ ap ! (SuspFmap.glue-β f (snd X))))
(pt-lemma (susp-fmap f) (merid _ (snd X)) (SuspFmap.glue-β f (snd X)))
where
pt-lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y : A} (p : x == y) {q : f x == f y} (α : ap f p == q)
→ !-inv-r q == (! $ ap-∙ f p (! p) ∙ α ∙2 (ap-! f p ∙ ap ! α))
∙ ap (ap f) (!-inv-r p) ∙ idp
pt-lemma f idp idp = idp
ε-natural : {X Y : Ptd i} (f : fst (X ⊙→ Y))
→ ⊙ε Y ⊙∘ ⊙susp-fmap (⊙ap f) == f ⊙∘ ⊙ε X
ε-natural (f , idp) = ⊙λ=
(SuspensionElim.f _ idp idp
(λ p → ↓-='-from-square $ vert-degen-square $
ap-∘ (ε _) (susp-fmap (ap f)) (merid _ p)
∙ ap (ap (ε _)) (SuspFmap.glue-β (ap f) p)
∙ E.glue-β _ (ap f p)
∙ ap (ap f) (! (E.glue-β _ p))
∙ ∘-ap f (ε _) (merid _ p)))
idp
εΣ-Ση : (X : Ptd i) → ⊙ε (⊙Susp X) ⊙∘ ⊙susp-fmap (⊙η X) == ⊙idf _
εΣ-Ση X = ⊙λ=
(SuspensionElim.f _
idp
(merid _ (snd X))
(λ x → ↓-='-from-square $
(ap-∘ (ε (⊙Susp X)) (susp-fmap (η X)) (merid _ x)
∙ ap (ap (ε (⊙Susp X))) (SuspFmap.glue-β (η X) x)
∙ E.glue-β _ (merid _ x ∙ ! (merid _ (snd X))))
∙v⊡ square-lemma (merid _ x) (merid _ (snd X))
⊡v∙ ! (ap-idf (merid _ x))))
idp
where
square-lemma : ∀ {i} {A : Type i} {x y z : A}
(p : x == y) (q : z == y)
→ Square idp (p ∙ ! q) p q
square-lemma idp idp = ids
Ωε-ηΩ : (X : Ptd i) → ⊙ap (⊙ε X) ⊙∘ ⊙η (⊙Ω X) == ⊙idf _
Ωε-ηΩ X = ⊙λ=
(λ p → ap-∙ (ε X) (merid _ p) (! (merid _ idp))
∙ (E.glue-β X p ∙2 (ap-! (ε X) (merid _ idp) ∙ ap ! (E.glue-β X idp)))
∙ ∙-unit-r _)
(pt-lemma (ε X) (merid _ idp) (E.glue-β X idp))
where
pt-lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y : A} (p : x == y) {q : f x == f y} (α : ap f p == q)
→ ap (ap f) (!-inv-r p) ∙ idp
== (ap-∙ f p (! p) ∙ (α ∙2 (ap-! f p ∙ ap ! α)) ∙ !-inv-r q) ∙ idp
pt-lemma f idp idp = idp
adj : CounitUnitAdjoint SuspFunctor LoopFunctor
adj = record {
η = ⊙η;
ε = ⊙ε;
η-natural = η-natural;
ε-natural = ε-natural;
εF-Fη = εΣ-Ση;
Gε-ηG = Ωε-ηΩ}
| {
"alphanum_fraction": 0.4459333126,
"avg_line_length": 29.1727272727,
"ext": "agda",
"hexsha": "45f75ab6d03fd666ba9f21f6ff314ca937ec5da7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "homotopy/SuspAdjointLoop.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "homotopy/SuspAdjointLoop.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "homotopy/SuspAdjointLoop.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1551,
"size": 3209
} |
module EvenOdd where
open import Data.Nat
data Even : ℕ → Set where
evenZero : Even 0
evenSuc : {n : ℕ} → Even n → Even (suc (suc n))
data Odd : ℕ → Set where
oddOne : Odd 1
oddSuc : {n : ℕ} → Odd n → Odd (suc (suc n))
_e+e_ : {n m : ℕ} → Even n → Even m → Even (n + m)
evenZero e+e b = b
evenSuc a e+e b = evenSuc (a e+e b)
_o+o_ : {n m : ℕ} → Odd n → Odd m → Even (n + m)
oddOne o+o oddOne = evenSuc evenZero
oddOne o+o oddSuc b = evenSuc (oddOne o+o b)
oddSuc a o+o b = evenSuc (a o+o b)
_o+e_ : {n m : ℕ} → Odd n → Even m → Odd (n + m)
oddOne o+e evenZero = oddOne
oddOne o+e evenSuc b = oddSuc (oddOne o+e b)
oddSuc a o+e b = oddSuc (a o+e b)
_e+o_ : {n m : ℕ} → Even n → Odd m → Odd (n + m)
evenZero e+o b = b
evenSuc a e+o b = oddSuc (a e+o b)
| {
"alphanum_fraction": 0.5809399478,
"avg_line_length": 25.5333333333,
"ext": "agda",
"hexsha": "8ed5ff2ba3740aeb87f91ca55ff1dacd3b893d3f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/adventofcode2017",
"max_forks_repo_path": "lib/EvenOdd.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/adventofcode2017",
"max_issues_repo_path": "lib/EvenOdd.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/adventofcode2017",
"max_stars_repo_path": "lib/EvenOdd.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 331,
"size": 766
} |
-- {-# OPTIONS -v tc.meta:40 #-}
-- {-# OPTIONS --verbose tc.conv.term:40 #-}
-- {-# OPTIONS --verbose tc.conv.level:40 #-}
-- {-# OPTIONS --verbose tc.conv.atom:50 #-}
-- {-# OPTIONS --verbose tc.conv.elim:50 #-}
module Issue680-NeutralLevels where
open import Common.Level
postulate
N : Set
A : N → Set
level : N → Level
lac : ∀ {n} → A n → N
I : Level → Level → Set
refl : ∀ {l : Level} → I l l
data Test : Set where
mkTest : (n : N) → (tel : A n) → Test
test : Test → N
test (mkTest n tel) = n
where
test′ : I (lsuc (level (lac tel)))
(lsuc (level (lac tel)))
test′ = refl
| {
"alphanum_fraction": 0.5377358491,
"avg_line_length": 21.9310344828,
"ext": "agda",
"hexsha": "e21d331ac4ca3e226a5a61229988f22b6efe6b02",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue680-NeutralLevels.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue680-NeutralLevels.agda",
"max_line_length": 45,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue680-NeutralLevels.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 210,
"size": 636
} |
module sum where
open import level
open import bool
open import eq
open import maybe
open import product
open import functions
open import empty public
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
data _⊎_ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') : Set (ℓ ⊔ ℓ') where
inj₁ : (x : A) → A ⊎ B
inj₂ : (y : B) → A ⊎ B
_∨_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ')
_∨_ = _⊎_
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infixr 1 _⊎_ _∨_
----------------------------------------------------------------------
-- operations
----------------------------------------------------------------------
_≫=⊎_ : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}{C : Set (ℓ ⊔ ℓ')} → A ⊎ B → (B → A ⊎ C) → A ⊎ C
inj₁ x ≫=⊎ f = inj₁ x
inj₂ x ≫=⊎ f = f x
return⊎ : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → B → A ⊎ B
return⊎ b = inj₂ b
infix 5 error⊎_
error⊎_ : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → A → A ⊎ B
error⊎_ a = inj₁ a
extract-inj₁≡ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'}{a a' : A} → inj₁{B = B} a ≡ inj₁ a' → a ≡ a'
extract-inj₁≡ refl = refl
extract-inj₂≡ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'}{b b' : B} → inj₂{A = A} b ≡ inj₂ b' → b ≡ b'
extract-inj₂≡ refl = refl
=⊎ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'} → (A → A → 𝔹) → (B → B → 𝔹) → A ⊎ B → A ⊎ B → 𝔹
=⊎ eqa eqb (inj₁ a) (inj₁ a') = eqa a a'
=⊎ eqa eqb (inj₂ b) (inj₂ b') = eqb b b'
=⊎ _ _ _ _ = ff
=⊎-to-≡ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'} → (_eqa_ : A → A → 𝔹) → (_eqb_ : B → B → 𝔹) → ((a a' : A) → (a eqa a' ≡ tt) → a ≡ a') → ((b b' : B) → (b eqb b' ≡ tt) → b ≡ b') → (x y : A ⊎ B) → =⊎ _eqa_ _eqb_ x y ≡ tt → x ≡ y
=⊎-to-≡ eqa eqb risea riseb (inj₁ a) (inj₁ a') p rewrite risea a a' p = refl
=⊎-to-≡ eqa eqb risea riseb (inj₂ b) (inj₂ b') p rewrite riseb b b' p = refl
=⊎-to-≡ eqa eqb risea riseb (inj₁ a) (inj₂ b) ()
=⊎-to-≡ eqa eqb risea riseb (inj₂ b) (inj₁ a) ()
≡⊎-to-= : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'} → (_eqa_ : A → A → 𝔹) → (_eqb_ : B → B → 𝔹) → ((a a' : A) → a ≡ a' → a eqa a' ≡ tt) → ((b b' : B) → b ≡ b' → b eqb b' ≡ tt) → (x y : A ⊎ B) → x ≡ y → =⊎ _eqa_ _eqb_ x y ≡ tt
≡⊎-to-= eqa eqb dropa dropb (inj₁ a) (inj₁ a') p = dropa a a' (extract-inj₁≡ p)
≡⊎-to-= eqa eqb dropa dropb (inj₂ b) (inj₂ b') p = dropb b b' (extract-inj₂≡ p)
≡⊎-to-= eqa eqb dropa dropb (inj₁ a) (inj₂ b) ()
≡⊎-to-= eqa eqb dropa dropb (inj₂ b) (inj₁ a) ()
⊎-assoc : ∀{ℓ}{U V W : Set ℓ} → U ⊎ V ⊎ W → (U ⊎ V) ⊎ W
⊎-assoc (inj₁ x) = inj₁ (inj₁ x)
⊎-assoc (inj₂ (inj₁ x)) = inj₁ (inj₂ x)
⊎-assoc (inj₂ (inj₂ y)) = inj₂ y
⊎-assoc-inv : ∀{ℓ}{U V W : Set ℓ} → (U ⊎ V) ⊎ W → U ⊎ V ⊎ W
⊎-assoc-inv (inj₁ (inj₁ x)) = inj₁ x
⊎-assoc-inv (inj₁ (inj₂ y)) = inj₂ (inj₁ y)
⊎-assoc-inv (inj₂ y) = inj₂ (inj₂ y)
⊎-ar : ∀{ℓ}{U V W : Set ℓ} → (U → W) → (V → W) → U ⊎ V → W
⊎-ar f g (inj₁ x) = f x
⊎-ar f g (inj₂ y) = g y
⊎-sym : ∀{ℓ}{X Y : Set ℓ} → X ⊎ Y → Y ⊎ X
⊎-sym (inj₁ x) = inj₂ x
⊎-sym (inj₂ y) = inj₁ y
⊎-left-ident : ∀{ℓ}{X : Set ℓ} → ⊥ {ℓ} ⊎ X → X
⊎-left-ident (inj₁ x) = ⊥-elim x
⊎-left-ident (inj₂ y) = y
⊎-left-ident-inv : ∀{ℓ}{X : Set ℓ} → X → ⊥ {ℓ} ⊎ X
⊎-left-ident-inv = inj₂
⊎-right-ident : ∀{ℓ}{X : Set ℓ} → X ⊎ ⊥ {ℓ} → X
⊎-right-ident (inj₁ x) = x
⊎-right-ident (inj₂ y) = ⊥-elim y
⊎-right-ident-inv : ∀{ℓ}{X : Set ℓ} → X → X ⊎ ⊥ {ℓ}
⊎-right-ident-inv = inj₁
⊎-map : {U W V R : Set} → (U → V) → (W → R) → U ⊎ W → V ⊎ R
⊎-map {U} {W} {V} {R} f g (inj₁ u) = inj₁ (f u)
⊎-map {U} {W} {V} {R} f g (inj₂ w) = inj₂ (g w)
⊎-×-distl : {U V W : Set} → U × (V ⊎ W) → U × V ⊎ U × W
⊎-×-distl {U} {V} {W} (u , inj₁ v) = inj₁ (u , v)
⊎-×-distl {U} {V} {W} (u , inj₂ w) = inj₂ (u , w)
⊎-×-distl-inv : {X Y Z : Set} → X × Y ⊎ X × Z → X × (Y ⊎ Z)
⊎-×-distl-inv {X} {Y} {Z} (inj₁ (x , y)) = x , inj₁ y
⊎-×-distl-inv {X} {Y} {Z} (inj₂ (x , z)) = x , inj₂ z
⊎-×-distl-iso₁ : ∀{U V W}{a : U × (V ⊎ W)} → (⊎-×-distl-inv ∘ ⊎-×-distl) a ≡ id a
⊎-×-distl-iso₁ {a = u , inj₁ v} = refl
⊎-×-distl-iso₁ {a = u , inj₂ w} = refl
⊎-×-distl-iso₂ : ∀{U V W}{a : U × V ⊎ U × W} → (⊎-×-distl ∘ ⊎-×-distl-inv) a ≡ id a
⊎-×-distl-iso₂ {a = inj₁ (u , v)} = refl
⊎-×-distl-iso₂ {a = inj₂ (u , w)} = refl
⊎-×-distr : {U V W : Set} → (U ⊎ V) × W → U × W ⊎ V × W
⊎-×-distr {U} {V} {W} (inj₁ u , w) = inj₁ (u , w)
⊎-×-distr {U} {V} {W} (inj₂ v , w) = inj₂ (v , w)
⊎-×-distr-inv : {X Z Y : Set} → X × Z ⊎ Y × Z → (X ⊎ Y) × Z
⊎-×-distr-inv {X} {Z} {Y} (inj₁ (x , z)) = inj₁ x , z
⊎-×-distr-inv {X} {Z} {Y} (inj₂ (y , z)) = inj₂ y , z
⊎-×-distr-iso₁ : ∀{U V W}{a : (U ⊎ V) × W} → (⊎-×-distr-inv ∘ ⊎-×-distr) a ≡ id a
⊎-×-distr-iso₁ {a = inj₁ u , w} = refl
⊎-×-distr-iso₁ {a = inj₂ v , w} = refl
⊎-×-distr-iso₂ : ∀{U V W}{a : (U × W) ⊎ (V × W)} → (⊎-×-distr ∘ ⊎-×-distr-inv) a ≡ id a
⊎-×-distr-iso₂ {a = inj₁ (u , w)} = refl
⊎-×-distr-iso₂ {a = inj₂ (v , w)} = refl
⊎-codiag : ∀{ℓ : level}{U : Set ℓ} → U ⊎ U → U
⊎-codiag (inj₁ x) = x
⊎-codiag (inj₂ y) = y
| {
"alphanum_fraction": 0.4176731079,
"avg_line_length": 34.985915493,
"ext": "agda",
"hexsha": "d9202268faaea4bd5fbffacad61aadbbbe4f05dc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "sum.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "sum.agda",
"max_line_length": 222,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "sum.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2751,
"size": 4968
} |
module Text.Greek.Script.Unicode where
open import Text.Greek.Script
-- U+0390 - U+03CE
ΐ : Token -- U+0390 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
ΐ = with-accent-diaeresis ι′ lower (acute ι-vowel) ι-diaeresis
Α : Token -- U+0391 GREEK CAPITAL LETTER ALPHA
Α = unmarked α′ upper
Β : Token -- U+0392 GREEK CAPITAL LETTER BETA
Β = unmarked β′ upper
Γ : Token -- U+0393 GREEK CAPITAL LETTER GAMMA
Γ = unmarked γ′ upper
Δ : Token -- U+0394 GREEK CAPITAL LETTER DELTA
Δ = unmarked δ′ upper
Ε : Token -- U+0395 GREEK CAPITAL LETTER EPSILON
Ε = unmarked ε′ upper
Ζ : Token -- U+0396 GREEK CAPITAL LETTER ZETA
Ζ = unmarked ζ′ upper
Η : Token -- U+0397 GREEK CAPITAL LETTER ETA
Η = unmarked η′ upper
Θ : Token -- U+0398 GREEK CAPITAL LETTER THETA
Θ = unmarked θ′ upper
Ι : Token -- U+0399 GREEK CAPITAL LETTER IOTA
Ι = unmarked ι′ upper
Κ : Token -- U+039A GREEK CAPITAL LETTER KAPPA
Κ = unmarked κ′ upper
Λ : Token -- U+039B GREEK CAPITAL LETTER LAMDA
Λ = unmarked λ′ upper
Μ : Token -- U+039C GREEK CAPITAL LETTER MU
Μ = unmarked μ′ upper
Ν : Token -- U+039D GREEK CAPITAL LETTER NU
Ν = unmarked ν′ upper
Ξ : Token -- U+039E GREEK CAPITAL LETTER XI
Ξ = unmarked ξ′ upper
Ο : Token -- U+039F GREEK CAPITAL LETTER OMICRON
Ο = unmarked ο′ upper
Π : Token -- U+03A0 GREEK CAPITAL LETTER PI
Π = unmarked π′ upper
Ρ : Token -- U+03A1 GREEK CAPITAL LETTER RHO
Ρ = unmarked ρ′ upper
-- U+03A2 <reserved>
Σ : Token -- U+03A3 GREEK CAPITAL LETTER SIGMA
Σ = unmarked σ′ upper
Τ : Token -- U+03A4 GREEK CAPITAL LETTER TAU
Τ = unmarked τ′ upper
Υ : Token -- U+03A5 GREEK CAPITAL LETTER UPSILON
Υ = unmarked υ′ upper
Φ : Token -- U+03A6 GREEK CAPITAL LETTER PHI
Φ = unmarked φ′ upper
Χ : Token -- U+03A7 GREEK CAPITAL LETTER CHI
Χ = unmarked χ′ upper
Ψ : Token -- U+03A8 GREEK CAPITAL LETTER PSI
Ψ = unmarked ψ′ upper
Ω : Token -- U+03A9 GREEK CAPITAL LETTER OMEGA
Ω = unmarked ω′ upper
Ϊ : Token -- U+03AA GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
Ϊ = with-diaeresis ι′ upper ι-diaeresis
Ϋ : Token -- U+03AB GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
Ϋ = with-diaeresis υ′ upper υ-diaeresis
ά : Token -- U+03AC GREEK SMALL LETTER ALPHA WITH TONOS
ά = with-accent α′ lower (acute α-vowel)
έ : Token -- U+03AD GREEK SMALL LETTER EPSILON WITH TONOS
έ = with-accent ε′ lower (acute ε-vowel)
ή : Token -- U+03AE GREEK SMALL LETTER ETA WITH TONOS
ή = with-accent η′ lower (acute η-vowel)
ί : Token -- U+03AF GREEK SMALL LETTER IOTA WITH TONOS
ί = with-accent ι′ lower (acute ι-vowel)
ΰ : Token -- U+03B0 GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
ΰ = with-accent-diaeresis υ′ lower (acute υ-vowel) υ-diaeresis
α : Token -- U+03B1 GREEK SMALL LETTER ALPHA
α = unmarked α′ lower
β : Token -- U+03B2 GREEK SMALL LETTER BETA
β = unmarked β′ lower
γ : Token -- U+03B3 GREEK SMALL LETTER GAMMA
γ = unmarked γ′ lower
δ : Token -- U+03B4 GREEK SMALL LETTER DELTA
δ = unmarked δ′ lower
ε : Token -- U+03B5 GREEK SMALL LETTER EPSILON
ε = unmarked ε′ lower
ζ : Token -- U+03B6 GREEK SMALL LETTER ZETA
ζ = unmarked ζ′ lower
η : Token -- U+03B7 GREEK SMALL LETTER ETA
η = unmarked η′ lower
θ : Token -- U+03B8 GREEK SMALL LETTER THETA
θ = unmarked θ′ lower
ι : Token -- U+03B9 GREEK SMALL LETTER IOTA
ι = unmarked ι′ lower
κ : Token -- U+03BA GREEK SMALL LETTER KAPPA
κ = unmarked κ′ lower
∙λ : Token -- U+03BB GREEK SMALL LETTER LAMDA
∙λ = unmarked λ′ lower
μ : Token -- U+03BC GREEK SMALL LETTER MU
μ = unmarked μ′ lower
ν : Token -- U+03BD GREEK SMALL LETTER NU
ν = unmarked ν′ lower
ξ : Token -- U+03BE GREEK SMALL LETTER XI
ξ = unmarked ξ′ lower
ο : Token -- U+03BF GREEK SMALL LETTER OMICRON
ο = unmarked ο′ lower
π : Token -- U+03C0 GREEK SMALL LETTER PI
π = unmarked π′ lower
ρ : Token -- U+03C1 GREEK SMALL LETTER RHO
ρ = unmarked ρ′ lower
ς : Token -- U+03C2 GREEK SMALL LETTER FINAL SIGMA
ς = final σ′ lower σ-final
σ : Token -- U+03C3 GREEK SMALL LETTER SIGMA
σ = unmarked σ′ lower
τ : Token -- U+03C4 GREEK SMALL LETTER TAU
τ = unmarked τ′ lower
υ : Token -- U+03C5 GREEK SMALL LETTER UPSILON
υ = unmarked υ′ lower
φ : Token -- U+03C6 GREEK SMALL LETTER PHI
φ = unmarked φ′ lower
χ : Token -- U+03C7 GREEK SMALL LETTER CHI
χ = unmarked χ′ lower
ψ : Token -- U+03C8 GREEK SMALL LETTER PSI
ψ = unmarked ψ′ lower
ω : Token -- U+03C9 GREEK SMALL LETTER OMEGA
ω = unmarked ω′ lower
ϊ : Token -- U+03CA GREEK SMALL LETTER IOTA WITH DIALYTIKA
ϊ = with-diaeresis ι′ lower ι-diaeresis
ϋ : Token -- U+03CB GREEK SMALL LETTER UPSILON WITH DIALYTIKA
ϋ = with-diaeresis υ′ lower υ-diaeresis
ό : Token -- U+03CC GREEK SMALL LETTER OMICRON WITH TONOS
ό = with-accent ο′ lower (acute ο-vowel)
ύ : Token -- U+03CD GREEK SMALL LETTER UPSILON WITH TONOS
ύ = with-accent υ′ lower (acute υ-vowel)
ώ : Token -- U+03CE GREEK SMALL LETTER OMEGA WITH TONOS
ώ = with-accent ω′ lower (acute ω-vowel)
-- U+1F00 - U+1FFF
ἀ : Token -- U+1F00 ἀ GREEK SMALL LETTER ALPHA WITH PSILI
ἀ = with-breathing α′ lower (smooth α-smooth)
ἁ : Token -- U+1F01 ἁ GREEK SMALL LETTER ALPHA WITH DASIA
ἁ = with-breathing α′ lower (rough α-rough)
ἂ : Token -- U+1F02 ἂ GREEK SMALL LETTER ALPHA WITH PSILI AND VARIA
ἂ = with-accent-breathing α′ lower (grave α-vowel) (smooth α-smooth)
ἃ : Token -- U+1F03 ἃ GREEK SMALL LETTER ALPHA WITH DASIA AND VARIA
ἃ = with-accent-breathing α′ lower (grave α-vowel) (rough α-rough)
ἄ : Token -- U+1F04 ἄ GREEK SMALL LETTER ALPHA WITH PSILI AND OXIA
ἄ = with-accent-breathing α′ lower (acute α-vowel) (smooth α-smooth)
ἅ : Token -- U+1F05 ἅ GREEK SMALL LETTER ALPHA WITH DASIA AND OXIA
ἅ = with-accent-breathing α′ lower (acute α-vowel) (rough α-rough)
ἆ : Token -- U+1F06 ἆ GREEK SMALL LETTER ALPHA WITH PSILI AND PERISPOMENI
ἆ = with-accent-breathing α′ lower (circumflex α-long-vowel) (smooth α-smooth)
ἇ : Token -- U+1F07 ἇ GREEK SMALL LETTER ALPHA WITH DASIA AND PERISPOMENI
ἇ = with-accent-breathing α′ lower (circumflex α-long-vowel) (rough α-rough)
Ἀ : Token -- U+1F08 Ἀ GREEK CAPITAL LETTER ALPHA WITH PSILI
Ἀ = with-breathing α′ upper (smooth Α-smooth)
Ἁ : Token -- U+1F09 Ἁ GREEK CAPITAL LETTER ALPHA WITH DASIA
Ἁ = with-breathing α′ upper (rough α-rough)
Ἂ : Token -- U+1F0A Ἂ GREEK CAPITAL LETTER ALPHA WITH PSILI AND VARIA
Ἂ = with-accent-breathing α′ upper (grave α-vowel) (smooth Α-smooth)
Ἃ : Token -- U+1F0B Ἃ GREEK CAPITAL LETTER ALPHA WITH DASIA AND VARIA
Ἃ = with-accent-breathing α′ upper (grave α-vowel) (rough α-rough)
Ἄ : Token -- U+1F0C Ἄ GREEK CAPITAL LETTER ALPHA WITH PSILI AND OXIA
Ἄ = with-accent-breathing α′ upper (acute α-vowel) (smooth Α-smooth)
Ἅ : Token -- U+1F0D Ἅ GREEK CAPITAL LETTER ALPHA WITH DASIA AND OXIA
Ἅ = with-accent-breathing α′ upper (acute α-vowel) (rough α-rough)
Ἆ : Token -- U+1F0E Ἆ GREEK CAPITAL LETTER ALPHA WITH PSILI AND PERISPOMENI
Ἆ = with-accent-breathing α′ upper (circumflex α-long-vowel) (smooth Α-smooth)
Ἇ : Token -- U+1F0F Ἇ GREEK CAPITAL LETTER ALPHA WITH DASIA AND PERISPOMENI
Ἇ = with-accent-breathing α′ upper (circumflex α-long-vowel) (rough α-rough)
ἐ : Token -- U+1F10 ἐ GREEK SMALL LETTER EPSILON WITH PSILI
ἐ = with-breathing ε′ lower (smooth ε-smooth)
ἑ : Token -- U+1F11 ἑ GREEK SMALL LETTER EPSILON WITH DASIA
ἑ = with-breathing ε′ lower (rough ε-rough)
ἒ : Token -- U+1F12 ἒ GREEK SMALL LETTER EPSILON WITH PSILI AND VARIA
ἒ = with-accent-breathing ε′ lower (grave ε-vowel) (smooth ε-smooth)
ἓ : Token -- U+1F13 ἓ GREEK SMALL LETTER EPSILON WITH DASIA AND VARIA
ἓ = with-accent-breathing ε′ lower (grave ε-vowel) (rough ε-rough)
ἔ : Token -- U+1F14 ἔ GREEK SMALL LETTER EPSILON WITH PSILI AND OXIA
ἔ = with-accent-breathing ε′ lower (acute ε-vowel) (smooth ε-smooth)
ἕ : Token -- U+1F15 ἕ GREEK SMALL LETTER EPSILON WITH DASIA AND OXIA
ἕ = with-accent-breathing ε′ lower (acute ε-vowel) (rough ε-rough)
-- U+1F16
-- U+1F17
Ἐ : Token -- U+1F18 Ἐ GREEK CAPITAL LETTER EPSILON WITH PSILI
Ἐ = with-breathing ε′ upper (smooth Ε-smooth)
Ἑ : Token -- U+1F19 Ἑ GREEK CAPITAL LETTER EPSILON WITH DASIA
Ἑ = with-breathing ε′ upper (rough ε-rough)
Ἒ : Token -- U+1F1A Ἒ GREEK CAPITAL LETTER EPSILON WITH PSILI AND VARIA
Ἒ = with-accent-breathing ε′ upper (grave ε-vowel) (smooth Ε-smooth)
Ἓ : Token -- U+1F1B Ἓ GREEK CAPITAL LETTER EPSILON WITH DASIA AND VARIA
Ἓ = with-accent-breathing ε′ upper (grave ε-vowel) (rough ε-rough)
Ἔ : Token -- U+1F1C Ἔ GREEK CAPITAL LETTER EPSILON WITH PSILI AND OXIA
Ἔ = with-accent-breathing ε′ upper (acute ε-vowel) (smooth Ε-smooth)
Ἕ : Token -- U+1F1D Ἕ GREEK CAPITAL LETTER EPSILON WITH DASIA AND OXIA
Ἕ = with-accent-breathing ε′ upper (acute ε-vowel) (rough ε-rough)
-- U+1F1E
-- U+1F1F
ἠ : Token -- U+1F20 ἠ GREEK SMALL LETTER ETA WITH PSILI
ἠ = with-breathing η′ lower (smooth η-smooth)
ἡ : Token -- U+1F21 ἡ GREEK SMALL LETTER ETA WITH DASIA
ἡ = with-breathing η′ lower (rough η-rough)
ἢ : Token -- U+1F22 ἢ GREEK SMALL LETTER ETA WITH PSILI AND VARIA
ἢ = with-accent-breathing η′ lower (grave η-vowel) (smooth η-smooth)
ἣ : Token -- U+1F23 ἣ GREEK SMALL LETTER ETA WITH DASIA AND VARIA
ἣ = with-accent-breathing η′ lower (grave η-vowel) (rough η-rough)
ἤ : Token -- U+1F24 ἤ GREEK SMALL LETTER ETA WITH PSILI AND OXIA
ἤ = with-accent-breathing η′ lower (acute η-vowel) (smooth η-smooth)
ἥ : Token -- U+1F25 ἥ GREEK SMALL LETTER ETA WITH DASIA AND OXIA
ἥ = with-accent-breathing η′ lower (acute η-vowel) (rough η-rough)
ἦ : Token -- U+1F26 ἦ GREEK SMALL LETTER ETA WITH PSILI AND PERISPOMENI
ἦ = with-accent-breathing η′ lower (circumflex η-long-vowel) (smooth η-smooth)
ἧ : Token -- U+1F27 ἧ GREEK SMALL LETTER ETA WITH DASIA AND PERISPOMENI
ἧ = with-accent-breathing η′ lower (circumflex η-long-vowel) (rough η-rough)
Ἠ : Token -- U+1F28 Ἠ GREEK CAPITAL LETTER ETA WITH PSILI
Ἠ = with-breathing η′ upper (smooth Η-smooth)
Ἡ : Token -- U+1F29 Ἡ GREEK CAPITAL LETTER ETA WITH DASIA
Ἡ = with-breathing η′ upper (rough η-rough)
Ἢ : Token -- U+1F2A Ἢ GREEK CAPITAL LETTER ETA WITH PSILI AND VARIA
Ἢ = with-accent-breathing η′ upper (grave η-vowel) (smooth Η-smooth)
Ἣ : Token -- U+1F2B Ἣ GREEK CAPITAL LETTER ETA WITH DASIA AND VARIA
Ἣ = with-accent-breathing η′ upper (grave η-vowel) (rough η-rough)
Ἤ : Token -- U+1F2C Ἤ GREEK CAPITAL LETTER ETA WITH PSILI AND OXIA
Ἤ = with-accent-breathing η′ upper (acute η-vowel) (smooth Η-smooth)
Ἥ : Token -- U+1F2D Ἥ GREEK CAPITAL LETTER ETA WITH DASIA AND OXIA
Ἥ = with-accent-breathing η′ upper (acute η-vowel) (rough η-rough)
Ἦ : Token -- U+1F2E Ἦ GREEK CAPITAL LETTER ETA WITH PSILI AND PERISPOMENI
Ἦ = with-accent-breathing η′ upper (circumflex η-long-vowel) (smooth Η-smooth)
Ἧ : Token -- U+1F2F Ἧ GREEK CAPITAL LETTER ETA WITH DASIA AND PERISPOMENI
Ἧ = with-accent-breathing η′ upper (circumflex η-long-vowel) (rough η-rough)
ἰ : Token -- U+1F30 ἰ GREEK SMALL LETTER IOTA WITH PSILI
ἰ = with-breathing ι′ lower (smooth ι-smooth)
ἱ : Token -- U+1F31 ἱ GREEK SMALL LETTER IOTA WITH DASIA
ἱ = with-breathing ι′ lower (rough ι-rough)
ἲ : Token -- U+1F32 ἲ GREEK SMALL LETTER IOTA WITH PSILI AND VARIA
ἲ = with-accent-breathing ι′ lower (grave ι-vowel) (smooth ι-smooth)
ἳ : Token -- U+1F33 ἳ GREEK SMALL LETTER IOTA WITH DASIA AND VARIA
ἳ = with-accent-breathing ι′ lower (grave ι-vowel) (rough ι-rough)
ἴ : Token -- U+1F34 ἴ GREEK SMALL LETTER IOTA WITH PSILI AND OXIA
ἴ = with-accent-breathing ι′ lower (acute ι-vowel) (smooth ι-smooth)
ἵ : Token -- U+1F35 ἵ GREEK SMALL LETTER IOTA WITH DASIA AND OXIA
ἵ = with-accent-breathing ι′ lower (acute ι-vowel) (rough ι-rough)
ἶ : Token -- U+1F36 ἶ GREEK SMALL LETTER IOTA WITH PSILI AND PERISPOMENI
ἶ = with-accent-breathing ι′ lower (circumflex ι-long-vowel) (smooth ι-smooth)
ἷ : Token -- U+1F37 ἷ GREEK SMALL LETTER IOTA WITH DASIA AND PERISPOMENI
ἷ = with-accent-breathing ι′ lower (circumflex ι-long-vowel) (rough ι-rough)
Ἰ : Token -- U+1F38 Ἰ GREEK CAPITAL LETTER IOTA WITH PSILI
Ἰ = with-breathing ι′ upper (smooth Ι-smooth)
Ἱ : Token -- U+1F39 Ἱ GREEK CAPITAL LETTER IOTA WITH DASIA
Ἱ = with-breathing ι′ upper (rough ι-rough)
Ἲ : Token -- U+1F3A Ἲ GREEK CAPITAL LETTER IOTA WITH PSILI AND VARIA
Ἲ = with-accent-breathing ι′ upper (grave ι-vowel) (smooth Ι-smooth)
Ἳ : Token -- U+1F3B Ἳ GREEK CAPITAL LETTER IOTA WITH DASIA AND VARIA
Ἳ = with-accent-breathing ι′ upper (grave ι-vowel) (rough ι-rough)
Ἴ : Token -- U+1F3C Ἴ GREEK CAPITAL LETTER IOTA WITH PSILI AND OXIA
Ἴ = with-accent-breathing ι′ upper (acute ι-vowel) (smooth Ι-smooth)
Ἵ : Token -- U+1F3D Ἵ GREEK CAPITAL LETTER IOTA WITH DASIA AND OXIA
Ἵ = with-accent-breathing ι′ upper (acute ι-vowel) (rough ι-rough)
Ἶ : Token -- U+1F3E Ἶ GREEK CAPITAL LETTER IOTA WITH PSILI AND PERISPOMENI
Ἶ = with-accent-breathing ι′ upper (circumflex ι-long-vowel) (smooth Ι-smooth)
Ἷ : Token -- U+1F3F Ἷ GREEK CAPITAL LETTER IOTA WITH DASIA AND PERISPOMENI
Ἷ = with-accent-breathing ι′ upper (circumflex ι-long-vowel) (rough ι-rough)
ὀ : Token -- U+1F40 ὀ GREEK SMALL LETTER OMICRON WITH PSILI
ὀ = with-breathing ο′ lower (smooth ο-smooth)
ὁ : Token -- U+1F41 ὁ GREEK SMALL LETTER OMICRON WITH DASIA
ὁ = with-breathing ο′ lower (rough ο-rough)
ὂ : Token -- U+1F42 ὂ GREEK SMALL LETTER OMICRON WITH PSILI AND VARIA
ὂ = with-accent-breathing ο′ lower (grave ο-vowel) (smooth ο-smooth)
ὃ : Token -- U+1F43 ὃ GREEK SMALL LETTER OMICRON WITH DASIA AND VARIA
ὃ = with-accent-breathing ο′ lower (grave ο-vowel) (rough ο-rough)
ὄ : Token -- U+1F44 ὄ GREEK SMALL LETTER OMICRON WITH PSILI AND OXIA
ὄ = with-accent-breathing ο′ lower (acute ο-vowel) (smooth ο-smooth)
ὅ : Token -- U+1F45 ὅ GREEK SMALL LETTER OMICRON WITH DASIA AND OXIA
ὅ = with-accent-breathing ο′ lower (acute ο-vowel) (rough ο-rough)
-- U+1F46
-- U+1F47
Ὀ : Token -- U+1F48 Ὀ GREEK CAPITAL LETTER OMICRON WITH PSILI
Ὀ = with-breathing ο′ upper (smooth Ο-smooth)
Ὁ : Token -- U+1F49 Ὁ GREEK CAPITAL LETTER OMICRON WITH DASIA
Ὁ = with-breathing ο′ upper (rough ο-rough)
Ὂ : Token -- U+1F4A Ὂ GREEK CAPITAL LETTER OMICRON WITH PSILI AND VARIA
Ὂ = with-accent-breathing ο′ upper (grave ο-vowel) (smooth Ο-smooth)
Ὃ : Token -- U+1F4B Ὃ GREEK CAPITAL LETTER OMICRON WITH DASIA AND VARIA
Ὃ = with-accent-breathing ο′ upper (grave ο-vowel) (rough ο-rough)
Ὄ : Token -- U+1F4C Ὄ GREEK CAPITAL LETTER OMICRON WITH PSILI AND OXIA
Ὄ = with-accent-breathing ο′ upper (acute ο-vowel) (smooth Ο-smooth)
Ὅ : Token -- U+1F4D Ὅ GREEK CAPITAL LETTER OMICRON WITH DASIA AND OXIA
Ὅ = with-accent-breathing ο′ upper (acute ο-vowel) (rough ο-rough)
-- U+1F4E
-- U+1F4F
ὐ : Token -- U+1F50 ὐ GREEK SMALL LETTER UPSILON WITH PSILI
ὐ = with-breathing υ′ lower (smooth υ-smooth)
ὑ : Token -- U+1F51 ὑ GREEK SMALL LETTER UPSILON WITH DASIA
ὑ = with-breathing υ′ lower (rough υ-rough)
ὒ : Token -- U+1F52 ὒ GREEK SMALL LETTER UPSILON WITH PSILI AND VARIA
ὒ = with-accent-breathing υ′ lower (grave υ-vowel) (smooth υ-smooth)
ὓ : Token -- U+1F53 ὓ GREEK SMALL LETTER UPSILON WITH DASIA AND VARIA
ὓ = with-accent-breathing υ′ lower (grave υ-vowel) (rough υ-rough)
ὔ : Token -- U+1F54 ὔ GREEK SMALL LETTER UPSILON WITH PSILI AND OXIA
ὔ = with-accent-breathing υ′ lower (acute υ-vowel) (smooth υ-smooth)
ὕ : Token -- U+1F55 ὕ GREEK SMALL LETTER UPSILON WITH DASIA AND OXIA
ὕ = with-accent-breathing υ′ lower (acute υ-vowel) (rough υ-rough)
ὖ : Token -- U+1F56 ὖ GREEK SMALL LETTER UPSILON WITH PSILI AND PERISPOMENI
ὖ = with-accent-breathing υ′ lower (circumflex υ-long-vowel) (smooth υ-smooth)
ὗ : Token -- U+1F57 ὗ GREEK SMALL LETTER UPSILON WITH DASIA AND PERISPOMENI
ὗ = with-accent-breathing υ′ lower (circumflex υ-long-vowel) (rough υ-rough)
-- U+1F58
Ὑ : Token -- U+1F59 Ὑ GREEK CAPITAL LETTER UPSILON WITH DASIA
Ὑ = with-breathing υ′ upper (rough υ-rough)
-- U+1F5A
Ὓ : Token -- U+1F5B Ὓ GREEK CAPITAL LETTER UPSILON WITH DASIA AND VARIA
Ὓ = with-accent-breathing υ′ upper (grave υ-vowel) (rough υ-rough)
-- U+1F5C
Ὕ : Token -- U+1F5D Ὕ GREEK CAPITAL LETTER UPSILON WITH DASIA AND OXIA
Ὕ = with-accent-breathing υ′ upper (acute υ-vowel) (rough υ-rough)
-- U+1F5E
Ὗ : Token -- U+1F5F Ὗ GREEK CAPITAL LETTER UPSILON WITH DASIA AND PERISPOMENI
Ὗ = with-accent-breathing υ′ upper (circumflex υ-long-vowel) (rough υ-rough)
ὠ : Token -- U+1F60 ὠ GREEK SMALL LETTER OMEGA WITH PSILI
ὠ = with-breathing ω′ lower (smooth ω-smooth)
ὡ : Token -- U+1F61 ὡ GREEK SMALL LETTER OMEGA WITH DASIA
ὡ = with-breathing ω′ lower (rough ω-rough)
ὢ : Token -- U+1F62 ὢ GREEK SMALL LETTER OMEGA WITH PSILI AND VARIA
ὢ = with-accent-breathing ω′ lower (grave ω-vowel) (smooth ω-smooth)
ὣ : Token -- U+1F63 ὣ GREEK SMALL LETTER OMEGA WITH DASIA AND VARIA
ὣ = with-accent-breathing ω′ lower (grave ω-vowel) (rough ω-rough)
ὤ : Token -- U+1F64 ὤ GREEK SMALL LETTER OMEGA WITH PSILI AND OXIA
ὤ = with-accent-breathing ω′ lower (acute ω-vowel) (smooth ω-smooth)
ὥ : Token -- U+1F65 ὥ GREEK SMALL LETTER OMEGA WITH DASIA AND OXIA
ὥ = with-accent-breathing ω′ lower (acute ω-vowel) (rough ω-rough)
ὦ : Token -- U+1F66 ὦ GREEK SMALL LETTER OMEGA WITH PSILI AND PERISPOMENI
ὦ = with-accent-breathing ω′ lower (circumflex ω-long-vowel) (smooth ω-smooth)
ὧ : Token -- U+1F67 ὧ GREEK SMALL LETTER OMEGA WITH DASIA AND PERISPOMENI
ὧ = with-accent-breathing ω′ lower (circumflex ω-long-vowel) (rough ω-rough)
Ὠ : Token -- U+1F68 Ὠ GREEK CAPITAL LETTER OMEGA WITH PSILI
Ὠ = with-breathing ω′ upper (smooth Ω-smooth)
Ὡ : Token -- U+1F69 Ὡ GREEK CAPITAL LETTER OMEGA WITH DASIA
Ὡ = with-breathing ω′ upper (rough ω-rough)
Ὢ : Token -- U+1F6A Ὢ GREEK CAPITAL LETTER OMEGA WITH PSILI AND VARIA
Ὢ = with-accent-breathing ω′ upper (grave ω-vowel) (smooth Ω-smooth)
Ὣ : Token -- U+1F6B Ὣ GREEK CAPITAL LETTER OMEGA WITH DASIA AND VARIA
Ὣ = with-accent-breathing ω′ upper (grave ω-vowel) (rough ω-rough)
Ὤ : Token -- U+1F6C Ὤ GREEK CAPITAL LETTER OMEGA WITH PSILI AND OXIA
Ὤ = with-accent-breathing ω′ upper (acute ω-vowel) (smooth Ω-smooth)
Ὥ : Token -- U+1F6D Ὥ GREEK CAPITAL LETTER OMEGA WITH DASIA AND OXIA
Ὥ = with-accent-breathing ω′ upper (acute ω-vowel) (rough ω-rough)
Ὦ : Token -- U+1F6E Ὦ GREEK CAPITAL LETTER OMEGA WITH PSILI AND PERISPOMENI
Ὦ = with-accent-breathing ω′ upper (circumflex ω-long-vowel) (smooth Ω-smooth)
Ὧ : Token -- U+1F6F Ὧ GREEK CAPITAL LETTER OMEGA WITH DASIA AND PERISPOMENI
Ὧ = with-accent-breathing ω′ upper (circumflex ω-long-vowel) (rough ω-rough)
ὰ : Token -- U+1F70 ὰ GREEK SMALL LETTER ALPHA WITH VARIA
ὰ = with-accent α′ lower (grave α-vowel)
ά : Token -- U+1F71 ά GREEK SMALL LETTER ALPHA WITH OXIA
ά = with-accent α′ lower (acute α-vowel)
ὲ : Token -- U+1F72 ὲ GREEK SMALL LETTER EPSILON WITH VARIA
ὲ = with-accent ε′ lower (grave ε-vowel)
έ : Token -- U+1F73 έ GREEK SMALL LETTER EPSILON WITH OXIA
έ = with-accent ε′ lower (acute ε-vowel)
ὴ : Token -- U+1F74 ὴ GREEK SMALL LETTER ETA WITH VARIA
ὴ = with-accent η′ lower (grave η-vowel)
ή : Token -- U+1F75 ή GREEK SMALL LETTER ETA WITH OXIA
ή = with-accent η′ lower (acute η-vowel)
ὶ : Token -- U+1F76 ὶ GREEK SMALL LETTER IOTA WITH VARIA
ὶ = with-accent ι′ lower (grave ι-vowel)
ί : Token -- U+1F77 ί GREEK SMALL LETTER IOTA WITH OXIA
ί = with-accent ι′ lower (acute ι-vowel)
ὸ : Token -- U+1F78 ὸ GREEK SMALL LETTER OMICRON WITH VARIA
ὸ = with-accent ο′ lower (grave ο-vowel)
ό : Token -- U+1F79 ό GREEK SMALL LETTER OMICRON WITH OXIA
ό = with-accent ο′ lower (acute ο-vowel)
ὺ : Token -- U+1F7A ὺ GREEK SMALL LETTER UPSILON WITH VARIA
ὺ = with-accent υ′ lower (grave υ-vowel)
ύ : Token -- U+1F7B ύ GREEK SMALL LETTER UPSILON WITH OXIA
ύ = with-accent υ′ lower (acute υ-vowel)
ὼ : Token -- U+1F7C ὼ GREEK SMALL LETTER OMEGA WITH VARIA
ὼ = with-accent ω′ lower (grave ω-vowel)
ώ : Token -- U+1F7D ώ GREEK SMALL LETTER OMEGA WITH OXIA
ώ = with-accent ω′ lower (acute ω-vowel)
-- U+1F7E
-- U+1F7F
ᾀ : Token -- U+1F80 ᾀ GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI
ᾀ = with-breathing-iota α′ lower (smooth α-smooth) α-iota-subscript
ᾁ : Token -- U+1F81 ᾁ GREEK SMALL LETTER ALPHA WITH DASIA AND YPOGEGRAMMENI
ᾁ = with-breathing-iota α′ lower (rough α-rough) α-iota-subscript
ᾂ : Token -- U+1F82 ᾂ GREEK SMALL LETTER ALPHA WITH PSILI AND VARIA AND YPOGEGRAMMENI
ᾂ = with-accent-breathing-iota α′ lower (grave α-vowel) (smooth α-smooth) α-iota-subscript
ᾃ : Token -- U+1F83 ᾃ GREEK SMALL LETTER ALPHA WITH DASIA AND VARIA AND YPOGEGRAMMENI
ᾃ = with-accent-breathing-iota α′ lower (grave α-vowel) (rough α-rough) α-iota-subscript
ᾄ : Token -- U+1F84 ᾄ GREEK SMALL LETTER ALPHA WITH PSILI AND OXIA AND YPOGEGRAMMENI
ᾄ = with-accent-breathing-iota α′ lower (acute α-vowel) (smooth α-smooth) α-iota-subscript
ᾅ : Token -- U+1F85 ᾅ GREEK SMALL LETTER ALPHA WITH DASIA AND OXIA AND YPOGEGRAMMENI
ᾅ = with-accent-breathing-iota α′ lower (acute α-vowel) (rough α-rough) α-iota-subscript
ᾆ : Token -- U+1F86 ᾆ GREEK SMALL LETTER ALPHA WITH PSILI AND PERISPOMENI AND YPOGEGRAMMENI
ᾆ = with-accent-breathing-iota α′ lower (circumflex α-long-vowel) (smooth α-smooth) α-iota-subscript
ᾇ : Token -- U+1F87 ᾇ GREEK SMALL LETTER ALPHA WITH DASIA AND PERISPOMENI AND YPOGEGRAMMENI
ᾇ = with-accent-breathing-iota α′ lower (circumflex α-long-vowel) (rough α-rough) α-iota-subscript
ᾈ : Token -- U+1F88 ᾈ GREEK CAPITAL LETTER ALPHA WITH PSILI AND PROSGEGRAMMENI
ᾈ = with-breathing-iota α′ upper (smooth Α-smooth) α-iota-subscript
ᾉ : Token -- U+1F89 ᾉ GREEK CAPITAL LETTER ALPHA WITH DASIA AND PROSGEGRAMMENI
ᾉ = with-breathing-iota α′ upper (rough α-rough) α-iota-subscript
ᾊ : Token -- U+1F8A ᾊ GREEK CAPITAL LETTER ALPHA WITH PSILI AND VARIA AND PROSGEGRAMMENI
ᾊ = with-accent-breathing-iota α′ upper (grave α-vowel) (smooth Α-smooth) α-iota-subscript
ᾋ : Token -- U+1F8B ᾋ GREEK CAPITAL LETTER ALPHA WITH DASIA AND VARIA AND PROSGEGRAMMENI
ᾋ = with-accent-breathing-iota α′ upper (grave α-vowel) (rough α-rough) α-iota-subscript
ᾌ : Token -- U+1F8C ᾌ GREEK CAPITAL LETTER ALPHA WITH PSILI AND OXIA AND PROSGEGRAMMENI
ᾌ = with-accent-breathing-iota α′ upper (acute α-vowel) (smooth Α-smooth) α-iota-subscript
ᾍ : Token -- U+1F8D ᾍ GREEK CAPITAL LETTER ALPHA WITH DASIA AND OXIA AND PROSGEGRAMMENI
ᾍ = with-accent-breathing-iota α′ upper (acute α-vowel) (rough α-rough) α-iota-subscript
ᾎ : Token -- U+1F8E ᾎ GREEK CAPITAL LETTER ALPHA WITH PSILI AND PERISPOMENI AND PROSGEGRAMMENI
ᾎ = with-accent-breathing-iota α′ upper (circumflex α-long-vowel) (smooth Α-smooth) α-iota-subscript
ᾏ : Token -- U+1F8F ᾏ GREEK CAPITAL LETTER ALPHA WITH DASIA AND PERISPOMENI AND PROSGEGRAMMENI
ᾏ = with-accent-breathing-iota α′ upper (circumflex α-long-vowel) (rough α-rough) α-iota-subscript
ᾐ : Token -- U+1F90 ᾐ GREEK SMALL LETTER ETA WITH PSILI AND YPOGEGRAMMENI
ᾐ = with-breathing-iota η′ lower (smooth η-smooth) η-iota-subscript
ᾑ : Token -- U+1F91 ᾑ GREEK SMALL LETTER ETA WITH DASIA AND YPOGEGRAMMENI
ᾑ = with-breathing-iota η′ lower (rough η-rough) η-iota-subscript
ᾒ : Token -- U+1F92 ᾒ GREEK SMALL LETTER ETA WITH PSILI AND VARIA AND YPOGEGRAMMENI
ᾒ = with-accent-breathing-iota η′ lower (grave η-vowel) (smooth η-smooth) η-iota-subscript
ᾓ : Token -- U+1F93 ᾓ GREEK SMALL LETTER ETA WITH DASIA AND VARIA AND YPOGEGRAMMENI
ᾓ = with-accent-breathing-iota η′ lower (grave η-vowel) (rough η-rough) η-iota-subscript
ᾔ : Token -- U+1F94 ᾔ GREEK SMALL LETTER ETA WITH PSILI AND OXIA AND YPOGEGRAMMENI
ᾔ = with-accent-breathing-iota η′ lower (acute η-vowel) (smooth η-smooth) η-iota-subscript
ᾕ : Token -- U+1F95 ᾕ GREEK SMALL LETTER ETA WITH DASIA AND OXIA AND YPOGEGRAMMENI
ᾕ = with-accent-breathing-iota η′ lower (acute η-vowel) (rough η-rough) η-iota-subscript
ᾖ : Token -- U+1F96 ᾖ GREEK SMALL LETTER ETA WITH PSILI AND PERISPOMENI AND YPOGEGRAMMENI
ᾖ = with-accent-breathing-iota η′ lower (circumflex η-long-vowel) (smooth η-smooth) η-iota-subscript
ᾗ : Token -- U+1F97 ᾗ GREEK SMALL LETTER ETA WITH DASIA AND PERISPOMENI AND YPOGEGRAMMENI
ᾗ = with-accent-breathing-iota η′ lower (circumflex η-long-vowel) (rough η-rough) η-iota-subscript
ᾘ : Token -- U+1F98 ᾘ GREEK CAPITAL LETTER ETA WITH PSILI AND PROSGEGRAMMENI
ᾘ = with-breathing-iota η′ upper (smooth Η-smooth) η-iota-subscript
ᾙ : Token -- U+1F99 ᾙ GREEK CAPITAL LETTER ETA WITH DASIA AND PROSGEGRAMMENI
ᾙ = with-breathing-iota η′ upper (rough η-rough) η-iota-subscript
ᾚ : Token -- U+1F9A ᾚ GREEK CAPITAL LETTER ETA WITH PSILI AND VARIA AND PROSGEGRAMMENI
ᾚ = with-accent-breathing-iota η′ upper (grave η-vowel) (smooth Η-smooth) η-iota-subscript
ᾛ : Token -- U+1F9B ᾛ GREEK CAPITAL LETTER ETA WITH DASIA AND VARIA AND PROSGEGRAMMENI
ᾛ = with-accent-breathing-iota η′ upper (grave η-vowel) (rough η-rough) η-iota-subscript
ᾜ : Token -- U+1F9C ᾜ GREEK CAPITAL LETTER ETA WITH PSILI AND OXIA AND PROSGEGRAMMENI
ᾜ = with-accent-breathing-iota η′ upper (acute η-vowel) (smooth Η-smooth) η-iota-subscript
ᾝ : Token -- U+1F9D ᾝ GREEK CAPITAL LETTER ETA WITH DASIA AND OXIA AND PROSGEGRAMMENI
ᾝ = with-accent-breathing-iota η′ upper (acute η-vowel) (rough η-rough) η-iota-subscript
ᾞ : Token -- U+1F9E ᾞ GREEK CAPITAL LETTER ETA WITH PSILI AND PERISPOMENI AND PROSGEGRAMMENI
ᾞ = with-accent-breathing-iota η′ upper (circumflex η-long-vowel) (smooth Η-smooth) η-iota-subscript
ᾟ : Token -- U+1F9F ᾟ GREEK CAPITAL LETTER ETA WITH DASIA AND PERISPOMENI AND PROSGEGRAMMENI
ᾟ = with-accent-breathing-iota η′ upper (circumflex η-long-vowel) (rough η-rough) η-iota-subscript
ᾠ : Token -- U+1FA0 ᾠ GREEK SMALL LETTER OMEGA WITH PSILI AND YPOGEGRAMMENI
ᾠ = with-breathing-iota ω′ lower (smooth ω-smooth) ω-iota-subscript
ᾡ : Token -- U+1FA1 ᾡ GREEK SMALL LETTER OMEGA WITH DASIA AND YPOGEGRAMMENI
ᾡ = with-breathing-iota ω′ lower (rough ω-rough) ω-iota-subscript
ᾢ : Token -- U+1FA2 ᾢ GREEK SMALL LETTER OMEGA WITH PSILI AND VARIA AND YPOGEGRAMMENI
ᾢ = with-accent-breathing-iota ω′ lower (grave ω-vowel) (smooth ω-smooth) ω-iota-subscript
ᾣ : Token -- U+1FA3 ᾣ GREEK SMALL LETTER OMEGA WITH DASIA AND VARIA AND YPOGEGRAMMENI
ᾣ = with-accent-breathing-iota ω′ lower (grave ω-vowel) (rough ω-rough) ω-iota-subscript
ᾤ : Token -- U+1FA4 ᾤ GREEK SMALL LETTER OMEGA WITH PSILI AND OXIA AND YPOGEGRAMMENI
ᾤ = with-accent-breathing-iota ω′ lower (acute ω-vowel) (smooth ω-smooth) ω-iota-subscript
ᾥ : Token -- U+1FA5 ᾥ GREEK SMALL LETTER OMEGA WITH DASIA AND OXIA AND YPOGEGRAMMENI
ᾥ = with-accent-breathing-iota ω′ lower (acute ω-vowel) (rough ω-rough) ω-iota-subscript
ᾦ : Token -- U+1FA6 ᾦ GREEK SMALL LETTER OMEGA WITH PSILI AND PERISPOMENI AND YPOGEGRAMMENI
ᾦ = with-accent-breathing-iota ω′ lower (circumflex ω-long-vowel) (smooth ω-smooth) ω-iota-subscript
ᾧ : Token -- U+1FA7 ᾧ GREEK SMALL LETTER OMEGA WITH DASIA AND PERISPOMENI AND YPOGEGRAMMENI
ᾧ = with-accent-breathing-iota ω′ lower (circumflex ω-long-vowel) (rough ω-rough) ω-iota-subscript
ᾨ : Token -- U+1FA8 ᾨ GREEK CAPITAL LETTER OMEGA WITH PSILI AND PROSGEGRAMMENI
ᾨ = with-breathing-iota ω′ upper (smooth Ω-smooth) ω-iota-subscript
ᾩ : Token -- U+1FA9 ᾩ GREEK CAPITAL LETTER OMEGA WITH DASIA AND PROSGEGRAMMENI
ᾩ = with-breathing-iota ω′ upper (rough ω-rough) ω-iota-subscript
ᾪ : Token -- U+1FAA ᾪ GREEK CAPITAL LETTER OMEGA WITH PSILI AND VARIA AND PROSGEGRAMMENI
ᾪ = with-accent-breathing-iota ω′ upper (grave ω-vowel) (smooth Ω-smooth) ω-iota-subscript
ᾫ : Token -- U+1FAB ᾫ GREEK CAPITAL LETTER OMEGA WITH DASIA AND VARIA AND PROSGEGRAMMENI
ᾫ = with-accent-breathing-iota ω′ upper (grave ω-vowel) (rough ω-rough) ω-iota-subscript
ᾬ : Token -- U+1FAC ᾬ GREEK CAPITAL LETTER OMEGA WITH PSILI AND OXIA AND PROSGEGRAMMENI
ᾬ = with-accent-breathing-iota ω′ upper (acute ω-vowel) (smooth Ω-smooth) ω-iota-subscript
ᾭ : Token -- U+1FAD ᾭ GREEK CAPITAL LETTER OMEGA WITH DASIA AND OXIA AND PROSGEGRAMMENI
ᾭ = with-accent-breathing-iota ω′ upper (acute ω-vowel) (rough ω-rough) ω-iota-subscript
ᾮ : Token -- U+1FAE ᾮ GREEK CAPITAL LETTER OMEGA WITH PSILI AND PERISPOMENI AND PROSGEGRAMMENI
ᾮ = with-accent-breathing-iota ω′ upper (circumflex ω-long-vowel) (smooth Ω-smooth) ω-iota-subscript
ᾯ : Token -- U+1FAF ᾯ GREEK CAPITAL LETTER OMEGA WITH DASIA AND PERISPOMENI AND PROSGEGRAMMENI
ᾯ = with-accent-breathing-iota ω′ upper (circumflex ω-long-vowel) (rough ω-rough) ω-iota-subscript
-- U+1FB0 ᾰ GREEK SMALL LETTER ALPHA WITH VRACHY
-- U+1FB1 ᾱ GREEK SMALL LETTER ALPHA WITH MACRON
ᾲ : Token -- U+1FB2 ᾲ GREEK SMALL LETTER ALPHA WITH VARIA AND YPOGEGRAMMENI
ᾲ = with-accent-iota α′ lower (grave α-vowel) α-iota-subscript
ᾳ : Token -- U+1FB3 ᾳ GREEK SMALL LETTER ALPHA WITH YPOGEGRAMMENI
ᾳ = with-iota α′ lower α-iota-subscript
ᾴ : Token -- U+1FB4 ᾴ GREEK SMALL LETTER ALPHA WITH OXIA AND YPOGEGRAMMENI
ᾴ = with-accent-iota α′ lower (acute α-vowel) α-iota-subscript
-- U+1FB5
ᾶ : Token -- U+1FB6 ᾶ GREEK SMALL LETTER ALPHA WITH PERISPOMENI
ᾶ = with-accent α′ lower (circumflex α-long-vowel)
ᾷ : Token -- U+1FB7 ᾷ GREEK SMALL LETTER ALPHA WITH PERISPOMENI AND YPOGEGRAMMENI
ᾷ = with-accent-iota α′ lower (circumflex α-long-vowel) α-iota-subscript
-- U+1FB8 Ᾰ GREEK CAPITAL LETTER ALPHA WITH VRACHY
-- U+1FB9 Ᾱ GREEK CAPITAL LETTER ALPHA WITH MACRON
Ὰ : Token -- U+1FBA Ὰ GREEK CAPITAL LETTER ALPHA WITH VARIA
Ὰ = with-accent α′ upper (grave α-vowel)
Ά : Token -- U+1FBB Ά GREEK CAPITAL LETTER ALPHA WITH OXIA
Ά = with-accent α′ upper (acute α-vowel)
ᾼ : Token -- U+1FBC ᾼ GREEK CAPITAL LETTER ALPHA WITH PROSGEGRAMMENI
ᾼ = with-iota α′ upper α-iota-subscript
-- U+1FBD ᾽ GREEK KORONIS
-- U+1FBE ι GREEK PROSGEGRAMMENI
-- U+1FBF ᾿ GREEK PSILI
-- U+1FC0 ῀ GREEK PERISPOMENI
-- U+1FC1 ῁ GREEK DIALYTIKA AND PERISPOMENI
ῂ : Token -- U+1FC2 ῂ GREEK SMALL LETTER ETA WITH VARIA AND YPOGEGRAMMENI accent (circumflex α-long-vowel)
ῂ = with-accent-iota η′ lower (grave η-vowel) η-iota-subscript
ῃ : Token -- U+1FC3 ῃ GREEK SMALL LETTER ETA WITH YPOGEGRAMMENI
ῃ = with-iota η′ lower η-iota-subscript
ῄ : Token -- U+1FC4 ῄ GREEK SMALL LETTER ETA WITH OXIA AND YPOGEGRAMMENI
ῄ = with-accent-iota η′ lower (acute η-vowel) η-iota-subscript
-- U+1FC5
ῆ : Token -- U+1FC6 ῆ GREEK SMALL LETTER ETA WITH PERISPOMENI
ῆ = with-accent η′ lower (circumflex η-long-vowel)
ῇ : Token -- U+1FC7 ῇ GREEK SMALL LETTER ETA WITH PERISPOMENI AND YPOGEGRAMMENI
ῇ = with-accent-iota η′ lower (circumflex η-long-vowel) η-iota-subscript
Ὲ : Token -- U+1FC8 Ὲ GREEK CAPITAL LETTER EPSILON WITH VARIA
Ὲ = with-accent ε′ upper (grave ε-vowel)
Έ : Token -- U+1FC9 Έ GREEK CAPITAL LETTER EPSILON WITH OXIA
Έ = with-accent ε′ upper (acute ε-vowel)
Ὴ : Token -- U+1FCA Ὴ GREEK CAPITAL LETTER ETA WITH VARIA
Ὴ = with-accent η′ upper (grave η-vowel)
Ή : Token -- U+1FCB Ή GREEK CAPITAL LETTER ETA WITH OXIA
Ή = with-accent η′ upper (acute η-vowel)
ῌ : Token -- U+1FCC ῌ GREEK CAPITAL LETTER ETA WITH PROSGEGRAMMENI
ῌ = with-iota η′ upper η-iota-subscript
-- U+1FCD ῍ GREEK PSILI AND VARIA
-- U+1FCE ῎ GREEK PSILI AND OXIA
-- U+1FCF ῏ GREEK PSILI AND PERISPOMENI
-- U+1FD0 ῐ GREEK SMALL LETTER IOTA WITH VRACHY
-- U+1FD1 ῑ GREEK SMALL LETTER IOTA WITH MACRON
ῒ : Token -- U+1FD2 ῒ GREEK SMALL LETTER IOTA WITH DIALYTIKA AND VARIA
ῒ = with-accent-diaeresis ι′ lower (grave ι-vowel) ι-diaeresis
ΐ : Token -- U+1FD3 ΐ GREEK SMALL LETTER IOTA WITH DIALYTIKA AND OXIA
ΐ = with-accent-diaeresis ι′ lower (acute ι-vowel) ι-diaeresis
-- U+1FD4
-- U+1FD5
ῖ : Token -- U+1FD6 ῖ GREEK SMALL LETTER IOTA WITH PERISPOMENI
ῖ = with-accent ι′ lower (circumflex ι-long-vowel)
ῗ : Token -- U+1FD7 ῗ GREEK SMALL LETTER IOTA WITH DIALYTIKA AND PERISPOMENI
ῗ = with-accent-diaeresis ι′ lower (circumflex ι-long-vowel) ι-diaeresis
-- U+1FD8 Ῐ GREEK CAPITAL LETTER IOTA WITH VRACHY
-- U+1FD9 Ῑ GREEK CAPITAL LETTER IOTA WITH MACRON
Ὶ : Token -- U+1FDA Ὶ GREEK CAPITAL LETTER IOTA WITH VARIA
Ὶ = with-accent ι′ upper (grave ι-vowel)
Ί : Token -- U+1FDB Ί GREEK CAPITAL LETTER IOTA WITH OXIA
Ί = with-accent ι′ upper (acute ι-vowel)
-- U+1FDC
-- U+1FDD ῝ GREEK DASIA AND VARIA
-- U+1FDE ῞ GREEK DASIA AND OXIA
-- U+1FDF ῟ GREEK DASIA AND PERISPOMENI
-- U+1FE0 ῠ GREEK SMALL LETTER UPSILON WITH VRACHY
-- U+1FE1 ῡ GREEK SMALL LETTER UPSILON WITH MACRON
ῢ : Token -- U+1FE2 ῢ GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND VARIA
ῢ = with-accent-diaeresis υ′ lower (grave υ-vowel) υ-diaeresis
ΰ : Token -- U+1FE3 ΰ GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND OXIA
ΰ = with-accent-diaeresis υ′ lower (acute υ-vowel) υ-diaeresis
ῤ : Token -- U+1FE4 ῤ GREEK SMALL LETTER RHO WITH PSILI
ῤ = with-breathing ρ′ lower (smooth ρ-smooth)
ῥ : Token -- U+1FE5 ῥ GREEK SMALL LETTER RHO WITH DASIA
ῥ = with-breathing ρ′ lower (rough ρ-rough)
ῦ : Token -- U+1FE6 ῦ GREEK SMALL LETTER UPSILON WITH PERISPOMENI
ῦ = with-accent υ′ lower (circumflex υ-long-vowel)
ῧ : Token -- U+1FE7 ῧ GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND PERISPOMENI
ῧ = with-accent-diaeresis υ′ lower (circumflex υ-long-vowel) υ-diaeresis
-- U+1FE8 Ῠ GREEK CAPITAL LETTER UPSILON WITH VRACHY
-- U+1FE9 Ῡ GREEK CAPITAL LETTER UPSILON WITH MACRON
Ὺ : Token -- U+1FEA Ὺ GREEK CAPITAL LETTER UPSILON WITH VARIA
Ὺ = with-accent υ′ upper (grave υ-vowel)
Ύ : Token -- U+1FEB Ύ GREEK CAPITAL LETTER UPSILON WITH OXIA
Ύ = with-accent υ′ upper (acute υ-vowel)
Ῥ : Token -- U+1FEC Ῥ GREEK CAPITAL LETTER RHO WITH DASIA
Ῥ = with-breathing ρ′ upper (rough ρ-rough)
-- U+1FED ῭ GREEK DIALYTIKA AND VARIA
-- U+1FEE ΅ GREEK DIALYTIKA AND OXIA
-- U+1FEF ` GREEK VARIA
-- U+1FF0
-- U+1FF1
ῲ : Token -- U+1FF2 ῲ GREEK SMALL LETTER OMEGA WITH VARIA AND YPOGEGRAMMENI
ῲ = with-accent-iota ω′ lower (grave ω-vowel) ω-iota-subscript
ῳ : Token -- U+1FF3 ῳ GREEK SMALL LETTER OMEGA WITH YPOGEGRAMMENI
ῳ = with-iota ω′ lower ω-iota-subscript
ῴ : Token -- U+1FF4 ῴ GREEK SMALL LETTER OMEGA WITH OXIA AND YPOGEGRAMMENI
ῴ = with-accent-iota ω′ lower (acute ω-vowel) ω-iota-subscript
-- U+1FF5
ῶ : Token -- U+1FF6 ῶ GREEK SMALL LETTER OMEGA WITH PERISPOMENI
ῶ = with-accent ω′ lower (circumflex ω-long-vowel)
ῷ : Token -- U+1FF7 ῷ GREEK SMALL LETTER OMEGA WITH PERISPOMENI AND YPOGEGRAMMENI
ῷ = with-accent-iota ω′ lower (circumflex ω-long-vowel) ω-iota-subscript
Ὸ : Token -- U+1FF8 Ὸ GREEK CAPITAL LETTER OMICRON WITH VARIA
Ὸ = with-accent ο′ upper (grave ο-vowel)
Ό : Token -- U+1FF9 Ό GREEK CAPITAL LETTER OMICRON WITH OXIA
Ό = with-accent ο′ upper (acute ο-vowel)
Ὼ : Token -- U+1FFA Ὼ GREEK CAPITAL LETTER OMEGA WITH VARIA
Ὼ = with-accent ω′ upper (grave ω-vowel)
Ώ : Token -- U+1FFB Ώ GREEK CAPITAL LETTER OMEGA WITH OXIA
Ώ = with-accent ω′ upper (acute ω-vowel)
ῼ : Token -- U+1FFC ῼ GREEK CAPITAL LETTER OMEGA WITH PROSGEGRAMMENI
ῼ = with-iota ω′ upper ω-iota-subscript
-- U+1FFD ´ GREEK OXIA
-- U+1FFE ῾ GREEK DASIA
-- U+1FFF
| {
"alphanum_fraction": 0.7291100791,
"avg_line_length": 57.6414141414,
"ext": "agda",
"hexsha": "6a8f76af66530f1c516c5401b51fed2c3a7b3c81",
"lang": "Agda",
"max_forks_count": 5,
"max_forks_repo_forks_event_max_datetime": "2017-06-11T11:25:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-27T22:34:13.000Z",
"max_forks_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "scott-fleischman/GreekGrammar",
"max_forks_repo_path": "agda/Text/Greek/Script/Unicode.agda",
"max_issues_count": 13,
"max_issues_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_issues_repo_issues_event_max_datetime": "2020-09-07T11:58:38.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-28T20:04:08.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "scott-fleischman/GreekGrammar",
"max_issues_repo_path": "agda/Text/Greek/Script/Unicode.agda",
"max_line_length": 107,
"max_stars_count": 44,
"max_stars_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "scott-fleischman/GreekGrammar",
"max_stars_repo_path": "agda/Text/Greek/Script/Unicode.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-06T15:41:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-29T14:48:51.000Z",
"num_tokens": 14275,
"size": 34239
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring -- for length
open import Lists.Lists
open import Functions.Definition
--open import Groups.Actions
module Groups.FinitePermutations where
allInsertions : {a : _} {A : Set a} (x : A) (l : List A) → List (List A)
allInsertions x [] = [ x ] :: []
allInsertions x (y :: l) = (x :: (y :: l)) :: (map (λ i → y :: i) (allInsertions x l))
permutations : {a : _} {A : Set a} (l : List A) → List (List A)
permutations [] = [ [] ]
permutations (x :: l) = flatten (map (allInsertions x) (permutations l))
factorial : ℕ → ℕ
factorial zero = 1
factorial (succ n) = (succ n) *N factorial n
factCheck : factorial 5 ≡ 120
factCheck = refl
allInsertionsLength : {a : _} {A : Set a} (x : A) (l : List A) → length (allInsertions x l) ≡ succ (length l)
allInsertionsLength x [] = refl
allInsertionsLength x (y :: l) = applyEquality succ (transitivity (equalityCommutative (lengthMap (allInsertions x l) {f = y ::_})) (allInsertionsLength x l))
allInsertionsLength' : {a : _} {A : Set a} (x : A) (l : List A) → allTrue (λ i → length i ≡ succ (length l)) (allInsertions x l)
allInsertionsLength' x [] = refl ,, record {}
allInsertionsLength' x (y :: l) with allInsertionsLength' x l
... | bl = refl ,, allTrueMap (λ i → length i ≡ succ (succ (length l))) (y ::_) (allInsertions x l) (allTrueExtension (λ z → length z ≡ succ (length l)) ((λ i → length i ≡ succ (succ (length l))) ∘ (y ::_)) (allInsertions x l) (λ {x} → λ p → applyEquality succ p) bl)
permutationsCheck : permutations (3 :: 4 :: []) ≡ (3 :: 4 :: []) :: (4 :: 3 :: []) :: []
permutationsCheck = refl
permsAllSameLength : {a : _} {A : Set a} (l : List A) → allTrue (λ i → length i ≡ length l) (permutations l)
permsAllSameLength [] = refl ,, record {}
permsAllSameLength (x :: l) with permsAllSameLength l
... | bl = allTrueFlatten (λ i → length i ≡ succ (length l)) (map (allInsertions x) (permutations l)) (allTrueMap (allTrue (λ i → length i ≡ succ (length l))) (allInsertions x) (permutations l) (allTrueExtension (λ z → length z ≡ length l) (allTrue (λ i → length i ≡ succ (length l)) ∘ allInsertions x) (permutations l) lemma bl))
where
lemma : {m : List _} → (lenM=lenL : length m ≡ length l) → allTrue (λ i → length i ≡ succ (length l)) (allInsertions x m)
lemma {m} lm=ll rewrite equalityCommutative lm=ll = allInsertionsLength' x m
allTrueEqual : {a b : _} {A : Set a} {B : Set b} (f : A → B) (equalTo : B) (l : List A) → allTrue (λ i → f i ≡ equalTo) l → map f l ≡ replicate (length l) equalTo
allTrueEqual f equalTo [] pr = refl
allTrueEqual f equalTo (x :: l) (fst ,, snd) rewrite fst | allTrueEqual f equalTo l snd = refl
totalReplicate : (l len : ℕ) → fold _+N_ 0 (replicate len l) ≡ l *N len
totalReplicate l zero rewrite multiplicationNIsCommutative l 0 = refl
totalReplicate l (succ len) rewrite totalReplicate l len | multiplicationNIsCommutative l (succ len) = applyEquality (l +N_) (multiplicationNIsCommutative l len)
permsLen : {a : _} {A : Set a} (l : List A) → length (permutations l) ≡ factorial (length l)
permsLen [] = refl
permsLen (x :: l) = transitivity (lengthFlatten (map (allInsertions x) (permutations l))) (transitivity (applyEquality (fold _+N_ 0) (mapMap (permutations l))) (transitivity (applyEquality (fold _+N_ 0) (mapExtension (permutations l) (length ∘ allInsertions x) (succ ∘ length) λ {y} → allInsertionsLength x y)) (transitivity (applyEquality (fold _+N_ 0) lemma) (transitivity (totalReplicate (succ (length l)) (length (permutations l))) ans))))
where
lemma : map (λ a → succ (length a)) (permutations l) ≡ replicate (length (permutations l)) (succ (length l))
lemma = allTrueEqual (λ a → succ (length a)) (succ (length l)) (permutations l) (allTrueExtension (λ z → length z ≡ length l) (λ i → succ (length i) ≡ succ (length l)) (permutations l) (λ pr → applyEquality succ pr) (permsAllSameLength l))
ans : length (permutations l) +N length l *N length (permutations l) ≡ factorial (length l) +N length l *N factorial (length l)
ans rewrite permsLen l = refl
--act : GroupAction (symmetricGroup (symmetricSetoid (reflSetoid (FinSet n))))
--act = ?
{- TODO: show that symmetricGroup acts in the obvious way on permutations FinSet
listElements : {a : _} {A : Set a} (l : List A) → Set
listElements [] = False
listElements (x :: l) = True || listElements l
listElement : {a : _} {A : Set a} {l : List A} (elt : listElements l) → A
listElement {l = []} ()
listElement {l = x :: l} (inl record {}) = x
listElement {l = x :: l} (inr elt) = listElement {l = l} elt
backwardRange : ℕ → List ℕ
backwardRange zero = []
backwardRange (succ n) = n :: backwardRange n
backwardRangeLength : {n : ℕ} → length (backwardRange n) ≡ n
backwardRangeLength {zero} = refl
backwardRangeLength {succ n} rewrite backwardRangeLength {n} = refl
applyPermutation : {n : ℕ} → (f : FinSet n → FinSet n) → listElements (permutations (backwardRange n)) → listElements (permutations (backwardRange n))
applyPermutation {zero} f (inl record {}) = inl (record {})
applyPermutation {zero} f (inr ())
applyPermutation {succ n} f elt = {!!}
finitePermutations : (n : ℕ) → SetoidToSet (symmetricSetoid (reflSetoid (FinSet n))) (listElements (permutations (backwardRange n)))
SetoidToSet.project (finitePermutations n) (sym {f} fBij) = {!!}
SetoidToSet.wellDefined (finitePermutations n) = {!!}
SetoidToSet.surj (finitePermutations n) = {!!}
SetoidToSet.inj (finitePermutations n) = {!!}
-}
| {
"alphanum_fraction": 0.6696315121,
"avg_line_length": 57.3854166667,
"ext": "agda",
"hexsha": "3698e70ec144bae45ba794d74b4cbc40d4e73d05",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/FinitePermutations.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/FinitePermutations.agda",
"max_line_length": 443,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/FinitePermutations.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 1781,
"size": 5509
} |
{-# OPTIONS --safe #-}
module RevRev where
open import Relation.Binary.PropositionalEquality
open import Data.List
open import Data.List.Properties
rev : ∀ {ℓ} {A : Set ℓ} → List A → List A
rev [] = []
rev (x ∷ xs) = rev xs ++ x ∷ []
lemma : ∀ {ℓ} {A : Set ℓ} (a b : List A) → rev (a ++ b) ≡ rev b ++ rev a
lemma [] b rewrite ++-identityʳ (rev b) = refl
lemma (x ∷ a) b rewrite lemma a b | ++-assoc (rev b) (rev a) (x ∷ []) = refl
revrevid : ∀ {ℓ} {A : Set ℓ} (a : List A) → rev (rev a) ≡ a
revrevid [] = refl
revrevid (x ∷ a) rewrite lemma (rev a) (x ∷ []) | revrevid a = refl
| {
"alphanum_fraction": 0.5738831615,
"avg_line_length": 30.6315789474,
"ext": "agda",
"hexsha": "18af3d0e94e08557428b7293ad64c1b83bb314cc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Brethland/LEARNING-STUFF",
"max_forks_repo_path": "Agda/RevRev.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Brethland/LEARNING-STUFF",
"max_issues_repo_path": "Agda/RevRev.agda",
"max_line_length": 76,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Brethland/LEARNING-STUFF",
"max_stars_repo_path": "Agda/RevRev.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z",
"num_tokens": 221,
"size": 582
} |
------------------------------------------------------------------------
-- Some properties about subsets
------------------------------------------------------------------------
module Data.Fin.Subset.Props where
open import Data.Nat
open import Data.Vec hiding (_∈_)
open import Data.Empty
open import Data.Function
open import Data.Fin
open import Data.Fin.Subset
open import Data.Product
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Constructor mangling
drop-there : ∀ {s n x} {p : Subset n} → suc x ∈ s ∷ p → x ∈ p
drop-there (there x∈p) = x∈p
drop-∷-⊆ : ∀ {n s₁ s₂} {p₁ p₂ : Subset n} → s₁ ∷ p₁ ⊆ s₂ ∷ p₂ → p₁ ⊆ p₂
drop-∷-⊆ p₁s₁⊆p₂s₂ x∈p₁ = drop-there $ p₁s₁⊆p₂s₂ (there x∈p₁)
drop-∷-Empty : ∀ {n s} {p : Subset n} → Empty (s ∷ p) → Empty p
drop-∷-Empty ¬¬∅ (x , x∈p) = ¬¬∅ (suc x , there x∈p)
------------------------------------------------------------------------
-- More interesting properties
allInside : ∀ {n} (x : Fin n) → x ∈ all inside
allInside zero = here
allInside (suc x) = there (allInside x)
allOutside : ∀ {n} (x : Fin n) → x ∉ all outside
allOutside zero ()
allOutside (suc x) (there x∈) = allOutside x x∈
⊆⊇⟶≡ : ∀ {n} {p₁ p₂ : Subset n} →
p₁ ⊆ p₂ → p₂ ⊆ p₁ → p₁ ≡ p₂
⊆⊇⟶≡ = helper _ _
where
helper : ∀ {n} (p₁ p₂ : Subset n) →
p₁ ⊆ p₂ → p₂ ⊆ p₁ → p₁ ≡ p₂
helper [] [] _ _ = refl
helper (s₁ ∷ p₁) (s₂ ∷ p₂) ₁⊆₂ ₂⊆₁ with ⊆⊇⟶≡ (drop-∷-⊆ ₁⊆₂)
(drop-∷-⊆ ₂⊆₁)
helper (outside ∷ p) (outside ∷ .p) ₁⊆₂ ₂⊆₁ | refl = refl
helper (inside ∷ p) (inside ∷ .p) ₁⊆₂ ₂⊆₁ | refl = refl
helper (outside ∷ p) (inside ∷ .p) ₁⊆₂ ₂⊆₁ | refl with ₂⊆₁ here
... | ()
helper (inside ∷ p) (outside ∷ .p) ₁⊆₂ ₂⊆₁ | refl with ₁⊆₂ here
... | ()
∅⟶allOutside : ∀ {n} {p : Subset n} →
Empty p → p ≡ all outside
∅⟶allOutside {p = []} ¬¬∅ = refl
∅⟶allOutside {p = s ∷ ps} ¬¬∅ with ∅⟶allOutside (drop-∷-Empty ¬¬∅)
∅⟶allOutside {p = outside ∷ .(all outside)} ¬¬∅ | refl = refl
∅⟶allOutside {p = inside ∷ .(all outside)} ¬¬∅ | refl =
⊥-elim (¬¬∅ (zero , here))
| {
"alphanum_fraction": 0.4479302832,
"avg_line_length": 37.0161290323,
"ext": "agda",
"hexsha": "cbac082a07b0ea51feba646378d293b3ccd40d59",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Fin/Subset/Props.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Fin/Subset/Props.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Fin/Subset/Props.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 878,
"size": 2295
} |
postulate
A B : Set
f : @0 {{A}} → B
g : @0 {{A}} → B
g = f
| {
"alphanum_fraction": 0.3636363636,
"avg_line_length": 8.25,
"ext": "agda",
"hexsha": "8024e6d2bd3cc3b0eecea5d7b0971dc54b48675d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/Succeed/Issue5787.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/Succeed/Issue5787.agda",
"max_line_length": 18,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue5787.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 35,
"size": 66
} |
{-# OPTIONS --without-K #-}
module sets.nat.struct where
open import sum
open import equality
open import function
open import container.core
open import container.w
open import sets.empty
open import sets.unit
open import sets.nat.core
open import sets.fin
open import sets.vec.dependent
open import hott.level
ℕ-c : Container _ _ _
ℕ-c = record
{ I = ⊤
; A = λ _ → Fin 2
; B = ⊥ ∷∷ ⊤ ∷∷ ⟦⟧
; r = λ _ → tt }
open Container ℕ-c
ℕ-algebra-iso : (⊤ ⊎ ℕ) ≅ ℕ
ℕ-algebra-iso = record
{ to = λ { (inj₁ _) → zero ; (inj₂ n) → suc n }
; from = λ { zero → inj₁ tt ; (suc n) → inj₂ n }
; iso₁ = λ { (inj₁ _) → refl ; (inj₂ n) → refl }
; iso₂ = λ { zero → refl ; (suc n) → refl } }
private
inℕ : F (λ _ → ℕ) tt → ℕ
inℕ (zero , u) = 0
inℕ (suc zero , u) = suc (u tt)
inℕ (suc (suc ()) , u)
ℕ-struct-iso : ℕ ≅ W ℕ-c tt
ℕ-struct-iso = iso f g α β
where
f : ℕ → W ℕ-c tt
f 0 = sup (zero) (λ ())
f (suc n) = sup (suc zero) (λ _ → f n)
g : W ℕ-c tt → ℕ
g = fold ℕ-c (λ i → inℕ) tt
α : (n : ℕ) → g (f n) ≡ n
α zero = refl
α (suc n) = ap suc (α n)
β : (n : W ℕ-c tt) → f (g n) ≡ n
β (sup zero u) = ap (sup zero) (funext λ ())
β (sup (suc zero) u) = ap (sup (suc zero)) (funext (λ x → β (u tt)))
β (sup (suc (suc ())) u)
private
F-struct-iso : ∀ {i}(X : ⊤ → Set i) → F X tt ≅ (⊤ ⊎ X tt)
F-struct-iso X = begin
( Σ (A tt) λ a → B a → X tt )
≅⟨ sym≅ (⊎-Σ-iso (λ a → B a → X tt)) ⟩
( (⊥ → X tt) ⊎ (⊤ → X tt) )
≅⟨ ⊎-ap-iso (contr-⊤-iso ⊥-initial) Π-left-unit ⟩
( ⊤ ⊎ X tt )
∎
where open ≅-Reasoning
ℕ-initial : ∀ {i} (X : ℕ → Set i)
→ (x₀ : X 0)(f : ∀ n → X n → X (suc n))
→ contr ( Σ ((n : ℕ) → X n) λ x
→ (x₀ ≡ x 0)
× (∀ n → f n (x n) ≡ x (suc n)) )
ℕ-initial X x₀ f = iso-level ℕ-alg-iso (W-section-contr ℕ-c 𝓧)
where
ψ : ∀ x → ((b : B (proj₁ x)) → X (proj₂ x b)) → X (inℕ x)
ψ (zero , u) v = x₀
ψ (suc zero , u) v = f (u tt) (v tt)
ψ (suc (suc ()) , u) v
P : ∀ i (n : W ℕ-c i) → Set _
P i n = X (invert ℕ-struct-iso n)
θ : ∀ i x → ((b : B (proj₁ x)) → P tt (proj₂ x b)) → P i (inW ℕ-c i x)
θ i (a , u) v = ψ (a , invert ℕ-struct-iso ∘' u) v
𝓧 : AlgFib ℕ-c _
𝓧 = P , θ
ℕ-alg-iso : AlgSection ℕ-c 𝓧 ≅
( Σ ((n : ℕ) → X n) λ x
→ (x₀ ≡ x 0)
× (∀ n → f n (x n) ≡ x (suc n)) )
ℕ-alg-iso = begin
AlgSection ℕ-c 𝓧
≅⟨ ( Σ-ap-iso Π-left-unit λ g → iso≡ Π-left-unit) ⟩
( Σ ((w : W ℕ-c tt) → P tt w) λ g
→ ( _≡_ {A = (x : F (W ℕ-c) tt) → P tt (inW ℕ-c tt x)}
(λ x → θ tt x (λ b → g (proj₂ x b)))
(λ x → g (inW ℕ-c tt x)) ) )
≅⟨ sym≅ ( Σ-ap-iso (Π-ap-iso ℕ-struct-iso λ _ → refl≅) λ g
→ iso≡ (Π-ap-iso (sym≅ (F-ap-iso (λ i → sym≅ ℕ-struct-iso) tt)) λ x
→ refl≅ ) ) ⟩
( Σ ((n : ℕ) → X n) λ g
→ ( _≡_ {A = (x : F (λ _ → ℕ) tt) → X (inℕ x)}
(λ x → ψ x (λ b → g (proj₂ x b)))
(λ x → g (inℕ x)) ) )
≅⟨ ( Σ-ap-iso refl≅ λ g
→ iso≡ (Π-ap-iso (F-struct-iso (λ _ → ℕ)) λ _ → refl≅) ) ⟩
( let φ = invert (F-struct-iso (λ _ → ℕ))
in Σ ((n : ℕ) → X n) λ g
→ ( _≡_ {A = (x : ⊤ ⊎ ℕ) → X (inℕ (φ x))}
(λ x → ψ (φ x) (λ b → g (proj₂ (φ x) b)))
(λ x → g (inℕ (φ x))) ) )
≅⟨ ( Σ-ap-iso refl≅ λ x → iso≡ ⊎-universal ) ⟩
( Σ ((n : ℕ) → X n) λ x
→ ( _≡_ {A = (⊤ → X 0) × ((n : ℕ) → X (suc n))}
((λ _ → x₀) , (λ n → f n (x n)))
((λ _ → x 0) , (λ n → x (suc n))) ) )
≅⟨ ( Σ-ap-iso refl≅ λ x → sym≅ ×-split-iso ) ⟩
( Σ ((n : ℕ) → X n) λ x
→ (_≡_ {A = ⊤ → X 0} (λ _ → x₀) (λ _ → x 0))
× (_≡_ {A = (n : ℕ) → X (suc n)} (λ n → f n (x n)) (λ n → x (suc n))) )
≅⟨ ( Σ-ap-iso refl≅ λ x → ×-ap-iso (iso≡ Π-left-unit) (sym≅ strong-funext-iso) ) ⟩
( Σ ((n : ℕ) → X n) λ x
→ (x₀ ≡ x 0)
× (∀ n → f n (x n) ≡ x (suc n)) )
∎
where
open ≅-Reasoning
ℕ-initial-simple : ∀ {i} {X : Set i} (x₀ : X)
→ contr ( Σ (ℕ → X) λ x
→ (x₀ ≡ x 0)
× (∀ n → x n ≡ x (suc n)) )
ℕ-initial-simple {X = X} x₀
= ((λ _ → x₀) , refl , λ _ → refl)
, (λ u → contr⇒prop (ℕ-initial (λ _ → X) x₀ (λ _ x → x)) _ u)
ℕ-elim-shift : ∀ {i}{X : ℕ → Set i}
→ ((n : ℕ) → X n)
≅ ( (X 0) × ((n : ℕ) → X (suc n)) )
ℕ-elim-shift {i}{X} = begin
((n : ℕ) → X n)
≅⟨ (Π-ap-iso (sym≅ ℕ-algebra-iso) λ _ → refl≅) ⟩
((n : ⊤ ⊎ ℕ) → X (apply ℕ-algebra-iso n))
≅⟨ ⊎-universal ⟩
((⊤ → X 0) × ((n : ℕ) → X (suc n)))
≅⟨ ×-ap-iso Π-left-unit refl≅ ⟩
(X 0 × ((n : ℕ) → X (suc n)))
∎
where
open ≅-Reasoning
| {
"alphanum_fraction": 0.4024186822,
"avg_line_length": 31.3464052288,
"ext": "agda",
"hexsha": "6a134aae6a46537190d8a070dade0821782dfe04",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "sets/nat/struct.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "sets/nat/struct.agda",
"max_line_length": 88,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "sets/nat/struct.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 2225,
"size": 4796
} |
module Category.Functor.Lawful where
open import Agda.Primitive using (lsuc; _⊔_)
open import Category.Functor
open import Category.Applicative
open import Function using (id; _∘_)
open import Relation.Binary.PropositionalEquality using (_≡_; module ≡-Reasoning; sym; cong)
record LawfulFunctorImp {l₁ l₂} {F : Set l₁ → Set l₂} (FFunc : RawFunctor F) : Set (lsuc l₁ ⊔ l₂) where
open RawFunctor FFunc
field
<$>-identity : ∀ {a} {x : F a} → (id <$> x) ≡ x
<$>-compose : ∀ {a b c} {f : a → b} {g : b → c} {x : F a} → ((g ∘ f) <$> x) ≡ (g <$> (f <$> x))
module LawfulFunctor {l₁ l₂} {F : Set l₁ → Set l₂} {FFunc : RawFunctor F} (FLawful : LawfulFunctorImp FFunc) where
open RawFunctor FFunc public
open LawfulFunctorImp FLawful public
record LawfulApplicativeImp {l} {F : Set l → Set l} (FAppl : RawApplicative F) : Set (lsuc l) where
open RawApplicative FAppl
field
⊛-identity : ∀ {A} {u : F A} → (pure id ⊛ u) ≡ u
⊛-homomorphism : ∀ {A B} {u : A → B } {v : A} → (pure u ⊛ pure v) ≡ pure (u v)
⊛-interchange : ∀ {A B} {u : F (A → B)} {v : A} → (u ⊛ pure v) ≡ (pure (λ uᵢ → uᵢ v) ⊛ u)
⊛-composition : ∀ {A B C} {u : F (B → C)} {v : F (A → B)} {w : F A} → (pure (λ f g a → f (g a)) ⊛ u ⊛ v ⊛ w) ≡ (u ⊛ (v ⊛ w))
open ≡-Reasoning
private
composelemma : ∀ {a b c} {f : a → b} {g : b → c} {x : F a} → ((g ∘ f) <$> x) ≡ (g <$> (f <$> x))
composelemma {_} {_} {_} {f} {g} {x} =
pure (λ x₁ → g (f x₁)) ⊛ x ≡⟨ cong (_⊛ x) (sym ⊛-homomorphism) ⟩
pure (λ f x → g (f x)) ⊛ pure f ⊛ x ≡⟨ cong ((_⊛ x) ∘ (_⊛ pure f)) (sym ⊛-homomorphism) ⟩
pure (λ g f x → g (f x)) ⊛ pure g ⊛ pure f ⊛ x ≡⟨ ⊛-composition ⟩
pure g ⊛ (pure f ⊛ x) ∎
isLawfulFunctor : LawfulFunctorImp rawFunctor
isLawfulFunctor = record
{ <$>-identity = ⊛-identity
; <$>-compose = composelemma
}
module LawfulApplicative {l} {F : Set l → Set l} (FAppl : RawApplicative F) (FLawful : LawfulApplicativeImp FAppl) where
open RawApplicative FAppl public
open LawfulApplicativeImp FLawful public
open LawfulFunctorImp isLawfulFunctor public
| {
"alphanum_fraction": 0.5574526996,
"avg_line_length": 50.3953488372,
"ext": "agda",
"hexsha": "5b34c43eb121d8a498fce1fa6c42f314042e2b4e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crisoagf/agda-optics",
"max_forks_repo_path": "src/Category/Functor/Lawful.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crisoagf/agda-optics",
"max_issues_repo_path": "src/Category/Functor/Lawful.agda",
"max_line_length": 129,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crisoagf/agda-optics",
"max_stars_repo_path": "src/Category/Functor/Lawful.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 877,
"size": 2167
} |
module Common.Equality where
open import Common.Level
infix 4 _≡_
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
subst : ∀ {a p}{A : Set a}(P : A → Set p){x y : A} → x ≡ y → P x → P y
subst P refl t = t | {
"alphanum_fraction": 0.541958042,
"avg_line_length": 20.4285714286,
"ext": "agda",
"hexsha": "b9a84df0fda80d5570299dade21768b9458e5fa2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/Common/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/agda-kanso",
"max_issues_repo_path": "test/Common/Equality.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/Common/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 114,
"size": 286
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Unary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Unary where
open import Data.Empty
open import Data.Unit.Base using (⊤)
open import Data.Product
open import Data.Sum using (_⊎_; [_,_])
open import Function
open import Level
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality.Core using (_≡_)
------------------------------------------------------------------------
-- Unary relations
Pred : ∀ {a} → Set a → (ℓ : Level) → Set (a ⊔ suc ℓ)
Pred A ℓ = A → Set ℓ
------------------------------------------------------------------------
-- Unary relations can be seen as sets
-- i.e. they can be seen as subsets of the universe of discourse.
module _ {a} {A : Set a} where
----------------------------------------------------------------------
-- Special sets
-- The empty set
∅ : Pred A zero
∅ = λ _ → ⊥
-- The singleton set
{_} : A → Pred A a
{ x } = x ≡_
-- The universe
U : Pred A zero
U = λ _ → ⊤
----------------------------------------------------------------------
-- Membership
infix 4 _∈_ _∉_
_∈_ : ∀ {ℓ} → A → Pred A ℓ → Set _
x ∈ P = P x
_∉_ : ∀ {ℓ} → A → Pred A ℓ → Set _
x ∉ P = ¬ x ∈ P
----------------------------------------------------------------------
-- Subsets
infix 4 _⊆_ _⊇_ _⊈_ _⊉_ _⊂_ _⊃_ _⊄_ _⊅_
_⊆_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
_⊇_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊇ Q = Q ⊆ P
_⊈_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊈ Q = ¬ (P ⊆ Q)
_⊉_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊉ Q = ¬ (P ⊇ Q)
_⊂_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊂ Q = P ⊆ Q × Q ⊈ P
_⊃_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊃ Q = Q ⊂ P
_⊄_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊄ Q = ¬ (P ⊂ Q)
_⊅_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊅ Q = ¬ (P ⊃ Q)
-- Dashed variants of _⊆_ for when 'x' can't be inferred from 'x ∈ P'.
infix 4 _⊆′_ _⊇′_ _⊈′_ _⊉′_ _⊂′_ _⊃′_ _⊄′_ _⊅′_
_⊆′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊆′ Q = ∀ x → x ∈ P → x ∈ Q
_⊇′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
Q ⊇′ P = P ⊆′ Q
_⊈′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊈′ Q = ¬ (P ⊆′ Q)
_⊉′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊉′ Q = ¬ (P ⊇′ Q)
_⊂′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊂′ Q = P ⊆′ Q × Q ⊈′ P
_⊃′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊃′ Q = Q ⊂′ P
_⊄′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊄′ Q = ¬ (P ⊂′ Q)
_⊅′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊅′ Q = ¬ (P ⊃′ Q)
----------------------------------------------------------------------
-- Properties of sets
-- Emptiness
Empty : ∀ {ℓ} → Pred A ℓ → Set _
Empty P = ∀ x → x ∉ P
-- Satisfiable
Satisfiable : ∀ {ℓ} → Pred A ℓ → Set _
Satisfiable P = ∃ λ x → x ∈ P
-- Universality
infix 10 Universal IUniversal
Universal : ∀ {ℓ} → Pred A ℓ → Set _
Universal P = ∀ x → x ∈ P
IUniversal : ∀ {ℓ} → Pred A ℓ → Set _
IUniversal P = ∀ {x} → x ∈ P
syntax Universal P = Π[ P ]
syntax IUniversal P = ∀[ P ]
-- Decidability
Decidable : ∀ {ℓ} → Pred A ℓ → Set _
Decidable P = ∀ x → Dec (P x)
-- Irrelevance
Irrelevant : ∀ {ℓ} → Pred A ℓ → Set _
Irrelevant P = ∀ {x} (a : P x) (b : P x) → a ≡ b
----------------------------------------------------------------------
-- Operations on sets
-- Set complement.
∁ : ∀ {ℓ} → Pred A ℓ → Pred A ℓ
∁ P = λ x → x ∉ P
-- Positive version of non-disjointness, dual to inclusion.
infix 4 _≬_
_≬_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ≬ Q = ∃ λ x → x ∈ P × x ∈ Q
-- Set union.
infixr 6 _∪_
_∪_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ∪ Q = λ x → x ∈ P ⊎ x ∈ Q
-- Set intersection.
infixr 7 _∩_
_∩_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ∩ Q = λ x → x ∈ P × x ∈ Q
-- Implication.
infixr 8 _⇒_
_⇒_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ⇒ Q = λ x → x ∈ P → x ∈ Q
-- Infinitary union and intersection.
infix 10 ⋃ ⋂
⋃ : ∀ {ℓ i} (I : Set i) → (I → Pred A ℓ) → Pred A _
⋃ I P = λ x → Σ[ i ∈ I ] P i x
syntax ⋃ I (λ i → P) = ⋃[ i ∶ I ] P
⋂ : ∀ {ℓ i} (I : Set i) → (I → Pred A ℓ) → Pred A _
⋂ I P = λ x → (i : I) → P i x
syntax ⋂ I (λ i → P) = ⋂[ i ∶ I ] P
-- Update.
infixr 9 _⊢_
_⊢_ : ∀ {a b} {A : Set a} {B : Set b} {ℓ} → (A → B) → Pred B ℓ → Pred A ℓ
f ⊢ P = λ x → P (f x)
------------------------------------------------------------------------
-- Unary relation combinators
infixr 2 _⟨×⟩_
infixr 2 _⟨⊙⟩_
infixr 1 _⟨⊎⟩_
infixr 0 _⟨→⟩_
infixl 9 _⟨·⟩_
infix 10 _~
infixr 9 _⟨∘⟩_
infixr 2 _//_ _\\_
_⟨×⟩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
Pred A ℓ₁ → Pred B ℓ₂ → Pred (A × B) _
(P ⟨×⟩ Q) (x , y) = x ∈ P × y ∈ Q
_⟨⊙⟩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
Pred A ℓ₁ → Pred B ℓ₂ → Pred (A × B) _
(P ⟨⊙⟩ Q) (x , y) = x ∈ P ⊎ y ∈ Q
_⟨⊎⟩_ : ∀ {a b ℓ} {A : Set a} {B : Set b} →
Pred A ℓ → Pred B ℓ → Pred (A ⊎ B) _
P ⟨⊎⟩ Q = [ P , Q ]
_⟨→⟩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
Pred A ℓ₁ → Pred B ℓ₂ → Pred (A → B) _
(P ⟨→⟩ Q) f = P ⊆ Q ∘ f
_⟨·⟩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
(P : Pred A ℓ₁) (Q : Pred B ℓ₂) →
(P ⟨×⟩ (P ⟨→⟩ Q)) ⊆ Q ∘ uncurry (flip _$_)
(P ⟨·⟩ Q) (p , f) = f p
-- Converse.
_~ : ∀ {a b ℓ} {A : Set a} {B : Set b} →
Pred (A × B) ℓ → Pred (B × A) ℓ
P ~ = P ∘ swap
-- Composition.
_⟨∘⟩_ : ∀ {a b c ℓ₁ ℓ₂} {A : Set a} {B : Set b} {C : Set c} →
Pred (A × B) ℓ₁ → Pred (B × C) ℓ₂ → Pred (A × C) _
(P ⟨∘⟩ Q) (x , z) = ∃ λ y → (x , y) ∈ P × (y , z) ∈ Q
-- Post and pre-division.
_//_ : ∀ {a b c ℓ₁ ℓ₂} {A : Set a} {B : Set b} {C : Set c} →
Pred (A × C) ℓ₁ → Pred (B × C) ℓ₂ → Pred (A × B) _
(P // Q) (x , y) = Q ∘ _,_ y ⊆ P ∘ _,_ x
_\\_ : ∀ {a b c ℓ₁ ℓ₂} {A : Set a} {B : Set b} {C : Set c} →
Pred (A × C) ℓ₁ → Pred (A × B) ℓ₂ → Pred (B × C) _
P \\ Q = (P ~ // Q ~) ~
| {
"alphanum_fraction": 0.4055366683,
"avg_line_length": 23.3977272727,
"ext": "agda",
"hexsha": "5c72d2245eccbf866f8184dff95997ba09a1e620",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Unary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Unary.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Unary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2817,
"size": 6177
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Sn.Base where
open import Cubical.HITs.Susp
open import Cubical.Foundations.Pointed
open import Cubical.Data.Nat
open import Cubical.Data.NatMinusOne
open import Cubical.Data.Empty
open import Cubical.Foundations.Prelude
open import Cubical.Data.Bool
open import Cubical.HITs.S1
S : ℕ₋₁ → Type₀
S neg1 = ⊥
S (ℕ→ℕ₋₁ n) = Susp (S (-1+ n))
S₊ : ℕ → Type₀
S₊ 0 = Bool
S₊ 1 = S¹
S₊ (suc (suc n)) = Susp (S₊ (suc n))
ptSn : (n : ℕ) → S₊ n
ptSn zero = true
ptSn (suc zero) = base
ptSn (suc (suc n)) = north
-- Pointed version
S₊∙ : (n : ℕ) → Pointed₀
S₊∙ n = (S₊ n) , ptSn n
| {
"alphanum_fraction": 0.6645962733,
"avg_line_length": 21.4666666667,
"ext": "agda",
"hexsha": "a8c656e722f9edfb8578f88ccfbe4f0790463b66",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/Sn/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/Sn/Base.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/Sn/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 264,
"size": 644
} |
{-# OPTIONS --cubical --safe #-}
module Data.List.Syntax where
open import Data.List
open import Prelude
open import Data.Vec.Sigma using () renaming (toList to [_]) public
open import Data.Vec.Sigma
[_][_] : ∀ n → Vec A n → List A
[ n ][ xs ] = toList {n = n} xs
-- record ListSyntax {a b} (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
-- field [_] : B → List A
-- open ListSyntax ⦃ ... ⦄ public
-- instance
-- cons : ⦃ _ : ListSyntax A B ⦄ → ListSyntax A (A × B)
-- [_] ⦃ cons ⦄ (x , xs) = x ∷ [ xs ]
-- instance
-- sing : ListSyntax A A
-- [_] ⦃ sing ⦄ = _∷ []
| {
"alphanum_fraction": 0.5614334471,
"avg_line_length": 21.7037037037,
"ext": "agda",
"hexsha": "e07dc5e0a096f38e209f7c9f0ff1ad7dac3fc352",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/List/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/List/Syntax.agda",
"max_line_length": 74,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/List/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 215,
"size": 586
} |
module Data.Nat.DivMod.Properties where
open import Data.Nat
open ≤-Reasoning
open import Data.Nat.DivMod
open import Data.Nat.Etc
open import Data.Nat.Properties using (≰⇒>; m≤m+n)
open import Data.Nat.Properties.Simple using (+-right-identity; +-suc; +-assoc; +-comm; distribʳ-*-+)
open import Data.Fin using (Fin; toℕ; fromℕ; fromℕ≤; inject≤; inject₁)
renaming (_+_ to _F+_; zero to Fzero; suc to Fsuc)
open import Data.Fin.Properties using (bounded)
open import Function
-- import Level
open import Relation.Nullary.Negation using (contradiction; contraposition)
open import Relation.Nullary.Decidable using (True; False; toWitness)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; cong₂; sym; trans; inspect)
open PropEq.≡-Reasoning
renaming (begin_ to beginEq_; _≡⟨_⟩_ to _≡Eq⟨_⟩_; _∎ to _∎Eq)
ℕ-isDecTotalOrder = DecTotalOrder.isDecTotalOrder decTotalOrder
ℕ-isTotalOrder = IsDecTotalOrder.isTotalOrder ℕ-isDecTotalOrder
ℕ-isPartialOrder = IsTotalOrder.isPartialOrder ℕ-isTotalOrder
ℕ-isPreorder = IsPartialOrder.isPreorder ℕ-isPartialOrder
≤-refl = IsPreorder.reflexive ℕ-isPreorder
≤-antisym = IsPartialOrder.antisym ℕ-isPartialOrder
≤-total = IsTotalOrder.total ℕ-isTotalOrder
lem-+-exchange : ∀ a b c d → (a + b) + (c + d) ≡ (a + c) + (b + d)
lem-+-exchange a b c d = beginEq
(a + b) + (c + d)
≡Eq⟨ sym (+-assoc (a + b) c d) ⟩
a + b + c + d
≡Eq⟨ cong (λ x → x + d) (+-assoc a b c) ⟩
a + (b + c) + d
≡Eq⟨ cong (λ x → a + x + d) (+-comm b c) ⟩
a + (c + b) + d
≡Eq⟨ cong (λ x → x + d) (sym (+-assoc a c b)) ⟩
a + c + b + d
≡Eq⟨ +-assoc (a + c) b d ⟩
(a + c) + (b + d)
∎Eq
{-
beginEq
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
∎Eq
-}
record DM (dividend divisor : ℕ) : Set where
constructor dm
field
q : ℕ
r : Fin divisor
{-
_DM+_ : ∀ {b m n} → DM m b → DM n b → DM (m + n) b
_DM+_ {zero} (dm q₀ ()) (dm q₁ ())
_DM+_ {suc b} (dm zero Fzero) (dm q₁ r₁) = dm q₁ Fzero
_DM+_ {suc n₁} (dm zero (Fsuc r₀)) (dm q₁ r₁) = {! !}
_DM+_ {suc b} (dm (suc q₀) Fzero) (dm q₁ r₁) = {! !}
_DM+_ {suc b} (dm (suc q₀) (Fsuc r₀)) (dm q₁ r₁) = {! !}
-}
{-
_DivMod+_ : ∀ {b m n} → DivMod m b → DivMod n b → DivMod (m + n) b
_DivMod+_ {zero} (result q₀ () prop₀) (result q₁ () prop₁)
_DivMod+_ {suc b} {m} {n} (result zero Fzero prop₀) (result q₁ r₁ prop₁) = result q₁ r₁ {! prop₁ !} -- (cong₂ _+_ prop₀ prop₁)
_DivMod+_ {suc b} {m} {n} (result zero (Fsuc r₀) prop₀) (result q₁ r₁ prop₁) with ((toℕ (Fsuc r₀) + toℕ r₁) divMod (suc b))
_DivMod+_ {suc b} {m} {n} (result zero (Fsuc r₀) prop₀) (result q₁ r₁ prop₁) | result zero rᵣ propᵣ =
let q = q₁
r = rᵣ
in result q r $
beginEq
m + n
≡Eq⟨ cong₂ _+_ prop₀ prop₁ ⟩
suc (toℕ r₀ + zero + (toℕ r₁ + q₁ * suc b))
≡Eq⟨ lem-+-exchange (suc (toℕ r₀)) zero (toℕ r₁) (q₁ * suc b) ⟩
suc (toℕ r₀ + toℕ r₁) + (q₁ * suc b)
≡Eq⟨ cong (λ x → x + q₁ * suc b) propᵣ ⟩
toℕ rᵣ + zero + q₁ * suc b
≡Eq⟨ cong (λ x → x + q₁ * suc b) (+-right-identity (toℕ rᵣ)) ⟩
toℕ rᵣ + q₁ * suc b
∎Eq
_DivMod+_ {suc b} {m} {n} (result zero (Fsuc r₀) prop₀) (result q₁ r₁ prop₁) | result (suc qᵣ) rᵣ propᵣ =
let q = suc qᵣ + q₁
r = rᵣ
in result q r $
beginEq
m + n
≡Eq⟨ cong₂ _+_ prop₀ prop₁ ⟩
suc (toℕ r₀) + zero + (toℕ r₁ + q₁ * suc b)
≡Eq⟨ lem-+-exchange (suc (toℕ r₀)) zero (toℕ r₁) (q₁ * suc b) ⟩
suc (toℕ r₀) + toℕ r₁ + q₁ * suc b
≡Eq⟨ cong (λ x → x + q₁ * suc b) propᵣ ⟩
toℕ rᵣ + suc qᵣ * suc b + q₁ * suc b
≡Eq⟨ +-assoc (toℕ rᵣ) (suc qᵣ * suc b) (q₁ * suc b) ⟩
toℕ rᵣ + (suc qᵣ * suc b + q₁ * suc b)
≡Eq⟨ cong (λ x → toℕ rᵣ + x) (sym (distribʳ-*-+ (suc b) (suc qᵣ) q₁)) ⟩
toℕ rᵣ + (suc qᵣ + q₁) * suc b
∎Eq
_DivMod+_ {suc b} {m} {n} (result (suc q₀) Fzero prop₀) (result q₁ r₁ prop₁) = result (suc q₀ + q₁) r₁ $
beginEq
m + n
≡Eq⟨ cong₂ _+_ prop₀ prop₁ ⟩
suc q₀ * suc b + (toℕ r₁ + q₁ * suc b)
≡Eq⟨ sym (+-assoc (suc (b + q₀ * suc b)) (toℕ r₁) (q₁ * suc b)) ⟩
suc q₀ * suc b + toℕ r₁ + q₁ * suc b
≡Eq⟨ cong (λ x → x + q₁ * suc b) (+-comm (suc q₀ * suc b) (toℕ r₁)) ⟩
toℕ r₁ + suc q₀ * suc b + q₁ * suc b
≡Eq⟨ +-assoc (toℕ r₁) (suc q₀ * suc b) (q₁ * suc b) ⟩
toℕ r₁ + (suc q₀ * suc b + q₁ * suc b)
≡Eq⟨ cong (λ x → toℕ r₁ + x) (sym (distribʳ-*-+ (suc b) (suc q₀) q₁)) ⟩
toℕ r₁ + (suc q₀ + q₁) * suc b
∎Eq
_DivMod+_ {suc b} {m} {n} (result (suc q₀) (Fsuc r₀) prop₀) (result q₁ r₁ prop₁) with ((toℕ (Fsuc r₀) + toℕ r₁) divMod (suc b))
_DivMod+_ {suc b} {m} {n} (result (suc q₀) (Fsuc r₀) prop₀) (result q₁ r₁ prop₁) | result zero rᵣ propᵣ =
let q = suc q₀ + q₁
r = rᵣ
in result q r $
beginEq
m + n
≡Eq⟨ cong₂ _+_ prop₀ prop₁ ⟩
(suc (toℕ r₀) + suc q₀ * suc b) + (toℕ r₁ + q₁ * suc b)
≡Eq⟨ lem-+-exchange (suc (toℕ r₀)) (suc (b + q₀ * suc b)) (toℕ r₁) (q₁ * suc b) ⟩
(suc (toℕ r₀) + toℕ r₁) + (suc q₀ * suc b + q₁ * suc b)
≡Eq⟨ cong (λ x → (suc (toℕ r₀) + toℕ r₁) + x) (sym (distribʳ-*-+ (suc b) (suc q₀) q₁)) ⟩
(suc (toℕ r₀) + toℕ r₁) + (suc q₀ + q₁) * suc b
≡Eq⟨ cong (λ x → x + suc (q₀ + q₁) * suc b) propᵣ ⟩
toℕ rᵣ + zero + suc (b + (q₀ + q₁) * suc b)
≡Eq⟨ cong (λ x → x + suc (q₀ + q₁) * suc b) (+-right-identity (toℕ rᵣ)) ⟩
toℕ rᵣ + suc (q₀ + q₁) * suc b
∎Eq
_DivMod+_ {suc b} {m} {n} (result (suc q₀) (Fsuc r₀) prop₀) (result q₁ r₁ prop₁) | result (suc qᵣ) rᵣ propᵣ =
let q = suc qᵣ + (suc q₀ + q₁)
r = rᵣ
in result q r $
beginEq
m + n
≡Eq⟨ cong₂ _+_ prop₀ prop₁ ⟩
suc (toℕ r₀ + suc q₀ * suc b) + (toℕ r₁ + q₁ * suc b)
≡Eq⟨ lem-+-exchange (suc (toℕ r₀)) (suc (b + q₀ * suc b)) (toℕ r₁) (q₁ * suc b) ⟩
suc (toℕ r₀) + toℕ r₁ + ((suc q₀) * suc b + q₁ * suc b)
≡Eq⟨ cong (λ x → suc (toℕ r₀) + toℕ r₁ + x) (sym (distribʳ-*-+ (suc b) (suc q₀) q₁)) ⟩
suc (toℕ r₀) + toℕ r₁ + (suc q₀ + q₁) * suc b
≡Eq⟨ cong (λ x → x + (suc q₀ + q₁) * suc b) propᵣ ⟩
toℕ rᵣ + suc qᵣ * suc b + (suc q₀ + q₁) * suc b
≡Eq⟨ +-assoc (toℕ rᵣ) (suc qᵣ * suc b) ((suc q₀ + q₁) * suc b) ⟩
toℕ rᵣ + (suc qᵣ * suc b + (suc q₀ + q₁) * suc b)
≡Eq⟨ cong (λ x → toℕ rᵣ + x) (sym (distribʳ-*-+ (suc b) (suc qᵣ) (suc (q₀ + q₁)))) ⟩
toℕ rᵣ + (suc qᵣ + (suc q₀ + q₁)) * suc b
∎Eq
-}
-- DivMod+-left-identity : ∀ {b n} → (x : DivMod n (suc b)) → _DivMod+_ {suc b} {0} {n} (result 0 Fzero refl) x ≡ x
-- DivMod+-left-identity {b} {n} (result q r prop) = {! !}
{-
beginEq
_DivMod+_ {suc b} {m} {n} (result 0 Fzero p) (result q r prop)
≡Eq⟨ refl ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
result q r prop
∎Eq -- cong (result q r) {! !} -- cong (result q r) refl
-}
{-
DivMod+-left-identity : ∀ {b m} → (x : DivMod m (suc b)) → (result 0 Fzero refl) DivMod+ x ≡ x
DivMod+-left-identity {b} {m} (result q r prop) with (toℕ Fzero + toℕ r) divMod (suc b)
DivMod+-left-identity {b} {m} (result q r prop) | result zero rᵣ propᵣ =
-- propᵣ : toℕ r ≡ toℕ rᵣ + 0
-- prop : m ≡ toℕ r + q * suc b
-- prop : m ≡ toℕ rᵣ + q * suc b
-- trans (cong₂ _+_ refl prop) (trans (trans (cong (λ z → z + q * suc b) (sym (+-right-identity (toℕ r)))) (trans (+-assoc (toℕ r) zero (q * suc b)) refl)) (trans (cong₂ _+_ propᵣ refl) (trans (cong (λ z → z + q * suc b) (+-right-identity (toℕ rᵣ))) refl))))
let prop' = beginEq
m
≡Eq⟨ cong₂ _+_ refl prop ⟩
toℕ r + q * suc b
≡Eq⟨ cong₂ _+_ propᵣ refl ⟩
toℕ rᵣ + 0 + q * suc b
≡Eq⟨ cong₂ _+_ (+-right-identity (toℕ rᵣ)) refl ⟩
toℕ rᵣ + q * suc b
∎Eq
in beginEq
result q rᵣ prop'
≡Eq⟨ cong (λ x → result q x {! prop' !}) (sym {! +-right-identity !}) ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
result q r prop
∎Eq
DivMod+-left-identity (result q r prop) | result (suc qᵣ) rᵣ propᵣ = {! !}
-}
{-
DivMod+-left-identity : ∀ {b m} → (x : DivMod m (suc b)) → (result 0 Fzero refl) DivMod+ x ≡ x
DivMod+-left-identity {b} {m} (result q r prop) with (toℕ r) divMod (suc b)
DivMod+-left-identity {b} {m} (result q r prop) | result zero rᵣ propᵣ =
beginEq
result q rᵣ (beginEq
m
≡Eq⟨ cong (λ z → z) prop ⟩
toℕ r + q * suc b
≡Eq⟨ cong (λ z → z + q * suc b) (sym (+-right-identity (toℕ r))) ⟩
(toℕ r + zero) + q * suc b
≡Eq⟨ cong (λ z → z + zero + q * suc b) propᵣ ⟩
toℕ rᵣ + zero + zero + q * suc b
≡Eq⟨ cong (λ z → z + zero + q * suc b) (+-right-identity (toℕ rᵣ)) ⟩
(toℕ rᵣ + zero) + q * suc b
≡Eq⟨ +-assoc (toℕ rᵣ) zero (q * suc b) ⟩
toℕ rᵣ + q * suc b
∎Eq)
≡Eq⟨ {! !} ⟩
result q r prop
∎Eq
DivMod+-left-identity (result q r prop) | result (suc qᵣ) rᵣ propᵣ =
beginEq
(result 0 Fzero refl) DivMod+ {! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
result q r prop
∎Eq
DivMod+-left-identity : (b n : ℕ) → (≢0 : False (b ≟ 0)) → ((0 divMod b) {≢0}) DivMod+ ((n divMod b) {≢0}) ≡ ((n divMod b) {≢0})
DivMod+-left-identity zero n ()
DivMod+-left-identity (suc b) zero ≢0 = refl
DivMod+-left-identity (suc b) (suc n) ≢0 = {! !}
divMod-hom : (b m n : ℕ) → (≢0 : False (b ≟ 0)) → ((m + n) divMod b) {≢0} ≡ ((m divMod b) {≢0}) DivMod+ ((n divMod b) {≢0})
divMod-hom zero m n ()
divMod-hom (suc b) zero n ≢0 = {! !}
divMod-hom (suc b) (suc m) n ≢0 = {! !}
div-suc-mono : (n base : ℕ) → (≢0 : False (base ≟ 0))
→ let _/base = λ x → (x div base) {≢0}
in suc n /base ≥ n /base
div-suc-mono n zero ()
div-suc-mono zero (suc b) ≢0 = z≤n
div-suc-mono (suc n) (suc b) ≢0 = {! !}
-}
-- TODO: proof div monotone
postulate
div-mono : (base : ℕ) → (≢0 : False (base ≟ 0))
→ let _/base = λ x → (x div base) {≢0}
in _/base Preserves _≤_ ⟶ _≤_
{-
n/n≡1 : ∀ n → (≢0 : False (n ≟ 0)) → (n div n) {≢0} ≡ 1
n/n≡1 zero ()
n/n≡1 (suc n) ≢0 with ((suc n) divMod (suc n)) {≢0} | inspect (λ w → ((suc n) divMod (suc n)) {w}) ≢0
n/n≡1 (suc n) ≢0 | result zero r prop | PropEq.[ eq ] =
let prop' : suc n ≡ toℕ r
prop' = trans prop (+-right-identity (toℕ r))
in contradiction (≤-refl prop') (>⇒≰ (bounded r))
n/n≡1 (suc n) ≢0 | result (suc zero) r prop | PropEq.[ eq ] = {! !}
n/n≡1 (suc n) ≢0 | result (suc (suc q)) r prop | PropEq.[ eq ] =
let prop' : suc n ≡ suc n + toℕ r + suc q * suc n
prop' = beginEq
suc n
≡Eq⟨ prop ⟩
toℕ r + (suc n + suc (n + q * suc n))
≡Eq⟨ sym (+-assoc (toℕ r) (suc n) (suc (n + q * suc n))) ⟩
toℕ r + suc n + suc (n + q * suc n)
≡Eq⟨ cong₂ _+_ (+-comm (toℕ r) (suc n)) refl ⟩
suc (n + toℕ r + suc (n + q * suc n))
∎Eq
in contradiction (≤-refl prop') (>⇒≰ {! !})
lem : ∀ m n → n ≤ m → (≢0 : False (n ≟ 0)) → (n div n) {≢0} ≤ (m div n) {≢0}
lem m zero n≤m ()
lem m (suc n) n≤m ≢0 = div-mono (suc n) {! !} n≤m
-}
{-
div-mono : (base : ℕ) → (≢0 : False (base ≟ 0))
→ let _/base = λ x → (x div base) {≢0}
in _/base Preserves _≤_ ⟶ _≤_
div-mono zero () rel
div-mono (suc b) ≢0 z≤n = z≤n
div-mono (suc b) ≢0 (s≤s {x} {y} rel) with compare x y
div-mono (suc b) ≢0 (s≤s rel) | less m k with ((suc m) divMod (suc b)) {≢0}
| inspect (λ w → ((suc m) divMod (suc b)) {w}) ≢0
| ((suc (suc m + k)) divMod (suc b)) {≢0}
| inspect (λ w → ((suc (suc m + k)) divMod (suc b)) {w}) ≢0
| ((suc k) divMod (suc b)) {≢0}
| inspect (λ w → ((suc k) divMod (suc b)) {w}) ≢0
div-mono (suc b) ≢0 (s≤s rel) | less m k | result q₀ r₀ prop₀ | PropEq.[ eq₀ ] | result q₁ r₁ prop₁ | PropEq.[ eq₁ ] | result q₂ r₂ prop₂ | PropEq.[ eq₂ ] =
-- prop₀: suc m ≡ toℕ r₀ + qₒ * suc b
-- prop₁: suc (suc m + k) ≡ toℕ r₁ + q₁ * suc b
-- prop₂: suc k ≡ toℕ r₂ + q₂ * suc b
begin
q₀
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
q₁
∎
div-mono (suc b) ≢0 (s≤s rel) | equal m = ≤-refl refl
div-mono (suc b) ≢0 (s≤s rel) | greater m k = contradiction rel (>⇒≰ (s≤s (m≤m+n m k)))
div-mono (suc b) ≢0 (s≤s {x} {y} rel) with (x divMod (suc b)) {≢0}
| inspect (λ w → (x divMod (suc b)) {w}) ≢0
| (y divMod (suc b)) {≢0}
| inspect (λ w → (y divMod (suc b)) {w}) ≢0
div-mono (suc b) ≢0 (s≤s {x} {y} rel) | result qx rx propx | PropEq.[ eqx ] | result qy ry propy | PropEq.[ eqy ] with = {! !}
begin
{! !}
<⟨ {! !} ⟩
{! !}
<⟨ {! !} ⟩
{! !}
∎
begin
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
≤⟨ {! !} ⟩
{! !}
∎
beginEq
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
≡Eq⟨ {! !} ⟩
{! !}
∎Eq
-}
| {
"alphanum_fraction": 0.4437824732,
"avg_line_length": 39.6565934066,
"ext": "agda",
"hexsha": "e4ccf5eb7e17aea9cd3465edfd027429a2504e1b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "legacy/Data/Nat/DivMod/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "legacy/Data/Nat/DivMod/Properties.agda",
"max_line_length": 262,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "legacy/Data/Nat/DivMod/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 6328,
"size": 14435
} |
open import Relation.Binary.Core
module Heapsort.Impl2.Correctness.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_ hiding (forget) renaming (flatten to flatten')
open import BBHeap.Compound _≤_
open import BBHeap.Drop _≤_ tot≤ trans≤
open import BBHeap.Drop.Properties _≤_ tot≤ trans≤
open import BBHeap.Heapify _≤_ tot≤ trans≤
open import BBHeap.Insert _≤_ tot≤ trans≤
open import BBHeap.Insert.Properties _≤_ tot≤ trans≤
open import BBHeap.Order _≤_
open import BBHeap.Order.Properties _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.List
open import Heapsort.Impl2 _≤_ tot≤ trans≤
open import List.Permutation.Base A
open import List.Permutation.Base.Equivalence A
open import OList _≤_
open import Order.Total _≤_ tot≤
lemma-flatten-flatten' : {b : Bound}(h : BBHeap b)(accₕ : Acc h) → forget (flatten h accₕ) ∼ flatten' h
lemma-flatten-flatten' leaf _ = ∼[]
lemma-flatten-flatten' (left {l = l} {r = r} b≤x l⋘r) (acc rs) = ∼x /head /head (trans∼ (lemma-flatten-flatten' (drop⋘ b≤x l⋘r) (rs (drop⋘ b≤x l⋘r) (lemma-drop≤′ (cl b≤x l⋘r)))) (lemma-drop⋘∼ b≤x l⋘r))
lemma-flatten-flatten' (right {l = l} {r = r} b≤x l⋙r) (acc rs) = ∼x /head /head (trans∼ (lemma-flatten-flatten' (drop⋙ b≤x l⋙r) (rs (drop⋙ b≤x l⋙r) (lemma-drop≤′ (cr b≤x l⋙r)))) (lemma-drop⋙∼ b≤x l⋙r))
lemma-flatten'-flatten : {b : Bound}(h : BBHeap b)(accₕ : Acc h) → (flatten' h) ∼ (forget (flatten h accₕ))
lemma-flatten'-flatten h tₕ = sym∼ (lemma-flatten-flatten' h tₕ)
theorem-heapsort∼ : (xs : List A) → xs ∼ forget (heapsort xs)
theorem-heapsort∼ [] = ∼[]
theorem-heapsort∼ (x ∷ xs) =
let h = heapify xs ;
accₕ = ≺-wf h ;
hᵢ = insert lebx h ;
accₕᵢ = ≺-wf hᵢ ;
xs∼fh = theorem-heapsort∼ xs ;
fh∼f'h = lemma-flatten-flatten' h accₕ ;
xs∼f'h = trans∼ xs∼fh fh∼f'h ;
xxs∼xf'h = ∼x /head /head xs∼f'h ;
xf'h∼f'hᵢ = lemma-insert∼ lebx h ;
xxs∼f'hᵢ = trans∼ xxs∼xf'h xf'h∼f'hᵢ ;
f'hᵢ∼fhᵢ = lemma-flatten'-flatten hᵢ accₕᵢ
in trans∼ xxs∼f'hᵢ f'hᵢ∼fhᵢ
| {
"alphanum_fraction": 0.5742449664,
"avg_line_length": 48.6530612245,
"ext": "agda",
"hexsha": "520565ae25c850ee1bd6d726711cf8ff97480c64",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/Heapsort/Impl2/Correctness/Permutation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/Heapsort/Impl2/Correctness/Permutation.agda",
"max_line_length": 202,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/Heapsort/Impl2/Correctness/Permutation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 905,
"size": 2384
} |
module Rec2 where
open import Data.Nat
open import Rec1
x : ℕ
x = 42
z : ℕ
z = y
| {
"alphanum_fraction": 0.5729166667,
"avg_line_length": 8.7272727273,
"ext": "agda",
"hexsha": "a355d47f47a5c8330c1df1deedcf8fa082b2e594",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "5468837f55cbea38d5c5a163e1ea5d48edb92bcc",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "andorp/plfa.github.io",
"max_forks_repo_path": "extra/extra/Rec2.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "5468837f55cbea38d5c5a163e1ea5d48edb92bcc",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "andorp/plfa.github.io",
"max_issues_repo_path": "extra/extra/Rec2.agda",
"max_line_length": 22,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "5468837f55cbea38d5c5a163e1ea5d48edb92bcc",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "andorp/plfa.github.io",
"max_stars_repo_path": "extra/extra/Rec2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 39,
"size": 96
} |
-- Following A CUBICAL TYPE THEORY FOR HIGHER INDUCTIVE TYPES
-- by Simon Huber at https://simhu.github.io/misc/hcomp.pdf
-- as closely as possible.
open import Cubical.Core.Primitives
open import Cubical.Core.Glue
import Agda.Builtin.Cubical.HCompU as HCompU
open HCompU using (primFaceForall)
open HCompU.Helpers using (refl)
private
variable
ℓ ℓ₁ : Level
ℓ′ ℓ₁′ : I → Level
-- Section 2 : New Primitives
-- This is just a special case of transp where φ = i0. I include it as it
-- has a far simpler type.
transport : (A : ∀ i → Type (ℓ′ i)) → A i0 → A i1
transport A u₀ = transp A i0 u₀
transp' :
(φ : I)
{ℓ' : I → Level [ φ ↦ (λ _ → ℓ) ]}
{a : PartialP φ (λ _ → Type ℓ)}
(A : (i : I) → Type (outS (ℓ' i)) [ φ ↦ (λ { (φ = i1) → a 1=1 }) ])
(u₀ : outS (A i0))
→ outS (A i1) [ φ ↦ (λ { (φ = i1) → u₀ }) ]
transp' φ A u₀ = inS (transp (λ i → outS (A i)) φ u₀)
transportFill :
(A : ∀ i → Type (ℓ′ i))
(u₀ : A i0)
(i : I)
→ A i
transportFill A u₀ i = transp (λ j → A (i ∧ j)) (~ i) u₀
-- Note that I fix the universe of A to make the type simpler. From now on we
-- are going to do that for all code involving transp where φ is not just i0.
transpFill :
(φ : I)
{a : Partial φ (Type ℓ)}
(A : I → Type ℓ [ φ ↦ a ])
(u₀ : outS (A i0))
(i : I)
→ outS (A i)
transpFill φ A u₀ i = transp (λ j → outS (A (i ∧ j))) (φ ∨ ~ i) u₀
forward :
(A : ∀ i → Type (ℓ′ i))
(r : I)
(u : A r)
→ A i1
forward A r u = transp (λ i → A (i ∨ r)) r u
hcomp' :
{A : Type ℓ}
{φ : I}
(u : ∀ i → Partial φ A)
(u₀ : A [ φ ↦ u i0 ])
→ A [ φ ↦ u i1 ]
hcomp' u u₀ = inS (hcomp u (outS u₀))
module Comp
(A : ∀ i → Type (ℓ′ i))
{φ : I}
(u : ∀ i → Partial φ (A i))
(u₀ : A i0 [ φ ↦ u i0 ])
where
comp' : A i1 [ φ ↦ u i1 ]
comp' =
inS
(hcomp
(λ i o → forward A i (u i o))
(forward A i0 (outS u₀)))
compId : comp A {φ = φ} u (outS u₀) ≡ outS comp'
compId = refl
-- Section 3 : Recursive definition of transport
data ℕ : Type where
zero : ℕ
suc : ℕ → ℕ
transpZeroId : (φ : I) → transp (λ _ → ℕ) φ zero ≡ zero
transpZeroId φ = refl
transpSucId : (φ : I) (u₀ : ℕ)
→ transp (λ _ → ℕ) φ (suc u₀) ≡ suc (transp (λ _ → ℕ) φ u₀)
transpSucId φ u₀ = refl
transpℕId : (φ : I) (u₀ : ℕ) → transp (λ _ → ℕ) φ u₀ ≡ u₀
transpℕId φ u₀ = refl
transportPathPId :
(A : (i j : I) → Type (ℓ′ i))
(v : (i : I) → A i i0)
(w : (i : I) → A i i1)
(u₀ : PathP (A i0) (v i0) (w i0))
→ transport (λ i → PathP (A i) (v i) (w i)) u₀
≡ λ j → comp
(λ i → A i j)
(λ i → λ
{ (j = i0) → v i
; (j = i1) → w i })
(u₀ j)
transportPathPId A v w u₀ = refl
transpPathPId :
(φ : I)
{a : I → Partial φ (Type ℓ)}
(A : (i j : I) → Type ℓ [ φ ↦ a j ])
{vφ : PartialP φ (a i0)}
(v : (i : I) → outS (A i i0) [ φ ↦ (λ { (φ = i1) → vφ 1=1 }) ])
{wφ : PartialP φ (a i1)}
(w : (i : I) → outS (A i i1) [ φ ↦ (λ { (φ = i1) → wφ 1=1 }) ])
(u₀ : PathP (λ j → outS (A i0 j)) (outS (v i0)) (outS (w i0)))
→ transp (λ i → PathP (λ j → outS (A i j)) (outS (v i)) (outS (w i))) φ u₀
≡ λ j → comp
(λ i → outS (A i j))
(λ i → λ
{ (φ = i1) → u₀ j
; (j = i0) → outS (v i)
; (j = i1) → outS (w i) })
(u₀ j)
transpPathPId φ A v w u₀ = refl
transportΣId :
(A : ∀ i → Type (ℓ′ i))
(B : ∀ i → A i → Type (ℓ₁′ i))
(u₀ : Σ (A i0) (B i0))
→ transport (λ i → Σ (A i) (B i)) u₀
≡ (transport A (u₀ .fst) ,
let v = transportFill A (u₀ .fst)
in transport (λ i → B i (v i)) (u₀ .snd))
transportΣId A B u₀ = refl
transpΣId :
(φ : I)
{a : Partial φ (Type ℓ)}
(A : I → Type ℓ [ φ ↦ a ])
{b : Partial φ (Type ℓ₁)}
(B : (i : I) → outS (A i) → Type ℓ₁ [ φ ↦ b ])
(u₀ : Σ (outS (A i0)) (λ x → outS (B i0 x)))
→ transp (λ i → Σ (outS (A i)) (λ x → outS (B i x))) φ u₀
≡ (transp (λ i → outS (A i)) φ (u₀ .fst) ,
let v = transpFill φ A (u₀ .fst)
in transp (λ i → outS (B i (v i))) φ (u₀ .snd))
transpΣId φ A B u₀ = refl
transportΠId :
(A : ∀ i → Type (ℓ′ i))
(B : ∀ i → A i → Type (ℓ₁′ i))
(u₀ : (x : A i0) → B i0 x)
→ transport (λ i → (x : A i) → B i x) u₀
≡ λ v →
let
w : (i : I) → A i
w i = transportFill (λ j → A (~ j)) v (~ i)
in
transport (λ i → B i (w i)) (u₀ (w i0))
transportΠId A B u₀ = refl
transpΠId :
(φ : I)
{a : Partial φ (Type ℓ)}
(A : I → Type ℓ [ φ ↦ a ])
{b : Partial φ (Type ℓ₁)}
(B : (i : I) → outS (A i) → Type ℓ₁ [ φ ↦ b ])
(u₀ : ((x : outS (A i0)) → outS (B i0 x)))
→ transp (λ i → (x : outS (A i)) → outS (B i x)) φ u₀
≡ λ v →
let
w : (i : I) → outS (A i)
w i = transpFill φ (λ j → (A (~ j))) v (~ i)
in
transp (λ i → outS (B i (w i))) φ (u₀ (w i0))
transpΠId φ A B u₀ = refl
transpUniverseId : (φ : I) (A : Type ℓ) → transp (λ _ → Type ℓ) φ A ≡ A
transpUniverseId φ A = refl
module TransportGlue
(A : ∀ i → Type (ℓ′ i))
(φ : I → I)
(T : (i : I) → Partial (φ i) (Type (ℓ₁′ i)))
(w : (i : I) → PartialP (φ i) (λ o → T i o ≃ A i))
(u₀ : primGlue (A i0) (T i0) (w i0))
where
B : (i : I) → Type (ℓ₁′ i)
B i = primGlue (A i) (T i) (w i)
∀φ : I
∀φ = primFaceForall φ
t : (i : I) → PartialP ∀φ (λ { (∀φ = i1) → T i 1=1 })
t i (∀φ = i1) = {!!}
transportGlue : B i1
transportGlue = {!!}
transportGlueId : transport B u₀ ≡ transportGlue
transportGlueId = {!!}
-- Section 4 : Recursive Definition of Homogeneous Composition
hcompZeroId : {φ : I} → hcomp (λ i → λ { (φ = i1) → zero }) zero ≡ zero
hcompZeroId = refl
hcompSucId :
{φ : I}
(u : I → Partial φ ℕ)
(u₀ : ℕ [ φ ↦ u i0 ])
→ hcomp (λ i o → suc (u i o)) (suc (outS u₀)) ≡ suc (hcomp u (outS u₀))
hcompSucId u u₀ = refl
hcompPathPId :
(A : I → Type ℓ)
(v : A i0)
(w : A i1)
{φ : I}
(u : I → Partial φ (PathP A v w))
(u₀ : PathP A v w [ φ ↦ u i0 ])
→ hcomp u (outS u₀)
≡ λ j →
hcomp
(λ i → λ { (φ = i1) → u i 1=1 j ; (j = i0) → v ; (j = i1) → w })
(outS u₀ j)
hcompPathPId A v w u u₀ = refl
hcompΣId :
(A : Type ℓ)
(B : (x : A) → Type ℓ₁)
{φ : I}
(u : I → Partial φ (Σ A B))
(u₀ : Σ A B [ φ ↦ u i0 ])
→ hcomp u (outS u₀)
≡ let
v : (i : I) → A
-- should use hfill instead
v = fill (λ _ → A) (λ i o → u i o .fst) (inS (outS u₀ .fst))
in
(v i1 ,
comp (λ i → B (v i)) (λ i → λ { (φ = i1) → u i 1=1 .snd }) (outS u₀ .snd))
hcompΣId A B u u₀ = refl
hcompΠId :
(A : Type ℓ)
(B : (x : A) → Type ℓ₁)
{φ : I}
(u : I → Partial φ ((x : A) → B x))
(u₀ : ((x : A) → B x) [ φ ↦ u i0 ])
→ hcomp u (outS u₀)
≡ λ v → hcomp (λ i o → u i o v) (outS u₀ v)
hcompΠId A B u u₀ = refl
-- Unfortunately hcomp E (outS A) is not judgmentally equal to
-- outS (hcompUniverse E A) which I don't know why.
hcompUniverse :
{φ : I}
(E : I → Partial φ (Type ℓ))
(A : Type ℓ [ φ ↦ E i0 ])
→ Type ℓ [ φ ↦ E i1 ]
hcompUniverse {φ = φ} E A =
inS
(primGlue
(outS A)
(E i1)
(λ { (φ = i1) → lineToEquiv (λ i → E (~ i) 1=1) }))
module HcompGlue
(A : Type ℓ)
{φ : I}
(T : Partial φ (Type ℓ₁))
(w : PartialP φ (λ o → T o ≃ A))
{ψ : I}
(u : I → Partial ψ (primGlue A T w))
(u₀ : primGlue A T w [ ψ ↦ u i0 ])
where
t : (i : I) → PartialP φ T
t i (φ = i1) = hfill u u₀ i
a₁ : A
a₁ = hcomp (λ i → λ
{ (ψ = i1) → unglue φ (u i 1=1)
; (φ = i1) → w 1=1 .fst (t i 1=1) })
(unglue φ (outS u₀))
hcompGlue : primGlue A T w [ ψ ↦ u i1 ]
hcompGlue = inS (glue (t i1) a₁)
hcompGlueId : hcomp u (outS u₀) ≡ outS hcompGlue
hcompGlueId = refl
| {
"alphanum_fraction": 0.4822891885,
"avg_line_length": 24.4854368932,
"ext": "agda",
"hexsha": "4c6ee76d259ef31211a648971b59707b17e8e3a7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3aa0425c12e2edeb284ab8588a2b25ea46ae4394",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "howsiyu/hott-notes",
"max_forks_repo_path": "hcomp_paper.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3aa0425c12e2edeb284ab8588a2b25ea46ae4394",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "howsiyu/hott-notes",
"max_issues_repo_path": "hcomp_paper.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3aa0425c12e2edeb284ab8588a2b25ea46ae4394",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "howsiyu/hott-notes",
"max_stars_repo_path": "hcomp_paper.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3499,
"size": 7566
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
module HoTT.Identity where
open variables
private variable x y z w : A
-- Lemma 2.1.4
-- (i)
unitᵣ : {p : x == y} → p == p ∙ refl
unitᵣ {p = refl} = refl
unitₗ : {p : x == y} → p == refl ∙ p
unitₗ {p = refl} = refl
-- (ii)
invₗ : {p : x == y} → p ⁻¹ ∙ p == refl
invₗ {p = refl} = refl
invᵣ : {p : x == y} → p ∙ p ⁻¹ == refl
invᵣ {p = refl} = refl
-- (iv)
assoc : {p : x == y} {q : y == z} {r : z == w} →
p ∙ (q ∙ r) == (p ∙ q) ∙ r
assoc {p = refl} {refl} {refl} = refl
invinv : {p : x == y} → p ⁻¹ ⁻¹ == p
invinv {p = refl} = refl
-- Whiskering
_∙ᵣ_ : {p q : x == y} (α : p == q) (r : y == z) → p ∙ r == q ∙ r
refl ∙ᵣ refl = refl
infixl 25 _∙ᵣ_
_∙ₗ_ : {r s : y == z} (q : x == y) (β : r == s) → q ∙ r == q ∙ s
refl ∙ₗ refl = refl
infixl 25 _∙ₗ_
-- Horizontal composition
_⋆_ : {p q : x == y} {r s : y == z} → (p == q) → (r == s) → p ∙ r == q ∙ s
refl ⋆ refl = refl
cancelᵣ : {p q : x == y} {r : y == z} (α : p ∙ r == q ∙ r) → p == q
cancelᵣ {r = refl} α = unitᵣ ∙ α ∙ unitᵣ ⁻¹
cancelₗ : {r s : y == z} {q : x == y} (β : q ∙ r == q ∙ s) → r == s
cancelₗ {q = refl} β = unitₗ ∙ β ∙ unitₗ ⁻¹
pivotᵣ : {p : x == y} {q : y == z} {r : x == z} → p ∙ q == r → p == r ∙ q ⁻¹
pivotᵣ {p = refl} {q = refl} α = α ∙ unitᵣ
pivotₗ : {p : x == y} {q : y == z} {r : x == z} → p ∙ q == r → q == p ⁻¹ ∙ r
pivotₗ {p = refl} {q = refl} α = α ∙ unitₗ
-- Lemma 2.2.2
-- (i)
ap-∙ : (f : A → B) (p : x == y) (q : y == z) → ap f (p ∙ q) == ap f p ∙ ap f q
ap-∙ _ refl refl = refl
-- (ii)
ap-inv : (f : A → B) (p : x == y) → ap f (p ⁻¹) == ap f p ⁻¹
ap-inv _ refl = refl
-- (iii)
ap-∘ : {C : 𝒰 i} (f : B → C) (g : A → B) (p : x == y) → ap (f ∘ g) p == ap f (ap g p)
ap-∘ _ _ refl = refl
-- (iv)
ap-id : (p : x == y) → ap id p == p
ap-id refl = refl
ap-const : (p : x == y) → ap (const B) p == refl
ap-const refl = refl
-- Lemma 2.3.5
transportconst : (p : x == y) → transport (const B) p ~ id
transportconst refl _ = refl
-- Lemma 2.3.9
transport-∙ : (P : A → 𝒰 i) (p : x == y) (q : y == z) →
transport P (p ∙ q) ~ transport P q ∘ transport P p
transport-∙ P refl refl _ = refl
-- Lemma 2.3.10
transport-ap : (P : B → 𝒰 i) (f : A → B) {x y : A} (p : x == y) →
transport P (ap f p) ~ transport (P ∘ f) p
transport-ap _ _ refl _ = refl
-- Lemma 2.3.11
transport-∘ : (f : {x : A} → P x → Q x) (p : x == y) →
transport Q p ∘ f ~ f ∘ transport P p
transport-∘ _ refl _ = refl
module =-Reasoning {i} {A : 𝒰 i}
where
_=⟨_⟩_ : (x : A) {y z : A} → x == y → y == z → x == z
x =⟨ p ⟩ q = p ∙ q
infixr 2 _=⟨_⟩_
_=⟨⟩_ : (x : A) {y : A} → x == y → x == y
_ =⟨⟩ p = p
infixr 2 _=⟨⟩_
_∎ : (x : A) → x == x
_ ∎ = refl
infix 3 _∎
| {
"alphanum_fraction": 0.4350364964,
"avg_line_length": 25.1376146789,
"ext": "agda",
"hexsha": "170d26688b8672ebc147ab3aa0aa6d7998e4dd3e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Identity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Identity.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Identity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1363,
"size": 2740
} |
open import Coinduction using ( ♭ ; ♯_ )
open import Data.Empty using ( ⊥-elim )
open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ )
open import Relation.Binary.PropositionalEquality
using ( _≡_ ; _≢_ ; refl ; sym ; cong ; cong₂ )
open import Relation.Nullary using ( ¬_ ; Dec ; yes ; no )
open import System.IO.Transducers.Lazy
using ( _⇒_ ; inp ; out ; done ; _⟫_ ;
equiv ; assoc ; assoc⁻¹ ; unit₁ ; unit₁⁻¹ ; unit₂ ; unit₂⁻¹ ;
_[&]_ ; ⟦_⟧ ; _≃_ )
open import System.IO.Transducers.Reflective using ( Reflective )
open import System.IO.Transducers.Strict using ( Strict )
open import System.IO.Transducers.Session
using ( I ; Σ ; IsΣ ; _∼_ ; ∼-refl ; ∼-trans ; ∼-sym ; _&_ )
renaming ( unit₁ to ∼-unit₁ ; unit₂ to ∼-unit₂ ; assoc to ∼-assoc )
open import System.IO.Transducers.Trace using ( Trace ; _✓ ; [] ; _∷_ )
open import System.IO.Transducers.Properties.Category
using ( ⟦done⟧ ; done-semantics ; _⟦⟫⟧_ ; ⟫-semantics ; ⟫-≃-⟦⟫⟧ ; ⟫-resp-≃ ; done-isEquiv ; ⟫-isEquiv ; equiv-is-iso )
open import System.IO.Transducers.Properties.Lemmas
using ( ≃-refl ; ≃-sym ; ✓-tl ; ✓? ; ⟦⟧-resp-✓ ; ⟦⟧-refl-✓ ; ⟦⟧-resp-[] ;
IsEquiv ; isEquiv ; ≃-equiv ; I-η)
module System.IO.Transducers.Properties.Monoidal where
open Relation.Binary.PropositionalEquality.≡-Reasoning
infixr 8 _++_ _⟦[&]⟧_
-- Concatenation of traces
_++_ : ∀ {S T} → (Trace S) → (Trace T) → (Trace (S & T))
_++_ {I} [] bs = bs
_++_ {Σ V F} [] bs = []
_++_ {Σ V F} (a ∷ as) bs = a ∷ (as ++ bs)
_++_ {I} (() ∷ as) bs
-- Projection of traces
front : ∀ {S T} → (Trace (S & T)) → (Trace S)
front {I} as = []
front {Σ V F} [] = []
front {Σ V F} (a ∷ as) = a ∷ front as
back : ∀ {S T} → (Trace (S & T)) → (Trace T)
back {I} as = as
back {Σ V F} [] = []
back {Σ V F} (a ∷ as) = back {♭ F a} as
-- Semantics of tensor
_⟦[&]⟧_ : ∀ {S T U V} →
(f : Trace S → Trace T) → (g : Trace U → Trace V) →
(Trace (S & U)) → (Trace (T & V))
_⟦[&]⟧_ {S} f g as = f (front as) ++ g (back {S} as)
[&]-semantics : ∀ {S T U V} (P : S ⇒ T) (Q : U ⇒ V) →
⟦ P [&] Q ⟧ ≃ ⟦ P ⟧ ⟦[&]⟧ ⟦ Q ⟧
[&]-semantics (inp {I} P) (inp Q) [] = refl
[&]-semantics (inp {I} P) (inp Q) (a ∷ as) = [&]-semantics (♭ P a) (inp Q) as
[&]-semantics (inp {I} P) done [] = refl
[&]-semantics (inp {I} P) done (a ∷ as) = [&]-semantics (♭ P a) done as
[&]-semantics (inp {Σ V F} P) Q [] = refl
[&]-semantics (inp {Σ V F} P) Q (a ∷ as) = [&]-semantics (♭ P a) Q as
[&]-semantics (out b P) Q as = cong (_∷_ b) ([&]-semantics P Q as)
[&]-semantics (done {I}) Q as = refl
[&]-semantics (done {Σ V F}) Q [] = refl
[&]-semantics (done {Σ V F}) Q (a ∷ as) = cong (_∷_ a) ([&]-semantics (done {♭ F a}) Q as)
[&]-semantics (inp {I} P) (out c Q) as =
begin
c ∷ ⟦ inp P [&] Q ⟧ as
≡⟨ cong (_∷_ c) ([&]-semantics (inp P) Q as) ⟩
c ∷ (⟦ inp P ⟧ ⟦[&]⟧ ⟦ Q ⟧) as
≡⟨ cong (_∷_ c) (cong₂ _++_ (I-η (⟦ inp P ⟧ (front as))) refl) ⟩
c ∷ ⟦ Q ⟧ _
≡⟨ cong₂ _++_ (sym (I-η (⟦ inp P ⟧ (front as)))) refl ⟩
(⟦ inp P ⟧ ⟦[&]⟧ ⟦ out c Q ⟧) as
∎
[&]-≃-⟦[&]⟧ : ∀ {S T U V}
{P : S ⇒ T} {f : Trace S → Trace T} {Q : U ⇒ V} {g : Trace U → Trace V} →
(⟦ P ⟧ ≃ f) → (⟦ Q ⟧ ≃ g) → (⟦ P [&] Q ⟧ ≃ f ⟦[&]⟧ g)
[&]-≃-⟦[&]⟧ {S} {T} {U} {V} {P} {f} {Q} {g} P≃f Q≃g as =
begin
⟦ P [&] Q ⟧ as
≡⟨ [&]-semantics P Q as ⟩
(⟦ P ⟧ ⟦[&]⟧ ⟦ Q ⟧) as
≡⟨ cong₂ _++_ (P≃f (front as)) (Q≃g (back {S} as)) ⟩
(f ⟦[&]⟧ g) as
∎
-- Semantics of units
⟦unit₁⟧ : ∀ {S} → (Trace (I & S)) → (Trace S)
⟦unit₁⟧ as = as
unit₁-semantics : ∀ {S} → ⟦ unit₁ {S} ⟧ ≃ ⟦unit₁⟧ {S}
unit₁-semantics {I} as = refl
unit₁-semantics {Σ V F} [] = refl
unit₁-semantics {Σ V F} (a ∷ as) = cong (_∷_ a) (unit₁-semantics as)
⟦unit₁⁻¹⟧ : ∀ {S} → (Trace (I & S)) → (Trace S)
⟦unit₁⁻¹⟧ as = as
unit₁⁻¹-semantics : ∀ {S} → ⟦ unit₁⁻¹ {S} ⟧ ≃ ⟦unit₁⁻¹⟧ {S}
unit₁⁻¹-semantics {I} as = refl
unit₁⁻¹-semantics {Σ V F} [] = refl
unit₁⁻¹-semantics {Σ V F} (a ∷ as) = cong (_∷_ a) (unit₁⁻¹-semantics as)
⟦unit₂⟧ : ∀ {S} → (Trace (S & I)) → (Trace S)
⟦unit₂⟧ = front
unit₂-semantics : ∀ {S} → ⟦ unit₂ {S} ⟧ ≃ ⟦unit₂⟧ {S}
unit₂-semantics {I} [] = refl
unit₂-semantics {Σ V F} [] = refl
unit₂-semantics {Σ V F} (a ∷ as) = cong (_∷_ a) (unit₂-semantics as)
unit₂-semantics {I} (() ∷ as)
⟦unit₂⁻¹⟧ : ∀ {S} → (Trace S) → (Trace (S & I))
⟦unit₂⁻¹⟧ as = as ++ []
unit₂⁻¹-semantics : ∀ {S} → ⟦ unit₂⁻¹ {S} ⟧ ≃ ⟦unit₂⁻¹⟧
unit₂⁻¹-semantics {I} [] = refl
unit₂⁻¹-semantics {Σ W F} [] = refl
unit₂⁻¹-semantics {Σ W F} (a ∷ as) = cong (_∷_ a) (unit₂⁻¹-semantics as)
unit₂⁻¹-semantics {I} (() ∷ as)
-- Semantics of associativity
⟦assoc⟧ : ∀ {S T U} → (Trace (S & (T & U))) → (Trace ((S & T) & U))
⟦assoc⟧ {S} {T} {U} as =
(front {S} as ++ front {T} (back {S} as)) ++ back {T} (back {S} as)
assoc-semantics : ∀ {S T U} → ⟦ assoc {S} {T} {U} ⟧ ≃ ⟦assoc⟧ {S} {T} {U}
assoc-semantics {I} {I} {I} [] = refl
assoc-semantics {I} {I} {Σ X H} [] = refl
assoc-semantics {I} {Σ W G} [] = refl
assoc-semantics {I} {I} {Σ X H} (a ∷ as) = cong (_∷_ a) (assoc-semantics {I} {I} as)
assoc-semantics {I} {Σ W G} (a ∷ as) = cong (_∷_ a) (assoc-semantics {I} {♭ G a} as)
assoc-semantics {Σ V F} [] = refl
assoc-semantics {Σ V F} (a ∷ as) = cong (_∷_ a) (assoc-semantics {♭ F a} as)
assoc-semantics {I} {I} {I} (() ∷ as)
⟦assoc⁻¹⟧ : ∀ {S T U} → (Trace ((S & T) & U)) → (Trace (S & (T & U)))
⟦assoc⁻¹⟧ {S} {T} {U} as =
front {S} (front {S & T} as) ++ back {S} (front {S & T} as) ++ back {S & T} as
assoc⁻¹-semantics : ∀ {S T U} → ⟦ assoc⁻¹ {S} {T} {U} ⟧ ≃ ⟦assoc⁻¹⟧ {S} {T} {U}
assoc⁻¹-semantics {I} {I} {I} [] = refl
assoc⁻¹-semantics {I} {I} {Σ X H} [] = refl
assoc⁻¹-semantics {I} {Σ W G} [] = refl
assoc⁻¹-semantics {I} {I} {Σ X H} (a ∷ as) = cong (_∷_ a) (assoc⁻¹-semantics {I} {I} as)
assoc⁻¹-semantics {I} {Σ W G} (a ∷ as) = cong (_∷_ a) (assoc⁻¹-semantics {I} {♭ G a} as)
assoc⁻¹-semantics {Σ V F} [] = refl
assoc⁻¹-semantics {Σ V F} (a ∷ as) = cong (_∷_ a) (assoc⁻¹-semantics {♭ F a} as)
assoc⁻¹-semantics {I} {I} {I} (() ∷ as)
-- Congruence for concatenation, where the rhs can assume the lhs has terminated
++-cong : ∀ {S T} {as₁ as₂ : Trace S} {bs₁ bs₂ : Trace T} →
(as₁ ≡ as₂) → (as₁ ✓ → bs₁ ≡ bs₂) → (as₁ ++ bs₁) ≡ (as₂ ++ bs₂)
++-cong {I} {T} {[]} refl bs₁≡bs₂ = bs₁≡bs₂ []
++-cong {Σ V F} {T} {[]} refl bs₁≡bs₂ = refl
++-cong {Σ V F} {T} {a ∷ as} refl bs₁≡bs₂ = cong (_∷_ a) (++-cong refl (λ ✓as → bs₁≡bs₂ (a ∷ ✓as)))
++-cong {I} {T} {() ∷ as} refl bs₁≡bs₂
-- Concatenation respects and reflects termination
++-resp-✓ : ∀ {S T} {as : Trace S} {bs : Trace T} → (as ✓) → (bs ✓) → (as ++ bs ✓)
++-resp-✓ [] ✓bs = ✓bs
++-resp-✓ {Σ V F} (a ∷ ✓as) ✓bs = a ∷ ++-resp-✓ ✓as ✓bs
++-resp-✓ {I} (() ∷ ✓as) ✓bs
++-refl-✓₁ : ∀ {S T} {as : Trace S} {bs : Trace T} → (as ++ bs ✓) → (as ✓)
++-refl-✓₁ {I} {T} {[]} ✓cs = []
++-refl-✓₁ {Σ V F} {T} {a ∷ as} (.a ∷ ✓cs) = a ∷ ++-refl-✓₁ ✓cs
++-refl-✓₁ {I} {T} {() ∷ as} ✓cs
++-refl-✓₁ {Σ V F} {T} {[]} ()
++-refl-✓₂ : ∀ {S T} {as : Trace S} {bs : Trace T} → (as ++ bs ✓) → (bs ✓)
++-refl-✓₂ {I} {T} {[]} ✓cs = ✓cs
++-refl-✓₂ {Σ W F} {T} {a ∷ as} (.a ∷ ✓cs) = ++-refl-✓₂ {♭ F a} {T} {as} ✓cs
++-refl-✓₂ {I} {T} {() ∷ as} cs
++-refl-✓₂ {Σ V F} {T} {[]} ()
-- Concatenaton respects emptiness
++-resp-[] : ∀ {S T} {as : Trace S} {bs : Trace T} →
(as ≡ []) → (bs ≡ []) → (as ++ bs ≡ [])
++-resp-[] {I} refl refl = refl
++-resp-[] {Σ V F} refl refl = refl
-- Beta and eta equivalence for concatenation.
-- Note that β₂ only holds when as is complete.
++-β₁ : ∀ {S T} (as : Trace S) → (bs : Trace T) → (front (as ++ bs) ≡ as)
++-β₁ {I} [] bs = refl
++-β₁ {I} (() ∷ as) bs
++-β₁ {Σ V F} [] bs = refl
++-β₁ {Σ V F} (a ∷ as) bs = cong (_∷_ a) (++-β₁ as bs)
++-β₂ : ∀ {S T} {as : Trace S} → (as ✓) → (bs : Trace T) → (back {S} (as ++ bs) ≡ bs)
++-β₂ {I} [] bs = refl
++-β₂ {Σ V F} (a ∷ as) bs = ++-β₂ as bs
++-β₂ {I} (() ∷ as) bs
++-η : ∀ {S T} (as : Trace (S & T)) → (front {S} as ++ back {S} as ≡ as)
++-η {I} [] = refl
++-η {I} (a ∷ as) = refl
++-η {Σ V F} [] = refl
++-η {Σ V F} (a ∷ as) = cong (_∷_ a) (++-η {♭ F a} as)
-- Beta for concatenation with an incomplete trace
++-β₂-[] : ∀ {S T} {as : Trace S} → (¬ (as ✓)) → (bs : Trace T) → (back {S} (as ++ bs) ≡ [])
++-β₂-[] {I} {T} {[]} ¬✓[] bs = ⊥-elim (¬✓[] [])
++-β₂-[] {Σ V F} {T} {[]} ¬✓[] bs = refl
++-β₂-[] {Σ V F} {T} {a ∷ as} ¬✓a∷as bs = ++-β₂-[] (λ ✓as → ¬✓a∷as (a ∷ ✓as)) bs
++-β₂-[] {I} {T} {() ∷ as} ¬✓a∷as bs
-- If the front of a trace is incomplete then its back is empty
back≡[] : ∀ {S T as} → (¬ (front {S} {T} as ✓)) → (back {S} {T} as ≡ [])
back≡[] {I} {T} {as} ¬✓as₁ = ⊥-elim (¬✓as₁ [])
back≡[] {Σ V F} {T} {[]} ¬✓as₁ = refl
back≡[] {Σ V F} {T} {a ∷ as} ¬✓a∷as₁ = back≡[] (λ ✓as₁ → ¬✓a∷as₁ (a ∷ ✓as₁))
-- Front respects completion, but only reflects it when T = I.
front-resp-✓ : ∀ {S T} {as : Trace (S & T)} → (as ✓) → (front {S} as ✓)
front-resp-✓ {I} ✓as = []
front-resp-✓ {Σ V F} (a ∷ ✓as) = a ∷ front-resp-✓ ✓as
front-refl-✓ : ∀ {S} (as : Trace (S & I)) → (front {S} as ✓) → (as ✓)
front-refl-✓ {I} [] ✓as₁ = []
front-refl-✓ {Σ V F} (a ∷ as) (.a ∷ ✓as₁) = a ∷ front-refl-✓ as ✓as₁
front-refl-✓ {I} (() ∷ as) ✓as₁
front-refl-✓ {Σ V F} [] ()
-- Back respects emptiness
back-resp-[] : ∀ {S T as} → (as ≡ []) → (back {S} {T} as ≡ [])
back-resp-[] {I} refl = refl
back-resp-[] {Σ V F} refl = refl
-- Back reflects completion for non-trivial T
back-refl-✓ : ∀ {S T} {isΣ : IsΣ T} (as : Trace (S & T)) → (back {S} as ✓) → (as ✓)
back-refl-✓ {I} as ✓as₂ = ✓as₂
back-refl-✓ {Σ V F} {Σ W G} (a ∷ as) ✓as₂ = a ∷ back-refl-✓ {♭ F a} as ✓as₂
back-refl-✓ {Σ V F} {I} {} as ✓as₂
back-refl-✓ {Σ V F} {Σ W G} [] ()
-- Back respects completion
back-resp-✓ : ∀ {S} {T} {as : Trace (S & T)} → (as ✓) → (back {S} as ✓)
back-resp-✓ {I} ✓as = ✓as
back-resp-✓ {Σ W F} (a ∷ ✓as) = back-resp-✓ {♭ F a} ✓as
-- Tensor plays nicely with concatenation when f reflects completion
⟦[&]⟧-++ : ∀ {S T U V} (f : Trace S → Trace T) (g : Trace U → Trace V) →
(∀ cs → (f cs ✓) → (cs ✓)) → ∀ as bs →
(f ⟦[&]⟧ g) (as ++ bs) ≡ (f as ++ g bs)
⟦[&]⟧-++ {S} {T} {U} {V} f g f-refl-✓ as bs =
begin
f (front {S} (as ++ bs)) ++ g (back {S} (as ++ bs))
≡⟨ cong₂ _++_ (cong f (++-β₁ as bs)) refl ⟩
f as ++ g (back {S} (as ++ bs))
≡⟨ ++-cong refl (λ ✓fas → cong g (++-β₂ (f-refl-✓ as ✓fas) bs)) ⟩
f as ++ g bs
∎
-- Tensor respects ≃
[&]-resp-≃ : ∀ {S T U V} {P₁ P₂ : S ⇒ T} {Q₁ Q₂ : U ⇒ V} →
(⟦ P₁ ⟧ ≃ ⟦ P₂ ⟧) → (⟦ Q₁ ⟧ ≃ ⟦ Q₂ ⟧) →
(⟦ P₁ [&] Q₁ ⟧ ≃ ⟦ P₂ [&] Q₂ ⟧)
[&]-resp-≃ {S} {T} {U} {V} {P₁} {P₂} {Q₁} {Q₂} P₁≃P₂ Q₁≃Q₂ as =
begin
⟦ P₁ [&] Q₁ ⟧ as
≡⟨ [&]-≃-⟦[&]⟧ P₁≃P₂ Q₁≃Q₂ as ⟩
(⟦ P₂ ⟧ ⟦[&]⟧ ⟦ Q₂ ⟧) as
≡⟨ sym ([&]-semantics P₂ Q₂ as) ⟩
⟦ P₂ [&] Q₂ ⟧ as
∎
-- Tensor respects identity
[&]-resp-done : ∀ S T → ⟦ done {S} [&] done {T} ⟧ ≃ ⟦ done {S & T} ⟧
[&]-resp-done S T as =
begin
⟦ done {S} [&] done {T} ⟧ as
≡⟨ [&]-semantics (done {S}) (done {T}) as ⟩
front {S} as ++ back {S} as
≡⟨ ++-η {S} as ⟩
as
∎
-- Tensor respects composition when g₁ reflects completion
⟦[&]⟧-resp-⟦⟫⟧ : ∀ {S₁ S₂ T₁ T₂ U₁ U₂} →
(f₁ : Trace S₁ → Trace T₁) → (g₁ : Trace T₁ → Trace U₁) →
(f₂ : Trace S₂ → Trace T₂) → (g₂ : Trace T₂ → Trace U₂) →
(∀ as → (g₁ as ✓) → (as ✓)) →
(((f₁ ⟦⟫⟧ g₁) ⟦[&]⟧ (f₂ ⟦⟫⟧ g₂)) ≃ (f₁ ⟦[&]⟧ f₂) ⟦⟫⟧ (g₁ ⟦[&]⟧ g₂))
⟦[&]⟧-resp-⟦⟫⟧ {S₁} f₁ g₁ f₂ g₂ g₁-refl-✓ as =
sym (⟦[&]⟧-++ g₁ g₂ g₁-refl-✓ (f₁ (front {S₁} as)) (f₂ (back {S₁} as)))
-- Tensor respects composition when f₁ respects completion and f₂ is strict
⟦[&]⟧-resp-⟦⟫⟧' : ∀ {S₁ S₂ T₁ T₂ U₁ U₂} →
(f₁ : Trace S₁ → Trace T₁) → (g₁ : Trace T₁ → Trace U₁) →
(f₂ : Trace S₂ → Trace T₂) → (g₂ : Trace T₂ → Trace U₂) →
(∀ as → as ✓ → f₁ as ✓) → (f₂ [] ≡ []) →
(((f₁ ⟦⟫⟧ g₁) ⟦[&]⟧ (f₂ ⟦⟫⟧ g₂)) ≃ (f₁ ⟦[&]⟧ f₂) ⟦⟫⟧ (g₁ ⟦[&]⟧ g₂))
⟦[&]⟧-resp-⟦⟫⟧' {S₁} {S₂} {T₁} {T₂} f₁ g₁ f₂ g₂ f₁-resp-✓ f₂[]≡[] as with ✓? (f₁ (front as))
⟦[&]⟧-resp-⟦⟫⟧' {S₁} {S₂} {T₁} {T₂} f₁ g₁ f₂ g₂ f₁-resp-✓ f₂[]≡[] as | yes ✓bs₁ =
cong₂ _++_ (cong g₁ (sym (++-β₁ _ _))) (cong g₂ (sym (++-β₂ ✓bs₁ _)))
⟦[&]⟧-resp-⟦⟫⟧' {S₁} {S₂} {T₁} {T₂} f₁ g₁ f₂ g₂ f₁-resp-✓ f₂[]≡[] as | no ¬✓bs₁ =
begin
g₁ (f₁ as₁) ++ g₂ (f₂ as₂)
≡⟨ cong (_++_ (g₁ (f₁ as₁))) (cong g₂ (cong f₂ (back≡[] ¬✓as₁))) ⟩
g₁ (f₁ as₁) ++ g₂ (f₂ [])
≡⟨ cong (_++_ (g₁ (f₁ as₁))) (cong g₂ f₂[]≡[]) ⟩
g₁ (f₁ as₁) ++ g₂ []
≡⟨ cong₂ _++_ (cong g₁ (sym (++-β₁ _ _))) (cong g₂ (sym (++-β₂-[] ¬✓bs₁ _))) ⟩
g₁ (front (f₁ as₁ ++ f₂ as₂)) ++ g₂ (back {T₁} (f₁ as₁ ++ f₂ as₂))
∎ where
as₁ = front {S₁} as
as₂ = back {S₁} as
¬✓as₁ : ¬ as₁ ✓
¬✓as₁ = λ as₁✓ → ¬✓bs₁ (f₁-resp-✓ as₁ as₁✓)
-- Tensor respects composition when Q₁ is reflective
[&]-resp-⟫ : ∀ {S₁ S₂ T₁ T₂ U₁ U₂}
(P₁ : S₁ ⇒ T₁) {Q₁ : T₁ ⇒ U₁} (⟳Q₁ : Reflective Q₁)
(P₂ : S₂ ⇒ T₂) (Q₂ : T₂ ⇒ U₂) →
⟦ (P₁ ⟫ Q₁) [&] (P₂ ⟫ Q₂) ⟧ ≃ ⟦ (P₁ [&] P₂) ⟫ (Q₁ [&] Q₂) ⟧
[&]-resp-⟫ P₁ {Q₁} ⟳Q₁ P₂ Q₂ as =
begin
⟦ (P₁ ⟫ Q₁) [&] (P₂ ⟫ Q₂) ⟧ as
≡⟨ [&]-≃-⟦[&]⟧ (⟫-semantics P₁ Q₁) (⟫-semantics P₂ Q₂) as ⟩
((⟦ P₁ ⟧ ⟦⟫⟧ ⟦ Q₁ ⟧) ⟦[&]⟧ (⟦ P₂ ⟧ ⟦⟫⟧ ⟦ Q₂ ⟧)) as
≡⟨ ⟦[&]⟧-resp-⟦⟫⟧ ⟦ P₁ ⟧ ⟦ Q₁ ⟧ ⟦ P₂ ⟧ ⟦ Q₂ ⟧ (⟦⟧-refl-✓ ⟳Q₁) as ⟩
((⟦ P₁ ⟧ ⟦[&]⟧ ⟦ P₂ ⟧) ⟦⟫⟧ (⟦ Q₁ ⟧ ⟦[&]⟧ ⟦ Q₂ ⟧)) as
≡⟨ sym (⟫-≃-⟦⟫⟧ ([&]-semantics P₁ P₂) ([&]-semantics Q₁ Q₂) as) ⟩
⟦ P₁ [&] P₂ ⟫ Q₁ [&] Q₂ ⟧ as
∎
-- Tensor respects composition when P₂ is strict
[&]-resp-⟫' : ∀ {S₁ S₂ T₁ T₂ U₁ U₂}
(P₁ : S₁ ⇒ T₁) (Q₁ : T₁ ⇒ U₁)
{P₂ : S₂ ⇒ T₂} (#P₂ : Strict P₂) (Q₂ : T₂ ⇒ U₂) →
⟦ (P₁ ⟫ Q₁) [&] (P₂ ⟫ Q₂) ⟧ ≃ ⟦ (P₁ [&] P₂) ⟫ (Q₁ [&] Q₂) ⟧
[&]-resp-⟫' P₁ Q₁ {P₂} #P₂ Q₂ as =
begin
⟦ (P₁ ⟫ Q₁) [&] (P₂ ⟫ Q₂) ⟧ as
≡⟨ [&]-≃-⟦[&]⟧ (⟫-semantics P₁ Q₁) (⟫-semantics P₂ Q₂) as ⟩
((⟦ P₁ ⟧ ⟦⟫⟧ ⟦ Q₁ ⟧) ⟦[&]⟧ (⟦ P₂ ⟧ ⟦⟫⟧ ⟦ Q₂ ⟧)) as
≡⟨ ⟦[&]⟧-resp-⟦⟫⟧' ⟦ P₁ ⟧ ⟦ Q₁ ⟧ ⟦ P₂ ⟧ ⟦ Q₂ ⟧ (⟦⟧-resp-✓ P₁) (⟦⟧-resp-[] #P₂) as ⟩
((⟦ P₁ ⟧ ⟦[&]⟧ ⟦ P₂ ⟧) ⟦⟫⟧ (⟦ Q₁ ⟧ ⟦[&]⟧ ⟦ Q₂ ⟧)) as
≡⟨ sym (⟫-≃-⟦⟫⟧ ([&]-semantics P₁ P₂) ([&]-semantics Q₁ Q₂) as) ⟩
⟦ P₁ [&] P₂ ⟫ Q₁ [&] Q₂ ⟧ as
∎
-- Units and associator are equivalences
unit₁-isEquiv : ∀ {S} → IsEquiv (unit₁ {S})
unit₁-isEquiv = isEquiv ∼-unit₁ ≃-refl
unit₂-isEquiv : ∀ {S} → IsEquiv (unit₂ {S})
unit₂-isEquiv {S} = isEquiv (∼-unit₂ {S}) ≃-refl
assoc-isEquiv : ∀ {S T U} → IsEquiv (assoc {S} {T} {U})
assoc-isEquiv {S} {T} = isEquiv (∼-assoc {S} {T}) ≃-refl
unit₁⁻¹-isEquiv : ∀ {S} → IsEquiv (unit₁⁻¹ {S})
unit₁⁻¹-isEquiv = isEquiv (∼-sym ∼-unit₁) ≃-refl
unit₂⁻¹-isEquiv : ∀ {S} → IsEquiv (unit₂⁻¹ {S})
unit₂⁻¹-isEquiv = isEquiv (∼-sym ∼-unit₂) ≃-refl
assoc⁻¹-isEquiv : ∀ {S T U} → IsEquiv (assoc⁻¹ {S} {T} {U})
assoc⁻¹-isEquiv {S} = isEquiv (∼-sym (∼-assoc {S})) ≃-refl
-- Equivalence respects &
&-resp-∼ : ∀ {S T U V} → (S ∼ T) → (U ∼ V) → ((S & U) ∼ (T & V))
&-resp-∼ I U∼V = U∼V
&-resp-∼ (Σ V F) U∼V = Σ V (♯ λ a → &-resp-∼ (♭ F a) U∼V)
equiv-resp-⟦[&]⟧ : ∀ {S T U V} (S∼T : S ∼ T) (U∼V : U ∼ V) →
⟦ equiv S∼T ⟧ ⟦[&]⟧ ⟦ equiv U∼V ⟧ ≃ ⟦ equiv (&-resp-∼ S∼T U∼V) ⟧
equiv-resp-⟦[&]⟧ I U∼V as = refl
equiv-resp-⟦[&]⟧ (Σ V F) U∼V [] = refl
equiv-resp-⟦[&]⟧ (Σ V F) U∼V (a ∷ as) = cong (_∷_ a) (equiv-resp-⟦[&]⟧ (♭ F a) U∼V as)
equiv-resp-[&] : ∀ {S T U V} (S∼T : S ∼ T) (U∼V : U ∼ V) →
⟦ equiv S∼T [&] equiv U∼V ⟧ ≃ ⟦ equiv (&-resp-∼ S∼T U∼V) ⟧
equiv-resp-[&] S∼T U∼V as =
begin
⟦ equiv S∼T [&] equiv U∼V ⟧ as
≡⟨ [&]-semantics (equiv S∼T) (equiv U∼V) as ⟩
(⟦ equiv S∼T ⟧ ⟦[&]⟧ ⟦ equiv U∼V ⟧) as
≡⟨ equiv-resp-⟦[&]⟧ S∼T U∼V as ⟩
⟦ equiv (&-resp-∼ S∼T U∼V) ⟧ as
∎
[&]-isEquiv : ∀ {S T U V} {P : S ⇒ T} {Q : U ⇒ V} →
(IsEquiv P) → (IsEquiv Q) → (IsEquiv (P [&] Q))
[&]-isEquiv {S} {T} {U} {V} {P} {Q} (isEquiv S∼T P≃S∼T) (isEquiv U∼V Q≃U∼V) =
isEquiv (&-resp-∼ S∼T U∼V) λ as →
begin
⟦ P [&] Q ⟧ as
≡⟨ [&]-resp-≃ P≃S∼T Q≃U∼V as ⟩
⟦ equiv S∼T [&] equiv U∼V ⟧ as
≡⟨ equiv-resp-[&] S∼T U∼V as ⟩
⟦ equiv (&-resp-∼ S∼T U∼V) ⟧ as
∎
-- Isomorphisms
unit₁-iso : ∀ {S} → ⟦ unit₁ {S} ⟫ unit₁⁻¹ {S} ⟧ ≃ ⟦ done ⟧
unit₁-iso = equiv-is-iso unit₁-isEquiv unit₁⁻¹-isEquiv
unit₁⁻¹-iso : ∀ {S} → ⟦ unit₁⁻¹ {S} ⟫ unit₁ {S} ⟧ ≃ ⟦ done ⟧
unit₁⁻¹-iso = equiv-is-iso unit₁⁻¹-isEquiv unit₁-isEquiv
unit₂-iso : ∀ {S} → ⟦ unit₂ {S} ⟫ unit₂⁻¹ {S} ⟧ ≃ ⟦ done ⟧
unit₂-iso {S} = equiv-is-iso (unit₂-isEquiv {S}) unit₂⁻¹-isEquiv
unit₂⁻¹-iso : ∀ {S} → ⟦ unit₂⁻¹ {S} ⟫ unit₂ {S} ⟧ ≃ ⟦ done ⟧
unit₂⁻¹-iso {S} = equiv-is-iso unit₂⁻¹-isEquiv (unit₂-isEquiv {S})
assoc-iso : ∀ {S T U} → ⟦ assoc {S} {T} {U} ⟫ assoc⁻¹ {S} {T} {U} ⟧ ≃ ⟦ done ⟧
assoc-iso {S} {T} = equiv-is-iso (assoc-isEquiv {S} {T}) (assoc⁻¹-isEquiv {S} {T})
assoc⁻¹-iso : ∀ {S T U} → ⟦ assoc⁻¹ {S} {T} {U} ⟫ assoc {S} {T} {U} ⟧ ≃ ⟦ done ⟧
assoc⁻¹-iso {S} {T} = equiv-is-iso (assoc⁻¹-isEquiv {S} {T}) (assoc-isEquiv {S} {T})
-- Coherence conditions
assoc-unit : ∀ {S T} →
⟦ done {S} [&] unit₁ {T} ⟧ ≃ ⟦ assoc {S} {I} {T} ⟫ unit₂ {S} [&] done {T} ⟧
assoc-unit {S} {T} =
≃-equiv ([&]-isEquiv (done-isEquiv {S}) (unit₁-isEquiv {T}))
(⟫-isEquiv (assoc-isEquiv {S} {I} {T}) ([&]-isEquiv (unit₂-isEquiv {S}) (done-isEquiv {T})))
assoc-assoc : ∀ {S T U V} →
⟦ done {S} [&] assoc {T} {U} {V} ⟫
assoc {S} {T & U} {V} ⟫
assoc {S} {T} {U} [&] done {V} ⟧ ≃
⟦ assoc {S} {T} {U & V} ⟫ assoc {S & T} {U} {V} ⟧
assoc-assoc {S} {T} {U} {V} =
≃-equiv
(⟫-isEquiv ([&]-isEquiv (done-isEquiv {S}) (assoc-isEquiv {T} {U} {V}))
(⟫-isEquiv (assoc-isEquiv {S} {T & U} {V})
([&]-isEquiv (assoc-isEquiv {S} {T} {U}) done-isEquiv)))
(⟫-isEquiv (assoc-isEquiv {S} {T} {U & V}) (assoc-isEquiv {S & T} {U} {V}))
-- Concatenation plays nicely with associativity
⟦assoc⟧-++ : ∀ {S T U} → (as : Trace S) (bs : Trace T) (cs : Trace U) →
⟦assoc⟧ {S} (as ++ (bs ++ cs)) ≡ ((as ++ bs) ++ cs)
⟦assoc⟧-++ {I} {I} [] bs cs = refl
⟦assoc⟧-++ {I} {Σ W G} [] [] cs = refl
⟦assoc⟧-++ {I} {Σ W G} [] (b ∷ bs) cs = cong (_∷_ b) (⟦assoc⟧-++ {I} [] bs cs)
⟦assoc⟧-++ {Σ W F} [] bs cs = refl
⟦assoc⟧-++ {Σ W F} (a ∷ as) bs cs = cong (_∷_ a) (⟦assoc⟧-++ as bs cs)
⟦assoc⟧-++ {I} (() ∷ as) bs cs
⟦assoc⁻¹⟧-++ : ∀ {S T U} → (as : Trace S) (bs : Trace T) (cs : Trace U) →
⟦assoc⁻¹⟧ {S} ((as ++ bs) ++ cs) ≡ (as ++ (bs ++ cs))
⟦assoc⁻¹⟧-++ {I} {I} [] bs cs = refl
⟦assoc⁻¹⟧-++ {I} {Σ W G} [] [] cs = refl
⟦assoc⁻¹⟧-++ {I} {Σ W G} [] (b ∷ bs) cs = cong (_∷_ b) (⟦assoc⁻¹⟧-++ {I} [] bs cs)
⟦assoc⁻¹⟧-++ {Σ W F} [] bs cs = refl
⟦assoc⁻¹⟧-++ {Σ W F} (a ∷ as) bs cs = cong (_∷_ a) (⟦assoc⁻¹⟧-++ as bs cs)
⟦assoc⁻¹⟧-++ {I} (() ∷ as) bs cs
-- Front and back play well with associativity
front-⟦assoc⟧ : ∀ {S T U} (as : Trace (S & (T & U))) →
(front {S} as ≡ front {S} (front {S & T} (⟦assoc⟧ {S} as)))
front-⟦assoc⟧ {I} as = refl
front-⟦assoc⟧ {Σ V F} [] = refl
front-⟦assoc⟧ {Σ V F} (a ∷ as) = cong (_∷_ a) (front-⟦assoc⟧ as)
mid-⟦assoc⟧ : ∀ {S T U} (as : Trace (S & (T & U))) →
(front {T} (back {S} as) ≡ back {S} (front {S & T} (⟦assoc⟧ {S} as)))
mid-⟦assoc⟧ {I} {T} as = cong (front {T}) (sym (++-η {T} as))
mid-⟦assoc⟧ {Σ V F} {I} [] = refl
mid-⟦assoc⟧ {Σ V F} {Σ W G} [] = refl
mid-⟦assoc⟧ {Σ V F} (a ∷ as) = mid-⟦assoc⟧ {♭ F a} as
back-⟦assoc⟧ : ∀ {S T U} (as : Trace (S & (T & U))) →
(back {T} (back {S} as) ≡ back {S & T} (⟦assoc⟧ {S} as))
back-⟦assoc⟧ {I} {T} as = cong (back {T}) (sym (++-η {T} as))
back-⟦assoc⟧ {Σ V F} {I} [] = refl
back-⟦assoc⟧ {Σ V F} {Σ W G} [] = refl
back-⟦assoc⟧ {Σ V F} (a ∷ as) = back-⟦assoc⟧ {♭ F a} as
-- Units are natural
⟦unit₁⟧-natural : ∀ {S T} (f : Trace S → Trace T) →
(⟦done⟧ {I} ⟦[&]⟧ f) ⟦⟫⟧ ⟦unit₁⟧ ≃ ⟦unit₁⟧ ⟦⟫⟧ f
⟦unit₁⟧-natural f [] = refl
⟦unit₁⟧-natural f (a ∷ as) = refl
unit₁-natural : ∀ {S T} (P : S ⇒ T) →
⟦ done {I} [&] P ⟫ unit₁ ⟧ ≃ ⟦ unit₁ ⟫ P ⟧
unit₁-natural P as =
begin
⟦ done {I} [&] P ⟫ unit₁ ⟧ as
≡⟨ ⟫-≃-⟦⟫⟧ ([&]-semantics (done {I}) P) unit₁-semantics as ⟩
(⟦done⟧ {I} ⟦[&]⟧ ⟦ P ⟧ ⟦⟫⟧ ⟦unit₁⟧) as
≡⟨ ⟦unit₁⟧-natural ⟦ P ⟧ as ⟩
(⟦unit₁⟧ ⟦⟫⟧ ⟦ P ⟧) as
≡⟨ sym (⟫-≃-⟦⟫⟧ unit₁-semantics ≃-refl as) ⟩
⟦ unit₁ ⟫ P ⟧ as
∎
⟦unit₂⟧-natural : ∀ {S T} (f : Trace S → Trace T) →
(f ⟦[&]⟧ ⟦done⟧ {I}) ⟦⟫⟧ ⟦unit₂⟧ ≃ ⟦unit₂⟧ ⟦⟫⟧ f
⟦unit₂⟧-natural {S} {T} f as =
++-β₁ (f (front {S} as)) (back {S} as)
unit₂-natural : ∀ {S T} (P : S ⇒ T) →
⟦ P [&] done {I} ⟫ unit₂ ⟧ ≃ ⟦ unit₂ ⟫ P ⟧
unit₂-natural {S} {T} P as =
begin
⟦ P [&] done {I} ⟫ unit₂ ⟧ as
≡⟨ ⟫-≃-⟦⟫⟧ ([&]-semantics P (done {I})) (unit₂-semantics {T}) as ⟩
(⟦ P ⟧ ⟦[&]⟧ ⟦done⟧ {I} ⟦⟫⟧ ⟦unit₂⟧) as
≡⟨ ⟦unit₂⟧-natural ⟦ P ⟧ as ⟩
(⟦unit₂⟧ ⟦⟫⟧ ⟦ P ⟧) as
≡⟨ sym (⟫-≃-⟦⟫⟧ (unit₂-semantics {S}) ≃-refl as) ⟩
⟦ unit₂ ⟫ P ⟧ as
∎
-- Associativity is natural
⟦assoc⟧-natural : ∀ {S S' T T' U U'}
(f : Trace S → Trace S') (g : Trace T → Trace T') (h : Trace U → Trace U') →
((f ⟦[&]⟧ (g ⟦[&]⟧ h)) ⟦⟫⟧ ⟦assoc⟧ {S'} {T'} {U'}) ≃
(⟦assoc⟧ {S} {T} {U} ⟦⟫⟧ ((f ⟦[&]⟧ g) ⟦[&]⟧ h))
⟦assoc⟧-natural {S} {S'} {T} {T'} {U} {U'} f g h as =
begin
⟦assoc⟧ {S'} (f as₁ ++ g as₂ ++ h as₃)
≡⟨ ⟦assoc⟧-++ (f as₁) (g as₂) (h as₃) ⟩
(f as₁ ++ g as₂) ++ h as₃
≡⟨ cong₂ _++_ (cong₂ _++_ (cong f (front-⟦assoc⟧ as))
(cong g (mid-⟦assoc⟧ {S} as))) (cong h (back-⟦assoc⟧ {S} as)) ⟩
((f ⟦[&]⟧ g) ⟦[&]⟧ h) ((as₁ ++ as₂) ++ as₃)
∎ where
as₁ = front {S} as
as₂ = front {T} (back {S} as)
as₃ = back {T} (back {S} as)
assoc-natural : ∀ {S S' T T' U U'} (P : S ⇒ S') (Q : T ⇒ T') (R : U ⇒ U') →
⟦ P [&] (Q [&] R) ⟫ assoc {S'} {T'} {U'} ⟧ ≃
⟦ assoc {S} {T} {U} ⟫ (P [&] Q) [&] R ⟧
assoc-natural {S} {S'} {T} {T'} {U} {U'} P Q R as =
begin
⟦ P [&] (Q [&] R) ⟫ assoc {S'} {T'} {U'} ⟧ as
≡⟨ ⟫-≃-⟦⟫⟧ ([&]-≃-⟦[&]⟧ {P = P} ≃-refl ([&]-semantics Q R)) (assoc-semantics {S'} {T'} {U'}) as ⟩
((⟦ P ⟧ ⟦[&]⟧ (⟦ Q ⟧ ⟦[&]⟧ ⟦ R ⟧)) ⟦⟫⟧ ⟦assoc⟧ {S'} {T'} {U'}) as
≡⟨ ⟦assoc⟧-natural ⟦ P ⟧ ⟦ Q ⟧ ⟦ R ⟧ as ⟩
(⟦assoc⟧ {S} {T} {U} ⟦⟫⟧ ((⟦ P ⟧ ⟦[&]⟧ ⟦ Q ⟧) ⟦[&]⟧ ⟦ R ⟧)) as
≡⟨ sym (⟫-≃-⟦⟫⟧ (assoc-semantics {S} {T} {U}) ([&]-≃-⟦[&]⟧ ([&]-semantics P Q) ≃-refl) as) ⟩
⟦ assoc {S} {T} {U} ⟫ (P [&] Q) [&] R ⟧ as
∎
| {
"alphanum_fraction": 0.4445519729,
"avg_line_length": 39.5356521739,
"ext": "agda",
"hexsha": "eb831d291e99571663a86fd5d3376878ecedfbd4",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/Properties/Monoidal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/Properties/Monoidal.agda",
"max_line_length": 120,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/Properties/Monoidal.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 12011,
"size": 22733
} |
open import Proc
module Silence (param : Param) where
open import Basics
import Interp
import Hear
open Process param
open Interp param
open Hear param
NoSpeak : {a : U} -> Proc a -> Set
NoSpeak {a} p = (w : LT a)(q : Proc a) -> ¬ (p -! w !-> q)
silent-nospeak : {a : U}{p : Proc a} -> Silent p -> NoSpeak p
silent-nospeak silent-o w q ()
silent-nospeak silent-> w q ()
silent-nospeak (silent-|| s1 s2) w ._ (tx-!| h _) = silent-nospeak s1 _ _ h
silent-nospeak (silent-|| s1 s2) w ._ (tx-|! _ h) = silent-nospeak s2 _ _ h
silent-nospeak (silent-def s) w q (tx-def h) = silent-nospeak s _ _ h
silent-nospeak (silent-/| s) ._ ._ (tx-/| h) = silent-nospeak s _ _ h
nospeak-silent : {a : U}{p : Proc a} -> Guard p -> NoSpeak p -> Silent p
nospeak-silent og s = silent-o
nospeak-silent (>g f) s = silent->
nospeak-silent (w !g p) s = kill (s _ _ tx-!)
nospeak-silent (w ! p +g f) s = kill (s _ _ tx-+)
nospeak-silent (g1 ||g g2) s =
silent-|| (nospeak-silent g1 (inv1 g2 s))
(nospeak-silent g2 (inv2 g1 s))
where
module Inv {a : U}{p1 p2 : Proc a} where
inv1 : Guard p2 -> NoSpeak (p1 || p2) -> NoSpeak p1
inv1 g2 h w p t = h _ _ (tx-!| t (sound g2))
inv2 : Guard p1 -> NoSpeak (p1 || p2) -> NoSpeak p2
inv2 g1 h w p t = h _ _ (tx-|! (sound g1) t)
open Inv
nospeak-silent (φ /|g g) s = silent-/| (nospeak-silent g (inv s))
where
inv : forall {p} -> NoSpeak (φ /| p) -> NoSpeak p
inv h w p t = h _ _ (tx-/| t)
nospeak-silent (defg x g) s = silent-def (nospeak-silent g (inv s))
where
inv : NoSpeak (def x) -> NoSpeak (env _ x)
inv h w p t = h _ _ (tx-def t)
| {
"alphanum_fraction": 0.5667060213,
"avg_line_length": 34.5714285714,
"ext": "agda",
"hexsha": "ee8a8559debc022d8945185622168e70025fab30",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/cbs/Silence.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/cbs/Silence.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/cbs/Silence.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 646,
"size": 1694
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
module HoTT.Equivalence.Transport where
open variables
transport-equiv : {x y : A} → x == y → P x ≃ P y
transport-equiv {A = A} {P = P} p = f , qinv→isequiv (g , η p , ε p)
where
f = transport P p
g = transport P (p ⁻¹)
variable x y : A
η : (p : x == y) → transport P (p ⁻¹) ∘ transport P p ~ id
η refl _ = refl
ε : (p : x == y) → transport P p ∘ transport P (p ⁻¹) ~ id
ε refl _ = refl
| {
"alphanum_fraction": 0.5855670103,
"avg_line_length": 25.5263157895,
"ext": "agda",
"hexsha": "7c3d5322f30dbf8cd7bf09a3dfb973cec3c1765a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Equivalence/Transport.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Equivalence/Transport.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Equivalence/Transport.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 182,
"size": 485
} |
module Data where
import Lvl
open import Type
-- An empty type which cannot be constructed.
-- By default, this should be used to represent _the_ empty type.
data Empty {ℓ} : Type{ℓ} where
{-# FOREIGN GHC data Empty ℓ #-}
{-# COMPILE GHC Empty = data Empty () #-}
-- Empty functions.
-- The empty type eliminator.
-- Any type can be constructed from the empty type.
empty : ∀{ℓ₁ ℓ₂}{T : Type{ℓ₁}} → Empty{ℓ₂} → T
empty ()
{-# COMPILE GHC empty = \_ _ _ e -> case e of{} #-}
-- An unit type which can only be constructed in one way.
-- By default, this should be used to represent _the_ unit type.
record Unit {ℓ} : Type{ℓ} where
instance constructor <>
open Unit public
{-# BUILTIN UNIT Unit #-}
{-# FOREIGN GHC type Unit ℓ = () #-}
{-# COMPILE GHC Unit = data Unit (()) #-}
| {
"alphanum_fraction": 0.6594663278,
"avg_line_length": 28.1071428571,
"ext": "agda",
"hexsha": "214383e4dc3e8ebaab0603f364448129eda726ae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data.agda",
"max_line_length": 65,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 218,
"size": 787
} |
{-# OPTIONS --cubical --safe #-}
module Data.Maybe.Base where
open import Level
data Maybe (A : Type a) : Type a where
nothing : Maybe A
just : A → Maybe A
maybe : {B : Maybe A → Type b} → B nothing → ((x : A) → B (just x)) → (x : Maybe A) → B x
maybe b f nothing = b
maybe b f (just x) = f x
| {
"alphanum_fraction": 0.5880398671,
"avg_line_length": 21.5,
"ext": "agda",
"hexsha": "6fc33d91c2220c3b4fdb3968c7a258f5f5b429a7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Maybe/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Maybe/Base.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Maybe/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 101,
"size": 301
} |
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Homomorphism.Definitions (Σ : Signature) where
open import Fragment.Algebra.Algebra Σ
open import Level using (Level; _⊔_)
open import Relation.Binary using (Setoid)
open import Data.Vec using (Vec; map)
open import Function using (Congruent) public
private
variable
a b ℓ₁ ℓ₂ : Level
Homomorphic : (S : Algebra {a} {ℓ₁}) (T : Algebra {b} {ℓ₂})
→ (∥ S ∥ → ∥ T ∥) → Set (a ⊔ ℓ₂)
Homomorphic S T h = ∀ {arity} → (f : ops Σ arity)
→ (xs : Vec ∥ S ∥ arity)
→ T ⟦ f ⟧ (map h xs) =[ T ] h (S ⟦ f ⟧ xs)
| {
"alphanum_fraction": 0.5985185185,
"avg_line_length": 28.125,
"ext": "agda",
"hexsha": "997d7cfac7c8f6d48d17b92c199264e01357e9c6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Algebra/Homomorphism/Definitions.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Algebra/Homomorphism/Definitions.agda",
"max_line_length": 70,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Algebra/Homomorphism/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 217,
"size": 675
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Helper where
open import Level
open import Relation.Binary using (Rel; IsEquivalence)
open import Categories.Category.Core using (Category)
-- Since we add extra proofs in the definition of `Category` (i.e. `sym-assoc` and
-- `identity²`), we might still want to construct a `Category` in its originally
-- easier manner. Thus, this redundant definition is here to ease the construction.
record CategoryHelper (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
infix 4 _≈_ _⇒_
infixr 9 _∘_
field
Obj : Set o
_⇒_ : Rel Obj ℓ
_≈_ : ∀ {A B} → Rel (A ⇒ B) e
id : ∀ {A} → (A ⇒ A)
_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)
field
assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → (h ∘ g) ∘ f ≈ h ∘ (g ∘ f)
identityˡ : ∀ {A B} {f : A ⇒ B} → id ∘ f ≈ f
identityʳ : ∀ {A B} {f : A ⇒ B} → f ∘ id ≈ f
equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
∘-resp-≈ : ∀ {A B C} {f h : B ⇒ C} {g i : A ⇒ B} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i
categoryHelper : ∀ {o ℓ e} → CategoryHelper o ℓ e → Category o ℓ e
categoryHelper C = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; assoc = assoc
; sym-assoc = sym assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identityˡ
; equiv = equiv
; ∘-resp-≈ = ∘-resp-≈
}
where open CategoryHelper C
module _ {A B} where
open IsEquivalence (equiv {A} {B}) public
| {
"alphanum_fraction": 0.5342913129,
"avg_line_length": 31.2448979592,
"ext": "agda",
"hexsha": "4cef9e39f6ce2c5af0f90b394ee96b3a14c3478d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Helper.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Helper.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Helper.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 606,
"size": 1531
} |
{-# OPTIONS --warning=error #-}
module Issue329 where
mutual
infixl 0 D Undeclared
data D : Set where
| {
"alphanum_fraction": 0.7009345794,
"avg_line_length": 15.2857142857,
"ext": "agda",
"hexsha": "48948c488f609473fc936dccf0b90db95a75f7fb",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue329.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue329.agda",
"max_line_length": 31,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue329.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 32,
"size": 107
} |
module PLRTree {A : Set} where
open import BTree {A} hiding (flatten)
open import Data.List
data Tag : Set where
perfect : Tag
left : Tag
right : Tag
data PLRTree : Set where
leaf : PLRTree
node : Tag → A → PLRTree → PLRTree → PLRTree
forget : PLRTree → BTree
forget leaf = leaf
forget (node _ x l r) = node x (forget l) (forget r)
flatten : PLRTree → List A
flatten leaf = []
flatten (node _ x l r) = x ∷ flatten l ++ flatten r
| {
"alphanum_fraction": 0.6629213483,
"avg_line_length": 20.2272727273,
"ext": "agda",
"hexsha": "118b59ab75a76a9603de5488e9d76cf8663093a9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/PLRTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/PLRTree.agda",
"max_line_length": 52,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/PLRTree.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 146,
"size": 445
} |
open import Data.Product using ( _×_ )
open import Web.Semantic.DL.Signature using ( Signature ; CN ; RN )
module Web.Semantic.DL.FOL where
-- A fragment of first order logic with no existentials or disjunctions.
infixr 4 _∧_
data Formula (Σ : Signature) (Δ : Set) : Set where
true : Formula Σ Δ
false : Formula Σ Δ
_∧_ : Formula Σ Δ → Formula Σ Δ → Formula Σ Δ
_∈₁_ : Δ → CN Σ → Formula Σ Δ
_∈₁_⇒_ : Δ → CN Σ → Formula Σ Δ → Formula Σ Δ
_∈₂_ : (Δ × Δ) → RN Σ → Formula Σ Δ
_∈₂_⇒_ : (Δ × Δ) → RN Σ → Formula Σ Δ → Formula Σ Δ
_∼_ : Δ → Δ → Formula Σ Δ
_∼_⇒_ : Δ → Δ → Formula Σ Δ → Formula Σ Δ
∀₁ : (Δ → Formula Σ Δ) → Formula Σ Δ
| {
"alphanum_fraction": 0.6152671756,
"avg_line_length": 31.1904761905,
"ext": "agda",
"hexsha": "6cda59c91985174c6ee0bcb736196ae33bb1e915",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/FOL.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/FOL.agda",
"max_line_length": 72,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/FOL.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 277,
"size": 655
} |
-- Andreas, 2015-07-16
-- For printing lambda-bound names, name _ should behave as no name.
-- {-# OPTIONS -v tc.term.lambda:60 #-}
module _ where
Test = (A : Set) {A : Set} → A → A
works : Test
works = λ C x → {!!}
-- the goal should be displayed as ?0 : .A
g : Test
g = λ C {_} x → {!!}
-- the goal should be displayed as ?1 : .A
-- not ?1 : _ or ?1 : A
h : Test
h = λ C {_} → λ x → {!!}
-- the goal should be displayed as ?1 : .A
-- not ?1 : _ or ?1 : A
| {
"alphanum_fraction": 0.5472103004,
"avg_line_length": 17.9230769231,
"ext": "agda",
"hexsha": "2617883f9a8cc5f499c19a23660624ab1ce82629",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue630a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue630a.agda",
"max_line_length": 68,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue630a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 164,
"size": 466
} |
-- Andreas, 2018-09-12, issue #3167-2: --(no-)prop option
--
-- A local --prop option should override a global --no-prop flag.
-- Issue3167prop.flags has --no-prop.
{-# OPTIONS --prop #-}
-- The following depends on Prop enabled
data _≡_ {a} {A : Prop a} (x : A) : A → Prop a where
refl : x ≡ x
data P : Prop where
a b : P
test : (x y : P) → x ≡ y
test x y = refl
| {
"alphanum_fraction": 0.5951742627,
"avg_line_length": 20.7222222222,
"ext": "agda",
"hexsha": "5936c9983e2e992a50da077df72aef4d04d1ff1b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3167prop.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3167prop.agda",
"max_line_length": 65,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3167prop.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 131,
"size": 373
} |
module BTA10 where
----------------------------------------
--equivalence between two typing systems
----------------------------------------
------------
--system one
------------
-- module annotated-type-one where
-- open import Data.Bool
-- open import Data.List
-- open import Data.Nat
-- infix 4 _∈_
-- data _∈_ {A : Set} : A → List A → Set where
-- hd : ∀ {x xs} → x ∈ (x ∷ xs)
-- tl : ∀ {x y xs} → x ∈ xs → x ∈ (y ∷ xs)
-- data BT : Set where
-- S : BT
-- D : BT
-- data _⊑_ : BT → BT → Set where
-- bt-refl : ∀ {bt} → bt ⊑ bt
-- bt-≤-dyn : ∀ {bt} → bt ⊑ D
-- data atype : BT → Set where
-- AInt : (bt : BT) → atype bt
-- AFun : (bt : BT) → ∀ {bt₁ bt₂} → atype bt₁ → atype bt₂ → bt ⊑ bt₁ → bt ⊑ bt₂ → atype bt
-- ⊎ : (bt : BT) → ∀ {bt₁ bt₂} → atype bt₁ → atype bt₂ → bt ⊑ bt₁ → bt ⊑ bt₂ → atype bt
-- • : (bt : BT) → ∀ {bt₁ bt₂} → atype bt₁ → atype bt₂ → bt ⊑ bt₁ → bt ⊑ bt₂ → atype bt
-- -- btof : ∀ {bt : BT} → atype bt → BT
-- -- btof (AInt bt) = bt
-- -- btof (AFun bt ty ty₁ x x₁) = bt
-- -- btof (⊎ bt ty ty₁ x x₁) = bt
-- -- btof (• bt ty ty₁ x x₁) = bt
-- ----------------
-- --typing context
-- ----------------
-- ----------------------
-- --auxiliary definition
-- ----------------------
-- record Sg (S : Set) (T : S → Set) : Set where
-- constructor _,_
-- field
-- ffst : S
-- ssnd : T ffst
-- open Sg public
-- _of_ : (BT : Set) → (BT → Set) → Set
-- BT of atype = Sg BT \ x → atype x
-- AType : Set
-- AType = BT of atype
-- ---------
-- --context
-- ---------
-- ACtx = List AType
-- ---------
-- --example
-- ---------
-- context1 : ACtx
-- context1 = (D , AInt D) ∷ (S , AInt S) ∷ (S , AFun S (AInt D) (AInt D) bt-≤-dyn bt-≤-dyn) ∷ []
-- ------------------
-- --typed expression
-- ------------------
-- data AExp (Δ : ACtx) : AType → Set where
-- Var : ∀ {α} → α ∈ Δ → AExp Δ α
-- Int : (bt : BT) → ℕ → AExp Δ (bt , AInt bt)
-- Add : ∀ {bt₁ bt₂} → (bt : BT) → AExp Δ (bt₁ , AInt bt₁) → AExp Δ (bt₂ , AInt bt₂)
-- → bt ⊑ bt₁ → bt ⊑ bt₂ → AExp Δ (bt , AInt bt)
-- ALam : ∀ {b b' : BT} {α₁ : atype b} {α₂ : atype b'} → (bt : BT) → AExp ((b , α₁) ∷ Δ) (b' , α₂)
-- → (e₁ : bt ⊑ b) → (e₂ : bt ⊑ b') → AExp Δ (bt , AFun bt α₁ α₂ e₁ e₂)
-- AApp : ∀ {b b' bt : BT} {α₁ : atype b} {α₂ : atype b'} {e₁ : bt ⊑ b} {e₂ : bt ⊑ b'} → AExp Δ (bt , AFun bt α₁ α₂ e₁ e₂)
-- → AExp Δ (b , α₁) → AExp Δ (b' , α₂)
-- -- Static pairs and sums
-- _,_ : ∀ {b b' bt : BT} {α₁ : atype b} {α₂ : atype b'} → AExp Δ (b , α₁) → AExp Δ (b' , α₂)
-- → (e₁ : bt ⊑ b) → (e₂ : bt ⊑ b') → AExp Δ (bt , • bt α₁ α₂ e₁ e₂)
-- Tl : ∀ {b b' bt : BT} {α₁ : atype b} {α₂ : atype b'} → AExp Δ (b , α₁) → (e₁ : bt ⊑ b) → (e₂ : bt ⊑ b')
-- → AExp Δ (bt , ⊎ bt α₁ α₂ e₁ e₂)
-- Tr : ∀ {b b' bt : BT} {α₁ : atype b} {α₂ : atype b'} → AExp Δ (b' , α₂) → (e₁ : bt ⊑ b) → (e₂ : bt ⊑ b')
-- → AExp Δ (bt , ⊎ bt α₁ α₂ e₁ e₂)
-- Fst : ∀ {b b' bt : BT} {α₁ : atype b} {α₂ : atype b'} {e₁ : bt ⊑ b} {e₂ : bt ⊑ b'} → AExp Δ (bt , • bt α₁ α₂ e₁ e₂) → AExp Δ (b , α₁)
-- Snd : ∀ {b b' bt : BT} {α₁ : atype b} {α₂ : atype b'} {e₁ : bt ⊑ b} {e₂ : bt ⊑ b'} → AExp Δ (bt , • bt α₁ α₂ e₁ e₂) → AExp Δ (b' , α₂)
-- Case : ∀ {b b' b'' bt : BT} {α₁ : atype b} {α₂ : atype b'} {α₃ : atype b''} {e₁ : bt ⊑ b} {e₂ : bt ⊑ b'}
-- → AExp Δ (bt , ⊎ bt α₁ α₂ e₁ e₂) → AExp ((b , α₁) ∷ Δ) (b'' , α₃)
-- → AExp ((b' , α₂) ∷ Δ) (b'' , α₃)
-- → bt ⊑ b'' → AExp Δ (b'' , α₃)
-- -- Liftable static terms
-- -- ↑ : ∀ {α} → Liftable α → AExp Δ α → AExp Δ (D (typeof α))
------------
--system two
------------
module annotated-type-two where
open import Data.Bool
open import Data.List
open import Data.Nat
module traditional-representation where
infix 4 _∈_
data _∈_ {A : Set} : A → List A → Set where
hd : ∀ {x xs} → x ∈ (x ∷ xs)
tl : ∀ {x y xs} → x ∈ xs → x ∈ (y ∷ xs)
data BT : Set where
S : BT
D : BT
------------------------------
--binding time annotated types
------------------------------
------------------------------
--Note
--[BType] for ?
--[AType] for annotated type
------------------------------
mutual
data AType : Set where
an : BT → BType → AType
data BType : Set where
BInt : BType
BFun : AType → AType → BType
_•_ : AType → AType → BType
_⊎_ : AType → AType → BType
ACtx = List AType
------------------
--well-formed type
------------------
---------------------
--auxiliaries
---------------------
btof : AType → BT
btof (an a x₁) = a
data _⊑_ : BT → BT → Set where
reflS : S ⊑ S
reflD : D ⊑ D
S≤D : S ⊑ D
-----
--wft
-----
data wft : AType → Set where
wf-int : ∀ {a : BT} → wft (an a BInt)
wf-fun : ∀ {a : BT} {α₁ α₂ : AType} → wft α₁ → wft α₂
→ a ⊑ btof α₁ → a ⊑ btof α₂ → wft (an a (BFun α₁ α₂))
wf-pair : ∀ {a : BT} {α₁ α₂ : AType} → wft α₁ → wft α₂
→ a ⊑ btof α₁ → a ⊑ btof α₂ → wft (an a (α₁ • α₂))
wf-sum : ∀ {a : BT} {α₁ α₂ : AType} → wft α₁ → wft α₂
→ a ⊑ btof α₁ → a ⊑ btof α₂ → wft (an a (α₁ ⊎ α₂))
----------
--Liftable
----------
-----------------------------------------------------------------
--Note
--• liftable defines a subset of annotated expressions whose type
-- annotation can be "lifted" to "D"
--• liftable dynamic types are trivially lifted
--• assume that we only consider the set of well-formed types
-----------------------------------------------------------------
mutual
data Liftable : AType → Set where
--dynamic type can be trivially lifted
D-aty : ∀ {σ} → Liftable (an D σ)
--static integer can be lifted to a dynamic one
--same holds for static pair and sum
S-int : Liftable (an S BInt)
S-pair : ∀ {α₁ α₂} → Liftable α₁ → Liftable α₂
→ Liftable (an S (α₁ • α₂))
S-sum : ∀ {α₁ α₂} → Liftable α₁ → Liftable α₂
→ Liftable (an S (α₁ ⊎ α₂))
--a liftable static functional type must have
--1. dynamic value as input
--2. higher-order static value with dynamic output
--3. higher-order static value as input with no
-- static inputs
S-fun : ∀ {α₁ α₂} → Liftable⁻ α₁ → Liftable α₂
→ Liftable (an S (BFun α₁ α₂))
data Liftable⁻ : AType → Set where
D-aty : ∀ {σ} → Liftable⁻ (an D σ)
S-pair : ∀ {α₁ α₂} → Liftable⁻ α₁ → Liftable⁻ α₂
→ Liftable⁻ (an S (α₁ • α₂))
S-fun : ∀ {α₁ α₂} → Liftable α₁ → Liftable⁻ α₂
→ Liftable⁻ (an S (BFun α₁ α₂))
data liftable : AType → Set where
↑ : ∀ {α} → wft α → Liftable α → liftable α
----------------------------
--typed annotated expression
----------------------------
----------------------------------------------------
--Note
--constructor name begins with an "A" for "annotated"
--typing constructor as [AExp]
--typing context as [Δ]
--"a" for both expression and type annotation
--"α" for [AType]
--"σ" for [BType]
----------------------------------------------------
data AExp (Δ : ACtx) : AType → Set where
Var : ∀ {α} → α ∈ Δ → AExp Δ α
AInt : (a : BT) → ℕ → AExp Δ (an a BInt)
AAdd : (a : BT) → AExp Δ (an a BInt) → AExp Δ (an a BInt) → AExp Δ (an a BInt)
ALam : ∀ {α₁ α₂} → (a : BT) → wft (an a (BFun α₁ α₂)) → AExp (α₁ ∷ Δ) α₂
→ AExp Δ (an a (BFun α₁ α₂))
AApp : ∀ {α₁ α₂} → (a : BT) → wft (an a (BFun α₁ α₂)) → AExp Δ (an a (BFun α₁ α₂))
→ AExp Δ α₁ → AExp Δ α₂
APair : ∀ {α₁ α₂} → (a : BT) → wft (an a (α₁ • α₂)) → AExp Δ α₁ → AExp Δ α₂
→ AExp Δ (an a (α₁ • α₂))
ATl : ∀ {α₁ α₂} → (a : BT) → wft (an a (α₁ ⊎ α₂)) → AExp Δ α₁
→ AExp Δ (an a (α₁ ⊎ α₂))
ATr : ∀ {α₁ α₂} → (a : BT) → wft (an a (α₁ ⊎ α₂)) → AExp Δ α₂
→ AExp Δ (an a (α₁ ⊎ α₂))
ACase : ∀ {α₁ α₂ α₃} {a : BT} → a ⊑ btof α₃ → AExp Δ (an a (α₁ ⊎ α₂)) → AExp (α₁ ∷ Δ) α₃
→ AExp (α₂ ∷ Δ) α₃ → AExp Δ α₃
Lift : ∀ {a} {σ} → liftable (an a σ) → AExp Δ (an a σ) → AExp Δ (an D σ)
module two-level-representation where
---------------
--residual type
---------------
data type : Set where
Int : type
Fun : type → type → type
_•_ : type → type → type
_⊎_ : type → type → type
----------------
--annotated type
----------------
---------------------------------------------
--Note
--• static type constructor starting with "S"
-- except for pair and sum
--• residual type used for building dynamic
-- type
---------------------------------------------
data atype : Set where
SInt : atype
SFun : atype → atype → atype
D : type → atype
_•_ : atype → atype → atype
_⊎_ : atype → atype → atype
btof-γ : atype → BT
btof-γ SInt = S
btof-γ (SFun γ γ₁) = S
btof-γ (D x) = D
btof-γ (γ • γ₁) = S
btof-γ (γ ⊎ γ₁) = S
actx = List atype
----------
--Liftable
----------
--Note
--"τ" for residual type [type]
--"γ" for [atype]
mutual
data Liftok : atype → Set where
D-aty : ∀ τ → Liftok (D τ)
S-int : Liftok SInt
S-sum : ∀ {γ₁ γ₂} → Liftok γ₁ → Liftok γ₂ → Liftok (γ₁ ⊎ γ₂)
S-pair : ∀ {γ₁ γ₂} → Liftok γ₁ → Liftok γ₂ → Liftok (γ₁ • γ₂)
S-fun : ∀ {γ₁ γ₂} → Liftok⁻ γ₁ → Liftok γ₂ → Liftok (SFun γ₁ γ₂)
data Liftok⁻ : atype → Set where
D-aty : ∀ τ → Liftok⁻ (D τ)
_•_ : ∀ {γ₁ γ₂} → Liftok⁻ γ₁ → Liftok⁻ γ₂ → Liftok⁻ (γ₁ • γ₂)
S-fun : ∀ {γ₁ γ₂} → Liftok γ₁ → Liftok⁻ γ₂ → Liftok⁻ (SFun γ₁ γ₂)
----------------------------
--typed two-level annotated expression
----------------------------
--------------------
--auxiliary function
--------------------
typeof : atype → type
typeof SInt = Int
typeof (SFun γ₁ γ₂) = Fun (typeof γ₁) (typeof γ₂)
typeof (D τ) = τ
typeof (γ₁ • γ₂) = typeof γ₁ • typeof γ₂
typeof (γ₁ ⊎ γ₂) = typeof γ₁ ⊎ typeof γ₂
--------
--[aexp]
--------
--Note
--• "γ" for [atype]
--• "τ" for [type]
--• typed terms starting with "S" for "static"
-- and "D" for "dynamic",except for pair
--• "Ω" for typing context
data aexp (Ω : actx) : atype → Set where
Var : ∀ {γ} → γ ∈ Ω → aexp Ω γ
SInt : ℕ → aexp Ω SInt
SAdd : aexp Ω SInt → aexp Ω SInt → aexp Ω SInt
SLam : ∀ {γ₁ γ₂} → aexp (γ₁ ∷ Ω) γ₂ → aexp Ω (SFun γ₁ γ₂)
SApp : ∀ {γ₁ γ₂} → aexp Ω (SFun γ₁ γ₂) → aexp Ω γ₁ → aexp Ω γ₂
DInt : ℕ → aexp Ω (D Int)
DAdd : aexp Ω (D Int) → aexp Ω (D Int) → aexp Ω (D Int)
DLam : ∀ {τ₁ τ₂} → aexp ((D τ₁) ∷ Ω) (D τ₂) → aexp Ω (D (Fun τ₁ τ₂))
DApp : ∀ {τ₁ τ₂} → aexp Ω (D (Fun τ₁ τ₂)) → aexp Ω (D τ₁) → aexp Ω (D τ₂)
-- Static pairs and sums
_,_ : ∀ {γ₁ γ₂} → aexp Ω γ₁ → aexp Ω γ₂ → aexp Ω (γ₁ • γ₂)
STl : ∀ {γ₁ γ₂} → aexp Ω γ₁ → aexp Ω (γ₁ ⊎ γ₂)
STr : ∀ {γ₁ γ₂} → aexp Ω γ₂ → aexp Ω (γ₁ ⊎ γ₂)
SFst : ∀ {γ₁ γ₂} → aexp Ω (γ₁ • γ₂) → aexp Ω γ₁
SSnd : ∀ {γ₁ γ₂} → aexp Ω (γ₁ • γ₂) → aexp Ω γ₂
SCase : ∀ {γ₁ γ₂ γ₃} → aexp Ω (γ₁ ⊎ γ₂) → aexp (γ₁ ∷ Ω) γ₃ → aexp (γ₂ ∷ Ω) γ₃ → aexp Ω γ₃
-- Dynamic pairs and sums
_ḋ_ : ∀ {τ₁ τ₂} → aexp Ω (D τ₁) → aexp Ω (D τ₂) → aexp Ω (D (τ₁ • τ₂))
DTl : ∀ {τ₁ τ₂} → aexp Ω (D τ₁) → aexp Ω (D (τ₁ ⊎ τ₂))
DTr : ∀ {τ₁ τ₂} → aexp Ω (D τ₂) → aexp Ω (D (τ₁ ⊎ τ₂))
DFst : ∀ {τ₁ τ₂} → aexp Ω (D (τ₁ • τ₂)) → aexp Ω (D τ₁)
DSnd : ∀ {τ₁ τ₂} → aexp Ω (D (τ₁ • τ₂)) → aexp Ω (D τ₂)
DCase : ∀ {τ₁ τ₂ τ₃} → aexp Ω (D (τ₁ ⊎ τ₂)) → aexp ((D τ₁) ∷ Ω) (D τ₃) → aexp ((D τ₂) ∷ Ω) (D τ₃) → aexp Ω (D τ₃)
-- Liftable static terms
Lift : ∀ {γ} → Liftok γ → aexp Ω γ → aexp Ω (D (typeof γ))
---------------------------------------------------------------
--Isomorphism between terms typed by [AExp] and terms by [aexp]
---------------------------------------------------------------
module isomorphism where
open import Data.Product
open import Relation.Binary.PropositionalEquality
----------
--Analysis
----------
--consider static integer in [aexp],
--SInt 0 : aexp Ω SInt,∀ Ω
--naturally its counter-part in [AExp] should be,
--AInt S 0 : AExp Δ (an S BInt)
--for dynamic integer,
--DInt 0 : aexp Ω (D Int)
--AInt D 0 : aexp Δ (an D BInt)
--Notice the two kinds of isomorphisms involved in above example
--a. isomorphism w.r.t. types
--b. isomorphism w.r.t. typed terms
---------------------
--a. type isomorphism
---------------------
--a.1. [atype] to [AType]
--integer
--SInt ==> an S BInt
--D Int ==> an D BInt
--function
--SFun (D Int)(D Int) ==> an S (BFun (an D BInt) (an D BInt))
--D (Fun Int Int) ==> an D (BFun (an D BInt) (an D BInt))
------------------------------------
--projection from [atype] to [AType]
------------------------------------
projT₁ : atype → AType
projT₁ SInt = an S BInt
projT₁ (SFun aty aty₁) = an S (BFun (projT₁ aty) (projT₁ aty₁))
projT₁ (D Int) = an D BInt
projT₁ (D (Fun x x₁)) = an D (BFun (projT₁ (D x)) (projT₁ (D x₁)))
projT₁ (D (x • x₁)) = an D (projT₁ (D x) • projT₁ (D x₁))
projT₁ (D (x ⊎ x₁)) = an D (projT₁ (D x) ⊎ projT₁ (D x₁))
projT₁ (aty • aty₁) = an S ((projT₁ aty) • projT₁ aty₁)
projT₁ (aty ⊎ aty₁) = an S ((projT₁ aty) ⊎ projT₁ aty₁)
--a.2. [AType] to [atype]
--imposing [wft] upon types defined in [AType] before projection
--consider the following type,
--an D (BFun (an S BInt) (an S BInt)) which has no counter part
--in [atype] for the following lemma,
-- ∀ γ, wft (projT₁ γ)
--suppose we focus on these types satisfying [wft],
--integer
--an S BInt ==> SInt
--an D BInt ==> D Int
--function
--an S BFun (an D BInt) (an D BInt) ==> SFun (D Int) (D Int)
--an D BFun (an D BInt) (an D BInt) ==> D (Fun Int Int)
------------------------------------------------
--projection from well-formed [AType] to [atype]
------------------------------------------------
--------
--helper
--------
------------------------
--from [atype] to [type]
------------------------
γ→τ : atype → type
γ→τ SInt = Int
γ→τ (SFun aty aty₁) = Fun (γ→τ aty) (γ→τ aty₁)
γ→τ (D x) = x
γ→τ (aty • aty₁) = (γ→τ aty) • (γ→τ aty₁)
γ→τ (aty ⊎ aty₁) = (γ→τ aty) ⊎ (γ→τ aty₁)
projT₂ : (α : AType) → wft α → atype
projT₂ .(an S BInt) (wf-int {S}) = SInt
projT₂ .(an D BInt) (wf-int {D}) = D Int
projT₂ .(an S (BFun α₁ α₂)) (wf-fun {S} {α₁} {α₂} wft wft₁ x x₁) = SFun (projT₂ α₁ wft) (projT₂ α₂ wft₁)
projT₂ .(an D (BFun α₁ α₂)) (wf-fun {D} {α₁} {α₂} wft wft₁ x x₁) = D (Fun (γ→τ (projT₂ α₁ wft)) (γ→τ (projT₂ α₂ wft₁)))
projT₂ .(an S (α₁ • α₂)) (wf-pair {S} {α₁} {α₂} wft wft₁ x x₁) = (projT₂ α₁ wft) • (projT₂ α₂ wft₁)
projT₂ .(an D (α₁ • α₂)) (wf-pair {D} {α₁} {α₂} wft wft₁ x x₁) = D (γ→τ (projT₂ α₁ wft) • γ→τ (projT₂ α₂ wft₁))
projT₂ .(an S (α₁ ⊎ α₂)) (wf-sum {S} {α₁} {α₂} wft wft₁ x x₁) = (projT₂ α₁ wft) ⊎ (projT₂ α₂ wft₁)
projT₂ .(an D (α₁ ⊎ α₂)) (wf-sum {D} {α₁} {α₂} wft wft₁ x x₁) = D (γ→τ (projT₂ α₁ wft) ⊎ γ→τ (projT₂ α₂ wft₁))
-------------------------------------
--lemmas w.r.t. isomorphism of types
-------------------------------------
-----------------------------------------------
--direction one:"starting from type in [atype]"
-----------------------------------------------
-----------------------
--some auxiliary lemmas
-----------------------
S⊑* : ∀ {α} → S ⊑ btof α
S⊑* {an S x₁} = reflS
S⊑* {an D x₁} = S≤D
a-pDatype : ∀ {τ : type} → btof (projT₁ (D τ)) ≡ D
a-pDatype {Int} = refl
a-pDatype {Fun τ τ₁} = refl
a-pDatype {τ • τ₁} = refl
a-pDatype {τ ⊎ τ₁} = refl
D-a-pDatype : ∀ {τ : type} → D ⊑ (btof (projT₁ (D τ)))
D-a-pDatype {τ} rewrite a-pDatype {τ} = reflD
isoT₁ : ∀ (γ : atype) → Σ (wft (projT₁ γ)) \ x → γ ≡ projT₂ (projT₁ γ) x
isoT₁ SInt = wf-int , refl
isoT₁ (SFun γ γ₁) with (proj₂ (isoT₁ γ)) | (proj₂ (isoT₁ γ₁))
... | I | I' = wf-fun (proj₁ (isoT₁ γ)) (proj₁ (isoT₁ γ₁)) (S⊑* {(projT₁ γ)}) (S⊑* {projT₁ γ₁}) , cong₂ SFun I I'
isoT₁ (D Int) = wf-int , refl
isoT₁ (D (Fun x x₁)) = wf-fun (proj₁ (isoT₁ (D x))) (proj₁ (isoT₁ (D x₁))) (D-a-pDatype {x}) (D-a-pDatype {x₁}) ,
cong
D
(cong₂ Fun (cong γ→τ (proj₂ (isoT₁ (D x))))
(cong γ→τ (proj₂ (isoT₁ (D x₁)))))
isoT₁ (D (x • x₁)) = wf-pair (proj₁ (isoT₁ (D x))) (proj₁ (isoT₁ (D x₁))) (D-a-pDatype {x}) (D-a-pDatype {x₁}) ,
cong
D
(cong₂ _•_ (cong γ→τ (proj₂ (isoT₁ (D x))))
(cong γ→τ (proj₂ (isoT₁ (D x₁)))))
isoT₁ (D (x ⊎ x₁)) = wf-sum (proj₁ (isoT₁ (D x))) (proj₁ (isoT₁ (D x₁))) (D-a-pDatype {x}) (D-a-pDatype {x₁}) ,
cong
D
(cong₂ _⊎_ (cong γ→τ (proj₂ (isoT₁ (D x))))
(cong γ→τ (proj₂ (isoT₁ (D x₁)))))
isoT₁ (γ • γ₁) = wf-pair (proj₁ (isoT₁ γ)) (proj₁ (isoT₁ γ₁)) (S⊑* {projT₁ γ}) (S⊑* {projT₁ γ₁}) ,
cong₂ _•_ (proj₂ (isoT₁ γ)) (proj₂ (isoT₁ γ₁))
isoT₁ (γ ⊎ γ₁) = wf-sum (proj₁ (isoT₁ γ)) (proj₁ (isoT₁ γ₁)) (S⊑* {projT₁ γ}) (S⊑* {projT₁ γ₁}) ,
cong₂ _⊎_ (proj₂ (isoT₁ γ)) (proj₂ (isoT₁ γ₁))
-----------------------------------------------------------
--direction two:"starting from type in well-formed [AType]"
-----------------------------------------------------------
-----------------------
--some auxiliary lemmas
-----------------------
eqDγ→τprojT₂ : ∀ {α : AType} {wf : wft α} → D ⊑ btof α → D (γ→τ (projT₂ α wf)) ≡ projT₂ α wf
eqDγ→τprojT₂ {an S BInt} {wf-int} ()
eqDγ→τprojT₂ {an D BInt} {wf-int} e = refl
eqDγ→τprojT₂ {an S (BFun α₁ α₂)} {wf-fun wf wf₁ x x₁} ()
eqDγ→τprojT₂ {an D (BFun α₁ α₂)} {wf-fun wf wf₁ x x₁} e = refl
eqDγ→τprojT₂ {an S (α₁ • α₂)} {wf-pair wf wf₁ x x₁} ()
eqDγ→τprojT₂ {an D (α₁ • α₂)} {wf-pair wf wf₁ x x₁} e = refl
eqDγ→τprojT₂ {an S (α₁ ⊎ α₂)} {wf-sum wf wf₁ x x₁} ()
eqDγ→τprojT₂ {an D (α₁ ⊎ α₂)} {wf-sum wf wf₁ x x₁} e = refl
isoT₂ : ∀ {α : AType} → (wf : wft α) → α ≡ projT₁ (projT₂ α wf)
isoT₂ {an S BInt} wf-int = refl
isoT₂ {an S (BFun x x₁)} (wf-fun wf wf₁ x₂ x₃) = cong₂ an refl (cong₂ BFun (isoT₂ {x} wf) (isoT₂ {x₁} wf₁))
isoT₂ {an S (x • x₁)} (wf-pair wf wf₁ x₂ x₃) = cong₂ an refl (cong₂ _•_ (isoT₂ {x} wf) (isoT₂ {x₁} wf₁))
isoT₂ {an S (x ⊎ x₁)} (wf-sum wf wf₁ x₂ x₃) = cong₂ an refl (cong₂ _⊎_ (isoT₂ {x} wf) (isoT₂ {x₁} wf₁))
isoT₂ {an D BInt} wf-int = refl
isoT₂ {an D (BFun x x₁)} (wf-fun wf wf₁ x₂ x₃) =
cong₂ an refl
(cong₂ BFun
(trans (isoT₂ {x} wf)
(sym (cong projT₁ (eqDγ→τprojT₂ {x} {wf} x₂))))
(trans (isoT₂ {x₁} wf₁)
(sym (cong projT₁ (eqDγ→τprojT₂ {x₁} {wf₁} x₃)))))
isoT₂ {an D (x • x₁)} (wf-pair wf wf₁ x₂ x₃) =
cong₂ an refl
(cong₂ _•_
(trans (isoT₂ {x} wf)
(sym (cong projT₁ (eqDγ→τprojT₂ {x} {wf} x₂))))
(trans (isoT₂ {x₁} wf₁)
(sym (cong projT₁ (eqDγ→τprojT₂ {x₁} {wf₁} x₃)))))
isoT₂ {an D (x ⊎ x₁)} (wf-sum wf wf₁ x₂ x₃) =
cong₂ an refl
(cong₂ _⊎_
(trans (isoT₂ {x} wf)
(sym (cong projT₁ (eqDγ→τprojT₂ {x} {wf} x₂))))
(trans (isoT₂ {x₁} wf₁)
(sym (cong projT₁ (eqDγ→τprojT₂ {x₁} {wf₁} x₃)))))
------------------------------------------------
--lemmas w.r.t. isomorphism of typed expressions
------------------------------------------------
----------------
--some instances
----------------
------------------
--[AExp] to [aexp]
------------------
--Var hd : AExp [an D (BFun (an D BInt) (an D BInt))]
-- (an D (BFun (an D BInt) (an D BInt)))
--==>projt₂*
--Var hd : aexp [D (Fun Int Int)] (D (Fun Int Int))
--*Note that projection from expression in [AExp] to
-- that in [aexp] requires that both the type and the
-- typing environment are well-formed
--AInt S 0 : AExp Δ (an S BInt),∀ Δ
--==>projt₂
--SInt 0 : aexp Ω* SInt,∀ Ω
--*Note that the corresponding typing environment in [aexp] satisfies,
-- Ω = projection of Δ
--ALam S (wf-fun wf-int wf-int *≤D *≤D) (Var hd)
--:AExp [] (an S (BFun (an D BInt) (an D BInt)))
--==>projt₂
--SLam (Var hd) : aexp [] (SFun (D Int) (D Int))
--ALam D (wf-fun wf-int wf-int refl refl) (Var hd)
--:AExp [] (an D (BFun (an D BInt) (an D BInt)))
--==>projt₂
--DLam (Var hd) : aexp [] (D (Fun Int Int))
-----------------------
--summary upon [projt₂]
-----------------------
--• projection only of terms which are typed both by
-- well-formed [AType] and under well-formed Δ
--• the results are typed under Ω which is the projection
-- of Δ
------------------------------------------
--some auxiliary functions and definitions
------------------------------------------
---------------
--Well-formed Δ
---------------
data wfe : ACtx → Set where
wf-[] : wfe []
wf-∷ : ∀ {α : AType} {AEnv : ACtx}
→ wft α → wfe AEnv
→ wfe (α ∷ AEnv)
-----------------------------
--projΔ (similar to [projT₂])
-----------------------------
projΔ : (Δ : ACtx) → wfe Δ → actx
projΔ [] wfe = []
projΔ (x ∷ Δ) (wf-∷ x₁ wfe) = projT₂ x x₁ ∷ projΔ Δ wfe
--------
--projt₂
--------
-----------------------
--some auxiliary lemmas
-----------------------
-- --------
-- --is-≡-α
-- --------
-- is-≡-α : (α₁ α₂ : AType) → Bool
-- is-≡-α (an S BInt) (an S BInt) = true
-- is-≡-α (an S BInt) (an S (BFun x x₁)) = false
-- is-≡-α (an S BInt) (an S (x • x₁)) = false
-- is-≡-α (an S BInt) (an S (x ⊎ x₁)) = false
-- is-≡-α (an S (BFun x x₁)) (an S BInt) = false
-- is-≡-α (an S (BFun x x₁)) (an S (BFun x₂ x₃)) = is-≡-α x x₂ ∧ is-≡-α x₁ x₃
-- is-≡-α (an S (BFun x x₁)) (an S (x₂ • x₃)) = false
-- is-≡-α (an S (BFun x x₁)) (an S (x₂ ⊎ x₃)) = false
-- is-≡-α (an S (x • x₁)) (an S BInt) = false
-- is-≡-α (an S (x • x₁)) (an S (BFun x₂ x₃)) = false
-- is-≡-α (an S (x • x₁)) (an S (x₂ • x₃)) = is-≡-α x x₂ ∧ is-≡-α x₁ x₃
-- is-≡-α (an S (x • x₁)) (an S (x₂ ⊎ x₃)) = false
-- is-≡-α (an S (x ⊎ x₁)) (an S BInt) = false
-- is-≡-α (an S (x ⊎ x₁)) (an S (BFun x₂ x₃)) = false
-- is-≡-α (an S (x ⊎ x₁)) (an S (x₂ • x₃)) = false
-- is-≡-α (an S (x ⊎ x₁)) (an S (x₂ ⊎ x₃)) = is-≡-α x x₂ ∧ is-≡-α x₁ x₃
-- is-≡-α (an S x₁) (an D x₃) = false
-- is-≡-α (an D x₁) (an S x₃) = false
-- is-≡-α (an D BInt) (an D BInt) = true
-- is-≡-α (an D BInt) (an D (BFun x x₁)) = false
-- is-≡-α (an D BInt) (an D (x • x₁)) = false
-- is-≡-α (an D BInt) (an D (x ⊎ x₁)) = false
-- is-≡-α (an D (BFun x x₁)) (an D BInt) = false
-- is-≡-α (an D (BFun x x₁)) (an D (BFun x₂ x₃)) = is-≡-α x x₂ ∧ is-≡-α x₁ x₃
-- is-≡-α (an D (BFun x x₁)) (an D (x₂ • x₃)) = false
-- is-≡-α (an D (BFun x x₁)) (an D (x₂ ⊎ x₃)) = false
-- is-≡-α (an D (x • x₁)) (an D BInt) = false
-- is-≡-α (an D (x • x₁)) (an D (BFun x₂ x₃)) = false
-- is-≡-α (an D (x • x₁)) (an D (x₂ • x₃)) = is-≡-α x x₂ ∧ is-≡-α x₁ x₃
-- is-≡-α (an D (x • x₁)) (an D (x₂ ⊎ x₃)) = false
-- is-≡-α (an D (x ⊎ x₁)) (an D BInt) = false
-- is-≡-α (an D (x ⊎ x₁)) (an D (BFun x₂ x₃)) = false
-- is-≡-α (an D (x ⊎ x₁)) (an D (x₂ • x₃)) = false
-- is-≡-α (an D (x ⊎ x₁)) (an D (x₂ ⊎ x₃)) = is-≡-α x x₂ ∧ is-≡-α x₁ x₃
-- --------
-- --is-≡-τ
-- --------
-- is-≡-τ : (τ₁ τ₂ : type) → Bool
-- is-≡-τ Int Int = true
-- is-≡-τ Int (Fun τ₂ τ₃) = false
-- is-≡-τ Int (τ₂ • τ₃) = false
-- is-≡-τ Int (τ₂ ⊎ τ₃) = false
-- is-≡-τ (Fun τ₁ τ₂) Int = false
-- is-≡-τ (Fun τ₁ τ₂) (Fun τ₃ τ₄) = is-≡-τ τ₁ τ₃ ∧ is-≡-τ τ₂ τ₄
-- is-≡-τ (Fun τ₁ τ₂) (τ₃ • τ₄) = false
-- is-≡-τ (Fun τ₁ τ₂) (τ₃ ⊎ τ₄) = false
-- is-≡-τ (τ₁ • τ₂) Int = false
-- is-≡-τ (τ₁ • τ₂) (Fun τ₃ τ₄) = false
-- is-≡-τ (τ₁ • τ₂) (τ₃ • τ₄) = is-≡-τ τ₁ τ₃ ∧ is-≡-τ τ₂ τ₄
-- is-≡-τ (τ₁ • τ₂) (τ₃ ⊎ τ₄) = false
-- is-≡-τ (τ₁ ⊎ τ₂) Int = false
-- is-≡-τ (τ₁ ⊎ τ₂) (Fun τ₃ τ₄) = false
-- is-≡-τ (τ₁ ⊎ τ₂) (τ₃ • τ₄) = false
-- is-≡-τ (τ₁ ⊎ τ₂) (τ₃ ⊎ τ₄) = is-≡-τ τ₁ τ₃ ∧ is-≡-τ τ₂ τ₄
-- --------
-- --is-≡-γ
-- --------
-- is-≡-γ : (γ₁ γ₂ : atype) → Bool
-- is-≡-γ SInt SInt = true
-- is-≡-γ SInt (SFun γ₂ γ₃) = false
-- is-≡-γ SInt (D x) = false
-- is-≡-γ SInt (γ₂ • γ₃) = false
-- is-≡-γ SInt (γ₂ ⊎ γ₃) = false
-- is-≡-γ (SFun γ₁ γ₂) SInt = false
-- is-≡-γ (SFun γ₁ γ₂) (SFun γ₃ γ₄) = is-≡-γ γ₁ γ₃ ∧ is-≡-γ γ₂ γ₄
-- is-≡-γ (SFun γ₁ γ₂) (D x) = false
-- is-≡-γ (SFun γ₁ γ₂) (γ₃ • γ₄) = false
-- is-≡-γ (SFun γ₁ γ₂) (γ₃ ⊎ γ₄) = false
-- is-≡-γ (D x) SInt = false
-- is-≡-γ (D x) (SFun γ₂ γ₃) = false
-- is-≡-γ (D x) (D x₁) = is-≡-τ x x₁
-- is-≡-γ (D x) (γ₂ • γ₃) = false
-- is-≡-γ (D x) (γ₂ ⊎ γ₃) = false
-- is-≡-γ (γ₁ • γ₂) SInt = false
-- is-≡-γ (γ₁ • γ₂) (SFun γ₃ γ₄) = false
-- is-≡-γ (γ₁ • γ₂) (D x) = false
-- is-≡-γ (γ₁ • γ₂) (γ₃ • γ₄) = is-≡-γ γ₁ γ₃ ∧ is-≡-γ γ₂ γ₄
-- is-≡-γ (γ₁ • γ₂) (γ₃ ⊎ γ₄) = false
-- is-≡-γ (γ₁ ⊎ γ₂) SInt = false
-- is-≡-γ (γ₁ ⊎ γ₂) (SFun γ₃ γ₄) = false
-- is-≡-γ (γ₁ ⊎ γ₂) (D x) = false
-- is-≡-γ (γ₁ ⊎ γ₂) (γ₃ • γ₄) = false
-- is-≡-γ (γ₁ ⊎ γ₂) (γ₃ ⊎ γ₄) = is-≡-γ γ₁ γ₃ ∧ is-≡-γ γ₂ γ₄
-- is-≡-γ→τ : {γ₁ γ₂ : atype} → btof-γ γ₁ ≡ D → btof-γ γ₁ ≡ btof-γ γ₂
-- → is-≡-γ γ₁ γ₂ ≡ is-≡-τ (γ→τ γ₁) (γ→τ γ₂)
-- is-≡-γ→τ {SInt} {SInt} eq eq' = refl
-- is-≡-γ→τ {SInt} {SFun γ₂ γ₃} eq eq' = refl
-- is-≡-γ→τ {SInt} {D x} () ()
-- is-≡-γ→τ {SInt} {γ₂ • γ₃} () eq'
-- is-≡-γ→τ {SInt} {γ₂ ⊎ γ₃} () eq'
-- is-≡-γ→τ {SFun γ₁ γ₂} {SInt} () eq'
-- is-≡-γ→τ {SFun γ₁ γ₂} {SFun γ₃ γ₄} () eq'
-- is-≡-γ→τ {SFun γ₁ γ₂} {D x} () eq'
-- is-≡-γ→τ {SFun γ₁ γ₂} {γ₃ • γ₄} () eq'
-- is-≡-γ→τ {SFun γ₁ γ₂} {γ₃ ⊎ γ₄} () eq'
-- is-≡-γ→τ {D x} {SInt} eq ()
-- is-≡-γ→τ {D x} {SFun γ₂ γ₃} eq ()
-- is-≡-γ→τ {D x} {D x₁} eq eq' = refl
-- is-≡-γ→τ {D x} {γ₂ • γ₃} eq ()
-- is-≡-γ→τ {D x} {γ₂ ⊎ γ₃} eq ()
-- is-≡-γ→τ {γ₁ • γ₂} {SInt} eq eq' = refl
-- is-≡-γ→τ {γ₁ • γ₂} {SFun γ₃ γ₄} () eq'
-- is-≡-γ→τ {γ₁ • γ₂} {D x} eq ()
-- is-≡-γ→τ {γ₁ • γ₂} {γ₃ • γ₄} () eq'
-- is-≡-γ→τ {γ₁ • γ₂} {γ₃ ⊎ γ₄} () eq'
-- is-≡-γ→τ {γ₁ ⊎ γ₂} {SInt} () eq'
-- is-≡-γ→τ {γ₁ ⊎ γ₂} {SFun γ₃ γ₄} () eq'
-- is-≡-γ→τ {γ₁ ⊎ γ₂} {D x} eq ()
-- is-≡-γ→τ {γ₁ ⊎ γ₂} {γ₃ • γ₄} () eq'
-- is-≡-γ→τ {γ₁ ⊎ γ₂} {γ₃ ⊎ γ₄} () eq'
-- btof-γ-projT₂-α : ∀ {a : BT} {σ : BType} {wft : wft (an a σ)}
-- → btof-γ (projT₂ (an a σ) wft) ≡ a
-- btof-γ-projT₂-α {S} {BInt} {wf-int} = refl
-- btof-γ-projT₂-α {D} {BInt} {wf-int} = refl
-- btof-γ-projT₂-α {S} {BFun α₁ α₂} {wf-fun wft wft₁ x x₁} = refl
-- btof-γ-projT₂-α {D} {BFun α₁ α₂} {wf-fun wft wft₁ x x₁} = refl
-- btof-γ-projT₂-α {S} {α₁ • α₂} {wf-pair wft wft₁ x x₁} = refl
-- btof-γ-projT₂-α {D} {α₁ • α₂} {wf-pair wft wft₁ x x₁} = refl
-- btof-γ-projT₂-α {S} {α₁ ⊎ α₂} {wf-sum wft wft₁ x x₁} = refl
-- btof-γ-projT₂-α {D} {α₁ ⊎ α₂} {wf-sum wft wft₁ x x₁} = refl
-- is-≡-projT₂ : {α₁ α₂ : AType} {wft₁ : wft α₁} {wft₂ : wft α₂}
-- → (is-≡-α α₁ α₂) ≡ (is-≡-γ (projT₂ α₁ wft₁) (projT₂ α₂ wft₂))
-- is-≡-projT₂ {an S BInt} {an S BInt} {wf-int} {wf-int} = refl
-- is-≡-projT₂ {an S BInt} {an D BInt} {wf-int} {wf-int} = refl
-- is-≡-projT₂ {an D BInt} {an S BInt} {wf-int} {wf-int} = refl
-- is-≡-projT₂ {an D BInt} {an D BInt} {wf-int} {wf-int} = refl
-- is-≡-projT₂ {an S BInt} {an S (BFun α₁ α₂)} {wf-int} {wf-fun wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an S BInt} {an D (BFun α₁ α₂)} {wf-int} {wf-fun wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an D BInt} {an S (BFun α₁ α₂)} {wf-int} {wf-fun wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an D BInt} {an D (BFun α₁ α₂)} {wf-int} {wf-fun wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an S BInt} {an S (α₁ • α₂)} {wf-int} {wf-pair wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an S BInt} {an D (α₁ • α₂)} {wf-int} {wf-pair wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an D BInt} {an S (α₁ • α₂)} {wf-int} {wf-pair wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an D BInt} {an D (α₁ • α₂)} {wf-int} {wf-pair wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an S BInt} {an S (α₁ ⊎ α₂)} {wf-int} {wf-sum wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an S BInt} {an D (α₁ ⊎ α₂)} {wf-int} {wf-sum wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an D BInt} {an S (α₁ ⊎ α₂)} {wf-int} {wf-sum wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an D BInt} {an D (α₁ ⊎ α₂)} {wf-int} {wf-sum wft₂ wft₃ x x₁} = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an S BInt} {wf-fun wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an D BInt} {wf-fun wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an S BInt} {wf-fun wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an D BInt} {wf-fun wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an S (BFun α₂ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃}
-- rewrite (is-≡-projT₂ {α₁} {α₂} {wft₁} {wft₃}) | (is-≡-projT₂ {α₃} {α₄} {wft₂} {wft₄}) = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an D (BFun α₂ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an S (BFun α₂ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (BFun (an D σ₁) (an D σ₃))} {an D (BFun (an D σ₂) (an D σ₄))} {wf-fun wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃}
-- rewrite ((is-≡-projT₂ {an D σ₁} {an D σ₂} {wft₁} {wft₃})) | ((is-≡-projT₂ {an D σ₃} {an D σ₄} {wft₂} {wft₄}))
-- | is-≡-γ→τ {projT₂ (an D σ₁) wft₁} {projT₂ (an D σ₂) wft₃}
-- (btof-γ-projT₂-α {D} {σ₁} {wft₁}) (trans (btof-γ-projT₂-α {D} {σ₁} {wft₁}) (sym (btof-γ-projT₂-α {D} {σ₂} {wft₃})))
-- | is-≡-γ→τ {projT₂ (an D σ₃) wft₂} {projT₂ (an D σ₄) wft₄}
-- (btof-γ-projT₂-α {D} {σ₃} {wft₂}) (trans (btof-γ-projT₂-α {D} {σ₃} {wft₂}) (sym (btof-γ-projT₂-α {D} {σ₄} {wft₄})))
-- = refl
-- is-≡-projT₂ {an D (BFun (an D σ₁) (an D σ₃))} {an D (BFun (an D σ₂) (an S σ₄))} {wf-fun wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ ()}
-- is-≡-projT₂ {an D (BFun (an D σ₁) (an S σ₃))} {an D (BFun (an D σ₂) (an a₄ σ₄))} {wf-fun wft₁ wft₂ x ()} {wf-fun wft₃ wft₄ x₂ x₃}
-- is-≡-projT₂ {an D (BFun (an D σ₁) (an a₃ σ₃))} {an D (BFun (an S σ₂) (an a₄ σ₄))} {wf-fun wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ () x₃}
-- is-≡-projT₂ {an D (BFun (an S σ₁) (an a₃ σ₃))} {an D (BFun (an D σ₂) (an a₄ σ₄))} {wf-fun wft₁ wft₂ () x₁} {wf-fun wft₃ wft₄ x₂ x₃}
-- is-≡-projT₂ {an D (BFun (an S σ₁) (an a₃ σ₃))} {an D (BFun (an S σ₂) (an a₄ σ₄))} {wf-fun wft₁ wft₂ () x₁} {wf-fun wft₃ wft₄ () x₃}
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an S (α₂ • α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an D (α₂ • α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an S (α₂ • α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an D (α₂ • α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an S (α₂ ⊎ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-sum wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an S (BFun α₁ α₃)} {an D (α₂ ⊎ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-sum wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an S (α₂ ⊎ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-sum wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (BFun α₁ α₃)} {an D (α₂ ⊎ α₄)} {wf-fun wft₁ wft₂ x x₁} {wf-sum wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an S (α₁ • α₃)} {an S BInt} {wf-pair wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an S (α₁ • α₃)} {an D BInt} {wf-pair wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an D (α₁ • α₃)} {an S BInt} {wf-pair wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an D (α₁ • α₃)} {an D BInt} {wf-pair wft₁ wft₂ x x₁} {wf-int} = refl
-- is-≡-projT₂ {an S (α₁ • α₃)} {an S (BFun α₂ α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an S (α₁ • α₃)} {an D (BFun α₂ α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (α₁ • α₃)} {an S (BFun α₂ α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (α₁ • α₃)} {an D (BFun α₂ α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-fun wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an S (α₁ • α₃)} {an S (α₂ • α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃}
-- rewrite (is-≡-projT₂ {α₁} {α₂} {wft₁} {wft₃}) | (is-≡-projT₂ {α₃} {α₄} {wft₂} {wft₄})
-- = refl
-- is-≡-projT₂ {an S (α₁ • α₃)} {an D (α₂ • α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (α₁ • α₃)} {an S (α₂ • α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = refl
-- is-≡-projT₂ {an D (α₁ • α₃)} {an D (α₂ • α₄)} {wf-pair wft₁ wft₂ x x₁} {wf-pair wft₃ wft₄ x₂ x₃} = {!!}
-- is-≡-projT₂ {an a (α₁ • α₃)} {(an a₁ (α₂ ⊎ α₄))} {wf-pair wft₁ wft₂ x x₁} {wf-sum wft₃ wft₄ x₂ x₃} = {!!}
-- is-≡-projT₂ {(an a (α₁ ⊎ α₃))} {α₂} {wf-sum wft₁ wft₂ x x₁} {wft'} = {!!}
⊑-≡ : ∀ {a b : BT} → (e : a ⊑ b) → (e' : a ⊑ b) → e ≡ e'
⊑-≡ {S} {S} reflS reflS = refl
⊑-≡ {S} {D} S≤D S≤D = refl
⊑-≡ {D} {S} () e'
⊑-≡ {D} {D} reflD reflD = refl
wft-≡ : ∀ {α : AType} → (α₁ : wft α) → (α₂ : wft α) → α₁ ≡ α₂
wft-≡ wf-int wf-int = refl
wft-≡ (wf-fun wft₁ wft₂ x x₁) (wf-fun wft₃ wft₄ x₂ x₃) rewrite wft-≡ wft₁ wft₃ | wft-≡ wft₂ wft₄ | ⊑-≡ x x₂ | ⊑-≡ x₁ x₃
= refl
wft-≡ (wf-pair wft₁ wft₂ x x₁) (wf-pair wft₃ wft₄ x₂ x₃) rewrite wft-≡ wft₁ wft₃ | wft-≡ wft₂ wft₄ | ⊑-≡ x x₂ | ⊑-≡ x₁ x₃
= refl
wft-≡ (wf-sum wft₁ wft₂ x x₁) (wf-sum wft₃ wft₄ x₂ x₃) rewrite wft-≡ wft₁ wft₃ | wft-≡ wft₂ wft₄ | ⊑-≡ x x₂ | ⊑-≡ x₁ x₃
= refl
id-projT₂&Δ : {α : AType} {Δ : ACtx}
→ (wft : wft α) → (wfe : wfe Δ)
→ (id : α ∈ Δ)
→ projT₂ α wft ∈ (projΔ Δ wfe)
id-projT₂&Δ {α} {[]} wft wfe ()
id-projT₂&Δ {.x} {x ∷ Δ} wft (wf-∷ x₁ wfe) hd rewrite wft-≡ x₁ wft = hd {x = projT₂ x wft} {xs = projΔ Δ wfe}
id-projT₂&Δ {α} {x ∷ Δ} wft (wf-∷ x₁ wfe) (tl x₂) = tl (id-projT₂&Δ wft wfe x₂)
αAExp→wft : ∀ {α : AType} {Δ : ACtx} → (e : AExp Δ α) → wft α
αAExp→wft {α} {Δ} e = {!!}
projt₂ : ∀ {α : AType} {Δ : ACtx} → (wft : wft α) → (wfe : wfe Δ)
→ AExp Δ α → aexp (projΔ Δ wfe) (projT₂ α wft)
projt₂ {an x x₁} wft wfe (Var x₂) = Var (id-projT₂&Δ wft wfe x₂)
projt₂ {an S BInt} wf-int wfe (AInt .S x₁) = SInt x₁
projt₂ {an D BInt} wf-int wfe (AInt .D x₁) = DInt x₁
projt₂ {an S BInt} wf-int wfe (AAdd .S e e₁) = SAdd (projt₂ wf-int wfe e) (projt₂ wf-int wfe e₁)
projt₂ {an D BInt} wf-int wfe (AAdd .D e e₁) = DAdd (projt₂ wf-int wfe e) (projt₂ wf-int wfe e₁)
projt₂ {an S (BFun α₁ α₂)} {Δ} (wf-fun wft wft₁ x x₁) wfe (ALam .S x₂ e) = SLam (projt₂ {α₂} {α₁ ∷ Δ} wft₁ (wf-∷ wft wfe) e)
projt₂ {an D (BFun α₁ α₂)} {Δ} (wf-fun wft wft₁ x x₁) wfe (ALam .D x₂ e) =
DLam myrewrite
where myrewrite : aexp (D (γ→τ (projT₂ α₁ wft)) ∷ projΔ Δ wfe) (D (γ→τ (projT₂ α₂ wft₁)))
myrewrite rewrite (cong₂ aexp (cong₂ (_∷_) {D (γ→τ (projT₂ α₁ wft))} {projT₂ α₁ wft} {projΔ Δ wfe} {projΔ Δ wfe}
(eqDγ→τprojT₂ {α₁} {wft} x) refl) (eqDγ→τprojT₂ {α₂} {wft₁} x₁))
= projt₂ {α₂} {α₁ ∷ Δ} wft₁ (wf-∷ wft wfe) e
projt₂ {an x x₁} wft wfe (AApp {α₁} S (wf-fun x₂ x₃ x₄ x₅) e e₁) rewrite sym (wft-≡ x₃ wft)
= SApp {γ₁ = (projT₂ α₁ x₂)} (projt₂ (wf-fun x₂ x₃ x₄ x₅) wfe e) (projt₂ x₂ wfe e₁)
projt₂ {an S x₁} wft wfe (AApp D (wf-fun x₂ x₃ x ()) e e₁)
projt₂ {an D x₁} wft wfe (AApp {an S x₂} D (wf-fun x₃ x₄ () x₅) e e₁)
projt₂ {an D x₁} {Δ} wft wfe (AApp {an D x₂} D (wf-fun x₃ x₄ x x₅) e e₁)
rewrite sym (wft-≡ x₄ wft)
= myrewrite'
where myrewrite' : aexp (projΔ Δ wfe) (projT₂ (an D x₁) x₄)
myrewrite' rewrite sym (cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {an D x₁} {x₄} x₅))
= DApp (projt₂ (wf-fun x₃ x₄ x x₅) wfe e) myrewrite
where myrewrite : aexp (projΔ Δ wfe) (D (γ→τ (projT₂ (an D x₂) x₃)))
myrewrite rewrite cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {an D x₂} {x₃} x)
= projt₂ x₃ wfe e₁
projt₂ {an S (α₁ • α₂)} (wf-pair wft wft₁ x x₁) wfe (APair .S x₂ e e₁) = projt₂ wft wfe e , projt₂ wft₁ wfe e₁
projt₂ {an D (α₁ • α₂)} {Δ} (wf-pair wft wft₁ x x₁) wfe (APair .D x₂ e e₁)
= myrewrite1 ḋ myrewrite2
where myrewrite1 : aexp (projΔ Δ wfe) (D (γ→τ (projT₂ α₁ wft)))
myrewrite1 rewrite cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {α₁} {wft} x)
= projt₂ wft wfe e
myrewrite2 : aexp (projΔ Δ wfe) (D (γ→τ (projT₂ α₂ wft₁)))
myrewrite2 rewrite cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {α₂} {wft₁} x₁)
= projt₂ wft₁ wfe e₁
projt₂ {an S (α₁ ⊎ α₂)} (wf-sum wft wft₁ x x₁) wfe (ATl .S x₂ e) = STl (projt₂ wft wfe e)
projt₂ {an D (α₁ ⊎ α₂)} {Δ} (wf-sum wft wft₁ x x₁) wfe (ATl .D x₂ e)
= DTl myrewrite
where myrewrite : aexp (projΔ Δ wfe) (D (γ→τ (projT₂ α₁ wft)))
myrewrite rewrite cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {α₁} {wft} x)
= projt₂ wft wfe e
projt₂ {an S (α₁ ⊎ α₂)} (wf-sum wft wft₁ x x₁) wfe (ATr .S x₂ e) = STr (projt₂ wft₁ wfe e)
projt₂ {an D (α₁ ⊎ α₂)} {Δ} (wf-sum wft wft₁ x x₁) wfe (ATr .D x₂ e)
= DTr myrewrite
where myrewrite : aexp (projΔ Δ wfe) (D (γ→τ (projT₂ α₂ wft₁)))
myrewrite rewrite cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {α₂} {wft₁} x₁)
= projt₂ wft₁ wfe e
projt₂ {an x x₁} wft wfe (ACase {α₁} {α₂} {.(an x x₁)} {S} x₂ e e₁ e₂) with αAExp→wft e
projt₂ {an x₂ x₃} wft wfe (ACase {α₁} {α₂} {.(an x₂ x₃)} {S} x₄ e e₁ e₂) | wf-sum WFT WFT₁ x x₁
= SCase {γ₁ = projT₂ α₁ WFT} {γ₂ = projT₂ α₂ WFT₁}
{γ₃ = projT₂ (an x₂ x₃) wft} (projt₂ (wf-sum WFT WFT₁ x x₁) wfe e) (projt₂ wft (wf-∷ WFT wfe) e₁) (projt₂ wft (wf-∷ WFT₁ wfe) e₂)
projt₂ {an S x₁} wft wfe (ACase {α₁} {α₂} {.(an S x₁)} {D} () e e₁ e₂)
projt₂ {an D x₁} wft wfe (ACase {α₁} {α₂} {.(an D x₁)} {D} x₂ e e₁ e₂) with αAExp→wft e
projt₂ {an D x₂} {Δ} wft wfe (ACase {α₁} {α₂} {.(an D x₂)} {D} x₃ e e₁ e₂) | wf-sum WFT WFT₁ x x₁
= myrewrite
where myrewrite : aexp (projΔ Δ wfe) (projT₂ (an D x₂) wft)
myrewrite rewrite sym (cong₂ aexp {(projΔ Δ wfe)} {(projΔ Δ wfe)} refl (eqDγ→τprojT₂ {an D x₂} {wft} x₃))
= DCase (projt₂ (wf-sum WFT WFT₁ x x₁) wfe e) myrewrite1 myrewrite2
where myrewrite1 : aexp (D (γ→τ (projT₂ α₁ WFT)) ∷ projΔ Δ wfe) (D (γ→τ (projT₂ (an D x₂) wft)))
myrewrite1 rewrite (cong₂ aexp (cong₂ (_∷_) {D (γ→τ (projT₂ α₁ WFT))} {projT₂ α₁ WFT} {projΔ Δ wfe} {projΔ Δ wfe}
(eqDγ→τprojT₂ {α₁} {WFT} x) refl) (eqDγ→τprojT₂ {an D x₂} {wft} x₃))
= projt₂ wft (wf-∷ WFT wfe) e₁
myrewrite2 : aexp (D (γ→τ (projT₂ α₂ WFT₁)) ∷ projΔ Δ wfe) (D (γ→τ (projT₂ (an D x₂) wft)))
myrewrite2 rewrite (cong₂ aexp (cong₂ (_∷_) {D (γ→τ (projT₂ α₂ WFT₁))} {projT₂ α₂ WFT₁} {projΔ Δ wfe} {projΔ Δ wfe}
(eqDγ→τprojT₂ {α₂} {WFT₁} x₁) refl) (eqDγ→τprojT₂ {an D x₂} {wft} x₃))
= projt₂ wft (wf-∷ WFT₁ wfe) e₂
projt₂ {an D x₁} wft wfe (Lift x e) = {!!}
| {
"alphanum_fraction": 0.4597405122,
"avg_line_length": 47.0915331808,
"ext": "agda",
"hexsha": "83139cfb6b550c141286d65fa08f15fee6c8d0e2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "luminousfennell/polybta",
"max_forks_repo_path": "BTA10.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "luminousfennell/polybta",
"max_issues_repo_path": "BTA10.agda",
"max_line_length": 146,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "luminousfennell/polybta",
"max_stars_repo_path": "BTA10.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-15T04:35:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-15T04:35:29.000Z",
"num_tokens": 19102,
"size": 41158
} |
{-# OPTIONS --prop --rewriting #-}
open import Examples.Sorting.Sequential.Comparable
module Examples.Sorting.Sequential.MergeSort (M : Comparable) where
open Comparable M
open import Examples.Sorting.Sequential.Core M
open import Calf costMonoid
open import Calf.Types.Bool
open import Calf.Types.Nat
open import Calf.Types.List
open import Calf.Types.Eq
open import Calf.Types.Bounded costMonoid
open import Calf.Types.BigO costMonoid
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning)
open import Data.Product using (_×_; _,_; ∃)
open import Data.Sum using (inj₁; inj₂)
open import Function
open import Data.Nat as Nat using (ℕ; zero; suc; z≤n; s≤s; _+_; _*_; ⌊_/2⌋; ⌈_/2⌉)
import Data.Nat.Properties as N
open import Data.Nat.Square
open import Data.Nat.Log2
open import Examples.Sorting.Sequential.MergeSort.Split M public
open import Examples.Sorting.Sequential.MergeSort.Merge M public
sort/clocked : cmp (Π nat λ _ → Π (list A) λ _ → F (list A))
sort/clocked zero l = ret l
sort/clocked (suc k) l =
bind (F (list A)) (split l) λ (l₁ , l₂) →
bind (F (list A)) (sort/clocked k l₁) λ l₁' →
bind (F (list A)) (sort/clocked k l₂) λ l₂' →
merge (l₁' , l₂')
sort/clocked/correct : ∀ k l → ⌈log₂ length l ⌉ Nat.≤ k → SortResult (sort/clocked k) l
sort/clocked/correct zero l h u = l , refl , refl , short-sorted (⌈log₂n⌉≡0⇒n≤1 (N.n≤0⇒n≡0 h))
sort/clocked/correct (suc k) l h u =
let (l₁ , l₂ , ≡ , length₁ , length₂ , ↭) = split/correct l u in
let (l₁' , ≡₁ , ↭₁ , sorted₁) = sort/clocked/correct k l₁ (
let open ≤-Reasoning in
begin
⌈log₂ length l₁ ⌉
≡⟨ Eq.cong ⌈log₂_⌉ length₁ ⟩
⌈log₂ ⌊ length l /2⌋ ⌉
≤⟨ log₂-mono (N.⌊n/2⌋≤⌈n/2⌉ (length l)) ⟩
⌈log₂ ⌈ length l /2⌉ ⌉
≤⟨ log₂-suc (length l) h ⟩
k
∎
) u in
let (l₂' , ≡₂ , ↭₂ , sorted₂) = sort/clocked/correct k l₂ (
let open ≤-Reasoning in
begin
⌈log₂ length l₂ ⌉
≡⟨ Eq.cong ⌈log₂_⌉ length₂ ⟩
⌈log₂ ⌈ length l /2⌉ ⌉
≤⟨ log₂-suc (length l) h ⟩
k
∎
) u in
let (l' , ≡' , h-sorted) = merge/correct l₁' l₂' u
(↭' , sorted) = h-sorted sorted₁ sorted₂
in
l' , (
let open ≡-Reasoning in
begin
sort/clocked (suc k) l
≡⟨⟩
(bind (F (list A)) (split l) λ (l₁ , l₂) →
bind (F (list A)) (sort/clocked k l₁) λ l₁' →
bind (F (list A)) (sort/clocked k l₂) λ l₂' →
merge (l₁' , l₂'))
≡⟨ Eq.cong (λ e → bind (F (list A)) e _) ≡ ⟩
(bind (F (list A)) (sort/clocked k l₁) λ l₁' →
bind (F (list A)) (sort/clocked k l₂) λ l₂' →
merge (l₁' , l₂'))
≡⟨ Eq.cong (λ e → bind (F (list A)) e λ l₁' → bind (F (list A)) (sort/clocked k l₂) _) ≡₁ ⟩
(bind (F (list A)) (sort/clocked k l₂) λ l₂' →
merge (l₁' , l₂'))
≡⟨ Eq.cong (λ e → bind (F (list A)) e λ l₂' → merge (l₁' , l₂')) ≡₂ ⟩
merge (l₁' , l₂')
≡⟨ ≡' ⟩
ret l'
∎
) , (
let open PermutationReasoning in
begin
l
↭⟨ ↭ ⟩
l₁ ++ l₂
↭⟨ ++⁺-↭ ↭₁ ↭₂ ⟩
l₁' ++ l₂'
↭⟨ ↭' ⟩
l'
∎
) , sorted
sort/clocked/cost : cmp (Π nat λ _ → Π (list A) λ _ → cost)
sort/clocked/cost zero l = zero
sort/clocked/cost (suc k) l =
bind cost (split l) λ (l₁ , l₂) → split/cost l +
bind cost (sort/clocked k l₁) λ l₁' → sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂')
sort/clocked/cost/closed : cmp (Π nat λ _ → Π (list A) λ _ → cost)
sort/clocked/cost/closed k l = k * length l
sort/clocked/cost≡sort/clocked/cost/closed : ∀ k l → ⌈log₂ length l ⌉ Nat.≤ k → ◯ (sort/clocked/cost k l ≡ sort/clocked/cost/closed k l)
sort/clocked/cost≡sort/clocked/cost/closed zero l h u = refl
sort/clocked/cost≡sort/clocked/cost/closed (suc k) l h u =
let (l₁ , l₂ , ≡ , length₁ , length₂ , ↭) = split/correct l u in
let h₁ : ⌈log₂ length l₁ ⌉ Nat.≤ k
h₁ =
let open ≤-Reasoning in
begin
⌈log₂ length l₁ ⌉
≡⟨ Eq.cong ⌈log₂_⌉ length₁ ⟩
⌈log₂ ⌊ length l /2⌋ ⌉
≤⟨ log₂-mono (N.⌊n/2⌋≤⌈n/2⌉ (length l)) ⟩
⌈log₂ ⌈ length l /2⌉ ⌉
≤⟨ log₂-suc (length l) h ⟩
k
∎
h₂ : ⌈log₂ length l₂ ⌉ Nat.≤ k
h₂ =
let open ≤-Reasoning in
begin
⌈log₂ length l₂ ⌉
≡⟨ Eq.cong ⌈log₂_⌉ length₂ ⟩
⌈log₂ ⌈ length l /2⌉ ⌉
≤⟨ log₂-suc (length l) h ⟩
k
∎
in
let (l₁' , ≡₁ , ↭₁ , sorted₁) = sort/clocked/correct k l₁ h₁ u in
let (l₂' , ≡₂ , ↭₂ , sorted₂) = sort/clocked/correct k l₂ h₂ u in
let open ≡-Reasoning in
begin
sort/clocked/cost (suc k) l
≡⟨⟩
(bind cost (split l) λ (l₁ , l₂) → split/cost l +
bind cost (sort/clocked k l₁) λ l₁' → sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡⟨ Eq.cong (λ e → bind cost e _) (≡) ⟩
(split/cost l +
bind cost (sort/clocked k l₁) λ l₁' → sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡⟨⟩
(0 +
bind cost (sort/clocked k l₁) λ l₁' → sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡⟨ N.+-identityˡ _ ⟩
(bind cost (sort/clocked k l₁) λ l₁' → sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡⟨
Eq.cong
(λ e →
bind cost e λ l₁' → sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡₁
⟩
(sort/clocked/cost k l₁ +
bind cost (sort/clocked k l₂) λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡⟨
Eq.cong
(λ e →
sort/clocked/cost k l₁ +
bind cost e λ l₂' → sort/clocked/cost k l₂ +
merge/cost/closed (l₁' , l₂'))
≡₂
⟩
sort/clocked/cost k l₁ + (sort/clocked/cost k l₂ + merge/cost/closed (l₁' , l₂'))
≡˘⟨ N.+-assoc (sort/clocked/cost k l₁) (sort/clocked/cost k l₂) (merge/cost/closed (l₁' , l₂')) ⟩
(sort/clocked/cost k l₁ + sort/clocked/cost k l₂) + merge/cost/closed (l₁' , l₂')
≡⟨
Eq.cong (_+ merge/cost/closed (l₁' , l₂')) (
Eq.cong₂ _+_
(sort/clocked/cost≡sort/clocked/cost/closed k l₁ h₁ u)
(sort/clocked/cost≡sort/clocked/cost/closed k l₂ h₂ u)
)
⟩
(sort/clocked/cost/closed k l₁ + sort/clocked/cost/closed k l₂) + merge/cost/closed (l₁' , l₂')
≡⟨⟩
(sort/clocked/cost/closed k l₁ + sort/clocked/cost/closed k l₂) + (length l₁' + length l₂')
≡˘⟨
Eq.cong ((sort/clocked/cost/closed k l₁ + sort/clocked/cost/closed k l₂) +_) (
Eq.cong₂ _+_ (↭-length ↭₁) (↭-length ↭₂)
)
⟩
(sort/clocked/cost/closed k l₁ + sort/clocked/cost/closed k l₂) + (length l₁ + length l₂)
≡⟨⟩
(k * length l₁ + k * length l₂) + (length l₁ + length l₂)
≡⟨
Eq.cong₂
(λ n₁ n₂ → k * n₁ + k * n₂ + (n₁ + n₂))
length₁
length₂
⟩
(k * ⌊ length l /2⌋ + k * ⌈ length l /2⌉) + (⌊ length l /2⌋ + ⌈ length l /2⌉)
≡⟨ N.+-comm _ (⌊ length l /2⌋ + ⌈ length l /2⌉) ⟩
(⌊ length l /2⌋ + ⌈ length l /2⌉) + (k * ⌊ length l /2⌋ + k * ⌈ length l /2⌉)
≡˘⟨ Eq.cong ((⌊ length l /2⌋ + ⌈ length l /2⌉) +_) (N.*-distribˡ-+ k _ _) ⟩
(⌊ length l /2⌋ + ⌈ length l /2⌉) + k * (⌊ length l /2⌋ + ⌈ length l /2⌉)
≡⟨⟩
suc k * (⌊ length l /2⌋ + ⌈ length l /2⌉)
≡⟨ Eq.cong (suc k *_) (N.⌊n/2⌋+⌈n/2⌉≡n (length l)) ⟩
suc k * length l
∎
sort/clocked≤sort/clocked/cost : ∀ k l → IsBounded (list A) (sort/clocked k l) (sort/clocked/cost k l)
sort/clocked≤sort/clocked/cost zero l = bound/ret
sort/clocked≤sort/clocked/cost (suc k) l =
bound/bind _ _ (split≤split/cost l) λ (l₁ , l₂) →
bound/bind _ _ (sort/clocked≤sort/clocked/cost k l₁) λ l₁' →
bound/bind _ _ (sort/clocked≤sort/clocked/cost k l₂) λ l₂' →
merge≤merge/cost/closed (l₁' , l₂')
sort/clocked≤sort/clocked/cost/closed : ∀ k l → ⌈log₂ length l ⌉ Nat.≤ k → IsBounded (list A) (sort/clocked k l) (sort/clocked/cost/closed k l)
sort/clocked≤sort/clocked/cost/closed k l h = bound/relax (λ u → N.≤-reflexive (sort/clocked/cost≡sort/clocked/cost/closed k l h u)) (sort/clocked≤sort/clocked/cost k l)
sort/depth : cmp (Π (list A) λ _ → meta ℕ)
sort/depth l = ⌈log₂ length l ⌉
sort : cmp (Π (list A) λ _ → F (list A))
sort l = sort/clocked (sort/depth l) l
sort/correct : IsSort sort
sort/correct l = sort/clocked/correct (sort/depth l) l N.≤-refl
sort/cost : cmp (Π (list A) λ _ → cost)
sort/cost l = sort/clocked/cost (sort/depth l) l
sort/cost/closed : cmp (Π (list A) λ _ → cost)
sort/cost/closed l = sort/clocked/cost/closed (sort/depth l) l
sort≤sort/cost : ∀ l → IsBounded (list A) (sort l) (sort/cost l)
sort≤sort/cost l = sort/clocked≤sort/clocked/cost (sort/depth l) l
sort≤sort/cost/closed : ∀ l → IsBounded (list A) (sort l) (sort/cost/closed l)
sort≤sort/cost/closed l = sort/clocked≤sort/clocked/cost/closed (sort/depth l) l N.≤-refl
sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n * ⌈log₂ n ⌉)
sort/asymptotic = 0 ≤n⇒f[n]≤g[n]via λ l _ →
bound/relax
(λ u → ≤-reflexive (N.*-comm ⌈log₂ length l ⌉ (length l)))
(sort≤sort/cost/closed l)
| {
"alphanum_fraction": 0.5396088503,
"avg_line_length": 38.7892720307,
"ext": "agda",
"hexsha": "c661568b6d3839bf946bbe1ba87469ecce851e39",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Examples/Sorting/Sequential/MergeSort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Examples/Sorting/Sequential/MergeSort.agda",
"max_line_length": 169,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Sorting/Sequential/MergeSort.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 4030,
"size": 10124
} |
module Data.Union.Relation.Binary.Subtype.Instances where
open import Data.List using (List)
open import Data.List.Relation.Binary.Subset.Propositional.Instances using (⦅_⊆_⦆; [_])
open import Data.Union using (Union)
open import Data.Union.Relation.Binary.Subtype
using (_≼_; _,_⊢_≼_; refl; trans; generalize; function)
open import Level using (Level; _⊔_)
private
variable
a b c d f : Level
A : Set a
B : Set b
C : Set c
D : Set d
F : A → Set f
ts ts′ : List A
-- ----------------------------------------------------------------------
-- Wrapped subtypes
infix 4 ⦅_≼_⦆ ⦅_,_⊢_≼_⦆
data ⦅_≼_⦆ {a b} : Set a → Set b → Set (a ⊔ b) where
[_] : A ≼ B → ⦅ A ≼ B ⦆
⦅_,_⊢_≼_⦆ : (A : Set a) → (B : A → Set b) → List A → List A → Set (a ⊔ b)
⦅ A , B ⊢ ts ≼ ts′ ⦆ = ⦅ Union A B ts ≼ Union A B ts′ ⦆
proj : ⦅ A ≼ B ⦆ → A ≼ B
proj [ A≼B ] = A≼B
⊢proj : ⦅ A , F ⊢ ts ≼ ts′ ⦆ → A , F ⊢ ts ≼ ts′
⊢proj [ A,F⊢ts≼ts′ ] = A,F⊢ts≼ts′
-- ----------------------------------------------------------------------
-- Instances
instance
⦃refl⦄ : ⦅ A ≼ A ⦆
⦃refl⦄ = [ refl ]
-- Removed since the transitivity of ⊆ provides this
-- Also now allows for syntax directed instance search :)
-- ⦃trans⦄ : ⦃ ⦅ A ≼ B ⦆ ⦄ → ⦃ ⦅ B ≼ C ⦆ ⦄ → ⦅ A ≼ C ⦆
-- ⦃trans⦄ ⦃ [ A≼B ] ⦄ ⦃ [ B≼C ] ⦄ = [ trans A≼B B≼C ]
⦃generalize⦄ : ⦃ ⦅ ts ⊆ ts′ ⦆ ⦄ → ⦅ A , F ⊢ ts ≼ ts′ ⦆
⦃generalize⦄ ⦃ [ ts⊆ts′ ] ⦄ = [ generalize ts⊆ts′ ]
⦃function⦄ : ⦃ ⦅ C ≼ A ⦆ ⦄ → ⦃ ⦅ B ≼ D ⦆ ⦄ → ⦅ (A → B) ≼ (C → D) ⦆
⦃function⦄ ⦃ [ C≼A ] ⦄ ⦃ [ B≼D ] ⦄ = [ function C≼A B≼D ]
-- ----------------------------------------------------------------------
-- Coercion using instance search
⌊_⌋ : ⦃ ⦅ A ≼ B ⦆ ⦄ → A → B
⌊_⌋ ⦃ [ A≼B ] ⦄ A = A≼B A | {
"alphanum_fraction": 0.4436133487,
"avg_line_length": 27.5873015873,
"ext": "agda",
"hexsha": "cfaab33cbb5977792664306d088dd285beb6bc8b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "johnyob/agda-union",
"max_forks_repo_path": "src/Data/Union/Relation/Binary/Subtype/Instances.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "johnyob/agda-union",
"max_issues_repo_path": "src/Data/Union/Relation/Binary/Subtype/Instances.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "johnyob/agda-union",
"max_stars_repo_path": "src/Data/Union/Relation/Binary/Subtype/Instances.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 836,
"size": 1738
} |
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ
postulate
I : Set
U : I → Set
El : ∀ {i} → U i → Set
Ctxt : Set
Env : Ctxt → Set
Type : Ctxt → Set
Type Γ = Σ I λ i → Env Γ → U i
Value : (Γ : Ctxt) → Type Γ → Set
Value Γ σ = (γ : Env Γ) → El (proj₂ σ γ)
_/id : ∀ {Γ} → Type Γ → Type Γ
(i , σ) /id = i , σ
data [Type] : Set where
[_] : ∀ {Γ} → Type Γ → [Type]
_≅-Type_ : ∀ {Γ} (σ₁ σ₂ : Type Γ) → Set
σ₁ ≅-Type σ₂ = [ σ₁ ] ≡ [ σ₂ ]
data [Value] : Set where
[_] : ∀ {Γ σ} → Value Γ σ → [Value]
_≅-Value_ : ∀ {Γ σ} (v₁ v₂ : Value Γ σ) → Set
v₁ ≅-Value v₂ = [Value].[ v₁ ] ≡ [ v₂ ]
Foo : ∀ {Γ} {σ₁ σ₂ : Type Γ} {v : Value Γ (σ₁ /id)} →
σ₁ ≅-Type σ₂ → v ≅-Value v → Set₁
Foo refl refl = Set
| {
"alphanum_fraction": 0.483490566,
"avg_line_length": 19.7209302326,
"ext": "agda",
"hexsha": "f253ae6615d7c2eefb4b7f9dfb0258f474bb7ed4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1872.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1872.agda",
"max_line_length": 53,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1872.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 399,
"size": 848
} |
{-# OPTIONS --rewriting #-}
module NewEquations where
open import Common.Prelude hiding (map; _++_)
open import Common.Equality
infixr 5 _++_
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)
fold : ∀ {A B : Set} → (A → B → B) → B → List A → B
fold f v [] = v
fold f v (x ∷ xs) = f x (fold f v xs)
++-[] : ∀ {A} {xs : List A} → xs ++ [] ≡ xs
++-[] {xs = []} = refl
++-[] {xs = x ∷ xs} = cong (_∷_ x) ++-[]
++-assoc : ∀ {A} {xs ys zs : List A} → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
++-assoc {xs = []} = refl
++-assoc {xs = x ∷ xs} = cong (_∷_ x) (++-assoc {xs = xs})
map-id : ∀ {A} {xs : List A} → map (λ x → x) xs ≡ xs
map-id {xs = []} = refl
map-id {xs = x ∷ xs} = cong (_∷_ x) map-id
map-fuse : ∀ {A B C} {f : B → C} {g : A → B} {xs : List A} → map f (map g xs) ≡ map (λ x → f (g x)) xs
map-fuse {xs = []} = refl
map-fuse {xs = x ∷ xs} = cong (_∷_ _) map-fuse
map-++ : ∀ {A B} {f : A → B} {xs ys : List A} → map f (xs ++ ys) ≡ (map f xs) ++ (map f ys)
map-++ {xs = []} = refl
map-++ {xs = x ∷ xs} = cong (_∷_ _) (map-++ {xs = xs})
fold-map : ∀ {A B C} {f : A → B} {c : B → C → C} {n : C} {xs : List A} →
fold c n (map f xs) ≡ fold (λ x → c (f x)) n xs
fold-map {xs = []} = refl
fold-map {c = c} {xs = x ∷ xs} = cong (c _) (fold-map {xs = xs})
fold-++ : ∀ {A B} {c : A → B → B} {n : B} {xs ys : List A} →
fold c n (xs ++ ys) ≡ fold c (fold c n ys) xs
fold-++ {xs = []} = refl
fold-++ {c = c} {xs = x ∷ xs} = cong (c _) (fold-++ {xs = xs})
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE ++-[] #-}
{-# REWRITE ++-assoc #-}
{-# REWRITE map-id #-}
{-# REWRITE map-fuse #-}
{-# REWRITE map-++ #-}
{-# REWRITE fold-map #-}
{-# REWRITE fold-++ #-}
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
swap : ∀ {A B} → A × B → B × A
swap (x , y) = y , x
test₁ : ∀ {A B} {xs : List (A × B)} → map swap (map swap xs) ≡ xs
test₁ = refl
| {
"alphanum_fraction": 0.4460325283,
"avg_line_length": 28.1805555556,
"ext": "agda",
"hexsha": "751fa62b7188341f9f6e5b421f846c6ab9121723",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/NewEquations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/NewEquations.agda",
"max_line_length": 102,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/NewEquations.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 871,
"size": 2029
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.NConnected
open import lib.types.Nat
open import lib.types.Subtype
open import lib.types.Truncation
-- classifying types of automorphism groups of types
module lib.types.BAut where
BAut : ∀ {i} → Type i → Type (lsucc i)
BAut {i} A = Σ (Type i) λ X → Trunc -1 (A == X)
BAut-prop : ∀ {i} (A : Type i) → SubtypeProp (Type i) (lsucc i)
BAut-prop A = ((λ X → Trunc -1 (A == X)) , (λ X → Trunc-level))
pBAut : ∀ {i} → Type i → Ptd (lsucc i)
de⊙ (pBAut A) = BAut A
pt (pBAut A) = A , [ idp ]
BAut-trunc-path : ∀ {i} (A X : Type i) → (tp : Trunc -1 (A == X))
→ Trunc -1 ((A , [ idp ]) == (X , tp) :> BAut A)
BAut-trunc-path {i} A X = Trunc-elim λ p → [ pair= p prop-has-all-paths-↓ ]
BAut-conn : ∀ {i} (A : Type i) → is-connected 0 (BAut A)
fst (has-level-apply (BAut-conn A)) = [ pt (pBAut A) ]
snd (has-level-apply (BAut-conn A)) = Trunc-elim (λ { (X , tp) → <– (=ₜ-equiv [ A , [ idp ] ] [ X , tp ])
(BAut-trunc-path A X tp) })
| {
"alphanum_fraction": 0.545210385,
"avg_line_length": 36.0322580645,
"ext": "agda",
"hexsha": "e6ca12224092ab74eadd52bd9b57576b71fddbd8",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/BAut.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/BAut.agda",
"max_line_length": 105,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/BAut.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 403,
"size": 1117
} |
{-# OPTIONS --without-K #-}
module GroupoidStructure {a} {A : Set a} where
open import PathOperations
open import Types
p·p⁻¹ : {a b : A} (p : a ≡ b) → p · p ⁻¹ ≡ refl
p·p⁻¹ = J (λ _ _ p → p · p ⁻¹ ≡ refl) (λ _ → refl) _ _
p⁻¹·p : {a b : A} (p : a ≡ b) → p ⁻¹ · p ≡ refl
p⁻¹·p = J (λ _ _ p → p ⁻¹ · p ≡ refl) (λ _ → refl) _ _
p·id : {a b : A} (p : a ≡ b) → p · refl ≡ p
p·id = J (λ _ _ p → p · refl ≡ p) (λ _ → refl) _ _
id·p : {a b : A} (p : a ≡ b) → refl · p ≡ p
id·p _ = refl
p·q·r : {a b c d : A} (p : a ≡ b) (q : b ≡ c) (r : c ≡ d) →
p · (q · r) ≡ (p · q) · r
p·q·r {c = c} {d = d} = J
(λ _ b p → (q : b ≡ c) (r : c ≡ d) → p · q · r ≡ (p · q) · r)
(λ b → J
(λ _ c q → (r : c ≡ d) → refl · q · r ≡ (refl · q) · r)
(λ _ _ → refl) _ _)
_ _
| {
"alphanum_fraction": 0.4005235602,
"avg_line_length": 28.2962962963,
"ext": "agda",
"hexsha": "f7908c7e69baed5ef87e5201c977ab8d9b21ed8b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/GroupoidStructure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/GroupoidStructure.agda",
"max_line_length": 63,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/GroupoidStructure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 411,
"size": 764
} |
------------------------------------------------------------------------
-- An example of how Abstract-binding-tree can be used
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module README.Abstract-binding-tree where
open import Dec
open import Equality.Path
open import Prelude as P hiding (swap; [_,_]; type-signature)
open import Abstract-binding-tree equality-with-paths
open import Bijection equality-with-J using (_↔_)
open import Equality.Decision-procedures equality-with-J
open import Equivalence equality-with-J using (_≃_)
open import Erased.Cubical equality-with-paths as E
open import Finite-subset.Listed equality-with-paths as L
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
as Trunc
import Nat equality-with-J as Nat
-- Sorts: expressions and statements.
Sort : Type
Sort = Bool
pattern expr = true
pattern stmt = false
-- Constructors: lambda, application and print.
data Constructor : @0 Sort → Type where
exprᶜ : Bool → Constructor expr
stmtᶜ : ⊤ → Constructor stmt
pattern lamᶜ = exprᶜ true
pattern appᶜ = exprᶜ false
pattern printᶜ = stmtᶜ tt
-- Erased equality of constructors is decidable.
_≟O_ : ∀ {@0 s} → Decidable-erased-equality (Constructor s)
exprᶜ x ≟O exprᶜ y = Dec-Erased-map
(record { to = cong exprᶜ
; from = cong (λ { (exprᶜ x) → x })
})
(Decidable-equality→Decidable-erased-equality
Bool._≟_ x y)
printᶜ ≟O printᶜ = yes [ refl ]
-- Variables are natural numbers.
Var : @0 Sort → Type
Var _ = ℕ
-- A signature.
sig : Signature lzero
sig .Signature.Sort = Sort
sig .Signature.Op = Constructor
sig .Signature.domain lamᶜ = (expr ∷ [] , expr) ∷ []
sig .Signature.domain appᶜ = ([] , expr) ∷ ([] , expr) ∷ []
sig .Signature.domain printᶜ = ([] , expr) ∷ []
sig .Signature.Var = Var
sig .Signature._≟O_ = _≟O_
sig .Signature._≟S_ =
Decidable-equality→Decidable-erased-equality Bool._≟_
sig .Signature._≟V_ =
Decidable-equality→Decidable-erased-equality Nat._≟_
sig .Signature.fresh {s = s} xs = $⟨ L.fresh (L.map proj₂ xs) ⟩
(∃ λ n → n ∉ L.map proj₂ xs) ↝⟨ Σ-map id [_]→ ⟩
(∃ λ n → Erased (n ∉ L.map proj₂ xs)) ↝⟨ (∃-cong λ n → E.map (
n ∉ L.map proj₂ xs ↔⟨ ¬-cong ext ∈map≃ ⟩
¬ ∥ (∃ λ x → x ∈ xs × proj₂ x ≡ n) ∥ ↔⟨ ¬∥∥↔¬ ⟩
¬ (∃ λ x → x ∈ xs × proj₂ x ≡ n) ↝⟨ (λ hyp ∈xs → hyp (_ , ∈xs , refl)) ⟩□
(s , n) ∉ xs □)) ⟩□
(∃ λ n → Erased ((s , n) ∉ xs)) □
open Signature sig public
hiding (Sort; Var; _≟O_)
renaming (var to varᶜ)
private
variable
@0 s : Sort
@0 xs : Vars
@0 A : Type
@0 x : A
-- Pattern synonyms.
pattern varᵖ x wf = varᶜ , x , [ wf ]
pattern lamˢᵖ tˢ =
op lamᶜ (cons (cons (nil tˢ)) nil)
pattern lamᵖ x tˢ t wf =
lamˢᵖ tˢ
, ((x , t) , lift tt)
, [ wf , lift tt ]
pattern appˢᵖ t₁ˢ t₂ˢ =
op appᶜ (cons (nil t₁ˢ) (cons (nil t₂ˢ) nil))
pattern appᵖ t₁ˢ t₂ˢ t₁ t₂ wf₁ wf₂ =
appˢᵖ t₁ˢ t₂ˢ
, (t₁ , t₂ , lift tt)
, [ wf₁ , wf₂ , lift tt ]
pattern printˢᵖ tˢ =
op printᶜ (cons (nil tˢ) nil)
pattern printᵖ tˢ t wf =
printˢᵖ tˢ
, (t , lift tt)
, [ wf , lift tt ]
-- Some (more or less) smart constructors.
var : ∀ {s} (x : Var s) → Term ((s , x) ∷ xs) s
var x = varᵖ x (≡→∈∷ refl)
lam :
(x : Var expr) →
Term ((expr , x) ∷ xs) expr →
Term xs expr
lam x (tˢ , t , [ wf ]) =
lamᵖ x tˢ t (λ _ _ → rename₁-Wf tˢ wf)
app : Term xs expr → Term xs expr → Term xs expr
app (t₁ˢ , t₁ , [ wf₁ ]) (t₂ˢ , t₂ , [ wf₂ ]) =
appᵖ t₁ˢ t₂ˢ t₁ t₂ wf₁ wf₂
print : Term xs expr → Term xs stmt
print (tˢ , t , [ wf ]) = printᵖ tˢ t wf
-- A representation of "λ x. x".
λx→x : Term [] expr
λx→x = lam 0 (var 0)
-- A representation of "λ x y. y y".
λxy→yy : Term [] expr
λxy→yy = lam 1 $ lam 2 $ app (var 2) (var 2)
-- Two representations of "λ x y. x y".
private
λxy→xy : ℕ → ℕ → Term [] expr
λxy→xy x y =
lam x $ lam y $ app (weaken (λ _ → ∈→∈∷) (var x)) (var y)
λxy→xy₁ : Term [] expr
λxy→xy₁ = λxy→xy 2 1
λxy→xy₂ : Term [] expr
λxy→xy₂ = λxy→xy 1 2
-- A representation of "print (λ x y. x y)".
print[λxy→xy] : Term [] stmt
print[λxy→xy] = print λxy→xy₁
-- A third representation of "λ x y. x y".
λxy→xy₃ : Term [] expr
λxy→xy₃ = weaken lemma λxy→xy₁ [ 0 ← λx→x ]
where
@0 lemma : _
lemma =
from-⊎ $
subset?
(decidable→decidable-∥∥
(Decidable-erased-equality≃Decidable-equality _ _≟∃V_))
[]
((expr , 0) ∷ [])
-- The second and third representations of "λ x y. x y" are equal (in
-- erased contexts).
@0 _ : λxy→xy₂ ≡ λxy→xy₃
_ = Wf-proof-irrelevant
-- An interpreter that uses fuel.
eval : ∀ {xs} → ℕ → Term xs s → Term xs s
eval zero t = t
eval (suc n) t = eval′ t
where
apply : ∀ {xs} → @0 s ≡ expr → Term xs s → Term xs s → Term xs s
apply _ (lamᵖ x t₁ˢ′ t₁′ wf₁′) t₂′ =
eval n (subst-Term x t₂′
( t₁ˢ′
, t₁′
, [ body-Wf t₁ˢ′ wf₁′ ]
))
apply s≡expr t₁′ t₂′ =
substᴱ (Term _) (sym s≡expr) $
app (substᴱ (Term _) s≡expr t₁′) (substᴱ (Term _) s≡expr t₂′)
eval′ : ∀ {xs} → Term xs s → Term xs s
eval′ t@(varᵖ _ _) = t
eval′ t@(lamᵖ _ _ _ _) = t
eval′ (printᵖ tˢ t wf) = print (eval′ (tˢ , t , [ wf ]))
eval′ (appᵖ t₁ˢ t₂ˢ t₁ t₂ wf₁ wf₂) = apply refl
(eval′ (t₁ˢ , t₁ , [ wf₁ ]))
(eval′ (t₂ˢ , t₂ , [ wf₂ ]))
-- Simple types.
infixr 6 _⇨_
data Ty : Type where
base : Ty
_⇨_ : Ty → Ty → Ty
-- Contexts.
Ctxt : Vars → Type
Ctxt xs = Block "Ctxt" → ∀ x → x ∈ xs → Ty
private
variable
@0 σ : Ty
@0 Γ : Ctxt xs
-- Extends a context with a new variable. If the variable already
-- exists in the context, then the old binding is removed.
infixl 5 _,_⦂_
_,_⦂_ : ∀ {xs} → Ctxt xs → ∀ x → Ty → Ctxt (x ∷ xs)
(Γ , x ⦂ σ) ⊠ y y∈x∷xs =
case y ≟∃V x of λ where
(yes y≡x) → σ
(no y≢x) → Γ ⊠ y (_≃_.to (∈≢∷≃ (Stable-¬ y≢x)) y∈x∷xs)
-- A type system.
infix 4 _⊢_⦂_
data _⊢_⦂_ : Ctxt xs → Term xs s → Ty → Type where
⊢var : ∀ {s x xs} {Γ : Ctxt ((s , x) ∷ xs)} {t σ} →
t ≡ var x →
σ ≡ Γ ⊠ (s , x) (≡→∈∷ refl) →
Γ ⊢ t ⦂ σ
⊢lam : ∀ {xs} {Γ : Ctxt xs} {x t t′ σ τ} →
Γ , (_ , x) ⦂ σ ⊢ t ⦂ τ →
t′ ≡ lam x t →
Γ ⊢ t′ ⦂ σ ⇨ τ
⊢app : ∀ {xs} {Γ : Ctxt xs} {t₁ t₂ t′ σ τ} →
Γ ⊢ t₁ ⦂ σ ⇨ τ →
Γ ⊢ t₂ ⦂ σ →
t′ ≡ app t₁ t₂ →
Γ ⊢ t′ ⦂ τ
⊢print : ∀ {xs} {Γ : Ctxt xs} {t t′ σ} →
Γ ⊢ t ⦂ σ →
t′ ≡ print t →
Γ ⊢ t′ ⦂ σ
| {
"alphanum_fraction": 0.527721919,
"avg_line_length": 26.2716981132,
"ext": "agda",
"hexsha": "5bd5374b845952d3ecbed4ec6652f6d4d3ccf7ae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "README/Abstract-binding-tree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "README/Abstract-binding-tree.agda",
"max_line_length": 90,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "README/Abstract-binding-tree.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 2726,
"size": 6962
} |
module Lib.Bool where
open import Lib.Logic
data Bool : Set where
true : Bool
false : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
{-# COMPILED_DATA Bool Bool True False #-}
isTrue : Bool -> Set
isTrue true = True
isTrue false = False
isFalse : Bool -> Set
isFalse true = False
isFalse false = True
data Inspect (b : Bool) : Set where
itsTrue : .(isTrue b) -> Inspect b
itsFalse : .(isFalse b) -> Inspect b
inspect : (b : Bool) -> Inspect b
inspect true = itsTrue _
inspect false = itsFalse _
infix 5 if_then_else_
if_then_else_ : {A : Set} -> Bool -> A -> A -> A
if true then x else y = x
if false then x else y = y
not : Bool -> Bool
not true = false
not false = true
infixr 25 _&&_
infixr 22 _||_
_&&_ : Bool -> Bool -> Bool
false && y = false
true && y = y
_||_ : Bool -> Bool -> Bool
false || y = y
true || y = true
| {
"alphanum_fraction": 0.6252796421,
"avg_line_length": 17.1923076923,
"ext": "agda",
"hexsha": "d60d5585ba277bdfab5c251e73a8e702b87cd8df",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/simple-lib/Lib/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/simple-lib/Lib/Bool.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/simple-lib/Lib/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 290,
"size": 894
} |
-- Andreas, 2020-01-28, issue #4399
-- Pattern @{{_ = p}}@ should not be parsed as cubical partial split.
postulate
A : Set
data T : Set where
tt : T
f : {x : A} {{_ : T}} → Set
f ⦃ _ = tt ⦄ = A
-- Expected: Parse error
-- Not a valid named argument: _ = tt
| {
"alphanum_fraction": 0.5864661654,
"avg_line_length": 17.7333333333,
"ext": "agda",
"hexsha": "656dc0f4fbfbf171215770ee7f0783e07a9be1b0",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue4399.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4399.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4399.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 99,
"size": 266
} |
------------------------------------------------------------------------
-- A universe which includes several kinds of functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Function-universe
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq as Bijection using (_↔_; module _↔_)
open Derived-definitions-and-properties eq
open import Embedding eq as Emb using (Is-embedding; Embedding)
open import Equality.Decidable-UIP eq
open import Equality.Decision-procedures eq
open import Equivalence eq as Eq using (_≃_; module _≃_; Is-equivalence)
import Equivalence.Contractible-preimages eq as CP
open import Equivalence.Erased.Basics eq as EEq using (_≃ᴱ_)
import Equivalence.Half-adjoint eq as HA
open import Erased.Basics as E using (Erased)
open import H-level eq as H-level
open import H-level.Closure eq
open import Injection eq as Injection using (_↣_; module _↣_; Injective)
open import Logical-equivalence as L using (_⇔_; module _⇔_)
open import Nat eq hiding (_≟_)
open import Preimage eq using (_⁻¹_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Surjection eq as Surjection using (_↠_; Split-surjective)
------------------------------------------------------------------------
-- The universe
-- The universe includes implications, logical equivalences,
-- injections, embeddings, surjections, bijections, equivalences, and
-- equivalences with erased proofs.
data Kind : Type where
implication
logical-equivalence
injection
embedding
surjection
bijection
equivalence
equivalenceᴱ : Kind
-- The interpretation of the universe.
infix 0 _↝[_]_
_↝[_]_ : ∀ {ℓ₁ ℓ₂} → Type ℓ₁ → Kind → Type ℓ₂ → Type _
A ↝[ implication ] B = A → B
A ↝[ logical-equivalence ] B = A ⇔ B
A ↝[ injection ] B = A ↣ B
A ↝[ embedding ] B = Embedding A B
A ↝[ surjection ] B = A ↠ B
A ↝[ bijection ] B = A ↔ B
A ↝[ equivalence ] B = A ≃ B
A ↝[ equivalenceᴱ ] B = A ≃ᴱ B
-- Equivalences can be converted to all kinds of functions.
from-equivalence : ∀ {k a b} {A : Type a} {B : Type b} →
A ≃ B → A ↝[ k ] B
from-equivalence {implication} = _≃_.to
from-equivalence {logical-equivalence} = _≃_.logical-equivalence
from-equivalence {injection} = _≃_.injection
from-equivalence {embedding} = Emb.≃→Embedding
from-equivalence {surjection} = _≃_.surjection
from-equivalence {bijection} = _≃_.bijection
from-equivalence {equivalence} = P.id
from-equivalence {equivalenceᴱ} = EEq.≃→≃ᴱ
-- Bijections can be converted to all kinds of functions.
from-bijection : ∀ {k a b} {A : Type a} {B : Type b} →
A ↔ B → A ↝[ k ] B
from-bijection {implication} = _↔_.to
from-bijection {logical-equivalence} = _↔_.logical-equivalence
from-bijection {injection} = _↔_.injection
from-bijection {embedding} = from-equivalence ⊚ Eq.↔⇒≃
from-bijection {surjection} = _↔_.surjection
from-bijection {bijection} = P.id
from-bijection {equivalence} = Eq.↔⇒≃
from-bijection {equivalenceᴱ} = EEq.≃→≃ᴱ ⊚ Eq.↔⇒≃
-- All kinds of functions can be converted to implications.
to-implication : ∀ {k a b} {@0 A : Type a} {@0 B : Type b} →
A ↝[ k ] B → A → B
to-implication {implication} f =
f
to-implication {logical-equivalence} f =
let record { to = to } = f in to
to-implication {injection} f =
let record { to = to } = f in to
to-implication {embedding} f =
let record { to = to } = f in to
to-implication {surjection} f =
let record
{ logical-equivalence = record
{ to = to
}
} = f
in to
to-implication {bijection} f =
let record
{ surjection = record
{ logical-equivalence = record
{ to = to
}
}
} = f
in to
to-implication {equivalence} f =
let record { to = to } = f in to
to-implication {equivalenceᴱ} f =
_≃ᴱ_.to f
------------------------------------------------------------------------
-- A sub-universe of symmetric kinds of functions
data Symmetric-kind : Type where
logical-equivalence bijection equivalence equivalenceᴱ :
Symmetric-kind
⌊_⌋-sym : Symmetric-kind → Kind
⌊ logical-equivalence ⌋-sym = logical-equivalence
⌊ bijection ⌋-sym = bijection
⌊ equivalence ⌋-sym = equivalence
⌊ equivalenceᴱ ⌋-sym = equivalenceᴱ
inverse : ∀ {k a b} {A : Type a} {B : Type b} →
A ↝[ ⌊ k ⌋-sym ] B → B ↝[ ⌊ k ⌋-sym ] A
inverse {logical-equivalence} = L.inverse
inverse {bijection} = Bijection.inverse
inverse {equivalence} = Eq.inverse
inverse {equivalenceᴱ} = EEq.inverse
-- If there is a symmetric kind of function from A to B, then A and B
-- are logically equivalent.
sym→⇔ :
∀ {k a b} {A : Type a} {B : Type b} →
A ↝[ ⌊ k ⌋-sym ] B → A ⇔ B
sym→⇔ {k = logical-equivalence} = P.id
sym→⇔ {k = bijection} = from-bijection
sym→⇔ {k = equivalence} = from-equivalence
sym→⇔ {k = equivalenceᴱ} = _≃ᴱ_.logical-equivalence
------------------------------------------------------------------------
-- A sub-universe of isomorphisms
data Isomorphism-kind : Type where
bijection equivalence : Isomorphism-kind
⌊_⌋-iso : Isomorphism-kind → Kind
⌊ bijection ⌋-iso = bijection
⌊ equivalence ⌋-iso = equivalence
infix 0 _↔[_]_
_↔[_]_ : ∀ {ℓ₁ ℓ₂} → Type ℓ₁ → Isomorphism-kind → Type ℓ₂ → Type _
A ↔[ k ] B = A ↝[ ⌊ k ⌋-iso ] B
from-isomorphism : ∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
A ↔[ k₁ ] B → A ↝[ k₂ ] B
from-isomorphism {bijection} = from-bijection
from-isomorphism {equivalence} = from-equivalence
-- Lemma: to-implication after from-isomorphism is the same as
-- to-implication.
to-implication∘from-isomorphism :
∀ {a b} {A : Type a} {B : Type b} k₁ k₂ {A↔B : A ↔[ k₁ ] B} →
to-implication A↔B ≡
to-implication (from-isomorphism {k₂ = k₂} A↔B)
to-implication∘from-isomorphism {A = A} {B} = t∘f
where
t∘f : ∀ k₁ k₂ {A↔B : A ↔[ k₁ ] B} →
to-implication A↔B ≡
to-implication (from-isomorphism {k₂ = k₂} A↔B)
t∘f bijection implication = refl _
t∘f bijection logical-equivalence = refl _
t∘f bijection injection = refl _
t∘f bijection embedding = refl _
t∘f bijection surjection = refl _
t∘f bijection bijection = refl _
t∘f bijection equivalence = refl _
t∘f bijection equivalenceᴱ = refl _
t∘f equivalence implication = refl _
t∘f equivalence logical-equivalence = refl _
t∘f equivalence injection = refl _
t∘f equivalence embedding = refl _
t∘f equivalence surjection = refl _
t∘f equivalence bijection = refl _
t∘f equivalence equivalence = refl _
t∘f equivalence equivalenceᴱ = refl _
------------------------------------------------------------------------
-- Preorder
-- All the different kinds of functions form preorders.
-- Composition.
infixr 9 _∘_
_∘_ : ∀ {k a b c} {A : Type a} {B : Type b} {C : Type c} →
B ↝[ k ] C → A ↝[ k ] B → A ↝[ k ] C
_∘_ {implication} = λ f g → f ⊚ g
_∘_ {logical-equivalence} = L._∘_
_∘_ {injection} = Injection._∘_
_∘_ {embedding} = Emb._∘_
_∘_ {surjection} = Surjection._∘_
_∘_ {bijection} = Bijection._∘_
_∘_ {equivalence} = Eq._∘_
_∘_ {equivalenceᴱ} = EEq._∘_
-- Identity.
id : ∀ {k a} {A : Type a} → A ↝[ k ] A
id {implication} = P.id
id {logical-equivalence} = L.id
id {injection} = Injection.id
id {embedding} = Emb.id
id {surjection} = Surjection.id
id {bijection} = Bijection.id
id {equivalence} = Eq.id
id {equivalenceᴱ} = EEq.id
-- "Equational" reasoning combinators.
infix -1 finally-↝ finally-↔
infix -1 _□
infixr -2 step-↝ step-↔ _↔⟨⟩_
infix -3 $⟨_⟩_
-- For an explanation of why step-↝ and step-↔ are defined in this
-- way, see Equality.step-≡.
step-↝ : ∀ {k a b c} (A : Type a) {B : Type b} {C : Type c} →
B ↝[ k ] C → A ↝[ k ] B → A ↝[ k ] C
step-↝ _ = _∘_
syntax step-↝ A B↝C A↝B = A ↝⟨ A↝B ⟩ B↝C
step-↔ : ∀ {k₁ k₂ a b c} (A : Type a) {B : Type b} {C : Type c} →
B ↝[ k₂ ] C → A ↔[ k₁ ] B → A ↝[ k₂ ] C
step-↔ _ B↝C A↔B = step-↝ _ B↝C (from-isomorphism A↔B)
syntax step-↔ A B↝C A↔B = A ↔⟨ A↔B ⟩ B↝C
_↔⟨⟩_ : ∀ {k a b} (A : Type a) {B : Type b} →
A ↝[ k ] B → A ↝[ k ] B
_ ↔⟨⟩ A↝B = A↝B
_□ : ∀ {k a} (A : Type a) → A ↝[ k ] A
A □ = id
finally-↝ : ∀ {k a b} (A : Type a) (B : Type b) →
A ↝[ k ] B → A ↝[ k ] B
finally-↝ _ _ A↝B = A↝B
syntax finally-↝ A B A↝B = A ↝⟨ A↝B ⟩□ B □
finally-↔ : ∀ {k₁ k₂ a b} (A : Type a) (B : Type b) →
A ↔[ k₁ ] B → A ↝[ k₂ ] B
finally-↔ _ _ A↔B = from-isomorphism A↔B
syntax finally-↔ A B A↔B = A ↔⟨ A↔B ⟩□ B □
$⟨_⟩_ : ∀ {k a b} {@0 A : Type a} {@0 B : Type b} →
A → A ↝[ k ] B → B
$⟨ a ⟩ A↝B = to-implication A↝B a
-- Lemma: to-implication maps id to the identity function.
to-implication-id :
∀ {a} {A : Type a} k →
to-implication {k = k} id ≡ id {A = A}
to-implication-id implication = refl _
to-implication-id logical-equivalence = refl _
to-implication-id injection = refl _
to-implication-id embedding = refl _
to-implication-id surjection = refl _
to-implication-id bijection = refl _
to-implication-id equivalence = refl _
to-implication-id equivalenceᴱ = refl _
-- Lemma: to-implication is homomorphic with respect to _∘_.
to-implication-∘ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(k : Kind) {f : A ↝[ k ] B} {g : B ↝[ k ] C} →
to-implication (g ∘ f) ≡ to-implication g ∘ to-implication f
to-implication-∘ implication = refl _
to-implication-∘ logical-equivalence = refl _
to-implication-∘ injection = refl _
to-implication-∘ embedding = refl _
to-implication-∘ surjection = refl _
to-implication-∘ bijection = refl _
to-implication-∘ equivalence = refl _
to-implication-∘ equivalenceᴱ = refl _
-- Lemma: to-implication maps inverse id to the identity function.
to-implication-inverse-id :
∀ {a} {A : Type a} k →
to-implication (inverse {k = k} id) ≡ id {A = A}
to-implication-inverse-id logical-equivalence = refl _
to-implication-inverse-id bijection = refl _
to-implication-inverse-id equivalence = refl _
to-implication-inverse-id equivalenceᴱ = refl _
------------------------------------------------------------------------
-- Conditional extensionality
-- Code that provides support for proving general statements about
-- functions of different kinds, in which the statements involve
-- assumptions of extensionality for some kinds of functions, but not
-- all. For some examples, see ∀-cong and ∀-intro.
-- Kinds for which extensionality is not provided.
data Without-extensionality : Type where
implication logical-equivalence : Without-extensionality
⌊_⌋-without : Without-extensionality → Kind
⌊ implication ⌋-without = implication
⌊ logical-equivalence ⌋-without = logical-equivalence
-- Kinds for which erased extensionality is not provided.
data With-erased-extensionality : Type where
equivalenceᴱ : With-erased-extensionality
⌊_⌋-with-erased : With-erased-extensionality → Kind
⌊ equivalenceᴱ ⌋-with-erased = equivalenceᴱ
-- Kinds for which extensionality is provided.
data With-extensionality : Type where
injection embedding surjection bijection equivalence :
With-extensionality
⌊_⌋-with : With-extensionality → Kind
⌊ injection ⌋-with = injection
⌊ embedding ⌋-with = embedding
⌊ surjection ⌋-with = surjection
⌊ bijection ⌋-with = bijection
⌊ equivalence ⌋-with = equivalence
-- Kinds annotated with information about what kind of extensionality
-- is provided, if any.
data Extensionality-kind : Kind → Type where
without-extensionality : (k : Without-extensionality) →
Extensionality-kind ⌊ k ⌋-without
with-erased-extensionality : (k : With-erased-extensionality) →
Extensionality-kind ⌊ k ⌋-with-erased
with-extensionality : (k : With-extensionality) →
Extensionality-kind ⌊ k ⌋-with
-- Is extensionality provided for the given kind?
extensionality? : (k : Kind) → Extensionality-kind k
extensionality? implication = without-extensionality implication
extensionality? logical-equivalence = without-extensionality
logical-equivalence
extensionality? injection = with-extensionality injection
extensionality? embedding = with-extensionality embedding
extensionality? surjection = with-extensionality surjection
extensionality? bijection = with-extensionality bijection
extensionality? equivalence = with-extensionality equivalence
extensionality? equivalenceᴱ = with-erased-extensionality
equivalenceᴱ
-- Extensionality, but only for certain kinds of functions, and
-- possibly erased.
Extensionality? : Kind → (a b : Level) → Type (lsuc (a ⊔ b))
Extensionality? k a b with extensionality? k
... | without-extensionality _ = ↑ _ ⊤
... | with-erased-extensionality _ = Erased (Extensionality a b)
... | with-extensionality _ = Extensionality a b
-- A variant of _↝[_]_. A ↝[ c ∣ d ] B means that A ↝[ k ] B can be
-- proved for all kinds k, in some cases assuming extensionality (for
-- the levels c and d).
infix 0 _↝[_∣_]_
_↝[_∣_]_ :
∀ {a b} →
Type a → (c d : Level) → Type b → Type (a ⊔ b ⊔ lsuc (c ⊔ d))
A ↝[ c ∣ d ] B = ∀ {k} → Extensionality? k c d → A ↝[ k ] B
-- A variant of _↝[_∣_]_ with erased extensionality assumptions.
infix 0 _↝[_∣_]ᴱ_
_↝[_∣_]ᴱ_ :
∀ {a b} →
Type a → (c d : Level) → Type b → Type (a ⊔ b ⊔ lsuc (c ⊔ d))
A ↝[ c ∣ d ]ᴱ B = ∀ {k} → @0 Extensionality? k c d → A ↝[ k ] B
-- Turns extensionality into conditional extensionality.
forget-ext? : ∀ k {a b} → Extensionality a b → Extensionality? k a b
forget-ext? k with extensionality? k
... | without-extensionality _ = _
... | with-erased-extensionality _ = E.[_]→
... | with-extensionality _ = id
-- A variant of lower-extensionality.
lower-extensionality? :
∀ k {a b} â b̂ →
Extensionality? k (a ⊔ â) (b ⊔ b̂) → Extensionality? k a b
lower-extensionality? k â b̂ with extensionality? k
... | without-extensionality _ = _
... | with-erased-extensionality _ = E.map (lower-extensionality â b̂)
... | with-extensionality _ = lower-extensionality â b̂
-- Some functions that can be used to generalise results.
generalise-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
(A⇔B : A ⇔ B) →
(Extensionality c d →
let open _⇔_ A⇔B in
(∀ x → to (from x) ≡ x) ×
(∀ x → from (to x) ≡ x)) →
A ↝[ c ∣ d ] B
generalise-ext? A⇔B hyp {k = k} with extensionality? k
... | without-extensionality implication =
λ _ → _⇔_.to A⇔B
... | without-extensionality logical-equivalence =
λ _ → A⇔B
... | with-extensionality _ = λ ext →
from-bijection record
{ surjection = record
{ logical-equivalence = A⇔B
; right-inverse-of = hyp ext .proj₁
}
; left-inverse-of = hyp ext .proj₂
}
... | with-erased-extensionality equivalenceᴱ = λ (E.[ ext ]) →
EEq.↔→≃ᴱ (_⇔_.to A⇔B) (_⇔_.from A⇔B) (hyp ext .proj₁) (hyp ext .proj₂)
generalise-erased-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
A ⇔ B →
(@0 Extensionality c d → A ↔ B) →
A ↝[ c ∣ d ]ᴱ B
generalise-erased-ext? f⇔ f↔ {k = k} with extensionality? k
... | without-extensionality implication =
λ _ → _⇔_.to f⇔
... | without-extensionality logical-equivalence =
λ _ → f⇔
... | with-extensionality _ = λ ext →
from-isomorphism (f↔ ext)
... | with-erased-extensionality _ = λ ext →
from-isomorphism (f↔ (E.erased ext))
generalise-ext?-prop :
∀ {a b c d} {A : Type a} {B : Type b} →
A ⇔ B →
(Extensionality c d → Is-proposition A) →
(Extensionality c d → Is-proposition B) →
A ↝[ c ∣ d ] B
generalise-ext?-prop f⇔ A-prop B-prop =
generalise-ext?
f⇔
(λ ext →
(λ _ → B-prop ext _ _)
, (λ _ → A-prop ext _ _))
generalise-erased-ext?-prop :
∀ {a b c d} {A : Type a} {B : Type b} →
A ⇔ B →
(@0 Extensionality c d → Is-proposition A) →
(@0 Extensionality c d → Is-proposition B) →
A ↝[ c ∣ d ]ᴱ B
generalise-erased-ext?-prop f⇔ A-prop B-prop =
generalise-erased-ext?
f⇔
(λ ext → _≃_.bijection $
_↠_.from (Eq.≃↠⇔ (A-prop ext) (B-prop ext)) f⇔)
generalise-ext?-sym :
∀ {a b c d} {A : Type a} {B : Type b} →
(∀ {k} → Extensionality? ⌊ k ⌋-sym c d → A ↝[ ⌊ k ⌋-sym ] B) →
A ↝[ c ∣ d ] B
generalise-ext?-sym hyp {k = k} ext with extensionality? k
... | without-extensionality implication =
_⇔_.to $ hyp {k = logical-equivalence} ext
... | without-extensionality logical-equivalence =
hyp {k = logical-equivalence} ext
... | with-extensionality _ =
from-bijection $ hyp {k = bijection} ext
... | with-erased-extensionality equivalenceᴱ =
hyp {k = equivalenceᴱ} ext
generalise-erased-ext?-sym :
∀ {a b c d} {A : Type a} {B : Type b} →
(∀ {k} → @0 Extensionality? ⌊ k ⌋-sym c d → A ↝[ ⌊ k ⌋-sym ] B) →
A ↝[ c ∣ d ]ᴱ B
generalise-erased-ext?-sym hyp = generalise-erased-ext? (hyp _) hyp
-- General results of the kind produced by generalise-ext? are
-- symmetric.
inverse-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
A ↝[ c ∣ d ] B → B ↝[ c ∣ d ] A
inverse-ext? hyp = generalise-ext?-sym (inverse ⊚ hyp)
inverse-erased-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
A ↝[ c ∣ d ]ᴱ B → B ↝[ c ∣ d ]ᴱ A
inverse-erased-ext? hyp =
generalise-erased-ext?-sym (λ ext → inverse (hyp ext))
------------------------------------------------------------------------
-- Lots of properties
------------------------------------------------------------------------
-- Properties of the form A ↝[ k ] B, for arbitrary k, are only stated
-- for bijections or equivalences; converting to the other forms is
-- easy.
------------------------------------------------------------------------
-- Equalities can be converted to all kinds of functions
≡⇒↝ : ∀ k {ℓ} {A B : Type ℓ} → A ≡ B → A ↝[ k ] B
≡⇒↝ k = elim (λ {A B} _ → A ↝[ k ] B) (λ _ → id)
abstract
-- Some lemmas that can be used to manipulate expressions involving
-- ≡⇒↝ and refl/sym/trans.
≡⇒↝-refl : ∀ {k a} {A : Type a} →
≡⇒↝ k (refl A) ≡ id
≡⇒↝-refl {k} = elim-refl (λ {A B} _ → A ↝[ k ] B) _
≡⇒↝-sym : ∀ k {ℓ} {A B : Type ℓ} {eq : A ≡ B} →
to-implication (≡⇒↝ ⌊ k ⌋-sym (sym eq)) ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym eq))
≡⇒↝-sym k {A = A} {eq = eq} = elim¹
(λ eq → to-implication (≡⇒↝ ⌊ k ⌋-sym (sym eq)) ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym eq)))
(to-implication (≡⇒↝ ⌊ k ⌋-sym (sym (refl A))) ≡⟨ cong (to-implication ∘ ≡⇒↝ ⌊ k ⌋-sym) sym-refl ⟩
to-implication (≡⇒↝ ⌊ k ⌋-sym (refl A)) ≡⟨ cong (to-implication {k = ⌊ k ⌋-sym}) ≡⇒↝-refl ⟩
to-implication {k = ⌊ k ⌋-sym} id ≡⟨ to-implication-id ⌊ k ⌋-sym ⟩
id ≡⟨ sym $ to-implication-inverse-id k ⟩
to-implication (inverse {k = k} id) ≡⟨ cong (to-implication ∘ inverse {k = k}) $ sym ≡⇒↝-refl ⟩∎
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (refl A))) ∎)
eq
≡⇒↝-trans : ∀ k {ℓ} {A B C : Type ℓ} {A≡B : A ≡ B} {B≡C : B ≡ C} →
to-implication (≡⇒↝ k (trans A≡B B≡C)) ≡
to-implication (≡⇒↝ k B≡C ∘ ≡⇒↝ k A≡B)
≡⇒↝-trans k {B = B} {A≡B = A≡B} = elim¹
(λ B≡C → to-implication (≡⇒↝ k (trans A≡B B≡C)) ≡
to-implication (≡⇒↝ k B≡C ∘ ≡⇒↝ k A≡B))
(to-implication (≡⇒↝ k (trans A≡B (refl B))) ≡⟨ cong (to-implication ∘ ≡⇒↝ k) $ trans-reflʳ _ ⟩
to-implication (≡⇒↝ k A≡B) ≡⟨ sym $ cong (λ f → f ∘ to-implication (≡⇒↝ k A≡B)) $ to-implication-id k ⟩
to-implication {k = k} id ∘ to-implication (≡⇒↝ k A≡B) ≡⟨ sym $ to-implication-∘ k ⟩
to-implication (id ∘ ≡⇒↝ k A≡B) ≡⟨ sym $ cong (λ f → to-implication (f ∘ ≡⇒↝ k A≡B)) ≡⇒↝-refl ⟩∎
to-implication (≡⇒↝ k (refl B) ∘ ≡⇒↝ k A≡B) ∎)
_
-- One can sometimes "push" ≡⇒↝ through cong.
--
-- This is a generalisation of a lemma due to Thierry Coquand.
≡⇒↝-cong : ∀ {k ℓ p A B} {eq : A ≡ B}
(P : Type ℓ → Type p)
(P-cong : ∀ {A B} → A ↝[ k ] B → P A ↝[ k ] P B) →
P-cong (id {A = A}) ≡ id →
≡⇒↝ _ (cong P eq) ≡ P-cong (≡⇒↝ _ eq)
≡⇒↝-cong {eq = eq} P P-cong P-cong-id = elim¹
(λ eq → ≡⇒↝ _ (cong P eq) ≡ P-cong (≡⇒↝ _ eq))
(≡⇒↝ _ (cong P (refl _)) ≡⟨ cong (≡⇒↝ _) $ cong-refl P ⟩
≡⇒↝ _ (refl _) ≡⟨ elim-refl (λ {A B} _ → A ↝[ _ ] B) _ ⟩
id ≡⟨ sym P-cong-id ⟩
P-cong id ≡⟨ cong P-cong $ sym $
elim-refl (λ {A B} _ → A ↝[ _ ] B) _ ⟩∎
P-cong (≡⇒↝ _ (refl _)) ∎)
eq
-- One can express ≡⇒↝ in terms of subst.
≡⇒↝-in-terms-of-subst :
∀ k {ℓ} {A B : Type ℓ} (A≡B : A ≡ B) →
≡⇒↝ k A≡B ≡ subst (A ↝[ k ]_) A≡B id
≡⇒↝-in-terms-of-subst k {B = B} = elim₁
(λ {A} A≡B → ≡⇒↝ k A≡B ≡ subst (A ↝[ k ]_) A≡B id)
(≡⇒↝ k (refl B) ≡⟨ ≡⇒↝-refl ⟩
id ≡⟨ sym $ subst-refl _ _ ⟩∎
subst (B ↝[ k ]_) (refl B) id ∎)
≡⇒↝-in-terms-of-subst-sym :
∀ k {ℓ} {A B : Type ℓ} (A≡B : A ≡ B) →
≡⇒↝ k A≡B ≡ subst (_↝[ k ] B) (sym A≡B) id
≡⇒↝-in-terms-of-subst-sym k {B = B} = elim₁
(λ {A} A≡B → ≡⇒↝ k A≡B ≡ subst (_↝[ k ] B) (sym A≡B) id)
(≡⇒↝ k (refl B) ≡⟨ ≡⇒↝-refl ⟩
id ≡⟨ sym $ subst-refl _ _ ⟩
subst (_↝[ k ] B) (refl B) id ≡⟨ cong (flip (subst _) _) $ sym sym-refl ⟩∎
subst (_↝[ k ] B) (sym (refl B)) id ∎)
-- One can express subst in terms of ≡⇒↝.
subst-in-terms-of-≡⇒↝ :
∀ k {a p} {A : Type a} {x y} (x≡y : x ≡ y) (P : A → Type p) p →
subst P x≡y p ≡ to-implication (≡⇒↝ k (cong P x≡y)) p
subst-in-terms-of-≡⇒↝ k x≡y P p = elim¹
(λ eq → subst P eq p ≡ to-implication (≡⇒↝ k (cong P eq)) p)
(subst P (refl _) p ≡⟨ subst-refl P p ⟩
p ≡⟨ sym $ cong (_$ p) (to-implication-id k) ⟩
to-implication {k = k} id p ≡⟨ sym $ cong (λ f → to-implication {k = k} f p) ≡⇒↝-refl ⟩
to-implication (≡⇒↝ k (refl _)) p ≡⟨ sym $ cong (λ eq → to-implication (≡⇒↝ k eq) p) $ cong-refl P ⟩∎
to-implication (≡⇒↝ k (cong P (refl _))) p ∎)
x≡y
subst-in-terms-of-inverse∘≡⇒↝ :
∀ k {a p} {A : Type a} {x y} (x≡y : x ≡ y) (P : A → Type p) p →
subst P (sym x≡y) p ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (cong P x≡y))) p
subst-in-terms-of-inverse∘≡⇒↝ k x≡y P p =
subst P (sym x≡y) p ≡⟨ subst-in-terms-of-≡⇒↝ ⌊ k ⌋-sym (sym x≡y) P p ⟩
to-implication (≡⇒↝ ⌊ k ⌋-sym (cong P (sym x≡y))) p ≡⟨ cong (λ eq → to-implication (≡⇒↝ ⌊ k ⌋-sym eq) p) (cong-sym P _) ⟩
to-implication (≡⇒↝ ⌊ k ⌋-sym (sym $ cong P x≡y)) p ≡⟨ cong (_$ p) (≡⇒↝-sym k) ⟩∎
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (cong P x≡y))) p ∎
-- One can express subst id in terms of ≡⇒↝.
subst-id-in-terms-of-≡⇒↝ :
∀ k {a} {A B : Type a} {A≡B : A ≡ B} {x} →
subst id A≡B x ≡ to-implication (≡⇒↝ k A≡B) x
subst-id-in-terms-of-≡⇒↝ k {A≡B = A≡B} {x = x} =
subst id A≡B x ≡⟨ subst-in-terms-of-≡⇒↝ k _ _ _ ⟩
to-implication (≡⇒↝ k (cong id A≡B)) x ≡⟨ cong (λ eq → to-implication (≡⇒↝ k eq) x) $ sym $ cong-id _ ⟩∎
to-implication (≡⇒↝ k A≡B) x ∎
subst-id-in-terms-of-inverse∘≡⇒↝ :
∀ k {a} {A B : Type a} {A≡B : A ≡ B} {y} →
subst id (sym A≡B) y ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym A≡B)) y
subst-id-in-terms-of-inverse∘≡⇒↝ k {A≡B = A≡B} {y = y} =
subst id (sym A≡B) y ≡⟨ subst-in-terms-of-inverse∘≡⇒↝ k _ _ _ ⟩
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (cong id A≡B))) y ≡⟨ cong (λ eq → to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym eq)) y) $ sym $ cong-id _ ⟩∎
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym A≡B)) y ∎
to-implication-≡⇒↝ :
∀ k {ℓ} {A B : Type ℓ} (eq : A ≡ B) →
to-implication (≡⇒↝ k eq) ≡ ≡⇒↝ implication eq
to-implication-≡⇒↝ k =
elim (λ eq → to-implication (≡⇒↝ k eq) ≡ ≡⇒↝ implication eq)
(λ A → to-implication (≡⇒↝ k (refl A)) ≡⟨ cong to-implication (≡⇒↝-refl {k = k}) ⟩
to-implication {k = k} id ≡⟨ to-implication-id k ⟩
id ≡⟨ sym ≡⇒↝-refl ⟩∎
≡⇒↝ implication (refl A) ∎)
------------------------------------------------------------------------
-- One can replace the "to" and "from" functions with extensionally
-- equal functions
-- One can replace the "to" function with an extensionally equal
-- function.
with-other-function :
∀ {k a b} {A : Type a} {B : Type b}
(A↝B : A ↝[ k ] B) (f : A → B) →
(∀ x → to-implication A↝B x ≡ f x) →
A ↝[ k ] B
with-other-function {k = implication} _ f _ = f
with-other-function {k = logical-equivalence} A⇔B f _ = record
{ to = f
; from = _⇔_.from A⇔B
}
with-other-function {k = injection} A↣B f ≡f = record
{ to = f
; injective = λ {x = x} {y = y} →
f x ≡ f y →⟨ flip trans (sym $ ≡f y) ∘ trans (≡f x) ⟩
_↣_.to A↣B x ≡ _↣_.to A↣B y →⟨ _↣_.injective A↣B ⟩□
x ≡ y □
}
with-other-function {k = embedding} A↣B f ≡f = record
{ to = f
; is-embedding = λ x y →
_≃_.is-equivalence $
Eq.with-other-function
(x ≡ y ↝⟨ Eq.⟨ _ , Embedding.is-embedding A↣B x y ⟩ ⟩
Embedding.to A↣B x ≡ Embedding.to A↣B y ↝⟨ ≡⇒↝ _ $ cong₂ _≡_ (≡f x) (≡f y) ⟩□
f x ≡ f y □)
(cong f)
(elim
(λ {x = x} {y = y} x≡y →
_≃_.to (≡⇒↝ _ (cong₂ _≡_ (≡f x) (≡f y)))
(cong (Embedding.to A↣B) x≡y) ≡
cong f x≡y)
(λ x →
_≃_.to (≡⇒↝ _ (cong₂ _≡_ (≡f x) (≡f x)))
(cong (Embedding.to A↣B) (refl _)) ≡⟨ cong (_≃_.to (≡⇒↝ _ _)) $
cong-refl _ ⟩
_≃_.to (≡⇒↝ _ (cong₂ _≡_ (≡f x) (≡f x))) (refl _) ≡⟨ cong (_$ _) $
≡⇒↝-trans equivalence ⟩
_≃_.to (≡⇒↝ _ (cong (_ ≡_) (≡f x)))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) (≡f x))) (refl _)) ≡⟨ sym $
trans (subst-in-terms-of-≡⇒↝ equivalence _ _ _) $
cong (_≃_.to (≡⇒↝ _ _)) $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst (_ ≡_) (≡f x) (subst (_≡ _) (≡f x) (refl _)) ≡⟨ trans (cong (subst (_ ≡_) (≡f x)) $
trans subst-trans-sym $
trans-reflʳ _) $
sym trans-subst ⟩
trans (sym (≡f x)) (≡f x) ≡⟨ trans-symˡ _ ⟩
refl (f x) ≡⟨ sym $ cong-refl _ ⟩∎
cong f (refl x) ∎))
}
with-other-function {k = surjection} A↠B f ≡f = record
{ logical-equivalence = record
{ to = f
; from = _↠_.from A↠B
}
; right-inverse-of = λ x →
f (_↠_.from A↠B x) ≡⟨ sym $ ≡f _ ⟩
_↠_.to A↠B (_↠_.from A↠B x) ≡⟨ _↠_.right-inverse-of A↠B _ ⟩∎
x ∎
}
with-other-function {k = bijection} = Bijection.with-other-function
with-other-function {k = equivalence} = Eq.with-other-function
with-other-function {k = equivalenceᴱ} A≃ᴱB f ≡f =
EEq.with-other-function A≃ᴱB f ≡f
-- The function with-other-function changes the "to" function in the
-- advertised way.
to-implication-with-other-function :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ k ] B} {f : A → B}
{≡f : ∀ x → to-implication A↝B x ≡ f x} {x} →
to-implication (with-other-function A↝B f ≡f) x ≡ f x
to-implication-with-other-function implication = refl _
to-implication-with-other-function logical-equivalence = refl _
to-implication-with-other-function injection = refl _
to-implication-with-other-function embedding = refl _
to-implication-with-other-function surjection = refl _
to-implication-with-other-function bijection = refl _
to-implication-with-other-function equivalence = refl _
to-implication-with-other-function equivalenceᴱ = refl _
-- The function with-other-function does not change the "from"
-- function (if any).
to-implication-inverse-with-other-function :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ ⌊ k ⌋-sym ] B}
{f : A → B} {≡f : ∀ x → to-implication A↝B x ≡ f x} {x} →
to-implication (inverse (with-other-function A↝B f ≡f)) x ≡
to-implication (inverse A↝B) x
to-implication-inverse-with-other-function logical-equivalence = refl _
to-implication-inverse-with-other-function bijection = refl _
to-implication-inverse-with-other-function equivalence = refl _
to-implication-inverse-with-other-function equivalenceᴱ = refl _
-- One can replace the "from" function with an extensionally equal
-- function.
with-other-inverse :
∀ {k a b} {A : Type a} {B : Type b}
(A↝B : A ↝[ ⌊ k ⌋-sym ] B) (f : B → A) →
(∀ x → to-implication (inverse A↝B) x ≡ f x) →
A ↝[ ⌊ k ⌋-sym ] B
with-other-inverse {k = logical-equivalence} A⇔B f _ = record
{ to = _⇔_.to A⇔B
; from = f
}
with-other-inverse {k = bijection} = Bijection.with-other-inverse
with-other-inverse {k = equivalence} = Eq.with-other-inverse
with-other-inverse {k = equivalenceᴱ} A≃ᴱB f ≡f =
EEq.with-other-inverse A≃ᴱB f ≡f
-- The function with-other-inverse does not change the "to" function.
to-implication-with-other-inverse :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ ⌊ k ⌋-sym ] B}
{f : B → A} {≡f : ∀ x → to-implication (inverse A↝B) x ≡ f x} {x} →
to-implication (with-other-inverse A↝B f ≡f) x ≡
to-implication A↝B x
to-implication-with-other-inverse logical-equivalence = refl _
to-implication-with-other-inverse bijection = refl _
to-implication-with-other-inverse equivalence = refl _
to-implication-with-other-inverse equivalenceᴱ = refl _
-- The function with-other-inverse changes the "from" function in the
-- advertised way.
to-implication-inverse-with-other-inverse :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ ⌊ k ⌋-sym ] B}
{f : B → A} {≡f : ∀ x → to-implication (inverse A↝B) x ≡ f x} {x} →
to-implication (inverse (with-other-inverse A↝B f ≡f)) x ≡ f x
to-implication-inverse-with-other-inverse logical-equivalence = refl _
to-implication-inverse-with-other-inverse bijection = refl _
to-implication-inverse-with-other-inverse equivalence = refl _
to-implication-inverse-with-other-inverse equivalenceᴱ = refl _
------------------------------------------------------------------------
-- _⊎_ is a commutative monoid
-- _⊎_ preserves all kinds of functions.
private
⊎-cong-inj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↣ A₂ → B₁ ↣ B₂ → A₁ ⊎ B₁ ↣ A₂ ⊎ B₂
⊎-cong-inj A₁↣A₂ B₁↣B₂ = record
{ to = to′
; injective = injective′
}
where
open _↣_
to′ = ⊎-map (to A₁↣A₂) (to B₁↣B₂)
abstract
injective′ : Injective to′
injective′ {x = inj₁ x} {y = inj₁ y} = cong inj₁ ⊚ injective A₁↣A₂ ⊚ ⊎.cancel-inj₁
injective′ {x = inj₂ x} {y = inj₂ y} = cong inj₂ ⊚ injective B₁↣B₂ ⊚ ⊎.cancel-inj₂
injective′ {x = inj₁ x} {y = inj₂ y} = ⊥-elim ⊚ ⊎.inj₁≢inj₂
injective′ {x = inj₂ x} {y = inj₁ y} = ⊥-elim ⊚ ⊎.inj₁≢inj₂ ⊚ sym
⊎-cong-emb : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
Embedding A₁ A₂ → Embedding B₁ B₂ →
Embedding (A₁ ⊎ B₁) (A₂ ⊎ B₂)
⊎-cong-emb A₁↣A₂ B₁↣B₂ = record
{ to = to′
; is-embedding = is-embedding′
}
where
open Embedding
to′ = ⊎-map (to A₁↣A₂) (to B₁↣B₂)
is-embedding′ : Is-embedding to′
is-embedding′ (inj₁ x) (inj₁ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₁ x ≡ inj₁ y ↔⟨ inverse Bijection.≡↔inj₁≡inj₁ ⟩
x ≡ y ↝⟨ Eq.⟨ _ , is-embedding A₁↣A₂ _ _ ⟩ ⟩
to A₁↣A₂ x ≡ to A₁↣A₂ y ↔⟨ Bijection.≡↔inj₁≡inj₁ ⟩□
inj₁ (to A₁↣A₂ x) ≡ inj₁ (to A₁↣A₂ y) □)
_
(λ eq →
cong inj₁ (cong (to A₁↣A₂) (⊎.cancel-inj₁ eq)) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₁ ⊚ to A₁↣A₂) (⊎.cancel-inj₁ eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₁ ⊚ to A₁↣A₂ ⊚ [ id , const x ]) eq ≡⟨ sym $ trans-reflʳ _ ⟩
trans (cong (inj₁ ⊚ to A₁↣A₂ ⊚ [ id , const x ]) eq) (refl _) ≡⟨ cong-respects-relevant-equality
{f = inj₁ ⊚ to A₁↣A₂ ⊚ [ id , const x ]}
(if_then true else false)
[ (λ _ _ → refl _) , (λ _ ()) ] ⟩
trans (refl _) (cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq) ≡⟨ trans-reflˡ _ ⟩∎
cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq ∎)
is-embedding′ (inj₂ x) (inj₂ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₂ x ≡ inj₂ y ↔⟨ inverse Bijection.≡↔inj₂≡inj₂ ⟩
x ≡ y ↝⟨ Eq.⟨ _ , is-embedding B₁↣B₂ _ _ ⟩ ⟩
to B₁↣B₂ x ≡ to B₁↣B₂ y ↔⟨ Bijection.≡↔inj₂≡inj₂ ⟩□
inj₂ (to B₁↣B₂ x) ≡ inj₂ (to B₁↣B₂ y) □)
_
(λ eq →
cong inj₂ (cong (to B₁↣B₂) (⊎.cancel-inj₂ eq)) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₂ ⊚ to B₁↣B₂) (⊎.cancel-inj₂ eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₂ ⊚ to B₁↣B₂ ⊚ [ const x , id ]) eq ≡⟨ sym $ trans-reflʳ _ ⟩
trans (cong (inj₂ ⊚ to B₁↣B₂ ⊚ [ const x , id ]) eq) (refl _) ≡⟨ cong-respects-relevant-equality
{f = inj₂ ⊚ to B₁↣B₂ ⊚ [ const x , id ]}
(if_then false else true)
[ (λ _ ()) , (λ _ _ → refl _) ] ⟩
trans (refl _) (cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq) ≡⟨ trans-reflˡ _ ⟩∎
cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq ∎)
is-embedding′ (inj₁ x) (inj₂ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₁ x ≡ inj₂ y ↔⟨ inverse $ Bijection.⊥↔uninhabited ⊎.inj₁≢inj₂ ⟩
⊥₀ ↔⟨ Bijection.⊥↔uninhabited ⊎.inj₁≢inj₂ ⟩□
inj₁ (to A₁↣A₂ x) ≡ inj₂ (to B₁↣B₂ y) □)
_
(⊥-elim ⊚ ⊎.inj₁≢inj₂)
is-embedding′ (inj₂ x) (inj₁ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₂ x ≡ inj₁ y ↔⟨ inverse $ Bijection.⊥↔uninhabited (⊎.inj₁≢inj₂ ⊚ sym) ⟩
⊥₀ ↔⟨ Bijection.⊥↔uninhabited (⊎.inj₁≢inj₂ ⊚ sym) ⟩□
inj₂ (to B₁↣B₂ x) ≡ inj₁ (to A₁↣A₂ y) □)
_
(⊥-elim ⊚ ⊎.inj₁≢inj₂ ⊚ sym)
⊎-cong-surj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↠ A₂ → B₁ ↠ B₂ → A₁ ⊎ B₁ ↠ A₂ ⊎ B₂
⊎-cong-surj A₁↠A₂ B₁↠B₂ = record
{ logical-equivalence =
_↠_.logical-equivalence A₁↠A₂
L.⊎-cong
_↠_.logical-equivalence B₁↠B₂
; right-inverse-of =
[ cong inj₁ ⊚ _↠_.right-inverse-of A₁↠A₂
, cong inj₂ ⊚ _↠_.right-inverse-of B₁↠B₂
]
}
⊎-cong-bij : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↔ A₂ → B₁ ↔ B₂ → A₁ ⊎ B₁ ↔ A₂ ⊎ B₂
⊎-cong-bij A₁↔A₂ B₁↔B₂ = record
{ surjection = ⊎-cong-surj (_↔_.surjection A₁↔A₂)
(_↔_.surjection B₁↔B₂)
; left-inverse-of =
[ cong inj₁ ⊚ _↔_.left-inverse-of A₁↔A₂
, cong inj₂ ⊚ _↔_.left-inverse-of B₁↔B₂
]
}
⊎-cong-≃ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ ⊎ B₁) ≃ (A₂ ⊎ B₂)
⊎-cong-≃ A₁≃A₂ B₁≃B₂ =
from-bijection $ ⊎-cong-bij (from-equivalence A₁≃A₂)
(from-equivalence B₁≃B₂)
⊎-cong-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ᴱ A₂ → B₁ ≃ᴱ B₂ → (A₁ ⊎ B₁) ≃ᴱ (A₂ ⊎ B₂)
⊎-cong-≃ᴱ f g =
EEq.[≃]→≃ᴱ (EEq.[proofs] (⊎-cong-≃ (EEq.≃ᴱ→≃ f) (EEq.≃ᴱ→≃ g)))
infixr 1 _⊎-cong_
_⊎-cong_ : ∀ {k a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↝[ k ] A₂ → B₁ ↝[ k ] B₂ → A₁ ⊎ B₁ ↝[ k ] A₂ ⊎ B₂
_⊎-cong_ {implication} = ⊎-map
_⊎-cong_ {logical-equivalence} = L._⊎-cong_
_⊎-cong_ {injection} = ⊎-cong-inj
_⊎-cong_ {embedding} = ⊎-cong-emb
_⊎-cong_ {surjection} = ⊎-cong-surj
_⊎-cong_ {bijection} = ⊎-cong-bij
_⊎-cong_ {equivalence} = ⊎-cong-≃
_⊎-cong_ {equivalenceᴱ} = ⊎-cong-≃ᴱ
-- _⊎_ is commutative.
⊎-comm : ∀ {a b} {A : Type a} {B : Type b} → A ⊎ B ↔ B ⊎ A
⊎-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = [ inj₂ , inj₁ ]
; from = [ inj₂ , inj₁ ]
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
-- _⊎_ is associative.
⊎-assoc : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
A ⊎ (B ⊎ C) ↔ (A ⊎ B) ⊎ C
⊎-assoc = record
{ surjection = record
{ logical-equivalence = record
{ to = [ inj₁ ⊚ inj₁ , [ inj₁ ⊚ inj₂ , inj₂ ] ]
; from = [ [ inj₁ , inj₂ ⊚ inj₁ ] , inj₂ ⊚ inj₂ ]
}
; right-inverse-of =
[ [ refl ⊚ inj₁ ⊚ inj₁ , refl ⊚ inj₁ ⊚ inj₂ ] , refl ⊚ inj₂ ]
}
; left-inverse-of =
[ refl ⊚ inj₁ , [ refl ⊚ inj₂ ⊚ inj₁ , refl ⊚ inj₂ ⊚ inj₂ ] ]
}
-- ⊥ is a left and right identity of _⊎_.
⊎-left-identity : ∀ {a ℓ} {A : Type a} → ⊥ {ℓ = ℓ} ⊎ A ↔ A
⊎-left-identity = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (inj₁ ()); (inj₂ x) → x }
; from = inj₂
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (inj₁ ()); (inj₂ x) → refl (inj₂ x) }
}
⊎-right-identity : ∀ {a ℓ} {A : Type a} → A ⊎ ⊥ {ℓ = ℓ} ↔ A
⊎-right-identity {A = A} =
A ⊎ ⊥ ↔⟨ ⊎-comm ⟩
⊥ ⊎ A ↔⟨ ⊎-left-identity ⟩□
A □
-- For logical equivalences _⊎_ is also idempotent. (This lemma could
-- be generalised to cover surjections and implications.)
⊎-idempotent : ∀ {a} {A : Type a} → A ⊎ A ⇔ A
⊎-idempotent = record
{ to = [ id , id ]
; from = inj₁
}
-- Lemmas that can be used to simplify binary sums where one of the
-- two type arguments is related to the empty type.
drop-⊥-right :
∀ {k a b} {A : Type a} {B : Type b} →
B ↝[ k ] ⊥₀ → A ⊎ B ↝[ k ] A
drop-⊥-right {A = A} {B} B↔⊥ =
A ⊎ B ↝⟨ id ⊎-cong B↔⊥ ⟩
A ⊎ ⊥ ↔⟨ ⊎-right-identity ⟩□
A □
drop-⊥-left :
∀ {k a b} {A : Type a} {B : Type b} →
A ↝[ k ] ⊥₀ → A ⊎ B ↝[ k ] B
drop-⊥-left {A = A} {B} A↔⊥ =
A ⊎ B ↔⟨ ⊎-comm ⟩
B ⊎ A ↝⟨ drop-⊥-right A↔⊥ ⟩□
B □
------------------------------------------------------------------------
-- _×_ is a commutative monoid with a zero
-- Σ preserves embeddings. (This definition is used in the proof of
-- _×-cong_.)
Σ-preserves-embeddings :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂}
(A₁↣A₂ : Embedding A₁ A₂) →
(∀ x → Embedding (B₁ x) (B₂ (Embedding.to A₁↣A₂ x))) →
Embedding (Σ A₁ B₁) (Σ A₂ B₂)
Σ-preserves-embeddings {B₁ = B₁} {B₂} A₁↣A₂ B₁↣B₂ = record
{ to = Σ-map (to A₁↣A₂) (to (B₁↣B₂ _))
; is-embedding = λ { (x₁ , x₂) (y₁ , y₂) →
_≃_.is-equivalence $
Eq.with-other-function
((x₁ , x₂) ≡ (y₁ , y₂) ↝⟨ inverse $ Eq.↔⇒≃ Bijection.Σ-≡,≡↔≡ ⟩
(∃ λ (eq : x₁ ≡ y₁) → subst B₁ eq x₂ ≡ y₂) ↝⟨ Eq.Σ-preserves (Embedding.equivalence A₁↣A₂) (λ eq →
subst B₁ eq x₂ ≡ y₂ ↝⟨ Embedding.equivalence (B₁↣B₂ y₁) ⟩
to (B₁↣B₂ y₁) (subst B₁ eq x₂) ≡ to (B₁↣B₂ y₁) y₂ ↝⟨ ≡⇒↝ _ (cong (_≡ _) $ lemma₁ eq _ y₂) ⟩□
subst B₂ (cong (to A₁↣A₂) eq) (to (B₁↣B₂ x₁) x₂) ≡
to (B₁↣B₂ y₁) y₂ □) ⟩
(∃ λ (eq : to A₁↣A₂ x₁ ≡ to A₁↣A₂ y₁) →
subst B₂ eq (to (B₁↣B₂ x₁) x₂) ≡ to (B₁↣B₂ y₁) y₂) ↝⟨ Eq.↔⇒≃ Bijection.Σ-≡,≡↔≡ ⟩□
(to A₁↣A₂ x₁ , to (B₁↣B₂ x₁) x₂) ≡
(to A₁↣A₂ y₁ , to (B₁↣B₂ y₁) y₂) □)
_
(elim
(λ { {y = _ , y₂} eq →
uncurry Σ-≡,≡→≡
(Σ-map (cong (to A₁↣A₂))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ _ _ y₂)) ⊚
cong (to (B₁↣B₂ _)))
(Σ-≡,≡←≡ eq)) ≡
cong (Σ-map (to A₁↣A₂) (to (B₁↣B₂ _))) eq })
(λ _ →
uncurry Σ-≡,≡→≡
(Σ-map (cong (to A₁↣A₂))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ _ _ _)) ⊚
cong (to (B₁↣B₂ _)))
(Σ-≡,≡←≡ (refl _))) ≡⟨ cong (λ eq → uncurry Σ-≡,≡→≡
(Σ-map _
(_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ _ _ _)) ⊚
cong (to (B₁↣B₂ _)))
eq))
Σ-≡,≡←≡-refl ⟩
Σ-≡,≡→≡
(cong (to A₁↣A₂) (refl _))
(_≃_.to (≡⇒↝ _ (cong (_≡ to (B₁↣B₂ _) _) $ lemma₁ _ _ _))
(cong (to (B₁↣B₂ _)) (subst-refl B₁ _))) ≡⟨ Σ-≡,≡→≡-cong (cong-refl _) (lemma₂ _ _) ⟩
Σ-≡,≡→≡ (refl _) (subst-refl B₂ _) ≡⟨ Σ-≡,≡→≡-refl-subst-refl ⟩
refl _ ≡⟨ sym $ cong-refl _ ⟩∎
cong (Σ-map (to A₁↣A₂) (to (B₁↣B₂ _))) (refl _) ∎)) }
}
where
open Embedding using (to)
lemma₁ : ∀ {x₁ y₁} (_ : x₁ ≡ y₁) → _
lemma₁ = elim
(λ {x₁ y₁} eq → (x₂ : B₁ x₁) (y₂ : B₁ y₁) →
to (B₁↣B₂ y₁) (subst B₁ eq x₂) ≡
subst B₂ (cong (to A₁↣A₂) eq) (to (B₁↣B₂ x₁) x₂))
(λ z₁ x₂ y₂ →
to (B₁↣B₂ z₁) (subst B₁ (refl z₁) x₂) ≡⟨ cong (to (B₁↣B₂ z₁)) $ subst-refl _ _ ⟩
to (B₁↣B₂ z₁) x₂ ≡⟨ sym $ subst-refl _ _ ⟩
subst B₂ (refl (to A₁↣A₂ z₁)) (to (B₁↣B₂ z₁) x₂) ≡⟨ cong (λ eq → subst B₂ eq _) (sym $ cong-refl _) ⟩∎
subst B₂ (cong (to A₁↣A₂) (refl z₁)) (to (B₁↣B₂ z₁) x₂) ∎)
lemma₂ = λ x y →
let eq₁ = cong (flip (subst B₂) _) (sym (cong-refl _))
eq₂ = cong (to (B₁↣B₂ x)) (subst-refl B₁ y)
in
trans eq₁ (_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ (refl x) y y)) eq₂) ≡⟨ cong (λ eq → trans eq₁ (_≃_.to (≡⇒↝ _ (cong (_≡ _) (eq y y))) eq₂)) $
elim-refl (λ {x₁ y₁} eq → (x₂ : B₁ x₁) (y₂ : B₁ y₁) →
to (B₁↣B₂ y₁) (subst B₁ eq x₂) ≡
subst B₂ (cong (to A₁↣A₂) eq) (to (B₁↣B₂ x₁) x₂))
_ ⟩
trans eq₁ (_≃_.to (≡⇒↝ _ $ cong (_≡ _) $
trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (trans _) $ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
trans eq₁ (subst (_≡ _)
(trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (λ eq → trans eq₁ (subst (_≡ _) eq eq₂)) $
sym $ sym-sym (trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁)) ⟩
trans eq₁ (subst (_≡ _)
(sym $ sym $
trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (trans _) $ subst-trans _ ⟩
trans eq₁ (trans
(sym $ trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (λ eq → trans eq₁ (trans eq eq₂)) $
sym-trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁) ⟩
trans eq₁ (trans (trans (sym $ trans (sym $ subst-refl B₂ _) eq₁)
(sym eq₂))
eq₂) ≡⟨ cong (trans _) $ trans-[trans-sym]- _ _ ⟩
trans eq₁ (sym $ trans (sym $ subst-refl B₂ _) eq₁) ≡⟨ cong (trans _) $ sym-trans _ _ ⟩
trans eq₁ (trans (sym eq₁) (sym $ sym $ subst-refl B₂ _)) ≡⟨ trans--[trans-sym] _ _ ⟩
sym $ sym $ subst-refl B₂ _ ≡⟨ sym-sym _ ⟩∎
subst-refl B₂ _ ∎
-- _×_ preserves all kinds of functions.
private
×-cong-inj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↣ A₂ → B₁ ↣ B₂ → A₁ × B₁ ↣ A₂ × B₂
×-cong-inj {A₁ = A₁} {A₂} {B₁} {B₂} A₁↣A₂ B₁↣B₂ = record
{ to = to′
; injective = injective′
}
where
open _↣_
to′ : A₁ × B₁ → A₂ × B₂
to′ = Σ-map (to A₁↣A₂) (to B₁↣B₂)
abstract
injective′ : Injective to′
injective′ to′-x≡to′-y =
cong₂ _,_ (injective A₁↣A₂ (cong proj₁ to′-x≡to′-y))
(injective B₁↣B₂ (cong proj₂ to′-x≡to′-y))
×-cong-surj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↠ A₂ → B₁ ↠ B₂ → A₁ × B₁ ↠ A₂ × B₂
×-cong-surj A₁↠A₂ B₁↠B₂ = record
{ logical-equivalence =
_↠_.logical-equivalence A₁↠A₂
L.×-cong
_↠_.logical-equivalence B₁↠B₂
; right-inverse-of = uncurry λ x y →
cong₂ _,_ (_↠_.right-inverse-of A₁↠A₂ x)
(_↠_.right-inverse-of B₁↠B₂ y)
}
×-cong-bij : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↔ A₂ → B₁ ↔ B₂ → A₁ × B₁ ↔ A₂ × B₂
×-cong-bij A₁↔A₂ B₁↔B₂ = record
{ surjection = ×-cong-surj (_↔_.surjection A₁↔A₂)
(_↔_.surjection B₁↔B₂)
; left-inverse-of = uncurry λ x y →
cong₂ _,_ (_↔_.left-inverse-of A₁↔A₂ x)
(_↔_.left-inverse-of B₁↔B₂ y)
}
×-cong-≃ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ × B₁) ≃ (A₂ × B₂)
×-cong-≃ A₁≃A₂ B₁≃B₂ =
from-bijection $ ×-cong-bij (from-equivalence A₁≃A₂)
(from-equivalence B₁≃B₂)
×-cong-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ᴱ A₂ → B₁ ≃ᴱ B₂ → (A₁ × B₁) ≃ᴱ (A₂ × B₂)
×-cong-≃ᴱ f g =
EEq.[≃]→≃ᴱ (EEq.[proofs] (×-cong-≃ (EEq.≃ᴱ→≃ f) (EEq.≃ᴱ→≃ g)))
infixr 2 _×-cong_
_×-cong_ : ∀ {k a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↝[ k ] A₂ → B₁ ↝[ k ] B₂ → A₁ × B₁ ↝[ k ] A₂ × B₂
_×-cong_ {implication} = λ f g → Σ-map f g
_×-cong_ {logical-equivalence} = L._×-cong_
_×-cong_ {injection} = ×-cong-inj
_×-cong_ {embedding} = λ A₁↣A₂ B₁↣B₂ →
Σ-preserves-embeddings
A₁↣A₂ (λ _ → B₁↣B₂)
_×-cong_ {surjection} = ×-cong-surj
_×-cong_ {bijection} = ×-cong-bij
_×-cong_ {equivalence} = ×-cong-≃
_×-cong_ {equivalenceᴱ} = ×-cong-≃ᴱ
-- The function to-implication is homomorphic with respect to
-- _×-cong_/Σ-map.
to-implication-×-cong :
∀ k {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d}
{A↝B : A ↝[ k ] B} {C↝D : C ↝[ k ] D} →
to-implication (A↝B ×-cong C↝D) ≡
Σ-map (to-implication A↝B) (to-implication C↝D)
to-implication-×-cong implication = refl _
to-implication-×-cong logical-equivalence = refl _
to-implication-×-cong injection = refl _
to-implication-×-cong embedding = refl _
to-implication-×-cong surjection = refl _
to-implication-×-cong bijection = refl _
to-implication-×-cong equivalence = refl _
to-implication-×-cong equivalenceᴱ = refl _
-- _×_ is commutative.
×-comm : ∀ {a b} {A : Type a} {B : Type b} → A × B ↔ B × A
×-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ x y → (y , x)
; from = uncurry λ x y → (y , x)
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Σ is associative.
open Bijection public using (Σ-assoc)
-- _×_ is associative.
×-assoc : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
A × (B × C) ↔ (A × B) × C
×-assoc = Σ-assoc
-- ⊤ is a left and right identity of _×_ and Σ.
Σ-left-identity : ∀ {a} {A : ⊤ → Type a} → Σ ⊤ A ↔ A tt
Σ-left-identity = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₂
; from = λ x → (tt , x)
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
×-left-identity : ∀ {a} {A : Type a} → ⊤ × A ↔ A
×-left-identity = Σ-left-identity
×-right-identity : ∀ {a} {A : Type a} → A × ⊤ ↔ A
×-right-identity {A = A} =
A × ⊤ ↔⟨ ×-comm ⟩
⊤ × A ↔⟨ ×-left-identity ⟩□
A □
-- ⊥ is a left and right zero of _×_ and Σ.
Σ-left-zero : ∀ {ℓ₁ a ℓ₂} {A : ⊥ {ℓ = ℓ₁} → Type a} →
Σ ⊥ A ↔ ⊥ {ℓ = ℓ₂}
Σ-left-zero = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (() , _) }
; from = λ ()
}
; right-inverse-of = λ ()
}
; left-inverse-of = λ { (() , _) }
}
×-left-zero : ∀ {a ℓ₁ ℓ₂} {A : Type a} → ⊥ {ℓ = ℓ₁} × A ↔ ⊥ {ℓ = ℓ₂}
×-left-zero = Σ-left-zero
×-right-zero : ∀ {a ℓ₁ ℓ₂} {A : Type a} → A × ⊥ {ℓ = ℓ₁} ↔ ⊥ {ℓ = ℓ₂}
×-right-zero {A = A} =
A × ⊥ ↔⟨ ×-comm ⟩
⊥ × A ↔⟨ ×-left-zero ⟩□
⊥ □
------------------------------------------------------------------------
-- Some lemmas related to Σ/∃/_×_
-- See also Σ-left-zero and Σ-right-zero above.
-- Σ preserves isomorphisms in its first argument and all kinds of
-- functions in its second argument.
Σ-cong : ∀ {k₁ k₂ a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
Σ A₁ B₁ ↝[ k₂ ] Σ A₂ B₂
Σ-cong {equivalence} {implication} = λ A₁≃A₂ B₁→B₂ →
Σ-map (from-isomorphism A₁≃A₂) (B₁→B₂ _)
Σ-cong {bijection} {implication} = λ A₁↔A₂ B₁→B₂ →
Σ-map (from-isomorphism A₁↔A₂) (B₁→B₂ _)
Σ-cong {equivalence} {logical-equivalence} = Surjection.Σ-cong-⇔ ⊚ from-isomorphism
Σ-cong {bijection} {logical-equivalence} = Surjection.Σ-cong-⇔ ⊚ from-isomorphism
Σ-cong {equivalence} {injection} = Eq.∃-preserves-injections
Σ-cong {bijection} {injection} = Eq.∃-preserves-injections ⊚ from-isomorphism
Σ-cong {equivalence} {embedding} = Σ-preserves-embeddings ⊚ from-isomorphism
Σ-cong {bijection} {embedding} = Σ-preserves-embeddings ⊚ from-isomorphism
Σ-cong {equivalence} {surjection} = Surjection.Σ-cong ⊚ from-isomorphism
Σ-cong {bijection} {surjection} = Surjection.Σ-cong ⊚ from-isomorphism
Σ-cong {equivalence} {bijection} = Eq.∃-preserves-bijections
Σ-cong {bijection} {bijection} = Eq.∃-preserves-bijections ⊚ from-isomorphism
Σ-cong {equivalence} {equivalence} = Eq.Σ-preserves
Σ-cong {bijection} {equivalence} = Eq.Σ-preserves ⊚ from-isomorphism
Σ-cong {equivalence} {equivalenceᴱ}
{B₂ = B₂} = λ f g →
EEq.[≃]→≃ᴱ
{to = λ (x , y) → _≃_.to f x , _≃ᴱ_.to (g x) y}
{from = λ (x , y) →
_≃_.from f x
, _≃ᴱ_.from (g (_≃_.from f x))
(subst B₂ (sym (_≃_.right-inverse-of f x)) y)}
(EEq.[proofs]
(Eq.Σ-preserves f (EEq.≃ᴱ→≃ ⊚ g)))
Σ-cong {bijection} {equivalenceᴱ}
{B₂ = B₂} = λ f g →
EEq.[≃]→≃ᴱ
{to = λ (x , y) → _↔_.to f x , _≃ᴱ_.to (g x) y}
{from = λ (x , y) →
_↔_.from f x
, _≃ᴱ_.from (g (_↔_.from f x))
(subst B₂
(sym (_≃_.right-inverse-of (Eq.↔⇒≃ f) x))
y)}
(EEq.[proofs]
(Eq.Σ-preserves (from-isomorphism f)
(EEq.≃ᴱ→≃ ⊚ g)))
-- A variant of Σ-cong.
Σ-cong-contra :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
Σ A₁ B₁ ↝[ k₂ ] Σ A₂ B₂
Σ-cong-contra {k₁} {k₂} {A₁ = A₁} {A₂} {B₁} {B₂} A₂↔A₁ B₁↝B₂ =
Σ-cong A₁↔A₂ B₁↝B₂′
where
A₁↔A₂ : A₁ ↔ A₂
A₁↔A₂ = inverse $ from-isomorphism A₂↔A₁
B₁↝B₂′ : ∀ x → B₁ x ↝[ k₂ ] B₂ (_↔_.to A₁↔A₂ x)
B₁↝B₂′ x =
B₁ x ↝⟨ ≡⇒↝ _ $ cong B₁ $ sym $ _↔_.left-inverse-of A₁↔A₂ _ ⟩
B₁ (_↔_.from A₁↔A₂ (_↔_.to A₁↔A₂ x)) ↝⟨ ≡⇒↝ _ $ cong (λ f → B₁ (f (_↔_.to A₁↔A₂ x))) $ sym $
to-implication∘from-isomorphism k₁ bijection ⟩
B₁ (to-implication A₂↔A₁ (_↔_.to A₁↔A₂ x)) ↝⟨ B₁↝B₂ (_↔_.to A₁↔A₂ x) ⟩□
B₂ (_↔_.to A₁↔A₂ x) □
-- Variants of special cases of Σ-cong-contra.
Σ-cong-contra-→ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) → B₂ x) →
Σ A₁ B₁ → Σ A₂ B₂
Σ-cong-contra-→ {B₁ = B₁} A₂↠A₁ B₁→B₂ =
Σ-map (_↠_.from A₂↠A₁)
(B₁→B₂ _ ∘ subst B₁ (sym $ _↠_.right-inverse-of A₂↠A₁ _))
Σ-cong-contra-⇔ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) ⇔ B₂ x) →
Σ A₁ B₁ ⇔ Σ A₂ B₂
Σ-cong-contra-⇔ A₂↠A₁ B₁⇔B₂ =
inverse $
Surjection.Σ-cong-⇔ A₂↠A₁ (inverse ⊚ B₁⇔B₂)
-- ∃ preserves all kinds of functions. One could define
-- ∃-cong = Σ-cong Bijection.id, but the resulting "from" functions
-- would contain an unnecessary use of substitutivity, and I want to
-- avoid that.
private
∃-cong-impl : ∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x → B₂ x) → ∃ B₁ → ∃ B₂
∃-cong-impl B₁→B₂ = Σ-map id (λ {x} → B₁→B₂ x)
∃-cong-surj : ∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↠ B₂ x) → ∃ B₁ ↠ ∃ B₂
∃-cong-surj B₁↠B₂ = record
{ logical-equivalence = L.∃-cong (_↠_.logical-equivalence ⊚ B₁↠B₂)
; right-inverse-of = uncurry λ x y →
cong (_,_ x) (_↠_.right-inverse-of (B₁↠B₂ x) y)
}
∃-cong-bij : ∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↔ B₂ x) → ∃ B₁ ↔ ∃ B₂
∃-cong-bij B₁↔B₂ = record
{ surjection = ∃-cong-surj (_↔_.surjection ⊚ B₁↔B₂)
; left-inverse-of = uncurry λ x y →
cong (_,_ x) (_↔_.left-inverse-of (B₁↔B₂ x) y)
}
∃-cong-≃ᴱ :
∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ᴱ B₂ x) → ∃ B₁ ≃ᴱ ∃ B₂
∃-cong-≃ᴱ f = EEq.[≃]→≃ᴱ (EEq.[proofs] (Eq.∃-cong (EEq.≃ᴱ→≃ ⊚ f)))
∃-cong : ∀ {k a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↝[ k ] B₂ x) → ∃ B₁ ↝[ k ] ∃ B₂
∃-cong {implication} = ∃-cong-impl
∃-cong {logical-equivalence} = L.∃-cong
∃-cong {injection} = Σ-cong Bijection.id
∃-cong {embedding} = Σ-preserves-embeddings Emb.id
∃-cong {surjection} = ∃-cong-surj
∃-cong {bijection} = ∃-cong-bij
∃-cong {equivalence} = Eq.∃-cong
∃-cong {equivalenceᴱ} = ∃-cong-≃ᴱ
private
-- ∃-cong also works for _×_, in which case it is a more general
-- variant of id ×-cong_:
×-cong₂ : ∀ {k a b₁ b₂}
{A : Type a} {B₁ : Type b₁} {B₂ : Type b₂} →
(A → B₁ ↝[ k ] B₂) → A × B₁ ↝[ k ] A × B₂
×-cong₂ = ∃-cong
-- The following lemma is a more general variant of _×-cong id.
×-cong₁ : ∀ {k a₁ a₂ b}
{A₁ : Type a₁} {A₂ : Type a₂} {B : Type b} →
(B → A₁ ↝[ k ] A₂) → A₁ × B ↝[ k ] A₂ × B
×-cong₁ {A₁ = A₁} {A₂} {B} A₁↔A₂ =
A₁ × B ↔⟨ ×-comm ⟩
B × A₁ ↝⟨ ∃-cong A₁↔A₂ ⟩
B × A₂ ↔⟨ ×-comm ⟩□
A₂ × B □
-- Lemmas that can be used to simplify sigma types where one of the
-- two type arguments is (conditionally) related to the unit type.
drop-⊤-right : ∀ {k a b} {A : Type a} {B : A → Type b} →
((x : A) → B x ↝[ k ] ⊤) → Σ A B ↝[ k ] A
drop-⊤-right {A = A} {B} B↝⊤ =
Σ A B ↝⟨ ∃-cong B↝⊤ ⟩
A × ⊤ ↔⟨ ×-right-identity ⟩□
A □
drop-⊤-left-× : ∀ {k a b} {A : Type a} {B : Type b} →
(B → A ↝[ k ] ⊤) → A × B ↝[ k ] B
drop-⊤-left-× {A = A} {B} A↝⊤ =
A × B ↔⟨ ×-comm ⟩
B × A ↝⟨ drop-⊤-right A↝⊤ ⟩□
B □
drop-⊤-left-Σ : ∀ {a b} {A : Type a} {B : A → Type b} →
(A↔⊤ : A ↔ ⊤) →
Σ A B ↔ B (_↔_.from A↔⊤ tt)
drop-⊤-left-Σ {A = A} {B} A↔⊤ =
Σ A B ↝⟨ inverse $ Σ-cong (inverse A↔⊤) (λ _ → id) ⟩
Σ ⊤ (B ∘ _↔_.from A↔⊤) ↝⟨ Σ-left-identity ⟩□
B (_↔_.from A↔⊤ tt) □
-- Currying.
currying :
∀ {a b c} {A : Type a} {B : A → Type b} {C : Σ A B → Type c} →
((p : Σ A B) → C p) ↔ ((x : A) (y : B x) → C (x , y))
currying = record
{ surjection = record
{ logical-equivalence = record { to = curry; from = uncurry }
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Some lemmas relating functions from binary sums and pairs of
-- functions.
Π⊎↠Π×Π :
∀ {a b c} {A : Type a} {B : Type b} {C : A ⊎ B → Type c} →
((x : A ⊎ B) → C x)
↠
((x : A) → C (inj₁ x)) × ((y : B) → C (inj₂ y))
Π⊎↠Π×Π = record
{ logical-equivalence = record
{ to = λ f → f ⊚ inj₁ , f ⊚ inj₂
; from = uncurry [_,_]
}
; right-inverse-of = refl
}
Π⊎↔Π×Π :
∀ {a b c} {A : Type a} {B : Type b} {C : A ⊎ B → Type c} →
((x : A ⊎ B) → C x)
↝[ a ⊔ b ∣ c ]
((x : A) → C (inj₁ x)) × ((y : B) → C (inj₂ y))
Π⊎↔Π×Π =
generalise-ext?
(_↠_.logical-equivalence Π⊎↠Π×Π)
(λ ext →
refl
, (λ _ → apply-ext ext [ refl ⊚ _ , refl ⊚ _ ]))
-- ∃ distributes "from the left" over _⊎_.
∃-⊎-distrib-left :
∀ {a b c} {A : Type a} {B : A → Type b} {C : A → Type c} →
(∃ λ x → B x ⊎ C x) ↔ ∃ B ⊎ ∃ C
∃-⊎-distrib-left = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ x → [ inj₁ ⊚ _,_ x , inj₂ ⊚ _,_ x ]
; from = [ Σ-map id inj₁ , Σ-map id inj₂ ]
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of =
uncurry λ x → [ refl ⊚ _,_ x ⊚ inj₁ , refl ⊚ _,_ x ⊚ inj₂ ]
}
-- ∃ also distributes "from the right" over _⊎_.
∃-⊎-distrib-right :
∀ {a b c} {A : Type a} {B : Type b} {C : A ⊎ B → Type c} →
Σ (A ⊎ B) C ↔ Σ A (C ⊚ inj₁) ⊎ Σ B (C ⊚ inj₂)
∃-⊎-distrib-right {A = A} {B} {C} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of = from∘to
}
where
to : Σ (A ⊎ B) C → Σ A (C ⊚ inj₁) ⊎ Σ B (C ⊚ inj₂)
to (inj₁ x , y) = inj₁ (x , y)
to (inj₂ x , y) = inj₂ (x , y)
from = [ Σ-map inj₁ id , Σ-map inj₂ id ]
from∘to : ∀ p → from (to p) ≡ p
from∘to (inj₁ x , y) = refl _
from∘to (inj₂ x , y) = refl _
-- ∃ is "commutative".
∃-comm : ∀ {a b c} {A : Type a} {B : Type b} {C : A → B → Type c} →
(∃ λ x → ∃ λ y → C x y) ↔ (∃ λ y → ∃ λ x → C x y)
∃-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ x → uncurry λ y z → (y , (x , z))
; from = uncurry λ x → uncurry λ y z → (y , (x , z))
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- One can introduce an existential by also introducing an equality.
∃-intro : ∀ {a b} {A : Type a} (B : A → Type b) (x : A) →
B x ↔ ∃ λ y → B y × y ≡ x
∃-intro B x = _≃_.bijection $ Eq.↔→≃
(λ b → x , b , refl _)
(λ (y , b , y≡x) → subst B y≡x b)
(λ (y , b , y≡x) →
sym $
Σ-≡,≡→≡
y≡x
(subst (λ y → B y × y ≡ x) y≡x (b , y≡x) ≡⟨ push-subst-, _ _ ⟩
subst B y≡x b , subst (_≡ x) y≡x y≡x ≡⟨ cong (_ ,_) subst-trans-sym ⟩
subst B y≡x b , trans (sym y≡x) y≡x ≡⟨ cong (_ ,_) $ trans-symˡ _ ⟩∎
subst B y≡x b , refl x ∎))
(subst-refl B)
-- A variant of ∃-intro.
other-∃-intro :
∀ {a b} {A : Type a} (B : A → Type b) (x : A) →
B x ≃ ∃ λ y → B y × x ≡ y
other-∃-intro B x = Eq.↔→≃
(λ b → x , b , refl _)
(λ (y , b , x≡y) → subst B (sym x≡y) b)
(λ (y , b , x≡y) →
Σ-≡,≡→≡
x≡y
(subst (λ y → B y × x ≡ y) x≡y (subst B (sym x≡y) b , refl x) ≡⟨ push-subst-, _ _ ⟩
subst B x≡y (subst B (sym x≡y) b) , subst (x ≡_) x≡y (refl x) ≡⟨ cong₂ _,_
(subst-subst-sym _ _ _)
(trans (sym trans-subst) $
trans-reflˡ _) ⟩∎
b , x≡y ∎))
(λ b →
subst B (sym (refl _)) b ≡⟨ cong (flip (subst B) _) sym-refl ⟩
subst B (refl _) b ≡⟨ subst-refl _ _ ⟩∎
b ∎)
-- Another variant of ∃-intro.
∃-introduction :
∀ {a b} {A : Type a} {x : A} (B : (y : A) → x ≡ y → Type b) →
B x (refl x) ↔ ∃ λ y → ∃ λ (x≡y : x ≡ y) → B y x≡y
∃-introduction {x = x} B =
B x (refl x) ↝⟨ ∃-intro (uncurry B) _ ⟩
(∃ λ { (y , x≡y) → B y x≡y × (y , x≡y) ≡ (x , refl x) }) ↝⟨ (∃-cong λ _ → ∃-cong λ _ →
_⇔_.to contractible⇔↔⊤ $
⇒≡ 0 (other-singleton-contractible x)) ⟩
(∃ λ { (y , x≡y) → B y x≡y × ⊤ }) ↝⟨ (∃-cong λ _ → ×-right-identity) ⟩
(∃ λ { (y , x≡y) → B y x≡y }) ↝⟨ inverse Σ-assoc ⟩□
(∃ λ y → ∃ λ x≡y → B y x≡y) □
-- A non-dependent variant of Σ-≡,≡↔≡.
--
-- This property used to be defined in terms of Σ-≡,≡↔≡, but was
-- changed in order to make it compute in a different way.
≡×≡↔≡ : ∀ {a b} {A : Type a} {B : Type b} {p₁ p₂ : A × B} →
(proj₁ p₁ ≡ proj₁ p₂ × proj₂ p₁ ≡ proj₂ p₂) ↔ (p₁ ≡ p₂)
≡×≡↔≡ {B = B} {p₁} {p₂} = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry (cong₂ _,_)
; from = λ eq → cong proj₁ eq , cong proj₂ eq
}
; right-inverse-of = λ eq →
cong₂ _,_ (cong proj₁ eq) (cong proj₂ eq) ≡⟨ cong₂-cong-cong _ _ _,_ ⟩
cong (λ p → proj₁ p , proj₂ p) eq ≡⟨⟩
cong id eq ≡⟨ sym $ cong-id _ ⟩∎
eq ∎
}
; left-inverse-of = λ { (eq₁ , eq₂) →
cong proj₁ (cong₂ _,_ eq₁ eq₂) , cong proj₂ (cong₂ _,_ eq₁ eq₂) ≡⟨ cong₂ _,_ (cong-proj₁-cong₂-, eq₁ eq₂) (cong-proj₂-cong₂-, eq₁ eq₂) ⟩∎
eq₁ , eq₂ ∎
}
}
-- If one is given an equality between pairs, where the second
-- components of the pairs are propositional, then one can restrict
-- attention to the first components.
ignore-propositional-component :
∀ {a b} {A : Type a} {B : A → Type b} {p q : Σ A B} →
Is-proposition (B (proj₁ q)) →
(proj₁ p ≡ proj₁ q) ↔ (p ≡ q)
ignore-propositional-component {B = B} {p₁ , p₂} {q₁ , q₂} Bq₁-prop =
(p₁ ≡ q₁) ↝⟨ inverse ×-right-identity ⟩
(p₁ ≡ q₁ × ⊤) ↝⟨ ∃-cong (λ _ → inverse $ _⇔_.to contractible⇔↔⊤ (+⇒≡ Bq₁-prop)) ⟩
(∃ λ (eq : p₁ ≡ q₁) → subst B eq p₂ ≡ q₂) ↝⟨ Bijection.Σ-≡,≡↔≡ ⟩□
((p₁ , p₂) ≡ (q₁ , q₂)) □
-- Contractible commutes with _×_ (assuming extensionality).
Contractible-commutes-with-× :
∀ {x y} {X : Type x} {Y : Type y} →
Contractible (X × Y) ↝[ x ⊔ y ∣ x ⊔ y ]
(Contractible X × Contractible Y)
Contractible-commutes-with-× {x = x} {y} =
generalise-ext?-prop
(record
{ to = λ cX×Y →
lemma cX×Y ,
lemma (H-level.respects-surjection
(_↔_.surjection ×-comm) 0 cX×Y)
; from = λ { ((x , eq₁) , (y , eq₂)) →
(x , y) ,
λ { (x′ , y′) →
(x , y) ≡⟨ cong₂ _,_ (eq₁ x′) (eq₂ y′) ⟩∎
(x′ , y′) ∎ } }
})
Contractible-propositional
(λ ext → ×-closure 1 (Contractible-propositional
(lower-extensionality y y ext))
(Contractible-propositional
(lower-extensionality x x ext)))
where
lemma : ∀ {x y} {X : Type x} {Y : Type y} →
Contractible (X × Y) → Contractible X
lemma ((x , y) , eq) = x , λ x′ →
x ≡⟨⟩
proj₁ (x , y) ≡⟨ cong proj₁ (eq (x′ , y)) ⟩∎
proj₁ (x′ , y) ∎
------------------------------------------------------------------------
-- Some lemmas relating equality of certain kinds of functions to
-- pointwise equality of the underlying functions
-- Equality of equivalences is isomorphic to pointwise equality of the
-- underlying functions (assuming extensionality).
≃-to-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ≃ B} →
(∀ x → _≃_.to p x ≡ _≃_.to q x) ↔ p ≡ q
≃-to-≡↔≡ {a} {b} ext {p = p} {q} =
(∀ x → _≃_.to p x ≡ _≃_.to q x) ↔⟨ Eq.extensionality-isomorphism (lower-extensionality b a ext) ⟩
_≃_.to p ≡ _≃_.to q ↝⟨ ignore-propositional-component (Eq.propositional ext _) ⟩
(_≃_.to p , _≃_.is-equivalence p) ≡ (_≃_.to q , _≃_.is-equivalence q) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Eq.≃-as-Σ) ⟩□
p ≡ q □
-- A variant of the previous result for which both directions compute
-- in certain ways.
≃-to-≡≃≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Extensionality a b →
{A : Type a} {B : Type b} {p q : A ≃ B} →
(∀ x → _≃_.to p x ≡ _≃_.to q x) ≃ (p ≡ q)
≃-to-≡≃≡ ext₁ ext₂ {p = p} {q = q} =
Eq.↔→≃
(Eq.lift-equality ext₁ ⊚ apply-ext (Eq.good-ext ext₂))
(flip $ cong ⊚ flip _≃_.to)
(elim¹
(λ p≡q →
Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂)
(λ x → cong (λ eq → _≃_.to eq x) p≡q)) ≡
p≡q)
(Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂)
(λ x → cong (λ eq → _≃_.to eq x) (refl _))) ≡⟨ (cong (Eq.lift-equality ext₁) $
cong (apply-ext (Eq.good-ext ext₂)) $
apply-ext ext₂ λ _ →
cong-refl _) ⟩
Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂) (λ _ → refl _)) ≡⟨ cong (Eq.lift-equality ext₁) $
Eq.good-ext-refl ext₂ _ ⟩
Eq.lift-equality ext₁ (refl _) ≡⟨ Eq.lift-equality-refl ext₁ ⟩
cong Eq.⟨ _≃_.to p ,_⟩ _ ≡⟨ cong (cong Eq.⟨ _≃_.to p ,_⟩) $
mono₁ 1 (Eq.propositional ext₁ _) _ _ ⟩
cong Eq.⟨ _≃_.to p ,_⟩ (refl _) ≡⟨ cong-refl _ ⟩∎
refl _ ∎))
(λ p≡q → apply-ext ext₂ λ x →
cong (λ eq → _≃_.to eq x)
(Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂) p≡q)) ≡⟨ elim¹
(λ {g} p≡g →
(eq : Is-equivalence g) →
cong (λ eq → _≃_.to eq x)
(Eq.lift-equality ext₁ {q = Eq.⟨ _ , eq ⟩} p≡g) ≡
ext⁻¹ p≡g x)
(λ eq →
cong (λ eq → _≃_.to eq x)
(Eq.lift-equality ext₁ (refl _)) ≡⟨ cong (cong _) $ Eq.lift-equality-refl ext₁ ⟩
cong (λ eq → _≃_.to eq x)
(cong Eq.⟨ _≃_.to p ,_⟩ _) ≡⟨ cong-∘ _ _ _ ⟩
cong (const (_≃_.to p x)) _ ≡⟨ cong-const _ ⟩
refl _ ≡⟨ sym $ cong-refl _ ⟩∎
ext⁻¹ (refl _) x ∎)
(apply-ext (Eq.good-ext ext₂) p≡q)
_ ⟩
ext⁻¹ (apply-ext (Eq.good-ext ext₂) p≡q) x ≡⟨ cong (_$ x) $
_≃_.left-inverse-of (Eq.extensionality-isomorphism ext₂) _ ⟩∎
p≡q x ∎)
-- Equality of equivalences is isomorphic to pointwise equality of the
-- underlying /inverse/ functions (assuming extensionality).
≃-from-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ≃ B} →
(∀ x → _≃_.from p x ≡ _≃_.from q x) ↔ p ≡ q
≃-from-≡↔≡ ext {p = p} {q} =
(∀ x → _≃_.from p x ≡ _≃_.from q x) ↝⟨ ≃-to-≡↔≡ ext ⟩
inverse p ≡ inverse q ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (Eq.inverse-isomorphism ext)) ⟩□
p ≡ q □
-- Equality of bijections between a set and a type is isomorphic to
-- pointwise equality of the underlying functions (assuming
-- extensionality).
↔-to-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ↔ B} →
Is-set A →
(∀ x → _↔_.to p x ≡ _↔_.to q x) ↔ p ≡ q
↔-to-≡↔≡ ext {p = p} {q} A-set =
(∀ x → _↔_.to p x ≡ _↔_.to q x) ↝⟨ id ⟩
(∀ x → _≃_.to (Eq.↔⇒≃ p) x ≡ _≃_.to (Eq.↔⇒≃ q) x) ↝⟨ ≃-to-≡↔≡ ext ⟩
Eq.↔⇒≃ p ≡ Eq.↔⇒≃ q ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (Eq.↔↔≃ ext A-set)) ⟩□
p ≡ q □
-- Equality of bijections between a set and a type is isomorphic to
-- pointwise equality of the underlying /inverse/ functions (assuming
-- extensionality).
↔-from-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ↔ B} →
Is-set A →
(∀ x → _↔_.from p x ≡ _↔_.from q x) ↔ p ≡ q
↔-from-≡↔≡ ext {p = p} {q} A-set =
(∀ x → _↔_.from p x ≡ _↔_.from q x) ↝⟨ id ⟩
(∀ x → _≃_.from (Eq.↔⇒≃ p) x ≡ _≃_.from (Eq.↔⇒≃ q) x) ↝⟨ ≃-from-≡↔≡ ext ⟩
Eq.↔⇒≃ p ≡ Eq.↔⇒≃ q ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (Eq.↔↔≃ ext A-set)) ⟩□
p ≡ q □
-- Equality of embeddings is isomorphic to pointwise equality of the
-- underlying functions (assuming extensionality).
Embedding-to-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : Embedding A B} →
(∀ x → Embedding.to p x ≡ Embedding.to q x) ↔ p ≡ q
Embedding-to-≡↔≡ {a} {b} ext {p = p} {q} =
(∀ x → Embedding.to p x ≡ Embedding.to q x) ↔⟨ Eq.extensionality-isomorphism (lower-extensionality b a ext) ⟩
Embedding.to p ≡ Embedding.to q ↝⟨ ignore-propositional-component (Emb.Is-embedding-propositional ext) ⟩
(Embedding.to p , Embedding.is-embedding p) ≡
(Embedding.to q , Embedding.is-embedding q) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Emb.Embedding-as-Σ) ⟩□
p ≡ q □
------------------------------------------------------------------------
-- _⊎_ and _×_ form a commutative semiring
-- _×_ distributes from the left over _⊎_.
×-⊎-distrib-left : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
A × (B ⊎ C) ↔ (A × B) ⊎ (A × C)
×-⊎-distrib-left = ∃-⊎-distrib-left
-- _×_ distributes from the right over _⊎_.
×-⊎-distrib-right : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(A ⊎ B) × C ↔ (A × C) ⊎ (B × C)
×-⊎-distrib-right = ∃-⊎-distrib-right
------------------------------------------------------------------------
-- Some lemmas related to functions
-- The non-dependent function space preserves non-dependent functions
-- (contravariantly for the domain).
→-cong-→ : ∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
(B → A) → (C → D) → (A → C) → (B → D)
→-cong-→ B→A C→D = (C→D ∘_) ∘ (_∘ B→A)
-- The non-dependent function space preserves split surjections
-- (assuming extensionality).
→-cong-↠ : ∀ {a b c d} → Extensionality b d →
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
A ↠ B → C ↠ D → (A → C) ↠ (B → D)
→-cong-↠ {a} {b} {c} {d} ext A↠B C↠D = record
{ logical-equivalence = logical-equiv
; right-inverse-of = right-inv
}
where
open _↠_
logical-equiv = L.→-cong (_↠_.logical-equivalence A↠B)
(_↠_.logical-equivalence C↠D)
abstract
right-inv :
∀ f → _⇔_.to logical-equiv (_⇔_.from logical-equiv f) ≡ f
right-inv f = apply-ext ext λ x →
to C↠D (from C↠D (f (to A↠B (from A↠B x)))) ≡⟨ right-inverse-of C↠D _ ⟩
f (to A↠B (from A↠B x)) ≡⟨ cong f $ right-inverse-of A↠B _ ⟩∎
f x ∎
private
-- Lemmas used in the implementation of →-cong.
→-cong-↔ : ∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Extensionality (a ⊔ b) (c ⊔ d) →
A ↔ B → C ↔ D → (A → C) ↔ (B → D)
→-cong-↔ {a} {b} {c} {d} ext A↔B C↔D = record
{ surjection = surj
; left-inverse-of = left-inv
}
where
open _↔_
surj = →-cong-↠ (lower-extensionality a c ext)
(_↔_.surjection A↔B)
(_↔_.surjection C↔D)
abstract
left-inv :
∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
left-inv f = apply-ext (lower-extensionality b d ext) λ x →
from C↔D (to C↔D (f (from A↔B (to A↔B x)))) ≡⟨ left-inverse-of C↔D _ ⟩
f (from A↔B (to A↔B x)) ≡⟨ cong f $ left-inverse-of A↔B _ ⟩∎
f x ∎
→-cong-≃ :
∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Extensionality (a ⊔ b) (c ⊔ d) →
A ≃ B → C ≃ D → (A → C) ≃ (B → D)
→-cong-≃ ext A≃B C≃D = record
{ to = to
; is-equivalence = from , proofs
}
where
A→C≃B→D =
Eq.↔⇒≃ (→-cong-↔ ext (_≃_.bijection A≃B) (_≃_.bijection C≃D))
to = _≃_.to A→C≃B→D
from = _≃_.from A→C≃B→D
abstract
proofs : HA.Proofs to from
proofs = proj₂ (_≃_.is-equivalence A→C≃B→D)
→-cong-≃ᴱ :
∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Erased (Extensionality (a ⊔ b) (c ⊔ d)) →
A ≃ᴱ B → C ≃ᴱ D → (A → C) ≃ᴱ (B → D)
→-cong-≃ᴱ E.[ ext ] f g =
EEq.[≃]→≃ᴱ (EEq.[proofs] (→-cong-≃ ext (EEq.≃ᴱ→≃ f) (EEq.≃ᴱ→≃ g)))
-- The non-dependent function space preserves symmetric kinds of
-- functions (in some cases assuming extensionality).
→-cong : ∀ {k a b c d} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b) (c ⊔ d) →
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
A ↝[ ⌊ k ⌋-sym ] B → C ↝[ ⌊ k ⌋-sym ] D →
(A → C) ↝[ ⌊ k ⌋-sym ] (B → D)
→-cong {logical-equivalence} _ = L.→-cong
→-cong {bijection} ext = →-cong-↔ ext
→-cong {equivalence} ext = →-cong-≃ ext
→-cong {equivalenceᴱ} ext = →-cong-≃ᴱ ext
-- A variant of →-cong.
→-cong₁ :
∀ {k₁ k₂ a b c} →
Extensionality? k₂ (a ⊔ b) c →
{A : Type a} {B : Type b} {C : Type c} →
A ↔[ k₁ ] B → (A → C) ↝[ k₂ ] (B → C)
→-cong₁ ext hyp = generalise-ext?-sym
(λ ext → →-cong ext (from-bijection (from-isomorphism hyp)) id)
ext
private
-- Lemmas used in the implementation of ∀-cong.
∀-cong-→ :
∀ {a b₁ b₂} {A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x → B₂ x) →
((x : A) → B₁ x) → ((x : A) → B₂ x)
∀-cong-→ B₁→B₂ = B₁→B₂ _ ⊚_
∀-cong-bij :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↔ B₂ x) →
((x : A) → B₁ x) ↔ ((x : A) → B₂ x)
∀-cong-bij {b₂ = b₂} ext B₁↔B₂ = record
{ surjection = surj
; left-inverse-of = left-inverse-of
}
where
surj = Surjection.∀-cong ext (_↔_.surjection ⊚ B₁↔B₂)
abstract
left-inverse-of : ∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
left-inverse-of = λ f →
apply-ext (lower-extensionality lzero b₂ ext) λ x →
_↔_.from (B₁↔B₂ x) (_↔_.to (B₁↔B₂ x) (f x)) ≡⟨ _↔_.left-inverse-of (B₁↔B₂ x) (f x) ⟩∎
f x ∎
∀-cong-eq :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ B₂ x) →
((x : A) → B₁ x) ≃ ((x : A) → B₂ x)
∀-cong-eq ext = Eq.↔⇒≃ ⊚ ∀-cong-bij ext ⊚ (_≃_.bijection ⊚_)
∀-cong-eqᴱ :
∀ {a b₁ b₂} →
Erased (Extensionality a (b₁ ⊔ b₂)) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ᴱ B₂ x) →
((x : A) → B₁ x) ≃ᴱ ((x : A) → B₂ x)
∀-cong-eqᴱ E.[ ext ] f =
EEq.[≃]→≃ᴱ (EEq.[proofs] (∀-cong-eq ext (EEq.≃ᴱ→≃ ⊚ f)))
∀-cong-inj :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↣ B₂ x) →
((x : A) → B₁ x) ↣ ((x : A) → B₂ x)
∀-cong-inj {b₁ = b₁} {b₂} ext B₁↣B₂ = record
{ to = to
; injective = injective
}
where
to = ∀-cong-→ (_↣_.to ⊚ B₁↣B₂)
abstract
injective : Injective to
injective {x = f} {y = g} =
(λ x → _↣_.to (B₁↣B₂ x) (f x)) ≡ (λ x → _↣_.to (B₁↣B₂ x) (g x)) ↔⟨ inverse $ Eq.extensionality-isomorphism
(lower-extensionality lzero b₁ ext) ⟩
(∀ x → _↣_.to (B₁↣B₂ x) (f x) ≡ _↣_.to (B₁↣B₂ x) (g x)) ↝⟨ ∀-cong-→ (λ x → _↣_.injective (B₁↣B₂ x)) ⟩
(∀ x → f x ≡ g x) ↔⟨ Eq.extensionality-isomorphism
(lower-extensionality lzero b₂ ext) ⟩□
f ≡ g □
∀-cong-emb :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → Embedding (B₁ x) (B₂ x)) →
Embedding ((x : A) → B₁ x) ((x : A) → B₂ x)
∀-cong-emb {b₁ = b₁} {b₂} ext B₁↣B₂ = record
{ to = to
; is-embedding = is-embedding
}
where
to = ∀-cong-→ (Embedding.to ⊚ B₁↣B₂)
ext₂ = lower-extensionality lzero b₁ ext
abstract
is-embedding : Is-embedding to
is-embedding f g = _≃_.is-equivalence $
Eq.with-other-function
(f ≡ g ↝⟨ inverse $ Eq.extensionality-isomorphism
(lower-extensionality lzero b₂ ext) ⟩
(∀ x → f x ≡ g x) ↝⟨ ∀-cong-eq ext (λ x →
Eq.⟨ _ , Embedding.is-embedding (B₁↣B₂ x) (f x) (g x) ⟩) ⟩
(∀ x → Embedding.to (B₁↣B₂ x) (f x) ≡
Embedding.to (B₁↣B₂ x) (g x)) ↝⟨ Eq.extensionality-isomorphism ext₂ ⟩□
(λ x → Embedding.to (B₁↣B₂ x) (f x)) ≡
(λ x → Embedding.to (B₁↣B₂ x) (g x)) □)
_
(λ f≡g →
apply-ext (Eq.good-ext ext₂)
(λ x → cong (Embedding.to (B₁↣B₂ x)) (ext⁻¹ f≡g x)) ≡⟨⟩
apply-ext (Eq.good-ext ext₂)
(λ x → cong (Embedding.to (B₁↣B₂ x)) (cong (_$ x) f≡g)) ≡⟨ cong (apply-ext (Eq.good-ext ext₂)) (apply-ext ext₂ λ _ →
cong-∘ _ _ _) ⟩
apply-ext (Eq.good-ext ext₂)
(λ x → cong (λ h → Embedding.to (B₁↣B₂ x) (h x)) f≡g) ≡⟨ cong (apply-ext (Eq.good-ext ext₂)) (apply-ext ext₂ λ _ → sym $
cong-∘ _ _ _) ⟩
apply-ext (Eq.good-ext ext₂)
(λ x → cong (_$ x)
(cong (λ h x → Embedding.to (B₁↣B₂ x) (h x))
f≡g)) ≡⟨⟩
apply-ext (Eq.good-ext ext₂)
(ext⁻¹ (cong (λ h x → Embedding.to (B₁↣B₂ x) (h x)) f≡g)) ≡⟨ _≃_.right-inverse-of (Eq.extensionality-isomorphism ext₂) _ ⟩∎
cong (λ h x → Embedding.to (B₁↣B₂ x) (h x)) f≡g ∎)
-- Π preserves all kinds of functions in its second argument (in some
-- cases assuming extensionality).
∀-cong :
∀ {k a b₁ b₂} →
Extensionality? k a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↝[ k ] B₂ x) →
((x : A) → B₁ x) ↝[ k ] ((x : A) → B₂ x)
∀-cong {implication} = λ _ → ∀-cong-→
∀-cong {logical-equivalence} = λ _ → L.∀-cong
∀-cong {injection} = ∀-cong-inj
∀-cong {embedding} = ∀-cong-emb
∀-cong {surjection} = Surjection.∀-cong
∀-cong {bijection} = ∀-cong-bij
∀-cong {equivalence} = ∀-cong-eq
∀-cong {equivalenceᴱ} = ∀-cong-eqᴱ
-- The implicit variant of Π preserves all kinds of functions in its
-- second argument (in some cases assuming extensionality).
implicit-∀-cong :
∀ {k a b₁ b₂} →
Extensionality? k a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ {x} → B₁ x ↝[ k ] B₂ x) →
({x : A} → B₁ x) ↝[ k ] ({x : A} → B₂ x)
implicit-∀-cong ext {A} {B₁} {B₂} B₁↝B₂ =
({x : A} → B₁ x) ↔⟨ Bijection.implicit-Π↔Π ⟩
((x : A) → B₁ x) ↝⟨ ∀-cong ext (λ _ → B₁↝B₂) ⟩
((x : A) → B₂ x) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
({x : A} → B₂ x) □
-- Two generalisations of ∀-cong for non-dependent functions.
Π-cong-contra-→ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂→A₁ : A₂ → A₁) →
(∀ x → B₁ (A₂→A₁ x) → B₂ x) →
((x : A₁) → B₁ x) → ((x : A₂) → B₂ x)
Π-cong-contra-→ {B₁ = B₁} {B₂} A₂→A₁ B₁→B₂ f x =
$⟨ f (A₂→A₁ x) ⟩
B₁ (A₂→A₁ x) ↝⟨ B₁→B₂ x ⟩
B₂ x □
Π-cong-→ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ x → B₁ x → B₂ (_↠_.to A₁↠A₂ x)) →
((x : A₁) → B₁ x) → ((x : A₂) → B₂ x)
Π-cong-→ {B₁ = B₁} {B₂} A₁↠A₂ B₁→B₂ f x =
$⟨ f (_↠_.from A₁↠A₂ x) ⟩
B₁ (_↠_.from A₁↠A₂ x) ↝⟨ B₁→B₂ (_↠_.from A₁↠A₂ x) ⟩
B₂ (_↠_.to A₁↠A₂ (_↠_.from A₁↠A₂ x)) ↝⟨ subst B₂ (_↠_.right-inverse-of A₁↠A₂ x) ⟩□
B₂ x □
-- Two generalisations of ∀-cong for logical equivalences.
Π-cong-⇔ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ x → B₁ x ⇔ B₂ (_↠_.to A₁↠A₂ x)) →
((x : A₁) → B₁ x) ⇔ ((x : A₂) → B₂ x)
Π-cong-⇔ {A₁ = A₁} {A₂} {B₁} {B₂} A₁↠A₂ B₁⇔B₂ = record
{ to = Π-cong-→ A₁↠A₂ (_⇔_.to ⊚ B₁⇔B₂)
; from = Π-cong-contra-→ (_↠_.to A₁↠A₂) (_⇔_.from ⊚ B₁⇔B₂)
}
Π-cong-contra-⇔ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) ⇔ B₂ x) →
((x : A₁) → B₁ x) ⇔ ((x : A₂) → B₂ x)
Π-cong-contra-⇔ {A₁ = A₁} {A₂} {B₁} {B₂} A₂↠A₁ B₁⇔B₂ = record
{ to = Π-cong-contra-→ (_↠_.to A₂↠A₁) (_⇔_.to ⊚ B₁⇔B₂)
; from = Π-cong-→ A₂↠A₁ (_⇔_.from ⊚ B₁⇔B₂)
}
-- A generalisation of ∀-cong for split surjections.
Π-cong-↠ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₂ b₂ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ x → B₁ x ↠ B₂ (_↠_.to A₁↠A₂ x)) →
((x : A₁) → B₁ x) ↠ ((x : A₂) → B₂ x)
Π-cong-↠ ext {B₂ = B₂} A₁↠A₂ B₁↠B₂ = record
{ logical-equivalence = equiv
; right-inverse-of = to∘from
}
where
equiv = Π-cong-⇔ A₁↠A₂ (_↠_.logical-equivalence ⊚ B₁↠B₂)
abstract
to∘from : ∀ f → _⇔_.to equiv (_⇔_.from equiv f) ≡ f
to∘from f = apply-ext ext λ x →
subst B₂ (_↠_.right-inverse-of A₁↠A₂ x)
(_↠_.to (B₁↠B₂ (_↠_.from A₁↠A₂ x))
(_↠_.from (B₁↠B₂ (_↠_.from A₁↠A₂ x))
(f (_↠_.to A₁↠A₂ (_↠_.from A₁↠A₂ x))))) ≡⟨ cong (subst B₂ (_↠_.right-inverse-of A₁↠A₂ x)) $ _↠_.right-inverse-of (B₁↠B₂ _) _ ⟩
subst B₂ (_↠_.right-inverse-of A₁↠A₂ x)
(f (_↠_.to A₁↠A₂ (_↠_.from A₁↠A₂ x))) ≡⟨ dcong f _ ⟩∎
f x ∎
-- A generalisation of ∀-cong for injections.
Π-cong-contra-↣ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₁ b₁ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) ↣ B₂ x) →
((x : A₁) → B₁ x) ↣ ((x : A₂) → B₂ x)
Π-cong-contra-↣ ext A₂↠A₁ B₁↣B₂ = record
{ to = to
; injective = injective
}
where
to = Π-cong-contra-→ (_↠_.to A₂↠A₁) (_↣_.to ⊚ B₁↣B₂)
abstract
injective : Injective to
injective {x = f} {y = g} to-f≡to-g = apply-ext ext λ x →
let x′ = _↠_.to A₂↠A₁ (_↠_.from A₂↠A₁ x) in
$⟨ to-f≡to-g ⟩
(λ x → _↣_.to (B₁↣B₂ x) (f (_↠_.to A₂↠A₁ x))) ≡
(λ x → _↣_.to (B₁↣B₂ x) (g (_↠_.to A₂↠A₁ x))) ↝⟨ cong (_$ _) ⟩
_↣_.to (B₁↣B₂ (_↠_.from A₂↠A₁ x)) (f x′) ≡
_↣_.to (B₁↣B₂ (_↠_.from A₂↠A₁ x)) (g x′) ↝⟨ _↣_.injective (B₁↣B₂ _) ⟩
f x′ ≡ g x′ ↝⟨ subst (λ x → f x ≡ g x) $ _↠_.right-inverse-of A₂↠A₁ x ⟩□
f x ≡ g x □
private
-- Lemmas used in the implementations of Π-cong and Π-cong-contra.
Π-cong-contra-↠ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₂ b₂ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ↠ B₂ x) →
((x : A₁) → B₁ x) ↠ ((x : A₂) → B₂ x)
Π-cong-contra-↠ ext {B₁ = B₁} A₂≃A₁ B₁↠B₂ = record
{ logical-equivalence = equiv
; right-inverse-of = to∘from
}
where
equiv = Π-cong-contra-⇔ (_≃_.surjection A₂≃A₁)
(_↠_.logical-equivalence ⊚ B₁↠B₂)
abstract
to∘from : ∀ f → _⇔_.to equiv (_⇔_.from equiv f) ≡ f
to∘from f = apply-ext ext λ x →
_↠_.to (B₁↠B₂ x)
(subst B₁ (_≃_.right-inverse-of A₂≃A₁ (_≃_.to A₂≃A₁ x))
(_↠_.from (B₁↠B₂ (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x)))
(f (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x))))) ≡⟨ cong (λ eq → _↠_.to (B₁↠B₂ x)
(subst B₁ eq (_↠_.from (B₁↠B₂ _) (f _)))) $ sym $
_≃_.left-right-lemma A₂≃A₁ _ ⟩
_↠_.to (B₁↠B₂ x)
(subst B₁ (cong (_≃_.to A₂≃A₁) $ _≃_.left-inverse-of A₂≃A₁ x)
(_↠_.from (B₁↠B₂ (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x)))
(f (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x))))) ≡⟨ cong (_↠_.to (B₁↠B₂ x)) $ sym $ subst-∘ _ _ _ ⟩
_↠_.to (B₁↠B₂ x)
(subst (B₁ ∘ _≃_.to A₂≃A₁) (_≃_.left-inverse-of A₂≃A₁ x)
(_↠_.from (B₁↠B₂ (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x)))
(f (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x))))) ≡⟨ cong (_↠_.to (B₁↠B₂ x)) $
dcong (λ x → _↠_.from (B₁↠B₂ x) (f x)) _ ⟩
_↠_.to (B₁↠B₂ x) (_↠_.from (B₁↠B₂ x) (f x)) ≡⟨ _↠_.right-inverse-of (B₁↠B₂ x) _ ⟩∎
f x ∎
Π-cong-↔ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ↔ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ↔ ((x : A₂) → B₂ x)
Π-cong-↔ {a₁} {a₂} {b₁} {b₂} ext {B₂ = B₂} A₁≃A₂ B₁↔B₂ = record
{ surjection = surj
; left-inverse-of = from∘to
}
where
surj = Π-cong-↠ (lower-extensionality a₁ b₁ ext)
(_≃_.surjection A₁≃A₂) (_↔_.surjection ⊚ B₁↔B₂)
abstract
from∘to : ∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
from∘to =
_↠_.right-inverse-of $
Π-cong-contra-↠ (lower-extensionality a₂ b₂ ext)
{B₁ = B₂}
A₁≃A₂
(_↔_.surjection ⊚ inverse ⊚ B₁↔B₂)
Π-cong-contra-↔ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ↔ B₂ x) →
((x : A₁) → B₁ x) ↔ ((x : A₂) → B₂ x)
Π-cong-contra-↔ {a₁} {a₂} {b₁} {b₂} ext {B₂ = B₂} A₂≃A₁ B₁↔B₂ = record
{ surjection = surj
; left-inverse-of = from∘to
}
where
surj = Π-cong-contra-↠ (lower-extensionality a₁ b₁ ext)
A₂≃A₁ (_↔_.surjection ⊚ B₁↔B₂)
abstract
from∘to : ∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
from∘to =
_↠_.right-inverse-of $
Π-cong-↠ (lower-extensionality a₂ b₂ ext)
(_≃_.surjection A₂≃A₁)
(_↔_.surjection ⊚ inverse ⊚ B₁↔B₂)
Π-cong-≃ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ≃ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ≃ ((x : A₂) → B₂ x)
Π-cong-≃ ext A₁≃A₂ =
from-isomorphism ⊚ Π-cong-↔ ext A₁≃A₂ ⊚ (from-isomorphism ⊚_)
Π-cong-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} →
Erased (Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂)) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ≃ᴱ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ≃ᴱ ((x : A₂) → B₂ x)
Π-cong-≃ᴱ E.[ ext ] {B₂ = B₂} f g =
EEq.[≃]→≃ᴱ
{to = λ h x → subst B₂ (_≃_.right-inverse-of f x)
(_≃ᴱ_.to (g (_≃_.from f x)) (h (_≃_.from f x)))}
{from = λ h x → _≃ᴱ_.from (g x) (h (_≃_.to f x))}
(EEq.[proofs] (Π-cong-≃ ext f (EEq.≃ᴱ→≃ ⊚ g)))
Π-cong-contra-≃ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ≃ B₂ x) →
((x : A₁) → B₁ x) ≃ ((x : A₂) → B₂ x)
Π-cong-contra-≃ ext A₂≃A₁ =
from-isomorphism ⊚ Π-cong-contra-↔ ext A₂≃A₁ ⊚ (from-isomorphism ⊚_)
Π-cong-contra-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} →
Erased (Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂)) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ≃ᴱ B₂ x) →
((x : A₁) → B₁ x) ≃ᴱ ((x : A₂) → B₂ x)
Π-cong-contra-≃ᴱ E.[ ext ] {B₁ = B₁} f g =
EEq.[≃]→≃ᴱ
{to = λ h x → _≃ᴱ_.to (g x) (h (_≃_.to f x))}
{from = λ h x → subst B₁ (_≃_.right-inverse-of f x)
(_≃ᴱ_.from (g (_≃_.from f x))
(h (_≃_.from f x)))}
(EEq.[proofs] (Π-cong-contra-≃ ext f (EEq.≃ᴱ→≃ ⊚ g)))
Π-cong-↣ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₁ b₁ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ↣ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ↣ ((x : A₂) → B₂ x)
Π-cong-↣ ext {A₁} {A₂} {B₁} {B₂} A₁≃A₂ =
(∀ x → B₁ x ↣ B₂ (_≃_.to A₁≃A₂ x)) ↝⟨ Π-cong-contra-→ (_≃_.from A₁≃A₂) (λ _ → id) ⟩
(∀ x → B₁ (_≃_.from A₁≃A₂ x) ↣ B₂ (_≃_.to A₁≃A₂ (_≃_.from A₁≃A₂ x))) ↝⟨ (∀-cong _ λ _ →
subst ((B₁ _ ↣_) ⊚ B₂) (_≃_.right-inverse-of A₁≃A₂ _)) ⟩
(∀ x → B₁ (_≃_.from A₁≃A₂ x) ↣ B₂ x) ↝⟨ Π-cong-contra-↣ ext (_≃_.surjection $ inverse A₁≃A₂) ⟩□
((x : A₁) → B₁ x) ↣ ((x : A₂) → B₂ x) □
Π-cong-contra-Emb :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → Embedding (B₁ (_≃_.to A₂≃A₁ x)) (B₂ x)) →
Embedding ((x : A₁) → B₁ x) ((x : A₂) → B₂ x)
Π-cong-contra-Emb {a₁} {a₂} {b₁} {b₂} ext A₂≃A₁ B₁↣B₂ = record
{ to = to
; is-embedding = is-embedding
}
where
to = Π-cong-contra-→ (_≃_.to A₂≃A₁) (Embedding.to ⊚ B₁↣B₂)
abstract
ext₁₁ : Extensionality a₁ b₁
ext₁₁ = lower-extensionality a₂ b₂ ext
ext₂₁ : Extensionality a₂ b₁
ext₂₁ = lower-extensionality a₁ b₂ ext
ext₂₂ : Extensionality a₂ b₂
ext₂₂ = lower-extensionality a₁ b₁ ext
is-embedding : Is-embedding to
is-embedding f g =
_≃_.is-equivalence $
Eq.with-other-function
(f ≡ g ↝⟨ inverse $ Eq.extensionality-isomorphism ext₁₁ ⟩
(∀ x → f x ≡ g x) ↝⟨ (inverse $ Π-cong-≃ ext A₂≃A₁ λ x →
inverse $ Embedding.equivalence (B₁↣B₂ x)) ⟩
(∀ x → Embedding.to (B₁↣B₂ x) (f (_≃_.to A₂≃A₁ x)) ≡
Embedding.to (B₁↣B₂ x) (g (_≃_.to A₂≃A₁ x))) ↝⟨ Eq.extensionality-isomorphism ext₂₂ ⟩
(λ {x} → Embedding.to (B₁↣B₂ x)) ⊚ f ⊚ _≃_.to A₂≃A₁ ≡
(λ {x} → Embedding.to (B₁↣B₂ x)) ⊚ g ⊚ _≃_.to A₂≃A₁ ↔⟨⟩
to f ≡ to g □)
_
(λ f≡g →
apply-ext (Eq.good-ext ext₂₂)
(cong (Embedding.to (B₁↣B₂ _)) ⊚
ext⁻¹ f≡g ⊚ _≃_.to A₂≃A₁) ≡⟨ sym $ Eq.cong-post-∘-good-ext ext₂₁ ext₂₂ _ ⟩
cong (Embedding.to (B₁↣B₂ _) ⊚_)
(apply-ext (Eq.good-ext ext₂₁)
(ext⁻¹ f≡g ⊚ _≃_.to A₂≃A₁)) ≡⟨ cong (cong (Embedding.to (B₁↣B₂ _) ⊚_)) $ sym $
Eq.cong-pre-∘-good-ext ext₂₁ ext₁₁ _ ⟩
cong (Embedding.to (B₁↣B₂ _) ⊚_)
(cong (_⊚ _≃_.to A₂≃A₁)
(apply-ext (Eq.good-ext ext₁₁) (ext⁻¹ f≡g))) ≡⟨ cong-∘ _ _ _ ⟩
cong to (apply-ext (Eq.good-ext ext₁₁) (ext⁻¹ f≡g)) ≡⟨ cong (cong to) $
_≃_.right-inverse-of (Eq.extensionality-isomorphism ext₁₁) _ ⟩∎
cong to f≡g ∎)
Π-cong-Emb :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → Embedding (B₁ x) (B₂ (_≃_.to A₁≃A₂ x))) →
Embedding ((x : A₁) → B₁ x) ((x : A₂) → B₂ x)
Π-cong-Emb ext {A₁} {A₂} {B₁} {B₂} A₁≃A₂ =
(∀ x → Embedding (B₁ x) (B₂ (_≃_.to A₁≃A₂ x))) ↝⟨ Π-cong-contra-→ (_≃_.from A₁≃A₂) (λ _ → id) ⟩
(∀ x → Embedding (B₁ (_≃_.from A₁≃A₂ x))
(B₂ (_≃_.to A₁≃A₂ (_≃_.from A₁≃A₂ x)))) ↝⟨ (∀-cong _ λ _ → subst (Embedding (B₁ _) ⊚ B₂) (_≃_.right-inverse-of A₁≃A₂ _)) ⟩
(∀ x → Embedding (B₁ (_≃_.from A₁≃A₂ x)) (B₂ x)) ↝⟨ Π-cong-contra-Emb ext (inverse A₁≃A₂) ⟩□
Embedding ((x : A₁) → B₁ x) ((x : A₂) → B₂ x) □
-- A generalisation of ∀-cong.
Π-cong :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
Π-cong {k₁} {k₂} {a₁} {a₂} {b₁} {b₂}
ext {A₁} {A₂} {B₁} {B₂} A₁↔A₂ B₁↝B₂ =
helper k₂ ext (B₁↝B₂′ k₁ A₁↔A₂ B₁↝B₂)
where
-- The first four clauses are included as optimisations intended to
-- make some proof terms easier to work with. These clauses cover
-- every possible use of B₁↝B₂′ in the expression above.
B₁↝B₂′ :
∀ k₁ (A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
∀ k x →
B₁ x ↝[ k₂ ] B₂ (to-implication {k = k} (from-isomorphism A₁↔A₂) x)
B₁↝B₂′ bijection _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ bijection _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ k₁ A₁↔A₂ B₁↝B₂ k = λ x →
B₁ x ↝⟨ B₁↝B₂ x ⟩
B₂ (to-implication A₁↔A₂ x) ↝⟨ ≡⇒↝ _ $ cong (λ f → B₂ (f x)) $
to-implication∘from-isomorphism k₁ k ⟩□
B₂ (to-implication {k = k} (from-isomorphism A₁↔A₂) x) □
A₁↝A₂ : ∀ {k} → A₁ ↝[ k ] A₂
A₁↝A₂ = from-isomorphism A₁↔A₂
l₁ = lower-extensionality a₁ b₁
l₂ = lower-extensionality a₂ b₂
helper :
∀ k₂ →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
(∀ k x → B₁ x ↝[ k₂ ]
B₂ (to-implication {k = k} (from-isomorphism A₁↔A₂) x)) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
helper implication _ = Π-cong-→ A₁↝A₂ ⊚ (_$ surjection)
helper logical-equivalence _ = Π-cong-⇔ A₁↝A₂ ⊚ (_$ surjection)
helper injection ext = Π-cong-↣ (l₂ ext) A₁↝A₂ ⊚ (_$ equivalence)
helper embedding ext = Π-cong-Emb ext A₁↝A₂ ⊚ (_$ equivalence)
helper surjection ext = Π-cong-↠ (l₁ ext) A₁↝A₂ ⊚ (_$ surjection)
helper bijection ext = Π-cong-↔ ext A₁↝A₂ ⊚ (_$ equivalence)
helper equivalence ext = Π-cong-≃ ext A₁↝A₂ ⊚ (_$ equivalence)
helper equivalenceᴱ ext = Π-cong-≃ᴱ ext A₁↝A₂ ⊚ (_$ equivalence)
-- A variant of Π-cong.
Π-cong-contra :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
Π-cong-contra {k₁} {k₂} {a₁} {a₂} {b₁} {b₂}
ext {A₁} {A₂} {B₁} {B₂} A₂↔A₁ B₁↝B₂ =
helper k₂ ext (B₁↝B₂′ k₁ A₂↔A₁ B₁↝B₂)
where
-- The first six clauses are included as optimisations intended to
-- make some proof terms easier to work with. These clauses cover
-- every possible use of B₁↝B₂′ in the expression above.
B₁↝B₂′ :
∀ k₁ (A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
∀ k x →
B₁ (to-implication {k = k} (from-isomorphism A₂↔A₁) x) ↝[ k₂ ] B₂ x
B₁↝B₂′ bijection _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ bijection _ B₁↝B₂ implication = B₁↝B₂
B₁↝B₂′ bijection _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ implication = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ k₁ A₂↔A₁ B₁↝B₂ k = λ x →
B₁ (to-implication {k = k} (from-isomorphism A₂↔A₁) x) ↝⟨ ≡⇒↝ _ $ cong (λ f → B₁ (f x)) $ sym $ to-implication∘from-isomorphism k₁ k ⟩
B₁ (to-implication A₂↔A₁ x) ↝⟨ B₁↝B₂ x ⟩□
B₂ x □
A₂↝A₁ : ∀ {k} → A₂ ↝[ k ] A₁
A₂↝A₁ = from-isomorphism A₂↔A₁
l₁ = lower-extensionality a₁ b₁
l₂ = lower-extensionality a₂ b₂
helper :
∀ k₂ →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
(∀ k x → B₁ (to-implication {k = k} (from-isomorphism A₂↔A₁) x)
↝[ k₂ ]
B₂ x) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
helper implication _ = Π-cong-contra-→ A₂↝A₁ ⊚ (_$ implication)
helper logical-equivalence _ = Π-cong-contra-⇔ A₂↝A₁ ⊚ (_$ surjection)
helper injection ext = Π-cong-contra-↣ (l₂ ext) A₂↝A₁ ⊚ (_$ surjection)
helper embedding ext = Π-cong-contra-Emb ext A₂↝A₁ ⊚ (_$ equivalence)
helper surjection ext = Π-cong-contra-↠ (l₁ ext) A₂↝A₁ ⊚ (_$ equivalence)
helper bijection ext = Π-cong-contra-↔ ext A₂↝A₁ ⊚ (_$ equivalence)
helper equivalence ext = Π-cong-contra-≃ ext A₂↝A₁ ⊚ (_$ equivalence)
helper equivalenceᴱ ext = Π-cong-contra-≃ᴱ ext A₂↝A₁ ⊚ (_$ equivalence)
-- A variant of Π-cong for implicit Πs.
implicit-Π-cong :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
({x : A₁} → B₁ x) ↝[ k₂ ] ({x : A₂} → B₂ x)
implicit-Π-cong ext {A₁} {A₂} {B₁} {B₂} A₁↔A₂ B₁↝B₂ =
({x : A₁} → B₁ x) ↔⟨ Bijection.implicit-Π↔Π ⟩
((x : A₁) → B₁ x) ↝⟨ Π-cong ext A₁↔A₂ B₁↝B₂ ⟩
((x : A₂) → B₂ x) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
({x : A₂} → B₂ x) □
-- A variant of Π-cong-contra for implicit Πs.
implicit-Π-cong-contra :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
({x : A₁} → B₁ x) ↝[ k₂ ] ({x : A₂} → B₂ x)
implicit-Π-cong-contra ext {A₁} {A₂} {B₁} {B₂} A₁↔A₂ B₁↝B₂ =
({x : A₁} → B₁ x) ↔⟨ Bijection.implicit-Π↔Π ⟩
((x : A₁) → B₁ x) ↝⟨ Π-cong-contra ext A₁↔A₂ B₁↝B₂ ⟩
((x : A₂) → B₂ x) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
({x : A₂} → B₂ x) □
Π-left-identity : ∀ {a} {A : ⊤ → Type a} → ((x : ⊤) → A x) ↔ A tt
Π-left-identity = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → f tt
; from = λ x _ → x
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- A variant of Π-left-identity.
Π-left-identity-↑ :
∀ {a ℓ} {A : ↑ ℓ ⊤ → Type a} → ((x : ↑ ℓ ⊤) → A x) ↔ A (lift tt)
Π-left-identity-↑ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → f (lift tt)
; from = λ x _ → x
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- A lemma that can be used to simplify a pi type where the domain is
-- isomorphic to the unit type.
drop-⊤-left-Π :
∀ {k a b} {A : Type a} {B : A → Type b} →
Extensionality? k a b →
(A↔⊤ : A ↔ ⊤) →
((x : A) → B x) ↝[ k ] B (_↔_.from A↔⊤ tt)
drop-⊤-left-Π {A = A} {B} ext A↔⊤ =
((x : A) → B x) ↝⟨ Π-cong-contra ext (inverse A↔⊤) (λ _ → id) ⟩
((x : ⊤) → B (_↔_.from A↔⊤ x)) ↔⟨ Π-left-identity ⟩□
B (_↔_.from A↔⊤ tt) □
→-right-zero : ∀ {a} {A : Type a} → (A → ⊤) ↔ ⊤
→-right-zero = record
{ surjection = record
{ logical-equivalence = record
{ to = λ _ → tt
; from = λ _ _ → tt
}
; right-inverse-of = λ _ → refl tt
}
; left-inverse-of = λ _ → refl (λ _ → tt)
}
-- A lemma relating function types with the empty type as domain and
-- the unit type.
Π⊥↔⊤ : ∀ {ℓ a} {A : ⊥ {ℓ = ℓ} → Type a} →
((x : ⊥) → A x) ↝[ ℓ ∣ a ] ⊤
Π⊥↔⊤ = generalise-ext?
(record
{ to = _
; from = λ _ x → ⊥-elim x
})
(λ ext →
(λ _ → refl _)
, (λ _ → apply-ext ext (λ x → ⊥-elim x)))
-- A lemma relating ¬ ⊥ and ⊤.
¬⊥↔⊤ : ∀ {ℓ} → ¬ ⊥ {ℓ = ℓ} ↝[ ℓ ∣ lzero ] ⊤
¬⊥↔⊤ = Π⊥↔⊤
-- Simplification lemmas for types of the form A → A → B.
→→↠→ :
∀ {a b} {A : Type a} {B : Type b} →
(A → A → B) ↠ (A → B)
→→↠→ = record
{ logical-equivalence = record
{ to = λ f x → f x x
; from = λ f x _ → f x
}
; right-inverse-of = refl
}
→→proposition↔→ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality a (a ⊔ b) →
Is-proposition B →
(A → A → B) ↔ (A → B)
→→proposition↔→ {a} ext B-prop = record
{ surjection = →→↠→
; left-inverse-of = λ f →
apply-ext ext λ x →
(Π-closure (lower-extensionality lzero a ext) 1 λ _ →
B-prop) _ _
}
-- If A is inhabited, then there is a split surjection from A → B to
-- B.
inhabited→↠ :
∀ {a b} {A : Type a} {B : Type b} →
A → (A → B) ↠ B
inhabited→↠ x = record
{ logical-equivalence = record
{ to = _$ x
; from = const
}
; right-inverse-of = refl
}
-- If A is inhabited and B is a proposition, then A → B and B are
-- isomorphic (assuming extensionality).
inhabited→proposition↔ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality a b →
Is-proposition B →
A → (A → B) ↔ B
inhabited→proposition↔ ext B-prop x = record
{ surjection = inhabited→↠ x
; left-inverse-of = λ f →
apply-ext ext λ y →
f x ≡⟨ B-prop _ _ ⟩∎
f y ∎
}
-- Π is "commutative".
Π-comm : ∀ {a b c} {A : Type a} {B : Type b} {C : A → B → Type c} →
(∀ x y → C x y) ↔ (∀ y x → C x y)
Π-comm = record
{ surjection = record
{ logical-equivalence = record { to = flip; from = flip }
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Π and Σ commute (in a certain sense).
open Bijection public using (ΠΣ-comm)
-- The implicit variant of Π and Σ commute (in a certain sense).
implicit-ΠΣ-comm :
∀ {a b c} {A : Type a} {B : A → Type b} {C : (x : A) → B x → Type c} →
(∀ {x} → ∃ λ (y : B x) → C x y)
↔
(∃ λ (f : ∀ {x} → B x) → ∀ {x} → C x f)
implicit-ΠΣ-comm {A = A} {B} {C} =
(∀ {x} → ∃ λ (y : B x) → C x y) ↝⟨ Bijection.implicit-Π↔Π ⟩
(∀ x → ∃ λ (y : B x) → C x y) ↝⟨ ΠΣ-comm ⟩
(∃ λ (f : ∀ x → B x) → ∀ x → C x (f x)) ↝⟨ inverse $ Σ-cong Bijection.implicit-Π↔Π (λ _ → Bijection.implicit-Π↔Π) ⟩□
(∃ λ (f : ∀ {x} → B x) → ∀ {x} → C x f) □
-- Some variants of De Morgan's laws.
¬⊎↠¬×¬ :
∀ {a b} {A : Type a} {B : Type b} →
¬ (A ⊎ B) ↠ ¬ A × ¬ B
¬⊎↠¬×¬ = record
{ logical-equivalence = record
{ to = λ ¬[A⊎B] → ¬[A⊎B] ∘ inj₁ , ¬[A⊎B] ∘ inj₂
; from = λ (¬A , ¬B) → [ ¬A , ¬B ]
}
; right-inverse-of = refl
}
¬⊎↔¬×¬ :
∀ {a b} {A : Type a} {B : Type b} →
¬ (A ⊎ B) ↝[ a ⊔ b ∣ lzero ] ¬ A × ¬ B
¬⊎↔¬×¬ = generalise-ext?
(_↠_.logical-equivalence ¬⊎↠¬×¬)
(λ ext →
refl
, (λ _ → apply-ext ext [ (λ _ → refl _) , (λ _ → refl _) ]))
¬⊎¬→׬ :
∀ {a b} {A : Type a} {B : Type b} →
¬ A ⊎ ¬ B → ¬ (A × B)
¬⊎¬→׬ = [ (_∘ proj₁) , (_∘ proj₂) ]
¬⊎¬⇔¬× :
∀ {a b} {A : Type a} {B : Type b} →
Dec (¬ A) → Dec (¬ B) →
¬ A ⊎ ¬ B ⇔ ¬ (A × B)
¬⊎¬⇔¬× (yes ¬A) _ = record
{ to = ¬⊎¬→׬
; from = λ _ → inj₁ ¬A
}
¬⊎¬⇔¬× _ (yes ¬B) = record
{ to = ¬⊎¬→׬
; from = λ _ → inj₂ ¬B
}
¬⊎¬⇔¬× (no ¬¬A) (no ¬¬B) = record
{ to = ¬⊎¬→׬
; from = λ ¬[A×B] →
⊥-elim $
¬¬A λ a →
¬¬B λ b →
¬[A×B] (a , b)
}
¬⊎¬↠¬× :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) lzero →
Dec (¬ A) → Dec (¬ B) →
¬ A ⊎ ¬ B ↠ ¬ (A × B)
¬⊎¬↠¬× ext dec-¬A dec-¬B = record
{ logical-equivalence = ¬⊎¬⇔¬× dec-¬A dec-¬B
; right-inverse-of = λ _ → ¬-propositional ext _ _
}
-- A variant of extensionality-isomorphism for functions with implicit
-- arguments.
implicit-extensionality-isomorphism :
∀ {k a b} →
Extensionality a b →
{A : Type a} {B : A → Type b} {f g : {x : A} → B x} →
(∀ x → f {x} ≡ g {x}) ↔[ k ] ((λ {x} → f {x}) ≡ g)
implicit-extensionality-isomorphism ext {f = f} {g} =
(∀ x → f {x} ≡ g {x}) ↔⟨ Eq.extensionality-isomorphism ext ⟩
((λ x → f {x}) ≡ (λ x → g {x})) ↔⟨ inverse $ Eq.≃-≡ (Eq.↔⇒≃ (inverse Bijection.implicit-Π↔Π)) ⟩□
((λ {x} → f {x}) ≡ g) □
private
-- The forward direction of
-- implicit-extensionality-isomorphism {k = bijection} computes in a
-- certain way.
--
-- Note that (at the time of writing) the proof below fails if the
-- two occurrences of "inverse" in the previous proof are removed.
to-implicit-extensionality-isomorphism :
∀ {a b}
(ext : Extensionality a b) {A : Type a} {B : A → Type b}
{f g : {x : A} → B x} (f≡g : ∀ x → f {x} ≡ g {x}) →
_↔_.to (implicit-extensionality-isomorphism ext) f≡g
≡
implicit-extensionality (Eq.good-ext ext) f≡g
to-implicit-extensionality-isomorphism _ _ = refl _
-- The Yoneda lemma, as given in the HoTT book, but specialised to the
-- opposite of the category of sets and functions, and with some
-- naturality properties omitted. (The proof uses extensionality.)
yoneda :
∀ {a b X} →
Extensionality (lsuc a) (lsuc a ⊔ b) →
(F : Set a → Set b) →
(map : ∀ {A B} → (⌞ A ⌟ → ⌞ B ⌟) → ⌞ F A ⌟ → ⌞ F B ⌟) →
(∀ {A} {x : ⌞ F A ⌟} → map id x ≡ x) →
(∀ {A B C f g x} →
(map {A = B} {B = C} f ∘ map {A = A} g) x ≡ map (f ∘ g) x) →
⌞ F X ⌟
↔
∃ λ (γ : ∀ Y → (⌞ X ⌟ → ⌞ Y ⌟) → ⌞ F Y ⌟) →
∀ Y₁ Y₂ f g → map f (γ Y₁ g) ≡ γ Y₂ (f ∘ g)
yoneda {a} {X = X} ext F map map-id map-∘ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ x → (λ _ f → map f x) , λ _ _ f g →
map f (map g x) ≡⟨ map-∘ ⟩∎
map (f ∘ g) x ∎
; from = λ { (γ , _) → γ X id }
}
; right-inverse-of = λ { (γ , h) → Σ-≡,≡→≡
((λ _ f → map f (γ X id)) ≡⟨ (apply-ext (lower-extensionality lzero (lsuc a) ext) λ Y →
apply-ext (lower-extensionality _ (lsuc a) ext) λ f →
h X Y f id) ⟩∎
(λ Y f → γ Y f) ∎)
((Π-closure ext 1 λ _ →
Π-closure (lower-extensionality lzero (lsuc a) ext) 1 λ Y₂ →
Π-closure (lower-extensionality _ (lsuc a) ext) 1 λ _ →
Π-closure (lower-extensionality _ (lsuc a) ext) 1 λ _ →
proj₂ (F Y₂)) _ _) }
}
; left-inverse-of = λ x →
map id x ≡⟨ map-id ⟩∎
x ∎
}
-- There is a (split) surjection from products of equality
-- isomorphisms to equalities.
Π≡↔≡-↠-≡ : ∀ k {a} {A : Type a} (x y : A) →
(∀ z → (z ≡ x) ↔[ k ] (z ≡ y)) ↠ (x ≡ y)
Π≡↔≡-↠-≡ k x y = record
{ logical-equivalence = record { to = to; from = from }
; right-inverse-of = to∘from
}
where
to : (∀ z → (z ≡ x) ↔[ k ] (z ≡ y)) → x ≡ y
to f = to-implication (f x) (refl x)
from′ : x ≡ y → ∀ z → (z ≡ x) ↔ (z ≡ y)
from′ x≡y z = record
{ surjection = record
{ logical-equivalence = record
{ to = λ z≡x → trans z≡x x≡y
; from = λ z≡y → trans z≡y (sym x≡y)
}
; right-inverse-of = λ z≡y → trans-[trans-sym]- z≡y x≡y
}
; left-inverse-of = λ z≡x → trans-[trans]-sym z≡x x≡y
}
from : x ≡ y → ∀ z → (z ≡ x) ↔[ k ] (z ≡ y)
from x≡y z = from-bijection (from′ x≡y z)
abstract
to∘from : ∀ x≡y → to (from x≡y) ≡ x≡y
to∘from x≡y =
to (from x≡y) ≡⟨ sym $ cong (λ f → f (refl x)) $ to-implication∘from-isomorphism bijection ⌊ k ⌋-iso ⟩
trans (refl x) x≡y ≡⟨ trans-reflˡ _ ⟩∎
x≡y ∎
-- Products of equivalences of equalities are isomorphic to equalities
-- (assuming extensionality).
Π≡≃≡-↔-≡ :
∀ {a} {A : Type a} (x y : A) →
(∀ z → (z ≡ x) ≃ (z ≡ y)) ↝[ a ∣ a ] (x ≡ y)
Π≡≃≡-↔-≡ {a = a} x y =
generalise-ext?
(_↠_.logical-equivalence surj)
(λ ext →
_↠_.right-inverse-of surj
, from∘to ext)
where
surj = Π≡↔≡-↠-≡ equivalence x y
open _↠_ surj
abstract
from∘to :
Extensionality a a →
∀ f → from (to f) ≡ f
from∘to ext f =
apply-ext ext λ z → Eq.lift-equality ext $ apply-ext ext λ z≡x →
trans z≡x (_≃_.to (f x) (refl x)) ≡⟨ elim (λ {u v} u≡v →
(f : ∀ z → (z ≡ v) ≃ (z ≡ y)) →
trans u≡v (_≃_.to (f v) (refl v)) ≡
_≃_.to (f u) u≡v)
(λ _ _ → trans-reflˡ _)
z≡x f ⟩∎
_≃_.to (f z) z≡x ∎
-- One can introduce a universal quantifier by also introducing an
-- equality (perhaps assuming extensionality).
∀-intro :
∀ {a b} {A : Type a} {x : A} (B : (y : A) → x ≡ y → Type b) →
B x (refl x) ↝[ a ∣ a ⊔ b ] (∀ y (x≡y : x ≡ y) → B y x≡y)
∀-intro {a = a} {b = b} {A = A} {x = x} B =
generalise-ext? ∀-intro-⇔ (λ ext → to∘from ext , from∘to ext)
where
∀-intro-⇔ : B x (refl x) ⇔ (∀ y (x≡y : x ≡ y) → B y x≡y)
∀-intro-⇔ = record
{ to = λ b y x≡y →
subst (uncurry B)
(proj₂ (other-singleton-contractible x) (y , x≡y))
b
; from = λ f → f x (refl x)
}
abstract
from∘to :
Extensionality a (a ⊔ b) →
∀ b → _⇔_.from ∀-intro-⇔ (_⇔_.to ∀-intro-⇔ b) ≡ b
from∘to ext b =
subst (uncurry B)
(proj₂ (other-singleton-contractible x) (x , refl x)) b ≡⟨ cong (λ eq → subst (uncurry B) eq b) $
other-singleton-contractible-refl x ⟩
subst (uncurry B) (refl (x , refl x)) b ≡⟨ subst-refl (uncurry B) _ ⟩∎
b ∎
to∘from :
Extensionality a (a ⊔ b) →
∀ b → _⇔_.to ∀-intro-⇔ (_⇔_.from ∀-intro-⇔ b) ≡ b
to∘from ext f =
apply-ext ext λ y →
apply-ext (lower-extensionality lzero a ext) λ x≡y →
elim¹ (λ {y} x≡y →
subst (uncurry B)
(proj₂ (other-singleton-contractible x)
(y , x≡y))
(f x (refl x)) ≡
f y x≡y)
(subst (uncurry B)
(proj₂ (other-singleton-contractible x)
(x , refl x))
(f x (refl x)) ≡⟨ from∘to ext (f x (refl x)) ⟩∎
f x (refl x) ∎)
x≡y
private
-- The following proof is perhaps easier to follow, but the
-- resulting "from" functions are more complicated than the one used
-- in ∀-intro. (If subst reduced in the usual way when applied to
-- refl, then the two functions would perhaps be definitionally
-- equal.)
--
-- This proof is based on one presented by Egbert Rijke in "A type
-- theoretical Yoneda lemma"
-- (http://homotopytypetheory.org/2012/05/02/a-type-theoretical-yoneda-lemma/).
∀-intro′ :
∀ {a b} {A : Type a} {x : A} (B : (y : A) → x ≡ y → Type b) →
B x (refl x) ↝[ a ∣ a ⊔ b ] (∀ y (x≡y : x ≡ y) → B y x≡y)
∀-intro′ {a = a} {x = x} B {k = k} ext =
B x (refl x) ↔⟨ inverse Π-left-identity ⟩
(⊤ → B x (refl x)) ↝⟨ Π-cong-contra (lower-extensionality? k lzero a ext)
(_⇔_.to contractible⇔↔⊤ c) (λ _ → id) ⟩
((∃ λ y → x ≡ y) → B x (refl x)) ↔⟨ currying ⟩
(∀ y (x≡y : x ≡ y) → B x (refl x)) ↝⟨ (∀-cong ext λ y →
∀-cong (lower-extensionality? k lzero a ext) λ x≡y → from-isomorphism $
Eq.subst-as-equivalence (uncurry B) (proj₂ c (y , x≡y))) ⟩□
(∀ y (x≡y : x ≡ y) → B y x≡y) □
where
c : Contractible (∃ λ y → x ≡ y)
c = other-singleton-contractible x
-- One can introduce a (non-dependent) function argument of the same
-- type as another one if the codomain is propositional (assuming
-- extensionality).
→-intro :
∀ {a p} {A : Type a} {P : A → Type p} →
Extensionality a (a ⊔ p) →
(∀ x → Is-proposition (P x)) →
(∀ x → P x) ↔ (A → ∀ x → P x)
→-intro {a = a} ext P-prop = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f _ x → f x
; from = λ f x → f x x
}
; right-inverse-of = λ _ →
(Π-closure ext 1 λ _ →
Π-closure (lower-extensionality a a ext) 1 λ _ →
P-prop _) _ _
}
; left-inverse-of = refl
}
-- Logical equivalences can be expressed as pairs of functions.
⇔↔→×→ :
∀ {a b} {A : Type a} {B : Type b} →
(A ⇔ B) ↔ (A → B) × (B → A)
⇔↔→×→ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → _⇔_.to f , _⇔_.from f
; from = λ { (to , from) → record { to = to; from = from } }
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
------------------------------------------------------------------------
-- A lemma related to _≃_
-- The operator _⇔_ preserves symmetric kinds of functions.
⇔-cong :
∀ {k a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b ⊔ c ⊔ d) (a ⊔ b ⊔ c ⊔ d) →
A ↝[ ⌊ k ⌋-sym ] B → C ↝[ ⌊ k ⌋-sym ] D →
(A ⇔ C) ↝[ ⌊ k ⌋-sym ] (B ⇔ D)
⇔-cong {k = k} {a = a} {b = b} {c = c} {d = d}
{A = A} {B = B} {C = C} {D = D} ext A↝B C↝D =
A ⇔ C ↔⟨ ⇔↔→×→ ⟩
(A → C) × (C → A) ↝⟨ →-cong (lower-extensionality? ⌊ k ⌋-sym (c ⊔ d) (a ⊔ b) ext) A↝B C↝D
×-cong
→-cong (lower-extensionality? ⌊ k ⌋-sym (a ⊔ b) (c ⊔ d) ext) C↝D A↝B ⟩
(B → D) × (D → B) ↔⟨ inverse ⇔↔→×→ ⟩□
B ⇔ D □
------------------------------------------------------------------------
-- Some lemmas related to _≃_
-- Contractibility is isomorphic to equivalence to the unit type
-- (assuming extensionality).
contractible↔≃⊤ :
∀ {a} {A : Type a} →
Extensionality a a →
Contractible A ↔ (A ≃ ⊤)
contractible↔≃⊤ ext = record
{ surjection = record
{ logical-equivalence = record
{ to = Eq.↔⇒≃ ∘ _⇔_.to contractible⇔↔⊤
; from = _⇔_.from contractible⇔↔⊤ ∘ _≃_.bijection
}
; right-inverse-of = λ _ →
Eq.lift-equality ext (refl _)
}
; left-inverse-of = λ _ → Contractible-propositional ext _ _
}
-- Equivalence to the empty type is equivalent to not being inhabited
-- (assuming extensionality).
≃⊥≃¬ :
∀ {a ℓ} {A : Type a} →
Extensionality (a ⊔ ℓ) (a ⊔ ℓ) →
(A ≃ ⊥ {ℓ = ℓ}) ≃ (¬ A)
≃⊥≃¬ {ℓ = ℓ} {A} ext =
_↔_.to (Eq.⇔↔≃ ext (Eq.right-closure ext 0 ⊥-propositional)
(¬-propositional
(lower-extensionality ℓ _ ext))) (record
{ to = λ eq a → ⊥-elim (_≃_.to eq a)
; from = λ ¬a → A ↔⟨ inverse (Bijection.⊥↔uninhabited ¬a) ⟩□
⊥ □
})
-- If f and g are pointwise equal, then HA.Proofs f f⁻¹ and
-- HA.Proofs g f⁻¹ are equivalent (assuming extensionality).
Proofs-cong :
∀ {a b} {A : Type a} {B : Type b} {f g : A → B} {f⁻¹ : B → A} →
Extensionality (a ⊔ b) (a ⊔ b) →
(∀ x → f x ≡ g x) →
HA.Proofs f f⁻¹ ≃ HA.Proofs g f⁻¹
Proofs-cong
{a = a} {b = b} {f = f} {g = g} {f⁻¹ = f⁻¹} ext f≡g =
Σ-cong (∀-cong (lower-extensionality a a ext) λ _ →
≡⇒↝ equivalence $ cong (_≡ _) $ f≡g _) λ f-f⁻¹ →
Σ-cong (∀-cong (lower-extensionality b b ext) λ _ →
≡⇒↝ equivalence $ cong (_≡ _) $ cong f⁻¹ $ f≡g _) λ f⁻¹-f →
∀-cong (lower-extensionality b a ext) λ x → ≡⇒↝ _
(cong f (f⁻¹-f x) ≡ f-f⁻¹ (f x) ≡⟨ lemma f-f⁻¹ f⁻¹-f _ ⟩
trans (ext⁻¹ (ext″ f≡g) (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (ext⁻¹ (ext″ f≡g) x)))
(f⁻¹-f x))) ≡
f-f⁻¹ (g x) ≡⟨ cong (_≡ _) $
cong₂ (λ p q →
trans (p (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (q x))) (f⁻¹-f x))))
(_≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) f≡g)
(_≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) f≡g) ⟩
trans (f≡g (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (f≡g x))) (f⁻¹-f x))) ≡
f-f⁻¹ (g x) ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩
cong g (trans (sym (cong f⁻¹ (f≡g x))) (f⁻¹-f x)) ≡
trans (sym (f≡g (f⁻¹ (g x)))) (f-f⁻¹ (g x)) ≡⟨ sym $ cong₂ (λ p q → cong g p ≡ q)
subst-trans-sym
subst-trans-sym ⟩
cong g (subst (_≡ x) (cong f⁻¹ (f≡g x)) (f⁻¹-f x)) ≡
subst (_≡ g x) (f≡g (f⁻¹ (g x))) (f-f⁻¹ (g x)) ≡⟨ cong₂ (λ p q → cong g p ≡ q)
(subst-in-terms-of-≡⇒↝ equivalence _ _ _)
(subst-in-terms-of-≡⇒↝ equivalence _ _ _) ⟩∎
cong g
(_≃_.to (≡⇒↝ _ (cong (_≡ x) (cong f⁻¹ (f≡g x)))) (f⁻¹-f x)) ≡
_≃_.to (≡⇒↝ _ (cong (_≡ g x) (f≡g (f⁻¹ (g x))))) (f-f⁻¹ (g x)) ∎)
where
ext′ = lower-extensionality b a ext
ext″ = apply-ext $ Eq.good-ext ext′
lemma :
∀ {x} f-f⁻¹ f⁻¹-f f≡g →
(cong f (f⁻¹-f x) ≡ f-f⁻¹ (f x))
≡
(trans (ext⁻¹ f≡g (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (ext⁻¹ f≡g x))) (f⁻¹-f x))) ≡
f-f⁻¹ (g x))
lemma {x = x} f-f⁻¹ f⁻¹-f = elim¹
(λ {g} f≡g →
(cong f (f⁻¹-f x) ≡ f-f⁻¹ (f x))
≡
(trans (ext⁻¹ f≡g (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (ext⁻¹ f≡g x))) (f⁻¹-f x))) ≡
f-f⁻¹ (g x)))
(cong (_≡ f-f⁻¹ (f x))
(cong f (f⁻¹-f x) ≡⟨ cong (cong f) $ sym $
trans (cong (flip trans _) $
trans (cong sym $ cong-refl _) $
sym-refl) $
trans-reflˡ _ ⟩
cong f (trans (sym (cong f⁻¹ (refl (f x)))) (f⁻¹-f x)) ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl (f (f⁻¹ (f x))))
(cong f (trans (sym (cong f⁻¹ (refl (f x)))) (f⁻¹-f x))) ≡⟨ sym $
cong₂ (λ p q →
trans p (cong f (trans (sym (cong f⁻¹ q)) (f⁻¹-f x))))
(ext⁻¹-refl _)
(ext⁻¹-refl _) ⟩∎
trans (ext⁻¹ (refl f) (f⁻¹ (f x)))
(cong f (trans (sym (cong f⁻¹ (ext⁻¹ (refl f) x))) (f⁻¹-f x))) ∎))
-- Is-equivalence preserves equality, if we see _≃_ as a form of
-- equality (assuming extensionality).
Is-equivalence-cong :
∀ {k a b} {A : Type a} {B : Type b} {f g : A → B} →
Extensionality? k (a ⊔ b) (a ⊔ b) →
(∀ x → f x ≡ g x) →
Is-equivalence f ↝[ k ] Is-equivalence g
Is-equivalence-cong ext f≡g =
generalise-ext?-prop
(record
{ to = Eq.respects-extensional-equality f≡g
; from = Eq.respects-extensional-equality (sym ⊚ f≡g)
})
(λ ext → Eq.propositional ext _)
(λ ext → Eq.propositional ext _)
ext
-- Is-equivalence is pointwise equivalent to CP.Is-equivalence
-- (assuming extensionality).
Is-equivalence≃Is-equivalence-CP :
∀ {a b} {A : Type a} {B : Type b} {f : A → B} →
Is-equivalence f ↝[ a ⊔ b ∣ a ⊔ b ] CP.Is-equivalence f
Is-equivalence≃Is-equivalence-CP =
generalise-ext?
HA.Is-equivalence⇔Is-equivalence-CP
(λ ext →
let bij = HA.Is-equivalence↔Is-equivalence-CP ext in
_↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
-- Two notions of equivalence are pointwise equivalent (assuming
-- extensionality).
≃≃≃-CP :
∀ {a b} {A : Type a} {B : Type b} →
(A ≃ B) ↝[ a ⊔ b ∣ a ⊔ b ] (A CP.≃ B)
≃≃≃-CP {A = A} {B = B} ext =
A ≃ B ↔⟨ Eq.≃-as-Σ ⟩
(∃ λ (f : A → B) → Is-equivalence f) ↝⟨ (∃-cong λ _ → Is-equivalence≃Is-equivalence-CP ext) ⟩□
(∃ λ (f : A → B) → CP.Is-equivalence f) □
-- _≃_ is commutative (assuming extensionality).
≃-comm :
∀ {a b} {A : Type a} {B : Type b} →
A ≃ B ↝[ a ⊔ b ∣ a ⊔ b ] B ≃ A
≃-comm =
generalise-ext?
Eq.inverse-logical-equivalence
(λ ext →
let bij = Eq.inverse-isomorphism ext in
_↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
-- Two consequences of the two-out-of-three property.
Is-equivalence≃Is-equivalence-∘ˡ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
{f : B → C} {g : A → B} →
Is-equivalence f →
Is-equivalence g ↝[ a ⊔ b ⊔ c ∣ a ⊔ b ⊔ c ] Is-equivalence (f ∘ g)
Is-equivalence≃Is-equivalence-∘ˡ {b = b} {c = c} f-eq =
generalise-ext?-prop
(record
{ to = flip (Eq.Two-out-of-three.f-g (Eq.two-out-of-three _ _))
f-eq
; from = Eq.Two-out-of-three.g-g∘f (Eq.two-out-of-three _ _) f-eq
})
(flip Eq.propositional _ ⊚ lower-extensionality c c)
(flip Eq.propositional _ ⊚ lower-extensionality b b)
Is-equivalence≃Is-equivalence-∘ʳ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
{f : B → C} {g : A → B} →
Is-equivalence g →
Is-equivalence f ↝[ a ⊔ b ⊔ c ∣ a ⊔ b ⊔ c ] Is-equivalence (f ∘ g)
Is-equivalence≃Is-equivalence-∘ʳ {a = a} {b = b} g-eq =
generalise-ext?-prop
(record
{ to = Eq.Two-out-of-three.f-g (Eq.two-out-of-three _ _) g-eq
; from = flip
(Eq.Two-out-of-three.g∘f-f (Eq.two-out-of-three _ _))
g-eq
})
(flip Eq.propositional _ ⊚ lower-extensionality a a)
(flip Eq.propositional _ ⊚ lower-extensionality b b)
------------------------------------------------------------------------
-- Lemmas related to _↠_
-- An alternative characterisation of split surjections.
↠↔∃-Split-surjective :
∀ {a b} {A : Type a} {B : Type b} →
(A ↠ B) ↔ ∃ λ (f : A → B) → Split-surjective f
↠↔∃-Split-surjective = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → _↠_.to f , _↠_.split-surjective f
; from = λ { (f , s) → record
{ logical-equivalence = record
{ to = f
; from = proj₁ ⊚ s
}
; right-inverse-of = proj₂ ⊚ s
} }
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
------------------------------------------------------------------------
-- Lemmas related to _↣_
-- An alternative characterisation of injections.
↣↔∃-Injective :
∀ {a b} {A : Type a} {B : Type b} →
(A ↣ B) ↔ ∃ λ (f : A → B) → Injective f
↣↔∃-Injective = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → _↣_.to f , _↣_.injective f
; from = λ (f , i) → record
{ to = f
; injective = i
}
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
------------------------------------------------------------------------
-- Lemmas related to _≡_
-- Equality is commutative.
open Bijection public using (≡-comm)
-- The following two lemmas are based on Example 2.4.8 in the HoTT
-- book.
-- The function trans x≡y is the to component of an isomorphism.
trans-isomorphism :
∀ {a} {A : Type a} {x y z : A} →
x ≡ y → y ≡ z ↔ x ≡ z
trans-isomorphism x≡y = record
{ surjection = record
{ logical-equivalence = record
{ to = trans x≡y
; from = trans (sym x≡y)
}
; right-inverse-of = trans--[trans-sym] _
}
; left-inverse-of = trans-sym-[trans] _
}
-- The function flip trans x≡y is the to component of an isomorphism.
flip-trans-isomorphism :
∀ {a} {A : Type a} {x y z : A} →
x ≡ y → z ≡ x ↔ z ≡ y
flip-trans-isomorphism x≡y = record
{ surjection = record
{ logical-equivalence = record
{ to = flip trans x≡y
; from = flip trans (sym x≡y)
}
; right-inverse-of = λ _ → trans-[trans-sym]- _ _
}
; left-inverse-of = λ _ → trans-[trans]-sym _ _
}
-- Equality expression rearrangement lemmas.
from≡↔≡to : ∀ {a b} →
{A : Type a} {B : Type b}
(A≃B : A ≃ B) {x : B} {y : A} →
(_≃_.from A≃B x ≡ y) ↔ (x ≡ _≃_.to A≃B y)
from≡↔≡to A≃B {x} {y} =
(_≃_.from A≃B x ≡ y) ↔⟨ inverse $ Eq.≃-≡ A≃B ⟩
(_≃_.to A≃B (_≃_.from A≃B x) ≡ _≃_.to A≃B y) ↝⟨ ≡⇒↝ _ $ cong (λ z → z ≡ _≃_.to A≃B y) $ _≃_.right-inverse-of A≃B x ⟩□
(x ≡ _≃_.to A≃B y) □
to∘≡↔≡from∘ : ∀ {a b c} →
Extensionality a (b ⊔ c) →
{A : Type a} {B : A → Type b} {C : A → Type c}
(B≃C : ∀ {x} → B x ≃ C x)
{f : (x : A) → B x} {g : (x : A) → C x} →
(_≃_.to B≃C ⊚ f ≡ g) ↔ (f ≡ _≃_.from B≃C ⊚ g)
to∘≡↔≡from∘ ext B≃C =
from≡↔≡to (∀-cong ext (λ _ → inverse B≃C))
∘from≡↔≡∘to : ∀ {a b c} →
Extensionality (a ⊔ b) c →
{A : Type a} {B : Type b} {C : Type c}
(A≃B : A ≃ B) {f : A → C} {g : B → C} →
(f ∘ _≃_.from A≃B ≡ g) ↔ (f ≡ g ∘ _≃_.to A≃B)
∘from≡↔≡∘to ext A≃B = from≡↔≡to (→-cong₁ ext (inverse A≃B))
∘from≡↔≡∘to′ :
∀ {a b c} →
Extensionality (a ⊔ b) c →
{A : Type a} {B : Type b} {C : A → Type c}
(A≃B : A ≃ B)
{f : (x : A) → C x} {g : (x : B) → C (_≃_.from A≃B x)} →
(f ⊚ _≃_.from A≃B ≡ g) ↔
(f ≡ subst C (_≃_.left-inverse-of A≃B _) ⊚ g ⊚ _≃_.to A≃B)
∘from≡↔≡∘to′ {a = a} {b = b} ext {C = C} A≃B {f = f} {g = g} =
f ⊚ _≃_.from A≃B ≡ g ↝⟨ ≡⇒↝ _ $ cong (_≡ g) $ apply-ext (lower-extensionality a lzero ext)
lemma ⟩
subst (C ⊚ _≃_.from A≃B) (_≃_.right-inverse-of A≃B _) ⊚
_≃_.from (≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B _)) ⊚
f ⊚ _≃_.from A≃B ≡
g ↝⟨ from≡↔≡to
(Π-cong-contra ext A≃B λ x →
≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B x)) ⟩
f ≡
_≃_.to (≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B _)) ⊚ g ⊚ _≃_.to A≃B ↝⟨ (≡⇒↝ _ $ cong (f ≡_) $ apply-ext (lower-extensionality b lzero ext) λ _ →
sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _) ⟩□
f ≡ subst C (_≃_.left-inverse-of A≃B _) ⊚ g ⊚ _≃_.to A≃B □
where
lemma : ∀ _ → _
lemma x =
f (_≃_.from A≃B x) ≡⟨ sym $ _≃_.right-inverse-of equiv _ ⟩
_≃_.to equiv (_≃_.from equiv (f (_≃_.from A≃B x))) ≡⟨ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst C (_≃_.left-inverse-of A≃B (_≃_.from A≃B x))
(_≃_.from equiv (f (_≃_.from A≃B x))) ≡⟨ cong (λ eq → subst C eq (_≃_.from equiv (f (_≃_.from A≃B x)))) $ sym $
_≃_.right-left-lemma A≃B _ ⟩
subst C (cong (_≃_.from A≃B) (_≃_.right-inverse-of A≃B x))
(_≃_.from equiv (f (_≃_.from A≃B x))) ≡⟨ sym $ subst-∘ _ _ (_≃_.right-inverse-of A≃B x) ⟩∎
subst (C ⊚ _≃_.from A≃B) (_≃_.right-inverse-of A≃B x)
(_≃_.from equiv (f (_≃_.from A≃B x))) ∎
where
equiv = ≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B (_≃_.from A≃B x))
------------------------------------------------------------------------
-- Some lemmas related to _⁻¹_
-- A fibre of a composition can be expressed as a pair of fibres.
∘⁻¹≃ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c} {z} →
(f : B → C) (g : A → B) →
f ∘ g ⁻¹ z ≃ ∃ λ ((y , _) : f ⁻¹ z) → g ⁻¹ y
∘⁻¹≃ {z = z} f g =
f ∘ g ⁻¹ z ↔⟨⟩
(∃ λ a → f (g a) ≡ z) ↔⟨ (∃-cong λ _ → other-∃-intro _ _) ⟩
(∃ λ a → ∃ λ y → f y ≡ z × g a ≡ y) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩
(∃ λ a → ∃ λ ((y , _) : f ⁻¹ z) → g a ≡ y) ↔⟨ ∃-comm ⟩□
(∃ λ ((y , _) : f ⁻¹ z) → g ⁻¹ y) □
-- The type of fibres of Σ-map P.id f over a pair is equivalent to the
-- fibres of f over the pair's second component.
--
-- This is Theorem 4.7.6 from the HoTT book.
Σ-map-id-⁻¹≃⁻¹ :
∀ {a p q} {A : Type a} {P : A → Type p} {Q : A → Type q}
{f : ∀ {x} → P x → Q x} {x : A} {y : Q x} →
Σ-map P.id f ⁻¹ _,_ {B = Q} x y ≃ f ⁻¹ y
Σ-map-id-⁻¹≃⁻¹ {Q = Q} {f = f} {x = x} {y = y} =
Σ-map P.id f ⁻¹ (x , y) ↔⟨⟩
(∃ λ (u , v) → (u , f v) ≡ (x , y)) ↔⟨ inverse Bijection.Σ-assoc ⟩
(∃ λ u → ∃ λ v → (u , f v) ≡ (x , y)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → inverse
Bijection.Σ-≡,≡↔≡) ⟩
(∃ λ u → ∃ λ v → ∃ λ (p : u ≡ x) → subst Q p (f v) ≡ y) ↔⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ u → ∃ λ (p : u ≡ x) → ∃ λ v → subst Q p (f v) ≡ y) ↔⟨ Bijection.Σ-assoc ⟩
(∃ λ ((_ , p) : ∃ λ u → u ≡ x) → ∃ λ v → subst Q p (f v) ≡ y) ↔⟨ drop-⊤-left-Σ $
_⇔_.to contractible⇔↔⊤ $
singleton-contractible _ ⟩
(∃ λ v → subst Q (refl _) (f v) ≡ y) ↝⟨ (∃-cong λ _ → ≡⇒↝ _ $ cong (_≡ _) $
subst-refl _ _) ⟩
(∃ λ v → f v ≡ y) ↔⟨⟩
f ⁻¹ y □
------------------------------------------------------------------------
-- Lemmas related to ↑
-- ↑ _ preserves all kinds of functions.
private
↑-cong-→ :
∀ {a b c} {B : Type b} {C : Type c} →
(B → C) → ↑ a B → ↑ a C
↑-cong-→ B→C = lift ⊚ B→C ⊚ lower
↑-cong-↣ :
∀ {a b c} {B : Type b} {C : Type c} →
B ↣ C → ↑ a B ↣ ↑ a C
↑-cong-↣ {a} B↣C = record
{ to = to′
; injective = injective′
}
where
open _↣_ B↣C
to′ = ↑-cong-→ {a = a} to
abstract
injective′ : Injective to′
injective′ = cong lift ⊚ injective ⊚ cong lower
↑-cong-Embedding :
∀ {a b c} {B : Type b} {C : Type c} →
Embedding B C → Embedding (↑ a B) (↑ a C)
↑-cong-Embedding {a} {B = B} B↣C = record
{ to = ↑-cong-→ to
; is-embedding = λ x y →
_≃_.is-equivalence $
Eq.with-other-function
(x ≡ y ↔⟨⟩
lift (lower x) ≡ lift (lower y) ↔⟨ inverse lift-lemma ⟩
lower x ≡ lower y ↝⟨ Eq.⟨ _ , is-embedding _ _ ⟩ ⟩
to (lower x) ≡ to (lower y) ↔⟨ lift-lemma ⟩□
lift (to (lower x)) ≡ lift (to (lower y)) □)
_
(λ p → cong lift (cong to (cong lower p)) ≡⟨ cong-∘ _ _ _ ⟩
cong (lift ⊚ to) (cong lower p) ≡⟨ cong-∘ _ _ _ ⟩∎
cong (lift ⊚ to ⊚ lower) p ∎)
}
where
open Embedding B↣C
lift-lemma : ∀ {ℓ a} {A : Type a} {x y : A} →
(x ≡ y) ↔ (lift {ℓ = ℓ} x ≡ lift y)
lift-lemma {ℓ} = record
{ surjection = record
{ logical-equivalence = record
{ to = cong lift
; from = cong lower
}
; right-inverse-of = λ eq →
cong lift (cong lower eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (lift ⊚ lower) eq ≡⟨ sym (cong-id _) ⟩∎
eq ∎
}
; left-inverse-of = λ eq →
cong lower (cong lift eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (lower {ℓ = ℓ} ⊚ lift) eq ≡⟨ sym (cong-id _) ⟩∎
eq ∎
}
↑-cong-↠ :
∀ {a b c} {B : Type b} {C : Type c} →
B ↠ C → ↑ a B ↠ ↑ a C
↑-cong-↠ {a} B↠C = record
{ logical-equivalence = logical-equivalence′
; right-inverse-of = right-inverse-of′
}
where
open _↠_ B↠C renaming (logical-equivalence to logical-equiv)
logical-equivalence′ = L.↑-cong {a = a} logical-equiv
abstract
right-inverse-of′ : ∀ x →
_⇔_.to logical-equivalence′
(_⇔_.from logical-equivalence′ x) ≡
x
right-inverse-of′ = cong lift ⊚ right-inverse-of ⊚ lower
↑-cong-↔ :
∀ {a b c} {B : Type b} {C : Type c} →
B ↔ C → ↑ a B ↔ ↑ a C
↑-cong-↔ {a} B↔C = record
{ surjection = surjection′
; left-inverse-of = left-inverse-of′
}
where
open _↔_ B↔C renaming (surjection to surj)
surjection′ = ↑-cong-↠ {a = a} surj
abstract
left-inverse-of′ :
∀ x → _↠_.from surjection′ (_↠_.to surjection′ x) ≡ x
left-inverse-of′ = cong lift ⊚ left-inverse-of ⊚ lower
↑-cong-≃ :
∀ {a b c} {B : Type b} {C : Type c} →
B ≃ C → ↑ a B ≃ ↑ a C
↑-cong-≃ = from-bijection ∘ ↑-cong-↔ ∘ from-equivalence
↑-cong-≃ᴱ :
∀ {a b c} {B : Type b} {C : Type c} →
B ≃ᴱ C → ↑ a B ≃ᴱ ↑ a C
↑-cong-≃ᴱ f = EEq.[≃]→≃ᴱ (EEq.[proofs] (↑-cong-≃ (EEq.≃ᴱ→≃ f)))
↑-cong : ∀ {k a b c} {B : Type b} {C : Type c} →
B ↝[ k ] C → ↑ a B ↝[ k ] ↑ a C
↑-cong {implication} = ↑-cong-→
↑-cong {logical-equivalence} = L.↑-cong
↑-cong {injection} = ↑-cong-↣
↑-cong {embedding} = ↑-cong-Embedding
↑-cong {surjection} = ↑-cong-↠
↑-cong {bijection} = ↑-cong-↔
↑-cong {equivalence} = ↑-cong-≃
↑-cong {equivalenceᴱ} = ↑-cong-≃ᴱ
------------------------------------------------------------------------
-- Lemmas related to unit types
-- The type of equalities tt ≡ tt is isomorphic to the unit type.
tt≡tt↔⊤ : tt ≡ tt ↔ ⊤
tt≡tt↔⊤ = _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(mono (zero≤ 2) ⊤-contractible) (refl _)
-- Unit is equivalent to ⊤.
--
-- The forward direction of the equivalence returns the supplied value
-- of type Unit.
Unit≃⊤ : Unit → Unit ≃ ⊤
Unit≃⊤ x =
Eq.↔→≃ _ (λ _ → x) refl
(λ { ⊠ → unblock x (_≡ ⊠) (refl _) })
------------------------------------------------------------------------
-- Lemmas related to ⊥
-- All instances of ⊥ are isomorphic.
⊥↔⊥ : ∀ {ℓ₁ ℓ₂} → ⊥ {ℓ = ℓ₁} ↔ ⊥ {ℓ = ℓ₂}
⊥↔⊥ = Bijection.⊥↔uninhabited ⊥-elim
-- All instances of A → ⊥ are isomorphic to ¬ A.
¬↔→⊥ : ∀ {a ℓ} {A : Type a} →
¬ A ↝[ a ∣ ℓ ] (A → ⊥ {ℓ = ℓ})
¬↔→⊥ {A = A} ext =
(A → ⊥₀) ↝⟨ (∀-cong ext λ _ → from-isomorphism ⊥↔⊥) ⟩□
(A → ⊥) □
-- A type cannot be logically equivalent to its own negation.
¬[⇔¬] : ∀ {a} {A : Type a} → ¬ (A ⇔ ¬ A)
¬[⇔¬] {A = A} =
A ⇔ ¬ A ↝⟨ (λ eq → (λ a → _⇔_.to eq a a) , eq) ⟩
¬ A × (A ⇔ ¬ A) ↝⟨ (λ { (¬a , eq) → ¬a , _⇔_.from eq ¬a }) ⟩
¬ A × A ↝⟨ uncurry _$_ ⟩□
⊥ □
-- If two types are logically equivalent, then their negations are
-- equivalent (assuming extensionality).
¬-cong-⇔ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) lzero →
A ⇔ B → (¬ A) ≃ (¬ B)
¬-cong-⇔ {a} {b} ext A⇔B =
_↠_.from
(Eq.≃↠⇔ (¬-propositional (lower-extensionality b lzero ext))
(¬-propositional (lower-extensionality a lzero ext)))
(→-cong _ A⇔B id)
-- Symmetric kinds of functions are preserved by ¬_ (assuming
-- extensionality).
¬-cong :
∀ {k a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) lzero →
A ↝[ ⌊ k ⌋-sym ] B → (¬ A) ↝[ ⌊ k ⌋-sym ] (¬ B)
¬-cong ext A↝B = from-equivalence (¬-cong-⇔ ext (sym→⇔ A↝B))
-- If B can be decided, given that A is inhabited, then A → B is
-- logically equivalent to ¬ B → ¬ A.
→⇔¬→¬ :
∀ {a b} {A : Type a} {B : Type b} →
(A → Dec B) →
(A → B) ⇔ (¬ B → ¬ A)
→⇔¬→¬ _ ._⇔_.to = flip _∘_
→⇔¬→¬ dec ._⇔_.from ¬B→¬A A with dec A
… | yes B = B
… | no ¬B = ⊥-elim $ ¬B→¬A ¬B A
-- If B is additionally a proposition (assuming that A is inhabited),
-- then the two types are equivalent (assuming extensionality).
→≃¬→¬ :
∀ {a b} {A : Type a} {B : Type b} →
(Extensionality (a ⊔ b) (a ⊔ b) → A → Is-proposition B) →
(A → Dec B) →
(A → B) ↝[ a ⊔ b ∣ a ⊔ b ] (¬ B → ¬ A)
→≃¬→¬ {a = a} {b = b} prop dec =
generalise-ext?-prop
(→⇔¬→¬ dec)
(λ ext → Π-closure (lower-extensionality b a ext) 1 (prop ext))
(λ ext → Π-closure (lower-extensionality a b ext) 1 λ _ →
¬-propositional (lower-extensionality b _ ext))
------------------------------------------------------------------------
-- Lemmas related to H-level
-- H-level and H-level′ are pointwise isomorphic (assuming
-- extensionality).
H-level↔H-level′ :
∀ {a} {A : Type a} {n} →
H-level n A ↝[ a ∣ a ] H-level′ n A
H-level↔H-level′ {n = n} =
generalise-ext?-prop
H-level⇔H-level′
(λ ext → H-level-propositional ext _)
(λ ext → H-level′-propositional ext n)
-- H-level n preserves isomorphisms (assuming extensionality).
H-level-cong :
∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
Extensionality? k₂ (a ⊔ b) (a ⊔ b) →
∀ n → A ↔[ k₁ ] B → H-level n A ↝[ k₂ ] H-level n B
H-level-cong {a = a} {b} ext n A↔B′ =
generalise-ext?-prop
(record
{ to = respects-surjection (_↔_.surjection A↔B) n
; from = respects-surjection (_↔_.surjection (inverse A↔B)) n
})
(λ ext → H-level-propositional (lower-extensionality b b ext) n)
(λ ext → H-level-propositional (lower-extensionality a a ext) n)
ext
where
A↔B = from-isomorphism A↔B′
-- H-level′ n preserves isomorphisms (assuming extensionality).
H-level′-cong :
∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
Extensionality? k₂ (a ⊔ b) (a ⊔ b) →
∀ n → A ↔[ k₁ ] B → H-level′ n A ↝[ k₂ ] H-level′ n B
H-level′-cong {k₂ = k₂} {a = a} {b = b} {A = A} {B = B} ext n A↔B =
H-level′ n A ↝⟨ inverse-ext? H-level↔H-level′ (lower-extensionality? k₂ b b ext) ⟩
H-level n A ↝⟨ H-level-cong ext n A↔B ⟩
H-level n B ↝⟨ H-level↔H-level′ (lower-extensionality? k₂ a a ext) ⟩□
H-level′ n B □
-- There is an isomorphism between (x y : A) → H-level n (x ≡ y) and
-- H-level (suc n) A (assuming extensionality).
≡↔+ :
∀ {a} {A : Type a} n →
((x y : A) → H-level n (x ≡ y)) ↝[ a ∣ a ] H-level (suc n) A
≡↔+ {A = A} n ext =
((x y : A) → H-level n (x ≡ y)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → H-level↔H-level′ ext) ⟩
((x y : A) → H-level′ n (x ≡ y)) ↔⟨⟩
H-level′ (suc n) A ↝⟨ inverse-ext? H-level↔H-level′ ext ⟩□
H-level (suc n) A □
-- Some lemmas relating equivalences A ≃ B with types of the form
-- ∀ C → H-level n C → (A → C) ≃ (B → C).
→≃→↠≃ :
∀ n {ℓ} {A B : Type ℓ} →
Extensionality ℓ ℓ →
(hA : H-level n A) (hB : H-level n B) →
(∃ λ (f : (C : Type ℓ) → H-level n C → (A → C) ≃ (B → C)) →
((C : Type ℓ) (hC : H-level n C) (g : A → C) →
g ∘ _≃_.to (f A hA) id ≡ _≃_.to (f C hC) g) ×
((C : Type ℓ) (hC : H-level n C) (g : B → C) →
g ∘ _≃_.from (f B hB) id ≡ _≃_.from (f C hC) g))
↠
(A ≃ B)
→≃→↠≃ _ {A = A} {B} ext hA hB = record
{ logical-equivalence = record
{ from = λ A≃B → (λ _ _ → →-cong₁ ext A≃B)
, (λ _ _ g → refl (g ∘ _≃_.from A≃B))
, (λ _ _ g → refl (g ∘ _≃_.to A≃B))
; to = λ { (A→≃B→ , ∘to≡ , ∘from≡) → Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = _≃_.from (A→≃B→ B hB) id
; from = _≃_.to (A→≃B→ A hA) id
}
; right-inverse-of = λ x →
_≃_.from (A→≃B→ B hB) id (_≃_.to (A→≃B→ A hA) id x) ≡⟨⟩
(_≃_.from (A→≃B→ B hB) id ∘ _≃_.to (A→≃B→ A hA) id) x ≡⟨ cong (_$ x) $ ∘to≡ _ _ _ ⟩
(_≃_.to (A→≃B→ B hB) (_≃_.from (A→≃B→ B hB) id)) x ≡⟨ cong (_$ x) $ _≃_.right-inverse-of (A→≃B→ B hB) _ ⟩∎
x ∎
}
; left-inverse-of = λ x →
_≃_.to (A→≃B→ A hA) id (_≃_.from (A→≃B→ B hB) id x) ≡⟨⟩
(_≃_.to (A→≃B→ A hA) id ∘ _≃_.from (A→≃B→ B hB) id) x ≡⟨ cong (_$ x) $ ∘from≡ _ _ _ ⟩
(_≃_.from (A→≃B→ A hA) (_≃_.to (A→≃B→ A hA) id)) x ≡⟨ cong (_$ x) $ _≃_.left-inverse-of (A→≃B→ A hA) _ ⟩∎
x ∎
}) }
}
; right-inverse-of = λ A≃B → _↔_.to (≃-to-≡↔≡ ext) λ x →
refl (_≃_.to A≃B x)
}
-- The following property can be generalised.
→≃→↔≃ :
∀ {ℓ} {A B : Type ℓ} →
Extensionality (lsuc ℓ) ℓ →
(hA : Is-set A) (hB : Is-set B) →
(∃ λ (f : (C : Type ℓ) → Is-set C → (A → C) ≃ (B → C)) →
((C : Type ℓ) (hC : Is-set C) (g : A → C) →
g ∘ _≃_.to (f A hA) id ≡ _≃_.to (f C hC) g) ×
((C : Type ℓ) (hC : Is-set C) (g : B → C) →
g ∘ _≃_.from (f B hB) id ≡ _≃_.from (f C hC) g))
↔
(A ≃ B)
→≃→↔≃ {A = A} {B} ext hA hB = record
{ surjection = →≃→↠≃ 2 ext′ hA hB
; left-inverse-of = λ { (A→≃B→ , ∘to≡ , _) →
Σ-≡,≡→≡
(apply-ext ext λ C →
apply-ext ext′ λ hC →
_↔_.to (≃-to-≡↔≡ ext′) λ f →
f ∘ _≃_.to (A→≃B→ A hA) id ≡⟨ ∘to≡ _ _ _ ⟩∎
_≃_.to (A→≃B→ C (hC {_})) f ∎)
((×-closure 1
(Π-closure ext 1 λ _ →
Π-closure ext′ 1 λ hC →
Π-closure ext′ 1 λ _ →
Π-closure ext′ 2 λ _ → hC {_})
(Π-closure ext 1 λ _ →
Π-closure ext′ 1 λ hC →
Π-closure ext′ 1 λ _ →
Π-closure ext′ 2 λ _ → hC {_})) _ _) }
}
where
ext′ = lower-extensionality _ lzero ext
------------------------------------------------------------------------
-- Lemmas related to Dec
-- A preservation lemma for Dec.
Dec-cong :
∀ {k a b} {A : Type a} {B : Type b} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b) lzero →
A ↝[ ⌊ k ⌋-sym ] B →
Dec A ↝[ ⌊ k ⌋-sym ] Dec B
Dec-cong {A = A} {B = B} ext A↝B =
A ⊎ ¬ A ↝⟨ A↝B ⊎-cong →-cong ext A↝B id ⟩□
B ⊎ ¬ B □
-- A preservation lemma for Decidable.
Decidable-cong :
∀ {k₁ k₂ k₃ a₁ b₁ p₁ a₂ b₂ p₂}
{A₁ : Type a₁} {B₁ : Type b₁} {P₁ : A₁ → B₁ → Type p₁}
{A₂ : Type a₂} {B₂ : Type b₂} {P₂ : A₂ → B₂ → Type p₂} →
Extensionality? ⌊ k₃ ⌋-sym (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂ ⊔ p₁ ⊔ p₂)
(b₁ ⊔ b₂ ⊔ p₁ ⊔ p₂) →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂)
(B₁↔B₂ : B₁ ↔[ k₂ ] B₂) →
(∀ x y →
P₁ x y
↝[ ⌊ k₃ ⌋-sym ]
P₂ (to-implication A₁↔A₂ x) (to-implication B₁↔B₂ y)) →
Decidable P₁ ↝[ ⌊ k₃ ⌋-sym ] Decidable P₂
Decidable-cong
{k₃ = k₃} {a₁} {b₁} {p₁} {a₂} {b₂} {p₂} {P₁ = P₁} {P₂ = P₂}
ext A₁↔A₂ B₁↔B₂ P₁↝P₂ =
(∀ x y → Dec (P₁ x y)) ↝⟨ (Π-cong (lower-extensionality? ⌊ k₃ ⌋-sym (b₁ ⊔ b₂ ⊔ p₁ ⊔ p₂) lzero ext) A₁↔A₂ λ x →
Π-cong (lower-extensionality? ⌊ k₃ ⌋-sym (a₁ ⊔ a₂ ⊔ p₁ ⊔ p₂) (b₁ ⊔ b₂) ext) B₁↔B₂ λ y →
Dec-cong (lower-extensionality? ⌊ k₃ ⌋-sym (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂) _ ext) (P₁↝P₂ x y)) ⟩□
(∀ x y → Dec (P₂ x y)) □
-- A preservation lemma for Decidable-equality.
Decidable-equality-cong :
∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
Extensionality? k₂ (a ⊔ b) (a ⊔ b) →
A ↔[ k₁ ] B →
Decidable-equality A ↝[ k₂ ] Decidable-equality B
Decidable-equality-cong ext A↔B =
generalise-ext?
(Decidable-cong _ A≃B A≃B lemma)
(λ ext →
let bij = Decidable-cong ext A≃B A≃B lemma in
_↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
ext
where
A≃B = from-isomorphism A↔B
lemma : ∀ {k} _ _ → _ ↝[ k ] _
lemma x y =
x ≡ y ↔⟨ inverse $ Eq.≃-≡ A≃B ⟩□
_≃_.to A≃B x ≡ _≃_.to A≃B y □
------------------------------------------------------------------------
-- Lemmas related to if
-- A generalisation of if-encoding (which is defined below).
if-lemma : ∀ {a b p} {A : Type a} {B : Type b} (P : Bool → Type p) →
A ↔ P true → B ↔ P false →
∀ b → T b × A ⊎ T (not b) × B ↔ P b
if-lemma {A = A} {B} P A↔ B↔ true =
⊤ × A ⊎ ⊥ × B ↔⟨ ×-left-identity ⊎-cong ×-left-zero ⟩
A ⊎ ⊥₀ ↔⟨ ⊎-right-identity ⟩
A ↔⟨ A↔ ⟩
P true □
if-lemma {A = A} {B} P A↔ B↔ false =
⊥ × A ⊎ ⊤ × B ↔⟨ ×-left-zero ⊎-cong ×-left-identity ⟩
⊥₀ ⊎ B ↔⟨ ⊎-left-identity ⟩
B ↔⟨ B↔ ⟩
P false □
-- An encoding of if_then_else_ in terms of _⊎_, _×_, T and not.
if-encoding : ∀ {ℓ} {A B : Type ℓ} →
∀ b → (if b then A else B) ↔ T b × A ⊎ T (not b) × B
if-encoding {A = A} {B} =
inverse ⊚ if-lemma (λ b → if b then A else B) id id
------------------------------------------------------------------------
-- Properties related to ℕ
-- The natural numbers are isomorphic to the natural numbers extended
-- with another element.
ℕ↔ℕ⊎⊤ : ℕ ↔ ℕ ⊎ ⊤
ℕ↔ℕ⊎⊤ = record
{ surjection = record
{ logical-equivalence = record
{ to = ℕ-rec (inj₂ tt) (λ n _ → inj₁ n)
; from = [ suc , const zero ]
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of = ℕ-rec (refl 0) (λ n _ → refl (suc n))
}
private
-- Two consequences of ℕ↔ℕ⊎⊤.
Σℕ≃′ :
∀ {p} {P : ℕ → Type p} →
(∃ λ n → P n) ≃ (P zero ⊎ ∃ λ n → P (suc n))
Σℕ≃′ {P = P} =
(∃ λ n → P n) ↝⟨ (Σ-cong-contra (inverse ℕ↔ℕ⊎⊤) λ _ → id) ⟩
(∃ λ (x : ℕ ⊎ ⊤) → P (_↔_.from ℕ↔ℕ⊎⊤ x)) ↔⟨ ∃-⊎-distrib-right ⟩
(∃ λ (n : ℕ) → P (suc n)) ⊎ ⊤ × P zero ↔⟨ ⊎-comm ⟩
⊤ × P zero ⊎ (∃ λ (n : ℕ) → P (suc n)) ↔⟨ ×-left-identity ⊎-cong id ⟩□
P zero ⊎ (∃ λ (n : ℕ) → P (suc n)) □
Πℕ≃′ :
∀ {p} {P : ℕ → Type p} →
(∀ n → P n) ↝[ lzero ∣ p ] (P zero × ∀ n → P (suc n))
Πℕ≃′ {P = P} ext =
(∀ n → P n) ↝⟨ (Π-cong-contra ext (inverse ℕ↔ℕ⊎⊤) λ _ → id) ⟩
((x : ℕ ⊎ ⊤) → P (_↔_.from ℕ↔ℕ⊎⊤ x)) ↝⟨ Π⊎↔Π×Π ext ⟩
((n : ℕ) → P (suc n)) × (⊤ → P zero) ↔⟨ ×-comm ⟩
(⊤ → P zero) × ((n : ℕ) → P (suc n)) ↔⟨ Π-left-identity ×-cong id ⟩□
P zero × ((n : ℕ) → P (suc n)) □
-- Variants of Σℕ≃′ and Πℕ≃′ which, at the time of writing, have
-- "better" computational behaviour.
Σℕ≃ :
∀ {p} {P : ℕ → Type p} →
(∃ λ n → P n) ≃ (P zero ⊎ ∃ λ n → P (suc n))
Σℕ≃ {P = P} = Eq.↔→≃
(λ where
(zero , p) → inj₁ p
(suc n , p) → inj₂ (n , p))
[ (zero ,_) , Σ-map suc id ]
[ (λ _ → refl _) , (λ _ → refl _) ]
(λ where
(zero , _) → refl _
(suc _ , _) → refl _)
Πℕ≃ :
∀ {p} {P : ℕ → Type p} →
(∀ n → P n) ↝[ lzero ∣ p ] (P zero × ∀ n → P (suc n))
Πℕ≃ {P = P} =
generalise-ext?
Πℕ⇔
(λ ext →
refl
, (λ _ →
apply-ext ext $
ℕ-case (refl _) (λ _ → refl _)))
where
Πℕ⇔ : _ ⇔ _
Πℕ⇔ ._⇔_.to f = f zero , f ⊚ suc
Πℕ⇔ ._⇔_.from = uncurry ℕ-case
-- ℕ is isomorphic to ℕ ⊎ ℕ.
ℕ↔ℕ⊎ℕ : ℕ ↔ ℕ ⊎ ℕ
ℕ↔ℕ⊎ℕ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
step : ℕ ⊎ ℕ → ℕ ⊎ ℕ
step = [ inj₂ , inj₁ ∘ suc ]
to : ℕ → ℕ ⊎ ℕ
to zero = inj₁ zero
to (suc n) = step (to n)
double : ℕ → ℕ
double zero = zero
double (suc n) = suc (suc (double n))
from : ℕ ⊎ ℕ → ℕ
from = [ double , suc ∘ double ]
from∘to : ∀ n → from (to n) ≡ n
from∘to zero = zero ∎
from∘to (suc n) with to n | from∘to n
... | inj₁ m | eq =
suc (double m) ≡⟨ cong suc eq ⟩∎
suc n ∎
... | inj₂ m | eq =
suc (suc (double m)) ≡⟨ cong suc eq ⟩∎
suc n ∎
to∘double : ∀ n → to (double n) ≡ inj₁ n
to∘double zero = inj₁ zero ∎
to∘double (suc n) =
to (double (suc n)) ≡⟨⟩
to (suc (suc (double n))) ≡⟨⟩
step (step (to (double n))) ≡⟨ cong (step ∘ step) (to∘double n) ⟩
step (step (inj₁ n)) ≡⟨⟩
inj₁ (suc n) ∎
to∘from : ∀ x → to (from x) ≡ x
to∘from =
[ to∘double
, (λ n →
to (from (inj₂ n)) ≡⟨⟩
to (suc (double n)) ≡⟨⟩
step (to (double n)) ≡⟨ cong step (to∘double n) ⟩
step (inj₁ n) ≡⟨⟩
inj₂ n ∎)
]
-- ℕ is isomorphic to ℕ².
ℕ↔ℕ² : ℕ ↔ ℕ × ℕ
ℕ↔ℕ² = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
step : ℕ × ℕ → ℕ × ℕ
step (m , zero) = (zero , suc m)
step (m , suc n) = (suc m , n)
to : ℕ → ℕ × ℕ
to zero = (zero , zero)
to (suc n) = step (to n)
-- The function from′ is defined by lexicographic induction on first
-- sum, and then m.
from′ : (m n sum : ℕ) → n + m ≡ sum → ℕ
from′ zero zero _ _ = zero
from′ zero (suc n) zero eq = ⊥-elim (0≢+ (sym eq))
from′ zero (suc n) (suc sum) eq = suc (from′ n zero sum (cancel-suc
(suc n ≡⟨ cong suc (sym +-right-identity) ⟩
suc (n + 0) ≡⟨ eq ⟩∎
suc sum ∎)))
from′ (suc m) n sum eq = suc (from′ m (suc n) sum
(suc n + m ≡⟨ suc+≡+suc n ⟩
n + suc m ≡⟨ eq ⟩∎
sum ∎))
from : ℕ × ℕ → ℕ
from (m , n) = from′ m n _ (refl _)
from′-irr : ∀ m {n sum₁ eq₁ sum₂ eq₂} →
from′ m n sum₁ eq₁ ≡ from′ m n sum₂ eq₂
from′-irr m {n} {sum₁} {eq₁} {sum₂} {eq₂} =
from′ m n sum₁ eq₁ ≡⟨ cong (uncurry (from′ m n)) (Σ-≡,≡→≡ lemma (ℕ-set _ _)) ⟩∎
from′ m n sum₂ eq₂ ∎
where
lemma =
sum₁ ≡⟨ sym eq₁ ⟩
n + m ≡⟨ eq₂ ⟩∎
sum₂ ∎
from∘step : ∀ p → from (step p) ≡ suc (from p)
from∘step (m , zero) = from (zero , suc m) ≡⟨ cong suc (from′-irr m) ⟩∎
suc (from (m , zero)) ∎
from∘step (m , suc n) = from (suc m , n) ≡⟨ cong suc (from′-irr m) ⟩∎
suc (from (m , suc n)) ∎
from∘to : ∀ n → from (to n) ≡ n
from∘to zero = refl _
from∘to (suc n) =
from (to (suc n)) ≡⟨⟩
from (step (to n)) ≡⟨ from∘step (to n) ⟩
suc (from (to n)) ≡⟨ cong suc (from∘to n) ⟩∎
suc n ∎
to∘from′ : ∀ m n sum eq → to (from′ m n sum eq) ≡ (m , n)
to∘from′ zero zero _ _ = refl _
to∘from′ zero (suc n) zero eq = ⊥-elim (0≢+ (sym eq))
to∘from′ zero (suc n) (suc sum) eq =
step (to (from′ n zero _ _)) ≡⟨ cong step (to∘from′ n zero sum _) ⟩
step (n , zero) ≡⟨⟩
(zero , suc n) ∎
to∘from′ (suc m) n sum eq =
step (to (from′ m (suc n) _ _)) ≡⟨ cong step (to∘from′ m (suc n) sum _) ⟩
step (m , suc n) ≡⟨⟩
(suc m , n) ∎
to∘from : ∀ p → to (from p) ≡ p
to∘from _ = to∘from′ _ _ _ _
-- Some isomorphisms related to equality of natural numbers.
zero≡zero↔ : zero ≡ zero ↔ ⊤
zero≡zero↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ℕ-set (mono₁ 0 ⊤-contractible)) $
record { to = _; from = λ _ → refl _ }
zero≡suc↔ : ∀ {n} → zero ≡ suc n ↔ ⊥₀
zero≡suc↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ℕ-set ⊥-propositional) $
record { to = 0≢+; from = ⊥-elim }
suc≡zero↔ : ∀ {m} → suc m ≡ zero ↔ ⊥₀
suc≡zero↔ {m} =
suc m ≡ zero ↝⟨ ≡-comm ⟩
zero ≡ suc m ↝⟨ zero≡suc↔ ⟩□
⊥ □
suc≡suc↔ : ∀ {m n} → suc m ≡ suc n ↔ m ≡ n
suc≡suc↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ℕ-set ℕ-set) $
record { to = cancel-suc; from = cong suc }
-- The equality test Nat._==_ gives the right result.
T[==]↔≡ : {m n : ℕ} → T (m == n) ↔ m ≡ n
T[==]↔≡ {m = zero} {n = zero} =
T (zero == zero) ↔⟨⟩
⊤ ↝⟨ inverse zero≡zero↔ ⟩□
zero ≡ zero □
T[==]↔≡ {m = zero} {n = suc n} =
T (zero == suc n) ↔⟨⟩
⊥ ↝⟨ inverse zero≡suc↔ ⟩□
zero ≡ suc n □
T[==]↔≡ {m = suc m} {n = zero} =
T (suc m == zero) ↔⟨⟩
⊥ ↝⟨ inverse suc≡zero↔ ⟩□
suc m ≡ zero □
T[==]↔≡ {m = suc m} {n = suc n} =
T (suc m == suc n) ↔⟨⟩
T (m == n) ↝⟨ T[==]↔≡ ⟩
m ≡ n ↝⟨ inverse suc≡suc↔ ⟩□
suc m ≡ suc n □
-- Some isomorphisms related to the ordering of natural numbers.
zero≤↔ : ∀ {n} → zero ≤ n ↔ ⊤
zero≤↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional (mono₁ 0 ⊤-contractible)) $
record { to = _; from = λ _ → zero≤ _ }
<zero↔ : ∀ {n} → n < zero ↔ ⊥
<zero↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ⊥-propositional) $
record { to = ≮0 _; from = ⊥-elim }
suc≤suc↔ : ∀ {m n} → suc m ≤ suc n ↔ m ≤ n
suc≤suc↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ≤-propositional) $
record { to = suc≤suc⁻¹; from = suc≤suc }
≤↔<⊎≡ : ∀ {m n} → m ≤ n ↔ m < n ⊎ m ≡ n
≤↔<⊎≡ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional
(⊎-closure-propositional
<→≢ ≤-propositional ℕ-set)) $
record { to = ≤→<⊎≡; from = [ <→≤ , ≤-refl′ ] }
≤↔≡0⊎0<×≤ : ∀ {m n} → m ≤ n ↔ m ≡ 0 ⊎ 0 < m × m ≤ n
≤↔≡0⊎0<×≤ {zero} {n} =
0 ≤ n ↝⟨ zero≤↔ ⟩
⊤ ↝⟨ inverse ⊎-right-identity ⟩
⊤ ⊎ ⊥₀ ↝⟨ id ⊎-cong inverse ×-left-zero ⟩
⊤ ⊎ (⊥ × 0 ≤ n) ↝⟨ inverse (_⇔_.to contractible⇔↔⊤ (propositional⇒inhabited⇒contractible ℕ-set (refl _)))
⊎-cong
inverse <zero↔ ×-cong id ⟩□
0 ≡ 0 ⊎ 0 < 0 × 0 ≤ n □
≤↔≡0⊎0<×≤ {suc m} {n} =
m < n ↝⟨ inverse ×-left-identity ⟩
⊤ × m < n ↝⟨ inverse zero≤↔ ×-cong id ⟩
0 ≤ m × m < n ↝⟨ inverse ⊎-left-identity ⟩
⊥₀ ⊎ 0 ≤ m × m < n ↝⟨ Bijection.⊥↔uninhabited (0≢+ ∘ sym) ⊎-cong inverse suc≤suc↔ ×-cong id ⟩□
1 + m ≡ 0 ⊎ 0 < 1 + m × m < n □
≤↔min≡ : ∀ {m n} → m ≤ n ↔ min m n ≡ m
≤↔min≡ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ℕ-set) $
≤⇔min≡
≤↔max≡ : ∀ {m n} → m ≤ n ↔ max m n ≡ n
≤↔max≡ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ℕ-set) $
≤⇔max≡
∃0<↔∃suc :
∀ {p} {P : ℕ → Type p} →
(∃ λ n → 0 < n × P n) ↔ (∃ λ n → P (suc n))
∃0<↔∃suc {P = P} = record
{ surjection = record
{ logical-equivalence = record
{ to = Σ-map pred λ where
{zero} (0<0 , _) → ⊥-elim (≮0 _ 0<0)
{suc _} (_ , p) → p
; from = Σ-map suc (λ p → suc≤suc (zero≤ _) , p)
}
; right-inverse-of = refl
}
; left-inverse-of = λ where
(zero , 0<0 , p) → ⊥-elim (≮0 _ 0<0)
(suc n , 0<+ , p) →
Σ-≡,≡→≡ (refl _)
(trans (subst-refl _ _)
(_↔_.to ≡×≡↔≡
( ≤-propositional _ _
, refl _
)))
}
∃<↔∃0<×≤ : ∀ {n} → (∃ λ m → m < n) ↔ (∃ λ m → 0 < m × m ≤ n)
∃<↔∃0<×≤ {n} =
(∃ λ m → m < n) ↔⟨⟩
(∃ λ m → suc m ≤ n) ↝⟨ inverse ∃0<↔∃suc ⟩□
(∃ λ m → 0 < m × m ≤ n) □
-- The ordering test Nat._<=_ gives the right result.
T[<=]↔≤ : {m n : ℕ} → T (m <= n) ↔ m ≤ n
T[<=]↔≤ {m = zero} {n = n} =
T (zero <= n) ↔⟨⟩
⊤ ↝⟨ inverse zero≤↔ ⟩□
zero ≤ n □
T[<=]↔≤ {m = suc m} {n = zero} =
T (suc m <= zero) ↔⟨⟩
⊥ ↝⟨ inverse <zero↔ ⟩□
suc m ≤ zero □
T[<=]↔≤ {m = suc m} {n = suc n} =
T (suc m <= suc n) ↔⟨⟩
T (m <= n) ↝⟨ T[<=]↔≤ ⟩
m ≤ n ↝⟨ inverse suc≤suc↔ ⟩□
suc m ≤ suc n □
-- Equality or distinctness of two natural numbers is isomorphic to
-- the unit type.
≡⊎Distinct↔⊤ : ∀ m n → m ≡ n ⊎ Distinct m n ↔ ⊤
≡⊎Distinct↔⊤ m n =
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(⊎-closure-propositional
(λ m≡n m≢n → _⇔_.to Distinct⇔≢ m≢n m≡n)
ℕ-set
(Distinct-propositional m n))
(≡⊎Distinct m n)
-- Distinct is pointwise logically equivalent to _≢_, and in the
-- presence of extensionality the two definitions are pointwise
-- isomorphic.
Distinct↔≢ : ∀ {m n} → Distinct m n ↝[ lzero ∣ lzero ] m ≢ n
Distinct↔≢ {m = m} {n} =
generalise-ext?-prop
Distinct⇔≢
(λ _ → Distinct-propositional m n)
¬-propositional
------------------------------------------------------------------------
-- Left cancellation for _⊎_
-- In general _⊎_ is not left cancellative.
¬-⊎-left-cancellative :
∀ k → ¬ ((A B C : Type) → A ⊎ B ↝[ k ] A ⊎ C → B ↝[ k ] C)
¬-⊎-left-cancellative k cancel =
¬B→C $ to-implication $ cancel A B C (from-bijection A⊎B↔A⊎C)
where
A = ℕ
B = ⊤
C = ⊥
A⊎B↔A⊎C : A ⊎ B ↔ A ⊎ C
A⊎B↔A⊎C =
ℕ ⊎ ⊤ ↔⟨ inverse ℕ↔ℕ⊎⊤ ⟩
ℕ ↔⟨ inverse ⊎-right-identity ⟩
ℕ ⊎ ⊥ □
¬B→C : ¬ (B → C)
¬B→C B→C = B→C tt
-- However, it is left cancellative for certain well-behaved
-- bijections.
-- A function is "well-behaved" if any "left" element which is the
-- image of a "right" element is in turn not mapped to another "left"
-- element.
Well-behaved : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(A ⊎ B → A ⊎ C) → Type _
Well-behaved f =
∀ {b a a′} → f (inj₂ b) ≡ inj₁ a → f (inj₁ a) ≢ inj₁ a′
private
-- Some helper functions.
module ⊎-left-cancellative
{a b c} {A : Type a} {B : Type b} {C : Type c}
(f : A ⊎ B → A ⊎ C)
(hyp : Well-behaved f)
where
mutual
g : B → C
g b = g′ (inspect (f (inj₂ b)))
g′ : ∀ {b} → Other-singleton (f (inj₂ b)) → C
g′ (inj₂ c , _) = c
g′ (inj₁ a , eq) = g″ eq (inspect (f (inj₁ a)))
g″ : ∀ {a b} →
f (inj₂ b) ≡ inj₁ a → Other-singleton (f (inj₁ a)) → C
g″ _ (inj₂ c , _) = c
g″ eq₁ (inj₁ _ , eq₂) = ⊥-elim $ hyp eq₁ eq₂
⊎-left-cancellative :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
(f : A ⊎ B ↔ A ⊎ C) →
Well-behaved (_↔_.to f) →
Well-behaved (_↔_.from f) →
B ↔ C
⊎-left-cancellative {A = A} = λ inv to-hyp from-hyp → record
{ surjection = record
{ logical-equivalence = record
{ to = g (to inv) to-hyp
; from = g (from inv) from-hyp
}
; right-inverse-of = g∘g (inverse inv) from-hyp to-hyp
}
; left-inverse-of = g∘g inv to-hyp from-hyp
}
where
open _↔_
open ⊎-left-cancellative
abstract
g∘g : ∀ {b c} {B : Type b} {C : Type c}
(f : A ⊎ B ↔ A ⊎ C) →
(to-hyp : Well-behaved (to f)) →
(from-hyp : Well-behaved (from f)) →
∀ b → g (from f) from-hyp (g (to f) to-hyp b) ≡ b
g∘g f to-hyp from-hyp b = g∘g′
where
g∘g′ : g (from f) from-hyp (g (to f) to-hyp b) ≡ b
g∘g′ with inspect (to f (inj₂ b))
g∘g′ | inj₂ c , eq₁ with inspect (from f (inj₂ c))
g∘g′ | inj₂ c , eq₁ | inj₂ b′ , eq₂ = ⊎.cancel-inj₂ (
inj₂ b′ ≡⟨ sym eq₂ ⟩
from f (inj₂ c) ≡⟨ to-from f eq₁ ⟩∎
inj₂ b ∎)
g∘g′ | inj₂ c , eq₁ | inj₁ a , eq₂ = ⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ a ≡⟨ sym eq₂ ⟩
from f (inj₂ c) ≡⟨ to-from f eq₁ ⟩∎
inj₂ b ∎)
g∘g′ | inj₁ a , eq₁ with inspect (to f (inj₁ a))
g∘g′ | inj₁ a , eq₁ | inj₁ a′ , eq₂ = ⊥-elim $ to-hyp eq₁ eq₂
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ with inspect (from f (inj₂ c))
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₂ b′ , eq₃ = ⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ a ≡⟨ sym $ to-from f eq₂ ⟩
from f (inj₂ c) ≡⟨ eq₃ ⟩∎
inj₂ b′ ∎)
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ with inspect (from f (inj₁ a′))
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ | inj₁ a″ , eq₄ = ⊥-elim $ from-hyp eq₃ eq₄
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ | inj₂ b′ , eq₄ = ⊎.cancel-inj₂ (
let lemma =
inj₁ a′ ≡⟨ sym eq₃ ⟩
from f (inj₂ c) ≡⟨ to-from f eq₂ ⟩∎
inj₁ a ∎
in
inj₂ b′ ≡⟨ sym eq₄ ⟩
from f (inj₁ a′) ≡⟨ cong (from f ⊚ inj₁) $ ⊎.cancel-inj₁ lemma ⟩
from f (inj₁ a) ≡⟨ to-from f eq₁ ⟩∎
inj₂ b ∎)
-- _⊎_ is left cancellative (for bijections) if the left argument is
-- the unit type.
⊎-left-cancellative-⊤ :
∀ {a b} {A : Type a} {B : Type b} →
(⊤ ⊎ A) ↔ (⊤ ⊎ B) → A ↔ B
⊎-left-cancellative-⊤ = λ ⊤⊎A↔⊤⊎B →
⊎-left-cancellative ⊤⊎A↔⊤⊎B
(wb ⊤⊎A↔⊤⊎B)
(wb $ inverse ⊤⊎A↔⊤⊎B)
where
open _↔_
abstract
wb : ∀ {a b} {A : Type a} {B : Type b}
(⊤⊎A↔⊤⊎B : (⊤ ⊎ A) ↔ (⊤ ⊎ B)) →
Well-behaved (_↔_.to ⊤⊎A↔⊤⊎B)
wb ⊤⊎A↔⊤⊎B {b = b} eq₁ eq₂ = ⊎.inj₁≢inj₂ (
inj₁ tt ≡⟨ sym $ to-from ⊤⊎A↔⊤⊎B eq₂ ⟩
from ⊤⊎A↔⊤⊎B (inj₁ tt) ≡⟨ to-from ⊤⊎A↔⊤⊎B eq₁ ⟩∎
inj₂ b ∎)
-- If the codomain of ⊎-left-cancellative-⊤ is paired up with a value
-- in ⊤ ⊎ B, then the function can be strengthened to a bijection
-- (assuming both decidability of equality of values in B and
-- extensionality).
[⊤⊎↔⊤⊎]↔[⊤⊎×↔] :
∀ {a b} {A : Type a} {B : Type b} →
Decidable-equality B →
((⊤ ⊎ A) ↔ (⊤ ⊎ B)) ↝[ a ⊔ b ∣ a ⊔ b ] (⊤ ⊎ B) × (A ↔ B)
[⊤⊎↔⊤⊎]↔[⊤⊎×↔] {a = a} {b = b} {A = A} {B = B} _≟B_ =
generalise-ext? [⊤⊎↔⊤⊎]⇔[⊤⊎×↔] (λ ext → to∘from ext , from∘to ext)
where
_≟_ : Decidable-equality (⊤ ⊎ B)
_≟_ = ⊎.Dec._≟_ ⊤._≟_ _≟B_
if-not : ∀ {a p} {A : Type a} {P : Type p} (d : Dec P) (t e : A) →
¬ P → if d then t else e ≡ e
if-not (yes p) t e ¬p = ⊥-elim (¬p p)
if-not (no _) t e ¬p = refl _
to : (⊤ ⊎ A) ↔ (⊤ ⊎ B) → (⊤ ⊎ B) × (A ↔ B)
to ⊤⊎A↔⊤⊎B = _↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt) , ⊎-left-cancellative-⊤ ⊤⊎A↔⊤⊎B
from : (⊤ ⊎ B) × (A ↔ B) → (⊤ ⊎ A) ↔ (⊤ ⊎ B)
from (⊤⊎B , A↔B) = record
{ surjection = record
{ logical-equivalence = record
{ to = t ⊤⊎B
; from = f ⊤⊎B
}
; right-inverse-of = t∘f ⊤⊎B
}
; left-inverse-of = f∘t ⊤⊎B
}
where
t : ⊤ ⊎ B → ⊤ ⊎ A → ⊤ ⊎ B
t ⊤⊎B (inj₁ tt) = ⊤⊎B
t ⊤⊎B (inj₂ a) =
let b = inj₂ (_↔_.to A↔B a) in
if b ≟ ⊤⊎B then inj₁ tt else b
f : ⊤ ⊎ B → ⊤ ⊎ B → ⊤ ⊎ A
f ⊤⊎B (inj₁ tt) = [ const (inj₁ tt) , inj₂ ∘ _↔_.from A↔B ] ⊤⊎B
f ⊤⊎B (inj₂ b) =
if ⊤⊎B ≟ inj₂ b then inj₁ tt else inj₂ (_↔_.from A↔B b)
abstract
t∘f : ∀ ⊤⊎B x → t ⊤⊎B (f ⊤⊎B x) ≡ x
t∘f (inj₁ tt) (inj₁ tt) = refl _
t∘f (inj₁ tt) (inj₂ b′) = inj₂ (_↔_.to A↔B (_↔_.from A↔B b′)) ≡⟨ cong inj₂ $ _↔_.right-inverse-of A↔B _ ⟩∎
inj₂ b′ ∎
t∘f (inj₂ b) (inj₁ tt) with _↔_.to A↔B (_↔_.from A↔B b) ≟B b
t∘f (inj₂ b) (inj₁ tt) | yes _ = refl _
t∘f (inj₂ b) (inj₁ tt) | no b≢b = ⊥-elim $ b≢b (
_↔_.to A↔B (_↔_.from A↔B b) ≡⟨ _↔_.right-inverse-of A↔B _ ⟩∎
b ∎)
t∘f (inj₂ b) (inj₂ b′) with b ≟B b′
t∘f (inj₂ b) (inj₂ b′) | yes b≡b′ = inj₂ b ≡⟨ cong inj₂ b≡b′ ⟩∎
inj₂ b′ ∎
t∘f (inj₂ b) (inj₂ b′) | no b≢b′ =
t (inj₂ b) (inj₂ (_↔_.from A↔B b′)) ≡⟨⟩
if inj₂ (_↔_.to A↔B (_↔_.from A↔B b′)) ≟ inj₂ b then inj₁ tt
else inj₂ (_↔_.to A↔B (_↔_.from A↔B b′)) ≡⟨ cong (λ b′ → if inj₂ b′ ≟ inj₂ b then inj₁ tt else inj₂ b′) $
_↔_.right-inverse-of A↔B _ ⟩
if inj₂ b′ ≟ inj₂ b then inj₁ tt else inj₂ b′ ≡⟨ if-not (inj₂ b′ ≟ inj₂ b) (inj₁ tt) _ (b≢b′ ∘ sym ∘ ⊎.cancel-inj₂) ⟩∎
inj₂ b′ ∎
f∘t : ∀ ⊤⊎B x → f ⊤⊎B (t ⊤⊎B x) ≡ x
f∘t (inj₁ tt) (inj₁ tt) = refl _
f∘t (inj₁ tt) (inj₂ a) = inj₂ (_↔_.from A↔B (_↔_.to A↔B a)) ≡⟨ cong inj₂ $ _↔_.left-inverse-of A↔B _ ⟩∎
inj₂ a ∎
f∘t (inj₂ b) (inj₁ tt) with b ≟B b
f∘t (inj₂ b) (inj₁ tt) | yes _ = refl _
f∘t (inj₂ b) (inj₁ tt) | no b≢b = ⊥-elim $ b≢b (refl _)
f∘t (inj₂ b) (inj₂ a) with _↔_.to A↔B a ≟B b
f∘t (inj₂ b) (inj₂ a) | yes to-a≡b = inj₂ (_↔_.from A↔B b) ≡⟨ cong inj₂ $ _↔_.to-from A↔B to-a≡b ⟩∎
inj₂ a ∎
f∘t (inj₂ b) (inj₂ a) | no to-a≢b with b ≟B _↔_.to A↔B a
f∘t (inj₂ b) (inj₂ a) | no to-a≢b | yes b≡to-a = ⊥-elim $ to-a≢b
(_↔_.to A↔B a ≡⟨ sym b≡to-a ⟩∎
b ∎)
f∘t (inj₂ b) (inj₂ a) | no to-a≢b | no b≢to-a =
inj₂ (_↔_.from A↔B (_↔_.to A↔B a)) ≡⟨ cong inj₂ $ _↔_.left-inverse-of A↔B _ ⟩∎
inj₂ a ∎
[⊤⊎↔⊤⊎]⇔[⊤⊎×↔] : ((⊤ ⊎ A) ↔ (⊤ ⊎ B)) ⇔ (⊤ ⊎ B) × (A ↔ B)
[⊤⊎↔⊤⊎]⇔[⊤⊎×↔] = record
{ to = to
; from = from
}
to∘from :
Extensionality (a ⊔ b) (a ⊔ b) →
∀ x → to (from x) ≡ x
to∘from ext (⊤⊎B , A↔B) =
cong (⊤⊎B ,_) (_↔_.to (↔-to-≡↔≡ ext A-set) (lemma ⊤⊎B))
where
A-set : Is-set A
A-set = $⟨ _≟B_ ⟩
Decidable-equality B ↝⟨ decidable⇒set ⟩
Is-set B ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse A↔B) 2 ⟩□
Is-set A □
lemma :
∀ ⊤⊎B a →
_↔_.to (⊎-left-cancellative-⊤ (from (⊤⊎B , A↔B))) a ≡ _↔_.to A↔B a
lemma (inj₁ tt) a = refl _
lemma (inj₂ b) a with inspect (_↔_.to (from (inj₂ b , A↔B))
(inj₂ a))
lemma (inj₂ b) a | (inj₁ tt , eq) with _↔_.to A↔B a ≟B b
lemma (inj₂ b) a | (inj₁ tt , eq) | yes to-a≡b = sym to-a≡b
lemma (inj₂ b) a | (inj₁ tt , eq) | no _ = ⊥-elim $ ⊎.inj₁≢inj₂ $ sym eq
lemma (inj₂ b) a | (inj₂ _ , eq) with _↔_.to A↔B a ≟B b
lemma (inj₂ b) a | (inj₂ _ , eq) | yes _ = ⊥-elim $ ⊎.inj₁≢inj₂ eq
lemma (inj₂ b) a | (inj₂ _ , eq) | no _ = ⊎.cancel-inj₂ $ sym eq
from∘to :
Extensionality (a ⊔ b) (a ⊔ b) →
∀ x → from (to x) ≡ x
from∘to ext ⊤⊎A↔⊤⊎B = _↔_.to (↔-to-≡↔≡ ext ⊤⊎A-set) lemma₁
where
open ⊎-left-cancellative
⊤⊎A-set : Is-set (⊤ ⊎ A)
⊤⊎A-set = $⟨ _≟B_ ⟩
Decidable-equality B ↝⟨ decidable⇒set ⟩
Is-set B ↝⟨ ⊎-closure 0 (mono (zero≤ 2) ⊤-contractible) ⟩
Is-set (⊤ ⊎ B) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse ⊤⊎A↔⊤⊎B) 2 ⟩□
Is-set (⊤ ⊎ A) □
mutual
lemma₁ : ∀ ⊤⊎A →
_↔_.to (from (to ⊤⊎A↔⊤⊎B)) ⊤⊎A ≡ _↔_.to ⊤⊎A↔⊤⊎B ⊤⊎A
lemma₁ (inj₁ tt) = refl _
lemma₁ (inj₂ a) = lemma₂ (inspect _) (inspect _)
lemma₂ :
∀ {a} {wb : Well-behaved (_↔_.to ⊤⊎A↔⊤⊎B)}
(x : Other-singleton (_↔_.to ⊤⊎A↔⊤⊎B (inj₂ a)))
(y : Other-singleton (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt))) →
let b = g′ (_↔_.to ⊤⊎A↔⊤⊎B) wb x in
if inj₂ b ≟ proj₁ y then inj₁ tt else inj₂ b ≡ proj₁ x
lemma₂ {a} (inj₁ tt , eq₁) (inj₁ tt , eq₂) = ⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ tt ≡⟨ sym $ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt)) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) eq₂ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (inj₁ tt) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) $ sym eq₁ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₂ a)) ≡⟨ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩∎
inj₂ a ∎)
lemma₂ (inj₁ tt , eq₁) (inj₂ b′ , eq₂) = lemma₃ eq₁ (inspect _) eq₂ (inj₂ _ ≟ inj₂ b′)
lemma₂ (inj₂ b , eq₁) (inj₁ tt , eq₂) = refl _
lemma₂ (inj₂ b , eq₁) (inj₂ b′ , eq₂) with b ≟B b′
lemma₂ (inj₂ b , eq₁) (inj₂ b′ , eq₂) | no _ = refl _
lemma₂ {a} (inj₂ b , eq₁) (inj₂ b′ , eq₂) | yes b≡b′ =
⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ tt ≡⟨ sym $ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt)) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) eq₂ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (inj₂ b′) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B ∘ inj₂) $ sym b≡b′ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (inj₂ b) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) $ sym eq₁ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₂ a)) ≡⟨ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩∎
inj₂ a ∎)
lemma₃ :
∀ {a b′} {wb : Well-behaved (_↔_.to ⊤⊎A↔⊤⊎B)}
(eq : _↔_.to ⊤⊎A↔⊤⊎B (inj₂ a) ≡ inj₁ tt)
(x : Other-singleton (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt))) →
proj₁ x ≡ inj₂ b′ →
let b = g″ (_↔_.to ⊤⊎A↔⊤⊎B) wb eq x in
(d : Dec (inj₂ {A = ⊤} b ≡ inj₂ b′)) →
if d then inj₁ tt else inj₂ b ≡ inj₁ tt
lemma₃ eq₁ (inj₁ _ , eq₂) eq₃ _ = ⊥-elim $ ⊎.inj₁≢inj₂ eq₃
lemma₃ eq₁ (inj₂ b″ , eq₂) eq₃ (yes b″≡b′) = refl _
lemma₃ eq₁ (inj₂ b″ , eq₂) eq₃ (no b″≢b′) = ⊥-elim $ b″≢b′ eq₃
| {
"alphanum_fraction": 0.4486350187,
"avg_line_length": 37.2425972927,
"ext": "agda",
"hexsha": "f083e0bb93e7c34844c8f1a9a5e317517735b254",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Function-universe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Function-universe.agda",
"max_line_length": 148,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Function-universe.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 73799,
"size": 176083
} |
module Ambient where
open import Relation.Nullary
using (yes; no)
open import Data.String
using (String; _≟_)
open import Data.Bool
using (Bool; true; false)
open import Relation.Binary.PropositionalEquality
using (_≢_; refl)
renaming (_≡_ to _≡≡_)
open import Data.List
using (List; []; _∷_; _++_; filter)
-- Local modules ---------------------------------------------------------------
open import Common
using (Id)
open import Capability
using (Capability; `_; In; Out; Open; ε; _∙_)
renaming (_[_/_] to _[_/_]-capa; freeVar to freeVar-capa)
-- Process Definition ----------------------------------------------------------
infix 40 _[_/_]
infixr 30 Λ_∙_
infix 20 _[_]
infixr 10 _||_
data Process : Set where
ν_∙_ : Id → Process → Process -- Restriction
Zero : Process -- Inactivity
_||_ : Process → Process → Process -- Composition
!_ : Process → Process -- Replication
_[_] : Capability → Process → Process -- Ambient
_∙_ : Capability → Process → Process -- Action
Λ_∙_ : Id → Process → Process -- Input Action
<_> : Capability → Process -- Message
-- Free variable ---------------------------------------------------------------
_-_ : List Id → Id → List Id
[] - _ = []
(x ∷ xs) - y with x ≟ y
... | yes _ = xs - y
... | no _ = x ∷ (xs - y)
freeVar : Process → List Id
freeVar (ν x ∙ P) = freeVar P
freeVar Zero = []
freeVar (P || Q) = (freeVar P) ++ (freeVar Q)
freeVar (! P) = freeVar P
freeVar (M [ P ]) = (freeVar-capa M) ++ (freeVar P)
freeVar (M ∙ P) = (freeVar-capa M) ++ (freeVar P)
freeVar (Λ x ∙ P) = (freeVar P) - x
freeVar (< M >) = freeVar-capa M
_∉_ : Id → List Id → Set
y ∉ l = member y l ≡≡ false
where member : Id → List Id → Bool -- Should propably use the List filter instead!
member y [] = false
member y (x ∷ xs) with x ≟ y
... | yes _ = true
... | no _ = member y xs
-- Process substitution --------------------------------------------------------
_[_/_] : Process → Id → Capability → Process
Zero [ _ / _ ] = Zero
(P || Q) [ x / M ] = P [ x / M ] || Q [ x / M ]
(! P) [ x / M ] = ! (P [ x / M ])
(x [ P ]) [ y / M ] = (x [ y / M ]-capa) [ P [ y / M ] ]
(ν x ∙ P) [ y / M ] with x ≟ y
... | yes _ = ν x ∙ P
... | no _ = ν x ∙ (P [ y / M ])
< N > [ x / M ] = < N [ x / M ]-capa >
(Λ x ∙ P) [ y / M ] with x ≟ y
... | yes _ = Λ x ∙ P
... | no _ = Λ x ∙ (P [ y / M ])
( N ∙ P) [ x / M ] = (N [ x / M ]-capa) ∙ (P [ x / M ])
module Test where
a = "a"
b = "b"
------------------------------------------------------------------------------
_ : (` a [ < ` b > ]) [ b / Open a ] ≡≡ ` a [ < Open a > ]
_ = refl
_ : (< ` a > || < ` b >) [ b / Open a ] ≡≡ < ` a > || < Open a >
_ = refl
-- Congruence ------------------------------------------------------------------
infix 5 _≡_
data _≡_ : Process → Process → Set where
Struct-Refl : ∀ {P}
-----
→ P ≡ P
Struct-Symm : ∀ {P Q}
→ P ≡ Q
-----
→ Q ≡ P
Struct-Trans : ∀ {P Q R}
→ P ≡ Q → Q ≡ R
-------------
→ P ≡ R
Struct-Res : ∀ {n P Q}
→ P ≡ Q
-----------------
→ ν n ∙ P ≡ ν n ∙ Q
Struct-Par : ∀ {P Q R}
→ P ≡ Q
---------------
→ P || R ≡ Q || R
Struct-Repl : ∀ {P Q}
→ P ≡ Q
---------
→ ! P ≡ ! Q
Struct-Amb : ∀ {M P Q}
→ P ≡ Q
-----------------
→ M [ P ] ≡ M [ Q ]
Struct-Action : ∀ {M P Q}
→ P ≡ Q
-------------
→ M ∙ P ≡ M ∙ Q
Struct-Input : ∀ {x P Q}
→ P ≡ Q
---------------------
→ Λ x ∙ P ≡ Λ x ∙ Q
Struct-Comm : ∀ {P Q}
→ P ≡ Q
-----
→ Q ≡ P
Struct-Assoc : ∀ {P Q R}
-----------------------------
→ (P || Q) || R ≡ P || (Q || R)
Struct-ResRes : ∀ {n m P}
→ n ≢ m
-----------------------------
→ ν n ∙ ν m ∙ P ≡ ν m ∙ ν n ∙ P
Struct-ResPar : ∀ {n P Q}
→ n ∉ freeVar(P)
-----------------------------
→ ν n ∙ (P || Q) ≡ P || ν n ∙ Q
Struct-ResAmb : ∀ {n m P}
→ n ≢ m
-----------------------------------
→ ν n ∙ (` m [ P ]) ≡ ` m [ ν n ∙ P ]
Struct-ZeroPar : ∀ {P}
-------------
→ P || Zero ≡ P
Struct-ZeroRes : ∀ {n}
-----------------
→ ν n ∙ Zero ≡ Zero
Struct-ZeroRep : ! Zero ≡ Zero
Struct-ε : ---------------
ε ∙ Zero ≡ Zero
Struct-∙ : ∀ {M M' P}
---------------------------
→ (M ∙ M') ∙ P ≡ M ∙ (M' ∙ P)
-- Reduction rules -------------------------------------------------------------
infix 5 _~>_
data _~>_ : Process → Process → Set where
Red-In : ∀ {m n P Q R}
-----------------------------------------------------------------
→ ` m [ In n ∙ P || Q ] || ` n [ R ] ~> ` n [ ` m [ P || Q ] || R ]
Red-Out : ∀ {m n P Q R}
------------------------------------------------------------------
→ ` m [ ` n [ Out m ∙ P || R ] || Q ] ~> ` m [ Q ] || ` n [ P || R ]
Red-Open : ∀ {m P Q}
---------------------------------
→ ` m [ P ] || Open m ∙ Q ~> P || Q
Red-I/O : ∀ {M x P}
---------------------------------
→ < M > || Λ x ∙ P ~> P [ x / M ]
Red-Par : ∀ {P Q R}
→ P ~> Q
------------------
→ P || R ~> Q || R
Red-Res : ∀ {n P Q}
→ P ~> Q
--------------------
→ ν n ∙ P ~> ν n ∙ Q
Red-Amb : ∀ {M P Q}
→ P ~> Q
--------------------
→ M [ P ] ~> M [ Q ]
Red-≡ : ∀ {P P' Q Q'}
→ P' ≡ P → P ~> Q → Q ≡ Q'
-------------------------
→ P' ~> Q'
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.2844814534,
"avg_line_length": 28.4698275862,
"ext": "agda",
"hexsha": "3401ef5d5334a83bd2f34862e3383abe1a2ebdbc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "d-plaindoux/colca",
"max_forks_repo_path": "src/Ambient.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "d-plaindoux/colca",
"max_issues_repo_path": "src/Ambient.agda",
"max_line_length": 87,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "d-plaindoux/colca",
"max_stars_repo_path": "src/Ambient.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-04T09:35:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-03-12T18:31:14.000Z",
"num_tokens": 1904,
"size": 6605
} |
------------------------------------------------------------------------
-- The untyped SKI combinator calculus
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Undecidable.SK where
open import Data.Bool
open import Data.Product as Prod using (_,_; ∃; _×_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- The untyped SK(I) combinator calculus
infixl 9 _·_
infixl 4 _≡SK_ _≤SK?_ _⇛[_]_ _⇛[_]*_ _⇛≤_ _⇛≤*_ _⇛≥_ _⇛≥*_ _⇛≤*≤⇚_
-- Terms of the SK combinator calculus.
data SKTerm : Set where
S : SKTerm
K : SKTerm
_·_ : SKTerm → SKTerm → SKTerm
-- Equality of SK terms.
data _≡SK_ : SKTerm → SKTerm → Set where
≡-refl : ∀ {t} → t ≡SK t
≡-trans : ∀ {s t u} → s ≡SK t → t ≡SK u → s ≡SK u
≡-sym : ∀ {s t} → s ≡SK t → t ≡SK s
≡-Sred : ∀ {s t u} → S · s · t · u ≡SK s · u · (t · u)
≡-Kred : ∀ {s t} → K · s · t ≡SK s
≡-· : ∀ {s₁ s₂ t₁ t₂} →
s₁ ≡SK s₂ → t₁ ≡SK t₂ → s₁ · t₁ ≡SK s₂ · t₂
-- A well-known encoding of the I combinator.
I : SKTerm
I = S · K · K
-- Some admissible equality rules.
≡-Ired : ∀ {t} → I · t ≡SK t
≡-Ired = ≡-trans ≡-Sred ≡-Kred
≡-Sexp : ∀ {s t u} → s · u · (t · u) ≡SK S · s · t · u
≡-Sexp = ≡-sym ≡-Sred
≡-Kexp : ∀ {s t} → s ≡SK K · s · t
≡-Kexp = ≡-sym ≡-Kred
≡-Iexp : ∀ {t} → t ≡SK I · t
≡-Iexp = ≡-sym ≡-Ired
------------------------------------------------------------------------
-- A variant of the untyped SK calculus with extra term formers
data SK?Term : Set where
⊥ : SK?Term -- degenerate term
⊤ : SK?Term -- degenerate term
S : SK?Term
K : SK?Term
_·_ : SK?Term → SK?Term → SK?Term
-- An SK? term is pure if it is an SK term.
data Pure : SK?Term → Set where
S : Pure S
K : Pure K
_·_ : ∀ {s t} → Pure s → Pure t → Pure (s · t)
-- A partial order on SK? terms that resembles subtyping.
data _≤SK?_ : SK?Term → SK?Term → Set where
≤?-refl : ∀ {t} → t ≤SK? t
≤?-trans : ∀ {s t u} → s ≤SK? t → t ≤SK? u → s ≤SK? u
≤?-⊥ : ∀ {t} → ⊥ ≤SK? t
≤?-⊤ : ∀ {t} → t ≤SK? ⊤
≤?-Sred : ∀ {s t u} → S · s · t · u ≤SK? s · u · (t · u)
≤?-Kred : ∀ {s t} → K · s · t ≤SK? s
≤?-Sexp : ∀ {s t u} → s · u · (t · u) ≤SK? S · s · t · u
≤?-Kexp : ∀ {s t} → s ≤SK? K · s · t
≤?-· : ∀ {s₁ s₂ t₁ t₂} →
s₁ ≤SK? s₂ → t₁ ≤SK? t₂ → s₁ · t₁ ≤SK? s₂ · t₂
-- Parallel one-step and multi-step reduction of SK? terms, possibly
-- containing instances of ⊥-elim and ⊤-intro.
--
-- The `i' index in `_⇛[ i ]_' indicates whether the relation is
-- increasing (true) or decreasing (false). The increasing
-- single/multi-step relations are (strict) subrelations of _≤SK?_,
-- while the decreasing ones are subrelations of _≥SK?_ (i.e. the
-- inverse of _≤SK?_).
data _⇛[_]_ : SK?Term → Bool → SK?Term → Set where
⇛-refl : ∀ {t i} → t ⇛[ i ] t
⇛-Sred : ∀ {s₁ s₂ t₁ t₂ u₁ u₂ i} →
s₁ ⇛[ i ] s₂ → t₁ ⇛[ i ] t₂ → u₁ ⇛[ i ] u₂ →
S · s₁ · t₁ · u₁ ⇛[ i ] s₂ · u₂ · (t₂ · u₂)
⇛-Kred : ∀ {s₁ s₂ t i} → s₁ ⇛[ i ] s₂ → K · s₁ · t ⇛[ i ] s₂
⇛-· : ∀ {s₁ s₂ t₁ t₂ i} →
s₁ ⇛[ i ] s₂ → t₁ ⇛[ i ] t₂ → s₁ · t₁ ⇛[ i ] s₂ · t₂
⇛-⊥ : ∀ {t} → ⊥ ⇛[ true ] t
⇛-⊤ : ∀ {t} → ⊤ ⇛[ false ] t
_⇛[_]*_ : SK?Term → Bool → SK?Term → Set
s ⇛[ i ]* t = (Star _⇛[ i ]_) s t
_⇛≤_ : SK?Term → SK?Term → Set
_⇛≤_ = _⇛[ true ]_
_⇛≤*_ : SK?Term → SK?Term → Set
_⇛≤*_ = _⇛[ true ]*_
_⇛≥_ : SK?Term → SK?Term → Set
_⇛≥_ = _⇛[ false ]_
_⇛≥*_ : SK?Term → SK?Term → Set
_⇛≥*_ = _⇛[ false ]*_
-- A combination of the two multi-step reductions that is equivalent
-- to _≤SK?_ modulo "squashing" of intermediate terms (see ≤SK?--⇛≤*≤⇚
-- below).
_⇛≤*≤⇚_ : SK?Term → SK?Term → Set
s ⇛≤*≤⇚ t = ∃ λ u → s ⇛≤* u × t ⇛≥* u
-- SK terms are SK? terms
inject : SKTerm → SK?Term
inject S = S
inject K = K
inject (s · t) = inject s · inject t
inject-Pure : ∀ t → Pure (inject t)
inject-Pure S = S
inject-Pure K = K
inject-Pure (s · t) = inject-Pure s · inject-Pure t
-- The inverse of inject on pure terms.
inject⁻¹ : ∀ {t} → Pure t → SKTerm
inject⁻¹ S = S
inject⁻¹ K = K
inject⁻¹ (p · q) = inject⁻¹ p · inject⁻¹ q
inject⁻¹-inject-Pure : ∀ t → inject⁻¹ (inject-Pure t) ≡ t
inject⁻¹-inject-Pure S = refl
inject⁻¹-inject-Pure K = refl
inject⁻¹-inject-Pure (s · t) =
cong₂ _·_ (inject⁻¹-inject-Pure s) (inject⁻¹-inject-Pure t)
inject⁻¹-unique : ∀ {t} → (p q : Pure t) → inject⁻¹ p ≡ inject⁻¹ q
inject⁻¹-unique S S = refl
inject⁻¹-unique K K = refl
inject⁻¹-unique (p₁ · p₂) (q₁ · q₂) =
cong₂ _·_ (inject⁻¹-unique p₁ q₁) (inject⁻¹-unique p₂ q₂)
-- Equality of SK terms is a subrelation of the SK? term order and its
-- inverse.
mutual
≡SK-≤SK? : ∀ {s t} → s ≡SK t → inject s ≤SK? inject t
≡SK-≤SK? ≡-refl = ≤?-refl
≡SK-≤SK? (≡-trans s≡t t≡u) = ≤?-trans (≡SK-≤SK? s≡t) (≡SK-≤SK? t≡u)
≡SK-≤SK? (≡-sym s≡t) = ≡SK-≥SK? s≡t
≡SK-≤SK? ≡-Sred = ≤?-Sred
≡SK-≤SK? ≡-Kred = ≤?-Kred
≡SK-≤SK? (≡-· s₁≡t₁ s₂≡t₂) = ≤?-· (≡SK-≤SK? s₁≡t₁) (≡SK-≤SK? s₂≡t₂)
≡SK-≥SK? : ∀ {s t} → s ≡SK t → inject t ≤SK? inject s
≡SK-≥SK? ≡-refl = ≤?-refl
≡SK-≥SK? (≡-trans s≡t t≡u) = ≤?-trans (≡SK-≥SK? t≡u) (≡SK-≥SK? s≡t)
≡SK-≥SK? (≡-sym s≡t) = ≡SK-≤SK? s≡t
≡SK-≥SK? ≡-Sred = ≤?-Sexp
≡SK-≥SK? ≡-Kred = ≤?-Kexp
≡SK-≥SK? (≡-· s₁≡t₁ s₂≡t₂) = ≤?-· (≡SK-≥SK? s₁≡t₁) (≡SK-≥SK? s₂≡t₂)
-- Admissible constructors for multi-step reduction
⇛*-· : ∀ {ab s₁ s₂ t₁ t₂} →
s₁ ⇛[ ab ]* s₂ → t₁ ⇛[ ab ]* t₂ → s₁ · t₁ ⇛[ ab ]* s₂ · t₂
⇛*-· ε ε = ε
⇛*-· ε (t₁⇛t₂ ◅ t₂⇛*t₃) = (⇛-· ⇛-refl t₁⇛t₂) ◅ (⇛*-· ε t₂⇛*t₃)
⇛*-· (s₁⇛s₂ ◅ s₂⇛*s₃) ε = (⇛-· s₁⇛s₂ ⇛-refl) ◅ (⇛*-· s₂⇛*s₃ ε)
⇛*-· (s₁⇛s₂ ◅ s₂⇛*s₃) (t₁⇛t₂ ◅ t₂⇛*t₃) = (⇛-· s₁⇛s₂ t₁⇛t₂) ◅ (⇛*-· s₂⇛*s₃ t₂⇛*t₃)
-- A Church-Rosser theorem for SK? reductions.
⇛-CR : ∀ {s t₁ t₂} → s ⇛≤ t₁ → s ⇛≥ t₂ → ∃ λ u → t₁ ⇛≥ u × t₂ ⇛≤ u
⇛-CR ⇛-refl s⇛t₂ = _ , s⇛t₂ , ⇛-refl
⇛-CR (⇛-Sred s₁⇛t₁₁ s₂⇛t₂₁ s₃⇛t₃₁) (⇛-Sred s₁⇛t₁₂ s₂⇛t₂₂ s₃⇛t₃₂) =
let u₁ , t₁₁⇛u₁ , t₁₂⇛u₁ = ⇛-CR s₁⇛t₁₁ s₁⇛t₁₂
u₂ , t₂₁⇛u₂ , t₂₂⇛u₂ = ⇛-CR s₂⇛t₂₁ s₂⇛t₂₂
u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in u₁ · u₃ · (u₂ · u₃) ,
⇛-· (⇛-· t₁₁⇛u₁ t₃₁⇛u₃) (⇛-· t₂₁⇛u₂ t₃₁⇛u₃) ,
⇛-· (⇛-· t₁₂⇛u₁ t₃₂⇛u₃) (⇛-· t₂₂⇛u₂ t₃₂⇛u₃)
⇛-CR (⇛-Sred s₁⇛t₁₁ s₂⇛t₂₁ s₃⇛t₃₁) (⇛-· ⇛-refl s₃⇛t₃₂) =
let u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in _ · u₃ · (_ · u₃) ,
⇛-· (⇛-· ⇛-refl t₃₁⇛u₃) (⇛-· ⇛-refl t₃₁⇛u₃) ,
⇛-Sred s₁⇛t₁₁ s₂⇛t₂₁ t₃₂⇛u₃
⇛-CR (⇛-Sred s₁⇛t₁₁ s₂⇛t₂₁ s₃⇛t₃₁) (⇛-· (⇛-· ⇛-refl s₂⇛t₂₂) s₃⇛t₃₂) =
let u₂ , t₂₁⇛u₂ , t₂₂⇛u₂ = ⇛-CR s₂⇛t₂₁ s₂⇛t₂₂
u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in _ · u₃ · (u₂ · u₃) ,
⇛-· (⇛-· ⇛-refl t₃₁⇛u₃) (⇛-· t₂₁⇛u₂ t₃₁⇛u₃) ,
⇛-Sred s₁⇛t₁₁ t₂₂⇛u₂ t₃₂⇛u₃
⇛-CR (⇛-Sred s₁⇛t₁₁ s₂⇛t₂₁ s₃⇛t₃₁)
(⇛-· (⇛-· (⇛-· ⇛-refl s₁⇛t₁₂) s₂⇛t₂₂) s₃⇛t₃₂) =
let u₁ , t₁₁⇛u₁ , t₁₂⇛u₁ = ⇛-CR s₁⇛t₁₁ s₁⇛t₁₂
u₂ , t₂₁⇛u₂ , t₂₂⇛u₂ = ⇛-CR s₂⇛t₂₁ s₂⇛t₂₂
u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in u₁ · u₃ · (u₂ · u₃) ,
⇛-· (⇛-· t₁₁⇛u₁ t₃₁⇛u₃) (⇛-· t₂₁⇛u₂ t₃₁⇛u₃) ,
⇛-Sred t₁₂⇛u₁ t₂₂⇛u₂ t₃₂⇛u₃
⇛-CR (⇛-Kred s⇛t₁) (⇛-Kred s⇛t₂) =
let u , t₁⇛u , t₂⇛u = ⇛-CR s⇛t₁ s⇛t₂
in u , t₁⇛u , t₂⇛u
⇛-CR (⇛-Kred s₁⇛t₁₁) (⇛-· ⇛-refl _) = _ , ⇛-refl , ⇛-Kred s₁⇛t₁₁
⇛-CR (⇛-Kred s₁⇛t₁₁) (⇛-· (⇛-· ⇛-refl s₁⇛t₂₁) _) =
let u₁ , t₁₁⇛u₁ , t₂₁⇛u₁ = ⇛-CR s₁⇛t₁₁ s₁⇛t₂₁
in u₁ , t₁₁⇛u₁ , ⇛-Kred t₂₁⇛u₁
⇛-CR (⇛-· ⇛-refl s₃⇛t₃₁) (⇛-Sred s₁⇛t₁₂ s₂⇛t₂₂ s₃⇛t₃₂) =
let u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in _ · u₃ · (_ · u₃) ,
⇛-Sred s₁⇛t₁₂ s₂⇛t₂₂ t₃₁⇛u₃ ,
⇛-· (⇛-· ⇛-refl t₃₂⇛u₃) (⇛-· ⇛-refl t₃₂⇛u₃)
⇛-CR (⇛-· (⇛-· ⇛-refl s₂⇛t₂₁) s₃⇛t₃₁) (⇛-Sred s₁⇛t₁₂ s₂⇛t₂₂ s₃⇛t₃₂) =
let u₂ , t₂₁⇛u₂ , t₂₂⇛u₂ = ⇛-CR s₂⇛t₂₁ s₂⇛t₂₂
u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in _ · u₃ · (u₂ · u₃) ,
⇛-Sred s₁⇛t₁₂ t₂₁⇛u₂ t₃₁⇛u₃ ,
⇛-· (⇛-· ⇛-refl t₃₂⇛u₃) (⇛-· t₂₂⇛u₂ t₃₂⇛u₃)
⇛-CR (⇛-· (⇛-· (⇛-· ⇛-refl s₁⇛t₁₁) s₂⇛t₂₁) s₃⇛t₃₁)
(⇛-Sred s₁⇛t₁₂ s₂⇛t₂₂ s₃⇛t₃₂) =
let u₁ , t₁₁⇛u₁ , t₁₂⇛u₁ = ⇛-CR s₁⇛t₁₁ s₁⇛t₁₂
u₂ , t₂₁⇛u₂ , t₂₂⇛u₂ = ⇛-CR s₂⇛t₂₁ s₂⇛t₂₂
u₃ , t₃₁⇛u₃ , t₃₂⇛u₃ = ⇛-CR s₃⇛t₃₁ s₃⇛t₃₂
in u₁ · u₃ · (u₂ · u₃) ,
⇛-Sred t₁₁⇛u₁ t₂₁⇛u₂ t₃₁⇛u₃ ,
⇛-· (⇛-· t₁₂⇛u₁ t₃₂⇛u₃) (⇛-· t₂₂⇛u₂ t₃₂⇛u₃)
⇛-CR (⇛-· ⇛-refl _) (⇛-Kred s₁⇛t₂₁) =
_ , ⇛-Kred s₁⇛t₂₁ , ⇛-refl
⇛-CR (⇛-· (⇛-· ⇛-refl s₁⇛t₁₁) _) (⇛-Kred s₁⇛t₂₁) =
let u₁ , t₁₁⇛u₁ , t₂₁⇛u₁ = ⇛-CR s₁⇛t₁₁ s₁⇛t₂₁
in u₁ , ⇛-Kred t₁₁⇛u₁ , t₂₁⇛u₁
{-# CATCHALL #-}
⇛-CR (⇛-· s₁⇛t₁₁ s₂⇛t₂₁) (⇛-· s₁⇛t₁₂ s₂⇛t₂₂) =
let u₁ , t₁₁⇛u₁ , t₁₂⇛u₁ = ⇛-CR s₁⇛t₁₁ s₁⇛t₁₂
u₂ , t₂₁⇛u₂ , t₂₂⇛u₂ = ⇛-CR s₂⇛t₂₁ s₂⇛t₂₂
in u₁ · u₂ , ⇛-· t₁₁⇛u₁ t₂₁⇛u₂ , ⇛-· t₁₂⇛u₁ t₂₂⇛u₂
{-# CATCHALL #-}
⇛-CR s⇛t₁ ⇛-refl = _ , ⇛-refl , s⇛t₁
⇛-⇛*-CR : ∀ {s t₁ t₂} → s ⇛≤ t₁ → s ⇛≥* t₂ → ∃ λ u → t₁ ⇛≥* u × t₂ ⇛≤ u
⇛-⇛*-CR s⇛≤t ε = _ , ε , s⇛≤t
⇛-⇛*-CR s⇛≤u₁ (s⇛≥t₁ ◅ t₁⇛≥*t₂) =
let u₂ , u₁⇛≥u₂ , t₁⇛≤u₂ = ⇛-CR s⇛≤u₁ s⇛≥t₁
u₃ , u₂⇛≥*u₃ , t₂⇛≤u₃ = ⇛-⇛*-CR t₁⇛≤u₂ t₁⇛≥*t₂
in u₃ , u₁⇛≥u₂ ◅ u₂⇛≥*u₃ , t₂⇛≤u₃
⇛*-CR : ∀ {s t₁ t₂} → s ⇛≤* t₁ → s ⇛≥* t₂ → ∃ λ u → t₁ ⇛≥* u × t₂ ⇛≤* u
⇛*-CR ε s⇛≥*t = _ , s⇛≥*t , ε
⇛*-CR (s⇛≤t₁ ◅ t₁⇛≤*t₂) s⇛≥*u₁ =
let u₂ , t₁⇛≥*u₂ , u₁⇛≤u₂ = ⇛-⇛*-CR s⇛≤t₁ s⇛≥*u₁
u₃ , t₂⇛≥*u₃ , u₂⇛≤*u₃ = ⇛*-CR t₁⇛≤*t₂ t₁⇛≥*u₂
in u₃ , t₂⇛≥*u₃ , u₁⇛≤u₂ ◅ u₂⇛≤*u₃
-- Thanks to Church-Rosser, thee combined multi-step reduction is
-- transitive.
⇛≤*≤⇚-trans : ∀ {s t u} → s ⇛≤*≤⇚ t → t ⇛≤*≤⇚ u → s ⇛≤*≤⇚ u
⇛≤*≤⇚-trans (v , s⇛≤*v , t⇛≥*v) (w , t⇛≤*w , u⇛≥*w) =
let u′ , w⇛≥*u′ , v⇛≤*u′ = ⇛*-CR t⇛≤*w t⇛≥*v
in u′ , (s⇛≤*v ◅◅ v⇛≤*u′ , u⇛≥*w ◅◅ w⇛≥*u′)
-- The order on SK? terms is a subrelation of the combined multi-step
-- reduction (modulo squashing).
--
-- The two orders are in fact equivalent, but we don't need that
-- result here, so we omit its proof. Instead we will establish that
-- the two relations are both equivalent to _≡SK_ on pure SK terms
-- (see inject-⇛≤*≤⇚-≡SK below).
≤SK?--⇛≤*≤⇚ : ∀ {s t} → s ≤SK? t → s ⇛≤*≤⇚ t
≤SK?--⇛≤*≤⇚ ≤?-refl = (_ , ε , ε)
≤SK?--⇛≤*≤⇚ (≤?-trans s≤t t≤u) =
⇛≤*≤⇚-trans (≤SK?--⇛≤*≤⇚ s≤t) (≤SK?--⇛≤*≤⇚ t≤u)
≤SK?--⇛≤*≤⇚ ≤?-⊥ = (_ , ⇛-⊥ ◅ ε , ε)
≤SK?--⇛≤*≤⇚ ≤?-⊤ = (_ , ε , ⇛-⊤ ◅ ε)
≤SK?--⇛≤*≤⇚ ≤?-Sred = _ , ⇛-Sred ⇛-refl ⇛-refl ⇛-refl ◅ ε , ε
≤SK?--⇛≤*≤⇚ ≤?-Kred = _ , ⇛-Kred ⇛-refl ◅ ε , ε
≤SK?--⇛≤*≤⇚ ≤?-Sexp = _ , ε , ⇛-Sred ⇛-refl ⇛-refl ⇛-refl ◅ ε
≤SK?--⇛≤*≤⇚ ≤?-Kexp = _ , ε , ⇛-Kred ⇛-refl ◅ ε
≤SK?--⇛≤*≤⇚ (≤?-· s₁≤t₁ s₂≤t₂) =
let u₁ , s₁⇛u₁ , t₁⇛u₁ = ≤SK?--⇛≤*≤⇚ s₁≤t₁
u₂ , s₂⇛u₂ , t₂⇛u₂ = ≤SK?--⇛≤*≤⇚ s₂≤t₂
in u₁ · u₂ , ⇛*-· s₁⇛u₁ s₂⇛u₂ , ⇛*-· t₁⇛u₁ t₂⇛u₂
-- Reduction preserves pure terms.
⇛-Pure : ∀ {ab s t} (ps : Pure s) → s ⇛[ ab ] t →
∃ λ pt → inject⁻¹ ps ≡SK inject⁻¹ {t} pt
⇛-Pure p ⇛-refl = p , ≡-refl
⇛-Pure (S · ps₁ · pt₁ · pu₁) (⇛-Sred s₁⇛s₂ t₁⇛t₂ u₁⇛u₂) =
let ps₂ , s₁≡s₂ = ⇛-Pure ps₁ s₁⇛s₂
pt₂ , t₁≡t₂ = ⇛-Pure pt₁ t₁⇛t₂
pu₂ , u₁≡u₂ = ⇛-Pure pu₁ u₁⇛u₂
in ps₂ · pu₂ · (pt₂ · pu₂) ,
≡-trans (≡-· (≡-· (≡-· ≡-refl s₁≡s₂) t₁≡t₂) u₁≡u₂) ≡-Sred
⇛-Pure (K · ps₁ · _) (⇛-Kred s₁⇛s₂) =
let ps₂ , s₁≡s₂ = ⇛-Pure ps₁ s₁⇛s₂
in ps₂ , ≡-trans ≡-Kred s₁≡s₂
⇛-Pure (ps · pt) (⇛-· s₁⇛s₂ t₁⇛t₂) =
Prod.zip _·_ ≡-· (⇛-Pure ps s₁⇛s₂) (⇛-Pure pt t₁⇛t₂)
⇛*-Pure : ∀ {ab s t} (ps : Pure s) → s ⇛[ ab ]* t →
∃ λ pt → inject⁻¹ ps ≡SK inject⁻¹ {t} pt
⇛*-Pure p ε = p , ≡-refl
⇛*-Pure ps (s⇛t ◅ t⇛*u) =
let pt , s≡t = ⇛-Pure ps s⇛t
pu , t≡u = ⇛*-Pure pt t⇛*u
in pu , ≡-trans s≡t t≡u
-- The combined multi-step reduction is a subrelation of ≡SK on pure terms.
inject-⇛≤*≤⇚-≡SK : ∀ {s t} → inject s ⇛≤*≤⇚ inject t → s ≡SK t
inject-⇛≤*≤⇚-≡SK {s} {t} (u , s⇛≤*u , t⇛≥*u) =
let pu , s≡u = ⇛*-Pure (inject-Pure s) s⇛≤*u
pu′ , t≡u = ⇛*-Pure (inject-Pure t) t⇛≥*u
in ≡-trans (subst (_≡SK (inject⁻¹ pu)) (inject⁻¹-inject-Pure s) s≡u)
(subst₂ (_≡SK_) (inject⁻¹-unique pu′ pu) (inject⁻¹-inject-Pure t)
(≡-sym t≡u))
-- The order on SK? terms is a subrelation of the equality on pure SK
-- terms.
--
-- NOTE. This establishes a circular equivalence between the three
-- relations _≡SK_, _⇛≤*≤⇚_ and _≤SK?_ when restricted to pure SK
-- terms:
--
-- _≡SK_ ⊆ _≤SK?_ ⊆ _⇛≤*≤⇚_ ⊆ _≡SK_
--
-- This equivalence will allow us to encode/extract equivalence proofs
-- on (pure) SK terms from typing derivations.
inject-≤SK?-≡SK : ∀ {s t} → inject s ≤SK? inject t → s ≡SK t
inject-≤SK?-≡SK {s} {t} s≤t = inject-⇛≤*≤⇚-≡SK (≤SK?--⇛≤*≤⇚ s≤t)
| {
"alphanum_fraction": 0.4705882353,
"avg_line_length": 35.8571428571,
"ext": "agda",
"hexsha": "dcb120169094163c31b226995e21346bf823fae2",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z",
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Undecidable/SK.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Undecidable/SK.agda",
"max_line_length": 81,
"max_stars_count": 12,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Undecidable/SK.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z",
"num_tokens": 8186,
"size": 12801
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Hash
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Abstract.Types
open EpochConfig
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle sha256 sha256-cr
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Yasm.Base
open import LibraBFT.Yasm.AvailableEpochs using (AvailableEpochs ; lookup'; lookup'')
open import LibraBFT.Yasm.System ConcSysParms
open import LibraBFT.Yasm.Properties ConcSysParms
-- In this module, we define two "implementation obligations"
-- (ImplObligationᵢ for i ∈ {1 , 2}), which are predicates over
-- reachable states of a system defined by
-- 'LibraBFT.Concrete.System.Parameters'. These two properties relate
-- votes sent by the same sender, ensuring that if they are for the
-- same epoch and round, then they vote for the same blockID; the
-- first relates a vote output by the handler to a vote sent
-- previously, and the second relates two votes both sent by the
-- handler.
--
-- We then prove that, if an implementation satisfies these two
-- semantic obligations, along with a structural one about messages
-- sent by honest peers in the implementation, then the implemenation
-- satisfies the LibraBFT.Abstract.Properties.VotesOnce invariant.
module LibraBFT.Concrete.Properties.VotesOnce where
-- TODO-3: This may not be the best way to state the implementation obligation. Why not reduce
-- this as much as possible before giving the obligation to the implementation? For example, this
-- will still require the implementation to deal with hash collisons (v and v' could be different,
-- but yield the same bytestring and therefore same signature). Also, avoid the need for the
-- implementation to reason about messages sent by step-cheat, or give it something to make this
-- case easy to eliminate.
ImplObligation₁ : Set₁
ImplObligation₁ =
∀{e pid sndr s' outs pk}{pre : SystemState e}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ StepPeerState pid (availEpochs pre) (msgPool pre) (Map-lookup pid (peerStates pre)) s' outs
→ ∀{v m v' m'} → Meta-Honest-PK pk
-- For signed every vote v of every outputted message
→ v ⊂Msg m → m ∈ outs → (sig : WithVerSig pk v)
-- If v is really new and valid
-- Note that this does not directly exclude possibility of previous message with
-- same signature, but sent by someone else. We could prove it implies it though.
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → ValidPartForPK (availEpochs pre) v pk
-- And if there exists another v' that has been sent before
→ v' ⊂Msg m' → (sndr , m') ∈ (msgPool pre) → WithVerSig pk v'
-- If v and v' share the same epoch and round
→ (v ^∙ vEpoch) ≡ (v' ^∙ vEpoch)
→ (v ^∙ vProposed ∙ biRound) ≡ (v' ^∙ vProposed ∙ biRound)
----------------------------------------------------------
-- Then an honest implemenation promises v and v' vote for the same blockId.
→ (v ^∙ vProposed ∙ biId) ≡ (v' ^∙ vProposed ∙ biId)
ImplObligation₂ : Set₁
ImplObligation₂ =
∀{e pid s' outs pk}{pre : SystemState e}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ StepPeerState pid (availEpochs pre) (msgPool pre) (Map-lookup pid (peerStates pre)) s' outs
→ ∀{v m v' m'} → Meta-Honest-PK pk
-- For every vote v represented in a message output by the call
→ v ⊂Msg m → m ∈ outs → (sig : WithVerSig pk v)
-- If v is really new and valid
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → ValidPartForPK (availEpochs pre) v pk
-- And if there exists another v' that is also new and valid
→ v' ⊂Msg m' → m' ∈ outs → (sig' : WithVerSig pk v')
→ ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre)) → ValidPartForPK (availEpochs pre) v' pk
-- If v and v' share the same epoch and round
→ (v ^∙ vEpoch) ≡ (v' ^∙ vEpoch)
→ (v ^∙ vProposed ∙ biRound) ≡ (v' ^∙ vProposed ∙ biRound)
----------------------------------------------------------
-- Then, an honest implemenation promises v and v' vote for the same blockId.
→ (v ^∙ vProposed ∙ biId) ≡ (v' ^∙ vProposed ∙ biId)
-- Next, we prove that, given the necessary obligations,
module Proof
(sps-corr : StepPeerState-AllValidParts)
(Impl-VO1 : ImplObligation₁)
(Impl-VO2 : ImplObligation₂)
where
-- Any reachable state satisfies the VO rule for any epoch in the system.
module _ {e}(st : SystemState e)(r : ReachableSystemState st)(eid : Fin e) where
-- Bring in 'unwind', 'ext-unforgeability' and friends
open Structural sps-corr
-- Bring in ConcSystemState
open import LibraBFT.Concrete.System sps-corr
open PerState st r
open PerEpoch eid
open import LibraBFT.Abstract.Obligations.VotesOnce 𝓔 Hash _≟Hash_ (ConcreteVoteEvidence 𝓔) as VO
-- The VO proof is done by induction on the execution trace leading to 'st'. In
-- Agda, this is 'r : RechableSystemState st' above. We will use induction to
-- construct a predicate Pred'' below, which holds for every state on the trace.
private
-- First we specify the predicate we need: it relates two votes verified
-- by the same public key, such that both are elements of the same message pool
Pred'' : PK → Vote → Vote → SentMessages → Set
Pred'' pk v v' pool
= Meta-Honest-PK pk
→ (ver : WithVerSig pk v) → MsgWithSig∈ pk (ver-signature ver) pool
→ (ver' : WithVerSig pk v') → MsgWithSig∈ pk (ver-signature ver') pool
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
-- Usually, we want to universally quantify Pred'' over arbitrary votes and pks
Pred' : SentMessages → Set
Pred' pool = ∀{pk}{v v' : Vote} → Pred'' pk v v' pool
-- Finally, we state Pred' in terms of SystemSate
Pred : ∀{e} → SystemState e → Set
Pred = Pred' ∘ msgPool
-------------------
-- * Base Case * --
-------------------
-- Pred above is trivially true for the initial state: there are no messages in the pool
Pred₀ : Pred initialState
Pred₀ _ _ ()
--------------------------------------------------
-- * Inductive Case: New Epochs in the System * --
--------------------------------------------------
-- Because pushEpoch does not alter the msgPool, the proof is trivial.
Pred𝓔 : ∀{e}{st : SystemState e}(𝓔 : EpochConfigFor e) → Pred st → Pred (pushEpoch 𝓔 st)
Pred𝓔 𝓔 p = p
----------------------------------------------
-- * Inductive Case: Transition by a Peer * --
----------------------------------------------
-- From this point onwards, it might be easier to read this proof starting at 'voo'
-- at the end of the file. Next, we provide an overview the proof.
--
-- We wish to prove that, for any two votes v and v' cast by an honest α in the message pool of
-- a state st, if v and v' have equal rounds and epochs, then they vote for the same block. As
-- we have seen above, the base case and the case for a new epoch in the system are
-- trivial. Next, we look at the PeerStep case.
--
-- The induction hypothesis tells us that the property holds in the pre-state. Next, we reason
-- about the post-state. We start by analyzing whether v and v' have been sent as outputs of
-- the PeerStep under scrutiny or were already in the pool before (captured by the PredStep
-- function). There are four possibilities:
--
-- i) v and v' were aleady present in the msgPool before: use induction hypothesis.
-- ii) v and v' are both in the output produced by the PeerStep under scrutiny.
-- iii) v was present before, but v' is new.
-- iv) v' was present before, but v is new.
--
-- Case (i) is trivial; cases (iii) and (iv) are symmetric and reduce to an implementation
-- obligation (Impl-VO1) and case (ii) reduces to a different implementation obligation (Impl-VO2).
--
-- The proofs of cases (iii) and (iv) are in PredStep-wlog-ht and PredStep-wlog-ht'. The 'ht'
-- suffix refers to 'Here-There' as in one vote is "here" and the other is old, or "there". We
-- first analyze whether the new vote is really new or a replay; sps-cor provides us this
-- information. If the new vote is, in fact, a replay of an old message, we have two old
-- messages and can call the induction hypothesis. If it is really new, we must rely on the
-- implementation obligation. But to do so, we must prove that the old vote was also sent by
-- the same peer. We can see that is the case by reasoning about PK-inj and IsValidEpochMember.
--
-- Finally, the proof of case (ii) also branches on whether either of the "new" votes
-- are replays or are really new. In case at least one is a replay we fallback to cases (iii) and (iv)
-- or just call the induction hypothesis when both are replays.
-- When both votes are in fact new, we rely on Impl-VO2 to conclude.
--
-- In both PredSetp-wlog-ht and PredStep-wlog-hh, we must eliminate the possibility of
-- either vote being produced by a cheat step. This is easy because we received
-- a proof that the PK in question is honest, hence, it must be the case that a cheat
-- step is at most replaying these votes, not producing them. Producing them would
-- require the cheater to forge a signature. This is the purpose of the isCheat constraint.
PredStep-wlog-ht' : ∀{e pid pid' s' outs pk}{pre : SystemState e}
→ ReachableSystemState pre
→ Pred pre
→ StepPeerState pid (availEpochs pre) (msgPool pre) (Map-lookup pid (peerStates pre)) s' outs
→ ∀{v m v' m'}
→ v ⊂Msg m → m ∈ outs
→ v' ⊂Msg m' → (pid' , m') ∈ msgPool pre
→ WithVerSig pk v → WithVerSig pk v' → Meta-Honest-PK pk
→ (v ^∙ vEpoch) ≡ (v' ^∙ vEpoch)
→ (v ^∙ vProposed ∙ biRound) ≡ (v' ^∙ vProposed ∙ biRound)
→ (v ^∙ vProposed ∙ biId) ≡ (v' ^∙ vProposed ∙ biId)
PredStep-wlog-ht' {pre = pre} preach hip ps {v} v⊂m m∈outs v'⊂m' m'∈pool ver ver' hpk eids≡ r≡
-- (1) The first step is branching on whether 'v' above is a /new/ vote or not.
-- (1.1) If it's new:
with sps-corr preach hpk ps m∈outs v⊂m ver
...| inj₁ (vValid , vNew)
with honestPartValid preach hpk v'⊂m' m'∈pool ver'
...| v'Old , vOldValid
with sameHonestSig⇒sameVoteData hpk ver' (msgSigned v'Old) (sym (msgSameSig v'Old))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl = Impl-VO1 preach ps hpk v⊂m m∈outs ver vNew vValid
(msg⊆ v'Old) (msg∈pool v'Old)
(msgSigned v'Old) eids≡ r≡
-- (1.1) If 'v' is not new, then there exists a msg sent with the
-- same signature.
PredStep-wlog-ht' preach hip ps {v} v⊂m m∈outs v'⊂m' m'∈pool ver ver' hpk e≡ r≡
| inj₂ vOld
with honestPartValid preach hpk v'⊂m' m'∈pool ver'
...| sv' , _ = hip hpk ver vOld ver' sv' e≡ r≡
-- Here we prove a modified version of Pred'' where we assume w.l.o.g that
-- one vote is sent by "pstep" and another was present in the prestate.
PredStep-wlog-ht
: ∀{e pid st' outs}{pre : SystemState e}
→ ReachableSystemState pre
→ (pstep : StepPeer pre pid st' outs)
→ Pred pre
→ ∀{pk v v'}
-- Below is a inline expansion of "Pred'' pk v v' (msgPool (StepPeer-post pstep))",
-- but with the added information that one vote (v) was sent by pstep whereas the
-- other (v') was in the pool of the prestate.
→ let pool = msgPool (StepPeer-post pstep)
in Meta-Honest-PK pk
→ (ver : WithVerSig pk v )(sv : MsgWithSig∈ pk (ver-signature ver ) pool)
→ (msgSender sv , msgWhole sv) ∈ List-map (pid ,_) outs
→ (ver' : WithVerSig pk v')(sv' : MsgWithSig∈ pk (ver-signature ver') pool)
→ (msgSender sv' , msgWhole sv') ∈ msgPool pre
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
PredStep-wlog-ht preach (step-cheat fm isCheat) hip hpk ver sv (here refl) ver' sv' furtherBack' epoch≡ r≡
with isCheat (msg⊆ sv) (msgSigned sv)
...| inj₁ abs = ⊥-elim (hpk abs) -- The key was honest by hypothesis.
...| inj₂ sentb4
-- the cheater replayed the message; which means the message was sent before this
-- step; hence, call induction hypothesis.
with msgSameSig sv
...| refl = hip hpk ver sentb4 ver' (MsgWithSig∈-transp sv' furtherBack') epoch≡ r≡
PredStep-wlog-ht preach (step-honest x) hip hpk ver sv thisStep ver' sv' furtherBack' epoch≡ r≡
with sameHonestSig⇒sameVoteData hpk ver (msgSigned sv) (sym (msgSameSig sv))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl
with sameHonestSig⇒sameVoteData hpk ver' (msgSigned sv') (sym (msgSameSig sv'))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl
= PredStep-wlog-ht' preach hip x
(msg⊆ sv) (Any-map (cong proj₂) (Any-map⁻ thisStep))
(msg⊆ sv') furtherBack'
(msgSigned sv) (msgSigned sv') hpk epoch≡ r≡
-- Analogous to PredStep-wlog-ht', but here we must reason about two messages that are in the
-- outputs of a step.
PredStep-hh' : ∀{e pid s' outs pk}{pre : SystemState e}
→ ReachableSystemState pre → Pred pre
→ StepPeerState pid (availEpochs pre) (msgPool pre) (Map-lookup pid (peerStates pre)) s' outs
→ ∀{v m v' m'}
→ v ⊂Msg m → m ∈ outs
→ v' ⊂Msg m' → m' ∈ outs
→ WithVerSig pk v → WithVerSig pk v' → Meta-Honest-PK pk
→ (v ^∙ vEpoch) ≡ (v' ^∙ vEpoch)
→ (v ^∙ vProposed ∙ biRound) ≡ (v' ^∙ vProposed ∙ biRound)
→ (v ^∙ vProposed ∙ biId) ≡ (v' ^∙ vProposed ∙ biId)
-- Since the step is from an honest peer, we can check whether the messages are in fact
-- new or not.
PredStep-hh' preach hip ps {v} v⊂m m∈outs v'⊂m' m'∈outs ver ver' hpk e≡ r≡
with sps-corr preach hpk ps m∈outs v⊂m ver | sps-corr preach hpk ps m'∈outs v'⊂m' ver'
-- (A) Both are old: call induction hypothesis
...| inj₂ vOld | inj₂ v'Old = hip hpk ver vOld ver' v'Old e≡ r≡
-- (B) One is new, one is old: use PredStep-wlog-ht'
PredStep-hh' preach hip ps {v} v⊂m m∈outs v'⊂m' m'∈outs ver ver' hpk e≡ r≡
| inj₁ (vValid , vNew) | inj₂ v'Old
with sameHonestSig⇒sameVoteData hpk ver' (msgSigned v'Old) (sym (msgSameSig v'Old))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl
= PredStep-wlog-ht' preach hip ps v⊂m m∈outs (msg⊆ v'Old) (msg∈pool v'Old) ver (msgSigned v'Old) hpk e≡ r≡
-- (C) One is old, one is new: use PredStep-wlog-ht'
PredStep-hh' preach hip ps {v} v⊂m m∈outs v'⊂m' m'∈outs ver ver' hpk e≡ r≡
| inj₂ vOld | inj₁ (v'Valid , v'New)
with sameHonestSig⇒sameVoteData hpk ver (msgSigned vOld) (sym (msgSameSig vOld))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl
= sym (PredStep-wlog-ht' preach hip ps v'⊂m' m'∈outs (msg⊆ vOld) (msg∈pool vOld) ver' (msgSigned vOld) hpk (sym e≡) (sym r≡))
-- (D) Finally, both votes are new in this step. The proof is then trivially
-- forwarded to the implementation obligation.
PredStep-hh' preach hip ps {v} v⊂m m∈outs v'⊂m' m'∈outs ver ver' hpk e≡ r≡
| inj₁ (vValid , vNew) | inj₁ (v'Valid , v'New)
= Impl-VO2 preach ps hpk v⊂m m∈outs ver vNew vValid v'⊂m' m'∈outs ver' v'New v'Valid e≡ r≡
PredStep-hh
: ∀{e pid st' outs}{pre : SystemState e}
→ ReachableSystemState pre
→ (pstep : StepPeer pre pid st' outs)
→ Pred pre
→ ∀{pk v v'}
→ let pool = msgPool (StepPeer-post pstep)
in Meta-Honest-PK pk
→ (ver : WithVerSig pk v )(sv : MsgWithSig∈ pk (ver-signature ver ) pool)
→ (msgSender sv , msgWhole sv) ∈ List-map (pid ,_) outs
→ (ver' : WithVerSig pk v')(sv' : MsgWithSig∈ pk (ver-signature ver') pool)
→ (msgSender sv' , msgWhole sv') ∈ List-map (pid ,_) outs
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
PredStep-hh preach (step-cheat fm isCheat) hip hpk ver sv (here refl) ver' sv' (here refl) epoch≡ r≡
with isCheat (msg⊆ sv) (msgSigned sv)
...| inj₁ abs = ⊥-elim (hpk abs) -- The key was honest by hypothesis.
...| inj₂ sentb4
with isCheat (msg⊆ sv') (msgSigned sv')
...| inj₁ abs = ⊥-elim (hpk abs) -- The key was honest by hypothesis.
...| inj₂ sentb4'
with msgSameSig sv | msgSameSig sv'
...| refl | refl = hip hpk ver sentb4 ver' sentb4' epoch≡ r≡
PredStep-hh preach (step-honest x) hip hpk ver sv thisStep ver' sv' thisStep' epoch≡ r≡
with sameHonestSig⇒sameVoteData hpk ver (msgSigned sv) (sym (msgSameSig sv))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl
with sameHonestSig⇒sameVoteData hpk ver' (msgSigned sv') (sym (msgSameSig sv'))
...| inj₁ abs = ⊥-elim (meta-sha256-cr abs)
...| inj₂ refl
= PredStep-hh' preach hip x
(msg⊆ sv ) (Any-map (cong proj₂) (Any-map⁻ thisStep))
(msg⊆ sv') (Any-map (cong proj₂) (Any-map⁻ thisStep'))
(msgSigned sv) (msgSigned sv') hpk epoch≡ r≡
PredStep : ∀{e pid st' outs}{pre : SystemState e}
→ ReachableSystemState pre
→ (pstep : StepPeer pre pid st' outs)
→ Pred pre
→ Pred (StepPeer-post pstep)
PredStep {e} {pid} {st'} {outs} {pre} preach pstep hip hpk ver sv ver' sv' epoch≡ r≡
-- First we check when have the votes been sent:
with Any-++⁻ (List-map (pid ,_) outs) {msgPool pre} (msg∈pool sv)
| Any-++⁻ (List-map (pid ,_) outs) {msgPool pre} (msg∈pool sv')
-- (A) Neither vote has been sent by the step under scrutiny: invoke inductive hypothesis
...| inj₂ furtherBack | inj₂ furtherBack'
= hip hpk ver (MsgWithSig∈-transp sv furtherBack)
ver' (MsgWithSig∈-transp sv' furtherBack') epoch≡ r≡
-- (B) One vote was cast here; the other was cast in the past.
PredStep {e} {pid} {st'} {outs} {pre} preach pstep hip hpk ver sv ver' sv' epoch≡ r≡
| inj₁ thisStep | inj₂ furtherBack'
= PredStep-wlog-ht preach pstep hip hpk ver sv thisStep ver' sv' furtherBack' epoch≡ r≡
-- (C) Symmetric to (B)
PredStep {e} {pid} {st'} {outs} {pre} preach pstep hip hpk ver sv ver' sv' epoch≡ r≡
| inj₂ furtherBack | inj₁ thisStep'
= sym (PredStep-wlog-ht preach pstep hip hpk ver' sv' thisStep' ver sv furtherBack (sym epoch≡) (sym r≡))
-- (D) Both votes were cast here
PredStep {e} {pid} {st'} {outs} {pre} preach pstep hip hpk ver sv ver' sv' epoch≡ r≡
| inj₁ thisStep | inj₁ thisStep'
= PredStep-hh preach pstep hip hpk ver sv thisStep ver' sv' thisStep' epoch≡ r≡
voo : VO.Type ConcSystemState
voo hpk refl sv refl sv' round≡
with Step*-Step-fold Pred (λ {e} {st} _ → Pred𝓔 {e} {st}) PredStep Pred₀ r
...| res
with vmsg≈v (vmFor sv) | vmsg≈v (vmFor sv')
...| refl | refl
= res hpk (vmsgSigned (vmFor sv))
(mkMsgWithSig∈ (nm (vmFor sv)) (cv (vmFor sv)) (cv∈nm (vmFor sv))
_ (nmSentByAuth sv) (vmsgSigned (vmFor sv)) refl)
(vmsgSigned (vmFor sv'))
(mkMsgWithSig∈ (nm (vmFor sv')) (cv (vmFor sv')) (cv∈nm (vmFor sv'))
_ (nmSentByAuth sv') (vmsgSigned (vmFor sv')) refl)
(trans (vmsgEpoch (vmFor sv)) (sym (vmsgEpoch (vmFor sv'))))
round≡
| {
"alphanum_fraction": 0.6210817759,
"avg_line_length": 52.2635658915,
"ext": "agda",
"hexsha": "609830bdd8066304fdda11b4d75a251a85997d19",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_forks_repo_path": "LibraBFT/Concrete/Properties/VotesOnce.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_issues_repo_path": "LibraBFT/Concrete/Properties/VotesOnce.agda",
"max_line_length": 132,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_stars_repo_path": "LibraBFT/Concrete/Properties/VotesOnce.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6458,
"size": 20226
} |
{-# OPTIONS --cubical-compatible #-}
data D : Set → Set₁ where
c : (@0 A : Set) → D A
| {
"alphanum_fraction": 0.5505617978,
"avg_line_length": 17.8,
"ext": "agda",
"hexsha": "9a96f2a7ca2e97998c413452d1d5a732b1833507",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/Issue5434-1.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/Issue5434-1.agda",
"max_line_length": 36,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue5434-1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 30,
"size": 89
} |
module ANF where
open import Data.List
open import Data.List.All
open import Typing
open import DSyntax
open import Syntax
-- transform a direct style expression into and anf expression
anf : ∀ {φ t} → DExpr φ t → Expr φ t
anf (var x) = var x
anf (nat unr-φ i) = nat unr-φ i
anf (unit unr-φ) = unit unr-φ
anf (pair sp de de₁) = letbind sp (anf de) (letbind (rght (split-all-left _)) (anf de₁) (pair (rght (left [])) (here []) (here [])))
anf (letpair sp de de₁) = letbind sp (anf de) (letpair (left (split-all-right _)) (here []) (anf de₁))
anf (fork de) = fork (anf de)
anf (new unr-φ s) = new unr-φ s
anf (send sp de de₁) = letbind sp (anf de) (letbind (rght (split-all-left _)) (anf de₁) (send (rght (left [])) (here []) (here [])))
anf (recv de) = letbind (split-all-left _) (anf de) (recv (here []))
anf (close de) = letbind (split-all-left _) (anf de) (close (here []))
anf (wait de) = letbind (split-all-left _) (anf de) (wait (here []))
anf (select lab de) = letbind (split-all-left _) (anf de) (select lab (here []))
anf (branch sp de de₁ de₂) = letbind sp (anf de) (branch (left (split-all-right _)) (here []) (anf de₁) (anf de₂))
anf (ulambda unr-φ de) = ulambda (split-all-left _) unr-φ [] (anf de)
anf (llambda de) = llambda (split-all-left _) [] (anf de)
anf (app sp de de₁) = letbind sp (anf de) (letbind (rght (split-all-left _)) (anf de₁) (app (rght (left [])) (here []) (here [])))
anf (subsume de t≤t') = subsume (anf de) t≤t'
| {
"alphanum_fraction": 0.6331034483,
"avg_line_length": 48.3333333333,
"ext": "agda",
"hexsha": "98a1088760dfe98bdd1b43f7143554f9538a9095",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "peterthiemann/definitional-session",
"max_forks_repo_path": "src/ANF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "peterthiemann/definitional-session",
"max_issues_repo_path": "src/ANF.agda",
"max_line_length": 132,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "peterthiemann/definitional-session",
"max_stars_repo_path": "src/ANF.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z",
"num_tokens": 545,
"size": 1450
} |
{-# OPTIONS --without-K #-}
open import homotopy.3x3.Common
open import homotopy.3x3.PushoutPushout
module homotopy.3x3.Transpose where
open M using (Pushout^2)
type-of : ∀ {i} {A : Type i} (u : A) → Type i
type-of {A = A} _ = A
module _ {i} (d : Span^2 {i}) where
open Span^2 d
transpose-f : (f : type-of H₁₁ → _) (g : type-of H₃₃ → _) → Span^2
transpose-f f g = span^2 A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄
f₁₀ f₃₀ f₁₂ f₃₂ f₁₄ f₃₄ f₀₁ f₀₃ f₂₁ f₂₃ f₄₁ f₄₃
(f H₁₁) H₃₁ H₁₃ (g H₃₃)
transpose : Span^2
transpose = span^2 A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄
f₁₀ f₃₀ f₁₂ f₃₂ f₁₄ f₃₄ f₀₁ f₀₃ f₂₁ f₂₃ f₄₁ f₄₃
(! ∘ H₁₁) H₃₁ H₁₃ (! ∘ H₃₃)
ch1 : ∀ {i j} {A : Type i} {x y : A} {p : x == y} {f g : A → Type j} {a : f x → g x} {b : f y → g y}
→ (a == b [ (λ u → f u → g u) ↓ p ]) → (a == b [ (λ u → fst u → snd u) ↓ pair×= (ap f p) (ap g p)])
ch1 {p = idp} α = α
ch2 : ∀ {i j} {X : Type i} {x y : X} {p : x == y}
{A B₁ B₂ C : X → Type j}
{f₁ : (x : X) → A x → B₁ x} {g₁ : (x : X) → B₁ x → C x}
{f₂ : (x : X) → A x → B₂ x} {g₂ : (x : X) → B₂ x → C x}
{a : _} {b : _}
→ (a == b [ (λ z → (x : A z) → g₁ z (f₁ z x) == g₂ z (f₂ z x)) ↓ p ])
→ (a == b [ (λ u → (x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x))
↓ square=-raw (ap A p) (ap B₁ p) (ap B₂ p) (ap C p) (ch1 (apd f₁ p)) (ch1 (apd f₂ p)) (ch1 (apd g₁ p)) (ch1 (apd g₂ p)) ])
ch2 {p = idp} α = α
ap-span^2=-priv : ∀ {i} {d d' : Span^2 {i}} (p : d == d')
→ ap transpose p == span^2=-raw (ap Span^2.A₀₀ p) (ap Span^2.A₂₀ p) (ap Span^2.A₄₀ p)
(ap Span^2.A₀₂ p) (ap Span^2.A₂₂ p) (ap Span^2.A₄₂ p)
(ap Span^2.A₀₄ p) (ap Span^2.A₂₄ p) (ap Span^2.A₄₄ p)
(ch1 (apd Span^2.f₁₀ p)) (ch1 (apd Span^2.f₃₀ p))
(ch1 (apd Span^2.f₁₂ p)) (ch1 (apd Span^2.f₃₂ p))
(ch1 (apd Span^2.f₁₄ p)) (ch1 (apd Span^2.f₃₄ p))
(ch1 (apd Span^2.f₀₁ p)) (ch1 (apd Span^2.f₀₃ p))
(ch1 (apd Span^2.f₂₁ p)) (ch1 (apd Span^2.f₂₃ p))
(ch1 (apd Span^2.f₄₁ p)) (ch1 (apd Span^2.f₄₃ p))
(ch2 (ap↓ (λ u → ! ∘ u) (apd Span^2.H₁₁ p))) (ch2 (apd Span^2.H₃₁ p))
(ch2 (apd Span^2.H₁₃ p)) (ch2 (ap↓ (λ u → ! ∘ u) (apd Span^2.H₃₃ p)))
ap-span^2=-priv {i} {d} {.d} idp = idp
ap-span^2=-priv2 : ∀ {i}
{A₀₀ A₀₀' : Type i} (eq-A₀₀ : A₀₀ == A₀₀')
{A₀₂ A₀₂' : Type i} (eq-A₀₂ : A₀₂ == A₀₂')
{A₀₄ A₀₄' : Type i} (eq-A₀₄ : A₀₄ == A₀₄')
{A₂₀ A₂₀' : Type i} (eq-A₂₀ : A₂₀ == A₂₀')
{A₂₂ A₂₂' : Type i} (eq-A₂₂ : A₂₂ == A₂₂')
{A₂₄ A₂₄' : Type i} (eq-A₂₄ : A₂₄ == A₂₄')
{A₄₀ A₄₀' : Type i} (eq-A₄₀ : A₄₀ == A₄₀')
{A₄₂ A₄₂' : Type i} (eq-A₄₂ : A₄₂ == A₄₂')
{A₄₄ A₄₄' : Type i} (eq-A₄₄ : A₄₄ == A₄₄')
{f₀₁ : A₀₂ → A₀₀} {f₀₁' : A₀₂' → A₀₀'} (eq-f₀₁ : f₀₁ == f₀₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₀₂ eq-A₀₀ ])
{f₀₃ : A₀₂ → A₀₄} {f₀₃' : A₀₂' → A₀₄'} (eq-f₀₃ : f₀₃ == f₀₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₀₂ eq-A₀₄ ])
{f₂₁ : A₂₂ → A₂₀} {f₂₁' : A₂₂' → A₂₀'} (eq-f₂₁ : f₂₁ == f₂₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₂₀ ])
{f₂₃ : A₂₂ → A₂₄} {f₂₃' : A₂₂' → A₂₄'} (eq-f₂₃ : f₂₃ == f₂₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₂₄ ])
{f₄₁ : A₄₂ → A₄₀} {f₄₁' : A₄₂' → A₄₀'} (eq-f₄₁ : f₄₁ == f₄₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₄₂ eq-A₄₀ ])
{f₄₃ : A₄₂ → A₄₄} {f₄₃' : A₄₂' → A₄₄'} (eq-f₄₃ : f₄₃ == f₄₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₄₂ eq-A₄₄ ])
{f₁₀ : A₂₀ → A₀₀} {f₁₀' : A₂₀' → A₀₀'} (eq-f₁₀ : f₁₀ == f₁₀' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₀ eq-A₀₀ ])
{f₃₀ : A₂₀ → A₄₀} {f₃₀' : A₂₀' → A₄₀'} (eq-f₃₀ : f₃₀ == f₃₀' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₀ eq-A₄₀ ])
{f₁₂ : A₂₂ → A₀₂} {f₁₂' : A₂₂' → A₀₂'} (eq-f₁₂ : f₁₂ == f₁₂' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₀₂ ])
{f₃₂ : A₂₂ → A₄₂} {f₃₂' : A₂₂' → A₄₂'} (eq-f₃₂ : f₃₂ == f₃₂' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₄₂ ])
{f₁₄ : A₂₄ → A₀₄} {f₁₄' : A₂₄' → A₀₄'} (eq-f₁₄ : f₁₄ == f₁₄' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₄ eq-A₀₄ ])
{f₃₄ : A₂₄ → A₄₄} {f₃₄' : A₂₄' → A₄₄'} (eq-f₃₄ : f₃₄ == f₃₄' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₄ eq-A₄₄ ])
{H₁₁ : (x : A₂₂) → f₁₀ (f₂₁ x) == f₀₁ (f₁₂ x)} {H₁₁' : (x : A₂₂') → f₁₀' (f₂₁' x) == f₀₁' (f₁₂' x)}
(eq-H₁₁ : H₁₁ == H₁₁' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))
↓ square=-raw eq-A₂₂ eq-A₂₀ eq-A₀₂ eq-A₀₀ eq-f₂₁ eq-f₁₂ eq-f₁₀ eq-f₀₁ ])
{H₁₃ : (x : A₂₂) → f₀₃ (f₁₂ x) == f₁₄ (f₂₃ x)} {H₁₃' : (x : A₂₂') → f₀₃' (f₁₂' x) == f₁₄' (f₂₃' x)}
(eq-H₁₃ : H₁₃ == H₁₃' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))
↓ square=-raw eq-A₂₂ eq-A₀₂ eq-A₂₄ eq-A₀₄ eq-f₁₂ eq-f₂₃ eq-f₀₃ eq-f₁₄ ])
{H₃₁ : (x : A₂₂) → f₃₀ (f₂₁ x) == f₄₁ (f₃₂ x)} {H₃₁' : (x : A₂₂') → f₃₀' (f₂₁' x) == f₄₁' (f₃₂' x)}
(eq-H₃₁ : H₃₁ == H₃₁' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))
↓ square=-raw eq-A₂₂ eq-A₂₀ eq-A₄₂ eq-A₄₀ eq-f₂₁ eq-f₃₂ eq-f₃₀ eq-f₄₁ ])
{H₃₃ : (x : A₂₂) → f₄₃ (f₃₂ x) == f₃₄ (f₂₃ x)} {H₃₃' : (x : A₂₂') → f₄₃' (f₃₂' x) == f₃₄' (f₂₃' x)}
(eq-H₃₃ : H₃₃ == H₃₃' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))
↓ square=-raw eq-A₂₂ eq-A₄₂ eq-A₂₄ eq-A₄₄ eq-f₃₂ eq-f₂₃ eq-f₄₃ eq-f₃₄ ])
→ ap transpose (span^2=-raw eq-A₀₀ eq-A₀₂ eq-A₀₄ eq-A₂₀ eq-A₂₂ eq-A₂₄ eq-A₄₀ eq-A₄₂ eq-A₄₄ eq-f₀₁ eq-f₀₃ eq-f₂₁ eq-f₂₃ eq-f₄₁ eq-f₄₃ eq-f₁₀ eq-f₃₀ eq-f₁₂ eq-f₃₂ eq-f₁₄ eq-f₃₄ eq-H₁₁ eq-H₁₃ eq-H₃₁ eq-H₃₃)
== span^2=-raw eq-A₀₀ eq-A₂₀ eq-A₄₀ eq-A₀₂ eq-A₂₂ eq-A₄₂ eq-A₀₄ eq-A₂₄ eq-A₄₄ eq-f₁₀ eq-f₃₀ eq-f₁₂ eq-f₃₂ eq-f₁₄ eq-f₃₄ eq-f₀₁ eq-f₀₃ eq-f₂₁ eq-f₂₃ eq-f₄₁ eq-f₄₃ (square-thing _ _ _ _ _ _ _ _ (ap↓ (λ u → ! ∘ u) eq-H₁₁)) eq-H₃₁ eq-H₁₃ (square-thing _ _ _ _ _ _ _ _ (ap↓ (λ u → ! ∘ u) eq-H₃₃))
ap-span^2=-priv2 idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp = idp
module _ {i} (d : Span^2 {i}) where
open Span^2 d
transpose-transpose : transpose (transpose d) == d
transpose-transpose = span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp
(λ= (!-! ∘ Span^2.H₁₁ d)) idp idp (λ= (!-! ∘ Span^2.H₃₃ d))
module _ {i} (d : Span^2 {i}) where
transpose-equiv : Span^2 {i} ≃ Span^2
transpose-equiv = equiv transpose transpose transpose-transpose transpose-transpose
module _ {i} (d : Span^2 {i}) where
open Span^2 d
d' : (H₁₁' : type-of H₁₁) (H₃₃' : type-of H₃₃) → Span^2
d' H₁₁' H₃₃' = record d {H₁₁ = H₁₁'; H₃₃ = H₃₃'}
e : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (c : M.A₂∙ (d' H₁₁' H₃₃'))
→ left (M.f₁∙ (d' H₁₁' H₃₃') c) == right (M.f₃∙ (d' H₁₁' H₃₃') c)
e {H₁₁'} eq₁ {H₃₃'} eq₃ = E.f module _ where
e-glue : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (c : Span^2.A₂₂ (d' H₁₁' H₃₃'))
→ glue (left (f₂₁ c)) == glue (right (f₂₃ c)) [ (λ z → left (M.f₁∙ (d' H₁₁' H₃₃') z) == right (M.f₃∙ (d' H₁₁' H₃₃') z)) ↓ glue c ]
e-glue idp idp c = apd glue (glue c)
module E = PushoutElim {P = λ c → left (M.f₁∙ (d' H₁₁' H₃₃') c) == right (M.f₃∙ (d' H₁₁' H₃₃') c) :> Pushout^2 d} (glue ∘ left) (glue ∘ right) (e-glue eq₁ eq₃)
module F {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃')
= PushoutRec {d = M.v-h-span (d' H₁₁' H₃₃')} {D = Pushout^2 d}
left right (e eq₁ eq₃)
tr-tr-fun : Pushout^2 (transpose (transpose d)) → Pushout^2 d
tr-tr-fun = F.f (! (λ= (!-! ∘ H₁₁))) (! (λ= (!-! ∘ H₃₃)))
lemma12 : (c : M.A₂∙ d) → e idp idp c == glue c
lemma12 = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-=-in (! (E.glue-β idp idp c)))
result' : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (x : Pushout^2 (d' H₁₁' H₃₃'))
→ transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (! eq₁) idp idp (! eq₃) :> (d' H₁₁' H₃₃' == d)) x == F.f eq₁ eq₃ x
result' idp idp = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-='-in (F.glue-β idp idp c ∙ lemma12 c ∙ ! (ap-idf (glue c))))
result : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁' == H₁₁) {H₃₃' : type-of H₃₃} (eq₃ : H₃₃' == H₃₃) (x : Pushout^2 (d' H₁₁' H₃₃'))
→ transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp eq₁ idp idp eq₃ :> (d' H₁₁' H₃₃' == d)) x == F.f (! eq₁) (! eq₃) x
result eq₁ eq₃ x = ap (λ u → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp
idp idp idp idp idp idp idp idp (fst u) idp idp (snd u) :> (_ == d)) x)
(pair×= (! (!-! eq₁)) (! (!-! eq₃)))
∙ result' (! eq₁) (! eq₃) x
result2 : (x : Pushout^2 (transpose (transpose d))) → transport Pushout^2 (transpose-transpose d) x == tr-tr-fun x
result2 = result (λ= (!-! ∘ Span^2.H₁₁ d)) (λ= (!-! ∘ Span^2.H₃₃ d))
-- module _ {i} where
-- postulate
-- to : (d : Span^2 {i}) → Pushout^2 d → Pushout^2 (transpose d)
-- from : (d : Span^2 {i}) → Pushout^2 (transpose d) → Pushout^2 d
-- from d = tr-tr-fun d ∘ to (transpose d)
-- postulate
-- from-to : (d : Span^2 {i}) (x : Pushout^2 d) → from d (to d x) == x
-- lemma3 : {d d' : Span^2 {i}} (p : d == d') (x : Pushout^2 d) → transport (Pushout^2 ∘ transpose) p (to d x) == to d' (transport Pushout^2 p x)
-- lemma3 {d} {.d} idp x = idp
-- lemma34 : (d : Span^2 {i}) (x : Pushout^2 (transpose (transpose d))) → transport (Pushout^2 ∘ transpose) (transpose-transpose d) (to (transpose (transpose d)) x) == to d (tr-tr-fun d x)
-- lemma34 d x = lemma3 (transpose-transpose d) x ∙ ap (to d) (result2 d x)
-- lm2 : (d : Span^2 {i}) → ap transpose (transpose-transpose d) == transpose-transpose (transpose d)
-- lm2 d = ap-span^2=-priv2 idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp
-- (! (! (λ= (!-! ∘ Span^2.H₁₁ d)))) idp idp (! (! (λ= (!-! ∘ Span^2.H₃₃ d)))) ∙ ap (λ u → span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (fst u) idp idp (snd u)) (pair×= (lm3 (Span^2.H₁₁ d)) (lm3 (Span^2.H₃₃ d))) where
-- lm3 : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B} (p : (a : A) → f a == g a)
-- → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ p)))) == ! (! (λ= (!-! ∘ ! ∘ p)))
-- lm3 p = transport (λ u → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ u)))) == ! (! (λ= (!-! ∘ ! ∘ u)))) (λ= (app=-β p)) (lm3' (λ= p)) where
-- lm3' : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B} (p : f == g)
-- → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ app= p)))) == ! (! (λ= (!-! ∘ ! ∘ app= p)))
-- lm3' idp = ap (λ u → ap (λ u → ! ∘ u) (! (! u))) (! (λ=-η idp)) ∙ ap (! ∘ !) (λ=-η idp)
-- lemma345 : (d : Span^2 {i}) (x : Pushout^2 (transpose (transpose (transpose d))))
-- → transport (Pushout^2 ∘ transpose) (transpose-transpose d) x == tr-tr-fun (transpose d) x
-- lemma345 d x =
-- transport (Pushout^2 ∘ transpose) (transpose-transpose d) x
-- =⟨ ap (λ u → coe u x) (ap-∘ Pushout^2 transpose (transpose-transpose d)) ⟩
-- transport Pushout^2 (ap transpose (transpose-transpose d)) x
-- =⟨ ap (λ u → transport Pushout^2 u x) (lm2 d) ⟩
-- transport Pushout^2 (transpose-transpose (transpose d)) x
-- =⟨ result2 (transpose d) x ⟩
-- tr-tr-fun (transpose d) x ∎
-- to-from : (d : Span^2 {i}) (x : Pushout^2 (transpose d)) → to d (from d x) == x
-- to-from d x =
-- to d (tr-tr-fun d (to (transpose d) x))
-- =⟨ ! (lemma34 d (to (transpose d) x)) ⟩
-- transport (Pushout^2 ∘ transpose) (transpose-transpose d) (to (transpose (transpose d)) (to (transpose d) x))
-- =⟨ lemma345 d (to (transpose (transpose d)) (to (transpose d) x)) ⟩
-- tr-tr-fun (transpose d) (to (transpose (transpose d)) (to (transpose d) x))
-- =⟨ from-to (transpose d) x ⟩
-- x ∎
| {
"alphanum_fraction": 0.5030861723,
"avg_line_length": 63.6479591837,
"ext": "agda",
"hexsha": "22cfacdd9945131f2e169d8532962c055c6df568",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "homotopy/3x3/Transpose.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "homotopy/3x3/Transpose.agda",
"max_line_length": 294,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "homotopy/3x3/Transpose.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 6244,
"size": 12475
} |
module Issue443 where
module M (A : Set) where
record R : Set where
field
a : A
postulate
A : Set
I : A → Set
i : (x : A) → I x
r : M.R A
a = M.R.a A r
Foo : Set₁
Foo with i (M.R.a A r)
Foo | _ = Set
| {
"alphanum_fraction": 0.5223214286,
"avg_line_length": 11.7894736842,
"ext": "agda",
"hexsha": "ab6bd1c38913a69e5c948b88ebae991c6186adb3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/Issue443.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/Issue443.agda",
"max_line_length": 24,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue443.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 92,
"size": 224
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.RingSolver.CommRingHornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool using (Bool; true; false; if_then_else_; _and_)
open import Cubical.Algebra.RingSolver.RawRing
open import Cubical.Algebra.RingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ₐ)
open import Cubical.Algebra.RingSolver.AlmostRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
private
variable
ℓ ℓ′ : Level
{-
This defines the type of multivariate Polynomials over the RawRing R.
The construction is based on the algebraic fact
R[X₀][X₁]⋯[Xₙ] ≅ R[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n R k' is identified
with 'Xₖ', then the RawRing we construct should rather be denoted with
R[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((R[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms (A : RawAlgebra ℤAsRawRing ℓ) : ℕ → Type ℓ where
const : ℤ → IteratedHornerForms A ℕ.zero
0H : {n : ℕ} → IteratedHornerForms A (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms A (ℕ.suc n) → IteratedHornerForms A n
→ IteratedHornerForms A (ℕ.suc n)
module _ (A : RawAlgebra ℤAsRawRing ℓ′) where
open RawRing ℤAsRawRing
isZero : {n : ℕ} → IteratedHornerForms A n
→ Bool
isZero (const (pos ℕ.zero)) = true
isZero (const (pos (ℕ.suc _))) = false
isZero (const (negsuc _)) = false
isZero 0H = true
isZero (P ·X+ P₁) = false
eval : {A : RawAlgebra ℤAsRawRing ℓ′}
(n : ℕ) (P : IteratedHornerForms A n)
→ Vec ⟨ A ⟩ₐ n → ⟨ A ⟩ₐ
eval {A = A} ℕ.zero (const r) [] = RawAlgebra.scalar A r
eval {A = A} .(ℕ.suc _) 0H (_ ∷ _) = RawAlgebra.0r A
eval {A = A} (ℕ.suc n) (P ·X+ Q) (x ∷ xs) =
let open RawAlgebra A
P' = (eval (ℕ.suc n) P (x ∷ xs))
Q' = eval n Q xs
in if (isZero A P)
then Q'
else P' · x + Q'
module IteratedHornerOperations (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
private
1H' : (n : ℕ) → IteratedHornerForms A n
1H' ℕ.zero = const 1r
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms A n
0H' ℕ.zero = const 0r
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms A n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms A n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms A n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) =
let left = (P +ₕ Q)
right = (r +ₕ s)
in if ((isZero A left) and (isZero A right))
then 0ₕ
else left ·X+ right
-ₕ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
-ₕ (const x) = const (- x)
-ₕ 0H = 0H
-ₕ (P ·X+ Q) = (-ₕ P) ·X+ (-ₕ Q)
_⋆_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A (ℕ.suc n)
→ IteratedHornerForms A (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) =
if (isZero A r)
then 0ₕ
else (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero A z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
asRawRing : (n : ℕ) → RawRing {ℓ}
RawRing.Carrier (asRawRing n) = IteratedHornerForms A n
RawRing.0r (asRawRing n) = 0ₕ
RawRing.1r (asRawRing n) = 1ₕ
RawRing._+_ (asRawRing n) = _+ₕ_
RawRing._·_ (asRawRing n) = _·ₕ_
RawRing.- (asRawRing n) = -ₕ
Variable : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (k : Fin n) → IteratedHornerForms R n
Variable n R k = IteratedHornerOperations.X R n k
Constant : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (r : ℤ) → IteratedHornerForms R n
Constant ℕ.zero R r = const r
Constant (ℕ.suc n) R r = IteratedHornerOperations.0ₕ R ·X+ Constant n R r
| {
"alphanum_fraction": 0.6010838831,
"avg_line_length": 30.7536231884,
"ext": "agda",
"hexsha": "18a36a364d7407f549da703df573d1a574d353af",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Algebra/RingSolver/CommRingHornerForms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Algebra/RingSolver/CommRingHornerForms.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Algebra/RingSolver/CommRingHornerForms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1791,
"size": 4244
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module cw.cohomology.GridPtdMap {i j k}
{X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : X ⊙→ Y) (g : Y ⊙→ Z) where
open import cw.cohomology.GridMap (fst f) (fst g) public
Y/X = ⊙Cofiber f
Z/X = ⊙Cofiber (g ⊙∘ f)
Z/Y = ⊙Cofiber g
Y/X-to-Z/X : Y/X ⊙→ Z/X
Y/X-to-Z/X = B/A-to-C/A , idp
Z/X-to-Z/Y : Z/X ⊙→ Z/Y
Z/X-to-Z/Y = C/A-to-C/B , idp
| {
"alphanum_fraction": 0.5289855072,
"avg_line_length": 20.7,
"ext": "agda",
"hexsha": "dd50bbf352bd4722b6231be616a0701d9d7d0a24",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/GridPtdMap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/GridPtdMap.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/GridPtdMap.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 193,
"size": 414
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.HLevels
module Cubical.Algebra.Semigroup.Construct.Left {ℓ} (Aˢ : hSet ℓ) where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Semigroup
import Cubical.Algebra.Magma.Construct.Left Aˢ as LMagma
open LMagma public hiding (Left-isMagma; LeftMagma)
private
A = ⟨ Aˢ ⟩
isSetA = Aˢ .snd
◂-assoc : Associative _◂_
◂-assoc _ _ _ = refl
Left-isSemigroup : IsSemigroup A _◂_
Left-isSemigroup = record
{ isMagma = LMagma.Left-isMagma
; assoc = ◂-assoc
}
LeftSemigroup : Semigroup ℓ
LeftSemigroup = record { isSemigroup = Left-isSemigroup }
| {
"alphanum_fraction": 0.7424023155,
"avg_line_length": 23.0333333333,
"ext": "agda",
"hexsha": "bd2170437c18f0a55be098c94c934bd4aa6479f9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Algebra/Semigroup/Construct/Left.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Algebra/Semigroup/Construct/Left.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Algebra/Semigroup/Construct/Left.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 225,
"size": 691
} |
{-
Base facts about that the ring ℤ is Bézout domain
-}
{-# OPTIONS --safe #-}
module Cubical.Data.Int.Divisibility where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat
hiding (+-assoc ; +-comm ; ·-comm)
renaming (_·_ to _·ℕ_; _+_ to _+ℕ_ ; ·-assoc to ·ℕ-assoc)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Nat.Divisibility
using (m∣n→m≤n)
renaming (_∣_ to _∣ℕ_ ; isProp∣ to isProp∣ℕ ; stDivIneq to stDivIneqℕ)
open import Cubical.Data.Nat.Mod
open import Cubical.Data.Int
hiding (_+_ ; _·_ ; _-_ ; -_ ; addEq ; ·Comm ; ·Assoc ; +Comm ; +Assoc)
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.Relation.Nullary
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int
renaming (ℤ to Ringℤ)
open import Cubical.Algebra.RingSolver.Reflection
private
variable
m n k : ℤ
-- It seems there are bugs when applying ring solver to integers.
-- The following is a work-around.
private
module Helper {ℓ : Level}(𝓡 : CommRing ℓ) where
open CommRingStr (𝓡 .snd)
helper1 : (a b m d r : 𝓡 .fst) → (- a · d + b) · m + a · (d · m + r) ≡ a · r + b · m
helper1 = solve 𝓡
helper2 : (d m r : 𝓡 .fst) → (d · m + r) + (- d) · m ≡ r
helper2 = solve 𝓡
helper3 : (n m d r : 𝓡 .fst) → n ≡ d · m + r → n + (- d) · m ≡ r
helper3 n m d r p = (λ t → p t + (- d) · m) ∙ helper2 d m r
open Helper Ringℤ
open CommRingStr (Ringℤ .snd)
-- The Divisibility Relation
-- Most definitions are the same as in Cubical.Data.Nat.Divisibility
_∣_ : ℤ → ℤ → Type
m ∣ n = ∃[ c ∈ ℤ ] c · m ≡ n
isProp∣ : isProp (m ∣ n)
isProp∣ = squash
-- Untruncated divisiblility relation
_∣'_ : ℤ → ℤ → Type
pos 0 ∣' n = 0 ≡ n
pos (suc m) ∣' n = Σ[ c ∈ ℤ ] c · (pos (suc m)) ≡ n
(negsuc m) ∣' n = Σ[ c ∈ ℤ ] c · (negsuc m) ≡ n
isProp∣' : isProp (m ∣' n)
isProp∣' {m = pos 0} {n = n} = isSetℤ 0 n
isProp∣' {m = pos (suc m)} {n = n} p q =
Σ≡Prop (λ _ → isSetℤ _ _) (·rCancel (pos (suc m)) _ _ (p .snd ∙ sym (q .snd)) (λ r → snotz (injPos r)))
isProp∣' {m = negsuc m} {n = n} p q =
Σ≡Prop (λ _ → isSetℤ _ _) (·rCancel (negsuc m) _ _ (p .snd ∙ sym (q .snd)) (negsucNotpos _ 0))
∣→∣' : (m n : ℤ) → m ∣ n → m ∣' n
∣→∣' (pos 0) n ∣ c , p ∣ = ·Comm 0 c ∙ p
∣→∣' (pos (suc m)) n ∣ p ∣ = p
∣→∣' (negsuc m) n ∣ p ∣ = p
∣→∣' m n (squash p q i) = isProp∣' (∣→∣' _ _ p) (∣→∣' _ _ q) i
∣'→∣ : (m n : ℤ) → m ∣' n → m ∣ n
∣'→∣ (pos 0) n p = ∣ 0 , p ∣
∣'→∣ (pos (suc m)) n p = ∣ p ∣
∣'→∣ (negsuc m) n p = ∣ p ∣
∣≃∣' : (m n : ℤ) → (m ∣ n) ≃ (m ∣' n)
∣≃∣' m n = propBiimpl→Equiv isProp∣ isProp∣' (∣→∣' _ _) (∣'→∣ _ _)
-- Properties of divisibility
∣-left : m ∣ (m · k)
∣-left {k = k} = ∣ k , ·Comm k _ ∣
∣-right : m ∣ (k · m)
∣-right {k = k} = ∣ k , refl ∣
∣-refl : m ≡ n → m ∣ n
∣-refl p = ∣ 1 , p ∣
∣-zeroˡ : 0 ∣ m → 0 ≡ m
∣-zeroˡ = ∣→∣' _ _
∣-zeroʳ : m ∣ 0
∣-zeroʳ = ∣ 0 , refl ∣
∣-+ : k ∣ m → k ∣ n → k ∣ (m + n)
∣-+ =
Prop.map2
λ {(c₁ , p) (c₂ , q) → (c₁ + c₂ , ·DistL+ c₁ c₂ _ ∙ (λ t → p t + q t))}
∣-trans : k ∣ m → m ∣ n → k ∣ n
∣-trans =
Prop.map2
λ {(c₁ , p) (c₂ , q) → (c₂ · c₁ , sym (·Assoc c₂ c₁ _) ∙ cong (c₂ ·_) p ∙ q)}
∣-left· : k ∣ n → k ∣ (n · m)
∣-left· {k = k} {m = m} p = ∣-trans p (∣-left {k = m})
∣-right· : k ∣ m → k ∣ (n · m)
∣-right· {k = k} {n = n} p = ∣-trans p (∣-right {k = n})
-- Natural numbers back and forth (using abs)
∣→∣ℕ : m ∣ n → abs m ∣ℕ abs n
∣→∣ℕ {m = m} = Prop.rec isProp∣ℕ (λ (c , h) → ∣ abs c , sym (abs· c m) ∙ cong abs h ∣)
private
∣ℕ→∣-helper : (m n : ℤ)
→ (c : ℕ)(h : c ·ℕ abs m ≡ abs n)
→ (m ≡ pos (abs m)) ⊎ (m ≡ - pos (abs m))
→ (n ≡ pos (abs n)) ⊎ (n ≡ - pos (abs n))
→ Σ[ d ∈ ℤ ] d · m ≡ n
∣ℕ→∣-helper _ _ c _ (inl _) (inl _) .fst = pos c
∣ℕ→∣-helper m n c h (inl p) (inl q) .snd =
(λ t → pos c · p t)
∙ sym (pos·pos c (abs m))
∙ cong pos h
∙ sym q
∣ℕ→∣-helper _ _ c _ (inl _) (inr _) .fst = - pos c
∣ℕ→∣-helper m n c h (inl p) (inr q) .snd =
(λ t → - pos c · p t)
∙ sym (-DistL· (pos c) (pos (abs m)))
∙ (λ t → - pos·pos c (abs m) (~ t))
∙ cong (-_) (cong pos h)
∙ sym q
∣ℕ→∣-helper _ _ c _ (inr _) (inl _) .fst = - pos c
∣ℕ→∣-helper m n c h (inr p) (inl q) .snd =
(λ t → - pos c · p t)
∙ sym (-DistLR· (pos c) (pos (abs m)))
∙ sym (pos·pos c (abs m))
∙ cong pos h
∙ sym q
∣ℕ→∣-helper _ _ c _ (inr _) (inr _) .fst = pos c
∣ℕ→∣-helper m n c h (inr p) (inr q) .snd =
(λ t → pos c · p t)
∙ sym (-DistR· (pos c) (pos (abs m)))
∙ (λ t → - pos·pos c (abs m) (~ t))
∙ cong (-_) (cong pos h)
∙ sym q
∣ℕ→∣ : abs m ∣ℕ abs n → m ∣ n
∣ℕ→∣ = Prop.rec isProp∣ (λ (c , h) → ∣ ∣ℕ→∣-helper _ _ c h (abs→⊎ _ _ refl) (abs→⊎ _ _ refl) ∣)
¬∣→¬∣ℕ : ¬ m ∣ n → ¬ abs m ∣ℕ abs n
¬∣→¬∣ℕ p q = p (∣ℕ→∣ q)
-- Inequality for strict divisibility
stDivIneq : ¬ m ≡ 0 → ¬ m ∣ n → k ∣ m → k ∣ n → abs k < abs m
stDivIneq p q h h' = stDivIneqℕ (¬x≡0→¬abs≡0 p) (¬∣→¬∣ℕ q) (∣→∣ℕ h) (∣→∣ℕ h')
-- Exact division
divide : m ∣ n → ℤ
divide {m = pos 0} _ = 0
divide {m = pos (suc m)} p = ∣→∣' _ _ p .fst
divide {m = negsuc m} p = ∣→∣' _ _ p .fst
divideEq : (p : m ∣ n) → divide p · m ≡ n
divideEq {m = pos 0} = ∣→∣' _ _
divideEq {m = pos (suc m)} p = ∣→∣' _ _ p .snd
divideEq {m = negsuc m} p = ∣→∣' _ _ p .snd
-- Bézout and Euclidean Domain
record Bézout (m n : ℤ) : Type where
constructor bezout
field
coef₁ : ℤ
coef₂ : ℤ
gcd : ℤ
identity : coef₁ · m + coef₂ · n ≡ gcd
isCD : (gcd ∣ m) × (gcd ∣ n)
open Bézout
Bézout0 : (n : ℤ) → Bézout 0 n
Bézout0 n .coef₁ = 0
Bézout0 n .coef₂ = 1
Bézout0 n .gcd = n
Bézout0 n .identity = +Comm 0 n
Bézout0 n .isCD = ∣-zeroʳ , ∣-refl refl
bézoutReduction : (m d r : ℤ) → Bézout r m → Bézout m (d · m + r)
bézoutReduction m d r b .coef₁ = - b .coef₁ · d + b .coef₂
bézoutReduction m d r b .coef₂ = b .coef₁
bézoutReduction m d r b .gcd = b .gcd
bézoutReduction m d r b .identity = helper1 (b .coef₁) (b .coef₂) m d r ∙ b .identity
bézoutReduction m d r b .isCD .fst = b .isCD .snd
bézoutReduction m d r b .isCD .snd = ∣-+ (∣-right· {n = d} (b .isCD .snd)) (b .isCD .fst)
-- Properties of Bézout identity
module _
(b : Bézout m n) where
private
g = b .gcd
gcdIsGCD : k ∣ m → k ∣ n → k ∣ g
gcdIsGCD {k = k} p q =
subst (k ∣_) (b .identity) (∣-+ (∣-right· {n = b .coef₁} p) (∣-right· {n = b .coef₂} q))
gcd≡0 : g ≡ 0 → (m ≡ 0) × (n ≡ 0)
gcd≡0 p .fst = sym (∣-zeroˡ (subst (λ a → a ∣ _) p (b .isCD .fst)))
gcd≡0 p .snd = sym (∣-zeroˡ (subst (λ a → a ∣ _) p (b .isCD .snd)))
¬m≡0→¬gcd≡0 : ¬ m ≡ 0 → ¬ g ≡ 0
¬m≡0→¬gcd≡0 p q = p (gcd≡0 q .fst)
div₁ div₂ : ℤ
div₁ = divide (b .isCD .fst)
div₂ = divide (b .isCD .snd)
div·-helper : g · (div₁ · n) ≡ g · (div₂ · m)
div·-helper =
·Assoc g div₁ n
∙ (λ i → ·Comm g div₁ i · n)
∙ (λ i → divideEq (b .isCD .fst) i · n)
∙ ·Comm m n
∙ (λ i → divideEq (b .isCD .snd) (~ i) · m)
∙ (λ i → ·Comm div₂ g i · m)
∙ sym (·Assoc g div₂ m)
div·-g≠0 : ¬ g ≡ 0 → div₁ · n ≡ div₂ · m
div·-g≠0 p = ·lCancel _ _ _ div·-helper p
div·-g≡0 : g ≡ 0 → div₁ · n ≡ div₂ · m
div·-g≡0 p =
(λ i → div₁ · gcd≡0 p .snd i)
∙ ·Comm div₁ 0
∙ ·Comm 0 div₂
∙ (λ i → div₂ · gcd≡0 p .fst (~ i))
div·-case : Dec (g ≡ 0) → div₁ · n ≡ div₂ · m
div·-case (yes p) = div·-g≡0 p
div·-case (no ¬p) = div·-g≠0 ¬p
div· : div₁ · n ≡ div₂ · m
div· = div·-case (discreteℤ g 0)
div·- : - div₂ · m + div₁ · n ≡ 0
div·- = (λ i → -DistL· div₂ m (~ i) + div₁ · n)
∙ subst (λ a → - a + div₁ · n ≡ 0) div· (-Cancel' (div₁ · n))
-- Quotient and Remainder
record QuotRem (m n : ℤ) : Type where
constructor quotrem
field
div : ℤ
rem : ℤ
quotEq : n ≡ div · m + rem
normIneq : (rem ≡ 0) ⊎ ((¬ rem ≡ 0) × (abs rem < abs m))
open QuotRem
-- Using remainder to decide divisibility
module _
(m n : ℤ)(qr : QuotRem m n) where
rem≡0→m∣n : qr .rem ≡ 0 → m ∣ n
rem≡0→m∣n p = ∣ qr .div , (λ i → qr .div · m + p (~ i)) ∙ sym (qr .quotEq) ∣
m∣n→rem≡0 : m ∣ n → qr .rem ≡ 0
m∣n→rem≡0 p =
case qr .normIneq
return _ of λ
{ (inl q) → q
; (inr q) →
let ∣+ = ∣-+ p (∣-right {m = m} {k = - qr .div})
m∣r = subst (m ∣_) (helper3 _ _ (qr .div) (qr .rem) (qr .quotEq)) ∣+
m≤r = m∣n→m≤n (¬x≡0→¬abs≡0 (q .fst)) (∣→∣ℕ m∣r)
in Empty.rec (<-asym (q .snd) m≤r) }
m∣n→rem≡0' : (p : m ∣ n) → qr .normIneq ≡ inl (m∣n→rem≡0 p)
m∣n→rem≡0' p =
case (qr .normIneq)
return (λ x → x ≡ inl (m∣n→rem≡0 p)) of λ
{ (inl q) → cong inl (isSet→SquareP (λ i j → isSetℤ) q (m∣n→rem≡0 p) refl refl)
; (inr q) → Empty.rec (q .fst (m∣n→rem≡0 p)) }
rem≢0→m∤n : ¬ qr .rem ≡ 0 → ¬ m ∣ n
rem≢0→m∤n p q = p (m∣n→rem≡0 q)
-- The Euclidean Algorithm
module _
(decEq0 : (n : ℤ) → Dec (n ≡ 0))
(quotRem : (m n : ℤ)(¬z : ¬ m ≡ 0) → QuotRem m n) where
euclidStep : (norm : ℕ)
→ (m n : ℤ)(h : abs m < norm)
→ (b : QuotRem m n)
→ Bézout m n
euclidStep 0 _ _ h _ = Empty.rec (¬-<-zero h)
euclidStep (suc N) m n h (quotrem div rem quotEq (inl p)) =
let q = subst (λ r → n ≡ div · m + r) p quotEq
in bezout 1 0 m refl (∣-refl refl , subst (λ k → m ∣ k) (sym q) (∣-right {k = div}))
euclidStep (suc N) m n h (quotrem div rem quotEq (inr p)) =
let b = euclidStep N rem m (<≤-trans (p .snd) (pred-≤-pred h)) (quotRem _ _ (p .fst))
in subst (λ x → Bézout m x) (sym quotEq) (bézoutReduction _ div _ b)
private
euclid-helper : (m n : ℤ)(dec : Dec (m ≡ 0)) → Bézout m n
euclid-helper m n (yes z) = subst (λ x → Bézout x n) (sym z) (Bézout0 n)
euclid-helper m n (no ¬z) = euclidStep (suc (abs m)) m n ≤-refl (quotRem m n ¬z)
euclid : (m n : ℤ) → Bézout m n
euclid m n = euclid-helper m n (decEq0 _)
-- Euclid algorithm when divisibility holds
euclid∣ : (m n : ℤ) → ¬ m ≡ 0 → m ∣ n → (euclid m n .coef₁ ≡ 1) × (euclid m n .coef₂ ≡ 0)
euclid∣ _ _ = euclid∣-helper _ _ (decEq0 _)
where
euclid∣-helper : (m n : ℤ)(dec : Dec (m ≡ 0)) → ¬ m ≡ 0 → m ∣ n
→ (euclid-helper m n dec .coef₁ ≡ 1) × (euclid-helper m n dec .coef₂ ≡ 0)
euclid∣-helper _ _ (yes z) q = Empty.rec (q z)
euclid∣-helper m n (no ¬z) _ q =
let qr = quotRem m n ¬z
path : qr ≡ quotrem _ _ _ _
path t = record qr { normIneq = m∣n→rem≡0' _ _ qr q t }
in (λ t → euclidStep (suc (abs m)) m n ≤-refl (path t) .coef₁) ,
(λ t → euclidStep (suc (abs m)) m n ≤-refl (path t) .coef₂)
-- The ring ℤ is an Euclidean domain
private
dec-helper : {ℓ ℓ' : Level}{A : Type ℓ}{B : Type ℓ'} → Dec A → B → A ⊎ ((¬ A) × B)
dec-helper (yes p) _ = inl p
dec-helper (no ¬p) b = inr (¬p , b)
quotRemPosPos : (m n : ℕ)(¬z : ¬ pos m ≡ 0) → QuotRem (pos m) (pos n)
quotRemPosPos m n _ .div = pos (quotient n / m)
quotRemPosPos m n _ .rem = pos (remainder n / m)
quotRemPosPos m n _ .quotEq =
(λ t → pos (≡remainder+quotient m n (~ t)))
∙ pos+ (remainder n / m) (m ·ℕ (quotient n / m))
∙ +Comm (pos (remainder n / m)) (pos (m ·ℕ (quotient n / m)))
∙ (λ t → pos·pos m (quotient n / m) t + pos (remainder n / m))
∙ (λ t → ·Comm (pos m) (pos (quotient n / m)) t + pos (remainder n / m))
quotRemPosPos 0 n ¬z .normIneq = Empty.rec (¬z refl)
quotRemPosPos (suc m) n ¬z .normIneq = dec-helper (discreteℤ _ 0) (mod< m n)
quotRemNegPos : (m n : ℕ)(¬z : ¬ - pos m ≡ 0) → QuotRem (- pos m) (pos n)
quotRemNegPos m n ¬z .div = - (quotRemPosPos m n (λ p → ¬z (λ t → - p t)) .div)
quotRemNegPos m n ¬z .rem = quotRemPosPos m n (λ p → ¬z (λ t → - p t)) .rem
quotRemNegPos m n ¬z .quotEq =
quotRemPosPos m n (λ p → ¬z (λ t → - p t)) .quotEq
∙ (λ t → -DistLR· (pos (quotient n / m)) (pos m) t + (pos (remainder n / m)))
quotRemNegPos 0 n ¬z .normIneq = Empty.rec (¬z refl)
quotRemNegPos (suc m) n ¬z .normIneq = quotRemPosPos (suc m) n (λ p → ¬z (λ t → - p t)) .normIneq
private
quotRemPos-helper : (m : ℤ)(k n : ℕ)(¬z : ¬ m ≡ 0) → (m ≡ pos k) ⊎ (m ≡ - pos k) → QuotRem m (pos n)
quotRemPos-helper m k n ¬z (inl p) =
subst (λ l → QuotRem l (pos n)) (sym p) (quotRemPosPos k n (λ r → ¬z (p ∙ r)))
quotRemPos-helper m k n ¬z (inr p) =
subst (λ l → QuotRem l (pos n)) (sym p) (quotRemNegPos k n (λ r → ¬z (p ∙ r)))
quotRemPos : (m : ℤ)(n : ℕ)(¬z : ¬ m ≡ 0) → QuotRem m (pos n)
quotRemPos m n ¬z = quotRemPos-helper m (abs m) n ¬z (abs→⊎ _ _ refl)
private
sum-helper : (m r : ℤ)
→ (r ≡ 0) ⊎ ((¬ r ≡ 0) × (abs r < abs m))
→ (- r ≡ 0) ⊎ ((¬ - r ≡ 0) × (abs (- r) < abs m))
sum-helper m r (inl p) = inl (λ t → - p t)
sum-helper m r (inr p) =
inr ((λ q → p .fst (sym (-Involutive r) ∙ (λ t → - q t)))
, subst (λ k → k < abs m) (sym (abs- r)) (p .snd))
quotRemNeg : (m : ℤ)(n : ℕ)(¬z : ¬ m ≡ 0) → QuotRem m (- pos n)
quotRemNeg m n ¬z .div = - (quotRemPos m n ¬z .div)
quotRemNeg m n ¬z .rem = - (quotRemPos m n ¬z .rem)
quotRemNeg m n ¬z .quotEq =
(λ t → - quotRemPos m n ¬z .quotEq t)
∙ -Dist+ (quotRemPos m n ¬z .div · m) (quotRemPos m n ¬z .rem)
∙ (λ t → -DistL· (quotRemPos m n ¬z .div) m t + - quotRemPos m n ¬z .rem)
quotRemNeg m n ¬z .normIneq = sum-helper m _ (quotRemPos m n ¬z .normIneq)
private
quotRem-helper : (m n : ℤ)(k : ℕ)(¬z : ¬ m ≡ 0) → (n ≡ pos k) ⊎ (n ≡ - pos k) → QuotRem m n
quotRem-helper m n k ¬z (inl p) = subst (λ l → QuotRem m l) (sym p) (quotRemPos m k ¬z)
quotRem-helper m n k ¬z (inr p) = subst (λ l → QuotRem m l) (sym p) (quotRemNeg m k ¬z)
-- The quotient-remainder Theorem and the Bézout identity
quotRem : (m n : ℤ)(¬z : ¬ m ≡ 0) → QuotRem m n
quotRem m n ¬z = quotRem-helper m n (abs n) ¬z (abs→⊎ _ _ refl)
bézout : (m n : ℤ) → Bézout m n
bézout = euclid (λ m → discreteℤ m 0) quotRem
bézout∣ : (m n : ℤ) → ¬ m ≡ 0 → m ∣ n → (bézout m n .coef₁ ≡ 1) × (bézout m n .coef₂ ≡ 0)
bézout∣ = euclid∣ (λ m → discreteℤ m 0) quotRem
-- Divisibility is decidable
dec∣ : (m n : ℤ) → Dec (m ∣ n)
dec∣ m n =
case discreteℤ m 0
return (λ _ → Dec (m ∣ n)) of λ
{ (yes p) →
case discreteℤ n 0
return (λ _ → Dec (m ∣ n)) of λ
{ (yes p) → yes (subst (m ∣_) (sym p) ∣-zeroʳ)
; (no ¬p) → no (λ r → ¬p (sym (∣-zeroˡ (subst (_∣ n) p r)))) }
; (no ¬p) →
let qr = quotRem m n ¬p in
case discreteℤ (qr .rem) 0
return (λ _ → Dec (m ∣ n)) of λ
{ (yes p) → yes (rem≡0→m∣n _ _ qr p)
; (no ¬p) → no (rem≢0→m∤n _ _ qr ¬p) }}
| {
"alphanum_fraction": 0.5179086044,
"avg_line_length": 32.3866666667,
"ext": "agda",
"hexsha": "075e9f1dd4d7ecb397f9e576e183f5d5e57496aa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Data/Int/Divisibility.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Data/Int/Divisibility.agda",
"max_line_length": 105,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Data/Int/Divisibility.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6945,
"size": 14574
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Constructions.Product where
open import Data.Bool using (Bool ; true ; false ; not)
open import Data.Empty using (⊥)
open import Data.Product using (_,_ ; proj₁ ; proj₂) renaming (_×_ to _×T_)
open import Level
open import Cats.Category.Base
open import Cats.Category.Constructions.Terminal as Terminal using (HasTerminal)
open import Cats.Functor using (Functor)
open import Cats.Util.Conv
import Cats.Category.Constructions.Iso as Iso
import Cats.Category.Constructions.Unique as Unique
Bool-elim : ∀ {a} {A : Bool → Set a} → A true → A false → (i : Bool) → A i
Bool-elim x y true = x
Bool-elim x y false = y
module Build {lo la l≈} (Cat : Category lo la l≈) where
private open module Cat = Category Cat
open Cat.≈-Reasoning
open Iso.Build Cat
open Unique.Build Cat
open Terminal.Build Cat
open _≅_
IsProduct : ∀ {li} {I : Set li} (O : I → Obj) P → (∀ i → P ⇒ O i)
→ Set (lo ⊔ la ⊔ l≈ ⊔ li)
IsProduct O P proj
= ∀ {X} (x : ∀ i → X ⇒ O i) → ∃![ u ] (∀ i → x i ≈ proj i ∘ u)
-- TODO The types of the equalities in IsBinaryProducts are backwards, since
-- we want the RHS to be simpler than the LHS. So, projl ∘ u ≈ xl instead
-- of xl ≈ projl ∘ u.
IsBinaryProduct : ∀ {A B} P → (P ⇒ A) → (P ⇒ B) → Set (lo ⊔ la ⊔ l≈)
IsBinaryProduct {A} {B} P projl projr
= ∀ {X} (xl : X ⇒ A) (xr : X ⇒ B)
→ ∃![ u ] (xl ≈ projl ∘ u ×T xr ≈ projr ∘ u)
IsBinaryProduct→IsProduct : ∀ {A B P} {pl : P ⇒ A} {pr : P ⇒ B}
→ IsBinaryProduct P pl pr
→ IsProduct (Bool-elim A B) P (Bool-elim pl pr)
IsBinaryProduct→IsProduct isBinProd x = record
{ arr = f ⃗
; prop = Bool-elim (proj₁ (∃!′.prop f)) (proj₂ (∃!′.prop f))
; unique = λ eq → ∃!′.unique f (eq true , eq false)
}
where
f = isBinProd (x true) (x false)
record Product {li} {I : Set li} (O : I → Obj) : Set (lo ⊔ la ⊔ l≈ ⊔ li) where
field
prod : Obj
proj : ∀ i → prod ⇒ O i
isProduct : IsProduct O prod proj
open Product using (proj ; isProduct)
instance
HasObj-Product : ∀ {li} {I : Set li} {O : I → Obj}
→ HasObj (Product O) lo la l≈
HasObj-Product = record { Cat = Cat ; _ᴼ = Product.prod }
BinaryProduct : Obj → Obj → Set (lo ⊔ la ⊔ l≈)
BinaryProduct A B = Product (Bool-elim A B)
mkBinaryProduct : ∀ {A B P} (pl : P ⇒ A) (pr : P ⇒ B)
→ IsBinaryProduct P pl pr
→ BinaryProduct A B
mkBinaryProduct {P = P} pl pr isBinProd = record
{ isProduct = IsBinaryProduct→IsProduct isBinProd }
nullaryProduct-Terminal : (P : Product {I = ⊥} (λ())) → IsTerminal (P ᴼ)
nullaryProduct-Terminal P X with isProduct P {X = X} λ()
... | ∃!-intro arr _ unique = ∃!-intro arr _ (λ _ → unique λ())
module _ {li} {I : Set li} {O : I → Obj} (P : Product O) where
factorizer : ∀ {X} → (∀ i → X ⇒ O i) → X ⇒ P ᴼ
factorizer proj = isProduct P proj ⃗
factorizer-unique : ∀ {X} (fact : X ⇒ P ᴼ)
→ {x : ∀ i → X ⇒ O i}
→ (∀ i → x i ≈ proj P i ∘ fact)
→ factorizer x ≈ fact
factorizer-unique fact {x} eq = ∃!′.unique (isProduct P x) eq
factorizer-proj : ∀ {X} {x : ∀ i → X ⇒ O i} {i}
→ proj P i ∘ factorizer x ≈ x i
factorizer-proj {x = x} {i} = ≈.sym (∃!′.prop (isProduct P x) i)
factorizer-resp : ∀ {X} {x y : ∀ i → X ⇒ O i}
→ (∀ i → x i ≈ y i)
→ factorizer x ≈ factorizer y
factorizer-resp {x = x} {y} eq = factorizer-unique (factorizer y)
λ i → ≈.trans (eq _) (≈.sym factorizer-proj)
factorizer-∘ : ∀ {X} {x : ∀ i → X ⇒ O i} {Z} {f : Z ⇒ X}
→ factorizer x ∘ f ≈ factorizer (λ i → x i ∘ f)
factorizer-∘ {x = x} {f = f} = ≈.sym
(factorizer-unique (factorizer x ∘ f)
λ _ → ≈.sym (≈.trans unassoc (∘-resp-l factorizer-proj)))
factorizer-id : factorizer (proj P) ≈ id
factorizer-id = factorizer-unique id λ i → ≈.sym id-r
module _ {li} {I : Set li}
{O : I → Obj} (P : Product O)
{O′ : I → Obj} (P′ : Product O′)
where
times : (∀ i → O i ⇒ O′ i) → P ᴼ ⇒ P′ ᴼ
times x = factorizer P′ (λ i → x i ∘ proj P i)
times-proj : ∀ {x : ∀ i → O i ⇒ O′ i} {i}
→ proj P′ i ∘ times x ≈ x i ∘ proj P i
times-proj = factorizer-proj P′
times-resp : {x y : ∀ i → O i ⇒ O′ i}
→ (∀ i → x i ≈ y i)
→ times x ≈ times y
times-resp {x} {y} eq = factorizer-resp P′ (λ i → ∘-resp-l (eq i))
times-id : ∀ {li} {I : Set li} {O : I → Obj} (P : Product O)
→ times P P (λ _ → id) ≈ id
times-id P = factorizer-unique P id λ _ → ≈.trans id-l (≈.sym id-r)
times-∘ : ∀ {li} {I : Set li}
→ {O O′ O″ : I → Obj}
→ (P : Product O) (P′ : Product O′) (P″ : Product O″)
→ {x : ∀ i → O i ⇒ O′ i} {y : ∀ i → O′ i ⇒ O″ i}
→ times P′ P″ y ∘ times P P′ x ≈ times P P″ (λ i → y i ∘ x i)
times-∘ P P′ P″ {x} {y} =
begin
times P′ P″ y ∘ times P P′ x
≈⟨ factorizer-∘ P″ ⟩
factorizer P″ (λ i → (y i ∘ proj P′ i) ∘ times P P′ x)
≈⟨ factorizer-resp P″ (λ i → assoc) ⟩
factorizer P″ (λ i → y i ∘ proj P′ i ∘ times P P′ x)
≈⟨ factorizer-resp P″ (λ i → ∘-resp-r (times-proj P P′)) ⟩
factorizer P″ (λ i → y i ∘ x i ∘ proj P i)
≈⟨ factorizer-resp P″ (λ i → unassoc) ⟩
times P P″ (λ i → y i ∘ x i)
∎
times-factorizer : ∀ {li} {I : Set li}
→ {O O′ : I → Obj}
→ (P : Product O) (P′ : Product O′)
→ ∀ {X} {x : ∀ i → X ⇒ O i} {y : ∀ i → O i ⇒ O′ i}
→ times P P′ y ∘ factorizer P x ≈ factorizer P′ (λ i → y i ∘ x i)
times-factorizer P P′
= ≈.trans (factorizer-∘ P′)
(factorizer-resp P′ λ i → ≈.trans assoc (∘-resp-r (factorizer-proj P)))
proj-cancel : ∀ {li} {I : Set li} {O : I → Obj} {P proj}
→ IsProduct O P proj
→ ∀ {X} {f g : X ⇒ P}
→ (∀ i → proj i ∘ f ≈ proj i ∘ g)
→ f ≈ g
proj-cancel {proj = proj} prod {f = f} {g} eq with prod (λ i → proj i ∘ g)
... | ∃!-intro u _ u-uniq
= begin
f
≈⟨ ≈.sym (u-uniq (λ i → ≈.sym (eq i))) ⟩
u
≈⟨ u-uniq (λ i → ≈.refl) ⟩
g
∎
Product-resp-≅ : ∀ {li} {I : Set li} {O O′ : I → Obj}
→ (∀ i → O i ≅ O′ i)
→ (P : Product O) (P′ : Product O′)
→ P ᴼ ≅ P′ ᴼ
Product-resp-≅ O≅O′ P P′ = record
{ forth = factorizer P′ (λ i → O≅O′ i .forth ∘ proj P i)
; back = factorizer P (λ i → O≅O′ i .back ∘ proj P′ i)
; back-forth = ≈.trans (factorizer-∘ P)
(factorizer-unique P id λ i →
≈.trans assoc (≈.trans (∘-resp-r (factorizer-proj P′))
(≈.trans unassoc (≈.trans (∘-resp-l (O≅O′ i .back-forth))
(≈.trans id-l (≈.sym id-r))))))
; forth-back = ≈.trans (factorizer-∘ P′)
(factorizer-unique P′ id λ i →
≈.trans assoc (≈.trans (∘-resp-r (factorizer-proj P))
(≈.trans unassoc (≈.trans (∘-resp-l (O≅O′ i .forth-back))
(≈.trans id-l (≈.sym id-r))))))
}
open Build public using
(IsProduct ; IsBinaryProduct ; Product ; BinaryProduct ; HasObj-Product)
record HasProducts {lo la l≈} li (C : Category lo la l≈)
: Set (suc li ⊔ lo ⊔ la ⊔ l≈ )
where
private module Bld = Build C
open Category C
open Iso.Build C
field
Π′ : {I : Set li} (O : I → Obj) → Product C O
module _ {I : Set li} where
Π : ∀ (O : I → Obj) → Obj
Π O = Product.prod (Π′ O)
syntax Π (λ i → O) = Π[ i ] O
proj : ∀ {O : I → Obj} i → Π O ⇒ O i
proj {O} = Bld.Product.proj (Π′ O)
factorizer : ∀ {O : I → Obj} {X} → (∀ i → X ⇒ O i) → X ⇒ Π O
factorizer {O} = Bld.factorizer (Π′ O)
times : ∀ {O O′ : I → Obj} → (∀ i → O i ⇒ O′ i) → Π O ⇒ Π O′
times {O} {O′} = Bld.times (Π′ O) (Π′ O′)
factorizer-proj : ∀ {O : I → Obj} {X} {x : ∀ i → X ⇒ O i} {i}
→ proj i ∘ factorizer x ≈ x i
factorizer-proj {O} = Bld.factorizer-proj (Π′ O)
factorizer-resp : ∀ {O : I → Obj} {X} {x y : ∀ i → X ⇒ O i}
→ (∀ i → x i ≈ y i)
→ factorizer x ≈ factorizer y
factorizer-resp {O} = Bld.factorizer-resp (Π′ O)
factorizer-unique : ∀ {O : I → Obj} {X} {x : ∀ i → X ⇒ O i} {u}
→ (∀ i → x i ≈ proj i ∘ u)
→ factorizer x ≈ u
factorizer-unique {O} eq = Bld.factorizer-unique (Π′ O) _ eq
factorizer-∘ : ∀ {O : I → Obj} {X} {x : ∀ i → X ⇒ O i} {Z} {f : Z ⇒ X}
→ factorizer x ∘ f ≈ factorizer (λ i → x i ∘ f)
factorizer-∘ {O} = Bld.factorizer-∘ (Π′ O)
factorizer-id : ∀ {O} → factorizer {O} proj ≈ id
factorizer-id {O} = Bld.factorizer-id (Π′ O)
times-proj : ∀ {O O′ : I → Obj} {x : ∀ i → O i ⇒ O′ i} {i}
→ proj i ∘ times x ≈ x i ∘ proj i
times-proj {O} {O′} = Bld.times-proj (Π′ O) (Π′ O′)
times-resp : ∀ {O O′ : I → Obj} {x y : ∀ i → O i ⇒ O′ i}
→ (∀ i → x i ≈ y i)
→ times x ≈ times y
times-resp {O} {O′} = Bld.times-resp (Π′ O) (Π′ O′)
times-id : ∀ {O : I → Obj} → times {O} (λ _ → id) ≈ id
times-id {O} = Bld.times-id (Π′ O)
times-∘ : ∀ {O O′ O″ : I → Obj} {x : ∀ i → O i ⇒ O′ i} {y : ∀ i → O′ i ⇒ O″ i}
→ times y ∘ times x ≈ times (λ i → y i ∘ x i)
times-∘ {O} {O′} {O″} = Bld.times-∘ (Π′ O) (Π′ O′) (Π′ O″)
times-factorizer : ∀ {O O′ : I → Obj} {X}
→ {x : ∀ i → X ⇒ O i} {y : ∀ i → O i ⇒ O′ i}
→ times y ∘ factorizer x ≈ factorizer (λ i → y i ∘ x i)
times-factorizer {O} {O′} = Bld.times-factorizer (Π′ O) (Π′ O′)
Π-resp-≅ : ∀ {O O′ : I → Obj}
→ (∀ i → O i ≅ O′ i)
→ Π O ≅ Π O′
Π-resp-≅ {O} {O′} O≅O′ = Bld.Product-resp-≅ O≅O′ (Π′ O) (Π′ O′)
HasProducts→HasTerminal : ∀ {lo la l≈} {C : Category lo la l≈}
→ HasProducts zero C
→ HasTerminal C
HasProducts→HasTerminal {C = C} record { Π′ = Π }
= let P = Π {I = ⊥} λ() in
record
{ ⊤ = Product.prod P
; isTerminal = Build.nullaryProduct-Terminal C P
}
record HasBinaryProducts {lo la l≈} (C : Category lo la l≈)
: Set (lo ⊔ la ⊔ l≈)
where
private module Bld = Build C
open Category C
open Iso.Build C
open ≈-Reasoning
infixr 2 _×_ _×′_ ⟨_×_⟩ ⟨_,_⟩
field
_×′_ : ∀ A B → BinaryProduct C A B
_×_ : Obj → Obj → Obj
A × B = (A ×′ B) ᴼ
projl : ∀ {A B} → A × B ⇒ A
projl {A} {B} = Product.proj (A ×′ B) true
projr : ∀ {A B} → A × B ⇒ B
projr {A} {B} = Product.proj (A ×′ B) false
⟨_,_⟩ : ∀ {A B Z} → Z ⇒ A → Z ⇒ B → Z ⇒ A × B
⟨_,_⟩ {A} {B} f g
= Bld.factorizer (A ×′ B) (Bool-elim f g)
⟨_×_⟩ : ∀ {A B A′ B′} → A ⇒ A′ → B ⇒ B′ → A × B ⇒ A′ × B′
⟨_×_⟩ {A} {B} {A′} {B′} f g
= Bld.times (A ×′ B) (A′ ×′ B′) (Bool-elim f g)
first : ∀ {A A′ B} → A ⇒ A′ → A × B ⇒ A′ × B
first f = ⟨ f × id ⟩
second : ∀ {A B B′} → B ⇒ B′ → A × B ⇒ A × B′
second f = ⟨ id × f ⟩
swap : ∀ {A B} → A × B ⇒ B × A
swap = ⟨ projr , projl ⟩
⟨,⟩-resp : ∀ {A B Z} {f f′ : Z ⇒ A} {g g′ : Z ⇒ B}
→ f ≈ f′
→ g ≈ g′
→ ⟨ f , g ⟩ ≈ ⟨ f′ , g′ ⟩
⟨,⟩-resp {A} {B} f≈f′ g≈g′
= Bld.factorizer-resp (A ×′ B) (Bool-elim f≈f′ g≈g′)
⟨,⟩-projl : ∀ {A B Z} {f : Z ⇒ A} {g : Z ⇒ B} → projl ∘ ⟨ f , g ⟩ ≈ f
⟨,⟩-projl {A} {B} = Bld.factorizer-proj (A ×′ B)
⟨,⟩-projr : ∀ {A B Z} {f : Z ⇒ A} {g : Z ⇒ B} → projr ∘ ⟨ f , g ⟩ ≈ g
⟨,⟩-projr {A} {B} = Bld.factorizer-proj (A ×′ B)
⟨,⟩-unique : ∀ {A B Z} {f : Z ⇒ A} {g : Z ⇒ B} {u}
→ f ≈ projl ∘ u
→ g ≈ projr ∘ u
→ ⟨ f , g ⟩ ≈ u
⟨,⟩-unique {A} {B} eql eqr
= Bld.factorizer-unique (A ×′ B) _ (Bool-elim eql eqr)
⟨,⟩-∘ : ∀ {A B Y Z} {f : Y ⇒ Z} {g : Z ⇒ A} {h : Z ⇒ B}
→ ⟨ g , h ⟩ ∘ f ≈ ⟨ g ∘ f , h ∘ f ⟩
⟨,⟩-∘ {A} {B} {Y} {Z} {f} {g} {h}
= begin
⟨ g , h ⟩ ∘ f
≈⟨ Bld.factorizer-∘ (A ×′ B) ⟩
Bld.factorizer (A ×′ B)
(λ i → Bool-elim {A = λ i → Z ⇒ Bool-elim A B i} g h i ∘ f)
≈⟨ Bld.factorizer-resp (A ×′ B) (Bool-elim ≈.refl ≈.refl) ⟩
⟨ g ∘ f , h ∘ f ⟩
∎
⟨,⟩-id : ∀ {A B} → ⟨ projl , projr ⟩ ≈ id {A × B}
⟨,⟩-id {A} {B} = ⟨,⟩-unique (≈.sym id-r) (≈.sym id-r)
⟨×⟩-resp : ∀ {A A′ B B′} {f f′ : A ⇒ A′} {g g′ : B ⇒ B′}
→ f ≈ f′
→ g ≈ g′
→ ⟨ f × g ⟩ ≈ ⟨ f′ × g′ ⟩
⟨×⟩-resp {A} {A′} {B} {B′} f≈f′ g≈g′
= Bld.times-resp (A ×′ B) (A′ ×′ B′) (Bool-elim f≈f′ g≈g′)
⟨×⟩-projl : ∀ {A A′ B B′} {f : A ⇒ A′} {g : B ⇒ B′}
→ projl ∘ ⟨ f × g ⟩ ≈ f ∘ projl
⟨×⟩-projl {A} {A′} {B} {B′} = Bld.times-proj (A ×′ B) (A′ ×′ B′)
⟨×⟩-projr : ∀ {A A′ B B′} {f : A ⇒ A′} {g : B ⇒ B′}
→ projr ∘ ⟨ f × g ⟩ ≈ g ∘ projr
⟨×⟩-projr {A} {A′} {B} {B′} = Bld.times-proj (A ×′ B) (A′ ×′ B′)
⟨×⟩-id : ∀ {A B} → ⟨ id {A} × id {B} ⟩ ≈ id
⟨×⟩-id {A} {B} = Bld.factorizer-unique (A ×′ B) id
(Bool-elim (≈.trans id-l (≈.sym id-r)) (≈.trans id-l (≈.sym id-r)))
⟨×⟩-∘ : ∀ {A A′ A″ B B′ B″}
→ {f : A′ ⇒ A″} {f′ : A ⇒ A′} {g : B′ ⇒ B″} {g′ : B ⇒ B′}
→ ⟨ f × g ⟩ ∘ ⟨ f′ × g′ ⟩ ≈ ⟨ f ∘ f′ × g ∘ g′ ⟩
⟨×⟩-∘ {A} {A′} {A″} {B} {B′} {B″} {f} {f′} {g} {g′} = ≈.trans
(Bld.times-∘ (A ×′ B) (A′ ×′ B′) (A″ ×′ B″))
(Bld.times-resp (A ×′ B) (A″ ×′ B″) (Bool-elim ≈.refl ≈.refl))
⟨×⟩-⟨,⟩ : ∀ {A B C B′ C′} {f : A ⇒ B} {g : A ⇒ C} {f′ : B ⇒ B′} {g′ : C ⇒ C′}
→ ⟨ f′ × g′ ⟩ ∘ ⟨ f , g ⟩ ≈ ⟨ f′ ∘ f , g′ ∘ g ⟩
⟨×⟩-⟨,⟩ {A} {B} {C} {B′} {C′} = ≈.trans
(Bld.times-factorizer (B ×′ C) (B′ ×′ C′))
(Bld.factorizer-resp (B′ ×′ C′) (Bool-elim ≈.refl ≈.refl))
×-resp-≅ : ∀ {A A′ B B′}
→ A ≅ A′
→ B ≅ B′
→ (A × B) ≅ (A′ × B′)
×-resp-≅ {A} {A′} {B} {B′} A≅A′ B≅B′
= Bld.Product-resp-≅ (Bool-elim A≅A′ B≅B′) (A ×′ B) (A′ ×′ B′)
-- The following is conceptually trivial, but we have to dig quite deep to
-- avoid level-related nonsense.
HasProducts→HasBinaryProducts : ∀ {lp lo la l≈} {C : Category lo la l≈}
→ HasProducts lp C
→ HasBinaryProducts C
HasProducts→HasBinaryProducts {lp} {C = C} record { Π′ = Π }
= record { _×′_ = _×_ }
where
open Category C
open Unique.Build C
open Product using (proj)
open ∃!′ using (arr ; prop ; unique)
_×_ : ∀ A B → Build.BinaryProduct C A B
A × B = record
{ prod = prod′
; proj = proj′
; isProduct = isProduct′
}
where
O : Lift lp Bool → _
O (lift true) = A
O (lift false) = B
prod′ = Product.prod (Π O)
proj′ = Bool-elim (proj (Π O) (lift true)) (proj (Π O) (lift false))
isProduct′ : IsProduct C (Bool-elim A B) prod′ proj′
isProduct′ {X} x = record
{ arr = arr′ ⃗
; prop = Bool-elim (prop arr′ (lift true)) (prop arr′ (lift false))
; unique = λ eq → unique arr′
(λ { (lift true) → eq true ; (lift false) → eq false})
}
where
arr′ = Product.isProduct (Π O)
λ { (lift true) → x true ; (lift false) → x false}
record HasFiniteProducts {lo la l≈} (Cat : Category lo la l≈)
: Set (lo ⊔ la ⊔ l≈)
where
field
{{hasTerminal}} : HasTerminal Cat
{{hasBinaryProducts}} : HasBinaryProducts Cat
open HasTerminal hasTerminal public
open HasBinaryProducts hasBinaryProducts public
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈}
{D : Category lo′ la′ l≈′}
where
open Category C
open Functor
PreservesBinaryProducts : (F : Functor C D) → Set _
PreservesBinaryProducts F
= ∀ {A B A×B} {projl : A×B ⇒ A} {projr : A×B ⇒ B}
→ IsBinaryProduct C A×B projl projr
→ IsBinaryProduct D (fobj F A×B) (fmap F projl) (fmap F projr)
PreservesProducts : ∀ {i} (I : Set i) (F : Functor C D) → Set _
PreservesProducts I F
= ∀ {O : I → Obj} {P} {proj : ∀ i → P ⇒ O i}
→ IsProduct C O P proj
→ IsProduct D (λ i → fobj F (O i)) (fobj F P) (λ i → fmap F (proj i))
| {
"alphanum_fraction": 0.4769933715,
"avg_line_length": 29.2086466165,
"ext": "agda",
"hexsha": "9ee9f44a71c592666f66ce2f48975e8118b195ee",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Constructions/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Constructions/Product.agda",
"max_line_length": 82,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Constructions/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 6705,
"size": 15539
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Abstract.Types
module LibraBFT.Abstract.BFT where
-- This is a utility function to make it easy to provide the bft-assumption
-- for the abstract EpochConfig by by assuming that at most bizF members are byzantine
-- and that authorsN ≥ suc (3 * bizF) and that a list of Members is a quorum if it
-- contains at least authorsN ∸ bizF distinct Members.
| {
"alphanum_fraction": 0.7679882526,
"avg_line_length": 40.0588235294,
"ext": "agda",
"hexsha": "d7edbe14f1a245462ed9754909c797e7df8f1e7c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_forks_repo_path": "LibraBFT/Abstract/BFT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_issues_repo_path": "LibraBFT/Abstract/BFT.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_stars_repo_path": "LibraBFT/Abstract/BFT.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 180,
"size": 681
} |
module Luau.Syntax.ToString where
open import Luau.Syntax using (Block; Stat; Expr; nil; var; addr; _$_; function⟨_⟩_end; return; function_⟨_⟩_end ;local_←_; _∙_; done; block_is_end)
open import FFI.Data.String using (String; _++_)
open import Luau.Addr.ToString using (addrToString)
open import Luau.Var.ToString using (varToString)
exprToString′ : String → Expr → String
statToString′ : String → Stat → String
blockToString′ : String → Block → String
exprToString′ lb nil =
"nil"
exprToString′ lb (addr a) =
addrToString(a)
exprToString′ lb (var x) =
varToString(x)
exprToString′ lb (M $ N) =
(exprToString′ lb M) ++ "(" ++ (exprToString′ lb N) ++ ")"
exprToString′ lb (function⟨ x ⟩ B end) =
"function(" ++ x ++ ")" ++ lb ++
" " ++ (blockToString′ (lb ++ " ") B) ++ lb ++
"end"
exprToString′ lb (block b is B end) =
"(function " ++ b ++ "()" ++ lb ++
" " ++ (blockToString′ (lb ++ " ") B) ++ lb ++
"end)()"
statToString′ lb (function f ⟨ x ⟩ B end) =
"local function " ++ f ++ "(" ++ x ++ ")" ++ lb ++
" " ++ (blockToString′ (lb ++ " ") B) ++ lb ++
"end"
statToString′ lb (local x ← M) =
"local " ++ x ++ " = " ++ (exprToString′ lb M)
statToString′ lb (return M) =
"return " ++ (exprToString′ lb M)
blockToString′ lb (S ∙ done) = statToString′ lb S
blockToString′ lb (S ∙ B) = statToString′ lb S ++ lb ++ blockToString′ lb B
blockToString′ lb (done) = ""
exprToString : Expr → String
exprToString = exprToString′ "\n"
statToString : Stat → String
statToString = statToString′ "\n"
blockToString : Block → String
blockToString = blockToString′ "\n"
| {
"alphanum_fraction": 0.6188087774,
"avg_line_length": 31.9,
"ext": "agda",
"hexsha": "afec09352b0e393e61f78596daf9b5dc1a28eb77",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FreakingBarbarians/luau",
"max_forks_repo_path": "prototyping/Luau/Syntax/ToString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "FreakingBarbarians/luau",
"max_issues_repo_path": "prototyping/Luau/Syntax/ToString.agda",
"max_line_length": 148,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FreakingBarbarians/luau",
"max_stars_repo_path": "prototyping/Luau/Syntax/ToString.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z",
"num_tokens": 499,
"size": 1595
} |
-- This module is responsible for adding the missing scope information to the parse tree.
module ScopeParseTree where
open import ParseTree
open import Data.Empty
open import ScopeState
open import Data.List hiding (_++_)
open import Data.Product hiding (map)
open import Data.Fin
open import Data.Nat
open import Data.Sum
open import Data.String
open import Data.Bool
open import AgdaHelperFunctions
scopeSignature : TypeSignature -> ScopeType -> ScopeState TypeSignature
scopeExpr : Expr -> ScopeState Expr
scopeExpr (ident identifier₁) = do
-- first try to find identifier among already declared (simplification for constructor), then assume new declaration (simplification for parameter or out-of-file declaration)
inj₂ r <- try $ fillInIdentifier identifier₁
where _ -> do x <- addIdentifier identifier₁
return $ ident x
return $ ident r
scopeExpr (functionApp e e₁ {b} ) = do
r1 <- scopeExpr e
r2 <- scopeExpr e₁
return $ functionApp r1 r2 {b}
scopeExpr (namedArgument arg {b} {bef} {aft}) = do
x <- scopeSignature arg addVariableToType
return $ namedArgument x {b}{bef}{aft}
scopeExpr x = return x
scopeSignature (typeSignature funcName funcType) scopeT = do
newType <- saveAndReturnToScope $ scopeExpr funcType
addScope scopeT
newId <- addIdentifier funcName
return $ typeSignature newId newType
scopePragma : Pragma -> ScopeState Pragma
scopePragma (builtin concept definition) = do
x <- fillInIdentifier definition
return $ builtin concept x
scopePragma x = return x
scopeParseTree : ParseTree -> ScopeState ParseTree
scopeParseTree (signature signature₁ range₁) = do
x <- scopeSignature signature₁ addFuncToModule
return $ signature x range₁
scopeParseTree (functionDefinition definitionOf params body range₁) = do
newId <- fillInIdentifier definitionOf
x <- saveAndReturnToScope $ do
addScope funcDef
newParams <- mapState scopeExpr params
newBody <- scopeExpr body
return $ functionDefinition newId newParams newBody range₁
return x
scopeParseTree
(dataStructure dataName parameters indexInfo constructors range₁ {comments}) = do
addScope $ moduleDef dataName
newDataName <- addIdentifier dataName
( newParams , newIndex) , newCons <- saveAndReturnToScope $ do
newParams <- mapState (λ x -> scopeSignature x addVariableToType) parameters
newIndex <- scopeExpr indexInfo
newCons <- mapState (λ x -> scopeSignature x addFuncToModule) constructors
return ((newParams , newIndex) , newCons)
r <- mapState addContentReferenceToModuleTop newCons
return $ dataStructure newDataName newParams newIndex newCons range₁ {comments}
scopeParseTree (moduleName moduleName₁ range₁) = do
newMod <- addIdentifier moduleName₁
addScope $ moduleDef moduleName₁
return $ moduleName newMod range₁
scopeParseTree (pragma pragma₁ range₁) = do
x <- scopePragma pragma₁
return $ pragma x range₁
scopeParseTree x = return x
scopeParseTreeList : List ParseTree -> ScopeState (List ParseTree)
scopeParseTreeList program = do
--TODO: fix sloppy workaround
put newEnv
addIdentifier (identifier "Set" (λ _ -> before) 0 0 {true}{[]} {[]})
mapState scopeParseTree program
| {
"alphanum_fraction": 0.7467811159,
"avg_line_length": 38.8333333333,
"ext": "agda",
"hexsha": "5e57ab1dfa0c39d8f88f8470b98336e7dfb68764",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/ScopeParseTree.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/ScopeParseTree.agda",
"max_line_length": 176,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/ScopeParseTree.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 805,
"size": 3262
} |
-- Andreas, 2017-10-17, issue #2807
--
-- Refining with an extended lambda gave internal error.
-- Seemed to be triggered only when giving resulted in an error.
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v scope.extendedLambda:60 #-}
-- {-# OPTIONS -v impossible:10 #-}
data ⊥ : Set where
actuallyNotEmpty : ⊥
data D : Set where
c : ⊥ → D
test : D → ⊥
test = {! λ{ (c ()) }!} -- C-c C-r
-- WAS: internal error in ConcreteToAbstract (insertApp)
--
-- Expected:
-- Succeed with unsolved constraints and metas.
| {
"alphanum_fraction": 0.6440677966,
"avg_line_length": 22.125,
"ext": "agda",
"hexsha": "921edb45906739dc0956aa04a56d6e5d4b52637c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2807.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2807.agda",
"max_line_length": 64,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2807.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 156,
"size": 531
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
open import HoTT.Identity.Pi
open import HoTT.Identity.Sigma
module HoTT.Exercises.Chapter2.Exercise11 where
private
variable
i j k : Level
A B C D : 𝒰 i
pullback : (A : 𝒰 i) (B : 𝒰 j) → (A → C) → (B → C) → 𝒰 _
pullback A B ac bc = Σ[ a ∶ A ] Σ[ b ∶ B ] (ac a == bc b)
module Square (ab : A → B) (ac : A → C) (bd : B → D) (cd : C → D)
where
IsCommutative = bd ∘ ab ~ cd ∘ ac
module Commutative (comm : IsCommutative)
where
inducedMap : {X : 𝒰 i} → (X → A) → pullback (X → B) (X → C) (bd ∘_) (cd ∘_)
inducedMap xa = ab ∘ xa , ac ∘ xa , funext (comm ∘ xa)
IsPullback : ∀ {i} → 𝒰 _
IsPullback {i} = (X : 𝒰 i) → isequiv (inducedMap {X = X})
open Commutative public
module _ {ac : A → C} {bc : B → C}
where
P = pullback A B ac bc
open Square.Commutative {A = P} pr₁ (pr₁ ∘ pr₂) ac bc (pr₂ ∘ pr₂)
prop : IsPullback {i}
prop X = qinv→isequiv (g , η , ε)
where
f = inducedMap
g : pullback (X → A) (X → B) (ac ∘_) (bc ∘_) → (X → P)
g (h' , k' , p) x = h' x , k' x , happly p x
η : g ∘ f ~ id
η xp = funext λ x → pair⁼ (refl , pair⁼ (refl ,
happly (=Π-β (pr₂ ∘ pr₂ ∘ xp)) x))
ε : f ∘ g ~ id
ε (_ , _ , p) = pair⁼ (refl , pair⁼ (refl , =Π-η p))
| {
"alphanum_fraction": 0.5294117647,
"avg_line_length": 27.2708333333,
"ext": "agda",
"hexsha": "ab92aad811daab991869221e3098bf6f680cae00",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Exercises/Chapter2/Exercise11.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Exercises/Chapter2/Exercise11.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Exercises/Chapter2/Exercise11.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 564,
"size": 1309
} |
module Cats.Limit where
open import Level
open import Cats.Category.Base
open import Cats.Category.Cones using
(Cone ; Cones ; HasObj-Cone ; HasArrow-⇒ ; cone-iso→obj-iso ; apFunctor)
open import Cats.Functor using (Functor)
open import Cats.Util.Conv
import Cats.Category.Constructions.Terminal as Terminal
import Cats.Category.Constructions.Iso as Iso
module _ {lo la l≈ lo′ la′ l≈′}
{J : Category lo la l≈}
{Z : Category lo′ la′ l≈′}
where
IsLimit : {D : Functor J Z} → Cone D → Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′)
IsLimit {D} = Terminal.Build.IsTerminal (Cones D)
record Limit (D : Functor J Z) : Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′) where
field
cone : Cone D
isLimit : IsLimit cone
instance
HasObj-Limit : ∀ D → HasObj (Limit D) _ _ _
HasObj-Limit D = record { Cat = Cones D ; _ᴼ = Limit.cone }
module _ {D : Functor J Z} where
open Iso.Build (Cones D) using (_≅_)
open Iso.Build Z using () renaming (_≅_ to _≅Z_)
open Limit using (isLimit)
unique : (l m : Limit D) → l ᴼ ≅ m ᴼ
unique l m = Terminal.Build.terminal-unique (Cones D) (isLimit l) (isLimit m)
obj-unique : (l m : Limit D) → l ᴼ ᴼ ≅Z m ᴼ ᴼ
obj-unique l m = cone-iso→obj-iso _ (unique l m)
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈}
{D : Category lo′ la′ l≈′}
where
preservesLimits : (lo″ la″ l≈″ : Level) → (F : Functor C D) → Set _
preservesLimits lo″ la″ l≈″ F
= {J : Category lo″ la″ l≈″}
→ {D : Functor J C}
→ {c : Cone D}
→ IsLimit c
→ IsLimit (apFunctor F c)
| {
"alphanum_fraction": 0.6053639847,
"avg_line_length": 25.2580645161,
"ext": "agda",
"hexsha": "175f925712352af7b8f789cfea88d0e00f9f60b8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Limit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Limit.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Limit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 571,
"size": 1566
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module groups.CoefficientExtensionality {i} {A : Type i} where
module _ (dec : has-dec-eq A) where
Word-coef : Word A → (A → ℤ)
Word-coef nil a = 0
Word-coef (inl a' :: w) a with dec a' a
Word-coef (inl a' :: w) a | inl a'=a = succ $ Word-coef w a
Word-coef (inl a' :: w) a | inr a'≠a = Word-coef w a
Word-coef (inr a' :: w) a with dec a' a
Word-coef (inr a' :: w) a | inl a'=a = pred $ Word-coef w a
Word-coef (inr a' :: w) a | inr a'≠a = Word-coef w a
abstract
Word-coef-++ : ∀ w₁ w₂ a → Word-coef (w₁ ++ w₂) a
== Word-coef w₁ a ℤ+ Word-coef w₂ a
Word-coef-++ nil w₂ a = idp
Word-coef-++ (inl a' :: w₁) w₂ a with dec a' a
Word-coef-++ (inl a' :: w₁) w₂ a | inl a'=a =
ap succ (Word-coef-++ w₁ w₂ a)
∙ ! (succ-+ (Word-coef w₁ a) (Word-coef w₂ a))
Word-coef-++ (inl a' :: w₁) w₂ a | inr a'≠a = Word-coef-++ w₁ w₂ a
Word-coef-++ (inr a' :: w₁) w₂ a with dec a' a
Word-coef-++ (inr a' :: w₁) w₂ a | inl a'=a =
ap pred (Word-coef-++ w₁ w₂ a)
∙ ! (pred-+ (Word-coef w₁ a) (Word-coef w₂ a))
Word-coef-++ (inr a' :: w₁) w₂ a | inr a'≠a = Word-coef-++ w₁ w₂ a
Word-coef-flip : ∀ w a → Word-coef (Word-flip w) a == ℤ~ (Word-coef w a)
Word-coef-flip nil a = idp
Word-coef-flip (inl a' :: w) a with dec a' a
Word-coef-flip (inl a' :: w) a | inl a'=a =
ap pred (Word-coef-flip w a) ∙ ! (ℤ~-succ (Word-coef w a))
Word-coef-flip (inl a' :: w) a | inr a'≠a = Word-coef-flip w a
Word-coef-flip (inr a' :: w) a with dec a' a
Word-coef-flip (inr a' :: w) a | inl a'=a =
ap succ (Word-coef-flip w a) ∙ ! (ℤ~-pred (Word-coef w a))
Word-coef-flip (inr a' :: w) a | inr a'≠a = Word-coef-flip w a
private
abstract
FormalSum-coef-rel : {w₁ w₂ : Word A} → FormalSumRel w₁ w₂
→ ∀ a → Word-coef w₁ a == Word-coef w₂ a
FormalSum-coef-rel (fsr-refl p) a = ap (λ w → Word-coef w a) p
FormalSum-coef-rel (fsr-trans fwr₁ fwr₂) a = (FormalSum-coef-rel fwr₁ a) ∙ (FormalSum-coef-rel fwr₂ a)
FormalSum-coef-rel (fsr-sym fsr) a = ! $ FormalSum-coef-rel fsr a
FormalSum-coef-rel (fsr-cons x fwr) a =
Word-coef-++ (x :: nil) _ a
∙ ap (Word-coef (x :: nil) a ℤ+_) (FormalSum-coef-rel fwr a)
∙ ! (Word-coef-++ (x :: nil) _ a)
FormalSum-coef-rel (fsr-swap x y w) a =
Word-coef-++ (x :: y :: nil) _ a
∙ ap (_ℤ+ Word-coef w a)
( Word-coef-++ (x :: nil) (y :: nil) a
∙ ℤ+-comm (Word-coef (x :: nil) a) (Word-coef (y :: nil) a)
∙ ! (Word-coef-++ (y :: nil) (x :: nil) a))
∙ ! (Word-coef-++ (y :: x :: nil) _ a)
FormalSum-coef-rel (fsr-flip x w) a =
Word-coef-++ (x :: flip x :: nil) w a
∙ ap (_ℤ+ Word-coef w a)
( Word-coef-++ (x :: nil) (flip x :: nil) a
∙ ap (Word-coef (x :: nil) a ℤ+_) (Word-coef-flip (x :: nil) a)
∙ ℤ~-inv-r (Word-coef (x :: nil) a) )
∙ ℤ+-unit-l (Word-coef w a)
FormalSum-coef : FormalSum A → (A → ℤ)
FormalSum-coef = FormalSum-rec (→-is-set ℤ-is-set) Word-coef (λ r → λ= $ FormalSum-coef-rel r)
-- Theorem : if coef w a == 0 then FormalSumRel w nil
private
exp : A → ℤ → Word A
exp a (pos 0) = nil
exp a (pos (S n)) = inl a :: exp a (pos n)
exp a (negsucc 0) = inr a :: nil
exp a (negsucc (S n)) = inr a :: exp a (negsucc n)
abstract
exp-succ : ∀ a z → FormalSumRel (inl a :: exp a z) (exp a (succ z))
exp-succ a (pos _) = fsr-refl idp
exp-succ a (negsucc 0) = fsr-flip (inl a) nil
exp-succ a (negsucc (S n)) = fsr-flip (inl a) (exp a (negsucc n))
exp-pred : ∀ a z → FormalSumRel (inr a :: exp a z) (exp a (pred z))
exp-pred a (pos 0) = fsr-refl idp
exp-pred a (pos (S n)) = fsr-flip (inr a) (exp a (pos n))
exp-pred a (negsucc _) = fsr-refl idp
Word-coef-inl-eq : ∀ {a b} (p : b == a) w
→ Word-coef (inl b :: w) a == succ (Word-coef w a)
Word-coef-inl-eq {a} {b} p w with dec b a
Word-coef-inl-eq {a} {b} p w | inl _ = idp
Word-coef-inl-eq {a} {b} p w | inr ¬p = ⊥-rec (¬p p)
Word-coef-inr-eq : ∀ {a b} (p : b == a) w
→ Word-coef (inr b :: w) a == pred (Word-coef w a)
Word-coef-inr-eq {a} {b} p w with dec b a
Word-coef-inr-eq {a} {b} p w | inl _ = idp
Word-coef-inr-eq {a} {b} p w | inr ¬p = ⊥-rec (¬p p)
Word-coef-inl-neq : ∀ {a b} (p : b ≠ a) w
→ Word-coef (inl b :: w) a == Word-coef w a
Word-coef-inl-neq {a} {b} ¬p w with dec b a
Word-coef-inl-neq {a} {b} ¬p w | inl p = ⊥-rec (¬p p)
Word-coef-inl-neq {a} {b} ¬p w | inr _ = idp
Word-coef-inr-neq : ∀ {a b} (p : b ≠ a) w
→ Word-coef (inr b :: w) a == Word-coef w a
Word-coef-inr-neq {a} {b} ¬p w with dec b a
Word-coef-inr-neq {a} {b} ¬p w | inl p = ⊥-rec (¬p p)
Word-coef-inr-neq {a} {b} ¬p w | inr _ = idp
-- TODO maybe there is a better way to prove the final theorem?
-- Here we are collecting all elements [inl a] and [inr a], and recurse on the rest.
-- The [right-shorter] field makes sure that it is terminating.
record CollectSplitIH (a : A) {n : ℕ} (w : Word A) (len : length w == n) : Type i where
field
left-exponent : ℤ
left-captures-all : Word-coef w a == left-exponent
right-list : Word A
right-shorter : length right-list ≤ n
fsr : FormalSumRel w (exp a left-exponent ++ right-list)
abstract
collect-split : ∀ a {n} w (len=n : length w == n) → CollectSplitIH a w len=n
collect-split a nil idp = record {
left-exponent = 0;
left-captures-all = idp;
right-list = nil;
right-shorter = inl idp;
fsr = fsr-refl idp}
collect-split a (inl b :: w) idp with dec b a
... | inl b=a = record {
left-exponent = succ left-exponent;
left-captures-all = Word-coef-inl-eq b=a w ∙ ap succ left-captures-all;
right-list = right-list;
right-shorter = ≤-trans right-shorter (inr ltS);
fsr = fsr-trans (fsr-refl (ap (λ a → inl a :: w) b=a)) $
fsr-trans (fsr-cons (inl a) fsr) $
(FormalSumRel-cong-++-l (exp-succ a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
... | inr b≠a = record {
left-exponent = left-exponent;
left-captures-all = Word-coef-inl-neq b≠a w ∙ left-captures-all;
right-list = inl b :: right-list;
right-shorter = ≤-ap-S right-shorter;
fsr = fsr-trans (fsr-cons (inl b) fsr) $
fsr-sym (FormalSumRel-swap1 (inl b) (exp a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
collect-split a (inr b :: w) idp with dec b a
... | inl b=a = record {
left-exponent = pred left-exponent;
left-captures-all = Word-coef-inr-eq b=a w ∙ ap pred left-captures-all;
right-list = right-list;
right-shorter = ≤-trans right-shorter (inr ltS);
fsr = fsr-trans (fsr-refl (ap (λ a → inr a :: w) b=a)) $
fsr-trans (fsr-cons (inr a) fsr) $
(FormalSumRel-cong-++-l (exp-pred a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
... | inr b≠a = record {
left-exponent = left-exponent;
left-captures-all = Word-coef-inr-neq b≠a w ∙ left-captures-all;
right-list = inr b :: right-list;
right-shorter = ≤-ap-S right-shorter;
fsr = fsr-trans (fsr-cons (inr b) fsr) $
fsr-sym (FormalSumRel-swap1 (inr b) (exp a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
-- We simulate strong induction by recursing on both [m] and [n≤m].
-- We could develop a general framework for strong induction but I am lazy. -Favonia
zero-coef-is-ident' : ∀ {m n} (n≤m : n ≤ m) (w : Word A) (len : length w == n)
→ (∀ a → Word-coef w a == 0) → FormalSumRel w nil
zero-coef-is-ident' (inr ltS) w len zero-coef
= zero-coef-is-ident' (inl idp) w len zero-coef
zero-coef-is-ident' (inr (ltSR lt)) w len zero-coef
= zero-coef-is-ident' (inr lt) w len zero-coef
zero-coef-is-ident' {m = O} (inl idp) nil _ _ = fsr-refl idp
zero-coef-is-ident' {m = O} (inl idp) (_ :: _) len _ = ⊥-rec $ ℕ-S≠O _ len
zero-coef-is-ident' {m = S m} (inl idp) nil len _ = ⊥-rec $ ℕ-S≠O _ (! len)
zero-coef-is-ident' {m = S m} (inl idp) (inl a :: w) len zero-coef =
fsr-trans whole-is-right (zero-coef-is-ident' right-shorter right-list idp right-zero-coef)
where
open CollectSplitIH (collect-split a w (ℕ-S-is-inj _ _ len))
left-exponent-is-minus-one : left-exponent == -1
left-exponent-is-minus-one = succ-is-inj left-exponent -1 $
ap succ (! left-captures-all) ∙ ! (Word-coef-inl-eq idp w) ∙ zero-coef a
whole-is-right : FormalSumRel (inl a :: w) right-list
whole-is-right =
fsr-trans (fsr-cons (inl a) fsr) $
fsr-trans (fsr-refl (ap (λ e → inl a :: exp a e ++ right-list) left-exponent-is-minus-one)) $
fsr-flip (inl a) right-list
right-zero-coef : ∀ a' → Word-coef right-list a' == 0
right-zero-coef a' = ! (FormalSum-coef-rel whole-is-right a') ∙ zero-coef a'
zero-coef-is-ident' {m = S m} (inl idp) (inr a :: w) len zero-coef =
fsr-trans whole-is-right (zero-coef-is-ident' right-shorter right-list idp right-zero-coef)
where
open CollectSplitIH (collect-split a w (ℕ-S-is-inj _ _ len))
left-exponent-is-one : left-exponent == 1
left-exponent-is-one = pred-is-inj left-exponent 1 $
ap pred (! left-captures-all) ∙ ! (Word-coef-inr-eq idp w) ∙ zero-coef a
whole-is-right : FormalSumRel (inr a :: w) right-list
whole-is-right =
fsr-trans (fsr-cons (inr a) fsr) $
fsr-trans (fsr-refl (ap (λ e → inr a :: exp a e ++ right-list) left-exponent-is-one)) $
fsr-flip (inr a) right-list
right-zero-coef : ∀ a' → Word-coef right-list a' == 0
right-zero-coef a' = ! (FormalSum-coef-rel whole-is-right a') ∙ zero-coef a'
zero-coef-is-ident : ∀ (w : Word A)
→ (∀ a → Word-coef w a == 0)
→ FormalSumRel w nil
zero-coef-is-ident w = zero-coef-is-ident' (inl idp) w idp
abstract
FormalSum-coef-ext' : ∀ w₁ w₂
→ (∀ a → Word-coef w₁ a == Word-coef w₂ a)
→ fs[ w₁ ] == fs[ w₂ ]
FormalSum-coef-ext' w₁ w₂ same-coef = G.inv-is-inj fs[ w₁ ] fs[ w₂ ] $
G.inv-unique-l (G.inv fs[ w₂ ]) fs[ w₁ ] $ quot-rel $
zero-coef-is-ident (Word-flip w₂ ++ w₁)
(λ a → Word-coef-++ (Word-flip w₂) w₁ a
∙ ap2 _ℤ+_ (Word-coef-flip w₂ a) (same-coef a)
∙ ℤ~-inv-l (Word-coef w₂ a))
where module G = FreeAbGroup A
FormalSum-coef-ext : ∀ fs₁ fs₂
→ (∀ a → FormalSum-coef fs₁ a == FormalSum-coef fs₂ a)
→ fs₁ == fs₂
FormalSum-coef-ext = FormalSum-elim
(λ fs₁ → Π-is-set λ fs₂ → →-is-set $ =-preserves-set FormalSum-is-set)
(λ w₁ → FormalSum-elim
(λ fs₂ → →-is-set $ =-preserves-set FormalSum-is-set)
(λ w₂ → FormalSum-coef-ext' w₁ w₂)
(λ _ → prop-has-all-paths-↓ (→-is-prop $ FormalSum-is-set _ _)))
(λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → →-is-prop $ FormalSum-is-set _ _))
has-finite-support : (A → ℤ) → Type i
has-finite-support f = Σ (FormalSum A) λ fs → ∀ a → f a == FormalSum-coef fs a
module _ {dec : has-dec-eq A} where
abstract
has-finite-support-is-prop : ∀ f → is-prop (has-finite-support dec f)
has-finite-support-is-prop f = all-paths-is-prop
λ{(fs₁ , match₁) (fs₂ , match₂) → pair=
(FormalSum-coef-ext dec fs₁ fs₂ λ a → ! (match₁ a) ∙ match₂ a)
(prop-has-all-paths-↓ $ Π-is-prop λ _ → ℤ-is-set _ _)}
| {
"alphanum_fraction": 0.544841369,
"avg_line_length": 46.91015625,
"ext": "agda",
"hexsha": "eef123f3f5c19241dd4f401f6b14a3ad4e2a3fec",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/groups/CoefficientExtensionality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/groups/CoefficientExtensionality.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/groups/CoefficientExtensionality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4433,
"size": 12009
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NConnected
open import lib.types.Bool
open import lib.types.Nat
open import lib.types.TLevel
open import lib.types.Suspension
module lib.types.IteratedSuspension where
⊙Susp^ : ∀ {i} (n : ℕ) → Ptd i → Ptd i
⊙Susp^ O X = X
⊙Susp^ (S n) X = ⊙Susp (⊙Susp^ n X)
abstract
⊙Susp^-conn : ∀ {i} (n : ℕ) {X : Ptd i} {m : ℕ₋₂}
{{_ : is-connected m (de⊙ X)}} → is-connected (⟨ n ⟩₋₂ +2+ m) (de⊙ (⊙Susp^ n X))
⊙Susp^-conn O = ⟨⟩
⊙Susp^-conn (S n) = Susp-conn (⊙Susp^-conn n)
⊙Susp^-conn' : ∀ {i} (n : ℕ) {X : Ptd i}
{{_ : is-connected 0 (de⊙ X)}} → is-connected ⟨ n ⟩ (de⊙ (⊙Susp^ n X))
⊙Susp^-conn' O = ⟨⟩
⊙Susp^-conn' (S n) = Susp-conn (⊙Susp^-conn' n)
⊙Susp^-+ : ∀ {i} (m n : ℕ) {X : Ptd i}
→ ⊙Susp^ m (⊙Susp^ n X) == ⊙Susp^ (m + n) X
⊙Susp^-+ O n = idp
⊙Susp^-+ (S m) n = ap ⊙Susp (⊙Susp^-+ m n)
⊙Susp^-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → ⊙Susp^ n X ⊙→ ⊙Susp^ n Y
⊙Susp^-fmap O f = f
⊙Susp^-fmap (S n) f = ⊙Susp-fmap (⊙Susp^-fmap n f)
⊙Susp^-fmap-idf : ∀ {i} (n : ℕ) (X : Ptd i)
→ ⊙Susp^-fmap n (⊙idf X) == ⊙idf (⊙Susp^ n X)
⊙Susp^-fmap-idf O X = idp
⊙Susp^-fmap-idf (S n) X =
ap ⊙Susp-fmap (⊙Susp^-fmap-idf n X) ∙ ⊙Susp-fmap-idf (⊙Susp^ n X)
⊙Susp^-fmap-cst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ ⊙Susp^-fmap n (⊙cst {X = X} {Y = Y}) == ⊙cst
⊙Susp^-fmap-cst O = idp
⊙Susp^-fmap-cst (S n) = ap ⊙Susp-fmap (⊙Susp^-fmap-cst n)
∙ (⊙Susp-fmap-cst {X = ⊙Susp^ n _})
⊙Susp^-fmap-∘ : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : Y ⊙→ Z) (f : X ⊙→ Y)
→ ⊙Susp^-fmap n (g ⊙∘ f) == ⊙Susp^-fmap n g ⊙∘ ⊙Susp^-fmap n f
⊙Susp^-fmap-∘ O g f = idp
⊙Susp^-fmap-∘ (S n) g f =
ap ⊙Susp-fmap (⊙Susp^-fmap-∘ n g f)
∙ ⊙Susp-fmap-∘ (⊙Susp^-fmap n g) (⊙Susp^-fmap n f)
⊙Susp^-Susp-split-iso : ∀ {i} (n : ℕ) (X : Ptd i)
→ ⊙Susp^ (S n) X ⊙≃ ⊙Susp^ n (⊙Susp X)
⊙Susp^-Susp-split-iso O X = ⊙ide _
⊙Susp^-Susp-split-iso (S n) X = ⊙Susp-emap (⊙Susp^-Susp-split-iso n X)
⊙Sphere : (n : ℕ) → Ptd₀
⊙Sphere n = ⊙Susp^ n ⊙Bool
Sphere : (n : ℕ) → Type₀
Sphere n = de⊙ (⊙Sphere n)
abstract
instance
Sphere-conn : ∀ (n : ℕ) → is-connected ⟨ n ⟩₋₁ (Sphere n)
Sphere-conn 0 = inhab-conn true
Sphere-conn (S n) = Susp-conn (Sphere-conn n)
-- favonia: [S¹] has its own elim rules in Circle.agda.
⊙S⁰ = ⊙Sphere 0
⊙S¹ = ⊙Sphere 1
⊙S² = ⊙Sphere 2
⊙S³ = ⊙Sphere 3
S⁰ = Sphere 0
S¹ = Sphere 1
S² = Sphere 2
S³ = Sphere 3
| {
"alphanum_fraction": 0.5243264978,
"avg_line_length": 29.6071428571,
"ext": "agda",
"hexsha": "bdaf29bbc039b4ad582aea19f0b8b76f29503ff0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/IteratedSuspension.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/IteratedSuspension.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/IteratedSuspension.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1271,
"size": 2487
} |
{-
Basic theory about h-levels/n-types:
- Basic properties of isContr, isProp and isSet (definitions are in Prelude)
- Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.HLevels where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.FunExtEquiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HAEquiv using (congEquiv)
open import Cubical.Foundations.Equiv using (isoToEquiv; isPropIsEquiv; retEq; invEquiv)
open import Cubical.Foundations.Univalence using (ua; univalence)
open import Cubical.Data.Sigma using (ΣPathP; sigmaPath→pathSigma; pathSigma≡sigmaPath; _Σ≡T_)
open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-comm)
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y : A
n : ℕ
hProp : Type (ℓ-suc ℓ)
hProp {ℓ} = Σ (Type ℓ) isProp
isOfHLevel : ℕ → Type ℓ → Type ℓ
isOfHLevel 0 A = isContr A
isOfHLevel 1 A = isProp A
isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y)
isOfHLevelDep : ℕ → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
isOfHLevelDep 0 {A = A} B = {a : A} → B a
isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1
isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1)
isOfHLevel→isOfHLevelDep : {n : ℕ} → {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B
isOfHLevel→isOfHLevelDep {n = 0} {A = A} {B} h {a} = h a .fst
isOfHLevel→isOfHLevelDep {n = 1} {A = A} {B} h = λ b0 b1 p → isProp→PathP h p b0 b1
isOfHLevel→isOfHLevelDep {n = suc (suc n)} {A = A} {B} h {a0} {a1} b0 b1 =
isOfHLevel→isOfHLevelDep {n = suc n}
{B = λ p → PathP (λ i → B (p i)) b0 b1} λ p → helper a1 p b1
where
helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) →
isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)
helper a1 p b1 = J
(λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1))
(λ _ → h _ _ _) p b1
HLevel : ℕ → Type (ℓ-suc ℓ)
HLevel {ℓ} n = Σ[ A ∈ Type ℓ ] (isOfHLevel n A)
inhProp→isContr : A → isProp A → isContr A
inhProp→isContr x h = x , h x
isPropIsProp : isProp (isProp A)
isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i
-- A retract of a contractible type is contractible
retractIsContr
: ∀ {B : Type ℓ}
→ (f : A → B) (g : B → A)
→ (h : (x : A) → g (f x) ≡ x)
→ (v : isContr B) → isContr A
retractIsContr f g h (b , p) = (g b , λ x → (cong g (p (f x))) ∙ (h x))
retractIsProp
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isProp B → isProp A
retractIsProp f g h p x y i =
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (p (f x) (f y) i))
retractIsOfHLevel
: (n : ℕ) {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isOfHLevel n B → isOfHLevel n A
retractIsOfHLevel 0 = retractIsContr
retractIsOfHLevel 1 = retractIsProp
retractIsOfHLevel (suc (suc n)) f g h ofLevel x y =
retractIsOfHLevel (suc n)
(cong f)
(λ q i →
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (q i)))
(λ p k i →
hcomp
(λ j → λ
{ (i = i0) → h x (j ∨ k)
; (i = i1) → h y (j ∨ k)
; (k = i1) → p i})
(h (p i) k))
(ofLevel (f x) (f y))
isContrSigma
: isContr A
→ ((x : A) → isContr (B x))
→ isContr (Σ[ x ∈ A ] B x)
isContrSigma {A = A} {B = B} (a , p) q =
let h : (x : A) (y : B x) → (q x) .fst ≡ y
h x y = (q x) .snd y
in (( a , q a .fst)
, ( λ x i → p (x .fst) i
, h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i))
isProp→isPropPathP : (∀ a → isProp (B a))
→ (m : x ≡ y) (g : B x) (h : B y)
→ isProp (PathP (λ i → B (m i)) g h)
isProp→isPropPathP {B = B} {x = x} isPropB m = J P d m where
P : ∀ σc → x ≡ σc → _
P _ m = ∀ g h → isProp (PathP (λ i → B (m i)) g h)
d : P x refl
d = isProp→isSet (isPropB x)
isProp→isContrPathP : (∀ a → isProp (B a))
→ (m : x ≡ y) (g : B x) (h : B y)
→ isContr (PathP (λ i → B (m i)) g h)
isProp→isContrPathP isPropB m g h =
inhProp→isContr (isProp→PathP isPropB m g h) (isProp→isPropPathP isPropB m g h)
isProp→isContr≡ : isProp A → (x y : A) → isContr (x ≡ y)
isProp→isContr≡ isPropA x y = inhProp→isContr (isPropA x y) (isProp→isSet isPropA x y)
isContrPath : isContr A → (x y : A) → isContr (x ≡ y)
isContrPath cA = isProp→isContr≡ (isContr→isProp cA)
-- Π preserves propositionality in the following sense:
propPi : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x)
propPi h f0 f1 i x = h x (f0 x) (f1 x) i
ΣProp≡
: ((x : A) → isProp (B x)) → {u v : Σ[ a ∈ A ] B a}
→ (p : u .fst ≡ v .fst) → u ≡ v
ΣProp≡ pB {u} {v} p i = (p i) , isProp→PathP pB p (u .snd) (v .snd) i
isPropSigma : isProp A → ((x : A) → isProp (B x)) → isProp (Σ[ x ∈ A ] B x)
isPropSigma pA pB t u = ΣProp≡ pB (pA (t .fst) (u .fst))
hLevelPi
: ∀ n
→ ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n ((x : A) → B x)
hLevelPi 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i
hLevelPi {B = B} 1 h f g i x = (h x) (f x) (g x) i
hLevelPi (suc (suc n)) h f g =
subst (isOfHLevel (suc n)) funExtPath (hLevelPi (suc n) λ x → h x (f x) (g x))
isSetPi : ((x : A) → isSet (B x)) → isSet ((x : A) → B x)
isSetPi Bset = hLevelPi 2 (λ a → Bset a)
isSet→isSet' : isSet A → isSet' A
isSet→isSet' {A = A} Aset {x} {y} {z} {w} p q r s
= transport (squeezeSq≡ r p q s) (Aset _ _ p (r ∙∙ q ∙∙ sym s))
isSet'→isSet : isSet' A → isSet A
isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl
squeezeCu≡
: ∀{w x y z w' x' y' z' : A}
→ {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z}
→ {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'}
→ {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'}
→ (ps : Square a p p' c) (qs : Square a q q' b)
→ (rs : Square c r r' d) (ss : Square b s s' d)
→ (f0 : Square p q r s) (f1 : Square p' q' r' s')
→ (f0 ≡ transport⁻ (λ k → Square (ps k) (qs k) (rs k) (ss k)) f1)
≡ Cube ps qs rs ss f0 f1
squeezeCu≡ ps qs rs ss f0 f1 τ
= Cube
(λ j → ps (j ∧ τ))
(λ j → qs (j ∧ τ))
(λ j → rs (j ∧ τ))
(λ j → ss (j ∧ τ))
f0
(toPathP {A = λ k → Square (ps k) (qs k) (rs k) (ss k)}
(transportTransport⁻ (λ k → Square (ps k) (qs k) (rs k) (ss k)) f1) τ)
isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A
isGroupoid→isGroupoid' Agpd ps qs rs ss f0 f1
= transport
( squeezeCu≡ (λ _ → refl) f0 f1' (λ _ → refl) (λ _ → f0 i0) (λ _ → f1' i1)
∙ transpose≡
∙ squeezeCu≡ ps qs rs ss f0 f1
) (Agpd (ps i0 i0) (ss i0 i0) (f0 i0) (f1' i0) refl rs')
where
Sq = λ k → Square (ps k) (qs k) (rs k) (ss k)
f1' = transport⁻ Sq f1
rs' = transport⁻ (λ k → Square refl (f0 k) (f1' k) refl) (λ _ → f1' i1)
transpose≡
: Cube (λ i _ → ps i0 i) f0 f1' (λ i _ → ss i0 i) refl refl
≡ Cube refl refl refl refl f0 f1'
transpose≡
= ua ((λ cu i j → cu j i)
, λ where
.equiv-proof cu
→ ((λ i j → cu j i) , refl)
, (λ{ (cu' , p) → λ k → (λ j i → p (~ k) i j) , λ τ → p (~ k ∨ τ) }))
isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A
isGroupoid'→isGroupoid Agpd' w x p q r s
= Agpd' {q = p} {r = q} {q' = p} {r' = q} refl refl refl refl r s
hLevelSuc : (n : ℕ) (A : Type ℓ) → isOfHLevel n A → isOfHLevel (suc n) A
hLevelSuc 0 A = isContr→isProp
hLevelSuc 1 A = isProp→isSet
hLevelSuc (suc (suc n)) A h a b = hLevelSuc (suc n) (a ≡ b) (h a b)
hLevelLift : (m : ℕ) (hA : isOfHLevel n A) → isOfHLevel (m + n) A
hLevelLift zero hA = hA
hLevelLift {A = A} (suc m) hA = hLevelSuc _ A (hLevelLift m hA)
isPropIsOfHLevel : (n : ℕ) (A : Type ℓ) → isProp (isOfHLevel n A)
isPropIsOfHLevel 0 A = isPropIsContr
isPropIsOfHLevel 1 A = isPropIsProp
isPropIsOfHLevel (suc (suc n)) A f g i a b =
isPropIsOfHLevel (suc n) (a ≡ b) (f a b) (g a b) i
isPropIsSet : isProp (isSet A)
isPropIsSet {A = A} = isPropIsOfHLevel 2 A
HLevel≡ : ∀ {A B : Type ℓ} {hA : isOfHLevel n A} {hB : isOfHLevel n B} →
(A ≡ B) ≡ ((A , hA) ≡ (B , hB))
HLevel≡ {n = n} {A = A} {B = B} {hA} {hB} =
isoToPath (iso intro elim intro-elim elim-intro)
where
intro : A ≡ B → (A , hA) ≡ (B , hB)
intro eq = ΣProp≡ (λ A → isPropIsOfHLevel n _) eq
elim : (A , hA) ≡ (B , hB) → A ≡ B
elim = cong fst
intro-elim : ∀ x → intro (elim x) ≡ x
intro-elim eq = cong ΣPathP (ΣProp≡ (λ e →
J (λ B e →
∀ k → (x y : PathP (λ i → isOfHLevel n (e i)) hA k) → x ≡ y)
(λ k → isProp→isSet (isPropIsOfHLevel n _) _ _) e hB) refl)
elim-intro : ∀ x → elim (intro x) ≡ x
elim-intro eq = refl
-- H-level for Σ-types
isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n (Σ A B)
isOfHLevelΣ zero h1 h2 =
let center = (fst h1 , fst (h2 (fst h1))) in
let p : ∀ x → center ≡ x
p = λ x → sym (sigmaPath→pathSigma _ _ (sym (snd h1 (fst x)) , sym (snd (h2 (fst h1)) _)))
in (center , p)
isOfHLevelΣ 1 h1 h2 x y = sigmaPath→pathSigma x y ((h1 _ _) , (h2 _ _ _))
isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y =
let h3 : isOfHLevel (suc n) (x Σ≡T y)
h3 = isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ p → h2 (p i1)
(subst B p (snd x)) (snd y)
in transport (λ i → isOfHLevel (suc n) (pathSigma≡sigmaPath x y (~ i))) h3
hLevel≃ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B)
hLevel≃ zero {A = A} {B = B} hA hB = A≃B , contr
where
A≃B : A ≃ B
A≃B = isoToEquiv (iso (λ _ → fst hB) (λ _ → fst hA) (snd hB ) (snd hA))
contr : (y : A ≃ B) → A≃B ≡ y
contr y = ΣProp≡ isPropIsEquiv (funExt (λ a → snd hB (fst y a)))
hLevel≃ (suc n) hA hB =
isOfHLevelΣ (suc n) (hLevelPi (suc n) (λ _ → hB))
(λ a → subst (λ n → isOfHLevel n (isEquiv a)) (+-comm n 1) (hLevelLift n (isPropIsEquiv a)))
hLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : ℕ) → A ≃ B → isOfHLevel n A → isOfHLevel n B
hLevelRespectEquiv 0 eq hA =
( fst eq (fst hA)
, λ b → cong (fst eq) (snd hA (eq .snd .equiv-proof b .fst .fst)) ∙ eq .snd .equiv-proof b .fst .snd)
hLevelRespectEquiv 1 eq hA x y i =
hcomp (λ j → λ { (i = i0) → retEq eq x j ; (i = i1) → retEq eq y j })
(cong (eq .fst) (hA (invEquiv eq .fst x) (invEquiv eq .fst y)) i)
hLevelRespectEquiv {A = A} {B = B} (suc (suc n)) eq hA x y =
hLevelRespectEquiv (suc n) (invEquiv (congEquiv (invEquiv eq))) (hA _ _)
hLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) →
isOfHLevel n (A ≡ B)
hLevel≡ n hA hB = hLevelRespectEquiv n (invEquiv univalence) (hLevel≃ n hA hB)
hLevelHLevel1 : isProp (HLevel {ℓ = ℓ} 0)
hLevelHLevel1 x y = ΣProp≡ (λ _ → isPropIsContr) ((hLevel≡ 0 (x .snd) (y .snd) .fst))
hLevelHLevelSuc : ∀ n → isOfHLevel (suc (suc n)) (HLevel {ℓ = ℓ} (suc n))
hLevelHLevelSuc n x y = subst (λ e → isOfHLevel (suc n) e) HLevel≡ (hLevel≡ (suc n) (snd x) (snd y))
hProp≡HLevel1 : hProp {ℓ} ≡ HLevel {ℓ} 1
hProp≡HLevel1 {ℓ} = isoToPath (iso intro elim intro-elim elim-intro)
where
intro : hProp {ℓ} → HLevel {ℓ} 1
intro h = fst h , snd h
elim : HLevel 1 → hProp
elim h = (fst h) , (snd h)
intro-elim : ∀ h → intro (elim h) ≡ h
intro-elim h = ΣProp≡ (λ _ → isPropIsOfHLevel 1 _) refl
elim-intro : ∀ h → elim (intro h) ≡ h
elim-intro h = ΣProp≡ (λ _ → isPropIsProp) refl
isSetHProp : isSet (hProp {ℓ = ℓ})
isSetHProp = subst (λ X → isOfHLevel 2 X) (sym hProp≡HLevel1) (hLevelHLevelSuc 0)
isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ}
→ (extend : ∀ φ → Partial φ A → A)
→ (∀ u → u ≡ (extend i1 λ { _ → u}))
→ isContr A
isContrPartial→isContr {A = A} extend law
= ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y)
where ex = extend i0 empty
module Aux (y : A) (i : I) where
φ = ~ i ∨ i
u : Partial φ A
u = λ { (i = i0) → ex ; (i = i1) → y }
v = extend φ u
isOfHLevelLift : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A)
isOfHLevelLift n = retractIsOfHLevel n lower lift λ _ → refl
| {
"alphanum_fraction": 0.540521214,
"avg_line_length": 36.4811594203,
"ext": "agda",
"hexsha": "c592d46ed874a6842987632ef070e1bb8f1d54d6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Foundations/HLevels.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Foundations/HLevels.agda",
"max_line_length": 150,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Foundations/HLevels.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5636,
"size": 12586
} |
module Type.Core where
open import Context
open import Function
infix 3 _⊢ᵗ_
infixr 6 _⇒ᵏ_ _⇒_
infixl 7 _∙_
-- | A `Kind` is either a star or an arrow.
data Kind : Set where
⋆ : Kind
_⇒ᵏ_ : Kind -> Kind -> Kind
-- | Kind contexts.
Conᵏ : Set
Conᵏ = Con Kind
mutual
-- | Types of kind `⋆`.
Star : Conᵏ -> Set
Star Θ = Θ ⊢ᵗ ⋆
-- | A type is defined in a context and has a kind.
data _⊢ᵗ_ Θ : Kind -> Set where
Var : ∀ {σ} -> (v : σ ∈ Θ) -> Θ ⊢ᵗ σ
Lam_ : ∀ {σ τ} -> (β : Θ ▻ σ ⊢ᵗ τ) -> Θ ⊢ᵗ σ ⇒ᵏ τ
_∙_ : ∀ {σ τ} -> (φ : Θ ⊢ᵗ σ ⇒ᵏ τ) -> (α : Θ ⊢ᵗ σ) -> Θ ⊢ᵗ τ
_⇒_ : (α : Star Θ) -> (β : Star Θ) -> Star Θ
π : ∀ σ -> (β : Star (Θ ▻ σ)) -> Star Θ
μ : ∀ {κ} -> (ψ : Θ ⊢ᵗ (κ ⇒ᵏ ⋆) ⇒ᵏ κ ⇒ᵏ ⋆) -> (α : Θ ⊢ᵗ κ) -> Star Θ
-- | Closed types.
Type⁽⁾ : Kind -> Set
Type⁽⁾ σ = ε ⊢ᵗ σ
-- | Closed types that can be used in any context.
Type⁺ : Kind -> Set
Type⁺ σ = ∀ {Γ} -> Γ ⊢ᵗ σ
Star⁺ : Set
Star⁺ = Type⁺ ⋆
bindᵗ : ∀ {Θ σ τ} -> Θ ⊢ᵗ σ -> Θ ▻ σ ⊢ᵗ τ -> Θ ⊢ᵗ τ
bindᵗ α β = (Lam β) ∙ α
-- | Expand the context that a type is defined in, but do not change anything in the type
-- (including variables).
wkᵗ : ∀ {Θ Ξ σ} -> Ξ ⊢ᵗ σ -> Θ ▻▻ Ξ ⊢ᵗ σ
wkᵗ (Var v) = Var (wkᵛ v)
wkᵗ (Lam β) = Lam (wkᵗ β)
wkᵗ (φ ∙ α) = wkᵗ φ ∙ wkᵗ α
wkᵗ (α ⇒ β) = wkᵗ α ⇒ wkᵗ β
wkᵗ (π σ β) = π σ (wkᵗ β)
wkᵗ (μ ψ α) = μ (wkᵗ ψ) (wkᵗ α)
-- | Lift a closed type to any context.
wk⁺ : ∀ {σ} -> Type⁽⁾ σ -> Type⁺ σ
wk⁺ α = wkᵗ α
-- | Rename a type.
renᵗ : ∀ {Θ Ξ σ} -> Θ ⊆ Ξ -> Θ ⊢ᵗ σ -> Ξ ⊢ᵗ σ
renᵗ ι (Var v) = Var (renᵛ ι v)
renᵗ ι (Lam β) = Lam (renᵗ (keep ι) β)
renᵗ ι (φ ∙ α) = renᵗ ι φ ∙ renᵗ ι α
renᵗ ι (α ⇒ β) = renᵗ ι α ⇒ renᵗ ι β
renᵗ ι (π σ α) = π σ (renᵗ (keep ι) α)
renᵗ ι (μ ψ α) = μ (renᵗ ι ψ) (renᵗ ι α)
-- | Extend the context of a type by another context and increase all variables as appropriate.
shiftᵗⁿ : ∀ {Θ σ} Ξ -> Θ ⊢ᵗ σ -> Θ ▻▻ Ξ ⊢ᵗ σ
shiftᵗⁿ Ξ = renᵗ (extʳ Ξ)
-- | Increase all variables in a type by one.
shiftᵗ : ∀ {Θ σ τ} -> Θ ⊢ᵗ σ -> Θ ▻ τ ⊢ᵗ σ
shiftᵗ = shiftᵗⁿ (ε ▻ _)
unshiftᵗ : ∀ {Θ σ τ} -> Θ ▻ σ ▻ σ ⊢ᵗ τ -> Θ ▻ σ ⊢ᵗ τ
unshiftᵗ = renᵗ dupl
shiftᶜⁿ : ∀ {Θ σ} Ξ -> Con (Θ ⊢ᵗ σ) -> Con (Θ ▻▻ Ξ ⊢ᵗ σ)
shiftᶜⁿ Ξ = mapᶜ (shiftᵗⁿ Ξ)
shiftᶜ : ∀ {Θ σ τ} -> Con (Θ ⊢ᵗ σ) -> Con (Θ ▻ τ ⊢ᵗ σ)
shiftᶜ = mapᶜ shiftᵗ
environmentᵗ : Environment _⊢ᵗ_
environmentᵗ = record
{ varᵈ = Var
; renᵈ = renᵗ
}
module TypeEnv = Environment environmentᵗ
_⊢ᵗᵉ_ = TypeEnv._⊢ᵉ_
module _ where
open TypeEnv
subᵗ : ∀ {Θ Ξ σ} -> Ξ ⊢ᵗᵉ Θ -> Θ ⊢ᵗ σ -> Ξ ⊢ᵗ σ
subᵗ ρ (Var v) = lookupᵉ v ρ
subᵗ ρ (Lam β) = Lam (subᵗ (keepᵉ ρ) β)
subᵗ ρ (φ ∙ α) = subᵗ ρ φ ∙ subᵗ ρ α
subᵗ ρ (α ⇒ β) = subᵗ ρ α ⇒ subᵗ ρ β
subᵗ ρ (π σ β) = π σ (subᵗ (keepᵉ ρ) β)
subᵗ ρ (μ ψ α) = μ (subᵗ ρ ψ) (subᵗ ρ α)
_<_>ᵗ : ∀ {Θ σ τ} -> Θ ▻ σ ⊢ᵗ τ -> Θ ⊢ᵗ σ -> Θ ⊢ᵗ τ
β < α >ᵗ = subᵗ (topᵉ α) β
-- | Right-fold a context with `_⇒ᵏ_ ∘ f`.
--
-- > conToKindBy f (ε ▻ σ₁ ▻ … ▻ σₙ) τ = f σ₁ ⇒ᵏ … ⇒ᵏ f σₙ ⇒ᵏ τ
conToKindBy : ∀ {α} {A : Set α} -> (A -> Kind) -> Con A -> Kind -> Kind
conToKindBy f Θ τ = foldrᶜ (_⇒ᵏ_ ∘ f) τ Θ
-- | Right-fold a context with `_⇒ᵏ_`.
--
-- > conToKind (ε ▻ σ₁ ▻ … ▻ σₙ) τ = σ₁ ⇒ᵏ … ⇒ᵏ σₙ ⇒ᵏ τ
conToKind : Conᵏ -> Kind -> Kind
conToKind = conToKindBy id
-- | Construct an environment with n variables going in reverse order.
--
-- > subVars' = ∅ ▷ (n - 1) ▷ … ▷ 0
--
-- (each variable is denoted by its De Bruijn index).
subVars' : ∀ {Θ Ξ} -> Seq (λ σ -> Ξ ▻▻ Θ ⊢ᵗ σ) Θ
subVars' {ε} = ø
subVars' {Θ ▻ σ} = mapˢ shiftᵗ subVars' ▶ Var vz
-- | Construct an environment with n variables going in reverse order.
--
-- > subVars' = ∅ ▷ (n - 1) ▷ … ▷ 0
--
-- (each variable is denoted by its De Bruijn index).
subVars : ∀ {α} {A : Set α} {Ξ Θ} {f : A -> Kind} -> Seq (λ σ -> Ξ ▻▻ mapᶜ f Θ ⊢ᵗ f σ) Θ
subVars {Θ = ε} = ø
subVars {Θ = Θ ▻ σ} = mapˢ shiftᵗ subVars ▶ Var vz
-- | Apply π` to a type `n` times.
--
-- > πⁿ' (ε ▻ σ₁ ▻ … ▻ σₙ) β = πₙ ∘ … ∘ π₁ $ β
πⁿ' : ∀ {Ξ} Θ -> Star (Ξ ▻▻ Θ) -> Star Ξ
πⁿ' ε β = β
πⁿ' (Θ ▻ σ) β = πⁿ' Θ (π σ β)
-- | Apply `Lam` to a type `n` times.
--
-- > Lamⁿ' (ε ▻ σ₁ ▻ … ▻ σₙ) β = Lamₙ ∘ … ∘ Lam₁ $ β
Lamⁿ' : ∀ {Ξ τ} Θ -> Ξ ▻▻ Θ ⊢ᵗ τ -> Ξ ⊢ᵗ conToKind Θ τ
Lamⁿ' ε β = β
Lamⁿ' (Θ ▻ σ) β = Lamⁿ' Θ (Lam β)
-- | Apply `Lam` to a type `n` times.
--
-- > Lamⁿ' (ε ▻ σ₁ ▻ … ▻ σₙ) β = Lamₙ ∘ … ∘ Lam₁ $ β
Lamⁿ : ∀ {α} {A : Set α} {Ξ τ f} (Θ : Con A) -> Ξ ▻▻ mapᶜ f Θ ⊢ᵗ τ -> Ξ ⊢ᵗ conToKindBy f Θ τ
Lamⁿ ε β = β
Lamⁿ (Θ ▻ σ) β = Lamⁿ Θ (Lam β)
-- | Apply a type function to an environment.
--
-- > applyᵗⁿ _ ψ (∅ ▷ α₁ ▷ … ▷ αₙ) = ψ α₁ … αₙ
applyᵗⁿ
: ∀ {α} {A : Set α} {Ξ f τ}
-> (Θ : Con A)
-> Ξ ⊢ᵗ foldrᶜ (_⇒ᵏ_ ∘ f) τ Θ
-> Seq (λ σ -> Ξ ⊢ᵗ f σ) Θ
-> Ξ ⊢ᵗ τ
applyᵗⁿ _ ψ ø = ψ
applyᵗⁿ _ ψ (ρ ▶ α) = applyᵗⁿ _ ψ ρ ∙ α
instᵗⁿ
: ∀ {α} {A : Set α} {Θ Ξ σ} {f : Con A -> Kind}
-> Seq (λ τ -> Θ ⊢ᵗ f τ) Ξ -> Θ ▻▻ mapᶜ f Ξ ⊢ᵗ σ -> Θ ⊢ᵗ σ
instᵗⁿ ø β = β
instᵗⁿ {Ξ = Ξ ▻ _} (ρ ▶ α) β = instᵗⁿ ρ (bindᵗ (shiftᵗⁿ (mapᶜ _ Ξ) α) β)
instᵗⁿ' : ∀ {Θ Ξ σ} -> Seq (Θ ⊢ᵗ_) Ξ -> Θ ▻▻ Ξ ⊢ᵗ σ -> Θ ⊢ᵗ σ
instᵗⁿ' ø β = β
instᵗⁿ' {Ξ = Ξ ▻ _} (ρ ▶ α) β = instᵗⁿ' ρ (bindᵗ (shiftᵗⁿ Ξ α) β)
conToTypeBy : ∀ {Θ Ξ} -> (Star Θ -> Star Ξ) -> Con (Star Θ) -> Star Ξ -> Star Ξ
conToTypeBy f Δ β = foldrᶜ (_⇒_ ∘ f) β Δ
| {
"alphanum_fraction": 0.4992360581,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "46cfd6f9e60f2b5a3220996ddff3d4498a7d7d90",
"lang": "Agda",
"max_forks_count": 399,
"max_forks_repo_forks_event_max_datetime": "2022-03-31T11:18:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-05T09:36:10.000Z",
"max_forks_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "AriFordsham/plutus",
"max_forks_repo_path": "papers/unraveling-recursion/code/src/Type/Core.agda",
"max_issues_count": 2493,
"max_issues_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T15:31:31.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-09-28T19:28:17.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "AriFordsham/plutus",
"max_issues_repo_path": "papers/unraveling-recursion/code/src/Type/Core.agda",
"max_line_length": 95,
"max_stars_count": 1299,
"max_stars_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "AriFordsham/plutus",
"max_stars_repo_path": "papers/unraveling-recursion/code/src/Type/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-28T01:10:02.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-02T13:41:39.000Z",
"num_tokens": 3099,
"size": 5236
} |
module Adjunctions where
open import Library
open import Categories
open import Functors
open Cat
open Fun
record Adj {a b c d}(C : Cat {a}{b})(D : Cat {c}{d}) : Set (a ⊔ b ⊔ c ⊔ d)
where
constructor adjunction
field L : Fun C D
R : Fun D C
left : {X : Obj C}{Y : Obj D} →
Hom D (OMap L X) Y → Hom C X (OMap R Y)
right : {X : Obj C}{Y : Obj D} →
Hom C X (OMap R Y) → Hom D (OMap L X) Y
lawa : {X : Obj C}{Y : Obj D}(f : Hom D (OMap L X) Y) →
right (left f) ≅ f
lawb : {X : Obj C}{Y : Obj D}(f : Hom C X (OMap R Y)) →
left (right f) ≅ f
natleft : {X X' : Obj C}{Y Y' : Obj D}
(f : Hom C X' X)(g : Hom D Y Y')
(h : Hom D (OMap L X) Y) →
comp C (HMap R g) (comp C (left h) f)
≅
left (comp D g (comp D h (HMap L f)))
natright : {X X' : Obj C}{Y Y' : Obj D}
(f : Hom C X' X)(g : Hom D Y Y')
(h : Hom C X (OMap R Y)) →
right (comp C (HMap R g) (comp C h f))
≅
comp D g (comp D (right h) (HMap L f))
| {
"alphanum_fraction": 0.390513834,
"avg_line_length": 36.1428571429,
"ext": "agda",
"hexsha": "3b010400be8aca1a90510163d675f5cbb010dc66",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Adjunctions.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Adjunctions.agda",
"max_line_length": 74,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Adjunctions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 426,
"size": 1265
} |
------------------------------------------------------------------------
-- A combined definition of strong and weak bisimilarity and
-- expansion, along with various properties
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Delay-monad.Sized.Bisimilarity where
open import Equality.Propositional as E using (_≡_)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Prelude.Size
open import Function-universe E.equality-with-J hiding (_∘_; Kind)
open import Delay-monad.Sized
open import Delay-monad.Bisimilarity.Kind
------------------------------------------------------------------------
-- The code below is defined for a fixed type family A
module _ {a} {A : Size → Type a} where
----------------------------------------------------------------------
-- The relations
mutual
-- A combined definition of all three relations. The definition
-- uses mixed induction and coinduction.
--
-- Note that this type is not defined in the same way as Delay.
-- One might argue that the now constructor should have the
-- following type, using a /sized/ identity type Id:
--
-- now : ∀ {x y} →
-- Id (A ∞) i x y →
-- [ i ] now x ∼ now y
infix 4 [_]_⟨_⟩_ [_]_⟨_⟩′_
data [_]_⟨_⟩_ (i : Size) :
Delay A ∞ → Kind → Delay A ∞ → Type a where
now : ∀ {k x} → [ i ] now x ⟨ k ⟩ now x
later : ∀ {k x₁ x₂} →
[ i ] force x₁ ⟨ k ⟩′ force x₂ →
[ i ] later x₁ ⟨ k ⟩ later x₂
laterˡ : ∀ {k x₁ x₂} →
[ i ] force x₁ ⟨ other k ⟩ x₂ →
[ i ] later x₁ ⟨ other k ⟩ x₂
laterʳ : ∀ {x₁ x₂} →
[ i ] x₁ ⟨ other weak ⟩ force x₂ →
[ i ] x₁ ⟨ other weak ⟩ later x₂
record [_]_⟨_⟩′_ (i : Size)
(x₁ : Delay A ∞) (k : Kind) (x₂ : Delay A ∞) :
Type a where
coinductive
field
force : {j : Size< i} → [ j ] x₁ ⟨ k ⟩ x₂
open [_]_⟨_⟩′_ public
-- Strong bisimilarity.
infix 4 [_]_∼_ [_]_∼′_ _∼_ _∼′_
[_]_∼_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_∼_ = [_]_⟨ strong ⟩_
[_]_∼′_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_∼′_ = [_]_⟨ strong ⟩′_
_∼_ : Delay A ∞ → Delay A ∞ → Type a
_∼_ = [ ∞ ]_∼_
_∼′_ : Delay A ∞ → Delay A ∞ → Type a
_∼′_ = [ ∞ ]_∼′_
-- Expansion.
infix 4 [_]_≳_ [_]_≳′_ _≳_ _≳′_
[_]_≳_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_≳_ = [_]_⟨ other expansion ⟩_
[_]_≳′_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_≳′_ = [_]_⟨ other expansion ⟩′_
_≳_ : Delay A ∞ → Delay A ∞ → Type a
_≳_ = [ ∞ ]_≳_
_≳′_ : Delay A ∞ → Delay A ∞ → Type a
_≳′_ = [ ∞ ]_≳′_
-- The converse of expansion.
infix 4 [_]_≲_ [_]_≲′_ _≲_ _≲′_
[_]_≲_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_≲_ i = flip [ i ]_⟨ other expansion ⟩_
[_]_≲′_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_≲′_ i = flip [ i ]_⟨ other expansion ⟩′_
_≲_ : Delay A ∞ → Delay A ∞ → Type a
_≲_ = [ ∞ ]_≲_
_≲′_ : Delay A ∞ → Delay A ∞ → Type a
_≲′_ = [ ∞ ]_≲′_
-- Weak bisimilarity.
infix 4 [_]_≈_ [_]_≈′_ _≈_ _≈′_
[_]_≈_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_≈_ = [_]_⟨ other weak ⟩_
[_]_≈′_ : Size → Delay A ∞ → Delay A ∞ → Type a
[_]_≈′_ = [_]_⟨ other weak ⟩′_
_≈_ : Delay A ∞ → Delay A ∞ → Type a
_≈_ = [ ∞ ]_≈_
_≈′_ : Delay A ∞ → Delay A ∞ → Type a
_≈′_ = [ ∞ ]_≈′_
----------------------------------------------------------------------
-- Conversions
-- Strong bisimilarity is contained in the other relations (and
-- itself).
∼→ : ∀ {k i x y} → [ i ] x ∼ y → [ i ] x ⟨ k ⟩ y
∼→ now = now
∼→ (later p) = later λ { .force → ∼→ (force p) }
-- Expansion is contained in weak bisimilarity (and expansion).
≳→ : ∀ {k i x y} → [ i ] x ≳ y → [ i ] x ⟨ other k ⟩ y
≳→ now = now
≳→ (later p) = later λ { .force → ≳→ (force p) }
≳→ (laterˡ p) = laterˡ (≳→ p)
-- In some cases weak bisimilarity is contained in expansion (and
-- itself).
≈→-now : ∀ {k i x y} → [ i ] x ≈ now y → [ i ] x ⟨ other k ⟩ now y
≈→-now now = now
≈→-now (laterˡ p) = laterˡ (≈→-now p)
-- In some cases all three relations are contained in strong
-- bisimilarity.
→∼-neverˡ : ∀ {k i x} → [ i ] never ⟨ k ⟩ x → [ i ] never ∼ x
→∼-neverˡ (later p) = later λ { .force → →∼-neverˡ (force p) }
→∼-neverˡ (laterˡ p) = →∼-neverˡ p
→∼-neverˡ (laterʳ p) = later λ { .force → →∼-neverˡ p }
→∼-neverʳ : ∀ {k i x} → [ i ] x ⟨ k ⟩ never → [ i ] x ∼ never
→∼-neverʳ (later p) = later λ { .force → →∼-neverʳ (force p) }
→∼-neverʳ (laterˡ p) = later λ { .force → →∼-neverʳ p }
→∼-neverʳ (laterʳ p) = →∼-neverʳ p
----------------------------------------------------------------------
-- Removing later constructors
-- Later constructors can sometimes be removed.
drop-laterʳ :
∀ {k i} {j : Size< i} {x y} →
[ i ] x ⟨ other k ⟩ y →
[ j ] x ⟨ other k ⟩ drop-later y
drop-laterʳ now = now
drop-laterʳ (later p) = laterˡ (force p)
drop-laterʳ (laterʳ p) = p
drop-laterʳ (laterˡ p) = laterˡ (drop-laterʳ p)
drop-laterˡ :
∀ {i} {j : Size< i} {x y} →
[ i ] x ≈ y →
[ j ] drop-later x ≈ y
drop-laterˡ now = now
drop-laterˡ (later p) = laterʳ (force p)
drop-laterˡ (laterʳ p) = laterʳ (drop-laterˡ p)
drop-laterˡ (laterˡ p) = p
drop-laterˡʳ :
∀ {k i} {j : Size< i} {x y} →
[ i ] x ⟨ k ⟩ y →
[ j ] drop-later x ⟨ k ⟩ drop-later y
drop-laterˡʳ now = now
drop-laterˡʳ (later p) = force p
drop-laterˡʳ (laterʳ p) = drop-laterˡ p
drop-laterˡʳ (laterˡ p) = drop-laterʳ p
-- Special cases of the functions above.
laterʳ⁻¹ : ∀ {k i} {j : Size< i} {x y} →
[ i ] x ⟨ other k ⟩ later y →
[ j ] x ⟨ other k ⟩ force y
laterʳ⁻¹ = drop-laterʳ
laterˡ⁻¹ : ∀ {i} {j : Size< i} {x y} →
[ i ] later x ≈ y →
[ j ] force x ≈ y
laterˡ⁻¹ = drop-laterˡ
later⁻¹ : ∀ {k i} {j : Size< i} {x y} →
[ i ] later x ⟨ k ⟩ later y →
[ j ] force x ⟨ k ⟩ force y
later⁻¹ = drop-laterˡʳ
-- The following size-preserving variant of laterʳ⁻¹ and laterˡ⁻¹
-- can be defined.
--
-- Several other variants cannot be defined if ∀ i → A i is
-- inhabited, see Delay-monad.Bisimilarity.Sized.Negative.
laterˡʳ⁻¹ :
∀ {k i x y} →
[ i ] later x ⟨ other k ⟩ force y →
[ i ] force x ⟨ other k ⟩ later y →
[ i ] force x ⟨ other k ⟩ force y
laterˡʳ⁻¹ {k} {i} p q = laterˡʳ⁻¹′ p q E.refl E.refl
where
laterˡʳ⁻¹″ :
∀ {x′ y′ x y} →
({j : Size< i} → [ j ] x′ ⟨ other k ⟩ force y) →
({j : Size< i} → [ j ] force x ⟨ other k ⟩ y′) →
x′ ≡ later x → y′ ≡ later y →
[ i ] later x ⟨ other k ⟩ later y
laterˡʳ⁻¹″ p q E.refl E.refl = later λ { .force → laterˡʳ⁻¹ p q }
laterˡʳ⁻¹′ :
∀ {x′ y′ x y} →
[ i ] later x ⟨ other k ⟩ y′ →
[ i ] x′ ⟨ other k ⟩ later y →
force x ≡ x′ → force y ≡ y′ →
[ i ] x′ ⟨ other k ⟩ y′
laterˡʳ⁻¹′ (later p) (later q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (force p) (force q) ≡x′ ≡y′
laterˡʳ⁻¹′ (laterʳ p) (later q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (λ { {_} → laterˡ⁻¹ p }) (force q) ≡x′ ≡y′
laterˡʳ⁻¹′ (later p) (laterˡ q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (force p) (λ { {_} → laterʳ⁻¹ q }) ≡x′ ≡y′
laterˡʳ⁻¹′ (laterʳ p) (laterˡ q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (λ { {_} → laterˡ⁻¹ p }) (λ { {_} → laterʳ⁻¹ q }) ≡x′ ≡y′
laterˡʳ⁻¹′ (laterˡ p) _ E.refl E.refl = p
laterˡʳ⁻¹′ _ (laterʳ q) E.refl ≡y′ = E.subst ([ i ] _ ⟨ _ ⟩_) ≡y′ q
----------------------------------------------------------------------
-- Reflexivity, symmetry/antisymmetry, transitivity
-- All three relations are reflexive.
reflexive : ∀ {k i} x → [ i ] x ⟨ k ⟩ x
reflexive (now _) = now
reflexive (later x) = later λ { .force → reflexive (force x) }
-- Strong and weak bisimilarity are symmetric.
symmetric :
∀ {k i x y} {¬≳ : if k ≟-Kind other expansion then ⊥ else ⊤} →
[ i ] x ⟨ k ⟩ y → [ i ] y ⟨ k ⟩ x
symmetric now = now
symmetric (laterˡ {k = weak} p) = laterʳ (symmetric p)
symmetric (laterʳ p) = laterˡ (symmetric p)
symmetric {¬≳ = ¬≳} (later p) =
later λ { .force → symmetric {¬≳ = ¬≳} (force p) }
symmetric {¬≳ = ()} (laterˡ {k = expansion} _)
-- Some special cases of symmetry hold for expansion.
symmetric-neverˡ : ∀ {i x} → [ i ] never ≳ x → [ i ] x ≳ never
symmetric-neverˡ = ∼→ ∘ symmetric ∘ →∼-neverˡ
symmetric-neverʳ : ∀ {i x} → [ i ] x ≳ never → [ i ] never ≳ x
symmetric-neverʳ = ∼→ ∘ symmetric ∘ →∼-neverʳ
-- The expansion relation is antisymmetric (up to weak
-- bisimilarity).
antisymmetric-≳ : ∀ {i x y} → [ i ] x ≳ y → [ i ] y ≳ x → [ i ] x ≈ y
antisymmetric-≳ p _ = ≳→ p
-- Several more or less size-preserving variants of transitivity.
--
-- Many size-preserving variants cannot be defined if ∀ i → A i is
-- inhabited, see Delay-monad.Sized.Bisimilarity.Negative.
transitive-∼ʳ :
∀ {k i x y z}
{¬≈ : if k ≟-Kind other weak then ⊥ else ⊤} →
[ i ] x ⟨ k ⟩ y → [ i ] y ∼ z → [ i ] x ⟨ k ⟩ z
transitive-∼ʳ now now = now
transitive-∼ʳ {¬≈ = ¬≈} (laterˡ p) q = laterˡ
(transitive-∼ʳ {¬≈ = ¬≈} p q)
transitive-∼ʳ {¬≈ = ()} (laterʳ _) _
transitive-∼ʳ {¬≈ = ¬≈} (later p) (later q) =
later λ { .force → transitive-∼ʳ {¬≈ = ¬≈} (force p) (force q) }
transitive-∼ˡ :
∀ {k i x y z} →
x ∼ y → [ i ] y ⟨ k ⟩ z → [ i ] x ⟨ k ⟩ z
transitive-∼ˡ now now = now
transitive-∼ˡ (later p) (later q) = later λ { .force →
transitive-∼ˡ (force p) (force q) }
transitive-∼ˡ (later p) (laterˡ q) = laterˡ (transitive-∼ˡ (force p) q)
transitive-∼ˡ p (laterʳ q) = laterʳ (transitive-∼ˡ p q)
transitive-∞∼ʳ :
∀ {k i x y z} →
[ i ] x ⟨ k ⟩ y → y ∼ z → [ i ] x ⟨ k ⟩ z
transitive-∞∼ʳ now now = now
transitive-∞∼ʳ (later p) (later q) = later λ { .force →
transitive-∞∼ʳ (force p) (force q) }
transitive-∞∼ʳ (laterˡ p) q = laterˡ (transitive-∞∼ʳ p q)
transitive-∞∼ʳ (laterʳ p) (later q) = laterʳ (transitive-∞∼ʳ p (force q))
transitive-≳ˡ :
∀ {k i x y z} →
x ≳ y → [ i ] y ⟨ other k ⟩ z → [ i ] x ⟨ other k ⟩ z
transitive-≳ˡ now now = now
transitive-≳ˡ (later p) (later q) = later λ { .force →
transitive-≳ˡ (force p) (force q) }
transitive-≳ˡ (later p) (laterˡ q) = laterˡ (transitive-≳ˡ (force p) q)
transitive-≳ˡ (laterˡ p) q = laterˡ (transitive-≳ˡ p q)
transitive-≳ˡ p (laterʳ q) = laterʳ (transitive-≳ˡ p q)
transitive-≈≲ :
∀ {i x y z} →
[ i ] x ≈ y → y ≲ z → [ i ] x ≈ z
transitive-≈≲ p q = symmetric (transitive-≳ˡ q (symmetric p))
transitive-≈-now :
∀ {i x′ y z} →
let x = now x′ in
[ i ] x ≈ y → y ≈ z → [ i ] x ≈ z
transitive-≈-now now now = now
transitive-≈-now (laterʳ p) q = transitive-≈-now p (laterˡ⁻¹ q)
transitive-≈-now p (laterʳ q) = laterʳ (transitive-≈-now p q)
mutual
transitive-≈-later :
∀ {i x′ y z} →
let x = later x′ in
x ≈ y → y ≈ z → [ i ] x ≈ z
transitive-≈-later p (later q) = later λ { .force →
transitive-≈ (later⁻¹ p) (force q) }
transitive-≈-later p (laterʳ q) = laterʳ (transitive-≈-later p q)
transitive-≈-later p (laterˡ q) = transitive-≈ (laterʳ⁻¹ p) q
transitive-≈-later (laterˡ p) q = laterˡ (transitive-≈ p q)
transitive-≈ : ∀ {i x y z} → x ≈ y → y ≈ z → [ i ] x ≈ z
transitive-≈ {x = now x} p q = transitive-≈-now p q
transitive-≈ {x = later x} p q = transitive-≈-later p q
-- Equational reasoning combinators.
infix -1 _∎ finally finally-≳ finally-≈
infixr -2 step-∼ˡ step-∼∼ step-≳∼ step-≈∼ step-?∼ step-≳ˡ step-≈
_≳⟨⟩_ step-≡ˡ _∼⟨⟩_
_∎ : ∀ {k i} x → [ i ] x ⟨ k ⟩ x
_∎ = reflexive
finally : ∀ {k i} x y →
[ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ y
finally _ _ x?y = x?y
syntax finally x y x≈y = x ?⟨ x≈y ⟩∎ y ∎
finally-≳ : ∀ {i} x y →
[ i ] x ≳ y → [ i ] x ≳ y
finally-≳ _ _ x≳y = x≳y
syntax finally-≳ x y x≳y = x ≳⟨ x≳y ⟩∎ y ∎
finally-≈ : ∀ {i} x y →
[ i ] x ≈ y → [ i ] x ≈ y
finally-≈ _ _ x≈y = x≈y
syntax finally-≈ x y x≈y = x ≈⟨ x≈y ⟩∎ y ∎
step-∼ˡ : ∀ {k i} x {y z} →
[ i ] y ⟨ k ⟩ z → x ∼ y → [ i ] x ⟨ k ⟩ z
step-∼ˡ _ y⟨⟩z x∼y = transitive-∼ˡ x∼y y⟨⟩z
syntax step-∼ˡ x y⟨⟩z x∼y = x ∼⟨ x∼y ⟩ y⟨⟩z
step-∼∼ : ∀ {i} x {y z} →
[ i ] y ∼ z → [ i ] x ∼ y → [ i ] x ∼ z
step-∼∼ _ y∼z x∼y = transitive-∼ʳ x∼y y∼z
syntax step-∼∼ x y∼z x∼y = x ∼⟨ x∼y ⟩∼ y∼z
step-≳∼ : ∀ {i} x {y z} →
[ i ] y ∼ z → [ i ] x ≳ y → [ i ] x ≳ z
step-≳∼ _ y∼z x≳y = transitive-∼ʳ x≳y y∼z
syntax step-≳∼ x y∼z x≳y = x ≳⟨ x≳y ⟩∼ y∼z
step-≈∼ : ∀ {k i} x {y z} →
y ∼ z → [ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ z
step-≈∼ _ y∼z x≈y = transitive-∞∼ʳ x≈y y∼z
syntax step-≈∼ x y∼z x≈y = x ≈⟨ x≈y ⟩∼ y∼z
step-?∼ : ∀ {k i} x {y z} →
y ∼ z → [ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ z
step-?∼ _ y∼z x?y = transitive-∞∼ʳ x?y y∼z
syntax step-?∼ x y∼z x?y = x ?⟨ x?y ⟩∼ y∼z
step-≳ˡ : ∀ {k i} x {y z} →
[ i ] y ⟨ other k ⟩ z → x ≳ y →
[ i ] x ⟨ other k ⟩ z
step-≳ˡ _ y≳≈z x≳y = transitive-≳ˡ x≳y y≳≈z
syntax step-≳ˡ x y≳≈z x≳y = x ≳⟨ x≳y ⟩ y≳≈z
step-≈ : ∀ {i} x {y z} →
y ≈ z → x ≈ y → [ i ] x ≈ z
step-≈ _ y≈z x≈y = transitive-≈ x≈y y≈z
syntax step-≈ x y≈z x≈y = x ≈⟨ x≈y ⟩ y≈z
_≳⟨⟩_ : ∀ {k i} x {y} →
[ i ] drop-later x ⟨ other k ⟩ y → [ i ] x ⟨ other k ⟩ y
now _ ≳⟨⟩ p = p
later _ ≳⟨⟩ p = laterˡ p
step-≡ˡ : ∀ {k i} x {y z} →
[ i ] y ⟨ k ⟩ z → x ≡ y → [ i ] x ⟨ k ⟩ z
step-≡ˡ _ y⟨⟩z E.refl = y⟨⟩z
syntax step-≡ˡ x y⟨⟩z x≡y = x ≡⟨ x≡y ⟩ y⟨⟩z
_∼⟨⟩_ : ∀ {k i} x {y} →
[ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ y
_ ∼⟨⟩ x≈y = x≈y
----------------------------------------------------------------------
-- Some results related to negation
-- The computation never is not related to now x.
never≉now : ∀ {k i x} → ¬ [ i ] never ⟨ k ⟩ now x
never≉now (laterˡ p) = never≉now p
-- The computation now x is not related to never.
now≉never : ∀ {k i x} → ¬ [ i ] now x ⟨ k ⟩ never
now≉never (laterʳ p) = now≉never p
-- If A ∞ is uninhabited, then the three relations defined above are
-- trivial.
uninhabited→trivial : ∀ {k i} → ¬ A ∞ → ∀ x y → [ i ] x ⟨ k ⟩ y
uninhabited→trivial ¬A (now x) _ = ⊥-elim (¬A x)
uninhabited→trivial ¬A (later x) (now y) = ⊥-elim (¬A y)
uninhabited→trivial ¬A (later x) (later y) =
later λ { .force → uninhabited→trivial ¬A (force x) (force y) }
-- Expansion and weak bisimilarity are not pointwise propositional.
¬-≳≈-propositional :
∀ {k} → ¬ (∀ {x y} → E.Is-proposition ([ ∞ ] x ⟨ other k ⟩ y))
¬-≳≈-propositional {k} =
(∀ {x y} → E.Is-proposition ([ ∞ ] x ⟨ other k ⟩ y)) ↝⟨ (λ prop → prop {x = never} {y = never}) ⟩
E.Is-proposition ([ ∞ ] never ⟨ other k ⟩ never) ↝⟨ (λ irr → irr _ _) ⟩
proof₁ ≡ proof₂ ↝⟨ (λ ()) ⟩□
⊥₀ □
where
proof₁ : ∀ {i} → [ i ] never ⟨ other k ⟩ never
proof₁ = later λ { .force → proof₁ }
proof₂ : ∀ {i} → [ i ] never ⟨ other k ⟩ never
proof₂ = laterˡ proof₁
------------------------------------------------------------------------
-- A statement of extensionality for strong bisimilarity
-- A statement of extensionality: strongly bisimilar computations are
-- equal.
Extensionality : (ℓ : Level) → Type (lsuc ℓ)
Extensionality a =
{A : Size → Type a} {x y : Delay A ∞} → x ∼ y → x ≡ y
| {
"alphanum_fraction": 0.4645029167,
"avg_line_length": 32.8857142857,
"ext": "agda",
"hexsha": "1c3fd1a8ceed5b3964db37a029e0905358c9373a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Sized/Bisimilarity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Sized/Bisimilarity.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Sized/Bisimilarity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6892,
"size": 16114
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Diagram.Cocone.Properties where
open import Level
open import Categories.Category
open import Categories.Functor
open import Categories.Functor.Properties
open import Categories.NaturalTransformation
open import Categories.Diagram.Cone.Properties
open import Categories.Diagram.Duality
import Categories.Diagram.Cocone as Coc
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D J J′ : Category o ℓ e
module _ {F : Functor J C} (G : Functor C D) where
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
module CF = Coc F
GF = G ∘F F
module CGF = Coc GF
F-map-Coconeˡ : CF.Cocone → CGF.Cocone
F-map-Coconeˡ K = record
{ coapex = record
{ ψ = λ X → G.F₁ (ψ X)
; commute = λ f → [ G ]-resp-∘ (commute f)
}
}
where open CF.Cocone K
F-map-Cocone⇒ˡ : ∀ {K K′} (f : CF.Cocone⇒ K K′) → CGF.Cocone⇒ (F-map-Coconeˡ K) (F-map-Coconeˡ K′)
F-map-Cocone⇒ˡ f = record
{ arr = G.F₁ arr
; commute = [ G ]-resp-∘ commute
}
where open CF.Cocone⇒ f
module _ {F : Functor J C} (G : Functor J′ J) where
private
module C = Category C
module J′ = Category J′
module F = Functor F
module G = Functor G
module CF = Coc F
FG = F ∘F G
module CFG = Coc FG
F-map-Coconeʳ : CF.Cocone → CFG.Cocone
F-map-Coconeʳ K = coCone⇒Cocone C (F-map-Coneʳ G.op (Cocone⇒coCone C K))
F-map-Cocone⇒ʳ : ∀ {K K′} (f : CF.Cocone⇒ K K′) → CFG.Cocone⇒ (F-map-Coconeʳ K) (F-map-Coconeʳ K′)
F-map-Cocone⇒ʳ f = coCone⇒⇒Cocone⇒ C (F-map-Cone⇒ʳ G.op (Cocone⇒⇒coCone⇒ C f))
module _ {F G : Functor J C} (α : NaturalTransformation F G) where
private
module α = NaturalTransformation α
module CF = Coc F
module CG = Coc G
nat-map-Cocone : CG.Cocone → CF.Cocone
nat-map-Cocone K = coCone⇒Cocone C (nat-map-Cone α.op (Cocone⇒coCone C K))
nat-map-Cocone⇒ : ∀ {K K′} (f : CG.Cocone⇒ K K′) → CF.Cocone⇒ (nat-map-Cocone K) (nat-map-Cocone K′)
nat-map-Cocone⇒ f = coCone⇒⇒Cocone⇒ C (nat-map-Cone⇒ α.op (Cocone⇒⇒coCone⇒ C f))
| {
"alphanum_fraction": 0.6324274528,
"avg_line_length": 28.9466666667,
"ext": "agda",
"hexsha": "dba9f470867f9e49c2196f72369d85367a8628e4",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Cocone/Properties.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Cocone/Properties.agda",
"max_line_length": 102,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Cocone/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 822,
"size": 2171
} |
-- Andreas, 2014-10-23
-- We want to split on hidden variables.
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
f : {n : ℕ} → Set₁
f = Set
where
g : {n : ℕ} → Set → Set
g _ = {!.n!}
| {
"alphanum_fraction": 0.5079365079,
"avg_line_length": 13.5,
"ext": "agda",
"hexsha": "41f00278ef825c96a4b919b93261746c897a8baf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/interaction/Issue1325a.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/interaction/Issue1325a.agda",
"max_line_length": 40,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/interaction/Issue1325a.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 80,
"size": 189
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Coinductive "natural" numbers
------------------------------------------------------------------------
module Data.Conat where
open import Coinduction
open import Data.Nat using (ℕ; zero; suc)
open import Relation.Binary
------------------------------------------------------------------------
-- The type
data Coℕ : Set where
zero : Coℕ
suc : (n : ∞ Coℕ) → Coℕ
------------------------------------------------------------------------
-- Some operations
fromℕ : ℕ → Coℕ
fromℕ zero = zero
fromℕ (suc n) = suc (♯ fromℕ n)
∞ℕ : Coℕ
∞ℕ = suc (♯ ∞ℕ)
infixl 6 _+_
_+_ : Coℕ → Coℕ → Coℕ
zero + n = n
suc m + n = suc (♯ (♭ m + n))
------------------------------------------------------------------------
-- Equality
data _≈_ : Coℕ → Coℕ → Set where
zero : zero ≈ zero
suc : ∀ {m n} (m≈n : ∞ (♭ m ≈ ♭ n)) → suc m ≈ suc n
setoid : Setoid _ _
setoid = record
{ Carrier = Coℕ
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {zero} = zero
refl {suc n} = suc (♯ refl)
sym : Symmetric _≈_
sym zero = zero
sym (suc m≈n) = suc (♯ sym (♭ m≈n))
trans : Transitive _≈_
trans zero zero = zero
trans (suc m≈n) (suc n≈k) = suc (♯ trans (♭ m≈n) (♭ n≈k))
| {
"alphanum_fraction": 0.3937716263,
"avg_line_length": 22.2307692308,
"ext": "agda",
"hexsha": "185e892390ce8b46d5a343286bffdfc5cc843fdf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Conat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Conat.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Conat.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 468,
"size": 1445
} |
-- A DSL example in the language Agda: "polynomial types"
module TypeDSL where
open import Data.Nat using (ℕ;_+_;_*_)
data E : Set where
Zero : E
One : E
Add : (x : E) -> (y : E) -> E
Mul : (x : E) -> (y : E) -> E
two : E
two = Add One One
four : E
four = Mul two two
-- First semantics: compute the natural number "value" of the expression
card : E -> ℕ
card Zero = 0
card One = 1
card (Add x y) = card x + card y
card (Mul x y) = card x * card y
data Empty : Set where
data Unit : Set where unit : Unit
data Either (a : Set) (b : Set) : Set where
Left : a -> Either a b
Right : b -> Either a b
data Both (a : Set) (b : Set) : Set where
_,_ : a -> b -> Both a b
-- Second semantics: compute the corresponding finite type
typ : E -> Set
typ Zero = Empty
typ One = Unit
typ (Add x y) = Either (typ x) (typ y) -- disjoint union type = sum type
typ (Mul x y) = Both (typ x) (typ y) -- cartesian product type = pair type
Bool : Set
Bool = typ two
false : Bool
false = Left unit
true : Bool
true = Right unit
BothBoolBool : Set
BothBoolBool = typ four
ex1 : BothBoolBool
ex1 = ( false , true )
open import Data.Vec as V
variable
a b : Set
m n : ℕ
enumAdd : Vec a m -> Vec b n -> Vec (Either a b) (m + n)
enumAdd as bs = V.map Left as ++ V.map Right bs
enumMul : Vec a m -> Vec b n -> Vec (Both a b) (m * n)
enumMul as bs = concat (V.map (\ a -> V.map (\ b -> (a , b)) bs) as)
-- Third semantics: enumerate all the values in a vector
enumerate : (t : E) -> Vec (typ t) (card t)
enumerate Zero = []
enumerate One = [ unit ]
enumerate (Add x y) = enumAdd (enumerate x) (enumerate y)
enumerate (Mul x y) = enumMul (enumerate x) (enumerate y)
test2 : Vec (typ two) (card two) -- Vec Bool 2
test2 = enumerate two
-- false ∷ true ∷ []
test4 : Vec (typ four) (card four) -- Vec BothBoolBool 4
test4 = enumerate four
{-
(false , false) ∷
(false , true) ∷
(true , false) ∷
(true , true) ∷ []
-}
-- Exercise: add a constructor for function types
| {
"alphanum_fraction": 0.6149974836,
"avg_line_length": 23.1046511628,
"ext": "agda",
"hexsha": "4787ff189c69f1dced0db0a5d9886a52813a2a04",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ce764c9bbff5a726d5cf1699a433d9921a1d6a60",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "nicolabotta/DSLsofMath",
"max_forks_repo_path": "L/01/agda/TypeDSL.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce764c9bbff5a726d5cf1699a433d9921a1d6a60",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "nicolabotta/DSLsofMath",
"max_issues_repo_path": "L/01/agda/TypeDSL.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ce764c9bbff5a726d5cf1699a433d9921a1d6a60",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "nicolabotta/DSLsofMath",
"max_stars_repo_path": "L/01/agda/TypeDSL.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-24T21:27:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-24T21:27:31.000Z",
"num_tokens": 662,
"size": 1987
} |
module IsLiteralFormula where
open import OscarPrelude
open import PredicateName
open import Term
open import Formula
open import HasNegation
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₂
| {
"alphanum_fraction": 0.7233082707,
"avg_line_length": 31.6666666667,
"ext": "agda",
"hexsha": "dc9f89657b1f8dfad1923912f3cb0cd0efe31749",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/IsLiteralFormula.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/IsLiteralFormula.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/IsLiteralFormula.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 217,
"size": 665
} |
open import Agda.Primitive
postulate
X : Set
Id : Set → Set
module Generic1HIT (S : Set) where
module RecType k (C : Set k) (Necc : Set) where
postulate P : Set
module Flattening k (F : Set → Set) (C : Set k) (Necc : Set) where
-- order f before C matters!
module W = Generic1HIT (F X) -- use of F matters, application of F matters
module M = W.RecType k C X -- k matters
module S¹RecType i (A : Set i) where
module FlatteningS¹ = Flattening i Id A X -- i matters here
module HopfJunior = S¹RecType _ Set -- meta variable matters
| {
"alphanum_fraction": 0.665480427,
"avg_line_length": 26.7619047619,
"ext": "agda",
"hexsha": "04ef333d30e179f6c0c7ee80169fcb0ca39b49e1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2150.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2150.agda",
"max_line_length": 77,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2150.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 186,
"size": 562
} |
data Nat : Set where
zero : Nat -- Comment which gets eaten
suc : Nat -> Nat
{-# BUILTIN NATURAL
Nat #-}
f : Nat -> Nat
f a = 3
g : Nat -> Nat
g a = 4
--TODO found first bug
function : Nat -> (Nat -> Nat) -> Nat
function a f = f a
apply : Nat
apply = function 2 g
| {
"alphanum_fraction": 0.5833333333,
"avg_line_length": 12.5454545455,
"ext": "agda",
"hexsha": "2a3e172dc82c0652323cb01de6b7a3803961ae11",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/input/Test2.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/input/Test2.agda",
"max_line_length": 40,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/input/Test2.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 93,
"size": 276
} |
open import Web.Semantic.DL.ABox using ( ABox )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
module Web.Semantic.DL.KB where
infixr 4 _,_
data KB (Σ : Signature) (X : Set) : Set where
_,_ : (T : TBox Σ) → (A : ABox Σ X) → KB Σ X
tbox : ∀ {Σ X} → KB Σ X → TBox Σ
tbox (T , A) = T
abox : ∀ {Σ X} → KB Σ X → ABox Σ X
abox (T , A) = A
| {
"alphanum_fraction": 0.6140350877,
"avg_line_length": 23.4705882353,
"ext": "agda",
"hexsha": "17998e95fd7d5382517d2e00dc0f7ecb1eca26b2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/KB.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/KB.agda",
"max_line_length": 57,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/KB.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 166,
"size": 399
} |
-- Andreas, 2022-03-28, issue #5856, reported by Szumi Xie.
-- Patterns in path-lambdas were simply ignored, but should be illegal.
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
postulate
A E : Set
a : A
data C : Set where
c : E → C
p : a ≡ a
p = λ (c e) → e
-- WAS: panic about unbound identifier e.
-- Expected error:
-- Patterns are not allowed in Path-lambdas
-- when checking that the expression λ .patternInTele0 @ (c e) → e has type a ≡ a
| {
"alphanum_fraction": 0.6666666667,
"avg_line_length": 20.7391304348,
"ext": "agda",
"hexsha": "dd3b3d13e1d1899e1d47869e75392ce25db201aa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/Issue5856b.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/Issue5856b.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue5856b.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 152,
"size": 477
} |
module Issue1245AmbiguousParse where
postulate
A : Set
*_* : A → A
_*_ : A → A → A
module M (_ : A) where
module N (a : A) = M * a * a * a *
| {
"alphanum_fraction": 0.5466666667,
"avg_line_length": 13.6363636364,
"ext": "agda",
"hexsha": "ca7022a4240a170d673d301c48590cf233acddf4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1245AmbiguousParse.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1245AmbiguousParse.agda",
"max_line_length": 36,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1245AmbiguousParse.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 59,
"size": 150
} |
------------------------------------------------------------------------
-- Safe modules that use --erased-cubical
------------------------------------------------------------------------
{-# OPTIONS --safe --erased-cubical #-}
module README.Safe.Cubical.Erased where
-- Paths, extensionality and univalence.
import Equality.Path
-- Isomorphisms and equalities relating an arbitrary "equality with J"
-- to path equality, along with proofs of extensionality and
-- univalence for the "equality with J".
import Equality.Path.Isomorphisms
-- The cubical identity type.
import Equality.Id
-- Propositional equality, with some extra bells and whistles
-- definable in Cubical Agda.
import Equality.Propositional.Cubical
-- Some tactics aimed at making equational reasoning proofs more
-- readable for path equality.
import Tactic.By.Path
-- Some tactics aimed at making equational reasoning proofs more
-- readable for the cubical identity type.
import Tactic.By.Id
-- Some theory of Erased, developed using Cubical Agda.
import Erased.Cubical
-- Some theory of equivalences with erased "proofs", defined in terms
-- of partly erased contractible fibres, developed using Cubical Agda.
import Equivalence.Erased.Contractible-preimages.Cubical
-- Some theory of equivalences with erased "proofs", developed using
-- Cubical Agda.
import Equivalence.Erased.Cubical
-- A sequential colimit for which everything except for the "base
-- case" is erased.
import Colimit.Sequential.Very-erased
-- The sequential colimit HIT with an erased higher constructor.
import Colimit.Sequential.Erased
-- Sequential colimits.
import Colimit.Sequential
-- The one-step truncation HIT with an erased higher constructor.
import H-level.Truncation.Propositional.One-step.Erased
-- The one-step truncation.
import H-level.Truncation.Propositional.One-step
-- A non-recursive variant of H-level.Truncation.Propositional.Erased.
import H-level.Truncation.Propositional.Non-recursive.Erased
-- A variant of the propositional truncation operator with an erased
-- truncation constructor.
import H-level.Truncation.Propositional.Erased
-- Propositional truncation.
import H-level.Truncation.Propositional
-- A definition of the propositional truncation operator that does not
-- use recursive higher inductive types.
import H-level.Truncation.Propositional.Non-recursive
-- Some properties that hold for Erased do not hold for every
-- accessible modality.
import Erased.Counterexamples.Cubical
-- The "interval".
import Interval
-- Suspensions.
import Suspension
-- Spheres.
import Sphere
-- Pushouts, defined using a HIT.
import Pushout
-- Localisation.
import Localisation
-- Truncation, defined as a HIT.
import H-level.Truncation
-- Homotopy groups of pointed types.
import Pointed-type.Homotopy-group
-- Connectedness for pointed types.
import Pointed-type.Connected
-- A variant of set quotients with erased higher constructors.
import Quotient.Erased.Basics
-- Quotients (set-quotients), defined using a higher inductive type.
import Quotient
-- Two variants of the set quotients from Quotient.
import Quotient.Set-truncated-if-propositional
import Quotient.Higher-constructors-if-propositional
-- A variant of set quotients with erased higher constructors.
import Quotient.Erased
-- Cyclic groups.
import Group.Cyclic
-- Integers, defined using a quotient type.
import Integer.Quotient
-- The Eilenberg-MacLane space K(G, 1).
import Eilenberg-MacLane-space
-- Coherently constant functions.
import Coherently-constant
-- The "circle".
import Circle
-- The circle with an erased higher constructor.
import Circle.Erased
-- The torus, defined as a HIT.
import Torus
-- The figure of eight.
import Figure-of-eight
-- A variant of Nat.Wrapper.Cubical, defined using --erased-cubical.
import Nat.Wrapper.Cubical.Erased
-- A variant of the development in "Internalizing Representation
-- Independence with Univalence" (by Angiuli, Cavallo, Mörtberg and
-- Zeuner) with support for erasure.
import Structure-identity-principle.Erased
-- Truncated queues: any two queues representing the same sequence are
-- equal, and things are set up so that at compile-time (but not at
-- run-time) some queue operations compute in roughly the same way as
-- the corresponding list operations.
import Queue.Truncated
-- Queue instances for the queues in Queue.Truncated.
import Queue.Truncated.Instances
-- Quotiented queues: any two queues representing the same sequence
-- are equal.
import Queue.Quotiented
-- Queue instances for the queues in Queue.Quotiented.
import Queue.Quotiented.Instances
| {
"alphanum_fraction": 0.7581755594,
"avg_line_length": 22.5631067961,
"ext": "agda",
"hexsha": "9ce94b7caaa0ed9dc1c706d8706133bcc38604b4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "README/Safe/Cubical/Erased.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "README/Safe/Cubical/Erased.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "README/Safe/Cubical/Erased.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 1058,
"size": 4648
} |
------------------------------------------------------------------------------
-- Translation of projection-like functions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- 2012-04-03: More information about what is a projection-like in the
-- patch:
--
-- Mon Apr 2 02:41:41 COT 2012 Andreas Abel <[email protected]>
-- * Type signatures and comments explaining what is considered projection-like.
-- 2012-02-23: The function P is not considered a projection-like
-- function after the patch:
--
-- Tue Feb 21 11:41:08 COT 2012 Nils Anders Danielsson <[email protected]>
-- * The positivity checker (and more) is now only run once per mutual block.
-- 2011-09-23: From the Agda mailing list
-- Subject: Compiler internals for projection functions
-- There is some additional information about this issue.
-- 2011-09-19: Maybe the information in the issue 465 (Missing
-- patterns in funClauses) is useful.
------------------------------------------------------------------------------
module ProjectionLikeFunction where
open import Common.FOL
postulate
N : D → Set
-- See Issue #81.
P : D → Set
P i = i ≡ i
{-# ATP definition P #-}
foo : ∀ {n} → N n → n ≡ n
foo {n} Nn = bar
where
postulate bar : P n
{-# ATP prove bar #-}
| {
"alphanum_fraction": 0.5608108108,
"avg_line_length": 30.8333333333,
"ext": "agda",
"hexsha": "2a9ffb933d0f477895ea25cbd975bb0fe61442f8",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/ProjectionLikeFunction.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/ProjectionLikeFunction.agda",
"max_line_length": 92,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/ProjectionLikeFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 348,
"size": 1480
} |
module _ where
open import Common.Prelude
open import Lib.Vec
_∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c}
(f : ∀ {x} (y : B x) → C x y) (g : ∀ x → B x) → ∀ x → C x (g x)
(f ∘ g) x = f (g x)
sum : ∀ {n} → Vec Nat n → Nat
sum (x ∷ xs) = x + sum xs
sum [] = 0
foldl : ∀ {A}{B : Nat → Set} → (∀ {n} → B n → A → B (suc n)) → B 0 → ∀ {n} → Vec A n → B n
foldl {B = B} f z (x ∷ xs) = foldl {B = λ n → B (suc n)} f (f z x) xs
foldl f z [] = z
reverse : ∀ {A n} → Vec A n → Vec A n
reverse = foldl {B = Vec _} (λ xs x → x ∷ xs) []
downFrom : ∀ n → Vec Nat n
downFrom zero = []
downFrom (suc n) = n ∷ downFrom n
main : IO Unit
main = printNat (sum (reverse (downFrom 6000)))
| {
"alphanum_fraction": 0.4759206799,
"avg_line_length": 25.2142857143,
"ext": "agda",
"hexsha": "2136d8dd0e32c7114cdd4a6e382c6af60e8a9dfe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Compiler/simple/VecReverse.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Compiler/simple/VecReverse.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Compiler/simple/VecReverse.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 317,
"size": 706
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.NatSolver.Examples where
open import Cubical.Foundations.Prelude
open import Cubical.Data.FinData
open import Cubical.Data.Nat
open import Cubical.Data.Vec.Base
open import Cubical.Algebra.NatSolver.NatExpression
open import Cubical.Algebra.NatSolver.HornerForms
open import Cubical.Algebra.NatSolver.Solver
open import Cubical.Algebra.NatSolver.Reflection
private
variable
ℓ : Level
module ReflectionSolving where
_ : (x y : ℕ) → (x + y) · (x + y) ≡ x · x + 2 · x · y + y · y
_ = solve
{-
If you want to use the solver in some more complex situation,
you have to declare a helper variable (`useSolver` below) that
is a term of a dependent function type as above:
-}
module _ (SomeType : Type ℓ-zero) where
complexSolverApplication :
(someStuff : SomeType) → (x y : ℕ) → (moreStuff : SomeType)
→ x + y ≡ y + x
complexSolverApplication someStuff x y moreStuff = useSolver x y
where useSolver : (x y : ℕ) → x + y ≡ y + x
useSolver = solve
module SolvingExplained where
open EqualityToNormalform renaming (solve to natSolve)
open IteratedHornerOperations hiding (X)
ℕ[X₀,X₁] = IteratedHornerForms 2
X₀ : ℕ[X₀,X₁]
X₀ = Variable 2 (Fin.zero)
X₁ : ℕ[X₀,X₁]
X₁ = Variable 2 (suc Fin.zero)
Two : ℕ[X₀,X₁]
Two = Constant 2 2
_ : eval X₀ (1 ∷ 0 ∷ []) ≡ 1
_ = refl
_ : eval X₁ (0 ∷ 1 ∷ []) ≡ 1
_ = refl
X : Expr 3
X = ∣ Fin.zero
Y : Expr 3
Y = ∣ (suc Fin.zero)
Z : Expr 3
Z = ∣ (suc (suc Fin.zero))
{-
'normalize' maps an expression to its Horner Normalform.
Two expressions evaluating to the same ring element
have the same Horner Normal form.
This means equality of the represented ring elements
can be checked by agda's unification (so refl is a proof)
-}
_ : normalize ((K 2) ·' X) ≡
normalize (X +' X)
_ = refl
_ : normalize ((K 2) ·' X) ≡ normalize (X +' X)
_ = refl
_ : normalize (((K 2) ·' X) ·' Y) ≡ normalize (Y ·' (X +' X))
_ = refl
_ : normalize (Z ·' (((K 2) ·' X) ·' Y)) ≡ normalize (Z ·' (Y ·' (X +' X)))
_ = refl
{-
The solver needs to produce an equality between
actual ring elements. So we need a proof that
those actual ring elements are equal to a normal form:
-}
_ : (x y z : ℕ) →
eval (normalize ((K 2) ·' X ·' Y)) (x ∷ y ∷ z ∷ [])
≡ 2 · x · y
_ = λ x y z → isEqualToNormalform ((K 2) ·' X ·' Y) (x ∷ y ∷ z ∷ [])
{-
Now two of these proofs can be plugged together
to solve an equation:
-}
open Eval
_ : (x y z : ℕ) → 3 + x + y · y ≡ y · y + x + 1 + 2
_ = let
lhs = (K 3) +' X +' (Y ·' Y)
rhs = Y ·' Y +' X +' (K 1) +' (K 2)
in (λ x y z →
⟦ lhs ⟧ (x ∷ y ∷ z ∷ [])
≡⟨ sym (isEqualToNormalform lhs (x ∷ y ∷ z ∷ [])) ⟩
eval (normalize lhs) (x ∷ y ∷ z ∷ [])
≡⟨ refl ⟩
eval (normalize rhs) (x ∷ y ∷ z ∷ [])
≡⟨ isEqualToNormalform rhs (x ∷ y ∷ z ∷ []) ⟩
⟦ rhs ⟧ (x ∷ y ∷ z ∷ []) ∎)
{-
Parts of that can be automated easily:
-}
_ : (x y z : ℕ) → (x + y) · (x + y) ≡ x · x + 2 · x · y + y · y
_ = λ x y z → let
lhs = (X +' Y) ·' (X +' Y)
rhs = X ·' X +' (K 2) ·' X ·' Y +' Y ·' Y
in natSolve lhs rhs (x ∷ y ∷ z ∷ []) refl
{-
A bigger example
-}
_ : (x y z : ℕ) → (x + y) · (x + y) · (x + y) · (x + y)
≡ x · x · x · x + 4 · x · x · x · y + 6 · x · x · y · y
+ 4 · x · y · y · y + y · y · y · y
_ = λ x y z → let
lhs = (X +' Y) ·' (X +' Y) ·' (X +' Y) ·' (X +' Y)
rhs = X ·' X ·' X ·' X
+' (K 4) ·' X ·' X ·' X ·' Y
+' (K 6) ·' X ·' X ·' Y ·' Y
+' (K 4) ·' X ·' Y ·' Y ·' Y
+' Y ·' Y ·' Y ·' Y
in natSolve lhs rhs (x ∷ y ∷ z ∷ []) refl
{-
this one cannot work so far:
_ : (x y z : ℕ) → (x + y) · (x - y) ≡ (x · x - (y · y))
_ = λ x y z → let
lhs = (X +' Y) ·' (X +' (-' Y))
rhs = (X ·' X) +' (-' (Y ·' Y))
in natSolve lhs rhs (x ∷ y ∷ z ∷ []) {!!}
-}
| {
"alphanum_fraction": 0.479811098,
"avg_line_length": 28.6148648649,
"ext": "agda",
"hexsha": "f177de40487a7f69838d96fd88ea012f1eff04aa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Algebra/NatSolver/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Algebra/NatSolver/Examples.agda",
"max_line_length": 77,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Algebra/NatSolver/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 1566,
"size": 4235
} |
module Tuples where
open import Haskell.Prelude
swap : a × b → b × a
swap (a , b) = b , a
{-# COMPILE AGDA2HS swap #-}
unit2unit : ⊤ → Tuple []
unit2unit tt = []
{-# COMPILE AGDA2HS unit2unit #-}
| {
"alphanum_fraction": 0.6089108911,
"avg_line_length": 13.4666666667,
"ext": "agda",
"hexsha": "0a70371962ff28eaf00b403e53d8229599949e9f",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "test/Tuples.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "test/Tuples.agda",
"max_line_length": 33,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "test/Tuples.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 68,
"size": 202
} |
-- Andreas, 2016-12-29, issue #2366
-- With clauses need to be printed in fresh environment,
-- as they DON'T shadow the pattern variables of the parent clause.
-- (These are not even in scope)
-- {-# OPTIONS -v error.checkclause:60 #-}
open import Agda.Builtin.List
test : {A : Set} → List A → List A
test (x ∷ y ∷ ys) with []
test (x ∷ xs) | q = []
test _ = []
-- ERROR WAS:
-- With clause pattern xs is not an instance of its parent pattern y ∷ ys
-- when checking that the clause
-- test (x ∷ y ∷ ys) with []
-- test (x₁ ∷ xs) | q = []
-- has type {A : Set} → List A → List A
-- NOTE THE x₁!
-- Expected error:
-- With clause pattern xs is not an instance of its parent pattern y ∷ ys
-- when checking that the clause
-- test (x ∷ y ∷ ys) with []
-- test (x ∷ xs) | q = []
-- has type {A : Set} → List A → List A
| {
"alphanum_fraction": 0.6192214112,
"avg_line_length": 28.3448275862,
"ext": "agda",
"hexsha": "0030be87b044bdd913b9e3611389fa36091e6cc8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Fail/Issue2366.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/Fail/Issue2366.agda",
"max_line_length": 73,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Fail/Issue2366.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 256,
"size": 822
} |
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
foo : Nat → (Nat → Nat) → Nat
foo zero f = f zero
foo (suc n) f = foo n λ n → f (suc n)
fsuc : (Nat → Nat) → Nat → Nat
fsuc f n = f (suc n)
foo' : Nat → (Nat → Nat) → Nat
foo' zero f = f zero
foo' (suc n) f = foo' n (fsuc f)
foo'' : Nat → (Nat → Nat) → Nat
foo'' zero f = f zero
foo'' (suc n) f = foo'' n λ { n → f (suc n) }
test : foo 50000 (λ n → n) ≡ 50000
test = refl
test' : foo' 50000 (λ n → n) ≡ 50000
test' = refl
test'' : foo'' 50000 (λ n → n) ≡ 50000
test'' = refl
| {
"alphanum_fraction": 0.5459459459,
"avg_line_length": 19.8214285714,
"ext": "agda",
"hexsha": "167ec9ae41a6cb029b9db7944a86f39b87aadf56",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2255.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2255.agda",
"max_line_length": 45,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2255.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 238,
"size": 555
} |
-- Andreas, 2013-02-27 issue reported by Nisse
-- {-# OPTIONS -v tc.polarity:100 -v tc.pos:100 #-}
module Issue802 where
data I : Set where
i : I
mutual
data P : I → Set where
p : (x : I) → Q x x → P x
Q : I → I → Set
Q i = P
-- Polarity of Q should be mixed for both arguments.
f : (x y : I) → Q x y → P y
f i _ q = q
data R (x : I) : P x → Set where
r : (q : Q x x) → R _ (f x _ q) → R x (p x q)
-- Agda should solve the two meta variables in the type of r.
| {
"alphanum_fraction": 0.5569358178,
"avg_line_length": 20.125,
"ext": "agda",
"hexsha": "bd27f80cc8686ea63730f8d715a529b920deb413",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue802.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue802.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue802.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 185,
"size": 483
} |
module BHeap.Heap {A : Set}(_≤_ : A → A → Set) where
open import BHeap _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import BTree.Heap _≤_
lemma-bheap-heap : {b : Bound}(h : BHeap b) → Heap (forget h)
lemma-bheap-heap lf = leaf
lemma-bheap-heap (nd {x = x} _ lf lf) = single x
lemma-bheap-heap (nd _ (nd (lexy x≤y) l r) lf) = left x≤y (lemma-bheap-heap (nd (lexy x≤y) l r))
lemma-bheap-heap (nd _ lf (nd (lexy x≤y) l r)) = right x≤y (lemma-bheap-heap (nd (lexy x≤y) l r))
lemma-bheap-heap (nd _ (nd (lexy x≤y) l r) (nd (lexy x≤y') l' r')) = both x≤y x≤y' (lemma-bheap-heap (nd (lexy x≤y) l r)) (lemma-bheap-heap (nd (lexy x≤y') l' r'))
| {
"alphanum_fraction": 0.6299093656,
"avg_line_length": 47.2857142857,
"ext": "agda",
"hexsha": "a05534c90196e8da324eacb0a1ea129d141c846d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/BHeap/Heap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/BHeap/Heap.agda",
"max_line_length": 163,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/BHeap/Heap.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 291,
"size": 662
} |
-- Andreas, 2013-09-17 catches a bug in constraint solving
-- with meta-variables applied to underapplied record constructors
-- {-# OPTIONS --show-implicit -v tc.meta.assign:50 -v tc.conv.elim:30 #-}
module Issue889 where
record Monad (M : Set → Set) : Set₁ where
field
return : ∀ {A} → A → M A
_>>=_ : ∀ {A} {B : M A → Set} (m : M A) →
((x : A) → M (B (return x))) → M (B m)
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
_×_ : (A B : Set) → Set
A × B = Σ A λ _ → B
State : Set → Set → Set
State S X = S → X × S
-- Here is the underapplied record constructor
-- (made underapplied by eta-contraction, resp.).
state-return : ∀ {S X} → X → State S X
state-return x = _,_ x -- λ s → x , s
-- When giving the @_>>=_@ function to the record goal we get:
--
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:524
state-monad : ∀ {S} → Monad (State S)
state-monad {S} = record { return = state-return; _>>=_ = {!_>>=_!} }
where
postulate
_>>=_ : ∀ {A} {B : State S A → Set} (m : State S A) →
((x : A) → State S (B (state-return x))) → State S (B m)
-- Bug arises when checking
-- _B (state-return x) = B (state-return x)
-- _B (_,_ x) = B (_,_ x)
-- then Agda does something special for record constructors
-- [Miller unification in the presence of records]
-- (now only done for FULLY APPLIED record constructors!)
-- and produces some garbage solution for _B.
------------------------------------------------------------------------
-- Note that if we define the product type using data instead of
-- record then it works:
data _×′_ (A B : Set) : Set where
_,_ : A → B → A ×′ B
State′ : Set → Set → Set
State′ S X = S → X ×′ S
state-return′ : ∀ {S X} → X → State′ S X
state-return′ x = λ s → x , s
state-monad′ : ∀ {S} → Monad (State′ S)
state-monad′ {S} = record { return = state-return′; _>>=_ = _>>=_ }
where
postulate
_>>=_ : ∀ {A} {B : State′ S A → Set} (m : State′ S A) →
((x : A) → State′ S (B (state-return′ x))) → State′ S (B m)
| {
"alphanum_fraction": 0.5662037037,
"avg_line_length": 32.2388059701,
"ext": "agda",
"hexsha": "b4a0570aad1588caa992f606f222db637a129dc4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue889.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue889.agda",
"max_line_length": 74,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue889.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 704,
"size": 2160
} |
open import AEff
open import EffectAnnotations
open import Renamings
open import Types hiding (``)
open import Relation.Binary.PropositionalEquality hiding ([_])
module Substitutions where
-- SET OF SUBSTITUTIONS BETWEEN CONTEXTS
Sub : Ctx → Ctx → Set
Sub Γ Γ' = {X : VType} → X ∈ Γ → Γ' ⊢V⦂ X
-- IDENTITY AND EXTENSION SUBSTITUTIONS
id-subst : {Γ : Ctx} → Sub Γ Γ
id-subst x = ` x
_[_]s : {Γ Γ' : Ctx} {X : VType} → Sub Γ Γ' → Γ' ⊢V⦂ X → Sub (Γ ∷ X) Γ'
(s [ V ]s) Hd = V
(s [ V ]s) (Tl x) = s x
-- LIFTING SUBSTITUTIONS
lift : {Γ Γ' : Ctx} {X : VType} → Sub Γ Γ' → Sub (Γ ∷ X) (Γ' ∷ X)
lift s Hd = ` Hd
lift s (Tl x) = V-rename Tl (s x)
-- ACTION OF SUBSTITUTION ON WELL-TYPED VALUES AND COMPUTATIONS
mutual
infix 40 _[_]v
infix 40 _[_]m
_[_]v : {Γ Γ' : Ctx} → {X : VType} → Γ ⊢V⦂ X → Sub Γ Γ' → Γ' ⊢V⦂ X
(` x) [ s ]v =
s x
(`` c) [ s ]v =
`` c
(ƛ M) [ s ]v =
ƛ (M [ lift s ]m)
⟨ V ⟩ [ s ]v =
⟨ V [ s ]v ⟩
_[_]m : {Γ Γ' : Ctx} → {C : CType} → Γ ⊢M⦂ C → Sub Γ Γ' → Γ' ⊢M⦂ C
(return V) [ s ]m =
return (V [ s ]v)
(let= M `in N) [ s ]m =
let= (M [ s ]m) `in (N [ lift s ]m)
(letrec M `in N) [ s ]m =
letrec M [ lift (lift s) ]m `in (N [ lift s ]m)
(V · W) [ s ]m =
(V [ s ]v) · (W [ s ]v)
(↑ op p V M) [ s ]m =
↑ op p (V [ s ]v) (M [ s ]m)
(↓ op V M) [ s ]m =
↓ op (V [ s ]v) (M [ s ]m)
(promise op ∣ p ↦ M `in N) [ s ]m =
promise op ∣ p ↦ (M [ lift s ]m) `in (N [ lift s ]m)
(await V until M) [ s ]m =
await (V [ s ]v) until (M [ lift s ]m)
(coerce p q M) [ s ]m =
coerce p q (M [ s ]m)
-- ACTION OF SUBSTITUTION ON WELL-TYPED TERMS
infix 40 _[_]p
_[_]p : {Γ Γ' : Ctx} {o : O} {PP : PType o} → Γ ⊢P⦂ PP → Sub Γ Γ' → Γ' ⊢P⦂ PP
(run M) [ s ]p =
run (M [ s ]m)
(P ∥ Q) [ s ]p =
(P [ s ]p) ∥ (Q [ s ]p)
(↑ op p V P) [ s ]p =
↑ op p (V [ s ]v) (P [ s ]p)
(↓ op V P) [ s ]p =
↓ op (V [ s ]v) (P [ s ]p)
| {
"alphanum_fraction": 0.4680962343,
"avg_line_length": 22.7619047619,
"ext": "agda",
"hexsha": "6427665c6d832413e1dfca80d44c2c0c693576bc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danelahman/aeff-agda",
"max_forks_repo_path": "Substitutions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "danelahman/aeff-agda",
"max_issues_repo_path": "Substitutions.agda",
"max_line_length": 77,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danelahman/aeff-agda",
"max_stars_repo_path": "Substitutions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T22:48:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-17T00:15:00.000Z",
"num_tokens": 906,
"size": 1912
} |
------------------------------------------------------------------------------
-- Problem with a simplified version of the combinators for preorder
-- reasoning
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.Common.FOL.Relation.Binary.PreorderReasoning.ImplicitArgumentsProblem
where
-- Nils suggested a possible problem with the relation
-- R : {A : Set} → A → A → Set
-- R _ _ = ⊤
-- and a version of the combinators for preorder reasoning without use
-- the wrapper data type. This example shows that Nils was right.
------------------------------------------------------------------------------
record ⊤ : Set where
constructor tt
R : {A : Set} → A → A → Set
R _ _ = ⊤
R-refl : {A : Set}{x : A} → R x x
R-refl = tt
R-trans : {A : Set}{x y z : A} → R x y → R y z → R x z
R-trans _ _ = tt
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
module Thesis where
-- From Ulf's thesis (p. 112).
infix 7 _≃_
infix 6 chain>_
infixl 5 _===_by_
infix 4 _qed
data _≃_ {A : Set}(x y : A) : Set where
prf : R x y → x ≃ y
chain>_ : {A : Set}(x : A) → x ≃ x
chain> x = prf (R-refl {x = x})
_===_by_ : {A : Set}{x y : A} → x ≃ y → (z : A) → R y z → x ≃ z
_===_by_ {x = x} {y} (prf p) z q = prf (R-trans {x = x} {y} {z} p q)
_qed : {A : Set}{x y : A} → x ≃ y → R x y
prf p qed = p
-- Example (no problem with implicit arguments).
test : (x y : ℕ) → R x y
test x y =
chain> x
=== y by tt
qed
module SL where
-- Adapted from the Agda standard library 0.8.1 (see
-- Relation/Binary/PreorderReasoning.agda).
infix 7 _≃_
infix 4 begin_
infixr 5 _≡⟨_⟩_
infix 6 _∎
data _≃_ {A : Set}(x y : A) : Set where
prf : R x y → x ≃ y
begin_ : {A : Set}{x y : A} → x ≃ y → R x y
begin_ {x = x} (prf Rxy) = R-refl {x = x}
_≡⟨_⟩_ : {A : Set}(x : A){y z : A} → R x y → y ≃ z → x ≃ z
_≡⟨_⟩_ x {y} {z} Rxy (prf Ryz) = prf (R-trans {x = x} {y} {z} Rxy Ryz)
_∎ : {A : Set}(x : A) → x ≃ x
_∎ x = prf (R-refl {x = x})
-- Example (no problem with implicit arguments).
test : (x y : ℕ) → R x y
test x y =
begin
x ≡⟨ tt ⟩
y
∎
module NonWrapper where
-- A set of combinators without request a wrapper data type (Mu,
-- S.-C., Ko, H.-S. and Jansson, P. (2009)).
infixr 5 _≡⟨_⟩_
infix 6 _∎
_≡⟨_⟩_ : {A : Set}(x : A){y z : A} → R x y → R y z → R x z
_≡⟨_⟩_ x {y} {z} x≡y y≡z = R-trans {x = x} {y} {z} x≡y y≡z
_∎ : {A : Set}(x : A) → R x x
_∎ x = R-refl {x = x}
-- Example.
test : (x y : ℕ) → R x y
test x y = x ≡⟨ tt ⟩
y ∎
------------------------------------------------------------------------------
-- References
--
-- Mu, S.-C., Ko, H.-S. and Jansson, P. (2009). Algebra of programming
-- in Agda: Dependent types for relational program derivation. Journal
-- of Functional Programming 19.5, pp. 545–579.
| {
"alphanum_fraction": 0.4773901809,
"avg_line_length": 25.5867768595,
"ext": "agda",
"hexsha": "84aef8f47e4e5fb39fd8a0e1b02c9b055396a582",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PreorderReasoning/ImplicitArgumentsProblem.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PreorderReasoning/ImplicitArgumentsProblem.agda",
"max_line_length": 80,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PreorderReasoning/ImplicitArgumentsProblem.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1140,
"size": 3096
} |
{- wip, coming to realise that the instance of IsSetoid defined in Data.Equality.properties is over-eager (defining _≡_ for all (A : Set (a : Level)), _≡̇_ for ∀ (x : A : Set (a : Level)) → (B : A → Set (b : Level)) x -}
-- add samples of stuff from unification (AList, etc.)
module Oscar.Data5 where
record ⊤ : Set where
constructor tt
Const_ : ∀ {a} {A : Set a} {b} {B : Set b} → B → A → B
Const_ x _ = x
infixr 20 _∷_
-- List
data ⟦_⟧ {a} (A : Set a) : Set a where
∅ : ⟦ A ⟧
_∷_ : A → ⟦ A ⟧ → ⟦ A ⟧
-- Nat
⟦⟧ = ⟦ ⊤ ⟧
infix 21 ¡_
pattern ¡_ ⟦A⟧ = tt ∷ ⟦A⟧
--¡ : ⟦⟧ → ⟦⟧
--¡ ⟦A⟧ = tt ∷ ⟦A⟧
-- Fin (with a payload)
data ⟦_⟧[_] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where
∅ : ∀ {n} → ⟦ A ⟧[ ¡ n ]
_∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ] → ⟦ A ⟧[ ¡ n ]
⟦⟧[_] = ⟦ Const ⊤ ⟧[_]
-- Vec (with an (optional) index)
data ⟦_⟧[_₀] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where
∅ : ⟦ A ⟧[ ∅ ₀]
_∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ₀] → ⟦ A ⟧[ ¡ n ₀]
⟦⟧[_₀] = ⟦ Const ⊤ ⟧[_₀]
-- m ≤ n, counting down from n-1 to m
data ⟦_⟧[_≤_↓] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where
∅ : ⟦ A ⟧[ m ≤ m ↓]
_∷_ : ∀ {n} → A n → ⟦ A ⟧[ m ≤ n ↓] → ⟦ A ⟧[ m ≤ ¡ n ↓]
⟦⟧[_≤_↓] = ⟦ Const ⊤ ⟧[_≤_↓]
-- m ≤ n, counting up from m to n-1
data ⟦_⟧[↑_≤_] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where
∅ : ⟦ A ⟧[↑ m ≤ m ]
_∷_ : ∀ {n} → A m → ⟦ A ⟧[↑ ¡ m ≤ n ] → ⟦ A ⟧[↑ m ≤ n ]
⟦⟧[↑_≤_] = ⟦ Const ⊤ ⟧[↑_≤_]
-- Inj (almost)
data ⟦_⟧[↓_≤_↓] {a} (A : ⟦⟧ → ⟦⟧ → Set a) : ⟦⟧ → ⟦⟧ → Set a where
∅ : ∀ {n} → ⟦ A ⟧[↓ ∅ ≤ n ↓]
_∷_ : ∀ {m n} → A m n → ⟦ A ⟧[↓ m ≤ n ↓] → ⟦ A ⟧[↓ ¡ m ≤ ¡ n ↓]
⟦⟧[↓_≤_↓] = ⟦ Const Const ⊤ ⟧[↓_≤_↓]
⟦_⟧[_⇒_]∞ : ∀ {a} (A : ⟦⟧ → Set a) → ⟦⟧ → ⟦⟧ → Set a
⟦ A ⟧[ m ⇒ n ]∞ = A m → A n
open import Oscar.Category.Semigroupoid
open import Oscar.Category.Category
open import Oscar.Category.Morphism
open import Oscar.Category.Setoid
--open import Oscar.Data.Equality
--open import Oscar.Data.Equality.properties
open import Oscar.Function
module _ {𝔬 𝔪 𝔮} (G : Semigroupoid 𝔬 𝔪 𝔮) where
open Semigroupoid G
{-
_≋̇_ : ∀ {a} {A : ⋆ → Set a} {m n : ⋆} → (A m → A n) → (A m → A n) → Set 𝔮
_≋̇_ {A = A} {m = m} m→n₁ m→n₂ = {!∀ (am : A m) → m→n₁ am ≋ m→n₂ am!}
cat2 : ∀ {a} (A : ⋆ → Set a) → Category {!!} {!!} {!!}
Semigroupoid.⋆ (Category.semigroupoid (cat2 A)) = ⋆
Setoid.⋆ ((Semigroupoid.𝔐 (Category.semigroupoid (cat2 A)) Morphism.⇒ m) n) = A m → A n
IsSetoid._≋_ (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2 A)) Morphism.⇒ m) n)) = _≡̇_
IsSetoid.isEquivalence (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2 A)) Morphism.⇒ m) n)) = it
Semigroupoid._∙_ (Category.semigroupoid (cat2 A)) g f = g ∘ f
Semigroupoid.isSemigroupoid (Category.semigroupoid (cat2 A)) = it
Category.ε (cat2 A) = id
Category.isCategory (cat2 A) = it
-}
cat2G : ∀ {a} (A : ⋆ → Set a) → ∀ ℓ ⦃ _ : ∀ {n : ⋆} → IsSetoid (A n) ℓ ⦄ → Category {!!} {!!} {!!}
Semigroupoid.⋆ (Category.semigroupoid (cat2G A ℓ)) = ⋆
Setoid.⋆ ((Semigroupoid.𝔐 (Category.semigroupoid (cat2G A ℓ)) Morphism.⇒ m) n) = A m → A n
IsSetoid._≋_ (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2G A ℓ)) Morphism.⇒ m) n)) m↦n₁ m↦n₂ = ∀ (am : A m) → m↦n₁ am ≋ m↦n₂ am
-- ∀ (am : A m) → m↦n₁ am ≋ m↦n₂ am
{-
_≋̇_ : ∀ {a} {A : ⋆ → Set a} {m n : ⋆} → (A m → A n) → (A m → A n) → Set 𝔮
_≋̇_ {A = A} {m = m} m→n₁ m→n₂ = {!∀ (am : A m) → m→n₁ am ≋ m→n₂ am!}
-}
IsSetoid.isEquivalence (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2G A ℓ)) Morphism.⇒ m) n)) = {!it!}
Semigroupoid._∙_ (Category.semigroupoid (cat2G A ℓ)) g f = g ∘ f
Semigroupoid.isSemigroupoid (Category.semigroupoid (cat2G A ℓ)) = {!it!}
Category.ε (cat2G A ℓ) = id
Category.isCategory (cat2G A ℓ) = {!it!}
infix 21 ‼_
pattern ‼_ ⟦A⟧ = tt ∷ ⟦A⟧ -- tricky, works for all above _∷_ constructors only because it is defined afterwards, won't work for any later-defined constructors
open import Agda.Primitive
open import Oscar.Data.Product
open import Oscar.Function
postulate
ℓ : Level
Term : ⟦⟧ → Set ℓ
Step : ⟦⟧ → Set ℓ
Fin = ⟦⟧[_]
Inj = ⟦ Const Fin ⟧[↓_≤_↓]
Terms = λ N n → ⟦ Const (Term n) ⟧[ N ₀]
AList = ⟦ (λ n → Term n × Fin (¡ n)) ⟧[_≤_↓]
Fx : ∀ {a} {A : Set a} → A → A → ∀ {b₁} (B₁ : A → Set b₁) → ∀ {b₂} (B₂ : A → Set b₂) → Set (b₁ ⊔ b₂)
Fx m n B₁ B₂ = B₁ m → B₂ n
Fx₁ : ∀ {a} {A : Set a} → A → ∀ {b₁} (B₁ : A → Set b₁) → ∀ {b₂} (B₂ : A → Set b₂) → Set (b₁ ⊔ b₂)
Fx₁ n B₁ B₂ = Fx n n B₁ B₂
ListStep = λ n → ⟦ Step n ⟧
Rel : ∀ {a} {A : Set a} {b₁} (B₁ : A → Set b₁) {b₂} (B₂ : A → Set b₂) {c₁} (C₁ : A → Set c₁) {c₂} (C₂ : A → Set c₂) → Set (a ⊔ b₁ ⊔ b₂ ⊔ c₁ ⊔ c₂)
Rel B₁ B₂ C₁ C₂ = ∀ {m n} → Fx m n B₁ B₂ → Fx m n C₁ C₂
Morph : ∀ {a} {A : Set a} {b₁} {b₂} (B : (A → Set b₁) × (A → Set b₂)) {c₁} {c₂} (C₂ : (A → Set c₁) × (A → Set c₂)) → Set (a ⊔ b₁ ⊔ b₂ ⊔ c₁ ⊔ c₂)
Morph (B₁ , B₂) (C₁ , C₂) = ∀ {m n} → Fx m n B₁ B₂ → Fx m n C₁ C₂
-- functor mappings
postulate
_◃_ : Morph (Fin , Term) (Term , Term)
_◃s_ : ∀ N → Morph (Fin , Term) (Terms N , Terms N)
sub : ∀ {m n} → AList m n → Fx m n Fin Term
fmapS : Morph (Term , Term) (Step , Step)
_◃S_ : Morph (Fin , Term) (ListStep , ListStep)
-- ?
postulate
_⊹_ : ∀ {n} → ⟦ Step n ⟧ → Fx₁ n Term Term
testNat : ⟦⟧
testNat = ¡ ∅
testListNat : ⟦ ⟦⟧ ⟧
testListNat = ¡ ∅ ∷ ‼ ∅ ∷ ‼ ‼ ∅ ∷ ∅ ∷ ¡ ¡ ¡ ∅ ∷ ∅
testFin : ⟦⟧[ ¡ ¡ ∅ ]
testFin = ‼ ∅
test≤↓ : ⟦⟧[ ‼ ‼ ‼ ∅ ≤ ‼ ‼ ‼ ‼ ‼ ∅ ↓]
test≤↓ = ‼ ‼ ∅
⓪ ⑴ ⑵ ⑶ : ⟦⟧
⓪ = ∅
⑴ = ‼ ∅
⑵ = ‼ ⑴
⑶ = ‼ ⑵
testInj : Inj ⑵ ⑶
testInj = ‼ ∅ ∷ ∅ ∷ ∅
| {
"alphanum_fraction": 0.5027402265,
"avg_line_length": 31.28,
"ext": "agda",
"hexsha": "c2545d039caa9d4ec945bf63066f469c0b568c0b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data5.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data5.agda",
"max_line_length": 220,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data5.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2829,
"size": 5474
} |
module ProjectionLikeAndMatching where
data Unit : Set where
* : Unit
data Box A : Set where
[_] : A → Box A
-- Unbox should not be considered projection-like since it's matching on more than
-- the eliminatee.
unbox : ∀ {A} → Box A → Unit → A
unbox [ x ] * = x
postulate
Thm : {A : Set} → A → Set
prf : {A : Set}(x : A) → Thm x
-- If unbox was projection-like we would end up with
-- [_] (apply x) (elim unbox) (apply u) : A
-- and we wouldn't be able to reconstruct the parameter
-- argument to [_].
lem : ∀ {A} (x : A) u → Thm (unbox [ x ] u)
lem x u = prf (unbox [ x ] u)
| {
"alphanum_fraction": 0.6108291032,
"avg_line_length": 24.625,
"ext": "agda",
"hexsha": "481e6eea60ee108dee60aaa1f7d45f011b94f8c8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/ProjectionLikeAndMatching.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/ProjectionLikeAndMatching.agda",
"max_line_length": 82,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/ProjectionLikeAndMatching.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 202,
"size": 591
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Induced preorders
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.InducedPreorders
{s₁ s₂}
(S : Setoid s₁ s₂) -- The underlying equality.
where
open import Function
open import Data.Product
open Setoid S
-- Every respectful unary relation induces a preorder. (No claim is
-- made that this preorder is unique.)
InducedPreorder₁ : ∀ {p} (P : Carrier → Set p) →
P Respects _≈_ → Preorder _ _ _
InducedPreorder₁ P resp = record
{ _≈_ = _≈_
; _∼_ = λ c₁ c₂ → P c₁ → P c₂
; isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = resp
; trans = flip _∘′_
}
}
-- Every respectful binary relation induces a preorder. (No claim is
-- made that this preorder is unique.)
InducedPreorder₂ : ∀ {a r} {A : Set a} →
(_R_ : A → Carrier → Set r) →
(∀ {x} → _R_ x Respects _≈_) → Preorder _ _ _
InducedPreorder₂ _R_ resp = record
{ _≈_ = _≈_
; _∼_ = λ c₁ c₂ → ∀ {a} → a R c₁ → a R c₂
; isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = λ c₁≈c₂ → resp c₁≈c₂
; trans = λ c₁∼c₂ c₂∼c₃ → c₂∼c₃ ∘ c₁∼c₂
}
}
| {
"alphanum_fraction": 0.5129682997,
"avg_line_length": 28.3265306122,
"ext": "agda",
"hexsha": "53d343b2d6602e0493bbe84a40a78f4fe9e36374",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/InducedPreorders.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/InducedPreorders.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/InducedPreorders.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 425,
"size": 1388
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Setoids.Facts.Terminal where
open import Level
open import Relation.Binary using (Setoid)
open import Cats.Category
open import Cats.Category.Setoids using (Setoids)
import Data.Unit as Unit
⊤ : ∀ {l l′} → Setoid l l′
⊤ = record
{ Carrier = Lift _ Unit.⊤
; _≈_ = λ _ _ → Lift _ Unit.⊤
}
instance
hasTerminal : ∀ {l l≈} → HasTerminal (Setoids l l≈)
hasTerminal = record { ⊤ = ⊤ }
| {
"alphanum_fraction": 0.6615044248,
"avg_line_length": 19.652173913,
"ext": "agda",
"hexsha": "9f9f5f0f201c65342a02f6fdff6e150c0368e249",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Setoids/Facts/Terminal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Setoids/Facts/Terminal.agda",
"max_line_length": 53,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Setoids/Facts/Terminal.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 146,
"size": 452
} |
module Data.QuadTree.Implementation.SafeFunctions where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Lens.Lens
open import Data.Logic
open import Data.QuadTree.Implementation.PropDepthRelation
open import Data.QuadTree.Implementation.Definition
open import Data.QuadTree.Implementation.ValidTypes
open import Data.QuadTree.Implementation.QuadrantLenses
open import Data.QuadTree.Implementation.DataLenses
{-# FOREIGN AGDA2HS
{-# LANGUAGE Safe #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Rank2Types #-}
import Data.Nat
import Data.Lens.Lens
import Data.Logic
import Data.QuadTree.Implementation.Definition
import Data.QuadTree.Implementation.ValidTypes
import Data.QuadTree.Implementation.QuadrantLenses
import Data.QuadTree.Implementation.DataLenses
#-}
---- Safe functions
makeTreeSafe : {t : Set} {{eqT : Eq t}} -> (size : Nat × Nat) -> (v : t) -> VQuadTree t {maxDepth $ Wrapper size (Leaf v)}
makeTreeSafe (w , h) v = CVQuadTree (Wrapper (w , h) (Leaf v)) {andCombine (zeroLteAny (log2up $ max w h)) IsTrue.itsTrue} {eqReflexivity (maxDepth $ Wrapper (w , h) (Leaf v))}
{-# COMPILE AGDA2HS makeTreeSafe #-}
getLocationSafe : {t : Set} {{eqT : Eq t}}
-> (loc : Nat × Nat) -> (dep : Nat)
-> (qt : VQuadTree t {dep})
-> {.(IsTrue (isInsideQuadTree loc (qtFromSafe qt)))}
-> t
getLocationSafe index dep vqt {inside} = view (atLocation index dep {insideQTtoInsidePow index vqt inside}) vqt
{-# COMPILE AGDA2HS getLocationSafe #-}
setLocationSafe : {t : Set} {{eqT : Eq t}}
-> (loc : Nat × Nat) -> (dep : Nat)
-> t -> (qt : VQuadTree t {dep})
-> {.(IsTrue (isInsideQuadTree loc (qtFromSafe qt)))}
-> VQuadTree t {dep}
setLocationSafe index dep v vqt {inside} = set (atLocation index dep {insideQTtoInsidePow index vqt inside}) v vqt
{-# COMPILE AGDA2HS setLocationSafe #-}
mapLocationSafe : {t : Set} {{eqT : Eq t}}
-> (loc : Nat × Nat) -> (dep : Nat)
-> (t -> t) -> (qt : VQuadTree t {dep})
-> {.(IsTrue (isInsideQuadTree loc (qtFromSafe qt)))}
-> VQuadTree t {dep}
mapLocationSafe index dep f vqt {inside} = over (atLocation index dep {insideQTtoInsidePow index vqt inside}) f vqt
{-# COMPILE AGDA2HS mapLocationSafe #-} | {
"alphanum_fraction": 0.7068493151,
"avg_line_length": 40.5555555556,
"ext": "agda",
"hexsha": "d67d72c26800ef95e6f61d246b5d8ae348c6aed3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/QuadTree/Implementation/SafeFunctions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/QuadTree/Implementation/SafeFunctions.agda",
"max_line_length": 176,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/QuadTree/Implementation/SafeFunctions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 649,
"size": 2190
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.