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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cc8932b22116c74df0ffdfb37de389a0ba38d6fa
| 10,821
|
agda
|
Agda
|
Cubical/HITs/Rationals/QuoQ/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/Rationals/QuoQ/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/Rationals/QuoQ/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Rationals.QuoQ.Properties where
open import Cubical.Foundations.Everything hiding (_⁻¹)
open import Cubical.Data.Int.MoreInts.QuoInt as ℤ using (ℤ; Sign; signed; pos; neg; posneg; sign)
open import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_)
open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc)
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Sigma
open import Cubical.Data.Sum
open import Cubical.Relation.Nullary
open import Cubical.HITs.Rationals.QuoQ.Base
ℚ-cancelˡ : ∀ {a b} (c : ℕ₊₁) → [ ℕ₊₁→ℤ c ℤ.· a / c ·₊₁ b ] ≡ [ a / b ]
ℚ-cancelˡ {a} {b} c = eq/ _ _
(cong (ℤ._· ℕ₊₁→ℤ b) (ℤ.·-comm (ℕ₊₁→ℤ c) a) ∙ sym (ℤ.·-assoc a (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)))
ℚ-cancelʳ : ∀ {a b} (c : ℕ₊₁) → [ a ℤ.· ℕ₊₁→ℤ c / b ·₊₁ c ] ≡ [ a / b ]
ℚ-cancelʳ {a} {b} c = eq/ _ _
(sym (ℤ.·-assoc a (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)) ∙ cong (a ℤ.·_) (ℤ.·-comm (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)))
-- useful functions for defining operations on ℚ
onCommonDenom :
(g : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ)
(g-eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)
→ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) ≡ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)))
(g-eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)
→ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d)
→ ℚ → ℚ → ℚ
onCommonDenom g g-eql g-eqr = SetQuotient.rec2 isSetℚ
(λ { (a , b) (c , d) → [ g (a , b) (c , d) / b ·₊₁ d ] })
(λ { (a , b) (c , d) (e , f) p → eql (a , b) (c , d) (e , f) p })
(λ { (a , b) (c , d) (e , f) p → eqr (a , b) (c , d) (e , f) p })
where eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)
→ [ g (a , b) (e , f) / b ·₊₁ f ] ≡ [ g (c , d) (e , f) / d ·₊₁ f ]
eql (a , b) (c , d) (e , f) p =
[ g (a , b) (e , f) / b ·₊₁ f ]
≡⟨ sym (ℚ-cancelˡ d) ⟩
[ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / d ·₊₁ (b ·₊₁ f) ]
≡[ i ]⟨ [ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / ·₊₁-assoc d b f i ] ⟩
[ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / (d ·₊₁ b) ·₊₁ f ]
≡[ i ]⟨ [ g-eql (a , b) (c , d) (e , f) p i / ·₊₁-comm d b i ·₊₁ f ] ⟩
[ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / (b ·₊₁ d) ·₊₁ f ]
≡[ i ]⟨ [ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / ·₊₁-assoc b d f (~ i) ] ⟩
[ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / b ·₊₁ (d ·₊₁ f) ]
≡⟨ ℚ-cancelˡ b ⟩
[ g (c , d) (e , f) / d ·₊₁ f ] ∎
eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)
→ [ g (a , b) (c , d) / b ·₊₁ d ] ≡ [ g (a , b) (e , f) / b ·₊₁ f ]
eqr (a , b) (c , d) (e , f) p =
[ g (a , b) (c , d) / b ·₊₁ d ]
≡⟨ sym (ℚ-cancelʳ f) ⟩
[ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / (b ·₊₁ d) ·₊₁ f ]
≡[ i ]⟨ [ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / ·₊₁-assoc b d f (~ i) ] ⟩
[ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / b ·₊₁ (d ·₊₁ f) ]
≡[ i ]⟨ [ g-eqr (a , b) (c , d) (e , f) p i / b ·₊₁ ·₊₁-comm d f i ] ⟩
[ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / b ·₊₁ (f ·₊₁ d) ]
≡[ i ]⟨ [ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / ·₊₁-assoc b f d i ] ⟩
[ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / (b ·₊₁ f) ·₊₁ d ]
≡⟨ ℚ-cancelʳ d ⟩
[ g (a , b) (e , f) / b ·₊₁ f ] ∎
onCommonDenomSym :
(g : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ)
(g-sym : ∀ x y → g x y ≡ g y x)
(g-eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)
→ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) ≡ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)))
→ ℚ → ℚ → ℚ
onCommonDenomSym g g-sym g-eql = onCommonDenom g g-eql q-eqr
where q-eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)
→ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d
q-eqr (a , b) (c , d) (e , f) p =
(g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡[ i ]⟨ ℤ.·-comm (g-sym (a , b) (c , d) i) (ℕ₊₁→ℤ f) i ⟩
ℕ₊₁→ℤ f ℤ.· (g (c , d) (a , b)) ≡⟨ g-eql (c , d) (e , f) (a , b) p ⟩
ℕ₊₁→ℤ d ℤ.· (g (e , f) (a , b)) ≡[ i ]⟨ ℤ.·-comm (ℕ₊₁→ℤ d) (g-sym (e , f) (a , b) i) i ⟩
(g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d ∎
onCommonDenomSym-comm : ∀ {g} g-sym {g-eql} (x y : ℚ)
→ onCommonDenomSym g g-sym g-eql x y ≡
onCommonDenomSym g g-sym g-eql y x
onCommonDenomSym-comm g-sym = SetQuotient.elimProp2 (λ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) i → [ g-sym (a , b) (c , d) i / ·₊₁-comm b d i ] })
-- basic arithmetic operations on ℚ
infixl 6 _+_
infixl 7 _·_
private
lem₁ : ∀ a b c d e (p : a ℤ.· b ≡ c ℤ.· d) → b ℤ.· (a ℤ.· e) ≡ d ℤ.· (c ℤ.· e)
lem₁ a b c d e p = ℤ.·-assoc b a e
∙ cong (ℤ._· e) (ℤ.·-comm b a ∙ p ∙ ℤ.·-comm c d)
∙ sym (ℤ.·-assoc d c e)
lem₂ : ∀ a b c → a ℤ.· (b ℤ.· c) ≡ c ℤ.· (b ℤ.· a)
lem₂ a b c = cong (a ℤ.·_) (ℤ.·-comm b c) ∙ ℤ.·-assoc a c b
∙ cong (ℤ._· b) (ℤ.·-comm a c) ∙ sym (ℤ.·-assoc c a b)
∙ cong (c ℤ.·_) (ℤ.·-comm a b)
_+_ : ℚ → ℚ → ℚ
_+_ = onCommonDenomSym
(λ { (a , b) (c , d) → a ℤ.· (ℕ₊₁→ℤ d) ℤ.+ c ℤ.· (ℕ₊₁→ℤ b) })
(λ { (a , b) (c , d) → ℤ.+-comm (a ℤ.· (ℕ₊₁→ℤ d)) (c ℤ.· (ℕ₊₁→ℤ b)) })
(λ { (a , b) (c , d) (e , f) p →
ℕ₊₁→ℤ d ℤ.· (a ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ b)
≡⟨ sym (ℤ.·-distribˡ (ℕ₊₁→ℤ d) (a ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ b)) ⟩
ℕ₊₁→ℤ d ℤ.· (a ℤ.· ℕ₊₁→ℤ f) ℤ.+ ℕ₊₁→ℤ d ℤ.· (e ℤ.· ℕ₊₁→ℤ b)
≡[ i ]⟨ lem₁ a (ℕ₊₁→ℤ d) c (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ f) p i ℤ.+ lem₂ (ℕ₊₁→ℤ d) e (ℕ₊₁→ℤ b) i ⟩
ℕ₊₁→ℤ b ℤ.· (c ℤ.· ℕ₊₁→ℤ f) ℤ.+ ℕ₊₁→ℤ b ℤ.· (e ℤ.· ℕ₊₁→ℤ d)
≡⟨ ℤ.·-distribˡ (ℕ₊₁→ℤ b) (c ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ d) ⟩
ℕ₊₁→ℤ b ℤ.· (c ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ d) ∎ })
+-comm : ∀ x y → x + y ≡ y + x
+-comm = onCommonDenomSym-comm
(λ { (a , b) (c , d) → ℤ.+-comm (a ℤ.· (ℕ₊₁→ℤ d)) (c ℤ.· (ℕ₊₁→ℤ b)) })
+-identityˡ : ∀ x → 0 + x ≡ x
+-identityˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) i → [ ℤ.·-identityʳ a i / ·₊₁-identityˡ b i ] })
+-identityʳ : ∀ x → x + 0 ≡ x
+-identityʳ x = +-comm x _ ∙ +-identityˡ x
+-assoc : ∀ x y z → x + (y + z) ≡ (x + y) + z
+-assoc = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) (e , f) i → [ eq a (ℕ₊₁→ℤ b) c (ℕ₊₁→ℤ d) e (ℕ₊₁→ℤ f) i / ·₊₁-assoc b d f i ] })
where eq₁ : ∀ a b c → (a ℤ.· b) ℤ.· c ≡ a ℤ.· (c ℤ.· b)
eq₁ a b c = sym (ℤ.·-assoc a b c) ∙ cong (a ℤ.·_) (ℤ.·-comm b c)
eq₂ : ∀ a b c → (a ℤ.· b) ℤ.· c ≡ (a ℤ.· c) ℤ.· b
eq₂ a b c = eq₁ a b c ∙ ℤ.·-assoc a c b
eq : ∀ a b c d e f → Path ℤ _ _
eq a b c d e f =
a ℤ.· (d ℤ.· f) ℤ.+ (c ℤ.· f ℤ.+ e ℤ.· d) ℤ.· b
≡[ i ]⟨ a ℤ.· (d ℤ.· f) ℤ.+ ℤ.·-distribʳ (c ℤ.· f) (e ℤ.· d) b (~ i) ⟩
a ℤ.· (d ℤ.· f) ℤ.+ ((c ℤ.· f) ℤ.· b ℤ.+ (e ℤ.· d) ℤ.· b)
≡[ i ]⟨ ℤ.+-assoc (ℤ.·-assoc a d f i) (eq₂ c f b i) (eq₁ e d b i) i ⟩
((a ℤ.· d) ℤ.· f ℤ.+ (c ℤ.· b) ℤ.· f) ℤ.+ e ℤ.· (b ℤ.· d)
≡[ i ]⟨ ℤ.·-distribʳ (a ℤ.· d) (c ℤ.· b) f i ℤ.+ e ℤ.· (b ℤ.· d) ⟩
(a ℤ.· d ℤ.+ c ℤ.· b) ℤ.· f ℤ.+ e ℤ.· (b ℤ.· d) ∎
_·_ : ℚ → ℚ → ℚ
_·_ = onCommonDenomSym
(λ { (a , _) (c , _) → a ℤ.· c })
(λ { (a , _) (c , _) → ℤ.·-comm a c })
(λ { (a , b) (c , d) (e , _) p → lem₁ a (ℕ₊₁→ℤ d) c (ℕ₊₁→ℤ b) e p })
·-comm : ∀ x y → x · y ≡ y · x
·-comm = onCommonDenomSym-comm (λ { (a , _) (c , _) → ℤ.·-comm a c })
·-identityˡ : ∀ x → 1 · x ≡ x
·-identityˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) i → [ ℤ.·-identityˡ a i / ·₊₁-identityˡ b i ] })
·-identityʳ : ∀ x → x · 1 ≡ x
·-identityʳ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) i → [ ℤ.·-identityʳ a i / ·₊₁-identityʳ b i ] })
·-zeroˡ : ∀ x → 0 · x ≡ 0
·-zeroˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) → (λ i → [ p a b i / 1 ·₊₁ b ]) ∙ ℚ-cancelʳ b })
where p : ∀ a b → 0 ℤ.· a ≡ 0 ℤ.· ℕ₊₁→ℤ b
p a b = ℤ.·-zeroˡ {ℤ.spos} a ∙ sym (ℤ.·-zeroˡ {ℤ.spos} (ℕ₊₁→ℤ b))
·-zeroʳ : ∀ x → x · 0 ≡ 0
·-zeroʳ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) → (λ i → [ p a b i / b ·₊₁ 1 ]) ∙ ℚ-cancelˡ b })
where p : ∀ a b → a ℤ.· 0 ≡ ℕ₊₁→ℤ b ℤ.· 0
p a b = ℤ.·-zeroʳ {ℤ.spos} a ∙ sym (ℤ.·-zeroʳ {ℤ.spos} (ℕ₊₁→ℤ b))
·-assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z
·-assoc = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) (e , f) i → [ ℤ.·-assoc a c e i / ·₊₁-assoc b d f i ] })
·-distribˡ : ∀ x y z → (x · y) + (x · z) ≡ x · (y + z)
·-distribˡ = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) (e , f) → eq a b c d e f })
where lem : ∀ {ℓ} {A : Type ℓ} (_·_ : A → A → A)
(·-comm : ∀ x y → x · y ≡ y · x)
(·-assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z)
a c b d
→ (a · c) · (b · d) ≡ (a · (c · d)) · b
lem _·_ ·-comm ·-assoc a c b d =
(a · c) · (b · d) ≡[ i ]⟨ (a · c) · ·-comm b d i ⟩
(a · c) · (d · b) ≡⟨ ·-assoc (a · c) d b ⟩
((a · c) · d) · b ≡[ i ]⟨ ·-assoc a c d (~ i) · b ⟩
(a · (c · d)) · b ∎
lemℤ = lem ℤ._·_ ℤ.·-comm ℤ.·-assoc
lemℕ₊₁ = lem _·₊₁_ ·₊₁-comm ·₊₁-assoc
eq : ∀ a b c d e f →
[ (a ℤ.· c) ℤ.· ℕ₊₁→ℤ (b ·₊₁ f) ℤ.+ (a ℤ.· e) ℤ.· ℕ₊₁→ℤ (b ·₊₁ d)
/ (b ·₊₁ d) ·₊₁ (b ·₊₁ f) ]
≡ [ a ℤ.· (c ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ d)
/ b ·₊₁ (d ·₊₁ f) ]
eq a b c d e f =
(λ i → [ lemℤ a c (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ f) i ℤ.+ lemℤ a e (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ d) i
/ lemℕ₊₁ b d b f i ]) ∙
(λ i → [ ℤ.·-distribʳ (a ℤ.· (c ℤ.· ℕ₊₁→ℤ f)) (a ℤ.· (e ℤ.· ℕ₊₁→ℤ d)) (ℕ₊₁→ℤ b) i
/ (b ·₊₁ (d ·₊₁ f)) ·₊₁ b ]) ∙
ℚ-cancelʳ {a ℤ.· (c ℤ.· ℕ₊₁→ℤ f) ℤ.+ a ℤ.· (e ℤ.· ℕ₊₁→ℤ d)} {b ·₊₁ (d ·₊₁ f)} b ∙
(λ i → [ ℤ.·-distribˡ a (c ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ d) i
/ b ·₊₁ (d ·₊₁ f) ])
·-distribʳ : ∀ x y z → (x · z) + (y · z) ≡ (x + y) · z
·-distribʳ x y z = (λ i → ·-comm x z i + ·-comm y z i) ∙ ·-distribˡ z x y ∙ ·-comm z (x + y)
-_ : ℚ → ℚ
- x = -1 · x
negate-invol : ∀ x → - - x ≡ x
negate-invol x = ·-assoc -1 -1 x ∙ ·-identityˡ x
negateEquiv : ℚ ≃ ℚ
negateEquiv = isoToEquiv (iso -_ -_ negate-invol negate-invol)
negateEq : ℚ ≡ ℚ
negateEq = ua negateEquiv
+-inverseˡ : ∀ x → (- x) + x ≡ 0
+-inverseˡ x = (λ i → (-1 · x) + ·-identityˡ x (~ i)) ∙ ·-distribʳ -1 1 x ∙ ·-zeroˡ x
_-_ : ℚ → ℚ → ℚ
x - y = x + (- y)
+-inverseʳ : ∀ x → x - x ≡ 0
+-inverseʳ x = +-comm x (- x) ∙ +-inverseˡ x
+-injˡ : ∀ x y z → x + y ≡ x + z → y ≡ z
+-injˡ x y z p = sym (q y) ∙ cong ((- x) +_) p ∙ q z
where q : ∀ y → (- x) + (x + y) ≡ y
q y = +-assoc (- x) x y ∙ cong (_+ y) (+-inverseˡ x) ∙ +-identityˡ y
+-injʳ : ∀ x y z → x + y ≡ z + y → x ≡ z
+-injʳ x y z p = +-injˡ y x z (+-comm y x ∙ p ∙ +-comm z y)
| 43.987805
| 102
| 0.382312
|
7348f674adf728b4ee2e736ff8d039f43a4b7904
| 10,136
|
agda
|
Agda
|
src/LibraBFT/Impl/Consensus/BlockStorage/Properties/BlockStore.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Consensus/BlockStorage/Properties/BlockStore.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Consensus/BlockStorage/Properties/BlockStore.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
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Impl.Consensus.BlockStorage.BlockStore
import LibraBFT.Impl.Consensus.BlockStorage.BlockTree as BlockTree
open import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
import LibraBFT.Impl.Consensus.PersistentLivenessStorage as PersistentLivenessStorage
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.ByteString
open import Util.Hash
open import Util.KVMap as Map
open import Util.PKCS
open import Util.Prelude
open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms
open Invariants
open RoundManagerTransProps
open QCProps
module LibraBFT.Impl.Consensus.BlockStorage.Properties.BlockStore where
module new
(storage : PersistentLivenessStorage)
(initialData : RecoveryData)
(stateComp : StateComputer)
(maxPrunedBlocksInMem : Usize)
where
-- TODO-2: May require refinement (additional requirements and/or properties, particularly regarding ECinfo)
Contract : ECinfo → EitherD-Post ErrLog BlockStore
Contract _ (Left _) = ⊤
Contract eci (Right bs) = BlockStoreInv (bs , eci)
postulate
contract : ∀ {eci}
→ Contract eci (new-e-abs storage initialData stateComp maxPrunedBlocksInMem)
module executeBlockESpec (bs : BlockStore) (block : Block) where
Ok : Set
Ok = ∃[ eb ] (executeBlockE bs block ≡ Right eb)
record ContractOk (eb : ExecutedBlock) : Set where
constructor mkContractOk
field
ebBlock≡ : block ≡ eb ^∙ ebBlock
postulate -- TODO: prove
contract : (isOk : Ok) → ContractOk (proj₁ isOk)
module executeAndInsertBlockESpec (bs0 : BlockStore) (vblock : ValidBlock) where
block = vbBlock vblock
block-c = vbValid vblock
open executeAndInsertBlockE bs0 block
open import LibraBFT.Impl.Consensus.BlockStorage.Properties.BlockTree
blockId = block ^∙ bId
------ These are used only outside this module.
Ok : Set
Ok = ∃₂ λ bs' eb → executeAndInsertBlockE bs0 block ≡ Right (bs' , eb)
open Reqs block (bs0 ^∙ bsInner)
record ContractOk (bs' : BlockStore) (eb : ExecutedBlock) : Set where
constructor mkContractOk
field
ebBlock≈ : NoHC1 → eb ^∙ ebBlock ≈Block block
bsInv : ∀ {eci}
→ Preserves BlockStoreInv (bs0 , eci) (bs' , eci)
-- executeAndInsertBlockE does not modify BlockTree fields other than btIDToBlock
bs≡x : bs0 ≡ (bs' & (bsInner ∙ btIdToBlock) ∙~ (bs0 ^∙ bsInner ∙ btIdToBlock))
Contract : EitherD-Post ErrLog (BlockStore × ExecutedBlock)
Contract (Left x) = ⊤
Contract (Right (bs' , eb)) = ContractOk bs' eb
-- TUTORIAL: This proof has some additional commentary helping to understand the structure of the
-- proof, and showing an example of how using abstract variants of functions makes proofs more
-- resilient to change, as explained in
-- https://github.com/oracle/bft-consensus-agda/blob/main/docs/PeerHandlerContracts.org
contract' : EitherD-weakestPre step₀ Contract
-- step₀ is a maybeSD in context of EitherD. Therefore, via MonadMaybeD and EitherD-MonadMaybeD,
-- this translates to EitherD-maybe. We first deal with the easy case, applying the NoHC1
-- function provided to ebBlock≈ to evidence eb≡ that eb is in btIdToBlock.
proj₂ contract' eb eb≡ =
mkContractOk (λ nohc → nohc eb≡ block-c) id refl
proj₁ contract' getBlock≡nothing = contract₁
where
-- step₁ is again a maybeSD; if bs0 ^∙ bsRoot ≡ nothing, the Contract is trivial
contract₁ : EitherD-weakestPre step₁ Contract
proj₁ contract₁ _ = tt
-- otherwise, bs0 ^∙ bsRoot ≡ just bsr, and we have an ifD; in the true branch, step₁ returns a
-- Left, so again it is trivial
proj₁ (proj₂ contract₁ bsr bsr≡) _ = tt
-- in the else branch, we call step₂ bsr
proj₂ (proj₂ contract₁ bsr bsr≡) btr<br = contract₂
where
contract₃ : ∀ eb → block ≡ (eb ^∙ ebBlock)
→ EitherD-weakestPre (step₃ eb) Contract
module EB = executeBlockESpec bs0 block
open EB.ContractOk
contract₂ : EitherD-weakestPre (step₂ bsr) Contract
proj₂ contract₂ eb eb≡ ._ executeBlockE≡Right@refl = let con = (EB.contract (eb , eb≡))
in contract₃ eb
(EB.ContractOk.ebBlock≡ con)
proj₁ contract₂ (ErrCBlockNotFound _) executeBlockE≡Left = tt
proj₁ contract₂ (ErrVerify _) executeBlockE≡Left = tt
proj₁ contract₂ (ErrInfo _) executeBlockE≡Left = tt
-- if executeBlockE returns Left (ErrECCBlockNotFound parentBlockId), then we have two casesdue to
-- eitherSD (pathFromRoot parentBlockId bs0) LeftD λ blocksToReexecute →
-- in the first case, we have a Left, so it's easy
proj₁ (proj₁ contract₂ (ErrECCBlockNotFound parentBlockId) executeBlockE≡Left) _ _ = tt
-- in the second case, we have
-- case⊎D (forM) blocksToReexecute (executeBlockE bs0 ∘ (_^∙ ebBlock)) of λ where
-- and therefore two more cases; if the case⊎D returns Left, it's easy again
proj₁ (proj₂ (proj₁ contract₂ (ErrECCBlockNotFound parentBlockId) executeBlockE≡Left) blocksToReexecute btr≡) _ _ = tt
-- if the case⊎D returns a Right, we call executeBlockE₀ (the EitherD variant). We use executeBlockE≡ to handle case
-- analysis on the result of calling the abstract executeBlockE variant, ensuring we must use the contract for
-- executeBlockE because the proof cannot "look into" the implementation of executeBlockE, which makes the proof
-- more resilient in case of changes in its implementation.
-- TODO-2: clean this up by writing a general version of the contract for executeBlockE
proj₂ (proj₂ (proj₁ contract₂ (ErrECCBlockNotFound parentBlockId) executeBlockE≡Left) blocksToReexecute btr≡) _ _
with executeBlockE bs0 block | inspect
(executeBlockE bs0) block
... | Left x | [ R ] rewrite executeBlockE≡ R = tt
... | Right y | [ R ] rewrite executeBlockE≡ R =
λ where c refl ._ refl →
let con = EB.contract (c , R) in
contract₃ c
(ebBlock≡ con)
_ refl
contract₃ eb refl _ _ = contract₄
where
contract₄ : EitherD-weakestPre (step₄ eb) Contract
contract₄
with insertBlockESpec.contract eb (bs0 ^∙ bsInner)
...| con
with BlockTree.insertBlockE.E eb (bs0 ^∙ bsInner)
...| Left _ = tt
...| Right (bt' , eb') =
λ where ._ refl → mkContractOk IBE.blocks≈ btP bss≡x
where
module IBE = insertBlockESpec.ContractOk con
open BlockStoreInv
btP : ∀ {eci} → Preserves BlockStoreInv (bs0 , eci) ((bs0 & bsInner ∙~ bt') , eci)
btP (mkBlockStoreInv bti) = mkBlockStoreInv (IBE.btiPres bti)
bss≡x : bs0 ≡ (bs0 & bsInner ∙~ bt' & bsInner ∙ btIdToBlock ∙~ (bs0 ^∙ (bsInner ∙ btIdToBlock)))
bss≡x rewrite sym IBE.bt≡x = refl
contract : Contract (executeAndInsertBlockE bs0 block)
contract = EitherD-contract (executeAndInsertBlockE.step₀ bs0 block) Contract contract'
module executeAndInsertBlockMSpec (vb : ValidBlock) where
b = vbBlock vb
-- NOTE: This function returns any errors, rather than producing them as output.
module _ (pre : RoundManager) where
bs = pre ^∙ lBlockStore
contract
: ∀ Post
→ (∀ e → {- At the moment we do not need to know why it failed -} Post (Left e) pre [])
→ ((isOk : executeAndInsertBlockESpec.Ok bs vb) → let (bs' , eb , _) = isOk in
executeAndInsertBlockESpec.ContractOk bs vb bs' eb
→ Post (Right eb) (pre & rmBlockStore ∙~ bs') [])
→ LBFT-weakestPre (executeAndInsertBlockM b) Post pre
proj₁ (contract Post pfBail pfOk ._ refl) e ≡left = pfBail e
proj₂ (contract Post pfBail pfOk ._ refl) (bs' , eb) ≡right ._ refl unit refl
with executeAndInsertBlockESpec.contract bs vb
...| con rewrite ≡right = pfOk (bs' , eb , refl) con
module insertSingleQuorumCertMSpec
(qc : QuorumCert) where
module _ (pre : RoundManager) where
record Contract (r : Either ErrLog Unit) (post : RoundManager) (outs : List Output) : Set where
constructor mkContract
field
-- General invariants / properties
rmInv : Preserves RoundManagerInv pre post
noEpochChange : NoEpochChange pre post
noMsgOuts : OutputProps.NoMsgs outs
-- Voting
noVote : VoteNotGenerated pre post true
-- Signatures
qcPost : ∈Post⇒∈PreOr (_≡ qc) pre post
postulate -- TODO-2: prove
contract' : LBFT-weakestPre (insertSingleQuorumCertM qc) Contract pre
contract : ∀ Q → RWS-Post-⇒ Contract Q → LBFT-weakestPre (insertSingleQuorumCertM qc) Q pre
contract Q pf = LBFT-⇒ (insertSingleQuorumCertM qc) pre contract' pf
module syncInfoMSpec where
syncInfo : RoundManager → SyncInfo
syncInfo pre =
SyncInfo∙new (pre ^∙ lBlockStore ∙ bsHighestQuorumCert)
(pre ^∙ lBlockStore ∙ bsHighestCommitCert)
(pre ^∙ lBlockStore ∙ bsHighestTimeoutCert)
contract : ∀ pre Post → (Post (syncInfo pre) pre []) → LBFT-weakestPre syncInfoM Post pre
contract pre Post pf ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl = pf
| 44.849558
| 124
| 0.67206
|
43a86909ce2ee8a26bee1c865bb65fd141ccec23
| 552
|
agda
|
Agda
|
test/Common/Product.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Common/Product.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Common/Product.agda
|
xekoukou/agda-ocaml
|
026a8f8473ab91f99c3f6545728e71fa847d2720
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:39:14.000Z
|
2022-03-12T11:39:14.000Z
|
module Common.Product where
open import Common.Level
infixr 4 _,_ _,′_
infixr 2 _×_
------------------------------------------------------------------------
-- Definition
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
syntax Σ A (λ x → B) = Σ[ x ∶ A ] B
∃ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
∃ = Σ _
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)
A × B = Σ[ x ∶ A ] B
_,′_ : ∀ {a b} {A : Set a} {B : Set b} → A → B → A × B
_,′_ = _,_
| 19.034483
| 72
| 0.42029
|
722e0fbd924dd8848b8801873e0d7440a0235004
| 1,150
|
agda
|
Agda
|
src/LibraBFT/Impl/IO/OBM/ObmNeedFetch.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
src/LibraBFT/Impl/IO/OBM/ObmNeedFetch.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
src/LibraBFT/Impl/IO/OBM/ObmNeedFetch.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 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.ImplShared.Consensus.Types
module LibraBFT.Impl.IO.OBM.ObmNeedFetch where
{-
The functions in this module are used when a node needs to catchup.
TODO-3: model catchup request/response in Agda.
In haskell, for each message received from the network (including messages to self),
each message is processed in a single thread that completes the processing
before then processing a subsequent message.
However, a node detects that it needs to catchup "in the middle" of that processing.
In Haskell we use unsafePerformIO to send a network request to other nodes asking
for "catchup" data.
The responses are received by a different thread that then feeds them to the waiting thread,
which then proceeds.
-}
postulate -- TODO-3: writeRequestReadResponseUNSAFE
writeRequestReadResponseUNSAFE
: ObmNeedFetch → Author → Author → BlockRetrievalRequest
→ BlockRetrievalResponse
| 33.823529
| 111
| 0.791304
|
8b7c4b048c6a7e5f47f94f408bb505d086a2bbb0
| 13,143
|
agda
|
Agda
|
src/fot/FOTC/Data/Nat/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Data/Nat/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Data/Nat/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Arithmetic properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.PropertiesI
open import FOTC.Data.Nat
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.Nat.UnaryNumbers.TotalityI
------------------------------------------------------------------------------
-- Congruence properties
+-leftCong : ∀ {m n o} → m ≡ n → m + o ≡ n + o
+-leftCong refl = refl
+-rightCong : ∀ {m n o} → n ≡ o → m + n ≡ m + o
+-rightCong refl = refl
∸-leftCong : ∀ {m n o} → m ≡ n → m ∸ o ≡ n ∸ o
∸-leftCong refl = refl
∸-rightCong : ∀ {m n o} → n ≡ o → m ∸ n ≡ m ∸ o
∸-rightCong refl = refl
*-leftCong : ∀ {m n o} → m ≡ n → m * o ≡ n * o
*-leftCong refl = refl
*-rightCong : ∀ {m n o} → n ≡ o → m * n ≡ m * o
*-rightCong refl = refl
------------------------------------------------------------------------------
Sx≢x : ∀ {n} → N n → succ₁ n ≢ n
Sx≢x nzero h = ⊥-elim (0≢S (sym h))
Sx≢x (nsucc Nn) h = ⊥-elim (Sx≢x Nn (succInjective h))
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity = +-0x
+-rightIdentity : ∀ {n} → N n → n + zero ≡ n
+-rightIdentity nzero = +-leftIdentity zero
+-rightIdentity (nsucc {n} Nn) =
trans (+-Sx n zero) (succCong (+-rightIdentity Nn))
pred-N : ∀ {n} → N n → N (pred₁ n)
pred-N nzero = subst N (sym pred-0) nzero
pred-N (nsucc {n} Nn) = subst N (sym (pred-S n)) Nn
+-N : ∀ {m n} → N m → N n → N (m + n)
+-N {n = n} nzero Nn = subst N (sym (+-leftIdentity n)) Nn
+-N {n = n} (nsucc {m} Nm) Nn = subst N (sym (+-Sx m n)) (nsucc (+-N Nm Nn))
∸-N : ∀ {m n} → N m → N n → N (m ∸ n)
∸-N {m} Nm nzero = subst N (sym (∸-x0 m)) Nm
∸-N {m} Nm (nsucc {n} Nn) = subst N (sym (∸-xS m n)) (pred-N (∸-N Nm Nn))
+-assoc : ∀ {m} → N m → ∀ n o → m + n + o ≡ m + (n + o)
+-assoc nzero n o =
zero + n + o ≡⟨ +-leftCong (+-leftIdentity n) ⟩
n + o ≡⟨ sym (+-leftIdentity (n + o)) ⟩
zero + (n + o) ∎
+-assoc (nsucc {m} Nm) n o =
succ₁ m + n + o ≡⟨ +-leftCong (+-Sx m n) ⟩
succ₁ (m + n) + o ≡⟨ +-Sx (m + n) o ⟩
succ₁ (m + n + o) ≡⟨ succCong (+-assoc Nm n o) ⟩
succ₁ (m + (n + o)) ≡⟨ sym (+-Sx m (n + o)) ⟩
succ₁ m + (n + o) ∎
x+Sy≡S[x+y] : ∀ {m} → N m → ∀ n → m + succ₁ n ≡ succ₁ (m + n)
x+Sy≡S[x+y] nzero n =
zero + succ₁ n ≡⟨ +-leftIdentity (succ₁ n) ⟩
succ₁ n ≡⟨ succCong (sym (+-leftIdentity n)) ⟩
succ₁ (zero + n) ∎
x+Sy≡S[x+y] (nsucc {m} Nm) n =
succ₁ m + succ₁ n ≡⟨ +-Sx m (succ₁ n) ⟩
succ₁ (m + succ₁ n) ≡⟨ succCong (x+Sy≡S[x+y] Nm n) ⟩
succ₁ (succ₁ (m + n)) ≡⟨ succCong (sym (+-Sx m n)) ⟩
succ₁ (succ₁ m + n) ∎
+-comm : ∀ {m n} → N m → N n → m + n ≡ n + m
+-comm {n = n} nzero Nn =
zero + n ≡⟨ +-leftIdentity n ⟩
n ≡⟨ sym (+-rightIdentity Nn) ⟩
n + zero ∎
+-comm {n = n} (nsucc {m} Nm) Nn =
succ₁ m + n ≡⟨ +-Sx m n ⟩
succ₁ (m + n) ≡⟨ succCong (+-comm Nm Nn) ⟩
succ₁ (n + m) ≡⟨ sym (x+Sy≡S[x+y] Nn m) ⟩
n + succ₁ m ∎
0∸x : ∀ {n} → N n → zero ∸ n ≡ zero
0∸x nzero = ∸-x0 zero
0∸x (nsucc {n} Nn) =
zero ∸ succ₁ n ≡⟨ ∸-xS zero n ⟩
pred₁ (zero ∸ n) ≡⟨ predCong (0∸x Nn) ⟩
pred₁ zero ≡⟨ pred-0 ⟩
zero ∎
S∸S : ∀ {m n} → N m → N n → succ₁ m ∸ succ₁ n ≡ m ∸ n
S∸S {m} _ nzero =
succ₁ m ∸ succ₁ zero ≡⟨ ∸-xS (succ₁ m) zero ⟩
pred₁ (succ₁ m ∸ zero) ≡⟨ predCong (∸-x0 (succ₁ m)) ⟩
pred₁ (succ₁ m) ≡⟨ pred-S m ⟩
m ≡⟨ sym (∸-x0 m) ⟩
m ∸ zero ∎
S∸S {m} Nm (nsucc {n} Nn) =
succ₁ m ∸ succ₁ (succ₁ n) ≡⟨ ∸-xS (succ₁ m) (succ₁ n) ⟩
pred₁ (succ₁ m ∸ succ₁ n) ≡⟨ predCong (S∸S Nm Nn) ⟩
pred₁ (m ∸ n) ≡⟨ sym (∸-xS m n) ⟩
m ∸ succ₁ n ∎
x∸x≡0 : ∀ {n} → N n → n ∸ n ≡ zero
x∸x≡0 nzero = ∸-x0 zero
x∸x≡0 (nsucc Nn) = trans (S∸S Nn Nn) (x∸x≡0 Nn)
Sx∸x≡1 : ∀ {n} → N n → succ₁ n ∸ n ≡ 1'
Sx∸x≡1 nzero = ∸-x0 1'
Sx∸x≡1 (nsucc Nn) = trans (S∸S (nsucc Nn) Nn) (Sx∸x≡1 Nn)
[x+Sy]∸y≡Sx : ∀ {m n} → N m → N n → m + succ₁ n ∸ n ≡ succ₁ m
[x+Sy]∸y≡Sx {n = n} nzero Nn =
zero + succ₁ n ∸ n ≡⟨ ∸-leftCong (+-leftIdentity (succ₁ n)) ⟩
succ₁ n ∸ n ≡⟨ Sx∸x≡1 Nn ⟩
1' ∎
[x+Sy]∸y≡Sx (nsucc {m} Nm) nzero =
succ₁ m + 1' ∸ zero ≡⟨ ∸-leftCong (+-Sx m 1') ⟩
succ₁ (m + 1') ∸ zero ≡⟨ ∸-x0 (succ₁ (m + 1')) ⟩
succ₁ (m + 1') ≡⟨ succCong (+-comm Nm 1-N) ⟩
succ₁ (1' + m) ≡⟨ succCong (+-Sx zero m) ⟩
succ₁ (succ₁ (zero + m)) ≡⟨ succCong (succCong (+-leftIdentity m)) ⟩
succ₁ (succ₁ m) ∎
[x+Sy]∸y≡Sx (nsucc {m} Nm) (nsucc {n} Nn) =
succ₁ m + succ₁ (succ₁ n) ∸ succ₁ n
≡⟨ ∸-leftCong (+-Sx m (succ₁ (succ₁ n))) ⟩
succ₁ (m + succ₁ (succ₁ n)) ∸ succ₁ n
≡⟨ S∸S (+-N Nm (nsucc (nsucc Nn))) Nn ⟩
m + succ₁ (succ₁ n) ∸ n
≡⟨ ∸-leftCong (x+Sy≡S[x+y] Nm (succ₁ n)) ⟩
succ₁ (m + succ₁ n) ∸ n
≡⟨ ∸-leftCong (sym (+-Sx m (succ₁ n))) ⟩
succ₁ m + succ₁ n ∸ n
≡⟨ [x+Sy]∸y≡Sx (nsucc Nm) Nn ⟩
succ₁ (succ₁ m) ∎
[x+y]∸[x+z]≡y∸z : ∀ {m n o} → N m → N n → N o → (m + n) ∸ (m + o) ≡ n ∸ o
[x+y]∸[x+z]≡y∸z {n = n} {o} nzero _ _ =
(zero + n) ∸ (zero + o) ≡⟨ ∸-leftCong (+-leftIdentity n) ⟩
n ∸ (zero + o) ≡⟨ ∸-rightCong (+-leftIdentity o) ⟩
n ∸ o ∎
[x+y]∸[x+z]≡y∸z {n = n} {o} (nsucc {m} Nm) Nn No =
(succ₁ m + n) ∸ (succ₁ m + o) ≡⟨ ∸-leftCong (+-Sx m n) ⟩
succ₁ (m + n) ∸ (succ₁ m + o) ≡⟨ ∸-rightCong (+-Sx m o) ⟩
succ₁ (m + n) ∸ succ₁ (m + o) ≡⟨ S∸S (+-N Nm Nn) (+-N Nm No) ⟩
(m + n) ∸ (m + o) ≡⟨ [x+y]∸[x+z]≡y∸z Nm Nn No ⟩
n ∸ o ∎
*-leftZero : ∀ n → zero * n ≡ zero
*-leftZero = *-0x
*-rightZero : ∀ {n} → N n → n * zero ≡ zero
*-rightZero nzero = *-leftZero zero
*-rightZero (nsucc {n} Nn) =
trans (*-Sx n zero)
(trans (+-leftIdentity (n * zero)) (*-rightZero Nn))
*-N : ∀ {m n} → N m → N n → N (m * n)
*-N {n = n} nzero Nn = subst N (sym (*-leftZero n)) nzero
*-N {n = n} (nsucc {m} Nm) Nn = subst N (sym (*-Sx m n)) (+-N Nn (*-N Nm Nn))
*-leftIdentity : ∀ {n} → N n → 1' * n ≡ n
*-leftIdentity {n} Nn =
1' * n ≡⟨ *-Sx zero n ⟩
n + zero * n ≡⟨ +-rightCong (*-leftZero n) ⟩
n + zero ≡⟨ +-rightIdentity Nn ⟩
n ∎
x*Sy≡x+xy : ∀ {m n} → N m → N n → m * succ₁ n ≡ m + m * n
x*Sy≡x+xy {n = n} nzero Nn = sym
(
zero + zero * n ≡⟨ +-rightCong (*-leftZero n) ⟩
zero + zero ≡⟨ +-leftIdentity zero ⟩
zero ≡⟨ sym (*-leftZero (succ₁ n)) ⟩
zero * succ₁ n ∎
)
x*Sy≡x+xy {n = n} (nsucc {m} Nm) Nn =
succ₁ m * succ₁ n
≡⟨ *-Sx m (succ₁ n) ⟩
succ₁ n + m * succ₁ n
≡⟨ +-rightCong (x*Sy≡x+xy Nm Nn) ⟩
succ₁ n + (m + m * n)
≡⟨ +-Sx n (m + m * n) ⟩
succ₁ (n + (m + m * n))
≡⟨ succCong (sym (+-assoc Nn m (m * n))) ⟩
succ₁ (n + m + m * n)
≡⟨ succCong (+-leftCong (+-comm Nn Nm)) ⟩
succ₁ (m + n + m * n)
≡⟨ succCong (+-assoc Nm n (m * n)) ⟩
succ₁ (m + (n + m * n))
≡⟨ sym (+-Sx m (n + m * n)) ⟩
succ₁ m + (n + m * n)
≡⟨ +-rightCong (sym (*-Sx m n)) ⟩
succ₁ m + succ₁ m * n ∎
*-comm : ∀ {m n} → N m → N n → m * n ≡ n * m
*-comm {n = n} nzero Nn = trans (*-leftZero n) (sym (*-rightZero Nn))
*-comm {n = n} (nsucc {m} Nm) Nn =
succ₁ m * n ≡⟨ *-Sx m n ⟩
n + m * n ≡⟨ +-rightCong (*-comm Nm Nn) ⟩
n + n * m ≡⟨ sym (x*Sy≡x+xy Nn Nm) ⟩
n * succ₁ m ∎
*-rightIdentity : ∀ {n} → N n → n * 1' ≡ n
*-rightIdentity {n} Nn = trans (*-comm Nn (nsucc nzero)) (*-leftIdentity Nn)
*∸-leftDistributive : ∀ {m n o} → N m → N n → N o → (m ∸ n) * o ≡ m * o ∸ n * o
*∸-leftDistributive {m} {o = o} _ nzero _ =
(m ∸ zero) * o ≡⟨ *-leftCong (∸-x0 m) ⟩
m * o ≡⟨ sym (∸-x0 (m * o)) ⟩
m * o ∸ zero ≡⟨ ∸-rightCong (sym (*-leftZero o)) ⟩
m * o ∸ zero * o ∎
*∸-leftDistributive {o = o} nzero (nsucc {n} Nn) No =
(zero ∸ succ₁ n) * o ≡⟨ *-leftCong (0∸x (nsucc Nn)) ⟩
zero * o ≡⟨ *-leftZero o ⟩
zero ≡⟨ sym (0∸x (*-N (nsucc Nn) No)) ⟩
zero ∸ succ₁ n * o ≡⟨ ∸-leftCong (sym (*-leftZero o)) ⟩
zero * o ∸ succ₁ n * o ∎
*∸-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) nzero =
(succ₁ m ∸ succ₁ n) * zero
≡⟨ *-comm (∸-N (nsucc Nm) (nsucc Nn)) nzero ⟩
zero * (succ₁ m ∸ succ₁ n)
≡⟨ *-leftZero (succ₁ m ∸ succ₁ n) ⟩
zero
≡⟨ sym (0∸x (*-N (nsucc Nn) nzero)) ⟩
zero ∸ succ₁ n * zero
≡⟨ ∸-leftCong (sym (*-leftZero (succ₁ m))) ⟩
zero * succ₁ m ∸ succ₁ n * zero
≡⟨ ∸-leftCong (*-comm nzero (nsucc Nm)) ⟩
succ₁ m * zero ∸ succ₁ n * zero ∎
*∸-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) =
(succ₁ m ∸ succ₁ n) * succ₁ o
≡⟨ *-leftCong (S∸S Nm Nn) ⟩
(m ∸ n) * succ₁ o
≡⟨ *∸-leftDistributive Nm Nn (nsucc No) ⟩
m * succ₁ o ∸ n * succ₁ o
≡⟨ sym ([x+y]∸[x+z]≡y∸z (nsucc No) (*-N Nm (nsucc No)) (*-N Nn (nsucc No))) ⟩
(succ₁ o + m * succ₁ o) ∸ (succ₁ o + n * succ₁ o)
≡⟨ ∸-leftCong (sym (*-Sx m (succ₁ o))) ⟩
(succ₁ m * succ₁ o) ∸ (succ₁ o + n * succ₁ o)
≡⟨ ∸-rightCong (sym (*-Sx n (succ₁ o))) ⟩
(succ₁ m * succ₁ o) ∸ (succ₁ n * succ₁ o) ∎
*+-leftDistributive : ∀ {m n o} → N m → N n → N o → (m + n) * o ≡ m * o + n * o
*+-leftDistributive {m} {n} Nm Nn nzero =
(m + n) * zero
≡⟨ *-comm (+-N Nm Nn) nzero ⟩
zero * (m + n)
≡⟨ *-leftZero (m + n) ⟩
zero
≡⟨ sym (*-leftZero m) ⟩
zero * m
≡⟨ *-comm nzero Nm ⟩
m * zero
≡⟨ sym (+-rightIdentity (*-N Nm nzero)) ⟩
m * zero + zero
≡⟨ +-rightCong (trans (sym (*-leftZero n)) (*-comm nzero Nn)) ⟩
m * zero + n * zero ∎
*+-leftDistributive {n = n} nzero Nn (nsucc {o} No) =
(zero + n) * succ₁ o ≡⟨ *-leftCong (+-leftIdentity n) ⟩
n * succ₁ o ≡⟨ sym (+-leftIdentity (n * succ₁ o)) ⟩
zero + n * succ₁ o ≡⟨ +-leftCong (sym (*-leftZero (succ₁ o))) ⟩
zero * succ₁ o + n * succ₁ o ∎
*+-leftDistributive (nsucc {m} Nm) nzero (nsucc {o} No) =
(succ₁ m + zero) * succ₁ o
≡⟨ *-leftCong (+-rightIdentity (nsucc Nm)) ⟩
succ₁ m * succ₁ o
≡⟨ sym (+-rightIdentity (*-N (nsucc Nm) (nsucc No))) ⟩
succ₁ m * succ₁ o + zero
≡⟨ +-rightCong (sym (*-leftZero (succ₁ o))) ⟩
succ₁ m * succ₁ o + zero * succ₁ o ∎
*+-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) =
(succ₁ m + succ₁ n) * succ₁ o
≡⟨ *-leftCong (+-Sx m (succ₁ n)) ⟩
succ₁ (m + succ₁ n) * succ₁ o
≡⟨ *-Sx (m + succ₁ n) (succ₁ o) ⟩
succ₁ o + (m + succ₁ n) * succ₁ o
≡⟨ +-rightCong (*+-leftDistributive Nm (nsucc Nn) (nsucc No)) ⟩
succ₁ o + (m * succ₁ o + succ₁ n * succ₁ o)
≡⟨ sym (+-assoc (nsucc No) (m * succ₁ o) (succ₁ n * succ₁ o)) ⟩
succ₁ o + m * succ₁ o + succ₁ n * succ₁ o
≡⟨ +-leftCong (sym (*-Sx m (succ₁ o))) ⟩
succ₁ m * succ₁ o + succ₁ n * succ₁ o ∎
xy≡0→x≡0∨y≡0 : ∀ {m n} → N m → N n → m * n ≡ zero → m ≡ zero ∨ n ≡ zero
xy≡0→x≡0∨y≡0 nzero _ _ = inj₁ refl
xy≡0→x≡0∨y≡0 (nsucc Nm) nzero _ = inj₂ refl
xy≡0→x≡0∨y≡0 (nsucc {m} Nm) (nsucc {n} Nn) SmSn≡0 = ⊥-elim (0≢S prf)
where
prf : zero ≡ succ₁ (n + m * succ₁ n)
prf = zero ≡⟨ sym SmSn≡0 ⟩
succ₁ m * succ₁ n ≡⟨ *-Sx m (succ₁ n) ⟩
succ₁ n + m * succ₁ n ≡⟨ +-Sx n (m * succ₁ n) ⟩
succ₁ (n + m * succ₁ n) ∎
xy≡1→x≡1 : ∀ {m n} → N m → N n → m * n ≡ 1' → m ≡ 1'
xy≡1→x≡1 {n = n} nzero Nn h = ⊥-elim (0≢S (trans (sym (*-leftZero n)) h))
xy≡1→x≡1 (nsucc nzero) Nn h = refl
xy≡1→x≡1 (nsucc (nsucc {m} Nm)) nzero h =
⊥-elim (0≢S (trans (sym (*-rightZero (nsucc (nsucc Nm)))) h))
xy≡1→x≡1 (nsucc (nsucc {m} Nm)) (nsucc {n} Nn) h = ⊥-elim (0≢S prf₂)
where
prf₁ : 1' ≡ succ₁ (succ₁ (m + n * succ₁ (succ₁ m)))
prf₁ = 1'
≡⟨ sym h ⟩
succ₁ (succ₁ m) * succ₁ n
≡⟨ *-comm (nsucc (nsucc Nm)) (nsucc Nn) ⟩
succ₁ n * succ₁ (succ₁ m)
≡⟨ *-Sx n (succ₁ (succ₁ m)) ⟩
succ₁ (succ₁ m) + n * succ₁ (succ₁ m)
≡⟨ +-Sx (succ₁ m) (n * succ₁ (succ₁ m)) ⟩
succ₁ (succ₁ m + n * succ₁ (succ₁ m))
≡⟨ succCong (+-Sx m (n * succ₁ (succ₁ m))) ⟩
succ₁ (succ₁ (m + n * succ₁ (succ₁ m))) ∎
prf₂ : zero ≡ succ₁ (m + n * succ₁ (succ₁ m))
prf₂ = succInjective prf₁
xy≡1→y≡1 : ∀ {m n} → N m → N n → m * n ≡ 1' → n ≡ 1'
xy≡1→y≡1 Nm Nn h = xy≡1→x≡1 Nn Nm (trans (*-comm Nn Nm) h)
-- Feferman's axiom as presented by (Beeson 1986, p. 74).
succOnto : ∀ {n} → N n → n ≢ zero → succ₁ (pred₁ n) ≡ n
succOnto nzero h = ⊥-elim (h refl)
succOnto (nsucc {n} Nn) h = succCong (pred-S n)
------------------------------------------------------------------------------
-- References
--
-- Beeson, M. J. (1986). Proving Programs and Programming Proofs. In:
-- Logic, Methodology and Philosophy of Science VII (1983). Ed. by
-- Barcan Marcus, Ruth, Dorn, George J. W. and Weingartner,
-- Paul. Vol. 114. Studies in Logic and the Foundations of
-- Mathematics. Elsevier, pp. 51–82.
| 35.811989
| 81
| 0.465647
|
37c5fcfc18d398e85bd315be37b6a9c5f13aea56
| 890
|
agda
|
Agda
|
src/Categories/Morphism/Normal.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Morphism/Normal.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Morphism/Normal.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.Core
open import Categories.Object.Zero
-- Normal Mono and Epimorphisms
-- https://ncatlab.org/nlab/show/normal+monomorphism
module Categories.Morphism.Normal {o ℓ e} (𝒞 : Category o ℓ e) (𝒞-Zero : Zero 𝒞) where
open import Level
open import Categories.Object.Kernel 𝒞-Zero
open import Categories.Object.Kernel.Properties 𝒞-Zero
open import Categories.Morphism 𝒞
open Category 𝒞
record IsNormalMonomorphism {A K : Obj} (k : K ⇒ A) : Set (o ⊔ ℓ ⊔ e) where
field
{B} : Obj
arr : A ⇒ B
isKernel : IsKernel k arr
open IsKernel isKernel public
mono : Mono k
mono = Kernel-Mono (IsKernel⇒Kernel isKernel)
record NormalMonomorphism (K A : Obj) : Set (o ⊔ ℓ ⊔ e) where
field
mor : K ⇒ A
isNormalMonomorphism : IsNormalMonomorphism mor
open IsNormalMonomorphism isNormalMonomorphism public
| 25.428571
| 86
| 0.720225
|
37a37ae8b114b21dc8224641ac0a2f364b082c2e
| 912
|
agda
|
Agda
|
Cubical/Data/Everything.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Data/Everything.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Data/Everything.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Everything where
open import Cubical.Data.BinNat public
open import Cubical.Data.Bool public
open import Cubical.Data.Empty public
open import Cubical.Data.Equality public
open import Cubical.Data.Fin public
open import Cubical.Data.Nat public
open import Cubical.Data.Int public renaming (_+_ to _+Int_ ; +-assoc to +Int-assoc; +-comm to +Int-comm)
open import Cubical.Data.Sum public
open import Cubical.Data.Prod public
open import Cubical.Data.Unit public
open import Cubical.Data.Sigma public
open import Cubical.Data.Universe public
open import Cubical.Data.DiffInt public
open import Cubical.Data.Group public hiding (_≃_)
open import Cubical.Data.HomotopyGroup public
open import Cubical.Data.List public
open import Cubical.Data.Graph public
open import Cubical.Data.InfNat public renaming (_*_ to _*ℕ+∞_; _+_ to _+ℕ+∞_; suc to ∞suc; zero to ∞zero)
| 41.454545
| 106
| 0.794956
|
655bd656dc4238f3435e01a727d0d63280ba0b9a
| 713
|
agda
|
Agda
|
test/Succeed/fol-theorems/VariableNamesClash.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Succeed/fol-theorems/VariableNamesClash.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Succeed/fol-theorems/VariableNamesClash.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
------------------------------------------------------------------------------
-- Testing variable names clash
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module VariableNamesClash where
postulate
D : Set
_≡_ : D → D → Set
a b : D
postulate a≡b : a ≡ b
{-# ATP axiom a≡b #-}
foo : (n : D) → a ≡ b
foo n = prf n
where
-- The translation of this postulate must use two diferents
-- quantified variables names e.g. ∀ x. ∀ y. a ≡ b.
postulate prf : (n : D) → a ≡ b
{-# ATP prove prf #-}
| 26.407407
| 78
| 0.42777
|
724035496d6b583d134d549f2c1c7aaa72f0322c
| 311
|
agda
|
Agda
|
test/epic/Prelude/Char.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/epic/Prelude/Char.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/epic/Prelude/Char.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
module Prelude.Char where
open import Prelude.Bool
postulate
Char : Set
{-# BUILTIN CHAR Char #-}
private
primitive
primCharEquality : (c c' : Char) -> Bool
postulate
eof : Char
{-# COMPILED_EPIC eof () -> Int = foreign Int "eof" () #-}
charEq : Char -> Char -> Bool
charEq = primCharEquality
| 14.136364
| 58
| 0.655949
|
1ea56a263b5a1acd8c76378f831cfb3659b6b2c4
| 801
|
agda
|
Agda
|
src/Library.agda
|
gunpinyo/agda-cat
|
045f2ab8a40c1b87f578ef12c0d1e10d131b7da3
|
[
"BSD-3-Clause"
] | null | null | null |
src/Library.agda
|
gunpinyo/agda-cat
|
045f2ab8a40c1b87f578ef12c0d1e10d131b7da3
|
[
"BSD-3-Clause"
] | null | null | null |
src/Library.agda
|
gunpinyo/agda-cat
|
045f2ab8a40c1b87f578ef12c0d1e10d131b7da3
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module Library where
open import Data.Product
using ( Σ ; Σ-syntax ; _×_ )
public
open import Function
using ()
renaming ( id to λ-id
; _∘_ to λ-comp
; flip to λ-flip )
public
open import Level
using ( Level )
renaming ( zero to ℓ-zero
; suc to ℓ-suc
; _⊔_ to ℓ-max )
public
open import Relation.Binary.Core
using ( Rel )
public
open import Relation.Unary
using ( Pred )
public
open import Relation.Binary.PropositionalEquality
using ( _≡_ ; module ≡-Reasoning )
renaming ( refl to ≡-refl
; sym to ≡-sym
; trans to ≡-trans)
public
open ≡-Reasoning
using ( _≡⟨_⟩_ )
renaming ( begin_ to ≡-proof_
; _∎ to _≡-qed )
public
| 18.627907
| 49
| 0.565543
|
ed2a0959a153a61fbbc223f166af6963c92f0905
| 505
|
agda
|
Agda
|
agda/BBHeap/Subtyping.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/BBHeap/Subtyping.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/BBHeap/Subtyping.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module BBHeap.Subtyping {A : Set}
(_≤_ : A → A → Set)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Bound.Lower.Order.Properties _≤_ trans≤
subtyping : {b b' : Bound} → LeB b' b → BBHeap b → BBHeap b'
subtyping _ leaf = leaf
subtyping b'≤b (left b≤x l⋘r) = left (transLeB b'≤b b≤x) l⋘r
subtyping b'≤b (right b≤x l⋙r) = right (transLeB b'≤b b≤x) l⋙r
| 31.5625
| 62
| 0.631683
|
3fa0df2c609d28711aade6ffd7d5050f2151a1ec
| 14,148
|
agda
|
Agda
|
Cubical/Homotopy/Connected.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Connected.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Connected.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.Connected where
open import Cubical.Core.Everything
open import Cubical.Foundations.Everything
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Univalence
open import Cubical.Functions.Fibration
open import Cubical.Data.Nat
open import Cubical.Data.Prod hiding (map)
open import Cubical.Data.Sigma hiding (_×_)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Susp
open import Cubical.HITs.SmashProduct
open import Cubical.HITs.Truncation as Trunc
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn.Base
open import Cubical.Data.Unit
-- Note that relative to most sources, this notation is off by +2
isConnected : ∀ {ℓ} (n : HLevel) (A : Type ℓ) → Type ℓ
isConnected n A = isContr (hLevelTrunc n A)
isConnectedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isConnectedFun n f = ∀ b → isConnected n (fiber f b)
isTruncatedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isTruncatedFun n f = ∀ b → isOfHLevel n (fiber f b)
isConnectedSubtr : ∀ {ℓ} {A : Type ℓ} (n m : HLevel)
→ isConnected (m + n) A
→ isConnected n A
isConnectedSubtr {A = A} n m iscon =
transport (λ i → isContr (ua (truncOfTruncEq {A = A} n m) (~ i)))
(∣ iscon .fst ∣ , Trunc.elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → cong ∣_∣ (iscon .snd a))
isConnectedFunSubtr : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : HLevel) (f : A → B)
→ isConnectedFun (m + n) f
→ isConnectedFun n f
isConnectedFunSubtr n m f iscon b = isConnectedSubtr n m (iscon b)
private
typeToFiber : ∀ {ℓ} (A : Type ℓ) → A ≡ fiber (λ (x : A) → tt) tt
typeToFiber A = isoToPath typeToFiberIso
where
typeToFiberIso : Iso A (fiber (λ (x : A) → tt) tt)
Iso.fun typeToFiberIso x = x , refl
Iso.inv typeToFiberIso = fst
Iso.rightInv typeToFiberIso b i = fst b , (isOfHLevelSuc 1 (isPropUnit) tt tt (snd b) refl) i
Iso.leftInv typeToFiberIso a = refl
module elim {ℓ ℓ' : Level} {A : Type ℓ} {B : Type ℓ'} (f : A → B) (n : HLevel) where
isIsoPrecompose : ∀ {ℓ'''} (P : B → TypeOfHLevel ℓ''' n)
→ isConnectedFun n f
→ Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)
isIsoPrecompose P fConn =
(iso (_∘ f)
(λ t b → inv t b (fConn b .fst))
(λ t → funExt λ a →
cong (inv t (f a)) (fConn (f a) .snd ∣ a , refl ∣)
∙ substRefl {B = fst ∘ P} (t a))
(λ s → funExt λ b →
Trunc.elim
{B = λ d → inv (s ∘ f) b d ≡ s b}
(λ _ → isOfHLevelPath n (P b .snd) _ _)
(λ {(a , p) i → transp (λ j → P (p (j ∨ i)) .fst) i (s (p i))})
(fConn b .fst)))
where
inv : ((a : A) → P (f a) .fst) → (b : B) → hLevelTrunc n (fiber f b) → P b .fst
inv t b =
Trunc.rec
(P b .snd)
(λ {(a , p) → subst (fst ∘ P) p (t a)})
isEquivPrecompose : ∀ {ℓ'''} (P : B → TypeOfHLevel ℓ''' n)
→ isConnectedFun n f
→ isEquiv (λ(s : (b : B) → P b .fst) → s ∘ f)
isEquivPrecompose P fConn = isoToIsEquiv (isIsoPrecompose P fConn)
isConnectedPrecompose : ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n)
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))
→ isConnectedFun n f
isConnectedPrecompose P→sect b = c n P→sect b , λ y → sym (fun n P→sect b y) -- (c n P→sect b) , λ y → sym (fun n P→sect b y)
where
P : (n : HLevel) → ((P : B → TypeOfHLevel ℓ n)
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))
→ B → Type _
P n s b = hLevelTrunc n (fiber f b)
c : (n : HLevel) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n)
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → (b : B)
→ hLevelTrunc n (fiber f b)
c n s = (s λ b → (hLevelTrunc n (fiber f b) , isOfHLevelTrunc _)) .fst
λ a → ∣ a , refl ∣
fun : (n : HLevel) (P→sect : ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n)
→ hasSection λ(s : (b : B) → P b .fst) → s ∘ f))
→ (b : B) (w : (hLevelTrunc n (fiber f b)))
→ w ≡ c n P→sect b
fun zero P→sect b w = isOfHLevelSuc zero (isOfHLevelTrunc _) w (c zero P→sect b)
fun (suc n) P→sect b = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) x (c (suc n) P→sect b))
λ a → transport eqtyp c* b (fst a) (snd a)
where
eqtyp : ((a : A) → ∣ (a , refl {x = f a}) ∣
≡ c (suc n) P→sect (f a))
≡ ((b : B) (a : A) (p : f (a) ≡ b) → ∣ (a , p) ∣
≡ c (suc n) P→sect b)
eqtyp =
isoToPath
(iso (λ g b a → J (λ b p → ∣ a , p ∣ ≡ c (suc n) P→sect b) (g a))
(λ g a → g (f a) a refl)
(λ h i b a p → (J (λ b x → (J (λ b₂ p → ∣ a , p ∣ ≡ c (suc n) P→sect b₂)
(h (f a) a (λ _ → f a)) x ≡ h b a x))
(JRefl (λ b₂ p → ∣ a , p ∣ ≡ c (suc n) P→sect b₂) (h (f a) a (λ _ → f a))))
p i)
λ h i a p → JRefl (λ b₁ p → ∣ a , p ∣ ≡ c (suc n) P→sect b₁) (h a) i p)
c* : ((a : A) → ∣ (a , refl {x = f a}) ∣ ≡ c (suc n) P→sect (f a))
c* a = sym (cong (λ x → x a) (P→sect (λ b → hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _) .snd λ a → ∣ a , refl ∣))
isOfHLevelPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (k : HLevel) (n : HLevel)
{A : Type ℓ} {B : Type ℓ'} (P : B → TypeOfHLevel ℓ'' (k + n)) (f : A → B)
→ isConnectedFun n f
→ isOfHLevelFun k (λ(s : (b : B) → P b .fst) → s ∘ f)
isOfHLevelPrecomposeConnected zero n P f fConn =
elim.isEquivPrecompose f n P fConn .equiv-proof
isOfHLevelPrecomposeConnected (suc k) n P f fConn t =
isOfHLevelPath'⁻ k
(λ {(s₀ , p₀) (s₁ , p₁) →
subst (isOfHLevel k) (sym (fiber≡ (s₀ , p₀) (s₁ , p₁)))
(isOfHLevelRetract k
(λ {(q , α) → (funExt⁻ q) , (cong funExt⁻ α)})
(λ {(h , β) → (funExt h) , (cong funExt β)})
(λ _ → refl)
(isOfHLevelPrecomposeConnected k n
(λ b → (s₀ b ≡ s₁ b) , isOfHLevelPath' (k + n) (P b .snd) _ _)
f fConn
(funExt⁻ (p₀ ∙∙ refl ∙∙ sym p₁))))})
indMapEquiv→conType : ∀ {ℓ} {A : Type ℓ} (n : HLevel)
→ ((B : TypeOfHLevel ℓ n)
→ isEquiv (λ (b : (fst B)) → λ (a : A) → b))
→ isConnected n A
indMapEquiv→conType {A = A} n BEq =
transport (λ i → isContr (hLevelTrunc n (typeToFiber A (~ i))))
(elim.isConnectedPrecompose (λ _ → tt) n
(λ P → isEquiv→hasSection ((compEquiv ((λ Q → Q tt) , isoToIsEquiv (helper P))
(_ , BEq (P tt)) .snd )))
tt)
where
helper : ∀ {ℓ'} (P : Unit → TypeOfHLevel ℓ' n)
→ Iso ((b : Unit) → fst (P b)) (fst (P tt))
Iso.fun (helper P) = λ Q → Q tt
Iso.inv (helper P) = λ a _ → a
Iso.rightInv (helper P) b = refl
Iso.leftInv (helper P) b = refl
isConnectedPath : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isConnected (suc n) A
→ (a₀ a₁ : A) → isConnected n (a₀ ≡ a₁)
isConnectedPath n connA a₀ a₁ =
subst isContr (PathIdTrunc _)
(isContr→isContrPath connA _ _)
isConnectedRetract : ∀ {ℓ ℓ'} (n : HLevel)
{A : Type ℓ} {B : Type ℓ'}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isConnected n B → isConnected n A
isConnectedRetract n f g h =
isContrRetract
(Trunc.map f)
(Trunc.map g)
(Trunc.elim
(λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _)
(λ a → cong ∣_∣ (h a)))
isConnectedPoint : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isConnected (suc n) A
→ (a : A) → isConnectedFun n (λ(_ : Unit) → a)
isConnectedPoint n connA a₀ a =
isConnectedRetract n
snd (_ ,_) (λ _ → refl)
(isConnectedPath n connA a₀ a)
isConnectedPoint2 : ∀ {ℓ} (n : HLevel) {A : Type ℓ} (a : A)
→ isConnectedFun n (λ(_ : Unit) → a)
→ isConnected (suc n) A
isConnectedPoint2 n {A = A} a connMap = indMapEquiv→conType _ λ B → isoToIsEquiv (theIso B)
where
module _ {ℓ' : Level} (B : TypeOfHLevel ℓ' (suc n))
where
helper : (f : A → fst B) → (a2 : A) → f a2 ≡ f a
helper f = equiv-proof (elim.isEquivPrecompose (λ _ → a) n (λ a2 → (f a2 ≡ f a) ,
isOfHLevelPath' n (snd B) (f a2) (f a)) connMap) (λ _ → refl) .fst .fst
theIso : Iso (fst B) (A → fst B)
Iso.fun theIso b a = b
Iso.inv theIso f = f a
Iso.rightInv theIso f = funExt λ y → sym (helper f y)
Iso.leftInv theIso _ = refl
connectedTruncIso : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)
→ isConnectedFun n f
→ Iso (hLevelTrunc n A) (hLevelTrunc n B)
connectedTruncIso {A = A} {B = B} zero f con = g
where
g : Iso (hLevelTrunc zero A) (hLevelTrunc zero B)
Iso.fun g = λ _ → fst (isOfHLevelTrunc 0)
Iso.inv g = λ _ → fst (isOfHLevelTrunc 0)
Iso.rightInv g = λ b → isOfHLevelTrunc 0 .snd b
Iso.leftInv g = λ b → isOfHLevelTrunc 0 .snd b
connectedTruncIso {A = A} {B = B} (suc n) f con = g
where
back : B → hLevelTrunc (suc n) A
back y = map fst ((con y) .fst)
backSection : (b : B) → Path (hLevelTrunc (suc n) B)
(Trunc.rec (isOfHLevelTrunc (suc n))
(λ a → ∣ f a ∣)
(Trunc.rec {n = suc n }
{B = hLevelTrunc (suc n) A} (isOfHLevelTrunc (suc n)) back ∣ b ∣))
∣ b ∣
backSection b = helper (λ p → map f p ≡ ∣ b ∣)
(λ x → (isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)))
(map f (map fst x)) ∣ b ∣)
(λ a p → cong ∣_∣ p)
(fst (con b))
where
helper : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} (P : hLevelTrunc (suc n) A → Type ℓ'')
→ ((x : hLevelTrunc (suc n) (Σ A B)) → isOfHLevel (suc n) (P (map fst x)))
→ ((a : A) (b : B a) → P ∣ a ∣)
→ (p : hLevelTrunc (suc n) (Σ A B))
→ P (map fst p)
helper P hlev pf = Trunc.elim hlev λ pair → pf (fst pair) (snd pair)
backRetract : (a : A) → map fst (con (f a) .fst) ≡ ∣ a ∣
backRetract a = cong (map fst) (con (f a) .snd ∣ a , refl ∣)
g : Iso (hLevelTrunc (suc n) A) (hLevelTrunc (suc n) B)
Iso.fun g = map f
Iso.inv g = Trunc.rec (isOfHLevelTrunc _) back
Iso.leftInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
λ a → cong (map fst) (con (f a) .snd ∣ a , refl ∣)
Iso.rightInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
backSection
connectedTruncIso2 : ∀ {ℓ} {A B : Type ℓ} (n m : HLevel) (f : A → B)
→ Σ[ x ∈ ℕ ] x + n ≡ m
→ isConnectedFun m f
→ Iso (hLevelTrunc n A) (hLevelTrunc n B)
connectedTruncIso2 {A = A} {B = B} n m f (x , pf) con =
connectedTruncIso n f (isConnectedFunSubtr n x f (transport (λ i → isConnectedFun (pf (~ i)) f) con))
connectedTruncEquiv : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)
→ isConnectedFun n f
→ hLevelTrunc n A ≃ hLevelTrunc n B
connectedTruncEquiv {A = A} {B = B} n f con = isoToEquiv (connectedTruncIso n f con)
-- TODO : Reorganise the following proofs.
inrConnected : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (n : HLevel)
→ (f : C → A) (g : C → B)
→ isConnectedFun n f
→ isConnectedFun n {A = B} {B = Pushout f g} inr
inrConnected {A = A} {B = B} {C = C} n f g iscon =
elim.isConnectedPrecompose inr n λ P → (λ l → k P l) , λ b → refl
where
module _ {ℓ : Level} (P : (Pushout f g) → TypeOfHLevel ℓ n)
(h : (b : B) → typ (P (inr b)))
where
Q : A → TypeOfHLevel _ n
Q a = (P (inl a))
fun : (c : C) → typ (Q (f c))
fun c = transport (λ i → typ (P (push c (~ i)))) (h (g c))
k : (d : Pushout f g) → typ (P d)
k (inl x) = equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .fst x
k (inr x) = h x
k (push a i) =
hcomp (λ k → λ { (i = i0) → equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .snd i0 a
; (i = i1) → transportTransport⁻ (λ j → typ (P (push a j))) (h (g a)) k })
(transp (λ j → typ (P (push a (i ∧ j))))
(~ i)
(equiv-proof (elim.isEquivPrecompose f n Q iscon)
fun .fst .snd i a))
sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n)
sphereConnected zero = ∣ north ∣ , isOfHLevelTrunc 1 ∣ north ∣
sphereConnected (suc n) =
transport (λ i → isConnected (2 + n) (PushoutSusp≡Susp {A = S₊ n} i))
(isConnectedPoint2 (suc n)
{A = Pushout {A = S₊ n} (λ _ → tt) λ _ → tt}
(inr tt)
((transport (λ i → isConnectedFun (suc n) (mapsAgree (~ i)))
(inrConnected _ (λ _ → tt) (λ _ → tt)
λ {tt → transport (λ i → isContr (hLevelTrunc (suc n) (fibId (S₊ n) (~ i))))
(sphereConnected n)}))))
where
mapsAgree : Path ((x : Unit) → Pushout {A = S₊ n} (λ x → tt) (λ x → tt))
(λ (x : Unit) → inr tt)
inr
mapsAgree = funExt λ _ → refl
| 45.057325
| 139
| 0.49484
|
1121769cc332fcc346ee07da001ba145571daa37
| 1,498
|
agda
|
Agda
|
src/fot/FOTC/Data/Nat/UnaryNumbers/TotalityATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Data/Nat/UnaryNumbers/TotalityATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Data/Nat/UnaryNumbers/TotalityATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- The unary numbers are FOTC total natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.UnaryNumbers.TotalityATP where
open import FOTC.Base
open import FOTC.Data.Nat.Type
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
postulate
0-N : N 0'
1-N : N 1'
2-N : N 2'
3-N : N 3'
4-N : N 4'
5-N : N 5'
{-# ATP prove 0-N #-}
{-# ATP prove 1-N #-}
{-# ATP prove 2-N #-}
{-# ATP prove 3-N #-}
{-# ATP prove 4-N #-}
{-# ATP prove 5-N #-}
postulate
10-N : N 10'
11-N : N 11'
{-# ATP prove 10-N #-}
{-# ATP prove 11-N #-}
postulate 89-N : N 89'
{-# ATP prove 89-N #-}
postulate
90-N : N 90'
91-N : N 91'
92-N : N 92'
93-N : N 93'
94-N : N 94'
95-N : N 95'
96-N : N 96'
97-N : N 97'
98-N : N 98'
99-N : N 99'
{-# ATP prove 90-N #-}
{-# ATP prove 91-N #-}
{-# ATP prove 92-N #-}
{-# ATP prove 93-N #-}
{-# ATP prove 94-N #-}
{-# ATP prove 95-N #-}
{-# ATP prove 96-N #-}
{-# ATP prove 97-N #-}
{-# ATP prove 98-N #-}
{-# ATP prove 99-N #-}
postulate
100-N : N 100'
101-N : N 101'
{-# ATP prove 100-N #-}
{-# ATP prove 101-N #-}
postulate 111-N : N 111'
{-# ATP prove 111-N #-}
| 21.098592
| 78
| 0.441255
|
3fea82ed9e64be606346565b0b135e0d08f49fa4
| 798
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/RawRing.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/RingSolver/RawRing.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/RingSolver/RawRing.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.RawRing where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Algebra.RingSolver.AlmostRing hiding (⟨_⟩)
private
variable
ℓ : Level
record RawRing ℓ : Type (ℓ-suc ℓ) where
constructor rawring
field
Carrier : Type ℓ
0r : Carrier
1r : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
infixl 8 _·_
infixl 7 -_
infixl 6 _+_
⟨_⟩ : RawRing ℓ → Type ℓ
⟨_⟩ = RawRing.Carrier
AlmostRing→RawRing : AlmostRing ℓ → RawRing ℓ
AlmostRing→RawRing (almostring Carrier 0r 1r _+_ _·_ -_ isAlmostRing) =
rawring Carrier 0r 1r _+_ _·_ -_
| 22.166667
| 71
| 0.660401
|
651eb44520f5e0a6b00974b668efe1cdb063af68
| 8,886
|
agda
|
Agda
|
formalization/agda/Spire/Examples/InferredPropositionalDesc.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 43
|
2015-05-28T23:25:33.000Z
|
2022-03-08T17:10:59.000Z
|
formalization/agda/Spire/Examples/InferredPropositionalDesc.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | null | null | null |
formalization/agda/Spire/Examples/InferredPropositionalDesc.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 1
|
2015-08-17T21:00:07.000Z
|
2015-08-17T21:00:07.000Z
|
{-# OPTIONS --type-in-type #-}
open import Data.Unit
open import Data.Product
open import Data.List hiding ( concat )
open import Data.String
open import Relation.Binary.PropositionalEquality
module Spire.Examples.InferredPropositionalDesc where
----------------------------------------------------------------------
elimEq : {A : Set} (x : A) (P : (y : A) → x ≡ y → Set)
→ P x refl
→ (y : A) (p : x ≡ y) → P y p
elimEq .x P prefl x refl = prefl
----------------------------------------------------------------------
Label : Set
Label = String
Enum : Set
Enum = List Label
data Tag : Enum → Set where
here : ∀{l E} → Tag (l ∷ E)
there : ∀{l E} → Tag E → Tag (l ∷ E)
Cases : {E : Enum} (P : Tag E → Set) → Set
Cases {[]} P = ⊤
Cases {l ∷ E} P = P here × Cases λ t → P (there t)
case : {E : Enum} (P : Tag E → Set) (cs : Cases P) (t : Tag E) → P t
case {l ∷ E} P (c , cs) here = c
case {l ∷ E} P (c , cs) (there t) = case (λ t → P (there t)) cs t
----------------------------------------------------------------------
data Desc (I : Set) : Set₁ where
`End : (i : I) → Desc I
`Rec : (i : I) (D : Desc I) → Desc I
`Arg : (A : Set) (B : A → Desc I) → Desc I
`RecFun : (A : Set) (B : A → I) (D : Desc I) → Desc I
ISet : Set → Set₁
ISet I = I → Set
El : {I : Set} (D : Desc I) (X : ISet I) → ISet I
El (`End j) X i = j ≡ i
El (`Rec j D) X i = X j × El D X i
El (`Arg A B) X i = Σ A (λ a → El (B a) X i)
El (`RecFun A B D) X i = ((a : A) → X (B a)) × El D X i
data μ {I : Set} (D : Desc I) (i : I) : Set where
con : El D (μ D) i → μ D i
All : {I : Set} (D : Desc I) {X : ISet I} (P : (i : I) → X i → Set) (i : I) (xs : El D X i) → Set
All (`End j) P i q = ⊤
All (`Rec j D) P i (x , xs) = P j x × All D P i xs
All (`Arg A B) P i (a , b) = All (B a) P i b
All (`RecFun A B D) P i (f , xs) = ((a : A) → P (B a) (f a)) × All D P i xs
caseD : (E : Enum) (I : Set) (cs : Cases (λ _ → Desc I)) (t : Tag E) → Desc I
caseD E I cs t = case (λ _ → Desc I) cs t
----------------------------------------------------------------------
ind :
{I : Set}
(D : Desc I)
(P : (i : I) → μ D i → Set)
(pcon : (i : I) (xs : El D (μ D) i) → All D P i xs → P i (con xs))
{i : I}
(x : μ D i)
→ P i x
hyps :
{I : Set}
(D₁ : Desc I)
(P : (i : I) → μ D₁ i → Set)
(pcon : (i : I) (xs : El D₁ (μ D₁) i) → All D₁ P i xs → P i (con xs))
(D₂ : Desc I)
{i : I}
(xs : El D₂ (μ D₁) i)
→ All D₂ P i xs
ind D P pcon (con xs) = pcon _ xs (hyps D P pcon D xs)
hyps D P pcon (`End j) q = tt
hyps D P pcon (`Rec j A) (x , xs) = ind D P pcon x , hyps D P pcon A xs
hyps D P pcon (`Arg A B) (a , b) = hyps D P pcon (B a) b
hyps D P pcon (`RecFun A B E) (f , xs) = (λ a → ind D P pcon (f a)) , hyps D P pcon E xs
----------------------------------------------------------------------
module Desugared where
ℕT : Enum
ℕT = "zero" ∷ "suc" ∷ []
VecT : Enum
VecT = "nil" ∷ "cons" ∷ []
ℕC : Tag ℕT → Desc ⊤
ℕC = caseD ℕT ⊤
( `End tt
, `Rec tt (`End tt)
, tt
)
ℕD : Desc ⊤
ℕD = `Arg (Tag ℕT) ℕC
ℕ : ⊤ → Set
ℕ = μ ℕD
zero : ℕ tt
zero = con (here , refl)
suc : ℕ tt → ℕ tt
suc n = con (there here , n , refl)
VecC : (A : Set) → Tag VecT → Desc (ℕ tt)
VecC A = caseD VecT (ℕ tt)
( `End zero
, `Arg (ℕ tt) (λ n → `Arg A λ _ → `Rec n (`End (suc n)))
, tt
)
VecD : (A : Set) → Desc (ℕ tt)
VecD A = `Arg (Tag VecT) (VecC A)
Vec : (A : Set) (n : ℕ tt) → Set
Vec A n = μ (VecD A) n
nil : (A : Set) → Vec A zero
nil A = con (here , refl)
cons : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons A n x xs = con (there here , n , x , xs , refl)
----------------------------------------------------------------------
module Induction where
add : ℕ tt → ℕ tt → ℕ tt
add = ind ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ u t,c → case
(λ t → (c : El (ℕC t) ℕ u)
(ih : All ℕD (λ u n → ℕ u → ℕ u) u (t , c))
→ ℕ u → ℕ u
)
( (λ q ih n → n)
, (λ m,q ih,tt n → suc (proj₁ ih,tt n))
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
mult : ℕ tt → ℕ tt → ℕ tt
mult = ind ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ u t,c → case
(λ t → (c : El (ℕC t) ℕ u)
(ih : All ℕD (λ u n → ℕ u → ℕ u) u (t , c))
→ ℕ u → ℕ u
)
( (λ q ih n → zero)
, (λ m,q ih,tt n → add n (proj₁ ih,tt n))
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A m = ind (VecD A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ m t,c → case
(λ t → (c : El (VecC A t) (Vec A) m)
(ih : All (VecD A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)) m (t , c))
(n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
)
( (λ q ih n ys → subst (λ m → Vec A (add m n)) q ys)
, (λ m',x,xs,q ih,tt n ys →
let m' = proj₁ m',x,xs,q
x = proj₁ (proj₂ m',x,xs,q)
q = proj₂ (proj₂ (proj₂ m',x,xs,q))
ih = proj₁ ih,tt
in
subst (λ m → Vec A (add m n)) q (cons A (add m' n) x (ih n ys))
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m n = ind (VecD (Vec A m)) (λ n xss → Vec A (mult n m))
(λ n t,c → case
(λ t → (c : El (VecC (Vec A m) t) (Vec (Vec A m)) n)
(ih : All (VecD (Vec A m)) (λ n xss → Vec A (mult n m)) n (t , c))
→ Vec A (mult n m)
)
( (λ q ih → subst (λ n → Vec A (mult n m)) q (nil A))
, (λ n',xs,xss,q ih,tt →
let n' = proj₁ n',xs,xss,q
xs = proj₁ (proj₂ n',xs,xss,q)
q = proj₂ (proj₂ (proj₂ n',xs,xss,q))
ih = proj₁ ih,tt
in
subst (λ n → Vec A (mult n m)) q (append A m xs (mult n' m) ih)
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
----------------------------------------------------------------------
module Eliminator where
elimℕ : (P : (ℕ tt) → Set)
(pzero : P zero)
(psuc : (m : ℕ tt) → P m → P (suc m))
(n : ℕ tt)
→ P n
elimℕ P pzero psuc = ind ℕD (λ u n → P n)
(λ u t,c → case
(λ t → (c : El (ℕC t) ℕ u)
(ih : All ℕD (λ u n → P n) u (t , c))
→ P (con (t , c))
)
( (λ q ih →
elimEq tt (λ u q → P (con (here , q)))
pzero
u q
)
, (λ n,q ih,tt →
elimEq tt (λ u q → P (con (there here , proj₁ n,q , q)))
(psuc (proj₁ n,q) (proj₁ ih,tt))
u (proj₂ n,q)
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
elimVec : (A : Set) (P : (n : ℕ tt) → Vec A n → Set)
(pnil : P zero (nil A))
(pcons : (n : ℕ tt) (a : A) (xs : Vec A n) → P n xs → P (suc n) (cons A n a xs))
(n : ℕ tt)
(xs : Vec A n)
→ P n xs
elimVec A P pnil pcons n = ind (VecD A) (λ n xs → P n xs)
(λ n t,c → case
(λ t → (c : El (VecC A t) (Vec A) n)
(ih : All (VecD A) (λ n xs → P n xs) n (t , c))
→ P n (con (t , c))
)
( (λ q ih →
elimEq zero (λ n q → P n (con (here , q)))
pnil
n q
)
, (λ n',x,xs,q ih,tt →
let n' = proj₁ n',x,xs,q
x = proj₁ (proj₂ n',x,xs,q)
xs = proj₁ (proj₂ (proj₂ n',x,xs,q))
q = proj₂ (proj₂ (proj₂ n',x,xs,q))
ih = proj₁ ih,tt
in
elimEq (suc n') (λ n q → P n (con (there here , n' , x , xs , q)))
(pcons n' x xs ih )
n q
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
----------------------------------------------------------------------
add : ℕ tt → ℕ tt → ℕ tt
add = elimℕ (λ _ → ℕ tt → ℕ tt)
(λ n → n)
(λ m ih n → suc (ih n))
mult : ℕ tt → ℕ tt → ℕ tt
mult = elimℕ (λ _ → ℕ tt → ℕ tt)
(λ n → zero)
(λ m ih n → add n (ih n))
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = elimVec A (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ n ys → ys)
(λ m x xs ih n ys → cons A (add m n) x (ih n ys))
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = elimVec (Vec A m) (λ n xss → Vec A (mult n m))
(nil A)
(λ n xs xss ih → append A m xs (mult n m) ih)
----------------------------------------------------------------------
| 28.944625
| 99
| 0.381274
|
43858fda06af1dbd85accae6afff72b146d88105
| 31,349
|
agda
|
Agda
|
agda/paper/2021-03-Jesper_Cockx-Programming_and_Proving_in_Agda/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/paper/2021-03-Jesper_Cockx-Programming_and_Proving_in_Agda/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/paper/2021-03-Jesper_Cockx-Programming_and_Proving_in_Agda/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module z where
------------------------------------------------------------------------------
-- 1 intro
-- data types
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
--------------------------------------------------
-- begin : from later - here to use in tests
data Bool : Set where
true : Bool
false : Bool
data IsTrue : Bool → Set where
is-true : IsTrue true
_=Nat_ : Nat → Nat → Bool
zero =Nat zero = true
(suc x) =Nat (suc y) = x =Nat y
_ =Nat _ = false
-- end : from later
--------------------------------------------------
-- pattern matching
_+_ : Nat → Nat → Nat
zero + y = y
(suc x) + y = suc (x + y)
infixl 9 _+_
-- {-# BUILTIN NATPLUS _+_ #-}
-- ex 1.1
halve : Nat → Nat
halve zero = zero
halve (suc zero) = zero
halve (suc (suc n)) = suc (halve n)
halve-0 : IsTrue (halve 0 =Nat 0)
halve-0 = is-true
halve-1 : IsTrue (halve 1 =Nat 0)
halve-1 = is-true
halve-2 : IsTrue (halve 2 =Nat 1)
halve-2 = is-true
halve-3 : IsTrue (halve 3 =Nat 1)
halve-3 = is-true
halve-4 : IsTrue (halve 4 =Nat 2)
halve-4 = is-true
halve-14 : IsTrue (halve 14 =Nat 7)
halve-14 = is-true
halve-15 : IsTrue (halve 15 =Nat 7)
halve-15 = is-true
halve-16 : IsTrue (halve 16 =Nat 8)
halve-16 = is-true
-- ex 1.2
_*_ : Nat → Nat → Nat
zero * y = zero
(suc x) * y = y + (x * y)
2*0 : IsTrue ((2 * 0) =Nat 0)
2*0 = is-true
2*1 : IsTrue ((2 * 1) =Nat 2)
2*1 = is-true
2*2 : IsTrue ((2 * 2) =Nat 4)
2*2 = is-true
3*3 : IsTrue ((3 * 3) =Nat 9)
3*3 = is-true
4*4 : IsTrue ((4 * 4) =Nat 16)
4*4 = is-true
{-
-- ex 1.3
data Bool : Set where
true : Bool
false : Bool
-}
not : Bool → Bool
not true = false
not false = true
_&&_ : Bool → Bool → Bool
_&&_ true y = y
_&&_ false _ = false
_||_ : Bool → Bool → Bool
_||_ true _ = true
_||_ false y = y
-- types are 1st class
-- equivalent to Haskell type alias : type MyNat = Nat
MyNat : Set
MyNat = Nat
-- Set used to implement polymorphic functions
idA : (A : Set) → A → A
idA _ x = x
-- implicit args
id : {A : Set} → A → A
id x = x
-- polymorphic data types
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
infixr 5 _::_
-- ex 1.4
length : {A : Set} → List A → Nat
length [] = zero
length (_ :: xs) = 1 + length xs
_++_ : {A : Set} → List A → List A → List A
_++_ [] l2 = l2
_++_ (x :: xs) l2 = x :: xs ++ l2
map : { A B : Set } → (A → B) → List A → List B
map _ [] = []
map f (x :: xs) = f x :: map f xs
-- ex 1.5
data Maybe (A : Set) : Set where
just : A → Maybe A
nothing : Maybe A
lookup : {A : Set} → List A → Nat → Maybe A
lookup [] _ = nothing
lookup (x :: _) zero = just x
lookup (_ :: xs) (suc n) = lookup xs n
_=List-Nat_ : List Nat → List Nat → Bool
[] =List-Nat [] = true
(x :: xs) =List-Nat (y :: ys) = (x =Nat y) && (xs =List-Nat ys)
_ =List-Nat _ = false
ex-xs : List Nat
ex-xs = 0 :: 1 :: 2 :: 3 :: []
length++ : IsTrue ((length ex-xs + length ex-xs) =Nat (length (ex-xs ++ ex-xs)))
length++ = is-true
map2* : IsTrue (map (2 *_) ex-xs =List-Nat (0 :: 2 :: 4 :: 6 :: []))
map2* = is-true
_=Maybe-Nat_ : Maybe Nat → Maybe Nat → Bool
nothing =Maybe-Nat nothing = true
(just x) =Maybe-Nat (just y) = x =Nat y
_ =Maybe-Nat _ = false
lookup[]0 : IsTrue (lookup [] 0 =Maybe-Nat nothing)
lookup[]0 = is-true
lookupex-xs0 : IsTrue (lookup ex-xs 0 =Maybe-Nat (just 0))
lookupex-xs0 = is-true
lookupex-xs1 : IsTrue (lookup ex-xs 1 =Maybe-Nat (just 1))
lookupex-xs1 = is-true
lookupex-xs9 : IsTrue (lookup ex-xs 9 =Maybe-Nat nothing)
lookupex-xs9 = is-true
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
infixr 4 _,_
fst : {A B : Set} → A × B → A
fst (a , _) = a
snd : {A B : Set} → A × B → B
snd (_ , b) = b
-- ex 1.6
-- NO. Regardless of the value of 'Nat', there is NO way to construct an A if given [].
------------------------------------------------------------------------------
-- 2 dependent types
-- parameter : bound for ENTIRE def
-- index : varies according to constructor
-- v v
data Vec (A : Set) : Nat → Set where -- Vec is dependent TYPE
[] : Vec A 0
_::_ : {n : Nat} → A → Vec A n → Vec A (suc n)
--infixr 5 _::_
-- dependent FUNCTION : return TYPE depends on inputs
zeroes : (n : Nat) → Vec Nat n
zeroes zero = []
zeroes (suc n) = 0 :: zeroes n
-- ex 2.1
downFrom : (n : Nat) → Vec Nat n
downFrom zero = []
downFrom (suc n) = n :: downFrom n
_=Vec-Nat_ : {n : Nat} → Vec Nat n → Vec Nat n → Bool
[] =Vec-Nat [] = true
(x :: xs) =Vec-Nat (y :: ys) = (x =Nat y) && (xs =Vec-Nat ys)
downFrom0 : IsTrue (downFrom 0 =Vec-Nat [])
downFrom0 = is-true
downFrom1 : IsTrue (downFrom 1 =Vec-Nat (0 :: []))
downFrom1 = is-true
downFrom2 : IsTrue (downFrom 2 =Vec-Nat (1 :: 0 :: []))
downFrom2 = is-true
downFrom3 : IsTrue (downFrom 3 =Vec-Nat (2 :: 1 :: 0 :: []))
downFrom3 = is-true
downFrom7 : IsTrue (downFrom 7 =Vec-Nat (6 :: 5 :: 4 :: 3 :: 2 :: 1 :: 0 :: []))
downFrom7 = is-true
-- ex 2.2
tail : {A : Set} {n : Nat} → Vec A (suc n) → Vec A n
tail (_ :: xs) = xs
-- ex 2.3
dotProduct : {n : Nat} → Vec Nat n → Vec Nat n → Nat
dotProduct [] [] = 0
dotProduct (x :: xs) (y :: ys) = (x * y) + dotProduct xs ys
dotProduct32 : IsTrue (dotProduct (1 :: 2 :: 3 :: []) (1 :: 5 :: 7 :: []) =Nat 32)
dotProduct32 = is-true
-- finite type family
data Fin : Nat → Set where
zero : {n : Nat} → Fin (suc n)
suc : {n : Nat} → Fin n → Fin (suc n)
lookupVec : {A : Set} {n : Nat} → Vec A n → Fin n → A
lookupVec [] ()
lookupVec (x :: _) zero = x
lookupVec (_ :: xs) (suc i) = lookupVec xs i
-- ex 2.4
putVec : {A : Set} {n : Nat} → Fin n → A → Vec A n → Vec A n
putVec zero a (_ :: xs) = a :: xs
putVec (suc i) a (x :: xs) = x :: putVec i a xs
ex-vxs : Vec Nat 4
ex-vxs = 0 :: 1 :: 2 :: 3 :: []
lookupVecex-vxs0 : IsTrue (lookupVec ex-vxs zero =Nat 0)
lookupVecex-vxs0 = is-true
lookupVecex-vxs3 : IsTrue (lookupVec ex-vxs (suc (suc (suc zero))) =Nat 3)
lookupVecex-vxs3 = is-true
putVecex-vxs3 : IsTrue (putVec (suc (suc zero)) 22 ex-vxs =Vec-Nat (0 :: 1 :: 22 :: 3 :: []))
putVecex-vxs3 = is-true
{-
dependent pair type - aka Σ type
aka Σ type because can be seen as sum (or disjoint union) of all the types B x
- where 1st component is viewed as a label indicating
which type of the family the 2nd belong to
generalization of pair type A × B
- where type of 2nd component can be different depending on value of 1st
- e.g., Σ Nat (Vec Bool)
(or equivalently, Σ Nat (λn → Vec Bool n))
contains elements
2 , (true :: false :: [])
and
0 , []
but not
2 , [] (since [] does not have type Vec Bool 2).
-}
-- function
-- v
data Σ (A : Set) (B : A → Set) : Set where
_,_ : (x : A) → B x → Σ A B
-- see Σ as generalization of normal pair : normal pair ignores its input
_×'_ : (A B : Set) → Set
A ×' B = Σ A (λ _ → B)
-- ex 2.5
×-to-×' : {A B : Set} → (A × B) → (A ×' B)
×-to-×' (a , b) = a , b
×'-to-× : {A B : Set} → (A ×' B) → (A × B)
×'-to-× (a , b) = a , b
-- Σ USE CASE : hide type info
-- e.g., hide length of vector
List' : (A : Set) → Set
List' A = Σ Nat (Vec A)
-- ex 2.6
list-to-vec : {A : Set} → (l : List A) → Vec A (length l)
list-to-vec [] = []
list-to-vec (x :: xs) = x :: list-to-vec xs
vec-to-list : {A : Set} {n : Nat} → Vec A n → List A
vec-to-list [] = []
vec-to-list (x :: xs) = x :: vec-to-list xs
list-to-list' : {A : Set} → List A → List' A
list-to-list' l = length l , list-to-vec l
list'-to-list : {A : Set} → List' A → List A
list'-to-list (_ , v) = vec-to-list v
-- if Nat relations existed at this point this function would be very different
lookup-List' : {A : Set} → List' A -> Nat -> Maybe A
lookup-List' (_ , []) _ = nothing
lookup-List' (_ , (x :: _)) zero = just x
lookup-List' (_ , (_ :: xs)) (suc n) = lookup-List' ((list-to-list' (vec-to-list xs))) n
ex-l'xs : List' Nat
ex-l'xs = (4 , 0 :: 1 :: 2 :: 3 :: [])
lookup-List'[]0 : IsTrue (lookup-List' (0 , []) 0 =Maybe-Nat nothing)
lookup-List'[]0 = is-true
lookup-List'ex-l'xs0 : IsTrue (lookup-List' ex-l'xs 0 =Maybe-Nat (just 0))
lookup-List'ex-l'xs0 = is-true
lookup-List'ex-l'xs1 : IsTrue (lookup-List' ex-l'xs 1 =Maybe-Nat (just 1))
lookup-List'ex-l'xs1 = is-true
lookup-List'ex-l'xs9 : IsTrue (lookup-List' ex-l'xs 9 =Maybe-Nat nothing)
lookup-List'ex-l'xs9 = is-true
------------------------------------------------------------------------------
-- 3 The Curry-Howard correspondence
-- can interpret logical propositions — such as “P and Q”, “not P”, “P implies Q”, ...
-- as types whose inhabitants are valid proofs of that proposition.
--------------------------------------------------
-- PROPOSITIONAL LOGIC
-- ex 3.1
data Either (A B : Set) : Set where
left : A → Either A B
right : B → Either A B
cases : {A B C : Set} → Either A B → (A → C) → (B → C) → C
cases (left a) fac _ = fac a
cases (right b) _ fbc = fbc b
cases-left : IsTrue (cases (left 3) (2 +_) (2 *_) =Nat 5)
cases-left = is-true
cases-right : IsTrue (cases (right 3) (2 +_) (2 *_) =Nat 6)
cases-right = is-true
{-
-------------------------
TRUTH : true : the proposition that always holds no matter what.
Proving it is straightforward: do not need to provide any assumptions.
Assuming true in a proof does not provide any new information.
'true' corresponds to the unit type
-}
data ⊤ : Set where
tt : ⊤
{-
-------------------------
FALSITY. the proposition that is never true.
There are no ways to prove it.
Represented by empty type : datatype with no constructors
-}
data ⊥ : Set where
{-
given a proof p of “false” (which can't happen because no constructors)
- “ex falso quodlibet” : “from falsity follows anything”)
- can can get a proof of any proposition
-}
absurd : {A : Set} → ⊥ → A
absurd ()
{-
-------------------------
NEGATION : the type P → ⊥
EQUIVALENCE. “P is equivalent to Q” as (P → Q) × (Q → P)
Propositional logic versus boolean logic.
types ⊤ and ⊥ seem similar to booleans true and false
- true and false are VALUES : can manipulate and return
- ⊤ and and ⊥ are TYPES
- not possible to check whether a given type ⊤ or ⊥
-}
curryCompose : {P Q R : Set} → (P → Q) × (Q → R) -> (P → R)
curryCompose (f , g) = λ x → g (f x)
-- ex 3.2
if-A-then-B-implies-A : {A B : Set} → A → (B → A)
if-A-then-B-implies-A a = λ _ → a
if-A-and-true-then-A-or-false : {A : Set} → (A × ⊤) → Either A ⊥
if-A-and-true-then-A-or-false (a , ⊤) = left a
uncurry : {A B C : Set} → (A → (B → C)) → (A × B) → C
uncurry f = λ a×b → f (fst a×b) (snd a×b)
ex32x : {A B C : Set} → (A × Either B C) → Either (A × B) (A × C)
ex32x (a , left b) = left (a , b)
ex32x (a , right c) = right (a , c)
ex32y : {A B C D : Set} → ((A → C) × (B → D)) → (A × B) → (C × D)
ex32y (ac , bd) (a , b) = ac a , bd b
{-
--------------------------------------------------
-- PREDICATE LOGIC
to prove propositions that say something about a given VALUE or FUNCTION
e.g., 6 is even
length (map f xs) is equal to length xs for all xs
there exists a number n such that n + n = 12
Curry-Howard : propositions are types
can define new propositions by defining new data types
e.g.,
-}
-- index
-- v
data IsEven : Nat → Set where
even-zero : IsEven zero
even-suc2 : {n : Nat} → IsEven n → IsEven (suc (suc n))
6-is-even : IsEven 6
6-is-even = even-suc2 (even-suc2 (even-suc2 even-zero))
7-is-not-even : IsEven 7 → ⊥
7-is-not-even (even-suc2 (even-suc2 (even-suc2 ())))
-- ^ -- absurb pattern as arg
{-
-- useful predicate
-- states that a given Bool is true
data IsTrue : Bool → Set where
is-true : IsTrue true
_=Nat_ : Nat → Nat → Bool
zero =Nat zero = true
(suc x) =Nat (suc y) = x =Nat y
_ =Nat _ = false
-}
length-is-3 : IsTrue (length (1 :: 2 :: 3 :: []) =Nat 3)
length-is-3 = is-true
{-
Defining properties as functions.
Can define properties as
- data types, or
- functions that return a value of type Set
e..g.,
-}
IsTrue’ : Bool → Set
IsTrue’ true = ⊤
IsTrue’ false = ⊥
{-
Function approach often results in proofs that are shorter, but less readable.
Also less general, as some types (e.g., identity type in next section)
can only be defined as a data type.
BEST PRACTICE: use data types (not functions)
--------------------------------------------------
UNIVERSAL QUANTIFICATION : “∀ x of type A, P(x)”
to prove : provide proof of P(v) for EVERY concrete value v : A.
i.e., a function λv → P v
in opposite direction
assume a f of “∀ x of type A, P(x)”
and given a concrete v : A
then can the proof to the case of v to get a proof f v of P(v)
under Curry-Howard, universal quantification corresponds to dependent function
(x : A) → P x
-}
double : Nat → Nat
double zero = zero
double (suc n) = suc (suc (double n))
-- ∀ n : Nat, double n is an even number
-- 'double-is-even' is a dependent function : return TYPE depends on input VALUE
-- pattern matching here is "proof by cases"
-- recursion here is "induction on n"
double-is-even : (n : Nat) → IsEven (double n)
double-is-even zero = even-zero
double-is-even (suc m) = even-suc2 (double-is-even m)
n-equals-n : (n : Nat) → IsTrue (n =Nat n)
n-equals-n zero = is-true
n-equals-n (suc m) = n-equals-n m
{-
--------------------------------------------------
EXISTENTIAL QUANTIFICATION : “∃ a x : A such that P( x )”
to prove : provide a concrete v : A, and a proof that P(v) holds
i.e. a pair (v : A, P v)
in opposite direction
given proof z of “∃ a x : A such that P( x )”
then extract the witness fst z : A
and the proof snd z : P (fst z)
under Curry-Howard, existential quantification corresponds to the dependent pair type
Σ A ( λ x → P x ).
-}
-- ∃ an n such that n + n = 12
half-a-dozen : Σ Nat (λ n → IsTrue ((n + n) =Nat 12))
half-a-dozen = 6 , is-true
-- any number n is either 0 or the successor of another number m
-- ∀ n, n is 0
-- or ∃ m such that n is suc m
zero-or-suc : (n : Nat) → Either (IsTrue (n =Nat 0))
(Σ Nat (λ m → IsTrue (n =Nat (suc m))))
zero-or-suc zero = left is-true
zero-or-suc (suc m) = right (m , n-equals-n m)
{-
--------------------------------------------------
Propositional logic Type System
------------------------------------------------------------
proposition P type
proof of a proposition p : P program of a type
conjunction P × Q pair type
disjunction Either P Q either type
implication P → Q function type
truth ⊤ unit type
falsity ⊥ empty type
negation P → ⊥ function to ⊥
equivalence (P → Q) × (Q → P) pair of two functions
------------------------------------------------------------
Predicate log
universal quantification (x : A) → P x dependent function type
existential quantification Σ A (λ x → P x ) dependent pair type
--------------------------------------------------
-- IDENTITY TYPE : EQUALITY at any type (to avoid =Nat, =Vec-Nat, ...)
Martin-Löf introduced a new type x ≡ y, called the IDENTITY TYPE (NOT FUNCTION)
if x and y are equal, then x ≡ y has a single inhabitant refl
- behaves like the unit type ⊤
if x and y are distinct, then x ≡ y has no constructors
- behaves like the empty type ⊥
-}
data _≡_ {A : Set} : A → A → Set where
-- ‘reflexivity’
refl : {x : A} → x ≡ x
infix 4 _≡_
{-# BUILTIN EQUALITY _≡_ #-}
one-plus-one-IsTrue : IsTrue ((1 + 1) =Nat 2)
one-plus-one-IsTrue = is-true
one-plus-one : 1 + 1 ≡ 2
one-plus-one = refl
{-
zero-not-one-not-IsTrue : IsTrue (0 =Nat 1)
zero-not-one-not-IsTrue = {!!}
-}
zero-not-one : 0 ≡ 1 → ⊥
zero-not-one ()
-- prove facts about polymorphic types
id-returns-input : {A : Set}
→ (x : A)
→ id x ≡ x
id-returns-input _ = refl
-- unit tests using identity type
length-test1 : length (1 :: 2 :: []) ≡ 2
length-test1 = refl
-- symmetry of equality
sym : {A : Set} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
-- transitivity of equality
trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
-- congruence of equality
cong : {A B : Set} {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
{-
If a and b can be unified by instantiating some of the variables, then can match on refl.
If a and b are different (e.g. different constructors), then match on absurb pattern ().
Agda canNOT always tell if they are different.
-}
------------------------------------------------------------------------------
-- 4 EQUATIONAL REASONING
begin_ : {A : Set} → {x y : A} → x ≡ y → x ≡ y
begin p = p
_end : {A : Set} → (x : A) → x ≡ x
x end = refl
_=⟨_⟩_ : {A : Set} → (x : A) → {y z : A} → x ≡ y → y ≡ z → x ≡ z
x =⟨ p ⟩ q = trans p q
_=⟨⟩_ : {A : Set} → (x : A) → {y : A} → x ≡ y → x ≡ y
x =⟨⟩ q = x =⟨ refl ⟩ q
infix 1 begin_
infix 3 _end
infixr 2 _=⟨_⟩_
infixr 2 _=⟨⟩_
-- create singleton list
[_] : {A : Set} → A → List A
[ x ] = x :: []
reverse : {A : Set} → List A → List A
reverse [] = []
reverse (x :: xs) = reverse xs ++ [ x ]
-- reverse has no effect on singleton lists
reverse-singleton : {A : Set}
→ (x : A)
→ reverse [ x ] ≡ [ x ]
reverse-singleton x =
begin
reverse [ x ] =⟨⟩ -- definition of [_]
reverse (x :: []) =⟨⟩ -- applying reverse (second clause)
reverse [] ++ [ x ] =⟨⟩ -- applying reverse (first clause)
[] ++ [ x ] =⟨⟩ -- applying _++_
[ x ]
end
-- proof by cases and induction
not-not : (b : Bool)
→ not (not b) ≡ b
not-not true =
begin
not (not true) =⟨⟩
not false =⟨⟩ -- apply inner not
true -- apply not
end
not-not false =
begin
not (not false) =⟨⟩
not true =⟨⟩
false
end
-- prove fact about Nat by induction (i.e., recursion)
add-n-zero : (n : Nat)
→ n + zero ≡ n
add-n-zero zero =
begin
zero + zero =⟨⟩
zero =⟨⟩
zero
end
add-n-zero (suc n) =
begin
(suc n) + zero =⟨⟩ -- applying +
suc (n + zero) =⟨ cong suc (add-n-zero n) ⟩ -- using induction hypothesis
suc n
end
add-n-zero' : (n : Nat)
→ n + zero ≡ n
add-n-zero' zero = refl
add-n-zero' (suc n) = cong suc (add-n-zero' n)
add-assoc : (x y z : Nat)
→ x + (y + z) ≡ (x + y) + z
add-assoc zero y z =
begin
zero + (y + z) =⟨⟩ -- def of +
y + z =⟨⟩ -- unapply +
(zero + y) + z
end
add-assoc (suc x) y z =
begin
(suc x) + (y + z) =⟨⟩ -- def of +
suc (x + (y + z)) =⟨ cong suc (add-assoc x y z) ⟩ -- inductive hypo
suc ((x + y) + z) =⟨⟩ -- unapply outer add
(suc (x + y)) + z =⟨⟩ -- unapply inner add
((suc x) + y) + z
end
-- ex 4.1
add-suc : (m n : Nat)
→ m + suc n ≡ suc (m + n)
add-suc zero n =
begin
zero + suc n =⟨⟩ -- def of +
suc n =⟨⟩
suc (zero + n)
end
add-suc (suc m) n = -- cong suc (add-suc m n)
begin
suc m + suc n =⟨⟩ -- def of +
suc (m + suc n) =⟨ cong suc (add-suc m n) ⟩
suc (suc m + n)
end
--use add-suc and add-n-zero
+-comm : (m n : Nat)
→ m + n ≡ n + m
+-comm zero n = sym (add-n-zero n)
+-comm (suc m) n
rewrite -- suc m + n ≡ n + suc m
-- suc (m + n) ≡ n + suc m
+-comm m n -- suc (n + m) ≡ n + suc m
| sym (add-suc n m) -- n + suc m ≡ n + suc m
= refl
+-comm' : (m n : Nat)
→ m + n ≡ n + m
+-comm' zero n =
begin
zero + n =⟨⟩ -- def of +
n =⟨ sym (add-n-zero n) ⟩ -- add zero to right
n + zero
end
+-comm' (suc m) n =
begin
suc m + n =⟨⟩ -- def of +
suc (m + n) =⟨ cong suc (+-comm m n) ⟩
suc (n + m) =⟨ sym (add-suc n m) ⟩
n + suc m
end
--------------------------------------------------
-- induction on lists
-- ex 4.2
replicate : {A : Set} → Nat → A → List A
replicate zero x = []
replicate (suc n) x = x :: replicate n x
length-replicate : {A : Set} {a : A}
→ (n : Nat)
→ length (replicate n a) ≡ n
length-replicate zero = refl
length-replicate (suc n) = cong suc (length-replicate n)
-- ex 4.3
append-[] : {A : Set}
→ (xs : List A)
→ xs ++ [] ≡ xs
append-[] [] = refl
append-[] (x :: xs) = cong (x ::_) (append-[] xs)
append-assoc : {A : Set}
→ (xs ys zs : List A)
→ (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
append-assoc [] ys zs = refl
append-assoc (x :: xs) ys zs -- (((x :: xs) ++ ys) ++ zs) ≡ ((x :: xs) ++ (ys ++ zs))
-- x :: ((xs ++ ys) ++ zs) ≡ x :: (xs ++ (ys ++ zs))
= cong (x ::_) (append-assoc xs ys zs)
reverse-distributivity : {A : Set}
→ (xs ys : List A)
→ reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-distributivity [] ys = sym (append-[] (reverse ys))
reverse-distributivity (x :: xs) ys
-- reverse ((x :: xs) ++ ys) ≡ (reverse ys ++ reverse (x :: xs))
-- (reverse (xs ++ ys) ++ (x :: [])) ≡ (reverse ys ++ (reverse xs ++ (x :: [])))
rewrite
reverse-distributivity xs ys
-- ((reverse ys ++ reverse xs) ++ (x :: []))
-- ≡ (reverse ys ++ (reverse xs ++ (x :: [])))
| sym (append-assoc (reverse ys) (reverse xs) (x :: []))
= refl
reverse-reverse : {A : Set}
→ (xs : List A)
→ reverse (reverse xs) ≡ xs
reverse-reverse [] = refl
reverse-reverse (x :: xs) -- reverse (reverse (x :: xs)) ≡ x :: xs
-- reverse (reverse xs ++ (x :: [])) ≡ x :: xs
rewrite
-- NOTE
-- v
reverse-distributivity (reverse xs) [ x ]
-- x :: reverse (reverse xs) ≡ x :: xs
-- can rewrite here then refl
--| reverse-reverse xs -- x :: xs ≡ x :: xs
--= refl
-- or use 'cong' on rightof '='
= cong (x ::_) (reverse-reverse xs)
{-
map satisfies functor laws:
- identity : map id = id
- composition : map (g . h) = map g . h
-}
map-id : {A : Set}
→ (xs : List A)
→ map id xs ≡ xs
map-id [] = refl
map-id (x :: xs) -- map id (x :: xs) ≡ x :: xs
-- id x :: map id xs ≡ x :: xs
= cong (x ::_) (map-id xs)
_◦_ : {A B C : Set} → (B → C) → (A → B) → (A → C)
g ◦ h = λ x → g (h x)
map-compose : {A B C : Set}
→ (f : B → C) → (g : A → B) → (xs : List A)
→ map (f ◦ g) xs ≡ map f (map g xs)
map-compose f g [] = refl
map-compose f g (x :: xs)
-- map (f ◦ g) (x :: xs) ≡ map f (map g (x :: xs))
-- (f ◦ g) x :: map (f ◦ g) xs ≡ f (g x) :: map f (map g xs)
{- this
rewrite
sym (map-compose f g xs)
-- f (g x) :: map (λ x₁ → f (g x₁)) xs ≡
f (g x) :: map (λ x₁ → f (g x₁)) xs
= refl
-}
-- or this
= cong (f (g x) ::_) (map-compose f g xs)
-- ex 4.4
length-map : {A B : Set} {f : A → B}
→ (xs : List A)
→ length (map f xs) ≡ length xs
length-map [] = refl
length-map (x :: xs) -- length (map f (x :: xs)) ≡ length (x :: xs)
-- suc (length (map f xs)) ≡ suc (length xs)
= cong suc (length-map xs)
-- ex 4.5
take : {A : Set} → List A → Nat → List A
take _ zero = []
take [] (suc n) = []
take (x :: xs) (suc n) = x :: take xs n
take-0 : take ex-xs 0 ≡ []
take-0 = refl
take-1 : take ex-xs 1 ≡ 0 :: []
take-1 = refl
take-2 : take ex-xs 2 ≡ 0 :: 1 :: []
take-2 = refl
take-3 : take ex-xs 3 ≡ 0 :: 1 :: 2 :: []
take-3 = refl
take-4 : take ex-xs 4 ≡ ex-xs
take-4 = refl
take-5 : take ex-xs 5 ≡ ex-xs
take-5 = refl
drop : {A : Set} → List A → Nat → List A
drop xs zero = xs
drop [] (suc x) = []
drop (_ :: xs) (suc n) = drop xs n
drop-0 : drop ex-xs 0 ≡ ex-xs
drop-0 = refl
drop-1 : drop ex-xs 1 ≡ 1 :: 2 :: 3 :: []
drop-1 = refl
drop-2 : drop ex-xs 2 ≡ 2 :: 3 :: []
drop-2 = refl
drop-3 : drop ex-xs 3 ≡ 3 :: []
drop-3 = refl
drop-4 : drop ex-xs 4 ≡ []
drop-4 = refl
drop-5 : drop ex-xs 5 ≡ []
drop-5 = refl
take-drop : {A : Set} → (xs : List A) → (n : Nat) → take xs n ++ drop xs n ≡ xs
take-drop [] zero = refl
take-drop [] (suc n) = refl
take-drop (x :: xs) zero = refl
take-drop (x :: xs) (suc n) -- (take (x :: xs) (suc n) ++ drop (x :: xs) (suc n)) ≡ x :: xs
-- x :: (take xs n ++ drop xs n) ≡ x :: xs
= cong (x ::_) (take-drop xs n)
--------------------------------------------------
-- verifying optimizations
-- list optimization
reverse-acc : {A : Set} → List A → List A → List A
reverse-acc [] ys = ys
reverse-acc (x :: xs) ys = reverse-acc xs (x :: ys)
reverse' : {A : Set} → List A → List A
reverse' xs = reverse-acc xs []
reverse-acc-lemma : {A : Set}
→ (xs ys : List A)
→ reverse-acc xs ys ≡ reverse xs ++ ys
reverse-acc-lemma [] _ = refl
reverse-acc-lemma (x :: xs) ys -- reverse-acc (x :: xs) ys ≡ (reverse (x :: xs) ++ ys)
-- reverse-acc xs (x :: ys) ≡ ((reverse xs ++ (x :: [])) ++ ys)
rewrite
append-assoc (reverse xs) [ x ] ys
-- reverse-acc xs (x :: ys) ≡ (reverse xs ++ (x :: ys))
| reverse-acc-lemma xs (x :: ys)
-- (reverse xs ++ (x :: ys)) ≡ (reverse xs ++ (x :: ys))
= refl
reverse'-reverse : {A : Set}
→ (xs : List A)
→ reverse' xs ≡ reverse xs
reverse'-reverse [] = refl
reverse'-reverse (x :: xs) -- reverse' (x :: xs) ≡ reverse (x :: xs)
-- reverse' (x :: xs) ≡ (reverse xs ++ (x :: []))
rewrite
reverse-acc-lemma xs [ x ] -- (reverse xs ++ (x :: [])) ≡ (reverse xs ++ (x :: []))
= refl
-- tree optimization
data Tree (A : Set) : Set where
leaf : A → Tree A
node : Tree A → Tree A → Tree A
flatten : {A : Set} → Tree A → List A
flatten (leaf a) = [ a ]
flatten (node t1 t2) = flatten t1 ++ flatten t2
flatten-acc : {A : Set} → Tree A → List A → List A
flatten-acc (leaf x) xs = x :: xs
flatten-acc (node t1 t2) xs = flatten-acc t1 (flatten-acc t2 xs)
flatten' : {A : Set} → Tree A → List A
flatten' t = flatten-acc t []
flatten-acc-lemma : {A : Set}
→ (t : Tree A) → (ys : List A)
→ flatten-acc t ys ≡ flatten t ++ ys
flatten-acc-lemma (leaf x) _ = refl
flatten-acc-lemma (node t1 t2) ys
-- flatten-acc (node t1 t2) ys ≡ (flatten (node t1 t2) ++ ys)
-- flatten-acc t1 (flatten-acc t2 ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
rewrite
flatten-acc-lemma t1 (flatten-acc t2 ys)
-- (flatten t1 ++ flatten-acc t2 ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| flatten-acc-lemma t2 ys
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| append-assoc (flatten t1) (flatten t2) ys
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ (flatten t1 ++ (flatten t2 ++ ys))
= refl
flatten-acc-flatten : {A : Set}
→ (t : Tree A) → (ys : List A)
→ flatten-acc t ys ≡ flatten t ++ ys
flatten-acc-flatten (leaf x) ys = refl
-- flatten-acc (leaf x) ys ≡ (flatten (leaf x) ++ ys)
flatten-acc-flatten (node t1 t2) ys
-- flatten-acc (node t1 t2) ys ≡ (flatten (node t1 t2) ++ ys)
-- flatten-acc t1 (flatten-acc t2 ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
rewrite
flatten-acc-lemma t2 ys
-- flatten-acc t1 (flatten t2 ++ ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| flatten-acc-lemma t1 (flatten t2 ++ ys)
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| append-assoc (flatten t1) (flatten t2) ys
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ (flatten t1 ++ (flatten t2 ++ ys))
= refl
-- ex 4.6
flatten'-flatten : {A : Set}
→ (t : Tree A)
→ flatten' t ≡ flatten t
flatten'-flatten (leaf x) = refl
flatten'-flatten (node t1 t2)
-- flatten' (node t1 t2) ≡ flatten (node t1 t2)
-- flatten' (node t1 t2) ≡ (flatten t1 ++ flatten t2)
rewrite
sym (flatten-acc-flatten t1 (flatten t2))
-- flatten-acc t1 (flatten-acc t2 []) ≡ flatten-acc t1 (flatten t2)
| flatten-acc-flatten t2 []
-- flatten-acc t1 (flatten t2 ++ []) ≡ flatten-acc t1 (flatten t2)
| append-[] (flatten t2)
-- flatten-acc t1 (flatten t2) ≡ flatten-acc t1 (flatten t2)
= refl
--------------------------------------------------
-- compiler correctness
data Expr : Set where
valE : Nat → Expr
addE : Expr → Expr → Expr
eval : Expr → Nat
eval (valE x) = x
eval (addE e1 e2) = eval e1 + eval e2
data Op : Set where
PUSH : Nat → Op
ADD : Op
Stack = List Nat
Code = List Op
exec : Code → Stack → Stack
exec [] s = s
exec (PUSH x :: c) s = exec c (x :: s)
exec (ADD :: c) (m :: n :: s) = exec c (n + m :: s)
exec (ADD :: c) _ = []
compile' : Expr → Code → Code
compile' (valE x) c = PUSH x :: c
compile' (addE e1 e2) c = compile' e1 (compile' e2 (ADD :: c))
compile : Expr → Code
compile e = compile' e []
compile'-exec-eval : (e : Expr) → (s : Stack) → (c : Code)
→ exec (compile' e c) s ≡ exec c (eval e :: s)
compile'-exec-eval (valE _) _ _ = refl
compile'-exec-eval (addE e1 e2) s c
-- exec (compile' (addE e1 e2) c) s ≡ exec c (eval (addE e1 e2) :: s)
-- exec (compile' e1 (compile' e2 (ADD :: c))) s ≡ exec c (eval e1 + eval e2 :: s)
rewrite
compile'-exec-eval e1 s (compile' e2 (ADD :: c))
-- exec (compile' e2 (ADD :: c)) (eval e1 :: s) ≡ exec c (eval e1 + eval e2 :: s)
| compile'-exec-eval e2 (eval e1 :: s) (ADD :: c)
-- exec c (eval e1 + eval e2 :: s) ≡ exec c (eval e1 + eval e2 :: s)
= refl
compile-exec-eval : (e : Expr) → exec (compile e) [] ≡ [ eval e ]
compile-exec-eval e = compile'-exec-eval e [] []
| 29.714692
| 99
| 0.492424
|
37b7ddc91dcd3155516f58f98b67a45444a61ae3
| 1,972
|
agda
|
Agda
|
homotopy/3x3/ToFrom.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/3x3/ToFrom.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/3x3/ToFrom.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
--open import HoTT
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
import homotopy.3x3.To as To
import homotopy.3x3.From as From
open import homotopy.3x3.Common
module homotopy.3x3.ToFrom {i} (d : Span^2 {i}) where
open Span^2 d
open M d hiding (Pushout^2)
open M (transpose d) using () renaming (A₀∙ to A∙₀; A₂∙ to A∙₂; A₄∙ to A∙₄;
module F₁∙ to F∙₁; f₁∙ to f∙₁;
module F₃∙ to F∙₃; f₃∙ to f∙₃;
v-h-span to h-v-span)
open M using (Pushout^2)
open To d
open From d
open import homotopy.3x3.ToFromInit d
open import homotopy.3x3.ToFrom2 d
open import homotopy.3x3.ToFrom3 d
to-from-g-g : (c : A₂₂) → (to-from-g-l (f₁₂ c) , ↓-='-out (apd (to-from-r ∘ f∙₃) (glue c)) , ↓-='-out (apd (ap to ∘ ap from ∘ glue) (glue c))
=□□ ↓-='-out (apd glue (glue c)) , ↓-='-out (apd (to-from-l ∘ f∙₁) (glue c)) , to-from-g-r (f₃₂ c))
to-from-g-g c = coh _ lemma1 lemma3 _ _ (↓-='-out (apd glue (glue c))) lemma2
where
open M2 c
open M3 c
to-from-g-g' : (c : A₂₂) → to-from-g-l (f₁₂ c) == to-from-g-r (f₃₂ c) [ (λ c → (to-from-l (f∙₁ c) , glue c =□ ap to (ap from (glue c)) , to-from-r (f∙₃ c))) ↓ glue c ]
to-from-g-g' c = ↓-=□-in (to-from-g-g c)
module ToFromG = PushoutElim {d = span _ _ _ f₁₂ f₃₂} {P = λ c → (to-from-l (f∙₁ c) , glue c =□ ap to (ap from (glue c)) , to-from-r (f∙₃ c))}
to-from-g-l to-from-g-r to-from-g-g'
to-from-g : (c : A∙₂) → (to-from-l (f∙₁ c) , glue c =□ ap to (ap from (glue c)) , to-from-r (f∙₃ c))
to-from-g = ToFromG.f
to-from-g' : (c : A∙₂) → to-from-l (f∙₁ c) == to-from-r (f∙₃ c) [ (λ z → to (from z) == z) ↓ glue c ]
to-from-g' c = ↓-∘=idf-in to from (to-from-g c)
to-from : (x : Pushout^2 (transpose d)) → to (from x) == x
to-from = Pushout-elim to-from-l to-from-r to-from-g'
| 41.083333
| 167
| 0.535497
|
7226c4e90eb34d574b26630971ad15471e7d2480
| 622
|
agda
|
Agda
|
test/Succeed/Issue383b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue383b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue383b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2011-05-09
-- {-# OPTIONS -v tc.inj:40 -v tc.meta:30 #-}
module Issue383b where
postulate
Σ : (A : Set) → (A → Set) → Set
U : Set
El : U → Set
mutual
data Ctxt : Set where
_▻_ : (Γ : Ctxt) → (Env Γ → U) → Ctxt
Env : Ctxt → Set
Env (Γ ▻ σ) = Σ (Env Γ) λ γ → El (σ γ)
postulate
Δ : Ctxt
σ : Env Δ → U
δ : U → Env (Δ ▻ σ)
data Foo : (Γ : Ctxt) → (U → Env Γ) → Set where
foo : Foo _ δ
-- WORKS NOW; OLD COMPLAINT:
-- Agda does not solve or simplify the following constraint. Why? Env
-- is constructor-headed.
--
-- _40 := δ if [(Σ (Env Δ) (λ γ → El (σ γ))) =< (Env _39) : Set]
| 20.064516
| 69
| 0.53537
|
643f05a3bb85f0ca6989d2be0c6c24fa37ad843b
| 8,218
|
agda
|
Agda
|
agda/Pi.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
agda/Pi.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
agda/Pi.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --no-termination-check #-}
module Pi where
open import Data.Empty
open import Data.Unit
open import Data.Sum hiding (map)
open import Data.Product hiding (map)
open import Relation.Binary.PropositionalEquality hiding (sym; [_])
infixr 30 _⟷_
infixr 30 _⟺_
infixr 20 _◎_
------------------------------------------------------------------------------
-- A universe of our value types
data B : Set where
ZERO : B
ONE : B
PLUS : B → B → B
TIMES : B → B → B
⟦_⟧ : B → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS b1 b2 ⟧ = ⟦ b1 ⟧ ⊎ ⟦ b2 ⟧
⟦ TIMES b1 b2 ⟧ = ⟦ b1 ⟧ × ⟦ b2 ⟧
------------------------------------------------------------------------------
-- Primitive isomorphisms
data _⟷_ : B → B → Set where
-- (+,0) commutative monoid
unite₊ : { b : B } → PLUS ZERO b ⟷ b
uniti₊ : { b : B } → b ⟷ PLUS ZERO b
swap₊ : { b₁ b₂ : B } → PLUS b₁ b₂ ⟷ PLUS b₂ b₁
assocl₊ : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷ PLUS (PLUS b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷ PLUS b₁ (PLUS b₂ b₃)
-- (*,1) commutative monoid
unite⋆ : { b : B } → TIMES ONE b ⟷ b
uniti⋆ : { b : B } → b ⟷ TIMES ONE b
swap⋆ : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷ TIMES b₂ b₁
assocl⋆ : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷ TIMES (TIMES b₁ b₂) b₃
assocr⋆ : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷ TIMES b₁ (TIMES b₂ b₃)
-- * distributes over +
dist : { b₁ b₂ b₃ : B } →
TIMES (PLUS b₁ b₂) b₃ ⟷ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
factor : { b₁ b₂ b₃ : B } →
PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷ TIMES (PLUS b₁ b₂) b₃
-- id
id⟷ : { b : B } → b ⟷ b
adjointP : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)
adjointP unite₊ = uniti₊
adjointP uniti₊ = unite₊
adjointP swap₊ = swap₊
adjointP assocl₊ = assocr₊
adjointP assocr₊ = assocl₊
adjointP unite⋆ = uniti⋆
adjointP uniti⋆ = unite⋆
adjointP swap⋆ = swap⋆
adjointP assocl⋆ = assocr⋆
adjointP assocr⋆ = assocl⋆
adjointP dist = factor
adjointP factor = dist
adjointP id⟷ = id⟷
evalP : { b₁ b₂ : B } → (b₁ ⟷ b₂) → ⟦ b₁ ⟧ → ⟦ b₂ ⟧
evalP unite₊ (inj₁ ())
evalP unite₊ (inj₂ v) = v
evalP uniti₊ v = inj₂ v
evalP swap₊ (inj₁ v) = inj₂ v
evalP swap₊ (inj₂ v) = inj₁ v
evalP assocl₊ (inj₁ v) = inj₁ (inj₁ v)
evalP assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
evalP assocl₊ (inj₂ (inj₂ v)) = inj₂ v
evalP assocr₊ (inj₁ (inj₁ v)) = inj₁ v
evalP assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
evalP assocr₊ (inj₂ v) = inj₂ (inj₂ v)
evalP unite⋆ (tt , v) = v
evalP uniti⋆ v = (tt , v)
evalP swap⋆ (v₁ , v₂) = (v₂ , v₁)
evalP assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
evalP assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
evalP dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
evalP dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
evalP factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
evalP factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
evalP id⟷ v = v
-- Backwards evaluator
bevalP : { b₁ b₂ : B } → (b₁ ⟷ b₂) → ⟦ b₂ ⟧ → ⟦ b₁ ⟧
bevalP c v = evalP (adjointP c) v
------------------------------------------------------------------------------
-- Closure combinators
data _⟺_ : B → B → Set where
iso : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₁ ⟺ b₂)
sym : { b₁ b₂ : B } → (b₁ ⟺ b₂) → (b₂ ⟺ b₁)
_◎_ : { b₁ b₂ b₃ : B } → (b₁ ⟺ b₂) → (b₂ ⟺ b₃) → (b₁ ⟺ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟺ b₃) → (b₂ ⟺ b₄) → (PLUS b₁ b₂ ⟺ PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟺ b₃) → (b₂ ⟺ b₄) → (TIMES b₁ b₂ ⟺ TIMES b₃ b₄)
--
adjoint : { b₁ b₂ : B } → (b₁ ⟺ b₂) → (b₂ ⟺ b₁)
adjoint (iso c) = iso (adjointP c)
adjoint (sym c) = c
adjoint (c₁ ◎ c₂) = adjoint c₂ ◎ adjoint c₁
adjoint (c₁ ⊕ c₂) = adjoint c₁ ⊕ adjoint c₂
adjoint (c₁ ⊗ c₂) = adjoint c₁ ⊗ adjoint c₂
--
-- (Context a b c d) represents a combinator (c <-> d) with a hole
-- requiring something of type (a <-> b). When we use these contexts,
-- it is always the case that the (c <-> a) part of the computation
-- has ALREADY been done and that we are about to evaluate (a <-> b)
-- using a given 'a'. The continuation takes the output 'b' and
-- produces a 'd'.
data Context : B → B → B → B → Set where
emptyC : {a b : B} → Context a b a b
seqC₁ : {a b c i o : B} → (b ⟺ c) → Context a c i o → Context a b i o
seqC₂ : {a b c i o : B} → (a ⟺ b) → Context a c i o → Context b c i o
leftC : {a b c d i o : B} →
(c ⟺ d) → Context (PLUS a c) (PLUS b d) i o → Context a b i o
rightC : {a b c d i o : B} →
(a ⟺ b) → Context (PLUS a c) (PLUS b d) i o → Context c d i o
-- the (i <-> a) part of the computation is completely done; so we must store
-- the value of type [[ c ]] as part of the context
fstC : {a b c d i o : B} →
⟦ c ⟧ → (c ⟺ d) → Context (TIMES a c) (TIMES b d) i o → Context a b i o
-- the (i <-> c) part of the computation and the (a <-> b) part of
-- the computation are completely done; so we must store the value
-- of type [[ b ]] as part of the context
sndC : {a b c d i o : B} →
(a ⟺ b) → ⟦ b ⟧ → Context (TIMES a c) (TIMES b d) i o → Context c d i o
-- Evaluation
mutual
-- The (c <-> a) part of the computation has been done.
-- We have an 'a' and we are about to do the (a <-> b) computation.
-- We get a 'b' and examine the context to get the 'd'
eval_c : { a b c d : B } → (a ⟺ b) → ⟦ a ⟧ → Context a b c d → ⟦ d ⟧
eval_c (iso f) v C = eval_k (iso f) (evalP f v) C
eval_c (sym c) v C = eval_c (adjoint c) v C
eval_c (f ◎ g) v C = eval_c f v (seqC₁ g C)
eval_c (f ⊕ g) (inj₁ v) C = eval_c f v (leftC g C)
eval_c (f ⊕ g) (inj₂ v) C = eval_c g v (rightC f C)
eval_c (f ⊗ g) (v₁ , v₂) C = eval_c f v₁ (fstC v₂ g C)
-- The (c <-> a) part of the computation has been done.
-- The (a <-> b) part of the computation has been done.
-- We need to examine the context to get the 'd'.
-- We rebuild the combinator on the way out.
eval_k : { a b c d : B } → (a ⟺ b) → ⟦ b ⟧ → Context a b c d → ⟦ d ⟧
eval_k f v emptyC = v
eval_k f v (seqC₁ g C) = eval_c g v (seqC₂ f C)
eval_k g v (seqC₂ f C) = eval_k (f ◎ g) v C
eval_k f v (leftC g C) = eval_k (f ⊕ g) (inj₁ v) C
eval_k g v (rightC f C) = eval_k (f ⊕ g) (inj₂ v) C
eval_k f v₁ (fstC v₂ g C) = eval_c g v₂ (sndC f v₁ C)
eval_k g v₂ (sndC f v₁ C) = eval_k (f ⊗ g) (v₁ , v₂) C
-- Backwards evaluator
mutual
-- The (d <-> b) part of the computation has been done.
-- We have a 'b' and we are about to do the (a <-> b) computation backwards.
-- We get an 'a' and examine the context to get the 'c'
beval_c : { a b c d : B } → (a ⟺ b) → ⟦ b ⟧ → Context a b c d → ⟦ c ⟧
beval_c (iso f) v C = beval_k (iso f) (bevalP f v) C
beval_c (sym c) v C = beval_c (adjoint c) v C
beval_c (f ◎ g) v C = beval_c g v (seqC₂ f C)
beval_c (f ⊕ g) (inj₁ v) C = beval_c f v (leftC g C)
beval_c (f ⊕ g) (inj₂ v) C = beval_c g v (rightC f C)
beval_c (f ⊗ g) (v₁ , v₂) C = beval_c g v₂ (sndC f v₁ C)
-- The (d <-> b) part of the computation has been done.
-- The (a <-> b) backwards computation has been done.
-- We have an 'a' and examine the context to get the 'c'
beval_k : { a b c d : B } → (a ⟺ b) → ⟦ a ⟧ → Context a b c d → ⟦ c ⟧
beval_k f v emptyC = v
beval_k g v (seqC₂ f C) = beval_c f v (seqC₁ g C)
beval_k f v (seqC₁ g C) = beval_k (f ◎ g) v C
beval_k f v (leftC g C) = beval_k (f ⊕ g) (inj₁ v) C
beval_k g v (rightC f C) = beval_k (f ⊕ g) (inj₂ v) C
beval_k g v₂ (sndC f v₁ C) = beval_c f v₁ (fstC v₂ g C)
beval_k f v₁ (fstC v₂ g C) = beval_k (f ⊗ g) (v₁ , v₂) C
------------------------------------------------------------------------------
-- Proposition 'Reversible'
-- eval_c : { a b c d : B } → (a ⟺ b) → ⟦ a ⟧ → Context a b c d → ⟦ d ⟧
-- eval_k : { a b c d : B } → (a ⟺ b) → ⟦ b ⟧ → Context a b c d → ⟦ d ⟧
-- beval_c : { a b c d : B } → (a ⟺ b) → ⟦ b ⟧ → Context a b c d → ⟦ c ⟧
-- beval_k : { a b c d : B } → (a ⟺ b) → ⟦ a ⟧ → Context a b c d → ⟦ c ⟧
-- Prop. 2.2
{-
logical-reversibility : {a b : B} {f : a ⟺ b} {va : ⟦ a ⟧} {vb : ⟦ b ⟧} →
eval_c f va emptyC ≡ eval_k f vb emptyC →
eval_c (adjoint f) vb emptyC ≡ eval_k (adjoint f) va emptyC
logical-reversibility = λ fwd≡bwd → {!!}
-}
------------------------------------------------------------------------------
| 37.697248
| 80
| 0.520321
|
73911edaa3f6823f38973634630504b8438082a1
| 60
|
agda
|
Agda
|
test/interaction/Imports/Issue5357-B.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Imports/Issue5357-B.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Imports/Issue5357-B.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Imports.Issue5357-B where
import Imports.Issue5357-D
| 20
| 32
| 0.85
|
0df2ad0ce5f4c3258ce0068bfd7fbce8a4192b4a
| 19,277
|
agda
|
Agda
|
models/IDescTT.agda
|
dataronio/epigram2
|
17b7858f51a35b3becb8433028c3f1ba25fbba9a
|
[
"MIT"
] | 48
|
2016-01-09T17:36:19.000Z
|
2022-02-11T01:55:28.000Z
|
models/IDescTT.agda
|
seanwallawalla-forks/Epigram
|
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
|
[
"MIT"
] | null | null | null |
models/IDescTT.agda
|
seanwallawalla-forks/Epigram
|
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
|
[
"MIT"
] | 12
|
2016-08-14T21:36:35.000Z
|
2022-02-11T01:57:40.000Z
|
{-# OPTIONS --type-in-type #-}
module IDescTT where
--********************************************
-- Prelude
--********************************************
-- Some preliminary stuffs, to avoid relying on the stdlib
--****************
-- Sigma and friends
--****************
data Sigma (A : Set) (B : A -> Set) : Set where
_,_ : (x : A) (y : B x) -> Sigma A B
_*_ : (A : Set)(B : Set) -> Set
A * B = Sigma A \_ -> B
fst : {A : Set}{B : A -> Set} -> Sigma A B -> A
fst (a , _) = a
snd : {A : Set}{B : A -> Set} (p : Sigma A B) -> B (fst p)
snd (a , b) = b
data Zero : Set where
data Unit : Set where
Void : Unit
--****************
-- Sum and friends
--****************
data _+_ (A : Set)(B : Set) : Set where
l : A -> A + B
r : B -> A + B
--****************
-- Equality
--****************
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
subst : forall {x y} -> x == y -> x -> y
subst refl x = x
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong f refl = refl
cong2 : {A B C : Set}(f : A -> B -> C){x y : A}{z t : B} ->
x == y -> z == t -> f x z == f y t
cong2 f refl refl = refl
postulate
reflFun : {A B : Set}(f : A -> B)(g : A -> B)-> ((a : A) -> f a == g a) -> f == g
--****************
-- Meta-language
--****************
-- Note that we could define Nat, Bool, and the related operations in
-- IDesc. But it is awful to code with them, in Agda.
data Nat : Set where
ze : Nat
su : Nat -> Nat
data Bool : Set where
true : Bool
false : Bool
plus : Nat -> Nat -> Nat
plus ze n' = n'
plus (su n) n' = su (plus n n')
le : Nat -> Nat -> Bool
le ze _ = true
le (su _) ze = false
le (su n) (su n') = le n n'
--********************************************
-- Desc code
--********************************************
data IDesc (I : Set) : Set where
var : I -> IDesc I
const : Set -> IDesc I
prod : IDesc I -> IDesc I -> IDesc I
sigma : (S : Set) -> (S -> IDesc I) -> IDesc I
pi : (S : Set) -> (S -> IDesc I) -> IDesc I
--********************************************
-- Desc interpretation
--********************************************
[|_|] : {I : Set} -> IDesc I -> (I -> Set) -> Set
[| var i |] P = P i
[| const X |] P = X
[| prod D D' |] P = [| D |] P * [| D' |] P
[| sigma S T |] P = Sigma S (\s -> [| T s |] P)
[| pi S T |] P = (s : S) -> [| T s |] P
--********************************************
-- Fixpoint construction
--********************************************
data IMu {I : Set}(R : I -> IDesc I)(i : I) : Set where
con : [| R i |] (\j -> IMu R j) -> IMu R i
--********************************************
-- Predicate: All
--********************************************
All : {I : Set}(D : IDesc I)(P : I -> Set) -> [| D |] P -> IDesc (Sigma I P)
All (var i) P x = var (i , x)
All (const X) P x = const Unit
All (prod D D') P (d , d') = prod (All D P d) (All D' P d')
All (sigma S T) P (a , b) = All (T a) P b
All (pi S T) P f = pi S (\s -> All (T s) P (f s))
all : {I : Set}(D : IDesc I)(X : I -> Set)
(R : Sigma I X -> Set)(P : (x : Sigma I X) -> R x) ->
(xs : [| D |] X) -> [| All D X xs |] R
all (var i) X R P x = P (i , x)
all (const K) X R P k = Void
all (prod D D') X R P (x , y) = ( all D X R P x , all D' X R P y )
all (sigma S T) X R P (a , b) = all (T a) X R P b
all (pi S T) X R P f = \a -> all (T a) X R P (f a)
--********************************************
-- Elimination principle: induction
--********************************************
-- One would like to write the following:
{-
indI : {I : Set}
(R : I -> IDesc I)
(P : Sigma I (IMu R) -> Set)
(m : (i : I)
(xs : [| R i |] (IMu R))
(hs : [| All (R i) (IMu R) xs |] P) ->
P ( i , con xs)) ->
(i : I)(x : IMu R i) -> P ( i , x )
indI {I} R P m i (con xs) = m i xs (all (R i) (IMu R) P induct xs)
where induct : (x : Sigma I (IMu R)) -> P x
induct (i , xs) = indI R P m i xs
-}
-- But the termination-checker complains, so here we go
-- inductive-recursive:
module Elim {I : Set}
(R : I -> IDesc I)
(P : Sigma I (IMu R) -> Set)
(m : (i : I)
(xs : [| R i |] (IMu R))
(hs : [| All (R i) (IMu R) xs |] P) ->
P ( i , con xs ))
where
mutual
indI : (i : I)(x : IMu R i) -> P (i , x)
indI i (con xs) = m i xs (hyps (R i) xs)
hyps : (D : IDesc I) ->
(xs : [| D |] (IMu R)) ->
[| All D (IMu R) xs |] P
hyps (var i) x = indI i x
hyps (const X) x = Void
hyps (prod D D') (d , d') = hyps D d , hyps D' d'
hyps (pi S R) f = \ s -> hyps (R s) (f s)
hyps (sigma S R) ( a , b ) = hyps (R a) b
indI : {I : Set}
(R : I -> IDesc I)
(P : Sigma I (IMu R) -> Set)
(m : (i : I)
(xs : [| R i |] (IMu R))
(hs : [| All (R i) (IMu R) xs |] P) ->
P ( i , con xs)) ->
(i : I)(x : IMu R i) -> P ( i , x )
indI = Elim.indI
--********************************************
-- Examples
--********************************************
--****************
-- Nat
--****************
data NatConst : Set where
Ze : NatConst
Su : NatConst
natCases : NatConst -> IDesc Unit
natCases Ze = const Unit
natCases Suc = var Void
NatD : Unit -> IDesc Unit
NatD Void = sigma NatConst natCases
Natd : Unit -> Set
Natd x = IMu NatD x
zed : Natd Void
zed = con (Ze , Void)
sud : Natd Void -> Natd Void
sud n = con (Su , n)
--****************
-- Desc
--****************
data DescDConst : Set where
lvar : DescDConst
lconst : DescDConst
lprod : DescDConst
lpi : DescDConst
lsigma : DescDConst
descDChoice : Set -> DescDConst -> IDesc Unit
descDChoice I lvar = const I
descDChoice _ lconst = const Set
descDChoice _ lprod = prod (var Void) (var Void)
descDChoice _ lpi = sigma Set (\S -> pi S (\s -> var Void))
descDChoice _ lsigma = sigma Set (\S -> pi S (\s -> var Void))
descD : (I : Set) -> IDesc Unit
descD I = sigma DescDConst (descDChoice I)
IDescl0 : (I : Set) -> Unit -> Set
IDescl0 I = IMu (\_ -> descD I)
IDescl : (I : Set) -> Set
IDescl I = IDescl0 I _
varl : {I : Set}(i : I) -> IDescl I
varl i = con (lvar , i)
constl : {I : Set}(X : Set) -> IDescl I
constl X = con (lconst , X)
prodl : {I : Set}(D D' : IDescl I) -> IDescl I
prodl D D' = con (lprod , (D , D'))
pil : {I : Set}(S : Set)(T : S -> IDescl I) -> IDescl I
pil S T = con (lpi , ( S , T))
sigmal : {I : Set}(S : Set)(T : S -> IDescl I) -> IDescl I
sigmal S T = con (lsigma , ( S , T))
--****************
-- Vec (constraints)
--****************
data VecConst : Set where
Vnil : VecConst
Vcons : VecConst
vecDChoice : Set -> Nat -> VecConst -> IDesc Nat
vecDChoice X n Vnil = const (n == ze)
vecDChoice X n Vcons = sigma Nat (\m -> prod (var m) (const (n == su m)))
vecD : Set -> Nat -> IDesc Nat
vecD X n = sigma VecConst (vecDChoice X n)
vec : Set -> Nat -> Set
vec X n = IMu (vecD X) n
--****************
-- Vec (de-tagged, forced)
--****************
data VecConst2 : Nat -> Set where
Vnil : VecConst2 ze
Vcons : {n : Nat} -> VecConst2 (su n)
vecDChoice2 : Set -> (n : Nat) -> VecConst2 n -> IDesc Nat
vecDChoice2 X ze Vnil = const Unit
vecDChoice2 X (su n) Vcons = prod (const X) (var n)
vecD2 : Set -> Nat -> IDesc Nat
vecD2 X n = sigma (VecConst2 n) (vecDChoice2 X n)
vec2 : Set -> Nat -> Set
vec2 X n = IMu (vecD2 X) n
--****************
-- Fin (de-tagged)
--****************
data FinConst : Nat -> Set where
Fz : {n : Nat} -> FinConst (su n)
Fs : {n : Nat} -> FinConst (su n)
finDChoice : (n : Nat) -> FinConst n -> IDesc Nat
finDChoice ze ()
finDChoice (su n) Fz = const Unit
finDChoice (su n) Fs = var n
finD : Nat -> IDesc Nat
finD n = sigma (FinConst n) (finDChoice n)
fin : Nat -> Set
fin n = IMu finD n
--********************************************
-- Enumerations (hard-coded)
--********************************************
-- Unlike in Desc.agda, we don't carry the levitation of finite sets
-- here. We hard-code them and manipulate with standard Agda
-- machinery. Both presentation are isomorph but, in Agda, the coded
-- one quickly gets unusable.
data EnumU : Set where
nilE : EnumU
consE : EnumU -> EnumU
data EnumT : (e : EnumU) -> Set where
EZe : {e : EnumU} -> EnumT (consE e)
ESu : {e : EnumU} -> EnumT e -> EnumT (consE e)
spi : (e : EnumU)(P : EnumT e -> Set) -> Set
spi nilE P = Unit
spi (consE e) P = P EZe * spi e (\e -> P (ESu e))
switch : (e : EnumU)(P : EnumT e -> Set)(b : spi e P)(x : EnumT e) -> P x
switch nilE P b ()
switch (consE e) P b EZe = fst b
switch (consE e) P b (ESu n) = switch e (\e -> P (ESu e)) (snd b) n
_++_ : EnumU -> EnumU -> EnumU
nilE ++ e' = e'
(consE e) ++ e' = consE (e ++ e')
-- A special switch, for tagged descriptions. Switching on a
-- concatenation of finite sets:
sswitch : (e : EnumU)(e' : EnumU)(P : Set)
(b : spi e (\_ -> P))(b' : spi e' (\_ -> P))(x : EnumT (e ++ e')) -> P
sswitch nilE nilE P b b' ()
sswitch nilE (consE e') P b b' EZe = fst b'
sswitch nilE (consE e') P b b' (ESu n) = sswitch nilE e' P b (snd b') n
sswitch (consE e) e' P b b' EZe = fst b
sswitch (consE e) e' P b b' (ESu n) = sswitch e e' P (snd b) b' n
--********************************************
-- Tagged indexed description
--********************************************
FixMenu : Set -> Set
FixMenu I = Sigma EnumU (\e -> (i : I) -> spi e (\_ -> IDesc I))
SensitiveMenu : Set -> Set
SensitiveMenu I = Sigma (I -> EnumU) (\F -> (i : I) -> spi (F i) (\_ -> IDesc I))
TagIDesc : Set -> Set
TagIDesc I = FixMenu I * SensitiveMenu I
toIDesc : (I : Set) -> TagIDesc I -> (I -> IDesc I)
toIDesc I ((E , ED) , (F , FD)) i = sigma (EnumT (E ++ F i))
(\x -> sswitch E (F i) (IDesc I) (ED i) (FD i) x)
--********************************************
-- Catamorphism
--********************************************
cata : (I : Set)
(R : I -> IDesc I)
(T : I -> Set) ->
((i : I) -> [| R i |] T -> T i) ->
(i : I) -> IMu R i -> T i
cata I R T phi i x = indI R (\it -> T (fst it)) (\i xs ms -> phi i (replace (R i) T xs ms)) i x
where replace : (D : IDesc I)(T : I -> Set)
(xs : [| D |] (IMu R))
(ms : [| All D (IMu R) xs |] (\it -> T (fst it))) ->
[| D |] T
replace (var i) T x y = y
replace (const Z) T z z' = z
replace (prod D D') T (x , x') (y , y') = replace D T x y , replace D' T x' y'
replace (sigma A B) T (a , b) t = a , replace (B a) T b t
replace (pi A B) T f t = \s -> replace (B s) T (f s) (t s)
--********************************************
-- Hutton's razor
--********************************************
--********************************
-- Types code
--********************************
data Type : Set where
nat : Type
bool : Type
pair : Type -> Type -> Type
--********************************
-- Typed expressions
--********************************
Val : Type -> Set
Val nat = Nat
Val bool = Bool
Val (pair x y) = (Val x) * (Val y)
-- Fix menu:
exprFixMenu : FixMenu Type
exprFixMenu = ( consE (consE nilE) ,
\ty -> (const (Val ty), -- Val t
(prod (var bool) (prod (var ty) (var ty)), -- if b then t1 else t2
Void)))
-- Indexed menu:
choiceMenu : Type -> EnumU
choiceMenu nat = consE nilE
choiceMenu bool = consE nilE
choiceMenu (pair x y) = nilE
choiceDessert : (ty : Type) -> spi (choiceMenu ty) (\ _ -> IDesc Type)
choiceDessert nat = (prod (var nat) (var nat) , Void)
choiceDessert bool = (prod (var nat) (var nat) , Void )
choiceDessert (pair x y) = Void
exprSensitiveMenu : SensitiveMenu Type
exprSensitiveMenu = ( choiceMenu , choiceDessert )
-- Expression:
expr : TagIDesc Type
expr = exprFixMenu , exprSensitiveMenu
exprIDesc : TagIDesc Type -> (Type -> IDesc Type)
exprIDesc D = toIDesc Type D
--********************************
-- Closed terms
--********************************
closeTerm : Type -> IDesc Type
closeTerm = exprIDesc expr
--********************************
-- Closed term evaluation
--********************************
eval : {ty : Type} -> IMu closeTerm ty -> Val ty
eval {ty} term = cata Type closeTerm Val evalOneStep ty term
where evalOneStep : (ty : Type) -> [| closeTerm ty |] Val -> Val ty
evalOneStep _ (EZe , t) = t
evalOneStep _ ((ESu EZe) , (true , ( x , _))) = x
evalOneStep _ ((ESu EZe) , (false , ( _ , y ))) = y
evalOneStep nat ((ESu (ESu EZe)) , (x , y)) = plus x y
evalOneStep nat ((ESu (ESu (ESu ()))) , t)
evalOneStep bool ((ESu (ESu EZe)) , (x , y) ) = le x y
evalOneStep bool ((ESu (ESu (ESu ()))) , _)
evalOneStep (pair x y) (ESu (ESu ()) , _)
--********************************************
-- Free monad construction
--********************************************
_**_ : {I : Set} (R : TagIDesc I)(X : I -> Set) -> TagIDesc I
((E , ED) , FFD) ** X = ((( consE E , \ i -> ( const (X i) , ED i ))) , FFD)
--********************************************
-- Substitution
--********************************************
apply : {I : Set}
(R : TagIDesc I)(X Y : I -> Set) ->
((i : I) -> X i -> IMu (toIDesc I (R ** Y)) i) ->
(i : I) ->
[| toIDesc I (R ** X) i |] (IMu (toIDesc I (R ** Y))) ->
IMu (toIDesc I (R ** Y)) i
apply (( E , ED) , (F , FD)) X Y sig i (EZe , x) = sig i x
apply (( E , ED) , (F , FD)) X Y sig i (ESu n , t) = con (ESu n , t)
substI : {I : Set} (X Y : I -> Set)(R : TagIDesc I)
(sigma : (i : I) -> X i -> IMu (toIDesc I (R ** Y)) i)
(i : I)(D : IMu (toIDesc I (R ** X)) i) ->
IMu (toIDesc I (R ** Y)) i
substI {I} X Y R sig i term = cata I (toIDesc I (R ** X)) (IMu (toIDesc I (R ** Y))) (apply R X Y sig) i term
--********************************************
-- Hutton's razor is free monad
--********************************************
Empty : Type -> Set
Empty _ = Zero
closeTerm' : Type -> IDesc Type
closeTerm' = toIDesc Type (expr ** Empty)
update : {ty : Type} -> IMu closeTerm ty -> IMu closeTerm' ty
update {ty} tm = cata Type closeTerm (IMu closeTerm') (\ _ tagTm -> con (ESu (fst tagTm) , (snd tagTm))) ty tm
--********************************
-- Closed term' evaluation
--********************************
eval' : {ty : Type} -> IMu closeTerm' ty -> Val ty
eval' {ty} term = cata Type closeTerm' Val evalOneStep ty term
where evalOneStep : (ty : Type) -> [| closeTerm' ty |] Val -> Val ty
evalOneStep _ (EZe , ())
evalOneStep _ (ESu EZe , t) = t
evalOneStep _ ((ESu (ESu EZe)) , (true , ( x , _))) = x
evalOneStep _ ((ESu (ESu EZe)) , (false , ( _ , y ))) = y
evalOneStep nat ((ESu (ESu (ESu EZe))) , (x , y)) = plus x y
evalOneStep nat (((ESu (ESu (ESu (ESu ()))))) , t)
evalOneStep bool ((ESu (ESu (ESu EZe))) , (x , y) ) = le x y
evalOneStep bool ((ESu (ESu (ESu (ESu ())))) , _)
evalOneStep (pair x y) (ESu (ESu (ESu ())) , _)
--********************************
-- Open terms
--********************************
-- A context is a snoc-list of types
-- put otherwise, a context is a type telescope
data Context : Set where
[] : Context
_,_ : Context -> Type -> Context
-- The environment realizes the context, having a value for each type
Env : Context -> Set
Env [] = Unit
Env (G , S) = Env G * Val S
-- A typed-variable indexes into the context, obtaining a proof that
-- what we get is what you want (WWGIWYW)
Var : Context -> Type -> Set
Var [] T = Zero
Var (G , S) T = Var G T + (S == T)
-- The lookup gets into the context to extract the value
lookup : (G : Context) -> Env G -> (T : Type) -> Var G T -> Val T
lookup [] _ T ()
lookup (G , .T) (g , t) T (r refl) = t
lookup (G , S) (g , t) T (l x) = lookup G g T x
-- Open term: holes are either values or variables in a context
openTerm : Context -> Type -> IDesc Type
openTerm c = toIDesc Type (expr ** (Var c))
--********************************
-- Evaluation of open terms
--********************************
-- |discharge| is the local substitution expected by |substI|. It is
-- just sugar around context lookup
discharge : (context : Context) ->
Env context ->
(ty : Type) ->
Var context ty ->
IMu closeTerm' ty
discharge ctxt env ty variable = con (ESu EZe , lookup ctxt env ty variable )
-- |substExpr| is the specialized |substI| to expressions. We get it
-- generically from the free monad construction.
substExpr : {ty : Type}
(context : Context)
(sigma : (ty : Type) ->
Var context ty ->
IMu closeTerm' ty) ->
IMu (openTerm context) ty ->
IMu closeTerm' ty
substExpr {ty} c sig term =
substI (Var c) Empty expr sig ty term
-- By first doing substitution to close the term, we can use
-- evaluation of closed terms, obtaining evaluation of open terms
-- under a valid context.
evalOpen : {ty : Type}(context : Context) ->
Env context ->
IMu (openTerm context) ty ->
Val ty
evalOpen ctxt env tm = eval' (substExpr ctxt (discharge ctxt env) tm)
--********************************
-- Tests
--********************************
-- Test context:
-- V 0 :-> true, V 1 :-> 2, V 2 :-> ( false , 1 )
testContext : Context
testContext = (([] , bool) , nat) , pair bool nat
testEnv : Env testContext
testEnv = ((Void , true ) , su (su ze)) , (false , su ze)
-- V 1
test1 : IMu (openTerm testContext) nat
test1 = con (EZe , ( l (r refl) ) )
testSubst1 : IMu closeTerm' nat
testSubst1 = substExpr testContext
(discharge testContext testEnv)
test1
-- = 2
testEval1 : Val nat
testEval1 = evalOpen testContext testEnv test1
-- add 1 (V 1)
test2 : IMu (openTerm testContext) nat
test2 = con (ESu (ESu (ESu EZe)) , (con (ESu EZe , su ze) , con ( EZe , l (r refl) )) )
testSubst2 : IMu closeTerm' nat
testSubst2 = substExpr testContext
(discharge testContext testEnv)
test2
-- = 3
testEval2 : Val nat
testEval2 = evalOpen testContext testEnv test2
-- if (V 0) then (V 1) else 0
test3 : IMu (openTerm testContext) nat
test3 = con (ESu (ESu EZe) , (con (EZe , l (l (r refl))) ,
(con (EZe , l (r refl)) ,
con (ESu EZe , ze))))
testSubst3 : IMu closeTerm' nat
testSubst3 = substExpr testContext
(discharge testContext testEnv)
test3
-- = 2
testEval3 : Val nat
testEval3 = evalOpen testContext testEnv test3
-- V 2
test4 : IMu (openTerm testContext) (pair bool nat)
test4 = con (EZe , r refl )
testSubst4 : IMu closeTerm' (pair bool nat)
testSubst4 = substExpr testContext
(discharge testContext testEnv)
test4
-- = (false , 1)
testEval4 : Val (pair bool nat)
testEval4 = evalOpen testContext testEnv test4
| 29.296353
| 110
| 0.468797
|
9afc69a77fb744b70045de0c6a2fdc76c3d62265
| 1,205
|
agda
|
Agda
|
Structure/Setoid.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Setoid.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Setoid.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Setoid {ℓₑ ℓₒ} where
import Lvl
open import Functional.Dependent
open import Lang.Instance
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Relator.Equivalence
open import Syntax.Function
import Type
module _ where
open Type
-- An instance of `Equiv(T)` is that the type `T` has an equivalence relation which may be treated as a default one.
-- Helps finding an instance of an equivalence relation for a type.
record Equiv (T : Type{ℓₒ}) : Type{Lvl.𝐒(ℓₑ) Lvl.⊔ ℓₒ} where
constructor intro
infixl 15 _≡_ _≢_
field
_≡_ : T → T → Type{ℓₑ}
field
instance ⦃ equivalence ⦄ : Equivalence(_≡_)
_≢_ : T → T → Type{ℓₑ}
a ≢ b = ¬(a ≡ b)
open Equivalence(equivalence) public
open Equiv ⦃ ... ⦄ using (_≡_ ; _≢_) renaming (equivalence to Equiv-equivalence) public
{-# INLINE _≡_ #-} -- TODO: Not sure if this does anything
{-# DISPLAY Equiv._≡_ a b = a ≡ b #-} -- TODO: Not sure about this either
module _ where
-- A set and an equivalence relation on it
Setoid = ∃(Equiv)
module Setoid(([∃]-intro T ⦃ equiv-T ⦄) : Setoid) where
Type : Type.Type
Type = T
open Equiv(equiv-T) public
| 28.023256
| 118
| 0.66888
|
ed77f79a01c7f4f9379daea23e26a4d62fb47e0a
| 622
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/M.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/Data/M.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/M.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- M-types (the dual of W-types)
------------------------------------------------------------------------
module Data.M where
open import Level
open import Coinduction
-- The family of M-types.
data M {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
inf : (x : A) (f : B x → ∞ (M A B)) → M A B
-- Projections.
head : ∀ {a b} {A : Set a} {B : A → Set b} →
M A B → A
head (inf x f) = x
tail : ∀ {a b} {A : Set a} {B : A → Set b} →
(x : M A B) → B (head x) → M A B
tail (inf x f) b = ♭ (f b)
| 23.923077
| 72
| 0.382637
|
3ff9218173357d25042e1a4bde58bcfee17fddfd
| 1,716
|
agda
|
Agda
|
Cubical/Data/SumFin/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/SumFin/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Data/SumFin/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.SumFin.Properties where
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Data.Empty as ⊥
import Cubical.Data.Fin as Fin
open import Cubical.Data.Nat
open import Cubical.Data.SumFin.Base as SumFin
private
variable
ℓ : Level
k : ℕ
SumFin→Fin : Fin k → Fin.Fin k
SumFin→Fin = SumFin.elim (λ {k} _ → Fin.Fin k) Fin.fzero Fin.fsuc
Fin→SumFin : Fin.Fin k → Fin k
Fin→SumFin = Fin.elim (λ {k} _ → Fin k) fzero fsuc
Fin→SumFin-fsuc : (fk : Fin.Fin k) → Fin→SumFin (Fin.fsuc fk) ≡ fsuc (Fin→SumFin fk)
Fin→SumFin-fsuc = Fin.elim-fsuc (λ {k} _ → Fin k) fzero fsuc
SumFin→Fin→SumFin : (fk : Fin k) → Fin→SumFin (SumFin→Fin fk) ≡ fk
SumFin→Fin→SumFin = SumFin.elim (λ fk → Fin→SumFin (SumFin→Fin fk) ≡ fk)
refl λ {k} {fk} eq →
Fin→SumFin (Fin.fsuc (SumFin→Fin fk)) ≡⟨ Fin→SumFin-fsuc (SumFin→Fin fk) ⟩
fsuc (Fin→SumFin (SumFin→Fin fk)) ≡⟨ cong fsuc eq ⟩
fsuc fk ∎
Fin→SumFin→Fin : (fk : Fin.Fin k) → SumFin→Fin (Fin→SumFin fk) ≡ fk
Fin→SumFin→Fin = Fin.elim (λ fk → SumFin→Fin (Fin→SumFin fk) ≡ fk)
refl λ {k} {fk} eq →
SumFin→Fin (Fin→SumFin (Fin.fsuc fk)) ≡⟨ cong SumFin→Fin (Fin→SumFin-fsuc fk) ⟩
Fin.fsuc (SumFin→Fin (Fin→SumFin fk)) ≡⟨ cong Fin.fsuc eq ⟩
Fin.fsuc fk ∎
SumFin≃Fin : ∀ k → Fin k ≃ Fin.Fin k
SumFin≃Fin _ =
isoToEquiv (iso SumFin→Fin Fin→SumFin Fin→SumFin→Fin SumFin→Fin→SumFin)
SumFin≡Fin : ∀ k → Fin k ≡ Fin.Fin k
SumFin≡Fin k = ua (SumFin≃Fin k)
| 35.020408
| 84
| 0.635781
|
4d953052f9e68997876641a0b65923b0f10e2f91
| 1,719
|
agda
|
Agda
|
src/Categories/Category/Monoidal/Traced.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Monoidal/Traced.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Monoidal/Traced.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
open import Categories.Category.Monoidal
module Categories.Category.Monoidal.Traced {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where
open Category C
open import Level
open import Data.Product using (_,_)
open import Categories.Category.Monoidal.Symmetric M
private
variable
A B X Y : Obj
f g : A ⇒ B
------------------------------------------------------------------------------
-- Def from http://ncatlab.org/nlab/show/traced+monoidal+category
--
-- A symmetric monoidal category (C,⊗,1,b) (where b is the symmetry) is
-- said to be traced if it is equipped with a natural family of functions
--
-- TrXA,B:C(A⊗X,B⊗X)→C(A,B)
-- satisfying three axioms:
--
-- Vanishing: Tr1A,B(f)=f (for all f:A→B) and
-- TrX⊗YA,B=TrXA,B(TrYA⊗X,B⊗X(f)) (for all f:A⊗X⊗Y→B⊗X⊗Y)
--
-- Superposing: TrXC⊗A,C⊗B(idC⊗f)=idC⊗TrXA,B(f) (for all f:A⊗X→B⊗X)
--
-- Yanking: TrXX,X(bX,X)=idX
-- Traced monoidal category
-- is a symmetric monoidal category with a trace operation
--
-- note that the definition in this library is significantly easier than the previous one because
-- we adopt a simpler definition of monoidal category to begin with.
record Traced : Set (levelOfTerm M) where
field
symmetric : Symmetric
open Symmetric symmetric public
field
trace : ∀ {X A B} → A ⊗₀ X ⇒ B ⊗₀ X → A ⇒ B
vanishing₁ : trace {X = unit} (f ⊗₁ id) ≈ f
vanishing₂ : trace {X = X} (trace {X = Y} (associator.to ∘ f ∘ associator.from))
≈ trace {X = X ⊗₀ Y} f
superposing : trace {X = X} (associator.to ∘ id {Y} ⊗₁ f ∘ associator.from) ≈ id {Y} ⊗₁ trace {X = X} f
yanking : trace (braiding.⇒.η (X , X)) ≈ id
| 30.696429
| 107
| 0.622455
|
3faa37d347ba6c50d182a3919f1d3d98d886fab4
| 17
|
agda
|
Agda
|
test/Fail/Issue1389.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1389.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1389.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
unquoteDef x = ?
| 8.5
| 16
| 0.647059
|
37c122d4acc1bcf9fefbba2e876dfd7cd06f6ea0
| 16,934
|
agda
|
Agda
|
Cubical/Foundations/Prelude.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Prelude.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Prelude.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-
This file proves a variety of basic results about paths:
- refl, sym, cong and composition of paths. This is used to set up
equational reasoning.
- Transport, subst and functional extensionality
- J and its computation rule (up to a path)
- Σ-types and contractibility of singletons
- Converting PathP to and from a homogeneous path with transp
- Direct definitions of lower h-levels
- Export natural numbers
- Export universe lifting
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.Prelude where
open import Cubical.Core.Primitives public
infixr 30 _∙_
infixr 30 _∙₂_
infix 3 _∎
infixr 2 _≡⟨_⟩_
infixr 2.5 _≡⟨_⟩≡⟨_⟩_
-- Basic theory about paths. These proofs should typically be
-- inlined. This module also makes equational reasoning work with
-- (non-dependent) paths.
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
B : A → Type ℓ
x y z w : A
refl : x ≡ x
refl {x = x} _ = x
{-# INLINE refl #-}
sym : x ≡ y → y ≡ x
sym p i = p (~ i)
{-# INLINE sym #-}
symP : {A : I → Type ℓ} → {x : A i1} → {y : A i0} →
(p : PathP (λ i → A (~ i)) x y) → PathP A y x
symP p j = p (~ j)
cong : (f : (a : A) → B a) (p : x ≡ y) →
PathP (λ i → B (p i)) (f x) (f y)
cong f p i = f (p i)
{-# INLINE cong #-}
congP : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ'}
(f : (i : I) → (a : A i) → B i a) {x : A i0} {y : A i1}
(p : PathP A x y) → PathP (λ i → B i (p i)) (f i0 x) (f i1 y)
congP f p i = f i (p i)
{-# INLINE congP #-}
cong₂ : {C : (a : A) → (b : B a) → Type ℓ} →
(f : (a : A) → (b : B a) → C a b) →
(p : x ≡ y) →
{u : B x} {v : B y} (q : PathP (λ i → B (p i)) u v) →
PathP (λ i → C (p i) (q i)) (f x u) (f y v)
cong₂ f p q i = f (p i) (q i)
{-# INLINE cong₂ #-}
congP₂ : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ'}
{C : (i : I) (a : A i) → B i a → Type ℓ''}
(f : (i : I) → (a : A i) → (b : B i a) → C i a b)
{x : A i0} {y : A i1} {u : B i0 x} {v : B i1 y}
(p : PathP A x y) (q : PathP (λ i → B i (p i)) u v)
→ PathP (λ i → C i (p i) (q i)) (f i0 x u) (f i1 y v)
congP₂ f p q i = f i (p i) (q i)
{-# INLINE congP₂ #-}
{- The most natural notion of homogenous path composition
in a cubical setting is double composition:
x ∙ ∙ ∙ > w
^ ^
p⁻¹ | | r ^
| | j |
y — — — > z ∙ — >
q i
`p ∙∙ q ∙∙ r` gives the line at the top,
`doubleCompPath-filler p q r` gives the whole square
-}
doubleComp-faces : {x y z w : A } (p : x ≡ y) (r : z ≡ w)
→ (i : I) (j : I) → Partial (i ∨ ~ i) A
doubleComp-faces p r i j (i = i0) = p (~ j)
doubleComp-faces p r i j (i = i1) = r j
_∙∙_∙∙_ : w ≡ x → x ≡ y → y ≡ z → w ≡ z
(p ∙∙ q ∙∙ r) i =
hcomp (doubleComp-faces p r i) (q i)
doubleCompPath-filler : (p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ PathP (λ j → p (~ j) ≡ r j) q (p ∙∙ q ∙∙ r)
doubleCompPath-filler p q r j i =
hfill (doubleComp-faces p r i) (inS (q i)) j
-- any two definitions of double composition are equal
compPath-unique : (p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ (α β : Σ[ s ∈ x ≡ w ] PathP (λ j → p (~ j) ≡ r j) q s)
→ α ≡ β
compPath-unique p q r (α , α-filler) (β , β-filler) t
= (λ i → cb i1 i) , (λ j i → cb j i)
where cb : I → I → _
cb j i = hfill (λ j → λ { (t = i0) → α-filler j i
; (t = i1) → β-filler j i
; (i = i0) → p (~ j)
; (i = i1) → r j })
(inS (q i)) j
{- For single homogenous path composition, we take `p = refl`:
x ∙ ∙ ∙ > z
‖ ^
‖ | r ^
‖ | j |
x — — — > y ∙ — >
q i
`q ∙ r` gives the line at the top,
`compPath-filler q r` gives the whole square
-}
_∙_ : x ≡ y → y ≡ z → x ≡ z
p ∙ q = refl ∙∙ p ∙∙ q
compPath-filler : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → x ≡ q j) p (p ∙ q)
compPath-filler p q = doubleCompPath-filler refl p q
-- We could have also defined single composition by taking `r = refl`:
_∙'_ : x ≡ y → y ≡ z → x ≡ z
p ∙' q = p ∙∙ q ∙∙ refl
compPath'-filler : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → p (~ j) ≡ z) q (p ∙' q)
compPath'-filler p q = doubleCompPath-filler p q refl
-- It's easy to show that `p ∙ q` also has such a filler:
compPath-filler' : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → p (~ j) ≡ z) q (p ∙ q)
compPath-filler' {z = z} p q j i =
hcomp (λ k → λ { (i = i0) → p (~ j)
; (i = i1) → q k
; (j = i0) → q (i ∧ k) })
(p (i ∨ ~ j))
-- Note: We can omit a (j = i1) case here since when (j = i1), the whole expression is
-- definitionally equal to `p ∙ q`. (Notice that `p ∙ q` is also an hcomp.) Nevertheless,
-- we could have given `compPath-filler p q k i` as the (j = i1) case.
-- From this, we can show that these two notions of composition are the same
compPath≡compPath' : (p : x ≡ y) (q : y ≡ z) → p ∙ q ≡ p ∙' q
compPath≡compPath' p q j =
compPath-unique p q refl (p ∙ q , compPath-filler' p q)
(p ∙' q , compPath'-filler p q) j .fst
-- Double composition agrees with iterated single composition
doubleCompPath≡compPath : {x y z w : A}
(p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ p ∙∙ q ∙∙ r ≡ p ∙ q ∙ r
doubleCompPath≡compPath p q r i j =
hcomp (λ k → λ { (i = i1) → compPath-filler' p (q ∙ r) k j
; (j = i0) → p (~ k)
; (j = i1) → r (i ∨ k)})
(compPath-filler q r i j)
-- Heterogeneous path composition and its filler:
-- Composition in a family indexed by the interval
compPathP : {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} {z : B i1}
→ PathP A x y → PathP (λ i → B i) y z → PathP (λ j → ((λ i → A i) ∙ B) j) x z
compPathP {A = A} {x = x} {B = B} p q i =
comp (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j })
(p i)
-- Composition in a family indexed by a type
compPathP' : {B : A → Type ℓ'} {x' : B x} {y' : B y} {z' : B z} {p : x ≡ y} {q : y ≡ z}
(P : PathP (λ i → B (p i)) x' y') (Q : PathP (λ i → B (q i)) y' z')
→ PathP (λ i → B ((p ∙ q) i)) x' z'
compPathP' {B = B} {x' = x'} {p = p} {q = q} P Q i =
comp (λ j → B (compPath-filler p q j i))
(λ j → λ { (i = i0) → x' ;
(i = i1) → Q j })
(P i)
compPathP-filler : {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : A i1 ≡ B_i1} {z : B i1}
(p : PathP A x y) (q : PathP (λ i → B i) y z)
→ PathP (λ j → PathP (λ k → (compPath-filler (λ i → A i) B j k)) x (q j)) p (compPathP p q)
compPathP-filler {A = A} {x = x} {B = B} p q j i =
fill (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j })
(inS (p i)) j
compPathP'-filler : {B : A → Type ℓ'} {x' : B x} {y' : B y} {z' : B z} {p : x ≡ y} {q : y ≡ z}
(P : PathP (λ i → B (p i)) x' y') (Q : PathP (λ i → B (q i)) y' z')
→ PathP (λ j → PathP (λ i → B (compPath-filler p q j i)) x' (Q j)) P (compPathP' {B = B} P Q)
compPathP'-filler {B = B} {x' = x'} {p = p} {q = q} P Q j i =
fill (λ j → B (compPath-filler p q j i))
(λ j → λ { (i = i0) → x' ;
(i = i1) → Q j })
(inS (P i))
j
-- Syntax for chains of equational reasoning
_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
≡⟨⟩-syntax : (x : A) → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 2 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
≡⟨⟩⟨⟩-syntax : (x y : A) → x ≡ y → y ≡ z → z ≡ w → x ≡ w
≡⟨⟩⟨⟩-syntax x y p q r = p ∙∙ q ∙∙ r
infixr 3 ≡⟨⟩⟨⟩-syntax
syntax ≡⟨⟩⟨⟩-syntax x y B C = x ≡⟨ B ⟩≡ y ≡⟨ C ⟩≡
_≡⟨_⟩≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → z ≡ w → x ≡ w
_ ≡⟨ x≡y ⟩≡⟨ y≡z ⟩ z≡w = x≡y ∙∙ y≡z ∙∙ z≡w
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- Transport and subst
-- transport is a special case of transp
transport : {A B : Type ℓ} → A ≡ B → A → B
transport p a = transp (λ i → p i) i0 a
-- Transporting in a constant family is the identity function (up to a
-- path). If we would have regularity this would be definitional.
transportRefl : (x : A) → transport refl x ≡ x
transportRefl {A = A} x i = transp (λ _ → A) i x
transport-filler : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) (x : A)
→ PathP (λ i → p i) x (transport p x)
transport-filler p x i = transp (λ j → p (i ∧ j)) (~ i) x
-- We want B to be explicit in subst
subst : (B : A → Type ℓ') (p : x ≡ y) → B x → B y
subst B p pa = transport (λ i → B (p i)) pa
subst2 : ∀ {ℓ' ℓ''} {B : Type ℓ'} {z w : B} (C : A → B → Type ℓ'')
(p : x ≡ y) (q : z ≡ w) → C x z → C y w
subst2 B p q b = transport (λ i → B (p i) (q i)) b
substRefl : ∀ {B : A → Type ℓ} {x} → (px : B x) → subst B refl px ≡ px
substRefl px = transportRefl px
subst-filler : (B : A → Type ℓ') (p : x ≡ y) (b : B x)
→ PathP (λ i → B (p i)) b (subst B p b)
subst-filler B p = transport-filler (cong B p)
-- Function extensionality
funExt : {B : A → I → Type ℓ'}
{f : (x : A) → B x i0} {g : (x : A) → B x i1}
→ ((x : A) → PathP (B x) (f x) (g x))
→ PathP (λ i → (x : A) → B x i) f g
funExt p i x = p x i
implicitFunExt : {B : A → I → Type ℓ'}
{f : {x : A} → B x i0} {g : {x : A} → B x i1}
→ ({x : A} → PathP (B x) (f {x}) (g {x}))
→ PathP (λ i → {x : A} → B x i) f g
implicitFunExt p i {x} = p {x} i
-- the inverse to funExt (see Functions.FunExtEquiv), converting paths
-- between functions to homotopies; `funExt⁻` is called `happly` and
-- defined by path induction in the HoTT book (see function 2.9.2 in
-- section 2.9)
funExt⁻ : {B : A → I → Type ℓ'}
{f : (x : A) → B x i0} {g : (x : A) → B x i1}
→ PathP (λ i → (x : A) → B x i) f g
→ ((x : A) → PathP (B x) (f x) (g x))
funExt⁻ eq x i = eq i x
-- J for paths and its computation rule
module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
J : (p : x ≡ y) → P y p
J p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
JRefl : J refl ≡ d
JRefl = transportRefl d
J-∙ : (p : x ≡ y) (q : y ≡ z)
→ J (p ∙ q) ≡ transport (λ i → P (q i) (λ j → compPath-filler p q i j)) (J p)
J-∙ p q k =
transp
(λ i → P (q (i ∨ ~ k))
(λ j → compPath-filler p q (i ∨ ~ k) j)) (~ k)
(J (λ j → compPath-filler p q (~ k) j))
-- Converting to and from a PathP
module _ {A : I → Type ℓ} {x : A i0} {y : A i1} where
toPathP : transport (λ i → A i) x ≡ y → PathP A x y
toPathP p i = hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
fromPathP : PathP A x y → transport (λ i → A i) x ≡ y
fromPathP p i = transp (λ j → A (i ∨ j)) i (p i)
-- Whiskering a dependent path by a path
-- Double whiskering
_◁_▷_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ a₀' : A i0} {a₁ a₁' : A i1}
→ a₀ ≡ a₀' → PathP A a₀' a₁ → a₁ ≡ a₁'
→ PathP A a₀ a₁'
(p ◁ P ▷ q) i =
hcomp (λ j → λ {(i = i0) → p (~ j) ; (i = i1) → q j}) (P i)
doubleWhiskFiller :
∀ {ℓ} {A : I → Type ℓ} {a₀ a₀' : A i0} {a₁ a₁' : A i1}
→ (p : a₀ ≡ a₀') (pq : PathP A a₀' a₁) (q : a₁ ≡ a₁')
→ PathP (λ i → PathP A (p (~ i)) (q i))
pq
(p ◁ pq ▷ q)
doubleWhiskFiller p pq q k i =
hfill (λ j → λ {(i = i0) → p (~ j) ; (i = i1) → q j})
(inS (pq i))
k
_◁_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ a₀' : A i0} {a₁ : A i1}
→ a₀ ≡ a₀' → PathP A a₀' a₁ → PathP A a₀ a₁
(p ◁ q) = p ◁ q ▷ refl
_▷_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ : A i0} {a₁ a₁' : A i1}
→ PathP A a₀ a₁ → a₁ ≡ a₁' → PathP A a₀ a₁'
p ▷ q = refl ◁ p ▷ q
-- Direct definitions of lower h-levels
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
isGroupoid : Type ℓ → Type ℓ
isGroupoid A = ∀ a b → isSet (Path A a b)
is2Groupoid : Type ℓ → Type ℓ
is2Groupoid A = ∀ a b → isGroupoid (Path A a b)
-- Contractibility of singletons
singlP : (A : I → Type ℓ) (a : A i0) → Type _
singlP A a = Σ[ x ∈ A i1 ] PathP A a x
singl : (a : A) → Type _
singl {A = A} a = singlP (λ _ → A) a
isContrSingl : (a : A) → isContr (singl a)
isContrSingl a .fst = (a , refl)
isContrSingl a .snd p i .fst = p .snd i
isContrSingl a .snd p i .snd j = p .snd (i ∧ j)
isContrSinglP : (A : I → Type ℓ) (a : A i0) → isContr (singlP A a)
isContrSinglP A a .fst = _ , transport-filler (λ i → A i) a
isContrSinglP A a .snd (x , p) i =
_ , λ j → fill A (λ j → λ {(i = i0) → transport-filler (λ i → A i) a j; (i = i1) → p j}) (inS a) j
-- Higher cube types
SquareP :
(A : I → I → Type ℓ)
{a₀₀ : A i0 i0} {a₀₁ : A i0 i1} (a₀₋ : PathP (λ j → A i0 j) a₀₀ a₀₁)
{a₁₀ : A i1 i0} {a₁₁ : A i1 i1} (a₁₋ : PathP (λ j → A i1 j) a₁₀ a₁₁)
(a₋₀ : PathP (λ i → A i i0) a₀₀ a₁₀) (a₋₁ : PathP (λ i → A i i1) a₀₁ a₁₁)
→ Type ℓ
SquareP A a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → PathP (λ j → A i j) (a₋₀ i) (a₋₁ i)) a₀₋ a₁₋
Square :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Type _
Square a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋
Cube :
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Type _
Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
PathP (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋
-- Vertical composition of squares
_∙₂_ :
{a₀₀ a₀₁ a₀₂ : A} {a₀₋ : a₀₀ ≡ a₀₁} {b₀₋ : a₀₁ ≡ a₀₂}
{a₁₀ a₁₁ a₁₂ : A} {a₁₋ : a₁₀ ≡ a₁₁} {b₁₋ : a₁₁ ≡ a₁₂}
{a₋₀ : a₀₀ ≡ a₁₀} {a₋₁ : a₀₁ ≡ a₁₁} {a₋₂ : a₀₂ ≡ a₁₂}
(p : Square a₀₋ a₁₋ a₋₀ a₋₁) (q : Square b₀₋ b₁₋ a₋₁ a₋₂)
→ Square (a₀₋ ∙ b₀₋) (a₁₋ ∙ b₁₋) a₋₀ a₋₂
_∙₂_ = congP₂ (λ _ → _∙_)
-- Alternative (equivalent) definitions of hlevel n that give fillers for n-cubes instead of n-globes
isSet' : Type ℓ → Type ℓ
isSet' A =
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Square a₀₋ a₁₋ a₋₀ a₋₁
isSet→isSet' : isSet A → isSet' A
isSet→isSet' Aset _ _ _ _ = toPathP (Aset _ _ _ _)
isSet'→isSet : isSet' A → isSet A
isSet'→isSet Aset' x y p q = Aset' p q refl refl
isGroupoid' : Type ℓ → Type ℓ
isGroupoid' A =
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁
-- Essential properties of isProp and isContr
isProp→PathP : ∀ {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ PathP B b0 b1
isProp→PathP hB b0 b1 = toPathP (hB _ _ _)
isPropIsContr : isProp (isContr A)
isPropIsContr (c0 , h0) (c1 , h1) j .fst = h0 c1 j
isPropIsContr (c0 , h0) (c1 , h1) j .snd y i =
hcomp (λ k → λ { (i = i0) → h0 (h0 c1 j) k;
(i = i1) → h0 y k;
(j = i0) → h0 (h0 y i) k;
(j = i1) → h0 (h1 y i) k})
c0
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b = sym (p a) ∙ p b
isProp→isSet : isProp A → isSet A
isProp→isSet h a b p q j i =
hcomp (λ k → λ { (i = i0) → h a a k
; (i = i1) → h a b k
; (j = i0) → h a (p i) k
; (j = i1) → h a (q i) k }) a
isProp→isSet' : isProp A → isSet' A
isProp→isSet' h {a} p q r s i j =
hcomp (λ k → λ { (i = i0) → h a (p j) k
; (i = i1) → h a (q j) k
; (j = i0) → h a (r i) k
; (j = i1) → h a (s i) k}) a
isPropIsProp : isProp (isProp A)
isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i
isPropSingl : {a : A} → isProp (singl a)
isPropSingl = isContr→isProp (isContrSingl _)
isPropSinglP : {A : I → Type ℓ} {a : A i0} → isProp (singlP A a)
isPropSinglP = isContr→isProp (isContrSinglP _ _)
-- Universe lifting
record Lift {i j} (A : Type i) : Type (ℓ-max i j) where
constructor lift
field
lower : A
open Lift public
liftExt : ∀ {A : Type ℓ} {a b : Lift {ℓ} {ℓ'} A} → (lower a ≡ lower b) → a ≡ b
liftExt x i = lift (x i)
| 32.754352
| 102
| 0.481812
|
edc9f943c6972d4a3da8b60f600f3166a8eb900c
| 3,064
|
agda
|
Agda
|
Numeral/Integer/Relation/Divisibility/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Integer/Relation/Divisibility/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Integer/Relation/Divisibility/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Integer.Relation.Divisibility.Proofs where
open import Functional
open import Logic.Propositional
import Numeral.Natural.Relation.Divisibility as ℕ
import Numeral.Natural.Relation.Divisibility.Proofs as ℕ
open import Numeral.Natural using (ℕ)
import Numeral.Natural.Oper as ℕ
open import Numeral.Integer.Oper
open import Numeral.Integer.Proofs
open import Numeral.Integer.Relation.Divisibility
open import Numeral.Integer
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function.Multi
open import Structure.Operator.Properties
open import Structure.Relator
open import Structure.Relator.Properties
open import Type
instance
[∣][−𝐒ₙ]-sub : ((_∣_) on₂ (−𝐒ₙ_)) ⊆₂ ((ℕ._∣_) on₂ ℕ.𝐒)
[∣][−𝐒ₙ]-sub = intro id
instance
[∣][+ₙ]-sub : ((_∣_) on₂ (+ₙ_)) ⊆₂ (ℕ._∣_)
[∣][+ₙ]-sub = intro id
instance
[∣][−ₙ]-sub : ((_∣_) on₂ (−ₙ_)) ⊆₂ (ℕ._∣_)
_⊆₂_.proof [∣][−ₙ]-sub {ℕ.𝟎} {ℕ.𝟎} p = p
_⊆₂_.proof [∣][−ₙ]-sub {ℕ.𝟎} {ℕ.𝐒 y} p = p
_⊆₂_.proof [∣][−ₙ]-sub {ℕ.𝐒 x} {ℕ.𝟎} p = p
_⊆₂_.proof [∣][−ₙ]-sub {ℕ.𝐒 x} {ℕ.𝐒 y} p = p
instance
[∣][−𝐒ₙ]-super : ((_∣_) on₂ (−𝐒ₙ_)) ⊇₂ ((ℕ._∣_) on₂ ℕ.𝐒)
[∣][−𝐒ₙ]-super = intro id
instance
[∣][+ₙ]-super : ((_∣_) on₂ (+ₙ_)) ⊇₂ (ℕ._∣_)
[∣][+ₙ]-super = intro id
instance
[∣][−ₙ]-super : ((_∣_) on₂ (−ₙ_)) ⊇₂ (ℕ._∣_)
_⊆₂_.proof [∣][−ₙ]-super {ℕ.𝟎} {ℕ.𝟎} p = p
_⊆₂_.proof [∣][−ₙ]-super {ℕ.𝟎} {ℕ.𝐒 y} p = p
_⊆₂_.proof [∣][−ₙ]-super {ℕ.𝐒 x} {ℕ.𝟎} p = p
_⊆₂_.proof [∣][−ₙ]-super {ℕ.𝐒 x} {ℕ.𝐒 y} p = p
divides-with-[−ₙ] : ∀{a b c} → ((absₙ a) ℕ.∣ b) → ((absₙ a) ℕ.∣ c) → (a ∣ (b −ₙ c))
divides-with-[−ₙ] {a} ℕ.Div𝟎 ℕ.Div𝟎 = ℕ.Div𝟎
divides-with-[−ₙ] {a} (ℕ.Div𝐒 ab) ℕ.Div𝟎 = ℕ.Div𝐒 ab
divides-with-[−ₙ] {a} ℕ.Div𝟎 (ℕ.Div𝐒 {x = x} ac)
with p ← ℕ.divides-with-[+] (reflexivity(ℕ._∣_)) ((super₂((_∣_) on₂ (−ₙ_))(ℕ._∣_) ac))
rewrite absₙ-of-[−ₙ] {x}
rewrite absₙ-of-[−ₙ] {absₙ a}
rewrite [−ₙ]-antiidentityₗ {absₙ a ℕ.+ x}
rewrite absₙ-of-[−ₙ] {absₙ(a) ℕ.+ x}
= p
divides-with-[−ₙ] {a} (ℕ.Div𝐒 {x = x} ab) (ℕ.Div𝐒 {x = y} ac)
rewrite [−ₙ]-on-[+]ₗ-redundancy{absₙ a}{x}{y}
= divides-with-[−ₙ] {a} ab ac
divides-with-[+] : ∀{a b c} → (a ∣ b) → (a ∣ c) → (a ∣ (b + c))
divides-with-[+] {+ₙ a} {+ₙ b} {+ₙ c} ab ac = ℕ.divides-with-[+] ab ac
divides-with-[+] {+ₙ a} {+ₙ b} {−𝐒ₙ c} ab ac = divides-with-[−ₙ] {+ₙ a} ab ac
divides-with-[+] {+ₙ a} {−𝐒ₙ b} {+ₙ c} ab ac = divides-with-[−ₙ] {+ₙ a} ac ab
divides-with-[+] {+ₙ a} {−𝐒ₙ b} {−𝐒ₙ c} ab ac = ℕ.divides-with-[+] ab ac
divides-with-[+] {−𝐒ₙ a} {+ₙ b} {+ₙ c} ab ac = ℕ.divides-with-[+] ab ac
divides-with-[+] {−𝐒ₙ a} {+ₙ b} {−𝐒ₙ c} ab ac = divides-with-[−ₙ] {−𝐒ₙ a} ab ac
divides-with-[+] {−𝐒ₙ a} {−𝐒ₙ b} {+ₙ c} ab ac = divides-with-[−ₙ] {−𝐒ₙ a} ac ab
divides-with-[+] {−𝐒ₙ a} {−𝐒ₙ b} {−𝐒ₙ c} ab ac = ℕ.divides-with-[+] ab ac
divides-with-[⋅] : ∀{a b c} → ((a ∣ b) ∨ (a ∣ c)) → (a ∣ (b ⋅ c))
divides-with-[⋅] {a} {b} {c} p = substitute₂ᵣ(ℕ._∣_) {absₙ a} (symmetry(_≡_) (preserving₂(absₙ)(_⋅_)(ℕ._⋅_) {b}{c})) (ℕ.divides-with-[⋅] {absₙ a}{absₙ b}{absₙ c} p)
| 39.282051
| 164
| 0.563969
|
72ea0474c69abe1c522a64c00ad95e2d356f4678
| 3,020
|
agda
|
Agda
|
archive/agda-1/UnifyMguCorrectG.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/UnifyMguCorrectG.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/UnifyMguCorrectG.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Relation.Binary using (IsDecEquivalence)
open import Agda.Builtin.Equality
module UnifyMguCorrectG (FunctionName : Set) ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ (PredicateName VariableName : Set) where
open import UnifyTermF FunctionName
open import UnifyMguF FunctionName
open import UnifyMguCorrectF FunctionName
open import Data.Nat
open import Data.Vec
open import Function
open import Data.Fin renaming (thin to thinF; thick to thickF)
data Formula (n : ℕ) : Set
where
atomic : PredicateName → ∀ {t} → Vec (Term n) t → Formula n
logical : Formula n →
Formula n →
Formula n
quantified : Formula (suc n) → Formula n
open import Relation.Binary.PropositionalEquality
instance ThinFormula : Thin Formula
Thin.thin ThinFormula x (atomic x₁ x₂) = atomic x₁ (thin x x₂)
Thin.thin ThinFormula x (logical x₁ x₂) = logical (thin x x₁) (thin x x₂)
Thin.thin ThinFormula x (quantified x₁) = quantified (thin zero x₁)
Thin.thinfact1 ThinFormula f {atomic pn1 ts1} {atomic pn2 ts2} r = {!!}
Thin.thinfact1 ThinFormula f {atomic x x₁} {logical y y₁} ()
Thin.thinfact1 ThinFormula f {atomic x x₁} {quantified y} ()
Thin.thinfact1 ThinFormula f {logical x x₁} {atomic x₂ x₃} ()
Thin.thinfact1 ThinFormula f {logical x x₁} {logical y y₁} x₂ = {!!}
Thin.thinfact1 ThinFormula f {logical x x₁} {quantified y} ()
Thin.thinfact1 ThinFormula f {quantified x} {atomic x₁ x₂} ()
Thin.thinfact1 ThinFormula f {quantified x} {logical y y₁} ()
Thin.thinfact1 ThinFormula f {quantified x} {quantified y} x₁ = {!!}
foo~ : ∀ {m₁ n₁} →
(Fin m₁ → Term n₁) →
Fin (suc m₁) → Term (suc n₁)
foo~ f = (λ { zero → i zero ; (suc x) → thin zero (f x)})
foo~i≐i : ∀ {m} → foo~ {m} i ≐ i
foo~i≐i zero = refl
foo~i≐i (suc x) = refl
instance SubstitutionFormula : Substitution Formula
Substitution._◃_ SubstitutionFormula = _◃′_ where
_◃′_ : ∀ {m n} -> (f : m ~> n) -> Formula m -> Formula n
f ◃′ atomic 𝑃 τs = atomic 𝑃 (f ◃ τs)
f ◃′ logical φ₁ φ₂ = logical (f ◃ φ₁) (f ◃ φ₂)
f ◃′ quantified φ = quantified (foo~ f ◃ φ)
instance SubstitutionExtensionalityFormula : SubstitutionExtensionality Formula
SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (atomic x₁ x₂) = cong (atomic x₁) (◃ext x x₂)
SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (logical t t₁) = cong₂ logical (◃ext x t) (◃ext x t₁)
SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (quantified t) = cong quantified ((◃ext (λ { zero → refl ; (suc x₁) → cong (mapTerm suc) (x x₁)}) t)) --
instance SubFact1Formula : Sub.Fact1 Formula
Sub.Fact1.fact1 SubFact1Formula (atomic x x₁) = cong (atomic x) (Sub.fact1 x₁)
Sub.Fact1.fact1 SubFact1Formula (logical t t₁) = cong₂ logical (Sub.fact1 t) (Sub.fact1 t₁)
Sub.Fact1.fact1 SubFact1Formula {n} (quantified φ) = cong quantified (trans (◃ext {Formula} {_} {_} {foo~ {_} i} {i} (foo~i≐i {_}) φ) (Sub.fact1 φ))
Unifies⋆F : ∀ {m} (s t : Formula m) -> Property⋆ m
Unifies⋆F s t f = f ◃ s ≡ f ◃ t
| 44.411765
| 172
| 0.702318
|
0163526e04906f43f6c93fee7d33c9be4fc82794
| 229
|
agda
|
Agda
|
Cubical/HITs/Modulo.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Modulo.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/Modulo.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Modulo where
open import Cubical.HITs.Modulo.Base public
open import Cubical.HITs.Modulo.Properties public
open import Cubical.HITs.Modulo.FinEquiv public
| 25.444444
| 50
| 0.786026
|
0b440622a834ebc918e67e41b54c081d6039c72d
| 334
|
agda
|
Agda
|
test/Fail/Issue1606.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1606.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1606.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
postulate
C : Set
anything : C
record I : Set where
constructor c
field
f : C
data Wrap : (j : I) → Set where
wrap : ∀ {j} → Wrap j
-- The following should not pass.
-- It did before the fix of #142.
issue142 : ∀ {j} → Wrap j → C
issue142 {c _} (wrap {c _}) with anything
issue142 {c _} (wrap .{c anything}) | z = z
| 17.578947
| 43
| 0.595808
|
64a1362b3a46bd7f0ab0dd5101ddec104ddef54b
| 5,999
|
agda
|
Agda
|
Cubical/HITs/SetTruncation/Fibers.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/HITs/SetTruncation/Fibers.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetTruncation/Fibers.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Fibers of induced map between set truncations is the set truncation of fibers
modulo a certain equivalence relation defined by π₁ of the base.
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.SetTruncation.Fibers where
open import Cubical.HITs.SetTruncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Path
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.HITs.SetTruncation as Set
open import Cubical.HITs.SetQuotients as SetQuot
open import Cubical.Relation.Binary
private
variable
ℓ ℓ' : Level
module _
{X : Type ℓ }
{Y : Type ℓ'}
(f : X → Y) where
private
∥f∥₂ : ∥ X ∥₂ → ∥ Y ∥₂
∥f∥₂ = Set.map f
module _ (y : Y) where
open Iso
isSetFiber∥∥₂ : isSet (fiber ∥f∥₂ ∣ y ∣₂)
isSetFiber∥∥₂ = isOfHLevelΣ 2 squash₂ (λ _ → isProp→isSet (squash₂ _ _))
fiberRel : ∥ fiber f y ∥₂ → ∥ fiber f y ∥₂ → Type ℓ
fiberRel a b = Set.map fst a ≡ Set.map fst b
private
proj : ∥ fiber f y ∥₂ / fiberRel → ∥ X ∥₂
proj = SetQuot.rec squash₂ (Set.map fst) (λ _ _ p → p)
∥fiber∥₂/R→fiber∥∥₂ : ∥ fiber f y ∥₂ / fiberRel → fiber ∥f∥₂ ∣ y ∣₂
∥fiber∥₂/R→fiber∥∥₂ = SetQuot.rec isSetFiber∥∥₂ ∥fiber∥₂→fiber∥∥₂ feq
where
fiber→fiber∥∥₂ : fiber f y → fiber ∥f∥₂ ∣ y ∣₂
fiber→fiber∥∥₂ (x , p) = ∣ x ∣₂ , cong ∣_∣₂ p
∥fiber∥₂→fiber∥∥₂ : ∥ fiber f y ∥₂ → fiber ∥f∥₂ ∣ y ∣₂
∥fiber∥₂→fiber∥∥₂ = Set.rec isSetFiber∥∥₂ fiber→fiber∥∥₂
feq : (a b : ∥ fiber f y ∥₂) (r : fiberRel a b) → ∥fiber∥₂→fiber∥∥₂ a ≡ ∥fiber∥₂→fiber∥∥₂ b
feq =
Set.elim2 (λ _ _ → isProp→isSet (isPropΠ (λ _ → isSetFiber∥∥₂ _ _))) λ _ _ p →
ΣPathP (p , isSet→isSet' squash₂ _ _ _ _)
mereFiber→∥fiber∥₂/R : (x : X) → ∥ f x ≡ y ∥₁ → ∥ fiber f y ∥₂ / fiberRel
mereFiber→∥fiber∥₂/R x = Prop.rec→Set squash/ (λ p → [ ∣ _ , p ∣₂ ]) (λ _ _ → eq/ _ _ refl)
fiber∥∥₂→∥fiber∥₂/R : fiber ∥f∥₂ ∣ y ∣₂ → ∥ fiber f y ∥₂ / fiberRel
fiber∥∥₂→∥fiber∥₂/R =
uncurry
(Set.elim (λ _ → isSetΠ λ _ → squash/) λ x p →
mereFiber→∥fiber∥₂/R x (PathIdTrunc₀Iso .fun p))
∥fiber∥₂/R→fiber∥∥₂→fst : (q : ∥ fiber f y ∥₂ / fiberRel) → ∥fiber∥₂/R→fiber∥∥₂ q .fst ≡ proj q
∥fiber∥₂/R→fiber∥∥₂→fst =
SetQuot.elimProp (λ _ → squash₂ _ _)
(Set.elim (λ _ → isProp→isSet (squash₂ _ _)) (λ _ → refl))
fiber∥∥₂→∥fiber∥₂/R→proj : (x : fiber ∥f∥₂ ∣ y ∣₂) → proj (fiber∥∥₂→∥fiber∥₂/R x) ≡ x .fst
fiber∥∥₂→∥fiber∥₂/R→proj =
uncurry
(Set.elim (λ _ → isSetΠ λ _ → isProp→isSet (squash₂ _ _)) λ x p →
Prop.elim {P = λ t → proj (mereFiber→∥fiber∥₂/R x t) ≡ ∣ x ∣₂}
(λ _ → squash₂ _ _)
(λ _ → refl)
(PathIdTrunc₀Iso .fun p))
∥fiber∥₂/R→fiber∥∥₂→∥fiber∥₂/R :
(x : ∥ fiber f y ∥₂ / fiberRel) → fiber∥∥₂→∥fiber∥₂/R (∥fiber∥₂/R→fiber∥∥₂ x) ≡ x
∥fiber∥₂/R→fiber∥∥₂→∥fiber∥₂/R =
SetQuot.elimProp (λ _ → squash/ _ _)
(Set.elim (λ _ → isProp→isSet (squash/ _ _))
(λ _ → eq/ _ _ refl))
fiber∥∥₂→∥fiber∥₂/R→fiber∥∥₂ :
(x : fiber ∥f∥₂ ∣ y ∣₂) → ∥fiber∥₂/R→fiber∥∥₂ (fiber∥∥₂→∥fiber∥₂/R x) ≡ x
fiber∥∥₂→∥fiber∥₂/R→fiber∥∥₂ x =
Σ≡Prop
(λ _ → squash₂ _ _)
(∥fiber∥₂/R→fiber∥∥₂→fst (fiber∥∥₂→∥fiber∥₂/R x) ∙ fiber∥∥₂→∥fiber∥₂/R→proj x)
Iso-∥fiber∥₂/R-fiber∥∥₂ : Iso (∥ fiber f y ∥₂ / fiberRel) (fiber ∥f∥₂ ∣ y ∣₂)
Iso-∥fiber∥₂/R-fiber∥∥₂ .fun = ∥fiber∥₂/R→fiber∥∥₂
Iso-∥fiber∥₂/R-fiber∥∥₂ .inv = fiber∥∥₂→∥fiber∥₂/R
Iso-∥fiber∥₂/R-fiber∥∥₂ .leftInv = ∥fiber∥₂/R→fiber∥∥₂→∥fiber∥₂/R
Iso-∥fiber∥₂/R-fiber∥∥₂ .rightInv = fiber∥∥₂→∥fiber∥₂/R→fiber∥∥₂
-- main results
∥fiber∥₂/R≃fiber∥∥₂ : ∥ fiber f y ∥₂ / fiberRel ≃ fiber ∥f∥₂ ∣ y ∣₂
∥fiber∥₂/R≃fiber∥∥₂ = isoToEquiv Iso-∥fiber∥₂/R-fiber∥∥₂
-- the relation is an equivalence relation
open BinaryRelation
open isEquivRel
isEquivRelFiberRel : isEquivRel fiberRel
isEquivRelFiberRel .reflexive _ = refl
isEquivRelFiberRel .symmetric _ _ = sym
isEquivRelFiberRel .transitive _ _ _ = _∙_
-- alternative characterization of the relation in terms of equality in Y and fiber f y
∣transport∣ : ∥ y ≡ y ∥₂ → ∥ fiber f y ∥₂ → ∥ fiber f y ∥₂
∣transport∣ = Set.rec2 squash₂ (λ s (x , q) → ∣ x , q ∙ s ∣₂)
fiberRel2 : (x x' : ∥ fiber f y ∥₂) → Type (ℓ-max ℓ ℓ')
fiberRel2 x x' = ∥ Σ[ s ∈ ∥ y ≡ y ∥₂ ] ∣transport∣ s x ≡ x' ∥₁
fiberRel2→1 : ∀ x x' → fiberRel2 x x' → fiberRel x x'
fiberRel2→1 =
Set.elim2 (λ _ _ → isSetΠ λ _ → isOfHLevelPath 2 squash₂ _ _) λ _ _ →
Prop.rec (squash₂ _ _)
(uncurry
(Set.elim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 squash₂ _ _) λ _ →
cong (Set.map fst)))
fiberRel1→2 : ∀ x x' → fiberRel x x' → fiberRel2 x x'
fiberRel1→2 =
Set.elim2 (λ _ _ → isSetΠ λ _ → isProp→isSet squash₁) λ a b p →
Prop.rec squash₁
(λ q →
let
filler = doubleCompPath-filler (sym (a .snd)) (cong f q) (b .snd)
in
∣ ∣ filler i1 ∣₂ , cong ∣_∣₂ (ΣPathP (q , adjustLemma (flipSquare filler))) ∣₁)
(PathIdTrunc₀Iso .Iso.fun p)
where
adjustLemma : {x y z w : Y} {p : x ≡ y} {q : x ≡ z} {r : z ≡ w} {s : y ≡ w}
→ PathP (λ i → p i ≡ r i) q s
→ PathP (λ i → p i ≡ w) (q ∙ r) s
adjustLemma {p = p} {q} {r} {s} α i j =
hcomp
(λ k → λ
{ (i = i0) → compPath-filler q r k j
; (i = i1) → s j
; (j = i0) → p i
; (j = i1) → r (i ∨ k)})
(α i j)
fiberRel1≃2 : ∀ x x' → fiberRel x x' ≃ fiberRel2 x x'
fiberRel1≃2 _ _ =
propBiimpl→Equiv (squash₂ _ _) squash₁ (fiberRel1→2 _ _) (fiberRel2→1 _ _)
| 35.081871
| 99
| 0.564594
|
14dfaefee00e0e191606dbf861ef115e56b41283
| 21,327
|
agda
|
Agda
|
Cubical/ZCohomology/Groups/KleinBottle.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/ZCohomology/Groups/KleinBottle.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Groups/KleinBottle.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.KleinBottle where
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Equiv
open import Cubical.Data.Nat hiding (isEven)
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Int renaming (+Comm to +-commℤ ; _+_ to _+ℤ_)
open import Cubical.Data.Sigma
open import Cubical.HITs.SetTruncation as ST
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.HITs.Truncation as T
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.KleinBottle
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.DirProd
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Bool
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.Unit
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Loopspace
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open IsGroupHom
open Iso
characFunSpace𝕂² : ∀ {ℓ} (A : Type ℓ) →
Iso (KleinBottle → A)
(Σ[ x ∈ A ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q)
fun (characFunSpace𝕂² A) f =
(f point) ,
((cong f line1) ,
(cong f line2 ,
fst (Square≃doubleComp
(cong f line2) (cong f line2)
(sym (cong f line1)) (cong f line1))
(λ i j → f (square i j))))
inv (characFunSpace𝕂² A) (x , p , q , sq) point = x
inv (characFunSpace𝕂² A) (x , p , q , sq) (line1 i) = p i
inv (characFunSpace𝕂² A) (x , p , q , sq) (line2 i) = q i
inv (characFunSpace𝕂² A) (x , p , q , sq) (square i j) =
invEq (Square≃doubleComp q q (sym p) p) sq i j
rightInv (characFunSpace𝕂² A) (x , (p , (q , sq))) =
ΣPathP (refl , (ΣPathP (refl , (ΣPathP (refl , secEq (Square≃doubleComp q q (sym p) p) sq)))))
leftInv (characFunSpace𝕂² A) f _ point = f point
leftInv (characFunSpace𝕂² A) f _ (line1 i) = f (line1 i)
leftInv (characFunSpace𝕂² A) f _ (line2 i) = f (line2 i)
leftInv (characFunSpace𝕂² A) f z (square i j) =
retEq (Square≃doubleComp
(cong f line2) (cong f line2)
(sym (cong f line1)) (cong f line1))
(λ i j → f (square i j)) z i j
private
movePathLem : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x)
→ (p ∙∙ q ∙∙ p ≡ q) ≡ ((p ∙ p) ∙ q ≡ q)
movePathLem p q comm =
cong (_≡ q) (doubleCompPath-elim' p q p ∙∙ cong (p ∙_) (comm q p) ∙∙ assoc _ _ _)
movePathLem2 : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x)
→ (((p ∙ p) ∙ q) ∙ sym q ≡ q ∙ sym q) ≡ (p ∙ p ≡ refl)
movePathLem2 p q =
cong₂ _≡_ (sym (assoc (p ∙ p) q (sym q)) ∙∙ cong ((p ∙ p) ∙_) (rCancel q) ∙∙ sym (rUnit (p ∙ p)))
(rCancel q)
movePathIso : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x)
→ Iso (p ∙∙ q ∙∙ p ≡ q) (p ∙ p ≡ refl)
movePathIso {x = x} p q comm =
compIso (pathToIso (movePathLem p q comm))
(compIso (helper (p ∙ p))
(pathToIso (movePathLem2 p q)))
where
helper : (p : x ≡ x) → Iso (p ∙ q ≡ q) ((p ∙ q) ∙ sym q ≡ q ∙ sym q)
helper p = congIso (equivToIso (_ , compPathr-isEquiv (sym q)))
------ H¹(𝕂²) ≅ 0 --------------
H⁰-𝕂² : GroupIso (coHomGr 0 KleinBottle) ℤGroup
fun (fst H⁰-𝕂²) = ST.rec isSetℤ λ f → f point
inv (fst H⁰-𝕂²) x = ∣ (λ _ → x) ∣₂
rightInv (fst H⁰-𝕂²) _ = refl
leftInv (fst H⁰-𝕂²) =
ST.elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ f → cong ∣_∣₂ (funExt (λ {point → refl
; (line1 i) j → isSetℤ (f point) (f point) refl (cong f line1) j i
; (line2 i) j → isSetℤ (f point) (f point) refl (cong f line2) j i
; (square i j) z → helper f i j z}))
where
helper : (f : KleinBottle → ℤ)
→ Cube (λ j z → isSetℤ (f point) (f point) refl (cong f line2) z j)
(λ j z → isSetℤ (f point) (f point) refl (cong f line2) z j)
(λ i z → isSetℤ (f point) (f point) refl (cong f line1) z (~ i))
(λ i z → isSetℤ (f point) (f point) refl (cong f line1) z i)
refl
λ i j → f (square i j)
helper f = isGroupoid→isGroupoid' (isOfHLevelSuc 2 isSetℤ) _ _ _ _ _ _
snd H⁰-𝕂² =
makeIsGroupHom (ST.elim2 (λ _ _ → isOfHLevelPath 2 isSetℤ _ _) λ _ _ → refl)
------ H¹(𝕂¹) ≅ ℤ ------------
{-
Step one :
H¹(𝕂²) := ∥ 𝕂² → K₁ ∥₂
≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²)
≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂)
≡ ∥ Σ[ x ∈ K₁ ] (x ≡ x) ∥₂ (p ∙ p ≡ refl forces p ≡ refl. Also, p ∙ p ≡ refl is an hProp)
-}
nilpotent→≡0 : (x : ℤ) → x +ℤ x ≡ 0 → x ≡ 0
nilpotent→≡0 (pos zero) p = refl
nilpotent→≡0 (pos (suc n)) p =
⊥.rec (negsucNotpos _ _
(sym (cong (_- 1) (cong sucℤ (sym (helper2 n)) ∙ p))))
where
helper2 : (n : ℕ) → pos (suc n) +pos n ≡ pos (suc (n + n))
helper2 zero = refl
helper2 (suc n) = cong sucℤ (sym (sucℤ+pos n (pos (suc n))))
∙∙ cong (sucℤ ∘ sucℤ) (helper2 n)
∙∙ cong (pos ∘ suc ∘ suc) (sym (+-suc n n))
nilpotent→≡0 (negsuc n) p = ⊥.rec (negsucNotpos _ _ (helper2 n p))
where
helper2 : (n : ℕ) → (negsuc n +negsuc n) ≡ pos 0 → negsuc n ≡ pos (suc n)
helper2 n p = cong (negsuc n +ℤ_) (sym (helper3 n))
∙ +Assoc (negsuc n) (negsuc n) (pos (suc n))
∙∙ cong (_+ℤ (pos (suc n))) p
∙∙ cong sucℤ (+-commℤ (pos 0) (pos n))
where
helper3 : (n : ℕ) → negsuc n +pos (suc n) ≡ 0
helper3 zero = refl
helper3 (suc n) = cong sucℤ (sucℤ+pos n (negsuc (suc n))) ∙ helper3 n
nilpotent→≡refl : (x : coHomK 1) (p : x ≡ x) → p ∙ p ≡ refl → p ≡ refl
nilpotent→≡refl =
T.elim (λ _ → isGroupoidΠ2 λ _ _ → isOfHLevelPlus {n = 1} 2 (isOfHLevelTrunc 3 _ _ _ _))
(toPropElim (λ _ → isPropΠ2 λ _ _ → isOfHLevelTrunc 3 _ _ _ _)
λ p pId → sym (rightInv (Iso-Kn-ΩKn+1 0) p)
∙∙ cong (Kn→ΩKn+1 0) (nilpotent→≡0 (ΩKn+1→Kn 0 p)
(sym (ΩKn+1→Kn-hom 0 p p)
∙ cong (ΩKn+1→Kn 0) pId))
∙∙ Kn→ΩKn+10ₖ 0)
Iso-H¹-𝕂²₁ : Iso (Σ[ x ∈ coHomK 1 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl)
(Σ[ x ∈ coHomK 1 ] x ≡ x)
fun Iso-H¹-𝕂²₁ (x , (_ , (q , _))) = x , q
inv Iso-H¹-𝕂²₁ (x , q) = x , (refl , (q , (sym (rUnit refl))))
rightInv Iso-H¹-𝕂²₁ _ = refl
leftInv Iso-H¹-𝕂²₁ (x , (p , (q , P))) =
ΣPathP (refl ,
(ΣPathP (sym (nilpotent→≡refl x p P)
, toPathP (Σ≡Prop (λ _ → isOfHLevelTrunc 3 _ _ _ _)
(transportRefl q)))))
{- But this is precisely the type (minus set-truncation) of H¹(S¹) -}
Iso-H¹-𝕂²₂ : Iso (Σ[ x ∈ coHomK 1 ] x ≡ x) (S¹ → coHomK 1)
Iso-H¹-𝕂²₂ = invIso IsoFunSpaceS¹
H¹-𝕂²≅ℤ : GroupIso (coHomGr 1 KleinBottle) ℤGroup
H¹-𝕂²≅ℤ = compGroupIso theGroupIso (Hⁿ-Sⁿ≅ℤ 0)
where
theIso : Iso (coHom 1 KleinBottle) (coHom 1 S¹)
theIso =
setTruncIso (
compIso (characFunSpace𝕂² (coHomK 1))
(compIso
(Σ-cong-iso-snd (λ x → Σ-cong-iso-snd
λ p → Σ-cong-iso-snd
λ q → movePathIso p q (isCommΩK-based 1 x)))
(compIso Iso-H¹-𝕂²₁
Iso-H¹-𝕂²₂)))
is-hom : IsGroupHom (coHomGr 1 KleinBottle .snd) (fun theIso) (coHomGr 1 S¹ .snd)
is-hom =
makeIsGroupHom
(ST.elim2 (λ _ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ f g → cong ∣_∣₂ (funExt λ {base → refl ; (loop i) → refl}))
theGroupIso : GroupIso (coHomGr 1 KleinBottle) (coHomGr 1 S¹)
theGroupIso = (theIso , is-hom)
------ H²(𝕂²) ≅ ℤ/2ℤ (represented here by BoolGroup) -------
-- It suffices to show that H²(Klein) is equivalent to Bool as types
{-
Step one :
H²(𝕂²) := ∥ 𝕂² → K₂ ∥₂
≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²)
≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂)
≡ ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (connectedness of K₂)
-}
Iso-H²-𝕂²₁ : Iso ∥ Σ[ x ∈ coHomK 2 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂
∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl ∥₂
fun Iso-H²-𝕂²₁ =
ST.rec isSetSetTrunc
(uncurry (T.elim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 2} 2 isSetSetTrunc)
(sphereElim _ (λ _ → isSetΠ λ _ → isSetSetTrunc)
λ y → ∣ fst y , snd (snd y) ∣₂)))
inv Iso-H²-𝕂²₁ =
ST.map λ p → (0ₖ 2) , ((fst p) , (refl , (snd p)))
rightInv Iso-H²-𝕂²₁ =
ST.elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ p → refl
leftInv Iso-H²-𝕂²₁ =
ST.elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
(uncurry (T.elim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 1} 3 (isSetSetTrunc _ _))
(sphereToPropElim _
(λ _ → isPropΠ λ _ → isSetSetTrunc _ _)
λ {(p , (q , sq))
→ T.rec (isSetSetTrunc _ _)
(λ qid → cong ∣_∣₂ (ΣPathP (refl , (ΣPathP (refl , (ΣPathP (sym qid , refl)))))))
(fun (PathIdTruncIso _)
(isContr→isProp (isConnectedPathKn 1 (0ₖ 2) (0ₖ 2)) ∣ q ∣ ∣ refl ∣))})))
{- Step two : ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ -}
Iso-H²-𝕂²₂ : Iso ∥ (Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl) ∥₂ ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
Iso-H²-𝕂²₂ = setTruncIso (Σ-cong-iso {B' = λ x → x +ₖ x ≡ 0ₖ 1} (invIso (Iso-Kn-ΩKn+1 1))
λ p → compIso (congIso (invIso (Iso-Kn-ΩKn+1 1)))
(pathToIso λ i → ΩKn+1→Kn-hom 1 p p i ≡ 0ₖ 1))
{- Step three :
∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ ≡ Bool
We begin by defining the a map Σ[ x ∈ K₁ ] x + x ≡ 0 → Bool. For a point
(0 , p) we map it to true if winding(p) is even and false if winding(p) is odd.
We also have to show that this map respects the loop
-}
ΣKₙNilpot→Bool : Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 → Bool
ΣKₙNilpot→Bool = uncurry (T.elim (λ _ → isGroupoidΠ λ _ → isOfHLevelSuc 2 isSetBool)
λ {base p → isEven (ΩKn+1→Kn 0 p)
; (loop i) p → hcomp (λ k → λ { (i = i0) → respectsLoop p k
; (i = i1) → isEven (ΩKn+1→Kn 0 p)})
(isEven (ΩKn+1→Kn 0 (transp (λ j → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) i
p)))})
where
isEven-2 : (x : ℤ) → isEven (-2 +ℤ x) ≡ isEven x
isEven-2 (pos zero) = refl
isEven-2 (pos (suc zero)) = refl
isEven-2 (pos (suc (suc n))) =
cong isEven (cong sucℤ (sucℤ+pos _ _)
∙∙ sucℤ+pos _ _
∙∙ +-commℤ 0 (pos n))
∙ lossy n
where
lossy : (n : ℕ) → isEven (pos n) ≡ isEven (pos n)
lossy n = refl
isEven-2 (negsuc zero) = refl
isEven-2 (negsuc (suc n)) =
cong isEven (predℤ+negsuc n _
∙ +-commℤ -3 (negsuc n))
∙ lossy2 n
where
lossy2 : (n : ℕ) → isEven (negsuc (suc (suc (suc n)))) ≡ isEven (pos n)
lossy2 n = refl
respectsLoop : (p : 0ₖ 1 ≡ 0ₖ 1)
→ isEven (ΩKn+1→Kn 0 (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1) p))
≡ isEven (ΩKn+1→Kn 0 p)
respectsLoop p =
cong isEven (cong (ΩKn+1→Kn 0) (cong (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1))
(lUnit p)))
∙∙ cong isEven (cong (ΩKn+1→Kn 0)
λ j → transp (λ i → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) j
((λ i → ∣ (loop ∙ loop) (~ i ∧ j) ∣) ∙ p))
∙∙ cong isEven (ΩKn+1→Kn-hom 0 (sym (cong ∣_∣ (loop ∙ loop))) p)
∙ isEven-2 (ΩKn+1→Kn 0 p)
{-
We show that for any x : ℤ we have ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , refl) ∣₂ when x is even
and ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ when x is odd
This is done by induction on x. For the inductive step we define a multiplication _*_ on ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
which is just ∣ (0 , p) ∣₂ * ∣ (0 , q) ∣₂ ≡ ∣ (0 , p ∙ q) ∣₂ when x is 0
-}
private
_*_ : ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
_*_ = ST.rec (isSetΠ (λ _ → isSetSetTrunc)) λ a → ST.rec isSetSetTrunc λ b → *' (fst a) (fst b) (snd a) (snd b)
where
*' : (x y : coHomK 1) (p : x +ₖ x ≡ 0ₖ 1) (q : y +ₖ y ≡ 0ₖ 1) → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
*' =
T.elim2 (λ _ _ → isGroupoidΠ2 λ _ _ → isOfHLevelSuc 2 isSetSetTrunc)
(wedgeconFun _ _
(λ _ _ → isSetΠ2 λ _ _ → isSetSetTrunc)
(λ x p q → ∣ ∣ x ∣ , cong₂ _+ₖ_ p q ∣₂)
(λ y p q → ∣ ∣ y ∣ , sym (rUnitₖ 1 (∣ y ∣ +ₖ ∣ y ∣)) ∙ cong₂ _+ₖ_ p q ∣₂)
(funExt λ p → funExt λ q → cong ∣_∣₂ (ΣPathP (refl , (sym (lUnit _))))))
*=∙ : (p q : 0ₖ 1 ≡ 0ₖ 1) → ∣ 0ₖ 1 , p ∣₂ * ∣ 0ₖ 1 , q ∣₂ ≡ ∣ 0ₖ 1 , p ∙ q ∣₂
*=∙ p q = cong ∣_∣₂ (ΣPathP (refl , sym (∙≡+₁ p q)))
isEvenNegsuc : (n : ℕ) → isEven (pos (suc n)) ≡ true → isEven (negsuc n) ≡ true
isEvenNegsuc zero p = ⊥.rec (true≢false (sym p))
isEvenNegsuc (suc n) p = p
¬isEvenNegSuc : (n : ℕ) → isEven (pos (suc n)) ≡ false → isEven (negsuc n) ≡ false
¬isEvenNegSuc zero p = refl
¬isEvenNegSuc (suc n) p = p
evenCharac : (x : ℤ) → isEven x ≡ true
→ Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂
∣ (0ₖ 1 , refl) ∣₂
evenCharac (pos zero) isisEven i = ∣ (0ₖ 1) , (rUnit refl (~ i)) ∣₂
evenCharac (pos (suc zero)) isisEven = ⊥.rec (true≢false (sym isisEven))
evenCharac (pos (suc (suc zero))) isisEven =
cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (cong ∣_∣ ((lUnit loop (~ i)) ∙ loop)) (~ i))
∙ (ΣPathP (cong ∣_∣ loop , λ i j → ∣ (loop ∙ loop) (i ∨ j) ∣)))
evenCharac (pos (suc (suc (suc n)))) isisEven =
(λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos (suc n)) 2 i ∣₂)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos (suc n))) (Kn→ΩKn+1 0 (pos 2)))
∙∙ (cong₂ _*_ (evenCharac (pos (suc n)) isisEven) (evenCharac 2 refl))
evenCharac (negsuc zero) isisEven = ⊥.rec (true≢false (sym isisEven))
evenCharac (negsuc (suc zero)) isisEven =
cong ∣_∣₂ ((λ i → 0ₖ 1
, λ i₁ → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) i₁)
(inS ∣ compPath≡compPath' (sym loop) (sym loop) i i₁ ∣) (~ i))
∙ ΣPathP ((cong ∣_∣ (sym loop)) , λ i j → ∣ (sym loop ∙' sym loop) (i ∨ j) ∣))
evenCharac (negsuc (suc (suc n))) isisEven =
cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2))
∙∙ cong₂ _*_ (evenCharac (negsuc n) (isEvenNegsuc n isisEven)) (evenCharac -2 refl)
oddCharac : (x : ℤ) → isEven x ≡ false
→ Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂
∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂
oddCharac (pos zero) isOdd = ⊥.rec (true≢false isOdd)
oddCharac (pos (suc zero)) isOdd i =
∣ (0ₖ 1 , λ j → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) j)
(inS ∣ lUnit loop (~ i) j ∣) (~ i)) ∣₂
oddCharac (pos (suc (suc n))) isOdd =
(λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos n) 2 i ∣₂)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos n)) (Kn→ΩKn+1 0 2))
∙∙ cong₂ _*_ (oddCharac (pos n) isOdd) (evenCharac 2 refl)
oddCharac (negsuc zero) isOdd =
cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (sym (cong ∣_∣ loop)) (~ i))
∙ ΣPathP (cong ∣_∣ (sym loop) , λ i j → ∣ hcomp (λ k → λ { (i = i0) → loop (~ j ∧ k)
; (i = i1) → loop j
; (j = i1) → base})
(loop (j ∨ ~ i)) ∣))
oddCharac (negsuc (suc zero)) isOdd = ⊥.rec (true≢false isOdd)
oddCharac (negsuc (suc (suc n))) isOdd =
cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2))
∙∙ cong₂ _*_ (oddCharac (negsuc n) (¬isEvenNegSuc n isOdd)) (evenCharac (negsuc 1) refl)
{- We now have all we need to establish the Iso -}
Bool→ΣKₙNilpot : Bool → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
Bool→ΣKₙNilpot false = ∣ 0ₖ 1 , cong ∣_∣ loop ∣₂
Bool→ΣKₙNilpot true = ∣ 0ₖ 1 , refl ∣₂
testIso : Iso ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool
fun testIso = ST.rec isSetBool ΣKₙNilpot→Bool
inv testIso = Bool→ΣKₙNilpot
rightInv testIso false = refl
rightInv testIso true = refl
leftInv testIso =
ST.elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
(uncurry (T.elim
(λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (isSetSetTrunc _ _))
(toPropElim (λ _ → isPropΠ (λ _ → isSetSetTrunc _ _))
(λ p → path p (isEven (ΩKn+1→Kn 0 p)) refl))))
where
path : (p : 0ₖ 1 ≡ 0ₖ 1) (b : Bool) → (isEven (ΩKn+1→Kn 0 p) ≡ b)
→ Bool→ΣKₙNilpot (ΣKₙNilpot→Bool (∣ base ∣ , p)) ≡ ∣ ∣ base ∣ , p ∣₂
path p false q =
(cong Bool→ΣKₙNilpot q)
∙∙ sym (oddCharac (ΩKn+1→Kn 0 p) q)
∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i
path p true q =
cong Bool→ΣKₙNilpot q
∙∙ sym (evenCharac (ΩKn+1→Kn 0 p) q)
∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i
H²-𝕂²≅Bool : GroupIso (coHomGr 2 KleinBottle) BoolGroup
H²-𝕂²≅Bool = invGroupIso (≅Bool theIso)
where
theIso : Iso _ _
theIso =
compIso (setTruncIso
(compIso (characFunSpace𝕂² (coHomK 2))
(Σ-cong-iso-snd
λ x → Σ-cong-iso-snd
λ p → Σ-cong-iso-snd
λ q → (movePathIso p q (isCommΩK-based 2 x)))))
(compIso Iso-H²-𝕂²₁
(compIso
Iso-H²-𝕂²₂
testIso))
------ Hⁿ(𝕂²) ≅ 0 , n ≥ 3 ------
isContrHⁿ-𝕂² : (n : ℕ) → isContr (coHom (3 + n) KleinBottle)
isContrHⁿ-𝕂² n =
isOfHLevelRetractFromIso 0
(setTruncIso (characFunSpace𝕂² (coHomK _)))
isContrΣ-help
where
helper : (x : coHomK (3 + n))(p : x ≡ x) → (refl ≡ p) → (q : x ≡ x) → (refl ≡ q)
→ (P : p ∙∙ q ∙∙ p ≡ q)
→ Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂
∣ x , p , q , P ∣₂
∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂
helper =
T.elim (λ _ → isProp→isOfHLevelSuc (4 + n) (isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → isSetSetTrunc _ _))
(sphereToPropElim _ (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → isSetSetTrunc _ _)
λ p → J (λ p _ → (q : 0ₖ _ ≡ 0ₖ _) → (refl ≡ q)
→ (P : p ∙∙ q ∙∙ p ≡ q)
→ Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂
∣ 0ₖ _ , p , q , P ∣₂
∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂)
λ q → J (λ q _ → (P : refl ∙∙ q ∙∙ refl ≡ q)
→ Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂
∣ 0ₖ _ , refl , q , P ∣₂
∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂)
λ P → T.rec (isProp→isOfHLevelSuc n (isSetSetTrunc _ _))
(λ P≡rUnitrefl i → ∣ 0ₖ (3 + n) , refl , refl , P≡rUnitrefl i ∣₂)
(fun (PathIdTruncIso _)
(isContr→isProp (isConnectedPath _ (isConnectedPathKn (2 + n) _ _)
(refl ∙∙ refl ∙∙ refl) refl)
∣ P ∣ ∣ sym (rUnit refl) ∣)))
isContrΣ-help : isContr ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂
fst isContrΣ-help = ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂
snd isContrΣ-help =
ST.elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ {(x , p , q , P)
→ T.rec (isProp→isOfHLevelSuc (suc n) (isSetSetTrunc _ _))
(λ pId → T.rec (isProp→isOfHLevelSuc (suc n) (isSetSetTrunc _ _))
(λ qId → sym (helper x p pId q qId P))
(fun (PathIdTruncIso (2 + n))
(isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ q ∣)))
(fun (PathIdTruncIso (2 + n))
(isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ p ∣))}
Hⁿ⁺³-𝕂²≅0 : (n : ℕ) → GroupIso (coHomGr (3 + n) KleinBottle) UnitGroup₀
Hⁿ⁺³-𝕂²≅0 n = contrGroupIsoUnit (isContrHⁿ-𝕂² n)
| 46.565502
| 141
| 0.505416
|
7286d973d1701959c8d07edeb5ce8cda45fdf84d
| 13,426
|
agda
|
Agda
|
src/Categories/NaturalTransformation/NaturalIsomorphism/Monoidal.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/NaturalTransformation/NaturalIsomorphism/Monoidal.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/NaturalTransformation/NaturalIsomorphism/Monoidal.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.Monoidal
open import Categories.Functor.Monoidal
module Categories.NaturalTransformation.NaturalIsomorphism.Monoidal
where
open import Level
open import Data.Product using (_,_)
open import Relation.Binary using (IsEquivalence; Setoid)
open import Categories.Category.Product
import Categories.Category.Monoidal.Reasoning as MonoidalReasoning
import Categories.Category.Monoidal.Utilities as MonoidalUtilities
open import Categories.Functor hiding (id)
open import Categories.Functor.Monoidal.Properties using () renaming
( idF-Monoidal to idFˡ ; idF-StrongMonoidal to idFˢ
; ∘-Monoidal to _∘Fˡ_ ; ∘-StrongMonoidal to _∘Fˢ_
)
import Categories.Morphism.Reasoning as MorphismReasoning
import Categories.NaturalTransformation.Monoidal as NT
open import Categories.NaturalTransformation.NaturalIsomorphism as NI
using (NaturalIsomorphism)
open NaturalIsomorphism using (F⇒G; F⇐G)
-- Monoidal natural isomorphisms between lax monoidal functors.
module Lax where
open NT.Lax hiding (id)
module _ {o ℓ e o′ ℓ′ e′}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′}
(F G : MonoidalFunctor C D) where
private
module C = MonoidalCategory C
module D = MonoidalCategory D
module F = MonoidalFunctor F renaming (F to U)
module G = MonoidalFunctor G renaming (F to U)
IsMonoidalNaturalIsomorphism : NaturalIsomorphism F.U G.U → Set (o ⊔ ℓ′ ⊔ e′)
IsMonoidalNaturalIsomorphism α = IsMonoidalNaturalTransformation F G (F⇒G α)
record MonoidalNaturalIsomorphism : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
field
U : NaturalIsomorphism F.U G.U
F⇒G-isMonoidal : IsMonoidalNaturalIsomorphism U
open NaturalIsomorphism U public hiding (module ⇒; module ⇐)
open IsMonoidalNaturalTransformation F⇒G-isMonoidal public
open D using (module Equiv)
open MorphismReasoning D.U using (switch-fromtoˡ; conjugate-from)
open MonoidalUtilities D.monoidal using (_⊗ᵢ_)
F⇐G-isMonoidal : IsMonoidalNaturalTransformation G F (F⇐G U)
F⇐G-isMonoidal = record
{ ε-compat = Equiv.sym (switch-fromtoˡ FX≅GX ε-compat)
; ⊗-homo-compat =
conjugate-from (FX≅GX ⊗ᵢ FX≅GX) FX≅GX (Equiv.sym ⊗-homo-compat)
}
F⇒G-monoidal : MonoidalNaturalTransformation F G
F⇒G-monoidal = record { U = F⇒G U ; isMonoidal = F⇒G-isMonoidal }
F⇐G-monoidal : MonoidalNaturalTransformation G F
F⇐G-monoidal = record { U = F⇐G U ; isMonoidal = F⇐G-isMonoidal }
module ⇒ = MonoidalNaturalTransformation F⇒G-monoidal
module ⇐ = MonoidalNaturalTransformation F⇐G-monoidal
infix 4 _≃_
_≃_ = MonoidalNaturalIsomorphism
open MonoidalNaturalTransformation using (isMonoidal)
open MonoidalNaturalIsomorphism
-- Identity and compositions
module _ {o ℓ e o′ ℓ′ e′}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′} where
infixr 9 _ⓘᵥ_
id : {F : MonoidalFunctor C D} → F ≃ F
id = record { U = NI.refl ; F⇒G-isMonoidal = isMonoidal NT.Lax.id }
_ⓘᵥ_ : {F G H : MonoidalFunctor C D} → G ≃ H → F ≃ G → F ≃ H
_ⓘᵥ_ α β = record
{ U = U α NI.ⓘᵥ U β
; F⇒G-isMonoidal = isMonoidal (F⇒G-monoidal α ∘ᵥ F⇒G-monoidal β)
}
isEquivalence : IsEquivalence _≃_
isEquivalence = record
{ refl = id
; sym = λ α → record
{ U = NI.sym (U α)
; F⇒G-isMonoidal = F⇐G-isMonoidal α
}
; trans = λ α β → β ⓘᵥ α
}
module _ {o ℓ e o′ ℓ′ e′ o″ ℓ″ e″}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′}
{E : MonoidalCategory o″ ℓ″ e″} where
infixr 9 _ⓘₕ_ _ⓘˡ_ _ⓘʳ_
_ⓘₕ_ : {F G : MonoidalFunctor C D} {H I : MonoidalFunctor D E} →
H ≃ I → F ≃ G → (H ∘Fˡ F) ≃ (I ∘Fˡ G)
_ⓘₕ_ α β = record
{ U = U α NI.ⓘₕ U β
; F⇒G-isMonoidal = isMonoidal (F⇒G-monoidal α ∘ₕ F⇒G-monoidal β)
}
_ⓘˡ_ : {F G : MonoidalFunctor C D}
(H : MonoidalFunctor D E) → F ≃ G → (H ∘Fˡ F) ≃ (H ∘Fˡ G)
H ⓘˡ α = id {F = H} ⓘₕ α
_ⓘʳ_ : {G H : MonoidalFunctor D E} →
G ≃ H → (F : MonoidalFunctor C D) → (G ∘Fˡ F) ≃ (H ∘Fˡ F)
α ⓘʳ F = α ⓘₕ id {F = F}
-- Left and right unitors.
module _ {o ℓ e o′ ℓ′ e′}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′}
{F : MonoidalFunctor C D} where
private
module C = MonoidalCategory C
module D = MonoidalCategory D
module F = MonoidalFunctor F
open D hiding (U; id; unitorˡ; unitorʳ)
open MorphismReasoning D.U using (id-comm-sym)
open MonoidalReasoning D.monoidal
unitorˡ : idFˡ D ∘Fˡ F ≃ F
unitorˡ = record
{ U = NI.unitorˡ
; F⇒G-isMonoidal = record
{ ε-compat = identityˡ ○ identityʳ
; ⊗-homo-compat = λ {X Y} → begin
D.id D.∘ F.⊗-homo.η (X , Y) D.∘ D.id ≈⟨ identityˡ ⟩
F.⊗-homo.η (X , Y) D.∘ D.id ≈˘⟨ refl⟩∘⟨ ⊗.identity ⟩
F.⊗-homo.η (X , Y) D.∘ D.id ⊗₁ D.id ∎
}
}
unitorʳ : F ∘Fˡ idFˡ C ≃ F
unitorʳ = record
{ U = NI.unitorʳ
; F⇒G-isMonoidal = record
{ ε-compat = begin
D.id ∘ F.₁ C.id ∘ F.ε ≈⟨ identityˡ ⟩
F.₁ C.id ∘ F.ε ≈⟨ F.identity ⟩∘⟨refl ⟩
D.id ∘ F.ε ≈⟨ identityˡ ⟩
F.ε ∎
; ⊗-homo-compat = λ {X Y} → begin
D.id D.∘ F.₁ C.id ∘ F.⊗-homo.η (X , Y) ≈⟨ identityˡ ⟩
F.₁ C.id ∘ F.⊗-homo.η (X , Y) ≈⟨ F.identity ⟩∘⟨refl ⟩
D.id ∘ F.⊗-homo.η (X , Y) ≈⟨ id-comm-sym ⟩
F.⊗-homo.η (X , Y) D.∘ D.id ≈˘⟨ refl⟩∘⟨ ⊗.identity ⟩
F.⊗-homo.η (X , Y) D.∘ D.id ⊗₁ D.id ∎
}
}
-- Associator.
module _ {o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ o‴ ℓ‴ e‴}
{B : MonoidalCategory o ℓ e} {C : MonoidalCategory o′ ℓ′ e′}
{D : MonoidalCategory o″ ℓ″ e″} {E : MonoidalCategory o‴ ℓ‴ e‴}
{F : MonoidalFunctor B C} {G : MonoidalFunctor C D}
{H : MonoidalFunctor D E} where
private
module D = MonoidalCategory D
module E = MonoidalCategory E
module F = MonoidalFunctor F
module G = MonoidalFunctor G
module H = MonoidalFunctor H
open E hiding (U; id; associator)
open MorphismReasoning E.U
open MonoidalReasoning E.monoidal
associator : (H ∘Fˡ G) ∘Fˡ F ≃ H ∘Fˡ (G ∘Fˡ F)
associator = record
{ U = NI.associator (F.F) (G.F) (H.F)
; F⇒G-isMonoidal = record
{ ε-compat = begin
E.id ∘ H.₁ (G.₁ F.ε) ∘ H.₁ G.ε ∘ H.ε ≈⟨ identityˡ ⟩
H.₁ (G.₁ F.ε) ∘ H.₁ G.ε ∘ H.ε ≈˘⟨ pushˡ H.homomorphism ⟩
H.₁ (G.₁ F.ε D.∘ G.ε) ∘ H.ε ∎
; ⊗-homo-compat = λ {X Y} → begin
E.id ∘ H.₁ (G.₁ (F.⊗-homo.η (X , Y))) ∘
H.₁ (G.⊗-homo.η (F.F₀ X , F.F₀ Y)) ∘
H.⊗-homo.η (G.F₀ (F.F₀ X) , G.F₀ (F.F₀ Y))
≈⟨ identityˡ ⟩
H.₁ (G.₁ (F.⊗-homo.η (X , Y))) ∘
H.₁ (G.⊗-homo.η (F.F₀ X , F.F₀ Y)) ∘
H.⊗-homo.η (G.F₀ (F.F₀ X) , G.F₀ (F.F₀ Y))
≈˘⟨ pushˡ H.homomorphism ⟩
H.₁ (G.₁ (F.⊗-homo.η (X , Y)) D.∘ G.⊗-homo.η (F.F₀ X , F.F₀ Y)) ∘
H.⊗-homo.η (G.F₀ (F.F₀ X) , G.F₀ (F.F₀ Y))
≈˘⟨ identityʳ ⟩
(H.₁ (G.₁ (F.⊗-homo.η (X , Y)) D.∘ G.⊗-homo.η (F.F₀ X , F.F₀ Y)) ∘
H.⊗-homo.η (G.F₀ (F.F₀ X) , G.F₀ (F.F₀ Y))) ∘ E.id
≈˘⟨ refl⟩∘⟨ ⊗.identity ⟩
(H.₁ (G.₁ (F.⊗-homo.η (X , Y)) D.∘ G.⊗-homo.η (F.F₀ X , F.F₀ Y)) ∘
H.⊗-homo.η (G.F₀ (F.F₀ X) , G.F₀ (F.F₀ Y))) ∘
E.id ⊗₁ E.id
∎
}
}
-- Monoidal natural isomorphisms between strong monoidal functors.
module Strong where
open NT.Strong hiding (id; strengthen)
open StrongMonoidalFunctor renaming (F to UF; monoidalFunctor to laxF)
module _ {o ℓ e o′ ℓ′ e′}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′}
(F G : StrongMonoidalFunctor C D) where
IsMonoidalNaturalIsomorphism : NaturalIsomorphism (UF F) (UF G) →
Set (o ⊔ ℓ′ ⊔ e′)
IsMonoidalNaturalIsomorphism α = IsMonoidalNaturalTransformation F G (F⇒G α)
-- NOTE. This record contains the same data as the lax version,
-- but the type arguments are different. This helps type
-- inference by providing the right constraints.
record MonoidalNaturalIsomorphism : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
field
U : NaturalIsomorphism (UF F) (UF G)
F⇒G-isMonoidal : IsMonoidalNaturalIsomorphism U
laxNI : Lax.MonoidalNaturalIsomorphism (laxF F) (laxF G)
laxNI = record { U = U ; F⇒G-isMonoidal = F⇒G-isMonoidal }
open Lax.MonoidalNaturalIsomorphism laxNI public hiding
(U; F⇒G-isMonoidal; F⇒G-monoidal; F⇐G-monoidal; module ⇒; module ⇐)
F⇒G-monoidal : MonoidalNaturalTransformation F G
F⇒G-monoidal = record { U = F⇒G U ; isMonoidal = F⇒G-isMonoidal }
F⇐G-monoidal : MonoidalNaturalTransformation G F
F⇐G-monoidal = record { U = F⇐G U ; isMonoidal = F⇐G-isMonoidal }
module ⇒ = MonoidalNaturalTransformation F⇒G-monoidal
module ⇐ = MonoidalNaturalTransformation F⇐G-monoidal
infix 4 _≃_
_≃_ = MonoidalNaturalIsomorphism
open MonoidalNaturalIsomorphism
module _ {o ℓ e o′ ℓ′ e′}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′} where
infixr 9 _ⓘᵥ_
-- Since they contain the same data, we can strengthen a lax
-- monoidal isomorphism to a strong one.
strengthen : {F G : StrongMonoidalFunctor C D} →
(laxF F) Lax.≃ (laxF G) → F ≃ G
strengthen α = record { U = L.U ; F⇒G-isMonoidal = L.F⇒G-isMonoidal }
where module L = Lax.MonoidalNaturalIsomorphism α
-- Identity and compositions
id : {F : StrongMonoidalFunctor C D} → F ≃ F
id = strengthen Lax.id
_ⓘᵥ_ : {F G H : StrongMonoidalFunctor C D} → G ≃ H → F ≃ G → F ≃ H
α ⓘᵥ β = strengthen (laxNI α Lax.ⓘᵥ laxNI β)
isEquivalence : IsEquivalence _≃_
isEquivalence = record
{ refl = λ {F} → id {F}
; sym = λ α → record
{ U = NI.sym (U α)
; F⇒G-isMonoidal = F⇐G-isMonoidal α
}
; trans = λ {F} {G} {H} α β → _ⓘᵥ_ {F} {G} {H} β α
}
module _ {o ℓ e o′ ℓ′ e′ o″ ℓ″ e″}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′}
{E : MonoidalCategory o″ ℓ″ e″} where
open Lax.MonoidalNaturalIsomorphism
infixr 9 _ⓘₕ_ _ⓘˡ_ _ⓘʳ_
_ⓘₕ_ : {F G : StrongMonoidalFunctor C D} {H I : StrongMonoidalFunctor D E} →
H ≃ I → F ≃ G → (H ∘Fˢ F) ≃ (I ∘Fˢ G)
-- FIXME: this definition is clearly equivalent to
--
-- α ⓘₕ β = strengthen (laxNI α Lax.ⓘₕ laxNI β)
--
-- but the latter takes an unreasonably long time to typecheck,
-- while the unfolded version typechecks almost immediately.
α ⓘₕ β = record
{ U = L.U
; F⇒G-isMonoidal = record
{ ε-compat = L.ε-compat
; ⊗-homo-compat = L.⊗-homo-compat }
}
where
module L = Lax.MonoidalNaturalIsomorphism (laxNI α Lax.ⓘₕ laxNI β)
_ⓘˡ_ : {F G : StrongMonoidalFunctor C D}
(H : StrongMonoidalFunctor D E) → F ≃ G → (H ∘Fˢ F) ≃ (H ∘Fˢ G)
H ⓘˡ α = id {F = H} ⓘₕ α
_ⓘʳ_ : {G H : StrongMonoidalFunctor D E} →
G ≃ H → (F : StrongMonoidalFunctor C D) → (G ∘Fˢ F) ≃ (H ∘Fˢ F)
α ⓘʳ F = α ⓘₕ id {F = F}
-- Left and right unitors.
module _ {o ℓ e o′ ℓ′ e′}
{C : MonoidalCategory o ℓ e} {D : MonoidalCategory o′ ℓ′ e′}
{F : StrongMonoidalFunctor C D} where
unitorˡ : idFˢ D ∘Fˢ F ≃ F
-- FIXME: Again, this unfolded definition typechecks considerably
-- faster than the equivalent
--
-- strengthen (Lax.unitorʳ {F = laxF F})
unitorˡ = record
{ U = L.U
; F⇒G-isMonoidal = record
{ ε-compat = L.ε-compat
; ⊗-homo-compat = L.⊗-homo-compat
}
}
where module L = Lax.MonoidalNaturalIsomorphism (Lax.unitorˡ {F = laxF F})
unitorʳ : F ∘Fˢ idFˢ C ≃ F
-- FIXME: ... same here ...
unitorʳ = record
{ U = L.U
; F⇒G-isMonoidal = record
{ ε-compat = L.ε-compat
; ⊗-homo-compat = L.⊗-homo-compat
}
}
where module L = Lax.MonoidalNaturalIsomorphism (Lax.unitorʳ {F = laxF F})
-- Associator.
module _ {o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ o‴ ℓ‴ e‴}
{B : MonoidalCategory o ℓ e} {C : MonoidalCategory o′ ℓ′ e′}
{D : MonoidalCategory o″ ℓ″ e″} {E : MonoidalCategory o‴ ℓ‴ e‴}
{F : StrongMonoidalFunctor B C} {G : StrongMonoidalFunctor C D}
{H : StrongMonoidalFunctor D E} where
associator : (H ∘Fˢ G) ∘Fˢ F ≃ H ∘Fˢ (G ∘Fˢ F)
-- FIXME: ... and here. Though, for this one, even the unfolded
-- version takes a lot of time.
associator = record
{ U = L.U
; F⇒G-isMonoidal = record
{ ε-compat = L.ε-compat
; ⊗-homo-compat = L.⊗-homo-compat
}
}
where
α = Lax.associator {F = laxF F} {laxF G} {laxF H}
module L = Lax.MonoidalNaturalIsomorphism α
| 35.612732
| 81
| 0.555936
|
0178a67fd129f47ed17d7eba8efcc324ffd95217
| 1,375
|
agda
|
Agda
|
models/DescFix.agda
|
dataronio/epigram2
|
17b7858f51a35b3becb8433028c3f1ba25fbba9a
|
[
"MIT"
] | 48
|
2016-01-09T17:36:19.000Z
|
2022-02-11T01:55:28.000Z
|
models/DescFix.agda
|
seanwallawalla-forks/Epigram
|
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
|
[
"MIT"
] | null | null | null |
models/DescFix.agda
|
seanwallawalla-forks/Epigram
|
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
|
[
"MIT"
] | 12
|
2016-08-14T21:36:35.000Z
|
2022-02-11T01:57:40.000Z
|
{-# OPTIONS --type-in-type #-}
module DescFix where
open import DescTT
aux : (C : Desc)(D : Desc)(P : Mu C -> Set)(x : [| D |] (Mu C)) -> Set
aux C id P (con y) = P (con y) * aux C C P y
aux C (const K) P k = Unit
aux C (prod D D') P (s , t) = aux C D P s * aux C D' P t
aux C (sigma S T) P (s , t) = aux C (T s) P t
aux C (pi S T) P f = (s : S) -> aux C (T s) P (f s)
gen : (C : Desc)(D : Desc)(P : Mu C -> Set)
(rec : (y : [| C |] Mu C) -> aux C C P y -> P (con y))
(x : [| D |] Mu C) -> aux C D P x
gen C id P rec (con x) = rec x (gen C C P rec x) , gen C C P rec x
gen C (const K) P rec k = Void
gen C (prod D D') P rec (s , t) = gen C D P rec s , gen C D' P rec t
gen C (sigma S T) P rec (s , t) = gen C (T s) P rec t
gen C (pi S T) P rec f = \ s -> gen C (T s) P rec (f s)
fix : (D : Desc)(P : Mu D -> Set)
(rec : (y : [| D |] Mu D) -> aux D D P y -> P (con y))
(x : Mu D) -> P x
fix D P rec (con x) = rec x (gen D D P rec x)
plus : Nat -> Nat -> Nat
plus (con (Ze , Void)) n = n
plus (con (Suc , m)) n = suc (plus m n)
fib : Nat -> Nat
fib = fix NatD (\ _ -> Nat) help
where
help : (m : [| NatD |] Nat) -> aux NatD NatD (\ _ -> Nat) m -> Nat
help (Ze , x) a = suc ze
help (Suc , con (Ze , _)) a = suc ze
help (Suc , con (Suc , con n)) (fib-n , (fib-sn , a)) = plus fib-n fib-sn
| 31.976744
| 77
| 0.464
|
72402de561f05694959156cb60ee9c2a50b883ac
| 8,158
|
agda
|
Agda
|
Groups/Cyclic/DefinitionLemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Groups/Cyclic/DefinitionLemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Groups/Cyclic/DefinitionLemmas.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 Setoids.Setoids
open import Sets.EquivalenceRelations
open import Numbers.Naturals.Semiring
open import Numbers.Integers.Integers
open import Numbers.Integers.Addition
open import Groups.Lemmas
open import Groups.Definition
open import Groups.Cyclic.Definition
open import Semirings.Definition
module Groups.Cyclic.DefinitionLemmas {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} (G : Group S _+_) where
open Setoid S
open Group G
open Equivalence eq
elementPowerCommutes : (x : A) (n : ℕ) → (x + positiveEltPower G x n) ∼ ((positiveEltPower G x n) + x)
elementPowerCommutes x zero = transitive identRight (symmetric identLeft)
elementPowerCommutes x (succ n) = transitive (+WellDefined reflexive (elementPowerCommutes x n)) +Associative
elementPowerCollapse : (x : A) (i j : ℤ) → Setoid._∼_ S ((elementPower G x i) + (elementPower G x j)) (elementPower G x (i +Z j))
elementPowerCollapse x (nonneg a) (nonneg b) rewrite equalityCommutative (+Zinherits a b) = positiveEltPowerCollapse G x a b
elementPowerCollapse x (nonneg zero) (negSucc b) = identLeft
elementPowerCollapse x (nonneg (succ a)) (negSucc zero) = transitive (+WellDefined (elementPowerCommutes x a) reflexive) (transitive (symmetric +Associative) (transitive (+WellDefined reflexive (transitive (+WellDefined reflexive (invContravariant G)) (transitive (+WellDefined reflexive (transitive (+WellDefined (invIdent G) reflexive) identLeft)) invRight))) identRight))
elementPowerCollapse x (nonneg (succ a)) (negSucc (succ b)) = transitive (transitive (+WellDefined (elementPowerCommutes x a) reflexive) (transitive (symmetric +Associative) (+WellDefined reflexive (transitive (transitive (+WellDefined reflexive (inverseWellDefined G (transitive (+WellDefined reflexive (elementPowerCommutes x b)) +Associative))) (transitive (+WellDefined reflexive (invContravariant G)) (transitive +Associative (transitive (+WellDefined invRight (invContravariant G)) identLeft)))) (symmetric (invContravariant G)))))) (elementPowerCollapse x (nonneg a) (negSucc b))
elementPowerCollapse x (negSucc zero) (nonneg zero) = identRight
elementPowerCollapse x (negSucc zero) (nonneg (succ b)) = transitive (transitive +Associative (+WellDefined (transitive (+WellDefined (inverseWellDefined G identRight) reflexive) invLeft) reflexive)) identLeft
elementPowerCollapse x (negSucc (succ a)) (nonneg zero) = identRight
elementPowerCollapse x (negSucc (succ a)) (nonneg (succ b)) = transitive (transitive +Associative (+WellDefined (transitive (+WellDefined (invContravariant G) reflexive) (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invLeft) identRight))) reflexive)) (elementPowerCollapse x (negSucc a) (nonneg b))
elementPowerCollapse x (negSucc a) (negSucc b) = transitive (+WellDefined reflexive (invContravariant G)) (transitive (transitive (transitive +Associative (+WellDefined (transitive (symmetric (invContravariant G)) (transitive (inverseWellDefined G +Associative) (transitive (inverseWellDefined G (+WellDefined (symmetric (elementPowerCommutes x b)) reflexive)) (transitive (inverseWellDefined G (symmetric +Associative)) (transitive (invContravariant G) (+WellDefined (inverseWellDefined G (transitive (positiveEltPowerCollapse G x b a) (identityOfIndiscernablesRight _∼_ reflexive (applyEquality (positiveEltPower G x) {b +N a} {a +N b} (Semiring.commutative ℕSemiring b a))))) reflexive)))))) reflexive)) (+WellDefined (symmetric (invContravariant G)) reflexive)) (symmetric (invContravariant G)))
positiveEltPowerInverse : (m : ℕ) → (x : A) → (positiveEltPower G (inverse x) m) ∼ inverse (positiveEltPower G x m)
positiveEltPowerInverse zero x = symmetric (invIdent G)
positiveEltPowerInverse (succ m) x = transitive (+WellDefined reflexive (positiveEltPowerInverse m x)) (transitive (symmetric (invContravariant G)) (inverseWellDefined G (symmetric (elementPowerCommutes x m))))
positiveEltPowerMultiplies : (m n : ℕ) → (x : A) → (positiveEltPower G x (m *N n)) ∼ (positiveEltPower G (positiveEltPower G x n) m)
positiveEltPowerMultiplies zero n x = reflexive
positiveEltPowerMultiplies (succ m) n x = transitive (symmetric (positiveEltPowerCollapse G x n (m *N n))) (+WellDefined reflexive (positiveEltPowerMultiplies m n x))
powerZero : (m : ℕ) → positiveEltPower G 0G m ∼ 0G
powerZero zero = reflexive
powerZero (succ m) = transitive identLeft (powerZero m)
elementPowerMultiplies : (m n : ℤ) → (x : A) → (elementPower G x (m *Z n)) ∼ (elementPower G (elementPower G x n) m)
elementPowerMultiplies (nonneg m) (nonneg n) x = positiveEltPowerMultiplies m n x
elementPowerMultiplies (nonneg zero) (negSucc n) x = reflexive
elementPowerMultiplies (nonneg (succ m)) (negSucc n) x = transitive (transitive (inverseWellDefined G (transitive (transitive (elementPowerWellDefinedZ' G (nonneg (succ (n +N m *N n) +N m)) (nonneg (m *N succ n +N succ n)) (applyEquality nonneg (transitivity (applyEquality succ (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring n (m *N n) m)) (applyEquality (n +N_) (transitivity (transitivity (Semiring.commutative ℕSemiring _ m) (applyEquality (m +N_) (multiplicationNIsCommutative m n))) (multiplicationNIsCommutative (succ n) m))))) (Semiring.commutative ℕSemiring (succ n) _))) {x}) (symmetric (positiveEltPowerCollapse G x (m *N succ n) (succ n)))) (+WellDefined (positiveEltPowerMultiplies m (succ n) x) reflexive))) (invContravariant G)) (+WellDefined reflexive (symmetric (positiveEltPowerInverse m (x + positiveEltPower G x n))))
elementPowerMultiplies (negSucc m) (nonneg zero) r = transitive (symmetric (invIdent G)) (inverseWellDefined G (transitive (symmetric identLeft) (+WellDefined reflexive (symmetric (powerZero m)))))
elementPowerMultiplies (negSucc m) (nonneg (succ n)) x = inverseWellDefined G (transitive (transitive (+WellDefined reflexive (transitive (elementPowerWellDefinedZ' G (nonneg ((m +N n *N m) +N n)) (nonneg (n +N m *N succ n)) (applyEquality nonneg (transitivity (Semiring.commutative ℕSemiring _ n) (applyEquality (n +N_) (multiplicationNIsCommutative _ m)))) {x}) (symmetric (positiveEltPowerCollapse G x n (m *N succ n))))) +Associative) (+WellDefined reflexive (positiveEltPowerMultiplies m (succ n) x)))
elementPowerMultiplies (negSucc m) (negSucc n) r = transitive (transitive (transitive (transitive (elementPowerWellDefinedZ' G (nonneg (succ m *N succ n)) (nonneg (m *N succ n +N succ n)) (applyEquality nonneg (Semiring.commutative ℕSemiring (succ n) _)) {r}) (symmetric (positiveEltPowerCollapse G r (m *N succ n) (succ n)))) (transitive (elementPowerCollapse r (nonneg (m *N succ n)) (nonneg (succ n))) (transitive (transitive (elementPowerWellDefinedZ' G (nonneg (m *N succ n) +Z nonneg (succ n)) (nonneg (m *N succ n +N succ n)) (equalityCommutative (+Zinherits (m *N succ n) (succ n))) {r}) (symmetric (positiveEltPowerCollapse G r (m *N succ n) (succ n)))) (+WellDefined (positiveEltPowerMultiplies m (succ n) r) reflexive)))) (+WellDefined (transitive (symmetric (invTwice G _)) (inverseWellDefined G (symmetric (positiveEltPowerInverse m (r + positiveEltPower G r n))))) (symmetric (invTwice G _)))) (symmetric (invContravariant G))
positiveEltPowerHomAbelian : ({x y : A} → (x + y) ∼ (y + x)) → (x y : A) → (r : ℕ) → (positiveEltPower G (x + y) r) ∼ (positiveEltPower G x r + positiveEltPower G y r)
positiveEltPowerHomAbelian ab x y zero = symmetric identRight
positiveEltPowerHomAbelian ab x y (succ r) = transitive (symmetric +Associative) (transitive (+WellDefined reflexive (transitive (+WellDefined reflexive (positiveEltPowerHomAbelian ab x y r)) (transitive (+WellDefined reflexive ab) (transitive +Associative ab)))) +Associative)
elementPowerHomAbelian : ({x y : A} → (x + y) ∼ (y + x)) → (x y : A) → (r : ℤ) → (elementPower G (x + y) r) ∼ (elementPower G x r + elementPower G y r)
elementPowerHomAbelian ab x y (nonneg n) = positiveEltPowerHomAbelian ab x y n
elementPowerHomAbelian ab x y (negSucc n) = transitive (transitive (inverseWellDefined G (positiveEltPowerHomAbelian ab x y (succ n))) (inverseWellDefined G ab)) (invContravariant G)
| 131.580645
| 940
| 0.75619
|
36fd86cda320dfbb18f88e2c488fec97d9a0d63d
| 1,707
|
agda
|
Agda
|
Cats/Category/Preorder/Facts/PreorderAsCategory.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Category/Preorder/Facts/PreorderAsCategory.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Category/Preorder/Facts/PreorderAsCategory.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 1
|
2019-03-18T15:35:07.000Z
|
2019-03-18T15:35:07.000Z
|
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Preorder.Facts.PreorderAsCategory where
open import Data.Bool using (true ; false)
open import Data.Product using (_×_ ; _,_ ; proj₁ ; proj₂)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
open import Relation.Binary using (Preorder)
import Level
open import Cats.Category
open import Cats.Category.Preorder using (preorderAsCategory)
module _ {lc l≈ l≤} (P : Preorder lc l≈ l≤) where
C : Category _ _ _
C = preorderAsCategory P
open module P = Preorder P using (_∼_) renaming (_≈_ to _≋_)
open Category C
_≈_⊔_ : Obj → Obj → Obj → Set l≤
lub ≈ x ⊔ y = x ∼ lub × y ∼ lub × (lub ∼ x ⊎ lub ∼ y)
_≈_⊓_ : Obj → Obj → Obj → Set l≤
glb ≈ x ⊓ y = glb ∼ x × glb ∼ y × (x ∼ glb ⊎ y ∼ glb)
IsMinimum : Obj → Set (lc Level.⊔ l≤)
IsMinimum m = ∀ x → m ∼ x
IsMaximum : Obj → Set (lc Level.⊔ l≤)
IsMaximum m = ∀ x → x ∼ m
initial : ∀ {x} → IsMinimum x → IsInitial x
initial min y = ∃!-intro (min y) _ _
terminal : ∀ {x} → IsMaximum x → IsTerminal x
terminal max y = ∃!-intro (max y) _ _
⊓-isBinaryProduct : ∀ {glb x y}
→ (pl : glb ∼ x)
→ (pr : glb ∼ y)
→ (x ∼ glb ⊎ y ∼ glb)
→ IsBinaryProduct glb pl pr
⊓-isBinaryProduct pl pr (inj₁ x∼glb) xl xr = ∃!-intro (x∼glb ∘ xl) _ _
⊓-isBinaryProduct pl pr (inj₂ y∼glb) xl xr = ∃!-intro (y∼glb ∘ xr) _ _
⊓-to-BinaryProduct : ∀ {glb x y} → glb ≈ x ⊓ y → BinaryProduct x y
⊓-to-BinaryProduct {glb} (pl , pr , maximal)
= mkBinaryProduct pl pr (⊓-isBinaryProduct pl pr maximal)
mono : ∀ {x y} (f : x ⇒ y) → IsMono f
mono = _
epi : ∀ {x y} (f : x ⇒ y) → IsEpi f
epi = _
unique : ∀ {x y} (f : x ⇒ y) → IsUnique f
unique = _
| 23.383562
| 72
| 0.582308
|
142959c56bdd92633f2463ff20ee39bc2ad8834d
| 13,198
|
agda
|
Agda
|
Cubical/Foundations/Univalence.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Foundations/Univalence.agda
|
seanwallawalla-forks/cubical
|
ccf7c01d6168a5e17c2aee89fd8f670585720b17
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Univalence.agda
|
seanwallawalla-forks/cubical
|
ccf7c01d6168a5e17c2aee89fd8f670585720b17
|
[
"MIT"
] | null | null | null |
{-
Proof of the standard formulation of the univalence theorem and
various consequences of univalence
- Re-exports Glue types from Cubical.Core.Glue
- The ua constant and its computation rule (up to a path)
- Proof of univalence using that unglue is an equivalence ([EquivContr])
- Equivalence induction ([EquivJ], [elimEquiv])
- Univalence theorem ([univalence])
- The computation rule for ua ([uaβ])
- Isomorphism induction ([elimIso])
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.Univalence where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma.Base
open import Cubical.Core.Glue public
using ( Glue ; glue ; unglue ; lineToEquiv )
open import Cubical.Reflection.StrictEquiv
private
variable
ℓ ℓ' : Level
-- The ua constant
ua : ∀ {A B : Type ℓ} → A ≃ B → A ≡ B
ua {A = A} {B = B} e i = Glue B (λ { (i = i0) → (A , e)
; (i = i1) → (B , idEquiv B) })
uaIdEquiv : {A : Type ℓ} → ua (idEquiv A) ≡ refl
uaIdEquiv {A = A} i j = Glue A {φ = i ∨ ~ j ∨ j} (λ _ → A , idEquiv A)
-- Propositional extensionality
hPropExt : {A B : Type ℓ} → isProp A → isProp B → (A → B) → (B → A) → A ≡ B
hPropExt Aprop Bprop f g = ua (propBiimpl→Equiv Aprop Bprop f g)
-- the unglue and glue primitives specialized to the case of ua
ua-unglue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : ua e i)
→ B {- [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → x }) ] -}
ua-unglue e i x = unglue (i ∨ ~ i) x
ua-glue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : Partial (~ i) A)
(y : B [ _ ↦ (λ { (i = i0) → e .fst (x 1=1) }) ])
→ ua e i {- [ _ ↦ (λ { (i = i0) → x 1=1 ; (i = i1) → outS y }) ] -}
ua-glue e i x y = glue {φ = i ∨ ~ i} (λ { (i = i0) → x 1=1 ; (i = i1) → outS y }) (outS y)
module _ {A B : Type ℓ} (e : A ≃ B) {x : A} {y : B} where
-- sometimes more useful are versions of these functions with the (i : I) factored in
ua-ungluePath : PathP (λ i → ua e i) x y → e .fst x ≡ y
ua-ungluePath p i = ua-unglue e i (p i)
ua-gluePath : e .fst x ≡ y → PathP (λ i → ua e i) x y
ua-gluePath p i = ua-glue e i (λ { (i = i0) → x }) (inS (p i))
-- ua-ungluePath and ua-gluePath are definitional inverses
ua-ungluePath-Equiv : (PathP (λ i → ua e i) x y) ≃ (e .fst x ≡ y)
unquoteDef ua-ungluePath-Equiv =
defStrictEquiv ua-ungluePath-Equiv ua-ungluePath ua-gluePath
-- ua-unglue and ua-glue are also definitional inverses, in a way
-- strengthening the types of ua-unglue and ua-glue gives a nicer formulation of this, see below
ua-unglue-glue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : Partial (~ i) A) (y : B [ _ ↦ _ ])
→ ua-unglue e i (ua-glue e i x y) ≡ outS y
ua-unglue-glue _ _ _ _ = refl
ua-glue-unglue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : ua e i)
→ ua-glue e i (λ { (i = i0) → x }) (inS (ua-unglue e i x)) ≡ x
ua-glue-unglue _ _ _ = refl
-- mainly for documentation purposes, ua-unglue and ua-glue wrapped in cubical subtypes
ua-unglueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
→ ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ]
→ B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ]
ua-unglueS e i x y s = inS (ua-unglue e i (outS s))
ua-glueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
→ B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ]
→ ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ]
ua-glueS e i x y s = inS (ua-glue e i (λ { (i = i0) → x }) (inS (outS s)))
ua-unglueS-glueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
(s : B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ])
→ outS (ua-unglueS e i x y (ua-glueS e i x y s)) ≡ outS s
ua-unglueS-glueS _ _ _ _ _ = refl
ua-glueS-unglueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
(s : ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ])
→ outS (ua-glueS e i x y (ua-unglueS e i x y s)) ≡ outS s
ua-glueS-unglueS _ _ _ _ _ = refl
-- a version of ua-glue with a single endpoint, identical to `ua-gluePath e {x} refl i`
ua-gluePt : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A)
→ ua e i {- [ _ ↦ (λ { (i = i0) → x ; (i = i1) → e .fst x }) ] -}
ua-gluePt e i x = ua-glue e i (λ { (i = i0) → x }) (inS (e .fst x))
-- Proof of univalence using that unglue is an equivalence:
-- unglue is an equivalence
unglueIsEquiv : ∀ (A : Type ℓ) (φ : I)
(f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) →
isEquiv {A = Glue A f} (unglue φ)
equiv-proof (unglueIsEquiv A φ f) = λ (b : A) →
let u : I → Partial φ A
u i = λ{ (φ = i1) → equivCtr (f 1=1 .snd) b .snd (~ i) }
ctr : fiber (unglue φ) b
ctr = ( glue (λ { (φ = i1) → equivCtr (f 1=1 .snd) b .fst }) (hcomp u b)
, λ j → hfill u (inS b) (~ j))
in ( ctr
, λ (v : fiber (unglue φ) b) i →
let u' : I → Partial (φ ∨ ~ i ∨ i) A
u' j = λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .snd (~ j)
; (i = i0) → hfill u (inS b) j
; (i = i1) → v .snd (~ j) }
in ( glue (λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .fst }) (hcomp u' b)
, λ j → hfill u' (inS b) (~ j)))
-- Any partial family of equivalences can be extended to a total one
-- from Glue [ φ ↦ (T,f) ] A to A
unglueEquiv : ∀ (A : Type ℓ) (φ : I)
(f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) →
(Glue A f) ≃ A
unglueEquiv A φ f = ( unglue φ , unglueIsEquiv A φ f )
-- The following is a formulation of univalence proposed by Martín Escardó:
-- https://groups.google.com/forum/#!msg/homotopytypetheory/HfCB_b-PNEU/Ibb48LvUMeUJ
-- See also Theorem 5.8.4 of the HoTT Book.
--
-- The reason we have this formulation in the core library and not the
-- standard one is that this one is more direct to prove using that
-- unglue is an equivalence. The standard formulation can be found in
-- Cubical/Basics/Univalence.
--
EquivContr : ∀ (A : Type ℓ) → ∃![ T ∈ Type ℓ ] (T ≃ A)
EquivContr {ℓ = ℓ} A =
( (A , idEquiv A)
, idEquiv≡ )
where
idEquiv≡ : (y : Σ (Type ℓ) (λ T → T ≃ A)) → (A , idEquiv A) ≡ y
idEquiv≡ w = \ { i .fst → Glue A (f i)
; i .snd .fst → unglueEquiv _ _ (f i) .fst
; i .snd .snd .equiv-proof → unglueEquiv _ _ (f i) .snd .equiv-proof
}
where
f : ∀ i → PartialP (~ i ∨ i) (λ x → Σ[ T ∈ Type ℓ ] T ≃ A)
f i = λ { (i = i0) → A , idEquiv A ; (i = i1) → w }
contrSinglEquiv : {A B : Type ℓ} (e : A ≃ B) → (B , idEquiv B) ≡ (A , e)
contrSinglEquiv {A = A} {B = B} e =
isContr→isProp (EquivContr B) (B , idEquiv B) (A , e)
-- Equivalence induction
EquivJ : {A B : Type ℓ} (P : (A : Type ℓ) → (e : A ≃ B) → Type ℓ')
→ (r : P B (idEquiv B)) → (e : A ≃ B) → P A e
EquivJ P r e = subst (λ x → P (x .fst) (x .snd)) (contrSinglEquiv e) r
-- Assuming that we have an inverse to ua we can easily prove univalence
module Univalence (au : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → A ≃ B)
(aurefl : ∀ {ℓ} {A B : Type ℓ} → au refl ≡ idEquiv A) where
ua-au : {A B : Type ℓ} (p : A ≡ B) → ua (au p) ≡ p
ua-au {B = B} = J (λ _ p → ua (au p) ≡ p)
(cong ua (aurefl {B = B}) ∙ uaIdEquiv)
au-ua : {A B : Type ℓ} (e : A ≃ B) → au (ua e) ≡ e
au-ua {B = B} = EquivJ (λ _ f → au (ua f) ≡ f)
(subst (λ r → au r ≡ idEquiv _) (sym uaIdEquiv) (aurefl {B = B}))
isoThm : ∀ {ℓ} {A B : Type ℓ} → Iso (A ≡ B) (A ≃ B)
isoThm .Iso.fun = au
isoThm .Iso.inv = ua
isoThm .Iso.rightInv = au-ua
isoThm .Iso.leftInv = ua-au
thm : ∀ {ℓ} {A B : Type ℓ} → isEquiv au
thm {A = A} {B = B} = isoToIsEquiv {B = A ≃ B} isoThm
pathToEquiv : {A B : Type ℓ} → A ≡ B → A ≃ B
pathToEquiv p = lineToEquiv (λ i → p i)
pathToEquivRefl : {A : Type ℓ} → pathToEquiv refl ≡ idEquiv A
pathToEquivRefl {A = A} = equivEq (λ i x → transp (λ _ → A) i x)
pathToEquiv-ua : {A B : Type ℓ} (e : A ≃ B) → pathToEquiv (ua e) ≡ e
pathToEquiv-ua = Univalence.au-ua pathToEquiv pathToEquivRefl
ua-pathToEquiv : {A B : Type ℓ} (p : A ≡ B) → ua (pathToEquiv p) ≡ p
ua-pathToEquiv = Univalence.ua-au pathToEquiv pathToEquivRefl
-- Univalence
univalenceIso : {A B : Type ℓ} → Iso (A ≡ B) (A ≃ B)
univalenceIso = Univalence.isoThm pathToEquiv pathToEquivRefl
univalence : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalence = ( pathToEquiv , Univalence.thm pathToEquiv pathToEquivRefl )
-- The original map from UniMath/Foundations
eqweqmap : {A B : Type ℓ} → A ≡ B → A ≃ B
eqweqmap {A = A} e = J (λ X _ → A ≃ X) (idEquiv A) e
eqweqmapid : {A : Type ℓ} → eqweqmap refl ≡ idEquiv A
eqweqmapid {A = A} = JRefl (λ X _ → A ≃ X) (idEquiv A)
univalenceStatement : {A B : Type ℓ} → isEquiv (eqweqmap {ℓ} {A} {B})
univalenceStatement = Univalence.thm eqweqmap eqweqmapid
univalenceUAH : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalenceUAH = ( _ , univalenceStatement )
univalencePath : {A B : Type ℓ} → (A ≡ B) ≡ Lift (A ≃ B)
univalencePath = ua (compEquiv univalence LiftEquiv)
-- The computation rule for ua. Because of "ghcomp" it is now very
-- simple compared to cubicaltt:
-- https://github.com/mortberg/cubicaltt/blob/master/examples/univalence.ctt#L202
uaβ : {A B : Type ℓ} (e : A ≃ B) (x : A) → transport (ua e) x ≡ equivFun e x
uaβ e x = transportRefl (equivFun e x)
uaη : ∀ {A B : Type ℓ} → (P : A ≡ B) → ua (pathToEquiv P) ≡ P
uaη = J (λ _ q → ua (pathToEquiv q) ≡ q) (cong ua pathToEquivRefl ∙ uaIdEquiv)
-- Lemmas for constructing and destructing dependent paths in a function type where the domain is ua.
ua→ : ∀ {ℓ ℓ'} {A₀ A₁ : Type ℓ} {e : A₀ ≃ A₁} {B : (i : I) → Type ℓ'}
{f₀ : A₀ → B i0} {f₁ : A₁ → B i1}
→ ((a : A₀) → PathP B (f₀ a) (f₁ (e .fst a)))
→ PathP (λ i → ua e i → B i) f₀ f₁
ua→ {e = e} {f₀ = f₀} {f₁} h i a =
hcomp
(λ j → λ
{ (i = i0) → f₀ a
; (i = i1) → f₁ (lem a j)
})
(h (transp (λ j → ua e (~ j ∧ i)) (~ i) a) i)
where
lem : ∀ a₁ → e .fst (transport (sym (ua e)) a₁) ≡ a₁
lem a₁ = secEq e _ ∙ transportRefl _
ua→⁻ : ∀ {ℓ ℓ'} {A₀ A₁ : Type ℓ} {e : A₀ ≃ A₁} {B : (i : I) → Type ℓ'}
{f₀ : A₀ → B i0} {f₁ : A₁ → B i1}
→ PathP (λ i → ua e i → B i) f₀ f₁
→ ((a : A₀) → PathP B (f₀ a) (f₁ (e .fst a)))
ua→⁻ {e = e} {f₀ = f₀} {f₁} p a i =
hcomp
(λ k → λ
{ (i = i0) → f₀ a
; (i = i1) → f₁ (uaβ e a k)
})
(p i (transp (λ j → ua e (j ∧ i)) (~ i) a))
ua→2 : ∀ {ℓ ℓ' ℓ''} {A₀ A₁ : Type ℓ} {e₁ : A₀ ≃ A₁}
{B₀ B₁ : Type ℓ'} {e₂ : B₀ ≃ B₁}
{C : (i : I) → Type ℓ''}
{f₀ : A₀ → B₀ → C i0} {f₁ : A₁ → B₁ → C i1}
→ (∀ a b → PathP C (f₀ a b) (f₁ (e₁ .fst a) (e₂ .fst b)))
→ PathP (λ i → ua e₁ i → ua e₂ i → C i) f₀ f₁
ua→2 h = ua→ (ua→ ∘ h)
-- Useful lemma for unfolding a transported function over ua
-- If we would have regularity this would be refl
transportUAop₁ : ∀ {A B : Type ℓ} → (e : A ≃ B) (f : A → A) (x : B)
→ transport (λ i → ua e i → ua e i) f x ≡ equivFun e (f (invEq e x))
transportUAop₁ e f x i = transportRefl (equivFun e (f (invEq e (transportRefl x i)))) i
-- Binary version
transportUAop₂ : ∀ {ℓ} {A B : Type ℓ} → (e : A ≃ B) (f : A → A → A) (x y : B)
→ transport (λ i → ua e i → ua e i → ua e i) f x y ≡
equivFun e (f (invEq e x) (invEq e y))
transportUAop₂ e f x y i =
transportRefl (equivFun e (f (invEq e (transportRefl x i))
(invEq e (transportRefl y i)))) i
-- Alternative version of EquivJ that only requires a predicate on functions
elimEquivFun : {A B : Type ℓ} (P : (A : Type ℓ) → (A → B) → Type ℓ')
→ (r : P B (idfun B)) → (e : A ≃ B) → P A (e .fst)
elimEquivFun P r e = subst (λ x → P (x .fst) (x .snd .fst)) (contrSinglEquiv e) r
-- Isomorphism induction
elimIso : {B : Type ℓ} → (Q : {A : Type ℓ} → (A → B) → (B → A) → Type ℓ') →
(h : Q (idfun B) (idfun B)) → {A : Type ℓ} →
(f : A → B) → (g : B → A) → section f g → retract f g → Q f g
elimIso {ℓ} {ℓ'} {B} Q h {A} f g sfg rfg = rem1 f g sfg rfg
where
P : (A : Type ℓ) → (f : A → B) → Type (ℓ-max ℓ' ℓ)
P A f = (g : B → A) → section f g → retract f g → Q f g
rem : P B (idfun B)
rem g sfg rfg = subst (Q (idfun B)) (λ i b → (sfg b) (~ i)) h
rem1 : {A : Type ℓ} → (f : A → B) → P A f
rem1 f g sfg rfg = elimEquivFun P rem (f , isoToIsEquiv (iso f g sfg rfg)) g sfg rfg
uaInvEquiv : ∀ {A B : Type ℓ} → (e : A ≃ B) → ua (invEquiv e) ≡ sym (ua e)
uaInvEquiv {B = B} = EquivJ (λ _ e → ua (invEquiv e) ≡ sym (ua e))
(cong ua (invEquivIdEquiv B))
uaCompEquiv : ∀ {A B C : Type ℓ} → (e : A ≃ B) (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f
uaCompEquiv {B = B} {C} = EquivJ (λ _ e → (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f)
(λ f → cong ua (compEquivIdEquiv f)
∙ sym (cong (λ x → x ∙ ua f) uaIdEquiv
∙ sym (lUnit (ua f))))
| 41.503145
| 101
| 0.522125
|
738d12e5cce3f7f297099bf4486a08514a9af6fa
| 25,776
|
agda
|
Agda
|
Agda/06-universes.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/06-universes.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/06-universes.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split --safe #-}
module 06-universes where
import 05-identity-types
open 05-identity-types public
--------------------------------------------------------------------------------
-- Section 6.3 Observational equality on the natural numbers
-- Definition 6.3.1
Eq-ℕ : ℕ → ℕ → UU lzero
Eq-ℕ zero-ℕ zero-ℕ = 𝟙
Eq-ℕ zero-ℕ (succ-ℕ n) = 𝟘
Eq-ℕ (succ-ℕ m) zero-ℕ = 𝟘
Eq-ℕ (succ-ℕ m) (succ-ℕ n) = Eq-ℕ m n
-- Lemma 6.3.2
refl-Eq-ℕ : (n : ℕ) → Eq-ℕ n n
refl-Eq-ℕ zero-ℕ = star
refl-Eq-ℕ (succ-ℕ n) = refl-Eq-ℕ n
-- Proposition 6.3.3
Eq-ℕ-eq : {x y : ℕ} → Id x y → Eq-ℕ x y
Eq-ℕ-eq {x} {.x} refl = refl-Eq-ℕ x
eq-Eq-ℕ : (x y : ℕ) → Eq-ℕ x y → Id x y
eq-Eq-ℕ zero-ℕ zero-ℕ e = refl
eq-Eq-ℕ (succ-ℕ x) (succ-ℕ y) e = ap succ-ℕ (eq-Eq-ℕ x y e)
--------------------------------------------------------------------------------
-- Section 6.4 Peano's seventh and eighth axioms
-- Theorem 6.4.1
is-injective-succ-ℕ : (x y : ℕ) → Id (succ-ℕ x) (succ-ℕ y) → Id x y
is-injective-succ-ℕ x y e = eq-Eq-ℕ x y (Eq-ℕ-eq e)
Peano-7 :
(x y : ℕ) →
((Id x y) → (Id (succ-ℕ x) (succ-ℕ y))) ×
((Id (succ-ℕ x) (succ-ℕ y)) → (Id x y))
Peano-7 x y = pair (ap succ-ℕ) (is-injective-succ-ℕ x y)
-- Theorem 6.4.2
Peano-8 :
(x : ℕ) → ¬ (Id zero-ℕ (succ-ℕ x))
Peano-8 x p = Eq-ℕ-eq p
--------------------------------------------------------------------------------
-- Exercises
-- Exercise 6.1
-- Exercise 6.1 (a)
is-injective-add-ℕ :
(k m n : ℕ) → Id (add-ℕ m k) (add-ℕ n k) → Id m n
is-injective-add-ℕ zero-ℕ m n = id
is-injective-add-ℕ (succ-ℕ k) m n p =
is-injective-add-ℕ k m n (is-injective-succ-ℕ (add-ℕ m k) (add-ℕ n k) p)
-- Exercise 6.1 (b)
is-injective-mul-ℕ :
(k m n : ℕ) → Id (mul-ℕ m (succ-ℕ k)) (mul-ℕ n (succ-ℕ k)) → Id m n
is-injective-mul-ℕ k zero-ℕ zero-ℕ p = refl
is-injective-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
ap succ-ℕ
( is-injective-mul-ℕ k m n
( is-injective-add-ℕ
( succ-ℕ k)
( mul-ℕ m (succ-ℕ k))
( mul-ℕ n (succ-ℕ k))
( ( inv (left-successor-law-mul-ℕ m (succ-ℕ k))) ∙
( ( p) ∙
( left-successor-law-mul-ℕ n (succ-ℕ k))))))
-- Exercise 6.1 (c)
neq-add-ℕ :
(m n : ℕ) → ¬ (Id m (add-ℕ m (succ-ℕ n)))
neq-add-ℕ (succ-ℕ m) n p =
neq-add-ℕ m n
( ( is-injective-succ-ℕ m (add-ℕ (succ-ℕ m) n) p) ∙
( left-successor-law-add-ℕ m n))
-- Exercise 6.1 (d)
neq-mul-ℕ :
(m n : ℕ) → ¬ (Id (succ-ℕ m) (mul-ℕ (succ-ℕ m) (succ-ℕ (succ-ℕ n))))
neq-mul-ℕ m n p =
neq-add-ℕ
( succ-ℕ m)
( add-ℕ (mul-ℕ m (succ-ℕ n)) n)
( ( p) ∙
( ( right-successor-law-mul-ℕ (succ-ℕ m) (succ-ℕ n)) ∙
( ap (add-ℕ (succ-ℕ m)) (left-successor-law-mul-ℕ m (succ-ℕ n)))))
-- Exercise 6.2
-- Exercise 6.2 (a)
Eq-𝟚 : bool → bool → UU lzero
Eq-𝟚 true true = unit
Eq-𝟚 true false = empty
Eq-𝟚 false true = empty
Eq-𝟚 false false = unit
-- Exercise 6.2 (b)
reflexive-Eq-𝟚 : (x : bool) → Eq-𝟚 x x
reflexive-Eq-𝟚 true = star
reflexive-Eq-𝟚 false = star
Eq-eq-𝟚 :
{x y : bool} → Id x y → Eq-𝟚 x y
Eq-eq-𝟚 {x = x} refl = reflexive-Eq-𝟚 x
eq-Eq-𝟚 :
{x y : bool} → Eq-𝟚 x y → Id x y
eq-Eq-𝟚 {true} {true} star = refl
eq-Eq-𝟚 {false} {false} star = refl
-- Exercise 6.2 (c)
neq-neg-𝟚 : (b : bool) → ¬ (Id b (neg-𝟚 b))
neq-neg-𝟚 true = Eq-eq-𝟚
neq-neg-𝟚 false = Eq-eq-𝟚
neq-false-true-𝟚 :
¬ (Id false true)
neq-false-true-𝟚 = Eq-eq-𝟚
-- Exercise 6.3
-- Exercise 6.3 (a)
leq-ℕ : ℕ → ℕ → UU lzero
leq-ℕ zero-ℕ m = unit
leq-ℕ (succ-ℕ n) zero-ℕ = empty
leq-ℕ (succ-ℕ n) (succ-ℕ m) = leq-ℕ n m
_≤_ = leq-ℕ
-- Some trivialities that will be useful later
leq-zero-ℕ :
(n : ℕ) → leq-ℕ zero-ℕ n
leq-zero-ℕ n = star
eq-leq-zero-ℕ :
(x : ℕ) → leq-ℕ x zero-ℕ → Id zero-ℕ x
eq-leq-zero-ℕ zero-ℕ star = refl
succ-leq-ℕ : (n : ℕ) → leq-ℕ n (succ-ℕ n)
succ-leq-ℕ zero-ℕ = star
succ-leq-ℕ (succ-ℕ n) = succ-leq-ℕ n
concatenate-eq-leq-eq-ℕ :
{x1 x2 x3 x4 : ℕ} → Id x1 x2 → leq-ℕ x2 x3 → Id x3 x4 → leq-ℕ x1 x4
concatenate-eq-leq-eq-ℕ refl H refl = H
concatenate-leq-eq-ℕ :
(m : ℕ) {n n' : ℕ} → leq-ℕ m n → Id n n' → leq-ℕ m n'
concatenate-leq-eq-ℕ m H refl = H
concatenate-eq-leq-ℕ :
{m m' : ℕ} (n : ℕ) → Id m' m → leq-ℕ m n → leq-ℕ m' n
concatenate-eq-leq-ℕ n refl H = H
-- Exercise 6.3 (b)
reflexive-leq-ℕ : (n : ℕ) → leq-ℕ n n
reflexive-leq-ℕ zero-ℕ = star
reflexive-leq-ℕ (succ-ℕ n) = reflexive-leq-ℕ n
leq-eq-ℕ : (m n : ℕ) → Id m n → leq-ℕ m n
leq-eq-ℕ m .m refl = reflexive-leq-ℕ m
transitive-leq-ℕ :
(n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l)
transitive-leq-ℕ zero-ℕ m l p q = star
transitive-leq-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-leq-ℕ n m l p q
preserves-leq-succ-ℕ :
(m n : ℕ) → leq-ℕ m n → leq-ℕ m (succ-ℕ n)
preserves-leq-succ-ℕ m n p = transitive-leq-ℕ m n (succ-ℕ n) p (succ-leq-ℕ n)
anti-symmetric-leq-ℕ : (m n : ℕ) → leq-ℕ m n → leq-ℕ n m → Id m n
anti-symmetric-leq-ℕ zero-ℕ zero-ℕ p q = refl
anti-symmetric-leq-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-leq-ℕ m n p q)
-- Exercise 6.3 (c)
decide-leq-ℕ :
(m n : ℕ) → coprod (leq-ℕ m n) (leq-ℕ n m)
decide-leq-ℕ zero-ℕ zero-ℕ = inl star
decide-leq-ℕ zero-ℕ (succ-ℕ n) = inl star
decide-leq-ℕ (succ-ℕ m) zero-ℕ = inr star
decide-leq-ℕ (succ-ℕ m) (succ-ℕ n) = decide-leq-ℕ m n
-- Exercise 6.3 (d)
preserves-order-add-ℕ :
(k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k)
preserves-order-add-ℕ zero-ℕ m n = id
preserves-order-add-ℕ (succ-ℕ k) m n = preserves-order-add-ℕ k m n
reflects-order-add-ℕ :
(k m n : ℕ) → leq-ℕ (add-ℕ m k) (add-ℕ n k) → leq-ℕ m n
reflects-order-add-ℕ zero-ℕ m n = id
reflects-order-add-ℕ (succ-ℕ k) m n = reflects-order-add-ℕ k m n
-- Exercise 6.3 (e)
preserves-order-mul-ℕ :
(k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k)
preserves-order-mul-ℕ k zero-ℕ n p = star
preserves-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
preserves-order-add-ℕ k
( mul-ℕ m k)
( mul-ℕ n k)
( preserves-order-mul-ℕ k m n p)
reflects-order-mul-ℕ :
(k m n : ℕ) → leq-ℕ (mul-ℕ m (succ-ℕ k)) (mul-ℕ n (succ-ℕ k)) → leq-ℕ m n
reflects-order-mul-ℕ k zero-ℕ n p = star
reflects-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
reflects-order-mul-ℕ k m n
( reflects-order-add-ℕ
( succ-ℕ k)
( mul-ℕ m (succ-ℕ k))
( mul-ℕ n (succ-ℕ k))
( p))
-- Exercise 6.3 (f)
leq-min-ℕ :
(k m n : ℕ) → leq-ℕ k m → leq-ℕ k n → leq-ℕ k (min-ℕ m n)
leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star
leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H K = star
leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H K = star
leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H K = star
leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-min-ℕ k m n H K
leq-left-leq-min-ℕ :
(k m n : ℕ) → leq-ℕ k (min-ℕ m n) → leq-ℕ k m
leq-left-leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H = star
leq-left-leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H = star
leq-left-leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H = star
leq-left-leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H = star
leq-left-leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-left-leq-min-ℕ k m n H
leq-right-leq-min-ℕ :
(k m n : ℕ) → leq-ℕ k (min-ℕ m n) → leq-ℕ k n
leq-right-leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H = star
leq-right-leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H = star
leq-right-leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H = star
leq-right-leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H = star
leq-right-leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-right-leq-min-ℕ k m n H
leq-max-ℕ :
(k m n : ℕ) → leq-ℕ m k → leq-ℕ n k → leq-ℕ (max-ℕ m n) k
leq-max-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star
leq-max-ℕ (succ-ℕ k) zero-ℕ zero-ℕ H K = star
leq-max-ℕ (succ-ℕ k) zero-ℕ (succ-ℕ n) H K = K
leq-max-ℕ (succ-ℕ k) (succ-ℕ m) zero-ℕ H K = H
leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-max-ℕ k m n H K
leq-left-leq-max-ℕ :
(k m n : ℕ) → leq-ℕ (max-ℕ m n) k → leq-ℕ m k
leq-left-leq-max-ℕ k zero-ℕ zero-ℕ H = star
leq-left-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = star
leq-left-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = H
leq-left-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-left-leq-max-ℕ k m n H
leq-right-leq-max-ℕ :
(k m n : ℕ) → leq-ℕ (max-ℕ m n) k → leq-ℕ n k
leq-right-leq-max-ℕ k zero-ℕ zero-ℕ H = star
leq-right-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = H
leq-right-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = star
leq-right-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-right-leq-max-ℕ k m n H
-- Exercise 6.4
-- Exercise 6.4 (a)
-- We define a distance function on ℕ --
dist-ℕ : ℕ → ℕ → ℕ
dist-ℕ zero-ℕ n = n
dist-ℕ (succ-ℕ m) zero-ℕ = succ-ℕ m
dist-ℕ (succ-ℕ m) (succ-ℕ n) = dist-ℕ m n
dist-ℕ' : ℕ → ℕ → ℕ
dist-ℕ' m n = dist-ℕ n m
ap-dist-ℕ :
{m n m' n' : ℕ} → Id m m' → Id n n' → Id (dist-ℕ m n) (dist-ℕ m' n')
ap-dist-ℕ refl refl = refl
{- We show that two natural numbers are equal if and only if their distance is
zero. -}
eq-dist-ℕ :
(m n : ℕ) → Id zero-ℕ (dist-ℕ m n) → Id m n
eq-dist-ℕ zero-ℕ zero-ℕ p = refl
eq-dist-ℕ (succ-ℕ m) (succ-ℕ n) p = ap succ-ℕ (eq-dist-ℕ m n p)
dist-eq-ℕ' :
(n : ℕ) → Id zero-ℕ (dist-ℕ n n)
dist-eq-ℕ' zero-ℕ = refl
dist-eq-ℕ' (succ-ℕ n) = dist-eq-ℕ' n
dist-eq-ℕ :
(m n : ℕ) → Id m n → Id zero-ℕ (dist-ℕ m n)
dist-eq-ℕ m .m refl = dist-eq-ℕ' m
-- The distance function is symmetric --
symmetric-dist-ℕ :
(m n : ℕ) → Id (dist-ℕ m n) (dist-ℕ n m)
symmetric-dist-ℕ zero-ℕ zero-ℕ = refl
symmetric-dist-ℕ zero-ℕ (succ-ℕ n) = refl
symmetric-dist-ℕ (succ-ℕ m) zero-ℕ = refl
symmetric-dist-ℕ (succ-ℕ m) (succ-ℕ n) = symmetric-dist-ℕ m n
-- We compute the distance from zero --
left-zero-law-dist-ℕ :
(n : ℕ) → Id (dist-ℕ zero-ℕ n) n
left-zero-law-dist-ℕ zero-ℕ = refl
left-zero-law-dist-ℕ (succ-ℕ n) = refl
right-zero-law-dist-ℕ :
(n : ℕ) → Id (dist-ℕ n zero-ℕ) n
right-zero-law-dist-ℕ zero-ℕ = refl
right-zero-law-dist-ℕ (succ-ℕ n) = refl
-- We prove the triangle inequality --
ap-add-ℕ :
{m n m' n' : ℕ} → Id m m' → Id n n' → Id (add-ℕ m n) (add-ℕ m' n')
ap-add-ℕ refl refl = refl
triangle-inequality-dist-ℕ :
(m n k : ℕ) → leq-ℕ (dist-ℕ m n) (add-ℕ (dist-ℕ m k) (dist-ℕ k n))
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = star
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = star
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ =
tr ( leq-ℕ (succ-ℕ n))
( inv (left-unit-law-add-ℕ (succ-ℕ n)))
( reflexive-leq-ℕ (succ-ℕ n))
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (left-zero-law-dist-ℕ n)))
( triangle-inequality-dist-ℕ zero-ℕ n k)
( ( ap (succ-ℕ ∘ (add-ℕ' (dist-ℕ k n))) (left-zero-law-dist-ℕ k)) ∙
( inv (left-successor-law-add-ℕ k (dist-ℕ k n))))
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = reflexive-leq-ℕ (succ-ℕ m)
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (right-zero-law-dist-ℕ m)))
( triangle-inequality-dist-ℕ m zero-ℕ k)
( ap (succ-ℕ ∘ (add-ℕ (dist-ℕ m k))) (right-zero-law-dist-ℕ k))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ =
concatenate-leq-eq-ℕ
( dist-ℕ m n)
( transitive-leq-ℕ
( dist-ℕ m n)
( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))
( succ-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))
( transitive-leq-ℕ
( dist-ℕ m n)
( add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))
( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))
( triangle-inequality-dist-ℕ m n zero-ℕ)
( succ-leq-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))
( succ-leq-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))))
( ( ap (succ-ℕ ∘ succ-ℕ)
( ap-add-ℕ (right-zero-law-dist-ℕ m) (left-zero-law-dist-ℕ n))) ∙
( inv (left-successor-law-add-ℕ m (succ-ℕ n))))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
triangle-inequality-dist-ℕ m n k
-- We show that dist-ℕ x y is a solution to a simple equation.
leq-dist-ℕ :
(x y : ℕ) → leq-ℕ x y → Id (add-ℕ x (dist-ℕ x y)) y
leq-dist-ℕ zero-ℕ zero-ℕ H = refl
leq-dist-ℕ zero-ℕ (succ-ℕ y) star = left-unit-law-add-ℕ (succ-ℕ y)
leq-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
( left-successor-law-add-ℕ x (dist-ℕ x y)) ∙
( ap succ-ℕ (leq-dist-ℕ x y H))
rewrite-left-add-dist-ℕ :
(x y z : ℕ) → Id (add-ℕ x y) z → Id x (dist-ℕ y z)
rewrite-left-add-dist-ℕ zero-ℕ zero-ℕ .zero-ℕ refl = refl
rewrite-left-add-dist-ℕ zero-ℕ (succ-ℕ y) .(succ-ℕ (add-ℕ zero-ℕ y)) refl =
( dist-eq-ℕ' y) ∙
( inv (ap (dist-ℕ (succ-ℕ y)) (left-unit-law-add-ℕ (succ-ℕ y))))
rewrite-left-add-dist-ℕ (succ-ℕ x) zero-ℕ .(succ-ℕ x) refl = refl
rewrite-left-add-dist-ℕ
(succ-ℕ x) (succ-ℕ y) .(succ-ℕ (add-ℕ (succ-ℕ x) y)) refl =
rewrite-left-add-dist-ℕ (succ-ℕ x) y (add-ℕ (succ-ℕ x) y) refl
rewrite-left-dist-add-ℕ :
(x y z : ℕ) → leq-ℕ y z → Id x (dist-ℕ y z) → Id (add-ℕ x y) z
rewrite-left-dist-add-ℕ .(dist-ℕ y z) y z H refl =
( commutative-add-ℕ (dist-ℕ y z) y) ∙
( leq-dist-ℕ y z H)
rewrite-right-add-dist-ℕ :
(x y z : ℕ) → Id (add-ℕ x y) z → Id y (dist-ℕ x z)
rewrite-right-add-dist-ℕ x y z p =
rewrite-left-add-dist-ℕ y x z (commutative-add-ℕ y x ∙ p)
rewrite-right-dist-add-ℕ :
(x y z : ℕ) → leq-ℕ x z → Id y (dist-ℕ x z) → Id (add-ℕ x y) z
rewrite-right-dist-add-ℕ x .(dist-ℕ x z) z H refl =
leq-dist-ℕ x z H
-- We show that dist-ℕ is translation invariant
translation-invariant-dist-ℕ :
(k m n : ℕ) → Id (dist-ℕ (add-ℕ k m) (add-ℕ k n)) (dist-ℕ m n)
translation-invariant-dist-ℕ zero-ℕ m n =
ap-dist-ℕ (left-unit-law-add-ℕ m) (left-unit-law-add-ℕ n)
translation-invariant-dist-ℕ (succ-ℕ k) m n =
( ap-dist-ℕ (left-successor-law-add-ℕ k m) (left-successor-law-add-ℕ k n)) ∙
( translation-invariant-dist-ℕ k m n)
-- We show that dist-ℕ is linear with respect to scalar multiplication
linear-dist-ℕ :
(m n k : ℕ) → Id (dist-ℕ (mul-ℕ k m) (mul-ℕ k n)) (mul-ℕ k (dist-ℕ m n))
linear-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = refl
linear-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = linear-dist-ℕ zero-ℕ zero-ℕ k
linear-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ = refl
linear-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
ap (dist-ℕ' (mul-ℕ (succ-ℕ k) (succ-ℕ n))) (right-zero-law-mul-ℕ (succ-ℕ k))
linear-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = refl
linear-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
ap (dist-ℕ (mul-ℕ (succ-ℕ k) (succ-ℕ m))) (right-zero-law-mul-ℕ (succ-ℕ k))
linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ = refl
linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
( ap-dist-ℕ
( right-successor-law-mul-ℕ (succ-ℕ k) m)
( right-successor-law-mul-ℕ (succ-ℕ k) n)) ∙
( ( translation-invariant-dist-ℕ
( succ-ℕ k)
( mul-ℕ (succ-ℕ k) m)
( mul-ℕ (succ-ℕ k) n)) ∙
( linear-dist-ℕ m n (succ-ℕ k)))
-- Exercise 6.6
{- In this exercise we were asked to define the relations ≤ and < on the
integers. As a criterion of correctness, we were then also asked to show
that the type of all integers l satisfying k ≤ l satisfy the induction
principle of the natural numbers. -}
diff-ℤ : ℤ → ℤ → ℤ
diff-ℤ k l = add-ℤ (neg-ℤ k) l
is-non-negative-ℤ : ℤ → UU lzero
is-non-negative-ℤ (inl x) = empty
is-non-negative-ℤ (inr k) = unit
leq-ℤ : ℤ → ℤ → UU lzero
leq-ℤ k l = is-non-negative-ℤ (diff-ℤ k l)
reflexive-leq-ℤ : (k : ℤ) → leq-ℤ k k
reflexive-leq-ℤ k =
tr is-non-negative-ℤ (inv (left-inverse-law-add-ℤ k)) star
is-non-negative-succ-ℤ :
(k : ℤ) → is-non-negative-ℤ k → is-non-negative-ℤ (succ-ℤ k)
is-non-negative-succ-ℤ (inr (inl star)) p = star
is-non-negative-succ-ℤ (inr (inr x)) p = star
is-non-negative-add-ℤ :
(k l : ℤ) →
is-non-negative-ℤ k → is-non-negative-ℤ l → is-non-negative-ℤ (add-ℤ k l)
is-non-negative-add-ℤ (inr (inl star)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inl star)) (inr (inr n)) p q = star
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inl star)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inl star)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inl star)) star star)
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inr m)) star star = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inr m)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inr m)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inr m)) star star)
triangle-diff-ℤ :
(k l m : ℤ) → Id (add-ℤ (diff-ℤ k l) (diff-ℤ l m)) (diff-ℤ k m)
triangle-diff-ℤ k l m =
( associative-add-ℤ (neg-ℤ k) l (diff-ℤ l m)) ∙
( ap
( add-ℤ (neg-ℤ k))
( ( inv (associative-add-ℤ l (neg-ℤ l) m)) ∙
( ( ap (λ x → add-ℤ x m) (right-inverse-law-add-ℤ l)) ∙
( left-unit-law-add-ℤ m))))
transitive-leq-ℤ : (k l m : ℤ) → leq-ℤ k l → leq-ℤ l m → leq-ℤ k m
transitive-leq-ℤ k l m p q =
tr is-non-negative-ℤ
( triangle-diff-ℤ k l m)
( is-non-negative-add-ℤ
( add-ℤ (neg-ℤ k) l)
( add-ℤ (neg-ℤ l) m)
( p)
( q))
succ-leq-ℤ : (k : ℤ) → leq-ℤ k (succ-ℤ k)
succ-leq-ℤ k =
tr is-non-negative-ℤ
( inv
( ( right-successor-law-add-ℤ (neg-ℤ k) k) ∙
( ap succ-ℤ (left-inverse-law-add-ℤ k))))
( star)
leq-ℤ-succ-leq-ℤ : (k l : ℤ) → leq-ℤ k l → leq-ℤ k (succ-ℤ l)
leq-ℤ-succ-leq-ℤ k l p = transitive-leq-ℤ k l (succ-ℤ l) p (succ-leq-ℤ l)
is-positive-ℤ : ℤ → UU lzero
is-positive-ℤ k = is-non-negative-ℤ (pred-ℤ k)
le-ℤ : ℤ → ℤ → UU lzero
le-ℤ (inl zero-ℕ) (inl x) = empty
le-ℤ (inl zero-ℕ) (inr y) = unit
le-ℤ (inl (succ-ℕ x)) (inl zero-ℕ) = unit
le-ℤ (inl (succ-ℕ x)) (inl (succ-ℕ y)) = le-ℤ (inl x) (inl y)
le-ℤ (inl (succ-ℕ x)) (inr y) = unit
le-ℤ (inr x) (inl y) = empty
le-ℤ (inr (inl star)) (inr (inl star)) = empty
le-ℤ (inr (inl star)) (inr (inr x)) = unit
le-ℤ (inr (inr x)) (inr (inl star)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr (succ-ℕ y))) = unit
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr (succ-ℕ y))) =
le-ℤ (inr (inr x)) (inr (inr y))
-- Extra material
-- We show that ℕ is an ordered semi-ring
left-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k)
left-law-leq-add-ℕ zero-ℕ m n = id
left-law-leq-add-ℕ (succ-ℕ k) m n H = left-law-leq-add-ℕ k m n H
right-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ k m) (add-ℕ k n)
right-law-leq-add-ℕ k m n H =
concatenate-eq-leq-eq-ℕ
( commutative-add-ℕ k m)
( left-law-leq-add-ℕ k m n H)
( commutative-add-ℕ n k)
preserves-leq-add-ℕ :
{m m' n n' : ℕ} → leq-ℕ m m' → leq-ℕ n n' → leq-ℕ (add-ℕ m n) (add-ℕ m' n')
preserves-leq-add-ℕ {m} {m'} {n} {n'} H K =
transitive-leq-ℕ
( add-ℕ m n)
( add-ℕ m' n)
( add-ℕ m' n')
( left-law-leq-add-ℕ n m m' H)
( right-law-leq-add-ℕ m' n n' K)
{-
right-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ k m) (mul-ℕ k n)
right-law-leq-mul-ℕ zero-ℕ m n H = star
right-law-leq-mul-ℕ (succ-ℕ k) m n H = {!!}
-}
{-
preserves-leq-add-ℕ
{ m = mul-ℕ k m}
{ m' = mul-ℕ k n}
( right-law-leq-mul-ℕ k m n H) H
left-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k)
left-law-leq-mul-ℕ k m n H =
concatenate-eq-leq-eq-ℕ
( commutative-mul-ℕ k m)
( commutative-mul-ℕ k n)
( right-law-leq-mul-ℕ k m n H)
-}
-- We show that ℤ is an ordered ring
{-
leq-add-ℤ : (m k l : ℤ) → leq-ℤ k l → leq-ℤ (add-ℤ m k) (add-ℤ m l)
leq-add-ℤ (inl zero-ℕ) k l H = {!!}
leq-add-ℤ (inl (succ-ℕ x)) k l H = {!!}
leq-add-ℤ (inr m) k l H = {!!}
-}
-- Section 5.5 Identity systems
succ-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) →
(m n : ℕ) → Eq-ℕ m n → UU i
succ-fam-Eq-ℕ R m n e = R (succ-ℕ m) (succ-ℕ n) e
succ-refl-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
(ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
(n : ℕ) → (succ-fam-Eq-ℕ R n n (refl-Eq-ℕ n))
succ-refl-fam-Eq-ℕ R ρ n = ρ (succ-ℕ n)
path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( m n : ℕ) (e : Eq-ℕ m n) → R m n e
path-ind-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
path-ind-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
path-ind-Eq-ℕ
( λ m n e → R (succ-ℕ m) (succ-ℕ n) e)
( λ n → ρ (succ-ℕ n)) m n e
comp-path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( n : ℕ) → Id (path-ind-Eq-ℕ R ρ n n (refl-Eq-ℕ n)) (ρ n)
comp-path-ind-Eq-ℕ R ρ zero-ℕ = refl
comp-path-ind-Eq-ℕ R ρ (succ-ℕ n) =
comp-path-ind-Eq-ℕ
( λ m n e → R (succ-ℕ m) (succ-ℕ n) e)
( λ n → ρ (succ-ℕ n)) n
{-
-- Graphs
Gph : (i : Level) → UU (lsuc i)
Gph i = Σ (UU i) (λ X → (X → X → (UU i)))
-- Reflexive graphs
rGph : (i : Level) → UU (lsuc i)
rGph i = Σ (UU i) (λ X → Σ (X → X → (UU i)) (λ R → (x : X) → R x x))
-}
-- Exercise 3.7
{- With the construction of the divisibility relation we open the door to basic
number theory. -}
divides : (d n : ℕ) → UU lzero
divides d n = Σ ℕ (λ m → Eq-ℕ (mul-ℕ d m) n)
-- We prove some lemmas about inequalities --
leq-add-ℕ :
(m n : ℕ) → leq-ℕ m (add-ℕ m n)
leq-add-ℕ m zero-ℕ = reflexive-leq-ℕ m
leq-add-ℕ m (succ-ℕ n) =
transitive-leq-ℕ m (add-ℕ m n) (succ-ℕ (add-ℕ m n))
( leq-add-ℕ m n)
( succ-leq-ℕ (add-ℕ m n))
leq-add-ℕ' :
(m n : ℕ) → leq-ℕ m (add-ℕ n m)
leq-add-ℕ' m n =
concatenate-leq-eq-ℕ m (leq-add-ℕ m n) (commutative-add-ℕ m n)
leq-leq-add-ℕ :
(m n x : ℕ) → leq-ℕ (add-ℕ m x) (add-ℕ n x) → leq-ℕ m n
leq-leq-add-ℕ m n zero-ℕ H = H
leq-leq-add-ℕ m n (succ-ℕ x) H = leq-leq-add-ℕ m n x H
leq-leq-add-ℕ' :
(m n x : ℕ) → leq-ℕ (add-ℕ x m) (add-ℕ x n) → leq-ℕ m n
leq-leq-add-ℕ' m n x H =
leq-leq-add-ℕ m n x
( concatenate-eq-leq-eq-ℕ
( commutative-add-ℕ m x)
( H)
( commutative-add-ℕ x n))
leq-leq-mul-ℕ :
(m n x : ℕ) → leq-ℕ (mul-ℕ (succ-ℕ x) m) (mul-ℕ (succ-ℕ x) n) → leq-ℕ m n
leq-leq-mul-ℕ zero-ℕ zero-ℕ x H = star
leq-leq-mul-ℕ zero-ℕ (succ-ℕ n) x H = star
leq-leq-mul-ℕ (succ-ℕ m) zero-ℕ x H =
ex-falso
( concatenate-leq-eq-ℕ
( mul-ℕ (succ-ℕ x) (succ-ℕ m))
( H)
( right-zero-law-mul-ℕ (succ-ℕ x)))
leq-leq-mul-ℕ (succ-ℕ m) (succ-ℕ n) x H =
leq-leq-mul-ℕ m n x
( leq-leq-add-ℕ' (mul-ℕ (succ-ℕ x) m) (mul-ℕ (succ-ℕ x) n) (succ-ℕ x)
( concatenate-eq-leq-eq-ℕ
( inv (right-successor-law-mul-ℕ (succ-ℕ x) m))
( H)
( right-successor-law-mul-ℕ (succ-ℕ x) n)))
leq-leq-mul-ℕ' :
(m n x : ℕ) → leq-ℕ (mul-ℕ m (succ-ℕ x)) (mul-ℕ n (succ-ℕ x)) → leq-ℕ m n
leq-leq-mul-ℕ' m n x H =
leq-leq-mul-ℕ m n x
( concatenate-eq-leq-eq-ℕ
( commutative-mul-ℕ (succ-ℕ x) m)
( H)
( commutative-mul-ℕ n (succ-ℕ x)))
{-
succ-relation-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) → ℕ → ℕ → UU i
succ-relation-ℕ R m n = R (succ-ℕ m) (succ-ℕ n)
succ-reflexivity-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(n : ℕ) → succ-relation-ℕ R n n
succ-reflexivity-ℕ R ρ n = ρ (succ-ℕ n)
{- In the book we suggest that first the order of the variables should be
swapped, in order to make the inductive hypothesis stronger. Agda's pattern
matching mechanism allows us to bypass this step and give a more direct
construction. -}
least-reflexive-Eq-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(m n : ℕ) → Eq-ℕ m n → R m n
least-reflexive-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
least-reflexive-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
least-reflexive-Eq-ℕ (succ-relation-ℕ R) (succ-reflexivity-ℕ R ρ) m n e
-}
-- The definition of <
le-ℕ : ℕ → ℕ → UU lzero
le-ℕ m zero-ℕ = empty
le-ℕ zero-ℕ (succ-ℕ m) = unit
le-ℕ (succ-ℕ n) (succ-ℕ m) = le-ℕ n m
_<_ = le-ℕ
anti-reflexive-le-ℕ : (n : ℕ) → ¬ (n < n)
anti-reflexive-le-ℕ zero-ℕ = ind-empty
anti-reflexive-le-ℕ (succ-ℕ n) = anti-reflexive-le-ℕ n
transitive-le-ℕ : (n m l : ℕ) → (le-ℕ n m) → (le-ℕ m l) → (le-ℕ n l)
transitive-le-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ l) p q = star
transitive-le-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-le-ℕ n m l p q
succ-le-ℕ : (n : ℕ) → le-ℕ n (succ-ℕ n)
succ-le-ℕ zero-ℕ = star
succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n
anti-symmetric-le-ℕ : (m n : ℕ) → le-ℕ m n → le-ℕ n m → Id m n
anti-symmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-le-ℕ m n p q)
{-
--------------------------------------------------------------------------------
data Fin-Tree : UU lzero where
constr : (n : ℕ) → (Fin n → Fin-Tree) → Fin-Tree
root-Fin-Tree : Fin-Tree
root-Fin-Tree = constr zero-ℕ ex-falso
succ-Fin-Tree : Fin-Tree → Fin-Tree
succ-Fin-Tree t = constr one-ℕ (λ i → t)
map-assoc-coprod :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {C : UU l3} →
coprod (coprod A B) C → coprod A (coprod B C)
map-assoc-coprod (inl (inl x)) = inl x
map-assoc-coprod (inl (inr x)) = inr (inl x)
map-assoc-coprod (inr x) = inr (inr x)
map-coprod-Fin :
(m n : ℕ) → Fin (add-ℕ m n) → coprod (Fin m) (Fin n)
map-coprod-Fin m zero-ℕ = inl
map-coprod-Fin m (succ-ℕ n) =
map-assoc-coprod ∘ (functor-coprod (map-coprod-Fin m n) (id {A = unit}))
add-Fin-Tree : Fin-Tree → Fin-Tree → Fin-Tree
add-Fin-Tree (constr n x) (constr m y) =
constr (add-ℕ n m) ((ind-coprod (λ i → Fin-Tree) x y) ∘ (map-coprod-Fin n m))
--------------------------------------------------------------------------------
data labeled-Bin-Tree {l1 : Level} (A : UU l1) : UU l1 where
leaf : A → labeled-Bin-Tree A
constr : (bool → labeled-Bin-Tree A) → labeled-Bin-Tree A
mul-leaves-labeled-Bin-Tree :
{l1 : Level} {A : UU l1} (μ : A → (A → A)) →
labeled-Bin-Tree A → A
mul-leaves-labeled-Bin-Tree μ (leaf x) = x
mul-leaves-labeled-Bin-Tree μ (constr f) =
μ ( mul-leaves-labeled-Bin-Tree μ (f false))
( mul-leaves-labeled-Bin-Tree μ (f true))
pick-list : {l1 : Level} {A : UU l1} → ℕ → list A → coprod A unit
pick-list zero-ℕ nil = inr star
pick-list zero-ℕ (cons a x) = inl a
pick-list (succ-ℕ n) nil = inr star
pick-list (succ-ℕ n) (cons a x) = pick-list n x
-}
| 31.205811
| 80
| 0.568746
|
ed1b784d896b8230b60e9cde6bd43c5c93a9c5f5
| 1,705
|
agda
|
Agda
|
src/IO-monad.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/IO-monad.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/IO-monad.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- IO
------------------------------------------------------------------------
{-# OPTIONS --without-K #-}
module IO-monad where
open import Monad.Raw
open import Prelude
open import String
------------------------------------------------------------------------
-- The IO type former
open import Agda.Builtin.IO public using (IO)
------------------------------------------------------------------------
-- The IO monad
postulate
returnIO : ∀ {a} {A : Type a} → A → IO A
bindIO : ∀ {a b} {A : Type a} {B : Type b} →
IO A → (A → IO B) → IO B
{-# COMPILE GHC returnIO = \_ _ -> return #-}
{-# COMPILE GHC bindIO = \_ _ _ _ -> (>>=) #-}
instance
io-monad : ∀ {ℓ} → Raw-monad (IO {a = ℓ})
Raw-monad.return io-monad = returnIO
Raw-monad._>>=_ io-monad = bindIO
------------------------------------------------------------------------
-- Some IO primitives
-- Note that some commands may raise exceptions when executed.
postulate
putStr : String → IO ⊤
putStrLn : String → IO ⊤
exitFailure : IO ⊤
getArgs : IO (List String)
{-# FOREIGN GHC
import qualified Data.Text
import qualified Data.Text.IO
import qualified System.Environment
import qualified System.Exit
#-}
-- Note that the GHC code below ignores potential problems. For
-- instance, putStr could raise an exception.
{-# COMPILE GHC putStr = Data.Text.IO.putStr #-}
{-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
{-# COMPILE GHC exitFailure = System.Exit.exitFailure #-}
{-# COMPILE GHC getArgs = fmap (map Data.Text.pack)
System.Environment.getArgs #-}
| 27.95082
| 72
| 0.491496
|
ed04f7d7b603627c11cc4f16b428cff10ac1f9f7
| 195
|
agda
|
Agda
|
test/Succeed/Issue3659.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3659.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3659.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical --allow-unsolved-metas #-}
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
module _ where
data D {ℓ} (A : Set ℓ) : Set ℓ where
c : PathP _ _ _
| 19.5
| 48
| 0.692308
|
3fb9ebb75f2f87bdb4eca2278cea4f9fed1ffa56
| 10,054
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
-----------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of the setoid sublist relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Setoid; _⇒_; _Preserves_⟶_)
module Data.List.Relation.Binary.Sublist.Setoid.Properties
{c ℓ} (S : Setoid c ℓ) where
open import Level
open import Data.List.Base hiding (_∷ʳ_)
import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality
import Data.List.Relation.Binary.Sublist.Setoid as SetoidSublist
import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties
as HeteroProperties
import Data.List.Membership.Setoid as SetoidMembership
open import Data.List.Relation.Unary.Any using (Any)
import Data.Maybe.Relation.Unary.All as Maybe
open import Data.Nat.Base using (_≤_; _≥_; z≤n; s≤s)
import Data.Nat.Properties as ℕₚ
open import Data.Product using (∃; _,_; proj₂)
open import Function.Base
open import Function.Bijection using (_⤖_)
open import Function.Equivalence using (_⇔_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
open import Relation.Unary using (Pred; Decidable; Irrelevant)
open import Relation.Nullary using (¬_)
open import Relation.Nullary.Negation using (¬?)
open Setoid S using (_≈_; trans) renaming (Carrier to A; refl to ≈-refl)
open SetoidEquality S using (_≋_; ≋-refl)
open SetoidSublist S hiding (map)
open SetoidMembership S using (_∈_)
------------------------------------------------------------------------
-- Injectivity of constructors
------------------------------------------------------------------------
module _ {xs ys : List A} where
∷-injectiveˡ : ∀ {x y} {px qx : x ≈ y} {pxs qxs : xs ⊆ ys} →
((x ∷ xs) ⊆ (y ∷ ys) ∋ px ∷ pxs) ≡ (qx ∷ qxs) → px ≡ qx
∷-injectiveˡ refl = refl
∷-injectiveʳ : ∀ {x y} {px qx : x ≈ y} {pxs qxs : xs ⊆ ys} →
((x ∷ xs) ⊆ (y ∷ ys) ∋ px ∷ pxs) ≡ (qx ∷ qxs) → pxs ≡ qxs
∷-injectiveʳ refl = refl
∷ʳ-injective : ∀ {y} {pxs qxs : xs ⊆ ys} → y ∷ʳ pxs ≡ y ∷ʳ qxs → pxs ≡ qxs
∷ʳ-injective refl = refl
------------------------------------------------------------------------
-- Various functions' outputs are sublists
------------------------------------------------------------------------
tail-⊆ : ∀ xs → Maybe.All (_⊆ xs) (tail xs)
tail-⊆ xs = HeteroProperties.tail-Sublist ⊆-refl
take-⊆ : ∀ n xs → take n xs ⊆ xs
take-⊆ n xs = HeteroProperties.take-Sublist n ⊆-refl
drop-⊆ : ∀ n xs → drop n xs ⊆ xs
drop-⊆ n xs = HeteroProperties.drop-Sublist n ⊆-refl
module _ {p} {P : Pred A p} (P? : Decidable P) where
takeWhile-⊆ : ∀ xs → takeWhile P? xs ⊆ xs
takeWhile-⊆ xs = HeteroProperties.takeWhile-Sublist P? ⊆-refl
dropWhile-⊆ : ∀ xs → dropWhile P? xs ⊆ xs
dropWhile-⊆ xs = HeteroProperties.dropWhile-Sublist P? ⊆-refl
filter-⊆ : ∀ xs → filter P? xs ⊆ xs
filter-⊆ xs = HeteroProperties.filter-Sublist P? ⊆-refl
module _ {p} {P : Pred A p} (P? : Decidable P) where
takeWhile⊆filter : ∀ xs → takeWhile P? xs ⊆ filter P? xs
takeWhile⊆filter xs = HeteroProperties.takeWhile-filter P? {xs} ≋-refl
filter⊆dropWhile : ∀ xs → filter P? xs ⊆ dropWhile (¬? ∘ P?) xs
filter⊆dropWhile xs = HeteroProperties.filter-dropWhile P? {xs} ≋-refl
------------------------------------------------------------------------
-- Various list functions are increasing wrt _⊆_
------------------------------------------------------------------------
-- We write f⁺ for the proof that `xs ⊆ ys → f xs ⊆ f ys`
-- and f⁻ for the one that `f xs ⊆ f ys → xs ⊆ ys`.
module _ {as bs : List A} where
∷ˡ⁻ : ∀ {a} → a ∷ as ⊆ bs → as ⊆ bs
∷ˡ⁻ = HeteroProperties.∷ˡ⁻
∷ʳ⁻ : ∀ {a b} → ¬ (a ≈ b) → a ∷ as ⊆ b ∷ bs → a ∷ as ⊆ bs
∷ʳ⁻ = HeteroProperties.∷ʳ⁻
∷⁻ : ∀ {a b} → a ∷ as ⊆ b ∷ bs → as ⊆ bs
∷⁻ = HeteroProperties.∷⁻
------------------------------------------------------------------------
-- map
module _ {b ℓ} (R : Setoid b ℓ) where
open Setoid R using () renaming (Carrier to B; _≈_ to _≈′_)
open SetoidSublist R using () renaming (_⊆_ to _⊆′_)
map⁺ : ∀ {as bs} {f : A → B} → f Preserves _≈_ ⟶ _≈′_ →
as ⊆ bs → map f as ⊆′ map f bs
map⁺ {f = f} f-resp as⊆bs =
HeteroProperties.map⁺ f f (SetoidSublist.map S f-resp as⊆bs)
------------------------------------------------------------------------
-- _++_
module _ {as bs : List A} where
++⁺ˡ : ∀ cs → as ⊆ bs → as ⊆ cs ++ bs
++⁺ˡ = HeteroProperties.++ˡ
++⁺ʳ : ∀ cs → as ⊆ bs → as ⊆ bs ++ cs
++⁺ʳ = HeteroProperties.++ʳ
++⁺ : ∀ {cs ds} → as ⊆ bs → cs ⊆ ds → as ++ cs ⊆ bs ++ ds
++⁺ = HeteroProperties.++⁺
++⁻ : ∀ {cs ds} → length as ≡ length bs → as ++ cs ⊆ bs ++ ds → cs ⊆ ds
++⁻ = HeteroProperties.++⁻
------------------------------------------------------------------------
-- take
module _ {m n} {xs} where
take⁺ : m ≤ n → take m xs ⊆ take n xs
take⁺ m≤n = HeteroProperties.take⁺ m≤n ≋-refl
------------------------------------------------------------------------
-- drop
module _ {m n} {xs ys : List A} where
drop⁺ : m ≥ n → xs ⊆ ys → drop m xs ⊆ drop n ys
drop⁺ = HeteroProperties.drop⁺
module _ {m n} {xs : List A} where
drop⁺-≥ : m ≥ n → drop m xs ⊆ drop n xs
drop⁺-≥ m≥n = drop⁺ m≥n ⊆-refl
module _ {xs ys : List A} where
drop⁺-⊆ : ∀ n → xs ⊆ ys → drop n xs ⊆ drop n ys
drop⁺-⊆ n xs⊆ys = drop⁺ {n} ℕₚ.≤-refl xs⊆ys
------------------------------------------------------------------------
-- takeWhile / dropWhile
module _ {p q} {P : Pred A p} {Q : Pred A q}
(P? : Decidable P) (Q? : Decidable Q) where
takeWhile⁺ : ∀ {xs} → (∀ {a b} → a ≈ b → P a → Q b) →
takeWhile P? xs ⊆ takeWhile Q? xs
takeWhile⁺ {xs} P⇒Q = HeteroProperties.⊆-takeWhile-Sublist P? Q? {xs} P⇒Q ≋-refl
dropWhile⁺ : ∀ {xs} → (∀ {a b} → a ≈ b → Q b → P a) →
dropWhile P? xs ⊆ dropWhile Q? xs
dropWhile⁺ {xs} P⇒Q = HeteroProperties.⊇-dropWhile-Sublist P? Q? {xs} P⇒Q ≋-refl
------------------------------------------------------------------------
-- filter
module _ {p q} {P : Pred A p} {Q : Pred A q}
(P? : Decidable P) (Q? : Decidable Q) where
filter⁺ : ∀ {as bs} → (∀ {a b} → a ≈ b → P a → Q b) →
as ⊆ bs → filter P? as ⊆ filter Q? bs
filter⁺ = HeteroProperties.⊆-filter-Sublist P? Q?
------------------------------------------------------------------------
-- reverse
module _ {as bs : List A} where
reverseAcc⁺ : ∀ {cs ds} → as ⊆ bs → cs ⊆ ds →
reverseAcc cs as ⊆ reverseAcc ds bs
reverseAcc⁺ = HeteroProperties.reverseAcc⁺
ʳ++⁺ : ∀ {cs ds} →
as ⊆ bs →
cs ⊆ ds →
as ʳ++ cs ⊆ bs ʳ++ ds
ʳ++⁺ = reverseAcc⁺
reverse⁺ : as ⊆ bs → reverse as ⊆ reverse bs
reverse⁺ = HeteroProperties.reverse⁺
reverse⁻ : reverse as ⊆ reverse bs → as ⊆ bs
reverse⁻ = HeteroProperties.reverse⁻
------------------------------------------------------------------------
-- Inversion lemmas
------------------------------------------------------------------------
module _ {a as b bs} where
∷⁻¹ : a ≈ b → as ⊆ bs ⇔ a ∷ as ⊆ b ∷ bs
∷⁻¹ = HeteroProperties.∷⁻¹
∷ʳ⁻¹ : ¬ (a ≈ b) → a ∷ as ⊆ bs ⇔ a ∷ as ⊆ b ∷ bs
∷ʳ⁻¹ = HeteroProperties.∷ʳ⁻¹
------------------------------------------------------------------------
-- Other
------------------------------------------------------------------------
module _ where
length-mono-≤ : ∀ {as bs} → as ⊆ bs → length as ≤ length bs
length-mono-≤ = HeteroProperties.length-mono-≤
------------------------------------------------------------------------
-- Conversion to and from list equality
to-≋ : ∀ {as bs} → length as ≡ length bs → as ⊆ bs → as ≋ bs
to-≋ = HeteroProperties.toPointwise
------------------------------------------------------------------------
-- Irrelevant special case
[]⊆-irrelevant : Irrelevant ([] ⊆_)
[]⊆-irrelevant = HeteroProperties.Sublist-[]-irrelevant
------------------------------------------------------------------------
-- (to/from)∈ is a bijection
module _ {x xs} where
to∈-injective : ∀ {p q : [ x ] ⊆ xs} → to∈ p ≡ to∈ q → p ≡ q
to∈-injective = HeteroProperties.toAny-injective
from∈-injective : ∀ {p q : x ∈ xs} → from∈ p ≡ from∈ q → p ≡ q
from∈-injective = HeteroProperties.fromAny-injective
to∈∘from∈≗id : ∀ (p : x ∈ xs) → to∈ (from∈ p) ≡ p
to∈∘from∈≗id = HeteroProperties.toAny∘fromAny≗id
[x]⊆xs⤖x∈xs : ([ x ] ⊆ xs) ⤖ (x ∈ xs)
[x]⊆xs⤖x∈xs = HeteroProperties.Sublist-[x]-bijection
------------------------------------------------------------------------
-- Properties of Disjoint(ness) and DisjointUnion
open HeteroProperties.Disjointness {R = _≈_} public
open HeteroProperties.DisjointnessMonotonicity {R = _≈_} {S = _≈_} {T = _≈_} trans public
-- Shrinking one of two disjoint lists preserves disjointness.
-- We would have liked to define shrinkDisjointˡ σ = shrinkDisjoint σ ⊆-refl
-- but alas, this is only possible for groupoids, not setoids in general.
shrinkDisjointˡ : ∀ {xs ys zs us} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} (σ : us ⊆ xs) →
Disjoint τ₁ τ₂ →
Disjoint (⊆-trans σ τ₁) τ₂
-- Not affected by σ:
shrinkDisjointˡ σ (y ∷ₙ d) = y ∷ₙ shrinkDisjointˡ σ d
shrinkDisjointˡ σ (y≈z ∷ᵣ d) = y≈z ∷ᵣ shrinkDisjointˡ σ d
-- In σ: keep x.
shrinkDisjointˡ (u≈x ∷ σ) (x≈z ∷ₗ d) = trans u≈x x≈z ∷ₗ shrinkDisjointˡ σ d
-- Not in σ: drop x.
shrinkDisjointˡ (x ∷ʳ σ) (x≈z ∷ₗ d) = _ ∷ₙ shrinkDisjointˡ σ d
shrinkDisjointˡ [] [] = []
shrinkDisjointʳ : ∀ {xs ys zs vs} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} (σ : vs ⊆ ys) →
Disjoint τ₁ τ₂ →
Disjoint τ₁ (⊆-trans σ τ₂)
-- Not affected by σ:
shrinkDisjointʳ σ (y ∷ₙ d) = y ∷ₙ shrinkDisjointʳ σ d
shrinkDisjointʳ σ (x≈z ∷ₗ d) = x≈z ∷ₗ shrinkDisjointʳ σ d
-- In σ: keep y.
shrinkDisjointʳ (v≈y ∷ σ) (y≈z ∷ᵣ d) = trans v≈y y≈z ∷ᵣ shrinkDisjointʳ σ d
-- Not in σ: drop y.
shrinkDisjointʳ (y ∷ʳ σ) (y≈z ∷ᵣ d) = _ ∷ₙ shrinkDisjointʳ σ d
shrinkDisjointʳ [] [] = []
| 34.197279
| 89
| 0.497016
|
65bba45d0a4466f9aada7393d98648dc075ab532
| 103
|
agda
|
Agda
|
test/Fail/ModuleArityMismatch.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/ModuleArityMismatch.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/ModuleArityMismatch.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module ModuleArityMismatch where
module M (A : Set) where
postulate
A : Set
module M′ = M A A
| 11.444444
| 32
| 0.669903
|
0106b41326f39ad5a47b8f6d4322f4ac6c43b424
| 671
|
agda
|
Agda
|
test/Succeed/Issue3544.agda
|
gallais/agda
|
e7f588d478bdd3c03088c49e009bcdf6a2a3310f
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue3544.agda
|
gallais/agda
|
e7f588d478bdd3c03088c49e009bcdf6a2a3310f
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue3544.agda
|
gallais/agda
|
e7f588d478bdd3c03088c49e009bcdf6a2a3310f
|
[
"BSD-3-Clause"
] | 1
|
2021-04-01T18:30:09.000Z
|
2021-04-01T18:30:09.000Z
|
data Nat : Set where
succ : Nat → Nat
data Fin : Nat → Set where
zero : (n : Nat) → Fin (succ n)
data Tm (n : Nat) : Set where
var : Fin n → Tm n
piv : Fin (succ n) → Tm n
data Cx : Nat → Set where
succ : (n : Nat) → Tm n → Cx (succ n)
data CxChk : ∀ n → Cx n → Set where
succ : (n : Nat) (T : Tm n) → CxChk (succ n) (succ n T)
data TmChk (n : Nat) : Cx n → Tm n → Set where
vtyp : (g : Cx n) (v : Fin n) → CxChk n g → TmChk n g (var v)
error : ∀ n g s → TmChk n g s → Set
error n g s (vtyp g' (zero x) (succ n' (piv (zero y)))) = Nat -- Internal error here.
error _ _ _ (vtyp g' (zero n) (succ n (var x))) = Nat -- This clause added to pass 2.5.3.
| 27.958333
| 89
| 0.546945
|
64698e358b17b671019d790407068aa81e3c5b17
| 278
|
agda
|
Agda
|
Data/Binary/Tests/Multiplication.agda
|
oisdk/agda-binary
|
92af4d620febd47a9791d466d747278dc4a417aa
|
[
"MIT"
] | 1
|
2019-03-21T21:30:10.000Z
|
2019-03-21T21:30:10.000Z
|
Data/Binary/Tests/Multiplication.agda
|
oisdk/agda-binary
|
92af4d620febd47a9791d466d747278dc4a417aa
|
[
"MIT"
] | null | null | null |
Data/Binary/Tests/Multiplication.agda
|
oisdk/agda-binary
|
92af4d620febd47a9791d466d747278dc4a417aa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Data.Binary.Tests.Multiplication where
import Data.Binary.Operations.Multiplication as 𝔹
open import Data.Binary.Tests.Helpers
open import Relation.Binary.PropositionalEquality
import Data.Nat as ℕ
_ : 𝔹._*_ ≡⌈ 60 ⌉₂≡ ℕ._*_
_ = refl
| 23.166667
| 49
| 0.755396
|
6558be7eead49d96517ee0130805420543a67684
| 941
|
agda
|
Agda
|
test/epic/Prelude/String.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/epic/Prelude/String.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/epic/Prelude/String.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module Prelude.String where
open import Prelude.Bool
open import Prelude.Char
open import Prelude.List
open import Prelude.Nat
postulate
String : Set
nil : String
primStringToNat : String → Nat
charToString : Char -> String
{-# BUILTIN STRING String #-}
primitive
primStringAppend : String → String → String
primStringToList : String → List Char
primStringFromList : List Char → String
primStringEquality : String → String → Bool
{-# COMPILED_EPIC nil () -> String = "" #-}
{-# COMPILED_EPIC primStringToNat (s : String) -> BigInt = foreign BigInt "strToBigInt" (s : String) #-}
-- {-# COMPILED_EPIC charToString (c : Int) -> String = charToString(c) #-}
strEq : (x y : String) -> Bool
strEq = primStringEquality
infixr 30 _+S+_
_+S+_ : (x y : String) -> String
_+S+_ = primStringAppend
fromList : List Char -> String
fromList = primStringFromList
fromString : String -> List Char
fromString = primStringToList
| 24.763158
| 104
| 0.706695
|
651a833ccddde738c4b377cbc7a3b22892f46b58
| 8,937
|
agda
|
Agda
|
Cubical/Algebra/Ring/Base.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring/Base.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring/Base.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Ring.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.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Reflection.StrictEquiv
open Iso
private
variable
ℓ ℓ' : Level
record IsRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor isring
field
+IsAbGroup : IsAbGroup 0r _+_ -_
·IsMonoid : IsMonoid 1r _·_
dist : (x y z : R) → (x · (y + z) ≡ (x · y) + (x · z))
× ((x + y) · z ≡ (x · z) + (y · z))
-- This is in the Agda stdlib, but it's redundant
-- zero : (x : R) → (x · 0r ≡ 0r) × (0r · x ≡ 0r)
open IsAbGroup +IsAbGroup public
renaming
( assoc to +Assoc
; identity to +Identity
; lid to +Lid
; rid to +Rid
; inverse to +Inv
; invl to +Linv
; invr to +Rinv
; comm to +Comm
; isSemigroup to +IsSemigroup
; isMonoid to +IsMonoid
; isGroup to +IsGroup )
open IsMonoid ·IsMonoid public
renaming
( assoc to ·Assoc
; identity to ·Identity
; lid to ·Lid
; rid to ·Rid
; isSemigroup to ·IsSemigroup )
hiding
( is-set ) -- We only want to export one proof of this
·Rdist+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)
·Rdist+ x y z = dist x y z .fst
·Ldist+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z)
·Ldist+ x y z = dist x y z .snd
record RingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor ringstr
field
0r : A
1r : A
_+_ : A → A → A
_·_ : A → A → A
-_ : A → A
isRing : IsRing 0r 1r _+_ _·_ -_
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsRing isRing public
Ring : Type (ℓ-suc ℓ)
Ring = TypeWithStr _ RingStr
isSetRing : (R : Ring {ℓ}) → isSet ⟨ R ⟩
isSetRing R = R .snd .RingStr.isRing .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
makeIsRing : {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)
(r+-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-lid : (x : R) → 1r · x ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-ldist-+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z))
→ IsRing 0r 1r _+_ _·_ -_
makeIsRing is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ =
isring (makeIsAbGroup is-setR assoc +-rid +-rinv +-comm)
(makeIsMonoid is-setR ·-assoc ·-rid ·-lid)
λ x y z → ·-rdist-+ x y z , ·-ldist-+ x y z
makeRing : {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)
(·-lid : (x : R) → 1r · x ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-ldist-+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z))
→ Ring
makeRing 0r 1r _+_ _·_ -_ is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ =
_ , ringstr 0r 1r _+_ _·_ -_
(makeIsRing is-setR assoc +-rid +-rinv +-comm
·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ )
record RingEquiv (R : Ring {ℓ}) (S : Ring {ℓ'}) (e : ⟨ R ⟩ ≃ ⟨ S ⟩) : Type (ℓ-max ℓ ℓ') where
constructor ringequiv
private
module R = RingStr (snd R)
module S = RingStr (snd S)
field
pres1 : equivFun e R.1r ≡ S.1r
isHom+ : (x y : ⟨ R ⟩) → equivFun e (x R.+ y) ≡ equivFun e x S.+ equivFun e y
isHom· : (x y : ⟨ R ⟩) → equivFun e (x R.· y) ≡ equivFun e x S.· equivFun e y
record RingHom (R S : Ring {ℓ}) : Type ℓ where
constructor ringhom
private
module R = RingStr (snd R)
module S = RingStr (snd S)
field
f : ⟨ R ⟩ → ⟨ S ⟩
pres1 : f R.1r ≡ S.1r
isHom+ : (x y : ⟨ R ⟩) → f (x R.+ y) ≡ f x S.+ f y
isHom· : (x y : ⟨ R ⟩) → f (x R.· y) ≡ f x S.· f y
_$_ : {R S : Ring {ℓ}} → (φ : RingHom R S) → (x : ⟨ R ⟩) → ⟨ S ⟩
φ $ x = RingHom.f φ x
module RingΣTheory {ℓ} where
RawRingStructure = λ (X : Type ℓ) → (X → X → X) × X × (X → X → X)
RawRingEquivStr = AutoEquivStr RawRingStructure
rawRingUnivalentStr : UnivalentStr _ RawRingEquivStr
rawRingUnivalentStr = autoUnivalentStr RawRingStructure
RingAxioms : (R : Type ℓ) (s : RawRingStructure R) → Type ℓ
RingAxioms R (_+_ , 1r , _·_) =
AbGroupΣTheory.AbGroupAxioms R _+_
× IsMonoid 1r _·_
× ((x y z : R) → (x · (y + z) ≡ (x · y) + (x · z)) × ((x + y) · z ≡ (x · z) + (y · z)))
RingStructure : Type ℓ → Type ℓ
RingStructure = AxiomsStructure RawRingStructure RingAxioms
RingΣ : Type (ℓ-suc ℓ)
RingΣ = TypeWithStr ℓ RingStructure
RingEquivStr : StrEquiv RingStructure ℓ
RingEquivStr = AxiomsEquivStr RawRingEquivStr RingAxioms
isPropRingAxioms : (R : Type ℓ) (s : RawRingStructure R) → isProp (RingAxioms R s)
isPropRingAxioms R (_+_ , 1r , _·_) =
isProp× (AbGroupΣTheory.isPropAbGroupAxioms R _+_)
(isPropΣ (isPropIsMonoid 1r _·_)
λ R → isPropΠ3 λ _ _ _ →
isProp× (IsSemigroup.is-set (R .IsMonoid.isSemigroup) _ _)
(IsSemigroup.is-set (R .IsMonoid.isSemigroup) _ _))
Ring→RingΣ : Ring → RingΣ
Ring→RingΣ (R , ringstr 0r 1r _+_ _·_ -_ (isring +-isAbelianGroup ·-isMonoid dist)) =
( R
, (_+_ , 1r , _·_)
, AbGroupΣTheory.AbGroup→AbGroupΣ (_ , abgroupstr _ _ _ +-isAbelianGroup) .snd .snd
, ·-isMonoid , dist
)
RingΣ→Ring : RingΣ → Ring
RingΣ→Ring (_ , (y1 , y2 , y3) , z , w1 , w2) =
_ , ringstr _ y2 y1 y3 _
(isring (AbGroupΣTheory.AbGroupΣ→AbGroup (_ , _ , z ) .snd .AbGroupStr.isAbGroup)
w1 w2)
RingIsoRingΣ : Iso Ring RingΣ
RingIsoRingΣ = iso Ring→RingΣ RingΣ→Ring (λ _ → refl) (λ _ → refl)
ringUnivalentStr : UnivalentStr RingStructure RingEquivStr
ringUnivalentStr = axiomsUnivalentStr _ isPropRingAxioms rawRingUnivalentStr
RingΣPath : (R S : RingΣ) → (R ≃[ RingEquivStr ] S) ≃ (R ≡ S)
RingΣPath = SIP ringUnivalentStr
RingEquivΣ : (R S : Ring) → Type ℓ
RingEquivΣ R S = Ring→RingΣ R ≃[ RingEquivStr ] Ring→RingΣ S
RingIsoΣPath : {R S : Ring} → Iso (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e) (RingEquivΣ R S)
fun RingIsoΣPath (e , ringequiv h1 h2 h3) = e , h2 , h1 , h3
inv RingIsoΣPath (e , h1 , h2 , h3) = e , ringequiv h2 h1 h3
rightInv RingIsoΣPath _ = refl
leftInv RingIsoΣPath _ = refl
RingPath : (R S : Ring) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e) ≃ (R ≡ S)
RingPath R S =
Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e ≃⟨ strictIsoToEquiv RingIsoΣPath ⟩
RingEquivΣ R S ≃⟨ RingΣPath _ _ ⟩
Ring→RingΣ R ≡ Ring→RingΣ S ≃⟨ isoToEquiv (invIso (congIso RingIsoRingΣ)) ⟩
R ≡ S ■
RingPath : (R S : Ring {ℓ}) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e) ≃ (R ≡ S)
RingPath = RingΣTheory.RingPath
isPropIsRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
→ isProp (IsRing 0r 1r _+_ _·_ -_)
isPropIsRing 0r 1r _+_ _·_ -_ (isring RG RM RD) (isring SG SM SD) =
λ i → isring (isPropIsAbGroup _ _ _ RG SG i)
(isPropIsMonoid _ _ RM SM i)
(isPropDistr RD SD i)
where
isSetR : isSet _
isSetR = RM .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropDistr : isProp ((x y z : _) → ((x · (y + z)) ≡ ((x · y) + (x · z)))
× (((x + y) · z) ≡ ((x · z) + (y · z))))
isPropDistr = isPropΠ3 λ _ _ _ → isProp× (isSetR _ _) (isSetR _ _)
-- Rings have an abelian group and a monoid
Ring→AbGroup : Ring {ℓ} → AbGroup {ℓ}
Ring→AbGroup (A , ringstr _ _ _ _ _ R) = A , abgroupstr _ _ _ (IsRing.+IsAbGroup R)
Ring→Monoid : Ring {ℓ} → Monoid {ℓ}
Ring→Monoid (A , ringstr _ _ _ _ _ R) = monoid _ _ _ (IsRing.·IsMonoid R)
| 34.505792
| 101
| 0.529037
|
edc80b7a7e7da673c8dc71d61935e62221d9ec8d
| 62
|
agda
|
Agda
|
test/Fail/Issue461.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue461.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue461.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue461 where
data D : Set where
data D : Set where
| 10.333333
| 21
| 0.725806
|
3f2b17d38ea526355b8a194e120887bcfedf2988
| 2,480
|
agda
|
Agda
|
src/Bisimilarity/Delay-monad.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Bisimilarity/Delay-monad.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Bisimilarity/Delay-monad.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some results related to strong bisimilarity for the delay monad
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.Delay-monad {a} {A : Type a} where
open import Delay-monad
open import Delay-monad.Bisimilarity as D using (force)
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import Labelled-transition-system
open import Labelled-transition-system.Delay-monad A
open import Bisimilarity delay-monad
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
------------------------------------------------------------------------
-- The direct and the indirect definitions of strong bisimilarity are
-- pointwise logically equivalent
-- An emulation of the constructor D.later.
later-cong : ∀ {i x y} →
[ i ] force x ∼′ force y → [ i ] later x ∼ later y
later-cong x∼′y =
⟨ (λ { later → _ , later , x∼′y })
, (λ { later → _ , later , x∼′y })
⟩
-- The direct definition of strong bisimilarity is contained in the
-- one obtained from the transition relation.
direct→indirect : ∀ {i x y} →
D.[ i ] x ∼ y → [ i ] x ∼ y
direct→indirect D.now = reflexive
direct→indirect (D.later p) = later-cong λ { .force →
direct→indirect (force p) }
-- The definition of strong bisimilarity obtained from the transition
-- relation is contained in the direct one.
indirect→direct : ∀ {i} x y → [ i ] x ∼ y → D.[ i ] x ∼ y
indirect→direct (now x) (now y) nx∼ny
with left-to-right nx∼ny now
... | _ , now , _ = D.now
indirect→direct (later x) (later y) lx∼ly
with left-to-right lx∼ly later
... | _ , later , x∼′y = D.later λ { .force →
indirect→direct _ _ (force x∼′y) }
indirect→direct (now x) (later y) nx∼ly
with left-to-right nx∼ly now
... | _ , () , _
indirect→direct (later x) (now y) lx∼ny
with left-to-right lx∼ny later
... | _ , () , _
-- The direct definition of strong bisimilarity is pointwise logically
-- equivalent to the one obtained from the transition relation.
--
-- TODO: Are the two definitions isomorphic?
direct⇔indirect : ∀ {i x y} → D.[ i ] x ∼ y ⇔ [ i ] x ∼ y
direct⇔indirect = record
{ to = direct→indirect
; from = indirect→direct _ _
}
| 31.794872
| 72
| 0.599194
|
72498ce93b22e000e786a162ff6c900dcdc08d0b
| 113
|
agda
|
Agda
|
test/fail/NoTerminationCheck1.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/NoTerminationCheck1.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/NoTerminationCheck1.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- 2012-03-08 Andreas
module NoTerminationCheck1 where
{-# NO_TERMINATION_CHECK #-}
-- error: misplaced pragma
| 16.142857
| 32
| 0.752212
|
34c9b1ec61af6d818bff3c0ecf23627d9682e0dd
| 109
|
agda
|
Agda
|
agda/Everything.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 32
|
2017-05-22T14:33:27.000Z
|
2021-03-05T12:12:03.000Z
|
agda/Everything.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 2
|
2018-02-14T16:42:36.000Z
|
2018-02-20T14:54:18.000Z
|
agda/Everything.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 4
|
2017-11-10T16:44:52.000Z
|
2018-02-23T18:22:17.000Z
|
module Everything where
import Library
import Syntax
import RenamingAndSubstitution
import EquationalTheory
| 15.571429
| 30
| 0.889908
|
721d74ea6a633396368266a1be9ca03841d84b7d
| 12,488
|
agda
|
Agda
|
Cubical/HITs/SetQuotients/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetQuotients/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetQuotients/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
{-
Set quotients:
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetQuotients.Properties where
open import Cubical.HITs.SetQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
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.Functions.FunExtEquiv
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open import Cubical.HITs.TypeQuotients as TypeQuot using (_/ₜ_ ; [_] ; eq/)
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥ ; ∣_∣ ; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂ ; ∣_∣₂ ; squash₂
; setTruncIsSet)
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ
B : A / R → Type ℓ
C : A / R → A / R → Type ℓ
D : A / R → A / R → A / R → Type ℓ
elimEq/ : (Bprop : (x : A / R ) → isProp (B x))
{x y : A / R}
(eq : x ≡ y)
(bx : B x)
(by : B y) →
PathP (λ i → B (eq i)) bx by
elimEq/ {B = B} Bprop {x = x} =
J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by)
elimProp : ((x : A / R ) → isProp (B x))
→ ((a : A) → B ( [ a ]))
→ (x : A / R)
→ B x
elimProp Bprop f [ x ] = f x
elimProp Bprop f (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 (λ x → isProp→isSet (Bprop x))
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elimProp Bprop f
elimProp Bprop f (eq/ a b r i) = elimEq/ Bprop (eq/ a b r) (f a) (f b) i
elimProp2 : ((x y : A / R ) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
→ (x y : A / R)
→ C x y
elimProp2 Cprop f = elimProp (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp (λ y → Cprop [ x ] y) (f x))
elimProp3 : ((x y z : A / R ) → isProp (D x y z))
→ ((a b c : A) → D [ a ] [ b ] [ c ])
→ (x y z : A / R)
→ D x y z
elimProp3 Dprop f = elimProp (λ x → isPropΠ2 (λ y z → Dprop x y z))
(λ x → elimProp2 (λ y z → Dprop [ x ] y z) (f x))
-- lemma 6.10.2 in hott book
[]surjective : (x : A / R) → ∃[ a ∈ A ] [ a ] ≡ x
[]surjective = elimProp (λ x → squash) (λ a → ∣ a , refl ∣)
elim : {B : A / R → Type ℓ}
→ ((x : A / R) → isSet (B x))
→ (f : (a : A) → (B [ a ]))
→ ((a b : A) (r : R a b) → PathP (λ i → B (eq/ a b r i)) (f a) (f b))
→ (x : A / R)
→ B x
elim Bset f feq [ a ] = f a
elim Bset f feq (eq/ a b r i) = feq a b r i
elim Bset f feq (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elim Bset f feq
rec : {B : Type ℓ}
(Bset : isSet B)
(f : A → B)
(feq : (a b : A) (r : R a b) → f a ≡ f b)
→ A / R → B
rec Bset f feq [ a ] = f a
rec Bset f feq (eq/ a b r i) = feq a b r i
rec Bset f feq (squash/ x y p q i j) = Bset (g x) (g y) (cong g p) (cong g q) i j
where
g = rec Bset f feq
rec2 : {B : Type ℓ} (Bset : isSet B)
(f : A → A → B) (feql : (a b c : A) (r : R a b) → f a c ≡ f b c)
(feqr : (a b c : A) (r : R b c) → f a b ≡ f a c)
→ A / R → A / R → B
rec2 Bset f feql feqr = rec (isSetΠ (λ _ → Bset))
(λ a → rec Bset (f a) (feqr a))
(λ a b r → funExt (elimProp (λ _ → Bset _ _)
(λ c → feql a b c r)))
-- the recursor for maps into groupoids:
-- i.e. for any type A with a binary relation R and groupoid B,
-- we can construct a map A / R → B from a map A → B satisfying the conditions
-- (i) ∀ (a b : A) → R a b → f a ≡ f b
-- (ii) ∀ (a b : A) → isProp (f a ≡ f b)
-- We start by proving that we can recover the set-quotient
-- by set-truncating the (non-truncated type quotient)
typeQuotSetTruncIso : Iso (A / R) ∥ A /ₜ R ∥₂
Iso.fun typeQuotSetTruncIso = rec setTruncIsSet (λ a → ∣ [ a ] ∣₂)
λ a b r → cong ∣_∣₂ (eq/ a b r)
Iso.inv typeQuotSetTruncIso = SetTrunc.rec squash/ (TypeQuot.rec [_] eq/)
Iso.rightInv typeQuotSetTruncIso = SetTrunc.elim (λ _ → isProp→isSet (squash₂ _ _))
(TypeQuot.elimProp (λ _ → squash₂ _ _) λ _ → refl)
Iso.leftInv typeQuotSetTruncIso = elimProp (λ _ → squash/ _ _) λ _ → refl
module rec→Gpd {A : Type ℓ} {R : A → A → Type ℓ'} {B : Type ℓ''} (Bgpd : isGroupoid B)
(f : A → B)
(feq : ∀ (a b : A) → R a b → f a ≡ f b)
(fprop : ∀ (a b : A) → isProp (f a ≡ f b)) where
fun : A / R → B
fun = f₁ ∘ f₂
where
f₁ : ∥ A /ₜ R ∥₂ → B
f₁ = SetTrunc.rec→Gpd.fun Bgpd f/ congF/Const
where
f/ : A /ₜ R → B
f/ = TypeQuot.rec f feq
congF/Const : (a b : A /ₜ R) (p q : a ≡ b) → cong f/ p ≡ cong f/ q
congF/Const = TypeQuot.elimProp2 (λ _ _ → isPropΠ2 λ _ _ → Bgpd _ _ _ _)
λ a b p q → fprop a b (cong f/ p) (cong f/ q)
f₂ : A / R → ∥ A /ₜ R ∥₂
f₂ = Iso.fun typeQuotSetTruncIso
setQuotUniversalIso : {B : Type ℓ} (Bset : isSet B)
→ Iso (A / R → B) (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b))
Iso.fun (setQuotUniversalIso Bset) g = (λ a → g [ a ]) , λ a b r i → g (eq/ a b r i)
Iso.inv (setQuotUniversalIso Bset) h = elim (λ x → Bset) (fst h) (snd h)
Iso.rightInv (setQuotUniversalIso Bset) h = refl
Iso.leftInv (setQuotUniversalIso Bset) g =
funExt (λ x → PropTrunc.elim (λ sur → Bset (out (intro g) x) (g x))
(λ sur → cong (out (intro g)) (sym (snd sur)) ∙ (cong g (snd sur))) ([]surjective x))
where
intro = Iso.fun (setQuotUniversalIso Bset)
out = Iso.inv (setQuotUniversalIso Bset)
setQuotUniversal : {B : Type ℓ} (Bset : isSet B) →
(A / R → B) ≃ (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b))
setQuotUniversal Bset = isoToEquiv (setQuotUniversalIso Bset)
open BinaryRelation
-- characterisation of binary functions/operations on set-quotients
setQuotUniversal2Iso : {B : Type ℓ} (Bset : isSet B) → isRefl R
→ Iso (A / R → A / R → B)
(Σ[ _∗_ ∈ (A → A → B) ] ((a a' b b' : A) → R a a' → R b b' → a ∗ b ≡ a' ∗ b'))
Iso.fun (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) _∗/_ = _∗_ , h
where
_∗_ = λ a b → [ a ] ∗/ [ b ]
h : (a a' b b' : A) → R a a' → R b b' → a ∗ b ≡ a' ∗ b'
h a a' b b' ra rb = cong (_∗/ [ b ]) (eq/ _ _ ra) ∙ cong ([ a' ] ∗/_) (eq/ _ _ rb)
Iso.inv (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) (_∗_ , h) =
rec2 Bset _∗_ hleft hright
where
hleft : ∀ a b c → R a b → (a ∗ c) ≡ (b ∗ c)
hleft _ _ c r = h _ _ _ _ r (isReflR c)
hright : ∀ a b c → R b c → (a ∗ b) ≡ (a ∗ c)
hright a _ _ r = h _ _ _ _ (isReflR a) r
Iso.rightInv (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) (_∗_ , h) =
Σ≡Prop (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ2 λ _ _ → Bset _ _) refl
Iso.leftInv (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) _∗/_ =
funExt₂ (elimProp2 (λ _ _ → Bset _ _) λ _ _ → refl)
setQuotUniversal2 : {B : Type ℓ} (Bset : isSet B) → isRefl R
→ (A / R → A / R → B)
≃ (Σ[ _∗_ ∈ (A → A → B) ] ((a a' b b' : A) → R a a' → R b b' → a ∗ b ≡ a' ∗ b'))
setQuotUniversal2 Bset isReflR = isoToEquiv (setQuotUniversal2Iso Bset isReflR)
-- corollary for binary operations
-- TODO: prove truncated inverse for effective relations
setQuotBinOp : isRefl R
→ (_∗_ : A → A → A)
→ (∀ a a' b b' → R a a' → R b b' → R (a ∗ b) (a' ∗ b'))
→ (A / R → A / R → A / R)
setQuotBinOp isReflR _∗_ h = Iso.inv (setQuotUniversal2Iso squash/ isReflR)
((λ a b → [ a ∗ b ]) , λ _ _ _ _ ra rb → eq/ _ _ (h _ _ _ _ ra rb))
setQuotSymmBinOp : isRefl R → isTrans R
→ (_∗_ : A → A → A)
→ (∀ a b → a ∗ b ≡ b ∗ a)
→ (∀ a a' b → R a a' → R (a ∗ b) (a' ∗ b))
→ (A / R → A / R → A / R)
setQuotSymmBinOp {A = A} {R = R} isReflR isTransR _∗_ ∗-symm h = setQuotBinOp isReflR _∗_ h'
where
h' : ∀ a a' b b' → R a a' → R b b' → R (a ∗ b) (a' ∗ b')
h' a a' b b' ra rb = isTransR _ _ _ (h a a' b ra)
(transport (λ i → R (∗-symm b a' i) (∗-symm b' a' i)) (h b b' a' rb))
effective : (Rprop : isPropValued R) (Requiv : isEquivRel R) (a b : A) → [ a ] ≡ [ b ] → R a b
effective {A = A} {R = R} Rprop (equivRel R/refl R/sym R/trans) a b p = transport aa≡ab (R/refl _)
where
helper : A / R → hProp _
helper =
rec isSetHProp (λ c → (R a c , Rprop a c))
(λ c d cd → Σ≡Prop (λ _ → isPropIsProp)
(hPropExt (Rprop a c) (Rprop a d)
(λ ac → R/trans _ _ _ ac cd) (λ ad → R/trans _ _ _ ad (R/sym _ _ cd))))
aa≡ab : R a a ≡ R a b
aa≡ab i = helper (p i) .fst
isEquivRel→effectiveIso : isPropValued R → isEquivRel R → (a b : A) → Iso ([ a ] ≡ [ b ]) (R a b)
Iso.fun (isEquivRel→effectiveIso {R = R} Rprop Req a b) = effective Rprop Req a b
Iso.inv (isEquivRel→effectiveIso {R = R} Rprop Req a b) = eq/ a b
Iso.rightInv (isEquivRel→effectiveIso {R = R} Rprop Req a b) _ = Rprop a b _ _
Iso.leftInv (isEquivRel→effectiveIso {R = R} Rprop Req a b) _ = squash/ _ _ _ _
isEquivRel→isEffective : isPropValued R → isEquivRel R → isEffective R
isEquivRel→isEffective Rprop Req a b = isoToIsEquiv (invIso (isEquivRel→effectiveIso Rprop Req a b))
discreteSetQuotients : Discrete A → isPropValued R → isEquivRel R → (∀ a₀ a₁ → Dec (R a₀ a₁)) → Discrete (A / R)
discreteSetQuotients {A = A} {R = R} Adis Rprop Req Rdec =
elim (λ a₀ → isSetΠ (λ a₁ → isProp→isSet (isPropDec (squash/ a₀ a₁))))
discreteSetQuotients' discreteSetQuotients'-eq
where
discreteSetQuotients' : (a : A) (y : A / R) → Dec ([ a ] ≡ y)
discreteSetQuotients' a₀ = elim (λ a₁ → isProp→isSet (isPropDec (squash/ [ a₀ ] a₁))) dis dis-eq
where
dis : (a₁ : A) → Dec ([ a₀ ] ≡ [ a₁ ])
dis a₁ with Rdec a₀ a₁
... | (yes p) = yes (eq/ a₀ a₁ p)
... | (no ¬p) = no λ eq → ¬p (effective Rprop Req a₀ a₁ eq )
dis-eq : (a b : A) (r : R a b) →
PathP (λ i → Dec ([ a₀ ] ≡ eq/ a b r i)) (dis a) (dis b)
dis-eq a b ab = J (λ b ab → ∀ k → PathP (λ i → Dec ([ a₀ ] ≡ ab i)) (dis a) k)
(λ k → isPropDec (squash/ _ _) _ _) (eq/ a b ab) (dis b)
discreteSetQuotients'-eq : (a b : A) (r : R a b) →
PathP (λ i → (y : A / R) → Dec (eq/ a b r i ≡ y))
(discreteSetQuotients' a) (discreteSetQuotients' b)
discreteSetQuotients'-eq a b ab =
J (λ b ab → ∀ k → PathP (λ i → (y : A / R) → Dec (ab i ≡ y))
(discreteSetQuotients' a) k)
(λ k → funExt (λ x → isPropDec (squash/ _ _) _ _)) (eq/ a b ab) (discreteSetQuotients' b)
-- Quotienting by the truncated relation is equivalent to quotienting by untruncated relation
truncRelIso : Iso (A / R) (A / (λ a b → ∥ R a b ∥))
Iso.fun truncRelIso = rec squash/ [_] λ _ _ r → eq/ _ _ ∣ r ∣
Iso.inv truncRelIso = rec squash/ [_] λ _ _ → PropTrunc.rec (squash/ _ _) λ r → eq/ _ _ r
Iso.rightInv truncRelIso = elimProp (λ _ → squash/ _ _) λ _ → refl
Iso.leftInv truncRelIso = elimProp (λ _ → squash/ _ _) λ _ → refl
truncRelEquiv : A / R ≃ A / (λ a b → ∥ R a b ∥)
truncRelEquiv = isoToEquiv truncRelIso
-- Using this we can obtain a useful characterization of
-- path-types for equivalence relations (not prop-valued)
-- and their quotients
isEquivRel→TruncIso : isEquivRel R → (a b : A) → Iso ([ a ] ≡ [ b ]) ∥ R a b ∥
isEquivRel→TruncIso {A = A} {R = R} Req a b = compIso (isProp→Iso (squash/ _ _) (squash/ _ _)
(cong (Iso.fun truncRelIso)) (cong (Iso.inv truncRelIso)))
(isEquivRel→effectiveIso (λ _ _ → PropTrunc.propTruncIsProp) ∥R∥eq a b)
where
open isEquivRel
∥R∥eq : isEquivRel λ a b → ∥ R a b ∥
reflexive ∥R∥eq a = ∣ reflexive Req a ∣
symmetric ∥R∥eq a b = PropTrunc.map (symmetric Req a b)
transitive ∥R∥eq a b c = PropTrunc.map2 (transitive Req a b c)
| 42.62116
| 121
| 0.521701
|
65fd10c7d9defdca94b6c56046c1073e05fe2817
| 322
|
agda
|
Agda
|
src/main/agda/lemmas.agda
|
hablapps/safeoptics
|
90fc9586f4c126ee83b8aa54ad417bb7a5325b1b
|
[
"Apache-2.0"
] | null | null | null |
src/main/agda/lemmas.agda
|
hablapps/safeoptics
|
90fc9586f4c126ee83b8aa54ad417bb7a5325b1b
|
[
"Apache-2.0"
] | null | null | null |
src/main/agda/lemmas.agda
|
hablapps/safeoptics
|
90fc9586f4c126ee83b8aa54ad417bb7a5325b1b
|
[
"Apache-2.0"
] | null | null | null |
{-# OPTIONS --verbose=10 #-}
module lemmas where
open import Data.Nat
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; trans; sym; cong; cong-app; subst)
+-suc : (n₁ n₂ : ℕ) -> (n₁ + (1 + n₂)) ≡ (1 + (n₁ + n₂))
+-suc zero n2 = refl
+-suc (suc n1) n2 rewrite +-suc n1 n2 = refl
| 26.833333
| 62
| 0.60559
|
342e0dffa82548de24ce8323a588fc656b558816
| 519
|
agda
|
Agda
|
test/Succeed/Issue1944-1.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue1944-1.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1944-1.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, AIM XXIII 2016-04-21 Overloaded projections
-- Milestone 1: Check overloaded projections on rhs (without postponing).
module _ (A : Set) (a : A) where
module RecDefs where
record R B : Set where
field f : B
open R public
record S B : Set where
field f : B
open S public
record T B : Set where
field f : B → B
open T public
open RecDefs public
r : R A
R.f r = a
s : S A
S.f s = f r
t : R A → S A
S.f (t r) = f r
u : _
u = f s
v = f s
w : ∀{A} → T A → A → A
w t x = f t x
| 13.307692
| 73
| 0.585742
|
65d164ab9ffbc17b187a94b0cd57a39edf2c0364
| 517
|
agda
|
Agda
|
data/test-files/Prelude.agda
|
carlostome/martin
|
baf979ef78b5ec0f4783240b03f9547490bc5d42
|
[
"BSD-3-Clause"
] | null | null | null |
data/test-files/Prelude.agda
|
carlostome/martin
|
baf979ef78b5ec0f4783240b03f9547490bc5d42
|
[
"BSD-3-Clause"
] | null | null | null |
data/test-files/Prelude.agda
|
carlostome/martin
|
baf979ef78b5ec0f4783240b03f9547490bc5d42
|
[
"BSD-3-Clause"
] | null | null | null |
module Prelude where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
data _==_ {A : Set} (x : A) : A → Set where
refl : x == x
data Vec (A : Set) : Nat -> Set where
nil : Vec A 0
cons : forall {n} -> A -> Vec A n -> Vec A (suc n)
data List (A : Set) : Set where
nil : List A
cons : A -> List A -> List A
data Empty : Set where
data Not (A : Set) : Set where
is-absurd : (A -> Empty) -> Not A
data Dec (A : Set) : Set where
yes : A -> Dec A
no : Not A -> Dec A
| 18.464286
| 52
| 0.545455
|
5e3e42383d855e4e0374f5852d11f4f42f08717f
| 398
|
agda
|
Agda
|
notes/papers/implicit/examples/IllTyped.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
notes/papers/implicit/examples/IllTyped.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
notes/papers/implicit/examples/IllTyped.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module IllTyped where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Bool : Set where
false : Bool
true : Bool
F : Nat -> Set
F zero = Nat
F (suc x) = Bool
postulate
D : (x:Nat)(y:F x) -> Set
T : Nat -> Set
f : {x:Nat -> Nat}{y:F (x zero)} ->
(T (x zero) -> T (suc zero)) ->
(D zero zero -> D (x zero) y) ->
Nat
test = f {?} (\x -> x) (\x -> x)
| 14.214286
| 38
| 0.479899
|
65ed183185df4f7de2708437f0f7fdc9e6239bbf
| 3,515
|
agda
|
Agda
|
prototyping/Luau/TypeCheck.agda
|
morgoth990/luau
|
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
|
[
"MIT"
] | 1
|
2022-03-18T04:10:20.000Z
|
2022-03-18T04:10:20.000Z
|
prototyping/Luau/TypeCheck.agda
|
morgoth990/luau
|
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
|
[
"MIT"
] | null | null | null |
prototyping/Luau/TypeCheck.agda
|
morgoth990/luau
|
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
open import Luau.Type using (Mode)
module Luau.TypeCheck (m : Mode) where
open import Agda.Builtin.Equality using (_≡_)
open import FFI.Data.Maybe using (Maybe; just)
open import Luau.Syntax using (Expr; Stat; Block; BinaryOperator; yes; nil; addr; number; bool; string; val; var; var_∈_; _⟨_⟩∈_; function_is_end; _$_; block_is_end; binexp; local_←_; _∙_; done; return; name; +; -; *; /; <; >; ==; ~=; <=; >=; ··)
open import Luau.Var using (Var)
open import Luau.Addr using (Addr)
open import Luau.Heap using (Heap; Object; function_is_end) renaming (_[_] to _[_]ᴴ)
open import Luau.Type using (Type; Mode; nil; none; number; boolean; string; _⇒_; tgt)
open import Luau.VarCtxt using (VarCtxt; ∅; _⋒_; _↦_; _⊕_↦_; _⊝_) renaming (_[_] to _[_]ⱽ)
open import FFI.Data.Vector using (Vector)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import Properties.Product using (_×_; _,_)
src : Type → Type
src = Luau.Type.src m
orNone : Maybe Type → Type
orNone nothing = none
orNone (just T) = T
tgtBinOp : BinaryOperator → Type
tgtBinOp + = number
tgtBinOp - = number
tgtBinOp * = number
tgtBinOp / = number
tgtBinOp < = boolean
tgtBinOp > = boolean
tgtBinOp == = boolean
tgtBinOp ~= = boolean
tgtBinOp <= = boolean
tgtBinOp >= = boolean
tgtBinOp ·· = string
data _⊢ᴮ_∈_ : VarCtxt → Block yes → Type → Set
data _⊢ᴱ_∈_ : VarCtxt → Expr yes → Type → Set
data _⊢ᴮ_∈_ where
done : ∀ {Γ} →
---------------
Γ ⊢ᴮ done ∈ nil
return : ∀ {M B T U Γ} →
Γ ⊢ᴱ M ∈ T →
Γ ⊢ᴮ B ∈ U →
---------------------
Γ ⊢ᴮ return M ∙ B ∈ T
local : ∀ {x M B T U V Γ} →
Γ ⊢ᴱ M ∈ U →
(Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V →
--------------------------------
Γ ⊢ᴮ local var x ∈ T ← M ∙ B ∈ V
function : ∀ {f x B C T U V W Γ} →
(Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V →
(Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W →
-------------------------------------------------
Γ ⊢ᴮ function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B ∈ W
data _⊢ᴱ_∈_ where
nil : ∀ {Γ} →
--------------------
Γ ⊢ᴱ (val nil) ∈ nil
var : ∀ {x T Γ} →
T ≡ orNone(Γ [ x ]ⱽ) →
----------------
Γ ⊢ᴱ (var x) ∈ T
addr : ∀ {a Γ} T →
-----------------
Γ ⊢ᴱ val(addr a) ∈ T
number : ∀ {n Γ} →
---------------------------
Γ ⊢ᴱ val(number n) ∈ number
bool : ∀ {b Γ} →
--------------------------
Γ ⊢ᴱ val(bool b) ∈ boolean
string : ∀ {x Γ} →
---------------------------
Γ ⊢ᴱ val(string x) ∈ string
app : ∀ {M N T U Γ} →
Γ ⊢ᴱ M ∈ T →
Γ ⊢ᴱ N ∈ U →
----------------------
Γ ⊢ᴱ (M $ N) ∈ (tgt T)
function : ∀ {f x B T U V Γ} →
(Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V →
-----------------------------------------------------
Γ ⊢ᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) ∈ (T ⇒ U)
block : ∀ {b B T U Γ} →
Γ ⊢ᴮ B ∈ U →
------------------------------------
Γ ⊢ᴱ (block var b ∈ T is B end) ∈ T
binexp : ∀ {op Γ M N T U} →
Γ ⊢ᴱ M ∈ T →
Γ ⊢ᴱ N ∈ U →
----------------------------------
Γ ⊢ᴱ (binexp M op N) ∈ tgtBinOp op
data ⊢ᴼ_ : Maybe(Object yes) → Set where
nothing :
---------
⊢ᴼ nothing
function : ∀ {f x T U V B} →
(x ↦ T) ⊢ᴮ B ∈ V →
----------------------------------------------
⊢ᴼ (just function f ⟨ var x ∈ T ⟩∈ U is B end)
⊢ᴴ_ : Heap yes → Set
⊢ᴴ H = ∀ a {O} → (H [ a ]ᴴ ≡ O) → (⊢ᴼ O)
_⊢ᴴᴱ_▷_∈_ : VarCtxt → Heap yes → Expr yes → Type → Set
(Γ ⊢ᴴᴱ H ▷ M ∈ T) = (⊢ᴴ H) × (Γ ⊢ᴱ M ∈ T)
_⊢ᴴᴮ_▷_∈_ : VarCtxt → Heap yes → Block yes → Type → Set
(Γ ⊢ᴴᴮ H ▷ B ∈ T) = (⊢ᴴ H) × (Γ ⊢ᴮ B ∈ T)
| 23.433333
| 246
| 0.455761
|
ccd82eab8df23d5e296cc6df41b362b5f618d3b7
| 11,768
|
agda
|
Agda
|
Examples/Lambda/Proofs.agda
|
LcicC/inference-systems-agda
|
b9043f99e4bf7211db4066a7a943401d127f0c8f
|
[
"MIT"
] | 3
|
2022-03-10T15:53:47.000Z
|
2022-03-25T15:48:52.000Z
|
Examples/Lambda/Proofs.agda
|
LcicC/inference-systems-agda
|
b9043f99e4bf7211db4066a7a943401d127f0c8f
|
[
"MIT"
] | null | null | null |
Examples/Lambda/Proofs.agda
|
LcicC/inference-systems-agda
|
b9043f99e4bf7211db4066a7a943401d127f0c8f
|
[
"MIT"
] | null | null | null |
--------------------------------------------------------------------------------
-- This is part of Agda Inference Systems
{-# OPTIONS --sized-types #-}
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Data.Nat
open import Data.Vec
open import Data.Fin
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.Unit
open import Data.Empty
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Size
open import Codata.Thunk
open import Axiom.ExcludedMiddle
open import Level renaming (zero to ∅ ; suc to ++)
open import is-lib.SInfSys as IS
open import Examples.Lambda.Lambda
open import Examples.Lambda.BigStep renaming (U to BigStepU)
open import Examples.Lambda.SmallStep
module Examples.Lambda.Proofs where
Spec : BigStepU → Set
Spec (e , res x) = e ⇒* term x
Spec (e , div) = ∀{i} → ⇒∞ e i
{- Soundness -}
Spec-val : BigStepU → Set
Spec-val (e , v) = ∀{v'} → v ≡ res v' → Spec (e , v)
Spec-closed : ISClosed (BigStepIS ∪ BigStepCOIS) Spec-val
Spec-closed (inj₁ VAL) _ _ refl = ε
Spec-closed (inj₁ APP) _ prem refl =
let s-e1 = prem zero refl in
let s-e2 = prem (suc zero) refl in
let s-subst = prem (suc (suc zero)) refl in
let subst = IS.fold (β , _ , refl , λ ()) in
inj-l-app _ (prem zero refl) ◅◅ inj-r-app _ (prem (suc zero) refl) ◅◅ subst ◅ prem (suc (suc zero)) refl
Spec-closed (inj₂ COA) s_ _ ()
⇓ᵢ-to-⇒* : ∀{e v} → e ⇓ᵢ v → Spec-val (e , v)
⇓ᵢ-to-⇒* = ind[ BigStepIS ∪ BigStepCOIS ] Spec-val Spec-closed
bs-sound-v : ∀{e v} → (∀{i} → (e ⇓ (res v)) i) → e ⇒* (term v)
bs-sound-v r = ⇓ᵢ-to-⇒* (sfcoind-to-ind r) refl
subject-red-⇓ : ∀{e e' v} → (∀{i} → (e ⇓ v) i) → e ⇒ e' → (∀{i} → (e' ⇓ v) i)
subject-red-⇓ bs (fold (β , (e , v) , eq , _)) with bs
subject-red-⇓ bs (fold (β , (e , v) , () , _)) | sfold (VAL , (lambda x , _) , refl , prem)
subject-red-⇓ bs (fold (β , (e , lambda x) , refl , _)) | sfold (APP , ((.(lambda e) , _ , .(lambda x) , v , _) , _) , refl , prem)
with val-⇓-≡ (prem zero .force) | val-⇓-≡ (prem (suc zero) .force)
subject-red-⇓ bs (fold (β , (e , lambda x) , refl , _)) | sfold (APP , ((.(lambda e) , .e , .(lambda x) , .(lambda x) , _) , _) , refl , prem) | refl | refl = prem (suc (suc zero)) .force
subject-red-⇓ bs (fold (β , (e , v) , refl , _)) | sfold (L-DIV , _ , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem zero .force))
subject-red-⇓ bs (fold (β , (e , v) , refl , _)) | sfold (R-DIV , _ , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem (suc zero) .force))
subject-red-⇓ bs (fold (L-APP , c , eq , _)) with bs
subject-red-⇓ bs (fold (L-APP , _ , () , _)) | sfold (VAL , (lambda _ , _) , refl , _)
subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (APP , ((.e1 , e1'' , .e2 , lambda _ , _) , ind) , refl , prem) =
let rec = subject-red-⇓ (prem zero .force) (pr zero) in
let prems = λ{zero → rec ; (suc zero) → prem (suc zero) .force ; (suc (suc zero)) → prem (suc (suc zero)) .force} in
apply-sfcoind APP _ prems
subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (L-DIV , ((.e1 , .e2) , ind) , refl , prem) =
let rec = subject-red-⇓ (prem zero .force) (pr zero) in
apply-sfcoind L-DIV _ λ{zero → rec}
subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (R-DIV , ((.e1 , .e2 , lambda v) , ind) , refl , prem) =
let rec = subject-red-⇓ (prem zero .force) (pr zero) in
let prems = λ{zero → rec ; (suc zero) → prem (suc zero) .force} in
apply-sfcoind R-DIV _ prems
subject-red-⇓ bs (fold (R-APP , (lambda _ , e2 , e2') , eq , pr)) with bs
subject-red-⇓ bs (fold (R-APP , (lambda _ , _ , _) , refl , _)) | sfold (VAL , (lambda _ , _) , () , _)
subject-red-⇓ bs (fold (R-APP , (lambda e1 , e2 , e2') , refl , pr)) | sfold (APP , ((.(lambda _) , e1' , .e2 , lambda _ , _) , ind) , refl , prem)
with val-⇓-≡ (prem zero .force)
subject-red-⇓ bs (fold (R-APP , (lambda e1 , e2 , e2') , refl , pr)) | sfold (APP , ((.(lambda e1) , .e1 , .e2 , lambda _ , _) , ind) , refl , prem) | refl =
let rec = subject-red-⇓ (prem (suc zero) .force) (pr zero) in
let prems = λ{zero → prem zero .force ; (suc zero) → rec ; (suc (suc zero)) → prem (suc (suc zero)) .force} in
apply-sfcoind APP _ prems
subject-red-⇓ bs (fold (R-APP , (lambda _ , e2 , e2') , refl , _)) | sfold (L-DIV , ((.(lambda _) , .e2) , _) , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem zero .force))
subject-red-⇓ bs (fold (R-APP , (lambda e , e2 , e2') , refl , pr)) | sfold (R-DIV , ((.(lambda e) , .e2 , v) , ind) , refl , prem) with val-⇓-≡ (prem zero .force)
subject-red-⇓ bs (fold (R-APP , (lambda e , e2 , e2') , refl , pr)) | sfold (R-DIV , ((.(lambda e) , .e2 , .(lambda e)) , ind) , refl , prem) | refl =
let rec = subject-red-⇓ (prem (suc zero) .force) (pr zero) in
let prems = λ{zero → prem zero .force ; (suc zero) → rec} in
apply-sfcoind R-DIV _ prems
progress : ∀{e} →(∀{i} → (e ⇓ div) i) → Σ[ e' ∈ Term 0 ] (e ⇒ e')
progress {e} bs with bs
progress bs | sfold (APP , _ , refl , prem) with bs-sound-v (prem zero .force)
progress bs | sfold (APP , ((_ , e1' , _ , _ , .div) , _) , refl , prem) | ε with bs-sound-v (prem (suc zero) .force)
progress bs | sfold (APP , ((.(lambda e1') , e1' , _ , v , .div) , _) , refl , prem) | ε | ε =
_ , apply-ind β _ λ ()
progress bs | sfold (APP , ((.(lambda e1') , e1' , e2 , _ , .div) , _) , refl , prem) | ε | x ◅ _ =
app (lambda e1') _ , apply-ind R-APP _ λ{zero → x}
progress bs | sfold (APP , ((e1 , _ , e2 , _ , .div) , _) , refl , prem) | x ◅ _ =
app _ e2 , apply-ind L-APP _ λ{zero → x}
progress bs | sfold (L-DIV , ((e1 , e2) , _) , refl , prem) =
let e1' , e1⇒e1' = progress (prem zero .force) in
app e1' e2 , apply-ind L-APP _ λ{zero → e1⇒e1'}
progress bs | sfold (R-DIV , ((e1 , e2 , v) , _) , refl , prem) with bs-sound-v (prem zero .force)
progress bs | sfold (R-DIV , ((.(term _) , e2 , (lambda e)) , _) , refl , prem) | ε =
let e2' , e2⇒e2' = progress (prem (suc zero) .force) in
app (lambda e) e2' , apply-ind R-APP _ λ{zero → e2⇒e2'}
progress bs | sfold (R-DIV , ((e1 , e2 , (lambda e)) , _) , refl , prem) | x ◅ _ =
app _ e2 , apply-ind L-APP _ λ{zero → x}
bs-sound-∞ : ∀{e} → (∀{i} → (e ⇓ div) i) → (∀{i} → ⇒∞ e i)
bs-sound-∞ bs with progress bs
... | e' , ss = step ss λ where .force → bs-sound-∞ (subject-red-⇓ bs ss)
bs-sound : ∀{e v} → (∀{i} → (e ⇓ v) i) → Spec (e , v)
bs-sound {_} {res _} = bs-sound-v
bs-sound {_} {div} = bs-sound-∞
{- Completeness -}
inv-app : ∀{e1 e2 v} → (app e1 e2) ⇓ᵢ (res v) →
Σ[ e1' ∈ Term 1 ] Σ[ e2' ∈ Value ]
(e1 ⇓ᵢ res (lambda e1')) ×
(e2 ⇓ᵢ (res e2')) ×
(subst-0 e1' (term e2') ⇓ᵢ res v)
-- Using consistency of inductive interpretation
inv-app bs with ind-postfix bs
inv-app bs | inj₁ VAL , lambda _ , () , _
inv-app bs | inj₁ APP , _ , refl , pr = _ , _ , pr zero , pr (suc zero) , pr (suc (suc zero))
inv-app bs | inj₂ COA , _ , () , _
subject-exp : ∀{e e' v} → e ⇒ e' → e' ⇓ᵢ v → e ⇓ᵢ v
subject-exp {.(app (lambda e1) (term v))} {_} {v'} (fold (β , (e1 , v) , refl , _)) bs =
let prem-e1 = IS.fold (inj₁ VAL , lambda e1 , refl , λ ()) in
let prem-e2 = IS.fold (inj₁ VAL , v , refl , λ ()) in
let prems = λ{zero → prem-e1 ; (suc zero) → prem-e2 ; (suc (suc zero)) → bs} in
apply-ind (inj₁ APP) _ prems
subject-exp {.(app e1 e2)} {.(app e1' e2)} {res x} (fold (L-APP , (e1 , e1' , e2) , refl , pr)) bs =
let e1'' , e2' , bs-e1' , bs-e2 , bs-subst = inv-app bs in
let prems = λ{zero → subject-exp (pr zero) bs-e1' ; (suc zero) → bs-e2 ; (suc (suc zero)) → bs-subst} in
apply-ind (inj₁ APP) _ prems
subject-exp {.(app e1 e2)} {.(app e1' e2)} {div} (fold (L-APP , (e1 , e1' , e2) , refl , pr)) bs =
apply-ind (inj₂ COA) _ λ ()
subject-exp {.(app (term v) e2)} {.(app (term v) e2')} {res x} (fold (R-APP , (v , e2 , e2') , refl , pr)) bs =
let e1' , e2'' , bs-e1 , bs-e2' , bs-subst = inv-app bs in
let prems = λ{zero → bs-e1 ; (suc zero) → subject-exp (pr zero) bs-e2' ; (suc (suc zero)) → bs-subst} in
apply-ind (inj₁ APP) _ prems
subject-exp {.(app (term v) e2)} {.(app (term v) e2')} {div} (fold (R-APP , (v , e2 , e2') , refl , _)) bs =
apply-ind (inj₂ COA) _ λ ()
bounded-v : ∀{e v} → e ⇒* term v → e ⇓ᵢ res v
bounded-v ε = apply-ind (inj₁ VAL) _ λ ()
bounded-v (x ◅ ss) = subject-exp x (bounded-v ss)
bounded-∞ : ∀{e} → (∀{i} → ⇒∞ e i) → e ⇓ᵢ div
bounded-∞ {e} ss = apply-ind (inj₂ COA) _ λ ()
bounded : ∀{e v} → Spec (e , v) → e ⇓ᵢ v
bounded {_} {res _} = bounded-v
bounded {_} {div} = bounded-∞
get-prem-cons : ∀{e1 e2 v} → app e1 e2 ⇒* (term v) →
Σ[ e1' ∈ Term 1 ] Σ[ e2' ∈ Value ]
(e1 ⇒* lambda e1') ×
(e2 ⇒* term e2') ×
(subst-0 e1' (term e2') ⇒* (term v))
get-prem-cons {.(lambda e1)} {.(term v)} {lambda _} (fold (β , (e1 , v) , refl , _) ◅ ss) =
e1 , v , ε , ε , ss
get-prem-cons {.e1} {.e2} {lambda _} (fold (L-APP , (e1 , e1' , e2) , refl , pr) ◅ ss) =
let e1'' , e2' , rec-e1' , rec-e2 , rec-subst = get-prem-cons ss in
e1'' , e2' , pr zero ◅ rec-e1' , rec-e2 , rec-subst
get-prem-cons {.(term v)} {.e2} {lambda _} (fold (R-APP , (v , e2 , e2') , refl , pr) ◅ ss) =
let e1' , e2'' , rec-e1 , rec-e2' , rec-subst = get-prem-cons ss in
e1' , e2'' , rec-e1 , pr zero ◅ rec-e2' , rec-subst
consistent-v : ∀{e v} → e ⇒* term v → IS.ISF[ BigStepIS ] Spec (e , res v)
consistent-v {.(lambda _)} {lambda _} ε = VAL , _ , refl , λ ()
consistent-v {lambda _} {lambda _} (x ◅ ss) = ⊥-elim (val-not-reduce⇒ x)
consistent-v {app e1 e2} {lambda _} (x ◅ ss) =
let e1' , e2' , e1⇒* , e2⇒* , subst⇒* = get-prem-cons (x ◅ ss) in
let prems = λ{zero → e1⇒* ; (suc zero) → e2⇒* ; (suc (suc zero)) → subst⇒*} in
APP , (e1 , e1' , e2 , e2' , _) , refl , prems
postulate
excluded-middle : ExcludedMiddle ∅
lemma-divergence : ∀{e1 e2} → (∀{i} → ⇒∞ (app e1 e2) i) →
(∀{i} → ⇒∞ e1 i) ⊎
e1 ConvergesSS × (∀{i} → ⇒∞ e2 i) ⊎
Σ[ t1 ∈ Term 1 ] Σ[ v ∈ Value ] (e1 ⇒* lambda t1) × (e2 ⇒* term v) × (∀{i} → ⇒∞ (subst-0 t1 (term v)) i)
lemma-divergence {e1} {e2} ss with excluded-middle {e1 ConvergesSS}
lemma-divergence {e1} {e2} ss | no ¬e1-conv = inj₁ (div-app-l-not-conv ss ¬e1-conv)
lemma-divergence {e1} {e2} ss | yes e1-conv with excluded-middle {e2 ConvergesSS}
lemma-divergence {e1} {e2} ss | yes e1-conv | no ¬e2-conv =
inj₂ (inj₁ (e1-conv , div-app-r-not-conv ss (proj₂ e1-conv) ¬e2-conv))
lemma-divergence {e1} {e2} ss | yes (lambda _ , red-e1) | yes (_ , red-e2) =
inj₂ (inj₂ (_ , _ , ( red-e1 , red-e2 , app-subst-⇒∞₁ red-e1 red-e2 ss)))
consistent-∞ : ∀{e} → (∀{i} → ⇒∞ e i) → IS.ISF[ BigStepIS ] Spec (e , div)
consistent-∞ {e} ss with ss
consistent-∞ {lambda e} ss | step x _ = ⊥-elim (val-not-reduce⇒ x)
consistent-∞ {app e₁ e₂} ss | step x x₁ with lemma-divergence (step x x₁)
consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₁ e1-div =
L-DIV , _ , refl , λ{zero → e1-div}
consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₂ (inj₁ (e1-conv , e2-div)) =
R-DIV , _ , refl , λ{zero → proj₂ e1-conv ; (suc zero) → e2-div}
consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₂ (inj₂ (_ , _ , red-e1 , red-e2 , subst-div)) =
APP , _ , refl , λ{zero → red-e1 ; (suc zero) → red-e2 ; (suc (suc zero)) → subst-div}
consistent : ∀{e v} → Spec (e , v) → IS.ISF[ BigStepIS ] Spec (e , v)
consistent {_} {res _} = consistent-v
consistent {_} {div} = consistent-∞
complete : ∀{e v} → Spec (e , v) → (∀{i} → (e ⇓ v) i)
complete = bounded-scoind[ BigStepIS , BigStepCOIS ] Spec bounded consistent
| 54.990654
| 189
| 0.543168
|
018866b9818becc3dc626aa9a9f476b01d04e9dc
| 414
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Symmetrical/Symmetry.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Symmetrical/Symmetry.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/Symmetrical/Symmetry.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class.Symmetry
open import Oscar.Class.Symmetrical
import Oscar.Data.Proposequality
module Oscar.Class.Symmetrical.Symmetry where
module _
{𝔬} {𝔒 : Ø 𝔬}
{ℓ} {_∼_ : 𝔒 → 𝔒 → Ø ℓ}
⦃ _ : Symmetry.class _∼_ ⦄
where
instance
Symmetrical𝓢ymmetry : Symmetrical _∼_ (λ x∼y y∼x → x∼y → y∼x)
Symmetrical𝓢ymmetry .𝓢ymmetrical.symmetrical _ _ = symmetry
| 21.789474
| 65
| 0.698068
|
196b6a1ae1e2f5626639ee16cfc3457b087d7ad9
| 1,712
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Axiom/Extensionality/Propositional.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Axiom/Extensionality/Propositional.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Axiom/Extensionality/Propositional.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Results concerning function extensionality for propositional equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Axiom.Extensionality.Propositional where
open import Function
open import Level using (Level; _⊔_; suc; lift)
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality.Core
------------------------------------------------------------------------
-- Function extensionality states that if two functions are
-- propositionally equal for every input, then the functions themselves
-- must be propositionally equal.
Extensionality : (a b : Level) → Set _
Extensionality a b =
{A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
(∀ x → f x ≡ g x) → f ≡ g
------------------------------------------------------------------------
-- Properties
-- If extensionality holds for a given universe level, then it also
-- holds for lower ones.
lower-extensionality : ∀ {a₁ b₁} a₂ b₂ →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
Extensionality a₁ b₁
lower-extensionality a₂ b₂ ext f≡g = cong (λ h → Level.lower ∘ h ∘ lift) $
ext (cong (lift {ℓ = b₂}) ∘ f≡g ∘ Level.lower {ℓ = a₂})
-- Functional extensionality implies a form of extensionality for
-- Π-types.
∀-extensionality : ∀ {a b} → Extensionality a (suc b) →
{A : Set a} (B₁ B₂ : A → Set b) →
(∀ x → B₁ x ≡ B₂ x) →
(∀ x → B₁ x) ≡ (∀ x → B₂ x)
∀-extensionality ext B₁ B₂ B₁≡B₂ with ext B₁≡B₂
∀-extensionality ext B .B B₁≡B₂ | refl = refl
| 36.425532
| 74
| 0.521028
|
ed87c2d855d98deb56efdd1524456133d0e1996e
| 3,903
|
agda
|
Agda
|
lib/prelude.agda
|
siddharthist/hs2agda
|
4172bef9f4eede7e45dc002a70bf8c6dd9a56b5c
|
[
"MIT"
] | 17
|
2016-10-25T10:07:49.000Z
|
2016-10-25T19:54:48.000Z
|
lib/prelude.agda
|
siddharthist/CoverTranslator
|
4172bef9f4eede7e45dc002a70bf8c6dd9a56b5c
|
[
"MIT"
] | 6
|
2016-10-25T02:27:55.000Z
|
2016-10-25T17:50:18.000Z
|
lib/prelude.agda
|
siddharthist/CoverTranslator
|
4172bef9f4eede7e45dc002a70bf8c6dd9a56b5c
|
[
"MIT"
] | null | null | null |
-- BEGIN prelude.agda
-- the Haskell $ and .
($) (A::Set) (B::Set) (f :: A -> B) (a :: A) :: B
= f a
compose (B,C,A::Set)(f :: B -> C)(g :: A -> B) :: A -> C
= \ (x::A) -> f (g x)
{- hardwired into Agda
Integer :: Set
= ?
Bool :: Set
= data True | False
-}
not (b::Bool) :: Bool
= case b of {
(True) -> False; -- Agda does not require @_ for built-in constructors
(False) -> True;}
(||) (b1::Bool)(b2::Bool) :: Bool
= case b1 of {
(True) -> True@_;
(False) ->
case b2 of {
(True) -> True@_;
(False) -> False@_;};}
(&&) (b1::Bool)(b2::Bool) :: Bool
= case b1 of {
(True) ->
case b2 of {
(True) -> False@_;
(False) -> True@_;};
(False) -> False@_;}
Pair (a::Set)(b::Set) :: Set
= data Pair (x::a) (y::b)
Triple (a::Set)(b::Set)(c::Set) :: Set
= data Triple (x::a) (y::b) (z::c)
flip (a::Set)(b::Set)(c::Set)(f::a -> b -> c)(x::b)(y::a) :: c
= f y x
{- hardwired into Agda:
List (a::Set) :: Set
= data Nil | (:) (x::a) (xs::List a)
-}
foldl (a::Set)(b::Set)(f::a -> b -> a)(acc::a)(l::List b) :: a
= case l of {
(Nil) -> acc;
(x:xs) -> foldl a b f (f acc x) xs;}
reverse (a::Set)(l::List a) :: List a
= foldl (List a) a
(flip a (List a) (List a) (\(h::a) -> \(h'::List a) -> (:)@_ h h'))
Nil@_
l
append (a::Set)(l1::List a)(l2::List a) :: List a
= case l1 of {
(Nil) -> l2;
(x:xs) -> x : (append a xs l2);}
null (a::Set)(l::List a) :: Bool
= case l of {
(Nil) -> True@_;
(x:xs) -> False@_;}
map (a,b::Set)(f::a -> b)(l::List a) :: List b
= case l of
(Nil) -> Nil
(x:xs) -> f x : map a b f xs
Maybe (a::Set) :: Set
= data Nothing | Just (x::a)
-- Should not be here - temporary addition to provide an "interesting" type
-- data Simple = A | B | C -gone
-- Properties
-- naive implementation of Property.hs
-- from SET.alfa
Rel (X::Set) :: Type
= X -> X -> Set
Id (X::Set) :: Rel X
= idata ref (x::X) :: _ x x
Zero :: Set
= data
whenZero (X::Set)(z::Zero) :: X
= case z of { }
Unit :: Set
= data tt
Sum (X::Set)(Y::X -> Set) :: Set
= sig{fst :: X;
snd :: Y fst;}
Plus (X::Set)(Y::Set) :: Set
= data inl (x::X) | inr (y::Y)
package Property where
Prop :: Type
= Set
(===) (A :: Set) (a :: A) (b :: A) :: Prop
= Id A a b
-- translate forAll into a dependent function type
forAll (A :: Set) (f :: A -> Prop) :: Prop
= (x :: A) -> f x
exists (A :: Set) (f :: A -> Prop) :: Prop
= sig { witness :: A;
prop :: f witness; }
(/\) (A,B :: Prop) :: Prop
= Sum A (\(a::A) -> B)
(\/) (A,B :: Prop) :: Prop
= Plus A B
(<=>) (A,B :: Prop) :: Prop
= (A -> B) /\ (B -> A)
(==>) (A,B :: Prop) :: Prop
= (A -> B)
true :: Prop
= Unit
false :: Prop
= Zero
nt (A :: Prop) :: Prop
= A -> false
-- cannot do the naive using because of universe conflict
-- List cannot have a parameter which is not a set, and Prop is a type
--using (L :: List Prop) (A :: Prop) :: Prop
-- = A
holds (b::Bool) :: Prop
= if b then true else false
holdsNot (b::Bool) :: Prop
= if b then false else true
-- Class of inhabited types
class Inhabited (a::Set) :: Set exports
arbitrary :: a
error (a::Set)(|ia::Inhabited a)(msg::String) :: a
= arbitrary
-- Prelude types are inhabited
instance iBool :: Inhabited Bool where
arbitrary = True
instance iString :: Inhabited String where
arbitrary = "I AM ARBITRARY"
instance iInteger :: Inhabited Integer where
arbitrary = 123456789
{- Syntax error:
instance iRational :: Inhabited Rational where
arbitrary = 0.123456789
-}
instance iList (|a::Set) :: Inhabited (List a) where
arbitrary = Nil
-- instance iList (a::Set)(ia::Inhabited a) :: Inhabited (List a) where
-- END prelude.agda
| 20.542105
| 77
| 0.498078
|
7c66fe00a606a5a1430f63b1e16de93f127ae7c6
| 166
|
agda
|
Agda
|
Cubical/Relation/Nullary/DecidableEq.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Relation/Nullary/DecidableEq.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Relation/Nullary/DecidableEq.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Relation.Nullary.DecidableEq where
open import Cubical.Relation.Nullary.Properties
using (Dec→Stable; Discrete→isSet) public
| 27.666667
| 49
| 0.783133
|
cc6bb5c15810d884f172c90e26aa12c6c6e3588d
| 15,824
|
agda
|
Agda
|
prototyping/Properties/Subtyping.agda
|
EtiTheSpirit/luau
|
d37d0c857ba543ea47f0b8fce5678f7aadf5239e
|
[
"MIT"
] | null | null | null |
prototyping/Properties/Subtyping.agda
|
EtiTheSpirit/luau
|
d37d0c857ba543ea47f0b8fce5678f7aadf5239e
|
[
"MIT"
] | null | null | null |
prototyping/Properties/Subtyping.agda
|
EtiTheSpirit/luau
|
d37d0c857ba543ea47f0b8fce5678f7aadf5239e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Properties.Subtyping where
open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.Either using (Either; Left; Right; mapLR; swapLR; cond)
open import Luau.Subtyping using (_<:_; _≮:_; Tree; Language; ¬Language; witness; unknown; never; scalar; function; scalar-function; scalar-function-ok; scalar-function-err; scalar-scalar; function-scalar; function-ok; function-err; left; right; _,_)
open import Luau.Type using (Type; Scalar; strict; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_; tgt)
open import Properties.Contradiction using (CONTRADICTION; ¬)
open import Properties.Equality using (_≢_)
open import Properties.Functions using (_∘_)
open import Properties.Product using (_×_; _,_)
src = Luau.Type.src strict
-- Language membership is decidable
dec-language : ∀ T t → Either (¬Language T t) (Language T t)
dec-language nil (scalar number) = Left (scalar-scalar number nil (λ ()))
dec-language nil (scalar boolean) = Left (scalar-scalar boolean nil (λ ()))
dec-language nil (scalar string) = Left (scalar-scalar string nil (λ ()))
dec-language nil (scalar nil) = Right (scalar nil)
dec-language nil function = Left (scalar-function nil)
dec-language nil (function-ok t) = Left (scalar-function-ok nil)
dec-language nil (function-err t) = Right (scalar-function-err nil)
dec-language boolean (scalar number) = Left (scalar-scalar number boolean (λ ()))
dec-language boolean (scalar boolean) = Right (scalar boolean)
dec-language boolean (scalar string) = Left (scalar-scalar string boolean (λ ()))
dec-language boolean (scalar nil) = Left (scalar-scalar nil boolean (λ ()))
dec-language boolean function = Left (scalar-function boolean)
dec-language boolean (function-ok t) = Left (scalar-function-ok boolean)
dec-language boolean (function-err t) = Right (scalar-function-err boolean)
dec-language number (scalar number) = Right (scalar number)
dec-language number (scalar boolean) = Left (scalar-scalar boolean number (λ ()))
dec-language number (scalar string) = Left (scalar-scalar string number (λ ()))
dec-language number (scalar nil) = Left (scalar-scalar nil number (λ ()))
dec-language number function = Left (scalar-function number)
dec-language number (function-ok t) = Left (scalar-function-ok number)
dec-language number (function-err t) = Right (scalar-function-err number)
dec-language string (scalar number) = Left (scalar-scalar number string (λ ()))
dec-language string (scalar boolean) = Left (scalar-scalar boolean string (λ ()))
dec-language string (scalar string) = Right (scalar string)
dec-language string (scalar nil) = Left (scalar-scalar nil string (λ ()))
dec-language string function = Left (scalar-function string)
dec-language string (function-ok t) = Left (scalar-function-ok string)
dec-language string (function-err t) = Right (scalar-function-err string)
dec-language (T₁ ⇒ T₂) (scalar s) = Left (function-scalar s)
dec-language (T₁ ⇒ T₂) function = Right function
dec-language (T₁ ⇒ T₂) (function-ok t) = mapLR function-ok function-ok (dec-language T₂ t)
dec-language (T₁ ⇒ T₂) (function-err t) = mapLR function-err function-err (swapLR (dec-language T₁ t))
dec-language never t = Left never
dec-language unknown t = Right unknown
dec-language (T₁ ∪ T₂) t = cond (λ p → cond (Left ∘ _,_ p) (Right ∘ right) (dec-language T₂ t)) (Right ∘ left) (dec-language T₁ t)
dec-language (T₁ ∩ T₂) t = cond (Left ∘ left) (λ p → cond (Left ∘ right) (Right ∘ _,_ p) (dec-language T₂ t)) (dec-language T₁ t)
-- ¬Language T is the complement of Language T
language-comp : ∀ {T} t → ¬Language T t → ¬(Language T t)
language-comp t (p₁ , p₂) (left q) = language-comp t p₁ q
language-comp t (p₁ , p₂) (right q) = language-comp t p₂ q
language-comp t (left p) (q₁ , q₂) = language-comp t p q₁
language-comp t (right p) (q₁ , q₂) = language-comp t p q₂
language-comp (scalar s) (scalar-scalar s p₁ p₂) (scalar s) = p₂ refl
language-comp (scalar s) (function-scalar s) (scalar s) = language-comp function (scalar-function s) function
language-comp (scalar s) never (scalar ())
language-comp function (scalar-function ()) function
language-comp (function-ok t) (scalar-function-ok ()) (function-ok q)
language-comp (function-ok t) (function-ok p) (function-ok q) = language-comp t p q
language-comp (function-err t) (function-err p) (function-err q) = language-comp t q p
-- ≮: is the complement of <:
¬≮:-impl-<: : ∀ {T U} → ¬(T ≮: U) → (T <: U)
¬≮:-impl-<: {T} {U} p t q with dec-language U t
¬≮:-impl-<: {T} {U} p t q | Left r = CONTRADICTION (p (witness t q r))
¬≮:-impl-<: {T} {U} p t q | Right r = r
<:-impl-¬≮: : ∀ {T U} → (T <: U) → ¬(T ≮: U)
<:-impl-¬≮: p (witness t q r) = language-comp t r (p t q)
-- reflexivity
≮:-refl : ∀ {T} → ¬(T ≮: T)
≮:-refl (witness t p q) = language-comp t q p
<:-refl : ∀ {T} → (T <: T)
<:-refl = ¬≮:-impl-<: ≮:-refl
-- transititivity
≮:-trans-≡ : ∀ {S T U} → (S ≮: T) → (T ≡ U) → (S ≮: U)
≮:-trans-≡ p refl = p
≡-trans-≮: : ∀ {S T U} → (S ≡ T) → (T ≮: U) → (S ≮: U)
≡-trans-≮: refl p = p
≮:-trans : ∀ {S T U} → (S ≮: U) → Either (S ≮: T) (T ≮: U)
≮:-trans {T = T} (witness t p q) = mapLR (witness t p) (λ z → witness t z q) (dec-language T t)
<:-trans : ∀ {S T U} → (S <: T) → (T <: U) → (S <: U)
<:-trans p q = ¬≮:-impl-<: (cond (<:-impl-¬≮: p) (<:-impl-¬≮: q) ∘ ≮:-trans)
-- Properties of scalars
skalar = number ∪ (string ∪ (nil ∪ boolean))
function-≮:-scalar : ∀ {S T U} → (Scalar U) → ((S ⇒ T) ≮: U)
function-≮:-scalar s = witness function function (scalar-function s)
scalar-≮:-function : ∀ {S T U} → (Scalar U) → (U ≮: (S ⇒ T))
scalar-≮:-function s = witness (scalar s) (scalar s) (function-scalar s)
unknown-≮:-scalar : ∀ {U} → (Scalar U) → (unknown ≮: U)
unknown-≮:-scalar s = witness (function-ok (scalar s)) unknown (scalar-function-ok s)
scalar-≮:-never : ∀ {U} → (Scalar U) → (U ≮: never)
scalar-≮:-never s = witness (scalar s) (scalar s) never
scalar-≢-impl-≮: : ∀ {T U} → (Scalar T) → (Scalar U) → (T ≢ U) → (T ≮: U)
scalar-≢-impl-≮: s₁ s₂ p = witness (scalar s₁) (scalar s₁) (scalar-scalar s₁ s₂ p)
-- Properties of tgt
tgt-function-ok : ∀ {T t} → (Language (tgt T) t) → Language T (function-ok t)
tgt-function-ok {T = nil} (scalar ())
tgt-function-ok {T = T₁ ⇒ T₂} p = function-ok p
tgt-function-ok {T = never} (scalar ())
tgt-function-ok {T = unknown} p = unknown
tgt-function-ok {T = boolean} (scalar ())
tgt-function-ok {T = number} (scalar ())
tgt-function-ok {T = string} (scalar ())
tgt-function-ok {T = T₁ ∪ T₂} (left p) = left (tgt-function-ok p)
tgt-function-ok {T = T₁ ∪ T₂} (right p) = right (tgt-function-ok p)
tgt-function-ok {T = T₁ ∩ T₂} (p₁ , p₂) = (tgt-function-ok p₁ , tgt-function-ok p₂)
function-ok-tgt : ∀ {T t} → Language T (function-ok t) → (Language (tgt T) t)
function-ok-tgt (function-ok p) = p
function-ok-tgt (left p) = left (function-ok-tgt p)
function-ok-tgt (right p) = right (function-ok-tgt p)
function-ok-tgt (p₁ , p₂) = (function-ok-tgt p₁ , function-ok-tgt p₂)
function-ok-tgt unknown = unknown
skalar-function-ok : ∀ {t} → (¬Language skalar (function-ok t))
skalar-function-ok = (scalar-function-ok number , (scalar-function-ok string , (scalar-function-ok nil , scalar-function-ok boolean)))
skalar-scalar : ∀ {T} (s : Scalar T) → (Language skalar (scalar s))
skalar-scalar number = left (scalar number)
skalar-scalar boolean = right (right (right (scalar boolean)))
skalar-scalar string = right (left (scalar string))
skalar-scalar nil = right (right (left (scalar nil)))
tgt-never-≮: : ∀ {T U} → (tgt T ≮: U) → (T ≮: (skalar ∪ (never ⇒ U)))
tgt-never-≮: (witness t p q) = witness (function-ok t) (tgt-function-ok p) (skalar-function-ok , function-ok q)
never-tgt-≮: : ∀ {T U} → (T ≮: (skalar ∪ (never ⇒ U))) → (tgt T ≮: U)
never-tgt-≮: (witness (scalar s) p (q₁ , q₂)) = CONTRADICTION (≮:-refl (witness (scalar s) (skalar-scalar s) q₁))
never-tgt-≮: (witness function p (q₁ , scalar-function ()))
never-tgt-≮: (witness (function-ok t) p (q₁ , function-ok q₂)) = witness t (function-ok-tgt p) q₂
never-tgt-≮: (witness (function-err (scalar s)) p (q₁ , function-err (scalar ())))
-- Properties of src
function-err-src : ∀ {T t} → (¬Language (src T) t) → Language T (function-err t)
function-err-src {T = nil} never = scalar-function-err nil
function-err-src {T = T₁ ⇒ T₂} p = function-err p
function-err-src {T = never} (scalar-scalar number () p)
function-err-src {T = never} (scalar-function-ok ())
function-err-src {T = unknown} never = unknown
function-err-src {T = boolean} p = scalar-function-err boolean
function-err-src {T = number} p = scalar-function-err number
function-err-src {T = string} p = scalar-function-err string
function-err-src {T = T₁ ∪ T₂} (left p) = left (function-err-src p)
function-err-src {T = T₁ ∪ T₂} (right p) = right (function-err-src p)
function-err-src {T = T₁ ∩ T₂} (p₁ , p₂) = function-err-src p₁ , function-err-src p₂
¬function-err-src : ∀ {T t} → (Language (src T) t) → ¬Language T (function-err t)
¬function-err-src {T = nil} (scalar ())
¬function-err-src {T = T₁ ⇒ T₂} p = function-err p
¬function-err-src {T = never} unknown = never
¬function-err-src {T = unknown} (scalar ())
¬function-err-src {T = boolean} (scalar ())
¬function-err-src {T = number} (scalar ())
¬function-err-src {T = string} (scalar ())
¬function-err-src {T = T₁ ∪ T₂} (p₁ , p₂) = (¬function-err-src p₁ , ¬function-err-src p₂)
¬function-err-src {T = T₁ ∩ T₂} (left p) = left (¬function-err-src p)
¬function-err-src {T = T₁ ∩ T₂} (right p) = right (¬function-err-src p)
src-¬function-err : ∀ {T t} → Language T (function-err t) → (¬Language (src T) t)
src-¬function-err {T = nil} p = never
src-¬function-err {T = T₁ ⇒ T₂} (function-err p) = p
src-¬function-err {T = never} (scalar-function-err ())
src-¬function-err {T = unknown} p = never
src-¬function-err {T = boolean} p = never
src-¬function-err {T = number} p = never
src-¬function-err {T = string} p = never
src-¬function-err {T = T₁ ∪ T₂} (left p) = left (src-¬function-err p)
src-¬function-err {T = T₁ ∪ T₂} (right p) = right (src-¬function-err p)
src-¬function-err {T = T₁ ∩ T₂} (p₁ , p₂) = (src-¬function-err p₁ , src-¬function-err p₂)
src-¬scalar : ∀ {S T t} (s : Scalar S) → Language T (scalar s) → (¬Language (src T) t)
src-¬scalar number (scalar number) = never
src-¬scalar boolean (scalar boolean) = never
src-¬scalar string (scalar string) = never
src-¬scalar nil (scalar nil) = never
src-¬scalar s (left p) = left (src-¬scalar s p)
src-¬scalar s (right p) = right (src-¬scalar s p)
src-¬scalar s (p₁ , p₂) = (src-¬scalar s p₁ , src-¬scalar s p₂)
src-¬scalar s unknown = never
src-unknown-≮: : ∀ {T U} → (T ≮: src U) → (U ≮: (T ⇒ unknown))
src-unknown-≮: (witness t p q) = witness (function-err t) (function-err-src q) (¬function-err-src p)
unknown-src-≮: : ∀ {S T U} → (U ≮: S) → (T ≮: (U ⇒ unknown)) → (U ≮: src T)
unknown-src-≮: (witness t x x₁) (witness (scalar s) p (function-scalar s)) = witness t x (src-¬scalar s p)
unknown-src-≮: r (witness (function-ok (scalar s)) p (function-ok (scalar-scalar s () q)))
unknown-src-≮: r (witness (function-ok (function-ok _)) p (function-ok (scalar-function-ok ())))
unknown-src-≮: r (witness (function-err t) p (function-err q)) = witness t q (src-¬function-err p)
-- Properties of unknown and never
unknown-≮: : ∀ {T U} → (T ≮: U) → (unknown ≮: U)
unknown-≮: (witness t p q) = witness t unknown q
never-≮: : ∀ {T U} → (T ≮: U) → (T ≮: never)
never-≮: (witness t p q) = witness t p never
unknown-≮:-never : (unknown ≮: never)
unknown-≮:-never = witness (scalar nil) unknown never
function-≮:-never : ∀ {T U} → ((T ⇒ U) ≮: never)
function-≮:-never = witness function function never
-- A Gentle Introduction To Semantic Subtyping (https://www.cduce.org/papers/gentle.pdf)
-- defines a "set-theoretic" model (sec 2.5)
-- Unfortunately we don't quite have this property, due to uninhabited types,
-- for example (never -> T) is equivalent to (never -> U)
-- when types are interpreted as sets of syntactic values.
_⊆_ : ∀ {A : Set} → (A → Set) → (A → Set) → Set
(P ⊆ Q) = ∀ a → (P a) → (Q a)
_⊗_ : ∀ {A B : Set} → (A → Set) → (B → Set) → ((A × B) → Set)
(P ⊗ Q) (a , b) = (P a) × (Q b)
Comp : ∀ {A : Set} → (A → Set) → (A → Set)
Comp P a = ¬(P a)
set-theoretic-if : ∀ {S₁ T₁ S₂ T₂} →
-- This is the "if" part of being a set-theoretic model
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)) →
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Language T₁)) → Q ⊆ Comp((Language S₂) ⊗ Comp(Language T₂)))
set-theoretic-if {S₁} {T₁} {S₂} {T₂} p Q q (t , u) Qtu (S₂t , ¬T₂u) = q (t , u) Qtu (S₁t , ¬T₁u) where
S₁t : Language S₁ t
S₁t with dec-language S₁ t
S₁t | Left ¬S₁t with p (function-err t) (function-err ¬S₁t)
S₁t | Left ¬S₁t | function-err ¬S₂t = CONTRADICTION (language-comp t ¬S₂t S₂t)
S₁t | Right r = r
¬T₁u : ¬(Language T₁ u)
¬T₁u T₁u with p (function-ok u) (function-ok T₁u)
¬T₁u T₁u | function-ok T₂u = ¬T₂u T₂u
not-quite-set-theoretic-only-if : ∀ {S₁ T₁ S₂ T₂} →
-- We don't quite have that this is a set-theoretic model
-- it's only true when Language T₁ and ¬Language T₂ t₂ are inhabited
-- in particular it's not true when T₁ is never, or T₂ is unknown.
∀ s₂ t₂ → Language S₂ s₂ → ¬Language T₂ t₂ →
-- This is the "only if" part of being a set-theoretic model
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Language T₁)) → Q ⊆ Comp((Language S₂) ⊗ Comp(Language T₂))) →
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂))
not-quite-set-theoretic-only-if {S₁} {T₁} {S₂} {T₂} s₂ t₂ S₂s₂ ¬T₂t₂ p = r where
Q : (Tree × Tree) → Set
Q (t , u) = Either (¬Language S₁ t) (Language T₁ u)
q : Q ⊆ Comp((Language S₁) ⊗ Comp(Language T₁))
q (t , u) (Left ¬S₁t) (S₁t , ¬T₁u) = language-comp t ¬S₁t S₁t
q (t , u) (Right T₂u) (S₁t , ¬T₁u) = ¬T₁u T₂u
r : Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)
r function function = function
r (function-err t) (function-err ¬S₁t) with dec-language S₂ t
r (function-err t) (function-err ¬S₁t) | Left ¬S₂t = function-err ¬S₂t
r (function-err t) (function-err ¬S₁t) | Right S₂t = CONTRADICTION (p Q q (t , t₂) (Left ¬S₁t) (S₂t , language-comp t₂ ¬T₂t₂))
r (function-ok t) (function-ok T₁t) with dec-language T₂ t
r (function-ok t) (function-ok T₁t) | Left ¬T₂t = CONTRADICTION (p Q q (s₂ , t) (Right T₁t) (S₂s₂ , language-comp t ¬T₂t))
r (function-ok t) (function-ok T₁t) | Right T₂t = function-ok T₂t
-- A counterexample when the argument type is empty.
set-theoretic-counterexample-one : (∀ Q → Q ⊆ Comp((Language never) ⊗ Comp(Language number)) → Q ⊆ Comp((Language never) ⊗ Comp(Language string)))
set-theoretic-counterexample-one Q q ((scalar s) , u) Qtu (scalar () , p)
set-theoretic-counterexample-one Q q ((function-err t) , u) Qtu (scalar-function-err () , p)
set-theoretic-counterexample-two : (never ⇒ number) ≮: (never ⇒ string)
set-theoretic-counterexample-two = witness
(function-ok (scalar number)) (function-ok (scalar number))
(function-ok (scalar-scalar number string (λ ())))
-- At some point we may deal with overloaded function resolution, which should fix this problem...
-- The reason why this is connected to overloaded functions is that currently we have that the type of
-- f(x) is (tgt T) where f:T. Really we should have the type depend on the type of x, that is use (tgt T U),
-- where U is the type of x. In particular (tgt (S => T) (U & V)) should be the same as (tgt ((S&U) => T) V)
-- and tgt(never => T) should be unknown. For example
--
-- tgt((number => string) & (string => bool))(number)
-- is tgt(number => string)(number) & tgt(string => bool)(number)
-- is tgt(number => string)(number) & tgt(string => bool)(number&unknown)
-- is tgt(number => string)(number) & tgt(string&number => bool)(unknown)
-- is tgt(number => string)(number) & tgt(never => bool)(unknown)
-- is string & unknown
-- is string
--
-- there's some discussion of this in the Gentle Introduction paper.
| 50.717949
| 250
| 0.648509
|
a0cd97c142725e09ae2d31bbcae32e057a06271c
| 976
|
agda
|
Agda
|
test/Compiler/simple/Issue4169-2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Issue4169-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/Issue4169-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
open import Agda.Builtin.Unit
open import Agda.Primitive
open import Common.IO
data ⊥ : Set where
record R₁ a : Set (lsuc a) where
field
R : {A : Set a} → A → A → Set a
r : {A : Set a} (x : A) → R x x
P : Set a → Set a
P A = (x y : A) → R x y
record R₂ (r : ∀ ℓ → R₁ ℓ) : Set₁ where
field
f :
{X Y : Σ Set (R₁.P (r lzero))} →
R₁.R (r (lsuc lzero)) X Y → fst X → fst Y
module M (r₁ : ∀ ℓ → R₁ ℓ) (r₂ : R₂ r₁) where
open module R₁′ {ℓ} = R₁ (r₁ ℓ) public using (P)
open module R₂′ = R₂ r₂ public
⊥-elim : {A : Set} → ⊥ → A
⊥-elim ()
p : P ⊥
p x = ⊥-elim x
open Agda.Builtin.Equality
r₁ : ∀ ℓ → R₁ ℓ
R₁.R (r₁ _) = _≡_
R₁.r (r₁ _) = λ _ → refl
r₂ : R₂ r₁
R₂.f r₂ refl x = x
open M r₁ r₂
data Unit : Set where
unit : Unit
g : Σ Unit λ _ → P (Σ Set P) → ⊥
g = unit , λ h → f (h (⊤ , λ _ _ → refl) (⊥ , p)) tt
main : IO ⊤
main = return _
| 17.745455
| 52
| 0.533811
|
146c4481cca6ed72b6c3ffccfd8f34aa9210b565
| 5,928
|
agda
|
Agda
|
Cubical/Structures/Semigroup.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Semigroup.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Semigroup.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Semigroup 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.Structures.Auto
open Iso
private
variable
ℓ : Level
-- Semigroups as a record, inspired by the Agda standard library:
--
-- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Bundles.agda#L48
-- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Structures.agda#L50
--
-- Note that as we are using Path for all equations the IsMagma record
-- would only contain isSet A if we had it.
record IsSemigroup {A : Type ℓ} (_·_ : A → A → A) : Type ℓ where
-- TODO: add no-eta-equality for efficiency? This breaks some proofs later
constructor issemigroup
field
is-set : isSet A
assoc : (x y z : A) → x · (y · z) ≡ (x · y) · z
record Semigroup : Type (ℓ-suc ℓ) where
constructor semigroup
field
Carrier : Type ℓ
_·_ : Carrier → Carrier → Carrier
isSemigroup : IsSemigroup _·_
infixl 7 _·_
open IsSemigroup isSemigroup public
-- Extractor for the carrier type
⟨_⟩ : Semigroup → Type ℓ
⟨_⟩ = Semigroup.Carrier
record SemigroupEquiv (M N : Semigroup {ℓ}) : Type ℓ where
constructor semigroupequiv
-- Shorter qualified names
private
module M = Semigroup M
module N = Semigroup N
field
e : ⟨ M ⟩ ≃ ⟨ N ⟩
isHom : (x y : ⟨ M ⟩) → equivFun e (x M.· y) ≡ equivFun e x N.· equivFun e y
-- Develop some theory about Semigroups using various general results
-- that are stated using Σ-types. For this we define Semigroup as a
-- nested Σ-type, prove that it's equivalent to the above record
-- definition and then transport results along this equivalence.
module SemigroupΣTheory {ℓ} where
RawSemigroupStructure : Type ℓ → Type ℓ
RawSemigroupStructure X = X → X → X
RawSemigroupEquivStr = AutoEquivStr RawSemigroupStructure
rawSemigroupUnivalentStr : UnivalentStr _ RawSemigroupEquivStr
rawSemigroupUnivalentStr = autoUnivalentStr RawSemigroupStructure
SemigroupAxioms : (A : Type ℓ) → RawSemigroupStructure A → Type ℓ
SemigroupAxioms A _·_ = isSet A
× ((x y z : A) → x · (y · z) ≡ (x · y) · z)
SemigroupStructure : Type ℓ → Type ℓ
SemigroupStructure = AxiomsStructure RawSemigroupStructure SemigroupAxioms
SemigroupΣ : Type (ℓ-suc ℓ)
SemigroupΣ = TypeWithStr ℓ SemigroupStructure
isPropSemigroupAxioms : (A : Type ℓ) (_·_ : RawSemigroupStructure A)
→ isProp (SemigroupAxioms A _·_)
isPropSemigroupAxioms _ _ = isPropΣ isPropIsSet λ isSetA → isPropΠ3 λ _ _ _ → isSetA _ _
SemigroupEquivStr : StrEquiv SemigroupStructure ℓ
SemigroupEquivStr = AxiomsEquivStr RawSemigroupEquivStr SemigroupAxioms
SemigroupAxiomsIsoIsSemigroup : {A : Type ℓ} (_·_ : RawSemigroupStructure A)
→ Iso (SemigroupAxioms A _·_) (IsSemigroup _·_)
fun (SemigroupAxiomsIsoIsSemigroup s) (x , y) = issemigroup x y
inv (SemigroupAxiomsIsoIsSemigroup s) (issemigroup x y) = (x , y)
rightInv (SemigroupAxiomsIsoIsSemigroup s) _ = refl
leftInv (SemigroupAxiomsIsoIsSemigroup s) _ = refl
SemigroupAxioms≡IsSemigroup : {A : Type ℓ} (_·_ : RawSemigroupStructure A)
→ SemigroupAxioms _ _·_ ≡ IsSemigroup _·_
SemigroupAxioms≡IsSemigroup s = isoToPath (SemigroupAxiomsIsoIsSemigroup s)
Semigroup→SemigroupΣ : Semigroup → SemigroupΣ
Semigroup→SemigroupΣ (semigroup A _·_ isSemigroup) =
A , _·_ , SemigroupAxiomsIsoIsSemigroup _ .inv isSemigroup
SemigroupΣ→Semigroup : SemigroupΣ → Semigroup
SemigroupΣ→Semigroup (A , _·_ , isSemigroupΣ) =
semigroup A _·_ (SemigroupAxiomsIsoIsSemigroup _ .fun isSemigroupΣ)
SemigroupIsoSemigroupΣ : Iso Semigroup SemigroupΣ
SemigroupIsoSemigroupΣ =
iso Semigroup→SemigroupΣ SemigroupΣ→Semigroup (λ _ → refl) (λ _ → refl)
semigroupUnivalentStr : UnivalentStr SemigroupStructure SemigroupEquivStr
semigroupUnivalentStr = axiomsUnivalentStr _ isPropSemigroupAxioms rawSemigroupUnivalentStr
SemigroupΣPath : (M N : SemigroupΣ) → (M ≃[ SemigroupEquivStr ] N) ≃ (M ≡ N)
SemigroupΣPath = SIP semigroupUnivalentStr
SemigroupEquivΣ : (M N : Semigroup) → Type ℓ
SemigroupEquivΣ M N = Semigroup→SemigroupΣ M ≃[ SemigroupEquivStr ] Semigroup→SemigroupΣ N
SemigroupIsoΣPath : {M N : Semigroup} → Iso (SemigroupEquiv M N) (SemigroupEquivΣ M N)
fun SemigroupIsoΣPath (semigroupequiv e h) = (e , h)
inv SemigroupIsoΣPath (e , h) = semigroupequiv e h
rightInv SemigroupIsoΣPath _ = refl
leftInv SemigroupIsoΣPath _ = refl
SemigroupPath : (M N : Semigroup) → (SemigroupEquiv M N) ≃ (M ≡ N)
SemigroupPath M N =
SemigroupEquiv M N ≃⟨ isoToEquiv SemigroupIsoΣPath ⟩
SemigroupEquivΣ M N ≃⟨ SemigroupΣPath _ _ ⟩
Semigroup→SemigroupΣ M ≡ Semigroup→SemigroupΣ N ≃⟨ isoToEquiv (invIso (congIso SemigroupIsoSemigroupΣ)) ⟩
M ≡ N ■
-- We now extract the important results from the above module
isPropIsSemigroup : {A : Type ℓ} (_·_ : A → A → A) → isProp (IsSemigroup _·_)
isPropIsSemigroup _·_ =
subst isProp (SemigroupΣTheory.SemigroupAxioms≡IsSemigroup _·_)
(SemigroupΣTheory.isPropSemigroupAxioms _ _·_)
SemigroupPath : (M N : Semigroup {ℓ}) → (SemigroupEquiv M N) ≃ (M ≡ N)
SemigroupPath = SemigroupΣTheory.SemigroupPath
-- To rename the fields when using a Semigroup use for example the following:
--
-- open Semigroup M renaming ( Carrier to M ; _·_ to _·M_ )
| 36.592593
| 109
| 0.707996
|
0d235a3849a4ddc0efb40c1097c2729721a8e050
| 7,962
|
agda
|
Agda
|
src/Expansion/Delay-monad.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Expansion/Delay-monad.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Expansion/Delay-monad.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some results related to expansion for the delay monad
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Expansion.Delay-monad {a} {A : Type a} where
open import Delay-monad
open import Delay-monad.Bisimilarity as D using (force)
import Delay-monad.Bisimilarity.Negative as DN
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Function-universe equality-with-J hiding (id; _∘_)
open import Function-universe.Size equality-with-J
import Bisimilarity.Delay-monad as SD
open import Equational-reasoning
import Expansion.Equational-reasoning-instances
open import Labelled-transition-system.Delay-monad A
open import Bisimilarity delay-monad using ([_]_∼_)
open import Expansion delay-monad
------------------------------------------------------------------------
-- The direct and the indirect definitions of expansion are pointwise
-- logically equivalent
-- Emulations of the constructors D.later and D.laterˡ.
later-cong : ∀ {i x y} →
[ i ] force x ≳′ force y → [ i ] later x ≳ later y
later-cong x≳′y =
⟨ (λ { later → _ , ⟶→⟶̂ later , x≳′y })
, (λ { later → _ , ⟶→[]⇒ later , x≳′y })
⟩
laterˡ : ∀ {i x y} → [ i ] force x ≳ y → [ i ] later x ≳ y
laterˡ x≳y =
⟨ (λ { later → _ , done _ , convert {a = a} x≳y })
, Σ-map id (Σ-map later[]⇒ id) ∘ right-to-left x≳y
⟩
-- The direct definition of expansion is contained in the one
-- obtained from the transition relation.
direct→indirect : ∀ {i x y} →
D.[ i ] x ≳ y → [ i ] x ≳ y
direct→indirect D.now = reflexive
direct→indirect (D.later p) = later-cong λ { .force →
direct→indirect (force p) }
direct→indirect (D.laterˡ p) = laterˡ (direct→indirect p)
-- If x makes a sequence of zero or more silent transitions to y, then
-- x is an expansion of y.
⇒→≳ : ∀ {i x y} → x ⇒ y → D.[ i ] x ≳ y
⇒→≳ done = D.reflexive _
⇒→≳ (step _ later tr) = D.laterˡ (⇒→≳ tr)
⇒→≳ (step () now tr)
-- If x makes a non-silent transition with the label y, then x is an
-- expansion of now y.
[just]⟶→≳now : ∀ {i x x′ y} → x [ just y ]⟶ x′ → D.[ i ] x ≳ now y
[just]⟶→≳now now = D.reflexive _
[just]⇒→≳now : ∀ {i x x′ y} → x [ just y ]⇒ x′ → D.[ i ] x ≳ now y
[just]⇒→≳now (steps tr now _) = ⇒→≳ tr
[just]⇒̂→≳now : ∀ {i x x′ y} → x [ just y ]⇒̂ x′ → D.[ i ] x ≳ now y
[just]⇒̂→≳now (silent () _)
[just]⇒̂→≳now (non-silent _ tr) = [just]⇒→≳now tr
[just]⟶̂→≳now : ∀ {i x x′ y} → x [ just y ]⟶̂ x′ → D.[ i ] x ≳ now y
[just]⟶̂→≳now (done ())
[just]⟶̂→≳now (step tr) = [just]⇒̂→≳now (⟶→⇒̂ tr)
-- The definition of expansion obtained from the transition relation
-- is contained in the direct one.
indirect→direct : ∀ {i} x y → [ i ] x ≳ y → D.[ i ] x ≳ y
indirect→direct {i} (now x) y =
([ i ] now x ≳ y) ↝⟨ (λ p → left-to-right p now) ⟩
(∃ λ y′ → y [ just x ]⟶̂ y′ × [ i ] now x ≳′ y′) ↝⟨ sym ∘ [just]⟶̂→≡now ∘ proj₁ ∘ proj₂ ⟩
now x ≡ y ↝⟨ (λ { refl → D.reflexive _ }) ⟩□
D.[ i ] now x ≳ y □
indirect→direct {i} x (now y) =
[ i ] x ≳ now y ↝⟨ (λ p → right-to-left p now) ⟩
(∃ λ x′ → x [ just y ]⇒ x′ × [ i ] x′ ≳′ now y) ↝⟨ [just]⇒→≳now ∘ proj₁ ∘ proj₂ ⟩□
D.[ i ] x ≳ now y □
indirect→direct (later x) (later y) lx≳ly =
case left-to-right lx≳ly later of λ where
(_ , step later , x≳′y) → D.later λ { .force {j} →
indirect→direct _ _
(force x≳′y {j = j}) }
(_ , done _ , x≳′ly) →
let x′ , lx⇒x′ , x′≳′y = right-to-left lx≳ly later
in lemma x≳′ly ([]⇒→⇒ _ lx⇒x′) x′≳′y
where
indirect→direct′ : ∀ {i x x′ y} →
x ⇒ x′ → [ i ] x′ ≳ y → D.[ i ] x ≳ y
indirect→direct′ done p = indirect→direct _ _ p
indirect→direct′ (step _ later tr) p = D.laterˡ
(indirect→direct′ tr p)
indirect→direct′ (step () now _)
lemma :
∀ {i x x′} →
[ i ] force x ≳′ later y →
later x ⇒ x′ → [ i ] x′ ≳′ force y →
D.[ i ] later x ≳ later y
lemma x≳′ly done lx≳′y =
D.later λ { .force →
D.laterˡʳ⁻¹
(indirect→direct _ _ (force lx≳′y))
(indirect→direct _ _ (force x≳′ly)) }
lemma x≳′ly (step _ later x⇒x′) x′≳′y =
D.later λ { .force →
indirect→direct′ x⇒x′ (force x′≳′y) }
-- The direct definition of the expansion relation is logically
-- equivalent to the one obtained from the transition relation.
--
-- TODO: Are the two definitions isomorphic?
direct⇔indirect : ∀ {i x y} → D.[ i ] x ≳ y ⇔ [ i ] x ≳ y
direct⇔indirect = record
{ to = direct→indirect
; from = indirect→direct _ _
}
------------------------------------------------------------------------
-- Some non-existence results
Now≳later-now = ∀ x → now x ≳ later (record { force = now x })
now≳later-now⇔uninhabited : Now≳later-now ⇔ ¬ A
now≳later-now⇔uninhabited =
Now≳later-now ↝⟨ inverse $ ∀-cong _ (λ _ → direct⇔indirect) ⟩
DN.Now≳later-now ↝⟨ DN.now≳later-now⇔uninhabited ⟩□
¬ A □
Laterˡ⁻¹ = ∀ {x y} → later x ≳ y → force x ≳ y
laterˡ⁻¹⇔uninhabited : Laterˡ⁻¹ ⇔ ¬ A
laterˡ⁻¹⇔uninhabited =
Laterˡ⁻¹ ↝⟨ inverse $ implicit-∀-cong _ $ implicit-∀-cong _ $ →-cong _ direct⇔indirect direct⇔indirect ⟩
DN.Laterˡ⁻¹-≳ ↝⟨ DN.laterˡ⁻¹-≳⇔uninhabited ⟩□
¬ A □
Laterʳ⁻¹-∼≳ =
∀ {i x} →
[ i ] never ∼ later (record { force = now x }) →
[ i ] never ≳ now x
size-preserving-laterʳ⁻¹-∼≳⇔uninhabited : Laterʳ⁻¹-∼≳ ⇔ ¬ A
size-preserving-laterʳ⁻¹-∼≳⇔uninhabited =
Laterʳ⁻¹-∼≳ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ →-cong _ SD.direct⇔indirect direct⇔indirect ⟩
DN.Laterʳ⁻¹-∼≳ ↝⟨ DN.size-preserving-laterʳ⁻¹-∼≳⇔uninhabited ⟩□
¬ A □
Laterʳ⁻¹ = ∀ {i x y} → [ i ] x ≳ later y → [ i ] x ≳ force y
size-preserving-laterʳ⁻¹⇔uninhabited : Laterʳ⁻¹ ⇔ ¬ A
size-preserving-laterʳ⁻¹⇔uninhabited =
Laterʳ⁻¹ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ →-cong _ direct⇔indirect direct⇔indirect ⟩
DN.Laterʳ⁻¹-≳ ↝⟨ DN.size-preserving-laterʳ⁻¹-≳⇔uninhabited ⟩□
¬ A □
Transitivity-∼≳ˡ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ∼ y → y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-∼≳ˡ⇔uninhabited : Transitivity-∼≳ˡ ⇔ ¬ A
size-preserving-transitivity-∼≳ˡ⇔uninhabited =
Transitivity-∼≳ˡ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ SD.direct⇔indirect (→-cong _ direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-∼≳ˡ ↝⟨ DN.size-preserving-transitivity-∼≳ˡ⇔uninhabited ⟩□
¬ A □
Transitivityˡ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → y ≳ z → [ i ] x ≳ z
size-preserving-transitivityˡ⇔uninhabited : Transitivityˡ ⇔ ¬ A
size-preserving-transitivityˡ⇔uninhabited =
Transitivityˡ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect (→-cong _ direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-≳ˡ ↝⟨ DN.size-preserving-transitivity-≳ˡ⇔uninhabited ⟩□
¬ A □
Transitivity =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → [ i ] y ≳ z → [ i ] x ≳ z
size-preserving-transitivity⇔uninhabited : Transitivity ⇔ ¬ A
size-preserving-transitivity⇔uninhabited =
Transitivity ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect $ →-cong _ direct⇔indirect direct⇔indirect ⟩
DN.Transitivity-≳ ↝⟨ DN.size-preserving-transitivity-≳⇔uninhabited ⟩□
¬ A □
| 38.095694
| 137
| 0.538935
|
649dde3e56d47d69aebae4d84d1bd0c31c72cc23
| 1,453
|
agda
|
Agda
|
LibraBFT/Impl/Types/LedgerInfoWithSignatures.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Impl/Types/LedgerInfoWithSignatures.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Impl/Types/LedgerInfoWithSignatures.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
import LibraBFT.Base.KVMap as Map
open import LibraBFT.Base.PKCS
import LibraBFT.Impl.OBM.Crypto as Crypto
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.Prelude
open import Optics.All
module LibraBFT.Impl.Types.LedgerInfoWithSignatures where
obmNewNoSigs : LedgerInfo → LedgerInfoWithSignatures
obmNewNoSigs li = LedgerInfoWithSignatures∙new li Map.empty
-- HC-TODO : refactor this and TimeoutCertificate
addSignature : AccountAddress → Signature → LedgerInfoWithSignatures → LedgerInfoWithSignatures
addSignature validator sig liws =
case Map.lookup validator (liws ^∙ liwsSignatures) of λ where
(just _) → liws
nothing →
liws & liwsSignatures ∙~ Map.kvm-insert-Haskell validator sig (liws ^∙ liwsSignatures)
verifySignatures : LedgerInfoWithSignatures → ValidatorVerifier → Either ErrLog Unit
verifySignatures self validator = withErrCtx'
("LedgerInfoWithSignatures" ∷ "verify" ∷ [])
(ValidatorVerifier.batchVerifyAggregatedSignatures
validator (self ^∙ liwsLedgerInfo) (self ^∙ liwsSignatures))
| 41.514286
| 111
| 0.775637
|
7371735decbdbe265ec27680be37df2f19ae1fb6
| 654
|
agda
|
Agda
|
test/Succeed/UncurryMeta.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/succeed/UncurryMeta.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/UncurryMeta.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- It would be nice if this worked. The constraint we can't solve is
-- P x y = ? (x, y)
-- Solution: extend the notion of Miller patterns to include record
-- constructions.
--
-- Andreas, 2012-02-27 works now! (see issues 376 and 456)
module UncurryMeta where
data Unit : Set where
unit : Unit
record R : Set where
field
x : Unit
y : Unit
_,_ : Unit -> Unit -> R
x , y = record {x = x; y = y}
data P : Unit -> Unit -> Set where
mkP : forall x y -> P x y
data D : (R -> Set) -> Set1 where
d : {F : R -> Set} -> (forall x y -> F (x , y)) -> D F
unD : {F : R -> Set} -> D F -> Unit
unD (d _) = unit
test : Unit
test = unD (d mkP)
| 21.096774
| 68
| 0.576453
|
11a127f6e447ee1efd60f99f4cc72a8d12d1a3af
| 5,973
|
agda
|
Agda
|
Cubical/Structures/Relational/Product.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Structures/Relational/Product.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Relational/Product.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-
Product of structures S and T: X ↦ S X × T X
-}
{-# OPTIONS --safe #-}
module Cubical.Structures.Relational.Product where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Foundations.RelationalStructure
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as Trunc
open import Cubical.HITs.SetQuotients
open import Cubical.Structures.Product
private
variable
ℓ ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓ₂' ℓ₂'' : Level
-- Structured relations
ProductRelStr :
{S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁')
{S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂')
→ StrRel (ProductStructure S₁ S₂) (ℓ-max ℓ₁' ℓ₂')
ProductRelStr ρ₁ ρ₂ R (s₁ , s₂) (t₁ , t₂) =
ρ₁ R s₁ t₁ × ρ₂ R s₂ t₂
productSuitableRel :
{S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'}
{S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'}
→ SuitableStrRel S₁ ρ₁ → SuitableStrRel S₂ ρ₂
→ SuitableStrRel (ProductStructure S₁ S₂) (ProductRelStr ρ₁ ρ₂)
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .fst .fst =
θ₁ .quo (X , s₁) R r₁ .fst .fst , θ₂ .quo (X , s₂) R r₂ .fst .fst
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .fst .snd =
θ₁ .quo (X , s₁) R r₁ .fst .snd , θ₂ .quo (X , s₂) R r₂ .fst .snd
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .snd ((q₁ , q₂) , (c₁ , c₂)) i .fst =
θ₁ .quo (X , s₁) R r₁ .snd (q₁ , c₁) i .fst , θ₂ .quo (X , s₂) R r₂ .snd (q₂ , c₂) i .fst
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .snd ((q₁ , q₂) , (c₁ , c₂)) i .snd =
θ₁ .quo (X , s₁) R r₁ .snd (q₁ , c₁) i .snd , θ₂ .quo (X , s₂) R r₂ .snd (q₂ , c₂) i .snd
productSuitableRel θ₁ θ₂ .symmetric R (r₁ , r₂) =
θ₁ .symmetric R r₁ , θ₂ .symmetric R r₂
productSuitableRel θ₁ θ₂ .transitive R R' (r₁ , r₂) (r₁' , r₂') =
θ₁ .transitive R R' r₁ r₁' , θ₂ .transitive R R' r₂ r₂'
productSuitableRel θ₁ θ₂ .set setX =
isSet× (θ₁ .set setX) (θ₂ .set setX)
productSuitableRel θ₁ θ₂ .prop propR (s₁ , s₂) (t₁ , t₂) =
isProp× (θ₁ .prop propR s₁ t₁) (θ₂ .prop propR s₂ t₂)
productRelMatchesEquiv :
{S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁') {ι₁ : StrEquiv S₁ ℓ₁''}
{S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂') {ι₂ : StrEquiv S₂ ℓ₂''}
→ StrRelMatchesEquiv ρ₁ ι₁ → StrRelMatchesEquiv ρ₂ ι₂
→ StrRelMatchesEquiv (ProductRelStr ρ₁ ρ₂) (ProductEquivStr ι₁ ι₂)
productRelMatchesEquiv ρ₁ ρ₂ μ₁ μ₂ A B e =
Σ-cong-equiv (μ₁ _ _ e) (λ _ → μ₂ _ _ e)
productRelAction :
{S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'} (α₁ : StrRelAction ρ₁)
{S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'} (α₂ : StrRelAction ρ₂)
→ StrRelAction (ProductRelStr ρ₁ ρ₂)
productRelAction α₁ α₂ .actStr f (s₁ , s₂) = α₁ .actStr f s₁ , α₂ .actStr f s₂
productRelAction α₁ α₂ .actStrId (s₁ , s₂) = ΣPathP (α₁ .actStrId s₁ , α₂ .actStrId s₂)
productRelAction α₁ α₂ .actRel h _ _ (r₁ , r₂) = α₁ .actRel h _ _ r₁ , α₂ .actRel h _ _ r₂
productPositiveRel :
{S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'} {θ₁ : SuitableStrRel S₁ ρ₁}
{S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'} {θ₂ : SuitableStrRel S₂ ρ₂}
→ PositiveStrRel θ₁
→ PositiveStrRel θ₂
→ PositiveStrRel (productSuitableRel θ₁ θ₂)
productPositiveRel σ₁ σ₂ .act = productRelAction (σ₁ .act) (σ₂ .act)
productPositiveRel σ₁ σ₂ .reflexive (s₁ , s₂) = σ₁ .reflexive s₁ , σ₂ .reflexive s₂
productPositiveRel σ₁ σ₂ .detransitive R R' (rr'₁ , rr'₂) =
Trunc.rec squash₁
(λ {(s₁ , r₁ , r₁') →
Trunc.rec squash₁
(λ {(s₂ , r₂ , r₂') → ∣ (s₁ , s₂) , (r₁ , r₂) , (r₁' , r₂') ∣₁})
(σ₂ .detransitive R R' rr'₂)})
(σ₁ .detransitive R R' rr'₁)
productPositiveRel {S₁ = S₁} {ρ₁} {θ₁} {S₂} {ρ₂} {θ₂} σ₁ σ₂ .quo {X} R =
subst isEquiv
(funExt (elimProp (λ _ → productSuitableRel θ₁ θ₂ .set squash/ _ _) (λ _ → refl)))
(compEquiv
(isoToEquiv isom)
(Σ-cong-equiv (_ , σ₁ .quo R) (λ _ → _ , σ₂ .quo R)) .snd)
where
fwd :
ProductStructure S₁ S₂ X / ProductRelStr ρ₁ ρ₂ (R .fst .fst)
→ (S₁ X / ρ₁ (R .fst .fst)) × (S₂ X / ρ₂ (R .fst .fst))
fwd [ s₁ , s₂ ] = [ s₁ ] , [ s₂ ]
fwd (eq/ (s₁ , s₂) (t₁ , t₂) (r₁ , r₂) i) = eq/ s₁ t₁ r₁ i , eq/ s₂ t₂ r₂ i
fwd (squash/ _ _ p q i j) =
isSet× squash/ squash/ _ _ (cong fwd p) (cong fwd q) i j
bwd[] : S₁ X → S₂ X / ρ₂ (R .fst .fst)
→ ProductStructure S₁ S₂ X / ProductRelStr ρ₁ ρ₂ (R .fst .fst)
bwd[] s₁ [ s₂ ] = [ s₁ , s₂ ]
bwd[] s₁ (eq/ s₂ t₂ r₂ i) =
eq/ (s₁ , s₂) (s₁ , t₂) (posRelReflexive σ₁ R s₁ , r₂) i
bwd[] s₁ (squash/ _ _ p q i j) =
squash/ _ _ (λ j → bwd[] s₁ (p j)) (λ j → bwd[] s₁ (q j)) i j
bwd : S₁ X / ρ₁ (R .fst .fst) → S₂ X / ρ₂ (R .fst .fst)
→ ProductStructure S₁ S₂ X / ProductRelStr ρ₁ ρ₂ (R .fst .fst)
bwd [ s₁ ] u = bwd[] s₁ u
bwd (eq/ s₁ t₁ r₁ i) u = path u i
where
path : ∀ u → bwd [ s₁ ] u ≡ bwd [ t₁ ] u
path = elimProp (λ _ → squash/ _ _) (λ s₂ → eq/ (s₁ , s₂) (t₁ , s₂) (r₁ , posRelReflexive σ₂ R s₂))
bwd (squash/ _ _ p q i j) =
isSetΠ (λ _ → squash/) _ _ (cong bwd p) (cong bwd q) i j
open Iso
isom : Iso _ _
isom .fun = fwd
isom .inv = uncurry bwd
isom .rightInv =
uncurry
(elimProp (λ _ → isPropΠ λ _ → isSet× squash/ squash/ _ _)
(λ _ → elimProp (λ _ → isSet× squash/ squash/ _ _) (λ _ → refl)))
isom .leftInv = elimProp (λ _ → squash/ _ _) (λ _ → refl)
productRelMatchesTransp :
{S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁') (α₁ : EquivAction S₁)
{S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂') (α₂ : EquivAction S₂)
→ StrRelMatchesEquiv ρ₁ (EquivAction→StrEquiv α₁)
→ StrRelMatchesEquiv ρ₂ (EquivAction→StrEquiv α₂)
→ StrRelMatchesEquiv (ProductRelStr ρ₁ ρ₂) (EquivAction→StrEquiv (productEquivAction α₁ α₂))
productRelMatchesTransp _ _ _ _ μ₁ μ₂ _ _ e =
compEquiv (Σ-cong-equiv (μ₁ _ _ e) (λ _ → μ₂ _ _ e)) ΣPath≃PathΣ
| 42.361702
| 103
| 0.624644
|
ed6b8b7d4924d7efc701a0258da98442d873bfc9
| 2,145
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the heterogeneous sublist relation
-- This is a generalisation of what is commonly known as Order
-- Preserving Embeddings (OPE).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (REL)
module Data.List.Relation.Binary.Sublist.Heterogeneous
{a b r} {A : Set a} {B : Set b} {R : REL A B r}
where
open import Level using (_⊔_)
open import Data.List.Base using (List; []; _∷_; [_])
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Function
open import Relation.Unary using (Pred)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Re-export core definitions
open import Data.List.Relation.Binary.Sublist.Heterogeneous.Core public
------------------------------------------------------------------------
-- Type and basic combinators
module _ {s} {S : REL A B s} where
map : R ⇒ S → Sublist R ⇒ Sublist S
map f [] = []
map f (y ∷ʳ rs) = y ∷ʳ map f rs
map f (r ∷ rs) = f r ∷ map f rs
minimum : Min (Sublist R) []
minimum [] = []
minimum (x ∷ xs) = x ∷ʳ minimum xs
------------------------------------------------------------------------
-- Conversion to and from Any
toAny : ∀ {a bs} → Sublist R [ a ] bs → Any (R a) bs
toAny (y ∷ʳ rs) = there (toAny rs)
toAny (r ∷ rs) = here r
fromAny : ∀ {a bs} → Any (R a) bs → Sublist R [ a ] bs
fromAny (here r) = r ∷ minimum _
fromAny (there p) = _ ∷ʳ fromAny p
------------------------------------------------------------------------
-- Generalised lookup based on a proof of Any
module _ {p q} {P : Pred A p} {Q : Pred B q} (resp : P ⟶ Q Respects R) where
lookup : ∀ {xs ys} → Sublist R xs ys → Any P xs → Any Q ys
lookup [] ()
lookup (y ∷ʳ p) k = there (lookup p k)
lookup (rxy ∷ p) (here px) = here (resp rxy px)
lookup (rxy ∷ p) (there k) = there (lookup p k)
| 33
| 76
| 0.508625
|
cc58a49e996b1bb78803033713eeba785afb28c5
| 1,280
|
agda
|
Agda
|
test/Succeed/Issue1422.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1422.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1422.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue1422 where
open import Common.Level public using (Level ; lzero ; lsuc) renaming (_⊔_ to _l⊔_)
open import Common.Equality public
-- # Relations
relation : ∀ {ℓ} ℓ' → Set ℓ → Set (lsuc ℓ' l⊔ ℓ)
relation ℓ' α = α → α → Set ℓ'
reflexive : ∀ {ℓ ℓ'} {α : Set ℓ} → relation ℓ' α → Set (ℓ l⊔ ℓ')
reflexive _R_ = ∀ {x} → x R x
antisymmetric : ∀ {ℓ ℓ'} {α : Set ℓ} → relation ℓ' α → Set (ℓ l⊔ ℓ')
antisymmetric _R_ = ∀ {x y} → x R y → y R x → x ≡ y
_⇉_ : ∀ {ℓ₁ ℓ₁' ℓ₂ ℓ₂'} {α : Set ℓ₁} {β : Set ℓ₂} (_R₁_ : relation ℓ₁' α) (_R₂_ : relation ℓ₂' β) → relation (ℓ₁ l⊔ ℓ₁' l⊔ ℓ₂') (α → β)
(_R₁_ ⇉ _R₂_) f g = ∀ {x y} → x R₁ y → f x R₂ g y
proper : ∀ {ℓ ℓ'} {α : Set ℓ} (_R_ : relation ℓ' α) → α → Set ℓ'
proper _R_ x = x R x
-- # Dom
record Dom {ℓ} ℓ' (D : Set ℓ) : Set (lsuc ℓ l⊔ lsuc ℓ') where
field
⟦_⟧ : D → Set ℓ'
open Dom {{...}} public
-- # Partial Order
record PartialOrder {ℓ} ℓ' (α : Set ℓ) : Set (ℓ l⊔ lsuc ℓ') where
infix 4 _⊑_
field
_⊑_ : relation ℓ' α
⊑-reflexivity : reflexive _⊑_
⊑-antisymmetry : antisymmetric _⊑_
open PartialOrder {{...}} public
monotonic : ∀ {ℓ₁ ℓ₁' ℓ₂ ℓ₂'} {α : Set ℓ₁} {{αPO : PartialOrder ℓ₁' α}} {β : Set ℓ₂} {{βPO : PartialOrder ℓ₂' β}} → (α → β) → Set (ℓ₁ l⊔ ℓ₁' l⊔ ℓ₂')
monotonic = proper (_⊑_ ⇉ _⊑_)
| 29.767442
| 148
| 0.557031
|
64f46c8802fa7458833b6acdaebdefb1c3d1b156
| 6,495
|
agda
|
Agda
|
agda-stdlib/README/Text/Pretty.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/README/Text/Pretty.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/README/Text/Pretty.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Examples of pretty printing
------------------------------------------------------------------------
module README.Text.Pretty where
open import Size
open import Data.Bool.Base
open import Data.List.Base as List
open import Data.List.NonEmpty as List⁺
open import Data.Nat.Base
open import Data.Product
open import Data.String.Base hiding (parens; _<+>_)
open import Data.Vec.Base as Vec
open import Function.Base
-- We import the pretty printer and pass 80 to say that we do not want to
-- have lines longer than 80 characters
open import Text.Pretty 80
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- A small declarative programming language
------------------------------------------------------------------------
-- We define a small programming language where definitions are
-- introduced by providing a non-empty list of equations with:
-- * the same number of patterns on the LHS
-- * a term on the RHS of each equation
-- A pattern is either a variable or a constructor applied to a
-- list of subpatterns
data Pattern (i : Size) : Set where
var : String → Pattern i
con : ∀ {j : Size< i} → String → List (Pattern j) → Pattern i
-- A term is either a (bound) variable, the application of a
-- named definition / constructor to a list of arguments or a
-- lambda abstraction
data Term (i : Size) : Set where
var : String → Term i
app : ∀ {j : Size< i} → String → List (Term j) → Term i
lam : ∀ {j : Size< i} → String → Term j → Term i
-- As explained before, a definitions is given by a list of equations
infix 1 _by_
record Def : Set where
constructor _by_
field name : String
{arity} : ℕ
equations : List⁺ (Vec (Pattern _) arity × (Term _))
------------------------------------------------------------------------
-- A pretty printer for this language
------------------------------------------------------------------------
-- First we print patterns. We only wrap a pattern in parentheses if it
-- is compound: i.e. if it is a constructor applied to a non-empty list
-- of subpatterns
-- Lists of patterns are printed separated by a single space.
prettyPattern : ∀ {i} → Pattern i → Doc
prettyPatterns : ∀ {i} → List (Pattern i) → Doc
prettyPattern (var v) = text v
prettyPattern (con c []) = text c
prettyPattern (con c ps) = parens $ text c <+> prettyPatterns ps
prettyPatterns = hsep ∘ List.map prettyPattern
-- Next we print terms. The Bool argument tells us whether we are on
-- the RHS of an application (in which case it is sensible to wrap
-- complex subterms in parentheses).
prettyTerm : ∀ {i} → Bool → Term i → Doc
prettyTerm l (var v) = text v
prettyTerm l (app f []) = text f
prettyTerm l (app f es) = if l then parens else id
$ text f <+> sep (List.map (prettyTerm true) es)
prettyTerm l (lam x b) = if l then parens else id
$ text "λ" <+> text x <> text "." <+> prettyTerm false b
-- We now have all the pieces to print definitions.
-- We print the equations below each other by using vcat.
--
-- The LHS is printed as follows: the name of the function followed by
-- the space-separated list of patterns (if any) and then an equal sign.
--
-- The RHS is printed as a term which is *not* on the RHS of an application.
--
-- Finally we can layout the definition in two different manners:
-- * either LHS followed by RHS
-- * or LHS followed and the RHS as a relative block (indented by 2 spaces)
-- on the next line
prettyDef : Def → Doc
prettyDef (fun by eqs) =
vcat $ List⁺.toList $ flip List⁺.map eqs $ uncurry $ λ ps e →
let lhs = text fun <+> (case ps of λ where
[] → text "="
_ → prettyPatterns (Vec.toList ps) <+> text "=")
rhs = prettyTerm false e
in lhs <+> rhs <|> lhs $$ (spaces 2 <> rhs)
-- The pretty printer is obtained by using the renderer.
pretty : Def → String
pretty = render ∘ prettyDef
------------------------------------------------------------------------
-- Some examples
------------------------------------------------------------------------
-- Our first example is the identity function defined as a λ-abstraction
`id : Def
`id = "id" by ([] , lam "x" (var "x")) ∷ []
_ : pretty `id ≡ "id = λ x. x"
_ = refl
-- If we were to assume that this definition also takes a level (a) and
-- a Set at that level (A) as arguments, we can have a slightly more complex
-- definition like so.
`explicitid : Def
`explicitid = "id" by (var "a" ∷ var "A" ∷ [] , lam "x" (var "x")) ∷ []
_ : pretty `explicitid ≡ "id a A = λ x. x"
_ = refl
-- A more complex example: boolFilter, a function that takes a boolean
-- predicate and a list as arguments and returns a list containing only
-- the values that satisfy the predicate.
-- We use nil and con for [] and _∷_ as our little toy language does not
-- support infix notations.
`filter : Def
`filter = "boolFilter"
by ( var "P?" ∷ con "nil" [] ∷ []
, app "nil" []
)
∷ ( var "P?" ∷ con "con" (var "x" ∷ var "xs" ∷ []) ∷ []
, let rec = app "filter" (var "P?" ∷ var "xs" ∷ []) in
app "if" (app "P?" (var "x" ∷ [])
∷ app "con" (var "x" ∷ rec ∷ [])
∷ rec
∷ [])
)
∷ []
_ : pretty `filter ≡
"boolFilter P? nil = nil
\ \boolFilter P? (con x xs) = if (P? x) (con x (filter P? xs)) (filter P? xs)"
_ = refl
-- We can once more revisit this example with its more complex counterpart:
-- boolFilter taking its level and set arguments explicitly (idem for the
-- list constructors nil and con).
-- This time laying out the second equation on a single line would produce a
-- string larger than 80 characters long. So the pretty printer decides to
-- make the RHS a relative block indented by 2 spaces.
`explicitfilter : Def
`explicitfilter = "boolFilter"
by ( var "a" ∷ var "A" ∷ var "P?" ∷ con "nil" [] ∷ []
, app "nil" (var "a" ∷ var "A" ∷ [])
)
∷ ( var "a" ∷ var "A" ∷ var "P?" ∷ con "con" (var "x" ∷ var "xs" ∷ []) ∷ []
, let rec = app "filter" (var "a" ∷ var "A" ∷ var "P?" ∷ var "xs" ∷ []) in
app "if" (app "P?" (var "x" ∷ [])
∷ app "con" (var "a" ∷ var "A" ∷ var "x" ∷ rec ∷ [])
∷ rec
∷ [])
)
∷ []
_ : pretty `explicitfilter
≡ "boolFilter a A P? nil = nil a A
\ \boolFilter a A P? (con x xs) =
\ \ if (P? x) (con a A x (filter a A P? xs)) (filter a A P? xs)"
_ = refl
| 34.184211
| 79
| 0.5806
|
ed2372efa54be6e63149cf2839d58b4a871df762
| 209
|
agda
|
Agda
|
test/Fail/Issue3090-lparen.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue3090-lparen.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue3090-lparen.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2018-05-27, issue #3090, reported by anka-213
-- Parser should not raise internal error for invalid symbol in name
{-# BUILTIN NATURAL ( #-}
-- Should fail with a parse error, not internal error
| 29.857143
| 68
| 0.722488
|
7cc89ed6484ab55ca8017d003bdbe999fb615889
| 932
|
agda
|
Agda
|
test/Succeed/Issue3989.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3989.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3989.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --warning ShadowingInTelescope --allow-unsolved-metas #-}
open import Agda.Primitive
-- warning here
data _~_ {a a : Level} {A : Set a} (a : A) : A -> Set where
refl : a ~ a
module _ {a} {A : Set a} where
-- nothing: the repetition is in separate telescopes
data Eq (a : A) : (a : A) → Set where
refl : Eq a a
-- warning here
f : ∀ (a : Level) → ∀ {A : Set a} A ~ A → Set → Set
f a A ~ B = λ x → x
-- nothing here: the repetition is in separate telescopes
f' : ∀ a → Set a → Set a
f' a = g a where
g : ∀ a → Set a → Set a
g a z = z
-- nothing here: the variable {a} is not user-written
h : ∀ {a} → Set a → Set a
h = g _ where
g : ∀ a → Set a → Set a
g a z = z
i : (Set → Set → Set) → (∀ _ _ → _)
i f = f
module Issue2284Examples where
badλ : Set → Set → Set
badλ = λ x x → x
postulate
bad₁ : (A A : Set) → Set
bad₂ : (A : Set) (A : A) → Set
ok : (A : Set) → (A : A) → Set
| 20.26087
| 69
| 0.541845
|
7c922d138dbb239ee8eb259ddb19346a20ea9ba2
| 1,849
|
agda
|
Agda
|
test/Succeed/PropTests.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/PropTests.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/PropTests.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --prop #-}
open import Agda.Builtin.Nat
-- You can define datatypes in Prop, even with multiple constructors.
-- However, all constructors are considered (definitionally) equal.
data TestProp : Prop where
p₁ p₂ : TestProp
-- Pattern matching on a datatype in Prop is disallowed unless the
-- target type is a Prop:
test-case : {P : Prop} (x₁ x₂ : P) → TestProp → P
test-case x₁ x₂ p₁ = x₁
test-case x₁ x₂ p₂ = x₂
-- All elements of a Prop are definitionally equal:
data _≡Prop_ {A : Prop} (x : A) : A → Set where
refl : x ≡Prop x
p₁≡p₂ : p₁ ≡Prop p₂
p₁≡p₂ = refl
-- A special case are empty types in Prop: these can be eliminated to
-- any other type.
data ⊥ : Prop where
absurd : {A : Set} → ⊥ → A
absurd ()
-- We can also define record types in Prop, such as the unit:
record ⊤ : Prop where
constructor tt
-- We have Prop : Set₀, so we can store predicates in a small datatype:
data NatProp : Set₁ where
c : (Nat → Prop) → NatProp
-- To define more interesting predicates, we need to define them by pattern matching:
_≤_ : Nat → Nat → Prop
zero ≤ y = ⊤
suc x ≤ suc y = x ≤ y
_ ≤ _ = ⊥
-- We can also define the induction principle for predicates defined in this way,
-- using the fact that we can eliminate absurd propositions with a () pattern.
≤-ind : (P : (m n : Nat) → Set)
→ (pzy : (y : Nat) → P zero y)
→ (pss : (x y : Nat) → P x y → P (suc x) (suc y))
→ (m n : Nat) → m ≤ n → P m n
≤-ind P pzy pss zero y pf = pzy y
≤-ind P pzy pss (suc x) (suc y) pf = pss x y (≤-ind P pzy pss x y pf)
≤-ind P pzy pss (suc _) zero ()
-- We can define equality as a Prop, but (currently) we cannot define
-- the corresponding eliminator, so the equality is only useful for
-- refuting impossible equations.
data _≡P_ {A : Set} (x : A) : A → Prop where
refl : x ≡P x
0≢1 : 0 ≡P 1 → ⊥
0≢1 ()
| 29.822581
| 85
| 0.639264
|
72453728534c3986eabe4e2c1f1df889693eb4f1
| 4,214
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.CommRingHornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool using (Bool; true; false; if_then_else_; _and_)
open import Cubical.Algebra.RingSolver.RawRing
open import Cubical.Algebra.RingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ₐ)
open import Cubical.Algebra.RingSolver.AlmostRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
private
variable
ℓ ℓ′ : Level
{-
This defines the type of multivariate Polynomials over the RawRing R.
The construction is based on the algebraic fact
R[X₀][X₁]⋯[Xₙ] ≅ R[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n R k' is identified
with 'Xₖ', then the RawRing we construct should rather be denoted with
R[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((R[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms (A : RawAlgebra ℤAsRawRing ℓ) : ℕ → Type ℓ where
const : ℤ → IteratedHornerForms A ℕ.zero
0H : {n : ℕ} → IteratedHornerForms A (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms A (ℕ.suc n) → IteratedHornerForms A n
→ IteratedHornerForms A (ℕ.suc n)
module _ (A : RawAlgebra ℤAsRawRing ℓ′) where
open RawRing ℤAsRawRing
isZero : {n : ℕ} → IteratedHornerForms A n
→ Bool
isZero (const (pos ℕ.zero)) = true
isZero (const (pos (ℕ.suc _))) = false
isZero (const (negsuc _)) = false
isZero 0H = true
isZero (P ·X+ P₁) = false
eval : {A : RawAlgebra ℤAsRawRing ℓ′}
(n : ℕ) (P : IteratedHornerForms A n)
→ Vec ⟨ A ⟩ₐ n → ⟨ A ⟩ₐ
eval {A = A} ℕ.zero (const r) [] = RawAlgebra.scalar A r
eval {A = A} .(ℕ.suc _) 0H (_ ∷ _) = RawAlgebra.0r A
eval {A = A} (ℕ.suc n) (P ·X+ Q) (x ∷ xs) =
let open RawAlgebra A
P' = (eval (ℕ.suc n) P (x ∷ xs))
Q' = eval n Q xs
in if (isZero A P)
then Q'
else P' · x + Q'
module IteratedHornerOperations (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
private
1H' : (n : ℕ) → IteratedHornerForms A n
1H' ℕ.zero = const 1r
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms A n
0H' ℕ.zero = const 0r
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms A n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms A n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms A n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) =
let left = (P +ₕ Q)
right = (r +ₕ s)
in if ((isZero A left) and (isZero A right))
then 0ₕ
else left ·X+ right
-ₕ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
-ₕ (const x) = const (- x)
-ₕ 0H = 0H
-ₕ (P ·X+ Q) = (-ₕ P) ·X+ (-ₕ Q)
_⋆_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A (ℕ.suc n)
→ IteratedHornerForms A (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) =
if (isZero A r)
then 0ₕ
else (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero A z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
asRawRing : (n : ℕ) → RawRing ℓ
RawRing.Carrier (asRawRing n) = IteratedHornerForms A n
RawRing.0r (asRawRing n) = 0ₕ
RawRing.1r (asRawRing n) = 1ₕ
RawRing._+_ (asRawRing n) = _+ₕ_
RawRing._·_ (asRawRing n) = _·ₕ_
RawRing.- (asRawRing n) = -ₕ
Variable : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (k : Fin n) → IteratedHornerForms R n
Variable n R k = IteratedHornerOperations.X R n k
Constant : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (r : ℤ) → IteratedHornerForms R n
Constant ℕ.zero R r = const r
Constant (ℕ.suc n) R r = IteratedHornerOperations.0ₕ R ·X+ Constant n R r
| 30.536232
| 87
| 0.600617
|
65df98cdf67317e2408f450ef5e0858dae3975af
| 2,808
|
agda
|
Agda
|
soundness/StdLibStuff.agda
|
frelindb/agsyHOL
|
032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7
|
[
"MIT"
] | 17
|
2015-09-04T14:38:28.000Z
|
2021-03-19T20:53:45.000Z
|
soundness/StdLibStuff.agda
|
frelindb/agsyHOL
|
032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7
|
[
"MIT"
] | null | null | null |
soundness/StdLibStuff.agda
|
frelindb/agsyHOL
|
032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7
|
[
"MIT"
] | 3
|
2016-05-17T20:28:10.000Z
|
2022-01-15T11:51:19.000Z
|
module StdLibStuff where
{-
-- Data.Empty
data ⊥ : Set where
-- Relation.Nullary.Core
infix 3 ¬_
¬_ : Set → Set
¬ P = P → ⊥
data Dec (P : Set) : Set where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
-}
-- Relation.Binary.Core
infix 4 _≡_ -- _≢_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
{-
_≢_ : ∀ {A : Set} → A → A → Set
x ≢ y = ¬ x ≡ y
Decidable : {A : Set} → Set
Decidable {A} = (x y : A) → Dec (x ≡ y)
-}
-- equality properties
sym : {A : Set} → {x y : A} → x ≡ y → y ≡ x
sym refl = refl
subst : {A : Set} → {x y : A} → (p : A → Set) → x ≡ y → p x → p y
subst p refl h = h
cong : {A B : Set} → {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
trans : {A : Set} → {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl h = h
{-
-- Data.List
infixr 5 _∷_
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
data List₁ (A : Set₁) : Set₁ where
[] : List₁ A
_∷_ : (x : A) (xs : List₁ A) → List₁ A
-}
-- Data.Bool
infixr 5 _∨_
data Bool : Set where
true : Bool
false : Bool
not : Bool → Bool
not true = false
not false = true
_∨_ : Bool → Bool → Bool
true ∨ b = true
false ∨ b = b
{-
-- Data.Product
infixr 4 _,_ _,′_
infixr 2 _×_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
record Σ₁ (A : Set₁) (B : A → Set) : Set₁ where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
-- nondep product
record _×_ (A B : Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B
open _×_ public
_,′_ : {A B : Set} → A → B → A × B
_,′_ = _,_
∃ : ∀ {A : Set} → (A → Set) → Set
∃ = Σ _
∃₁ : ∀ {A : Set₁} → (A → Set) → Set₁
∃₁ = Σ₁ _
-}
-- Data.Nat
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
-- Data.Fin
data Fin : ℕ → Set where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} (i : Fin n) → Fin (suc n)
{-
-- Data.Vec
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)
data Vec₁ (A : Set₁) : ℕ → Set₁ where
[] : Vec₁ A zero
_∷_ : ∀ {n} (x : A) (xs : Vec₁ A n) → Vec₁ A (suc n)
lookup : ∀ {n} {A : Set} → Fin n → Vec A n → A
lookup zero (x ∷ xs) = x
lookup (suc i) (x ∷ xs) = lookup i xs
lookup₁ : ∀ {n} {A : Set₁} → Fin n → Vec₁ A n → A
lookup₁ zero (x ∷ xs) = x
lookup₁ (suc i) (x ∷ xs) = lookup₁ i xs
-- Data.Sum
infixr 1 _⊎_
data _⊎_ (A : Set) (B : Set) : Set where
inj₁ : (x : A) → A ⊎ B
inj₂ : (y : B) → A ⊎ B
[_,_]′ : ∀ {A : Set} {B : Set} {C : Set} →
(A → C) → (B → C) → (A ⊎ B → C)
[_,_]′ h₁ h₂ (inj₁ x) = h₁ x
[_,_]′ h₁ h₂ (inj₂ y) = h₂ y
--
_↔_ : Set → Set → Set
X ↔ Y = (X → Y) × (Y → X)
-- Misc
record ⊤ : Set where
-}
| 15.687151
| 65
| 0.480057
|
cca6922337eb31e72676c7af54e043f909db754b
| 154
|
agda
|
Agda
|
proofs/AKS/Polynomial.agda
|
mckeankylej/thesis
|
ddad4c0d5f384a0219b2177461a68dae06952dde
|
[
"MIT"
] | 1
|
2020-12-01T22:38:27.000Z
|
2020-12-01T22:38:27.000Z
|
proofs/AKS/Polynomial.agda
|
mckeankylej/thesis
|
ddad4c0d5f384a0219b2177461a68dae06952dde
|
[
"MIT"
] | null | null | null |
proofs/AKS/Polynomial.agda
|
mckeankylej/thesis
|
ddad4c0d5f384a0219b2177461a68dae06952dde
|
[
"MIT"
] | null | null | null |
open import Algebra using (CommutativeRing)
module AKS.Polynomial {c ℓ} (R : CommutativeRing c ℓ) where
open import AKS.Polynomial.Properties R public
| 22
| 59
| 0.785714
|
012c4595d4ee301d8a7e3df809d0b77d7540edcd
| 18,309
|
agda
|
Agda
|
core/lib/cubical/Square.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/cubical/Square.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/cubical/Square.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.PathOver
module lib.cubical.Square where
{-
*--1--*
| |
0 3
| |
*--2--*
-}
data Square {i} {A : Type i} {a₀₀ : A} : {a₀₁ a₁₀ a₁₁ : A}
→ a₀₀ == a₀₁ → a₀₀ == a₁₀ → a₀₁ == a₁₁ → a₁₀ == a₁₁ → Type i
where
ids : Square idp idp idp idp
hid-square : ∀ {i} {A : Type i} {a₀₀ a₀₁ : A} {p : a₀₀ == a₀₁}
→ Square p idp idp p
hid-square {p = idp} = ids
vid-square : ∀ {i} {A : Type i} {a₀₀ a₁₀ : A} {p : a₀₀ == a₁₀}
→ Square idp p p idp
vid-square {p = idp} = ids
square-to-disc : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋
square-to-disc ids = idp
disc-to-square : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋
→ Square p₀₋ p₋₀ p₋₁ p₁₋
disc-to-square {p₀₋ = idp} {p₋₀ = idp} {p₋₁ = idp} {p₁₋ = .idp} idp = ids
square-to-disc-β : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(α : p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋)
→ square-to-disc (disc-to-square {p₀₋ = p₀₋} {p₋₀ = p₋₀} α) == α
square-to-disc-β {p₀₋ = idp} {p₋₀ = idp} {p₋₁ = idp} {p₁₋ = .idp} idp = idp
disc-to-square-β : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ disc-to-square (square-to-disc sq) == sq
disc-to-square-β ids = idp
ap-square : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square (ap f p₀₋) (ap f p₋₀) (ap f p₋₁) (ap f p₁₋)
ap-square f ids = ids
ap-square-hid : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}
{a₀ a₁ : A} {p : a₀ == a₁}
→ ap-square f (hid-square {p = p}) == hid-square
ap-square-hid {p = idp} = idp
ap-square-vid : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}
{a₀ a₁ : A} {p : a₀ == a₁}
→ ap-square f (vid-square {p = p}) == vid-square
ap-square-vid {p = idp} = idp
module _ {i} {A : Type i} where
horiz-degen-square : {a a' : A} {p q : a == a'}
→ p == q → Square p idp idp q
horiz-degen-square {p = idp} α = disc-to-square α
horiz-degen-path : {a a' : A} {p q : a == a'}
→ Square p idp idp q → p == q
horiz-degen-path {p = idp} sq = square-to-disc sq
horiz-degen-path-β : {a a' : A} {p q : a == a'} (α : p == q)
→ horiz-degen-path (horiz-degen-square α) == α
horiz-degen-path-β {p = idp} α = square-to-disc-β α
horiz-degen-square-β : {a a' : A} {p q : a == a'} (sq : Square p idp idp q)
→ horiz-degen-square (horiz-degen-path sq) == sq
horiz-degen-square-β {p = idp} sq = disc-to-square-β sq
vert-degen-square : {a a' : A} {p q : a == a'}
→ p == q → Square idp p q idp
vert-degen-square {p = idp} α = disc-to-square (! α)
vert-degen-path : {a a' : A} {p q : a == a'}
→ Square idp p q idp → p == q
vert-degen-path {p = idp} sq = ! (square-to-disc sq)
vert-degen-path-β : {a a' : A} {p q : a == a'} (α : p == q)
→ vert-degen-path (vert-degen-square α) == α
vert-degen-path-β {p = idp} α = ap ! (square-to-disc-β (! α)) ∙ !-! α
vert-degen-square-β : {a a' : A} {p q : a == a'} (sq : Square idp p q idp)
→ vert-degen-square (vert-degen-path sq) == sq
vert-degen-square-β {p = idp} sq =
ap disc-to-square (!-! (square-to-disc sq)) ∙ disc-to-square-β sq
horiz-degen-square-idp : {a a' : A} {p : a == a'}
→ horiz-degen-square (idp {a = p}) == hid-square
horiz-degen-square-idp {p = idp} = idp
vert-degen-square-idp : {a a' : A} {p : a == a'}
→ vert-degen-square (idp {a = p}) == vid-square
vert-degen-square-idp {p = idp} = idp
{- Flipping squares -}
module _ {i} {A : Type i} where
square-symmetry : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₋₀ p₀₋ p₁₋ p₋₁
square-symmetry ids = ids
square-sym-inv : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ square-symmetry (square-symmetry sq) == sq
square-sym-inv ids = idp
ap-square-symmetry : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ ap-square f (square-symmetry sq) == square-symmetry (ap-square f sq)
ap-square-symmetry f ids = idp
{- Alternate induction principles -}
square-left-J : ∀ {i j} {A : Type i} {a₀₀ a₀₁ : A} {p₀₋ : a₀₀ == a₀₁}
(P : {a₁₀ a₁₁ : A} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P hid-square)
{a₁₀ a₁₁ : A} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-left-J P r ids = r
square-top-J : ∀ {i j} {A : Type i} {a₀₀ a₁₀ : A} {p₋₀ : a₀₀ == a₁₀}
(P : {a₀₁ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P vid-square)
{a₀₁ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-top-J P r ids = r
square-bot-J : ∀ {i j} {A : Type i} {a₀₁ a₁₁ : A} {p₋₁ : a₀₁ == a₁₁}
(P : {a₀₀ a₁₀ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P vid-square)
{a₀₀ a₁₀ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-bot-J P r ids = r
square-right-J : ∀ {i j} {A : Type i} {a₁₀ a₁₁ : A} {p₁₋ : a₁₀ == a₁₁}
(P : {a₀₀ a₀₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P hid-square)
{a₀₀ a₀₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-right-J P r ids = r
module _ where
private
lemma : ∀ {i j} {A : Type i} {a₀ : A}
(P : {a₁ : A} {p q : a₀ == a₁} → p == q → Type j)
(r : P (idp {a = idp}))
{a₁ : A} {p q : a₀ == a₁} (α : p == q)
→ P α
lemma P r {p = idp} idp = r
horiz-degen-J : ∀ {i j} {A : Type i} {a₀ : A}
(P : {a₁ : A} {p q : a₀ == a₁} → Square p idp idp q → Type j)
(r : P ids)
{a₁ : A} {p q : a₀ == a₁} (sq : Square p idp idp q)
→ P sq
horiz-degen-J P r sq = transport P
(horiz-degen-square-β sq)
(lemma (P ∘ horiz-degen-square) r (horiz-degen-path sq))
vert-degen-J : ∀ {i j} {A : Type i} {a₀ : A}
(P : {a₁ : A} {p q : a₀ == a₁} → Square idp p q idp → Type j)
(r : P ids)
{a₁ : A} {p q : a₀ == a₁} (sq : Square idp p q idp)
→ P sq
vert-degen-J P r sq = transport P
(vert-degen-square-β sq)
(lemma (P ∘ vert-degen-square) r (vert-degen-path sq))
{- Square filling -}
module _ {i} {A : Type i} where
fill-square-left : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₋₀ : a₀₀ == a₁₀) (p₋₁ : a₀₁ == a₁₁) (p₁₋ : a₁₀ == a₁₁)
→ Σ (a₀₀ == a₀₁) (λ p₀₋ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-left idp idp p = (p , hid-square)
fill-square-top : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₀₋ : a₀₀ == a₀₁) (p₋₁ : a₀₁ == a₁₁) (p₁₋ : a₁₀ == a₁₁)
→ Σ (a₀₀ == a₁₀) (λ p₋₀ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-top idp p idp = (p , vid-square)
fill-square-bot : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₀₋ : a₀₀ == a₀₁) (p₋₀ : a₀₀ == a₁₀) (p₁₋ : a₁₀ == a₁₁)
→ Σ (a₀₁ == a₁₁) (λ p₋₁ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-bot idp p idp = (p , vid-square)
fill-square-right : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₀₋ : a₀₀ == a₀₁) (p₋₀ : a₀₀ == a₁₀) (p₋₁ : a₀₁ == a₁₁)
→ Σ (a₁₀ == a₁₁) (λ p₁₋ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-right p idp idp = (p , hid-square)
module _ {i j} {A : Type i} {B : Type j} {f g : A → B} where
↓-='-to-square : {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ u == v [ (λ z → f z == g z) ↓ p ]
→ Square u (ap f p) (ap g p) v
↓-='-to-square {p = idp} α = horiz-degen-square α
↓-='-from-square : {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ Square u (ap f p) (ap g p) v
→ u == v [ (λ z → f z == g z) ↓ p ]
↓-='-from-square {p = idp} sq = horiz-degen-path sq
module _ {i j} {A : Type i} {B : Type j} {f : A → B} {b : B} where
↓-cst=app-from-square : {x y : A} {p : x == y}
{u : b == f x} {v : b == f y}
→ Square u idp (ap f p) v
→ u == v [ (λ z → b == f z) ↓ p ]
↓-cst=app-from-square {p = idp} sq = horiz-degen-path sq
↓-cst=app-to-square : {x y : A} {p : x == y}
{u : b == f x} {v : b == f y}
→ u == v [ (λ z → b == f z) ↓ p ]
→ Square u idp (ap f p) v
↓-cst=app-to-square {p = idp} α = horiz-degen-square α
↓-app=cst-from-square : {x y : A} {p : x == y}
{u : f x == b} {v : f y == b}
→ Square u (ap f p) idp v
→ u == v [ (λ z → f z == b) ↓ p ]
↓-app=cst-from-square {p = idp} sq = horiz-degen-path sq
↓-app=cst-to-square : {x y : A} {p : x == y}
{u : f x == b} {v : f y == b}
→ u == v [ (λ z → f z == b) ↓ p ]
→ Square u (ap f p) idp v
↓-app=cst-to-square {p = idp} α = horiz-degen-square α
module _ {i} {A : Type i} {f : A → A} where
↓-idf=app-from-square : {x y : A} {p : x == y}
{u : x == f x} {v : y == f y}
→ Square u p (ap f p) v
→ u == v [ (λ z → z == f z) ↓ p ]
↓-idf=app-from-square {p = idp} sq = horiz-degen-path sq
↓-idf=app-to-square : {x y : A} {p : x == y}
{u : x == f x} {v : y == f y}
→ u == v [ (λ z → z == f z) ↓ p ]
→ Square u p (ap f p) v
↓-idf=app-to-square {p = idp} α = horiz-degen-square α
↓-app=idf-from-square : {x y : A} {p : x == y}
{u : f x == x} {v : f y == y}
→ Square u (ap f p) p v
→ u == v [ (λ z → f z == z) ↓ p ]
↓-app=idf-from-square {p = idp} sq = horiz-degen-path sq
↓-app=idf-to-square : {x y : A} {p : x == y}
{u : f x == x} {v : f y == y}
→ u == v [ (λ z → f z == z) ↓ p ]
→ Square u (ap f p) p v
↓-app=idf-to-square {p = idp} α = horiz-degen-square α
module _ {i j} {A : Type i} {B : Type j} (g : B → A) (f : A → B) where
↓-∘=idf-from-square : {x y : A} {p : x == y}
{u : g (f x) == x} {v : g (f y) == y}
→ Square u (ap g (ap f p)) p v
→ (u == v [ (λ z → g (f z) == z) ↓ p ])
↓-∘=idf-from-square {p = idp} sq = horiz-degen-path sq
↓-∘=idf-to-square : {x y : A} {p : x == y}
{u : g (f x) == x} {v : g (f y) == y}
→ (u == v [ (λ z → g (f z) == z) ↓ p ])
→ Square u (ap g (ap f p)) p v
↓-∘=idf-to-square {p = idp} α = horiz-degen-square α
module _ {i j} {A : Type i} {B : Type j} where
natural-square : {f₁ f₂ : A → B} (p : ∀ a → f₁ a == f₂ a)
{a₁ a₂ : A} (q : a₁ == a₂)
→ Square (p a₁) (ap f₁ q) (ap f₂ q) (p a₂)
natural-square p idp = hid-square
natural-square-idp : {f₁ : A → B} {a₁ a₂ : A} (q : a₁ == a₂)
→ natural-square {f₁ = f₁} (λ _ → idp) q == vid-square
natural-square-idp idp = idp
{- Used for getting square equivalents of glue-β terms -}
natural-square-β : {f₁ f₂ : A → B} (p : (a : A) → f₁ a == f₂ a)
{x y : A} (q : x == y)
{sq : Square (p x) (ap f₁ q) (ap f₂ q) (p y)}
→ apd p q == ↓-='-from-square sq
→ natural-square p q == sq
natural-square-β _ idp α =
! horiz-degen-square-idp ∙ ap horiz-degen-square α ∙ horiz-degen-square-β _
_⊡v_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₀₂ a₁₂ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₀₋ : a₀₁ == a₀₂} {q₋₂ : a₀₂ == a₁₂} {q₁₋ : a₁₁ == a₁₂}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square q₀₋ p₋₁ q₋₂ q₁₋
→ Square (p₀₋ ∙ q₀₋) p₋₀ q₋₂ (p₁₋ ∙ q₁₋)
ids ⊡v sq = sq
_⊡v'_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₀₂ a₁₂ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₀₋ : a₀₁ == a₀₂} {q₋₂ : a₀₂ == a₁₂} {q₁₋ : a₁₁ == a₁₂}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square q₀₋ p₋₁ q₋₂ q₁₋
→ Square (p₀₋ ∙' q₀₋) p₋₀ q₋₂ (p₁₋ ∙' q₁₋)
sq ⊡v' ids = sq
_∙v⊡_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ p₋₀' : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ p₋₀ == p₋₀'
→ Square p₀₋ p₋₀' p₋₁ p₁₋
→ Square p₀₋ p₋₀ p₋₁ p₁₋
idp ∙v⊡ sq = sq
_⊡v∙_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ p₋₁ == p₋₁'
→ Square p₀₋ p₋₀ p₋₁' p₁₋
sq ⊡v∙ idp = sq
_⊡h_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₂₀ a₂₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₋₀ : a₁₀ == a₂₀} {q₋₁ : a₁₁ == a₂₁} {q₂₋ : a₂₀ == a₂₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₁₋ q₋₀ q₋₁ q₂₋
→ Square p₀₋ (p₋₀ ∙ q₋₀) (p₋₁ ∙ q₋₁) q₂₋
ids ⊡h sq = sq
_⊡h'_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₂₀ a₂₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₋₀ : a₁₀ == a₂₀} {q₋₁ : a₁₁ == a₂₁} {q₂₋ : a₂₀ == a₂₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₁₋ q₋₀ q₋₁ q₂₋
→ Square p₀₋ (p₋₀ ∙' q₋₀) (p₋₁ ∙' q₋₁) q₂₋
sq ⊡h' ids = sq
_∙h⊡_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ p₀₋' : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ p₀₋ == p₀₋'
→ Square p₀₋' p₋₀ p₋₁ p₁₋
→ Square p₀₋ p₋₀ p₋₁ p₁₋
idp ∙h⊡ sq = sq
_⊡h∙_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ p₁₋ == p₁₋'
→ Square p₀₋ p₋₀ p₋₁ p₁₋'
sq ⊡h∙ idp = sq
infixr 80 _⊡v_ _⊡v'_ _⊡h_ _⊡h'_
infixr 80 _∙v⊡_ _∙h⊡_
infixl 85 _⊡v∙_ _⊡h∙_
module _ {i} {A : Type i} where
!□h : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₁₋ (! p₋₀) (! p₋₁) p₀₋
!□h ids = ids
!□v : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square (! p₀₋) p₋₁ p₋₀ (! p₁₋)
!□v ids = ids
module _ {i} {A : Type i} where
{- TODO rest of these -}
⊡h-unit-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ hid-square ⊡h sq == sq
⊡h-unit-l ids = idp
⊡h-unit-r : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq ⊡h hid-square == ∙-unit-r _ ∙v⊡ (sq ⊡v∙ ! (∙-unit-r _))
⊡h-unit-r ids = idp
⊡h'-unit-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ hid-square ⊡h' sq == ∙'-unit-l _ ∙v⊡ (sq ⊡v∙ ! (∙'-unit-l _))
⊡h'-unit-l ids = idp
⊡h-unit-l-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq' : Square p₀₋ idp idp p₀₋) (sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq' ⊡h sq == sq
→ sq' == hid-square
⊡h-unit-l-unique sq' ids p = ! (⊡h-unit-r sq') ∙ p
module _ {i} {A : Type i} where
!□h-inv-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ (!□h sq) ⊡h sq == !-inv-l p₋₀ ∙v⊡ (hid-square ⊡v∙ ! (!-inv-l p₋₁))
!□h-inv-l ids = idp
!□h-inv-r : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq ⊡h (!□h sq) == !-inv-r p₋₀ ∙v⊡ (hid-square ⊡v∙ ! (!-inv-r p₋₁))
!□h-inv-r ids = idp
!□v-inv-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ (!□v sq) ⊡v sq == !-inv-l p₀₋ ∙h⊡ (vid-square ⊡h∙ ! (!-inv-l p₁₋))
!□v-inv-l ids = idp
!□v-inv-r : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq ⊡v (!□v sq) == !-inv-r p₀₋ ∙h⊡ (vid-square ⊡h∙ ! (!-inv-r p₁₋))
!□v-inv-r ids = idp
module _ {i} {A : Type i} where
square-left-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ p₀₋' : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋' p₋₀ p₋₁ p₁₋
→ p₀₋ == p₀₋'
square-left-unique {p₋₀ = idp} {p₋₁ = idp} sq₁ sq₂ =
horiz-degen-path (sq₁ ⊡h (!□h sq₂))
square-top-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ p₋₀' : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋ p₋₀' p₋₁ p₁₋
→ p₋₀ == p₋₀'
square-top-unique {p₀₋ = idp} {p₁₋ = idp} sq₁ sq₂ =
vert-degen-path (sq₁ ⊡v (!□v sq₂))
square-bot-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋ p₋₀ p₋₁' p₁₋
→ p₋₁ == p₋₁'
square-bot-unique {p₀₋ = idp} {p₁₋ = idp} sq₁ sq₂ =
vert-degen-path ((!□v sq₁) ⊡v sq₂)
square-right-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋ p₋₀ p₋₁ p₁₋'
→ p₁₋ == p₁₋'
square-right-unique {p₋₀ = idp} {p₋₁ = idp} sq₁ sq₂ =
horiz-degen-path ((!□h sq₁) ⊡h sq₂)
module _ {i} {A : Type i} where
{- XXX naminig -}
connection : {a₀ a₁ : A} {q : a₀ == a₁}
→ Square idp idp q q
connection {q = idp} = ids
{- XXX naminig -}
connection2 : {a₀ a₁ a₂ : A} {p : a₀ == a₁} {q : a₁ == a₂}
→ Square p p q q
connection2 {p = idp} {q = idp} = ids
lb-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square p idp (! p) idp
lb-square idp = ids
bl-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square (! p) idp p idp
bl-square idp = ids
br-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square idp idp p p
br-square idp = ids
rb-square = br-square
rt-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square idp (! p) idp p
rt-square idp = ids
tr-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square idp p idp (! p)
tr-square idp = ids
lt-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square p p idp idp
lt-square idp = ids
tl-square = lt-square
| 33.842884
| 79
| 0.476487
|
edc266ed0854c41b8113f2d7aec2224f7b334dfc
| 1,088
|
agda
|
Agda
|
test/succeed/Issue458b.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/Issue458b.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue458b.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- {-# OPTIONS -v tc.meta:100 #-}
-- Andreas, 2011-09-21 (fix by Ulf)
module Issue458b where
data _≡_ {A : Set}(a : A) : A -> Set where
refl : a ≡ a
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Pair (A B : Set) : Set where
pair : A -> B -> Pair A B
fst : {A B : Set} -> Pair A B -> A
fst (pair a b) = a
overzeal : let X : Nat -> Nat -> Nat
X = _
Y : Pair Nat Nat -> Nat
Y = _
in {C : Set} ->
(({x y : Nat} -> X x x ≡ Y (pair x y)) ->
({z : Pair Nat Nat} -> Y z ≡ fst z) ->
({x y : Nat} -> X x y ≡ x) -> C) -> C
overzeal k = k refl refl refl
-- This should succeed.
-- However, before Ulf's fix the first constraint would lead to
-- a pruning of y from Y, since X does not depend on y
-- This lost the solution Y = fst.
{- ERROR was:
Cannot instantiate the metavariable _59 to (fst .z) since it
contains the variable .z which is not in scope of the metavariable
when checking that the expression refl has type (_59 ≡ fst .z)
-}
| 30.222222
| 70
| 0.523897
|
0d9aac63f5390ecb4c667447df66b59e59885ea6
| 242
|
agda
|
Agda
|
test/Fail/NonDependentConstructorType.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/NonDependentConstructorType.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/NonDependentConstructorType.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2010-10-01 Issue 342
module NonDependentConstructorType where
data Wrap : Set1 where
wrap : Set -> Wrap
bla : Set
bla = wrap
-- 2010-10-01 error is printed as (_ : Set) -> Wrap !=< Set
-- error should be printed as Set -> Wrap !=< Set
| 22
| 59
| 0.669421
|
72428a32eda14aed249431bf99be5bcf7ca51afd
| 108
|
agda
|
Agda
|
examples/examplesPaperJFP/triangleRightOperator.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/examplesPaperJFP/triangleRightOperator.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/examplesPaperJFP/triangleRightOperator.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module examplesPaperJFP.triangleRightOperator where
_▹_ : ∀{A B : Set} → A → (A → B) → B
a ▹ f = f a
| 21.6
| 51
| 0.583333
|
14c0828d6c39b543e1583c57fb63e1877f1c0d9e
| 2,656
|
agda
|
Agda
|
Monads/EM.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 21
|
2015-07-30T01:25:12.000Z
|
2021-02-13T18:02:18.000Z
|
Monads/EM.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 3
|
2019-01-13T13:12:33.000Z
|
2019-05-29T09:50:26.000Z
|
Monads/EM.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 1
|
2019-11-04T21:33:13.000Z
|
2019-11-04T21:33:13.000Z
|
open import Categories
open import Monads
module Monads.EM {a b}{C : Cat {a}{b}}(M : Monad C) where
open import Library
open import Functors
open Cat C
open Monad M
record Alg : Set (a ⊔ b) where
constructor alg
field acar : Obj
astr : ∀ Z → Hom Z acar → Hom (T Z) acar
alaw1 : ∀ {Z}{f : Hom Z acar} → f ≅ comp (astr Z f) η
alaw2 : ∀{Z}{W}{k : Hom Z (T W)}{f : Hom W acar} →
astr Z (comp (astr W f) k) ≅ comp (astr W f) (bind k)
open Alg
AlgEq : {X Y : Alg} → acar X ≅ acar Y → (astr X ≅ astr Y) → X ≅ Y
AlgEq {alg acar astr _ _} {alg ._ ._ _ _} refl refl =
cong₂ (alg acar astr)
(iext λ _ → iext λ _ → ir _ _)
(iext λ _ → iext λ _ → iext λ _ → iext λ _ → ir _ _)
record AlgMorph (A B : Alg) : Set (a ⊔ b) where
constructor algmorph
field amor : Hom (acar A) (acar B)
ahom : ∀{Z}{f : Hom Z (acar A)} →
comp amor (astr A Z f) ≅ astr B Z (comp amor f)
open AlgMorph
AlgMorphEq : {X Y : Alg}{f g : AlgMorph X Y} → amor f ≅ amor g → f ≅ g
AlgMorphEq {f = algmorph amor _}{algmorph .amor _} refl =
cong (algmorph amor)
(iext λ _ → iext λ _ → ir _ _)
AlgMorphEq' : {X X' Y Y' : Alg}
{f : AlgMorph X Y}{g : AlgMorph X' Y'} → X ≅ X' → Y ≅ Y' →
amor f ≅ amor g → f ≅ g
AlgMorphEq' refl refl = AlgMorphEq
IdMorph : {A : Alg} → AlgMorph A A
IdMorph {A} = record {
amor = iden;
ahom = λ {Z} {f} →
proof
comp iden (astr A Z f)
≅⟨ idl ⟩
astr A Z f
≅⟨ cong (astr A Z) (sym idl) ⟩
astr A Z (comp iden f)
∎}
CompMorph : {X Y Z : Alg} → AlgMorph Y Z → AlgMorph X Y → AlgMorph X Z
CompMorph {X}{Y}{Z} f g = record {
amor = comp (amor f) (amor g);
ahom = λ{W}{h} →
proof
comp (comp (amor f) (amor g)) (astr X W h)
≅⟨ ass ⟩
comp (amor f) (comp (amor g) (astr X W h))
≅⟨ cong (comp (amor f)) (ahom g) ⟩
comp (amor f) (astr Y W (comp (amor g) h))
≅⟨ ahom f ⟩
astr Z W (comp (amor f) (comp (amor g) h))
≅⟨ cong (astr Z W) (sym ass) ⟩
astr Z W (comp (comp (amor f) (amor g)) h)
∎}
idlMorph : {X Y : Alg}{f : AlgMorph X Y} → CompMorph IdMorph f ≅ f
idlMorph = AlgMorphEq idl
idrMorph : {X Y : Alg}{f : AlgMorph X Y} → CompMorph f IdMorph ≅ f
idrMorph = AlgMorphEq idr
assMorph : {W X Y Z : Alg}
{f : AlgMorph Y Z}{g : AlgMorph X Y}{h : AlgMorph W X} →
CompMorph (CompMorph f g) h ≅ CompMorph f (CompMorph g h)
assMorph = AlgMorphEq ass
EM : Cat {a ⊔ b}{a ⊔ b}
EM = record{
Obj = Alg;
Hom = AlgMorph;
iden = IdMorph;
comp = CompMorph;
idl = idlMorph;
idr = idrMorph;
ass = λ{_}{_}{_}{_}{f}{g}{h} → assMorph {f = f}{g}{h}}
-- -}
| 28.55914
| 70
| 0.541416
|
37a13111faf1d338e7616a0c89196be4f8597ccc
| 1,801
|
agda
|
Agda
|
Definition/LogicalRelation/Substitution/Reduction.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Definition/LogicalRelation/Substitution/Reduction.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Definition/LogicalRelation/Substitution/Reduction.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Reduction {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.Untyped using (Con ; Term)
open import Tools.Nat
open import Tools.Product
private
variable
n : Nat
Γ : Con Term n
-- Weak head expansion of valid terms.
redSubstTermᵛ : ∀ {A t u l}
→ ([Γ] : ⊩ᵛ Γ)
→ Γ ⊩ᵛ t ⇒ u ∷ A / [Γ]
→ ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ u ∷ A / [Γ] / [A]
→ Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A]
× Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A]
redSubstTermᵛ [Γ] t⇒u [A] [u] =
(λ ⊢Δ [σ] →
let [σA] = proj₁ ([A] ⊢Δ [σ])
[σt] , [σt≡σu] = redSubstTerm (t⇒u ⊢Δ [σ])
(proj₁ ([A] ⊢Δ [σ]))
(proj₁ ([u] ⊢Δ [σ]))
in [σt]
, (λ [σ′] [σ≡σ′] →
let [σ′A] = proj₁ ([A] ⊢Δ [σ′])
[σA≡σ′A] = proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′]
[σ′t] , [σ′t≡σ′u] = redSubstTerm (t⇒u ⊢Δ [σ′])
(proj₁ ([A] ⊢Δ [σ′]))
(proj₁ ([u] ⊢Δ [σ′]))
in transEqTerm [σA] [σt≡σu]
(transEqTerm [σA] ((proj₂ ([u] ⊢Δ [σ])) [σ′] [σ≡σ′])
(convEqTerm₂ [σA] [σ′A] [σA≡σ′A]
(symEqTerm [σ′A] [σ′t≡σ′u])))))
, (λ ⊢Δ [σ] → proj₂ (redSubstTerm (t⇒u ⊢Δ [σ])
(proj₁ ([A] ⊢Δ [σ]))
(proj₁ ([u] ⊢Δ [σ]))))
| 37.520833
| 85
| 0.381455
|
654d316c057fbb9eda0bab8d5cb5ca99ded3c01e
| 5,617
|
agda
|
Agda
|
Cubical/Categories/NaturalTransformation/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/NaturalTransformation/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/NaturalTransformation/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.NaturalTransformation.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism renaming (iso to iIso)
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
open import Cubical.Categories.NaturalTransformation.Base
private
variable
ℓC ℓC' ℓD ℓD' : Level
open isIsoC
open NatIso
open NatTrans
open Precategory
open Functor
module _ {C : Precategory ℓC ℓC'} {D : Precategory ℓD ℓD'} where
private
_⋆ᴰ_ : ∀ {x y z} (f : D [ x , y ]) (g : D [ y , z ]) → D [ x , z ]
f ⋆ᴰ g = f ⋆⟨ D ⟩ g
-- natural isomorphism is symmetric
symNatIso : ∀ {F G : Functor C D}
→ F ≅ᶜ G
→ G ≅ᶜ F
symNatIso η .trans .N-ob x = η .nIso x .inv
symNatIso η .trans .N-hom _ = sqLL η
symNatIso η .nIso x .inv = η .trans .N-ob x
symNatIso η .nIso x .sec = η .nIso x .ret
symNatIso η .nIso x .ret = η .nIso x .sec
-- Properties
-- path helpers
module NatTransP where
module _ {F G : Functor C D} where
open Iso
-- same as Sigma version
NatTransΣ = Σ[ ob ∈ ((x : C .ob) → D [(F .F-ob x) , (G .F-ob x)]) ]
({x y : _ } (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (ob y) ≡ (ob x) ⋆ᴰ (G .F-hom f))
NatTransIsoΣ : Iso (NatTrans F G) NatTransΣ
NatTransIsoΣ .fun (natTrans N-ob N-hom) = N-ob , N-hom
NatTransIsoΣ .inv (N-ob , N-hom) = (natTrans N-ob N-hom)
NatTransIsoΣ .rightInv _ = refl
NatTransIsoΣ .leftInv _ = refl
NatTrans≡Σ = ua (isoToEquiv NatTransIsoΣ)
-- introducing paths
NatTrans-≡-intro : ∀ {αo βo : N-ob-Type F G}
{αh : N-hom-Type F G αo}
{βh : N-hom-Type F G βo}
→ (p : αo ≡ βo)
→ PathP (λ i → ({x y : C .ob} (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (p i y) ≡ (p i x) ⋆ᴰ (G .F-hom f))) αh βh
→ natTrans {F = F} {G} αo αh ≡ natTrans βo βh
NatTrans-≡-intro p q i = natTrans (p i) (q i)
module _ {F G : Functor C D} {α β : NatTrans F G} where
open Iso
private
αOb = α .N-ob
βOb = β .N-ob
αHom = α .N-hom
βHom = β .N-hom
-- path between natural transformations is the same as a pair of paths (between ob and hom)
NTPathIsoPathΣ : Iso (α ≡ β)
(Σ[ p ∈ (αOb ≡ βOb) ]
(PathP (λ i → ({x y : _} (f : _) → F ⟪ f ⟫ ⋆ᴰ (p i y) ≡ (p i x) ⋆ᴰ G ⟪ f ⟫))
αHom
βHom))
NTPathIsoPathΣ .fun p = (λ i → p i .N-ob) , (λ i → p i .N-hom)
NTPathIsoPathΣ .inv (po , ph) i = record { N-ob = po i ; N-hom = ph i }
NTPathIsoPathΣ .rightInv pσ = refl
NTPathIsoPathΣ .leftInv p = refl
NTPath≃PathΣ = isoToEquiv NTPathIsoPathΣ
NTPath≡PathΣ = ua NTPath≃PathΣ
module _ ⦃ isCatD : isCategory D ⦄ where
open NatTransP
-- if the target category has hom Sets, then any natural transformation is a set
isSetNat : ∀ {F G : Functor C D}
→ isSet (NatTrans F G)
isSetNat {F} {G} α β p1 p2 i = comp (λ i → NTPath≡PathΣ {F = F} {G} {α} {β} (~ i))
(λ j → λ {(i = i0) → transport-filler NTPath≡PathΣ p1 (~ j) ;
(i = i1) → transport-filler NTPath≡PathΣ p2 (~ j)})
(p1Σ≡p2Σ i)
where
αOb = α .N-ob
βOb = β .N-ob
αHom = α .N-hom
βHom = β .N-hom
-- convert to sigmas so we can reason about constituent paths separately
p1Σ : Σ[ p ∈ (αOb ≡ βOb) ]
(PathP (λ i → ({x y : _} (f : _) → F ⟪ f ⟫ ⋆ᴰ (p i y) ≡ (p i x) ⋆ᴰ G ⟪ f ⟫))
αHom
βHom)
p1Σ = transport NTPath≡PathΣ p1
p2Σ : Σ[ p ∈ (αOb ≡ βOb) ]
(PathP (λ i → ({x y : _} (f : _) → F ⟪ f ⟫ ⋆ᴰ (p i y) ≡ (p i x) ⋆ᴰ G ⟪ f ⟫))
αHom
βHom)
p2Σ = transport NTPath≡PathΣ p2
-- type aliases
typeN-ob = (x : C .ob) → D [(F .F-ob x) , (G .F-ob x)]
typeN-hom : typeN-ob → Type _
typeN-hom ϕ = {x y : C .ob} (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (ϕ y) ≡ (ϕ x) ⋆ᴰ (G .F-hom f)
-- the Ob function is a set
isSetN-ob : isSet ((x : C .ob) → D [(F .F-ob x) , (G .F-ob x)])
isSetN-ob = isOfHLevelΠ 2 λ _ → isCatD .isSetHom
-- the Hom function is a set
isSetN-hom : (ϕ : typeN-ob) → isSet (typeN-hom ϕ)
isSetN-hom γ = isProp→isSet (isPropImplicitΠ λ x → isPropImplicitΠ λ y → isPropΠ λ f → isCatD .isSetHom _ _)
-- in fact it's a dependent Set, which we need because N-hom depends on N-ob
isSetN-homP : isOfHLevelDep 2 (λ γ → {x y : C .ob} (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (γ y) ≡ (γ x) ⋆ᴰ (G .F-hom f))
isSetN-homP = isOfHLevel→isOfHLevelDep 2 isSetN-hom
-- components of the equality
p1Ob≡p2Ob : fst p1Σ ≡ fst p2Σ
p1Ob≡p2Ob = isSetN-ob _ _ (fst p1Σ) (fst p2Σ)
p1Hom≡p2Hom : PathP (λ i → PathP (λ j → typeN-hom (p1Ob≡p2Ob i j)) αHom βHom)
(snd p1Σ) (snd p2Σ)
p1Hom≡p2Hom = isSetN-homP _ _ (snd p1Σ) (snd p2Σ) p1Ob≡p2Ob
p1Σ≡p2Σ : p1Σ ≡ p2Σ
p1Σ≡p2Σ = ΣPathP (p1Ob≡p2Ob , p1Hom≡p2Hom)
| 38.210884
| 130
| 0.510415
|
012e927e18ce60815dbacd4bca9fff2b257ee28c
| 17,662
|
agda
|
Agda
|
formalization/agda/Spire/Examples/PropositionalDesc.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 43
|
2015-05-28T23:25:33.000Z
|
2022-03-08T17:10:59.000Z
|
formalization/agda/Spire/Examples/PropositionalDesc.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | null | null | null |
formalization/agda/Spire/Examples/PropositionalDesc.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 1
|
2015-08-17T21:00:07.000Z
|
2015-08-17T21:00:07.000Z
|
{-# OPTIONS --type-in-type #-}
open import Data.Unit
open import Data.Product hiding ( curry ; uncurry )
open import Data.List hiding ( concat )
open import Data.String
open import Relation.Binary.PropositionalEquality
module Spire.Examples.PropositionalDesc where
----------------------------------------------------------------------
elimEq : (A : Set) (x : A) (P : (y : A) → x ≡ y → Set)
→ P x refl
→ (y : A) (p : x ≡ y) → P y p
elimEq A .x P prefl x refl = prefl
----------------------------------------------------------------------
Label : Set
Label = String
Enum : Set
Enum = List Label
data Tag : Enum → Set where
here : ∀{l E} → Tag (l ∷ E)
there : ∀{l E} → Tag E → Tag (l ∷ E)
Cases : (E : Enum) (P : Tag E → Set) → Set
Cases [] P = ⊤
Cases (l ∷ E) P = P here × Cases E λ t → P (there t)
case : (E : Enum) (P : Tag E → Set) (cs : Cases E P) (t : Tag E) → P t
case (l ∷ E) P (c , cs) here = c
case (l ∷ E) P (c , cs) (there t) = case E (λ t → P (there t)) cs t
UncurriedCases : (E : Enum) (P : Tag E → Set) (X : Set)
→ Set
UncurriedCases E P X = Cases E P → X
CurriedCases : (E : Enum) (P : Tag E → Set) (X : Set)
→ Set
CurriedCases [] P X = X
CurriedCases (l ∷ E) P X = P here → CurriedCases E (λ t → P (there t)) X
curryCases : (E : Enum) (P : Tag E → Set) (X : Set)
(f : UncurriedCases E P X) → CurriedCases E P X
curryCases [] P X f = f tt
curryCases (l ∷ E) P X f = λ c → curryCases E (λ t → P (there t)) X (λ cs → f (c , cs))
uncurryCases : (E : Enum) (P : Tag E → Set) (X : Set)
(f : CurriedCases E P X) → UncurriedCases E P X
uncurryCases [] P X x tt = x
uncurryCases (l ∷ E) P X f (c , cs) = uncurryCases E (λ t → P (there t)) X (f c) cs
----------------------------------------------------------------------
data Desc (I : Set) : Set₁ where
`End : (i : I) → Desc I
`Rec : (i : I) (D : Desc I) → Desc I
`Arg : (A : Set) (B : A → Desc I) → Desc I
`RecFun : (A : Set) (B : A → I) (D : Desc I) → Desc I
ISet : Set → Set₁
ISet I = I → Set
El : (I : Set) (D : Desc I) (X : ISet I) → ISet I
El I (`End j) X i = j ≡ i
El I (`Rec j D) X i = X j × El I D X i
El I (`Arg A B) X i = Σ A (λ a → El I (B a) X i)
El I (`RecFun A B D) X i = ((a : A) → X (B a)) × El I D X i
Hyps : (I : Set) (D : Desc I) (X : ISet I) (P : (i : I) → X i → Set) (i : I) (xs : El I D X i) → Set
Hyps I (`End j) X P i q = ⊤
Hyps I (`Rec j D) X P i (x , xs) = P j x × Hyps I D X P i xs
Hyps I (`Arg A B) X P i (a , b) = Hyps I (B a) X P i b
Hyps I (`RecFun A B D) X P i (f , xs) = ((a : A) → P (B a) (f a)) × Hyps I D X P i xs
caseD : (E : Enum) (I : Set) (cs : Cases E (λ _ → Desc I)) (t : Tag E) → Desc I
caseD E I cs t = case E (λ _ → Desc I) cs t
----------------------------------------------------------------------
TagDesc : (I : Set) → Set
TagDesc I = Σ Enum (λ E → Cases E (λ _ → Desc I))
toCase : (I : Set) (E,cs : TagDesc I) → Tag (proj₁ E,cs) → Desc I
toCase I (E , cs) = case E (λ _ → Desc I) cs
toDesc : (I : Set) → TagDesc I → Desc I
toDesc I (E , cs) = `Arg (Tag E) (toCase I (E , cs))
----------------------------------------------------------------------
UncurriedEl : (I : Set) (D : Desc I) (X : ISet I) → Set
UncurriedEl I D X = {i : I} → El I D X i → X i
CurriedEl : (I : Set) (D : Desc I) (X : ISet I) → Set
CurriedEl I (`End i) X = X i
CurriedEl I (`Rec j D) X = (x : X j) → CurriedEl I D X
CurriedEl I (`Arg A B) X = (a : A) → CurriedEl I (B a) X
CurriedEl I (`RecFun A B D) X = ((a : A) → X (B a)) → CurriedEl I D X
curryEl : (I : Set) (D : Desc I) (X : ISet I)
(cn : UncurriedEl I D X) → CurriedEl I D X
curryEl I (`End i) X cn = cn refl
curryEl I (`Rec i D) X cn = λ x → curryEl I D X (λ xs → cn (x , xs))
curryEl I (`Arg A B) X cn = λ a → curryEl I (B a) X (λ xs → cn (a , xs))
curryEl I (`RecFun A B D) X cn = λ f → curryEl I D X (λ xs → cn (f , xs))
uncurryEl : (I : Set) (D : Desc I) (X : ISet I)
(cn : CurriedEl I D X) → UncurriedEl I D X
uncurryEl I (`End i) X cn refl = cn
uncurryEl I (`Rec i D) X cn (x , xs) = uncurryEl I D X (cn x) xs
uncurryEl I (`Arg A B) X cn (a , xs) = uncurryEl I (B a) X (cn a) xs
uncurryEl I (`RecFun A B D) X cn (f , xs) = uncurryEl I D X (cn f) xs
data μ (I : Set) (D : Desc I) : I → Set where
con : UncurriedEl I D (μ I D)
con2 : (I : Set) (D : Desc I) → CurriedEl I D (μ I D)
con2 I D = curryEl I D (μ I D) con
----------------------------------------------------------------------
UncurriedHyps : (I : Set) (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl I D X)
→ Set
UncurriedHyps I D X P cn =
(i : I) (xs : El I D X i) → Hyps I D X P i xs → P i (cn xs)
CurriedHyps : (I : Set) (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl I D X)
→ Set
CurriedHyps I (`End i) X P cn =
P i (cn refl)
CurriedHyps I (`Rec i D) X P cn =
(x : X i) → P i x → CurriedHyps I D X P (λ xs → cn (x , xs))
CurriedHyps I (`Arg A B) X P cn =
(a : A) → CurriedHyps I (B a) X P (λ xs → cn (a , xs))
CurriedHyps I (`RecFun A B D) X P cn =
(f : (a : A) → X (B a)) (ihf : (a : A) → P (B a) (f a)) → CurriedHyps I D X P (λ xs → cn (f , xs))
curryHyps : (I : Set) (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl I D X)
(pf : UncurriedHyps I D X P cn)
→ CurriedHyps I D X P cn
curryHyps I (`End i) X P cn pf =
pf i refl tt
curryHyps I (`Rec i D) X P cn pf =
λ x ih → curryHyps I D X P (λ xs → cn (x , xs)) (λ i xs ihs → pf i (x , xs) (ih , ihs))
curryHyps I (`Arg A B) X P cn pf =
λ a → curryHyps I (B a) X P (λ xs → cn (a , xs)) (λ i xs ihs → pf i (a , xs) ihs)
curryHyps I (`RecFun A B D) X P cn pf =
λ f ihf → curryHyps I D X P (λ xs → cn (f , xs)) (λ i xs ihs → pf i (f , xs) (ihf , ihs))
uncurryHyps : (I : Set) (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl I D X)
(pf : CurriedHyps I D X P cn)
→ UncurriedHyps I D X P cn
uncurryHyps I (`End .i) X P cn pf i refl tt =
pf
uncurryHyps I (`Rec j D) X P cn pf i (x , xs) (ih , ihs) =
uncurryHyps I D X P (λ ys → cn (x , ys)) (pf x ih) i xs ihs
uncurryHyps I (`Arg A B) X P cn pf i (a , xs) ihs =
uncurryHyps I (B a) X P (λ ys → cn (a , ys)) (pf a) i xs ihs
uncurryHyps I (`RecFun A B D) X P cn pf i (f , xs) (ihf , ihs) =
uncurryHyps I D X P (λ ys → cn (f , ys)) (pf f ihf) i xs ihs
----------------------------------------------------------------------
ind :
(I : Set)
(D : Desc I)
(P : (i : I) → μ I D i → Set)
(pcon : UncurriedHyps I D (μ I D) P con)
(i : I)
(x : μ I D i)
→ P i x
hyps :
(I : Set)
(D₁ : Desc I)
(P : (i : I) → μ I D₁ i → Set)
(pcon : UncurriedHyps I D₁ (μ I D₁) P con)
(D₂ : Desc I)
(i : I)
(xs : El I D₂ (μ I D₁) i)
→ Hyps I D₂ (μ I D₁) P i xs
ind I D P pcon i (con xs) = pcon i xs (hyps I D P pcon D i xs)
hyps I D P pcon (`End j) i q = tt
hyps I D P pcon (`Rec j A) i (x , xs) = ind I D P pcon j x , hyps I D P pcon A i xs
hyps I D P pcon (`Arg A B) i (a , b) = hyps I D P pcon (B a) i b
hyps I D P pcon (`RecFun A B E) i (f , xs) = (λ a → ind I D P pcon (B a) (f a)) , hyps I D P pcon E i xs
----------------------------------------------------------------------
ind2 :
(I : Set)
(D : Desc I)
(P : (i : I) → μ I D i → Set)
(pcon : CurriedHyps I D (μ I D) P con)
(i : I)
(x : μ I D i)
→ P i x
ind2 I D P pcon i x = ind I D P (uncurryHyps I D (μ I D) P con pcon) i x
elim :
(I : Set)
(TD : TagDesc I)
→ let
D = toDesc I TD
E = proj₁ TD
Cs = toCase I TD
in (P : (i : I) → μ I D i → Set)
→ let
Q = λ t → CurriedHyps I (Cs t) (μ I D) P (λ xs → con (t , xs))
X = (i : I) (x : μ I D i) → P i x
in UncurriedCases E Q X
elim I TD P cs i x =
let
D = toDesc I TD
E = proj₁ TD
Cs = toCase I TD
Q = λ t → CurriedHyps I (Cs t) (μ I D) P (λ xs → con (t , xs))
p = case E Q cs
in ind2 I D P p i x
elim2 :
(I : Set)
(TD : TagDesc I)
→ let
D = toDesc I TD
E = proj₁ TD
Cs = toCase I TD
in (P : (i : I) → μ I D i → Set)
→ let
Q = λ t → CurriedHyps I (Cs t) (μ I D) P (λ xs → con (t , xs))
X = (i : I) (x : μ I D i) → P i x
in CurriedCases E Q X
elim2 I TD P =
let
D = toDesc I TD
E = proj₁ TD
Cs = toCase I TD
Q = λ t → CurriedHyps I (Cs t) (μ I D) P (λ xs → con (t , xs))
X = (i : I) (x : μ I D i) → P i x
in curryCases E Q X (elim I TD P)
----------------------------------------------------------------------
module Sugared where
data ℕT : Set where `zero `suc : ℕT
data VecT : Set where `nil `cons : VecT
ℕD : Desc ⊤
ℕD = `Arg ℕT λ
{ `zero → `End tt
; `suc → `Rec tt (`End tt)
}
ℕ : ⊤ → Set
ℕ = μ ⊤ ℕD
zero : ℕ tt
zero = con (`zero , refl)
suc : ℕ tt → ℕ tt
suc n = con (`suc , n , refl)
VecD : (A : Set) → Desc (ℕ tt)
VecD A = `Arg VecT λ
{ `nil → `End zero
; `cons → `Arg (ℕ tt) λ n → `Arg A λ _ → `Rec n (`End (suc n))
}
Vec : (A : Set) (n : ℕ tt) → Set
Vec A n = μ (ℕ tt) (VecD A) n
nil : (A : Set) → Vec A zero
nil A = con (`nil , refl)
cons : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons A n x xs = con (`cons , n , x , xs , refl)
----------------------------------------------------------------------
add : ℕ tt → ℕ tt → ℕ tt
add = ind ⊤ ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ
{ tt (`zero , q) tt n → n
; tt (`suc , m , q) (ih , tt) n → suc (ih n)
}
)
tt
mult : ℕ tt → ℕ tt → ℕ tt
mult = ind ⊤ ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ
{ tt (`zero , q) tt n → zero
; tt (`suc , m , q) (ih , tt) n → add n (ih n)
}
)
tt
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = ind (ℕ tt) (VecD A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ
{ .(con (`zero , refl)) (`nil , refl) ih n ys → ys
; .(con (`suc , m , refl)) (`cons , m , x , xs , refl) (ih , tt) n ys → cons A (add m n) x (ih n ys)
}
)
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = ind (ℕ tt) (VecD (Vec A m)) (λ n xss → Vec A (mult n m))
(λ
{ .(con (`zero , refl)) (`nil , refl) tt → nil A
; .(con (`suc , n , refl)) (`cons , n , xs , xss , refl) (ih , tt) → append A m xs (mult n m) ih
}
)
----------------------------------------------------------------------
module Desugared where
ℕT : Enum
ℕT = "zero" ∷ "suc" ∷ []
VecT : Enum
VecT = "nil" ∷ "cons" ∷ []
ℕTD : TagDesc ⊤
ℕTD = ℕT
, `End tt
, `Rec tt (`End tt)
, tt
ℕCs : Tag ℕT → Desc ⊤
ℕCs = toCase ⊤ ℕTD
ℕD : Desc ⊤
ℕD = toDesc ⊤ ℕTD
ℕ : ⊤ → Set
ℕ = μ ⊤ ℕD
zero : ℕ tt
zero = con (here , refl)
suc : ℕ tt → ℕ tt
suc n = con (there here , n , refl)
zero2 : ℕ tt
zero2 = con2 ⊤ ℕD here
suc2 : ℕ tt → ℕ tt
suc2 = con2 ⊤ ℕD (there here)
VecTD : (A : Set) → TagDesc (ℕ tt)
VecTD A = VecT
, `End zero
, `Arg (ℕ tt) (λ n → `Arg A λ _ → `Rec n (`End (suc n)))
, tt
VecCs : (A : Set) → Tag VecT → Desc (ℕ tt)
VecCs A = toCase (ℕ tt) (VecTD A)
VecD : (A : Set) → Desc (ℕ tt)
VecD A = toDesc (ℕ tt) (VecTD A)
Vec : (A : Set) (n : ℕ tt) → Set
Vec A n = μ (ℕ tt) (VecD A) n
nil : (A : Set) → Vec A zero
nil A = con (here , refl)
cons : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons A n x xs = con (there here , n , x , xs , refl)
nil2 : (A : Set) → Vec A zero
nil2 A = con2 (ℕ tt) (VecD A) here
cons2 : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons2 A = con2 (ℕ tt) (VecD A) (there here)
----------------------------------------------------------------------
module Induction where
add : ℕ tt → ℕ tt → ℕ tt
add = ind ⊤ ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ u t,c → case ℕT
(λ t → (c : El ⊤ (ℕCs t) ℕ u)
(ih : Hyps ⊤ ℕD ℕ (λ u n → ℕ u → ℕ u) u (t , c))
→ ℕ u → ℕ u
)
( (λ q ih n → n)
, (λ m,q ih,tt n → suc (proj₁ ih,tt n))
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
tt
mult : ℕ tt → ℕ tt → ℕ tt
mult = ind ⊤ ℕD (λ _ _ → ℕ tt → ℕ tt)
(λ u t,c → case ℕT
(λ t → (c : El ⊤ (ℕCs t) ℕ u)
(ih : Hyps ⊤ ℕD ℕ (λ u n → ℕ u → ℕ u) u (t , c))
→ ℕ u → ℕ u
)
( (λ q ih n → zero)
, (λ m,q ih,tt n → add n (proj₁ ih,tt n))
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
tt
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = ind (ℕ tt) (VecD A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ m t,c → case VecT
(λ t → (c : El (ℕ tt) (VecCs A t) (Vec A) m)
(ih : Hyps (ℕ tt) (VecD A) (Vec A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)) m (t , c))
(n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
)
( (λ q ih n ys → subst (λ m → Vec A (add m n)) q ys)
, (λ m',x,xs,q ih,tt n ys →
let m' = proj₁ m',x,xs,q
x = proj₁ (proj₂ m',x,xs,q)
q = proj₂ (proj₂ (proj₂ m',x,xs,q))
ih = proj₁ ih,tt
in
subst (λ m → Vec A (add m n)) q (cons A (add m' n) x (ih n ys))
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = ind (ℕ tt) (VecD (Vec A m)) (λ n xss → Vec A (mult n m))
(λ n t,c → case VecT
(λ t → (c : El (ℕ tt) (VecCs (Vec A m) t) (Vec (Vec A m)) n)
(ih : Hyps (ℕ tt) (VecD (Vec A m)) (Vec (Vec A m)) (λ n xss → Vec A (mult n m)) n (t , c))
→ Vec A (mult n m)
)
( (λ q ih → subst (λ n → Vec A (mult n m)) q (nil A))
, (λ n',xs,xss,q ih,tt →
let n' = proj₁ n',xs,xss,q
xs = proj₁ (proj₂ n',xs,xss,q)
q = proj₂ (proj₂ (proj₂ n',xs,xss,q))
ih = proj₁ ih,tt
in
subst (λ n → Vec A (mult n m)) q (append A m xs (mult n' m) ih)
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
----------------------------------------------------------------------
module Eliminator where
elimℕ : (P : (ℕ tt) → Set)
(pzero : P zero)
(psuc : (m : ℕ tt) → P m → P (suc m))
(n : ℕ tt)
→ P n
elimℕ P pzero psuc = ind ⊤ ℕD (λ u n → P n)
(λ u t,c → case ℕT
(λ t → (c : El ⊤ (ℕCs t) ℕ u)
(ih : Hyps ⊤ ℕD ℕ (λ u n → P n) u (t , c))
→ P (con (t , c))
)
( (λ q ih →
elimEq ⊤ tt (λ u q → P (con (here , q)))
pzero
u q
)
, (λ n,q ih,tt →
elimEq ⊤ tt (λ u q → P (con (there here , proj₁ n,q , q)))
(psuc (proj₁ n,q) (proj₁ ih,tt))
u (proj₂ n,q)
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
tt
elimVec : (A : Set) (P : (n : ℕ tt) → Vec A n → Set)
(pnil : P zero (nil A))
(pcons : (n : ℕ tt) (a : A) (xs : Vec A n) → P n xs → P (suc n) (cons A n a xs))
(n : ℕ tt)
(xs : Vec A n)
→ P n xs
elimVec A P pnil pcons = ind (ℕ tt) (VecD A) (λ n xs → P n xs)
(λ n t,c → case VecT
(λ t → (c : El (ℕ tt) (VecCs A t) (Vec A) n)
(ih : Hyps (ℕ tt) (VecD A) (Vec A) (λ n xs → P n xs) n (t , c))
→ P n (con (t , c))
)
( (λ q ih →
elimEq (ℕ tt) zero (λ n q → P n (con (here , q)))
pnil
n q
)
, (λ n',x,xs,q ih,tt →
let n' = proj₁ n',x,xs,q
x = proj₁ (proj₂ n',x,xs,q)
xs = proj₁ (proj₂ (proj₂ n',x,xs,q))
q = proj₂ (proj₂ (proj₂ n',x,xs,q))
ih = proj₁ ih,tt
in
elimEq (ℕ tt) (suc n') (λ n q → P n (con (there here , n' , x , xs , q)))
(pcons n' x xs ih )
n q
)
, tt
)
(proj₁ t,c)
(proj₂ t,c)
)
----------------------------------------------------------------------
add : ℕ tt → ℕ tt → ℕ tt
add = elimℕ (λ _ → ℕ tt → ℕ tt)
(λ n → n)
(λ m ih n → suc (ih n))
mult : ℕ tt → ℕ tt → ℕ tt
mult = elimℕ (λ _ → ℕ tt → ℕ tt)
(λ n → zero)
(λ m ih n → add n (ih n))
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = elimVec A (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ n ys → ys)
(λ m x xs ih n ys → cons A (add m n) x (ih n ys))
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = elimVec (Vec A m) (λ n xss → Vec A (mult n m))
(nil A)
(λ n xs xss ih → append A m xs (mult n m) ih)
----------------------------------------------------------------------
module GenericEliminator where
add : ℕ tt → ℕ tt → ℕ tt
add = elim2 ⊤ ℕTD _
(λ n → n)
(λ m ih n → suc (ih n))
tt
mult : ℕ tt → ℕ tt → ℕ tt
mult = elim2 ⊤ ℕTD _
(λ n → zero)
(λ m ih n → add n (ih n))
tt
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = elim2 (ℕ tt) (VecTD A) _
(λ n ys → ys)
(λ m x xs ih n ys → cons A (add m n) x (ih n ys))
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = elim2 (ℕ tt) (VecTD (Vec A m)) _
(nil A)
(λ n xs xss ih → append A m xs (mult n m) ih)
----------------------------------------------------------------------
| 30.088586
| 115
| 0.426566
|
645335b07a46477b413c37f4ae2679b1f4858446
| 2,597
|
agda
|
Agda
|
Cubical/Structures/Relational/Parametrized.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Relational/Parametrized.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Structures/Relational/Parametrized.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-
A parameterized family of structures S can be combined into a single structure:
X ↦ (a : A) → S a X
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Relational.Parameterized where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.RelationalStructure
open import Cubical.Functions.FunExtEquiv
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
open import Cubical.HITs.SetQuotients
open import Cubical.Structures.Parameterized
private
variable
ℓ ℓ₀ ℓ₁ ℓ₁' ℓ₁'' : Level
-- Structured relations
module _ (A : Type ℓ₀) where
ParamRelStr : {S : A → Type ℓ → Type ℓ₁}
→ (∀ a → StrRel (S a) ℓ₁')
→ StrRel (ParamStructure A S) (ℓ-max ℓ₀ ℓ₁')
ParamRelStr ρ R s t =
(a : A) → ρ a R (s a) (t a)
paramSuitableRel : {S : A → Type ℓ → Type ℓ₁} {ρ : ∀ a → StrRel (S a) ℓ₁'}
→ (∀ a → SuitableStrRel (S a) (ρ a))
→ SuitableStrRel (ParamStructure A S) (ParamRelStr ρ)
paramSuitableRel {ρ = ρ} θ .quo (X , f) R r .fst .fst a =
θ a .quo (X , f a) R (r a) .fst .fst
paramSuitableRel {ρ = ρ} θ .quo (X , f) R r .fst .snd a =
θ a .quo (X , f a) R (r a) .fst .snd
paramSuitableRel {ρ = ρ} θ .quo (X , f) R r .snd (q , c) i .fst a =
θ a .quo (X , f a) R (r a) .snd (q a , c a) i .fst
paramSuitableRel {ρ = ρ} θ .quo (X , f) R r .snd (q , c) i .snd a =
θ a .quo (X , f a) R (r a) .snd (q a , c a) i .snd
paramSuitableRel {ρ = ρ} θ .symmetric R r a =
θ a .symmetric R (r a)
paramSuitableRel {ρ = ρ} θ .transitive R R' r r' a =
θ a .transitive R R' (r a) (r' a)
paramSuitableRel {ρ = ρ} θ .set setX =
isSetΠ λ a → θ a .set setX
paramSuitableRel {ρ = ρ} θ .prop propR s t =
isPropΠ λ a → θ a .prop propR (s a) (t a)
paramRelMatchesEquiv : {S : A → Type ℓ → Type ℓ₁}
(ρ : ∀ a → StrRel (S a) ℓ₁') {ι : ∀ a → StrEquiv (S a) ℓ₁''}
→ (∀ a → StrRelMatchesEquiv (ρ a) (ι a))
→ StrRelMatchesEquiv (ParamRelStr ρ) (ParamEquivStr A ι)
paramRelMatchesEquiv ρ μ _ _ e = equivΠCod λ a → μ a _ _ e
paramRelAction : {S : A → Type ℓ → Type ℓ₁} {ρ : ∀ a → StrRel (S a) ℓ₁'}
→ (∀ a → StrRelAction (ρ a))
→ StrRelAction (ParamRelStr ρ)
paramRelAction α .actStr f s a = α a .actStr f (s a)
paramRelAction α .actStrId s = funExt λ a → α a .actStrId (s a)
paramRelAction α .actRel h _ _ r a = α a .actRel h _ _ (r a)
-- Detransitivity of ParamRelStr would depend on choice in general, so
-- we don't get positivity
| 36.577465
| 79
| 0.627262
|
64ac2c543336cb0b84fa2db1b0daeefe4a9710ee
| 2,495
|
agda
|
Agda
|
Cubical/HITs/Ints/DeltaInt/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/Ints/DeltaInt/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/DeltaInt/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
{-
This file defines
deltaIntSec : ∀ b → toInt (fromInt b) ≡ b
succPred : ∀ n → succ (pred n) ≡ n
predSucc : ∀ n → pred (succ n) ≡ n
and proved DeltaInt ≡ DeltaInt by the above functions
succPredEq : DeltaInt ≡ DeltaInt
along with some interval-relevant lemmas
cancelDiamond : ∀ a b i → cancel a b i ≡ cancel (suc a) (suc b) i
cancelTriangle : ∀ a b i → a ⊖ b ≡ cancel a b i
we also have DeltaInt ≡ Int proof
DeltaInt≡Int : DeltaInt ≡ Int
and we transported some proofs from Int to DeltaInt
discreteDeltaInt : Discrete DeltaInt
isSetDeltaInt : isSet DeltaInt
-}
module Cubical.HITs.Ints.DeltaInt.Properties where
open import Cubical.Foundations.Everything
open import Cubical.Data.Nat hiding (zero)
open import Cubical.Data.Int hiding (abs; sgn; _+_)
open import Cubical.HITs.Ints.DeltaInt.Base
open import Cubical.Relation.Nullary using (Discrete)
deltaIntSec : ∀ b → toInt (fromInt b) ≡ b
deltaIntSec (pos n) = refl
deltaIntSec (negsuc n) = refl
cancelDiamond : ∀ a b i → cancel a b i ≡ cancel (suc a) (suc b) i
cancelDiamond a b i j = hcomp (λ k → λ
{ (i = i0) → cancel a b j
; (i = i1) → cancel (suc a) (suc b) (j ∧ k)
; (j = i0) → cancel a b i
; (j = i1) → cancel (suc a) (suc b) (i ∧ k)
}) (cancel a b (i ∨ j))
cancelTriangle : ∀ a b i → a ⊖ b ≡ cancel a b i
cancelTriangle a b i j = hcomp (λ k → λ
{ (i = i0) → a ⊖ b
; (j = i0) → a ⊖ b
; (j = i1) → cancel a b (i ∧ k)
}) (a ⊖ b)
deltaIntRet : ∀ a → fromInt (toInt a) ≡ a
deltaIntRet (x ⊖ 0) = refl
deltaIntRet (0 ⊖ suc y) = refl
deltaIntRet (suc x ⊖ suc y) = deltaIntRet (x ⊖ y) ∙ cancel x y
deltaIntRet (cancel a 0 i) = cancelTriangle a 0 i
deltaIntRet (cancel 0 (suc b) i) = cancelTriangle 0 (suc b) i
deltaIntRet (cancel (suc a) (suc b) i) = deltaIntRet (cancel a b i) ∙ cancelDiamond a b i
DeltaInt≡Int : DeltaInt ≡ Int
DeltaInt≡Int = isoToPath (iso toInt fromInt deltaIntSec deltaIntRet)
discreteDeltaInt : Discrete DeltaInt
discreteDeltaInt = subst Discrete (sym DeltaInt≡Int) discreteInt
isSetDeltaInt : isSet DeltaInt
isSetDeltaInt = subst isSet (sym DeltaInt≡Int) isSetInt
succPred : ∀ n → succ (pred n) ≡ n
succPred (x ⊖ y) i = cancel x y (~ i)
-- cancel (suc a) (suc b) i ≡ cancel a b i
succPred (cancel a b i) = sym (cancelDiamond a b i)
predSucc : ∀ n → pred (succ n) ≡ n
predSucc (x ⊖ y) = succPred (x ⊖ y)
predSucc (cancel a b i) = succPred (cancel a b i)
succPredEq : DeltaInt ≡ DeltaInt
succPredEq = isoToPath (iso succ pred succPred predSucc)
| 28.678161
| 89
| 0.666533
|
36e195039e5ddf8356fe48e74448ea374cdd030f
| 76
|
agda
|
Agda
|
test/Fail/WrongHidingInLambda.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/WrongHidingInLambda.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/WrongHidingInLambda.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module WrongHidingInLambda where
f : (A : Set) -> A -> A
f = \{A} x -> x
| 10.857143
| 32
| 0.539474
|
5915c027213ad78ff6485cfd7eba73b8f2349382
| 2,317
|
agda
|
Agda
|
Numbers/Modulo/ZModule.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Numbers/Modulo/ZModule.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Numbers/Modulo/ZModule.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 Groups.Definition
open import Groups.Abelian.Definition
open import Groups.FiniteGroups.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Setoids.Setoids
open import Sets.FinSet.Definition
open import Sets.FinSet.Lemmas
open import Functions
open import Semirings.Definition
open import Numbers.Modulo.Definition
open import Numbers.Modulo.Addition
open import Orders.Total.Definition
open import Numbers.Modulo.ModuloFunction
open import Numbers.Integers.Definition
open import Numbers.Modulo.Group
open import Modules.Definition
open import Numbers.Integers.RingStructure.Ring
module Numbers.Modulo.ZModule {n : ℕ} (pr : 0 <N n) where
timesNat : ℕ → ℤn n pr → ℤn n pr
timesNat 0 b = record { x = 0 ; xLess = pr }
timesNat (succ x) b = _+n_ pr b (timesNat x b)
times : ℤ → ℤn n pr → ℤn n pr
times (nonneg x) b = timesNat x b
times (negSucc x) b = Group.inverse (ℤnGroup n pr) (timesNat (succ x) b)
dotDistributesLeft : (r : ℤ) → (x y : ℤn n pr) → times r ((_ +n x) y) ≡ (_ +n times r x) (times r y)
dotDistributesLeft (nonneg zero) x y = equalityCommutative (Group.identRight (ℤnGroup n pr))
dotDistributesLeft (nonneg (succ r)) x y rewrite dotDistributesLeft (nonneg r) x y = equalityZn (transitivity (equalityCommutative (modExtracts pr _ _)) (transitivity (applyEquality (mod n pr) (transitivity (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring (ℤn.x x) _ _)) (applyEquality (ℤn.x x +N_) (transitivity (Semiring.commutative ℕSemiring (ℤn.x y) _) (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring _ (ℤn.x (timesNat r y)) (ℤn.x y))) (applyEquality (ℤn.x (timesNat r x) +N_) (Semiring.commutative ℕSemiring (ℤn.x (timesNat r y)) (ℤn.x y))))))) (Semiring.+Associative ℕSemiring (ℤn.x x) _ _))) (modExtracts pr _ _)))
dotDistributesLeft (negSucc r) x y = {!!}
ZnZModule : Module ℤRing (ℤnAbGroup n pr) times
Module.dotWellDefined (ZnZModule) refl refl = refl
Module.dotDistributesLeft (ZnZModule) {r} {x} {y} = dotDistributesLeft r x y
Module.dotDistributesRight (ZnZModule) = {!!}
Module.dotAssociative (ZnZModule) = {!!}
Module.dotIdentity (ZnZModule) {record { x = x ; xLess = xLess }} = {!!}
| 51.488889
| 660
| 0.748382
|
36ed8dedd347f415a41c7373e13ae2c46c89c7d8
| 1,263
|
agda
|
Agda
|
src/Tactic/Monoid/Proofs.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Tactic/Monoid/Proofs.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Tactic/Monoid/Proofs.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Tactic.Monoid.Proofs where
open import Prelude
open import Tactic.Monoid.Exp
⟦_⟧_ : ∀ {a} {A : Set a} {{_ : Monoid A}} → Exp → (Nat → A) → A
⟦ var x ⟧ ρ = ρ x
⟦ ε ⟧ ρ = mempty
⟦ e ⊕ e₁ ⟧ ρ = ⟦ e ⟧ ρ <> ⟦ e₁ ⟧ ρ
⟦_⟧n_ : ∀ {a} {A : Set a} {{_ : Monoid A}} → List Nat → (Nat → A) → A
⟦ xs ⟧n ρ = mconcat (map ρ xs)
map/++ : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) (xs ys : List A) → map f (xs ++ ys) ≡ map f xs ++ map f ys
map/++ f [] ys = refl
map/++ f (x ∷ xs) ys = f x ∷_ $≡ map/++ f xs ys
module _ {a} {A : Set a} {{Mon : Monoid A}} {{Laws : Monoid/Laws A}} where
mconcat/++ : (xs ys : List A) → mconcat (xs ++ ys) ≡ mconcat xs <> mconcat ys
mconcat/++ [] ys = sym (left-identity _)
mconcat/++ (x ∷ xs) ys = x <>_ $≡ mconcat/++ xs ys ⟨≡⟩ sym (monoid-assoc x _ _)
sound : ∀ e (ρ : Nat → A) → ⟦ e ⟧ ρ ≡ ⟦ flatten e ⟧n ρ
sound (var x) ρ = sym (right-identity (ρ x))
sound ε ρ = refl
sound (e ⊕ e₁) ρ = _<>_ $≡ sound e ρ *≡ sound e₁ ρ ⟨≡⟩ʳ
mconcat $≡ map/++ ρ (flatten e) (flatten e₁) ⟨≡⟩
mconcat/++ (map ρ (flatten e)) _
proof : ∀ e e₁ (ρ : Nat → A) → flatten e ≡ flatten e₁ → ⟦ e ⟧ ρ ≡ ⟦ e₁ ⟧ ρ
proof e e₁ ρ nfeq = eraseEquality $ sound e ρ ⟨≡⟩ (⟦_⟧n ρ) $≡ nfeq ⟨≡⟩ʳ sound e₁ ρ
| 37.147059
| 111
| 0.489311
|
6501cea4d42f2d646fb913083a849552cfcf2962
| 385
|
agda
|
Agda
|
src/ConsoleLib.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
src/ConsoleLib.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
src/ConsoleLib.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module ConsoleLib where
open import NativeIO public
open import SizedIO.Console public hiding (main) renaming (translateIOConsole to run)
open import Size
open import SizedIO.Base
open import Data.List
WriteString : (s : String) → IOConsole ∞ Unit
WriteString s = Exec (putStrLn s)
GetLine : IOConsole ∞ String
GetLine = Exec getLine
ConsoleProg : Set
ConsoleProg = NativeIO Unit
| 22.647059
| 86
| 0.784416
|
73343828fd85fd51d3d988887800e0fb074fa060
| 2,577
|
agda
|
Agda
|
Type/Cubical.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Type/Cubical.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Type/Cubical.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical #-}
module Type.Cubical where
import Lvl
open import Type
open import Agda.Primitive public
using (SSet)
open import Agda.Primitive.Cubical public
using ()
renaming (I to Interval) -- _ : SSet(Lvl.𝟎). Inhabitants can be seen as points on a closed unit interval.
module Interval where
open Agda.Primitive.Cubical public
using (
Partial ; -- _ : ∀{ℓ} → Interval → Type{ℓ} → SSet(ℓ)
PartialP -- _ : ∀{ℓ} → (i : Interval) → (.(Is-𝟏 i) → Type{ℓ}) → SSet(ℓ)
)
renaming (
i0 to 𝟎 ; -- _ : Interval. 0 (the initial point) in the interval.
i1 to 𝟏 ; -- _ : Interval. 1 (the terminal point) in the interval.
primIMin to min ; -- _ : Interval → Interval → Interval. Chooses the point nearest 𝟎. Also called: _∧_ (from lattice structure).
primIMax to max ; -- _ : Interval → Interval → Interval. Chooses the point nearest 𝟏. Also called: _∨_ (from lattice structure).
primINeg to flip ; -- _ : Interval → Interval. Flips a point in the interval around the point of symmetry (the middle). Essentially (p ↦ 𝟏 − p).
IsOne to Is-𝟏 ; -- _ : Interval → SSet(Lvl.𝟎). The predicate stating that a point is 𝟏.
itIsOne to 𝟏-is-𝟏 ; -- _ : Is-𝟏(𝟏). Proof of 𝟏 being 𝟏.
primComp to comp ; -- _ : ∀{ℓ : Interval → Lvl.Level} → (P : (i : Interval) → Type{ℓ(i)}) → ∀{i : Interval} → ((j : Interval) → .(Is-𝟏 i) → P(j)) → (P(𝟎) → P(𝟏))
primHComp to hComp ; -- _ : ∀{ℓ}{A : Type{ℓ}}{i : Interval} → (Interval → .(Is-𝟏 i) → A) → (A → A)
primTransp to transp -- _ : ∀{ℓ : Interval → Lvl.Level}(A : (i : Interval) → Type{ℓ(i)}) → Interval → A(𝟎)→ A(𝟏).
)
-- The distance to the nearest boundary.
nearBound : Interval → Interval
nearBound x = min x (flip x)
-- The distance to the furthest boundary.
farBound : Interval → Interval
farBound x = max x (flip x)
-- Proof of maximum of 𝟏 being 𝟏.
maxₗ-is-𝟏 : ∀{x y} → Is-𝟏(x) → Is-𝟏(max x y)
maxₗ-is-𝟏 {x}{y} = Agda.Primitive.Cubical.IsOne1 x y
-- Proof of maximum of 𝟏 being 𝟏.
maxᵣ-is-𝟏 : ∀{x y} → Is-𝟏(y) → Is-𝟏(max x y)
maxᵣ-is-𝟏 {x}{y} = Agda.Primitive.Cubical.IsOne2 x y
-- The predicate stating that a point is 𝟎.
Is-𝟎 : Interval → SSet(Lvl.𝟎)
Is-𝟎 i = Is-𝟏(flip i)
-- Proof of 𝟎 being 𝟎.
𝟎-is-𝟎 : Is-𝟎(𝟎)
𝟎-is-𝟎 = 𝟏-is-𝟏
-- Proof of minimum of 𝟎 being 𝟎.
minₗ-is-𝟎 : ∀{x y} → Is-𝟎(x) → Is-𝟎(min x y)
minₗ-is-𝟎 {x}{y} = maxₗ-is-𝟏 {flip x} {flip y}
-- Proof of minimum of 𝟎 being 𝟎.
minᵣ-is-𝟎 : ∀{x y} → Is-𝟎(y) → Is-𝟎(min x y)
minᵣ-is-𝟎 {x}{y} = maxᵣ-is-𝟏 {flip x} {flip y}
| 39.646154
| 167
| 0.595654
|
37bd9a38cb41cc10fdac09dc59fcc0d9fd0649ba
| 1,501
|
agda
|
Agda
|
src/Polynomial/Homomorphism/Negation.agda
|
mckeankylej/agda-ring-solver
|
f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500
|
[
"MIT"
] | 36
|
2019-01-25T16:40:52.000Z
|
2022-02-15T00:57:55.000Z
|
src/Polynomial/Homomorphism/Negation.agda
|
oisdk/agda-algebra
|
7e4ee048dab68ccb0a8673a6a663a37c1d1f4080
|
[
"MIT"
] | 5
|
2019-04-17T20:48:48.000Z
|
2022-03-12T01:55:42.000Z
|
src/Polynomial/Homomorphism/Negation.agda
|
oisdk/agda-algebra
|
7e4ee048dab68ccb0a8673a6a663a37c1d1f4080
|
[
"MIT"
] | 4
|
2019-04-16T02:23:16.000Z
|
2022-01-20T07:07:11.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Polynomial.Parameters
module Polynomial.Homomorphism.Negation
{c r₁ r₂ r₃}
(homo : Homomorphism c r₁ r₂ r₃)
where
open import Data.Product using (_,_)
open import Data.Vec using (Vec)
open import Induction.WellFounded using (Acc; acc)
open import Induction.Nat using (<′-wellFounded)
open import Function
open Homomorphism homo
open import Polynomial.Homomorphism.Lemmas homo
open import Polynomial.Reasoning ring
open import Polynomial.NormalForm homo
⊟-step-hom : ∀ {n} (a : Acc _<′_ n) → (xs : Poly n) → ∀ ρ → ⟦ ⊟-step a xs ⟧ ρ ≈ - (⟦ xs ⟧ ρ)
⊟-step-hom (acc _ ) (Κ x Π i≤n) ρ = -‿homo x
⊟-step-hom (acc wf) (Σ xs Π i≤n) ρ′ =
let (ρ , ρs) = drop-1 i≤n ρ′
neg-zero =
begin
0#
≈⟨ sym (zeroʳ _) ⟩
- 0# * 0#
≈⟨ -‿*-distribˡ 0# 0# ⟩
- (0# * 0#)
≈⟨ -‿cong (zeroˡ 0#) ⟩
- 0#
∎
in
begin
⟦ poly-map (⊟-step (wf _ i≤n)) xs Π↓ i≤n ⟧ ρ′
≈⟨ Π↓-hom (poly-map (⊟-step (wf _ i≤n)) xs) i≤n ρ′ ⟩
Σ?⟦ poly-map (⊟-step (wf _ i≤n)) xs ⟧ (ρ , ρs)
≈⟨ poly-mapR ρ ρs (⊟-step (wf _ i≤n)) -_ (-‿cong) (λ x y → *-comm x (- y) ⟨ trans ⟩ -‿*-distribˡ y x ⟨ trans ⟩ -‿cong (*-comm _ _)) (λ x y → sym (-‿+-comm x y)) (flip (⊟-step-hom (wf _ i≤n)) ρs) (sym neg-zero ) xs ⟩
- Σ⟦ xs ⟧ (ρ , ρs)
∎
⊟-hom : ∀ {n}
→ (xs : Poly n)
→ (Ρ : Vec Carrier n)
→ ⟦ ⊟ xs ⟧ Ρ ≈ - ⟦ xs ⟧ Ρ
⊟-hom = ⊟-step-hom (<′-wellFounded _)
| 30.02
| 217
| 0.515656
|
0d3710b7bbaa3b91729a65eb25da57631e035a7d
| 252
|
agda
|
Agda
|
test/Fail/InjectiveTypeConstructors.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/InjectiveTypeConstructors.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/InjectiveTypeConstructors.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Needs the --injective-type-constructors option enabled to type check.
module InjectiveTypeConstructors where
data D (A : Set) : Set where
data _==_ (A : Set) : Set → Set where
refl : A == A
injD : ∀ {A B} → D A == D B → A == B
injD refl = refl
| 22.909091
| 72
| 0.638889
|
646c08b4bb7d47f479519685835a90366be98ce2
| 2,857
|
agda
|
Agda
|
cohomology/Torus.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
cohomology/Torus.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
cohomology/Torus.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.Theory
{- Ordinary cohomology groups of the n-torus Tⁿ = (S¹)ⁿ.
- We have Cᵏ(Tⁿ) == C⁰(S⁰)^(n choose' k) where _choose'_ defined as below.
- This argument could give Cᵏ((Sᵐ)ⁿ) with a little more work. -}
module cohomology.Torus {i} (OT : OrdinaryTheory i) where
open OrdinaryTheory OT
open import cohomology.Sn OT
open import cohomology.SphereProduct cohomology-theory
open import cohomology.Unit cohomology-theory
{- Almost n choose k, but with n choose' O = 0 for any n. -}
_choose'_ : ℕ → ℤ → ℕ
n choose' (neg _) = 0
n choose' O = 0
n choose' pos O = n
O choose' (pos (S k)) = 0
S n choose' pos (S k) = (n choose' (pos (S k))) + (n choose' (pos k))
_-⊙Torus : ℕ → Ptd i
O -⊙Torus = ⊙Lift ⊙Unit
(S n) -⊙Torus = (⊙Sphere {i} 1) ⊙× (n -⊙Torus)
C-nTorus : (k : ℤ) (n : ℕ)
→ C k (n -⊙Torus) == (C O (⊙Sphere 0)) ^ᴳ (n choose' k)
C-nTorus (neg k) O = C-Unit (neg k)
C-nTorus (neg k) (S n) =
C-Sphere× (neg k) 1 (n -⊙Torus)
∙ ap (λ K → K ×ᴳ (C (neg k) (n -⊙Torus)
×ᴳ C (neg k) (⊙Susp^ 1 (n -⊙Torus))))
(C-Sphere-≠ (neg k) 1 (ℤ-neg≠pos _ _))
∙ ×ᴳ-unit-l {G = C (neg k) (n -⊙Torus)
×ᴳ C (neg k) (⊙Susp (n -⊙Torus))}
∙ ap (λ K → K ×ᴳ C (neg k) (⊙Susp (n -⊙Torus)))
(C-nTorus (neg k) n)
∙ ×ᴳ-unit-l {G = C (neg k) (⊙Susp (n -⊙Torus))}
∙ group-ua (C-Susp (neg (S k)) (n -⊙Torus))
∙ C-nTorus (neg (S k)) n
C-nTorus O O = C-Unit O
C-nTorus O (S n) =
C-Sphere× O 1 (n -⊙Torus)
∙ ap (λ K → K ×ᴳ (C O (n -⊙Torus) ×ᴳ C O (⊙Susp (n -⊙Torus))))
(C-Sphere-≠ O 1 (ℤ-O≠pos _))
∙ ×ᴳ-unit-l {G = C O (n -⊙Torus) ×ᴳ C O (⊙Susp (n -⊙Torus))}
∙ ap (λ K → K ×ᴳ C O (⊙Susp (n -⊙Torus)))
(C-nTorus O n)
∙ ×ᴳ-unit-l {G = C O (⊙Susp (n -⊙Torus))}
∙ group-ua (C-Susp (neg O) (n -⊙Torus))
∙ C-nTorus (neg O) n
C-nTorus (pos O) O = C-Unit (pos O)
C-nTorus (pos O) (S n) =
C-Sphere× (pos O) 1 (n -⊙Torus)
∙ ap (λ K → K ×ᴳ (C (pos O) (n -⊙Torus)
×ᴳ C (pos O) (⊙Susp (n -⊙Torus))))
(C-Sphere-diag 1)
∙ ap (λ K → C O (⊙Sphere O) ×ᴳ K)
(ap2 _×ᴳ_
(C-nTorus (pos O) n)
(group-ua (C-Susp O (n -⊙Torus)) ∙ C-nTorus O n)
∙ ×ᴳ-unit-r {G = C O (⊙Sphere 0) ^ᴳ (n choose' pos O)})
C-nTorus (pos (S k)) O =
C-Unit (pos (S k))
C-nTorus (pos (S k)) (S n) =
C-Sphere× (pos (S k)) 1 (n -⊙Torus)
∙ ap (λ K → K ×ᴳ (C (pos (S k)) (n -⊙Torus)
×ᴳ C (pos (S k)) (⊙Susp (n -⊙Torus))))
(C-Sphere-≠ (pos (S k)) 1 (ℕ-S≠O k ∘ pos-injective (S k) 0))
∙ ×ᴳ-unit-l {G = (C (pos (S k)) (n -⊙Torus))
×ᴳ (C (pos (S k)) (⊙Susp (n -⊙Torus)))}
∙ ap2 _×ᴳ_ (C-nTorus (pos (S k)) n)
(group-ua (C-Susp (pos k) (n -⊙Torus)) ∙ C-nTorus (pos k) n)
∙ ^ᴳ-sum (C O (⊙Sphere 0)) (n choose' pos (S k)) (n choose' pos k)
| 32.465909
| 75
| 0.502275
|
1171bc539e3ebab02b7887326f81660393085963
| 891
|
agda
|
Agda
|
agda-stdlib-0.9/src/Relation/Binary/Properties/Poset.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/Relation/Binary/Properties/Poset.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Relation/Binary/Properties/Poset.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by posets
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.Properties.Poset
{p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where
open Relation.Binary.Poset P hiding (trans)
import Relation.Binary.NonStrictToStrict as Conv
open Conv _≈_ _≤_
------------------------------------------------------------------------
-- Posets can be turned into strict partial orders
strictPartialOrder : StrictPartialOrder _ _ _
strictPartialOrder = record
{ isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = irrefl
; trans = trans isPartialOrder
; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
}
}
open StrictPartialOrder strictPartialOrder
| 29.7
| 72
| 0.535354
|
0d534d19fb062533309239df92afd9066cdfbef6
| 444
|
agda
|
Agda
|
test/interaction/Issue3578.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3578.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3578.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2019-02-23, issue #3578.
-- Preserve types as much as possible during pattern matching.
-- New unifier (from Agda 2.5.1) was normalizing too much.
-- {-# OPTIONS -v tc.lhs.unify:45 #-}
data Nat : Set where
zero : Nat
postulate
MustNotBeNamed : Set
A = MustNotBeNamed
data P : Nat → Set where
z : A → P zero
test : ∀{n} → P n → Set
test (z x) = {!x!} -- C-c C-,
-- EXPECTED:
--
-- Goal: Set
-- ——————————————
-- x : A
| 17.076923
| 62
| 0.583333
|
72e71509c12418dcbe76ac15850883d74d74da22
| 6,093
|
agda
|
Agda
|
agda/book/Programming_Language_Foundations_in_Agda/x09-747Decidable.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/Programming_Language_Foundations_in_Agda/x09-747Decidable.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/Programming_Language_Foundations_in_Agda/x09-747Decidable.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module 747Decidable where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym) -- added sym
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _≤_; z≤n; s≤s)
open import Data.Product using (_×_) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Relation.Nullary using (¬_)
open import Relation.Nullary.Negation using ()
renaming (contradiction to ¬¬-intro)
open import Data.Unit using (⊤; tt)
open import Data.Empty using (⊥; ⊥-elim)
-- Copied from 747Isomorphism.
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_
-- Copied from 747Relations.
infix 4 _<_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ}
------------
→ zero < suc n
s<s : ∀ {m n : ℕ}
→ m < n
-------------
→ suc m < suc n
-- Recall that the constructors for _≤_ are z≤n and s≤s.
-- Here are a couple of examples to show how to prove inequalities
-- (or their negations).
2≤4 : 2 ≤ 4
2≤4 = {!!}
¬4≤2 : ¬ (4 ≤ 2)
¬4≤2 = {!!}
-- This should be familiar.
data Bool : Set where
true : Bool
false : Bool
-- We can define a Boolean comparison function.
infix 4 _≤ᵇ_
_≤ᵇ_ : ℕ → ℕ → Bool
m ≤ᵇ n = {!!}
-- PLFA steps through these computations using equational reasoning.
_ : (2 ≤ᵇ 4) ≡ true
_ = refl
_ : (4 ≤ᵇ 2) ≡ false
_ = refl
-- Relating evidence and computation.
T : Bool → Set
T true = ⊤
T false = ⊥
T→≡ : ∀ (b : Bool) → T b → b ≡ true
T→≡ b t = {!!}
≡→T : ∀ {b : Bool} → b ≡ true → T b
≡→T e = {!!}
≤ᵇ→≤ : ∀ (m n : ℕ) → T (m ≤ᵇ n) → m ≤ n
≤ᵇ→≤ m n t = {!!}
≤→≤ᵇ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ n)
≤→≤ᵇ m≤n = {!!}
-- Getting the best of both worlds!
data Dec (A : Set) : Set where
yes : A → Dec A
no : ¬ A → Dec A
-- Helpers for defining _≤?_
-- If you don't use these, the examples below won't normalize.
¬s≤z : ∀ {m : ℕ} → ¬ (suc m ≤ zero)
¬s≤z = {!!}
¬s≤s : ∀ {m n : ℕ} → ¬ (m ≤ n) → ¬ (suc m ≤ suc n)
¬s≤s = {!!}
-- Decidable ≤.
_≤?_ : ∀ (m n : ℕ) → Dec (m ≤ n)
m ≤? n = {!!}
_ : 2 ≤? 4 ≡ yes (s≤s (s≤s z≤n))
_ = refl
_ : 4 ≤? 2 ≡ no (¬s≤s (¬s≤s ¬s≤z))
_ = refl
-- We can also evaluate the LHS of these using C-c C-n.
-- 747/PLFA exercise: DecLT (3 point)
-- Decidable strict equality.
-- You will need these helper functions as we did above.
¬z<z : ¬ (zero < zero)
¬z<z = {!!}
¬s<s : ∀ {m n : ℕ} → ¬ (m < n) → ¬ (suc m < suc n)
¬s<s = {!!}
¬s<z : ∀ {n : ℕ} → ¬ (suc n < zero)
¬s<z = {!!}
_<?_ : ∀ (m n : ℕ) → Dec (m < n)
m <? n = {!!}
-- Some tests.
_ : 2 <? 4 ≡ yes (s<s (s<s (z<s)))
_ = refl
_ : 4 <? 2 ≡ no (¬s<s (¬s<s ¬s<z))
_ = refl
_ : 3 <? 3 ≡ no (¬s<s (¬s<s (¬s<s ¬z<z)))
_ = refl
-- 747/PLFA exercise: DecNatEq (3 points)
-- Decidable equality for natural numbers.
_≡ℕ?_ : ∀ (m n : ℕ) → Dec (m ≡ n) -- split m,n
m ≡ℕ? n = {!!}
-- Reusing ≤ᵇ and proofs of equivalence with ≤ to decide ≤.
_≤?′_ : ∀ (m n : ℕ) → Dec (m ≤ n)
m ≤?′ n = {!!}
-- Erasing Dec down to Bool (or "isYes").
⌊_⌋ : ∀ {A : Set} → Dec A → Bool
⌊ yes x ⌋ = true
⌊ no x ⌋ = false
_≤ᵇ′_ : ℕ → ℕ → Bool
m ≤ᵇ′ n = ⌊ m ≤? n ⌋
-- If D is Dec A, then T ⌊ D ⌋ is inhabited exactly when A is inhabited.
toWitness : ∀ {A : Set} {D : Dec A} → T ⌊ D ⌋ → A
toWitness t = {!!}
fromWitness : ∀ {A : Set} {D : Dec A} → A → T ⌊ D ⌋
fromWitness a = {!!}
-- Similar ideas when it is the "no" witnesses we want to handle.
isNo : ∀ {A : Set} → Dec A → Bool
isNo (yes _) = false
isNo (no _) = true
toWitnessFalse : ∀ {A : Set} {D : Dec A} → T (isNo D) → ¬ A
toWitnessFalse = {!!}
fromWitnessFalse : ∀ {A : Set} {D : Dec A} → ¬ A → T (isNo D)
fromWitnessFalse = {!!}
-- Agda standard library definitions for use of these.
True : ∀ {A : Set} → (D : Dec A) → Set
True Q = T ⌊ Q ⌋
False : ∀ {A : Set} → (D : Dec A) → Set
False Q = T (isNo Q)
-- A concrete example.
≤ᵇ′→≤ : ∀ {m n : ℕ} → T (m ≤ᵇ′ n) → m ≤ n
≤ᵇ′→≤ = toWitness
≤→≤ᵇ′ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ′ n)
≤→≤ᵇ′ = fromWitness
-- Conclusion: use Decidables instead of Booleans!
-- Logical connectives for Decidables.
infixr 6 _∧_
_∧_ : Bool → Bool → Bool
true ∧ true = true
true ∧ false = false
false ∧ y = false
infixr 6 _×-dec_
_×-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A × B)
da ×-dec db = {!!}
infixr 5 _∨_
_∨_ : Bool → Bool → Bool
true ∨ y = true
false ∨ y = y
infixr 5 _⊎-dec_
_⊎-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⊎ B)
da ⊎-dec db = {!!}
not : Bool → Bool
not true = false
not false = true
¬? : ∀ {A : Set} → Dec A → Dec (¬ A)
¬? da = {!!}
-- A Boolean version of implication.
_⊃_ : Bool → Bool → Bool
true ⊃ true = true
true ⊃ false = false
false ⊃ y = true
_→-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A → B)
da →-dec db = {!!}
-- 747/PLFA exercise: ErasBoolDec (3 points)
-- Erasure relates boolean and decidable operations.
∧-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∧ ⌊ y ⌋ ≡ ⌊ x ×-dec y ⌋
∧-× da db = {!!}
∨-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∨ ⌊ y ⌋ ≡ ⌊ x ⊎-dec y ⌋
∨-× da db = {!!}
not-¬ : ∀ {A : Set} (x : Dec A) → not ⌊ x ⌋ ≡ ⌊ ¬? x ⌋
not-¬ da = {!!}
-- 747/PLFA exercise: iff-erasure.
_iff_ : Bool → Bool → Bool
true iff true = true
true iff false = false
false iff true = false
false iff false = true
_⇔-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⇔ B)
da ⇔-dec db = {!!}
iff-⇔ : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ iff ⌊ y ⌋ ≡ ⌊ x ⇔-dec y ⌋
iff-⇔ da db = {!!}
-- Proof by reflection.
-- Or, getting Agda to construct proofs at compile time.
-- A guarded version of monus.
minus : (m n : ℕ) (n≤m : n ≤ m) → ℕ
minus m zero _ = m
minus (suc m) (suc n) (s≤s m≤n) = minus m n m≤n
-- But we have to provide proofs.
_ : minus 5 3 (s≤s (s≤s (s≤s z≤n))) ≡ 2
_ = refl
-- Agda will fill in an implicit record type if it can fill in all fields.
-- Since ⊤ is defined as a record type with no fields...
-- We can get Agda to compute a value of type True (n ≤? m).
_-_ : (m n : ℕ) {n≤m : True (n ≤? m)} → ℕ
_-_ m n {n≤m} = minus m n (toWitness n≤m)
_ : 5 - 3 ≡ 2
_ = refl
-- We will later use this to get Agda to compute parts of proofs
-- that would be annoying for us to provide.
| 20.31
| 80
| 0.529952
|
ed7cc09c610ff4fa52a4e7137e6f27f937a6afb2
| 2,802
|
agda
|
Agda
|
agda-stdlib/src/Data/Fin/Subset.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Fin/Subset.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Fin/Subset.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Subsets of finite sets
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Subset where
open import Algebra
import Algebra.Properties.BooleanAlgebra as BoolAlgProp
import Algebra.Properties.BooleanAlgebra.Expression as BAExpr
open import Data.Bool using (not; _∧_; _∨_; _≟_)
open import Data.Fin.Base using (Fin; zero; suc)
open import Data.List.Base using (List; foldr; foldl)
open import Data.Nat.Base using (ℕ)
open import Data.Product using (∃; _×_)
open import Data.Vec hiding (foldr; foldl)
import Data.Vec.Relation.Binary.Pointwise.Extensional as Pointwise
open import Relation.Nullary
------------------------------------------------------------------------
-- Definitions
-- Sides.
open import Data.Bool.Base public
using () renaming (Bool to Side; true to inside; false to outside)
-- Partitions a finite set into two parts, the inside and the outside.
Subset : ℕ → Set
Subset = Vec Side
------------------------------------------------------------------------
-- Special subsets
-- The empty subset
⊥ : ∀ {n} → Subset n
⊥ = replicate outside
-- The full subset
⊤ : ∀ {n} → Subset n
⊤ = replicate inside
-- A singleton subset, containing just the given element.
⁅_⁆ : ∀ {n} → Fin n → Subset n
⁅ zero ⁆ = inside ∷ ⊥
⁅ suc i ⁆ = outside ∷ ⁅ i ⁆
------------------------------------------------------------------------
-- Membership and subset predicates
infix 4 _∈_ _∉_ _⊆_ _⊈_ _⊂_ _⊄_
_∈_ : ∀ {n} → Fin n → Subset n → Set
x ∈ p = p [ x ]= inside
_∉_ : ∀ {n} → Fin n → Subset n → Set
x ∉ p = ¬ (x ∈ p)
_⊆_ : ∀ {n} → Subset n → Subset n → Set
p ⊆ q = ∀ {x} → x ∈ p → x ∈ q
_⊈_ : ∀ {n} → Subset n → Subset n → Set
p ⊈ q = ¬ (p ⊆ q)
_⊂_ : ∀ {n} → Subset n → Subset n → Set
p ⊂ q = p ⊆ q × ∃ (λ x → x ∈ q × x ∉ p)
_⊄_ : ∀ {n} → Subset n → Subset n → Set
p ⊄ q = ¬ (p ⊂ q)
------------------------------------------------------------------------
-- Set operations
infixr 7 _∩_
infixr 6 _∪_
-- Complement
∁ : ∀ {n} → Op₁ (Subset n)
∁ p = map not p
-- Intersection
_∩_ : ∀ {n} → Op₂ (Subset n)
p ∩ q = zipWith _∧_ p q
-- Union
_∪_ : ∀ {n} → Op₂ (Subset n)
p ∪ q = zipWith _∨_ p q
-- N-ary union
⋃ : ∀ {n} → List (Subset n) → Subset n
⋃ = foldr _∪_ ⊥
-- N-ary intersection
⋂ : ∀ {n} → List (Subset n) → Subset n
⋂ = foldr _∩_ ⊤
-- Size
∣_∣ : ∀ {n} → Subset n → ℕ
∣ p ∣ = count (_≟ inside) p
------------------------------------------------------------------------
-- Properties
Nonempty : ∀ {n} (p : Subset n) → Set
Nonempty p = ∃ λ f → f ∈ p
Empty : ∀ {n} (p : Subset n) → Set
Empty p = ¬ Nonempty p
Lift : ∀ {n ℓ} → (Fin n → Set ℓ) → (Subset n → Set ℓ)
Lift P p = ∀ {x} → x ∈ p → P x
| 24.155172
| 72
| 0.48858
|
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.