hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
126ad82ec80e0cc0f4a6e85bb6ec77a6564206cd
| 6,273
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Base.agda
|
apabepa10/cubical
|
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Base.agda
|
apabepa10/cubical
|
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Base.agda
|
apabepa10/cubical
|
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.CommRing.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring.Base
open Iso
private
variable
ℓ : Level
record IsCommRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor iscommring
field
isRing : IsRing 0r 1r _+_ _·_ -_
·-comm : (x y : R) → x · y ≡ y · x
open IsRing isRing public
record CommRingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor commringstr
field
0r : A
1r : A
_+_ : A → A → A
_·_ : A → A → A
-_ : A → A
isCommRing : IsCommRing 0r 1r _+_ _·_ -_
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsCommRing isCommRing public
CommRing : Type (ℓ-suc ℓ)
CommRing = TypeWithStr _ CommRingStr
makeIsCommRing : {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R}
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-comm : (x y : R) → x · y ≡ y · x)
→ IsCommRing 0r 1r _+_ _·_ -_
makeIsCommRing {_+_ = _+_} is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm =
iscommring (makeIsRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid
(λ x → ·-comm _ _ ∙ ·-rid x) ·-rdist-+
(λ x y z → ·-comm _ _ ∙∙ ·-rdist-+ z x y ∙∙ λ i → (·-comm z x i) + (·-comm z y i))) ·-comm
makeCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-comm : (x y : R) → x · y ≡ y · x)
→ CommRing
makeCommRing 0r 1r _+_ _·_ -_ is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm =
_ , commringstr _ _ _ _ _ (makeIsCommRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm)
CommRing→Ring : CommRing {ℓ} → Ring
CommRing→Ring (_ , commringstr _ _ _ _ _ H) = _ , ringstr _ _ _ _ _ (IsCommRing.isRing H)
CommRingEquiv : (R S : CommRing) (e : ⟨ R ⟩ ≃ ⟨ S ⟩) → Type ℓ
CommRingEquiv R S e = RingEquiv (CommRing→Ring R) (CommRing→Ring S) e
CommRingHom : (R S : CommRing) → Type ℓ
CommRingHom R S = RingHom (CommRing→Ring R) (CommRing→Ring S)
module CommRingΣTheory {ℓ} where
open RingΣTheory
CommRingAxioms : (R : Type ℓ) (s : RawRingStructure R) → Type ℓ
CommRingAxioms R (_+_ , 1r , _·_) = RingAxioms R (_+_ , 1r , _·_)
× ((x y : R) → x · y ≡ y · x)
CommRingStructure : Type ℓ → Type ℓ
CommRingStructure = AxiomsStructure RawRingStructure CommRingAxioms
CommRingΣ : Type (ℓ-suc ℓ)
CommRingΣ = TypeWithStr ℓ CommRingStructure
CommRingEquivStr : StrEquiv CommRingStructure ℓ
CommRingEquivStr = AxiomsEquivStr RawRingEquivStr CommRingAxioms
isPropCommRingAxioms : (R : Type ℓ) (s : RawRingStructure R)
→ isProp (CommRingAxioms R s)
isPropCommRingAxioms R (_·_ , 0r , _+_) =
isPropΣ (isPropRingAxioms R (_·_ , 0r , _+_))
λ { (_ , x , _) → isPropΠ2 λ _ _ →
x .IsMonoid.isSemigroup .IsSemigroup.is-set _ _}
CommRing→CommRingΣ : CommRing → CommRingΣ
CommRing→CommRingΣ (_ , commringstr _ _ _ _ _ (iscommring G C)) =
_ , _ , Ring→RingΣ (_ , ringstr _ _ _ _ _ G) .snd .snd , C
CommRingΣ→CommRing : CommRingΣ → CommRing
CommRingΣ→CommRing (_ , _ , G , C) =
_ , commringstr _ _ _ _ _ (iscommring (RingΣ→Ring (_ , _ , G) .snd .RingStr.isRing) C)
CommRingIsoCommRingΣ : Iso CommRing CommRingΣ
CommRingIsoCommRingΣ =
iso CommRing→CommRingΣ CommRingΣ→CommRing (λ _ → refl) (λ _ → refl)
commRingUnivalentStr : UnivalentStr CommRingStructure CommRingEquivStr
commRingUnivalentStr = axiomsUnivalentStr _ isPropCommRingAxioms rawRingUnivalentStr
CommRingΣPath : (R S : CommRingΣ) → (R ≃[ CommRingEquivStr ] S) ≃ (R ≡ S)
CommRingΣPath = SIP commRingUnivalentStr
CommRingEquivΣ : (R S : CommRing) → Type ℓ
CommRingEquivΣ R S = CommRing→CommRingΣ R ≃[ CommRingEquivStr ] CommRing→CommRingΣ S
CommRingPath : (R S : CommRing) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] CommRingEquiv R S e) ≃ (R ≡ S)
CommRingPath R S =
Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] CommRingEquiv R S e ≃⟨ isoToEquiv RingIsoΣPath ⟩
CommRingEquivΣ R S ≃⟨ CommRingΣPath _ _ ⟩
CommRing→CommRingΣ R ≡ CommRing→CommRingΣ S
≃⟨ isoToEquiv (invIso (congIso CommRingIsoCommRingΣ)) ⟩
R ≡ S ■
CommRingPath : (R S : CommRing {ℓ}) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] CommRingEquiv R S e) ≃ (R ≡ S)
CommRingPath = CommRingΣTheory.CommRingPath
isPropIsCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
→ isProp (IsCommRing 0r 1r _+_ _·_ -_)
isPropIsCommRing 0r 1r _+_ _·_ -_ (iscommring RR RC) (iscommring SR SC) =
λ i → iscommring (isPropIsRing _ _ _ _ _ RR SR i)
(isPropComm RC SC i)
where
isSetR : isSet _
isSetR = RR .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropComm : isProp ((x y : _) → x · y ≡ y · x)
isPropComm = isPropΠ2 λ _ _ → isSetR _ _
| 38.25
| 115
| 0.565599
|
570c0211ec6243fd8c9454f771ced967b5d757fa
| 1,366
|
agda
|
Agda
|
examples/lib/Logic/Congruence.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/lib/Logic/Congruence.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/lib/Logic/Congruence.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Logic.Congruence where
import Prelude
import Logic.Relations
import Logic.Equivalence
open Prelude
open Logic.Relations
open Logic.Equivalence using (Equivalence)
renaming (module Equivalence to Proj)
data Congruence (A : Set) : Set1 where
congruence :
(Eq : Equivalence A) ->
Congruent (Proj._==_ Eq) ->
Congruence A
module Projections where
eq : {A : Set} -> Congruence A -> Rel A
eq (congruence Eq _) = Proj._==_ Eq
refl : {A : Set}(Cong : Congruence A) -> Reflexive (eq Cong)
refl (congruence Eq _) = Proj.refl Eq
sym : {A : Set}(Cong : Congruence A) -> Symmetric (eq Cong)
sym (congruence Eq _) = Proj.sym Eq
trans : {A : Set}(Cong : Congruence A) -> Transitive (eq Cong)
trans (congruence Eq _) = Proj.trans Eq
cong : {A : Set}(Cong : Congruence A) -> Congruent (eq Cong)
cong (congruence _ c) = c
module Congruence {A : Set}(Cong : Congruence A) where
_==_ = Projections.eq Cong
refl = Projections.refl Cong
sym = Projections.sym Cong
trans = Projections.trans Cong
cong = Projections.cong Cong
cong2 : (f : A -> A -> A)(a b c d : A) -> a == c -> b == d -> f a b == f c d
cong2 f a b c d ac bd = trans _ _ _ rem1 rem2
where
rem1 : f a b == f a d
rem1 = cong (f a) _ _ bd
rem2 : f a d == f c d
rem2 = cong (flip f d) _ _ ac
| 25.773585
| 78
| 0.611274
|
12c16ab75c3ee77fdd61e205339d15373792c12d
| 24,652
|
agda
|
Agda
|
Cubical/HITs/Truncation/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/HITs/Truncation/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Truncation/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.HITs.Truncation.Properties where
open import Cubical.Data.NatMinusOne
open import Cubical.HITs.Truncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Equiv.PathSplit
open isPathSplitEquiv
open import Cubical.Modalities.Modality
open Modality
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Data.Unit
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.S1
open import Cubical.HITs.Susp.Base
open import Cubical.HITs.Nullification as Null hiding (rec; elim)
open import Cubical.HITs.PropositionalTruncation as PropTrunc
renaming (∥_∥ to ∥_∥₁; ∣_∣ to ∣_∣₁; squash to squash₁) using ()
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂)
open import Cubical.HITs.GroupoidTruncation as GpdTrunc using (∥_∥₃; ∣_∣₃; squash₃)
open import Cubical.HITs.2GroupoidTruncation as 2GpdTrunc using (∥_∥₄; ∣_∣₄; squash₄)
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
sphereFill : (n : ℕ) (f : S₊ n → A) → Type _
sphereFill {A = A} n f = Σ[ top ∈ A ] ((x : S₊ n) → top ≡ f x)
isSphereFilled : ℕ → Type ℓ → Type ℓ
isSphereFilled n A = (f : S₊ n → A) → sphereFill n f
isSphereFilled∥∥ : {n : ℕ} → isSphereFilled n (HubAndSpoke A n)
isSphereFilled∥∥ f = (hub f) , (spoke f)
isSphereFilled→isOfHLevel : (n : ℕ) → isSphereFilled n A → isOfHLevel (suc n) A
isSphereFilled→isOfHLevel {A = A} zero h x y = sym (snd (h f) true) ∙ snd (h f) false
where
f : Bool → A
f true = x
f false = y
isSphereFilled→isOfHLevel {A = A} (suc zero) h x y =
J (λ y q → (p : x ≡ y) → q ≡ p) (helper x)
where
helper : (x : A) (p : x ≡ x) → refl ≡ p
helper x p i j =
hcomp (λ k → λ { (i = i0) → h S¹→A .snd base k
; (i = i1) → p j
; (j = i0) → h S¹→A .snd base (i ∨ k)
; (j = i1) → h S¹→A .snd base (i ∨ k)})
(h S¹→A .snd (loop j) i)
where
S¹→A : S¹ → A
S¹→A base = x
S¹→A (loop i) = p i
isSphereFilled→isOfHLevel {A = A} (suc (suc n)) h x y =
isSphereFilled→isOfHLevel (suc n) (helper h x y)
where
helper : {n : ℕ} → isSphereFilled (suc (suc n)) A → (x y : A) → isSphereFilled (suc n) (x ≡ y)
helper {n = n} h x y f = sym (snd (h f') north) ∙ (snd (h f') south) , r
where
f' : Susp (S₊ (suc n)) → A
f' north = x
f' south = y
f' (merid u i) = f u i
r : (s : S₊ (suc n)) → sym (snd (h f') north) ∙ (snd (h f') south) ≡ f s
r s i j = hcomp
(λ k →
λ { (i = i1) → snd (h f') (merid s j) k
; (j = i0) → snd (h f') north (k ∨ (~ i))
; (j = i1) → snd (h f') south k
})
(snd (h f') north (~ i ∧ ~ j))
isOfHLevel→isSphereFilled : (n : ℕ) → isOfHLevel (suc n) A → isSphereFilled n A
isOfHLevel→isSphereFilled zero h f = (f true) , (λ _ → h _ _)
isOfHLevel→isSphereFilled {A = A} (suc zero) h f = (f base) , toPropElim (λ _ → h _ _) refl
isOfHLevel→isSphereFilled {A = A} (suc (suc n)) h =
helper λ x y → isOfHLevel→isSphereFilled (suc n) (h x y)
where
helper : {n : ℕ} → ((x y : A) → isSphereFilled (suc n) (x ≡ y))
→ isSphereFilled (suc (suc n)) A
helper {n = n} h f = f north , r
where
r : (x : S₊ (suc (suc n))) → f north ≡ f x
r north = refl
r south = h (f north) (f south) (λ x → cong f (merid x)) .fst
r (merid x i) j = hcomp (λ k → λ { (i = i0) → f north
; (i = i1) → h (f north) (f south) (λ x → cong f (merid x)) .snd x (~ k) j
; (j = i0) → f north
; (j = i1) → f (merid x i) }) (f (merid x (i ∧ j)))
isOfHLevelTrunc : (n : ℕ) → isOfHLevel n (∥ A ∥ n)
isOfHLevelTrunc zero = isOfHLevelUnit* 0
isOfHLevelTrunc (suc n) = isSphereFilled→isOfHLevel n isSphereFilled∥∥
isOfHLevelTruncPath : {n : ℕ} {x y : hLevelTrunc n A} → isOfHLevel n (x ≡ y)
isOfHLevelTruncPath {n = n} = isOfHLevelPath n (isOfHLevelTrunc n) _ _
rec₊ : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel (suc n) B →
(A → B) →
hLevelTrunc (suc n) A →
B
rec₊ h g ∣ x ∣ = g x
rec₊ {n = n} {B = B} hB g (hub f) = isOfHLevel→isSphereFilled n hB (λ x → rec₊ hB g (f x)) .fst
rec₊ {n = n} hB g (spoke f x i) =
isOfHLevel→isSphereFilled n hB (λ x → rec₊ hB g (f x)) .snd x i
rec : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel n B →
(A → B) →
hLevelTrunc n A →
B
rec {n = zero} h g t = h .fst
rec {n = suc n} = rec₊
rec2 : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel n B →
(A → A → B) →
(t u : hLevelTrunc n A)
→ B
rec2 h g = rec (isOfHLevelΠ _ (λ _ → h)) (λ a → rec h (λ b → g a b))
rec3 : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel n B →
(A → A → A → B) →
(t u v : hLevelTrunc n A)
→ B
rec3 h g = rec2 (isOfHLevelΠ _ (λ _ → h)) (λ a b → rec h (λ c → g a b c))
elim₊ : {n : ℕ}
{B : ∥ A ∥ (suc n) → Type ℓ'}
(hB : (x : ∥ A ∥ (suc n)) → isOfHLevel (suc n) (B x))
(g : (a : A) → B (∣ a ∣))
(x : ∥ A ∥ (suc n)) →
B x
elim₊ hB g (∣ a ∣ ) = g a
elim₊ {B = B} hB g (hub f) =
isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (elim₊ hB g (f x)) ) .fst
elim₊ {B = B} hB g (spoke f x i) =
toPathP {A = λ i → B (spoke f x (~ i))}
(sym (isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (elim₊ hB g (f x))) .snd x))
(~ i)
elim : {n : ℕ}
{B : ∥ A ∥ n → Type ℓ'}
(hB : (x : ∥ A ∥ n) → isOfHLevel n (B x))
(g : (a : A) → B (∣ a ∣ₕ))
(x : ∥ A ∥ n) →
B x
elim {n = zero} h g t = h t .fst
elim {n = suc n} = elim₊
elim2 : {n : ℕ}
{B : ∥ A ∥ n → ∥ A ∥ n → Type ℓ'}
(hB : ((x y : ∥ A ∥ n) → isOfHLevel n (B x y)))
(g : (a b : A) → B ∣ a ∣ₕ ∣ b ∣ₕ)
(x y : ∥ A ∥ n) →
B x y
elim2 hB g = elim (λ _ → isOfHLevelΠ _ (λ _ → hB _ _)) λ a →
elim (λ _ → hB _ _) (λ b → g a b)
elim3 : {n : ℕ}
{B : (x y z : ∥ A ∥ n) → Type ℓ'}
(hB : ((x y z : ∥ A ∥ n) → isOfHLevel n (B x y z)))
(g : (a b c : A) → B (∣ a ∣ₕ) ∣ b ∣ₕ ∣ c ∣ₕ)
(x y z : ∥ A ∥ n) →
B x y z
elim3 hB g = elim2 (λ _ _ → isOfHLevelΠ _ (hB _ _)) λ a b →
elim (λ _ → hB _ _ _) (λ c → g a b c)
isContr→isContr∥ : (n : ℕ) → isContr A → isContr (∥ A ∥ n)
isContr→isContr∥ zero _ = tt* , (λ _ _ → tt*)
isContr→isContr∥ (suc n) contr = ∣ fst contr ∣ , (elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a i → ∣ snd contr a i ∣))
isOfHLevelMin→isOfHLevel : {n m : ℕ} → isOfHLevel (min n m) A → isOfHLevel n A × isOfHLevel m A
isOfHLevelMin→isOfHLevel {n = zero} {m = m} h = h , isContr→isOfHLevel m h
isOfHLevelMin→isOfHLevel {n = suc n} {m = zero} h = (isContr→isOfHLevel (suc n) h) , h
isOfHLevelMin→isOfHLevel {A = A} {n = suc n} {m = suc m} h =
subst (λ x → isOfHLevel x A) (helper n m)
(isOfHLevelPlus (suc n ∸ (suc (min n m))) h)
, subst (λ x → isOfHLevel x A) ((λ i → m ∸ (minComm n m i) + suc (minComm n m i)) ∙ helper m n)
(isOfHLevelPlus (suc m ∸ (suc (min n m))) h)
where
helper : (n m : ℕ) → n ∸ min n m + suc (min n m) ≡ suc n
helper zero zero = refl
helper zero (suc m) = refl
helper (suc n) zero = cong suc (+-comm n 1)
helper (suc n) (suc m) = +-suc _ _ ∙ cong suc (helper n m)
ΣTruncElim : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {n m : ℕ}
{B : (x : ∥ A ∥ n) → Type ℓ'}
{C : (Σ[ a ∈ (∥ A ∥ n) ] (∥ B a ∥ m)) → Type ℓ''}
→ ((x : (Σ[ a ∈ (∥ A ∥ n) ] (∥ B a ∥ m))) → isOfHLevel (min n m) (C x))
→ ((a : A) (b : B (∣ a ∣ₕ)) → C (∣ a ∣ₕ , ∣ b ∣ₕ))
→ (x : (Σ[ a ∈ (∥ A ∥ n) ] (∥ B a ∥ m))) → C x
ΣTruncElim hB g (a , b) =
elim (λ x → isOfHLevelΠ _ λ b → isOfHLevelMin→isOfHLevel (hB (x , b)) .fst )
(λ a → elim (λ _ → isOfHLevelMin→isOfHLevel (hB (∣ a ∣ₕ , _)) .snd) λ b → g a b)
a b
truncIdempotentIso : (n : ℕ) → isOfHLevel n A → Iso (∥ A ∥ n) A
truncIdempotentIso zero hA = isContr→Iso (isOfHLevelUnit* 0) hA
Iso.fun (truncIdempotentIso (suc n) hA) = rec hA λ a → a
Iso.inv (truncIdempotentIso (suc n) hA) = ∣_∣
Iso.rightInv (truncIdempotentIso (suc n) hA) _ = refl
Iso.leftInv (truncIdempotentIso (suc n) hA) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ _ → refl
truncIdempotent≃ : (n : ℕ) → isOfHLevel n A → ∥ A ∥ n ≃ A
truncIdempotent≃ n hA = isoToEquiv (truncIdempotentIso n hA)
truncIdempotent : (n : ℕ) → isOfHLevel n A → ∥ A ∥ n ≡ A
truncIdempotent n hA = ua (truncIdempotent≃ n hA)
HLevelTruncModality : ∀ {ℓ} (n : HLevel) → Modality ℓ
isModal (HLevelTruncModality n) = isOfHLevel n
isPropIsModal (HLevelTruncModality n) = isPropIsOfHLevel n
◯ (HLevelTruncModality n) = hLevelTrunc n
◯-isModal (HLevelTruncModality n) = isOfHLevelTrunc n
η (HLevelTruncModality zero) _ = tt*
η (HLevelTruncModality (suc n)) = ∣_∣
◯-elim (HLevelTruncModality zero) cB _ tt* = cB tt* .fst
◯-elim (HLevelTruncModality (suc n)) = elim
◯-elim-β (HLevelTruncModality zero) cB f a = cB tt* .snd (f a)
◯-elim-β (HLevelTruncModality (suc n)) = λ _ _ _ → refl
◯-=-isModal (HLevelTruncModality zero) x y = (isOfHLevelUnit* 1 x y) , (isOfHLevelUnit* 2 x y _)
◯-=-isModal (HLevelTruncModality (suc n)) = isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n))
-- universal property
univTrunc : ∀ {ℓ} (n : HLevel) {B : TypeOfHLevel ℓ n} → Iso (hLevelTrunc n A → B .fst) (A → B .fst)
univTrunc zero {B , lev} = isContr→Iso (isOfHLevelΠ 0 (λ _ → lev)) (isOfHLevelΠ 0 λ _ → lev)
Iso.fun (univTrunc (suc n) {B , lev}) g a = g ∣ a ∣
Iso.inv (univTrunc (suc n) {B , lev}) = rec lev
Iso.rightInv (univTrunc (suc n) {B , lev}) b = refl
Iso.leftInv (univTrunc (suc n) {B , lev}) b = funExt (elim (λ x → isOfHLevelPath _ lev _ _)
λ a → refl)
-- some useful properties of recursor
recUniq : {n : HLevel}
→ (h : isOfHLevel n B)
→ (g : A → B)
→ (x : A)
→ rec h g ∣ x ∣ₕ ≡ g x
recUniq {n = zero} h g x = h .snd (g x)
recUniq {n = suc n} _ _ _ = refl
∘rec : ∀{ℓ''} {n : HLevel}{C : Type ℓ''}
→ (h : isOfHLevel n B)
→ (h' : isOfHLevel n C)
→ (g : A → B)
→ (f : B → C)
→ (x : hLevelTrunc n A)
→ rec h' (f ∘ g) x ≡ f (rec h g x)
∘rec {n = zero} h h' g f x = h' .snd (f (rec h g x))
∘rec {n = suc n} h h' g f = elim (λ _ → isOfHLevelPath _ h' _ _) (λ _ → refl)
recId : {n : HLevel}
→ (f : A → hLevelTrunc n A)
→ ((x : A) → f x ≡ ∣ x ∣ₕ)
→ rec (isOfHLevelTrunc _) f ≡ idfun _
recId {n = n} f h i x =
elim {B = λ a → rec (isOfHLevelTrunc _) f a ≡ a}
(λ _ → isOfHLevelTruncPath) (λ a → recUniq {n = n} (isOfHLevelTrunc _) f a ∙ h a) x i
-- functorial action
map : {n : HLevel} {B : Type ℓ'} (g : A → B)
→ hLevelTrunc n A → hLevelTrunc n B
map g = rec (isOfHLevelTrunc _) (λ a → ∣ g a ∣ₕ)
map2 : ∀ {ℓ''} {n : HLevel} {B : Type ℓ'} {C : Type ℓ''} (g : A → B → C)
→ hLevelTrunc n A → hLevelTrunc n B → hLevelTrunc n C
map2 {n = zero} g = λ _ _ → tt*
map2 {n = suc n} g = rec (isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc _)
(λ a → rec (isOfHLevelTrunc _) λ b → ∣ g a b ∣)
mapCompIso : {n : HLevel} {B : Type ℓ'} → (Iso A B) → Iso (hLevelTrunc n A) (hLevelTrunc n B)
mapCompIso {n = zero} {B} _ = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevelUnit* 0)
Iso.fun (mapCompIso {n = (suc n)} g) = map (Iso.fun g)
Iso.inv (mapCompIso {n = (suc n)} g) = map (Iso.inv g)
Iso.rightInv (mapCompIso {n = (suc n)} g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ b → cong ∣_∣ (Iso.rightInv g b)
Iso.leftInv (mapCompIso {n = (suc n)} g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ a → cong ∣_∣ (Iso.leftInv g a)
mapId : {n : HLevel} → ∀ t → map {n = n} (idfun A) t ≡ t
mapId {n = 0} tt* = refl
mapId {n = (suc n)} =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (λ _ → refl)
-- equivalences to prop/set/groupoid truncations
propTruncTrunc1Iso : Iso ∥ A ∥₁ (∥ A ∥ 1)
Iso.fun propTruncTrunc1Iso = PropTrunc.rec (isOfHLevelTrunc 1) ∣_∣
Iso.inv propTruncTrunc1Iso = rec squash₁ ∣_∣₁
Iso.rightInv propTruncTrunc1Iso = elim (λ _ → isOfHLevelPath 1 (isOfHLevelTrunc 1) _ _) (λ _ → refl)
Iso.leftInv propTruncTrunc1Iso = PropTrunc.elim (λ _ → isOfHLevelPath 1 squash₁ _ _) (λ _ → refl)
propTrunc≃Trunc1 : ∥ A ∥₁ ≃ ∥ A ∥ 1
propTrunc≃Trunc1 = isoToEquiv propTruncTrunc1Iso
propTrunc≡Trunc1 : ∥ A ∥₁ ≡ ∥ A ∥ 1
propTrunc≡Trunc1 = ua propTrunc≃Trunc1
setTruncTrunc2Iso : Iso ∥ A ∥₂ (∥ A ∥ 2)
Iso.fun setTruncTrunc2Iso = SetTrunc.rec (isOfHLevelTrunc 2) ∣_∣
Iso.inv setTruncTrunc2Iso = rec squash₂ ∣_∣₂
Iso.rightInv setTruncTrunc2Iso = elim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _) (λ _ → refl)
Iso.leftInv setTruncTrunc2Iso = SetTrunc.elim (λ _ → isOfHLevelPath 2 squash₂ _ _) (λ _ → refl)
setTrunc≃Trunc2 : ∥ A ∥₂ ≃ ∥ A ∥ 2
setTrunc≃Trunc2 = isoToEquiv setTruncTrunc2Iso
propTrunc≡Trunc2 : ∥ A ∥₂ ≡ ∥ A ∥ 2
propTrunc≡Trunc2 = ua setTrunc≃Trunc2
groupoidTruncTrunc3Iso : Iso ∥ A ∥₃ (∥ A ∥ 3)
Iso.fun groupoidTruncTrunc3Iso = GpdTrunc.rec (isOfHLevelTrunc 3) ∣_∣
Iso.inv groupoidTruncTrunc3Iso = rec squash₃ ∣_∣₃
Iso.rightInv groupoidTruncTrunc3Iso = elim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) (λ _ → refl)
Iso.leftInv groupoidTruncTrunc3Iso = GpdTrunc.elim (λ _ → isOfHLevelPath 3 squash₃ _ _) (λ _ → refl)
groupoidTrunc≃Trunc3 : ∥ A ∥₃ ≃ ∥ A ∥ 3
groupoidTrunc≃Trunc3 = isoToEquiv groupoidTruncTrunc3Iso
groupoidTrunc≡Trunc3 : ∥ A ∥₃ ≡ ∥ A ∥ 3
groupoidTrunc≡Trunc3 = ua groupoidTrunc≃Trunc3
2GroupoidTruncTrunc4Iso : Iso ∥ A ∥₄ (∥ A ∥ 4)
Iso.fun 2GroupoidTruncTrunc4Iso = 2GpdTrunc.rec (isOfHLevelTrunc 4) ∣_∣
Iso.inv 2GroupoidTruncTrunc4Iso = rec squash₄ ∣_∣₄
Iso.rightInv 2GroupoidTruncTrunc4Iso = elim (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _) (λ _ → refl)
Iso.leftInv 2GroupoidTruncTrunc4Iso = 2GpdTrunc.elim (λ _ → isOfHLevelPath 4 squash₄ _ _) (λ _ → refl)
2GroupoidTrunc≃Trunc4 : ∥ A ∥₄ ≃ ∥ A ∥ 4
2GroupoidTrunc≃Trunc4 = isoToEquiv 2GroupoidTruncTrunc4Iso
2GroupoidTrunc≡Trunc4 : ∥ A ∥₄ ≡ ∥ A ∥ 4
2GroupoidTrunc≡Trunc4 = ua 2GroupoidTrunc≃Trunc4
isContr→isContrTrunc : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A → isContr (hLevelTrunc n A)
isContr→isContrTrunc zero contr = isOfHLevelUnit* 0
isContr→isContrTrunc (suc n) contr =
∣ fst contr ∣ , (elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → cong ∣_∣ (snd contr a))
truncOfProdIso : (n : ℕ) → Iso (hLevelTrunc n (A × B)) (hLevelTrunc n A × hLevelTrunc n B)
truncOfProdIso 0 = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevel× 0 (isOfHLevelUnit* 0) (isOfHLevelUnit* 0))
Iso.fun (truncOfProdIso (suc n)) = rec (isOfHLevelΣ (suc n) (isOfHLevelTrunc (suc n)) (λ _ → isOfHLevelTrunc (suc n))) λ {(a , b) → ∣ a ∣ , ∣ b ∣}
Iso.inv (truncOfProdIso (suc n)) (a , b) = rec (isOfHLevelTrunc (suc n))
(λ a → rec (isOfHLevelTrunc (suc n))
(λ b → ∣ a , b ∣)
b)
a
Iso.rightInv (truncOfProdIso (suc n)) (a , b) =
elim {B = λ a → Iso.fun (truncOfProdIso (suc n)) (Iso.inv (truncOfProdIso (suc n)) (a , b)) ≡ (a , b)}
(λ _ → isOfHLevelPath (suc n) (isOfHLevelΣ (suc n) (isOfHLevelTrunc (suc n)) (λ _ → isOfHLevelTrunc (suc n))) _ _)
(λ a → elim {B = λ b → Iso.fun (truncOfProdIso (suc n)) (Iso.inv (truncOfProdIso (suc n)) (∣ a ∣ , b)) ≡ (∣ a ∣ , b)}
(λ _ → isOfHLevelPath (suc n) (isOfHLevelΣ (suc n) (isOfHLevelTrunc (suc n)) (λ _ → isOfHLevelTrunc (suc n))) _ _)
(λ b → refl) b) a
Iso.leftInv (truncOfProdIso (suc n)) = elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → refl
---- ∥ Ω A ∥ ₙ ≡ Ω ∥ A ∥ₙ₊₁ ----
{- Proofs of Theorem 7.3.12. and Corollary 7.3.13. in the HoTT book -}
module ΩTrunc {X : Type ℓ} {n : HLevel} where
{- We define the fibration P to show a more general result -}
Code : ∥ X ∥ (2 + n) → ∥ X ∥ (2 + n) → TypeOfHLevel ℓ (suc n)
Code x y =
rec2 (isOfHLevelTypeOfHLevel (suc n))
(λ a b → ∥ a ≡ b ∥ (suc n) , isOfHLevelTrunc (suc n)) x y
P : ∥ X ∥ (2 + n) → ∥ X ∥ (2 + n) → Type ℓ
P x y = Code x y .fst
{- We will need P to be of hLevel n + 3 -}
hLevelP : (a b : ∥ X ∥ (2 + n)) → isOfHLevel (2 + n) (P a b)
hLevelP x y = isOfHLevelSuc (suc n) (Code x y .snd)
{- decode function from P x y to x ≡ y -}
decode-fun : (x y : ∥ X ∥ (2 + n)) → P x y → x ≡ y
decode-fun =
elim2 (λ u v → isOfHLevelΠ (2 + n)(λ _ → isOfHLevelSuc (2 + n) (isOfHLevelTrunc (2 + n)) u v))
decode*
where
decode* : (u v : X) → P ∣ u ∣ ∣ v ∣ → Path (∥ X ∥ (2 + n)) ∣ u ∣ ∣ v ∣
decode* u v =
rec (isOfHLevelTrunc (2 + n) ∣ u ∣ ∣ v ∣) (cong ∣_∣)
{- auxiliary function r used to define encode -}
r : (u : ∥ X ∥ (2 + n)) → P u u
r = elim (λ x → hLevelP x x) (λ a → ∣ refl ∣)
encode-fun : (x y : ∥ X ∥ (2 + n)) → x ≡ y → P x y
encode-fun x y p = subst (P x) p (r x)
encode-fill : (x y : ∥ X ∥ (2 + n)) (p : x ≡ y)
→ PathP (λ i → P x (p i)) (r x) (encode-fun x y p)
encode-fill x y p = subst-filler (P x) p (r x)
{- We need the following lemma on the functions behaviour for refl -}
dec-refl : (x : ∥ X ∥ (2 + n)) → decode-fun x x (r x) ≡ refl
dec-refl =
elim (λ x → isOfHLevelSuc (1 + n)
(isOfHLevelSuc (1 + n)
(isOfHLevelTrunc (2 + n) x x)
(decode-fun x x (r x)) refl))
(λ _ → refl)
{- decode-fun is a right-inverse -}
P-rinv : (u v : ∥ X ∥ (2 + n)) (x : Path (∥ X ∥ (2 + n)) u v)
→ decode-fun u v (encode-fun u v x) ≡ x
P-rinv u v p =
transport
(λ i → decode-fun u (p i) (encode-fill u v p i) ≡ (λ j → p (i ∧ j)))
(dec-refl u)
{- decode-fun is a left-inverse -}
P-linv : (u v : ∥ X ∥ (2 + n)) (x : P u v)
→ encode-fun u v (decode-fun u v x) ≡ x
P-linv =
elim2 (λ x y → isOfHLevelΠ (2 + n) (λ z → isOfHLevelSuc (2 + n) (hLevelP x y) _ _))
(λ a b → elim (λ p → hLevelP ∣ a ∣ ∣ b ∣ _ _) (helper a b))
where
helper : (a b : X) (p : a ≡ b) → encode-fun _ _ (decode-fun ∣ a ∣ ∣ b ∣ (∣ p ∣)) ≡ ∣ p ∣
helper a b p =
transport
(λ i → subst-filler (P ∣ a ∣) (cong ∣_∣ p) ∣ refl ∣ i ≡ ∣ (λ j → p (i ∧ j)) ∣)
refl
{- The final Iso established -}
IsoFinal : (x y : ∥ X ∥ (2 + n)) → Iso (x ≡ y) (P x y)
Iso.fun (IsoFinal x y) = encode-fun x y
Iso.inv (IsoFinal x y) = decode-fun x y
Iso.rightInv (IsoFinal x y) = P-linv x y
Iso.leftInv (IsoFinal x y) = P-rinv x y
+P : (x y z : ∥ X ∥ (2 + n)) → (P x y) → (P y z) → P x z
+P =
elim3 (λ x _ z → isOfHLevelΠ (2 + n) λ _ → isOfHLevelΠ (2 + n) λ _ → hLevelP x z) λ a b c →
rec (isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n)) λ p →
rec (isOfHLevelTrunc (suc n)) λ q →
∣ p ∙ q ∣
+P-funct : (x y z : ∥ X ∥ (2 + n)) (p : x ≡ y) (q : y ≡ z)
→ +P x y z (encode-fun x y p) (encode-fun y z q) ≡ encode-fun x z (p ∙ q)
+P-funct x y z p q =
transport
(λ i → +P x y (q i) (encode-fun x y p) (encode-fill y z q i) ≡ encode-fun x (q i) (compPath-filler p q i))
(transport
(λ i → +P x (p i) (p i) (encode-fill x y p i) (r (p i)) ≡ encode-fill x y p i)
(elim {B = λ x → +P x x x (r x) (r x) ≡ r x}
(λ x → isOfHLevelPath (2 + n) (hLevelP x x) _ _)
(λ a i → ∣ rUnit refl (~ i) ∣)
x))
PathIdTruncIso : {a b : A} (n : HLevel) → Iso (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ b ∣) (∥ a ≡ b ∥ n)
PathIdTruncIso zero =
isContr→Iso
(isOfHLevelTrunc 1 _ _ , isOfHLevelPath 1 (isOfHLevelTrunc 1) ∣ _ ∣ ∣ _ ∣ _)
(isOfHLevelUnit* 0)
PathIdTruncIso (suc n) = ΩTrunc.IsoFinal ∣ _ ∣ ∣ _ ∣
PathIdTrunc : {a b : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ b ∣) ≡ (∥ a ≡ b ∥ n)
PathIdTrunc n = isoToPath (PathIdTruncIso n)
PathΩ : {a : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ a ∣) ≡ (∥ a ≡ a ∥ n)
PathΩ n = PathIdTrunc n
PathIdTruncIsoFunct : ∀ {A : Type ℓ} {a : A} (n : HLevel) → (p q : (Path (∥ A ∥ (2 + n)) ∣ a ∣ ∣ a ∣))
→ Iso.fun (PathIdTruncIso (suc n)) (p ∙ q)
≡ map2 _∙_ (Iso.fun (PathIdTruncIso (suc n)) p) (Iso.fun (PathIdTruncIso (suc n)) q)
PathIdTruncIsoFunct {a = a} n p q = sym (ΩTrunc.+P-funct (∣ a ∣) ∣ a ∣ ∣ a ∣ p q)
-------------------------
truncOfTruncIso : (n m : HLevel) → Iso (hLevelTrunc n A) (hLevelTrunc n (hLevelTrunc (m + n) A))
truncOfTruncIso zero m = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevelUnit* 0)
Iso.fun (truncOfTruncIso (suc n) zero) = rec (isOfHLevelTrunc (suc n)) λ a → ∣ ∣ a ∣ ∣
Iso.fun (truncOfTruncIso (suc n) (suc m)) = rec (isOfHLevelTrunc (suc n)) λ a → ∣ ∣ a ∣ ∣
Iso.inv (truncOfTruncIso (suc n) zero) = rec (isOfHLevelTrunc (suc n))
(rec (isOfHLevelTrunc (suc n))
λ a → ∣ a ∣)
Iso.inv (truncOfTruncIso (suc n) (suc m)) = rec (isOfHLevelTrunc (suc n))
(rec (isOfHLevelPlus (suc m) (isOfHLevelTrunc (suc n)))
λ a → ∣ a ∣)
Iso.rightInv (truncOfTruncIso (suc n) zero) =
elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _ )
(elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _ )
λ a → refl)
Iso.rightInv (truncOfTruncIso (suc n) (suc m)) =
elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _ )
(elim (λ x → isOfHLevelPath ((suc m) + (suc n)) (isOfHLevelPlus (suc m) (isOfHLevelTrunc (suc n))) _ _ )
λ a → refl)
Iso.leftInv (truncOfTruncIso (suc n) zero) =
elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ a → refl
Iso.leftInv (truncOfTruncIso (suc n) (suc m)) =
elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ a → refl
truncOfTruncIso' : (n m : HLevel) → Iso (hLevelTrunc n A) (hLevelTrunc n (hLevelTrunc (n + m) A))
truncOfTruncIso' zero m = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevelUnit* 0)
Iso.fun (truncOfTruncIso' (suc n) m) = rec (isOfHLevelTrunc (suc n)) λ a → ∣ ∣ a ∣ ∣
Iso.inv (truncOfTruncIso' {A = A} (suc n) m) =
rec (isOfHLevelTrunc (suc n))
(rec (isOfHLevelPlus' {n = m} (suc n) (isOfHLevelTrunc (suc n))) ∣_∣)
Iso.rightInv (truncOfTruncIso' (suc n) m) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(elim (λ _ → isOfHLevelPath (suc n + m) (isOfHLevelPlus' {n = m} (suc n) (isOfHLevelTrunc (suc n))) _ _)
λ _ → refl)
Iso.leftInv (truncOfTruncIso' (suc n) m) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ _ → refl
truncOfTruncEq : (n m : ℕ) → (hLevelTrunc n A) ≃ (hLevelTrunc n (hLevelTrunc (m + n) A))
truncOfTruncEq n m = isoToEquiv (truncOfTruncIso n m)
truncOfTruncIso2 : (n m : HLevel) → Iso (hLevelTrunc (m + n) (hLevelTrunc n A)) (hLevelTrunc n A)
truncOfTruncIso2 n m = truncIdempotentIso (m + n) (isOfHLevelPlus m (isOfHLevelTrunc n))
truncOfΣIso : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : A → Type ℓ'}
→ Iso (hLevelTrunc n (Σ A B)) (hLevelTrunc n (Σ A λ x → hLevelTrunc n (B x)))
truncOfΣIso zero = idIso
Iso.fun (truncOfΣIso (suc n)) = map λ {(a , b) → a , ∣ b ∣}
Iso.inv (truncOfΣIso (suc n)) =
rec (isOfHLevelTrunc (suc n))
(uncurry λ a → rec (isOfHLevelTrunc (suc n)) λ b → ∣ a , b ∣)
Iso.rightInv (truncOfΣIso (suc n)) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(uncurry λ a → elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ b → refl)
Iso.leftInv (truncOfΣIso (suc n)) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ {(a , b) → refl}
{- transport along family of truncations -}
transportTrunc : {n : HLevel}{p : A ≡ B}
→ (a : A)
→ transport (λ i → hLevelTrunc n (p i)) ∣ a ∣ₕ ≡ ∣ transport (λ i → p i) a ∣ₕ
transportTrunc {n = zero} a = refl
transportTrunc {n = suc n} a = refl
| 43.477954
| 146
| 0.550706
|
dcf7c49e348a35315ed41cc7842e271e79509e95
| 90
|
agda
|
Agda
|
test/interaction/Issue4215.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue4215.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue4215.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Nat
foo : Nat → Nat → Nat
foo 0 m = {!m!}
foo (suc n) m = {!!}
| 12.857143
| 28
| 0.555556
|
5969e8de8704c6862cd0fb6062152c1dc2c451b5
| 238
|
agda
|
Agda
|
test/Fail/CoinductiveBuiltinList.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/CoinductiveBuiltinList.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Fail/CoinductiveBuiltinList.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module CoinductiveBuiltinList where
open import Common.Coinduction
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) (xs : ∞ (List A)) → List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
| 19.833333
| 42
| 0.584034
|
23def69502ccde6368272f5648a846a698a23454
| 1,522
|
agda
|
Agda
|
src/Categories/Minus2-Category/Properties.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Minus2-Category/Properties.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Minus2-Category/Properties.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Minus2-Category.Properties where
-- All -2-Categories are equivalent to One
open import Level
open import Data.Product using (Σ; _,_; proj₁; proj₂)
open import Data.Unit using (⊤; tt)
open import Categories.Minus2-Category
open import Categories.Category
import Categories.Morphism as M
open import Categories.Category.Monoidal
open import Categories.Category.Instance.One
open import Categories.Category.Equivalence hiding (refl)
open import Categories.NaturalTransformation using (ntHelper)
private
variable
o ℓ e : Level
shrink-them-all : (X : -2-Category {o} {ℓ} {e}) → StrongEquivalence (-2-Category.cat X) (One {o} {ℓ} {e})
shrink-them-all X = record
{ F = record
{ F₀ = λ _ → lift tt
; F₁ = λ _ → lift tt
}
; G = record
{ F₀ = λ _ → proj₁ Obj-Contr
; F₁ = λ _ → M._≅_.from (proj₂ Obj-Contr (proj₁ Obj-Contr))
; identity = Hom-Conn
; homomorphism = Hom-Conn
; F-resp-≈ = λ _ → Hom-Conn
}
; weak-inverse = record
{ F∘G≈id = _
; G∘F≈id = record
{ F⇒G = ntHelper (record
{ η = λ y → M._≅_.from (proj₂ Obj-Contr y)
; commute = λ _ → Hom-Conn
})
; F⇐G = ntHelper (record
{ η = λ y → M._≅_.to (proj₂ Obj-Contr y)
; commute = λ _ → Hom-Conn
})
; iso = λ Z → record
{ isoˡ = M._≅_.isoˡ (proj₂ Obj-Contr Z)
; isoʳ = M._≅_.isoʳ (proj₂ Obj-Contr Z)
}
}
}
}
where
open -2-Category X
open Category cat
| 26.701754
| 105
| 0.604468
|
06b1d21487c59a58803fd36e4e40bef2c3735b55
| 421
|
agda
|
Agda
|
Eq.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | 4
|
2016-12-25T01:52:57.000Z
|
2021-03-22T00:28:03.000Z
|
Eq.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | null | null | null |
Eq.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | 3
|
2015-04-26T11:39:14.000Z
|
2021-05-04T22:37:18.000Z
|
module Eq where
open import Prelude
open import T
open import Contexts
open import Eq.Defs
import Eq.KleeneTheory
import Eq.ObsTheory
import Eq.LogicalTheory
import Eq.Theory
open Eq.Defs public
open Eq.KleeneTheory public using (kleene-is-equivalence ; nats-halt)
open Eq.ObsTheory public using (obs-is-coarsest ; obs-is-con-congruence)
open Eq.LogicalTheory public using (log-is-con-congruence)
open Eq.Theory public
| 24.764706
| 72
| 0.812352
|
1d0c02576e146353a45a8d094e4d691a8ece1969
| 1,466
|
agda
|
Agda
|
src/LibraBFT/Impl/Consensus/ConsensusTypes/ExecutedBlock.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Consensus/ConsensusTypes/ExecutedBlock.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Consensus/ConsensusTypes/ExecutedBlock.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block
import LibraBFT.Impl.Execution.ExecutorTypes.StateComputeResult as StateComputeResult
import LibraBFT.Impl.OBM.Crypto as Crypto
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.Prelude
module LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock where
isNilBlock : ExecutedBlock → Bool
isNilBlock eb = Block.isNilBlock (eb ^∙ ebBlock)
blockInfo : ExecutedBlock → BlockInfo
blockInfo eb =
Block.genBlockInfo
(eb ^∙ ebBlock)
(Crypto.obmHashVersion -- OBM-LBFT-DIFF - see SafetyRules.extensionCheck
(eb ^∙ ebStateComputeResult ∙ scrObmNumLeaves))
(eb ^∙ ebStateComputeResult ∙ scrObmNumLeaves)
(eb ^∙ ebStateComputeResult ∙ scrEpochState)
maybeSignedVoteProposal : ExecutedBlock → MaybeSignedVoteProposal
maybeSignedVoteProposal self =
MaybeSignedVoteProposal∙new
(VoteProposal∙new (StateComputeResult.extensionProof (self ^∙ ebStateComputeResult))
(self ^∙ ebBlock)
(self ^∙ ebStateComputeResult ∙ scrEpochState))
| 40.722222
| 111
| 0.740791
|
3d52ca2a14165c539bbe847c6e176ce35a4fa107
| 1,489
|
agda
|
Agda
|
test/Succeed/QuoteExtLam.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/QuoteExtLam.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/QuoteExtLam.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Common.Prelude
open import Common.Reflection
open import Common.Equality
open import Agda.Builtin.Sigma
magic₁ : ⊥ → Nat
magic₁ = λ ()
magic₂ : ⊥ → Nat
magic₂ = λ { () }
magic₃ : ⊥ → Nat
magic₃ ()
data Wrap (A : Set) : Set where
wrap : A → Wrap A
magic₄ : Wrap ⊥ → Nat
magic₄ (wrap ())
data OK : Set where
ok : OK
bad : String
bad = "not good"
macro
checkDefinition : (Definition → Bool) → QName → Tactic
checkDefinition isOk f hole =
bindTC (getDefinition f) λ def →
give (if isOk def then quoteTerm ok else quoteTerm bad) hole
pattern `Nat = def (quote Nat) []
pattern _`→_ a b = pi (vArg a) (abs "_" b)
pattern `Wrap a = def (quote Wrap) (vArg a ∷ [])
pattern `⊥ = def (quote ⊥) []
pattern expected₄ = funDef
(absurdClause (("()" , vArg `⊥) ∷ []) (vArg (con (quote wrap) (vArg (absurd 0) ∷ [])) ∷ [])
∷ [])
check₄ : OK
check₄ = checkDefinition (λ { expected₄ → true; _ → false }) magic₄
expected = extLam (absurdClause (("()" , vArg `⊥) ∷ []) (vArg (absurd 0) ∷ []) ∷ []) []
macro
quoteTermNormalised : Term → Term → TC ⊤
quoteTermNormalised t hole =
bindTC (normalise t) λ t →
bindTC (quoteTC t) λ t →
unify hole t
check₁ : quoteTermNormalised magic₁ ≡ expected
check₁ = refl
check₂ : quoteTermNormalised magic₂ ≡ expected
check₂ = refl
pattern expectedDef =
funDef (absurdClause (("()" , vArg `⊥) ∷ []) (vArg (absurd 0) ∷ []) ∷ [])
check₃ : OK
check₃ = checkDefinition (λ { expectedDef → true; _ → false }) magic₃
| 22.223881
| 93
| 0.627267
|
3db94f28f40c5c1591aed1deab022e532f43ddfc
| 2,328
|
agda
|
Agda
|
Cubical/Categories/Additive/Instances/Terminal.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Categories/Additive/Instances/Terminal.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Additive/Instances/Terminal.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Additive.Instances.Terminal where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Categories.Category
open import Cubical.Categories.Additive.Base
open import Cubical.Categories.Instances.Discrete
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.AbGroup.Instances.Unit
open import Cubical.Data.Unit
private
variable
ℓ ℓ' : Level
open PreaddCategory
open PreaddCategoryStr
open AdditiveCategory
open AdditiveCategoryStr
private
terminalCategory : Category ℓ ℓ
terminalCategory = DiscreteCategory (Unit* , isOfHLevelUnit* 3)
terminalAbGroupStr : AbGroupStr {ℓ = ℓ} Unit*
terminalAbGroupStr = snd UnitAbGroup
homProp : (x y : Category.ob {ℓ = ℓ} terminalCategory) → isProp (terminalCategory [ x , y ])
homProp x y = isOfHLevelUnit* 2 x y
homContr : (x y : Category.ob {ℓ = ℓ} terminalCategory) → isContr (terminalCategory [ x , y ])
homContr x y = isProp→isContrPath (isOfHLevelUnit* 1) x y
terminalPreAdd : PreaddCategory ℓ ℓ
cat terminalPreAdd = terminalCategory
homAbStr (preadd terminalPreAdd) =
λ x y →
subst
AbGroupStr
(sym (isContr→≡Unit* (homContr x y)))
terminalAbGroupStr
⋆distl+ (preadd terminalPreAdd) = λ _ _ _ _ → refl
⋆distr+ (preadd terminalPreAdd) = λ _ _ _ → refl
terminalAdditiveCategory : AdditiveCategory ℓ ℓ
preaddcat terminalAdditiveCategory = terminalPreAdd
ZeroObject.z (zero (addit terminalAdditiveCategory)) = tt*
ZeroObject.zInit (zero (addit terminalAdditiveCategory)) y = homContr _ _
ZeroObject.zTerm (zero (addit terminalAdditiveCategory)) y = homContr _ _
biprod (addit terminalAdditiveCategory) x y = trivProd
where trivProd : Biproduct terminalPreAdd x y
Biproduct.x⊕y trivProd = tt*
Biproduct.i₁ trivProd = refl
Biproduct.i₂ trivProd = refl
Biproduct.π₁ trivProd = refl
Biproduct.π₂ trivProd = refl
IsBiproduct.i₁⋆π₁ (Biproduct.isBipr trivProd) = homProp _ _ _ _
IsBiproduct.i₁⋆π₂ (Biproduct.isBipr trivProd) = homProp _ _ _ _
IsBiproduct.i₂⋆π₁ (Biproduct.isBipr trivProd) = homProp _ _ _ _
IsBiproduct.i₂⋆π₂ (Biproduct.isBipr trivProd) = homProp _ _ _ _
IsBiproduct.∑π⋆i (Biproduct.isBipr trivProd) = homProp _ _ _ _
| 34.746269
| 96
| 0.734536
|
299a852c9841ee9d6a016a12bf43323e193c683e
| 2,082
|
agda
|
Agda
|
notes/FOT/FOTC/Polymorphism/List.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Polymorphism/List.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Polymorphism/List.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Testing polymorphic lists using data types
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Polymorphism.List where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool.Type
open import FOTC.Data.List.Type
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
-- "Heterogeneous" total lists
xs : D
xs = 0' ∷ true ∷ 1' ∷ false ∷ []
xs-List : List xs
xs-List = lcons 0' (lcons true (lcons 1' (lcons false lnil)))
-- Total lists of total natural numbers
ys : D
ys = 0' ∷ 1' ∷ 2' ∷ []
ys-ListN : ListN ys
ys-ListN =
lncons nzero (lncons (nsucc nzero) (lncons (nsucc (nsucc nzero)) lnnil))
-- Total lists of total Booleans
data ListB : D → Set where
lbnil : ListB []
lbcons : ∀ {b bs} → Bool b → ListB bs → ListB (b ∷ bs)
zs : D
zs = true ∷ false ∷ true ∷ []
zs-ListB : ListB zs
zs-ListB = lbcons btrue (lbcons bfalse (lbcons btrue lbnil))
------------------------------------------------------------------------------
-- Polymorphic lists.
data Plist (P : D → Set) : D → Set where
lnil : Plist P []
lcons : ∀ {x xs} → P x → Plist P xs → Plist P (x ∷ xs)
-- "Heterogeneous" total lists
List₁ : D → Set
List₁ = Plist (λ d → d ≡ d)
xs-List₁ : List₁ xs
xs-List₁ = lcons refl (lcons refl (lcons refl (lcons refl lnil)))
-- Total lists of total natural numbers
ListN₁ : D → Set
ListN₁ = Plist N
ys-ListN₁ : ListN₁ ys
ys-ListN₁ = lcons nzero (lcons (nsucc nzero) (lcons (nsucc (nsucc nzero)) lnil))
-- Total lists of total Booleans
ListB₁ : D → Set
ListB₁ = Plist Bool
zs-ListB₁ : ListB₁ zs
zs-ListB₁ = lcons btrue (lcons bfalse (lcons btrue lnil))
| 28.520548
| 80
| 0.534582
|
3d3369edfd6b96bd62c1798a3b9a4f7acf497ebb
| 321
|
agda
|
Agda
|
notes/agda-interface/OptionPragma.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
notes/agda-interface/OptionPragma.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
notes/agda-interface/OptionPragma.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
{-# OPTIONS --no-termination-check #-}
-- Testing how the pragmas are saved in the agda interface files (using
-- the program dump-agdai).
-- 13 July 2012. Because for example the --no-termination-check is a
-- PragmaOption it is saved as:
--
-- iPragmaOptions = [["--no-termination-check"]]
module OptionPragma where
| 26.75
| 71
| 0.713396
|
c58e8de704e9b49a95e8de304577807f8def9918
| 2,064
|
agda
|
Agda
|
examples/Sized/CounterCell.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/Sized/CounterCell.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/Sized/CounterCell.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module Sized.CounterCell where
open import Data.Product
open import Data.Nat.Base
open import Data.Nat.Show
open import Data.String.Base using (String; _++_)
open import SizedIO.Object
open import SizedIO.IOObject
open import SizedIO.Base
open import SizedIO.Console hiding (main)
open import SizedIO.ConsoleObject
open import NativeIO
open import Sized.SimpleCell hiding (program; main)
open import Size
data CounterMethod A : Set where
super : (m : CellMethod A) → CounterMethod A
stats : CounterMethod A
pattern getᶜ = super get
pattern putᶜ x = super (put x)
-- CounterResult : ∀{A} →
counterI : (A : Set) → Interface
Method (counterI A) = CounterMethod A
Result (counterI A) (super m) = Result (cellJ A) m
Result (counterI A) stats = Unit
CounterC : (i : Size) → Set
CounterC i = ConsoleObject i (counterI String)
-- counterP is constructor for the consoleObject for interface counterI
counterP : ∀{i} (c : CellC i) (ngets nputs : ℕ) → CounterC i
method (counterP c ngets nputs) getᶜ =
method c get >>= λ { (s , c') →
return (s , counterP c' (1 + ngets) nputs) }
method (counterP c ngets nputs) (putᶜ x) =
method c (put x) >>= λ { (_ , c') →
return (_ , counterP c' ngets (1 + nputs)) }
method (counterP c ngets nputs) stats =
exec (putStrLn ("Counted "
++ show ngets ++ " calls to get and "
++ show nputs ++ " calls to put.")) λ _ →
return (_ , counterP c ngets nputs)
program : String → IOConsole ∞ Unit
program arg =
let c₀ = counterP (cellP "Start") 0 0 in
method c₀ getᶜ >>= λ{ (s , c₁) →
exec1 (putStrLn s) >>
method c₁ (putᶜ arg) >>= λ{ (_ , c₂) →
method c₂ getᶜ >>= λ{ (s' , c₃) →
exec1 (putStrLn s') >>
method c₃ (putᶜ "Over!") >>= λ{ (_ , c₄) →
method c₄ stats >>= λ{ (_ , c₅) →
return _ }}}}}
main : NativeIO Unit
main = translateIOConsole (program "Hello")
-- -}
-- -}
-- -}
-- -}
-- -}
-- -}
-- -}
| 27.157895
| 71
| 0.588663
|
068d53d8dc10e05ab2125b8d79c589208f6bc5d0
| 6,145
|
agda
|
Agda
|
src/Categories/Category/Construction/Adjoints.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Construction/Adjoints.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Construction/Adjoints.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Adjoints where
open import Level
open import Data.Product using (_×_ ; _,_)
open import Categories.Category
open import Categories.Category.Helper
open import Categories.Adjoint
open import Categories.Adjoint.Compose
open import Categories.Adjoint.Mate
open import Categories.Functor renaming (id to idF)
open import Categories.NaturalTransformation renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.NaturalTransformation.Equivalence renaming (_≃_ to _≊_)
import Categories.Morphism.Reasoning as MR
private
variable
o o′ ℓ ℓ′ e e′ : Level
-- category of adjunctions between two fixed categories
module _ (C : Category o ℓ e) (D : Category o′ ℓ′ e′) where
private
module C = Category C using (_∘_; ∘-resp-≈ˡ; ∘-resp-≈; sym-assoc; identityʳ; identityˡ; module Equiv; module HomReasoning)
module D = Category D using (_∘_; ∘-resp-≈ʳ; ∘-resp-≈; assoc; identityˡ; identityʳ; module Equiv; module HomReasoning)
record AdjointObj : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
L : Functor C D
R : Functor D C
L⊣R : L ⊣ R
module L = Functor L
module R = Functor R
module L⊣R = Adjoint L⊣R using (module unit; module counit)
record Adjoint⇒ (X Y : AdjointObj) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
mate : HaveMate (AdjointObj.L⊣R X) (AdjointObj.L⊣R Y)
open HaveMate mate using (α; β; commute₁; commute₂) public
private
_≈_ : ∀ {A B} → Adjoint⇒ A B → Adjoint⇒ A B → Set (o ⊔ e ⊔ o′ ⊔ e′)
f ≈ g = Adjoint⇒.α f ≊ Adjoint⇒.α g × Adjoint⇒.β f ≊ Adjoint⇒.β g
id : {X : AdjointObj} → Adjoint⇒ X X
id {X} = record
{ mate = record
{ α = idN
; β = idN
; mate = record
{ commute₁ = C.∘-resp-≈ˡ R.identity
; commute₂ = D.∘-resp-≈ʳ L.identity
}
}
}
where open AdjointObj X using (L; R)
_∘_ : ∀ {X Y Z} → Adjoint⇒ Y Z → Adjoint⇒ X Y → Adjoint⇒ X Z
_∘_ {X} {Y} {Z} f g = record
{ mate = record
{ α = f.α ∘ᵥ g.α
; β = g.β ∘ᵥ f.β
; mate = record
{ commute₁ = λ {W} →
let open C.HomReasoning
open MR C using (pullʳ; pullˡ)
in begin
X.R.F₁ (f.α.η W D.∘ g.α.η W) C.∘ X.L⊣R.unit.η W ≈⟨ X.R.homomorphism ⟩∘⟨refl ⟩
(X.R.F₁ (f.α.η W) C.∘ X.R.F₁ (g.α.η W)) C.∘ X.L⊣R.unit.η W ≈⟨ pullʳ g.commute₁ ⟩
X.R.F₁ (f.α.η W) C.∘ g.β.η (Y.L.F₀ W) C.∘ Y.L⊣R.unit.η W ≈⟨ pullˡ (g.β.sym-commute _) ⟩
(g.β.η (Z.L.F₀ W) C.∘ Y.R.F₁ (f.α.η W)) C.∘ Y.L⊣R.unit.η W ≈⟨ pullʳ f.commute₁ ⟩
g.β.η (Z.L.F₀ W) C.∘ f.β.η (Z.L.F₀ W) C.∘ Z.L⊣R.unit.η W ≈⟨ C.sym-assoc ⟩
(g.β.η (Z.L.F₀ W) C.∘ f.β.η (Z.L.F₀ W)) C.∘ Z.L⊣R.unit.η W ∎
; commute₂ = λ {W} →
let open D.HomReasoning
open MR D using (pullʳ; pullˡ)
in begin
X.L⊣R.counit.η W D.∘ X.L.F₁ (g.β.η W C.∘ f.β.η W) ≈⟨ refl⟩∘⟨ X.L.homomorphism ⟩
X.L⊣R.counit.η W D.∘ X.L.F₁ (g.β.η W) D.∘ X.L.F₁ (f.β.η W) ≈⟨ pullˡ g.commute₂ ⟩
(Y.L⊣R.counit.η W D.∘ g.α.η (Y.R.F₀ W)) D.∘ X.L.F₁ (f.β.η W) ≈⟨ pullʳ (g.α.commute _) ⟩
Y.L⊣R.counit.η W D.∘ Y.L.F₁ (f.β.η W) D.∘ g.α.η (Z.R.F₀ W) ≈⟨ pullˡ f.commute₂ ⟩
(Z.L⊣R.counit.η W D.∘ f.α.η (Z.R.F₀ W)) D.∘ g.α.η (Z.R.F₀ W) ≈⟨ D.assoc ⟩
Z.L⊣R.counit.η W D.∘ f.α.η (Z.R.F₀ W) D.∘ g.α.η (Z.R.F₀ W) ∎
}
}
}
where module X = AdjointObj X using (module L⊣R; module R; module L)
module Y = AdjointObj Y using (module L⊣R; module R; module L)
module Z = AdjointObj Z using (module L⊣R; module R; module L)
module f = Adjoint⇒ f using (α; β; commute₁; commute₂)
module g = Adjoint⇒ g using (α; β; commute₁; commute₂)
Adjoints : Category (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (o ⊔ e ⊔ o′ ⊔ e′)
Adjoints = categoryHelper record
{ Obj = AdjointObj
; _⇒_ = Adjoint⇒
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; assoc = D.assoc , C.sym-assoc
; identityˡ = D.identityˡ , C.identityʳ
; identityʳ = D.identityʳ , C.identityˡ
; equiv = record
{ refl = D.Equiv.refl , C.Equiv.refl
; sym = λ { (eq₁ , eq₂) → D.Equiv.sym eq₁ , C.Equiv.sym eq₂ }
; trans = λ { (eq₁ , eq₂) (eq₃ , eq₄) → D.Equiv.trans eq₁ eq₃ , C.Equiv.trans eq₂ eq₄ }
}
; ∘-resp-≈ = λ { (eq₁ , eq₂) (eq₃ , eq₄) → D.∘-resp-≈ eq₁ eq₃ , C.∘-resp-≈ eq₄ eq₂ }
}
module _ o ℓ e where
private
_≈_ : ∀ {A B : Category o ℓ e} → AdjointObj A B → AdjointObj A B → Set (o ⊔ ℓ ⊔ e)
f ≈ g = f.L ≃ g.L × f.R ≃ g.R
where module f = AdjointObj f using (L;R)
module g = AdjointObj g using (L;R)
id : {A : Category o ℓ e} → AdjointObj A A
id = record
{ L = idF
; R = idF
; L⊣R = ⊣-id
}
_∘_ : {A B C : Category o ℓ e} → AdjointObj B C → AdjointObj A B → AdjointObj A C
f ∘ g = record
{ L = f.L ∘F g.L
; R = g.R ∘F f.R
; L⊣R = g.L⊣R ∘⊣ f.L⊣R
}
where module f = AdjointObj f using (L; R; L⊣R)
module g = AdjointObj g using (L; R; L⊣R)
Adjunctions : Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e)
Adjunctions = categoryHelper record
{ Obj = Category o ℓ e
; _⇒_ = AdjointObj
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; assoc = λ {_ _ _ _ f g h} → associator (AdjointObj.L f) (AdjointObj.L g) (AdjointObj.L h)
, sym-associator (AdjointObj.R h) (AdjointObj.R g) (AdjointObj.R f)
; identityˡ = unitorˡ , unitorʳ
; identityʳ = unitorʳ , unitorˡ
; equiv = record
{ refl = ≃.refl , ≃.refl
; sym = λ { (α , β) → ≃.sym α , ≃.sym β }
; trans = λ { (α₁ , β₁) (α₂ , β₂) → ≃.trans α₁ α₂ , ≃.trans β₁ β₂ }
}
; ∘-resp-≈ = λ { (α₁ , β₁) (α₂ , β₂) → α₁ ⓘₕ α₂ , β₂ ⓘₕ β₁ }
}
| 38.892405
| 126
| 0.5131
|
59b1243121a3dca7dfdc2768a67b7f3e31cf758b
| 1,560
|
agda
|
Agda
|
src/Prelude/Functor.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Prelude/Functor.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Prelude/Functor.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Prelude.Functor where
open import Agda.Primitive
open import Prelude.Function
open import Prelude.Equality
record Functor {a b} (F : Set a → Set b) : Set (lsuc a ⊔ b) where
infixl 4 _<$>_ _<$_
field
fmap : ∀ {A B} → (A → B) → F A → F B
_<$>_ = fmap
_<$_ : ∀ {A B} → A → F B → F A
x <$ m = fmap (const x) m
open Functor {{...}} public
{-# DISPLAY Functor.fmap _ = fmap #-}
{-# DISPLAY Functor._<$>_ _ = _<$>_ #-}
{-# DISPLAY Functor._<$_ _ = _<$_ #-}
-- Level polymorphic functors
record Functor′ {a b} (F : ∀ {a} → Set a → Set a) : Set (lsuc (a ⊔ b)) where
infixl 4 _<$>′_ _<$′_
field
fmap′ : {A : Set a} {B : Set b} → (A → B) → F A → F B
_<$>′_ = fmap′
_<$′_ : {A : Set a} {B : Set b} → B → F A → F B
x <$′ m = fmap′ (const x) m
open Functor′ {{...}} public
infixr 0 flip-fmap
syntax flip-fmap a (λ x → y) = for x ← a return y
flip-fmap : ∀ {a b} {F : Set a → Set b} {{_ : Functor F}} {A B} → F A → (A → B) → F B
flip-fmap x f = fmap f x
infixr 0 caseF_of_
caseF_of_ : ∀ {a b} {F : Set a → Set b} {{_ : Functor F}} {A B} → F A → (A → B) → F B
caseF_of_ x f = fmap f x
for = caseF_of_
{-# INLINE for #-}
{-# INLINE caseF_of_ #-}
-- Congruence for _<$>_ --
infixl 4 _=$=_ _=$=′_
_=$=_ : ∀ {a b} {A B : Set a} {F : Set a → Set b} {{_ : Functor F}} {x y : F A}
(f : A → B) → x ≡ y → (f <$> x) ≡ (f <$> y)
f =$= refl = refl
_=$=′_ : ∀ {a b} {A : Set a} {B : Set b} {F : ∀ {a} → Set a → Set a} {{_ : Functor′ F}} {x y : F A}
(f : A → B) → x ≡ y → (f <$>′ x) ≡ (f <$>′ y)
f =$=′ refl = refl
| 26.440678
| 99
| 0.484615
|
29e3a8eb9c0e9d19b155ff219991289ce6919bb4
| 2,516
|
agda
|
Agda
|
Cubical/Categories/Instances/CommAlgebras.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Categories/Instances/CommAlgebras.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/CommAlgebras.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.CommAlgebras where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Powerset
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommAlgebra
open import Cubical.Categories.Category
open import Cubical.Categories.Functor.Base
open import Cubical.HITs.PropositionalTruncation
open Category
open CommAlgebraHoms
private
variable
ℓ ℓ' ℓ'' : Level
module _ (R : CommRing ℓ) where
CommAlgebrasCategory : Category (ℓ-suc (ℓ-max ℓ ℓ')) (ℓ-max ℓ ℓ')
ob CommAlgebrasCategory = CommAlgebra R _
Hom[_,_] CommAlgebrasCategory = CommAlgebraHom
id CommAlgebrasCategory {A} = idCommAlgebraHom A
_⋆_ CommAlgebrasCategory {A} {B} {C} = compCommAlgebraHom A B C
⋆IdL CommAlgebrasCategory {A} {B} = compIdCommAlgebraHom {A = A} {B}
⋆IdR CommAlgebrasCategory {A} {B} = idCompCommAlgebraHom {A = A} {B}
⋆Assoc CommAlgebrasCategory {A} {B} {C} {D} = compAssocCommAlgebraHom {A = A} {B} {C} {D}
isSetHom CommAlgebrasCategory = isSetAlgebraHom _ _
module PreSheafFromUniversalProp (C : Category ℓ ℓ') (P : ob C → Type ℓ)
{R : CommRing ℓ''} (𝓕 : Σ (ob C) P → CommAlgebra R ℓ'')
(uniqueHom : ∀ x y → C [ fst x , fst y ] → isContr (CommAlgebraHom (𝓕 y) (𝓕 x)))
where
private
∥P∥ : ℙ (ob C)
∥P∥ x = ∥ P x ∥ , isPropPropTrunc
ΣC∥P∥Cat = ΣPropCat C ∥P∥
𝓕UniqueEquiv : (x : ob C) (p q : P x) → isContr (CommAlgebraEquiv (𝓕 (x , p)) (𝓕 (x , q)))
𝓕UniqueEquiv x = contrCommAlgebraHom→contrCommAlgebraEquiv (curry 𝓕 x) λ p q → uniqueHom _ _ (id C)
theMap : (x : ob C) → ∥ P x ∥ → CommAlgebra R ℓ''
theMap x = recPT→CommAlgebra (curry 𝓕 x) (λ p q → 𝓕UniqueEquiv x p q .fst)
λ p q r → 𝓕UniqueEquiv x p r .snd _
theAction : (x y : ob C) → C [ x , y ]
→ (p : ∥ P x ∥) (q : ∥ P y ∥) → isContr (CommAlgebraHom (theMap y q) (theMap x p))
theAction _ _ f = elim2 (λ _ _ → isPropIsContr) λ _ _ → uniqueHom _ _ f
open Functor
universalPShf : Functor (ΣC∥P∥Cat ^op) (CommAlgebrasCategory {ℓ = ℓ''} R {ℓ' = ℓ''})
F-ob universalPShf = uncurry theMap
F-hom universalPShf {x = x} {y = y} f = theAction _ _ f (y .snd) (x. snd) .fst
F-id universalPShf {x = x} = theAction (x .fst) (x .fst) (id C) (x .snd) (x .snd) .snd _
F-seq universalPShf {x = x} {z = z} f g = theAction _ _ (g ⋆⟨ C ⟩ f) (z .snd) (x .snd) .snd _
| 39.936508
| 100
| 0.638712
|
29afc43a8ff6e4af733d97802c820d7782ad76e4
| 1,274
|
agda
|
Agda
|
test/interaction/Issue1138.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue1138.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue1138.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2014-05-21, reported and test case by Fabien Renaud
module Issue1138 where
open import Common.Equality
postulate
Var : Set
Varset : Set
_∖_ : Varset -> Var -> Varset
_⊆_ : Varset -> Varset -> Set
data Expression : Set where
abs : Var -> Expression -> Expression
FV : Expression -> Varset
FV (abs x M) = FV M ∖ x
data Env (A : Set) : Set where
<> : Env A
_,_:=_ : Env A -> Var -> A -> Env A
postulate
dom : ∀ {A} -> Env A -> Varset
extend-dom : ∀ {A : Set} {a : A} {x xs ρ}
-> (xs ∖ x) ⊆ dom ρ
-> xs ⊆ dom (ρ , x := a)
record Model (D : Set) : Set where
field
eval : (e : Expression) (ρ : Env D) -> FV e ⊆ dom ρ -> D
d : D
law : ∀ {M N ρ ν x y}
-> eval M (ρ , x := d) (extend-dom {!!}) ≡
eval N (ν , y := d) (extend-dom {!!})
-> eval (abs x M) ρ {!!} ≡
eval (abs y N) ν {!!}
-- Expected: For holes numbered 0,1,2,3 above and four goals below:
-- ?0 : (FV M ∖ x) ⊆ dom ρ
-- ?1 : (FV N ∖ y) ⊆ dom ν
-- ?2 : FV (abs x M) ⊆ dom ρ
-- ?3 : FV (abs y N) ⊆ dom ν
-- There was a problem that two interaction points were created
-- per ? in record fields, thus, they were off in emacs.
-- (Introduced by fix for issue 1083).
| 26
| 68
| 0.511774
|
414d931715b84d1150a8a189edb0822dbc47f43a
| 2,396
|
agda
|
Agda
|
src/Categories/Morphism/Properties.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Morphism/Properties.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Morphism/Properties.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Morphism.Properties {o ℓ e} (𝒞 : Category o ℓ e) where
open import Data.Product using (_,_; _×_)
open Category 𝒞
open Definitions 𝒞
open HomReasoning
import Categories.Morphism as M
open M 𝒞
open import Categories.Morphism.Reasoning 𝒞
private
variable
A B C D : Obj
f g h i : A ⇒ B
module _ (iso : Iso f g) where
open Iso iso
Iso-resp-≈ : f ≈ h → g ≈ i → Iso h i
Iso-resp-≈ {h = h} {i = i} eq₁ eq₂ = record
{ isoˡ = begin
i ∘ h ≈˘⟨ eq₂ ⟩∘⟨ eq₁ ⟩
g ∘ f ≈⟨ isoˡ ⟩
id ∎
; isoʳ = begin
h ∘ i ≈˘⟨ eq₁ ⟩∘⟨ eq₂ ⟩
f ∘ g ≈⟨ isoʳ ⟩
id ∎
}
Iso-swap : Iso g f
Iso-swap = record
{ isoˡ = isoʳ
; isoʳ = isoˡ
}
Iso⇒Mono : Mono f
Iso⇒Mono h i eq = begin
h ≈⟨ introˡ isoˡ ⟩
(g ∘ f) ∘ h ≈⟨ pullʳ eq ⟩
g ∘ f ∘ i ≈⟨ cancelˡ isoˡ ⟩
i ∎
Iso⇒Epi : Epi f
Iso⇒Epi h i eq = begin
h ≈⟨ introʳ isoʳ ⟩
h ∘ f ∘ g ≈⟨ pullˡ eq ⟩
(i ∘ f) ∘ g ≈⟨ cancelʳ isoʳ ⟩
i ∎
Iso-∘ : Iso f g → Iso h i → Iso (h ∘ f) (g ∘ i)
Iso-∘ {f = f} {g = g} {h = h} {i = i} iso iso′ = record
{ isoˡ = begin
(g ∘ i) ∘ h ∘ f ≈⟨ cancelInner (isoˡ iso′) ⟩
g ∘ f ≈⟨ isoˡ iso ⟩
id ∎
; isoʳ = begin
(h ∘ f) ∘ g ∘ i ≈⟨ cancelInner (isoʳ iso) ⟩
h ∘ i ≈⟨ isoʳ iso′ ⟩
id ∎
}
where open Iso
Iso-≈ : f ≈ h → Iso f g → Iso h i → g ≈ i
Iso-≈ {f = f} {h = h} {g = g} {i = i} eq iso iso′ = begin
g ≈⟨ introˡ (isoˡ iso′) ⟩
(i ∘ h) ∘ g ≈˘⟨ (refl⟩∘⟨ eq) ⟩∘⟨refl ⟩
(i ∘ f) ∘ g ≈⟨ cancelʳ (isoʳ iso) ⟩
i ∎
where open Iso
module _ where
open _≅_
isos×≈⇒≈ : ∀ {f g : A ⇒ B} → h ≈ i → (iso₁ : A ≅ C) → (iso₂ : B ≅ D) →
CommutativeSquare f (from iso₁) (from iso₂) h →
CommutativeSquare g (from iso₁) (from iso₂) i →
f ≈ g
isos×≈⇒≈ {h = h} {i = i} {f = f} {g = g} eq iso₁ iso₂ sq₁ sq₂ = begin
f ≈⟨ switch-fromtoˡ iso₂ sq₁ ⟩
to iso₂ ∘ h ∘ from iso₁ ≈⟨ refl⟩∘⟨ (eq ⟩∘⟨refl ) ⟩
to iso₂ ∘ i ∘ from iso₁ ≈˘⟨ switch-fromtoˡ iso₂ sq₂ ⟩
g ∎
-- This might be trivial, but it also shouldn't be proved more than once!
Mono-id : Mono {A = A} id
Mono-id g₁ g₂ eq = begin
g₁ ≈˘⟨ identityˡ ⟩
id ∘ g₁ ≈⟨ eq ⟩
id ∘ g₂ ≈⟨ identityˡ ⟩
g₂ ∎
| 24.44898
| 73
| 0.476628
|
313b0ff2f91a8d2b56ed9d4907615576452f1165
| 121
|
agda
|
Agda
|
prototyping/Properties/Functions.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-12-05T21:53:03.000Z
|
2021-12-05T21:53:03.000Z
|
prototyping/Properties/Functions.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/Properties/Functions.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
module Properties.Functions where
infixr 5 _∘_
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(f ∘ g) x = f (g x)
| 17.285714
| 51
| 0.487603
|
4aafcf4749a34ebb46473069bd29f34af434055d
| 30,869
|
agda
|
Agda
|
agda/FsubMinus.agda
|
HuStmpHrrr/popl20-artifact
|
48214a55ebb484fd06307df4320813d4a002535b
|
[
"MIT"
] | 1
|
2021-09-23T08:40:28.000Z
|
2021-09-23T08:40:28.000Z
|
agda/FsubMinus.agda
|
HuStmpHrrr/popl20-artifact
|
48214a55ebb484fd06307df4320813d4a002535b
|
[
"MIT"
] | null | null | null |
agda/FsubMinus.agda
|
HuStmpHrrr/popl20-artifact
|
48214a55ebb484fd06307df4320813d4a002535b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
-- In this module, we define F<:⁻, F<:ᵈ (F<: deterministic defined in Pierce92) and
-- show that F<:⁻ subtyping is undecidable.
module FsubMinus where
open import Data.List as List
open import Data.Nat
open import Data.Maybe as Maybe
open import Data.Product
open import Data.Vec as Vec renaming (_∷_ to _‼_ ; [] to nil) hiding (_++_)
open import Function
open import Data.Empty renaming (⊥ to False)
open import Relation.Nullary
open import Relation.Unary using () renaming (Decidable to UDecidable)
open import Relation.Binary using () renaming (Decidable to BDecidable)
open import Relation.Binary.PropositionalEquality as ≡
open import Data.Nat.Properties as ℕₚ
open import Data.Maybe.Properties as Maybeₚ
open import Utils
-- Definition of F<:⁻
--
-- F<:⁻ is defined by removing function types (_⟶_ in the paper) from F<:.
module FsubMinus where
infix 6 var_
infixr 6 Π<:_∙_
-- Types
--
-- * ⊤ is a supertype of all types.
-- * (var n) represents a type variable.
-- * (Π<: S ∙ U) represent a universal type (∀ X <: S . U).
data Ftyp : Set where
⊤ : Ftyp
var_ : ℕ → Ftyp
Π<:_∙_ : Ftyp → Ftyp → Ftyp
-- typing context
Env : Set
Env = List Ftyp
-- shifting operation of de Bruijn indices
infixl 7 _↑_
_↑_ : Ftyp → ℕ → Ftyp
⊤ ↑ n = ⊤
(var x) ↑ n with n ≤? x
... | yes p = var (suc x)
... | no ¬p = var x
(Π<: S ∙ U) ↑ n = Π<: S ↑ n ∙ U ↑ suc n
infix 4 _<:_∈_
data _<:_∈_ : ℕ → Ftyp → Env → Set where
hd : ∀ {T Γ} → 0 <: T ↑ 0 ∈ T ∷ Γ
tl : ∀ {n T T′ Γ} → n <: T ∈ Γ → suc n <: T ↑ 0 ∈ T′ ∷ Γ
-- subtyping judgment of F<:⁻
-- The statement of the rules should be self-explanatory.
infix 4 _⊢F_<:_
data _⊢F_<:_ : Env → Ftyp → Ftyp → Set where
ftop : ∀ {Γ T} →
Γ ⊢F T <: ⊤
fvrefl : ∀ {Γ n} →
Γ ⊢F var n <: var n
fbinds : ∀ {Γ n T U} →
n <: T ∈ Γ →
Γ ⊢F T <: U →
Γ ⊢F var n <: U
fall : ∀ {Γ S₁ S₂ U₁ U₂} →
Γ ⊢F S₂ <: S₁ →
Γ ‣ S₂ ! ⊢F U₁ <: U₂ →
Γ ⊢F Π<: S₁ ∙ U₁ <: Π<: S₂ ∙ U₂
-- The remaining are some technical setup.
env-lookup : Env → ℕ → Maybe Ftyp
env-lookup [] n = nothing
env-lookup (T ∷ Γ) zero = just $ T ↑ 0
env-lookup (T ∷ Γ) (suc n) = Maybe.map (_↑ 0) $ env-lookup Γ n
lookup⇒<:∈ : ∀ {Γ n T} → env-lookup Γ n ≡ just T → n <: T ∈ Γ
lookup⇒<:∈ {[]} {n} ()
lookup⇒<:∈ {T ∷ Γ} {zero} refl = hd
lookup⇒<:∈ {T ∷ Γ} {suc n} eq with env-lookup Γ n | lookup⇒<:∈ {Γ} {n}
... | nothing | rec with eq
... | ()
lookup⇒<:∈ {T ∷ Γ} {suc n} refl | just T′ | rec = tl (rec refl)
<:∈⇒lookup : ∀ {Γ n T} → n <: T ∈ Γ → env-lookup Γ n ≡ just T
<:∈⇒lookup hd = refl
<:∈⇒lookup (tl <:∈)
rewrite <:∈⇒lookup <:∈ = refl
env-lookup′ : Env → ℕ → Maybe Ftyp
env-lookup′ Γ n = Maybe.map (repeat (suc n) (_↑ 0)) (lookupOpt Γ n)
env-lookup-same : ∀ Γ n → env-lookup Γ n ≡ env-lookup′ Γ n
env-lookup-same [] n = refl
env-lookup-same (T ∷ Γ) zero = refl
env-lookup-same (T ∷ Γ) (suc n)
rewrite env-lookup-same Γ n = sym $ Maybeₚ.map-compose (lookupOpt Γ n)
<:∈-map : ∀ {a} {A : Set a} {n T} {f : A → Ftyp} {_↑′_ : A → ℕ → A} Γ →
(∀ a n → f a ↑ n ≡ f (a ↑′ n)) →
n <: T ∈ List.map f Γ → ∃ λ a → T ≡ f a
<:∈-map {f = f} Γ comm d = aux _ d refl
where aux : ∀ {n T Γ*} Γ → n <: T ∈ Γ* → Γ* ≡ List.map f Γ → ∃ λ a → T ≡ f a
aux [] hd ()
aux (T ∷ Γ) hd refl = -, comm _ _
aux [] (tl <:∈) ()
aux (T ∷ Γ) (tl <:∈) refl with aux Γ <:∈ refl
... | a , refl = -, comm _ _
<:∈-func : ∀ {x T T′ Γ} → x <: T ∈ Γ → x <: T′ ∈ Γ → T ≡ T′
<:∈-func hd hd = refl
<:∈-func (tl T∈Γ) (tl T′∈Γ) = cong (_↑ 0) (<:∈-func T∈Γ T′∈Γ)
Ftyp-measure : Ftyp → ℕ
Ftyp-measure ⊤ = 1
Ftyp-measure (var x) = 1
Ftyp-measure (Π<: S ∙ U) = Ftyp-measure S + Ftyp-measure U
Ftyp-measure≥1 : ∀ T → Ftyp-measure T ≥ 1
Ftyp-measure≥1 ⊤ = s≤s z≤n
Ftyp-measure≥1 (var _) = s≤s z≤n
Ftyp-measure≥1 (Π<: S ∙ U) = ≤-trans (Ftyp-measure≥1 S) (≤-stepsʳ _ ≤-refl)
↑-idx : ℕ → ℕ → ℕ
↑-idx x n with n ≤? x
... | yes p = suc x
... | no ¬p = x
↑-var : ∀ x n → (var x) ↑ n ≡ var (↑-idx x n)
↑-var x n with n ≤? x
... | yes p = refl
... | no ¬p = refl
Ftyp-measure-↑ : ∀ T m → Ftyp-measure (T ↑ m) ≡ Ftyp-measure T
Ftyp-measure-↑ ⊤ m = refl
Ftyp-measure-↑ (var x) m
rewrite ↑-var x m = refl
Ftyp-measure-↑ (Π<: S ∙ U) m
rewrite Ftyp-measure-↑ S m
| Ftyp-measure-↑ U (suc m) = refl
F-measure : ∀ {Γ S U} → Γ ⊢F S <: U → ℕ
F-measure ftop = 1
F-measure fvrefl = 1
F-measure (fbinds _ D) = 1 + F-measure D
F-measure (fall D₁ D₂) = 1 + F-measure D₁ + F-measure D₂
F-deriv = Σ (Env × Ftyp × Ftyp) λ { (Γ , S , U) → Γ ⊢F S <: U }
env : F-deriv → Env
env ((Γ , _) , _) = Γ
typ₁ : F-deriv → Ftyp
typ₁ ((_ , S , U) , _) = S
typ₂ : F-deriv → Ftyp
typ₂ ((_ , S , U) , _) = U
F-measure-packed : F-deriv → ℕ
F-measure-packed (_ , D) = F-measure D
≡⊤-dec : UDecidable (_≡ ⊤)
≡⊤-dec ⊤ = yes refl
≡⊤-dec (var _) = no (λ ())
≡⊤-dec (Π<: _ ∙ _) = no (λ ())
Π<:-injective : ∀ {S U S′ U′} → Π<: S ∙ U ≡ Π<: S′ ∙ U′ → S ≡ S′ × U ≡ U′
Π<:-injective refl = refl , refl
Ftyp-≡-dec : BDecidable (_≡_ {A = Ftyp})
Ftyp-≡-dec ⊤ ⊤ = yes refl
Ftyp-≡-dec ⊤ (var _) = no (λ ())
Ftyp-≡-dec ⊤ (Π<: _ ∙ _) = no (λ ())
Ftyp-≡-dec (var _) ⊤ = no (λ ())
Ftyp-≡-dec (var x) (var y) with x ≟ y
... | yes x≡y = yes (cong var_ x≡y)
... | no x≢y = no (λ { refl → x≢y refl })
Ftyp-≡-dec (var _) (Π<: _ ∙ _) = no (λ ())
Ftyp-≡-dec (Π<: _ ∙ _) ⊤ = no (λ ())
Ftyp-≡-dec (Π<: _ ∙ _) (var _) = no (λ ())
Ftyp-≡-dec (Π<: S ∙ U) (Π<: S′ ∙ U′)
with Ftyp-≡-dec S S′ | Ftyp-≡-dec U U′
... | yes S≡S′ | yes U≡U′ = yes (cong₂ Π<:_∙_ S≡S′ U≡U′)
... | yes S≡S′ | no U≢U′ = no λ Π<:≡ → U≢U′ (proj₂ (Π<:-injective Π<:≡))
... | no S≢S′ | yes U≡U′ = no (λ Π<:≡ → S≢S′ (proj₁ (Π<:-injective Π<:≡)))
... | no S≢S′ | no U≢U′ = no (λ Π<:≡ → S≢S′ (proj₁ (Π<:-injective Π<:≡)))
-- Definition of F<:
--
-- Here we also define full F<:. We do not use it anywhere.
module Full where
infix 6 var_
infixr 6 _⇒_ Π<:_∙_
-- Types
--
-- * ⊤ is a supertype of all types.
-- * (var n) represent a type variable.
-- * (S ⇒ U) represents a function type (S ⟶ U).
-- * (Π<: S ∙ U) represents a universal type (∀ X <: S . U).
data Ftyp : Set where
⊤ : Ftyp
var_ : ℕ → Ftyp
_⇒_ : Ftyp → Ftyp → Ftyp
Π<:_∙_ : Ftyp → Ftyp → Ftyp
Env : Set
Env = List Ftyp
infixl 7 _↑_
_↑_ : Ftyp → ℕ → Ftyp
⊤ ↑ n = ⊤
(var x) ↑ n with n ≤? x
... | yes p = var (suc x)
... | no ¬p = var x
(S ⇒ U) ↑ n = S ↑ n ⇒ U ↑ n
(Π<: S ∙ U) ↑ n = Π<: S ↑ n ∙ U ↑ suc n
infix 4 _<:_∈_
data _<:_∈_ : ℕ → Ftyp → Env → Set where
hd : ∀ {T Γ} → 0 <: T ↑ 0 ∈ T ∷ Γ
tl : ∀ {n T T′ Γ} → n <: T ∈ Γ → suc n <: T ↑ 0 ∈ T′ ∷ Γ
infix 4 _⊢F_<:_
data _⊢F_<:_ : Env → Ftyp → Ftyp → Set where
ftop : ∀ {Γ T} → Γ ⊢F T <: ⊤
fvrefl : ∀ {Γ n} → Γ ⊢F var n <: var n
fbinds : ∀ {Γ n T U} →
n <: T ∈ Γ →
Γ ⊢F T <: U →
Γ ⊢F var n <: U
ffun : ∀ {Γ S₁ S₂ U₁ U₂} →
Γ ⊢F S₂ <: S₁ →
Γ ⊢F U₁ <: U₂ →
Γ ⊢F S₁ ⇒ U₁ <: S₂ ⇒ U₂
fall : ∀ {Γ S₁ S₂ U₁ U₂} →
Γ ⊢F S₂ <: S₁ →
S₂ ∷ Γ ⊢F U₁ <: U₂ →
Γ ⊢F Π<: S₁ ∙ U₁ <: Π<: S₂ ∙ U₂
env-lookup : Env → ℕ → Maybe Ftyp
env-lookup [] n = nothing
env-lookup (T ∷ Γ) zero = just $ T ↑ 0
env-lookup (T ∷ Γ) (suc n) = Maybe.map (_↑ 0) $ env-lookup Γ n
lookup⇒<:∈ : ∀ {Γ n T} → env-lookup Γ n ≡ just T → n <: T ∈ Γ
lookup⇒<:∈ {[]} {n} ()
lookup⇒<:∈ {T ∷ Γ} {zero} refl = hd
lookup⇒<:∈ {T ∷ Γ} {suc n} eq with env-lookup Γ n | lookup⇒<:∈ {Γ} {n}
... | nothing | rec with eq
... | ()
lookup⇒<:∈ {T ∷ Γ} {suc n} refl | just T′ | rec = tl (rec refl)
<:∈⇒lookup : ∀ {Γ n T} → n <: T ∈ Γ → env-lookup Γ n ≡ just T
<:∈⇒lookup hd = refl
<:∈⇒lookup (tl <:∈)
rewrite <:∈⇒lookup <:∈ = refl
env-lookup′ : Env → ℕ → Maybe Ftyp
env-lookup′ Γ n = Maybe.map (repeat (suc n) (_↑ 0)) (lookupOpt Γ n)
env-lookup-same : ∀ Γ n → env-lookup Γ n ≡ env-lookup′ Γ n
env-lookup-same [] n = refl
env-lookup-same (T ∷ Γ) zero = refl
env-lookup-same (T ∷ Γ) (suc n)
rewrite env-lookup-same Γ n = sym $ Maybeₚ.map-compose (lookupOpt Γ n)
open FsubMinus
-- Undecidability of F<:
--
-- Here we show a reduction proof from F<:⁻ to F<:. Assuming F<:⁻ subtyping being
-- undecidable (which is about to be shown below), we formalize that F<: subtyping is
-- undecidable.
module FsubUndec where
-- the interpretation function of types from F<:⁻ to F<:
infixl 5 _*
_* : Ftyp → Full.Ftyp
⊤ * = Full.⊤
var x * = Full.var x
Π<: T₁ ∙ T₂ * = Full.Π<: T₁ * ∙ (T₂ *)
*-↑-comm : ∀ (T : Ftyp) n → (T *) Full.↑ n ≡ (T ↑ n) *
*-↑-comm ⊤ n = refl
*-↑-comm (var x) n with n ≤? x
... | yes p = refl
... | no ¬p = refl
*-↑-comm (Π<: S ∙ U) n rewrite *-↑-comm S n | *-↑-comm U (suc n)
= refl
repeat*-↑-comm : ∀ T n m → repeat n (Full._↑ m) (T *) ≡ (repeat n (_↑ m) T) *
repeat*-↑-comm T zero m = refl
repeat*-↑-comm T (suc n) m
rewrite repeat*-↑-comm T n m = *-↑-comm (repeat n (_↑ m) T) m
*-injective : ∀ {S U} → S * ≡ U * → S ≡ U
*-injective {⊤} {⊤} refl = refl
*-injective {⊤} {var x} ()
*-injective {⊤} {Π<: _ ∙ _} ()
*-injective {var x} {⊤} ()
*-injective {var x} {var .x} refl = refl
*-injective {var _} {Π<: _ ∙ _} ()
*-injective {Π<: S ∙ S₁} {⊤} ()
*-injective {Π<: _ ∙ _} {var x} ()
*-injective {Π<: S ∙ S₁} {Π<: U ∙ U₁} eq
with S * | U * | *-injective {S} {U} | S₁ * | U₁ * | *-injective {S₁} {U₁}
... | S* | U* | r | S₁* | U₁* | r₁ with eq
... | refl rewrite r refl | r₁ refl = refl
Full<:∈⇒<:∈ : ∀ {Γ n T} → n Full.<: T * ∈ List.map _* Γ → n <: T ∈ Γ
Full<:∈⇒<:∈ {Γ} {n} <:∈
with Full.<:∈⇒lookup <:∈
... | eq rewrite Full.env-lookup-same (List.map _* Γ) n
with lookupOpt (List.map _* Γ) n | lookupOpt-map-inv {f = _*} Γ {n}
... | just T | inv
with inv refl
... | T′ , refl , lk
with just-injective eq
... | eq′
rewrite repeat*-↑-comm T′ n 0 | *-↑-comm (repeat n (_↑ 0) T′) 0
with *-injective eq′
... | refl = lookup⇒<:∈ (trans (env-lookup-same Γ n) aux)
where aux : env-lookup′ Γ n ≡ just (repeat n (_↑ 0) T′ ↑ 0)
aux rewrite lk = refl
Full<:∈⇒<:∈ {Γ} {n} <:∈ | () | nothing | _
<:∈⇒Full<:∈ : ∀ {Γ n T} → n <: T ∈ Γ → n Full.<: T * ∈ List.map _* Γ
<:∈⇒Full<:∈ (hd {T})
rewrite sym $ *-↑-comm T 0 = Full.hd
<:∈⇒Full<:∈ (tl {T = T} <:∈)
rewrite sym $ *-↑-comm T 0 = Full.tl (<:∈⇒Full<:∈ <:∈)
full⇒minus-gen : ∀ {Γ* S* U*} → Γ* Full.⊢F S* <: U* →
∀ {Γ S U} → Γ* ≡ List.map _* Γ → S* ≡ (S *) → U* ≡ (U *) →
Γ ⊢F S <: U
full⇒minus-gen Full.ftop {Γ} {S} {⊤} eqΓ eqS refl = ftop
full⇒minus-gen Full.ftop {Γ} {S} {var x} eqΓ eqS ()
full⇒minus-gen Full.ftop {Γ} {S} {Π<: U ∙ U₁} eqΓ eqS ()
full⇒minus-gen Full.fvrefl {Γ} {⊤} {⊤} eqΓ () eqU
full⇒minus-gen Full.fvrefl {Γ} {var x} {⊤} eqΓ refl ()
full⇒minus-gen Full.fvrefl {Γ} {Π<: S ∙ S₁} {⊤} eqΓ () eqU
full⇒minus-gen Full.fvrefl {Γ} {⊤} {var x} eqΓ () eqU
full⇒minus-gen Full.fvrefl {Γ} {var x} {var .x} eqΓ refl refl = fvrefl
full⇒minus-gen Full.fvrefl {Γ} {Π<: S ∙ S₁} {var x} eqΓ () eqU
full⇒minus-gen Full.fvrefl {Γ} {⊤} {Π<: U ∙ U₁} eqΓ () eqU
full⇒minus-gen Full.fvrefl {Γ} {var x} {Π<: U ∙ U₁} eqΓ refl ()
full⇒minus-gen Full.fvrefl {Γ} {Π<: S ∙ S₁} {Π<: U ∙ U₁} eqΓ () eqU
full⇒minus-gen (Full.fbinds T∈Γ* Dfull) {Γ} {⊤} {U} eqΓ () eqU
full⇒minus-gen (Full.fbinds {n = n} T∈Γ* Dfull)
{Γ} {var x} {U} eqΓ refl eqU = aux
where T′∈Γ : ∀ {Γ* T} → n Full.<: T ∈ Γ* → Γ* ≡ List.map _* Γ → ∃[ T′ ] (T ≡ T′ *)
T′∈Γ <:∈ refl with Full.<:∈⇒lookup <:∈
... | eq rewrite Full.env-lookup-same (List.map _* Γ) n
with lookupOpt (List.map _* Γ) n | inspect (lookupOpt (List.map _* Γ)) n
... | just T | [ lk ]
with lookupOpt-map-inv Γ lk | just-injective eq
... | T′ , refl , lkeq | eq′
rewrite repeat*-↑-comm T′ n 0
| *-↑-comm (repeat n (_↑ 0) T′) 0 = -, sym eq′
T′∈Γ <:∈ refl | () | nothing | _
aux : Γ ⊢F var n <: U
aux with T′∈Γ T∈Γ* eqΓ
... | T′ , refl rewrite eqΓ = fbinds (Full<:∈⇒<:∈ T∈Γ*) (full⇒minus-gen Dfull refl refl eqU)
full⇒minus-gen (Full.fbinds T∈Γ* Dfull) {Γ} {Π<: S ∙ S₁} {U} eqΓ () eqU
full⇒minus-gen (Full.ffun _ _) {Γ} {⊤} {U} eqΓ () eqU
full⇒minus-gen (Full.ffun _ _) {Γ} {var x₂} {U} eqΓ () eqU
full⇒minus-gen (Full.ffun _ _) {Γ} {Π<: S ∙ S₁} {U} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {⊤} {⊤} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {⊤} {var x} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {⊤} {Π<: U ∙ U₁} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {var x} {⊤} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {var x} {var x₁} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {var x} {Π<: U ∙ U₁} eqΓ () eqU
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {Π<: S ∙ S₁} {⊤} eqΓ refl ()
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {Π<: S ∙ S₁} {var x} eqΓ refl ()
full⇒minus-gen (Full.fall Dp Dbody) {Γ} {Π<: S₁ ∙ U₁} {Π<: S₂ ∙ U₂}
eqΓ refl refl = fall (full⇒minus-gen Dp eqΓ refl refl)
(full⇒minus-gen Dbody (aux eqΓ) refl refl)
where aux : ∀ {Γ*} → Γ* ≡ List.map _* Γ → (S₂ *) ∷ Γ* ≡ (S₂ *) ∷ List.map _* Γ
aux refl = refl
-- The following two functions accomplish the reduction proof.
full⇒minus : ∀ {Γ S U} → List.map _* Γ Full.⊢F S * <: U * → Γ ⊢F S <: U
full⇒minus Dfull = full⇒minus-gen Dfull refl refl refl
minus⇒full : ∀ {Γ S U} → Γ ⊢F S <: U → List.map _* Γ Full.⊢F S * <: U *
minus⇒full ftop = Full.ftop
minus⇒full fvrefl = Full.fvrefl
minus⇒full {Γ} (fbinds T∈Γ Dminus) = Full.fbinds (<:∈⇒Full<:∈ T∈Γ) (minus⇒full Dminus)
minus⇒full (fall Dp Db) = Full.fall (minus⇒full Dp) (minus⇒full Db)
-- Definition of F<:ᵈ
--
-- Definition of F<:ᵈ F<:ᵈ (F<: deterministic) is an intermediate construction in
-- Pierce92 towards the undecidability proof of F<: subtyping. This intermediate
-- construction is also shown undecidable and we directly use that result here.
module DeterministicFsubSized where
open import Induction.Nat
import Relation.Binary.EqReasoning as Eq
infix 6 var⁻_
infixr 6 Π⁺<:_∙¬_ Π⁻<:⊤∙¬_
-- Types
--
-- Types in F<:ᵈ are divided into two parts and the two parts are mutually defined.
-- The two parts are positive types [Ftyp⁺] and negative types [Ftyp⁻] and defined
-- as follows.
mutual
-- Positive types
-- * ⊤⁺ corresponds to ⊤ in F<:⁻.
-- * (Π⁺<: Ts ∙¬ U) represents a universal type where all types involved are negative types (∀ X₁ <: T₁ ... ∀ Xₙ <: Tₙ . ∀ X <: U . X).
data Ftyp⁺ (n : ℕ) : Set where
⊤⁺ : Ftyp⁺ n
Π⁺<:_∙¬_ : Vec (Ftyp⁻ n) n → Ftyp⁻ n → Ftyp⁺ n
-- Negative types
-- * (var⁻ n) corresponds to a type variable in F<:⁻.
-- * (Π⁻<:⊤∙¬_ T) represents a universal type where all parameter types are ⊤ and T is positive (∀ X₁ <: ⊤ ... ∀ Xₙ <: ⊤ . ∀ X <: T . X).
data Ftyp⁻ (n : ℕ) : Set where
var⁻_ : ℕ → Ftyp⁻ n
Π⁻<:⊤∙¬_ : Ftyp⁺ n → Ftyp⁻ n
-- shifting operation for both positive and negative types
infixl 7 _↑⁺_ _↑⁺_ ⟦_↑⁻_⟧
mutual
_↑⁺_ : ∀ {n} → Ftyp⁺ n → ℕ → Ftyp⁺ n
⊤⁺ ↑⁺ n = ⊤⁺
_↑⁺_ {m} (Π⁺<: S ∙¬ U) n = Π⁺<: ⟦ S ↑⁻ n ⟧ ∙¬ (U ↑⁻ (m + n))
_↑⁻_ : ∀ {n} → Ftyp⁻ n → ℕ → Ftyp⁻ n
(var⁻ x) ↑⁻ n with n ≤? x
... | yes p = var⁻ (suc x)
... | no ¬p = var⁻ x
_↑⁻_ {m} (Π⁻<:⊤∙¬ T) n = Π⁻<:⊤∙¬ (T ↑⁺ (m + n))
⟦_↑⁻_⟧ : ∀ {n m} → Vec (Ftyp⁻ n) m → ℕ → Vec (Ftyp⁻ n) m
⟦ nil ↑⁻ n ⟧ = nil
⟦ T ‼ S ↑⁻ n ⟧ = T ↑⁻ n ‼ ⟦ S ↑⁻ suc n ⟧
-- In F<:ᵈ, typing contexts consist only of negative types.
NEnv : ℕ → Set
NEnv n = List (Ftyp⁻ n)
nenv-lookup : ∀ {n} → NEnv n → ℕ → Maybe (Ftyp⁻ n)
nenv-lookup Γ n = Maybe.map (repeat (suc n) (_↑⁻ 0)) (lookupOpt Γ n)
-- subtyping judgment of F<:ᵈ
--
-- For a fixed n, a subtyping judgment of F<:ᵈ is a ternary predicate, among a
-- typing context (consisting of negative types), a negative type and a positive
-- type. A subtyping judgment in F<:ᵈ asserts that a negative type is a subtype of
-- a positive type in the given context. Notice that there is no subtyping relation
-- between two negative types or two positive types.
infix 4 [_]_⊢FD_<:_
data [_]_⊢FD_<:_ (n : ℕ) : NEnv n → Ftyp⁻ n → Ftyp⁺ n → Set where
fdtop : ∀ {Γ T} → [ n ] Γ ⊢FD T <: ⊤⁺
fdvar : ∀ {Γ m T S U} →
nenv-lookup Γ m ≡ just T →
[ n ] Γ ⊢FD T <: Π⁺<: S ∙¬ U →
[ n ] Γ ⊢FD var⁻ m <: Π⁺<: S ∙¬ U
fdall : ∀ {Γ T S U} →
[ n ] Vec.foldl (λ _ → _) (flip _∷_) Γ S ⊢FD U <: T →
[ n ] Γ ⊢FD Π⁻<:⊤∙¬ T <: Π⁺<: S ∙¬ U
infix 5 _*⁺ _*⁻
infix 6 Π⁻[_]∙_ Π⁺_∙_
-- the interpretation function of types from F<:ᵈ to F<:⁻
mutual
_*⁺ : ∀ {n} → Ftyp⁺ n → Ftyp
⊤⁺ *⁺ = ⊤
Π⁺<: S ∙¬ U *⁺ = Π⁻[ S ]∙ U
Π⁻[_]∙_ : ∀ {n m} → Vec (Ftyp⁻ n) m → Ftyp⁻ n → Ftyp
Π⁻[ nil ]∙ U = Π<: U *⁻ ∙ var zero
Π⁻[ S ‼ Ss ]∙ U = Π<: S *⁻ ∙ Π⁻[ Ss ]∙ U
_*⁻ : ∀ {n} → Ftyp⁻ n → Ftyp
var⁻ n *⁻ = var n
_*⁻ {n} (Π⁻<:⊤∙¬ T) = Π⁺ n ∙ T
Π⁺_∙_ : ∀ {n} → ℕ → Ftyp⁺ n → Ftyp
Π⁺ zero ∙ T = Π<: T *⁺ ∙ var zero
Π⁺ suc n ∙ T = Π<: ⊤ ∙ Π⁺ n ∙ T
module _ where
open Eq (setoid ℕ)
mutual
*-↑-comm⁺ : ∀ {m} (T : Ftyp⁺ m) n → (T *⁺) ↑ n ≡ (T ↑⁺ n) *⁺
*-↑-comm⁺ ⊤⁺ n = refl
*-↑-comm⁺ (Π⁺<: S ∙¬ U) n = Π-↑-comm⁻ S U n
Π-↑-comm⁻ : ∀ {i j} (S : Vec (Ftyp⁻ i) j) (U : Ftyp⁻ i) n →
(Π⁻[ S ]∙ U) ↑ n ≡ Π⁻[ ⟦ S ↑⁻ n ⟧ ]∙ (U ↑⁻ (j + n))
Π-↑-comm⁻ nil U n
rewrite *-↑-comm⁻ U n = refl
Π-↑-comm⁻ {j = suc j} (T ‼ S) U n
rewrite *-↑-comm⁻ T n
| Π-↑-comm⁻ S U (suc n)
| +-suc j n = refl
*-↑-comm⁻ : ∀ {m} (T : Ftyp⁻ m) n → (T *⁻) ↑ n ≡ (T ↑⁻ n) *⁻
*-↑-comm⁻ (var⁻ x) n with n ≤? x
... | yes p = refl
... | no ¬p = refl
*-↑-comm⁻ (Π⁻<:⊤∙¬ T) n = Π-↑-comm⁺ _ T n
Π-↑-comm⁺ : ∀ {i} j (T : Ftyp⁺ i) n →
(Π⁺ j ∙ T) ↑ n ≡ Π⁺ j ∙ (T ↑⁺ (j + n))
Π-↑-comm⁺ zero T n
rewrite *-↑-comm⁺ T n = refl
Π-↑-comm⁺ (suc j) T n
rewrite Π-↑-comm⁺ j T (suc n)
| +-suc j n = refl
repeat*-↑-comm⁻ : ∀ {i} (T : Ftyp⁻ i) n m →
repeat n (_↑ m) (T *⁻) ≡ (repeat n (_↑⁻ m) T) *⁻
repeat*-↑-comm⁻ T zero m = refl
repeat*-↑-comm⁻ T (suc n) m
rewrite repeat*-↑-comm⁻ T n m = *-↑-comm⁻ (repeat n (_↑⁻ m) T) m
mutual
*-injective⁺ : ∀ {n} {S U : Ftyp⁺ n} → S *⁺ ≡ U *⁺ → S ≡ U
*-injective⁺ {n} {⊤⁺} {⊤⁺} eq = refl
*-injective⁺ {.0} {⊤⁺} {Π⁺<: nil ∙¬ _} ()
*-injective⁺ {.(suc _)} {⊤⁺} {Π⁺<: _ ‼ _ ∙¬ _} ()
*-injective⁺ {n} {Π⁺<: S ∙¬ U} {⊤⁺} eq = ⊥-elim $ aux eq
where aux : ∀ {n m} {S : Vec (Ftyp⁻ n) m} {U} → ¬ Π⁻[ S ]∙ U ≡ ⊤
aux {S = nil} ()
aux {S = _ ‼ S} ()
*-injective⁺ {n} {Π⁺<: S₁ ∙¬ U₁} {Π⁺<: S₂ ∙¬ U₂} eq with Π-injective⁻ eq
... | refl , refl = refl
Π-injective⁻ : ∀ {n m} {S₁ S₂ : Vec (Ftyp⁻ n) m} {U₁ U₂ : Ftyp⁻ n} →
Π⁻[ S₁ ]∙ U₁ ≡ Π⁻[ S₂ ]∙ U₂ →
S₁ ≡ S₂ × U₁ ≡ U₂
Π-injective⁻ {S₁ = nil} {nil} {U₁} {U₂} eq
with U₁ *⁻ | U₂ *⁻ | *-injective⁻ {S = U₁} {U₂}
... | U₁* | U₂* | rec with eq
... | refl = refl , rec refl
Π-injective⁻ {S₁ = S ‼ S₁} {S′ ‼ S₂} {U₁} {U₂} eq
with S *⁻ | S′ *⁻ | Π⁻[ S₁ ]∙ U₁ | Π⁻[ S₂ ]∙ U₂
| *-injective⁻ {S = S} {S′}
| Π-injective⁻ {S₁ = S₁} {S₂} {U₁} {U₂}
... | S* | S′* | Π₁ | Π₂ | recS | rec with eq
... | refl with recS refl | rec refl
... | refl | refl , eqU = refl , eqU
*-injective⁻ : ∀ {n} {S U : Ftyp⁻ n} → S *⁻ ≡ U *⁻ → S ≡ U
*-injective⁻ {n} {var⁻ x} {var⁻ .x} refl = refl
*-injective⁻ {zero} {var⁻ _} {Π⁻<:⊤∙¬ _} ()
*-injective⁻ {suc n} {var⁻ _} {Π⁻<:⊤∙¬ _} ()
*-injective⁻ {n} {Π⁻<:⊤∙¬ T} {var⁻ x} eq = ⊥-elim $ aux _ eq
where aux : ∀ {n x} {T : Ftyp⁺ n} m → ¬ Π⁺ m ∙ T ≡ var x
aux zero ()
aux (suc m) ()
*-injective⁻ {n} {Π⁻<:⊤∙¬ T₁} {Π⁻<:⊤∙¬ T₂} eq with Π-injective⁺ n eq
... | refl = refl
Π-injective⁺ : ∀ {n} {T₁ T₂ : Ftyp⁺ n} m →
Π⁺ m ∙ T₁ ≡ Π⁺ m ∙ T₂ →
T₁ ≡ T₂
Π-injective⁺ {T₁ = T₁} {T₂} zero eq
with T₁ *⁺ | T₂ *⁺ | *-injective⁺ {S = T₁} {T₂}
... | T₁* | T₂* | rec with eq
... | refl = rec refl
Π-injective⁺ {T₁ = T₁} {T₂} (suc m) eq
with Π⁺ m ∙ T₁ | Π⁺ m ∙ T₂ | Π-injective⁺ {T₁ = T₁} {T₂} m
... | Π₁ | Π₂ | rec with eq
... | refl = rec refl
data Pi (P Q : Ftyp → Set) : ℕ → Ftyp → Set where
pzero : ∀ {U} → Q U → Pi P Q zero (Π<: U ∙ var zero)
psuc : ∀ {n S T} → P S → Pi P Q n T -> Pi P Q (suc n) (Π<: S ∙ T)
-- two predicates that capture the images of the interpretation functions
mutual
-- Covar captures the image of the interpretation function from positive types to F<:.
data Covar (n : ℕ) : Ftyp → Set where
cvtop : Covar n ⊤
cvΠ : ∀ {T} → Pi (Contra n) (Contra n) n T → Covar n T
-- Contra captures the image of the interpretation function from negative types to F<:.
data Contra (n : ℕ) : Ftyp → Set where
cnvar : ∀ m → Contra n (var m)
cnΠ : ∀ {T} → Pi (⊤ ≡_) (Covar n) n T → Contra n T
infix 5 ⟦_⟧⁺ ⟦_⟧⁻
-- the inverse functions of the interpretation functions
mutual
⟦_⟧⁺ : ∀ {n T} → Covar n T → Ftyp⁺ n
⟦ cvtop ⟧⁺ = ⊤⁺
⟦ cvΠ P ⟧⁺ = Π⁺<: ∥ P ∥⁺₁ ∙¬ ∥ P ∥⁺₂
∥_∥⁺₁ : ∀ {n m T} → Pi (Contra n) (Contra n) m T → Vec (Ftyp⁻ n) m
∥ pzero U ∥⁺₁ = nil
∥ psuc S P ∥⁺₁ = ⟦ S ⟧⁻ ‼ ∥ P ∥⁺₁
∥_∥⁺₂ : ∀ {n m T} → Pi (Contra n) (Contra n) m T → Ftyp⁻ n
∥ pzero U ∥⁺₂ = ⟦ U ⟧⁻
∥ psuc S P ∥⁺₂ = ∥ P ∥⁺₂
⟦_⟧⁻ : ∀ {n T} → Contra n T → Ftyp⁻ n
⟦ cnvar m ⟧⁻ = var⁻ m
⟦ cnΠ P ⟧⁻ = Π⁻<:⊤∙¬ ∥ P ∥⁻
∥_∥⁻ : ∀ {n m T} → Pi (⊤ ≡_) (Covar n) m T → Ftyp⁺ n
∥ pzero T ∥⁻ = ⟦ T ⟧⁺
∥ psuc S P ∥⁻ = ∥ P ∥⁻
mutual
⟦⟧⁺*⁺⇒id : ∀ {n T} (cT : Covar n T) → (⟦ cT ⟧⁺ *⁺) ≡ T
⟦⟧⁺*⁺⇒id cvtop = refl
⟦⟧⁺*⁺⇒id (cvΠ P) = ∥∥⁻Π⇒id P
∥∥⁻Π⇒id : ∀ {n m T} (P : Pi (Contra n) (Contra n) m T) →
Π⁻[ ∥ P ∥⁺₁ ]∙ ∥ P ∥⁺₂ ≡ T
∥∥⁻Π⇒id (pzero U)
rewrite ⟦⟧⁻*⁻⇒id U = refl
∥∥⁻Π⇒id (psuc S P)
rewrite ⟦⟧⁻*⁻⇒id S | ∥∥⁻Π⇒id P = refl
⟦⟧⁻*⁻⇒id : ∀ {n T} (cT : Contra n T) → (⟦ cT ⟧⁻ *⁻) ≡ T
⟦⟧⁻*⁻⇒id (cnvar m) = refl
⟦⟧⁻*⁻⇒id (cnΠ P) = ∥∥⁺Π⇒id P
∥∥⁺Π⇒id : ∀ {n m T} (P : Pi (⊤ ≡_) (Covar n) m T) → Π⁺ m ∙ ∥ P ∥⁻ ≡ T
∥∥⁺Π⇒id (pzero U) rewrite ⟦⟧⁺*⁺⇒id U = refl
∥∥⁺Π⇒id (psuc refl P) rewrite ∥∥⁺Π⇒id P = refl
infix 5 *⟦_⟧⁺ *⟦_⟧⁻ *∥_,_∥⁺
mutual
*⟦_⟧⁺ : ∀ {n} (T : Ftyp⁺ n) → Covar n (T *⁺)
*⟦ ⊤⁺ ⟧⁺ = cvtop
*⟦ Π⁺<: S ∙¬ U ⟧⁺ = cvΠ *∥ S , U ∥⁺
*∥_,_∥⁺ : ∀ {n m} (S : Vec (Ftyp⁻ n) m) (U : Ftyp⁻ n) →
Pi (Contra n) (Contra n) m (Π⁻[ S ]∙ U)
*∥ nil , U ∥⁺ = pzero *⟦ U ⟧⁻
*∥ S ‼ Ss , U ∥⁺ = psuc *⟦ S ⟧⁻ *∥ Ss , U ∥⁺
*⟦_⟧⁻ : ∀ {n} (T : Ftyp⁻ n) → Contra n (T *⁻)
*⟦ var⁻ x ⟧⁻ = cnvar x
*⟦ Π⁻<:⊤∙¬ T ⟧⁻ = cnΠ *∥ _ , T ∥⁻
*∥_,_∥⁻ : ∀ {n} m (T : Ftyp⁺ n) → Pi (⊤ ≡_) (Covar n) m (Π⁺ m ∙ T)
*∥ zero , T ∥⁻ = pzero *⟦ T ⟧⁺
*∥ suc m , T ∥⁻ = psuc refl *∥ m , T ∥⁻
mutual
*⁺⟦⟧⁺⇒id : ∀ {n} (T : Ftyp⁺ n) → ⟦ *⟦ T ⟧⁺ ⟧⁺ ≡ T
*⁺⟦⟧⁺⇒id ⊤⁺ = refl
*⁺⟦⟧⁺⇒id (Π⁺<: S ∙¬ U)
rewrite *∥∥⁺₁⇒id S U | *∥∥⁺₂⇒id S U = refl
*∥∥⁺₁⇒id : ∀ {n m} (S : Vec (Ftyp⁻ n) m) (U : Ftyp⁻ n) → ∥ *∥ S , U ∥⁺ ∥⁺₁ ≡ S
*∥∥⁺₁⇒id nil U = refl
*∥∥⁺₁⇒id (S ‼ Ss) U
rewrite *⁻⟦⟧⁻⇒id S | *∥∥⁺₁⇒id Ss U = refl
*∥∥⁺₂⇒id : ∀ {n m} (S : Vec (Ftyp⁻ n) m) (U : Ftyp⁻ n) → ∥ *∥ S , U ∥⁺ ∥⁺₂ ≡ U
*∥∥⁺₂⇒id nil U = *⁻⟦⟧⁻⇒id U
*∥∥⁺₂⇒id (S ‼ Ss) U = *∥∥⁺₂⇒id Ss U
*⁻⟦⟧⁻⇒id : ∀ {n} (T : Ftyp⁻ n) → ⟦ *⟦ T ⟧⁻ ⟧⁻ ≡ T
*⁻⟦⟧⁻⇒id (var⁻ x) = refl
*⁻⟦⟧⁻⇒id {n} (Π⁻<:⊤∙¬ T)
rewrite *∥∥⁻⇒id n T = refl
*∥∥⁻⇒id : ∀ {n} m (T : Ftyp⁺ n) → ∥ *∥ m , T ∥⁻ ∥⁻ ≡ T
*∥∥⁻⇒id zero T = *⁺⟦⟧⁺⇒id T
*∥∥⁻⇒id (suc m) T = *∥∥⁻⇒id m T
open Measure <-wellFounded F-measure-packed renaming (wfRec to F-rec)
minus⇒deterministic-gen : ∀ (D : F-deriv) →
∀ n {Γ} (S : Contra n (typ₁ D)) (U : Covar n (typ₂ D)) →
env D ≡ List.map _*⁻ Γ →
[ n ] Γ ⊢FD ⟦ S ⟧⁻ <: ⟦ U ⟧⁺
minus⇒deterministic-gen D = F-rec (λ D → prop D) pf D
where prop : F-deriv → Set
prop D = ∀ n {Γ} (S : Contra n (typ₁ D)) (U : Covar n (typ₂ D)) →
env D ≡ List.map _*⁻ Γ →
[ n ] Γ ⊢FD ⟦ S ⟧⁻ <: ⟦ U ⟧⁺
open ≤-Reasoning
pf : ∀ (D : F-deriv) →
(∀ D′ → F-measure-packed D′ < F-measure-packed D → prop D′) → prop D
pf ((Γ , S* , .⊤) , ftop) rec n S cvtop eq = fdtop
pf ((Γ , S* , .⊤) , ftop) rec n S (cvΠ ()) eq
pf ((Γ , .(var _) , .(var _)) , fvrefl) rec n S (cvΠ ()) eq
pf ((Γ , .(var m) , .⊤) , fbinds T∈Γ D) rec n (cnvar m) cvtop eq = fdtop
pf ((Γ , .(var m) , U*) , fbinds T∈Γ D) rec n {Γ′} (cnvar m) (cvΠ P) refl
with trans (sym $ env-lookup-same (List.map _*⁻ Γ′) m) $ <:∈⇒lookup T∈Γ
... | eq with lookupOpt (List.map _*⁻ Γ′) m | inspect (lookupOpt (List.map _*⁻ Γ′)) m
pf ((Γ , .(var m) , U*) , fbinds T∈Γ D) rec n {Γ′} (cnvar m) (cvΠ P) refl | refl | just T | [ lk ]
with lookupOpt-map-inv Γ′ lk
... | T′ , refl , lk′
rewrite repeat*-↑-comm⁻ T′ m 0
| *-↑-comm⁻ (repeat m (_↑⁻ 0) T′) 0
with rec (-, D) ≤-refl n *⟦ repeat m (_↑⁻ 0) T′ ↑⁻ 0 ⟧⁻ (cvΠ P) refl
... | Drec rewrite *⁻⟦⟧⁻⇒id (repeat m (_↑⁻ 0) T′ ↑⁻ 0)
= fdvar (cong (Maybe.map (repeat (suc m) (_↑⁻ 0))) lk′) Drec
pf ((Γ , .(var m) , U*) , fbinds T∈Γ D) rec n {Γ′} (cnvar m) (cvΠ P) refl | () | nothing | [ lk ]
pf ((Γ , .(var _) , U*) , fbinds T∈Γ D) rec n (cnΠ ()) U eq
pf ((Γ , .(Π<: _ ∙ _) , .(Π<: _ ∙ _)) , Dtop@(fall S₂<:S₁ U₁<:U₂))
rec n (cnΠ Ps) (cvΠ Pu) refl = fdall (aux _ n (fall S₂<:S₁ U₁<:U₂) Ps Pu ≤-refl)
where transport : ∀ {Γ T₁ T₂ S*} (S : Contra n S*)
(D : S* ∷ Γ ⊢F T₁ <: T₂) →
Σ ((⟦ S ⟧⁻ *⁻) ∷ Γ ⊢F T₁ <: T₂) (λ D′ → F-measure D′ ≡ F-measure D)
transport {Γ} {T₁} {T₂} S D
= subst (λ S → Σ (S ∷ Γ ⊢F T₁ <: T₂) (λ D′ → F-measure D′ ≡ F-measure D))
(sym $ ⟦⟧⁻*⁻⇒id S) (D , refl)
aux : ∀ {T₁ T₂} Γ m (D : List.map _*⁻ Γ ⊢F T₁ <: T₂)
(Ps : Pi (_≡_ ⊤) (Covar n) m T₁)
(Pu : Pi (Contra n) (Contra n) m T₂) →
F-measure D ≤ F-measure Dtop →
[ n ] Vec.foldl (λ _ → _) (flip _∷_) Γ ∥ Pu ∥⁺₁ ⊢FD ∥ Pu ∥⁺₂ <: ∥ Ps ∥⁻
aux Γ zero (fall <:₁ <:₂) (pzero S₁) (pzero S₂) ≤
= rec (-, <:₁) (≤-trans shrinks ≤) n S₂ S₁ refl
where shrinks : (F-measure <:₁) < suc (F-measure <:₁ + F-measure <:₂)
shrinks = begin-strict
F-measure <:₁ ≤⟨ ≤-stepsʳ (F-measure <:₂) ≤-refl ⟩
F-measure <:₁ + F-measure <:₂ <⟨ ≤-refl ⟩
suc (F-measure <:₁ + F-measure <:₂) ∎
aux Γ (suc m) (fall <:₁ <:₂) (psuc refl Ps) (psuc S₂ Pu) ≤
with transport S₂ <:₂
... | <:₂′ , eq = aux (⟦ S₂ ⟧⁻ ∷ Γ) m <:₂′ Ps Pu $
begin
F-measure <:₂′ ≡⟨ eq ⟩
F-measure <:₂ ≤⟨ ≤-stepsˡ (F-measure <:₁) ≤-refl ⟩
F-measure <:₁ + F-measure <:₂ <⟨ ≤ ⟩
suc (F-measure S₂<:S₁ + F-measure U₁<:U₂) ∎
-- The following two functions conclude the reduction proof from F<:ᵈ to F<:⁻.
minus⇒deterministic : ∀ n {Γ : NEnv n} {S U} → List.map _*⁻ Γ ⊢F S *⁻ <: U *⁺ → [ n ] Γ ⊢FD S <: U
minus⇒deterministic n {Γ} {S} {U} D with minus⇒deterministic-gen (-, D) n *⟦ S ⟧⁻ *⟦ U ⟧⁺ refl
... | D′ rewrite *⁻⟦⟧⁻⇒id S | *⁺⟦⟧⁺⇒id U = D′
deterministic⇒minus : ∀ n {Γ : NEnv n} {S U} → [ n ] Γ ⊢FD S <: U → List.map _*⁻ Γ ⊢F S *⁻ <: U *⁺
deterministic⇒minus n fdtop = ftop
deterministic⇒minus n {Γ} (fdvar {m = m} T∈Γ D)
with lookupOpt Γ m | inspect (lookupOpt Γ) m
deterministic⇒minus n {Γ} (fdvar {m = m} refl D) | just T | [ eq ]
= fbinds (lookup⇒<:∈ $ begin
env-lookup (List.map _*⁻ Γ) m ≡⟨ env-lookup-same (List.map _*⁻ Γ) m ⟩
env-lookup′ (List.map _*⁻ Γ) m ≡⟨ cong (Maybe.map (repeat (suc m) (_↑ 0)))
(lookupOpt-map Γ _*⁻ eq) ⟩
just (repeat m (_↑ 0) (T *⁻) ↑ 0) ≡⟨ cong (just ∘ (_↑ 0))
(repeat*-↑-comm⁻ T m 0) ⟩
just ((repeat m (_↑⁻ 0) T *⁻) ↑ 0) ≡⟨ cong just $ *-↑-comm⁻ (repeat m (_↑⁻ 0) T) 0 ⟩
just ((repeat m (_↑⁻ 0) T ↑⁻ 0) *⁻) ∎)
(deterministic⇒minus n D)
where open Eq (setoid (Maybe Ftyp))
deterministic⇒minus n {Γ} (fdvar {m = m} () D) | nothing | _
deterministic⇒minus n {Γ} (fdall D) = aux n _ _ _ D
where aux : ∀ {n} m {Γ} (S : Vec (Ftyp⁻ n) m) U T →
[ n ] Vec.foldl (λ _ → _) (flip _∷_) Γ S ⊢FD U <: T →
List.map _*⁻ Γ ⊢F Π⁺ m ∙ T <: Π⁻[ S ]∙ U
aux .0 nil U T D = fall (deterministic⇒minus _ D) fvrefl
aux .(suc _) (x ‼ S) U T D = fall ftop (aux _ S U T D)
| 39.626444
| 139
| 0.439826
|
1293c21dd341e78c395ee6572a3c180b7ee1e413
| 1,783
|
agda
|
Agda
|
Cubical/Data/HomotopyGroup/Base.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Data/HomotopyGroup/Base.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
Cubical/Data/HomotopyGroup/Base.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.HomotopyGroup.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
import Cubical.Foundations.GroupoidLaws as GL
open import Cubical.Foundations.Pointed
open import Cubical.Data.Nat
open import Cubical.Data.Group.Base
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.SetTruncation as SetTrunc
π^_ : ∀ {ℓ} → ℕ → Pointed ℓ → Group ℓ
π^_ {ℓ} n p = group ∥ A ∥₀ squash₀ g
where
n' : ℕ
n' = suc n
A : Type ℓ
A = typ ((Ω^ n') p)
g : isGroup ∥ A ∥₀
g = group-struct e _⁻¹ _⊙_ lUnit rUnit assoc lCancel rCancel
where
e : ∥ A ∥₀
e = ∣ pt ((Ω^ n') p) ∣₀
_⁻¹ : ∥ A ∥₀ → ∥ A ∥₀
_⁻¹ = SetTrunc.elim {B = λ _ → ∥ A ∥₀} (λ x → squash₀) λ a → ∣ sym a ∣₀
_⊙_ : ∥ A ∥₀ → ∥ A ∥₀ → ∥ A ∥₀
_⊙_ = SetTrunc.elim2 (λ _ _ → squash₀) λ a₀ a₁ → ∣ a₀ ∙ a₁ ∣₀
lUnit : (a : ∥ A ∥₀) → (e ⊙ a) ≡ a
lUnit = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _))
(λ a → cong ∣_∣₀ (sym (GL.lUnit a) ))
rUnit : (a : ∥ A ∥₀) → a ⊙ e ≡ a
rUnit = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _))
(λ a → cong ∣_∣₀ (sym (GL.rUnit a) ))
assoc : (a b c : ∥ A ∥₀) → ((a ⊙ b) ⊙ c) ≡ (a ⊙ (b ⊙ c))
assoc = SetTrunc.elim3 (λ _ _ _ → isProp→isSet (squash₀ _ _))
(λ a b c → cong ∣_∣₀ (sym (GL.assoc _ _ _)))
lCancel : (a : ∥ A ∥₀) → ((a ⁻¹) ⊙ a) ≡ e
lCancel = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _))
λ a → cong ∣_∣₀ (GL.lCancel _)
rCancel : (a : ∥ A ∥₀) → (a ⊙ (a ⁻¹)) ≡ e
rCancel = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _))
λ a → cong ∣_∣₀ (GL.rCancel _)
| 31.839286
| 80
| 0.514302
|
1c2f030b97274f8c50775b169eba2f6f1df89364
| 559
|
agda
|
Agda
|
test/Succeed/Issue133.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue133.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue133.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue133 where
data Nat : Set where
zz : Nat
ss : Nat → Nat
data _==_ {X : Set}(x : X) : X → Set where
refl : x == x
data Zero : Set where
data Eq? (x : Nat) : Nat → Set where
same : Eq? x x
diff : {y : Nat} → (x == y → Zero) → Eq? x y
-- This failed before due to absurd lambda checking not getting
-- postponed.
ioo : {y : Nat} → Eq? zz (ss y)
ioo {y} = diff λ ()
foo : {y : Nat} → zz == ss y → Zero
foo ()
goo : {y : Nat} → zz == ss y → Zero
goo = λ ()
hoo : {y : Nat}{X : Set} → ((zz == ss y → Zero) → X) → X
hoo boo = boo λ ()
| 18.032258
| 63
| 0.520572
|
417f9125ec2e908813fcc9640dd9941664d09e53
| 342
|
agda
|
Agda
|
test/Succeed/OverloadedConstructors.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/OverloadedConstructors.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/OverloadedConstructors.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module OverloadedConstructors where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Fin : Nat -> Set where
zero : {n : Nat} -> Fin (suc n)
suc : {n : Nat} -> Fin n -> Fin (suc n)
three : Nat
three = suc (suc (suc zero))
ftwo : Fin three
ftwo = suc (suc zero)
inc : Nat -> Nat
inc = suc
{-
{-# BUILTIN NATURAL Nat #-}
-}
| 14.25
| 42
| 0.581871
|
57de82bb317950f59abe43b9dc83a7e74c9bda68
| 9,696
|
agda
|
Agda
|
dialectica-cats/DCBSets.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
dialectica-cats/DCBSets.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
dialectica-cats/DCBSets.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
module DCBSets where
open import prelude
open import relations
-- The objects:
Obj : Set₁
Obj = Σ[ U ∈ Set ] (Σ[ X ∈ Set ] (Σ[ x ∈ (⊤ → X) ] (Σ[ d ∈ (X × X → X) ](Σ[ α ∈ (U → X → Set) ](
(∀{u : U}{x₁ x₂ : X} → α u (d (x₁ , x₂)) → ((α u x₁) × (α u x₂))) ×
( ∀{Y : Set}{x' : X}{F : Y → X}{y : ⊤ → Y} → d (x' , F (y triv)) ≡ x' ) ×
( ∀{Y : Set}{x' : X}{F : Y → X}{y : ⊤ → Y} → d (F (y triv) , x') ≡ x' ))))))
-- The morphisms:
Hom : Obj → Obj → Set
Hom (U , X , x , d₁ , α , p₁ ) (V , Y , y , d₂ , β , p₂) =
Σ[ f ∈ (U → V) ]
(Σ[ F ∈ (U → Y → X) ] ((∀{u : U}{y : Y} → α u (F u y) → β (f u) y)))
-- Composition:
comp : {A B C : Obj} → Hom A B → Hom B C → Hom A C
comp {(U , X , x , d₁ , α , dec₁ , p₁ , p₂)} {(V , Y , y , d₂ , β , dec₂ , p₃ , p₄)} {(W , Z , z , d₃ , γ , dec₃ , p₅ , p₆)} (f , F , q₁) (g , G , q₂) =
g ∘ f , (((λ u z' → F u (G (f u) z'))) ) , (λ {u} {z'} r → q₂ (q₁ r))
infixl 5 _○_
_○_ = comp
-- The contravariant hom-functor:
Homₐ : {A' A B B' : Obj} → Hom A' A → Hom B B' → Hom A B → Hom A' B'
Homₐ f h g = comp f (comp g h)
-- The identity function:
id : {A : Obj} → Hom A A
id {(U , V , n , d , α , p)} = (id-set , curry snd , id-set)
-- In this formalization we will only worry about proving that the
-- data of morphisms are equivalent, and not worry about the morphism
-- conditions. This will make proofs shorter and faster.
--
-- If we have parallel morphisms (f,F) and (g,G) in which we know that
-- f = g and F = G, then the condition for (f,F) will imply the
-- condition of (g,G) and vice versa. Thus, we can safely ignore it.
infix 4 _≡h_
_≡h_ : {A B : Obj} → (f g : Hom A B) → Set
_≡h_ {(U , X , _ , _ , _ , _ , _ , _)}{(V , Y , _ , β , _ , _ , _ , _)} (f , F , p₁) (g , G , p₂) = f ≡ g × F ≡ G
≡h-refl : {A B : Obj}{f : Hom A B} → f ≡h f
≡h-refl {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{f , F , _} = refl , refl
≡h-trans : ∀{A B}{f g h : Hom A B} → f ≡h g → g ≡h h → f ≡h h
≡h-trans {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{f , F , _}{g , G , _}{h , H , _} (p₁ , p₂) (p₃ , p₄) rewrite p₁ | p₂ | p₃ | p₄ = refl , refl
≡h-sym : ∀{A B}{f g : Hom A B} → f ≡h g → g ≡h f
≡h-sym {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{f , F , _}{g , G , _} (p₁ , p₂) rewrite p₁ | p₂ = refl , refl
≡h-subst-○ : ∀{A B C}{f₁ f₂ : Hom A B}{g₁ g₂ : Hom B C}{j : Hom A C}
→ f₁ ≡h f₂
→ g₁ ≡h g₂
→ f₂ ○ g₂ ≡h j
→ f₁ ○ g₁ ≡h j
≡h-subst-○ {U , X , _ , α , _ , _ , _ , _}
{V , Y , _ , β , _ , _ , _ , _}
{W , Z , _ , γ , _ , _ , _ , _}
{f₁ , F₁ , _}
{f₂ , F₂ , _}
{g₁ , G₁ , _}
{g₂ , G₂ , _}
{j , J , _}
(p₅ , p₆) (p₇ , p₈) (p₉ , p₁₀) rewrite p₅ | p₆ | p₇ | p₈ | p₉ | p₁₀ = refl , refl
○-assoc : ∀{A B C D}{f : Hom A B}{g : Hom B C}{h : Hom C D}
→ f ○ (g ○ h) ≡h (f ○ g) ○ h
○-assoc {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{W , Z , _ , γ , _ , _ , _ , _}{S , T , _ , ι , _ , _ , _ , _}
{f , F , _}{g , G , _}{h , H , _} = refl , refl
○-idl : ∀{A B}{f : Hom A B} → id ○ f ≡h f
○-idl {U , X , _ , _ , _ , _ , _ , _}{V , Y , _ , _ , _ , _ , _ , _}{f , F , _} = refl , refl
○-idr : ∀{A B}{f : Hom A B} → f ○ id ≡h f
○-idr {U , X , _ , _ , _ , _ , _ , _}{V , Y , _ , _ , _ , _ , _ , _}{f , F , _} = refl , refl
-- The tensor functor: ⊗
_⊗ᵣ_ : ∀{U X V Y : Set} → (U → X → Set) → (V → Y → Set) → ((U × V) → (X × Y) → Set)
_⊗ᵣ_ α β (u , v) (x , y) = (α u x) × (β v y)
_⊗ₒ_ : (A B : Obj) → Obj
(U , X , n₁ , d₁ , α , pr₁ , q₁ , q₂ ) ⊗ₒ (V , Y , n₂ , d₂ , β , pr₂ , q₃ , q₄) = ((U × V) , (X × Y) , trans-× n₁ n₂ , d⊗ , (α ⊗ᵣ β) , pr⊗ , ((λ {Y x' F y} → q₁⊗ {Y} {x'}{F}{y}) , (λ {Y x' F y} → q₂⊗ {Y} {x'}{F}{y})))
where
d⊗ : Σ (Σ X (λ x → Y)) (λ x → Σ X (λ x₁ → Y)) → Σ X (λ x → Y)
d⊗ ((x , y) , (x' , y')) = d₁ (x , x') , d₂ (y , y')
pr⊗ : {u : Σ U (λ x → V)} {x₁ x₂ : Σ X (λ x → Y)} → (α ⊗ᵣ β) u (d⊗ (x₁ , x₂)) → Σ ((α ⊗ᵣ β) u x₁) (λ x → (α ⊗ᵣ β) u x₂)
pr⊗ {u , v}{x , y}{x' , y'} (p , p') = (fst (pr₁ p) , fst (pr₂ p')) , snd (pr₁ p) , snd (pr₂ p')
q₁⊗ : {Y₁ : Set} {x' : Σ X (λ x → Y)} {F : Y₁ → Σ X (λ x → Y)}{y : ⊤ → Y₁} → d⊗ (x' , F (y triv)) ≡ x'
q₁⊗ {_}{x , y}{F}{p} with q₁ {x' = x}{fst ∘ F}{p} | q₃ {x' = y}{snd ∘ F}{p}
... | q'₁ | q'₂ with F (p triv)
... | x' , y' rewrite q'₁ | q'₂ = refl
q₂⊗ : {Y₁ : Set} {x' : Σ X (λ x → Y)} {F : Y₁ → Σ X (λ x → Y)}{y : ⊤ → Y₁} → d⊗ (F (y triv) , x') ≡ x'
q₂⊗ {Y}{x , y}{F}{p} with q₂ {_}{x}{fst ∘ F}{p} | q₄ {_}{y}{snd ∘ F}{p}
... | q'₁ | q'₂ with F (p triv)
... | x' , y' rewrite q'₁ | q'₂ = refl
F⊗ : ∀{Z T V X U Y : Set}{F : U → Z → X}{G : V → T → Y} → (U × V) → (Z × T) → (X × Y)
F⊗ {F = F}{G} (u , v) (z , t) = F u z , G v t
_⊗ₐ_ : {A B C D : Obj} → Hom A C → Hom B D → Hom (A ⊗ₒ B) (C ⊗ₒ D)
_⊗ₐ_ {(U , X , _ , _ , α , _ , _ , _)}{(V , Y , _ , _ , β , _ , _ , _)}{(W , Z , _ , _ , γ , _ , _ , _)}{(S , T , _ , _ , δ , _ , _ , _)} (f , F , p₁) (g , G , p₂) = ⟨ f , g ⟩ , F⊗ {F = F}{G} , p⊗
where
p⊗ : {u : Σ U (λ x → V)} {y : Σ Z (λ x → T)} → (α ⊗ᵣ β) u (F⊗ {F = F}{G} u y) → (γ ⊗ᵣ δ) (⟨ f , g ⟩ u) y
p⊗ {u , v}{z , t} (p₃ , p₄) = p₁ p₃ , p₂ p₄
π₁ : {A B : Obj} → Hom (A ⊗ₒ B) A
π₁ {U , X , n₁ , _ , α , _ , _ , _}{V , Y , n₂ , _ , β , _ , _ , _} = fst , (λ r x → x , n₂ triv) , cond
where
cond : {u : Σ U (λ x → V)} {y : X} → (α ⊗ᵣ β) u (y , n₂ triv) → α (fst u) y
cond {u , v}{x} (p₁ , p₂) = p₁
π₂ : {A B : Obj} → Hom (A ⊗ₒ B) B
π₂ {U , X , n₁ , _ , α , _ , _ , _}{V , Y , n₂ , _ , β , _ , _ , _} = snd , (λ r y → n₁ triv , y) , cond
where
cond : {u : Σ U (λ x → V)} {y : Y} → (α ⊗ᵣ β) u (n₁ triv , y) → β (snd u) y
cond {u , v}{y} (p₁ , p₂) = p₂
cart-ar : {A B C : Obj}
→ (f : Hom C A)
→ (g : Hom C B)
→ Hom C (A ⊗ₒ B)
cart-ar {U , X , x , d₁ , α , pr₁ , q₁ , q₂}{V , Y , y , d₂ , β , pr₂ , q₃ , q₄}{W , Z , z , d₃ , γ , pr₃ , q₅ , q₆} (f , F , p₁) (g , G , p₂) = trans-× f g , crt , cond
where
crt : W → Σ X (λ x₁ → Y) → Z
crt w (x' , y') = d₃ ((F w x') , (G w y'))
cond : {u : W} {y₁ : Σ X (λ x₁ → Y)} → γ u (crt u y₁) → (α ⊗ᵣ β) (f u , g u) y₁
cond {w}{x' , y'} p = p₁ (fst (pr₃ {w}{F w x'}{G w y'} p)) , p₂ (snd (pr₃ {w}{F w x'}{G w y'} p))
cart-diag₁ : ∀{A B C : Obj}
→ {f : Hom C A}
→ {g : Hom C B}
→ (cart-ar f g) ○ π₁ ≡h f
cart-diag₁ {U , X , x , d₁ , α , pr₁ , q₁ , q₂}{V , Y , y , d₂ , β , q₃ , q₄ , q₅}{W , Z , z , d₃ , γ , q₆ , q₇ , q₈}{f , F , p₁}{g , G , p₂} = refl , ext-set (λ {w} → ext-set (λ {x} → q₇ {x' = F w x}{G w}{y}))
cart-diag₂ : ∀{A B C : Obj}
→ {f : Hom C A}
→ {g : Hom C B}
→ (cart-ar f g) ○ π₂ ≡h g
cart-diag₂ {U , X , x , d₁ , α , pr₁ , q₁ , q₂}{V , Y , y , d₂ , β , q₃ , q₄ , q₅}{W , Z , z , d₃ , γ , q₆ , q₇ , q₈}{f , F , p₁}{g , G , p₂} = refl , ext-set (λ {w} → ext-set (λ {y₁} → q₈ {x' = G w y₁}{F w}{x}))
-- The □-comonad:
□ₒ-cond : ∀{U X : Set} → (α : U → X → Set) → U → 𝕃 X → Set
□ₒ-cond {U}{X} α u [] = ⊤
□ₒ-cond {U}{X} α u (x :: xs) = (α u x) × (□ₒ-cond α u xs)
□ₒ-cond-++ : ∀{U X : Set}{α : U → X → Set}{u : U}{l₁ l₂ : 𝕃 X}
→ □ₒ-cond α u (l₁ ++ l₂) ≡ ((□ₒ-cond α u l₁) × (□ₒ-cond α u l₂))
□ₒ-cond-++ {U}{X}{α}{u}{[]}{l₂} = ∧-unit
□ₒ-cond-++ {U}{X}{α}{u}{x :: xs}{l₂} rewrite □ₒ-cond-++ {U}{X}{α}{u}{xs}{l₂} = ∧-assoc
□ₒ : Obj → Obj
□ₒ (U , X , x , d , α , pr , q₁ , q₂) = U , X * , (λ t → [ x t ]) , □d , □ₒ-cond {U}{X} α , {!!} , {!!} , {!!}
where
□d : (X *) × (X *) → X *
□d (l₁ , l₂) = l₁ ++ l₂
-- □pr : {u : U} {x₁ x₂ : 𝕃 X}
-- → □ₒ-cond α u (□d (x₁ , x₂))
-- → Σ (□ₒ-cond α u x₁) (λ x₃ → □ₒ-cond α u x₂)
-- □pr {_}{[]} {[]} x₁ = triv , triv
-- □pr {u}{x₁ = []} {x₁ :: x₂} (a , b) = triv , snd (pr a) , snd (□pr {u}{[]}{x₂} b)
-- □pr {u}{x₁ = x₁ :: x₂} {[]} (a , b) = (fst (pr a) , fst (□pr {u}{x₂}{[]} b)) , triv
-- □pr {_}{x₁ :: x₂} {x₃ :: x₄} (a , b) with pr a
-- ... | c , e with □pr {x₁ = x₂} b
-- ... | f , g = (c , f) , (e , g)
□q₁ : {Y : Set} {x' : 𝕃 X} {F : Y → 𝕃 X} {y : ⊤ → Y} → □d (x' , F (y triv)) ≡ x'
□q₁ {x' = []}{F}{y} = {!!}
□q₁ {x' = x₁ :: x'}{F}{y} with F (y triv)
... | [] = {!!}
... | a :: as = {!!}
{-
□ₐ-s : ∀{U Y X : Set}
→ (U → Y → X)
→ (U → Y * → X *)
□ₐ-s f u l = map (f u) l
□ₐ : {A B : Obj} → Hom A B → Hom (□ₒ A) (□ₒ B)
□ₐ {U , X , α}{V , Y , β} (f , F , p) = f , (□ₐ-s F , aux)
where
aux : {u : U} {y : 𝕃 Y} → □ₒ-cond α u (□ₐ-s F u y) → □ₒ-cond β (f u) y
aux {u}{[]} p₁ = triv
aux {u}{y :: ys} (p₁ , p₂) = p p₁ , aux p₂
-- Of-course is a comonad:
ε : ∀{A} → Hom (□ₒ A) A
ε {U , X , α} = id-set , (λ u x → [ x ]) , fst
δ-s : {U X : Set} → U → 𝕃 (𝕃 X) → 𝕃 X
δ-s u xs = foldr _++_ [] xs
δ : ∀{A} → Hom (□ₒ A) (□ₒ (□ₒ A))
δ {U , X , α} = id-set , δ-s , cond
where
cond : {u : U} {y : 𝕃 (𝕃 X)} → □ₒ-cond α u (foldr _++_ [] y) → □ₒ-cond (□ₒ-cond α) u y
cond {u}{[]} p = triv
cond {u}{l :: ls} p with □ₒ-cond-++ {U}{X}{α}{u}{l}{foldr _++_ [] ls}
... | p' rewrite p' with p
... | p₂ , p₃ = p₂ , cond {u}{ls} p₃
comonand-diag₁ : ∀{A}
→ (δ {A}) ○ (□ₐ (δ {A})) ≡h (δ {A}) ○ (δ { □ₒ A})
comonand-diag₁ {U , X , α} = refl , ext-set (λ {x} → ext-set (λ {l} → aux {x} {l}))
where
aux : ∀{x : U}{l : 𝕃 (𝕃 (𝕃 X))}
→ foldr _++_ [] (□ₐ-s (λ u xs
→ foldr _++_ [] xs) x l) ≡ foldr _++_ [] (foldr _++_ [] l)
aux {u}{[]} = refl
aux {u}{x :: xs} rewrite aux {u}{xs} = foldr-append {_}{_}{X}{X}{x}{foldr _++_ [] xs}
comonand-diag₂ : ∀{A}
→ (δ {A}) ○ (ε { □ₒ A}) ≡h (δ {A}) ○ (□ₐ (ε {A}))
comonand-diag₂ {U , X , α} =
refl , ext-set (λ {u} → ext-set (λ {l} → aux {l}))
where
aux : ∀{a : 𝕃 X} → a ++ [] ≡ foldr _++_ [] (map (λ x → x :: []) a)
aux {[]} = refl
aux {x :: xs} rewrite (++[] xs) | sym (foldr-map {_}{X}{xs}) = refl
-}
| 39.414634
| 218
| 0.379744
|
29c9a393b0381dd344d77bd9f5a8de7d7f9d6282
| 214
|
agda
|
Agda
|
src/Auxiliary/Extensionality.agda
|
peterthiemann/dual-session
|
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
|
[
"BSD-2-Clause"
] | 1
|
2022-02-13T05:43:25.000Z
|
2022-02-13T05:43:25.000Z
|
src/Auxiliary/Extensionality.agda
|
peterthiemann/dual-session
|
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
|
[
"BSD-2-Clause"
] | null | null | null |
src/Auxiliary/Extensionality.agda
|
peterthiemann/dual-session
|
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
|
[
"BSD-2-Clause"
] | 1
|
2019-12-07T16:12:50.000Z
|
2019-12-07T16:12:50.000Z
|
module Auxiliary.Extensionality where
open import Relation.Binary.PropositionalEquality using (_≡_)
postulate
ext : {A : Set}{B : A → Set}{f : (x : A) → B x} {g : (x : A) → B x} →
(∀ x → f x ≡ g x) → f ≡ g
| 26.75
| 71
| 0.579439
|
57ef13a9b6c667e681b5d8a6e4fd17c8c8258ace
| 111,198
|
agda
|
Agda
|
src/Structure-identity-principle/Erased.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Structure-identity-principle/Erased.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Structure-identity-principle/Erased.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A variant of the development in "Internalizing Representation
-- Independence with Univalence" (by Angiuli, Cavallo, Mörtberg and
-- Zeuner) with support for erasure
------------------------------------------------------------------------
-- This development follows parts of "Internalizing Representation
-- Independence with Univalence" (and sometimes the code supporting
-- that paper) fairly closely, but with explicit support for erasure,
-- and there are some other differences. Note that some things
-- discussed in the paper are not included, for instance tactics and
-- most examples.
-- This formalisation was started because an anonymous reviewer asked
-- whether something like this could be done, and when I had made some
-- initial experiments Andrea Vezzosi encouraged me to include more in
-- the formalisation.
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Structure-identity-principle.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as B using (_↔_)
open import Equality.Decidable-UIP equality-with-J
open import Equality.Path.Isomorphisms eq
import Equality.Path.Isomorphisms.Univalence eq as U
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Erased.Cubical eq as EEq
using (_≃ᴱ_; Is-equivalenceᴱ)
open import Equivalence.Erased.Contractible-preimages.Cubical eq as ECP
using (Contractibleᴱ)
open import Equivalence-relation equality-with-J
open import Erased.Cubical eq as Er hiding (map; map-id)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional.Erased eq as T
using (∥_∥ᴱ; ∣_∣)
import List equality-with-J as L
import Maybe equality-with-J as Maybe
import Monad equality-with-J as Monad
import Nat equality-with-J as Nat
open import Quotient.Erased eq as Q using (_/ᴱ_; [_])
open import Univalence-axiom equality-with-J
open import
Nat.Binary equality-with-J instance-of-[]-cong-axiomatisation
as Bin using (Bin)
private
variable
a b c d e r : Level
C : Type c
A A₁ A₂ B B₁ B₂ Ax F f G g M m N P R R₁ R₂ S
x x′ x₁ x₂ y y′ ys z z₁ z₂ : C
------------------------------------------------------------------------
-- The structure identity principle
-- Structures.
Structure : (a b : Level) → Type (lsuc (a ⊔ b))
Structure a b = Type a → Type b
-- Types with a given structure.
Type-with : Structure a b → Type (lsuc a ⊔ b)
Type-with {a = a} F = ∃ λ (A : Type a) → F A
-- Axioms.
--
-- Originally I made the argument of type Type-with F erased. After
-- feedback from Andrea Vezzosi I instead added a use of Erased in
-- _With-the-axioms_ below.
Axioms : Structure a b → (c : Level) → Type (lsuc a ⊔ b ⊔ lsuc c)
Axioms F c = Type-with F → Type c
-- One can add axioms to structures.
_With-the-axioms_ :
(F : Structure a b) → Axioms F c → Structure a (b ⊔ c)
(F With-the-axioms Ax) A = ∃ λ (x : F A) → Erased (Ax (A , x))
-- A type of predicates defining when a given equivalence (with erased
-- proofs) is structure-preserving.
Structure-preserving-equivalence-predicate :
Structure a b → (c : Level) → Type (lsuc a ⊔ b ⊔ lsuc c)
Structure-preserving-equivalence-predicate F c =
(A B : Type-with F) → proj₁ A ≃ᴱ proj₁ B → Type c
-- One can lift a "structure-preserving equivalence predicate" from F
-- to F With-the-axioms Ax.
Lift-With-the-axioms :
Structure-preserving-equivalence-predicate F c →
Structure-preserving-equivalence-predicate (F With-the-axioms Ax) c
Lift-With-the-axioms P (A , x , _) (B , y , _) = P (A , x) (B , y)
-- Structure-preserving equivalences (with erased proofs).
infix 4 _≃[_]ᴱ_
_≃[_]ᴱ_ :
{F : Structure a b} →
Type-with F → @0 Structure-preserving-equivalence-predicate F c →
Type-with F →
Type (a ⊔ c)
A ≃[ P ]ᴱ B = ∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → Erased (P A B eq)
-- Univalent pairs of structures and predicates.
record Univalent
(@0 F : Structure a b)
(@0 P : Structure-preserving-equivalence-predicate F c) :
Type (lsuc a ⊔ b ⊔ c) where
field
-- This field is erased because it uses univalence and EEq.≃ᴱ→≃.
@0 univalent :
{A B : Type-with F}
(eq : proj₁ A ≃ᴱ proj₁ B) →
P A B eq ≃
(subst F (≃⇒≡ U.abstract-univ (EEq.≃ᴱ→≃ eq)) (proj₂ A) ≡ proj₂ B)
-- If Ax is pointwise propositional, then the functions
-- _With-the-axioms Ax and Lift-With-the-axioms preserve
-- Univalent univ.
--
-- This is a variant of Lemma 3.3 from "Internalizing Representation
-- Independence with Univalence".
Univalent-With-the-axioms :
{@0 P : Structure-preserving-equivalence-predicate F c} →
@0 (∀ A → Is-proposition (Ax A)) →
Univalent F P →
Univalent (F With-the-axioms Ax) (Lift-With-the-axioms P)
Univalent-With-the-axioms
{F = F} {Ax = Ax} {P = P} prop u .Univalent.univalent
{A = A₁ , x₁ , ax₁} {B = A₂ , x₂ , ax₂} eq =
P (A₁ , x₁) (A₂ , x₂) eq ↝⟨ u .Univalent.univalent eq ⟩
subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ ≡ x₂ ↔⟨ ignore-propositional-component (H-level-Erased 1 (prop _)) ⟩
(subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ , _) ≡ (x₂ , ax₂) ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-pair _ _ ⟩□
subst (F With-the-axioms Ax) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (x₁ , ax₁) ≡
(x₂ , ax₂) □
where
univ = U.abstract-univ
-- The structure identity principle.
--
-- This is a variant of Theorem 3.1 from "Internalizing Representation
-- Independence with Univalence". Note that the principle is erased.
@0 sip :
Univalent F P →
(A ≃[ P ]ᴱ B) ≃ (A ≡ B)
sip {F = F} {P = P} {A = A} {B = B} u =
(A ≃[ P ]ᴱ B) ↔⟨⟩
(∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → Erased (P A B eq)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → P A B eq) ↝⟨ Σ-cong
(inverse $ EEq.≃≃≃ᴱ F.∘ ≡≃≃ U.abstract-univ)
(u .Univalent.univalent) ⟩
(∃ λ (eq : proj₁ A ≡ proj₁ B) → subst F eq (proj₂ A) ≡ proj₂ B) ↔⟨ B.Σ-≡,≡↔≡ ⟩□
(A ≡ B) □
-- If there is a structure-preserving equivalence (for a univalent
-- pair of a structure and a predicate) between two types with
-- structures, where one side satisfies some axioms, then the other
-- side also satisfies the axioms (in erased contexts), and the
-- resulting triple is equivalent (with erased proofs) to the other
-- one.
--
-- This is a variant of Corollary 3.4 from "Internalizing
-- Representation Independence with Univalence".
induced-structures :
{@0 P : Structure-preserving-equivalence-predicate F c} →
@0 Univalent F P →
(X@(A , x , _) : Type-with (F With-the-axioms Ax)) →
((B , y) : Type-with F) →
(A , x) ≃[ P ]ᴱ (B , y) →
∃ λ (ax : Erased (Ax (B , y))) →
X ≃[ Lift-With-the-axioms P ]ᴱ (B , y , ax)
induced-structures {Ax = Ax} u (A , x , ax) (B , y) eq =
Er.map (subst Ax (_≃_.to (sip u) eq)) ax
, eq
------------------------------------------------------------------------
-- Some binary relation combinators, along with some properties
-- The converse of a binary relation.
infix 10 _⁻¹
_⁻¹ : (A → B → Type c) → (B → A → Type c)
(R ⁻¹) x y = R y x
-- Propositionally truncated composition of two binary relations (the
-- definition uses ∥_∥ᴱ).
infixr 9 _;ᴱ_
_;ᴱ_ :
{B : Type b} →
(A → B → Type d) → (B → C → Type e) → A → C → Type (b ⊔ d ⊔ e)
(R ;ᴱ S) x z = ∥ (∃ λ y → R x y × S y z) ∥ᴱ
-- Two ways to compose a relation and its converse.
infix 10 _⟵ _⟶
_⟵ : {B : Type b} → (A → B → Type c) → A → A → Type (b ⊔ c)
R ⟵ = R ;ᴱ R ⁻¹
_⟶ : {A : Type a} → (A → B → Type c) → B → B → Type (a ⊔ c)
R ⟶ = R ⁻¹ ;ᴱ R
-- If R is a propositional equivalence relation targetting a certain
-- universe, then R ⟵ is pointwise logically equivalent (with erased
-- proofs) to R.
⟵≃ᴱ :
{A : Type a}
{R : A → A → Type a} →
@0 (∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
∀ {x y} → (R ⟵) x y ≃ᴱ R x y
⟵≃ᴱ prop equiv =
EEq.⇔→≃ᴱ
T.truncation-is-proposition
(prop _ _)
(T.rec λ where
.T.truncation-is-propositionʳ → prop _ _
.T.∣∣ʳ (_ , Rxy , Rzy) →
E.transitive Rxy (E.symmetric Rzy))
(λ Rxz → ∣ _ , Rxz , E.reflexive ∣)
where
module E = Is-equivalence-relation equiv
-- If R is a propositional equivalence relation targetting a certain
-- universe, then R ⟶ is pointwise logically equivalent (with erased
-- proofs) to R.
⟶≃ᴱ :
{A : Type a}
{R : A → A → Type a} →
@0 (∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
∀ {x y} → (R ⟶) x y ≃ᴱ R x y
⟶≃ᴱ prop equiv =
EEq.⇔→≃ᴱ
T.truncation-is-proposition
(prop _ _)
(T.rec λ where
.T.truncation-is-propositionʳ → prop _ _
.T.∣∣ʳ (_ , Ryx , Ryz) →
E.transitive (E.symmetric Ryx) Ryz)
(λ Rzx →
∣ _ , E.symmetric Rzx , E.reflexive ∣)
where
module E = Is-equivalence-relation equiv
-- If R is a propositional equivalence relation targetting a certain
-- universe, then R ⟵ is equal to R (in erased contexts).
@0 ⟵≡ :
{A : Type a}
{R : A → A → Type a} →
(∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
R ⟵ ≡ R
⟵≡ prop equiv =
⟨ext⟩ λ _ → ⟨ext⟩ λ _ →
≃⇒≡ U.univ $
EEq.≃ᴱ→≃ $
⟵≃ᴱ prop equiv
-- If R is a propositional equivalence relation targetting a certain
-- universe, then R ⟶ is equal to R (in erased contexts).
@0 ⟶≡ :
{A : Type a}
{R : A → A → Type a} →
(∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
R ⟶ ≡ R
⟶≡ prop equiv =
⟨ext⟩ λ _ → ⟨ext⟩ λ _ →
≃⇒≡ U.univ $
EEq.≃ᴱ→≃ $
⟶≃ᴱ prop equiv
-- The graph of a function.
Graph : {A : Type a} {B : Type b} → (A → B) → A → B → Type b
Graph f x y = f x ≡ y
-- If R is a propositional equivalence relation targetting a certain
-- universe, then Graph (Q.[_] {R = R}) ⟵ is equal to R (in erased
-- contexts).
@0 Graph-[]-⟵≡ :
{A : Type a}
{R : A → A → Type a} →
(∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
Graph (Q.[_] {R = R}) ⟵ ≡ R
Graph-[]-⟵≡ {R = R} prop equiv =
⟨ext⟩ λ x → ⟨ext⟩ λ y →
let
lemma =
Eq.⇔→≃
T.truncation-is-proposition
Q./ᴱ-is-set
(T.rec λ @0 where
.T.truncation-is-propositionʳ → Q./ᴱ-is-set
.T.∣∣ʳ (_ , [x]≡z , [y]≡z) → trans [x]≡z (sym [y]≡z))
(λ [x]≡[y] → ∣ _ , [x]≡[y] , refl _ ∣)
in
≃⇒≡ U.univ
((Graph [_] ⟵) x y ↝⟨ lemma ⟩
[ x ] ≡ [ y ] ↔⟨ inverse $ Q.related≃[equal] equiv (prop _ _) ⟩□
R x y □)
-- If R is a propositional equivalence relation, then
-- R ;ᴱ Graph ([_] {R = R}) is equal to Graph ([_] {R = R}) (in erased
-- contexts).
@0 ;ᴱ-Graph-[]≡Graph-[] :
{A : Type a}
{R : A → A → Type r} →
(∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
R ;ᴱ Graph ([_] {R = R}) ≡ Graph ([_] {R = R})
;ᴱ-Graph-[]≡Graph-[] {R = R} prop equiv =
⟨ext⟩ λ x → ⟨ext⟩ λ y →
≃⇒≡ U.univ $
flip
(Q.elim-prop
{P = λ y → (R ;ᴱ Graph ([_] {R = R})) x y ≃
Graph ([_] {R = R}) x y})
y
λ @0 where
.Q.is-propositionʳ _ →
Eq.left-closure ext 0 $
T.truncation-is-proposition
.Q.[]ʳ y →
Eq.⇔→≃
T.truncation-is-proposition
Q./ᴱ-is-set
(T.rec λ @0 where
.T.Rec.truncation-is-propositionʳ →
Q./ᴱ-is-set
.T.Rec.∣∣ʳ (z , Rxz , [z]≡[y]) →
[ x ] ≡⟨ Q.[]-respects-relation Rxz ⟩
[ z ] ≡⟨ [z]≡[y] ⟩∎
[ y ] ∎)
([ x ] ≡ [ y ] ↔⟨ inverse $ Q.related≃[equal] equiv (prop _ _) ⟩
R x y ↝⟨ (λ Rxy → ∣ _ , Rxy , refl _ ∣) ⟩
(R ;ᴱ Graph [_]) x [ y ] □)
------------------------------------------------------------------------
-- Quasi-equivalence relations
-- Quasi-PERs, or zigzag-complete relations (following Krishnaswami
-- and Dreyer, see "Internalizing Relational Parametricity in the
-- Extensional Calculus of Constructions").
--
-- Angiuli et al. only define what it means to be a quasi-PER for
-- propositional relations. The following definition applies to
-- arbitrary relations.
Is-QPER :
{A : Type a} {B : Type b} →
(A → B → Type c) → Type (a ⊔ b ⊔ c)
Is-QPER R =
∀ {x x′ y y′} →
R x y → R x′ y → R x′ y′ → R x y′
-- Quasi-equivalence relations (QERs), defined using ∥_∥ᴱ instead of
-- ∥_∥.
Is-QER :
{A : Type a} {B : Type b} →
(A → B → Type c) → Type (a ⊔ b ⊔ c)
Is-QER R =
Is-QPER R ×
(∀ x → ∥ ∃ (λ y → R x y) ∥ᴱ) ×
(∀ y → ∥ ∃ (λ x → R x y) ∥ᴱ)
-- Quasi-equivalence relations (QERs), defined using ∥_∥ᴱ instead of
-- ∥_∥, and with some parts erased.
Is-QERᴱ :
{A : Type a} {B : Type b} →
@0 (A → B → Type c) → Type (a ⊔ b ⊔ c)
Is-QERᴱ R =
Erased (Is-QPER R) ×
(∀ x → ∥ ∃ (λ y → Erased (R x y)) ∥ᴱ) ×
(∀ y → ∥ ∃ (λ x → Erased (R x y)) ∥ᴱ)
-- Is-QERᴱ can be expressed using Is-QER and Erased.
Is-QERᴱ≃Is-QER-Erased :
{@0 R : A → B → Type r} →
Is-QERᴱ R ≃ Is-QER (λ x y → Erased (R x y))
Is-QERᴱ≃Is-QER-Erased {A = A} {B = B} {R = R} = ×-cong₁ λ _ →
Erased (∀ {x x′ y y′} → R x y → R x′ y → R x′ y′ → R x y′) ↝⟨ Erased-cong lemma ⟩
Erased (∀ x x′ y y′ → R x y → R x′ y → R x′ y′ → R x y′) ↔⟨ (∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
Erased-Π↔Π) F.∘
Erased-Π↔Π) F.∘
Erased-Π↔Π) F.∘
Erased-Π↔Π ⟩
(∀ x x′ y y′ → Erased (R x y → R x′ y → R x′ y′ → R x y′)) ↔⟨ (∀-cong ext λ _ →
∀-cong ext λ _ →
∀-cong ext λ _ →
∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
Erased-Π↔Π-Erased) F.∘
Erased-Π↔Π-Erased) F.∘
Erased-Π↔Π-Erased) ⟩
(∀ x x′ y y′ →
Erased (R x y) → Erased (R x′ y) →
Erased (R x′ y′) → Erased (R x y′)) ↝⟨ inverse lemma ⟩□
(∀ {x x′ y y′} →
Erased (R x y) → Erased (R x′ y) →
Erased (R x′ y′) → Erased (R x y′)) □
where
lemma :
{P : A → A → B → B → Type r} →
(∀ {x x′ y y′} → P x x′ y y′) ≃
(∀ x x′ y y′ → P x x′ y y′)
lemma = Eq.↔⇒≃ $
(∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
B.implicit-Π↔Π) F.∘
B.implicit-Π↔Π) F.∘
B.implicit-Π↔Π) F.∘
B.implicit-Π↔Π
-- Is-QER R implies Is-QERᴱ R.
Is-QER→Is-QERᴱ : Is-QER R → Is-QERᴱ R
Is-QER→Is-QERᴱ =
[_]→
×-cong
(∀-cong _ λ x →
T.∥∥ᴱ-map $ ∃-cong λ _ → [_]→)
×-cong
(∀-cong _ λ x →
T.∥∥ᴱ-map $ ∃-cong λ _ → [_]→)
-- In erased contexts Is-QER R is equivalent to Is-QERᴱ R.
@0 Is-QER≃Is-QERᴱ : Is-QER R ≃ Is-QERᴱ R
Is-QER≃Is-QERᴱ = Eq.↔⇒≃ $ inverse $
Erased↔ .erased
×-cong
(∀-cong ext λ x →
T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased)
×-cong
(∀-cong ext λ x →
T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased)
-- The forward direction of Is-QER≃Is-QERᴱ {R = R} is definitionally
-- equal to Is-QER→Is-QERᴱ.
_ : _≃_.to (Is-QER≃Is-QERᴱ {R = R}) ≡ Is-QER→Is-QERᴱ
_ = refl _
-- If Is-QER R holds, then R ⟵ is an equivalence relation.
Is-QER→Is-equivalence-relation-⟵ :
Is-QER R →
Is-equivalence-relation (R ⟵)
Is-QER→Is-equivalence-relation-⟵ (qper , lr , rl) = λ where
.Is-equivalence-relation.reflexive {x = x} →
T.∥∥ᴱ-map (λ (y , Rxy) → y , Rxy , Rxy) (lr x)
.Is-equivalence-relation.symmetric →
T.∥∥ᴱ-map (Σ-map id swap)
.Is-equivalence-relation.transitive →
T.rec λ where
.T.truncation-is-propositionʳ →
Π-closure ext 1 λ _ →
T.truncation-is-proposition
.T.∣∣ʳ (_ , Rx₁y₁ , Rx₂y₁) → T.∥∥ᴱ-map
λ (_ , Rx₂y₂ , Rx₃y₂) →
_ , qper Rx₁y₁ Rx₂y₁ Rx₂y₂ , Rx₃y₂
-- If Is-QERᴱ R holds, then R ⟵ is an equivalence relation (in erased
-- contexts).
@0 Is-QERᴱ→Is-equivalence-relation-⟵ :
Is-QERᴱ R →
Is-equivalence-relation (R ⟵)
Is-QERᴱ→Is-equivalence-relation-⟵ {R = R} =
Is-QERᴱ R ↔⟨ inverse Is-QER≃Is-QERᴱ ⟩
Is-QER R ↝⟨ Is-QER→Is-equivalence-relation-⟵ ⟩□
Is-equivalence-relation (R ⟵) □
-- If Is-QER R holds, then R ⟶ is an equivalence relation.
Is-QER→Is-equivalence-relation-⟶ :
Is-QER R →
Is-equivalence-relation (R ⟶)
Is-QER→Is-equivalence-relation-⟶ (qper , lr , rl) = λ where
.Is-equivalence-relation.reflexive {x = y} →
T.∥∥ᴱ-map (λ (x , Rxy) → x , Rxy , Rxy) (rl y)
.Is-equivalence-relation.symmetric →
T.∥∥ᴱ-map (Σ-map id swap)
.Is-equivalence-relation.transitive →
T.rec λ where
.T.truncation-is-propositionʳ →
Π-closure ext 1 λ _ →
T.truncation-is-proposition
.T.∣∣ʳ (_ , Rx₁y₁ , Rx₁y₂) → T.∥∥ᴱ-map
λ (_ , Rx₂y₂ , Rx₂y₃) →
_ , qper Rx₂y₂ Rx₁y₂ Rx₁y₁ , Rx₂y₃
-- If Is-QERᴱ R holds, then R ⟶ is an equivalence relation (in erased
-- contexts).
@0 Is-QERᴱ→Is-equivalence-relation-⟶ :
Is-QERᴱ R →
Is-equivalence-relation (R ⟶)
Is-QERᴱ→Is-equivalence-relation-⟶ {R = R} =
Is-QERᴱ R ↔⟨ inverse Is-QER≃Is-QERᴱ ⟩
Is-QER R ↝⟨ Is-QER→Is-equivalence-relation-⟶ ⟩□
Is-equivalence-relation (R ⟶) □
-- A propositional QER R can be turned into an equivalence (with
-- erased proofs) satisfying a certain (partly erased) condition.
--
-- This is a variant of Lemma 5.4 from "Internalizing Representation
-- Independence with Univalence".
/ᴱ⟵≃ᴱ/ᴱ⟶ :
Is-QER R →
@0 (∀ x y → Is-proposition (R x y)) →
∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) →
∀ x y →
∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → R x y) →
Erased (Is-equivalence f)
/ᴱ⟵≃ᴱ/ᴱ⟶ {A = A} {B = B} {R = R} qer@(qper , lr , rl) prop =
EEq.↔→≃ᴱ to from to-from from-to
, (λ _ _ →
to″
, [ _≃_.is-equivalence $
Eq.⇔→≃ Q./ᴱ-is-set (prop _ _) to″ from″
])
where
to′ : ∥ ∃ (R x) ∥ᴱ → B /ᴱ R ⟶
to′ =
_≃_.to (Q.Σ→Erased-Constant≃∥∥ᴱ→ Q./ᴱ-is-set)
( [_] ∘ proj₁
, [ (λ (_ , r₁) (_ , r₂) →
Q.[]-respects-relation ∣ _ , r₁ , r₂ ∣)
]
)
@0 to′-lemma :
R x y → R x′ y →
(p : ∥ ∃ (R x) ∥ᴱ)
(p′ : ∥ ∃ (R x′) ∥ᴱ) →
to′ p ≡ to′ p′
to′-lemma Rxy Rx′y = T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
Π-closure ext 1 λ _ →
Q./ᴱ-is-set
.T.∣∣ʳ (y₁ , Rxy₁) → T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (y₂ , Rx′y₂) →
[ y₁ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rxy₁ , qper Rxy Rx′y Rx′y₂ ∣ ⟩∎
[ y₂ ] ∎
to : A /ᴱ R ⟵ → B /ᴱ R ⟶
to = Q.rec λ where
.Q.is-setʳ → Q./ᴱ-is-set
.Q.[]ʳ → to′ ∘ lr
.Q.[]-respects-relationʳ {x = x} {y = x′} → T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (_ , Rxy , Rx′y) →
to′ (lr x) ≡⟨ to′-lemma Rxy Rx′y (lr x) (lr x′) ⟩∎
to′ (lr x′) ∎
from′ : ∥ ∃ ((R ⁻¹) y) ∥ᴱ → A /ᴱ R ⟵
from′ =
_≃_.to (Q.Σ→Erased-Constant≃∥∥ᴱ→ Q./ᴱ-is-set)
( [_] ∘ proj₁
, [ (λ (_ , r₁) (_ , r₂) →
Q.[]-respects-relation ∣ _ , r₁ , r₂ ∣)
]
)
@0 from′-lemma :
R x y → R x y′ →
(p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ)
(p′ : ∥ ∃ ((R ⁻¹) y′) ∥ᴱ) →
from′ p ≡ from′ p′
from′-lemma Rxy Rxy′ = T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
Π-closure ext 1 λ _ →
Q./ᴱ-is-set
.T.∣∣ʳ (x₁ , Rx₁y) → T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (x₂ , Rx₂y′) →
[ x₁ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rx₁y , qper Rx₂y′ Rxy′ Rxy ∣ ⟩∎
[ x₂ ] ∎
from : B /ᴱ R ⟶ → A /ᴱ R ⟵
from = Q.rec λ where
.Q.is-setʳ → Q./ᴱ-is-set
.Q.[]ʳ → from′ ∘ rl
.Q.[]-respects-relationʳ {x = y} {y = y′} → T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (_ , Rxy , Rxy′) →
from′ (rl y) ≡⟨ from′-lemma Rxy Rxy′ (rl y) (rl y′) ⟩∎
from′ (rl y′) ∎
@0 to′≡[] :
R x y → (p : ∥ ∃ (R x) ∥ᴱ) →
to′ p ≡ [ y ]
to′≡[] {x = x} {y = y} Rxy = T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (y′ , Rxy′) →
[ y′ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rxy′ , Rxy ∣ ⟩∎
[ y ] ∎
@0 to-from′ :
∀ y (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) →
to (from′ p) ≡ [ y ]
to-from′ y = T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (x , Rxy) →
to′ (lr x) ≡⟨ to′≡[] Rxy (lr x) ⟩∎
[ y ] ∎
@0 to-from : ∀ y → to (from y) ≡ y
to-from = Q.elim-prop λ @0 where
.Q.is-propositionʳ _ → Q./ᴱ-is-set
.Q.[]ʳ y →
to (from′ (rl y)) ≡⟨ to-from′ y (rl y) ⟩∎
[ y ] ∎
@0 from′≡[] :
R x y → (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) →
from′ p ≡ [ x ]
from′≡[] {x = x} {y = y} Rxy = T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (x′ , Rx′y) →
[ x′ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rx′y , Rxy ∣ ⟩∎
[ x ] ∎
@0 from-to′ :
∀ x (p : ∥ ∃ (R x) ∥ᴱ) →
from (to′ p) ≡ [ x ]
from-to′ x = T.elim λ @0 where
.T.truncation-is-propositionʳ _ → Q./ᴱ-is-set
.T.∣∣ʳ (y , Rxy) →
from′ (rl y) ≡⟨ from′≡[] Rxy (rl y) ⟩∎
[ x ] ∎
@0 from-to : ∀ x → from (to x) ≡ x
from-to = Q.elim-prop λ @0 where
.Q.is-propositionʳ _ → Q./ᴱ-is-set
.Q.[]ʳ x →
from (to′ (lr x)) ≡⟨ from-to′ x (lr x) ⟩∎
[ x ] ∎
to″ : to [ x ] ≡ [ y ] → R x y
to″ {x = x} {y = y} =
to′ (lr x) ≡ [ y ] ↝⟨ flip (T.elim {P = λ p → to′ p ≡ [ y ] → R x y}) (lr x) (λ where
.T.truncation-is-propositionʳ _ →
Π-closure ext 1 λ _ →
prop _ _
.T.∣∣ʳ (y′ , Rxy′) →
[ y′ ] ≡ [ y ] ↝⟨ Q.effective
(Is-QER→Is-equivalence-relation-⟶ qer)
T.truncation-is-proposition
∣ _ , Rxy′ , Rxy′ ∣ ⟩
(R ⟶) y′ y ↝⟨ T.rec (λ where
.T.truncation-is-propositionʳ → prop _ _
.T.∣∣ʳ (_ , Rx′y′ , Rx′y) →
qper Rxy′ Rx′y′ Rx′y) ⟩□
R x y □) ⟩□
R x y □
@0 from″ : R x y → to [ x ] ≡ [ y ]
from″ {x = x} {y = y} Rxy =
to′ (lr x) ≡⟨ to′≡[] Rxy (lr x) ⟩∎
[ y ] ∎
-- A propositional QER R (with erased proofs) can be turned into an
-- equivalence (with erased proofs) satisfying a certain (erased)
-- condition.
--
-- This is another variant of Lemma 5.4 from "Internalizing
-- Representation Independence with Univalence".
/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ :
{@0 R : A → B → Type c} →
Is-QERᴱ R →
@0 (∀ x y → Is-proposition (R x y)) →
∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) →
Erased (∀ x y → (_≃ᴱ_.to eq [ x ] ≡ [ y ]) ≃ R x y)
/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ {A = A} {B = B} {R = R} qer prop = $⟨ [ prop ] ⟩
Erased (∀ x y → Is-proposition (R x y)) ↝⟨ (λ ([ hyp ]) x y → H-level-Erased 1 (hyp x y)) ⦂ (_ → _) ⟩
(∀ x y → Is-proposition (Rᴱ x y)) ↝⟨ (λ prop → /ᴱ⟵≃ᴱ/ᴱ⟶ (_≃_.to Is-QERᴱ≃Is-QER-Erased qer) prop) ⟩
(∃ λ (eq : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶) →
∀ x y →
∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → Rᴱ x y) →
Erased (Is-equivalence f)) ↝⟨ (λ (eq , ok) → drop-ᴱ eq , [ drop-ᴱ-ok eq ok ]) ⟩□
(∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) →
Erased (∀ x y → (_≃ᴱ_.to eq [ x ] ≡ [ y ]) ≃ R x y)) □
where
Rᴱ = λ x y → Erased (R x y)
@0 lemma :
∀ x y →
((λ x y → Erased (R₁ x y)) ;ᴱ (λ x y → Erased (R₂ x y))) x y ⇔
(R₁ ;ᴱ R₂) x y
lemma {R₁ = R₁} {R₂ = R₂} x z =
∥ (∃ λ y → Erased (R₁ x y) × Erased (R₂ y z)) ∥ᴱ ↔⟨ (T.∥∥ᴱ-cong $ ∃-cong λ _ →
Erased↔ .erased
×-cong
Erased↔ .erased) ⟩□
∥ (∃ λ y → R₁ x y × R₂ y z) ∥ᴱ □
drop-ᴱ :
A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶ →
A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶
drop-ᴱ eq =
A /ᴱ R ⟵ ↔⟨ Eq.id Q./ᴱ-cong (λ x y → inverse (lemma {R₁ = R} {R₂ = R ⁻¹} x y)) ⟩
A /ᴱ Rᴱ ⟵ ↝⟨ eq ⟩
B /ᴱ Rᴱ ⟶ ↔⟨ Eq.id Q./ᴱ-cong lemma ⟩□
B /ᴱ R ⟶ □
@0 drop-ᴱ-ok :
(eq : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶) →
(∀ x y →
∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → Rᴱ x y) →
Erased (Is-equivalence f)) →
∀ x y → (_≃ᴱ_.to (drop-ᴱ eq) [ x ] ≡ [ y ]) ≃ R x y
drop-ᴱ-ok eq ok x y =
_≃ᴱ_.to (drop-ᴱ eq) [ x ] ≡ [ y ] ↔⟨⟩
_≃_.to (Eq.id Q./ᴱ-cong lemma) (_≃ᴱ_.to eq [ x ]) ≡ [ y ] ↝⟨ Eq.≃-≡ (Eq.id Q./ᴱ-cong lemma) ⟩
_≃ᴱ_.to eq [ x ] ≡ [ y ] ↝⟨ (let f , [ eq ] = ok x y in Eq.⟨ f , eq ⟩) ⟩
Rᴱ x y ↔⟨ Erased↔ .erased ⟩□
R x y □
------------------------------------------------------------------------
-- Relation transformers
-- Relation transformers for a given structure.
Relation-transformer-for :
Structure a b → Type (lsuc (a ⊔ b))
Relation-transformer-for {a = a} {b = b} F =
∀ {A B} → (A → B → Type a) → F A → F B → Type b
-- A notion of "suitable" relation transformers.
record Suitable
{F : Structure a b}
(@0 G : Relation-transformer-for F) :
Type (lsuc a ⊔ b) where
field
-- F preserves Is-set.
@0 preserves-is-set :
Is-set A → Is-set (F A)
-- G preserves a variant of Is-proposition.
@0 preserves-is-proposition :
(∀ x y → Is-proposition (R x y)) →
∀ x y → Is-proposition (G R x y)
-- G is "symmetric" for propositional relations.
@0 symmetric :
(∀ x y → Is-proposition (R x y)) →
G R x y → G (R ⁻¹) y x
-- G is "transitive" for propositional relations.
@0 transitive :
(∀ x y → Is-proposition (R x y)) →
(∀ x y → Is-proposition (S x y)) →
G R x y → G S y z → G (R ;ᴱ S) x z
-- Descent to quotients. Note that this is the only non-erased
-- field of this record type.
descent :
{@0 R : A → A → Type a} →
@0 (∀ x y → Is-proposition (R x y)) →
@0 Is-equivalence-relation R →
@0 G R x x →
Contractibleᴱ (∃ λ (y : F (A /ᴱ R)) → Erased (G (Graph [_]) x y))
-- A variant of transitive.
@0 transitive-;ᴱ :
(∀ x y → Is-proposition (R x y)) →
(∀ x y → Is-proposition (S x y)) →
∀ x z → (G R ;ᴱ G S) x z → G (R ;ᴱ S) x z
transitive-;ᴱ R-prop S-prop _ _ = T.rec λ @0 where
.T.truncation-is-propositionʳ →
preserves-is-proposition
(λ _ _ → T.truncation-is-proposition) _ _
.T.∣∣ʳ (_ , GRxy , GSyz) →
transitive R-prop S-prop GRxy GSyz
-- A variant of Univalent for relation transformers.
Univalentᴿ :
{F : Structure a b} →
@0 Relation-transformer-for F → Type (lsuc a ⊔ b)
Univalentᴿ {F = F} G =
Suitable G ×
Univalent F (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y)
-- A notion of "acting on functions" for relation transformers.
record Acts-on-functions
{F : Structure a b}
(@0 G : Relation-transformer-for F) :
Type (lsuc a ⊔ b) where
field
-- A map function.
map : (A → B) → F A → F B
-- Mapping the identity function is the same thing as applying the
-- identity function.
@0 map-id : map {A = A} id ≡ id
-- G respects map in a certain way.
@0 map-map :
{R₁ : A₁ → B₁ → Type a} {R₂ : A₂ → B₂ → Type a} →
(∀ {x y} → R₁ x y → R₂ (f x) (g y)) →
G R₁ x y → G R₂ (map f x) (map g y)
-- Suitable respects equivalences.
Suitable-map :
{@0 G H : Relation-transformer-for F} →
@0 (∀ {A B} {R : A → B → _} {x y} → G R x y ≃ H R x y) →
Suitable G → Suitable H
Suitable-map {G = G} {H = H} G≃H s-G = λ where
.Suitable.preserves-is-set → S.preserves-is-set
.Suitable.preserves-is-proposition {R = R} →
(∀ x y → Is-proposition (R x y)) ↝⟨ S.preserves-is-proposition ⟩
(∀ x y → Is-proposition (G R x y)) ↝⟨ (∀-cong _ λ _ → ∀-cong _ λ _ → H-level-cong _ 1 G≃H) ⟩□
(∀ x y → Is-proposition (H R x y)) □
.Suitable.symmetric {R = R} {x = x} {y = y} →
(∀ x y → Is-proposition (R x y)) ↝⟨ S.symmetric ⟩
(G R x y → G (R ⁻¹) y x) ↝⟨ →-cong-→ (_≃_.from G≃H) (_≃_.to G≃H) ⟩□
(H R x y → H (R ⁻¹) y x) □
.Suitable.transitive {R = R} {S = S} {x = x} {y = y} {z = z} → curry
((∀ x y → Is-proposition (R x y)) ×
(∀ x y → Is-proposition (S x y)) ↝⟨ uncurry S.transitive ⟩
(G R x y → G S y z → G (R ;ᴱ S) x z) ↝⟨ →-cong-→ (_≃_.from G≃H) (→-cong-→ (_≃_.from G≃H) (_≃_.to G≃H)) ⟩□
(H R x y → H S y z → H (R ;ᴱ S) x z) □)
.Suitable.descent {x = x} {R = R} prop equiv HRxx → $⟨ [ HRxx ] ⟩
Erased (H R x x) ↔⟨ Erased-cong (inverse G≃H) ⟩
Erased (G R x x) ↝⟨ (λ ([ hyp ]) → S.descent prop equiv hyp) ⦂ (_ → _) ⟩
Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y)) ↝⟨ ECP.Contractibleᴱ-cong _ (∃-cong λ _ → Erased-cong G≃H) ⟩□
Contractibleᴱ (∃ λ y → Erased (H (Graph [_]) x y)) □
where
module S = Suitable s-G
-- If R is a propositional QER (with erased proofs) between A and B, G
-- is a suitable relation transformer for F, and G R x y holds, then
-- there are structures in F (A /ᴱ R ⟵) and F (B /ᴱ R ⟶) that are
-- related in a certain way to x and y, respectively, and the two
-- structures are also related to each other by /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ in a certain
-- way.
--
-- This is a variant of Theorem 5.7 from "Internalizing Representation
-- Independence with Univalence". Note that quite a few inputs are
-- erased, and also parts of the result.
Suitable→/ᴱ⟵×/ᴱ⟶ :
{F : Structure a b}
((A , x) (B , y) : Type-with F) →
{@0 R : A → B → Type a}
{@0 G : Relation-transformer-for F} →
Suitable G →
(qer : Is-QERᴱ R)
(@0 prop : ∀ x y → Is-proposition (R x y)) →
@0 G R x y →
∃ λ (x′ : F (A /ᴱ R ⟵)) → ∃ λ (y′ : F (B /ᴱ R ⟶)) →
Erased
(G (Graph [_]) x x′ × G (Graph [_]) y y′ ×
G (Graph (_≃ᴱ_.to (/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁))) x′ y′)
Suitable→/ᴱ⟵×/ᴱ⟶ {F = F} (A , x) (B , y) {R = R} {G = G}
s qer@([ qper ] , _) prop g =
x″ , y″ , [ (Gxx″ , Gyy″ , g″) ]
where
module S = Suitable s
@0 x∼x : G (R ⟵) x x
x∼x = S.transitive prop (flip prop) g (S.symmetric prop g)
@0 y∼y : G (R ⟶) y y
y∼y = S.transitive (flip prop) prop (S.symmetric prop g) g
x-lemma :
Contractibleᴱ
(∃ λ (x′ : F (A /ᴱ R ⟵)) → Erased (G (Graph [_]) x x′))
x-lemma =
S.descent
(λ _ _ → T.truncation-is-proposition)
(Is-QERᴱ→Is-equivalence-relation-⟵ qer)
x∼x
y-lemma :
Contractibleᴱ
(∃ λ (y′ : F (B /ᴱ R ⟶)) → Erased (G (Graph [_]) y y′))
y-lemma =
S.descent
(λ _ _ → T.truncation-is-proposition)
(Is-QERᴱ→Is-equivalence-relation-⟶ qer)
y∼y
x″ = x-lemma .proj₁ .proj₁
y″ = y-lemma .proj₁ .proj₁
@0 Gxx″ : G (Graph [_]) x x″
Gxx″ = x-lemma .proj₁ .proj₂ .erased
@0 Gyy″ : G (Graph [_]) y y″
Gyy″ = y-lemma .proj₁ .proj₂ .erased
@0 g′ : G (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) x″ y″
g′ =
S.transitive
(λ _ _ → Q./ᴱ-is-set)
(λ _ _ → T.truncation-is-proposition)
(S.symmetric (λ _ _ → Q./ᴱ-is-set) Gxx″)
(S.transitive prop (λ _ _ → Q./ᴱ-is-set) g Gyy″)
equiv = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁
@0 to :
∀ {x y} →
(Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] → R x y
to {x = x} {y = y} =
T.rec λ @0 where
.T.truncation-is-propositionʳ →
prop _ _
.T.∣∣ʳ → uncurry λ x′ → uncurry λ [x′]≡[x] →
T.rec λ @0 where
.T.truncation-is-propositionʳ →
prop _ _
.T.∣∣ʳ (y′ , Rx′y′ , [y′]≡[y]) →
let R⟵x′x : (R ⟵) x′ x
R⟵x′x =
_≃_.from
(Q.related≃[equal]
(Is-QERᴱ→Is-equivalence-relation-⟵ qer)
T.truncation-is-proposition)
[x′]≡[x]
R⟶y′y : (R ⟶) y′ y
R⟶y′y =
_≃_.from
(Q.related≃[equal]
(Is-QERᴱ→Is-equivalence-relation-⟶ qer)
T.truncation-is-proposition)
[y′]≡[y]
in
flip T.rec R⟵x′x λ @0 where
.T.truncation-is-propositionʳ →
prop _ _
.T.∣∣ʳ (_ , Rx′x″ , Rxx″) →
flip T.rec R⟶y′y λ @0 where
.T.truncation-is-propositionʳ →
prop _ _
.T.∣∣ʳ (_ , Ry″y′ , Ry″y) →
qper Rxx″ Rx′x″ (qper Rx′y′ Ry″y′ Ry″y)
@0 from :
∀ {x y} →
R x y → (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ]
from Rxy = ∣ _ , refl _ , ∣ _ , Rxy , refl _ ∣ ∣
@0 lemma :
∀ x y →
(Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) x y ≃
Graph (_≃ᴱ_.to equiv) x y
lemma = Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Eq.left-closure ext 0 T.truncation-is-proposition
.Q.[]ʳ x → Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
Eq.left-closure ext 0 T.truncation-is-proposition
.Q.[]ʳ y →
(Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] ↝⟨ Eq.⇔→≃ T.truncation-is-proposition (prop _ _) to from ⟩
R x y ↝⟨ inverse (/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₂ .erased _ _) ⟩□
Graph (_≃ᴱ_.to equiv) [ x ] [ y ] □
@0 g″ : G (Graph (_≃ᴱ_.to equiv)) x″ y″
g″ =
subst (λ R → G R x″ y″)
(⟨ext⟩ λ x → ⟨ext⟩ λ y →
≃⇒≡ U.univ (lemma x y))
g′
-- If R is a propositional QER (with erased proofs) between A and B, G
-- is a univalent relation transformer for F, and G R x y holds, then
-- there are structures x′ : F (A /ᴱ R ⟵) and y′ : F (B /ᴱ R ⟶) that
-- are related in a certain way to x and y, respectively, and
-- furthermore the two values A /ᴱ R ⟵ , x′ and B /ᴱ R ⟶ , y′ of type
-- Type-with F are equal (in erased contexts).
--
-- This is a corollary of Suitable→/ᴱ⟵×/ᴱ⟶, /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ and sip.
Univalentᴿ→/ᴱ⟵×/ᴱ⟶ :
{F : Structure a b}
((A , x) (B , y) : Type-with F) →
{@0 R : A → B → Type a}
{@0 G : Relation-transformer-for F} →
Univalentᴿ G →
(qer : Is-QERᴱ R)
(@0 prop : ∀ x y → Is-proposition (R x y)) →
@0 G R x y →
∃ λ (x′ : F (A /ᴱ R ⟵)) → ∃ λ (y′ : F (B /ᴱ R ⟶)) →
Erased (G (Graph [_]) x x′ × G (Graph [_]) y y′ ×
_≡_ {A = Type-with F}
(A /ᴱ R ⟵ , x′) (B /ᴱ R ⟶ , y′))
Univalentᴿ→/ᴱ⟵×/ᴱ⟶ (A , x) (B , y) {R = R} {G = G} (s , u) qer prop g =
let (x′ , y′ , [ x∼x′ , y∼y′ , x′∼y′ ]) =
Suitable→/ᴱ⟵×/ᴱ⟶ (A , x) (B , y) s qer prop g
in
x′
, y′
, [ ( x∼x′
, y∼y′
, ( $⟨ /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁ , [ x′∼y′ ] ⟩
(A /ᴱ R ⟵ , x′)
≃[ (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y) ]ᴱ
(B /ᴱ R ⟶ , y′) ↝⟨ sip u ⟩□
(A /ᴱ R ⟵ , x′) ≡ (B /ᴱ R ⟶ , y′) □)
)
]
-- If G is a suitable relation transformer (for F) that acts on
-- functions, and R is a propositional equivalence relation on A, then
-- there is a function from F A /ᴱ G R to F (A /ᴱ R).
--
-- This is a variant of Lemma 5.10 from "Internalizing Representation
-- Independence with Univalence". Note that quite a few inputs are
-- erased.
/ᴱ→/ᴱ :
{A : Type a}
{@0 R : A → A → Type a}
(@0 G : Relation-transformer-for F) →
Suitable G →
Acts-on-functions G →
@0 (∀ x y → Is-proposition (R x y)) →
@0 Is-equivalence-relation R →
F A /ᴱ G R → F (A /ᴱ R)
/ᴱ→/ᴱ {F = F} {R = R} G s acts prop equiv =
Q.rec λ where
.Q.[]ʳ → map [_]
.Q.is-setʳ → S.preserves-is-set Q./ᴱ-is-set
.Q.[]-respects-relationʳ {x = x} {y = y} GRxy →
let GRxx = $⟨ GRxy ⟩
G R x y ↝⟨ (λ GRxy → S.transitive prop (flip prop) GRxy (S.symmetric prop GRxy)) ⟩
G (R ⟵) x x ↝⟨ subst (λ R → G R _ _) (⟵≡ prop equiv) ⟩□
G R x x □
((z , _) , [ unique ]) = $⟨ GRxx ⟩
G R x x ↝⟨ (λ GRxx → S.descent prop equiv GRxx) ⦂ (_ → _) ⟩□
Contractibleᴱ (∃ λ z → Erased (G (Graph [_]) x z)) □
lemma₁ = $⟨ map-map Q.[]-respects-relation GRxx ⟩
G (Graph [_]) (map id x) (map [_] x) ↝⟨ subst (λ x′ → G (Graph [_]) x′ (map [_] x)) (cong (_$ x) map-id) ⟩□
G (Graph [_]) x (map [_] x) □
lemma₂ = $⟨ map-map Q.[]-respects-relation GRxy ⟩
G (Graph [_]) (map id x) (map [_] y) ↝⟨ subst (λ x → G (Graph [_]) x (map [_] y)) (cong (_$ x) map-id) ⟩□
G (Graph [_]) x (map [_] y) □
in
map [_] x ≡⟨ sym $ cong proj₁ (unique (_ , [ lemma₁ ])) ⟩
z ≡⟨ cong proj₁ (unique (_ , [ lemma₂ ])) ⟩∎
map [_] y ∎
where
module S = Suitable s
open Acts-on-functions acts
-- Positive relation transformers.
--
-- Angiuli et al. define this notion for suitable relation
-- transformers that act on functions. This definition works for
-- arbitrary relation transformers G, and instead inludes fields of
-- type Suitable G and Acts-on-functions G. (In their source code
-- Angiuli et al. take a third approach, with the property
-- corresponding to Suitable G as a parameter, and the property
-- corresponding to Acts-on-functions G as a field.)
record Positive
{F : Structure a b}
(@0 G : Relation-transformer-for F) :
Type (lsuc a ⊔ b) where
field
-- G is suitable.
suitable : Suitable G
-- G acts on functions.
acts-on-functions : Acts-on-functions G
-- G is reflexive for a certain relation.
@0 reflexive-∥≡∥ᴱ : G (λ x y → ∥ x ≡ y ∥ᴱ) x x
-- The function Suitable.transitive-;ᴱ suitable is an equivalence
-- (pointwise).
@0 transitive-;ᴱ⁻¹ :
{R : A → B → Type a} {S : B → C → Type a}
(R-prop : ∀ x y → Is-proposition (R x y))
(S-prop : ∀ x y → Is-proposition (S x y))
(x : F A) (z : F C) →
Is-equivalence
(Suitable.transitive-;ᴱ suitable R-prop S-prop x z)
-- The function /ᴱ→/ᴱ G suitable acts-on-functions is an
-- equivalence with erased proofs (pointwise).
commutes-with-/ᴱ :
{@0 R : A → A → Type a}
(@0 prop : ∀ x y → Is-proposition (R x y))
(@0 equiv : Is-equivalence-relation R) →
Is-equivalenceᴱ (/ᴱ→/ᴱ G suitable acts-on-functions prop equiv)
-- G R is reflexive for propositional equivalence relations R (in
-- erased contexts).
@0 reflexive :
(∀ x y → Is-proposition (R x y)) →
Is-equivalence-relation R →
∀ x → G R x x
reflexive {R = R} prop equiv x = $⟨ reflexive-∥≡∥ᴱ ⟩
G (λ x y → ∥ x ≡ y ∥ᴱ) x x ↝⟨ A.map-map
(T.rec λ @0 where
.T.truncation-is-propositionʳ →
prop _ _
.T.∣∣ʳ x≡y →
subst (R _) x≡y E.reflexive) ⟩
G R (A.map id x) (A.map id x) ↝⟨ subst (uncurry (G R)) (cong (λ f → f x , f x) A.map-id) ⟩□
G R x x □
where
module A = Acts-on-functions acts-on-functions
module E = Is-equivalence-relation equiv
------------------------------------------------------------------------
-- The Const and Constᴿ combinators, along with some properties
-- Constant structures.
Const : Type b → Structure a b
Const B = λ _ → B
-- Relation transformers for Const.
Constᴿ : (B : Type b) → Relation-transformer-for (Const {a = a} B)
Constᴿ _ _ = _≡_
-- When is an equivalence structure-preserving for Const?
Is-Const-equivalence :
{B : Type b} →
Structure-preserving-equivalence-predicate (Const {a = a} B) b
Is-Const-equivalence (_ , x) (_ , y) _ = x ≡ y
-- Const and Is-Const-equivalence are univalent.
Const-univalent : Univalent (Const {a = a} B) Is-Const-equivalence
Const-univalent {B = B}
.Univalent.univalent {A = _ , x} {B = _ , y} eq =
x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ subst-const _ ⟩□
subst (Const B) (≃⇒≡ U.abstract-univ (EEq.≃ᴱ→≃ eq)) x ≡ y □
-- Constᴿ is suitable for sets.
Constᴿ-suitable : @0 Is-set B → Suitable (Constᴿ {a = a} B)
Constᴿ-suitable set = λ where
.Suitable.preserves-is-set _ → set
.Suitable.preserves-is-proposition _ _ _ → set
.Suitable.symmetric _ → sym
.Suitable.transitive _ _ → trans
.Suitable.descent _ _ _ → Contractibleᴱ-Erased-other-singleton
-- Constᴿ is univalent for sets.
Constᴿ-univalent : @0 Is-set B → Univalentᴿ (Constᴿ {a = a} B)
Constᴿ-univalent set = Constᴿ-suitable set , Const-univalent
-- Constᴿ acts on functions.
Constᴿ-acts-on-functions : Acts-on-functions (Constᴿ {a = a} B)
Constᴿ-acts-on-functions = λ where
.Acts-on-functions.map _ → id
.Acts-on-functions.map-id → refl _
.Acts-on-functions.map-map _ → id
-- Constᴿ is positive for sets.
Constᴿ-positive : @0 Is-set B → Positive (Constᴿ {a = a} B)
Constᴿ-positive {B = B} set = λ where
.Positive.suitable → Constᴿ-suitable set
.Positive.acts-on-functions → Constᴿ-acts-on-functions
.Positive.reflexive-∥≡∥ᴱ → refl _
.Positive.transitive-;ᴱ⁻¹ {R = R} {S = S} _ _ x z →
_≃_.is-equivalence
((Constᴿ B R ;ᴱ Constᴿ B S) x z ↔⟨⟩
∥ (∃ λ y → x ≡ y × y ≡ z) ∥ᴱ ↝⟨ Eq.⇔→≃ T.truncation-is-proposition set _
(λ x≡z → ∣ _ , x≡z , refl _ ∣) ⟩
x ≡ z ↔⟨⟩
Constᴿ B (R ;ᴱ S) x z □)
.Positive.commutes-with-/ᴱ {A = C} {R = R} prop equiv →
_≃ᴱ_.is-equivalence $
EEq.with-other-function
(Const B C /ᴱ Constᴿ B R ↔⟨⟩
B /ᴱ _≡_ ↔⟨ Q./ᴱ≡↔ set ⟩
B ↔⟨⟩
Const B (C /ᴱ R) □)
(/ᴱ→/ᴱ (Constᴿ B) (Constᴿ-suitable set) Constᴿ-acts-on-functions
prop equiv)
(Q.elim-prop λ @0 where
.Q.is-propositionʳ _ → set
.Q.[]ʳ _ → refl _)
------------------------------------------------------------------------
-- The Id and Idᴿ combinators, along with some properties
-- Identity structures.
Id : Structure a a
Id A = A
-- Relation transformers for Id.
Idᴿ : Relation-transformer-for (Id {a = a})
Idᴿ R = R
-- When is an equivalence structure-preserving for Id?
Is-Id-equivalence : Structure-preserving-equivalence-predicate Id a
Is-Id-equivalence (_ , x) (_ , y) eq = _≃ᴱ_.to eq x ≡ y
-- Id and Is-Id-equivalence are univalent.
Id-univalent : Univalent (Id {a = a}) Is-Id-equivalence
Id-univalent .Univalent.univalent {A = _ , x} {B = _ , y} eq =
_≃ᴱ_.to eq x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ cong (λ eq → _≃_.to eq x) $ sym $
_≃_.right-inverse-of (≡≃≃ univ) _ ⟩
≡⇒→ (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $
subst-id-in-terms-of-≡⇒↝ equivalence ⟩□
subst Id (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y □
where
univ = U.abstract-univ
-- Idᴿ is suitable.
Idᴿ-suitable : Suitable (Idᴿ {a = a})
Idᴿ-suitable = λ where
.Suitable.preserves-is-set → id
.Suitable.preserves-is-proposition → id
.Suitable.symmetric _ → id
.Suitable.transitive _ _ Rxy Syz → ∣ _ , Rxy , Syz ∣
.Suitable.descent _ _ _ →
Contractibleᴱ-Erased-other-singleton
-- Idᴿ is univalent.
Idᴿ-univalent : Univalentᴿ (Idᴿ {a = a})
Idᴿ-univalent = Idᴿ-suitable , Id-univalent
-- Idᴿ acts on functions.
Idᴿ-acts-on-functions : Acts-on-functions (Idᴿ {a = a})
Idᴿ-acts-on-functions = λ where
.Acts-on-functions.map → id
.Acts-on-functions.map-id → refl _
.Acts-on-functions.map-map f → f
-- Idᴿ is positive.
Idᴿ-positive : Positive (Idᴿ {a = a})
Idᴿ-positive = λ where
.Positive.suitable → Idᴿ-suitable
.Positive.acts-on-functions → Idᴿ-acts-on-functions
.Positive.reflexive-∥≡∥ᴱ → ∣ refl _ ∣
.Positive.transitive-;ᴱ⁻¹ {R = R} {S = S} R-prop S-prop x z →
_≃_.is-equivalence $
Eq.with-other-function
((Idᴿ R ;ᴱ Idᴿ S) x z ↔⟨⟩
(R ;ᴱ S) x z ↔⟨⟩
Idᴿ (R ;ᴱ S) x z □)
(Suitable.transitive-;ᴱ Idᴿ-suitable R-prop S-prop x z)
(T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
H-level.⇒≡ 1 T.truncation-is-proposition
.T.∣∣ʳ _ →
refl _)
.Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv →
_≃ᴱ_.is-equivalence $
EEq.with-other-function
(Id A /ᴱ Idᴿ R ↔⟨⟩
A /ᴱ R ↔⟨⟩
Id (A /ᴱ R) □)
(/ᴱ→/ᴱ Idᴿ Idᴿ-suitable Idᴿ-acts-on-functions prop equiv)
(Q.elim-prop λ @0 where
.Q.is-propositionʳ _ → Q./ᴱ-is-set
.Q.[]ʳ _ → refl _)
------------------------------------------------------------------------
-- Combinators related to Cartesian products
-- Product structures.
Product : Structure a b → Structure a c → Structure a (b ⊔ c)
Product F G A = F A × G A
-- A combinator that, given relation transformers for F and G,
-- produces a relation transformer for Product F G.
Productᴿ :
Relation-transformer-for F →
Relation-transformer-for G →
Relation-transformer-for (Product F G)
Productᴿ S T R = S R ×ᴾ T R
-- When is an equivalence structure-preserving for Product F G?
Is-Product-equivalence :
Structure-preserving-equivalence-predicate F a →
Structure-preserving-equivalence-predicate G b →
Structure-preserving-equivalence-predicate (Product F G) (a ⊔ b)
Is-Product-equivalence Is-F-eq Is-G-eq (A , x₁ , x₂) (B , y₁ , y₂) eq =
Is-F-eq (A , x₁) (B , y₁) eq ×
Is-G-eq (A , x₂) (B , y₂) eq
-- If F and G are univalent, then Product F G is univalent.
Product-univalent :
{@0 F : Structure a b}
{@0 G : Structure a c}
{@0 Is-F-eq : Structure-preserving-equivalence-predicate F d}
{@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} →
@0 Univalent F Is-F-eq →
@0 Univalent G Is-G-eq →
Univalent (Product F G) (Is-Product-equivalence Is-F-eq Is-G-eq)
Product-univalent
{F = F} {G = G} {Is-F-eq = Is-F-eq} {Is-G-eq = Is-G-eq}
u-F u-G .Univalent.univalent {A = A , x₁ , x₂} {B = B , y₁ , y₂} eq =
Is-F-eq (A , x₁) (B , y₁) eq × Is-G-eq (A , x₂) (B , y₂) eq ↝⟨ u-F .Univalent.univalent eq
×-cong
u-G .Univalent.univalent eq ⟩
subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ ≡ y₁ ×
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₂ ≡ y₂ ↔⟨ ≡×≡↔≡ ⟩
( subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁
, subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₂
) ≡ (y₁ , y₂) ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $
push-subst-, _ _ ⟩□
subst (Product F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (x₁ , x₂) ≡ (y₁ , y₂) □
where
univ = U.abstract-univ
-- If S and T are suitable, then Productᴿ S T is suitable.
Productᴿ-suitable :
{@0 S : Relation-transformer-for F}
{@0 T : Relation-transformer-for G} →
Suitable S →
Suitable T →
Suitable (Productᴿ S T)
Productᴿ-suitable {S = S} {T = T} s-S s-T = λ where
.Suitable.preserves-is-set set →
×-closure 2
(s-S .Suitable.preserves-is-set set)
(s-T .Suitable.preserves-is-set set)
.Suitable.preserves-is-proposition prop _ _ →
×-closure 1
(s-S .Suitable.preserves-is-proposition prop _ _)
(s-T .Suitable.preserves-is-proposition prop _ _)
.Suitable.symmetric prop →
Σ-map
(s-S .Suitable.symmetric prop)
(s-T .Suitable.symmetric prop)
.Suitable.transitive prop₁ prop₂ →
Σ-zip
(s-S .Suitable.transitive prop₁ prop₂)
(s-T .Suitable.transitive prop₁ prop₂)
.Suitable.descent {x = x , y} {R = R} prop equiv (SRxx , Tryy) → $⟨ [ SRxx ] , [ Tryy ] ⟩
Erased (S R x x) × Erased (T R y y) ↝⟨ Σ-map (λ ([ SRxx ]) → s-S .Suitable.descent prop equiv SRxx)
(λ ([ TRyy ]) → s-T .Suitable.descent prop equiv TRyy) ⟩
Contractibleᴱ (∃ λ x′ → Erased (S (Graph [_]) x x′)) ×
Contractibleᴱ (∃ λ y′ → Erased (T (Graph [_]) y y′)) ↝⟨ uncurry ECP.Contractibleᴱ-× ⟩
Contractibleᴱ
((∃ λ x′ → Erased (S (Graph [_]) x x′)) ×
(∃ λ y′ → Erased (T (Graph [_]) y y′))) ↝⟨ ECP.Contractibleᴱ-cong _ $
Σ-assoc F.∘
(∃-cong λ _ → ∃-cong λ _ → inverse Erased-Σ↔Σ) F.∘
(∃-cong λ _ → ∃-comm) F.∘
inverse Σ-assoc ⟩□
Contractibleᴱ (∃ λ p → Erased (Productᴿ S T (Graph [_]) (x , y) p)) □
-- If S and T are univalent, then Productᴿ S T is univalent.
Productᴿ-univalent :
{@0 S : Relation-transformer-for F}
{@0 T : Relation-transformer-for G} →
Univalentᴿ S →
Univalentᴿ T →
Univalentᴿ (Productᴿ S T)
Productᴿ-univalent (s-S , u-S) (s-T , u-T) =
Productᴿ-suitable s-S s-T
, Product-univalent u-S u-T
-- If S and T act on functions, then Productᴿ S T acts on functions.
Productᴿ-acts-on-functions :
{@0 S : Relation-transformer-for F}
{@0 T : Relation-transformer-for G} →
Acts-on-functions S →
Acts-on-functions T →
Acts-on-functions (Productᴿ S T)
Productᴿ-acts-on-functions {S = S} {T = T} a-S a-T = λ where
.Acts-on-functions.map f →
Σ-map (a-S .Acts-on-functions.map f)
(a-T .Acts-on-functions.map f)
.Acts-on-functions.map-id →
Σ-map (a-S .Acts-on-functions.map id)
(a-T .Acts-on-functions.map id) ≡⟨ cong₂ (λ f g → Σ-map f g)
(a-S .Acts-on-functions.map-id)
(a-T .Acts-on-functions.map-id) ⟩
Σ-map id id ≡⟨⟩
id ∎
.Acts-on-functions.map-map {f = f} {g = g} {x = x₁ , x₂} {y = y₁ , y₂} {R₁ = R₁} {R₂ = R₂} R₁→R₂ →
S R₁ x₁ y₁ × T R₁ x₂ y₂ ↝⟨ a-S .Acts-on-functions.map-map R₁→R₂
×-cong
a-T .Acts-on-functions.map-map R₁→R₂ ⟩□
S R₂ (a-S .Acts-on-functions.map f x₁)
(a-S .Acts-on-functions.map g y₁) ×
T R₂ (a-T .Acts-on-functions.map f x₂)
(a-T .Acts-on-functions.map g y₂) □
-- If S and T are positive, then Productᴿ S T is positive.
Productᴿ-positive :
{@0 S : Relation-transformer-for F}
{@0 T : Relation-transformer-for G} →
Positive S →
Positive T →
Positive (Productᴿ S T)
Productᴿ-positive {F = F} {G = G} {S = S} {T = T} p-S p-T = λ where
.Positive.suitable → suitable
.Positive.acts-on-functions → acts-on-functions
.Positive.reflexive-∥≡∥ᴱ → SP.reflexive-∥≡∥ᴱ , TP.reflexive-∥≡∥ᴱ
.Positive.transitive-;ᴱ⁻¹
{R = R₁} {S = R₂} R₁-prop R₂-prop x@(x₁ , x₂) z@(z₁ , z₂) →
_≃_.is-equivalence $
Eq.with-other-function
((Productᴿ S T R₁ ;ᴱ Productᴿ S T R₂) x z ↝⟨ lemma ⟩
(S R₁ ;ᴱ S R₂) x₁ z₁ × (T R₁ ;ᴱ T R₂) x₂ z₂ ↝⟨ Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩
×-cong
Eq.⟨ _ , TP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩
S (R₁ ;ᴱ R₂) x₁ z₁ × T (R₁ ;ᴱ R₂) x₂ z₂ ↔⟨⟩
Productᴿ S T (R₁ ;ᴱ R₂) x z □)
_
(T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
H-level.mono₁ 1 $
×-closure 1
(SS.preserves-is-proposition
(λ _ _ → T.truncation-is-proposition) _ _)
(TS.preserves-is-proposition
(λ _ _ → T.truncation-is-proposition) _ _)
.T.∣∣ʳ _ →
refl _)
.Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv →
_≃ᴱ_.is-equivalence $
EEq.with-other-function
(Product F G A /ᴱ Productᴿ S T R ↔⟨⟩
(F A × G A) /ᴱ Productᴿ S T R ↔⟨ Q.×/ᴱ (SP.reflexive prop equiv _) (TP.reflexive prop equiv _) ⟩
F A /ᴱ S R × G A /ᴱ T R ↝⟨ EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩
×-cong
EEq.⟨ _ , TP.commutes-with-/ᴱ prop equiv ⟩ ⟩
F (A /ᴱ R) × G (A /ᴱ R) ↔⟨⟩
Product F G (A /ᴱ R) □)
_
(Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
×-closure 2
(SS.preserves-is-set Q./ᴱ-is-set)
(TS.preserves-is-set Q./ᴱ-is-set)
.Q.[]ʳ _ → refl _)
where
module SP = Positive p-S
module SS = Suitable SP.suitable
module TP = Positive p-T
module TS = Suitable TP.suitable
suitable =
Productᴿ-suitable
SP.suitable
TP.suitable
acts-on-functions =
Productᴿ-acts-on-functions
SP.acts-on-functions
TP.acts-on-functions
@0 lemma :
(Productᴿ S T R₁ ;ᴱ Productᴿ S T R₂) (x₁ , x₂) (z₁ , z₂) ≃
((S R₁ ;ᴱ S R₂) x₁ z₁ × (T R₁ ;ᴱ T R₂) x₂ z₂)
lemma = Eq.⇔→≃
T.truncation-is-proposition
(×-closure 1
T.truncation-is-proposition
T.truncation-is-proposition)
(T.rec λ @0 where
.T.truncation-is-propositionʳ →
×-closure 1
T.truncation-is-proposition
T.truncation-is-proposition
.T.∣∣ʳ (_ , (SR₁x₁y₁ , TR₁x₂y₂) , (SR₂y₁z₁ , TR₂y₂z₂)) →
∣ _ , SR₁x₁y₁ , SR₂y₁z₁ ∣
, ∣ _ , TR₁x₂y₂ , TR₂y₂z₂ ∣)
(uncurry $ T.rec λ @0 where
.T.truncation-is-propositionʳ →
Π-closure ext 1 λ _ →
T.truncation-is-proposition
.T.∣∣ʳ (_ , SR₁x₁y₁ , SR₂y₁z₁) →
T.∥∥ᴱ-map
λ (_ , TR₁x₂y₂ , TR₂y₂z₂) →
_ , (SR₁x₁y₁ , TR₁x₂y₂) , (SR₂y₁z₁ , TR₂y₂z₂))
------------------------------------------------------------------------
-- Combinators related to Maybe
-- A combinator that, given a relation transformer for F, produces a
-- relation transformer for Maybe ∘ F.
Maybeᴿ :
Relation-transformer-for F →
Relation-transformer-for (Maybe ∘ F)
Maybeᴿ = Maybeᴾ ∘_
-- When is an equivalence structure-preserving for Maybe ∘ F?
Is-Maybe-equivalence :
Structure-preserving-equivalence-predicate F a →
Structure-preserving-equivalence-predicate (Maybe ∘ F) a
Is-Maybe-equivalence Is-F-eq = λ where
(A , nothing) (B , nothing) eq → ↑ _ ⊤
(A , just x) (B , just y) eq → Is-F-eq (A , x) (B , y) eq
(A , _) (B , _) eq → ⊥
-- If F is univalent, then Maybe ∘ F is univalent.
Maybe-univalent :
{@0 F : Structure a b}
{@0 Is-F-eq : Structure-preserving-equivalence-predicate F c} →
@0 Univalent F Is-F-eq →
Univalent (Maybe ∘ F) (Is-Maybe-equivalence Is-F-eq)
Maybe-univalent
{F = F} {Is-F-eq = Is-F-eq} u-F .Univalent.univalent
{A = A , x} {B = B , y} =
lemma x y
where
univ = U.abstract-univ
lemma :
(x : Maybe (F A)) (y : Maybe (F B)) →
(eq : A ≃ᴱ B) →
Is-Maybe-equivalence Is-F-eq (A , x) (B , y) eq ≃
(subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y)
lemma nothing nothing eq =
↑ _ ⊤ ↔⟨ B.↑↔ ⟩
⊤ ↔⟨ inverse tt≡tt↔⊤ ⟩
tt ≡ tt ↔⟨ B.≡↔inj₁≡inj₁ ⟩
nothing ≡ nothing ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₁ _ _ ⟩□
subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) nothing ≡ nothing □
lemma nothing (just y) eq =
⊥ ↔⟨ ⊥↔⊥ ⟩
⊥ ↔⟨ inverse B.≡↔⊎ ⟩
nothing ≡ just y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₁ _ _ ⟩□
subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) nothing ≡ just y □
lemma (just x) nothing eq =
⊥ ↔⟨ ⊥↔⊥ ⟩
⊥ ↔⟨ inverse B.≡↔⊎ ⟩
just _ ≡ nothing ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₂ _ _ ⟩□
subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (just x) ≡ nothing □
lemma (just x) (just y) eq =
Is-F-eq (A , x) (B , y) eq ↝⟨ u-F .Univalent.univalent eq ⟩
subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y ↔⟨ B.≡↔inj₂≡inj₂ ⟩
just (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x) ≡ just y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₂ _ _ ⟩□
subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (just x) ≡ just y □
-- If G is suitable, then Maybeᴿ G is suitable.
Maybeᴿ-suitable :
{@0 G : Relation-transformer-for F} →
Suitable G →
Suitable (Maybeᴿ G)
Maybeᴿ-suitable {G = G} s-G = λ where
.Suitable.preserves-is-set set →
Maybe-closure 0 (S.preserves-is-set set)
.Suitable.preserves-is-proposition prop → λ @0 where
nothing nothing →
H-level.mono₁ 0 $
↑-closure 0 ⊤-contractible
nothing (just _) →
⊥-propositional
(just _) nothing →
⊥-propositional
(just x) (just y) →
S.preserves-is-proposition prop x y
.Suitable.symmetric {x = nothing} {y = nothing} → _
.Suitable.symmetric {x = just x} {y = just y} → S.symmetric
.Suitable.transitive {x = nothing} {y = nothing} {z = nothing} → _
.Suitable.transitive {x = just _} {y = just _} {z = just _} →
S.transitive
.Suitable.descent {x = nothing} {R = R} prop equiv _ →
(nothing , [ _ ])
, [ (λ @0 where
(nothing , _) → refl _)
]
.Suitable.descent {x = just x} {R = R} prop equiv SRxx →
$⟨ [ SRxx ] ⟩
Erased (G R x x) ↝⟨ (λ ([ SRxx ]) → S.descent prop equiv SRxx) ⟩
Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y)) ↝⟨ ECP.Contractibleᴱ-cong _
(Eq.↔→≃
(Σ-map just id)
(λ where
(nothing , ())
(just y , s) → y , s)
(λ where
(nothing , ())
(just _ , _) → refl _)
refl)
⦂ (_ → _) ⟩□
Contractibleᴱ (∃ λ y → Erased (Maybeᴿ G (Graph [_]) (just x) y)) □
where
module S = Suitable s-G
-- If G is univalent, then Maybeᴿ G is univalent.
Maybeᴿ-univalent :
{@0 G : Relation-transformer-for F} →
Univalentᴿ G →
Univalentᴿ (Maybeᴿ G)
Maybeᴿ-univalent {F = F} {G = G} (s-G , u-G) =
Maybeᴿ-suitable s-G
, ( $⟨ Maybe-univalent u-G ⟩
Univalent (Maybe ∘ F)
(Is-Maybe-equivalence λ (A , x) (B , y) eq →
G (Graph (_≃ᴱ_.to eq)) x y) ↝⟨ substᴱ (Univalent _)
(⟨ext⟩ λ p → ⟨ext⟩ λ q → lemma (p .proj₂) (q .proj₂)) ⟩□
Univalent (Maybe ∘ F)
(λ (A , x) (B , y) eq → Maybeᴿ G (Graph (_≃ᴱ_.to eq)) x y) □)
where
@0 lemma :
∀ x y →
Is-Maybe-equivalence
(λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y)
(A , x) (B , y) ≡
(λ eq → Maybeᴿ G (Graph (_≃ᴱ_.to eq)) x y)
lemma nothing nothing = refl _
lemma nothing (just _) = refl _
lemma (just _) nothing = refl _
lemma (just _) (just _) = refl _
-- If G acts on functions, then Maybeᴿ G acts on functions.
Maybeᴿ-acts-on-functions :
{@0 G : Relation-transformer-for F} →
Acts-on-functions G →
Acts-on-functions (Maybeᴿ G)
Maybeᴿ-acts-on-functions {G = G} a-G = λ where
.Acts-on-functions.map f →
Monad.map (A.map f)
.Acts-on-functions.map-id →
Monad.map (A.map id) ≡⟨ cong Monad.map A.map-id ⟩
Monad.map id ≡⟨ ⟨ext⟩ Monad.map-id ⟩∎
id ∎
.Acts-on-functions.map-map {x = nothing} {y = nothing} → _
.Acts-on-functions.map-map {x = nothing} {y = just _} _ ()
.Acts-on-functions.map-map {x = just _} {y = nothing} _ ()
.Acts-on-functions.map-map {x = just _} {y = just _} →
A.map-map
where
module A = Acts-on-functions a-G
-- If G is positive, then Maybeᴿ G is positive.
Maybeᴿ-positive :
{@0 G : Relation-transformer-for F} →
Positive G →
Positive (Maybeᴿ G)
Maybeᴿ-positive {F = F} {G = G} p-G = λ where
.Positive.suitable → suitable
.Positive.acts-on-functions → acts-on-functions
.Positive.reflexive-∥≡∥ᴱ {x = nothing} → _
.Positive.reflexive-∥≡∥ᴱ {x = just _} → SP.reflexive-∥≡∥ᴱ
.Positive.transitive-;ᴱ⁻¹ R₁-prop R₂-prop x z →
_≃_.is-equivalence $
Eq.with-other-function
(lemma R₁-prop R₂-prop x z .proj₁)
_
(lemma R₁-prop R₂-prop x z .proj₂)
.Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv →
_≃ᴱ_.is-equivalence $
EEq.with-other-function
(Maybe (F A) /ᴱ Maybeᴿ G R ↔⟨ Q.Maybe/ᴱ ⟩
Maybe (F A /ᴱ G R) ↝⟨ F.id ⊎-cong EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩ ⟩□
Maybe (F (A /ᴱ R)) □)
(/ᴱ→/ᴱ (Maybeᴿ G) suitable acts-on-functions prop equiv)
(Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
Maybe-closure 0 (SS.preserves-is-set Q./ᴱ-is-set)
.Q.[]ʳ nothing → refl _
.Q.[]ʳ (just _) → refl _)
where
module SP = Positive p-G
module SS = Suitable SP.suitable
suitable = Maybeᴿ-suitable SP.suitable
acts-on-functions = Maybeᴿ-acts-on-functions SP.acts-on-functions
@0 lemma :
(R₁-prop : ∀ x y → Is-proposition (R₁ x y)) →
(R₂-prop : ∀ x y → Is-proposition (R₂ x y)) →
∀ x z →
∃ λ (eq : (Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) x z ≃
Maybeᴿ G (R₁ ;ᴱ R₂) x z) →
∀ p →
_≃_.to eq p ≡
Suitable.transitive-;ᴱ suitable R₁-prop R₂-prop x z p
lemma {R₁ = R₁} {R₂ = R₂} R₁-prop R₂-prop = λ @0 where
nothing nothing →
((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) nothing nothing ↝⟨ Eq.⇔→≃
T.truncation-is-proposition
(H-level.mono₁ 0 $ ↑-closure 0 ⊤-contractible)
_
(λ _ → ∣ nothing , _ ∣) ⟩□
↑ _ ⊤ □)
, (λ _ → refl _)
nothing (just z) →
((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) nothing (just z) ↝⟨ Eq.⇔→≃
T.truncation-is-proposition
⊥-propositional
(T.rec λ @0 where
.T.truncation-is-propositionʳ →
⊥-propositional
.T.∣∣ʳ (nothing , _ , ())
.T.∣∣ʳ (just _ , () , _))
⊥-elim ⟩□
⊥ □)
, (T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
H-level.⇒≡ 1 $
⊥-propositional
.T.∣∣ʳ (nothing , _ , ())
.T.∣∣ʳ (just _ , () , _))
(just x) nothing →
((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) (just x) nothing ↝⟨ Eq.⇔→≃
T.truncation-is-proposition
⊥-propositional
(T.rec λ @0 where
.T.truncation-is-propositionʳ →
⊥-propositional
.T.∣∣ʳ (nothing , () , _)
.T.∣∣ʳ (just _ , _ , ()))
⊥-elim ⟩□
⊥ □)
, (T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
H-level.⇒≡ 1 $
⊥-propositional
.T.∣∣ʳ (nothing , () , _)
.T.∣∣ʳ (just _ , _ , ()))
(just x) (just z) →
((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) (just x) (just z) ↝⟨ Eq.⇔→≃
T.truncation-is-proposition
T.truncation-is-proposition
(T.∥∥ᴱ-map λ where
(nothing , () , ())
(just _ , p) → _ , p)
(T.∥∥ᴱ-map (Σ-map just id)) ⟩
(G R₁ ;ᴱ G R₂) x z ↝⟨ Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩□
G (R₁ ;ᴱ R₂) x z □)
, (T.elim λ @0 where
.T.truncation-is-propositionʳ _ →
H-level.⇒≡ 1 $
SS.preserves-is-proposition
(λ _ _ → T.truncation-is-proposition) _ _
.T.∣∣ʳ (nothing , () , ())
.T.∣∣ʳ (just _ , _) → refl _)
------------------------------------------------------------------------
-- The Function and Functionᴿ combinators, along with some properties
-- Function structures.
Function : Structure a b → Structure a c → Structure a (b ⊔ c)
Function F G A = F A → G A
-- A combinator that, given relation transformers for F and G,
-- produces a relation transformer for Function F G.
Functionᴿ :
{F : Structure a b}
{G : Structure a c} →
Relation-transformer-for F →
Relation-transformer-for G →
Relation-transformer-for (Function F G)
Functionᴿ S T R f g = ∀ {x y} → S R x y → T R (f x) (g y)
-- A variant of Functionᴿ ∘ Constᴿ.
Function-Constᴿ :
{F : Structure b c}
(A : Type a) →
Relation-transformer-for F →
Relation-transformer-for (Function (Const A) F)
Function-Constᴿ A G R f g = (x : A) → G R (f x) (g x)
-- Function-Constᴿ is pointwise equivalent to Functionᴿ ∘ Constᴿ.
Function-Constᴿ≃Functionᴿ∘Constᴿ :
{f : A → F B} {g : A → F C}
(G : Relation-transformer-for F) →
Function-Constᴿ A G R f g ≃
(Functionᴿ ∘ Constᴿ) A G R f g
Function-Constᴿ≃Functionᴿ∘Constᴿ {R = R} {f = f} {g = g} G =
(∀ x → G R (f x) (g x)) ↝⟨ (∀-cong ext λ _ → ∀-intro _ ext) ⟩
(∀ x y → x ≡ y → G R (f x) (g y)) ↔⟨ inverse (∀-cong ext (λ _ → B.implicit-Π↔Π) F.∘ B.implicit-Π↔Π) ⟩□
(∀ {x y} → x ≡ y → G R (f x) (g y)) □
-- When is an equivalence structure-preserving for Function F G?
Is-Function-equivalence :
{F : Structure a b} →
Structure-preserving-equivalence-predicate F c →
Structure-preserving-equivalence-predicate G d →
Structure-preserving-equivalence-predicate (Function F G) (b ⊔ c ⊔ d)
Is-Function-equivalence Is-F-eq Is-G-eq (A , f) (B , g) eq =
∀ {x y} → Is-F-eq (A , x) (B , y) eq → Is-G-eq (A , f x) (B , g y) eq
-- A variant of Is-Function-equivalence.
Is-Function-equivalence′ :
{F : Structure a b} →
(∀ {A B} → A ≃ᴱ B → F A ≃ᴱ F B) →
Structure-preserving-equivalence-predicate G c →
Structure-preserving-equivalence-predicate (Function F G) (b ⊔ c)
Is-Function-equivalence′ F-cong Is-G-eq (A , f) (B , g) eq =
∀ x → Is-G-eq (A , f x) (B , g (_≃ᴱ_.to (F-cong eq) x)) eq
-- If F and G are univalent, then Function F G is univalent.
Function-univalent :
{@0 F : Structure a b}
{@0 G : Structure a c}
{@0 Is-F-eq : Structure-preserving-equivalence-predicate F d}
{@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} →
@0 Univalent F Is-F-eq →
@0 Univalent G Is-G-eq →
Univalent (Function F G) (Is-Function-equivalence Is-F-eq Is-G-eq)
Function-univalent
{F = F} {G = G} {Is-F-eq = Is-F-eq} {Is-G-eq = Is-G-eq}
u-F u-G .Univalent.univalent
{A = A , f} {B = B , g} eq =
(∀ {x y} → Is-F-eq (A , x) (B , y) eq →
Is-G-eq (A , f x) (B , g y) eq) ↔⟨ B.implicit-Π↔Π F.∘
implicit-∀-cong ext B.implicit-Π↔Π ⟩
(∀ x y → Is-F-eq (A , x) (B , y) eq →
Is-G-eq (A , f x) (B , g y) eq) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ →
→-cong ext (u-F .Univalent.univalent eq) (u-G .Univalent.univalent eq)) ⟩
(∀ x y → subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y →
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $
≡⇒≃ (cong (_ ≡_) $ _≃_.left-inverse-of (Eq.subst-as-equivalence _ _) _) F.∘
inverse (Eq.≃-≡ $ inverse $ Eq.subst-as-equivalence _ _) F.∘
from-bijection ≡-comm) ⟩
(∀ x y → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x →
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↔⟨ Π-comm ⟩
(∀ y x → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x →
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ eq →
≡⇒≃ $ cong (_≡ _) $ cong (subst G _) $ cong f $ sym eq) ⟩
(∀ y x → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x →
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))
(f (subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y)) ≡
g y) ↝⟨ (∀-cong ext λ _ → inverse $
∀-intro _ ext) ⟩
(∀ y →
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))
(f (subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y)) ≡
g y) ↝⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong (_≡ _) $ sym $
subst-→) ⟩
(∀ y → subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f y ≡ g y) ↝⟨ Eq.extensionality-isomorphism ext ⟩□
subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f ≡ g □
where
univ = U.abstract-univ
-- A variant of Function-univalent that is stated using
-- Is-Function-equivalence′ instead of Is-Function-equivalence.
Function-univalent′ :
{@0 G : Structure a c}
{@0 Is-G-eq : Structure-preserving-equivalence-predicate G e}
(@0 F-cong : ∀ {A B} → A ≃ᴱ B → F A ≃ᴱ F B) →
@0 (∀ {A} (x : F A) → _≃ᴱ_.to (F-cong F.id) x ≡ x) →
@0 Univalent G Is-G-eq →
Univalent (Function F G) (Is-Function-equivalence′ F-cong Is-G-eq)
Function-univalent′
{F = F} {G = G} {Is-G-eq = Is-G-eq}
F-cong F-cong-id u-G .Univalent.univalent
{A = A , f} {B = B , g} eq =
(∀ x → Is-G-eq (A , f x) (B , g (_≃ᴱ_.to (F-cong eq) x)) eq) ↝⟨ (∀-cong ext λ _ → u-G .Univalent.univalent eq) ⟩
(∀ x →
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g (_≃ᴱ_.to (F-cong eq) x)) ↝⟨ Eq.extensionality-isomorphism ext ⟩
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡ g ∘ _≃ᴱ_.to (F-cong eq) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡_) $
cong (g ∘_) $ cong _≃ᴱ_.to $ cong F-cong $ sym $
_≃_.right-inverse-of EEq.≃≃≃ᴱ _ ⟩
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡
g ∘ _≃ᴱ_.to (F-cong $ EEq.≃→≃ᴱ $ EEq.≃ᴱ→≃ eq) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡_) $
cong (g ∘_) $ ⟨ext⟩ $
transport-theorem
F (_≃ᴱ_.to ∘ F-cong ∘ EEq.≃→≃ᴱ) F-cong-id univ (EEq.≃ᴱ→≃ eq) ⟩
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡
g ∘ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ↝⟨ inverse $ Eq.≃-≡ $ →-cong₁ ext $ Eq.subst-as-equivalence _ _ ⟩
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘
subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡
g ∘ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘
subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘
subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡_) $
cong (g ∘_) $ ⟨ext⟩ $
_≃_.right-inverse-of (Eq.subst-as-equivalence _ _) ⟩
subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘
subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡
g ↝⟨ (≡⇒≃ $ cong (_≡ _) $ sym $ ⟨ext⟩ λ _ →
subst-→) ⟩□
subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f ≡ g □
where
univ = U.abstract-univ
-- If S is positive and T is suitable, then Functionᴿ S T is suitable.
--
-- This is a variant of Theorem 5.12 from "Internalizing
-- Representation Independence with Univalence".
Functionᴿ-suitable :
{@0 S : Relation-transformer-for F} →
{@0 T : Relation-transformer-for G} →
Positive S →
Suitable T →
Suitable (Functionᴿ S T)
Functionᴿ-suitable {F = F} {G = G} {S = S} {T = T} p-S s-T = λ where
.Suitable.preserves-is-set set →
Π-closure ext 2 λ _ →
TS.preserves-is-set set
.Suitable.preserves-is-proposition prop _ _ →
implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
TS.preserves-is-proposition prop _ _
.Suitable.symmetric
{R = R} {x = f} {y = g} prop S→T {x = x} {y = y} →
S (R ⁻¹) x y ↝⟨ SS.symmetric (flip prop) ⟩
S R y x ↝⟨ S→T ⟩
T R (f y) (g x) ↝⟨ TS.symmetric prop ⟩□
T (R ⁻¹) (g x) (f y) □
.Suitable.transitive
{R = R₁} {S = R₂} {x = f} {y = g} {z = h}
R₁-prop R₂-prop S→T₁ S→T₂ {x = x} {y = y} →
S (R₁ ;ᴱ R₂) x y ↔⟨ inverse Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩
(S R₁ ;ᴱ S R₂) x y ↝⟨ T.∥∥ᴱ-map (Σ-map _ (Σ-map S→T₁ S→T₂)) ⟩
(T R₁ ;ᴱ T R₂) (f x) (h y) ↝⟨ TS.transitive-;ᴱ R₁-prop R₂-prop _ _ ⟩□
T (R₁ ;ᴱ R₂) (f x) (h y) □
.Suitable.descent {A = A} {x = f} {R = R} prop equiv S→T →
let
d :
(x : F A) →
Contractibleᴱ (∃ λ y → Erased (T (Graph [_]) (f x) y))
d x = TS.descent prop equiv (S→T (SP.reflexive prop equiv x))
g-[] : F A → G (A /ᴱ R)
g-[] x = d x .proj₁ .proj₁
S→T′ : Erased (S R x y → T (Graph [_]) (f x) (g-[] y))
S→T′ = λ {x = x} {y = y} →
[ S R x y ↝⟨ S→T ⟩
T R (f x) (f y) ↝⟨ flip (TS.transitive prop (λ _ _ → Q./ᴱ-is-set)) (d y .proj₁ .proj₂ .erased) ⟩
T (R ;ᴱ Graph [_]) (f x) (g-[] y) ↝⟨ subst (λ R → T R (f x) (g-[] y)) (;ᴱ-Graph-[]≡Graph-[] prop equiv) ⟩□
T (Graph [_]) (f x) (g-[] y) □
]
S-[]-map-[] : ∀ {x} → Erased (S (Graph [_]) x (SA.map [_] x))
S-[]-map-[] = λ {x = x} →
[ $⟨ SA.map-map Q.[]-respects-relation (SP.reflexive prop equiv x) ⟩
S (Graph [_]) (SA.map id x) (SA.map [_] x) ↝⟨ subst (λ f → S (Graph (Q.[_] {R = R})) (f x) (SA.map Q.[_] x)) SA.map-id ⟩□
S (Graph [_]) x (SA.map [_] x) □
]
g : F A /ᴱ S R → G (A /ᴱ R)
g = Q.rec λ where
.Q.is-setʳ → TS.preserves-is-set Q./ᴱ-is-set
.Q.[]ʳ → g-[]
.Q.[]-respects-relationʳ {x = x} {y = y} SRxy →
g-[] x ≡⟨ cong proj₁ $
d x .proj₂ .erased
(g-[] y , Er.map (_$ SRxy) S→T′) ⟩∎
g-[] y ∎
h : F A /ᴱ S R ≃ᴱ F (A /ᴱ R)
h = EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩
in
( (F (A /ᴱ R) ↝⟨ _≃ᴱ_.from h ⟩
F A /ᴱ S R ↝⟨ g ⟩□
G (A /ᴱ R) □)
, [ (λ {x = x} {y = y} →
let
lemma :
∀ y →
S (Graph [_]) x (_≃ᴱ_.to h y) →
T (Graph [_]) (f x) (g y)
lemma = Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
Π-closure ext 1 λ _ →
TS.preserves-is-proposition
(λ _ _ → Q./ᴱ-is-set) _ _
.Q.[]ʳ y →
let
s = $⟨ S-[]-map-[] .erased ⟩
S (Graph [_]) y (SA.map [_] y) ↝⟨ SS.symmetric (λ _ _ → Q./ᴱ-is-set) ⟩□
S (Graph [_] ⁻¹) (SA.map [_] y) y □
in
S (Graph [_]) x (SA.map [_] y) ↝⟨ flip (SS.transitive (λ _ _ → Q./ᴱ-is-set) λ _ _ → Q./ᴱ-is-set) s ⟩
S (Graph [_] ⟵) x y ↝⟨ subst (λ R → S R x y) (Graph-[]-⟵≡ prop equiv) ⟩
S R x y ↝⟨ S→T′ .erased ⟩□
T (Graph [_]) (f x) (g-[] y) □
in
S (Graph [_]) x y ↝⟨ subst (S (Graph [_]) x) (sym $ _≃ᴱ_.right-inverse-of h _) ⟩
S (Graph [_]) x (_≃ᴱ_.to h (_≃ᴱ_.from h y)) ↝⟨ lemma (_≃ᴱ_.from h y) ⟩□
T (Graph [_]) (f x) (g (_≃ᴱ_.from h y)) □)
]
)
, [ (λ (g′ , [ g′-hyp ]) →
let
lemma : ∀ y → g y ≡ g′ (_≃ᴱ_.to h y)
lemma = Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
TS.preserves-is-set Q./ᴱ-is-set
.Q.[]ʳ y →
g-[] y ≡⟨ cong proj₁ $
d y .proj₂ .erased
( g′ (SA.map [_] y)
, [
$⟨ S-[]-map-[] .erased ⟩
S (Graph [_]) y (SA.map [_] y) ↝⟨ g′-hyp ⟩□
T (Graph [_]) (f y) (g′ (SA.map [_] y)) □
]
) ⟩∎
g′ (SA.map [_] y) ∎
in
Σ-≡,≡→≡
(⟨ext⟩ λ x →
g (_≃ᴱ_.from h x) ≡⟨ lemma (_≃ᴱ_.from h x) ⟩
g′ (_≃ᴱ_.to h (_≃ᴱ_.from h x)) ≡⟨ cong g′ $ _≃ᴱ_.right-inverse-of h _ ⟩∎
g′ x ∎)
(H-level-Erased 1
(implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
TS.preserves-is-proposition (λ _ _ → Q./ᴱ-is-set) _ _)
_ _))
]
where
module SP = Positive p-S
module SA = Acts-on-functions SP.acts-on-functions
module SS = Suitable SP.suitable
module TS = Suitable s-T
-- If A is a set and G is suitable, then Function-Constᴿ A G is
-- suitable.
Function-Constᴿ-suitable :
{@0 G : Relation-transformer-for F} →
@0 Is-set A →
Suitable G →
Suitable (Function-Constᴿ A G)
Function-Constᴿ-suitable {F = F} {A = A} {G = G} set =
Suitable G ↝⟨ Functionᴿ-suitable (Constᴿ-positive set) ⟩
Suitable (Functionᴿ (Constᴿ A) G) ↝⟨ Suitable-map (inverse $ Function-Constᴿ≃Functionᴿ∘Constᴿ G) ⟩□
Suitable (Function-Constᴿ A G) □
-- If S is positive and univalent, and T is univalent, then
-- Functionᴿ S T is univalent.
Functionᴿ-univalent :
{@0 S : Relation-transformer-for F}
{@0 T : Relation-transformer-for G} →
Positive S →
Univalentᴿ S →
Univalentᴿ T →
Univalentᴿ (Functionᴿ S T)
Functionᴿ-univalent p-S (_ , u-S) (s-T , u-T) =
Functionᴿ-suitable p-S s-T
, Function-univalent u-S u-T
-- If A is a set and G is univalent, then Function-Constᴿ A G is
-- univalent.
Function-Constᴿ-univalent :
{@0 G : Relation-transformer-for F} →
@0 Is-set A →
Univalentᴿ G →
Univalentᴿ (Function-Constᴿ A G)
Function-Constᴿ-univalent set (s-G , u-G) =
Function-Constᴿ-suitable set s-G
, Function-univalent′ (λ _ → F.id) refl u-G
------------------------------------------------------------------------
-- Combinators related to Erased
-- A combinator that, given a relation transformer for F, produces a
-- relation transformer for λ A → Erased (F A).
--
-- Note that I have not proved that Erasedᴿ G is positive if G is
-- positive.
Erasedᴿ :
{@0 F : Structure a b} →
@0 Relation-transformer-for F →
Relation-transformer-for (λ A → Erased (F A))
Erasedᴿ G R = Erasedᴾ (G R)
-- When is an equivalence structure-preserving for λ A → Erased (F A)?
Is-Erased-equivalence :
@0 Structure-preserving-equivalence-predicate F a →
Structure-preserving-equivalence-predicate (λ A → Erased (F A)) a
Is-Erased-equivalence Is-F-eq (_ , [ x ]) (_ , [ y ]) eq =
Erased (Is-F-eq (_ , x) (_ , y) eq)
-- If F is univalent, then λ A → Erased (F A) is univalent.
Erased-univalent :
{@0 F : Structure a b}
{@0 Is-F-eq : Structure-preserving-equivalence-predicate F c} →
@0 Univalent F Is-F-eq →
Univalent (λ A → Erased (F A)) (Is-Erased-equivalence Is-F-eq)
Erased-univalent
{F = F} {Is-F-eq = Is-F-eq} u-F .Univalent.univalent
{A = A , [ x ]} {B = B , [ y ]} eq =
Erased (Is-F-eq (A , x) (B , y) eq) ↝⟨ Erased-cong (u-F .Univalent.univalent eq) ⟩
Erased (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y) ↔⟨ Erased-≡↔[]≡[] ⟩
[ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ] ≡ [ y ] ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym push-subst-[] ⟩□
subst (λ A → Erased (F A)) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) [ x ] ≡ [ y ] □
where
univ = U.abstract-univ
-- If G is suitable, then Erasedᴿ G is suitable.
Erasedᴿ-suitable :
{@0 G : Relation-transformer-for F} →
@0 Suitable G →
Suitable (Erasedᴿ G)
Erasedᴿ-suitable {G = G} s-G = λ where
.Suitable.preserves-is-set set →
H-level-Erased 2 (s-G .Suitable.preserves-is-set set)
.Suitable.preserves-is-proposition prop _ _ →
H-level-Erased 1 (s-G .Suitable.preserves-is-proposition prop _ _)
.Suitable.symmetric prop →
Er.map (s-G .Suitable.symmetric prop)
.Suitable.transitive R-prop S-prop [ GRxy ] [ GSyz ] →
[ s-G .Suitable.transitive R-prop S-prop GRxy GSyz ]
.Suitable.descent {x = [ x ]} {R = R} prop equiv [GRxx] → $⟨ [ [GRxx] .erased ] ⟩
Erased (G R x x) ↝⟨ Er.map (λ GRxx → s-G .Suitable.descent prop equiv GRxx) ⟩
Erased (Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y))) ↝⟨ ECP.Erased-Contractibleᴱ↔Contractibleᴱ-Erased _ ⟩
Contractibleᴱ (Erased (∃ λ y → Erased (G (Graph [_]) x y))) ↝⟨ ECP.Contractibleᴱ-cong _ Erased-Σ↔Σ ⟩
Contractibleᴱ (∃ λ ([ y ]) → Erased (Erased (G (Graph [_]) x y))) ↔⟨⟩
Contractibleᴱ (∃ λ y → Erased (Erasedᴿ G (Graph [_]) [ x ] y)) □
-- If G is univalent, then Erasedᴿ G is univalent.
Erasedᴿ-univalent :
{@0 G : Relation-transformer-for F} →
@0 Univalentᴿ G →
Univalentᴿ (Erasedᴿ G)
Erasedᴿ-univalent (s-G , u-G) =
Erasedᴿ-suitable s-G
, Erased-univalent u-G
-- If G acts on functions, then Erasedᴿ G acts on functions.
Erasedᴿ-acts-on-functions :
{@0 G : Relation-transformer-for F} →
@0 Acts-on-functions G →
Acts-on-functions (Erasedᴿ G)
Erasedᴿ-acts-on-functions {G = G} a-G = λ where
.Acts-on-functions.map f →
Er.map (a-G .Acts-on-functions.map f)
.Acts-on-functions.map-id →
Er.map (a-G .Acts-on-functions.map id) ≡⟨ cong (λ f → Er.map f) (a-G .Acts-on-functions.map-id) ⟩
Er.map id ≡⟨⟩
id ∎
.Acts-on-functions.map-map
{f = f} {g = g} {x = [ x ]} {y = [ y ]} {R₁ = R₁} {R₂ = R₂} R₁→R₂ →
Erased (G R₁ x y) ↝⟨ Er.map (a-G .Acts-on-functions.map-map R₁→R₂) ⟩□
Erased (G R₂ (a-G .Acts-on-functions.map f x)
(a-G .Acts-on-functions.map g y)) □
------------------------------------------------------------------------
-- An example: monoids
-- This is a variant of Examples 3.5 and 3.6 from "Internalizing
-- Representation Independence with Univalence".
module Example₁ where
-- Raw monoid structures.
Raw-monoid-structure : Structure a a
Raw-monoid-structure A = A × (A → A → A)
-- Raw-monoid-structure can be expressed using some combinators.
_ :
Raw-monoid-structure {a = a} ≡
Product Id (Function Id (Function Id Id))
_ = refl _
-- Raw monoids, i.e., monoids without the monoid laws.
Raw-monoid : (a : Level) → Type (lsuc a)
Raw-monoid _ = Type-with Raw-monoid-structure
-- Raw monoid equivalence predicates.
Is-raw-monoid-equivalence :
Structure-preserving-equivalence-predicate Raw-monoid-structure a
Is-raw-monoid-equivalence (_ , id₁ , _∘₁_) (_ , id₂ , _∘₂_) eq =
_≃ᴱ_.to eq id₁ ≡ id₂ ×
(∀ x y → _≃ᴱ_.to eq (x ∘₁ y) ≡ _≃ᴱ_.to eq x ∘₂ _≃ᴱ_.to eq y)
-- Is-raw-monoid-equivalence can be expressed using some
-- combinators.
_ :
Is-raw-monoid-equivalence {a = a} ≡
Is-Product-equivalence
Is-Id-equivalence
(Is-Function-equivalence′ id
(Is-Function-equivalence′ id
Is-Id-equivalence))
_ = refl _
-- Raw monoid equivalences (with erased proofs).
infix 4 _≃ᴿᴹᴱ_
_≃ᴿᴹᴱ_ : Raw-monoid a → Raw-monoid a → Type a
_≃ᴿᴹᴱ_ = _≃[ Is-raw-monoid-equivalence ]ᴱ_
-- The combination of Raw-monoid-structure and
-- Is-raw-monoid-equivalence is univalent (in erased settings).
Is-raw-monoid-equivalence-univalent :
Univalent (Raw-monoid-structure {a = a}) Is-raw-monoid-equivalence
Is-raw-monoid-equivalence-univalent =
Product-univalent
Id-univalent
(Function-univalent′ id refl
(Function-univalent′ id refl
Id-univalent))
-- The monoid laws.
Monoid-laws : Axioms Raw-monoid-structure a
Monoid-laws (A , id , _∘_) =
Is-set A ×
(∀ x → id ∘ x ≡ x) ×
(∀ x → x ∘ id ≡ x) ×
(∀ x y z → x ∘ (y ∘ z) ≡ (x ∘ y) ∘ z)
-- The monoid laws are propositional.
Monoid-laws-propositional :
(M : Raw-monoid a) → Is-proposition (Monoid-laws M)
Monoid-laws-propositional (A , id , _∘_) =
Σ-closure 1 (H-level-propositional ext 2) λ A-set →
×-closure 1 (Π-closure ext 1 λ _ → A-set) $
×-closure 1 (Π-closure ext 1 λ _ → A-set) $
Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ →
A-set
-- Monoid structures.
Monoid-structure : Structure a a
Monoid-structure =
Raw-monoid-structure With-the-axioms Monoid-laws
-- Monoids.
Monoid : (a : Level) → Type (lsuc a)
Monoid _ = Type-with Monoid-structure
-- Monoid equivalence predicates.
Is-monoid-equivalence :
Structure-preserving-equivalence-predicate Monoid-structure a
Is-monoid-equivalence = Lift-With-the-axioms Is-raw-monoid-equivalence
-- Monoid equivalences (with erased proofs).
infix 4 _≃ᴹᴱ_
_≃ᴹᴱ_ : Monoid a → Monoid a → Type a
_≃ᴹᴱ_ = _≃[ Is-monoid-equivalence ]ᴱ_
-- The combination of Monoid-structure and Is-monoid-equivalence is
-- univalent (in erased settings).
Is-monoid-equivalence-univalent :
Univalent (Monoid-structure {a = a}) Is-monoid-equivalence
Is-monoid-equivalence-univalent =
Univalent-With-the-axioms
Monoid-laws-propositional
Is-raw-monoid-equivalence-univalent
-- The structure identity principle for monoids.
@0 sip-for-monoids : (M ≃ᴹᴱ N) ≃ (M ≡ N)
sip-for-monoids = sip Is-monoid-equivalence-univalent
-- If a raw monoid M₂ is equivalent (with erased proofs) to the
-- underlying raw monoid of a monoid M₁, then the monoid laws hold
-- for M₂ (in erased contexts), and M₁ is equivalent (with erased
-- proofs) to the monoid constructed from M₂ and the laws.
induced-monoid :
(M₁@(A₁ , ops₁ , _) : Monoid a)
(M₂@(A₂ , ops₂) : Raw-monoid a) →
(A₁ , ops₁) ≃ᴿᴹᴱ M₂ →
∃ λ (l₂ : Erased (Monoid-laws M₂)) → M₁ ≃ᴹᴱ (A₂ , ops₂ , l₂)
induced-monoid =
induced-structures Is-raw-monoid-equivalence-univalent
-- The unary natural numbers form a monoid.
ℕ-monoid : Monoid lzero
ℕ-monoid =
ℕ
, (0 , _+_)
, [ ( ℕ-set
, refl
, (λ _ → Nat.+-right-identity)
, (λ m _ _ → Nat.+-assoc m)
)
]
-- One variant of binary natural numbers forms a raw monoid.
Bin-raw-monoid : Raw-monoid lzero
Bin-raw-monoid =
Bin
, Bin.Operations-for-Bin.zero
, Bin.Operations-for-Bin._+_
-- The raw monoid underlying ℕ-monoid is equivalent (with erased
-- proofs) to Bin-raw-monoid.
ℕ≃ᴿᴹᴱBin : (ℕ , (0 , _+_)) ≃ᴿᴹᴱ Bin-raw-monoid
ℕ≃ᴿᴹᴱBin =
(ℕ ↔⟨ inverse Bin.Bin↔ℕ ⟩□
Bin □)
, [ ( (_↔_.from Bin.Bin↔ℕ 0 ≡⟨ _↔_.to Bin.≡-for-indices↔≡ [ refl _ ] ⟩∎
Bin.Operations-for-Bin.zero ∎)
, (λ m n →
_↔_.from Bin.Bin↔ℕ (m + n) ≡⟨ _↔_.to Bin.≡-for-indices↔≡ [ refl _ ] ⟩∎
_↔_.from Bin.Bin↔ℕ m Bin.Operations-for-Bin.+
_↔_.from Bin.Bin↔ℕ n ∎)
)
]
-- The monoid laws hold for Bin-raw-monoid (in erased contexts).
@0 Bin-monoid-laws : Monoid-laws Bin-raw-monoid
Bin-monoid-laws =
induced-monoid ℕ-monoid Bin-raw-monoid ℕ≃ᴿᴹᴱBin .proj₁ .erased
-- One variant of binary natural numbers forms a monoid.
Bin-monoid : Monoid lzero
Bin-monoid =
Bin-raw-monoid .proj₁ , Bin-raw-monoid .proj₂ , [ Bin-monoid-laws ]
-- This monoid is equivalent, with erased proofs, to ℕ-monoid.
ℕ≃ᴹᴱBin : ℕ-monoid ≃ᴹᴱ Bin-monoid
ℕ≃ᴹᴱBin =
induced-monoid ℕ-monoid Bin-raw-monoid ℕ≃ᴿᴹᴱBin .proj₂
-- In erased contexts the monoid is equal to ℕ-monoid.
@0 ℕ≡Bin : ℕ-monoid ≡ Bin-monoid
ℕ≡Bin = _≃_.to sip-for-monoids ℕ≃ᴹᴱBin
------------------------------------------------------------------------
-- Another example: bags
-- This is a variant of Examples 5.5 and 5.13 from "Internalizing
-- Representation Independence with Univalence".
-- The type A is assumed to come with decidable equality.
module Example₂ {A : Type a} (_≟_ : Decidable-equality A) where
private
-- The type A is a set.
set : Is-set A
set = decidable⇒set _≟_
-- Raw bag structures.
Raw-bag-structure : Structure a a
Raw-bag-structure Bag =
-- An empty bag.
Bag ×
-- Insertion.
(A → Bag → Bag) ×
-- Union.
(Bag → Bag → Bag) ×
-- The number of occurrences of the given element in the given
-- bag.
(A → Bag → ℕ)
-- Raw-bag-structure can be expressed using some combinators.
_ :
Raw-bag-structure ≡
Product Id
(Product (Function (Const A) (Function Id Id))
(Product (Function Id (Function Id Id))
(Function (Const A) (Function Id (Const ℕ)))))
_ = refl _
-- Raw bag types.
Raw-bag-type : Type (lsuc a)
Raw-bag-type = Type-with Raw-bag-structure
-- Raw bag equivalence predicates.
Is-raw-bag-equivalence :
Structure-preserving-equivalence-predicate Raw-bag-structure a
Is-raw-bag-equivalence
(_ , empty₁ , insert₁ , union₁ , count₁)
(_ , empty₂ , insert₂ , union₂ , count₂)
eq =
_≃ᴱ_.to eq empty₁ ≡ empty₂ ×
(∀ x xs → _≃ᴱ_.to eq (insert₁ x xs) ≡ insert₂ x (_≃ᴱ_.to eq xs)) ×
(∀ xs ys →
_≃ᴱ_.to eq (union₁ xs ys) ≡
union₂ (_≃ᴱ_.to eq xs) (_≃ᴱ_.to eq ys)) ×
(∀ x xs → count₁ x xs ≡ count₂ x (_≃ᴱ_.to eq xs))
-- Is-raw-bag-equivalence can be expressed using some combinators.
_ :
Is-raw-bag-equivalence ≡
Is-Product-equivalence
Is-Id-equivalence
(Is-Product-equivalence
(Is-Function-equivalence′ (λ _ → EEq.id)
(Is-Function-equivalence′ id
Is-Id-equivalence))
(Is-Product-equivalence
(Is-Function-equivalence′ id
(Is-Function-equivalence′ id
Is-Id-equivalence))
(Is-Function-equivalence′ (λ _ → EEq.id)
(Is-Function-equivalence′ id
Is-Const-equivalence))))
_ = refl _
-- Raw bag equivalences (with erased proofs).
infix 4 _≃ᴮᴱ_
_≃ᴮᴱ_ : Raw-bag-type → Raw-bag-type → Type a
_≃ᴮᴱ_ = _≃[ Is-raw-bag-equivalence ]ᴱ_
-- Relation transformers for raw bag types.
Raw-bag-typeᴿ : Relation-transformer-for Raw-bag-structure
Raw-bag-typeᴿ =
Productᴿ Idᴿ
(Productᴿ (Function-Constᴿ A (Functionᴿ Idᴿ Idᴿ))
(Productᴿ (Functionᴿ Idᴿ (Functionᴿ Idᴿ Idᴿ))
(Function-Constᴿ A (Functionᴿ Idᴿ (Constᴿ ℕ)))))
-- Raw-bag-typeᴿ is univalent.
Raw-bag-typeᴿ-univalent : Univalentᴿ Raw-bag-typeᴿ
Raw-bag-typeᴿ-univalent =
Productᴿ-univalent Idᴿ-univalent
(Productᴿ-univalent
(Function-Constᴿ-univalent set
(Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent
Idᴿ-univalent))
(Productᴿ-univalent
(Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent
(Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent
Idᴿ-univalent))
(Function-Constᴿ-univalent set
(Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent
(Constᴿ-univalent ℕ-set)))))
-- One implementation of bags.
List-bag : Type a
List-bag = List A
count₁′ : A → A → ℕ
count₁′ x y = if x ≟ y then 1 else 0
count₁ : A → List-bag → ℕ
count₁ x = L.foldr (λ y → count₁′ x y +_) 0
Raw-bag-structure-List-bag : Raw-bag-structure List-bag
Raw-bag-structure-List-bag =
[]
, _∷_
, L._++_
, count₁
Raw-bag-type-List-bag : Raw-bag-type
Raw-bag-type-List-bag = List-bag , Raw-bag-structure-List-bag
-- Another implementation of bags.
Assoc-list-bag : Type a
Assoc-list-bag = List (ℕ × A)
insert : ℕ → A → Assoc-list-bag → Assoc-list-bag
insert m x [] = (m , x) ∷ []
insert m x ((n , y) ∷ ys) =
if x ≟ y
then (m + n , y) ∷ ys
else (n , y) ∷ insert m x ys
union : Assoc-list-bag → Assoc-list-bag → Assoc-list-bag
union = flip (L.foldr (uncurry insert))
count₂′ : A → ℕ × A → ℕ
count₂′ x (n , y) = if x ≟ y then n else 0
count₂ : A → Assoc-list-bag → ℕ
count₂ x = L.foldr (λ y → count₂′ x y +_) 0
Raw-bag-structure-Assoc-list-bag : Raw-bag-structure Assoc-list-bag
Raw-bag-structure-Assoc-list-bag =
[]
, insert 1
, union
, count₂
Raw-bag-type-Assoc-list-bag : Raw-bag-type
Raw-bag-type-Assoc-list-bag =
Assoc-list-bag , Raw-bag-structure-Assoc-list-bag
-- Some properties of count₁.
count₁-++ :
∀ xs → count₁ z (xs L.++ ys) ≡ count₁ z xs + count₁ z ys
count₁-++ [] = refl _
count₁-++ {z = z} {ys = ys} (x ∷ xs) =
count₁′ z x + (count₁ z (xs L.++ ys)) ≡⟨ cong (count₁′ z x +_) $ count₁-++ xs ⟩
count₁′ z x + (count₁ z xs + count₁ z ys) ≡⟨ Nat.+-assoc (count₁′ z x) ⟩∎
(count₁′ z x + count₁ z xs) + count₁ z ys ∎
count₁-replicate :
∀ n → count₁ z (L.replicate n y) ≡ count₂′ z (n , y)
count₁-replicate {z = z} {y = y} zero with z ≟ y
… | yes _ = refl _
… | no _ = refl _
count₁-replicate {z = z} {y = y} (suc n) =
count₁′ z y + count₁ z (L.replicate n y) ≡⟨ cong (count₁′ z y +_) $ count₁-replicate n ⟩
count₁′ z y + count₂′ z (n , y) ≡⟨ lemma ⟩∎
count₂′ z (suc n , y) ∎
where
lemma : count₁′ z y + count₂′ z (n , y) ≡ count₂′ z (suc n , y)
lemma with z ≟ y
… | yes _ = refl _
… | no _ = refl _
-- Some properties of count₂.
count₂-insert-≡ :
z ≡ x → ∀ ys → count₂ z (insert m x ys) ≡ m + count₂ z ys
count₂-insert-≡ {z = z} {x = x} {m = m} z≡x = helper
where
helper : ∀ ys → count₂ z (insert m x ys) ≡ m + count₂ z ys
helper [] with z ≟ x
… | yes _ = m + 0 ∎
… | no z≢x = ⊥-elim $ z≢x z≡x
helper ((n , y) ∷ ys) with x ≟ y
helper ((n , y) ∷ ys) | no x≢y =
count₂′ z (n , y) + count₂ z (insert m x ys) ≡⟨ cong (count₂′ z (n , y) +_) $ helper ys ⟩
count₂′ z (n , y) + (m + count₂ z ys) ≡⟨ Nat.+-assoc (count₂′ z (n , y)) ⟩
(count₂′ z (n , y) + m) + count₂ z ys ≡⟨ cong (_+ count₂ z ys) $ sym $ Nat.+-comm m ⟩
(m + count₂′ z (n , y)) + count₂ z ys ≡⟨ sym $ Nat.+-assoc m ⟩∎
m + (count₂′ z (n , y) + count₂ z ys) ∎
helper ((n , y) ∷ ys) | yes x≡y =
count₂′ z (m + n , y) + count₂ z ys ≡⟨ cong (_+ _) lemma ⟩
(m + count₂′ z (n , y)) + count₂ z ys ≡⟨ sym $ Nat.+-assoc m ⟩∎
m + (count₂′ z (n , y) + count₂ z ys) ∎
where
lemma : count₂′ z (m + n , y) ≡ m + count₂′ z (n , y)
lemma with z ≟ y
… | yes _ = m + n ∎
… | no z≢y = ⊥-elim $ z≢y (trans z≡x x≡y)
count₂-insert-≢ :
z ≢ x → ∀ ys → count₂ z (insert m x ys) ≡ count₂ z ys
count₂-insert-≢ {z = z} {x = x} {m = m} z≢x = helper
where
helper : ∀ ys → count₂ z (insert m x ys) ≡ count₂ z ys
helper [] with z ≟ x
… | no _ = 0 ∎
… | yes z≡x = ⊥-elim $ z≢x z≡x
helper ((n , y) ∷ ys) with x ≟ y
… | no _ =
count₂′ z (n , y) + count₂ z (insert m x ys) ≡⟨ cong (count₂′ z (n , y) +_) $ helper ys ⟩∎
count₂′ z (n , y) + count₂ z ys ∎
… | yes x≡y =
count₂′ z (m + n , y) + count₂ z ys ≡⟨ cong (_+ _) lemma ⟩∎
count₂′ z ( n , y) + count₂ z ys ∎
where
lemma : count₂′ z (m + n , y) ≡ count₂′ z (n , y)
lemma with z ≟ y
… | no _ = 0 ∎
… | yes z≡y = ⊥-elim $ z≢x (trans z≡y (sym x≡y))
count₂-insert :
∀ ys → count₂ z (insert m x ys) ≡ count₂′ z (m , x) + count₂ z ys
count₂-insert {z = z} {m = m} {x = x} ys with z ≟ x
… | yes z≡x =
count₂ z (insert m x ys) ≡⟨ count₂-insert-≡ z≡x ys ⟩∎
m + count₂ z ys ∎
… | no z≢x =
count₂ z (insert m x ys) ≡⟨ count₂-insert-≢ z≢x ys ⟩∎
count₂ z ys ∎
count₂-union :
∀ xs → count₂ z (union xs ys) ≡ count₂ z xs + count₂ z ys
count₂-union {z = z} {ys = ys} [] =
count₂ z ys ∎
count₂-union {z = z} {ys = ys} ((m , x) ∷ xs) =
count₂ z (insert m x (union xs ys)) ≡⟨ count₂-insert (union xs ys) ⟩
count₂′ z (m , x) + count₂ z (union xs ys) ≡⟨ cong (count₂′ z (m , x) +_) $ count₂-union xs ⟩
count₂′ z (m , x) + (count₂ z xs + count₂ z ys) ≡⟨ Nat.+-assoc (count₂′ z (m , x)) ⟩∎
(count₂′ z (m , x) + count₂ z xs) + count₂ z ys ∎
-- A relation relating values of the two bag types.
infix 4 _∼_
_∼_ : List-bag → Assoc-list-bag → Type a
xs ∼ ys = ∀ z → count₁ z xs ≡ count₂ z ys
-- The relation _∼_ is propositional.
∼-propositional : ∀ xs ys → Is-proposition (xs ∼ ys)
∼-propositional _ _ =
Π-closure ext 1 λ _ →
ℕ-set
-- The relation _∼_ is a QER.
∼-QER : Is-QER _∼_
∼-QER =
(λ {xs₁ xs₂ ys₁ ys₂} xs₁∼ys₁ xs₂∼ys₁ xs₂∼ys₂ z →
count₁ z xs₁ ≡⟨ xs₁∼ys₁ z ⟩
count₂ z ys₁ ≡⟨ sym $ xs₂∼ys₁ z ⟩
count₁ z xs₂ ≡⟨ xs₂∼ys₂ z ⟩∎
count₂ z ys₂ ∎)
, (λ xs → ∣ to xs , ∼to xs ∣)
, (λ ys → ∣ from ys , from∼ ys ∣)
where
to : List-bag → Assoc-list-bag
to = L.foldr (insert 1) []
from : Assoc-list-bag → List-bag
from = L.foldr (λ (n , x) → L.replicate n x L.++_) []
∼to : ∀ xs → xs ∼ to xs
∼to [] _ = refl _
∼to (x ∷ xs) z =
count₁′ z x + count₁ z xs ≡⟨ cong (count₁′ z x +_) $ ∼to xs z ⟩
count₁′ z x + count₂ z (to xs) ≡⟨⟩
count₂′ z (1 , x) + count₂ z (to xs) ≡⟨ sym $ count₂-insert (to xs) ⟩∎
count₂ z (insert 1 x (to xs)) ∎
from∼ : ∀ ys → from ys ∼ ys
from∼ [] _ = refl _
from∼ ((n , y) ∷ ys) z =
count₁ z (L.replicate n y L.++ from ys) ≡⟨ count₁-++ (L.replicate n y) ⟩
count₁ z (L.replicate n y) + count₁ z (from ys) ≡⟨ cong (count₁ z (L.replicate n y) +_) $ from∼ ys z ⟩
count₁ z (L.replicate n y) + count₂ z ys ≡⟨ cong (_+ count₂ z ys) $ count₁-replicate n ⟩
count₂′ z (n , y) + count₂ z ys ≡⟨⟩
count₂ z ((n , y) ∷ ys) ∎
-- Raw-bag-structure-List-bag and Raw-bag-structure-Assoc-list-bag
-- are related by Raw-bag-typeᴿ _∼_.
List-bag∼Assoc-list-bag :
Raw-bag-typeᴿ _∼_
Raw-bag-structure-List-bag Raw-bag-structure-Assoc-list-bag
List-bag∼Assoc-list-bag =
(λ z →
count₁ z [] ≡⟨⟩
count₂ z [] ∎)
, (λ x {x = xs} {y = ys} xs∼ys z →
count₁ z (x ∷ xs) ≡⟨⟩
count₁′ z x + count₁ z xs ≡⟨ cong (count₁′ z x +_) (xs∼ys z) ⟩
count₁′ z x + count₂ z ys ≡⟨⟩
count₂′ z (1 , x) + count₂ z ys ≡⟨ sym $ count₂-insert ys ⟩∎
count₂ z (insert 1 x ys) ∎)
, (λ {x = xs₁} {y = ys₁} xs₁∼ys₁ {x = xs₂} {y = ys₂} xs₂∼ys₂ z →
count₁ z (xs₁ L.++ xs₂) ≡⟨ count₁-++ xs₁ ⟩
count₁ z xs₁ + count₁ z xs₂ ≡⟨ cong₂ _+_ (xs₁∼ys₁ z) (xs₂∼ys₂ z) ⟩
count₂ z ys₁ + count₂ z ys₂ ≡⟨ sym $ count₂-union ys₁ ⟩∎
count₂ z (union ys₁ ys₂) ∎)
, (λ x {x = xs} {y = ys} xs∼ys →
count₁ x xs ≡⟨ xs∼ys x ⟩∎
count₂ x ys ∎)
-- There is an equivalence (with erased proofs) between List-bag
-- quotiented by _∼_ ⟵ and Assoc-list-bag quotiented by _∼_ ⟶
-- (where _/ᴱ_ is used for the quotients).
List-bag≃ᴱAssoc-list-bag :
List-bag /ᴱ _∼_ ⟵ ≃ᴱ Assoc-list-bag /ᴱ _∼_ ⟶
List-bag≃ᴱAssoc-list-bag =
/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional .proj₁
-- Lists that are related by List-bag≃ᴱAssoc-list-bag (in a
-- certain way) are also related by _∼_.
--
-- Note that this definition is not erased: it uses /ᴱ⟵≃ᴱ/ᴱ⟶
-- instead of /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ, and ∼-QER instead of
-- Is-QER→Is-QERᴱ ∼-QER.
→∼ :
∀ xs ys →
_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag [ xs ] ≡ [ ys ] →
xs ∼ ys
→∼ xs ys = /ᴱ⟵≃ᴱ/ᴱ⟶ ∼-QER ∼-propositional .proj₂ xs ys .proj₁
-- The function →∼ is an equivalence (in erased contexts).
@0 →∼-equivalence : ∀ xs ys → Is-equivalence (→∼ xs ys)
→∼-equivalence xs ys =
/ᴱ⟵≃ᴱ/ᴱ⟶ ∼-QER ∼-propositional .proj₂ xs ys .proj₂ .erased
-- The relation _∼_ can be expressed using
-- List-bag≃ᴱAssoc-list-bag (in erased contexts).
@0 ≃∼ :
∀ xs ys →
(_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag [ xs ] ≡ [ ys ]) ≃ (xs ∼ ys)
≃∼ = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional .proj₂ .erased
private
instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ =
Suitable→/ᴱ⟵×/ᴱ⟶
Raw-bag-type-List-bag
Raw-bag-type-Assoc-list-bag
(Raw-bag-typeᴿ-univalent .proj₁)
(Is-QER→Is-QERᴱ ∼-QER)
∼-propositional
List-bag∼Assoc-list-bag
-- There is a raw bag structure on List-bag /ᴱ _∼_ ⟵.
Raw-bag-structure-List-bag-/ᴱ :
Raw-bag-structure (List-bag /ᴱ _∼_ ⟵)
Raw-bag-structure-List-bag-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₁
Raw-bag-type-List-bag-/ᴱ : Raw-bag-type
Raw-bag-type-List-bag-/ᴱ =
List-bag /ᴱ _∼_ ⟵ , Raw-bag-structure-List-bag-/ᴱ
-- There is a raw bag structure on Assoc-list-bag /ᴱ _∼_ ⟶.
Raw-bag-structure-Assoc-list-bag-/ᴱ :
Raw-bag-structure (Assoc-list-bag /ᴱ _∼_ ⟶)
Raw-bag-structure-Assoc-list-bag-/ᴱ =
instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₁
Raw-bag-type-Assoc-list-bag-/ᴱ : Raw-bag-type
Raw-bag-type-Assoc-list-bag-/ᴱ =
Assoc-list-bag /ᴱ _∼_ ⟶ , Raw-bag-structure-Assoc-list-bag-/ᴱ
-- The two raw bag structures are related to the underlying raw
-- bag structures (in erased contexts).
@0 List∼List-/ᴱ :
Raw-bag-typeᴿ (Graph [_])
Raw-bag-structure-List-bag Raw-bag-structure-List-bag-/ᴱ
List∼List-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₁
@0 Assoc-list∼Assoc-list-/ᴱ :
Raw-bag-typeᴿ (Graph [_])
Raw-bag-structure-Assoc-list-bag
Raw-bag-structure-Assoc-list-bag-/ᴱ
Assoc-list∼Assoc-list-/ᴱ =
instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₂ .proj₁
-- They are also related to each other (in erased contexts).
@0 List-/ᴱ∼Assoc-list-/ᴱ :
Raw-bag-typeᴿ (Graph (_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag))
Raw-bag-structure-List-bag-/ᴱ
Raw-bag-structure-Assoc-list-bag-/ᴱ
List-/ᴱ∼Assoc-list-/ᴱ =
instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₂ .proj₂
-- Raw-bag-type-List-bag-/ᴱ is equal to
-- Raw-bag-type-Assoc-list-bag-/ᴱ (in erased contexts).
@0 List-/ᴱ≡Assoc-list-/ᴱ :
Raw-bag-type-List-bag-/ᴱ ≡ Raw-bag-type-Assoc-list-bag-/ᴱ
List-/ᴱ≡Assoc-list-/ᴱ =
Univalentᴿ→/ᴱ⟵×/ᴱ⟶
Raw-bag-type-List-bag
Raw-bag-type-Assoc-list-bag
Raw-bag-typeᴿ-univalent
(Is-QER→Is-QERᴱ ∼-QER)
∼-propositional
List-bag∼Assoc-list-bag
.proj₂ .proj₂ .erased .proj₂ .proj₂
-- For List-bag /ᴱ _∼_ ⟵ equality of two lists can be expressed in
-- terms of the induced count function (in erased contexts).
@0 List-≡≃ :
let count = Raw-bag-structure-List-bag-/ᴱ .proj₂ .proj₂ .proj₂ in
(xs ys : List-bag /ᴱ _∼_ ⟵) →
(xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys)
List-≡≃ = Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Eq.left-closure ext 0 $
Q./ᴱ-is-set
.Q.[]ʳ xs → Q.elim-prop λ @0 where
.Q.is-propositionʳ _ →
Eq.left-closure ext 0 $
Q./ᴱ-is-set
.Q.[]ʳ ys →
([ xs ] ≡ [ ys ]) ↝⟨ inverse $
Q.related≃[equal]
(Is-QER→Is-equivalence-relation-⟵ ∼-QER)
T.truncation-is-proposition ⟩
(_∼_ ⟵) xs ys ↝⟨ Eq.⇔→≃
T.truncation-is-proposition
(Π-closure ext 1 λ _ → ℕ-set)
(T.rec λ @0 where
.T.truncation-is-propositionʳ →
Π-closure ext 1 λ _ → ℕ-set
.T.∣∣ʳ (zs , xs∼zs , ys∼zs) z →
count₁ z xs ≡⟨ xs∼zs z ⟩
count₂ z zs ≡⟨ sym $ ys∼zs z ⟩∎
count₁ z ys ∎)
(λ xs∼ys →
T.∥∥ᴱ-map
(λ (zs , xs∼zs) →
zs
, xs∼zs
, λ z →
count₁ z ys ≡⟨ sym $ xs∼ys z ⟩
count₁ z xs ≡⟨ xs∼zs z ⟩∎
count₂ z zs ∎)
(∼-QER .proj₂ .proj₁ xs)) ⟩□
(∀ z → count₁ z xs ≡ count₁ z ys) □
-- This property can easily be transported to
-- Assoc-list-bag /ᴱ _∼_ ⟶.
@0 Assoc-list-≡≃ :
let count = Raw-bag-structure-Assoc-list-bag-/ᴱ
.proj₂ .proj₂ .proj₂ in
(xs ys : Assoc-list-bag /ᴱ _∼_ ⟶) →
(xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys)
Assoc-list-≡≃ =
subst
(λ B → let count = B .proj₂ .proj₂ .proj₂ .proj₂ in
(xs ys : B .proj₁) →
(xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys))
List-/ᴱ≡Assoc-list-/ᴱ
List-≡≃
| 36.66271
| 146
| 0.479298
|
59a97c5ab989f2f1dbbf45b113b5cbcb6f004d60
| 618
|
agda
|
Agda
|
test/Succeed/Issue1292.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1292.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1292.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2014-10-05, issue reported by Stevan Andjelkovic
{-# OPTIONS --without-K #-}
postulate
IO : Set → Set
record ⊤ : Set where
constructor tt
record Container : Set₁ where
field
Shape : Set
Position : Shape → Set
open Container public
data W (A : Set) (B : A → Set) : Set where
sup : (x : A) (f : B x → W A B) → W A B
postulate
Ω : Container
p : ∀ {s} → Position Ω s
mutual
bad : W (Shape Ω) (Position Ω) → IO ⊤
bad (sup c k) = helper c k
helper : (s : Shape Ω) → (Position Ω s → W (Shape Ω) (Position Ω)) → IO ⊤
helper _ k = bad (k p)
-- should pass termination check
| 18.727273
| 75
| 0.595469
|
295d1d912ae496a39acf28cc2e455e08d7e7f71b
| 725
|
agda
|
Agda
|
Parametric/Change/Type.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 10
|
2015-03-04T06:09:20.000Z
|
2019-07-19T07:06:59.000Z
|
Parametric/Change/Type.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 6
|
2015-07-01T18:09:31.000Z
|
2017-05-04T13:53:59.000Z
|
Parametric/Change/Type.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 1
|
2016-02-18T12:26:44.000Z
|
2016-02-18T12:26:44.000Z
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Simply-typed changes (Fig. 3 and Fig. 4d)
------------------------------------------------------------------------
import Parametric.Syntax.Type as Type
module Parametric.Change.Type
(Base : Type.Structure)
where
open Type.Structure Base
-- Extension point: Simply-typed changes of base types.
Structure : Set
Structure = Base → Type
module Structure (ΔBase : Structure) where
-- We provide: Simply-typed changes on simple types.
ΔType : Type → Type
ΔType (base ι) = ΔBase ι
ΔType (σ ⇒ τ) = σ ⇒ ΔType σ ⇒ ΔType τ
-- And we also provide context merging.
open import Base.Change.Context ΔType public
| 26.851852
| 72
| 0.571034
|
579bc96e79998985f0235dd79c04aa08165ba3ef
| 1,187
|
agda
|
Agda
|
src/Structure/Monoid/Laws.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
src/Structure/Monoid/Laws.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
src/Structure/Monoid/Laws.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
module Structure.Monoid.Laws where
open import Prelude
record MonoidLaws {a} (A : Set a) {{Mon : Monoid A}} : Set a where
field
idLeft : (x : A) → mempty <> x ≡ x
idRight : (x : A) → x <> mempty ≡ x
<>assoc : (x y z : A) → x <> (y <> z) ≡ (x <> y) <> z
open MonoidLaws {{...}} public
{-# DISPLAY MonoidLaws.idLeft _ = idLeft #-}
{-# DISPLAY MonoidLaws.idRight _ = idRight #-}
{-# DISPLAY MonoidLaws.<>assoc _ = <>assoc #-}
instance
MonoidLawsList : ∀ {a} {A : Set a} → MonoidLaws (List A)
idLeft {{MonoidLawsList}} xs = refl
idRight {{MonoidLawsList}} [] = refl
idRight {{MonoidLawsList}} (x ∷ xs) = x ∷_ $≡ idRight xs
<>assoc {{MonoidLawsList}} [] ys zs = refl
<>assoc {{MonoidLawsList}} (x ∷ xs) ys zs = x ∷_ $≡ <>assoc xs ys zs
MonoidLawsMaybe : ∀ {a} {A : Set a} {{_ : Monoid A}} {{_ : MonoidLaws A}} → MonoidLaws (Maybe A)
idLeft {{MonoidLawsMaybe}} x = refl
idRight {{MonoidLawsMaybe}} nothing = refl
idRight {{MonoidLawsMaybe}} (just _) = refl
<>assoc {{MonoidLawsMaybe}} nothing y z = refl
<>assoc {{MonoidLawsMaybe}} (just x) y z = refl
-- Can't do function lifting because no extentionality.
| 34.911765
| 98
| 0.590564
|
2966cae708ad6e70042228ea1fd0bd48aafc3728
| 305
|
agda
|
Agda
|
setoid-cats/Basics.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
setoid-cats/Basics.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
setoid-cats/Basics.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
-------------------------------------------
-- This file contains basic definitions. --
-------------------------------------------
module Basics where
open import Level
data ⊥-poly {l : Level} : Set l where
⊥-poly-elim : ∀ {l w} {Whatever : Set w} → ⊥-poly {l} → Whatever
⊥-poly-elim ()
| 25.416667
| 66
| 0.42623
|
29e036e6086afaf8a3bfa714b25c3f4ddb02c530
| 266
|
agda
|
Agda
|
src/Utilities/ExistsSyntax.agda
|
armkeh/agda-computability
|
f6a6845a54aed7ecc6841ff5ad89643b553cbd77
|
[
"MIT"
] | null | null | null |
src/Utilities/ExistsSyntax.agda
|
armkeh/agda-computability
|
f6a6845a54aed7ecc6841ff5ad89643b553cbd77
|
[
"MIT"
] | null | null | null |
src/Utilities/ExistsSyntax.agda
|
armkeh/agda-computability
|
f6a6845a54aed7ecc6841ff5ad89643b553cbd77
|
[
"MIT"
] | null | null | null |
module Utilities.ExistsSyntax where
open import Level using (Level ; _⊔_)
open import Data.Product using (Σ)
variable
a b : Level
A : Set a
B : Set b
∃-syntax : (A : Set a) → (A → Set b) → Set (a ⊔ b)
∃-syntax = Σ
syntax ∃-syntax A (λ x → B) = ∃ x ∶ A • B
| 17.733333
| 50
| 0.593985
|
18184134662dd12aa651dfdadbd92368c5b190c0
| 3,132
|
agda
|
Agda
|
homotopy/SuspensionJoin.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/SuspensionJoin.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/SuspensionJoin.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
module homotopy.SuspensionJoin {i} (A : Type i) where
{- To -}
false, : A → Bool × A
false, a = false , a
true, : A → Bool × A
true, a = true , a
module To = SuspensionRec {i} A {_} {Bool * A} (left false :> Bool * A) (left true) (λ a → glue (false, a) ∙ ! (glue (true, a)))
to : Suspension A → (Bool * A)
to = To.f
{- From -}
from : Bool * A → Suspension A
from = From.f module _ where
from-bool : Bool → Suspension A
from-bool false = north A
from-bool true = south A
from-glue : (c : Bool × A) → from-bool (fst c) == south A
from-glue (false , a) = merid A a
from-glue (true , a) = idp
module From = PushoutRec {d = *-span Bool A} from-bool (λ _ → south A) from-glue
{- ToFrom -}
to-from : (c : Bool * A) → to (from c) == c
to-from = Pushout-elim to-from-left (λ a → glue (true , a)) to-from-glue where
to-from-left : (b : Bool) → to (from (left b)) == left b
to-from-left false = idp
to-from-left true = idp
to-from-glue' : (b : Bool) (a : A)
→ ap to (ap from (glue (b , a))) ∙' glue (true , a) == to-from-left b ∙ glue (b , a)
to-from-glue' true a =
ap to (ap from (glue (true , a))) ∙' glue (true , a) =⟨ From.glue-β (true , a) |in-ctx (λ u → ap to u ∙' glue (true , a)) ⟩
idp ∙' glue (true , a) =⟨ ∙'-unit-l _ ⟩
glue (true , a) ∎
to-from-glue' false a =
ap to (ap from (glue (false , a))) ∙' glue (true , a) =⟨ From.glue-β (false , a) |in-ctx (λ u → ap to u ∙' glue (true , a)) ⟩
ap to (merid A a) ∙' glue (true , a) =⟨ To.glue-β a |in-ctx (λ u → u ∙' glue (true , a)) ⟩
(glue (false , a) ∙ ! (glue (true , a))) ∙' glue (true , a) =⟨ coh (glue (false , a)) (glue (true , a)) ⟩
glue (false , a) ∎ where
coh : ∀ {i} {A : Type i} {a b c : A} (p : a == b) (q : c == b) → (p ∙ ! q) ∙' q == p
coh idp idp = idp
to-from-glue : (c : Bool × A)
→ to-from-left (fst c) == glue (true , snd c) [ (λ z → to (from z) == z) ↓ glue c ]
to-from-glue c = ↓-∘=idf-in to from (uncurry to-from-glue' c)
{- FromTo -}
from-to : (c : Suspension A) → from (to c) == c
from-to = Suspension-elim A idp idp from-to-merid where
from-to-merid' : (a : A) → ap from (ap to (merid A a)) == merid A a
from-to-merid' a =
ap from (ap to (merid A a)) =⟨ To.glue-β a |in-ctx ap from ⟩
ap from (glue (false , a) ∙ ! (glue (true , a))) =⟨ ap-∙ from (glue (false , a)) (! (glue (true , a))) ⟩
ap from (glue (false , a)) ∙ ap from (! (glue (true , a))) =⟨ ap-! from (glue (true , a)) |in-ctx (λ u → ap from (glue (false , a)) ∙ u) ⟩
ap from (glue (false , a)) ∙ ! (ap from (glue (true , a))) =⟨ From.glue-β (false , a) |in-ctx (λ u → u ∙ ! (ap from (glue (true , a)))) ⟩
merid A a ∙ ! (ap from (glue (true , a))) =⟨ From.glue-β (true , a) |in-ctx (λ u → merid A a ∙ ! u) ⟩
merid A a ∙ idp =⟨ ∙-unit-r _ ⟩
merid A a ∎
from-to-merid : (a : A) → idp == idp [ (λ z → from (to z) == z) ↓ merid A a ]
from-to-merid a = ↓-∘=idf-in from to (from-to-merid' a)
{- Conclusion -}
e : Suspension A ≃ (Bool * A)
e = equiv to from to-from from-to
| 36.418605
| 144
| 0.515645
|
06612f6b2d88751d9f90a743139b1bab8d4b5d60
| 4,050
|
agda
|
Agda
|
Cubical/Foundations/Pointed/Homotopy.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Foundations/Pointed/Homotopy.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Foundations/Pointed/Homotopy.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Foundations.Pointed.Homotopy where
{-
This module defines two kinds of pointed homotopies,
∙∼ and ∙∼P, and proves their equivalence
-}
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Fiberwise
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Pointed.Base
open import Cubical.Foundations.Pointed.Properties
open import Cubical.Homotopy.Base
open import Cubical.Data.Sigma
private
variable
ℓ ℓ' : Level
module _ {A : Pointed ℓ} {B : typ A → Type ℓ'} {ptB : B (pt A)} where
⋆ = pt A
-- pointed homotopy as pointed Π. This is just a Σ-type, see ∙∼Σ
_∙∼_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ')
(f₁ , f₂) ∙∼ (g₁ , g₂) = Π∙ A (λ x → f₁ x ≡ g₁ x) (f₂ ∙ g₂ ⁻¹)
-- pointed homotopy with PathP. Also a Σ-type, see ∙∼PΣ
_∙∼P_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ')
(f₁ , f₂) ∙∼P (g₁ , g₂) = Σ[ h ∈ f₁ ∼ g₁ ] PathP (λ i → h ⋆ i ≡ ptB) f₂ g₂
-- Proof that f ∙∼ g ≃ f ∙∼P g
-- using equivalence of the total map of φ
private
module _ (f g : Π∙ A B ptB) (H : f .fst ∼ g .fst) where
-- convenient notation
f₁ = fst f
f₂ = snd f
g₁ = fst g
g₂ = snd g
-- P is the predicate on a homotopy H to be pointed of the ∙∼ kind
P : Type ℓ'
P = H ⋆ ≡ f₂ ∙ g₂ ⁻¹
-- Q is the predicate on a homotopy H to be pointed of the ∙∼P kind
Q : Type ℓ'
Q = PathP (λ i → H ⋆ i ≡ ptB) f₂ g₂
-- simplify the notation even more to see that P≡Q
-- is just a jingle of paths
p = H ⋆
r = f₂
s = g₂
P≡Q : P ≡ Q
P≡Q = p ≡ r ∙ s ⁻¹
≡⟨ isoToPath (symIso p (r ∙ s ⁻¹)) ⟩
r ∙ s ⁻¹ ≡ p
≡⟨ cong (r ∙ s ⁻¹ ≡_) (rUnit p ∙∙ cong (p ∙_) (sym (rCancel s)) ∙∙ assoc p s (s ⁻¹)) ⟩
r ∙ s ⁻¹ ≡ (p ∙ s) ∙ s ⁻¹
≡⟨ sym (ua (compr≡Equiv r (p ∙ s) (s ⁻¹))) ⟩
r ≡ p ∙ s
≡⟨ ua (compl≡Equiv (p ⁻¹) r (p ∙ s)) ⟩
p ⁻¹ ∙ r ≡ p ⁻¹ ∙ (p ∙ s)
≡⟨ cong (p ⁻¹ ∙ r ≡_ ) (assoc (p ⁻¹) p s ∙∙ (cong (_∙ s) (lCancel p)) ∙∙ sym (lUnit s)) ⟩
p ⁻¹ ∙ r ≡ s
≡⟨ cong (λ z → p ⁻¹ ∙ z ≡ s) (rUnit r) ⟩
p ⁻¹ ∙ (r ∙ refl) ≡ s
≡⟨ cong (_≡ s) (sym (doubleCompPath-elim' (p ⁻¹) r refl)) ⟩
p ⁻¹ ∙∙ r ∙∙ refl ≡ s
≡⟨ sym (ua (Square≃doubleComp r s p refl)) ⟩
PathP (λ i → p i ≡ ptB) r s ∎
-- φ is a fiberwise transformation (H : f ∼ g) → P H → Q H
-- φ is even a fiberwise equivalence by P≡Q
φ : P → Q
φ = transport P≡Q
-- The total map corresponding to φ
totφ : (f g : Π∙ A B ptB) → f ∙∼ g → f ∙∼P g
totφ f g p .fst = p .fst
totφ f g p .snd = φ f g (p .fst) (p .snd)
-- transformation of the homotopies using totφ
∙∼→∙∼P : (f g : Π∙ A B ptB) → (f ∙∼ g) → (f ∙∼P g)
∙∼→∙∼P f g = totφ f g
-- Proof that ∙∼ and ∙∼P are equivalent using the fiberwise equivalence φ
∙∼≃∙∼P : (f g : Π∙ A B ptB) → (f ∙∼ g) ≃ (f ∙∼P g)
∙∼≃∙∼P f g = Σ-cong-equiv-snd (λ H → transportEquiv (P≡Q f g H))
-- inverse of ∙∼→∙∼P extracted from the equivalence
∙∼P→∙∼ : {f g : Π∙ A B ptB} → f ∙∼P g → f ∙∼ g
∙∼P→∙∼ {f = f} {g = g} = invEq (∙∼≃∙∼P f g)
-- ∙∼≃∙∼P transformed to a path
∙∼≡∙∼P : (f g : Π∙ A B ptB) → (f ∙∼ g) ≡ (f ∙∼P g)
∙∼≡∙∼P f g = ua (∙∼≃∙∼P f g)
-- Verifies that the pointed homotopies actually correspond
-- to their Σ-type versions
_∙∼Σ_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ')
f ∙∼Σ g = Σ[ H ∈ f .fst ∼ g .fst ] (P f g H)
_∙∼PΣ_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ')
f ∙∼PΣ g = Σ[ H ∈ f .fst ∼ g .fst ] (Q f g H)
∙∼≡∙∼Σ : (f g : Π∙ A B ptB) → f ∙∼ g ≡ f ∙∼Σ g
∙∼≡∙∼Σ f g = refl
∙∼P≡∙∼PΣ : (f g : Π∙ A B ptB) → f ∙∼P g ≡ f ∙∼PΣ g
∙∼P≡∙∼PΣ f g = refl
| 33.75
| 103
| 0.512593
|
c5518ca6f89ab2d8be41d51cb37b7ddc3093192f
| 629
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/PreludeString.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/Alonzo/PreludeString.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/Alonzo/PreludeString.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module PreludeString where
import RTP -- magic module
import PreludeList
open PreludeList using (List)
open import AlonzoPrelude
infixr 50 _++_
private
primitive
primStringAppend : String -> String -> String
-- primStringReverse : String -> String
primStringToList : String -> List Char
primStringFromList : List Char -> String
_++_ = primStringAppend
reverseString = RTP.primStringReverse
toList : String -> List Char
toList = primStringToList
fromList : List Char -> String
fromList = primStringFromList
-- toList = RTP.primStringToList
-- fromList = RTP.primStringFromList
| 17.971429
| 52
| 0.721781
|
4a61b856ef684ab111337fb8759f321e001e06aa
| 3,174
|
agda
|
Agda
|
Cubical/Foundations/FunExtEquiv.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/FunExtEquiv.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/FunExtEquiv.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.FunExtEquiv where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ : Level
-- Function extensionality is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {f g : (x : A) → B x} where
private
fib : (p : f ≡ g) → fiber funExt p
fib p = (funExt⁻ p , refl)
funExt-fiber-isContr : (p : f ≡ g) → (fi : fiber funExt p) → fib p ≡ fi
funExt-fiber-isContr p (h , eq) i = (funExt⁻ (eq (~ i)) , λ j → eq (~ i ∨ j))
funExt-isEquiv : isEquiv funExt
equiv-proof funExt-isEquiv p = (fib p , funExt-fiber-isContr p)
funExtEquiv : (∀ x → f x ≡ g x) ≃ (f ≡ g)
funExtEquiv = (funExt {B = B} , funExt-isEquiv)
funExtPath : (∀ x → f x ≡ g x) ≡ (f ≡ g)
funExtPath = ua funExtEquiv
-- Function extensionality for binary functions
funExt₂ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{f g : (x : A) → (y : B x) → C x y}
→ ((x : A) (y : B x) → f x y ≡ g x y) → f ≡ g
funExt₂ p i x y = p x y i
-- Function extensionality for binary functions is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{f g : (x : A) → (y : B x) → C x y} where
private
appl₂ : f ≡ g → ∀ x y → f x y ≡ g x y
appl₂ eq x y i = eq i x y
fib : (p : f ≡ g) → fiber funExt₂ p
fib p = (appl₂ p , refl)
funExt₂-fiber-isContr : (p : f ≡ g) → (fi : fiber funExt₂ p) → fib p ≡ fi
funExt₂-fiber-isContr p (h , eq) i = (appl₂ (eq (~ i)) , λ j → eq (~ i ∨ j))
funExt₂-isEquiv : isEquiv funExt₂
equiv-proof funExt₂-isEquiv p = (fib p , funExt₂-fiber-isContr p)
funExt₂Equiv : (∀ x y → f x y ≡ g x y) ≃ (f ≡ g)
funExt₂Equiv = (funExt₂ , funExt₂-isEquiv)
funExt₂Path : (∀ x y → f x y ≡ g x y) ≡ (f ≡ g)
funExt₂Path = ua funExt₂Equiv
-- Function extensionality for ternary functions
funExt₃ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{D : (x : A) → (y : B x) → C x y → Type ℓ₃}
{f g : (x : A) → (y : B x) → (z : C x y) → D x y z}
→ ((x : A) (y : B x) (z : C x y) → f x y z ≡ g x y z) → f ≡ g
funExt₃ p i x y z = p x y z i
-- Function extensionality for ternary functions is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{D : (x : A) → (y : B x) → C x y → Type ℓ₃}
{f g : (x : A) → (y : B x) → (z : C x y) → D x y z} where
private
appl₃ : f ≡ g → ∀ x y z → f x y z ≡ g x y z
appl₃ eq x y z i = eq i x y z
fib : (p : f ≡ g) → fiber funExt₃ p
fib p = (appl₃ p , refl)
funExt₃-fiber-isContr : (p : f ≡ g) → (fi : fiber funExt₃ p) → fib p ≡ fi
funExt₃-fiber-isContr p (h , eq) i = (appl₃ (eq (~ i)) , λ j → eq (~ i ∨ j))
funExt₃-isEquiv : isEquiv funExt₃
equiv-proof funExt₃-isEquiv p = (fib p , funExt₃-fiber-isContr p)
funExt₃Equiv : (∀ x y z → f x y z ≡ g x y z) ≃ (f ≡ g)
funExt₃Equiv = (funExt₃ , funExt₃-isEquiv)
funExt₃Path : (∀ x y z → f x y z ≡ g x y z) ≡ (f ≡ g)
funExt₃Path = ua funExt₃Equiv
-- Puzzle: Can one generalize this to n-ary functions?
| 34.5
| 81
| 0.543793
|
3d3c79a681db018ee58ea8b7a9c4a23b8432d79c
| 25,358
|
agda
|
Agda
|
Cubical/Homotopy/Group/Base.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Group/Base.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Group/Base.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.Base where
open import Cubical.Homotopy.Loopspace
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Functions.Morphism
open import Cubical.HITs.SetTruncation
renaming (rec to sRec ; rec2 to sRec2
; elim to sElim ; elim2 to sElim2 ; elim3 to sElim3
; map to sMap)
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.HITs.S1
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Algebra.Group
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open Iso
open IsGroup
open IsSemigroup
open IsMonoid
open GroupStr
{- Homotopy group -}
π : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Type ℓ
π n A = ∥ typ ((Ω^ n) A) ∥₂
{- Alternative formulation. This will be given a group structure in
the Properties file -}
π' : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Type ℓ
π' n A = ∥ S₊∙ n →∙ A ∥₂
{- π as a group -}
1π : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π n A
1π zero {A = A} = ∣ pt A ∣₂
1π (suc n) = ∣ refl ∣₂
·π : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π (suc n) A → π (suc n) A → π (suc n) A
·π n = sRec2 squash₂ λ p q → ∣ p ∙ q ∣₂
-π : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π (suc n) A → π (suc n) A
-π n = sMap sym
π-rUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n x (1π (suc n))) ≡ x
π-rUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ rUnit p (~ i) ∣₂
π-lUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n (1π (suc n)) x) ≡ x
π-lUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ lUnit p (~ i) ∣₂
π-rCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n x (-π n x)) ≡ 1π (suc n)
π-rCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ rCancel p i ∣₂
π-lCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n (-π n x) x) ≡ 1π (suc n)
π-lCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ lCancel p i ∣₂
π-assoc : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y z : π (suc n) A)
→ ·π n x (·π n y z) ≡ ·π n (·π n x y) z
π-assoc n = sElim3 (λ _ _ _ → isSetPathImplicit) λ p q r i → ∣ ∙assoc p q r i ∣₂
π-comm : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y : π (suc (suc n)) A)
→ ·π (suc n) x y ≡ ·π (suc n) y x
π-comm n = sElim2 (λ _ _ → isSetPathImplicit) λ p q i → ∣ EH n p q i ∣₂
-- πₙ₊₁
πGr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Group ℓ
fst (πGr n A) = π (suc n) A
1g (snd (πGr n A)) = 1π (suc n)
GroupStr._·_ (snd (πGr n A)) = ·π n
inv (snd (πGr n A)) = -π n
is-set (isSemigroup (isMonoid (isGroup (snd (πGr n A))))) = squash₂
assoc (isSemigroup (isMonoid (isGroup (snd (πGr n A))))) = π-assoc n
identity (isMonoid (isGroup (snd (πGr n A)))) x = (π-rUnit n x) , (π-lUnit n x)
inverse (isGroup (snd (πGr n A))) x = (π-rCancel n x) , (π-lCancel n x)
-- Group operations on π'.
-- We define the corresponding structure on the untruncated
-- (S₊∙ n →∙ A).
∙Π : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (S₊∙ n →∙ A)
→ (S₊∙ n →∙ A)
→ (S₊∙ n →∙ A)
∙Π {A = A} {n = zero} p q = (λ _ → pt A) , refl
fst (∙Π {A = A} {n = suc zero} (f , p) (g , q)) base = pt A
fst (∙Π {A = A} {n = suc zero} (f , p) (g , q)) (loop j) =
((sym p ∙∙ cong f loop ∙∙ p) ∙ (sym q ∙∙ cong g loop ∙∙ q)) j
snd (∙Π {A = A} {n = suc zero} (f , p) (g , q)) = refl
fst (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) north = pt A
fst (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) south = pt A
fst (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) (merid a j) =
((sym p ∙∙ cong f (merid a ∙ sym (merid (ptSn (suc n)))) ∙∙ p)
∙ (sym q ∙∙ cong g (merid a ∙ sym (merid (ptSn (suc n)))) ∙∙ q)) j
snd (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) = refl
-Π : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (S₊∙ n →∙ A)
→ (S₊∙ n →∙ A)
-Π {n = zero} f = f
fst (-Π {A = A} {n = suc zero} f) base = fst f base
fst (-Π {A = A} {n = suc zero} f) (loop j) = fst f (loop (~ j))
snd (-Π {A = A} {n = suc zero} f) = snd f
fst (-Π {A = A} {n = suc (suc n)} f) north = fst f north
fst (-Π {A = A} {n = suc (suc n)} f) south = fst f north
fst (-Π {A = A} {n = suc (suc n)} f) (merid a j) =
fst f ((merid a ∙ sym (merid (ptSn _))) (~ j))
snd (-Π {A = A} {n = suc (suc n)} f) = snd f
-- to prove that this gives a group structure on π', we first
-- prove that Ωⁿ A ≃ (Sⁿ →∙ A).
-- We use the following map
mutual
Ω→SphereMap : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ typ ((Ω^ n) A) → (S₊∙ n →∙ A)
fst (Ω→SphereMap zero a) false = a
fst (Ω→SphereMap zero {A = A} a) true = pt A
snd (Ω→SphereMap zero a) = refl
fst (Ω→SphereMap (suc zero) {A = A} p) base = pt A
fst (Ω→SphereMap (suc zero) p) (loop i) = p i
snd (Ω→SphereMap (suc zero) p) = refl
fst (Ω→SphereMap (suc (suc n)) {A = A} p) north = pt A
fst (Ω→SphereMap (suc (suc n)) {A = A} p) south = pt A
fst (Ω→SphereMap (suc (suc n)) p) (merid a i) =
(sym (Ω→SphereMapId (suc n) a)
∙∙ (λ i → Ω→SphereMap (suc n) (p i) .fst a)
∙∙ Ω→SphereMapId (suc n) a) i
snd (Ω→SphereMap (suc (suc n)) p) = refl
Ω→SphereMapId : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (a : _)
→ Ω→SphereMap n {A = A} (pt ((Ω^ n) A)) .fst a ≡ pt A
Ω→SphereMapId zero false = refl
Ω→SphereMapId zero true = refl
Ω→SphereMapId (suc zero) base = refl
Ω→SphereMapId (suc zero) (loop i) = refl
Ω→SphereMapId (suc (suc n)) north = refl
Ω→SphereMapId (suc (suc n)) south = refl
Ω→SphereMapId (suc (suc n)) {A = A} (merid a i) j =
∙∙lCancel (Ω→SphereMapId (suc n) {A = A} a) j i
Ω→SphereMapId2 : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ Ω→SphereMap n {A = A} (pt ((Ω^ n) A)) ≡ ((λ _ → pt A) , refl)
fst (Ω→SphereMapId2 n {A = A} i) a = funExt (Ω→SphereMapId n {A = A}) i a
snd (Ω→SphereMapId2 zero {A = A} i) = refl
snd (Ω→SphereMapId2 (suc zero) {A = A} i) = refl
snd (Ω→SphereMapId2 (suc (suc n)) {A = A} i) = refl
-- Pointed version
Ω→SphereMap∙ : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ ((Ω^ n) A) →∙ (S₊∙ n →∙ A ∙)
Ω→SphereMap∙ n .fst = Ω→SphereMap n
Ω→SphereMap∙ n .snd = Ω→SphereMapId2 n
-- We define the following maps which will be used to
-- show that Ω→SphereMap is an equivalence
Ω→SphereMapSplit₁ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ typ ((Ω^ (suc n)) A)
→ typ (Ω (S₊∙ n →∙ A ∙))
Ω→SphereMapSplit₁ n = Ω→ (Ω→SphereMap∙ n) .fst
ΩSphereMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ typ (Ω (S₊∙ n →∙ A ∙))
→ (S₊∙ (suc n) →∙ A)
fst (ΩSphereMap {A = A} zero p) base = p i0 .fst false
fst (ΩSphereMap {A = A} zero p) (loop i) = p i .fst false
snd (ΩSphereMap {A = A} zero p) = refl
ΩSphereMap {A = A} (suc n) = fun IsoΩFunSuspFun
-- Functoriality
-- The homogeneity assumption is not necessary but simplifying
isNaturalΩSphereMap : ∀ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ')
(homogB : isHomogeneous B) (f : A →∙ B) (n : ℕ)
→ ∀ g → f ∘∙ ΩSphereMap n g ≡ ΩSphereMap n (Ω→ (post∘∙ (S₊∙ n) f) .fst g)
isNaturalΩSphereMap A B homogB f 0 g =
→∙Homogeneous≡ homogB (funExt lem)
where
lem : ∀ x → f .fst (ΩSphereMap 0 g .fst x)
≡ ΩSphereMap 0 (Ω→ (post∘∙ (S₊∙ 0) f) .fst g) .fst x
lem base = f .snd
lem (loop i) j =
hfill
(λ j → λ
{ (i = i0) → post∘∙ _ f .snd j
; (i = i1) → post∘∙ _ f .snd j
})
(inS (f ∘∙ g i))
j .fst false
isNaturalΩSphereMap A B homogB f (n@(suc _)) g =
→∙Homogeneous≡ homogB (funExt lem)
where
lem : ∀ x → f .fst (ΩSphereMap n g .fst x)
≡ ΩSphereMap n (Ω→ (post∘∙ (S₊∙ n) f) .fst g) .fst x
lem north = f .snd
lem south = f .snd
lem (merid a i) j =
hfill
(λ j → λ
{ (i = i0) → post∘∙ _ f .snd j
; (i = i1) → post∘∙ _ f .snd j
})
(inS (f ∘∙ g i))
j .fst a
SphereMapΩ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (S₊∙ (suc n) →∙ A)
→ typ (Ω (S₊∙ n →∙ A ∙))
SphereMapΩ {A = A} zero (f , p) =
ΣPathP ((funExt λ { false → sym p ∙∙ cong f loop ∙∙ p
; true → refl})
, refl)
SphereMapΩ {A = A} (suc n) = inv IsoΩFunSuspFun
SphereMapΩIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (S₊∙ (suc n) →∙ A)
(typ (Ω (S₊∙ n →∙ A ∙)))
fun (SphereMapΩIso n) = SphereMapΩ n
inv (SphereMapΩIso n) = ΩSphereMap n
fst (rightInv (SphereMapΩIso zero) f i j) false = rUnit (λ j → fst (f j) false) (~ i) j
fst (rightInv (SphereMapΩIso {A = A} zero) f i j) true = snd (f j) (~ i)
snd (rightInv (SphereMapΩIso {A = A} zero) f i j) k = snd (f j) (~ i ∨ k)
rightInv (SphereMapΩIso (suc n)) = leftInv IsoΩFunSuspFun
leftInv (SphereMapΩIso zero) f =
ΣPathP ((funExt (λ { base → sym (snd f)
; (loop i) j → doubleCompPath-filler
(sym (snd f))
(cong (fst f) loop)
(snd f) (~ j) i}))
, λ i j → snd f (~ i ∨ j))
leftInv (SphereMapΩIso (suc n)) = rightInv IsoΩFunSuspFun
{-
In order to show that Ω→SphereMap is an equivalence, we show that it factors
Ω→SphereMapSplit₁ ΩSphereMap
Ωⁿ⁺¹(Sⁿ →∙ A) ----------------> Ω (Sⁿ →∙ A) -----------> (Sⁿ⁺¹ →∙ A)
-}
Ω→SphereMap-split : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p : typ ((Ω^ (suc n)) A))
→ Ω→SphereMap (suc n) p ≡ ΩSphereMap n (Ω→SphereMapSplit₁ n p)
Ω→SphereMap-split {A = A} zero p =
ΣPathP ((funExt (λ { base → refl
; (loop i) j → lem (~ j) i}))
, refl)
where
lem : funExt⁻ (cong fst (Ω→SphereMapSplit₁ zero p)) false ≡ p
lem = (λ i → funExt⁻ (cong-∙∙ fst (sym (Ω→SphereMapId2 zero))
(cong (Ω→SphereMap zero) p)
(Ω→SphereMapId2 zero) i) false)
∙ sym (rUnit _)
Ω→SphereMap-split {A = A} (suc n) p =
ΣPathP ((funExt (λ { north → refl
; south → refl
; (merid a i) j → lem₂ a j i}))
, refl)
where
lem : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (a : S₊ (suc n))
→ Ω→SphereMapId (suc n) {A = A} a
≡ (λ i → fst (Ω→SphereMapId2 (suc n) {A = A} i) a)
lem zero base = refl
lem zero (loop i) = refl
lem (suc n) north = refl
lem (suc n) south = refl
lem (suc n) (merid a i) = refl
lem₂ : (a : S₊ (suc n))
→ ((λ i₁ → Ω→SphereMapId (suc n) {A = A} a (~ i₁))
∙∙ (λ i₁ → Ω→SphereMap (suc n) (p i₁) .fst a)
∙∙ Ω→SphereMapId (suc n) a)
≡ (λ i → Ω→SphereMapSplit₁ (suc n) p i .fst a)
lem₂ a = cong (λ x → sym x
∙∙ funExt⁻ (cong fst (λ i → Ω→SphereMap (suc n) (p i))) a
∙∙ x)
(lem n a)
∙∙ sym (cong-∙∙ (λ x → x a)
(cong fst (λ i → Ω→SphereMapId2 (suc n) (~ i)))
(cong fst (λ i → Ω→SphereMap (suc n) (p i)))
(cong fst (Ω→SphereMapId2 (suc n))))
∙∙ (λ i → funExt⁻ (cong-∙∙ fst (sym (Ω→SphereMapId2 (suc n)))
(cong (Ω→SphereMap (suc n)) p)
(Ω→SphereMapId2 (suc n)) (~ i)) a)
isEquiv-Ω→SphereMap₀ : ∀ {ℓ} {A : Pointed ℓ}
→ isEquiv (Ω→SphereMap 0 {A = A})
isEquiv-Ω→SphereMap₀ {A = A} =
isoToIsEquiv
(iso _ (λ f → fst f false)
(λ f → ΣPathP ((funExt (λ { false → refl ; true → sym (snd f)}))
, λ i j → snd f (~ i ∨ j)))
λ p → refl)
isEquiv-Ω→SphereMap : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ isEquiv (Ω→SphereMap n {A = A})
isEquiv-Ω→SphereMap zero {A = A} =
(isoToIsEquiv
(iso _ (λ f → fst f false)
(λ f → ΣPathP ((funExt (λ { false → refl
; true → sym (snd f)}))
, λ i j → snd f (~ i ∨ j)))
λ _ → refl))
isEquiv-Ω→SphereMap (suc zero) {A = A} =
isoToIsEquiv (iso _ invFun sec λ p → sym (rUnit p))
where
invFun : S₊∙ 1 →∙ A → typ (Ω A)
invFun (f , p) = sym p ∙∙ cong f loop ∙∙ p
sec : section (Ω→SphereMap 1) invFun
sec (f , p) =
ΣPathP ((funExt (λ { base → sym p
; (loop i) j → doubleCompPath-filler
(sym p) (cong f loop) p (~ j) i}))
, λ i j → p (~ i ∨ j))
isEquiv-Ω→SphereMap (suc (suc n)) =
subst isEquiv (sym (funExt (Ω→SphereMap-split (suc n))))
(snd (compEquiv
((Ω→SphereMapSplit₁ (suc n)) ,
(isEquivΩ→ (Ω→SphereMap (suc n) , Ω→SphereMapId2 (suc n))
(isEquiv-Ω→SphereMap (suc n))))
(invEquiv (isoToEquiv (SphereMapΩIso (suc n))))))
IsoΩSphereMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (typ ((Ω^ n) A)) (S₊∙ n →∙ A)
IsoΩSphereMap n = equivToIso (_ , isEquiv-Ω→SphereMap n)
IsoSphereMapΩ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (S₊∙ n →∙ A) (fst ((Ω^ n) A))
IsoSphereMapΩ {A = A} n =
invIso (IsoΩSphereMap n)
SphereMap→Ω : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ S₊∙ n →∙ A → fst ((Ω^ n) A)
SphereMap→Ω n = fun (IsoSphereMapΩ n)
isHom-Ω→SphereMap : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (p q : _)
→ Ω→SphereMap (suc n) {A = A} (p ∙ q)
≡ ∙Π (Ω→SphereMap (suc n) {A = A} p)
(Ω→SphereMap (suc n) {A = A} q)
isHom-Ω→SphereMap zero {A = A} p q =
ΣPathP ((funExt (λ { base → refl
; (loop i) j → (rUnit p j ∙ rUnit q j) i}))
, refl)
isHom-Ω→SphereMap (suc n) {A = A} p q =
ΣPathP ((funExt (λ { north → refl
; south → refl
; (merid a i) j → main a j i}))
, refl)
where
doubleComp-lem : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) (q r : y ≡ y)
→ (p ∙∙ q ∙∙ sym p) ∙ (p ∙∙ r ∙∙ sym p)
≡ (p ∙∙ (q ∙ r) ∙∙ sym p)
doubleComp-lem p q r i j =
hcomp (λ k → λ { (i = i0) → (doubleCompPath-filler p q (sym p) k
∙ doubleCompPath-filler p r (sym p) k) j
; (i = i1) → doubleCompPath-filler p (q ∙ r) (sym p) k j
; (j = i0) → p (~ k)
; (j = i1) → p (~ k)})
((q ∙ r) j)
lem : (p : typ ((Ω^ (suc (suc n))) A))
→ cong (fst (Ω→SphereMap (suc (suc n)) p)) (merid (ptSn _)) ≡ refl
lem p =
cong (sym (Ω→SphereMapId (suc n) (ptSn _)) ∙∙_∙∙ Ω→SphereMapId (suc n) (ptSn _))
(rUnit _ ∙ (λ j → (λ i → Ω→SphereMap (suc n) {A = A} refl .snd (i ∧ j))
∙∙ (λ i → Ω→SphereMap (suc n) {A = A} (p i) .snd j)
∙∙ λ i → Ω→SphereMap (suc n) {A = A} refl .snd (~ i ∧ j))
∙ ∙∙lCancel _)
∙ ∙∙lCancel _
main : (a : S₊ (suc n))
→ sym (Ω→SphereMapId (suc n) a)
∙∙ funExt⁻ (cong fst (cong (Ω→SphereMap (suc n)) (p ∙ q))) a
∙∙ Ω→SphereMapId (suc n) a
≡ cong (fst (∙Π (Ω→SphereMap (suc (suc n)) p) (Ω→SphereMap (suc (suc n)) q))) (merid a)
main a = (cong (sym (Ω→SphereMapId (suc n) a) ∙∙_∙∙ (Ω→SphereMapId (suc n) a))
(cong-∙ (λ x → Ω→SphereMap (suc n) x .fst a) p q)
∙ sym (doubleComp-lem (sym (Ω→SphereMapId (suc n) a)) _ _))
∙∙ cong₂ _∙_ (sym (cong (cong (fst (Ω→SphereMap (suc (suc n)) p)) (merid a) ∙_)
(cong sym (lem p)) ∙ sym (rUnit _)))
(sym (cong (cong (fst (Ω→SphereMap (suc (suc n)) q)) (merid a) ∙_)
(cong sym (lem q)) ∙ sym (rUnit _)))
∙∙ λ i → (rUnit (cong-∙ (fst (Ω→SphereMap (suc (suc n)) p))
(merid a) (sym (merid (ptSn _))) (~ i)) i)
∙ (rUnit (cong-∙ (fst (Ω→SphereMap (suc (suc n)) q))
(merid a) (sym (merid (ptSn _)))(~ i)) i)
-- The iso is structure preserving
IsoSphereMapΩ-pres∙Π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f g : S₊∙ (suc n) →∙ A)
→ SphereMap→Ω (suc n) (∙Π f g)
≡ SphereMap→Ω (suc n) f ∙ SphereMap→Ω (suc n) g
IsoSphereMapΩ-pres∙Π n =
morphLemmas.isMorphInv _∙_ ∙Π (Ω→SphereMap (suc n))
(isHom-Ω→SphereMap n)
(SphereMap→Ω (suc n))
(leftInv (IsoSphereMapΩ (suc n)))
(rightInv (IsoSphereMapΩ (suc n)))
-- It is useful to define the ``Group Structure'' on (S₊∙ n →∙ A)
-- before doing it on π'. These will be the equivalents of the
-- usual groupoid laws on Ω A.
1Π : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ} → (S₊∙ n →∙ A)
fst (1Π {A = A}) _ = pt A
snd (1Π {A = A}) = refl
∙Π-rUnit : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π f 1Π ≡ f
fst (∙Π-rUnit {A = A} {n = zero} f i) base = snd f (~ i)
fst (∙Π-rUnit {A = A} {n = zero} f i) (loop j) = help i j
where
help : PathP (λ i → snd f (~ i) ≡ snd f (~ i))
(((sym (snd f)) ∙∙ (cong (fst f) loop) ∙∙ snd f)
∙ (refl ∙ refl))
(cong (fst f) loop)
help = (cong ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f) ∙_)
(sym (rUnit refl)) ∙ sym (rUnit _))
◁ λ i j → doubleCompPath-filler (sym (snd f))
(cong (fst f) loop) (snd f) (~ i) j
snd (∙Π-rUnit {A = A} {n = zero} f i) j = snd f (~ i ∨ j)
fst (∙Π-rUnit {A = A} {n = suc n} f i) north = snd f (~ i)
fst (∙Π-rUnit {A = A} {n = suc n} f i) south =
(sym (snd f) ∙ cong (fst f) (merid (ptSn (suc n)))) i
fst (∙Π-rUnit {A = A} {n = suc n} f i) (merid a j) = help i j
where
help : PathP (λ i → snd f (~ i)
≡ (sym (snd f) ∙ cong (fst f) (merid (ptSn (suc n)))) i)
(((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f)
∙ (refl ∙ refl))
(cong (fst f) (merid a))
help = (cong (((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f) ∙_)
(sym (rUnit refl))
∙ sym (rUnit _))
◁ λ i j → hcomp (λ k →
λ { (j = i0) → snd f (~ i ∧ k)
; (j = i1) → compPath-filler' (sym (snd f))
(cong (fst f) (merid (ptSn (suc n)))) k i
; (i = i0) → doubleCompPath-filler (sym (snd f))
(cong (fst f)
(merid a ∙ sym (merid (ptSn (suc n)))))
(snd f) k j
; (i = i1) → fst f (merid a j)})
(fst f (compPath-filler (merid a)
(sym (merid (ptSn _))) (~ i) j))
snd (∙Π-rUnit {A = A} {n = suc n} f i) j = snd f (~ i ∨ j)
∙Π-lUnit : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π 1Π f ≡ f
fst (∙Π-lUnit {n = zero} f i) base = snd f (~ i)
fst (∙Π-lUnit {n = zero} f i) (loop j) = s i j
where
s : PathP (λ i → snd f (~ i) ≡ snd f (~ i))
((refl ∙ refl) ∙ (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f))
(cong (fst f) loop)
s = (cong (_∙ (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f))
(sym (rUnit refl)) ∙ sym (lUnit _))
◁ λ i j → doubleCompPath-filler (sym (snd f))
(cong (fst f) loop) (snd f) (~ i) j
snd (∙Π-lUnit {n = zero} f i) j = snd f (~ i ∨ j)
fst (∙Π-lUnit {n = suc n} f i) north = snd f (~ i)
fst (∙Π-lUnit {n = suc n} f i) south =
(sym (snd f) ∙ cong (fst f) (merid (ptSn _))) i
fst (∙Π-lUnit {n = suc n} f i) (merid a j) = help i j
where
help : PathP (λ i → snd f (~ i)
≡ (sym (snd f) ∙ cong (fst f) (merid (ptSn (suc n)))) i)
((refl ∙ refl) ∙ ((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f))
(cong (fst f) (merid a))
help =
(cong (_∙ ((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f))
(sym (rUnit refl))
∙ sym (lUnit _))
◁ λ i j → hcomp (λ k →
λ { (j = i0) → snd f (~ i ∧ k)
; (j = i1) → compPath-filler' (sym (snd f))
(cong (fst f) (merid (ptSn (suc n)))) k i
; (i = i0) → doubleCompPath-filler (sym (snd f))
(cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
(snd f) k j
; (i = i1) → fst f (merid a j)})
(fst f (compPath-filler (merid a) (sym (merid (ptSn _))) (~ i) j))
snd (∙Π-lUnit {n = suc n} f i) j = snd f (~ i ∨ j)
∙Π-rCancel : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π f (-Π f) ≡ 1Π
fst (∙Π-rCancel {A = A} {n = zero} f i) base = pt A
fst (∙Π-rCancel {A = A} {n = zero} f i) (loop j) =
rCancel (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f) i j
snd (∙Π-rCancel {A = A} {n = zero} f i) = refl
fst (∙Π-rCancel {A = A} {n = suc n} f i) north = pt A
fst (∙Π-rCancel {A = A} {n = suc n} f i) south = pt A
fst (∙Π-rCancel {A = A} {n = suc n} f i) (merid a i₁) = lem i i₁
where
pl = (sym (snd f)
∙∙ cong (fst f) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f)
lem : pl
∙ ((sym (snd f)
∙∙ cong (fst (-Π f)) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f)) ≡ refl
lem = cong (pl ∙_) (cong (sym (snd f) ∙∙_∙∙ (snd f))
(cong-∙ (fst (-Π f)) (merid a) (sym (merid (ptSn _)))
∙∙ cong₂ _∙_ refl
(cong (cong (fst f)) (rCancel (merid (ptSn _))))
∙∙ sym (rUnit _)))
∙ rCancel pl
snd (∙Π-rCancel {A = A} {n = suc n} f i) = refl
∙Π-lCancel : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π (-Π f) f ≡ 1Π
fst (∙Π-lCancel {A = A} {n = zero} f i) base = pt A
fst (∙Π-lCancel {A = A} {n = zero} f i) (loop j) =
rCancel (sym (snd f) ∙∙ cong (fst f) (sym loop) ∙∙ snd f) i j
fst (∙Π-lCancel {A = A} {n = suc n} f i) north = pt A
fst (∙Π-lCancel {A = A} {n = suc n} f i) south = pt A
fst (∙Π-lCancel {A = A} {n = suc n} f i) (merid a j) = lem i j
where
pl = (sym (snd f)
∙∙ cong (fst f) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f)
lem : (sym (snd f)
∙∙ cong (fst (-Π f)) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f) ∙ pl
≡ refl
lem = cong (_∙ pl) (cong (sym (snd f) ∙∙_∙∙ (snd f))
(cong-∙ (fst (-Π f)) (merid a) (sym (merid (ptSn _)))
∙∙ cong₂ _∙_ refl (cong (cong (fst f)) (rCancel (merid (ptSn _))))
∙∙ sym (rUnit _)))
∙ lCancel pl
snd (∙Π-lCancel {A = A} {n = zero} f i) = refl
snd (∙Π-lCancel {A = A} {n = suc n} f i) = refl
∙Π-assoc : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f g h : S₊∙ (suc n) →∙ A)
→ ∙Π f (∙Π g h) ≡ ∙Π (∙Π f g) h
∙Π-assoc {n = n} f g h =
sym (leftInv (IsoSphereMapΩ (suc n)) (∙Π f (∙Π g h)))
∙∙ cong (Ω→SphereMap (suc n)) (IsoSphereMapΩ-pres∙Π n f (∙Π g h)
∙∙ cong (SphereMap→Ω (suc n) f ∙_) (IsoSphereMapΩ-pres∙Π n g h)
∙∙ ∙assoc (SphereMap→Ω (suc n) f) (SphereMap→Ω (suc n) g) (SphereMap→Ω (suc n) h)
∙∙ cong (_∙ SphereMap→Ω (suc n) h) (sym (IsoSphereMapΩ-pres∙Π n f g))
∙∙ sym (IsoSphereMapΩ-pres∙Π n (∙Π f g) h))
∙∙ leftInv (IsoSphereMapΩ (suc n)) (∙Π (∙Π f g) h)
∙Π-comm : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f g : S₊∙ (suc (suc n)) →∙ A)
→ ∙Π f g ≡ ∙Π g f
∙Π-comm {A = A} {n = n} f g =
sym (leftInv (IsoSphereMapΩ (suc (suc n))) (∙Π f g))
∙∙ cong (Ω→SphereMap (suc (suc n))) (IsoSphereMapΩ-pres∙Π (suc n) f g
∙∙ EH _ _ _
∙∙ sym (IsoSphereMapΩ-pres∙Π (suc n) g f))
∙∙ leftInv (IsoSphereMapΩ (suc (suc n))) (∙Π g f)
{- π'' as a group -}
1π' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π' n A
1π' n {A = A} = ∣ 1Π ∣₂
·π' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π' (suc n) A → π' (suc n) A → π' (suc n) A
·π' n = sRec2 squash₂ λ p q → ∣ ∙Π p q ∣₂
-π' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π' (suc n) A → π' (suc n) A
-π' n = sMap -Π
π'-rUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n x (1π' (suc n))) ≡ x
π'-rUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-rUnit p i ∣₂
π'-lUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n (1π' (suc n)) x) ≡ x
π'-lUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-lUnit p i ∣₂
π'-rCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n x (-π' n x)) ≡ 1π' (suc n)
π'-rCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-rCancel p i ∣₂
π'-lCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n (-π' n x) x) ≡ 1π' (suc n)
π'-lCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-lCancel p i ∣₂
π'-assoc : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y z : π' (suc n) A)
→ ·π' n x (·π' n y z) ≡ ·π' n (·π' n x y) z
π'-assoc n = sElim3 (λ _ _ _ → isSetPathImplicit) λ p q r i → ∣ ∙Π-assoc p q r i ∣₂
π'-comm : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y : π' (suc (suc n)) A)
→ ·π' (suc n) x y ≡ ·π' (suc n) y x
π'-comm n = sElim2 (λ _ _ → isSetPathImplicit) λ p q i → ∣ ∙Π-comm p q i ∣₂
-- We finally get the group definition
π'Gr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Group ℓ
fst (π'Gr n A) = π' (suc n) A
1g (snd (π'Gr n A)) = 1π' (suc n)
GroupStr._·_ (snd (π'Gr n A)) = ·π' n
inv (snd (π'Gr n A)) = -π' n
is-set (isSemigroup (isMonoid (isGroup (snd (π'Gr n A))))) = squash₂
assoc (isSemigroup (isMonoid (isGroup (snd (π'Gr n A))))) = π'-assoc n
identity (isMonoid (isGroup (snd (π'Gr n A)))) x = (π'-rUnit n x) , (π'-lUnit n x)
inverse (isGroup (snd (π'Gr n A))) x = (π'-rCancel n x) , (π'-lCancel n x)
-- and finally, the Iso
π'Gr≅πGr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → GroupIso (π'Gr n A) (πGr n A)
fst (π'Gr≅πGr n A) = setTruncIso (IsoSphereMapΩ (suc n))
snd (π'Gr≅πGr n A) =
makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit)
λ p q i → ∣ IsoSphereMapΩ-pres∙Π n p q i ∣₂)
| 39.871069
| 97
| 0.486158
|
585892ca4d325640137f88710f6ea731791250b4
| 33,561
|
agda
|
Agda
|
test/LibSucceed/Issue784/Values.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/LibSucceed/Issue784/Values.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/LibSucceed/Issue784/Values.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
module Issue784.Values where
open import Data.Bool using (Bool; true; false; not)
open import Data.String public using (String; _≟_)
open import Function public
open import Data.List using (List; []; _∷_; _++_; [_]; filter) renaming (map to mapL)
open import Data.List.Any public using (Any; here; there) renaming (map to mapA; any to anyA)
open import Data.Product public using (Σ; Σ-syntax; proj₁; proj₂; _,_; _×_) renaming (map to mapΣ)
open import Data.Unit public using (⊤)
open import Data.Unit.NonEta public using (Unit; unit)
open import Data.Empty public using (⊥; ⊥-elim)
open import Relation.Binary.Core public
open import Relation.Nullary public
import Level
open import Relation.Binary.PropositionalEquality public hiding ([_]) renaming (cong to ≡-cong; cong₂ to ≡-cong₂)
open import Relation.Binary.PropositionalEquality.Core public renaming (sym to ≡-sym; trans to ≡-trans)
≢-sym : ∀ {ℓ} {A : Set ℓ} {x y : A} → x ≢ y → y ≢ x
≢-sym x≢y = x≢y ∘ ≡-sym
≡-elim : ∀ {ℓ} {X Y : Set ℓ} → X ≡ Y → X → Y
≡-elim refl p = p
≡-elim′ : ∀ {a ℓ} {A : Set a} {x y : A} → (P : A → Set ℓ) → x ≡ y → P x → P y
≡-elim′ P = ≡-elim ∘ (≡-cong P)
Named : ∀ {ℓ} (A : Set ℓ) → Set ℓ
Named A = String × A
NamedType : ∀ ℓ → Set (Level.suc ℓ)
NamedType ℓ = Named (Set ℓ)
NamedValue : ∀ ℓ → Set (Level.suc ℓ)
NamedValue ℓ = Named (Σ[ A ∈ Set ℓ ] A)
Names : Set
Names = List String
Types : ∀ ℓ → Set (Level.suc ℓ)
Types ℓ = List (NamedType ℓ)
Values : ∀ ℓ → Set (Level.suc ℓ)
Values ℓ = List (NamedValue ℓ)
names : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names
names = mapL proj₁
types : ∀ {ℓ} → Values ℓ → Types ℓ
types = mapL (mapΣ id proj₁)
infix 4 _∈_ _∉_
_∈_ : ∀ {ℓ} {A : Set ℓ} → A → List A → Set ℓ
x ∈ xs = Any (_≡_ x) xs
_∉_ : ∀ {ℓ} {A : Set ℓ} → A → List A → Set ℓ
x ∉ xs = ¬ x ∈ xs
x∉y∷l⇒x≢y : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ∉ y ∷ l → x ≢ y
x∉y∷l⇒x≢y x∉y∷l x≡y = x∉y∷l $ here x≡y
x∉y∷l⇒x∉l : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ∉ y ∷ l → x ∉ l
x∉y∷l⇒x∉l x∉y∷l x∈l = x∉y∷l $ there x∈l
x≢y⇒x∉l⇒x∉y∷l : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ≢ y → x ∉ l → x ∉ y ∷ l
x≢y⇒x∉l⇒x∉y∷l x≢y x∉l (here x≡y) = x≢y x≡y
x≢y⇒x∉l⇒x∉y∷l x≢y x∉l (there x∈l) = x∉l x∈l
infix 5 _∋!_ _∈?_
_∈?_ : (s : String) (n : Names) → Dec (s ∈ n)
s ∈? [] = no λ()
s ∈? (h ∷ t) with s ≟ h
... | yes s≡h = yes $ here s≡h
... | no s≢h with s ∈? t
... | yes s∈t = yes $ there s∈t
... | no s∉t = no $ x≢y⇒x∉l⇒x∉y∷l s≢h s∉t
_∋!_ : Names → String → Bool
l ∋! e with e ∈? l
... | yes _ = true
... | no _ = false
infix 4 _⊆_ _⊈_
_⊆_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys
_⊈_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
xs ⊈ ys = ¬ xs ⊆ ys
infixl 5 _∪_
_∪_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → List A
_∪_ = _++_
infixl 6 _∩_
_∩_ : Names → Names → Names
x ∩ y = filter (_∋!_ y) x
infixl 6 _∖_ _∖∖_
_∖_ : Names → Names → Names
_∖_ x y = filter (not ∘ _∋!_ y) x
_∖∖_ : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names → List (Named A)
_∖∖_ l n = filter (not ∘ _∋!_ n ∘ proj₁) l
filter-∈ : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names → List (Named A)
filter-∈ l n = filter (_∋!_ n ∘ proj₁) l
infixr 5 _∷_
data NonRepetitive {ℓ} {A : Set ℓ} : List A → Set ℓ where
[] : NonRepetitive []
_∷_ : ∀ {x xs} → x ∉ xs → NonRepetitive xs → NonRepetitive (x ∷ xs)
infix 4 _≋_
data _≋_ {ℓ} {A : Set ℓ} : List A → List A → Set ℓ where
refl : ∀ {l} → l ≋ l
perm : ∀ {l} l₁ x₁ x₂ l₂ → l ≋ l₁ ++ x₂ ∷ x₁ ∷ l₂ → l ≋ l₁ ++ x₁ ∷ x₂ ∷ l₂
NonRepetitiveNames : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Set
NonRepetitiveNames = NonRepetitive ∘ names
NonRepetitiveTypes : ∀ ℓ → Set (Level.suc ℓ)
NonRepetitiveTypes ℓ = Σ[ t ∈ Types ℓ ] NonRepetitiveNames t
-- lemmas
∪-assoc : ∀ {l} {A : Set l} (x y z : List A) → (x ∪ y) ∪ z ≡ x ∪ (y ∪ z)
∪-assoc [] y z = refl
∪-assoc (x ∷ xs) y z = ≡-elim′ (λ e → x ∷ e ≡ (x ∷ xs) ∪ (y ∪ z)) (≡-sym $ ∪-assoc xs y z) refl
≡⇒≋ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≡ y → x ≋ y
≡⇒≋ refl = refl
private
∈-perm : ∀ {ℓ} {A : Set ℓ} {x : A} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → x ∈ l₁ ++ e₁ ∷ e₂ ∷ l₂ → x ∈ l₁ ++ e₂ ∷ e₁ ∷ l₂
∈-perm [] e₁ e₂ l₂ (here .{e₁} .{e₂ ∷ l₂} px) = there $ here px
∈-perm [] e₁ e₂ l₂ (there .{e₁} .{e₂ ∷ l₂} (here .{e₂} .{l₂} px)) = here px
∈-perm [] e₁ e₂ l₂ (there .{e₁} .{e₂ ∷ l₂} (there .{e₂} .{l₂} pxs)) = there $ there pxs
∈-perm (h₁ ∷ t₁) e₁ e₂ l₂ (here .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} px) = here px
∈-perm (h₁ ∷ t₁) e₁ e₂ l₂ (there .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} pxs) = there $ ∈-perm t₁ e₁ e₂ l₂ pxs
≋⇒⊆ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≋ y → x ⊆ y
≋⇒⊆ refl p = p
≋⇒⊆ {x = x} {y = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} (perm l₁ x₁ x₂ l₂ p) {e} e∈x = ∈-perm l₁ x₂ x₁ l₂ $ ≋⇒⊆ p e∈x
≋-trans : ∀ {l} {A : Set l} {x y z : List A} → x ≋ y → y ≋ z → x ≋ z
≋-trans p refl = p
≋-trans p₁ (perm l₁ x₁ x₂ l₂ p₂) = perm l₁ x₁ x₂ l₂ $ ≋-trans p₁ p₂
≋-sym : ∀ {l} {A : Set l} {x y : List A} → x ≋ y → y ≋ x
≋-sym refl = refl
≋-sym (perm l₁ x₁ x₂ l₂ p) = ≋-trans (perm l₁ x₂ x₁ l₂ refl) (≋-sym p)
≋-del-ins-r : ∀ {l} {A : Set l} (l₁ : List A) (x : A) (l₂ l₃ : List A) → (l₁ ++ x ∷ l₂ ++ l₃) ≋ (l₁ ++ l₂ ++ x ∷ l₃)
≋-del-ins-r l₁ x [] l₃ = refl
≋-del-ins-r l₁ x (h ∷ t) l₃ = ≋-trans p₀ p₅
where p₀ : (l₁ ++ x ∷ h ∷ t ++ l₃) ≋ (l₁ ++ h ∷ x ∷ t ++ l₃)
p₀ = perm l₁ h x (t ++ l₃) refl
p₁ : ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ ((l₁ ++ [ h ]) ++ t ++ x ∷ l₃)
p₁ = ≋-del-ins-r (l₁ ++ [ h ]) x t l₃
p₂ : (l₁ ++ [ h ]) ++ t ++ x ∷ l₃ ≡ l₁ ++ h ∷ t ++ x ∷ l₃
p₂ = ∪-assoc l₁ [ h ] (t ++ x ∷ l₃)
p₃ : (l₁ ++ [ h ]) ++ x ∷ t ++ l₃ ≡ l₁ ++ h ∷ x ∷ t ++ l₃
p₃ = ∪-assoc l₁ [ h ] (x ∷ t ++ l₃)
p₄ : ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)
p₄ = ≡-elim′ (λ y → ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ y) p₂ p₁
p₅ : (l₁ ++ h ∷ x ∷ t ++ l₃) ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)
p₅ = ≡-elim′ (λ y → y ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)) p₃ p₄
≋-del-ins-l : ∀ {l} {A : Set l} (l₁ l₂ : List A) (x : A) (l₃ : List A) → (l₁ ++ l₂ ++ x ∷ l₃) ≋ (l₁ ++ x ∷ l₂ ++ l₃)
≋-del-ins-l l₁ l₂ x l₃ = ≋-sym $ ≋-del-ins-r l₁ x l₂ l₃
x∪[]≡x : ∀ {ℓ} {A : Set ℓ} (x : List A) → x ∪ [] ≡ x
x∪[]≡x [] = refl
x∪[]≡x (h ∷ t) = ≡-trans p₀ p₁
where p₀ : (h ∷ t) ++ [] ≡ h ∷ t ++ []
p₀ = ∪-assoc [ h ] t []
p₁ : h ∷ t ++ [] ≡ h ∷ t
p₁ = ≡-cong (λ x → h ∷ x) (x∪[]≡x t)
x∖[]≡x : (x : Names) → x ∖ [] ≡ x
x∖[]≡x [] = refl
x∖[]≡x (h ∷ t) = ≡-cong (_∷_ h) (x∖[]≡x t)
t∖[]≡t : ∀ {ℓ} {A : Set ℓ} (t : List (Named A)) → t ∖∖ [] ≡ t
t∖[]≡t [] = refl
t∖[]≡t (h ∷ t) = ≡-cong (_∷_ h) (t∖[]≡t t)
e∷x≋e∷y : ∀ {ℓ} {A : Set ℓ} (e : A) {x y : List A} → x ≋ y → e ∷ x ≋ e ∷ y
e∷x≋e∷y _ refl = refl
e∷x≋e∷y x (perm l₁ e₁ e₂ l₂ p) = perm (x ∷ l₁) e₁ e₂ l₂ (e∷x≋e∷y x p)
∪-sym : ∀ {ℓ} {A : Set ℓ} (x y : List A) → x ∪ y ≋ y ∪ x
∪-sym [] y = ≡-elim′ (λ z → y ≋ z) (≡-sym $ x∪[]≡x y) refl
∪-sym x [] = ≡-elim′ (λ z → z ≋ x) (≡-sym $ x∪[]≡x x) refl
∪-sym x (y ∷ ys) = ≡-elim′ (λ z → x ++ (y ∷ ys) ≋ z) p₃ (≋-trans p₁ p₂) where
p₁ : x ++ (y ∷ ys) ≋ y ∷ (x ++ ys)
p₁ = ≋-del-ins-l [] x y ys
p₂ : y ∷ (x ++ ys) ≋ y ∷ (ys ++ x)
p₂ = e∷x≋e∷y y $ ∪-sym x ys
p₃ : y ∷ (ys ++ x) ≡ (y ∷ ys) ++ x
p₃ = ∪-assoc [ y ] ys x
y≋ỳ⇒x∪y≋x∪ỳ : ∀ {ℓ} {A : Set ℓ} (x : List A) {y ỳ : List A} → y ≋ ỳ → x ∪ y ≋ x ∪ ỳ
y≋ỳ⇒x∪y≋x∪ỳ [] p = p
y≋ỳ⇒x∪y≋x∪ỳ (h ∷ t) p = e∷x≋e∷y h (y≋ỳ⇒x∪y≋x∪ỳ t p)
x≋x̀⇒x∪y≋x̀∪y : ∀ {ℓ} {A : Set ℓ} {x x̀ : List A} → x ≋ x̀ → (y : List A) → x ∪ y ≋ x̀ ∪ y
x≋x̀⇒x∪y≋x̀∪y {x = x} {x̀ = x̀} p y = ≋-trans (∪-sym x y) $ ≋-trans (y≋ỳ⇒x∪y≋x∪ỳ y p) (∪-sym y x̀)
x⊆y≋z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ⊆ y → y ≋ z → x ⊆ z
x⊆y≋z x⊆y refl = x⊆y
x⊆y≋z {x = x} {y = y} {z = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} x⊆y (perm l₁ x₁ x₂ l₂ p) = ∈-perm l₁ x₂ x₁ l₂ ∘ x⊆y≋z x⊆y p
x≋y⊆z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ≋ y → x ⊆ z → y ⊆ z
x≋y⊆z refl x⊆z = x⊆z
x≋y⊆z {y = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} {z = z} (perm l₁ x₁ x₂ l₂ p) x⊆z = x≋y⊆z p x⊆z ∘ ∈-perm l₁ x₁ x₂ l₂
x⊆x∪y : ∀ {ℓ} {A : Set ℓ} (x y : List A) → x ⊆ x ∪ y
x⊆x∪y .(x ∷ xs) y (here {x} {xs} px) = here px
x⊆x∪y .(x ∷ xs) y (there {x} {xs} pxs) = there $ x⊆x∪y xs y pxs
x∪y⊆z⇒x⊆z : ∀ {ℓ} {A : Set ℓ} (x y : List A) {z : List A} → x ∪ y ⊆ z → x ⊆ z
x∪y⊆z⇒x⊆z x y x∪y⊆z = x∪y⊆z ∘ x⊆x∪y x y
x∪y⊆z⇒y⊆z : ∀ {ℓ} {A : Set ℓ} (x y : List A) {z : List A} → x ∪ y ⊆ z → y ⊆ z
x∪y⊆z⇒y⊆z x y = x∪y⊆z⇒x⊆z y x ∘ x≋y⊆z (∪-sym x y)
n-x∪y : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) → names (x ∪ y) ≡ names x ∪ names y
n-x∪y [] _ = refl
n-x∪y {ℓ} (x ∷ xs) y = ≡-trans p₁ p₂ where
nx = [ proj₁ x ]
nxs = names xs
ny = names y
p₁ : nx ∪ names (xs ∪ y) ≡ nx ∪ (nxs ∪ ny)
p₁ = ≡-cong (λ z → nx ∪ z) (n-x∪y xs y)
p₂ : nx ∪ (nxs ∪ ny) ≡ (nx ∪ nxs) ∪ ny
p₂ = ≡-sym $ ∪-assoc nx nxs ny
t-x∪y : ∀ {ℓ} (x y : Values ℓ) → types (x ∪ y) ≡ types x ∪ types y
t-x∪y [] _ = refl
t-x∪y (x ∷ xs) y = ≡-trans p₁ p₂ where
nx = types [ x ]
nxs = types xs
ny = types y
p₁ : nx ∪ types (xs ∪ y) ≡ nx ∪ (nxs ∪ ny)
p₁ = ≡-cong (λ z → nx ∪ z) (t-x∪y xs y)
p₂ : nx ∪ (nxs ∪ ny) ≡ (nx ∪ nxs) ∪ ny
p₂ = ≡-sym $ ∪-assoc nx nxs ny
n-x≋y : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ≋ y → names x ≋ names y
n-x≋y refl = refl
n-x≋y (perm {x} l₁ e₁ e₂ l₂ p) = p₃ where
n-l₁e₁e₂l₂ : ∀ e₁ e₂ → names (l₁ ++ e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names [ e₂ ] ++ names l₂
n-l₁e₁e₂l₂ e₁ e₂ = ≡-trans p₁ $ ≡-trans p₂ p₃ where
p₁ : names (l₁ ++ e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names (e₁ ∷ e₂ ∷ l₂)
p₁ = n-x∪y l₁ (e₁ ∷ e₂ ∷ l₂)
p₂ : names l₁ ++ names (e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names (e₂ ∷ l₂)
p₂ = ≡-cong (λ z → names l₁ ++ z) (n-x∪y [ e₁ ] (e₂ ∷ l₂))
p₃ : names l₁ ++ names [ e₁ ] ++ names (e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names [ e₂ ] ++ names l₂
p₃ = ≡-cong (λ z → names l₁ ++ names [ e₁ ] ++ z) (n-x∪y [ e₂ ] l₂)
p₁ : names x ≋ names l₁ ++ proj₁ e₂ ∷ proj₁ e₁ ∷ names l₂
p₁ = ≡-elim′ (λ z → names x ≋ z) (n-l₁e₁e₂l₂ e₂ e₁) (n-x≋y p)
p₂ : names x ≋ names l₁ ++ proj₁ e₁ ∷ proj₁ e₂ ∷ names l₂
p₂ = perm (names l₁) (proj₁ e₁) (proj₁ e₂) (names l₂) p₁
p₃ : names x ≋ names (l₁ ++ e₁ ∷ e₂ ∷ l₂)
p₃ = ≡-elim′ (λ z → names x ≋ z) (≡-sym $ n-l₁e₁e₂l₂ e₁ e₂) p₂
n-types : ∀ {ℓ} (x : Values ℓ) → names (types x) ≡ names x
n-types [] = refl
n-types (x ∷ xs) = ≡-cong (λ z → proj₁ x ∷ z) (n-types xs)
nr-x≋y : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≋ y → NonRepetitive x → NonRepetitive y
nr-x≋y refl u = u
nr-x≋y {y = .(l₁ ++ e₁ ∷ e₂ ∷ l₂)} (perm l₁ e₁ e₂ l₂ p) u = ≋-step l₁ e₂ e₁ l₂ (nr-x≋y p u) where
∉-step : ∀ {ℓ} {A : Set ℓ} {x : A} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → x ∉ l₁ ++ e₁ ∷ e₂ ∷ l₂ → x ∉ l₁ ++ e₂ ∷ e₁ ∷ l₂
∉-step l₁ e₁ e₂ l₂ x∉l x∈l = ⊥-elim $ x∉l $ ∈-perm l₁ e₂ e₁ l₂ x∈l
≋-step : ∀ {ℓ} {A : Set ℓ} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → NonRepetitive (l₁ ++ e₁ ∷ e₂ ∷ l₂) → NonRepetitive (l₁ ++ e₂ ∷ e₁ ∷ l₂)
≋-step [] e₁ e₂ l₂ (_∷_ .{e₁} .{e₂ ∷ l₂} e₁∉e₂∷l₂ (_∷_ .{e₂} .{l₂} e₂∉l₂ pU)) = e₂∉e₁∷l₂ ∷ e₁∉l₂ ∷ pU where
e₁∉l₂ = e₁ ∉ l₂ ∋ x∉y∷l⇒x∉l e₁∉e₂∷l₂
e₂∉e₁∷l₂ = e₂ ∉ e₁ ∷ l₂ ∋ x≢y⇒x∉l⇒x∉y∷l (≢-sym $ x∉y∷l⇒x≢y e₁∉e₂∷l₂) e₂∉l₂
≋-step (h₁ ∷ t₁) e₁ e₂ l₂ (_∷_ .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} p∉ pU) = ∉-step t₁ e₁ e₂ l₂ p∉ ∷ ≋-step t₁ e₁ e₂ l₂ pU
nr-x⇒nr-t-x : ∀ {ℓ} {x : Values ℓ} → NonRepetitiveNames x → NonRepetitiveNames (types x)
nr-x⇒nr-t-x {x = x} = ≡-elim′ NonRepetitive (≡-sym $ n-types x)
n-x∖y : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → names (x ∖∖ y) ≡ names x ∖ y
n-x∖y [] _ = refl
n-x∖y (x ∷ xs) ny with not $ ny ∋! proj₁ x
... | false = n-x∖y xs ny
... | true = ≡-trans p₁ p₂ where
p₁ : names (x ∷ (xs ∖∖ ny)) ≡ proj₁ x ∷ names (xs ∖∖ ny)
p₁ = n-x∪y [ x ] (xs ∖∖ ny)
p₂ : proj₁ x ∷ names (xs ∖∖ ny) ≡ proj₁ x ∷ (names xs ∖ ny)
p₂ = ≡-cong (λ z → proj₁ x ∷ z) (n-x∖y xs ny)
t-x∖y : ∀ {ℓ} (x : Values ℓ) (y : Names) → types (x ∖∖ y) ≡ types x ∖∖ y
t-x∖y [] _ = refl
t-x∖y (x ∷ xs) ny with not $ ny ∋! proj₁ x
... | false = t-x∖y xs ny
... | true = ≡-trans p₁ p₂ where
x̀ = types [ x ]
p₁ : types (x ∷ (xs ∖∖ ny)) ≡ x̀ ∪ types (xs ∖∖ ny)
p₁ = t-x∪y [ x ] (xs ∖∖ ny)
p₂ : x̀ ∪ types (xs ∖∖ ny) ≡ x̀ ∪ (types xs ∖∖ ny)
p₂ = ≡-cong (λ z → x̀ ∪ z) (t-x∖y xs ny)
n-filter-∈ : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → names (filter-∈ x y) ≡ names x ∩ y
n-filter-∈ [] _ = refl
n-filter-∈ (x ∷ xs) ny with ny ∋! proj₁ x
... | false = n-filter-∈ xs ny
... | true = ≡-trans p₁ p₂ where
p₁ : names (x ∷ (filter-∈ xs ny)) ≡ proj₁ x ∷ names (filter-∈ xs ny)
p₁ = n-x∪y [ x ] (filter-∈ xs ny)
p₂ : proj₁ x ∷ names (filter-∈ xs ny) ≡ proj₁ x ∷ (names xs ∩ ny)
p₂ = ≡-cong (λ z → proj₁ x ∷ z) (n-filter-∈ xs ny)
t-filter-∈ : ∀ {ℓ} (x : Values ℓ) (y : Names) → types (filter-∈ x y) ≡ filter-∈ (types x) y
t-filter-∈ [] _ = refl
t-filter-∈ (x ∷ xs) ny with ny ∋! proj₁ x
... | false = t-filter-∈ xs ny
... | true = ≡-trans p₁ p₂ where
x̀ = types [ x ]
p₁ : types (x ∷ filter-∈ xs ny) ≡ x̀ ∪ types (filter-∈ xs ny)
p₁ = t-x∪y [ x ] (filter-∈ xs ny)
p₂ : x̀ ∪ types (filter-∈ xs ny) ≡ x̀ ∪ filter-∈ (types xs) ny
p₂ = ≡-cong (λ z → x̀ ∪ z) (t-filter-∈ xs ny)
[]⊆x : ∀ {ℓ} {A : Set ℓ} (x : List A) → [] ⊆ x
[]⊆x _ ()
∀x∉[] : ∀ {ℓ} {A : Set ℓ} {x : A} → x ∉ []
∀x∉[] ()
x⊆[]⇒x≡[] : ∀ {ℓ} {A : Set ℓ} {x : List A} → x ⊆ [] → x ≡ []
x⊆[]⇒x≡[] {x = []} _ = refl
x⊆[]⇒x≡[] {x = _ ∷ _} x⊆[] = ⊥-elim $ ∀x∉[] $ x⊆[] (here refl)
x∩y⊆x : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → filter-∈ x y ⊆ x
x∩y⊆x [] _ = λ()
x∩y⊆x (h ∷ t) y with y ∋! proj₁ h
... | false = there ∘ x∩y⊆x t y
... | true = f where
f : h ∷ filter-∈ t y ⊆ h ∷ t
f (here {x = .h} p) = here p
f (there {xs = .(filter-∈ t y)} p) = there $ x∩y⊆x t y p
e∈x⇒e∈y∪x : ∀ {ℓ} {A : Set ℓ} {e : A} {x : List A} (y : List A) → e ∈ x → e ∈ y ∪ x
e∈x⇒e∈y∪x [] = id
e∈x⇒e∈y∪x (h ∷ t) = there ∘ e∈x⇒e∈y∪x t
e∈x⇒e∈x∪y : ∀ {ℓ} {A : Set ℓ} {e : A} {x : List A} (y : List A) → e ∈ x → e ∈ x ∪ y
e∈x⇒e∈x∪y {e = e} {x = x} y e∈x = x⊆y≋z f (∪-sym y x) (e ∈ [ e ] ∋ here refl) where
f : [ e ] ⊆ y ∪ x
f {è} (here {x = .e} p) = ≡-elim′ (λ z → z ∈ y ∪ x) (≡-sym p) (e∈x⇒e∈y∪x y e∈x)
f (there ())
x∪y⊆x̀∪ỳ : ∀ {ℓ} {A : Set ℓ} {x x̀ y ỳ : List A} → x ⊆ x̀ → y ⊆ ỳ → x ∪ y ⊆ x̀ ∪ ỳ
x∪y⊆x̀∪ỳ {x = []} {x̀ = []} _ y⊆ỳ = y⊆ỳ
x∪y⊆x̀∪ỳ {x = []} {x̀ = _ ∷ t̀} _ y⊆ỳ = there ∘ x∪y⊆x̀∪ỳ ([]⊆x t̀) y⊆ỳ
x∪y⊆x̀∪ỳ {x = h ∷ t} {x̀ = x̀} {y = y} {ỳ = ỳ} x⊆x̀ y⊆ỳ = f where
f : (h ∷ t) ∪ y ⊆ x̀ ∪ ỳ
f {e} (here {x = .h} e≡h) = e∈x⇒e∈x∪y ỳ (x⊆x̀ $ here e≡h)
f {e} (there {xs = .(t ∪ y)} p) = x∪y⊆x̀∪ỳ (x∪y⊆z⇒y⊆z [ h ] t x⊆x̀) y⊆ỳ p
x∖y⊆x : (x y : Names) → x ∖ y ⊆ x
x∖y⊆x [] _ = λ()
x∖y⊆x (h ∷ t) y with y ∋! h
... | true = there ∘ x∖y⊆x t y
... | false = x∪y⊆x̀∪ỳ (≋⇒⊆ $ ≡⇒≋ $ refl {x = [ h ]}) (x∖y⊆x t y)
t≋t∖n∪t∩n : ∀ {ℓ} {A : Set ℓ} (t : List (Named A)) (n : Names) → t ≋ (t ∖∖ n) ∪ filter-∈ t n
t≋t∖n∪t∩n [] _ = refl
t≋t∖n∪t∩n (h ∷ t) n with n ∋! proj₁ h
... | false = e∷x≋e∷y h $ t≋t∖n∪t∩n t n
... | true = ≋-trans p₁ p₂ where
p₁ : h ∷ t ≋ (h ∷ (t ∖∖ n)) ∪ filter-∈ t n
p₁ = e∷x≋e∷y h $ t≋t∖n∪t∩n t n
p₂ : (h ∷ (t ∖∖ n)) ∪ filter-∈ t n ≋ (t ∖∖ n) ∪ (h ∷ filter-∈ t n)
p₂ = ≋-del-ins-r [] h (t ∖∖ n) (filter-∈ t n)
e₁∈x⇒e₂∉x⇒e≢e₂ : ∀ {ℓ} {A : Set ℓ} {e₁ e₂ : A} {x : List A} → e₁ ∈ x → e₂ ∉ x → e₁ ≢ e₂
e₁∈x⇒e₂∉x⇒e≢e₂ e₁∈x e₂∉x refl = e₂∉x e₁∈x
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x : ∀ {ℓ} {A : Set ℓ} {e₁ e₂ : A} {x : List A} → e₁ ∈ e₂ ∷ x → e₁ ≢ e₂ → e₁ ∈ x
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (here e₁≡e₂) e₁≢e₂ = ⊥-elim $ e₁≢e₂ e₁≡e₂
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (there e₁∈x) _ = e₁∈x
x⊆e∷y⇒e∉x⇒x⊆y : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → x ⊆ e ∷ y → e ∉ x → x ⊆ y
x⊆e∷y⇒e∉x⇒x⊆y {e = e} {x = x} {y = y} x⊆e∷y e∉x {è} è∈x = e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (x⊆e∷y è∈x) (e₁∈x⇒e₂∉x⇒e≢e₂ è∈x e∉x)
n-e∉l⇒e∉l : ∀ {ℓ} {A : Set ℓ} {e : Named A} {l : List (Named A)} → proj₁ e ∉ names l → e ∉ l
n-e∉l⇒e∉l {e = e} n-e∉l (here {x = è} p) = ⊥-elim $ n-e∉l $ here $ ≡-cong proj₁ p
n-e∉l⇒e∉l n-e∉l (there p) = n-e∉l⇒e∉l (x∉y∷l⇒x∉l n-e∉l) p
nr-names⇒nr : ∀ {ℓ} {A : Set ℓ} {l : List (Named A)} → NonRepetitiveNames l → NonRepetitive l
nr-names⇒nr {l = []} [] = []
nr-names⇒nr {l = _ ∷ _} (nh∉nt ∷ nr-t) = n-e∉l⇒e∉l nh∉nt ∷ nr-names⇒nr nr-t
e∉x⇒e∉y⇒e∉x∪y : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → e ∉ x → e ∉ y → e ∉ x ∪ y
e∉x⇒e∉y⇒e∉x∪y {x = []} _ e∉y e∈y = ⊥-elim $ e∉y e∈y
e∉x⇒e∉y⇒e∉x∪y {x = h ∷ t} e∉x e∉y (here e≡h) = ⊥-elim $ e∉x $ here e≡h
e∉x⇒e∉y⇒e∉x∪y {x = h ∷ t} e∉x e∉y (there e∈t∪y) = e∉x⇒e∉y⇒e∉x∪y (x∉y∷l⇒x∉l e∉x) e∉y e∈t∪y
nr-x∖y∪y : {x y : Names} → NonRepetitive x → NonRepetitive y → NonRepetitive (x ∖ y ∪ y)
nr-x∖y∪y {x = []} _ nr-y = nr-y
nr-x∖y∪y {x = x ∷ xs} {y = y} (x∉xs ∷ nr-xs) nr-y with x ∈? y
... | yes x∈y = nr-x∖y∪y nr-xs nr-y
... | no x∉y = e∉x⇒e∉y⇒e∉x∪y (⊥-elim ∘ x∉xs ∘ x∖y⊆x xs y) x∉y ∷ nr-x∖y∪y nr-xs nr-y
e∉l∖[e] : (e : String) (l : Names) → e ∉ l ∖ [ e ]
e∉l∖[e] _ [] = λ()
e∉l∖[e] e (h ∷ t) with h ≟ e
... | yes _ = e∉l∖[e] e t
... | no h≢e = x≢y⇒x∉l⇒x∉y∷l (≢-sym h≢e) (e∉l∖[e] e t)
e∉l⇒l∖e≡l : {e : String} {l : Names} → e ∉ l → l ∖ [ e ] ≡ l
e∉l⇒l∖e≡l {e = e} {l = []} _ = refl
e∉l⇒l∖e≡l {e = e} {l = h ∷ t} e∉l with h ∈? [ e ]
... | yes h∈e = ⊥-elim $ x≢y⇒x∉l⇒x∉y∷l (≢-sym $ x∉y∷l⇒x≢y e∉l) (λ()) h∈e
... | no h∉e = ≡-cong (_∷_ h) (e∉l⇒l∖e≡l $ x∉y∷l⇒x∉l e∉l)
e∈l⇒nr-l⇒l∖e∪e≋l : {e : String} {l : Names} → e ∈ l → NonRepetitive l → l ∖ [ e ] ∪ [ e ] ≋ l
e∈l⇒nr-l⇒l∖e∪e≋l {l = []} () _
e∈l⇒nr-l⇒l∖e∪e≋l {e = e} {l = h ∷ t} e∈h∷t (h∉t ∷ nr-t) with h ∈? [ e ]
... | yes (here h≡e) = ≋-trans (≡⇒≋ $ ≡-trans p₁ p₂) (∪-sym t [ h ]) where
p₁ : t ∖ [ e ] ∪ [ e ] ≡ t ∖ [ h ] ∪ [ h ]
p₁ = ≡-cong (λ x → t ∖ [ x ] ∪ [ x ]) (≡-sym h≡e)
p₂ : t ∖ [ h ] ∪ [ h ] ≡ t ∪ [ h ]
p₂ = ≡-cong (λ x → x ∪ [ h ]) (e∉l⇒l∖e≡l h∉t)
... | yes (there ())
... | no h∉e with e∈h∷t
... | here e≡h = ⊥-elim ∘ h∉e ∘ here ∘ ≡-sym $ e≡h
... | there e∈t = e∷x≋e∷y _ $ e∈l⇒nr-l⇒l∖e∪e≋l e∈t nr-t
nr-x∖y : {x : Names} → NonRepetitive x → (y : Names) → NonRepetitive (x ∖ y)
nr-x∖y {x = []} _ _ = []
nr-x∖y {x = x ∷ xs} (x∉xs ∷ nr-xs) y with x ∈? y
... | yes x∈y = nr-x∖y nr-xs y
... | no x∉y = ⊥-elim ∘ x∉xs ∘ x∖y⊆x xs y ∷ nr-x∖y nr-xs y
x⊆y⇒e∉y⇒e∉x : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → x ⊆ y → e ∉ y → e ∉ x
x⊆y⇒e∉y⇒e∉x x⊆y e∉y e∈x = e∉y $ x⊆y e∈x
e∈n-l⇒∃è,n-è≡e×è∈l : ∀ {ℓ} {A : Set ℓ} {e : String} {l : List (Named A)} → e ∈ names l → Σ[ è ∈ Named A ] (e ≡ proj₁ è × è ∈ l)
e∈n-l⇒∃è,n-è≡e×è∈l {l = []} ()
e∈n-l⇒∃è,n-è≡e×è∈l {l = h ∷ t} (here e≡n-h) = h , e≡n-h , here refl
e∈n-l⇒∃è,n-è≡e×è∈l {l = h ∷ t} (there e∈n-t) with e∈n-l⇒∃è,n-è≡e×è∈l e∈n-t
... | è , n-è≡e , è∈l = è , n-è≡e , there è∈l
x⊆y⇒nx⊆ny : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ⊆ y → names x ⊆ names y
x⊆y⇒nx⊆ny {x = x} {y = y} x⊆y {e} e∈n-x with e ∈? names y
... | yes e∈n-y = e∈n-y
... | no e∉n-y with e∈n-l⇒∃è,n-è≡e×è∈l e∈n-x
... | è , e≡n-è , è∈x = ⊥-elim $ x⊆y⇒e∉y⇒e∉x x⊆y (n-e∉l⇒e∉l $ ≡-elim′ (λ z → z ∉ names y) e≡n-è e∉n-y) è∈x
nr-x⇒nr-x∩y : ∀ {ℓ} {A : Set ℓ} {x : List (Named A)} → NonRepetitiveNames x → (y : Names) → NonRepetitiveNames (filter-∈ x y)
nr-x⇒nr-x∩y {x = []} _ _ = []
nr-x⇒nr-x∩y {x = h ∷ t} (h∉t ∷ nr-t) y with y ∋! proj₁ h
... | false = nr-x⇒nr-x∩y nr-t y
... | true = x⊆y⇒e∉y⇒e∉x (x⊆y⇒nx⊆ny $ x∩y⊆x t y) h∉t ∷ nr-x⇒nr-x∩y nr-t y
e∈l⇒[e]⊆l : ∀ {ℓ} {A : Set ℓ} {e : A} {l : List A} → e ∈ l → [ e ] ⊆ l
e∈l⇒[e]⊆l e∈l (here è≡e) = ≡-elim′ (λ x → x ∈ _) (≡-sym è≡e) e∈l
e∈l⇒[e]⊆l e∈l (there ())
a∈x⇒x≋y⇒a∈y : ∀ {ℓ} {A : Set ℓ} {x y : List A} {a : A} → a ∈ x → x ≋ y → a ∈ y
a∈x⇒x≋y⇒a∈y a∈x x≋y = x⊆y≋z (e∈l⇒[e]⊆l a∈x) x≋y (here refl)
x⊆z⇒y⊆z⇒x∪y⊆z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ⊆ z → y ⊆ z → x ∪ y ⊆ z
x⊆z⇒y⊆z⇒x∪y⊆z {x = []} _ y⊆z = y⊆z
x⊆z⇒y⊆z⇒x∪y⊆z {x = h ∷ t} {y = y} {z = z} x⊆z y⊆z = f where
f : (h ∷ t) ∪ y ⊆ z
f {e} (here e≡h) = x⊆z $ here e≡h
f {e} (there e∈t∪y) = x⊆z⇒y⊆z⇒x∪y⊆z (x∪y⊆z⇒y⊆z [ h ] t x⊆z) y⊆z e∈t∪y
x⊆x∖y∪y : (x y : Names) → x ⊆ x ∖ y ∪ y
x⊆x∖y∪y [] _ = []⊆x _
x⊆x∖y∪y (h ∷ t) y with h ∈? y
x⊆x∖y∪y (h ∷ t) y | yes h∈y = x⊆z⇒y⊆z⇒x∪y⊆z (e∈l⇒[e]⊆l $ e∈x⇒e∈y∪x (t ∖ y) h∈y) (x⊆x∖y∪y t y)
x⊆x∖y∪y (h ∷ t) y | no _ = x∪y⊆x̀∪ỳ ([ h ] ⊆ [ h ] ∋ ≋⇒⊆ refl) (x⊆x∖y∪y t y)
e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ : {e₁ e₂ : String} {l : Names} → e₁ ∈ l → e₁ ∉ l ∖ [ e₂ ] → e₁ ≡ e₂
e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ {e₁ = e₁} {e₂ = e₂} {l = l} e₁∈l e₁∉l∖e₂ with e₁ ≟ e₂
... | yes e₁≡e₂ = e₁≡e₂
... | no e₁≢e₂ = ⊥-elim $ p₄ e₁∈l where
p₁ : e₁ ∉ [ e₂ ] ∪ (l ∖ [ e₂ ])
p₁ = x≢y⇒x∉l⇒x∉y∷l e₁≢e₂ e₁∉l∖e₂
p₂ : [ e₂ ] ∪ (l ∖ [ e₂ ]) ≋ (l ∖ [ e₂ ]) ∪ [ e₂ ]
p₂ = ∪-sym [ e₂ ] (l ∖ [ e₂ ])
p₃ : e₁ ∉ (l ∖ [ e₂ ]) ∪ [ e₂ ]
p₃ = p₁ ∘ ≋⇒⊆ (∪-sym (l ∖ [ e₂ ]) [ e₂ ])
p₄ : e₁ ∉ l
p₄ = x⊆y⇒e∉y⇒e∉x (x⊆x∖y∪y l [ e₂ ]) p₃
e∉x⇒x∩y≋x∩y∖e : {e : String} {x : Names} (y : Names) → e ∉ x → x ∩ y ≡ x ∩ (y ∖ [ e ])
e∉x⇒x∩y≋x∩y∖e {x = []} _ _ = refl
e∉x⇒x∩y≋x∩y∖e {e = e} {x = h ∷ t} y e∉x with h ∈? y | h ∈? (y ∖ [ e ])
... | yes h∈y | yes h∈y∖e = ≡-cong (_∷_ h) $ e∉x⇒x∩y≋x∩y∖e y $ x∉y∷l⇒x∉l e∉x
... | yes h∈y | no h∉y∖e = ⊥-elim $ e∉x e∈x where
e∈x : e ∈ h ∷ t
e∈x = here $ ≡-sym $ e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ h∈y h∉y∖e
... | no h∉y | yes h∈y∖e = ⊥-elim $ h∉y $ x∖y⊆x y [ e ] h∈y∖e
... | no h∉y | no h∉y∖e = e∉x⇒x∩y≋x∩y∖e y $ x∉y∷l⇒x∉l e∉x
y⊆x⇒x∩y≋y : {x y : Names} → NonRepetitive y → NonRepetitive x → y ⊆ x → x ∩ y ≋ y
y⊆x⇒x∩y≋y {x = []} _ _ y⊆[] = ≡⇒≋ $ ≡-elim′ (λ y → [] ∩ y ≡ y) (≡-sym $ x⊆[]⇒x≡[] y⊆[]) refl
y⊆x⇒x∩y≋y {x = h ∷ t} {y = y} nr-y (h∉t ∷ nr-t) y⊆h∷t with h ∈? y
... | yes h∈y = ≋-trans (∪-sym [ h ] (t ∩ y)) p₄ where
p₁ : t ∩ y ≋ t ∩ (y ∖ [ h ])
p₁ = ≡⇒≋ $ e∉x⇒x∩y≋x∩y∖e y h∉t
p₂ : t ∩ (y ∖ [ h ]) ≋ y ∖ [ h ]
p₂ = y⊆x⇒x∩y≋y (nr-x∖y nr-y [ h ]) nr-t $ x⊆e∷y⇒e∉x⇒x⊆y (y⊆h∷t ∘ x∖y⊆x y [ h ]) (e∉l∖[e] h y)
p₃ : y ∖ [ h ] ∪ [ h ] ≋ y
p₃ = e∈l⇒nr-l⇒l∖e∪e≋l h∈y nr-y
p₄ : t ∩ y ∪ [ h ] ≋ y
p₄ = ≋-trans (x≋x̀⇒x∪y≋x̀∪y (≋-trans p₁ p₂) [ h ]) p₃
... | no h∉y = y⊆x⇒x∩y≋y nr-y nr-t $ x⊆e∷y⇒e∉x⇒x⊆y y⊆h∷t h∉y
x∪y∖n≡x∖n∪y∖n : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) (n : Names) → (x ∪ y) ∖∖ n ≡ (x ∖∖ n) ∪ (y ∖∖ n)
x∪y∖n≡x∖n∪y∖n [] _ _ = refl
x∪y∖n≡x∖n∪y∖n (h ∷ t) y n with proj₁ h ∈? n
... | yes _ = x∪y∖n≡x∖n∪y∖n t y n
... | no _ = ≡-cong (_∷_ h) (x∪y∖n≡x∖n∪y∖n t y n)
n-x⊆n⇒x∖n≡[] : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (n : Names) → names x ⊆ n → x ∖∖ n ≡ []
n-x⊆n⇒x∖n≡[] [] _ _ = refl
n-x⊆n⇒x∖n≡[] (h ∷ t) n n-x⊆n with proj₁ h ∈? n
... | yes _ = n-x⊆n⇒x∖n≡[] t n $ x∪y⊆z⇒y⊆z [ proj₁ h ] (names t) (x≋y⊆z (≡⇒≋ $ n-x∪y [ h ] t) n-x⊆n)
... | no h∉n = ⊥-elim $ h∉n $ n-x⊆n (proj₁ h ∈ proj₁ h ∷ names t ∋ here refl)
x∖x≡[] : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) → x ∖∖ names x ≡ []
x∖x≡[] x = n-x⊆n⇒x∖n≡[] x (names x) (≋⇒⊆ refl)
nr-[a] : ∀ {ℓ} {A : Set ℓ} {a : A} → NonRepetitive [ a ]
nr-[a] = (λ()) ∷ []
x≋y⇒x∖n≋y∖n : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ≋ y → (n : Names) → x ∖∖ n ≋ y ∖∖ n
x≋y⇒x∖n≋y∖n refl _ = refl
x≋y⇒x∖n≋y∖n {x = x} (perm l₁ x₁ x₂ l₂ p) n = ≋-trans p₀ $ ≋-trans (≡⇒≋ p₅) $ ≋-trans pg (≡⇒≋ $ ≡-sym g₅) where
p₀ : x ∖∖ n ≋ (l₁ ++ x₂ ∷ x₁ ∷ l₂) ∖∖ n
p₀ = x≋y⇒x∖n≋y∖n p n
p₁ : (l₁ ++ [ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n
p₁ = x∪y∖n≡x∖n∪y∖n l₁ ([ x₂ ] ++ [ x₁ ] ++ l₂) n
p₂ : l₁ ∖∖ n ++ ([ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ ([ x₁ ] ++ l₂) ∖∖ n
p₂ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₂ ] ([ x₁ ] ++ l₂) n)
p₃ : l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ ([ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n ++ l₂ ∖∖ n
p₃ = ≡-cong (λ z → l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₁ ] l₂ n)
p₄ : l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n ++ l₂ ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n
p₄ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (≡-sym $ ∪-assoc ([ x₂ ] ∖∖ n) ([ x₁ ] ∖∖ n) (l₂ ∖∖ n))
p₅ : (l₁ ++ [ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n
p₅ = ≡-trans p₁ $ ≡-trans p₂ $ ≡-trans p₃ p₄
pg : l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n ≋ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
pg = y≋ỳ⇒x∪y≋x∪ỳ (l₁ ∖∖ n) $ x≋x̀⇒x∪y≋x̀∪y (∪-sym ([ x₂ ] ∖∖ n) ([ x₁ ] ∖∖ n)) (l₂ ∖∖ n)
g₁ : (l₁ ++ [ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n
g₁ = x∪y∖n≡x∖n∪y∖n l₁ ([ x₁ ] ++ [ x₂ ] ++ l₂) n
g₂ : l₁ ∖∖ n ++ ([ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ ([ x₂ ] ++ l₂) ∖∖ n
g₂ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₁ ] ([ x₂ ] ++ l₂) n)
g₃ : l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ ([ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n ++ l₂ ∖∖ n
g₃ = ≡-cong (λ z → l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₂ ] l₂ n)
g₄ : l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n ++ l₂ ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
g₄ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (≡-sym $ ∪-assoc ([ x₁ ] ∖∖ n) ([ x₂ ] ∖∖ n) (l₂ ∖∖ n))
g₅ : (l₁ ++ [ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
g₅ = ≡-trans g₁ $ ≡-trans g₂ $ ≡-trans g₃ g₄
nr-x∪y⇒e∈x⇒e∈y⇒⊥ : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → NonRepetitive (x ∪ y) → e ∈ x → e ∈ y → ⊥
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = []} _ ()
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = h ∷ t} (h∉t∪y ∷ nr-t∪y) (here e≡h) = h∉t∪y ∘ e∈x⇒e∈y∪x t ∘ ≡-elim′ (λ x → x ∈ _) e≡h
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = h ∷ t} (h∉t∪y ∷ nr-t∪y) (there e∈t) = nr-x∪y⇒e∈x⇒e∈y⇒⊥ nr-t∪y e∈t
nr-x∪y⇒x∖y≡x : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) → NonRepetitiveNames (x ∪ y) → y ∖∖ names x ≡ y
nr-x∪y⇒x∖y≡x x y nr-x∪y = f₀ y (≋⇒⊆ refl) where
f₀ : ∀ t → t ⊆ y → t ∖∖ names x ≡ t
f₀ [] _ = refl
f₀ (h ∷ t) h∷t⊆y with proj₁ h ∈? names x
... | yes h∈x = ⊥-elim $ nr-x∪y⇒e∈x⇒e∈y⇒⊥ (≡-elim′ NonRepetitive (n-x∪y x y) nr-x∪y) h∈x (x⊆y⇒nx⊆ny h∷t⊆y $ here refl)
... | no _ = ≡-cong (_∷_ h) (f₀ t $ x∪y⊆z⇒y⊆z [ h ] t h∷t⊆y)
t≋t₁∪t₂⇒t∖t₁≋t₂ : ∀ {ℓ} {A : Set ℓ} {t : List (Named A)} → NonRepetitiveNames t → (t₁ t₂ : List (Named A)) → t ≋ t₁ ∪ t₂ → t ∖∖ names t₁ ≋ t₂
t≋t₁∪t₂⇒t∖t₁≋t₂ {t = t} nr-t t₁ t₂ t≋t₁∪t₂ = ≋-trans p₂ (≡⇒≋ $ nr-x∪y⇒x∖y≡x t₁ t₂ $ nr-x≋y (n-x≋y t≋t₁∪t₂) nr-t) where
n-t₁ = names t₁
p₁ : t ∖∖ n-t₁ ≋ (t₁ ∖∖ n-t₁) ∪ (t₂ ∖∖ n-t₁)
p₁ = ≋-trans (x≋y⇒x∖n≋y∖n t≋t₁∪t₂ n-t₁) (≡⇒≋ $ x∪y∖n≡x∖n∪y∖n t₁ t₂ n-t₁)
p₂ : t ∖∖ n-t₁ ≋ t₂ ∖∖ n-t₁
p₂ = ≡-elim′ (λ x → t ∖∖ n-t₁ ≋ x ∪ (t₂ ∖∖ n-t₁)) (x∖x≡[] t₁) p₁
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ : ∀ {ℓ} {A : Set ℓ} {x x̀ y ỳ : List A} → x ≋ x̀ → y ≋ ỳ → x ∪ y ≋ x̀ ∪ ỳ
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ x≋x̀ (refl {y}) = x≋x̀⇒x∪y≋x̀∪y x≋x̀ y
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ {x = x} {x̀ = x̀} {y = y} {ỳ = ._} x≋x̀ (perm l₁ x₁ x₂ l₂ y≋l₁x₂x₁l₂) = ≋-trans p₁ $ ≋-trans p₂ $ ≋-trans p₃ p₄ where
p₁ : x ∪ y ≋ x̀ ∪ (l₁ ++ x₂ ∷ x₁ ∷ l₂)
p₁ = x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ x≋x̀ y≋l₁x₂x₁l₂
p₂ : x̀ ∪ (l₁ ++ x₂ ∷ x₁ ∷ l₂) ≋ (x̀ ∪ l₁) ++ x₂ ∷ x₁ ∷ l₂
p₂ = ≡⇒≋ $ ≡-sym $ ∪-assoc x̀ l₁ (x₂ ∷ x₁ ∷ l₂)
p₃ : (x̀ ∪ l₁) ++ x₂ ∷ x₁ ∷ l₂ ≋ (x̀ ∪ l₁) ++ x₁ ∷ x₂ ∷ l₂
p₃ = perm (x̀ ∪ l₁) x₁ x₂ l₂ refl
p₄ : (x̀ ∪ l₁) ++ x₁ ∷ x₂ ∷ l₂ ≋ x̀ ∪ (l₁ ++ x₁ ∷ x₂ ∷ l₂)
p₄ = ≡⇒≋ $ ∪-assoc x̀ l₁ (x₁ ∷ x₂ ∷ l₂)
x∖y∪y≋y∖x∪x : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) →
let nx = names x
ny = names y
in filter-∈ x ny ≋ filter-∈ y nx → x ∖∖ ny ∪ y ≋ y ∖∖ nx ∪ x
x∖y∪y≋y∖x∪x x y p₀ = ≋-trans p₁ $ ≋-trans p₂ p₃ where
nx = names x
ny = names y
p₁ : x ∖∖ ny ∪ y ≋ x ∖∖ ny ∪ y ∖∖ nx ∪ filter-∈ y nx
p₁ = ≋-trans (y≋ỳ⇒x∪y≋x∪ỳ (x ∖∖ ny) (t≋t∖n∪t∩n y nx)) (≡⇒≋ $ ≡-sym $ ∪-assoc (x ∖∖ ny) (y ∖∖ nx) (filter-∈ y nx))
p₂ : (x ∖∖ ny ∪ y ∖∖ nx) ∪ filter-∈ y nx ≋ (y ∖∖ nx ∪ x ∖∖ ny) ∪ filter-∈ x ny
p₂ = x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ (∪-sym (x ∖∖ ny) (y ∖∖ nx)) (≋-sym p₀)
p₃ : y ∖∖ nx ∪ x ∖∖ ny ∪ filter-∈ x ny ≋ y ∖∖ nx ∪ x
p₃ = ≋-trans (≡⇒≋ $ ∪-assoc (y ∖∖ nx) (x ∖∖ ny) (filter-∈ x ny)) (≋-sym $ y≋ỳ⇒x∪y≋x∪ỳ (y ∖∖ nx) (t≋t∖n∪t∩n x ny))
names⇒named : Names → List (Named Unit)
names⇒named = mapL (λ x → x , unit)
nn-x∪y≡nn-x∪nn-y : ∀ x y → names⇒named (x ∪ y) ≡ names⇒named x ∪ names⇒named y
nn-x∪y≡nn-x∪nn-y [] y = refl
nn-x∪y≡nn-x∪nn-y (h ∷ t) y = ≡-cong (_∷_ _) (nn-x∪y≡nn-x∪nn-y t y)
nn-x≡x : ∀ x → names (names⇒named x) ≡ x
nn-x≡x [] = refl
nn-x≡x (h ∷ t) = ≡-cong (_∷_ h) (nn-x≡x t)
x≋y⇒nn-x≋nn-y : ∀ {x y} → x ≋ y → names⇒named x ≋ names⇒named y
x≋y⇒nn-x≋nn-y refl = refl
x≋y⇒nn-x≋nn-y {x = x} {y = ._} (perm l₁ x₁ x₂ l₂ x≋l₁x₂x₁l₂) = ≋-trans p₁ p₂ where
p₁ : names⇒named x ≋ names⇒named l₁ ++ (x₂ , unit) ∷ (x₁ , unit) ∷ names⇒named l₂
p₁ = ≋-trans (x≋y⇒nn-x≋nn-y x≋l₁x₂x₁l₂) (≡⇒≋ $ nn-x∪y≡nn-x∪nn-y l₁ (x₂ ∷ x₁ ∷ l₂))
p₂ : names⇒named l₁ ++ (x₂ , unit) ∷ (x₁ , unit) ∷ names⇒named l₂ ≋ names⇒named (l₁ ++ x₁ ∷ x₂ ∷ l₂)
p₂ = ≋-trans (perm (names⇒named l₁) (x₁ , unit) (x₂ , unit) (names⇒named l₂) refl) (≡⇒≋ $ ≡-sym $ nn-x∪y≡nn-x∪nn-y l₁ (x₁ ∷ x₂ ∷ l₂))
x≋y∪z⇒x∖y≋z : {x : Names} → NonRepetitive x → (y z : Names) → x ≋ y ∪ z → x ∖ y ≋ z
x≋y∪z⇒x∖y≋z {x} nr-x y z x≋y∪z = ≋-trans (≡⇒≋ $ ≡-sym $ ≡-trans p₂ p₃) (≋-trans p₁ $ ≡⇒≋ $ nn-x≡x z) where
ux = names⇒named x
uy = names⇒named y
uz = names⇒named z
ux≋uy∪uz : ux ≋ uy ∪ uz
ux≋uy∪uz = ≋-trans (x≋y⇒nn-x≋nn-y x≋y∪z) (≡⇒≋ $ nn-x∪y≡nn-x∪nn-y y z)
p₁ : names (ux ∖∖ names uy) ≋ names uz
p₁ = n-x≋y $ t≋t₁∪t₂⇒t∖t₁≋t₂ (≡-elim′ NonRepetitive (≡-sym $ nn-x≡x x) nr-x) uy uz ux≋uy∪uz
p₂ : names (ux ∖∖ names uy) ≡ names ux ∖ names uy
p₂ = n-x∖y ux (names uy)
p₃ : names ux ∖ names uy ≡ x ∖ y
p₃ = ≡-cong₂ _∖_ (nn-x≡x x) (nn-x≡x y)
h∈x⇒∃t,x≋h∷t : ∀ {ℓ} {A : Set ℓ} {h : A} {x : List A} → h ∈ x → NonRepetitive x → Σ[ t ∈ List A ] x ≋ h ∷ t
h∈x⇒∃t,x≋h∷t {h = h} .{x = x ∷ xs} (here {x = x} {xs = xs} h≡x) (x∉xs ∷ nr-xs) = xs , ≡⇒≋ (≡-cong (λ z → z ∷ xs) (≡-sym h≡x))
h∈x⇒∃t,x≋h∷t {h = h} .{x = x ∷ xs} (there {x = x} {xs = xs} h∈xs) (x∉xs ∷ nr-xs) =
let t , xs≋h∷t = ((Σ[ t ∈ List _ ] xs ≋ h ∷ t) ∋ h∈x⇒∃t,x≋h∷t h∈xs nr-xs)
p₁ : x ∷ xs ≋ x ∷ h ∷ t
p₁ = y≋ỳ⇒x∪y≋x∪ỳ [ x ] xs≋h∷t
p₂ : x ∷ h ∷ t ≋ h ∷ x ∷ t
p₂ = ≋-del-ins-l [] [ x ] h t
in x ∷ t , ≋-trans p₁ p₂
nr-x∪y⇒nr-y : ∀ {ℓ} {A : Set ℓ} (x y : List A) → NonRepetitive (x ∪ y) → NonRepetitive y
nr-x∪y⇒nr-y [] _ nr-y = nr-y
nr-x∪y⇒nr-y (h ∷ t) y (_ ∷ nr-t∪y) = nr-x∪y⇒nr-y t y nr-t∪y
x⊆y⇒∃x̀,y≋x∪x̀ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → NonRepetitive x → NonRepetitive y → x ⊆ y → Σ[ x̀ ∈ List A ] y ≋ x ∪ x̀
x⊆y⇒∃x̀,y≋x∪x̀ {x = []} {y = y} _ _ _ = y , refl
x⊆y⇒∃x̀,y≋x∪x̀ {x = h ∷ t} {y = y} (h∉t ∷ nr-t) nr-y h∷t⊆y =
let ỳ , y≋h∷ỳ = h∈x⇒∃t,x≋h∷t (h∷t⊆y (h ∈ h ∷ t ∋ here refl)) nr-y
p₁ : t ⊆ ỳ
p₁ = x⊆e∷y⇒e∉x⇒x⊆y (x⊆y≋z (x∪y⊆z⇒y⊆z [ h ] t h∷t⊆y) y≋h∷ỳ) h∉t
nr-ỳ = nr-x∪y⇒nr-y [ h ] ỳ $ nr-x≋y y≋h∷ỳ nr-y
t̀ , ỳ≋t∪t̀ = x⊆y⇒∃x̀,y≋x∪x̀ nr-t nr-ỳ p₁
p₂ : h ∷ ỳ ≋ (h ∷ t) ∪ t̀
p₂ = y≋ỳ⇒x∪y≋x∪ỳ [ h ] ỳ≋t∪t̀
in t̀ , ≋-trans y≋h∷ỳ p₂
t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ : ∀ {ℓ} {A : Set ℓ} {t₁ t₂ : List (Named A)} → NonRepetitiveNames t₁ → NonRepetitiveNames t₂ → t₁ ⊆ t₂ → t₂ ≋ t₁ ∪ t₂ ∖∖ names t₁
t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ {t₁ = t₁} {t₂ = t₂} nr-nt₁ nr-nt₂ t₁⊆t₂ = ≋-trans p₁ $ y≋ỳ⇒x∪y≋x∪ỳ t₁ p₆ where
n-t₁ = names t₁
nr-t₁ = nr-names⇒nr nr-nt₁
nr-t₂ = nr-names⇒nr nr-nt₂
t̀₁,t₁∪t̀₁≋t₂ = x⊆y⇒∃x̀,y≋x∪x̀ nr-t₁ nr-t₂ t₁⊆t₂
t̀₁ = proj₁ t̀₁,t₁∪t̀₁≋t₂
p₁ : t₂ ≋ t₁ ∪ t̀₁
p₁ = proj₂ t̀₁,t₁∪t̀₁≋t₂
p₂ : t₂ ∖∖ n-t₁ ≋ (t₁ ∪ t̀₁) ∖∖ n-t₁
p₂ = x≋y⇒x∖n≋y∖n p₁ n-t₁
p₃ : (t₁ ∪ t̀₁) ∖∖ n-t₁ ≡ t₁ ∖∖ n-t₁ ∪ t̀₁ ∖∖ n-t₁
p₃ = x∪y∖n≡x∖n∪y∖n t₁ t̀₁ n-t₁
p₄ : t₁ ∖∖ n-t₁ ∪ t̀₁ ∖∖ n-t₁ ≡ t̀₁ ∖∖ n-t₁
p₄ = ≡-cong (λ x → x ∪ t̀₁ ∖∖ n-t₁) (x∖x≡[] t₁)
p₅ : t̀₁ ∖∖ n-t₁ ≡ t̀₁
p₅ = nr-x∪y⇒x∖y≡x t₁ t̀₁ $ nr-x≋y (n-x≋y p₁) nr-nt₂
p₆ : t̀₁ ≋ t₂ ∖∖ n-t₁
p₆ = ≋-sym $ ≋-trans p₂ $ ≡⇒≋ $ ≡-trans p₃ $ ≡-trans p₄ p₅
t₁⊆t₂⇒t₁≋f∈-t₂-nt₁ : ∀ {ℓ} {A : Set ℓ} {t₁ t₂ : List (Named A)} → NonRepetitiveNames t₁ → NonRepetitiveNames t₂ → t₁ ⊆ t₂ → t₁ ≋ filter-∈ t₂ (names t₁)
t₁⊆t₂⇒t₁≋f∈-t₂-nt₁ {t₁ = t₁} {t₂ = t₂} nr-t₁ nr-t₂ t₁⊆t₂ = ≋-trans (≋-sym p₃) p₄ where
nt₁ = names t₁
p₁ : t₂ ≋ t₂ ∖∖ nt₁ ∪ t₁
p₁ = ≋-trans (t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ nr-t₁ nr-t₂ t₁⊆t₂) (∪-sym t₁ (t₂ ∖∖ nt₁))
p₂ : t₂ ≋ t₂ ∖∖ nt₁ ∪ filter-∈ t₂ nt₁
p₂ = t≋t∖n∪t∩n t₂ nt₁
p₃ : t₂ ∖∖ names (t₂ ∖∖ nt₁) ≋ t₁
p₃ = t≋t₁∪t₂⇒t∖t₁≋t₂ nr-t₂ (t₂ ∖∖ nt₁) t₁ p₁
p₄ : t₂ ∖∖ names (t₂ ∖∖ nt₁) ≋ filter-∈ t₂ nt₁
p₄ = t≋t₁∪t₂⇒t∖t₁≋t₂ nr-t₂ (t₂ ∖∖ nt₁) (filter-∈ t₂ nt₁) p₂
-- /lemmas
-- assertions
infix 4 _s-≢!_
_s-≢!_ : String → String → Set
x s-≢! y with x ≟ y
... | yes _ = ⊥
... | no _ = ⊤
s-≢!⇒≢? : ∀ {x y} → x s-≢! y → x ≢ y
s-≢!⇒≢? {x} {y} x≢!y with x ≟ y
s-≢!⇒≢? () | yes _
s-≢!⇒≢? _ | no p = p
s-NonRepetitive? : (n : Names) → Dec (NonRepetitive n)
s-NonRepetitive? [] = yes []
s-NonRepetitive? (h ∷ t) with h ∈? t | s-NonRepetitive? t
... | no h∉t | yes nr-t = yes (h∉t ∷ nr-t)
... | yes h∈t | _ = no f where
f : NonRepetitive (_ ∷ _) → _
f (h∉t ∷ _) = h∉t h∈t
... | _ | no ¬nr-t = no f where
f : NonRepetitive (_ ∷ _) → _
f (_ ∷ nr-t) = ¬nr-t nr-t
s-NonRepetitive! : Names → Set
s-NonRepetitive! n with s-NonRepetitive? n
... | yes _ = ⊤
... | no _ = ⊥
NonRepetitiveNames! : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Set
NonRepetitiveNames! = s-NonRepetitive! ∘ names
s-nr!⇒nr : {n : Names} → s-NonRepetitive! n → NonRepetitive n
s-nr!⇒nr {n = n} _ with s-NonRepetitive? n
s-nr!⇒nr _ | yes p = p
s-nr!⇒nr () | no _
-- /assertions
| 43.529183
| 151
| 0.430559
|
3d58a993f4c6bc86cd5491e4665afdb5df87c7d6
| 32,269
|
agda
|
Agda
|
agda/sn-calculus-confluence/potrec.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/sn-calculus-confluence/potrec.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/sn-calculus-confluence/potrec.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module sn-calculus-confluence.potrec where
open import utility
open import sn-calculus
open import context-properties
using (->pot-view ; ->E-view)
open import sn-calculus-confluence.helper
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.Properties
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Properties
using (canθₛ-subset ; canθₛₕ-subset ; canθₛ-membership ; canθₛₕ-membership
; canθₛ-mergeˡ ; canθₛₕ-mergeˡ
; canθ-is-present ; canθ-is-absent
; canθₛₕ-emit ; canθₛ-emit
; term-raise ; canₛ-raise ; canₛₕ-raise
; term-nothin ; canₛ-term-nothin ; canₛₕ-term-nothin
; canₛ-if-true ; canₛ-if-false ; canₛₕ-if-true ; canₛₕ-if-false
; canₛ-capture-emit-signal ; canₛₕ-capture-set-shared)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open import Data.Bool
using (Bool ; true ; false ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; [] ; _∷_ ; [_])
open import Data.List.Any
using (Any ; here ; there ; any)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; _≟_ ; zero ; suc ; _+_)
open import Data.Product
using (Σ ; Σ-syntax ; _,_ ; proj₁ ; proj₂ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; trans ; cong ; subst ; module ≡-Reasoning)
open ->pot-view
open ->E-view
open term-nothin
open term-raise
open ≡-Reasoning
using (begin_ ; _∎ ; _≡⟨_⟩_ ; _≡⟨⟩_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
ρ-pot-conf-rec : ∀{p θ ql θl qr θr p≡ql E pin qin FV₀ BV₀ A Al Ar A≡Al}
→ {ρθ·psn⟶₁ρθl·ql : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θl , Al ⟩· ql)}
→ {ρθ·psn⟶₁ρθr·qr : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θr , Ar ⟩· qr)}
→ {p≐E⟦pin⟧ : p ≐ E ⟦ pin ⟧e}
→ {qr≐E⟦qin⟧ : qr ≐ E ⟦ qin ⟧e}
→ CorrectBinding (ρ⟨ θ , A ⟩· p) FV₀ BV₀
→ ->pot-view ρθ·psn⟶₁ρθl·ql p≡ql A≡Al
→ ->E-view ρθ·psn⟶₁ρθr·qr p≐E⟦pin⟧ qr≐E⟦qin⟧
→
(ρ⟨ θl , Al ⟩· ql sn⟶₁ ρ⟨ θr , Ar ⟩· qr) ⊎
(Σ[ s ∈ Term ]
Σ[ θo ∈ Env.Env ]
Σ[ Ao ∈ Ctrl ]
(ρ⟨ θl , Al ⟩· ql) sn⟶₁ (ρ⟨ θo , Ao ⟩· s)
× (ρ⟨ θr , Ar ⟩· qr) sn⟶₁ (ρ⟨ θo , Ao ⟩· s))
ρ-pot-conf-rec {p} {θ} {ql} {θl} {.(E ⟦ qin ⟧e)} {θr} {_} {E} {(ρ⟨ .θin , Ain ⟩· .qin)} {qin} {_} {_} {A} {.A} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)} {.(rmerge {θ} {θin} p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vmerge {.θ} {θin} {.p} {.qin} {.E})
with Env.Sig∈ S θin
... | yes S∈Domθin
rewrite SigMap.update-union-union S Signal.absent (Env.sig θ) (Env.sig θin) S∈ S∈Domθin
= inj₁ (ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ (θl ← θin) , A-max A Ain ⟩· E ⟦ qin ⟧e ∋ rmerge {θl} {θin} p≐E⟦pin⟧)
... | no S∉Domθin
with Env.sig-←-irr-get {θ} {θin} {S} S∈ S∉Domθin -- θr ≡ (θ ← θin)
... | S∈Domθ←θin , θS≡⟨θ←θin⟩S
= inj₂
(_ , _ , A-max A Ain ,
subst (λ { θ* → ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ θ* , A-max A Ain ⟩· E ⟦ qin ⟧e})
((Env.set-sig {S} θ S∈ Signal.absent) ← θin ≡
Env.set-sig {S} (θ ← θin) S∈Domθ←θin Signal.absent ∋
cong (λ sig* → Θ sig* (Env.shr (θ ← θin)) (Env.var (θ ← θin)))
(SigMap.put-union-comm S Signal.absent (Env.sig θ) (Env.sig θin) S∉Domθin))
(ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ (θl ← θin) , A-max A Ain ⟩· E ⟦ qin ⟧e ∋
rmerge {θl} {θin} p≐E⟦pin⟧) ,′
(ρ⟨ (θ ← θin) , A-max A Ain ⟩· E ⟦ qin ⟧e sn⟶₁ ρ⟨ (Env.set-sig {S} (θ ← θin) S∈Domθ←θin Signal.absent) , A-max A Ain ⟩· E ⟦ qin ⟧e ∋
(rabsence {θr} {_} {S} S∈Domθ←θin (trans (sym θS≡⟨θ←θin⟩S) θS≡unknown)
(λ S∈can-E⟦qin⟧-θ←θin →
S∉can-p-θ
(canθₛ-mergeˡ (Env.sig θ) Env.[]env cbp p≐E⟦pin⟧
S S∉Domθin S∈can-E⟦qin⟧-θ←θin)))))
ρ-pot-conf-rec {p} {θ} {ql} {θl} {.(E ⟦ qin ⟧e)} {θr} {_} {E} {(ρ⟨ .θin , Ain ⟩· qin)} {qin} {_} {_} {A} {Al} {Ar} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)} {.(rmerge p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vmerge {.θ} {θin} {.p} {.qin} {.E})
with Env.Shr∈ s θin
... | yes s∈Domθin
rewrite ShrMap.update-union-union s (SharedVar.ready , Env.shr-vals {s} θ s∈) (Env.shr θ) (Env.shr θin) s∈ s∈Domθin
= inj₁ (rmerge {θl} {θin} p≐E⟦pin⟧)
... | no s∉Domθin
with Env.shr-←-irr-get {θ} {θin} {s} s∈ s∉Domθin
... | s∈Domθ←θin , θs≡⟨θ←θin⟩s
= inj₂
(_ , _ , _ ,
subst (λ { θ* → ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ θ* , A-max A Ain ⟩· E ⟦ qin ⟧e })
(cong (λ shr* → Θ (Env.sig (θ ← θin)) shr* (Env.var (θ ← θin)))
(trans
(cong (λ shrval* →
ShrMap.union
(ShrMap.update (Env.shr θ) s (SharedVar.ready , proj₂ shrval*))
(Env.shr θin))
(ShrMap.U-∉-irr-get-help-m {_} {Env.shr θ} {Env.shr θin} {s}
s∈ s∉Domθin s∈Domθ←θin ))
(ShrMap.put-union-comm s (SharedVar.ready , Env.shr-vals {s} (θ ← θin) s∈Domθ←θin)
(Env.shr θ) (Env.shr θin) s∉Domθin)))
(rmerge {θl} {θin} p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈Domθ←θin
(Data.Sum.map (trans (sym θs≡⟨θ←θin⟩s)) (trans (sym θs≡⟨θ←θin⟩s))
θs≡old⊎θs≡new)
(λ s∈can-E⟦qin⟧-θ←θin →
s∉can-p-θ
(canθₛₕ-mergeˡ (Env.sig θ) Env.[]env cbp p≐E⟦pin⟧
s s∉Domθin s∈can-E⟦qin⟧-θ←θin)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ qin ∣⇒ _)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(ris-present {θ} {S'} S'∈ θS'≡present p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vis-present {.θ} {S'} {S∈ = S'∈} {θS'≡present} {.p≐E⟦pin⟧})
with S' Signal.≟ S
... | yes refl =
((Signal.unknown ≡ Signal.present → _) ∋ λ ())
(trans (trans (sym θS≡unknown) (Env.sig-stats-∈-irr {S} {θ} S∈ S'∈)) θS'≡present)
... | no S'≠S =
inj₂
(_ , _ , _ ,
ris-present {θl} {S'}
(Env.sig-set-mono' {S'} {S} {θ} {_} {S∈} S'∈)
(Env.sig-putputget {S'} {S} {θ} S'≠S S'∈ S∈ _ θS'≡present)
p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧-θ →
S∉can-p-θ
(subst (Signal.unwrap S ∈_)
(cong proj₁ (sym (canθ-is-present (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡present)) )
S∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ _ ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(ris-absent {θ} {S'} S'∈ θS'≡absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vis-absent {.θ} {S'} {S∈ = S'∈} {θS'≡absent} {.p≐E⟦pin⟧})
with S' Signal.≟ S
... | yes refl =
((Signal.unknown ≡ Signal.absent → _) ∋ λ ())
(trans (trans (sym θS≡unknown) (Env.sig-stats-∈-irr {S} {θ} S∈ S'∈)) θS'≡absent)
... | no S'≠S =
inj₂
(_ , _ , _ ,
ris-absent {θl} {S'}
(Env.sig-set-mono' {S'} {S} {θ} {_} {S∈} S'∈)
(Env.sig-putputget {S'} {S} {θ} S'≠S S'∈ S∈ _ θS'≡absent)
p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧-θ →
S∉can-p-θ
(subst (Signal.unwrap S ∈_)
(cong proj₁ (sym (canθ-is-absent (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡absent)))
S∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ qin ∣⇒ _)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(ris-present {θ} {S'} S'∈ θS'≡present p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vis-present {.θ} {S'} {S∈ = S'∈} {θS'≡present} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
ris-present {θl} {S'} S'∈ θS'≡present p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧-θ →
s∉can-p-θ
(subst (SharedVar.unwrap s ∈_)
(cong (proj₂ ∘ proj₂)
(sym (canθ-is-present (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡present)))
s∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ _ ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(ris-absent {θ} {S'} S'∈ θS'≡absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vis-absent {.θ} {S'} {S∈ = S'∈} {θS'≡absent} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
ris-absent {θl} {S'} S'∈ θS'≡absent p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧-θ →
s∉can-p-θ
(subst (SharedVar.unwrap s ∈_)
(cong (proj₂ ∘ proj₂)
(sym (canθ-is-absent (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡absent)))
s∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(emit S')} {.nothin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(remit {θ} {p} {S'} S'∈ θS'≢absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vemit {.θ} {.p} {S'} {.E} {S'∈} {θS'≢absent} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
remit {θl} {_} {S'} S'∈ θS'≢absent p≐E⟦pin⟧ ,′
rreadyness {θr} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦nothin⟧-θr →
s∉can-p-θ
(canθₛₕ-emit θ S'∈ Env.[]env p≐E⟦pin⟧
θS'≢absent
(canθₛ-membership (Env.sig θ) 0 p Env.[]env S'
(λ θ* → canₛ-capture-emit-signal θ* p≐E⟦pin⟧))
s s∈can-E⟦nothin⟧-θr)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(emit S')} {.nothin} {_} {_} {A} {Al} {Ar} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(remit {θ} {p} {S'} S'∈ θS'≢absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vemit {.θ} {.p} {S'} {.E} {S'∈} {θS'≢absent} {.p≐E⟦pin⟧})
with S' Signal.≟ S
... | yes refl =
⊥-elim
(S∉can-p-θ
(canθₛ-membership (Env.sig θ) 0 p Env.[]env S'
(λ θ* → canₛ-capture-emit-signal θ* p≐E⟦pin⟧)))
... | no S'≢S =
inj₂
(_ , _ , _ ,
remit {θl} {_} {S'}
(SigMap.insert-mono {_} {S'} {Env.sig θ} {S} {Signal.absent} S'∈)
(θS'≢absent ∘
trans
(sym (SigMap.putputget {_} {Env.sig θ} {S'} {S}
{_} {Signal.absent} S'≢S S'∈ S'∈Domθl refl)))
p≐E⟦pin⟧ ,′
subst (λ sig* → ρ⟨ θr , Ar ⟩· E ⟦ nothin ⟧e sn⟶₁ ρ⟨ (Θ sig* (Env.shr θ) (Env.var θ)) , Ar ⟩· E ⟦ nothin ⟧e)
(SigMap.put-comm {_} {Env.sig θ} {_} {_} {Signal.present} {Signal.absent} S'≢S)
(rabsence {θr} {_} {S}
S∈Domθr
(SigMap.putputget {_} {Env.sig θ} {S} {S'} {_} {Signal.present}
(S'≢S ∘ sym) S∈ S∈Domθr θS≡unknown)
(λ S''∈can-E⟦nothin⟧-θr →
S∉can-p-θ
(canθₛ-emit θ S'∈ Env.[]env p≐E⟦pin⟧
θS'≢absent
(canθₛ-membership (Env.sig θ) 0 p Env.[]env S'
(λ θ* → canₛ-capture-emit-signal θ* p≐E⟦pin⟧))
S S''∈can-E⟦nothin⟧-θr))))
where S∈Domθr = SigMap.insert-mono {_} {S} {Env.sig θ} {S'} {Signal.present} S∈
S'∈Domθl = SigMap.insert-mono {_} {S'} {Env.sig θ} {S} {Signal.absent} S'∈
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(shared s' ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p')}
{_} {_} {A} {Al} {Ar} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rraise-shared e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vraise-shared {.θ} {.p} {s'} {e} {p'} {.E} {e'} {.p≐E⟦pin⟧})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , Al ⟩· p) sn⟶₁
(ρ⟨ θl , Al ⟩· E ⟦ ρ⟨ ([s,δe]-env s' δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-shared e'' p≐E⟦pin⟧) ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦ρΘp'⟧-θ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ ρ⟨ ([s,δe]-env s' (δ e')) , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tshared (δ e') s' e p') p≐E⟦pin⟧ S*)
S S∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(shared s' ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p')}
{_} {_} {A} {Al} {Ar} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rraise-shared e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vraise-shared {.θ} {.p} {s'} {e} {p'} {.E} {e'} {.p≐E⟦pin⟧})
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , Al ⟩· p) sn⟶₁
(ρ⟨ θl , Al ⟩· E ⟦ ρ⟨ ([s,δe]-env s' δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-shared e'' p≐E⟦pin⟧) ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦ρΘp'⟧-θ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0
(E ⟦ ρ⟨ ([s,δe]-env s' (δ e')) , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tshared (δ e') s' e p') p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-raise θ* (tshared (δ e') s' e p') p≐E⟦pin⟧ s*)
s s∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rset-shared-value-old {θ} {p} {s'} e' s'∈ θs'≡old p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vset-shared-value-old {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡old})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (θl-set-shr δe*) , GO ⟩· E ⟦ nothin ⟧e)
(sym δe'≡δe'')
(rset-shared-value-old {θl} {_} {s'} e'' s'∈ θs'≡old p≐E⟦pin⟧) ,′
rabsence {θr} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦nothin⟧-θr →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
S S∈can-E⟦nothin⟧-θr)))
where
θl-set-shr : ℕ → Env
θl-set-shr n = Env.set-shr {s'} θl s'∈ SharedVar.new n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rset-shared-value-old {θ} {p} {s'} e' s'∈ θs'≡old p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vset-shared-value-old {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡old})
with s SharedVar.≟ s'
... | yes refl =
⊥-elim
(s∉can-p-θ
(canθₛₕ-membership (Env.sig θ) 0 p Env.[]env s
(λ θ* → canₛₕ-capture-set-shared θ* p≐E⟦pin⟧)))
... | no s≢s'
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ shr* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (Θ (Env.sig θl) shr* (Env.var θl)) , GO ⟩·
E ⟦ nothin ⟧e)
(cong Env.shr
(begin
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (δ e'')
≡⟨ cong (Env.set-shr {s'} θl s'∈Domθl SharedVar.new) (sym δe'≡δe'') ⟩
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (δ e')
≡⟨ cong (λ sig* → Θ (Env.sig θ) sig* (Env.var θ))
(ShrMap.put-comm {_} {Env.shr θ} {_} {_}
{SharedVar.ready ,′ θs}
{SharedVar.new ,′ δ e'}
s≢s') ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready θs
≡⟨ cong (Env.set-shr {s} θr s∈Domθr SharedVar.ready ∘ proj₂) (sym θrs≡θs) ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready
(Env.shr-vals {s} θr s∈Domθr) ∎))
(rset-shared-value-old {θl} {_} {s'} e'' s'∈Domθl
(trans (cong proj₁ θls'≡θs') θs'≡old) p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈Domθr
(Data.Sum.map (trans (cong proj₁ θrs≡θs)) (trans (cong proj₁ θrs≡θs))
θs≡old⊎θs≡new)
(λ s∈can-E⟦nothin⟧-θr →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ s*)
s s∈can-E⟦nothin⟧-θr)))
where
θs = Env.shr-vals {s} θ s∈
s∈Domθr = Env.shr-set-mono' {s} {s'} {θ} {SharedVar.new} {δ e'} {s'∈} s∈
θrs≡θs = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.new ,′ δ e'}
s≢s' s∈ s∈Domθr refl
s'∈Domθl = Env.shr-set-mono' {s'} {s} {θ} {SharedVar.ready} {θs} {s∈} s'∈
θls'≡θs' = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.ready ,′ θs}
(s≢s' ∘ sym) s'∈ s'∈Domθl refl
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rset-shared-value-new {θ} {p} {s'} e' s'∈ θs'≡new p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vset-shared-value-new {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡new})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (θl-set-shr δe*) , GO ⟩· E ⟦ nothin ⟧e)
(cong
(Env.shr-vals {s'} θ s'∈ +_)
(sym δe'≡δe''))
(rset-shared-value-new {θl} {_} {s'} e'' s'∈ θs'≡new p≐E⟦pin⟧) ,′
rabsence {θr} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦nothin⟧-θr →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
S S∈can-E⟦nothin⟧-θr)))
where
θl-set-shr : ℕ → Env
θl-set-shr n = Env.set-shr {s'} θl s'∈ SharedVar.new n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rset-shared-value-new {θ} {p} {s'} e' s'∈ θs'≡new p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vset-shared-value-new {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡new})
with s SharedVar.≟ s'
... | yes refl =
⊥-elim
(s∉can-p-θ
(canθₛₕ-membership (Env.sig θ) 0 p Env.[]env s
(λ θ* → canₛₕ-capture-set-shared θ* p≐E⟦pin⟧)))
... | no s≢s'
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ shr* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (Θ (Env.sig θl) shr* (Env.var θl)) , GO ⟩·
E ⟦ nothin ⟧e)
(cong Env.shr
(begin
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (Env.shr-vals {s'} θl s'∈Domθl + δ e'')
≡⟨ cong
(λ v* → Env.set-shr {s'} θl s'∈Domθl SharedVar.new (v* + δ e''))
(cong proj₂ θls'≡θs') ⟩
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (θs' + δ e'')
≡⟨ cong (λ v* → Env.set-shr {s'} θl s'∈Domθl SharedVar.new
(θs' + v*))
(sym δe'≡δe'') ⟩
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (θs' + δ e')
≡⟨ cong (λ sig* → Θ (Env.sig θ) sig* (Env.var θ))
(ShrMap.put-comm {_} {Env.shr θ} {_} {_}
{SharedVar.ready ,′ θs}
{SharedVar.new ,′ θs' + δ e'}
s≢s') ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready θs
≡⟨ cong (Env.set-shr {s} θr s∈Domθr SharedVar.ready ∘ proj₂) (sym θrs≡θs) ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready
(Env.shr-vals {s} θr s∈Domθr) ∎))
(rset-shared-value-new {θl} {_} {s'} e'' s'∈Domθl
(trans (cong proj₁ θls'≡θs') θs'≡new) p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈Domθr
(Data.Sum.map (trans (cong proj₁ θrs≡θs)) (trans (cong proj₁ θrs≡θs))
θs≡old⊎θs≡new)
(λ s∈can-E⟦nothin⟧-θr →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ s*)
s s∈can-E⟦nothin⟧-θr)))
where
θs' = Env.shr-vals {s'} θ s'∈
θs = Env.shr-vals {s} θ s∈
s∈Domθr = Env.shr-set-mono' {s} {s'} {θ} {SharedVar.new} {θs' + δ e'} {s'∈} s∈
θrs≡θs = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.new ,′ θs' + δ e'}
s≢s' s∈ s∈Domθr refl
s'∈Domθl = Env.shr-set-mono' {s'} {s} {θ} {SharedVar.ready} {θs} {s∈} s'∈
θls'≡θs' = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.ready ,′ θs}
(s≢s' ∘ sym) s'∈ s'∈Domθl refl
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(var x ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p')}
{_} {_} {A} {.A} {.A} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rraise-var {θ} {p} {x} {p'} {e} e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vraise-var {.θ} {.p} {x} {p'} {e} {.E} {e'} {.p≐E⟦pin⟧})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , A ⟩· p) sn⟶₁
(ρ⟨ θl , A ⟩· E ⟦ ρ⟨ ([x,δe]-env x δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-var {θl} {_} {x} {p'} {e} e'' p≐E⟦pin⟧) ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦ρΘp'⟧-θ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ ρ⟨ [x,δe]-env x (δ e') , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tvar (δ e') x e p') p≐E⟦pin⟧ S*)
S S∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(var x ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p')}
{_} {_} {A} {.A} {.A} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rraise-var {θ} {p} {x} {p'} {e} e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vraise-var {.θ} {.p} {x} {p'} {e} {.E} {e'} {.p≐E⟦pin⟧})
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , A ⟩· p) sn⟶₁
(ρ⟨ θl , A ⟩· E ⟦ ρ⟨ ([x,δe]-env x δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-var {θl} {_} {x} {p'} {e} e'' p≐E⟦pin⟧) ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦ρΘp'⟧-θ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ ρ⟨ [x,δe]-env x (δ e') , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tvar (δ e') x e p') p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-raise θ* (tvar (δ e') x e p') p≐E⟦pin⟧ s*)
s s∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr}
{_} {E} {.(x ≔ e)} {.nothin} {_} {_} {A} {.A} {.A} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rset-var {θ} {p} {x} {e} x∈ e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vset-var {.θ} {.p} {x} {e} {.E} {x∈} {e'} {.p≐E⟦pin⟧})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , A ⟩· p sn⟶₁
ρ⟨ (θl-set-var δe*) , A ⟩· E ⟦ nothin ⟧e)
(sym δe'≡δe'')
(rset-var {θl} {_} {x} {e} x∈ e'' p≐E⟦pin⟧) ,′
rabsence {θr} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦nothin⟧-θ' →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-var x e) p≐E⟦pin⟧ S*)
S S∈can-E⟦nothin⟧-θ')))
where
θl-set-var : ℕ → Env
θl-set-var n = Env.set-var {x} θl x∈ n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr}
{_} {E} {.(x ≔ e)} {.nothin} {_} {_} {A} {.A} {.A} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rset-var {θ} {p} {x} {e} x∈ e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vset-var {.θ} {.p} {x} {e} {.E} {x∈} {e'} {.p≐E⟦pin⟧})
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , A ⟩· p sn⟶₁
ρ⟨ (θl-set-var δe*) , A ⟩· E ⟦ nothin ⟧e)
(sym δe'≡δe'')
(rset-var {θl} {_} {x} {e} x∈ e'' p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦nothin⟧-θ' →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-var x e) p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-term-nothin θ* θ* refl (tset-var x e) p≐E⟦pin⟧ s*)
s s∈can-E⟦nothin⟧-θ')))
where
θl-set-var : ℕ → Env
θl-set-var n = Env.set-var {x} θl x∈ n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ th ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vif-false {.θ} {.p} {th} {.qin} {x} {.E} {x∈} {θx≡zero} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-false θ* p≐E⟦pin⟧ S*)
S S∈can-E⟦qin⟧)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ th ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vif-false {.θ} {.p} {th} {.qin} {x} {.E} {x∈} {θx≡zero} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-false θ* p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-if-false θ* p≐E⟦pin⟧ s*)
s s∈can-E⟦qin⟧)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ qin ∣⇒ els)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rif-true {x = x} {E} {n} x∈ θx≡suc p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vif-true {.θ} {.p} {.qin} {els} {x} {.E} {n} {x∈} {θx≡suc} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-true {x = x} x∈ θx≡suc p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-true θ* p≐E⟦pin⟧ S*)
S S∈can-E⟦qin⟧)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ qin ∣⇒ els)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rif-true {x = x} {E} {n} x∈ θx≡suc p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vif-true {.θ} {.p} {.qin} {els} {x} {.E} {n} {x∈} {θx≡suc} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-true {x = x} x∈ θx≡suc p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-true θ* p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-if-true θ* p≐E⟦pin⟧ s*)
s s∈can-E⟦qin⟧)))
| 42.740397
| 137
| 0.45254
|
291624ab2602e7a17b001193f29b65afdfe8bf44
| 1,664
|
agda
|
Agda
|
Univalence/Pi0Semiring.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/Pi0Semiring.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/Pi0Semiring.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module Pi0Semiring where
import Level
open import PiU
open import PiLevel0
open import Algebra using (CommutativeSemiring)
open import Algebra.Structures
using (IsSemigroup; IsCommutativeMonoid; IsCommutativeSemiring)
------------------------------------------------------------------------------
-- Commutative semiring structure of U
typesPlusIsSG : IsSemigroup _⟷_ PLUS
typesPlusIsSG = record {
isEquivalence = record { refl = id⟷ ; sym = ! ; trans = _◎_ } ;
assoc = λ t₁ t₂ t₃ → assocr₊ {t₁} {t₂} {t₃} ;
∙-cong = _⊕_
}
typesTimesIsSG : IsSemigroup _⟷_ TIMES
typesTimesIsSG = record {
isEquivalence = record { refl = id⟷ ; sym = ! ; trans = _◎_ } ;
assoc = λ t₁ t₂ t₃ → assocr⋆ {t₁} {t₂} {t₃} ;
∙-cong = _⊗_
}
typesPlusIsCM : IsCommutativeMonoid _⟷_ PLUS ZERO
typesPlusIsCM = record {
isSemigroup = typesPlusIsSG ;
identityˡ = λ t → unite₊l {t} ;
comm = λ t₁ t₂ → swap₊ {t₁} {t₂}
}
typesTimesIsCM : IsCommutativeMonoid _⟷_ TIMES ONE
typesTimesIsCM = record {
isSemigroup = typesTimesIsSG ;
identityˡ = λ t → unite⋆l {t} ;
comm = λ t₁ t₂ → swap⋆ {t₁} {t₂}
}
typesIsCSR : IsCommutativeSemiring _⟷_ PLUS TIMES ZERO ONE
typesIsCSR = record {
+-isCommutativeMonoid = typesPlusIsCM ;
*-isCommutativeMonoid = typesTimesIsCM ;
distribʳ = λ t₁ t₂ t₃ → dist {t₂} {t₃} {t₁} ;
zeroˡ = λ t → absorbr {t}
}
typesCSR : CommutativeSemiring Level.zero Level.zero
typesCSR = record {
Carrier = U ;
_≈_ = _⟷_ ;
_+_ = PLUS ;
_*_ = TIMES ;
0# = ZERO ;
1# = ONE ;
isCommutativeSemiring = typesIsCSR
}
------------------------------------------------------------------------------
| 25.6
| 78
| 0.602163
|
39f1db7849806cd4d7fa25d67003b627da323b5b
| 4,539
|
agda
|
Agda
|
Cubical/Algebra/Ring/BigOps.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/Ring/BigOps.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring/BigOps.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
-- define ∑ and ∏ as the bigOps of a Ring when interpreted
-- as an additive/multiplicative monoid
{-# OPTIONS --safe #-}
module Cubical.Algebra.Ring.BigOps where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ ; zero ; suc)
open import Cubical.Data.FinData
open import Cubical.Data.Bool
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Monoid.BigOp
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring.Base
open import Cubical.Algebra.Ring.Properties
private
variable
ℓ ℓ' : Level
module KroneckerDelta (R' : Ring ℓ) where
private
R = fst R'
open RingStr (snd R')
δ : {n : ℕ} (i j : Fin n) → R
δ i j = if i == j then 1r else 0r
module Sum (R' : Ring ℓ) where
private
R = fst R'
open RingStr (snd R')
open MonoidBigOp (Ring→AddMonoid R')
open RingTheory R'
open KroneckerDelta R'
∑ = bigOp
∑Ext = bigOpExt
∑0r = bigOpε
∑Last = bigOpLast
∑Split : ∀ {n} → (V W : FinVec R n) → ∑ (λ i → V i + W i) ≡ ∑ V + ∑ W
∑Split = bigOpSplit +Comm
∑Split++ : ∀ {n m : ℕ} (V : FinVec R n) (W : FinVec R m)
→ ∑ (V ++Fin W) ≡ ∑ V + ∑ W
∑Split++ = bigOpSplit++ +Comm
∑Mulrdist : ∀ {n} → (x : R) → (V : FinVec R n)
→ x · ∑ V ≡ ∑ λ i → x · V i
∑Mulrdist {n = zero} x _ = 0RightAnnihilates x
∑Mulrdist {n = suc n} x V =
x · (V zero + ∑ (V ∘ suc)) ≡⟨ ·Rdist+ _ _ _ ⟩
x · V zero + x · ∑ (V ∘ suc) ≡⟨ (λ i → x · V zero + ∑Mulrdist x (V ∘ suc) i) ⟩
x · V zero + ∑ (λ i → x · V (suc i)) ∎
∑Mulldist : ∀ {n} → (x : R) → (V : FinVec R n)
→ (∑ V) · x ≡ ∑ λ i → V i · x
∑Mulldist {n = zero} x _ = 0LeftAnnihilates x
∑Mulldist {n = suc n} x V =
(V zero + ∑ (V ∘ suc)) · x ≡⟨ ·Ldist+ _ _ _ ⟩
V zero · x + (∑ (V ∘ suc)) · x ≡⟨ (λ i → V zero · x + ∑Mulldist x (V ∘ suc) i) ⟩
V zero · x + ∑ (λ i → V (suc i) · x) ∎
∑Mulr0 : ∀ {n} → (V : FinVec R n) → ∑ (λ i → V i · 0r) ≡ 0r
∑Mulr0 V = sym (∑Mulldist 0r V) ∙ 0RightAnnihilates _
∑Mul0r : ∀ {n} → (V : FinVec R n) → ∑ (λ i → 0r · V i) ≡ 0r
∑Mul0r V = sym (∑Mulrdist 0r V) ∙ 0LeftAnnihilates _
∑Mulr1 : (n : ℕ) (V : FinVec R n) → (j : Fin n) → ∑ (λ i → V i · δ i j) ≡ V j
∑Mulr1 (suc n) V zero = (λ k → ·Rid (V zero) k + ∑Mulr0 (V ∘ suc) k) ∙ +Rid (V zero)
∑Mulr1 (suc n) V (suc j) =
(λ i → 0RightAnnihilates (V zero) i + ∑ (λ x → V (suc x) · δ x j))
∙∙ +Lid _ ∙∙ ∑Mulr1 n (V ∘ suc) j
∑Mul1r : (n : ℕ) (V : FinVec R n) → (j : Fin n) → ∑ (λ i → (δ j i) · V i) ≡ V j
∑Mul1r (suc n) V zero = (λ k → ·Lid (V zero) k + ∑Mul0r (V ∘ suc) k) ∙ +Rid (V zero)
∑Mul1r (suc n) V (suc j) =
(λ i → 0LeftAnnihilates (V zero) i + ∑ (λ i → (δ j i) · V (suc i)))
∙∙ +Lid _ ∙∙ ∑Mul1r n (V ∘ suc) j
∑Dist- : ∀ {n : ℕ} (V : FinVec R n) → ∑ (λ i → - V i) ≡ - ∑ V
∑Dist- V = ∑Ext (λ i → -IsMult-1 (V i)) ∙ sym (∑Mulrdist _ V) ∙ sym (-IsMult-1 _)
module SumMap
(Ar@(A , Astr) : Ring ℓ)
(Br@(B , Bstr) : Ring ℓ')
(f'@(f , fstr) : RingHom Ar Br)
where
open IsRingHom fstr
open RingStr Astr using ()
renaming
( _+_ to _+A_ )
open RingStr Bstr using ()
renaming
( _+_ to _+B_ )
∑Map : {n : ℕ} → (V : FinVec A n) → f (Sum.∑ Ar V) ≡ Sum.∑ Br (λ k → f (V k))
∑Map {n = zero} V = pres0
∑Map {n = suc n} V =
f ((V zero) +A helper) ≡⟨ pres+ (V zero) helper ⟩
((f (V zero)) +B (f helper)) ≡⟨ cong (λ X → f (V zero) +B X) (∑Map (λ k → (V ∘ suc) k)) ⟩
Sum.∑ Br (λ k → f (V k)) ∎
where
helper : _
helper = foldrFin _+A_ (RingStr.0r (snd Ar)) (λ x → V (suc x))
-- anything interesting to prove here?
module Product (R' : Ring ℓ) where
private
R = fst R'
open RingStr (snd R')
open RingTheory R'
open MonoidBigOp (Ring→MultMonoid R')
∏ = bigOp
∏Ext = bigOpExt
∏0r = bigOpε
∏Last = bigOpLast
-- only holds in CommRings!
-- ∏Split : ∀ {n} → (V W : FinVec R n) → ∏ (λ i → V i · W i) ≡ ∏ V · ∏ W
-- ∏Split = bigOpSplit MultR' ·-comm
| 31.303448
| 112
| 0.551223
|
cb1ebcac57aefa7095f26d5f1263dbcaaf463afa
| 2,236
|
agda
|
Agda
|
BasicIPC/Metatheory/GentzenNormalForm-KripkeMcKinseyTarski.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIPC/Metatheory/GentzenNormalForm-KripkeMcKinseyTarski.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIPC/Metatheory/GentzenNormalForm-KripkeMcKinseyTarski.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module BasicIPC.Metatheory.GentzenNormalForm-KripkeMcKinseyTarski where
open import BasicIPC.Syntax.GentzenNormalForm public
open import BasicIPC.Semantics.KripkeMcKinseyTarski public
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = λ ξ a → eval t (mono⊩⋆ ξ γ , a)
eval (app t u) γ = (eval t γ refl≤) (eval u γ)
eval (pair t u) γ = eval t γ , eval u γ
eval (fst t) γ = π₁ (eval t γ)
eval (snd t) γ = π₂ (eval t γ)
eval unit γ = ∙
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ = ∙
eval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ World = Cx Ty
; _≤_ = _⊆_
; refl≤ = refl⊆
; trans≤ = trans⊆
; _⊩ᵅ_ = λ Γ P → Γ ⊢ⁿᵉ α P
; mono⊩ᵅ = mono⊢ⁿᵉ
}
-- Soundness and completeness with respect to the canonical model.
mutual
reflectᶜ : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊩ A
reflectᶜ {α P} t = t
reflectᶜ {A ▻ B} t = λ η a → reflectᶜ (appⁿᵉ (mono⊢ⁿᵉ η t) (reifyᶜ a))
reflectᶜ {A ∧ B} t = reflectᶜ (fstⁿᵉ t) , reflectᶜ (sndⁿᵉ t)
reflectᶜ {⊤} t = ∙
reifyᶜ : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ⁿᶠ A
reifyᶜ {α P} s = neⁿᶠ s
reifyᶜ {A ▻ B} s = lamⁿᶠ (reifyᶜ (s weak⊆ (reflectᶜ {A} (varⁿᵉ top))))
reifyᶜ {A ∧ B} s = pairⁿᶠ (reifyᶜ (π₁ s)) (reifyᶜ (π₂ s))
reifyᶜ {⊤} s = unitⁿᶠ
reflectᶜ⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ⁿᵉ Ξ → Γ ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
reifyᶜ⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ⁿᶠ Ξ
reifyᶜ⋆ {∅} ∙ = ∙
reifyᶜ⋆ {Ξ , A} (ts , t) = reifyᶜ⋆ ts , reifyᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆ⁿᵉ
trans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″
trans⊩⋆ ts us = eval⋆ (trans⊢⋆ (nf→tm⋆ (reifyᶜ⋆ ts)) (nf→tm⋆ (reifyᶜ⋆ us))) refl⊩⋆
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = nf→tm (reifyᶜ (s refl⊩⋆))
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
| 25.701149
| 82
| 0.549195
|
59948cf2299311be70bc0abf948e15756afb1abb
| 1,832
|
agda
|
Agda
|
test/LanguageConstructs.agda
|
JonathanBrouwer/agda2hs
|
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
|
[
"MIT"
] | 55
|
2020-10-20T13:36:25.000Z
|
2022-03-26T21:57:56.000Z
|
test/LanguageConstructs.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 63
|
2020-10-22T05:19:27.000Z
|
2022-02-25T15:47:30.000Z
|
test/LanguageConstructs.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 18
|
2020-10-21T22:19:09.000Z
|
2022-03-12T11:42:52.000Z
|
module LanguageConstructs where
open import Haskell.Prelude
{-# FOREIGN AGDA2HS {-# LANGUAGE LambdaCase #-} #-}
--------------------------------------------------
-- Lists
oneTwoThree : List Int
oneTwoThree = 1 ∷ 2 ∷ 3 ∷ []
{-# COMPILE AGDA2HS oneTwoThree #-}
exactlyTwo : List a → Maybe (a × a)
exactlyTwo (x ∷ y ∷ []) = Just (x , y)
exactlyTwo _ = Nothing
{-# COMPILE AGDA2HS exactlyTwo #-}
--------------------------------------------------
-- If-then-else
ifThenElse : Int → String
ifThenElse n = if n >= 10 then "big" else "small"
{-# COMPILE AGDA2HS ifThenElse #-}
--------------------------------------------------
-- Case
maybeToList : Maybe a → List a
maybeToList = λ where Nothing → []
(Just x) → x ∷ []
{-# COMPILE AGDA2HS maybeToList #-}
mhead : List a → Maybe a
mhead xs = case xs of λ where
[] → Nothing
(x ∷ _) → Just x
{-# COMPILE AGDA2HS mhead #-}
-- Applied to lambda
plus5minus5 : Int → Int
plus5minus5 n = case n + 5 of λ m → m - 5
{-# COMPILE AGDA2HS plus5minus5 #-}
-- Applied to non-lambda
len : List a → Int
len xs = case xs of length
{-# COMPILE AGDA2HS len #-}
-- Underapplied
applyToFalse : (Bool → a) → a
applyToFalse = case false of_
{-# COMPILE AGDA2HS applyToFalse #-}
caseOf : a → (a → b) → b
caseOf = case_of_
{-# COMPILE AGDA2HS caseOf #-}
--------------------------------------------------
-- Enums
enum₁ : List Int
enum₁ = enumFromTo 5 10
{-# COMPILE AGDA2HS enum₁ #-}
enum₂ : List Integer
enum₂ = enumFromThenTo 10 20 100
{-# COMPILE AGDA2HS enum₂ #-}
enum₃ : List Bool
enum₃ = enumFrom false
{-# COMPILE AGDA2HS enum₃ #-}
enum₄ : List Ordering
enum₄ = enumFromThen LT EQ
{-# COMPILE AGDA2HS enum₄ #-}
underappliedEnum : List Int → List (List Int)
underappliedEnum = map (enumFromTo 1)
{-# COMPILE AGDA2HS underappliedEnum #-}
| 21.302326
| 51
| 0.57369
|
31f718821773ee9ce7bdd8bbbfecb3f878f79948
| 879
|
agda
|
Agda
|
archive/agda-2/Oscar/Property/Extensionality.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-2/Oscar/Property/Extensionality.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-2/Oscar/Property/Extensionality.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Oscar.Property.Extensionality where
open import Oscar.Level
record Extensionality
{a} {A : Set a} {b} {B : A → Set b} {ℓ₁}
(_≤₁_ : (x : A) → B x → Set ℓ₁)
{c} {C : A → Set c} {d} {D : ∀ {x} → B x → Set d} {ℓ₂}
(_≤₂_ : ∀ {x} → C x → ∀ {y : B x} → D y → Set ℓ₂)
(μ₁ : (x : A) → C x)
(μ₂ : ∀ {x} → (y : B x) → D y)
: Set (a ⊔ ℓ₁ ⊔ b ⊔ ℓ₂) where
field
extensionality : ∀ {x} {y : B x} → x ≤₁ y → μ₁ x ≤₂ μ₂ y
open Extensionality ⦃ … ⦄ public
extension : ∀
{a} {A : Set a}
{b} {B : A → Set b}
{ℓ₁} {_≤₁_ : (x : A) → B x → Set ℓ₁}
{c} {C : A → Set c} {d} {D : ∀ {x} → B x → Set d} {ℓ₂}
(_≤₂_ : ∀ {x} → C x → ∀ {y : B x} → D y → Set ℓ₂)
{μ₁ : (x : A) → C x}
{μ₂ : ∀ {x} → (y : B x) → D y}
⦃ _ : Extensionality _≤₁_ _≤₂_ μ₁ μ₂ ⦄
{x} {y : B x}
→ x ≤₁ y → μ₁ x ≤₂ μ₂ y
extension _≤₂_ = extensionality {_≤₂_ = _≤₂_}
| 28.354839
| 60
| 0.431172
|
58175f345dbe2857f9928405920814726e1c742b
| 2,928
|
agda
|
Agda
|
Fields/Orders/Partial/Archimedean.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Fields/Orders/Partial/Archimedean.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Fields/Orders/Partial/Archimedean.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Sets.EquivalenceRelations
open import Numbers.Naturals.Semiring
open import Numbers.Integers.Definition
open import Numbers.Naturals.Order
open import LogicalFormulae
open import Groups.Definition
open import Rings.Orders.Partial.Definition
open import Setoids.Orders.Partial.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Rings.Definition
open import Fields.Fields
open import Fields.Orders.Partial.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Fields.Orders.Partial.Archimedean {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} {c : _} {_<_ : A → A → Set c} {pOrder : SetoidPartialOrder S _<_} {F : Field R} (p : PartiallyOrderedField F pOrder) where
open Setoid S
open Equivalence eq
open Ring R
open Group additiveGroup
open import Groups.Lemmas additiveGroup
open import Groups.Cyclic.Definition additiveGroup
open import Groups.Cyclic.DefinitionLemmas additiveGroup
open import Groups.Orders.Archimedean (toGroup R (PartiallyOrderedField.oRing p))
open import Rings.Orders.Partial.Lemmas (PartiallyOrderedField.oRing p)
open import Rings.InitialRing R
open SetoidPartialOrder pOrder
open PartiallyOrderedRing (PartiallyOrderedField.oRing p)
open Field F
ArchimedeanField : Set (a ⊔ c)
ArchimedeanField = (x : A) → (0R < x) → Sg ℕ (λ n → x < (fromN n))
private
lemma : (r : A) (N : ℕ) → (positiveEltPower 1R N * r) ∼ positiveEltPower r N
lemma r zero = timesZero'
lemma r (succ n) = transitive *DistributesOver+' (+WellDefined identIsIdent (lemma r n))
findBound : (0<1 : 0R < 1R) → (r s : A) (N : ℕ) → (1R < r) → (s < positiveEltPower 1R N) → s < positiveEltPower r N
findBound _ r s zero 1<r s<N = s<N
findBound 0<1 r s (succ N) 1<r s<N = <Transitive s<N (<WellDefined (transitive *Commutative identIsIdent) (lemma r (succ N)) (ringCanMultiplyByPositive' (fromNPreservesOrder 0<1 (succIsPositive N)) 1<r))
archFieldToGrp : ((x y : A) → .(0R < x) → (x * y) ∼ 1R → 0R < y) → ArchimedeanField → Archimedean
archFieldToGrp reciprocalPositive a r s 0<r 0<s with allInvertible r (λ r=0 → irreflexive (<WellDefined reflexive r=0 0<r))
... | inv , prInv with a inv (reciprocalPositive r inv 0<r (transitive *Commutative prInv))
... | N , invBound with a s 0<s
... | Ns , nSBound = (Ns *N N) , <WellDefined reflexive (symmetric (elementPowerMultiplies (nonneg Ns) (nonneg N) r)) (findBound (<WellDefined reflexive (transitive *Commutative prInv) (orderRespectsMultiplication 0<r (reciprocalPositive r inv 0<r (transitive *Commutative prInv)))) (positiveEltPower r N) s Ns m nSBound)
where
m : 1R < positiveEltPower r N
m = <WellDefined prInv (lemma r N) (ringCanMultiplyByPositive 0<r invBound)
archToArchField : 0R < 1R → Archimedean → ArchimedeanField
archToArchField 0<1 arch a 0<a with arch 1R a 0<1 0<a
... | N , pr = N , pr
| 49.627119
| 321
| 0.730533
|
2fb54e35d6d1df9408cedf4f14cdc028a265b26e
| 705
|
agda
|
Agda
|
test/Compiler/simple/VecReverse.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Compiler/simple/VecReverse.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Compiler/simple/VecReverse.agda
|
xekoukou/agda-ocaml
|
026a8f8473ab91f99c3f6545728e71fa847d2720
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
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 600)))
| 25.178571
| 90
| 0.475177
|
dc73acad7124149d51753fbe125fe233e75ad97c
| 2,100
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Product/Categorical/Examples.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Data/Product/Categorical/Examples.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Product/Categorical/Examples.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Universe-sensitive functor and monad instances for the Product type.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Data.Product.Categorical.Examples
{a e b} {A : Monoid a e} {B : Set b} where
open import Level using (Lift; lift; _⊔_)
open import Category.Functor using (RawFunctor)
open import Category.Monad using (RawMonad)
open import Data.Product
open import Data.Product.Relation.Binary.Pointwise.NonDependent
open import Function
import Function.Identity.Categorical as Id
open import Relation.Binary using (Rel)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
------------------------------------------------------------------------
-- Examples
-- Note that these examples are simple unit tests, because the type
-- checker verifies them.
private
module A = Monoid A
open import Data.Product.Categorical.Left A.rawMonoid b
_≈_ : Rel (A.Carrier × Lift a B) (e ⊔ a ⊔ b)
_≈_ = Pointwise A._≈_ _≡_
open RawFunctor functor
-- This type to the right of × needs to be a "lifted" version of (B : Set b)
-- that lives in the universe (Set (a ⊔ b)).
fmapIdₗ : (x : A.Carrier × Lift a B) → (id <$> x) ≈ x
fmapIdₗ x = A.refl , refl
open RawMonad monad
-- Now, let's show that "return" is a unit for >>=. We use Lift in exactly
-- the same way as above. The data (x : B) then needs to be "lifted" to
-- this new type (Lift B).
returnUnitL : ∀ {x : B} {f : Lift a B → A.Carrier × Lift a B} →
((return (lift x)) >>= f) ≈ f (lift x)
returnUnitL = A.identityˡ _ , refl
returnUnitR : {x : A.Carrier × Lift a B} → (x >>= return) ≈ x
returnUnitR = A.identityʳ _ , refl
-- And another (limited version of a) monad law...
bindCompose : ∀ {f g : Lift a B → A.Carrier × Lift a B} →
{x : A.Carrier × Lift a B} →
((x >>= f) >>= g) ≈ (x >>= (λ y → (f y >>= g)))
bindCompose = A.assoc _ _ _ , refl
| 33.333333
| 78
| 0.57619
|
299f648cfdc4094f77243c5efd93c26d2263296c
| 19,747
|
agda
|
Agda
|
prototyping/Properties/TypeNormalization.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-12-05T21:53:03.000Z
|
2021-12-05T21:53:03.000Z
|
prototyping/Properties/TypeNormalization.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/Properties/TypeNormalization.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Properties.TypeNormalization where
open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_)
open import Luau.Subtyping using (scalar-function-err)
open import Luau.TypeNormalization using (_∪ⁿ_; _∩ⁿ_; _∪ᶠ_; _∪ⁿˢ_; _∩ⁿˢ_; normalize)
open import Luau.Subtyping using (_<:_)
open import Properties.Subtyping using (<:-trans; <:-refl; <:-unknown; <:-never; <:-∪-left; <:-∪-right; <:-∪-lub; <:-∩-left; <:-∩-right; <:-∩-glb; <:-∩-symm; <:-function; <:-function-∪-∩; <:-function-∩-∪; <:-function-∪; <:-everything; <:-union; <:-∪-assocl; <:-∪-assocr; <:-∪-symm; <:-intersect; ∪-distl-∩-<:; ∪-distr-∩-<:; <:-∪-distr-∩; <:-∪-distl-∩; ∩-distl-∪-<:; <:-∩-distl-∪; <:-∩-distr-∪; scalar-∩-function-<:-never; scalar-≢-∩-<:-never)
-- Notmal forms for types
data FunType : Type → Set
data Normal : Type → Set
data FunType where
_⇒_ : ∀ {S T} → Normal S → Normal T → FunType (S ⇒ T)
_∩_ : ∀ {F G} → FunType F → FunType G → FunType (F ∩ G)
data Normal where
never : Normal never
unknown : Normal unknown
_⇒_ : ∀ {S T} → Normal S → Normal T → Normal (S ⇒ T)
_∩_ : ∀ {F G} → FunType F → FunType G → Normal (F ∩ G)
_∪_ : ∀ {S T} → Normal S → Scalar T → Normal (S ∪ T)
data OptScalar : Type → Set where
never : OptScalar never
number : OptScalar number
boolean : OptScalar boolean
string : OptScalar string
nil : OptScalar nil
-- Normalization produces normal types
normal : ∀ T → Normal (normalize T)
normalᶠ : ∀ {F} → FunType F → Normal F
normal-∪ⁿ : ∀ {S T} → Normal S → Normal T → Normal (S ∪ⁿ T)
normal-∩ⁿ : ∀ {S T} → Normal S → Normal T → Normal (S ∩ⁿ T)
normal-∪ⁿˢ : ∀ {S T} → Normal S → OptScalar T → Normal (S ∪ⁿˢ T)
normal-∩ⁿˢ : ∀ {S T} → Normal S → Scalar T → OptScalar (S ∩ⁿˢ T)
normal-∪ᶠ : ∀ {F G} → FunType F → FunType G → FunType (F ∪ᶠ G)
normal nil = never ∪ nil
normal (S ⇒ T) = normalᶠ ((normal S) ⇒ (normal T))
normal never = never
normal unknown = unknown
normal boolean = never ∪ boolean
normal number = never ∪ number
normal string = never ∪ string
normal (S ∪ T) = normal-∪ⁿ (normal S) (normal T)
normal (S ∩ T) = normal-∩ⁿ (normal S) (normal T)
normalᶠ (S ⇒ T) = S ⇒ T
normalᶠ (F ∩ G) = F ∩ G
normal-∪ⁿ S (T₁ ∪ T₂) = (normal-∪ⁿ S T₁) ∪ T₂
normal-∪ⁿ S never = S
normal-∪ⁿ S unknown = unknown
normal-∪ⁿ never (T ⇒ U) = T ⇒ U
normal-∪ⁿ never (G₁ ∩ G₂) = G₁ ∩ G₂
normal-∪ⁿ unknown (T ⇒ U) = unknown
normal-∪ⁿ unknown (G₁ ∩ G₂) = unknown
normal-∪ⁿ (R ⇒ S) (T ⇒ U) = normalᶠ (normal-∪ᶠ (R ⇒ S) (T ⇒ U))
normal-∪ⁿ (R ⇒ S) (G₁ ∩ G₂) = normalᶠ (normal-∪ᶠ (R ⇒ S) (G₁ ∩ G₂))
normal-∪ⁿ (F₁ ∩ F₂) (T ⇒ U) = normalᶠ (normal-∪ᶠ (F₁ ∩ F₂) (T ⇒ U))
normal-∪ⁿ (F₁ ∩ F₂) (G₁ ∩ G₂) = normalᶠ (normal-∪ᶠ (F₁ ∩ F₂) (G₁ ∩ G₂))
normal-∪ⁿ (S₁ ∪ S₂) (T₁ ⇒ T₂) = normal-∪ⁿ S₁ (T₁ ⇒ T₂) ∪ S₂
normal-∪ⁿ (S₁ ∪ S₂) (G₁ ∩ G₂) = normal-∪ⁿ S₁ (G₁ ∩ G₂) ∪ S₂
normal-∩ⁿ S never = never
normal-∩ⁿ S unknown = S
normal-∩ⁿ S (T ∪ U) = normal-∪ⁿˢ (normal-∩ⁿ S T) (normal-∩ⁿˢ S U )
normal-∩ⁿ never (T ⇒ U) = never
normal-∩ⁿ unknown (T ⇒ U) = T ⇒ U
normal-∩ⁿ (R ⇒ S) (T ⇒ U) = (R ⇒ S) ∩ (T ⇒ U)
normal-∩ⁿ (R ∩ S) (T ⇒ U) = (R ∩ S) ∩ (T ⇒ U)
normal-∩ⁿ (R ∪ S) (T ⇒ U) = normal-∩ⁿ R (T ⇒ U)
normal-∩ⁿ never (T ∩ U) = never
normal-∩ⁿ unknown (T ∩ U) = T ∩ U
normal-∩ⁿ (R ⇒ S) (T ∩ U) = (R ⇒ S) ∩ (T ∩ U)
normal-∩ⁿ (R ∩ S) (T ∩ U) = (R ∩ S) ∩ (T ∩ U)
normal-∩ⁿ (R ∪ S) (T ∩ U) = normal-∩ⁿ R (T ∩ U)
normal-∪ⁿˢ S never = S
normal-∪ⁿˢ never number = never ∪ number
normal-∪ⁿˢ unknown number = unknown
normal-∪ⁿˢ (R ⇒ S) number = (R ⇒ S) ∪ number
normal-∪ⁿˢ (R ∩ S) number = (R ∩ S) ∪ number
normal-∪ⁿˢ (R ∪ number) number = R ∪ number
normal-∪ⁿˢ (R ∪ boolean) number = normal-∪ⁿˢ R number ∪ boolean
normal-∪ⁿˢ (R ∪ string) number = normal-∪ⁿˢ R number ∪ string
normal-∪ⁿˢ (R ∪ nil) number = normal-∪ⁿˢ R number ∪ nil
normal-∪ⁿˢ never boolean = never ∪ boolean
normal-∪ⁿˢ unknown boolean = unknown
normal-∪ⁿˢ (R ⇒ S) boolean = (R ⇒ S) ∪ boolean
normal-∪ⁿˢ (R ∩ S) boolean = (R ∩ S) ∪ boolean
normal-∪ⁿˢ (R ∪ number) boolean = normal-∪ⁿˢ R boolean ∪ number
normal-∪ⁿˢ (R ∪ boolean) boolean = R ∪ boolean
normal-∪ⁿˢ (R ∪ string) boolean = normal-∪ⁿˢ R boolean ∪ string
normal-∪ⁿˢ (R ∪ nil) boolean = normal-∪ⁿˢ R boolean ∪ nil
normal-∪ⁿˢ never string = never ∪ string
normal-∪ⁿˢ unknown string = unknown
normal-∪ⁿˢ (R ⇒ S) string = (R ⇒ S) ∪ string
normal-∪ⁿˢ (R ∩ S) string = (R ∩ S) ∪ string
normal-∪ⁿˢ (R ∪ number) string = normal-∪ⁿˢ R string ∪ number
normal-∪ⁿˢ (R ∪ boolean) string = normal-∪ⁿˢ R string ∪ boolean
normal-∪ⁿˢ (R ∪ string) string = R ∪ string
normal-∪ⁿˢ (R ∪ nil) string = normal-∪ⁿˢ R string ∪ nil
normal-∪ⁿˢ never nil = never ∪ nil
normal-∪ⁿˢ unknown nil = unknown
normal-∪ⁿˢ (R ⇒ S) nil = (R ⇒ S) ∪ nil
normal-∪ⁿˢ (R ∩ S) nil = (R ∩ S) ∪ nil
normal-∪ⁿˢ (R ∪ number) nil = normal-∪ⁿˢ R nil ∪ number
normal-∪ⁿˢ (R ∪ boolean) nil = normal-∪ⁿˢ R nil ∪ boolean
normal-∪ⁿˢ (R ∪ string) nil = normal-∪ⁿˢ R nil ∪ string
normal-∪ⁿˢ (R ∪ nil) nil = R ∪ nil
normal-∩ⁿˢ never number = never
normal-∩ⁿˢ never boolean = never
normal-∩ⁿˢ never string = never
normal-∩ⁿˢ never nil = never
normal-∩ⁿˢ unknown number = number
normal-∩ⁿˢ unknown boolean = boolean
normal-∩ⁿˢ unknown string = string
normal-∩ⁿˢ unknown nil = nil
normal-∩ⁿˢ (R ⇒ S) number = never
normal-∩ⁿˢ (R ⇒ S) boolean = never
normal-∩ⁿˢ (R ⇒ S) string = never
normal-∩ⁿˢ (R ⇒ S) nil = never
normal-∩ⁿˢ (R ∩ S) number = never
normal-∩ⁿˢ (R ∩ S) boolean = never
normal-∩ⁿˢ (R ∩ S) string = never
normal-∩ⁿˢ (R ∩ S) nil = never
normal-∩ⁿˢ (R ∪ number) number = number
normal-∩ⁿˢ (R ∪ boolean) number = normal-∩ⁿˢ R number
normal-∩ⁿˢ (R ∪ string) number = normal-∩ⁿˢ R number
normal-∩ⁿˢ (R ∪ nil) number = normal-∩ⁿˢ R number
normal-∩ⁿˢ (R ∪ number) boolean = normal-∩ⁿˢ R boolean
normal-∩ⁿˢ (R ∪ boolean) boolean = boolean
normal-∩ⁿˢ (R ∪ string) boolean = normal-∩ⁿˢ R boolean
normal-∩ⁿˢ (R ∪ nil) boolean = normal-∩ⁿˢ R boolean
normal-∩ⁿˢ (R ∪ number) string = normal-∩ⁿˢ R string
normal-∩ⁿˢ (R ∪ boolean) string = normal-∩ⁿˢ R string
normal-∩ⁿˢ (R ∪ string) string = string
normal-∩ⁿˢ (R ∪ nil) string = normal-∩ⁿˢ R string
normal-∩ⁿˢ (R ∪ number) nil = normal-∩ⁿˢ R nil
normal-∩ⁿˢ (R ∪ boolean) nil = normal-∩ⁿˢ R nil
normal-∩ⁿˢ (R ∪ string) nil = normal-∩ⁿˢ R nil
normal-∩ⁿˢ (R ∪ nil) nil = nil
normal-∪ᶠ (R ⇒ S) (T ⇒ U) = (normal-∩ⁿ R T) ⇒ (normal-∪ⁿ S U)
normal-∪ᶠ (R ⇒ S) (G ∩ H) = normal-∪ᶠ (R ⇒ S) G ∩ normal-∪ᶠ (R ⇒ S) H
normal-∪ᶠ (E ∩ F) G = normal-∪ᶠ E G ∩ normal-∪ᶠ F G
scalar-∩-fun-<:-never : ∀ {F S} → FunType F → Scalar S → (F ∩ S) <: never
scalar-∩-fun-<:-never (T ⇒ U) S = scalar-∩-function-<:-never S
scalar-∩-fun-<:-never (F ∩ G) S = <:-trans (<:-intersect <:-∩-left <:-refl) (scalar-∩-fun-<:-never F S)
flipper : ∀ {S T U} → ((S ∪ T) ∪ U) <: ((S ∪ U) ∪ T)
flipper = <:-trans <:-∪-assocr (<:-trans (<:-union <:-refl <:-∪-symm) <:-∪-assocl)
∩-<:-∩ⁿ : ∀ {S T} → Normal S → Normal T → (S ∩ T) <: (S ∩ⁿ T)
∩ⁿ-<:-∩ : ∀ {S T} → Normal S → Normal T → (S ∩ⁿ T) <: (S ∩ T)
∩-<:-∩ⁿˢ : ∀ {S T} → Normal S → Scalar T → (S ∩ T) <: (S ∩ⁿˢ T)
∩ⁿˢ-<:-∩ : ∀ {S T} → Normal S → Scalar T → (S ∩ⁿˢ T) <: (S ∩ T)
∪ᶠ-<:-∪ : ∀ {F G} → FunType F → FunType G → (F ∪ᶠ G) <: (F ∪ G)
∪ⁿ-<:-∪ : ∀ {S T} → Normal S → Normal T → (S ∪ⁿ T) <: (S ∪ T)
∪-<:-∪ⁿ : ∀ {S T} → Normal S → Normal T → (S ∪ T) <: (S ∪ⁿ T)
∪ⁿˢ-<:-∪ : ∀ {S T} → Normal S → OptScalar T → (S ∪ⁿˢ T) <: (S ∪ T)
∪-<:-∪ⁿˢ : ∀ {S T} → Normal S → OptScalar T → (S ∪ T) <: (S ∪ⁿˢ T)
∩-<:-∩ⁿ S never = <:-∩-right
∩-<:-∩ⁿ S unknown = <:-∩-left
∩-<:-∩ⁿ S (T ∪ U) = <:-trans <:-∩-distl-∪ (<:-trans (<:-union (∩-<:-∩ⁿ S T) (∩-<:-∩ⁿˢ S U)) (∪-<:-∪ⁿˢ (normal-∩ⁿ S T) (normal-∩ⁿˢ S U)) )
∩-<:-∩ⁿ never (T ⇒ U) = <:-∩-left
∩-<:-∩ⁿ unknown (T ⇒ U) = <:-∩-right
∩-<:-∩ⁿ (R ⇒ S) (T ⇒ U) = <:-refl
∩-<:-∩ⁿ (R ∩ S) (T ⇒ U) = <:-refl
∩-<:-∩ⁿ (R ∪ S) (T ⇒ U) = <:-trans <:-∩-distr-∪ (<:-trans (<:-union (∩-<:-∩ⁿ R (T ⇒ U)) (<:-trans <:-∩-symm (∩-<:-∩ⁿˢ (T ⇒ U) S))) (<:-∪-lub <:-refl <:-never))
∩-<:-∩ⁿ never (T ∩ U) = <:-∩-left
∩-<:-∩ⁿ unknown (T ∩ U) = <:-∩-right
∩-<:-∩ⁿ (R ⇒ S) (T ∩ U) = <:-refl
∩-<:-∩ⁿ (R ∩ S) (T ∩ U) = <:-refl
∩-<:-∩ⁿ (R ∪ S) (T ∩ U) = <:-trans <:-∩-distr-∪ (<:-trans (<:-union (∩-<:-∩ⁿ R (T ∩ U)) (<:-trans <:-∩-symm (∩-<:-∩ⁿˢ (T ∩ U) S))) (<:-∪-lub <:-refl <:-never))
∩ⁿ-<:-∩ S never = <:-never
∩ⁿ-<:-∩ S unknown = <:-∩-glb <:-refl <:-unknown
∩ⁿ-<:-∩ S (T ∪ U) = <:-trans (∪ⁿˢ-<:-∪ (normal-∩ⁿ S T) (normal-∩ⁿˢ S U)) (<:-trans (<:-union (∩ⁿ-<:-∩ S T) (∩ⁿˢ-<:-∩ S U)) ∩-distl-∪-<:)
∩ⁿ-<:-∩ never (T ⇒ U) = <:-never
∩ⁿ-<:-∩ unknown (T ⇒ U) = <:-∩-glb <:-unknown <:-refl
∩ⁿ-<:-∩ (R ⇒ S) (T ⇒ U) = <:-refl
∩ⁿ-<:-∩ (R ∩ S) (T ⇒ U) = <:-refl
∩ⁿ-<:-∩ (R ∪ S) (T ⇒ U) = <:-trans (∩ⁿ-<:-∩ R (T ⇒ U)) (<:-∩-glb (<:-trans <:-∩-left <:-∪-left) <:-∩-right)
∩ⁿ-<:-∩ never (T ∩ U) = <:-never
∩ⁿ-<:-∩ unknown (T ∩ U) = <:-∩-glb <:-unknown <:-refl
∩ⁿ-<:-∩ (R ⇒ S) (T ∩ U) = <:-refl
∩ⁿ-<:-∩ (R ∩ S) (T ∩ U) = <:-refl
∩ⁿ-<:-∩ (R ∪ S) (T ∩ U) = <:-trans (∩ⁿ-<:-∩ R (T ∩ U)) (<:-∩-glb (<:-trans <:-∩-left <:-∪-left) <:-∩-right)
∩-<:-∩ⁿˢ never number = <:-∩-left
∩-<:-∩ⁿˢ never boolean = <:-∩-left
∩-<:-∩ⁿˢ never string = <:-∩-left
∩-<:-∩ⁿˢ never nil = <:-∩-left
∩-<:-∩ⁿˢ unknown T = <:-∩-right
∩-<:-∩ⁿˢ (R ⇒ S) T = scalar-∩-fun-<:-never (R ⇒ S) T
∩-<:-∩ⁿˢ (F ∩ G) T = scalar-∩-fun-<:-never (F ∩ G) T
∩-<:-∩ⁿˢ (R ∪ number) number = <:-∩-right
∩-<:-∩ⁿˢ (R ∪ boolean) number = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R number) (scalar-≢-∩-<:-never boolean number (λ ())))
∩-<:-∩ⁿˢ (R ∪ string) number = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R number) (scalar-≢-∩-<:-never string number (λ ())))
∩-<:-∩ⁿˢ (R ∪ nil) number = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R number) (scalar-≢-∩-<:-never nil number (λ ())))
∩-<:-∩ⁿˢ (R ∪ number) boolean = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R boolean) (scalar-≢-∩-<:-never number boolean (λ ())))
∩-<:-∩ⁿˢ (R ∪ boolean) boolean = <:-∩-right
∩-<:-∩ⁿˢ (R ∪ string) boolean = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R boolean) (scalar-≢-∩-<:-never string boolean (λ ())))
∩-<:-∩ⁿˢ (R ∪ nil) boolean = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R boolean) (scalar-≢-∩-<:-never nil boolean (λ ())))
∩-<:-∩ⁿˢ (R ∪ number) string = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R string) (scalar-≢-∩-<:-never number string (λ ())))
∩-<:-∩ⁿˢ (R ∪ boolean) string = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R string) (scalar-≢-∩-<:-never boolean string (λ ())))
∩-<:-∩ⁿˢ (R ∪ string) string = <:-∩-right
∩-<:-∩ⁿˢ (R ∪ nil) string = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R string) (scalar-≢-∩-<:-never nil string (λ ())))
∩-<:-∩ⁿˢ (R ∪ number) nil = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R nil) (scalar-≢-∩-<:-never number nil (λ ())))
∩-<:-∩ⁿˢ (R ∪ boolean) nil = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R nil) (scalar-≢-∩-<:-never boolean nil (λ ())))
∩-<:-∩ⁿˢ (R ∪ string) nil = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R nil) (scalar-≢-∩-<:-never string nil (λ ())))
∩-<:-∩ⁿˢ (R ∪ nil) nil = <:-∩-right
∩ⁿˢ-<:-∩ never T = <:-never
∩ⁿˢ-<:-∩ unknown T = <:-∩-glb <:-unknown <:-refl
∩ⁿˢ-<:-∩ (R ⇒ S) T = <:-never
∩ⁿˢ-<:-∩ (F ∩ G) T = <:-never
∩ⁿˢ-<:-∩ (R ∪ number) number = <:-∩-glb <:-∪-right <:-refl
∩ⁿˢ-<:-∩ (R ∪ boolean) number = <:-trans (∩ⁿˢ-<:-∩ R number) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ string) number = <:-trans (∩ⁿˢ-<:-∩ R number) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ nil) number = <:-trans (∩ⁿˢ-<:-∩ R number) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ number) boolean = <:-trans (∩ⁿˢ-<:-∩ R boolean) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ boolean) boolean = <:-∩-glb <:-∪-right <:-refl
∩ⁿˢ-<:-∩ (R ∪ string) boolean = <:-trans (∩ⁿˢ-<:-∩ R boolean) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ nil) boolean = <:-trans (∩ⁿˢ-<:-∩ R boolean) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ number) string = <:-trans (∩ⁿˢ-<:-∩ R string) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ boolean) string = <:-trans (∩ⁿˢ-<:-∩ R string) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ string) string = <:-∩-glb <:-∪-right <:-refl
∩ⁿˢ-<:-∩ (R ∪ nil) string = <:-trans (∩ⁿˢ-<:-∩ R string) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ number) nil = <:-trans (∩ⁿˢ-<:-∩ R nil) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ boolean) nil = <:-trans (∩ⁿˢ-<:-∩ R nil) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ string) nil = <:-trans (∩ⁿˢ-<:-∩ R nil) (<:-intersect <:-∪-left <:-refl)
∩ⁿˢ-<:-∩ (R ∪ nil) nil = <:-∩-glb <:-∪-right <:-refl
∪ᶠ-<:-∪ (R ⇒ S) (T ⇒ U) = <:-trans (<:-function (∩-<:-∩ⁿ R T) (∪ⁿ-<:-∪ S U)) <:-function-∪-∩
∪ᶠ-<:-∪ (R ⇒ S) (G ∩ H) = <:-trans (<:-intersect (∪ᶠ-<:-∪ (R ⇒ S) G) (∪ᶠ-<:-∪ (R ⇒ S) H)) ∪-distl-∩-<:
∪ᶠ-<:-∪ (E ∩ F) G = <:-trans (<:-intersect (∪ᶠ-<:-∪ E G) (∪ᶠ-<:-∪ F G)) ∪-distr-∩-<:
∪-<:-∪ᶠ : ∀ {F G} → FunType F → FunType G → (F ∪ G) <: (F ∪ᶠ G)
∪-<:-∪ᶠ (R ⇒ S) (T ⇒ U) = <:-trans <:-function-∪ (<:-function (∩ⁿ-<:-∩ R T) (∪-<:-∪ⁿ S U))
∪-<:-∪ᶠ (R ⇒ S) (G ∩ H) = <:-trans <:-∪-distl-∩ (<:-intersect (∪-<:-∪ᶠ (R ⇒ S) G) (∪-<:-∪ᶠ (R ⇒ S) H))
∪-<:-∪ᶠ (E ∩ F) G = <:-trans <:-∪-distr-∩ (<:-intersect (∪-<:-∪ᶠ E G) (∪-<:-∪ᶠ F G))
∪ⁿˢ-<:-∪ S never = <:-∪-left
∪ⁿˢ-<:-∪ never number = <:-refl
∪ⁿˢ-<:-∪ never boolean = <:-refl
∪ⁿˢ-<:-∪ never string = <:-refl
∪ⁿˢ-<:-∪ never nil = <:-refl
∪ⁿˢ-<:-∪ unknown number = <:-∪-left
∪ⁿˢ-<:-∪ unknown boolean = <:-∪-left
∪ⁿˢ-<:-∪ unknown string = <:-∪-left
∪ⁿˢ-<:-∪ unknown nil = <:-∪-left
∪ⁿˢ-<:-∪ (R ⇒ S) number = <:-refl
∪ⁿˢ-<:-∪ (R ⇒ S) boolean = <:-refl
∪ⁿˢ-<:-∪ (R ⇒ S) string = <:-refl
∪ⁿˢ-<:-∪ (R ⇒ S) nil = <:-refl
∪ⁿˢ-<:-∪ (R ∩ S) number = <:-refl
∪ⁿˢ-<:-∪ (R ∩ S) boolean = <:-refl
∪ⁿˢ-<:-∪ (R ∩ S) string = <:-refl
∪ⁿˢ-<:-∪ (R ∩ S) nil = <:-refl
∪ⁿˢ-<:-∪ (R ∪ number) number = <:-union <:-∪-left <:-refl
∪ⁿˢ-<:-∪ (R ∪ boolean) number = <:-trans (<:-union (∪ⁿˢ-<:-∪ R number) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ string) number = <:-trans (<:-union (∪ⁿˢ-<:-∪ R number) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ nil) number = <:-trans (<:-union (∪ⁿˢ-<:-∪ R number) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ number) boolean = <:-trans (<:-union (∪ⁿˢ-<:-∪ R boolean) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ boolean) boolean = <:-union <:-∪-left <:-refl
∪ⁿˢ-<:-∪ (R ∪ string) boolean = <:-trans (<:-union (∪ⁿˢ-<:-∪ R boolean) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ nil) boolean = <:-trans (<:-union (∪ⁿˢ-<:-∪ R boolean) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ number) string = <:-trans (<:-union (∪ⁿˢ-<:-∪ R string) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ boolean) string = <:-trans (<:-union (∪ⁿˢ-<:-∪ R string) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ string) string = <:-union <:-∪-left <:-refl
∪ⁿˢ-<:-∪ (R ∪ nil) string = <:-trans (<:-union (∪ⁿˢ-<:-∪ R string) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ number) nil = <:-trans (<:-union (∪ⁿˢ-<:-∪ R nil) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ boolean) nil = <:-trans (<:-union (∪ⁿˢ-<:-∪ R nil) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ string) nil = <:-trans (<:-union (∪ⁿˢ-<:-∪ R nil) <:-refl) flipper
∪ⁿˢ-<:-∪ (R ∪ nil) nil = <:-union <:-∪-left <:-refl
∪-<:-∪ⁿˢ T never = <:-∪-lub <:-refl <:-never
∪-<:-∪ⁿˢ never number = <:-refl
∪-<:-∪ⁿˢ never boolean = <:-refl
∪-<:-∪ⁿˢ never string = <:-refl
∪-<:-∪ⁿˢ never nil = <:-refl
∪-<:-∪ⁿˢ unknown number = <:-unknown
∪-<:-∪ⁿˢ unknown boolean = <:-unknown
∪-<:-∪ⁿˢ unknown string = <:-unknown
∪-<:-∪ⁿˢ unknown nil = <:-unknown
∪-<:-∪ⁿˢ (R ⇒ S) number = <:-refl
∪-<:-∪ⁿˢ (R ⇒ S) boolean = <:-refl
∪-<:-∪ⁿˢ (R ⇒ S) string = <:-refl
∪-<:-∪ⁿˢ (R ⇒ S) nil = <:-refl
∪-<:-∪ⁿˢ (R ∩ S) number = <:-refl
∪-<:-∪ⁿˢ (R ∩ S) boolean = <:-refl
∪-<:-∪ⁿˢ (R ∩ S) string = <:-refl
∪-<:-∪ⁿˢ (R ∩ S) nil = <:-refl
∪-<:-∪ⁿˢ (R ∪ number) number = <:-∪-lub <:-refl <:-∪-right
∪-<:-∪ⁿˢ (R ∪ boolean) number = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R number) <:-refl)
∪-<:-∪ⁿˢ (R ∪ string) number = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R number) <:-refl)
∪-<:-∪ⁿˢ (R ∪ nil) number = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R number) <:-refl)
∪-<:-∪ⁿˢ (R ∪ number) boolean = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R boolean) <:-refl)
∪-<:-∪ⁿˢ (R ∪ boolean) boolean = <:-∪-lub <:-refl <:-∪-right
∪-<:-∪ⁿˢ (R ∪ string) boolean = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R boolean) <:-refl)
∪-<:-∪ⁿˢ (R ∪ nil) boolean = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R boolean) <:-refl)
∪-<:-∪ⁿˢ (R ∪ number) string = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R string) <:-refl)
∪-<:-∪ⁿˢ (R ∪ boolean) string = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R string) <:-refl)
∪-<:-∪ⁿˢ (R ∪ string) string = <:-∪-lub <:-refl <:-∪-right
∪-<:-∪ⁿˢ (R ∪ nil) string = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R string) <:-refl)
∪-<:-∪ⁿˢ (R ∪ number) nil = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R nil) <:-refl)
∪-<:-∪ⁿˢ (R ∪ boolean) nil = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R nil) <:-refl)
∪-<:-∪ⁿˢ (R ∪ string) nil = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R nil) <:-refl)
∪-<:-∪ⁿˢ (R ∪ nil) nil = <:-∪-lub <:-refl <:-∪-right
∪ⁿ-<:-∪ S never = <:-∪-left
∪ⁿ-<:-∪ S unknown = <:-∪-right
∪ⁿ-<:-∪ never (T ⇒ U) = <:-∪-right
∪ⁿ-<:-∪ unknown (T ⇒ U) = <:-∪-left
∪ⁿ-<:-∪ (R ⇒ S) (T ⇒ U) = ∪ᶠ-<:-∪ (R ⇒ S) (T ⇒ U)
∪ⁿ-<:-∪ (R ∩ S) (T ⇒ U) = ∪ᶠ-<:-∪ (R ∩ S) (T ⇒ U)
∪ⁿ-<:-∪ (R ∪ S) (T ⇒ U) = <:-trans (<:-union (∪ⁿ-<:-∪ R (T ⇒ U)) <:-refl) (<:-∪-lub (<:-∪-lub (<:-trans <:-∪-left <:-∪-left) <:-∪-right) (<:-trans <:-∪-right <:-∪-left))
∪ⁿ-<:-∪ never (T ∩ U) = <:-∪-right
∪ⁿ-<:-∪ unknown (T ∩ U) = <:-∪-left
∪ⁿ-<:-∪ (R ⇒ S) (T ∩ U) = ∪ᶠ-<:-∪ (R ⇒ S) (T ∩ U)
∪ⁿ-<:-∪ (R ∩ S) (T ∩ U) = ∪ᶠ-<:-∪ (R ∩ S) (T ∩ U)
∪ⁿ-<:-∪ (R ∪ S) (T ∩ U) = <:-trans (<:-union (∪ⁿ-<:-∪ R (T ∩ U)) <:-refl) (<:-∪-lub (<:-∪-lub (<:-trans <:-∪-left <:-∪-left) <:-∪-right) (<:-trans <:-∪-right <:-∪-left))
∪ⁿ-<:-∪ S (T ∪ U) = <:-∪-lub (<:-trans (∪ⁿ-<:-∪ S T) (<:-union <:-refl <:-∪-left)) (<:-trans <:-∪-right <:-∪-right)
∪-<:-∪ⁿ S never = <:-∪-lub <:-refl <:-never
∪-<:-∪ⁿ S unknown = <:-unknown
∪-<:-∪ⁿ never (T ⇒ U) = <:-∪-lub <:-never <:-refl
∪-<:-∪ⁿ unknown (T ⇒ U) = <:-unknown
∪-<:-∪ⁿ (R ⇒ S) (T ⇒ U) = ∪-<:-∪ᶠ (R ⇒ S) (T ⇒ U)
∪-<:-∪ⁿ (R ∩ S) (T ⇒ U) = ∪-<:-∪ᶠ (R ∩ S) (T ⇒ U)
∪-<:-∪ⁿ (R ∪ S) (T ⇒ U) = <:-trans <:-∪-assocr (<:-trans (<:-union <:-refl <:-∪-symm) (<:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ R (T ⇒ U)) <:-refl)))
∪-<:-∪ⁿ never (T ∩ U) = <:-∪-lub <:-never <:-refl
∪-<:-∪ⁿ unknown (T ∩ U) = <:-unknown
∪-<:-∪ⁿ (R ⇒ S) (T ∩ U) = ∪-<:-∪ᶠ (R ⇒ S) (T ∩ U)
∪-<:-∪ⁿ (R ∩ S) (T ∩ U) = ∪-<:-∪ᶠ (R ∩ S) (T ∩ U)
∪-<:-∪ⁿ (R ∪ S) (T ∩ U) = <:-trans <:-∪-assocr (<:-trans (<:-union <:-refl <:-∪-symm) (<:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ R (T ∩ U)) <:-refl)))
∪-<:-∪ⁿ never (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ never T) <:-refl)
∪-<:-∪ⁿ unknown (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ unknown T) <:-refl)
∪-<:-∪ⁿ (R ⇒ S) (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ (R ⇒ S) T) <:-refl)
∪-<:-∪ⁿ (R ∩ S) (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ (R ∩ S) T) <:-refl)
∪-<:-∪ⁿ (R ∪ S) (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ (R ∪ S) T) <:-refl)
normalize-<: : ∀ T → normalize T <: T
<:-normalize : ∀ T → T <: normalize T
<:-normalize nil = <:-∪-right
<:-normalize (S ⇒ T) = <:-function (normalize-<: S) (<:-normalize T)
<:-normalize never = <:-refl
<:-normalize unknown = <:-refl
<:-normalize boolean = <:-∪-right
<:-normalize number = <:-∪-right
<:-normalize string = <:-∪-right
<:-normalize (S ∪ T) = <:-trans (<:-union (<:-normalize S) (<:-normalize T)) (∪-<:-∪ⁿ (normal S) (normal T))
<:-normalize (S ∩ T) = <:-trans (<:-intersect (<:-normalize S) (<:-normalize T)) (∩-<:-∩ⁿ (normal S) (normal T))
normalize-<: nil = <:-∪-lub <:-never <:-refl
normalize-<: (S ⇒ T) = <:-function (<:-normalize S) (normalize-<: T)
normalize-<: never = <:-refl
normalize-<: unknown = <:-refl
normalize-<: boolean = <:-∪-lub <:-never <:-refl
normalize-<: number = <:-∪-lub <:-never <:-refl
normalize-<: string = <:-∪-lub <:-never <:-refl
normalize-<: (S ∪ T) = <:-trans (∪ⁿ-<:-∪ (normal S) (normal T)) (<:-union (normalize-<: S) (normalize-<: T))
normalize-<: (S ∩ T) = <:-trans (∩ⁿ-<:-∩ (normal S) (normal T)) (<:-intersect (normalize-<: S) (normalize-<: T))
| 52.37931
| 443
| 0.495316
|
1877a7fe8a330a747a8d8cd3621c2067a5e16768
| 625
|
agda
|
Agda
|
test/Fail/Issue2985-2.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2985-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2985-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- This variant of the code is due to Ulf Norell.
{-# OPTIONS --sized-types #-}
open import Agda.Builtin.Size
data ⊥ : Set where
mutual
data Unit (i : Size) : Set where
c : Unit′ i → Unit i
data Unit₁ (i : Size) : Set where
c₁ : ⊥ → Unit i → Unit₁ i
record Unit′ (i : Size) : Set where
coinductive
field
force : {j : Size< i} → Unit₁ j
open Unit′ public
tail : Unit ∞ → Unit₁ ∞
tail (c x) = force x
u : (∀ {i} → Unit′ i → Unit i) →
∀ {i} → Unit₁ i
u cons = tail (cons λ { .force → u cons })
bad : Unit₁ ∞
bad = u c
refute : Unit₁ ∞ → ⊥
refute (c₁ () _)
loop : ⊥
loop = refute bad
| 16.025641
| 49
| 0.5616
|
598edf4561251944b74482cac06ffab0439dffa7
| 4,586
|
agda
|
Agda
|
src/fot/FOTC/Data/Stream/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Data/Stream/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Data/Stream/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Streams properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Stream.PropertiesI where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Base.List.PropertiesI
open import FOTC.Data.Conat
open import FOTC.Data.Conat.Equality.Type
open import FOTC.Data.Colist
open import FOTC.Data.Colist.PropertiesI
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesI
open import FOTC.Data.Stream
-----------------------------------------------------------------------------
-- Because a greatest post-fixed point is a fixed-point, then the
-- Stream predicate is also a pre-fixed point of the functional
-- StreamF, i.e.
--
-- StreamF Stream ≤ Stream (see FOTC.Data.Stream.Type).
Stream-in : ∀ {xs} →
∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs' →
Stream xs
Stream-in h = Stream-coind A h' h
where
A : D → Set
A xs = ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs'
h' : ∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
h' (x' , xs' , prf , Sxs') = x' , xs' , prf , Stream-out Sxs'
zeros-Stream : Stream zeros
zeros-Stream = Stream-coind A h refl
where
A : D → Set
A xs = xs ≡ zeros
h : ∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
h Axs = zero , zeros , trans Axs zeros-eq , refl
ones-Stream : Stream ones
ones-Stream = Stream-coind A h refl
where
A : D → Set
A xs = xs ≡ ones
h : ∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
h Axs = succ₁ zero , ones , trans Axs ones-eq , refl
∷-Stream : ∀ {x xs} → Stream (x ∷ xs) → Stream xs
∷-Stream {x} {xs} h = ∷-Stream-helper (Stream-out h)
where
∷-Stream-helper : ∃[ x' ] ∃[ xs' ] x ∷ xs ≡ x' ∷ xs' ∧ Stream xs' →
Stream xs
∷-Stream-helper (x' , xs' , prf , Sxs') =
subst Stream (sym (∧-proj₂ (∷-injective prf))) Sxs'
-- Version using Agda with constructor.
∷-Stream' : ∀ {x xs} → Stream (x ∷ xs) → Stream xs
∷-Stream' h with Stream-out h
... | x' , xs' , prf , Sxs' =
subst Stream (sym (∧-proj₂ (∷-injective prf))) Sxs'
Stream→Colist : ∀ {xs} → Stream xs → Colist xs
Stream→Colist {xs} Sxs = Colist-coind A h₁ h₂
where
A : D → Set
A ys = Stream ys
h₁ : ∀ {xs} → A xs → xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs')
h₁ Axs with Stream-out Axs
... | x' , xs' , prf , Sxs' = inj₂ (x' , xs' , prf , Sxs')
h₂ : A xs
h₂ = Sxs
-- Adapted from (Sander 1992, p. 59).
streamLength : ∀ {xs} → Stream xs → length xs ≈ ∞
streamLength {xs} Sxs = ≈-coind R h₁ h₂
where
R : D → D → Set
R m n = ∃[ xs ] Stream xs ∧ m ≡ length xs ∧ n ≡ ∞
h₁ : ∀ {m n} → R m n →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')
h₁ {m} {n} (xs , Sxs , m=lxs , n≡∞) = helper₁ (Stream-out Sxs)
where
helper₁ : (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs') →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')
helper₁ (x' , xs' , xs≡x'∷xs' , Sxs') =
inj₂ (length xs'
, ∞
, helper₂
, trans n≡∞ ∞-eq
, (xs' , Sxs' , refl , refl))
where
helper₂ : m ≡ succ₁ (length xs')
helper₂ = trans m=lxs (trans (lengthCong xs≡x'∷xs') (length-∷ x' xs'))
h₂ : R (length xs) ∞
h₂ = xs , Sxs , refl , refl
-- Adapted from (Sander 1992, p. 59). Version using Agda with
-- constructor.
streamLength' : ∀ {xs} → Stream xs → length xs ≈ ∞
streamLength' {xs} Sxs = ≈-coind R h₁ h₂
where
R : D → D → Set
R m n = ∃[ xs ] Stream xs ∧ m ≡ length xs ∧ n ≡ ∞
h₁ : ∀ {m n} → R m n →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')
h₁ {m} (xs , Sxs , m=lxs , n≡∞) with Stream-out Sxs
... | x' , xs' , xs≡x'∷xs' , Sxs' =
inj₂ (length xs' , ∞ , helper , trans n≡∞ ∞-eq , (xs' , Sxs' , refl , refl))
where
helper : m ≡ succ₁ (length xs')
helper = trans m=lxs (trans (lengthCong xs≡x'∷xs') (length-∷ x' xs'))
h₂ : R (length xs) ∞
h₂ = xs , Sxs , refl , refl
------------------------------------------------------------------------------
-- References
--
-- Sander, Herbert P. (1992). A Logic of Functional Programs with an
-- Application to Concurrency. PhD thesis. Department of Computer
-- Sciences: Chalmers University of Technology and University of
-- Gothenburg.
| 32.524823
| 80
| 0.497165
|
41a5a84d0dd8059dfba3704fb37f6b61e8437733
| 8,645
|
agda
|
Agda
|
Cubical/Functions/Embedding.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Embedding.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Embedding.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Functions.Embedding where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Univalence using (ua)
open import Cubical.Functions.Fibration
open import Cubical.Relation.Nullary using (Discrete; yes; no)
open import Cubical.Data.Nat using (ℕ; zero; suc)
open import Cubical.Data.Sigma
private
variable
ℓ ℓ₁ ℓ₂ : Level
A B : Type ℓ
f : A → B
w x : A
y z : B
-- Embeddings are generalizations of injections. The usual
-- definition of injection as:
--
-- f x ≡ f y → x ≡ y
--
-- is not well-behaved with higher h-levels, while embeddings
-- are.
isEmbedding : (A → B) → Type _
isEmbedding f = ∀ w x → isEquiv {A = w ≡ x} (cong f)
isEmbeddingIsProp : isProp (isEmbedding f)
isEmbeddingIsProp {f = f} = isPropΠ2 λ _ _ → isPropIsEquiv (cong f)
-- If A and B are h-sets, then injective functions between
-- them are embeddings.
--
-- Note: It doesn't appear to be possible to omit either of
-- the `isSet` hypotheses.
injEmbedding
: {f : A → B}
→ isSet A → isSet B
→ (∀{w x} → f w ≡ f x → w ≡ x)
→ isEmbedding f
injEmbedding {f = f} iSA iSB inj w x
= isoToIsEquiv (iso (cong f) inj sect retr)
where
sect : section (cong f) inj
sect p = iSB (f w) (f x) _ p
retr : retract (cong f) inj
retr p = iSA w x _ p
private
lemma₀ : (p : y ≡ z) → fiber f y ≡ fiber f z
lemma₀ {f = f} p = λ i → fiber f (p i)
lemma₁ : isEmbedding f → ∀ x → isContr (fiber f (f x))
lemma₁ {f = f} iE x = value , path
where
value : fiber f (f x)
value = (x , refl)
path : ∀(fi : fiber f (f x)) → value ≡ fi
path (w , p) i
= case equiv-proof (iE w x) p of λ
{ ((q , sq) , _)
→ hfill (λ j → λ { (i = i0) → (x , refl)
; (i = i1) → (w , sq j)
})
(inS (q (~ i) , λ j → f (q (~ i ∨ j))))
i1
}
-- If `f` is an embedding, we'd expect the fibers of `f` to be
-- propositions, like an injective function.
hasPropFibers : (A → B) → Type _
hasPropFibers f = ∀ y → isProp (fiber f y)
-- some notation
_↪_ : Type ℓ₁ → Type ℓ₂ → Type (ℓ-max ℓ₁ ℓ₂)
A ↪ B = Σ[ f ∈ (A → B) ] hasPropFibers f
hasPropFibersIsProp : isProp (hasPropFibers f)
hasPropFibersIsProp = isPropΠ (λ _ → isPropIsProp)
isEmbedding→hasPropFibers : isEmbedding f → hasPropFibers f
isEmbedding→hasPropFibers iE y (x , p)
= subst (λ f → isProp f) (lemma₀ p) (isContr→isProp (lemma₁ iE x)) (x , p)
private
fibCong→PathP
: {f : A → B}
→ (p : f w ≡ f x)
→ (fi : fiber (cong f) p)
→ PathP (λ i → fiber f (p i)) (w , refl) (x , refl)
fibCong→PathP p (q , r) i = q i , λ j → r j i
PathP→fibCong
: {f : A → B}
→ (p : f w ≡ f x)
→ (pp : PathP (λ i → fiber f (p i)) (w , refl) (x , refl))
→ fiber (cong f) p
PathP→fibCong p pp = (λ i → fst (pp i)) , (λ j i → snd (pp i) j)
PathP≡fibCong
: {f : A → B}
→ (p : f w ≡ f x)
→ PathP (λ i → fiber f (p i)) (w , refl) (x , refl) ≡ fiber (cong f) p
PathP≡fibCong p
= isoToPath (iso (PathP→fibCong p) (fibCong→PathP p) (λ _ → refl) (λ _ → refl))
hasPropFibers→isEmbedding : hasPropFibers f → isEmbedding f
hasPropFibers→isEmbedding {f = f} iP w x .equiv-proof p
= subst isContr (PathP≡fibCong p) (isProp→isContrPathP (λ i → iP (p i)) fw fx)
where
fw : fiber f (f w)
fw = (w , refl)
fx : fiber f (f x)
fx = (x , refl)
isEmbedding≡hasPropFibers : isEmbedding f ≡ hasPropFibers f
isEmbedding≡hasPropFibers
= isoToPath
(iso isEmbedding→hasPropFibers
hasPropFibers→isEmbedding
(λ _ → hasPropFibersIsProp _ _)
(λ _ → isEmbeddingIsProp _ _))
isEquiv→hasPropFibers : isEquiv f → hasPropFibers f
isEquiv→hasPropFibers e b = isContr→isProp (equiv-proof e b)
isEquiv→isEmbedding : isEquiv f → isEmbedding f
isEquiv→isEmbedding e = λ _ _ → congEquiv (_ , e) .snd
iso→isEmbedding : ∀ {ℓ} {A B : Type ℓ}
→ (isom : Iso A B)
-------------------------------
→ isEmbedding (Iso.fun isom)
iso→isEmbedding {A = A} {B} isom = (isEquiv→isEmbedding (equivIsEquiv (isoToEquiv isom)))
isEmbedding→Injection :
∀ {ℓ} {A B C : Type ℓ}
→ (a : A -> B)
→ (e : isEmbedding a)
----------------------
→ ∀ {f g : C -> A} ->
∀ x → (a (f x) ≡ a (g x)) ≡ (f x ≡ g x)
isEmbedding→Injection a e {f = f} {g} x = sym (ua (cong a , e (f x) (g x)))
-- if `f` has a retract, then `cong f` has, as well. If `B` is a set, then `cong f`
-- further has a section, making `f` an embedding.
module _ {f : A → B} (retf : hasRetract f) where
open Σ retf renaming (fst to g ; snd to ϕ)
congRetract : f w ≡ f x → w ≡ x
congRetract {w = w} {x = x} p = sym (ϕ w) ∙∙ cong g p ∙∙ ϕ x
isRetractCongRetract : retract (cong {x = w} {y = x} f) congRetract
isRetractCongRetract p = transport (PathP≡doubleCompPathˡ _ _ _ _) (λ i j → ϕ (p j) i)
hasRetract→hasRetractCong : hasRetract (cong {x = w} {y = x} f)
hasRetract→hasRetractCong = congRetract , isRetractCongRetract
retractableIntoSet→isEmbedding : isSet B → isEmbedding f
retractableIntoSet→isEmbedding setB w x =
isoToIsEquiv (iso (cong f) congRetract (λ _ → setB _ _ _ _) (hasRetract→hasRetractCong .snd))
Embedding-into-Discrete→Discrete : A ↪ B → Discrete B → Discrete A
Embedding-into-Discrete→Discrete (f , propFibers) _≟_ x y with f x ≟ f y
... | yes p = yes (cong fst (propFibers (f y) (x , p) (y , refl)))
... | no ¬p = no (¬p ∘ cong f)
Embedding-into-isProp→isProp : A ↪ B → isProp B → isProp A
Embedding-into-isProp→isProp (f , hasPropFibers-f) isProp-B x y
= invIsEq (hasPropFibers→isEmbedding hasPropFibers-f x y) (isProp-B (f x) (f y))
Embedding-into-isSet→isSet : A ↪ B → isSet B → isSet A
Embedding-into-isSet→isSet (f , hasPropFibers-f) isSet-B x y p q =
p ≡⟨ sym (retIsEq isEquiv-cong-f p) ⟩
cong-f⁻¹ (cong f p) ≡⟨ cong cong-f⁻¹ cong-f-p≡cong-f-q ⟩
cong-f⁻¹ (cong f q) ≡⟨ retIsEq isEquiv-cong-f q ⟩
q ∎
where
cong-f-p≡cong-f-q = isSet-B (f x) (f y) (cong f p) (cong f q)
isEquiv-cong-f = hasPropFibers→isEmbedding hasPropFibers-f x y
cong-f⁻¹ = invIsEq isEquiv-cong-f
Embedding-into-hLevel→hLevel
: ∀ n → A ↪ B → isOfHLevel (suc n) B → isOfHLevel (suc n) A
Embedding-into-hLevel→hLevel zero = Embedding-into-isProp→isProp
Embedding-into-hLevel→hLevel (suc n) (f , hasPropFibers-f) Blvl x y
= isOfHLevelRespectEquiv (suc n) (invEquiv equiv) subLvl
where
equiv : (x ≡ y) ≃ (f x ≡ f y)
equiv .fst = cong f
equiv .snd = hasPropFibers→isEmbedding hasPropFibers-f x y
subLvl : isOfHLevel (suc n) (f x ≡ f y)
subLvl = Blvl (f x) (f y)
-- We now show that the powerset is the subtype classifier
-- i.e. ℙ X ≃ Σ[A ∈ Type ℓ] (A ↪ X)
Embedding→Subset : {X : Type ℓ} → Σ[ A ∈ Type ℓ ] (A ↪ X) → ℙ X
Embedding→Subset (_ , f , isPropFiber) x = fiber f x , isPropFiber x
Subset→Embedding : {X : Type ℓ} → ℙ X → Σ[ A ∈ Type ℓ ] (A ↪ X)
Subset→Embedding {X = X} A = D , fst , ψ
where
D = Σ[ x ∈ X ] x ∈ A
ψ : hasPropFibers fst
ψ x ((y , y∈A) , y≡x) ((z , z∈A) , z≡x) = ΣPathP (r , q)
where
p : y ≡ z
p = y≡x ∙ sym z≡x
r : (y , y∈A) ≡ (z , z∈A)
r = Σ≡Prop (∈-isProp A) p
q : PathP (λ i → p i ≡ x) y≡x z≡x
q i j = hcomp (λ k → λ { (j = i1) → x
; (i = i0) → y≡x j
; (i = i1) → z≡x (~ k ∨ j) })
(y≡x (i ∨ j))
Subset→Embedding→Subset : {X : Type ℓ} → section (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Subset→Embedding→Subset _ = funExt λ x → Σ≡Prop (λ _ → isPropIsProp) (ua (FiberIso.fiberEquiv _ x))
Embedding→Subset→Embedding : {X : Type ℓ} → retract (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Embedding→Subset→Embedding {ℓ = ℓ} {X = X} (A , f , ψ) = cong (Σ-assoc-≃ .fst) p
where
χ = Subset→Embedding (Embedding→Subset (A , f , ψ)) .snd .snd
p : (((Σ[ x ∈ X ] fiber f x) , fst) , χ) ≡ ((A , f) , ψ)
p = Σ≡Prop (λ _ → hasPropFibersIsProp) (equivToIso (fibrationEquiv X ℓ) .Iso.leftInv (A , f))
Subset≃Embedding : {X : Type ℓ} → ℙ X ≃ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≃Embedding = isoToEquiv (iso Subset→Embedding Embedding→Subset
Embedding→Subset→Embedding Subset→Embedding→Subset)
Subset≡Embedding : {X : Type ℓ} → ℙ X ≡ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≡Embedding = ua Subset≃Embedding
| 34.035433
| 105
| 0.605205
|
593702ff4b28b413f5850fa33ebfb3d45309f04f
| 4,143
|
agda
|
Agda
|
LibraBFT/Impl/Util/RWST.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Impl/Util/RWST.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Impl/Util/RWST.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Optics.All
open import LibraBFT.Prelude
-- This module defines syntax and functionality modeling an RWST monad,
-- which we use to define an implementation.
-- TODO-2: this module is independent of any particular implementation
-- and arguably belongs somewhere more general, such as next to Optics.
module LibraBFT.Impl.Util.RWST (ℓ-State : Level) where
----------------
-- RWST Monad --
----------------
-- 'Fake' RWST monad; fake in the sense
-- we use the free monoid on the writer (aka. lists)
-- instad of requiring it to be a monoid in a separate
-- argument.
RWST-Raw : Set → Set → Set ℓ-State → {ℓ-Result : Level} → Set ℓ-Result → Set (ℓ-State ℓ⊔ ℓ-Result)
RWST-Raw Ev Wr St R = Ev → St → (R × St × List Wr)
-- Wrap it in a type; prevents spurious evaluation and
-- obliges us to 'run' the monad.
data RWST (Ev Wr : Set) (St : Set ℓ-State) {ℓ-Result : Level} : Set ℓ-Result → Set (ℓ-State ℓ⊔ ℓ-Result) where
rwst : ∀ {R : Set ℓ-Result} → RWST-Raw Ev Wr St {ℓ-Result} R → RWST Ev Wr St R
private
variable
Ev Wr : Set
ℓ-A ℓ-B : Level
A : Set ℓ-A
B : Set ℓ-B
St : Set ℓ-State
RWST-run : RWST Ev Wr St A → Ev → St → (A × St × List Wr)
RWST-run (rwst f) = f
RWST-bind : RWST Ev Wr St A → (A → RWST Ev Wr St B) → RWST Ev Wr St B
RWST-bind x f = rwst (λ ev st →
let (a , st' , wr₀) = RWST-run x ev st
(b , st'' , wr₁) = RWST-run (f a) ev st'
in b , st'' , wr₀ ++ wr₁)
RWST-return : A → RWST Ev Wr St A
RWST-return x = rwst (λ _ st → x , st , [])
-- Functorial Functionality
RWST-map : (A → B) → RWST Ev Wr St A → RWST Ev Wr St B
RWST-map f x = rwst (λ ev st →
let (a , st' , wr) = RWST-run x ev st
in f a , st' , wr)
-- Provided Functionality
get : RWST Ev Wr St {ℓ-State} St
get = rwst (λ _ st → st , st , [])
gets : (St → A) → RWST Ev Wr St A
gets f = RWST-bind get (RWST-return ∘ f)
{- TODO-2: extend Lens to work with different levels and reinstate this
Note that a preliminary exploration by @cwjnkins revealed this to
be more painful than it's worth, at least until we have a
compelling use case for St to be at a higher level. In the
meantime, we have defined use and modify' specifically for our
state type, which is in Set; see LibraBFT.Impl.Util.Util.
use : Lens St A → RWST Ev Wr St A
use f = RWST-bind get (RWST-return ∘ (_^∙ f))
-}
modify : (St → St) → RWST Ev Wr St Unit
modify f = rwst (λ _ st → unit , f st , [])
{- TODO-2: extend Lens to work with different levels and reinstate this
See comment above for use
modify' : ∀ {A} → Lens St A → A → RWST Ev Wr St Unit
modify' l val = modify λ x → x [ l := val ]
syntax modify' l val = l ∙= val
-}
put : St → RWST Ev Wr St Unit
put s = modify (λ _ → s)
tell : List Wr → RWST Ev Wr St Unit
tell wrs = rwst (λ _ st → unit , st , wrs)
tell1 : Wr → RWST Ev Wr St Unit
tell1 wr = tell (wr ∷ [])
ask : RWST Ev Wr St Ev
ask = rwst (λ ev st → (ev , st , []))
-- Easy to use do notation; i.e.;
module RWST-do where
infixl 1 _>>=_ _>>_
_>>=_ : RWST Ev Wr St A → (A → RWST Ev Wr St B) → RWST Ev Wr St B
_>>=_ = RWST-bind
_>>_ : RWST Ev Wr St A → RWST Ev Wr St B → RWST Ev Wr St B
x >> y = x >>= λ _ → y
return : A → RWST Ev Wr St A
return = RWST-return
pure : A → RWST Ev Wr St A
pure = return
infixr 4 _<$>_
_<$>_ : (A → B) → RWST Ev Wr St A → RWST Ev Wr St B
_<$>_ = RWST-map
private
ex₀ : RWST ℕ Wr (Lift ℓ-State ℕ) ℕ
ex₀ = do
x₁ ← get
x₂ ← ask
return (lower x₁ + x₂)
where open RWST-do
-- Derived Functionality
maybeMP : RWST Ev Wr St (Maybe A) → B → (A → RWST Ev Wr St B)
→ RWST Ev Wr St B
maybeMP ma b f = do
x ← ma
case x of
λ { (just r) → f r
; nothing → return b
}
where open RWST-do
| 29.592857
| 112
| 0.5916
|
57ce5d72918f4b4e13f6b72b8bf6577741f57d37
| 142
|
agda
|
Agda
|
test/fail/IrrelevantModuleParameter1.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/IrrelevantModuleParameter1.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/IrrelevantModuleParameter1.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module IrrelevantModuleParameter1 (A : Set) .(a : A) where
postulate
P : A -> Set
p : P a
-- cannot use a here, because it is irrelevant
| 23.666667
| 58
| 0.669014
|
41b431be371e2e72a44d4eca5b9531841c267a3b
| 1,011
|
agda
|
Agda
|
archive/agda-3/src/AgdaFeatureInstanceResolutionViaConstraint.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/AgdaFeatureInstanceResolutionViaConstraint.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/AgdaFeatureInstanceResolutionViaConstraint.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
{-# OPTIONS --allow-unsolved-metas #-}
module AgdaFeatureInstanceResolutionViaConstraint where
postulate A : Set
postulate y : A
Appy : (A → Set) → Set
Appy H = H y
record Foo (T : Set) : Set where field foo : T
open Foo ⦃ … ⦄ public
postulate
S : A → Set
record Failing : Set where
no-eta-equality
postulate
instance FooInstance : {R : A → Set} → Foo (Appy R)
works1 : Appy S
works1 = foo ⦃ FooInstance {R = S} ⦄
fails2 : Appy S
fails2 = foo ⦃ FooInstance {R = {!!}} ⦄
{-
[21] (_R_11 y) =< (S y) : Set
_12 := λ → Foo.foo FooInstance [blocked by problem 21]
-}
fails3 : Appy S
fails3 = foo
record Succeeds : Set where
no-eta-equality
record Bar (B : A → Set) : Set where
no-eta-equality
postulate
instance BarInstance : Bar S
instance FooInstance : {R : A → Set} ⦃ _ : Bar R ⦄ → Foo (Appy R)
works1 : Appy S
works1 = foo ⦃ FooInstance {R = S} ⦄
works2 : Appy S
works2 = foo ⦃ FooInstance {R = {!!}} ⦄
works3 : Appy S
works3 = foo
| 18.381818
| 69
| 0.60633
|
4d173c6ca7f5eee294dcaf24d565acc211b0d0e8
| 1,883
|
agda
|
Agda
|
proto/agda/Equality.agda
|
Riib11/monadic-equality
|
525a3d42431bf5dc6837939441f389ea5cead937
|
[
"BSD-3-Clause"
] | null | null | null |
proto/agda/Equality.agda
|
Riib11/monadic-equality
|
525a3d42431bf5dc6837939441f389ea5cead937
|
[
"BSD-3-Clause"
] | 1
|
2021-02-25T15:49:12.000Z
|
2021-02-25T15:49:12.000Z
|
proto/agda/Equality.agda
|
Riib11/monadic-equality
|
525a3d42431bf5dc6837939441f389ea5cead937
|
[
"BSD-3-Clause"
] | null | null | null |
module Equality where
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Data.Product using (_×_; _,_; ∃-syntax; proj₁; proj₂)
open import Data.Bool using (Bool; true; false)
open import Data.Nat using (ℕ)
--
-- Relation
--
record Relation (R : Set → Set) (A : Set) : Set where
field
relate : A × A → Bool
to-witness : ∀ x → relate x ≡ true → R A
from-witness : R A → ∃[ x ] (relate x ≡ true)
to-from-witness : ∀ x d → x ≡ (proj₁ ∘ from-witness) (to-witness x d)
Related : A × A → Set
Related (x , y) = R A × relate (x , y) ≡ true
-- Properties
IsReflexive : ∀ R A (rel : Relation R A) → Set
IsReflexive R A rel = ∀ x → Related (x , x)
where open Relation rel
IsSymmetric : ∀ R A (rel : Relation R A) → Set
IsSymmetric R A rel = ∀ x y → Related (x , y) → Related (y , x)
where open Relation rel
IsTransitive : ∀ R A (rel : Relation R A) → Set
IsTransitive R A rel = ∀ x y z → Related (x , y) → Related (y , z) → Related (x , z)
where open Relation rel
--
-- Equality
--
record Equality (E : Set → Set) (A : Set) : Set where
field
rel : Relation E A
isReflexive : IsReflexive E A rel
isSymmetric : IsSymmetric E A rel
isTransitive : IsTransitive E A rel
--
-- SMT Equality
--
postulate
-- datatype
EqualitySMT : ∀ A → A → A → Set
-- instances
equalitySMT-Bool : Equality EqualitySMT Bool
equalitySMT-ℕ : Equality EqualitySMT ℕ
-- eq-smt : (A : Set) (x y : A) → Bool
--
-- Propositional Equality
--
postulate
eq-prop : ∀ (A : Set) (x y : A) → Bool
data EqualityProp : ∀ A → A → A → Set where
injection-SMT :
∀ (A : Set) (equ : Equality EqualitySMT A) x y →
Relation.Related EqualitySMT (x , y) →
Relation.Related EqualityProp (x , y)
-- extensional :
-- ∀ (A B : Set) f g →
-- (∀ x → EqualityProp
| 22.416667
| 84
| 0.603824
|
312b72a4dddb2fb2cb642ca4e8b0fc172a55196b
| 19,430
|
agda
|
Agda
|
agda-stdlib-0.9/src/Algebra/RingSolver.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | 1
|
2016-10-20T15:52:05.000Z
|
2016-10-20T15:52:05.000Z
|
agda-stdlib-0.9/src/Algebra/RingSolver.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Algebra/RingSolver.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Solver for commutative ring or semiring equalities
------------------------------------------------------------------------
-- Uses ideas from the Coq ring tactic. See "Proving Equalities in a
-- Commutative Ring Done Right in Coq" by Grégoire and Mahboubi. The
-- code below is not optimised like theirs, though (in particular, our
-- Horner normal forms are not sparse).
open import Algebra
open import Algebra.RingSolver.AlmostCommutativeRing
open import Relation.Binary
module Algebra.RingSolver
{r₁ r₂ r₃}
(Coeff : RawRing r₁) -- Coefficient "ring".
(R : AlmostCommutativeRing r₂ r₃) -- Main "ring".
(morphism : Coeff -Raw-AlmostCommutative⟶ R)
(_coeff≟_ : Decidable (Induced-equivalence morphism))
where
import Algebra.RingSolver.Lemmas as L; open L Coeff R morphism
private module C = RawRing Coeff
open AlmostCommutativeRing R renaming (zero to zero*)
import Algebra.FunctionProperties as P; open P _≈_
open import Algebra.Morphism
open _-Raw-AlmostCommutative⟶_ morphism renaming (⟦_⟧ to ⟦_⟧′)
import Algebra.Operations as Ops; open Ops semiring
open import Relation.Binary
open import Relation.Nullary.Core
import Relation.Binary.EqReasoning as EqR; open EqR setoid
import Relation.Binary.PropositionalEquality as PropEq
import Relation.Binary.Reflection as Reflection
open import Data.Empty
open import Data.Product
open import Data.Nat as Nat using (ℕ; suc; zero)
open import Data.Fin as Fin using (Fin; zero; suc)
open import Data.Vec
open import Function
open import Level using (_⊔_)
infix 9 :-_ -H_ -N_
infixr 9 _:^_ _^N_
infix 8 _*x+_ _*x+HN_ _*x+H_
infixl 8 _:*_ _*N_ _*H_ _*NH_ _*HN_
infixl 7 _:+_ _:-_ _+H_ _+N_
infix 4 _≈H_ _≈N_
------------------------------------------------------------------------
-- Polynomials
data Op : Set where
[+] : Op
[*] : Op
-- The polynomials are indexed by the number of variables.
data Polynomial (m : ℕ) : Set r₁ where
op : (o : Op) (p₁ : Polynomial m) (p₂ : Polynomial m) → Polynomial m
con : (c : C.Carrier) → Polynomial m
var : (x : Fin m) → Polynomial m
_:^_ : (p : Polynomial m) (n : ℕ) → Polynomial m
:-_ : (p : Polynomial m) → Polynomial m
-- Short-hand notation.
_:+_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
_:+_ = op [+]
_:*_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
_:*_ = op [*]
_:-_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
x :- y = x :+ :- y
-- Semantics.
sem : Op → Op₂ Carrier
sem [+] = _+_
sem [*] = _*_
⟦_⟧ : ∀ {n} → Polynomial n → Vec Carrier n → Carrier
⟦ op o p₁ p₂ ⟧ ρ = ⟦ p₁ ⟧ ρ ⟨ sem o ⟩ ⟦ p₂ ⟧ ρ
⟦ con c ⟧ ρ = ⟦ c ⟧′
⟦ var x ⟧ ρ = lookup x ρ
⟦ p :^ n ⟧ ρ = ⟦ p ⟧ ρ ^ n
⟦ :- p ⟧ ρ = - ⟦ p ⟧ ρ
------------------------------------------------------------------------
-- Normal forms of polynomials
-- A univariate polynomial of degree d,
--
-- p = a_d x^d + a_{d-1}x^{d-1} + … + a_0,
--
-- is represented in Horner normal form by
--
-- p = ((a_d x + a_{d-1})x + …)x + a_0.
--
-- Note that Horner normal forms can be represented as lists, with the
-- empty list standing for the zero polynomial of degree "-1".
--
-- Given this representation of univariate polynomials over an
-- arbitrary ring, polynomials in any number of variables over the
-- ring C can be represented via the isomorphisms
--
-- C[] ≅ C
--
-- and
--
-- C[X_0,...X_{n+1}] ≅ C[X_0,...,X_n][X_{n+1}].
mutual
-- The polynomial representations are indexed by the polynomial's
-- degree.
data HNF : ℕ → Set r₁ where
∅ : ∀ {n} → HNF (suc n)
_*x+_ : ∀ {n} → HNF (suc n) → Normal n → HNF (suc n)
data Normal : ℕ → Set r₁ where
con : C.Carrier → Normal zero
poly : ∀ {n} → HNF (suc n) → Normal (suc n)
-- Note that the data types above do /not/ ensure uniqueness of
-- normal forms: the zero polynomial of degree one can be
-- represented using both ∅ and ∅ *x+ con C.0#.
mutual
-- Semantics.
⟦_⟧H : ∀ {n} → HNF (suc n) → Vec Carrier (suc n) → Carrier
⟦ ∅ ⟧H _ = 0#
⟦ p *x+ c ⟧H (x ∷ ρ) = ⟦ p ⟧H (x ∷ ρ) * x + ⟦ c ⟧N ρ
⟦_⟧N : ∀ {n} → Normal n → Vec Carrier n → Carrier
⟦ con c ⟧N _ = ⟦ c ⟧′
⟦ poly p ⟧N ρ = ⟦ p ⟧H ρ
------------------------------------------------------------------------
-- Equality and decidability
mutual
-- Equality.
data _≈H_ : ∀ {n} → HNF n → HNF n → Set (r₁ ⊔ r₃) where
∅ : ∀ {n} → _≈H_ {suc n} ∅ ∅
_*x+_ : ∀ {n} {p₁ p₂ : HNF (suc n)} {c₁ c₂ : Normal n} →
p₁ ≈H p₂ → c₁ ≈N c₂ → (p₁ *x+ c₁) ≈H (p₂ *x+ c₂)
data _≈N_ : ∀ {n} → Normal n → Normal n → Set (r₁ ⊔ r₃) where
con : ∀ {c₁ c₂} → ⟦ c₁ ⟧′ ≈ ⟦ c₂ ⟧′ → con c₁ ≈N con c₂
poly : ∀ {n} {p₁ p₂ : HNF (suc n)} → p₁ ≈H p₂ → poly p₁ ≈N poly p₂
mutual
-- Equality is decidable.
_≟H_ : ∀ {n} → Decidable (_≈H_ {n = n})
∅ ≟H ∅ = yes ∅
∅ ≟H (_ *x+ _) = no λ()
(_ *x+ _) ≟H ∅ = no λ()
(p₁ *x+ c₁) ≟H (p₂ *x+ c₂) with p₁ ≟H p₂ | c₁ ≟N c₂
... | yes p₁≈p₂ | yes c₁≈c₂ = yes (p₁≈p₂ *x+ c₁≈c₂)
... | _ | no c₁≉c₂ = no λ { (_ *x+ c₁≈c₂) → c₁≉c₂ c₁≈c₂ }
... | no p₁≉p₂ | _ = no λ { (p₁≈p₂ *x+ _) → p₁≉p₂ p₁≈p₂ }
_≟N_ : ∀ {n} → Decidable (_≈N_ {n = n})
con c₁ ≟N con c₂ with c₁ coeff≟ c₂
... | yes c₁≈c₂ = yes (con c₁≈c₂)
... | no c₁≉c₂ = no λ { (con c₁≈c₂) → c₁≉c₂ c₁≈c₂}
poly p₁ ≟N poly p₂ with p₁ ≟H p₂
... | yes p₁≈p₂ = yes (poly p₁≈p₂)
... | no p₁≉p₂ = no λ { (poly p₁≈p₂) → p₁≉p₂ p₁≈p₂ }
mutual
-- The semantics respect the equality relations defined above.
⟦_⟧H-cong : ∀ {n} {p₁ p₂ : HNF (suc n)} →
p₁ ≈H p₂ → ∀ ρ → ⟦ p₁ ⟧H ρ ≈ ⟦ p₂ ⟧H ρ
⟦ ∅ ⟧H-cong _ = refl
⟦ p₁≈p₂ *x+ c₁≈c₂ ⟧H-cong (x ∷ ρ) =
(⟦ p₁≈p₂ ⟧H-cong (x ∷ ρ) ⟨ *-cong ⟩ refl)
⟨ +-cong ⟩
⟦ c₁≈c₂ ⟧N-cong ρ
⟦_⟧N-cong :
∀ {n} {p₁ p₂ : Normal n} →
p₁ ≈N p₂ → ∀ ρ → ⟦ p₁ ⟧N ρ ≈ ⟦ p₂ ⟧N ρ
⟦ con c₁≈c₂ ⟧N-cong _ = c₁≈c₂
⟦ poly p₁≈p₂ ⟧N-cong ρ = ⟦ p₁≈p₂ ⟧H-cong ρ
------------------------------------------------------------------------
-- Ring operations on Horner normal forms
-- Zero.
0H : ∀ {n} → HNF (suc n)
0H = ∅
0N : ∀ {n} → Normal n
0N {zero} = con C.0#
0N {suc n} = poly 0H
mutual
-- One.
1H : ∀ {n} → HNF (suc n)
1H {n} = ∅ *x+ 1N {n}
1N : ∀ {n} → Normal n
1N {zero} = con C.1#
1N {suc n} = poly 1H
-- A simplifying variant of _*x+_.
_*x+HN_ : ∀ {n} → HNF (suc n) → Normal n → HNF (suc n)
(p *x+ c′) *x+HN c = (p *x+ c′) *x+ c
∅ *x+HN c with c ≟N 0N
... | yes c≈0 = ∅
... | no c≉0 = ∅ *x+ c
mutual
-- Addition.
_+H_ : ∀ {n} → HNF (suc n) → HNF (suc n) → HNF (suc n)
∅ +H p = p
p +H ∅ = p
(p₁ *x+ c₁) +H (p₂ *x+ c₂) = (p₁ +H p₂) *x+HN (c₁ +N c₂)
_+N_ : ∀ {n} → Normal n → Normal n → Normal n
con c₁ +N con c₂ = con (c₁ C.+ c₂)
poly p₁ +N poly p₂ = poly (p₁ +H p₂)
-- Multiplication.
_*x+H_ : ∀ {n} → HNF (suc n) → HNF (suc n) → HNF (suc n)
p₁ *x+H (p₂ *x+ c) = (p₁ +H p₂) *x+HN c
∅ *x+H ∅ = ∅
(p₁ *x+ c) *x+H ∅ = (p₁ *x+ c) *x+ 0N
mutual
_*NH_ : ∀ {n} → Normal n → HNF (suc n) → HNF (suc n)
c *NH ∅ = ∅
c *NH (p *x+ c′) with c ≟N 0N
... | yes c≈0 = ∅
... | no c≉0 = (c *NH p) *x+ (c *N c′)
_*HN_ : ∀ {n} → HNF (suc n) → Normal n → HNF (suc n)
∅ *HN c = ∅
(p *x+ c′) *HN c with c ≟N 0N
... | yes c≈0 = ∅
... | no c≉0 = (p *HN c) *x+ (c′ *N c)
_*H_ : ∀ {n} → HNF (suc n) → HNF (suc n) → HNF (suc n)
∅ *H _ = ∅
(_ *x+ _) *H ∅ = ∅
(p₁ *x+ c₁) *H (p₂ *x+ c₂) =
((p₁ *H p₂) *x+H (p₁ *HN c₂ +H c₁ *NH p₂)) *x+HN (c₁ *N c₂)
_*N_ : ∀ {n} → Normal n → Normal n → Normal n
con c₁ *N con c₂ = con (c₁ C.* c₂)
poly p₁ *N poly p₂ = poly (p₁ *H p₂)
-- Exponentiation.
_^N_ : ∀ {n} → Normal n → ℕ → Normal n
p ^N zero = 1N
p ^N suc n = p *N (p ^N n)
mutual
-- Negation.
-H_ : ∀ {n} → HNF (suc n) → HNF (suc n)
-H p = (-N 1N) *NH p
-N_ : ∀ {n} → Normal n → Normal n
-N con c = con (C.- c)
-N poly p = poly (-H p)
------------------------------------------------------------------------
-- Normalisation
normalise-con : ∀ {n} → C.Carrier → Normal n
normalise-con {zero} c = con c
normalise-con {suc n} c = poly (∅ *x+HN normalise-con c)
normalise-var : ∀ {n} → Fin n → Normal n
normalise-var zero = poly ((∅ *x+ 1N) *x+ 0N)
normalise-var (suc i) = poly (∅ *x+HN normalise-var i)
normalise : ∀ {n} → Polynomial n → Normal n
normalise (op [+] t₁ t₂) = normalise t₁ +N normalise t₂
normalise (op [*] t₁ t₂) = normalise t₁ *N normalise t₂
normalise (con c) = normalise-con c
normalise (var i) = normalise-var i
normalise (t :^ k) = normalise t ^N k
normalise (:- t) = -N normalise t
-- Evaluation after normalisation.
⟦_⟧↓ : ∀ {n} → Polynomial n → Vec Carrier n → Carrier
⟦ p ⟧↓ ρ = ⟦ normalise p ⟧N ρ
------------------------------------------------------------------------
-- Homomorphism lemmas
0N-homo : ∀ {n} ρ → ⟦ 0N {n} ⟧N ρ ≈ 0#
0N-homo [] = 0-homo
0N-homo (x ∷ ρ) = refl
-- If c is equal to 0N, then c is semantically equal to 0#.
0≈⟦0⟧ : ∀ {n} {c : Normal n} → c ≈N 0N → ∀ ρ → 0# ≈ ⟦ c ⟧N ρ
0≈⟦0⟧ {c = c} c≈0 ρ = sym (begin
⟦ c ⟧N ρ ≈⟨ ⟦ c≈0 ⟧N-cong ρ ⟩
⟦ 0N ⟧N ρ ≈⟨ 0N-homo ρ ⟩
0# ∎)
1N-homo : ∀ {n} ρ → ⟦ 1N {n} ⟧N ρ ≈ 1#
1N-homo [] = 1-homo
1N-homo (x ∷ ρ) = begin
0# * x + ⟦ 1N ⟧N ρ ≈⟨ refl ⟨ +-cong ⟩ 1N-homo ρ ⟩
0# * x + 1# ≈⟨ lemma₆ _ _ ⟩
1# ∎
-- _*x+HN_ is equal to _*x+_.
*x+HN≈*x+ : ∀ {n} (p : HNF (suc n)) (c : Normal n) →
∀ ρ → ⟦ p *x+HN c ⟧H ρ ≈ ⟦ p *x+ c ⟧H ρ
*x+HN≈*x+ (p *x+ c′) c ρ = refl
*x+HN≈*x+ ∅ c (x ∷ ρ) with c ≟N 0N
... | yes c≈0 = begin
0# ≈⟨ 0≈⟦0⟧ c≈0 ρ ⟩
⟦ c ⟧N ρ ≈⟨ sym $ lemma₆ _ _ ⟩
0# * x + ⟦ c ⟧N ρ ∎
... | no c≉0 = refl
∅*x+HN-homo : ∀ {n} (c : Normal n) x ρ →
⟦ ∅ *x+HN c ⟧H (x ∷ ρ) ≈ ⟦ c ⟧N ρ
∅*x+HN-homo c x ρ with c ≟N 0N
... | yes c≈0 = 0≈⟦0⟧ c≈0 ρ
... | no c≉0 = lemma₆ _ _
mutual
+H-homo : ∀ {n} (p₁ p₂ : HNF (suc n)) →
∀ ρ → ⟦ p₁ +H p₂ ⟧H ρ ≈ ⟦ p₁ ⟧H ρ + ⟦ p₂ ⟧H ρ
+H-homo ∅ p₂ ρ = sym (proj₁ +-identity _)
+H-homo (p₁ *x+ x₁) ∅ ρ = sym (proj₂ +-identity _)
+H-homo (p₁ *x+ c₁) (p₂ *x+ c₂) (x ∷ ρ) = begin
⟦ (p₁ +H p₂) *x+HN (c₁ +N c₂) ⟧H (x ∷ ρ) ≈⟨ *x+HN≈*x+ (p₁ +H p₂) (c₁ +N c₂) (x ∷ ρ) ⟩
⟦ p₁ +H p₂ ⟧H (x ∷ ρ) * x + ⟦ c₁ +N c₂ ⟧N ρ ≈⟨ (+H-homo p₁ p₂ (x ∷ ρ) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ +N-homo c₁ c₂ ρ ⟩
(⟦ p₁ ⟧H (x ∷ ρ) + ⟦ p₂ ⟧H (x ∷ ρ)) * x + (⟦ c₁ ⟧N ρ + ⟦ c₂ ⟧N ρ) ≈⟨ lemma₁ _ _ _ _ _ ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * x + ⟦ c₁ ⟧N ρ) +
(⟦ p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ) ∎
+N-homo : ∀ {n} (p₁ p₂ : Normal n) →
∀ ρ → ⟦ p₁ +N p₂ ⟧N ρ ≈ ⟦ p₁ ⟧N ρ + ⟦ p₂ ⟧N ρ
+N-homo (con c₁) (con c₂) _ = +-homo _ _
+N-homo (poly p₁) (poly p₂) ρ = +H-homo p₁ p₂ ρ
*x+H-homo :
∀ {n} (p₁ p₂ : HNF (suc n)) x ρ →
⟦ p₁ *x+H p₂ ⟧H (x ∷ ρ) ≈
⟦ p₁ ⟧H (x ∷ ρ) * x + ⟦ p₂ ⟧H (x ∷ ρ)
*x+H-homo ∅ ∅ _ _ = sym $ lemma₆ _ _
*x+H-homo (p *x+ c) ∅ x ρ = begin
⟦ p *x+ c ⟧H (x ∷ ρ) * x + ⟦ 0N ⟧N ρ ≈⟨ refl ⟨ +-cong ⟩ 0N-homo ρ ⟩
⟦ p *x+ c ⟧H (x ∷ ρ) * x + 0# ∎
*x+H-homo p₁ (p₂ *x+ c₂) x ρ = begin
⟦ (p₁ +H p₂) *x+HN c₂ ⟧H (x ∷ ρ) ≈⟨ *x+HN≈*x+ (p₁ +H p₂) c₂ (x ∷ ρ) ⟩
⟦ p₁ +H p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ ≈⟨ (+H-homo p₁ p₂ (x ∷ ρ) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ refl ⟩
(⟦ p₁ ⟧H (x ∷ ρ) + ⟦ p₂ ⟧H (x ∷ ρ)) * x + ⟦ c₂ ⟧N ρ ≈⟨ lemma₀ _ _ _ _ ⟩
⟦ p₁ ⟧H (x ∷ ρ) * x + (⟦ p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ) ∎
mutual
*NH-homo :
∀ {n} (c : Normal n) (p : HNF (suc n)) x ρ →
⟦ c *NH p ⟧H (x ∷ ρ) ≈ ⟦ c ⟧N ρ * ⟦ p ⟧H (x ∷ ρ)
*NH-homo c ∅ x ρ = sym (proj₂ zero* _)
*NH-homo c (p *x+ c′) x ρ with c ≟N 0N
... | yes c≈0 = begin
0# ≈⟨ sym (proj₁ zero* _) ⟩
0# * (⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) ≈⟨ 0≈⟦0⟧ c≈0 ρ ⟨ *-cong ⟩ refl ⟩
⟦ c ⟧N ρ * (⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) ∎
... | no c≉0 = begin
⟦ c *NH p ⟧H (x ∷ ρ) * x + ⟦ c *N c′ ⟧N ρ ≈⟨ (*NH-homo c p x ρ ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ *N-homo c c′ ρ ⟩
(⟦ c ⟧N ρ * ⟦ p ⟧H (x ∷ ρ)) * x + (⟦ c ⟧N ρ * ⟦ c′ ⟧N ρ) ≈⟨ lemma₃ _ _ _ _ ⟩
⟦ c ⟧N ρ * (⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) ∎
*HN-homo :
∀ {n} (p : HNF (suc n)) (c : Normal n) x ρ →
⟦ p *HN c ⟧H (x ∷ ρ) ≈ ⟦ p ⟧H (x ∷ ρ) * ⟦ c ⟧N ρ
*HN-homo ∅ c x ρ = sym (proj₁ zero* _)
*HN-homo (p *x+ c′) c x ρ with c ≟N 0N
... | yes c≈0 = begin
0# ≈⟨ sym (proj₂ zero* _) ⟩
(⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) * 0# ≈⟨ refl ⟨ *-cong ⟩ 0≈⟦0⟧ c≈0 ρ ⟩
(⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) * ⟦ c ⟧N ρ ∎
... | no c≉0 = begin
⟦ p *HN c ⟧H (x ∷ ρ) * x + ⟦ c′ *N c ⟧N ρ ≈⟨ (*HN-homo p c x ρ ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ *N-homo c′ c ρ ⟩
(⟦ p ⟧H (x ∷ ρ) * ⟦ c ⟧N ρ) * x + (⟦ c′ ⟧N ρ * ⟦ c ⟧N ρ) ≈⟨ lemma₂ _ _ _ _ ⟩
(⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) * ⟦ c ⟧N ρ ∎
*H-homo : ∀ {n} (p₁ p₂ : HNF (suc n)) →
∀ ρ → ⟦ p₁ *H p₂ ⟧H ρ ≈ ⟦ p₁ ⟧H ρ * ⟦ p₂ ⟧H ρ
*H-homo ∅ p₂ ρ = sym $ proj₁ zero* _
*H-homo (p₁ *x+ c₁) ∅ ρ = sym $ proj₂ zero* _
*H-homo (p₁ *x+ c₁) (p₂ *x+ c₂) (x ∷ ρ) = begin
⟦ ((p₁ *H p₂) *x+H ((p₁ *HN c₂) +H (c₁ *NH p₂))) *x+HN
(c₁ *N c₂) ⟧H (x ∷ ρ) ≈⟨ *x+HN≈*x+ ((p₁ *H p₂) *x+H ((p₁ *HN c₂) +H (c₁ *NH p₂)))
(c₁ *N c₂) (x ∷ ρ) ⟩
⟦ (p₁ *H p₂) *x+H
((p₁ *HN c₂) +H (c₁ *NH p₂)) ⟧H (x ∷ ρ) * x +
⟦ c₁ *N c₂ ⟧N ρ ≈⟨ (*x+H-homo (p₁ *H p₂) ((p₁ *HN c₂) +H (c₁ *NH p₂)) x ρ
⟨ *-cong ⟩
refl)
⟨ +-cong ⟩
*N-homo c₁ c₂ ρ ⟩
(⟦ p₁ *H p₂ ⟧H (x ∷ ρ) * x +
⟦ (p₁ *HN c₂) +H (c₁ *NH p₂) ⟧H (x ∷ ρ)) * x +
⟦ c₁ ⟧N ρ * ⟦ c₂ ⟧N ρ ≈⟨ (((*H-homo p₁ p₂ (x ∷ ρ) ⟨ *-cong ⟩ refl)
⟨ +-cong ⟩
(+H-homo (p₁ *HN c₂) (c₁ *NH p₂) (x ∷ ρ)))
⟨ *-cong ⟩
refl)
⟨ +-cong ⟩
refl ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * ⟦ p₂ ⟧H (x ∷ ρ) * x +
(⟦ p₁ *HN c₂ ⟧H (x ∷ ρ) + ⟦ c₁ *NH p₂ ⟧H (x ∷ ρ))) * x +
⟦ c₁ ⟧N ρ * ⟦ c₂ ⟧N ρ ≈⟨ ((refl ⟨ +-cong ⟩ (*HN-homo p₁ c₂ x ρ ⟨ +-cong ⟩ *NH-homo c₁ p₂ x ρ))
⟨ *-cong ⟩
refl)
⟨ +-cong ⟩
refl ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * ⟦ p₂ ⟧H (x ∷ ρ) * x +
(⟦ p₁ ⟧H (x ∷ ρ) * ⟦ c₂ ⟧N ρ + ⟦ c₁ ⟧N ρ * ⟦ p₂ ⟧H (x ∷ ρ))) * x +
(⟦ c₁ ⟧N ρ * ⟦ c₂ ⟧N ρ) ≈⟨ lemma₄ _ _ _ _ _ ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * x + ⟦ c₁ ⟧N ρ) *
(⟦ p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ) ∎
*N-homo : ∀ {n} (p₁ p₂ : Normal n) →
∀ ρ → ⟦ p₁ *N p₂ ⟧N ρ ≈ ⟦ p₁ ⟧N ρ * ⟦ p₂ ⟧N ρ
*N-homo (con c₁) (con c₂) _ = *-homo _ _
*N-homo (poly p₁) (poly p₂) ρ = *H-homo p₁ p₂ ρ
^N-homo : ∀ {n} (p : Normal n) (k : ℕ) →
∀ ρ → ⟦ p ^N k ⟧N ρ ≈ ⟦ p ⟧N ρ ^ k
^N-homo p zero ρ = 1N-homo ρ
^N-homo p (suc k) ρ = begin
⟦ p *N (p ^N k) ⟧N ρ ≈⟨ *N-homo p (p ^N k) ρ ⟩
⟦ p ⟧N ρ * ⟦ p ^N k ⟧N ρ ≈⟨ refl ⟨ *-cong ⟩ ^N-homo p k ρ ⟩
⟦ p ⟧N ρ * (⟦ p ⟧N ρ ^ k) ∎
mutual
-H‿-homo : ∀ {n} (p : HNF (suc n)) →
∀ ρ → ⟦ -H p ⟧H ρ ≈ - ⟦ p ⟧H ρ
-H‿-homo p (x ∷ ρ) = begin
⟦ (-N 1N) *NH p ⟧H (x ∷ ρ) ≈⟨ *NH-homo (-N 1N) p x ρ ⟩
⟦ -N 1N ⟧N ρ * ⟦ p ⟧H (x ∷ ρ) ≈⟨ trans (-N‿-homo 1N ρ) (-‿cong (1N-homo ρ)) ⟨ *-cong ⟩ refl ⟩
- 1# * ⟦ p ⟧H (x ∷ ρ) ≈⟨ lemma₇ _ ⟩
- ⟦ p ⟧H (x ∷ ρ) ∎
-N‿-homo : ∀ {n} (p : Normal n) →
∀ ρ → ⟦ -N p ⟧N ρ ≈ - ⟦ p ⟧N ρ
-N‿-homo (con c) _ = -‿homo _
-N‿-homo (poly p) ρ = -H‿-homo p ρ
------------------------------------------------------------------------
-- Correctness
correct-con : ∀ {n} (c : C.Carrier) (ρ : Vec Carrier n) →
⟦ normalise-con c ⟧N ρ ≈ ⟦ c ⟧′
correct-con c [] = refl
correct-con c (x ∷ ρ) = begin
⟦ ∅ *x+HN normalise-con c ⟧H (x ∷ ρ) ≈⟨ ∅*x+HN-homo (normalise-con c) x ρ ⟩
⟦ normalise-con c ⟧N ρ ≈⟨ correct-con c ρ ⟩
⟦ c ⟧′ ∎
correct-var : ∀ {n} (i : Fin n) →
∀ ρ → ⟦ normalise-var i ⟧N ρ ≈ lookup i ρ
correct-var () []
correct-var (suc i) (x ∷ ρ) = begin
⟦ ∅ *x+HN normalise-var i ⟧H (x ∷ ρ) ≈⟨ ∅*x+HN-homo (normalise-var i) x ρ ⟩
⟦ normalise-var i ⟧N ρ ≈⟨ correct-var i ρ ⟩
lookup i ρ ∎
correct-var zero (x ∷ ρ) = begin
(0# * x + ⟦ 1N ⟧N ρ) * x + ⟦ 0N ⟧N ρ ≈⟨ ((refl ⟨ +-cong ⟩ 1N-homo ρ) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ 0N-homo ρ ⟩
(0# * x + 1#) * x + 0# ≈⟨ lemma₅ _ ⟩
x ∎
correct : ∀ {n} (p : Polynomial n) → ∀ ρ → ⟦ p ⟧↓ ρ ≈ ⟦ p ⟧ ρ
correct (op [+] p₁ p₂) ρ = begin
⟦ normalise p₁ +N normalise p₂ ⟧N ρ ≈⟨ +N-homo (normalise p₁) (normalise p₂) ρ ⟩
⟦ p₁ ⟧↓ ρ + ⟦ p₂ ⟧↓ ρ ≈⟨ correct p₁ ρ ⟨ +-cong ⟩ correct p₂ ρ ⟩
⟦ p₁ ⟧ ρ + ⟦ p₂ ⟧ ρ ∎
correct (op [*] p₁ p₂) ρ = begin
⟦ normalise p₁ *N normalise p₂ ⟧N ρ ≈⟨ *N-homo (normalise p₁) (normalise p₂) ρ ⟩
⟦ p₁ ⟧↓ ρ * ⟦ p₂ ⟧↓ ρ ≈⟨ correct p₁ ρ ⟨ *-cong ⟩ correct p₂ ρ ⟩
⟦ p₁ ⟧ ρ * ⟦ p₂ ⟧ ρ ∎
correct (con c) ρ = correct-con c ρ
correct (var i) ρ = correct-var i ρ
correct (p :^ k) ρ = begin
⟦ normalise p ^N k ⟧N ρ ≈⟨ ^N-homo (normalise p) k ρ ⟩
⟦ p ⟧↓ ρ ^ k ≈⟨ correct p ρ ⟨ ^-cong ⟩ PropEq.refl {x = k} ⟩
⟦ p ⟧ ρ ^ k ∎
correct (:- p) ρ = begin
⟦ -N normalise p ⟧N ρ ≈⟨ -N‿-homo (normalise p) ρ ⟩
- ⟦ p ⟧↓ ρ ≈⟨ -‿cong (correct p ρ) ⟩
- ⟦ p ⟧ ρ ∎
------------------------------------------------------------------------
-- "Tactics"
open Reflection setoid var ⟦_⟧ ⟦_⟧↓ correct public
using (prove; solve) renaming (_⊜_ to _:=_)
-- For examples of how solve and _:=_ can be used to
-- semi-automatically prove ring equalities, see, for instance,
-- Data.Digit or Data.Nat.DivMod.
| 35.914972
| 145
| 0.403551
|
2fc17099c074492c322e0c9f6a22dc043fc30fc3
| 1,633
|
agda
|
Agda
|
char.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
char.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
char.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module char where
open import bool
open import nat
open import eq
open import product
open import product-thms
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
postulate
char : Set
{-# BUILTIN CHAR char #-}
----------------------------------------------------------------------
-- primitive operations
----------------------------------------------------------------------
private
primitive
primCharToNat : char → ℕ
primCharEquality : char → char → 𝔹
toNat : char → ℕ
toNat = primCharToNat
infix 4 _=char_
_=char_ : char → char → 𝔹
_=char_ = primCharEquality
postulate
≡char-to-= : (c1 c2 : char) → c1 ≡ c2 → _=char_ c1 c2 ≡ tt
=char-to-≡ : (c1 c2 : char) → _=char_ c1 c2 ≡ tt → c1 ≡ c2
=char-sym : (c1 c2 : char) → (c1 =char c2) ≡ (c2 =char c1)
=char-sym c1 c2 with keep (c1 =char c2)
=char-sym c1 c2 | tt , p rewrite =char-to-≡ c1 c2 p = refl
=char-sym c1 c2 | ff , p with keep (c2 =char c1)
=char-sym c1 c2 | ff , p | tt , p' rewrite =char-to-≡ c2 c1 p' = refl
=char-sym c1 c2 | ff , p | ff , p' rewrite p | p' = refl
postulate
_<char_ : char → char → 𝔹
{-# COMPILE GHC _<char_ = (<) #-}
----------------------------------------------------------------------
-- defined operations
----------------------------------------------------------------------
-- is a decimal digit
is-digit : char → 𝔹
is-digit '0' = tt
is-digit '1' = tt
is-digit '2' = tt
is-digit '3' = tt
is-digit '4' = tt
is-digit '5' = tt
is-digit '6' = tt
is-digit '7' = tt
is-digit '8' = tt
is-digit '9' = tt
is-digit _ = ff
| 24.014706
| 70
| 0.454991
|
3d96c013b17151a76007027ec27ad02823a51d01
| 1,205
|
agda
|
Agda
|
test/succeed/Issue376.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/succeed/Issue376.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue376.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- {-# OPTIONS -v tc.meta:50 #-}
-- Andreas 2012-03-27, record pattern unification
module Issue376 where
import Common.Level
open import Common.Equality
open import Common.Irrelevance
record Sigma (A : Set)(B : A -> Set) : Set where
constructor _,_
field
fst : A
snd : B fst
open Sigma public
record Unit : Set where
constructor unit
bla1 : (A : Set) (a : A) ->
let X : Unit -> A
X = _
in X unit ≡ a
bla1 A a = refl
bla2 : (A : Set)(B : A -> Set) ->
let X : Sigma A B -> Sigma A B
X = _
in (x : A)(y : B x) -> X (x , y) ≡ (x , y)
bla2 A B x y = refl
-- _55 A B (x , y) := (x , y)
-- irrelevant records
bla3 : (A : Set)(B : A -> Set) ->
let X : .(z : Sigma A B) -> (C : .(Sigma A B) -> Set) -> (.(z : Sigma A B) -> C z) -> C z
X = _
in (x : A)(y : B x)(C : .(Sigma A B) -> Set)(k : .(z : Sigma A B) -> C z) ->
X (x , y) C k ≡ k (x , y)
bla3 A B x y C k = refl
-- nested irrelevance
bla4 : (A : Set) ->
let A' = Squash (Squash A) in
let X : .(z : A') -> (C : .A' -> Set) -> (.(z : A') -> C z) -> C z
X = _
in (a : A)(C : .A' -> Set)(k : .(z : A') -> C z) ->
X (squash (squash a)) C k ≡ k (squash (squash a))
bla4 A a C k = refl
| 25.104167
| 91
| 0.488797
|
1ddc12a1df5316a88b7ab6647a0b9d7a0119431b
| 370
|
agda
|
Agda
|
Cubical/Algebra/AbGroup/Instances/FreeAbGroup.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/AbGroup/Instances/FreeAbGroup.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/AbGroup/Instances/FreeAbGroup.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.AbGroup.Instances.FreeAbGroup where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.FreeAbGroup
open import Cubical.Algebra.AbGroup
private variable
ℓ : Level
module _ {A : Type ℓ} where
FAGAbGroup : AbGroup ℓ
FAGAbGroup = makeAbGroup {G = FreeAbGroup A} ε _·_ _⁻¹ trunc assoc identityᵣ invᵣ comm
| 24.666667
| 88
| 0.767568
|
3d73782800f4489c62dc7019dfd6980ed6171630
| 369
|
agda
|
Agda
|
test/Fail/Issue2840.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2840.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2840.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-11-06, issue #2840 reported by wenkokke
Id : (F : Set → Set) → Set → Set
Id F = F
data D (A : Set) : Set where
c : Id _ A
-- WAS: internal error in positivity checker
-- EXPECTED: success, or
-- The target of a constructor must be the datatype applied to its
-- parameters, _F_2 A isn't
-- when checking the constructor c in the declaration of D
| 24.6
| 66
| 0.682927
|
419ccf875ae6c67840aee4eaa90dd3108d16e723
| 670
|
agda
|
Agda
|
src/Categories/Category/SetoidDiscrete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
src/Categories/Category/SetoidDiscrete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
src/Categories/Category/SetoidDiscrete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.SetoidDiscrete where
open import Categories.Category
open import Level
open import Relation.Binary using (Setoid)
open import Function
open import Data.Unit
{-
This is a better version of Discrete, which is more in line with
the rest of this library, and makes a Category out of a Setoid.
But here we have no choice, and we need to truncate the equivalence.
-}
Discrete : ∀ {o ℓ e} (A : Setoid o ℓ) → Category o ℓ e
Discrete {_} {_} {e} A = record
{ Obj = Carrier
; _⇒_ = _≈_
; _≈_ = λ _ _ → Lift e ⊤
; id = refl
; _∘_ = flip trans
}
where
open Setoid A
| 24.814815
| 69
| 0.650746
|
5783cebe99429226ae69ab8380dbc0d6c07c9ea0
| 4,579
|
agda
|
Agda
|
Cubical/Foundations/Path.agda
|
scott-fleischman/cubical
|
337ce3883449862c2d27380b36a2a7b599ef9f0d
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Path.agda
|
scott-fleischman/cubical
|
337ce3883449862c2d27380b36a2a7b599ef9f0d
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Path.agda
|
scott-fleischman/cubical
|
337ce3883449862c2d27380b36a2a7b599ef9f0d
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Path where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- Less polymorphic version of `cong`, to avoid some unresolved metas
cong′ : ∀ {B : Type ℓ'} (f : A → B) {x y : A} (p : x ≡ y)
→ Path B (f x) (f y)
cong′ f = cong f
PathP≡Path : ∀ (P : I → Type ℓ) (p : P i0) (q : P i1) →
PathP P p q ≡ Path (P i1) (transport (λ i → P i) p) q
PathP≡Path P p q i = PathP (λ j → P (i ∨ j)) (transp (λ j → P (i ∧ j)) (~ i) p) q
PathP≃Path : ∀ (P : I → Type ℓ) (p : P i0) (q : P i1) →
PathP P p q ≃ Path (P i1) (transport (λ i → P i) p) q
PathP≃Path P p q = transportEquiv (PathP≡Path P p q)
-- Alternative more unfolded proof
toPathP-isEquiv : ∀ (A : I → Set ℓ) {x y} → isEquiv (toPathP {A = A} {x} {y})
toPathP-isEquiv A {x} {y} = isoToIsEquiv (iso toPathP fromPathP to-from from-to)
where
to-from : ∀ (p : PathP A x y) → toPathP (fromPathP p) ≡ p
to-from p h i = outS (hcomp-unique (λ { j (i = i0) → x ; j (i = i1) → fromPathP p j })
(inS (transp (λ j → A (i ∧ j)) (~ i) x))
\ h → inS (sq1 h i))
h
where
sq1 : (\ h → A [ x ≡ transp (\ j → A (h ∨ j)) h (p h) ]) [ (\ i → transp (λ j → A (i ∧ j)) (~ i) x) ≡ p ]
sq1 = \ h i → comp (\ z → (hcomp (\ w →
\ { (z = i1) → A (i ∧ (w ∨ h))
; (z = i0) → A (i ∧ h)
; (i = i0) → A i0
; (i = i1) → A (h ∨ (w ∧ z))
; (h = i0) → A (i ∧ (w ∧ z))
; (h = i1) → A i})
((A (i ∧ h)))))
(\ z → \ { (i = i0) → x
; (i = i1) → transp (\ j → A (h ∨ (z ∧ j))) (h ∨ ~ z) (p h)
; (h = i0) → transp (λ j → A ((i ∧ z) ∧ j)) (~ (i ∧ z)) x
; (h = i1) → p i })
(p (i ∧ h))
from-to : ∀ (q : transp A i0 x ≡ y) → fromPathP (toPathP {A = A} q) ≡ q
from-to q = (\ h i → outS (transp-hcomp i {A' = A i1} (\ j → inS (A (i ∨ j)))
((λ { j (i = i0) → x ; j (i = i1) → q j }))
(inS ((transp (λ j → A (i ∧ j)) (~ i) x))))
h)
∙ (\ h i → outS (hcomp-unique {A = A i1} ((λ { j (i = i0) → transp A i0 x ; j (i = i1) → q j }))
(inS ((transp (λ j → A (i ∨ j)) i (transp (λ j → A (i ∧ j)) (~ i) x))))
\ h → inS (sq2 h i))
h)
∙ sym (lUnit q)
where
sq2 : (\ h → transp A i0 x ≡ q h) [ (\ i → transp (\ j → A (i ∨ j)) i (transp (\ j → A (i ∧ j)) (~ i) x)) ≡ refl ∙ q ]
sq2 = \ h i → comp (\ z → hcomp (\ w → \ { (i = i1) → A i1
; (i = i0) → A (h ∨ (w ∧ z))
; (h = i0) → A (i ∨ (w ∧ z))
; (h = i1) → A i1
; (z = i0) → A (i ∨ h)
; (z = i1) → A ((i ∨ h) ∨ w) })
(A (i ∨ h)))
(\ z → \ { (i = i0) → transp (λ j → A ((z ∨ h) ∧ j)) (~ z ∧ ~ h) x
; (i = i1) → q (z ∧ h)
; (h = i1) → compPath-filler refl q z i
; (h = i0) → transp (\ j → A (i ∨ (z ∧ j))) (i ∨ ~ z) (transp (\ j → A (i ∧ j)) (~ i) x)
})
(transp (\ j → A ((i ∨ h) ∧ j)) (~ (i ∨ h)) x)
-- Variation of isProp→isSet for PathP
isProp→isSet-PathP : ∀ {ℓ} {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ isProp (PathP (λ i → B i) b0 b1)
isProp→isSet-PathP {B = B} hB b0 b1 =
transport (λ i → isProp (PathP≡Path B b0 b1 (~ i))) (isProp→isSet (hB i1) _ _)
| 53.870588
| 125
| 0.322123
|
06bc6616efb75aaf5db50b92ce6ae770c33fb09d
| 2,786
|
agda
|
Agda
|
src/Tactic/Reflection.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
src/Tactic/Reflection.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
src/Tactic/Reflection.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
module Tactic.Reflection where
open import Prelude hiding (abs; _>>=_) renaming (_>>=′_ to _>>=_)
open import Builtin.Reflection public
open import Tactic.Reflection.DeBruijn public
open import Tactic.Reflection.Telescope public
open import Tactic.Reflection.Substitute public
open import Tactic.Reflection.Free public
open import Tactic.Reflection.Equality public
open import Tactic.Reflection.Meta public
set₀ : Type
set₀ = agda-sort (lit 0)
set! : Type
set! = agda-sort unknown
pattern var₀ x = var x []
pattern var₁ x a = var x (vArg a ∷ [])
pattern var₂ x a b = var x (vArg a ∷ vArg b ∷ [])
pattern var₃ x a b c = var x (vArg a ∷ vArg b ∷ vArg c ∷ [])
pattern var₄ x a b c d = var x (vArg a ∷ vArg b ∷ vArg c ∷ vArg d ∷ [])
pattern con₀ c = con c []
pattern con₁ c x = con c (vArg x ∷ [])
pattern con₂ c x y = con c (vArg x ∷ vArg y ∷ [])
pattern con₃ c x y z = con c (vArg x ∷ vArg y ∷ vArg z ∷ [])
pattern con₄ c x y z u = con c (vArg x ∷ vArg y ∷ vArg z ∷ vArg u ∷ [])
pattern def₀ f = def f []
pattern def₁ f x = def f (vArg x ∷ [])
pattern def₂ f x y = def f (vArg x ∷ vArg y ∷ [])
pattern def₃ f x y z = def f (vArg x ∷ vArg y ∷ vArg z ∷ [])
pattern def₄ f x y z u = def f (vArg x ∷ vArg y ∷ vArg z ∷ vArg u ∷ [])
infixr 4 _`→_ _`→ʰ_ _`→ⁱ_
_`→_ _`→ʰ_ _`→ⁱ_ : Type → Type → Type
_`→_ a b = pi (vArg a) (abs "_" b)
_`→ʰ_ a b = pi (hArg a) (abs "_" b)
_`→ⁱ_ a b = pi (iArg a) (abs "_" b)
`λ : Term → Term
`λ b = lam visible (abs "_" b)
infixl 9 _`∘_
_`∘_ : Term → Term → Term
_`∘_ = def₂ (quote _∘_)
infixr -20 _`$_
_`$_ : Term → Term → Term
_`$_ = def₂ (quote _$_)
_:′_ : Term → Type → TC Term
_:′_ = checkType
λ′ : ∀ {a} {A : Set a} → Arg Type → TC A → TC A
λ′ = extendContext
infix 2 _=′_
_=′_ : Term → Term → TC ⊤
_=′_ = unify
on-goal : (Type → Tactic) → Tactic
on-goal tac hole = inferNormalisedType hole >>= λ goal → tac goal hole
forceFun : Type → TC Type
forceFun a = do
dom ← newMeta set!
rng ← newMeta set!
unify a (dom `→ weaken 1 rng)
normalise a
inferFunRange : Term → TC Type
inferFunRange hole = unPi =<< forceFun =<< inferType hole where
unPi : Type → TC Type
unPi (pi _ (abs _ (meta x _))) = blockOnMeta! x
unPi (pi _ (abs _ b)) = maybe (typeError ( strErr "Must be applied in a non-dependent function position"
∷ termErr b ∷ [])) pure $ strengthen 1 b
unPi x = typeError (strErr "Invalid goal" ∷ termErr x ∷ [])
macro
runT : Tactic → Tactic
runT t = t
evalTC : ∀ {a} {A : Set a} → TC A → Tactic
evalTC {A = A} c hole = do
v ← c
`v ← quoteTC v
`A ← quoteTC A
checkedHole ← checkType hole `A
unify checkedHole `v
macro
evalT : ∀ {a} {A : Set a} → TC A → Tactic
evalT = evalTC
| 28.721649
| 106
| 0.591888
|
591b1e66b2f511ff75e7dd9a687de04c5b9b00f3
| 4,730
|
agda
|
Agda
|
Cubical/HITs/GroupoidQuotients/Properties.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/HITs/GroupoidQuotients/Properties.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/HITs/GroupoidQuotients/Properties.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
{-
Groupoid quotients:
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.GroupoidQuotients.Properties where
open import Cubical.HITs.GroupoidQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥; ∣_∣; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂)
-- Type quotients
private
variable
ℓA ℓR ℓ : Level
A : Type ℓA
R : A → A → Type ℓR
-- B : A // Rt → Type ℓ
-- C : A // Rt → A // Rt → Type ℓ
elimEq// : (Rt : BinaryRelation.isTrans R)
{B : A // Rt → Type ℓ}
(Bprop : (x : A // Rt) → isProp (B x))
{x y : A // Rt}
(eq : x ≡ y)
(bx : B x)
(by : B y) →
PathP (λ i → B (eq i)) bx by
elimEq// Rt {B} Bprop {x = x} =
J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by)
elimProp : (Rt : BinaryRelation.isTrans R)
→ {B : A // Rt → Type ℓ}
→ ((x : A // Rt) → isProp (B x))
→ ((a : A) → B [ a ])
→ (x : A // Rt)
→ B x
elimProp Rt Bprop f [ x ] = f x
elimProp Rt Bprop f (eq// {a} {b} r i) = elimEq// Rt Bprop (eq// r) (f a) (f b) i
elimProp Rt Bprop f (comp// {a} {b} {c} r s i j) =
isSet→isSetDep (λ x → isProp→isSet (Bprop x))
(eq// r) (eq// (Rt a b c r s)) (λ j → [ a ]) (eq// s) (comp// r s)
(λ i → elimEq// Rt Bprop (eq// r) (f a) (f b) i)
(λ i → elimEq// Rt Bprop (eq// (Rt a b c r s)) (f a) (f c) i)
(λ j → f a ) (λ j → elimEq// Rt Bprop (eq// s) (f b) (f c) j) i j
elimProp Rt Bprop f (squash// x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 (λ x → isSet→isGroupoid (isProp→isSet (Bprop x)))
_ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (squash// x y p q r s) i j k
where
g = elimProp Rt Bprop f
elimProp2 : (Rt : BinaryRelation.isTrans R)
→ {C : A // Rt → A // Rt → Type ℓ}
→ ((x y : A // Rt) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
→ (x y : A // Rt)
→ C x y
elimProp2 Rt Cprop f = elimProp Rt (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp Rt (λ y → Cprop [ x ] y) (f x))
[]surjective : (Rt : BinaryRelation.isTrans R)
→ (x : A // Rt ) → ∃[ a ∈ A ] [ a ] ≡ x
[]surjective Rt = elimProp Rt (λ x → squash) (λ a → ∣ a , refl ∣)
elimSet : (Rt : BinaryRelation.isTrans R)
→ {B : A // Rt → Type ℓ}
→ ((x : A // Rt) → isSet (B x))
→ (f : (a : A) → B [ a ])
→ ({a b : A} (r : R a b) → PathP (λ i → B (eq// r i)) (f a) (f b))
→ (x : A // Rt)
→ B x
elimSet Rt Bset f feq [ a ] = f a
elimSet Rt Bset f feq (eq// r i) = feq r i
elimSet Rt Bset f feq (comp// {a} {b} {c} r s i j) =
isSet→isSetDep Bset (eq// r) (eq// (Rt a b c r s)) (λ j → [ a ]) (eq// s) (comp// r s)
(feq r) (feq (Rt a b c r s)) refl (feq s) i j
elimSet Rt Bset f feq (squash// x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 (λ x → isSet→isGroupoid (Bset x))
_ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (squash// x y p q r s) i j k
where
g = elimSet Rt Bset f feq
elim : (Rt : BinaryRelation.isTrans R)
→ {B : A // Rt → Type ℓ}
→ ((x : A // Rt) → isGroupoid (B x))
→ (f : (a : A) → B [ a ])
→ (feq : {a b : A} (r : R a b) → PathP (λ i → B (eq// r i)) (f a) (f b))
→ ({a b c : A} (r : R a b) (s : R b c)
→ SquareP (λ i j → B (comp// r s i j))
(feq r) (feq (Rt a b c r s)) (λ j → f a) (feq s))
→ (x : A // Rt)
→ B x
elim Rt Bgpd f feq fcomp [ a ] = f a
elim Rt Bgpd f feq fcomp (eq// r i) = feq r i
elim Rt Bgpd f feq fcomp (comp// r s i j) = fcomp r s i j
elim Rt Bgpd f feq fcomp (squash// x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 Bgpd
_ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (squash// x y p q r s) i j k
where
g = elim Rt Bgpd f feq fcomp
rec : (Rt : BinaryRelation.isTrans R)
→ {B : Type ℓ}
→ isGroupoid B
→ (f : A → B)
→ (feq : {a b : A} (r : R a b) → f a ≡ f b)
→ ({a b c : A} (r : R a b) (s : R b c)
→ Square (feq r) (feq (Rt a b c r s)) refl (feq s))
→ (x : A // Rt)
→ B
rec Rt Bgpd = elim Rt (λ _ → Bgpd)
module BinarySetRelation {ℓA ℓR : Level} {A : Type ℓA} (R : Rel A A ℓR) where
open BinaryRelation R
isSetValued : Type (ℓ-max ℓA ℓR)
isSetValued = (a b : A) → isSet (R a b)
| 34.525547
| 88
| 0.515011
|
3d9b73c12b25f7bf1931226fc56a0f6402dd3f4b
| 354
|
agda
|
Agda
|
agda/Data/Maybe/Sugar.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/Maybe/Sugar.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/Maybe/Sugar.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Data.Maybe.Sugar where
open import Prelude
open import Data.Maybe
_>>=_ : Maybe A → (A → Maybe B) → Maybe B
nothing >>= f = nothing
just x >>= f = f x
pure : A → Maybe A
pure = just
_<*>_ : Maybe (A → B) → Maybe A → Maybe B
nothing <*> xs = nothing
just f <*> nothing = nothing
just f <*> just x = just (f x)
| 18.631579
| 41
| 0.60452
|
1d32d9db34a34c51095ee8befdebe03e9810ef6b
| 6,919
|
agda
|
Agda
|
src/Categories/NaturalTransformation/Monoidal/Symmetric.agda
|
o1lo01ol1o/agda-categories
|
5fc007768264a270b8ff319570225986773da601
|
[
"MIT"
] | null | null | null |
src/Categories/NaturalTransformation/Monoidal/Symmetric.agda
|
o1lo01ol1o/agda-categories
|
5fc007768264a270b8ff319570225986773da601
|
[
"MIT"
] | null | null | null |
src/Categories/NaturalTransformation/Monoidal/Symmetric.agda
|
o1lo01ol1o/agda-categories
|
5fc007768264a270b8ff319570225986773da601
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
-- Monoidal natural transformations between lax and strong symmetric
-- monoidal functors.
--
-- NOTE. Symmetric monoidal natural transformations are really just
-- monoidal natural transformations that happen to go between
-- symmetric monoidal functors. No additional conditions are
-- necessary. Nevertheless, the definitions in this module are useful
-- when one is working in a symmetric monoidal setting. They also
-- help Agda's type checker by bundling the (symmetric monoidal)
-- categories and functors involved.
--
-- See
-- * John Baez, Some definitions everyone should know,
-- https://math.ucr.edu/home/baez/qg-fall2004/definitions.pdf
-- * https://ncatlab.org/nlab/show/monoidal+natural+transformation
module Categories.NaturalTransformation.Monoidal.Symmetric where
open import Level
open import Categories.Category.Monoidal using (SymmetricMonoidalCategory)
import Categories.Functor.Monoidal.Symmetric as BMF
open import Categories.Functor.Monoidal.Properties using ()
renaming (∘-SymmetricMonoidal to _∘Fˡ_; ∘-StrongSymmetricMonoidal to _∘Fˢ_)
open import Categories.NaturalTransformation as NT using (NaturalTransformation)
import Categories.NaturalTransformation.Monoidal as MNT
module Lax where
open BMF.Lax using (SymmetricMonoidalFunctor)
open MNT.Lax using (IsMonoidalNaturalTransformation)
open SymmetricMonoidalFunctor using ()
renaming (F to UF; monoidalFunctor to MF)
module _ {o ℓ e o′ ℓ′ e′}
{C : SymmetricMonoidalCategory o ℓ e}
{D : SymmetricMonoidalCategory o′ ℓ′ e′} where
-- Monoidal natural transformations between symmetric monoidal functors.
record SymmetricMonoidalNaturalTransformation
(F G : SymmetricMonoidalFunctor C D) : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
field
U : NaturalTransformation (UF F) (UF G)
isMonoidal : IsMonoidalNaturalTransformation (MF F) (MF G) U
open NaturalTransformation U public
open IsMonoidalNaturalTransformation isMonoidal public
-- To shorten some definitions
private
_⇛_ = SymmetricMonoidalNaturalTransformation
module U = MNT.Lax
module _ {o ℓ e o′ ℓ′ e′}
{C : SymmetricMonoidalCategory o ℓ e}
{D : SymmetricMonoidalCategory o′ ℓ′ e′} where
-- Conversions
⌊_⌋ : {F G : SymmetricMonoidalFunctor C D} →
F ⇛ G → U.MonoidalNaturalTransformation (MF F) (MF G)
⌊ α ⌋ = record { U = U ; isMonoidal = isMonoidal }
where open SymmetricMonoidalNaturalTransformation α
⌈_⌉ : {F G : SymmetricMonoidalFunctor C D} →
U.MonoidalNaturalTransformation (MF F) (MF G) → F ⇛ G
⌈ α ⌉ = record { U = U ; isMonoidal = isMonoidal }
where open U.MonoidalNaturalTransformation α
-- Identity and compositions
infixr 9 _∘ᵥ_
id : {F : SymmetricMonoidalFunctor C D} → F ⇛ F
id = ⌈ U.id ⌉
_∘ᵥ_ : {F G H : SymmetricMonoidalFunctor C D} → G ⇛ H → F ⇛ G → F ⇛ H
α ∘ᵥ β = ⌈ ⌊ α ⌋ U.∘ᵥ ⌊ β ⌋ ⌉
module _ {o ℓ e o′ ℓ′ e′ o″ ℓ″ e″}
{C : SymmetricMonoidalCategory o ℓ e}
{D : SymmetricMonoidalCategory o′ ℓ′ e′}
{E : SymmetricMonoidalCategory o″ ℓ″ e″} where
infixr 9 _∘ₕ_ _∘ˡ_ _∘ʳ_
_∘ₕ_ : {F G : SymmetricMonoidalFunctor C D}
{H I : SymmetricMonoidalFunctor D E} →
H ⇛ I → F ⇛ G → (H ∘Fˡ F) ⇛ (I ∘Fˡ G)
α ∘ₕ β = ⌈ ⌊ α ⌋ U.∘ₕ ⌊ β ⌋ ⌉
_∘ˡ_ : {F G : SymmetricMonoidalFunctor C D}
(H : SymmetricMonoidalFunctor D E) → F ⇛ G → (H ∘Fˡ F) ⇛ (H ∘Fˡ G)
H ∘ˡ α = id {F = H} ∘ₕ α
_∘ʳ_ : {G H : SymmetricMonoidalFunctor D E} →
G ⇛ H → (F : SymmetricMonoidalFunctor C D) → (G ∘Fˡ F) ⇛ (H ∘Fˡ F)
α ∘ʳ F = α ∘ₕ id {F = F}
module Strong where
open BMF.Strong using (SymmetricMonoidalFunctor)
open MNT.Strong using (IsMonoidalNaturalTransformation)
open SymmetricMonoidalFunctor using () renaming
( F to UF
; monoidalFunctor to MF
; laxSymmetricMonoidalFunctor to laxBMF
)
module _ {o ℓ e o′ ℓ′ e′}
{C : SymmetricMonoidalCategory o ℓ e}
{D : SymmetricMonoidalCategory o′ ℓ′ e′} where
-- Monoidal natural transformations between symmetric strong
-- monoidal functors.
record SymmetricMonoidalNaturalTransformation
(F G : SymmetricMonoidalFunctor C D) : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
field
U : NaturalTransformation (UF F) (UF G)
isMonoidal : IsMonoidalNaturalTransformation (MF F) (MF G) U
laxBNT : Lax.SymmetricMonoidalNaturalTransformation (laxBMF F) (laxBMF G)
laxBNT = record { U = U ; isMonoidal = isMonoidal }
open Lax.SymmetricMonoidalNaturalTransformation laxBNT public
hiding (U; isMonoidal)
-- To shorten some definitions
private
_⇛_ = SymmetricMonoidalNaturalTransformation
module U = MNT.Strong
module _ {o ℓ e o′ ℓ′ e′}
{C : SymmetricMonoidalCategory o ℓ e}
{D : SymmetricMonoidalCategory o′ ℓ′ e′} where
-- Conversions
⌊_⌋ : {F G : SymmetricMonoidalFunctor C D} →
F ⇛ G → U.MonoidalNaturalTransformation (MF F) (MF G)
⌊ α ⌋ = record { U = U ; isMonoidal = isMonoidal }
where open SymmetricMonoidalNaturalTransformation α
⌈_⌉ : {F G : SymmetricMonoidalFunctor C D} →
U.MonoidalNaturalTransformation (MF F) (MF G) → F ⇛ G
⌈ α ⌉ = record { U = U ; isMonoidal = isMonoidal }
where open U.MonoidalNaturalTransformation α
-- Identity and compositions
infixr 9 _∘ᵥ_
id : {F : SymmetricMonoidalFunctor C D} → F ⇛ F
id = ⌈ U.id ⌉
_∘ᵥ_ : {F G H : SymmetricMonoidalFunctor C D} → G ⇛ H → F ⇛ G → F ⇛ H
α ∘ᵥ β = ⌈ ⌊ α ⌋ U.∘ᵥ ⌊ β ⌋ ⌉
module _ {o ℓ e o′ ℓ′ e′ o″ ℓ″ e″}
{C : SymmetricMonoidalCategory o ℓ e}
{D : SymmetricMonoidalCategory o′ ℓ′ e′}
{E : SymmetricMonoidalCategory o″ ℓ″ e″} where
infixr 9 _∘ₕ_ _∘ˡ_ _∘ʳ_
_∘ₕ_ : {F G : SymmetricMonoidalFunctor C D}
{H I : SymmetricMonoidalFunctor D E} →
H ⇛ I → F ⇛ G → (H ∘Fˢ F) ⇛ (I ∘Fˢ G)
-- NOTE: this definition is clearly equivalent to
--
-- α ∘ₕ β = ⌈ ⌊ α ⌋ U.∘ₕ ⌊ β ⌋ ⌉
--
-- but the latter takes an unreasonably long time to typecheck,
-- while the unfolded version typechecks almost immediately.
α ∘ₕ β = record
{ U = C.U
; isMonoidal = record
{ ε-compat = C.ε-compat
; ⊗-homo-compat = C.⊗-homo-compat
}
}
where module C = U.MonoidalNaturalTransformation (⌊ α ⌋ U.∘ₕ ⌊ β ⌋)
_∘ˡ_ : {F G : SymmetricMonoidalFunctor C D}
(H : SymmetricMonoidalFunctor D E) → F ⇛ G → (H ∘Fˢ F) ⇛ (H ∘Fˢ G)
H ∘ˡ α = id {F = H} ∘ₕ α
_∘ʳ_ : {G H : SymmetricMonoidalFunctor D E} →
G ⇛ H → (F : SymmetricMonoidalFunctor C D) → (G ∘Fˢ F) ⇛ (H ∘Fˢ F)
α ∘ʳ F = α ∘ₕ id {F = F}
| 35.30102
| 80
| 0.62509
|
3108637958879ff8d6b952f0647bdcb3196b643b
| 566
|
agda
|
Agda
|
src/FRP/LTL/ISet/Stateless.agda
|
agda/agda-frp-ltl
|
e88107d7d192cbfefd0a94505e6a5793afe1a7a5
|
[
"MIT"
] | 21
|
2015-07-02T20:25:05.000Z
|
2020-06-15T02:51:13.000Z
|
src/FRP/LTL/ISet/Stateless.agda
|
agda/agda-frp-ltl
|
e88107d7d192cbfefd0a94505e6a5793afe1a7a5
|
[
"MIT"
] | 2
|
2015-03-01T07:01:31.000Z
|
2015-03-02T15:23:53.000Z
|
src/FRP/LTL/ISet/Stateless.agda
|
agda/agda-frp-ltl
|
e88107d7d192cbfefd0a94505e6a5793afe1a7a5
|
[
"MIT"
] | 3
|
2015-03-01T07:33:00.000Z
|
2022-03-12T11:39:04.000Z
|
open import Data.Product using ( _,_ )
open import FRP.LTL.ISet.Core using ( ISet ; _⇛_ ; mset ; M⟦_⟧ ; ⟦_⟧ ; [_] ; subsumM⟦_⟧ )
open import FRP.LTL.Time.Interval using ( ⊑-refl )
module FRP.LTL.ISet.Stateless where
infixr 2 _⇒_
_⇒_ : ISet → ISet → ISet
A ⇒ B = mset A ⇛ B
-- We could define $ as
-- f $ σ = i→m (λ j j⊑i → f j j⊑i [ subsumM⟦ A ⟧ j i j⊑i σ ])
-- but we inline i→m for efficiency
_$_ : ∀ {A B i} → M⟦ A ⇒ B ⟧ i → M⟦ A ⟧ i → M⟦ B ⟧ i
_$_ {A} {[ B ]} {i} f σ = f i ⊑-refl [ σ ]
_$_ {A} {B ⇛ C} {i} f σ = λ j j⊑i → f j j⊑i [ subsumM⟦ A ⟧ j i j⊑i σ ]
| 31.444444
| 89
| 0.531802
|
3d8d71347aa28d33da9f0397149108b2f1382d48
| 14,259
|
agda
|
Agda
|
Preliminaries.agda
|
ayberkt/system-t-normalization
|
785c3d1f93ce2dac7801504b806abfd59f3875f6
|
[
"BSD-3-Clause"
] | 3
|
2016-06-24T14:36:42.000Z
|
2016-06-25T03:40:58.000Z
|
Preliminaries.agda
|
ayberkt/system-t-normalization
|
785c3d1f93ce2dac7801504b806abfd59f3875f6
|
[
"BSD-3-Clause"
] | null | null | null |
Preliminaries.agda
|
ayberkt/system-t-normalization
|
785c3d1f93ce2dac7801504b806abfd59f3875f6
|
[
"BSD-3-Clause"
] | null | null | null |
module Preliminaries where
-- universe levels
postulate
Level : Set
lZ : Level
lS : Level -> Level
lmax : Level -> Level -> Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO lZ #-}
{-# BUILTIN LEVELSUC lS #-}
{-# BUILTIN LEVELMAX lmax #-}
-- ----------------------------------------------------------------------
-- functions
_o_ : {A B C : Set} → (B → C) → (A → B) → A → C
g o f = \ x → g (f x)
infixr 10 _o_
-- ----------------------------------------------------------------------
-- identity type
data _==_ {l : Level} {A : Set l} (M : A) : A → Set l where
Refl : M == M
{-# BUILTIN EQUALITY _==_ #-}
{-# BUILTIN REFL Refl #-}
transport : {l1 : Level} {l2 : Level} {A : Set l1} (B : A → Set l2)
{a1 a2 : A} → a1 == a2 → (B a1 → B a2)
transport B Refl = λ x → x
! : {l : Level} {A : Set l} {M N : A} → M == N → N == M
! Refl = Refl
_∘_ : {l : Level} {A : Set l} {M N P : A}
→ N == P → M == N → M == P
β ∘ Refl = β
ap : {l1 l2 : Level} {A : Set l1} {B : Set l2} {M N : A}
(f : A → B) → M == N → (f M) == (f N)
ap f Refl = Refl
ap2 : {l1 l2 l3 : Level} {A : Set l1} {B : Set l2} {C : Set l3} {M N : A} {M' N' : B} (f : A -> B -> C) -> M == N -> M' == N' -> (f M M') == (f N N')
ap2 f Refl Refl = Refl
postulate
-- function extensionality
λ= : {l1 l2 : Level} {A : Set l1} {B : A -> Set l2} {f g : (x : A) -> B x} -> ((x : A) -> (f x) == (g x)) -> f == g
-- function extensionality for implicit functions
λ=i : {l1 l2 : Level} {A : Set l1} {B : A -> Set l2} {f g : {x : A} -> B x} -> ((x : A) -> (f {x}) == (g {x})) -> _==_ {_}{ {x : A} → B x } f g
private primitive primTrustMe : {l : Level} {A : Set l} {x y : A} -> x == y
infixr 9 _==_
infix 2 _∎
infixr 2 _=〈_〉_
_=〈_〉_ : {l : Level} {A : Set l} (x : A) {y z : A} → x == y → y == z → x == z
_ =〈 p1 〉 p2 = (p2 ∘ p1)
_∎ : {l : Level} {A : Set l} (x : A) → x == x
_∎ _ = Refl
-- ----------------------------------------------------------------------
-- product types
record Unit : Set where
constructor <>
record Σ {l1 l2 : Level} {A : Set l1} (B : A -> Set l2) : Set (lmax l1 l2) where
constructor _,_
field
fst : A
snd : B fst
open Σ public
infixr 0 _,_
_×_ : {l1 l2 : Level} → Set l1 -> Set l2 -> Set (lmax l1 l2)
A × B = Σ (\ (_ : A) -> B)
infixr 10 _×_
-- ----------------------------------------------------------------------
-- booleans
data Bool : Set where
True : Bool
False : Bool
{-# COMPILED_DATA Bool Bool True False #-}
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE True #-}
{-# BUILTIN FALSE False #-}
-- ----------------------------------------------------------------------
-- order
data Order : Set where
Less : Order
Equal : Order
Greater : Order
-- ----------------------------------------------------------------------
-- sums
data Void : Set where
abort : {A : Set} → Void → A
abort ()
data Either (A B : Set) : Set where
Inl : A → Either A B
Inr : B → Either A B
DecEq : Set → Set
DecEq A = (x y : A) → Either (x == y) (x == y → Void)
-- ----------------------------------------------------------------------
-- natural numbers
module Nat where
data Nat : Set where
Z : Nat
S : Nat -> Nat
-- let's you use numerals for Nat
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN SUC S #-}
{-# BUILTIN ZERO Z #-}
_+_ : Nat → Nat → Nat
Z + n = n
(S m) + n = S (m + n)
max : Nat → Nat → Nat
max Z n = n
max m Z = m
max (S m) (S n) = S (max m n)
equal : Nat → Nat → Bool
equal Z Z = True
equal Z (S _) = False
equal (S _) Z = False
equal (S m) (S n) = equal m n
compare : Nat → Nat → Order
compare Z Z = Equal
compare Z (S m) = Less
compare (S n) Z = Greater
compare (S n) (S m) = compare n m
open Nat public using (Nat ; Z ; S)
-- ----------------------------------------------------------------------
-- monad
module Monad where
record Monad : Set1 where
field
T : Set → Set
return : ∀ {A} → A → T A
_>>=_ : ∀ {A B} → T A → (A → T B) -> T B
-- ----------------------------------------------------------------------
-- options
module Maybe where
data Maybe {l : Level} (A : Set l) : Set l where
Some : A → Maybe A
None : Maybe A
Monad : Monad.Monad
Monad = record { T = Maybe; return = Some; _>>=_ = (λ {None _ → None; (Some v) f → f v}) }
open Maybe public using (Maybe;Some;None)
-- ----------------------------------------------------------------------
-- lists
module List where
data List {l : Level} (A : Set l) : Set l where
[] : List A
_::_ : A -> List A -> List A
{-# COMPILED_DATA List [] [] (:) #-}
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
infixr 99 _::_
_++_ : {A : Set} → List A → List A → List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
infixr 10 _++_
map : {l1 l2 : Level} {A : Set l1} {B : Set l2} → (A → B) → List A → List B
map f [] = []
map f (x :: xs) = f x :: map f xs
map-id : {l : Level} {A : Set l} (l : List A) → map (\ (x : A) → x) l == l
map-id [] = Refl
map-id (x :: l) with map (\ x -> x) l | map-id l
... | ._ | Refl = Refl
module Uninformative where
-- simply typed version
peelOff : {A : Set} (eq : A → A → Bool) → List A → List A → Maybe (List A)
peelOff eq [] ys = Some ys
peelOff eq (_ :: _) [] = None
peelOff eq (x :: xs) (y :: ys) with eq x y
... | False = None
... | True = peelOff eq xs ys
peelOff : {A : Set} (eq : DecEq A) → (xs ys : List A) → Maybe (Σ \ zs → (xs ++ zs) == ys )
peelOff eq [] ys = Some (ys , Refl)
peelOff eq (_ :: _) [] = None
peelOff eq (x :: xs) (y :: ys) with eq x y
... | Inr xyneq = None
peelOff eq (x :: xs) (.x :: ys) | Inl Refl with peelOff eq xs ys
peelOff eq (x :: xs) (.x :: .(xs ++ zs)) | Inl Refl | Some (zs , Refl) = Some (zs , Refl)
... | None = None
[_] : {A : Set} → A → List A
[ c ] = c :: []
++-assoc : ∀ {A} (l1 l2 l3 : List A) → (l1 ++ l2) ++ l3 == l1 ++ (l2 ++ l3)
++-assoc [] l2 l3 = Refl
++-assoc (x :: xs) l2 l3 = ap (_::_ x) (++-assoc xs l2 l3)
open List public using (List ; [] ; _::_)
-- ----------------------------------------------------------------------
-- characters
module Char where
postulate {- Agda Primitive -}
Char : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
private
primitive
primCharToNat : Char → Nat
primCharEquality : Char → Char → Bool
toNat : Char → Nat
toNat = primCharToNat
equalb : Char -> Char -> Bool
equalb = primCharEquality
-- need to go outside the real language a little to give the primitives good types,
-- but from the outside this should be safe
equal : DecEq Char
equal x y with equalb x y
... | True = Inl primTrustMe
... | False = Inr canthappen where
postulate canthappen : _
open Char public using (Char)
-- ----------------------------------------------------------------------
-- vectors
module Vector where
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
_::_ : ∀ {n} → A → Vec A n → Vec A (S n)
infixr 99 _::_
Vec-elim : {A : Set} (P : {n : Nat} → Vec A n → Set)
→ (P [])
→ ({n : Nat} (x : A) (xs : Vec A n) → P xs → P (x :: xs))
→ {n : Nat} (v : Vec A n) → P v
Vec-elim P n c [] = n
Vec-elim P n c (y :: ys) = c y ys (Vec-elim P n c ys)
fromList : {A : Set} → List A → Σ \n → Vec A n
fromList [] = _ , []
fromList (x :: xs) = _ , x :: snd (fromList xs)
toList : {A : Set} {n : Nat} → Vec A n → List A
toList [] = []
toList (x :: xs) = x :: (toList xs)
toList' : {A : Set} → (Σ \ n → Vec A n) → List A
toList' (._ , []) = []
toList' (._ , (x :: xs)) = x :: (toList' (_ , xs))
to-from : {A : Set} (l : List A) → toList' (fromList l) == l
to-from [] = Refl
to-from (x :: l) with toList' (fromList l) | to-from l
to-from (x :: l) | .l | Refl = Refl
from-to : {A : Set} (l : Σ \n → Vec A n) → fromList (toList' l) == l
from-to (._ , []) = Refl
from-to (._ , x :: l) with fromList (toList' (_ , l)) | from-to (_ , l)
from-to (.(S n) , _::_ {n} x l) | .(n , l) | Refl = Refl
-- ----------------------------------------------------------------------
-- strings
module String where
postulate {- Agda Primitive -}
String : Set
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
private
primitive
primStringToList : String -> List Char
primStringFromList : List Char -> String
primStringAppend : String -> String -> String
primStringEquality : String -> String -> Bool
equal : String -> String -> Bool
equal = primStringEquality
toList = primStringToList
fromList = primStringFromList
append = primStringAppend
toVec : String -> Σ \ m → Vector.Vec Char m
toVec = Vector.fromList o toList
-- ----------------------------------------------------------------------
-- fancy order
module FancyOrder where
data FancyOrder {A : Set} {_≤_ : A → A → Set} (a1 a2 : A) : Set where
Less : a1 ≤ a2 -> (a1 == a2 -> Void) → FancyOrder a1 a2
Equal : a1 == a2 -> FancyOrder a1 a2
Greater : a2 ≤ a1 → (a1 == a2 -> Void) -> FancyOrder a1 a2
record DecidableOrder : Set1 where
field
A : Set
_≤_ : A → A → Set
≤-refl : ∀ {a} → a ≤ a
≤-trans : ∀ {a1 a2 a3} → a1 ≤ a2 -> a2 ≤ a3 -> a1 ≤ a3
≤-saturated : ∀ {a1 a2} -> a1 ≤ a2 -> a2 ≤ a1 -> a1 == a2
compare : (a1 a2 : A) → FancyOrder {A}{_≤_} a1 a2
≤-refl' : ∀ {a1 a2} → a1 == a2 -> a1 ≤ a2
≤-refl' Refl = ≤-refl
min : A → A → A
min a1 a2 with compare a1 a2
... | Less _ _ = a1
... | Equal _ = a1
... | Greater _ _ = a2
min-≤-1 : {a1 a2 : A} → min a1 a2 ≤ a1
min-≤-1 {a1}{a2} with compare a1 a2
... | Less lt _ = ≤-refl
... | Equal eq = ≤-refl
... | Greater gt _ = gt
min-≤-2 : {a1 a2 : A} → min a1 a2 ≤ a2
min-≤-2 {a1}{a2} with compare a1 a2
... | Less lt _ = lt
min-≤-2 | Equal Refl = ≤-refl
... | Greater gt _ = ≤-refl
min-sym : {a1 a2 : A} → min a1 a2 == min a2 a1
min-sym {a1}{a2} with compare a1 a2 | compare a2 a1
min-sym | Less lt12 _ | Less lt21 _ = ≤-saturated lt12 lt21
min-sym | Less lt12 _ | Equal Refl = Refl
min-sym | Less lt12 _ | Greater gt21 _ = Refl
min-sym | Equal eq12 | Less lt21 _ = eq12
min-sym | Equal eq12 | Equal eq21 = eq12
min-sym | Equal eq12 | Greater gt21 _ = Refl
min-sym | Greater gt12 _ | Less lt21 _ = Refl
min-sym | Greater gt12 _ | Equal eq21 = Refl
min-sym | Greater gt12 _ | Greater gt21 _ = ≤-saturated gt12 gt21
min-≤ : {a1 a2 : A} → a1 ≤ a2 -> (min a1 a2) == a1
min-≤ {a1} {a2} lt1 with compare a1 a2
... | Less lt _ = Refl
... | Equal eq = Refl
... | Greater gt _ = ≤-saturated gt lt1
max : A → A → A
max a1 a2 with compare a1 a2
... | Less _ _ = a2
... | Equal _ = a2
... | Greater _ _ = a1
max-≥-1 : {a1 a2 : A} → a1 ≤ max a1 a2
max-≥-1 {a1}{a2} with compare a1 a2
... | Less lt _ = lt
max-≥-1 | Equal Refl = ≤-refl
... | Greater gt _ = ≤-refl
max-≥-2 : {a1 a2 : A} → a2 ≤ max a1 a2
max-≥-2 {a1}{a2} with compare a1 a2
... | Less lt _ = ≤-refl
... | Equal eq = ≤-refl
... | Greater gt _ = gt
min-monotone : {a1 a1' a2 a2' : A} → a1 ≤ a1' -> a2 ≤ a2' -> min a1 a2 ≤ min a1' a2'
min-monotone {a1}{a1'}{a2}{a2'} lt1 lt2 with compare a1 a2 | compare a1' a2'
min-monotone lt1 lt2 | Less x x₁ | Less x₂ x₃ = lt1
min-monotone lt1 lt2 | Less x x₁ | Equal x₂ = lt1
min-monotone lt1 lt2 | Less x x₁ | Greater x₂ x₃ = ≤-trans x lt2
min-monotone lt1 lt2 | Equal x | Less x₁ x₂ = lt1
min-monotone lt1 lt2 | Equal x | Equal x₁ = lt1
min-monotone lt1 lt2 | Equal Refl | Greater x₁ x₂ = lt2
min-monotone lt1 lt2 | Greater x x₁ | Less x₂ x₃ = ≤-trans x lt1
min-monotone lt1 lt2 | Greater x x₁ | Equal x₂ = ≤-trans x lt1
min-monotone lt1 lt2 | Greater x x₁ | Greater x₂ x₃ = lt2
max-sym : {a1 a2 : A} → max a1 a2 == max a2 a1
max-sym {a1}{a2} with compare a1 a2 | compare a2 a1
max-sym | Less lt12 _ | Less lt21 _ = ≤-saturated lt21 lt12
max-sym | Less lt12 _ | Equal eq21 = eq21
max-sym | Less lt12 _ | Greater gt21 _ = Refl
max-sym | Equal eq12 | Less lt21 _ = ! eq12
max-sym | Equal eq12 | Equal eq21 = eq21
max-sym | Equal eq12 | Greater gt21 _ = Refl
max-sym | Greater gt12 _ | Less lt21 _ = Refl
max-sym | Greater gt12 _ | Equal eq21 = Refl
max-sym | Greater gt12 _ | Greater gt21 _ = ≤-saturated gt21 gt12
max-≤ : {a1 a2 : A} → a1 ≤ a2 -> (max a1 a2) == a2
max-≤ {a1} {a2} lt1 with compare a1 a2
... | Less lt _ = Refl
... | Equal eq = Refl
... | Greater gt _ = ≤-saturated lt1 gt
max-monotone : {a1 a1' a2 a2' : A} → a1 ≤ a1' -> a2 ≤ a2' -> max a1 a2 ≤ max a1' a2'
max-monotone {a1}{a1'}{a2}{a2'} lt1 lt2 with compare a1 a2 | compare a1' a2'
max-monotone lt1 lt2 | Less x x₁ | Less x₂ x₃ = lt2
max-monotone lt1 lt2 | Less x x₁ | Equal x₂ = lt2
max-monotone lt1 lt2 | Less x x₁ | Greater x₂ x₃ = ≤-trans lt2 x₂
max-monotone lt1 lt2 | Equal x | Less x₁ x₂ = lt2
max-monotone lt1 lt2 | Equal x | Equal x₁ = lt2
max-monotone lt1 lt2 | Equal Refl | Greater x₁ x₂ = lt1
max-monotone lt1 lt2 | Greater x x₁ | Less x₂ x₃ = ≤-trans lt1 x₂
max-monotone lt1 lt2 | Greater x x₁ | Equal Refl = lt1
max-monotone lt1 lt2 | Greater x x₁ | Greater x₂ x₃ = lt1
| 30.796976
| 151
| 0.458167
|
3d375b184f959d8ed92cd09b34993d58704e116d
| 1,493
|
agda
|
Agda
|
GauInt/Instances.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
GauInt/Instances.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
GauInt/Instances.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
-- Instances of Gaussian integers.
{-# OPTIONS --without-K --safe #-}
module GauInt.Instances where
open import Data.Integer using (+_ ; -[1+_] ; +[1+_])
open import Data.Nat using (suc )
open import Instances
open import GauInt.Base renaming (-_ to -𝔾_ ; _-_ to _-𝔾_ ; _+_ to _+𝔾_ ; _*_ to _*𝔾_ ; NonZero to NonZero𝔾 ; rank to rank𝔾)
-- Instances to overload operations.
instance
sr𝔾 : SemiRing 𝔾
_+_ {{sr𝔾}} = _+𝔾_
_*_ {{sr𝔾}} = _*𝔾_
0# {{sr𝔾}} = 0𝔾
1# {{sr𝔾}} = 1𝔾
instance
ring𝔾 : Ring 𝔾
ring𝔾 .sra = sr𝔾
ring𝔾 .-_ = -𝔾_
instance
Rank𝔾 : Rank 𝔾
Rank𝔾 .rank = rank𝔾
-- This depends on how the boolean equality on 𝔾 is defined. To be
-- precise, it depends on the order of comparing the components.
instance
nzp : ∀ {n} {y} -> NonZero𝔾 (+ suc n + y i)
nzp = _
nzn : ∀ {n} {y} -> NonZero𝔾 (-[1+ n ] + y i)
nzn = _
nzpi : ∀ {n} -> NonZero𝔾 (0# + (+ suc n) i)
nzpi = _
nzni : ∀ {n} -> NonZero𝔾 (0# + (-[1+ n ]) i)
nzni = _
instance
NZT𝔾 : NonZeroTypeclass 𝔾
NZT𝔾 .NonZero = NonZero𝔾
{-
-- Translation from NonZero predicate to non-equality.
test-t : ∀ (x : 𝔾) -> .{{NonZero x}} -> ¬ x ≡ 0#
test-t (+_ zero + +[1+ n ] i) = λ {()}
test-t (+_ zero + -[1+_] n i) = λ {()}
test-t (+[1+ n ] + x₁ i) = λ {()}
test-t (-[1+_] n + x₁ i) = λ {()}
open import Relation.Binary.Structures
open IsDecEquivalence {{...}}
open IsDecTotalOrder {{...}}
open import Data.Nat.Instances
open import Data.Integer.Instances
test : {!!}
test = 0ℤ ≤? 0ℤ
-}
| 21.637681
| 124
| 0.586068
|
58233971c6f0cd908ef7d6637bfcf334676bf33c
| 1,365
|
agda
|
Agda
|
Cubical/HITs/Truncation/Base.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/Truncation/Base.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Truncation/Base.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Truncation.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.NatMinusOne
open import Cubical.Data.NatMinusTwo hiding (-1+_)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Sn
-- For the hub-and-spoke construction discussed in the HoTT book, which doesn't work in the base case
-- of contractibility, see `HITs.Truncation.FromNegOne`. The definition of truncation here contains
-- two more constructors which are redundant when n ≥ 1 but give contractibility when n = 0.
-- data hLevelTrunc {ℓ} (n : ℕ) (A : Type ℓ) : Type (ℓ-max ℓ ℓ') where
-- -- the hub-and-spoke definition in `Truncation.FromNegOne`
-- ∣_∣ : A → hLevelTrunc n A
-- hub : (f : S (-1+ n) → hLevelTrunc n A) → hLevelTrunc n A
-- spoke : (f : S (-1+ n) → hLevelTrunc n A) (s : S) → hub f ≡ f s
-- -- two additional constructors needed to ensure that hLevelTrunc 0 A is contractible
-- ≡hub : ∀ {x y} (p : S (-1+ n) → x ≡ y) → x ≡ y
-- ≡spoke : ∀ {x y} (p : S (-1+ n) → x ≡ y) (s : S (-1+ n)) → ≡hub p ≡ p s
hLevelTrunc : ∀ {ℓ} → ℕ → Type ℓ → Type ℓ
hLevelTrunc n A = Null (S (-1+ n)) A
-- a re-indexing of `hLevelTrunc` which is consistent with the HoTT book
∥_∥_ : ∀ {ℓ} → Type ℓ → ℕ₋₂ → Type ℓ
∥ A ∥ n = hLevelTrunc (2+ n) A -- ≡ Null (S (1+ n)) A
| 45.5
| 101
| 0.644689
|
2f9c7d9081327136236d0a2dd2dc791deab00add
| 109
|
agda
|
Agda
|
Cubical/Algebra/Algebra.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/Algebra.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/Algebra.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Algebra where
open import Cubical.Algebra.Algebra.Base public
| 21.8
| 47
| 0.770642
|
207f590394c1e603bf5915ea80bfd786ea06f4ab
| 204
|
agda
|
Agda
|
agda/MoreLogic.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
agda/MoreLogic.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
agda/MoreLogic.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module MoreLogic where -- hProp logic
open import MoreLogic.Reasoning public
open import MoreLogic.Definitions public
open import MoreLogic.Properties public
| 25.5
| 43
| 0.794118
|
31b31e259f45073b995e2713143c0a4a39e39744
| 15,124
|
agda
|
Agda
|
Univalence/FinEquivEquivPlus.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/FinEquivEquivPlus.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/FinEquivEquivPlus.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module FinEquivEquivPlus where
open import Data.Product using (_×_; proj₁; proj₂)
open import Equiv using (refl∼; sym∼; sym≃; _⊎≃_; id≃; _≃_; _●_; _×≃_; qinv)
open import FinEquivPlusTimes using (F0≃⊥; module Plus; module Times)
open Plus using (⊎≃+; +≃⊎)
open Times using (×≃*; *≃×)
open import FinEquivTypeEquiv
using (_fin≃_; module PlusE; module TimesE; module PlusTimesE)
open PlusE using (_+F_; unite+; uniti+; unite+r; uniti+r; assocr+; assocl+;
swap+; sswap+)
open TimesE using (_*F_; unite*; uniti*; unite*r; uniti*r; assocr*; assocl*;
swap*; sswap*)
open PlusTimesE using (distz; factorz; distzr; factorzr;
dist; factor; distl; factorl)
open import EquivEquiv
open import TypeEquiv
using (unite₊equiv; unite₊′equiv; assocl₊equiv)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤)
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Fin using (Fin)
open import Data.Sum using (_⊎_)
open import Data.Product using (_,_)
import Relation.Binary.PropositionalEquality as P using (refl)
import TypeEquivEquiv as T
using ([id,id]≋id; ⊎●≋●⊎; _⊎≋_; sym≃-distrib⊎;
unite₊-nat; assocl₊-nat;
[g+1]●[1+f]≋[1+f]●[g+1]; unite₊′-nat)
------------------------------------------------------------------------------
-- equivalences for the ⊎ structure
id0≃ : Fin 0 ≃ Fin 0
id0≃ = id≃ {A = Fin 0}
[id+id]≋id : ∀ {p : ℕ × ℕ} →
let m = proj₁ p in let n = proj₂ p in
id≃ {A = Fin m} +F id≃ {A = Fin n} ≋ id≃
[id+id]≋id {(m , n)} =
let em = id≃ {A = Fin m} in
let en = id≃ {A = Fin n} in
let em⊎en = id≃ {A = Fin m ⊎ Fin n} in
let em+n = id≃ {A = Fin (m + n)} in
let f≋ = id≋ {x = ⊎≃+ {m} {n}} in
let g≋ = id≋ {x = +≃⊎ {m} {n}} in
begin (
em +F en
≋⟨ id≋ ⟩
⊎≃+ ● (em ⊎≃ en) ● +≃⊎
≋⟨ f≋ ◎ (T.[id,id]≋id ◎ g≋) ⟩
⊎≃+ ● id≃ {A = Fin m ⊎ Fin n} ● +≃⊎
≋⟨ f≋ ◎ lid≋ {f = +≃⊎} ⟩
⊎≃+ {m} ● +≃⊎
≋⟨ rinv≋ (⊎≃+ {m}) ⟩
em+n ∎)
where open ≋-Reasoning
intro-inv-r+ : {m n : ℕ} {B : Set} (f : (Fin m ⊎ Fin n) ≃ B) → f ≋ (f ● +≃⊎) ● ⊎≃+
intro-inv-r+ f =
begin (
f
≋⟨ sym≋ rid≋ ⟩
f ● id≃
≋⟨ id≋ {x = f} ◎ sym≋ (linv≋ ⊎≃+) ⟩
f ● (+≃⊎ ● ⊎≃+)
≋⟨ ●-assocl {f = ⊎≃+} {+≃⊎} {f} ⟩
(f ● +≃⊎) ● ⊎≃+ ∎)
where open ≋-Reasoning
+●≋●+ : {A B C D E F : ℕ} →
{f : A fin≃ C} {g : B fin≃ D} {h : C fin≃ E} {i : D fin≃ F} →
(h ● f) +F (i ● g) ≋ (h +F i) ● (f +F g)
+●≋●+ {f = f} {g} {h} {i} =
let f≋ = id≋ {x = ⊎≃+} in
let g≋ = id≋ {x = +≃⊎} in
let id≋fg = id≋ {x = f ⊎≃ g} in
begin (
(h ● f) +F (i ● g)
≋⟨ id≋ ⟩
⊎≃+ ● ((h ● f) ⊎≃ (i ● g)) ● +≃⊎
≋⟨ f≋ ◎ (T.⊎●≋●⊎ ◎ g≋) ⟩ -- the real work, rest is shuffling
⊎≃+ ● ((h ⊎≃ i) ● (f ⊎≃ g)) ● +≃⊎
≋⟨ ●-assocl ⟩
(⊎≃+ ● ((h ⊎≃ i) ● (f ⊎≃ g))) ● +≃⊎
≋⟨ ●-assocl ◎ g≋ ⟩
((⊎≃+ ● h ⊎≃ i) ● f ⊎≃ g) ● +≃⊎
≋⟨ ((f≋ ◎ intro-inv-r+ (h ⊎≃ i)) ◎ id≋fg) ◎ g≋ ⟩
((⊎≃+ ● (h ⊎≃ i ● +≃⊎) ● ⊎≃+) ● f ⊎≃ g) ● +≃⊎
≋⟨ (●-assocl ◎ id≋fg) ◎ g≋ ⟩
(((⊎≃+ ● (h ⊎≃ i ● +≃⊎)) ● ⊎≃+) ● f ⊎≃ g) ● +≃⊎
≋⟨ id≋ ⟩ -- the left part is done, show it
((h +F i ● ⊎≃+) ● f ⊎≃ g) ● +≃⊎
≋⟨ ●-assoc {f = f ⊎≃ g} {⊎≃+} {h +F i} ◎ g≋ ⟩
(h +F i ● (⊎≃+ ● f ⊎≃ g)) ● +≃⊎
≋⟨ ●-assoc {f = +≃⊎} {⊎≃+ ● f ⊎≃ g} {h +F i}⟩
(h +F i) ● ((⊎≃+ ● f ⊎≃ g) ● +≃⊎)
≋⟨ id≋ {x = h +F i} ◎ ●-assoc {f = +≃⊎} {f ⊎≃ g} {⊎≃+}⟩
(h +F i) ● (f +F g) ∎)
where open ≋-Reasoning
_+≋_ : {A B C D : ℕ} {f₁ g₁ : A fin≃ B} {f₂ g₂ : C fin≃ D} →
(f₁ ≋ g₁) → (f₂ ≋ g₂) → (f₁ +F f₂ ≋ g₁ +F g₂)
_+≋_ {A} {B} {C} {D} {f₁} {g₁} {f₂} {g₂} f₁≋g₁ f₂≋g₂ =
let f≋ = id≋ {x = ⊎≃+} in
let g≋ = id≋ {x = +≃⊎} in
begin (
f₁ +F f₂
≋⟨ id≋ ⟩
⊎≃+ ● (f₁ ⊎≃ f₂) ● +≃⊎
≋⟨ f≋ ◎ (T._⊎≋_ f₁≋g₁ f₂≋g₂ ◎ g≋) ⟩
⊎≃+ ● (g₁ ⊎≃ g₂) ● +≃⊎
≋⟨ id≋ ⟩
g₁ +F g₂ ∎)
where open ≋-Reasoning
unite₊-nat : {m n : ℕ} {f : m fin≃ n} →
unite+ ● (id0≃ +F f) ≋ f ● unite+
unite₊-nat {m} {n} {f} =
begin (
unite+ ● (id0≃ +F f)
≋⟨ id≋ ⟩
(unite₊equiv ● (F0≃⊥ ⊎≃ id≃) ● +≃⊎) ● ⊎≃+ ● ((id≃ ⊎≃ f) ● +≃⊎)
≋⟨ ●-assocl {f = (id≃ ⊎≃ f) ● +≃⊎} {⊎≃+} {unite₊equiv ● (F0≃⊥ ⊎≃ id≃) ● +≃⊎} ⟩
((unite₊equiv ● ((F0≃⊥ ⊎≃ id≃) ● +≃⊎)) ● ⊎≃+) ● ((id≃ ⊎≃ f) ● +≃⊎)
≋⟨ (●-assocl ◎ id≋) ◎ id≋ ⟩
(((unite₊equiv ● (F0≃⊥ ⊎≃ id≃)) ● +≃⊎) ● ⊎≃+) ● (id≃ ⊎≃ f) ● +≃⊎
≋⟨ sym≋ (intro-inv-r+ (unite₊equiv ● (F0≃⊥ ⊎≃ id≃))) ◎ id≋ ⟩
(unite₊equiv ● (F0≃⊥ ⊎≃ id≃)) ● (id≃ ⊎≃ f) ● +≃⊎
≋⟨ ●-assocl ⟩
((unite₊equiv ● (F0≃⊥ ⊎≃ id≃)) ● (id≃ ⊎≃ f)) ● +≃⊎
≋⟨ ●-assoc ◎ id≋ ⟩
(unite₊equiv ● (F0≃⊥ ⊎≃ id≃) ● (id≃ ⊎≃ f)) ● +≃⊎
≋⟨ (id≋ ◎ (T.[g+1]●[1+f]≋[1+f]●[g+1] {f = f} {F0≃⊥})) ◎ id≋ ⟩
(unite₊equiv ● ((id≃ ⊎≃ f) ● (F0≃⊥ ⊎≃ id≃))) ● +≃⊎
≋⟨ ●-assocl ◎ id≋ ⟩
((unite₊equiv ● (id≃ ⊎≃ f)) ● (F0≃⊥ ⊎≃ id≃)) ● +≃⊎
≋⟨ ●-assoc ⟩
(unite₊equiv ● (id≃ ⊎≃ f)) ● (F0≃⊥ ⊎≃ id≃) ● +≃⊎
≋⟨ T.unite₊-nat ◎ id≋ ⟩
(f ● unite₊equiv) ● (F0≃⊥ ⊎≃ id≃) ● +≃⊎
≋⟨ ●-assoc ⟩
f ● unite₊equiv ● (F0≃⊥ ⊎≃ id≃) ● +≃⊎
≋⟨ id≋ ⟩
f ● unite+ ∎)
where open ≋-Reasoning
-- sym≃ distributes over +F
sym+F : ∀ {A B C D} {f : A fin≃ B} {g : C fin≃ D} →
sym≃ (f +F g) ≋ sym≃ f +F sym≃ g
sym+F {f = f} {g = g} =
begin (
sym≃ (f +F g)
≋⟨ id≋ ⟩
sym≃ (⊎≃+ ● (f ⊎≃ g ● +≃⊎))
≋⟨ sym≃● ⟩
sym≃ (f ⊎≃ g ● +≃⊎) ● sym≃ ⊎≃+
≋⟨ sym≃● ◎ id≋ ⟩
(sym≃ +≃⊎ ● sym≃ (f ⊎≃ g)) ● sym≃ ⊎≃+
≋⟨ (id≋ ◎ T.sym≃-distrib⊎) ◎ id≋ ⟩
(sym≃ +≃⊎ ● (sym≃ f ⊎≃ sym≃ g)) ● sym≃ ⊎≃+
≋⟨ ●-assoc ⟩
sym≃ +≃⊎ ● ((sym≃ f ⊎≃ sym≃ g) ● sym≃ ⊎≃+)
≋⟨ id≋ ⟩
sym≃ f +F sym≃ g ∎)
where open ≋-Reasoning
uniti₊-nat : ∀ {A B} {f : A fin≃ B} →
uniti+ ● f ≋ (id0≃ +F f) ● uniti+
uniti₊-nat {f = f} =
begin (
uniti+ ● f
≋⟨ id≋ ⟩
sym≃ unite+ ● sym≃ (sym≃ f)
≋⟨ sym≋ sym≃● ⟩
sym≃ (sym≃ f ● unite+)
≋⟨ flip-sym≋ unite₊-nat ⟩
sym≃ (unite+ ● (id0≃ +F sym≃ f))
≋⟨ sym≃● ⟩
sym≃ (id0≃ +F sym≃ f) ● uniti+
≋⟨ sym+F ◎ id≋ {x = uniti+} ⟩
(id0≃ +F sym≃ (sym≃ f)) ● uniti+
≋⟨ id≋ ⟩
(id0≃ +F f) ● uniti+ ∎)
where open ≋-Reasoning
unite₊r-nat : {m n : ℕ} {f : m fin≃ n} →
unite+r ● (f +F id0≃) ≋ f ● unite+r
unite₊r-nat {m} {n} {f} =
let 1+⊥ = id≃ ⊎≃ F0≃⊥ in
let f+1 = f ⊎≃ id≃ in
let g≋ = id≋ {x = +≃⊎} in
let rhs≋ = id≋ {x = f+1 ● +≃⊎} in
begin (
unite+r ● (f +F id0≃)
≋⟨ id≋ ⟩
(unite₊′equiv ● 1+⊥ ● +≃⊎) ● ⊎≃+ ● (f+1 ● +≃⊎)
≋⟨ ●-assocl ⟩
((unite₊′equiv ● 1+⊥ ● +≃⊎) ● ⊎≃+) ● (f+1 ● +≃⊎)
≋⟨ (●-assocl ◎ id≋) ◎ id≋ ⟩
(((unite₊′equiv ● 1+⊥) ● +≃⊎) ● ⊎≃+) ● (f+1 ● +≃⊎)
≋⟨ sym≋ (intro-inv-r+ (unite₊′equiv ● 1+⊥)) ◎ rhs≋ ⟩
(unite₊′equiv ● 1+⊥) ● (f+1 ● +≃⊎)
≋⟨ trans≋ ●-assocl (●-assoc ◎ id≋) ⟩
(unite₊′equiv ● (1+⊥ ● f+1)) ● +≃⊎
≋⟨ (id≋ {x = unite₊′equiv} ◎ sym≋ (T.[g+1]●[1+f]≋[1+f]●[g+1] {f = F0≃⊥} {f})) ◎ g≋ ⟩
(unite₊′equiv ● (f ⊎≃ id≃) ● (id≃ ⊎≃ F0≃⊥)) ● +≃⊎ -- the id≃ are at different types!
≋⟨ ●-assocl ◎ id≋ ⟩
((unite₊′equiv ● (f ⊎≃ id≃)) ● (id≃ ⊎≃ F0≃⊥)) ● +≃⊎
≋⟨ ●-assoc ⟩
(unite₊′equiv ● (f ⊎≃ id≃)) ● (id≃ ⊎≃ F0≃⊥) ● +≃⊎
≋⟨ T.unite₊′-nat ◎ id≋ {x = (id≃ ⊎≃ F0≃⊥) ● +≃⊎} ⟩
(f ● unite₊′equiv) ● (id≃ ⊎≃ F0≃⊥) ● +≃⊎
≋⟨ ●-assoc ⟩ -- assoc + defn
f ● unite+r ∎)
where open ≋-Reasoning
uniti₊r-nat : {m n : ℕ} {f : m fin≃ n} →
uniti+r ● f ≋ (f +F id0≃) ● uniti+r
uniti₊r-nat {f = f} =
begin (
uniti+r ● f
≋⟨ id≋ ⟩
sym≃ unite+r ● sym≃ (sym≃ f)
≋⟨ sym≋ sym≃● ⟩
sym≃ (sym≃ f ● unite+r)
≋⟨ flip-sym≋ unite₊r-nat ⟩
sym≃ (unite+r ● (sym≃ f +F id0≃))
≋⟨ sym≃● ⟩
sym≃ (sym≃ f +F id0≃) ● uniti+r
≋⟨ sym+F ◎ id≋ {x = uniti+r} ⟩
(sym≃ (sym≃ f) +F id0≃) ● uniti+r
≋⟨ id≋ ⟩
(f +F id0≃) ● uniti+r ∎)
where open ≋-Reasoning
-- assocl+ is the one which is defined directly (?)
assocl₊-nat : {m n o m' n' o' : ℕ}
{f : m fin≃ m'} {g : n fin≃ n'} {h : o fin≃ o'} →
assocl+ {m'} {n'} {o'} ● (f +F (g +F h)) ≋
((f +F g) +F h) ● assocl+ {m} {n} {o}
-- expand the definitions right away, the pattern is clear
assocl₊-nat {m} {n} {o} {m'} {n'} {o'} {f} {g} {h} =
let αmno' = assocl₊equiv {Fin m'} {Fin n'} {Fin o'} in
let αmno = assocl₊equiv {Fin m} {Fin n} {Fin o} in
begin (
(⊎≃+ ● ⊎≃+ ⊎≃ id≃ ● αmno' ● id≃ ⊎≃ +≃⊎ ● +≃⊎) ●
⊎≃+ ● ((f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎)) ● +≃⊎)
≋⟨ ●-assocl ⟩
((⊎≃+ ● ⊎≃+ ⊎≃ id≃ ● assocl₊equiv ● id≃ ⊎≃ +≃⊎ ● +≃⊎) ● ⊎≃+) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ ((id≋ ◎ (id≋ ◎ ●-assocl)) ◎ id≋) ◎ id≋ ⟩
((⊎≃+ ● ⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎) ● +≃⊎) ● ⊎≃+) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ ((id≋ ◎ ●-assocl) ◎ id≋) ◎ id≋ ⟩
((⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎)) ● +≃⊎) ● ⊎≃+) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ (●-assocl ◎ id≋) ◎ id≋ ⟩
(((⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎))) ● +≃⊎) ● ⊎≃+) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ sym≋ (intro-inv-r+ (⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎)))) ◎ id≋ ⟩
(⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎))) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ ●-assoc ⟩
⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎)) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ id≋ ◎ (●-assocl ◎ id≋) ⟩
⊎≃+ ● ((⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● id≃ ⊎≃ +≃⊎) ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎)
≋⟨ id≋ ◎ ●-assoc ⟩
⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● (id≃ ⊎≃ +≃⊎ ●
(f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎) ● +≃⊎))
≋⟨ id≋ ◎ (id≋ ◎ ●-assocl) ⟩
⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● ((id≃ ⊎≃ +≃⊎ ●
f ⊎≃ (⊎≃+ ● g ⊎≃ h ● +≃⊎)) ● +≃⊎)
≋⟨ id≋ ◎ (id≋ ◎ (sym≋ T.⊎●≋●⊎ ◎ id≋)) ⟩
⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● ((id≃ ● f) ⊎≃ (+≃⊎ ● (⊎≃+ ● g ⊎≃ h ● +≃⊎))) ● +≃⊎
≋⟨ id≋ ◎ (id≋ ◎ (T._⊎≋_
(trans≋ lid≋ (sym≋ rid≋))
(trans≋ ●-assocl (trans≋ (linv≋ ⊎≃+ ◎ id≋) lid≋)) ◎ id≋)) ⟩
⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● ((f ● id≃) ⊎≃ (g ⊎≃ h ● +≃⊎)) ● +≃⊎
≋⟨ id≋ ◎ (id≋ ◎ (T.⊎●≋●⊎ ◎ id≋)) ⟩
⊎≃+ ● (⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● (f ⊎≃ (g ⊎≃ h) ● id≃ ⊎≃ +≃⊎) ● +≃⊎
≋⟨ id≋ ◎ ●-assocl ⟩
⊎≃+ ● ((⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● (f ⊎≃ (g ⊎≃ h) ● id≃ ⊎≃ +≃⊎)) ● +≃⊎
≋⟨ id≋ ◎ (●-assocl ◎ id≋) ⟩
⊎≃+ ● (((⊎≃+ ⊎≃ id≃ ● assocl₊equiv) ● f ⊎≃ (g ⊎≃ h)) ● id≃ ⊎≃ +≃⊎) ● +≃⊎
≋⟨ id≋ ◎ ((●-assoc ◎ id≋) ◎ id≋) ⟩
⊎≃+ ● ((⊎≃+ ⊎≃ id≃ ● (assocl₊equiv ● f ⊎≃ (g ⊎≃ h))) ● id≃ ⊎≃ +≃⊎) ● +≃⊎
≋⟨ id≋ ◎ ( ((id≋ ◎ T.assocl₊-nat) ◎ id≋) ◎ id≋) ⟩
⊎≃+ ● ((⊎≃+ ⊎≃ id≃ ● ((f ⊎≃ g) ⊎≃ h) ● assocl₊equiv) ● id≃ ⊎≃ +≃⊎) ● +≃⊎
≋⟨ id≋ ◎ ((●-assocl ◎ id≋) ◎ id≋) ⟩
⊎≃+ ● (((⊎≃+ ⊎≃ id≃ ● (f ⊎≃ g) ⊎≃ h) ● assocl₊equiv) ● id≃ ⊎≃ +≃⊎) ● +≃⊎
≋⟨ id≋ ◎ (((T+1-nat ◎ id≋) ◎ id≋) ◎ id≋) ⟩
⊎≃+ ● ((((⊎≃+ ● f ⊎≃ g ● +≃⊎) ● ⊎≃+) ⊎≃ (h ● id≃) ● assocl₊equiv) ● id≃ ⊎≃ +≃⊎) ● +≃⊎
≋⟨ id≋ ◎ ●-assoc ⟩
⊎≃+ ● (((⊎≃+ ● f ⊎≃ g ● +≃⊎) ● ⊎≃+) ⊎≃ (h ● id≃) ● assocl₊equiv) ● (id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ id≋ ◎ ●-assoc ⟩
⊎≃+ ● ((⊎≃+ ● f ⊎≃ g ● +≃⊎) ● ⊎≃+) ⊎≃ (h ● id≃) ● (assocl₊equiv ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ ●-assocl ⟩
(⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ● ⊎≃+) ⊎≃ (h ● id≃)) ● (αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ (id≋ ◎ T.⊎●≋●⊎ ) ◎ id≋ ⟩
(⊎≃+ ● (((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h) ● (⊎≃+ ⊎≃ id≃))) ●
(αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ ●-assocl ◎ id≋ ⟩
((⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h)) ● (⊎≃+ ⊎≃ id≃)) ●
(αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ ●-assoc ⟩
(⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h)) ●
(⊎≃+ ⊎≃ id≃ ● αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ id≋ ◎ sym≋ lid≋ ⟩
(⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h)) ●
id≃ ● (⊎≃+ ⊎≃ id≃ ● αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ id≋ ◎ (sym≋ (rinv≋ +≃⊎) ◎ id≋) ⟩
(⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h)) ●
(+≃⊎ ● ⊎≃+) ● (⊎≃+ ⊎≃ id≃ ● αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ id≋ ◎ ●-assoc ⟩
((⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h))) ●
(+≃⊎ ● ⊎≃+ ● ⊎≃+ ⊎≃ id≃ ● αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ ●-assocl ⟩
((⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h)) ● +≃⊎) ●
(⊎≃+ ● ⊎≃+ ⊎≃ id≃ ● αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎)
≋⟨ ●-assoc ◎ id≋ ⟩
(⊎≃+ ● ((⊎≃+ ● (f ⊎≃ g) ● +≃⊎) ⊎≃ h) ● +≃⊎) ●
(⊎≃+ ● ⊎≃+ ⊎≃ id≃ ● αmno ● id≃ ⊎≃ +≃⊎ ● +≃⊎) ∎)
where
open ≋-Reasoning
T+1-nat : ⊎≃+ ⊎≃ id≃ ● (f ⊎≃ g) ⊎≃ h ≋ ((⊎≃+ ● f ⊎≃ g ● +≃⊎) ● ⊎≃+) ⊎≃ (h ● id≃)
T+1-nat = begin (
⊎≃+ ⊎≃ id≃ ● (f ⊎≃ g) ⊎≃ h
≋⟨ sym≋ (T.⊎●≋●⊎) ⟩
(⊎≃+ ● f ⊎≃ g) ⊎≃ (id≃ ● h)
≋⟨ id≋ T.⊎≋ (trans≋ lid≋ (sym≋ rid≋))⟩
(⊎≃+ ● f ⊎≃ g) ⊎≃ (h ● id≃)
≋⟨ trans≋ (intro-inv-r+ ((⊎≃+ ● f ⊎≃ g))) ●-assoc T.⊎≋ id≋ ⟩
((⊎≃+ ● f ⊎≃ g) ● +≃⊎ ● ⊎≃+) ⊎≃ (h ● id≃)
≋⟨ trans≋ ●-assocl (●-assoc ◎ id≋) T.⊎≋ id≋ ⟩
((⊎≃+ ● f ⊎≃ g ● +≃⊎) ● ⊎≃+) ⊎≃ (h ● id≃) ∎)
assocr₊-nat : {m n o m' n' o' : ℕ}
{f : m fin≃ m'} {g : n fin≃ n'} {h : o fin≃ o'} →
assocr+ {m'} {n'} {o'} ● ((f +F g) +F h) ≋
(f +F (g +F h)) ● assocr+ {m} {n} {o}
assocr₊-nat {m} {n} {o} {m'} {n'} {o'} {f} {g} {h} = begin (
assocr+ {m'} {n'} {o'} ● ((f +F g) +F h)
≋⟨ id≋ ⟩
sym≃ assocl+ ● sym≃ (sym≃ ((f +F g) +F h))
≋⟨ sym≋ (sym≃● {f = assocl+}) ⟩
sym≃ (sym≃ ((f +F g) +F h) ● assocl+ {m'} {n'} {o'})
≋⟨ flip≋ ((trans≋ sym+F (sym+F +≋ id≋ )) ◎ id≋) ⟩
sym≃ (((sym≃ f +F sym≃ g) +F sym≃ h) ● assocl+ {m'})
≋⟨ flip-sym≋ assocl₊-nat ⟩
sym≃ (assocl+ {m} {n} {o} ● (sym≃ f +F (sym≃ g +F sym≃ h)))
≋⟨ flip≋ (id≋ ◎ (trans≋ (id≋ +≋ (sym≋ sym+F)) (sym≋ sym+F))) ⟩
sym≃ ( assocl+ ● sym≃ (f +F (g +F h)))
≋⟨ sym≃● ⟩
sym≃ (sym≃ (f +F (g +F h))) ● sym≃ (assocl+ {m} {n} {o})
≋⟨ id≋ ⟩
(f +F (g +F h)) ● (assocr+ {m} {n} {o}) ∎)
where open ≋-Reasoning
unite-assocr₊-coh : {m n : ℕ} →
unite+r {m = m} +F id≃ {A = Fin n} ≋
(id≃ {A = Fin m} +F unite+ {m = n}) ● assocr+ {m} {0} {n}
unite-assocr₊-coh {m} {n} = begin (
⊎≃+ ● (unite₊′equiv {Fin m} ● id≃ ⊎≃ F0≃⊥ ● +≃⊎) ⊎≃ id≃ {A = Fin n} ● +≃⊎
≋⟨ {!!} ⟩
(⊎≃+ ● (id≃ ⊎≃ (unite₊equiv ● F0≃⊥ ⊎≃ id≃ ● +≃⊎)) ● +≃⊎) ● sym≃ (assocl+ {m} {0} {n}) ∎)
where open ≋-Reasoning
assocr₊-coh : {m n o p : ℕ} →
assocr+ {m} {n} {o + p} ● assocr+ {m + n} {o} {p} ≋
(id≃ {A = Fin m} +F assocr+ {n} {o} {p}) ●
assocr+ {m} {n + o} {p} ● (assocr+ {m} {n} {o} +F id≃ {A = Fin p})
assocr₊-coh = {!!}
where open ≋-Reasoning
swap₊-nat : {m n o p : ℕ} {f : m fin≃ o} {g : n fin≃ p} →
swap+ {o} {p} ● (f +F g) ≋ (g +F f) ● swap+ {m} {n}
swap₊-nat = {!!}
sswap₊-nat : {m n o p : ℕ} {f : m fin≃ o} {g : n fin≃ p} →
sswap+ {o} {p} ● (g +F f) ≋ (f +F g) ● sswap+ {m} {n}
sswap₊-nat = {!!}
assocr₊-swap₊-coh : {m n o : ℕ} →
assocr+ {n} {o} {m} ● swap+ {m} {n + o} ● assocr+ {m} {n} {o} ≋
(id≃ {A = Fin n} +F swap+ {m} {o}) ●
assocr+ {n} {m} {o} ● (swap+ {m} {n} +F id≃ {A = Fin o})
assocr₊-swap₊-coh = {!!}
where open ≋-Reasoning
assocl₊-swap₊-coh : {m n o : ℕ} →
assocl+ {o} {m} {n} ● swap+ {m + n} {o} ● assocl+ {m} {n} {o} ≋
(swap+ {m} {o} +F id≃ {A = Fin n}) ●
assocl+ {m} {o} {n} ● (id≃ {A = Fin m} +F swap+ {n} {o})
assocl₊-swap₊-coh = {!!}
where open ≋-Reasoning
------------------------------------------------------------------------------
| 37.068627
| 91
| 0.336221
|
3d973672ec56bc440de938931cabdeb3f6fc40db
| 925
|
agda
|
Agda
|
test/Succeed/Issue3246.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/Issue3246.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue3246.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Andreas, 2018-10-29, issue #3246
-- More things are now allowed in mutual blocks.
-- @mutual@ just pushes the definition parts to the bottom.
-- Definitions exist for data, record, functions, and pattern synonyms.
postulate Float : Set
{-# BUILTIN FLOAT Float #-} -- not (yet) allowed in mutual block
mutual
import Agda.Builtin.Bool
open Agda.Builtin.Bool
f : Bool
f = g -- pushed to bottom
-- module M where -- not (yet) allowed in mutual block
module B = Agda.Builtin.Bool
primitive
primFloatEquality : Float → Float → Bool
{-# INJECTIVE primFloatEquality #-} -- certainly a lie
open import Agda.Builtin.Equality
{-# DISPLAY primFloatEquality x y = x ≡ y #-}
postulate A : Set
{-# COMPILE GHC A = type Integer #-}
variable x : Bool
g : Bool
g = true -- pushed to bottom
{-# STATIC g #-}
record R : Set where
coinductive
field foo : R
{-# ETA R #-}
| 19.680851
| 71
| 0.651892
|
129fd3a22319f3e3e604e025cca3d44f611582f1
| 5,261
|
agda
|
Agda
|
src/Web/Semantic/DL/Category/Properties/Tensor/Functor.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | 1
|
2022-02-22T09:43:23.000Z
|
2022-02-22T09:43:23.000Z
|
src/Web/Semantic/DL/Category/Properties/Tensor/Functor.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | null | null | null |
src/Web/Semantic/DL/Category/Properties/Tensor/Functor.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | null | null | null |
open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind ; _*_ )
open import Web.Semantic.DL.ABox.Model using
( _⊨a_ ; ⊨a-resp-≡³ ; on-bnode ; bnodes ; _,_ )
open import Web.Semantic.DL.Category.Object using ( Object ; IN )
open import Web.Semantic.DL.Category.Morphism using
( _⇒_ ; BN ; impl ; _⊑_ ; _≣_ ; _,_ )
open import Web.Semantic.DL.Category.Composition using ( _∙_ )
open import Web.Semantic.DL.Category.Tensor using ( _⊗_ ; _⟨⊗⟩_ )
open import Web.Semantic.DL.Category.Wiring using ( identity ; id✓ )
open import Web.Semantic.DL.Category.Properties.Composition.Lemmas using
( compose-left ; compose-right ; compose-resp-⊨a )
open import Web.Semantic.DL.Category.Properties.Tensor.Lemmas using
( tensor-up ; tensor-down ; tensor-resp-⊨a )
open import Web.Semantic.DL.Category.Properties.Tensor.RespectsWiring using
( tensor-resp-wiring )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.DL.TBox.Interp using ( Δ )
open import Web.Semantic.Util using
( id ; _∘_ ; _⊕_⊕_ ; inode ; bnode ; enode ; left ; right ; up ; down )
module Web.Semantic.DL.Category.Properties.Tensor.Functor
{Σ : Signature} {S T : TBox Σ} where
tensor-resp-id : ∀ (A₁ A₂ : Object S T) →
((identity A₁ ⟨⊗⟩ identity A₂) ≣ identity (A₁ ⊗ A₂))
tensor-resp-id A₁ A₂ =
tensor-resp-wiring A₁ A₂ A₁ A₂
id (id✓ A₁) id (id✓ A₂) id (id✓ (A₁ ⊗ A₂))
(λ x → refl) (λ x → refl)
tensor-resp-compose : ∀ {A₁ A₂ B₁ B₂ C₁ C₂ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (G₁ : B₁ ⇒ C₁) (G₂ : B₂ ⇒ C₂) →
(((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)) ≣ ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)))
tensor-resp-compose {A₁} {A₂} {B₁} {B₂} {C₁} {C₂} F₁ F₂ G₁ G₂ =
(LHS⊑RHS , RHS⊑LHS) where
LHS⊑RHS : (F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂) ⊑ (F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)
LHS⊑RHS I I⊨STA₁A₂ I⊨LHS = (f , I⊨RHS) where
f : ((BN F₁ ⊎ BN F₂) ⊕ (IN B₁ ⊎ IN B₂) ⊕ (BN G₁ ⊎ BN G₂)) → Δ ⌊ I ⌋
f (inode (inj₁ v)) = ind I (bnode (inj₁ (inode v)))
f (inode (inj₂ v)) = ind I (bnode (inj₂ (inode v)))
f (bnode (inj₁ y)) = ind I (bnode (inj₁ (bnode y)))
f (bnode (inj₂ y)) = ind I (bnode (inj₂ (bnode y)))
f (enode (inj₁ w)) = ind I (bnode (inj₁ (enode w)))
f (enode (inj₂ w)) = ind I (bnode (inj₂ (enode w)))
Iˡ₁⊨F₁ : up * left * bnodes I f ⊨a impl F₁
Iˡ₁⊨F₁ = ⊨a-resp-≡³
(left * up * I) (on-bnode {Σ} f (ind I) ∘ left ∘ up) refl (impl F₁)
(compose-left F₁ G₁ (up * I) (tensor-up (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))
Iˡ₂⊨F₂ : down * (left * bnodes I f) ⊨a impl F₂
Iˡ₂⊨F₂ = ⊨a-resp-≡³
(left * down * I) (on-bnode {Σ} f (ind I) ∘ left ∘ down) refl (impl F₂)
(compose-left F₂ G₂ (down * I) (tensor-down (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))
Iʳ₁⊨G₁ : up * (right * bnodes I f) ⊨a impl G₁
Iʳ₁⊨G₁ = ⊨a-resp-≡³
(right * up * I) (on-bnode {Σ} f (ind I) ∘ right ∘ up) refl (impl G₁)
(compose-right F₁ G₁ (up * I) (tensor-up (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))
Iʳ₂⊨G₂ : down * (right * bnodes I f) ⊨a impl G₂
Iʳ₂⊨G₂ = ⊨a-resp-≡³
(right * down * I) (on-bnode {Σ} f (ind I) ∘ right ∘ down) refl (impl G₂)
(compose-right F₂ G₂ (down * I) (tensor-down (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))
I⊨RHS : bnodes I f ⊨a impl ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂))
I⊨RHS = compose-resp-⊨a (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) (bnodes I f)
(tensor-resp-⊨a F₁ F₂ (left * bnodes I f) Iˡ₁⊨F₁ Iˡ₂⊨F₂)
(tensor-resp-⊨a G₁ G₂ (right * bnodes I f) Iʳ₁⊨G₁ Iʳ₂⊨G₂)
RHS⊑LHS : (F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂) ⊑ (F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)
RHS⊑LHS I I⊨STA₁A₂ I⊨RHS = (f , I⊨LHS) where
f : ((BN F₁ ⊕ IN B₁ ⊕ BN G₁) ⊎ (BN F₂ ⊕ IN B₂ ⊕ BN G₂)) → Δ ⌊ I ⌋
f (inj₁ (inode v)) = ind I (bnode (inode (inj₁ v)))
f (inj₁ (bnode y)) = ind I (bnode (bnode (inj₁ y)))
f (inj₁ (enode w)) = ind I (bnode (enode (inj₁ w)))
f (inj₂ (inode v)) = ind I (bnode (inode (inj₂ v)))
f (inj₂ (bnode y)) = ind I (bnode (bnode (inj₂ y)))
f (inj₂ (enode w)) = ind I (bnode (enode (inj₂ w)))
I₁ˡ⊨F₁ : left * up * bnodes I f ⊨a impl F₁
I₁ˡ⊨F₁ = ⊨a-resp-≡³
(up * left * I) (on-bnode {Σ} f (ind I) ∘ up ∘ left) refl (impl F₁)
(tensor-up F₁ F₂ (left * I) (compose-left (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))
I₁ʳ⊨G₁ : right * up * bnodes I f ⊨a impl G₁
I₁ʳ⊨G₁ = ⊨a-resp-≡³
(up * right * I) (on-bnode {Σ} f (ind I) ∘ up ∘ right) refl (impl G₁)
(tensor-up G₁ G₂ (right * I) (compose-right (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))
I₂ˡ⊨F₂ : left * down * bnodes I f ⊨a impl F₂
I₂ˡ⊨F₂ = ⊨a-resp-≡³
(down * left * I) (on-bnode {Σ} f (ind I) ∘ down ∘ left) refl (impl F₂)
(tensor-down F₁ F₂ (left * I) (compose-left (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))
I₂ʳ⊨G₂ : right * down * bnodes I f ⊨a impl G₂
I₂ʳ⊨G₂ = ⊨a-resp-≡³
(down * right * I) (on-bnode {Σ} f (ind I) ∘ down ∘ right) refl (impl G₂)
(tensor-down G₁ G₂ (right * I) (compose-right (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))
I⊨LHS : bnodes I f ⊨a impl ((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂))
I⊨LHS = tensor-resp-⊨a (F₁ ∙ G₁) (F₂ ∙ G₂) (bnodes I f)
(compose-resp-⊨a F₁ G₁ (up * bnodes I f) I₁ˡ⊨F₁ I₁ʳ⊨G₁)
(compose-resp-⊨a F₂ G₂ (down * bnodes I f) I₂ˡ⊨F₂ I₂ʳ⊨G₂)
| 47.396396
| 85
| 0.563771
|
c53c8be096e05f59282e50d8819a71e0f1604c07
| 3,278
|
agda
|
Agda
|
Modules/Span.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Modules/Span.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Modules/Span.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Functions.Definition
open import Groups.Definition
open import Groups.Abelian.Definition
open import Setoids.Setoids
open import Rings.Definition
open import Sets.FinSet.Definition
open import Vectors
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Sets.EquivalenceRelations
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Modules.Definition
module Modules.Span {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+R_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+R_ _*_} {m n : _} {M : Set m} {T : Setoid {m} {n} M} {_+_ : M → M → M} {G' : Group T _+_} {G : AbelianGroup G'} {_·_ : A → M → M} (mod : Module R G _·_) where
open Group G'
open Setoid T
open Equivalence eq
_=V_ : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) {n1 : ℕ} → Rel {a} {b ⊔ n} (Vec A n1)
_=V_ G [] [] = True'
_=V_ {S = S} G (x ,- xs) (y ,- ys) = (Setoid._∼_ S x y) && (_=V_ G xs ys)
dot : {n : ℕ} → (Vec M n) → (Vec A n) → M
dot [] [] = 0G
dot (v ,- vs) (x ,- xs) = (x · v) + (dot vs xs)
Spans : {c : _} {C : Set c} (f : C → M) → Set (a ⊔ m ⊔ n ⊔ c)
Spans {C = C} f = (m : M) → Sg ℕ (λ n → Sg ((Vec C n) && (Vec A n)) (λ t → (dot (vecMap f (_&&_.fst t)) (_&&_.snd t)) ∼ m))
Independent : {c : _} {C : Set c} (f : C → M) → Set (a ⊔ b ⊔ n ⊔ c)
Independent {C = C} f = {n : ℕ} → (r : Vec C n) → ({a b : ℕ} → (a<n : a <N n) → (b<n : b <N n) → vecIndex r a a<n ≡ vecIndex r b b<n → a ≡ b) → (b : Vec A n) → (dot (vecMap f r) b) ∼ 0G → _=V_ (Ring.additiveGroup R) (vecPure (Group.0G (Ring.additiveGroup R))) b
independentSubset : {c : _} {C : Set c} (f : C → M) → {d : _} {D : Set d} {inj : D → C} (isInj : Injection inj) → Independent f → Independent (f ∘ inj)
independentSubset f {inj = inj} isInj indp {n = n} r coeffInj coeffs dotZero = indp {n = n} (vecMap inj r) inj' coeffs (transitive (identityOfIndiscernablesRight _∼_ reflexive (applyEquality (λ i → dot i coeffs) (vecMapCompose inj f r))) dotZero)
where
inj' : {a b : ℕ} (a<n : a <N n) (b<n : b <N n) → vecIndex (vecMap inj r) a a<n ≡ vecIndex (vecMap inj r) b b<n → a ≡ b
inj' a<n b<n x rewrite vecMapAndIndex r inj a<n | vecMapAndIndex r inj b<n = coeffInj a<n b<n (isInj x)
spanSuperset : {c : _} {C : Set c} (f : C → M) → {d : _} {D : Set d} {surj : D → C} (isSurj : Surjection surj) → Spans f → Spans (f ∘ surj)
spanSuperset f {surj = surj} isSurj spans m with spans m
spanSuperset {C = C} f {surj = surj} isSurj spans m | n , ((coeffs ,, basis) , b) = n , ((vecMap (λ c → underlying (isSurj c)) coeffs ,, basis) , transitive (identityOfIndiscernablesLeft _∼_ reflexive (applyEquality (λ i → dot i basis) (equalityCommutative {x = vecMap (λ i → f (surj i)) (vecMap (λ c → underlying (isSurj c)) coeffs)} {vecMap f coeffs} (transitivity (vecMapCompose (λ i → underlying (isSurj i)) (λ z → f (surj z)) coeffs) (t coeffs))))) b)
where
t : {n : ℕ} (coeffs : Vec C n) → vecMap (λ i → f (surj (underlying (isSurj i)))) coeffs ≡ vecMap f coeffs
t [] = refl
t (x ,- coeffs) with isSurj x
... | img , pr rewrite pr | t coeffs = refl
Basis : {c : _} {C : Set c} (f : C → M) → Set (a ⊔ b ⊔ m ⊔ n ⊔ c)
Basis v = Spans v && Independent v
| 59.6
| 456
| 0.585723
|
3d36074668ea511cf749b4d817cb21d9cd0a8b19
| 9,654
|
agda
|
Agda
|
deBruijn/Substitution/Data/Application/Application222.agda
|
nad/dependently-typed-syntax
|
498f8aefc570f7815fd1d6616508eeb92c52abce
|
[
"MIT"
] | 5
|
2020-04-16T12:14:44.000Z
|
2020-07-08T22:51:36.000Z
|
deBruijn/Substitution/Data/Application/Application222.agda
|
nad/dependently-typed-syntax
|
498f8aefc570f7815fd1d6616508eeb92c52abce
|
[
"MIT"
] | null | null | null |
deBruijn/Substitution/Data/Application/Application222.agda
|
nad/dependently-typed-syntax
|
498f8aefc570f7815fd1d6616508eeb92c52abce
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Lemmas related to application of substitutions
------------------------------------------------------------------------
open import Data.Universe.Indexed
module deBruijn.Substitution.Data.Application.Application222
{i u e} {Uni : IndexedUniverse i u e}
where
import deBruijn.Context; open deBruijn.Context Uni
open import deBruijn.Substitution.Data.Application.Application221
open import deBruijn.Substitution.Data.Basics
open import deBruijn.Substitution.Data.Map
open import deBruijn.Substitution.Data.Simple
open import Function using (_$_)
open import Level using (_⊔_)
import Relation.Binary.PropositionalEquality as P
open P.≡-Reasoning
-- Lemmas related to application.
record Application₂₂₂
{t₁} {T₁ : Term-like t₁}
{t₂} {T₂ : Term-like t₂}
-- Simple substitutions for the first kind of terms.
(simple₁ : Simple T₁)
-- Simple substitutions for the second kind of terms.
(simple₂ : Simple T₂)
-- A translation from the first to the second kind of terms.
(trans : [ T₁ ⟶⁼ T₂ ])
: Set (i ⊔ u ⊔ e ⊔ t₁ ⊔ t₂) where
open Term-like T₁ using () renaming (_⊢_ to _⊢₁_)
open Term-like T₂ using ([_]) renaming (_⊢_ to _⊢₂_; _≅-⊢_ to _≅-⊢₂_)
open Simple simple₁
using ()
renaming ( id to id₁; sub to sub₁; var to var₁
; wk to wk₁; wk[_] to wk₁[_]
; _↑ to _↑₁; _↑_ to _↑₁_; _↑⁺_ to _↑⁺₁_; _↑₊_ to _↑₊₁_
; _↑⋆ to _↑⋆₁; _↑⁺⋆_ to _↑⁺⋆₁_
)
open Simple simple₂
using ()
renaming ( var to var₂
; weaken to weaken₂; weaken[_] to weaken₂[_]; wk⁺ to wk⁺₂
; wk-subst to wk-subst₂; wk-subst[_] to wk-subst₂[_]
; _↑ to _↑₂; _↑_ to _↑₂_; _↑⁺_ to _↑⁺₂_; _↑₊_ to _↑₊₂_
)
field
application₂₂₁ : Application₂₂₁ simple₁ simple₂ trans
open Application₂₂₁ application₂₂₁ public
abstract
-- A variant of suc-/∋-↑.
suc-/⊢⋆-↑⋆ :
∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ}
σ {τ} (x : Γ ∋ τ) (ρs : Subs T₁ ρ̂) →
var₂ · suc[ σ ] x /⊢⋆ ρs ↑⋆₁ ≅-⊢₂
var₂ · x /⊢⋆ (ρs ▻ wk₁[ σ /⋆ ρs ])
suc-/⊢⋆-↑⋆ σ x ε = begin
[ var₂ · suc x ] ≡⟨ P.sym $ var-/⊢-wk-↑⁺ ε x ⟩
[ var₂ · x /⊢ wk₁ ] ∎
suc-/⊢⋆-↑⋆ σ x (ρs ▻ ρ) = begin
[ var₂ · suc[ σ ] x /⊢⋆ ρs ↑⋆₁ /⊢ ρ ↑₁ ] ≡⟨ /⊢-cong (suc-/⊢⋆-↑⋆ σ x ρs) (P.refl {x = [ ρ ↑₁ ]}) ⟩
[ var₂ · x /⊢⋆ ρs /⊢ wk₁[ σ /⋆ ρs ] /⊢ ρ ↑₁ ] ≡⟨ P.sym $ /⊢-/⊢-wk (σ /⋆ ρs) (var₂ · x /⊢⋆ ρs) ρ ⟩
[ var₂ · x /⊢⋆ ρs /⊢ ρ /⊢ wk₁ ] ∎
-- The antecedent of var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆ follows from a less
-- complicated statement.
var-/⊢⋆-⇒-var-/⊢⋆-↑⁺⋆ :
∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} {ρs₁ : Subs T₁ ρ̂} {ρs₂ : Subs T₁ ρ̂} →
(∀ {σ} (x : Γ ∋ σ) → var₂ · x /⊢⋆ ρs₁ ≅-⊢₂ var₂ · x /⊢⋆ ρs₂) →
∀ Γ⁺ {σ} (x : Γ ++⁺ Γ⁺ ∋ σ) →
var₂ · x /⊢⋆ ρs₁ ↑⁺⋆₁ Γ⁺ ≅-⊢₂ var₂ · x /⊢⋆ ρs₂ ↑⁺⋆₁ Γ⁺
var-/⊢⋆-⇒-var-/⊢⋆-↑⁺⋆ hyp ε x = hyp x
var-/⊢⋆-⇒-var-/⊢⋆-↑⁺⋆ {ρs₁ = ρs₁} {ρs₂} hyp (Γ⁺ ▻ σ) zero = begin
[ var₂ · zero /⊢⋆ ρs₁ ↑⁺⋆₁ (Γ⁺ ▻ σ) ] ≡⟨ zero-/⊢⋆-↑⋆ σ (ρs₁ ↑⁺⋆₁ Γ⁺) ⟩
[ var₂ · zero ] ≡⟨ P.sym $ zero-/⊢⋆-↑⋆ σ (ρs₂ ↑⁺⋆₁ Γ⁺) ⟩
[ var₂ · zero /⊢⋆ ρs₂ ↑⁺⋆₁ (Γ⁺ ▻ σ) ] ∎
var-/⊢⋆-⇒-var-/⊢⋆-↑⁺⋆ {ρs₁ = ρs₁} {ρs₂} hyp (Γ⁺ ▻ σ) (suc x) = begin
[ var₂ · suc x /⊢⋆ ρs₁ ↑⁺⋆₁ (Γ⁺ ▻ σ) ] ≡⟨ suc-/⊢⋆-↑⋆ σ x (ρs₁ ↑⁺⋆₁ Γ⁺) ⟩
[ var₂ · x /⊢⋆ ρs₁ ↑⁺⋆₁ Γ⁺ /⊢ wk₁ ] ≡⟨ /⊢-cong (var-/⊢⋆-⇒-var-/⊢⋆-↑⁺⋆ hyp Γ⁺ x) (P.refl {x = [ wk₁ ]}) ⟩
[ var₂ · x /⊢⋆ ρs₂ ↑⁺⋆₁ Γ⁺ /⊢ wk₁ ] ≡⟨ P.sym $ suc-/⊢⋆-↑⋆ σ x (ρs₂ ↑⁺⋆₁ Γ⁺) ⟩
[ var₂ · suc x /⊢⋆ ρs₂ ↑⁺⋆₁ (Γ⁺ ▻ σ) ] ∎
-- Variants of var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆ which may be easier to use.
var-/⊢⋆-⇒-/⊢⋆-↑⁺⋆ :
∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρs₁ : Subs T₁ ρ̂) (ρs₂ : Subs T₁ ρ̂) →
(∀ {σ} (x : Γ ∋ σ) → var₂ · x /⊢⋆ ρs₁ ≅-⊢₂ var₂ · x /⊢⋆ ρs₂) →
∀ Γ⁺ {σ} (t : Γ ++⁺ Γ⁺ ⊢₂ σ) →
t /⊢⋆ ρs₁ ↑⁺⋆₁ Γ⁺ ≅-⊢₂ t /⊢⋆ ρs₂ ↑⁺⋆₁ Γ⁺
var-/⊢⋆-⇒-/⊢⋆-↑⁺⋆ ρs₁ ρs₂ hyp =
var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆ ρs₁ ρs₂ (var-/⊢⋆-⇒-var-/⊢⋆-↑⁺⋆ hyp)
var-/⊢⋆-⇒-/⊢⋆ :
∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρs₁ : Subs T₁ ρ̂) (ρs₂ : Subs T₁ ρ̂) →
(∀ {σ} (x : Γ ∋ σ) → var₂ · x /⊢⋆ ρs₁ ≅-⊢₂ var₂ · x /⊢⋆ ρs₂) →
∀ {σ} (t : Γ ⊢₂ σ) → t /⊢⋆ ρs₁ ≅-⊢₂ t /⊢⋆ ρs₂
var-/⊢⋆-⇒-/⊢⋆ ρs₁ ρs₂ hyp = var-/⊢⋆-⇒-/⊢⋆-↑⁺⋆ ρs₁ ρs₂ hyp ε
-- The identity substitution has no effect.
/⊢-id : ∀ {Γ σ} (t : Γ ⊢₂ σ) → t /⊢ id₁ ≅-⊢₂ t
/⊢-id = var-/⊢⋆-⇒-/⊢⋆ (ε ▻ id₁) ε var-/⊢-id
-- id is a right identity of _∘_.
∘-id : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T₂ ρ̂) → ρ ∘ id₁ ≅-⇨ ρ
∘-id ρ = extensionality P.refl λ x → begin
[ x /∋ ρ ∘ id₁ ] ≡⟨ /∋-∘ x ρ id₁ ⟩
[ x /∋ ρ /⊢ id₁ ] ≡⟨ /⊢-id (x /∋ ρ) ⟩
[ x /∋ ρ ] ∎
-- Lifting distributes over composition.
∘-↑ : ∀ {Γ Δ Ε} σ {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε}
(ρ₁ : Sub T₂ ρ̂₁) (ρ₂ : Sub T₁ ρ̂₂) →
(ρ₁ ∘ ρ₂) ↑₂ σ ≅-⇨ ρ₁ ↑₂ σ ∘ ρ₂ ↑₁
∘-↑ σ ρ₁ ρ₂ =
let ρ₂↑ = ρ₂ ↑₁ (σ / ρ₁)
lemma₁ = begin
[ wk-subst₂ (ρ₁ ∘ ρ₂) ] ≡⟨ P.refl ⟩
[ map weaken₂ (map (app ρ₂) ρ₁) ] ≡⟨ P.sym $ map-[∘] weaken₂ (app ρ₂) ρ₁ ⟩
[ map (weaken₂ [∘] app ρ₂) ρ₁ ] ≡⟨ map-cong-ext₁ P.refl
(λ t → begin
[ weaken₂ · (t /⊢ ρ₂) ] ≡⟨ P.sym $ /⊢-wk (t /⊢ ρ₂) ⟩
[ t /⊢ ρ₂ /⊢ wk₁ ] ≡⟨ /⊢-/⊢-wk (σ / ρ₁) t ρ₂ ⟩
[ t /⊢ wk₁ /⊢ ρ₂↑ ] ≡⟨ /⊢-cong (/⊢-wk t) P.refl ⟩
[ weaken₂ · t /⊢ ρ₂↑ ] ∎)
(P.refl {x = [ ρ₁ ]}) ⟩
[ map (app ρ₂↑ [∘] weaken₂) ρ₁ ] ≡⟨ map-[∘] (app ρ₂↑) weaken₂ ρ₁ ⟩
[ map (app ρ₂↑) (map (weaken₂) ρ₁) ] ∎
lemma₂ = begin
[ var₂ · zero ] ≡⟨ P.sym $ trans-var zero ⟩
[ trans · (var₁ · zero) ] ≡⟨ trans-cong (P.sym $ Simple.zero-/∋-↑ simple₁ (σ / ρ₁) ρ₂) ⟩
[ trans · (zero /∋ ρ₂↑) ] ≡⟨ P.sym $ var-/⊢ zero ρ₂↑ ⟩
[ var₂ · zero /⊢ ρ₂↑ ] ∎
in begin
[ (ρ₁ ∘ ρ₂) ↑₂ ] ≡⟨ Simple.unfold-↑ simple₂ (ρ₁ ∘ ρ₂) ⟩
[ wk-subst₂ (ρ₁ ∘ ρ₂) ▻ var₂ · zero ] ≡⟨ ▻⇨-cong P.refl lemma₁ lemma₂ ⟩
[ map (app ρ₂↑) (map weaken₂[ σ / ρ₁ ] ρ₁) ▻ var₂ · zero /⊢ ρ₂↑ ] ≡⟨ P.sym $
map-▻ (app ρ₂↑) (wk-subst₂[ σ / ρ₁ ] ρ₁) (var₂ · zero) ⟩
[ map (app ρ₂↑) (wk-subst₂[ σ / ρ₁ ] ρ₁ ▻ var₂ · zero) ] ≡⟨ map-cong (app ρ₂↑ ∎-⟶)
(P.sym $ Simple.unfold-↑ simple₂ ρ₁) ⟩
[ map (app ρ₂↑) (ρ₁ ↑₂) ] ≡⟨ P.refl ⟩
[ ρ₁ ↑₂ ∘ ρ₂ ↑₁ ] ∎
-- N-ary lifting distributes over composition.
∘-↑⁺ : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε}
(ρ₁ : Sub T₂ ρ̂₁) (ρ₂ : Sub T₁ ρ̂₂) Γ⁺ →
(ρ₁ ∘ ρ₂) ↑⁺₂ Γ⁺ ≅-⇨ ρ₁ ↑⁺₂ Γ⁺ ∘ ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁)
∘-↑⁺ ρ₁ ρ₂ ε = P.refl
∘-↑⁺ ρ₁ ρ₂ (Γ⁺ ▻ σ) = begin
[ ((ρ₁ ∘ ρ₂) ↑⁺₂ Γ⁺) ↑₂ ] ≡⟨ Simple.↑-cong simple₂ (∘-↑⁺ ρ₁ ρ₂ Γ⁺) P.refl ⟩
[ (ρ₁ ↑⁺₂ Γ⁺ ∘ ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁)) ↑₂ ] ≡⟨ ∘-↑ σ (ρ₁ ↑⁺₂ Γ⁺) (ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁)) ⟩
[ (ρ₁ ↑⁺₂ Γ⁺) ↑₂ ∘ (ρ₂ ↑⁺₁ (Γ⁺ /⁺ ρ₁)) ↑₁ ] ∎
∘-↑₊ : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε}
(ρ₁ : Sub T₂ ρ̂₁) (ρ₂ : Sub T₁ ρ̂₂) Γ₊ →
(ρ₁ ∘ ρ₂) ↑₊₂ Γ₊ ≅-⇨ ρ₁ ↑₊₂ Γ₊ ∘ ρ₂ ↑₊₁ (Γ₊ /₊ ρ₁)
∘-↑₊ ρ₁ ρ₂ ε = P.refl
∘-↑₊ ρ₁ ρ₂ (σ ◅ Γ₊) = begin
[ (ρ₁ ∘ ρ₂ ) ↑₂ σ ↑₊₂ Γ₊ ] ≡⟨ Simple.↑₊-cong simple₂ (∘-↑ σ ρ₁ ρ₂) (P.refl {x = [ Γ₊ ]}) ⟩
[ (ρ₁ ↑₂ σ ∘ ρ₂ ↑₁) ↑₊₂ Γ₊ ] ≡⟨ ∘-↑₊ (ρ₁ ↑₂ σ) (ρ₂ ↑₁) Γ₊ ⟩
[ ρ₁ ↑₊₂ (σ ◅ Γ₊) ∘ ρ₂ ↑₊₁ ((σ ◅ Γ₊) /₊ ρ₁) ] ∎
-- First weakening and then substituting something for the first
-- variable is equivalent to doing nothing.
/⊢-wk-/⊢-sub : ∀ {Γ σ τ} (t : Γ ⊢₂ τ) (t′ : Γ ⊢₁ σ) →
t /⊢ wk₁ /⊢ sub₁ t′ ≅-⊢₂ t
/⊢-wk-/⊢-sub t t′ = var-/⊢⋆-⇒-/⊢⋆ (ε ▻ wk₁ ▻ sub₁ t′) ε (λ x → begin
[ var₂ · x /⊢ wk₁ /⊢ sub₁ t′ ] ≡⟨ /⊢-cong (/∋-≅-⊢-var x wk₁ (Simple./∋-wk simple₁ x)) P.refl ⟩
[ var₂ · suc x /⊢ sub₁ t′ ] ≡⟨ suc-/⊢-sub x t′ ⟩
[ var₂ · x ] ∎) t
-- Weakening a substitution and composing with sub is the same as
-- doing nothing.
wk-subst-∘-sub : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T₂ ρ̂) (t : Δ ⊢₁ σ) →
wk-subst₂ ρ ∘ sub₁ t ≅-⇨ ρ
wk-subst-∘-sub ρ t = extensionality P.refl λ x →
let lemma = begin
[ x /∋ wk-subst₂ ρ ] ≡⟨ Simple./∋-wk-subst simple₂ x ρ ⟩
[ weaken₂ · (x /∋ ρ) ] ≡⟨ P.sym $ /⊢-wk (x /∋ ρ) ⟩
[ x /∋ ρ /⊢ wk₁ ] ∎
in begin
[ x /∋ wk-subst₂ ρ ∘ sub₁ t ] ≡⟨ /∋-∘ x (wk-subst₂ ρ) (sub₁ t) ⟩
[ x /∋ wk-subst₂ ρ /⊢ sub₁ t ] ≡⟨ /⊢-cong lemma P.refl ⟩
[ x /∋ ρ /⊢ wk₁ /⊢ sub₁ t ] ≡⟨ /⊢-wk-/⊢-sub (x /∋ ρ) t ⟩
[ x /∋ ρ ] ∎
-- Unfolding lemma for wk⁺.
wk⁺-▻ : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) {σ} →
wk⁺₂ (Γ⁺ ▻ σ) ≅-⇨ wk⁺₂ Γ⁺ ∘ wk₁[ σ ]
wk⁺-▻ Γ⁺ {σ = σ} = begin
[ wk⁺₂ (Γ⁺ ▻ σ) ] ≡⟨ P.refl ⟩
[ wk-subst₂ (wk⁺₂ Γ⁺) ] ≡⟨ P.sym $ ∘-wk (wk⁺₂ Γ⁺) ⟩
[ wk⁺₂ Γ⁺ ∘ wk₁ ] ∎
| 44.694444
| 134
| 0.379221
|
58fc21c4f41df5b2bef89880df5afd911e13c680
| 3,654
|
agda
|
Agda
|
Cubical/Data/Nat/Coprime.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Data/Nat/Coprime.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Coprime.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Data.Nat.Coprime where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Data.Sigma
open import Cubical.Data.NatPlusOne
open import Cubical.HITs.PropositionalTruncation as PropTrunc
open import Cubical.Data.Nat.Base
open import Cubical.Data.Nat.Properties
open import Cubical.Data.Nat.Divisibility
open import Cubical.Data.Nat.GCD
areCoprime : ℕ × ℕ → Type₀
areCoprime (m , n) = isGCD m n 1
-- Any pair (m , n) can be converted to a coprime pair (m' , n') s.t.
-- m' ∣ m, n' ∣ n if and only if one of m or n is nonzero
module ToCoprime ((m , n) : ℕ × ℕ₊₁) where
d = gcd m (ℕ₊₁→ℕ n)
d∣m = gcdIsGCD m (ℕ₊₁→ℕ n) .fst .fst
d∣n = gcdIsGCD m (ℕ₊₁→ℕ n) .fst .snd
gr = gcdIsGCD m (ℕ₊₁→ℕ n) .snd
c₁ : ℕ
p₁ : c₁ · d ≡ m
c₁ = ∣-untrunc d∣m .fst; p₁ = ∣-untrunc d∣m .snd
c₂ : ℕ₊₁
p₂ : (ℕ₊₁→ℕ c₂) · d ≡ (ℕ₊₁→ℕ n)
c₂ = 1+ (∣s-untrunc d∣n .fst); p₂ = ∣s-untrunc d∣n .snd
toCoprime : ℕ × ℕ₊₁
toCoprime = (c₁ , c₂)
private
lem : ∀ a {b c d e} → a · b ≡ c → c · d ≡ e → a · (b · d) ≡ e
lem a p q = ·-assoc a _ _ ∙ cong (_· _) p ∙ q
gr' : ∀ d' → prediv d' c₁ → prediv d' (ℕ₊₁→ℕ c₂) → (d' · d) ∣ d
gr' d' (b₁ , q₁) (b₂ , q₂) = gr (d' · d) ((∣ b₁ , lem b₁ q₁ p₁ ∣₁) ,
(∣ b₂ , lem b₂ q₂ p₂ ∣₁))
d-1 = m∣sn→z<m d∣n .fst
q : d ≡ suc d-1
q = sym (+-comm 1 d-1 ∙ m∣sn→z<m d∣n .snd)
private
-- this only works because d > 0 (<=> m > 0 or n > 0)
d-cancelʳ : ∀ d' → (d' · d) ∣ d → d' ∣ 1
d-cancelʳ d' div = ∣-cancelʳ d-1 (∣-trans (subst (λ x → (d' · x) ∣ x) q div)
(∣-refl (sym (·-identityˡ _))))
toCoprimeAreCoprime : areCoprime (c₁ , ℕ₊₁→ℕ c₂)
fst toCoprimeAreCoprime = ∣-oneˡ c₁ , ∣-oneˡ (ℕ₊₁→ℕ c₂)
snd toCoprimeAreCoprime d' (d'∣c₁ , d'∣c₂) = PropTrunc.rec isProp∣ (λ a →
PropTrunc.rec isProp∣ (λ b →
d-cancelʳ d' (gr' d' a b)) d'∣c₂) d'∣c₁
toCoprime∣ : (c₁ ∣ m) × (ℕ₊₁→ℕ c₂ ∣ ℕ₊₁→ℕ n)
toCoprime∣ = ∣ d , ·-comm d c₁ ∙ p₁ ∣₁ , ∣ d , ·-comm d (ℕ₊₁→ℕ c₂) ∙ p₂ ∣₁
toCoprime-idem : areCoprime (m , ℕ₊₁→ℕ n) → (c₁ , c₂) ≡ (m , n)
toCoprime-idem cp i = q₁ i , ℕ₊₁→ℕ-inj q₂ i
where q₁ = sym (·-identityʳ c₁) ∙ cong (c₁ ·_) (sym (isGCD→gcd≡ cp)) ∙ p₁
q₂ = sym (·-identityʳ (ℕ₊₁→ℕ c₂)) ∙ cong (ℕ₊₁→ℕ c₂ ·_) (sym (isGCD→gcd≡ cp)) ∙ p₂
open ToCoprime using (toCoprime; toCoprimeAreCoprime; toCoprime∣; toCoprime-idem) public
toCoprime-cancelʳ : ∀ ((m , n) : ℕ × ℕ₊₁) k
→ toCoprime (m · ℕ₊₁→ℕ k , n ·₊₁ k) ≡ toCoprime (m , n)
toCoprime-cancelʳ (m , n) (1+ k) i =
inj-·sm {c₁'} {d-1} {c₁} r₁ i , ℕ₊₁→ℕ-inj (inj-·sm {ℕ₊₁→ℕ c₂'} {d-1} {ℕ₊₁→ℕ c₂} r₂) i
where open ToCoprime (m , n)
open ToCoprime (m · suc k , n ·₊₁ (1+ k)) using ()
renaming (c₁ to c₁'; p₁ to p₁'; c₂ to c₂'; p₂ to p₂')
q₁ : c₁' · d · suc k ≡ m · suc k
q₁ = sym (·-assoc c₁' (ToCoprime.d (m , n)) (suc k))
∙ cong (c₁' ·_) (sym (gcd-factorʳ m (ℕ₊₁→ℕ n) (suc k)))
∙ p₁'
q₂ : ℕ₊₁→ℕ c₂' · (ToCoprime.d (m , n)) · suc k ≡ ℕ₊₁→ℕ n · suc k
q₂ = sym (·-assoc (ℕ₊₁→ℕ c₂') (ToCoprime.d (m , n)) (suc k))
∙ cong (ℕ₊₁→ℕ c₂' ·_) (sym (gcd-factorʳ m (ℕ₊₁→ℕ n) (suc k)))
∙ p₂'
r₁ : c₁' · suc d-1 ≡ c₁ · suc d-1
r₁ = subst (λ z → c₁' · z ≡ c₁ · z) q (inj-·sm q₁ ∙ sym p₁)
r₂ : ℕ₊₁→ℕ c₂' · suc d-1 ≡ ℕ₊₁→ℕ c₂ · suc d-1
r₂ = subst (λ z → ℕ₊₁→ℕ c₂' · z ≡ ℕ₊₁→ℕ c₂ · z) q (inj-·sm q₂ ∙ sym p₂)
| 38.0625
| 91
| 0.498905
|
12c5b3f15bad75952cfb0e7867a97db3a19529de
| 169
|
agda
|
Agda
|
test/Fail/NoEtaEquality.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/NoEtaEquality.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/NoEtaEquality.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-09-20 test whether --no-eta-equality is respected
{-# OPTIONS --no-eta-equality #-}
record ⊤ : Set where
test : ⊤
test = _ -- should remain unsolved
| 18.777778
| 66
| 0.668639
|
317bbc577520ce07cadcc8a87f31f3d3c60bad68
| 350
|
agda
|
Agda
|
test/Succeed/Issue3697.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3697.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3697.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --type-in-type #-}
open import Agda.Primitive using (Setω)
-- No panic should be triggered
data A : Setω where
record B' : Set where
field
theA : A
data B : Set where
b : A → B
data C : Set where
c : Setω → C
data C' : Setω where
c : Setω → C'
record C'' : Setω where
field
theSet : Setω
thefield : theSet
| 12.5
| 39
| 0.605714
|
220b2e3869d85755fe46c0399cbd2199a7d22fa8
| 418
|
agda
|
Agda
|
test/Compiler/with-stdlib/TrustMe.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Compiler/with-stdlib/TrustMe.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Compiler/with-stdlib/TrustMe.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module TrustMe where
open import Data.String
open import Data.String.Unsafe
open import Data.Unit using (⊤)
open import IO
import IO.Primitive as Prim
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
-- Check that trustMe works.
testTrustMe : IO ⊤
testTrustMe with "apa" ≟ "apa"
... | yes refl = putStrLn "Yes!"
... | no _ = putStrLn "No."
main : Prim.IO ⊤
main = run testTrustMe
| 20.9
| 49
| 0.732057
|
4a875685502e4716b0193b168c59dc818b14bfa7
| 5,455
|
agda
|
Agda
|
TotalRecognisers/LeftRecursion/Lib.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
TotalRecognisers/LeftRecursion/Lib.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
TotalRecognisers/LeftRecursion/Lib.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A tiny library of derived combinators
------------------------------------------------------------------------
module TotalRecognisers.LeftRecursion.Lib (Tok : Set) where
open import Coinduction
open import Data.Bool hiding (_∧_)
open import Data.Bool.Properties
open import Function hiding (_∋_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (module Equivalence)
open import Data.List
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product as Prod
open import Relation.Binary
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary.Decidable
import TotalRecognisers.LeftRecursion
open TotalRecognisers.LeftRecursion Tok
------------------------------------------------------------------------
-- Kleene star
-- The intended semantics of the Kleene star.
infixr 5 _∷_
infix 4 _∈[_]⋆
data _∈[_]⋆ {n} : List Tok → P n → Set where
[] : ∀ {p} → [] ∈[ p ]⋆
_∷_ : ∀ {s₁ s₂ p} → s₁ ∈ p → s₂ ∈[ p ]⋆ → s₁ ++ s₂ ∈[ p ]⋆
module KleeneStar₁ where
infix 15 _⋆ _+
-- This definition requires that the argument recognisers are not
-- nullable.
mutual
_⋆ : P false → P true
p ⋆ = empty ∣ p +
_+ : P false → P false
p + = p · ♯ (p ⋆)
-- The definition of _⋆ above is correct.
⋆-sound : ∀ {s p} → s ∈ p ⋆ → s ∈[ p ]⋆
⋆-sound (∣-left empty) = []
⋆-sound (∣-right (pr₁ · pr₂)) = pr₁ ∷ ⋆-sound pr₂
⋆-complete : ∀ {s p} → s ∈[ p ]⋆ → s ∈ p ⋆
⋆-complete [] = ∣-left empty
⋆-complete (_∷_ {[]} pr₁ pr₂) = ⋆-complete pr₂
⋆-complete (_∷_ {_ ∷ _} pr₁ pr₂) =
∣-right {n₁ = true} (pr₁ · ⋆-complete pr₂)
module KleeneStar₂ where
infix 15 _⋆
-- This definition works for any argument recogniser.
_⋆ : ∀ {n} → P n → P true
_⋆ = KleeneStar₁._⋆ ∘ nonempty
-- The definition of _⋆ above is correct.
⋆-sound : ∀ {s n} {p : P n} → s ∈ p ⋆ → s ∈[ p ]⋆
⋆-sound (∣-left empty) = []
⋆-sound (∣-right (nonempty pr₁ · pr₂)) = pr₁ ∷ ⋆-sound pr₂
⋆-complete : ∀ {s n} {p : P n} → s ∈[ p ]⋆ → s ∈ p ⋆
⋆-complete [] = ∣-left empty
⋆-complete (_∷_ {[]} pr₁ pr₂) = ⋆-complete pr₂
⋆-complete (_∷_ {_ ∷ _} pr₁ pr₂) =
∣-right {n₁ = true} (nonempty pr₁ · ⋆-complete pr₂)
-- Note, however, that for actual parsing the corresponding
-- definition would not be correct. The reason is that p would give
-- a result also when the empty string was accepted, and these
-- results are ignored by the definition above. In the case of
-- actual parsing the result of p ⋆, when p is nullable, should be a
-- stream and not a finite list.
------------------------------------------------------------------------
-- A simplified sequencing operator
infixl 10 _⊙_
_⊙_ : ∀ {n₁ n₂} → P n₁ → P n₂ → P (n₁ ∧ n₂)
_⊙_ {n₁ = n₁} p₁ p₂ = ♯? p₁ · ♯? {b = n₁} p₂
module ⊙ where
complete : ∀ {n₁ n₂ s₁ s₂} {p₁ : P n₁} {p₂ : P n₂} →
s₁ ∈ p₁ → s₂ ∈ p₂ → s₁ ++ s₂ ∈ p₁ ⊙ p₂
complete {n₁} {n₂} s₁∈p₁ s₂∈p₂ = add-♭♯ n₂ s₁∈p₁ · add-♭♯ n₁ s₂∈p₂
infixl 10 _⊙′_
infix 4 _⊙_∋_
data _⊙_∋_ {n₁ n₂} (p₁ : P n₁) (p₂ : P n₂) : List Tok → Set where
_⊙′_ : ∀ {s₁ s₂} (s₁∈p₁ : s₁ ∈ p₁) (s₂∈p₂ : s₂ ∈ p₂) →
p₁ ⊙ p₂ ∋ s₁ ++ s₂
sound : ∀ {n₁} n₂ {s} {p₁ : P n₁} {p₂ : P n₂} →
s ∈ p₁ ⊙ p₂ → p₁ ⊙ p₂ ∋ s
sound {n₁} n₂ (s₁∈p₁ · s₂∈p₂) = drop-♭♯ n₂ s₁∈p₁ ⊙′ drop-♭♯ n₁ s₂∈p₂
------------------------------------------------------------------------
-- A combinator which repeats a recogniser a fixed number of times
⟨_^_⟩-nullable : Bool → ℕ → Bool
⟨ n ^ zero ⟩-nullable = true
⟨ n ^ suc i ⟩-nullable = n ∧ ⟨ n ^ i ⟩-nullable
infixl 15 _^_
_^_ : ∀ {n} → P n → (i : ℕ) → P ⟨ n ^ i ⟩-nullable
p ^ 0 = empty
p ^ suc i = p ⊙ p ^ i
-- Some lemmas relating _^_ to _⋆.
open KleeneStar₂
^≤⋆ : ∀ {n} {p : P n} i → p ^ i ≤ p ⋆
^≤⋆ {n} {p} i s∈ = ⋆-complete $ helper i s∈
where
helper : ∀ i {s} → s ∈ p ^ i → s ∈[ p ]⋆
helper zero empty = []
helper (suc i) (s₁∈p · s₂∈pⁱ) =
drop-♭♯ ⟨ n ^ i ⟩-nullable s₁∈p ∷ helper i (drop-♭♯ n s₂∈pⁱ)
⋆≤^ : ∀ {n} {p : P n} {s} → s ∈ p ⋆ → ∃ λ i → s ∈ p ^ i
⋆≤^ {n} {p} s∈p⋆ = helper (⋆-sound s∈p⋆)
where
helper : ∀ {s} → s ∈[ p ]⋆ → ∃ λ i → s ∈ p ^ i
helper [] = (0 , empty)
helper (s₁∈p ∷ s₂∈p⋆) =
Prod.map suc (λ {i} s₂∈pⁱ → add-♭♯ ⟨ n ^ i ⟩-nullable s₁∈p ·
add-♭♯ n s₂∈pⁱ)
(helper s₂∈p⋆)
------------------------------------------------------------------------
-- A recogniser which only accepts a given token
module Tok (dec : Decidable (_≡_ {A = Tok})) where
tok : Tok → P false
tok t = sat (⌊_⌋ ∘ dec t)
sound : ∀ {s t} → s ∈ tok t → s ≡ [ t ]
sound (sat ok) = cong [_] $ sym $ toWitness ok
complete : ∀ {t} → [ t ] ∈ tok t
complete = sat (fromWitness refl)
------------------------------------------------------------------------
-- A recogniser which accepts the empty string iff the argument is
-- true (and never accepts non-empty strings)
accept-if-true : ∀ b → P b
accept-if-true true = empty
accept-if-true false = fail
module AcceptIfTrue where
sound : ∀ b {s} → s ∈ accept-if-true b → s ≡ [] × T b
sound true empty = (refl , _)
sound false ()
complete : ∀ {b} → T b → [] ∈ accept-if-true b
complete ok with Equivalence.to T-≡ ⟨$⟩ ok
... | refl = empty
| 30.138122
| 72
| 0.498992
|
2227f88da652d1b1ea394a735e2328267da7c53a
| 4,073
|
agda
|
Agda
|
formalization/agda/Spire/Hybrid.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 43
|
2015-05-28T23:25:33.000Z
|
2022-03-08T17:10:59.000Z
|
formalization/agda/Spire/Hybrid.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | null | null | null |
formalization/agda/Spire/Hybrid.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 1
|
2015-08-17T21:00:07.000Z
|
2015-08-17T21:00:07.000Z
|
open import Spire.Type
module Spire.Hybrid where
----------------------------------------------------------------------
data Context : Set₁
Environment : Context → Set
ScopedType : Context → Set₁
ScopedType Γ = Environment Γ → Set
data Context where
∅ : Context
_,_ : (Γ : Context) (A : ScopedType Γ) → Context
Environment ∅ = ⊤
Environment (Γ , A) = Σ (Environment Γ) A
data Var : (Γ : Context) (A : ScopedType Γ) → Set₁ where
here : ∀{Γ A} → Var (Γ , A) (λ vs → A (proj₁ vs))
there : ∀{Γ A} {B : ScopedType Γ}
→ Var Γ A → Var (Γ , B) (λ vs → A (proj₁ vs))
lookup : ∀{Γ A} → Var Γ A → (vs : Environment Γ) → A vs
lookup here (vs , v) = v
lookup (there i) (vs , v) = lookup i vs
ScopedType₂ : (Γ : Context) → ScopedType Γ → Set₁
ScopedType₂ Γ A = (vs : Environment Γ) → A vs → Set
----------------------------------------------------------------------
data Term (Γ : Context) : ScopedType Γ → Set₁
eval : ∀{Γ A} → Term Γ A → (vs : Environment Γ) → A vs
-- ----------------------------------------------------------------------
data Term Γ where
{- Type introduction -}
`⊥ `⊤ `Bool `ℕ `Type : ∀{ℓ}
→ Term Γ (const (Type ℓ))
`Π `Σ : ∀{ℓ}
(A : Term Γ (const (Type ℓ)))
(B : Term (Γ , λ vs → ⟦ ℓ ∣ eval A vs ⟧) (const (Type ℓ)))
→ Term Γ (λ _ → Type ℓ)
`⟦_⟧ : ∀{ℓ}
(A : Term Γ (const (Type ℓ)))
→ Term Γ (const (Type (suc ℓ)))
{- Value introduction -}
`tt : Term Γ (const ⊤)
`true `false : Term Γ (const Bool)
`zero : Term Γ (const ℕ)
`suc : Term Γ (const ℕ) → Term Γ (const ℕ)
`λ : ∀{A} {B : ScopedType₂ Γ A}
(f : Term (Γ , A) (λ vs → B (proj₁ vs) (proj₂ vs)))
→ Term Γ (λ vs → (v : A vs) → (B vs v))
_`,_ : ∀{A} {B : ScopedType₂ Γ A}
(a : Term Γ A)
(b : Term Γ (λ vs → B vs (eval a vs)))
→ Term Γ (λ vs → Σ (A vs) (λ v → B vs v))
{- Value elimination -}
`var : ∀{A} (a : Var Γ A) → Term Γ A
`elim⊥ : ∀{A ℓ}
(P : Term Γ (const (Type ℓ)))
(x : Term Γ (const ⊥))
→ Term Γ A
`elimBool : ∀{ℓ}
(P : Term (Γ , const Bool) (const (Type ℓ)))
(pt : Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , true) ⟧))
(pf : Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , false) ⟧))
(b : Term Γ (const Bool))
→ Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , eval b vs) ⟧)
`elimℕ : ∀{ℓ}
(P : Term (Γ , (const ℕ)) (const (Type ℓ)))
(pz : Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , zero) ⟧))
(ps : Term ((Γ , const ℕ) , (λ { (vs , n) → ⟦ ℓ ∣ eval P (vs , n) ⟧ }))
(λ { ((vs , n) , p) → ⟦ ℓ ∣ eval P (vs , suc n) ⟧ }))
(n : Term Γ (const ℕ))
→ Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , eval n vs) ⟧)
_`$_ : ∀{A} {B : ScopedType₂ Γ A}
(f : Term Γ (λ vs → (v : A vs) → (B vs v)))
(a : Term Γ A)
→ Term Γ (λ vs → B vs (eval a vs))
`proj₁ : ∀{A} {B : ScopedType₂ Γ A}
(ab : Term Γ (λ vs → Σ (A vs) (B vs)))
→ Term Γ A
`proj₂ : ∀{A} {B : ScopedType₂ Γ A}
(ab : Term Γ (λ vs → Σ (A vs) (B vs)))
→ Term Γ (λ vs → B vs (proj₁ (eval ab vs)))
----------------------------------------------------------------------
{- Type introduction -}
eval `⊥ vs = `⊥
eval `⊤ vs = `⊤
eval `Bool vs = `Bool
eval `ℕ vs = `ℕ
eval `Type vs = `Type
eval (`Π A B) vs = `Π (eval A vs) λ v → eval B (vs , v)
eval (`Σ A B) vs = `Σ (eval A vs) λ v → eval B (vs , v)
eval `⟦ A ⟧ vs = `⟦ eval A vs ⟧
{- Value introduction -}
eval `tt vs = tt
eval `true vs = true
eval `false vs = false
eval `zero vs = zero
eval (`suc n) vs = suc (eval n vs)
eval (`λ f) vs = λ v → eval f (vs , v)
eval (a `, b) vs = eval a vs , eval b vs
{- Value elimination -}
eval (`var i) vs = lookup i vs
eval (`elim⊥ P x) vs = elim⊥ (eval x vs)
eval (`elimBool {ℓ} P pt pf b) vs =
elimBool (λ v → ⟦ ℓ ∣ eval P (vs , v) ⟧)
(eval pt vs)
(eval pf vs)
(eval b vs)
eval (`elimℕ {ℓ} P pz ps n) vs =
elimℕ (λ v → ⟦ ℓ ∣ eval P (vs , v) ⟧)
(eval pz vs)
(λ n rec → eval ps ((vs , n) , rec))
(eval n vs)
eval (f `$ a) vs = (eval f vs) (eval a vs)
eval (`proj₁ ab) vs = proj₁ (eval ab vs)
eval (`proj₂ ab) vs = proj₂ (eval ab vs)
----------------------------------------------------------------------
| 30.856061
| 76
| 0.458876
|
0b40a14919f914f8ec170b1324e247e482e0a890
| 706
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Instances/Unit.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Algebra/CommRing/Instances/Unit.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Instances/Unit.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.Unit where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Unit
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
private
variable
ℓ : Level
open CommRingStr
UnitCommRing : CommRing ℓ-zero
fst UnitCommRing = Unit
0r (snd UnitCommRing) = tt
1r (snd UnitCommRing) = tt
_+_ (snd UnitCommRing) = λ _ _ → tt
_·_ (snd UnitCommRing) = λ _ _ → tt
- snd UnitCommRing = λ _ → tt
isCommRing (snd UnitCommRing) =
makeIsCommRing isSetUnit (λ _ _ _ → refl) (λ { tt → refl }) (λ _ → refl)
(λ _ _ → refl) (λ _ _ _ → refl) (λ { tt → refl })
(λ _ _ _ → refl) (λ _ _ → refl)
| 25.214286
| 74
| 0.657224
|
3d66a0ac3f5b62dcf286e862b9efddd57f66b374
| 415
|
agda
|
Agda
|
src/Fragment/Examples/Semigroup/Arith/Base.agda
|
yallop/agda-fragment
|
f2a6b1cf4bc95214bd075a155012f84c593b9496
|
[
"MIT"
] | 18
|
2021-06-15T15:45:39.000Z
|
2022-01-17T17:26:09.000Z
|
src/Fragment/Examples/Semigroup/Arith/Base.agda
|
yallop/agda-fragment
|
f2a6b1cf4bc95214bd075a155012f84c593b9496
|
[
"MIT"
] | 1
|
2021-06-16T09:44:31.000Z
|
2021-06-16T10:24:15.000Z
|
src/Fragment/Examples/Semigroup/Arith/Base.agda
|
yallop/agda-fragment
|
f2a6b1cf4bc95214bd075a155012f84c593b9496
|
[
"MIT"
] | 3
|
2021-06-15T15:34:50.000Z
|
2021-06-16T08:04:31.000Z
|
{-# OPTIONS --without-K --safe #-}
module Fragment.Examples.Semigroup.Arith.Base where
open import Fragment.Prelude public
open import Data.Nat using (ℕ; _*_; _+_) public
open import Data.Nat.Properties
using (*-isSemigroup; +-isSemigroup)
open import Relation.Binary.PropositionalEquality public
open ≡-Reasoning public
+-semigroup = semigroup→model +-isSemigroup
*-semigroup = semigroup→model *-isSemigroup
| 27.666667
| 56
| 0.771084
|
418b444311ad02b6946c0f08fdcfbdea94a6ad88
| 6,393
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Nat/GCD.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Nat/GCD.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Nat/GCD.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Greatest common divisor
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.GCD where
open import Data.Nat
open import Data.Nat.Divisibility
open import Data.Nat.GCD.Lemmas
open import Data.Nat.Properties using (+-suc)
open import Data.Product
open import Function
open import Induction
open import Induction.Nat using (<′-Rec; <′-recBuilder)
open import Induction.Lexicographic
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_; subst)
open import Relation.Nullary using (Dec; yes; no)
------------------------------------------------------------------------
-- Greatest common divisor
module GCD where
-- Specification of the greatest common divisor (gcd) of two natural
-- numbers.
record GCD (m n gcd : ℕ) : Set where
constructor is
field
-- The gcd is a common divisor.
commonDivisor : gcd ∣ m × gcd ∣ n
-- All common divisors divide the gcd, i.e. the gcd is the
-- greatest common divisor according to the partial order _∣_.
greatest : ∀ {d} → d ∣ m × d ∣ n → d ∣ gcd
open GCD public
-- The gcd is unique.
unique : ∀ {d₁ d₂ m n} → GCD m n d₁ → GCD m n d₂ → d₁ ≡ d₂
unique d₁ d₂ = ∣-antisym (GCD.greatest d₂ (GCD.commonDivisor d₁))
(GCD.greatest d₁ (GCD.commonDivisor d₂))
-- The gcd relation is "symmetric".
sym : ∀ {d m n} → GCD m n d → GCD n m d
sym g = is (swap $ GCD.commonDivisor g) (GCD.greatest g ∘ swap)
-- The gcd relation is "reflexive".
refl : ∀ {n} → GCD n n n
refl = is (∣-refl , ∣-refl) proj₁
-- The GCD of 0 and n is n.
base : ∀ {n} → GCD 0 n n
base {n} = is (n ∣0 , ∣-refl) proj₂
-- If d is the gcd of n and k, then it is also the gcd of n and
-- n + k.
step : ∀ {n k d} → GCD n k d → GCD n (n + k) d
step g with GCD.commonDivisor g
step {n} {k} {d} g | (d₁ , d₂) = is (d₁ , ∣m∣n⇒∣m+n d₁ d₂) greatest′
where
greatest′ : ∀ {d′} → d′ ∣ n × d′ ∣ n + k → d′ ∣ d
greatest′ (d₁ , d₂) = GCD.greatest g (d₁ , ∣m+n∣m⇒∣n d₂ d₁)
open GCD public using (GCD) hiding (module GCD)
------------------------------------------------------------------------
-- Calculating the gcd
-- The calculation also proves Bézout's lemma.
module Bézout where
module Identity where
-- If m and n have greatest common divisor d, then one of the
-- following two equations is satisfied, for some numbers x and y.
-- The proof is "lemma" below (Bézout's lemma).
--
-- (If this identity was stated using integers instead of natural
-- numbers, then it would not be necessary to have two equations.)
data Identity (d m n : ℕ) : Set where
+- : (x y : ℕ) (eq : d + y * n ≡ x * m) → Identity d m n
-+ : (x y : ℕ) (eq : d + x * m ≡ y * n) → Identity d m n
-- Various properties about Identity.
sym : ∀ {d} → Symmetric (Identity d)
sym (+- x y eq) = -+ y x eq
sym (-+ x y eq) = +- y x eq
refl : ∀ {d} → Identity d d d
refl = -+ 0 1 P.refl
base : ∀ {d} → Identity d 0 d
base = -+ 0 1 P.refl
private
infixl 7 _⊕_
_⊕_ : ℕ → ℕ → ℕ
m ⊕ n = 1 + m + n
step : ∀ {d n k} → Identity d n k → Identity d n (n + k)
step {d} (+- x y eq) with compare x y
step {d} (+- .x .x eq) | equal x = +- (2 * x) x (lem₂ d x eq)
step {d} (+- .x .(x ⊕ i) eq) | less x i = +- (2 * x ⊕ i) (x ⊕ i) (lem₃ d x eq)
step {d} {n} (+- .(y ⊕ i) .y eq) | greater y i = +- (2 * y ⊕ i) y (lem₄ d y n eq)
step {d} (-+ x y eq) with compare x y
step {d} (-+ .x .x eq) | equal x = -+ (2 * x) x (lem₅ d x eq)
step {d} (-+ .x .(x ⊕ i) eq) | less x i = -+ (2 * x ⊕ i) (x ⊕ i) (lem₆ d x eq)
step {d} {n} (-+ .(y ⊕ i) .y eq) | greater y i = -+ (2 * y ⊕ i) y (lem₇ d y n eq)
open Identity public using (Identity; +-; -+) hiding (module Identity)
module Lemma where
-- This type packs up the gcd, the proof that it is a gcd, and the
-- proof that it satisfies Bézout's identity.
data Lemma (m n : ℕ) : Set where
result : (d : ℕ) (g : GCD m n d) (b : Identity d m n) → Lemma m n
-- Various properties about Lemma.
sym : Symmetric Lemma
sym (result d g b) = result d (GCD.sym g) (Identity.sym b)
base : ∀ d → Lemma 0 d
base d = result d GCD.base Identity.base
refl : ∀ d → Lemma d d
refl d = result d GCD.refl Identity.refl
stepˡ : ∀ {n k} → Lemma n (suc k) → Lemma n (suc (n + k))
stepˡ {n} {k} (result d g b) =
subst (Lemma n) (+-suc n k) $
result d (GCD.step g) (Identity.step b)
stepʳ : ∀ {n k} → Lemma (suc k) n → Lemma (suc (n + k)) n
stepʳ = sym ∘ stepˡ ∘ sym
open Lemma public using (Lemma; result) hiding (module Lemma)
-- Bézout's lemma proved using some variant of the extended
-- Euclidean algorithm.
lemma : (m n : ℕ) → Lemma m n
lemma m n = build [ <′-recBuilder ⊗ <′-recBuilder ] P gcd (m , n)
where
P : ℕ × ℕ → Set
P (m , n) = Lemma m n
gcd : ∀ p → (<′-Rec ⊗ <′-Rec) P p → P p
gcd (zero , n ) rec = Lemma.base n
gcd (suc m , zero ) rec = Lemma.sym (Lemma.base (suc m))
gcd (suc m , suc n ) rec with compare m n
gcd (suc m , suc .m ) rec | equal .m = Lemma.refl (suc m)
gcd (suc m , suc .(suc (m + k))) rec | less .m k =
-- "gcd (suc m) (suc k)"
Lemma.stepˡ $ proj₁ rec (suc k) (lem₁ k m)
gcd (suc .(suc (n + k)) , suc n) rec | greater .n k =
-- "gcd (suc k) (suc n)"
Lemma.stepʳ $ proj₂ rec (suc k) (lem₁ k n) (suc n)
-- Bézout's identity can be recovered from the GCD.
identity : ∀ {m n d} → GCD m n d → Identity d m n
identity {m} {n} g with lemma m n
... | result d g′ b with GCD.unique g g′
... | P.refl = b
-- Calculates the gcd of the arguments.
gcd : (m n : ℕ) → ∃ λ d → GCD m n d
gcd m n with Bézout.lemma m n
... | Bézout.result d g _ = (d , g)
-- gcd as a proposition is decidable
gcd? : (m n d : ℕ) → Dec (GCD m n d)
gcd? m n d with gcd m n
... | d′ , p with d′ ≟ d
... | no ¬g = no (¬g ∘ GCD.unique p)
... | yes g = yes (subst (GCD m n) g p)
| 32.451777
| 91
| 0.51791
|
10bcbf704be0bb81aeda47765a72e07d0cce5ce9
| 6,537
|
agda
|
Agda
|
src/Syntax/Substitution/Kits.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | 4
|
2018-05-31T20:37:04.000Z
|
2022-01-04T09:33:48.000Z
|
src/Syntax/Substitution/Kits.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
src/Syntax/Substitution/Kits.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
-- Syntactic kits from Conor McBride's
-- "Type-Preserving Renaming and Substitution"
module Syntax.Substitution.Kits where
open import Syntax.Types
open import Syntax.Context
open import Syntax.Terms
open import CategoryTheory.Categories
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym)
-- Type of entities that we can traverse
-- (instantiated by variables and types)
Schema : Set₁
Schema = Context -> Judgement -> Set
-- Explicit substitution from term in context Δ to term in context Γ
-- E.g. from Γ ⌊ A ⌋ Γ′ ⊢ N : B to Γ ⌊⌋ Γ′ ⊢ N[σ] : B
-- using substitution Γ ⌊⌋ Γ′ ⊢ σ : Γ ⌊ A ⌋ Γ′
data Subst (𝒮 : Schema) : Context -> Context -> Set where
-- Empty substitution
● : ∀ {Δ} -> Subst 𝒮 ∙ Δ
-- Extending the domain of a substitution
_▸_ : ∀ {A Γ Δ} -> (σ : Subst 𝒮 Γ Δ) -> (T : 𝒮 Δ A) -> Subst 𝒮 (Γ , A) Δ
-- Syntactic kit grouping together common operations on traversable
-- syntactic entities such as variables and terms
record Kit (𝒮 : Schema) : Set where
field
-- Convert a variable to the entity
𝓋 : ∀ {Γ A} -> A ∈ Γ -> 𝒮 Γ A
-- Convert the entity to a term
𝓉 : ∀ {Γ A} -> 𝒮 Γ A -> Γ ⊢ A
-- Weaken the entity
𝓌 : ∀ {B Γ A} -> 𝒮 Γ A -> 𝒮 (Γ , B) A
-- Stabilise the context of the entity
𝒶 : ∀ {Γ A} -> 𝒮 Γ (A always) -> 𝒮 (Γ ˢ) (A always)
-- Substitutable kit
record SubstKit (𝒮 : Schema) : Set where
field
-- Underlying traversable kit
𝓀 : Kit 𝒮
-- Apply substitution to a kit
𝓈 : ∀ {Γ Δ A} -> Subst 𝒮 Γ Δ -> 𝒮 Γ A -> 𝒮 Δ A
open Kit
-- | Combinators
-- | All take a syntactic (substitutable) kit as an argument
-- | which provides the necessary operations
-- Weakening a substitution
-- Δ ⊢ σ : Γ to (Δ , A) ⊢ σ : Γ
_⁺_ : ∀ {A 𝒮 Γ Δ} -> Subst 𝒮 Γ Δ -> Kit 𝒮 -> Subst 𝒮 Γ (Δ , A)
● ⁺ _ = ●
(σ ▸ T) ⁺ k = (σ ⁺ k) ▸ 𝓌 k T
infixl 40 _⁺_
-- Lifting a substitution
-- Δ ⊢ σ : Γ to (Δ , A) ⊢ σ : (Γ , A)
_↑_ : ∀ {A 𝒮 Γ Δ} -> Subst 𝒮 Γ Δ -> Kit 𝒮 -> Subst 𝒮 (Γ , A) (Δ , A)
σ ↑ k = (σ ⁺ k) ▸ 𝓋 k top
infixl 40 _↑_
-- Stabilising a substitution
-- Δ ⊢ σ : Γ to Δ ˢ ⊢ σ : Γ ˢ
_↓ˢ_ : ∀ {𝒮 Γ Δ} -> Subst 𝒮 Γ Δ -> Kit 𝒮 -> Subst 𝒮 (Γ ˢ) (Δ ˢ)
● ↓ˢ _ = ●
(_▸_ {A now} σ T) ↓ˢ k = σ ↓ˢ k
(_▸_ {A always} σ T) ↓ˢ k = (σ ↓ˢ k) ▸ 𝒶 k T
infixl 40 _↓ˢ_
-- Identity substitution
idₛ : ∀ {Γ 𝒮} -> Kit 𝒮 -> Subst 𝒮 Γ Γ
idₛ {∙} k = ●
idₛ {Γ , _} k = idₛ k ↑ k
-- Composition of substitutions
_∘[_]ₛ_ : ∀ {𝒮 Γ Δ Ξ} -> Subst 𝒮 Δ Ξ -> SubstKit 𝒮 -> Subst 𝒮 Γ Δ -> Subst 𝒮 Γ Ξ
σ₂ ∘[ k ]ₛ ● = ●
σ₂ ∘[ k ]ₛ (σ₁ ▸ T) = (σ₂ ∘[ k ]ₛ σ₁) ▸ SubstKit.𝓈 k σ₂ T
-- Substitution from an order-preserving embedding
-- Γ ⊆ Δ to Δ ⊢ σ : Γ
_⊆ₛ_ : ∀ {𝒮 Γ Δ} -> Γ ⊆ Δ -> Kit 𝒮 -> Subst 𝒮 Γ Δ
refl ⊆ₛ k = idₛ k
(keep s) ⊆ₛ k = (s ⊆ₛ k) ↑ k
(drop s) ⊆ₛ k = (s ⊆ₛ k) ⁺ k
-- Substitution from propositional equality of contexts
_≡ₛ_ : ∀ {𝒮 Γ Δ} -> Γ ≡ Δ -> Kit 𝒮 -> Subst 𝒮 Γ Δ
refl ≡ₛ k = idₛ k
-- Substitution from idempotence of stabilisation
_ˢˢₛ_ : ∀ {𝒮} -> (Γ : Context) -> Kit 𝒮 -> Subst 𝒮 (Γ ˢ) (Γ ˢ ˢ)
∙ ˢˢₛ k = ●
(Γ , A now) ˢˢₛ k = Γ ˢˢₛ k
(Γ , A always) ˢˢₛ k = (Γ ˢˢₛ k) ↑ k
-- | Standard substitutions
-- | Common transformations between contexts
module _ {𝒮 : Schema} (sk : SubstKit 𝒮) where
open SubstKit sk
open Kit 𝓀
-- | Weakening
-- Weakening the top of the context
weak-topₛ : ∀{A Γ} -> Subst 𝒮 Γ (Γ , A)
weak-topₛ = idₛ 𝓀 ⁺ 𝓀
-- Weakening the middle of the context
weak-midₛ : ∀{A} Γ Γ′ -> Subst 𝒮 (Γ ⌊⌋ Γ′) (Γ ⌊ A ⌋ Γ′)
weak-midₛ Γ ∙ = weak-topₛ
weak-midₛ Γ (Γ′ , B) = weak-midₛ Γ Γ′ ↑ 𝓀
-- General weakening from an OPE
weakₛ : ∀{Γ Δ} -> Γ ⊆ Δ -> Subst 𝒮 Γ Δ
weakₛ = _⊆ₛ 𝓀
-- | Exchange
-- Exchange on top
ex-topₛ : ∀{A B} Γ -> Subst 𝒮 (Γ , A , B) (Γ , B , A)
ex-topₛ Γ = (idₛ 𝓀 ⁺ 𝓀 ↑ 𝓀) ▸ (𝓋 𝓀 (pop top))
-- General exchange lemma
exₛ : ∀{A B} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊ B ⌋ Γ″) (Γ ⌊ B ⌋ Γ′ ⌊ A ⌋ Γ″)
exₛ Γ ∙ ∙ = ex-topₛ Γ
exₛ {A} {B} Γ (Γ′ , C) ∙ =
(exₛ Γ Γ′ [ A ] ∘[ sk ]ₛ ex-topₛ (Γ , C ⌊⌋ Γ′)) ∘[ sk ]ₛ exₛ Γ Γ′ [ B ]
exₛ Γ ∙ (Γ″ , D) = exₛ Γ ∙ Γ″ ↑ 𝓀
exₛ Γ (Γ′ , C) (Γ″ , D) = exₛ Γ (Γ′ , C) Γ″ ↑ 𝓀
-- | Contraction
-- Contraction on top
contr-topₛ : ∀{A Γ} -> Subst 𝒮 (Γ , A , A) (Γ , A)
contr-topₛ = (idₛ 𝓀) ▸ (𝓋 𝓀 top)
-- General contraction lemma (left)
contr-lₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊ A ⌋ Γ″) (Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″)
contr-lₛ Γ ∙ ∙ = contr-topₛ
contr-lₛ Γ (Γ′ , B) ∙ = (idₛ 𝓀) ▸ (𝓌 𝓀 (𝓈 (contr-lₛ Γ Γ′ ∙) (𝓋 𝓀 top)))
contr-lₛ Γ ∙ (Γ″ , C) = contr-lₛ Γ ∙ Γ″ ↑ 𝓀
contr-lₛ Γ (Γ′ , B) (Γ″ , C) = contr-lₛ Γ (Γ′ , B) Γ″ ↑ 𝓀
-- General contraction lemma (right)
contr-rₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊ A ⌋ Γ″) (Γ ⌊⌋ Γ′ ⌊ A ⌋ Γ″)
contr-rₛ Γ ∙ ∙ = contr-topₛ
contr-rₛ {A} Γ (Γ′ , B) ∙ =
(ex-topₛ (Γ ⌊⌋ Γ′) ∘[ sk ]ₛ contr-rₛ Γ Γ′ [ B ]) ∘[ sk ]ₛ ex-topₛ (Γ , A ⌊⌋ Γ′)
contr-rₛ Γ ∙ (Γ″ , C) = contr-rₛ Γ ∙ Γ″ ↑ 𝓀
contr-rₛ Γ (Γ′ , B) (Γ″ , C) = contr-rₛ Γ (Γ′ , B) Γ″ ↑ 𝓀
-- | Movement
-- Moving a variable to the right in the context
move-rₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″) (Γ ⌊⌋ Γ′ ⌊ A ⌋ Γ″)
move-rₛ {A} Γ Γ′ Γ″ = contr-rₛ Γ Γ′ Γ″ ∘[ sk ]ₛ weak-midₛ (Γ ⌊ A ⌋ Γ′) Γ″
-- Moving a variable to the left in the context
-- Bit verbose as we have to deal with associativity
move-lₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊⌋ Γ′ ⌊ A ⌋ Γ″) (Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″)
move-lₛ {A} Γ Γ′ Γ″
= contr-lₛ Γ Γ′ Γ″
∘[ sk ]ₛ ((sym (⌊A⌋-assoc Γ Γ′ Γ″ A A) ≡ₛ 𝓀)
∘[ sk ]ₛ ((weak-midₛ {A} Γ (Γ′ ⌊ A ⌋ Γ″))
∘[ sk ]ₛ (⌊⌋-assoc Γ (Γ′ , A) Γ″ ≡ₛ 𝓀)))
-- Moving a variable to the right in the stabilised context context
moveˢ-rₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ˢ ⌊ A ⌋ (Γ′ ⌊⌋ Γ″) ˢ) ((Γ ⌊⌋ Γ′) ˢ ⌊ A ⌋ Γ″ ˢ)
moveˢ-rₛ {A} Γ Γ′ Γ″
rewrite ˢ-pres-⌊⌋ Γ Γ′
| ˢ-pres-⌊⌋ Γ′ Γ″
| sym (⌊⌋-assoc (Γ ˢ , A) (Γ′ ˢ) (Γ″ ˢ))
= move-rₛ (Γ ˢ) (Γ′ ˢ) (Γ″ ˢ)
-- | Substitution
-- Substitution for the top of the context
sub-topₛ : ∀{A Γ} -> 𝒮 Γ A -> Subst 𝒮 (Γ , A) Γ
sub-topₛ T = (idₛ 𝓀) ▸ T
-- Substitution for the top of a stabilised context
sub-topˢₛ : ∀{Γ A} -> 𝒮 Γ A -> Subst 𝒮 (Γ ˢ , A) Γ
sub-topˢₛ {Γ} T = (Γˢ⊆Γ Γ ⊆ₛ 𝓀) ▸ T
-- Substitution for the middle of the context
sub-midₛ : ∀{A} Γ Γ′ -> 𝒮 (Γ ⌊⌋ Γ′) A -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′) (Γ ⌊⌋ Γ′)
sub-midₛ Γ Γ′ T = sub-topₛ T ∘[ sk ]ₛ move-rₛ Γ Γ′ ∙
| 33.352041
| 88
| 0.503595
|
579e17821e53bcfd11580d9d22aaeee2dd05679f
| 161
|
agda
|
Agda
|
test/Fail/Issue1419.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1419.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1419.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue1419 where
module A where
module M where
module B where
module M where
open A
open B
module N (let open M) where
module LotsOfStuff where
| 10.733333
| 27
| 0.745342
|
39115e548dfb54ce683f78c86f95dbf19a5dd091
| 822
|
agda
|
Agda
|
lib/Explore/Experimental/Isos.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | 2
|
2016-06-05T09:25:32.000Z
|
2017-06-28T19:19:29.000Z
|
lib/Explore/Experimental/Isos.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | 1
|
2019-03-16T14:24:04.000Z
|
2019-03-16T14:24:04.000Z
|
lib/Explore/Experimental/Isos.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module Explore.Explorable.Isos where
open import Function
open import Data.Product
open import Data.Nat
open import Data.Vec renaming (sum to vsum)
open import Function.Related.TypeIsomorphisms.NP
import Relation.Binary.PropositionalEquality.NP as ≡
open ≡ using (_≡_; _≗_)
open import Explore.Type
open import Explore.Explorable
open import Explore.Product
swap-μ : ∀ {A B} → Explorable (A × B) → Explorable (B × A)
swap-μ = μ-iso swap-iso
swapS-preserve : ∀ {A B} f (μA×B : Explorable (A × B)) → sum μA×B f ≡ sum (swap-μ μA×B) (f ∘ swap)
swapS-preserve = μ-iso-preserve swap-iso
μ^ : ∀ {A} (μA : Explorable A) n → Explorable (A ^ n)
μ^ μA zero = μLift μ𝟙
μ^ μA (suc n) = μA ×-μ μ^ μA n
μVec : ∀ {A} (μA : Explorable A) n → Explorable (Vec A n)
μVec μA n = μ-iso (^↔Vec n) (μ^ μA n)
| 29.357143
| 98
| 0.671533
|
5864ad555148d25cd5e3d67557ce409bfb432958
| 454
|
agda
|
Agda
|
test/Succeed/Issue807.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue807.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue807.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- {-# OPTIONS -v term:20 -v tc.term:20 #-}
-- {-# OPTIONS -v tc.def.alias:100 -v tc.term.expr.coind:100 #-}
module Issue807 where
open import Common.Coinduction
data Stream : Set where
cons : ∞ Stream → Stream
mutual
-- s : Stream
s = cons s′
-- s′ : ∞ _
s′ = ♯ s
-- Under 2.3.0.1: The code is accepted.
-- Under 2.3.2: The termination checker complains.
-- Bug was that aliases did not lead to construction of ♯-auxiliary function.
| 20.636364
| 77
| 0.638767
|
2329beccf05ef9a8334ff75e2fbddf85f3c97dd1
| 2,244
|
agda
|
Agda
|
Cats/Category/Setoids/Facts/Exponentials.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Setoids/Facts/Exponentials.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Setoids/Facts/Exponentials.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
module Cats.Category.Setoids.Facts.Exponentials where
open import Data.Product using (_,_)
open import Relation.Binary using (Setoid)
open import Cats.Category
open import Cats.Category.Setoids as Setoids using (Setoids ; ≈-intro ; ≈-elim)
open import Cats.Category.Setoids.Facts.Products as Products using
(hasBinaryProducts)
open import Cats.Util.Conv
import Relation.Binary.PropositionalEquality as ≡
import Cats.Category.Base as Base
import Cats.Util.SetoidReasoning as SetoidReasoning
module Build l where
infixr 1 _↝_
open Base.Category (Setoids l l)
open Category (Setoids l l) using (∃!-intro ; Exp ; IsUniqueSuchThat)
open HasBinaryProducts (hasBinaryProducts l l)
open Setoids._⇒_ using (resp)
_↝_ : Obj → Obj → Obj
A ↝ B = record
{ Carrier = A ⇒ B
; _≈_ = _≈_ {A} {B}
; isEquivalence = equiv
}
eval : ∀ {B C} → (B ↝ C) × B ⇒ C
eval = record
{ arr = λ { (f , x) → (f ⃗) x }
; resp = λ { (eq₁ , eq₂) → ≈-elim eq₁ eq₂ }
}
curry : ∀ {A B C} → A × B ⇒ C → A ⇒ B ↝ C
curry {A} f = record
{ arr = λ a → record
{ arr = λ b → (f ⃗) (a , b)
; resp = λ eqb → resp f (refl , eqb)
}
; resp = λ eqa → ≈-intro λ eqb → resp f (eqa , eqb)
}
where
open Setoid A using (refl)
curry-correct : ∀ {A B C} (f : A × B ⇒ C)
→ eval ∘ ⟨ curry f × id ⟩ ≈ f
curry-correct f = ≈-intro (resp f)
curry-unique : ∀ {A B C} (f : A × B ⇒ C)
→ IsUniqueSuchThat (λ f̃ → eval ∘ ⟨ f̃ × id ⟩ ≈ f) (curry f)
curry-unique {A} {B} {C} f {g} eval∘g≈f
= ≈-intro λ {a} {a′} a≈a′ → ≈-intro λ {b} {b′} b≈b′ →
begin⟨ C ⟩
((((curry f) ⃗) a) ⃗) b
≡⟨⟩
(f ⃗) (a , b)
≈⟨ sym C (≈-elim eval∘g≈f (sym A a≈a′ , sym B b≈b′)) ⟩
(((g ⃗) a′) ⃗) b′
∎
where
open SetoidReasoning
open Setoid using (sym)
_↝′_ : ∀ B C → Exp B C
B ↝′ C = record
{ Cᴮ = B ↝ C
; eval = eval
; curry′ = λ f → ∃!-intro
(curry f)
(curry-correct f)
(λ {g} eval∘g≈f → curry-unique f {g} eval∘g≈f)
}
instance
hasExponentials : ∀ l → HasExponentials (Setoids l l)
hasExponentials l = record { _↝′_ = Build._↝′_ l }
| 24.933333
| 79
| 0.529857
|
10e83154aa11cc8089b50c3dbcd06c356926c33b
| 293
|
agda
|
Agda
|
test/Succeed/Issue611.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue611.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue611.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2012-04-18
module Issue611 where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Bool : Set where
true false : Bool
T : Bool -> Set
T true = {x : Bool} -> Nat
T false = {x : Bool} -> Bool
data D (b : Bool) : Set where
c : T b -> D b
d : D false
d = c {_} true
| 14.65
| 29
| 0.569966
|
a15267bbafa74e8ea7b71a5b6ba94d2b2b4658b2
| 941
|
agda
|
Agda
|
Cubical/Structures/Pointed.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Pointed.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Pointed.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-
Pointed structure: X ↦ X
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Pointed where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Pointed.Base
private
variable
ℓ : Level
-- Structured isomorphisms
PointedStructure : Type ℓ → Type ℓ
PointedStructure X = X
PointedEquivStr : StrEquiv PointedStructure ℓ
PointedEquivStr A B f = equivFun f (pt A) ≡ pt B
pointedUnivalentStr : UnivalentStr {ℓ} PointedStructure PointedEquivStr
pointedUnivalentStr f = invEquiv (ua-ungluePath-Equiv f)
pointedSIP : (A B : Pointed ℓ) → A ≃[ PointedEquivStr ] B ≃ (A ≡ B)
pointedSIP = SIP pointedUnivalentStr
pointed-sip : (A B : Pointed ℓ) → A ≃[ PointedEquivStr ] B → (A ≡ B)
pointed-sip A B = equivFun (pointedSIP A B) -- ≡ λ (e , p) i → ua e i , ua-gluePath e p i
| 26.138889
| 89
| 0.735388
|
1de609373ec8e653c3a77ffbf75e55d319b1519d
| 576
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Integer/Literals.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Integer/Literals.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Integer/Literals.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Integer Literals
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Integer.Literals where
open import Agda.Builtin.FromNat
open import Agda.Builtin.FromNeg
open import Data.Unit
open import Data.Integer
number : Number ℤ
number = record
{ Constraint = λ _ → ⊤
; fromNat = λ n → + n
}
negative : Negative ℤ
negative = record
{ Constraint = λ _ → ⊤
; fromNeg = λ n → - (+ n)
}
| 21.333333
| 72
| 0.487847
|
1d7ff4d259c0e12cbd3d69934945a553b1724a95
| 3,542
|
agda
|
Agda
|
src/JVM/Model/Properties.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 6
|
2020-10-07T14:07:17.000Z
|
2021-02-28T21:49:08.000Z
|
src/JVM/Model/Properties.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | null | null | null |
src/JVM/Model/Properties.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 1
|
2021-12-28T17:37:15.000Z
|
2021-12-28T17:37:15.000Z
|
module JVM.Model.Properties where
open import Data.List
open import Data.List.Properties
open import Data.List.Relation.Binary.Permutation.Propositional
open import Data.List.Relation.Binary.Permutation.Propositional.Properties
open import Data.Product hiding (map)
open import Relation.Unary using (Pred)
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax
open import Relation.Ternary.Construct.Bag.Properties
open import Function
module _ {p t} {T : Set t} {P : Pred _ p} where
open import JVM.Model (List T)
open import Data.List.Relation.Unary.All
-- If you know the split and what is bubbling up from the left and right parts,
-- then you know what bubbles up from the composite.
source : ∀ {Φ₁ : Intf} → Φ₁ ∙ Φ₂ ≣ Φ → All P (up Φ₁) → All P (up Φ₂) → All P (up Φ)
source (ex {u₁} {u₂} (sub x₁ x₂) (sub x₃ x₄) x₅ x₆) pu₁ pu₂ = joinAll (λ ()) x₅ pu₁' pu₂'
where
pu₂' = proj₁ (splitAll (λ where dup p → p , p) x₂ pu₂)
pu₁' = proj₁ (splitAll (λ where dup p → p , p) x₄ pu₁)
-- If you know the split and what is bubbling up from the left and flowing down the composite,
-- then you know what flows down the right part.
sinkᵣ : ∀ {Φ₁ : Intf} → Φ₁ ∙ Φ₂ ≣ Φ → All P (up Φ₁) → All P (down Φ) → All P (down Φ₂)
sinkᵣ (ex (sub x₁ x₂) (sub x₃ x₄) x₅ x₆) pu₁ pu₂ = joinAll (λ ()) x₃ pd₁' pe₁
where
pd₁' = proj₁ (splitAll (λ where dup p → p , p) x₆ pu₂)
pe₁ = proj₂ (splitAll (λ where dup p → p , p) x₄ pu₁)
-- The same, but different.
sinkₗ : ∀ {Φ₁ Φ₂ Φ : Intf} → Φ₁ ∙ Φ₂ ≣ Φ → All P (up Φ₂) → All P (down Φ) → All P (down Φ₁)
sinkₗ σ ups downs = sinkᵣ (∙-comm σ) ups downs
-- {- Mapping along any injection yields a model morphism -}
-- module _ {a b} {A : Set a} {B : Set b} (𝑚 : A ↣ B) where
-- open Injection 𝑚
-- private
-- ⟦_⟧ = λ a → f a
-- j = map ⟦_⟧
-- open import JVM.Model A as L
-- open import JVM.Model B as R
-- import Relation.Ternary.Construct.Duplicate.Properties as D
-- import Relation.Ternary.Construct.Empty.Properties as E
-- module OMM = MonoidMorphism (bagMap (D.f-morphism 𝑚))
-- module DMM = MonoidMorphism (bagMap (E.⊥-morphism ⟦_⟧))
-- import Relation.Ternary.Construct.Bag.Overlapping as O
-- import Relation.Ternary.Construct.Bag.Disjoint as D
-- private
-- sub-lemma⁺ : ∀ {xs ys u d} → xs L.- ys ≣ (u L.⇅ d) → j xs R.- j ys ≣ (j u R.⇅ j d)
-- sub-lemma⁺ (sub x x₁) = R.sub (DMM.j-∙ x) (OMM.j-∙ x₁)
-- sub-lemma⁻ : ∀ {xs ys u d} → j xs R.- j ys ≣ (u R.⇅ d) →
-- ∃₂ λ u' d' → xs L.- ys ≣ (u' L.⇅ d') × u ≡ j u' × d ≡ j d'
-- sub-lemma⁻ (sub x y)
-- with _ , x' , refl , refl ← D.map-inv _ ⟦_⟧ x
-- | _ , y' , refl , eq ← O.map-inv _ ⟦_⟧ y
-- with refl ← map-injective 𝑚 eq
-- = -, -, (L.sub x' y' , refl , refl)
-- ⟦⟧-morphism : SemigroupMorphism L.intf-isSemigroup R.intf-isSemigroup
-- SemigroupMorphism.j ⟦⟧-morphism (e ⇅ d) = (j e) R.⇅ (j d)
-- SemigroupMorphism.jcong ⟦⟧-morphism (ρ₁ , ρ₂) = map⁺ ⟦_⟧ ρ₁ , map⁺ ⟦_⟧ ρ₂
-- SemigroupMorphism.j-∙ ⟦⟧-morphism (ex x x₁ σ₁ σ₂) =
-- R.ex (sub-lemma⁺ x) (sub-lemma⁺ x₁) (DMM.j-∙ σ₁) (OMM.j-∙ σ₂)
-- SemigroupMorphism.j-∙⁻ ⟦⟧-morphism (ex x x₁ σ₁ σ₂) with sub-lemma⁻ x
-- ... | _ , _ , y , refl , refl with sub-lemma⁻ x₁
-- ... | _ , _ , y₁ , refl , refl with _ , τ₁ , refl ← DMM.j-∙⁻ σ₁ | _ , τ₂ , refl ← OMM.j-∙⁻ σ₂
-- = -, L.ex y y₁ τ₁ τ₂ , refl
| 42.674699
| 98
| 0.604461
|
d0d24933d1ed0bfbd9efd81df5eed3a46dec5c86
| 5,436
|
agda
|
Agda
|
Cubical/HITs/Ints/QuoInt/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/QuoInt/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/QuoInt/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
-- Define the integers as a HIT by identifying +0 and -0
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.QuoInt.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Relation.Nullary
open import Cubical.Data.Int as Int using (Int; sucInt; predInt; discreteInt; isSetInt)
open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc)
open import Cubical.Data.Bool as Bool using (Bool; not; notnot)
variable
l : Level
Sign : Type₀
Sign = Bool
pattern spos = Bool.false
pattern sneg = Bool.true
_*S_ : Sign → Sign → Sign
_*S_ = Bool._⊕_
data ℤ : Type₀ where
signed : (s : Sign) (n : ℕ) → ℤ
posneg : signed spos 0 ≡ signed sneg 0
pattern pos n = signed spos n
pattern neg n = signed sneg n
sign : ℤ → Sign
sign (signed _ zero) = spos
sign (signed s (suc _)) = s
sign (posneg i) = spos
sign-pos : ∀ n → sign (pos n) ≡ spos
sign-pos zero = refl
sign-pos (suc n) = refl
abs : ℤ → ℕ
abs (signed _ n) = n
abs (posneg i) = zero
signed-inv : ∀ n → signed (sign n) (abs n) ≡ n
signed-inv (pos zero) = refl
signed-inv (neg zero) = posneg
signed-inv (signed s (suc n)) = refl
signed-inv (posneg i) j = posneg (i ∧ j)
signed-zero : ∀ s₁ s₂ → signed s₁ zero ≡ signed s₂ zero
signed-zero spos spos = refl
signed-zero sneg sneg = refl
signed-zero spos sneg = posneg
signed-zero sneg spos = sym posneg
rec : ∀ {A : Type l} → (pos' neg' : ℕ → A) → pos' 0 ≡ neg' 0 → ℤ → A
rec pos' neg' eq (pos m) = pos' m
rec pos' neg' eq (neg m) = neg' m
rec pos' neg' eq (posneg i) = eq i
elim : ∀ (P : ℤ → Type l)
→ (pos' : ∀ n → P (pos n))
→ (neg' : ∀ n → P (neg n))
→ (λ i → P (posneg i)) [ pos' 0 ≡ neg' 0 ]
→ ∀ z → P z
elim P pos' neg' eq (pos n) = pos' n
elim P pos' neg' eq (neg n) = neg' n
elim P pos' neg' eq (posneg i) = eq i
Int→ℤ : Int → ℤ
Int→ℤ (Int.pos n) = pos n
Int→ℤ (Int.negsuc n) = neg (suc n)
ℤ→Int : ℤ → Int
ℤ→Int (pos n) = Int.pos n
ℤ→Int (neg zero) = Int.pos 0
ℤ→Int (neg (suc n)) = Int.negsuc n
ℤ→Int (posneg _) = Int.pos 0
ℤ→Int→ℤ : ∀ (n : ℤ) → Int→ℤ (ℤ→Int n) ≡ n
ℤ→Int→ℤ (pos n) _ = pos n
ℤ→Int→ℤ (neg zero) i = posneg i
ℤ→Int→ℤ (neg (suc n)) _ = neg (suc n)
ℤ→Int→ℤ (posneg j) i = posneg (j ∧ i)
Int→ℤ→Int : ∀ (n : Int) → ℤ→Int (Int→ℤ n) ≡ n
Int→ℤ→Int (Int.pos n) _ = Int.pos n
Int→ℤ→Int (Int.negsuc n) _ = Int.negsuc n
Int≡ℤ : Int ≡ ℤ
Int≡ℤ = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)
discreteℤ : Discrete ℤ
discreteℤ = subst Discrete Int≡ℤ discreteInt
isSetℤ : isSet ℤ
isSetℤ = subst isSet Int≡ℤ isSetInt
-_ : ℤ → ℤ
- signed s n = signed (not s) n
- posneg i = posneg (~ i)
negate-invol : ∀ n → - - n ≡ n
negate-invol (signed s n) i = signed (notnot s i) n
negate-invol (posneg i) _ = posneg i
negateEquiv : ℤ ≃ ℤ
negateEquiv = isoToEquiv (iso -_ -_ negate-invol negate-invol)
negateEq : ℤ ≡ ℤ
negateEq = ua negateEquiv
infixl 6 _+_
infixl 7 _*_
sucℤ : ℤ → ℤ
sucℤ (pos n) = pos (suc n)
sucℤ (neg zero) = pos 1
sucℤ (neg (suc n)) = neg n
sucℤ (posneg _) = pos 1
predℤ : ℤ → ℤ
predℤ = subst (λ Z → (Z → Z)) negateEq sucℤ
-- definitionally equal to λ n → - (sucℤ (- n))
-- strictly more useful than the direct pattern matching version,
-- see negateSuc and negatePred
sucPredℤ : ∀ n → sucℤ (predℤ n) ≡ n
sucPredℤ (pos zero) = sym posneg
sucPredℤ (pos (suc _)) = refl
sucPredℤ (neg _) = refl
sucPredℤ (posneg i) j = posneg (i ∨ ~ j)
predSucℤ : ∀ n → predℤ (sucℤ n) ≡ n
predSucℤ (pos _) = refl
predSucℤ (neg zero) = posneg
predSucℤ (neg (suc _)) = refl
predSucℤ (posneg i) j = posneg (i ∧ j)
_+_ : ℤ → ℤ → ℤ
(signed _ zero) + n = n
(posneg _) + n = n
(pos (suc m)) + n = sucℤ (pos m + n)
(neg (suc m)) + n = predℤ (neg m + n)
sucPathℤ : ℤ ≡ ℤ
sucPathℤ = isoToPath (iso sucℤ predℤ sucPredℤ predSucℤ)
-- We do the same trick as in Cubical.Data.Int to prove that addition
-- is an equivalence
addEqℤ : ℕ → ℤ ≡ ℤ
addEqℤ zero = refl
addEqℤ (suc n) = addEqℤ n ∙ sucPathℤ
predPathℤ : ℤ ≡ ℤ
predPathℤ = isoToPath (iso predℤ sucℤ predSucℤ sucPredℤ)
subEqℤ : ℕ → ℤ ≡ ℤ
subEqℤ zero = refl
subEqℤ (suc n) = subEqℤ n ∙ predPathℤ
addℤ : ℤ → ℤ → ℤ
addℤ (pos m) n = transport (addEqℤ m) n
addℤ (neg m) n = transport (subEqℤ m) n
addℤ (posneg _) n = n
isEquivAddℤ : (m : ℤ) → isEquiv (addℤ m)
isEquivAddℤ (pos n) = isEquivTransport (addEqℤ n)
isEquivAddℤ (neg n) = isEquivTransport (subEqℤ n)
isEquivAddℤ (posneg _) = isEquivTransport refl
addℤ≡+ℤ : addℤ ≡ _+_
addℤ≡+ℤ i (pos (suc m)) n = sucℤ (addℤ≡+ℤ i (pos m) n)
addℤ≡+ℤ i (neg (suc m)) n = predℤ (addℤ≡+ℤ i (neg m) n)
addℤ≡+ℤ i (pos zero) n = n
addℤ≡+ℤ i (neg zero) n = n
addℤ≡+ℤ _ (posneg _) n = n
isEquiv+ℤ : (m : ℤ) → isEquiv (m +_)
isEquiv+ℤ = subst (λ _+_ → (m : ℤ) → isEquiv (m +_)) addℤ≡+ℤ isEquivAddℤ
_*_ : ℤ → ℤ → ℤ
m * n = signed (sign m *S sign n) (abs m ℕ.* abs n)
private
*-abs : ∀ m n → abs (m * n) ≡ abs m ℕ.* abs n
*-abs m n = refl
-- Natural number and negative integer literals for ℤ
open import Cubical.Data.Nat.Literals public
instance
fromNatℤ : HasFromNat ℤ
fromNatℤ = record { Constraint = λ _ → Unit ; fromNat = λ n → pos n }
instance
fromNegℤ : HasFromNeg ℤ
fromNegℤ = record { Constraint = λ _ → Unit ; fromNeg = λ n → neg n }
| 25.166667
| 87
| 0.619573
|
a17883b1c7626a1c67463ef1797291101b226f76
| 4,137
|
agda
|
Agda
|
src/MultiSorted/AlgebraicTheory.agda
|
cilinder/formaltt
|
0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb
|
[
"MIT"
] | 21
|
2021-02-16T14:07:06.000Z
|
2021-11-19T15:50:08.000Z
|
src/MultiSorted/AlgebraicTheory.agda
|
andrejbauer/formaltt
|
2aaf850bb1a262681c5a232cdefae312f921b9d4
|
[
"MIT"
] | 1
|
2021-04-30T14:18:25.000Z
|
2021-05-14T16:15:17.000Z
|
src/MultiSorted/AlgebraicTheory.agda
|
andrejbauer/formaltt
|
2aaf850bb1a262681c5a232cdefae312f921b9d4
|
[
"MIT"
] | 6
|
2021-02-16T13:43:07.000Z
|
2021-05-24T02:51:43.000Z
|
open import Agda.Primitive using (lzero; lsuc; _⊔_)
open import Relation.Binary using (Setoid)
import MultiSorted.Context as Context
module MultiSorted.AlgebraicTheory where
-- an algebraic signature
record Signature {𝓈 ℴ} : Set (lsuc (𝓈 ⊔ ℴ)) where
field
sort : Set 𝓈 -- sorts
oper : Set ℴ -- operations
open Context sort public
-- Arity and arguments
Arity : Set 𝓈
Arity = Context
field
oper-arity : oper → Arity -- the arity of an operation (with the sorts of the arguments)
oper-sort : oper → sort -- the sort of an operation
arg : Arity → Set
arg = var
arg-sort : ∀ (f : oper) → arg (oper-arity f) → sort
arg-sort f = sort-of (oper-arity f)
-- terms in a context of a given sort
data Term (Γ : Context) : ∀ (A : sort) → Set (lsuc ℴ) where
tm-var : ∀ (x : var Γ) → Term Γ (sort-of Γ x)
tm-oper : ∀ (f : oper) → (∀ (i : arg (oper-arity f)) → Term Γ (arg-sort f i)) → Term Γ (oper-sort f)
-- Substitutions (definitions - some useful properties are in another file)
_⇒s_ : ∀ (Γ Δ : Context) → Set (lsuc ℴ)
Γ ⇒s Δ = ∀ (x : var Δ) → Term Γ (sort-of Δ x)
infix 4 _⇒s_
-- identity substitution
id-s : ∀ {Γ : Context} → Γ ⇒s Γ
id-s = tm-var
-- the action of a substitution on a term (contravariant)
_[_]s : ∀ {Γ Δ : Context} {A : sort} → Term Δ A → Γ ⇒s Δ → Term Γ A
(tm-var x) [ σ ]s = σ x
(tm-oper f ts) [ σ ]s = tm-oper f (λ i → ts i [ σ ]s)
infixr 6 _[_]s
-- composition of substitutions
_∘s_ : ∀ {Γ Δ Θ : Context} → Δ ⇒s Θ → Γ ⇒s Δ → Γ ⇒s Θ
(σ ∘s ρ) x = σ x [ ρ ]s
infixl 7 _∘s_
-- Equations
record Equation {s o} (Σ : Signature {s} {o} ) : Set (lsuc (s ⊔ o)) where
constructor make-eq
field
eq-ctx : Signature.Context Σ
eq-sort : Signature.sort Σ
eq-lhs : Signature.Term Σ eq-ctx eq-sort
eq-rhs : Signature.Term Σ eq-ctx eq-sort
infix 5 make-eq
syntax make-eq Γ A s t = Γ ∥ s ≈ t ⦂ A
-- Theory
-- an equational theory is a family of axioms over a given sort
record Theory ℓ {𝓈 ℴ} (Σ : Signature {𝓈} {ℴ}) : Set (lsuc (ℓ ⊔ 𝓈 ⊔ ℴ)) where
open Signature Σ public
field
ax : Set ℓ -- the axioms
ax-eq : ax → Equation Σ
ax-ctx : ax → Context
ax-ctx ε = Equation.eq-ctx (ax-eq ε)
ax-sort : ax → sort
ax-sort ε = Equation.eq-sort (ax-eq ε)
ax-lhs : ∀ (ε : ax) → Term (ax-ctx ε) (ax-sort ε)
ax-lhs ε = Equation.eq-lhs (ax-eq ε)
ax-rhs : ∀ (ε : ax) → Term (ax-ctx ε) (ax-sort ε)
ax-rhs ε = Equation.eq-rhs (ax-eq ε)
-- equality of terms
infix 4 ⊢_
data ⊢_ : Equation Σ → Set (lsuc (ℓ ⊔ 𝓈 ⊔ ℴ)) where
-- general rules
eq-refl : ∀ {Γ A} {t : Term Γ A} → ⊢ Γ ∥ t ≈ t ⦂ A
eq-symm : ∀ {Γ A} {s t : Term Γ A} → ⊢ Γ ∥ s ≈ t ⦂ A → ⊢ Γ ∥ t ≈ s ⦂ A
eq-tran : ∀ {Γ A} {s t u : Term Γ A} → ⊢ Γ ∥ s ≈ t ⦂ A → ⊢ Γ ∥ t ≈ u ⦂ A → ⊢ Γ ∥ s ≈ u ⦂ A
-- congruence rule
eq-congr : ∀ {Γ} {f : oper} {xs ys : ∀ (i : arg (oper-arity f)) → Term Γ (sort-of (oper-arity f) i)} →
(∀ i → ⊢ Γ ∥ (xs i) ≈ (ys i) ⦂ (sort-of (oper-arity f) i)) → ⊢ Γ ∥ (tm-oper f xs) ≈ (tm-oper f ys) ⦂ (oper-sort f)
-- equational axiom
eq-axiom : ∀ (ε : ax) {Γ : Context} (σ : Γ ⇒s ax-ctx ε) →
⊢ Γ ∥ (ax-lhs ε [ σ ]s) ≈ (ax-rhs ε [ σ ]s) ⦂ (ax-sort ε)
-- the action of the identity substitution is the identity
id-action : ∀ {Γ : Context} {A} {a : Term Γ A} → (⊢ Γ ∥ a ≈ (a [ id-s ]s) ⦂ A)
id-action {a = tm-var a} = eq-refl
id-action {a = tm-oper f x} = eq-congr (λ i → id-action {a = x i})
eq-axiom-id : ∀ (ε : ax) → ⊢ (ax-ctx ε ∥ ax-lhs ε ≈ ax-rhs ε ⦂ (ax-sort ε))
eq-axiom-id ε = eq-tran id-action (eq-tran (eq-axiom ε id-s) (eq-symm id-action))
eq-setoid : ∀ (Γ : Context) (A : sort) → Setoid (lsuc ℴ) (lsuc (ℓ ⊔ ℴ ⊔ 𝓈))
eq-setoid Γ A =
record
{ Carrier = Term Γ A
; _≈_ = λ s t → (⊢ Γ ∥ s ≈ t ⦂ A)
; isEquivalence =
record
{ refl = eq-refl
; sym = eq-symm
; trans = eq-tran
}
}
| 33.096
| 131
| 0.519942
|
413af7f062c43503a6e90c17366d2a95f0b5bec7
| 5,067
|
agda
|
Agda
|
part1/isomorphism/Isomorphism.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | 1
|
2020-07-07T09:42:22.000Z
|
2020-07-07T09:42:22.000Z
|
part1/isomorphism/Isomorphism.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
part1/isomorphism/Isomorphism.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
module Isomorphism where
-- Imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; cong-app)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm)
-- Function composition (関数の合成)
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘ f) x = g (f x)
_∘′_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
g ∘′ f = λ x → g (f x)
-- Extensionality
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
_+′_ : ℕ → ℕ → ℕ
m +′ zero = m
m +′ suc n = suc (m +′ n)
same-app : ∀ (m n : ℕ) → m +′ n ≡ m + n
same-app m n rewrite +-comm m n = helper m n
where
helper : ∀ (m n : ℕ) → m +′ n ≡ n + m
helper m zero = refl
helper m (suc n) = cong suc (helper m n)
same : _+′_ ≡ _+_
same = extensionality (λ m → extensionality (λ n → same-app m n))
postulate
∀-extensionality : ∀ {A : Set} {B : A → Set} {f g : ∀(x : A) → B x}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- Isomorphism (同型)
infix 0 _≃_
record _≃_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
data _≃′_ (A B : Set): Set where
mk-≃′ : ∀ (to : A → B) →
∀ (from : B → A) →
∀ (from∘to : (∀ (x : A) → from (to x) ≡ x)) →
∀ (to∘from : (∀ (y : B) → to (from y) ≡ y)) →
A ≃′ B
to′ : ∀ {A B : Set} → (A ≃′ B) → (A → B)
to′ (mk-≃′ f g g∘f f∘g) = f
from′ : ∀ {A B : Set} → (A ≃′ B) → (B → A)
from′ (mk-≃′ f g g∘f f∘g) = g
from∘to′ : ∀ {A B : Set} → (A≃B : A ≃′ B) → (∀ (x : A) → from′ A≃B (to′ A≃B x) ≡ x)
from∘to′ (mk-≃′ f g g∘f f∘g) = g∘f
to∘from′ : ∀ {A B : Set} → (A≃B : A ≃′ B) → (∀ (y : B) → to′ A≃B (from′ A≃B y) ≡ y)
to∘from′ (mk-≃′ f g g∘f f∘g) = f∘g
-- Isomorphism is an equivalence
≃-refl : ∀ {A : Set}
-----
→ A ≃ A
≃-refl =
record
{ to = λ{x → x}
; from = λ{y → y}
; from∘to = λ{x → refl}
; to∘from = λ{y → refl}
}
≃-sym : ∀ {A B : Set}
→ A ≃ B
-----
→ B ≃ A
≃-sym A≃B =
record
{ to = from A≃B
; from = to A≃B
; from∘to = to∘from A≃B
; to∘from = from∘to A≃B
}
≃-trans : ∀ {A B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
≃-trans A≃B B≃C =
record
{ to = to B≃C ∘ to A≃B
; from = from A≃B ∘ from B≃C
; from∘to = λ{x →
begin
(from A≃B ∘ from B≃C) ((to B≃C ∘ to A≃B) x)
≡⟨⟩
from A≃B (from B≃C (to B≃C (to A≃B x)))
≡⟨ cong (from A≃B) (from∘to B≃C (to A≃B x)) ⟩
from A≃B (to A≃B x)
≡⟨ from∘to A≃B x ⟩
x
∎}
; to∘from = λ{y →
begin
(to B≃C ∘ to A≃B) ((from A≃B ∘ from B≃C) y)
≡⟨⟩
to B≃C (to A≃B (from A≃B (from B≃C y)))
≡⟨ cong (to B≃C) (to∘from A≃B (from B≃C y)) ⟩
to B≃C (from B≃C y)
≡⟨ to∘from B≃C y ⟩
y
∎}
}
-- Equational reasoning for isomorphism
module ≃-Reasoning where
infix 1 ≃-begin_
infixr 2 _≃⟨_⟩_
infix 3 _≃-∎
≃-begin_ : ∀ {A B : Set}
→ A ≃ B
-----
→ A ≃ B
≃-begin A≃B = A≃B
_≃⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
A ≃⟨ A≃B ⟩ B≃C = ≃-trans A≃B B≃C
_≃-∎ : ∀ (A : Set)
-----
→ A ≃ A
A ≃-∎ = ≃-refl
open ≃-Reasoning
-- Embedding (埋め込み)
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
≲-refl : ∀ {A : Set} → A ≲ A
≲-refl =
record
{ to = λ{x → x}
; from = λ{y → y}
; from∘to = λ{x → refl}
}
≲-trans : ∀ {A B C : Set} → A ≲ B → B ≲ C → A ≲ C
≲-trans A≲B B≲C =
record
{ to = λ{x → to B≲C (to A≲B x)}
; from = λ{y → from A≲B (from B≲C y)}
; from∘to = λ{x →
begin
from A≲B (from B≲C (to B≲C (to A≲B x)))
≡⟨ cong (from A≲B) (from∘to B≲C (to A≲B x)) ⟩
from A≲B (to A≲B x)
≡⟨ from∘to A≲B x ⟩
x
∎}
}
≲-antisym : ∀ {A B : Set}
→ (A≲B : A ≲ B)
→ (B≲A : B ≲ A)
→ (to A≲B ≡ from B≲A)
→ (from A≲B ≡ to B≲A)
-------------------
→ A ≃ B
≲-antisym A≲B B≲A to≡from from≡to =
record
{ to = to A≲B
; from = from A≲B
; from∘to = from∘to A≲B
; to∘from = λ{y →
begin
to A≲B (from A≲B y)
≡⟨ cong (to A≲B) (cong-app from≡to y) ⟩
to A≲B (to B≲A y)
≡⟨ cong-app to≡from (to B≲A y) ⟩
from B≲A (to B≲A y)
≡⟨ from∘to B≲A y ⟩
y
∎}
}
-- Equational reasoning for embedding
module ≲-Reasoning where
infix 1 ≲-begin_
infixr 2 _≲⟨_⟩_
infix 3 _≲-∎
≲-begin_ : ∀ {A B : Set}
→ A ≲ B
-----
→ A ≲ B
≲-begin A≲B = A≲B
_≲⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≲ B
→ B ≲ C
-----
→ A ≲ C
A ≲⟨ A≲B ⟩ B≲C = ≲-trans A≲B B≲C
_≲-∎ : ∀ (A : Set)
-----
→ A ≲ A
A ≲-∎ = ≲-refl
open ≲-Reasoning
| 20.681633
| 83
| 0.397474
|
3d7f7d61026b6666e15eb94fa57f7a988a00d2b9
| 3,914
|
agda
|
Agda
|
Structure/Operator/Monoid/Invertible/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Operator/Monoid/Invertible/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Operator/Monoid/Invertible/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Operator.Monoid.Invertible.Proofs where
import Data.Tuple as Tuple
import Lvl
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Operator
open import Structure.Operator.Monoid
open import Structure.Operator.Monoid.Invertible
open import Structure.Operator.Properties hiding (InverseOperatorₗ ; InverseOperatorᵣ)
open import Structure.Relator.Properties
open import Structure.Setoid
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₗ ℓₑ : Lvl.Level
private variable T : Type{ℓ}
private variable _▫_ : T → T → T
private variable _⨞_ : T → T → Type{ℓₗ}
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ ⦃ monoid : Monoid{T = T}(_▫_) ⦄ ⦃ invRel : InverseRelationᵣ(_▫_){ℓₗ}(_⨞_) ⦄ where
open Monoid(monoid) using (id)
instance
inverseRelationᵣ-reflexivity : Reflexivity(_⨞_)
Reflexivity.proof inverseRelationᵣ-reflexivity = [↔]-to-[←] (InverseRelationᵣ.proof invRel) ([∃]-intro id ⦃ identityᵣ(_▫_)(id) ⦄)
instance
inverseRelationᵣ-transitivity : Transitivity(_⨞_)
Transitivity.proof inverseRelationᵣ-transitivity xy yz
with [∃]-intro a ⦃ pa ⦄ ← [↔]-to-[→] (InverseRelationᵣ.proof invRel) xy
with [∃]-intro b ⦃ pb ⦄ ← [↔]-to-[→] (InverseRelationᵣ.proof invRel) yz
= [↔]-to-[←] (InverseRelationᵣ.proof invRel) ([∃]-intro (a ▫ b) ⦃ symmetry(_≡_) (associativity(_▫_)) 🝖 congruence₂ₗ(_▫_)(b) pa 🝖 pb ⦄)
inverseRelationᵣ-with-opᵣ : ∀{a x y} → (x ⨞ y) → ((a ▫ x) ⨞ (a ▫ y))
inverseRelationᵣ-with-opᵣ {a}{x}{y} xy
with [∃]-intro z ⦃ xzy ⦄ ← [↔]-to-[→] (InverseRelationᵣ.proof invRel) xy
= [↔]-to-[←] (InverseRelationᵣ.proof invRel) ([∃]-intro z ⦃ associativity(_▫_) 🝖 congruence₂ᵣ(_▫_)(a) xzy ⦄)
inverseRelationᵣ-without-opᵣ : ⦃ cancₗ : Cancellationₗ(_▫_) ⦄ → ∀{a x y} → ((a ▫ x) ⨞ (a ▫ y)) → (x ⨞ y)
inverseRelationᵣ-without-opᵣ {a}{x}{y} xy
with [∃]-intro z ⦃ xzy ⦄ ← [↔]-to-[→] (InverseRelationᵣ.proof invRel) xy
= [↔]-to-[←] (InverseRelationᵣ.proof invRel) ([∃]-intro z ⦃ cancellationₗ(_▫_) (symmetry(_≡_) (associativity(_▫_)) 🝖 xzy) ⦄)
inverseRelationᵣ-of-idₗ : ∀{x} → (id ⨞ x)
inverseRelationᵣ-of-idₗ {x} = [↔]-to-[←] (InverseRelationᵣ.proof invRel) ([∃]-intro x ⦃ identityₗ(_▫_)(id) ⦄)
module _ {_⋄_ : (x : T) → (y : T) → . ⦃ inv : (y ⨞ x) ⦄ → T} ⦃ invOper : InverseOperatorᵣ(_▫_)(_⋄_) ⦄ where
{-op-cancellationᵣ : ∀{a x y} → (a ⨞ x) → (a ⨞ y) → (a ▫ x ≡ a ▫ y) → (x ≡ y)
op-cancellationᵣ {a}{x}{y} ax ay axay
with [∃]-intro r ⦃ pr ⦄ ← [↔]-to-[→] (InverseRelationᵣ.proof invRel) ax
with [∃]-intro s ⦃ ps ⦄ ← [↔]-to-[→] (InverseRelationᵣ.proof invRel) ay
=
x 🝖[ _≡_ ]-[ {!!} ]
y 🝖-end-}
inverseRelationᵣ-to-invertibleᵣ : ∀{x} → ⦃ x ⨞ id ⦄ → InvertibleElementᵣ(_▫_) ⦃ Monoid.identity-existenceᵣ(monoid) ⦄ (x)
inverseRelationᵣ-to-invertibleᵣ {x} ⦃ xid ⦄ = [∃]-intro (id ⋄ x) ⦃ intro p ⦄ where
p =
(x ▫ (id ⋄ x)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_▫_)(x) (InverseOperatorᵣ.proof invOper {id}{x}) ]
(x ▫ [∃]-witness([↔]-to-[→] (InverseRelationᵣ.proof invRel) xid)) 🝖[ _≡_ ]-[ [∃]-proof([↔]-to-[→] (InverseRelationᵣ.proof invRel) xid) ]
id 🝖-end
{- TODO: Should this not be possible without cancellation?
inverseOperator-self : ∀{x} → let instance _ = reflexivity(_⨞_) in (x ⋄ x ≡ id)
inverseOperator-self {x} = let instance _ = reflexivity(_⨞_) {x} in
(x ⋄ x) 🝖[ _≡_ ]-[ InverseOperatorᵣ.proof invOper {x}{x} ]
[∃]-witness([↔]-to-[→] (InverseRelationᵣ.proof invRel) (reflexivity(_⨞_) {x})) 🝖[ _≡_ ]-[]
∃.witness(Tuple.right(InverseRelationᵣ.proof invRel) (reflexivity(_⨞_))) 🝖[ _≡_ ]-[ {!!} ]
id 🝖-end
-}
| 54.361111
| 148
| 0.573838
|
415776b728e896003e5b35d8eb1b124242f1c096
| 4,121
|
agda
|
Agda
|
Formalization/PredicateLogic/Minimal/NaturalDeduction.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Formalization/PredicateLogic/Minimal/NaturalDeduction.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Formalization/PredicateLogic/Minimal/NaturalDeduction.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Formalization.PredicateLogic.Signature
module Formalization.PredicateLogic.Minimal.NaturalDeduction (𝔏 : Signature) where
open Signature(𝔏)
open import Data.ListSized
import Lvl
open import Formalization.PredicateLogic.Syntax(𝔏)
open import Formalization.PredicateLogic.Syntax.Substitution(𝔏)
open import Functional using (_∘_ ; _∘₂_ ; swap)
open import Numeral.Finite
open import Numeral.Natural
open import Relator.Equals.Proofs.Equiv
open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to · ; _≡_ to _≡ₛ_)
open import Type
private variable ℓ : Lvl.Level
private variable args vars : ℕ
private variable Γ : PredSet{ℓ}(Formula(vars))
data _⊢_ {ℓ} : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type{Lvl.𝐒(ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ ℓ)} where
direct : (Γ ⊆ (Γ ⊢_))
[⊤]-intro : (Γ ⊢ ⊤)
[∧]-intro : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ ψ) → (Γ ⊢ (φ ∧ ψ))
[∧]-elimₗ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ φ)
[∧]-elimᵣ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ ψ)
[∨]-introₗ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ∨ ψ))
[∨]-introᵣ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ∨ ψ))
[∨]-elim : ∀{φ ψ χ} → ((Γ ∪ · φ) ⊢ χ) → ((Γ ∪ · ψ) ⊢ χ) → (Γ ⊢ (φ ∨ ψ)) → (Γ ⊢ χ)
[⟶]-intro : ∀{φ ψ} → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟶ ψ))
[⟶]-elim : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟶ ψ)) → (Γ ⊢ ψ)
[Ɐ]-intro : ∀{φ} → (∀{t} → (Γ ⊢ (substitute0 t φ))) → (Γ ⊢ (Ɐ φ))
[Ɐ]-elim : ∀{φ} → (Γ ⊢ (Ɐ φ)) → ∀{t} → (Γ ⊢ (substitute0 t φ))
[∃]-intro : ∀{φ}{t} → (Γ ⊢ (substitute0 t φ)) → (Γ ⊢ (∃ φ))
[∃]-elim : ∀{φ ψ} → (∀{t} → (Γ ∪ ·(substitute0 t φ)) ⊢ ψ) → (Γ ⊢ (∃ φ)) → (Γ ⊢ ψ)
module _ where
open import Data.Either as Either
import Logic.Propositional as Meta
open import Relator.Equals
private variable Γ₁ Γ₂ : PredSet{ℓ}(Formula(vars))
private variable φ ψ : Formula(vars)
_⊬_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type
_⊬_ = Meta.¬_ ∘₂ (_⊢_)
[⟵]-intro : ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (ψ ⟵ φ))
[⟵]-intro = [⟶]-intro
[⟵]-elim : (Γ ⊢ φ) → (Γ ⊢ (ψ ⟵ φ)) → (Γ ⊢ ψ)
[⟵]-elim = [⟶]-elim
[¬]-intro : ((Γ ∪ · φ) ⊢ ⊥) → (Γ ⊢ (¬ φ))
[¬]-intro = [⟶]-intro
[⟷]-intro : ∀{φ ψ} → ((Γ ∪ · ψ) ⊢ φ) → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟷ ψ))
[⟷]-intro l r = [∧]-intro ([⟶]-intro l) ([⟶]-intro r)
[⟷]-elimₗ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ φ)
[⟷]-elimₗ Γψ Γφψ = [⟶]-elim Γψ ([∧]-elimₗ Γφψ)
[⟷]-elimᵣ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ ψ)
[⟷]-elimᵣ Γφ Γφψ = [⟶]-elim Γφ ([∧]-elimᵣ Γφψ)
weaken-union-singleton : (Γ₁ ⊆ Γ₂) → (((Γ₁ ∪ · φ) ⊢_) ⊆ ((Γ₂ ∪ · φ) ⊢_))
weaken : (Γ₁ ⊆ Γ₂) → ((Γ₁ ⊢_) ⊆ (Γ₂ ⊢_))
weaken Γ₁Γ₂ {φ} (direct p) = direct (Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.⊤} [⊤]-intro = [⊤]-intro
weaken Γ₁Γ₂ {.(_ ∧ _)} ([∧]-intro p q) = [∧]-intro (weaken Γ₁Γ₂ p) (weaken Γ₁Γ₂ q)
weaken Γ₁Γ₂ {φ} ([∧]-elimₗ p) = [∧]-elimₗ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([∧]-elimᵣ p) = [∧]-elimᵣ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(_ ∨ _)} ([∨]-introₗ p) = [∨]-introₗ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(_ ∨ _)} ([∨]-introᵣ p) = [∨]-introᵣ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([∨]-elim p q r) = [∨]-elim (weaken-union-singleton Γ₁Γ₂ p) (weaken-union-singleton Γ₁Γ₂ q) (weaken Γ₁Γ₂ r)
weaken Γ₁Γ₂ {.(_ ⟶ _)} ([⟶]-intro p) = [⟶]-intro (weaken-union-singleton Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([⟶]-elim p q) = [⟶]-elim (weaken Γ₁Γ₂ p) (weaken Γ₁Γ₂ q)
weaken Γ₁Γ₂ {.(Ɐ _)} ([Ɐ]-intro p) = [Ɐ]-intro (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(substitute0 _ _)} ([Ɐ]-elim p) = [Ɐ]-elim (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(∃ _)} ([∃]-intro p) = [∃]-intro (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([∃]-elim p q) = [∃]-elim (weaken-union-singleton Γ₁Γ₂ p) (weaken Γ₁Γ₂ q)
weaken-union-singleton Γ₁Γ₂ p = weaken (Either.mapLeft Γ₁Γ₂) p
weaken-union : (Γ₁ ⊢_) ⊆ ((Γ₁ ∪ Γ₂) ⊢_)
weaken-union = weaken Left
[¬¬]-intro : (Γ ⊢ φ) → (Γ ⊢ ¬(¬ φ))
[¬¬]-intro Γφ =
([¬]-intro
([⟶]-elim
(weaken-union Γφ)
(direct (Right [≡]-intro))
)
)
| 40.401961
| 151
| 0.480466
|
1d91fa367834b689f0ea766eb6090e862f8469b0
| 649
|
agda
|
Agda
|
test/Succeed/RewritingRuleInParametrizedModule.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/RewritingRuleInParametrizedModule.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/RewritingRuleInParametrizedModule.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2015-08-27 Rewrite rules in parametrized modules are fine.
-- Jesper, 2015-10-14 Semantics of rewrite rules in parametrized modules has
-- changed (see issue 1652)
-- Jesper, 2015-11-9 Rewrite rules in parametrized modules are now
-- generalized to the top-context automatically
{-# OPTIONS --rewriting #-}
open import Common.Nat
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
module _ (y z : Nat) where
assoc+ : ∀ x → (x + y) + z ≡ x + (y + z)
assoc+ zero = refl
assoc+ (suc x) rewrite assoc+ x = refl
{-# REWRITE assoc+ #-}
test : ∀{x y} → (x + 0) + y ≡ x + y
test = refl
| 27.041667
| 76
| 0.616333
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.