Skip to content

Commit 0420f86

Browse files
authored
Various functions that I found useful (#951)
* added various functions that I found useful * allow multiple universe levels in definition of JDep * remove unecessary implicit arguments from JDep
1 parent dbe0176 commit 0420f86

File tree

9 files changed

+93
-2
lines changed

9 files changed

+93
-2
lines changed

Cubical/Data/Nat/Order.agda

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,15 @@ min-≤-right {suc m} {suc n} = suc-≤-suc min-≤-right
252252
... | yes m≤n = yes (suc-≤-suc m≤n)
253253
... | no m≰n = no λ m+1≤n+1 m≰n (pred-≤-pred m+1≤n+1 )
254254

255+
≤Stable : m n Stable (m ≤ n)
256+
≤Stable m n = Dec→Stable (≤Dec m n)
257+
255258
<Dec : m n Dec (m < n)
256259
<Dec m n = ≤Dec (suc m) n
257260

261+
<Stable : m n Stable (m < n)
262+
<Stable m n = Dec→Stable (<Dec m n)
263+
258264
Trichotomy-suc : Trichotomy m n Trichotomy (suc m) (suc n)
259265
Trichotomy-suc (lt m<n) = lt (suc-≤-suc m<n)
260266
Trichotomy-suc (eq m=n) = eq (cong suc m=n)

Cubical/Data/Nat/Properties.agda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ discreteℕ (suc m) (suc n) with discreteℕ m n
127127
... | yes p = yes (cong suc p)
128128
... | no p = no (λ x p (injSuc x))
129129

130+
separatedℕ : Separated ℕ
131+
separatedℕ = Discrete→Separated discreteℕ
132+
130133
isSetℕ : isSet ℕ
131134
isSetℕ = Discrete→isSet discreteℕ
132135

Cubical/Data/Sigma/Properties.agda

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,13 @@ module _
446446

447447
fiberProjEquiv : B a ≃ fiber proj a
448448
fiberProjEquiv = isoToEquiv fiberProjIso
449+
450+
separatedΣ : Separated A ((a : A) Separated (B a)) Separated (Σ A B)
451+
separatedΣ {B = B} sepA sepB (a , b) (a' , b') p = ΣPathTransport→PathΣ _ _ (pA , pB)
452+
where
453+
pA : a ≡ a'
454+
pA = sepA a a' (λ q p (λ r q (cong fst r)))
455+
456+
pB : subst B pA b ≡ b'
457+
pB = sepB _ _ _ (λ q p (λ r q (cong (λ r' subst B r' b)
458+
(Separated→isSet sepA _ _ pA (cong fst r)) ∙ snd (PathΣ→ΣPathTransport _ _ r))))

Cubical/Data/Sum/Properties.agda

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ open import Cubical.Foundations.Isomorphism
1010
open import Cubical.Data.Empty
1111
open import Cubical.Data.Nat
1212
open import Cubical.Data.Sigma
13+
open import Cubical.Relation.Nullary
1314

1415
open import Cubical.Data.Sum.Base
1516

@@ -107,6 +108,14 @@ isGroupoid⊎ = isOfHLevel⊎ 1
107108
is2Groupoid⊎ : is2Groupoid A is2Groupoid B is2Groupoid (A ⊎ B)
108109
is2Groupoid⊎ = isOfHLevel⊎ 2
109110

111+
discrete⊎ : Discrete A Discrete B Discrete (A ⊎ B)
112+
discrete⊎ decA decB (inl a) (inl a') =
113+
mapDec (cong inl) (λ p q p (isEmbedding→Inj isEmbedding-inl _ _ q)) (decA a a')
114+
discrete⊎ decA decB (inl a) (inr b') = no (λ p lower (⊎Path.encode (inl a) (inr b') p))
115+
discrete⊎ decA decB (inr b) (inl a') = no ((λ p lower (⊎Path.encode (inr b) (inl a') p)))
116+
discrete⊎ decA decB (inr b) (inr b') =
117+
mapDec (cong inr) (λ p q p (isEmbedding→Inj isEmbedding-inr _ _ q)) (decB b b')
118+
110119
⊎Iso : Iso A C Iso B D Iso (A ⊎ B) (C ⊎ D)
111120
fun (⊎Iso iac ibd) (inl x) = inl (iac .fun x)
112121
fun (⊎Iso iac ibd) (inr x) = inr (ibd .fun x)

Cubical/Foundations/HLevels.agda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ isGroupoidHSet = isOfHLevelTypeOfHLevel 2
576576
isOfHLevelLift : {ℓ ℓ'} (n : HLevel) {A : Type ℓ} isOfHLevel n A isOfHLevel n (Lift {j = ℓ'} A)
577577
isOfHLevelLift n = isOfHLevelRetract n lower lift λ _ refl
578578

579+
isOfHLevelLower : {ℓ ℓ'} (n : HLevel) {A : Type ℓ} isOfHLevel n (Lift {j = ℓ'} A) isOfHLevel n A
580+
isOfHLevelLower n = isOfHLevelRetract n lift lower λ _ refl
581+
579582
----------------------------
580583

