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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
23d90b19744b8c64b80947cdcd77daf770182982
| 7,987
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/RawAlgebra.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/RingSolver/RawAlgebra.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/RingSolver/RawAlgebra.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.RawAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Int renaming (_+_ to _+ℤ_ ; _·_ to _·ℤ_ ; -_ to -ℤ_ ; _-_ to _-ℤ_ ; +Assoc to +ℤAssoc ; +Comm to +ℤComm ; -DistL· to -ℤDistL·ℤ)
open import Cubical.Algebra.RingSolver.AlmostRing hiding (⟨_⟩)
open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
open import Cubical.Algebra.RingSolver.IntAsRawRing
open import Cubical.Algebra.RingSolver.CommRingAsAlmostRing
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
private
variable
ℓ ℓ′ : Level
record RawAlgebra (R : RawRing ℓ) (ℓ′ : Level) : Type (ℓ-suc (ℓ-max ℓ ℓ′)) where
constructor rawalgebra
field
Carrier : Type ℓ′
scalar : ⟨ R ⟩ᵣ → Carrier
0r : Carrier
1r : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
infixl 8 _·_
infixl 7 -_
infixl 6 _+_
⟨_⟩ : {R : RawRing ℓ} → RawAlgebra R ℓ′ → Type ℓ′
⟨_⟩ = RawAlgebra.Carrier
{-
Mapping to integer scalars and its (homorphism) properties.
-}
module _ (R : CommRing ℓ) where
open CommRingStr (snd R)
open Cubical.Algebra.Ring.RingTheory (CommRing→Ring R)
scalarℕ : ℕ → (fst R)
scalarℕ ℕ.zero = 0r
scalarℕ (ℕ.suc ℕ.zero) = 1r
scalarℕ (ℕ.suc (ℕ.suc n)) = 1r + scalarℕ (ℕ.suc n)
scalar : ℤ → (fst R)
scalar (pos k) = scalarℕ k
scalar (negsuc k) = - scalarℕ (ℕ.suc k)
-DistScalar : (k : ℤ)
→ scalar (-ℤ k) ≡ - (scalar k)
-DistScalar (pos ℕ.zero) = sym 0Selfinverse
-DistScalar (pos (ℕ.suc n)) = refl
-DistScalar (negsuc n) = sym (-Idempotent _)
lemmaSuc : (k : ℤ)
→ scalar (sucℤ k) ≡ 1r + scalar k
lemmaSuc (pos ℕ.zero) = sym (+Rid _)
lemmaSuc (pos (ℕ.suc ℕ.zero)) = refl
lemmaSuc (pos (ℕ.suc (ℕ.suc n))) = refl
lemmaSuc (negsuc ℕ.zero) = sym (+Rinv _)
lemmaSuc (negsuc (ℕ.suc n)) =
scalar (negsuc n) ≡⟨ sym (+Lid (scalar (negsuc n))) ⟩
0r + scalar (negsuc n) ≡[ i ]⟨ +Rinv 1r (~ i) + scalar (negsuc n) ⟩
(1r - 1r) + scalar (negsuc n) ≡⟨ sym (+Assoc _ _ _) ⟩
1r + (- 1r + - scalar (pos (ℕ.suc n))) ≡[ i ]⟨ 1r + -Dist 1r (scalar (pos (ℕ.suc n))) i ⟩
1r + -(1r + scalar (pos (ℕ.suc n))) ≡⟨ refl ⟩
1r + -(scalar (pos (ℕ.suc (ℕ.suc n)))) ≡⟨ refl ⟩
1r + scalar (negsuc (ℕ.suc n)) ∎
lemmaPred : (k : ℤ)
→ scalar (predℤ k) ≡ - 1r + scalar k
lemmaPred k = sym(
- 1r + scalar k ≡[ i ]⟨ - 1r + scalar (sucPred k (~ i)) ⟩
- 1r + scalar (sucℤ (predℤ k)) ≡[ i ]⟨ - 1r + lemmaSuc (predℤ k) i ⟩
- 1r + (1r + scalar (predℤ k)) ≡⟨ +Assoc _ _ _ ⟩
(- 1r + 1r) + scalar (predℤ k) ≡[ i ]⟨ +Linv 1r i + scalar (predℤ k) ⟩
0r + scalar (predℤ k) ≡⟨ +Lid _ ⟩
scalar (predℤ k) ∎)
+HomScalar : (k l : ℤ)
→ scalar (k +ℤ l) ≡ (scalar k) + (scalar l)
+HomScalar (pos ℕ.zero) l =
scalar (0 +ℤ l) ≡[ i ]⟨ scalar (sym (pos0+ l) i) ⟩
scalar l ≡⟨ sym (+Lid _) ⟩
0r + scalar l ≡⟨ refl ⟩
scalar 0 + scalar l ∎
+HomScalar (pos (ℕ.suc ℕ.zero)) l =
scalar (1 +ℤ l) ≡[ i ]⟨ scalar (+ℤComm 1 l i) ⟩
scalar (l +ℤ 1) ≡⟨ refl ⟩
scalar (sucℤ l) ≡⟨ lemmaSuc l ⟩
1r + scalar l ≡⟨ refl ⟩
scalar (pos (ℕ.suc ℕ.zero)) + scalar l ∎
+HomScalar (pos (ℕ.suc (ℕ.suc n))) l =
scalar (pos (ℕ.suc (ℕ.suc n)) +ℤ l) ≡⟨ refl ⟩
scalar ((pos (ℕ.suc n) +ℤ 1) +ℤ l) ≡[ i ]⟨ scalar ((+ℤComm (pos (ℕ.suc n)) 1 i) +ℤ l) ⟩
scalar ((1 +ℤ (pos (ℕ.suc n))) +ℤ l) ≡[ i ]⟨ scalar (+ℤAssoc 1 (pos (ℕ.suc n)) l (~ i)) ⟩
scalar (1 +ℤ (pos (ℕ.suc n) +ℤ l)) ≡⟨ +HomScalar (pos (ℕ.suc ℕ.zero)) (pos (ℕ.suc n) +ℤ l) ⟩
scalar 1 + scalar (pos (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩
1r + (scalar (pos (ℕ.suc n) +ℤ l)) ≡[ i ]⟨ 1r + +HomScalar (pos (ℕ.suc n)) l i ⟩
1r + (scalar (pos (ℕ.suc n)) + scalar l) ≡⟨ +Assoc _ _ _ ⟩
(1r + scalar (pos (ℕ.suc n))) + scalar l ≡⟨ refl ⟩
scalar (pos (ℕ.suc (ℕ.suc n))) + scalar l ∎
+HomScalar (negsuc ℕ.zero) l =
scalar (-1 +ℤ l) ≡[ i ]⟨ scalar (+ℤComm -1 l i) ⟩
scalar (l +ℤ -1) ≡⟨ refl ⟩
scalar (predℤ l) ≡⟨ lemmaPred l ⟩
- 1r + scalar l ≡⟨ refl ⟩
scalar -1 + scalar l ∎
+HomScalar (negsuc (ℕ.suc n)) l =
scalar (negsuc (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩
scalar ((negsuc n +ℤ -1) +ℤ l) ≡[ i ]⟨ scalar (+ℤComm (negsuc n) -1 i +ℤ l) ⟩
scalar ((-1 +ℤ negsuc n) +ℤ l) ≡[ i ]⟨ scalar (+ℤAssoc -1 (negsuc n) l (~ i)) ⟩
scalar (-1 +ℤ (negsuc n +ℤ l)) ≡⟨ +HomScalar -1 (negsuc n +ℤ l) ⟩
- 1r + scalar (negsuc n +ℤ l) ≡[ i ]⟨ - 1r + +HomScalar (negsuc n) l i ⟩
- 1r + (scalar (negsuc n) + scalar l) ≡⟨ +Assoc (- 1r) _ _ ⟩
(- 1r + (scalar (negsuc n))) + scalar l ≡⟨ refl ⟩
(- 1r + - scalar (pos (ℕ.suc n))) + scalar l ≡[ i ]⟨ -Dist 1r (scalar (pos (ℕ.suc n))) i + scalar l ⟩
(- (1r + scalar (pos (ℕ.suc n)))) + scalar l ≡⟨ refl ⟩
scalar (negsuc (ℕ.suc n)) + scalar l ∎
lemma1 : (n : ℕ)
→ 1r + scalar (pos n) ≡ scalar (pos (ℕ.suc n))
lemma1 ℕ.zero = +Rid _
lemma1 (ℕ.suc k) = refl
lemma-1 : (n : ℕ)
→ - 1r + scalar (negsuc n) ≡ scalar (negsuc (ℕ.suc n))
lemma-1 ℕ.zero = -Dist _ _
lemma-1 (ℕ.suc k) =
- 1r + scalar (negsuc (ℕ.suc k)) ≡⟨ refl ⟩
- 1r + - scalar (pos (ℕ.suc (ℕ.suc k))) ≡⟨ -Dist _ _ ⟩
- (1r + scalar (pos (ℕ.suc (ℕ.suc k)))) ≡⟨ refl ⟩
scalar (negsuc (ℕ.suc (ℕ.suc k))) ∎
·HomScalar : (k l : ℤ)
→ scalar (k ·ℤ l) ≡ scalar k · scalar l
·HomScalar (pos ℕ.zero) l = 0r ≡⟨ sym (0LeftAnnihilates (scalar l)) ⟩ 0r · scalar l ∎
·HomScalar (pos (ℕ.suc n)) l =
scalar (l +ℤ (pos n ·ℤ l)) ≡⟨ +HomScalar l (pos n ·ℤ l) ⟩
scalar l + scalar (pos n ·ℤ l) ≡[ i ]⟨ scalar l + ·HomScalar (pos n) l i ⟩
scalar l + (scalar (pos n) · scalar l) ≡[ i ]⟨ ·Lid (scalar l) (~ i) + (scalar (pos n) · scalar l) ⟩
1r · scalar l + (scalar (pos n) · scalar l) ≡⟨ sym (·Ldist+ 1r _ _) ⟩
(1r + scalar (pos n)) · scalar l ≡[ i ]⟨ lemma1 n i · scalar l ⟩
scalar (pos (ℕ.suc n)) · scalar l ∎
·HomScalar (negsuc ℕ.zero) l =
scalar (-ℤ l) ≡⟨ -DistScalar l ⟩
- scalar l ≡[ i ]⟨ - (·Lid (scalar l) (~ i)) ⟩
- (1r · scalar l) ≡⟨ sym (-DistL· _ _) ⟩
- 1r · scalar l ≡⟨ refl ⟩
scalar (negsuc ℕ.zero) · scalar l ∎
·HomScalar (negsuc (ℕ.suc n)) l =
scalar ((-ℤ l) +ℤ (negsuc n ·ℤ l)) ≡⟨ +HomScalar (-ℤ l) (negsuc n ·ℤ l) ⟩
scalar (-ℤ l) + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ -DistScalar l i + scalar (negsuc n ·ℤ l) ⟩
- scalar l + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ - scalar l + ·HomScalar (negsuc n) l i ⟩
- scalar l + scalar (negsuc n) · scalar l ≡[ i ]⟨ (- ·Lid (scalar l) (~ i))
+ scalar (negsuc n) · scalar l ⟩
- (1r · scalar l) + scalar (negsuc n) · scalar l ≡[ i ]⟨ -DistL· 1r (scalar l) (~ i)
+ scalar (negsuc n) · scalar l ⟩
- 1r · scalar l + scalar (negsuc n) · scalar l ≡⟨ sym (·Ldist+ _ _ _) ⟩
(- 1r + scalar (negsuc n)) · scalar l ≡[ i ]⟨ lemma-1 n i · scalar l ⟩
scalar (negsuc (ℕ.suc n)) · scalar l ∎
CommRing→RawℤAlgebra : CommRing ℓ → RawAlgebra ℤAsRawRing ℓ
CommRing→RawℤAlgebra (R , commringstr 0r 1r _+_ _·_ -_ isCommRing) =
rawalgebra R (scalar ((R , commringstr 0r 1r _+_ _·_ -_ isCommRing))) 0r 1r _+_ _·_ -_
| 44.372222
| 152
| 0.493928
|
cbe5702d8fac49ab9b3a8b3ef3fb97b2ca52495e
| 2,003
|
agda
|
Agda
|
Data/Binary/Multiplication/Properties.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Data/Binary/Multiplication/Properties.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Data/Binary/Multiplication/Properties.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Data.Binary.Multiplication.Properties where
open import Prelude
open import Data.Binary.Definition
open import Data.Binary.Addition
open import Data.Binary.Addition.Properties using (+-cong)
open import Data.Binary.Multiplication
open import Data.Binary.Conversion
import Data.Nat as ℕ
import Data.Nat.Properties as ℕ
open import Path.Reasoning
open import Data.Binary.Isomorphism
double-cong : ∀ xs → ⟦ double xs ⇓⟧ ≡ ⟦ xs ⇓⟧ ℕ.* 2
double-cong 0ᵇ i = zero
double-cong (1ᵇ xs) i = 2 ℕ.+ double-cong xs i ℕ.* 2
double-cong (2ᵇ xs) i = ⟦ 2ᵇ 1ᵇ xs ⇓⟧
double-plus : ∀ x → x ℕ.+ x ≡ x ℕ.* 2
double-plus x = cong (x ℕ.+_) (sym (ℕ.+-idʳ x)) ; ℕ.*-comm 2 x
lemma₁ : ∀ x y → x ℕ.* y ℕ.* 2 ≡ y ℕ.* 2 ℕ.* x
lemma₁ x y =
x ℕ.* y ℕ.* 2 ≡⟨ ℕ.*-assoc x y 2 ⟩
x ℕ.* (y ℕ.* 2) ≡⟨ ℕ.*-comm x (y ℕ.* 2) ⟩
y ℕ.* 2 ℕ.* x ∎
lemma₂ : ∀ x y → (x ℕ.+ x ℕ.* y) ℕ.* 2 ≡ x ℕ.+ (x ℕ.+ y ℕ.* 2 ℕ.* x)
lemma₂ x y =
(x ℕ.+ x ℕ.* y) ℕ.* 2 ≡⟨ ℕ.+-*-distrib x (x ℕ.* y) 2 ⟩
x ℕ.* 2 ℕ.+ x ℕ.* y ℕ.* 2 ≡⟨ cong₂ ℕ._+_ (sym (double-plus x)) (lemma₁ x y) ⟩
x ℕ.+ x ℕ.+ y ℕ.* 2 ℕ.* x ≡⟨ ℕ.+-assoc x x (y ℕ.* 2 ℕ.* x) ⟩
x ℕ.+ (x ℕ.+ y ℕ.* 2 ℕ.* x) ∎
*-cong : ∀ xs ys → ⟦ xs * ys ⇓⟧ ≡ ⟦ xs ⇓⟧ ℕ.* ⟦ ys ⇓⟧
*-cong 0ᵇ ys = refl
*-cong (1ᵇ xs) ys =
⟦ ys + double (ys * xs) ⇓⟧ ≡⟨ +-cong ys (double (ys * xs)) ⟩
⟦ ys ⇓⟧ ℕ.+ ⟦ double (ys * xs) ⇓⟧ ≡⟨ cong (⟦ ys ⇓⟧ ℕ.+_) (double-cong (ys * xs)) ⟩
⟦ ys ⇓⟧ ℕ.+ ⟦ ys * xs ⇓⟧ ℕ.* 2 ≡⟨ cong (⟦ ys ⇓⟧ ℕ.+_) (cong (ℕ._* 2) (*-cong ys xs)) ⟩
⟦ ys ⇓⟧ ℕ.+ ⟦ ys ⇓⟧ ℕ.* ⟦ xs ⇓⟧ ℕ.* 2 ≡⟨ cong (⟦ ys ⇓⟧ ℕ.+_) (lemma₁ ⟦ ys ⇓⟧ ⟦ xs ⇓⟧) ⟩
⟦ ys ⇓⟧ ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2 ℕ.* ⟦ ys ⇓⟧ ∎
*-cong (2ᵇ xs) ys =
⟦ double (ys + ys * xs) ⇓⟧ ≡⟨ double-cong (ys + ys * xs) ⟩
⟦ ys + ys * xs ⇓⟧ ℕ.* 2 ≡⟨ cong (ℕ._* 2) (+-cong ys (ys * xs)) ⟩
(⟦ ys ⇓⟧ ℕ.+ ⟦ ys * xs ⇓⟧) ℕ.* 2 ≡⟨ cong (ℕ._* 2) (cong (⟦ ys ⇓⟧ ℕ.+_) (*-cong ys xs)) ⟩
(⟦ ys ⇓⟧ ℕ.+ ⟦ ys ⇓⟧ ℕ.* ⟦ xs ⇓⟧) ℕ.* 2 ≡⟨ lemma₂ ⟦ ys ⇓⟧ ⟦ xs ⇓⟧ ⟩
⟦ ys ⇓⟧ ℕ.+ (⟦ ys ⇓⟧ ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2 ℕ.* ⟦ ys ⇓⟧) ∎
| 39.27451
| 90
| 0.484274
|
c53c76a27ad96ea668d9619b4a9170958c52f48c
| 483
|
agda
|
Agda
|
agda-stdlib/src/Data/List/All.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/All.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/All.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use Data.List.Relation.Unary.All
-- directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.All where
open import Data.List.Relation.Unary.All public
{-# WARNING_ON_IMPORT
"Data.List.All was deprecated in v1.0.
Use Data.List.Relation.Unary.All instead."
#-}
| 26.833333
| 72
| 0.509317
|
df13e37661abe85b7f6fd33121a789f47279c4fa
| 1,993
|
agda
|
Agda
|
Cubical/Displayed/Subst.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/Displayed/Subst.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/Displayed/Subst.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
{-
Given a type A with a UARel and a family B over A,
a SubstRel on B is a family of functions a ≅ a' → B a ≃ B a' path-equal to transport in that family.
Any SubstRel gives rise to a DUARel in which b and b' are related over p when the transport of b along p is
equial to b'.
-}
{-# OPTIONS --safe #-}
module Cubical.Displayed.Subst where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Displayed.Base
private
variable
ℓA ℓ≅A ℓB : Level
record SubstRel {A : Type ℓA} {ℓ≅A : Level} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB)
: Type (ℓ-max (ℓ-max ℓA ℓB) ℓ≅A)
where
no-eta-equality
constructor substrel
open UARel 𝒮-A
field
act : {a a' : A} → a ≅ a' → B a ≃ B a'
uaˢ : {a a' : A} (p : a ≅ a') (b : B a) → subst B (≅→≡ p) b ≡ equivFun (act p) b
uaˢ⁻ : {a a' : A} (p : a ≅ a') (b : B a') → subst B (sym (≅→≡ p)) b ≡ invEq (act p) b
uaˢ⁻ p b =
subst B (sym (≅→≡ p)) b
≡⟨ cong (subst B (sym (≅→≡ p))) (sym (retEq (act p) b)) ⟩
subst B (sym (≅→≡ p)) (equivFun (act p) (invEq (act p) b))
≡⟨ cong (subst B (sym (≅→≡ p))) (sym (uaˢ p (invEq (act p) b))) ⟩
subst B (sym (≅→≡ p)) (subst B (≅→≡ p) (invEq (act p) b))
≡⟨ pathToIso (cong B (≅→≡ p)) .Iso.leftInv (invEq (act p) b) ⟩
invEq (act p) b
∎
Subst→DUA : {A : Type ℓA} {ℓ≅A : Level} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB}
→ SubstRel 𝒮-A B → DUARel 𝒮-A B ℓB
DUARel._≅ᴰ⟨_⟩_ (Subst→DUA 𝒮ˢ-B) b p b' =
equivFun (SubstRel.act 𝒮ˢ-B p) b ≡ b'
DUARel.uaᴰ (Subst→DUA {𝒮-A = 𝒮-A} {B = B} 𝒮ˢ-B) b p b' =
equivFun (SubstRel.act 𝒮ˢ-B p) b ≡ b'
≃⟨ invEquiv (compPathlEquiv (sym (SubstRel.uaˢ 𝒮ˢ-B p b))) ⟩
subst B (≅→≡ p) b ≡ b'
≃⟨ invEquiv (PathP≃Path (λ i → B (≅→≡ p i)) b b') ⟩
PathP (λ i → B (UARel.≅→≡ 𝒮-A p i)) b b'
■
where
open UARel 𝒮-A
| 32.672131
| 109
| 0.581535
|
df97b058cfa6a1113d52fd7dac91f64614d37bc0
| 5,132
|
agda
|
Agda
|
src-focusing/Library.agda
|
andreasabel/ipl
|
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
|
[
"Unlicense"
] | 19
|
2018-05-16T08:08:51.000Z
|
2021-04-27T19:10:49.000Z
|
src-focusing/Library.agda
|
andreasabel/ipl
|
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
|
[
"Unlicense"
] | null | null | null |
src-focusing/Library.agda
|
andreasabel/ipl
|
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
|
[
"Unlicense"
] | 2
|
2018-11-13T16:01:46.000Z
|
2021-02-25T20:39:03.000Z
|
{-# OPTIONS --rewriting #-}
-- Interface to the standard library.
-- Place to add own auxiliary definitions.
module Library where
open import Size public
open import Level public using () renaming (zero to lzero)
open import Data.Unit public using (⊤)
open import Data.Empty public using (⊥; ⊥-elim)
open import Data.Product public using (Σ; ∃; _×_; _,_; proj₁; proj₂; <_,_>; curry; uncurry) renaming (map to map-×)
open import Data.Sum public using (_⊎_; inj₁; inj₂; [_,_]; [_,_]′) renaming (map to map-⊎)
open import Data.List public using (List; []; _∷_) hiding (module List)
open import Data.List.Relation.Unary.All public using (All; []; _∷_) hiding (module All)
open import Data.List.Relation.Unary.Any public using (here; there)
open import Data.List.Membership.Propositional public using (_∈_)
open import Data.List.Relation.Binary.Sublist.Propositional public using (_⊆_; []; _∷_; _∷ʳ_; ⊆-refl; ⊆-trans) renaming (lookup to ⊆-lookup)
open import Function public using (_∘_; _∘′_; id; _$_; _ˢ_; case_of_; const; flip)
open import Relation.Binary.PropositionalEquality public using (_≡_; refl; sym; trans; cong; cong₂; subst; _≗_)
{-# BUILTIN REWRITE _≡_ #-}
module All where
open import Data.List.Relation.Unary.All public
module Any where
open import Data.List.Relation.Unary.Any public
-- open import Axiom.Extensionality.Propositional public using (Extensionality)
-- postulate
-- funExt : ∀{a b} → Extensionality a b -- inline to avoid library incomp.
postulate
funExt : ∀{a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x}
→ (∀ x → f x ≡ g x)
→ f ≡ g
funExtH : ∀{a b} {A : Set a} {B : A → Set b} {f g : {x : A} → B x}
→ (∀ {x} → f {x} ≡ g {x})
→ (λ {x} → f {x}) ≡ g
⊥-elim-ext : ∀{a b} {A : Set a} {B : Set b} {f : A → ⊥} {g : A → B} → ⊥-elim {b} {B} ∘ f ≡ g
⊥-elim-ext {f = f} = funExt λ a → ⊥-elim (f a)
cong₃ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
(f : A → B → C → D) {a a' b b' c c'} → a ≡ a' → b ≡ b' → c ≡ c' → f a b c ≡ f a' b' c'
cong₃ f refl refl refl = refl
_×̇_ : ∀{A B C D : Set} → (A → C) → (B → D) → A × B → C × D
(f ×̇ g) (x , y) = f x , g y
-- Application (S-combinator)
apply : ∀{A B C : Set} (f : C → A → B) (d : C → A) → C → B
apply f a = λ c → f c (a c)
-- Kripke application
kapply : ∀{A B C D : Set} (f : C → A → B) (τ : D → C) (d : D → A) → D → B
kapply f τ a = apply (f ∘ τ) a
-- kapply f τ a = λ d → f (τ d) (a d)
caseof : ∀{A B C D : Set} (f : C → A ⊎ B) (g : C × A → D) (h : C × B → D) → C → D
caseof f g h = λ c → [ curry g c , curry h c ]′ (f c)
sum-eta : ∀{A B : Set} (x : A ⊎ B) → [ inj₁ , inj₂ ] x ≡ x
sum-eta (inj₁ x) = refl
sum-eta (inj₂ y) = refl
caseof-eta : ∀{A B C : Set} (f : C → A ⊎ B) → caseof f (inj₁ ∘ proj₂) (inj₂ ∘ proj₂) ≡ f
caseof-eta f = funExt λ c → sum-eta (f c)
sum-perm : ∀{A B C D : Set} (k : C → D) {g : A → C} {h : B → C} (x : A ⊎ B) →
[ k ∘ g , k ∘ h ]′ x ≡ k ([ g , h ]′ x)
sum-perm k (inj₁ x) = refl
sum-perm k (inj₂ y) = refl
caseof-perm' : ∀{A B C D E : Set}
(k : C → D → E) {f : C → A ⊎ B} {g : C × A → D} {h : C × B → D} →
caseof f (apply (k ∘ proj₁) g) (apply (k ∘ proj₁) h)
≡ apply k (caseof f g h)
caseof-perm' k {f} = funExt λ c → sum-perm (k c) (f c)
caseof-perm : ∀{A B C D E : Set} (k : D → E) {f : C → A ⊎ B} {g : C × A → D} {h : C × B → D}
→ caseof f (k ∘ g) (k ∘ h) ≡ k ∘ caseof f g h
caseof-perm = caseof-perm' ∘ const
caseof-wk : ∀{A B C D E : Set} (k : D → C) {f : C → A ⊎ B} {g : C × A → E} {h : C × B → E}
→ caseof (f ∘ k) (g ∘ (k ×̇ id)) (h ∘ (k ×̇ id)) ≡ caseof f g h ∘ k
caseof-wk {A} {B} {C} {D} {E} k {f} {g} {h} = refl
caseof-apply : ∀{A B C D E : Set}
(f : C → A ⊎ B) {g : C × A → D → E} {h : C × B → D → E} (d : C → D)
→ caseof f (apply g (d ∘ proj₁)) (apply h (d ∘ proj₁))
≡ apply (caseof f g h) d
caseof-apply f {g} {h} d = funExt λ c → sum-perm (λ z → z (d c)) {curry g c} {curry h c} (f c)
-- caseof-apply {A} {B} {C} {D} {E} d {f} {g} {h} = funExt λ c → aux (f c)
-- where
-- aux : ∀ {c : C} (w : A ⊎ B) →
-- [ (λ y → curry g c y (d c)) , (λ y → curry h c y (d c)) ]′ w ≡
-- [ curry g c , curry h c ]′ w (d c)
-- aux (inj₁ a) = refl
-- aux (inj₂ b) = refl
-- caseof (f ∘ τ)
-- (apply (g ∘ (τ ×̇ id)) (a ∘ proj₁))
-- (apply (h ∘ (τ ×̇ id)) (a ∘ proj₁))
-- ≡
-- apply (caseof f g h ∘ τ) a
caseof-kapply : ∀{A B C D E F : Set}
(f : C → A ⊎ B) (g : C × A → E → F) (h : C × B → E → F) (τ : D → C) (a : D → E)
→ caseof (f ∘ τ)
(kapply g (τ ×̇ id) (a ∘ proj₁))
(kapply h (τ ×̇ id) (a ∘ proj₁))
≡
kapply (caseof f g h) τ a
caseof-kapply f g h τ a = caseof-apply (f ∘ τ) a
caseof-swap : ∀{A B C D X Y : Set}
(f : C → X ⊎ Y)
(i : C × X → A ⊎ B)
(j : C × Y → A ⊎ B)
(g : C → A → D)
(h : C → B → D) →
caseof f (caseof i (uncurry (g ∘ proj₁)) (uncurry (h ∘ proj₁)))
(caseof j (uncurry (g ∘ proj₁)) (uncurry (h ∘ proj₁)))
≡ caseof (caseof f i j) (uncurry g) (uncurry h)
caseof-swap {A} {B} {C} {D} {X} {Y} f i j g h = funExt λ c →
sum-perm [ (g c) , (h c) ] (f c)
| 37.188406
| 142
| 0.500974
|
cb153e26b65c2e7fd3547e11ed9c32d3a2d32744
| 402
|
agda
|
Agda
|
test/Succeed/Issue1834c.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue1834c.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1834c.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas & James, 2016-04-18 pre-AIM XXIII
-- order of clauses should not matter here!
{-# OPTIONS --exact-split #-}
open import Common.Prelude
record R A : Set where
field out : A
T : (x y : Bool) → Set
T true y = R Bool
T false true = R Nat
T false false = R String
test : (x y : Bool) → T x y
R.out (test true y) = y
R.out (test false true ) = 0
R.out (test false false) = "hallo"
| 20.1
| 44
| 0.621891
|
1c932af6caf1e37416964f94c277abb07aa827a3
| 7,445
|
agda
|
Agda
|
papers/unraveling-recursion/code/src/Compilation/Data.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 1,299
|
2018-10-02T13:41:39.000Z
|
2022-03-28T01:10:02.000Z
|
papers/unraveling-recursion/code/src/Compilation/Data.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 2,493
|
2018-09-28T19:28:17.000Z
|
2022-03-31T15:31:31.000Z
|
papers/unraveling-recursion/code/src/Compilation/Data.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 399
|
2018-10-05T09:36:10.000Z
|
2022-03-31T11:18:25.000Z
|
{-# OPTIONS --type-in-type #-}
module Compilation.Data where
open import Context
open import Type.Core
open import Function
open import Data.Product
open import Data.List.Base
infixr 6 _⇒ᶜ_
{- Note [Type denotations]
The denotation of a System Fωμ type is an Agda type that somehow corresponds to the original type.
For System Fωμ types we'll be using simple and straightforward denotations. For example, we map
π ⋆ (Var vz ⇒ Var vz)
to
(A : Set) -> A -> A
and
Lam (Var vz) ∙ (π ⋆ (Var vz ⇒ Var vz))
to
(λ x -> x) ((A : Set) -> A -> A)
which computes to
(A : Set) -> A -> A
The latter is due to the fact that we map System Fωμ lambdas to Agda lambdas and System Fωμ
applications to Agda applications and hence get type normalization of denotations for free.
-}
{- Note [Kind denotations]
Of course before taking denotations of System Fωμ types, we need to be able to take denotations
of System Fωμ kinds. We map a System Fωμ `⋆` to an Agda `Set` and a System Fωμ `_⇒ᵏ_` to an Agda
`_->_`. For example the denotation of
(⋆ ⇒ᵏ ⋆) ⇒ᵏ ⋆
is
(Set -> Set) -> Set
-}
-- | The Agda meaning of a kind.
⟦_⟧ᵏ : Kind -> Set
⟦ ⋆ ⟧ᵏ = Set
⟦ σ ⇒ᵏ τ ⟧ᵏ = ⟦ σ ⟧ᵏ -> ⟦ τ ⟧ᵏ
-- | The Agda meaning of a System Fωμ type in an environment.
evalᵗ : ∀ {Θ σ} -> Env ⟦_⟧ᵏ Θ -> Θ ⊢ᵗ σ -> ⟦ σ ⟧ᵏ
evalᵗ ρ (Var v) = lookupᵉ v ρ -- Look up a variable in the current context.
evalᵗ ρ (Lam β) = λ A -> evalᵗ (ρ ▷ A) β -- Map a System Fωμ lambda to an Agda lambda.
evalᵗ ρ (φ ∙ α) = evalᵗ ρ φ (evalᵗ ρ α) -- Map a System Fωμ application to an Agda application.
evalᵗ ρ (α ⇒ β) = evalᵗ ρ α -> evalᵗ ρ β -- Map a System Fωμ arrow to an Agda arrow.
evalᵗ ρ (π σ β) = (A : ⟦ σ ⟧ᵏ) -> evalᵗ (ρ ▷ A) β -- Map a System Fωμ `all` to an Agda `∀`.
evalᵗ ρ (μ ψ α) = IFix (evalᵗ ρ ψ) (evalᵗ ρ α) -- Map a System Fωμ `ifix` to an Agda `IFix`.
-- | The Agda meaning of a closed System Fωμ type.
⟦_⟧ᵗ : ∀ {σ} -> Type⁽⁾ σ -> ⟦ σ ⟧ᵏ
⟦_⟧ᵗ = evalᵗ ∅
{- Note [Representing data types]
We represent a single data type as a list of constructor types. Each constructor type is defined in
a non-empty context where the first bound variable is for handling recursion and other variables are
parameters of the data type (there can be none). Each constructor type is a sequence of `_⇒ᶜ_`
that ends in `endᶜ` where `endᶜ` is a placeholder that will later be substituted either for
a type being defined or a type we eliminate the data type into or the unit type,
depending on how we denote constructors (there are multiple ways).
Consider the `list` data type. Its pattern functor binds two variables:
1. one responsible for recursion
2. one for the type of the elements stored in a list
Since we define constructors in contexts, the list constructors are defined in
ε ▻ (⋆ ⇒ ⋆) ▻ ⋆
(the parens are for clarity, they're not really needed). The types of the constructors are
1. List A -- The type of the `nil` constructor.
2. A -> List A -> List A -- The type of the `cons` constructor.
and we translate them to
1. endᶜ
2. Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ
A more interesting example is
data InterList (A B : Set) : Set where
InterNil : InterList A B
InterCons : A -> B -> InterList B A -> InterList A B
The types of its constructors are described as
1. endᶜ
2. Var (vs vz) ⇒ᶜ Var vz ⇒ᶜ Var (vs vs vz) ∙ Var vz ∙ Var (vs vz) ⇒ᶜ endᶜ
Below we define the data type that describes constructors and some basic functions over it.
-}
-- | The type of a constructor is of the `σ₁ ⇒ … ⇒ σₙ ⇒ end` form
-- where each `σ` is a type of kind `⋆`.
data Cons Θ : Set where
endᶜ : Cons Θ
_⇒ᶜ_ : (α : Star Θ) -> (ξ : Cons Θ) -> Cons Θ
-- | Convert the type of a constructor to an actual type of kind `⋆`.
--
-- > consToType (α₁ ⇒ᶜ … ⇒ᶜ αₙ ⇒ᶜ endᶜ) β = α₁ ⇒ … ⇒ αₙ ⇒ β
consToType : ∀ {Θ} -> Cons Θ -> Star Θ -> Star Θ
consToType endᶜ β = β
consToType (α ⇒ᶜ ξ) β = α ⇒ consToType ξ β
-- | Rename the type of a constructor.
renᶜ : ∀ {Θ Ξ} -> Θ ⊆ Ξ -> Cons Θ -> Cons Ξ
renᶜ ι endᶜ = endᶜ
renᶜ ι (α ⇒ᶜ ξ) = renᵗ ι α ⇒ᶜ renᶜ ι ξ
-- The family we use as an example in docs below.
module ProdTreeTree where
mutual
data ProdTree (A : Set) (B : Set) : Set where
Prod : Tree (A × B) -> ProdTree A B
data Tree (A : Set) : Set where
Leaf : A -> Tree A
Fork : ProdTree A A -> Tree A
open import Data.Nat.Base
open import Data.Bool.Base
private
example : ProdTree ℕ Bool
example
= Prod ∘ Fork ∘ Prod ∘ Fork ∘ Prod ∘ Leaf
$ ( ( 0
, false
)
, ( 1
, true
)
)
, ( ( 2
, false
)
, (3
, true
)
)
-- | A data description is parameterized by a context of contexts of kinds. Inner contexts are those
-- single data types are defined in. Outer contexts are needed in order to allow to define mutually
-- recursive data types. I.e. each element of an outer context is an inner context, in which
-- a single data type is defined.
--
-- A single data type is described as a list of described constructors. The context of each
-- constructor consists of
--
-- 1. all the data types being defined (because we allow mutually recursive data types)
-- 2. the particular inner context of the data type that the constructor constructs
--
-- For example, consider the `ProdTree`/`Tree` family of data types defined above
--
-- Since there are two data types in this family, the length of the outer context is 2.
-- Since `ProdTree` is parameterized by two types, it's inner context is `ε ▻ ⋆ ▻ ⋆`.
-- Since `Tree` is parameterized by one type, it's inner context is `ε ▻ ⋆`.
-- I.e. the context this whole family is defined in, is
--
-- > ε ▻ (ε ▻ ⋆ ▻ ⋆) ▻ (ε ▻ ⋆)
--
-- The context that the constructor of `ProdTree` is defined in, consists of
--
-- 1. References to both `ProdTree` and `Tree` which have the `⋆ ⇒ᵏ ⋆ ⇒ᵏ ⋆` and `⋆ ⇒ᵏ ⋆`
-- kinds respectively.
-- 2. The inner context of `ProdTree` which has two parameters `A` and `B`, each of kind `⋆`.
--
-- hence the final context is
--
-- > ε ▻ {- ProdTree :: -} (⋆ ⇒ᵏ ⋆ ⇒ᵏ ⋆) ▻ {- Tree :: -} (⋆ ⇒ᵏ ⋆) ▻ {- A :: -} ⋆ ▻ {- B :: -} ⋆
--
-- (things in `{- … -}` are comments that assign names to variables for clarity).
--
-- Analogously, the context that the constructors of Tree` are defined in, is
--
-- > ε ▻ {- ProdTree :: -} (⋆ ⇒ᵏ ⋆ ⇒ᵏ ⋆) ▻ {- Tree :: -} (⋆ ⇒ᵏ ⋆) ▻ {- A :: -} ⋆
--
-- I.e. the same as the one of `ProdTree`, except we bind only one type parameter, because `Tree`
-- has only one type parameter.
record Data Ξ (Θs : Con Conᵏ) : Set where
constructor PackData
field constructors : Seq (λ Θ -> List (Cons (Ξ ▻▻ mapᶜ (λ Θᵢ -> conToKind Θᵢ ⋆) Θs ▻▻ Θ))) Θs
Data⁺ : Con Conᵏ -> Set
Data⁺ Θs = ∀ {Ξ} -> Data Ξ Θs
module prodTreeTree where
-- The encoded `ProdTree`/`Tree` family from the above looks like this:
-- (`∀ Q -> (A -> B -> Q) -> Q` is the Scott-encoded `A × B`)
prodTreeTree : Data⁺ (ε ▻ (ε ▻ ⋆ ▻ ⋆) ▻ (ε ▻ ⋆))
prodTreeTree
= PackData
$ ø
▶ ( -- `Tree (∀ Q -> (A -> B -> Q) -> Q) -> ProdTree A B`
Var (vs vs vz) ∙ π ⋆ ((Var (vs vs vz) ⇒ Var (vs vz) ⇒ Var vz) ⇒ Var vz) ⇒ᶜ endᶜ
∷ []
)
▶ ( -- `A -> Tree A`
Var vz ⇒ᶜ endᶜ
∷ -- `ProdTree A A -> Tree A`
Var (vs vs vz) ∙ Var vz ∙ Var vz ⇒ᶜ endᶜ
∷ []
)
| 33.38565
| 106
| 0.610208
|
d01b0b23a40f7e3f76a4d868b389d5c4af817cb0
| 9,753
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/List/Countdown.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/List/Countdown.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/List/Countdown.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A data structure which keeps track of an upper bound on the number
-- of elements /not/ in a given list
------------------------------------------------------------------------
import Level
open import Relation.Binary
module Data.List.Countdown (D : DecSetoid Level.zero Level.zero) where
open import Data.Empty
open import Data.Fin using (Fin; zero; suc)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Injection
using (Injection; module Injection)
open import Data.List
open import Data.List.Any as Any using (here; there)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product
open import Data.Sum
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong)
open PropEq.≡-Reasoning
private
open module D = DecSetoid D
hiding (refl) renaming (Carrier to Elem)
open Any.Membership D.setoid
------------------------------------------------------------------------
-- Helper functions
private
drop-suc : ∀ {n} {i j : Fin n} →
_≡_ {A = Fin (suc n)} (suc i) (suc j) → i ≡ j
drop-suc refl = refl
drop-inj₂ : ∀ {A B : Set} {x y} →
inj₂ {A = A} {B = B} x ≡ inj₂ y → x ≡ y
drop-inj₂ refl = refl
-- The /first/ occurrence of x in xs.
first-occurrence : ∀ {xs} x → x ∈ xs → x ∈ xs
first-occurrence x (here x≈y) = here x≈y
first-occurrence x (there {x = y} x∈xs) with x ≟ y
... | yes x≈y = here x≈y
... | no _ = there $ first-occurrence x x∈xs
-- The index of the first occurrence of x in xs.
first-index : ∀ {xs} x → x ∈ xs → Fin (length xs)
first-index x x∈xs = Any.index $ first-occurrence x x∈xs
-- first-index preserves equality of its first argument.
first-index-cong : ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
x₁ ≈ x₂ → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs
first-index-cong {x₁} {x₂} x₁∈xs x₂∈xs x₁≈x₂ = helper x₁∈xs x₂∈xs
where
helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs
helper (here x₁≈x) (here x₂≈x) = refl
helper (here x₁≈x) (there {x = x} x₂∈xs) with x₂ ≟ x
... | yes x₂≈x = refl
... | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x))
helper (there {x = x} x₁∈xs) (here x₂≈x) with x₁ ≟ x
... | yes x₁≈x = refl
... | no x₁≉x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x))
helper (there {x = x} x₁∈xs) (there x₂∈xs) with x₁ ≟ x | x₂ ≟ x
... | yes x₁≈x | yes x₂≈x = refl
... | yes x₁≈x | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x))
... | no x₁≉x | yes x₂≈x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x))
... | no x₁≉x | no x₂≉x = cong suc $ helper x₁∈xs x₂∈xs
-- first-index is injective in its first argument.
first-index-injective
: ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂
first-index-injective {x₁} {x₂} = helper
where
helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂
helper (here x₁≈x) (here x₂≈x) _ = trans x₁≈x (sym x₂≈x)
helper (here x₁≈x) (there {x = x} x₂∈xs) _ with x₂ ≟ x
helper (here x₁≈x) (there {x = x} x₂∈xs) _ | yes x₂≈x = trans x₁≈x (sym x₂≈x)
helper (here x₁≈x) (there {x = x} x₂∈xs) () | no x₂≉x
helper (there {x = x} x₁∈xs) (here x₂≈x) _ with x₁ ≟ x
helper (there {x = x} x₁∈xs) (here x₂≈x) _ | yes x₁≈x = trans x₁≈x (sym x₂≈x)
helper (there {x = x} x₁∈xs) (here x₂≈x) () | no x₁≉x
helper (there {x = x} x₁∈xs) (there x₂∈xs) _ with x₁ ≟ x | x₂ ≟ x
helper (there {x = x} x₁∈xs) (there x₂∈xs) _ | yes x₁≈x | yes x₂≈x = trans x₁≈x (sym x₂≈x)
helper (there {x = x} x₁∈xs) (there x₂∈xs) () | yes x₁≈x | no x₂≉x
helper (there {x = x} x₁∈xs) (there x₂∈xs) () | no x₁≉x | yes x₂≈x
helper (there {x = x} x₁∈xs) (there x₂∈xs) eq | no x₁≉x | no x₂≉x =
helper x₁∈xs x₂∈xs (drop-suc eq)
-- If there are at least two elements in Fin (suc n), then Fin n is
-- inhabited. This is a variant of the thick function from Conor
-- McBride's "First-order unification by structural recursion".
thick : ∀ {n} (i j : Fin (suc n)) → i ≢ j → Fin n
thick zero zero i≢j = ⊥-elim (i≢j refl)
thick zero (suc j) _ = j
thick {zero} (suc ()) _ _
thick {suc n} (suc i) zero _ = zero
thick {suc n} (suc i) (suc j) i≢j =
suc (thick i j (i≢j ∘ cong suc))
-- thick i is injective in one of its arguments.
thick-injective : ∀ {n} (i j k : Fin (suc n))
{i≢j : i ≢ j} {i≢k : i ≢ k} →
thick i j i≢j ≡ thick i k i≢k → j ≡ k
thick-injective zero zero _ {i≢j = i≢j} _ = ⊥-elim (i≢j refl)
thick-injective zero _ zero {i≢k = i≢k} _ = ⊥-elim (i≢k refl)
thick-injective zero (suc j) (suc k) j≡k = cong suc j≡k
thick-injective {zero} (suc ()) _ _ _
thick-injective {suc n} (suc i) zero zero _ = refl
thick-injective {suc n} (suc i) zero (suc k) ()
thick-injective {suc n} (suc i) (suc j) zero ()
thick-injective {suc n} (suc i) (suc j) (suc k) {i≢j} {i≢k} eq =
cong suc $ thick-injective i j k {i≢j ∘ cong suc} {i≢k ∘ cong suc} (drop-suc eq)
------------------------------------------------------------------------
-- The countdown data structure
-- If counted ⊕ n is inhabited then there are at most n values of type
-- Elem which are not members of counted (up to _≈_). You can read the
-- symbol _⊕_ as partitioning Elem into two parts: counted and
-- uncounted.
infix 4 _⊕_
record _⊕_ (counted : List Elem) (n : ℕ) : Set where
field
-- An element can be of two kinds:
-- ⑴ It is provably in counted.
-- ⑵ It is one of at most n elements which may or may not be in
-- counted. The "at most n" part is guaranteed by the field
-- "injective".
kind : ∀ x → x ∈ counted ⊎ Fin n
injective : ∀ {x y i} → kind x ≡ inj₂ i → kind y ≡ inj₂ i → x ≈ y
-- A countdown can be initialised by proving that Elem is finite.
empty : ∀ {n} → Injection D.setoid (PropEq.setoid (Fin n)) → [] ⊕ n
empty inj =
record { kind = inj₂ ∘ _⟨$⟩_ to
; injective = λ {x} {y} {i} eq₁ eq₂ → injective (begin
to ⟨$⟩ x ≡⟨ drop-inj₂ eq₁ ⟩
i ≡⟨ PropEq.sym $ drop-inj₂ eq₂ ⟩
to ⟨$⟩ y ∎)
}
where open Injection inj
-- A countdown can also be initialised by proving that Elem is finite.
emptyFromList : (counted : List Elem) → (∀ x → x ∈ counted) →
[] ⊕ length counted
emptyFromList counted complete = empty record
{ to = record
{ _⟨$⟩_ = λ x → first-index x (complete x)
; cong = first-index-cong (complete _) (complete _)
}
; injective = first-index-injective (complete _) (complete _)
}
-- Finds out if an element has been counted yet.
lookup : ∀ {counted n} → counted ⊕ n → ∀ x → Dec (x ∈ counted)
lookup {counted} _ x = Any.any (_≟_ x) counted
-- When no element remains to be counted all elements have been
-- counted.
lookup! : ∀ {counted} → counted ⊕ zero → ∀ x → x ∈ counted
lookup! counted⊕0 x with _⊕_.kind counted⊕0 x
... | inj₁ x∈counted = x∈counted
... | inj₂ ()
private
-- A variant of lookup!.
lookup‼ : ∀ {m counted} →
counted ⊕ m → ∀ x → x ∉ counted → ∃ λ n → m ≡ suc n
lookup‼ {suc m} counted⊕n x x∉counted = (m , refl)
lookup‼ {zero} counted⊕n x x∉counted =
⊥-elim (x∉counted $ lookup! counted⊕n x)
-- Counts a previously uncounted element.
insert : ∀ {counted n} →
counted ⊕ suc n → ∀ x → x ∉ counted → x ∷ counted ⊕ n
insert {counted} {n} counted⊕1+n x x∉counted =
record { kind = kind′; injective = inj }
where
open _⊕_ counted⊕1+n
helper : ∀ x y i {j} →
kind x ≡ inj₂ i → kind y ≡ inj₂ j → i ≡ j → x ≈ y
helper _ _ _ eq₁ eq₂ refl = injective eq₁ eq₂
kind′ : ∀ y → y ∈ x ∷ counted ⊎ Fin n
kind′ y with y ≟ x | kind x | kind y | helper x y
kind′ y | yes y≈x | _ | _ | _ = inj₁ (here y≈x)
kind′ y | _ | inj₁ x∈counted | _ | _ = ⊥-elim (x∉counted x∈counted)
kind′ y | _ | _ | inj₁ y∈counted | _ = inj₁ (there y∈counted)
kind′ y | no y≉x | inj₂ i | inj₂ j | hlp =
inj₂ (thick i j (y≉x ∘ sym ∘ hlp _ refl refl))
inj : ∀ {y z i} → kind′ y ≡ inj₂ i → kind′ z ≡ inj₂ i → y ≈ z
inj {y} {z} eq₁ eq₂ with y ≟ x | z ≟ x | kind x | kind y | kind z
| helper x y | helper x z | helper y z
inj () _ | yes _ | _ | _ | _ | _ | _ | _ | _
inj _ () | _ | yes _ | _ | _ | _ | _ | _ | _
inj _ _ | no _ | no _ | inj₁ x∈counted | _ | _ | _ | _ | _ = ⊥-elim (x∉counted x∈counted)
inj () _ | no _ | no _ | inj₂ _ | inj₁ _ | _ | _ | _ | _
inj _ () | no _ | no _ | inj₂ _ | _ | inj₁ _ | _ | _ | _
inj eq₁ eq₂ | no _ | no _ | inj₂ i | inj₂ _ | inj₂ _ | _ | _ | hlp =
hlp _ refl refl $
thick-injective i _ _ $
PropEq.trans (drop-inj₂ eq₁) (PropEq.sym (drop-inj₂ eq₂))
-- Counts an element if it has not already been counted.
lookupOrInsert : ∀ {counted m} →
counted ⊕ m →
∀ x → x ∈ counted ⊎
∃ λ n → m ≡ suc n × x ∷ counted ⊕ n
lookupOrInsert counted⊕n x with lookup counted⊕n x
... | yes x∈counted = inj₁ x∈counted
... | no x∉counted with lookup‼ counted⊕n x x∉counted
... | (n , refl) = inj₂ (n , refl , insert counted⊕n x x∉counted)
| 40.135802
| 107
| 0.532964
|
106e14f2d8cc8d59f3e62964e30b3ce4858072a6
| 1,914
|
agda
|
Agda
|
Definition/Typed/Consequences/NeTypeEq.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/Typed/Consequences/NeTypeEq.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/Typed/Consequences/NeTypeEq.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Consequences.NeTypeEq where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Substitution
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Helper function for the same variable instance of a context have equal types.
varTypeEq′ : ∀ {n R T Γ} → n ∷ R ∈ Γ → n ∷ T ∈ Γ → R PE.≡ T
varTypeEq′ here here = PE.refl
varTypeEq′ (there n∷R) (there n∷T) rewrite varTypeEq′ n∷R n∷T = PE.refl
-- The same variable instance of a context have equal types.
varTypeEq : ∀ {x A B Γ} → Γ ⊢ A → Γ ⊢ B → x ∷ A ∈ Γ → x ∷ B ∈ Γ → Γ ⊢ A ≡ B
varTypeEq A B x∷A x∷B rewrite varTypeEq′ x∷A x∷B = refl A
-- The same neutral term have equal types.
neTypeEq : ∀ {t A B Γ} → Neutral t → Γ ⊢ t ∷ A → Γ ⊢ t ∷ B → Γ ⊢ A ≡ B
neTypeEq (var x) (var x₁ x₂) (var x₃ x₄) =
varTypeEq (syntacticTerm (var x₃ x₂)) (syntacticTerm (var x₃ x₄)) x₂ x₄
neTypeEq (∘ₙ neT) (t∷A ∘ⱼ t∷A₁) (t∷B ∘ⱼ t∷B₁) with neTypeEq neT t∷A t∷B
... | q = let w = proj₂ (injectivity q)
in substTypeEq w (refl t∷A₁)
neTypeEq (fstₙ neP) (fstⱼ ⊢F ⊢G ⊢t) (fstⱼ ⊢F′ ⊢G′ ⊢t′) with neTypeEq neP ⊢t ⊢t′
... | q = proj₁ (Σ-injectivity q)
neTypeEq (sndₙ neP) (sndⱼ ⊢F ⊢G ⊢t) (sndⱼ ⊢F′ ⊢G′ ⊢t′) with neTypeEq neP ⊢t ⊢t′
... | q = let G≡G₁ = proj₂ (Σ-injectivity q)
⊢fst = fstⱼ ⊢F ⊢G ⊢t
in substTypeEq G≡G₁ (refl ⊢fst)
neTypeEq (natrecₙ neT) (natrecⱼ x t∷A t∷A₁ t∷A₂) (natrecⱼ x₁ t∷B t∷B₁ t∷B₂) =
refl (substType x₁ t∷B₂)
neTypeEq (Emptyrecₙ neT) (Emptyrecⱼ x t∷A) (Emptyrecⱼ x₁ t∷B) =
refl x₁
neTypeEq x (conv t∷A x₁) t∷B = let q = neTypeEq x t∷A t∷B
in trans (sym x₁) q
neTypeEq x t∷A (conv t∷B x₃) = let q = neTypeEq x t∷A t∷B
in trans q x₃
| 42.533333
| 80
| 0.626959
|
0b23419e5b1e5e90dab9a5b56212eb9f5767ae0e
| 2,925
|
agda
|
Agda
|
BasicIS4/Metatheory/DyadicGentzen-TarskiOvergluedDyadicImplicit.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Metatheory/DyadicGentzen-TarskiOvergluedDyadicImplicit.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Metatheory/DyadicGentzen-TarskiOvergluedDyadicImplicit.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module BasicIS4.Metatheory.DyadicGentzen-TarskiOvergluedDyadicImplicit where
open import BasicIS4.Syntax.DyadicGentzen public
open import BasicIS4.Semantics.TarskiOvergluedDyadicImplicit public
open ImplicitSyntax (_⊢_) (mono²⊢) public
-- Completeness with respect to a particular model.
module _ {{_ : Model}} where
reify : ∀ {A Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊢ A
reify {α P} s = syn s
reify {A ▻ B} s = syn (s refl⊆²)
reify {□ A} s = syn (s refl⊆²)
reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))
reify {⊤} s = unit
reify⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊩⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ
reify⋆ {∅} ∙ = ∙
reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A
eval (var i) γ δ = lookup i γ
eval (lam t) γ δ = λ ψ → let γ′ = mono²⊩⋆ ψ γ in
let δ′ = mono²⊩⋆ ψ δ
in multicut² (reify⋆ γ′) (reify⋆ δ′) (lam t) ⅋ λ a →
eval t (γ′ , a) δ′
eval (app t u) γ δ = eval t γ δ ⟪$⟫ eval u γ δ
eval (mvar i) γ δ = mlookup i δ
eval (box t) γ δ = λ ψ → let γ′ = mono²⊩⋆ ψ γ in
let δ′ = mono²⊩⋆ ψ δ
in multicut² (reify⋆ γ′) (reify⋆ δ′) (box t) ⅋
eval t ∙ δ′
eval (unbox t u) γ δ = eval u γ (δ , eval t γ δ)
eval (pair t u) γ δ = eval t γ δ , eval u γ δ
eval (fst t) γ δ = π₁ (eval t γ δ)
eval (snd t) γ δ = π₂ (eval t γ δ)
eval unit γ δ = ∙
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ _⊩ᵅ_ = λ Π P → Π ⊢ α P
; mono²⊩ᵅ = mono²⊢
}
-- Soundness with respect to the canonical model.
reflectᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊩ A
reflectᶜ {α P} t = t ⅋ t
reflectᶜ {A ▻ B} t = λ ψ → let t′ = mono²⊢ ψ t
in t′ ⅋ λ a → reflectᶜ (app t′ (reify a))
reflectᶜ {□ A} t = λ ψ → let t′ = mono²⊢ ψ t
in t′ ⅋ reflectᶜ (down t′)
reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)
reflectᶜ {⊤} t = ∙
reflectᶜ⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ Γ
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆
mrefl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ □⋆ Δ
mrefl⊩⋆ = reflectᶜ⋆ mrefl⊢⋆
trans⊩⋆ : ∀ {Γ Γ′ Δ Δ′ Ξ} → Γ ⁏ Δ ⊩⋆ Γ′ ⧺ (□⋆ Δ′) → Γ′ ⁏ Δ′ ⊩⋆ Ξ → Γ ⁏ Δ ⊩⋆ Ξ
trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reify⋆ ts) (reify⋆ us))
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ Δ} → Γ ⁏ Δ ⊨ A → Γ ⁏ Δ ⊢ A
quot s = reify (s refl⊩⋆ mrefl⊩⋆)
-- Normalisation by evaluation.
norm : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
| 29.25
| 83
| 0.499829
|
dccd7c84e870aee124d2542f0fb23fc0d7b2e3a4
| 3,915
|
agda
|
Agda
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
-- binary search trees (not balanced)
open import bool
open import bool-thms2
open import eq
open import maybe
open import product
open import product-thms
open import bool-relations using (transitive ; total)
module z05-01-bst (A : Set) -- type of elements
(_≤A_ : A → A → 𝔹) -- ordering function
(≤A-trans : transitive _≤A_) -- proof of transitivity of given ordering
(≤A-total : total _≤A_) -- proof of totality of given ordering
where
{-
IAL
- relations.agda
- models binary relation on A as functions from A to A to Set
- bool-relations.agda
- models binary realtion on A as functions from A to A to 𝔹
Cannot use A→A→Set relations here because code cannot manipulate types.
But code can pattern match on values of type 𝔹, so boolean relations more useful.
-}
open import bool-relations _≤A_ hiding (transitive ; total)
open import minmax _≤A_ ≤A-trans ≤A-total
-- able to store values in bounds 'l' and 'u'
-- l(ower) bound
-- | u(upper) bound
-- v v
data bst : A → A → Set where
bst-leaf : ∀ {l u : A}
→ l ≤A u ≡ tt
→ bst l u
bst-node : ∀ {l l' u' u : A}
→ (d : A) -- value stored in this node
→ bst l' d -- left subtree of values ≤ stored value
→ bst d u' -- right subtree of values ≥ stored value
→ l ≤A l' ≡ tt
→ u' ≤A u ≡ tt
→ bst l u
------------------------------------------------------------------------------
bst-search : ∀ {l u : A}
→ (d : A) -- find a node that is isomorphic (_=A_) to d
→ bst l u
→ maybe (Σ A (λ d' → d iso𝔹 d' ≡ tt)) -- return that node or nothing
bst-search d (bst-leaf _) = nothing -- could return proof not in tree instead
-- compare given element with stored element
bst-search d (bst-node d' L R _ _) with keep (d ≤A d')
-- compare given element with stored element (other direction)
bst-search d (bst-node d' L R _ _) | tt , p1 with keep (d' ≤A d)
-- both are true implying iso, so return that element and proof
bst-search d (bst-node d' L R _ _) | tt , p1 | tt , p2 = just (d' , iso𝔹-intro p1 p2)
-- if either is false then search the appropriate branch
bst-search d (bst-node d' L R _ _) | tt , p1 | ff , p2 = bst-search d L -- search in left
bst-search d (bst-node d' L R _ _) | ff , p1 = bst-search d R -- search in right
------------------------------------------------------------------------------
-- change the lower bound from l' to l
bst-dec-lb : ∀ {l l' u' : A}
→ bst l' u'
→ l ≤A l' ≡ tt
→ bst l u'
bst-dec-lb (bst-leaf p) q = bst-leaf (≤A-trans q p)
bst-dec-lb (bst-node d L R p1 p2) q = bst-node d L R (≤A-trans q p1) p2
-- change the upper bound from u' to u
bst-inc-ub : ∀ {l' u' u : A}
→ bst l' u'
→ u' ≤A u ≡ tt
→ bst l' u
bst-inc-ub (bst-leaf p) q = bst-leaf (≤A-trans p q)
bst-inc-ub (bst-node d L R p1 p2) q = bst-node d L R p1 (≤A-trans p2 q)
bst-insert : ∀{l u : A}
→ (d : A) -- insert 'd'
→ bst l u -- into this 'bst'
→ bst (min d l) (max d u) -- type might change
bst-insert d (bst-leaf p) =
bst-node d (bst-leaf ≤A-refl) (bst-leaf ≤A-refl) min-≤1 max-≤1
bst-insert d (bst-node d' L R p1 p2) with keep (d ≤A d')
bst-insert d (bst-node d' L R p1 p2) | tt , p with bst-insert d L
bst-insert d (bst-node d' L R p1 p2) | tt , p | L' rewrite p =
bst-node d' L' (bst-inc-ub R (≤A-trans p2 max-≤2))
(min2-mono p1) ≤A-refl
bst-insert d (bst-node d' L R p1 p2) | ff , p with bst-insert d R
bst-insert d (bst-node d' L R p1 p2) | ff , p | R' rewrite p =
bst-node d' (bst-dec-lb L p1) R'
min-≤2 (max2-mono p2)
| 39.94898
| 94
| 0.527203
|
dfa6162f0738431ce160d67aa2689a3520554a63
| 3,966
|
agda
|
Agda
|
src/Partiality-algebra/Omega-continuous.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | 2
|
2020-05-21T22:59:18.000Z
|
2020-07-03T08:56:08.000Z
|
src/Partiality-algebra/Omega-continuous.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
src/Partiality-algebra/Omega-continuous.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- ω-continuous functions
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Partiality-algebra.Omega-continuous where
open import Equality.Propositional.Cubical
open import Prelude
open import Bijection equality-with-J using (_↔_)
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J
open import H-level.Closure equality-with-J
open import Partiality-algebra as PA
open import Partiality-algebra.Monotone
-- Definition of ω-continuous functions.
record [_⟶_]
{a₁ p₁ q₁} {A₁ : Type a₁} (P₁ : Partiality-algebra p₁ q₁ A₁)
{a₂ p₂ q₂} {A₂ : Type a₂} (P₂ : Partiality-algebra p₂ q₂ A₂) :
Type (p₁ ⊔ p₂ ⊔ q₁ ⊔ q₂) where
private
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
field
monotone-function : [ P₁ ⟶ P₂ ]⊑
open [_⟶_]⊑ monotone-function public
field
ω-continuous :
∀ s → function (P₁.⨆ s) ≡ P₂.⨆ [ monotone-function $ s ]-inc
open [_⟶_]
-- Identity.
idω : ∀ {a p q} {A : Type a} {P : Partiality-algebra p q A} →
[ P ⟶ P ]
monotone-function idω = id⊑
ω-continuous idω _ = refl
-- Composition.
infixr 40 _∘ω_
_∘ω_ :
∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}
{a₃ p₃ q₃} {A₃ : Type a₃} {P₃ : Partiality-algebra p₃ q₃ A₃} →
[ P₂ ⟶ P₃ ] → [ P₁ ⟶ P₂ ] → [ P₁ ⟶ P₃ ]
monotone-function (f ∘ω g) = monotone-function f ∘⊑ monotone-function g
ω-continuous (_∘ω_ {P₁ = P₁} {P₂ = P₂} {P₃ = P₃} f g) s =
function f (function g (P₁.⨆ s)) ≡⟨ cong (function f) (ω-continuous g s) ⟩
function f (P₂.⨆ [ monotone-function g $ s ]-inc) ≡⟨ ω-continuous f _ ⟩∎
P₃.⨆ [ monotone-function f ∘⊑ monotone-function g $ s ]-inc ∎
where
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
module P₃ = Partiality-algebra P₃
-- Equality characterisation lemma for ω-continuous functions.
equality-characterisation-continuous :
∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}
{f g : [ P₁ ⟶ P₂ ]} →
(∀ x → function f x ≡ function g x) ↔ f ≡ g
equality-characterisation-continuous {P₁ = P₁} {P₂ = P₂} {f} {g} =
(∀ x → function f x ≡ function g x) ↝⟨ equality-characterisation-monotone ⟩
monotone-function f ≡ monotone-function g ↝⟨ ignore-propositional-component
(Π-closure ext 1 λ _ →
P₂.T-is-set) ⟩
_↔_.to rearrange f ≡ _↔_.to rearrange g ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ rearrange) ⟩□
f ≡ g □
where
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
rearrange :
[ P₁ ⟶ P₂ ]
↔
∃ λ (h : [ P₁ ⟶ P₂ ]⊑) →
∀ s → [_⟶_]⊑.function h (P₁.⨆ s) ≡ P₂.⨆ [ h $ s ]-inc
rearrange = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → monotone-function f , ω-continuous f
; from = uncurry λ f c → record { monotone-function = f
; ω-continuous = c
}
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
where
open Partiality-algebra
-- Composition is associative.
∘ω-assoc :
∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}
{a₃ p₃ q₃} {A₃ : Type a₃} {P₃ : Partiality-algebra p₃ q₃ A₃}
{a₄ p₄ q₄} {A₄ : Type a₄} {P₄ : Partiality-algebra p₄ q₄ A₄}
(f : [ P₃ ⟶ P₄ ]) (g : [ P₂ ⟶ P₃ ]) (h : [ P₁ ⟶ P₂ ]) →
f ∘ω (g ∘ω h) ≡ (f ∘ω g) ∘ω h
∘ω-assoc _ _ _ =
_↔_.to equality-characterisation-continuous λ _ → refl
| 33.897436
| 104
| 0.549924
|
230011ed9a3458dc259d19b4c5061c2d1fd17551
| 3,570
|
agda
|
Agda
|
core/lib/groups/Subgroup.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/groups/Subgroup.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/groups/Subgroup.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.Function2
open import lib.types.Group
open import lib.types.Sigma
open import lib.types.Truncation
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
open import lib.groups.SubgroupProp
module lib.groups.Subgroup where
module _ {i j} {G : Group i} (P : SubgroupProp G j) where
private
module G = Group G
module P = SubgroupProp P
subgroup-struct : GroupStructure P.SubEl
subgroup-struct = record {M} where
module M where
ident : P.SubEl
ident = G.ident , P.ident
inv : P.SubEl → P.SubEl
inv (g , p) = G.inv g , P.inv p
comp : P.SubEl → P.SubEl → P.SubEl
comp (g₁ , p₁) (g₂ , p₂) = G.comp g₁ g₂ , P.comp p₁ p₂
abstract
unit-l : ∀ g → comp ident g == g
unit-l (g , _) = Subtype=-out P.subEl-prop (G.unit-l g)
assoc : ∀ g₁ g₂ g₃ → comp (comp g₁ g₂) g₃ == comp g₁ (comp g₂ g₃)
assoc (g₁ , _) (g₂ , _) (g₃ , _) = Subtype=-out P.subEl-prop (G.assoc g₁ g₂ g₃)
inv-l : ∀ g → comp (inv g) g == ident
inv-l (g , _) = Subtype=-out P.subEl-prop (G.inv-l g)
Subgroup : Group (lmax i j)
Subgroup = group _ SubEl-level subgroup-struct
where abstract SubEl-level = Subtype-level P.subEl-prop G.El-level
module Subgroup {i j} {G : Group i} (P : SubgroupProp G j) where
private
module P = SubgroupProp P
module G = Group G
grp = Subgroup P
open Group grp public
El=-out : ∀ {s₁ s₂ : El} → fst s₁ == fst s₂ → s₁ == s₂
El=-out = Subtype=-out P.subEl-prop
inject : Subgroup P →ᴳ G
inject = record {f = fst; pres-comp = λ _ _ → idp}
inject-lift : ∀ {j} {H : Group j} (φ : H →ᴳ G)
→ Π (Group.El H) (P.prop ∘ GroupHom.f φ)
→ (H →ᴳ Subgroup P)
inject-lift {H = H} φ P-all = record {M} where
module H = Group H
module φ = GroupHom φ
module M where
f : H.El → P.SubEl
f h = φ.f h , P-all h
abstract
pres-comp : ∀ h₁ h₂ → f (H.comp h₁ h₂) == Group.comp (Subgroup P) (f h₁) (f h₂)
pres-comp h₁ h₂ = Subtype=-out P.subEl-prop (φ.pres-comp h₁ h₂)
full-subgroup : ∀ {i j} {G : Group i} {P : SubgroupProp G j}
→ is-fullᴳ P → Subgroup P ≃ᴳ G
full-subgroup {G = G} {P} full = Subgroup.inject P , is-eq _ from to-from from-to where
from : Group.El G → Subgroup.El P
from g = g , full g
abstract
from-to : ∀ p → from (fst p) == p
from-to p = Subtype=-out (SubgroupProp.subEl-prop P) idp
to-from : ∀ g → fst (from g) == g
to-from g = idp
module _ {i} {j} {G : Group i} {H : Group j} (φ : G →ᴳ H) where
private
module G = Group G
module H = Group H
module φ = GroupHom φ
module Ker = Subgroup (ker-propᴳ φ)
Ker = Ker.grp
module Im = Subgroup (im-propᴳ φ)
Im = Im.grp
im-lift : G →ᴳ Im
im-lift = Im.inject-lift φ (λ g → [ g , idp ])
im-lift-is-surj : is-surjᴳ im-lift
im-lift-is-surj (_ , s) = Trunc-fmap
(λ {(g , p) → (g , Subtype=-out (_ , λ _ → Trunc-level) p)}) s
module _ {i j k} {G : Group i} (P : SubgroupProp G j)
(Q : SubgroupProp G k) where
-- FIXME looks like a bad name
Subgroup-fmap-r : P ⊆ᴳ Q → Subgroup P →ᴳ Subgroup Q
Subgroup-fmap-r P⊆Q = group-hom (Σ-fmap-r P⊆Q)
(λ _ _ → Subtype=-out (SubgroupProp.subEl-prop Q) idp)
Subgroup-emap-r : P ⊆ᴳ Q → Q ⊆ᴳ P → Subgroup P ≃ᴳ Subgroup Q
Subgroup-emap-r P⊆Q Q⊆P = Subgroup-fmap-r P⊆Q ,
is-eq _ (Σ-fmap-r Q⊆P)
(λ _ → Subtype=-out (SubgroupProp.subEl-prop Q) idp)
(λ _ → Subtype=-out (SubgroupProp.subEl-prop P) idp)
| 29.75
| 87
| 0.597199
|
50b5dd3e75a1228da5219eeaa3d901839efeb7e3
| 9,310
|
agda
|
Agda
|
test/hPropInvestigations.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
test/hPropInvestigations.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
test/hPropInvestigations.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module hPropInvestigations where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Foundations.Prelude
open import Function.Base using (_∋_)
open import Cubical.Foundations.Logic
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Empty renaming (elim to ⊥-elim) renaming (⊥ to ⊥⊥) -- `⊥` and `elim`
import Cubical.Data.Empty as Empty
open import Cubical.Data.Unit.Base
import Cubical.Structures.Axioms
-- NOTE:
-- we have both:
-- the "classic" bundle/unbundle record-based definition of a CommRing from `Cubical.Structures.CommRing`
--
-- record IsCommRing {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
-- field
-- isRing : IsRing 0r 1r _+_ _·_ -_
-- ·-comm : (x y : R) → x · y ≡ y · x
-- record CommRing : Type (ℓ-suc ℓ) where
-- field
-- Carrier : Type ℓ
-- 0r : Carrier
-- 1r : Carrier
-- _+_ : Carrier → Carrier → Carrier
-- _·_ : Carrier → Carrier → Carrier
-- -_ : Carrier → Carrier
-- isCommRing : IsCommRing 0r 1r _+_ _·_ -_
--
-- and a CommRingΣTheory
--
-- CommRingAxioms R (_+_ , 1r , _·_) = RingAxioms R (_+_ , 1r , _·_) × ((x y : R) → x · y ≡ y · x)
-- CommRingStructure = AxiomsStructure RawRingStructure CommRingAxioms
-- CommRingΣ = TypeWithStr ℓ CommRingStructure
-- CommRingEquivStr : StrEquiv CommRingStructure ℓ
-- CommRingEquivStr = AxiomsEquivStr RawRingEquivStr CommRingAxioms
--
-- especially when we look at
--
-- CommRingEquivStr = AxiomsEquivStr RawRingEquivStr CommRingAxioms
--
-- here `AxiomsEquivStr` from `Cubical.Structures.Axioms`
--
-- AxiomsEquivStr : {S : Type ℓ → Type ℓ₁} (ι : StrEquiv S ℓ₁') (axioms : (X : Type ℓ) → S X → Type ℓ₂)
-- → StrEquiv (AxiomsStructure S axioms) ℓ₁'
-- AxiomsEquivStr ι axioms (X , (s , a)) (Y , (t , b)) e = ι (X , s) (Y , t) e
--
-- takes the two arguments `RawRingEquivStr` and `CommRingAxioms`
--
-- RawRingEquivStr = AutoEquivStr RawRingStructure
--
-- CommRingAxioms : (R : Type ℓ) (s : RawRingStructure R) → Type ℓ
-- CommRingAxioms R (_+_ , 1r , _·_) = RingAxioms R (_+_ , 1r , _·_) × ((x y : R) → x · y ≡ y · x)
--
-- where `AutoEquivStr` is a macro from `Cubical.Structures.Auto`
--
-- -- (S : Type ℓ → Type ℓ₁) → StrEquiv (AutoStructure S) _
-- AutoEquivStr : R.Term → R.Term → R.TC Unit
-- AutoEquivStr t hole =
-- newMeta (tDesc R.unknown) >>= λ d →
-- R.unify hole (R.def (quote MacroEquivStr) [ varg d ]) >>
-- autoDesc' t d
import Cubical.Structures.CommRing
open import Cubical.Data.Sigma.Properties
import Cubical.Foundations.Transport
import Cubical.Foundations.Path
¬[P⊓¬P] : ∀(P : hProp ℓ) → [ ¬(P ⊓ ¬ P) ]
¬[P⊓¬P] _ (p , q) = q p
lemma-comm : ∀(P : hProp ℓ) → P ⊓ ¬ P ≡ ¬ P ⊓ P
lemma-comm P = ⊓-comm P (¬ P)
lemma-comm-elm-forward : ∀(P : hProp ℓ) → [ P ⊓ ¬ P ] → [ ¬ P ⊓ P ]
lemma-comm-elm-forward P (p , ¬p) = (¬p , p)
lemma-comm-elm-back : ∀(P : hProp ℓ) → [ ¬ P ⊓ P ] → [ P ⊓ ¬ P ]
lemma-comm-elm-back P (¬p , p) = (p , ¬p)
comm-elm-iso : ∀(P : hProp ℓ) → Iso [ P ⊓ ¬ P ] [ ¬ P ⊓ P ]
comm-elm-iso P = λ where
.Iso.fun → lemma-comm-elm-forward P
.Iso.inv → lemma-comm-elm-back P
.Iso.rightInv _ → refl
.Iso.leftInv _ → refl
-- let A = fst P
-- [ P ⊓ ¬ P ] : A × (A → ⊥)
-- [ ¬ P ⊓ P ] : (A → ⊥) × A
-- we have `P ⊓ ¬ P ≡ ¬ P ⊓ P`
-- and we have ≡ for the witness-type `[ P ⊓ ¬ P ] ≡ [ ¬ P ⊓ P ]`
-- because `A × (A → ⊥) ≢ (A → ⊥) × A`
lemma-Σ-swap-≡ : ∀(A B : Type ℓ) → (A × B) ≡ (B × A)
lemma-Σ-swap-≡ A B = isoToPath (Σ-swap-Iso {A = A} {A' = B})
lemma-comm-elm' : ∀(P : hProp ℓ) → [ P ⊓ ¬ P ] ≡ [ ¬ P ⊓ P ]
lemma-comm-elm' P = lemma-Σ-swap-≡ _ _
lemma-comm-elm : ∀(P : hProp ℓ) → [ P ⊓ ¬ P ] ≡ [ ¬ P ⊓ P ]
lemma-comm-elm P = isoToPath (comm-elm-iso P)
-- see `2.8 Classical principles` in Booij's thesis
weak-LEM' : ∀(P : hProp ℓ) → [ (¬ ¬ P) ⊔ (¬ P) ]
weak-LEM' {ℓ = ℓ} P = {! (¬[P⊓¬P] P) ∘ pathTo⇒ (⊓-comm (¬ P) P) !} -- (⊓-comm P (¬ P)) ∘ (¬[P⊓¬P] P)
where
γ : P ⊓ ¬ P ≡ ¬ P ⊓ P
-- γ : PathP (λ i → ?)
γ = ⊓-comm P (¬ P)
κ : [ P ⊓ ¬ P ⇒ ¬ P ⊓ P ]
-- κ : [ P ⊓ ¬ P ] → [ ¬ P ⊓ P ] -- is the same !
κ = pathTo⇒ γ
η : [ P ⊓ ¬ P ] → [ ¬ P ⊓ P ]
η p = κ p
φ : [ ¬ (¬ P ⊓ P) ] -- and from here we would need deMorgan₁ to obtain the goal which is not provable without further assumptions
φ = (¬[P⊓¬P] P) ∘ pathTo⇒ (⊓-comm (¬ P) P)
-- (p , q) = Iso.inv ΣPathIsoPathΣ γ
pq : Σ[ p ∈ fst (P ⊓ ¬ P) ≡ fst (¬ P ⊓ P) ] PathP (λ i → isProp (p i)) (snd (P ⊓ ¬ P)) (snd (¬ P ⊓ P))
pq = Iso.inv ΣPathIsoPathΣ γ
p : fst (P ⊓ ¬ P) ≡ fst (¬ P ⊓ P)
p = fst pq
q : PathP (λ i → isProp (fst pq i)) (snd (P ⊓ ¬ P)) (snd (¬ P ⊓ P))
q = snd pq
k = transport {ℓ = ℓ} {A = isProp (fst (P ⊓ ¬ P))} {B = isProp (fst (¬ P ⊓ P))} {! κ !}
l = {! Σ[ A ∈ Type ℓ ] isProp A!}
-- ⊓-comm P (¬ P) : P ⊓ ¬ P ≡ ¬ P ⊓ P
-- [ ¬ ¬ P ⊔ ¬ P ]
-- [ ¬ (¬ P ⊓ P) ]
-- hProp ℓ = Σ[ A ∈ Type ℓ ] (∀(x y : A) → x ≡ y)
-- = Σ[ A ∈ Type ℓ ] isProp A
-- HOTT: Definition 3.3.1. A type P is a mere proposition if for all x, y : P we have x = y.
-- NOTE: so `isMere P = isProp P`
-- _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
-- _≡_ {A = A} = PathP (λ i → A)
-- transport : {A B : Type ℓ} → A ≡ B → A → B
-- transport p a = transp (λ i → p i) i0 a
-- pathTo⇒ : P ≡ Q → [ P ⇒ Q ]
-- PathP is dependent path type (builtin)
-- Path is non-dependent path type
-- PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
-- Path : ∀ {ℓ} (A : Type ℓ) → A → A → Type ℓ
-- Path A a b = PathP (λ _ → A) a b
-- Direct definitions of lower h-levels
-- isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
-- isProp A = (x y : A) → x ≡ y
-- isSet A = (x y : A) → isProp (x ≡ y)
--
-- an element of hProp states what the proposition is - the element is the proposition
-- an element of [ hProp ] states that the proposition holds - the element is the proof
-- pathes such as `P ⊓ ¬ P ≡ ¬ P ⊓ P` just state that the propositions are the same
-- we cannot use `transport` on `P ⊓ ¬ P ≡ ¬ P ⊓ P`
-- `⇔toPath` can be used to get equality of the propositions from forward and backward implication based on the witnesses
-- ⇔toPath : [ P ⇒ Q ] → [ Q ⇒ P ] → P ≡ Q
-- similar with `hProp≡`
-- hProp≡ : [ P ] ≡ [ Q ] → P ≡ Q
-- there is `pathTo⇒` and `pathTo⇐` to create witness-based implications
-- pathTo⇒ : P ≡ Q → [ P ⇒ Q ]
-- pathTo⇐ : P ≡ Q → [ Q ⇒ P ]
-- here, we have that `[ P ⇒ Q ]` is definitionally equivalent to `[ P ] → [ Q ]`
-- because `[ P ] → [ Q ]` is the first element of the tuple `P ⇒ Q` which gets projected out with `[_]`
-- A ⇒ B = ([ A ] → [ B ]) , isPropΠ λ _ → isProp[] B
-- we can use `isoToPath` to create a path `[ P ] ≡ [ Q ]` but only when we are able to formulate an isomorphism
-- so `[ P ] ≡ [ Q ]` is what we can transport the witnesses along
-- isoToPath : Iso A B → A ≡ B
-- isoToEquiv : Iso A B → A ≃ B
-- with
-- A ≃ B = Σ[ f ∈ A → B ] isEquiv f
-- where `isEquiv` is basically
-- isEquiv = (f : A → B) → ∀(y : B) → isContr (fiber f y)
-- but it seems to be a very strong property of two ≡-equal propositions to have their elements being ≡-equal too
-- is it? Or can we always find an isomorphism `Iso [ P ] [ Q ]` for every path `P ≡ Q`? I guess not
-- ∥¬A∥≡¬∥A∥
_ = hProp≡
_ = transport
_ = ∥ {!!} ∥
_ = _≡_
_ = Path
-- Propositions
--
-- Definition 2.4.1. A proposition is a type P all whose elements are identical, which is expressed type-theoretically as
--
-- isHProp(P) := (Π p, q : P) (p =ₚ q).
--
-- We have the type
--
-- HProp := (Σ P : U) isHProp(P)
--
-- of all propositions, and we identify elements of HProp with their underlying type, that is, their first projection.
-- The letter ‘H’ stands for homotopy, which we briefly touch on in Section 2.5.4.
--
-- checkout p.31 ff of Booij's thesis
--
-- Definition 2.4.5. Univalent logic is defined by the following, where P, Q : HProp and R : X → HProp [91, Definition 3.7.1]:
--
-- ⊤ := 1
-- ⊥ := 0
-- P ∧ Q := P × Q
-- P ⇒ Q := P → Q
-- P ⇔ Q := P = Q
-- ¬P := P → 0
-- P ∨ Q := ∥ P + Q ∥
-- (∀ x : X) R(x) := (Π x : X) R(x)
-- (∃ x : X) R(x) := ∥ (Σ x : X) R(x) ∥
--
-- NOTE: the important sentence is "we identify elements of HProp with ... their first projection"
-- therefore Agda's first projection `[_]` is not present in Booij's writing (it's implicit)
import Cubical.Functions.Embedding
-- Embeddings are generalizations of injections. The usual
-- definition of injection as:
--
-- f x ≡ f y → x ≡ y
--
-- is not well-behaved with higher h-levels, while embeddings
-- are.
--
-- isEmbedding : (A → B) → Type _
-- isEmbedding f = ∀ w x → isEquiv {A = w ≡ x} (cong f)
-- injEmbedding
-- : {f : A → B}
-- → isSet A → isSet B
-- → (∀{w x} → f w ≡ f x → w ≡ x)
-- → isEmbedding f
| 37.692308
| 133
| 0.542213
|
c579f2a0c67a659156e911e932117081396ec709
| 3,759
|
agda
|
Agda
|
LibraBFT/ImplShared/Util/Dijkstra/RWS/Syntax.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/ImplShared/Util/Dijkstra/RWS/Syntax.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/ImplShared/Util/Dijkstra/RWS/Syntax.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
-}
open import LibraBFT.ImplShared.Util.Dijkstra.RWS
open import LibraBFT.ImplShared.Util.Dijkstra.Syntax
open import LibraBFT.Prelude
open import Optics.All
-- This module contains definitions allowing RWS programs to be written using
-- Agda's do-notation, as well as convenient short names for operations
-- (including lens operations).
module LibraBFT.ImplShared.Util.Dijkstra.RWS.Syntax where
private
variable
Ev Wr St : Set
A B C : Set
-- From this instance declaration, we get _<$>_, pure, and _<*>_ also.
instance
RWS-Monad : Monad (RWS Ev Wr St)
Monad.return RWS-Monad = RWS-return
Monad._>>=_ RWS-Monad = RWS-bind
-- These instance declarations give us variant conditional operations that we
-- can define to play nice with `RWS-weakestPre`
instance
RWS-MonadIfD : MonadIfD{ℓ₃ = ℓ0} (RWS Ev Wr St)
MonadIfD.monad RWS-MonadIfD = RWS-Monad
MonadIfD.ifD‖ RWS-MonadIfD = RWS-if
RWS-MonadMaybeD : MonadMaybeD (RWS Ev Wr St)
MonadMaybeD.monad RWS-MonadMaybeD = RWS-Monad
MonadMaybeD.maybeSD RWS-MonadMaybeD = RWS-maybe
RWS-MonadEitherD : MonadEitherD (RWS Ev Wr St)
MonadEitherD.monad RWS-MonadEitherD = RWS-Monad
MonadEitherD.eitherSD RWS-MonadEitherD = RWS-either
gets : (St → A) → RWS Ev Wr St A
gets = RWS-gets
get : RWS Ev Wr St St
get = gets id
put : St → RWS Ev Wr St Unit
put = RWS-put
modify : (St → St) → RWS Ev Wr St Unit
modify f = do
st ← get
put (f st)
ask : RWS Ev Wr St Ev
ask = RWS-ask
tell : List Wr → RWS Ev Wr St Unit
tell = RWS-tell
tell1 : Wr → RWS Ev Wr St Unit
tell1 x = tell (x ∷ [])
act = tell1
void : RWS Ev Wr St A → RWS Ev Wr St Unit
void m = do
_ ← m
pure unit
-- -- Composition with error monad
ok : A → RWS Ev Wr St (B ⊎ A)
ok = pure ∘ Right
bail : B → RWS Ev Wr St (B ⊎ A)
bail = pure ∘ Left
infixl 4 _∙?∙_
_∙?∙_ : RWS Ev Wr St (Either C A) → (A → RWS Ev Wr St (Either C B)) → RWS Ev Wr St (Either C B)
_∙?∙_ = RWS-ebind
maybeSM : RWS Ev Wr St (Maybe A) → RWS Ev Wr St B → (A → RWS Ev Wr St B) → RWS Ev Wr St B
maybeSM mma mb f = do
x ← mma
caseMD x of λ where
nothing → mb
(just j) → f j
maybeSMP-RWS : RWS Ev Wr St (Maybe A) → B → (A → RWS Ev Wr St B)
→ RWS Ev Wr St B
maybeSMP-RWS ma b f = do
x ← ma
caseMD x of λ where
nothing → pure b
(just j) → f j
infixl 4 _∙^∙_
_∙^∙_ : RWS Ev Wr St (Either B A) → (B → B) → RWS Ev Wr St (Either B A)
m ∙^∙ f = do
x ← m
either (bail ∘ f) ok x
RWS-weakestPre-∙^∙Post : (ev : Ev) (e : C → C) → RWS-Post Wr St (C ⊎ A) → RWS-Post Wr St (C ⊎ A)
RWS-weakestPre-∙^∙Post ev e Post =
RWS-weakestPre-bindPost ev (either (bail ∘ e) ok) Post
-- Lens functionality
--
-- If we make RWS work for different level State types, we will break use and
-- modify because Lens does not support different levels, we define use and
-- modify' here for RoundManager. We are ok as long as we can keep
-- RoundManager in Set. If we ever need to make RoundManager at some higher
-- Level, we will have to consider making Lens level-agnostic. Preliminary
-- exploration by @cwjnkins showed this to be somewhat painful in particular
-- around composition, so we are not pursuing it for now.
use : Lens St A → RWS Ev Wr St A
use f = gets (_^∙ f)
modifyL : Lens St A → (A → A) → RWS Ev Wr St Unit
modifyL l f = modify (over l f)
syntax modifyL l f = l %= f
setL : Lens St A → A → RWS Ev Wr St Unit
setL l x = l %= const x
syntax setL l x = l ∙= x
setL? : Lens St (Maybe A) → A → RWS Ev Wr St Unit
setL? l x = l ∙= just x
syntax setL? l x = l ?= x
| 28.263158
| 111
| 0.667997
|
20d7c937857be83965e20328d4daabe352b12cd7
| 814
|
agda
|
Agda
|
test/Succeed/Issue2344.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue2344.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2344.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --allow-unsolved-metas #-}
-- Andreas, 2016-12-19, issue #2344, reported by oinkium, shrunk by Ulf
-- The function Agda.TypeChecking.Telescope.permuteTel
-- used in the unifier was buggy.
-- {-# OPTIONS -v tc.meta:25 #-}
-- {-# OPTIONS -v tc.lhs:10 #-}
-- {-# OPTIONS -v tc.lhs.unify:100 #-}
-- {-# OPTIONS -v tc.cover:20 #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
data Fin : Nat → Set where
zero : ∀ n → Fin (suc n)
postulate
T : Nat → Set
mkT : ∀{l} → T l
toNat : ∀ m → Fin m → Nat
-- The underscore in the type signature is originally dependent on A,X,i
-- but then pruned to be dependent on A,X only.
-- The unifier had a problem with this.
toNat-injective : ∀ (A : Set) X i → T (toNat _ i) -- Yellow expected.
toNat-injective A X (zero n) = mkT
-- Should pass.
| 26.258065
| 72
| 0.624079
|
1c148f38a445faa847242d5840150a73f56122d8
| 1,843
|
agda
|
Agda
|
examples/examplesPaperJFP/IOGraphicsLib.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/examplesPaperJFP/IOGraphicsLib.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/examplesPaperJFP/IOGraphicsLib.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
{-# OPTIONS --copatterns #-}
module examplesPaperJFP.IOGraphicsLib where
open import Data.Bool.Base
open import Data.Char.Base
open import Data.Nat.Base hiding (_⊓_; _+_; _*_)
open import Data.List.Base hiding (_++_)
open import Data.Integer.Base hiding (suc)
open import Data.String.Base
open import Data.Maybe.Base
open import Function
open import Size
open import SizedIO.Base
open import SizedIO.IOGraphicsLib hiding (GraphicsCommands; GraphicsResponses; GraphicsInterface; IOGraphics) renaming (Size to WindowSize)
open import NativeInt --PrimTypeHelpers
open import NativeIO
data GraphicsCommands : Set where
getWindowEvent : Window → GraphicsCommands
openWindow : String → Maybe Point → ℕ → ℕ
→ RedrawMode → Maybe Word32
→ GraphicsCommands
closeWindow : Window → GraphicsCommands
drawInWindow : Window → Graphic → GraphicsCommands
GraphicsResponses : GraphicsCommands → Set
GraphicsResponses (getWindowEvent _) = Event
GraphicsResponses (openWindow _ _ _ _ _ _) = Window
GraphicsResponses (closeWindow _) = Unit
GraphicsResponses (drawInWindow _ _) = Unit
GraphicsInterface : IOInterface
Command GraphicsInterface = GraphicsCommands
Response GraphicsInterface = GraphicsResponses
IOGraphics : Size → Set → Set
IOGraphics i = IO GraphicsInterface i
translateNative : (c : GraphicsCommands) → NativeIO (GraphicsResponses c)
translateNative (getWindowEvent w) = nativeGetWindowEvent w
translateNative (openWindow str point n1 n2 m w) = nativeOpenWindowExNat str point n1 n2 m w
translateNative (closeWindow w) = nativeCloseWindow w
translateNative (drawInWindow w g) = nativeDrawInWindow w g
| 33.509091
| 139
| 0.700488
|
cba93fdf19702f0a18ee0a488c516849ea2bf7e3
| 4,034
|
agda
|
Agda
|
hott/equivalence/alternative.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 27
|
2015-04-14T15:47:03.000Z
|
2022-01-09T07:26:57.000Z
|
src/hott/equivalence/alternative.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
hott/equivalence/alternative.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 4
|
2015-04-11T17:19:12.000Z
|
2019-02-26T06:17:38.000Z
|
{-# OPTIONS --without-K #-}
open import function.extensionality.core
module hott.equivalence.alternative where
open import sum
open import equality.core
open import equality.calculus
open import function.core
open import function.extensionality.proof
open import function.isomorphism.core
open import function.isomorphism.coherent
open import function.isomorphism.utils
open import hott.level.core
open import hott.equivalence.core
open import hott.univalence
module _ {i j}{X : Set i}{Y : Set j} where
open ≅-Reasoning
private
we-split-iso : (f : X → Y) → _
we-split-iso f = begin
weak-equiv f
≅⟨ ΠΣ-swap-iso ⟩
( Σ ((y : Y) → f ⁻¹ y) λ gβ
→ (y : Y)(u : f ⁻¹ y) → gβ y ≡ u )
≅⟨ Σ-ap-iso₁ ΠΣ-swap-iso ⟩
( Σ (Σ (Y → X) λ g → (y : Y) → f (g y) ≡ y) λ { (g , β)
→ (y : Y)(u : f ⁻¹ y) → (g y , β y) ≡ u } )
≅⟨ Σ-assoc-iso ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ (y : Y)(u : f ⁻¹ y) → (g y , β y) ≡ u )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ Π-ap-iso refl≅ λ y
→ curry-iso (λ x p → (g y , β y) ≡ (x , p)) ) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ (y : Y)(x : X)(p : f x ≡ y)
→ (g y , β y) ≡ (x , p) )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ Π-ap-iso refl≅ λ y
→ Π-ap-iso refl≅ λ x
→ Π-ap-iso refl≅ λ p
→ sym≅ Σ-split-iso ) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ (y : Y)(x : X)(p : f x ≡ y)
→ Σ (g y ≡ x) λ q
→ subst (λ x' → f x' ≡ y) q (β y) ≡ p )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ Π-ap-iso refl≅ λ y
→ Π-ap-iso refl≅ λ x
→ Π-ap-iso refl≅ λ p
→ Σ-ap-iso₂ λ q
→ sym≅ ( trans≡-iso (
subst-naturality (λ x' → x' ≡ y) f q (β y)
· subst-eq (ap f q) (β y)) )) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ (y : Y)(x : X)(p : f x ≡ y)
→ Σ (g y ≡ x) λ q
→ sym (ap f q) · β y ≡ p )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ Π-comm-iso ) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ (x : X)(y : Y)(p : f x ≡ y)
→ Σ (g y ≡ x) λ q
→ sym (ap f q) · β y ≡ p )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ Π-ap-iso refl≅ λ x
→ sym≅ J-iso ) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ (x : X)
→ Σ (g (f x) ≡ x) λ q
→ sym (ap f q) · β (f x) ≡ refl )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ ΠΣ-swap-iso ) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ Σ ((x : X) → g (f x) ≡ x) λ α
→ (x : X) → sym (ap f (α x)) · β (f x) ≡ refl )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₂ λ β
→ Σ-ap-iso₂ λ α
→ Π-ap-iso refl≅ λ x
→ sym≅ (trans≅ (trans≡-iso (left-unit (ap f (α x))))
(move-≡-iso (ap f (α x)) refl (β (f x)))) ) ⟩
( Σ (Y → X) λ g
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ Σ ((x : X) → g (f x) ≡ x) λ α
→ (x : X) → ap f (α x) ≡ β (f x) )
≅⟨ ( Σ-ap-iso₂ λ g → Σ-comm-iso ) ⟩
( Σ (Y → X) λ g
→ Σ ((x : X) → g (f x) ≡ x) λ α
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ ((x : X) → ap f (α x) ≡ β (f x)) )
∎
≈⇔≅' : (X ≈ Y) ≅ (X ≅' Y)
≈⇔≅' = begin
(X ≈ Y)
≅⟨ Σ-ap-iso₂ we-split-iso ⟩
( Σ (X → Y) λ f
→ Σ (Y → X) λ g
→ Σ ((x : X) → g (f x) ≡ x) λ α
→ Σ ((y : Y) → f (g y) ≡ y) λ β
→ ((x : X) → ap f (α x) ≡ β (f x)) )
≅⟨ record
{ to = λ {(f , g , α , β , γ) → iso f g α β , γ }
; from = λ { (iso f g α β , γ) → f , g , α , β , γ }
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl } ⟩
(X ≅' Y)
∎
open _≅_ ≈⇔≅' public using ()
renaming ( to to ≈⇒≅'
; from to ≅'⇒≈ )
≅⇒≈ : (X ≅ Y) → (X ≈ Y)
≅⇒≈ = ≅'⇒≈ ∘ ≅⇒≅'
| 30.560606
| 70
| 0.359197
|
df210fc3303199b3d4d56c18f383cf420b217dd2
| 1,818
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/PropositionalEquality/TrustMe.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Relation/Binary/PropositionalEquality/TrustMe.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/PropositionalEquality/TrustMe.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- An equality postulate which evaluates
------------------------------------------------------------------------
{-# OPTIONS --with-K #-}
module Relation.Binary.PropositionalEquality.TrustMe where
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
open import Agda.Builtin.TrustMe
-- trustMe {x = x} {y = y} evaluates to refl if x and y are
-- definitionally equal.
trustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y
trustMe = primTrustMe
-- "Erases" a proof. The original proof is not inspected. The
-- resulting proof reduces to refl if the two sides are definitionally
-- equal. Note that checking for definitional equality can be slow.
erase : ∀ {a} {A : Set a} {x y : A} → x ≡ y → x ≡ y
erase _ = trustMe
-- A "postulate with a reduction": postulate[ a ↦ b ] a evaluates to b,
-- while postulate[ a ↦ b ] a' gets stuck if a' is not definitionally
-- equal to a. This can be used to define a postulate of type (x : A) → B x
-- by only specifying the behaviour at B t for some t : A. Introduced in
--
-- Alan Jeffrey, Univalence via Agda's primTrustMe again
-- 23 January 2015
-- https://lists.chalmers.se/pipermail/agda/2015/007418.html
postulate[_↦_] : ∀ {a b} {A : Set a}{B : A → Set b} →
(t : A) → B t → (x : A) → B x
postulate[ a ↦ b ] a' with trustMe {x = a} {a'}
postulate[ a ↦ b ] .a | refl = b
------------------------------------------------------------------------
-- DEPRECATION
------------------------------------------------------------------------
-- Version 0.18
{-# WARNING_ON_USAGE erase
"Warning: erase was deprecated in v0.18.
Please use the safe function ≡-erase defined in Relation.Binary.PropositionalEquality.WithK instead."
#-}
| 34.301887
| 101
| 0.561606
|
0bd4c5e6fc6f6713798322fb1948d0522172ae76
| 11,428
|
agda
|
Agda
|
Cubical/Algebra/CommRing/FGIdeal.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/FGIdeal.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/FGIdeal.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
{-
Define finitely generated ideals of commutative rings and
show that they are an ideal.
Parts of this should be reusable for explicit constructions
of free modules over a finite set.
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.FGIdeal where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.FinData hiding (elim ; rec)
open import Cubical.Data.Nat renaming ( zero to ℕzero ; suc to ℕsuc
; _+_ to _+ℕ_ ; _·_ to _·ℕ_
; +-assoc to +ℕ-assoc ; +-comm to +ℕ-comm
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
hiding (elim)
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.Ring.QuotientRing
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.Matrix
private
variable
ℓ : Level
module _ (Ring@(R , str) : CommRing ℓ) where
infixr 5 _holds
_holds : hProp ℓ → Type ℓ
P holds = fst P
open CommRingStr str
open RingTheory (CommRing→Ring Ring)
open Sum (CommRing→Ring Ring)
linearCombination : {n : ℕ} → FinVec R n → FinVec R n → R
linearCombination α V = ∑ (λ i → α i · V i)
sumDist+ : ∀ {n : ℕ} (α β V : FinVec R n)
→ linearCombination (λ i → α i + β i) V ≡ linearCombination α V + linearCombination β V
sumDist+ α β V = ∑Ext (λ i → ·Ldist+ (α i) (β i) (V i)) ∙ ∑Split (λ i → α i · V i) (λ i → β i · V i)
dist- : ∀ {n : ℕ} (α V : FinVec R n)
→ linearCombination (λ i → - α i) V ≡ - linearCombination α V
dist- α V = ∑Ext (λ i → -DistL· (α i) (V i)) ∙ ∑Dist- (λ i → α i · V i)
dist0 : ∀ {n : ℕ} (V : FinVec R n)
→ linearCombination (replicateFinVec n 0r) V ≡ 0r
dist0 {n = n} V = ∑Ext (λ i → 0LeftAnnihilates (V i)) ∙ ∑0r n
isLinearCombination : {n : ℕ} → FinVec R n → R → Type ℓ
isLinearCombination V x = ∃[ α ∈ FinVec R _ ] x ≡ linearCombination α V
{- If x and y are linear combinations of l, then (x + y) is
a linear combination. -}
isLinearCombination+ : {n : ℕ} {x y : R} (V : FinVec R n)
→ isLinearCombination V x
→ isLinearCombination V y
→ isLinearCombination V (x + y)
isLinearCombination+ V = map2 λ α β → (λ i → α .fst i + β .fst i)
, cong₂ (_+_) (α .snd) (β .snd) ∙ sym (sumDist+ _ _ V)
{- If x is a linear combinations of l, then -x is
a linear combination. -}
isLinearCombination- : {n : ℕ} {x : R} (V : FinVec R n)
→ isLinearCombination V x → isLinearCombination V (- x)
isLinearCombination- V = map λ α → (λ i → - α .fst i) , cong (-_) (α .snd) ∙ sym (dist- _ V)
{- 0r is the trivial linear Combination -}
isLinearCombination0 : {n : ℕ} (V : FinVec R n)
→ isLinearCombination V 0r
isLinearCombination0 V = ∣ _ , sym (dist0 V) ∣
{- Linear combinations are stable under left multiplication -}
isLinearCombinationL· : {n : ℕ} (V : FinVec R n) (r : R) {x : R}
→ isLinearCombination V x → isLinearCombination V (r · x)
isLinearCombinationL· V r = map λ α → (λ i → r · α .fst i) , cong (r ·_) (α .snd)
∙∙ ∑Mulrdist r (λ i → α .fst i · V i)
∙∙ ∑Ext λ i → ·Assoc r (α .fst i) (V i)
generatedIdeal : {n : ℕ} → FinVec R n → IdealsIn Ring
generatedIdeal V = makeIdeal Ring
(λ x → isLinearCombination V x , isPropPropTrunc)
(isLinearCombination+ V)
(isLinearCombination0 V)
λ r → isLinearCombinationL· V r
open CommIdeal.isCommIdeal
genIdeal : {n : ℕ} (R : CommRing ℓ) → FinVec (fst R) n → CommIdeal.CommIdeal R
fst (genIdeal R V) x = isLinearCombination R V x , isPropPropTrunc
+Closed (snd (genIdeal R V)) = isLinearCombination+ R V
contains0 (snd (genIdeal R V)) = isLinearCombination0 R V
·Closed (snd (genIdeal R V)) r = isLinearCombinationL· R V r
syntax genIdeal R V = ⟨ V ⟩[ R ]
FGIdealIn : (R : CommRing ℓ) → Type (ℓ-suc ℓ)
FGIdealIn R = Σ[ I ∈ CommIdeal.CommIdeal R ]
∃[ nV ∈ Σ[ n ∈ ℕ ] FinVec (fst R) n ] I ≡ ⟨ nV .snd ⟩[ R ]
-- The lattice laws
module _ (R' : CommRing ℓ) where
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
open CommIdeal R'
open Sum (CommRing→Ring R')
open KroneckerDelta (CommRing→Ring R')
private
R = fst R'
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
inclOfFGIdeal : {n : ℕ} (V : FinVec R n) (I : CommIdeal)
→ (∀ i → V i ∈ I) → ⟨ V ⟩ ⊆ I
inclOfFGIdeal V I ∀i→Vi∈I x = elim (λ _ → I .fst x .snd) inclOfFGIdealΣ
where
inclOfFGIdealΣ : Σ[ α ∈ FinVec R _ ] x ≡ linearCombination R' α V → x ∈ I
inclOfFGIdealΣ (α , x≡α·V) = subst-∈ I (sym x≡α·V) (∑Closed I (λ i → α i · V i)
λ i → ·Closed (I .snd) _ (∀i→Vi∈I i))
indInIdeal : ∀ {n : ℕ} (U : FinVec R n) (i : Fin n) → U i ∈ ⟨ U ⟩
indInIdeal U i = ∣ (δ i) , sym (∑Mul1r _ U i) ∣
sucIncl : ∀ {n : ℕ} (U : FinVec R (ℕsuc n)) → ⟨ U ∘ suc ⟩ ⊆ ⟨ U ⟩
sucIncl U x = map λ (α , x≡∑αUsuc) → (λ { zero → 0r ; (suc i) → α i }) , x≡∑αUsuc ∙ path _ _
where
path : ∀ s u₀ → s ≡ 0r · u₀ + s
path = solve R'
emptyFGIdeal : ∀ (V : FinVec R 0) → ⟨ V ⟩ ≡ 0Ideal
emptyFGIdeal V = CommIdeal≡Char (λ _ → rec (is-set _ _) snd)
(λ _ x≡0 → ∣ (λ ()) , x≡0 ∣)
0FGIdealLIncl : {n : ℕ} → ⟨ replicateFinVec n 0r ⟩ ⊆ 0Ideal
0FGIdealLIncl x = elim (λ _ → is-set _ _)
λ (α , x≡∑α0) → subst-∈ 0Ideal (sym x≡∑α0) (∑Closed 0Ideal (λ i → α i · 0r)
λ i → subst-∈ 0Ideal (sym (0RightAnnihilates _)) refl)
0FGIdealRIncl : {n : ℕ} → 0Ideal ⊆ ⟨ replicateFinVec n 0r ⟩
0FGIdealRIncl x x≡0 = subst-∈ ⟨ replicateFinVec _ 0r ⟩ (sym x≡0)
(⟨ replicateFinVec _ 0r ⟩ .snd .contains0)
0FGIdeal : {n : ℕ} → ⟨ replicateFinVec n 0r ⟩ ≡ 0Ideal
0FGIdeal = CommIdeal≡Char 0FGIdealLIncl 0FGIdealRIncl
FGIdealAddLemmaLIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ++Fin V ⟩ ⊆ (⟨ U ⟩ +i ⟨ V ⟩)
FGIdealAddLemmaLIncl {n = ℕzero} U V x x∈⟨V⟩ =
∣ (0r , x) , ⟨ U ⟩ .snd .contains0 , x∈⟨V⟩ , sym (+Lid x) ∣
FGIdealAddLemmaLIncl {n = ℕsuc n} U V x = rec isPropPropTrunc helperΣ
where
helperΣ : Σ[ α ∈ FinVec R _ ] (x ≡ ∑ λ i → α i · (U ++Fin V) i) → x ∈ (⟨ U ⟩ +i ⟨ V ⟩)
helperΣ (α , p) = subst-∈ (⟨ U ⟩ +i ⟨ V ⟩) (sym p)
((⟨ U ⟩ +i ⟨ V ⟩) .snd .+Closed zeroIncl sumIncl)
where
zeroIncl : (α zero · U zero) ∈ (⟨ U ⟩ +i ⟨ V ⟩)
zeroIncl = +iLincl ⟨ U ⟩ ⟨ V ⟩ (α zero · U zero)
(⟨ U ⟩ .snd .·Closed (α zero) (indInIdeal U zero))
sumIncl : (∑ λ i → (α ∘ suc) i · ((U ∘ suc) ++Fin V) i) ∈ (⟨ U ⟩ +i ⟨ V ⟩)
sumIncl = let sum = ∑ λ i → (α ∘ suc) i · ((U ∘ suc) ++Fin V) i in
+iRespLincl ⟨ U ∘ suc ⟩ ⟨ U ⟩ ⟨ V ⟩ (sucIncl U) sum
(FGIdealAddLemmaLIncl (U ∘ suc) V _ ∣ (α ∘ suc) , refl ∣)
FGIdealAddLemmaRIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ (⟨ U ⟩ +i ⟨ V ⟩) ⊆ ⟨ U ++Fin V ⟩
FGIdealAddLemmaRIncl U V x = rec isPropPropTrunc (uncurry3 helper)
where
helperΣ : ((y , z) : R × R)
→ Σ[ α ∈ FinVec R _ ] (y ≡ ∑ λ i → α i · U i)
→ Σ[ β ∈ FinVec R _ ] (z ≡ ∑ λ i → β i · V i)
→ x ≡ y + z
→ x ∈ ⟨ U ++Fin V ⟩
helperΣ (y , z) (α , y≡∑αU) (β , z≡∑βV) x≡y+z = ∣ (α ++Fin β) , path ∣
where
path : x ≡ ∑ λ i → (α ++Fin β) i · (U ++Fin V) i
path = x ≡⟨ x≡y+z ⟩
y + z ≡⟨ cong₂ (_+_) y≡∑αU z≡∑βV ⟩
(∑ λ i → α i · U i) + (∑ λ i → β i · V i) ≡⟨ sym (∑Split++ (λ i → α i · U i) _) ⟩
(∑ ((λ i → α i · U i) ++Fin (λ i → β i · V i))) ≡⟨ ∑Ext (mul++dist α U β V) ⟩
(∑ λ i → (α ++Fin β) i · (U ++Fin V) i) ∎
helper : ((y , z) : R × R)
→ ∃[ α ∈ FinVec R _ ] (y ≡ ∑ λ i → α i · U i)
→ ∃[ β ∈ FinVec R _ ] (z ≡ ∑ λ i → β i · V i)
→ x ≡ y + z
→ x ∈ ⟨ U ++Fin V ⟩
helper _ = rec2 (isPropΠ (λ _ → isPropPropTrunc)) (helperΣ _)
FGIdealAddLemma : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ++Fin V ⟩ ≡ ⟨ U ⟩ +i ⟨ V ⟩
FGIdealAddLemma U V = CommIdeal≡Char (FGIdealAddLemmaLIncl U V) (FGIdealAddLemmaRIncl U V)
IdealAddAssoc : {n m k : ℕ} (U : FinVec R n) (V : FinVec R m) (W : FinVec R k)
→ ⟨ U ++Fin (V ++Fin W) ⟩ ≡ ⟨ (U ++Fin V) ++Fin W ⟩
IdealAddAssoc {n = n} {m = m} {k = k} U V W =
let genIdealExpl : (n : ℕ) → FinVec R n → CommIdeal
genIdealExpl _ V = ⟨ V ⟩
in cong₂ genIdealExpl (+ℕ-assoc n m k) (++FinAssoc U V W)
++FinComm : ∀ {n m : ℕ} (V : FinVec R n) (W : FinVec R m)
→ ⟨ V ++Fin W ⟩ ≡ ⟨ W ++Fin V ⟩
++FinComm V W = FGIdealAddLemma V W ∙∙ +iComm ⟨ V ⟩ ⟨ W ⟩ ∙∙ sym (FGIdealAddLemma W V)
open ProdFin R'
prodIn··Ideal : {n m : ℕ} (U : FinVec R n) (V : FinVec R m) (x y : R)
→ (x ∈ ⟨ U ⟩) → (y ∈ ⟨ V ⟩) → (x · y) ∈ ⟨ U ··Fin V ⟩
prodIn··Ideal {n = n} {m = m} U V x y = map2 Σhelper
where
Σhelper : Σ[ α ∈ FinVec R n ] x ≡ linearCombination R' α U
→ Σ[ β ∈ FinVec R m ] y ≡ linearCombination R' β V
→ Σ[ γ ∈ FinVec R (n ·ℕ m) ] (x · y) ≡ linearCombination R' γ (U ··Fin V)
Σhelper (α , x≡∑αU) (β , y≡∑βV) = α ··Fin β , path
where
path : x · y ≡ ∑ λ i → (α ··Fin β) i · (U ··Fin V) i
path = x · y ≡⟨ cong₂ (_·_) x≡∑αU y≡∑βV ⟩
(∑ λ i → α i · U i) · (∑ λ i → β i · V i) ≡⟨ ∑Dist··Fin (λ i → α i · U i) _ ⟩
(∑ λ j → ((λ i → α i · U i) ··Fin (λ i → β i · V i)) j) ≡⟨ ∑Ext (·Dist··Fin α U β V) ⟩
(∑ λ i → (α ··Fin β) i · (U ··Fin V) i) ∎
FGIdealMultLemmaLIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ··Fin V ⟩ ⊆ (⟨ U ⟩ ·i ⟨ V ⟩)
FGIdealMultLemmaLIncl U V x = elim (λ _ → isPropPropTrunc)
λ (α , x≡∑αUV) → subst-∈ (⟨ U ⟩ ·i ⟨ V ⟩) (sym x≡∑αUV) --replace x by ∑αᵢⱼUᵢVⱼ
(∑Closed (⟨ U ⟩ ·i ⟨ V ⟩) (λ i → α i · (U ··Fin V) i) --show that each αᵢ(U··V)ᵢ is in product
λ i → (⟨ U ⟩ ·i ⟨ V ⟩) .snd .·Closed (α i) --drop the α's
(flattenElim {P = _∈ (⟨ U ⟩ ·i ⟨ V ⟩)} (toMatrix U V) --show theat UᵢVⱼ is in product
(λ j k → prodInProd ⟨ U ⟩ ⟨ V ⟩ (U j) (V k) (indInIdeal U j) (indInIdeal V k)) i))
FGIdealMultLemmaRIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ (⟨ U ⟩ ·i ⟨ V ⟩) ⊆ ⟨ U ··Fin V ⟩
FGIdealMultLemmaRIncl U V x = elim (λ _ → isPropPropTrunc)
λ (_ , (α , β) , ∀α∈⟨U⟩ , ∀β∈⟨V⟩ , x≡∑αβ) → subst-∈ ⟨ U ··Fin V ⟩ (sym x≡∑αβ)
(∑Closed ⟨ U ··Fin V ⟩ _ (λ i → prodIn··Ideal U V (α i) (β i) (∀α∈⟨U⟩ i) (∀β∈⟨V⟩ i)))
FGIdealMultLemma : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ··Fin V ⟩ ≡ ⟨ U ⟩ ·i ⟨ V ⟩
FGIdealMultLemma U V = CommIdeal≡Char (FGIdealMultLemmaLIncl U V) (FGIdealMultLemmaRIncl U V)
| 45.712
| 102
| 0.506388
|
203d3890b67923dab46b0128035f2648601a9acd
| 852
|
agda
|
Agda
|
Data/PolyP/Derivations/Levels.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Data/PolyP/Derivations/Levels.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Data/PolyP/Derivations/Levels.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe --guardedness #-}
module Data.PolyP.Derivations.Levels where
open import Data.PolyP
open import Level
open import Data.PolyP.Types
open import Data.Sum
open import Data.Sigma
open import Data.Unit
open import Data.Fin
open import Data.Nat
open import Data.Vec
open import Function
open import Literals.Number
open import Data.Fin.Literals
open import Data.Nat.Literals
levels : ⟦ FOREST ⟧ ~ A → ⟦ LEVELS ⟧ ~ A
levels t = go t []′
where
go : ⟦ FOREST ⟧ ~ A → ⟦ LEVELS ⟧ ~ A → ⟦ LEVELS ⟧ ~ A
go =
cata λ xs zs →
cata (λ { (inl _ ) → zs
; (inr (inl _ , qs ) ) → qs
; (inr (inr (x , xs) , []′ ) ) → (x ∷′ []′ ) ∷′ xs []′
; (inr (inr (x , xs) , q ∷′ qs ) ) → (x ∷′ q ) ∷′ xs qs
}) xs
| 28.4
| 79
| 0.521127
|
fb3bea7423703f96d7fd38011214d0a43598fa13
| 2,267
|
agda
|
Agda
|
formalization/agda/Spire/Examples/Standard.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 43
|
2015-05-28T23:25:33.000Z
|
2022-03-08T17:10:59.000Z
|
formalization/agda/Spire/Examples/Standard.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | null | null | null |
formalization/agda/Spire/Examples/Standard.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 1
|
2015-08-17T21:00:07.000Z
|
2015-08-17T21:00:07.000Z
|
module Spire.Examples.Standard where
----------------------------------------------------------------------
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
data Vec (A : Set) : ℕ → Set where
nil : Vec A zero
cons : (n : ℕ) (a : A) (xs : Vec A n) → Vec A (suc n)
----------------------------------------------------------------------
elimℕ : (P : ℕ → Set)
(pzero : P zero)
(psuc : (m : ℕ) → P m → P (suc m))
(n : ℕ)
→ P n
elimℕ P pzero psuc zero = pzero
elimℕ P pzero psuc (suc n) = psuc n (elimℕ P pzero psuc n)
elimVec : (A : Set) (P : (n : ℕ) → Vec A n → Set)
(pnil : P zero nil)
(pcons : (n : ℕ) (a : A) (xs : Vec A n) → P n xs → P (suc n) (cons n a xs))
(n : ℕ)
(xs : Vec A n)
→ P n xs
elimVec A P pnil pcons .zero nil = pnil
elimVec A P pnil pcons .(suc n) (cons n a xs) = pcons n a xs (elimVec A P pnil pcons n xs)
----------------------------------------------------------------------
module PatternMatching where
add : ℕ → ℕ → ℕ
add zero n = n
add (suc m) n = suc (add m n)
mult : ℕ → ℕ → ℕ
mult zero n = zero
mult (suc m) n = add n (mult m n)
append : (A : Set) (m : ℕ) (xs : Vec A m) (n : ℕ) (ys : Vec A n) → Vec A (add m n)
append A .zero nil n ys = ys
append A .(suc m) (cons m x xs) n ys = cons (add m n) x (append A m xs n ys)
concat : (A : Set) (m n : ℕ) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m .zero nil = nil
concat A m .(suc n) (cons n xs xss) = append A m xs (mult n m) (concat A m n xss)
----------------------------------------------------------------------
module Eliminator where
add : ℕ → ℕ → ℕ
add = elimℕ (λ _ → ℕ → ℕ)
(λ n → n)
(λ m ih n → suc (ih n))
mult : ℕ → ℕ → ℕ
mult = elimℕ (λ _ → ℕ → ℕ)
(λ n → zero)
(λ m ih n → add n (ih n))
append : (A : Set) (m : ℕ) (xs : Vec A m) (n : ℕ) (ys : Vec A n) → Vec A (add m n)
append A = elimVec A (λ m xs → (n : ℕ) (ys : Vec A n) → Vec A (add m n))
(λ n ys → ys)
(λ m x xs ih n ys → cons (add m n) x (ih n ys))
concat : (A : Set) (m n : ℕ) (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
(λ n xs xss ih → append A m xs (mult n m) ih)
----------------------------------------------------------------------
| 29.441558
| 90
| 0.430525
|
4dc229fa7babb31e2e0d2dc4473ae34100f8783c
| 2,078
|
agda
|
Agda
|
src/Categories/Category/Construction/Core.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Construction/Core.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Construction/Core.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
-- The core of a category.
-- See https://ncatlab.org/nlab/show/core
module Categories.Category.Construction.Core {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level using (_⊔_)
open import Function using (flip)
open import Categories.Category.Groupoid using (Groupoid; IsGroupoid)
open import Categories.Morphism 𝒞 as Morphism
open import Categories.Morphism.IsoEquiv 𝒞 as IsoEquiv
open Category 𝒞
open _≃_
Core : Category o (ℓ ⊔ e) e
Core = record
{ Obj = Obj
; _⇒_ = _≅_
; _≈_ = _≃_
; id = ≅.refl
; _∘_ = flip ≅.trans
; assoc = ⌞ assoc ⌟
; sym-assoc = ⌞ sym-assoc ⌟
; identityˡ = ⌞ identityˡ ⌟
; identityʳ = ⌞ identityʳ ⌟
; identity² = ⌞ identity² ⌟
; equiv = ≃-isEquivalence
; ∘-resp-≈ = λ where ⌞ eq₁ ⌟ ⌞ eq₂ ⌟ → ⌞ ∘-resp-≈ eq₁ eq₂ ⌟
}
Core-isGroupoid : IsGroupoid Core
Core-isGroupoid = record
{ _⁻¹ = ≅.sym
; iso = λ {_ _ f} → record { isoˡ = ⌞ isoˡ f ⌟ ; isoʳ = ⌞ isoʳ f ⌟ }
}
where open _≅_
CoreGroupoid : Groupoid o (ℓ ⊔ e) e
CoreGroupoid = record { category = Core; isGroupoid = Core-isGroupoid }
module CoreGroupoid = Groupoid CoreGroupoid
-- Useful shorthands for reasoning about isomorphisms and morphisms of
-- 𝒞 in the same module.
module Shorthands where
module Commutationᵢ where
open Commutation Core public using () renaming ([_⇒_]⟨_≈_⟩ to [_≅_]⟨_≈_⟩)
infixl 2 connectᵢ
connectᵢ : ∀ {A C : Obj} (B : Obj) → A ≅ B → B ≅ C → A ≅ C
connectᵢ B f g = ≅.trans f g
syntax connectᵢ B f g = f ≅⟨ B ⟩ g
open _≅_ public
open _≃_ public
open Morphism public using (module _≅_)
open IsoEquiv public using (⌞_⌟) renaming (module _≃_ to _≈ᵢ_)
open CoreGroupoid public using (_⁻¹) renaming
( _⇒_ to _≅_
; _≈_ to _≈ᵢ_
; id to idᵢ
; _∘_ to _∘ᵢ_
; iso to ⁻¹-iso
; module Equiv to Equivᵢ
; module HomReasoning to HomReasoningᵢ
; module iso to ⁻¹-iso
)
| 27.706667
| 79
| 0.598171
|
4dba82f3a117ac414a87d2107e2dea0061489b47
| 1,752
|
agda
|
Agda
|
src/plfa-code/Naturals.agda
|
chirsz-ever/plfa-code
|
ec5b359a8c22bf5268cae3c36a97e6737c75d5f3
|
[
"MIT"
] | null | null | null |
src/plfa-code/Naturals.agda
|
chirsz-ever/plfa-code
|
ec5b359a8c22bf5268cae3c36a97e6737c75d5f3
|
[
"MIT"
] | null | null | null |
src/plfa-code/Naturals.agda
|
chirsz-ever/plfa-code
|
ec5b359a8c22bf5268cae3c36a97e6737c75d5f3
|
[
"MIT"
] | null | null | null |
module plfa-code.Naturals where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
_ : 2 + 3 ≡ 5
_ = refl
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + (m * n)
_^_ : ℕ → ℕ → ℕ
n ^ zero = suc zero
n ^ (suc m) = n * (n ^ m)
_ : 3 ^ 4 ≡ 81
_ =
begin
3 ^ 4
≡⟨⟩
3 * (3 ^ 3)
≡⟨⟩
3 * (3 * (3 ^ 2))
≡⟨⟩
3 * (3 * (3 * (3 ^ 1)))
≡⟨⟩
3 * (3 * (3 * (3 * (3 ^ 0))))
≡⟨⟩
3 * (3 * (3 * (3 * 1)))
≡⟨⟩
81
∎
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
_ =
begin
3 ∸ 2
≡⟨⟩
2 ∸ 1
≡⟨⟩
1 ∸ 0
≡⟨⟩
1
∎
_ =
begin
2 ∸ 3
≡⟨⟩
1 ∸ 2
≡⟨⟩
0 ∸ 1
≡⟨⟩
0
∎
infixl 6 _+_ _∸_
infixl 7 _*_
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
inc : Bin → Bin
inc nil = x1 nil
inc (x0 t) = x1 t
inc (x1 t) = x0 (inc t)
_ : inc (x1 x1 x0 x1 nil) ≡ x0 x0 x1 x1 nil
_ = refl
_ : inc (x0 nil) ≡ x1 nil
_ = refl
_ : inc (x1 nil) ≡ x0 x1 nil
_ = refl
_ : inc (x0 x1 nil) ≡ x1 x1 nil
_ = refl
_ : inc (x1 x1 nil) ≡ x0 x0 x1 nil
_ = refl
to : ℕ → Bin
to 0 = x0 nil
to (suc n) = inc (to n)
from : Bin → ℕ
from nil = 0
from (x0 t) = (from t) * 2
from (x1 t) = (from t) * 2 + 1
_ : to 0 ≡ x0 nil
_ = refl
_ : to 1 ≡ x1 nil
_ = refl
_ : to 2 ≡ x0 x1 nil
_ = refl
_ : to 3 ≡ x1 x1 nil
_ = refl
_ : to 4 ≡ x0 x0 x1 nil
_ = refl
_ : 0 ≡ from (x0 nil)
_ = refl
_ : 1 ≡ from (x1 nil)
_ = refl
_ : 2 ≡ from (x0 x1 nil)
_ = refl
_ : 3 ≡ from (x1 x1 nil)
_ = refl
_ : 4 ≡ from (x0 x0 x1 nil)
_ = refl
| 12.514286
| 50
| 0.447489
|
1c563d9246f91041eaf9dd754ef32a5ec3e6b0fc
| 1,298
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Cubical/Id.agda
|
banacorn/agda
|
2a07bfdf2c1c4ae87f428809af0887aceb6632c0
|
[
"MIT"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/Cubical/Id.agda
|
banacorn/agda
|
2a07bfdf2c1c4ae87f428809af0887aceb6632c0
|
[
"MIT"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/Cubical/Id.agda
|
banacorn/agda
|
2a07bfdf2c1c4ae87f428809af0887aceb6632c0
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --erased-cubical --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Cubical.Id where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub renaming (primSubOut to ouc; Sub to _[_↦_])
postulate
Id : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
{-# BUILTIN ID Id #-}
{-# BUILTIN CONID conid #-}
-- Id x y is treated as a pair of I and x ≡ y, using "i" for the
-- first component and "p" for the second.
{-# COMPILE JS conid =
_ => _ => _ => _ => i => p => { return { "i" : i, "p" : p } }
#-}
primitive
primDepIMin : _
primIdFace : ∀ {ℓ} {A : Set ℓ} {x y : A} → Id x y → I
primIdPath : ∀ {ℓ} {A : Set ℓ} {x y : A} → Id x y → x ≡ y
primitive
primIdJ : ∀ {ℓ ℓ'} {A : Set ℓ} {x : A} (P : ∀ y → Id x y → Set ℓ') →
P x (conid i1 (λ i → x)) → ∀ {y} (p : Id x y) → P y p
primitive
primIdElim : ∀ {a c} {A : Set a} {x : A}
(C : (y : A) → Id x y → Set c) →
((φ : I) (y : A [ φ ↦ (λ _ → x) ])
(w : (x ≡ ouc y) [ φ ↦ (λ { (φ = i1) → \ _ → x}) ]) →
C (ouc y) (conid φ (ouc w))) →
{y : A} (p : Id x y) → C y p
| 33.282051
| 82
| 0.44453
|
0bd84c0d578a70287c4022d247b8be50a7fda246
| 6,203
|
agda
|
Agda
|
Projection.agda
|
fangyi-zhou/mpst-in-agda
|
3d12eed9d340207d242d70f43c6b34e01d3620de
|
[
"MIT"
] | 1
|
2021-08-14T17:36:53.000Z
|
2021-08-14T17:36:53.000Z
|
Projection.agda
|
fangyi-zhou/mpst-in-agda
|
3d12eed9d340207d242d70f43c6b34e01d3620de
|
[
"MIT"
] | 1
|
2021-08-31T10:15:38.000Z
|
2021-11-24T11:30:17.000Z
|
Projection.agda
|
fangyi-zhou/mpst-in-agda
|
3d12eed9d340207d242d70f43c6b34e01d3620de
|
[
"MIT"
] | null | null | null |
open import Data.Empty using (⊥-elim)
open import Data.Fin using (Fin; _≟_)
open import Data.Nat using (ℕ)
open import Data.Product using (∃-syntax; _,_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Vec using (lookup; _[_]≔_)
open import Data.Vec.Properties using (lookup∘update; lookup∘update′)
open import Relation.Nullary using (yes; no; ¬_)
open import Relation.Binary.PropositionalEquality using (sym; trans; _≡_; refl; cong; _≢_; module ≡-Reasoning)
open import Data.Product using (∃-syntax; _,_; proj₁; proj₂; _×_)
open ≡-Reasoning
open import Common
open import Global
open import Local
private
variable
n : ℕ
l : Label
p q : Fin n
g gSub : Global n
lSub : Local n
project : Global n -> Fin n -> Local n
project endG _
= endL
project (msgSingle p q p≢q l gSub) r
with p ≟ r | q ≟ r
... | yes _ | no _ = sendSingle q l (project gSub r)
... | no _ | yes _ = recvSingle p l (project gSub r)
... | no _ | no _ = project gSub r
... | yes refl | yes refl = ⊥-elim (p≢q refl)
proj-prefix-other :
(r s t : Fin n)
-> ∀{ r≢s }
-> (gSub : Global n)
-> r ≢ t
-> s ≢ t
-> project (msgSingle r s r≢s l gSub) t ≡ project gSub t
proj-prefix-other r s t _ r≢t s≢t
with r ≟ t | s ≟ t
... | yes refl | _ = ⊥-elim (r≢t refl)
... | _ | yes refl = ⊥-elim (s≢t refl)
... | no _ | no _ = refl
proj-prefix-send :
(r s : Fin n)
-> (gSub : Global n)
-> (r≢s : r ≢ s)
-> project (msgSingle r s r≢s l gSub) r ≡ sendSingle s l (project gSub r)
proj-prefix-send r s _ r≢s
with r ≟ r | s ≟ r
... | yes _ | no _ = refl
... | _ | yes refl = ⊥-elim (r≢s refl)
... | no r≢r | no _ = ⊥-elim (r≢r refl)
proj-prefix-recv :
(r s : Fin n)
-> (gSub : Global n)
-> (r≢s : r ≢ s)
-> project (msgSingle r s r≢s l gSub) s ≡ recvSingle r l (project gSub s)
proj-prefix-recv r s _ r≢s
with r ≟ s | s ≟ s
... | no _ | yes _ = refl
... | yes refl | _ = ⊥-elim (r≢s refl)
... | _ | no s≢s = ⊥-elim (s≢s refl)
record _↔_ { n : ℕ } (g : Global n) (c : Configuration n) : Set where
field
isProj : ∀(p : Fin n) -> lookup c p ≡ project g p
proj-inv-send :
project {n} g p ≡ sendSingle q l lSub
-> ∃[ p≢q ] ∃[ gSub ] g ≡ msgSingle p q p≢q l gSub × project gSub p ≡ lSub
⊎
∃[ r ] ∃[ s ] ∃[ r≢s ] ∃[ l′ ] ∃[ gSub ]
g ≡ msgSingle r s r≢s l′ gSub ×
r ≢ p ×
s ≢ p ×
project gSub p ≡ sendSingle q l lSub
proj-inv-send {g = g@endG} projSend = ⊥-elim (endL≢sendSingle projSend)
proj-inv-send {n} {g = g@(msgSingle r s r≢s l′ gSub)} {p} {q} {l} {ltSub} projSend
with r ≟ p | s ≟ p
... | yes refl | yes refl = ⊥-elim (r≢s refl)
... | no r≢p | no s≢p = inj₂ (r , s , r≢s , l′ , gSub , refl , r≢p , s≢p , projSend)
... | yes refl | no s≢p
with sendSingle-injective projSend
... | refl , refl , refl = inj₁ (r≢s , gSub , refl , refl)
proj-inv-recv :
project {n} g p ≡ recvSingle q l lSub
-> ∃[ p≢q ] ∃[ gSub ] g ≡ msgSingle q p p≢q l gSub × project gSub p ≡ lSub
⊎
∃[ r ] ∃[ s ] ∃[ r≢s ] ∃[ l′ ] ∃[ gSub ]
g ≡ msgSingle r s r≢s l′ gSub ×
r ≢ p ×
s ≢ p ×
project gSub p ≡ recvSingle q l lSub
proj-inv-recv {g = g@endG} projRecv = ⊥-elim (endL≢recvSingle projRecv)
proj-inv-recv {n} {g = g@(msgSingle r s r≢s l′ gSub)} {p} {q} {l} {lSub} projRecv
with r ≟ p | s ≟ p
... | yes refl | yes refl = ⊥-elim (r≢s refl)
... | no r≢p | no s≢p = inj₂ (r , s , r≢s , l′ , gSub , refl , r≢p , s≢p , projRecv)
... | no r≢p | yes refl
with recvSingle-injective projRecv
... | refl , refl , refl = inj₁ (r≢s , gSub , refl , refl)
proj-inv-send-recv :
∀ { lpSub lqSub }
-> project {n} g p ≡ sendSingle q l lpSub
-> project {n} g q ≡ recvSingle p l lqSub
-> ∃[ p≢q ] ∃[ gSub ] g ≡ msgSingle p q p≢q l gSub × project gSub p ≡ lpSub × project gSub q ≡ lqSub
⊎
∃[ r ] ∃[ s ] ∃[ r≢s ] ∃[ l′ ] ∃[ gSub ]
g ≡ msgSingle r s r≢s l′ gSub ×
r ≢ p ×
s ≢ p ×
r ≢ q ×
s ≢ q ×
project gSub p ≡ sendSingle q l lpSub ×
project gSub q ≡ recvSingle p l lqSub
proj-inv-send-recv {n} {g} {p} {q} {l} {lpSub} {lqSub} projSend projRecv
with proj-inv-send {n} {g} projSend | proj-inv-recv {n} {g} projRecv
... | inj₁ (p≢q₁ , gSub₁ , refl , proj-g₁-p)
| inj₁ (_ , _ , refl , proj-g₂-q)
= inj₁ (p≢q₁ , gSub₁ , refl , proj-g₁-p , proj-g₂-q)
proj-inv-send-recv {n} {g} {p} {q} {l} {ltp′} {ltq′} projSend projRecv
| inj₁ (_ , _ , refl , _)
| inj₂ (_ , _ , _ , _ , _ , refl , _ , s≢q , _)
= ⊥-elim (s≢q refl)
proj-inv-send-recv {n} {g} {p} {q} {l} {ltp′} {ltq′} projSend projRecv
| inj₂ (_ , _ , _ , _ , _ , refl , r≢p , _ , _)
| inj₁ (_ , _ , refl , _)
= ⊥-elim (r≢p refl)
proj-inv-send-recv {n} {g} {p} {q} {l} {ltp′} {ltq′} projSend projRecv
| inj₂ (r , s , r≢s , l′ , gSub₁ , refl , r≢p , s≢p , proj-g₁-p)
| inj₂ (_ , _ , _ , _ , gSub₂ , refl , r≢q , s≢q , proj-g₂-q)
= inj₂ (r , s , r≢s , l′ , gSub₁ , refl , r≢p , s≢p , r≢q , s≢q , proj-g₁-p , proj-g₂-q)
config-gt-remove-prefix :
∀ { p≢q gSub }
-> (g : Global n)
-> (c : Configuration n)
-> g ↔ c
-> g ≡ msgSingle p q p≢q l gSub
-> ∃[ cSub ] cSub ≡ (c [ p ]≔ project gSub p) [ q ]≔ project gSub q × gSub ↔ cSub
config-gt-remove-prefix {n} {p} {q} {_} {p≢q} {gSub} g c assoc refl
= cSub , refl , (record { isProj = isProj-gSub })
where
lpSub = project gSub p
lqSub = project gSub q
cSub = (c [ p ]≔ lpSub) [ q ]≔ lqSub
isProj-gSub : ∀ (r : Fin n) -> lookup cSub r ≡ project gSub r
isProj-gSub r
with p ≟ r | q ≟ r
... | yes refl | yes refl = ⊥-elim (p≢q refl)
... | yes refl | no _
rewrite lookup∘update′ p≢q (c [ p ]≔ lpSub) lqSub
rewrite lookup∘update p c lpSub
= refl
... | no _ | yes refl
rewrite lookup∘update q (c [ p ]≔ lpSub) lqSub
= refl
... | no p≢r | no q≢r
rewrite lookup∘update′ (¬≡-flip q≢r) (c [ p ]≔ lpSub) lqSub
rewrite lookup∘update′ (¬≡-flip p≢r) c lpSub
rewrite _↔_.isProj assoc r
= proj-prefix-other p q r gSub p≢r q≢r
| 36.274854
| 110
| 0.522328
|
dcd747dceedd66ca4526fc84dc327dc7d89bcc3d
| 1,949
|
agda
|
Agda
|
Mockingbird/Problems/Chapter16.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | 1
|
2022-02-28T23:44:42.000Z
|
2022-02-28T23:44:42.000Z
|
Mockingbird/Problems/Chapter16.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | null | null | null |
Mockingbird/Problems/Chapter16.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | null | null | null |
open import Mockingbird.Forest using (Forest)
-- The Forest Without a Name
module Mockingbird.Problems.Chapter16 {b ℓ} (forest : Forest {b} {ℓ}) where
open import Data.Product using (_×_; _,_; ∃-syntax)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_$_; _⇔_; Equivalence)
open import Relation.Binary using (_Respects_)
open import Relation.Nullary using (¬_)
open import Relation.Unary using (Pred)
open Forest forest
import Mockingbird.Problems.Chapter14 forest as Chapter₁₄
open import Mockingbird.Problems.Chapter15 forest using (⇔-¬)
module _ {s} (Sings : Pred Bird s)
(respects : Sings Respects _≈_)
(LEM : ∀ x → Sings x ⊎ ¬ Sings x)
(e : Bird)
(law₁ : ∀ {x y} → Sings (e ∙ x ∙ y) → Sings y)
(law₂ : ∀ {x y} → Sings (e ∙ x ∙ y) ⇔ (¬ Sings x))
(law₃ : ∀ {x y} → Sings (e ∙ x ∙ y) ⇔ (¬ Sings x × Sings y))
(law₄ : ∀ x → ∃[ y ] Sings y ⇔ Sings (e ∙ y ∙ x)) where
IsSilent : Pred Bird s
IsSilent x = ¬ Sings x
private
respects′ : IsSilent Respects _≈_
respects′ x≈y ¬x-sings y-sings = ¬x-sings $ respects (sym x≈y) y-sings
LEM′ : ∀ x → IsSilent x ⊎ ¬ IsSilent x
LEM′ x with LEM x
... | inj₁ x-sings = inj₂ λ ¬x-sings → ¬x-sings x-sings
... | inj₂ ¬x-sings = inj₁ ¬x-sings
law₁′ : ∀ {x y} → IsSilent y → IsSilent (e ∙ x ∙ y)
law₁′ ¬y-sings exy-sings = ¬y-sings $ law₁ exy-sings
law₂′ : ∀ {x y} → ¬ IsSilent x → IsSilent (e ∙ x ∙ y)
law₂′ = Equivalence.g $ ⇔-¬ law₂
law₃′ : ∀ {x y} → IsSilent x → IsSilent (e ∙ x ∙ y) → IsSilent y
law₃′ {x} {y} ¬x-sings ¬exy-sings y-sings = Equivalence.f (⇔-¬ law₃) ¬exy-sings (¬x-sings , y-sings)
law₄′ : ∀ x → ∃[ y ] IsSilent y ⇔ IsSilent (e ∙ y ∙ x)
law₄′ x =
let (y , y-sings⇔eyx-sings) = law₄ x
in (y , ⇔-¬ y-sings⇔eyx-sings)
problem : ∀ x → ¬ Sings x
problem = Chapter₁₄.problem₁ IsSilent respects′ LEM′ e law₁′ law₂′ law₃′ law₄′
| 36.092593
| 104
| 0.586968
|
4dd46dfb2607ce0e84edddee3af5691eda962c5d
| 917
|
agda
|
Agda
|
Categories/PushOuts.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 21
|
2015-07-30T01:25:12.000Z
|
2021-02-13T18:02:18.000Z
|
Categories/PushOuts.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 3
|
2019-01-13T13:12:33.000Z
|
2019-05-29T09:50:26.000Z
|
Categories/PushOuts.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 1
|
2019-11-04T21:33:13.000Z
|
2019-11-04T21:33:13.000Z
|
module Categories.PushOuts where
open import Library
open import Categories
open Cat
record Square {a}{b}{C : Cat {a}{b}}{X Y Z}(f : Hom C Z X)(g : Hom C Z Y) : Set (a ⊔ b) where
constructor square
field W : Obj C
h : Hom C X W
k : Hom C Y W
scom : comp C h f ≅ comp C k g
record SqMap {a}{b}{C : Cat {a}{b}}{X Y Z : Obj C}{f : Hom C Z X}{g : Hom C Z Y}
(sq sq' : Square {a}{b}{C} f g) : Set (a ⊔ b) where
constructor sqmap
open Square
field sqMor : Hom C (W sq) (W sq')
leftTr : comp C sqMor (h sq) ≅ h sq'
rightTr : comp C sqMor (k sq) ≅ k sq'
open SqMap
record PushOut {a}{b}{C : Cat {a}{b}}{X Y Z}(f : Hom C Z X)(g : Hom C Z Y) : Set (a ⊔ b) where
constructor pushout
field sq : Square {a}{b}{C} f g
uniqPush : (sq' : Square f g) → Σ (SqMap sq sq')
\ u → (u' : SqMap sq sq') → sqMor u ≅ sqMor u'
| 30.566667
| 94
| 0.522356
|
398b9c03e763fb5106959d89355d8d2e9ea0b5ad
| 2,252
|
agda
|
Agda
|
TypeTheory/Lecture/PropsAsTypes.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
TypeTheory/Lecture/PropsAsTypes.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
TypeTheory/Lecture/PropsAsTypes.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
module PropsAsTypes where
data Σ {I : Set} (X : I → Set) : Set where
_,_ : (i : I) → X i → Σ X
drec-Σ : {I : Set} {X : I → Set} {A : Σ X → Set} →
((i : I) → (x : X i) → A (i , x)) →
(u : Σ X) → A u
drec-Σ f (i , x) = f i x
π₁ : {I : Set} {X : I → Set} → Σ X → I
π₁ = drec-Σ (λ i x → i)
π₂ : {I : Set} {X : I → Set} → (u : Σ X) → X (π₁ u)
π₂ = drec-Σ (λ i x → x)
_×_ : Set → Set → Set
A × B = Σ {A} λ _ → B
Prop = Set
Pred : Set → Set₁
Pred A = A → Prop
Rel : Set → Set₁
Rel A = A → A → Prop
_⊆_ : {A : Set} → Pred A → Pred A → Prop
P ⊆ Q = ∀ x → P x → Q x
_⊑_ : {A : Set} → Rel A → Rel A → Prop
R ⊑ S = ∀ {x y} → R x y → S x y
_∧_ : Prop → Prop → Prop
A ∧ B = A × B
∧-elim₁ : {A₁ A₂ : Prop} → A₁ ∧ A₂ → A₁
∧-elim₁ = π₁
∧-elim₂ : {A₁ A₂ : Prop} → A₁ ∧ A₂ → A₂
∧-elim₂ = π₂
∧-intro : {A₁ A₂ : Prop} → A₁ → A₂ → A₁ ∧ A₂
∧-intro a₁ a₂ = (a₁ , a₂)
∃ : {X : Set} → (A : X → Prop) → Prop
∃ = Σ
∃-syntax : ∀ X → (X → Prop) → Prop
∃-syntax X A = ∃ A
syntax ∃-syntax X (λ x → A) = ∃[ x ∈ X ] A
∃-intro : {X : Set} {A : X → Prop} → (x : X) → A x → ∃[ x ∈ X ] (A x)
∃-intro x a = (x , a)
∃-elim : {X : Set} {A : X → Prop} {B : Prop} →
((x : X) → A x → B) → ∃[ x ∈ X ] (A x) → B
∃-elim = drec-Σ
∃₂-elim : {X Y : Set} {A : X → Prop} {B : Y → Prop} {C : Prop} →
((x : X) (y : Y) → A x → B y → C) →
∃[ x ∈ X ] (A x) → ∃[ x ∈ Y ] (B x) → C
∃₂-elim f p q = ∃-elim (λ x p' → ∃-elim (λ y q' → f x y p' q') q) p
infix 3 _⇔_
_⇔_ : Prop → Prop → Prop
A ⇔ B = (A → B) ∧ (B → A)
equivalence : {A B : Prop} → (A → B) → (B → A) → A ⇔ B
equivalence = ∧-intro
data ⊥ : Prop where
absurd : ⊥ → ⊥
⊥-elim : {A : Prop} → ⊥ → A
⊥-elim (absurd p) = ⊥-elim p
¬ : Prop → Prop
¬ A = A → ⊥
data ⊤ : Prop where
∗ : ⊤
open import Data.Nat
open import Relation.Binary.PropositionalEquality as PE
IsSuc : ℕ → Set
IsSuc zero = ⊥
IsSuc (suc _) = ⊤
zero-not-suc : ∀ n → ¬ (suc n ≡ 0)
zero-not-suc n p = subst IsSuc p ∗
-- Easier in Agda with absurd elimination
-- suc-injective : ∀ n → ¬ (suc n ≡ n)
-- suc-injective n ()
drec-≡ : {X : Set} → {C : (x y : X) → x ≡ y → Set} →
((x : X) → C x x refl) →
∀ x y → (p : x ≡ y) → C x y p
drec-≡ f x .x refl = f x
| 21.245283
| 69
| 0.43206
|
124fb8ea7cd27be76f47a7d8a59c4866f6e367de
| 225
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Word.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
src/data/lib/prim/Agda/Builtin/Word.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/Word.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS --without-K #-}
module Agda.Builtin.Word where
open import Agda.Builtin.Nat
postulate Word64 : Set
{-# BUILTIN WORD64 Word64 #-}
primitive
primWord64ToNat : Word64 → Nat
primWord64FromNat : Nat → Word64
| 17.307692
| 34
| 0.715556
|
dc2dfda41688283f879e81906de30283e7540933
| 5,111
|
agda
|
Agda
|
src/StateMachineModel.agda
|
lisandrasilva/agda-liveness
|
391e148f391dc2d246249193788a0d203285b38e
|
[
"Apache-2.0"
] | null | null | null |
src/StateMachineModel.agda
|
lisandrasilva/agda-liveness
|
391e148f391dc2d246249193788a0d203285b38e
|
[
"Apache-2.0"
] | null | null | null |
src/StateMachineModel.agda
|
lisandrasilva/agda-liveness
|
391e148f391dc2d246249193788a0d203285b38e
|
[
"Apache-2.0"
] | null | null | null |
{-
Copyright 2019 Lisandra Silva
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}
open import Prelude
module StateMachineModel where
-----------------------------------------------------------------------------
-- State Machine
-----------------------------------------------------------------------------
record StateMachine (State : Set) (Event : Set) : Set₁ where
field
initial : Pred State 0ℓ
enabled : Event → State → Set
action : ∀ {preState} {event} → enabled event preState → State
open StateMachine
data Reachable {State Event} {sm : StateMachine State Event} : State → Set where
init : ∀ {s₀} → initial sm s₀
→ Reachable s₀
step : ∀ {st event} → Reachable {sm = sm} st → (enEv : enabled sm event st)
→ Reachable (action sm enEv)
Invariant : ∀ {State Event} (sm : StateMachine State Event) (P : Pred State 0ℓ) → Set
Invariant sm P = ∀ {state} (rs : Reachable {sm = sm} state) → P state
Stable : ∀ {State Event} (sm : StateMachine State Event) (P : Pred State 0ℓ) → Set
Stable sm P = ∀ {st ev} (enEv : enabled sm ev st)
→ P st
→ P (action sm enEv)
EventSet : ∀ {Event : Set} → Set₁
EventSet {Event} = Pred Event 0ℓ
record System State Event : Set₁ where
field
stateMachine : StateMachine State Event
weakFairness : Pred (EventSet {Event}) 0ℓ
open System
enabledSet : ∀ {State Event} → StateMachine State Event
→ EventSet {Event} → State → Set
enabledSet sm evSet state = ∃[ event ] (event ∈ evSet × enabled sm event state)
module LeadsTo
(State : Set) (Event : Set) (sys : System State Event)
where
-----------------------------------------------------------------------------
-- HOARE Triple
-----------------------------------------------------------------------------
data [_]_[_] (P : Pred State 0ℓ) (event : Event) (Q : Pred State 0ℓ) : Set where
hoare : (∀ {st} → P st
→ (enEv : enabled (stateMachine sys) event st)
→ Q (action (stateMachine sys) enEv ))
→ [ P ] event [ Q ]
Z : Set
Z = ℕ
-- Auxiliary properties with syntax renaming for better compliance with paper
-- TODO : Try to make this more generic
⋃₁ : ∀ {ℓ ℓ'} {A : Set ℓ'} → (A → Pred State ℓ) → Pred State (ℓ ⊔ ℓ')
⋃₁ {A = A} P = λ x → Σ[ i ∈ A ] P i x
syntax ⋃₁ (λ i → P) = [∃ i ∶ P ]
⋃₂ : ∀ {ℓ₁ ℓ₂ ℓ'} {A : Set ℓ'} → (C : Pred A ℓ₁) → (F : A → Pred State ℓ₂) → Pred State _
⋃₂ {A = A} C F = λ s → Σ[ i ∈ A ] ( C i × F i s )
syntax ⋃₂ C (λ x → P) = [∃ x ⇒ C ∶ P ]
-----------------------------------------------------------------------------
-- PROOF RULES for liveness
-----------------------------------------------------------------------------
infix 1 _l-t_
data _l-t_ (P : Pred State 0ℓ) (Q : Pred State 0ℓ) : Set₁ where
viaEvSet : (evSet : EventSet) → (weakFairness sys evSet)
→ (∀ (e : Event) → e ∈ evSet → [ P ] e [ Q ])
→ (∀ (e : Event) → ¬ (e ∈ evSet) → [ P ] e [ P ∪ Q ])
→ Invariant (stateMachine sys)
(P ⇒ enabledSet (stateMachine sys) evSet)
→ P l-t Q
viaInv : Invariant (stateMachine sys) (P ⇒ Q)
→ P l-t Q
viaTrans : ∀ {R} → P l-t R → R l-t Q
→ P l-t Q
viaTrans2 : ∀ {R} → P l-t (Q ∪ R) → R l-t Q
→ P l-t Q
viaDisj : ∀ {P₁ P₂} → P ⊆ (P₁ ∪ P₂) → P₁ l-t Q → P₂ l-t Q
→ P l-t Q
viaUseInv : ∀ {R} → Invariant (stateMachine sys) R → (P ∩ R) l-t (R ⇒ Q)
→ P l-t Q
viaWFR : ∀ (F : Z → Pred State 0ℓ)
→ P l-t (Q ∪ [∃ x ∶ F x ])
→ (∀ (w : Z) → F w l-t (Q ∪ [∃ x ⇒ _< w ∶ F x ]))
→ P l-t Q
viaAllVal : ∀ {A : Set} → {R : A → Pred State 0ℓ}
→ Invariant (stateMachine sys) [∃ x ∶ R x ]
→ (∀ (a : A) → (P ∩ R a) l-t Q )
→ P l-t Q
viaStable : ∀ {P' Q' S} → Stable (stateMachine sys) S
→ P l-t P' ∩ S → P' l-t Q' → Q' ∩ S l-t Q
→ P l-t Q
P⊆QQ→Inv[P⇒Q] : ∀ {P Q} {sm : StateMachine State Event}
→ P ⊆ Q
→ Invariant sm (P ⇒ Q)
P⊆QQ→Inv[P⇒Q] p⊆q rs pS
with p⊆q pS
... | qS = qS
invR⇒P-l-t-P∧R : ∀ {P R} {sm : StateMachine State Event}
→ Invariant (stateMachine sys) R
→ P l-t P ∩ R
invR⇒P-l-t-P∧R invR = viaInv (λ rs ps → ps , (invR rs))
| 32.974194
| 92
| 0.465271
|
20fff9337a60567cf4b67a8ee1e2e04698842c2f
| 3,015
|
agda
|
Agda
|
Math/FormalLanguage.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | 3
|
2020-04-07T17:49:42.000Z
|
2020-04-21T00:03:43.000Z
|
Math/FormalLanguage.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
Math/FormalLanguage.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Math.FormalLanguage where
-- agda-stdlib
import Algebra.FunctionProperties as FP
import Algebra.Structures as Structures
open import Level renaming (zero to lzero; suc to lsuc)
open import Data.List as L using (List; []; _++_)
import Data.List.Properties as Lₚ
open import Data.Nat hiding (_⊔_; _^_)
open import Data.Empty
open import Data.Product using (proj₁; proj₂; _,_; _×_; ∃₂; ∃)
open import Function using (_$_)
import Function as F
open import Relation.Binary.PropositionalEquality
open import Relation.Binary
open import Relation.Unary hiding (∅; {_})
import Relation.Unary as U
import Relation.Unary.Properties as Uₚ
-- Equivalence of predicate
infix 4 _≡ᴾ_
_≡ᴾ_ : ∀ {a l} {A : Set a} → Rel (Pred A l) (a ⊔ l)
_≡ᴾ_ P Q = (P ⊆ Q) × (Q ⊆ P)
≡ᴾ-refl : ∀ {a l} {A : Set a} → Reflexive {A = Pred A l} _≡ᴾ_
≡ᴾ-refl = F.id , F.id
≡ᴾ-sym : ∀ {a l} {A : Set a} → Symmetric {A = Pred A l} _≡ᴾ_
≡ᴾ-sym = Data.Product.swap
≡ᴾ-trans : ∀ {a l} {A : Set a} → Transitive {A = Pred A l} _≡ᴾ_
≡ᴾ-trans P≡Q Q≡R = proj₁ Q≡R F.∘ proj₁ P≡Q , proj₂ P≡Q F.∘ proj₂ Q≡R
≡ᴾ-isEquivalence : ∀ {a l} {A : Set a} → IsEquivalence {A = Pred A l} _≡ᴾ_
≡ᴾ-isEquivalence = record
{ refl = ≡ᴾ-refl
; sym = ≡ᴾ-sym
; trans = ≡ᴾ-trans
}
≡ᴾ-setoid : ∀ {a l} {A : Set a} → Setoid _ _
≡ᴾ-setoid {a} {l} {A} = record
{ Carrier = Pred A l
; _≈_ = _≡ᴾ_
; isEquivalence = ≡ᴾ-isEquivalence
}
∅ : ∀ {a l} {A : Set a} → Pred A l
∅ {l = l} = λ _ → Lift l ⊥
{_} : ∀ {a l} {A : Set a} → A → Pred A (a ⊔ l)
{_}{l = l} x = λ y → Lift l (y ≡ x)
Lang : ∀ {s} → Set s → (l : Level) → Set _
Lang Σ l = Pred (List Σ) l
-- TODO Move Math.FormalLanguage.Construct.EmptyLang
data EmptyLang {a l} {A : Set a} : Lang A (a ⊔ l) where
mkEmptyLang : EmptyLang []
-- TODO Move Math.FormalLanguage.Construct.Concat
-- TODO Hetero
-- Lang A l → Lang B l → Lang (A ⊎ B) l
-- map inj₁ xs ++ map inj₂ ys
-- concatenation of formal language
data _<>_ {a l} {A : Set a} (L₁ L₂ : Lang A l) : Lang A (a ⊔ l) where
mk<> : ∀ {xs ys} → L₁ xs → L₂ ys → (L₁ <> L₂) (xs ++ ys)
-- TODO Move Math.FormalLanguage.Construct.Concat.Properties
module _ {s l} {Σ : Set s} where
open FP {A = Lang Σ (s ⊔ l)} _≡ᴾ_
<>-identityˡ : LeftIdentity (EmptyLang {l = l}) _<>_
<>-identityˡ L = to , from
where
to : EmptyLang <> L ⊆ L
to (mk<> mkEmptyLang x₁) = x₁
from : L ⊆ EmptyLang <> L
from Lx = mk<> mkEmptyLang Lx
<>-identityʳ : RightIdentity (EmptyLang {l = l}) _<>_
<>-identityʳ L = to , from
where
to : L <> EmptyLang ⊆ L
to (mk<> Lx mkEmptyLang) = subst L (sym $ Lₚ.++-identityʳ _) Lx
from : L ⊆ L <> EmptyLang
from {xs} x = subst (L <> EmptyLang) (Lₚ.++-identityʳ xs) $
mk<> {xs = xs} {ys = []} x mkEmptyLang
{- TODO move contents of agda-combinatorics to agda-misc
<>-dec : ∀ {L₁ L₂ : Lang Σ l} →
U.Decidable L₁ → U.Decidable L₂ → U.Decidable (L₁ <> L₂)
<>-dec L₁? L₂? zs with L.filter (L₁? Uₚ.×? L₂?) (splits₂ zs)
... | x = ?
-}
| 30.765306
| 74
| 0.593698
|
5055a15468dd45391b0f08839d1124ab74ccab8a
| 437
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/IntAsRawRing.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/RingSolver/IntAsRawRing.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/RingSolver/IntAsRawRing.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.IntAsRawRing where
open import Cubical.Data.Nat hiding (_+_; _·_)
open import Cubical.Data.Int
open import Cubical.Data.Int.Base
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.RingSolver.RawRing
ℤAsRawRing : RawRing ℓ-zero
ℤAsRawRing = rawring ℤ (pos zero) (pos (suc zero)) _+_ _·_ (λ k → - k)
+Ridℤ : (k : ℤ) → (pos zero) + k ≡ k
+Ridℤ k = sym (pos0+ k)
| 27.3125
| 70
| 0.713959
|
1c4a99d9cd2a83a1078b1d99b0d81cd4d195b6ef
| 5,628
|
agda
|
Agda
|
core/lib/types/Cover.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Cover.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Cover.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics renaming (pt to pt⊙)
open import lib.NConnected
open import lib.types.TLevel
open import lib.NType2
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.LoopSpace
open import lib.types.Truncation
open import lib.types.PathSet
module lib.types.Cover {i} where
{-
The definition of covering spaces.
-}
record Cover (A : Type i) j : Type (lmax i (lsucc j)) where
constructor cover
field
Fiber : A → Type j
Fiber-level : ∀ a → is-set (Fiber a)
Fiber-is-set = Fiber-level
TotalSpace = Σ A Fiber
⊙Cover : ∀ (X : Ptd i) j → Type (lmax i (lsucc j))
⊙Cover X j = Σ (Cover (de⊙ X) j) λ C → Cover.Fiber C (pt⊙ X)
module ⊙Cover {X : Ptd i} {j} (⊙cov : ⊙Cover X j) where
cov = fst ⊙cov
pt = snd ⊙cov
open Cover cov public
-- Basics
module _ {A : Type i} {j} where
open Cover
-- Equality between covers.
private
cover=′ : {c₁ c₂ : Cover A j} → Fiber c₁ == Fiber c₂ → c₁ == c₂
cover=′ {cover f _} {cover .f _} idp = ap (cover f) $
prop-has-all-paths (Π-is-prop λ _ → is-set-is-prop) _ _
cover= : {c₁ c₂ : Cover A j} → (∀ a → Fiber c₁ a ≃ Fiber c₂ a)
→ c₁ == c₂
cover= F≃ = cover=′ (λ= λ a → ua $ F≃ a)
-- The definition of universality in terms of connectedness.
is-universal : Cover A j → Type (lmax i j)
is-universal cov = is-connected 1 $ TotalSpace cov
module _ (A : Type i) j where
-- In terms of connectedness
UniversalCover : Type (lmax i (lsucc j))
UniversalCover = Σ (Cover A j) is-universal
module _ (X : Ptd i) j where
-- In terms of connectedness
⊙UniversalCover : Type (lmax i (lsucc j))
⊙UniversalCover = Σ (⊙Cover X j) (λ ⊙cov → is-universal (fst ⊙cov))
module ⊙UniversalCover {X : Ptd i} {j} (⊙uc : ⊙UniversalCover X j) where
⊙cov = fst ⊙uc
is-univ = snd ⊙uc
open ⊙Cover ⊙cov public
-- Theorem: A covering space keeps higher homotopy groups.
module _ (X : Ptd i)
{j} (c : Cover (de⊙ X) j)
(a↑ : Cover.Fiber c (pt⊙ X)) where
open Cover c
private
F = Cover.Fiber c
F-level = Cover.Fiber-level c
A = de⊙ X
a = pt⊙ X
private
-- The projection map with one end free (in order to apply J).
to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}
→ idp == p⇑ → idp == fst= p⇑
to′ idp=p⇑ = ap fst= idp=p⇑
-- The projection map from Ω²(Σ A F) to Ω²(A).
to : Ω^ 2 ⊙[ Σ A F , (a , a↑) ] → Ω^ 2 X
to p²⇑ = to′ {p⇑ = idp} p²⇑
-- Auxiliary synthesized path for injection.
idp=p↑ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ idp == p↑
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]
idp=p↑ idp = prop-has-all-paths (F-level a _ _) _ _
-- The injection map with some ends free (in order to apply J).
from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ idp == p↑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]
→ idp == pair= p p↑
from′ idp=p idp=p↑ = pair== idp=p idp=p↑
-- The injection map from Ω²(A) to Ω²(Σ A F).
from : Ω^ 2 X → Ω^ 2 ⊙[ Σ A F , (a , a↑) ]
from p² = from′ {p = idp} {p↑ = idp} p² (idp=p↑ p²)
-- Injection is left-inverse to projection (with some ends free).
from′-to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}
→ (idp=p⇑ : idp == p⇑)
→ (idp=snd=p⇑ : idp == snd= p⇑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ to′ idp=p⇑ ])
→ from′ (to′ idp=p⇑) idp=snd=p⇑ == idp=p⇑
[ (λ p⇑ → idp == p⇑) ↓ ! (pair=-η p⇑) ]
from′-to′ idp idp=snd=p⇑ = ap (from′ idp)
$ contr-has-all-paths (F-level a _ _ _ _) _ _
-- Injection is left-inverse to projection.
from-to : ∀ p²⇑ → from (to p²⇑) == p²⇑
from-to p²⇑ = from′-to′ {p⇑ = idp} p²⇑ (idp=p↑ (to′ p²⇑))
-- Injection is right-inverse to projection (with some ends free).
to′-from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ (idp=p↑ : idp == p↑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ])
→ to′ (from′ idp=p idp=p↑) == idp=p
[ (λ p → idp == p) ↓ fst=-β p p↑ ]
to′-from′ idp idp = idp
-- Injection is right-inverse to projection.
to-from : ∀ p² → to (from p²) == p²
to-from p² = to′-from′ p² (idp=p↑ p²)
-- The theorem.
Ω²ΣAFiber≃Ω²A : Ω^ 2 ⊙[ Σ A F , (a , a↑) ] ≃ Ω^ 2 X
Ω²ΣAFiber≃Ω²A = to , is-eq to from to-from from-to
-- A natural way to construct a π1-set from covering spaces.
module _ {A : Type i} where
open Cover
cover-trace : ∀ {j} (cov : Cover A j) {a₁ a₂}
→ Fiber cov a₁ → a₁ =₀ a₂
→ Fiber cov a₂
cover-trace cov a↑ p =
transport₀ (Fiber cov) (Fiber-is-set cov _) p a↑
abstract
cover-trace-idp₀ : ∀ {j} (cov : Cover A j) {a₁}
→ (a↑ : Fiber cov a₁)
→ cover-trace cov a↑ idp₀ == a↑
cover-trace-idp₀ cov a↑ = idp
cover-paste : ∀ {j} (cov : Cover A j) {a₁ a₂}
→ (a↑ : Fiber cov a₁)
→ (loop : a₁ =₀ a₁)
→ (p : a₁ =₀ a₂)
→ cover-trace cov (cover-trace cov a↑ loop) p
== cover-trace cov a↑ (loop ∙₀ p)
cover-paste cov a↑ loop p = ! $ transp₀-∙₀ (Fiber-is-set cov) loop p a↑
-- Path sets form a covering space
module _ (X : Ptd i) where
path-set-cover : Cover (de⊙ X) i
path-set-cover = record
{ Fiber = λ a → pt⊙ X =₀ a
; Fiber-level = λ a → Trunc-level
}
-- Cover morphisms
CoverHom : ∀ {A : Type i} {j₁ j₂}
→ (cov1 : Cover A j₁)
→ (cov2 : Cover A j₂)
→ Type (lmax i (lmax j₁ j₂))
CoverHom (cover F₁ _) (cover F₂ _) = ∀ a → F₁ a → F₂ a
| 31.617978
| 75
| 0.524343
|
cb2e4429784b05161950b345853ab7b0c945fc18
| 3,443
|
agda
|
Agda
|
lib/types/Coproduct.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Coproduct.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
lib/types/Coproduct.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Empty
open import lib.types.Lift
open import lib.types.Pointed
module lib.types.Coproduct where
module _ {i j} {A : Type i} {B : Type j} where
⊔-code : Coprod A B → Coprod A B → Type (lmax i j)
⊔-code (inl a₁) (inl a₂) = Lift {j = (lmax i j)} $ a₁ == a₂
⊔-code (inl a₁) (inr b₂) = Lift Empty
⊔-code (inr b₁) (inl a₂) = Lift Empty
⊔-code (inr b₁) (inr b₂) = Lift {j = (lmax i j)} $ b₁ == b₂
⊔-encode : {x y : Coprod A B} → (x == y) → ⊔-code x y
⊔-encode {inl a₁} {y} p = transport (⊔-code $ inl a₁) p (lift $ idp {a = a₁})
⊔-encode {inr b₁} {y} p = transport (⊔-code $ inr b₁) p (lift $ idp {a = b₁})
⊔-decode : {x y : Coprod A B} → ⊔-code x y → (x == y)
⊔-decode {inl _} {inl _} c = ap inl $ lower c
⊔-decode {inl _} {inr _} c = Empty-rec $ lower c
⊔-decode {inr _} {inl _} c = Empty-rec $ lower c
⊔-decode {inr _} {inr _} c = ap inr (lower c)
⊔-code-equiv : (x y : Coprod A B) → (x == y) ≃ ⊔-code x y
⊔-code-equiv x y = equiv ⊔-encode ⊔-decode (f-g x y) (g-f x y)
where f-g : ∀ x' y' → ∀ c → ⊔-encode (⊔-decode {x'} {y'} c) == c
f-g (inl a₁) (inl .a₁) (lift idp) = idp
f-g (inl a₁) (inr b₂) b = Empty-rec $ lower b
f-g (inr b₁) (inl a₂) b = Empty-rec $ lower b
f-g (inr b₁) (inr .b₁) (lift idp) = idp
g-f : ∀ x' y' → ∀ p → ⊔-decode (⊔-encode {x'} {y'} p) == p
g-f (inl _) .(inl _) idp = idp
g-f (inr _) .(inr _) idp = idp
inl=inl-equiv : (a₁ a₂ : A) → (inl a₁ == inl a₂) ≃ (a₁ == a₂)
inl=inl-equiv a₁ a₂ = lift-equiv ∘e ⊔-code-equiv (inl a₁) (inl a₂)
inr=inr-equiv : (b₁ b₂ : B) → (inr b₁ == inr b₂) ≃ (b₁ == b₂)
inr=inr-equiv b₁ b₂ = lift-equiv ∘e ⊔-code-equiv (inr b₁) (inr b₂)
inl≠inr : (a₁ : A) (b₂ : B) → (inl a₁ ≠ inr b₂)
inl≠inr a₁ b₂ p = lower $ ⊔-encode p
inr≠inl : (b₁ : B) (a₂ : A) → (inr b₁ ≠ inl a₂)
inr≠inl a₁ b₂ p = lower $ ⊔-encode p
⊔-level : ∀ {n} → has-level (S (S n)) A → has-level (S (S n)) B
→ has-level (S (S n)) (Coprod A B)
⊔-level pA _ (inl a₁) (inl a₂) =
equiv-preserves-level ((inl=inl-equiv a₁ a₂)⁻¹) (pA a₁ a₂)
⊔-level _ _ (inl a₁) (inr b₂) = λ p → Empty-rec (inl≠inr a₁ b₂ p)
⊔-level _ _ (inr b₁) (inl a₂) = λ p → Empty-rec (inr≠inl b₁ a₂ p)
⊔-level _ pB (inr b₁) (inr b₂) =
equiv-preserves-level ((inr=inr-equiv b₁ b₂)⁻¹) (pB b₁ b₂)
infix 80 _⊙⊔_
_⊙⊔_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊙⊔ Y = ⊙[ Coprod (fst X) (fst Y) , inl (snd X) ]
_⊔⊙_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊔⊙ Y = ⊙[ Coprod (fst X) (fst Y) , inr (snd Y) ]
codiag : ∀ {i} {A : Type i} → A ⊔ A → A
codiag (inl a) = a
codiag (inr a) = a
⊙codiag : ∀ {i} {X : Ptd i} → fst (X ⊙⊔ X ⊙→ X)
⊙codiag = (codiag , idp)
-- A binary sigma is a coproduct
ΣBool-equiv-⊔ : ∀ {i} (Pick : Lift {j = i} Bool → Type i)
→ Σ _ Pick ≃ (Pick (lift true) ⊔ Pick (lift false))
ΣBool-equiv-⊔ Pick = equiv into out into-out out-into
where
into : Σ _ Pick → (Pick (lift true) ⊔ Pick (lift false))
into (lift true , a) = inl a
into (lift false , b) = inr b
out : (Pick (lift true) ⊔ Pick (lift false)) → Σ _ Pick
out (inl a) = (lift true , a)
out (inr b) = (lift false , b)
into-out : ∀ c → into (out c) == c
into-out (inl a) = idp
into-out (inr b) = idp
out-into : ∀ s → out (into s) == s
out-into (lift true , a) = idp
out-into (lift false , b) = idp
| 35.864583
| 79
| 0.526576
|
1c4679b695db6afe60a9819a13f9e58c013b65b3
| 6,188
|
agda
|
Agda
|
theorems/cw/cohomology/cochainequiv/HigherCoboundary.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/cw/cohomology/cochainequiv/HigherCoboundary.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/cw/cohomology/cochainequiv/HigherCoboundary.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.Bouquet
open import homotopy.FinWedge
open import homotopy.SphereEndomorphism
open import groups.SphereEndomorphism
open import cw.CW
open import cw.FinCW
open import cw.WedgeOfCells
open import cw.FinBoundary
open import cohomology.Theory
module cw.cohomology.cochainequiv.HigherCoboundary (OT : OrdinaryTheory lzero)
{n} (⊙fin-skel : ⊙FinSkeleton (S (S n))) where
open OrdinaryTheory OT
open import cohomology.SubFinBouquet OT
open import cohomology.RephraseSubFinCoboundary OT
private
fin-skel = ⊙FinSkeleton.skel ⊙fin-skel
I = AttachedFinSkeleton.numCells fin-skel
ac = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero
dec = ⊙FinSkeleton-has-cells-with-dec-eq ⊙fin-skel
⊙fin-skel₋₁ = ⊙fcw-init ⊙fin-skel
fin-skel₋₁ = ⊙FinSkeleton.skel ⊙fin-skel₋₁
I₋₁ = AttachedFinSkeleton.numCells fin-skel₋₁
ac₋₁ = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel₋₁ lzero
dec₋₁ = ⊙FinSkeleton-has-cells-with-dec-eq ⊙fin-skel₋₁
open import cw.cohomology.WedgeOfCells OT
open import cw.cohomology.reconstructed.HigherCoboundary OT ⊙⦉ ⊙fin-skel ⦊
open import cw.cohomology.cochainequiv.HigherCoboundaryAbstractDefs OT ⊙fin-skel
abstract
rephrase-cw-co∂-last-in-degree : ∀ g
→ GroupIso.f (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac) (GroupHom.f cw-co∂-last (GroupIso.g (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel₋₁ ⦊ ac₋₁) g))
∼ λ <I → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁))
rephrase-cw-co∂-last-in-degree g <I =
GroupIso.f (C-FinBouquet-diag (S (S n)) I)
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊))
(GroupHom.f cw-co∂-last
(CEl-fmap (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g)))) <I
=⟨ ap
(λ g →
GroupIso.f (C-FinBouquet-diag (S (S n)) I)
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) g) <I) $
cw-co∂-last-β
(CEl-fmap (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g)) ⟩
GroupIso.f (C-FinBouquet-diag (S (S n)) I)
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊))
(CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙cw-∂-before-Susp
(<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))
(CEl-fmap (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g))))) <I
=⟨ ap
(λ g →
GroupIso.f (C-FinBouquet-diag (S (S n)) I)
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊))
(CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙cw-∂-before-Susp g)) <I) $
C-Susp-fmap' (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)) □$ᴳ
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g) ⟩
GroupIso.f (C-FinBouquet-diag (S (S n)) I)
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊))
(CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙cw-∂-before-Susp
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)))
(<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n)))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g))))) <I
=⟨ ap (λ g → GroupIso.f (C-FinBouquet-diag (S (S n)) I) g <I) $
∘-CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) ⊙cw-∂-before-Susp
(CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)))
(<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n)))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g)))
∙ ∘-CEl-fmap (ℕ-to-ℤ (S (S n)))
(⊙cw-∂-before-Susp ⊙∘ ⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊))
(⊙Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)))
(<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n)))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g))
∙ ap (λ f → CEl-fmap (ℕ-to-ℤ (S (S n))) f
(<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n)))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g)))
(! ⊙function₀'-β) ⟩
GroupIso.f (C-FinBouquet-diag (S (S n)) I)
(CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙function₀'
(<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n)))
(GroupIso.g (C-FinBouquet-diag (S n) I₋₁)
g))) <I
=⟨ rephrase-in-degree' (S n) {I = I} {J = I₋₁} ⊙function₀' g <I ⟩
Group.sum (C2 0)
(λ <I₋₁ → Group.exp (C2 0) (g <I₋₁)
(⊙SphereS-endo-degree (S n)
(⊙Susp-fmap (fwproj <I₋₁) ⊙∘ ⊙function₀' ⊙∘ ⊙fwin <I)))
=⟨ ap (Group.sum (C2 0))
(λ= λ <I₋₁ → ap (Group.exp (C2 0) (g <I₋₁)) $
⊙SphereS-endo-degree-base-indep (S n)
{f = ( ⊙Susp-fmap (fwproj <I₋₁)
⊙∘ ⊙function₀'
⊙∘ ⊙fwin <I)}
{g = (Susp-fmap (function₁' <I <I₋₁) , idp)}
(mega-reduction <I <I₋₁)) ⟩
Group.sum (C2 0)
(λ <I₋₁ → Group.exp (C2 0) (g <I₋₁)
(⊙SphereS-endo-degree (S n)
(Susp-fmap (function₁' <I <I₋₁) , idp)))
=⟨ ap (Group.sum (C2 0))
(λ= λ <I₋₁ → ap (Group.exp (C2 0) (g <I₋₁)) $
⊙SphereS-endo-degree-Susp' n (function₁' <I <I₋₁)) ⟩
Group.sum (C2 0)
(λ <I₋₁ → Group.exp (C2 0) (g <I₋₁)
(Trunc-⊙SphereS-endo-degree n
(Trunc-⊙SphereS-endo-in n
[ function₁' <I <I₋₁ ])))
=⟨ ap (Group.sum (C2 0))
(λ= λ <I₋₁ → ap
(λ f → Group.exp (C2 0) (g <I₋₁)
(Trunc-⊙SphereS-endo-degree n
(Trunc-⊙SphereS-endo-in n
[ f ])))
(function₁'-β <I <I₋₁)) ⟩
Group.sum (C2 0)
(λ <I₋₁ → Group.exp (C2 0) (g <I₋₁)
(Trunc-⊙SphereS-endo-degree n
(Trunc-⊙SphereS-endo-in n
[ function₁ <I <I₋₁ ])))
=∎
| 44.84058
| 132
| 0.507434
|
c539636a2e51b880277560449e09822f6dcffdf0
| 919
|
agda
|
Agda
|
src/Categories/Category/Construction/Cowedges.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Construction/Cowedges.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Construction/Cowedges.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 using (Category)
open import Categories.Functor.Bifunctor using (Bifunctor)
module Categories.Category.Construction.Cowedges {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Bifunctor (Category.op C) C D) where
open import Level
open import Categories.Category.Core using (Category)
open import Categories.Diagram.Cowedge F
Cowedges : Category (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) e′
Cowedges = record
{ Obj = Cowedge
; _⇒_ = Cowedge-Morphism
; _≈_ = λ M N → u M ≈ u N
; id = Cowedge-id
; _∘_ = Cowedge-Morphism-∘
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record { refl = Equiv.refl ; sym = Equiv.sym ; trans = Equiv.trans }
; ∘-resp-≈ = ∘-resp-≈
}
where
open Cowedge-Morphism
open Category D
| 28.71875
| 110
| 0.645267
|
123aba03793af34365f2ff689c791296871a7ce8
| 18,623
|
agda
|
Agda
|
Multidimensional/NNat.agda
|
wrrnhttn/agda-cubical-multidimensional
|
55709dd950e319c4a105ace33ddaf8b955354add
|
[
"MIT"
] | null | null | null |
Multidimensional/NNat.agda
|
wrrnhttn/agda-cubical-multidimensional
|
55709dd950e319c4a105ace33ddaf8b955354add
|
[
"MIT"
] | 4
|
2019-06-19T20:40:07.000Z
|
2019-07-02T16:24:01.000Z
|
Multidimensional/NNat.agda
|
wrrnhttn/agda-cubical-multidimensional
|
55709dd950e319c4a105ace33ddaf8b955354add
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical #-}
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Empty
open import Cubical.Data.Unit
open import Cubical.Data.Prod
open import Cubical.Data.BinNat
open import Cubical.Data.Bool
open import Cubical.Relation.Nullary
open import Direction
module NNat where
-- much of this is based directly on the
-- BinNat module in the Cubical Agda library
data BNat : Type₀ where
b0 : BNat
b1 : BNat
x0 : BNat → BNat
x1 : BNat → BNat
sucBNat : BNat → BNat
sucBNat b0 = b1
sucBNat b1 = x0 b1
sucBNat (x0 bs) = x1 bs
sucBNat (x1 bs) = x0 (sucBNat bs)
BNat→ℕ : BNat → ℕ
BNat→ℕ b0 = 0
BNat→ℕ b1 = 1
BNat→ℕ (x0 x) = doubleℕ (BNat→ℕ x)
BNat→ℕ (x1 x) = suc (doubleℕ (BNat→ℕ x))
-- BNat→Binℕ : BNat → Binℕ
-- BNat→Binℕ pos0 = binℕ0
-- BNat→Binℕ pos1 = binℕpos pos1
-- BNat→Binℕ (x0 x) = {!binℕpos (x0 binℕpos (BNat→Binℕ x))!}
-- BNat→Binℕ (x1 x) = {!!}
BNat→ℕsucBNat : (b : BNat) → BNat→ℕ (sucBNat b) ≡ suc (BNat→ℕ b)
BNat→ℕsucBNat b0 = refl
BNat→ℕsucBNat b1 = refl
BNat→ℕsucBNat (x0 b) = refl
BNat→ℕsucBNat (x1 b) = λ i → doubleℕ (BNat→ℕsucBNat b i)
ℕ→BNat : ℕ → BNat
ℕ→BNat zero = b0
ℕ→BNat (suc zero) = b1
ℕ→BNat (suc (suc n)) = sucBNat (ℕ→BNat (suc n))
ℕ→BNatSuc : ∀ n → ℕ→BNat (suc n) ≡ sucBNat (ℕ→BNat n)
ℕ→BNatSuc zero = refl
ℕ→BNatSuc (suc n) = refl
bNatInd : {P : BNat → Type₀} → P b0 → ((b : BNat) → P b → P (sucBNat b)) → (b : BNat) → P b
-- prove later...
BNat→ℕ→BNat : (b : BNat) → ℕ→BNat (BNat→ℕ b) ≡ b
BNat→ℕ→BNat b = bNatInd refl hs b
where
hs : (b : BNat) → ℕ→BNat (BNat→ℕ b) ≡ b → ℕ→BNat (BNat→ℕ (sucBNat b)) ≡ sucBNat b
hs b hb =
ℕ→BNat (BNat→ℕ (sucBNat b))
≡⟨ cong ℕ→BNat (BNat→ℕsucBNat b) ⟩
ℕ→BNat (suc (BNat→ℕ b))
≡⟨ ℕ→BNatSuc (BNat→ℕ b) ⟩
sucBNat (ℕ→BNat (BNat→ℕ b))
≡⟨ cong sucBNat hb ⟩
sucBNat b
∎
ℕ→BNat→ℕ : (n : ℕ) → BNat→ℕ (ℕ→BNat n) ≡ n
ℕ→BNat→ℕ zero = refl
ℕ→BNat→ℕ (suc n) =
BNat→ℕ (ℕ→BNat (suc n))
≡⟨ cong BNat→ℕ (ℕ→BNatSuc n) ⟩
BNat→ℕ (sucBNat (ℕ→BNat n))
≡⟨ BNat→ℕsucBNat (ℕ→BNat n) ⟩
suc (BNat→ℕ (ℕ→BNat n))
≡⟨ cong suc (ℕ→BNat→ℕ n) ⟩
suc n
∎
BNat≃ℕ : BNat ≃ ℕ
BNat≃ℕ = isoToEquiv (iso BNat→ℕ ℕ→BNat ℕ→BNat→ℕ BNat→ℕ→BNat)
BNat≡ℕ : BNat ≡ ℕ
BNat≡ℕ = ua BNat≃ℕ
open NatImpl
NatImplBNat : NatImpl BNat
z NatImplBNat = b0
s NatImplBNat = sucBNat
--
data np (r : ℕ) : Type₀ where
bp : DirNum r → np r
zp : ∀ (d d′ : DirNum r) → bp d ≡ bp d′
xp : DirNum r → np r → np r
sucnp : ∀ {r} → np r → np r
sucnp {zero} (bp tt) = xp tt (bp tt)
sucnp {zero} (zp tt tt i) = xp tt (bp tt)
sucnp {zero} (xp tt n) = xp tt (sucnp n)
sucnp {suc r} (bp d) = xp (one-n (suc r)) (bp d)
sucnp {suc r} (zp d d′ i) = xp (one-n (suc r)) (zp d d′ i)
sucnp {suc r} (xp d n) with max? d
... | no _ = xp (next d) n
... | yes _ = xp (zero-n (suc r)) (sucnp n)
np→ℕ : (r : ℕ) (x : np r) → ℕ
np→ℕ r (bp x) = 0
np→ℕ r (zp d d′ i) = 0
np→ℕ zero (xp x x₁) = suc (np→ℕ zero x₁)
np→ℕ (suc r) (xp x x₁) = sucn (DirNum→ℕ x) (doublesℕ (suc r) (np→ℕ (suc r) x₁))
ℕ→np : (r : ℕ) → (n : ℕ) → np r
ℕ→np r zero = bp (zero-n r)
ℕ→np zero (suc n) = xp tt (ℕ→np zero n)
ℕ→np (suc r) (suc n) = sucnp (ℕ→np (suc r) n)
---- generalize bnat:
data N (r : ℕ) : Type₀ where
bn : DirNum r → N r
xr : DirNum r → N r → N r
-- should define induction principle for N r
-- we have 2ⁿ "unary" constructors, analogous to BNat with 2¹ (b0 and b1)
-- rename n to r
-- this likely introduces inefficiencies compared
-- to BinNat, with the max? check etc.
sucN : ∀ {n} → N n → N n
sucN {zero} (bn tt) = xr tt (bn tt)
sucN {zero} (xr tt x) = xr tt (sucN x)
sucN {suc n} (bn (↓ , ds)) = (bn (↑ , ds))
sucN {suc n} (bn (↑ , ds)) with max? ds
... | no _ = (bn (↓ , next ds))
... | yes _ = xr (zero-n (suc n)) (bn (one-n (suc n)))
sucN {suc n} (xr d x) with max? d
... | no _ = xr (next d) x
... | yes _ = xr (zero-n (suc n)) (sucN x)
sucnN : {r : ℕ} → (n : ℕ) → (N r → N r)
sucnN n = iter n sucN
doubleN : (r : ℕ) → N r → N r
doubleN zero (bn tt) = bn tt
doubleN zero (xr d x) = sucN (sucN (doubleN zero x))
doubleN (suc r) (bn x) with zero-n? x
... | yes _ = bn x
-- bad:
... | no _ = caseBool (bn (doubleDirNum (suc r) x)) (xr (zero-n (suc r)) (bn x)) (doubleable-n? x)
-- ... | no _ | doubleable = {!bn (doubleDirNum x)!}
-- ... | no _ | notdoubleable = xr (zero-n (suc r)) (bn x)
doubleN (suc r) (xr x x₁) = sucN (sucN (doubleN (suc r) x₁))
doublesN : (r : ℕ) → ℕ → N r → N r
doublesN r zero m = m
doublesN r (suc n) m = doublesN r n (doubleN r m)
N→ℕ : (r : ℕ) (x : N r) → ℕ
N→ℕ zero (bn tt) = zero
N→ℕ zero (xr tt x) = suc (N→ℕ zero x)
N→ℕ (suc r) (bn x) = DirNum→ℕ x
N→ℕ (suc r) (xr d x) = sucn (DirNum→ℕ d) (doublesℕ (suc r) (N→ℕ (suc r) x))
N→ℕsucN : (r : ℕ) (x : N r) → N→ℕ r (sucN x) ≡ suc (N→ℕ r x)
N→ℕsucN zero (bn tt) = refl
N→ℕsucN zero (xr tt x) =
suc (N→ℕ zero (sucN x))
≡⟨ cong suc (N→ℕsucN zero x) ⟩
suc (suc (N→ℕ zero x))
∎
N→ℕsucN (suc r) (bn (↓ , d)) = refl
N→ℕsucN (suc r) (bn (↑ , d)) with max? d
... | no d≠max =
doubleℕ (DirNum→ℕ (next d))
≡⟨ cong doubleℕ (next≡suc r d d≠max) ⟩
doubleℕ (suc (DirNum→ℕ d))
∎
... | yes d≡max = -- this can probably be shortened by not reducing down to zero
sucn (doubleℕ (DirNum→ℕ (zero-n r)))
(doublesℕ r (suc (suc (doubleℕ (doubleℕ (DirNum→ℕ (zero-n r)))))))
≡⟨ cong (λ x → sucn (doubleℕ x) (doublesℕ r (suc (suc (doubleℕ (doubleℕ x)))))) (zero-n→0 {r}) ⟩
sucn (doubleℕ zero) (doublesℕ r (suc (suc (doubleℕ (doubleℕ zero)))))
≡⟨ refl ⟩
doublesℕ (suc r) (suc zero) -- 2^(r+1)
≡⟨ sym (doubleDoubles r 1) ⟩
doubleℕ (doublesℕ r (suc zero)) --2*2^r
≡⟨ sym (sucPred (doubleℕ (doublesℕ r (suc zero))) (doubleDoublesOne≠0 r)) ⟩
suc (predℕ (doubleℕ (doublesℕ r (suc zero))))
≡⟨ cong suc (sym (sucPred (predℕ (doubleℕ (doublesℕ r (suc zero)))) (predDoubleDoublesOne≠0 r))) ⟩
suc (suc (predℕ (predℕ (doubleℕ (doublesℕ r (suc zero))))))
≡⟨ cong (λ x → suc (suc x)) (sym (doublePred (doublesℕ r (suc zero)))) ⟩
suc (suc (doubleℕ (predℕ (doublesℕ r (suc zero)))))
≡⟨ cong (λ x → suc (suc (doubleℕ x))) (sym (maxr≡pred2ʳ r d d≡max)) ⟩
suc (suc (doubleℕ (DirNum→ℕ d))) -- 2*(2^r - 1) + 2 = 2^(r+1) - 2 + 2 = 2^(r+1)
∎
N→ℕsucN (suc r) (xr (↓ , d) x) = refl
N→ℕsucN (suc r) (xr (↑ , d) x) with max? d
... | no d≠max =
sucn (doubleℕ (DirNum→ℕ (next d)))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x)))
≡⟨ cong (λ y → sucn (doubleℕ y) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))) (next≡suc r d d≠max) ⟩
sucn (doubleℕ (suc (DirNum→ℕ d)))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x)))
≡⟨ refl ⟩
suc
(suc
(iter (doubleℕ (DirNum→ℕ d)) suc
(doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))
∎
... | yes d≡max =
sucn (doubleℕ (DirNum→ℕ (zero-n r)))
(doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x))))
≡⟨ cong (λ z → sucn (doubleℕ z) (doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x))))) (zero-n≡0 {r}) ⟩
sucn (doubleℕ zero)
(doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x))))
≡⟨ refl ⟩
doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x)))
≡⟨ cong (λ x → doublesℕ r (doubleℕ x)) (N→ℕsucN (suc r) x) ⟩
doublesℕ r (doubleℕ (suc (N→ℕ (suc r) x)))
≡⟨ refl ⟩
doublesℕ r (suc (suc (doubleℕ (N→ℕ (suc r) x)))) -- 2^r * (2x + 2) = 2^(r+1)x + 2^(r+1)
≡⟨ doublesSucSuc r (doubleℕ (N→ℕ (suc r) x)) ⟩
sucn (doublesℕ (suc r) 1) -- _ + 2^(r+1)
(doublesℕ (suc r) (N→ℕ (suc r) x)) -- 2^(r+1)x + 2^(r+1)
≡⟨ H r (doublesℕ (suc r) (N→ℕ (suc r) x)) ⟩
suc
(suc
(sucn (doubleℕ (predℕ (doublesℕ r 1))) -- _ + 2(2^r - 1) + 2
(doublesℕ (suc r) (N→ℕ (suc r) x))))
≡⟨ refl ⟩
suc
(suc
(sucn (doubleℕ (predℕ (doublesℕ r 1)))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))
≡⟨ cong (λ z → suc (suc (sucn (doubleℕ z) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))) (sym (max→ℕ r)) ⟩
suc
(suc
(sucn (doubleℕ (DirNum→ℕ (max-n r)))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))
≡⟨ cong (λ z → suc (suc (sucn (doubleℕ (DirNum→ℕ z)) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))) (sym (d≡max)) ⟩
suc
(suc
(sucn (doubleℕ (DirNum→ℕ d))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- (2^r*2x + (2*(2^r - 1))) + 2 = 2^(r+1)x + 2^(r+1)
∎
where
H : (n m : ℕ) → sucn (doublesℕ (suc n) 1) m ≡ suc (suc (sucn (doubleℕ (predℕ (doublesℕ n 1))) m))
H zero m = refl
H (suc n) m =
sucn (doublesℕ n 4) m
≡⟨ cong (λ z → sucn z m) (doublesSucSuc n 2) ⟩
sucn (sucn (doublesℕ (suc n) 1) (doublesℕ n 2)) m
≡⟨ refl ⟩
sucn (sucn (doublesℕ n 2) (doublesℕ n 2)) m
≡⟨ {!!} ⟩
sucn (doubleℕ (doublesℕ n 2)) m
≡⟨ {!!} ⟩ {!!}
ℕ→N : (r : ℕ) → (n : ℕ) → N r
ℕ→N r zero = bn (zero-n r)
ℕ→N zero (suc n) = xr tt (ℕ→N zero n)
ℕ→N (suc r) (suc n) = sucN (ℕ→N (suc r) n)
ℕ→Nsuc : (r : ℕ) (n : ℕ) → ℕ→N r (suc n) ≡ sucN (ℕ→N r n)
ℕ→Nsuc r n = {!!}
ℕ→Nsucn : (r : ℕ) (n m : ℕ) → ℕ→N r (sucn n m) ≡ sucnN n (ℕ→N r m)
ℕ→Nsucn r n m = {!!}
-- NℕNlemma is actually a pretty important fact;
-- this is what allows the direct isomorphism of N and ℕ to go
-- without the need for an extra datatype, e.g. Pos for BinNat,
-- since each ℕ < 2^r maps to its "numeral" in N r.
-- should rename and move elsewhere.
numeral-next : (r : ℕ) (d : DirNum r) → N (suc r)
numeral-next r d = bn (embed-next r d)
--
NℕNlemma : (r : ℕ) (d : DirNum r) → ℕ→N r (DirNum→ℕ d) ≡ bn d
NℕNlemma zero tt = refl
NℕNlemma (suc r) (↓ , ds) =
ℕ→N (suc r) (doubleℕ (DirNum→ℕ ds))
≡⟨ {!!} ⟩ {!!}
NℕNlemma (suc r) (↑ , ds) = {!!}
N→ℕ→N : (r : ℕ) → (x : N r) → ℕ→N r (N→ℕ r x) ≡ x
N→ℕ→N zero (bn tt) = refl
N→ℕ→N zero (xr tt x) = cong (xr tt) (N→ℕ→N zero x)
N→ℕ→N (suc r) (bn (↓ , ds)) =
ℕ→N (suc r) (doubleℕ (DirNum→ℕ ds))
≡⟨ cong (λ x → ℕ→N (suc r) x) (double-lemma ds) ⟩
ℕ→N (suc r) (DirNum→ℕ {suc r} (↓ , ds))
≡⟨ NℕNlemma (suc r) (↓ , ds) ⟩
bn (↓ , ds)
∎
N→ℕ→N (suc r) (bn (↑ , ds)) =
sucN (ℕ→N (suc r) (doubleℕ (DirNum→ℕ ds)))
≡⟨ cong (λ x → sucN (ℕ→N (suc r) x)) (double-lemma ds) ⟩
sucN (ℕ→N (suc r) (DirNum→ℕ {suc r} (↓ , ds)))
≡⟨ cong sucN (NℕNlemma (suc r) (↓ , ds)) ⟩
sucN (bn (↓ , ds))
≡⟨ refl ⟩
bn (↑ , ds)
∎
N→ℕ→N (suc r) (xr (↓ , ds) x) =
ℕ→N (suc r)
(sucn (doubleℕ (DirNum→ℕ ds))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x))))
≡⟨ cong (λ z → ℕ→N (suc r) (sucn z (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) (double-lemma ds) ⟩
ℕ→N (suc r)
(sucn (DirNum→ℕ {suc r} (↓ , ds))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x))))
≡⟨ refl ⟩
ℕ→N (suc r)
(sucn (DirNum→ℕ {suc r} (↓ , ds))
(doublesℕ (suc r) (N→ℕ (suc r) x)))
≡⟨ ℕ→Nsucn (suc r) (DirNum→ℕ {suc r} (↓ , ds)) (doublesℕ (suc r) (N→ℕ (suc r) x)) ⟩
sucnN (DirNum→ℕ {suc r} (↓ , ds))
(ℕ→N (suc r) (doublesℕ (suc r) (N→ℕ (suc r) x)))
≡⟨ cong (λ z → sucnN (DirNum→ℕ {suc r} (↓ , ds)) z) (H (suc r) (suc r) (N→ℕ (suc r) x)) ⟩
sucnN (DirNum→ℕ {suc r} (↓ , ds))
(doublesN (suc r) (suc r) (ℕ→N (suc r) (N→ℕ (suc r) x)))
≡⟨ cong (λ z → sucnN (DirNum→ℕ {suc r} (↓ , ds)) (doublesN (suc r) (suc r) z)) (N→ℕ→N (suc r) x) ⟩
sucnN (DirNum→ℕ {suc r} (↓ , ds))
(doublesN (suc r) (suc r) x)
≡⟨ G (suc r) (↓ , ds) x snotz ⟩
xr (↓ , ds) x ∎
where
H : (r m n : ℕ) → ℕ→N r (doublesℕ m n) ≡ doublesN r m (ℕ→N r n)
H r m n = {!!}
G : (r : ℕ) (d : DirNum r) (x : N r) → ¬ (r ≡ 0) → sucnN (DirNum→ℕ {r} d) (doublesN r r x) ≡ xr d x
G zero d x 0≠0 = ⊥-elim (0≠0 refl)
G (suc r) d (bn x) r≠0 = {!!}
G (suc r) d (xr x x₁) r≠0 = {!!}
N→ℕ→N (suc r) (xr (↑ , ds) x) with max? ds
... | no ds≠max =
sucN
(ℕ→N (suc r)
(sucn (doubleℕ (DirNum→ℕ ds))
(doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))
≡⟨ sym (ℕ→Nsuc (suc r)
(sucn (doubleℕ (DirNum→ℕ ds)) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))
⟩
ℕ→N (suc r)
(suc (sucn (doubleℕ (DirNum→ℕ ds)) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))
≡⟨ refl ⟩
ℕ→N (suc r)
(suc (sucn (doubleℕ (DirNum→ℕ ds)) (doublesℕ (suc r) (N→ℕ (suc r) x))))
≡⟨ cong (λ z → ℕ→N (suc r) z)
(sym (sucnsuc (doubleℕ (DirNum→ℕ ds)) (doublesℕ (suc r) (N→ℕ (suc r) x))))
⟩
ℕ→N (suc r)
(sucn (doubleℕ (DirNum→ℕ ds)) (suc (doublesℕ (suc r) (N→ℕ (suc r) x))))
≡⟨ ℕ→Nsucn (suc r) (doubleℕ (DirNum→ℕ ds)) (suc (doublesℕ (suc r) (N→ℕ (suc r) x))) ⟩
sucnN (doubleℕ (DirNum→ℕ ds)) (ℕ→N (suc r) (suc (doublesℕ (suc r) (N→ℕ (suc r) x))))
≡⟨ cong (λ z → sucnN (doubleℕ (DirNum→ℕ ds)) z)
(ℕ→Nsuc (suc r) (doublesℕ (suc r) (N→ℕ (suc r) x)))
⟩
-- (2^(r+1)*x + 1) + 2*ds
-- = 2*(2^r*x + ds) + 1
-- = 2*(
sucnN (doubleℕ (DirNum→ℕ ds)) (sucN (ℕ→N (suc r) (doublesℕ (suc r) (N→ℕ (suc r) x))))
≡⟨ {!!} ⟩ {!!}
... | yes ds≡max = {!!}
ℕ→N→ℕ : (r : ℕ) → (n : ℕ) → N→ℕ r (ℕ→N r n) ≡ n
ℕ→N→ℕ zero zero = refl
ℕ→N→ℕ (suc r) zero =
doubleℕ (DirNum→ℕ (zero-n r))
≡⟨ cong doubleℕ (zero-n≡0 {r}) ⟩
doubleℕ zero
≡⟨ refl ⟩
zero
∎
ℕ→N→ℕ zero (suc n) = cong suc (ℕ→N→ℕ zero n)
ℕ→N→ℕ (suc r) (suc n) =
N→ℕ (suc r) (sucN (ℕ→N (suc r) n))
≡⟨ N→ℕsucN (suc r) (ℕ→N (suc r) n) ⟩
suc (N→ℕ (suc r) (ℕ→N (suc r) n))
≡⟨ cong suc (ℕ→N→ℕ (suc r) n) ⟩
suc n
∎
N≃ℕ : (r : ℕ) → N r ≃ ℕ
N≃ℕ r = isoToEquiv (iso (N→ℕ r) (ℕ→N r) (ℕ→N→ℕ r) (N→ℕ→N r))
N≡ℕ : (r : ℕ) → N r ≡ ℕ
N≡ℕ r = ua (N≃ℕ r)
---- pos approach:
data NPos (n : ℕ) : Type₀ where
npos1 : NPos n
x⇀ : DirNum n → NPos n → NPos n
sucNPos : ∀ {n} → NPos n → NPos n
sucNPos {zero} npos1 = x⇀ tt npos1
sucNPos {zero} (x⇀ tt x) = x⇀ tt (sucNPos x)
sucNPos {suc n} npos1 = x⇀ (next (one-n (suc n))) npos1
sucNPos {suc n} (x⇀ d x) with (max? d)
... | (no _) = x⇀ (next d) x
... | (yes _) = x⇀ (zero-n (suc n)) (sucNPos x)
-- some examples for sanity check
2₂ : NPos 1
2₂ = x⇀ (↓ , tt) npos1
3₂ : NPos 1
3₂ = x⇀ (↑ , tt) npos1
4₂ : NPos 1
4₂ = x⇀ (↓ , tt) (x⇀ (↓ , tt) npos1)
2₄ : NPos 2
2₄ = x⇀ (↓ , (↑ , tt)) npos1 -- how does this make sense?
3₄ : NPos 2
3₄ = x⇀ (↑ , (↑ , tt)) npos1 -- how does this make sense?
-- sucnpos1≡x⇀one-n : ∀ {r} → sucNPos npos1 ≡ x⇀ (one-n r) npos1
-- sucnpos1≡x⇀one-n {zero} = refl
-- sucnpos1≡x⇀one-n {suc r} = {!!}
-- sucnposx⇀zero-n≡x⇀one-n : ∀ {r} {p} → sucNPos (x⇀ (zero-n r) p) ≡ x⇀ (one-n r) p
-- sucnposx⇀zero-n≡x⇀one-n {zero} {npos1} = {!!}
-- sucnposx⇀zero-n≡x⇀one-n {zero} {x⇀ x p} = {!!}
-- sucnposx⇀zero-n≡x⇀one-n {suc r} {p} = refl
nPosInd : ∀ {r} {P : NPos r → Type₀} →
P npos1 →
((p : NPos r) → P p → P (sucNPos p)) →
(p : NPos r) →
P p
nPosInd {r} {P} h1 hs ps = f ps
where
H : (p : NPos r) → P (x⇀ (zero-n r) p) → P (x⇀ (zero-n r) (sucNPos p))
--H p hx0p = hs (x⇀ (one-n r) p) (hs (x⇀ (zero-n r) p) hx0p)
f : (ps : NPos r) → P ps
f npos1 = h1
f (x⇀ d ps) with (max? d)
... | (no _) = {!nPosInd (hs npos1 h1) H ps!}
... | (yes _) = {!hs (x⇀ (zero-n r) ps) (nPosInd (hs npos1 h1) H ps)!}
-- nPosInd {zero} {P} h1 hs ps = f ps
-- where
-- H : (p : NPos zero) → P (x⇀ (zero-n zero) p) → P (x⇀ (zero-n zero) (sucNPos p))
-- H p hx0p = hs (x⇀ tt (x⇀ (zero-n zero) p)) (hs (x⇀ (zero-n zero) p) hx0p)
-- f : (ps : NPos zero) → P ps
-- f npos1 = h1
-- f (x⇀ tt ps) = nPosInd (hs npos1 h1) H ps
-- nPosInd {suc r} {P} h1 hs ps = f ps
-- where
-- H : (p : NPos (suc r)) → P (x⇀ (zero-n (suc r)) p) → P (x⇀ (zero-n (suc r)) (sucNPos p))
-- --H p hx0p = hs (x⇀ (one-n r) p) (hs (x⇀ (zero-n r) p) hx0p)
-- f : (ps : NPos (suc r)) → P ps
-- f npos1 = h1
-- f (x⇀ d ps) = {!!}
NPos→ℕ : ∀ r → NPos r → ℕ
NPos→ℕ zero npos1 = suc zero
NPos→ℕ zero (x⇀ tt x) = suc (NPos→ℕ zero x)
NPos→ℕ (suc r) npos1 = suc zero
NPos→ℕ (suc r) (x⇀ d x) with max? d
... | no _ = sucn (DirNum→ℕ (next d)) (doublesℕ (suc r) (NPos→ℕ (suc r) x))
... | yes _ = sucn (DirNum→ℕ (next d)) (doublesℕ (suc r) (suc (NPos→ℕ (suc r) x)))
-- NPos→ℕ (suc r) (x⇀ d x) =
-- sucn (DirNum→ℕ d) (doublesℕ (suc r) (NPos→ℕ (suc r) x))
NPos→ℕsucNPos : ∀ r → (p : NPos r) → NPos→ℕ r (sucNPos p) ≡ suc (NPos→ℕ r p)
NPos→ℕsucNPos zero npos1 = refl
NPos→ℕsucNPos zero (x⇀ d p) = cong suc (NPos→ℕsucNPos zero p)
NPos→ℕsucNPos (suc r) npos1 = {!!}
sucn (doubleℕ (DirNum→ℕ (zero-n r))) (doublesℕ r 2)
≡⟨ cong (λ y → sucn y (doublesℕ r 2)) (zero-n→0) ⟩
sucn (doubleℕ zero) (doublesℕ r 2)
≡⟨ refl ⟩
doublesℕ r 2
≡⟨ {!!} ⟩ {!!}
NPos→ℕsucNPos (suc r) (x⇀ d p) with max? d
... | no _ = {!!}
... | yes _ = {!!}
-- zero≠NPos→ℕ : ∀ {r} → (p : NPos r) → ¬ (zero ≡ NPos→ℕ r p)
-- zero≠NPos→ℕ {r} p = {!!}
ℕ→NPos : ∀ r → ℕ → NPos r
ℕ→NPos zero zero = npos1
ℕ→NPos zero (suc zero) = npos1
ℕ→NPos zero (suc (suc n)) = sucNPos (ℕ→NPos zero (suc n))
ℕ→NPos (suc r) zero = npos1
ℕ→NPos (suc r) (suc zero) = npos1
ℕ→NPos (suc r) (suc (suc n)) = sucNPos (ℕ→NPos (suc r) (suc n))
lemma : ∀ {r} → (ℕ→NPos r (NPos→ℕ r npos1)) ≡ npos1
lemma {zero} = refl
lemma {suc r} = refl
NPos→ℕ→NPos : ∀ r → (p : NPos r) → ℕ→NPos r (NPos→ℕ r p) ≡ p
NPos→ℕ→NPos r p = nPosInd lemma hs p
where
hs : (p : NPos r) → ℕ→NPos r (NPos→ℕ r p) ≡ p → ℕ→NPos r (NPos→ℕ r (sucNPos p)) ≡ (sucNPos p)
hs p hp =
ℕ→NPos r (NPos→ℕ r (sucNPos p))
≡⟨ {!!} ⟩
ℕ→NPos r (suc (NPos→ℕ r p))
≡⟨ {!!} ⟩
sucNPos (ℕ→NPos r (NPos→ℕ r p))
≡⟨ cong sucNPos hp ⟩
sucNPos p
∎
-- note: the cases for zero and suc r are almost identical
-- (why) does this need to split?
ℕ→NPos→ℕ : ∀ r → (n : ℕ) → NPos→ℕ r (ℕ→NPos r (suc n)) ≡ (suc n)
ℕ→NPos→ℕ zero zero = refl
ℕ→NPos→ℕ zero (suc n) =
NPos→ℕ zero (sucNPos (ℕ→NPos zero (suc n)))
≡⟨ {!!} ⟩
suc (NPos→ℕ zero (ℕ→NPos zero (suc n)))
≡⟨ cong suc (ℕ→NPos→ℕ zero n) ⟩
suc (suc n)
∎
ℕ→NPos→ℕ (suc r) zero = refl
ℕ→NPos→ℕ (suc r) (suc n) =
NPos→ℕ (suc r) (sucNPos (ℕ→NPos (suc r) (suc n)))
≡⟨ {!!} ⟩
suc (NPos→ℕ (suc r) (ℕ→NPos (suc r) (suc n)))
≡⟨ cong suc (ℕ→NPos→ℕ (suc r) n) ⟩
suc (suc n)
∎
| 33.019504
| 116
| 0.503893
|
fb62ebea2bf70d9cfd2e34c790a0654d814cea12
| 110
|
agda
|
Agda
|
agda/Cham/Name.agda
|
riz0id/chemical-abstract-machine
|
292023fc36fa67ca4a81cff9a875a325a79b9d6f
|
[
"BSD-3-Clause"
] | null | null | null |
agda/Cham/Name.agda
|
riz0id/chemical-abstract-machine
|
292023fc36fa67ca4a81cff9a875a325a79b9d6f
|
[
"BSD-3-Clause"
] | null | null | null |
agda/Cham/Name.agda
|
riz0id/chemical-abstract-machine
|
292023fc36fa67ca4a81cff9a875a325a79b9d6f
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Cham.Name where
open import Data.String
Name : Set
Name = String
| 12.222222
| 34
| 0.681818
|
c558fa386b713a5e93bc278797c75acd7380432b
| 7,607
|
agda
|
Agda
|
agda/book/SFHC/v01-01-basics.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/SFHC/v01-01-basics.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/SFHC/v01-01-basics.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
-- this is so this can be imported even though it has unresolved holes
{-# OPTIONS --allow-unsolved-metas #-}
module v01-01-basics where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
data day : Set where
mon : day
tue : day
wed : day
thu : day
fri : day
sat : day
sun : day
next-weekday : day → day
next-weekday mon = tue
next-weekday tue = wed
next-weekday wed = thu
next-weekday thu = fri
next-weekday fri = mon
next-weekday sat = mon
next-weekday sun = mon
_ : next-weekday fri ≡ mon
_ = refl
_ : next-weekday (next-weekday sat) ≡ tue
_ = refl
data bool : Set where
true : bool
false : bool
negb : bool → bool
negb true = false
negb false = true
andb : bool → bool → bool
andb true b2 = b2
andb false _ = false
orb : bool → bool → bool
orb true _ = true
orb false b2 = b2
_ : orb false false ≡ false
_ = refl
_ : orb false true ≡ true
_ = refl
_ : orb true false ≡ true
_ = refl
_ : orb true true ≡ true
_ = refl
nandb : bool → bool → bool
nandb true true = false
nandb _ _ = true
_ : nandb false false ≡ true
_ = refl
_ : nandb false true ≡ true
_ = refl
_ : nandb true false ≡ true
_ = refl
_ : nandb true true ≡ false
_ = refl
andb3 : bool → bool → bool → bool
andb3 true true true = true
andb3 _ _ _ = false
_ : andb3 true true true ≡ true
_ = refl
_ : andb3 false true true ≡ false
_ = refl
_ : andb3 true false true ≡ false
_ = refl
_ : andb3 true true false ≡ false
_ = refl
data rgb : Set where
red : rgb
green : rgb
blue : rgb
data color : Set where
black : color
white : color
primary : rgb → color
monochrome : color → bool
monochrome black = true
monochrome white = true
monochrome (primary _) = false
isred : color → bool
isred (primary red) = true
isred _ = false
data bit : Set where
B0 : bit
B1 : bit
data nybble : Set where
bits : (b0 b1 b2 b3 : bit) → nybble
all-zero : nybble → bool
all-zero (bits B0 B0 B0 B0) = true
all-zero _ = false
_ : all-zero (bits B1 B0 B1 B0) ≡ false
_ = refl
_ : all-zero (bits B0 B0 B0 B0) ≡ true
_ = refl
data nat : Set where
O : nat
S : nat → nat
pred : nat → nat
pred O = O
pred (S n) = n
{-# BUILTIN NATURAL nat #-}
_ : S (S (S (S O))) ≡ 4
_ = refl
minustwo : nat → nat
minustwo O = O
minustwo (S O) = O
minustwo (S (S n)) = n
_ : minustwo 4 ≡ 2
_ = refl
evenb : nat → bool
evenb O = true
evenb (S O) = false
evenb (S (S n)) = evenb n
oddb : nat → bool
oddb n = negb (evenb n)
_ : oddb 1 ≡ true
_ = refl
_ : oddb 4 ≡ false
_ = refl
plus : nat → nat → nat
plus O m = m
plus (S n) m = S (plus n m)
_ : plus 3 2 ≡ 5
_ = refl
mult : nat → nat → nat
mult O m = 0
mult (S n) m = plus m (mult n m)
_ : mult 3 3 ≡ 9
_ = refl
minus : nat → nat → nat
minus O _ = O
minus x O = x
minus (S n) (S m) = minus n m
exp : (base power : nat) → nat
exp _ O = S O
exp b (S p) = mult b (exp b p)
_ : exp 2 0 ≡ 1
_ = refl
_ : exp 2 1 ≡ 2
_ = refl
_ : exp 2 2 ≡ 4
_ = refl
_ : exp 2 3 ≡ 8
_ = refl
factorial : nat → nat
factorial O = 1
factorial (S n) = mult (S n) (factorial n)
_ : factorial 3 ≡ 6
_ = refl
_ : factorial 5 ≡ mult 10 12
_ = refl
_+_ : nat → nat → nat
_+_ = plus
_-_ : nat → nat → nat
_-_ = minus
_*_ : nat → nat → nat
_*_ = mult
infixl 6 _+_ _-_
infixl 7 _*_
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
{-# BUILTIN NATMINUS _-_ #-}
eqb : (n m : nat) → bool
eqb O O = true
eqb O (S _) = false
eqb (S _) O = false
eqb (S l) (S r) = eqb l r
leb : (n m : nat) → bool
leb O _ = true
leb (S n) O = false
leb (S n) (S m) = leb n m
_ : leb 2 2 ≡ true
_ = refl
_ : leb 2 4 ≡ true
_ = refl
_ : leb 4 2 ≡ false
_ = refl
_=?_ : (n m : nat) → bool
_=?_ = eqb
_<=?_ : (n m : nat) → bool
_<=?_ = leb
infix 4 _=?_
infix 4 _<=?_
_ : (4 <=? 2) ≡ false
_ = refl
ltb : (n m : nat) → bool
ltb O O = false
ltb O (S m) = true
ltb (S n) O = false
ltb (S n) (S m) = ltb n m
_<?_ : (n m : nat) → bool
_<?_ = ltb
infix 4 _<?_
_ : ltb 2 2 ≡ false
_ = refl
_ : ltb 2 4 ≡ true
_ = refl
_ : ltb 4 2 ≡ false
_ = refl
-- proof by simplification
plus-O-n : ∀ {n : nat} → 0 + n ≡ n
plus-O-n = refl
plus-1-l : ∀ {n : nat} → 1 + n ≡ S n
plus-1-l = refl
mult-O-l : ∀ {n : nat} → 0 * n ≡ 0
mult-O-l = refl
-- proof by rewriting
plus-id-example : ∀ {n m : nat}
→ n ≡ m
→ n + n ≡ m + m
plus-id-example n≡m rewrite n≡m = refl
plus_id_exercise : ∀ {n m o : nat}
→ n ≡ m
→ m ≡ o
→ n + m ≡ m + o
plus_id_exercise n≡m m≡o rewrite n≡m | m≡o = refl
*0 : ∀ (m : nat) → m * 0 ≡ 0
*0 0 = refl
*0 (S m) = *0 m
mult-n-O : ∀ (n : nat) → 0 ≡ n * 0
mult-n-O n rewrite *0 n = refl
*1 : ∀ (n : nat) → n * 1 ≡ n
*1 0 = refl
*1 (S n) rewrite *1 n = refl
1* : ∀ (n : nat) → 1 * n ≡ n
1* 0 = refl
1* (S n) rewrite 1* n = refl
mult-n-Sm : ∀ (n m : nat) → n * m + n ≡ n * S m
mult-n-Sm O m = refl
mult-n-Sm n O rewrite *0 n | plus-O-n {n} | *1 n = refl
mult-n-Sm (S n) (S m) = {!!} -- TODO
mult-n-0-m-0 : ∀ (p q : nat)
→ (p * 0) + (q * 0) ≡ 0
mult-n-0-m-0 p q rewrite *0 p | *0 q = refl
mult-n-1 : ∀ (p : nat) → p * 1 ≡ p
mult-n-1 = *1
-- proof by case analysis
plus-1-neq-0 : ∀ (n : nat) → ((n + 1) =? 0) ≡ false
plus-1-neq-0 O = refl
plus-1-neq-0 (S n) rewrite plus-1-neq-0 n = refl
negb-involutive : ∀ (b : bool) → negb (negb b) ≡ b
negb-involutive true = refl
negb-involutive false = refl
andb-commutative : ∀ (b c : bool) → andb b c ≡ andb c b
andb-commutative false false = refl
andb-commutative false true = refl
andb-commutative true false = refl
andb-commutative true true = refl
andb3-exchange : ∀ (b c d : bool) → andb (andb b c) d ≡ andb (andb b d) c
andb3-exchange true true true = refl
andb3-exchange true true false = refl
andb3-exchange true false true = refl
andb3-exchange true false false = refl
andb3-exchange false true true = refl
andb3-exchange false true false = refl
andb3-exchange false false true = refl
andb3-exchange false false false = refl
andb-true-elim2 : ∀ (b c : bool)
→ andb b c ≡ true
→ c ≡ true
andb-true-elim2 false _ ()
andb-true-elim2 true false ()
andb-true-elim2 true true _ = refl
zero-nbeq-plus-1 : ∀ (n : nat) → (0 =? (n + 1)) ≡ false
zero-nbeq-plus-1 O = refl
zero-nbeq-plus-1 (S n) rewrite zero-nbeq-plus-1 n = refl
identity-fn-applied-twice : ∀ {f : bool → bool} (b : bool)
→ f b ≡ b
→ f (f b) ≡ b
identity-fn-applied-twice b p rewrite p | p = refl
negation-fn-applied-twice : ∀ {f : bool → bool} {b : bool} -- TODO
→ f b ≡ negb b
→ f (f b) ≡ b
negation-fn-applied-twice {f} {false} p = {!!} -- TODO
negation-fn-applied-twice {f} {true} p = {!!} -- TODO
andb-eq-orb : ∀ (b c : bool)
→ andb b c ≡ orb b c
→ b ≡ c
andb-eq-orb true c p rewrite p = refl
andb-eq-orb false c p rewrite p = refl
-- NOTE: lowest order bit is on LEFT
data bin : Set where
Z : bin
B₀ : bin → bin
B₁ : bin → bin
incr : bin → bin
incr Z = B₁ Z
incr (B₀ x) = B₁ x
incr (B₁ x) = B₀ (incr x)
bin-to-nat : bin → nat
bin-to-nat Z = 0
bin-to-nat (B₀ x) = 2 * (bin-to-nat x)
bin-to-nat (B₁ x) = 1 + 2 * (bin-to-nat x)
_ : (incr (B₁ Z)) ≡ B₀ (B₁ Z)
_ = refl
_ : (incr (B₀ (B₁ Z))) ≡ B₁ (B₁ Z)
_ = refl
_ : (incr (B₁ (B₁ Z))) ≡ B₀ (B₀ (B₁ Z))
_ = refl
_ : bin-to-nat (B₀ (B₁ Z)) ≡ 2
_ = refl
_ : bin-to-nat (incr (B₁ Z)) ≡ 1 + bin-to-nat (B₁ Z)
_ = refl
_ : bin-to-nat (incr (incr (B₁ Z))) ≡ 2 + bin-to-nat (B₁ Z)
_ = refl
| 19.405612
| 73
| 0.560273
|
cb160dc6dfebd8b91ccba3674d3bafb50e1537c4
| 356
|
agda
|
Agda
|
test/Succeed/ImplicitlyDottedVariable.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/ImplicitlyDottedVariable.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/ImplicitlyDottedVariable.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Nat
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
cons : (n : Nat) → A → Vec A n → Vec A (suc n)
tail : {A : Set} (n : Nat) → Vec A (suc n) → Vec A n
tail n (cons n x xs) = xs
tail' : {A : Set} (n : Nat) → Vec A (suc n) → Vec A n
tail' 0 (cons 0 x []) = []
tail' (suc n) (cons (suc n) x (cons n x₁ xs)) = (cons n x₁ xs)
| 27.384615
| 62
| 0.516854
|
dccb13a6cc520c23ed589953df57d0495f18f722
| 4,043
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Cubical/Glue.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
src/data/lib/prim/Agda/Builtin/Cubical/Glue.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
src/data/lib/prim/Agda/Builtin/Cubical/Glue.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.Cubical.Glue where
open import Agda.Primitive
open import Agda.Builtin.Sigma
open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_;
primHComp to hcomp; primTransp to transp; primComp to comp;
itIsOne to 1=1)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to ouc)
import Agda.Builtin.Cubical.HCompU as HCompU
module Helpers = HCompU.Helpers
open Helpers
-- We make this a record so that isEquiv can be proved using
-- copatterns. This is good because copatterns don't get unfolded
-- unless a projection is applied so it should be more efficient.
record isEquiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where
no-eta-equality
field
equiv-proof : (y : B) → isContr (fiber f y)
open isEquiv public
infix 4 _≃_
_≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ')
A ≃ B = Σ (A → B) \ f → (isEquiv f)
equivFun : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → A ≃ B → A → B
equivFun e = fst e
-- Improved version of equivProof compared to Lemma 5 in CCHM. We put
-- the (φ = i0) face in contr' making it be definitionally c in this
-- case. This makes the computational behavior better, in particular
-- for transp in Glue.
equivProof : ∀ {la lt} (T : Set la) (A : Set lt) → (w : T ≃ A) → (a : A)
→ ∀ ψ → (Partial ψ (fiber (w .fst) a)) → fiber (w .fst) a
equivProof A B w a ψ fb = contr' {A = fiber (w .fst) a} (w .snd .equiv-proof a) ψ fb
where
contr' : ∀ {ℓ} {A : Set ℓ} → isContr A → (φ : I) → (u : Partial φ A) → A
contr' {A = A} (c , p) φ u = hcomp (λ i → λ { (φ = i1) → p (u 1=1) i
; (φ = i0) → c }) c
{-# BUILTIN EQUIV _≃_ #-}
{-# BUILTIN EQUIVFUN equivFun #-}
{-# BUILTIN EQUIVPROOF equivProof #-}
primitive
primGlue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
→ (T : Partial φ (Set ℓ')) → (e : PartialP φ (λ o → T o ≃ A))
→ Set ℓ'
prim^glue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
→ {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
→ (t : PartialP φ T) → (a : A) → primGlue A T e
prim^unglue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
→ {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
→ primGlue A T e → A
module _ {ℓ : I → Level} (P : (i : I) → Set (ℓ i)) where
private
E : (i : I) → Set (ℓ i)
E = λ i → P i
~E : (i : I) → Set (ℓ (~ i))
~E = λ i → P (~ i)
A = P i0
B = P i1
f : A → B
f x = transp E i0 x
g : B → A
g y = transp ~E i0 y
u : ∀ i → A → E i
u i x = transp (λ j → E (i ∧ j)) (~ i) x
v : ∀ i → B → E i
v i y = transp (λ j → ~E ( ~ i ∧ j)) i y
fiberPath : (y : B) → (xβ0 xβ1 : fiber f y) → xβ0 ≡ xβ1
fiberPath y (x0 , β0) (x1 , β1) k = ω , λ j → δ (~ j) where
module _ (j : I) where
private
sys : A → ∀ i → PartialP (~ j ∨ j) (λ _ → E (~ i))
sys x i (j = i0) = v (~ i) y
sys x i (j = i1) = u (~ i) x
ω0 = comp ~E (sys x0) ((β0 (~ j)))
ω1 = comp ~E (sys x1) ((β1 (~ j)))
θ0 = fill ~E (sys x0) (inc (β0 (~ j)))
θ1 = fill ~E (sys x1) (inc (β1 (~ j)))
sys = λ {j (k = i0) → ω0 j ; j (k = i1) → ω1 j}
ω = hcomp sys (g y)
θ = hfill sys (inc (g y))
δ = λ (j : I) → comp E
(λ i → λ { (j = i0) → v i y ; (k = i0) → θ0 j (~ i)
; (j = i1) → u i ω ; (k = i1) → θ1 j (~ i) })
(θ j)
γ : (y : B) → y ≡ f (g y)
γ y j = comp E (λ i → λ { (j = i0) → v i y
; (j = i1) → u i (g y) }) (g y)
pathToisEquiv : isEquiv f
pathToisEquiv .equiv-proof y .fst .fst = g y
pathToisEquiv .equiv-proof y .fst .snd = sym (γ y)
pathToisEquiv .equiv-proof y .snd = fiberPath y _
pathToEquiv : A ≃ B
pathToEquiv .fst = f
pathToEquiv .snd = pathToisEquiv
| 33.413223
| 104
| 0.489241
|
df9cfe14188744d93f880e9fb974eb5bedb92e7f
| 1,597
|
agda
|
Agda
|
Data/ListSized/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Data/ListSized/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Data/ListSized/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Data.ListSized.Proofs where
import Lvl
open import Data.ListSized
open import Data.ListSized.Functions
open import Functional
open import Function.Equals
open import Numeral.Finite
open import Numeral.Natural
open import Numeral.Natural.Function
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
open import Type
private variable ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable T A A₁ A₂ B B₁ B₂ C C₁ C₂ Result : Type{ℓ}
private variable a b n n₁ n₂ : ℕ
private variable f : B → C
private variable g : A → B
private variable l l₁ l₂ : List(T)(n)
private variable x : T
map-id : (map{A = A}{n = n} id ⊜ id)
_⊜_.proof map-id {∅} = reflexivity(_≡_)
_⊜_.proof map-id {x ⊰ l} = congruence₂ᵣ(_⊰_)(_) (_⊜_.proof map-id {l})
map-[∘] : (map{n = n} (f ∘ g) ⊜ (map f) ∘ (map g))
_⊜_.proof map-[∘] {∅} = reflexivity(_≡_)
_⊜_.proof map-[∘] {x ⊰ l} = congruence₂ᵣ(_⊰_)(_) (_⊜_.proof map-[∘] {l})
map-[++] : map f(l₁ ++ l₂) ≡ map f(l₁) ++ map f(l₂)
map-[++] {l₁ = ∅} = reflexivity(_≡_)
map-[++] {l₁ = x₁ ⊰ l₁} = congruence₂ᵣ(_⊰_)(_) (map-[++] {l₁ = l₁})
map-repeat : map f(repeat x n) ≡ repeat (f(x)) n
map-repeat {n = 𝟎} = reflexivity(_≡_)
map-repeat {n = 𝐒 n} = congruence₂ᵣ(_⊰_)(_) (map-repeat {n = n})
[+][++]-repeat : repeat x (n₁ + n₂) ≡ repeat x n₁ ++ repeat x n₂
[+][++]-repeat {n₁ = 𝟎} = reflexivity(_≡_)
[+][++]-repeat {n₁ = 𝐒 n₁} = congruence₂ᵣ(_⊰_)(_) ([+][++]-repeat {n₁ = n₁})
| 33.978723
| 76
| 0.646212
|
1c2a8544144d932b0ab915248d59c18245666355
| 1,911
|
agda
|
Agda
|
Cubical/Data/HomotopyGroup/Base.agda
|
Rotsor/cubical
|
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
|
[
"MIT"
] | null | null | null |
Cubical/Data/HomotopyGroup/Base.agda
|
Rotsor/cubical
|
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
|
[
"MIT"
] | null | null | null |
Cubical/Data/HomotopyGroup/Base.agda
|
Rotsor/cubical
|
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.HomotopyGroup.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
import Cubical.Foundations.GroupoidLaws as GL
open import Cubical.Data.Nat
open import Cubical.Data.Group.Base
open import Cubical.HITs.SetTruncation
Pointed : ∀ {ℓ} → Type (ℓ-suc ℓ)
Pointed {ℓ} = Σ[ A ∈ Type ℓ ] A
Ω : ∀ {ℓ} → Pointed {ℓ} → Pointed {ℓ}
Ω (A , a ) = ( (a ≡ a) , refl)
Ω^_ : ∀ {ℓ} → ℕ → Pointed {ℓ} → Pointed {ℓ}
(Ω^ 0) p = p
(Ω^ (suc n)) p = Ω ((Ω^ n) p)
π^_ : ∀ {ℓ} → ℕ → Pointed {ℓ} → Group {ℓ}
π^_ {ℓ} n p = group ∥ A ∥₀ squash₀ g
where
n' : ℕ
n' = suc n
A : Type ℓ
A = (Ω^ n') p .fst
g : isGroup ∥ A ∥₀
g = group-struct e _⁻¹ _⊙_ lUnit rUnit assoc lCancel rCancel
where
e : ∥ A ∥₀
e = ∣ (Ω^ n') p .snd ∣₀
_⁻¹ : ∥ A ∥₀ → ∥ A ∥₀
_⁻¹ = elimSetTrunc {B = λ _ → ∥ A ∥₀} (λ x → squash₀) λ a → ∣ sym a ∣₀
_⊙_ : ∥ A ∥₀ → ∥ A ∥₀ → ∥ A ∥₀
_⊙_ = elimSetTrunc2 (λ _ _ → squash₀) λ a₀ a₁ → ∣ a₀ ∙ a₁ ∣₀
lUnit : (a : ∥ A ∥₀) → (e ⊙ a) ≡ a
lUnit = elimSetTrunc (λ _ → isProp→isSet (squash₀ _ _))
(λ a → cong ∣_∣₀ (sym (GL.lUnit a) ))
rUnit : (a : ∥ A ∥₀) → a ⊙ e ≡ a
rUnit = elimSetTrunc (λ _ → isProp→isSet (squash₀ _ _))
(λ a → cong ∣_∣₀ (sym (GL.rUnit a) ))
assoc : (a b c : ∥ A ∥₀) → ((a ⊙ b) ⊙ c) ≡ (a ⊙ (b ⊙ c))
assoc = elimSetTrunc3 (λ _ _ _ → isProp→isSet (squash₀ _ _))
(λ a b c → cong ∣_∣₀ (sym (GL.assoc _ _ _)))
lCancel : (a : ∥ A ∥₀) → ((a ⁻¹) ⊙ a) ≡ e
lCancel = elimSetTrunc (λ _ → isProp→isSet (squash₀ _ _))
λ a → cong ∣_∣₀ (GL.lCancel _)
rCancel : (a : ∥ A ∥₀) → (a ⊙ (a ⁻¹)) ≡ e
rCancel = elimSetTrunc (λ _ → isProp→isSet (squash₀ _ _))
λ a → cong ∣_∣₀ (GL.rCancel _)
| 30.333333
| 79
| 0.488226
|
4a702b49f482f5978ad8a379b08e1f90c2f48198
| 50,371
|
agda
|
Agda
|
archive/agda-1/Unify-monolithic.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/Unify-monolithic.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/Unify-monolithic.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
{- https://lists.chalmers.se/pipermail/agda/2013/006033.html http://code.haskell.org/~Saizan/unification/ 18-Nov-2013 Andrea Vezzosi -}
module Unify-monolithic where
-- some equivalences needed to adapt Tactic.Nat to the standard library
module EquivalenceOf≤ where
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
open import Data.Nat using (less-than-or-equal) renaming (_≤_ to _≤s_)
open import Data.Nat.Properties using (≤⇒≤″; ≤″⇒≤)
open import Prelude using (diff; id) renaming (_≤_ to _≤p_)
open import Tactic.Nat.Generic (quote _≤p_) (quote id) (quote id) using (by)
≤p→≤s : ∀ {a b} → a ≤p b → a ≤s b
≤p→≤s (diff k b₊₁≡k₊₁+a) = ≤″⇒≤ (less-than-or-equal {k = k} (by b₊₁≡k₊₁+a))
≤s→≤p : ∀ {a b} → a ≤s b → a ≤p b
≤s→≤p a≤sb with ≤⇒≤″ a≤sb
≤s→≤p _ | less-than-or-equal {k = k} a+k≡b = diff k (by a+k≡b)
module _ where
open EquivalenceOf≤
open import Data.Nat
open import Tactic.Nat.Generic (quote _≤_) (quote ≤s→≤p) (quote ≤p→≤s) public
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat hiding (_≤_)
--open import Relation.Binary.PropositionalEquality
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Function
open import Relation.Nullary
--open import Data.Product
open import Data.Product renaming (map to _***_)
open import Data.Empty
data Term (n : ℕ) : Set where
i : (x : Fin n) -> Term n
leaf : Term n
_fork_ : (s t : Term n) -> Term n
{-
data Term : ℕ -> Set where
i : ∀ ..{n} -> (x : Fin n) -> Term n
leaf : ∀ ..{n} -> Term n
_fork_ : ∀ ..{n} -> (s t : Term n) -> Term n
-}
_~>_ : (m n : ℕ) -> Set
m ~> n = Fin m -> Term n
▹ : ∀ {m n} -> (r : Fin m -> Fin n) -> Fin m -> Term n
▹ r = i ∘ r
_◃ : ∀ {m n} -> (f : m ~> n) -> Term m -> Term n
(f ◃ ) (i x) = f x
(f ◃ ) leaf = leaf
(f ◃ ) (s fork t) = (f ◃) s fork (f ◃) t
_◃_ : ∀ {m n} -> (f : m ~> n) -> Term m -> Term n
_◃_ = _◃
_≐_ : {m n : ℕ} -> (Fin m -> Term n) -> (Fin m -> Term n) -> Set
f ≐ g = ∀ x -> f x ≡ g x
◃ext : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> ∀ t -> f ◃ t ≡ g ◃ t
◃ext p (i x) = p x
◃ext p leaf = refl
◃ext p (s fork t) = cong₂ _fork_ (◃ext p s) (◃ext p t)
_◇_ : ∀ {l m n : ℕ } -> (f : Fin m -> Term n) (g : Fin l -> Term m) -> Fin l -> Term n
f ◇ g = (f ◃) ∘ g
≐-cong : ∀ {m n o} {f : m ~> n} {g} (h : _ ~> o) -> f ≐ g -> (h ◇ f) ≐ (h ◇ g)
≐-cong h f≐g t = cong (h ◃) (f≐g t)
≐-sym : ∀ {m n} {f : m ~> n} {g} -> f ≐ g -> g ≐ f
≐-sym f≐g = sym ∘ f≐g
module Sub where
fact1 : ∀ {n} -> (t : Term n) -> i ◃ t ≡ t
fact1 (i x) = refl
fact1 leaf = refl
fact1 (s fork t) = cong₂ _fork_ (fact1 s) (fact1 t)
fact2 : ∀ {l m n} -> (f : Fin m -> Term n) (g : _) (t : Term l)
-> (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
fact2 f g (i x) = refl
fact2 f g leaf = refl
fact2 f g (s fork t) = cong₂ _fork_ (fact2 f g s) (fact2 f g t)
fact3 : ∀ {l m n} (f : Fin m -> Term n) (r : Fin l -> Fin m) -> (f ◇ (▹ r)) ≡ (f ∘ r)
fact3 f r = refl -- ext (λ _ -> refl)
◃ext' : ∀ {m n o} {f : Fin m -> Term n}{g : Fin m -> Term o}{h} -> f ≐ (h ◇ g) -> ∀ t -> f ◃ t ≡ h ◃ (g ◃ t)
◃ext' p t = trans (◃ext p t) (Sub.fact2 _ _ t)
s : ℕ -> ℕ
s = suc
thin : ∀ {n} -> (x : Fin (s n)) (y : Fin n) -> Fin (s n)
thin zero y = suc y
thin (suc x) zero = zero
thin (suc x) (suc y) = suc (thin x y)
p : ∀ {n} -> Fin (suc (suc n)) -> Fin (suc n)
p (suc x) = x
p zero = zero
module Thin where
fact1 : ∀ {n} x y z -> thin {n} x y ≡ thin x z -> y ≡ z
fact1 zero y .y refl = refl
fact1 (suc x) zero zero r = refl
fact1 (suc x) zero (suc z) ()
fact1 (suc x) (suc y) zero ()
fact1 (suc x) (suc y) (suc z) r = cong suc (fact1 x y z (cong p r))
fact2 : ∀ {n} x y -> ¬ thin {n} x y ≡ x
fact2 zero y ()
fact2 (suc x) zero ()
fact2 (suc x) (suc y) r = fact2 x y (cong p r)
fact3 : ∀{n} x y -> ¬ x ≡ y -> ∃ λ y' -> thin {n} x y' ≡ y
fact3 zero zero ne = ⊥-elim (ne refl)
fact3 zero (suc y) _ = y , refl
fact3 {zero} (suc ()) _ _
fact3 {suc n} (suc x) zero ne = zero , refl
fact3 {suc n} (suc x) (suc y) ne with y | fact3 x y (ne ∘ cong suc)
... | .(thin x y') | y' , refl = suc y' , refl
open import Data.Maybe
open import Category.Functor
open import Category.Monad
import Level
open RawMonad (Data.Maybe.monad {Level.zero})
thick : ∀ {n} -> (x y : Fin (suc n)) -> Maybe (Fin n)
thick zero zero = nothing
thick zero (suc y) = just y
thick {zero} (suc ()) _
thick {suc _} (suc x) zero = just zero
thick {suc _} (suc x) (suc y) = suc <$> (thick x y)
open import Data.Sum
_≡Fin_ : ∀ {n} -> (x y : Fin n) -> Dec (x ≡ y)
zero ≡Fin zero = yes refl
zero ≡Fin suc y = no λ ()
suc x ≡Fin zero = no λ ()
suc {suc _} x ≡Fin suc y with x ≡Fin y
... | yes r = yes (cong suc r)
... | no r = no λ e -> r (cong p e)
suc {zero} () ≡Fin _
module Thick where
half1 : ∀ {n} (x : Fin (suc n)) -> thick x x ≡ nothing
half1 zero = refl
half1 {suc _} (suc x) = cong (_<$>_ suc) (half1 x)
half1 {zero} (suc ())
half2 : ∀ {n} (x : Fin (suc n)) y -> ∀ y' -> thin x y' ≡ y -> thick x y ≡ just y'
half2 zero zero y' ()
half2 zero (suc y) .y refl = refl
half2 {suc n} (suc x) zero zero refl = refl
half2 {suc _} (suc _) zero (suc _) ()
half2 {suc n} (suc x) (suc y) zero ()
half2 {suc n} (suc x) (suc .(thin x y')) (suc y') refl with thick x (thin x y') | half2 x (thin x y') y' refl
... | .(just y') | refl = refl
half2 {zero} (suc ()) _ _ _
fact1 : ∀ {n} (x : Fin (suc n)) y r
-> thick x y ≡ r
-> x ≡ y × r ≡ nothing ⊎ ∃ λ y' -> thin x y' ≡ y × r ≡ just y'
fact1 x y .(thick x y) refl with x ≡Fin y
fact1 x .x ._ refl | yes refl = inj₁ (refl , half1 x)
... | no el with Thin.fact3 x y el
... | y' , thinxy'=y = inj₂ (y' , ( thinxy'=y , half2 x y y' thinxy'=y ))
check : ∀{n} (x : Fin (suc n)) (t : Term (suc n)) -> Maybe (Term n)
check x (i y) = i <$> thick x y
check x leaf = just leaf
check x (s fork t) = _fork_ <$> check x s ⊛ check x t
_for_ : ∀ {n} (t' : Term n) (x : Fin (suc n)) -> Fin (suc n) -> Term n
(t' for x) y = maybe′ i t' (thick x y)
data AList : ℕ -> ℕ -> Set where
anil : ∀ {n} -> AList n n
_asnoc_/_ : ∀ {m n} (σ : AList m n) (t' : Term m) (x : Fin (suc m))
-> AList (suc m) n
alist≥ : ∀ m n → AList m n → m Data.Nat.≥ n
alist≥ m .m anil = {!!}
alist≥ .(suc _) n (x asnoc t' / x₁) with alist≥ _ _ x
… | r = {!!}
sub : ∀ {m n} (σ : AList m n) -> Fin m -> Term n
sub anil = i
sub (σ asnoc t' / x) = sub σ ◇ (t' for x)
_++_ : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> AList l n
ρ ++ anil = ρ
ρ ++ (σ asnoc t' / x) = (ρ ++ σ) asnoc t' / x
++-assoc : ∀ {l m n o} (ρ : AList l m) (σ : AList n _) (τ : AList o _) -> ρ ++ (σ ++ τ) ≡ (ρ ++ σ) ++ τ
++-assoc ρ σ anil = refl
++-assoc ρ σ (τ asnoc t / x) = cong (λ s -> s asnoc t / x) (++-assoc ρ σ τ)
module SubList where
anil-id-l : ∀ {m n} (σ : AList m n) -> anil ++ σ ≡ σ
anil-id-l anil = refl
anil-id-l (σ asnoc t' / x) = cong (λ σ -> σ asnoc t' / x) (anil-id-l σ)
fact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> sub (ρ ++ σ) ≐ (sub ρ ◇ sub σ)
fact1 ρ anil v = refl
fact1 {suc l} {m} {n} r (s asnoc t' / x) v = trans hyp-on-terms ◃-assoc
where
t = (t' for x) v
hyp-on-terms = ◃ext (fact1 r s) t
◃-assoc = Sub.fact2 (sub r) (sub s) t
_∃asnoc_/_ : ∀ {m} (a : ∃ (AList m)) (t' : Term m) (x : Fin (suc m))
-> ∃ (AList (suc m))
(n , σ) ∃asnoc t' / x = n , σ asnoc t' / x
flexFlex : ∀ {m} (x y : Fin m) -> ∃ (AList m)
flexFlex {suc m} x y with thick x y
... | just y' = m , anil asnoc i y' / x
... | nothing = suc m , anil
flexFlex {zero} () _
flexRigid : ∀ {m} (x : Fin m) (t : Term m) -> Maybe (∃(AList m))
flexRigid {suc m} x t with check x t
... | just t' = just (m , anil asnoc t' / x)
... | nothing = nothing
flexRigid {zero} () _
amgu : ∀ {m} (s t : Term m) (acc : ∃ (AList m)) -> Maybe (∃ (AList m))
amgu leaf leaf acc = just acc
amgu leaf (s' fork t') acc = nothing
amgu (s' fork t') leaf acc = nothing
amgu (s1 fork s2) (t1 fork t2) acc =
amgu s2 t2 =<< amgu s1 t1 acc
amgu (i x) (i y) (m , anil) = just (flexFlex x y)
amgu (i x) t (m , anil) = flexRigid x t
amgu t (i x) (m , anil) = flexRigid x t
amgu s t (n , σ asnoc r / z) =
(λ σ -> σ ∃asnoc r / z) <$>
amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ)
mgu : ∀ {m} -> (s t : Term m) -> Maybe (∃ (AList m))
mgu {m} s t = amgu s t (m , anil)
{-
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat hiding (_≤_)
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Function
open import Relation.Nullary
open import Data.Product renaming (map to _***_)
open import Data.Empty
-}
open import Data.Maybe using (maybe; maybe′; nothing; just; monad; Maybe)
open import Data.Sum
--open import Unify
open import Data.List renaming (_++_ to _++L_)
open ≡-Reasoning
open import Category.Functor
open import Category.Monad
import Level as L
--open RawMonad (Data.Maybe.monad {L.zero})
record Σ₁ (A : Set1) (F : A -> Set) : Set1 where
field
π₁ : A
π₂ : F π₁
_,,_ : ∀ {A F} (x : A) -> F x -> Σ₁ A F
x ,, b = record{ π₁ = x; π₂ = b }
open Σ₁
Property⋆ : (m : ℕ) -> Set1
Property⋆ m = ∀ {n} -> (Fin m -> Term n) -> Set
Extensional : {m : ℕ} -> Property⋆ m -> Set
Extensional P = ∀ {m f g} -> f ≐ g -> P {m} f -> P g
Property : (m : ℕ) -> Set1
Property m = Σ₁ (Property⋆ m) Extensional
prop-id : ∀ {m n} {f : _ ~> n} {P : Property m} -> π₁ P f -> π₁ P (i ◇ f)
prop-id {_} {_} {f} {P'} Pf = π₂ P' (λ x → sym (Sub.fact1 (f x))) Pf
Unifies⋆ : ∀ {m} (s t : Term m) -> Property⋆ m
Unifies⋆ s t f = f ◃ s ≡ f ◃ t
Unifies : ∀ {m} (s t : Term m) -> Property m
Unifies s t = (λ {_} -> Unifies⋆ s t) ,, λ {_} {f} {g} f≐g f◃s=f◃t ->
begin
g ◃ s
≡⟨ sym (◃ext f≐g s) ⟩
f ◃ s
≡⟨ f◃s=f◃t ⟩
f ◃ t
≡⟨ ◃ext f≐g t ⟩
g ◃ t
∎
_∧⋆_ : ∀{m} -> (P Q : Property⋆ m) -> Property⋆ m
P ∧⋆ Q = (λ f -> P f × Q f)
_∧_ : ∀{m} -> (P Q : Property m) -> Property m
P ∧ Q = (λ {_} f -> π₁ P f × π₁ Q f) ,, λ {_} {_} {_} f≐g Pf×Qf -> π₂ P f≐g (proj₁ Pf×Qf) , π₂ Q f≐g (proj₂ Pf×Qf)
_⇔⋆_ : ∀{m} -> (P Q : Property⋆ m) -> Set
P ⇔⋆ Q = ∀ {n} f -> (P {n} f -> Q f) × (Q f -> P f)
_⇔_ : ∀{m} -> (P Q : Property m) -> Set
P ⇔ Q = ∀ {n} f -> (π₁ P {n} f -> π₁ Q f) × (π₁ Q f -> π₁ P f)
switch⋆ : ∀ {m} (P Q : Property⋆ m) -> P ⇔⋆ Q -> Q ⇔⋆ P
switch⋆ _ _ P⇔Q f = proj₂ (P⇔Q f) , proj₁ (P⇔Q f)
switch : ∀ {m} (P Q : Property m) -> P ⇔ Q -> Q ⇔ P
switch _ _ P⇔Q f = proj₂ (P⇔Q f) , proj₁ (P⇔Q f)
Nothing⋆ : ∀{m} -> (P : Property⋆ m) -> Set
Nothing⋆ P = ∀{n} f -> P {n} f -> ⊥
Nothing : ∀{m} -> (P : Property m) -> Set
Nothing P = ∀{n} f -> π₁ P {n} f -> ⊥
_[-◇⋆_] : ∀{m n} (P : Property⋆ m) (f : Fin m -> Term n) -> Property⋆ n
(P [-◇⋆ f ]) g = P (g ◇ f)
_[-◇_] : ∀{m n} (P : Property m) (f : Fin m -> Term n) -> Property n
P [-◇ f ] = (λ {_} g -> π₁ P (g ◇ f)) ,, λ {_} {f'} {g'} f'≐g' Pf'◇f -> π₂ P (◃ext f'≐g' ∘ f) Pf'◇f
module Properties where
fact1 : ∀ {m} {s t : Term m} -> (Unifies s t) ⇔ (Unifies t s)
fact1 _ = sym , sym
fact1'⋆ : ∀ {m} {s1 s2 t1 t2 : Term m}
-> Unifies⋆ (s1 fork s2) (t1 fork t2) ⇔⋆ (Unifies⋆ s1 t1 ∧⋆ Unifies⋆ s2 t2)
fact1'⋆ f = deconstr _ _ _ _ , uncurry (cong₂ _fork_)
where deconstr : ∀ {m} (s1 s2 t1 t2 : Term m)
-> (s1 fork s2) ≡ (t1 fork t2)
-> (s1 ≡ t1) × (s2 ≡ t2)
deconstr s1 s2 .s1 .s2 refl = refl , refl
fact1' : ∀ {m} {s1 s2 t1 t2 : Term m}
-> Unifies (s1 fork s2) (t1 fork t2) ⇔ (Unifies s1 t1 ∧ Unifies s2 t2)
fact1' f = deconstr _ _ _ _ , uncurry (cong₂ _fork_)
where deconstr : ∀ {m} (s1 s2 t1 t2 : Term m)
-> (s1 fork s2) ≡ (t1 fork t2)
-> (s1 ≡ t1) × (s2 ≡ t2)
deconstr s1 s2 .s1 .s2 refl = refl , refl
fact2⋆ : ∀ {m} (P Q : Property⋆ m) -> P ⇔⋆ Q -> Nothing⋆ P -> Nothing⋆ Q
fact2⋆ P Q iff notp f q with iff f
... | (p2q , q2p) = notp f (q2p q)
fact2 : ∀ {m} (P Q : Property m) -> P ⇔ Q -> Nothing P -> Nothing Q
fact2 P Q iff notp f q with iff f
... | (p2q , q2p) = notp f (q2p q)
fact3 : ∀ {m} {P : Property m} -> P ⇔ (P [-◇ i ])
fact3 f = id , id
fact4 : ∀{m n} {P : Property m} (f : _ -> Term n)
-> Nothing P -> Nothing (P [-◇ f ])
fact4 f nop g = nop (g ◇ f)
fact5⋆ : ∀{m n} (P Q : Property⋆ _) (f : m ~> n) -> P ⇔⋆ Q -> (P [-◇⋆ f ]) ⇔⋆ (Q [-◇⋆ f ])
fact5⋆ _ _ f P⇔Q f' = P⇔Q (f' ◇ f)
fact5 : ∀{m n} (P Q : Property _) (f : m ~> n) -> P ⇔ Q -> (P [-◇ f ]) ⇔ (Q [-◇ f ])
fact5 _ _ f P⇔Q f' = P⇔Q (f' ◇ f)
fact6 : ∀{m n} P {f g : m ~> n} -> f ≐ g -> (P [-◇ f ]) ⇔ (P [-◇ g ])
fact6 P f≐g h = π₂ P (≐-cong h f≐g) , π₂ P (≐-sym (≐-cong h f≐g))
{-
fact5 : ∀ {l m n} {f : Fin n -> Term l} {g : Fin m -> Term n}
{P : Property _ }
-> (P [-◇ g ]) [-◇ f ] ⇔ P [-◇ (f ◇ g) ]
fact5 h = {!!} , {!!}
-}
_≤_ : ∀ {m n n'} (f : Fin m -> Term n) (g : Fin m -> Term n') -> Set
f ≤ g = ∃ λ f' -> f ≐ (f' ◇ g)
module Order where
reflex : ∀ {m n} {f : Fin m -> Term n} -> f ≤ f
reflex = i , λ _ -> sym (Sub.fact1 _)
transitivity : ∀ {l m n o} {f : Fin l -> Term m}{g : _ -> Term n}
{h : _ -> Term o}
-> f ≤ g -> g ≤ h -> f ≤ h
transitivity {l} {_} {_} {_} {f} {g} {h} (fg , pfg) (gh , pgh) =
fg ◇ gh , proof
where
proof : (x : Fin l) → f x ≡ (λ x' → fg ◃ (gh x')) ◃ (h x)
proof x = trans z (sym (Sub.fact2 fg gh (h x)))
where z = trans (pfg x) (cong (fg ◃) (pgh x))
i-max : ∀ {m n} (f : Fin m -> Term n) -> f ≤ i
i-max f = f , λ _ -> refl
dist : ∀{l m n o}{f : Fin l -> Term m}{g : _ -> Term n}(h : Fin o -> _) -> f ≤ g -> (f ◇ h) ≤ (g ◇ h)
dist h (fg , pfg) = fg , λ x -> trans (◃ext pfg (h x)) (Sub.fact2 _ _ (h x))
Max⋆ : ∀ {m} (P : Property⋆ m) -> Property⋆ m
Max⋆ P f = P f × (∀ {n} f' -> P {n} f' -> f' ≤ f)
Max : ∀ {m} (P : Property m) -> Property m
Max P' = (λ {_} → Max⋆ P) ,, λ {_} {_} {_} -> lemma1
where
open Σ₁ P' renaming (π₁ to P; π₂ to Peq)
lemma1 : {m : ℕ} {f : Fin _ → Term m} {g : Fin _ → Term m} →
f ≐ g →
P f × ({n : ℕ} (f' : Fin _ → Term n) → P f' → f' ≤ f) →
P g × ({n : ℕ} (f' : Fin _ → Term n) → P f' → f' ≤ g)
lemma1 {_} {f} {g} f≐g (Pf , MaxPf) = Peq f≐g Pf , λ {_} -> lemma2
where
lemma2 : ∀ {n} f' → P {n} f' → ∃ λ f0 → f' ≐ (f0 ◇ g)
lemma2 f' Pf' = f0 , λ x -> trans (f'≐f0◇f x) (cong (f0 ◃) (f≐g x))
where
f0 = proj₁ (MaxPf f' Pf')
f'≐f0◇f = proj₂ (MaxPf f' Pf')
module Max where
fact : ∀{m}(P Q : Property m) -> P ⇔ Q -> Max P ⇔ Max Q
fact {m} P Q a f =
(λ maxp → pq (proj₁ maxp) , λ f' → proj₂ maxp f' ∘ qp)
, λ maxq → qp (proj₁ maxq) , λ f' → proj₂ maxq f' ∘ pq
where
pq : {n : ℕ} {f0 : Fin m → Term n} → (π₁ P f0 → π₁ Q f0)
pq {_} {f} = proj₁ (a f)
qp : {n : ℕ} {f0 : Fin m → Term n} → (π₁ Q f0 → π₁ P f0)
qp {_} {f} = proj₂ (a f)
DClosed : ∀{m} (P : Property m) -> Set
DClosed P = ∀ {n} f {o} g -> f ≤ g -> π₁ P {o} g -> π₁ P {n} f
module DClosed where
fact1 : ∀ {m} s t -> DClosed {m} (Unifies s t)
fact1 s t f g (f≤g , p) gs=gt =
begin
f ◃ s
≡⟨ ◃ext' p s ⟩
f≤g ◃ (g ◃ s)
≡⟨ cong (f≤g ◃) gs=gt ⟩
f≤g ◃ (g ◃ t)
≡⟨ sym (◃ext' p t) ⟩
f ◃ t
∎
optimist : ∀ {l m n o} (a : Fin _ -> Term n) (p : Fin _ -> Term o)
(q : Fin _ -> Term l) (P Q : Property m)
-> DClosed P -> π₁ (Max (P [-◇ a ])) p
-> π₁ (Max (Q [-◇ (p ◇ a) ])) q
-> π₁ (Max ((P ∧ Q) [-◇ a ])) (q ◇ p)
optimist a p q P' Q' DCP (Ppa , pMax) (Qqpa , qMax) =
(Peq (sym ∘ (Sub.fact2 _ _) ∘ a) (DCP (q ◇ (p ◇ a)) (p ◇ a) (q , λ _ -> refl) Ppa)
, Qeq (sym ∘ (Sub.fact2 _ _) ∘ a) Qqpa )
, λ {_} -> aux
where
open Σ₁ P' renaming (π₁ to P; π₂ to Peq)
open Σ₁ Q' renaming (π₁ to Q; π₂ to Qeq)
aux : ∀ {n} (f : _ -> Term n) -> P (f ◇ a) × Q (f ◇ a) -> f ≤ (q ◇ p)
aux f (Pfa , Qfa) = h ,
λ x -> trans (f≐g◇p x) (◃ext' g≐h◇q (p x))
where
one = pMax f Pfa
g = proj₁ one
f≐g◇p = proj₂ one
Qgpa : Q (g ◇ (p ◇ a))
Qgpa = Qeq (λ x -> ◃ext' f≐g◇p (a x)) Qfa
g≤q = qMax g Qgpa
h = proj₁ g≤q
g≐h◇q = proj₂ g≤q
module failure-propagation where
first⋆ : ∀ {m n} (a : _ ~> n) (P Q : Property⋆ m) ->
Nothing⋆ (P [-◇⋆ a ]) -> Nothing⋆ ((P ∧⋆ Q) [-◇⋆ a ])
first⋆ a P' Q' noP-a f (Pfa , Qfa) = noP-a f Pfa
first : ∀ {m n} (a : _ ~> n) (P Q : Property m) ->
Nothing (P [-◇ a ]) -> Nothing ((P ∧ Q) [-◇ a ])
first a P' Q' noP-a f (Pfa , Qfa) = noP-a f Pfa
{-
second⋆ : ∀ {m n o} (a : _ ~> n) (p : _ ~> o)(P Q : Property⋆ m) ->
(Max⋆ (P [-◇⋆ a ])) p -> Nothing⋆ (Q [-◇⋆ (p ◇ a)])
-> Nothing⋆ ((P ∧⋆ Q) [-◇⋆ a ])
second⋆ a p P' Q' (Ppa , pMax) noQ-p◇a f (Pfa , Qfa) = noQ-p◇a g Qgpa
where
f≤p = pMax f Pfa
g = proj₁ f≤p
f≐g◇p = proj₂ f≤p
Qgpa : Q' (g ◇ (p ◇ a))
Qgpa = {!!}
{-
noQ-p◇a g Qgpa
where
f≤p = pMax f Pfa
g = proj₁ f≤p
f≐g◇p = proj₂ f≤p
Qgpa : π₁ Q' (g ◇ (p ◇ a))
Qgpa = π₂ Q' (◃ext' f≐g◇p ∘ a) Qfa
-}
-}
second⋆ : ∀ {m n o} (a : _ ~> n) (p : _ ~> o)(P : Property⋆ m)(Q : Property m) ->
(Max⋆ (P [-◇⋆ a ])) p -> Nothing⋆ (π₁ Q [-◇⋆ (p ◇ a)])
-> Nothing⋆ ((P ∧⋆ π₁ Q) [-◇⋆ a ])
second⋆ a p P' Q' (Ppa , pMax) noQ-p◇a f (Pfa , Qfa) = noQ-p◇a g Qgpa
where
f≤p = pMax f Pfa
g = proj₁ f≤p
f≐g◇p = proj₂ f≤p
Qgpa : π₁ Q' (g ◇ (p ◇ a))
Qgpa = π₂ Q' (◃ext' f≐g◇p ∘ a) Qfa
second : ∀ {m n o} (a : _ ~> n) (p : _ ~> o)(P Q : Property m) ->
π₁ (Max (P [-◇ a ])) p -> Nothing (Q [-◇ (p ◇ a)])
-> Nothing ((P ∧ Q) [-◇ a ])
second a p P' Q' (Ppa , pMax) noQ-p◇a f (Pfa , Qfa) =
noQ-p◇a g Qgpa
where
f≤p = pMax f Pfa
g = proj₁ f≤p
f≐g◇p = proj₂ f≤p
Qgpa : π₁ Q' (g ◇ (p ◇ a))
Qgpa = π₂ Q' (◃ext' f≐g◇p ∘ a) Qfa
trivial-problem : ∀ {m n t} {f : m ~> n} -> π₁ (Max ((Unifies t t) [-◇ f ])) i
trivial-problem = refl , λ f' _ → f' , λ _ → refl
var-elim : ∀ {m} (x : Fin (suc m)) (t' : Term _)
-> π₁ (Max ((Unifies (i x) ((▹ (thin x) ◃) t')))) (t' for x)
var-elim x t' = first , \{_} -> second
where
lemma : ∀{m}(x : Fin (suc m)) t → i ≐ ((t for x) ◇ (▹ (thin x)))
lemma x t x' = sym (cong (maybe i t) (Thick.half2 x _ x' refl))
first = begin
(t' for x) ◃ (i x) ≡⟨ cong (maybe i t') (Thick.half1 x) ⟩
t' ≡⟨ sym (Sub.fact1 t') ⟩
i ◃ t' ≡⟨ ◃ext' (lemma x t') t' ⟩
(t' for x) ◃ ((▹ (thin x) ◃) t') ∎
second : ∀ {n} (f : _ ~> n) → f x ≡ f ◃ ((▹ (thin x) ◃) t') → f ≤ (t' for x)
second f Unifiesf = (f ∘ thin x) , third
where
third : ((x' : Fin _) → f x' ≡ (f ∘ thin x) ◃ (maybe′ i t' (thick x x')))
third x' with thick x x' | Thick.fact1 x x' (thick x x') refl
third .x | .nothing | inj₁ (refl , refl) =
sym (begin
(f ∘ thin x) ◃ t' ≡⟨ cong (λ g -> (g ◃) t') (sym (Sub.fact3 f (thin x))) ⟩
(f ◇ (▹ (thin x))) ◃ t' ≡⟨ Sub.fact2 f (▹ (thin x)) t' ⟩
f ◃ ((▹ (thin x) ◃) t') ≡⟨ sym Unifiesf ⟩
f x ∎)
third x' | .(just y) | inj₂ (y , ( thinxy≡x' , refl)) = sym (cong f thinxy≡x')
var-elim-i : ∀ {m} (x : Fin (suc m)) (t' : Term _)
-> π₁ (Max ((Unifies (i x) ((▹ (thin x) ◃) t')))) (i ◇ (t' for x))
var-elim-i {m} x t = prop-id {_} {_} {t for x} {Max (Unifies (i x) ((▹ (thin x) ◃) t))} (var-elim {m} x t)
var-elim-i-≡ : ∀ {m} {t'} (x : Fin (suc m)) t1 -> t1 ≡ (i ∘ thin x) ◃ t' -> π₁ (Max (Unifies (i x) t1)) (i ◇ (t' for x))
var-elim-i-≡ {_} {t'} x .((i ∘ thin x) ◃ t') refl = var-elim-i x t'
data Step (n : ℕ) : Set where
left : Term n -> Step n
right : Term n -> Step n
fmapS : ∀ {n m} (f : Term n -> Term m) (s : Step n) -> Step m
fmapS f (left x) = left (f x)
fmapS f (right x) = right (f x)
_⊹_ : ∀ {n} (ps : List (Step n)) (t : Term n) -> Term n
[] ⊹ t = t
(left r ∷ ps) ⊹ t = (ps ⊹ t) fork r
(right l ∷ ps) ⊹ t = l fork (ps ⊹ t)
_◃S : ∀ {n m} (f : n ~> m) -> List (Step n) -> List (Step m)
_◃S f = Data.List.map (fmapS (f ◃))
map-[] : ∀ {n m} (f : n ~> m) ps -> (f ◃S) ps ≡ [] -> ps ≡ []
map-[] f [] _ = refl
map-[] f (x ∷ xs) ()
module StepM where
lemma1 : ∀ {n} (x : Step n) xs t -> [ x ] ⊹ ( xs ⊹ t ) ≡ (x ∷ xs) ⊹ t
lemma1 (left y) xs t = refl
lemma1 (right y) xs t = refl
lemma2 : ∀ {n} {r} {t} {xs} (x : Step n) -> xs ⊹ t ≡ r -> ((x ∷ xs) ⊹ t ) ≡ [ x ] ⊹ r
lemma2 (left y) eq = cong (λ t -> t fork y) eq
lemma2 (right y) eq = cong (λ t -> y fork t) eq
fact1 : ∀ {n} ps qs (t : Term n) -> (ps ++L qs) ⊹ t ≡ ps ⊹ (qs ⊹ t)
fact1 [] qs t = refl
fact1 (p ∷ ps) qs t = begin (p ∷ (ps ++L qs)) ⊹ t ≡⟨ lemma2 p (fact1 ps qs t) ⟩
[ p ] ⊹ (ps ⊹ (qs ⊹ t)) ≡⟨ lemma1 p ps (qs ⊹ t) ⟩
(p ∷ ps) ⊹ (qs ⊹ t) ∎
fact2 : ∀ {m n} (f : m ~> n) t ps ->
f ◃ (ps ⊹ t) ≡ (f ◃S) ps ⊹ (f ◃ t)
fact2 f t [] = refl
fact2 f t (left y ∷ xs) = cong (λ t -> t fork (f ◃ y)) (fact2 f t xs)
fact2 f t (right y ∷ xs) = cong (λ t -> (f ◃ y) fork t) (fact2 f t xs)
check-prop : ∀ {m} (x : Fin (suc m)) t ->
(∃ λ t' -> t ≡ (▹ (thin x) ◃) t' × check x t ≡ just t')
⊎ (∃ λ ps -> t ≡ (ps ⊹ i x) × check x t ≡ nothing)
check-prop x (i x') with Thick.fact1 x x' (thick x x') refl
check-prop x (i .x) | inj₁ (refl , e) = inj₂ ([] , refl , cong (_<$>_ i) e)
... | inj₂ (y , thinxy≡x' , thickxx'≡justy')
= inj₁ (i y
, cong i (sym (thinxy≡x'))
, cong (_<$>_ i) thickxx'≡justy' )
check-prop x leaf = inj₁ (leaf , (refl , refl))
check-prop x (s fork t)
with check-prop x s | check-prop x t
... | inj₁ (s' , s≡thinxs' , checkxs≡s') | inj₁ (t' , t≡thinxt' , checkxt≡t')
= inj₁ (s' fork t' , cong₂ _fork_ s≡thinxs' t≡thinxt'
, cong₂ (λ a b -> _fork_ <$> a ⊛ b) checkxs≡s' checkxt≡t' )
... | inj₂ (ps , s≡ps+ix , checkxs≡no ) | _
= inj₂ (left t ∷ ps , cong (λ s -> s fork t) s≡ps+ix
, cong (λ a -> _fork_ <$> a ⊛ check x t) checkxs≡no )
... | _ | inj₂ (ps , s≡ps+ix , checkxs≡no )
= inj₂ (right s ∷ ps , cong (λ t -> s fork t) s≡ps+ix
, trans (cong (λ a -> _fork_ <$> check x s ⊛ a) checkxs≡no) (lemma (_fork_ <$> check x s)))
where
lemma : ∀ {a b : Set} {y : b} (x : Maybe a) -> maybe (λ _ → y) y x ≡ y
lemma (just x') = refl
lemma nothing = refl
fork++ : ∀ {m} {s t : Term m} ps ->
(ps ⊹ (s fork t) ≡ (ps ++L [ left t ]) ⊹ s)
× (ps ⊹ (s fork t) ≡ (ps ++L [ right s ]) ⊹ t)
fork++ [] = refl , refl
fork++ (left y' ∷ xs') = (cong (λ a -> a fork y') *** cong (λ a -> a fork y')) (fork++ xs')
fork++ (right y' ∷ xs') = (cong (λ a -> y' fork a) *** cong (λ a -> y' fork a)) (fork++ xs')
No-Cycle : ∀{m} (t : Term m) ps -> t ≡ ps ⊹ t -> ps ≡ []
No-Cycle _ [] refl = refl
No-Cycle (i x) (left _ ∷ xs) ()
No-Cycle leaf (left y ∷ xs) ()
No-Cycle {m} (s fork t) (left y ∷ xs) r = proof
where f : Term m -> Term m
f (s fork t) = s
f _ = s
hyp : xs ++L [ left t ] ≡ []
hyp = No-Cycle s (xs ++L [ left t ]) (trans (cong f r) (proj₁ (fork++ xs)))
proof : left y ∷ xs ≡ []
proof = case (_,_ {B = λ x → x ++L _ ≡ _} xs hyp) of λ { ([] , ()) ; (_ ∷ _ , ()) }
No-Cycle (i x) (right _ ∷ xs) ()
No-Cycle leaf (right _ ∷ xs) ()
No-Cycle {m} (s fork t) (right y ∷ xs) r = proof
where f : Term m -> Term m
f (s fork t) = t
f _ = s
hyp = No-Cycle t (xs ++L [ right s ]) (trans (cong f r) (proj₂ (fork++ xs)))
proof : right y ∷ xs ≡ []
proof = case (_,_ {B = λ x → x ++L _ ≡ _} xs hyp) of λ { ([] , ()) ; (_ ∷ _ , ()) }
module Step2 where
fact : ∀{m} (x : Fin m) p ps -> Nothing (Unifies (i x) ((p ∷ ps) ⊹ i x))
fact x p ps f r with No-Cycle (f x) ((f ◃S) (p ∷ ps)) (trans r (StepM.fact2 f (i x) (p ∷ ps)))
... | ()
◇-assoc : ∀ {l m n o} (f : l ~> m) (g : n ~> _) (h : o ~> _) ->
(f ◇ (g ◇ h)) ≐ ((f ◇ g) ◇ h)
◇-assoc f g h x = sym (Sub.fact2 f g (h x))
bind-assoc : ∀ {l m n o} (f : l ~> m) (g : n ~> _) (h : o ~> _) t -> (f ◇ g) ◃ (h ◃ t) ≡ (f ◇ (g ◇ h)) ◃ t
bind-assoc f g h t = sym (begin
(f ◇ (g ◇ h)) ◃ t ≡⟨ ◃ext (◇-assoc f g h) t ⟩
((f ◇ g) ◇ h) ◃ t ≡⟨ Sub.fact2 (f ◇ g) h t ⟩
(f ◇ g) ◃ (h ◃ t)
∎)
step-prop : ∀ {m n} (s t : Term (suc m)) (σ : AList m n) r z ->
(Unifies s t [-◇ sub (σ asnoc r / z) ]) ⇔ (Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub σ ])
step-prop s t σ r z f = to , from
where
lemma1 : ∀ t -> (f ◇ sub σ) ◃ ((r for z) ◃ t) ≡ (f ◇ (sub σ ◇ (r for z))) ◃ t
lemma1 t = bind-assoc f (sub σ) (r for z) t
to = λ a → begin
(f ◇ sub σ) ◃ ((r for z) ◃ s) ≡⟨ lemma1 s ⟩
(f ◇ (sub σ ◇ (r for z))) ◃ s ≡⟨ a ⟩
(f ◇ (sub σ ◇ (r for z))) ◃ t ≡⟨ sym (lemma1 t) ⟩
(f ◇ sub σ) ◃ ((r for z) ◃ t) ∎
from = λ a → begin
(f ◇ (sub σ ◇ (r for z))) ◃ s ≡⟨ sym (lemma1 s) ⟩
(f ◇ sub σ) ◃ ((r for z) ◃ s) ≡⟨ a ⟩
(f ◇ sub σ) ◃ ((r for z) ◃ t) ≡⟨ lemma1 t ⟩
(f ◇ (sub σ ◇ (r for z))) ◃ t ∎
-- We use a view so that we need to handle fewer cases in the main proof
data Amgu : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Maybe (∃ (AList m)) -> Set where
Flip : ∀ {m s t acc} -> amgu t s acc ≡ amgu s t acc ->
Amgu {m} t s acc (amgu t s acc) -> Amgu s t acc (amgu s t acc)
leaf-leaf : ∀ {m acc} -> Amgu {m} leaf leaf acc (just acc)
leaf-fork : ∀ {m s t acc} -> Amgu {m} leaf (s fork t) acc nothing
fork-fork : ∀ {m s1 s2 t1 t2 acc} -> Amgu {m} (s1 fork s2) (t1 fork t2) acc (amgu s2 t2 =<< amgu s1 t1 acc)
var-var : ∀ {m x y} -> Amgu (i x) (i y) (m , anil) (just (flexFlex x y))
var-t : ∀ {m x t} -> i x ≢ t -> Amgu (i x) t (m , anil) (flexRigid x t)
s-t : ∀{m s t n σ r z} -> Amgu {suc m} s t (n , σ asnoc r / z) ((λ σ -> σ ∃asnoc r / z) <$>
amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ))
view : ∀ {m : ℕ} -> (s t : Term m) -> (acc : ∃ (AList m)) -> Amgu s t acc (amgu s t acc)
view leaf leaf acc = leaf-leaf
view leaf (s fork t) acc = leaf-fork
view (s fork t) leaf acc = Flip refl leaf-fork
view (s1 fork s2) (t1 fork t2) acc = fork-fork
view (i x) (i y) (m , anil) = var-var
view (i x) leaf (m , anil) = var-t (λ ())
view (i x) (s fork t) (m , anil) = var-t (λ ())
view leaf (i x) (m , anil) = Flip refl (var-t (λ ()))
view (s fork t) (i x) (m , anil) = Flip refl (var-t (λ ()))
view (i x) (i x') (n , σ asnoc r / z) = s-t
view (i x) leaf (n , σ asnoc r / z) = s-t
view (i x) (s fork t) (n , σ asnoc r / z) = s-t
view leaf (i x) (n , σ asnoc r / z) = s-t
view (s fork t) (i x) (n , σ asnoc r / z) = s-t
amgu-Correctness : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Set
amgu-Correctness s t (l , ρ) =
(∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t [-◇ sub ρ ])) (sub σ) × amgu s t (l , ρ) ≡ just (n , σ ++ ρ ))
⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu s t (l , ρ) ≡ nothing)
amgu-Correctness⋆ : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Set
amgu-Correctness⋆ s t (l , ρ) =
(∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t [-◇ sub ρ ])) (sub σ) × amgu s t (l , ρ) ≡ just (n , σ ++ ρ ))
⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu s t (l , ρ) ≡ nothing)
amgu-Ccomm : ∀ {m} s t acc -> amgu {m} s t acc ≡ amgu t s acc -> amgu-Correctness s t acc -> amgu-Correctness t s acc
amgu-Ccomm s t (l , ρ) st≡ts = lemma
where
Unst = (Unifies s t) [-◇ sub ρ ]
Unts = (Unifies t s) [-◇ sub ρ ]
Unst⇔Unts : ((Unifies s t) [-◇ sub ρ ]) ⇔ ((Unifies t s) [-◇ sub ρ ])
Unst⇔Unts = Properties.fact5 (Unifies s t) (Unifies t s) (sub ρ) (Properties.fact1 {_} {s} {t})
lemma : amgu-Correctness s t (l , ρ) -> amgu-Correctness t s (l , ρ)
lemma (inj₁ (n , σ , MaxUnst , amgu≡just)) =
inj₁ (n , σ , proj₁ (Max.fact Unst Unts Unst⇔Unts (sub σ)) MaxUnst , trans (sym st≡ts) amgu≡just)
lemma (inj₂ (NoUnst , amgu≡nothing)) =
inj₂ ((λ {_} → Properties.fact2 Unst Unts Unst⇔Unts NoUnst) , trans (sym st≡ts) amgu≡nothing)
amgu-Ccomm⋆ : ∀ {m} s t acc -> amgu {m} s t acc ≡ amgu t s acc -> amgu-Correctness⋆ s t acc -> amgu-Correctness⋆ t s acc
amgu-Ccomm⋆ s t (l , ρ) st≡ts = lemma
where
Unst = (Unifies s t) [-◇ sub ρ ]
Unts = (Unifies t s) [-◇ sub ρ ]
Unst⇔Unts : ((Unifies s t) [-◇ sub ρ ]) ⇔ ((Unifies t s) [-◇ sub ρ ])
Unst⇔Unts = Properties.fact5 (Unifies s t) (Unifies t s) (sub ρ) (Properties.fact1 {_} {s} {t})
lemma : amgu-Correctness s t (l , ρ) -> amgu-Correctness t s (l , ρ)
lemma (inj₁ (n , σ , MaxUnst , amgu≡just)) =
inj₁ (n , σ , proj₁ (Max.fact Unst Unts Unst⇔Unts (sub σ)) MaxUnst , trans (sym st≡ts) amgu≡just)
lemma (inj₂ (NoUnst , amgu≡nothing)) =
inj₂ ((λ {_} → Properties.fact2 Unst Unts Unst⇔Unts NoUnst) , trans (sym st≡ts) amgu≡nothing)
amgu-c : ∀ {m s t l ρ} -> Amgu s t (l , ρ) (amgu s t (l , ρ)) ->
(∃ λ n → ∃ λ σ → π₁ (Max ((Unifies s t) [-◇ sub ρ ])) (sub σ) × amgu {m} s t (l , ρ) ≡ just (n , σ ++ ρ ))
⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu {m} s t (l , ρ) ≡ nothing)
amgu-c {m} {s} {t} {l} {ρ} amg with amgu s t (l , ρ)
amgu-c {l = l} {ρ} leaf-leaf | ._
= inj₁ (l , anil , trivial-problem {_} {_} {leaf} {sub ρ} , cong (λ x -> just (l , x)) (sym (SubList.anil-id-l ρ)) )
amgu-c leaf-fork | .nothing = inj₂ ((λ _ () ) , refl)
amgu-c {m} {s1 fork s2} {t1 fork t2} {l} {ρ} fork-fork | ._
with amgu s1 t1 (l , ρ) | amgu-c $ view s1 t1 (l , ρ)
... | .nothing | inj₂ (nounify , refl) = inj₂ ((λ {_} -> No[Q◇ρ]→No[P◇ρ] No[Q◇ρ]) , refl)
where
P = Unifies (s1 fork s2) (t1 fork t2)
Q = (Unifies s1 t1 ∧ Unifies s2 t2)
Q⇔P : Q ⇔ P
Q⇔P = switch P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2})
No[Q◇ρ]→No[P◇ρ] : Nothing (Q [-◇ sub ρ ]) -> Nothing (P [-◇ sub ρ ])
No[Q◇ρ]→No[P◇ρ] = Properties.fact2 (Q [-◇ sub ρ ]) (P [-◇ sub ρ ]) (Properties.fact5 Q P (sub ρ) Q⇔P)
No[Q◇ρ] : Nothing (Q [-◇ sub ρ ])
No[Q◇ρ] = failure-propagation.first (sub ρ) (Unifies s1 t1) (Unifies s2 t2) nounify
... | .(just (n , σ ++ ρ)) | inj₁ (n , σ , a , refl)
with amgu s2 t2 (n , σ ++ ρ) | amgu-c (view s2 t2 (n , (σ ++ ρ)))
... | .nothing | inj₂ (nounify , refl) = inj₂ ( (λ {_} -> No[Q◇ρ]→No[P◇ρ] No[Q◇ρ]) , refl)
where
P = Unifies (s1 fork s2) (t1 fork t2)
Q = (Unifies s1 t1 ∧ Unifies s2 t2)
Q⇔P : Q ⇔ P
Q⇔P = switch P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2})
No[Q◇ρ]→No[P◇ρ] : Nothing (Q [-◇ sub ρ ]) -> Nothing (P [-◇ sub ρ ])
No[Q◇ρ]→No[P◇ρ] = Properties.fact2 (Q [-◇ sub ρ ]) (P [-◇ sub ρ ]) (Properties.fact5 Q P (sub ρ) Q⇔P)
No[Q◇ρ] : Nothing (Q [-◇ sub ρ ])
No[Q◇ρ] = failure-propagation.second (sub ρ) (sub σ) (Unifies s1 t1) (Unifies s2 t2) a
(λ f Unifs2t2-f◇σ◇ρ → nounify f (π₂ (Unifies s2 t2) (λ t → cong (f ◃) (sym (SubList.fact1 σ ρ t))) Unifs2t2-f◇σ◇ρ))
... | .(just (n1 , σ1 ++ (σ ++ ρ))) | inj₁ (n1 , σ1 , b , refl)
= inj₁ (n1 , σ1 ++ σ , Max[P∧Q◇ρ][σ1++σ] , cong (λ σ -> just (n1 , σ)) (++-assoc σ1 σ ρ))
where
P = Unifies s1 t1
Q = Unifies s2 t2
P∧Q = P ∧ Q
C = Unifies (s1 fork s2) (t1 fork t2)
Max[C◇ρ]⇔Max[P∧Q◇ρ] : Max (C [-◇ sub ρ ]) ⇔ Max (P∧Q [-◇ sub ρ ])
Max[C◇ρ]⇔Max[P∧Q◇ρ] = Max.fact (C [-◇ sub ρ ]) (P∧Q [-◇ sub ρ ]) (Properties.fact5 C P∧Q (sub ρ)
(Properties.fact1' {_} {s1} {s2} {t1} {t2}))
Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] : Max (Q [-◇ sub (σ ++ ρ)]) ⇔ Max (Q [-◇ sub σ ◇ sub ρ ])
Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] = Max.fact (Q [-◇ sub (σ ++ ρ)]) (Q [-◇ sub σ ◇ sub ρ ]) (Properties.fact6 Q (SubList.fact1 σ ρ))
Max[P∧Q◇ρ][σ1++σ] : π₁ (Max (C [-◇ sub ρ ])) (sub (σ1 ++ σ))
Max[P∧Q◇ρ][σ1++σ] = π₂ (Max (C [-◇ sub ρ ])) (≐-sym (SubList.fact1 σ1 σ))
(proj₂ (Max[C◇ρ]⇔Max[P∧Q◇ρ] (sub σ1 ◇ sub σ))
(optimist (sub ρ) (sub σ) (sub σ1) P Q (DClosed.fact1 s1 t1) a (proj₁ (Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] (sub σ1)) b)))
amgu-c {suc l} {i x} {i y} (var-var) | .(just (flexFlex x y))
with thick x y | Thick.fact1 x y (thick x y) refl
... | .(just y') | inj₂ (y' , thinxy'≡y , refl )
= inj₁ (l , anil asnoc i y' / x , var-elim-i-≡ x (i y) (sym (cong i thinxy'≡y)) , refl )
... | .nothing | inj₁ ( x≡y , refl ) rewrite sym x≡y
= inj₁ (suc l , anil , trivial-problem {_} {_} {i x} {sub anil} , refl)
amgu-c {suc l} {i x} {t} (var-t ix≢t) | .(flexRigid x t)
with check x t | check-prop x t
... | .nothing | inj₂ ( ps , r , refl) = inj₂ ( (λ {_} -> No-Unifier ) , refl)
where
No-Unifier : {n : ℕ} (f : Fin (suc l) → Term n) → f x ≡ f ◃ t → ⊥
No-Unifier f fx≡f◃t = ix≢t (sym (trans r (cong (λ ps -> ps ⊹ i x) ps≡[])))
where
ps≡[] : ps ≡ []
ps≡[] = map-[] f ps (No-Cycle (f x) ((f ◃S) ps)
(begin f x ≡⟨ fx≡f◃t ⟩
f ◃ t ≡⟨ cong (f ◃) r ⟩
f ◃ (ps ⊹ i x) ≡⟨ StepM.fact2 f (i x) ps ⟩
(f ◃S) ps ⊹ f x ∎))
... | .(just t') | inj₁ (t' , r , refl) = inj₁ ( l , anil asnoc t' / x , var-elim-i-≡ x t r , refl )
amgu-c {suc m} {s} {t} {l} {ρ asnoc r / z} s-t
| .((λ x' → x' ∃asnoc r / z) <$>
(amgu ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ)))
with amgu-c (view ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ))
... | inj₂ (nounify , ra) = inj₂ ( (λ {_} -> NoQ→NoP nounify) , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra )
where
P = Unifies s t [-◇ sub (ρ asnoc r / z) ]
Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ]
NoQ→NoP : Nothing Q → Nothing P
NoQ→NoP = Properties.fact2 Q P (switch P Q (step-prop s t ρ r z))
... | inj₁ (n , σ , a , ra) = inj₁ (n , σ , proj₂ (MaxP⇔MaxQ (sub σ)) a , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra)
where
P = Unifies s t [-◇ sub (ρ asnoc r / z) ]
Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ]
MaxP⇔MaxQ : Max P ⇔ Max Q
MaxP⇔MaxQ = Max.fact P Q (step-prop s t ρ r z)
amgu-c {m} {s} {t} {l} {ρ} (Flip amguts≡amgust amguts) | ._ = amgu-Ccomm t s (l , ρ) amguts≡amgust (amgu-c amguts)
amgu-c {zero} {i ()} _ | _
amgu-c⋆ : ∀ {m s t l ρ} -> Amgu s t (l , ρ) (amgu s t (l , ρ)) ->
(∃ λ n → ∃ λ σ → (Max⋆ ((Unifies⋆ s t) [-◇⋆ sub ρ ])) (sub σ) × amgu {m} s t (l , ρ) ≡ just (n , σ ++ ρ ))
⊎ (Nothing⋆ ((Unifies⋆ s t) [-◇⋆ sub ρ ]) × amgu {m} s t (l , ρ) ≡ nothing)
amgu-c⋆ {m} {s} {t} {l} {ρ} amg with amgu s t (l , ρ)
amgu-c⋆ {l = l} {ρ} leaf-leaf | ._
= inj₁ (l , anil , trivial-problem {_} {_} {leaf} {sub ρ} , cong (λ x -> just (l , x)) (sym (SubList.anil-id-l ρ)) )
amgu-c⋆ leaf-fork | .nothing = inj₂ ((λ _ () ) , refl)
amgu-c⋆ {m} {s1 fork s2} {t1 fork t2} {l} {ρ} fork-fork | ._
with amgu s1 t1 (l , ρ) | amgu-c⋆ $ view s1 t1 (l , ρ)
... | .nothing | inj₂ (nounify , refl) = inj₂ ((λ {_} -> No[Q◇ρ]→No[P◇ρ] No[Q◇ρ]) , refl)
where
P = Unifies⋆ (s1 fork s2) (t1 fork t2)
Q = (Unifies⋆ s1 t1 ∧⋆ Unifies⋆ s2 t2)
Q⇔P : Q ⇔⋆ P
Q⇔P = switch⋆ P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2})
No[Q◇ρ]→No[P◇ρ] : Nothing⋆ (Q [-◇⋆ sub ρ ]) -> Nothing⋆ (P [-◇⋆ sub ρ ])
No[Q◇ρ]→No[P◇ρ] = Properties.fact2⋆ (Q [-◇⋆ sub ρ ]) (P [-◇⋆ sub ρ ]) (Properties.fact5⋆ Q P (sub ρ) Q⇔P)
No[Q◇ρ] : Nothing⋆ (Q [-◇⋆ sub ρ ])
No[Q◇ρ] = failure-propagation.first⋆ (sub ρ) (Unifies⋆ s1 t1) (Unifies⋆ s2 t2) nounify
... | .(just (n , σ ++ ρ)) | inj₁ (n , σ , a , refl)
with amgu s2 t2 (n , σ ++ ρ) | amgu-c⋆ (view s2 t2 (n , (σ ++ ρ)))
... | .nothing | inj₂ (nounify , refl) = inj₂ ( (λ {_} -> No[Q◇ρ]→No[P◇ρ]⋆ No[Q◇ρ]⋆) , refl)
where
P⋆ = Unifies⋆ (s1 fork s2) (t1 fork t2)
Q⋆ = (Unifies⋆ s1 t1 ∧⋆ Unifies⋆ s2 t2)
Q⇔P⋆ : Q⋆ ⇔⋆ P⋆
Q⇔P⋆ = switch⋆ P⋆ Q⋆ (Properties.fact1'⋆ {_} {s1} {s2} {t1} {t2})
No[Q◇ρ]→No[P◇ρ]⋆ : Nothing⋆ (Q⋆ [-◇⋆ sub ρ ]) -> Nothing⋆ (P⋆ [-◇⋆ sub ρ ])
No[Q◇ρ]→No[P◇ρ]⋆ = Properties.fact2⋆ (Q⋆ [-◇⋆ sub ρ ]) (P⋆ [-◇⋆ sub ρ ]) (Properties.fact5⋆ Q⋆ P⋆ (sub ρ) Q⇔P⋆)
No[Q◇ρ]⋆ : Nothing⋆ (Q⋆ [-◇⋆ sub ρ ])
No[Q◇ρ]⋆ = failure-propagation.second⋆ (sub ρ) (sub σ) (Unifies⋆ s1 t1) (Unifies s2 t2) a
(λ f → nounify f ∘ π₂ (Unifies s2 t2) (cong (f ◃) ∘ sym ∘ SubList.fact1 σ ρ))
{-
No[Q◇ρ]⋆ = failure-propagation.second (sub ρ) (sub σ) (Unifies s1 t1) (Unifies s2 t2) a
-- (λ f Unifs2t2-f◇σ◇ρ → nounify f ((π₂ (Unifies s2 t2) (λ t → cong (f ◃) (sym (SubList.fact1 σ ρ t))) Unifs2t2-f◇σ◇ρ)))
-- (λ f → nounify f ∘ π₂ (Unifies s2 t2) (λ t → cong (f ◃) (sym (SubList.fact1 σ ρ t))))
(λ f → nounify f ∘ π₂ (Unifies s2 t2) (cong (f ◃) ∘ sym ∘ SubList.fact1 σ ρ))
-}
P = Unifies (s1 fork s2) (t1 fork t2)
Q = (Unifies s1 t1 ∧ Unifies s2 t2)
Q⇔P : Q ⇔ P
Q⇔P = switch P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2})
No[Q◇ρ]→No[P◇ρ] : Nothing (Q [-◇ sub ρ ]) -> Nothing (P [-◇ sub ρ ])
No[Q◇ρ]→No[P◇ρ] = Properties.fact2 (Q [-◇ sub ρ ]) (P [-◇ sub ρ ]) (Properties.fact5 Q P (sub ρ) Q⇔P)
No[Q◇ρ] : Nothing (Q [-◇ sub ρ ])
No[Q◇ρ] = failure-propagation.second (sub ρ) (sub σ) (Unifies s1 t1) (Unifies s2 t2) a
(λ f Unifs2t2-f◇σ◇ρ → nounify f (π₂ (Unifies s2 t2) (λ t → cong (f ◃) (sym (SubList.fact1 σ ρ t))) Unifs2t2-f◇σ◇ρ))
... | .(just (n1 , σ1 ++ (σ ++ ρ))) | inj₁ (n1 , σ1 , b , refl)
= inj₁ (n1 , σ1 ++ σ , Max[P∧Q◇ρ][σ1++σ] , cong (λ σ -> just (n1 , σ)) (++-assoc σ1 σ ρ))
where
P = Unifies s1 t1
Q = Unifies s2 t2
P∧Q = P ∧ Q
C = Unifies (s1 fork s2) (t1 fork t2)
Max[C◇ρ]⇔Max[P∧Q◇ρ] : Max (C [-◇ sub ρ ]) ⇔ Max (P∧Q [-◇ sub ρ ])
Max[C◇ρ]⇔Max[P∧Q◇ρ] = Max.fact (C [-◇ sub ρ ]) (P∧Q [-◇ sub ρ ]) (Properties.fact5 C P∧Q (sub ρ)
(Properties.fact1' {_} {s1} {s2} {t1} {t2}))
Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] : Max (Q [-◇ sub (σ ++ ρ)]) ⇔ Max (Q [-◇ sub σ ◇ sub ρ ])
Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] = Max.fact (Q [-◇ sub (σ ++ ρ)]) (Q [-◇ sub σ ◇ sub ρ ]) (Properties.fact6 Q (SubList.fact1 σ ρ))
Max[P∧Q◇ρ][σ1++σ] : π₁ (Max (C [-◇ sub ρ ])) (sub (σ1 ++ σ))
Max[P∧Q◇ρ][σ1++σ] = π₂ (Max (C [-◇ sub ρ ])) (≐-sym (SubList.fact1 σ1 σ))
(proj₂ (Max[C◇ρ]⇔Max[P∧Q◇ρ] (sub σ1 ◇ sub σ))
(optimist (sub ρ) (sub σ) (sub σ1) P Q (DClosed.fact1 s1 t1) a (proj₁ (Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] (sub σ1)) b)))
amgu-c⋆ {suc l} {i x} {i y} (var-var) | .(just (flexFlex x y))
with thick x y | Thick.fact1 x y (thick x y) refl
... | .(just y') | inj₂ (y' , thinxy'≡y , refl )
= inj₁ (l , anil asnoc i y' / x , var-elim-i-≡ x (i y) (sym (cong i thinxy'≡y)) , refl )
... | .nothing | inj₁ ( x≡y , refl ) rewrite sym x≡y
= inj₁ (suc l , anil , trivial-problem {_} {_} {i x} {sub anil} , refl)
amgu-c⋆ {suc l} {i x} {t} (var-t ix≢t) | .(flexRigid x t)
with check x t | check-prop x t
... | .nothing | inj₂ ( ps , r , refl) = inj₂ ( (λ {_} -> No-Unifier ) , refl)
where
No-Unifier : {n : ℕ} (f : Fin (suc l) → Term n) → f x ≡ f ◃ t → ⊥
No-Unifier f fx≡f◃t = ix≢t (sym (trans r (cong (λ ps -> ps ⊹ i x) ps≡[])))
where
ps≡[] : ps ≡ []
ps≡[] = map-[] f ps (No-Cycle (f x) ((f ◃S) ps)
(begin f x ≡⟨ fx≡f◃t ⟩
f ◃ t ≡⟨ cong (f ◃) r ⟩
f ◃ (ps ⊹ i x) ≡⟨ StepM.fact2 f (i x) ps ⟩
(f ◃S) ps ⊹ f x ∎))
... | .(just t') | inj₁ (t' , r , refl) = inj₁ ( l , anil asnoc t' / x , var-elim-i-≡ x t r , refl )
amgu-c⋆ {suc m} {s} {t} {l} {ρ asnoc r / z} s-t
| .((λ x' → x' ∃asnoc r / z) <$>
(amgu ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ)))
with amgu-c⋆ (view ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ))
... | inj₂ (nounify , ra) = inj₂ ( (λ {_} -> NoQ→NoP nounify) , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra )
where
P = Unifies s t [-◇ sub (ρ asnoc r / z) ]
Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ]
NoQ→NoP : Nothing Q → Nothing P
NoQ→NoP = Properties.fact2 Q P (switch P Q (step-prop s t ρ r z))
... | inj₁ (n , σ , a , ra) = inj₁ (n , σ , proj₂ (MaxP⇔MaxQ (sub σ)) a , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra)
where
P = Unifies s t [-◇ sub (ρ asnoc r / z) ]
Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ]
MaxP⇔MaxQ : Max P ⇔ Max Q
MaxP⇔MaxQ = Max.fact P Q (step-prop s t ρ r z)
amgu-c⋆ {m} {s} {t} {l} {ρ} (Flip amguts≡amgust amguts) | ._ = amgu-Ccomm⋆ t s (l , ρ) amguts≡amgust (amgu-c⋆ amguts)
amgu-c⋆ {zero} {i ()} _ | _
mgu-c : ∀ {m} (s t : Term m) ->
(∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t)) (sub σ) × mgu s t ≡ just (n , σ))
⊎ (Nothing (Unifies s t) × mgu s t ≡ nothing)
mgu-c {m} s t = amgu-c (view s t (m , anil))
mgu-c⋆ : ∀ {m} (s t : Term m) ->
(∃ λ n → ∃ λ σ → (Max⋆ (Unifies⋆ s t)) (sub σ) × mgu s t ≡ just (n , σ))
⊎ (Nothing⋆ (Unifies⋆ s t) × mgu s t ≡ nothing)
mgu-c⋆ {m} s t = amgu-c (view s t (m , anil))
data SidedTerm (n : ℕ) : Set where
i-left : (x : Fin n) -> 2 * Data.Fin.toℕ x Data.Nat.≤ n → SidedTerm n
i-right : (x : Fin n) -> n + Data.Fin.toℕ x Data.Nat.≤ 2 * n → SidedTerm n
leaf : SidedTerm n
_fork_ : (s t : SidedTerm n) -> SidedTerm n
data dTerm (n : ℕ) : Term (2 * n) → Set where
-- i :
l1 : ∀ m → Data.Fin.toℕ (Data.Fin.fromℕ m) ≡ m
l1 zero = refl
l1 (suc m) = cong suc (l1 m)
l2 : ∀ m → m ≡ m + 0
l2 zero = refl
l2 (suc m) = cong suc (l2 m)
fixup : ∀ m → Fin (Data.Fin.toℕ (Data.Fin.fromℕ m) + m) → Fin (m + (m + 0))
fixup m x rewrite l1 m | sym (l2 m) = x
revise-down : ∀ {m} → Fin m → Fin (2 * m)
revise-down {m} x = Data.Fin.inject+ (m + 0) x
revise-up : ∀ {m} → Fin m → Fin (2 * m)
revise-up {m} x = fixup m (Data.Fin.fromℕ m Data.Fin.+ x)
{-
reduce* : ∀ {m n} (i : Fin (m * 2)) → Fin m
reduce* {zero} i i≥m = i
reduce* {suc m} zero ()
reduce* {suc m} (suc i) (s≤s i≥m) = reduce≥ i i≥m
-}
downFin : ∀ {m} {x : Fin (2 * m)} → suc (Data.Fin.toℕ x) Data.Nat.≤ m → Fin m
downFin {zero} {()} p₁
downFin {suc m} {zero} (s≤s p₁) = zero
downFin {suc zero} {suc zero} (s≤s p₁) = zero
downFin {suc zero} {suc (suc ())} (s≤s p₁)
downFin {suc (suc m)} {suc zero} (s≤s x<m) = suc zero
downFin {suc (suc m)} {suc (suc x)} (s≤s (s≤s x<m)) = suc ((downFin {suc m} {x = subst Fin (foo m) x} (s≤s {!x<m!}))) where
foo : ∀ m → m + suc (suc (m + zero)) ≡ suc (m + suc (m + zero))
foo zero = refl
foo (suc m) rewrite foo m = cong suc {!refl!}
combineSubs : ∀ {m a} {A : Set a} → (Fin m → A) → (Fin m → A) → Fin (2 * m) → A
combineSubs {m} fl fr x with suc (Data.Fin.toℕ x) ≤? m
… | yes p = fl (downFin {x = x} p)
… | no _ = fr {!!}
write-variable-down : ∀ {m} → Term m → Term (2 * m)
write-variable-down {m} (i l) = i $ revise-down l
write-variable-down {m} leaf = leaf
write-variable-down {m} (s fork t) = write-variable-down s fork write-variable-down t
write-variable-up : ∀ {m} → Term m → Term (2 * m)
write-variable-up {m} (i r) = i (revise-up r)
write-variable-up {m} leaf = leaf
write-variable-up {m} (s fork t) = write-variable-up s fork write-variable-up t
write-variables-apart : ∀ {m} (s t : Term m) → Term (2 * m) × Term (2 * m)
write-variables-apart s t = write-variable-down s , write-variable-up t
separate-substitutions-down : ∀ {m n} → (Fin (2 * m) → Term n) → Fin m → Term n
separate-substitutions-down {m} f x = f $ revise-down x
separate-substitutions-up : ∀ {m n} → (Fin (2 * m) → Term n) → Fin m → Term n
separate-substitutions-up {m} f x = f $ revise-up x
separate-substitutions : ∀ {m n} → (Fin (2 * m) → Term n) → (Fin m → Term n) × (Fin m → Term n)
separate-substitutions {m} x = separate-substitutions-down {m} x , separate-substitutions-up {m} x
Property⋆2 : (m : ℕ) -> Set1
Property⋆2 m = ∀ {n} -> (Fin m -> Term n) × (Fin m -> Term n) -> Set
Nothing⋆2 : ∀{m} -> (P : Property⋆2 m) -> Set
Nothing⋆2 P = ∀{n} f -> P {n} f -> ⊥
Unifies⋆2 : ∀ {m} (s t : Term m) -> Property⋆2 m
Unifies⋆2 s t (f₁ , f₂) = f₁ ◃ s ≡ f₂ ◃ t
_≤2_ : ∀ {m n n'} (f : (Fin m -> Term n) × (Fin m -> Term n)) (g : (Fin m -> Term n') × (Fin m -> Term n')) -> Set
(f₁ , f₂) ≤2 (g₁ , g₂) = ∃ λ f' -> f₁ ≐ (f' ◇ g₁) × f₂ ≐ (f' ◇ g₂)
Max⋆2 : ∀ {m} (P : Property⋆2 m) -> Property⋆2 m
Max⋆2 P f = P f × (∀ {n} f' -> P {n} f' -> f' ≤2 f)
pair-mgu : ∀ {m} -> (s t : Term m) -> Maybe (∃ (AList m))
pair-mgu {m} s t = {!!} -- amgu s t (m , anil)
write≡separate : ∀ {m n} (σ : AList (2 * m) n) (t : Term m) → (sub σ ◃) (write-variable-down t) ≡ ((separate-substitutions-down $ sub σ) ◃) t
write≡separate {zero} {.0} anil (i x) = refl
write≡separate {suc m} {.(suc (m + suc (m + 0)))} anil (i x) = refl
write≡separate {suc m} {n} (σ asnoc t' / x) (i x₁) = refl
write≡separate σ leaf = refl
write≡separate σ (t₁ fork t₂) = cong₂ _fork_ (write≡separate σ t₁) (write≡separate σ t₂)
write≡separate' : ∀ {m n} (σ : AList (2 * m) n) (t : Term m) → (sub σ ◃) (write-variable-down t) ≡ ((separate-substitutions-down $ sub σ) ◃) t
write≡separate' {zero} {.0} anil (i x) = refl
write≡separate' {suc m} {.(suc (m + suc (m + 0)))} anil (i x) = refl
write≡separate' {suc m} {n} (σ asnoc t' / x) (i x₁) = refl
write≡separate' σ leaf = refl
write≡separate' σ (t₁ fork t₂) = cong₂ _fork_ (write≡separate σ t₁) (write≡separate σ t₂)
{-
(sub σ ◃) (write-variable-down s') ≡ (sub σ ◃) (write-variable-up t') →
((separate-substitutions-down $ sub σ) ◃) s' ≡ ((separate-substitutions-up $ sub σ) ◃) t'
-}
pair-mgu-c⋆! : ∀ {m} (s' t' : Term m) (let (s , t) = write-variables-apart s' t') ->
(∃ λ n → ∃ λ σ → ∃ λ σ₁ → ∃ λ σ₂ → (σ₁ , σ₂) ≡ separate-substitutions (sub σ) × (Max⋆2 (Unifies⋆2 s' t')) (σ₁ , σ₂) × mgu s t ≡ just (n , σ))
⊎ (Nothing⋆2 (Unifies⋆2 s t) × mgu s t ≡ nothing)
pair-mgu-c⋆! {m} s' t'
with write-variable-down s' | inspect write-variable-down s' | write-variable-up t' | inspect write-variable-up t'
… | s | Reveal_·_is_.[_] refl | t | Reveal_·_is_.[_] refl with amgu-c⋆ (view s t (2 * m , anil))
… | (inj₁ (n , σ , (s-un-t , s-un-t-correct) , amgu=nσ)) = inj₁ (_ , σ , ((separate-substitutions-down $ sub σ) , ((separate-substitutions-up $ sub σ) , (refl , (({!trans (sym $ write≡separate σ s') s-un-t!} , (λ {(fl , fr) x → ((proj₁ ∘ s-un-t-correct (combineSubs fl fr)) {!(proj₂ ∘ s-un-t-correct (combineSubs fl fr)) !}) , ({!!} , {!!})})) , amgu=nσ))))) where
… | (inj₂ (s-not-un-t , amgu=nothing)) = inj₂ {!!}
-- pair-mgu-c⋆ : ∀ {m} (s' t' : Term m) (let (s , t) = write-variables-apart s' t') ->
-- (∃ λ n → ∃ λ σ → ∃ λ σ₁ → ∃ λ σ₂ → (σ₁ , σ₂) ≡ separate-substitutions {m} {n} (sub {2 * m} {n} σ) × (Max⋆2 (Unifies⋆2 s t)) (σ₁ , σ₂) × mgu s t ≡ just (n , σ))
-- ⊎ (Nothing⋆2 (Unifies⋆2 s t) × mgu s t ≡ nothing)
-- pair-mgu-c⋆ {m} s' t'
-- with write-variables-apart s' t'
-- … | (s , t) with amgu-c⋆ (view s t (2 * m , anil))
-- pair-mgu-c⋆ {m} s' t' | s , t | (inj₁ (n , σ , (s-un-t , s-un-t-correct) , amgu=nσ)) = inj₁ ({!!} , {!!})
-- pair-mgu-c⋆ {m} s' t' | s , t | (inj₂ (s-not-un-t , amgu=nothing)) = inj₂ {!!}
-- -- pair-mgu-c⋆ {m} s t = {!!} -- amgu-c (view s t (m , anil))
-- {-
-- Goal: Σ ℕ
-- (λ n₁ →
-- Σ (AList (m + (m + 0)) n₁)
-- (λ σ₁ →
-- Σ (Fin (m + (m + 0)) → Term n₁)
-- (λ σ₂ →
-- Σ (Fin (m + (m + 0)) → Term n₁)
-- (λ σ₃ →
-- Σ ((σ₂ , σ₃) ≡ (?8 (sub σ₁) , ?9 (sub σ₁)))
-- (λ x →
-- Σ
-- (Σ ((σ₂ ◃) s ≡ (σ₃ ◃) t)
-- (λ x₁ →
-- {n = n₂ : ℕ}
-- (f'
-- : Σ (Fin (m + (m + 0)) → Term n₂)
-- (λ x₂ → Fin (m + (m + 0)) → Term n₂)) →
-- (proj₁ f' ◃) s ≡ (proj₂ f' ◃) t →
-- Σ (Fin n₁ → Term n₂)
-- (λ f'' →
-- Σ ((x₂ : Fin (m + (m + 0))) → proj₁ f' x₂ ≡ (f'' ◃) (σ₂ x₂))
-- (λ x₂ →
-- (x₃ : Fin (m + (m + 0))) → proj₂ f' x₃ ≡ (f'' ◃) (σ₃ x₃)))))
-- (λ x₁ → amgu s t (m + (m + 0) , anil) ≡ just (n₁ , σ₁)))))))
-- ⊎
-- Σ
-- ({n = n₁ : ℕ}
-- (f
-- : Σ (Fin (m + (m + 0)) → Term n₁)
-- (λ x → Fin (m + (m + 0)) → Term n₁)) →
-- (proj₁ f ◃) s ≡ (proj₂ f ◃) t → ⊥)
-- (λ x → amgu s t (m + (m + 0) , anil) ≡ nothing)
-- ————————————————————————————————————————————————————————————
-- t' : Term m
-- s' : Term m
-- amgu=nσ : amgu s t (m + (m + 0) , anil) ≡ just (n , σ)
-- s-un-t-correct
-- : {n = n₁ : ℕ} (f' : Fin (m + (m + 0)) → Term n₁) →
-- (f' ◃) s ≡ (f' ◃) t →
-- Σ (Fin n → Term n₁)
-- (λ f'' → (x : Fin (m + (m + 0))) → f' x ≡ (f'' ◃) (sub σ x))
-- s-un-t : (sub σ ◃) s ≡ (sub σ ◃) t
-- σ : AList (m + (m + 0)) n
-- n : ℕ
-- t : Term (m + (m + 0))
-- s : Term (m + (m + 0))
-- m : ℕ
-- -}
| 42.435552
| 364
| 0.45284
|
2040232bcb7329a1e76b75c710aab55038a001e0
| 1,290
|
agda
|
Agda
|
Chapter1/#3.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
Chapter1/#3.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
Chapter1/#3.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
module #3 where
open import Data.Product
open import Data.Sum
open import Relation.Binary.PropositionalEquality
{-
Exercise 1.3. Derive the induction principle for products indA×B, using only the projections and
the propositional uniqueness principle uppt. Verify that the definitional equalities are valid.
Generalize uppt to Σ-types, and do the same for Σ-types. (This requires concepts from Chapter 2.)
-}
module Product { a b c }{A : Set a}{B : Set b}{C : Set c}(g : A → B → C) where
uppt : (x : A × B) → (proj₁ x , proj₂ x) ≡ x
uppt = λ x → refl
indₓ : ∀{k}(P : A × B → Set k) → ((x : A)(y : B) → P (x , y)) → (x : A × B) → P x
indₓ P f x = subst P (uppt x) (f (proj₁ x) (proj₂ x))
indₓ-β : ∀{k}(P : A × B → Set k) → (f : (x : A)(y : B) → P (x , y)) → (x : A)(y : B) → indₓ P f (x , y) ≡ f x y
indₓ-β P f x y = refl
module Sum { a b c }{A : Set a}{B : A → Set b}{C : Set c}(g : (x : A) → B x → C) where
uppt : (x : Σ A B) → (proj₁ x , proj₂ x) ≡ x
uppt = λ x → refl
ind-Σ : ∀{k}(C : Σ A B → Set k) → ((a : A)(b : B a) → C (a , b)) → (p : Σ A B) → C p
ind-Σ C f x = subst C (uppt x) (f (proj₁ x) (proj₂ x))
ind-Σ-β : ∀{k}(C : Σ A B → Set k) → (f : (a : A)(b : B a) → C (a , b)) → (x : A)(y : B x) → ind-Σ C f (x , y) ≡ f x y
ind-Σ-β C f x y = refl
| 37.941176
| 119
| 0.531008
|
cbccbeaf919d66402d38856b9ab177a88e92ce8c
| 613
|
agda
|
Agda
|
Cubical/Algebra/CommAlgebra/Instances/Unit.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommAlgebra/Instances/Unit.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommAlgebra/Instances/Unit.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.Instances.Unit where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Unit
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Unit
open import Cubical.Algebra.CommAlgebra
private
variable
ℓ ℓ' : Level
open CommAlgebraStr
module _ (R : CommRing ℓ) where
UnitCommAlgebra : CommAlgebra R ℓ'
UnitCommAlgebra = commAlgebraFromCommRing
UnitCommRing
(λ _ _ → tt*) (λ _ _ _ → refl) (λ _ _ _ → refl)
(λ _ _ _ → refl) (λ _ → refl) (λ _ _ _ → refl)
| 23.576923
| 55
| 0.722675
|
cba53d3a581b08964ca9788cdc0e0d7c61652d66
| 4,843
|
agda
|
Agda
|
legacy/RandomAccessList/Redundant/Core/Properties.agda
|
banacorn/numeral
|
aae093cc9bf21f11064e7f7b12049448cd6449f1
|
[
"MIT"
] | 1
|
2015-04-23T15:58:28.000Z
|
2015-04-23T15:58:28.000Z
|
legacy/RandomAccessList/Redundant/Core/Properties.agda
|
banacorn/numeral
|
aae093cc9bf21f11064e7f7b12049448cd6449f1
|
[
"MIT"
] | null | null | null |
legacy/RandomAccessList/Redundant/Core/Properties.agda
|
banacorn/numeral
|
aae093cc9bf21f11064e7f7b12049448cd6449f1
|
[
"MIT"
] | 1
|
2015-05-30T05:50:50.000Z
|
2015-05-30T05:50:50.000Z
|
module RandomAccessList.Redundant.Core.Properties where
open import BuildingBlock
open import BuildingBlock.BinaryLeafTree using (BinaryLeafTree; Node; Leaf)
open import RandomAccessList.Redundant.Core
open import Data.Num.Redundant
open import Data.Num.Redundant.Properties
open import Data.Nat using (ℕ; zero; suc)
open import Data.Nat.Etc
open import Data.Nat.Properties.Simple
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; cong₂; trans; sym; inspect)
open PropEq.≡-Reasoning
⟦[]⟧≈zero∷[] : ∀ {n A} → (xs : 0-2-RAL A n) → {xs≣[] : xs ≡ []} → ⟦ xs ⟧ ≈ zero ∷ []
⟦[]⟧≈zero∷[] {n} {A} [] = <<<-zero n [] {eq refl}
⟦[]⟧≈zero∷[] ( 0∷ xs) {()}
⟦[]⟧≈zero∷[] (x 1∷ xs) {()}
⟦[]⟧≈zero∷[] (x , y 2∷ xs) {()}
--------------------------------------------------------------------------------
-- On ⟦_⟧ and ⟦_⟧ₙ
{-
⟦[]⟧ₙ≡0 : ∀ {A n} → (xs : 0-2-RAL A n) → {xs≣[] : xs ≡ []} → ⟦ xs ⟧ₙ ≡ zero ∷ []
⟦[]⟧ₙ≡0 [] = refl
⟦[]⟧ₙ≡0 ( 0∷ xs) {()}
⟦[]⟧ₙ≡0 (x 1∷ xs) {()}
⟦[]⟧ₙ≡0 (x , y 2∷ xs) {()}
⟦[]⟧≡0 : ∀ {n A} → (xs : 0-2-RAL A n) → {xs≣[] : xs ≡ []} → ⟦ xs ⟧ ≡ zero ∷ []
⟦[]⟧≡0 {n} [] {p} =
begin
n <<< (zero ∷ [])
≡⟨ {! !} ⟩
zero ∷ []
∎
⟦[]⟧≡0 ( 0∷ xs) {()}
⟦[]⟧≡0 (x 1∷ xs) {()}
⟦[]⟧≡0 (x , y 2∷ xs) {()}
-- identity
⟦[]⟧ₙ≡0 : ∀ {A n} → (xs : 0-2-RAL A n) → xs ≡ [] → ⟦ xs ⟧ₙ ≡ zero
⟦[]⟧ₙ≡0 [] p = refl
⟦[]⟧ₙ≡0 ( 0∷ xs) ()
⟦[]⟧ₙ≡0 (x 1∷ xs) ()
⟦[]⟧ₙ≡0 (x , y 2∷ xs) ()
⟦[]⟧≡0 : ∀ {n A} → (xs : 0-2-RAL A n) → xs ≡ [] → ⟦ xs ⟧ ≡ 0
⟦[]⟧≡0 {zero } [] p = refl
⟦[]⟧≡0 {suc n} [] p = *-right-zero (2 * 2 ^ n)
⟦[]⟧≡0 ( 0∷ xs) ()
⟦[]⟧≡0 (x 1∷ xs) ()
⟦[]⟧≡0 (x , y 2∷ xs) ()
⟦0∷xs⟧≡⟦xs⟧ : ∀ {n A} → (xs : 0-2-RAL A (suc n)) → ⟦ 0∷ xs ⟧ ≡ ⟦ xs ⟧
⟦0∷xs⟧≡⟦xs⟧ {zero} xs = +-right-identity (2 * ⟦ xs ⟧ₙ)
⟦0∷xs⟧≡⟦xs⟧ {suc n} xs =
begin
2 * 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ sym (*-assoc (2 * 2 ^ n) 2 ⟦ xs ⟧ₙ) ⟩
((2 * 2 ^ n) * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ x → x * ⟦ xs ⟧ₙ) (*-comm (2 * 2 ^ n) 2) ⟩
(2 * (2 * 2 ^ n)) * ⟦ xs ⟧ₙ
∎
⟦[]⟧≡⟦[]⟧ : ∀ {m n A} → ⟦ [] {A} {m} ⟧ ≡ ⟦ [] {A} {n} ⟧
⟦[]⟧≡⟦[]⟧ {m} {n} =
begin
2 ^ m * 0
≡⟨ *-right-zero (2 ^ m) ⟩
0
≡⟨ sym (*-right-zero (2 ^ n)) ⟩
2 ^ n * 0
∎
splitIndex : ∀ {n A} → (x : BinaryLeafTree A n) → (xs : 0-2-RAL A (suc n)) → ⟦ x 1∷ xs ⟧ ≡ 1 * (2 ^ n) + ⟦ xs ⟧
splitIndex {n} x xs =
begin
2 ^ n * suc (2 * ⟦ xs ⟧ₙ)
≡⟨ +-*-suc (2 ^ n) (2 * ⟦ xs ⟧ₙ) ⟩
2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (λ w → 2 ^ n + w) (sym (*-assoc (2 ^ n) 2 ⟦ xs ⟧ₙ)) ⟩
2 ^ n + (2 ^ n * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + w * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → w + (2 * 2 ^ n) * ⟦ xs ⟧ₙ) (sym (+-right-identity (2 ^ n))) ⟩
2 ^ n + 0 + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
∎
splitIndex2 : ∀ {n A} → (x : BinaryLeafTree A n) → (y : BinaryLeafTree A n) → (xs : 0-2-RAL A (suc n)) → ⟦ x , y 2∷ xs ⟧ ≡ 2 * (2 ^ n) + ⟦ xs ⟧
splitIndex2 {n} x y xs =
begin
2 ^ n * (1 + (1 + (2 * ⟦ xs ⟧ₙ)))
≡⟨ +-*-suc (2 ^ n) ((1 + (2 * ⟦ xs ⟧ₙ))) ⟩
2 ^ n + 2 ^ n * (1 + (2 * ⟦ xs ⟧ₙ))
≡⟨ cong (λ w → 2 ^ n + w) (+-*-suc (2 ^ n) (2 * ⟦ xs ⟧ₙ)) ⟩
2 ^ n + (2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ))
≡⟨ sym (+-assoc (2 ^ n) (2 ^ n) (2 ^ n * (2 * ⟦ xs ⟧ₙ))) ⟩
2 ^ n + 2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (λ w → 2 ^ n + 2 ^ n + w) (sym (*-assoc (2 ^ n) 2 ⟦ xs ⟧ₙ)) ⟩
2 ^ n + 2 ^ n + (2 ^ n * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + 2 ^ n + w * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
2 ^ n + 2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + w + (2 * 2 ^ n) * ⟦ xs ⟧ₙ) (sym (+-right-identity (2 ^ n))) ⟩
2 ^ n + (2 ^ n + 0) + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
≡⟨ refl ⟩
2 * 2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
∎
begin
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
∎
-}
{-
⟦[]⟧≡⟦[]⟧ : ∀ {n A} → ⟦ [] {A} {suc n} ⟧ ≡ ⟦ [] {A} {n} ⟧
⟦[]⟧≡⟦[]⟧ {n} =
begin
(2 * 2 ^ n) * 0
≡⟨ *-right-zero (2 * 2 ^ n) ⟩
0
≡⟨ sym (*-right-zero (2 ^ n)) ⟩
2 ^ n * 0
∎
⟦0∷xs⟧≡⟦xs⟧ {zero} xs = +-right-identity (2 * ⟦ xs ⟧ₙ)
⟦0∷xs⟧≡⟦xs⟧ {suc n} xs =
begin
2 * 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ sym (*-assoc (2 * 2 ^ n) 2 ⟦ xs ⟧ₙ) ⟩
2 * 2 ^ n * 2 * ⟦ xs ⟧ₙ
≡⟨ cong (λ x → x * ⟦ xs ⟧ₙ) (*-assoc 2 (2 ^ n) 2) ⟩
2 * (2 ^ n * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ x → 2 * x * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
(2 * (2 * 2 ^ n)) * ⟦ xs ⟧ₙ
∎
⟦0∷xs⟧≢0⇒⟦xs⟧≢0 : ∀ {n A}
→ (xs : 0-1-RAL A (suc n))
→ ⟦ 0∷ xs ⟧ ≢ 0
→ ⟦ xs ⟧ ≢ 0
⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p = contraposition (trans (⟦0∷xs⟧≡⟦xs⟧ xs)) p
-}
| 31.044872
| 143
| 0.33471
|
cbf62c75835aed33afe3a308e3938f4d60e5835b
| 7,187
|
agda
|
Agda
|
nicolai/thesis/Anonymous_Existence_CollSplit.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
nicolai/thesis/Anonymous_Existence_CollSplit.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
nicolai/thesis/Anonymous_Existence_CollSplit.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.NType2
open import lib.types.Paths
open import Preliminaries
open import Truncation_Level_Criteria
module Anonymous_Existence_CollSplit where
-- Chapter 4: Anonymous Existence
-- Chapter 4.1: Collapsible Types have Split Support
-- Main Lemma 4.1.1 is below.
-- Lemma 4.1.2, part 1
constant-implies-path-constant : ∀ {i j} {X : Type i} {Y : Type j} → (f : X → Y) → (const f)
→ (x₁ x₂ : X) → const (ap f {x = x₁} {y = x₂})
constant-implies-path-constant {X = X} f c x₁ x₂ p₁ p₂ = claim-cor where
claim : {x₃ x₄ : X} → {p : x₃ == x₄} → (ap f p) == ! (c x₃ x₃) ∙ (c x₃ x₄)
claim {x₃} {p = idp} = ! (!-inv-l (c x₃ x₃))
claim-cor : ap f p₁ == ap f p₂
claim-cor =
ap f p₁ =⟨ claim ⟩
! (c x₁ x₁) ∙ (c x₁ x₂) =⟨ ! claim ⟩
ap f p₂ ∎
-- Lemma 4.1.2, part 2
constant-refl : ∀ {i j} {X : Type i} {Y : Type j} → (f : X → Y) → (const f)
→ (x : X) → (p : x == x) → ap f p == idp
constant-refl f c x p = constant-implies-path-constant f c x x p idp
-- We also need the following very simple lemma:
ap-id-trivial : ∀ {i} {X : Type i} → {x₁ x₂ : X} → (p : x₁ == x₂) → ap (idf X) p == p
ap-id-trivial idp = idp
-- Main Lemma 4.1.1 needs a bit of preparation.
-- The definition of the type of fixed points:
fix : ∀ {i} {X : Type i} → (f : X → X) → Type i
fix {X = X} f = Σ X λ x → x == f x
-- Let us give a name to the map X → fix f:
to-fix : ∀ {i} {X : Type i} → (f : X → X) → (const f) → X → fix f
to-fix f c x₀ = f x₀ , c _ _
-- The other direction is just projection:
from-fix : ∀ {i} {X : Type i} → (f : X → X) → fix f → X
from-fix f (x₀ , p₀) = x₀
-- Let us structure the proof of the fixed point lemma a bit:
module fixedpoint {i : ULevel} {X : Type i} (f : X → X) (c : const f) where
-- Let us show that (x , p) == (x , q) first
module _ (x : X) (p q : x == f x) where
t : x == x
t = p ∙ ! q
r : f x == f x
r = ap f t
r-is-triv : r == idp
r-is-triv = constant-refl f c x t
t' : x == x
t' = ap (idf X) t
t'-is-t : t' == t
t'-is-t = ap-id-trivial t
trans-t-p-is-q : transport (λ y → y == f y) t p == q
trans-t-p-is-q =
transport (λ y → y == f y) t p =⟨ transport-is-comp (idf X) f t p ⟩
! t' ∙ p ∙ r =⟨ ap (λ s → ! s ∙ p ∙ r) t'-is-t ⟩
! t ∙ p ∙ r =⟨ ! (∙-assoc (! t) _ _) ⟩
(! t ∙ p) ∙ r =⟨ ap (λ s → (! t ∙ p) ∙ s) r-is-triv ⟩
(! t ∙ p) ∙ idp =⟨ ∙-unit-r _ ⟩
! t ∙ p =⟨ ap (λ s → s ∙ p) (!-∙ p (! q)) ⟩
(! (! q) ∙ ! p) ∙ p =⟨ ∙-assoc (! (! q)) _ _ ⟩
! (! q) ∙ ! p ∙ p =⟨ ap (λ s → ! (! q) ∙ s) (!-inv-l p) ⟩
! (! q) ∙ idp =⟨ ∙-unit-r _ ⟩
! (! q) =⟨ !-! _ ⟩
q ∎
single-x-claim : (x , p) == (x , q)
single-x-claim = pair= t (from-transp _ _ trans-t-p-is-q)
-- Now, we can prove that (x₁ , p₁) and (x₂ , p₂) are always equal:
fix-paths : has-all-paths (fix f)
fix-paths (x₁ , p₁) (x₂ , p₂) =
(x₁ , p₁) =⟨ pair= (p₁ ∙ c x₁ x₂ ∙ ! p₂) (from-transp _ (p₁ ∙ c x₁ x₂ ∙ ! p₂) idp) ⟩
(x₂ , _) =⟨ single-x-claim x₂ _ _ ⟩
(x₂ , p₂) ∎
-- Main Lemma 4.1.1
-- finally, the proof of the fixed point lemma
fixed-point : ∀ {i} {X : Type i} → (f : X → X) → (const f) → is-prop (fix f)
fixed-point {X = X} f c = all-paths-is-prop (fixedpoint.fix-paths f c)
-- Sattler's argument
fixed-point-alt : ∀ {i} {X : Type i} → (f : X → X) → (const f) → is-prop (fix f)
fixed-point-alt {X = X} f c = inhab-to-contr-is-prop inh→contr where
inh→contr : fix f → is-contr (fix f)
inh→contr (x₀ , p₀) = equiv-preserves-level {A = Σ X λ x → x == f x₀} {B = fix f} claim-Σ (pathto-is-contr _) where
claim : (x : X) → (x == f x₀) ≃ (x == f x)
claim x = (λ p → p ∙ c x₀ x) , post∙-is-equiv _
claim-Σ : (Σ X λ x → x == f x₀) ≃ fix f
claim-Σ = equiv-Σ-snd claim
--from here, we need truncation
module with-weak-trunc where
open wtrunc
-- Corollary 4.1.3
-- let us define the following map:
trunc-to-fix : ∀ {i} {X : Type i} → (fc : coll X) → ∣∣ X ∣∣ → fix (fst fc)
trunc-to-fix (f , c) z = tr-rec (fixed-point f c) (to-fix f c) z
coll→splitSup : ∀ {i} {X : Type i} → coll X → splitSup X
coll→splitSup (f , c) = (from-fix f) ∘ trunc-to-fix (f , c)
-- Theorem 4.1.4
coll↔splitSup : ∀ {i} {X : Type i} → coll X ↔ splitSup X
coll↔splitSup {X = X} = coll→splitSup , splitSup→coll where
splitSup→coll : splitSup X → coll X
splitSup→coll hst = f , c where
f = hst ∘ ∣_∣
c : const f
c x₁ x₂ =
f x₁ =⟨ idp ⟩
hst ∣ x₁ ∣ =⟨ ap hst (prop-has-all-paths tr-is-prop _ _) ⟩
hst ∣ x₂ ∣ =⟨ idp ⟩
f x₂ ∎
-- preparation for Proposition 4.1.5 - we need to prove that
-- f : X → X with an inhabitant of ∣∣ const f ∣∣ is enough
-- to show that fix f is propositional.
fixed-point-strong : ∀ {i} {X : Type i} → (f : X → X) → ∣∣ const f ∣∣ → is-prop (fix f)
fixed-point-strong {X = X} f = tr-rec {X = const f} {P = is-prop(fix f)} is-prop-is-prop (fixed-point f)
-- Proposition 4.1.5 (we exclude the part which is already included in Theorem 4.1.4)
-- to get an easy proof of the addendum, we structure it in the following way:
module thm46 {i : ULevel} {X : Type i} where
module _ (fhc : Σ (X → X) (λ f → ∣∣ const f ∣∣)) where
f = fst fhc
hc = snd fhc
trunc-const-fix : ∣∣ X ∣∣ → ∣∣ const f ∣∣ → fix f
trunc-const-fix z = tr-rec {X = const f} {P = fix f} (fixed-point-strong f hc) (λ c → trunc-to-fix (f , c) z)
trunc-fix : ∣∣ X ∣∣ → fix f
trunc-fix z = trunc-const-fix z hc
g : X → X
g = fst ∘ trunc-fix ∘ ∣_∣
g-const : const g
g-const x₁ x₂ = ap (fst ∘ trunc-fix) (prop-has-all-paths tr-is-prop _ _)
coll↔hideProof : ∀ {i} {X : Type i} → coll X ↔ Σ (X → X) (λ f → ∣∣ const f ∣∣)
coll↔hideProof {X = X} = one , two where
one : coll X → Σ (X → X) (λ f → ∣∣ const f ∣∣)
one (f , c) = f , ∣ c ∣
two : (Σ (X → X) (λ f → ∣∣ const f ∣∣)) → coll X
two fhc = thm46.g fhc , thm46.g-const fhc
-- Proposition 4.1.5 addendum
merely-equal : ∀ {i} {X : Type i} → (fhc : Σ (X → X) (λ f → ∣∣ const f ∣∣)) → ∣∣ ((x : X) → fst fhc x == thm46.g fhc x) ∣∣
merely-equal {X = X} (ff , hhc) = tr-rec tr-is-prop (∣_∣ ∘ const-equal) hhc where
open thm46
const-equal : const ff → (x : X) → ff x == thm46.g (ff , hhc) x
const-equal c x =
ff x =⟨ idp ⟩
fst (to-fix ff c x) =⟨ ap fst (! (trunc-β _ _ x)) ⟩
fst (trunc-to-fix (ff , c) ∣ x ∣) =⟨ ap fst (! (trunc-β _ _ c)) ⟩
fst (trunc-const-fix (ff , hhc) ∣ x ∣ ∣ c ∣) =⟨ ap (λ hc' → fst (trunc-const-fix (ff , hhc) ∣ x ∣ hc')) (prop-has-all-paths tr-is-prop _ _) ⟩
fst (trunc-const-fix (ff , hhc) ∣ x ∣ hhc) =⟨ idp ⟩
fst (trunc-fix (ff , hhc) ∣ x ∣) =⟨ idp ⟩
g (ff , hhc) x ∎
| 39.707182
| 148
| 0.488521
|
fbf2529caf66cd3a37c8e29c78b1428e1adc2d58
| 810
|
agda
|
Agda
|
test/Succeed/Issue1209-2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1209-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1209-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- A variant of code reported by Andreas Abel.
{-# OPTIONS --guardedness --sized-types #-}
open import Common.Coinduction renaming (∞ to Delay)
open import Common.Size
open import Common.Product
data ⊥ : Set where
record Stream (A : Set) : Set where
inductive
constructor delay
field
force : Delay (A × Stream A)
open Stream
head : ∀{A} → Stream A → A
head s = proj₁ (♭ (force s))
-- This type should be empty, as Stream A is isomorphic to ℕ → A.
data D : (i : Size) → Set where
lim : ∀ i → Stream (D i) → D (↑ i)
-- Emptiness witness for D.
empty : ∀ i → D i → ⊥
empty .(↑ i) (lim i s) = empty i (head s)
-- BAD: But we can construct an inhabitant.
inh : Stream (D ∞)
inh = delay (♯ (lim ∞ inh , inh)) -- Should be rejected by termination checker.
absurd : ⊥
absurd = empty ∞ (lim ∞ inh)
| 23.142857
| 79
| 0.638272
|
0b8fd16f2480abce2c9499a921c4c1f2f23048dc
| 1,088
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Binary/Equality/DecSetoid.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/Equality/DecSetoid.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Binary/Equality/DecSetoid.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise decidable equality over lists parameterised by a setoid
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.List.Relation.Binary.Equality.DecSetoid
{a ℓ} (DS : DecSetoid a ℓ) where
import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality
import Data.List.Relation.Binary.Pointwise as PW
open import Level
open import Relation.Binary using (Decidable)
open DecSetoid DS
------------------------------------------------------------------------
-- Make all definitions from setoid equality available
open SetoidEquality setoid public
------------------------------------------------------------------------
-- Additional properties
infix 4 _≋?_
_≋?_ : Decidable _≋_
_≋?_ = PW.decidable _≟_
≋-isDecEquivalence : IsDecEquivalence _≋_
≋-isDecEquivalence = PW.isDecEquivalence isDecEquivalence
≋-decSetoid : DecSetoid a (a ⊔ ℓ)
≋-decSetoid = PW.decSetoid DS
| 28.631579
| 72
| 0.5625
|
dcd62faa00e1629a8b45c893a4f9a177455bafb0
| 1,055
|
agda
|
Agda
|
test/Succeed/Issue1087.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1087.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1087.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2014-04-12, Order of declaration mattered in the presence
-- of meta variables involving sizes
-- {-# OPTIONS -v tc.meta:10 -v tc.meta.assign:10 #-}
-- Error persists without option sized-types
{-# OPTIONS --sized-types #-}
module _ where
open import Common.Size
-- different error if we do not use the built-ins (Size vs Size<)
module Works where
mutual
data Colist' i : Set where
inn : (xs : Colist i) → Colist' i
record Colist i : Set where
coinductive
field out : ∀ {j : Size< i} → Colist' j
module Fails where
mutual
record Colist i : Set where
coinductive
field out : ∀ {j : Size< i} → Colist' j
data Colist' i : Set where
inn : (xs : Colist i) → Colist' i
-- Error: Issue1087.agda:21,45-46
-- Cannot instantiate the metavariable _20 to solution (Size< i) since
-- it contains the variable i which is not in scope of the
-- metavariable or irrelevant in the metavariable but relevant in the
-- solution
-- when checking that the expression j has type _20
-- Works now.
| 26.375
| 70
| 0.67109
|
d062fe0363f6f8511ca00c13ac8a006b0edbe1d1
| 868
|
agda
|
Agda
|
agda-implicit/BoehmBerarducci.agda
|
mietek/scott-encoding
|
14e819383dd8730e1c3cbd9c2ce53335bd95188b
|
[
"X11",
"MIT"
] | 6
|
2015-05-27T19:33:52.000Z
|
2019-08-08T16:31:59.000Z
|
agda-implicit/BoehmBerarducci.agda
|
mietek/scott-encoding
|
14e819383dd8730e1c3cbd9c2ce53335bd95188b
|
[
"X11",
"MIT"
] | null | null | null |
agda-implicit/BoehmBerarducci.agda
|
mietek/scott-encoding
|
14e819383dd8730e1c3cbd9c2ce53335bd95188b
|
[
"X11",
"MIT"
] | null | null | null |
module BoehmBerarducci where
open import Data.Nat
open import Data.List
NatQ : Set₁
NatQ = {A : Set} -> (A -> A) -> A -> A
unNatQ : {A : Set} -> (A -> A) -> A -> NatQ -> A
unNatQ f a q = q f a
succQ : NatQ -> NatQ
succQ q = \f a -> f (q f a)
zeroQ : NatQ
zeroQ = \f a -> a
fromNatQ : NatQ -> ℕ
fromNatQ q = unNatQ suc zero q
toNatQ : ℕ -> NatQ
toNatQ (suc n) = succQ (toNatQ n)
toNatQ zero = zeroQ
ListQ : Set -> Set₁
ListQ A = {B : Set} -> (A -> B -> B) -> B -> B
unListQ : {A B : Set} -> (A -> B -> B) -> B -> ListQ A -> B
unListQ f b q = q f b
consQ : {A : Set} -> A -> ListQ A -> ListQ A
consQ a q = \f b -> f a (q f b)
nilQ : {A : Set} -> ListQ A
nilQ = \f b -> b
fromListQ : {A : Set} -> ListQ A -> List A
fromListQ q = unListQ (_∷_) [] q
toListQ : {A : Set} -> List A -> ListQ A
toListQ (a ∷ aa) = consQ a (toListQ aa)
toListQ [] = nilQ
| 19.288889
| 59
| 0.528802
|
39028c902e87ffa414f9df4dc2b22e084f665b89
| 1,114
|
agda
|
Agda
|
test/Fail/Issue822.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/Issue822.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue822.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- {-# OPTIONS -v tc.lhs:40 #-} {-# OPTIONS -v scope.pat:40 #-}
module Issue822 where
module M₁ where
postulate [_] : Set
module M₂ where
data D : Set₁ where
[_] : Set → D
module M₃ where
data D : Set₁ where
[_] : Set → D
open M₁
open M₂
open M₃
Foo : _ → Set
Foo [ A ] = A
-- Strange error message:
-- Bug.agda:16,1-14
-- Left hand side gives too many arguments to a function of type
-- D → Set
-- when checking that the clause Foo [ A ] = A has type D → Set
-- If the two open statements are swapped, then we get a more
-- reasonable error message:
-- Bug.agda:16,1-10
-- Ambiguous name [_]. It could refer to any one of
-- M₂.[_] bound at /home/nad/research/dtp/pretty/Bug.agda:10,5-8
-- M₁.[_] bound at /home/nad/research/dtp/pretty/Bug.agda:5,13-16
-- when scope checking the left-hand side Foo [ A ] in the definition
-- of Foo
-- One could perhaps also argue that the code above should be
-- syntactically correct, because M₁.[_] can't be used in the pattern
-- (except for under a dot).
-- Andreas, 2013-03-21
-- To reproduce an error, one now needs ambiguous constructors.
| 23.208333
| 69
| 0.667864
|
4ae1b7190e6dc5aa22271fdc6c97c3f4f9911d56
| 44,130
|
agda
|
Agda
|
archive/agda-1/NaturalDeduction-PatternLambdaBug.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/NaturalDeduction-PatternLambdaBug.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/NaturalDeduction-PatternLambdaBug.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
{-# OPTIONS --rewriting #-}
{-# OPTIONS --show-implicit #-}
module NaturalDeduction-PatternLambdaBug
where
record ⊤ : Set where
data ⊥ : Set where
foo : ⦃ _ : ⊤ ⦄ → ⊥ → Set
foo = λ {x → {!x!}}
{-
C-c C-c above generates invalid syntax:
foo = λ { }
Found an implicit lambda where an explicit lambda was expected
when checking that the expression λ {} has type ⊥ → Set
Better would have been
foo = λ {()}
-}
-- module DelayMishMash where
-- open import Level --public
-- using (Level) renaming (zero to lzero; suc to lsuc)
-- open import Size public
-- open import Prelude.Monad renaming (Monad to RawMonad)
-- --open import Category.Monad public
-- -- using (RawMonad; module RawMonad)
-- open import Data.Empty --public
-- using (⊥; ⊥-elim)
-- open import Data.List --public
-- using (List; []; _∷_; map)
-- open import Data.Maybe --public
-- using (Maybe; just; nothing) renaming (map to fmap)
-- open import Data.Product public
-- using (∃; _×_; _,_) renaming (proj₁ to fst; proj₂ to snd)
-- --infixr 1 _,_
-- open import Data.Sum --public
-- using (_⊎_; [_,_]′) renaming (inj₁ to inl; inj₂ to inr)
-- open import Data.Unit --public
-- using (⊤)
-- open import Function --public
-- using (_∘_; case_of_)
-- open import Relation.Nullary --public
-- using (Dec; yes; no)
-- open import Relation.Binary --public
-- using (Setoid; module Setoid)
-- import Relation.Binary.PreorderReasoning
-- module Pre = Relation.Binary.PreorderReasoning
-- open import Relation.Binary.PropositionalEquality --public
-- using (_≡_; refl; sym; trans; cong; cong₂; subst; module ≡-Reasoning)
-- --open ≡-Reasoning renaming (begin_ to proof_) public
-- open import Relation.Binary.HeterogeneousEquality --public
-- using (_≅_; refl; ≡-to-≅; module ≅-Reasoning)
-- renaming (sym to hsym; trans to htrans; cong to hcong;
-- cong₂ to hcong₂; subst to hsubst)
-- hcong₃ : {A : Set}{B : A → Set}{C : ∀ a → B a → Set}{D : ∀ a b → C a b → Set}
-- (f : ∀ a b c → D a b c)
-- {a a′ : A} → a ≅ a′ →
-- {b : B a}{b′ : B a′} → b ≅ b′ →
-- {c : C a b}{c′ : C a′ b′} → c ≅ c′ →
-- f a b c ≅ f a′ b′ c′
-- hcong₃ f refl refl refl = refl
-- ≅-to-≡ : ∀ {a} {A : Set a} {x y : A} → x ≅ y → x ≡ y
-- ≅-to-≡ refl = refl
-- mutual
-- data Delay (i : Size) (A : Set) : Set where
-- now : A → Delay i A
-- later : ∞Delay i A → Delay i A
-- record ∞Delay (i : Size) (A : Set) : Set where
-- coinductive
-- field
-- force : {j : Size< i} → Delay j A
-- open ∞Delay public
-- never : ∀{i A} → ∞Delay i A
-- force (never {i}) {j} = later (never {j})
-- module Bind where
-- mutual
-- bindDelay : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B
-- bindDelay (now a) f = f a
-- bindDelay (later a∞) f = later (bind∞Delay a∞ f)
-- bind∞Delay : ∀ {i A B} → ∞Delay i A → (A → Delay i B) → ∞Delay i B
-- force (bind∞Delay a∞ f) = bindDelay (force a∞) f
-- _d>>=_ : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B
-- _d>>=_ {i} = Bind.bindDelay {i}
-- {-
-- open import Prelude.Applicative using (Applicative)
-- instance delayApplicative : ∀ {i} → Applicative (Delay i)
-- Applicative.pure (delayApplicative {i}) x = now x
-- Applicative._<*>_ (delayApplicative {i}) (now f) x = x d>>= (now ∘ f)
-- Applicative._<*>_ (delayApplicative {i}) (later f) x = {!force f {i}!}
-- {-
-- Applicative._<*>_ (delayApplicative {i}) f (now x) = {!x!} -- Bind.bindDelay x (λ x₁ → {!!})
-- Applicative._<*>_ (delayApplicative {i}) (now f) (later x) = {!!} -- Bind.bindDelay x (λ x₁ → {!!})
-- Applicative._<*>_ (delayApplicative {i}) (later f) (later x) = {!!} -- Bind.bindDelay x (λ x₁ → {!!})
-- -}
-- Applicative.super (delayApplicative {i}) = {!!}
-- -}
-- {-
-- instance delayMonad : ∀ {i} → RawMonad (Delay i)
-- delayMonad {i} = record
-- { {-return = now
-- ; -}_>>=_ = bindDelay {i}
-- } where open Bind
-- -}
-- {-
-- module _ {i : Size} where
-- open module DelayMonad = RawMonad (delayMonad {i = i})
-- public -- renaming (_⊛_ to _<*>_)
-- -}
-- open Bind public using () renaming (bind∞Delay to _∞>>=_)
-- -- Map for Delay
-- dreturn : {i : Size} → {A : Set} → A → Delay i A
-- dreturn {i} = Delay.now {i}
-- _d<$>_ : ∀ {i A B} (f : A → B) (a : Delay i A) → Delay i B
-- f d<$> a = a d>>= λ a → dreturn (f a)
-- -- Map for ∞Delay
-- _∞<$>_ : ∀ {i A B} (f : A → B) (∞a : ∞Delay i A) → ∞Delay i B
-- f ∞<$> ∞a = ∞a ∞>>= λ a → dreturn (f a)
-- -- force (f ∞<$> ∞a) = f <$> force ∞a
-- -- Double bind
-- _=<<2_,_ : ∀ {i A B C} → (A → B → Delay i C) → Delay i A → Delay i B → Delay i C
-- f =<<2 x , y = x d>>= λ a → y d>>= λ b → f a b
-- mutual
-- data _∼_ {i : Size} {A : Set} : (a? b? : Delay ∞ A) → Set where
-- ∼now : ∀ a → now a ∼ now a
-- ∼later : ∀ {a∞ b∞} (eq : a∞ ∞∼⟨ i ⟩∼ b∞) → later a∞ ∼ later b∞
-- _∼⟨_⟩∼_ = λ {A} a? i b? → _∼_ {i}{A} a? b?
-- record _∞∼⟨_⟩∼_ {A} (a∞ : ∞Delay ∞ A) i (b∞ : ∞Delay ∞ A) : Set where
-- coinductive
-- field
-- ∼force : {j : Size< i} → force a∞ ∼⟨ j ⟩∼ force b∞
-- _∞∼_ = λ {i} {A} a∞ b∞ → _∞∼⟨_⟩∼_ {A} a∞ i b∞
-- open _∞∼⟨_⟩∼_ public
-- ∼never : ∀{i A} → (never {A = A}) ∞∼⟨ i ⟩∼ never
-- ∼force ∼never = ∼later ∼never
-- ∼refl : ∀{i A} (a? : Delay ∞ A) → a? ∼⟨ i ⟩∼ a?
-- ∞∼refl : ∀{i A} (a∞ : ∞Delay ∞ A) → a∞ ∞∼⟨ i ⟩∼ a∞
-- ∼sym : ∀{i A}{a? b? : Delay ∞ A } → a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ a?
-- ∞∼sym : ∀{i A}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ a∞
-- ∼trans : ∀{i A}{a? b? c? : Delay ∞ A} →
-- a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ c? → a? ∼⟨ i ⟩∼ c?
-- ∞∼trans : ∀{i A}{a∞ b∞ c∞ : ∞Delay ∞ A} →
-- a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ c∞ → a∞ ∞∼⟨ i ⟩∼ c∞
-- ∼refl (now a) = ∼now a
-- ∼refl (later a∞) = ∼later (∞∼refl a∞)
-- ∼force (∞∼refl a∞) = ∼refl (force a∞)
-- ∼sym (∼now a) = ∼now a
-- ∼sym (∼later eq) = ∼later (∞∼sym eq)
-- ∼force (∞∼sym eq) = ∼sym (∼force eq)
-- ∼trans (∼now a) (∼now .a) = ∼now a
-- ∼trans (∼later eq) (∼later eq′) = ∼later (∞∼trans eq eq′)
-- ∼force (∞∼trans eq eq′) = ∼trans (∼force eq) (∼force eq′)
-- -- Equality reasoning
-- ∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
-- ∼setoid i A = record
-- { Carrier = Delay ∞ A
-- ; _≈_ = _∼_ {i}
-- ; isEquivalence = record
-- { refl = λ {a?} → ∼refl a?
-- ; sym = ∼sym
-- ; trans = ∼trans
-- }
-- }
-- ∞∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
-- ∞∼setoid i A = record
-- { Carrier = ∞Delay ∞ A
-- ; _≈_ = _∞∼_ {i}
-- ; isEquivalence = record
-- { refl = λ {a?} → ∞∼refl a?
-- ; sym = ∞∼sym
-- ; trans = ∞∼trans
-- }
-- }
-- module ∼-Reasoning {i : Size} {A : Set} where
-- open Pre (Setoid.preorder (∼setoid i A)) public
-- -- using (begin_; _∎) (_≈⟨⟩_ to _∼⟨⟩_; _≈⟨_⟩_ to _∼⟨_⟩_)
-- renaming (_≈⟨⟩_ to _≡⟨⟩_; _≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _∼⟨_⟩_; begin_ to proof_)
-- module ∞∼-Reasoning {i : Size} {A : Set} where
-- open Pre (Setoid.preorder (∞∼setoid i A)) public
-- -- using (begin_; _∎) (_≈⟨⟩_ to _∼⟨⟩_; _≈⟨_⟩_ to _∼⟨_⟩_)
-- renaming (_≈⟨⟩_ to _≡⟨⟩_; _≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _∞∼⟨_⟩_; begin_ to proof_)
-- mutual
-- bind-assoc : ∀{i A B C} (m : Delay ∞ A)
-- {k : A → Delay ∞ B} {l : B → Delay ∞ C} →
-- ((m d>>= k) d>>= l) ∼⟨ i ⟩∼ (m d>>= λ a → (k a d>>= l))
-- bind-assoc (now a) = ∼refl _
-- bind-assoc (later a∞) = ∼later (∞bind-assoc a∞)
-- ∞bind-assoc : ∀{i A B C} (a∞ : ∞Delay ∞ A)
-- {k : A → Delay ∞ B} {l : B → Delay ∞ C} →
-- ((a∞ ∞>>= k) ∞>>= l) ∞∼⟨ i ⟩∼ (a∞ ∞>>= λ a → (k a d>>= l))
-- ∼force (∞bind-assoc a∞) = bind-assoc (force a∞)
-- bind-cong-l : ∀{i A B}{a? b? : Delay ∞ A} → a? ∼⟨ i ⟩∼ b? →
-- (k : A → Delay ∞ B) → (a? d>>= k) ∼⟨ i ⟩∼ (b? d>>= k)
-- ∞bind-cong-l : ∀{i A B}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ →
-- (k : A → Delay ∞ B) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (b∞ ∞>>= k)
-- bind-cong-r : ∀{i A B}(a? : Delay ∞ A){k l : A → Delay ∞ B} →
-- (∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a? d>>= k) ∼⟨ i ⟩∼ (a? d>>= l)
-- ∞bind-cong-r : ∀{i A B}(a∞ : ∞Delay ∞ A){k l : A → Delay ∞ B} →
-- (∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (a∞ ∞>>= l)
-- bind-cong-l (∼now a) k = ∼refl _
-- bind-cong-l (∼later eq) k = ∼later (∞bind-cong-l eq k)
-- ∼force (∞bind-cong-l eq k) = bind-cong-l (∼force eq) k
-- bind-cong-r (now a) h = h a
-- bind-cong-r (later a∞) h = ∼later (∞bind-cong-r a∞ h)
-- ∼force (∞bind-cong-r a∞ h) = bind-cong-r (force a∞) h
-- open import Prelude.Functor using (Functor; _<$>_)
-- {-
-- instance FunctorDelay : {i : Size} → Functor (Delay i)
-- Functor.fmap (FunctorDelay {i}) {A} {B} f (now x) = {!!}
-- Functor.fmap (FunctorDelay {i}) {A} {B} f (later x) = {!!}
-- -}
-- open import Prelude.Function using (_∘′_)
-- map-compose : ∀{i A B C} (a? : Delay ∞ A) {f : A → B} {g : B → C} →
-- (g d<$> (f d<$> a?)) ∼⟨ i ⟩∼ ((g ∘ f) d<$> a?)
-- map-compose a? = bind-assoc a?
-- map-cong : ∀{i A B}{a? b? : Delay ∞ A} (f : A → B) →
-- a? ∼⟨ i ⟩∼ b? → (f d<$> a?) ∼⟨ i ⟩∼ (f d<$> b?)
-- map-cong f eq = bind-cong-l eq (now ∘ f)
-- data _⇓_ {A : Set} : (a? : Delay ∞ A) (a : A) → Set where
-- now⇓ : ∀{a} → now a ⇓ a
-- later⇓ : ∀{a} {a∞ : ∞Delay ∞ A} → force a∞ ⇓ a → later a∞ ⇓ a
-- _⇓ : {A : Set} (x : Delay ∞ A) → Set
-- x ⇓ = ∃ λ a → x ⇓ a
-- map⇓ : ∀{A B}{a : A}{a? : Delay ∞ A}(f : A → B) → a? ⇓ a → (f d<$> a?) ⇓ f a
-- subst∼⇓ : ∀{A}{a? a?′ : Delay ∞ A}{a : A} → a? ⇓ a → a? ∼ a?′ → a?′ ⇓ a
-- bind⇓ : ∀{A B}(f : A → Delay ∞ B){?a : Delay ∞ A}{a : A}{b : B} →
-- ?a ⇓ a → f a ⇓ b → (?a d>>= f) ⇓ b
-- map⇓ f now⇓ = now⇓
-- map⇓ f (later⇓ a⇓) = later⇓ (map⇓ f a⇓)
-- subst∼⇓ now⇓ (∼now a) = now⇓
-- subst∼⇓ (later⇓ p) (∼later eq) = later⇓ (subst∼⇓ p (∼force eq))
-- bind⇓ f now⇓ q = q
-- bind⇓ f (later⇓ p) q = later⇓ (bind⇓ f p q)
-- --infixr 6 _⇒_
-- --infixl 1 _,_
-- module CustomPrelude where
-- open import Prelude public
-- renaming (_==_ to _≟_) -- TODO ask Agda to rename Eq._==_ to Eq._≟_
-- hiding (force) -- needed by ∞Delay
-- {-# BUILTIN REWRITE _≡_ #-}
-- --{-# DISPLAY Eq._==_ _ = _≟_ #-}
-- open import Container.List renaming (_∈_ to _∈C_; lookup∈ to lookup∈C) public
-- _∈C?_ : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ (a : A) → (xs : List A) → Dec (a ∈C xs)
-- a ∈C? [] = no λ ()
-- a ∈C? (x ∷ xs) with a ≟ x
-- … | yes a≡x rewrite a≡x = yes (zero refl)
-- … | no a≢x with a ∈C? xs
-- … | yes a∈xs = yes (suc a∈xs)
-- … | no a∉xs = no (λ {(zero a≡x) → a≢x a≡x ; (suc a∈xs) → a∉xs a∈xs})
-- data _∈_ {ℓ} {A : Set ℓ} (a : A) : List A → Set ℓ
-- where
-- here : (as : List A) → a ∈ (a ∷ as)
-- there : (x : A) {as : List A} → a ∈ as → a ∈ (x ∷ as)
-- _∉_ : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ (a : A) → (xs : List A) → Set ℓ
-- a ∉ xs = ¬ (a ∈ xs)
-- _∈?_ : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ (a : A) → (xs : List A) → Dec (a ∈ xs)
-- a ∈? [] = no λ ()
-- a ∈? (x ∷ xs) with a ≟ x
-- … | yes a≡x rewrite a≡x = yes (here xs)
-- … | no a≢x with a ∈? xs
-- … | yes a∈xs = yes (there x a∈xs)
-- … | no a∉xs = no (λ {(here _) → a≢x refl ; (there _ a∈xs) → a∉xs a∈xs})
-- _⊆_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
-- R ⊆ S = ∀ {x} → x ∈ R → x ∈ S
-- _≢_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
-- x ≢ y = ¬ (x ≡ y)
-- infix 0 _↔_
-- _↔_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
-- P ↔ Q = (P → Q) × (Q → P)
-- ∃ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
-- ∃ = Σ _
-- ∄ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
-- ∄ = ¬_ ∘ ∃
-- infixl 4 _⊎_
-- _⊎_ = Either
-- --open import Agda.Builtin.Size public
-- open import Size public
-- open import Control.Monad.State public
-- open import Control.Monad.Identity public
-- open import Container.Traversable public
-- sequence : ∀ {a b} {A : Set a} {F : Set a → Set b} ⦃ _ : Applicative F ⦄ → List (F A) → F ⊤′
-- sequence [] = pure tt
-- sequence (x ∷ xs) = x *> sequence xs
-- open import Tactic.Nat public
-- open import Tactic.Deriving.Eq public
-- mutual
-- data Delay (i : Size) (A : Set) : Set where
-- now : A → Delay i A
-- later : ∞Delay i A → Delay i A
-- record ∞Delay (i : Size) (A : Set) : Set where
-- coinductive
-- field
-- force : {j : Size< i} → Delay j A
-- open ∞Delay public
-- module BindDelay
-- where
-- mutual
-- bindDelay : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B
-- bindDelay (now a) f = f a
-- bindDelay (later ∞a) f = later (bind∞Delay ∞a f)
-- bind∞Delay : ∀ {i A B} → ∞Delay i A → (A → Delay i B) → ∞Delay i B
-- force (bind∞Delay ∞a f) = bindDelay (force ∞a) f
-- module _
-- where
-- open BindDelay
-- open BindDelay public using () renaming (bind∞Delay to _∞>>=_)
-- instance FunctorDelay : {i : Size} → Functor (Delay i)
-- Functor.fmap FunctorDelay f x = bindDelay x $ now ∘ f
-- instance ApplicativeDelay : {i : Size} → Applicative (Delay i)
-- Applicative.pure ApplicativeDelay x = now x
-- Applicative._<*>_ ApplicativeDelay (now f) x = f <$> x
-- Applicative._<*>_ ApplicativeDelay (later ∞f) x = later ∘ bind∞Delay ∞f $ flip fmap x
-- Applicative.super ApplicativeDelay = FunctorDelay
-- instance MonadDelay : {i : Size} → Monad (Delay i)
-- Monad._>>=_ MonadDelay = bindDelay
-- Monad.super MonadDelay = ApplicativeDelay
-- mutual
-- data _∼_ {i : Size} {A : Set} : (a? b? : Delay ∞ A) → Set where
-- ∼now : ∀ a → now a ∼ now a
-- ∼later : ∀ {a∞ b∞} (eq : a∞ ∞∼⟨ i ⟩∼ b∞) → later a∞ ∼ later b∞
-- _∼⟨_⟩∼_ = λ {A} a? i b? → _∼_ {i}{A} a? b?
-- record _∞∼⟨_⟩∼_ {A} (a∞ : ∞Delay ∞ A) i (b∞ : ∞Delay ∞ A) : Set where
-- coinductive
-- field
-- ∼force : {j : Size< i} → force a∞ ∼⟨ j ⟩∼ force b∞
-- open _∞∼⟨_⟩∼_ public
-- _∞∼_ = λ {i} {A} a∞ b∞ → _∞∼⟨_⟩∼_ {A} a∞ i b∞
-- mutual
-- ∼refl : ∀{i A} (a? : Delay ∞ A) → a? ∼⟨ i ⟩∼ a?
-- ∼refl (now a) = ∼now a
-- ∼refl (later a∞) = ∼later (∞∼refl a∞)
-- ∞∼refl : ∀{i A} (a∞ : ∞Delay ∞ A) → a∞ ∞∼⟨ i ⟩∼ a∞
-- ∼force (∞∼refl a∞) = ∼refl (force a∞)
-- mutual
-- ∼sym : ∀{i A}{a? b? : Delay ∞ A } → a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ a?
-- ∼sym (∼now a) = ∼now a
-- ∼sym (∼later eq) = ∼later (∞∼sym eq)
-- ∞∼sym : ∀{i A}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ a∞
-- ∼force (∞∼sym eq) = ∼sym (∼force eq)
-- mutual
-- ∼trans : ∀{i A}{a? b? c? : Delay ∞ A} →
-- a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ c? → a? ∼⟨ i ⟩∼ c?
-- ∼trans (∼now a) (∼now .a) = ∼now a
-- ∼trans (∼later eq) (∼later eq′) = ∼later (∞∼trans eq eq′)
-- ∞∼trans : ∀{i A}{a∞ b∞ c∞ : ∞Delay ∞ A} →
-- a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ c∞ → a∞ ∞∼⟨ i ⟩∼ c∞
-- ∼force (∞∼trans eq eq′) = ∼trans (∼force eq) (∼force eq′)
-- --∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
-- --∞∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
-- mutual
-- bind-assoc : ∀{i A B C} (m : Delay ∞ A)
-- {k : A → Delay ∞ B} {l : B → Delay ∞ C} →
-- ((m >>= k) >>= l) ∼⟨ i ⟩∼ (m >>= λ a → (k a >>= l))
-- bind-assoc (now a) = ∼refl _
-- bind-assoc (later a∞) = ∼later (∞bind-assoc a∞)
-- ∞bind-assoc : ∀{i A B C} (a∞ : ∞Delay ∞ A)
-- {k : A → Delay ∞ B} {l : B → Delay ∞ C} →
-- ((a∞ ∞>>= k) ∞>>= l) ∞∼⟨ i ⟩∼ (a∞ ∞>>= λ a → (k a >>= l))
-- ∼force (∞bind-assoc a∞) = bind-assoc (force a∞)
-- mutual
-- bind-cong-l : ∀{i A B}{a? b? : Delay ∞ A} → a? ∼⟨ i ⟩∼ b? →
-- (k : A → Delay ∞ B) → (a? >>= k) ∼⟨ i ⟩∼ (b? >>= k)
-- bind-cong-l (∼now a) k = ∼refl _
-- bind-cong-l (∼later eq) k = ∼later (∞bind-cong-l eq k)
-- ∞bind-cong-l : ∀{i A B}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ →
-- (k : A → Delay ∞ B) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (b∞ ∞>>= k)
-- ∼force (∞bind-cong-l eq k) = bind-cong-l (∼force eq) k
-- mutual
-- bind-cong-r : ∀{i A B}(a? : Delay ∞ A){k l : A → Delay ∞ B} →
-- (∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a? >>= k) ∼⟨ i ⟩∼ (a? >>= l)
-- bind-cong-r (now a) h = h a
-- bind-cong-r (later a∞) h = ∼later (∞bind-cong-r a∞ h)
-- ∞bind-cong-r : ∀{i A B}(a∞ : ∞Delay ∞ A){k l : A → Delay ∞ B} →
-- (∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (a∞ ∞>>= l)
-- ∼force (∞bind-cong-r a∞ h) = bind-cong-r (force a∞) h
-- map-compose : ∀{i A B C} (a? : Delay ∞ A) {f : A → B} {g : B → C} →
-- (g <$> (f <$> a?)) ∼⟨ i ⟩∼ ((g ∘ f) <$> a?)
-- map-compose a? = bind-assoc a?
-- map-cong : ∀{i A B}{a? b? : Delay ∞ A} (f : A → B) →
-- a? ∼⟨ i ⟩∼ b? → (f <$> a?) ∼⟨ i ⟩∼ (f <$> b?)
-- map-cong f eq = bind-cong-l eq (now ∘ f)
-- data _⇓_ {A : Set} : (a? : Delay ∞ A) (a : A) → Set where
-- now⇓ : ∀{a} → now a ⇓ a
-- later⇓ : ∀{a} {a∞ : ∞Delay ∞ A} → force a∞ ⇓ a → later a∞ ⇓ a
-- _⇓ : {A : Set} (x : Delay ∞ A) → Set
-- x ⇓ = ∃ λ a → x ⇓ a
-- map⇓ : ∀{A B}{a : A}{a? : Delay ∞ A}(f : A → B) → a? ⇓ a → (f <$> a?) ⇓ f a
-- map⇓ f now⇓ = now⇓
-- map⇓ f (later⇓ a⇓) = later⇓ (map⇓ f a⇓)
-- bind⇓ : ∀{A B}(f : A → Delay ∞ B){?a : Delay ∞ A}{a : A}{b : B} →
-- ?a ⇓ a → f a ⇓ b → (?a >>= f) ⇓ b
-- bind⇓ f now⇓ q = q
-- bind⇓ f (later⇓ p) q = later⇓ (bind⇓ f p q)
-- infixl 4 _>>=⇓_
-- _>>=⇓_ : ∀{A B}{f : A → Delay ∞ B}{?a : Delay ∞ A}{a : A}{b : B} →
-- ?a ⇓ a → f a ⇓ b → (?a >>= f) ⇓ b
-- _>>=⇓_ = bind⇓ _
-- infixl 4 _⇓>>=⇓_
-- _⇓>>=⇓_ : ∀{A B}{f : A → Delay ∞ B}{?a : Delay ∞ A}{b : B} →
-- (?a⇓ : ?a ⇓) → f (fst ?a⇓) ⇓ b → (?a >>= f) ⇓ b
-- _⇓>>=⇓_ (_ , a⇓) = bind⇓ _ a⇓
-- _⇓Dec>>=⇓_else⇓_ : ∀{A B}{f-yes : A → Delay ∞ B}{f-no : ¬ A → Delay ∞ B}{?a : Delay ∞ (Dec A)}{b : B} →
-- (?a⇓ : ?a ⇓) →
-- ((a : A) → f-yes a ⇓ b) →
-- ((¬a : ¬ A) → f-no ¬a ⇓ b) →
-- ((?a >>= (λ { (yes y) → f-yes y ; (no n) → f-no n }))) ⇓ b
-- (yes y , y⇓) ⇓Dec>>=⇓ fy⇓ else⇓ fn⇓ = y⇓ >>=⇓ fy⇓ y
-- (no n , n⇓) ⇓Dec>>=⇓ fy⇓ else⇓ fn⇓ = n⇓ >>=⇓ fn⇓ n
-- _⇓DecEq>>=⇓_else⇓_ : ∀{A : Set} {A₁ A₂ : A} {B}{f-yes : A₁ ≡ A₂ → Delay ∞ B}{f-no : A₁ ≢ A₂ → Delay ∞ B}{?a : Delay ∞ (Dec (A₁ ≡ A₂))}{b : B} →
-- (?a⇓ : ?a ⇓) →
-- ((eq : A₁ ≡ A₂) → f-yes eq ⇓ b) →
-- ((¬eq : A₁ ≢ A₂) → f-no ¬eq ⇓ b) →
-- ((?a >>= (λ { (yes refl) → f-yes refl ; (no n) → f-no n }))) ⇓ b
-- (yes refl , y⇓) ⇓DecEq>>=⇓ fy⇓ else⇓ fn⇓ = y⇓ >>=⇓ fy⇓ refl
-- (no n , n⇓) ⇓DecEq>>=⇓ fy⇓ else⇓ fn⇓ = n⇓ >>=⇓ fn⇓ n
-- app⇓ : ∀{A}{B}{f? : Delay ∞ (A → B)}{f : A → B}{x? : Delay ∞ A}{x : A} → f? ⇓ f → x? ⇓ x → (f? <*> x?) ⇓ f x
-- app⇓ now⇓ now⇓ = now⇓
-- app⇓ now⇓ (later⇓ x?) = later⇓ $ map⇓ _ x?
-- app⇓ (later⇓ f?) now⇓ = later⇓ $ bind⇓ _ f? now⇓
-- app⇓ (later⇓ ⇓f) (later⇓ ⇓x) = later⇓ $ bind⇓ _ ⇓f $ later⇓ $ bind⇓ _ ⇓x now⇓
-- subst∼⇓ : ∀{A}{a? a?′ : Delay ∞ A}{a : A} → a? ⇓ a → a? ∼ a?′ → a?′ ⇓ a
-- subst∼⇓ now⇓ (∼now a) = now⇓
-- subst∼⇓ (later⇓ p) (∼later eq) = later⇓ (subst∼⇓ p (∼force eq))
-- {-
-- traverse⇓' : ∀{A}{B}{f? : A → Delay ∞ B}{T : Set → Set}⦃ _ : Traversable T ⦄{X : T A} → (∀ x → f? x ⇓) → ∀ (x : T A) → traverse f? x ⇓
-- traverse⇓' x₁ x₂ = {!!} , {!!}
-- -}
-- {-
-- traverse⇓ : ∀{A}{B}{f : A → B}{T : Set → Set}⦃ _ : Traversable T ⦄{X : T A} → (∀ x → f? x ⇓) → ∀ (x : T A) → traverse f x ⇓
-- traverse⇓ x₁ x₂ = {!!} , {!!}
-- -}
-- traverse-list⇓ : ∀{A}{B} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : List A) → traverse f? xs ⇓
-- traverse-list⇓ f? f?⇓ [] = [] , now⇓
-- traverse-list⇓ f? f?⇓ (x ∷ xs)
-- with f?⇓ x | traverse-list⇓ f? f?⇓ xs
-- … | y , y⇓ | ys , ys⇓ = y ∷ ys , app⇓ (map⇓ _ y⇓) ys⇓
-- {-
-- traverse-vec⇓' : ∀{A}{B}{𝑎} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : Vector A 𝑎) → traverse f? xs ⇓
-- traverse-vec⇓' f? f?⇓ [] = [] , now⇓
-- traverse-vec⇓' f? f?⇓ (x ∷ xs)
-- with f?⇓ x | traverse-vec⇓' f? f?⇓ xs
-- … | y , y⇓ | ys , ys⇓ = y ∷ ys , app⇓ (map⇓ _ y⇓) ys⇓
-- traverse-vec⇓ : ∀{A}{B}{𝑎} (f : A → B) → (xs : Vector (Delay ∞ A) 𝑎) → traverse {!f!} xs ⇓
-- traverse-vec⇓ = {!!}
-- -}
-- open CustomPrelude
-- -- infix 15 _╱_
-- -- record Sequent (A : Set) ⦃ _ : BeFormula A ⦄ : Set
-- -- where
-- -- constructor _╱_
-- -- field
-- -- statement : A
-- -- suppositions : List A
-- -- open Sequent
-- -- foooo : {A : Set} ⦃ bf : BeFormula A ⦄ {-⦃ hs : HasNegation A ⦄-} {-(x : Sequent A)-} →
-- -- (∃ λ (x : A) → x ∈ List.[]) → ⊥
-- -- {-
-- -- Dec
-- -- (-- Either
-- -- (Σ A
-- -- (λ x₁ →
-- -- --Σ
-- -- ({-BeFormula.formula bf -}x₁ ∈
-- -- {-map (BeFormula.formula bf)-} [] {-(suppositions x)-})
-- -- {-
-- -- (λ _ →
-- -- ⊤
-- -- --BeFormula.formula bf (HasNegation.~ hs x₁) ∈
-- -- --map (BeFormula.formula bf) (suppositions x)
-- -- )-}
-- -- ))
-- -- {-(BeFormula.formula bf (statement x) ∈
-- -- map (BeFormula.formula bf) (suppositions x))-})
-- -- -}
-- -- foooo = λ {x → {!x!}}
-- -- {-
-- -- foooo (statement₁ ╱ []) = λ {x → {!x!}} -- no (λ {x → {!x!}})
-- -- foooo (statement₁ ╱ (x ∷ suppositions₁)) = {!!}
-- -- -}
-- -- -- TruthValue = Bool
-- -- -- -- reification of elements of the domain
-- -- -- Element = Nat
-- -- -- record VariableName : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- field
-- -- -- name : Nat
-- -- -- open VariableName
-- -- -- instance EqVariableName : Eq VariableName
-- -- -- Eq._==_ EqVariableName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
-- -- -- record FunctionName : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- field
-- -- -- name : Nat
-- -- -- open FunctionName
-- -- -- instance EqFunctionName : Eq FunctionName
-- -- -- Eq._==_ EqFunctionName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
-- -- -- record PredicateName : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- field
-- -- -- name : Nat
-- -- -- open PredicateName
-- -- -- instance EqPredicateName : Eq PredicateName
-- -- -- Eq._==_ EqPredicateName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
-- -- -- record Arity : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- field
-- -- -- arity : Nat
-- -- -- open Arity
-- -- -- instance EqArity : Eq Arity
-- -- -- Eq._==_ EqArity _ = decEq₁ (cong arity) ∘ (_≟_ on arity $ _)
-- -- -- Vector : Set → Arity → Set
-- -- -- Vector A = Vec A ∘ arity
-- -- -- record Elements : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- field
-- -- -- {arity} : Arity
-- -- -- elements : Vector Element arity
-- -- -- open Elements
-- -- -- instance EqElements : Eq Elements
-- -- -- Eq._==_ EqElements (⟨_⟩ {𝑎₁} εs₁) (⟨_⟩ {𝑎₂} εs₂)
-- -- -- with 𝑎₁ ≟ 𝑎₂
-- -- -- … | no 𝑎₁≢𝑎₂ = no λ {refl → 𝑎₁≢𝑎₂ refl}
-- -- -- … | yes refl
-- -- -- with εs₁ ≟ εs₂
-- -- -- … | yes refl = yes refl
-- -- -- … | no εs₁≢εs₂ = no λ {refl → εs₁≢εs₂ refl}
-- -- -- record Interpretation : Set
-- -- -- where
-- -- -- field
-- -- -- μ⟦_⟧ : VariableName → Element
-- -- -- 𝑓⟦_⟧ : FunctionName → Elements → Element
-- -- -- 𝑃⟦_⟧ : PredicateName → Elements → TruthValue
-- -- -- open Interpretation
-- -- -- mutual
-- -- -- data Term : Set
-- -- -- where
-- -- -- variable : VariableName → Term
-- -- -- function : FunctionName → Terms → Term
-- -- -- record Terms : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- inductive
-- -- -- field
-- -- -- {arity} : Arity
-- -- -- terms : Vector Term arity
-- -- -- open Terms
-- -- -- termVariable-inj : ∀ {𝑥₁ 𝑥₂} → Term.variable 𝑥₁ ≡ variable 𝑥₂ → 𝑥₁ ≡ 𝑥₂
-- -- -- termVariable-inj refl = refl
-- -- -- termFunction-inj₁ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → 𝑓₁ ≡ 𝑓₂
-- -- -- termFunction-inj₁ refl = refl
-- -- -- termFunction-inj₂ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → τ₁s ≡ τ₂s
-- -- -- termFunction-inj₂ refl = refl
-- -- -- foo : ∀ a → (ts1 ts2 : Vec Term (arity a)) → (τ₁≡τ₂ : Terms.⟨ ts1 ⟩ ≡ (⟨_⟩ {a} ts2)) → _≡_ {lzero} {Vec Term (arity a)} ts1 ts2
-- -- -- foo a ts1 .ts1 refl = refl
-- -- -- mutual
-- -- -- EqTerm⇑ : ∀ {i} → (x y : Term) → Delay i ∘ Dec $ x ≡ y
-- -- -- EqTerm⇑ (variable _) (variable _) = now (decEq₁ termVariable-inj $ _≟_ _ _)
-- -- -- EqTerm⇑ (function 𝑓₁ τ₁s) (function 𝑓₂ τ₂s) = EqTerms⇑ τ₁s τ₂s >>= λ τ₁s≟τ₂s → now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s
-- -- -- EqTerm⇑ (variable _) (function _ _) = now $ no λ ()
-- -- -- EqTerm⇑ (function _ _) (variable _) = now $ no λ ()
-- -- -- EqTerms⇑ : ∀ {i} → (x y : Terms) → Delay i ∘ Dec $ x ≡ y
-- -- -- EqTerms⇑ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s)
-- -- -- with 𝑎₁ ≟ 𝑎₂
-- -- -- … | no 𝑎₁≢𝑎₂ = now $ no λ {τ₁≡τ₂ → 𝑎₁≢𝑎₂ (cong arity τ₁≡τ₂)}
-- -- -- … | yes refl = EqVecTerm⇑ τ₁s τ₂s >>= λ { (yes refl) → now $ yes refl ; (no τ₁s≢τ₂s) → now $ no (λ ⟨τ₁s⟩≡⟨τ₂s⟩ → τ₁s≢τ₂s (foo ⟨ arity 𝑎₁ ⟩ τ₁s τ₂s ⟨τ₁s⟩≡⟨τ₂s⟩)) }
-- -- -- EqVecTerm⇑ : ∀ {i} {n} → (x y : Vec Term n) → Delay i ∘ Dec $ x ≡ y
-- -- -- EqVecTerm⇑ [] [] = now (yes refl)
-- -- -- EqVecTerm⇑ (τ₁ ∷ τ₁s) (τ₂ ∷ τ₂s) =
-- -- -- EqTerm⇑ τ₁ τ₂ >>= λ
-- -- -- { (yes refl) → EqVecTerm⇑ τ₁s τ₂s >>= λ
-- -- -- { (yes refl) → now $ yes refl
-- -- -- ; (no τ₁s≢τ₂s) → now $ no λ τ₁₁s≡τ₁₂s → τ₁s≢τ₂s $ vcons-inj-tail τ₁₁s≡τ₁₂s }
-- -- -- ; (no τ₁≢τ₂) → now $ no λ τ₁₁s≡τ₂₂s → τ₁≢τ₂ $ vcons-inj-head τ₁₁s≡τ₂₂s }
-- -- -- EqVecTerm⇓ : ∀ {n} → (x y : Vec Term n) → EqVecTerm⇑ x y ⇓
-- -- -- EqVecTerm⇓ [] [] = _ , now⇓
-- -- -- EqVecTerm⇓ (variable 𝑥₁ ∷ τ₁s) (variable 𝑥₂ ∷ τ₂s)
-- -- -- with 𝑥₁ ≟ 𝑥₂
-- -- -- … | yes refl with EqVecTerm⇓ τ₁s τ₂s
-- -- -- EqVecTerm⇓ (variable 𝑥₁ ∷ τ₁s) (variable .𝑥₁ ∷ .τ₁s) | yes refl | (yes refl , snd₁) = _ , snd₁ >>=⇓ now⇓
-- -- -- EqVecTerm⇓ (variable 𝑥₁ ∷ τ₁s) (variable .𝑥₁ ∷ τ₂s) | yes refl | (no x , snd₁) = _ , snd₁ >>=⇓ now⇓
-- -- -- EqVecTerm⇓ (variable 𝑥₁ ∷ τ₁s) (variable 𝑥₂ ∷ τ₂s) | no 𝑥₁≢𝑥₂ = _ , now⇓
-- -- -- EqVecTerm⇓ (variable x ∷ τ₁s) (function x₁ x₂ ∷ τ₂s) = _ , now⇓
-- -- -- EqVecTerm⇓ (function x x₁ ∷ τ₁s) (variable x₂ ∷ τ₂s) = _ , now⇓
-- -- -- EqVecTerm⇓ (function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s) (function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s)
-- -- -- with 𝑎₁ ≟ 𝑎₂ | 𝑓₁ ≟ 𝑓₂
-- -- -- … | no 𝑎₁≢𝑎₂ | no 𝑓₁≢𝑓₂ = _ , now⇓
-- -- -- … | no 𝑎₁≢𝑎₂ | yes refl = _ , now⇓
-- -- -- … | yes refl | no 𝑓₁≢𝑓₂
-- -- -- with EqVecTerm⇓ τ₁s τ₂s
-- -- -- … | (no τ₁s≢τ₂s , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
-- -- -- … | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
-- -- -- EqVecTerm⇓ (function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s) (function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s) | yes refl | yes refl
-- -- -- with EqVecTerm⇓ τ₁s τ₂s | EqVecTerm⇓ τ₁₂s τ₂₂s
-- -- -- … | (no τ₁s≢τ₂s , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
-- -- -- … | (yes refl , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓)
-- -- -- … | (no τ₁s≢τ₂s , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
-- -- -- … | (yes refl , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓)
-- -- -- EqTerms⇓ : (x y : Terms) → EqTerms⇑ x y ⇓
-- -- -- EqTerms⇓ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s)
-- -- -- with 𝑎₁ ≟ 𝑎₂
-- -- -- … | no 𝑎₁≢𝑎₂ = _ , now⇓
-- -- -- … | yes refl
-- -- -- with EqVecTerm⇓ τ₁s τ₂s
-- -- -- … | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓
-- -- -- … | (no _ , τ⇓) = _ , τ⇓ >>=⇓ now⇓
-- -- -- EqTerm⇓ : (x y : Term) → EqTerm⇑ x y ⇓
-- -- -- EqTerm⇓ (variable x) (variable x₁) = _ , now⇓
-- -- -- EqTerm⇓ (function _ τ₁s) (function _ τ₂s)
-- -- -- with EqTerms⇓ τ₁s τ₂s
-- -- -- … | (_ , τ⇓) = _ , τ⇓ >>=⇓ now⇓
-- -- -- EqTerm⇓ (variable x) (function x₁ x₂) = _ , now⇓
-- -- -- EqTerm⇓ (function x x₁) (variable x₂) = _ , now⇓
-- -- -- instance EqTerm : Eq Term
-- -- -- EqTerm = record { _==_ = λ x y → fst (EqTerm⇓ x y) }
-- -- -- instance EqTerms : Eq Terms
-- -- -- Eq._==_ EqTerms x y = fst (EqTerms⇓ x y)
-- -- -- mutual
-- -- -- τ⇑⟦_⟧ : Interpretation → {i : Size} → Term → Delay i Element
-- -- -- τ⇑⟦ I ⟧ (variable 𝑥) = now $ μ⟦ I ⟧ 𝑥
-- -- -- τ⇑⟦ I ⟧ (function 𝑓 τs) = 𝑓⟦ I ⟧ 𝑓 ∘ ⟨_⟩ <$> τs⇑⟦ I ⟧ τs
-- -- -- τs⇑⟦_⟧ : Interpretation → {i : Size} → (τs : Terms) → Delay i (Vector Element (arity τs))
-- -- -- τs⇑⟦ I ⟧ ⟨ [] ⟩ = now []
-- -- -- τs⇑⟦ I ⟧ ⟨ τ ∷ τs ⟩ = τ⇑⟦ I ⟧ τ >>= (λ t → τs⇑⟦ I ⟧ ⟨ τs ⟩ >>= λ ts → now (t ∷ ts))
-- -- -- τs⇓⟦_⟧ : (I : Interpretation) → (τs : Terms) → τs⇑⟦ I ⟧ τs ⇓
-- -- -- τs⇓⟦ I ⟧ ⟨ [] ⟩ = _ , now⇓
-- -- -- τs⇓⟦ I ⟧ ⟨ variable 𝑥 ∷ τs ⟩ = _ , τs⇓⟦ I ⟧ ⟨ τs ⟩ ⇓>>=⇓ now⇓
-- -- -- τs⇓⟦ I ⟧ ⟨ function 𝑓₁ τs₁ ∷ τs₂ ⟩ =
-- -- -- _ , τs⇓⟦ I ⟧ τs₁ ⇓>>=⇓ now⇓ >>=⇓ (τs⇓⟦ I ⟧ ⟨ τs₂ ⟩ ⇓>>=⇓ now⇓)
-- -- -- τ⇓⟦_⟧ : (I : Interpretation) → (τ : Term) → τ⇑⟦ I ⟧ τ ⇓
-- -- -- τ⇓⟦ I ⟧ (variable 𝑥) = _ , now⇓
-- -- -- τ⇓⟦ I ⟧ (function 𝑓 τs) = _ , τs⇓⟦ I ⟧ τs ⇓>>=⇓ now⇓
-- -- -- τ⟦_⟧ : (I : Interpretation) → {i : Size} → (τ : Term) → Element
-- -- -- τ⟦ I ⟧ τ = fst (τ⇓⟦ I ⟧ τ)
-- -- -- data Formula : Set
-- -- -- where
-- -- -- atomic : PredicateName → Terms → Formula
-- -- -- logical : Formula →
-- -- -- Formula →
-- -- -- Formula
-- -- -- quantified : VariableName → Formula → Formula
-- -- -- formulaAtomic-inj₁ : ∀ {𝑃₁ τs₁ 𝑃₂ τs₂} → Formula.atomic 𝑃₁ τs₁ ≡ atomic 𝑃₂ τs₂ → 𝑃₁ ≡ 𝑃₂
-- -- -- formulaAtomic-inj₁ refl = refl
-- -- -- formulaAtomic-inj₂ : ∀ {𝑃₁ τs₁ 𝑃₂ τs₂} → Formula.atomic 𝑃₁ τs₁ ≡ atomic 𝑃₂ τs₂ → τs₁ ≡ τs₂
-- -- -- formulaAtomic-inj₂ refl = refl
-- -- -- formulaLogical-inj₁ : ∀ {φ₁₁ φ₁₂ φ₂₁ φ₂₂} → Formula.logical φ₁₁ φ₁₂ ≡ logical φ₂₁ φ₂₂ → φ₁₁ ≡ φ₂₁
-- -- -- formulaLogical-inj₁ refl = refl
-- -- -- formulaLogical-inj₂ : ∀ {φ₁₁ φ₁₂ φ₂₁ φ₂₂} → Formula.logical φ₁₁ φ₁₂ ≡ logical φ₂₁ φ₂₂ → φ₁₂ ≡ φ₂₂
-- -- -- formulaLogical-inj₂ refl = refl
-- -- -- formulaQuantified-inj₁ : ∀ {𝑥₁ φ₁ 𝑥₂ φ₂} → Formula.quantified 𝑥₁ φ₁ ≡ quantified 𝑥₂ φ₂ → 𝑥₁ ≡ 𝑥₂
-- -- -- formulaQuantified-inj₁ refl = refl
-- -- -- formulaQuantified-inj₂ : ∀ {𝑥₁ φ₁ 𝑥₂ φ₂} → Formula.quantified 𝑥₁ φ₁ ≡ quantified 𝑥₂ φ₂ → φ₁ ≡ φ₂
-- -- -- formulaQuantified-inj₂ refl = refl
-- -- -- instance EqFormula : Eq Formula
-- -- -- Eq._==_ EqFormula (atomic 𝑃₁ τs₁) (atomic 𝑃₂ τs₂) = decEq₂ formulaAtomic-inj₁ formulaAtomic-inj₂ (𝑃₁ ≟ 𝑃₂) (τs₁ ≟ τs₂)
-- -- -- Eq._==_ EqFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) = decEq₂ formulaLogical-inj₁ formulaLogical-inj₂ (φ₁₁ ≟ φ₂₁) (φ₁₂ ≟ φ₂₂)
-- -- -- Eq._==_ EqFormula (quantified 𝑥₁ φ₁) (quantified 𝑥₂ φ₂) = decEq₂ formulaQuantified-inj₁ formulaQuantified-inj₂ (𝑥₁ ≟ 𝑥₂) (φ₁ ≟ φ₂)
-- -- -- Eq._==_ EqFormula (atomic _ _) (logical _ _) = no λ ()
-- -- -- Eq._==_ EqFormula (atomic _ _) (quantified _ _) = no λ ()
-- -- -- Eq._==_ EqFormula (logical _ _) (atomic _ _) = no λ ()
-- -- -- Eq._==_ EqFormula (logical _ _) (quantified _ _) = no λ ()
-- -- -- Eq._==_ EqFormula (quantified _ _) (atomic _ _) = no λ ()
-- -- -- Eq._==_ EqFormula (quantified _ _) (logical _ _) = no λ ()
-- -- -- record HasNegation (A : Set) : Set
-- -- -- where
-- -- -- field
-- -- -- ~ : A → A
-- -- -- open HasNegation ⦃ … ⦄
-- -- -- record BeFormula (A : Set) : Set
-- -- -- where
-- -- -- constructor ⟨_⟩
-- -- -- field
-- -- -- formula : A → Formula
-- -- -- open BeFormula ⦃ … ⦄
-- -- -- record HasSatisfaction (A : Set) : Set₁
-- -- -- where
-- -- -- field
-- -- -- _⊨_ : Interpretation → A → Set
-- -- -- _⊭_ : Interpretation → A → Set
-- -- -- _⊭_ I = ¬_ ∘ I ⊨_
-- -- -- open HasSatisfaction ⦃ … ⦄
-- -- -- record HasDecidableSatisfaction (A : Set) ⦃ _ : HasSatisfaction A ⦄ : Set₁
-- -- -- where
-- -- -- field
-- -- -- _⊨?_ : (I : Interpretation) → (x : A) → Dec (I ⊨ x)
-- -- -- open HasDecidableSatisfaction ⦃ … ⦄
-- -- -- infix 15 _╱_
-- -- -- record Sequent (A : Set) ⦃ _ : BeFormula A ⦄ : Set
-- -- -- where
-- -- -- constructor _╱_
-- -- -- field
-- -- -- statement : A
-- -- -- suppositions : List A
-- -- -- open Sequent
-- -- -- foooo : {A : Set} ⦃ bf : BeFormula A ⦄ {-⦃ hs : HasNegation A ⦄-} (x : Sequent A) →
-- -- -- Dec
-- -- -- (-- Either
-- -- -- (Σ A
-- -- -- (λ x₁ →
-- -- -- --Σ
-- -- -- ({-BeFormula.formula bf -}x₁ ∈
-- -- -- {-map (BeFormula.formula bf)-} (suppositions x))
-- -- -- {-
-- -- -- (λ _ →
-- -- -- ⊤
-- -- -- --BeFormula.formula bf (HasNegation.~ hs x₁) ∈
-- -- -- --map (BeFormula.formula bf) (suppositions x)
-- -- -- )-}
-- -- -- ))
-- -- -- {-(BeFormula.formula bf (statement x) ∈
-- -- -- map (BeFormula.formula bf) (suppositions x))-})
-- -- -- foooo (statement₁ ╱ []) = no (λ {x → {!x!}})
-- -- -- foooo (statement₁ ╱ (x ∷ suppositions₁)) = {!!}
-- -- -- -- record HasValidation (A : Set) : Set₁
-- -- -- -- where
-- -- -- -- field
-- -- -- -- ⊨_ : A → Set
-- -- -- -- ⊭_ : A → Set
-- -- -- -- ⊭_ = ¬_ ∘ ⊨_
-- -- -- -- open HasValidation ⦃ … ⦄
-- -- -- -- 𝑃[_♭_] : PredicateName → Terms → Formula
-- -- -- -- 𝑃[_♭_] = atomic
-- -- -- -- _⊗_ : Formula → Formula → Formula
-- -- -- -- _⊗_ = logical
-- -- -- -- instance
-- -- -- -- HasNegationFormula : HasNegation Formula
-- -- -- -- HasNegation.~ HasNegationFormula φ = φ ⊗ φ
-- -- -- -- data IsLiteral : Formula → Set
-- -- -- -- where
-- -- -- -- atomic : (𝑃 : PredicateName) → (τs : Terms) → IsLiteral $ 𝑃[ 𝑃 ♭ τs ]
-- -- -- -- logical : (𝑃 : PredicateName) → (τs : Terms) → IsLiteral ∘ ~ $ 𝑃[ 𝑃 ♭ τs ]
-- -- -- -- eqIsLiteral : ∀ {φ} → (lf₁ lf₂ : IsLiteral φ) → lf₁ ≡ lf₂
-- -- -- -- eqIsLiteral (atomic 𝑃 τs) (atomic .𝑃 .τs) = refl
-- -- -- -- eqIsLiteral (logical 𝑃 τs) (logical .𝑃 .τs) = refl
-- -- -- -- instance EqIsLiteral : ∀ {φ} → Eq (IsLiteral φ)
-- -- -- -- Eq._==_ EqIsLiteral lf₁ lf₂ = yes (eqIsLiteral lf₁ lf₂)
-- -- -- -- record LiteralFormula : Set
-- -- -- -- where
-- -- -- -- constructor ⟨_⟩
-- -- -- -- field
-- -- -- -- {formula} : Formula
-- -- -- -- isLiteral : IsLiteral formula
-- -- -- -- open LiteralFormula
-- -- -- -- instance EqLiteralFormula : Eq LiteralFormula
-- -- -- -- Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂)
-- -- -- -- with φ₁ ≟ φ₂
-- -- -- -- … | no φ₁≢φ₂ = no (λ {refl → φ₁≢φ₂ refl})
-- -- -- -- Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂) | yes refl = case (eqIsLiteral lf₁ lf₂) of λ {refl → yes refl}
-- -- -- -- infix 13 _¶_
-- -- -- -- record Problem (A : Set) ⦃ _ : BeFormula A ⦄ : Set
-- -- -- -- where
-- -- -- -- constructor _¶_
-- -- -- -- field
-- -- -- -- inferences : List (Sequent A)
-- -- -- -- interest : Sequent A
-- -- -- -- open Problem
-- -- -- -- record HasSubstantiveDischarge (+ : Set) (- : Set) : Set₁
-- -- -- -- where
-- -- -- -- field
-- -- -- -- _≽_ : + → - → Set
-- -- -- -- open HasSubstantiveDischarge ⦃ … ⦄
-- -- -- -- record HasVacuousDischarge (+ : Set) : Set₁
-- -- -- -- where
-- -- -- -- field
-- -- -- -- ◁_ : + → Set
-- -- -- -- open HasVacuousDischarge ⦃ … ⦄
-- -- -- -- record HasSalvation (A : Set) : Set₁
-- -- -- -- where
-- -- -- -- field
-- -- -- -- {isVacuouslyDischargable} : Set
-- -- -- -- ⦃ hasVacuousDischarge ⦄ : HasVacuousDischarge isVacuouslyDischargable
-- -- -- -- ▷_ : A → Set
-- -- -- -- open HasSalvation ⦃ … ⦄
-- -- -- -- record HasDecidableSalvation (A : Set) : Set₁
-- -- -- -- where
-- -- -- -- field
-- -- -- -- ⦃ hasSalvation ⦄ : HasSalvation A
-- -- -- -- ▷?_ : (x : A) → Dec $ ▷_ x
-- -- -- -- open HasDecidableSalvation ⦃ … ⦄
-- -- -- -- ∀[_♭_] : VariableName → Formula → Formula
-- -- -- -- ∀[_♭_] = quantified
-- -- -- -- _∧_ : Formula → Formula → Formula
-- -- -- -- φ₁ ∧ φ₂ = ~ φ₁ ⊗ ~ φ₂
-- -- -- -- _∨_ : Formula → Formula → Formula
-- -- -- -- φ₁ ∨ φ₂ = ~ (φ₁ ⊗ φ₂)
-- -- -- -- _⊃_ : Formula → Formula → Formula
-- -- -- -- φ₁ ⊃ φ₂ = ~ φ₁ ∨ φ₂
-- -- -- -- _⟷_ : Formula → Formula → Formula
-- -- -- -- φ₁ ⟷ φ₂ = (φ₁ ⊗ (φ₂ ⊗ φ₂)) ⊗ ((φ₁ ⊗ φ₁) ⊗ φ₂) -- TODO check that this is logically equivalent to the more verbose, (φ₁ ⊃ φ₂) ∧ (φ₂ ⊃ φ₁)
-- -- -- -- record _≞_/_ (𝓘 : Interpretation) (I : Interpretation) (𝑥 : VariableName) : Set
-- -- -- -- where
-- -- -- -- field
-- -- -- -- μEquality : {𝑥′ : VariableName} → 𝑥′ ≢ 𝑥 → μ⟦ 𝓘 ⟧ 𝑥 ≡ μ⟦ I ⟧ 𝑥′
-- -- -- -- 𝑓Equality : (𝑓 : FunctionName) (μs : Elements) → 𝑓⟦ 𝓘 ⟧ 𝑓 μs ≡ 𝑓⟦ I ⟧ 𝑓 μs
-- -- -- -- 𝑃Equality : (𝑃 : PredicateName) → (μs : Elements) → 𝑃⟦ 𝓘 ⟧ 𝑃 μs ≡ 𝑃⟦ I ⟧ 𝑃 μs
-- -- -- -- instance
-- -- -- -- BeFormulaFormula : BeFormula Formula
-- -- -- -- BeFormula.formula BeFormulaFormula = id
-- -- -- -- BeFormulaLiteralFormula : BeFormula LiteralFormula
-- -- -- -- BeFormula.formula BeFormulaLiteralFormula = formula
-- -- -- -- instance
-- -- -- -- HasNegationLiteralFormula : HasNegation LiteralFormula
-- -- -- -- HasNegation.~ HasNegationLiteralFormula ⟨ atomic 𝑃 τs ⟩ = ⟨ logical 𝑃 τs ⟩
-- -- -- -- HasNegation.~ HasNegationLiteralFormula ⟨ logical 𝑃 τs ⟩ = ⟨ atomic 𝑃 τs ⟩
-- -- -- -- HasNegationSequent : {A : Set} ⦃ _ : HasNegation A ⦄ ⦃ _ : BeFormula A ⦄ → HasNegation $ Sequent A
-- -- -- -- HasNegation.~ HasNegationSequent ( φᵗ ╱ φˢs ) = ~ φᵗ ╱ φˢs
-- -- -- -- instance
-- -- -- -- HasSatisfactionList : {A : Set} ⦃ _ : HasSatisfaction A ⦄ → HasSatisfaction $ List A
-- -- -- -- HasSatisfaction._⊨_ HasSatisfactionList I [] = ⊤
-- -- -- -- HasSatisfaction._⊨_ HasSatisfactionList I (x ∷ xs) = I ⊨ x × I ⊨ xs
-- -- -- -- HasSatisfactionBeFormula : {A : Set} → ⦃ _ : BeFormula A ⦄ → HasSatisfaction A
-- -- -- -- HasSatisfaction._⊨_ (HasSatisfactionBeFormula ⦃ beFormula ⦄) = λ I φ → I ⊨φ formula beFormula φ
-- -- -- -- where
-- -- -- -- _⊨φ_ : Interpretation → Formula → Set
-- -- -- -- I ⊨φ (atomic 𝑃 τs) = 𝑃⟦ I ⟧ 𝑃 ⟨ τ⟦ I ⟧ <$> terms τs ⟩ ≡ true
-- -- -- -- I ⊨φ (logical φ₁ φ₂) = ¬ I ⊨φ φ₁ × ¬ I ⊨φ φ₂
-- -- -- -- I ⊨φ (quantified 𝑥 φ) = (𝓘 : Interpretation) → 𝓘 ≞ I / 𝑥 → 𝓘 ⊨φ φ
-- -- -- -- HasSatisfactionSequent : {A : Set} ⦃ _ : BeFormula A ⦄ → HasSatisfaction $ Sequent A
-- -- -- -- HasSatisfaction._⊨_ HasSatisfactionSequent I (φᵗ ╱ φˢs) = I ⊨ φˢs → I ⊨ φᵗ
-- -- -- -- instance
-- -- -- -- postulate
-- -- -- -- HasDecidableSatisfactionFormula : HasDecidableSatisfaction Formula
-- -- -- -- instance
-- -- -- -- HasValidationBeFormula : {A : Set} ⦃ _ : BeFormula A ⦄ → HasValidation A
-- -- -- -- HasValidation.⊨_ HasValidationBeFormula φ = (I : Interpretation) → I ⊨ φ
-- -- -- -- HasValidationSequent : {A : Set} ⦃ _ : BeFormula A ⦄ → HasValidation $ Sequent A
-- -- -- -- HasValidation.⊨_ HasValidationSequent Φ = (I : Interpretation) → I ⊨ Φ
-- -- -- -- HasValidationProblem : {A : Set} ⦃ _ : BeFormula A ⦄ → HasValidation $ Problem A
-- -- -- -- HasValidation.⊨_ HasValidationProblem (χs ¶ ι) = (I : Interpretation) → I ⊨ χs → I ⊨ ι
-- -- -- -- instance
-- -- -- -- HasSubstantiveDischargeBeFormulaBeFormula : {A : Set} ⦃ _ : BeFormula A ⦄ → HasSubstantiveDischarge A A
-- -- -- -- HasSubstantiveDischarge._≽_ (HasSubstantiveDischargeBeFormulaBeFormula ⦃ ⟨ beFormula ⟩ ⦄) = _≡_ on beFormula -- _≡_ on (formula beFormula) -- _≡_
-- -- -- -- HasSubstantiveDischargeListBeFormulaBeFormula : {A : Set} ⦃ _ : BeFormula A ⦄ → HasSubstantiveDischarge (List A) A
-- -- -- -- HasSubstantiveDischarge._≽_ (HasSubstantiveDischargeListBeFormulaBeFormula ⦃ ⟨ beFormula ⟩ ⦄) +s - = beFormula - ∈ (beFormula <$> +s) -- flip _∈_
-- -- -- -- HasSubstantiveDischargeListFormulaListFormula : {A : Set} ⦃ _ : BeFormula A ⦄ → HasSubstantiveDischarge (List A) (List A)
-- -- -- -- HasSubstantiveDischarge._≽_ (HasSubstantiveDischargeListFormulaListFormula ⦃ ⟨ beFormula ⟩ ⦄) = flip $ _⊆_ on fmap beFormula -- flip _⊆_
-- -- -- -- HasSubstantiveDischargeSequentSequent : ∀ {A : Set} ⦃ _ : BeFormula A ⦄ → HasSubstantiveDischarge (Sequent A) (Sequent A)
-- -- -- -- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeSequentSequent (+ᵗ ╱ +ᵖs) (-ᵗ ╱ -ᵖs) = +ᵗ ≽ -ᵗ × +ᵖs ≽ -ᵖs
-- -- -- -- HasSubstantiveDischargeListSequentSequent : ∀ {A : Set} ⦃ _ : BeFormula A ⦄ → HasSubstantiveDischarge (List $ Sequent A) (Sequent A)
-- -- -- -- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeListSequentSequent χs ι = ∃ λ c → (c ∈ χs) × c ≽ ι
-- -- -- -- instance
-- -- -- -- HasVacuousDischargeList : {A : Set} ⦃ _ : HasSubstantiveDischarge (List A) A ⦄ ⦃ _ : HasNegation A ⦄ → HasVacuousDischarge (List A)
-- -- -- -- HasVacuousDischarge.◁_ (HasVacuousDischargeList {A}) xs = ∃ λ (x : A) → xs ≽ x × xs ≽ ~ x
-- -- -- -- HasVacuousDischargeSequent : {A : Set} ⦃ _ : BeFormula A ⦄ ⦃ _ : HasNegation A ⦄ → HasVacuousDischarge (Sequent A)
-- -- -- -- HasVacuousDischarge.◁_ HasVacuousDischargeSequent (_ ╱ φˢs) = ∃ λ s → (s ∈ φˢs) × (φˢs ≽ s) × (φˢs ≽ ~ s)
-- -- -- -- instance
-- -- -- -- HasSalvationSequent : {A : Set} ⦃ _ : BeFormula A ⦄ ⦃ _ : HasNegation A ⦄ {-⦃ _ : HasVacuousDischarge $ List A ⦄-} → HasSalvation $ Sequent A
-- -- -- -- HasSalvation.isVacuouslyDischargable (HasSalvationSequent {A}) = List A
-- -- -- -- HasSalvation.hasVacuousDischarge HasSalvationSequent = HasVacuousDischargeList
-- -- -- -- HasSalvation.▷_ HasSalvationSequent (φᵗ ╱ φᵖs) = (◁ φᵖs) ⊎ (φᵖs ≽ φᵗ)
-- -- -- -- HasDecidableSalvationSequent : {A : Set} ⦃ bf : BeFormula A ⦄ ⦃ hs : HasNegation A ⦄
-- -- -- -- → HasDecidableSalvation $ Sequent A
-- -- -- -- HasDecidableSalvation.hasSalvation HasDecidableSalvationSequent = HasSalvationSequent
-- -- -- -- --(HasDecidableSalvation.▷? HasDecidableSalvationSequent) (statement₁ ╱ []) = no (foo2 statement₁)
-- -- -- -- HasDecidableSalvation.▷? HasDecidableSalvationSequent = {!!}
-- -- -- -- --(HasDecidableSalvation.▷? HasDecidableSalvationSequent) (statement₁ ╱ []) = no (λ {x → {!!}})
-- -- -- -- --(HasDecidableSalvation.▷? HasDecidableSalvationSequent) (statement₁ ╱ (x₂ ∷ suppositions₁)) = {!!}
-- -- -- -- -- foo1 : ∀ {A} → ⦃ b : BeFormula A ⦄ ⦃ _ : HasNegation A ⦄ (statement₁ : A) → Σ A
-- -- -- -- -- (λ x →
-- -- -- -- -- Σ (BeFormula.formula b x ∈ [])
-- -- -- -- -- (λ _ → BeFormula.formula b (~ x) ∈ []))
-- -- -- -- -- ⊎ (BeFormula.formula b statement₁ ∈ []) →
-- -- -- -- -- ⊥
-- -- -- -- -- foo1 statement₁ (left (fst₁ , () , snd₁))
-- -- -- -- -- foo1 statement₁ (right ())
-- -- -- -- -- foo2 : ∀ {A} → ⦃ b : BeFormula A ⦄ ⦃ _ : HasNegation A ⦄ (statement₁ : A) → ▷ (statement₁ ╱ []) →
-- -- -- -- -- ⊥
-- -- -- -- -- foo2 statement₁ (left (fst₁ , () , snd₁))
-- -- -- -- -- foo2 statement₁ (right ())
| 38.440767
| 173
| 0.455495
|
10868e3465224b5920429036b2d54fa1b4a83b27
| 370
|
agda
|
Agda
|
test/fail/Issue1015OnlyRecord.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/Issue1015OnlyRecord.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/fail/Issue1015OnlyRecord.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
{-# OPTIONS --copatterns #-}
open import Common.Size
record R (i : Size) : Set where
-- Note: not coinductive
constructor delay
field
force : (j : Size< i) → R j
open R
inh : (i : Size) → R i
force (inh i) j = inh j
-- Should give termination error
data ⊥ : Set where
elim : R ∞ → ⊥
elim (delay f) = elim (f ∞)
-- Gives termination error, as expected.
| 15.416667
| 40
| 0.613514
|
128600e3f8e0d5ef252223b50f42d97f7ae9b4d0
| 99
|
agda
|
Agda
|
test/Fail/Issue2420.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2420.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2420.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
module M where
record S : Set₁ where
open M
field
F1 : Set
F2 : {!!}
| 9
| 21
| 0.575758
|
1cc03d57e379e5bd060dc538a5f846b7e4546496
| 4,508
|
agda
|
Agda
|
Cubical/Foundations/Pointed/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Foundations/Pointed/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Pointed/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Foundations.Pointed.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Structure using (typ) public
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Function
Pointed : (ℓ : Level) → Type (ℓ-suc ℓ)
Pointed ℓ = TypeWithStr ℓ (λ x → x)
pt : ∀ {ℓ} (A∙ : Pointed ℓ) → typ A∙
pt = str
Pointed₀ = Pointed ℓ-zero
{- Pointed functions -}
_→∙_ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ')
(A , a) →∙ (B , b) = Σ[ f ∈ (A → B) ] f a ≡ b
_→∙_∙ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
(A →∙ B ∙) .fst = A →∙ B
(A →∙ B ∙) .snd .fst x = pt B
(A →∙ B ∙) .snd .snd = refl
idfun∙ : ∀ {ℓ} (A : Pointed ℓ) → A →∙ A
idfun∙ A .fst x = x
idfun∙ A .snd = refl
{-Pointed equivalences -}
_≃∙_ : ∀ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ')
A ≃∙ B = Σ[ e ∈ fst A ≃ fst B ] fst e (pt A) ≡ pt B
{- Underlying pointed map of an equivalence -}
≃∙map : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} → A ≃∙ B → A →∙ B
fst (≃∙map e) = fst (fst e)
snd (≃∙map e) = snd e
invEquiv∙ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} → A ≃∙ B → B ≃∙ A
fst (invEquiv∙ x) = invEquiv (fst x)
snd (invEquiv∙ {A = A} x) =
sym (cong (fst (invEquiv (fst x))) (snd x)) ∙ retEq (fst x) (pt A)
compEquiv∙ : ∀ {ℓ ℓ' ℓ''} {A : Pointed ℓ} {B : Pointed ℓ'} {C : Pointed ℓ''}
→ A ≃∙ B → B ≃∙ C → A ≃∙ C
fst (compEquiv∙ e1 e2) = compEquiv (fst e1) (fst e2)
snd (compEquiv∙ e1 e2) = cong (fst (fst e2)) (snd e1) ∙ snd e2
Equiv∙J : ∀ {ℓ ℓ'} {B : Pointed ℓ} (C : (A : Pointed ℓ) → A ≃∙ B → Type ℓ')
→ C B (idEquiv (fst B) , refl)
→ {A : _} (e : A ≃∙ B) → C A e
Equiv∙J {ℓ} {ℓ'} {B = B} C ind {A = A} =
uncurry λ e p → help e (pt A) (pt B) p C ind
where
help : ∀ {A : Type ℓ} (e : A ≃ typ B) (a : A) (b : typ B)
→ (p : fst e a ≡ b)
→ (C : (A : Pointed ℓ) → A ≃∙ (fst B , b) → Type ℓ')
→ C (fst B , b) (idEquiv (fst B) , refl)
→ C (A , a) (e , p)
help = EquivJ (λ A e → (a : A) (b : typ B)
→ (p : fst e a ≡ b)
→ (C : (A : Pointed ℓ) → A ≃∙ (fst B , b) → Type ℓ')
→ C (fst B , b) (idEquiv (fst B) , refl)
→ C (A , a) (e , p))
λ a b → J (λ b p
→ (C : (A : Pointed ℓ) → A ≃∙ (fst B , b) → Type ℓ')
→ C (fst B , b)
(idEquiv (fst B) , refl) →
C (typ B , a) (idEquiv (typ B) , p))
λ _ p → p
ua∙ : ∀ {ℓ} {A B : Pointed ℓ} (e : fst A ≃ fst B)
→ fst e (snd A) ≡ snd B → A ≡ B
fst (ua∙ e p i) = ua e i
snd (ua∙ {A = A} e p i) = ua-gluePath e p i
{- J for pointed function types -}
→∙J : ∀ {ℓ ℓ' ℓ''} {A : Pointed ℓ} {B : Type ℓ'}
→ (P : (b₀ : B) (f : A →∙ (B , b₀)) → Type ℓ'')
→ ((f : fst A → B) → P (f (pt A)) (f , refl))
→ {b₀ : B} (f : A →∙ (B , b₀)) → P b₀ f
→∙J {A = A} P ind =
uncurry λ f → J (λ b₀ y → P b₀ (f , y)) (ind f)
{- HIT allowing for pattern matching on pointed types -}
data Pointer {ℓ} (A : Pointed ℓ) : Type ℓ where
pt₀ : Pointer A
⌊_⌋ : typ A → Pointer A
id : ⌊ pt A ⌋ ≡ pt₀
IsoPointedPointer : ∀ {ℓ} {A : Pointed ℓ} → Iso (typ A) (Pointer A)
Iso.fun IsoPointedPointer = ⌊_⌋
Iso.inv (IsoPointedPointer {A = A}) pt₀ = pt A
Iso.inv IsoPointedPointer ⌊ x ⌋ = x
Iso.inv (IsoPointedPointer {A = A}) (id i) = pt A
Iso.rightInv IsoPointedPointer pt₀ = id
Iso.rightInv IsoPointedPointer ⌊ x ⌋ = refl
Iso.rightInv IsoPointedPointer (id i) j = id (i ∧ j)
Iso.leftInv IsoPointedPointer x = refl
Pointed≡Pointer : ∀ {ℓ} {A : Pointed ℓ} → typ A ≡ Pointer A
Pointed≡Pointer = isoToPath IsoPointedPointer
Pointer∙ : ∀ {ℓ} (A : Pointed ℓ) → Pointed ℓ
Pointer∙ A .fst = Pointer A
Pointer∙ A .snd = pt₀
Pointed≡∙Pointer : ∀ {ℓ} {A : Pointed ℓ} → A ≡ (Pointer A , pt₀)
Pointed≡∙Pointer {A = A} i = (Pointed≡Pointer {A = A} i) , helper i
where
helper : PathP (λ i → Pointed≡Pointer {A = A} i) (pt A) pt₀
helper = ua-gluePath (isoToEquiv (IsoPointedPointer {A = A})) id
pointerFun : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B)
→ Pointer A → Pointer B
pointerFun f pt₀ = pt₀
pointerFun f ⌊ x ⌋ = ⌊ fst f x ⌋
pointerFun f (id i) = (cong ⌊_⌋ (snd f) ∙ id) i
pointerFun∙ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B)
→ Pointer∙ A →∙ Pointer∙ B
pointerFun∙ f .fst = pointerFun f
pointerFun∙ f .snd = refl
| 34.945736
| 76
| 0.533496
|
4ab5a541e6bb8825a3cea85a9398212a5a02346b
| 415
|
agda
|
Agda
|
agda/HLevels.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/HLevels.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/HLevels.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module HLevels where
open import Path
open import Cubical.Foundations.Everything
using (isProp
;isSet
;isContr
;isPropIsContr
;isProp→isSet
;isOfHLevel→isOfHLevelDep
;hProp
;isSetHProp
;isPropIsProp
)
public
open import Level
open import Data.Sigma
hSet : ∀ ℓ → Type (ℓsuc ℓ)
hSet ℓ = Σ (Type ℓ) isSet
| 17.291667
| 42
| 0.614458
|
1c186540eede2928925622247536273631451904
| 24,950
|
agda
|
Agda
|
GauInt/Properties.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
GauInt/Properties.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
GauInt/Properties.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
-- This file gives the definition of Gaussian Integers, the addition
-- and multiplication on them, and shows that they form a commutative
-- ring, and other properties. All the proofs are straightforward.
{-# OPTIONS --without-K --safe #-}
module GauInt.Properties where
-- imports from local.
open import GauInt.Instances
open import Instances
open import GauInt.Base using (𝔾 ; _+_i ; _ᶜ ; Re ; Im ; _+0i ; _+0i' ; 0𝔾)
open import Integer.Properties
-- imports from stdlib and Agda.
open import Level using (0ℓ)
open import Relation.Nullary using (yes; no; ¬_)
open import Relation.Binary using (DecidableEquality ; Setoid ; DecSetoid ; tri< ; tri≈ ; tri>)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Data.Product using (proj₁; proj₂; _,_ ; _×_)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) renaming ([_,_]′ to ⊎-elim)
open import Data.Nat as Nat using (ℕ; suc; zero)
import Data.Nat.Properties as NatP
open import Data.Integer.Properties as IntP
using (+-assoc ; +-identityˡ ; +-identityʳ ; *-identityˡ ; +-inverseˡ ; +-inverseʳ ; +-comm ; 0≤i⇒+∣i∣≡i ; +-mono-≤ ; +-mono-<-≤ ; +-mono-≤-<)
open import Data.Integer as Int
using (ℤ ; +_ ; NonNegative ; -[1+_] ; +[1+_] ; +≤+ ; +<+ ; ∣_∣ ; 0ℤ ; +0)
import Data.Integer.Solver as IS
open IS.+-*-Solver
open import Algebra.Bundles as B
import Algebra.Morphism as Morphism
open import Algebra.Structures {A = 𝔾} _≡_
open import Function.Base using (_$_)
module 𝔾toℕ = Morphism.Definitions 𝔾 ℕ _≡_
module ℕto𝔾 = Morphism.Definitions ℕ 𝔾 _≡_
open import Algebra.Definitions (_≡_ {A = 𝔾}) using (AlmostLeftCancellative)
-- ----------------------------------------------------------------------
-- Equality
-- Injections are injective.
+0i'-injective : ∀ {a b} -> a +0i' ≡ b +0i' → a ≡ b
+0i'-injective refl = refl
+0i-injective : ∀ {m n} -> m +0i ≡ n +0i → m ≡ n
+0i-injective refl = refl
-- Decidable equality on 𝔾.
infix 4 _≟_
_≟_ : DecidableEquality 𝔾
_≟_ x@(a + b i) y@(c + d i) with a Int.≟ c | b Int.≟ d
... | yes p | yes q = yes (cong₂ _+_i p q)
... | yes p | no ¬q = no (λ { refl → ¬q refl})
... | no ¬p | hyp = no (λ { refl → ¬p refl})
≡-setoid : Setoid 0ℓ 0ℓ
≡-setoid = setoid 𝔾
≡-decSetoid : DecSetoid 0ℓ 0ℓ
≡-decSetoid = decSetoid _≟_
-- ----------------------------------------------------------------------
-- Properties of _+_
-- Associativity of addition.
assoc-+ : ∀ (x y z : 𝔾) -> ((x + y) + z) ≡ (x + (y + z))
assoc-+ x@(a + b i) y@(c + d i) z@(e + f i) = begin
(((a + b i) + (c + d i)) + (e + f i)) ≡⟨ refl ⟩
((a + c + e) + (b + d + f) i) ≡⟨ cong₂ _+_i (+-assoc a c e) (+-assoc b d f) ⟩
((a + (c + e)) + (b + (d + f)) i) ≡⟨ refl ⟩
(x + (y + z)) ∎
-- Left additive identity.
leftId-+ : ∀ (x : 𝔾) -> 0# + x ≡ x
leftId-+ x@(a + b i) = begin
(0# + 0# i) + (a + b i) ≡⟨ refl ⟩
-- cannot parse if remove the outer layer parenthese.
((0# + a) + (0# + b) i) ≡⟨ cong₂ _+_i (+-identityˡ a) (+-identityˡ b) ⟩
(a + b i) ∎
-- Right additive identity.
rightId-+ : ∀ (x : 𝔾) -> (x + 0#) ≡ x
rightId-+ x@(a + b i) = begin
(a + b i) + (0# + 0# i) ≡⟨ refl ⟩
((a + 0#) + (b + 0#) i) ≡⟨ cong₂ _+_i (+-identityʳ a) (+-identityʳ b) ⟩
(a + b i) ∎
-- Left additive inverse.
leftInv-+ : ∀ (x : 𝔾) -> (- x) + x ≡ 0#
leftInv-+ x@(a + b i) = cong₂ _+_i (+-inverseˡ a) (+-inverseˡ b)
-- Right additive inverse.
rightInv-+ : ∀ (x : 𝔾) -> x + (- x) ≡ 0#
rightInv-+ x@(a + b i) = cong₂ _+_i (+-inverseʳ a) (+-inverseʳ b)
-- Addition is commutative.
comm-+ : (x y : 𝔾) → (x + y) ≡ (y + x)
comm-+ x@(a + b i) y@(c + d i) = cong₂ _+_i (+-comm a c) (+-comm b d)
-- ----------------------------------------------------------------------
-- Structures for addition
+-isMagma : IsMagma _+_
+-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _+_
}
+-isSemigroup : IsSemigroup _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = assoc-+
}
+-isCommutativeSemigroup : IsCommutativeSemigroup _+_
+-isCommutativeSemigroup = record
{ isSemigroup = +-isSemigroup
; comm = comm-+
}
+-0-isMonoid : IsMonoid _+_ 0#
+-0-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = leftId-+ , rightId-+
}
+-0-isCommutativeMonoid : IsCommutativeMonoid _+_ 0#
+-0-isCommutativeMonoid = record
{ isMonoid = +-0-isMonoid
; comm = comm-+
}
+-0-isGroup : IsGroup _+_ 0# (-_)
+-0-isGroup = record
{ isMonoid = +-0-isMonoid
; inverse = leftInv-+ , rightInv-+
; ⁻¹-cong = cong (-_)
}
+-isAbelianGroup : IsAbelianGroup _+_ 0# (-_)
+-isAbelianGroup = record
{ isGroup = +-0-isGroup
; comm = comm-+
}
-- ----------------------------------------------------------------------
-- Bundles for addition
+-magma : Magma 0ℓ 0ℓ
+-magma = record
{ isMagma = +-isMagma
}
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
+-commutativeSemigroup = record
{ isCommutativeSemigroup = +-isCommutativeSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
+-0-abelianGroup : AbelianGroup 0ℓ 0ℓ
+-0-abelianGroup = record
{ isAbelianGroup = +-isAbelianGroup
}
-- ----------------------------------------------------------------------
-- Properties of multiplication
-- Associativity of multiplication.
assoc-* : ∀ (x y z : 𝔾) -> ((x * y) * z) ≡ (x * (y * z))
assoc-* x@(a + b i) y@(c + d i) z@(e + f i) = begin
(((a + b i) * (c + d i)) * (e + f i)) ≡⟨ refl ⟩
((a * c - b * d) + (a * d + b * c) i) * (e + f i) ≡⟨ refl ⟩
((a * c - b * d) * e - (a * d + b * c) * f) + ((a * c - b * d) * f + (a * d + b * c) * e) i ≡⟨ cong₂ _+_i (let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (((a * c) - (b * d)) * e) - (((a * d) + (b * c)) * f) := (a * ((c * e) - (d * f))) - (b * ((c * f) + (d * e)))) refl a b c d e f)) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in
(solve 6 (\ a b c d e f -> (((a * c) - (b * d)) * f) + (((a * d) + (b * c)) * e) := (a * ((c * f) + (d * e))) + (b * ((c * e) - (d * f)))) refl a b c d e f))) ⟩
((a * (c * e - d * f) - b * (c * f + d * e) ) + (a * (c * f + d * e) + b * (c * e - d * f)) i ) ≡⟨ refl ⟩
((a + b i) * ((c * e - d * f) + (c * f + d * e) i) ) ≡⟨ refl ⟩
(x * (y * z)) ∎
-- Left multiplicative identity.
leftId-* : ∀ (x : 𝔾) -> (1# * x) ≡ x
leftId-* x@(a + b i) = begin
(1# + 0# i) * (a + b i) ≡⟨ refl ⟩
((1# * a - 0# * b) + (1# * b + 0# * a) i) ≡⟨ cong₂ _+_i (let _*_ = _:*_ in let _-_ = _:-_ in (solve 2 (\ a b -> (con 1# * a) - (con 0# * b) := con 1# * a) refl a b)) ( (let _*_ = _:*_ in let _+_ = _:+_ in (solve 2 (\ a b -> (con 1# * b) + (con 0# * a) := con 1# * b) refl a b))) ⟩
((1# * a) + (1# * b) i) ≡⟨ cong₂ _+_i (*-identityˡ a) (*-identityˡ b) ⟩
(a + b i) ∎
-- Right multiplicative identity.
rightId-* : ∀ (x : 𝔾) -> (x * 1#) ≡ x
rightId-* x@(a + b i) = begin
(a + b i) * (1# + 0# i) ≡⟨ refl ⟩
(( a * 1# - b * 0#) + ( a * 0# + b * 1# ) i) ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _-_ = _:-_ in (solve 2 (\ a b -> (a * con 1# ) - (b * con 0# ) := con 1# * a) refl a b))) ((let _*_ = _:*_ in let _+_ = _:+_ in (solve 2 (\ a b -> (a * con 0#) + (b * con 1# ) := con 1# * b) refl a b))) ⟩
((1# * a) + (1# * b) i) ≡⟨ cong₂ _+_i (*-identityˡ a) (*-identityˡ b) ⟩
(a + b i) ∎
-- Zero leftly times any number is zero.
leftZero : ∀ x -> (0# + 0# i) * x ≡ (0# + 0# i)
leftZero x@(a + b i) = begin
(0# + 0# i) * (a + b i) ≡⟨ refl ⟩
(0# * a - 0# * b) + (0# * a - 0# * b) i ≡⟨ refl ⟩
0# + 0# i ∎
-- Zero rightly times any number is zero.
rightZero : ∀ x -> x * (0# + 0# i) ≡ (0# + 0# i)
rightZero x@(a + b i) = begin
(a + b i) * (0# + 0# i) ≡⟨ refl ⟩
(a * 0# - b * 0# ) + (a * 0# + b * 0# ) i ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 2 (\ a b -> (a * con 0#) - (b * con 0# ) := con 0#) refl a b))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 2 (\ a b -> (a * con 0#) + (b * con 0# ) := con 0#) refl a b))) ⟩
0# + 0# i ∎
-- Left multiplication is distributive over addition.
*-DistributesOver-+ˡ : ∀ (x y z : 𝔾) -> (x * (y + z)) ≡ ((x * y) + (x * z))
*-DistributesOver-+ˡ x@(a + b i) y@(c + d i) z@(e + f i) = begin
x * (y + z) ≡⟨ refl ⟩
(a * (c + e) - b * (d + f) + (a * (d + f) + b * (c + e)) i) ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (a * (c + e)) - (b * (d + f) ) := ((a * c) - (b * d)) + ((a * e) - (b * f)) ) refl a b c d e f))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (a * (d + f)) + (b * (c + e) ) := ((a * d) + (b * c)) + ((a * f) + (b * e)) ) refl a b c d e f))) ⟩
((a * c - b * d) + (a * e - b * f)) + ((a * d + b * c) + (a * f + b * e)) i ≡⟨ refl ⟩
((x * y) + (x * z)) ∎
-- Right multiplication is distributive over addition.
*-DistributesOver-+ʳ : ∀ (x y z : 𝔾) -> ((y + z) * x) ≡ (y * x) + (z * x)
*-DistributesOver-+ʳ x@(a + b i) y@(c + d i) z@(e + f i) = begin
(y + z) * x ≡⟨ refl ⟩
((c + e) * a - (d + f) * b + ( (c + e) * b + (d + f) * a ) i) ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> ((c + e) * a) - ((d + f) * b ) := ((c * a ) - (d * b)) + ((e * a) - (f * b )) ) refl a b c d e f))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> ((c + e) * b) + ((d + f) * a ) := ((c * b ) + (d * a)) + ((e * b) + (f * a )) ) refl a b c d e f))) ⟩
((c * a - d * b) + (e * a - f * b)) + ((c * b + d * a ) + (e * b + f * a )) i ≡⟨ refl ⟩
((y * x) + (z * x)) ∎
-- Multiplicaton is commutative.
comm-* : ∀ (x y : 𝔾) -> x * y ≡ y * x
comm-* x@(a + b i) y@(c + d i) = begin
x * y ≡⟨ refl ⟩
(a * c - b * d) + (a * d + b * c) i ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 4 (\ a b c d -> (a * c) - (b * d) := (c * a ) - (d * b)) refl a b c d))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 4 (\ a b c d -> (a * d) + (b * c) := (c * b) + (d * a)) refl a b c d))) ⟩
(c * a - d * b) + (c * b + d * a) i ≡⟨ refl ⟩
(y * x) ∎
-- ----------------------------------------------------------------------
-- Structures for multiplication
*-isMagma : IsMagma _*_
*-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _*_
}
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = assoc-*
}
*-isCommutativeSemigroup : IsCommutativeSemigroup _*_
*-isCommutativeSemigroup = record
{ isSemigroup = *-isSemigroup
; comm = comm-*
}
*-1-isMonoid : IsMonoid _*_ 1#
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = leftId-* , rightId-*
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _*_ 1#
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; comm = comm-*
}
-- ----------------------------------------------------------------------
-- Structures for multiplication and addition
+-*-isSemiring : IsSemiring _+_ _*_ 0# 1#
+-*-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-0-isCommutativeMonoid
; *-isMonoid = *-1-isMonoid
; distrib = *-DistributesOver-+ˡ , *-DistributesOver-+ʳ
}
; zero = leftZero , rightZero
}
+-*-isCommutativeSemiring : IsCommutativeSemiring _+_ _*_ 0# 1#
+-*-isCommutativeSemiring = record
{ isSemiring = +-*-isSemiring
; *-comm = comm-*
}
+-*-isRing : IsRing _+_ _*_ -_ 0# 1#
+-*-isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-isMonoid = *-1-isMonoid
; distrib = *-DistributesOver-+ˡ , *-DistributesOver-+ʳ
; zero = leftZero , rightZero
}
+-*-isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0# 1#
+-*-isCommutativeRing = record
{ isRing = +-*-isRing
; *-comm = comm-*
}
------------------------------------------------------------------------
-- Bundles for multiplication
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
*-commutativeSemigroup = record
{ isCommutativeSemigroup = *-isCommutativeSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
------------------------------------------------------------------------
-- Bundles for multiplication and addition
+-*-semiring : Semiring 0ℓ 0ℓ
+-*-semiring = record
{ isSemiring = +-*-isSemiring
}
+-*-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
+-*-commutativeSemiring = record
{ isCommutativeSemiring = +-*-isCommutativeSemiring
}
+-*-ring : B.Ring 0ℓ 0ℓ
+-*-ring = record
{ isRing = +-*-isRing
}
+-*-commutativeRing : CommutativeRing 0ℓ 0ℓ
+-*-commutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
}
-- ----------------------------------------------------------------------
-- Properties of Re and Im
-- Re x + Im x i = x
Re+Im*i : ∀ {x} -> Re x + Im x i ≡ x
Re+Im*i {x + x₁ i} = refl
-- Re (y * y ᶜ) ≡ + rank y
Re[yyᶜ]=rank : ∀ {y : 𝔾} -> Re (y * y ᶜ) ≡ + rank y
Re[yyᶜ]=rank {y@(a + b i)} = sym $ begin
+ (rank y) ≡⟨ refl ⟩
+ (rank (a + b i)) ≡⟨ refl ⟩
+ ∣ a * a + b * b ∣ ≡⟨ cong +_ (tri-eq' a b) ⟩
+ (∣ a * a ∣ + ∣ b * b ∣) ≡⟨ refl ⟩
+ ∣ a * a ∣ + + ∣ b * b ∣ ≡⟨ cong₂ _+_ (+∣a*a∣=a*a a) (+∣a*a∣=a*a b) ⟩
a * a + b * b ≡⟨ solve 2 (\ a b -> a :* a :+ b :* b := a :* a :- b :* (:- b)) refl a b ⟩
a * a - b * (- b) ≡⟨ refl ⟩
Re ((a * a - b * (- b)) + 0ℤ i) ≡⟨ refl ⟩
Re ((a * a - b * (- b)) + (a * (- b) + b * a) i) ≡⟨ refl ⟩
Re (y * y ᶜ) ∎
-- Im y * y ᶜ = 0
Im[yyᶜ]=0 : ∀ {y : 𝔾} -> Im (y * y ᶜ) ≡ 0#
Im[yyᶜ]=0 {y@(a + b i)} = begin
Im (y * y ᶜ) ≡⟨ refl ⟩
Im ((a * a - b * (- b)) + (a * (- b) + b * a) i) ≡⟨ refl ⟩
a * (- b) + b * a ≡⟨ solve 2 (\ a b -> a :* (:- b) :+ b :* a := con 0#) refl a b ⟩
0# ∎
-- ----------------------------------------------------------------------
-- Properties of conjugation
-- Conjugation is injective.
ᶜ-injective : ∀ {x} -> x ᶜ ≡ 0# -> x ≡ 0#
ᶜ-injective {+ 0 + + 0 i} eq = refl
-- y * y ᶜ = rank y
y*yᶜ=rank : ∀ {y : 𝔾} -> y * y ᶜ ≡ rank y +0i
y*yᶜ=rank {y@(a + b i)} = begin
y * y ᶜ ≡⟨ sym $ Re+Im*i ⟩
Re (y * y ᶜ) + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (Re[yyᶜ]=rank {y}) (Im[yyᶜ]=0 {y}) ⟩
+ rank y + 0# i ∎
-- ----------------------------------------------------------------------
-- Properties of rank
-- rank on 𝔾 is homomorphic in multiplication.
rank-*-commute : 𝔾toℕ.Homomorphic₂ rank _*_ Nat._*_
rank-*-commute x@(a + b i) y@(c + d i) = claim
where
claim : rank (x * y) ≡ rank x * rank y
claim = begin
rank (x * y) ≡⟨ refl ⟩
rank ((a * c - b * d) + (a * d + b * c) i) ≡⟨ refl ⟩
∣ (a * c - b * d)^2 + (a * d + b * c)^2 ∣ ≡⟨ cong ∣_∣ (solve 4 (λ a b c d → (a :* c :- b :* d) :* (a :* c :- b :* d) :+ (a :* d :+ b :* c) :* (a :* d :+ b :* c) := (a :* a :+ b :* b) :* (c :* c :+ d :* d)) refl a b c d) ⟩
∣ (a ^2 + b ^2) * (c ^2 + d ^2) ∣ ≡⟨ IntP.abs-*-commute ((a ^2 + b ^2)) ((c ^2 + d ^2)) ⟩
∣ a ^2 + b ^2 ∣ * ∣ c ^2 + d ^2 ∣ ≡⟨ refl ⟩
rank x * rank y ∎
rank=∣Re[y*yᶜ]∣ : ∀ (x : 𝔾) -> rank x ≡ ∣ Re (x * x ᶜ) ∣
rank=∣Re[y*yᶜ]∣ x@(a + b i) = begin
rank (a + b i) ≡⟨ refl ⟩
∣ a * a + b * b ∣ ≡⟨ cong ∣_∣ (solve 2 (λ a b → a :* a :+ b :* b := a :* a :- b :* (:- b)) refl a b) ⟩
∣ a * a - b * (- b) ∣ ≡⟨ refl ⟩
∣ Re ((a * a - b * (- b)) + 0ℤ i) ∣ ≡⟨ refl ⟩
∣ Re ((a * a - b * (- b)) + (a * (- b) + b * a) i) ∣ ≡⟨ refl ⟩
∣ Re (x * x ᶜ) ∣ ∎
-- rank y + 0 i = y * y ᶜ
rank+0i=y*yᶜ : ∀ {y : 𝔾} -> (rank y) +0i ≡ y * y ᶜ
rank+0i=y*yᶜ {y} = sym $ begin
y * y ᶜ ≡⟨ sym $ Re+Im*i ⟩
Re (y * y ᶜ) + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (Re[yyᶜ]=rank {y}) (Im[yyᶜ]=0 {y}) ⟩
+ rank y + 0# i ∎
-- ----------------------------------------------------------------------
-- Injection preserves SemiRing Structure
+0i-+-commute : ℕto𝔾.Homomorphic₂ _+0i Nat._+_ _+_
+0i-+-commute a b = refl
+0i-*-commute : ℕto𝔾.Homomorphic₂ _+0i Nat._*_ _*_
+0i-*-commute a b rewrite NatP.*-zeroˡ a | NatP.*-zeroˡ b | NatP.*-zeroʳ a | NatP.*-zeroʳ b | sym (IntP.pos-distrib-* a b) | IntP.+-identityʳ (+ a * + b) = refl
0+0i=0 : 0 +0i ≡ 0#
0+0i=0 = refl
1+0i=1 : 1 +0i ≡ 1#
1+0i=1 = refl
-- ----------------------------------------------------------------------
-- Domain Structrue on 𝔾
-- Some auxillaries.
-- Zero is unique.
unique0 : ∀ {a b} -> (a + b i) ≡ 0# -> a ≡ 0ℤ × b ≡ 0ℤ
unique0 {.+0} {.+0} refl = refl , refl
-- Conversely, if a + bi ≠ 0 then at least one of a and b is not zero.
unique0' : ∀ {a b} -> ¬ (a + b i) ≡ 0# -> ¬ a ≡ 0ℤ ⊎ ¬ b ≡ 0ℤ
unique0' {a@(+_ zero)} {b@(+_ zero)} neq with neq refl
... | ()
unique0' {+_ zero} {+[1+ n ]} neq = inj₂ (λ ())
unique0' {+_ zero} { -[1+_] n} neq = inj₂ (λ ())
unique0' {+[1+ n ]} {b} neq = inj₁ (λ ())
unique0' { -[1+_] n} {b} neq = inj₁ (λ ())
-- Make an equation onesided.
oneside : ∀ {a b : 𝔾} -> a ≡ b -> a - b ≡ 0#
oneside {a} {b} eq rewrite eq = rightInv-+ b
-- Make an equation twosided.
twoside : ∀ {a b : 𝔾} -> a - b ≡ 0# -> a ≡ b
twoside {a} {b} eq = sym $ -‿injective $ +-inverseʳ-unique a (- b) eq
where
open import Algebra.Properties.Ring +-*-ring
-- Make an equation twosided, ℤ version.
twosideℤ : ∀ {a b : ℤ} -> a - b ≡ 0# -> a ≡ b
twosideℤ {a} {b} eq = sym (PRI.-‿injective (PRI.+-inverseʳ-unique a (- b) eq ))
where
import Algebra.Properties.Ring IntP.+-*-ring as PRI
-- We show zero divisor is necessary zero (equivalent to left or right
-- cancellation in a commutative ring), which makes 𝔾 an integral
-- domain.
zero-divisor-is-zero : ∀ {x y : 𝔾} -> x * y ≡ 0# -> ¬ x ≡ 0# -> y ≡ 0#
zero-divisor-is-zero {x@(a + b i)} {y@(c + d i)} eq neq = cong₂ _+_i (proj₁ step6) (proj₂ step6)
where
open ≡-Reasoning
open IS.+-*-Solver
-- 0 = x * y = (a * c - b * d) + (a * d + b * c) i, together with
-- c + d i ≠ 0, we can derive a = 0 and b = 0, contradicting x ≠
-- 0. The proof idea is:
--
-- step0 : a * c - b * d = 0 and a * d + b * c = 0
-- step1 : a * c * c - b * d * c = 0
-- step2 : a * d * d + b * c * d = 0
-- s1,s2 ⇒ step1&2 : a * (c * c + d * d) = 0
-- step3 : a * c * d - b * d * d = 0
-- step4 : a * d * c + b * c * c = 0
-- s3,s4 ⇒ step3&4 : b * (c * c + d * d) = 0
-- one of a b nonzero ⇒ step5 : (c * c + d * d) = 0
-- step5 ⇒ step6 : c = 0 and d = 0
-- step0 : a * c - b * d = 0 and a * d + b * c = 0
step0 : a * c - b * d ≡ 0# × a * d + b * c ≡ 0#
step0 = unique0 eq
-- step1 : a * c * c - b * d * c = 0
step1 : a * c * c - b * d * c ≡ 0#
step1 = begin
a * c * c - b * d * c ≡⟨ solve 4 (\ a b c d -> a :* c :* c :- b :* d :* c := (a :* c :- b :* d) :* c) refl a b c d ⟩
(a * c - b * d) * c ≡⟨ cong (_* c) (proj₁ step0) ⟩
0ℤ * c ≡⟨ refl ⟩
0ℤ ∎
-- step2 : a * d * d + b * c * d = 0
step2 : a * d * d + b * c * d ≡ 0#
step2 = begin
a * d * d + b * c * d ≡⟨ solve 4 (\ a b c d -> a :* d :* d :+ b :* c :* d := (a :* d :+ b :* c) :* d) refl a b c d ⟩
(a * d + (b * c)) * d ≡⟨ cong (_* d) (proj₂ step0) ⟩
0ℤ * d ≡⟨ refl ⟩
0ℤ ∎
-- c1,c2 ⇒ step1&2 : a * (c * c + d * d) = 0
step1&2 : a * (c * c + d * d) ≡ 0#
step1&2 = begin
a * (c * c + d * d) ≡⟨ solve 4 (\ a b c d -> a :* (c :* c :+ d :* d) := (a :* c :* c :- b :* d :* c) :+ (a :* d :* d :+ b :* c :* d) ) refl a b c d ⟩
(a * c * c - b * d * c) + (a * d * d + b * c * d) ≡⟨ cong₂ _+_ step1 step2 ⟩
0# ∎
-- step3 : a * c * d - b * d * d = 0
step3 : a * c * d - b * d * d ≡ 0#
step3 = begin
a * c * d - b * d * d ≡⟨ solve 4 (\ a b c d -> a :* c :* d :- b :* d :* d := (a :* c :- b :* d) :* d) refl a b c d ⟩
(a * c - b * d) * d ≡⟨ cong (_* d) (proj₁ step0) ⟩
0ℤ * d ≡⟨ refl ⟩
0ℤ ∎
-- step4 : a * d * c + b * c * c = 0
step4 : a * d * c + b * c * c ≡ 0#
step4 = begin
a * d * c + b * c * c ≡⟨ solve 4 (\ a b c d -> a :* d :* c :+ b :* c :* c := (a :* d :+ b :* c) :* c) refl a b c d ⟩
(a * d + (b * c)) * c ≡⟨ cong (_* c) (proj₂ step0) ⟩
0ℤ * c ≡⟨ refl ⟩
0ℤ ∎
-- s3,s4 ⇒ step3&4 : b * (c * c + d * d) = 0
step3&4 : b * (c * c + d * d) ≡ 0#
step3&4 = begin
b * (c * c + d * d) ≡⟨ solve 4 (\ a b c d -> b :* (c :* c :+ d :* d) := :- (a :* c :* d :- b :* d :* d) :+ (a :* d :* c :+ b :* c :* c) ) refl a b c d ⟩
- (a * c * d - b * d * d) + (a * d * c + b * c * c) ≡⟨ cong₂ (\x y -> (- x) + y) step3 step4 ⟩
0# ∎
-- one of a b nonzero ⇒ step5 : (c * c + d * d) = 0
-- some auxillary lemma.
aux : ∀ {a : ℤ} -> a * 0# ≡ 0#
aux {a} rewrite IntP.*-comm a 0# = refl
step1&2' : a * (c * c + d * d) ≡ a * 0#
step1&2' rewrite aux {a} = step1&2
step3&4' : b * (c * c + d * d) ≡ b * 0#
step3&4' rewrite aux {b} = step3&4
step5 : c * c + d * d ≡ 0#
step5 = ⊎-elim (λ x₁ → IntP.*-cancelˡ-≡ a (c * c + d * d) 0# {{myins2 {a} {x₁}}} step1&2') (λ x₁ → IntP.*-cancelˡ-≡ b (c * c + d * d) 0# {{myins2 {b} {x₁}}} step3&4') (unique0' neq)
where
-- We need a translation from non-equality to NonZero predicate.
open import Agda.Builtin.Unit
myins2 : ∀ {x : ℤ} -> {n0 : ¬ x ≡ 0ℤ} -> NonZero x
myins2 {+_ zero} {n0} with n0 refl
... | ()
myins2 {+[1+ n ]} {n0} = record { nonZero = tt }
myins2 { -[1+_] n} {n0} = record { nonZero = tt }
-- step5 ⇒ step6 : c = 0 and d = 0
step6 : c ≡ 0# × d ≡ 0#
step6 = aa+bb=0⇒a=0×b=0 step5
-- Almost left cancellative.
*-alc-𝔾 : AlmostLeftCancellative 0𝔾 _*_
*-alc-𝔾 {x@(a + b i)} y@(c + d i) z@(e + f i) neq eq = y=z
where
onesided-eq : x * (y + (- z)) ≡ 0#
onesided-eq = begin
x * (y + (- z)) ≡⟨ *-DistributesOver-+ˡ x y (- z) ⟩
x * y + x * (- z) ≡⟨ refl ⟩
x * y + (a + b i) * (- e + - f i) ≡⟨ cong (λ t → x * y + t) refl ⟩
x * y + ((a * - e - b * - f ) + (a * - f + b * - e) i) ≡⟨ cong (λ t → x * y + t) (cong₂ _+_i (solve 4 (\a e b f -> a :* :- e :- b :* :- f := :- (a :* e :- b :* f)) refl a e b f) (solve 4 (\a e b f -> a :* :- f :+ b :* :- e := :- (a :* f :+ b :* e)) refl a e b f)) ⟩
x * y + (- (a * e - b * f) + - (a * f + b * e) i) ≡⟨ cong (λ t → x * y + t) refl ⟩
x * y + (- (x * z)) ≡⟨ oneside eq ⟩
0# ∎
where
open ≡-Reasoning
open IS.+-*-Solver
y-z=0 : (y + (- z)) ≡ 0#
y-z=0 = zero-divisor-is-zero onesided-eq neq
y=z : y ≡ z
y=z = twoside y-z=0
-- Multiplication commutativity plus left cancellative implies 𝔾 is an
-- commutative Domain. Knowing this, we can show e.g.
y≠0⇒y*yᶜ≠0 : ∀ {y} -> ¬ y ≡ 0# -> ¬ y * y ᶜ ≡ 0#
y≠0⇒y*yᶜ≠0 {y} n0 eq = ⊥-elim (n0' e0)
where
open import Data.Empty
n0' : ¬ y ᶜ ≡ 0#
n0' x with n0 (ᶜ-injective {y} x)
... | ()
eq' : y * y ᶜ ≡ y * 0#
eq' = begin
y * y ᶜ ≡⟨ eq ⟩
0# ≡⟨ sym $ rightZero y ⟩
y * 0# ∎
where
open IS.+-*-Solver
open ≡-Reasoning
e0 : y ᶜ ≡ 0#
e0 = *-alc-𝔾 {y} (y ᶜ) 0# n0 eq'
y≠0#⇒rank≠0 : ∀ {y : 𝔾} -> ¬ y ≡ 0# -> ¬ rank y ≡ 0#
y≠0#⇒rank≠0 {y} n0 = rank≠0
where
open import Data.Empty
y*yᶜ≠0 : ¬ y * y ᶜ ≡ 0#
y*yᶜ≠0 = y≠0⇒y*yᶜ≠0 n0
rank≠0 : ¬ rank y ≡ 0#
rank≠0 e = ⊥-elim (y*yᶜ≠0 y*yᶜ=0)
where
y*yᶜ=0 : y * y ᶜ ≡ 0#
y*yᶜ=0 = begin
y * y ᶜ ≡⟨ sym $ Re+Im*i ⟩
Re (y * y ᶜ) + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (Re[yyᶜ]=rank {y}) refl ⟩
+ rank y + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (cong +_ e) (Im[yyᶜ]=0 {y}) ⟩
0# ∎
where
open IS.+-*-Solver
open ≡-Reasoning
rank=0⇒y=0 : ∀ {y : 𝔾} -> rank y ≡ 0# -> y ≡ 0#
rank=0⇒y=0 {y@(a + b i)} eq0 = y=0
where
eq0' : a * a + b * b ≡ 0#
eq0' = IntP.∣i∣≡0⇒i≡0 eq0
s1 : a ≡ 0ℤ × b ≡ 0ℤ
s1 = aa+bb=0⇒a=0×b=0 eq0'
y=0 : y ≡ 0#
y=0 with s1
... | fst , snd rewrite fst | snd = refl
rank≥1 : ∀ {y : 𝔾} -> ¬ y ≡ 0# -> 1# ≤ rank y
rank≥1 {y} n0 = aux (rank y) (y≠0#⇒rank≠0 {y} n0)
where
aux : ∀ (n : ℕ) -> ¬ n ≡ 0 -> 1 ≤ n
aux zero n0' with n0' refl
... | ()
aux (suc n) n0' = Nat.s≤s Nat.z≤n
ranky<1⇒y=0 : ∀ (y : 𝔾) -> rank y < 1# -> y ≡ 0#
ranky<1⇒y=0 y r = rank=0⇒y=0 {y} ranky=0
where
aux : ∀ (n : ℕ) -> n < 1 -> n ≡ 0
aux .zero (Nat.s≤s Nat.z≤n) = refl
ranky=0 : rank y ≡ 0
ranky=0 = aux (rank y) r
-- ----------------------------------------------------------------------
-- Properties of NonZero
| 35.140845
| 446
| 0.448257
|
cba94de9123442f3966656771a9ec295eaf6d359
| 746
|
agda
|
Agda
|
test/Succeed/Issue2484-6.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2484-6.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2484-6.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --sized-types #-}
module _ (_ : Set) where
open import Agda.Builtin.Size
postulate
I : Set
record ∃ (B : I → Set) : Set where
constructor _,_
field
proj₁ : I
proj₂ : B proj₁
module M (_ : Set₁) where
mutual
data P (i : Size) (x y : I) : Set where
⟨_⟩ : ∃ (Q i x) → P i x y
record Q (i : Size) (x y : I) : Set where
coinductive
field
force : {j : Size< i} → P j x y
open M Set
postulate
map : (B : I → Set) → (∀ x → B x → B x) → ∃ B → ∃ B
lemma : ∀ x y i → Q i x y → Q i x y
p : ∀ x i → P i x x
q′ : ∀ x i → ∃ λ y → Q i x y
q : ∀ x i → Q i x x
p x i = ⟨ map _ (λ y → lemma x y _) (q′ x _) ⟩
q′ x i = x , q x i
Q.force (q x i) {j} = p _ _
| 18.195122
| 60
| 0.458445
|
c5d3f6d008b8d44e74c85ea6d1e2d8948635f273
| 2,337
|
agda
|
Agda
|
test/Succeed/Issue1833.agda
|
sseefried/agda
|
6b13364d36eeb60d8ec15eaf8effe23c73401900
|
[
"BSD-2-Clause"
] | 1
|
2022-02-05T01:20:23.000Z
|
2022-02-05T01:20:23.000Z
|
test/Succeed/Issue1833.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Succeed/Issue1833.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | null | null | null |
module _ where
open import Common.Prelude hiding (_>>=_)
open import Common.Reflection
open import Agda.Builtin.Sigma
infix -100 This:_ this:_
data This:_ {a} {A : Set a} : A → Set where
this:_ : ∀ x → This: x
macro
runT : Tactic → Tactic
runT m = m
evalT : ∀ {a} {A : Set a} → TC A → Tactic
evalT m hole = m >>= quoteTC >>= unify hole
-- The context on the rhs of each of the two functions below is the same, a single String
Γ : Telescope
Γ = ("s" , vArg (def (quote String) [])) ∷ []
context-Γ₀ : String → This: Γ
context-Γ₀ s = this: evalT getContext
module _ (S : String) where
Γ' : Telescope
Γ' = ("S" , vArg (def (quote String) [])) ∷ []
context-Γ₁ : This: Γ'
context-Γ₁ = this: evalT getContext
downMap : {A : Set} → (Nat → A) → Nat → List A
downMap f zero = []
downMap f (suc n) = f n ∷ downMap f n
f-type : Term
f-type = def (quote String) []
f-tel : Nat → List (Σ String λ _ → Arg Type)
f-tel n = downMap (λ _ → "_" , vArg unknown) n
f-pats : Nat → List (Arg Pattern)
f-pats n = downMap (λ x → vArg (var x)) n
f-term : Nat → Term
f-term n = var n []
defineFresh : Nat → Nat → TC QName
defineFresh #pats #term =
freshName "f" >>= λ f →
define (vArg f) (funDef f-type (clause (f-tel #pats) (f-pats #pats) (f-term #term) ∷ [])) >>= λ _ →
returnTC f
freshFun : Nat → Nat → TC Bool
freshFun #pats #term =
catchTC (defineFresh #pats #term >>= λ _ → returnTC true)
(returnTC false)
-- Check that the pattern list must be of length 0
-- and the context features 1 available variable.
define-Γ₀-0-0 : String → This: true
define-Γ₀-0-0 s = this: evalT (freshFun 0 0)
define-Γ₀-1-0 : String → This: false
define-Γ₀-1-0 s = this: evalT (freshFun 1 0)
define-Γ₀-1-1 : String → This: false
define-Γ₀-1-1 s = this: evalT (freshFun 0 1)
module _ (S : String) where
define-Γ₁-0-0 : This: true
define-Γ₁-0-0 = this: evalT (freshFun 0 0)
define-Γ₁-0-1 : This: false
define-Γ₁-0-1 = this: evalT (freshFun 0 1)
define-Γ₁-1-0 : This: false
define-Γ₁-1-0 = this: evalT (freshFun 1 0)
f₀ : String → String
f₀ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])
f₁ : String → String
f₁ = λ s → runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])
f₂ : String → String
f₂ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])
where x = 0
| 25.402174
| 101
| 0.620454
|
4d15c24836a8d463282233f4558a3aaafa040acd
| 192
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/IO.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/IO.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/IO.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
module Agda.Builtin.IO where
postulate IO : ∀ {a} → Set a → Set a
{-# BUILTIN IO IO #-}
{-# HASKELL type AgdaIO a b = IO b #-}
{-# COMPILED_TYPE IO MAlonzo.Code.Agda.Builtin.IO.AgdaIO #-}
| 19.2
| 60
| 0.635417
|
39ef2e4f22ddf9daaedfea9d46bdd27b74d280ba
| 6,995
|
agda
|
Agda
|
Cubical/Algebra/Group/Base.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/Base.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/Base.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Data.Int hiding (-_) renaming (_+_ to _+Int_ ; _-_ to _-Int_)
open import Cubical.Data.Unit
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Semigroup
open import Cubical.Foundations.HLevels
private
variable
ℓ : Level
record IsGroup {G : Type ℓ}
(0g : G) (_+_ : G → G → G) (-_ : G → G) : Type ℓ where
constructor isgroup
field
isMonoid : IsMonoid 0g _+_
inverse : (x : G) → (x + (- x) ≡ 0g) × ((- x) + x ≡ 0g)
open IsMonoid isMonoid public
infixl 6 _-_
_-_ : G → G → G
x - y = x + (- y)
invl : (x : G) → (- x) + x ≡ 0g
invl x = inverse x .snd
invr : (x : G) → x + (- x) ≡ 0g
invr x = inverse x .fst
record GroupStr (G : Type ℓ) : Type (ℓ-suc ℓ) where
constructor groupstr
field
0g : G
_+_ : G → G → G
-_ : G → G
isGroup : IsGroup 0g _+_ -_
infix 8 -_
infixr 7 _+_
open IsGroup isGroup public
Group : Type (ℓ-suc ℓ)
Group = TypeWithStr _ GroupStr
Group₀ : Type₁
Group₀ = Group {ℓ-zero}
group : (G : Type ℓ) (0g : G) (_+_ : G → G → G) (-_ : G → G) (h : IsGroup 0g _+_ -_) → Group
group G 0g _+_ -_ h = G , groupstr 0g _+_ -_ h
isSetGroup : (G : Group {ℓ}) → isSet ⟨ G ⟩
isSetGroup G = GroupStr.isGroup (snd G) .IsGroup.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
makeIsGroup : {G : Type ℓ} {0g : G} {_+_ : G → G → G} { -_ : G → G}
(is-setG : isSet G)
(assoc : (x y z : G) → x + (y + z) ≡ (x + y) + z)
(rid : (x : G) → x + 0g ≡ x)
(lid : (x : G) → 0g + x ≡ x)
(rinv : (x : G) → x + (- x) ≡ 0g)
(linv : (x : G) → (- x) + x ≡ 0g)
→ IsGroup 0g _+_ -_
IsGroup.isMonoid (makeIsGroup is-setG assoc rid lid rinv linv) = makeIsMonoid is-setG assoc rid lid
IsGroup.inverse (makeIsGroup is-setG assoc rid lid rinv linv) = λ x → rinv x , linv x
makeGroup : {G : Type ℓ} (0g : G) (_+_ : G → G → G) (-_ : G → G)
(is-setG : isSet G)
(assoc : (x y z : G) → x + (y + z) ≡ (x + y) + z)
(rid : (x : G) → x + 0g ≡ x)
(lid : (x : G) → 0g + x ≡ x)
(rinv : (x : G) → x + (- x) ≡ 0g)
(linv : (x : G) → (- x) + x ≡ 0g)
→ Group
makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv = _ , helper
where
helper : GroupStr _
GroupStr.0g helper = 0g
GroupStr._+_ helper = _+_
GroupStr.- helper = -_
GroupStr.isGroup helper = makeIsGroup is-setG assoc rid lid rinv linv
makeGroup-right : ∀ {ℓ} {A : Type ℓ}
→ (id : A)
→ (comp : A → A → A)
→ (inv : A → A)
→ (set : isSet A)
→ (assoc : ∀ a b c → comp a (comp b c) ≡ comp (comp a b) c)
→ (rUnit : ∀ a → comp a id ≡ a)
→ (rCancel : ∀ a → comp a (inv a) ≡ id)
→ Group
makeGroup-right id comp inv set assoc rUnit rCancel =
makeGroup id comp inv set assoc rUnit lUnit rCancel lCancel
where
_⨀_ = comp
abstract
lCancel : ∀ a → comp (inv a) a ≡ id
lCancel a =
inv a ⨀ a
≡⟨ sym (rUnit (comp (inv a) a)) ⟩
(inv a ⨀ a) ⨀ id
≡⟨ cong (comp (comp (inv a) a)) (sym (rCancel (inv a))) ⟩
(inv a ⨀ a) ⨀ (inv a ⨀ (inv (inv a)))
≡⟨ assoc _ _ _ ⟩
((inv a ⨀ a) ⨀ (inv a)) ⨀ (inv (inv a))
≡⟨ cong (λ □ → □ ⨀ _) (sym (assoc _ _ _)) ⟩
(inv a ⨀ (a ⨀ inv a)) ⨀ (inv (inv a))
≡⟨ cong (λ □ → (inv a ⨀ □) ⨀ (inv (inv a))) (rCancel a) ⟩
(inv a ⨀ id) ⨀ (inv (inv a))
≡⟨ cong (λ □ → □ ⨀ (inv (inv a))) (rUnit (inv a)) ⟩
inv a ⨀ (inv (inv a))
≡⟨ rCancel (inv a) ⟩
id
∎
lUnit : ∀ a → comp id a ≡ a
lUnit a =
id ⨀ a
≡⟨ cong (λ b → comp b a) (sym (rCancel a)) ⟩
(a ⨀ inv a) ⨀ a
≡⟨ sym (assoc _ _ _) ⟩
a ⨀ (inv a ⨀ a)
≡⟨ cong (comp a) (lCancel a) ⟩
a ⨀ id
≡⟨ rUnit a ⟩
a
∎
makeGroup-left : ∀ {ℓ} {A : Type ℓ}
→ (id : A)
→ (comp : A → A → A)
→ (inv : A → A)
→ (set : isSet A)
→ (assoc : ∀ a b c → comp a (comp b c) ≡ comp (comp a b) c)
→ (lUnit : ∀ a → comp id a ≡ a)
→ (lCancel : ∀ a → comp (inv a) a ≡ id)
→ Group
makeGroup-left id comp inv set assoc lUnit lCancel =
makeGroup id comp inv set assoc rUnit lUnit rCancel lCancel
where
abstract
rCancel : ∀ a → comp a (inv a) ≡ id
rCancel a =
comp a (inv a)
≡⟨ sym (lUnit (comp a (inv a))) ⟩
comp id (comp a (inv a))
≡⟨ cong (λ b → comp b (comp a (inv a))) (sym (lCancel (inv a))) ⟩
comp (comp (inv (inv a)) (inv a)) (comp a (inv a))
≡⟨ sym (assoc (inv (inv a)) (inv a) (comp a (inv a))) ⟩
comp (inv (inv a)) (comp (inv a) (comp a (inv a)))
≡⟨ cong (comp (inv (inv a))) (assoc (inv a) a (inv a)) ⟩
comp (inv (inv a)) (comp (comp (inv a) a) (inv a))
≡⟨ cong (λ b → comp (inv (inv a)) (comp b (inv a))) (lCancel a) ⟩
comp (inv (inv a)) (comp id (inv a))
≡⟨ cong (comp (inv (inv a))) (lUnit (inv a)) ⟩
comp (inv (inv a)) (inv a)
≡⟨ lCancel (inv a) ⟩
id
∎
rUnit : ∀ a → comp a id ≡ a
rUnit a =
comp a id
≡⟨ cong (comp a) (sym (lCancel a)) ⟩
comp a (comp (inv a) a)
≡⟨ assoc a (inv a) a ⟩
comp (comp a (inv a)) a
≡⟨ cong (λ b → comp b a) (rCancel a) ⟩
comp id a
≡⟨ lUnit a ⟩
a
∎
open GroupStr hiding (0g ; _+_ ; -_)
isSetCarrier : ∀ {ℓ} → (G : Group {ℓ}) → isSet ⟨ G ⟩
isSetCarrier G = IsSemigroup.is-set (IsMonoid.isSemigroup (GroupStr.isMonoid (snd G)))
open GroupStr
dirProd : ∀ {ℓ ℓ'} → Group {ℓ} → Group {ℓ'} → Group
dirProd (GC , G) (HC , H) =
makeGroup (0g G , 0g H)
(λ { (x1 , x2) (y1 , y2) → _+_ G x1 y1 , _+_ H x2 y2 })
(λ { (x1 , x2) → -_ G x1 , -_ H x2 })
(isSet× (isSetCarrier (GC , G)) (isSetCarrier (HC , H)))
(λ { (x1 , x2) (y1 , y2) (z1 , z2) i →
assoc G x1 y1 z1 i , assoc H x2 y2 z2 i })
(λ { (x1 , x2) i → GroupStr.rid G x1 i , GroupStr.rid H x2 i })
(λ { (x1 , x2) i → GroupStr.lid G x1 i , GroupStr.lid H x2 i })
(λ { (x1 , x2) i → GroupStr.invr G x1 i , GroupStr.invr H x2 i })
(λ { (x1 , x2) i → GroupStr.invl G x1 i , GroupStr.invl H x2 i })
trivialGroup : Group₀
trivialGroup = Unit , groupstr tt (λ _ _ → tt) (λ _ → tt)
(makeIsGroup isSetUnit (λ _ _ _ → refl) (λ _ → refl) (λ _ → refl)
(λ _ → refl) (λ _ → refl))
intGroup : Group₀
intGroup = Int , groupstr 0 _+Int_ (0 -Int_)
(makeIsGroup isSetInt +-assoc (λ x → refl) (λ x → +-comm 0 x)
(λ x → +-comm x (pos 0 -Int x) ∙ minusPlus x 0) (λ x → minusPlus x 0))
| 32.686916
| 100
| 0.479342
|
0eed521de058d3aaa6504c72a5bbf91b07cbea1b
| 15,972
|
agda
|
Agda
|
Cubical/Algebra/Group/EilenbergMacLane/GroupStructure.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/Group/EilenbergMacLane/GroupStructure.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/EilenbergMacLane/GroupStructure.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Group.EilenbergMacLane.GroupStructure where
open import Cubical.Algebra.Group.EilenbergMacLane.Base
open import Cubical.Algebra.Group.EilenbergMacLane.WedgeConnectivity
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Data.Nat
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Path
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.EilenbergMacLane1
open import Cubical.HITs.Truncation
renaming (elim to trElim ; rec to trRec ; rec2 to trRec2)
open import Cubical.HITs.Susp
open import Cubical.Functions.Morphism
private
variable ℓ : Level
module _ {G : AbGroup ℓ} where
infixr 34 _+ₖ_
infixr 34 _-ₖ_
open AbGroupStr (snd G) renaming (_+_ to _+G_ ; -_ to -G_ ; assoc to assocG)
private
help : (n : ℕ) → n + (4 + n) ≡ (2 + n) + (2 + n)
help n = +-suc n (3 + n) ∙ cong suc (+-suc n (suc (suc n)))
hLevHelp : (n : ℕ) → isOfHLevel ((2 + n) + (2 + n)) (EM G (2 + n))
hLevHelp n =
transport (λ i → isOfHLevel (help n i) (EM G (2 + n)))
(isOfHLevelPlus {n = 4 + n} n (isOfHLevelTrunc (4 + n)))
helper : (g h : fst G)
→ PathP (λ i → Path (EM₁ (AbGroup→Group G))
(emloop h i) (emloop h i)) (emloop g) (emloop g)
helper g h =
comm→PathP
((sym (emloop-comp _ h g)
∙∙ cong emloop (comm h g)
∙∙ emloop-comp _ g h))
_+ₖ_ : {n : ℕ} → EM G n → EM G n → EM G n
_+ₖ_ {n = zero} = _+G_
_+ₖ_ {n = suc zero} =
rec _ (isGroupoidΠ (λ _ → emsquash))
(λ x → x)
(λ x → funExt (looper x))
λ g h i j x → el g h x i j
where
looper : fst G → (x : _) → x ≡ x
looper g = (elimSet _ (λ _ → emsquash _ _)
(emloop g)
(helper g))
el : (g h : fst G) (x : EM₁ (AbGroup→Group G))
→ Square (looper g x)
(looper (g +G h) x)
refl (looper h x)
el g h =
elimProp _ (λ _ → isOfHLevelPathP' 1 (emsquash _ _) _ _)
(emcomp g h)
_+ₖ_ {n = suc (suc n)} =
trRec2 (isOfHLevelTrunc (4 + n))
(wedgeConEM.fun G G (suc n) (suc n)
(λ _ _ → hLevHelp n)
∣_∣ ∣_∣ refl)
σ-EM : (n : ℕ) → EM-raw G (suc n) → Path (EM-raw G (2 + n)) ptEM-raw ptEM-raw
σ-EM n x = merid x ∙ sym (merid ptEM-raw)
-ₖ_ : {n : ℕ} → EM G n → EM G n
-ₖ_ {n = zero} x = -G x
-ₖ_ {n = suc zero} =
rec _ emsquash
embase
(λ g → sym (emloop g))
λ g h → sym (emloop-sym _ g)
◁ (flipSquare
(flipSquare (emcomp (-G g) (-G h))
▷ emloop-sym _ h)
▷ (cong emloop (comm (-G g) (-G h)
∙ sym (GroupTheory.invDistr (AbGroup→Group G) g h))
∙ emloop-sym _ (g +G h)))
-ₖ_ {n = suc (suc n)} =
map λ { north → north
; south → north
; (merid a i) → σ-EM n a (~ i)}
_-ₖ_ : {n : ℕ} → EM G n → EM G n → EM G n
_-ₖ_ {n = n} x y = _+ₖ_ {n = n} x (-ₖ_ {n = n} y)
+ₖ-syntax : (n : ℕ) → EM G n → EM G n → EM G n
+ₖ-syntax n = _+ₖ_ {n = n}
-ₖ-syntax : (n : ℕ) → EM G n → EM G n
-ₖ-syntax n = -ₖ_ {n = n}
-'ₖ-syntax : (n : ℕ) → EM G n → EM G n → EM G n
-'ₖ-syntax n = _-ₖ_ {n = n}
syntax +ₖ-syntax n x y = x +[ n ]ₖ y
syntax -ₖ-syntax n x = -[ n ]ₖ x
syntax -'ₖ-syntax n x y = x -[ n ]ₖ y
lUnitₖ : (n : ℕ) (x : EM G n) → 0ₖ n +[ n ]ₖ x ≡ x
lUnitₖ zero x = lid x
lUnitₖ (suc zero) _ = refl
lUnitₖ (suc (suc n)) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
λ _ → refl
rUnitₖ : (n : ℕ) (x : EM G n) → x +[ n ]ₖ 0ₖ n ≡ x
rUnitₖ zero x = rid x
rUnitₖ (suc zero) =
elimSet _ (λ _ → emsquash _ _)
refl
λ _ _ → refl
rUnitₖ (suc (suc n)) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
(wedgeConEM.right G G (suc n) (suc n)
(λ _ _ → hLevHelp n)
∣_∣ ∣_∣ refl)
commₖ : (n : ℕ) (x y : EM G n) → x +[ n ]ₖ y ≡ y +[ n ]ₖ x
commₖ zero = comm
commₖ (suc zero) =
wedgeConEM.fun G G 0 0 (λ _ _ → emsquash _ _)
(λ x → sym (rUnitₖ 1 x))
(rUnitₖ 1)
refl
commₖ (suc (suc n)) =
elim2 (λ _ _ → isOfHLevelTruncPath {n = 4 + n})
(wedgeConEM.fun G G _ _ (λ _ _ → isOfHLevelPath ((2 + n) + (2 + n)) (hLevHelp n) _ _)
(λ x → sym (rUnitₖ (2 + n) ∣ x ∣))
(λ x → rUnitₖ (2 + n) ∣ x ∣)
refl)
cong₂+₁ : (p q : typ (Ω (EM∙ G 1)))
→ cong₂ (λ x y → x +[ 1 ]ₖ y) p q ≡ p ∙ q
cong₂+₁ p q =
(cong₂Funct (λ x y → x +[ 1 ]ₖ y) p q)
∙ (λ i → (cong (λ x → rUnitₖ 1 x i) p) ∙ (cong (λ x → lUnitₖ 1 x i) q))
cong₂+₂ : (n : ℕ) (p q : typ (Ω (EM∙ G (suc (suc n)))))
→ cong₂ (λ x y → x +[ (2 + n) ]ₖ y) p q ≡ p ∙ q
cong₂+₂ n p q =
(cong₂Funct (λ x y → x +[ (2 + n) ]ₖ y) p q)
∙ (λ i → (cong (λ x → rUnitₖ (2 + n) x i) p) ∙ (cong (λ x → lUnitₖ (2 + n) x i) q))
isCommΩEM : (n : ℕ) (p q : typ (Ω (EM∙ G (suc n)))) → p ∙ q ≡ q ∙ p
isCommΩEM zero p q =
sym (cong₂+₁ p q)
∙∙ (λ i j → commₖ 1 (p j) (q j) i)
∙∙ cong₂+₁ q p
isCommΩEM (suc n) p q =
(sym (cong₂+₂ n p q)
∙∙ (λ i j → commₖ (suc (suc n)) (p j) (q j) i)
∙∙ cong₂+₂ n q p)
cong-₁ : (p : typ (Ω (EM∙ G 1))) → cong (λ x → -[ 1 ]ₖ x) p ≡ sym p
cong-₁ p = main embase p
where
decoder : (x : EM G 1) → embase ≡ x → x ≡ embase
decoder =
elimSet _
(λ _ → isSetΠ λ _ → emsquash _ _)
(λ p i → -[ 1 ]ₖ (p i))
λ g → toPathP
(funExt λ x →
(λ i → transport (λ i → Path (EM G 1) (emloop g i) embase)
(cong (-ₖ_ {n = 1})
(transp (λ j → Path (EM G 1) embase (emloop g (~ j ∧ ~ i))) i
(compPath-filler x (sym (emloop g)) i) )))
∙∙ (λ i → transp (λ j → Path (EM G 1) (emloop g (i ∨ j)) embase) i
(compPath-filler'
(sym (emloop g))
(cong-∙ (-ₖ_ {n = 1})
x (sym (emloop g)) i) i))
∙∙ (cong (sym (emloop g) ∙_) (isCommΩEM 0 (cong (-ₖ_ {n = 1}) x) (emloop g)))
∙∙ ∙assoc _ _ _
∙∙ cong (_∙ (cong (-ₖ_ {n = 1}) x)) (lCancel (emloop g))
∙ sym (lUnit _))
main : (x : EM G 1) (p : embase ≡ x) → decoder x p ≡ sym p
main x = J (λ x p → decoder x p ≡ sym p) refl
cong-₂ : (n : ℕ) (p : typ (Ω (EM∙ G (2 + n))))
→ cong (λ x → -[ 2 + n ]ₖ x) p ≡ sym p
cong-₂ n p = main _ p
where
pp : (a : _)
→ PathP (λ i → 0ₖ (suc (suc n)) ≡ ∣ merid a i ∣ₕ → ∣ merid a i ∣ₕ ≡ 0ₖ (2 + n))
(cong (λ x → -[ 2 + n ]ₖ x))
λ p → cong ∣_∣ₕ (sym (merid ptEM-raw)) ∙ cong (λ x → -[ 2 + n ]ₖ x) p
pp a =
toPathP
(funExt λ x →
(λ k → transp (λ i → Path (EM G (2 + n)) ∣ merid a (i ∨ k) ∣ ∣ ptEM-raw ∣) k
(compPath-filler' (cong ∣_∣ₕ (sym (merid a)))
(cong (-ₖ-syntax (suc (suc n)))
(transp (λ j → Path (EM G (2 + n)) ∣ ptEM-raw ∣ ∣ merid a (~ j ∧ ~ k) ∣) k
(compPath-filler x (sym (cong ∣_∣ₕ (merid a))) k))) k))
∙∙ cong (cong ∣_∣ₕ (sym (merid a)) ∙_)
(cong-∙ (λ x → -[ 2 + n ]ₖ x) x (sym (cong ∣_∣ₕ (merid a)))
∙ isCommΩEM (suc n) (cong (λ x → -[ 2 + n ]ₖ x) x) (cong ∣_∣ₕ (σ-EM n a)))
∙∙ (λ k → (λ i → ∣ merid a (~ i ∨ k) ∣)
∙ (λ i → ∣ compPath-filler' (merid a) (sym (merid ptEM-raw)) (~ k) i ∣)
∙ cong (λ x → -ₖ-syntax (suc (suc n)) x) x)
∙ sym (lUnit _))
decoder : (x : EM G (2 + n))
→ 0ₖ (2 + n) ≡ x → x ≡ 0ₖ (2 + n)
decoder =
trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelTruncPath {n = 4 + n})
λ { north → pp ptEM-raw i0
; south → pp ptEM-raw i1
; (merid a i) → pp a i}
main : (x : EM G (2 + n)) (p : 0ₖ (2 + n) ≡ x) → decoder x p ≡ sym p
main x = J (λ x p → decoder x p ≡ sym p) refl
rCancelₖ : (n : ℕ) (x : EM G n) → x +[ n ]ₖ (-[ n ]ₖ x) ≡ 0ₖ n
rCancelₖ zero x = invr x
rCancelₖ (suc zero) =
elimSet _ (λ _ → emsquash _ _)
refl
λ g → flipSquare (cong₂+₁ (emloop g) (λ i → -ₖ-syntax 1 (emloop g i))
∙ rCancel (emloop g))
rCancelₖ (suc (suc n)) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
λ { north → refl
; south i → +ₖ-syntax (suc (suc n)) ∣ merid ptEM-raw (~ i) ∣
(-ₖ-syntax (suc (suc n)) ∣ merid ptEM-raw (~ i) ∣)
; (merid a i) j
→ hcomp (λ r → λ { (i = i0) → 0ₖ (2 + n)
; (i = i1) → ∣ merid ptEM-raw (~ j ∧ r) ∣ₕ -[ 2 + n ]ₖ ∣ merid ptEM-raw (~ j ∧ r) ∣
; (j = i0) → ∣ compPath-filler (merid a) (sym (merid ptEM-raw)) (~ r) i ∣
-[ 2 + n ]ₖ ∣ compPath-filler (merid a) (sym (merid ptEM-raw)) (~ r) i ∣
; (j = i1) → 0ₖ (2 + n)})
(help' a j i) }
where
help' : (a : _)
→ cong₂ (λ x y → ∣ x ∣ -[ suc (suc n) ]ₖ ∣ y ∣) (σ-EM n a) (σ-EM n a) ≡ refl
help' a =
cong₂+₂ n (cong ∣_∣ₕ (σ-EM n a)) (cong (λ x → -[ 2 + n ]ₖ ∣ x ∣) (σ-EM n a))
∙∙ cong (cong ∣_∣ₕ (σ-EM n a) ∙_) (cong-₂ n (cong ∣_∣ₕ (σ-EM n a)))
∙∙ rCancel _
lCancelₖ : (n : ℕ) (x : EM G n) → (-[ n ]ₖ x) +[ n ]ₖ x ≡ 0ₖ n
lCancelₖ n x = commₖ n (-[ n ]ₖ x) x ∙ rCancelₖ n x
assocₖ : (n : ℕ) (x y z : EM G n)
→ (x +[ n ]ₖ (y +[ n ]ₖ z) ≡ (x +[ n ]ₖ y) +[ n ]ₖ z)
assocₖ zero = assocG
assocₖ (suc zero) =
elimSet _ (λ _ → isSetΠ2 λ _ _ → emsquash _ _)
(λ _ _ → refl)
λ g i y z k → lem g y z k i
where
lem : (g : fst G) (y z : _)
→ cong (λ x → x +[ suc zero ]ₖ (y +[ suc zero ]ₖ z)) (emloop g)
≡ cong (λ x → (x +[ suc zero ]ₖ y) +[ suc zero ]ₖ z) (emloop g)
lem g =
elimProp _ (λ _ → isPropΠ λ _ → emsquash _ _ _ _)
(elimProp _ (λ _ → emsquash _ _ _ _)
refl)
assocₖ (suc (suc n)) =
elim2 (λ _ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelTruncPath {n = 4 + n})
λ a b → trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
(λ c → main c a b)
where
lem : (c : _) (a b : _)
→ PathP (λ i → (∣ a ∣ₕ +[ suc (suc n) ]ₖ (∣ b ∣ₕ +[ suc (suc n) ]ₖ ∣ merid c i ∣ₕ)
≡ (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ) +[ suc (suc n) ]ₖ ∣ merid c i ∣ₕ))
(cong (λ x → ∣ a ∣ₕ +[ suc (suc n) ]ₖ x) (rUnitₖ (suc (suc n)) ∣ b ∣)
∙ sym (rUnitₖ (suc (suc n)) (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ)))
((λ i → ∣ a ∣ₕ +[ suc (suc n) ]ₖ (∣ b ∣ₕ +[ suc (suc n) ]ₖ ∣ merid ptEM-raw (~ i) ∣ₕ))
∙∙ cong (λ x → ∣ a ∣ₕ +[ suc (suc n) ]ₖ x) (rUnitₖ (suc (suc n)) ∣ b ∣)
∙ sym (rUnitₖ (suc (suc n)) (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ))
∙∙ λ i → (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ) +[ suc (suc n) ]ₖ ∣ merid ptEM-raw i ∣ₕ)
lem c =
raw-elim G (suc n)
(λ _ → isOfHLevelΠ (2 + n)
(λ _ → isOfHLevelPathP' (2 + n) (isOfHLevelTrunc (4 + n) _ _) _ _))
(raw-elim G (suc n)
(λ _ → isOfHLevelPathP' (2 + n) (isOfHLevelTrunc (4 + n) _ _) _ _)
((sym (rUnit refl)
◁ λ _ → refl)
▷ (sym (lCancel (cong ∣_∣ₕ (merid ptEM-raw)))
∙ λ i → (λ j → ∣ merid ptEM-raw (~ j ∨ ~ i) ∣ₕ)
∙∙ lUnit (λ j → ∣ merid ptEM-raw (~ j ∧ ~ i) ∣ₕ) i
∙∙ cong ∣_∣ₕ (merid ptEM-raw))))
main : (c a b : _)
→ (∣ a ∣ₕ +[ suc (suc n) ]ₖ (∣ b ∣ₕ +[ suc (suc n) ]ₖ ∣ c ∣ₕ)
≡ (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ) +[ suc (suc n) ]ₖ ∣ c ∣ₕ)
main north a b = lem ptEM-raw a b i0
main south a b = lem ptEM-raw a b i1
main (merid c i) a b = lem c a b i
σ-EM' : (n : ℕ) (x : EM G (suc n))
→ Path (EM G (suc (suc n)))
(0ₖ (suc (suc n)))
(0ₖ (suc (suc n)))
σ-EM' zero x = cong ∣_∣ₕ (σ-EM zero x)
σ-EM' (suc n) =
trElim (λ _ → isOfHLevelTrunc (5 + n) _ _)
λ x → cong ∣_∣ₕ (σ-EM (suc n) x)
σ-EM'-0ₖ : (n : ℕ) → σ-EM' n (0ₖ (suc n)) ≡ refl
σ-EM'-0ₖ zero = cong (cong ∣_∣ₕ) (rCancel (merid ptEM-raw))
σ-EM'-0ₖ (suc n) = cong (cong ∣_∣ₕ) (rCancel (merid ptEM-raw))
private
lUnit-rUnit-coh : ∀ {ℓ} {A : Type ℓ} {x : A} (p : x ≡ x) (r : refl ≡ p)
→ lUnit p ∙ cong (_∙ p) r
≡ rUnit p ∙ cong (p ∙_) r
lUnit-rUnit-coh p =
J (λ p r → lUnit p ∙ cong (_∙ p) r ≡ rUnit p ∙ cong (p ∙_) r) refl
σ-EM'-hom : (n : ℕ) → (a b : _) → σ-EM' n (a +ₖ b) ≡ σ-EM' n a ∙ σ-EM' n b
σ-EM'-hom zero =
wedgeConEM.fun G G 0 0 (λ _ _ → isOfHLevelTrunc 4 _ _ _ _) l r p
where
l : _
l x = cong (σ-EM' zero) (lUnitₖ 1 x)
∙∙ lUnit (σ-EM' zero x)
∙∙ cong (_∙ σ-EM' zero x) (sym (σ-EM'-0ₖ zero))
r : _
r x =
cong (σ-EM' zero) (rUnitₖ 1 x)
∙∙ rUnit (σ-EM' zero x)
∙∙ cong (σ-EM' zero x ∙_) (sym (σ-EM'-0ₖ zero))
p : _
p = lUnit-rUnit-coh (σ-EM' zero embase) (sym (σ-EM'-0ₖ zero))
σ-EM'-hom (suc n) =
elim2 (λ _ _ → isOfHLevelPath (4 + n) (isOfHLevelTrunc (5 + n) _ _) _ _)
(wedgeConEM.fun G G _ _
(λ x y → transport (λ i → isOfHLevel (help n i)
((σ-EM' (suc n) (∣ x ∣ₕ +ₖ ∣ y ∣ₕ)
≡ σ-EM' (suc n) ∣ x ∣ₕ ∙ σ-EM' (suc n) ∣ y ∣ₕ)))
(isOfHLevelPlus {n = 4 + n} n
(isOfHLevelPath (4 + n)
(isOfHLevelTrunc (5 + n) _ _) _ _)))
(λ x → cong (σ-EM' (suc n)) (lUnitₖ (suc (suc n)) ∣ x ∣)
∙∙ lUnit (σ-EM' (suc n) ∣ x ∣)
∙∙ cong (_∙ σ-EM' (suc n) ∣ x ∣) (sym (σ-EM'-0ₖ (suc n))))
(λ x → cong (σ-EM' (suc n)) (rUnitₖ (2 + n) ∣ x ∣)
∙∙ rUnit (σ-EM' (suc n) ∣ x ∣)
∙∙ cong (σ-EM' (suc n) ∣ x ∣ ∙_) (sym (σ-EM'-0ₖ (suc n))))
(lUnit-rUnit-coh (σ-EM' (suc n) (0ₖ (2 + n))) (sym (σ-EM'-0ₖ (suc n)))))
σ-EM'-ₖ : (n : ℕ) → (a : _) → σ-EM' n (-ₖ a) ≡ sym (σ-EM' n a)
σ-EM'-ₖ n =
morphLemmas.distrMinus
(λ x y → x +[ suc n ]ₖ y) (_∙_)
(σ-EM' n) (σ-EM'-hom n)
(0ₖ (suc n)) refl
(λ x → -ₖ x) sym
(λ x → sym (lUnit x)) (λ x → sym (rUnit x))
(lCancelₖ (suc n)) rCancel
∙assoc (σ-EM'-0ₖ n)
-Dist : (n : ℕ) (x y : EM G n) → -[ n ]ₖ (x +[ n ]ₖ y) ≡ (-[ n ]ₖ x) +[ n ]ₖ (-[ n ]ₖ y)
-Dist zero x y = (GroupTheory.invDistr (AbGroup→Group G) x y) ∙ commₖ zero _ _
-Dist (suc zero) = k
where -- useless where clause. Needed for fast type checking for some reason.
l : _
l x = refl
r : _
r x = cong (λ z → -[ 1 ]ₖ z) (rUnitₖ 1 x) ∙ sym (rUnitₖ 1 (-[ 1 ]ₖ x))
p : r ptEM-raw ≡ l ptEM-raw
p = sym (rUnit refl)
k = wedgeConEM.fun G G 0 0 (λ _ _ → emsquash _ _) l r (sym p)
-Dist (suc (suc n)) =
elim2 (λ _ _ → isOfHLevelTruncPath {n = 4 + n})
(wedgeConEM.fun G G (suc n) (suc n)
(λ _ _ → isOfHLevelPath ((2 + n) + (2 + n)) (hLevHelp n) _ _)
(λ x → refl)
(λ x → cong (λ z → -[ (suc (suc n)) ]ₖ z)
(rUnitₖ (suc (suc n)) ∣ x ∣ₕ)
∙ sym (rUnitₖ (suc (suc n)) (-[ (suc (suc n)) ]ₖ ∣ x ∣ₕ)))
(rUnit refl))
addIso : (n : ℕ) (x : EM G n) → Iso (EM G n) (EM G n)
Iso.fun (addIso n x) y = y +[ n ]ₖ x
Iso.inv (addIso n x) y = y -[ n ]ₖ x
Iso.rightInv (addIso n x) y =
sym (assocₖ n y (-[ n ]ₖ x) x)
∙∙ cong (λ x → y +[ n ]ₖ x) (lCancelₖ n x)
∙∙ rUnitₖ n y
Iso.leftInv (addIso n x) y =
sym (assocₖ n y x (-[ n ]ₖ x))
∙∙ cong (λ x → y +[ n ]ₖ x) (rCancelₖ n x)
∙∙ rUnitₖ n y
| 38.394231
| 112
| 0.450225
|
0e7129441a89d792baf8d2cf3bf1d1449501c188
| 2,295
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Product/Categorical/Right.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Product/Categorical/Right.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Product/Categorical/Right.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Right-biased universe-sensitive functor and monad instances for the
-- Product type.
--
-- To minimize the universe level of the RawFunctor, we require that
-- elements of B are "lifted" to a copy of B at a higher universe level
-- (a ⊔ b). See the Data.Product.Categorical.Examples for how this is
-- done.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
open import Level
module Data.Product.Categorical.Right
(a : Level) {b e} (B : RawMonoid b e) where
open import Data.Product
import Data.Product.Categorical.Right.Base as Base
open import Category.Applicative using (RawApplicative)
open import Category.Monad using (RawMonad; RawMonadT)
open import Function using (id; flip; _∘_; _∘′_)
import Function.Identity.Categorical as Id
open RawMonoid B
------------------------------------------------------------------------
-- Re-export the base contents publically
open Base Carrier a public
------------------------------------------------------------------------
-- Basic records
applicative : RawApplicative Productᵣ
applicative = record
{ pure = _, ε
; _⊛_ = zip id _∙_
}
monadT : RawMonadT (_∘′ Productᵣ)
monadT M = record
{ return = pure ∘′ (_, ε)
; _>>=_ = λ ma f → ma >>= uncurry λ x b → map₂ (b ∙_) <$> f x
} where open RawMonad M
monad : RawMonad Productᵣ
monad = monadT Id.monad
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {F} (App : RawApplicative {a ⊔ b} F) where
open RawApplicative App
sequenceA : ∀ {A} → Productᵣ (F A) → F (Productᵣ A)
sequenceA (fa , y) = (_, y) <$> fa
mapA : ∀ {A B} → (A → F B) → Productᵣ A → F (Productᵣ B)
mapA f = sequenceA ∘ map₁ f
forA : ∀ {A B} → Productᵣ A → (A → F B) → F (Productᵣ B)
forA = flip mapA
module _ {M} (Mon : RawMonad {a ⊔ b} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM : ∀ {A} → Productᵣ (M A) → M (Productᵣ A)
sequenceM = sequenceA App
mapM : ∀ {A B} → (A → M B) → Productᵣ A → M (Productᵣ B)
mapM = mapA App
forM : ∀ {A B} → Productᵣ A → (A → M B) → M (Productᵣ B)
forM = forA App
| 28.333333
| 72
| 0.555991
|
4ae8c4c37f722608110d621384f8130f94efb44e
| 1,502
|
agda
|
Agda
|
simpleAgda.agda
|
hjorthjort/IdrisToAgda
|
a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1
|
[
"MIT"
] | 2
|
2020-02-16T23:22:50.000Z
|
2020-06-29T20:42:43.000Z
|
simpleAgda.agda
|
hjorthjort/IdrisToAgda
|
a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1
|
[
"MIT"
] | 1
|
2019-11-28T17:52:42.000Z
|
2019-11-28T17:52:42.000Z
|
simpleAgda.agda
|
hjorthjort/IdrisToAgda
|
a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1
|
[
"MIT"
] | 1
|
2019-11-27T16:25:18.000Z
|
2019-11-27T16:25:18.000Z
|
module simpleAgda where
-- main : IO ()
-- main = putStrLn "Testing simple Idris"
--
-- Some simple equivalent Idris and Agda code.
--
-- data N = Z | Suc N
data N : Set where
Z : N
suc : N -> N
-- one : N
-- one = Suc Z
one : N
one = suc Z
-- addOne : N -> N
-- addOne Z = Suc Z
-- addOne (Suc n) = Suc (Suc n)
addOne : N -> N
addOne Z = suc Z
addOne (suc a) = suc (suc a)
-- add : N -> N -> N
-- add Z s = s
-- add (Suc a) b = add a (Suc b)
add : N -> N -> N
add Z s = s
add (suc a) b = add a (suc b)
-- data Vec : Type -> N -> Type where
-- Nil : Vec a Z
-- (::) : a -> Vec a n -> Vec a (Suc n)
data Vec (A : Set) : N -> Set where
Nil : Vec A Z
cons : {n : N} -> A -> Vec A n -> Vec A (suc n)
-- empt : Vec N Z
-- empt = Nil
empt : Vec N Z
empt = Nil
open import Agda.Builtin.Nat
-- test : Vec Nat (Suc Main.one)
-- test = 1 :: 2 :: Nil
test : Vec Nat (suc (suc Z))
test = cons 1 (cons 2 Nil)
-- test2 : Vec Nat (Suc (Suc Main.one))
-- test2 = 3 :: 4 :: 5 :: Nil
test2 : Vec Nat (suc (suc (suc Z)))
test2 = cons 3 (cons 4 (cons 5 Nil))
-- concat : Vec g a -> Vec g b -> Vec g (add a b)
-- concat Nil rest = rest
-- concat (a :: rest) b = concat rest (a :: b)
concat : {a b : N} {g : Set} -> (Vec g a) -> (Vec g b) -> (Vec g (add a b))
concat Nil rest = rest
concat (cons a rest) b = concat rest (cons a b)
-- t3 : Vec (addOne $ addOne $ addOne $ addOne Main.one) Nat
-- t3 = concat test test2
t3 : Vec Nat (addOne (addOne (addOne (addOne one))))
t3 = concat test test2
| 21.768116
| 75
| 0.543941
|
4d70ffeb98506dd7c37f86eb0c1f622ce312f79c
| 386
|
agda
|
Agda
|
Cats/Category/Constructions/Epi.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Category/Constructions/Epi.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Category/Constructions/Epi.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.Constructions.Epi where
open import Level
open import Cats.Category.Base
module Build {lo la l≈} (Cat : Category lo la l≈) where
private open module Cat = Category Cat
open Cat.≈-Reasoning
IsEpi : ∀ {A B} → A ⇒ B → Set (lo ⊔ la ⊔ l≈)
IsEpi {A} {B} f = ∀ {C} {g h : B ⇒ C} → g ∘ f ≈ h ∘ f → g ≈ h
open Build public
| 20.315789
| 63
| 0.606218
|
1c5060d4a968c380e555e5314e5b8dbeb315e6d2
| 33,630
|
agda
|
Agda
|
test/LibSucceed/Issue784/Values.agda
|
ayberkt/agda
|
376c2fcafef775847e336244ecf8020575b07d96
|
[
"BSD-3-Clause"
] | null | null | null |
test/LibSucceed/Issue784/Values.agda
|
ayberkt/agda
|
376c2fcafef775847e336244ecf8020575b07d96
|
[
"BSD-3-Clause"
] | null | null | null |
test/LibSucceed/Issue784/Values.agda
|
ayberkt/agda
|
376c2fcafef775847e336244ecf8020575b07d96
|
[
"BSD-3-Clause"
] | null | null | null |
module Issue784.Values where
open import Data.Bool using (Bool; true; false; not)
open import Data.String public using (String)
open import Data.String.Properties public using (_≟_)
open import Function public
open import Data.List using (List; []; _∷_; _++_; [_]; boolFilter) renaming (map to mapL)
open import Data.List.Any public using (Any; here; there) renaming (map to mapA; any to anyA)
open import Data.Product public using (Σ; Σ-syntax; proj₁; proj₂; _,_; _×_) renaming (map to mapΣ)
open import Data.Unit public using (⊤)
open import Data.Unit.NonEta public using (Unit; unit)
open import Data.Empty public using (⊥; ⊥-elim)
open import Relation.Binary.Core public
open import Relation.Nullary public
import Level
open import Relation.Binary.PropositionalEquality public hiding ([_]) renaming (cong to ≡-cong; cong₂ to ≡-cong₂)
open import Relation.Binary.PropositionalEquality.Core public renaming (sym to ≡-sym; trans to ≡-trans)
≢-sym : ∀ {ℓ} {A : Set ℓ} {x y : A} → x ≢ y → y ≢ x
≢-sym x≢y = x≢y ∘ ≡-sym
≡-elim : ∀ {ℓ} {X Y : Set ℓ} → X ≡ Y → X → Y
≡-elim refl p = p
≡-elim′ : ∀ {a ℓ} {A : Set a} {x y : A} → (P : A → Set ℓ) → x ≡ y → P x → P y
≡-elim′ P = ≡-elim ∘ (≡-cong P)
Named : ∀ {ℓ} (A : Set ℓ) → Set ℓ
Named A = String × A
NamedType : ∀ ℓ → Set (Level.suc ℓ)
NamedType ℓ = Named (Set ℓ)
NamedValue : ∀ ℓ → Set (Level.suc ℓ)
NamedValue ℓ = Named (Σ[ A ∈ Set ℓ ] A)
Names : Set
Names = List String
Types : ∀ ℓ → Set (Level.suc ℓ)
Types ℓ = List (NamedType ℓ)
Values : ∀ ℓ → Set (Level.suc ℓ)
Values ℓ = List (NamedValue ℓ)
names : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names
names = mapL proj₁
types : ∀ {ℓ} → Values ℓ → Types ℓ
types = mapL (mapΣ id proj₁)
infix 4 _∈_ _∉_
_∈_ : ∀ {ℓ} {A : Set ℓ} → A → List A → Set ℓ
x ∈ xs = Any (_≡_ x) xs
_∉_ : ∀ {ℓ} {A : Set ℓ} → A → List A → Set ℓ
x ∉ xs = ¬ x ∈ xs
x∉y∷l⇒x≢y : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ∉ y ∷ l → x ≢ y
x∉y∷l⇒x≢y x∉y∷l x≡y = x∉y∷l $ here x≡y
x∉y∷l⇒x∉l : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ∉ y ∷ l → x ∉ l
x∉y∷l⇒x∉l x∉y∷l x∈l = x∉y∷l $ there x∈l
x≢y⇒x∉l⇒x∉y∷l : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ≢ y → x ∉ l → x ∉ y ∷ l
x≢y⇒x∉l⇒x∉y∷l x≢y x∉l (here x≡y) = x≢y x≡y
x≢y⇒x∉l⇒x∉y∷l x≢y x∉l (there x∈l) = x∉l x∈l
infix 5 _∋!_ _∈?_
_∈?_ : (s : String) (n : Names) → Dec (s ∈ n)
s ∈? [] = no λ()
s ∈? (h ∷ t) with s ≟ h
... | yes s≡h = yes $ here s≡h
... | no s≢h with s ∈? t
... | yes s∈t = yes $ there s∈t
... | no s∉t = no $ x≢y⇒x∉l⇒x∉y∷l s≢h s∉t
_∋!_ : Names → String → Bool
l ∋! e with e ∈? l
... | yes _ = true
... | no _ = false
infix 4 _⊆_ _⊈_
_⊆_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys
_⊈_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
xs ⊈ ys = ¬ xs ⊆ ys
infixl 5 _∪_
_∪_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → List A
_∪_ = _++_
infixl 6 _∩_
_∩_ : Names → Names → Names
x ∩ y = boolFilter (_∋!_ y) x
infixl 6 _∖_ _∖∖_
_∖_ : Names → Names → Names
_∖_ x y = boolFilter (not ∘ _∋!_ y) x
_∖∖_ : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names → List (Named A)
_∖∖_ l n = boolFilter (not ∘ _∋!_ n ∘ proj₁) l
filter-∈ : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names → List (Named A)
filter-∈ l n = boolFilter (_∋!_ n ∘ proj₁) l
infixr 5 _∷_
data NonRepetitive {ℓ} {A : Set ℓ} : List A → Set ℓ where
[] : NonRepetitive []
_∷_ : ∀ {x xs} → x ∉ xs → NonRepetitive xs → NonRepetitive (x ∷ xs)
infix 4 _≋_
data _≋_ {ℓ} {A : Set ℓ} : List A → List A → Set ℓ where
refl : ∀ {l} → l ≋ l
perm : ∀ {l} l₁ x₁ x₂ l₂ → l ≋ l₁ ++ x₂ ∷ x₁ ∷ l₂ → l ≋ l₁ ++ x₁ ∷ x₂ ∷ l₂
NonRepetitiveNames : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Set
NonRepetitiveNames = NonRepetitive ∘ names
NonRepetitiveTypes : ∀ ℓ → Set (Level.suc ℓ)
NonRepetitiveTypes ℓ = Σ[ t ∈ Types ℓ ] NonRepetitiveNames t
-- lemmas
∪-assoc : ∀ {l} {A : Set l} (x y z : List A) → (x ∪ y) ∪ z ≡ x ∪ (y ∪ z)
∪-assoc [] y z = refl
∪-assoc (x ∷ xs) y z = ≡-elim′ (λ e → x ∷ e ≡ (x ∷ xs) ∪ (y ∪ z)) (≡-sym $ ∪-assoc xs y z) refl
≡⇒≋ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≡ y → x ≋ y
≡⇒≋ refl = refl
private
∈-perm : ∀ {ℓ} {A : Set ℓ} {x : A} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → x ∈ l₁ ++ e₁ ∷ e₂ ∷ l₂ → x ∈ l₁ ++ e₂ ∷ e₁ ∷ l₂
∈-perm [] e₁ e₂ l₂ (here .{e₁} .{e₂ ∷ l₂} px) = there $ here px
∈-perm [] e₁ e₂ l₂ (there .{e₁} .{e₂ ∷ l₂} (here .{e₂} .{l₂} px)) = here px
∈-perm [] e₁ e₂ l₂ (there .{e₁} .{e₂ ∷ l₂} (there .{e₂} .{l₂} pxs)) = there $ there pxs
∈-perm (h₁ ∷ t₁) e₁ e₂ l₂ (here .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} px) = here px
∈-perm (h₁ ∷ t₁) e₁ e₂ l₂ (there .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} pxs) = there $ ∈-perm t₁ e₁ e₂ l₂ pxs
≋⇒⊆ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≋ y → x ⊆ y
≋⇒⊆ refl p = p
≋⇒⊆ {x = x} {y = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} (perm l₁ x₁ x₂ l₂ p) {e} e∈x = ∈-perm l₁ x₂ x₁ l₂ $ ≋⇒⊆ p e∈x
≋-trans : ∀ {l} {A : Set l} {x y z : List A} → x ≋ y → y ≋ z → x ≋ z
≋-trans p refl = p
≋-trans p₁ (perm l₁ x₁ x₂ l₂ p₂) = perm l₁ x₁ x₂ l₂ $ ≋-trans p₁ p₂
≋-sym : ∀ {l} {A : Set l} {x y : List A} → x ≋ y → y ≋ x
≋-sym refl = refl
≋-sym (perm l₁ x₁ x₂ l₂ p) = ≋-trans (perm l₁ x₂ x₁ l₂ refl) (≋-sym p)
≋-del-ins-r : ∀ {l} {A : Set l} (l₁ : List A) (x : A) (l₂ l₃ : List A) → (l₁ ++ x ∷ l₂ ++ l₃) ≋ (l₁ ++ l₂ ++ x ∷ l₃)
≋-del-ins-r l₁ x [] l₃ = refl
≋-del-ins-r l₁ x (h ∷ t) l₃ = ≋-trans p₀ p₅
where p₀ : (l₁ ++ x ∷ h ∷ t ++ l₃) ≋ (l₁ ++ h ∷ x ∷ t ++ l₃)
p₀ = perm l₁ h x (t ++ l₃) refl
p₁ : ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ ((l₁ ++ [ h ]) ++ t ++ x ∷ l₃)
p₁ = ≋-del-ins-r (l₁ ++ [ h ]) x t l₃
p₂ : (l₁ ++ [ h ]) ++ t ++ x ∷ l₃ ≡ l₁ ++ h ∷ t ++ x ∷ l₃
p₂ = ∪-assoc l₁ [ h ] (t ++ x ∷ l₃)
p₃ : (l₁ ++ [ h ]) ++ x ∷ t ++ l₃ ≡ l₁ ++ h ∷ x ∷ t ++ l₃
p₃ = ∪-assoc l₁ [ h ] (x ∷ t ++ l₃)
p₄ : ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)
p₄ = ≡-elim′ (λ y → ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ y) p₂ p₁
p₅ : (l₁ ++ h ∷ x ∷ t ++ l₃) ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)
p₅ = ≡-elim′ (λ y → y ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)) p₃ p₄
≋-del-ins-l : ∀ {l} {A : Set l} (l₁ l₂ : List A) (x : A) (l₃ : List A) → (l₁ ++ l₂ ++ x ∷ l₃) ≋ (l₁ ++ x ∷ l₂ ++ l₃)
≋-del-ins-l l₁ l₂ x l₃ = ≋-sym $ ≋-del-ins-r l₁ x l₂ l₃
x∪[]≡x : ∀ {ℓ} {A : Set ℓ} (x : List A) → x ∪ [] ≡ x
x∪[]≡x [] = refl
x∪[]≡x (h ∷ t) = ≡-trans p₀ p₁
where p₀ : (h ∷ t) ++ [] ≡ h ∷ t ++ []
p₀ = ∪-assoc [ h ] t []
p₁ : h ∷ t ++ [] ≡ h ∷ t
p₁ = ≡-cong (λ x → h ∷ x) (x∪[]≡x t)
x∖[]≡x : (x : Names) → x ∖ [] ≡ x
x∖[]≡x [] = refl
x∖[]≡x (h ∷ t) = ≡-cong (_∷_ h) (x∖[]≡x t)
t∖[]≡t : ∀ {ℓ} {A : Set ℓ} (t : List (Named A)) → t ∖∖ [] ≡ t
t∖[]≡t [] = refl
t∖[]≡t (h ∷ t) = ≡-cong (_∷_ h) (t∖[]≡t t)
e∷x≋e∷y : ∀ {ℓ} {A : Set ℓ} (e : A) {x y : List A} → x ≋ y → e ∷ x ≋ e ∷ y
e∷x≋e∷y _ refl = refl
e∷x≋e∷y x (perm l₁ e₁ e₂ l₂ p) = perm (x ∷ l₁) e₁ e₂ l₂ (e∷x≋e∷y x p)
∪-sym : ∀ {ℓ} {A : Set ℓ} (x y : List A) → x ∪ y ≋ y ∪ x
∪-sym [] y = ≡-elim′ (λ z → y ≋ z) (≡-sym $ x∪[]≡x y) refl
∪-sym x [] = ≡-elim′ (λ z → z ≋ x) (≡-sym $ x∪[]≡x x) refl
∪-sym x (y ∷ ys) = ≡-elim′ (λ z → x ++ (y ∷ ys) ≋ z) p₃ (≋-trans p₁ p₂) where
p₁ : x ++ (y ∷ ys) ≋ y ∷ (x ++ ys)
p₁ = ≋-del-ins-l [] x y ys
p₂ : y ∷ (x ++ ys) ≋ y ∷ (ys ++ x)
p₂ = e∷x≋e∷y y $ ∪-sym x ys
p₃ : y ∷ (ys ++ x) ≡ (y ∷ ys) ++ x
p₃ = ∪-assoc [ y ] ys x
y≋ỳ⇒x∪y≋x∪ỳ : ∀ {ℓ} {A : Set ℓ} (x : List A) {y ỳ : List A} → y ≋ ỳ → x ∪ y ≋ x ∪ ỳ
y≋ỳ⇒x∪y≋x∪ỳ [] p = p
y≋ỳ⇒x∪y≋x∪ỳ (h ∷ t) p = e∷x≋e∷y h (y≋ỳ⇒x∪y≋x∪ỳ t p)
x≋x̀⇒x∪y≋x̀∪y : ∀ {ℓ} {A : Set ℓ} {x x̀ : List A} → x ≋ x̀ → (y : List A) → x ∪ y ≋ x̀ ∪ y
x≋x̀⇒x∪y≋x̀∪y {x = x} {x̀ = x̀} p y = ≋-trans (∪-sym x y) $ ≋-trans (y≋ỳ⇒x∪y≋x∪ỳ y p) (∪-sym y x̀)
x⊆y≋z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ⊆ y → y ≋ z → x ⊆ z
x⊆y≋z x⊆y refl = x⊆y
x⊆y≋z {x = x} {y = y} {z = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} x⊆y (perm l₁ x₁ x₂ l₂ p) = ∈-perm l₁ x₂ x₁ l₂ ∘ x⊆y≋z x⊆y p
x≋y⊆z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ≋ y → x ⊆ z → y ⊆ z
x≋y⊆z refl x⊆z = x⊆z
x≋y⊆z {y = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} {z = z} (perm l₁ x₁ x₂ l₂ p) x⊆z = x≋y⊆z p x⊆z ∘ ∈-perm l₁ x₁ x₂ l₂
x⊆x∪y : ∀ {ℓ} {A : Set ℓ} (x y : List A) → x ⊆ x ∪ y
x⊆x∪y .(x ∷ xs) y (here {x} {xs} px) = here px
x⊆x∪y .(x ∷ xs) y (there {x} {xs} pxs) = there $ x⊆x∪y xs y pxs
x∪y⊆z⇒x⊆z : ∀ {ℓ} {A : Set ℓ} (x y : List A) {z : List A} → x ∪ y ⊆ z → x ⊆ z
x∪y⊆z⇒x⊆z x y x∪y⊆z = x∪y⊆z ∘ x⊆x∪y x y
x∪y⊆z⇒y⊆z : ∀ {ℓ} {A : Set ℓ} (x y : List A) {z : List A} → x ∪ y ⊆ z → y ⊆ z
x∪y⊆z⇒y⊆z x y = x∪y⊆z⇒x⊆z y x ∘ x≋y⊆z (∪-sym x y)
n-x∪y : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) → names (x ∪ y) ≡ names x ∪ names y
n-x∪y [] _ = refl
n-x∪y {ℓ} (x ∷ xs) y = ≡-trans p₁ p₂ where
nx = [ proj₁ x ]
nxs = names xs
ny = names y
p₁ : nx ∪ names (xs ∪ y) ≡ nx ∪ (nxs ∪ ny)
p₁ = ≡-cong (λ z → nx ∪ z) (n-x∪y xs y)
p₂ : nx ∪ (nxs ∪ ny) ≡ (nx ∪ nxs) ∪ ny
p₂ = ≡-sym $ ∪-assoc nx nxs ny
t-x∪y : ∀ {ℓ} (x y : Values ℓ) → types (x ∪ y) ≡ types x ∪ types y
t-x∪y [] _ = refl
t-x∪y (x ∷ xs) y = ≡-trans p₁ p₂ where
nx = types [ x ]
nxs = types xs
ny = types y
p₁ : nx ∪ types (xs ∪ y) ≡ nx ∪ (nxs ∪ ny)
p₁ = ≡-cong (λ z → nx ∪ z) (t-x∪y xs y)
p₂ : nx ∪ (nxs ∪ ny) ≡ (nx ∪ nxs) ∪ ny
p₂ = ≡-sym $ ∪-assoc nx nxs ny
n-x≋y : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ≋ y → names x ≋ names y
n-x≋y refl = refl
n-x≋y (perm {x} l₁ e₁ e₂ l₂ p) = p₃ where
n-l₁e₁e₂l₂ : ∀ e₁ e₂ → names (l₁ ++ e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names [ e₂ ] ++ names l₂
n-l₁e₁e₂l₂ e₁ e₂ = ≡-trans p₁ $ ≡-trans p₂ p₃ where
p₁ : names (l₁ ++ e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names (e₁ ∷ e₂ ∷ l₂)
p₁ = n-x∪y l₁ (e₁ ∷ e₂ ∷ l₂)
p₂ : names l₁ ++ names (e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names (e₂ ∷ l₂)
p₂ = ≡-cong (λ z → names l₁ ++ z) (n-x∪y [ e₁ ] (e₂ ∷ l₂))
p₃ : names l₁ ++ names [ e₁ ] ++ names (e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names [ e₂ ] ++ names l₂
p₃ = ≡-cong (λ z → names l₁ ++ names [ e₁ ] ++ z) (n-x∪y [ e₂ ] l₂)
p₁ : names x ≋ names l₁ ++ proj₁ e₂ ∷ proj₁ e₁ ∷ names l₂
p₁ = ≡-elim′ (λ z → names x ≋ z) (n-l₁e₁e₂l₂ e₂ e₁) (n-x≋y p)
p₂ : names x ≋ names l₁ ++ proj₁ e₁ ∷ proj₁ e₂ ∷ names l₂
p₂ = perm (names l₁) (proj₁ e₁) (proj₁ e₂) (names l₂) p₁
p₃ : names x ≋ names (l₁ ++ e₁ ∷ e₂ ∷ l₂)
p₃ = ≡-elim′ (λ z → names x ≋ z) (≡-sym $ n-l₁e₁e₂l₂ e₁ e₂) p₂
n-types : ∀ {ℓ} (x : Values ℓ) → names (types x) ≡ names x
n-types [] = refl
n-types (x ∷ xs) = ≡-cong (λ z → proj₁ x ∷ z) (n-types xs)
nr-x≋y : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≋ y → NonRepetitive x → NonRepetitive y
nr-x≋y refl u = u
nr-x≋y {y = .(l₁ ++ e₁ ∷ e₂ ∷ l₂)} (perm l₁ e₁ e₂ l₂ p) u = ≋-step l₁ e₂ e₁ l₂ (nr-x≋y p u) where
∉-step : ∀ {ℓ} {A : Set ℓ} {x : A} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → x ∉ l₁ ++ e₁ ∷ e₂ ∷ l₂ → x ∉ l₁ ++ e₂ ∷ e₁ ∷ l₂
∉-step l₁ e₁ e₂ l₂ x∉l x∈l = ⊥-elim $ x∉l $ ∈-perm l₁ e₂ e₁ l₂ x∈l
≋-step : ∀ {ℓ} {A : Set ℓ} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → NonRepetitive (l₁ ++ e₁ ∷ e₂ ∷ l₂) → NonRepetitive (l₁ ++ e₂ ∷ e₁ ∷ l₂)
≋-step [] e₁ e₂ l₂ (_∷_ .{e₁} .{e₂ ∷ l₂} e₁∉e₂∷l₂ (_∷_ .{e₂} .{l₂} e₂∉l₂ pU)) = e₂∉e₁∷l₂ ∷ e₁∉l₂ ∷ pU where
e₁∉l₂ = e₁ ∉ l₂ ∋ x∉y∷l⇒x∉l e₁∉e₂∷l₂
e₂∉e₁∷l₂ = e₂ ∉ e₁ ∷ l₂ ∋ x≢y⇒x∉l⇒x∉y∷l (≢-sym $ x∉y∷l⇒x≢y e₁∉e₂∷l₂) e₂∉l₂
≋-step (h₁ ∷ t₁) e₁ e₂ l₂ (_∷_ .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} p∉ pU) = ∉-step t₁ e₁ e₂ l₂ p∉ ∷ ≋-step t₁ e₁ e₂ l₂ pU
nr-x⇒nr-t-x : ∀ {ℓ} {x : Values ℓ} → NonRepetitiveNames x → NonRepetitiveNames (types x)
nr-x⇒nr-t-x {x = x} = ≡-elim′ NonRepetitive (≡-sym $ n-types x)
n-x∖y : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → names (x ∖∖ y) ≡ names x ∖ y
n-x∖y [] _ = refl
n-x∖y (x ∷ xs) ny with not $ ny ∋! proj₁ x
... | false = n-x∖y xs ny
... | true = ≡-trans p₁ p₂ where
p₁ : names (x ∷ (xs ∖∖ ny)) ≡ proj₁ x ∷ names (xs ∖∖ ny)
p₁ = n-x∪y [ x ] (xs ∖∖ ny)
p₂ : proj₁ x ∷ names (xs ∖∖ ny) ≡ proj₁ x ∷ (names xs ∖ ny)
p₂ = ≡-cong (λ z → proj₁ x ∷ z) (n-x∖y xs ny)
t-x∖y : ∀ {ℓ} (x : Values ℓ) (y : Names) → types (x ∖∖ y) ≡ types x ∖∖ y
t-x∖y [] _ = refl
t-x∖y (x ∷ xs) ny with not $ ny ∋! proj₁ x
... | false = t-x∖y xs ny
... | true = ≡-trans p₁ p₂ where
x̀ = types [ x ]
p₁ : types (x ∷ (xs ∖∖ ny)) ≡ x̀ ∪ types (xs ∖∖ ny)
p₁ = t-x∪y [ x ] (xs ∖∖ ny)
p₂ : x̀ ∪ types (xs ∖∖ ny) ≡ x̀ ∪ (types xs ∖∖ ny)
p₂ = ≡-cong (λ z → x̀ ∪ z) (t-x∖y xs ny)
n-filter-∈ : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → names (filter-∈ x y) ≡ names x ∩ y
n-filter-∈ [] _ = refl
n-filter-∈ (x ∷ xs) ny with ny ∋! proj₁ x
... | false = n-filter-∈ xs ny
... | true = ≡-trans p₁ p₂ where
p₁ : names (x ∷ (filter-∈ xs ny)) ≡ proj₁ x ∷ names (filter-∈ xs ny)
p₁ = n-x∪y [ x ] (filter-∈ xs ny)
p₂ : proj₁ x ∷ names (filter-∈ xs ny) ≡ proj₁ x ∷ (names xs ∩ ny)
p₂ = ≡-cong (λ z → proj₁ x ∷ z) (n-filter-∈ xs ny)
t-filter-∈ : ∀ {ℓ} (x : Values ℓ) (y : Names) → types (filter-∈ x y) ≡ filter-∈ (types x) y
t-filter-∈ [] _ = refl
t-filter-∈ (x ∷ xs) ny with ny ∋! proj₁ x
... | false = t-filter-∈ xs ny
... | true = ≡-trans p₁ p₂ where
x̀ = types [ x ]
p₁ : types (x ∷ filter-∈ xs ny) ≡ x̀ ∪ types (filter-∈ xs ny)
p₁ = t-x∪y [ x ] (filter-∈ xs ny)
p₂ : x̀ ∪ types (filter-∈ xs ny) ≡ x̀ ∪ filter-∈ (types xs) ny
p₂ = ≡-cong (λ z → x̀ ∪ z) (t-filter-∈ xs ny)
[]⊆x : ∀ {ℓ} {A : Set ℓ} (x : List A) → [] ⊆ x
[]⊆x _ ()
∀x∉[] : ∀ {ℓ} {A : Set ℓ} {x : A} → x ∉ []
∀x∉[] ()
x⊆[]⇒x≡[] : ∀ {ℓ} {A : Set ℓ} {x : List A} → x ⊆ [] → x ≡ []
x⊆[]⇒x≡[] {x = []} _ = refl
x⊆[]⇒x≡[] {x = _ ∷ _} x⊆[] = ⊥-elim $ ∀x∉[] $ x⊆[] (here refl)
x∩y⊆x : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → filter-∈ x y ⊆ x
x∩y⊆x [] _ = λ()
x∩y⊆x (h ∷ t) y with y ∋! proj₁ h
... | false = there ∘ x∩y⊆x t y
... | true = f where
f : h ∷ filter-∈ t y ⊆ h ∷ t
f (here {x = .h} p) = here p
f (there {xs = .(filter-∈ t y)} p) = there $ x∩y⊆x t y p
e∈x⇒e∈y∪x : ∀ {ℓ} {A : Set ℓ} {e : A} {x : List A} (y : List A) → e ∈ x → e ∈ y ∪ x
e∈x⇒e∈y∪x [] = id
e∈x⇒e∈y∪x (h ∷ t) = there ∘ e∈x⇒e∈y∪x t
e∈x⇒e∈x∪y : ∀ {ℓ} {A : Set ℓ} {e : A} {x : List A} (y : List A) → e ∈ x → e ∈ x ∪ y
e∈x⇒e∈x∪y {e = e} {x = x} y e∈x = x⊆y≋z f (∪-sym y x) (e ∈ [ e ] ∋ here refl) where
f : [ e ] ⊆ y ∪ x
f {è} (here {x = .e} p) = ≡-elim′ (λ z → z ∈ y ∪ x) (≡-sym p) (e∈x⇒e∈y∪x y e∈x)
f (there ())
x∪y⊆x̀∪ỳ : ∀ {ℓ} {A : Set ℓ} {x x̀ y ỳ : List A} → x ⊆ x̀ → y ⊆ ỳ → x ∪ y ⊆ x̀ ∪ ỳ
x∪y⊆x̀∪ỳ {x = []} {x̀ = []} _ y⊆ỳ = y⊆ỳ
x∪y⊆x̀∪ỳ {x = []} {x̀ = _ ∷ t̀} _ y⊆ỳ = there ∘ x∪y⊆x̀∪ỳ ([]⊆x t̀) y⊆ỳ
x∪y⊆x̀∪ỳ {x = h ∷ t} {x̀ = x̀} {y = y} {ỳ = ỳ} x⊆x̀ y⊆ỳ = f where
f : (h ∷ t) ∪ y ⊆ x̀ ∪ ỳ
f {e} (here {x = .h} e≡h) = e∈x⇒e∈x∪y ỳ (x⊆x̀ $ here e≡h)
f {e} (there {xs = .(t ∪ y)} p) = x∪y⊆x̀∪ỳ (x∪y⊆z⇒y⊆z [ h ] t x⊆x̀) y⊆ỳ p
x∖y⊆x : (x y : Names) → x ∖ y ⊆ x
x∖y⊆x [] _ = λ()
x∖y⊆x (h ∷ t) y with y ∋! h
... | true = there ∘ x∖y⊆x t y
... | false = x∪y⊆x̀∪ỳ (≋⇒⊆ $ ≡⇒≋ $ refl {x = [ h ]}) (x∖y⊆x t y)
t≋t∖n∪t∩n : ∀ {ℓ} {A : Set ℓ} (t : List (Named A)) (n : Names) → t ≋ (t ∖∖ n) ∪ filter-∈ t n
t≋t∖n∪t∩n [] _ = refl
t≋t∖n∪t∩n (h ∷ t) n with n ∋! proj₁ h
... | false = e∷x≋e∷y h $ t≋t∖n∪t∩n t n
... | true = ≋-trans p₁ p₂ where
p₁ : h ∷ t ≋ (h ∷ (t ∖∖ n)) ∪ filter-∈ t n
p₁ = e∷x≋e∷y h $ t≋t∖n∪t∩n t n
p₂ : (h ∷ (t ∖∖ n)) ∪ filter-∈ t n ≋ (t ∖∖ n) ∪ (h ∷ filter-∈ t n)
p₂ = ≋-del-ins-r [] h (t ∖∖ n) (filter-∈ t n)
e₁∈x⇒e₂∉x⇒e≢e₂ : ∀ {ℓ} {A : Set ℓ} {e₁ e₂ : A} {x : List A} → e₁ ∈ x → e₂ ∉ x → e₁ ≢ e₂
e₁∈x⇒e₂∉x⇒e≢e₂ e₁∈x e₂∉x refl = e₂∉x e₁∈x
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x : ∀ {ℓ} {A : Set ℓ} {e₁ e₂ : A} {x : List A} → e₁ ∈ e₂ ∷ x → e₁ ≢ e₂ → e₁ ∈ x
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (here e₁≡e₂) e₁≢e₂ = ⊥-elim $ e₁≢e₂ e₁≡e₂
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (there e₁∈x) _ = e₁∈x
x⊆e∷y⇒e∉x⇒x⊆y : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → x ⊆ e ∷ y → e ∉ x → x ⊆ y
x⊆e∷y⇒e∉x⇒x⊆y {e = e} {x = x} {y = y} x⊆e∷y e∉x {è} è∈x = e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (x⊆e∷y è∈x) (e₁∈x⇒e₂∉x⇒e≢e₂ è∈x e∉x)
n-e∉l⇒e∉l : ∀ {ℓ} {A : Set ℓ} {e : Named A} {l : List (Named A)} → proj₁ e ∉ names l → e ∉ l
n-e∉l⇒e∉l {e = e} n-e∉l (here {x = è} p) = ⊥-elim $ n-e∉l $ here $ ≡-cong proj₁ p
n-e∉l⇒e∉l n-e∉l (there p) = n-e∉l⇒e∉l (x∉y∷l⇒x∉l n-e∉l) p
nr-names⇒nr : ∀ {ℓ} {A : Set ℓ} {l : List (Named A)} → NonRepetitiveNames l → NonRepetitive l
nr-names⇒nr {l = []} [] = []
nr-names⇒nr {l = _ ∷ _} (nh∉nt ∷ nr-t) = n-e∉l⇒e∉l nh∉nt ∷ nr-names⇒nr nr-t
e∉x⇒e∉y⇒e∉x∪y : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → e ∉ x → e ∉ y → e ∉ x ∪ y
e∉x⇒e∉y⇒e∉x∪y {x = []} _ e∉y e∈y = ⊥-elim $ e∉y e∈y
e∉x⇒e∉y⇒e∉x∪y {x = h ∷ t} e∉x e∉y (here e≡h) = ⊥-elim $ e∉x $ here e≡h
e∉x⇒e∉y⇒e∉x∪y {x = h ∷ t} e∉x e∉y (there e∈t∪y) = e∉x⇒e∉y⇒e∉x∪y (x∉y∷l⇒x∉l e∉x) e∉y e∈t∪y
nr-x∖y∪y : {x y : Names} → NonRepetitive x → NonRepetitive y → NonRepetitive (x ∖ y ∪ y)
nr-x∖y∪y {x = []} _ nr-y = nr-y
nr-x∖y∪y {x = x ∷ xs} {y = y} (x∉xs ∷ nr-xs) nr-y with x ∈? y
... | yes x∈y = nr-x∖y∪y nr-xs nr-y
... | no x∉y = e∉x⇒e∉y⇒e∉x∪y (⊥-elim ∘ x∉xs ∘ x∖y⊆x xs y) x∉y ∷ nr-x∖y∪y nr-xs nr-y
e∉l∖[e] : (e : String) (l : Names) → e ∉ l ∖ [ e ]
e∉l∖[e] _ [] = λ()
e∉l∖[e] e (h ∷ t) with h ≟ e
... | yes _ = e∉l∖[e] e t
... | no h≢e = x≢y⇒x∉l⇒x∉y∷l (≢-sym h≢e) (e∉l∖[e] e t)
e∉l⇒l∖e≡l : {e : String} {l : Names} → e ∉ l → l ∖ [ e ] ≡ l
e∉l⇒l∖e≡l {e = e} {l = []} _ = refl
e∉l⇒l∖e≡l {e = e} {l = h ∷ t} e∉l with h ∈? [ e ]
... | yes h∈e = ⊥-elim $ x≢y⇒x∉l⇒x∉y∷l (≢-sym $ x∉y∷l⇒x≢y e∉l) (λ()) h∈e
... | no h∉e = ≡-cong (_∷_ h) (e∉l⇒l∖e≡l $ x∉y∷l⇒x∉l e∉l)
e∈l⇒nr-l⇒l∖e∪e≋l : {e : String} {l : Names} → e ∈ l → NonRepetitive l → l ∖ [ e ] ∪ [ e ] ≋ l
e∈l⇒nr-l⇒l∖e∪e≋l {l = []} () _
e∈l⇒nr-l⇒l∖e∪e≋l {e = e} {l = h ∷ t} e∈h∷t (h∉t ∷ nr-t) with h ∈? [ e ]
... | yes (here h≡e) = ≋-trans (≡⇒≋ $ ≡-trans p₁ p₂) (∪-sym t [ h ]) where
p₁ : t ∖ [ e ] ∪ [ e ] ≡ t ∖ [ h ] ∪ [ h ]
p₁ = ≡-cong (λ x → t ∖ [ x ] ∪ [ x ]) (≡-sym h≡e)
p₂ : t ∖ [ h ] ∪ [ h ] ≡ t ∪ [ h ]
p₂ = ≡-cong (λ x → x ∪ [ h ]) (e∉l⇒l∖e≡l h∉t)
... | yes (there ())
... | no h∉e with e∈h∷t
... | here e≡h = ⊥-elim ∘ h∉e ∘ here ∘ ≡-sym $ e≡h
... | there e∈t = e∷x≋e∷y _ $ e∈l⇒nr-l⇒l∖e∪e≋l e∈t nr-t
nr-x∖y : {x : Names} → NonRepetitive x → (y : Names) → NonRepetitive (x ∖ y)
nr-x∖y {x = []} _ _ = []
nr-x∖y {x = x ∷ xs} (x∉xs ∷ nr-xs) y with x ∈? y
... | yes x∈y = nr-x∖y nr-xs y
... | no x∉y = ⊥-elim ∘ x∉xs ∘ x∖y⊆x xs y ∷ nr-x∖y nr-xs y
x⊆y⇒e∉y⇒e∉x : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → x ⊆ y → e ∉ y → e ∉ x
x⊆y⇒e∉y⇒e∉x x⊆y e∉y e∈x = e∉y $ x⊆y e∈x
e∈n-l⇒∃è,n-è≡e×è∈l : ∀ {ℓ} {A : Set ℓ} {e : String} {l : List (Named A)} → e ∈ names l → Σ[ è ∈ Named A ] (e ≡ proj₁ è × è ∈ l)
e∈n-l⇒∃è,n-è≡e×è∈l {l = []} ()
e∈n-l⇒∃è,n-è≡e×è∈l {l = h ∷ t} (here e≡n-h) = h , e≡n-h , here refl
e∈n-l⇒∃è,n-è≡e×è∈l {l = h ∷ t} (there e∈n-t) with e∈n-l⇒∃è,n-è≡e×è∈l e∈n-t
... | è , n-è≡e , è∈l = è , n-è≡e , there è∈l
x⊆y⇒nx⊆ny : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ⊆ y → names x ⊆ names y
x⊆y⇒nx⊆ny {x = x} {y = y} x⊆y {e} e∈n-x with e ∈? names y
... | yes e∈n-y = e∈n-y
... | no e∉n-y with e∈n-l⇒∃è,n-è≡e×è∈l e∈n-x
... | è , e≡n-è , è∈x = ⊥-elim $ x⊆y⇒e∉y⇒e∉x x⊆y (n-e∉l⇒e∉l $ ≡-elim′ (λ z → z ∉ names y) e≡n-è e∉n-y) è∈x
nr-x⇒nr-x∩y : ∀ {ℓ} {A : Set ℓ} {x : List (Named A)} → NonRepetitiveNames x → (y : Names) → NonRepetitiveNames (filter-∈ x y)
nr-x⇒nr-x∩y {x = []} _ _ = []
nr-x⇒nr-x∩y {x = h ∷ t} (h∉t ∷ nr-t) y with y ∋! proj₁ h
... | false = nr-x⇒nr-x∩y nr-t y
... | true = x⊆y⇒e∉y⇒e∉x (x⊆y⇒nx⊆ny $ x∩y⊆x t y) h∉t ∷ nr-x⇒nr-x∩y nr-t y
e∈l⇒[e]⊆l : ∀ {ℓ} {A : Set ℓ} {e : A} {l : List A} → e ∈ l → [ e ] ⊆ l
e∈l⇒[e]⊆l e∈l (here è≡e) = ≡-elim′ (λ x → x ∈ _) (≡-sym è≡e) e∈l
e∈l⇒[e]⊆l e∈l (there ())
a∈x⇒x≋y⇒a∈y : ∀ {ℓ} {A : Set ℓ} {x y : List A} {a : A} → a ∈ x → x ≋ y → a ∈ y
a∈x⇒x≋y⇒a∈y a∈x x≋y = x⊆y≋z (e∈l⇒[e]⊆l a∈x) x≋y (here refl)
x⊆z⇒y⊆z⇒x∪y⊆z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ⊆ z → y ⊆ z → x ∪ y ⊆ z
x⊆z⇒y⊆z⇒x∪y⊆z {x = []} _ y⊆z = y⊆z
x⊆z⇒y⊆z⇒x∪y⊆z {x = h ∷ t} {y = y} {z = z} x⊆z y⊆z = f where
f : (h ∷ t) ∪ y ⊆ z
f {e} (here e≡h) = x⊆z $ here e≡h
f {e} (there e∈t∪y) = x⊆z⇒y⊆z⇒x∪y⊆z (x∪y⊆z⇒y⊆z [ h ] t x⊆z) y⊆z e∈t∪y
x⊆x∖y∪y : (x y : Names) → x ⊆ x ∖ y ∪ y
x⊆x∖y∪y [] _ = []⊆x _
x⊆x∖y∪y (h ∷ t) y with h ∈? y
x⊆x∖y∪y (h ∷ t) y | yes h∈y = x⊆z⇒y⊆z⇒x∪y⊆z (e∈l⇒[e]⊆l $ e∈x⇒e∈y∪x (t ∖ y) h∈y) (x⊆x∖y∪y t y)
x⊆x∖y∪y (h ∷ t) y | no _ = x∪y⊆x̀∪ỳ ([ h ] ⊆ [ h ] ∋ ≋⇒⊆ refl) (x⊆x∖y∪y t y)
e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ : {e₁ e₂ : String} {l : Names} → e₁ ∈ l → e₁ ∉ l ∖ [ e₂ ] → e₁ ≡ e₂
e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ {e₁ = e₁} {e₂ = e₂} {l = l} e₁∈l e₁∉l∖e₂ with e₁ ≟ e₂
... | yes e₁≡e₂ = e₁≡e₂
... | no e₁≢e₂ = ⊥-elim $ p₄ e₁∈l where
p₁ : e₁ ∉ [ e₂ ] ∪ (l ∖ [ e₂ ])
p₁ = x≢y⇒x∉l⇒x∉y∷l e₁≢e₂ e₁∉l∖e₂
p₂ : [ e₂ ] ∪ (l ∖ [ e₂ ]) ≋ (l ∖ [ e₂ ]) ∪ [ e₂ ]
p₂ = ∪-sym [ e₂ ] (l ∖ [ e₂ ])
p₃ : e₁ ∉ (l ∖ [ e₂ ]) ∪ [ e₂ ]
p₃ = p₁ ∘ ≋⇒⊆ (∪-sym (l ∖ [ e₂ ]) [ e₂ ])
p₄ : e₁ ∉ l
p₄ = x⊆y⇒e∉y⇒e∉x (x⊆x∖y∪y l [ e₂ ]) p₃
e∉x⇒x∩y≋x∩y∖e : {e : String} {x : Names} (y : Names) → e ∉ x → x ∩ y ≡ x ∩ (y ∖ [ e ])
e∉x⇒x∩y≋x∩y∖e {x = []} _ _ = refl
e∉x⇒x∩y≋x∩y∖e {e = e} {x = h ∷ t} y e∉x with h ∈? y | h ∈? (y ∖ [ e ])
... | yes h∈y | yes h∈y∖e = ≡-cong (_∷_ h) $ e∉x⇒x∩y≋x∩y∖e y $ x∉y∷l⇒x∉l e∉x
... | yes h∈y | no h∉y∖e = ⊥-elim $ e∉x e∈x where
e∈x : e ∈ h ∷ t
e∈x = here $ ≡-sym $ e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ h∈y h∉y∖e
... | no h∉y | yes h∈y∖e = ⊥-elim $ h∉y $ x∖y⊆x y [ e ] h∈y∖e
... | no h∉y | no h∉y∖e = e∉x⇒x∩y≋x∩y∖e y $ x∉y∷l⇒x∉l e∉x
y⊆x⇒x∩y≋y : {x y : Names} → NonRepetitive y → NonRepetitive x → y ⊆ x → x ∩ y ≋ y
y⊆x⇒x∩y≋y {x = []} _ _ y⊆[] = ≡⇒≋ $ ≡-elim′ (λ y → [] ∩ y ≡ y) (≡-sym $ x⊆[]⇒x≡[] y⊆[]) refl
y⊆x⇒x∩y≋y {x = h ∷ t} {y = y} nr-y (h∉t ∷ nr-t) y⊆h∷t with h ∈? y
... | yes h∈y = ≋-trans (∪-sym [ h ] (t ∩ y)) p₄ where
p₁ : t ∩ y ≋ t ∩ (y ∖ [ h ])
p₁ = ≡⇒≋ $ e∉x⇒x∩y≋x∩y∖e y h∉t
p₂ : t ∩ (y ∖ [ h ]) ≋ y ∖ [ h ]
p₂ = y⊆x⇒x∩y≋y (nr-x∖y nr-y [ h ]) nr-t $ x⊆e∷y⇒e∉x⇒x⊆y (y⊆h∷t ∘ x∖y⊆x y [ h ]) (e∉l∖[e] h y)
p₃ : y ∖ [ h ] ∪ [ h ] ≋ y
p₃ = e∈l⇒nr-l⇒l∖e∪e≋l h∈y nr-y
p₄ : t ∩ y ∪ [ h ] ≋ y
p₄ = ≋-trans (x≋x̀⇒x∪y≋x̀∪y (≋-trans p₁ p₂) [ h ]) p₃
... | no h∉y = y⊆x⇒x∩y≋y nr-y nr-t $ x⊆e∷y⇒e∉x⇒x⊆y y⊆h∷t h∉y
x∪y∖n≡x∖n∪y∖n : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) (n : Names) → (x ∪ y) ∖∖ n ≡ (x ∖∖ n) ∪ (y ∖∖ n)
x∪y∖n≡x∖n∪y∖n [] _ _ = refl
x∪y∖n≡x∖n∪y∖n (h ∷ t) y n with proj₁ h ∈? n
... | yes _ = x∪y∖n≡x∖n∪y∖n t y n
... | no _ = ≡-cong (_∷_ h) (x∪y∖n≡x∖n∪y∖n t y n)
n-x⊆n⇒x∖n≡[] : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (n : Names) → names x ⊆ n → x ∖∖ n ≡ []
n-x⊆n⇒x∖n≡[] [] _ _ = refl
n-x⊆n⇒x∖n≡[] (h ∷ t) n n-x⊆n with proj₁ h ∈? n
... | yes _ = n-x⊆n⇒x∖n≡[] t n $ x∪y⊆z⇒y⊆z [ proj₁ h ] (names t) (x≋y⊆z (≡⇒≋ $ n-x∪y [ h ] t) n-x⊆n)
... | no h∉n = ⊥-elim $ h∉n $ n-x⊆n (proj₁ h ∈ proj₁ h ∷ names t ∋ here refl)
x∖x≡[] : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) → x ∖∖ names x ≡ []
x∖x≡[] x = n-x⊆n⇒x∖n≡[] x (names x) (≋⇒⊆ refl)
nr-[a] : ∀ {ℓ} {A : Set ℓ} {a : A} → NonRepetitive [ a ]
nr-[a] = (λ()) ∷ []
x≋y⇒x∖n≋y∖n : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ≋ y → (n : Names) → x ∖∖ n ≋ y ∖∖ n
x≋y⇒x∖n≋y∖n refl _ = refl
x≋y⇒x∖n≋y∖n {x = x} (perm l₁ x₁ x₂ l₂ p) n = ≋-trans p₀ $ ≋-trans (≡⇒≋ p₅) $ ≋-trans pg (≡⇒≋ $ ≡-sym g₅) where
p₀ : x ∖∖ n ≋ (l₁ ++ x₂ ∷ x₁ ∷ l₂) ∖∖ n
p₀ = x≋y⇒x∖n≋y∖n p n
p₁ : (l₁ ++ [ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n
p₁ = x∪y∖n≡x∖n∪y∖n l₁ ([ x₂ ] ++ [ x₁ ] ++ l₂) n
p₂ : l₁ ∖∖ n ++ ([ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ ([ x₁ ] ++ l₂) ∖∖ n
p₂ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₂ ] ([ x₁ ] ++ l₂) n)
p₃ : l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ ([ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n ++ l₂ ∖∖ n
p₃ = ≡-cong (λ z → l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₁ ] l₂ n)
p₄ : l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n ++ l₂ ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n
p₄ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (≡-sym $ ∪-assoc ([ x₂ ] ∖∖ n) ([ x₁ ] ∖∖ n) (l₂ ∖∖ n))
p₅ : (l₁ ++ [ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n
p₅ = ≡-trans p₁ $ ≡-trans p₂ $ ≡-trans p₃ p₄
pg : l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n ≋ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
pg = y≋ỳ⇒x∪y≋x∪ỳ (l₁ ∖∖ n) $ x≋x̀⇒x∪y≋x̀∪y (∪-sym ([ x₂ ] ∖∖ n) ([ x₁ ] ∖∖ n)) (l₂ ∖∖ n)
g₁ : (l₁ ++ [ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n
g₁ = x∪y∖n≡x∖n∪y∖n l₁ ([ x₁ ] ++ [ x₂ ] ++ l₂) n
g₂ : l₁ ∖∖ n ++ ([ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ ([ x₂ ] ++ l₂) ∖∖ n
g₂ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₁ ] ([ x₂ ] ++ l₂) n)
g₃ : l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ ([ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n ++ l₂ ∖∖ n
g₃ = ≡-cong (λ z → l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₂ ] l₂ n)
g₄ : l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n ++ l₂ ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
g₄ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (≡-sym $ ∪-assoc ([ x₁ ] ∖∖ n) ([ x₂ ] ∖∖ n) (l₂ ∖∖ n))
g₅ : (l₁ ++ [ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
g₅ = ≡-trans g₁ $ ≡-trans g₂ $ ≡-trans g₃ g₄
nr-x∪y⇒e∈x⇒e∈y⇒⊥ : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → NonRepetitive (x ∪ y) → e ∈ x → e ∈ y → ⊥
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = []} _ ()
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = h ∷ t} (h∉t∪y ∷ nr-t∪y) (here e≡h) = h∉t∪y ∘ e∈x⇒e∈y∪x t ∘ ≡-elim′ (λ x → x ∈ _) e≡h
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = h ∷ t} (h∉t∪y ∷ nr-t∪y) (there e∈t) = nr-x∪y⇒e∈x⇒e∈y⇒⊥ nr-t∪y e∈t
nr-x∪y⇒x∖y≡x : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) → NonRepetitiveNames (x ∪ y) → y ∖∖ names x ≡ y
nr-x∪y⇒x∖y≡x x y nr-x∪y = f₀ y (≋⇒⊆ refl) where
f₀ : ∀ t → t ⊆ y → t ∖∖ names x ≡ t
f₀ [] _ = refl
f₀ (h ∷ t) h∷t⊆y with proj₁ h ∈? names x
... | yes h∈x = ⊥-elim $ nr-x∪y⇒e∈x⇒e∈y⇒⊥ (≡-elim′ NonRepetitive (n-x∪y x y) nr-x∪y) h∈x (x⊆y⇒nx⊆ny h∷t⊆y $ here refl)
... | no _ = ≡-cong (_∷_ h) (f₀ t $ x∪y⊆z⇒y⊆z [ h ] t h∷t⊆y)
t≋t₁∪t₂⇒t∖t₁≋t₂ : ∀ {ℓ} {A : Set ℓ} {t : List (Named A)} → NonRepetitiveNames t → (t₁ t₂ : List (Named A)) → t ≋ t₁ ∪ t₂ → t ∖∖ names t₁ ≋ t₂
t≋t₁∪t₂⇒t∖t₁≋t₂ {t = t} nr-t t₁ t₂ t≋t₁∪t₂ = ≋-trans p₂ (≡⇒≋ $ nr-x∪y⇒x∖y≡x t₁ t₂ $ nr-x≋y (n-x≋y t≋t₁∪t₂) nr-t) where
n-t₁ = names t₁
p₁ : t ∖∖ n-t₁ ≋ (t₁ ∖∖ n-t₁) ∪ (t₂ ∖∖ n-t₁)
p₁ = ≋-trans (x≋y⇒x∖n≋y∖n t≋t₁∪t₂ n-t₁) (≡⇒≋ $ x∪y∖n≡x∖n∪y∖n t₁ t₂ n-t₁)
p₂ : t ∖∖ n-t₁ ≋ t₂ ∖∖ n-t₁
p₂ = ≡-elim′ (λ x → t ∖∖ n-t₁ ≋ x ∪ (t₂ ∖∖ n-t₁)) (x∖x≡[] t₁) p₁
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ : ∀ {ℓ} {A : Set ℓ} {x x̀ y ỳ : List A} → x ≋ x̀ → y ≋ ỳ → x ∪ y ≋ x̀ ∪ ỳ
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ x≋x̀ (refl {y}) = x≋x̀⇒x∪y≋x̀∪y x≋x̀ y
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ {x = x} {x̀ = x̀} {y = y} {ỳ = ._} x≋x̀ (perm l₁ x₁ x₂ l₂ y≋l₁x₂x₁l₂) = ≋-trans p₁ $ ≋-trans p₂ $ ≋-trans p₃ p₄ where
p₁ : x ∪ y ≋ x̀ ∪ (l₁ ++ x₂ ∷ x₁ ∷ l₂)
p₁ = x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ x≋x̀ y≋l₁x₂x₁l₂
p₂ : x̀ ∪ (l₁ ++ x₂ ∷ x₁ ∷ l₂) ≋ (x̀ ∪ l₁) ++ x₂ ∷ x₁ ∷ l₂
p₂ = ≡⇒≋ $ ≡-sym $ ∪-assoc x̀ l₁ (x₂ ∷ x₁ ∷ l₂)
p₃ : (x̀ ∪ l₁) ++ x₂ ∷ x₁ ∷ l₂ ≋ (x̀ ∪ l₁) ++ x₁ ∷ x₂ ∷ l₂
p₃ = perm (x̀ ∪ l₁) x₁ x₂ l₂ refl
p₄ : (x̀ ∪ l₁) ++ x₁ ∷ x₂ ∷ l₂ ≋ x̀ ∪ (l₁ ++ x₁ ∷ x₂ ∷ l₂)
p₄ = ≡⇒≋ $ ∪-assoc x̀ l₁ (x₁ ∷ x₂ ∷ l₂)
x∖y∪y≋y∖x∪x : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) →
let nx = names x
ny = names y
in filter-∈ x ny ≋ filter-∈ y nx → x ∖∖ ny ∪ y ≋ y ∖∖ nx ∪ x
x∖y∪y≋y∖x∪x x y p₀ = ≋-trans p₁ $ ≋-trans p₂ p₃ where
nx = names x
ny = names y
p₁ : x ∖∖ ny ∪ y ≋ x ∖∖ ny ∪ y ∖∖ nx ∪ filter-∈ y nx
p₁ = ≋-trans (y≋ỳ⇒x∪y≋x∪ỳ (x ∖∖ ny) (t≋t∖n∪t∩n y nx)) (≡⇒≋ $ ≡-sym $ ∪-assoc (x ∖∖ ny) (y ∖∖ nx) (filter-∈ y nx))
p₂ : (x ∖∖ ny ∪ y ∖∖ nx) ∪ filter-∈ y nx ≋ (y ∖∖ nx ∪ x ∖∖ ny) ∪ filter-∈ x ny
p₂ = x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ (∪-sym (x ∖∖ ny) (y ∖∖ nx)) (≋-sym p₀)
p₃ : y ∖∖ nx ∪ x ∖∖ ny ∪ filter-∈ x ny ≋ y ∖∖ nx ∪ x
p₃ = ≋-trans (≡⇒≋ $ ∪-assoc (y ∖∖ nx) (x ∖∖ ny) (filter-∈ x ny)) (≋-sym $ y≋ỳ⇒x∪y≋x∪ỳ (y ∖∖ nx) (t≋t∖n∪t∩n x ny))
names⇒named : Names → List (Named Unit)
names⇒named = mapL (λ x → x , unit)
nn-x∪y≡nn-x∪nn-y : ∀ x y → names⇒named (x ∪ y) ≡ names⇒named x ∪ names⇒named y
nn-x∪y≡nn-x∪nn-y [] y = refl
nn-x∪y≡nn-x∪nn-y (h ∷ t) y = ≡-cong (_∷_ _) (nn-x∪y≡nn-x∪nn-y t y)
nn-x≡x : ∀ x → names (names⇒named x) ≡ x
nn-x≡x [] = refl
nn-x≡x (h ∷ t) = ≡-cong (_∷_ h) (nn-x≡x t)
x≋y⇒nn-x≋nn-y : ∀ {x y} → x ≋ y → names⇒named x ≋ names⇒named y
x≋y⇒nn-x≋nn-y refl = refl
x≋y⇒nn-x≋nn-y {x = x} {y = ._} (perm l₁ x₁ x₂ l₂ x≋l₁x₂x₁l₂) = ≋-trans p₁ p₂ where
p₁ : names⇒named x ≋ names⇒named l₁ ++ (x₂ , unit) ∷ (x₁ , unit) ∷ names⇒named l₂
p₁ = ≋-trans (x≋y⇒nn-x≋nn-y x≋l₁x₂x₁l₂) (≡⇒≋ $ nn-x∪y≡nn-x∪nn-y l₁ (x₂ ∷ x₁ ∷ l₂))
p₂ : names⇒named l₁ ++ (x₂ , unit) ∷ (x₁ , unit) ∷ names⇒named l₂ ≋ names⇒named (l₁ ++ x₁ ∷ x₂ ∷ l₂)
p₂ = ≋-trans (perm (names⇒named l₁) (x₁ , unit) (x₂ , unit) (names⇒named l₂) refl) (≡⇒≋ $ ≡-sym $ nn-x∪y≡nn-x∪nn-y l₁ (x₁ ∷ x₂ ∷ l₂))
x≋y∪z⇒x∖y≋z : {x : Names} → NonRepetitive x → (y z : Names) → x ≋ y ∪ z → x ∖ y ≋ z
x≋y∪z⇒x∖y≋z {x} nr-x y z x≋y∪z = ≋-trans (≡⇒≋ $ ≡-sym $ ≡-trans p₂ p₃) (≋-trans p₁ $ ≡⇒≋ $ nn-x≡x z) where
ux = names⇒named x
uy = names⇒named y
uz = names⇒named z
ux≋uy∪uz : ux ≋ uy ∪ uz
ux≋uy∪uz = ≋-trans (x≋y⇒nn-x≋nn-y x≋y∪z) (≡⇒≋ $ nn-x∪y≡nn-x∪nn-y y z)
p₁ : names (ux ∖∖ names uy) ≋ names uz
p₁ = n-x≋y $ t≋t₁∪t₂⇒t∖t₁≋t₂ (≡-elim′ NonRepetitive (≡-sym $ nn-x≡x x) nr-x) uy uz ux≋uy∪uz
p₂ : names (ux ∖∖ names uy) ≡ names ux ∖ names uy
p₂ = n-x∖y ux (names uy)
p₃ : names ux ∖ names uy ≡ x ∖ y
p₃ = ≡-cong₂ _∖_ (nn-x≡x x) (nn-x≡x y)
h∈x⇒∃t,x≋h∷t : ∀ {ℓ} {A : Set ℓ} {h : A} {x : List A} → h ∈ x → NonRepetitive x → Σ[ t ∈ List A ] x ≋ h ∷ t
h∈x⇒∃t,x≋h∷t {h = h} .{x = x ∷ xs} (here {x = x} {xs = xs} h≡x) (x∉xs ∷ nr-xs) = xs , ≡⇒≋ (≡-cong (λ z → z ∷ xs) (≡-sym h≡x))
h∈x⇒∃t,x≋h∷t {h = h} .{x = x ∷ xs} (there {x = x} {xs = xs} h∈xs) (x∉xs ∷ nr-xs) =
let t , xs≋h∷t = ((Σ[ t ∈ List _ ] xs ≋ h ∷ t) ∋ h∈x⇒∃t,x≋h∷t h∈xs nr-xs)
p₁ : x ∷ xs ≋ x ∷ h ∷ t
p₁ = y≋ỳ⇒x∪y≋x∪ỳ [ x ] xs≋h∷t
p₂ : x ∷ h ∷ t ≋ h ∷ x ∷ t
p₂ = ≋-del-ins-l [] [ x ] h t
in x ∷ t , ≋-trans p₁ p₂
nr-x∪y⇒nr-y : ∀ {ℓ} {A : Set ℓ} (x y : List A) → NonRepetitive (x ∪ y) → NonRepetitive y
nr-x∪y⇒nr-y [] _ nr-y = nr-y
nr-x∪y⇒nr-y (h ∷ t) y (_ ∷ nr-t∪y) = nr-x∪y⇒nr-y t y nr-t∪y
x⊆y⇒∃x̀,y≋x∪x̀ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → NonRepetitive x → NonRepetitive y → x ⊆ y → Σ[ x̀ ∈ List A ] y ≋ x ∪ x̀
x⊆y⇒∃x̀,y≋x∪x̀ {x = []} {y = y} _ _ _ = y , refl
x⊆y⇒∃x̀,y≋x∪x̀ {x = h ∷ t} {y = y} (h∉t ∷ nr-t) nr-y h∷t⊆y =
let ỳ , y≋h∷ỳ = h∈x⇒∃t,x≋h∷t (h∷t⊆y (h ∈ h ∷ t ∋ here refl)) nr-y
p₁ : t ⊆ ỳ
p₁ = x⊆e∷y⇒e∉x⇒x⊆y (x⊆y≋z (x∪y⊆z⇒y⊆z [ h ] t h∷t⊆y) y≋h∷ỳ) h∉t
nr-ỳ = nr-x∪y⇒nr-y [ h ] ỳ $ nr-x≋y y≋h∷ỳ nr-y
t̀ , ỳ≋t∪t̀ = x⊆y⇒∃x̀,y≋x∪x̀ nr-t nr-ỳ p₁
p₂ : h ∷ ỳ ≋ (h ∷ t) ∪ t̀
p₂ = y≋ỳ⇒x∪y≋x∪ỳ [ h ] ỳ≋t∪t̀
in t̀ , ≋-trans y≋h∷ỳ p₂
t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ : ∀ {ℓ} {A : Set ℓ} {t₁ t₂ : List (Named A)} → NonRepetitiveNames t₁ → NonRepetitiveNames t₂ → t₁ ⊆ t₂ → t₂ ≋ t₁ ∪ t₂ ∖∖ names t₁
t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ {t₁ = t₁} {t₂ = t₂} nr-nt₁ nr-nt₂ t₁⊆t₂ = ≋-trans p₁ $ y≋ỳ⇒x∪y≋x∪ỳ t₁ p₆ where
n-t₁ = names t₁
nr-t₁ = nr-names⇒nr nr-nt₁
nr-t₂ = nr-names⇒nr nr-nt₂
t̀₁,t₁∪t̀₁≋t₂ = x⊆y⇒∃x̀,y≋x∪x̀ nr-t₁ nr-t₂ t₁⊆t₂
t̀₁ = proj₁ t̀₁,t₁∪t̀₁≋t₂
p₁ : t₂ ≋ t₁ ∪ t̀₁
p₁ = proj₂ t̀₁,t₁∪t̀₁≋t₂
p₂ : t₂ ∖∖ n-t₁ ≋ (t₁ ∪ t̀₁) ∖∖ n-t₁
p₂ = x≋y⇒x∖n≋y∖n p₁ n-t₁
p₃ : (t₁ ∪ t̀₁) ∖∖ n-t₁ ≡ t₁ ∖∖ n-t₁ ∪ t̀₁ ∖∖ n-t₁
p₃ = x∪y∖n≡x∖n∪y∖n t₁ t̀₁ n-t₁
p₄ : t₁ ∖∖ n-t₁ ∪ t̀₁ ∖∖ n-t₁ ≡ t̀₁ ∖∖ n-t₁
p₄ = ≡-cong (λ x → x ∪ t̀₁ ∖∖ n-t₁) (x∖x≡[] t₁)
p₅ : t̀₁ ∖∖ n-t₁ ≡ t̀₁
p₅ = nr-x∪y⇒x∖y≡x t₁ t̀₁ $ nr-x≋y (n-x≋y p₁) nr-nt₂
p₆ : t̀₁ ≋ t₂ ∖∖ n-t₁
p₆ = ≋-sym $ ≋-trans p₂ $ ≡⇒≋ $ ≡-trans p₃ $ ≡-trans p₄ p₅
t₁⊆t₂⇒t₁≋f∈-t₂-nt₁ : ∀ {ℓ} {A : Set ℓ} {t₁ t₂ : List (Named A)} → NonRepetitiveNames t₁ → NonRepetitiveNames t₂ → t₁ ⊆ t₂ → t₁ ≋ filter-∈ t₂ (names t₁)
t₁⊆t₂⇒t₁≋f∈-t₂-nt₁ {t₁ = t₁} {t₂ = t₂} nr-t₁ nr-t₂ t₁⊆t₂ = ≋-trans (≋-sym p₃) p₄ where
nt₁ = names t₁
p₁ : t₂ ≋ t₂ ∖∖ nt₁ ∪ t₁
p₁ = ≋-trans (t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ nr-t₁ nr-t₂ t₁⊆t₂) (∪-sym t₁ (t₂ ∖∖ nt₁))
p₂ : t₂ ≋ t₂ ∖∖ nt₁ ∪ filter-∈ t₂ nt₁
p₂ = t≋t∖n∪t∩n t₂ nt₁
p₃ : t₂ ∖∖ names (t₂ ∖∖ nt₁) ≋ t₁
p₃ = t≋t₁∪t₂⇒t∖t₁≋t₂ nr-t₂ (t₂ ∖∖ nt₁) t₁ p₁
p₄ : t₂ ∖∖ names (t₂ ∖∖ nt₁) ≋ filter-∈ t₂ nt₁
p₄ = t≋t₁∪t₂⇒t∖t₁≋t₂ nr-t₂ (t₂ ∖∖ nt₁) (filter-∈ t₂ nt₁) p₂
-- /lemmas
-- assertions
infix 4 _s-≢!_
_s-≢!_ : String → String → Set
x s-≢! y with x ≟ y
... | yes _ = ⊥
... | no _ = ⊤
s-≢!⇒≢? : ∀ {x y} → x s-≢! y → x ≢ y
s-≢!⇒≢? {x} {y} x≢!y with x ≟ y
s-≢!⇒≢? () | yes _
s-≢!⇒≢? _ | no p = p
s-NonRepetitive? : (n : Names) → Dec (NonRepetitive n)
s-NonRepetitive? [] = yes []
s-NonRepetitive? (h ∷ t) with h ∈? t | s-NonRepetitive? t
... | no h∉t | yes nr-t = yes (h∉t ∷ nr-t)
... | yes h∈t | _ = no f where
f : NonRepetitive (_ ∷ _) → _
f (h∉t ∷ _) = h∉t h∈t
... | _ | no ¬nr-t = no f where
f : NonRepetitive (_ ∷ _) → _
f (_ ∷ nr-t) = ¬nr-t nr-t
s-NonRepetitive! : Names → Set
s-NonRepetitive! n with s-NonRepetitive? n
... | yes _ = ⊤
... | no _ = ⊥
NonRepetitiveNames! : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Set
NonRepetitiveNames! = s-NonRepetitive! ∘ names
s-nr!⇒nr : {n : Names} → s-NonRepetitive! n → NonRepetitive n
s-nr!⇒nr {n = n} _ with s-NonRepetitive? n
s-nr!⇒nr _ | yes p = p
s-nr!⇒nr () | no _
-- /assertions
| 43.562176
| 151
| 0.43149
|
39e81b9cbc22ca8bee876244b1bfab9f9f1cc67a
| 399
|
agda
|
Agda
|
test/interaction/Issue1640.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue1640.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue1640.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
module M (X : Set) where
postulate
F : Set
G : Set
data ⊥ : Set where
open M ⊥ hiding (F)
easy : M.G ⊥
easy = {!!} -- G
hard : M.F ⊥
hard = {!!} -- M.F ⊥ (and not .Issue1640._.F)
data ⊤ : Set where
tt : ⊤
module With where
private
F : ⊤ → Set
F x with x
F _ | tt = ⊥
T = F
tricky : ∀ t → With.T t
tricky t = {!!} -- .Issue1640.With.F t | t
| 12.46875
| 48
| 0.496241
|
10a7fc8e03e7e7eba9859720dcc89b90e3ba5ca8
| 5,564
|
agda
|
Agda
|
agda-stdlib/src/Data/Vec/N-ary.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Vec/N-ary.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Vec/N-ary.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Code for converting Vec A n → B to and from n-ary functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.N-ary where
open import Data.Nat.Base hiding (_⊔_)
open import Data.Product as Prod
open import Data.Vec.Base
open import Function.Base
open import Function.Equivalence using (_⇔_; equivalence)
open import Level using (Level; _⊔_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
private
variable
a b c ℓ ℓ₁ ℓ₂ : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- N-ary functions
N-ary-level : Level → Level → ℕ → Level
N-ary-level ℓ₁ ℓ₂ zero = ℓ₂
N-ary-level ℓ₁ ℓ₂ (suc n) = ℓ₁ ⊔ N-ary-level ℓ₁ ℓ₂ n
N-ary : ∀ (n : ℕ) → Set ℓ₁ → Set ℓ₂ → Set (N-ary-level ℓ₁ ℓ₂ n)
N-ary zero A B = B
N-ary (suc n) A B = A → N-ary n A B
------------------------------------------------------------------------
-- Conversion
curryⁿ : ∀ {n} → (Vec A n → B) → N-ary n A B
curryⁿ {n = zero} f = f []
curryⁿ {n = suc n} f = λ x → curryⁿ (f ∘ _∷_ x)
_$ⁿ_ : ∀ {n} → N-ary n A B → (Vec A n → B)
f $ⁿ [] = f
f $ⁿ (x ∷ xs) = f x $ⁿ xs
------------------------------------------------------------------------
-- Quantifiers
module _ {A : Set a} where
-- Universal quantifier.
∀ⁿ : ∀ n → N-ary n A (Set ℓ) → Set (N-ary-level a ℓ n)
∀ⁿ zero P = P
∀ⁿ (suc n) P = ∀ x → ∀ⁿ n (P x)
-- Universal quantifier with implicit (hidden) arguments.
∀ⁿʰ : ∀ n → N-ary n A (Set ℓ) → Set (N-ary-level a ℓ n)
∀ⁿʰ zero P = P
∀ⁿʰ (suc n) P = ∀ {x} → ∀ⁿʰ n (P x)
-- Existential quantifier.
∃ⁿ : ∀ n → N-ary n A (Set ℓ) → Set (N-ary-level a ℓ n)
∃ⁿ zero P = P
∃ⁿ (suc n) P = ∃ λ x → ∃ⁿ n (P x)
------------------------------------------------------------------------
-- N-ary function equality
Eq : ∀ {A : Set a} {B : Set b} {C : Set c} n →
REL B C ℓ → REL (N-ary n A B) (N-ary n A C) (N-ary-level a ℓ n)
Eq n _∼_ f g = ∀ⁿ n (curryⁿ {n = n} λ xs → (f $ⁿ xs) ∼ (g $ⁿ xs))
-- A variant where all the arguments are implicit (hidden).
Eqʰ : ∀ {A : Set a} {B : Set b} {C : Set c} n →
REL B C ℓ → REL (N-ary n A B) (N-ary n A C) (N-ary-level a ℓ n)
Eqʰ n _∼_ f g = ∀ⁿʰ n (curryⁿ {n = n} λ xs → (f $ⁿ xs) ∼ (g $ⁿ xs))
------------------------------------------------------------------------
-- Some lemmas
-- The functions curryⁿ and _$ⁿ_ are inverses.
left-inverse : ∀ {n} (f : Vec A n → B) →
∀ xs → (curryⁿ f $ⁿ xs) ≡ f xs
left-inverse f [] = refl
left-inverse f (x ∷ xs) = left-inverse (f ∘ _∷_ x) xs
right-inverse : ∀ n (f : N-ary n A B) →
Eq n _≡_ (curryⁿ (_$ⁿ_ {n = n} f)) f
right-inverse zero f = refl
right-inverse (suc n) f = λ x → right-inverse n (f x)
-- ∀ⁿ can be expressed in an "uncurried" way.
uncurry-∀ⁿ : ∀ n {P : N-ary n A (Set ℓ)} →
∀ⁿ n P ⇔ (∀ (xs : Vec A n) → P $ⁿ xs)
uncurry-∀ⁿ {a} {A} {ℓ} n = equivalence (⇒ n) (⇐ n)
where
⇒ : ∀ n {P : N-ary n A (Set ℓ)} →
∀ⁿ n P → (∀ (xs : Vec A n) → P $ⁿ xs)
⇒ zero p [] = p
⇒ (suc n) p (x ∷ xs) = ⇒ n (p x) xs
⇐ : ∀ n {P : N-ary n A (Set ℓ)} →
(∀ (xs : Vec A n) → P $ⁿ xs) → ∀ⁿ n P
⇐ zero p = p []
⇐ (suc n) p = λ x → ⇐ n (p ∘ _∷_ x)
-- ∃ⁿ can be expressed in an "uncurried" way.
uncurry-∃ⁿ : ∀ n {P : N-ary n A (Set ℓ)} →
∃ⁿ n P ⇔ (∃ λ (xs : Vec A n) → P $ⁿ xs)
uncurry-∃ⁿ {a} {A} {ℓ} n = equivalence (⇒ n) (⇐ n)
where
⇒ : ∀ n {P : N-ary n A (Set ℓ)} →
∃ⁿ n P → (∃ λ (xs : Vec A n) → P $ⁿ xs)
⇒ zero p = ([] , p)
⇒ (suc n) (x , p) = Prod.map (_∷_ x) id (⇒ n p)
⇐ : ∀ n {P : N-ary n A (Set ℓ)} →
(∃ λ (xs : Vec A n) → P $ⁿ xs) → ∃ⁿ n P
⇐ zero ([] , p) = p
⇐ (suc n) (x ∷ xs , p) = (x , ⇐ n (xs , p))
-- Conversion preserves equality.
module _ (_∼_ : REL B C ℓ) where
curryⁿ-cong : ∀ {n} (f : Vec A n → B) (g : Vec A n → C) →
(∀ xs → f xs ∼ g xs) →
Eq n _∼_ (curryⁿ f) (curryⁿ g)
curryⁿ-cong {n = zero} f g hyp = hyp []
curryⁿ-cong {n = suc n} f g hyp = λ x →
curryⁿ-cong (f ∘ _∷_ x) (g ∘ _∷_ x) (λ xs → hyp (x ∷ xs))
curryⁿ-cong⁻¹ : ∀ {n} (f : Vec A n → B) (g : Vec A n → C) →
Eq n _∼_ (curryⁿ f) (curryⁿ g) →
∀ xs → f xs ∼ g xs
curryⁿ-cong⁻¹ f g hyp [] = hyp
curryⁿ-cong⁻¹ f g hyp (x ∷ xs) =
curryⁿ-cong⁻¹ (f ∘ _∷_ x) (g ∘ _∷_ x) (hyp x) xs
appⁿ-cong : ∀ {n} (f : N-ary n A B) (g : N-ary n A C) →
Eq n _∼_ f g →
(xs : Vec A n) → (f $ⁿ xs) ∼ (g $ⁿ xs)
appⁿ-cong f g hyp [] = hyp
appⁿ-cong f g hyp (x ∷ xs) = appⁿ-cong (f x) (g x) (hyp x) xs
appⁿ-cong⁻¹ : ∀ {n} (f : N-ary n A B) (g : N-ary n A C) →
((xs : Vec A n) → (f $ⁿ xs) ∼ (g $ⁿ xs)) →
Eq n _∼_ f g
appⁿ-cong⁻¹ {n = zero} f g hyp = hyp []
appⁿ-cong⁻¹ {n = suc n} f g hyp = λ x →
appⁿ-cong⁻¹ (f x) (g x) (λ xs → hyp (x ∷ xs))
-- Eq and Eqʰ are equivalent.
Eq-to-Eqʰ : ∀ n (_∼_ : REL B C ℓ) {f : N-ary n A B} {g : N-ary n A C} →
Eq n _∼_ f g → Eqʰ n _∼_ f g
Eq-to-Eqʰ zero _∼_ eq = eq
Eq-to-Eqʰ (suc n) _∼_ eq = Eq-to-Eqʰ n _∼_ (eq _)
Eqʰ-to-Eq : ∀ n (_∼_ : REL B C ℓ) {f : N-ary n A B} {g : N-ary n A C} →
Eqʰ n _∼_ f g → Eq n _∼_ f g
Eqʰ-to-Eq zero _∼_ eq = eq
Eqʰ-to-Eq (suc n) _∼_ eq = λ _ → Eqʰ-to-Eq n _∼_ eq
| 31.794286
| 72
| 0.442667
|
dcc08f82babe35d7db4bc271bba9f98cfc41a31d
| 938
|
agda
|
Agda
|
test/interaction/Issue3687.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3687.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3687.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2019-04-10, issue #3687, name mayhem when printing module contents (C-c C-o)
-- {-# OPTIONS -v interaction.contents.record:20 #-}
record Cat : Set₁ where
field
Obj : Set
Hom : (A B : Obj) → Set
Eq : ∀{A B} (f g : Hom A B) → Set
id : (A : Obj) → Hom A A
comp : ∀{A B C} (f : Hom B C) (g : Hom A B) → Hom A C
record Functor (C1 C2 : Cat) : Set where
record FunEq {C D : Cat} (F G : Functor C D) : Set₁ where
field
eqMap : ∀{c d} (f g : Cat.Hom C c d) (eq : Cat.Eq C f g) → Set
test : ∀ C D (F G : Functor C D) → FunEq F G
FunEq.eqMap (test C D F G) f g f=g = {!D!} -- C-c C-o
-- In the output, the names are completely garbled:
-- Names
-- Obj : Set
-- Hom : f=g → f=g → Set
-- Eq : {A B : g} → f=g A B → f=g A B → Set
-- id : (A : f) → g A A
-- comp : {A B : d} {C = C₁ : d} → f B C₁ → f A B → f A C₁
-- test/interaction$ make AGDA_BIN=agda-2.5.1.1 Issue3687.cmp
| 29.3125
| 88
| 0.523454
|
183e8c3791a8f12458e4a0a003ea28dccd84914e
| 3,817
|
agda
|
Agda
|
src/System/IO/Transducers/Properties/TwoCategory.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | 10
|
2015-01-04T13:45:16.000Z
|
2021-09-15T04:35:41.000Z
|
src/System/IO/Transducers/Properties/TwoCategory.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | null | null | null |
src/System/IO/Transducers/Properties/TwoCategory.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | 2
|
2017-08-10T06:12:54.000Z
|
2022-03-12T11:40:23.000Z
|
open import Coinduction using ( ♭ )
open import Data.Product using ( _,_ )
open import Relation.Binary using ( Poset )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; trans ; cong ; subst₂ ) renaming ( setoid to ≡-setoid )
open import System.IO.Transducers using ( _⇒_ ; inp ; out ; done ; ⟦_⟧ ; _≃_ ; _≲_ ; _⟫_ )
open import System.IO.Transducers.Session using ( Session )
open import System.IO.Transducers.Trace using ( Trace ; [] ; _∷_ ; _⊑_ )
open import System.IO.Transducers.Properties.Category using ( ⟫-semantics )
import Relation.Binary.PartialOrderReasoning
module System.IO.Transducers.Properties.TwoCategory where
-- The category is poset-enriched, with order inherited from prefix order on traces.
-- Reflexivity
⊑-refl : ∀ {S} (as : Trace S) → (as ⊑ as)
⊑-refl [] = []
⊑-refl (a ∷ as) = (a ∷ ⊑-refl as)
≡-impl-⊑ : ∀ {S} {as bs : Trace S} → (as ≡ bs) → (as ⊑ bs)
≡-impl-⊑ refl = ⊑-refl _
≲-refl : ∀ {S T} (f : Trace S → Trace T) → (f ≲ f)
≲-refl f as = ⊑-refl (f as)
≃-impl-≲ : ∀ {S T} {f g : Trace S → Trace T} → (f ≃ g) → (f ≲ g)
≃-impl-≲ f≃g as = ≡-impl-⊑ (f≃g as)
-- Transitivity
⊑-trans : ∀ {S} {as bs cs : Trace S} → (as ⊑ bs) → (bs ⊑ cs) → (as ⊑ cs)
⊑-trans [] bs = []
⊑-trans (a ∷ as) (.a ∷ bs) = (a ∷ ⊑-trans as bs)
≲-trans : ∀ {S T} {f g h : Trace S → Trace T} → (f ≲ g) → (g ≲ h) → (f ≲ h)
≲-trans f≲g g≲h as = ⊑-trans (f≲g as) (g≲h as)
-- Antisymmetry
⊑-antisym : ∀ {S} {as bs : Trace S} → (as ⊑ bs) → (bs ⊑ as) → (as ≡ bs)
⊑-antisym [] [] = refl
⊑-antisym (a ∷ as) (.a ∷ bs) = cong (_∷_ a) (⊑-antisym as bs)
≲-antisym : ∀ {S T} {f g : Trace S → Trace T} → (f ≲ g) → (g ≲ f) → (f ≃ g)
≲-antisym f≲g g≲f as = ⊑-antisym (f≲g as) (g≲f as)
-- ⊑ and ≲ form posets
⊑-poset : Session → Poset _ _ _
⊑-poset S = record
{ Carrier = Trace S
; _≈_ = _≡_
; _≤_ = _⊑_
; isPartialOrder = record
{ antisym = ⊑-antisym
; isPreorder = record
{ reflexive = ≡-impl-⊑
; trans = ⊑-trans
; ∼-resp-≈ = ((λ bs≡cs → subst₂ _⊑_ refl bs≡cs) , (λ as≡bs → subst₂ _⊑_ as≡bs refl))
; isEquivalence = Relation.Binary.Setoid.isEquivalence (≡-setoid (Trace S))
}
}
}
≲-poset : Session → Session → Poset _ _ _
≲-poset S T = record
{ Carrier = (Trace S → Trace T)
; _≈_ = _≃_
; _≤_ = _≲_
; isPartialOrder = record
{ antisym = ≲-antisym
; isPreorder = record
{ reflexive = ≃-impl-≲
; trans = ≲-trans
; ∼-resp-≈ = (λ P≃Q P≲R as → subst₂ _⊑_ refl (P≃Q as) (P≲R as)) , λ Q≃R Q≲P as → subst₂ _⊑_ (Q≃R as) refl (Q≲P as)
; isEquivalence = record
{ refl = λ as → refl
; sym = λ P≃Q as → sym (P≃Q as)
; trans = λ P≃Q Q≃R as → trans (P≃Q as) (Q≃R as)
}
}
}
}
-- Inequational reasoning
module ⊑-Reasoning {S} where
open Relation.Binary.PartialOrderReasoning (⊑-poset S) public renaming ( _≤⟨_⟩_ to _⊑⟨_⟩_ ; _≈⟨_⟩_ to _≡⟨_⟩_ )
module ≲-Reasoning {S T} where
open Relation.Binary.PartialOrderReasoning (≲-poset S T) public renaming ( _≤⟨_⟩_ to _≲⟨_⟩_ ; _≈⟨_⟩_ to _≃⟨_⟩_ )
open ⊑-Reasoning
-- Processes are ⊑-monotone
P-monotone : ∀ {S T as bs} → (P : S ⇒ T) → (as ⊑ bs) → (⟦ P ⟧ as ⊑ ⟦ P ⟧ bs)
P-monotone (inp F) [] = []
P-monotone (inp F) (a ∷ as⊑bs) = P-monotone (♭ F a) as⊑bs
P-monotone (out b P) as⊑bs = b ∷ P-monotone P as⊑bs
P-monotone done as⊑bs = as⊑bs
-- Composition is ≲-monotone
⟫-monotone : ∀ {S T U} (P₁ P₂ : S ⇒ T) (Q₁ Q₂ : T ⇒ U) →
(⟦ P₁ ⟧ ≲ ⟦ P₂ ⟧) → (⟦ Q₁ ⟧ ≲ ⟦ Q₂ ⟧) →
(⟦ P₁ ⟫ Q₁ ⟧ ≲ ⟦ P₂ ⟫ Q₂ ⟧)
⟫-monotone P₁ P₂ Q₁ Q₂ P₁≲P₂ Q₁≲Q₂ as =
begin
⟦ P₁ ⟫ Q₁ ⟧ as
≡⟨ ⟫-semantics P₁ Q₁ as ⟩
⟦ Q₁ ⟧ (⟦ P₁ ⟧ as)
⊑⟨ P-monotone Q₁ (P₁≲P₂ as) ⟩
⟦ Q₁ ⟧ (⟦ P₂ ⟧ as)
⊑⟨ Q₁≲Q₂ (⟦ P₂ ⟧ as) ⟩
⟦ Q₂ ⟧ (⟦ P₂ ⟧ as)
≡⟨ sym (⟫-semantics P₂ Q₂ as) ⟩
⟦ P₂ ⟫ Q₂ ⟧ as
∎
| 31.545455
| 132
| 0.534189
|
dc4c3f7a184311438eb95be91d6882ac3f40592c
| 256
|
agda
|
Agda
|
Cubical/Foundations/Pointed.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Pointed.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Pointed.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.Foundations.Pointed where
open import Cubical.Foundations.Pointed.Base public
open import Cubical.Foundations.Pointed.Properties public
open import Cubical.Foundations.Pointed.Homogeneous
| 32
| 57
| 0.816406
|
187dd8a19dd8a274457a5e1198e4efa77ba4939d
| 646
|
agda
|
Agda
|
test/interaction/Issue1083.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Issue1083.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue1083.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- Andreas, 2013-04-06
-- Interaction point buried in postponed type checking problem
module Issue1083 where
data Bool : Set where true false : Bool
T : Bool → Set
T true = Bool → Bool
T false = Bool
postulate
f : {x : Bool} → T x
test : (x : Bool) → T x
test true = f {!!}
test false = {!!}
-- Constraints show: _10 := (_ : T _x_9) ? : Bool
-- So there is a question mark which has never been seen by the type checker.
-- It is buried in a postponed type-checking problem.
-- Interaction points should probably be created by the scope checker,
-- and then hooked up to meta variables by the type checker.
-- This is how it works now.
| 23.925926
| 77
| 0.685759
|
0bdb33a245e87c059b1d20d535bc900079280c90
| 694
|
agda
|
Agda
|
_assets/agda/Girard.agda
|
ionathanch/ionathanch.github.io
|
d54cdaf24391b2726e491a18cba2d2d8ae3ac20b
|
[
"MIT"
] | null | null | null |
_assets/agda/Girard.agda
|
ionathanch/ionathanch.github.io
|
d54cdaf24391b2726e491a18cba2d2d8ae3ac20b
|
[
"MIT"
] | null | null | null |
_assets/agda/Girard.agda
|
ionathanch/ionathanch.github.io
|
d54cdaf24391b2726e491a18cba2d2d8ae3ac20b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --type-in-type #-}
data ⊥ : Set where
℘ : ∀ {ℓ} → Set ℓ → Set _
℘ {ℓ} S = S → Set
U : Set
U = ∀ (X : Set) → (℘ (℘ X) → X) → ℘ (℘ X)
{- If using two impredicative universe layers instead of type-in-type:
U : Set₁
U = ∀ (X : Set₁) → (℘ (℘ X) → X) → ℘ (℘ X)
-}
τ : ℘ (℘ U) → U
τ t = λ X f p → t (λ x → p (f (x X f)))
σ : U → ℘ (℘ U)
σ s = s U τ
Δ : ℘ U
Δ y = (∀ p → σ y p → p (τ (σ y))) → ⊥
Ω : U
Ω = τ (λ p → (∀ x → σ x p → p x))
R : ∀ p → (∀ x → σ x p → p x) → p Ω
R _ 𝟙 = 𝟙 Ω (λ x → 𝟙 (τ (σ x)))
M : ∀ x → σ x Δ → Δ x
M _ 𝟚 𝟛 = 𝟛 Δ 𝟚 (λ p → 𝟛 (λ y → p (τ (σ y))))
L : (∀ p → (∀ x → σ x p → p x) → p Ω) → ⊥
L 𝟘 = 𝟘 Δ M (λ p → 𝟘 (λ y → p (τ (σ y))))
false : ⊥
false = L R
| 18.263158
| 70
| 0.367435
|
dc4724086c959be7572e860d727b9b61c2336ebf
| 164,645
|
agda
|
Agda
|
src/Lens/Non-dependent/Traditional/Erased.agda
|
nad/dependent-lenses
|
f2da6f7e95b87ca525e8ea43929c6d6163a74811
|
[
"MIT"
] | 3
|
2020-04-16T12:10:46.000Z
|
2020-07-03T08:55:52.000Z
|
src/Lens/Non-dependent/Traditional/Erased.agda
|
nad/dependent-lenses
|
f2da6f7e95b87ca525e8ea43929c6d6163a74811
|
[
"MIT"
] | null | null | null |
src/Lens/Non-dependent/Traditional/Erased.agda
|
nad/dependent-lenses
|
f2da6f7e95b87ca525e8ea43929c6d6163a74811
|
[
"MIT"
] | 1
|
2020-07-01T14:33:26.000Z
|
2020-07-01T14:33:26.000Z
|
------------------------------------------------------------------------
-- Traditional non-dependent lenses with erased lens laws
------------------------------------------------------------------------
import Equality.Path as P
module Lens.Non-dependent.Traditional.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id; [_,_]) renaming (_∘_ to _⊚_)
import Bi-invertibility.Erased
open import Bijection equality-with-J as Bij using (_↔_)
open import Circle eq using (𝕊¹)
open import Circle.Erased eq as CE using (𝕊¹ᴱ)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Erased.Cubical eq as EEq
using (_≃ᴱ_; Is-equivalenceᴱ)
open import Equivalence.Erased.Contractible-preimages equality-with-J
as ECP using (Contractibleᴱ; _⁻¹ᴱ_)
open import Erased.Cubical eq
open import Function-universe equality-with-J as F
hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as PT using (∥_∥)
open import H-level.Truncation.Propositional.Erased eq as TE
using (∥_∥ᴱ; ∣_∣)
open import Preimage equality-with-J using (_⁻¹_)
open import Surjection equality-with-J as Surjection using (_↠_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq as Non-dependent
hiding (no-first-projection-lens)
import Lens.Non-dependent.Traditional eq as T
import Lens.Non-dependent.Traditional.Combinators eq as TC
private
variable
a b c p : Level
A A₁ A₂ B B₁ B₂ C D : Type a
u v x₁ x₂ y₁ y₂ : A
------------------------------------------------------------------------
-- Traditional lenses
-- Lenses with erased lens laws.
record Lens (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
-- Getter and setter.
get : A → B
set : A → B → A
-- Lens laws.
@0 get-set : ∀ a b → get (set a b) ≡ b
@0 set-get : ∀ a → set a (get a) ≡ a
@0 set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂
-- A combination of get and set.
modify : (B → B) → A → A
modify f x = set x (f (get x))
instance
-- Traditional lenses with erased laws have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
-- Lens A B is isomorphic to a nested Σ-type.
Lens-as-Σ :
Lens A B ↔
∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))
Lens-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ l → get l , set l
, [ get-set l , set-get l , set-set l ]
; from = λ { (get , set , [ get-set , set-get , set-set ]) →
record
{ get = get
; set = set
; get-set = get-set
; set-get = set-get
; set-set = set-set
}
}
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
where
open Lens
-- In erased contexts Lens A B is equivalent to T.Lens A B.
@0 Lens≃Traditional-lens : Lens A B ≃ T.Lens A B
Lens≃Traditional-lens {A = A} {B = B} =
Lens A B ↔⟨ Lens-as-Σ ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → erased Erased↔) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↔⟨ inverse T.Lens-as-Σ ⟩□
T.Lens A B □
-- Lenses without erased proofs can be turned into lenses with erased
-- proofs (in erased contexts).
@0 Traditional-lens→Lens : T.Lens A B → Lens A B
Traditional-lens→Lens = _≃_.from Lens≃Traditional-lens
private
-- The forward direction of Lens≃Traditional-lens.
@0 trad : Lens A B → T.Lens A B
trad = _≃_.to Lens≃Traditional-lens
private
variable
l₁ l₂ : Lens A B
------------------------------------------------------------------------
-- Somewhat coherent lenses
-- Traditional lenses with erased lens laws that satisfy some extra
-- coherence properties (that are also erased).
record Coherent-lens (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
lens : Lens A B
open Lens lens public
field
@0 get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a)
@0 get-set-set :
∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))
instance
-- Somewhat coherent lenses have getters and setters.
coherent-has-getter-and-setter :
Has-getter-and-setter (Coherent-lens {a = a} {b = b})
coherent-has-getter-and-setter = record
{ get = Coherent-lens.get
; set = Coherent-lens.set
}
-- Coherent-lens A B is equivalent to a nested Σ-type.
Coherent-lens-as-Σ :
Coherent-lens A B ≃
∃ λ (l : Lens A B) →
let open Lens l in
Erased
((∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))))
Coherent-lens-as-Σ = Eq.↔→≃
(λ l → lens l , [ get-set-get l , get-set-set l ])
(λ (l , [ get-set-get , get-set-set ]) → record
{ lens = l
; get-set-get = get-set-get
; get-set-set = get-set-set
})
refl
refl
where
open Coherent-lens
-- In erased contexts Coherent-lens A B is equivalent to
-- T.Coherent-lens A B.
@0 Coherent-lens≃Traditional-coherent-lens :
Coherent-lens A B ≃ T.Coherent-lens A B
Coherent-lens≃Traditional-coherent-lens {A = A} {B = B} =
Coherent-lens A B ↔⟨ Coherent-lens-as-Σ ⟩
(∃ λ (l : Lens A B) →
let open Lens l in
Erased
((∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))))) ↔⟨ (Σ-cong Lens≃Traditional-lens λ _ → erased Erased↔) ⟩
(∃ λ (l : T.Lens A B) →
let open T.Lens l in
(∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))) ↔⟨ inverse T.Coherent-lens-as-Σ ⟩
T.Coherent-lens A B □
------------------------------------------------------------------------
-- Some lemmas
-- If two lenses have equal setters, then they also have equal
-- getters (in erased contexts).
@0 getters-equal-if-setters-equal :
let open Lens in
(l₁ l₂ : Lens A B) →
set l₁ ≡ set l₂ →
get l₁ ≡ get l₂
getters-equal-if-setters-equal l₁ l₂ =
Lens.set l₁ ≡ Lens.set l₂ ↔⟨⟩
T.Lens.set (trad l₁) ≡ T.Lens.set (trad l₂) ↝⟨ T.getters-equal-if-setters-equal (trad l₁) (trad l₂) ⟩
T.Lens.get (trad l₁) ≡ T.Lens.get (trad l₂) ↔⟨⟩
Lens.get l₁ ≡ Lens.get l₂ □
-- If the forward direction of an equivalence with erased proofs is
-- Lens.get l, then the setter of l can be expressed using the other
-- direction of the equivalence (in erased contexts).
@0 from≡set :
∀ (l : Lens A B) is-equiv →
let open Lens
A≃B = EEq.⟨ get l , is-equiv ⟩
in
∀ a b → _≃ᴱ_.from A≃B b ≡ set l a b
from≡set l is-equiv =
T.from≡set (trad l) (EEq.Is-equivalenceᴱ→Is-equivalence is-equiv)
-- If A and B are "very stable n levels up" (given certain
-- assumptions), then Lens A B is "very stable n levels up".
Very-stable-Lensⁿ :
∀ n →
(A → B → For-iterated-equality n Very-stable A) →
(A → For-iterated-equality n Very-stable B) →
For-iterated-equality n Very-stable (Lens A B)
Very-stable-Lensⁿ {A = A} {B = B} n A-s B-s =
Very-stable-congⁿ _ n (inverse Lens-as-Σ) $
Very-stable-Σⁿ n (Very-stable-Πⁿ ext n λ a →
B-s a) λ _ →
Very-stable-Σⁿ n (Very-stable-Πⁿ ext n λ a →
Very-stable-Πⁿ ext n λ b →
A-s a b) λ _ →
Very-stable→Very-stableⁿ n
Very-stable-Erased
------------------------------------------------------------------------
-- Some lens isomorphisms
-- Lens preserves equivalences.
Lens-cong : A₁ ≃ A₂ → B₁ ≃ B₂ → Lens A₁ B₁ ≃ Lens A₂ B₂
Lens-cong {A₁ = A₁} {A₂ = A₂} {B₁ = B₁} {B₂ = B₂} A₁≃A₂ B₁≃B₂ =
Lens A₁ B₁ ↔⟨ Lens-as-Σ ⟩
(∃ λ (get : A₁ → B₁) →
∃ λ (set : A₁ → B₁ → A₁) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↝⟨ (Σ-cong (→-cong ext A₁≃A₂ B₁≃B₂) λ get →
Σ-cong (→-cong ext A₁≃A₂ $ →-cong ext B₁≃B₂ A₁≃A₂) λ set →
Erased-cong (
(Π-cong ext A₁≃A₂ λ a → Π-cong ext B₁≃B₂ λ b →
inverse (Eq.≃-≡ B₁≃B₂) F.∘
(≡⇒≃ $ cong (_≡ _)
(get (set a b) ≡⟨ sym $ cong₂ (λ a b → get (set a b))
(_≃_.left-inverse-of A₁≃A₂ _)
(_≃_.left-inverse-of B₁≃B₂ _) ⟩
get (set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))) ≡⟨ cong get $ sym $ _≃_.left-inverse-of A₁≃A₂ _ ⟩∎
get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂
(set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))))) ∎)))
×-cong
(Π-cong ext A₁≃A₂ λ a →
inverse (Eq.≃-≡ A₁≃A₂) F.∘
(≡⇒≃ $ cong (_≡ _)
(set a (get a) ≡⟨ cong (set a) $ sym $ _≃_.left-inverse-of B₁≃B₂ _ ⟩
set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a))) ≡⟨ cong (λ a → set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a)))) $ sym $
_≃_.left-inverse-of A₁≃A₂ _ ⟩∎
set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂
(get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))))) ∎)))
×-cong
(inverse $ Π-cong ext (inverse A₁≃A₂) λ a →
inverse $ Π-cong ext B₁≃B₂ λ b₁ →
inverse $ Π-cong ext (inverse B₁≃B₂) λ b₂ →
(≡⇒≃ $ cong (λ a′ → set a′ (_≃_.from B₁≃B₂ b₂) ≡
set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ b₂))
(_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂
(set (_≃_.from A₁≃A₂ a)
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)))) ≡⟨ _≃_.left-inverse-of A₁≃A₂ _ ⟩
set (_≃_.from A₁≃A₂ a)
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)) ≡⟨ cong (set (_≃_.from A₁≃A₂ a)) $
_≃_.left-inverse-of B₁≃B₂ _ ⟩∎
set (_≃_.from A₁≃A₂ a) b₁ ∎)) F.∘
Eq.≃-≡ A₁≃A₂))) ⟩
(∃ λ (get : A₂ → B₂) →
∃ λ (set : A₂ → B₂ → A₂) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ inverse Lens-as-Σ ⟩□
Lens A₂ B₂ □
-- If B is a proposition (when A is inhabited), then Lens A B is
-- equivalent (with erased proofs) to
-- (A → B) × Erased ((a : A) → a ≡ a).
lens-to-proposition≃ᴱ :
@0 (A → Is-proposition B) →
Lens A B ≃ᴱ ((A → B) × Erased ((a : A) → a ≡ a))
lens-to-proposition≃ᴱ {A = A} {B = B} B-prop =
Lens A B ↔⟨ Lens-as-Σ ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (
drop-⊤-left-× λ _ →
_⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ a →
Π-closure ext 0 λ _ →
+⇒≡ (B-prop a))) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased
((∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ get → ∃-cong λ set → Erased-cong (∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
≡⇒≃ (
(set (set a b₁) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a b) b₂ ≡ _) (B-prop a _ _) ⟩
(set (set a (get a)) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a (get a)) b ≡ _) (B-prop a _ _) ⟩
(set (set a (get a)) (get (set a (get a))) ≡ set a b₂) ≡⟨ cong (λ b → _ ≡ set a b) (B-prop a _ _) ⟩∎
(set (set a (get a)) (get (set a (get a))) ≡ set a (get a)) ∎))) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased
((∀ a → set a (get a) ≡ a) ×
(∀ a → B → B →
set (set a (get a)) (get (set a (get a))) ≡
set a (get a)))) ↝⟨ (∃-cong λ get →
EEq.Σ-cong-≃ᴱ-Erased (A→B→A≃ᴱA→A get) λ _ → F.id) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
((∀ a → f a ≡ a) ×
(∀ a → B → B → f (f a) ≡ f a))) ↝⟨ (∃-cong λ get → ∃-cong λ _ → Erased-cong (∃-cong λ _ →
∀-cong ext λ a →
EEq.drop-⊤-left-Π-≃ᴱ-Erased ext (B≃ᴱ⊤ get a) F.∘
EEq.drop-⊤-left-Π-≃ᴱ-Erased ext (B≃ᴱ⊤ get a))) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
((∀ a → f a ≡ a) ×
(∀ a → f (f a) ≡ f a))) ↔⟨ (∃-cong λ _ → ∃-cong λ f → Erased-cong (
Σ-cong (Eq.extensionality-isomorphism ext) λ f≡id →
∀-cong ext λ a →
≡⇒≃ (cong₂ _≡_ (trans (f≡id (f a)) (f≡id a)) (f≡id a)))) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
(f ≡ P.id ×
((a : A) → a ≡ a))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-Σ↔Σ) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased (f ≡ P.id) ×
Erased ((a : A) → a ≡ a)) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩
(A → B) ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased ((a : A) → a ≡ a) ↝⟨ (∃-cong λ _ → EEq.drop-⊤-left-Σ-≃ᴱ-Erased $
_⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ Contractibleᴱ-Erased-singleton) ⟩□
(A → B) × Erased ((a : A) → a ≡ a) □
where
B≃ᴱ⊤ : (A → B) → A → B ≃ᴱ ⊤
B≃ᴱ⊤ get a = EEq.inhabited→Is-proposition→≃ᴱ⊤ (get a) (B-prop a)
A→B→A≃ᴱA→A : (A → B) → (A → B → A) ≃ᴱ (A → A)
A→B→A≃ᴱA→A get =
(A → B → A) ↝⟨ ∀-cong ext (λ a → EEq.drop-⊤-left-Π-≃ᴱ-Erased ext $ B≃ᴱ⊤ get a) ⟩□
(A → A) □
-- If equality is very stable for A (when B is inhabited) and B is a
-- proposition (when A is inhabited), then Lens A B is equivalent to
-- (A → B) × Erased ((a : A) → a ≡ a).
Very-stable-≡→lens-to-proposition≃ :
(B → Very-stable-≡ A) →
(A → Is-proposition B) →
Lens A B ≃ ((A → B) × Erased ((a : A) → a ≡ a))
Very-stable-≡→lens-to-proposition≃ {B = B} {A = A} A-s B-prop =
Stable-≡→≃ᴱ→≃ stable₁ stable₂ (lens-to-proposition≃ᴱ B-prop)
where
stable₁ : Stable-≡ (Lens A B)
stable₁ =
Very-stable→Stable 1 $
Very-stable-Lensⁿ 1
(λ _ → A-s)
(H-level→Very-stable 1 ⊚ B-prop)
stable₂ : Stable-≡ ((A → B) × Erased ((a : A) → a ≡ a))
stable₂ =
Very-stable→Stable 1 $
Very-stable-×ⁿ 1
(Very-stable-Πⁿ ext 1 λ a →
H-level→Very-stable 1 (B-prop a))
(Very-stable→Very-stable-≡ 0
Very-stable-Erased)
-- Lens A ⊤ is equivalent (with erased proofs) to
-- Erased ((a : A) → a ≡ a).
lens-to-⊤≃ᴱ : Lens A ⊤ ≃ᴱ Erased ((a : A) → a ≡ a)
lens-to-⊤≃ᴱ {A = A} =
Lens A ⊤ ↝⟨ lens-to-proposition≃ᴱ (λ _ → mono₁ 0 ⊤-contractible) ⟩
(A → ⊤) × Erased ((a : A) → a ≡ a) ↔⟨ drop-⊤-left-× (λ _ → →-right-zero) ⟩□
Erased ((a : A) → a ≡ a) □
-- Lens A ⊥ is equivalent to ¬ A.
lens-to-⊥≃ : Lens A (⊥ {ℓ = b}) ≃ (¬ A)
lens-to-⊥≃ {A = A} =
Lens A ⊥ ↝⟨ Very-stable-≡→lens-to-proposition≃ (λ ()) (λ _ → ⊥-propositional) ⟩
(A → ⊥) × Erased ((a : A) → a ≡ a) ↔⟨ (×-cong₁ λ _ → →-cong ext F.id (Bij.⊥↔uninhabited ⊥-elim)) ⟩
¬ A × Erased ((a : A) → a ≡ a) ↔⟨ (drop-⊤-right λ ¬a →
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(H-level-Erased 1 (
Π-closure ext 1 λ a →
⊥-elim (¬a a)))
[ refl ]) ⟩□
¬ A □
-- See also lens-from-⊥≃⊤ and lens-from-⊤≃codomain-contractible below.
------------------------------------------------------------------------
-- Some lens results related to h-levels
-- If the domain of a lens is inhabited and has h-level n, then the
-- codomain also has h-level n (in erased contexts).
@0 h-level-respects-lens-from-inhabited :
∀ n → Lens A B → A → H-level n A → H-level n B
h-level-respects-lens-from-inhabited n l =
T.h-level-respects-lens-from-inhabited n (trad l)
-- Lenses with contractible domains have contractible codomains (in
-- erased contexts).
@0 contractible-to-contractible :
Lens A B → Contractible A → Contractible B
contractible-to-contractible l =
T.contractible-to-contractible (trad l)
-- A variant for Contractibleᴱ.
Contractibleᴱ→Contractibleᴱ :
Lens A B → Contractibleᴱ A → Contractibleᴱ B
Contractibleᴱ→Contractibleᴱ l c@(a , _) =
ECP.Contractibleᴱ-respects-surjection
(Lens.get l)
(λ b → Lens.set l a b
, (Lens.get l (Lens.set l a b) ≡⟨ Lens.get-set l _ _ ⟩∎
b ∎))
c
-- If A and B have h-level n given the assumption that A is inhabited,
-- then Lens A B also has h-level n.
lens-preserves-h-level :
∀ n → (A → H-level n A) → (A → H-level n B) →
H-level n (Lens A B)
lens-preserves-h-level n hA hB =
H-level.respects-surjection (_↔_.surjection (inverse Lens-as-Σ)) n $
Σ-closure n (Π-closure ext n λ a →
hB a) λ _ →
Σ-closure n (Π-closure ext n λ a →
Π-closure ext n λ _ →
hA a) λ _ →
H-level-Erased n
(×-closure n (Π-closure ext n λ a →
Π-closure ext n λ _ →
+⇒≡ $ mono₁ n (hB a)) $
×-closure n (Π-closure ext n λ a →
+⇒≡ $ mono₁ n (hA a))
(Π-closure ext n λ a →
Π-closure ext n λ _ →
Π-closure ext n λ _ →
+⇒≡ $ mono₁ n (hA a)))
-- If A has positive h-level n, then Lens A B also has h-level n (in
-- erased contexts).
@0 lens-preserves-h-level-of-domain :
∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B)
lens-preserves-h-level-of-domain {A = A} {B = B} n =
H-level (1 + n) A ↝⟨ T.lens-preserves-h-level-of-domain n ⟩
H-level (1 + n) (T.Lens A B) ↝⟨ H-level-cong _ (1 + n) (inverse Lens≃Traditional-lens) ⟩□
H-level (1 + n) (Lens A B) □
-- Lens 𝕊¹ᴱ ⊤ is not propositional (assuming univalence).
¬-lens-to-⊤-propositional :
@0 Univalence (# 0) →
¬ Is-proposition (Lens 𝕊¹ᴱ ⊤)
¬-lens-to-⊤-propositional univ =
Stable-¬
[ Is-proposition (Lens 𝕊¹ᴱ ⊤) ↝⟨ H-level-cong _ 1 (Lens-cong (inverse CE.𝕊¹≃𝕊¹ᴱ) Eq.id) ⟩
Is-proposition (Lens 𝕊¹ ⊤) ↝⟨ H-level-cong _ 1 Lens≃Traditional-lens ⟩
Is-proposition (T.Lens 𝕊¹ ⊤) ↝⟨ T.¬-lens-to-⊤-propositional univ ⟩□
⊥₀ □
]
------------------------------------------------------------------------
-- Some equality characterisation lemmas
abstract
-- An equality characterisation lemma.
equality-characterisation₁ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))
equality-characterisation₁ {l₁ = l₁} {l₂ = l₂} =
let l₁′ = _↔_.to Lens-as-Σ l₁
l₂′ = _↔_.to Lens-as-Σ l₂
in
l₁ ≡ l₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Lens-as-Σ)) ⟩
l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Σ-assoc)) ⟩
((get l₁ , set l₁) , proj₂ (proj₂ l₁′))
≡
((get l₂ , set l₂) , proj₂ (proj₂ l₂′)) ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩
(∃ λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
gs (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ Σ-cong (inverse ≡×≡↔≡) (λ gs → ≡⇒↝ _ $
cong (λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
gs (proj₂ (proj₂ l₁′))
≡
proj₂ (proj₂ l₂′))
(sym $ _↔_.right-inverse-of ≡×≡↔≡ gs)) ⟩
(∃ λ (gs : get l₁ ≡ get l₂ × set l₁ ≡ set l₂) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
(_↔_.to ≡×≡↔≡ gs) (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ inverse Σ-assoc ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
(_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ≡⇒↝ _ $ cong (_≡ proj₂ (proj₂ l₂′))
push-subst-[]) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
[ subst (λ (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))
(_↔_.to ≡×≡↔≡ (g , s)) (erased (proj₂ (proj₂ l₁′))) ] ≡
[ erased (proj₂ (proj₂ l₂′)) ]) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Erased-≡↔[]≡[]) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))
(_↔_.to ≡×≡↔≡ (g , s)) (erased (proj₂ (proj₂ l₁′))) ≡
erased (proj₂ (proj₂ l₂′)))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (≡⇒↝ _ $
cong (λ x → x ≡ erased (proj₂ (proj₂ l₂′)))
(push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(( subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁)
, subst (λ { (get , set) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s))
(proj₂ (erased (proj₂ (proj₂ l₁′))))
) ≡
erased (proj₂ (proj₂ l₂′)))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (inverse ≡×≡↔≡)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
subst (λ { (get , set) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s))
(proj₂ (erased (proj₂ (proj₂ l₁′)))) ≡
proj₂ (erased (proj₂ (proj₂ l₂′))))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ≡⇒↝ _ $
cong (λ x → x ≡ proj₂ (erased (proj₂ (proj₂ l₂′))))
(push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
( subst (λ { (get , set) → ∀ a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁)
, subst (λ { (get , set) →
∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁)
) ≡
proj₂ (erased (proj₂ (proj₂ l₂′))))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (∃-cong λ _ → inverse ≡×≡↔≡)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
subst (λ { (get , set) → ∀ a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) ≡
set-get l₂
×
subst (λ { (get , set) →
∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ≡
set-set l₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
lemma₁ (λ { (get , set) a → ∀ b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s))
×-cong
lemma₁ (λ { (get , set) a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s))
×-cong
lemma₁ (λ { (get , set) a → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a → subst (λ { (get , set) → ∀ b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a) ≡
get-set l₂ a)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a → subst (λ { (get , set) →
∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a) ≡
set-set l₂ a))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ a →
lemma₁ (λ { (get , set) b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)))
×-cong
F.id
×-cong
(∀-cong ext λ a →
lemma₁ (λ { (get , set) b₁ → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s))))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ { (get , set) → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡
get-set l₂ a b)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a b₁ → subst (λ { (get , set) →
∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁) ≡
set-set l₂ a b₁))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ →
lemma₁ (λ { (get , set) b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ { (get , set) → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡
get-set l₂ a b)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ { (get , set) →
set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ a → ∀-cong ext λ b →
lemma₂ (λ { (get , set) → get (set a b) ≡ b }) g s)
×-cong
(∀-cong ext λ a →
lemma₂ (λ { (get , set) → set a (get a) ≡ a }) g s)
×-cong
(∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
lemma₂ (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) g s))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ →
subst (λ get → set l₂ (set l₂ a b₁) b₂ ≡ set l₂ a b₂) g
(subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂)) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → x ≡ _) $ subst-const g)) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) □
where
open Lens
abstract
lemma₁ :
∀ (C : A → B → Type c) (eq : u ≡ v) {f g} →
(subst (λ x → ∀ y → C x y) eq f ≡ g)
↔
(∀ y → subst (λ x → C x y) eq (f y) ≡ g y)
lemma₁ C eq {f} {g} =
subst (λ x → ∀ y → C x y) eq f ≡ g ↔⟨ inverse $ Eq.extensionality-isomorphism ext ⟩
(∀ y → subst (λ x → ∀ y → C x y) eq f y ≡ g y) ↝⟨ (∀-cong ext λ y → ≡⇒↝ _ $
cong (λ x → x ≡ _) (sym $ push-subst-application eq _)) ⟩□
(∀ y → subst (λ x → C x y) eq (f y) ≡ g y) □
lemma₂ :
(P : A × B → Type p) (x₁≡x₂ : x₁ ≡ x₂) (y₁≡y₂ : y₁ ≡ y₂) →
∀ {p p′} →
(subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ p′)
↔
(subst (λ x → P (x , y₂)) x₁≡x₂ (subst (λ y → P (x₁ , y)) y₁≡y₂ p)
≡
p′)
lemma₂ P x₁≡x₂ y₁≡y₂ {p = p} = ≡⇒↝ _ $ cong (_≡ _) $ elim¹
(λ y₁≡y₂ →
subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡
subst (λ x → P (x , _)) x₁≡x₂
(subst (λ y → P (_ , y)) y₁≡y₂ p))
(subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , refl _)) p ≡⟨⟩
subst P (cong₂ _,_ x₁≡x₂ (refl _)) p ≡⟨⟩
subst P (trans (cong (_, _) x₁≡x₂) (cong (_ ,_) (refl _))) p ≡⟨ cong (λ eq → subst P (trans (cong (_, _) x₁≡x₂) eq) p) $ cong-refl _ ⟩
subst P (trans (cong (_, _) x₁≡x₂) (refl _)) p ≡⟨ cong (λ eq → subst P eq p) $ trans-reflʳ _ ⟩
subst P (cong (_, _) x₁≡x₂) p ≡⟨ sym $ subst-∘ _ _ _ ⟩
subst (λ x → P (x , _)) x₁≡x₂ p ≡⟨ cong (subst (λ x → P (x , _)) x₁≡x₂) $ sym $ subst-refl _ _ ⟩∎
subst (λ x → P (x , _)) x₁≡x₂
(subst (λ y → P (_ , y)) (refl _) p) ∎)
_
-- Another equality characterisation lemma.
equality-characterisation₂ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b →
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))
equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (_≡ _) $
lemma₁ g s a b)
×-cong
(∀-cong ext λ a → ≡⇒↝ _ $ cong (_≡ _) $
lemma₂ g s a)
×-cong
F.id)) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) □
where
open Lens
@0 lemma₁ :
(g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) →
∀ a b →
subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b)
lemma₁ g s a b =
subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g eq) $
subst-in-terms-of-trans-and-cong
{f = λ set → get l₁ (set a b)} {g = λ _ → b}
{x≡y = s} {fx≡gx = (get-set l₁ a b)} ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans (get-set l₁ a b) (cong (const b) s))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans _ eq))) $
cong-const s ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans (get-set l₁ a b) (refl _))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s)) eq)) $
trans-reflʳ _ ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g}
{fx≡gx = trans _ (get-set l₁ a b)} ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
(cong (const b) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
eq)) $
cong-const g ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
(refl _)) ≡⟨ cong (trans _) $
trans-reflʳ _ ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b)) ≡⟨ sym $ trans-assoc _ _ (get-set l₁ a b) ⟩
trans (trans (sym (cong (λ get → get (set l₂ a b)) g))
(sym (cong (λ set → get l₁ (set a b)) s)))
(get-set l₁ a b) ≡⟨ cong (λ eq → trans eq (get-set l₁ a b)) $ sym $
sym-trans _ (cong (λ get → get (set l₂ a b)) g) ⟩
trans (sym (trans (cong (λ set → get l₁ (set a b)) s)
(cong (λ get → get (set l₂ a b)) g)))
(get-set l₁ a b) ≡⟨⟩
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ∎
@0 lemma₂ :
(g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) →
∀ a →
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a)
lemma₂ g s a =
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡⟨⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡⟨ cong (subst (λ get → set l₂ a (get a) ≡ a) g) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-get l₁ a} ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans (set-get l₁ a) (cong (const a) s))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans _ eq))) $
cong-const s ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans (set-get l₁ a) (refl _))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s)) eq)) $
trans-reflʳ _ ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g}
{fx≡gx = trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)} ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
(cong (const a) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
eq)) $
cong-const g ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
(refl _)) ≡⟨ cong (trans _) $
trans-reflʳ _ ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a)) ≡⟨ sym $ trans-assoc _ _ (set-get l₁ a) ⟩
trans (trans (sym (cong (λ get → set l₂ a (get a)) g))
(sym (cong (λ set → set a (get l₁ a)) s)))
(set-get l₁ a) ≡⟨ cong (λ eq → trans eq (set-get l₁ a)) $ sym $
sym-trans _ (cong (λ get → set l₂ a (get a)) g) ⟩
trans (sym (trans (cong (λ set → set a (get l₁ a)) s)
(cong (λ get → set l₂ a (get a)) g)))
(set-get l₁ a) ≡⟨⟩
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ∎
-- And another one.
equality-characterisation₃ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b →
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂)))
equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $
lemma g s a b₁ b₂)) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂)))) □
where
open Lens
@0 lemma :
(g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) →
∀ a b₁ b₂ →
(subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂) ≡
(trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂))
lemma g s a b₁ b₂ =
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂ ≡⟨ cong (_≡ _) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-set l₁ a b₁ b₂} ⟩
trans (sym (cong (λ set → set (set a b₁) b₂) s))
(trans (set-set l₁ a b₁ b₂)
(cong (λ set → set a b₂) s)) ≡
set-set l₂ a b₁ b₂ ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (sym (sym (cong (λ set → set (set a b₁) b₂) s)))
(set-set l₂ a b₁ b₂) ≡⟨ cong (λ eq → trans _ (cong (λ set → set a b₂) s) ≡
trans eq (set-set l₂ a b₁ b₂)) $
sym-sym (cong (λ set → set (set a b₁) b₂) s) ⟩
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂) ∎
-- And yet another one.
equality-characterisation₄ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) →
Erased
((∀ a b →
trans (sym (trans (cong (get l₁) (s a b))
(g (set l₂ a b))))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (trans (s a (get l₁ a))
(cong (set l₂ a) (g a))))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))
(set-set l₂ a b₁ b₂)))
equality-characterisation₄ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₃ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂)))) ↝⟨ (Σ-cong (inverse $ Eq.extensionality-isomorphism ext) λ g →
Σ-cong (inverse $
Eq.extensionality-isomorphism ext F.∘
∀-cong ext λ _ → Eq.extensionality-isomorphism ext) λ s →
Erased-cong (
(∀-cong ext λ a → ∀-cong ext λ b →
≡⇒↝ _ $ cong (λ eq → trans (sym eq) (get-set l₁ a b) ≡ _) (
cong₂ (λ set get → get (set a b)) s g ≡⟨⟩
trans (cong (λ set → get l₁ (set a b)) s)
(cong (λ get → get (set l₂ a b)) g) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $
cong-∘ _ _ s ⟩
trans (cong (get l₁ ⊚ (_$ b)) (ext⁻¹ s a))
(ext⁻¹ g (set l₂ a b)) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $
cong-∘ _ _ (ext⁻¹ s a) ⟩∎
trans (cong (get l₁) (ext⁻¹ (ext⁻¹ s a) b))
(ext⁻¹ g (set l₂ a b)) ∎))
×-cong
(∀-cong ext λ a →
≡⇒↝ _ $ cong (λ eq → trans (sym eq) (set-get l₁ a) ≡ _) (
cong₂ (λ set get → set a (get a)) s g ≡⟨⟩
trans (cong (λ set → set a (get l₁ a)) s)
(cong (λ get → set l₂ a (get a)) g) ≡⟨ sym $ cong₂ trans (cong-∘ _ _ s) (cong-∘ _ _ g) ⟩
trans (ext⁻¹ (ext⁻¹ s a) (get l₁ a))
(cong (set l₂ a) (ext⁻¹ g a)) ∎))
×-cong
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
≡⇒↝ _ $
cong₂ (λ p q → trans _ p ≡
trans (cong (λ set → set (set a b₁) b₂) q)
(set-set l₂ a b₁ b₂)) (
cong (λ set → set a b₂) s ≡⟨ sym $ cong-∘ _ _ s ⟩∎
ext⁻¹ (ext⁻¹ s a) b₂ ∎)
(
s ≡⟨ sym $ _≃_.right-inverse-of
(Eq.extensionality-isomorphism bad-ext) _ ⟩
⟨ext⟩ (ext⁻¹ s) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → sym $
_≃_.right-inverse-of
(Eq.extensionality-isomorphism bad-ext) _) ⟩∎
⟨ext⟩ (⟨ext⟩ ⊚ ext⁻¹ ⊚ ext⁻¹ s) ∎))) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) →
Erased
((∀ a b →
trans (sym (trans (cong (get l₁) (s a b))
(g (set l₂ a b))))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (trans (s a (get l₁ a))
(cong (set l₂ a) (g a))))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))
(set-set l₂ a b₁ b₂)))) □
where
open Lens
-- A lemma that can be used to prove that two lenses with
-- definitionally equal getters and setters are equal.
equal-laws→≡ :
{get : A → B} {set : A → B → A}
{l₁′ l₂′ : Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))} →
let l₁ = _↔_.from Lens-as-Σ (get , set , l₁′)
l₂ = _↔_.from Lens-as-Σ (get , set , l₂′)
open Lens
in
@0 (∀ a b → get-set l₁ a b ≡ get-set l₂ a b) →
@0 (∀ a → set-get l₁ a ≡ set-get l₂ a) →
@0 (∀ a b₁ b₂ → set-set l₁ a b₁ b₂ ≡ set-set l₂ a b₁ b₂) →
l₁ ≡ l₂
equal-laws→≡ {l₁′ = l₁′} {l₂′ = l₂′} hyp₁ hyp₂ hyp₃ =
let l₁″ = _↔_.from Lens-as-Σ (_ , _ , l₁′)
l₂″ = _↔_.from Lens-as-Σ (_ , _ , l₂′)
in
_↔_.from equality-characterisation₂
( refl _
, refl _
, [ (λ a b →
trans (sym (cong₂ (λ set get → get (set a b))
(refl _) (refl _)))
(get-set l₁″ a b) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩
trans (sym (refl _)) (get-set l₁″ a b) ≡⟨ cong (flip trans _) sym-refl ⟩
trans (refl _) (get-set l₁″ a b) ≡⟨ trans-reflˡ _ ⟩
get-set l₁″ a b ≡⟨ hyp₁ _ _ ⟩∎
get-set l₂″ a b ∎)
, (λ a →
trans (sym (cong₂ (λ set get → set a (get a))
(refl _) (refl _)))
(set-get l₁″ a) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩
trans (sym (refl _)) (set-get l₁″ a) ≡⟨ cong (flip trans _) sym-refl ⟩
trans (refl _) (set-get l₁″ a) ≡⟨ trans-reflˡ _ ⟩
set-get l₁″ a ≡⟨ hyp₂ _ ⟩∎
set-get l₂″ a ∎)
, (λ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) (refl _)
(set-set l₁″ a b₁ b₂) ≡⟨ subst-refl _ _ ⟩
set-set l₁″ a b₁ b₂ ≡⟨ hyp₃ _ _ _ ⟩∎
set-set l₂″ a b₁ b₂ ∎)
]
)
where
open Lens
-- An equality characterisation lemma for lenses from sets.
@0 equality-characterisation-for-sets :
let open Lens in
{l₁ l₂ : Lens A B} →
Is-set A →
l₁ ≡ l₂
↔
set l₁ ≡ set l₂
equality-characterisation-for-sets
{A = A} {B = B} {l₁ = l₁} {l₂ = l₂} A-set =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Traditional-lens ⟩
trad l₁ ≡ trad l₂ ↝⟨ T.equality-characterisation-for-sets A-set ⟩□
set l₁ ≡ set l₂ □
where
open Lens
------------------------------------------------------------------------
-- More isomorphisms/equivalences related to lenses
-- Lens ⊤ B is equivalent (with erased proofs) to Contractibleᴱ B.
lens-from-⊤≃codomain-contractible :
Lens ⊤ B ≃ᴱ Contractibleᴱ B
lens-from-⊤≃codomain-contractible = EEq.⇔→≃ᴱ
(lens-preserves-h-level-of-domain 0 (mono₁ 0 ⊤-contractible))
(ECP.Contractibleᴱ-propositional ext)
(λ l → Contractibleᴱ→Contractibleᴱ l
(ECP.Contractible→Contractibleᴱ ⊤-contractible))
(λ (b , irrB) → record
{ get = λ _ → b
; get-set = λ _ → erased irrB
; set-get = refl
; set-set = λ _ _ _ → refl _
})
-- Lens ⊥ B is equivalent to the unit type.
lens-from-⊥≃⊤ : Lens (⊥ {ℓ = a}) B ≃ ⊤
lens-from-⊥≃⊤ =
Eq.↔⇒≃ $ _⇔_.to contractible⇔↔⊤ $
record
{ get = ⊥-elim
; set = ⊥-elim
; get-set = λ a → ⊥-elim a
; set-get = λ a → ⊥-elim a
; set-set = λ a → ⊥-elim a
} ,
λ l → _↔_.from equality-characterisation₁
( ⟨ext⟩ (λ a → ⊥-elim a)
, ⟨ext⟩ (λ a → ⊥-elim a)
, [ (λ a → ⊥-elim a)
, (λ a → ⊥-elim a)
, (λ a → ⊥-elim a)
]
)
-- If A is a set and there is a lens from A to B, then A is equivalent
-- (with erased proofs) to the cartesian product of some type (that
-- can be expressed using the setter of l) and B.
--
-- This result is based on Theorem 2.3.9 from "Lenses and View Update
-- Translation" by Pierce and Schmitt.
≃ᴱΣ∥set⁻¹ᴱ∥ᴱ× :
@0 Is-set A →
(l : Lens A B) →
A ≃ᴱ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B)
≃ᴱΣ∥set⁻¹ᴱ∥ᴱ× {A = A} {B = B} A-set l = EEq.↔→≃ᴱ
(λ a → (set a , ∣ a , [ refl _ ] ∣) , get a)
(λ ((f , _) , b) → f b)
to-from
(λ a →
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
where
open Lens l
@0 B-set : A → Is-set B
B-set a =
h-level-respects-lens-from-inhabited 2 l a A-set
@0 to-from : ∀ _ → _
to-from ((f , p) , b) = flip TE.rec p λ @0 where
.TE.truncation-is-propositionʳ →
×-closure 2
(Σ-closure 2
(Π-closure ext 2 λ _ → A-set) λ _ →
mono₁ 1 TE.truncation-is-proposition)
(B-set (f b))
.TE.∣∣ʳ (a , [ q ]) →
let
lemma₁ =
set (f b) ≡⟨ cong (λ f → set (f b)) $ sym q ⟩
set (set a b) ≡⟨ ⟨ext⟩ $ set-set a b ⟩
set a ≡⟨ q ⟩∎
f ∎
lemma₂ =
get (f b) ≡⟨ cong (λ f → get (f b)) $ sym q ⟩
get (set a b) ≡⟨ get-set _ _ ⟩∎
b ∎
in
(set (f b) , ∣ f b , [ refl _ ] ∣) , get (f b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ (TE.truncation-is-proposition _ _)) lemma₂ ⟩∎
(f , p) , b ∎
-- If B is an inhabited set and there is a lens from A to B, then A is
-- equivalent (with erased proofs) to the cartesian product of some
-- type (that can be expressed using the getter of l) and B.
--
-- This result is based on Corollary 13 from "Algebras and Update
-- Strategies" by Johnson, Rosebrugh and Wood.
≃ᴱget⁻¹ᴱ× :
@0 Is-set B →
(b : B)
(l : Lens A B) →
A ≃ᴱ (Lens.get l ⁻¹ᴱ b × B)
≃ᴱget⁻¹ᴱ× {B = B} {A = A} B-set b₀ l = EEq.↔→≃ᴱ
(λ a → (set a b₀ , [ get-set a b₀ ]) , get a)
(λ ((a , _) , b) → set a b)
(λ ((a , [ h ]) , b) →
let
lemma =
set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩
set a b₀ ≡⟨ cong (set a) (sym h) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
in
(set (set a b) b₀ , [ get-set (set a b) b₀ ]) , get (set a b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma ([]-cong [ B-set _ _ ])) (get-set a b) ⟩∎
(a , [ h ]) , b ∎)
(λ a →
set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
where
open Lens l
-- For somewhat coherent lenses the previous result can be proved
-- without the assumption that the codomain is a set.
≃ᴱget⁻¹ᴱ×-coherent :
(b : B)
(l : Coherent-lens A B) →
A ≃ᴱ (Coherent-lens.get l ⁻¹ᴱ b × B)
≃ᴱget⁻¹ᴱ×-coherent {B = B} {A = A} b₀ l = EEq.↔→≃ᴱ
(λ a → (set a b₀ , [ get-set a b₀ ]) , get a)
(λ ((a , _) , b) → set a b)
(λ ((a , [ h ]) , b) →
let
lemma₁ =
set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩
set a b₀ ≡⟨ cong (set a) (sym h) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
lemma₂₁ =
cong get (trans (set-set a b b₀)
(trans (cong (set a) (sym h))
(set-get a))) ≡⟨ trans (cong-trans _ _ _) $
cong (trans _) $
trans (cong-trans _ _ _) $
cong (flip trans _) $
cong-∘ _ _ _ ⟩
trans (cong get (set-set a b b₀))
(trans (cong (get ⊚ set a) (sym h))
(cong get (set-get a))) ≡⟨ cong₂ (λ p q → trans p (trans (cong (get ⊚ set a) (sym h)) q))
(get-set-set _ _ _)
(get-set-get _) ⟩∎
trans (trans (get-set (set a b) b₀)
(sym (get-set a b₀)))
(trans (cong (get ⊚ set a) (sym h))
(get-set a (get a))) ∎
lemma₂₂ =
sym (trans (trans (get-set (set a b) b₀)
(sym (get-set a b₀)))
(trans (cong (get ⊚ set a) (sym h))
(get-set a (get a)))) ≡⟨ trans (sym-trans _ _) $
cong₂ trans
(sym-trans _ _)
(sym-trans _ _) ⟩
trans (trans (sym (get-set a (get a)))
(sym (cong (get ⊚ set a) (sym h))))
(trans (sym (sym (get-set a b₀)))
(sym (get-set (set a b) b₀))) ≡⟨ cong₂ (λ p q → trans (trans (sym (get-set a (get a))) p)
(trans q (sym (get-set (set a b) b₀))))
(trans (cong sym $ cong-sym _ _) $
sym-sym _)
(sym-sym _) ⟩
trans (trans (sym (get-set a (get a)))
(cong (get ⊚ set a) h))
(trans (get-set a b₀)
(sym (get-set (set a b) b₀))) ≡⟨ trans (sym $ trans-assoc _ _ _) $
cong (flip trans _) $ trans-assoc _ _ _ ⟩∎
trans (trans (sym (get-set a (get a)))
(trans (cong (get ⊚ set a) h)
(get-set a b₀)))
(sym (get-set (set a b) b₀)) ∎
lemma₂′ =
subst (λ a → get a ≡ b₀)
(trans (set-set a b b₀)
(trans (cong (set a) (sym h)) (set-get a)))
(get-set (set a b) b₀) ≡⟨ subst-∘ _ _ _ ⟩
subst (_≡ b₀)
(cong get (trans (set-set a b b₀)
(trans (cong (set a) (sym h))
(set-get a))))
(get-set (set a b) b₀) ≡⟨ subst-trans-sym ⟩
trans
(sym (cong get (trans (set-set a b b₀)
(trans (cong (set a) (sym h))
(set-get a)))))
(get-set (set a b) b₀) ≡⟨ cong (flip (trans ⊚ sym) _) lemma₂₁ ⟩
trans
(sym (trans (trans (get-set (set a b) b₀)
(sym (get-set a b₀)))
(trans (cong (get ⊚ set a) (sym h))
(get-set a (get a)))))
(get-set (set a b) b₀) ≡⟨ cong (flip trans _) lemma₂₂ ⟩
trans
(trans (trans (sym (get-set a (get a)))
(trans (cong (get ⊚ set a) h)
(get-set a b₀)))
(sym (get-set (set a b) b₀)))
(get-set (set a b) b₀) ≡⟨ trans-[trans-sym]- _ _ ⟩
trans (sym (get-set a (get a)))
(trans (cong (get ⊚ set a) h)
(get-set a b₀)) ≡⟨ cong (λ f → trans (sym (f (get a))) (trans (cong (get ⊚ set a) h) (f b₀))) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) (get-set a) ⟩
trans (sym (ext⁻¹ (⟨ext⟩ (get-set a)) (get a)))
(trans (cong (get ⊚ set a) h)
(ext⁻¹ (⟨ext⟩ (get-set a)) b₀)) ≡⟨ elim₁
(λ {f} eq →
trans (sym (ext⁻¹ eq (get a)))
(trans (cong f h) (ext⁻¹ eq b₀)) ≡
h)
(
trans (sym (ext⁻¹ (refl P.id) (get a)))
(trans (cong P.id h) (ext⁻¹ (refl P.id) b₀)) ≡⟨ cong₂ (λ p q → trans p (trans (cong P.id h) q))
(trans (cong sym (ext⁻¹-refl _)) sym-refl)
(ext⁻¹-refl _) ⟩
trans (refl _) (trans (cong P.id h) (refl _)) ≡⟨ trans-reflˡ _ ⟩
trans (cong P.id h) (refl _) ≡⟨ trans-reflʳ _ ⟩
cong P.id h ≡⟨ sym $ cong-id _ ⟩∎
h ∎)
_ ⟩∎
h ∎
lemma₂ =
subst (λ a → Erased (get a ≡ b₀))
(trans (set-set a b b₀)
(trans (cong (set a) (sym h)) (set-get a)))
[ get-set (set a b) b₀ ] ≡⟨ push-subst-[] ⟩
[ subst (λ a → get a ≡ b₀)
(trans (set-set a b b₀)
(trans (cong (set a) (sym h)) (set-get a)))
(get-set (set a b) b₀)
] ≡⟨ []-cong [ lemma₂′ ] ⟩∎
[ h ] ∎
in
((set (set a b) b₀ , [ get-set (set a b) b₀ ]) , get (set a b)) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ lemma₂) (get-set a b) ⟩∎
((a , [ h ]) , b ) ∎)
(λ a →
set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
where
open Coherent-lens l
------------------------------------------------------------------------
-- A conversion function
-- If A is a set, then Lens A B is equivalent to Coherent-lens A B.
≃coherent : @0 Is-set A → Lens A B ≃ Coherent-lens A B
≃coherent {A = A} {B = B} A-set = Eq.↔→≃
to
Coherent-lens.lens
(λ l → let l′ = Coherent-lens.lens l in
$⟨ H-level-Erased 1
(×-closure 1
(Π-closure ext 1 λ a →
mono₁ 2 (B-set l′ a))
(Π-closure ext 1 λ a →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
mono₁ 2 (B-set l′ a))) ⟩
Is-proposition _ ↝⟨ (λ p → cong (l′ ,_) (p _ _)) ⦂ (_ → _) ⟩
(l′ , _) ≡ (l′ , _) ↔⟨ Eq.≃-≡ Coherent-lens-as-Σ ⟩□
to l′ ≡ l □)
refl
where
@0 B-set : Lens A B → A → Is-set B
B-set l a =
h-level-respects-lens-from-inhabited 2 l a A-set
to : Lens A B → Coherent-lens A B
to l = record
{ lens = l
; get-set-get = λ a → B-set l a _ _
; get-set-set = λ a _ _ → B-set l a _ _
}
-- The conversion preserves getters and setters.
≃coherent-preserves-getters-and-setters :
{A : Type a}
(@0 s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_≃_.logical-equivalence (≃coherent s))
≃coherent-preserves-getters-and-setters _ =
(λ _ → refl _ , refl _)
, (λ _ → refl _ , refl _)
------------------------------------------------------------------------
-- Lens combinators
module Lens-combinators where
-- If two types are isomorphic, then there is a lens between them.
↔→lens : A ↔ B → Lens A B
↔→lens A↔B = record
{ get = to
; set = const from
; get-set = const right-inverse-of
; set-get = left-inverse-of
; set-set = λ _ _ _ → refl _
}
where
open _↔_ A↔B
-- If there is an equivalence with erased proofs between two types,
-- then there is a lens between them.
≃ᴱ→lens : A ≃ᴱ B → Lens A B
≃ᴱ→lens A≃B = record
{ get = to
; set = const from
; get-set = const right-inverse-of
; set-get = left-inverse-of
; set-set = λ _ _ _ → refl _
}
where
open _≃ᴱ_ A≃B
-- Identity lens.
id : Lens A A
id = ≃ᴱ→lens F.id
-- The identity lens is equal to the one obtained from the
-- traditional identity lens without erased proofs.
Traditional-lens-id≡id :
Traditional-lens→Lens TC.id ≡ id {A = A}
Traditional-lens-id≡id = refl _
-- Composition of lenses.
infixr 9 _∘_
_∘_ : Lens B C → Lens A B → Lens A C
l₁ ∘ l₂ = record
{ get = λ a → get l₁ (get l₂ a)
; set = λ a c →
let b = set l₁ (get l₂ a) c in
set l₂ a b
; get-set = T.Lens.get-set l₁∘l₂
; set-get = T.Lens.set-get l₁∘l₂
; set-set = T.Lens.set-set l₁∘l₂
}
where
open Lens
@0 l₁∘l₂ : _
l₁∘l₂ = trad l₁ TC.∘ trad l₂
-- Traditional-lens→Lens commutes with composition.
@0 Traditional-lens-∘≡∘ :
{l₁ : T.Lens B C} {l₂ : T.Lens A B} →
Traditional-lens→Lens (l₁ TC.∘ l₂) ≡
Traditional-lens→Lens l₁ ∘ Traditional-lens→Lens l₂
Traditional-lens-∘≡∘ = refl _
-- Note that composition can be defined in several different ways.
-- Here are two alternative implementations.
infixr 9 _∘′_ _∘″_
_∘′_ : Lens B C → Lens A B → Lens A C
l₁ ∘′ l₂ = record (l₁ ∘ l₂)
{ set-set = T.Lens.set-set l₁∘′l₂
}
where
@0 l₁∘′l₂ : _
l₁∘′l₂ = trad l₁ TC.∘′ trad l₂
_∘″_ : Lens B C → Lens A B → Lens A C
l₁ ∘″ l₂ = record (l₁ ∘ l₂)
{ set-set = T.Lens.set-set l₁∘″l₂
}
where
@0 l₁∘″l₂ : _
l₁∘″l₂ = trad l₁ TC.∘″ trad l₂
-- These two implementations are pointwise equal to the other one.
-- However, I don't know if there is some other definition that is
-- distinct from these two (if we require that the definitions are
-- polymorphic, that get and set are implemented in the same way as
-- for _∘_, and that the three composition laws below hold).
∘≡∘′ : l₁ ∘ l₂ ≡ l₁ ∘′ l₂
∘≡∘′ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡
(λ _ _ → refl _)
(λ _ → refl _)
(λ a c₁ c₂ →
let b₁ = set l₁ (get l₂ a) c₁
b₂ = set l₁ b₁ c₂
a′ = set l₂ a b₁
b′ = set l₁ (get l₂ a′) c₂
in
set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩
trans (set-set l₂ a b₁ b′)
(trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁))
(cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ sym $ trans-assoc _ _ _ ⟩
trans (trans (set-set l₂ a b₁ b′)
(cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)))
(cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ cong (flip trans _) $
elim₁
(λ eq →
trans (set-set l₂ _ b₁ _)
(cong (λ b → set l₂ a (set l₁ b c₂)) eq) ≡
trans (cong (λ b → set l₂ _ (set l₁ b _)) eq)
(set-set l₂ _ _ _))
(
trans (set-set l₂ a b₁ b₂)
(cong (λ b → set l₂ a (set l₁ b c₂)) (refl _)) ≡⟨ trans (cong (trans _) $ cong-refl _) $
trans-reflʳ _ ⟩
set-set l₂ a b₁ b₂ ≡⟨ sym $
trans (cong (flip trans _) $ cong-refl _) $
trans-reflˡ _ ⟩∎
trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (refl _))
(set-set l₂ a b₁ b₂) ∎)
(get-set l₂ a b₁) ⟩
trans (trans (cong (λ b → set l₂ a′ (set l₁ b c₂))
(get-set l₂ a b₁))
(set-set l₂ a b₁ b₂))
(cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ trans-assoc _ _ _ ⟩
trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁))
(trans (set-set l₂ a b₁ b₂)
(cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨⟩
set-set (l₁ ∘′ l₂) a c₁ c₂ ∎)
where
open Lens
∘≡∘″ : l₁ ∘ l₂ ≡ l₁ ∘″ l₂
∘≡∘″ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡
(λ _ _ → refl _)
(λ _ → refl _)
(λ a c₁ c₂ →
let b₁ = set l₁ (get l₂ a) c₁
b₂ = set l₁ (get l₂ a) c₂
a′ = set l₂ a b₁
b′ = set l₁ (get l₂ a′) c₂
eq : b′ ≡ b₂
eq = trans (cong (λ b → set l₁ b c₂) (get-set l₂ a b₁))
(set-set l₁ (get l₂ a) c₁ c₂)
in
set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩
trans (set-set l₂ a b₁ b′)
(trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁))
(cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ cong (trans (set-set l₂ a b₁ b′)) $
trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $
sym $ cong-trans _ _ _ ⟩
trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡⟨ elim¹
(λ {b₂} eq → trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡
trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂))
(
trans (set-set l₂ a b₁ b′) (cong (set l₂ a) (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩
trans (set-set l₂ a b₁ b′) (refl _) ≡⟨ trans-reflʳ _ ⟩
set-set l₂ a b₁ b′ ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl _) (set-set l₂ a b₁ b′) ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩∎
trans (cong (set l₂ a′) (refl _)) (set-set l₂ a b₁ b′) ∎)
eq ⟩
trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂) ≡⟨ trans (cong (flip trans _) $
trans (cong-trans _ _ _) $
cong (flip trans _) $ cong-∘ _ _ _) $
trans-assoc _ _ _ ⟩
trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁))
(trans (cong (set l₂ a′) (set-set l₁ (get l₂ a) c₁ c₂))
(set-set l₂ a b₁ b₂)) ≡⟨⟩
set-set (l₁ ∘″ l₂) a c₁ c₂ ∎)
where
open Lens
-- id is a left identity of _∘_.
left-identity : (l : Lens A B) → id ∘ l ≡ l
left-identity l = equal-laws→≡
(λ a b →
trans (cong P.id (get-set a b)) (refl _) ≡⟨ trans-reflʳ _ ⟩
cong P.id (get-set a b) ≡⟨ sym $ cong-id _ ⟩∎
get-set a b ∎)
(λ a →
trans (cong (set a) (refl _)) (set-get a) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩
trans (refl _) (set-get a) ≡⟨ trans-reflˡ _ ⟩∎
set-get a ∎)
(λ a b₁ b₂ →
trans (set-set a b₁ b₂)
(trans (cong (λ _ → set a b₂) (get-set a b₁))
(cong (set a) (refl _))) ≡⟨ cong₂ (λ p q → trans _ (trans p q))
(cong-const _)
(cong-refl _) ⟩
trans (set-set a b₁ b₂) (trans (refl _) (refl _)) ≡⟨ trans (cong (trans _) trans-refl-refl) $
trans-reflʳ _ ⟩∎
set-set a b₁ b₂ ∎)
where
open Lens l
-- id is a right identity of _∘_.
right-identity : (l : Lens A B) → l ∘ id ≡ l
right-identity l = equal-laws→≡
(λ a b →
trans (cong get (refl _)) (get-set a b) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩
trans (refl _) (get-set a b) ≡⟨ trans-reflˡ _ ⟩∎
get-set a b ∎)
(λ a →
trans (cong P.id (set-get a)) (refl _) ≡⟨ trans-reflʳ _ ⟩
cong P.id (set-get a) ≡⟨ sym $ cong-id _ ⟩∎
set-get a ∎)
(λ a b₁ b₂ →
trans (refl _)
(trans (cong (λ b → set b b₂) (refl _))
(cong P.id (set-set a b₁ b₂))) ≡⟨ trans-reflˡ _ ⟩
trans (cong (λ b → set b b₂) (refl _))
(cong P.id (set-set a b₁ b₂)) ≡⟨ cong₂ trans (cong-refl _) (sym $ cong-id _) ⟩
trans (refl _) (set-set a b₁ b₂) ≡⟨ trans-reflˡ _ ⟩∎
set-set a b₁ b₂ ∎)
where
open Lens l
-- _∘_ is associative.
associativity :
(l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) →
l₁ ∘ (l₂ ∘ l₃) ≡ (l₁ ∘ l₂) ∘ l₃
associativity l₁ l₂ l₃ = equal-laws→≡ lemma₁ lemma₂ lemma₃
where
open Lens
@0 lemma₁ : _
lemma₁ = λ a d →
let
f = get l₁
g = get l₂
b = get l₃ a
c = g b
c′ = set l₁ c d
x = get-set l₃ a (set l₂ b c′)
y = get-set l₂ b c′
z = get-set l₁ c d
in
trans (cong f $ trans (cong g x) y) z ≡⟨ cong (λ x → trans x z) (cong-trans f _ y) ⟩
trans (trans (cong f $ cong g x) (cong f y)) z ≡⟨ trans-assoc _ _ z ⟩
trans (cong f $ cong g x) (trans (cong f y) z) ≡⟨ cong (λ x → trans x (trans (cong f y) z)) (cong-∘ f g x) ⟩∎
trans (cong (f ⊚ g) x) (trans (cong f y) z) ∎
@0 lemma₂ : _
lemma₂ = λ a →
let
b = get l₃ a
f = set l₃ a
g = set l₂ b
x = set-get l₁ (get l₂ b)
y = set-get l₂ b
z = set-get l₃ a
in
trans (cong (f ⊚ g) x) (trans (cong f y) z) ≡⟨ sym $ trans-assoc _ _ z ⟩
trans (trans (cong (f ⊚ g) x) (cong f y)) z ≡⟨ cong (λ x → trans (trans x (cong f y)) z) (sym $ cong-∘ f g x) ⟩
trans (trans (cong f (cong g x)) (cong f y)) z ≡⟨ cong (λ x → trans x z) (sym $ cong-trans f _ y) ⟩∎
trans (cong f $ trans (cong g x) y) z ∎
@0 lemma₃ : _
lemma₃ = λ a d₁ d₂ →
let
f = set l₃ a
g = set l₂ (get l₃ a)
h = λ x → set l₁ x d₂
i = get l₂
c₁ = set l₁ (get (l₂ ∘ l₃) a) d₁
c₂ = h (i (get l₃ a))
c₂′ = h (i (get l₃ (set (l₂ ∘ l₃) a c₁)))
c₂″ = h (i (set l₂ (get l₃ a) c₁))
b₁ = g c₁
b₁′ = get l₃ (f b₁)
x = set-set l₃ a b₁ (set l₂ b₁′ c₂′)
y = get-set l₃ a b₁
z = set-set l₂ (get l₃ a) c₁
u = get-set l₂ (get l₃ a) c₁
v = set-set l₁ (get (l₂ ∘ l₃) a) d₁ d₂
c₂′≡c₂″ =
c₂′ ≡⟨ cong (h ⊚ i) y ⟩∎
c₂″ ∎
lemma₁₀ =
trans (sym (cong (h ⊚ i) y)) (cong h (cong i y)) ≡⟨ cong (trans _) (cong-∘ h i y) ⟩
trans (sym (cong (h ⊚ i) y)) (cong (h ⊚ i) y) ≡⟨ trans-symˡ (cong (h ⊚ i) y) ⟩∎
refl _ ∎
lemma₉ =
trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″) ≡⟨ cong (trans (cong (λ x → set l₂ x c₂′) y))
(cong-∘ (set l₂ b₁) (h ⊚ i) y) ⟩
trans (cong (λ x → set l₂ x (h (i b₁′))) y)
(cong (λ x → set l₂ b₁ (h (i x ))) y) ≡⟨ trans-cong-cong (λ x y → set l₂ x (h (i y))) y ⟩∎
cong (λ x → set l₂ x (h (i x))) y ∎
lemma₈ =
sym (cong (set l₂ b₁) (sym c₂′≡c₂″)) ≡⟨ sym $ cong-sym (set l₂ b₁) (sym c₂′≡c₂″) ⟩
cong (set l₂ b₁) (sym (sym c₂′≡c₂″)) ≡⟨ cong (cong (set l₂ b₁)) (sym-sym c₂′≡c₂″) ⟩∎
cong (set l₂ b₁) c₂′≡c₂″ ∎
lemma₇ =
trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y))) ≡⟨ sym $ cong-trans g _ (cong h (cong i y)) ⟩
cong g (trans (sym c₂′≡c₂″) (cong h (cong i y))) ≡⟨ cong (cong g) lemma₁₀ ⟩
cong g (refl _) ≡⟨ cong-refl _ ⟩∎
refl _ ∎
lemma₆ =
trans (cong (λ x → set l₂ x c₂′) y)
(trans (cong (set l₂ b₁) c₂′≡c₂″)
(trans (z c₂″) (cong g (sym c₂′≡c₂″)))) ≡⟨ sym $ trans-assoc _ _ (trans _ (cong g (sym c₂′≡c₂″))) ⟩
trans (trans (cong (λ x → set l₂ x c₂′) y)
(cong (set l₂ b₁) c₂′≡c₂″))
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₉ ⟩
trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ sym $ trans-assoc _ _ (cong g (sym c₂′≡c₂″)) ⟩∎
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(cong g (sym c₂′≡c₂″)) ∎
lemma₅ =
z c₂′ ≡⟨ sym $ dcong z (sym c₂′≡c₂″) ⟩
subst (λ x → set l₂ b₁ x ≡ g x) (sym c₂′≡c₂″) (z c₂″) ≡⟨ subst-in-terms-of-trans-and-cong {f = set l₂ b₁} {g = g} {x≡y = sym c₂′≡c₂″} ⟩
trans (sym (cong (set l₂ b₁) (sym c₂′≡c₂″)))
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₈ ⟩∎
trans (cong (set l₂ b₁) c₂′≡c₂″)
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ∎
lemma₄ =
trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans (trans (cong (λ x → set l₂ x c₂′) y) e)
(cong g (cong h (cong i y))))
lemma₅ ⟩
trans (trans (cong (λ x → set l₂ x c₂′) y)
(trans (cong (set l₂ b₁) c₂′≡c₂″)
(trans (z c₂″) (cong g (sym c₂′≡c₂″)))))
(cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans e (cong g (cong h (cong i y)))) lemma₆ ⟩
trans (trans (trans (cong (λ x → set l₂ x (h (i x))) y)
(z c₂″))
(cong g (sym c₂′≡c₂″)))
(cong g (cong h (cong i y))) ≡⟨ trans-assoc _ _ (cong g (cong h (cong i y))) ⟩
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(trans (cong g (sym c₂′≡c₂″))
(cong g (cong h (cong i y)))) ≡⟨ cong (trans (trans _ (z c₂″))) lemma₇ ⟩
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(refl _) ≡⟨ trans-reflʳ _ ⟩∎
trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″) ∎
lemma₃ =
cong g (trans (cong h (trans (cong i y) u)) v) ≡⟨ cong (λ e → cong g (trans e v)) (cong-trans h _ u) ⟩
cong g (trans (trans (cong h (cong i y)) (cong h u)) v) ≡⟨ cong (cong g) (trans-assoc _ _ v) ⟩
cong g (trans (cong h (cong i y)) (trans (cong h u) v)) ≡⟨ cong-trans g _ (trans _ v) ⟩∎
trans (cong g (cong h (cong i y)))
(cong g (trans (cong h u) v)) ∎
lemma₂ =
trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (trans (trans _ (z c₂′))) lemma₃ ⟩
trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(trans (cong g (cong h (cong i y)))
(cong g (trans (cong h u) v))) ≡⟨ sym $ trans-assoc _ _ (cong g (trans _ v)) ⟩
trans (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (cong h (cong i y))))
(cong g (trans (cong h u) v)) ≡⟨ cong (λ e → trans e (cong g (trans (cong h u) v))) lemma₄ ⟩
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(cong g (trans (cong h u) v)) ≡⟨ trans-assoc _ _ (cong g (trans _ v)) ⟩∎
trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″) (cong g (trans (cong h u) v))) ∎
lemma₁ =
trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))
(cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (λ e → trans
(cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) e)
(sym $ cong-∘ f g (trans _ v)) ⟩
trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))
(cong f (cong g (trans (cong h (trans (cong i y) u))
v))) ≡⟨ sym $ cong-trans f (trans _ (z c₂′)) (cong g (trans _ v)) ⟩
cong f (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (trans (cong h (trans (cong i y) u))
v))) ≡⟨ cong (cong f) lemma₂ ⟩
cong f (trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong-trans _ _ _ ⟩
trans (cong f (cong (λ x → set l₂ x (h (i x))) y))
(cong f (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong₂ (λ p q → trans p (cong f (trans (z c₂″) q)))
(cong-∘ _ _ _)
(trans (cong-trans _ _ _) $
cong (flip trans _) $
cong-∘ _ _ _) ⟩∎
trans (cong (λ x → f (set l₂ x (h (i x)))) y)
(cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v)))) ∎
in
trans (trans x (trans (cong (λ x → f (set l₂ x c₂′)) y)
(cong f (z c₂′))))
(trans (cong (f ⊚ g ⊚ h) (trans (cong i y) u))
(cong (f ⊚ g) v)) ≡⟨ cong₂ (λ p q → trans (trans x p) q)
(trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $
sym $ cong-trans _ _ _)
(trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $
sym $ cong-trans _ _ _) ⟩
trans (trans x (cong f (trans (cong (λ x → set l₂ x c₂′) y)
(z c₂′))))
(cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ trans-assoc _ _ _ ⟩
trans x (trans (cong f (trans (cong (λ x → set l₂ x c₂′) y)
(z c₂′)))
(cong (f ⊚ g)
(trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (trans x) lemma₁ ⟩∎
trans x (trans (cong (λ x → f (set l₂ x (h (i x)))) y)
(cong f (trans (z c₂″) (trans (cong (g ⊚ h) u)
(cong g v))))) ∎
-- Every lens of type Lens A A that satisfies a certain right
-- identity law is equal to the identity lens.
id-unique :
(id′ : Lens A A) →
((l : Lens A A) → l ∘ id′ ≡ l) →
id′ ≡ id
id-unique id′ right-identity =
id′ ≡⟨ sym $ left-identity _ ⟩
id ∘ id′ ≡⟨ right-identity _ ⟩∎
id ∎
-- An equality characterisation lemma that can be used when one of
-- the lenses is the identity.
equality-characterisation-id :
{l : Lens A A} → let open Lens l in
l ≡ id
↔
∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) ×
(∀ a → set-get a ≡ trans (s a (get a)) (g a)) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))
equality-characterisation-id {l = l} =
l ≡ id ↝⟨ equality-characterisation₄ ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b →
trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡
refl _) ×
(∀ a →
trans (sym (trans (s a (get a)) (cong P.id (g a))))
(set-get a) ≡
refl _) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))
(refl _)))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → Erased-cong (∃-cong λ _ →
(∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ eq → trans (sym (trans _ eq)) (set-get _) ≡ _) $ sym $
cong-id (g _))
×-cong
∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (_ ≡_) $ trans-reflʳ _)) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b →
trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡
refl _) ×
(∀ a →
trans (sym (trans (s a (get a)) (g a))) (set-get a) ≡
refl _) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ _ → ∀-cong ext λ _ →
≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘
≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm)
×-cong
(∀-cong ext λ _ →
≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘
≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm)
×-cong
F.id)) ⟩□
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) ×
(∀ a → set-get a ≡ trans (s a (get a)) (g a)) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) □
where
open Lens l
-- A lemma that can be used to show that a lens with a constant
-- setter (such as the ones produced by getter-equivalence→lens
-- below) is equal to the identity lens.
constant-setter→≡id :
{l′ : ∃ λ (get : A → A) →
∃ λ (set : A → A) →
Erased
((A → ∀ a → get (set a) ≡ a) ×
(∀ a → set (get a) ≡ a) ×
(A → A → ∀ a → set a ≡ set a))} →
let l = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′)
set = proj₁ (proj₂ l′)
open Lens l hiding (set)
in
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _))) →
l ≡ id
constant-setter→≡id {A = A} {l′ = l′} =
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _))) ↝⟨ (Σ-map P.id $ Σ-map P.id λ {s} → Erased-cong (
Σ-map P.id $ Σ-map P.id λ hyp a a₁ a₂ →
trans (set-set a a₁ a₂) (s a₂) ≡⟨ cong (λ eq → trans eq (s a₂)) $ hyp _ _ _ ⟩
trans (refl _) (s a₂) ≡⟨ trans-reflˡ (s _) ⟩∎
s a₂ ∎)) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ s a₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ a₁ → ∀-cong ext λ a₂ →
≡⇒↝ F.equivalence $ cong (trans _ (s _) ≡_) (
s a₂ ≡⟨ sym $ cong-ext s ⟩
cong (λ set → set a₂) (⟨ext⟩ s) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ s) ⟩
cong (λ set → set (set a a₁) a₂) (cong const (⟨ext⟩ s)) ≡⟨ cong (cong (λ set → set (set a a₁) a₂)) $ sym $
ext-const (⟨ext⟩ s) ⟩∎
cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s) ∎))) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ →
trans (set-set a a₁ a₂) (s a₂) ≡
cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s)))) ↝⟨ Σ-map P.id (Σ-map const P.id) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : A → ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₁ a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s a (get a)) (g a)) ×
(∀ a a₁ a₂ →
trans (set-set a a₁ a₂) (s a a₂) ≡
cong (λ set → set (set a a₁) a₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) ↔⟨ inverse equality-characterisation-id ⟩□
l″ ≡ id □
where
l″ = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′)
set = proj₁ (proj₂ l′)
open Lens l″ hiding (set)
-- An identity function for lenses for which the forward direction
-- is an equivalence (with erased proofs).
--
-- Note that the setter of the resulting lens is definitionally
-- equal to a constant function returning the right-to-left
-- direction of the equivalence.
--
-- Note also that two proofs, set-get and set-set, have been
-- "obfuscated". They could have been shorter, but then it might not
-- have been possible to prove getter-equivalence→lens≡.
getter-equivalence→lens :
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) →
Lens A B
getter-equivalence→lens l is-equiv = record
{ get = to
; set = const from
; get-set = const right-inverse-of
; set-get = λ a →
from (to a) ≡⟨ cong from (sym (get-set a (to a))) ⟩
from (get (set a (to a))) ≡⟨⟩
from (to (set a (get a))) ≡⟨ cong (from ⊚ to) (set-get a) ⟩
from (to a) ≡⟨ left-inverse-of _ ⟩∎
a ∎
; set-set = λ a b₁ b₂ →
let s = from≡set l is-equiv in
from b₂ ≡⟨ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)) ⟩
set (set a b₁) b₂ ≡⟨ set-set a b₁ b₂ ⟩
set a b₂ ≡⟨ sym (s a b₂) ⟩∎
from b₂ ∎
}
where
A≃B = EEq.⟨ _ , is-equiv ⟩
open _≃ᴱ_ A≃B
open Lens l
-- In erased contexts it can be proved that the function
-- getter-equivalence→lens returns its input.
@0 getter-equivalence→lens≡ :
∀ (l : Lens A B) is-equiv →
getter-equivalence→lens l is-equiv ≡ l
getter-equivalence→lens≡ l is-equiv = $⟨ TC.getter-equivalence→lens≡ (trad l) is-equiv′ ⟩
TC.getter-equivalence→lens (trad l) is-equiv′ ≡ trad l ↝⟨ cong Traditional-lens→Lens ⟩□
getter-equivalence→lens l is-equiv ≡ l □
where
is-equiv′ = EEq.Is-equivalenceᴱ→Is-equivalence is-equiv
------------------------------------------------------------------------
-- Some existence results
-- There is, in general, no lens for the first projection from a
-- Σ-type.
no-first-projection-lens :
¬ Lens (∃ λ (b : Bool) → b ≡ true) Bool
no-first-projection-lens =
Non-dependent.no-first-projection-lens
Lens contractible-to-contractible
-- There are two lenses with equal setters that are not equal
-- (assuming univalence).
--
-- (The lemma does not actually use the univalence argument, but
-- univalence is used by CE.not-refl≢refl, which is only used in an
-- erased context.)
equal-setters-but-not-equal :
@0 Univalence lzero →
∃ λ (A : Type) →
∃ λ (B : Type) →
∃ λ (l₁ : Lens A B) →
∃ λ (l₂ : Lens A B) →
Lens.set l₁ ≡ Lens.set l₂ ×
l₁ ≢ l₂
equal-setters-but-not-equal _ =
block λ b →
𝕊¹ᴱ , ⊤ , l₁′ b , l₂′ , refl _ , l₁′≢l₂′ b
where
open Lens
@0 not-refl : Block "not-refl" → (x : 𝕊¹ᴱ) → x ≡ x
not-refl ⊠ = CE.not-refl
@0 not-refl≢refl : ∀ b → not-refl b ≢ refl
not-refl≢refl ⊠ = CE.not-refl≢refl
l₁′ : Block "not-refl" → Lens 𝕊¹ᴱ ⊤
l₁′ b = _≃ᴱ_.from lens-to-⊤≃ᴱ [ not-refl b ]
l₂′ : Lens 𝕊¹ᴱ ⊤
l₂′ = _≃ᴱ_.from lens-to-⊤≃ᴱ [ refl ]
l₁′≢l₂′ : ∀ b → l₁′ b ≢ l₂′
l₁′≢l₂′ b =
Stable-¬
[ l₁′ b ≡ l₂′ ↔⟨ Eq.≃-≡ (EEq.≃ᴱ→≃ $ inverse lens-to-⊤≃ᴱ)
{x = [ not-refl b ]} {y = [ refl ]} ⟩
[ not-refl b ] ≡ [ refl ] ↝⟨ cong erased ⟩
not-refl b ≡ refl ↝⟨ not-refl≢refl b ⟩□
⊥ □
]
-- A lens which is used in some counterexamples below.
bad : (a : Level) → Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)
bad a = record
{ get = P.id
; set = const P.id
; get-set = λ _ → cong lift ⊚ CE.not-refl ⊚ lower
; set-get = refl
; set-set = λ _ _ → cong lift ⊚ CE.not-refl ⊚ lower
}
-- The lens bad a has a getter which is an equivalence, but it does
-- not satisfy either of the coherence laws that Coherent-lens lenses
-- must satisfy (assuming univalence).
--
-- (The lemma does not actually use the univalence argument, but
-- univalence is used by CE.not-refl≢refl, which is only used in
-- erased contexts.)
getter-equivalence-but-not-coherent :
@0 Univalence lzero →
let open Lens (bad a) in
Is-equivalence get ×
¬ (∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
¬ (∀ a₁ a₂ a₃ →
cong get (set-set a₁ a₂ a₃) ≡
trans (get-set (set a₁ a₂) a₃) (sym (get-set a₁ a₃)))
getter-equivalence-but-not-coherent {a = a} univ =
_≃_.is-equivalence F.id
, Stable-¬
[ ((x : ↑ a 𝕊¹ᴱ) → cong get (set-get x) ≡ get-set x (get x)) ↔⟨⟩
((x : ↑ a 𝕊¹ᴱ) →
cong P.id (refl _) ≡ cong lift (CE.not-refl (lower x))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ → Eq.id) ⟩
((x : 𝕊¹ᴱ) → cong P.id (refl _) ≡ cong lift (CE.not-refl x)) ↝⟨ trans (trans (cong-refl _) (cong-id _)) ⊚_ ⟩
((x : 𝕊¹ᴱ) → cong lift (refl x) ≡ cong lift (CE.not-refl x)) ↔⟨ (∀-cong ext λ _ →
Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩
((x : 𝕊¹ᴱ) → refl x ≡ CE.not-refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩
refl ≡ CE.not-refl ↝⟨ CE.not-refl≢refl ⊚ sym ⟩□
⊥ □
]
, Stable-¬
[ ((x y z : ↑ a 𝕊¹ᴱ) →
cong get (set-set x y z) ≡
trans (get-set (set x y) z) (sym (get-set x z))) ↔⟨⟩
((x y z : ↑ a 𝕊¹ᴱ) →
cong P.id (cong lift (CE.not-refl (lower z))) ≡
trans (cong lift (CE.not-refl (lower z)))
(sym (cong lift (CE.not-refl (lower z))))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ →
Π-cong ext Bij.↑↔ λ _ →
Π-cong ext Bij.↑↔ λ _ →
Eq.id) ⟩
((x y z : 𝕊¹ᴱ) →
cong P.id (cong lift (CE.not-refl z)) ≡
trans (cong lift (CE.not-refl z))
(sym (cong lift (CE.not-refl z)))) ↝⟨ (λ hyp → hyp CE.base CE.base) ⟩
((x : 𝕊¹ᴱ) →
cong P.id (cong lift (CE.not-refl x)) ≡
trans (cong lift (CE.not-refl x))
(sym (cong lift (CE.not-refl x)))) ↔⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong₂ _≡_
(sym $ cong-id _)
(trans (trans-symʳ _) $
sym $ cong-refl _)) ⟩
((x : 𝕊¹ᴱ) →
cong lift (CE.not-refl x) ≡ cong lift (refl x)) ↔⟨ (∀-cong ext λ _ →
Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩
((x : 𝕊¹ᴱ) → CE.not-refl x ≡ refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩
CE.not-refl ≡ refl ↝⟨ CE.not-refl≢refl ⟩□
⊥ □
]
where
open Lens (bad a)
-- The lenses bad a and Lens-combinators.id {A = ↑ a 𝕊¹ᴱ} have equal
-- setters, and their getters are equivalences, but they are not equal
-- (assuming univalence).
equal-setters-and-equivalences-as-getters-but-not-equal :
@0 Univalence lzero →
let l₁ = bad a
l₂ = Lens-combinators.id {A = ↑ a 𝕊¹ᴱ}
in
Is-equivalence (Lens.get l₁) ×
Is-equivalence (Lens.get l₂) ×
Lens.set l₁ ≡ Lens.set l₂ ×
l₁ ≢ l₂
equal-setters-and-equivalences-as-getters-but-not-equal {a = ℓa} univ =
let is-equiv , not-coherent , _ =
getter-equivalence-but-not-coherent univ
in
is-equiv
, _≃_.is-equivalence F.id
, refl _
, Stable-¬
[ bad ℓa ≡ id ↝⟨ (λ eq → subst (λ l → ∀ a → cong (get l) (set-get l a) ≡
get-set l a (get l a))
(sym eq)
(λ _ → cong-refl _)) ⟩
(∀ a → cong (get (bad ℓa)) (set-get (bad ℓa) a) ≡
get-set (bad ℓa) a (get (bad ℓa) a)) ↝⟨ not-coherent ⟩□
⊥ □
]
where
open Lens
open Lens-combinators
-- There is in general no split surjection from equivalences with
-- erased proofs to lenses with getters that are equivalences with
-- erased proofs, if the right-to-left direction of the split
-- surjection is required to return the lens's getter plus some proof
-- (assuming univalence).
¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get :
@0 Univalence lzero →
¬ ∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠
(∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) →
Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)
¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get {a = a} univ =
Stable-¬
[ (let is-equiv₁′ , is-equiv₂′ , setters-equal , bad≢id =
equal-setters-and-equivalences-as-getters-but-not-equal univ
is-equiv₁ = EEq.Is-equivalence→Is-equivalenceᴱ is-equiv₁′
is-equiv₂ = EEq.Is-equivalence→Is-equivalenceᴱ is-equiv₂′
in
λ (f , hyp) → $⟨ setters-equal ⟩
Lens.set (bad a) ≡ Lens.set id ↝⟨ getters-equal-if-setters-equal (bad a) id ⟩
Lens.get (bad a) ≡ Lens.get id ↝⟨ (λ eq → trans (hyp _) (trans eq (sym (hyp _)))) ⟩
_≃ᴱ_.to (_↠_.from f (bad a , is-equiv₁)) ≡
_≃ᴱ_.to (_↠_.from f (id , is-equiv₂)) ↝⟨ EEq.to≡to→≡ ext ⟩
_↠_.from f (bad a , is-equiv₁) ≡
_↠_.from f (id , is-equiv₂) ↝⟨ _↠_.to (Surjection.↠-≡ f) ⟩
(bad a , is-equiv₁) ≡ (id , is-equiv₂) ↝⟨ cong proj₁ ⟩
bad a ≡ id ↝⟨ bad≢id ⟩□
⊥ □)
]
where
open Lens-combinators
-- There is in general no equivalence with erased proofs from
-- equivalences with erased proofs to lenses with getters that are
-- equivalences with erased proofs, if the right-to-left direction of
-- the equivalence is required to return the lens's getter plus some
-- proof (assuming univalence).
¬-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalence-get :
@0 Univalence lzero →
¬ ∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ
(∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) →
Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_≃ᴱ_.from f p) ≡ Lens.get (proj₁ p)
¬-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalence-get {a = a} univ =
Stable-¬
[ (∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ
(∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) →
Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_≃ᴱ_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map (_≃_.surjection ⊚ EEq.≃ᴱ→≃) P.id ⟩
(∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠
(∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) →
Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ ⟩□
⊥ □
]
------------------------------------------------------------------------
-- Isomorphisms expressed using lens quasi-inverses
private
module B {a} =
Bi-invertibility.Erased
equality-with-J (Type a) Lens
Lens-combinators.id Lens-combinators._∘_
module BM {a} =
B.More {a = a}
Lens-combinators.left-identity
Lens-combinators.right-identity
Lens-combinators.associativity
-- A form of isomorphism between types, expressed using lenses.
open B public
using ()
renaming (_≅ᴱ_ to _≅ᴱ_; Has-quasi-inverseᴱ to Has-quasi-inverseᴱ)
-- In erased contexts Has-quasi-inverseᴱ (Traditional-lens→Lens l) is
-- equivalent to TC.Has-quasi-inverse l.
@0 Has-quasi-inverseᴱ≃Has-quasi-inverse :
(l : T.Lens A B) →
Has-quasi-inverseᴱ (Traditional-lens→Lens l) ≃ TC.Has-quasi-inverse l
Has-quasi-inverseᴱ≃Has-quasi-inverse l =
(∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ →
inverse (Eq.≃-≡ Lens≃Traditional-lens)
×-cong
inverse (Eq.≃-≡ Lens≃Traditional-lens)) ⟩□
(∃ λ l⁻¹ → l TC.∘ l⁻¹ ≡ TC.id × l⁻¹ TC.∘ l ≡ TC.id ) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- In erased contexts A ≅ᴱ B is equivalent to A TC.≅ B.
@0 ≅ᴱ≃≅ : (A ≅ᴱ B) ≃ (A TC.≅ B)
≅ᴱ≃≅ {A = A} {B = B} =
(∃ λ (l : Lens A B) → Has-quasi-inverseᴱ l) ↝⟨ Σ-cong-contra (inverse Lens≃Traditional-lens) Has-quasi-inverseᴱ≃Has-quasi-inverse ⟩□
(∃ λ (l : T.Lens A B) → TC.Has-quasi-inverse l) □
-- An equality characterisation lemma for A ≅ B that applies when A is
-- a set.
@0 equality-characterisation-for-sets-≅ᴱ :
let open Lens in
{f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≅ᴱ B} →
Is-set A →
f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂
equality-characterisation-for-sets-≅ᴱ
{f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set =
f₁ ≡ f₂ ↔⟨ inverse $ Eq.≃-≡ ≅ᴱ≃≅ ⟩
_≃_.to ≅ᴱ≃≅ f₁ ≡ _≃_.to ≅ᴱ≃≅ f₂ ↝⟨ TC.equality-characterisation-for-sets-≅ A-set ⟩□
set l₁₁ ≡ set l₁₂ □
where
open Lens
-- There is a logical equivalence between A ≃ᴱ B and A ≅ᴱ B.
≃ᴱ⇔≅ᴱ : (A ≃ᴱ B) ⇔ (A ≅ᴱ B)
≃ᴱ⇔≅ᴱ {A = A} {B = B} = record
{ to = λ A≃B → ≃ᴱ→lens A≃B
, ≃ᴱ→lens (inverse A≃B)
, [ lemma A≃B
, (≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens A≃B ≡⟨ cong {x = A≃B} {y = inverse $ inverse A≃B}
(λ A≃B′ → ≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens A≃B′) $
sym $ EEq.to≡to→≡ ext (refl _) ⟩
≃ᴱ→lens (inverse A≃B) ∘
≃ᴱ→lens (inverse $ inverse A≃B) ≡⟨ lemma (inverse A≃B) ⟩∎
id ∎)
]
; from = λ (l₁ , l₂ , [ eq₁ , eq₂ ]) → EEq.↔→≃ᴱ
(get l₁)
(get l₂)
(ext⁻¹ $
getters-equal-if-setters-equal (l₁ ∘ l₂) id
(cong set eq₁))
(ext⁻¹ $
getters-equal-if-setters-equal (l₂ ∘ l₁) id
(cong set eq₂))
}
where
open Lens
open Lens-combinators
@0 lemma :
(C≃D : C ≃ᴱ D) → ≃ᴱ→lens C≃D ∘ ≃ᴱ→lens (inverse C≃D) ≡ id
lemma C≃D = _↔_.from equality-characterisation₂
( ⟨ext⟩ (_≃ᴱ_.right-inverse-of C≃D)
, (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
, [ lemma₁
, lemma₂
, lemma₃
]
)
where
@0 lemma₁ : _
lemma₁ = λ d₁ d₂ →
let lemma =
cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))) $
ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))
(cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₂)))
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)
(cong (λ set → set d₂)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) ≡⟨ cong (cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)) $ cong-ext _ ⟩
cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)
(_≃ᴱ_.right-inverse-of C≃D _) ≡⟨ sym $ cong-∘ _ _ (_≃ᴱ_.right-inverse-of C≃D _) ⟩
cong (_≃ᴱ_.to C≃D)
(cong (_≃ᴱ_.from C≃D) (_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ cong (cong (_≃ᴱ_.to C≃D)) $ _≃ᴱ_.right-left-lemma C≃D _ ⟩∎
cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _) ∎
in
trans (sym
(trans (cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))
(cong (λ get → get d₂)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))))
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ cong₂ (λ p q → trans (sym (trans p q))
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)))
lemma
(cong-ext _) ⟩
trans (sym
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)))
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃ᴱ_.right-inverse-of C≃D _)) ⟩∎
refl _ ∎
@0 lemma₂ : _
lemma₂ = λ d →
let lemma =
cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))) $
ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → set (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-ext _ ⟩∎
_≃ᴱ_.right-inverse-of C≃D _ ∎
in
trans (sym
(trans (cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))
(cong (λ get → get d)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))))
(trans
(cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.left-inverse-of (inverse C≃D) _)) ≡⟨ cong₂ (λ p q → trans (sym p) q)
(cong₂ trans lemma (cong-ext _))
(cong₂ trans
(_≃ᴱ_.left-right-lemma C≃D _)
(EEq.left-inverse-of∘inverse C≃D)) ⟩
trans (sym (trans (_≃ᴱ_.right-inverse-of C≃D _)
(_≃ᴱ_.right-inverse-of C≃D _)))
(trans (_≃ᴱ_.right-inverse-of C≃D _)
(_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃ᴱ_.right-inverse-of C≃D _)) ⟩∎
refl _ ∎
@0 lemma₃ : _
lemma₃ = λ d d₁ d₂ →
subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(trans (refl _)
(trans
(cong (λ _ → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d₂))
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁)))
(cong (_≃ᴱ_.to C≃D) (refl _)))) ≡⟨ cong (subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) $
trans (trans-reflˡ _) $
trans (cong (flip trans _) $ cong-const _) $
trans (trans-reflˡ _) $
cong-refl _ ⟩
subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(refl _) ≡⟨ cong (flip (subst (λ set → set (set d d₁) d₂ ≡ set d d₂)) _) $
ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(refl _) ≡⟨ sym $ subst-∘ _ _ _ ⟩
subst (λ set → set d₂ ≡ set d₂)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(refl _) ≡⟨ subst-ext _ _ ⟩
subst (λ set → set ≡ set)
(_≃ᴱ_.right-inverse-of C≃D d₂)
(refl _) ≡⟨ ≡⇒↝ _ (sym [subst≡]≡[trans≡trans]) (
trans (refl _) (_≃ᴱ_.right-inverse-of C≃D d₂) ≡⟨ trans-reflˡ _ ⟩
_≃ᴱ_.right-inverse-of C≃D d₂ ≡⟨ sym $ trans-reflʳ _ ⟩
trans (_≃ᴱ_.right-inverse-of C≃D d₂) (refl _) ∎) ⟩
refl _ ∎
-- In erased contexts the left-to-right direction of ≃ᴱ⇔≅ᴱ is a right
-- inverse of the right-to-left direction.
@0 ≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ :
(A≃B : A ≃ᴱ B) → _⇔_.from ≃ᴱ⇔≅ᴱ (_⇔_.to ≃ᴱ⇔≅ᴱ A≃B) ≡ A≃B
≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ _ = EEq.to≡to→≡ ext (refl _)
-- The forward direction of ≃ᴱ⇔≅ᴱ maps identity to an isomorphism for
-- which the first projection is the identity.
≃ᴱ⇔≅ᴱ-id≡id :
let open Lens-combinators in
proj₁ (_⇔_.to ≃ᴱ⇔≅ᴱ F.id) ≡ id {A = A}
≃ᴱ⇔≅ᴱ-id≡id = equal-laws→≡
(λ _ _ → refl _)
(λ a →
_≃ᴱ_.left-inverse-of F.id a ≡⟨ sym $ _≃ᴱ_.right-left-lemma F.id _ ⟩
cong P.id (_≃ᴱ_.right-inverse-of F.id a) ≡⟨⟩
cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎
refl _ ∎)
(λ _ _ _ → refl _)
where
open Lens-combinators
-- If A is a set, then there is an equivalence with erased proofs
-- between A ≃ᴱ B and A ≅ᴱ B.
≃ᴱ≃ᴱ≅ᴱ :
@0 Is-set A →
(A ≃ᴱ B) ≃ᴱ (A ≅ᴱ B)
≃ᴱ≃ᴱ≅ᴱ A-set = EEq.↔→≃ᴱ
(_⇔_.to ≃ᴱ⇔≅ᴱ)
(_⇔_.from ≃ᴱ⇔≅ᴱ)
(λ (l₁ , l₂ , [ eq₁ , eq₂ ]) →
_↔_.from (equality-characterisation-for-sets-≅ᴱ A-set) $
⟨ext⟩ λ a → ⟨ext⟩ λ b →
get l₂ b ≡⟨ sym $ ext⁻¹ (ext⁻¹ (cong set eq₂) _) _ ⟩
set l₁ (set l₁ a b)
(set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ set-set l₁ _ _ _ ⟩
set l₁ a (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ cong (λ b′ → set l₁ a (set l₂ b′ (get l₂ b))) $ get-set l₁ _ _ ⟩
set l₁ a (set l₂ b (get l₂ b)) ≡⟨ cong (set l₁ a) $ set-get l₂ _ ⟩∎
set l₁ a b ∎)
≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ
where
open Lens
open Lens-combinators
-- The equivalence maps identity to an isomorphism for which the first
-- projection is the identity.
≃ᴱ≃ᴱ≅ᴱ-id≡id :
let open Lens-combinators in
(@0 A-set : Is-set A) →
proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≅ᴱ A-set) F.id) ≡ id
≃ᴱ≃ᴱ≅ᴱ-id≡id _ = ≃ᴱ⇔≅ᴱ-id≡id
-- The type Has-quasi-inverseᴱ id is not necessarily a proposition
-- (assuming univalence).
Has-quasi-inverseᴱ-id-not-proposition :
@0 Univalence lzero →
let open Lens-combinators in
∃ λ (A : Type a) →
¬ Is-proposition (Has-quasi-inverseᴱ (id {A = A}))
Has-quasi-inverseᴱ-id-not-proposition univ =
_
, Stable-¬
[ Is-proposition (Has-quasi-inverseᴱ Lens-combinators.id) ↝⟨ H-level-cong _ 1 $ Has-quasi-inverseᴱ≃Has-quasi-inverse TC.id ⟩
Is-proposition (TC.Has-quasi-inverse TC.id) ↝⟨ proj₂ $ TC.Has-quasi-inverse-id-not-proposition univ ⟩□
⊥ □
]
-- There is not necessarily a split surjection from
-- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ :
@0 Univalence lzero →
¬ ({A B : Type a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l)
¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ {a = a} univ =
Stable-¬
[ ({A B : Type a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ↝⟨ (λ hyp l →
from-equivalence (Has-quasi-inverseᴱ≃Has-quasi-inverse l) F.∘
hyp (Traditional-lens→Lens l) F.∘
from-equivalence EEq.Is-equivalence≃Is-equivalenceᴱ) ⟩
({A B : Type a}
(l : T.Lens A B) →
Is-equivalence (T.Lens.get l) ↠ TC.Has-quasi-inverse l) ↝⟨ TC.¬Is-equivalence↠Has-quasi-inverse univ ⟩□
⊥ □
]
-- There is not necessarily an equivalence with erased proofs from
-- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalenceᴱ≃Has-quasi-inverseᴱ :
@0 Univalence lzero →
¬ ({A B : Type a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ l)
¬Is-equivalenceᴱ≃Has-quasi-inverseᴱ {a = a} univ =
Stable-¬
[ ({A B : Type a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ l) ↝⟨ (λ hyp → _≃_.surjection ⊚ EEq.≃ᴱ→≃ ⊚ hyp) ⟩
({A B : Type a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ↝⟨ ¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ univ ⟩□
⊥ □
]
------------------------------------------------------------------------
-- Isomorphisms expressed using bi-invertibility for lenses
-- A form of isomorphism between types, expressed using lenses.
open B public
using ()
renaming (_≊ᴱ_ to _≊ᴱ_;
Has-left-inverseᴱ to Has-left-inverseᴱ;
Has-right-inverseᴱ to Has-right-inverseᴱ;
Is-bi-invertibleᴱ to Is-bi-invertibleᴱ)
open BM public
using ()
renaming (Is-bi-invertibleᴱ-propositional to
Is-bi-invertibleᴱ-propositional)
-- In erased contexts Has-left-inverseᴱ (Traditional-lens→Lens l) is
-- equivalent to TC.Has-left-inverse l.
@0 Has-left-inverseᴱ≃Has-left-inverse :
(l : T.Lens A B) →
Has-left-inverseᴱ (Traditional-lens→Lens l) ≃ TC.Has-left-inverse l
Has-left-inverseᴱ≃Has-left-inverse l =
(∃ λ l⁻¹ → Erased (l⁻¹ LC.∘ l′ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse $ Eq.≃-≡ Lens≃Traditional-lens) ⟩□
(∃ λ l⁻¹ → l⁻¹ TC.∘ l ≡ TC.id ) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- In erased contexts Has-right-inverseᴱ (Traditional-lens→Lens l) is
-- equivalent to TC.Has-right-inverse l.
@0 Has-right-inverseᴱ≃Has-right-inverse :
(l : T.Lens A B) →
Has-right-inverseᴱ (Traditional-lens→Lens l) ≃ TC.Has-right-inverse l
Has-right-inverseᴱ≃Has-right-inverse l =
(∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse $ Eq.≃-≡ Lens≃Traditional-lens) ⟩□
(∃ λ l⁻¹ → l TC.∘ l⁻¹ ≡ TC.id ) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- In erased contexts Is-bi-invertibleᴱ (Traditional-lens→Lens l) is
-- equivalent to TC.Is-bi-invertible l.
@0 Is-bi-invertibleᴱ≃Is-bi-invertible :
(l : T.Lens A B) →
Is-bi-invertibleᴱ (Traditional-lens→Lens l) ≃ TC.Is-bi-invertible l
Is-bi-invertibleᴱ≃Is-bi-invertible l =
Is-bi-invertibleᴱ l′ ↔⟨⟩
Has-left-inverseᴱ l′ × Has-right-inverseᴱ l′ ↝⟨ Has-left-inverseᴱ≃Has-left-inverse l ×-cong
Has-right-inverseᴱ≃Has-right-inverse l ⟩
TC.Has-left-inverse l × TC.Has-right-inverse l ↔⟨⟩
TC.Is-bi-invertible l □
where
l′ = Traditional-lens→Lens l
-- In erased contexts A ≊ᴱ B is equivalent to A TC.≊ B.
@0 ≊ᴱ≃≊ : (A ≊ᴱ B) ≃ (A TC.≊ B)
≊ᴱ≃≊ {A = A} {B = B} =
(∃ λ (l : Lens A B) → Is-bi-invertibleᴱ l) ↝⟨ (inverse $
Σ-cong (inverse Lens≃Traditional-lens) λ l →
inverse $ Is-bi-invertibleᴱ≃Is-bi-invertible l) ⟩□
(∃ λ (l : T.Lens A B) → TC.Is-bi-invertible l) □
-- An equality characterisation lemma for A ≊ᴱ B that applies when A
-- is a set.
@0 equality-characterisation-for-sets-≊ᴱ :
let open Lens in
{f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≊ᴱ B} →
Is-set A →
f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂
equality-characterisation-for-sets-≊ᴱ
{f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set =
f₁ ≡ f₂ ↔⟨ inverse $ Eq.≃-≡ ≊ᴱ≃≊ ⟩
_≃_.to ≊ᴱ≃≊ f₁ ≡ _≃_.to ≊ᴱ≃≊ f₂ ↝⟨ TC.equality-characterisation-for-sets-≊ A-set ⟩□
set l₁₁ ≡ set l₁₂ □
where
open Lens
-- There is a logical equivalence between A ≃ᴱ B and A ≊ᴱ B.
≃ᴱ⇔≊ᴱ : (A ≃ᴱ B) ⇔ (A ≊ᴱ B)
≃ᴱ⇔≊ᴱ = record
{ to = _⇔_.to BM.≅ᴱ⇔≊ᴱ ⊚ _⇔_.to ≃ᴱ⇔≅ᴱ
; from = _⇔_.from ≃ᴱ⇔≅ᴱ ⊚ _⇔_.from BM.≅ᴱ⇔≊ᴱ
}
-- In erased contexts the left-to-right direction of ≃ᴱ⇔≊ᴱ is a right
-- inverse of the right-to-left direction.
@0 ≃ᴱ⇔≊ᴱ∘≃ᴱ⇔≊ᴱ :
(A≃B : A ≃ᴱ B) → _⇔_.from ≃ᴱ⇔≊ᴱ (_⇔_.to ≃ᴱ⇔≊ᴱ A≃B) ≡ A≃B
≃ᴱ⇔≊ᴱ∘≃ᴱ⇔≊ᴱ _ = EEq.to≡to→≡ ext (refl _)
-- The forward direction of ≃ᴱ⇔≊ᴱ maps identity to an isomorphism for
-- which the first projection is the identity.
≃ᴱ⇔≊ᴱ-id≡id :
let open Lens-combinators in
proj₁ (_⇔_.to ≃ᴱ⇔≊ᴱ F.id) ≡ id {A = A}
≃ᴱ⇔≊ᴱ-id≡id = equal-laws→≡
(λ _ _ → refl _)
(λ a →
_≃ᴱ_.left-inverse-of F.id a ≡⟨ sym $ _≃ᴱ_.right-left-lemma F.id _ ⟩
cong P.id (_≃ᴱ_.right-inverse-of F.id a) ≡⟨⟩
cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎
refl _ ∎)
(λ _ _ _ → refl _)
where
open Lens-combinators
-- If A is a set, then there is an equivalence between A ≃ᴱ B and
-- A ≊ᴱ B.
≃ᴱ≃ᴱ≊ᴱ : @0 Is-set A → (A ≃ᴱ B) ≃ᴱ (A ≊ᴱ B)
≃ᴱ≃ᴱ≊ᴱ {A = A} {B = B} A-set =
A ≃ᴱ B ↝⟨ ≃ᴱ≃ᴱ≅ᴱ A-set ⟩
A ≅ᴱ B ↝⟨ inverse $ BM.≊ᴱ≃ᴱ≅ᴱ-domain (lens-preserves-h-level-of-domain 1 A-set) ⟩□
A ≊ᴱ B □
-- The equivalence ≃ᴱ≃ᴱ≊ᴱ maps identity to an isomorphism for which the
-- first projection is the identity.
≃ᴱ≃ᴱ≊ᴱ-id≡id :
let open Lens-combinators in
(@0 A-set : Is-set A) →
proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≊ᴱ A-set) F.id) ≡ id
≃ᴱ≃ᴱ≊ᴱ-id≡id _ = ≃ᴱ⇔≊ᴱ-id≡id
where
open Lens-combinators
-- The right-to-left direction of ≃ᴱ≃ᴱ≊ᴱ maps bi-invertible lenses to
-- their getter functions.
to-from-≃ᴱ≃ᴱ≊ᴱ≡get :
(@0 A-set : Is-set A) (A≊B@(l , _) : A ≊ᴱ B) →
_≃ᴱ_.to (_≃ᴱ_.from (≃ᴱ≃ᴱ≊ᴱ A-set) A≊B) ≡ Lens.get l
to-from-≃ᴱ≃ᴱ≊ᴱ≡get _ _ = refl _
-- The getter function of a bi-invertible lens is an equivalence (with
-- erased proofs).
Is-bi-invertibleᴱ→Is-equivalenceᴱ-get :
(l : Lens A B) →
Is-bi-invertibleᴱ l → Is-equivalenceᴱ (Lens.get l)
Is-bi-invertibleᴱ→Is-equivalenceᴱ-get l is-bi-inv =
_≃ᴱ_.is-equivalence (_⇔_.from ≃ᴱ⇔≊ᴱ (l , is-bi-inv))
-- If the getter function is an equivalence (with erased proofs), then
-- the lens is bi-invertible (with erased proofs).
Is-equivalenceᴱ-get→Is-bi-invertibleᴱ :
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) → Is-bi-invertibleᴱ l
Is-equivalenceᴱ-get→Is-bi-invertibleᴱ {A = A} {B = B} l′ is-equiv =
block λ b →
$⟨ l⁻¹′ b , [ l∘l⁻¹≡id b , l⁻¹∘l≡id b ] ⟩
Has-quasi-inverseᴱ l ↝⟨ B.Has-quasi-inverseᴱ→Is-bi-invertibleᴱ l ⟩
Is-bi-invertibleᴱ l ↝⟨ subst (λ l → Is-bi-invertibleᴱ (erased l)) ([]-cong [ getter-equivalence→lens≡ l′ is-equiv ]) ⟩□
Is-bi-invertibleᴱ l′ □
where
open Lens
open Lens-combinators
-- A lens that is equal to l′.
l : Lens A B
l = getter-equivalence→lens l′ is-equiv
A≃B = EEq.⟨ get l , is-equiv ⟩
open _≃ᴱ_ A≃B
-- An inverse of l.
--
-- Note that the set-get and set-set proofs have been "obfuscated".
-- They could have been shorter, but then it might not have been
-- possible to prove l∘l⁻¹≡id and l⁻¹∘l≡id.
l⁻¹ : Lens B A
l⁻¹ = record
{ get = from
; set = λ _ → get l
; get-set = λ _ a →
from (get l a) ≡⟨ left-inverse-of a ⟩∎
a ∎
; set-get = λ b →
get l (from b) ≡⟨ sym $ cong (get l) $ set-get l (from b) ⟩
get l (from (get l (from b))) ≡⟨ right-inverse-of (get l (from b)) ⟩
get l (from b) ≡⟨ right-inverse-of b ⟩∎
b ∎
; set-set = λ b a₁ a₂ →
get l a₂ ≡⟨ sym $ right-inverse-of _ ⟩
get l (from (get l a₂)) ≡⟨ sym $ cong (get l) (set-set l (from b) (get l a₁) (get l a₂)) ⟩
get l (from (get l a₂)) ≡⟨ right-inverse-of _ ⟩∎
get l a₂ ∎
}
-- A blocked variant of l⁻¹.
l⁻¹′ : Block "l⁻¹" → Lens B A
l⁻¹′ ⊠ = l⁻¹
-- The lens l⁻¹ is a right inverse of l.
@0 l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹′ b ≡ id
l∘l⁻¹≡id ⊠ = constant-setter→≡id
( right-inverse-of
, right-inverse-of
, [ (λ b₁ b₂ →
get-set (l ∘ l⁻¹) b₁ b₂ ≡⟨⟩
trans (cong (get l) (get-set l⁻¹ b₁ (from b₂)))
(get-set l (from b₁) b₂) ≡⟨⟩
trans (cong (get l) (left-inverse-of (from b₂)))
(right-inverse-of b₂) ≡⟨ cong (λ eq → trans (cong (get l) eq) (right-inverse-of b₂)) $ sym $
right-left-lemma _ ⟩
trans (cong (get l) (cong from (right-inverse-of b₂)))
(right-inverse-of b₂) ≡⟨ cong (λ eq → trans eq (right-inverse-of b₂)) $
cong-∘ _ _ (right-inverse-of b₂) ⟩
trans (cong (get l ⊚ from) (right-inverse-of b₂))
(right-inverse-of b₂) ≡⟨⟩
trans (cong (get (l ∘ l⁻¹)) (right-inverse-of b₂))
(right-inverse-of b₂) ∎)
, (λ b →
set-get (l ∘ l⁻¹) b ≡⟨⟩
trans (cong (get l) (set-get l (from b)))
(set-get l⁻¹ b) ≡⟨⟩
trans (cong (get l) (set-get l (from b)))
(trans (sym (cong (get l) (set-get l (from b))))
(trans (right-inverse-of (get l (from b)))
(right-inverse-of b))) ≡⟨ trans--[trans-sym] _ _ ⟩
trans (right-inverse-of (get l (from b)))
(right-inverse-of b) ≡⟨⟩
trans (right-inverse-of (get (l ∘ l⁻¹) b))
(right-inverse-of b) ∎)
, (λ b b₁ b₂ →
set-set (l ∘ l⁻¹) b b₁ b₂ ≡⟨⟩
trans (set-set l⁻¹ b (from b₁) (from b₂))
(trans (cong (λ _ → get l (from b₂))
(get-set l⁻¹ b (from b₁)))
(cong (get l) (set-set l (from b) b₁ b₂))) ≡⟨ cong (trans _) $
trans (cong (flip trans _) $ cong-const _) $
trans-reflˡ _ ⟩
trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨⟩
trans (trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from b) (get l (from b₁))
(get l (from b₂)))))
(right-inverse-of _)))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ b′ → trans (trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from b) b′
(get l (from b₂)))))
(right-inverse-of _)))
(cong (get l) (set-set l (from b) b₁ b₂))) $
right-inverse-of _ ⟩
trans (trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from b) b₁
(get l (from b₂)))))
(right-inverse-of _)))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ f → trans (trans (sym (f _))
(trans (sym (cong (get l)
(set-set l (from b) b₁
(get l (from b₂)))))
(f _)))
(cong (get l) (set-set l (from b) b₁ b₂))) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext)
right-inverse-of ⟩
trans (trans (sym (ext⁻¹ (⟨ext⟩ right-inverse-of) _))
(trans (sym (cong (get l)
(set-set l (from b) b₁
(get l (from b₂)))))
(ext⁻¹ (⟨ext⟩ right-inverse-of) _)))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ elim₁
(λ {f} (p : f ≡ P.id) →
(q : ∀ b → f b ≡ f b) →
trans (trans (sym (ext⁻¹ p (f b₂)))
(trans (sym (q (f b₂))) (ext⁻¹ p (f b₂))))
(q b₂) ≡
refl _)
(λ q →
trans (trans (sym (ext⁻¹ (refl P.id) _))
(trans (sym (q _)) (ext⁻¹ (refl P.id) _)))
(q _) ≡⟨ cong (λ eq → trans (trans (sym eq) (trans (sym (q _)) eq))
(q _)) $
ext⁻¹-refl _ ⟩
trans (trans (sym (refl _))
(trans (sym (q _)) (refl _)))
(q _) ≡⟨ cong₂ (λ p r → trans (trans p r) (q _))
sym-refl
(trans-reflʳ _) ⟩
trans (trans (refl _) (sym (q _))) (q _) ≡⟨ cong (λ eq → trans eq (q _)) $ trans-reflˡ (sym (q _)) ⟩
trans (sym (q _)) (q _) ≡⟨ trans-symˡ (q _) ⟩∎
refl _ ∎)
(⟨ext⟩ right-inverse-of)
(cong (get l) ⊚ set-set l (from b) b₁) ⟩
refl _ ∎)
]
)
-- The lens l⁻¹ is a left inverse of l.
@0 l⁻¹∘l≡id : ∀ b → l⁻¹′ b ∘ l ≡ id
l⁻¹∘l≡id ⊠ = constant-setter→≡id
( left-inverse-of
, left-inverse-of
, [ (λ a₁ a₂ →
get-set (l⁻¹ ∘ l) a₁ a₂ ≡⟨⟩
trans (cong from (get-set l a₁ (to a₂)))
(get-set l⁻¹ (get l a₁) a₂) ≡⟨⟩
trans (cong from (right-inverse-of (to a₂)))
(left-inverse-of a₂) ≡⟨ cong (λ eq → trans (cong from eq) (left-inverse-of _)) $ sym $
left-right-lemma _ ⟩
trans (cong from (cong (get l) (left-inverse-of a₂)))
(left-inverse-of a₂) ≡⟨ cong (λ eq → trans eq (left-inverse-of _)) $
cong-∘ _ _ (left-inverse-of _) ⟩
trans (cong (from ⊚ get l) (left-inverse-of a₂))
(left-inverse-of a₂) ≡⟨⟩
trans (cong (get (l⁻¹ ∘ l)) (left-inverse-of a₂))
(left-inverse-of a₂) ∎)
, (λ a →
let lemma₁ =
cong from
(trans (sym (cong (get l)
(set-get l (from (get l a)))))
(trans (right-inverse-of _)
(right-inverse-of _))) ≡⟨ cong-trans _ _ (trans _ (right-inverse-of _)) ⟩
trans (cong from (sym (cong (get l)
(set-get l (from (get l a))))))
(cong from (trans (right-inverse-of _)
(right-inverse-of _))) ≡⟨ cong (λ eq → trans (cong from eq)
(cong from (trans (right-inverse-of _)
(right-inverse-of _)))) $ sym $
cong-sym _ (set-get l (from (get l a))) ⟩
trans (cong from (cong (get l)
(sym (set-get l (from (get l a))))))
(cong from (trans (right-inverse-of _)
(right-inverse-of _))) ≡⟨ cong₂ trans
(cong-∘ _ _ (sym (set-get l (from (get l a)))))
(cong-trans _ _ (right-inverse-of _)) ⟩
trans (cong (from ⊚ get l)
(sym (set-get l (from (get l a)))))
(trans (cong from (right-inverse-of _))
(cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p q → trans (cong (from ⊚ get l)
(sym (set-get l (from (get l a)))))
(trans p q))
(right-left-lemma _)
(right-left-lemma _) ⟩∎
trans (cong (from ⊚ get l)
(sym (set-get l (from (get l a)))))
(trans (left-inverse-of _)
(left-inverse-of _)) ∎
f = from ⊚ get l
lemma₂ : ∀ _ → _
lemma₂ = λ a →
trans (left-inverse-of (f a))
(left-inverse-of a) ≡⟨ cong (λ g → trans (g (f a)) (g a)) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext)
left-inverse-of ⟩∎
trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a))
(ext⁻¹ (⟨ext⟩ left-inverse-of) a) ∎
lemma₃ =
trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ≡⟨ cong₂ trans (ext⁻¹-refl _) (ext⁻¹-refl _) ⟩
trans (refl _) (refl _) ≡⟨ trans-refl-refl ⟩∎
refl _ ∎
in
trans (cong from (set-get l⁻¹ (get l a)))
(set-get l a) ≡⟨⟩
trans (cong from
(trans (sym (cong (get l)
(set-get l (from (get l a)))))
(trans (right-inverse-of _)
(right-inverse-of _))))
(set-get l a) ≡⟨ cong (λ eq → trans eq (set-get l a)) lemma₁ ⟩
trans (trans (cong f (sym (set-get l (f a))))
(trans (left-inverse-of (f (f a)))
(left-inverse-of (f a))))
(set-get l a) ≡⟨ cong (λ eq → trans (trans (cong f (sym (set-get l (f a)))) eq)
(set-get l a)) $
lemma₂ _ ⟩
trans (trans (cong f (sym (set-get l (f a))))
(trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f (f a)))
(ext⁻¹ (⟨ext⟩ left-inverse-of) (f a))))
(set-get l a) ≡⟨ elim₁
(λ {f} (p : f ≡ P.id) →
(q : ∀ a → f a ≡ a) →
trans (trans (cong f (sym (q (f a))))
(trans (ext⁻¹ p (f (f a))) (ext⁻¹ p (f a))))
(q a) ≡
trans (ext⁻¹ p (f a)) (ext⁻¹ p a))
(λ q →
trans (trans (cong P.id (sym (q a)))
(trans (ext⁻¹ (refl P.id) a)
(ext⁻¹ (refl P.id) a)))
(q a) ≡⟨ cong₂ (λ p r → trans (trans p r) (q a))
(sym $ cong-id _)
lemma₃ ⟩
trans (trans (sym (q a)) (refl _)) (q a) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩
trans (sym (q a)) (q a) ≡⟨ trans-symˡ (q a) ⟩
refl _ ≡⟨ sym lemma₃ ⟩∎
trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ∎)
(⟨ext⟩ left-inverse-of)
(set-get l) ⟩
trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a))
(ext⁻¹ (⟨ext⟩ left-inverse-of) a) ≡⟨ sym $ lemma₂ _ ⟩
trans (left-inverse-of (f a))
(left-inverse-of a) ≡⟨⟩
trans (left-inverse-of (get (l⁻¹ ∘ l) a))
(left-inverse-of a) ∎)
, (λ a a₁ a₂ →
let q = set-set l a (get l a₁) (get l a₂)
lemma =
cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l) q))
(right-inverse-of _))) ≡⟨ cong-trans _ _ (trans (sym (cong (get l) q)) (right-inverse-of _)) ⟩
trans (cong from (sym (right-inverse-of _)))
(cong from (trans (sym (cong (get l) q))
(right-inverse-of _))) ≡⟨ cong₂ trans
(cong-sym _ (right-inverse-of _))
(cong-trans _ _ (right-inverse-of _)) ⟩
trans (sym (cong from (right-inverse-of _)))
(trans (cong from (sym (cong (get l) q)))
(cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p r → trans (sym p) (trans (cong from (sym (cong (get l) q))) r))
(right-left-lemma _)
(right-left-lemma _) ⟩
trans (sym (left-inverse-of _))
(trans (cong from (sym (cong (get l) q)))
(left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _))
(trans eq (left-inverse-of _))) $
cong-sym _ (cong (get l) q) ⟩
trans (sym (left-inverse-of _))
(trans (sym (cong from (cong (get l) q)))
(left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _))
(trans (sym eq) (left-inverse-of _))) $
cong-∘ _ _ q ⟩
trans (sym (left-inverse-of _))
(trans (sym (cong (from ⊚ get l) q))
(left-inverse-of _)) ≡⟨ cong (λ g → trans (sym (g _))
(trans (sym (cong (from ⊚ get l) q)) (g _))) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext)
left-inverse-of ⟩∎
trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) _))
(trans (sym (cong (from ⊚ get l) q))
(ext⁻¹ (⟨ext⟩ left-inverse-of) _)) ∎
f = from ⊚ get l
in
set-set (l⁻¹ ∘ l) a a₁ a₂ ≡⟨⟩
trans (set-set l a (get l a₁) (get l a₂))
(trans (cong (λ _ → from (get l a₂))
(right-inverse-of (get l a₁)))
(cong from (set-set l⁻¹ (get l a) a₁ a₂))) ≡⟨ cong (trans _) $
trans (cong (flip trans _) $ cong-const _) $
trans-reflˡ _ ⟩
trans (set-set l a (get l a₁) (get l a₂))
(cong from (set-set l⁻¹ (get l a) a₁ a₂)) ≡⟨⟩
trans (set-set l a (get l a₁) (get l a₂))
(cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from (get l a))
(get l a₁) (get l a₂))))
(right-inverse-of _)))) ≡⟨ cong (λ a′ → trans q
(cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l a′ (get l a₁) (get l a₂))))
(right-inverse-of _))))) $
left-inverse-of _ ⟩
trans q
(cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l) q))
(right-inverse-of _)))) ≡⟨ cong (trans q) lemma ⟩
trans q
(trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))
(trans (sym (cong f q))
(ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))) ≡⟨ elim₁
(λ {f} (p : f ≡ P.id) →
(q : f a₂ ≡ f a₂) →
trans q
(trans (sym (ext⁻¹ p (f a₂)))
(trans (sym (cong f q))
(ext⁻¹ p (f a₂)))) ≡
refl _)
(λ q →
trans q
(trans (sym (ext⁻¹ (refl P.id) a₂))
(trans (sym (cong P.id q))
(ext⁻¹ (refl P.id) a₂))) ≡⟨ cong (λ eq → trans q (trans (sym eq)
(trans (sym (cong P.id q)) eq))) $
ext⁻¹-refl _ ⟩
trans q (trans (sym (refl _))
(trans (sym (cong P.id q)) (refl _))) ≡⟨ cong₂ (λ p r → trans q (trans p r))
sym-refl
(trans-reflʳ _) ⟩
trans q (trans (refl _) (sym (cong P.id q))) ≡⟨ cong (trans q) $ trans-reflˡ (sym (cong P.id q)) ⟩
trans q (sym (cong P.id q)) ≡⟨ cong (λ eq → trans q (sym eq)) $ sym $ cong-id q ⟩
trans q (sym q) ≡⟨ trans-symʳ q ⟩∎
refl _ ∎)
(⟨ext⟩ left-inverse-of)
q ⟩
refl _ ∎)
]
)
-- There is an equivalence with erased proofs between "l is
-- bi-invertible (with erased proofs) " and "the getter of l is an
-- equivalence (with erased proofs)".
Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get :
(l : Lens A B) →
Is-bi-invertibleᴱ l ≃ᴱ Is-equivalenceᴱ (Lens.get l)
Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get l = EEq.⇔→≃ᴱ
(BM.Is-bi-invertibleᴱ-propositional l)
(EEq.Is-equivalenceᴱ-propositional ext _)
(Is-bi-invertibleᴱ→Is-equivalenceᴱ-get l)
(Is-equivalenceᴱ-get→Is-bi-invertibleᴱ l)
-- There is in general no split surjection from equivalences (with
-- erased proofs) to lenses that are bi-invertible (with erased
-- proofs), if the right-to-left direction of the split surjection is
-- required to map bi-invertible lenses to their getter functions
-- (assuming univalence).
¬≃ᴱ↠≊ᴱ :
@0 Univalence lzero →
¬ ∃ λ (≃ᴱ↠≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) →
(x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) →
_≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ x) ≡ Lens.get l
¬≃ᴱ↠≊ᴱ {a = a} univ =
Stable-¬
[ (∃ λ (≃ᴱ↠≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) →
(x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) →
_≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ x) ≡ Lens.get l) ↝⟨ Σ-map
((∃-cong λ l → _≃_.surjection $ EEq.≃ᴱ→≃ $ Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get l) F.∘_)
(λ hyp _ → hyp _) ⟩
(∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠
(∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) →
Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ ⟩□
⊥ □
]
-- There is in general no equivalence with erased proofs between
-- equivalences (with erased proofs) and lenses that are bi-invertible
-- (with erased proofs), if the right-to-left direction of the
-- equivalence is required to map bi-invertible lenses to their getter
-- functions (assuming univalence).
¬≃ᴱ≃ᴱ≊ᴱ :
@0 Univalence lzero →
¬ ∃ λ (≃ᴱ≃ᴱ≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) →
(x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) →
_≃ᴱ_.to (_≃ᴱ_.from ≃ᴱ≃ᴱ≊ᴱ x) ≡ Lens.get l
¬≃ᴱ≃ᴱ≊ᴱ {a = a} univ =
Stable-¬
[ (∃ λ (≃ᴱ≃ᴱ≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) →
(x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) →
_≃ᴱ_.to (_≃ᴱ_.from ≃ᴱ≃ᴱ≊ᴱ x) ≡ Lens.get l) ↝⟨ Σ-map (_≃_.surjection ⊚ EEq.≃ᴱ→≃) P.id ⟩
(∃ λ (≃ᴱ↠≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) →
(x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) →
_≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ x) ≡ Lens.get l) ↝⟨ ¬≃ᴱ↠≊ᴱ univ ⟩□
⊥ □
]
-- The lemma ≃ᴱΣ∥set⁻¹ᴱ∥ᴱ× does not hold in general if the requirement
-- that A is a set is dropped (assuming univalence).
≄ᴱΣ∥set⁻¹ᴱ∥ᴱ× :
@0 Univalence lzero →
¬ ({A B : Type a} (l : Lens A B) →
A ≃ᴱ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B))
≄ᴱΣ∥set⁻¹ᴱ∥ᴱ× {a = a} univ =
Stable-¬
[ ({A B : Type a} (l : Lens A B) →
A ≃ᴱ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B)) ↝⟨ EEq.≃ᴱ→≃ ⊚_ ⟩
({A B : Type a} (l : Lens A B) →
A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B)) ↝⟨ ((×-cong₁ λ _ → ∃-cong λ _ → PT.∥∥ᴱ≃∥∥) F.∘_) ⊚_ ⟩
({A B : Type a} (l : Lens A B) →
A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥) × B)) ↝⟨ ((×-cong₁ λ _ → ∃-cong λ _ → PT.∥∥-cong $ inverse ECP.⁻¹≃⁻¹ᴱ) F.∘_) ⊚_ ⟩
({A B : Type a} (l : Lens A B) →
A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)) ↝⟨ _⊚ Traditional-lens→Lens ⟩
({A B : Type a} (l : T.Lens A B) →
A ≃ ((∃ λ (f : B → A) → ∥ T.Lens.set l ⁻¹ f ∥) × B)) ↝⟨ TC.≄Σ∥set⁻¹∥× univ ⟩□
⊥ □
]
| 46.827361
| 162
| 0.367044
|
39b16c47487944411df07d9a9eb5cd8975c8cd84
| 1,512
|
agda
|
Agda
|
src/LibraBFT/Impl/Types/OnChainConfig/ValidatorSet.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Types/OnChainConfig/ValidatorSet.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Types/OnChainConfig/ValidatorSet.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.ImplShared.Consensus.Types
open import Optics.All
open import Util.KVMap as Map hiding (empty)
open import Util.Prelude
module LibraBFT.Impl.Types.OnChainConfig.ValidatorSet where
new : List ValidatorInfo → ValidatorSet
new = ValidatorSet∙new ConsensusScheme∙new
empty : ValidatorSet
empty = new []
obmFromVV : ValidatorVerifier → ValidatorSet
obmFromVV vv0 = record -- ValidatorSet
{ _vsScheme = ConsensusScheme∙new -- TODO
; _vsPayload = fmap go (Map.toList (vv0 ^∙ vvAddressToValidatorInfo))
}
where
go : (Author × ValidatorConsensusInfo) → ValidatorInfo
go (address , ValidatorConsensusInfo∙new pk vp) =
record -- ValidatorInfo
{ _viAccountAddress = address
; _viConsensusVotingPower = vp
; _viConfig = record -- ValidatorConfig
{ _vcConsensusPublicKey = pk
; _vcValidatorNetworkAddress = address ^∙ aAuthorName } }
obmGetValidatorInfo : AuthorName → ValidatorSet → Either ErrLog ValidatorInfo
obmGetValidatorInfo name vs =
case List-filter (λ vi → vi ^∙ viAccountAddress ∙ aAuthorName ≟ name) (vs ^∙ vsPayload) of λ where
(vi ∷ []) → pure vi
_ → Left fakeErr -- ["ValidatorSet", "obmGetValidatorInfo", "TODO better err msg"]
| 37.8
| 111
| 0.712302
|
1082ee82cdb41af2d144990b812cf3699696e64c
| 9,048
|
agda
|
Agda
|
homotopy/JoinAssoc2.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/JoinAssoc2.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/JoinAssoc2.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
-- Associativity of the join (work in progress)
module homotopy.JoinAssoc2 where
import homotopy.JoinAssoc as Assoc
module Assoc2 {i j k} (A : Type i) (B : Type j) (C : Type k) where
open Assoc A B C
{- Here are the steps, without the junk around:
apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))
1 (From.glue-β)
apd (λ x → ap to (from-glue (a , x))) (glue (b , c))
2 (unfuse)
ap↓ (λ x → ap to {x = from-left a} {y = from-right x}) (apd (λ x → from-glue (a , x)) (glue (b , c)))
3 (FromGlue.glue-β)
ap↓ (λ x → ap to {x = from-left a} {y = from-right x}) (apd (λ x → glue (x , c)) (glue (a , b)))
4 (fuse)
apd (λ x → ap to (glue (x , c))) (glue (a , b))
5 (To.glue-β)
apd (λ x → to-glue (x , c)) (glue (a , b))
6 (ToGlue.glue-β)
apd (λ x → glue (a , x)) (glue (b , c))
-}
to-from-glue-glue' : (a : A) (b : B) (c : C)
→ (↯ to-from-glue-left' a b) == (↯ to-from-glue-right' a c) [ (λ x → ap to (ap from (glue (a , x))) ∙' to-from-right x == glue (a , x)) ↓ glue (b , c) ]
to-from-glue-glue' a b c =
↓-=-in (!(
apd (λ x → ap to (ap from (glue (a , x))) ∙' to-from-right x) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)
=⟨ apd∙' (λ x → ap to (ap from (glue (a , x)))) to-from-right (glue (b , c)) |in-ctx (λ u → u ▹ (↯ to-from-glue-right' a c)) ⟩
((apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) ∙'2ᵈ (apd to-from-right (glue (b , c)))) ▹ (↯ to-from-glue-right' a c)
=⟨ ToFromRight.glue-β (b , c) |in-ctx
(λ u → ((apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) ∙'2ᵈ u) ▹ (↯ to-from-glue-right' a c)) ⟩
((apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) ∙'2ᵈ (to-from-right-glue (b , c))) ▹ (↯ to-from-glue-right' a c)
=⟨ ▹-∙'2ᵈ (apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) (to-from-right-glue (b , c)) (↯ to-from-glue-right' a c) idp ⟩
(apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)) ∙'2ᵈ (to-from-right-glue (b , c) ▹ idp)
=⟨ (▹idp (to-from-right-glue (b , c))) |in-ctx (λ u → (apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)) ∙'2ᵈ u) ⟩
(apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ apd=-red (λ x → ap (ap to) (From.glue-β (a , x))) (glue (b , c)) (1! (to-from-glue-right' a c)) |in-ctx (λ u → u ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 1 -}
((↯ 1# (to-from-glue-left' a b)) ◃ (apd (λ x → ap to (from-glue (a , x))) (glue (b , c)) ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ apd-∘' (ap to) (λ x → from-glue (a , x)) (glue (b , c)) |in-ctx (λ u → ((↯ 1# (to-from-glue-left' a b)) ◃ (u ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 2 -}
((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) (apd (λ x → from-glue (a , x)) (glue (b , c))) ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ FromGlue.glue-β a (b , c) |in-ctx (λ u → ((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) u ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 3 -}
((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) (from-glue-glue a (b , c)) ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ idp ⟩
((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) (↓-swap! left from-right _ idp
(apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ Ap↓-swap!.β to left from-right _ idp (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c)))
|in-ctx (λ u → ((↯ 1# (to-from-glue-left' a b)) ◃ (u ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
((↯ 1# (to-from-glue-left' a b)) ◃ (((ap (λ u → u) (∘-ap to left (glue (a , b)))) ◃ ↓-swap! (to ∘ left) (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ ap-idf (∘-ap to left (glue (a , b))) |in-ctx (λ v → ((↯ 1# (to-from-glue-left' a b)) ◃ ((v ◃ ↓-swap! (to ∘ left) (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
((↯ 1# (to-from-glue-left' a b)) ◃ (((∘-ap to left (glue (a , b))) ◃ ↓-swap! (to ∘ left) (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ {!!} ⟩
((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ ap↓-▹! (ap to) (apd (λ x → glue (x , c)) (glue (a , b))) (FromRight.glue-β (b , c)) |in-ctx (λ v → ((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp (v ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b))) ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ ∘'-apd (ap to) (λ x → glue (x , c)) (glue (a , b)) |in-ctx (λ v → ((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((v ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 4 -}
((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((apd (λ x → ap to (glue (x , c))) (glue (a , b)) ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ {!!} ⟩
{- 5 -}
-- ((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((apd (λ x → to-glue (x , c)) (glue (a , b)) ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
-- ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
-- =⟨ {!!} ⟩
-- {- 5 -}
-- (↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp (To.glue-β (left a , c) !◃ (apd (λ x → ap to (glue (x , c))) (glue (a , b)) ▹ To.glue-β (right b , c))))
-- =⟨ {!!} ⟩
(↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp (apd (λ x → to-glue (x , c)) (glue (a , b))))
=⟨ ToGlue.glue-β c (a , b) |in-ctx (λ v → (↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp v)) ⟩
{- 6 -}
(↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp (to-glue-glue c (a , b)))
=⟨ ↓-swap-β to-left right {p = glue (a , b)} (to-glue-left c a) idp (ToLeft.glue-β (a , b) ◃ apd (λ x → glue (a , x)) (glue (b , c))) |in-ctx (λ v → (↯ 2# (to-from-glue-left' a b)) ◃ v) ⟩
(↯ 2# (to-from-glue-left' a b)) ◃ (ToLeft.glue-β (a , b) ◃ apd (λ x → glue (a , x)) (glue (b , c)))
=⟨ {!!} ⟩ -- associativity
(↯ to-from-glue-left' a b) ◃ apd (λ x → glue (a , x)) (glue (b , c)) ∎))
-- ((↓-apd-out (λ a' _ → to (from (left a)) == to (from (right a'))) (λ x → glue (a , x)) (glue (b , c)) (apdd (ap to ∘ ap from) (glue (b , c)) (apd (λ x → (glue (a , x))) (glue (b , c))))) ∙'2ᵈ (to-from-right-glue (b , c))) ▹ to-from-glue-right' a c =⟨ {!!} ⟩
-- to-from-glue-glue : (a : A) (bc : B × C)
-- → to-from-glue-left a (fst bc) == to-from-glue-right a (snd bc) [ (λ x → to-from-left a == to-from-right x [ (λ y → to (from y) == y) ↓ glue (a , x) ]) ↓ glue bc ]
-- to-from-glue-glue a (b , c) = {!!} -- Should not be too hard
-- to-from-glue : (x : A × (B * C)) → to-from-left (fst x) == to-from-right (snd x) [ (λ x → to (from x) == x) ↓ glue x ]
-- to-from-glue (a , bc) = pushout-rec (to-from-glue-left a) (to-from-glue-right a) (to-from-glue-glue a) bc
-- to-from : (x : A * (B * C)) → to (from x) == x
-- to-from = pushout-rec to-from-left to-from-right to-from-glue
-- *-assoc : (A * B) * C ≃ A * (B * C)
-- *-assoc = equiv to from to-from from-to
| 74.77686
| 294
| 0.463859
|
4de95f093dd9c0fa96e1a300d30cec9c19e6309e
| 6,932
|
agda
|
Agda
|
Nested.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | 1
|
2021-02-13T14:48:45.000Z
|
2021-02-13T14:48:45.000Z
|
Nested.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
Nested.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Nested applications of the defined function can be handled
------------------------------------------------------------------------
module Nested where
open import Codata.Musical.Notation
open import Codata.Musical.Stream
open import Function
import Relation.Binary.PropositionalEquality as P
------------------------------------------------------------------------
-- A definition of φ (x ∷ xs) = x ∷ φ (φ xs)
module φ where
infixr 5 _∷_
data StreamP (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (StreamP A)) → StreamP A
φP : (xs : StreamP A) → StreamP A
data StreamW (A : Set) : Set where
_∷_ : (x : A) (xs : StreamP A) → StreamW A
φW : {A : Set} → StreamW A → StreamW A
φW (x ∷ xs) = x ∷ φP (φP xs)
whnf : {A : Set} → StreamP A → StreamW A
whnf (x ∷ xs) = x ∷ ♭ xs
whnf (φP xs) = φW (whnf xs)
mutual
⟦_⟧W : {A : Set} → StreamW A → Stream A
⟦ x ∷ xs ⟧W = x ∷ ♯ ⟦ xs ⟧P
⟦_⟧P : {A : Set} → StreamP A → Stream A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
⌈_⌉ : {A : Set} → Stream A → StreamP A
⌈ x ∷ xs ⌉ = x ∷ ♯ ⌈ ♭ xs ⌉
φ : {A : Set} → Stream A → Stream A
φ xs = ⟦ φP ⌈ xs ⌉ ⟧P
open φ using (⟦_⟧P; ⟦_⟧W; φP; φW; φ; _∷_; ⌈_⌉)
------------------------------------------------------------------------
-- An equality proof language
module Equality where
φ-rhs : {A : Set} → (Stream A → Stream A) → Stream A → Stream A
φ-rhs φ (x ∷ xs) = x ∷ ♯ φ (φ (♭ xs))
SatisfiesEquation : {A : Set} → (Stream A → Stream A) → Set
SatisfiesEquation φ = ∀ xs → φ xs ≈ φ-rhs φ xs
infixr 5 _∷_
infix 4 _≈P_ _≈W_
infix 3 _∎
infixr 2 _≈⟨_⟩_
data _≈P_ {A : Set} : Stream A → Stream A → Set where
_∷_ : ∀ (x : A) {xs ys}
(xs≈ys : ∞ (♭ xs ≈P ♭ ys)) → x ∷ xs ≈P x ∷ ys
_≈⟨_⟩_ : ∀ (xs : Stream A) {ys zs}
(xs≈ys : xs ≈P ys) (ys≈zs : ys ≈P zs) → xs ≈P zs
_∎ : (xs : Stream A) → xs ≈P xs
sym : ∀ {xs ys} (xs≈ys : xs ≈P ys) → ys ≈P xs
φP-cong : (xs ys : φ.StreamP A) (xs≈ys : ⟦ xs ⟧P ≈P ⟦ ys ⟧P) →
⟦ φP xs ⟧P ≈P ⟦ φP ys ⟧P
lemma : (φ₁ φ₂ : Stream A → Stream A)
(s₁ : SatisfiesEquation φ₁) (s₂ : SatisfiesEquation φ₂) →
∀ {xs ys} (xs≈ys : xs ≈P ys) → φ-rhs φ₁ xs ≈P φ-rhs φ₂ ys
-- Completeness.
completeP : {A : Set} {xs ys : Stream A} → xs ≈ ys → xs ≈P ys
completeP (P.refl ∷ xs≈ys) = _ ∷ ♯ completeP (♭ xs≈ys)
-- Weak head normal forms.
data _≈W_ {A : Set} : Stream A → Stream A → Set where
_∷_ : ∀ x {xs ys} (xs≈ys : ♭ xs ≈P ♭ ys) → x ∷ xs ≈W x ∷ ys
transW : {A : Set} {xs ys zs : Stream A} →
xs ≈W ys → ys ≈W zs → xs ≈W zs
transW (x ∷ xs≈ys) (.x ∷ ys≈zs) = x ∷ (_ ≈⟨ xs≈ys ⟩ ys≈zs)
reflW : {A : Set} (xs : Stream A) → xs ≈W xs
reflW (x ∷ xs) = x ∷ (♭ xs ∎)
symW : {A : Set} {xs ys : Stream A} → xs ≈W ys → ys ≈W xs
symW (x ∷ xs≈ys) = x ∷ sym xs≈ys
φW-cong : {A : Set} (xs ys : φ.StreamW A) →
⟦ xs ⟧W ≈W ⟦ ys ⟧W → ⟦ φW xs ⟧W ≈W ⟦ φW ys ⟧W
φW-cong (.x ∷ xs) (.x ∷ ys) (x ∷ xs≈ys) =
x ∷ φP-cong (φP xs) (φP ys) (φP-cong xs ys xs≈ys)
lemmaW : {A : Set} (φ₁ φ₂ : Stream A → Stream A)
(s₁ : SatisfiesEquation φ₁) (s₂ : SatisfiesEquation φ₂) →
∀ {xs ys} → xs ≈W ys → φ-rhs φ₁ xs ≈W φ-rhs φ₂ ys
lemmaW φ₁ φ₂ s₁ s₂ {.x ∷ xs} {.x ∷ ys} (x ∷ xs≈ys) = x ∷ (
φ₁ (φ₁ (♭ xs)) ≈⟨ completeP $ s₁ (φ₁ (♭ xs)) ⟩
φ-rhs φ₁ (φ₁ (♭ xs)) ≈⟨ lemma φ₁ φ₂ s₁ s₂ (
φ₁ (♭ xs) ≈⟨ completeP $ s₁ (♭ xs) ⟩
φ-rhs φ₁ (♭ xs) ≈⟨ lemma φ₁ φ₂ s₁ s₂ xs≈ys ⟩
φ-rhs φ₂ (♭ ys) ≈⟨ sym $ completeP $ s₂ (♭ ys) ⟩
φ₂ (♭ ys) ∎) ⟩
φ-rhs φ₂ (φ₂ (♭ ys)) ≈⟨ sym $ completeP $ s₂ (φ₂ (♭ ys)) ⟩
φ₂ (φ₂ (♭ ys)) ∎)
whnf : {A : Set} {xs ys : Stream A} → xs ≈P ys → xs ≈W ys
whnf (x ∷ xs≈ys) = x ∷ ♭ xs≈ys
whnf (xs ≈⟨ xs≈ys ⟩ ys≈zs) = transW (whnf xs≈ys) (whnf ys≈zs)
whnf (xs ∎) = reflW xs
whnf (sym xs≈ys) = symW (whnf xs≈ys)
whnf (lemma φ₁ φ₂ s₁ s₂ xs≈ys) = lemmaW φ₁ φ₂ s₁ s₂ (whnf xs≈ys)
whnf (φP-cong xs ys xs≈ys) =
φW-cong (φ.whnf xs) (φ.whnf ys) (whnf xs≈ys)
-- Soundness.
mutual
soundW : {A : Set} {xs ys : Stream A} → xs ≈W ys → xs ≈ ys
soundW (x ∷ xs≈ys) = P.refl ∷ ♯ soundP xs≈ys
soundP : {A : Set} {xs ys : Stream A} → xs ≈P ys → xs ≈ ys
soundP xs≈ys = soundW (whnf xs≈ys)
open Equality
using (_≈P_; _∷_; _≈⟨_⟩_; _∎; sym; φP-cong; φ-rhs; SatisfiesEquation)
------------------------------------------------------------------------
-- Correctness
module Correctness where
-- Uniqueness of solutions for φ's defining equation.
φ-unique : {A : Set} (φ₁ φ₂ : Stream A → Stream A) →
SatisfiesEquation φ₁ → SatisfiesEquation φ₂ →
∀ xs → φ₁ xs ≈P φ₂ xs
φ-unique φ₁ φ₂ hyp₁ hyp₂ xs =
φ₁ xs ≈⟨ Equality.completeP (hyp₁ xs) ⟩
φ-rhs φ₁ xs ≈⟨ Equality.lemma φ₁ φ₂ hyp₁ hyp₂ (xs ∎) ⟩
φ-rhs φ₂ xs ≈⟨ sym (Equality.completeP (hyp₂ xs)) ⟩
φ₂ xs ∎
-- The remainder of this module establishes the existence of a
-- solution.
⟦⌈_⌉⟧P : {A : Set} (xs : Stream A) → ⟦ ⌈ xs ⌉ ⟧P ≈P xs
⟦⌈ x ∷ xs ⌉⟧P = x ∷ ♯ ⟦⌈ ♭ xs ⌉⟧P
φ-cong : {A : Set} (xs ys : Stream A) → xs ≈P ys → φ xs ≈P φ ys
φ-cong xs ys xs≈ys =
φ xs ≈⟨ φ xs ∎ ⟩
⟦ φP ⌈ xs ⌉ ⟧P ≈⟨ φP-cong ⌈ xs ⌉ ⌈ ys ⌉ lemma ⟩
⟦ φP ⌈ ys ⌉ ⟧P ≈⟨ φ ys ∎ ⟩
φ ys ∎
where
lemma =
⟦ ⌈ xs ⌉ ⟧P ≈⟨ ⟦⌈ xs ⌉⟧P ⟩
xs ≈⟨ xs≈ys ⟩
ys ≈⟨ sym ⟦⌈ ys ⌉⟧P ⟩
⟦ ⌈ ys ⌉ ⟧P ∎
-- ♯′ provides a workaround for Agda's strange definitional
-- equality.
infix 10 ♯′_
♯′_ : {A : Set} → A → ∞ A
♯′ x = ♯ x
φW-hom : {A : Set} (xs : φ.StreamW A) →
⟦ φW xs ⟧W ≈P head ⟦ xs ⟧W ∷ ♯′ φ (φ (tail ⟦ xs ⟧W))
φW-hom (x ∷ xs) = x ∷ ♯ (
⟦ φP (φP xs) ⟧P ≈⟨ φP-cong (φP xs) (φP ⌈ ⟦ xs ⟧P ⌉) $
φP-cong xs (⌈ ⟦ xs ⟧P ⌉)
(sym ⟦⌈ ⟦ xs ⟧P ⌉⟧P) ⟩
⟦ φP (φP ⌈ ⟦ xs ⟧P ⌉) ⟧P ≈⟨ φP-cong (φP ⌈ ⟦ xs ⟧P ⌉)
⌈ ⟦ φP ⌈ ⟦ xs ⟧P ⌉ ⟧P ⌉
(sym ⟦⌈ ⟦ φP ⌈ ⟦ xs ⟧P ⌉ ⟧P ⌉⟧P) ⟩
⟦ φP ⌈ ⟦ φP ⌈ ⟦ xs ⟧P ⌉ ⟧P ⌉ ⟧P ∎)
φ-hom : {A : Set} (xs : φ.StreamP A) →
⟦ φP xs ⟧P ≈P head ⟦ xs ⟧P ∷ ♯′ φ (φ (tail ⟦ xs ⟧P))
φ-hom xs = φW-hom (φ.whnf xs)
φ-correct : {A : Set} (xs : Stream A) →
φ xs ≈P φ-rhs φ xs
φ-correct (x ∷ xs) =
φ (x ∷ xs) ≈⟨ φ (x ∷ xs) ∎ ⟩
⟦ φP ⌈ x ∷ xs ⌉ ⟧P ≈⟨ φ-hom ⌈ x ∷ xs ⌉ ⟩
x ∷ ♯′ φ (φ ⟦ ⌈ ♭ xs ⌉ ⟧P) ≈⟨ x ∷ ♯ φ-cong (φ ⟦ ⌈ ♭ xs ⌉ ⟧P) (φ (♭ xs))
(φ-cong (⟦ ⌈ ♭ xs ⌉ ⟧P) (♭ xs) ⟦⌈ ♭ xs ⌉⟧P) ⟩
φ-rhs φ (x ∷ xs) ∎
| 33.980392
| 93
| 0.420514
|
1cdb0390c7d2d10f8d31e0be658a01c90160aa15
| 7,485
|
agda
|
Agda
|
core/lib/types/Nat.agda
|
maxdore/hott-morse
|
01bbd8841f9b9b25666b91e65b196d8f472b9978
|
[
"MIT"
] | null | null | null |
core/lib/types/Nat.agda
|
maxdore/hott-morse
|
01bbd8841f9b9b25666b91e65b196d8f472b9978
|
[
"MIT"
] | null | null | null |
core/lib/types/Nat.agda
|
maxdore/hott-morse
|
01bbd8841f9b9b25666b91e65b196d8f472b9978
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.Function
open import lib.NType
open import lib.PathGroupoid
open import lib.Relation
open import lib.types.Bool
open import lib.types.Coproduct
open import lib.types.Empty
open import lib.types.Sigma
module lib.types.Nat where
infixl 80 _+_
_+_ : ℕ → ℕ → ℕ
0 + n = n
(S m) + n = S (m + n)
{-# BUILTIN NATPLUS _+_ #-}
abstract
+-unit-r : (m : ℕ) → m + 0 == m
+-unit-r 0 = idp
+-unit-r (S m) = ap S (+-unit-r m)
+-βr : (m n : ℕ) → m + (S n) == S (m + n)
+-βr 0 n = idp
+-βr (S m) n = ap S (+-βr m n)
+-comm : (m n : ℕ) → m + n == n + m
+-comm m 0 = +-unit-r m
+-comm m (S n) = +-βr m n ∙ ap S (+-comm m n)
+-assoc : (k m n : ℕ) → (k + m) + n == k + (m + n)
+-assoc 0 m n = idp
+-assoc (S k) m n = ap S (+-assoc k m n)
-- the [+] is like [ℕ-S^]
ℕ-S^' : ℕ → ℕ → ℕ
ℕ-S^' O n = n
ℕ-S^' (S m) n = ℕ-S^' m (S n)
ℕ-pred : ℕ → ℕ
ℕ-pred 0 = 0
ℕ-pred (S n) = n
abstract
ℕ-S-is-inj : is-inj (S :> (ℕ → ℕ))
ℕ-S-is-inj n m p = ap ℕ-pred p
ℕ-S-≠ : ∀ {n m : ℕ} (p : n ≠ m) → S n ≠ S m :> ℕ
ℕ-S-≠ {n} {m} p = p ∘ ℕ-S-is-inj n m
private
ℕ-S≠O-type : ℕ → Type₀
ℕ-S≠O-type O = Empty
ℕ-S≠O-type (S n) = Unit
ℕ-S≠O : (n : ℕ) → S n ≠ O
ℕ-S≠O n p = transport ℕ-S≠O-type p unit
ℕ-O≠S : (n : ℕ) → (O ≠ S n)
ℕ-O≠S n p = ℕ-S≠O n (! p)
ℕ-has-dec-eq : has-dec-eq ℕ
ℕ-has-dec-eq O O = inl idp
ℕ-has-dec-eq O (S n) = inr (ℕ-O≠S n)
ℕ-has-dec-eq (S n) O = inr (ℕ-S≠O n)
ℕ-has-dec-eq (S n) (S m) with ℕ-has-dec-eq n m
ℕ-has-dec-eq (S n) (S m) | inl p = inl (ap S p)
ℕ-has-dec-eq (S n) (S m) | inr ¬p = inr (ℕ-S-≠ ¬p)
ℕ-is-set : is-set ℕ
ℕ-is-set = dec-eq-is-set ℕ-has-dec-eq
instance
ℕ-level : {n : ℕ₋₂} → has-level (S (S n)) ℕ
ℕ-level {⟨-2⟩} = ℕ-is-set
ℕ-level {n = S n} = raise-level (S (S n)) ℕ-level
+-0 : ∀ (m n : ℕ) → m + n == 0 → (m == 0) × (n == 0)
+-0 O O _ = idp , idp
+-0 O (S n) h = ⊥-elim (ℕ-S≠O n h)
+-0 (S m) n h = ⊥-elim (ℕ-S≠O (m + n) h)
even : ℕ → Bool
even O = true
even (S n) = negate (even n)
odd : ℕ → Bool
odd = negate ∘ even
{- Inequalities -}
infix 40 _<_ _≤_
data _<_ : ℕ → ℕ → Type₀ where
ltS : {m : ℕ} → m < (S m)
ltSR : {m n : ℕ} → m < n → m < (S n)
_≤_ : ℕ → ℕ → Type₀
m ≤ n = Coprod (m == n) (m < n)
-- experimental: [lteE] [lteS] [lteSR]
lteE : {m : ℕ} → m ≤ m
lteE = inl idp
lteS : {m : ℕ} → m ≤ S m
lteS = inr ltS
lteSR : {m n : ℕ} → m ≤ n → m ≤ (S n)
lteSR (inl idp) = lteS
lteSR (inr lt) = inr (ltSR lt)
-- properties of [<]
O<S : (m : ℕ) → O < S m
O<S O = ltS
O<S (S m) = ltSR (O<S m)
O≤ : (m : ℕ) → O ≤ m
O≤ O = inl idp
O≤ (S m) = inr (O<S m)
≮O : ∀ n → ¬ (n < O)
≮O _ ()
S≰O : ∀ n → ¬ (S n ≤ O)
S≰O _ (inl ())
S≰O _ (inr ())
<-trans : {m n k : ℕ} → m < n → n < k → m < k
<-trans lt₁ ltS = ltSR lt₁
<-trans lt₁ (ltSR lt₂) = ltSR (<-trans lt₁ lt₂)
≤-refl : {m : ℕ} → m ≤ m
≤-refl = lteE
≤-trans : {m n k : ℕ} → m ≤ n → n ≤ k → m ≤ k
≤-trans (inl idp) lte₂ = lte₂
≤-trans lte₁@(inr _) (inl idp) = lte₁
≤-trans (inr lt₁) (inr lt₂) = inr (<-trans lt₁ lt₂)
private
test₀ : {m n : ℕ} (m≤n : m ≤ n) → lteSR m≤n == ≤-trans m≤n lteS
test₀ (inl idp) = idp
test₀ (inr lt) = idp
<-ap-S : {m n : ℕ} → m < n → S m < S n
<-ap-S ltS = ltS
<-ap-S (ltSR lt) = ltSR (<-ap-S lt)
≤-ap-S : {m n : ℕ} → m ≤ n → S m ≤ S n
≤-ap-S (inl p) = inl (ap S p)
≤-ap-S (inr lt) = inr (<-ap-S lt)
<-cancel-S : {m n : ℕ} → S m < S n → m < n
<-cancel-S ltS = ltS
<-cancel-S (ltSR lt) = <-trans ltS lt
<-ap-S-right : {m n : ℕ} → m < n → m < S n
<-ap-S-right x = ltSR x
<-weaken-S : {m n : ℕ} → S m < n → m < n
<-weaken-S ltS = ltSR ltS
<-weaken-S (ltSR x) = ltSR (<-weaken-S x)
<-cancel-S-left : {m n : ℕ} → S m < S n → m < S n
<-cancel-S-left ltS = ltSR ltS
<-cancel-S-left (ltSR p) = ltSR (<-weaken-S p)
≤-cancel-S : {m n : ℕ} → S m ≤ S n → m ≤ n
≤-cancel-S (inl p) = inl (ap ℕ-pred p)
≤-cancel-S (inr lt) = inr (<-cancel-S lt)
<-dec : Decidable _<_
<-dec _ O = inr (≮O _)
<-dec O (S m) = inl (O<S m)
<-dec (S n) (S m) with <-dec n m
<-dec (S n) (S m) | inl p = inl (<-ap-S p)
<-dec (S n) (S m) | inr ¬p = inr (¬p ∘ <-cancel-S)
≤-dec : Decidable _≤_
≤-dec O m = inl (O≤ m) -- important for the current cohomology development
≤-dec (S n) O = inr (S≰O n)
≤-dec (S n) (S m) with ≤-dec n m
≤-dec (S n) (S m) | inl p = inl (≤-ap-S p)
≤-dec (S n) (S m) | inr ¬p = inr (¬p ∘ ≤-cancel-S)
abstract
<-to-≠ : {m n : ℕ} → m < n → m ≠ n
<-to-≠ {m = O} ltS = ℕ-O≠S _
<-to-≠ {m = O} (ltSR lt) = ℕ-O≠S _
<-to-≠ {m = S m} {n = O} ()
<-to-≠ {m = S m} {n = S n} lt = ℕ-S-≠ (<-to-≠ (<-cancel-S lt))
<-to-≱ : {m n : ℕ} → m < n → ¬ (n ≤ m)
<-to-≱ m<n (inl idp) = <-to-≠ m<n idp
<-to-≱ m<n (inr n<m) = <-to-≠ (<-trans m<n n<m) idp
<-has-all-paths : {m n : ℕ} → has-all-paths (m < n)
<-has-all-paths = <-has-all-paths' idp where
<-has-all-paths' : {m n₁ n₂ : ℕ} (eqn : n₁ == n₂) (lt₁ : m < n₁) (lt₂ : m < n₂)
→ PathOver (λ n → m < n) eqn lt₁ lt₂
<-has-all-paths' eqn ltS ltS = transport (λ eqn₁ → PathOver (_<_ _) eqn₁ ltS ltS)
(prop-has-all-paths idp eqn) idp
<-has-all-paths' idp ltS (ltSR lt₂) = ⊥-rec (<-to-≠ lt₂ idp)
<-has-all-paths' idp (ltSR lt₁) ltS = ⊥-rec (<-to-≠ lt₁ idp)
<-has-all-paths' idp (ltSR lt₁) (ltSR lt₂) = ap ltSR (<-has-all-paths' idp lt₁ lt₂)
instance
<-is-prop : {m n : ℕ} → is-prop (m < n)
<-is-prop = all-paths-is-prop <-has-all-paths
≤-has-all-paths : {m n : ℕ} → has-all-paths (m ≤ n)
≤-has-all-paths = λ{
(inl eq₁) (inl eq₂) → ap inl (prop-has-all-paths eq₁ eq₂);
(inl eq) (inr lt) → ⊥-rec (<-to-≠ lt eq);
(inr lt) (inl eq) → ⊥-rec (<-to-≠ lt eq);
(inr lt₁) (inr lt₂) → ap inr (<-has-all-paths lt₁ lt₂)}
instance
≤-is-prop : {m n : ℕ} → is-prop (m ≤ n)
≤-is-prop = all-paths-is-prop ≤-has-all-paths
<-+-l : {m n : ℕ} (k : ℕ) → m < n → (k + m) < (k + n)
<-+-l O lt = lt
<-+-l (S k) lt = <-ap-S (<-+-l k lt)
≤-+-l : {m n : ℕ} (k : ℕ) → m ≤ n → (k + m) ≤ (k + n)
≤-+-l k (inl p) = inl (ap (λ t → k + t) p)
≤-+-l k (inr lt) = inr (<-+-l k lt)
<-+-r : {m n : ℕ} (k : ℕ) → m < n → (m + k) < (n + k)
<-+-r k ltS = ltS
<-+-r k (ltSR lt) = ltSR (<-+-r k lt)
≤-+-r : {m n : ℕ} (k : ℕ) → m ≤ n → (m + k) ≤ (n + k)
≤-+-r k (inl p) = inl (ap (λ t → t + k) p)
≤-+-r k (inr lt) = inr (<-+-r k lt)
<-witness : {m n : ℕ} → (m < n) → Σ ℕ (λ k → S k + m == n)
<-witness ltS = (O , idp)
<-witness (ltSR lt) = let w' = <-witness lt in (S (fst w') , ap S (snd w'))
≤-witness : {m n : ℕ} → (m ≤ n) → Σ ℕ (λ k → k + m == n)
≤-witness (inl p) = (O , p)
≤-witness (inr lt) = let w' = <-witness lt in (S (fst w') , snd w')
-- Double
infix 120 _*2
_*2 : ℕ → ℕ
O *2 = O
(S n) *2 = S (S (n *2))
*2-increasing : (m : ℕ) → (m ≤ m *2)
*2-increasing O = inl idp
*2-increasing (S m) = ≤-trans (≤-ap-S (*2-increasing m)) (inr ltS)
*2-monotone-< : {m n : ℕ} → m < n → m *2 < n *2
*2-monotone-< ltS = ltSR ltS
*2-monotone-< (ltSR lt) = ltSR (ltSR (*2-monotone-< lt))
*2-monotone-≤ : {m n : ℕ} → m ≤ n → m *2 ≤ n *2
*2-monotone-≤ (inl p) = inl (ap _*2 p)
*2-monotone-≤ (inr lt) = inr (*2-monotone-< lt)
-- Trichotomy
ℕ-trichotomy : (m n : ℕ) → (m == n) ⊔ ((m < n) ⊔ (n < m))
ℕ-trichotomy O O = inl idp
ℕ-trichotomy O (S n) = inr (inl (O<S n))
ℕ-trichotomy (S m) O = inr (inr (O<S m))
ℕ-trichotomy (S m) (S n) with ℕ-trichotomy m n
ℕ-trichotomy (S m) (S n) | inl m=n = inl (ap S m=n)
ℕ-trichotomy (S m) (S n) | inr (inl m<n) = inr (inl (<-ap-S m<n))
ℕ-trichotomy (S m) (S n) | inr (inr m>n) = inr (inr (<-ap-S m>n))
| 26.827957
| 87
| 0.476019
|
a1ccb9059f0c41de457aadd344d110c378062d53
| 3,841
|
agda
|
Agda
|
core/lib/types/Wedge.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
core/lib/types/Wedge.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/types/Wedge.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Pushout
open import lib.types.PushoutFlattening
open import lib.types.Span
open import lib.types.Unit
-- Wedge of two pointed types is defined as a particular case of pushout
module lib.types.Wedge where
module _ {i j} (X : Ptd i) (Y : Ptd j) where
wedge-span : Span
wedge-span = span (fst X) (fst Y) Unit (λ _ → snd X) (λ _ → snd Y)
Wedge : Type (lmax i j)
Wedge = Pushout wedge-span
infix 80 _∨_
_∨_ = Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
winl : fst X → X ∨ Y
winl x = left x
winr : fst Y → X ∨ Y
winr y = right y
wglue : winl (snd X) == winr (snd Y)
wglue = glue tt
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙Wedge : Ptd (lmax i j)
⊙Wedge = ⊙[ Wedge X Y , winl (snd X) ]
infix 80 _⊙∨_
_⊙∨_ = ⊙Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
⊙winl : fst (X ⊙→ X ⊙∨ Y)
⊙winl = (winl , idp)
⊙winr : fst (Y ⊙→ X ⊙∨ Y)
⊙winr = (winr , ! wglue)
module _ {i j} {X : Ptd i} {Y : Ptd j} where
module WedgeElim {k} {P : X ∨ Y → Type k}
(winl* : (x : fst X) → P (winl x)) (winr* : (y : fst Y) → P (winr y))
(wglue* : winl* (snd X) == winr* (snd Y) [ P ↓ wglue ]) where
private
module M = PushoutElim winl* winr* (λ _ → wglue*)
f = M.f
glue-β = M.glue-β unit
open WedgeElim public using () renaming (f to Wedge-elim)
module WedgeRec {k} {C : Type k} (winl* : fst X → C) (winr* : fst Y → C)
(wglue* : winl* (snd X) == winr* (snd Y)) where
private
module M = PushoutRec {d = wedge-span X Y} winl* winr* (λ _ → wglue*)
f = M.f
glue-β = M.glue-β unit
add-wglue : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ fst (X ⊙⊔ Y) → X ∨ Y
add-wglue (inl x) = winl x
add-wglue (inr y) = winr y
⊙add-wglue : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ fst (X ⊙⊔ Y ⊙→ X ⊙∨ Y)
⊙add-wglue = (add-wglue , idp)
module ⊙WedgeRec {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : fst (X ⊙→ Z)) (h : fst (Y ⊙→ Z)) where
open WedgeRec (fst g) (fst h) (snd g ∙ ! (snd h)) public
⊙f : fst (X ⊙∨ Y ⊙→ Z)
⊙f = (f , snd g)
⊙winl-β : ⊙f ⊙∘ ⊙winl == g
⊙winl-β = idp
⊙winr-β : ⊙f ⊙∘ ⊙winr == h
⊙winr-β = ⊙λ= (λ _ → idp) $
ap (λ w → w ∙ snd g)
(ap-! f wglue ∙ ap ! glue-β ∙ !-∙ (snd g) (! (snd h)))
∙ ∙-assoc (! (! (snd h))) (! (snd g)) (snd g)
∙ ap (λ w → ! (! (snd h)) ∙ w) (!-inv-l (snd g))
∙ ∙-unit-r (! (! (snd h)))
∙ !-! (snd h)
⊙wedge-rec = ⊙WedgeRec.⊙f
⊙wedge-rec-post∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(k : fst (Z ⊙→ W)) (g : fst (X ⊙→ Z)) (h : fst (Y ⊙→ Z))
→ k ⊙∘ ⊙wedge-rec g h == ⊙wedge-rec (k ⊙∘ g) (k ⊙∘ h)
⊙wedge-rec-post∘ k g h = ⊙λ=
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in $ ⊙WedgeRec.glue-β (k ⊙∘ g) (k ⊙∘ h)
∙ lemma (fst k) (snd g) (snd h) (snd k)
∙ ! (ap (ap (fst k)) (⊙WedgeRec.glue-β g h))
∙ ∘-ap (fst k) (fst (⊙wedge-rec g h)) wglue))
idp
where
lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z : A} {w : B}
(p : x == z) (q : y == z) (r : f z == w)
→ (ap f p ∙ r) ∙ ! (ap f q ∙ r) == ap f (p ∙ ! q)
lemma f idp idp idp = idp
⊙wedge-rec-η : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ ⊙wedge-rec ⊙winl ⊙winr == ⊙idf (X ⊙∨ Y)
⊙wedge-rec-η = ⊙λ=
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in $ ap-idf wglue
∙ ! (!-! wglue)
∙ ! (⊙WedgeRec.glue-β ⊙winl ⊙winr)))
idp
module Fold {i} {X : Ptd i} = ⊙WedgeRec (⊙idf X) (⊙idf X)
fold = Fold.f
⊙fold = Fold.⊙f
module _ {i j} (X : Ptd i) (Y : Ptd j) where
module Projl = ⊙WedgeRec (⊙idf X) (⊙cst {X = Y})
module Projr = ⊙WedgeRec (⊙cst {X = X}) (⊙idf Y)
projl = Projl.f
projr = Projr.f
⊙projl = Projl.⊙f
⊙projr = Projr.⊙f
| 25.952703
| 78
| 0.497006
|
a1a45e0544d858fae6ae0099a0790d107a610319
| 139
|
agda
|
Agda
|
test/Fail/Issue478b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue478b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue478b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue478b where
record Ko (Q : Set) : Set₁ where
field
T : Set
foo : T
foo = Set
-- This previously said Set₁ !=< T r
| 11.583333
| 36
| 0.604317
|
fbe3d978b54d3fe508c888fc6d7d972b1cea4bc3
| 608
|
agda
|
Agda
|
test/Succeed/Issue1280.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1280.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1280.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue1280 where
open import Common.Prelude
open import Common.Reflection
infixr 5 _∷_
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
test : Vec _ _
test = 0 ∷ []
quoteTest : Term
quoteTest = quoteTerm test
unquoteTest = unquote (give quoteTest)
data Foo (A : Set) : Set where
foo : Foo A
ok : Foo Nat
ok = unquote (give (quoteTerm (foo {Nat})))
-- This shouldn't type-check. The term `bad` is type-checked because
-- the implicit argument of `foo` is missing when using quoteTerm.
bad : Foo Bool
bad = unquote (give (quoteTerm (foo {Nat})))
| 20.266667
| 68
| 0.666118
|
a1082c38d7811c26233f82085b5450d8c530e90e
| 485
|
agda
|
Agda
|
test/interaction/Issue289.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue289.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue289.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue289 where
data D : Set where
d : D
record ⊤ : Set where
foo : (x y : D) → ⊤
foo d y = {!y!}
-- WAS:
-- Right hand side must be a single hole when making a case
-- distinction.
-- when checking that the expression ? has type ⊤
-- THEN: (Andreas, 2013-03-22)
-- Since goal is solved, further case distinction is not supported;
-- try `Solve constraints' instead
-- when checking that the expression ? has type ⊤
-- NOW: (Andreas, 2016-06-08)
-- Case splitting works!
| 21.086957
| 67
| 0.670103
|
df6d50b49571f7807fd0312a442f7b29d23d96a9
| 432
|
agda
|
Agda
|
test/Fail/Issue202.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue202.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue202.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --no-universe-polymorphism #-}
module Issue202 where
open import Agda.Primitive public using (Level)
open import Imports.Test
module Test2 {ℓ : Level} (F : Foo ℓ) where
-- Test2.agda:4,31-36
-- The metavariable _1 cannot depend on ℓ because it does not depend
-- on any variables
-- when checking that the expression Foo ℓ has type _1
-- The code is accepted if universe polymorphism is turned on in
-- Test2.agda.
| 25.411765
| 68
| 0.738426
|
a17c36720307f71f9fae3718cdb5cfff7fca6137
| 11,972
|
agda
|
Agda
|
function/isomorphism/utils.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 27
|
2015-04-14T15:47:03.000Z
|
2022-01-09T07:26:57.000Z
|
function/isomorphism/utils.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 2
|
2015-02-11T11:14:59.000Z
|
2015-02-11T15:20:34.000Z
|
function/isomorphism/utils.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 4
|
2015-04-11T17:19:12.000Z
|
2019-02-26T06:17:38.000Z
|
{-# OPTIONS --without-K #-}
module function.isomorphism.utils where
open import sum
open import equality.core
open import equality.calculus
open import function.core
open import function.overloading
open import function.isomorphism.core
open import function.isomorphism.coherent
open import function.extensionality.proof
open import sets.unit
open import sets.empty
open import sets.fin.core
open import hott.level.core
Σ-split-iso : ∀ {i j}{X : Set i}{Y : X → Set j}
→ {a a' : X}{b : Y a}{b' : Y a'}
→ (Σ (a ≡ a') λ q → subst Y q b ≡ b')
≅ ((a , b) ≡ (a' , b'))
Σ-split-iso {Y = Y}{a}{a'}{b}{b'} = iso unapΣ apΣ H K
where
H : ∀ {a a'}{b : Y a}{b' : Y a'}
→ (p : Σ (a ≡ a') λ q → subst Y q b ≡ b')
→ apΣ (unapΣ {a = a}{a' = a'}{b = b}{b' = b'} p) ≡ p
H (refl , refl) = refl
K : (p : (a , b) ≡ (a' , b')) → unapΣ (apΣ p) ≡ p
K = J (λ u v p → unapΣ (apΣ p) ≡ p)
(λ {(a , b) → refl })
(a , b) (a' , b')
×-split-iso : ∀ {i j}{X : Set i}{Y : Set j}
→ {a a' : X}{b b' : Y}
→ ((a ≡ a') × (b ≡ b'))
≅ ((a , b) ≡ (a' , b'))
×-split-iso {X = X}{Y} = record
{ to = λ { (p , q) → ap₂ _,_ p q }
; from = λ { p → (ap proj₁ p , ap proj₂ p) }
; iso₁ = λ { (p , q) → H p q }
; iso₂ = K }
where
H : {a a' : X}{b b' : Y}(p : a ≡ a')(q : b ≡ b')
→ (ap proj₁ (ap₂ _,_ p q), ap proj₂ (ap₂ _,_ p q)) ≡ (p , q)
H refl refl = refl
K : {a a' : X}{b b' : Y}(p : (a , b) ≡ (a' , b'))
→ ap₂ _,_ (ap proj₁ p) (ap proj₂ p) ≡ p
K refl = refl
×-ap-iso : ∀ {i i' j j'}{X : Set i}{X' : Set i'}
{Y : Set j}{Y' : Set j'}
→ (isom : X ≅ X')
→ (isom' : Y ≅ Y')
→ (X × Y) ≅ (X' × Y')
×-ap-iso isom isom' = record
{ to = λ { (x , y) → (apply isom x , apply isom' y) }
; from = λ { (x' , y') → (invert isom x' , invert isom' y') }
; iso₁ = λ { (x , y) → pair≡ (_≅_.iso₁ isom x) (_≅_.iso₁ isom' y) }
; iso₂ = λ { (x' , y') → pair≡ (_≅_.iso₂ isom x') (_≅_.iso₂ isom' y') } }
Σ-ap-iso₂ : ∀ {i j j'}{X : Set i}
→ {Y : X → Set j}{Y' : X → Set j'}
→ ((x : X) → Y x ≅ Y' x)
→ Σ X Y ≅ Σ X Y'
Σ-ap-iso₂ {X = X}{Y}{Y'} isom = record
{ to = λ { (x , y) → (x , apply (isom x) y) }
; from = λ { (x , y') → (x , invert (isom x) y') }
; iso₁ = λ { (x , y) → unapΣ (refl , _≅_.iso₁ (isom x) y) }
; iso₂ = λ { (x , y') → unapΣ (refl , _≅_.iso₂ (isom x) y') } }
Σ-ap-iso₁ : ∀ {i i' j}{X : Set i}{X' : Set i'}{Y : X' → Set j}
→ (isom : X ≅ X')
→ Σ X (Y ∘ apply isom) ≅ Σ X' Y
Σ-ap-iso₁ {X = X}{X'}{Y} isom = record
{ to = λ { (x , y) → (f x , y) }
; from = λ { (x , y) → (g x , subst Y (sym (K x)) y) }
; iso₁ = λ { (x , y) → unapΣ (H x ,
subst-naturality Y f (H x) _
· (subst-hom Y (sym (K (f x))) (ap f (H x)) y
· ap (λ p → subst Y p y) (lem x) ) ) }
; iso₂ = λ { (x , y) → unapΣ (K x ,
subst-hom Y (sym (K x)) (K x) y
· ap (λ p → subst Y p y) (right-inverse (K x)) ) } }
where
isom-c = ≅⇒≅' isom
γ = proj₂ isom-c
open _≅_ (proj₁ isom-c)
renaming ( to to f ; from to g
; iso₁ to H; iso₂ to K )
lem : (x : X) → sym (K (f x)) · ap f (H x) ≡ refl
lem x = ap (λ z → sym (K (f x)) · z) (γ x)
· right-inverse (K (f x))
Σ-ap-iso : ∀ {i i' j j'}{X : Set i}{X' : Set i'}
{Y : X → Set j}{Y' : X' → Set j'}
→ (isom : X ≅ X')
→ ((x : X) → Y x ≅ Y' (apply isom x))
→ Σ X Y ≅ Σ X' Y'
Σ-ap-iso {X = X}{X'}{Y}{Y'} isom isom' = trans≅
(Σ-ap-iso₂ isom') (Σ-ap-iso₁ isom)
Σ-ap-iso' : ∀ {i i' j j'}{X : Set i}{X' : Set i'}
{Y : X → Set j}{Y' : X' → Set j'}
→ (isom : X ≅ X')
→ ((x : X') → Y (invert isom x) ≅ Y' x)
→ Σ X Y ≅ Σ X' Y'
Σ-ap-iso' {X = X}{X'}{Y}{Y'} isom isom'
= sym≅ (Σ-ap-iso (sym≅ isom) (λ x → sym≅ (isom' x)))
Π-ap-iso : ∀ {i i' j j'}{X : Set i}{X' : Set i'}
{Y : X → Set j}{Y' : X' → Set j'}
→ (isom : X ≅ X')
→ ((x' : X') → Y (invert isom x') ≅ Y' x')
→ ((x : X) → Y x)
≅ ((x' : X') → Y' x')
Π-ap-iso {X = X}{X'}{Y}{Y'} isom isom' =
trans≅ (Π-iso (≅⇒≅' isom)) (Π-iso' isom')
where
Π-iso : (isom : X ≅' X')
→ ((x : X) → Y x)
≅ ((x' : X') → Y (invert (proj₁ isom) x'))
Π-iso (iso f g H K , γ) = record
{ to = λ h x' → h (g x')
; from = λ h' x → subst Y (H x) (h' (f x))
; iso₁ = λ h → funext λ x → ap' h (H x)
; iso₂ = λ h' → funext λ x' →
ap (λ p → subst Y p _) (sym (γ' x'))
· sym (subst-naturality Y g (K x') _)
· ap' h' (K x') }
where γ' = co-coherence (iso f g H K) γ
Π-iso' : ∀ {i j j'}{X : Set i}
{Y : X → Set j}{Y' : X → Set j'}
→ ((x : X) → Y x ≅ Y' x)
→ ((x : X) → Y x)
≅ ((x : X) → Y' x)
Π-iso' isom = record
{ to = λ h x → apply (isom x) (h x)
; from = λ h' x → invert (isom x) (h' x)
; iso₁ = λ h → funext λ x → _≅_.iso₁ (isom x) _
; iso₂ = λ h' → funext λ x → _≅_.iso₂ (isom x) _ }
ΠΣ-swap-iso : ∀ {i j k}{X : Set i}{Y : X → Set j}
→ {Z : (x : X) → Y x → Set k}
→ ((x : X) → Σ (Y x) λ y → Z x y)
≅ (Σ ((x : X) → Y x) λ f → ((x : X) → Z x (f x)))
ΠΣ-swap-iso = record
{ to = λ f → (proj₁ ∘' f , proj₂ ∘' f)
; from = λ { (f , g) x → (f x , g x) }
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
curry-iso : ∀ {i j k}{X : Set i}{Y : X → Set j}
(Z : (x : X) → Y x → Set k)
→ ((xy : Σ X Y) → Z (proj₁ xy) (proj₂ xy))
≅ ((x : X) → (y : Y x) → Z x y)
curry-iso _ = record
{ to = λ f x y → f (x , y)
; from = λ { f (x , y) → f x y }
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
Π-comm-iso : ∀ {i j k}{X : Set i}{Y : Set j}{Z : X → Y → Set k}
→ ((x : X)(y : Y) → Z x y)
≅ ((y : Y)(x : X) → Z x y)
Π-comm-iso = record
{ to = λ f y x → f x y
; from = λ f x y → f y x
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
Σ-comm-iso : ∀ {i j k}{X : Set i}{Y : Set j}{Z : X → Y → Set k}
→ (Σ X λ x → Σ Y λ y → Z x y)
≅ (Σ Y λ y → Σ X λ x → Z x y)
Σ-comm-iso = record
{ to = λ { (x , y , z) → (y , x , z) }
; from = λ { (y , x , z) → (x , y , z) }
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
impl-iso : ∀ {i j}{X : Set i}{Y : X → Set j}
→ ((x : X) → Y x) ≅ ({x : X} → Y x)
impl-iso = record
{ to = λ f → f _
; from = λ f _ → f
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
Σ-assoc-iso : ∀ {i j k}
{X : Set i}{Y : X → Set j}
{Z : (x : X) → Y x → Set k}
→ Σ (Σ X Y) (λ {(x , y) → Z x y})
≅ Σ X λ x → Σ (Y x) (Z x)
Σ-assoc-iso = record
{ to = λ {((x , y) , z) → (x , y , z) }
; from = λ {(x , y , z) → ((x , y) , z) }
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
⊎-Σ-iso : ∀ {i}(X : Fin 2 → Set i)
→ (X zero ⊎ X (suc zero))
≅ Σ (Fin 2) X
⊎-Σ-iso X = record
{ to = λ { (inj₁ x) → zero , x
; (inj₂ x) → suc zero , x }
; from = λ { (zero , x) → inj₁ x
; (suc zero , x) → inj₂ x
; (suc (suc ()) , _) }
; iso₁ = λ { (inj₁ x) → refl
; (inj₂ x) → refl }
; iso₂ = λ { (zero , x) → refl
; (suc zero , x) → refl
; (suc (suc ()) , _) } }
⊎-ap-iso : ∀ {i j i' j'}
→ {X : Set i}{X' : Set i'}
→ {Y : Set j}{Y' : Set j'}
→ X ≅ X'
→ Y ≅ Y'
→ (X ⊎ Y) ≅ (X' ⊎ Y')
⊎-ap-iso (iso f g α β) (iso f' g' α' β') = record
{ to = λ { (inj₁ x) → inj₁ (f x) ; (inj₂ y) → inj₂ (f' y) }
; from = λ { (inj₁ x) → inj₁ (g x) ; (inj₂ y) → inj₂ (g' y) }
; iso₁ = λ { (inj₁ x) → ap inj₁ (α x) ; (inj₂ y) → ap inj₂ (α' y) }
; iso₂ = λ { (inj₁ x) → ap inj₁ (β x) ; (inj₂ y) → ap inj₂ (β' y) } }
⊎-assoc-iso : ∀ {i j k}
→ {X : Set i}{Y : Set j}{Z : Set k}
→ ((X ⊎ Y) ⊎ Z)
≅ (X ⊎ (Y ⊎ Z))
⊎-assoc-iso = record
{ to = λ { (inj₁ (inj₁ x)) → inj₁ x
; (inj₁ (inj₂ y)) → inj₂ (inj₁ y)
; (inj₂ z) → inj₂ (inj₂ z) }
; from = λ { (inj₁ x) → inj₁ (inj₁ x)
; (inj₂ (inj₁ y)) → inj₁ (inj₂ y)
; (inj₂ (inj₂ z)) → inj₂ z }
; iso₁ = λ { (inj₁ (inj₁ x)) → refl
; (inj₁ (inj₂ y)) → refl
; (inj₂ z) → refl }
; iso₂ = λ { (inj₁ x) → refl
; (inj₂ (inj₁ y)) → refl
; (inj₂ (inj₂ z)) → refl } }
⊎×-distr-iso : ∀ {i j k}
→ {X : Set i}{Y : Set j}{Z : Set k}
→ ((X ⊎ Y) × Z)
≅ ((X × Z) ⊎ (Y × Z))
⊎×-distr-iso = record
{ to = λ { (inj₁ x , z) → inj₁ (x , z)
; (inj₂ y , z) → inj₂ (y , z) }
; from = λ { (inj₁ (x , z)) → inj₁ x , z
; (inj₂ (y , z)) → inj₂ y , z }
; iso₁ = λ { (inj₁ x , z) → refl
; (inj₂ y , z) → refl }
; iso₂ = λ { (inj₁ (x , z)) → refl
; (inj₂ (y , z)) → refl } }
⊎-universal : ∀ {i j k}{X : Set i}{Y : Set j}
→ {Z : X ⊎ Y → Set k}
→ ((u : X ⊎ Y) → Z u)
≅ (((x : X) → Z (inj₁ x)) × ((y : Y) → Z (inj₂ y)))
⊎-universal = record
{ to = λ f → (f ∘' inj₁ , f ∘' inj₂)
; from = λ { (g₁ , g₂) (inj₁ x) → g₁ x
; (g₁ , g₂) (inj₂ y) → g₂ y }
; iso₁ = λ f → funext λ
{ (inj₁ x) → refl
; (inj₂ x) → refl }
; iso₂ = λ { (g₁ , g₂) → refl } }
×-left-unit : ∀ {i}{X : Set i} → (⊤ × X) ≅ X
×-left-unit = record
{ to = λ {(tt , x) → x }
; from = λ x → tt , x
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
×-right-unit : ∀ {i}{X : Set i} → (X × ⊤) ≅ X
×-right-unit = record
{ to = λ {(x , tt) → x }
; from = λ x → x , tt
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
contr-⊤-iso : ∀ {i}{X : Set i}
→ contr X → X ≅ ⊤
contr-⊤-iso hX = record
{ to = λ x → tt
; from = λ { tt → proj₁ hX }
; iso₁ = λ x → proj₂ hX x
; iso₂ = λ { tt → refl } }
empty-⊥-iso : ∀ {i}{X : Set i}
→ (X → ⊥) → X ≅ ⊥
empty-⊥-iso u = record
{ to = u
; from = ⊥-elim
; iso₁ = λ x → ⊥-elim (u x)
; iso₂ = λ () }
×-comm : ∀ {i j}{X : Set i}{Y : Set j}
→ (X × Y) ≅ (Y × X)
×-comm = record
{ to = λ {(x , y) → (y , x)}
; from = λ {(y , x) → (x , y)}
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
Π-left-unit : ∀ {i}{X : Set i}
→ (⊤ → X) ≅ X
Π-left-unit = record
{ to = λ f → f tt
; from = λ x _ → x
; iso₁ = λ _ → refl
; iso₂ = λ f → refl }
-- rewriting lemmas for equations on equalities
sym≡-iso : ∀ {i}{X : Set i}(x y : X)
→ (x ≡ y)
≅ (y ≡ x)
sym≡-iso _ _ = iso sym sym double-inverse double-inverse
trans≡-iso : ∀ {i}{X : Set i}{x y z : X}
→ (x ≡ y)
→ (y ≡ z) ≅ (x ≡ z)
trans≡-iso p = record
{ to = λ q → p · q
; from = λ q → sym p · q
; iso₁ = λ q → sym (associativity (sym p) p q)
· ap (λ z → z · q) (right-inverse p)
; iso₂ = λ q → sym (associativity p (sym p) q)
· ap (λ z → z · q) (left-inverse p) }
trans≡-iso' : ∀ {i}{X : Set i}{x y z : X}
→ (y ≡ z)
→ (x ≡ y) ≅ (x ≡ z)
trans≡-iso' q = record
{ to = λ p → p · q
; from = λ p → p · sym q
; iso₁ = λ p → associativity p q (sym q)
· ap (_·_ p) (left-inverse q)
· left-unit p
; iso₂ = λ p → associativity p (sym q) q
· (ap (_·_ p) (right-inverse q)
· left-unit p) }
move-≡-iso : ∀ {i}{X : Set i}{x y z : X}
→ (p : x ≡ y)(q : y ≡ z)(r : x ≡ z)
→ (p · q ≡ r)
≅ (sym p · r ≡ q)
move-≡-iso refl = sym≡-iso
J-iso : ∀ {i j}{X : Set i}{x : X}
→ {P : (y : X) → x ≡ y → Set j}
→ P x refl
≅ ((y : X)(p : x ≡ y) → P y p)
J-iso {X = X}{x}{P} = record
{ to = J' P
; from = λ u → u x refl
; iso₁ = λ _ → refl
; iso₂ = λ u → funext λ y → funext λ p → β u y p }
where
β : (u : (y : X)(p : x ≡ y) → P y p)
→ (y : X)(p : x ≡ y)
→ J' P (u x refl) y p ≡ u y p
β u .x refl = refl
| 32.269542
| 75
| 0.380638
|
a17d6d2dd828cbf6c750a30522a4ac6b3f844272
| 146
|
agda
|
Agda
|
test/epic/Prelude/Product.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/epic/Prelude/Product.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/epic/Prelude/Product.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
module Prelude.Product where
infixr 4 _,_
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_ public
| 12.166667
| 34
| 0.636986
|
a1935196ab1ce603a29d70b58576eaf8e29da5f9
| 167
|
agda
|
Agda
|
test/Fail/NoLetInRecordTele.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/NoLetInRecordTele.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/NoLetInRecordTele.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Primitive
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
record R {A : Set} {B : A → Set} p@ab : Set where
field
prf : p ≡ p
| 20.875
| 49
| 0.688623
|
107369c48245284a2df888f218e9a191640e8ed7
| 4,270
|
agda
|
Agda
|
examples/StateSized/StackStateDependent.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/StateSized/StackStateDependent.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/StateSized/StackStateDependent.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
{-# OPTIONS --postfix-projections #-}
module StateSized.StackStateDependent where
open import Data.Product
open import Function
open import Data.String.Base as Str
open import Data.Nat.Base as N
open import Data.Vec as Vec using (Vec; []; _∷_; head; tail)
open import Relation.Binary using (Rel)
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Product.Pointwise
open import NativeIO
open import SizedIO.Base
open import SizedIO.Console hiding (main)
open import StateSizedIO.GUI.BaseStateDependent
open import StateSizedIO.Object
open import StateSizedIO.IOObject
open import Size
StackStateˢ = ℕ
data StackMethodˢ (A : Set) : StackStateˢ → Set where
push : {n : StackStateˢ} → A → StackMethodˢ A n
pop : {n : StackStateˢ} → StackMethodˢ A (suc n)
StackResultˢ : (A : Set) → (s : StackStateˢ) → StackMethodˢ A s → Set
StackResultˢ A .n (push { n } x₁) = Unit
StackResultˢ A (suc .n) (pop {n} ) = A
nˢ : (A : Set) → (s : StackStateˢ) → (m : StackMethodˢ A s) → (r : StackResultˢ A s m) → StackStateˢ
nˢ A .n (push { n } x) r = suc n
nˢ A (suc .n) (pop { n }) r = n
StackInterfaceˢ : (A : Set) → Interfaceˢ
StackInterfaceˢ A .Stateˢ = StackStateˢ
StackInterfaceˢ A .Methodˢ = StackMethodˢ A
StackInterfaceˢ A .Resultˢ = StackResultˢ A
StackInterfaceˢ A .nextˢ = nˢ A
stackP : ∀{n : ℕ} → (i : Size) → (v : Vec String n) → IOObjectˢ consoleI (StackInterfaceˢ String) i n
method (stackP { n } i es) {j} (push e) = return (_ , stackP j (e ∷ es))
method (stackP {suc n} i (x ∷ xs)){j} pop = return (x , stackP j xs)
-- UNSIZED Version, without IO
stackP' : ∀{n : ℕ} → (v : Vec String n) → Objectˢ (StackInterfaceˢ String) n
stackP' es .objectMethod (push e) = (_ , stackP' (e ∷ es))
stackP' (x ∷ xs) .objectMethod pop = x , stackP' xs
stackO : ∀{E : Set} {n : ℕ} (v : Vec E n) → Objectˢ (StackInterfaceˢ E) n
objectMethod (stackO es) (push e) = _ , stackO (e ∷ es)
objectMethod (stackO (e ∷ es)) pop = e , stackO es
stackF : ∀{E : Set} (n : ℕ) (f : ℕ → E) → Objectˢ (StackInterfaceˢ E) n
objectMethod (stackF n f) (push x) = _ , stackF (suc n)
\{ zero → x
; (suc m) → f m
}
objectMethod (stackF (suc n) f) pop = (f zero) , stackF n (f ∘ suc)
tabulate : ∀{E : Set} (n : ℕ) (f : ℕ → E) → Vec E n
tabulate zero f = []
tabulate (suc n) f = f zero ∷ tabulate n λ m → f (suc m)
module _ {E : Set} where
private
I = StackInterfaceˢ E
S = Stateˢ I
O = Objectˢ I
open Bisim I
_≡×≅'_ : ∀{s} → (o o' : E × O s) → Set
_≡×≅'_ = _≡_ ×-Rel _≅_
Eq×Bisim : ∀ (s : S) → (o o' : E × O s) → Set
Eq×Bisim s = _≡_ ×-Rel _≅_
pop-after-push : ∀{n}{v : Vec E n} (e : E) (let stack = stackO v) →
(objectMethod stack (push e) ▹ λ { (_ , stack₁) →
objectMethod stack₁ pop ▹ λ { (e₁ , stack₂) →
( e₁ , stack₂ ) }})
≡×≅' (e , stack)
pop-after-push e = refl , refl≅ _
push-after-pop : ∀{n}{v : Vec E n} (e : E) (let stack = stackO (e ∷ v)) →
(objectMethod stack pop ▹ λ { (e₁ , stack₁) →
objectMethod stack₁ (push e₁) ▹ λ { (_ , stack₂) →
stack₂ }})
≅ stack
push-after-pop e = refl≅ _
-- The implementations of stacks with either vectors or functions are bisimilar.
impl-bisim : ∀{n : ℕ} {f : ℕ → E} (v : Vec E n) (p : tabulate n f ≡ v)
→ stackF n f ≅ stackO v
bisimMethod (impl-bisim v p) (push e) =
bisim (impl-bisim (e ∷ v) (cong (_∷_ e) p))
bisimMethod (impl-bisim (x ∷ v) p) pop rewrite cong head p =
bisim (impl-bisim v (cong tail p))
program : IOConsole ∞ Unit
program =
exec getLine λ str₀ →
method s₀ (push str₀) >>= λ{ (_ , s₁) → -- empty
exec getLine λ str₁ →
method s₁ (push str₁) >>= λ{ (_ , s₂) → -- full
method s₂ pop >>= λ{ (str₂ , s₃) →
exec (putStrLn ("first pop: " Str.++ str₂) ) λ _ →
exec getLine λ str₃ →
method s₃ (push str₃) >>= λ{ (_ , s₄) →
method s₄ pop >>= λ{ (str₄ , s₅) →
exec (putStrLn ("second pop: " Str.++ str₄) ) λ _ →
method s₅ pop >>= λ{ (str₅ , s₅) →
exec (putStrLn ("third pop: " Str.++ str₅) ) λ _ →
return unit
}}}}}}
where
s₀ = stackP ∞ []
main : NativeIO Unit
main = translateIOConsole program
| 30.719424
| 101
| 0.586651
|
12e5a9c994a5707a62a7ef60229bfd843fd075df
| 713
|
agda
|
Agda
|
test/interaction/Issue1349.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue1349.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue1349.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, fixed #1349 on 2016-06-08
-- {-# OPTIONS -v tc.term.exlam:50 -v scope.extendedLambda:10 #-}
module Issue1349 where
open import Common.Prelude
module Logic {s} (F : Set s) (arF : F → Nat) where
data Term : Nat → Set s where
var : ∀ n → Term (suc n)
d : Unit → Nat
d = \ {unit → zero} -- fails
-- d unit = zero -- works
module M = Logic Unit d -- (λ{unit -> zero})
test : Logic.Term Unit {!!} (suc zero)
test = M.var zero
-- WAS:
-- Agda2> Ambiguous name: Issue1349._..extendedlambda0
-- (agda2-info-action "*Error*" "An internal error has occurred. Please report this as a bug. Location of the error: src/full/Agda/TypeChecking/Reduce/Monad.hs:172" nil)
-- Gives proper error now.
| 25.464286
| 169
| 0.650771
|
1c159f3b42974f373c687e0c1e1eec0fc6eb32f2
| 2,489
|
agda
|
Agda
|
Categories/Functor/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Categories/Functor/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Categories/Functor/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error --without-K --safe #-}
open import LogicalFormulae
open import Categories.Definition
open import Categories.Functor.Definition
module Categories.Functor.Lemmas where
functorCompose : {a b c d e f : _} {B : Category {a} {b}} {C : Category {c} {d}} {D : Category {e} {f}} → (Functor C D) → (Functor B C) → (Functor B D)
functorCompose G F = record { onObj = λ x → Functor.onObj G (Functor.onObj F x) ; onArrow = λ f → Functor.onArrow G (Functor.onArrow F f) ; mapId = λ {T} → mapIdHelp G F T ; mapCompose = λ r s → mapComposeHelp G F r s }
where
mapIdHelp : {a b c d e f : _} {B : Category {a} {b}} {C : Category {c} {d}} {D : Category {e} {f}} → (G : Functor C D) → (F : Functor B C) → (T : Category.objects B) → Functor.onArrow G (Functor.onArrow F (Category.id B T)) ≡ Category.id D (Functor.onObj G (Functor.onObj F T))
mapIdHelp {B = B} {C} {D} record { onObj = onObjG ; onArrow = onArrowG ; mapId = mapIdG ; mapCompose = mapComposeG } record { onObj = onObj ; onArrow = onArrow ; mapId = mapId ; mapCompose = mapCompose } T rewrite mapId {T} = mapIdG {onObj T}
mapComposeHelp : {a b c d e f : _} {B : Category {a} {b}} {C : Category {c} {d}} {D : Category {e} {f}} → (G : Functor C D) → (F : Functor B C) → {S T U : Category.objects B} → (r : Category.arrows B S T) → (s : Category.arrows B T U) → (Functor.onArrow G (Functor.onArrow F (Category._∘_ B s r))) ≡ (Category._∘_ D (Functor.onArrow G (Functor.onArrow F s)) (Functor.onArrow G (Functor.onArrow F r)))
mapComposeHelp {B = record { objects = objectsB ; arrows = arrowsB ; id = idB ; _∘_ = _∘B_ ; rightId = rightIdB ; leftId = leftIdB ; compositionAssociative = associativeB }} {record { objects = objectsC ; arrows = arrowsC ; id = idC ; _∘_ = _∘C_ ; rightId = rightIdC ; leftId = leftIdC ; compositionAssociative = associativeC }} {record { objects = objectsD ; arrows = arrowsD ; id = idD ; _∘_ = _∘D_ ; rightId = rightIdD ; leftId = leftIdD ; compositionAssociative = associativeD }} record { onObj = onObjG ; onArrow = onArrowG ; mapId = mapIdG ; mapCompose = mapComposeG } record { onObj = onObjF ; onArrow = onArrowF ; mapId = mapIdF ; mapCompose = mapComposeF } {S} {T} {U} r s rewrite mapComposeF r s | mapComposeG (onArrowF r) (onArrowF s) = refl
idFunctor : {a b : _} (C : Category {a} {b}) → Functor C C
Functor.onObj (idFunctor C) = λ x → x
Functor.onArrow (idFunctor C) = λ f → f
Functor.mapId (idFunctor C) = refl
Functor.mapCompose (idFunctor C) = λ f g → refl
| 113.136364
| 756
| 0.653274
|
23523f01e0fa10db1652b7a785ece79b28bd20d4
| 199
|
agda
|
Agda
|
examples/AIM6/HelloAgda/Bool.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/AIM6/HelloAgda/Bool.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/AIM6/HelloAgda/Bool.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Bool where
data Bool : Set where
true : Bool
false : Bool
infix 0 if_then_else_
if_then_else_ : {A : Set} -> Bool -> A -> A -> A
if true then x else y = x
if false then x else y = y
| 15.307692
| 48
| 0.633166
|
dc7d8982d7ba282219a9b44f6502362add1fa184
| 2,544
|
agda
|
Agda
|
src/fot/README.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/README.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/README.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- FOT (First-Order Theories)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Code accompanying the PhD thesis "Reasoning about Functional
-- Programs by Combining Interactive and Automatic Proofs" by Andrés
-- Sicard-Ramírez.
-- The code presented here does not match the thesis exactly.
module README where
------------------------------------------------------------------------------
-- Description
-- Examples of the formalization of first-order theories showing the
-- combination of interactive proofs with automatics proofs carried
-- out by first-order automatic theorem provers (ATPs).
------------------------------------------------------------------------------
-- For the thesis, prerequisites, tested versions of the ATPs and use,
-- see https://github.com/asr/fotc/.
------------------------------------------------------------------------------
-- Conventions
-- If the module's name ends in 'I' the module contains interactive
-- proofs, if it ends in 'ATP' the module contains combined proofs,
-- otherwise the module contains definitions and/or interactive proofs
-- that are used by the interactive and combined proofs.
------------------------------------------------------------------------------
-- First-order theories
------------------------------------------------------------------------------
-- • First-order logic with equality
-- First-order logic (FOL)
open import FOL.README
-- Propositional equality
open import Common.FOL.Relation.Binary.PropositionalEquality
-- Equality reasoning
open import Common.FOL.Relation.Binary.EqReasoning
-- • Group theory
open import GroupTheory.README
-- • Distributive laws on a binary operation (Stanovský example)
open import DistributiveLaws.README
-- • First-order Peano arithmetic (PA)
open import PA.README
-- • First-Order Theory of Combinators (FOTC)
open import FOTC.README
-- • Logical Theory of Constructions for PCF (LTC-PCF)
open import LTC-PCF.README
------------------------------------------------------------------------------
-- Agsy examples
------------------------------------------------------------------------------
-- We cannot import the Agsy examples because some modules contain
-- unsolved metas, therefore see examples/Agsy/README.txt
| 32.615385
| 78
| 0.533019
|
12ab4aa290e65a88ed443c52be42e3f2877eec28
| 5,482
|
agda
|
Agda
|
agda-stdlib/src/Relation/Binary/Construct/NaturalOrder/Left.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Relation/Binary/Construct/NaturalOrder/Left.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Relation/Binary/Construct/NaturalOrder/Left.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Conversion of binary operators to binary relations via the left
-- natural order.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
open import Algebra.Core
module Relation.Binary.Construct.NaturalOrder.Left
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) (_∙_ : Op₂ A) where
open import Algebra.Definitions _≈_
open import Algebra.Structures _≈_
open import Data.Product using (_,_; _×_)
open import Data.Sum.Base using (inj₁; inj₂)
open import Relation.Nullary using (¬_)
import Relation.Binary.Reasoning.Setoid as EqReasoning
open import Relation.Binary.Lattice using (Infimum)
------------------------------------------------------------------------
-- Definition
infix 4 _≤_
_≤_ : Rel A ℓ
x ≤ y = x ≈ (x ∙ y)
------------------------------------------------------------------------
-- Relational properties
reflexive : IsMagma _∙_ → Idempotent _∙_ → _≈_ ⇒ _≤_
reflexive magma idem {x} {y} x≈y = begin
x ≈⟨ sym (idem x) ⟩
x ∙ x ≈⟨ ∙-cong refl x≈y ⟩
x ∙ y ∎
where open IsMagma magma; open EqReasoning setoid
refl : Symmetric _≈_ → Idempotent _∙_ → Reflexive _≤_
refl sym idem {x} = sym (idem x)
antisym : IsEquivalence _≈_ → Commutative _∙_ → Antisymmetric _≈_ _≤_
antisym isEq comm {x} {y} x≤y y≤x = begin
x ≈⟨ x≤y ⟩
x ∙ y ≈⟨ comm x y ⟩
y ∙ x ≈⟨ sym y≤x ⟩
y ∎
where open IsEquivalence isEq; open EqReasoning (record { isEquivalence = isEq })
total : Symmetric _≈_ → Transitive _≈_ → Selective _∙_ → Commutative _∙_ → Total _≤_
total sym trans sel comm x y with sel x y
... | inj₁ x∙y≈x = inj₁ (sym x∙y≈x)
... | inj₂ x∙y≈y = inj₂ (sym (trans (comm y x) x∙y≈y))
trans : IsSemigroup _∙_ → Transitive _≤_
trans semi {x} {y} {z} x≤y y≤z = begin
x ≈⟨ x≤y ⟩
x ∙ y ≈⟨ ∙-cong S.refl y≤z ⟩
x ∙ (y ∙ z) ≈⟨ sym (assoc x y z) ⟩
(x ∙ y) ∙ z ≈⟨ ∙-cong (sym x≤y) S.refl ⟩
x ∙ z ∎
where open module S = IsSemigroup semi; open EqReasoning S.setoid
respʳ : IsMagma _∙_ → _≤_ Respectsʳ _≈_
respʳ magma {x} {y} {z} y≈z x≤y = begin
x ≈⟨ x≤y ⟩
x ∙ y ≈⟨ ∙-cong M.refl y≈z ⟩
x ∙ z ∎
where open module M = IsMagma magma; open EqReasoning M.setoid
respˡ : IsMagma _∙_ → _≤_ Respectsˡ _≈_
respˡ magma {x} {y} {z} y≈z y≤x = begin
z ≈⟨ sym y≈z ⟩
y ≈⟨ y≤x ⟩
y ∙ x ≈⟨ ∙-cong y≈z M.refl ⟩
z ∙ x ∎
where open module M = IsMagma magma; open EqReasoning M.setoid
resp₂ : IsMagma _∙_ → _≤_ Respects₂ _≈_
resp₂ magma = respʳ magma , respˡ magma
dec : Decidable _≈_ → Decidable _≤_
dec _≟_ x y = x ≟ (x ∙ y)
module _ (semi : IsSemilattice _∙_) where
private open module S = IsSemilattice semi
open EqReasoning setoid
x∙y≤x : ∀ x y → (x ∙ y) ≤ x
x∙y≤x x y = begin
x ∙ y ≈⟨ ∧-cong (sym (idem x)) S.refl ⟩
(x ∙ x) ∙ y ≈⟨ assoc x x y ⟩
x ∙ (x ∙ y) ≈⟨ comm x (x ∙ y) ⟩
(x ∙ y) ∙ x ∎
x∙y≤y : ∀ x y → (x ∙ y) ≤ y
x∙y≤y x y = begin
x ∙ y ≈⟨ ∧-cong S.refl (sym (idem y)) ⟩
x ∙ (y ∙ y) ≈⟨ sym (assoc x y y) ⟩
(x ∙ y) ∙ y ∎
∙-presʳ-≤ : ∀ {x y} z → z ≤ x → z ≤ y → z ≤ (x ∙ y)
∙-presʳ-≤ {x} {y} z z≤x z≤y = begin
z ≈⟨ z≤y ⟩
z ∙ y ≈⟨ ∧-cong z≤x S.refl ⟩
(z ∙ x) ∙ y ≈⟨ assoc z x y ⟩
z ∙ (x ∙ y) ∎
infimum : Infimum _≤_ _∙_
infimum x y = x∙y≤x x y , x∙y≤y x y , ∙-presʳ-≤
------------------------------------------------------------------------
-- Structures
isPreorder : IsBand _∙_ → IsPreorder _≈_ _≤_
isPreorder band = record
{ isEquivalence = isEquivalence
; reflexive = reflexive isMagma idem
; trans = trans isSemigroup
}
where open IsBand band hiding (reflexive; trans)
isPartialOrder : IsSemilattice _∙_ → IsPartialOrder _≈_ _≤_
isPartialOrder semilattice = record
{ isPreorder = isPreorder isBand
; antisym = antisym isEquivalence comm
}
where open IsSemilattice semilattice
isDecPartialOrder : IsSemilattice _∙_ → Decidable _≈_ →
IsDecPartialOrder _≈_ _≤_
isDecPartialOrder semilattice _≟_ = record
{ isPartialOrder = isPartialOrder semilattice
; _≟_ = _≟_
; _≤?_ = dec _≟_
}
isTotalOrder : IsSemilattice _∙_ → Selective _∙_ → IsTotalOrder _≈_ _≤_
isTotalOrder latt sel = record
{ isPartialOrder = isPartialOrder latt
; total = total sym S.trans sel comm
}
where open module S = IsSemilattice latt
isDecTotalOrder : IsSemilattice _∙_ → Selective _∙_ →
Decidable _≈_ → IsDecTotalOrder _≈_ _≤_
isDecTotalOrder latt sel _≟_ = record
{ isTotalOrder = isTotalOrder latt sel
; _≟_ = _≟_
; _≤?_ = dec _≟_
}
------------------------------------------------------------------------
-- Bundles
preorder : IsBand _∙_ → Preorder a ℓ ℓ
preorder band = record
{ isPreorder = isPreorder band
}
poset : IsSemilattice _∙_ → Poset a ℓ ℓ
poset latt = record
{ isPartialOrder = isPartialOrder latt
}
decPoset : IsSemilattice _∙_ → Decidable _≈_ → DecPoset a ℓ ℓ
decPoset latt dec = record
{ isDecPartialOrder = isDecPartialOrder latt dec
}
totalOrder : IsSemilattice _∙_ → Selective _∙_ → TotalOrder a ℓ ℓ
totalOrder latt sel = record
{ isTotalOrder = isTotalOrder latt sel
}
decTotalOrder : IsSemilattice _∙_ → Selective _∙_ →
Decidable _≈_ → DecTotalOrder a ℓ ℓ
decTotalOrder latt sel dec = record
{ isDecTotalOrder = isDecTotalOrder latt sel dec
}
| 29.632432
| 84
| 0.564028
|
dc636f2800d99b19e9a9198688b784e1704b2089
| 1,244
|
agda
|
Agda
|
test/Succeed/Issue836a.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue836a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue836a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2013-05-02 This ain't a bug, it is a feature.
-- {-# OPTIONS -v scope.name:10 #-}
-- {-# OPTIONS -v scope:10 #-}
-- {-# OPTIONS -v scope.mod.inst:30 #-}
module _ where
module M (_ : Set₁) where
record R : Set₁ where
field
X : Set
open M Set using (R)
X : R → Set
X = R.X
-- A glimpse at the scope (showing only concrete names, though)
-- modules
-- * scope Issue836a
-- private names R --> [Issue836a._.R]
-- public modules M --> [Issue836a.M]
-- * scope Issue836a.M
-- public names R --> [Issue836a.M.R]
-- public modules R --> [Issue836a.M.R]
-- * scope Issue836a.M.R
-- public names X --> [Issue836a.M.R.X]
-- * scope Issue836a._
-- public names R --> [Issue836a._.R]
-- public modules R --> [Issue836a._.R]
-- * scope Issue836a._.R
-- public names X --> [Issue836a._.R.X]
-- Nisse:
-- The open directive did not mention the /module/ R, so (I think
-- that) the code above should be rejected.
-- Andreas
-- NO, it is a feature that projections can also be accessed via
-- the record /type/.
-- The following directive is (and should be) rejected:
-- open R
-- Bug.agda:19,6-7
-- No such module R
-- when scope checking the declaration
-- open R
| 24.88
| 65
| 0.606109
|
0ec46e1680495b8a1afdb8f787da152b76630398
| 180
|
agda
|
Agda
|
test/Fail/Issue782.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue782.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue782.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2013-02-21, example by Andres Sicard Ramirez
module Issue782 where
open import Common.Prelude renaming (zero toz; suc tos; Nat toℕ)
f : ℕ → ℕ
f z = z
f (s n) = z
| 20
| 64
| 0.677778
|
1cc204146f31103bb6c37ed650756c436d7ce32c
| 1,267
|
agda
|
Agda
|
test/Succeed/Issue723.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue723.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue723.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.constr.findInScope:15 -v tc.meta.new:50 #-}
-- Andreas, 2012-10-20 issue raised by d.starosud
-- solved by dropping UnBlock constraints during trial candidate assignment
-- Jesper, 2018-11-28: Now fixed more properly
module Succeed.Issue723 where
import Common.Level
open import Common.Prelude using (Bool; false; zero) renaming (Nat to ℕ)
record Default {ℓ} (A : Set ℓ) : Set ℓ where
constructor create
field default : A
open Default {{...}} using (default)
instance
defBool : Default Bool
defBool = create false
defSet : Default Set
defSet = create Bool
defNat : Default ℕ
defNat = create zero
defDef : Default (Default ℕ)
defDef = create defNat
defFunc : ∀ {ℓ} {A : Set ℓ} → Default (A → A)
defFunc = create (λ x → x)
-- these lines are compiled successfully
id : ∀ {a} (A : Set a) → A → A
id A x = x
syntax id A x = x ∶ A
n₁ = default ∶ ℕ
f₁ = default ∶ (ℕ → ℕ)
-- WAS: but this one hangs on "Checking"
n₂ = default (5 ∶ ℕ) ∶ ℕ
-- n₂ = id ℕ (default (id ℕ 5))
n : ℕ
n = default 5
-- now we get unsolved metas
-- that's kind of ok
-- Jesper!2018: no more yellow!
n₃ = (default ∶ (_ → _)) 5
-- this one works again (before: also unsolved metas (worked before switching of the occurs-error (Issue 795)))
| 23.462963
| 111
| 0.662194
|
4d3b7e8f78cbc5464053a30d33b5283c11cc343c
| 375
|
agda
|
Agda
|
test/Succeed/LevelLeqGeq.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/LevelLeqGeq.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/LevelLeqGeq.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-09-28
-- Level constraints X <= a and a <= X should solve X = a.
-- {-# OPTIONS -v tc.constr.add:40 #-}
open import Common.Level
module _ (a : Level) where
mutual
X : Level
X = _
data C : Set (lsuc X) where
c : Set a → C -- constrains X by a <= X
data D : Set (lsuc a) where
c : Set X → D -- constrains X by X <= a
-- should succeed
| 18.75
| 58
| 0.576
|
4d4cff1940892bd55677b7e4cd24606e6e76d057
| 902
|
agda
|
Agda
|
Rings/Homomorphisms/Kernel.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Rings/Homomorphisms/Kernel.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Rings/Homomorphisms/Kernel.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 Setoids.Setoids
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.Homomorphisms.Definition
open import Rings.Ideals.Definition
module Rings.Homomorphisms.Kernel {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_+1_ _*1_ : A → A → A} {_+2_ _*2_ : B → B → B} {R1 : Ring S _+1_ _*1_} {R2 : Ring T _+2_ _*2_} {f : A → B} (fHom : RingHom R1 R2 f) where
open import Groups.Homomorphisms.Kernel (RingHom.groupHom fHom)
ringKernelIsIdeal : Ideal R1 groupKernelPred
Ideal.isSubgroup ringKernelIsIdeal = groupKernelIsSubgroup
Ideal.accumulatesTimes ringKernelIsIdeal {x} {y} fx=0 = transitive (RingHom.ringHom fHom) (transitive (Ring.*WellDefined R2 fx=0 reflexive) (transitive (Ring.*Commutative R2) (Ring.timesZero R2)))
where
open Setoid T
open Equivalence eq
| 45.1
| 256
| 0.717295
|
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.