Skip to content

Commit a126e3f

Browse files
authored
a few minor utility functions (#1174)
1 parent 76f5e6a commit a126e3f

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

Cubical/Data/Bool/Properties.agda

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,19 @@ Iso.leftInv Iso-Bool→∙Bool-Bool f = Σ≡Prop (λ _ → isSetBool _ _) (help
427427
; true (λ j Bool→Bool→∙Bool (p j) .fst true) ∙ sym (snd f)}
428428
help true p = (λ j Bool→Bool→∙Bool (p j) .fst)
429429
∙ funExt λ { false sym p ; true sym (snd f)}
430+
431+
ΣBool : (b : Bool) (c : (Bool→Type b) Bool) Bool
432+
ΣBool false c = false
433+
ΣBool true c = c tt
434+
435+
ΣBoolΣIso : {b : Bool} {c : (Bool→Type b) Bool}
436+
Iso (Bool→Type (ΣBool b c)) (Σ[ z ∈ Bool→Type b ] Bool→Type (c z))
437+
438+
Iso.fun (ΣBoolΣIso {true}) x = tt , x
439+
Iso.inv (ΣBoolΣIso {true}) x = snd x
440+
Iso.leftInv (ΣBoolΣIso {true}) _ = refl
441+
Iso.rightInv (ΣBoolΣIso {true}) _ = refl
442+
443+
ΣBool≃Σ : {b : Bool} {c : (Bool→Type b) Bool}
444+
(Bool→Type (ΣBool b c)) ≃ (Σ[ z ∈ Bool→Type b ] Bool→Type (c z))
445+
ΣBool≃Σ = isoToEquiv ΣBoolΣIso

Cubical/Data/List/FinData.agda

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ module Cubical.Data.List.FinData where
33

44
open import Cubical.Foundations.Prelude
55
open import Cubical.Foundations.Function
6+
open import Cubical.Foundations.Equiv
7+
open import Cubical.Foundations.Isomorphism
68
open import Cubical.Data.List
79
open import Cubical.Data.FinData
810
open import Cubical.Data.Empty as ⊥
11+
open import Cubical.Data.Sigma.Properties
912
open import Cubical.Data.Nat
1013

1114
variable
@@ -34,6 +37,18 @@ lookup-tabulate : ∀ n → (^a : Fin n → A)
3437
lookup-tabulate (suc n) ^a i zero = ^a zero
3538
lookup-tabulate (suc n) ^a i (suc p) = lookup-tabulate n (^a ∘ suc) i p
3639

40+
open Iso
41+
42+
lookup-tabulate-iso : (A : Type ℓ) Iso (List A) (Σ[ n ∈ ℕ ] (Fin n A))
43+
fun (lookup-tabulate-iso A) xs = (length xs) , lookup xs
44+
inv (lookup-tabulate-iso A) (n , f) = tabulate n f
45+
leftInv (lookup-tabulate-iso A) = tabulate-lookup
46+
rightInv (lookup-tabulate-iso A) (n , f) =
47+
ΣPathP ((length-tabulate n f) , lookup-tabulate n f)
48+
49+
lookup-tabulate-equiv : (A : Type ℓ) List A ≃ (Σ[ n ∈ ℕ ] (Fin n A))
50+
lookup-tabulate-equiv A = isoToEquiv (lookup-tabulate-iso A)
51+
3752
lookup-map : (f : A B) (xs : List A)
3853
(p0 : Fin (length (map f xs)))
3954
(p1 : Fin (length xs))

Cubical/HITs/Nullification/Properties.agda

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open isPathSplitEquiv
2828

2929
private
3030
variable
31-
ℓα ℓs ℓ ℓ' : Level
31+
ℓα ℓs ℓ ℓ' ℓ'' : Level
3232
A : Type ℓα
3333
S : A Type ℓs
3434
X : Type ℓ
@@ -250,3 +250,29 @@ secCong (SeparatedAndInjective→Null X sep inj α) x y =
250250
fst s ∘ funExt⁻ , λ p i j α snd s (funExt⁻ p) i α j
251251
where
252252
s = sec (sep x y α)
253+
254+
generatorsConnected : {A : Type ℓα} (S : A Type ℓ)
255+
(a : A) isContr (Null S (S a))
256+
generatorsConnected S a = (hub a ∣_∣) ,
257+
elim (λ _ isNull≡ (isNull-Null S)) (spoke a ∣_∣)
258+
259+
nullMap : {A : Type ℓα} (S : A Type ℓ)
260+
{X : Type ℓ'} {Y : Type ℓ''} (X Y) Null S X Null S Y
261+
nullMap S f ∣ x ∣ = ∣ f x ∣
262+
nullMap S f (hub α g) = hub α (λ z nullMap S f (g z))
263+
nullMap S f (spoke α g s i) = spoke α (λ z nullMap S f (g z)) s i
264+
nullMap S f (≡hub p i) = ≡hub (λ z j nullMap S f (p z j)) i
265+
nullMap S f (≡spoke p s i i₁) = ≡spoke (λ z j nullMap S f (p z j)) s i i₁
266+
267+
nullPreservesIso : {A : Type ℓα} (S : A Type ℓ) {X : Type ℓ'}
268+
{Y : Type ℓ''} Iso X Y Iso (Null S X) (Null S Y)
269+
Iso.fun (nullPreservesIso S e) = nullMap S (Iso.fun e)
270+
Iso.inv (nullPreservesIso S e) = nullMap S (Iso.inv e)
271+
Iso.leftInv (nullPreservesIso S e) =
272+
elim (λ _ isNull≡ (isNull-Null S)) (λ x cong ∣_∣ (Iso.leftInv e x))
273+
Iso.rightInv (nullPreservesIso S e) =
274+
elim (λ _ isNull≡ (isNull-Null S)) (λ y cong ∣_∣ (Iso.rightInv e y))
275+
276+
nullPreservesEquiv : {A : Type ℓα} (S : A Type ℓ) {X : Type ℓ'}
277+
{Y : Type ℓ''} X ≃ Y Null S X ≃ Null S Y
278+
nullPreservesEquiv S {X = X} {Y = Y} e = isoToEquiv (nullPreservesIso S (equivToIso e))

Cubical/Relation/Nullary/Properties.agda

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open import Cubical.HITs.PropositionalTruncation.Base
2424

2525
private
2626
variable
27-
: Level
27+
ℓ' : Level
2828
A B : Type ℓ
2929
P : A -> Type ℓ
3030

@@ -62,6 +62,13 @@ Stable× As Bs e = λ where
6262
.fst As λ k e (k ∘ fst)
6363
.snd Bs λ k e (k ∘ snd)
6464

65+
StableΣ : {A : Type ℓ} {P : A Type ℓ'}
66+
Stable A isProp A ((a : A) Stable (P a)) Stable (Σ A P)
67+
StableΣ {P = P} As Aprop Ps e =
68+
let a = (As (λ notA e (λ (a , _) notA a))) in
69+
a ,
70+
Ps a λ notPa e (λ (a' , p) notPa (subst P (Aprop a' a) p))
71+
6572
fromYes : A Dec A A
6673
fromYes _ (yes a) = a
6774
fromYes a (no _) = a

0 commit comments

Comments
 (0)