581584
-- More consequences of isProp and isContr

Cubical/Foundations/Prelude.agda

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
347347

348348
-- Multi-variable versions of J
349349

350-
module _ {x : A}
351-
{B : A Type ℓ''} {b : B x}
350+
module _ {b : B x}
352351
(P : (y : A) (p : x ≡ y) (z : B y) (q : PathP (λ i B (p i)) b z) Type ℓ'')
353352
(d : P _ refl _ refl) where
354353

Cubical/HITs/Nullification/Properties.agda

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ open import Cubical.Foundations.Equiv
1010
open import Cubical.Foundations.Equiv.PathSplit
1111
open import Cubical.Foundations.Equiv.Properties
1212
open import Cubical.Foundations.Univalence
13+
open import Cubical.Functions.FunExtEquiv
1314

1415
open import Cubical.Modalities.Modality
1516

@@ -22,6 +23,34 @@ open import Cubical.HITs.Nullification.Base
2223
open Modality
2324
open isPathSplitEquiv
2425

26+
private
27+
variable
28+
ℓα ℓs ℓ ℓ' : Level
29+
30+
isNull≡ : {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ} (nX : isNull S X) {x y : X} isNull S (x ≡ y)
31+
isNull≡ {A = A} {S = S} nX {x = x} {y = y} α =
32+
fromIsEquiv (λ p _ i p i)
33+
(isEquiv[equivFunA≃B∘f]→isEquiv[f] (λ p _ p) funExtEquiv (isEquivCong (const , toIsEquiv _ (nX α))))
34+
35+
isNullΠ : {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ} {Y : X Type ℓ'} ((x : X) isNull S (Y x))
36+
isNull S ((x : X) Y x)
37+
isNullΠ {S = S} {X = X} {Y = Y} nY α = fromIsEquiv _ (snd e)
38+
where
39+
flipIso : Iso ((x : X) S α Y x) (S α (x : X) Y x)
40+
Iso.fun flipIso f = flip f
41+
Iso.inv flipIso f = flip f
42+
Iso.rightInv flipIso f = refl
43+
Iso.leftInv flipIso f = refl
44+
45+
e : ((x : X) Y x) ≃ (S α ((x : X) Y x))
46+
e =
47+
((x : X) Y x)
48+
≃⟨ equivΠCod (λ x const , (toIsEquiv _ (nY x α))) ⟩
49+
((x : X) (S α Y x))
50+
≃⟨ isoToEquiv flipIso ⟩
51+
(S α ((x : X) Y x))
52+
53+
2554
rec : {ℓα ℓs ℓ ℓ'} {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ} {Y : Type ℓ'}
2655
(nB : isNull S Y) (X Y) Null S X Y
2756
rec nB g ∣ x ∣ = g x
@@ -83,6 +112,26 @@ module _ {ℓα ℓs ℓ ℓ'} {A : Type ℓα} {S : A → Type ℓs} {X : Type
83112
(λ i elim nY g (p s i))
84113
q₂ j i = toPathP⁻ (λ j Y (≡spoke p s j i)) (λ j q₁ j i) j
85114

115+
NullRecIsPathSplitEquiv : {ℓα ℓs ℓ ℓ'} {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ} {Y : Type ℓ'} (isNull S Y)
116+
isPathSplitEquiv {A = (Null S X) Y} (λ f f ∘ ∣_∣)
117+
sec (NullRecIsPathSplitEquiv nY) = rec nY , λ _ refl
118+
secCong (NullRecIsPathSplitEquiv nY) f f' = (λ p funExt (elim (λ _ isNull≡ nY) (funExt⁻ p))) , λ _ refl
119+
120+
NullRecIsEquiv : {ℓα ℓs ℓ ℓ'} {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ} {Y : Type ℓ'} (isNull S Y)
121+
isEquiv {A = (Null S X) Y} (λ f f ∘ ∣_∣)
122+
NullRecIsEquiv nY = toIsEquiv _ (NullRecIsPathSplitEquiv nY)
123+
124+
NullRecEquiv : {ℓα ℓs ℓ ℓ'} {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ} {Y : Type ℓ'} (isNull S Y)
125+
((Null S X) Y) ≃ (X Y)
126+
NullRecEquiv nY = (λ f f ∘ ∣_∣) , (NullRecIsEquiv nY)
127+
128+
129+
NullPreservesProp : {ℓα ℓs ℓ} {A : Type ℓα} {S : A Type ℓs} {X : Type ℓ}
130+
(isProp X) isProp (Null S X)
131+
132+
NullPreservesProp {S = S} pX u = elim (λ v' isNull≡ (isNull-Null S))
133+
(λ y elim (λ u' isNull≡ (isNull-Null S) {x = u'}) (λ x cong ∣_∣ (pX x y)) u)
134+
86135
-- nullification is a modality
87136

88137
NullModality : {ℓα ℓs ℓ} {A : Type ℓα} (S : A Type ℓs) Modality (ℓ-max ℓ (ℓ-max ℓα ℓs))

Cubical/Modalities/Modality.agda

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open import Cubical.Foundations.Isomorphism
1212
open import Cubical.Foundations.Equiv
1313
open import Cubical.Foundations.Univalence
1414
open import Cubical.Foundations.Structure
15+
open import Cubical.Foundations.Equiv.Properties
1516

1617
record Modality: Type (ℓ-suc ℓ) where
1718
field
@@ -158,3 +159,10 @@ record Modality ℓ : Type (ℓ-suc ℓ) where
158159

159160
r : (x : Σ A B) η-inv (η x) ≡ x
160161
r x = (λ i h (η x) , p x i) ∙ (almost x)
162+
163+
isModal≡ : {A : Type ℓ} (isModal A) {x y : A} (isModal (x ≡ y))
164+
isModal≡ A-modal = equivPreservesIsModal (invEquiv (congEquiv (η , (isModalToIsEquiv A-modal)))) (◯-=-isModal _ _)
165+
166+
◯-preservesProp : {A : Type ℓ} (isProp A) (isProp (◯ A))
167+
◯-preservesProp pA u = ◯-elim (λ z ◯-=-isModal _ _)
168+
λ b ◯-elim (λ x ◯-=-isModal _ _) (λ a cong η (pA a b)) u

Cubical/Relation/Nullary/Base.agda

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ data Dec (P : Type ℓ) : Type ℓ where
2424
yes : ( p : P) Dec P
2525
no : (¬p : ¬ P) Dec P
2626

27+
decRec : {ℓ ℓ'} {P : Type ℓ} {A : Type ℓ'} (P A) (¬ P A) (Dec P) A
28+
decRec ifyes ifno (yes p) = ifyes p
29+
decRec ifyes ifno (no ¬p) = ifno ¬p
30+
2731
NonEmpty : Type ℓ Type ℓ
2832
NonEmpty A = ¬ ¬ A
2933

0 commit comments

Comments
 (0)