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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5e304c0d650de105fbec8223391d5945652814c4
| 693
|
agda
|
Agda
|
test/fail/JasonReedPruning.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/fail/JasonReedPruning.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | null | null | null |
test/fail/JasonReedPruning.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | null | null | null |
-- Andreas, 2012-05-04 Example from Jason Reed, LFMTP 2009
{-# OPTIONS --allow-unsolved-metas #-}
-- The option is supplied to force a real error to pass the regression test.
module JasonReedPruning where
open import Common.Equality
open import Common.Product
data o : Set where
f : o -> o
test :
let U : o → o
U = _
V : o → o
V = _
W : o → o
W = _
in (x y : o) → U x ≡ f (V (W y))
× V x ≡ U (W y)
test x y = refl , refl
{-
Considering U (W y) = V x, we can prune x from V
V x = V'
After instantiation
U x = f V' (solved)
V' = U (W y) (not solved)
U = \ x → f V'
V' = f V'
occurs check fails
-}
| 19.25
| 76
| 0.532468
|
43fa482d0e0aeda9378af2f0ae2517ef87958152
| 5,033
|
agda
|
Agda
|
list-thms2.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
list-thms2.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
list-thms2.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module list-thms2 where
open import bool
open import bool-thms
open import bool-thms2
open import functions
open import list
open import list-thms
open import nat
open import nat-thms
open import product-thms
open import logic
list-and-++ : ∀(l1 l2 : 𝕃 𝔹) → list-and (l1 ++ l2) ≡ (list-and l1) && (list-and l2)
list-and-++ [] l2 = refl
list-and-++ (x :: l1) l2 rewrite (list-and-++ l1 l2) | (&&-assoc x (list-and l1) (list-and l2))= refl
list-or-++ : ∀(l1 l2 : 𝕃 𝔹) → list-or (l1 ++ l2) ≡ (list-or l1) || (list-or l2)
list-or-++ [] l2 = refl
list-or-++ (x :: l1) l2 rewrite (list-or-++ l1 l2) | (||-assoc x (list-or l1) (list-or l2)) = refl
++-singleton : ∀{ℓ}{A : Set ℓ}(a : A)(l1 l2 : 𝕃 A) → (l1 ++ [ a ]) ++ l2 ≡ l1 ++ (a :: l2)
++-singleton a l1 [] rewrite ++[] (l1 ++ a :: []) = refl
++-singleton a l1 l2 rewrite (++-assoc l1 [ a ] l2) = refl
list-member-++ : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l1 l2 : 𝕃 A) →
list-member eq a (l1 ++ l2) ≡ (list-member eq a l1) || (list-member eq a l2)
list-member-++ eq a [] l2 = refl
list-member-++ eq a (x :: l1) l2 with eq a x
list-member-++ eq a (x :: l1) l2 | tt = refl
list-member-++ eq a (x :: l1) l2 | ff rewrite (list-member-++ eq a l1 l2) = refl
list-member-++2 : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l1 l2 : 𝕃 A) →
list-member eq a l1 ≡ tt →
list-member eq a (l1 ++ l2) ≡ tt
list-member-++2 eq a [] l2 ()
list-member-++2 eq a (x :: l1) l2 p with eq a x
list-member-++2 eq a (x :: l1) l2 p | tt = refl
list-member-++2 eq a (x :: l1) l2 p | ff rewrite (list-member-++2 eq a l1 l2 p) = refl
list-member-++3 : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l1 l2 : 𝕃 A) →
list-member eq a l2 ≡ tt →
list-member eq a (l1 ++ l2) ≡ tt
list-member-++3 eq a [] l2 p = p
list-member-++3 eq a (x :: l1) l2 p with eq a x
list-member-++3 eq a (x :: l1) l2 p | tt = refl
list-member-++3 eq a (x :: l1) l2 p | ff rewrite (list-member-++3 eq a l1 l2 p) = refl
filter-ff-repeat : ∀{ℓ}{A : Set ℓ}{p : A → 𝔹}{a : A}(n : ℕ) →
p a ≡ ff →
filter p (repeat n a) ≡ []
filter-ff-repeat zero p1 = refl
filter-ff-repeat{ℓ}{A}{p0}{a} (suc n) p1 with keep (p0 a)
filter-ff-repeat{ℓ}{A}{p0}{a} (suc n) p1 | tt , y rewrite y = 𝔹-contra (sym p1)
filter-ff-repeat{ℓ}{A}{p0}{a} (suc n) p1 | ff , y rewrite y = filter-ff-repeat {ℓ} {A} {p0} {a} n y
is-empty-distr : ∀{ℓ}{A : Set ℓ} (l1 l2 : 𝕃 A) → is-empty (l1 ++ l2) ≡ (is-empty l1) && (is-empty l2)
is-empty-distr [] l2 = refl
is-empty-distr (x :: l1) l2 = refl
is-empty-reverse : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → is-empty l ≡ is-empty (reverse l)
is-empty-reverse [] = refl
is-empty-reverse (x :: xs) rewrite (reverse-++h (x :: []) xs) | (is-empty-distr (reverse-helper [] xs) (x :: []))
| (&&-comm (is-empty (reverse-helper [] xs)) ff) = refl
reverse-length : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → length (reverse l) ≡ length l
reverse-length l = length-reverse-helper [] l
last-distr : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A)(x : A)(p : is-empty l ≡ ff) → last (x :: l) refl ≡ last l p
last-distr [] x ()
last-distr (x :: l) x2 refl = refl
is-empty-[] : ∀{ℓ}{A : Set ℓ} (l : 𝕃 A)(p : is-empty l ≡ tt) → l ≡ []
is-empty-[] [] p = refl
is-empty-[] (x :: l) ()
rev-help-empty : ∀ {ℓ}{A : Set ℓ} (l1 l2 : 𝕃 A) → (p1 : is-empty l2 ≡ ff) →
is-empty (reverse-helper l1 l2) ≡ ff
rev-help-empty l1 [] ()
rev-help-empty l1 (x :: l2) refl rewrite reverse-++h (x :: l1) l2 | is-empty-distr (reverse-helper [] l2) (x :: l1)
| (&&-comm (is-empty (reverse-helper [] l2)) ff) = refl
is-empty-revh : ∀{ℓ}{A : Set ℓ}(h l : 𝕃 A) → is-empty l ≡ ff → is-empty (reverse-helper h l) ≡ ff
is-empty-revh h l p = rev-help-empty h l p
head-last-reverse-lem : ∀{ℓ}{A : Set ℓ}(h l : 𝕃 A)(p : is-empty l ≡ ff) → last l p ≡ head (reverse-helper h l) (is-empty-revh h l p)
head-last-reverse-lem h [] ()
head-last-reverse-lem h (x :: []) _ = refl
head-last-reverse-lem h (x :: y :: l) refl = head-last-reverse-lem (x :: h) (y :: l) refl
head-last-reverse : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A)(p : is-empty l ≡ ff) → last l p ≡ head (reverse l) (rev-help-empty [] l p)
head-last-reverse [] ()
head-last-reverse (x :: l) p with keep (is-empty l)
head-last-reverse (x :: l) refl | tt , b rewrite is-empty-[] l b = refl
head-last-reverse (x :: l) refl | ff , b rewrite (last-distr l x b) = head-last-reverse-lem (x :: []) l b
reverse-reverse : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → reverse (reverse l) ≡ l
reverse-reverse [] = refl
reverse-reverse (x :: l) rewrite (reverse-++h (x :: []) l) | (reverse-++ (reverse-helper [] l) (x :: [])) | reverse-reverse l = refl
empty++elem : ∀ {ℓ}{A : Set ℓ} (a : A) (l : 𝕃 A) → is-empty ( l ++ [ a ]) ≡ ff
empty++elem a [] = refl
empty++elem a (x :: l) = refl
last-++ : ∀{ℓ}{A : Set ℓ} (a : A) (l : 𝕃 A) → last (l ++ [ a ]) (empty++elem a l) ≡ a
last-++ a [] = refl
last-++ a (x :: l) rewrite last-distr (l ++ [ a ]) x (empty++elem a l) | last-++ a l = refl
| 46.174312
| 133
| 0.532287
|
30dd85a57dcec5345f5949de5e594e3bc7ab249c
| 2,174
|
agda
|
Agda
|
Cubical/HITs/2GroupoidTruncation/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/2GroupoidTruncation/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/2GroupoidTruncation/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-
This file contains:
- Properties of 2-groupoid truncations
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.2GroupoidTruncation.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.HITs.2GroupoidTruncation.Base
private
variable
ℓ : Level
A : Type ℓ
rec : ∀ {B : Type ℓ} → is2Groupoid B → (A → B) → ∥ A ∥₄ → B
rec gB f ∣ x ∣₄ = f x
rec gB f (squash₄ _ _ _ _ _ _ t u i j k l) =
gB _ _ _ _ _ _ (λ m n o → rec gB f (t m n o)) (λ m n o → rec gB f (u m n o))
i j k l
elim : {B : ∥ A ∥₄ → Type ℓ}
(bG : (x : ∥ A ∥₄) → is2Groupoid (B x))
(f : (x : A) → B ∣ x ∣₄) (x : ∥ A ∥₄) → B x
elim bG f ∣ x ∣₄ = f x
elim bG f (squash₄ x y p q r s u v i j k l) =
isOfHLevel→isOfHLevelDep 4 bG _ _ _ _ _ _
(λ j k l → elim bG f (u j k l)) (λ j k l → elim bG f (v j k l))
(squash₄ x y p q r s u v)
i j k l
elim2 : {B : ∥ A ∥₄ → ∥ A ∥₄ → Type ℓ}
(gB : ((x y : ∥ A ∥₄) → is2Groupoid (B x y)))
(g : (a b : A) → B ∣ a ∣₄ ∣ b ∣₄)
(x y : ∥ A ∥₄) → B x y
elim2 gB g = elim (λ _ → is2GroupoidΠ (λ _ → gB _ _))
(λ a → elim (λ _ → gB _ _) (g a))
elim3 : {B : (x y z : ∥ A ∥₄) → Type ℓ}
(gB : ((x y z : ∥ A ∥₄) → is2Groupoid (B x y z)))
(g : (a b c : A) → B ∣ a ∣₄ ∣ b ∣₄ ∣ c ∣₄)
(x y z : ∥ A ∥₄) → B x y z
elim3 gB g = elim2 (λ _ _ → is2GroupoidΠ (λ _ → gB _ _ _))
(λ a b → elim (λ _ → gB _ _ _) (g a b))
is2Groupoid2GroupoidTrunc : is2Groupoid ∥ A ∥₄
is2Groupoid2GroupoidTrunc a b p q r s = squash₄ a b p q r s
2GroupoidTruncIdempotent≃ : is2Groupoid A → ∥ A ∥₄ ≃ A
2GroupoidTruncIdempotent≃ {A = A} hA = isoToEquiv f
where
f : Iso ∥ A ∥₄ A
Iso.fun f = rec hA (idfun A)
Iso.inv f x = ∣ x ∣₄
Iso.rightInv f _ = refl
Iso.leftInv f = elim (λ _ → isOfHLevelSuc 4 is2Groupoid2GroupoidTrunc _ _) (λ _ → refl)
2GroupoidTruncIdempotent : is2Groupoid A → ∥ A ∥₄ ≡ A
2GroupoidTruncIdempotent hA = ua (2GroupoidTruncIdempotent≃ hA)
| 31.507246
| 89
| 0.569917
|
35a717f46694c7e210750fc4912ce475eb357857
| 14,366
|
agda
|
Agda
|
proglangs-learning/Agda/sv20/assign1/First.agda
|
helq/old_code
|
a432faf1b340cb379190a2f2b11b997b02d1cd8d
|
[
"CC0-1.0"
] | null | null | null |
proglangs-learning/Agda/sv20/assign1/First.agda
|
helq/old_code
|
a432faf1b340cb379190a2f2b11b997b02d1cd8d
|
[
"CC0-1.0"
] | 4
|
2020-03-10T19:20:21.000Z
|
2021-06-07T15:39:48.000Z
|
proglangs-learning/Agda/sv20/assign1/First.agda
|
helq/old_code
|
a432faf1b340cb379190a2f2b11b997b02d1cd8d
|
[
"CC0-1.0"
] | null | null | null |
module sv20.assign1.First where
{- Code partially taken from the book "Programming Language Foundations in
- Agda" by Philip Wadler, Wen Kokke, Jeremy Siek and many others. The book
- can be found at https://plfa.github.io/
-
- Based on chapter 1 - Natural numbers - https://plfa.github.io/Naturals/
-
- The solution for the homework can be found from line 161
-}
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
-- Gives us the power of writing `3` to mean `suc (suc (suc zero))` :)
{-# BUILTIN NATURAL ℕ #-}
import Relation.Binary.PropositionalEquality as Eq
open import Function.Base using (flip)
open Eq using (_≡_; _≢_; refl; cong; sym; trans)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
_+_ : ℕ → ℕ → ℕ
zero + n = n -- +-def₀
(suc m) + n = suc (m + n) -- +-def₁
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
_^_ : ℕ → ℕ → ℕ
n ^ zero = suc zero
n ^ (suc m) = n * (n ^ m)
-- Monus
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
infixl 6 _+_ _∸_
infixl 7 _*_
infixr 8 _^_
assoc-+ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
assoc-+ zero n p = refl
assoc-+ (suc m) n p rewrite assoc-+ m n p = refl
comm-+₀ : ∀ (m : ℕ) → m + zero ≡ m
comm-+₀ zero = refl
-- Proofs on natural numbers can be written in a manner that ressembles a pen
-- and paper proof. For example:
comm-+₀ (suc n) =
begin
suc n + zero
≡⟨⟩ -- By addition definition
suc (n + zero)
≡⟨ cong suc (comm-+₀ n) ⟩
suc n
∎
-- But often, proofs are written for Agda to check them and not to humans to
-- read them. The above proof can be written succintly as:
--comm-+₀ (suc n) rewrite comm-+₀ n = refl
succ_right : ∀ (n m : ℕ) → suc (n + m) ≡ n + suc m
succ_right zero m = refl
succ_right (suc n) m rewrite succ_right n m = refl
--succ_right (suc n) m = cong suc (succ_right n m)
--succ_right (suc n) m =
-- begin
-- suc (suc n + m)
-- ≡⟨⟩
-- suc (suc (n + m))
-- ≡⟨ cong suc (succ_right n m) ⟩
-- suc (n + suc m)
-- ≡⟨⟩
-- suc n + suc m
-- ∎
comm-+ : ∀ (n m : ℕ) → n + m ≡ m + n
comm-+ zero n = sym (comm-+₀ n)
comm-+ (suc n) m rewrite comm-+ n m | succ_right m n = refl
--comm-+ (suc n) m = trans (cong suc (comm-+ n m)) (succ_right m n)
--comm-+ (suc n) m =
-- begin
-- suc n + m
-- ≡⟨⟩ -- +-def₁
-- suc (n + m)
-- ≡⟨ cong suc (comm-+ n m) ⟩
-- suc (m + n)
-- ≡⟨ succ_right m n ⟩
-- m + suc n
-- ∎
swap-m-n-+ : ∀ (m n p) → m + (n + p) ≡ n + (m + p)
swap-m-n-+ m n p rewrite
sym (assoc-+ m n p)
| sym (assoc-+ n m p)
| comm-+ m n
= refl
right-zero-* : ∀ (n : ℕ) → n * 0 ≡ 0
right-zero-* zero = refl
right-zero-* (suc n) rewrite right-zero-* n = refl
suc-right-* : ∀ (m n) → m * suc n ≡ m + m * n
suc-right-* zero n = refl
suc-right-* (suc m) n
rewrite
suc-right-* m n
| sym (assoc-+ n m (m * n))
| comm-+ n m
| assoc-+ m n (m * n)
= refl
comm-* : ∀ (m n : ℕ) → m * n ≡ n * m
comm-* zero n rewrite right-zero-* n = refl
comm-* (suc m) n
rewrite
comm-* m n
| suc-right-* n m
= refl
distr-*-+ : ∀ (m n p) → (m + n) * p ≡ m * p + n * p
distr-*-+ zero _ _ = refl
distr-*-+ (suc m) n p
rewrite
distr-*-+ m n p
| assoc-+ p (m * p) (n * p)
= refl
distl-*-+ : ∀ (p m n) → p * (m + n) ≡ p * m + p * n
distl-*-+ zero _ _ = refl
distl-*-+ (suc p) m n
rewrite
distl-*-+ p m n
| sym (assoc-+ (m + n) (p * m) (p * n))
| sym (assoc-+ (m + p * m) n (p * n))
| assoc-+ m n (p * m)
| comm-+ n (p * m)
| assoc-+ m (p * m) n
= refl
assoc-* : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
assoc-* zero n p = refl
assoc-* (suc m) n p
rewrite
assoc-* m n p
| distr-*-+ n (m * n) p
| assoc-* m n p
= refl
swap-m-n-* : ∀ (m n p) → m * (n * p) ≡ n * (m * p)
swap-m-n-* m n p rewrite
sym (assoc-* m n p)
| sym (assoc-* n m p)
| comm-* m n
= refl
------------------------------------------------------------------------------------------
-- HOMEWORK SOLUTION --
------------------------------------------------------------------------------------------
-- We want to proof that:
distr-^-* : ∀ (m n p) → (m * n) ^ p ≡ (m ^ p) * (n ^ p)
-- We will prove the `distr-^-*` by induction. To prove something by induction
-- in Agda, we use recursion.
-- The first basic case is when `p = 0`
distr-^-* m n zero =
begin
(m * n) ^ zero
≡⟨⟩ -- The builtin option "NATURAL" allows us to write `0` instead of `zero`
(m * n) ^ 0
≡⟨⟩ -- because: n ^ zero = suc zero
suc 0
≡⟨⟩ -- because: zero + n = n
suc (0 + 0)
≡⟨⟩ -- because: (suc m) + n = suc (m + n)
suc 0 + 0
≡⟨⟩ -- Agda builtin option "NATURAL" allows us to write `1` instead of `suc 0`
1 + 0
≡⟨⟩ -- because: zero * n = zero
1 + 0 * 1
≡⟨⟩ -- because: (suc m) * n = n + (m * n)
suc 0 * 1
≡⟨⟩ -- `1` instead of `suc 0`
1 * 1
≡⟨⟩ -- because: n ^ zero = suc zero
1 * (n ^ 0)
≡⟨⟩ -- because: n ^ zero = suc zero
(m ^ 0) * (n ^ 0)
∎
-- Agda computes every expression it is given until it can't apply any more
-- rules, i.e, Agda reduces every expression to its normal form.
-- For example, if we give Agda the expression `2 + 1`, it will apply the
-- rule `(suc m) + n = suc (m + n)` until it arrives to
-- `suc (suc (suc zero))`, `3`.
--
-- Notice that every line in the previous proof reduces to `1`. This means
-- that Agda read the previous proof as:
--
--distr-^-* m n zero =
-- begin
-- 1
-- ≡⟨⟩
-- 1
-- ≡⟨⟩ -- ...
-- 1
-- ≡⟨⟩
-- 1
-- ∎
--
-- So we could have written a shorter proof saying that `1 ≡⟨⟩ 1 ∎` and it
-- would sufficient for Agda to approve our proof.
--
--distr-^-* _ _ zero = 1 ≡⟨⟩ 1 ∎
--
-- In fact, `1 ≡⟨⟩ 1 ∎` can be written as `refl` in Agda.
--
--distr-^-* _ _ zero = refl
-- The following two base cases can be easily proven with the same technique as
-- the previous proof:
distr-^-* zero _ (suc p) = refl
-- For the last base case, we need a little more human involvement because the
-- expressions do not reduce completly to a common normal form.
distr-^-* (suc m) zero (suc p) =
begin
(suc m * 0) ^ suc p
≡⟨⟩ -- Agda reduces the expression to
m * 0 * (m * 0) ^ p
-- Applying `right-zero-*` (`n * 0 ≡ 0`) lemma to the left side
≡⟨ cong (_* (m * 0) ^ p) (right-zero-* m) ⟩
0 * (m * 0) ^ p
≡⟨⟩ -- reduces to
0
-- Applying `sym ∘ right-zero-*` (`0 ≡ n * 0`) lemma to the left side
≡⟨ sym (right-zero-* (suc m ^ suc p)) ⟩
(suc m ^ suc p) * 0
≡⟨⟩ -- reduces to
(suc m ^ p + m * suc m ^ p) * 0
≡⟨⟩ -- reduced from our goal
(suc m ^ suc p) * (0 ^ suc p)
∎
--
-- Notice how the previous proof required us to tell Agda which "lemmas" to use
-- to be able to link the left side of the proof with the right side.
--
-- As before, we have more ways to write the previous proof. We can forgo all
-- the intermediate steps and tell Agda which lemmas the proof needs.
--
--distr-^-* (suc m) 0 (suc p) =
-- trans
-- (cong (_* (m * 0) ^ p) (right-zero-* m))
-- (sym (right-zero-* (suc m ^ suc p)))
--
-- An even shorter proof can be written using `rewrite`. `rewrite` will try to
-- apply the `lemmas` we tell it to apply once, descending order. If the
-- rewriting process works by the end, we will only need `refl` to indicate
-- that both sides of the proof are the same.
--
--distr-^-* (suc m) zero (suc p)
-- rewrite
---- We start with what we want to proof:
----
---- (suc m * zero) ^ suc p ≡ suc m ^ suc p * zero ^ suc p
----
---- which reduces to
----
---- m * 0 * (m * 0) ^ p ≡ (suc m ^ p + m * suc m ^ p) * 0
----
-- right-zero-* m -- asking to rewrite all appearances of `m * 0` for `0`
----
---- λ m p → 0 * 0 ^ p ≡ (suc m ^ p + m * suc m ^ p) * 0
----
---- which reduces to
----
---- 0 ≡ (suc m ^ p + m * suc m ^ p) * 0
----
-- -- asking to rewrite all appearances of `(suc m ^ suc p) * 0` for `0`
-- -- (notice that: `(suc m ^ suc p)` reduces to `(suc m ^ p + m * suc m ^ p)`)
-- | right-zero-* (suc m ^ suc p)
----
---- 0 ≡ 0
----
---- We have arrived to a expression where both sides are equal. Thus we have
---- found a proof.
-- = refl
--
-- The final part of the inductive proof requires us to proof the inductive
-- case:
distr-^-* (suc m) (suc n) (suc p)
rewrite
-- First we start with expression:
--
-- (m * n) ^ p ≡ (m ^ p) * (n ^ p)
--
-- Reducing the expression to its normal form:
--
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡ (suc m ^ p + m * suc m ^ p) * (suc n ^ p + n * suc n ^ p)
-- Applying distributivity of _+_ over _*_
distr-*-+ (suc m ^ p) (m * suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * (suc n ^ p + n * suc n ^ p)
-- + m * suc m ^ p * (suc n ^ p + n * suc n ^ p)
| assoc-* m (suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * (suc n ^ p + n * suc n ^ p)
-- + m * (suc m ^ p * (suc n ^ p + n * suc n ^ p))
| distl-*-+ (suc m ^ p) (suc n ^ p) (n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| comm-* m (suc n)
-- suc (n + (m + n * m)) ^ p
-- + (n + (m + n * m)) * suc (n + (m + n * m)) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| comm-* n m
-- suc (n + (m + m * n)) ^ p
-- + (n + (m + m * n)) * suc (n + (m + m * n)) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| sym (suc-right-* m n)
-- suc (n + m * suc n) ^ p
-- + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distr-^-* (suc m) (suc n) p -- INDUCTIVE HYPOTHESIS!!
-- suc m ^ p * suc n ^ p + (n + m * suc n) * (suc m ^ p * suc n ^ p)
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distr-*-+ n (m * suc n) (suc m ^ p * suc n ^ p)
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + m * suc n * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distl-*-+ m (suc m ^ p * suc n ^ p) (suc m ^ p * (n * suc n ^ p))
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + m * suc n * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| comm-* m (suc n)
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + (m + n * m) * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| distr-*-+ m (n * m) (suc m ^ p * suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| swap-m-n-* n (suc m ^ p) (suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| swap-m-n-* (suc m ^ p) n (suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (n * (suc m ^ p * suc n ^ p)))
| sym (assoc-* m n (suc m ^ p * suc n ^ p))
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * n * (suc m ^ p * suc n ^ p))
| comm-* m n
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
| assoc-+ (suc m ^ p * suc n ^ p) (n * (suc m ^ p * suc n ^ p))
(m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
--
-- We finally find that the two expressions are equal!
--
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
--
-- QED
= refl
-- The full proof without comments:
--distr-^-* : ∀ (m n p) → (m * n) ^ p ≡ (m ^ p) * (n ^ p)
--distr-^-* _ _ zero = refl
--distr-^-* zero _ (suc p) = refl
--distr-^-* (suc m) zero (suc p)
-- rewrite
-- right-zero-* m
-- | right-zero-* (suc m ^ suc p)
-- = refl
--distr-^-* (suc m) (suc n) (suc p)
-- rewrite
-- distr-*-+ (suc m ^ p) (m * suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- | assoc-* m (suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- | distl-*-+ (suc m ^ p) (suc n ^ p) (n * suc n ^ p)
-- | comm-* m (suc n)
-- | comm-* n m
-- | sym (suc-right-* m n)
-- | distr-^-* (suc m) (suc n) p
-- | distr-*-+ n (m * suc n) (suc m ^ p * suc n ^ p)
-- | distl-*-+ m (suc m ^ p * suc n ^ p) (suc m ^ p * (n * suc n ^ p))
-- | comm-* m (suc n)
-- | distr-*-+ m (n * m) (suc m ^ p * suc n ^ p)
-- | swap-m-n-* n (suc m ^ p) (suc n ^ p)
-- | swap-m-n-* (suc m ^ p) n (suc n ^ p)
-- | sym (assoc-* m n (suc m ^ p * suc n ^ p))
-- | comm-* m n
-- | assoc-+ (suc m ^ p * suc n ^ p) (n * (suc m ^ p * suc n ^ p))
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
-- = refl
| 32.138702
| 90
| 0.450717
|
8b1d613500ca1dab89ffdda1138ffa9c3b2eda10
| 3,206
|
agda
|
Agda
|
agda-stdlib/src/Data/Vec/Functional/Relation/Unary/All/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Vec/Functional/Relation/Unary/All/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Vec/Functional/Relation/Unary/All/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to All
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Functional.Relation.Unary.All.Properties where
open import Data.Fin.Base
open import Data.Fin.Properties
open import Data.Nat.Base
open import Data.Product as Σ using (_×_; _,_; proj₁; proj₂; uncurry)
open import Data.Sum.Base using (_⊎_; inj₁; inj₂; [_,_])
open import Data.Vec.Functional as VF hiding (map)
open import Data.Vec.Functional.Relation.Unary.All
open import Function
open import Level using (Level)
open import Relation.Unary
private
variable
a b c p q r ℓ : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- map
module _ {P : Pred A p} {Q : Pred B q} {f : A → B} where
map⁺ : (∀ {x} → P x → Q (f x)) →
∀ {n xs} → All P {n = n} xs → All Q (VF.map f xs)
map⁺ pq ps i = pq (ps i)
------------------------------------------------------------------------
-- replicate
module _ {P : Pred A p} {x : A} {n : ℕ} where
replicate⁺ : P x → All P (replicate {n = n} x)
replicate⁺ = const
------------------------------------------------------------------------
-- _⊛_
module _ {P : Pred A p} {Q : Pred B q} where
⊛⁺ : ∀ {n} {fs : Vector (A → B) n} {xs} →
All (λ f → ∀ {x} → P x → Q (f x)) fs → All P xs → All Q (fs ⊛ xs)
⊛⁺ pqs ps i = (pqs i) (ps i)
------------------------------------------------------------------------
-- zipWith
module _ {P : Pred A p} {Q : Pred B q} {R : Pred C r} where
zipWith⁺ : ∀ {f} → (∀ {x y} → P x → Q y → R (f x y)) → ∀ {n xs ys} →
All P xs → All Q ys → All R (zipWith f {n = n} xs ys)
zipWith⁺ pqr ps qs i = pqr (ps i) (qs i)
------------------------------------------------------------------------
-- zip
module _ {P : Pred A p} {Q : Pred B q} {n} {xs : Vector A n} {ys} where
zip⁺ : All P xs → All Q ys → All (P ⟨×⟩ Q) (zip xs ys)
zip⁺ ps qs i = ps i , qs i
zip⁻ : All (P ⟨×⟩ Q) (zip xs ys) → All P xs × All Q ys
zip⁻ pqs = proj₁ ∘ pqs , proj₂ ∘ pqs
------------------------------------------------------------------------
-- head
head⁺ : ∀ (P : Pred A p) {n v} → All P v → P (head {n = n} v)
head⁺ P ps = ps zero
------------------------------------------------------------------------
-- tail
tail⁺ : ∀ (P : Pred A p) {n v} → All P v → All P (tail {n = n} v)
tail⁺ P ps = ps ∘ suc
------------------------------------------------------------------------
-- ++
module _ (P : Pred A p) {m n : ℕ} {xs : Vector A m} {ys : Vector A n} where
++⁺ : All P xs → All P ys → All P (xs ++ ys)
++⁺ pxs pys i with splitAt m i
... | inj₁ i′ = pxs i′
... | inj₂ j′ = pys j′
module _ (P : Pred A p) {m n : ℕ} (xs : Vector A m) {ys : Vector A n} where
++⁻ˡ : All P (xs ++ ys) → All P xs
++⁻ˡ ps i with ps (inject+ n i)
... | p rewrite splitAt-inject+ m n i = p
++⁻ʳ : All P (xs ++ ys) → All P ys
++⁻ʳ ps i with ps (raise m i)
... | p rewrite splitAt-raise m n i = p
++⁻ : All P (xs ++ ys) → All P xs × All P ys
++⁻ ps = ++⁻ˡ ps , ++⁻ʳ ps
| 29.412844
| 75
| 0.411104
|
347582945ec4c8a4e04be35bc1616f68153d8f57
| 1,973
|
agda
|
Agda
|
test/Fail/Issue3882.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue3882.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue3882.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
data _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where
instance refl : x ≡ x
{-# BUILTIN REWRITE _≡_ #-}
postulate
admit : ∀ {ℓ} {A : Set ℓ} → A
X : Set
postulate
Wrap : Set → Set
wrap : {A : Set} → A → Wrap A
rec : (A : Set) (P : Set) → (A → P) → Wrap A → P
Rec : (A : Set) (P : Set₁) → (A → P) → Wrap A → P
Rec-β : {A : Set} (P : Set₁) → ∀ f → (a : A) → Rec A P f (wrap a) ≡ f a
{-# REWRITE Rec-β #-} -- bug disappears without this
record Σ {ℓ} (A : Set ℓ) (B : A → Set) : Set ℓ where
constructor _,_
field
fst : A
snd : B fst
open Σ public
-- bug disappears if Comp or isFib is not wrapped in a record
record Comp (A : X → Set) : Set where
field
comp : ∀ s → A s
open Comp public
record isFib {Γ : Set} (A : Γ → Set) : Set where
field
lift : (p : X → Γ) → Comp (λ x → A (p x))
open isFib public
compSys : (ψ : X → Set)
(A : Σ X (λ x → Wrap (ψ x)) → Set)
(u : ∀ s → Wrap (ψ s)) (s : X)
→ A (s , u s)
compSys ψ A u s =
rec (∀ i → ψ i) (A (s , u s))
(λ v →
subst (λ s → wrap (v s)) (λ s → u s) admit
.lift (λ s → s) .comp s)
admit
where
subst : (w w' : ∀ i → Wrap (ψ i)) → isFib (λ s → A (s , w s)) → isFib (λ s → A (s , w' s))
subst = admit
-- bug disappears if ×id is inlined
×id : {A A' : Set} {B : A' → Set} (f : A → A') → Σ A (λ x → B (f x)) → Σ A' B
×id f (a , b) = (f a , b)
fib : (ψ : X → Set) (A : Σ X (λ x → Wrap (ψ x)) → Set) → isFib A
fib ψ A .lift p .comp =
compSys (λ x → ψ (p x .fst)) (λ xu → A (×id (λ x → p x .fst) xu)) (λ x → p x .snd)
-- bug seems to disappear if the underscore in (Σ Set _) is filled in
template : (ψ : X → Set) → X → Σ (Σ X (λ x → Wrap (ψ x)) → Set) isFib
template ψ n =
(_ , fib ψ (λ b → Rec (ψ (b .fst)) (Σ Set _) (λ _ → admit) (b .snd) .fst))
eq : {B : Set₁} (f : X → B) {x y : X} → f x ≡ f y
eq = admit
templateEq : (ψ : X → Set) (n₀ : X) → template ψ n₀ ≡ template ψ n₀
templateEq ψ n₀ = eq (template ψ)
| 24.974684
| 92
| 0.489103
|
ad6aab2d832e215aa20babe8e8dc074875b572fe
| 2,388
|
agda
|
Agda
|
test/interaction/NiceGoals.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/interaction/NiceGoals.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/interaction/NiceGoals.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module NiceGoals where
------------------------------------------------------------------------
postulate
Level : Set
zero : Level
suc : (i : Level) → Level
_⊔_ : Level → Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
------------------------------------------------------------------------
record RawMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Carrier → Carrier → Set ℓ
_∙_ : Carrier → Carrier → Carrier
ε : Carrier
module M (rm : RawMonoid zero zero) where
open RawMonoid rm
thm : ∀ x → x ∙ ε ≈ x
thm = {!!}
-- agda2-goal-and-context:
-- rm : RawMonoid zero zero
-- ------------------------
-- Goal: (x : RawMonoid.Carrier rm) →
-- RawMonoid._≈_ rm (RawMonoid._∙_ rm x (RawMonoid.ε rm)) x
------------------------------------------------------------------------
record RawMonoid′ : Set₁ where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set
_≈_ : Carrier → Carrier → Set
_∙_ : Carrier → Carrier → Carrier
ε : Carrier
module M′ (rm : RawMonoid′) where
open RawMonoid′ rm
thm′ : ∀ x → x ∙ ε ≈ x
thm′ = {!!}
-- agda2-goal-and-context:
-- rm : RawMonoid′
-- ---------------
-- Goal: (x : Carrier) → x ∙ ε ≈ x
------------------------------------------------------------------------
-- UP isn't relevant.
record RawMonoid″ (Carrier : Set) : Set₁ where
infixl 7 _∙_
infix 4 _≈_
field
_≈_ : Carrier → Carrier → Set
_∙_ : Carrier → Carrier → Carrier
ε : Carrier
data Bool : Set where
true false : Bool
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A)(xs : List A) → List A
module M″ (rm : RawMonoid″ (List Bool)) where
open RawMonoid″ rm
thm″ : ∀ x → x ∙ ε ≈ x
thm″ = {!!}
-- agda2-goal-and-context:
-- rm : RawMonoid″ (List Bool)
-- ---------------------------
-- Goal: (x : List Bool) →
-- RawMonoid″._≈_ rm (RawMonoid″._∙_ rm x (RawMonoid″.ε rm)) x
module M₁ (Z : Set₁) where
postulate
P : Set
Q : Set → Set
module M₂ (X Y : Set) where
module M₁′ = M₁ Set
open M₁′
p : P
p = {!!}
q : Q X
q = {!!}
postulate X : Set
pp : M₂.M₁′.P X X
pp = {!!}
| 19.414634
| 72
| 0.45603
|
4369bd472794f97584559c9cf0ed26c6b4c2ea3c
| 555
|
agda
|
Agda
|
Agda/AML.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | 2
|
2020-02-03T05:05:52.000Z
|
2020-03-11T10:35:42.000Z
|
Agda/AML.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | null | null | null |
Agda/AML.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | 1
|
2019-12-13T04:50:46.000Z
|
2019-12-13T04:50:46.000Z
|
module AML where
open import Level
open import Data.Product
data satisfied (a : Set) (m : Set → Set) : Set where
s : m a → satisfied a m
data reachability (m₀ : Set → Set) (m : Set → Set) : Set where
tt : reachability m₀ m
data necessarity (m₀ : Set → Set) (a : Set) : Set₁ where
n : ∀ m → (reachability m₀ m) → satisfied a m → necessarity m₀ a
□_ : Set → Set₁
□_ = necessarity {!!}
data posibility (m₀ : Set → Set) (a : Set) : Set₁ where
p : ∃[ m ](reachability m₀ m → satisfied a m) → posibility m₀ a
◇_ : Set → Set₁
◇_ = posibility {!!}
| 24.130435
| 66
| 0.621622
|
58d5b3f906cffdfdfc4cdea58dbcc26f9b8af597
| 830
|
agda
|
Agda
|
HoTT/Exercises/Chapter3/Exercise10.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
HoTT/Exercises/Chapter3/Exercise10.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
HoTT/Exercises/Chapter3/Exercise10.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
open import HoTT.Equivalence.Lift
open import HoTT.Identity.Sigma
open import HoTT.Identity.Universe
open import HoTT.HLevel
open import HoTT.Logic
module HoTT.Exercises.Chapter3.Exercise10 {i} where
postulate
lem : LEM {lsuc i}
_ : Prop𝒰 i ≃ Prop𝒰 (lsuc i)
_ = f , qinv→isequiv (g , η , ε)
where
f : _
f P = LiftProp P
g : _
g P with lem P
... | inl _ = ⊤
... | inr _ = ⊥
η : g ∘ f ~ id
η P with lem (f P)
... | inl t = hlevel⁼ (ua (prop-equiv (const (lower t)) (const ★)))
... | inr f = hlevel⁼ (ua (prop-equiv 𝟎-rec (𝟎-rec ∘ f ∘ lift)))
ε : f ∘ g ~ id
ε P with lem P
... | inl t = hlevel⁼ (ua (Lift-equiv ∙ₑ prop-equiv (const t) (const ★)))
... | inr f = hlevel⁼ (ua (Lift-equiv ∙ₑ prop-equiv 𝟎-rec (𝟎-rec ∘ f)))
| 25.9375
| 75
| 0.603614
|
43f980e126ff82cc2e3193932c44ef7d04c1acab
| 3,888
|
agda
|
Agda
|
UniDB/Morph/Shifts.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Morph/Shifts.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Morph/Shifts.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
module UniDB.Morph.Shifts where
open import UniDB.Spec
--------------------------------------------------------------------------------
data Shifts : MOR where
refl : {γ : Dom} → Shifts γ γ
step : {γ₁ γ₂ : Dom} (ξ : Shifts γ₁ γ₂) → Shifts γ₁ (suc γ₂)
skip : {γ₁ γ₂ : Dom} (ξ : Shifts γ₁ γ₂) → Shifts (suc γ₁) (suc γ₂)
shiftIx : {γ₁ γ₂ : Dom} (ξ : Shifts γ₁ γ₂) (i : Ix γ₁) → Ix γ₂
shiftIx refl i = i
shiftIx (step ξ) i = suc (shiftIx ξ i)
shiftIx (skip ξ) zero = zero
shiftIx (skip ξ) (suc i) = suc (shiftIx ξ i)
--------------------------------------------------------------------------------
instance
iLkShifts : {T : STX} {{vrT : Vr T}} → Lk T Shifts
lk {{iLkShifts}} ξ i = vr (shiftIx ξ i)
iUpShifts : Up Shifts
_↑₁ {{iUpShifts}} refl = refl
_↑₁ {{iUpShifts}} ξ = skip ξ
_↑_ {{iUpShifts}} ξ 0 = ξ
_↑_ {{iUpShifts}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpShifts}} ξ = refl
↑-suc {{iUpShifts}} ξ δ⁺ = refl
iIdmShifts : Idm Shifts
idm {{iIdmShifts}} γ = refl {γ}
iWkmShifts : Wkm Shifts
wkm {{iWkmShifts}} zero = idm _
wkm {{iWkmShifts}} (suc δ) = step (wkm δ)
iCompShifts : Comp Shifts
_⊙_ {{iCompShifts}} ξ₁ refl = ξ₁
_⊙_ {{iCompShifts}} ξ₁ (step ξ₂) = step (ξ₁ ⊙ ξ₂)
_⊙_ {{iCompShifts}} refl (skip ξ₂) = skip ξ₂
_⊙_ {{iCompShifts}} (step ξ₁) (skip ξ₂) = step (ξ₁ ⊙ ξ₂)
_⊙_ {{iCompShifts}} (skip ξ₁) (skip ξ₂) = skip (ξ₁ ⊙ ξ₂)
--------------------------------------------------------------------------------
shiftIx-⊙ : {γ₁ γ₂ γ₃ : Dom} (ξ₁ : Shifts γ₁ γ₂) (ξ₂ : Shifts γ₂ γ₃) →
(i : Ix γ₁) → shiftIx (ξ₁ ⊙ ξ₂) i ≡ shiftIx ξ₂ (shiftIx ξ₁ i)
shiftIx-⊙ ξ₁ refl i = refl
shiftIx-⊙ ξ₁ (step ξ₂) i = cong suc (shiftIx-⊙ ξ₁ ξ₂ i)
shiftIx-⊙ refl (skip ξ₂) i = refl
shiftIx-⊙ (step ξ₁) (skip ξ₂) i = cong suc (shiftIx-⊙ ξ₁ ξ₂ i)
shiftIx-⊙ (skip ξ₁) (skip ξ₂) zero = refl
shiftIx-⊙ (skip ξ₁) (skip ξ₂) (suc i) = cong suc (shiftIx-⊙ ξ₁ ξ₂ i)
shiftIx-wkm : {γ : Dom} (δ : Dom) (i : Ix γ) →
shiftIx (wkm δ) i ≡ wk δ i
shiftIx-wkm zero i = refl
shiftIx-wkm (suc δ) i = cong suc (shiftIx-wkm δ i)
--------------------------------------------------------------------------------
instance
iUpIdmShifts : UpIdm Shifts
idm-↑₁ {{iUpIdmShifts}} = refl
iCompIdmShifts : CompIdm Shifts
⊙-idm {{iCompIdmShifts}} ξ = refl
idm-⊙ {{iCompIdmShifts}} refl = refl
idm-⊙ {{iCompIdmShifts}} (step ξ) = cong step (idm-⊙ ξ)
idm-⊙ {{iCompIdmShifts}} (skip ξ) = refl
iUpCompShifts : UpComp Shifts
⊙-↑₁ {{iUpCompShifts}} ξ refl = refl
⊙-↑₁ {{iUpCompShifts}} refl (step ζ) = cong (skip ∘ step) (idm-⊙ ζ)
⊙-↑₁ {{iUpCompShifts}} (step ξ) (step ζ) = refl
⊙-↑₁ {{iUpCompShifts}} (skip ξ) (step ζ) = refl
⊙-↑₁ {{iUpCompShifts}} refl (skip ζ) = refl
⊙-↑₁ {{iUpCompShifts}} (step ξ) (skip ζ) = refl
⊙-↑₁ {{iUpCompShifts}} (skip ξ) (skip ζ) = refl
iWkmHomShifts : WkmHom Shifts
wkm-zero {{iWkmHomShifts}} = refl
wkm-suc {{iWkmHomShifts}} δ = refl
module _ {T : STX} {{vrT : Vr T}} where
instance
iLkUpShifts : {{wkT : Wk T}} {{wkVrT : WkVr T}} → LkUp T Shifts
lk-↑₁-zero {{iLkUpShifts}} refl = refl
lk-↑₁-zero {{iLkUpShifts}} (step ξ) = refl
lk-↑₁-zero {{iLkUpShifts}} (skip ξ) = refl
lk-↑₁-suc {{iLkUpShifts}} refl i = sym (wk₁-vr i)
lk-↑₁-suc {{iLkUpShifts}} (step ξ) i = sym (wk₁-vr (suc (shiftIx ξ i)))
lk-↑₁-suc {{iLkUpShifts}} (skip ξ) i = sym (wk₁-vr (shiftIx (skip ξ) i))
iLkRenShifts : LkRen T Shifts
lk-ren {{iLkRenShifts}} ξ i = refl
iLkIdmShifts : LkIdm T Shifts
lk-idm {{iLkIdmShifts}} i = refl
iLkWkmShifts : LkWkm T Shifts
lk-wkm {{iLkWkmShifts}} δ i = cong vr (shiftIx-wkm δ i)
--------------------------------------------------------------------------------
| 35.669725
| 80
| 0.508745
|
43f8313682311f338bce928ecd9db15df1954408
| 313
|
agda
|
Agda
|
Cubical/Data/Empty/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Data/Empty/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Empty/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Empty.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty.Base
isProp⊥ : isProp ⊥
isProp⊥ ()
isContr⊥→A : ∀ {ℓ} {A : Type ℓ} → isContr (⊥ → A)
fst isContr⊥→A ()
snd isContr⊥→A f i ()
| 19.5625
| 49
| 0.690096
|
2ef6db7f3ba8bf114042e351c32557504a4580b6
| 3,599
|
agda
|
Agda
|
agda/Esterel/CompletionCode.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/Esterel/CompletionCode.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/Esterel/CompletionCode.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module Esterel.CompletionCode where
open import Data.Nat
using (ℕ ; zero ; suc) renaming (_≟_ to _≟ℕ_ ; _⊔_ to _⊔ℕ_ ; _≤_ to _≤N_ ; _≤?_ to _≤?N_)
open import Data.Nat.Properties
using (⊔-⊓-isCommutativeSemiringWithoutOne)
open import Function
using (_∘_)
open import Relation.Nullary
using (Dec ; yes ; no)
open import Relation.Binary
using (Decidable)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; cong)
import Level
import Relation.Binary
open import Data.List using (List ; _∷_ ; [] ; _++_)
open import Data.List.Any.Properties using (++⁻)
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
open import Data.Empty using (⊥-elim)
import Data.Bool
open import Algebra.Structures
using (IsCommutativeSemiringWithoutOne ; IsCommutativeMonoid)
open import utility
data CompletionCode : Set where
nothin : CompletionCode
pause : CompletionCode
exit : ℕ → CompletionCode
↓* : CompletionCode → CompletionCode
↓* nothin = nothin
↓* pause = pause
↓* (exit zero) = nothin
↓* (exit (suc n)) = exit n
exit-injective : ∀{n m} → exit n ≡ exit m → n ≡ m
exit-injective refl = refl
_≟_ : Decidable {A = CompletionCode} _≡_
nothin ≟ nothin = yes refl
nothin ≟ pause = no λ()
nothin ≟ exit _ = no λ()
pause ≟ nothin = no λ()
pause ≟ pause = yes refl
pause ≟ exit _ = no λ()
exit _ ≟ nothin = no λ()
exit _ ≟ pause = no λ()
exit n ≟ exit m with n ≟ℕ m
... | yes n≡m = yes (cong exit n≡m)
... | no ¬n≡m = no (¬n≡m ∘ exit-injective)
open ListSet _≟_
_⊔_ : CompletionCode → CompletionCode → CompletionCode
nothin ⊔ r = r
pause ⊔ nothin = pause
pause ⊔ r = r
exit n ⊔ nothin = exit n
exit n ⊔ pause = exit n
exit n ⊔ exit m = exit (n ⊔ℕ m)
⊔-comm : ∀ c₁ c₂ → c₁ ⊔ c₂ ≡ c₂ ⊔ c₁
⊔-comm nothin nothin = refl
⊔-comm nothin pause = refl
⊔-comm nothin (exit m) = refl
⊔-comm pause nothin = refl
⊔-comm pause pause = refl
⊔-comm pause (exit m) = refl
⊔-comm (exit n) nothin = refl
⊔-comm (exit n) pause = refl
⊔-comm (exit n) (exit m)
rewrite IsCommutativeMonoid.comm
(IsCommutativeSemiringWithoutOne.+-isCommutativeMonoid
⊔-⊓-isCommutativeSemiringWithoutOne) n m
= refl
data _≤_ : Relation.Binary.Rel CompletionCode Level.zero where
nothin≤c : ∀ {c} -> nothin ≤ c
pause≤pause : pause ≤ pause
pause≤exit : ∀ {n} -> pause ≤ exit n
exit≤exit : ∀ {n} {m} -> (n ≤N m) -> exit n ≤ exit m
_≤?_ : Decidable _≤_
nothin ≤? c2 = yes nothin≤c
pause ≤? nothin = no (λ ())
pause ≤? pause = yes pause≤pause
pause ≤? exit x = yes pause≤exit
exit n ≤? nothin = no (λ ())
exit n ≤? pause = no (λ ())
exit n ≤? exit m with n ≤?N m
exit n ≤? exit m | yes n≤m = yes (exit≤exit n≤m)
exit n ≤? exit m | no ¬n≤m = no ¬≤ where
¬≤ : Relation.Nullary.¬ (exit n ≤ exit m)
¬≤ (exit≤exit n) = ¬n≤m n
codessub : (List CompletionCode) → (List CompletionCode) → Set
codessub codes' codes = (∀ a → a ∈ codes' → a ∈ codes)
codesub++ll : ∀{a b c} → codessub a b → codessub a (b ++ c)
codesub++ll sub a a∈ = ++ˡ (sub a a∈)
codesub++both : ∀{a b c d} → codessub a c → codessub b d → codessub (a ++ b) (c ++ d)
codesub++both{a}{b}{c}{d} a⊂c b⊂d z z∈ with ++⁻ a z∈
... | inj₁ z∈1 = ++ˡ (a⊂c z z∈1)
... | inj₂ z∈2 = ++ʳ c (b⊂d z z∈2)
codesub- : ∀{a b} z → codessub a b → codessub (set-remove a z) (set-remove b z)
codesub-{a}{b} z a⊂b x x∈ with z ≟ x
... | yes refl = ⊥-elim (set-remove-removed{x}{a} x∈)
... | no ¬refl = set-remove-not-removed ¬refl (a⊂b x (set-remove-mono-∈ z x∈))
| 31.849558
| 91
| 0.605446
|
21141cc16bad2208880594736245a197a1b4155b
| 909
|
agda
|
Agda
|
src/System/IO/Transducers.agda
|
agda/agda-system-io
|
121d6c66cba34b4c15b437366b80c65dd2b02a8d
|
[
"MIT"
] | 10
|
2015-01-04T13:45:16.000Z
|
2021-09-15T04:35:41.000Z
|
src/System/IO/Transducers.agda
|
agda/agda-system-io
|
121d6c66cba34b4c15b437366b80c65dd2b02a8d
|
[
"MIT"
] | null | null | null |
src/System/IO/Transducers.agda
|
agda/agda-system-io
|
121d6c66cba34b4c15b437366b80c65dd2b02a8d
|
[
"MIT"
] | 2
|
2017-08-10T06:12:54.000Z
|
2022-03-12T11:40:23.000Z
|
open import Coinduction using ( ♭ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl )
open import System.IO.Transducers.Lazy using ()
renaming ( done to doneL ; _⟫_ to _⟫L_ )
open import System.IO.Transducers.Strict using ()
renaming ( done to doneS ; _⟫_ to _⟫S_ )
open import System.IO.Transducers.Session using ( Session ; I ; Σ )
open import System.IO.Transducers.Trace using ( Trace )
module System.IO.Transducers where
open System.IO.Transducers.Lazy public
using ( _⇒_ ; inp ; out ; id ; ⟦_⟧ ; _≃_ )
open System.IO.Transducers.Strict public
using ( _⇛_ )
data Style : Set where
lazy strict : Style
_⇒_is_ : Session → Session → Style → Set
S ⇒ T is lazy = S ⇒ T
S ⇒ T is strict = S ⇛ T
done : ∀ {s S} → (S ⇒ S is s)
done {lazy} = doneL
done {strict} = doneS
_⟫_ : ∀ {s S T U} → (S ⇒ T is s) → (T ⇒ U is s) → (S ⇒ U is s)
_⟫_ {lazy} = _⟫L_
_⟫_ {strict} = _⟫S_
| 28.40625
| 70
| 0.649065
|
52e962e1dae80ccc9a38d75c3bc04d689d79daca
| 2,931
|
agda
|
Agda
|
src/Tactic/Cong.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Tactic/Cong.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Tactic/Cong.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
-- A tactic that applies congruence and symmetry of equality proofs.
-- Given a hole and a lemma it tries (in order)
-- - refl
-- - lemma
-- - sym lemma
-- - f $≡ X₁ *≡ .. *≡ Xₙ and recurses on Xᵢ
-- if the goal is f us ≡ f vs
-- Hidden and instance arguments of f are left alone.
module Tactic.Cong where
open import Prelude
open import Container.Traversable
open import Tactic.Reflection
private
refl′ : ∀ {a} {A : Set a} (x : A) → x ≡ x
refl′ _ = refl
pattern `refl a = def₁ (quote refl′) a
parseEq : Term → Maybe (Term × Term)
parseEq (def (quote _≡_) (hArg _ ∷ hArg _ ∷ vArg x ∷ vArg y ∷ [])) = just (x , y)
parseEq _ = nothing
-- build-cong f ps = f $≡ p₁ *≡ .. *≡ pₙ
build-cong : Term → List Term → Term
build-cong f [] = `refl unknown -- we tried this
build-cong f (p ∷ ps) = foldl ap (def₂ (quote cong) f p) ps
where
ap = λ p q → def₂ (quote _*≡_) p q
zipWithM!₃ : {A B C : Set} → (A → B → C → TC ⊤) → List A → List B → List C → TC ⊤
zipWithM!₃ f (x ∷ xs) (y ∷ ys) (z ∷ zs) = f x y z *> zipWithM!₃ f xs ys zs
zipWithM!₃ _ _ _ _ = pure _
module _ (lemma : Term) where
go go-cong : (d : Nat) (lhs rhs hole : Term) → TC ⊤
go d lhs rhs hole =
checkType hole (def₂ (quote _≡_) lhs rhs) *>
( unify hole (`refl lhs)
<|> unify hole lemma
<|> unify hole (def₁ (quote sym) lemma)
<|> go-cong d lhs rhs hole
<|> do lhs ← reduce lhs
rhs ← reduce rhs
go-cong d lhs rhs hole)
solve : (d : Nat) (hole : Term) → TC ⊤
solve d hole =
caseM parseEq <$> (reduce =<< inferType hole) of λ where
nothing → typeErrorS "Goal is not an equality type."
(just (lhs , rhs)) → go d lhs rhs hole
go-cong′ : ∀ d f us vs hole → TC ⊤
go-cong′ d f us vs hole = do
let us₁ = map unArg (filter isVisible us)
vs₁ = map unArg (filter isVisible vs)
holes ← traverse (const newMeta!) us₁
zipWithM!₃ (go d) us₁ vs₁ holes
unify hole (build-cong f holes)
go-cong (suc d) (def f us) (def f₁ vs) hole = guard (f == f₁) (go-cong′ d (def₀ f) us vs hole)
go-cong (suc d) (con c us) (con c₁ vs) hole = guard (c == c₁) (go-cong′ d (con₀ c) us vs hole)
go-cong (suc d) (var x us) (var x₁ vs) hole = guard (x == x₁) (go-cong′ d (var₀ x) us vs hole)
go-cong _ lhs rhs _ = empty
macro
by-cong : ∀ {a} {A : Set a} {x y : A} → x ≡ y → Tactic
by-cong {x = x} {y} lemma hole = do
`lemma ← quoteTC lemma
ensureNoMetas =<< inferType hole
lemMeta ← lemProxy `lemma
solve lemMeta 100 hole <|> typeErrorS "Congruence failed"
unify lemMeta `lemma
where
-- Create a meta for the lemma to avoid retype-checking it in case
-- it's expensive. Don't do this if the lemma is a variable.
lemProxy : Term → TC Term
lemProxy lemma@(var _ []) = pure lemma
lemProxy lemma = newMeta =<< quoteTC (x ≡ y)
| 35.313253
| 98
| 0.573524
|
4386bfc15919c1c4c717a5ab91eeba497943a628
| 5,147
|
agda
|
Agda
|
Cubical/HITs/Colimit/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Colimit/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Colimit/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-
Homotopy colimits of graphs
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Colimit.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Graph
-- Cones under a diagram
record Cocone ℓ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} (F : Diag ℓd I) (X : Type ℓ)
: Type (ℓ-suc (ℓ-max ℓ (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))) where
field
leg : ∀ (j : Obj I) → F $ j → X
com : ∀ {j k} (f : Hom I j k) → leg k ∘ F <$> f ≡ leg j
postcomp : ∀ {ℓ'} {Y : Type ℓ'} → (X → Y) → Cocone ℓ' F Y
leg (postcomp h) j = h ∘ leg j
com (postcomp h) f = cong (h ∘_) (com f)
open Cocone public
-- Σ (Type ℓ) (Cocone ℓ F) forms a category:
module _ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} where
private
-- the "lower star" functor
_* : ∀ {ℓ ℓ'} {X : Type ℓ} {Y : Type ℓ'} → (X → Y) → Cocone _ F X → Cocone _ F Y
(h *) C = postcomp C h
CoconeMor : ∀ {ℓ ℓ'} → Σ (Type ℓ) (Cocone ℓ F) → Σ (Type ℓ') (Cocone ℓ' F) → Type _
CoconeMor (X , C) (Y , D) = Σ[ h ∈ (X → Y) ] (h *) C ≡ D
idCoconeMor : ∀ {ℓ} (Cp : Σ (Type ℓ) (Cocone ℓ F)) → CoconeMor Cp Cp
idCoconeMor Cp = (λ x → x) , refl
compCoconeMor : ∀ {ℓ ℓ' ℓ''} {C : Σ (Type ℓ) (Cocone ℓ F)} {D : Σ (Type ℓ') (Cocone ℓ' F)}
{E : Σ (Type ℓ'') (Cocone ℓ'' F)}
→ CoconeMor D E → CoconeMor C D → CoconeMor C E
compCoconeMor (g , q) (f , p) = g ∘ f , (cong (g *) p) ∙ q
-- Universal cocones are initial objects in the category Σ (Type ℓ) (Cocone ℓ F)
module _ {ℓ ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} where
isUniversalAt : ∀ ℓq → Cocone ℓ F X → Type (ℓ-max ℓ (ℓ-suc (ℓ-max ℓq (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))))
isUniversalAt ℓq C = ∀ (Y : Type ℓq) → isEquiv {A = (X → Y)} {B = Cocone ℓq F Y} (postcomp C)
-- (unfolding isEquiv, this ^ is equivalent to what one might expect:)
-- ∀ (Y : Type ℓ) (D : Cocone ℓ F Y) → isContr (Σ[ h ∈ (X → Y) ] (h *) C ≡ D)
-- (≡ isContr (CoconeMor (X , C) (Y , D)))
isPropIsUniversalAt : ∀ ℓq (C : Cocone ℓ F X) → isProp (isUniversalAt ℓq C)
isPropIsUniversalAt ℓq C = propPi (λ Y → isPropIsEquiv (postcomp C))
isUniversal : Cocone ℓ F X → Typeω
isUniversal C = ∀ ℓq → isUniversalAt ℓq C
-- Colimits are universal cocones
record isColimit {ℓ ℓd ℓv ℓe} {I : Graph ℓv ℓe} (F : Diag ℓd I) (X : Type ℓ) : Typeω where
field
cone : Cocone ℓ F X
univ : isUniversal cone
open isColimit public
module _ {ℓ ℓ' ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} {Y : Type ℓ'} where
postcomp⁻¹ : isColimit F X → Cocone ℓ' F Y → (X → Y)
postcomp⁻¹ cl = invEq (_ , univ cl _ Y)
postcomp⁻¹-inv : (cl : isColimit F X) (D : Cocone ℓ' F Y) → (postcomp (cone cl) (postcomp⁻¹ cl D)) ≡ D
postcomp⁻¹-inv cl D = retEq (_ , univ cl _ Y) D
postcomp⁻¹-mor : (cl : isColimit F X) (D : Cocone ℓ' F Y) → CoconeMor (X , cone cl) (Y , D)
postcomp⁻¹-mor cl D = (postcomp⁻¹ cl D) , (postcomp⁻¹-inv cl D)
-- Colimits are unique
module _ {ℓ ℓ' ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} {Y : Type ℓ'} where
uniqColimit : isColimit F X → isColimit F Y → X ≃ Y
uniqColimit cl cl'
= isoToEquiv (iso (fst fwd) (fst bwd)
(λ x i → fst (isContr→isProp (equiv-proof (univ cl' ℓ' Y) (cone cl'))
(compCoconeMor fwd bwd)
(idCoconeMor (Y , cone cl')) i) x)
(λ x i → fst (isContr→isProp (equiv-proof (univ cl ℓ X) (cone cl))
(compCoconeMor bwd fwd)
(idCoconeMor (X , cone cl)) i) x))
where fwd : CoconeMor (X , cone cl ) (Y , cone cl')
bwd : CoconeMor (Y , cone cl') (X , cone cl )
fwd = postcomp⁻¹-mor cl (cone cl')
bwd = postcomp⁻¹-mor cl' (cone cl)
-- Colimits always exist
data colim {ℓd ℓe ℓv} {I : Graph ℓv ℓe} (F : Diag ℓd I) : Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd))) where
colim-leg : ∀ (j : Obj I) → F $ j → colim F
colim-com : ∀ {j k} (f : Hom I j k) → colim-leg k ∘ F <$> f ≡ colim-leg j
module _ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} where
colimCone : Cocone _ F (colim F)
leg colimCone = colim-leg
com colimCone = colim-com
colim-rec : ∀ {ℓ} {X : Type ℓ} → Cocone ℓ F X → (colim F → X)
colim-rec C (colim-leg j A) = leg C j A
colim-rec C (colim-com f i A) = com C f i A
colimIsColimit : isColimit F (colim F)
cone colimIsColimit = colimCone
univ colimIsColimit ℓq Y
= isoToIsEquiv record { fun = postcomp colimCone
; inv = colim-rec
; rightInv = λ C → refl
; leftInv = λ h → funExt (eq h) }
where eq : ∀ h (x : colim _) → colim-rec (postcomp colimCone h) x ≡ h x
eq h (colim-leg j A) = refl
eq h (colim-com f i A) = refl
| 38.125926
| 109
| 0.536235
|
192cd7b539b072c279aefb626b126b3676c9ef26
| 22,008
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to Any
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Any.Properties where
open import Category.Monad
open import Data.Bool.Base using (Bool; false; true; T)
open import Data.Bool.Properties
open import Data.Empty using (⊥)
open import Data.Fin using (Fin) renaming (zero to fzero; suc to fsuc)
open import Data.List as List
open import Data.List.Categorical using (monad)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties.Core
using (Any↔; find∘map; map∘find; lose∘find)
open import Data.List.Relation.Binary.Pointwise
using (Pointwise; []; _∷_)
open import Data.Nat using (zero; suc; _<_; z≤n; s≤s)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Maybe.Relation.Unary.Any as MAny using (just)
open import Data.Product as Prod
using (_×_; _,_; ∃; ∃₂; proj₁; proj₂; uncurry′)
open import Data.Product.Properties
open import Data.Product.Function.NonDependent.Propositional
using (_×-cong_)
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; equivalence; Equivalence)
open import Function.Inverse as Inv using (_↔_; inverse; Inverse)
open import Function.Related as Related using (Related; SK-sym)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; inspect)
open import Relation.Unary
using (Pred; _⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_)
open import Relation.Nullary using (¬_)
open Related.EquationalReasoning
private
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
------------------------------------------------------------------------
-- Equality properties
module _ {a p ℓ} {A : Set a} {P : A → Set p} {_≈_ : Rel A ℓ} where
lift-resp : P Respects _≈_ → (Any P) Respects (Pointwise _≈_)
lift-resp resp [] ()
lift-resp resp (x≈y ∷ xs≈ys) (here px) = here (resp x≈y px)
lift-resp resp (x≈y ∷ xs≈ys) (there pxs) =
there (lift-resp resp xs≈ys pxs)
module _ {a p} {A : Set a} {P : A → Set p} where
here-injective : ∀ {x xs} {p q : P x} →
here {P = P} {xs = xs} p ≡ here q → p ≡ q
here-injective refl = refl
there-injective : ∀ {x xs} {p q : Any P xs} →
there {x = x} p ≡ there q → p ≡ q
there-injective refl = refl
------------------------------------------------------------------------
-- Misc
module _ {a p} {A : Set a} {P : A → Set p} where
¬Any[] : ¬ Any P []
¬Any[] ()
------------------------------------------------------------------------
-- Any is a congruence
module _ {a k p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
Any-cong : ∀ {xs ys : List A} →
(∀ x → Related k (P x) (Q x)) →
Preorder._∼_ (Related.InducedPreorder₂ k {A = A} _∈_) xs ys →
Related k (Any P xs) (Any Q ys)
Any-cong {xs} {ys} P↔Q xs≈ys =
Any P xs ↔⟨ SK-sym Any↔ ⟩
(∃ λ x → x ∈ xs × P x) ∼⟨ Σ.cong Inv.id (xs≈ys ×-cong P↔Q _) ⟩
(∃ λ x → x ∈ ys × Q x) ↔⟨ Any↔ ⟩
Any Q ys ∎
------------------------------------------------------------------------
-- map
map-id : ∀ {a p} {A : Set a} {P : A → Set p} (f : P ⋐ P) {xs} →
(∀ {x} (p : P x) → f p ≡ p) →
(p : Any P xs) → Any.map f p ≡ p
map-id f hyp (here p) = P.cong here (hyp p)
map-id f hyp (there p) = P.cong there $ map-id f hyp p
map-∘ : ∀ {a p q r}
{A : Set a} {P : A → Set p} {Q : A → Set q} {R : A → Set r}
(f : Q ⋐ R) (g : P ⋐ Q)
{xs} (p : Any P xs) →
Any.map (f ∘ g) p ≡ Any.map f (Any.map g p)
map-∘ f g (here p) = refl
map-∘ f g (there p) = P.cong there $ map-∘ f g p
------------------------------------------------------------------------
-- Swapping
-- Nested occurrences of Any can sometimes be swapped. See also ×↔.
swap : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : A → B → Set ℓ} {xs ys} →
Any (λ x → Any (P x) ys) xs → Any (λ y → Any (flip P y) xs) ys
swap (here pys) = Any.map here pys
swap (there pxys) = Any.map there (swap pxys)
swap-there : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : A → B → Set ℓ}
{x xs ys} → (any : Any (λ x → Any (P x) ys) xs) →
swap (Any.map (there {x = x}) any) ≡ there (swap any)
swap-there (here pys) = refl
swap-there (there pxys) = P.cong (Any.map there) (swap-there pxys)
swap-invol : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : A → B → Set ℓ}
{xs ys} → (any : Any (λ x → Any (P x) ys) xs) →
swap (swap any) ≡ any
swap-invol (here (here px)) = refl
swap-invol (here (there pys)) =
P.cong (Any.map there) (swap-invol (here pys))
swap-invol (there pxys) =
P.trans (swap-there (swap pxys)) (P.cong there (swap-invol pxys))
swap↔ : ∀ {ℓ} {A B : Set ℓ} {P : A → B → Set ℓ} {xs ys} →
Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys
swap↔ {P = P} = inverse swap swap swap-invol swap-invol
------------------------------------------------------------------------
-- Lemmas relating Any to ⊥
⊥↔Any⊥ : ∀ {a} {A : Set a} {xs : List A} → ⊥ ↔ Any (const ⊥) xs
⊥↔Any⊥ {A = A} = inverse (λ()) (λ p → from p) (λ()) (λ p → from p)
where
from : {xs : List A} → Any (const ⊥) xs → ∀ {b} {B : Set b} → B
from (here ())
from (there p) = from p
⊥↔Any[] : ∀ {a p} {A : Set a} {P : A → Set p} → ⊥ ↔ Any P []
⊥↔Any[] = inverse (λ()) (λ()) (λ()) (λ())
------------------------------------------------------------------------
-- Lemmas relating Any to ⊤
-- These introduction and elimination rules are not inverses, though.
module _ {a} {A : Set a} where
any⁺ : ∀ (p : A → Bool) {xs} → Any (T ∘ p) xs → T (any p xs)
any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px
any⁺ p (there {x = x} pxs) with p x
... | true = _
... | false = any⁺ p pxs
any⁻ : ∀ (p : A → Bool) xs → T (any p xs) → Any (T ∘ p) xs
any⁻ p [] ()
any⁻ p (x ∷ xs) px∷xs with p x | inspect p x
any⁻ p (x ∷ xs) px∷xs | true | P.[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq)
any⁻ p (x ∷ xs) px∷xs | false | _ = there (any⁻ p xs px∷xs)
any⇔ : ∀ {p : A → Bool} {xs} → Any (T ∘ p) xs ⇔ T (any p xs)
any⇔ = equivalence (any⁺ _) (any⁻ _ _)
------------------------------------------------------------------------
-- Sums commute with Any
module _ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} where
Any-⊎⁺ : ∀ {xs} → Any P xs ⊎ Any Q xs → Any (λ x → P x ⊎ Q x) xs
Any-⊎⁺ = [ Any.map inj₁ , Any.map inj₂ ]′
Any-⊎⁻ : ∀ {xs} → Any (λ x → P x ⊎ Q x) xs → Any P xs ⊎ Any Q xs
Any-⊎⁻ (here (inj₁ p)) = inj₁ (here p)
Any-⊎⁻ (here (inj₂ q)) = inj₂ (here q)
Any-⊎⁻ (there p) = Sum.map there there (Any-⊎⁻ p)
⊎↔ : ∀ {xs} → (Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs
⊎↔ = inverse Any-⊎⁺ Any-⊎⁻ from∘to to∘from
where
from∘to : ∀ {xs} (p : Any P xs ⊎ Any Q xs) → Any-⊎⁻ (Any-⊎⁺ p) ≡ p
from∘to (inj₁ (here p)) = refl
from∘to (inj₁ (there p)) rewrite from∘to (inj₁ p) = refl
from∘to (inj₂ (here q)) = refl
from∘to (inj₂ (there q)) rewrite from∘to (inj₂ q) = refl
to∘from : ∀ {xs} (p : Any (λ x → P x ⊎ Q x) xs) →
Any-⊎⁺ (Any-⊎⁻ p) ≡ p
to∘from (here (inj₁ p)) = refl
to∘from (here (inj₂ q)) = refl
to∘from (there p) with Any-⊎⁻ p | to∘from p
to∘from (there .(Any.map inj₁ p)) | inj₁ p | refl = refl
to∘from (there .(Any.map inj₂ q)) | inj₂ q | refl = refl
------------------------------------------------------------------------
-- Products "commute" with Any.
module _ {a b p q} {A : Set a} {B : Set b}
{P : Pred A p} {Q : Pred B q} where
Any-×⁺ : ∀ {xs ys} → Any P xs × Any Q ys →
Any (λ x → Any (λ y → P x × Q y) ys) xs
Any-×⁺ (p , q) = Any.map (λ p → Any.map (λ q → (p , q)) q) p
Any-×⁻ : ∀ {xs ys} → Any (λ x → Any (λ y → P x × Q y) ys) xs →
Any P xs × Any Q ys
Any-×⁻ pq with Prod.map id (Prod.map id find) (find pq)
... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q)
×↔ : ∀ {xs ys} →
(Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs
×↔ {xs} {ys} = inverse Any-×⁺ Any-×⁻ from∘to to∘from
where
from∘to : ∀ pq → Any-×⁻ (Any-×⁺ pq) ≡ pq
from∘to (p , q) rewrite
find∘map p (λ p → Any.map (λ q → (p , q)) q)
| find∘map q (λ q → proj₂ (proj₂ (find p)) , q)
| lose∘find p
| lose∘find q
= refl
to∘from : ∀ pq → Any-×⁺ (Any-×⁻ pq) ≡ pq
to∘from pq
with find pq
| (λ (f : (proj₁ (find pq) ≡_) ⋐ _) → map∘find pq {f})
... | (x , x∈xs , pq′) | lem₁
with find pq′
| (λ (f : (proj₁ (find pq′) ≡_) ⋐ _) → map∘find pq′ {f})
... | (y , y∈ys , p , q) | lem₂
rewrite P.sym $ map-∘ {R = λ x → Any (λ y → P x × Q y) ys}
(λ p → Any.map (λ q → p , q) (lose y∈ys q))
(λ y → P.subst P y p)
x∈xs
= lem₁ _ helper
where
helper : Any.map (λ q → p , q) (lose y∈ys q) ≡ pq′
helper rewrite P.sym $ map-∘ (λ q → p , q)
(λ y → P.subst Q y q)
y∈ys
= lem₂ _ refl
------------------------------------------------------------------------
-- Invertible introduction (⁺) and elimination (⁻) rules for various
-- list functions
------------------------------------------------------------------------
-- map
module _ {a p} {A : Set a} {P : Pred A p} where
singleton⁺ : ∀ {x} → P x → Any P [ x ]
singleton⁺ Px = here Px
singleton⁻ : ∀ {x} → Any P [ x ] → P x
singleton⁻ (here Px) = Px
singleton⁻ (there ())
------------------------------------------------------------------------
-- map
module _ {a b} {A : Set a} {B : Set b} {f : A → B} where
map⁺ : ∀ {p} {P : B → Set p} {xs} →
Any (P ∘ f) xs → Any P (List.map f xs)
map⁺ (here p) = here p
map⁺ (there p) = there $ map⁺ p
map⁻ : ∀ {p} {P : B → Set p} {xs} →
Any P (List.map f xs) → Any (P ∘ f) xs
map⁻ {xs = []} ()
map⁻ {xs = x ∷ xs} (here p) = here p
map⁻ {xs = x ∷ xs} (there p) = there $ map⁻ p
map⁺∘map⁻ : ∀ {p} {P : B → Set p} {xs} →
(p : Any P (List.map f xs)) → map⁺ (map⁻ p) ≡ p
map⁺∘map⁻ {xs = []} ()
map⁺∘map⁻ {xs = x ∷ xs} (here p) = refl
map⁺∘map⁻ {xs = x ∷ xs} (there p) = P.cong there (map⁺∘map⁻ p)
map⁻∘map⁺ : ∀ {p} (P : B → Set p) {xs} →
(p : Any (P ∘ f) xs) → map⁻ {P = P} (map⁺ p) ≡ p
map⁻∘map⁺ P (here p) = refl
map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p)
map↔ : ∀ {p} {P : B → Set p} {xs} →
Any (P ∘ f) xs ↔ Any P (List.map f xs)
map↔ = inverse map⁺ map⁻ (map⁻∘map⁺ _) map⁺∘map⁻
------------------------------------------------------------------------
-- mapMaybe
module _ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
(f : A → Maybe B) where
mapMaybe⁺ : ∀ xs → Any (MAny.Any P) (map f xs) →
Any P (mapMaybe f xs)
mapMaybe⁺ [] ()
mapMaybe⁺ (x ∷ xs) ps with f x | ps
... | nothing | here ()
... | nothing | there pxs = mapMaybe⁺ xs pxs
... | just _ | here (just py) = here py
... | just _ | there pxs = there (mapMaybe⁺ xs pxs)
------------------------------------------------------------------------
-- _++_
module _ {a p} {A : Set a} {P : A → Set p} where
++⁺ˡ : ∀ {xs ys} → Any P xs → Any P (xs ++ ys)
++⁺ˡ (here p) = here p
++⁺ˡ (there p) = there (++⁺ˡ p)
++⁺ʳ : ∀ xs {ys} → Any P ys → Any P (xs ++ ys)
++⁺ʳ [] p = p
++⁺ʳ (x ∷ xs) p = there (++⁺ʳ xs p)
++⁻ : ∀ xs {ys} → Any P (xs ++ ys) → Any P xs ⊎ Any P ys
++⁻ [] p = inj₂ p
++⁻ (x ∷ xs) (here p) = inj₁ (here p)
++⁻ (x ∷ xs) (there p) = Sum.map there id (++⁻ xs p)
++⁺∘++⁻ : ∀ xs {ys} (p : Any P (xs ++ ys)) →
[ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs p) ≡ p
++⁺∘++⁻ [] p = refl
++⁺∘++⁻ (x ∷ xs) (here p) = refl
++⁺∘++⁻ (x ∷ xs) (there p) with ++⁻ xs p | ++⁺∘++⁻ xs p
++⁺∘++⁻ (x ∷ xs) (there p) | inj₁ p′ | ih = P.cong there ih
++⁺∘++⁻ (x ∷ xs) (there p) | inj₂ p′ | ih = P.cong there ih
++⁻∘++⁺ : ∀ xs {ys} (p : Any P xs ⊎ Any P ys) →
++⁻ xs ([ ++⁺ˡ , ++⁺ʳ xs ]′ p) ≡ p
++⁻∘++⁺ [] (inj₁ ())
++⁻∘++⁺ [] (inj₂ p) = refl
++⁻∘++⁺ (x ∷ xs) (inj₁ (here p)) = refl
++⁻∘++⁺ (x ∷ xs) {ys} (inj₁ (there p)) rewrite ++⁻∘++⁺ xs {ys} (inj₁ p) = refl
++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl
++↔ : ∀ {xs ys} → (Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys)
++↔ {xs = xs} = inverse [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs) (++⁻∘++⁺ xs) (++⁺∘++⁻ xs)
++-comm : ∀ xs ys → Any P (xs ++ ys) → Any P (ys ++ xs)
++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs
++-comm∘++-comm : ∀ xs {ys} (p : Any P (xs ++ ys)) →
++-comm ys xs (++-comm xs ys p) ≡ p
++-comm∘++-comm [] {ys} p
rewrite ++⁻∘++⁺ ys {ys = []} (inj₁ p) = refl
++-comm∘++-comm (x ∷ xs) {ys} (here p)
rewrite ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₂ (here p)) = refl
++-comm∘++-comm (x ∷ xs) (there p) with ++⁻ xs p | ++-comm∘++-comm xs p
++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ʳ ys p))))
| inj₁ p | refl
rewrite ++⁻∘++⁺ ys (inj₂ p)
| ++⁻∘++⁺ ys (inj₂ $ there {x = x} p) = refl
++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ˡ p))))
| inj₂ p | refl
rewrite ++⁻∘++⁺ ys {ys = xs} (inj₁ p)
| ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = refl
++↔++ : ∀ xs ys → Any P (xs ++ ys) ↔ Any P (ys ++ xs)
++↔++ xs ys = inverse (++-comm xs ys) (++-comm ys xs)
(++-comm∘++-comm xs) (++-comm∘++-comm ys)
++-insert : ∀ xs {ys x} → P x → Any P (xs ++ [ x ] ++ ys)
++-insert xs Px = ++⁺ʳ xs (++⁺ˡ (singleton⁺ Px))
------------------------------------------------------------------------
-- concat
module _ {a p} {A : Set a} {P : A → Set p} where
concat⁺ : ∀ {xss} → Any (Any P) xss → Any P (concat xss)
concat⁺ (here p) = ++⁺ˡ p
concat⁺ (there {x = xs} p) = ++⁺ʳ xs (concat⁺ p)
concat⁻ : ∀ xss → Any P (concat xss) → Any (Any P) xss
concat⁻ [] ()
concat⁻ ([] ∷ xss) p = there $ concat⁻ xss p
concat⁻ ((x ∷ xs) ∷ xss) (here p) = here (here p)
concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p
... | here p′ = here (there p′)
... | there p′ = there p′
concat⁻∘++⁺ˡ : ∀ {xs} xss (p : Any P xs) →
concat⁻ (xs ∷ xss) (++⁺ˡ p) ≡ here p
concat⁻∘++⁺ˡ xss (here p) = refl
concat⁻∘++⁺ˡ xss (there p) rewrite concat⁻∘++⁺ˡ xss p = refl
concat⁻∘++⁺ʳ : ∀ xs xss (p : Any P (concat xss)) →
concat⁻ (xs ∷ xss) (++⁺ʳ xs p) ≡ there (concat⁻ xss p)
concat⁻∘++⁺ʳ [] xss p = refl
concat⁻∘++⁺ʳ (x ∷ xs) xss p rewrite concat⁻∘++⁺ʳ xs xss p = refl
concat⁺∘concat⁻ : ∀ xss (p : Any P (concat xss)) →
concat⁺ (concat⁻ xss p) ≡ p
concat⁺∘concat⁻ [] ()
concat⁺∘concat⁻ ([] ∷ xss) p = concat⁺∘concat⁻ xss p
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (here p) = refl
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there p)
with concat⁻ (xs ∷ xss) p | concat⁺∘concat⁻ (xs ∷ xss) p
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ˡ p′)) | here p′ | refl = refl
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ʳ xs (concat⁺ p′))) | there p′ | refl = refl
concat⁻∘concat⁺ : ∀ {xss} (p : Any (Any P) xss) → concat⁻ xss (concat⁺ p) ≡ p
concat⁻∘concat⁺ (here p) = concat⁻∘++⁺ˡ _ p
concat⁻∘concat⁺ (there {x = xs} {xs = xss} p)
rewrite concat⁻∘++⁺ʳ xs xss (concat⁺ p) =
P.cong there $ concat⁻∘concat⁺ p
concat↔ : ∀ {xss} → Any (Any P) xss ↔ Any P (concat xss)
concat↔ {xss} = inverse concat⁺ (concat⁻ xss) concat⁻∘concat⁺ (concat⁺∘concat⁻ xss)
------------------------------------------------------------------------
-- applyUpTo
module _ {a p} {A : Set a} {P : A → Set p} where
applyUpTo⁺ : ∀ f {i n} → P (f i) → i < n → Any P (applyUpTo f n)
applyUpTo⁺ _ p (s≤s z≤n) = here p
applyUpTo⁺ f p (s≤s (s≤s i<n)) =
there (applyUpTo⁺ (f ∘ suc) p (s≤s i<n))
applyUpTo⁻ : ∀ f {n} → Any P (applyUpTo f n) →
∃ λ i → i < n × P (f i)
applyUpTo⁻ f {zero} ()
applyUpTo⁻ f {suc n} (here p) = zero , s≤s z≤n , p
applyUpTo⁻ f {suc n} (there p) with applyUpTo⁻ (f ∘ suc) p
... | i , i<n , q = suc i , s≤s i<n , q
------------------------------------------------------------------------
-- tabulate
module _ {a p} {A : Set a} {P : A → Set p} where
tabulate⁺ : ∀ {n} {f : Fin n → A} i → P (f i) → Any P (tabulate f)
tabulate⁺ fzero p = here p
tabulate⁺ (fsuc i) p = there (tabulate⁺ i p)
tabulate⁻ : ∀ {n} {f : Fin n → A} →
Any P (tabulate f) → ∃ λ i → P (f i)
tabulate⁻ {zero} ()
tabulate⁻ {suc n} (here p) = fzero , p
tabulate⁻ {suc n} (there p) = Prod.map fsuc id (tabulate⁻ p)
------------------------------------------------------------------------
-- map-with-∈.
module _ {a b p} {A : Set a} {B : Set b} {P : B → Set p} where
map-with-∈⁺ : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) →
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
Any P (map-with-∈ xs f)
map-with-∈⁺ f (_ , here refl , p) = here p
map-with-∈⁺ f (_ , there x∈xs , p) =
there $ map-with-∈⁺ (f ∘ there) (_ , x∈xs , p)
map-with-∈⁻ : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) →
Any P (map-with-∈ xs f) →
∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)
map-with-∈⁻ [] f ()
map-with-∈⁻ (y ∷ xs) f (here p) = (y , here refl , p)
map-with-∈⁻ (y ∷ xs) f (there p) =
Prod.map id (Prod.map there id) $ map-with-∈⁻ xs (f ∘ there) p
map-with-∈↔ : ∀ {xs : List A} {f : ∀ {x} → x ∈ xs → B} →
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (map-with-∈ xs f)
map-with-∈↔ = inverse (map-with-∈⁺ _) (map-with-∈⁻ _ _) (from∘to _) (to∘from _ _)
where
from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B)
(p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
map-with-∈⁻ xs f (map-with-∈⁺ f p) ≡ p
from∘to f (_ , here refl , p) = refl
from∘to f (_ , there x∈xs , p)
rewrite from∘to (f ∘ there) (_ , x∈xs , p) = refl
to∘from : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B)
(p : Any P (map-with-∈ xs f)) →
map-with-∈⁺ f (map-with-∈⁻ xs f p) ≡ p
to∘from [] f ()
to∘from (y ∷ xs) f (here p) = refl
to∘from (y ∷ xs) f (there p) =
P.cong there $ to∘from xs (f ∘ there) p
------------------------------------------------------------------------
-- return
module _ {a p} {A : Set a} {P : A → Set p} where
return⁺ : ∀ {x} → P x → Any P (return x)
return⁺ = here
return⁻ : ∀ {x} → Any P (return x) → P x
return⁻ (here p) = p
return⁻ (there ())
return⁺∘return⁻ : ∀ {x} (p : Any P (return x)) →
return⁺ (return⁻ p) ≡ p
return⁺∘return⁻ (here p) = refl
return⁺∘return⁻ (there ())
return⁻∘return⁺ : ∀ {x} (p : P x) → return⁻ (return⁺ p) ≡ p
return⁻∘return⁺ p = refl
return↔ : ∀ {x} → P x ↔ Any P (return x)
return↔ = inverse return⁺ return⁻ return⁻∘return⁺ return⁺∘return⁻
------------------------------------------------------------------------
-- _∷_
module _ {a p} {A : Set a} where
∷↔ : ∀ (P : Pred A p) {x xs} → (P x ⊎ Any P xs) ↔ Any P (x ∷ xs)
∷↔ P {x} {xs} =
(P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩
(Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩
Any P (x ∷ xs) ∎
------------------------------------------------------------------------
-- _>>=_
module _ {ℓ p} {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
>>=↔ : ∀ {xs} → Any (Any P ∘ f) xs ↔ Any P (xs >>= f)
>>=↔ {xs} =
Any (Any P ∘ f) xs ↔⟨ map↔ ⟩
Any (Any P) (List.map f xs) ↔⟨ concat↔ ⟩
Any P (xs >>= f) ∎
------------------------------------------------------------------------
-- _⊛_
module _ {ℓ} {A B : Set ℓ} where
⊛↔ : ∀ {P : B → Set ℓ} {fs : List (A → B)} {xs : List A} →
Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs)
⊛↔ {P = P} {fs} {xs} =
Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → return↔) (_ ∎)) (_ ∎) ⟩
Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ ) (_ ∎) ⟩
Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ ⟩
Any P (fs ⊛ xs) ∎
-- An alternative introduction rule for _⊛_
⊛⁺′ : ∀ {P : A → Set ℓ} {Q : B → Set ℓ} {fs : List (A → B)} {xs} →
Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs)
⊛⁺′ pq p =
Inverse.to ⊛↔ ⟨$⟩
Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq
------------------------------------------------------------------------
-- _⊗_
module _ {ℓ} {A B : Set ℓ} where
⊗↔ : {P : A × B → Set ℓ} {xs : List A} {ys : List B} →
Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys)
⊗↔ {P} {xs} {ys} =
Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ return↔ ⟩
Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩
Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩
Any P (xs ⊗ ys) ∎
⊗↔′ : {P : A → Set ℓ} {Q : B → Set ℓ} {xs : List A} {ys : List B} →
(Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys)
⊗↔′ {P} {Q} {xs} {ys} =
(Any P xs × Any Q ys) ↔⟨ ×↔ ⟩
Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩
Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎
| 37.879518
| 106
| 0.426618
|
576903df30cf7b89df3fcfd2cac4e44c3390ac3b
| 1,894
|
agda
|
Agda
|
theorems/homotopy/HopfConstruction.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/homotopy/HopfConstruction.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/homotopy/HopfConstruction.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.HSpace
module homotopy.HopfConstruction {i} {X : Ptd i} {{_ : is-connected 0 (de⊙ X)}}
(hX : HSpaceStructure X) where
module μ = ConnectedHSpace hX
μ = μ.μ
private
A = de⊙ X
{-
Using the fact that [μ a] is an equivalence, we define a fibration over the
suspension of [A] with fiber [A] and applying [μ a] when you move along
[merid a].
-}
module H = SuspRecType A A μ.r-equiv
{-
The total space of the previous fibration is the pushout of the following span
(thanks to the flattening lemma).
-}
s : Span
s = span (⊤ × A) (⊤ × A) (A × A)
(λ cc' → (tt , snd cc')) (λ cc' → (tt , uncurry μ cc'))
lemma : Σ (Susp A) H.f == Pushout s
lemma = H.flattening
{-
But that span is equal to the following span, which is almost the same as
the span for the join.
-}
x : s == Span-flip (*-span A A)
x = span= (equiv snd (_,_ tt) (λ b → idp) (λ a → idp))
(equiv snd (_,_ tt) (λ b → idp) (λ a → idp))
eq (λ a → idp) (λ a → idp) where
eq : (A × A) ≃ (A × A)
eq = equiv to from to-from from-to where
to : A × A → A × A
to (a , a') = (μ a a' , a')
from : A × A → A × A
from (a , a') = (<– (μ.l-equiv a') a , a')
to-from : (a : A × A) → to (from a) == a
to-from (a , a') = pair×= (<–-inv-r (μ.l-equiv a') a) idp
from-to : (a : A × A) → from (to a) == a
from-to (a , a') = pair×= (<–-inv-l (μ.l-equiv a') a) idp
lemma2 : (A * A) ≃ (Pushout (Span-flip (*-span A A)))
lemma2 = Pushout-flip-equiv (*-span A A)
theorem : Σ (Susp A) H.f == (A * A)
theorem = lemma ∙ ap Pushout x ∙ ! (ua lemma2)
-- record FibSeq {i j k ℓ} (A : Type i) (B : Type j) (C : Type k) (c : C)
-- : Type (lmax (lmax i j) (lmax k (lsucc ℓ))) where
-- constructor fibSeq
-- field
-- fibration : C → Type ℓ
-- fiber : fibration c ≃ A
-- total : Σ C fibration ≃ B
| 26.305556
| 79
| 0.55227
|
c54225b856f2aef2f11f2ec2469a88ad61bd410d
| 879
|
agda
|
Agda
|
Numeral/PositiveInteger.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/PositiveInteger.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/PositiveInteger.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.PositiveInteger where
import Lvl
open import Syntax.Number
open import Data.Boolean.Stmt
open import Functional
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural as ℕ using (ℕ)
open import Type
data ℕ₊ : Type{Lvl.𝟎} where
𝟏 : ℕ₊
𝐒 : ℕ₊ → ℕ₊
ℕ₊-to-ℕ : ℕ₊ → ℕ
ℕ₊-to-ℕ (𝟏) = ℕ.𝐒(ℕ.𝟎)
ℕ₊-to-ℕ (𝐒(n)) = ℕ.𝐒(ℕ₊-to-ℕ (n))
ℕ-to-ℕ₊ : (n : ℕ) → ⦃ _ : IsTrue(positive?(n)) ⦄ → ℕ₊
ℕ-to-ℕ₊ (ℕ.𝟎) ⦃ ⦄
ℕ-to-ℕ₊ (ℕ.𝐒(ℕ.𝟎)) ⦃ _ ⦄ = 𝟏
ℕ-to-ℕ₊ (ℕ.𝐒(ℕ.𝐒(x))) ⦃ p ⦄ = 𝐒(ℕ-to-ℕ₊ (ℕ.𝐒(x)) ⦃ p ⦄)
instance
ℕ₊-numeral : Numeral(ℕ₊)
Numeral.restriction-ℓ (ℕ₊-numeral) = Lvl.𝟎
Numeral.restriction (ℕ₊-numeral) (n) = IsTrue(positive?(n))
num ⦃ ℕ₊-numeral ⦄ (n) ⦃ proof ⦄ = ℕ-to-ℕ₊ (n) ⦃ proof ⦄
𝐒-from-ℕ : ℕ → ℕ₊
𝐒-from-ℕ (ℕ.𝟎) = 𝟏
𝐒-from-ℕ (ℕ.𝐒(n)) = 𝐒(𝐒-from-ℕ(n))
𝐏-to-ℕ : ℕ₊ → ℕ
𝐏-to-ℕ (𝟏) = ℕ.𝟎
𝐏-to-ℕ (𝐒(n)) = ℕ.𝐒(𝐏-to-ℕ(n))
| 23.756757
| 63
| 0.555176
|
218d967f216cae2667e55d15e48ceadbdc8fde10
| 930
|
agda
|
Agda
|
Data/List/Relation/Sublist.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Data/List/Relation/Sublist.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Data/List/Relation/Sublist.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
import Lvl
open import Type
module Data.List.Relation.Sublist {ℓ} {T : Type{ℓ}} where
open import Data.List using (List ; ∅ ; _⊰_)
open import Logic
-- Whether a list's elements are contained in another list in order.
-- Examples:
-- [1,2,3] ⊑ [1,2,3]
-- [1,2,3] ⊑ [1,2,3,4]
-- [1,2,3] ⊑ [0,1,2,3]
-- [1,2,3] ⊑ [0,1,10,2,20,3,30]
-- [0,10,20,30] ⊑ [0,1,10,2,20,3,30]
data _⊑_ : List(T) → List(T) → Stmt{ℓ} where
empty : (∅ ⊑ ∅)
use : ∀{x}{l₁ l₂} → (l₁ ⊑ l₂) → ((x ⊰ l₁) ⊑ (x ⊰ l₂))
skip : ∀{x}{l₁ l₂} → (l₁ ⊑ l₂) → (l₁ ⊑ (x ⊰ l₂))
-- Whether a list's elements are contained in another list in order while not containing the same sublist.
-- Examples:
-- [1,2,3] ⊏ [1,2,3,4]
-- [1,2,3] ⊏ [0,1,2,3]
-- [1,2,3] ⊏ [0,1,10,2,20,3,30]
data _⊏_ : List(T) → List(T) → Stmt{ℓ} where
use : ∀{x}{l₁ l₂} → (l₁ ⊏ l₂) → ((x ⊰ l₁) ⊏ (x ⊰ l₂))
skip : ∀{x}{l₁ l₂} → (l₁ ⊑ l₂) → (l₁ ⊏ (x ⊰ l₂))
| 32.068966
| 106
| 0.503226
|
35fff44095c0ef1f64b18c460b455c6db3781b78
| 5,740
|
agda
|
Agda
|
formalization/agda/Spire/Denotational.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 43
|
2015-05-28T23:25:33.000Z
|
2022-03-08T17:10:59.000Z
|
formalization/agda/Spire/Denotational.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | null | null | null |
formalization/agda/Spire/Denotational.agda
|
spire/spire
|
3d67f137ee9423b7e6f8593634583998cd692353
|
[
"BSD-3-Clause"
] | 1
|
2015-08-17T21:00:07.000Z
|
2015-08-17T21:00:07.000Z
|
open import Spire.Type
module Spire.Denotational where
----------------------------------------------------------------------
data Term : Set → Set₁
eval : {A : Set} → Term A → A
----------------------------------------------------------------------
data Term where
{- Type introduction -}
`⊥ `⊤ `Bool `ℕ `Desc `Type : ∀{ℓ} → Term (Type ℓ)
`Π `Σ : ∀{ℓ}
(A : Term (Type ℓ))
(B : ⟦ ℓ ∣ eval A ⟧ → Term (Type ℓ))
→ Term (Type ℓ)
`⟦_⟧ : ∀{ℓ}
(A : Term (Type ℓ))
→ Term (Type (suc ℓ))
`⟦_⟧ᵈ : ∀{ℓ}
(D : Term (Desc ℓ))
(X : Term (Type ℓ))
→ Term (Type ℓ)
`μ : ∀{ℓ}
(D : Term (Desc ℓ))
→ Term (Type ℓ)
{- Type elimination -}
`elimType : ∀{ℓ}
(P : (n : ℕ) → Type n → Term (Type ℓ))
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `⊥) ⟧)
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `⊤) ⟧)
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `Bool) ⟧)
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `ℕ) ⟧)
→ ((n : ℕ) (A : Type n) (B : ⟦ n ∣ A ⟧ → Type n)
(rec₁ : ⟦ ℓ ∣ eval (P n A) ⟧)
(rec₂ : (a : ⟦ n ∣ A ⟧) → ⟦ ℓ ∣ eval (P n (B a)) ⟧)
→ Term ⟦ ℓ ∣ eval (P n (`Π A B)) ⟧)
→ ((n : ℕ) (A : Type n) (B : ⟦ n ∣ A ⟧ → Type n)
(rec₁ : ⟦ ℓ ∣ eval (P n A) ⟧)
(rec₂ : (a : ⟦ n ∣ A ⟧) → ⟦ ℓ ∣ eval (P n (B a)) ⟧)
→ Term ⟦ ℓ ∣ eval (P n (`Σ A B)) ⟧)
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `Desc) ⟧)
→ ((n : ℕ) (D : Desc n) (X : Type n)
(rec : ⟦ ℓ ∣ eval (P n X) ⟧)
→ Term ⟦ ℓ ∣ eval (P n (`⟦ D ⟧ᵈ X)) ⟧)
→ ((n : ℕ) (D : Desc n) → Term ⟦ ℓ ∣ eval (P n (`μ D)) ⟧)
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `Type) ⟧)
→ ((n : ℕ) (A : Type n)
(rec : ⟦ ℓ ∣ eval (P n A) ⟧)
→ Term ⟦ ℓ ∣ eval (P (suc n) `⟦ A ⟧) ⟧)
→ (n : Term ℕ)
(A : Term (Type (eval n)))
→ Term ⟦ ℓ ∣ eval (P (eval n) (eval A)) ⟧
{- Desc introduction -}
`⊤ᵈ `Xᵈ : ∀{ℓ} → Term (Desc ℓ)
`Πᵈ `Σᵈ : ∀{ℓ}
(A : Term (Type ℓ))
(B : ⟦ ℓ ∣ eval A ⟧ → Term (Desc (suc ℓ)))
→ Term (Desc (suc ℓ))
{- Desc elimination -}
`elimDesc : ∀{ℓ}
(P : (n : ℕ) → Desc n → Term (Type ℓ))
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `⊤) ⟧)
→ ((n : ℕ) → Term ⟦ ℓ ∣ eval (P n `X) ⟧)
→ ((n : ℕ) (A : Type n) (D : ⟦ n ∣ A ⟧ → Desc (suc n))
(rec : (a : ⟦ n ∣ A ⟧) → ⟦ ℓ ∣ eval (P (suc n) (D a)) ⟧)
→ Term ⟦ ℓ ∣ eval (P (suc n) (`Π A D)) ⟧)
→ ((n : ℕ) (A : Type n) (D : ⟦ n ∣ A ⟧ → Desc (suc n))
(rec : (a : ⟦ n ∣ A ⟧) → ⟦ ℓ ∣ eval (P (suc n) (D a)) ⟧)
→ Term ⟦ ℓ ∣ eval (P (suc n) (`Σ A D)) ⟧)
→ (n : Term ℕ)
(D : Term (Desc (eval n)))
→ Term ⟦ ℓ ∣ eval (P (eval n) (eval D)) ⟧
{- Value introduction -}
`tt : Term ⊤
`true `false : Term Bool
`zero : Term ℕ
`suc : Term ℕ → Term ℕ
`λ : ∀{A} {B : A → Set}
(f : (a : A) → Term (B a))
→ Term ((a : A) → B a)
_`,_ : ∀{A B}
(a : Term A)
(b : Term (B (eval a)))
→ Term (Σ A B)
`con : ∀{ℓ D}
(x : Term (⟦ ℓ ∣ D ⟧ᵈ (μ D)))
→ Term (μ D)
{- Value elimination -}
`elim⊥ : ∀{A}
→ Term ⊥
→ Term A
`elimBool : ∀{ℓ}
(P : Bool → Term (Type ℓ))
(pt : Term ⟦ ℓ ∣ eval (P true) ⟧)
(pf : Term ⟦ ℓ ∣ eval (P false) ⟧)
(b : Term Bool)
→ Term ⟦ ℓ ∣ eval (P (eval b)) ⟧
`elimℕ : ∀{ℓ}
(P : ℕ → Term (Type ℓ))
(pz : Term ⟦ ℓ ∣ eval (P zero) ⟧)
(ps : (n : ℕ) → ⟦ ℓ ∣ eval (P n) ⟧ → Term ⟦ ℓ ∣ eval (P (suc n)) ⟧)
(n : Term ℕ)
→ Term ⟦ ℓ ∣ eval (P (eval n)) ⟧
`proj₁ : ∀{A B}
(ab : Term (Σ A B))
→ Term A
`proj₂ : ∀{A B}
(ab : Term (Σ A B))
→ Term (B (proj₁ (eval ab)))
_`$_ : ∀{A} {B : A → Set}
(f : Term ((a : A) → B a))
(a : Term A)
→ Term (B (eval a))
`des : ∀{ℓ} {D : Desc ℓ}
→ (Term (μ D))
→ Term (⟦ ℓ ∣ D ⟧ᵈ (μ D))
----------------------------------------------------------------------
{- Type introduction -}
eval `⊥ = `⊥
eval `⊤ = `⊤
eval `Bool = `Bool
eval `ℕ = `ℕ
eval `Desc = `Desc
eval `Type = `Type
eval (`Π A B) = `Π (eval A) (λ a → eval (B a))
eval (`Σ A B) = `Σ (eval A) (λ a → eval (B a))
eval (`μ D) = `μ (eval D)
eval (`⟦ D ⟧ᵈ X) = `⟦ eval D ⟧ᵈ (eval X)
eval `⟦ A ⟧ = `⟦ eval A ⟧
{- Type elimination -}
eval (`elimType {ℓ = ℓ} P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ n A) =
elimType (λ n A → ⟦ ℓ ∣ eval (P n A) ⟧)
(λ n → eval (p⊥ n)) (λ n → eval (p⊤ n)) (λ n → eval (pBool n)) (λ n → eval (pℕ n))
(λ n A B rec₁ rec₂ → eval (pΠ n A B rec₁ rec₂))
(λ n A B rec₁ rec₂ → eval (pΣ n A B rec₁ rec₂))
(λ n → eval (pDesc n))
(λ n D X rec → eval (p⟦D⟧ᵈ n D X rec))
(λ n D → eval (pμ n D))
(λ n → eval (pType n))
(λ n A rec → eval (p⟦A⟧ n A rec))
(eval n)
(eval A)
{- Desc introduction -}
eval `⊤ᵈ = `⊤
eval `Xᵈ = `X
eval (`Πᵈ A D) = `Π (eval A) (λ a → eval (D a))
eval (`Σᵈ A D) = `Σ (eval A) (λ a → eval (D a))
{- Desc elimination -}
eval (`elimDesc {ℓ = ℓ} P p⊤ pX pΠ pΣ n D) =
elimDesc (λ n D → ⟦ ℓ ∣ eval (P n D) ⟧)
(λ n → eval (p⊤ n)) (λ n → eval (pX n))
(λ n A D rec → eval (pΠ n A D rec))
(λ n A D rec → eval (pΣ n A D rec))
(eval n)
(eval D)
{- Value introduction -}
eval `tt = tt
eval `true = true
eval `false = false
eval `zero = zero
eval (`suc n) = suc (eval n)
eval (`λ f) = λ a → eval (f a)
eval (a `, b) = eval a , eval b
eval (`con x) = con (eval x)
{- Value elimination -}
eval (`elim⊥ bot) = elim⊥ (eval bot)
eval (`elimBool {ℓ = ℓ} P pt pf b) =
elimBool (λ b → ⟦ ℓ ∣ eval (P b) ⟧)
(eval pt) (eval pf) (eval b)
eval (`elimℕ {ℓ = ℓ} P pz ps n) =
elimℕ (λ n → ⟦ ℓ ∣ eval (P n) ⟧)
(eval pz) (λ n pn → eval (ps n pn)) (eval n)
eval (`proj₁ ab) = proj₁ (eval ab)
eval (`proj₂ ab) = proj₂ (eval ab)
eval (f `$ a) = (eval f) (eval a)
eval (`des {ℓ = ℓ} x) = des {ℓ = ℓ} (eval x)
----------------------------------------------------------------------
| 29.740933
| 86
| 0.401394
|
58aad59324c28aab06c46f1700442442e7a13f7a
| 346
|
agda
|
Agda
|
test/interaction/Issue3130Split.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3130Split.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3130Split.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2018-06-19, issue #3130
-- Produce parenthesized dot pattern .(p) instead of .p
-- when is a projection.
-- {-# OPTIONS -v reify.pat:80 #-}
record R : Set₁ where
field p : Set
open R
data D : (R → Set) → Set₁ where
c : D p
test : (f : R → Set) (x : D f) → Set₁
test f x = {!x!} -- split on x
-- Expected:
-- test .(p) c = ?
| 18.210526
| 55
| 0.566474
|
34e71ff7cba8b9fd9c21a994893a0797bd296db7
| 1,874
|
agda
|
Agda
|
vendor/stdlib/src/Data/List/NonEmpty/Properties.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Data/List/NonEmpty/Properties.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Data/List/NonEmpty/Properties.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Properties of non-empty lists
------------------------------------------------------------------------
module Data.List.NonEmpty.Properties where
open import Algebra
open import Category.Monad
open import Data.Function
open import Data.Product
open import Data.List as List using (List; []; _∷_; _++_)
open RawMonad List.monad using () renaming (_>>=_ to _⋆>>=_)
private module LM {A} = Monoid (List.monoid A)
open import Data.List.NonEmpty as List⁺
open RawMonad List⁺.monad
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
η : ∀ {A} (xs : List⁺ A) → head xs ∷ tail xs ≡ List⁺.toList xs
η [ x ] = refl
η (x ∷ xs) = refl
toList-fromList : ∀ {A} x (xs : List A) →
x ∷ xs ≡ List⁺.toList (List⁺.fromList x xs)
toList-fromList x [] = refl
toList-fromList x (y ∷ xs) = cong (_∷_ x) (toList-fromList y xs)
toList-⁺++ : ∀ {A} (xs : List⁺ A) ys →
List⁺.toList xs ++ ys ≡
List⁺.toList (xs ⁺++ ys)
toList-⁺++ [ x ] ys = toList-fromList x ys
toList-⁺++ (x ∷ xs) ys = cong (_∷_ x) (toList-⁺++ xs ys)
toList-⁺++⁺ : ∀ {A} (xs ys : List⁺ A) →
List⁺.toList xs ++ List⁺.toList ys ≡
List⁺.toList (xs ⁺++⁺ ys)
toList-⁺++⁺ [ x ] ys = refl
toList-⁺++⁺ (x ∷ xs) ys = cong (_∷_ x) (toList-⁺++⁺ xs ys)
toList->>= : ∀ {A B} (f : A → List⁺ B) (xs : List⁺ A) →
(List⁺.toList xs ⋆>>= List⁺.toList ∘ f) ≡
(List⁺.toList (xs >>= f))
toList->>= f [ x ] = proj₂ LM.identity _
toList->>= f (x ∷ xs) = begin
List⁺.toList (f x) ++ (List⁺.toList xs ⋆>>= List⁺.toList ∘ f) ≡⟨ cong (_++_ (List⁺.toList (f x))) (toList->>= f xs) ⟩
List⁺.toList (f x) ++ List⁺.toList (xs >>= f) ≡⟨ toList-⁺++⁺ (f x) (xs >>= f) ⟩
List⁺.toList (f x ⁺++⁺ (xs >>= f)) ∎
| 39.041667
| 119
| 0.495197
|
35388afa46b9a0644d931dddc907996ce6922d30
| 293
|
agda
|
Agda
|
test/fail/LevelLiterals.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/fail/LevelLiterals.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/LevelLiterals.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- There are no level literals in the concrete syntax. This file tests
-- if type errors use level literals.
{-# OPTIONS --universe-polymorphism #-}
module LevelLiterals where
open import Imports.Level
data ⊥ : Set₁ where
DoubleNegated : ∀ {ℓ} → Set ℓ → Set
DoubleNegated A = (A → ⊥) → ⊥
| 20.928571
| 70
| 0.699659
|
8b34ea5986a6bd904d95a3c6443e7e544d63f13c
| 7,702
|
agda
|
Agda
|
LibraBFT/Abstract/Obligations/LockedRound.agda
|
lisandrasilva/bft-consensus-agda-1
|
b7dd98dd90d98fbb934ef8cb4f3314940986790d
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Abstract/Obligations/LockedRound.agda
|
lisandrasilva/bft-consensus-agda-1
|
b7dd98dd90d98fbb934ef8cb4f3314940986790d
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Abstract/Obligations/LockedRound.agda
|
lisandrasilva/bft-consensus-agda-1
|
b7dd98dd90d98fbb934ef8cb4f3314940986790d
|
[
"UPL-1.0"
] | null | null | null |
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Abstract.Types
module LibraBFT.Abstract.Obligations.LockedRound
(𝓔 : EpochConfig)
(UID : Set)
(_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁))
(𝓥 : VoteEvidence 𝓔 UID)
where
open import LibraBFT.Abstract.Records 𝓔 UID _≟UID_ 𝓥
open import LibraBFT.Abstract.Records.Extends 𝓔 UID _≟UID_ 𝓥
open import LibraBFT.Abstract.RecordChain 𝓔 UID _≟UID_ 𝓥
import LibraBFT.Abstract.RecordChain.Assumptions 𝓔 UID _≟UID_ 𝓥
as StaticAssumptions
open import LibraBFT.Abstract.System 𝓔 UID _≟UID_ 𝓥
---------------------
-- * LockedRound * --
---------------------
module _ {ℓ}(𝓢 : AbsSystemState ℓ) where
open AbsSystemState 𝓢
-- The LockedRound rule is a little more involved to be expressed in terms
-- of /HasBeenSent/: it needs two additional pieces which are introduced
-- next.
-- Cand-3-chain v carries the information for estabilishing
-- that v.proposed will be part of a 3-chain if a QC containing v is formed.
-- The difficulty is that we can't easily access the "grandparent" of a vote.
-- Instead, we must explicitly state that it exists.
--
-- candidate 3-chain
-- +------------------------------------------------------+
-- | |
-- | 2-chain |
-- +----------------------------------+
-- ⋯ <- v.grandparent <- q₁ <- v.parent <- q <- v.proposed <- v
-- ̭
-- |
-- The 'qc' defined below is an
-- abstract view of q, above.
record voteExtends (v : Vote) : Set where
constructor mkVE
field
veBlock : Block
veId : vBlockUID v ≡ bId veBlock
veRounds≡ : vRound v ≡ bRound veBlock
open voteExtends
record Cand-3-chain-vote (v : Vote) : Set where
field
votesForB : voteExtends v
qc : QC
qc←b : Q qc ← B (veBlock votesForB)
rc : RecordChain (Q qc)
n : ℕ
is-2chain : 𝕂-chain Contig (2 + n) rc
open Cand-3-chain-vote public
-- Returns the round of the head of the candidate 3-chain. In the diagram
-- explaining Cand-3-chain-vote, this would be v.grandparent.round.
Cand-3-chain-head-round : ∀{v} → Cand-3-chain-vote v → Round
Cand-3-chain-head-round c3cand =
getRound (kchainBlock (suc zero) (is-2chain c3cand))
-- The locked round rule states a fact about the /previous round/
-- of a vote; that is, the round of the parent of the block
-- being voted for; the implementation will have to
-- show it can construct this parent.
data VoteParentData-BlockExt : Record → Set where
vpParent≡I : VoteParentData-BlockExt I
vpParent≡Q : ∀{b q} → B b ← Q q → VoteParentData-BlockExt (Q q)
-- TODO-2: it may be cleaner to specify this as a RC 2 vpParent vpQC,
-- and we should consider it once we address the issue in
-- Abstract.RecordChain (below the definition of transp-𝕂-chain)
record VoteParentData (v : Vote) : Set where
field
vpExt : voteExtends v
vpParent : Record
vpExt' : vpParent ← B (veBlock vpExt)
vpMaybeBlock : VoteParentData-BlockExt vpParent
open VoteParentData public
-- The setup for LockedRoundRule is like thta for VotesOnce.
-- Given two votes by an honest author α:
Type : Set ℓ
Type = ∀{α v v'}
→ Meta-Honest-Member 𝓔 α
→ vMember v ≡ α → (hbs : HasBeenSent v)
→ vMember v' ≡ α → (hbs' : HasBeenSent v')
-- If v is a vote on a candidate 3-chain, that is, is a vote on a block
-- that extends a 2-chain,
→ (c2 : Cand-3-chain-vote v)
-- and the round of v is lower than that of v',
→ vRound v < vRound v'
------------------------------
-- then α obeyed the locked round rule:
→ Σ (VoteParentData v')
(λ vp → Cand-3-chain-head-round c2 ≤ round (vpParent vp))
private
make-cand-3-chain : ∀{n α q}{rc : RecordChain (Q q)}
→ (c3 : 𝕂-chain Contig (3 + n) rc)
→ (v : α ∈QC q)
→ Cand-3-chain-vote (∈QC-Vote q v)
make-cand-3-chain {q = q} (s-chain {suc (suc n)} {rc = rc} {b = b} ext₀@(Q←B h0 refl) _ ext₁@(B←Q h1 refl) c2) v
with c2
...| (s-chain {q = q₀} _ _ _ (s-chain _ _ _ c))
= record { votesForB = mkVE b (All-lookup (qVotes-C3 q) (Any-lookup-correct v))
(trans (All-lookup (qVotes-C4 q) (Any-lookup-correct v)) h1)
; qc = q₀
; qc←b = ext₀
; rc = rc
; n = n
; is-2chain = c2
}
-- It is important that the make-cand-3-chain lemma doesn't change the head of
-- the 3-chain/cand-2-chain.
make-cand-3-chain-lemma
: ∀{n α q}{rc : RecordChain (Q q)}
→ (c3 : 𝕂-chain Contig (3 + n) rc)
→ (v : α ∈QC q)
→ NonInjective-≡ bId ⊎ kchainBlock (suc zero) (is-2chain (make-cand-3-chain c3 v)) ≡ kchainBlock (suc (suc zero)) c3
make-cand-3-chain-lemma {q = q} c3@(s-chain {suc (suc n)} {rc = rc} {b = b} ext₀@(Q←B h0 refl) _ ext₁@(B←Q h1 refl) c2) v
with (veBlock (Cand-3-chain-vote.votesForB (make-cand-3-chain c3 v))) ≟Block b
...| no neq = inj₁ ((veBlock (Cand-3-chain-vote.votesForB (make-cand-3-chain c3 v)) , b)
, neq
, trans (sym (veId (votesForB (make-cand-3-chain c3 v))))
(All-lookup (qVotes-C3 q) (∈QC-Vote-correct q v)))
...| yes b≡
with c2
...| (s-chain {q = q₀} _ _ _ (s-chain _ _ _ c)) rewrite b≡ = inj₂ refl
vdParent-prevRound-lemma
: ∀{α q}(rc : RecordChain (Q q))(va : α ∈QC q)
→ (vp : VoteParentData (∈QC-Vote q va))
→ NonInjective-≡ bId ⊎ (round (vpParent vp) ≡ prevRound rc)
vdParent-prevRound-lemma {q = q} (step {r = B b} (step rc y) x@(B←Q refl refl)) va vp
with b ≟Block (veBlock (vpExt vp))
...| no imp = inj₁ ( (b , veBlock (vpExt vp))
, (imp , id-B∨Q-inj (cong id-B∨Q (trans (sym (All-lookup (qVotes-C3 q) (∈QC-Vote-correct q va)))
(veId (vpExt vp))))))
...| yes refl
with ←-inj y (vpExt' vp)
...| bSameId'
with y | vpExt' vp
...| I←B y0 y1 | I←B e0 e1 = inj₂ refl
...| Q←B y0 refl | Q←B e0 refl
with vpMaybeBlock vp
...| vpParent≡Q {b = bP} bP←qP
with rc
...| step {r = B b'} rc' b←q
with b' ≟Block bP
...| no imp = inj₁ ((b' , bP) , imp , id-B∨Q-inj (lemmaS1-2 (eq-Q refl) b←q bP←qP))
...| yes refl
with bP←qP | b←q
...| B←Q refl refl | B←Q refl refl = inj₂ refl
-- Finally, we can prove the locked round rule from the global version;
proof : Type → StaticAssumptions.LockedRoundRule InSys
proof glob-inv α hα {q} {q'} q∈sys q'∈sys c3 va rc' va' hyp
with ∈QC⇒HasBeenSent q∈sys hα va
| ∈QC⇒HasBeenSent q'∈sys hα va'
...| sent-cv | sent-cv'
with make-cand-3-chain c3 va | inspect
(make-cand-3-chain c3) va
...| cand | [ R ]
with glob-inv hα
(sym (∈QC-Member q va )) sent-cv
(sym (∈QC-Member q' va')) sent-cv'
cand hyp
...| va'Par , res
with vdParent-prevRound-lemma rc' va' va'Par
...| inj₁ hb = inj₁ hb
...| inj₂ final
with make-cand-3-chain-lemma c3 va
...| inj₁ hb = inj₁ hb
...| inj₂ xx = inj₂ (subst₂ _≤_
(cong bRound (trans (cong (kchainBlock (suc zero) ∘ is-2chain) (sym R)) xx))
final
res)
| 40.751323
| 124
| 0.542716
|
34ac5e117772c1e37847595d3bb685acce9f33aa
| 3,637
|
agda
|
Agda
|
examples/outdated-and-incorrect/cat/Category.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/cat/Category.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/cat/Category.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Category where
open import Logic.Equivalence
open import Logic.Relations
open Equivalence using () renaming (_==_ to eq)
record Cat : Set2 where
field
Obj : Set1
_─→_ : Obj -> Obj -> Set
id : {A : Obj} -> A ─→ A
_∘_ : {A B C : Obj} -> B ─→ C -> A ─→ B -> A ─→ C
Eq : {A B : Obj} -> Equivalence (A ─→ B)
cong : {A B C : Obj}{f₁ f₂ : B ─→ C}{g₁ g₂ : A ─→ B} ->
eq Eq f₁ f₂ -> eq Eq g₁ g₂ -> eq Eq (f₁ ∘ g₁) (f₂ ∘ g₂)
idLeft : {A B : Obj}{f : A ─→ B} -> eq Eq (id ∘ f) f
idRight : {A B : Obj}{f : A ─→ B} -> eq Eq (f ∘ id) f
assoc : {A B C D : Obj}{f : C ─→ D}{g : B ─→ C}{h : A ─→ B} ->
eq Eq ((f ∘ g) ∘ h) (f ∘ (g ∘ h))
module Category (ℂ : Cat) where
private module CC = Cat ℂ
open CC public hiding (_─→_; _∘_)
private module Eq {A B : Obj} = Equivalence (Eq {A}{B})
open Eq public hiding (_==_)
infix 20 _==_
infixr 30 _─→_
infixr 90 _∘_
_─→_ = CC._─→_
_==_ : {A B : Obj} -> Rel (A ─→ B)
_==_ = Eq._==_
_∘_ : {A B C : Obj} -> B ─→ C -> A ─→ B -> A ─→ C
_∘_ = CC._∘_
congL : {A B C : Obj}{f₁ f₂ : B ─→ C}{g : A ─→ B} ->
f₁ == f₂ -> f₁ ∘ g == f₂ ∘ g
congL p = cong p (refl _)
congR : {A B C : Obj}{f : B ─→ C}{g₁ g₂ : A ─→ B} ->
g₁ == g₂ -> f ∘ g₁ == f ∘ g₂
congR p = cong (refl _) p
module Poly-Cat where
infix 20 _==_
infixr 30 _─→_ _─→'_
infixr 90 _∘_
private module C = Category
-- Objects
data Obj (ℂ : Cat) : Set1 where
-- obj : C.Obj ℂ -> Obj ℂ
-- obj⁻¹ : {ℂ : Cat} -> Obj ℂ -> C.Obj ℂ
-- obj⁻¹ {ℂ} (obj A) = A
postulate X : Set
-- Arrows
data _─→_ {ℂ : Cat}(A B : Obj ℂ) : Set where
arr : X -> A ─→ B -- C._─→_ ℂ (obj⁻¹ A) (obj⁻¹ B) -> A ─→ B
postulate
ℂ : Cat
A : Obj ℂ
B : Obj ℂ
foo : A ─→ B -> X
foo (arr f) = ?
-- arr⁻¹ : {ℂ : Cat}{A B : Obj ℂ} -> A ─→ B -> C._─→_ ℂ (obj⁻¹ A) (obj⁻¹ B)
-- arr⁻¹ {ℂ}{A}{B} (arr f) = f
open Poly-Cat
open Category hiding (Obj; _─→_)
{-
id : {ℂ : Cat}{A : Obj ℂ} -> A ─→ A
id {ℂ} = arr (Pr.id ℂ)
_∘_ : {ℂ : Cat}{A B C : Obj ℂ} -> B ─→ C -> A ─→ B -> A ─→ C
_∘_ {ℂ} (arr f) (arr g) = arr (Pr.compose ℂ f g)
data _==_ {ℂ : Cat}{A B : Obj ℂ}(f g : A ─→ B) : Set where
eqArr : Pr.equal ℂ (arr⁻¹ f) (arr⁻¹ g) -> f == g
refl : {ℂ : Cat}{A B : Obj ℂ}{f : A ─→ B} -> f == f
refl {ℂ} = eqArr (Pr.refl ℂ)
sym : {ℂ : Cat}{A B : Obj ℂ}{f g : A ─→ B} -> f == g -> g == f
sym {ℂ} (eqArr fg) = eqArr (Pr.sym ℂ fg)
trans : {ℂ : Cat}{A B : Obj ℂ}{f g h : A ─→ B} -> f == g -> g == h -> f == h
trans {ℂ} (eqArr fg) (eqArr gh) = eqArr (Pr.trans ℂ fg gh)
cong : {ℂ : Cat}{A B C : Obj ℂ}{f₁ f₂ : B ─→ C}{g₁ g₂ : A ─→ B} ->
f₁ == f₂ -> g₁ == g₂ -> f₁ ∘ g₁ == f₂ ∘ g₂
cong {ℂ} {f₁ = arr _}{f₂ = arr _}{g₁ = arr _}{g₂ = arr _}
(eqArr p) (eqArr q) = eqArr (Pr.cong ℂ p q)
congL : {ℂ : Cat}{A B C : Obj ℂ}{f₁ f₂ : B ─→ C}{g : A ─→ B} ->
f₁ == f₂ -> f₁ ∘ g == f₂ ∘ g
congL p = cong p refl
congR : {ℂ : Cat}{A B C : Obj ℂ}{f : B ─→ C}{g₁ g₂ : A ─→ B} ->
g₁ == g₂ -> f ∘ g₁ == f ∘ g₂
congR q = cong refl q
Eq : {ℂ : Cat}{A B : Obj ℂ} -> Equivalence (A ─→ B)
Eq = equiv _==_ (\x -> refl) (\x y -> sym) (\x y z -> trans)
idL : {ℂ : Cat}{A B : Obj ℂ}{f : A ─→ B} -> id ∘ f == f
idL {ℂ}{f = arr _} = eqArr (Pr.idL ℂ)
idR : {ℂ : Cat}{A B : Obj ℂ}{f : A ─→ B} -> f ∘ id == f
idR {ℂ}{f = arr _} = eqArr (Pr.idR ℂ)
assoc : {ℂ : Cat}{A B C D : Obj ℂ}{f : C ─→ D}{g : B ─→ C}{h : A ─→ B} ->
(f ∘ g) ∘ h == f ∘ (g ∘ h)
assoc {ℂ}{f = arr _}{g = arr _}{h = arr _} = eqArr (Pr.assoc ℂ)
-}
| 27.345865
| 78
| 0.432224
|
38ff0c7d44177b63928104cc0edf30a62e7f93ab
| 2,782
|
agda
|
Agda
|
Cubical/Algebra/Group/Morphisms.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:28:39.000Z
|
2022-03-05T00:28:39.000Z
|
Cubical/Algebra/Group/Morphisms.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/Morphisms.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-
Defines different notions of morphisms and properties of morphisms of
groups:
- GroupHom (homomorphisms)
- GroupEquiv (equivs which are homomorphisms)
- GroupIso (isos which are homomorphisms)
- Image
- Kernel
- Surjective
- Injective
- Mono
- BijectionIso (surjective + injective)
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Morphisms where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.DirProd
open import Cubical.Data.Sigma
open import Cubical.Reflection.RecordEquiv
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
record IsGroupHom {A : Type ℓ} {B : Type ℓ'}
(M : GroupStr A) (f : A → B) (N : GroupStr B)
: Type (ℓ-max ℓ ℓ')
where
-- Shorter qualified names
private
module M = GroupStr M
module N = GroupStr N
field
pres· : (x y : A) → f (x M.· y) ≡ f x N.· f y
pres1 : f M.1g ≡ N.1g
presinv : (x : A) → f (M.inv x) ≡ N.inv (f x)
unquoteDecl IsGroupHomIsoΣ = declareRecordIsoΣ IsGroupHomIsoΣ (quote IsGroupHom)
GroupHom : (G : Group ℓ) (H : Group ℓ') → Type (ℓ-max ℓ ℓ')
GroupHom G H = Σ[ f ∈ (G .fst → H .fst) ] IsGroupHom (G .snd) f (H .snd)
GroupIso : (G : Group ℓ) (H : Group ℓ') → Type (ℓ-max ℓ ℓ')
GroupIso G H = Σ[ e ∈ Iso (G .fst) (H .fst) ] IsGroupHom (G .snd) (e .Iso.fun) (H .snd)
IsGroupEquiv : {A : Type ℓ} {B : Type ℓ'}
(M : GroupStr A) (e : A ≃ B) (N : GroupStr B) → Type (ℓ-max ℓ ℓ')
IsGroupEquiv M e N = IsGroupHom M (e .fst) N
GroupEquiv : (G : Group ℓ) (H : Group ℓ') → Type (ℓ-max ℓ ℓ')
GroupEquiv G H = Σ[ e ∈ (G .fst ≃ H .fst) ] IsGroupEquiv (G .snd) e (H .snd)
groupEquivFun : {G : Group ℓ} {H : Group ℓ'} → GroupEquiv G H → G .fst → H .fst
groupEquivFun e = e .fst .fst
-- Image, kernel, surjective, injective, and bijections
open IsGroupHom
open GroupStr
private
variable
G H : Group ℓ
isInIm : GroupHom G H → ⟨ H ⟩ → Type _
isInIm {G = G} ϕ h = ∃[ g ∈ ⟨ G ⟩ ] ϕ .fst g ≡ h
isInKer : GroupHom G H → ⟨ G ⟩ → Type _
isInKer {H = H} ϕ g = ϕ .fst g ≡ 1g (snd H)
Ker : GroupHom G H → Type _
Ker {G = G} ϕ = Σ[ x ∈ ⟨ G ⟩ ] isInKer ϕ x
Im : GroupHom G H → Type _
Im {H = H} ϕ = Σ[ x ∈ ⟨ H ⟩ ] isInIm ϕ x
isSurjective : GroupHom G H → Type _
isSurjective {H = H} ϕ = (x : ⟨ H ⟩) → isInIm ϕ x
isInjective : GroupHom G H → Type _
isInjective {G = G} ϕ = (x : ⟨ G ⟩) → isInKer ϕ x → x ≡ 1g (snd G)
isMono : GroupHom G H → Type _
isMono {G = G} f = {x y : ⟨ G ⟩} → f .fst x ≡ f .fst y → x ≡ y
-- Group bijections
record BijectionIso (G : Group ℓ) (H : Group ℓ') : Type (ℓ-max ℓ ℓ') where
constructor bijIso
field
fun : GroupHom G H
inj : isInjective fun
surj : isSurjective fun
| 26
| 87
| 0.626168
|
21241dd03057872ebee824019161a421aa363977
| 26,604
|
agda
|
Agda
|
AAOSL/Hops.agda
|
LaudateCorpus1/aaosl-agda
|
318881fb24af06bbaafa33edeea0745eca1873f0
|
[
"UPL-1.0"
] | 9
|
2020-12-22T00:01:00.000Z
|
2022-03-31T10:16:38.000Z
|
AAOSL/Hops.agda
|
LaudateCorpus1/aaosl-agda
|
318881fb24af06bbaafa33edeea0745eca1873f0
|
[
"UPL-1.0"
] | 5
|
2021-01-04T03:45:34.000Z
|
2021-02-12T04:16:40.000Z
|
AAOSL/Hops.agda
|
LaudateCorpus1/aaosl-agda
|
318881fb24af06bbaafa33edeea0745eca1873f0
|
[
"UPL-1.0"
] | 3
|
2020-12-22T00:01:03.000Z
|
2022-02-18T04:33:50.000Z
|
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0.
Copyright (c) 2020 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 Data.Empty
open import Data.Fin.Properties using (toℕ<n; toℕ-injective)
open import Data.Product
open import Data.Sum
open import Data.Nat
open import Data.Nat.Divisibility
open import Data.Nat.Properties
open import Data.Nat.Induction
open import Data.List renaming (map to List-map)
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Unary.All
import Relation.Binary.PropositionalEquality as Eq
open import Relation.Binary.Definitions
open Eq using (_≡_; refl; trans; sym; cong; cong-app; subst)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
open import Relation.Binary.PropositionalEquality renaming ( [_] to Reveal[_])
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.HeterogeneousEquality
using (_≅_; ≅-to-≡; ≡-to-≅; _≇_)
renaming (cong to ≅-cong; refl to ≅-refl; cong₂ to ≅-cong₂)
open import Relation.Nullary
open import Relation.Binary.Core
open import Relation.Nullary.Negation using (contradiction; contraposition)
import Relation.Nullary using (¬_)
open import Function
-- This module defines the hop relation used by the original AAOSL due to Maniatis
-- and Baker, and proves various properties needed to establish it as a valid
-- DepRel, so that we can instantiate the asbtract model with it to demonstrate that
-- it is an instance of the class of AAOSLs for which we prove our properties.
module AAOSL.Hops where
open import AAOSL.Lemmas
open import Data.Nat.Even
-- The level of an index is 0 for index 0,
-- otherwise, it is one plus the number of times
-- that two divides said index.
--
-- lvlOf must be marked terminating because, in one branch, we make a
-- recursive call on the quotient of the argument. Agda's termination
-- checker cannot confirm that this is structurally smaller than the
-- argument. Use of the pragma is later justified by the proof
-- lvlOf≡lvlOfWF that lvlOf is equal to lvlOfWF, an alternative
-- implementation using well-founded recursion.
{-# TERMINATING #-}
lvlOf : ℕ → ℕ
lvlOf 0 = 0
lvlOf (suc n) with even? (suc n)
...| no _ = 1
...| yes e = suc (lvlOf (quotient e))
-- level of an index with well-founded recursion
lvlOfWFHelp : (n : ℕ) → Acc _<_ n → ℕ
lvlOfWFHelp 0 p = 0
lvlOfWFHelp (suc n) (acc rs) with even? (suc n)
...| no _ = 1
...| yes (divides q eq) = suc (lvlOfWFHelp q (rs q (1+n=m*2⇒m<1+n q n eq)))
lvlOfWF : ℕ → ℕ
lvlOfWF n = lvlOfWFHelp n (<-wellFounded n)
-- When looking at an index in the form 2^k * d, the level of
-- said index is more easily defined.
lvlOf' : ∀{n} → Pow2 n → ℕ
lvlOf' zero = zero
lvlOf' (pos l _ _ _) = suc l
-------------------------------------------
-- Properties of lvlOf, lvlOfWF, and lvlOf'
lvlOf≡lvlOfWFHelp : (n : ℕ) (p : Acc _<_ n) → lvlOf n ≡ lvlOfWFHelp n p
lvlOf≡lvlOfWFHelp 0 p = refl
lvlOf≡lvlOfWFHelp (suc n) (acc rs) with even? (suc n)
...| no _ = refl
...| yes (divides q eq) =
cong suc (lvlOf≡lvlOfWFHelp q (rs q (1+n=m*2⇒m<1+n q n eq)))
lvlOf≡lvlOfWF : (n : ℕ) → lvlOf n ≡ lvlOfWF n
lvlOf≡lvlOfWF n = lvlOf≡lvlOfWFHelp n (<-wellFounded n)
lvlOf≡lvlOf' : ∀ n → lvlOf n ≡ lvlOf' (to n)
lvlOf≡lvlOf' n rewrite lvlOf≡lvlOfWF n = go n (<-wellFounded n)
where
go : (n : ℕ) (p : Acc _<_ n) → lvlOfWFHelp n p ≡ lvlOf' (to n)
go 0 p = refl
go (suc n) (acc rs) with even? (suc n)
...| no _ = refl
...| yes (divides q eq) with go q (rs q (1+n=m*2⇒m<1+n q n eq))
...| ih with to q
...| pos l d odd prf = cong suc ih
lvl≥2-even : ∀ {n} → 2 ≤ lvlOf n → Even n
lvl≥2-even {suc n} x
with 2 ∣? (suc n)
...| yes prf = prf
...| no prf = ⊥-elim ((≤⇒≯ x) (s≤s (s≤s z≤n)))
lvlOfodd≡1 : ∀ n → Odd n → lvlOf n ≡ 1
lvlOfodd≡1 0 nodd = ⊥-elim (nodd (divides zero refl))
lvlOfodd≡1 (suc n) nodd
with even? (suc n)
...| yes prf = ⊥-elim (nodd prf)
...| no prf = refl
-- We eventually need to 'undo' a level
lvlOf-undo : ∀{j}(e : Even (suc j)) → suc (lvlOf (quotient e)) ≡ lvlOf (suc j)
lvlOf-undo {j} e with even? (suc j)
...| no abs = ⊥-elim (abs e)
...| yes prf rewrite even-irrelevant e prf = refl
∣-cmp : ∀{t u n} → (suc t * u) ∣ n → (d : suc t ∣ n) → u ∣ (quotient d)
∣-cmp {t} {u} {n} (divides q1 e1) (divides q2 e2)
rewrite sym (*-assoc q1 (suc t) u)
| *-comm q1 (suc t)
| *-comm q2 (suc t)
| *-assoc (suc t) q1 u
= divides q1 (*-cancelˡ-≡ t (trans (sym e2) e1))
∣-0< : ∀{n t} → 0 < n → (d : suc t ∣ n) → 0 < quotient d
∣-0< hip (divides zero e) = ⊥-elim (<⇒≢ hip (sym e))
∣-0< hip (divides (suc q) e) = s≤s z≤n
lvlOf-mono : ∀{n} k → 0 < n → 2 ^ k ∣ n → k ≤ lvlOf n
lvlOf-mono zero hip prf = z≤n
lvlOf-mono {suc n} (suc k) hip prf
with even? (suc n)
...| no abs = ⊥-elim (abs (divides (quotient prf * (2 ^ k))
(trans (_∣_.equality prf)
(trans (cong ((quotient prf) *_) (sym (*-comm (2 ^ k) 2)))
(sym (*-assoc (quotient prf) (2 ^ k) 2))))))
...| yes prf' = s≤s (lvlOf-mono {quotient prf'} k (∣-0< hip prf') (∣-cmp prf prf'))
-- This property can be strenghtened to < if we ever need.
lvlOf'-mono : ∀{k} d → 0 < d → k ≤ lvlOf' (to (2 ^ k * d))
lvlOf'-mono {k} d 0<d
with to d
...| pos {d} kk dd odd eq
with (2 ^ (k + kk)) * dd ≟ (2 ^ k) * d
...| no xx = ⊥-elim (xx ( trans (cong (_* dd) (^-distribˡ-+-* 2 k kk))
(trans (*-assoc (2 ^ k) (2 ^ kk) dd)
(cong (λ x → (2 ^ k) * x) (sym eq)))))
...| yes xx
with to-reduce {(2 ^ k) * d} {k + kk} {dd} (sym xx) odd
...| xx1 = ≤-trans (≮⇒≥ (m+n≮m k kk))
(≤-trans (n≤1+n (k + kk)) -- TODO-1: easy to strengthen to <; omit this step
(≤-reflexive (sym (cong lvlOf' xx1))))
-- And a progress property about levels:
-- These will be much easier to reason about in terms of lvlOf'
-- as we can see in lvlOf-correct.
lvlOf-correct : ∀{l j} → l < lvlOf j → 2 ^ l ≤ j
lvlOf-correct {l} {j} prf
rewrite lvlOf≡lvlOf' j
with to j
...| zero = ⊥-elim (1+n≢0 (n≤0⇒n≡0 prf))
...| pos l' d odd refl = 2^kd-mono (≤-unstep2 prf) (0<odd odd)
-- lvlOf-prog states that if we have not reached 0, we landed somewhere
-- where we can hop again at the same level.
lvlOf-prog : ∀{l j} → 0 < j ∸ 2 ^ l → l < lvlOf j → l < lvlOf (j ∸ 2 ^ l)
lvlOf-prog {l} {j} hip l<lvl
rewrite lvlOf≡lvlOf' j | lvlOf≡lvlOf' (j ∸ 2 ^ l)
with to j
...| zero = ⊥-elim (1+n≰n (≤-trans l<lvl z≤n))
...| pos l₁ d₁ o₁ refl
rewrite 2^ld-2l l₁ l d₁ (≤-unstep2 l<lvl)
with l ≟ l₁
...| no l≢l₁ rewrite to-2^kd l (odd-2^kd-1 (l₁ ∸ l) d₁
(0<m-n (≤∧≢⇒< (≤-unstep2 l<lvl) l≢l₁))
(0<odd o₁))
= ≤-refl
...| yes refl rewrite n∸n≡0 l₁ | +-comm d₁ 0
with odd∸1-even o₁
...| divides q prf rewrite prf
| sym (*-assoc (2 ^ l₁) q 2)
| a*b*2-lemma (2 ^ l₁) q
= lvlOf'-mono {suc l₁} q (1≤m*n⇒0<n {m = 2 ^ suc l₁} hip)
lvlOf-no-overshoot : ∀ j l → suc l < lvlOf j → 0 < j ∸ 2 ^ l
lvlOf-no-overshoot j l hip
rewrite lvlOf≡lvlOf' j with to j
...| zero = ⊥-elim (1+n≰n (≤-trans (s≤s z≤n) hip))
...| pos k d o refl = 0<m-n {2 ^ k * d} {2 ^ l}
(<-≤-trans (2^-mono (≤-unstep2 hip))
(2^kd-mono {k} {k} ≤-refl (0<odd o)))
---------------------------
-- The AAOSL Structure --
---------------------------
-------------------------------
-- Hops
-- Encoding our hops into a relation. A value of type 'H l j i'
-- witnesses the existence of a hop from j to i at level l.
data H : ℕ → ℕ → ℕ → Set where
hz : ∀ x → H 0 (suc x) x
hs : ∀ {l x y z}
→ H l x y
→ H l y z
→ suc l < lvlOf x
→ H (suc l) x z
-----------------------------
-- Hop's universal properties
-- The universal property comes for free
h-univ : ∀{l j i} → H l j i → i < j
h-univ (hz x) = s≤s ≤-refl
h-univ (hs h h₁ _) = <-trans (h-univ h₁) (h-univ h)
-- It is easy to prove there are no hops from zero
h-from0-⊥ : ∀{l i} → H l 0 i → ⊥
h-from0-⊥ (hs h h₁ _) = h-from0-⊥ h
-- And it is easy to prove that i is a distance of 2 ^ l away
-- from j.
h-univ₂ : ∀{l i j} → H l j i → i ≡ j ∸ 2 ^ l
h-univ₂ (hz x) = refl
h-univ₂ (hs {l = l} {j} h₀ h₁ _)
rewrite h-univ₂ h₀
| h-univ₂ h₁
| +-comm (2 ^ l) 0
| sym (∸-+-assoc j (2 ^ l) (2 ^ l))
= refl
-- and vice versa.
h-univ₁ : ∀{l i j} → H l j i → j ≡ i + 2 ^ l
h-univ₁ (hz x) = sym (+-comm x 1)
h-univ₁ (hs {l = l} {z = i} h₀ h₁ _)
rewrite h-univ₁ h₀
| h-univ₁ h₁
| +-comm (2 ^ l) 0
= +-assoc i (2 ^ l) (2 ^ l)
--------------
-- H and lvlOf
-- A value of type H says something about the levels of their indices
h-lvl-src : ∀{l j i} → H l j i → l < lvlOf j
h-lvl-src (hz x) with even? (suc x)
...| no _ = s≤s z≤n
...| yes _ = s≤s z≤n
h-lvl-src (hs h₀ h₁ prf) = prf
h-lvl-tgt : ∀{l j i} → 0 < i → H l j i → l < lvlOf i
h-lvl-tgt prf h rewrite h-univ₂ h = lvlOf-prog prf (h-lvl-src h)
h-lvl-inj : ∀{l₁ l₂ j i} (h₁ : H l₁ j i)(h₂ : H l₂ j i) → l₁ ≡ l₂
h-lvl-inj {i = i} h₁ h₂
= 2^-injective (+-cancelˡ-≡ i (trans (sym (h-univ₁ h₁)) (h-univ₁ h₂)))
-- TODO-1: document reasons for this pragma and justify it
{-# TERMINATING #-}
h-lvl-half : ∀{l j i y l₁} → H l j y → H l y i → H l₁ j i → lvlOf y ≡ suc l
h-lvl-half w₀ w₁ (hz n) = ⊥-elim (1+n≰n (≤-<-trans (h-univ w₁) (h-univ w₀)))
h-lvl-half {l}{j}{i}{y} w₀ w₁ (hs {l = l₁} {y = y₁} sh₀ sh₁ x)
-- TODO-2: factor out a lemma to prove l₁ ≡ l and y₁ ≡ y (already exists?)
with l₁ ≟ l
...| no imp
with j ≟ i + (2 ^ l₁) + (2 ^ l₁) | j ≟ i + (2 ^ l) + (2 ^ l)
...| no imp1 | _ rewrite h-univ₁ sh₁ = ⊥-elim (imp1 (h-univ₁ sh₀))
...| yes _ | no imp1 rewrite h-univ₁ w₁ = ⊥-elim (imp1 (h-univ₁ w₀))
...| yes j₁ | yes j₂
with trans (sym j₂) j₁
...| xx5 rewrite +-assoc i (2 ^ l) (2 ^ l)
| +-assoc i (2 ^ l₁) (2 ^ l₁)
with +-cancelˡ-≡ i xx5
...| xx6 rewrite sym (+-identityʳ (2 ^ l))
| sym (+-identityʳ (2 ^ l₁))
| +-assoc (2 ^ l) 0 ((2 ^ l) + 0)
| +-assoc (2 ^ l₁) 0 ((2 ^ l₁) + 0)
| *-comm 2 (2 ^ l)
| *-comm 2 (2 ^ l₁)
= ⊥-elim (imp (sym (2^-injective {l} {l₁} (
sym (*2-injective (2 ^ l) (2 ^ l₁) xx6)))))
h-lvl-half {l = l}{j = j}{i = i}{y = y} w₀ w₁ (hs {l = l₁} {y = y₁} sh₀ sh₁ x)
| yes xx1 rewrite xx1
with y₁ ≟ y
...| no imp = ⊥-elim (imp (+-cancelʳ-≡ y₁ y (trans (sym (h-univ₁ sh₀)) (h-univ₁ w₀))))
...| yes y₁≡y rewrite y₁≡y
with w₀
...| hs {l = l-1} ssh₀ ssh₁ xx rewrite sym xx1
= h-lvl-half sh₀ sh₁ (hs sh₀ sh₁ x)
...| hz y = lvlOfodd≡1 y (even-suc-odd y (lvl≥2-even {suc y} x))
-- If a hop goes over an index, then the level of this index is strictly
-- less than the level of the hop. The '≤' is there because
-- l starts at zero.
--
-- For example, lvlOf 4 ≡ 3; the only hops that can go over 4 are
-- those with l of 3 or higher. In fact, there is one at l ≡ 2
-- from 4 to 0: H 2 4 0
h-lvl-mid : ∀{l j i} → (k : ℕ) → H l j i → i < k → k < j → lvlOf k ≤ l
h-lvl-mid k (hz x) i<k k<j = ⊥-elim (n≮n k (<-≤-trans k<j i<k))
h-lvl-mid {j = j} k (hs {l = l₀}{y = y} w₀ w₁ x) i<k k<j
with <-cmp k y
...| tri< k<y k≢y k≯y = ≤-step (h-lvl-mid k w₁ i<k k<y)
...| tri> k≮y k≢y k>y = ≤-step (h-lvl-mid k w₀ k>y k<j)
...| tri≈ k≮y k≡y k≯y rewrite k≡y = ≤-reflexive (h-lvl-half w₀ w₁ (hs {l = l₀}{y = y} w₀ w₁ x))
h-lvl-≤₁ : ∀{l₁ l₂ j i₁ i₂}
→ (h : H l₁ j i₁)(v : H l₂ j i₂)
→ i₂ < i₁
→ l₁ < l₂
h-lvl-≤₁ {l₁} {l₂} {j} {i₁} {i₂} h v i₂<i₁ =
let h-univ = h-univ₁ h
v-univ = h-univ₁ v
eqj = trans (sym v-univ) h-univ
in log-mono l₁ l₂ (n+p≡m+q∧n<m⇒q<p i₂<i₁ eqj)
h-lvl-≤₂ : ∀{l₁ l₂ j₁ j₂ i}
→ (h : H l₁ j₁ i)(v : H l₂ j₂ i)
→ j₁ < j₂
→ l₁ < l₂
h-lvl-≤₂ {l₁} {l₂} {j₁} {j₂} {i} h v j₂<j₁ =
let h-univ = h-univ₁ h
v-univ = h-univ₁ v
in log-mono l₁ l₂ (+-cancelˡ-< i (subst (i + (2 ^ l₁) <_) v-univ (subst (_< j₂) h-univ j₂<j₁)))
------------------------------
-- Correctness and Irrelevance
h-correct : ∀ j l → l < lvlOf j → H l j (j ∸ 2 ^ l)
h-correct (suc j) zero prf = hz j
h-correct (suc j) (suc l) prf
with h-correct (suc j) l
...| ind with 2 ∣? (suc j)
...| no _ = ⊥-elim (ss≰1 prf)
...| yes e with ind (≤-unstep prf)
...| res₀
with h-correct (suc j ∸ 2 ^ l) l
(lvlOf-prog {l} {suc j}
(lvlOf-no-overshoot (suc j) l (subst (suc l <_ ) (lvlOf-undo e) prf))
(subst (l <_) (lvlOf-undo e) (≤-unstep prf)))
...| res₁
rewrite +-comm (2 ^ l) 0
| ∸-+-assoc (suc j) (2 ^ l) (2 ^ l)
= hs res₀ res₁ (subst (suc l <_) (lvlOf-undo e) prf)
h-irrelevant : ∀{l i j}
→ (h₁ : H l j i)
→ (h₂ : H l j i)
→ h₁ ≡ h₂
h-irrelevant (hz x) (hz .x) = refl
h-irrelevant (hs {y = y} h₁ h₃ x) (hs {y = z} h₂ h₄ x₁)
rewrite ≤-irrelevant x x₁
with y ≟ z
...| no abs = ⊥-elim (abs (trans (h-univ₂ h₁) (sym (h-univ₂ h₂))))
...| yes refl = cong₂ (λ P Q → hs P Q x₁) (h-irrelevant h₁ h₂) (h-irrelevant h₃ h₄)
-------------------------------------------------------------------
-- The non-overlapping property is stated in terms
-- of subhops. The idea is that a hop is either separate
-- from another one, or is entirely contained within the larger one.
--
-- Entirely contained comes from _⊆Hop_
data _⊆Hop_ : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ H l₁ j₁ i₁
→ H l₂ j₂ i₂
→ Set where
here : ∀{l i j}(h : H l j i) → h ⊆Hop h
left : ∀{l₁ i₁ j₁ l₂ i₂ w j₂ }
→ (h : H l₁ j₁ i₁)
→ (w₀ : H l₂ j₂ w)
→ (w₁ : H l₂ w i₂)
→ (p : suc l₂ < lvlOf j₂)
→ h ⊆Hop w₀
→ h ⊆Hop (hs w₀ w₁ p)
right : ∀{l₁ i₁ j₁ l₂ i₂ w j₂}
→ (h : H l₁ j₁ i₁)
→ (w₀ : H l₂ j₂ w)
→ (w₁ : H l₂ w i₂)
→ (p : suc l₂ < lvlOf j₂)
→ h ⊆Hop w₁
→ h ⊆Hop (hs w₀ w₁ p)
⊆Hop-refl : ∀{l₁ l₂ j i}
→ (h₁ : H l₁ j i)
→ (h₂ : H l₂ j i)
→ h₁ ⊆Hop h₂
⊆Hop-refl h₁ h₂ with h-lvl-inj h₁ h₂
...| refl rewrite h-irrelevant h₁ h₂ = here h₂
⊆Hop-univ : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h1 : H l₁ j₁ i₁)
→ (h2 : H l₂ j₂ i₂)
→ h1 ⊆Hop h2
→ i₂ ≤ i₁ × j₁ ≤ j₂ × l₁ ≤ l₂
⊆Hop-univ h1 .h1 (here .h1) = ≤-refl , ≤-refl , ≤-refl
⊆Hop-univ h1 (hs w₀ w₁ p) (left h1 w₀ w₁ q hip)
with ⊆Hop-univ h1 w₀ hip
...| a , b , c = (≤-trans (<⇒≤ (h-univ w₁)) a) , b , ≤-step c
⊆Hop-univ h1 (hs w₀ w₁ p) (right h1 w₀ w₁ q hip)
with ⊆Hop-univ h1 w₁ hip
...| a , b , c = a , ≤-trans b (<⇒≤ (h-univ w₀)) , ≤-step c
⊆Hop-univ₁ : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h1 : H l₁ j₁ i₁)
→ (h2 : H l₂ j₂ i₂)
→ h1 ⊆Hop h2
→ i₂ ≤ i₁
⊆Hop-univ₁ h1 h2 h1h2 = proj₁ (⊆Hop-univ h1 h2 h1h2)
⊆Hop-src-≤ : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h1 : H l₁ j₁ i₁)
→ (h2 : H l₂ j₂ i₂)
→ h1 ⊆Hop h2
→ j₁ ≤ j₂
⊆Hop-src-≤ h1 h2 h1h2 = (proj₁ ∘ proj₂) (⊆Hop-univ h1 h2 h1h2)
-- If two hops are not strictly the same, then the level of
-- the smaller hop is strictly smaller than the level of
-- the bigger hop.
--
-- VERY IMPORTANT
⊆Hop-univ-lvl : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h₁ : H l₁ j₁ i₁)
→ (h₂ : H l₂ j₂ i₂)
→ h₁ ⊆Hop h₂
→ j₁ < j₂
→ l₁ < l₂
⊆Hop-univ-lvl {l₁}{i₁}{j₁}{l₂}{i₂}{j₂} h₁ h₂ h₁⊆Hoph₂ j₁<j₂
= let r₁ : i₂ + (2 ^ l₁) ≤ i₁ + (2 ^ l₁)
r₁ = +-monoˡ-≤ (2 ^ l₁) (proj₁ (⊆Hop-univ h₁ h₂ h₁⊆Hoph₂))
r₂ : i₁ + (2 ^ l₁) < i₂ + (2 ^ l₂)
r₂ = subst₂ _<_ (h-univ₁ h₁) (h-univ₁ h₂) j₁<j₂
in log-mono l₁ l₂ ((+-cancelˡ-< i₂) (≤-<-trans r₁ r₂))
hz-⊆ : ∀{l j i k}
→ (v : H l j i)
→ i ≤ k
→ k < j
→ hz k ⊆Hop v
hz-⊆ (hz x) i<k k<j
rewrite ≤-antisym (≤-unstep2 k<j) i<k = here (hz x)
hz-⊆ {k = k} (hs {y = y} v v₁ x) i<k k<j
with k <? y
...| yes k<y = right (hz k) v v₁ x (hz-⊆ v₁ i<k k<y)
...| no k≮y = left (hz k) v v₁ x (hz-⊆ v (≮⇒≥ k≮y) k<j)
⊆Hop-inj₁ : ∀{l₁ l₂ j i₁ i₂}
→ (h : H l₁ j i₁)(v : H l₂ j i₂)
→ i₂ < i₁
→ h ⊆Hop v
⊆Hop-inj₁ {i₁ = i₁} h (hz x) prf
= ⊥-elim (n≮n i₁ (<-≤-trans (h-univ h) prf))
⊆Hop-inj₁ {l} {j = j} {i₁ = i₁} h (hs {l = l₁} {y = y} v v₁ x) prf
with y ≟ i₁
...| yes refl = left h v v₁ x (⊆Hop-refl h v)
...| no y≢i₁
with h-lvl-≤₁ h (hs v v₁ x) prf
...| sl≤sl₁
with h-univ₂ h | h-univ₂ v
...| prf1 | prf2
= let r : j ∸ (2 ^ l₁) ≤ j ∸ (2 ^ l)
r = ∸-monoʳ-≤ {m = 2 ^ l} {2 ^ l₁} j (^-mono l l₁ (≤-unstep2 sl≤sl₁))
in left h v v₁ x (⊆Hop-inj₁ h v (≤∧≢⇒< (subst₂ _≤_ (sym prf2) (sym prf1) r) y≢i₁))
⊆Hop-inj₂ : ∀{l₁ l₂ j₁ j₂ i}
→ (h : H l₁ j₁ i)(v : H l₂ j₂ i)
→ j₁ < j₂
→ h ⊆Hop v
⊆Hop-inj₂ h (hz x) prf
= ⊥-elim (n≮n _ (<-≤-trans prf (h-univ h)))
⊆Hop-inj₂ {l} {j₁ = j₁} {i = i} h (hs {l = l₁} {y = y} v v₁ x) prf
with y ≟ j₁
...| yes refl = right h v v₁ x (⊆Hop-refl h v₁)
...| no y≢j₁
with h-lvl-≤₂ h (hs v v₁ x) prf
...| sl≤sl₁
with h-univ₁ h | h-univ₁ v₁
...| prf1 | prf2
= let r : i + 2 ^ l ≤ i + 2 ^ l₁
r = +-monoʳ-≤ i (^-mono l l₁ (≤-unstep2 sl≤sl₁))
in right h v v₁ x (⊆Hop-inj₂ h v₁ (≤∧≢⇒< (subst₂ _≤_ (sym prf1) (sym prf2) r) (y≢j₁ ∘ sym)))
⊆Hop-inj₃ : ∀{l₁ l₂ j₁ j₂ i₁ i₂}
→ (h : H l₁ j₁ i₁)(v : H l₂ j₂ i₂)
→ i₁ ≡ i₂ → j₁ ≡ j₂ → h ⊆Hop v
⊆Hop-inj₃ h v refl refl with h-lvl-inj h v
...| refl rewrite h-irrelevant h v = here v
-- This datatype encodes all the possible hop situations. This makes is
-- much easier to structure proofs talking about two hops.
data HopStatus : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ H l₁ j₁ i₁
→ H l₂ j₂ i₂
→ Set where
-- Same hop; we carry the proofs explicitly here to be able to control
-- when to perform the rewrites.
Same : ∀{l₁ i₁ j₁ l₂ i₂ j₂}(h₁ : H l₁ j₁ i₁)(h₂ : H l₂ j₂ i₂)
→ i₁ ≡ i₂
→ j₁ ≡ j₂
→ HopStatus h₁ h₂
-- h₂ h₁
-- ⌜⁻⁻⁻⁻⁻⁻⁻⌝ ⌜⁻⁻⁻⁻⁻⁻⁻⌝
-- | | | |
-- i₂ < j₂ ≤ i₁ < j₁
SepL : ∀{l₁ i₁ j₁ l₂ i₂ j₂}(h₁ : H l₁ j₁ i₁)(h₂ : H l₂ j₂ i₂)
→ j₂ ≤ i₁
→ HopStatus h₁ h₂
-- h₁ h₂
-- ⌜⁻⁻⁻⁻⁻⁻⁻⌝ ⌜⁻⁻⁻⁻⁻⁻⁻⌝
-- | | | |
-- i₁ < j₁ ≤ i₂ < j₂
SepR : ∀{l₁ i₁ j₁ l₂ i₂ j₂}(h₁ : H l₁ j₁ i₁)(h₂ : H l₂ j₂ i₂)
→ j₁ ≤ i₂
→ HopStatus h₁ h₂
-- h₂
-- ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝
-- ∣ ∣
-- ∣ h₁ ∣
-- ∣ ⌜⁻⁻⁻⁻⁻⁻⁻⌝ |
-- | | | |
-- i₂ ≤ i₁ ⋯ j₁ ≤ j₂
SubL : ∀{l₁ i₁ j₁ l₂ i₂ j₂}(h₁ : H l₁ j₁ i₁)(h₂ : H l₂ j₂ i₂)
→ i₂ < i₁ ⊎ j₁ < j₂ -- makes sure hops differ!
→ h₁ ⊆Hop h₂
→ HopStatus h₁ h₂
-- h₁
-- ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝
-- ∣ ∣
-- ∣ h₂ ∣
-- ∣ ⌜⁻⁻⁻⁻⁻⁻⁻⌝ |
-- | | | |
-- i₁ ≤ i₂ ⋯ j₂ < j₁
SubR : ∀{l₁ i₁ j₁ l₂ i₂ j₂}(h₁ : H l₁ j₁ i₁)(h₂ : H l₂ j₂ i₂)
→ i₁ < i₂ ⊎ j₂ < j₁ -- makes sure hops differ
→ h₂ ⊆Hop h₁
→ HopStatus h₁ h₂
-- Finally, we can prove our no-overlap property. As it turns out, it is
-- just a special case of general non-overlapping, and therefore, it is
-- defined as such.
mutual
-- Distinguish is used to understand the relation between two arbitrary hops.
-- It is used to perform the induction step on arbitrary hops. Note how
-- 'no-overlap' has a clause that impedes the hops from being equal.
distinguish : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h₁ : H l₁ j₁ i₁)
→ (h₂ : H l₂ j₂ i₂)
→ HopStatus h₁ h₂
distinguish {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h1 h2
with <-cmp i₁ i₂
...| tri≈ i₁≮i₂ i₁≡i₂ i₂≮i₁
with <-cmp j₁ j₂
...| tri≈ j₁≮j₂ j₁≡j₂ j₂≮j₁ = Same h1 h2 i₁≡i₂ j₁≡j₂
...| tri< j₁<j₂ j₁≢j₂ j₂≮j₁ rewrite i₁≡i₂ = SubL h1 h2 (inj₂ j₁<j₂) (⊆Hop-inj₂ h1 h2 j₁<j₂)
...| tri> j₁≮j₂ j₁≢j₂ j₂<j₁ rewrite i₁≡i₂ = SubR h1 h2 (inj₂ j₂<j₁) (⊆Hop-inj₂ h2 h1 j₂<j₁)
distinguish {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h1 h2
| tri< i₁<i₂ i₁≢i₂ i₂≮i₁
with <-cmp j₁ j₂
...| tri≈ j₁≮j₂ j₁≡j₂ j₂≮j₁ rewrite j₁≡j₂ = SubR h1 h2 (inj₁ i₁<i₂) (⊆Hop-inj₁ h2 h1 i₁<i₂)
...| tri< j₁<j₂ j₁≢j₂ j₂≮j₁ with no-overlap h2 h1 i₁<i₂
...| inj₁ a = SepR h1 h2 a
...| inj₂ b = SubR h1 h2 (inj₁ i₁<i₂) b
distinguish {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h1 h2
| tri< i₁<i₂ i₁≢i₂ i₂≮i₁
| tri> j₁≮j₂ j₁≢j₂ j₂<j₁ with no-overlap h2 h1 i₁<i₂
...| inj₁ a = SepR h1 h2 a
...| inj₂ b = SubR h1 h2 (inj₁ i₁<i₂) b
distinguish {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h1 h2
| tri> i₁≮i₂ i₁≢i₂ i₂<i₁
with <-cmp j₁ j₂
...| tri≈ j₁≮j₂ j₁≡j₂ j₂≮j₁ rewrite j₁≡j₂ = SubL h1 h2 (inj₁ i₂<i₁) (⊆Hop-inj₁ h1 h2 i₂<i₁)
...| tri< j₁<j₂ j₁≢j₂ j₂≮j₁ with no-overlap h1 h2 i₂<i₁
...| inj₁ a = SepL h1 h2 a
...| inj₂ b = SubL h1 h2 (inj₁ i₂<i₁) b
distinguish {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h1 h2
| tri> i₁≮i₂ i₁≢i₂ i₂<i₁
| tri> j₁≮j₂ j₁≢j₂ j₂<j₁ with no-overlap h1 h2 i₂<i₁
...| inj₁ a = SepL h1 h2 a
...| inj₂ b = SubL h1 h2 (inj₁ i₂<i₁) b
no-overlap-< : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h₁ : H l₁ j₁ i₁)
→ (h₂ : H l₂ j₂ i₂)
→ i₂ < i₁
→ i₁ < j₂
→ j₁ ≤ j₂
no-overlap-< h₁ h₂ prf hip with no-overlap h₁ h₂ prf
...| inj₁ imp = ⊥-elim (1+n≰n (≤-trans hip imp))
...| inj₂ res = ⊆Hop-src-≤ h₁ h₂ res
-- TODO-1: rename to nocross for consistency with paper
-- Non-overlapping is more general, as hops might be completely
-- separate and then, naturally won't overlap.
no-overlap : ∀{l₁ i₁ j₁ l₂ i₂ j₂}
→ (h₁ : H l₁ j₁ i₁)
→ (h₂ : H l₂ j₂ i₂)
→ i₂ < i₁ -- this ensures h₁ ≢ h₂.
→ (j₂ ≤ i₁) ⊎ (h₁ ⊆Hop h₂)
no-overlap h (hz x) prf = inj₁ prf
no-overlap {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h₁ (hs {y = y} v₀ v₁ v-ok) hip
with distinguish h₁ v₀
...| SepL _ _ prf = inj₁ prf
...| SubL _ _ case prf = inj₂ (left h₁ v₀ v₁ v-ok prf)
...| Same _ _ p1 p2 = inj₂ (left h₁ v₀ v₁ v-ok (⊆Hop-inj₃ h₁ v₀ p1 p2))
no-overlap {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h₁ (hs {y = y} v₀ v₁ v-ok) hip
| SepR _ _ j₁≤y
with distinguish h₁ v₁
...| SepL _ _ prf = ⊥-elim (<⇒≱ (h-univ h₁) (≤-trans j₁≤y prf))
...| SepR _ _ prf = ⊥-elim (n≮n i₂ (<-trans hip (<-≤-trans (h-univ h₁) prf)))
...| SubR _ _ (inj₁ i₁<i₂) prf = ⊥-elim (n≮n i₂ (<-trans hip i₁<i₂))
...| SubR _ _ (inj₂ y<j₁) prf = ⊥-elim (n≮n j₁ (≤-<-trans j₁≤y y<j₁))
...| SubL _ _ case prf = inj₂ (right h₁ v₀ v₁ v-ok prf)
...| Same _ _ p1 p2 = inj₂ (right h₁ v₀ v₁ v-ok (⊆Hop-inj₃ h₁ v₁ p1 p2))
no-overlap {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h₁ (hs {y = y} v₀ v₁ v-ok) hip
| SubR _ _ (inj₁ i₁<y) v₀⊆h₁
with distinguish h₁ v₁
...| SepL _ _ prf = ⊥-elim (n≮n i₁ (<-≤-trans i₁<y prf))
...| SepR _ _ prf = ⊥-elim (n≮n i₂ (<-≤-trans (<-trans hip (h-univ h₁)) prf))
...| SubR _ _ (inj₁ i₁<i₂) prf = ⊥-elim (n≮n i₂ (<-trans hip i₁<i₂))
...| SubR _ _ (inj₂ y<j₁) prf = ⊥-elim (≤⇒≯ (no-overlap-< h₁ v₁ hip i₁<y) y<j₁)
...| SubL _ _ case prf = inj₂ (right h₁ v₀ v₁ v-ok prf)
...| Same _ _ p1 p2 = inj₂ (right h₁ v₀ v₁ v-ok (⊆Hop-inj₃ h₁ v₁ p1 p2))
no-overlap {l₁} {i₁} {j₁} {l₂} {i₂} {j₂} h₁ (hs {y = y} v₀ v₁ v-ok) hip
-- Here is the nasty case. We have to argue why this is impossible
-- WITHOUT resorting to 'nov h₁ (hs v₀ v₁ v-ok)', otherwise this would
-- result in an infinite loop. Note how 'nov' doesn't pattern match
-- on any argument.
--
-- Here's what this looks like:
--
-- (hs v₀ v₁ v-ok)
-- ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝
-- | h₁ |
-- | ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁺⁻⁻⁻⁻⁻⁻⁻⌝
-- | ∣ | ∣
-- | v₁ ∣ v₀ | ∣
-- ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁺⁻⁻⁻⁻⁻⁻⌜⁻⁻⁻⁻⁻⁻⁻⌝ |
-- | | | | |
-- i₂ < i₁ ≤ y ⋯ j₂ < j₁
--
-- We can pattern match on i₁ ≟ y
| SubR _ _ (inj₂ j₂<j₁) v₀⊆h₁
with i₁ ≟ y
-- And we quickly discover that if i≢y, we have a crossing between
-- v₁ and h₁, and that's impossible.
...| no i₁≢y = ⊥-elim (n≮n y (<-≤-trans (<-trans (h-univ v₀) j₂<j₁)
(no-overlap-< h₁ v₁ hip (≤∧≢⇒< (⊆Hop-univ₁ v₀ h₁ v₀⊆h₁) i₁≢y))))
-- The hard part really is when i₁ ≡ y, here's how this looks like:
--
-- (hs v₀ v₁ v-ok)
-- lvl l+1 ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝
-- | | h₁
-- | ⌜⁻⁻⁻⁻⁻⁻⁻⁺⁻⁻⁻⁻⁻⁻⁻⌝ lvl l₁
-- | ∣ | ∣
-- | v₁ ∣ v₀ | ∣
-- lvl l ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁺⁻⁻⁻⁻⁻⁻⁻⌝ |
-- | | | |
-- i₂ < i₁ ⋯ j₂ < j₁
--
-- We must show that the composite hop (hs v₀ v₁ v-ok) is impossible to build
-- to show that the crossing doesn't happen.
--
-- Hence, we MUST reason about the levels of the indices and eliminate 'v-ok',
-- Which is possible with a bit of struggling about levels.
...| yes refl with h-lvl-tgt (≤-trans (s≤s z≤n) hip) v₀
...| l≤lvli₁ with ⊆Hop-univ-lvl _ _ v₀⊆h₁ j₂<j₁
...| l<l₁ with h-lvl-mid i₁ (hs v₀ v₁ v-ok) hip (h-univ v₀)
...| lvli₁≤l+1 with h-lvl-tgt (≤-trans (s≤s z≤n) hip) h₁
...| l₁≤lvli₁ rewrite ≤-antisym lvli₁≤l+1 l≤lvli₁
= ⊥-elim (n≮n _ (<-≤-trans l<l₁ (≤-unstep2 l₁≤lvli₁)))
| 39.066079
| 111
| 0.486919
|
358ae8a0dca140f6549f0959916a4d674ad9cd10
| 2,898
|
agda
|
Agda
|
agda/Chord.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 28
|
2017-04-21T09:08:52.000Z
|
2022-03-04T18:04:07.000Z
|
agda/Chord.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 1
|
2020-11-13T01:26:20.000Z
|
2020-11-17T00:58:55.000Z
|
agda/Chord.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 3
|
2019-01-12T17:02:36.000Z
|
2020-11-10T04:04:40.000Z
|
{-# OPTIONS --cubical --safe #-}
module Chord where
open import Cubical.Core.Everything using (_≡_; Level; Type; Σ; _,_; fst; snd; _≃_; ~_)
open import Data.Fin using (Fin; toℕ) renaming (zero to fz; suc to fs)
open import Data.List using (List; map; []; _∷_; _++_; zip)
open import Data.Nat using (ℕ)
open import Data.Product using (_×_)
open import Data.String using (String) renaming (_++_ to _++s_)
open import Function using (_∘_)
open import AssocList
open import BitVec
open import Pitch
open import Util using (_+N_)
data Root : Type where
root : Fin s12 → Root
showRoot : Root → String
showRoot (root fz) = "I"
showRoot (root (fs fz)) = "♭II"
showRoot (root (fs (fs fz))) = "II"
showRoot (root (fs (fs (fs fz)))) = "♭III"
showRoot (root (fs (fs (fs (fs fz))))) = "III"
showRoot (root (fs (fs (fs (fs (fs fz)))))) = "IV"
showRoot (root (fs (fs (fs (fs (fs (fs fz))))))) = "♭V"
showRoot (root (fs (fs (fs (fs (fs (fs (fs fz)))))))) = "V"
showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))) = "♭VI"
showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))) = "VI"
showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))))) = "♭VII"
showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))))) = "VII"
data Quality : Type where
maj : Quality
min : Quality
dom7 : Quality
maj7 : Quality
showQuality : Quality → String
showQuality maj = "maj"
showQuality min = "min"
showQuality dom7 = "⁷"
showQuality maj7 = "maj⁷"
RootQuality : Type
RootQuality = Root × Quality
showRootQuality : RootQuality → String
showRootQuality (r , q) = showRoot r ++s showQuality q
Notes : Type
Notes = BitVec s12
ChordList : Type
ChordList = AList Notes RootQuality
-- The list should not include the root.
makeChord : Root → List ℕ → Notes
makeChord (root n) [] = BitVec.insert n empty
makeChord (root n) (x ∷ xs) = BitVec.insert (n +N x) (makeChord (root n) xs)
-- The list should not include the root.
qualityNotes : Quality → List ℕ
qualityNotes maj = 4 ∷ 7 ∷ []
qualityNotes min = 3 ∷ 7 ∷ []
qualityNotes dom7 = 4 ∷ 7 ∷ 10 ∷ []
qualityNotes maj7 = 4 ∷ 7 ∷ 11 ∷ []
makeChordQuality : RootQuality → Notes
makeChordQuality (r , q) = makeChord r (qualityNotes q)
---------
--addMajor
aa = show (makeChordQuality (root fz , maj))
{-
allPairs : {A : Type} → List A → List (A × A)
allPairs [] = []
allPairs (x ∷ xs) = map (x ,_) xs ++ allPairs xs
aa = allPairs (c 5 ∷ e 5 ∷ g 5 ∷ [])
bb = zip aa (map (toℕ ∘ unIntervalClass ∘ pitchPairToIntervalClass) aa)
-}
| 31.846154
| 87
| 0.545549
|
34421584bdf2acf969b36cd223f1f92b522b6d7b
| 3,757
|
agda
|
Agda
|
legacy/Misc/NumeralSystem.agda
|
banacorn/numeral
|
aae093cc9bf21f11064e7f7b12049448cd6449f1
|
[
"MIT"
] | 1
|
2015-04-23T15:58:28.000Z
|
2015-04-23T15:58:28.000Z
|
legacy/Misc/NumeralSystem.agda
|
banacorn/numeral
|
aae093cc9bf21f11064e7f7b12049448cd6449f1
|
[
"MIT"
] | null | null | null |
legacy/Misc/NumeralSystem.agda
|
banacorn/numeral
|
aae093cc9bf21f11064e7f7b12049448cd6449f1
|
[
"MIT"
] | 1
|
2015-05-30T05:50:50.000Z
|
2015-05-30T05:50:50.000Z
|
module Misc.NumeralSystem where -- One Numeral System to rule them all!?
open import Data.Maybe using (Maybe; nothing; just)
open import Data.Nat
open import Data.Product
open import Data.Unit using (⊤; tt)
open import Data.Empty using (⊥; ⊥-elim)
open import Relation.Nullary using (¬_ ; yes; no)
open import Relation.Binary
open import Level
renaming (zero to lzero; suc to lsuc)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl; setoid; cong)
open import Data.Nat.Properties using (≤-step)
open DecTotalOrder Data.Nat.decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans)
infixr 5 _∷[_,_]_
--------------------------------------------------------------------------------
-- PN - Positional Notation
-- http://en.wikipedia.org/wiki/Positional_notation
--
-- base: b
-- digits: consecutive ℕ from m to n
-- ●────○
data PN (b m n : ℕ) : Set where
[_] : m < n → PN b m n
_∷[_,_]_ : (x : ℕ) → (m ≤ x) → (x < n) → PN b m n → PN b m n
--------------------------------------------------------------------------------
toℕ : ∀ {b m n} → PN b m n → ℕ
toℕ [ _ ] = 0
toℕ {b} (x ∷[ x≥m , x<n ] xs) = x + b * toℕ xs
private
≤→< : ∀ {m n} → m ≤ n → ¬ (m ≡ n) → m < n
≤→< {n = zero} z≤n 0≠0 = ⊥-elim (0≠0 refl)
≤→< {n = suc n} z≤n neq = s≤s z≤n
≤→< (s≤s m≤n) 1+m≠1+n = s≤s (≤→< m≤n (λ m≡n → 1+m≠1+n (cong suc m≡n)))
--------------------------------------------------------------------------------
-- increment
-- the image of 'incr' is "continuous" if when
-- b = 1 ⇒ m ≥ 1, n ≥ 2m
-- b > 1 ⇒ m ≥ 0, n ≥ m + b, n ≥ 1 + mb
incr : ∀ {b m n} → m ≤ 1 → 2 ≤ n → PN b m n → PN b m n
incr m≤1 2≤n [ m<n ] = 1 ∷[ m≤1 , 2≤n ] [ m<n ]
incr {b} {m} {n} m≤1 2≤n (x ∷[ m≤x , x<n ] xs) with suc x ≟ n
incr {b} {m} m≤1 2≤n (x ∷[ m≤x , x<n ] xs) | no 1+x≠n = suc x ∷[ ≤-step m≤x , ≤→< x<n 1+x≠n ] xs
incr {b} {m} m≤1 2≤n (x ∷[ m≤x , x<n ] xs) | yes refl = m ∷[ ≤-refl , s≤s m≤x ] incr m≤1 2≤n xs
base=1-incr : ∀ {m n} → 1 ≤ m → m * 2 ≤ n → PN 1 m n → PN 1 m n
base=1-incr {m} {n} 1≤m 2m≤n [ m<n ] = m ∷[ ≤-refl , m<n ] [ m<n ]
base=1-incr {m} {n} 1≤m 2m≤n (x ∷[ m≤x , x<n ] xs) with suc x ≟ n
base=1-incr {m} {n} 1≤m 2m≤n (x ∷[ m≤x , x<n ] xs) | no 1+x≠n = suc x ∷[ ≤-step m≤x , ≤→< x<n 1+x≠n ] xs
base=1-incr {m} 1≤m 2m≤n (x ∷[ m≤x , x<n ] xs) | yes refl = m ∷[ ≤-refl , s≤s m≤x ] base=1-incr 1≤m 2m≤n xs
base>1-incr : ∀ {b m n} → 1 < b → 0 ≤ m → m + b ≤ n → m * b + 1 ≤ n → PN b m n → PN b m n
base>1-incr {b} {m} {n} 1<b 0≤m m+b≤n mb+1≤n [ m<n ] = m ∷[ ≤-refl , m<n ] [ m<n ]
base>1-incr {b} {m} {n} 1<b 0≤m m+b≤n mb+1≤n (x ∷[ m≤x , x<n ] xs) with suc x ≟ n
base>1-incr {b} {m} {n} 1<b 0≤m m+b≤n mb+1≤n (x ∷[ m≤x , x<n ] xs) | no 1+x≠n = suc x ∷[ ≤-step m≤x , ≤→< x<n 1+x≠n ] xs
base>1-incr {b} {m} 1<b 0≤m m+b≤n mb+1≤n (x ∷[ m≤x , x<n ] xs) | yes refl = m ∷[ ≤-refl , s≤s m≤x ] base>1-incr 1<b 0≤m m+b≤n mb+1≤n xs
--
-- A ── incr ⟶ A'
-- | |
-- toℕ toℕ
-- ↓ ↓
-- n ── suc ⟶ suc n
--
-- first attempt :p
-- unary-toℕ-hom : (a : PN 1 1 2) → suc (toℕ a) ≡ toℕ (base=1-incr (s≤s z≤n) (s≤s (s≤s z≤n)) a)
-- unary-toℕ-hom [ m<n ] = refl
-- unary-toℕ-hom (zero ∷[ () , x<n ] xs)
-- unary-toℕ-hom (suc zero ∷[ m≤x , x<n ] xs) = cong suc {! !}
-- unary-toℕ-hom (suc (suc x) ∷[ m≤x , s≤s (s≤s ()) ] xs)
--------------------------------------------------------------------------------
-- Instances
private
-- Unary
Unary : Set
Unary = PN 1 1 2
u₀ : Unary
u₀ = 1 ∷[ s≤s z≤n , s≤s (s≤s z≤n) ] 1 ∷[ s≤s z≤n , s≤s (s≤s z≤n) ] [ s≤s (s≤s z≤n) ]
-- Binary
Bin : Set
Bin = PN 2 0 2
b₀ : Bin
b₀ = 1 ∷[ z≤n , s≤s (s≤s z≤n) ] 0 ∷[ z≤n , s≤s z≤n ] [ s≤s z≤n ]
-- Zeroless Binary
Bin+ : Set
Bin+ = PN 2 1 3
| 34.154545
| 135
| 0.445036
|
2f6c0f855e4a5b7662847f3f09f29a18166f6ac4
| 885
|
agda
|
Agda
|
test/Succeed/Issue3332.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3332.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3332.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Jesper, Andreas, 2018-10-29, issue #3332
--
-- WAS: With-inlining failed in termination checker
-- due to a DontCare protecting the clause bodies
-- (introduced by Prop).
{-# OPTIONS --prop #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.List
postulate
A : Set
_++_ : List A → List A → List A
[] ++ l = l
(a ∷ l) ++ l' = a ∷ (l ++ l')
module PropEquality where
data _≐_ {A : Set} (a : A) : A → Prop where
refl : a ≐ a
test : (l : List A) → (l ++ []) ≐ l
test [] = refl
test (x ∷ xs) with xs ++ [] | test xs
test (x ∷ xs) | .xs | refl = refl
module SquashedEquality where
data Squash (A : Set) : Prop where
sq : A → Squash A
test : (l : List A) → Squash (l ++ [] ≡ l)
test [] = sq refl
test (x ∷ l) with test l
test (x ∷ l) | sq eq with l ++ [] | eq
test (x ∷ l) | .(test l) | .l | refl = sq refl
-- Both should succeed.
| 21.585366
| 51
| 0.559322
|
4bcdac0ec551a135034d9701b6dd9650d1ca902a
| 3,449
|
agda
|
Agda
|
agda-stdlib/src/Algebra/Definitions.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Algebra/Definitions.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Algebra/Definitions.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of functions, such as associativity and commutativity
------------------------------------------------------------------------
-- The contents of this module should be accessed via `Algebra`, unless
-- you want to parameterise it via the equality relation.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Algebra.Definitions
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality
where
open import Algebra.Core
open import Data.Product
open import Data.Sum.Base
------------------------------------------------------------------------
-- Properties of operations
Congruent₁ : Op₁ A → Set _
Congruent₁ f = f Preserves _≈_ ⟶ _≈_
Congruent₂ : Op₂ A → Set _
Congruent₂ ∙ = ∙ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
LeftCongruent : Op₂ A → Set _
LeftCongruent _∙_ = ∀ {x} → (x ∙_) Preserves _≈_ ⟶ _≈_
RightCongruent : Op₂ A → Set _
RightCongruent _∙_ = ∀ {x} → (_∙ x) Preserves _≈_ ⟶ _≈_
Associative : Op₂ A → Set _
Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z))
Commutative : Op₂ A → Set _
Commutative _∙_ = ∀ x y → (x ∙ y) ≈ (y ∙ x)
LeftIdentity : A → Op₂ A → Set _
LeftIdentity e _∙_ = ∀ x → (e ∙ x) ≈ x
RightIdentity : A → Op₂ A → Set _
RightIdentity e _∙_ = ∀ x → (x ∙ e) ≈ x
Identity : A → Op₂ A → Set _
Identity e ∙ = (LeftIdentity e ∙) × (RightIdentity e ∙)
LeftZero : A → Op₂ A → Set _
LeftZero z _∙_ = ∀ x → (z ∙ x) ≈ z
RightZero : A → Op₂ A → Set _
RightZero z _∙_ = ∀ x → (x ∙ z) ≈ z
Zero : A → Op₂ A → Set _
Zero z ∙ = (LeftZero z ∙) × (RightZero z ∙)
LeftInverse : A → Op₁ A → Op₂ A → Set _
LeftInverse e _⁻¹ _∙_ = ∀ x → ((x ⁻¹) ∙ x) ≈ e
RightInverse : A → Op₁ A → Op₂ A → Set _
RightInverse e _⁻¹ _∙_ = ∀ x → (x ∙ (x ⁻¹)) ≈ e
Inverse : A → Op₁ A → Op₂ A → Set _
Inverse e ⁻¹ ∙ = (LeftInverse e ⁻¹) ∙ × (RightInverse e ⁻¹ ∙)
LeftConical : A → Op₂ A → Set _
LeftConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → x ≈ e
RightConical : A → Op₂ A → Set _
RightConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → y ≈ e
Conical : A → Op₂ A → Set _
Conical e ∙ = (LeftConical e ∙) × (RightConical e ∙)
_DistributesOverˡ_ : Op₂ A → Op₂ A → Set _
_*_ DistributesOverˡ _+_ =
∀ x y z → (x * (y + z)) ≈ ((x * y) + (x * z))
_DistributesOverʳ_ : Op₂ A → Op₂ A → Set _
_*_ DistributesOverʳ _+_ =
∀ x y z → ((y + z) * x) ≈ ((y * x) + (z * x))
_DistributesOver_ : Op₂ A → Op₂ A → Set _
* DistributesOver + = (* DistributesOverˡ +) × (* DistributesOverʳ +)
_IdempotentOn_ : Op₂ A → A → Set _
_∙_ IdempotentOn x = (x ∙ x) ≈ x
Idempotent : Op₂ A → Set _
Idempotent ∙ = ∀ x → ∙ IdempotentOn x
IdempotentFun : Op₁ A → Set _
IdempotentFun f = ∀ x → f (f x) ≈ f x
Selective : Op₂ A → Set _
Selective _∙_ = ∀ x y → (x ∙ y) ≈ x ⊎ (x ∙ y) ≈ y
_Absorbs_ : Op₂ A → Op₂ A → Set _
_∙_ Absorbs _∘_ = ∀ x y → (x ∙ (x ∘ y)) ≈ x
Absorptive : Op₂ A → Op₂ A → Set _
Absorptive ∙ ∘ = (∙ Absorbs ∘) × (∘ Absorbs ∙)
Involutive : Op₁ A → Set _
Involutive f = ∀ x → f (f x) ≈ x
LeftCancellative : Op₂ A → Set _
LeftCancellative _•_ = ∀ x {y z} → (x • y) ≈ (x • z) → y ≈ z
RightCancellative : Op₂ A → Set _
RightCancellative _•_ = ∀ {x} y z → (y • x) ≈ (z • x) → y ≈ z
Cancellative : Op₂ A → Set _
Cancellative _•_ = (LeftCancellative _•_) × (RightCancellative _•_)
Interchangable : Op₂ A → Op₂ A → Set _
Interchangable _∘_ _∙_ = ∀ w x y z → ((w ∙ x) ∘ (y ∙ z)) ≈ ((w ∘ y) ∙ (x ∘ z))
| 28.04065
| 78
| 0.546825
|
1e4eec31ec7a6fe62b67ceea11a122db3bf3dba3
| 2,742
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Table/Base.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Table/Base.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Table/Base.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Tables, basic types and operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Table.Base where
open import Data.Nat
open import Data.Fin
open import Data.Product using (_×_ ; _,_)
open import Data.List as List using (List)
open import Data.Vec as Vec using (Vec)
open import Function using (_∘_; flip)
------------------------------------------------------------------------
-- Type
record Table {a} (A : Set a) n : Set a where
constructor tabulate
field lookup : Fin n → A
open Table public
------------------------------------------------------------------------
-- Basic operations
module _ {a} {A : Set a} where
head : ∀ {n} → Table A (suc n) → A
head t = lookup t zero
tail : ∀ {n} → Table A (suc n) → Table A n
tail t = tabulate (lookup t ∘ suc)
uncons : ∀ {n} → Table A (suc n) → A × Table A n
uncons t = head t , tail t
remove : ∀ {n} → Fin (suc n) → Table A (suc n) → Table A n
remove i t = tabulate (lookup t ∘ punchIn i)
------------------------------------------------------------------------
-- Operations for transforming tables
module _ {a} {A : Set a} where
rearrange : ∀ {m n} → (Fin m → Fin n) → Table A n → Table A m
rearrange f t = tabulate (lookup t ∘ f)
module _ {a b} {A : Set a} {B : Set b} where
map : ∀ {n} → (A → B) → Table A n → Table B n
map f t = tabulate (f ∘ lookup t)
_⊛_ : ∀ {n} → Table (A → B) n → Table A n → Table B n
fs ⊛ xs = tabulate λ i → lookup fs i (lookup xs i)
------------------------------------------------------------------------
-- Operations for reducing tables
module _ {a b} {A : Set a} {B : Set b} where
foldr : ∀ {n} → (A → B → B) → B → Table A n → B
foldr {n = zero} f z t = z
foldr {n = suc n} f z t = f (head t) (foldr f z (tail t))
foldl : ∀ {n} → (B → A → B) → B → Table A n → B
foldl {n = zero} f z t = z
foldl {n = suc n} f z t = foldl f (f z (head t)) (tail t)
------------------------------------------------------------------------
-- Operations for building tables
module _ {a} {A : Set a} where
replicate : ∀ {n} → A → Table A n
replicate x = tabulate (λ _ → x)
------------------------------------------------------------------------
-- Operations for converting tables
module _ {a} {A : Set a} where
toList : ∀ {n} → Table A n → List A
toList = List.tabulate ∘ lookup
fromList : ∀ (xs : List A) → Table A (List.length xs)
fromList = tabulate ∘ List.lookup
fromVec : ∀ {n} → Vec A n → Table A n
fromVec = tabulate ∘ Vec.lookup
toVec : ∀ {n} → Table A n → Vec A n
toVec = Vec.tabulate ∘ lookup
| 28.5625
| 72
| 0.463166
|
8b9e3c4113c34bed3704226a2b547beef04490d0
| 5,094
|
agda
|
Agda
|
Cubical/Data/Sum/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Data/Sum/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Data/Sum/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Data.Sum.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Functions.Embedding
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Empty
open import Cubical.Data.Nat
open import Cubical.Data.Sum.Base
open Iso
private
variable
ℓa ℓb ℓc ℓd : Level
A : Type ℓa
B : Type ℓb
C : Type ℓc
D : Type ℓd
-- Path space of sum type
module ⊎Path {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where
Cover : A ⊎ B → A ⊎ B → Type (ℓ-max ℓ ℓ')
Cover (inl a) (inl a') = Lift {j = ℓ-max ℓ ℓ'} (a ≡ a')
Cover (inl _) (inr _) = Lift ⊥
Cover (inr _) (inl _) = Lift ⊥
Cover (inr b) (inr b') = Lift {j = ℓ-max ℓ ℓ'} (b ≡ b')
reflCode : (c : A ⊎ B) → Cover c c
reflCode (inl a) = lift refl
reflCode (inr b) = lift refl
encode : ∀ c c' → c ≡ c' → Cover c c'
encode c _ = J (λ c' _ → Cover c c') (reflCode c)
encodeRefl : ∀ c → encode c c refl ≡ reflCode c
encodeRefl c = JRefl (λ c' _ → Cover c c') (reflCode c)
decode : ∀ c c' → Cover c c' → c ≡ c'
decode (inl a) (inl a') (lift p) = cong inl p
decode (inl a) (inr b') ()
decode (inr b) (inl a') ()
decode (inr b) (inr b') (lift q) = cong inr q
decodeRefl : ∀ c → decode c c (reflCode c) ≡ refl
decodeRefl (inl a) = refl
decodeRefl (inr b) = refl
decodeEncode : ∀ c c' → (p : c ≡ c') → decode c c' (encode c c' p) ≡ p
decodeEncode c _ =
J (λ c' p → decode c c' (encode c c' p) ≡ p)
(cong (decode c c) (encodeRefl c) ∙ decodeRefl c)
encodeDecode : ∀ c c' → (d : Cover c c') → encode c c' (decode c c' d) ≡ d
encodeDecode (inl a) (inl _) (lift d) =
J (λ a' p → encode (inl a) (inl a') (cong inl p) ≡ lift p) (encodeRefl (inl a)) d
encodeDecode (inr a) (inr _) (lift d) =
J (λ a' p → encode (inr a) (inr a') (cong inr p) ≡ lift p) (encodeRefl (inr a)) d
Cover≃Path : ∀ c c' → Cover c c' ≃ (c ≡ c')
Cover≃Path c c' =
isoToEquiv (iso (decode c c') (encode c c') (decodeEncode c c') (encodeDecode c c'))
isOfHLevelCover : (n : HLevel)
→ isOfHLevel (suc (suc n)) A
→ isOfHLevel (suc (suc n)) B
→ ∀ c c' → isOfHLevel (suc n) (Cover c c')
isOfHLevelCover n p q (inl a) (inl a') = isOfHLevelLift (suc n) (p a a')
isOfHLevelCover n p q (inl a) (inr b') =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p q (inr b) (inl a') =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p q (inr b) (inr b') = isOfHLevelLift (suc n) (q b b')
isEmbedding-inl : isEmbedding (inl {A = A} {B = B})
isEmbedding-inl w z = snd (compEquiv LiftEquiv (⊎Path.Cover≃Path (inl w) (inl z)))
isEmbedding-inr : isEmbedding (inr {A = A} {B = B})
isEmbedding-inr w z = snd (compEquiv LiftEquiv (⊎Path.Cover≃Path (inr w) (inr z)))
isOfHLevel⊎ : (n : HLevel)
→ isOfHLevel (suc (suc n)) A
→ isOfHLevel (suc (suc n)) B
→ isOfHLevel (suc (suc n)) (A ⊎ B)
isOfHLevel⊎ n lA lB c c' =
isOfHLevelRetract (suc n)
(⊎Path.encode c c')
(⊎Path.decode c c')
(⊎Path.decodeEncode c c')
(⊎Path.isOfHLevelCover n lA lB c c')
isSet⊎ : isSet A → isSet B → isSet (A ⊎ B)
isSet⊎ = isOfHLevel⊎ 0
isGroupoid⊎ : isGroupoid A → isGroupoid B → isGroupoid (A ⊎ B)
isGroupoid⊎ = isOfHLevel⊎ 1
is2Groupoid⊎ : is2Groupoid A → is2Groupoid B → is2Groupoid (A ⊎ B)
is2Groupoid⊎ = isOfHLevel⊎ 2
⊎Iso : Iso A C → Iso B D → Iso (A ⊎ B) (C ⊎ D)
fun (⊎Iso iac ibd) (inl x) = inl (iac .fun x)
fun (⊎Iso iac ibd) (inr x) = inr (ibd .fun x)
inv (⊎Iso iac ibd) (inl x) = inl (iac .inv x)
inv (⊎Iso iac ibd) (inr x) = inr (ibd .inv x)
rightInv (⊎Iso iac ibd) (inl x) = cong inl (iac .rightInv x)
rightInv (⊎Iso iac ibd) (inr x) = cong inr (ibd .rightInv x)
leftInv (⊎Iso iac ibd) (inl x) = cong inl (iac .leftInv x)
leftInv (⊎Iso iac ibd) (inr x) = cong inr (ibd .leftInv x)
⊎-swap-Iso : Iso (A ⊎ B) (B ⊎ A)
fun ⊎-swap-Iso (inl x) = inr x
fun ⊎-swap-Iso (inr x) = inl x
inv ⊎-swap-Iso (inl x) = inr x
inv ⊎-swap-Iso (inr x) = inl x
rightInv ⊎-swap-Iso (inl _) = refl
rightInv ⊎-swap-Iso (inr _) = refl
leftInv ⊎-swap-Iso (inl _) = refl
leftInv ⊎-swap-Iso (inr _) = refl
⊎-swap-≃ : A ⊎ B ≃ B ⊎ A
⊎-swap-≃ = isoToEquiv ⊎-swap-Iso
⊎-assoc-Iso : Iso ((A ⊎ B) ⊎ C) (A ⊎ (B ⊎ C))
fun ⊎-assoc-Iso (inl (inl x)) = inl x
fun ⊎-assoc-Iso (inl (inr x)) = inr (inl x)
fun ⊎-assoc-Iso (inr x) = inr (inr x)
inv ⊎-assoc-Iso (inl x) = inl (inl x)
inv ⊎-assoc-Iso (inr (inl x)) = inl (inr x)
inv ⊎-assoc-Iso (inr (inr x)) = inr x
rightInv ⊎-assoc-Iso (inl _) = refl
rightInv ⊎-assoc-Iso (inr (inl _)) = refl
rightInv ⊎-assoc-Iso (inr (inr _)) = refl
leftInv ⊎-assoc-Iso (inl (inl _)) = refl
leftInv ⊎-assoc-Iso (inl (inr _)) = refl
leftInv ⊎-assoc-Iso (inr _) = refl
⊎-assoc-≃ : (A ⊎ B) ⊎ C ≃ A ⊎ (B ⊎ C)
⊎-assoc-≃ = isoToEquiv ⊎-assoc-Iso
⊎-⊥-Iso : Iso (A ⊎ ⊥) A
fun ⊎-⊥-Iso (inl x) = x
inv ⊎-⊥-Iso x = inl x
rightInv ⊎-⊥-Iso _ = refl
leftInv ⊎-⊥-Iso (inl _) = refl
⊎-⊥-≃ : A ⊎ ⊥ ≃ A
⊎-⊥-≃ = isoToEquiv ⊎-⊥-Iso
| 32.653846
| 88
| 0.59148
|
fb852e6594492522f654757ce237c74aca6f7a52
| 55,216
|
agda
|
Agda
|
Definition/LogicalRelation/Substitution/Introductions/Sigma.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/LogicalRelation/Substitution/Introductions/Sigma.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Substitution/Introductions/Sigma.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Sigma {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening using (_∷_⊆_ ; _•ₜ_)
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Weakening
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Weakening
open import Definition.LogicalRelation.Substitution.Properties
open import Definition.LogicalRelation.Substitution.MaybeEmbed
import Definition.LogicalRelation.Substitution.Irrelevance as S
open import Definition.LogicalRelation.Substitution.Introductions.Universe
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
open import Tools.Empty using (⊥; ⊥-elim)
-- Validity of ∃.
∃ᵛ : ∀ {F G Γ l∃ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
→ Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ^ [ % , ι l∃ ] / [Γ] ∙ [F]
→ Γ ⊩ᵛ⟨ l ⟩ ∃ F ▹ G ^ [ % , ι l∃ ] / [Γ]
∃ᵛ {F} {G} {Γ} {l∃} {l} [Γ] [F] [G] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [F]σ {σ′} [σ′] = [F] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([F]σ [σ])
⊢F {σ′} [σ′] = escape (proj₁ ([F]σ {σ′} [σ′]))
⊢F≡F = escapeEq [σF] (reflEq [σF])
[G]σ {σ′} [σ′] = [G] {σ = liftSubst σ′} (⊢Δ ∙ ⊢F [σ′])
(liftSubstS {F = F} [Γ] ⊢Δ [F] [σ′])
⊢G {σ′} [σ′] = escape (proj₁ ([G]σ {σ′} [σ′]))
⊢G≡G = escapeEq (proj₁ ([G]σ [σ])) (reflEq (proj₁ ([G]σ [σ])))
⊢∃F▹G = ∃ⱼ un-univ (⊢F [σ]) ▹ un-univ (⊢G [σ])
in ∃ᵣ′ (subst σ F) (subst (liftSubst σ) G) (idRed:*: (univ ⊢∃F▹G)) (⊢F [σ]) (⊢G [σ]) (≅-univ (≅ₜ-∃-cong (⊢F [σ]) (≅-un-univ ⊢F≡F) (≅-un-univ ⊢G≡G)))
(λ ρ ⊢Δ₁ → wk ρ ⊢Δ₁ [σF]) (λ {ρ} {Δ₁} {a} [ρ] ⊢Δ₁ [a] →
let [a]′ = irrelevanceTerm′
(wk-subst F) PE.refl PE.refl (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]))) [a]
in Gapp {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′)
(λ {ρ} {Δ₁} {a} {b} [ρ] ⊢Δ₁ [a] [b] [a≡b] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[a]′ = irrelevanceTerm′
(wk-subst F) PE.refl PE.refl (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[b]′ = irrelevanceTerm′
(wk-subst F) PE.refl PE.refl (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [b]
[a≡b]′ = irrelevanceEqTerm′
(wk-subst F) PE.refl PE.refl (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a≡b]
in irrelevanceEq″
(PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp b σ G)) PE.refl PE.refl
(proj₁ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′))
(Gapp {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′)
(proj₂ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′)
([ρσ] , [b]′)
(reflSubst [Γ] ⊢Δ₁ [ρσ] , [a≡b]′)))
, λ {σ′} [σ′] [σ≡σ′] →
let var0 = var (⊢Δ ∙ ⊢F [σ])
(PE.subst (λ x → 0 ∷ x ^ [ % , ι l∃ ] ∈ (Δ ∙ subst σ F ^ [ % , ι l∃ ]))
(wk-subst F) here)
[wk1σ] = wk1SubstS [Γ] ⊢Δ (⊢F [σ]) [σ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ (⊢F [σ]) [σ′]
[wk1σ≡wk1σ′] = wk1SubstSEq [Γ] ⊢Δ (⊢F [σ]) [σ] [σ≡σ′]
[F][wk1σ] = proj₁ ([F] (⊢Δ ∙ ⊢F [σ]) [wk1σ])
[F][wk1σ′] = proj₁ ([F] (⊢Δ ∙ ⊢F [σ]) [wk1σ′])
var0′ = conv var0
(≅-eq (escapeEq [F][wk1σ]
(proj₂ ([F] (⊢Δ ∙ ⊢F [σ]) [wk1σ])
[wk1σ′] [wk1σ≡wk1σ′])))
in ∃₌ _ _ (id (univ (∃ⱼ un-univ (⊢F [σ′]) ▹ un-univ (⊢G [σ′]))))
(≅-univ (≅ₜ-∃-cong (⊢F [σ])
(≅-un-univ (escapeEq (proj₁ ([F] ⊢Δ [σ]))
(proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′])))
(≅-un-univ (escapeEq (proj₁ ([G]σ [σ])) (proj₂ ([G]σ [σ])
([wk1σ′] , neuTerm [F][wk1σ′] (var 0) var0′ (~-var var0′))
([wk1σ≡wk1σ′] , neuEqTerm [F][wk1σ]
(var 0) (var 0) var0 var0 (~-var var0)))))))
(λ ρ ⊢Δ₁ → wkEq ρ ⊢Δ₁ [σF] (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]))
(λ {ρ} {Δ₁} {a} [ρ] ⊢Δ₁ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[ρσ′] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ′]
[a]′ = irrelevanceTerm′ (wk-subst F) PE.refl PE.refl (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[a]″ = convTerm₁ (proj₁ ([F] ⊢Δ₁ [ρσ]))
(proj₁ ([F] ⊢Δ₁ [ρσ′]))
(proj₂ ([F] ⊢Δ₁ [ρσ]) [ρσ′]
(wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] [σ≡σ′]))
[a]′
[ρσa≡ρσ′a] = consSubstSEq {t = a} {A = F} [Γ] ⊢Δ₁
(wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])
(wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] [σ≡σ′])
[F] [a]′
in irrelevanceEq″ (PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ′ G)) PE.refl PE.refl
(proj₁ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′))
(Gapp {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′)
(proj₂ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F] [G] ⊢Δ [σ] a [ρ] ⊢Δ₁ [a]′)
(wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ′] , [a]″)
[ρσa≡ρσ′a]))
-- Validity of ∃-congurence.
∃-congᵛ : ∀ {F G H E Γ l∃ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
([G] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ^ [ % , ι l∃ ] / [Γ] ∙ [F])
([H] : Γ ⊩ᵛ⟨ l ⟩ H ^ [ % , ι l∃ ] / [Γ])
([E] : Γ ∙ H ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ E ^ [ % , ι l∃ ] / [Γ] ∙ [H])
([F≡H] : Γ ⊩ᵛ⟨ l ⟩ F ≡ H ^ [ % , ι l∃ ] / [Γ] / [F])
([G≡E] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ≡ E ^ [ % , ι l∃ ] / [Γ] ∙ [F] / [G])
→ Γ ⊩ᵛ⟨ l ⟩ ∃ F ▹ G ≡ ∃ H ▹ E ^ [ % , ι l∃ ] / [Γ] / ∃ᵛ {F} {G} [Γ] [F] [G]
∃-congᵛ {F} {G} {H} {E} [Γ] [F] [G] [H] [E] [F≡H] [G≡E] {σ = σ} ⊢Δ [σ] =
let [∃FG] = ∃ᵛ {F} {G} [Γ] [F] [G]
[σ∃FG] = proj₁ ([∃FG] ⊢Δ [σ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
[σF] = proj₁ ([F] ⊢Δ [σ])
⊢σF = escape [σF]
[σG] = proj₁ ([G] (⊢Δ ∙ ⊢σF) (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))
⊢σH = escape (proj₁ ([H] ⊢Δ [σ]))
⊢σE = escape (proj₁ ([E] (⊢Δ ∙ ⊢σH) (liftSubstS {F = H} [Γ] ⊢Δ [H] [σ])))
⊢σF≡σH = escapeEq [σF] ([F≡H] ⊢Δ [σ])
⊢σG≡σE = escapeEq [σG] ([G≡E] (⊢Δ ∙ ⊢σF) (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))
in ∃₌ (subst σ H)
(subst (liftSubst σ) E)
(id (univ (∃ⱼ (un-univ ⊢σH) ▹ (un-univ ⊢σE))))
(≅-univ (≅ₜ-∃-cong ⊢σF (≅-un-univ ⊢σF≡σH) (≅-un-univ ⊢σG≡σE)))
(λ ρ ⊢Δ₁ → let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ ρ [σ]
in irrelevanceEq″ (PE.sym (wk-subst F))
(PE.sym (wk-subst H)) PE.refl PE.refl
(proj₁ ([F] ⊢Δ₁ [ρσ]))
([F]′ ρ ⊢Δ₁)
([F≡H] ⊢Δ₁ [ρσ]))
(λ {ρ} {Δ} {a} [ρ] ⊢Δ₁ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[a]′ = irrelevanceTerm′ (wk-subst F) PE.refl PE.refl
([F]′ [ρ] ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[aρσ] = consSubstS {t = a} {A = F} [Γ] ⊢Δ₁ [ρσ] [F] [a]′
in irrelevanceEq″ (PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ E)) PE.refl PE.refl
(proj₁ ([G] ⊢Δ₁ [aρσ]))
([G]′ [ρ] ⊢Δ₁ [a])
([G≡E] ⊢Δ₁ [aρσ])
)
-- Validity of ∃ as a term.
∃ᵗᵛ₁ : ∀ {F G l∃ Γ} ([Γ] : ⊩ᵛ Γ)→
let l = ∞
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[U∃] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
in
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
([UG] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F])
→ Γ ⊩ᵛ⟨ l ⟩ F ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [UF]
→ Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F] / (λ {Δ} {σ} → [UG] {Δ} {σ})
→ ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩⟨ l ⟩ subst σ (∃ F ▹ G) ∷ subst σ (Univ % l∃) ^ [ ! , next l∃ ] / proj₁ ([U∃] ⊢Δ [σ])
∃ᵗᵛ₁ {F} {G} {l∃ = ¹} {Γ} [Γ] [F] [UG] [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let
l = ∞
l∃ = ¹
l∃≤ = ≡is≤ PE.refl
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[U∃] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
univΔ = proj₁ ([UF] ⊢Δ [σ])
[Fₜ]σ {σ′} [σ′] = [Fₜ] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
⊢Fₜ = escapeTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ]))
⊢F≡Fₜ = escapeTermEq univΔ (reflEqTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ])))
[UG]σ = proj₁ ([UG] {σ = liftSubst σ} (⊢Δ ∙ ⊢F) [liftσ])
[Gₜ]σ = proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ])
⊢Gₜ = escapeTerm [UG]σ [Gₜ]σ
⊢G≡Gₜ = escapeTermEq [UG]σ (reflEqTerm [UG]σ [Gₜ]σ)
[F]₀ = univᵛ {F} [Γ] l∃≤ [UF] [Fₜ]
[UG]′ = S.irrelevance {A = Univ % l∃} {r = [ ! , next l∃ ]} (_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀) (λ {Δ} {σ} → [UG] {Δ} {σ})
[Gₜ]′ = S.irrelevanceTerm {l′ = ∞} {A = Univ % l∃} {t = G}
(_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀)
(λ {Δ} {σ} → [UG] {Δ} {σ})
(λ {Δ} {σ} → [UG]′ {Δ} {σ})
[Gₜ]
[G]₀ = univᵛ {G} (_∙_ {A = F} [Γ] [F]₀) l∃≤
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) (λ {Δ} {σ} → [Gₜ]′ {Δ} {σ})
[Guniv] = univᵛ {A = G} (_∙_ {A = F} [Γ] [F]₀) l∃≤ (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [Gₜ]′
in Uₜ (∃ subst σ F ▹ subst (liftSubst σ) G) (idRedTerm:*: (∃ⱼ ⊢Fₜ ▹ ⊢Gₜ)) ∃ₙ (≅ₜ-∃-cong ⊢F ⊢F≡Fₜ ⊢G≡Gₜ)
(λ {ρ} {Δ₁} [ρ] ⊢Δ₁ → let
⊢Fₜ' = Definition.Typed.Weakening.wkTerm [ρ] ⊢Δ₁ ⊢Fₜ
⊢Gₜ' = Definition.Typed.Weakening.wkTerm
(Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') ⊢Gₜ
[wkFₜ] = wkTerm [ρ] ⊢Δ₁ univΔ (proj₁ ([Fₜ] ⊢Δ [σ]))
[wkGₜ] = wkTerm (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] {σ = liftSubst σ} (⊢Δ ∙ ⊢F) [liftσ])) (proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]))
[⊢weakF≡Fₜ] = escapeTermEq (wk [ρ] ⊢Δ₁ univΔ)
(reflEqTerm (wk [ρ] ⊢Δ₁ univΔ) [wkFₜ])
[⊢weakG≡Gₜ] = escapeTermEq (wk (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ])))
(reflEqTerm (wk (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ])))
(wkTerm (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ])) (proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]))))
[wkFₜ]Type : ∀ {ρ₁ Δ₂} [ρ₁] ⊢Δ₂ → Δ₂ ⊩⟨ ι ¹ ⟩ U.wk ρ₁ (U.wk ρ (subst σ F)) ^ [ % , ι l∃ ]
[wkFₜ]Type = λ {ρ₁} {Δ₂} [ρ₁] ⊢Δ₂ → let [wkFₜ]Type = univEq (wk [ρ₁] ⊢Δ₂ (wk [ρ] ⊢Δ₁ univΔ))
(wkTerm [ρ₁] ⊢Δ₂ (wk [ρ] ⊢Δ₁ univΔ) [wkFₜ])
in maybeEmb′ l∃≤ [wkFₜ]Type
in ∃ᵣ′ (U.wk ρ (subst σ F)) (U.wk (lift ρ) (subst (liftSubst σ) G))
(idRed:*: (univ (∃ⱼ ⊢Fₜ' ▹ ⊢Gₜ')))
(univ ⊢Fₜ') (univ ⊢Gₜ') (≅-univ (≅ₜ-∃-cong (univ ⊢Fₜ') [⊢weakF≡Fₜ] [⊢weakG≡Gₜ]))
[wkFₜ]Type
(λ {ρ₁} {Δ₂} {a} [ρ₁] ⊢Δ₂ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₂ ([ρ₁] •ₜ [ρ]) [σ]
[a]′ = irrelevanceTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [a]
[Gapp] = Gapp {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′
in PE.subst (λ X → _ ⊩⟨ ι ¹ ⟩ X ^ _) (wk-comp-subst _ _ (subst (liftSubst σ) G)) [Gapp])
(λ {ρ₁} {Δ₂} {a} {b} [ρ₁] ⊢Δ₂ [a] [b] [a≡b] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₂ ([ρ₁] •ₜ [ρ]) [σ]
[a]′ = irrelevanceTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [a]
[b]′ = irrelevanceTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [b]
[a≡b]′ = irrelevanceEqTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [a≡b]
[Gapp] = Gapp {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′
in irrelevanceEq″ (PE.trans (PE.sym (singleSubstWkComp a σ G)) (wk-comp-subst {a} ρ₁ ρ (subst (liftSubst σ) G)))
(PE.trans (PE.sym (singleSubstWkComp b σ G)) (wk-comp-subst {b} ρ₁ ρ (subst (liftSubst σ) G)))
PE.refl PE.refl
(proj₁ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′ ))
(PE.subst (λ X → _ ⊩⟨ ι ¹ ⟩ X ^ _) (wk-comp-subst _ _ (subst (liftSubst σ) G)) [Gapp])
(proj₂ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′ )
([ρσ] , [b]′) (reflSubst [Γ] ⊢Δ₂ [ρσ] , [a≡b]′))))
∃ᵗᵛ₁ {F} {G} {l∃ = ⁰} {Γ} [Γ] [F] [UG] [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let
l = ∞
l∃ = ⁰
l∃≤ = ≡is≤ PE.refl
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[U∃] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
univΔ = proj₁ ([UF] ⊢Δ [σ])
[Fₜ]σ {σ′} [σ′] = [Fₜ] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
⊢Fₜ = escapeTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ]))
⊢F≡Fₜ = escapeTermEq univΔ (reflEqTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ])))
[UG]σ = proj₁ ([UG] {σ = liftSubst σ} (⊢Δ ∙ ⊢F) [liftσ])
[Gₜ]σ = proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ])
⊢Gₜ = escapeTerm [UG]σ [Gₜ]σ
⊢G≡Gₜ = escapeTermEq [UG]σ (reflEqTerm [UG]σ [Gₜ]σ)
[F]₀ = univᵛ {F} [Γ] l∃≤ [UF] [Fₜ]
[UG]′ = S.irrelevance {A = Univ % l∃} {r = [ ! , next l∃ ]} (_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀) (λ {Δ} {σ} → [UG] {Δ} {σ})
[Gₜ]′ = S.irrelevanceTerm {l′ = ∞} {A = Univ % l∃} {t = G}
(_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀)
(λ {Δ} {σ} → [UG] {Δ} {σ})
(λ {Δ} {σ} → [UG]′ {Δ} {σ})
[Gₜ]
[G]₀ = univᵛ {G} (_∙_ {A = F} [Γ] [F]₀) l∃≤
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) (λ {Δ} {σ} → [Gₜ]′ {Δ} {σ})
[Guniv] = univᵛ {A = G} (_∙_ {A = F} [Γ] [F]₀) l∃≤ (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [Gₜ]′
in Uₜ (∃ subst σ F ▹ subst (liftSubst σ) G) (idRedTerm:*: (∃ⱼ ⊢Fₜ ▹ ⊢Gₜ)) ∃ₙ (≅ₜ-∃-cong ⊢F ⊢F≡Fₜ ⊢G≡Gₜ)
(λ {ρ} {Δ₁} [ρ] ⊢Δ₁ → let
⊢Fₜ' = Definition.Typed.Weakening.wkTerm [ρ] ⊢Δ₁ ⊢Fₜ
⊢Gₜ' = Definition.Typed.Weakening.wkTerm
(Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') ⊢Gₜ
[wkFₜ] = wkTerm [ρ] ⊢Δ₁ univΔ (proj₁ ([Fₜ] ⊢Δ [σ]))
[wkGₜ] = wkTerm (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] {σ = liftSubst σ} (⊢Δ ∙ ⊢F) [liftσ])) (proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]))
[⊢weakF≡Fₜ] = escapeTermEq (wk [ρ] ⊢Δ₁ univΔ)
(reflEqTerm (wk [ρ] ⊢Δ₁ univΔ) [wkFₜ])
[⊢weakG≡Gₜ] = escapeTermEq (wk (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ])))
(reflEqTerm (wk (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ])))
(wkTerm (Definition.Typed.Weakening.lift [ρ]) (⊢Δ₁ ∙ univ ⊢Fₜ') (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ])) (proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]))))
[wkFₜ]Type : ∀ {ρ₁ Δ₂} [ρ₁] ⊢Δ₂ → Δ₂ ⊩⟨ ι ⁰ ⟩ U.wk ρ₁ (U.wk ρ (subst σ F)) ^ [ % , ι l∃ ]
[wkFₜ]Type = λ {ρ₁} {Δ₂} [ρ₁] ⊢Δ₂ → let [wkFₜ]Type = univEq (wk [ρ₁] ⊢Δ₂ (wk [ρ] ⊢Δ₁ univΔ))
(wkTerm [ρ₁] ⊢Δ₂ (wk [ρ] ⊢Δ₁ univΔ) [wkFₜ])
in maybeEmb′ l∃≤ [wkFₜ]Type
in ∃ᵣ′ (U.wk ρ (subst σ F)) (U.wk (lift ρ) (subst (liftSubst σ) G))
(idRed:*: (univ (∃ⱼ ⊢Fₜ' ▹ ⊢Gₜ')))
(univ ⊢Fₜ') (univ ⊢Gₜ') (≅-univ (≅ₜ-∃-cong (univ ⊢Fₜ') [⊢weakF≡Fₜ] [⊢weakG≡Gₜ]))
[wkFₜ]Type
(λ {ρ₁} {Δ₂} {a} [ρ₁] ⊢Δ₂ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₂ ([ρ₁] •ₜ [ρ]) [σ]
[a]′ = irrelevanceTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [a]
[Gapp] = Gapp {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′
in PE.subst (λ X → _ ⊩⟨ ι ⁰ ⟩ X ^ _) (wk-comp-subst _ _ (subst (liftSubst σ) G)) [Gapp])
(λ {ρ₁} {Δ₂} {a} {b} [ρ₁] ⊢Δ₂ [a] [b] [a≡b] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₂ ([ρ₁] •ₜ [ρ]) [σ]
[a]′ = irrelevanceTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [a]
[b]′ = irrelevanceTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [b]
[a≡b]′ = irrelevanceEqTerm′ (wk-subst2 {ρ} {ρ₁} {σ} F) PE.refl PE.refl ([wkFₜ]Type [ρ₁] ⊢Δ₂)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ])) [a≡b]
[Gapp] = Gapp {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′
in irrelevanceEq″ (PE.trans (PE.sym (singleSubstWkComp a σ G)) (wk-comp-subst {a} ρ₁ ρ (subst (liftSubst σ) G)))
(PE.trans (PE.sym (singleSubstWkComp b σ G)) (wk-comp-subst {b} ρ₁ ρ (subst (liftSubst σ) G)))
PE.refl PE.refl
(proj₁ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′ ))
(PE.subst (λ X → _ ⊩⟨ ι ⁰ ⟩ X ^ _) (wk-comp-subst _ _ (subst (liftSubst σ) G)) [Gapp])
(proj₂ (GappGen {F = F} {G = G} {σ = σ} [Γ] [F]₀ [Guniv] ⊢Δ [σ] a ([ρ₁] •ₜ [ρ]) ⊢Δ₂ [a]′ )
([ρσ] , [b]′) (reflSubst [Γ] ⊢Δ₂ [ρσ] , [a≡b]′))))
∃ᵗᵛ : ∀ {F G l∃ Γ} ([Γ] : ⊩ᵛ Γ)→
let l = ∞
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[U∃] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
in
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
([UG] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F])
→ Γ ⊩ᵛ⟨ l ⟩ F ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [UF]
→ Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F] / (λ {Δ} {σ} → [UG] {Δ} {σ})
→ Γ ⊩ᵛ⟨ l ⟩ ∃ F ▹ G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [U∃]
∃ᵗᵛ {F} {G} {l∃ = ¹} {Γ} [Γ] [F] [UG] [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let l = ∞
l∃ = ¹
l∃≤ = ≡is≤ PE.refl
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
in ∃ᵗᵛ₁ {F} {G} {¹} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ]
, (λ {σ′} [σ′] [σ≡σ′] →
let ⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
univΔ = proj₁ ([UF] ⊢Δ [σ])
[Fₜ]σ {σ′} [σ′] = [Fₜ] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
⊢Fₜ = escapeTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ]))
⊢F≡Fₜ = escapeTermEq univΔ (reflEqTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ])))
[liftσ′] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ′]
[wk1σ] = wk1SubstS [Γ] ⊢Δ ⊢F [σ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ ⊢F [σ′]
var0 = conv (var (⊢Δ ∙ ⊢F)
(PE.subst (λ x → 0 ∷ x ^ [ % , ι l∃ ] ∈ (Δ ∙ subst σ F ^ [ % , ι l∃ ]))
(wk-subst F) here))
(≅-eq (escapeEq (proj₁ ([F] (⊢Δ ∙ ⊢F) [wk1σ]))
(proj₂ ([F] (⊢Δ ∙ ⊢F) [wk1σ]) [wk1σ′]
(wk1SubstSEq [Γ] ⊢Δ ⊢F [σ] [σ≡σ′]))))
[liftσ′]′ = [wk1σ′]
, neuTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [wk1σ′])) (var 0)
var0 (~-var var0)
⊢F′ = escape (proj₁ ([F] ⊢Δ [σ′]))
univΔ = proj₁ ([UF] ⊢Δ [σ])
univΔ′ = proj₁ ([UF] ⊢Δ [σ′])
[Fₜ]σ {σ′} [σ′] = [Fₜ] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
⊢Fₜ′ = escapeTerm univΔ′ (proj₁ ([Fₜ] ⊢Δ [σ′]))
⊢Gₜ′ = escapeTerm (proj₁ ([UG] {σ = liftSubst σ′} (⊢Δ ∙ ⊢F′) [liftσ′]))
(proj₁ ([Gₜ] (⊢Δ ∙ ⊢F′) [liftσ′]))
⊢F≡F′ = escapeTermEq univΔ (proj₂ ([Fₜ] ⊢Δ [σ]) [σ′] [σ≡σ′])
⊢G≡G′ = escapeTermEq (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ]))
(proj₂ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]) [liftσ′]′
(liftSubstSEq {F = F} [Γ] ⊢Δ [F] [σ] [σ≡σ′]))
[F]₀ = univᵛ {F} [Γ] l∃≤ [UF] [Fₜ]
[UG]′ = S.irrelevance {A = Univ % l∃} {r = [ ! , next l∃ ]} (_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀) (λ {Δ} {σ} → [UG] {Δ} {σ})
[Gₜ]′ = S.irrelevanceTerm {l′ = ∞} {A = Univ % l∃} {t = G}
(_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀)
(λ {Δ} {σ} → [UG] {Δ} {σ})
(λ {Δ} {σ} → [UG]′ {Δ} {σ})
[Gₜ]
[G]₀ = univᵛ {G} (_∙_ {A = F} [Γ] [F]₀) l∃≤
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) (λ {Δ} {σ} → [Gₜ]′ {Δ} {σ})
[∃FG-cong] = ∃-congᵛ {F} {G} {F} {G} [Γ] [F]₀ [G]₀ [F]₀ [G]₀
(λ ⊢Δ₁ [σ]₁ → proj₂ ([F]₀ ⊢Δ₁ [σ]₁) [σ]₁ (reflSubst [Γ] ⊢Δ₁ [σ]₁))
(λ {Δ₁} {σ₁} ⊢Δ₁ [σ]₁ → proj₂ ([G]₀ ⊢Δ₁ [σ]₁) [σ]₁ (reflSubst {σ₁} ((_∙_ {A = F} [Γ] [F]₀)) ⊢Δ₁ [σ]₁))
[∃FG]ᵗ = ∃ᵗᵛ₁ {F} {G} {l∃ = ¹} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ]
[∃FG]ᵗ′ = ∃ᵗᵛ₁ {F} {G} {l∃ = ¹} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] {Δ = Δ} {σ = σ′} ⊢Δ [σ′]
[∃FG] = ∃ᵛ {F} {G} {Γ} {l∃ = ¹} [Γ] [F]₀ [G]₀
in Uₜ₌ [∃FG]ᵗ
[∃FG]ᵗ′
(≅ₜ-∃-cong ⊢F ⊢F≡F′ ⊢G≡G′)
(λ {ρ} {Δ₁} [ρ] ⊢Δ₁ → let [∃FG-cong]′ = [∃FG-cong] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])
X = irrelevanceEq″ (PE.sym (wk-subst (∃ F ▹ G)))
(PE.sym (wk-subst (∃ F ▹ G)))
PE.refl PE.refl
(proj₁ ([∃FG] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])))
(LogRel._⊩¹U_∷_^_/_.[t] [∃FG]ᵗ [ρ] ⊢Δ₁)
[∃FG-cong]′
[σ∃FG] = proj₁ ([∃FG] ⊢Δ [σ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
[ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[σF]₀ = proj₁ ([F]₀ ⊢Δ₁ [ρσ])
⊢σF₀ = escape [σF]₀
[σG]₀ = proj₁ ([G]₀ (⊢Δ₁ ∙ ⊢σF₀) (liftSubstS {F = F} [Γ] ⊢Δ₁ [F]₀ [ρσ]))
[ρσ′] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ′]
[σF′]₀ = proj₁ ([F]₀ ⊢Δ₁ [ρσ′])
⊢σH = escape (proj₁ ([F]₀ ⊢Δ₁ [ρσ′]))
⊢σE = escape (proj₁ ([G]₀ (⊢Δ₁ ∙ ⊢σH) (liftSubstS {F = F} [Γ] ⊢Δ₁ [F]₀ [ρσ′])))
univΔ₁ = proj₁ ([UF] ⊢Δ₁ [ρσ])
[ρσ≡ρσ′] = wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] [σ≡σ′]
[σF≡σH] = univEqEq univΔ₁ [σF]₀ (proj₂ ([Fₜ] ⊢Δ₁ [ρσ]) [ρσ′] [ρσ≡ρσ′])
⊢σF≡σH = escapeEq [σF]₀ [σF≡σH]
[σF] = proj₁ ([F] ⊢Δ₁ [ρσ])
⊢σF = escape [σF]
liftσ = liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ]
[wk1σ] = wk1SubstS [Γ] ⊢Δ₁ ⊢σF [ρσ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ₁ ⊢σF [ρσ′]
var0 = conv (var (⊢Δ₁ ∙ ⊢σF)
(PE.subst (λ x → 0 ∷ x ^ [ % , ι l∃ ] ∈ (Δ₁ ∙ subst (ρ •ₛ σ) F ^ [ % , ι l∃ ]))
(wk-subst F) here))
(≅-eq (escapeEq (proj₁ ([F] (⊢Δ₁ ∙ ⊢σF) [wk1σ]))
(proj₂ ([F] (⊢Δ₁ ∙ ⊢σF) [wk1σ]) [wk1σ′]
(wk1SubstSEq [Γ] ⊢Δ₁ ⊢σF [ρσ] [ρσ≡ρσ′]))))
[liftσ′]′ : (Δ₁ ∙ subst (ρ •ₛ σ) F ^ [ % , ι l∃ ]) ⊩ˢ liftSubst (ρ •ₛ σ′) ∷
Γ ∙ F ^ [ % , ι l∃ ] / [Γ] ∙ [F] /
(⊢Δ₁ ∙ escape (proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]))))
[liftσ′]′ = [wk1σ′]
, neuTerm (proj₁ ([F] (⊢Δ₁ ∙ ⊢σF) [wk1σ′])) (var 0)
var0 (~-var var0)
liftσ′ = liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ′]
univΔ₁G = proj₁ ([UG] (⊢Δ₁ ∙ ⊢σF) liftσ)
[σG≡σE] = univEqEq univΔ₁G [σG]₀ (proj₂ ([Gₜ] {σ = liftSubst (ρ •ₛ σ)} (⊢Δ₁ ∙ ⊢σF) liftσ) [liftσ′]′
(liftSubstSEq {F = F} [Γ] ⊢Δ₁ [F] [ρσ] [ρσ≡ρσ′]))
⊢σG≡σE = escapeEq [σG]₀ [σG≡σE]
X = ∃₌ (subst (ρ •ₛ σ′) F)
(subst (liftSubst (ρ •ₛ σ′)) G)
(id (univ (∃ⱼ (un-univ ⊢σH) ▹ (un-univ ⊢σE))))
((≅-univ (≅ₜ-∃-cong ⊢σF (≅-un-univ ⊢σF≡σH) (≅-un-univ ⊢σG≡σE))))
(λ {ρ₂} {Δ₂} [ρ₂] ⊢Δ₂ →
let
[ρσ₂] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ]
[ρσ₂F]₀ = proj₁ ([F]₀ ⊢Δ₂ [ρσ₂])
[σ∃FG] = proj₁ ([∃FG] ⊢Δ₁ [ρσ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
⊢ρσ₂F = escape [ρσ₂F]₀
[ρσ₂′] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ′]
⊢σH = escape (proj₁ ([F]₀ ⊢Δ₂ [ρσ₂′]))
univΔ₂ = proj₁ ([UF] ⊢Δ₂ [ρσ₂])
[σF≡σH] = univEqEq univΔ₂ [ρσ₂F]₀ (proj₂ ([Fₜ] ⊢Δ₂ [ρσ₂]) [ρσ₂′]
(wkSubstSEq [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ] [ρσ≡ρσ′]))
in irrelevanceEq″ (PE.sym (wk-subst F))
(PE.sym (wk-subst F)) PE.refl PE.refl
[ρσ₂F]₀
([F]′ [ρ₂] ⊢Δ₂)
[σF≡σH])
(λ {ρ₂} {Δ₂} {a} [ρ₂] ⊢Δ₂ [a] →
let [ρσ₂] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ]
[ρσ₂F]₀ = proj₁ ([F]₀ ⊢Δ₂ [ρσ₂])
[σ∃FG] = proj₁ ([∃FG] ⊢Δ₁ [ρσ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
⊢ρσ₂F = escape [ρσ₂F]₀
[ρσ₂′] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ′]
⊢σH = escape (proj₁ ([F]₀ ⊢Δ₂ [ρσ₂′]))
univΔ₂ = proj₁ ([UF] ⊢Δ₂ [ρσ₂])
[a]′ = irrelevanceTerm′
(wk-subst F) PE.refl PE.refl (wk [ρ₂] ⊢Δ₂ [σF]₀)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ₂])) [a]
[a]″ = convTerm₁ (proj₁ ([F]₀ ⊢Δ₂ [ρσ₂]))
(proj₁ ([F]₀ ⊢Δ₂ [ρσ₂′]))
(proj₂ ([F]₀ ⊢Δ₂ [ρσ₂]) [ρσ₂′]
(wkSubstSEq [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ] [ρσ≡ρσ′]))
[a]′
[ρσa≡ρσ′a] = consSubstSEq {t = a} {A = F} [Γ] ⊢Δ₂
(wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ])
(wkSubstSEq [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ] [ρσ≡ρσ′])
[F]₀ [a]′
in irrelevanceEq″
(PE.sym (singleSubstWkComp a (ρ •ₛ σ) G))
(PE.sym (singleSubstWkComp a (ρ •ₛ σ′) G)) PE.refl PE.refl
(proj₁ (GappGen {F = F} {G = G} {σ = _} [Γ] [F]₀ [G]₀ ⊢Δ₁ [ρσ] a [ρ₂] ⊢Δ₂ [a]′))
(Gapp {F = F} {G = G} {σ = _} [Γ] [F]₀ [G]₀ ⊢Δ₁ [ρσ] a [ρ₂] ⊢Δ₂ [a]′)
(proj₂ (GappGen {F = F} {G = G} {σ = _} [Γ] [F]₀ [G]₀ ⊢Δ₁ [ρσ] a [ρ₂] ⊢Δ₂ [a]′)
([ρσ₂′] , [a]″)
[ρσa≡ρσ′a] ))
in irrelevanceEq″ (PE.sym (wk-subst (∃ F ▹ G)))
(PE.sym (wk-subst (∃ F ▹ G)))
PE.refl PE.refl
(proj₁ ([∃FG] ⊢Δ₁ [ρσ]))
(LogRel._⊩¹U_∷_^_/_.[t] [∃FG]ᵗ [ρ] ⊢Δ₁)
X))
∃ᵗᵛ {F} {G} {l∃ = ⁰} {Γ} [Γ] [F] [UG] [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let l = ∞
l∃ = ⁰
l∃≤ = ≡is≤ PE.refl
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
in ∃ᵗᵛ₁ {F} {G} {⁰} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ]
, (λ {σ′} [σ′] [σ≡σ′] →
let ⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
univΔ = proj₁ ([UF] ⊢Δ [σ])
[Fₜ]σ {σ′} [σ′] = [Fₜ] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
⊢Fₜ = escapeTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ]))
⊢F≡Fₜ = escapeTermEq univΔ (reflEqTerm univΔ (proj₁ ([Fₜ] ⊢Δ [σ])))
[liftσ′] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ′]
[wk1σ] = wk1SubstS [Γ] ⊢Δ ⊢F [σ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ ⊢F [σ′]
var0 = conv (var (⊢Δ ∙ ⊢F)
(PE.subst (λ x → 0 ∷ x ^ [ % , ι l∃ ] ∈ (Δ ∙ subst σ F ^ [ % , ι l∃ ]))
(wk-subst F) here))
(≅-eq (escapeEq (proj₁ ([F] (⊢Δ ∙ ⊢F) [wk1σ]))
(proj₂ ([F] (⊢Δ ∙ ⊢F) [wk1σ]) [wk1σ′]
(wk1SubstSEq [Γ] ⊢Δ ⊢F [σ] [σ≡σ′]))))
[liftσ′]′ = [wk1σ′]
, neuTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [wk1σ′])) (var 0)
var0 (~-var var0)
⊢F′ = escape (proj₁ ([F] ⊢Δ [σ′]))
univΔ = proj₁ ([UF] ⊢Δ [σ])
univΔ′ = proj₁ ([UF] ⊢Δ [σ′])
[Fₜ]σ {σ′} [σ′] = [Fₜ] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
⊢Fₜ′ = escapeTerm univΔ′ (proj₁ ([Fₜ] ⊢Δ [σ′]))
⊢Gₜ′ = escapeTerm (proj₁ ([UG] {σ = liftSubst σ′} (⊢Δ ∙ ⊢F′) [liftσ′]))
(proj₁ ([Gₜ] (⊢Δ ∙ ⊢F′) [liftσ′]))
⊢F≡F′ = escapeTermEq univΔ (proj₂ ([Fₜ] ⊢Δ [σ]) [σ′] [σ≡σ′])
⊢G≡G′ = escapeTermEq (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ]))
(proj₂ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]) [liftσ′]′
(liftSubstSEq {F = F} [Γ] ⊢Δ [F] [σ] [σ≡σ′]))
[F]₀ = univᵛ {F} [Γ] (≡is≤ PE.refl) [UF] [Fₜ]
[UG]′ = S.irrelevance {A = Univ % l∃} {r = [ ! , next l∃ ]} (_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀) (λ {Δ} {σ} → [UG] {Δ} {σ})
[Gₜ]′ = S.irrelevanceTerm {l′ = ∞} {A = Univ % l∃} {t = G}
(_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F]₀)
(λ {Δ} {σ} → [UG] {Δ} {σ})
(λ {Δ} {σ} → [UG]′ {Δ} {σ})
[Gₜ]
[G]₀ = univᵛ {G} (_∙_ {A = F} [Γ] [F]₀) l∃≤
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) (λ {Δ} {σ} → [Gₜ]′ {Δ} {σ})
[∃FG-cong] = ∃-congᵛ {F} {G} {F} {G} [Γ] [F]₀ [G]₀ [F]₀ [G]₀
(λ ⊢Δ₁ [σ]₁ → proj₂ ([F]₀ ⊢Δ₁ [σ]₁) [σ]₁ (reflSubst [Γ] ⊢Δ₁ [σ]₁))
(λ {Δ₁} {σ₁} ⊢Δ₁ [σ]₁ → proj₂ ([G]₀ ⊢Δ₁ [σ]₁) [σ]₁ (reflSubst {σ₁} ((_∙_ {A = F} [Γ] [F]₀)) ⊢Δ₁ [σ]₁))
[∃FG]ᵗ = ∃ᵗᵛ₁ {F} {G} {l∃ = ⁰} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ]
[∃FG]ᵗ′ = ∃ᵗᵛ₁ {F} {G} {l∃ = ⁰} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] {Δ = Δ} {σ = σ′} ⊢Δ [σ′]
[∃FG] = ∃ᵛ {F} {G} {Γ} {l∃ = ⁰} [Γ] [F]₀ [G]₀
in Uₜ₌ [∃FG]ᵗ
[∃FG]ᵗ′
(≅ₜ-∃-cong ⊢F ⊢F≡F′ ⊢G≡G′)
(λ {ρ} {Δ₁} [ρ] ⊢Δ₁ → let [∃FG-cong]′ = [∃FG-cong] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])
X = irrelevanceEq″ (PE.sym (wk-subst (∃ F ▹ G)))
(PE.sym (wk-subst (∃ F ▹ G)))
PE.refl PE.refl
(proj₁ ([∃FG] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])))
(LogRel._⊩¹U_∷_^_/_.[t] [∃FG]ᵗ [ρ] ⊢Δ₁)
[∃FG-cong]′
[σ∃FG] = proj₁ ([∃FG] ⊢Δ [σ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
[ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[σF]₀ = proj₁ ([F]₀ ⊢Δ₁ [ρσ])
⊢σF₀ = escape [σF]₀
[σG]₀ = proj₁ ([G]₀ (⊢Δ₁ ∙ ⊢σF₀) (liftSubstS {F = F} [Γ] ⊢Δ₁ [F]₀ [ρσ]))
[ρσ′] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ′]
[σF′]₀ = proj₁ ([F]₀ ⊢Δ₁ [ρσ′])
⊢σH = escape (proj₁ ([F]₀ ⊢Δ₁ [ρσ′]))
⊢σE = escape (proj₁ ([G]₀ (⊢Δ₁ ∙ ⊢σH) (liftSubstS {F = F} [Γ] ⊢Δ₁ [F]₀ [ρσ′])))
univΔ₁ = proj₁ ([UF] ⊢Δ₁ [ρσ])
[ρσ≡ρσ′] = wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] [σ≡σ′]
[σF≡σH] = univEqEq univΔ₁ [σF]₀ (proj₂ ([Fₜ] ⊢Δ₁ [ρσ]) [ρσ′] [ρσ≡ρσ′])
⊢σF≡σH = escapeEq [σF]₀ [σF≡σH]
[σF] = proj₁ ([F] ⊢Δ₁ [ρσ])
⊢σF = escape [σF]
liftσ = liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ]
[wk1σ] = wk1SubstS [Γ] ⊢Δ₁ ⊢σF [ρσ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ₁ ⊢σF [ρσ′]
var0 = conv (var (⊢Δ₁ ∙ ⊢σF)
(PE.subst (λ x → 0 ∷ x ^ [ % , ι l∃ ] ∈ (Δ₁ ∙ subst (ρ •ₛ σ) F ^ [ % , ι l∃ ]))
(wk-subst F) here))
(≅-eq (escapeEq (proj₁ ([F] (⊢Δ₁ ∙ ⊢σF) [wk1σ]))
(proj₂ ([F] (⊢Δ₁ ∙ ⊢σF) [wk1σ]) [wk1σ′]
(wk1SubstSEq [Γ] ⊢Δ₁ ⊢σF [ρσ] [ρσ≡ρσ′]))))
[liftσ′]′ : (Δ₁ ∙ subst (ρ •ₛ σ) F ^ [ % , ι l∃ ]) ⊩ˢ liftSubst (ρ •ₛ σ′) ∷
Γ ∙ F ^ [ % , ι l∃ ] / [Γ] ∙ [F] /
(⊢Δ₁ ∙ escape (proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]))))
[liftσ′]′ = [wk1σ′]
, neuTerm (proj₁ ([F] (⊢Δ₁ ∙ ⊢σF) [wk1σ′])) (var 0)
var0 (~-var var0)
liftσ′ = liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ′]
univΔ₁G = proj₁ ([UG] (⊢Δ₁ ∙ ⊢σF) liftσ)
[σG≡σE] = univEqEq univΔ₁G [σG]₀ (proj₂ ([Gₜ] {σ = liftSubst (ρ •ₛ σ)} (⊢Δ₁ ∙ ⊢σF) liftσ) [liftσ′]′
(liftSubstSEq {F = F} [Γ] ⊢Δ₁ [F] [ρσ] [ρσ≡ρσ′]))
⊢σG≡σE = escapeEq [σG]₀ [σG≡σE]
X = ∃₌ (subst (ρ •ₛ σ′) F)
(subst (liftSubst (ρ •ₛ σ′)) G)
(id (univ (∃ⱼ (un-univ ⊢σH) ▹ (un-univ ⊢σE))))
((≅-univ (≅ₜ-∃-cong ⊢σF (≅-un-univ ⊢σF≡σH) (≅-un-univ ⊢σG≡σE))))
(λ {ρ₂} {Δ₂} [ρ₂] ⊢Δ₂ →
let
[ρσ₂] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ]
[ρσ₂F]₀ = proj₁ ([F]₀ ⊢Δ₂ [ρσ₂])
[σ∃FG] = proj₁ ([∃FG] ⊢Δ₁ [ρσ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
⊢ρσ₂F = escape [ρσ₂F]₀
[ρσ₂′] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ′]
⊢σH = escape (proj₁ ([F]₀ ⊢Δ₂ [ρσ₂′]))
univΔ₂ = proj₁ ([UF] ⊢Δ₂ [ρσ₂])
[σF≡σH] = univEqEq univΔ₂ [ρσ₂F]₀ (proj₂ ([Fₜ] ⊢Δ₂ [ρσ₂]) [ρσ₂′]
(wkSubstSEq [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ] [ρσ≡ρσ′]))
in irrelevanceEq″ (PE.sym (wk-subst F))
(PE.sym (wk-subst F)) PE.refl PE.refl
[ρσ₂F]₀
([F]′ [ρ₂] ⊢Δ₂)
[σF≡σH])
(λ {ρ₂} {Δ₂} {a} [ρ₂] ⊢Δ₂ [a] →
let [ρσ₂] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ]
[ρσ₂F]₀ = proj₁ ([F]₀ ⊢Δ₂ [ρσ₂])
[σ∃FG] = proj₁ ([∃FG] ⊢Δ₁ [ρσ])
_ , ∃ᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmb (∃-elim [σ∃FG])
⊢ρσ₂F = escape [ρσ₂F]₀
[ρσ₂′] = wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ′]
⊢σH = escape (proj₁ ([F]₀ ⊢Δ₂ [ρσ₂′]))
univΔ₂ = proj₁ ([UF] ⊢Δ₂ [ρσ₂])
[a]′ = irrelevanceTerm′
(wk-subst F) PE.refl PE.refl (wk [ρ₂] ⊢Δ₂ [σF]₀)
(proj₁ ([F]₀ ⊢Δ₂ [ρσ₂])) [a]
[a]″ = convTerm₁ (proj₁ ([F]₀ ⊢Δ₂ [ρσ₂]))
(proj₁ ([F]₀ ⊢Δ₂ [ρσ₂′]))
(proj₂ ([F]₀ ⊢Δ₂ [ρσ₂]) [ρσ₂′]
(wkSubstSEq [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ] [ρσ≡ρσ′]))
[a]′
[ρσa≡ρσ′a] = consSubstSEq {t = a} {A = F} [Γ] ⊢Δ₂
(wkSubstS [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ])
(wkSubstSEq [Γ] ⊢Δ₁ ⊢Δ₂ [ρ₂] [ρσ] [ρσ≡ρσ′])
[F]₀ [a]′
in irrelevanceEq″
(PE.sym (singleSubstWkComp a (ρ •ₛ σ) G))
(PE.sym (singleSubstWkComp a (ρ •ₛ σ′) G)) PE.refl PE.refl
(proj₁ (GappGen {F = F} {G = G} {σ = _} [Γ] [F]₀ [G]₀ ⊢Δ₁ [ρσ] a [ρ₂] ⊢Δ₂ [a]′))
(Gapp {F = F} {G = G} {σ = _} [Γ] [F]₀ [G]₀ ⊢Δ₁ [ρσ] a [ρ₂] ⊢Δ₂ [a]′)
(proj₂ (GappGen {F = F} {G = G} {σ = _} [Γ] [F]₀ [G]₀ ⊢Δ₁ [ρσ] a [ρ₂] ⊢Δ₂ [a]′)
([ρσ₂′] , [a]″)
[ρσa≡ρσ′a] ))
in irrelevanceEq″ (PE.sym (wk-subst (∃ F ▹ G)))
(PE.sym (wk-subst (∃ F ▹ G)))
PE.refl PE.refl
(proj₁ ([∃FG] ⊢Δ₁ [ρσ]))
(LogRel._⊩¹U_∷_^_/_.[t] [∃FG]ᵗ [ρ] ⊢Δ₁)
X))
-- Validity of ∃-congurence as a term equality.
∃-congᵗᵛ : ∀ {F G H E l∃ Γ} ([Γ] : ⊩ᵛ Γ) →
let l = ∞
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[U∃] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
in
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
([H] : Γ ⊩ᵛ⟨ l ⟩ H ^ [ % , ι l∃ ] / [Γ])
([UG] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F])
([UE] : Γ ∙ H ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [H])
([F]ₜ : Γ ⊩ᵛ⟨ l ⟩ F ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [UF])
([G]ₜ : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F] / (λ {Δ} {σ} → [UG] {Δ} {σ}))
([H]ₜ : Γ ⊩ᵛ⟨ l ⟩ H ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [UF])
([E]ₜ : Γ ∙ H ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ E ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [H] / (λ {Δ} {σ} → [UE] {Δ} {σ}))
([F≡H]ₜ : Γ ⊩ᵛ⟨ l ⟩ F ≡ H ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [UF])
([G≡E]ₜ : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ≡ E ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F]
/ (λ {Δ} {σ} → [UG] {Δ} {σ}))
→ Γ ⊩ᵛ⟨ l ⟩ ∃ F ▹ G ≡ ∃ H ▹ E ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [U∃]
∃-congᵗᵛ {F} {G} {H} {E} {l∃ = ¹} {Γ}
[Γ] [F] [H] [UG] [UE] [F]ₜ [G]ₜ [H]ₜ [E]ₜ [F≡H]ₜ [G≡E]ₜ {Δ} {σ} ⊢Δ [σ] =
let l = ∞
l∃ = ¹
l∃≤ = ≡is≤ PE.refl
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[∃FG]ᵗ = ∃ᵗᵛ₁ {F} {G} {l∃ = ¹} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [F]ₜ [G]ₜ {Δ = Δ} {σ = σ} ⊢Δ [σ]
[∃HE]ᵗ = ∃ᵗᵛ₁ {H} {E} {l∃ = ¹} {Γ} [Γ] [H] (λ {Δ} {σ} → [UE] {Δ} {σ}) [H]ₜ [E]ₜ {Δ = Δ} {σ = σ} ⊢Δ [σ]
⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
univΔ = proj₁ ([UF] ⊢Δ [σ])
[G] = maybeEmbᵛ {A = G} (_∙_ {A = F} [Γ] [F]) (univᵛ {G} (_∙_ {A = F} [Γ] [F]) l∃≤ (λ {Δ} {σ} → [UG] {Δ} {σ}) [G]ₜ)
[E] = maybeEmbᵛ {A = E} (_∙_ {A = H} [Γ] [H]) (univᵛ {E} (_∙_ {A = H} [Γ] [H]) l∃≤ (λ {Δ} {σ} → [UE] {Δ} {σ}) [E]ₜ)
[F≡H] = univEqᵛ {F} {H} [Γ] [UF] [F] [F≡H]ₜ
[G≡E] = univEqᵛ {G} {E} (_∙_ {A = F} [Γ] [F]) (λ {Δ} {σ} → [UG] {Δ} {σ}) [G] [G≡E]ₜ
in Uₜ₌ [∃FG]ᵗ [∃HE]ᵗ (≅ₜ-∃-cong ⊢F (escapeTermEq univΔ ([F≡H]ₜ ⊢Δ [σ]))
(escapeTermEq (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ]))
([G≡E]ₜ (⊢Δ ∙ ⊢F) [liftσ])))
λ {ρ} {Δ₁} [ρ] ⊢Δ₁ → let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
X = ∃-congᵛ {F} {G} {H} {E} {Γ} {¹} [Γ] [F] [G] [H] [E] [F≡H] [G≡E] ⊢Δ₁ [ρσ]
in irrelevanceEq″ (PE.sym (wk-subst (∃ F ▹ G)))
(PE.sym (wk-subst (∃ H ▹ E))) PE.refl PE.refl
(proj₁ (∃ᵛ {F} {G} [Γ] [F] [G] ⊢Δ₁ [ρσ])) (LogRel._⊩¹U_∷_^_/_.[t] [∃FG]ᵗ [ρ] ⊢Δ₁) X
∃-congᵗᵛ {F} {G} {H} {E} {l∃ = ⁰} {Γ}
[Γ] [F] [H] [UG] [UE] [F]ₜ [G]ₜ [H]ₜ [E]ₜ [F≡H]ₜ [G≡E]ₜ {Δ} {σ} ⊢Δ [σ] =
let l = ∞
l∃ = ⁰
l∃≤ = ≡is≤ PE.refl
[UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[∃FG]ᵗ = ∃ᵗᵛ₁ {F} {G} {l∃ = ⁰} {Γ} [Γ] [F] (λ {Δ} {σ} → [UG] {Δ} {σ}) [F]ₜ [G]ₜ {Δ = Δ} {σ = σ} ⊢Δ [σ]
[∃HE]ᵗ = ∃ᵗᵛ₁ {H} {E} {l∃ = ⁰} {Γ} [Γ] [H] (λ {Δ} {σ} → [UE] {Δ} {σ}) [H]ₜ [E]ₜ {Δ = Δ} {σ = σ} ⊢Δ [σ]
⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
univΔ = proj₁ ([UF] ⊢Δ [σ])
[Fₜ]σ {σ′} [σ′] = [F]ₜ {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([Fₜ]σ [σ])
[G] = maybeEmbᵛ {A = G} (_∙_ {A = F} [Γ] [F]) (univᵛ {G} (_∙_ {A = F} [Γ] [F]) l∃≤ (λ {Δ} {σ} → [UG] {Δ} {σ}) [G]ₜ)
[E] = maybeEmbᵛ {A = E} (_∙_ {A = H} [Γ] [H]) (univᵛ {E} (_∙_ {A = H} [Γ] [H]) l∃≤ (λ {Δ} {σ} → [UE] {Δ} {σ}) [E]ₜ)
[F≡H] = univEqᵛ {F} {H} [Γ] [UF] [F] [F≡H]ₜ
[G≡E] = univEqᵛ {G} {E} (_∙_ {A = F} [Γ] [F]) (λ {Δ} {σ} → [UG] {Δ} {σ}) [G] [G≡E]ₜ
in Uₜ₌ [∃FG]ᵗ [∃HE]ᵗ (≅ₜ-∃-cong ⊢F (escapeTermEq univΔ ([F≡H]ₜ ⊢Δ [σ]))
(escapeTermEq (proj₁ ([UG] (⊢Δ ∙ ⊢F) [liftσ]))
([G≡E]ₜ (⊢Δ ∙ ⊢F) [liftσ])))
λ {ρ} {Δ₁} [ρ] ⊢Δ₁ → let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
X = ∃-congᵛ {F} {G} {H} {E} {Γ} {⁰} [Γ] [F] [G] [H] [E] [F≡H] [G≡E] ⊢Δ₁ [ρσ]
in irrelevanceEq″ (PE.sym (wk-subst (∃ F ▹ G)))
(PE.sym (wk-subst (∃ H ▹ E))) PE.refl PE.refl
(proj₁ (∃ᵛ {F} {G} [Γ] [F] [G] ⊢Δ₁ [ρσ])) (LogRel._⊩¹U_∷_^_/_.[t] [∃FG]ᵗ [ρ] ⊢Δ₁) X
-- Validity of non-dependent sum types.
××ᵛ : ∀ {F G l∃ Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ G ^ [ % , ι l∃ ] / [Γ]
→ Γ ⊩ᵛ⟨ l ⟩ F ×× G ^ [ % , ι l∃ ] / [Γ]
××ᵛ {F} {G} [Γ] [F] [G] =
∃ᵛ {F} {wk1 G} [Γ] [F] (wk1ᵛ {G} {F} [Γ] [F] [G])
-- Validity of non-dependent sum type congurence.
××-congᵛ : ∀ {F F′ G G′ l∃ Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
([F′] : Γ ⊩ᵛ⟨ l ⟩ F′ ^ [ % , ι l∃ ] / [Γ])
([F≡F′] : Γ ⊩ᵛ⟨ l ⟩ F ≡ F′ ^ [ % , ι l∃ ] / [Γ] / [F])
([G] : Γ ⊩ᵛ⟨ l ⟩ G ^ [ % , ι l∃ ] / [Γ])
([G′] : Γ ⊩ᵛ⟨ l ⟩ G′ ^ [ % , ι l∃ ] / [Γ])
([G≡G′] : Γ ⊩ᵛ⟨ l ⟩ G ≡ G′ ^ [ % , ι l∃ ] / [Γ] / [G])
→ Γ ⊩ᵛ⟨ l ⟩ F ×× G ≡ F′ ×× G′ ^ [ % , ι l∃ ] / [Γ] / ××ᵛ {F} {G} [Γ] [F] [G]
××-congᵛ {F} {F′} {G} {G′} [Γ] [F] [F′] [F≡F′] [G] [G′] [G≡G′] =
∃-congᵛ {F} {wk1 G} {F′} {wk1 G′} [Γ]
[F] (wk1ᵛ {G} {F} [Γ] [F] [G])
[F′] (wk1ᵛ {G′} {F′} [Γ] [F′] [G′])
[F≡F′] (wk1Eqᵛ {G} {G′} {F} [Γ] [F] [G] [G≡G′])
××ᵗᵛ : ∀ {F G l∃ Γ} ([Γ] : ⊩ᵛ Γ)→
let l = ∞
[U] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
in
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ F ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [U]
→ Γ ⊩ᵛ⟨ l ⟩ G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / (λ {Δ} {σ} → [U] {Δ} {σ})
→ Γ ⊩ᵛ⟨ l ⟩ F ×× G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [U]
××ᵗᵛ {F} {G} {l∃} [Γ] [F] [Fₜ] [Gₜ] =
let l = ∞
[U] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])
[Gₜ]′ = wk1ᵗᵛ {F} {G} {[ % , ι l∃ ]} {%} {l∃} [Γ] [F] [Gₜ]
[wU] = maybeEmbᵛ {A = Univ % _} (_∙_ {A = F} [Γ] [F]) (λ {Δ} {σ} → Uᵛ (proj₂ (levelBounded l∃)) (_∙_ {A = F} [Γ] [F]) {Δ} {σ})
[wU]′ = wk1ᵛ {Univ _ _ } {F} [Γ] [F] [U]
in ∃ᵗᵛ {F} {wk1 G} [Γ] [F] (λ {Δ} {σ} → [wU]′ {Δ} {σ}) [Fₜ]
(S.irrelevanceTerm {A = Univ _ _} {t = wk1 G} (_∙_ {A = F} [Γ] [F]) (_∙_ {A = F} [Γ] [F])
(λ {Δ} {σ} → [wU] {Δ} {σ}) (λ {Δ} {σ} → [wU]′ {Δ} {σ}) [Gₜ]′)
| 73.719626
| 186
| 0.286946
|
3d631f9ce2089ea03e232976be3d73d3cabe0fb3
| 11,150
|
agda
|
Agda
|
Cubical/HITs/PropositionalTruncation/Properties.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/HITs/PropositionalTruncation/Properties.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/PropositionalTruncation/Properties.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Eliminator for propositional truncation
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.PropositionalTruncation.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation.Base
private
variable
ℓ : Level
A B C : Type ℓ
rec : {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P
rec Pprop f ∣ x ∣ = f x
rec Pprop f (squash x y i) = Pprop (rec Pprop f x) (rec Pprop f y) i
rec2 : {P : Type ℓ} → isProp P → (A → A → P) → ∥ A ∥ → ∥ A ∥ → P
rec2 Pprop f ∣ x ∣ ∣ y ∣ = f x y
rec2 Pprop f ∣ x ∣ (squash y z i) = Pprop (rec2 Pprop f ∣ x ∣ y) (rec2 Pprop f ∣ x ∣ z) i
rec2 Pprop f (squash x y i) z = Pprop (rec2 Pprop f x z) (rec2 Pprop f y z) i
-- Old version
-- rec2 : ∀ {P : Type ℓ} → isProp P → (A → A → P) → ∥ A ∥ → ∥ A ∥ → P
-- rec2 Pprop f = rec (isProp→ Pprop) (λ a → rec Pprop (f a))
elim : {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a))
→ ((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
elim Pprop f ∣ x ∣ = f x
elim Pprop f (squash x y i) =
isOfHLevel→isOfHLevelDep 1 Pprop
(elim Pprop f x) (elim Pprop f y) (squash x y) i
elim2 : {P : ∥ A ∥ → ∥ A ∥ → Type ℓ}
(Bset : ((x y : ∥ A ∥) → isProp (P x y)))
(f : (a b : A) → P ∣ a ∣ ∣ b ∣)
(x y : ∥ A ∥) → P x y
elim2 Pprop f = elim (λ _ → isPropΠ (λ _ → Pprop _ _))
(λ a → elim (λ _ → Pprop _ _) (f a))
elim3 : {P : ∥ A ∥ → ∥ A ∥ → ∥ A ∥ → Type ℓ}
(Bset : ((x y z : ∥ A ∥) → isProp (P x y z)))
(g : (a b c : A) → P (∣ a ∣) ∣ b ∣ ∣ c ∣)
(x y z : ∥ A ∥) → P x y z
elim3 Pprop g = elim2 (λ _ _ → isPropΠ (λ _ → Pprop _ _ _))
(λ a b → elim (λ _ → Pprop _ _ _) (g a b))
propTruncIsProp : isProp ∥ A ∥
propTruncIsProp x y = squash x y
propTruncIdempotent≃ : isProp A → ∥ A ∥ ≃ A
propTruncIdempotent≃ {A = A} hA = isoToEquiv f
where
f : Iso ∥ A ∥ A
Iso.fun f = rec hA (idfun A)
Iso.inv f x = ∣ x ∣
Iso.rightInv f _ = refl
Iso.leftInv f = elim (λ _ → isProp→isSet propTruncIsProp _ _) (λ _ → refl)
propTruncIdempotent : isProp A → ∥ A ∥ ≡ A
propTruncIdempotent hA = ua (propTruncIdempotent≃ hA)
-- We could also define the eliminator using the recursor
elim' : {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) →
((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
elim' {P = P} Pprop f a =
rec (Pprop a) (λ x → transp (λ i → P (squash ∣ x ∣ a i)) i0 (f x)) a
map : (A → B) → (∥ A ∥ → ∥ B ∥)
map f = rec squash (∣_∣ ∘ f)
map2 : (A → B → C) → (∥ A ∥ → ∥ B ∥ → ∥ C ∥)
map2 f = rec (isPropΠ λ _ → squash) (map ∘ f)
-- The propositional truncation can be eliminated into non-propositional
-- types as long as the function used in the eliminator is 'coherently
-- constant.' The details of this can be found in the following paper:
--
-- https://arxiv.org/pdf/1411.2682.pdf
module SetElim (Bset : isSet B) where
Bset' : isSet' B
Bset' = isSet→isSet' Bset
rec→Set : (f : A → B) (kf : 2-Constant f) → ∥ A ∥ → B
helper : (f : A → B) (kf : 2-Constant f) → (t u : ∥ A ∥)
→ rec→Set f kf t ≡ rec→Set f kf u
rec→Set f kf ∣ x ∣ = f x
rec→Set f kf (squash t u i) = helper f kf t u i
helper f kf ∣ x ∣ ∣ y ∣ = kf x y
helper f kf (squash t u i) v
= Bset' (helper f kf t v) (helper f kf u v) (helper f kf t u) refl i
helper f kf t (squash u v i)
= Bset' (helper f kf t u) (helper f kf t v) refl (helper f kf u v) i
kcomp : (f : ∥ A ∥ → B) → 2-Constant (f ∘ ∣_∣)
kcomp f x y = cong f (squash ∣ x ∣ ∣ y ∣)
Fset : isSet (A → B)
Fset = isSetΠ (const Bset)
Kset : (f : A → B) → isSet (2-Constant f)
Kset f = isSetΠ (λ _ → isSetΠ (λ _ → isProp→isSet (Bset _ _)))
setRecLemma
: (f : ∥ A ∥ → B)
→ rec→Set (f ∘ ∣_∣) (kcomp f) ≡ f
setRecLemma f i t
= elim {P = λ t → rec→Set (f ∘ ∣_∣) (kcomp f) t ≡ f t}
(λ t → Bset _ _) (λ x → refl) t i
mkKmap : (∥ A ∥ → B) → Σ (A → B) 2-Constant
mkKmap f = f ∘ ∣_∣ , kcomp f
fib : (g : Σ (A → B) 2-Constant) → fiber mkKmap g
fib (g , kg) = rec→Set g kg , refl
eqv : (g : Σ (A → B) 2-Constant) → ∀ fi → fib g ≡ fi
eqv g (f , p) =
Σ≡Prop (λ f → isOfHLevelΣ 2 Fset Kset _ _)
(cong (uncurry rec→Set) (sym p) ∙ setRecLemma f)
trunc→Set≃ : (∥ A ∥ → B) ≃ (Σ (A → B) 2-Constant)
trunc→Set≃ .fst = mkKmap
trunc→Set≃ .snd .equiv-proof g = fib g , eqv g
-- The strategy of this equivalence proof follows the paper more closely.
-- It is used further down for the groupoid version, because the above
-- strategy does not generalize so easily.
e : B → Σ (A → B) 2-Constant
e b = const b , λ _ _ → refl
eval : A → (γ : Σ (A → B) 2-Constant) → B
eval a₀ (g , _) = g a₀
e-eval : ∀ (a₀ : A) γ → e (eval a₀ γ) ≡ γ
e-eval a₀ (g , kg) i .fst a₁ = kg a₀ a₁ i
e-eval a₀ (g , kg) i .snd a₁ a₂ = Bset' refl (kg a₁ a₂) (kg a₀ a₁) (kg a₀ a₂) i
e-isEquiv : A → isEquiv (e {A = A})
e-isEquiv a₀ = isoToIsEquiv (iso e (eval a₀) (e-eval a₀) λ _ → refl)
preEquiv₁ : ∥ A ∥ → B ≃ Σ (A → B) 2-Constant
preEquiv₁ t = e , rec (isPropIsEquiv e) e-isEquiv t
preEquiv₂ : (∥ A ∥ → Σ (A → B) 2-Constant) ≃ Σ (A → B) 2-Constant
preEquiv₂ = isoToEquiv (iso to const (λ _ → refl) retr)
where
to : (∥ A ∥ → Σ (A → B) 2-Constant) → Σ (A → B) 2-Constant
to f .fst x = f ∣ x ∣ .fst x
to f .snd x y i = f (squash ∣ x ∣ ∣ y ∣ i) .snd x y i
retr : retract to const
retr f i t .fst x = f (squash ∣ x ∣ t i) .fst x
retr f i t .snd x y
= Bset'
(λ j → f (squash ∣ x ∣ ∣ y ∣ j) .snd x y j)
(f t .snd x y)
(λ j → f (squash ∣ x ∣ t j) .fst x)
(λ j → f (squash ∣ y ∣ t j) .fst y)
i
trunc→Set≃₂ : (∥ A ∥ → B) ≃ Σ (A → B) 2-Constant
trunc→Set≃₂ = compEquiv (equivΠCod preEquiv₁) preEquiv₂
open SetElim public using (rec→Set; trunc→Set≃)
elim→Set
: {P : ∥ A ∥ → Type ℓ}
→ (∀ t → isSet (P t))
→ (f : (x : A) → P ∣ x ∣)
→ (kf : ∀ x y → PathP (λ i → P (squash ∣ x ∣ ∣ y ∣ i)) (f x) (f y))
→ (t : ∥ A ∥) → P t
elim→Set {A = A} {P = P} Pset f kf t
= rec→Set (Pset t) g gk t
where
g : A → P t
g x = transp (λ i → P (squash ∣ x ∣ t i)) i0 (f x)
gk : 2-Constant g
gk x y i = transp (λ j → P (squash (squash ∣ x ∣ ∣ y ∣ i) t j)) i0 (kf x y i)
RecHProp : (P : A → hProp ℓ) (kP : ∀ x y → P x ≡ P y) → ∥ A ∥ → hProp ℓ
RecHProp P kP = rec→Set isSetHProp P kP
module GpdElim (Bgpd : isGroupoid B) where
Bgpd' : isGroupoid' B
Bgpd' = isGroupoid→isGroupoid' Bgpd
module _ (f : A → B) (3kf : 3-Constant f) where
open 3-Constant 3kf
rec→Gpd : ∥ A ∥ → B
pathHelper : (t u : ∥ A ∥) → rec→Gpd t ≡ rec→Gpd u
triHelper₁
: (t u v : ∥ A ∥)
→ Square (pathHelper t u) (pathHelper t v) refl (pathHelper u v)
triHelper₂
: (t u v : ∥ A ∥)
→ Square (pathHelper t v) (pathHelper u v) (pathHelper t u) refl
rec→Gpd ∣ x ∣ = f x
rec→Gpd (squash t u i) = pathHelper t u i
pathHelper ∣ x ∣ ∣ y ∣ = link x y
pathHelper (squash t u j) v = triHelper₂ t u v j
pathHelper ∣ x ∣ (squash u v j) = triHelper₁ ∣ x ∣ u v j
triHelper₁ ∣ x ∣ ∣ y ∣ ∣ z ∣ = coh₁ x y z
triHelper₁ (squash s t i) u v
= Bgpd'
(triHelper₁ s u v)
(triHelper₁ t u v)
(triHelper₂ s t u)
(triHelper₂ s t v)
(λ i → refl)
(λ i → pathHelper u v)
i
triHelper₁ ∣ x ∣ (squash t u i) v
= Bgpd'
(triHelper₁ ∣ x ∣ t v)
(triHelper₁ ∣ x ∣ u v)
(triHelper₁ ∣ x ∣ t u)
(λ i → pathHelper ∣ x ∣ v)
(λ i → refl)
(triHelper₂ t u v)
i
triHelper₁ ∣ x ∣ ∣ y ∣ (squash u v i)
= Bgpd'
(triHelper₁ ∣ x ∣ ∣ y ∣ u)
(triHelper₁ ∣ x ∣ ∣ y ∣ v)
(λ i → link x y)
(triHelper₁ ∣ x ∣ u v)
(λ i → refl)
(triHelper₁ ∣ y ∣ u v)
i
triHelper₂ ∣ x ∣ ∣ y ∣ ∣ z ∣ = coh₂ x y z
triHelper₂ (squash s t i) u v
= Bgpd'
(triHelper₂ s u v)
(triHelper₂ t u v)
(triHelper₂ s t v)
(λ i → pathHelper u v)
(triHelper₂ s t u)
(λ i → refl)
i
triHelper₂ ∣ x ∣ (squash t u i) v
= Bgpd'
(triHelper₂ ∣ x ∣ t v)
(triHelper₂ ∣ x ∣ u v)
(λ i → pathHelper ∣ x ∣ v)
(triHelper₂ t u v)
(triHelper₁ ∣ x ∣ t u)
(λ i → refl)
i
triHelper₂ ∣ x ∣ ∣ y ∣ (squash u v i)
= Bgpd'
(triHelper₂ ∣ x ∣ ∣ y ∣ u)
(triHelper₂ ∣ x ∣ ∣ y ∣ v)
(triHelper₁ ∣ x ∣ u v)
(triHelper₁ ∣ y ∣ u v)
(λ i → link x y)
(λ i → refl)
i
preEquiv₁ : (∥ A ∥ → Σ (A → B) 3-Constant) ≃ Σ (A → B) 3-Constant
preEquiv₁ = isoToEquiv (iso fn const (λ _ → refl) retr)
where
open 3-Constant
fn : (∥ A ∥ → Σ (A → B) 3-Constant) → Σ (A → B) 3-Constant
fn f .fst x = f ∣ x ∣ .fst x
fn f .snd .link x y i = f (squash ∣ x ∣ ∣ y ∣ i) .snd .link x y i
fn f .snd .coh₁ x y z i j
= f (squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i) j) .snd .coh₁ x y z i j
retr : retract fn const
retr f i t .fst x = f (squash ∣ x ∣ t i) .fst x
retr f i t .snd .link x y j
= f (squash (squash ∣ x ∣ ∣ y ∣ j) t i) .snd .link x y j
retr f i t .snd .coh₁ x y z
= Bgpd'
(λ k j → f (cb k j i0) .snd .coh₁ x y z k j )
(λ k j → f (cb k j i1) .snd .coh₁ x y z k j)
(λ k j → f (cb i0 j k) .snd .link x y j)
(λ k j → f (cb i1 j k) .snd .link x z j)
(λ _ → refl)
(λ k j → f (cb j i1 k) .snd .link y z j)
i
where
cb : I → I → I → ∥ _ ∥
cb i j k = squash (squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i) j) t k
e : B → Σ (A → B) 3-Constant
e b .fst _ = b
e b .snd = record
{ link = λ _ _ _ → b
; coh₁ = λ _ _ _ _ _ → b
}
eval : A → Σ (A → B) 3-Constant → B
eval a₀ (g , _) = g a₀
module _ where
open 3-Constant
e-eval : ∀(a₀ : A) γ → e (eval a₀ γ) ≡ γ
e-eval a₀ (g , 3kg) i .fst x = 3kg .link a₀ x i
e-eval a₀ (g , 3kg) i .snd .link x y = λ j → 3kg .coh₁ a₀ x y j i
e-eval a₀ (g , 3kg) i .snd .coh₁ x y z
= Bgpd'
(λ _ _ → g a₀)
(3kg .coh₁ x y z)
(λ k j → 3kg .coh₁ a₀ x y j k)
(λ k j → 3kg .coh₁ a₀ x z j k)
(λ _ → refl)
(λ k j → 3kg .coh₁ a₀ y z j k)
i
e-isEquiv : A → isEquiv (e {A = A})
e-isEquiv a₀ = isoToIsEquiv (iso e (eval a₀) (e-eval a₀) λ _ → refl)
preEquiv₂ : ∥ A ∥ → B ≃ Σ (A → B) 3-Constant
preEquiv₂ t = e , rec (isPropIsEquiv e) e-isEquiv t
trunc→Gpd≃ : (∥ A ∥ → B) ≃ Σ (A → B) 3-Constant
trunc→Gpd≃ = compEquiv (equivΠCod preEquiv₂) preEquiv₁
open GpdElim using (rec→Gpd; trunc→Gpd≃) public
RecHSet : (P : A → TypeOfHLevel ℓ 2) → 3-Constant P → ∥ A ∥ → TypeOfHLevel ℓ 2
RecHSet P 3kP = rec→Gpd (isOfHLevelTypeOfHLevel 2) P 3kP
| 31.948424
| 89
| 0.503229
|
52b33ebf1469336fa71f9d562cac132658ad6985
| 1,979
|
agda
|
Agda
|
Numeral/Natural/Combinatorics.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Combinatorics.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Combinatorics.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Combinatorics where
open import Numeral.Natural
open import Numeral.Natural.Oper
-- Counting combinations.
-- `𝑐𝐶 n k` is the number of ways one can pick `k` number of distinct objects from a set of `n` number of distinct objects.
-- Equivalently, it is the number of `k`-sized subsets of an `n`-sized set.
-- Also called: Binomial coefficients
-- Formulated using sets:
-- 𝐶: Set → ℕ → Set
-- 𝐶 S k = {(K∊℘(S)). #K = k}
-- 𝑐𝐶(n) = #𝐶(𝕟(n))
𝑐𝐶 : ℕ → ℕ → ℕ
𝑐𝐶 _ 𝟎 = 𝐒 𝟎
𝑐𝐶 𝟎 (𝐒 k) = 𝟎
𝑐𝐶 (𝐒 n) (𝐒 k) = 𝑐𝐶 n k + 𝑐𝐶 n (𝐒 k)
-- Counting partial permutations.
-- `𝑐𝑃 n k` is the number of arrangements for a list of `n` number of distinct objects into `k` number of objects.
-- Equivalently, it is the number of injective functions (function equality by the standard function extensionality) of type `𝕟(k) → 𝕟(n)`.
-- Also called: Falling factorial
-- Formulated using sets:
-- 𝑃: Set → ℕ → Set
-- 𝑃 S k = {(π: 𝕟(k) → S). Injective(π)}
-- 𝑐𝑃(n) = #𝑃(𝕟(n))
𝑐𝑃 : ℕ → ℕ → ℕ
𝑐𝑃 _ 𝟎 = 𝐒 𝟎
𝑐𝑃 𝟎 (𝐒 k) = 𝟎
𝑐𝑃 (𝐒 n) (𝐒 k) = 𝑐𝑃 n k ⋅ (𝐒 n)
-- Counting derangements.
-- `𝑐𝐷(n)` is the number of permutations of a list of `n` number of distinct objects such that in every permutation, no object is permuted with itself.
-- Formulated using sets:
-- 𝐷: Set → Set
-- 𝐷(S) = {(π∊𝑃(S)). ∀(s∊S). π(s) ≠ s}
-- 𝑐𝐷(n) = #𝐷(𝕟(n))
𝑐𝐷 : ℕ → ℕ
𝑐𝐷(𝟎) = 𝐒 𝟎
𝑐𝐷(𝐒 𝟎) = 𝟎
𝑐𝐷(𝐒(𝐒 n)) = 𝐒(n) ⋅ (𝑐𝐷 (𝐒 n) + 𝑐𝐷 n)
-- Stirling numbers of the first kind.
stir₁ : ℕ → ℕ → ℕ
stir₁ 𝟎 𝟎 = 𝐒(𝟎)
stir₁ (𝐒(n)) 𝟎 = 𝟎
stir₁ 𝟎 (𝐒(k)) = 𝟎
stir₁ (𝐒(n)) (𝐒(k)) = (n ⋅ stir₁ n (𝐒(k))) + stir₁ n k
-- Stirling numbers of the second kind.
stir₂ : ℕ → ℕ → ℕ
stir₂ 𝟎 𝟎 = 𝐒(𝟎)
stir₂ (𝐒(n)) 𝟎 = 𝟎
stir₂ 𝟎 (𝐒(k)) = 𝟎
stir₂ (𝐒(n)) (𝐒(k)) = (𝐒(k) ⋅ stir₂ n (𝐒(k))) + stir₂ n k
-- Counting injective functions.
𝑐𝐼𝑛𝑗 : ℕ → ℕ → ℕ
𝑐𝐼𝑛𝑗 = 𝑐𝑃
-- Counting surjective functions.
𝑐𝑆𝑢𝑟𝑗 : ℕ → ℕ → ℕ
𝑐𝑆𝑢𝑟𝑗 a b = stir₂ a b ⋅ (b !)
| 30.921875
| 151
| 0.580596
|
21c48cabcf3e4af0a7d67d73be8ab35bfdb22b46
| 171
|
agda
|
Agda
|
test/Fail/Issue2167.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2167.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2167.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-09-08, issue #2167 reported by effectfully
loop : Set₁
loop = .Set
-- WAS: looping of type checker
-- NOW: proper error about invalid dotted expression
| 21.375
| 59
| 0.730994
|
43e2cce1959f58466f875120ba1400038d6c6627
| 41,878
|
agda
|
Agda
|
archive/agda-1/Scratch.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/Scratch.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/Scratch.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Scratch (FunctionName : Set) where
open import Oscar.Data.Fin using (Fin; zero; suc; thick?)
open import Data.Nat using (ℕ; suc; zero)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂; cong; sym; trans)
open import Function using (_∘_; flip)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (∃; _,_; _×_)
open import Data.Empty using (⊥-elim)
open import Data.Vec using (Vec; []; _∷_)
data Term (n : ℕ) : Set where
i : (x : Fin n) -> Term n
leaf : Term n
_fork_ : (s t : Term n) -> Term n
function : FunctionName → ∀ {f} → Vec (Term n) f → Term n
Term-function-inj-FunctionName : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → fn₁ ≡ fn₂
Term-function-inj-FunctionName refl = refl
Term-function-inj-VecSize : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → N₁ ≡ N₂
Term-function-inj-VecSize refl = refl
Term-function-inj-Vector : ∀ {fn₁ fn₂} {n N} {ts₁ : Vec (Term n) N} {ts₂ : Vec (Term n) N} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → ts₁ ≡ ts₂
Term-function-inj-Vector refl = refl
Term-fork-inj-left : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → l₁ ≡ l₂
Term-fork-inj-left refl = refl
Term-fork-inj-right : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → r₁ ≡ r₂
Term-fork-inj-right refl = refl
open import Relation.Binary.HeterogeneousEquality using (_≅_; refl)
Term-function-inj-HetVector : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → ts₁ ≅ ts₂
Term-function-inj-HetVector refl = refl
_~>_ : (m n : ℕ) -> Set
m ~> n = Fin m -> Term n
▹ : ∀ {m n} -> (r : Fin m -> Fin n) -> Fin m -> Term n
▹ r = i ∘ r
record Substitution (T : ℕ → Set) : Set where
field
_◃_ : ∀ {m n} -> (f : m ~> n) -> T m -> T n
open Substitution ⦃ … ⦄ public
{-# DISPLAY Substitution._◃_ _ = _◃_ #-}
mutual
instance SubstitutionTerm : Substitution Term
Substitution._◃_ SubstitutionTerm = _◃′_ where
_◃′_ : ∀ {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)
f ◃′ (function fn ts) = function fn (f ◃ ts)
instance SubstitutionVecTerm : ∀ {N} → Substitution (flip Vec N ∘ Term )
Substitution._◃_ (SubstitutionVecTerm {N}) = _◃′_ where
_◃′_ : ∀ {m n} -> (f : m ~> n) -> Vec (Term m) N -> Vec (Term n) N
f ◃′ [] = []
f ◃′ (t ∷ ts) = f ◃ t ∷ f ◃ ts
_≐_ : {m n : ℕ} -> (Fin m -> Term n) -> (Fin m -> Term n) -> Set
f ≐ g = ∀ x -> f x ≡ g x
record SubstitutionExtensionality (T : ℕ → Set) ⦃ _ : Substitution T ⦄ : Set₁ where
field
◃ext : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> (t : T m) -> f ◃ t ≡ g ◃ t
open SubstitutionExtensionality ⦃ … ⦄ public
mutual
instance SubstitutionExtensionalityTerm : SubstitutionExtensionality Term
SubstitutionExtensionality.◃ext SubstitutionExtensionalityTerm = ◃ext′ where
◃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)
◃ext′ p (function fn ts) = cong (function fn) (◃ext p ts)
instance SubstitutionExtensionalityVecTerm : ∀ {N} → SubstitutionExtensionality (flip Vec N ∘ Term)
SubstitutionExtensionality.◃ext (SubstitutionExtensionalityVecTerm {N}) = λ x → ◃ext′ x where
◃ext′ : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> ∀ {N} (t : Vec (Term m) N) -> f ◃ t ≡ g ◃ t
◃ext′ p [] = refl
◃ext′ p (t ∷ ts) = cong₂ _∷_ (◃ext p t) (◃ext p ts)
_◇_ : ∀ {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
record Fact1 (T : ℕ → Set) ⦃ _ : Substitution T ⦄ : Set where
field
fact1 : ∀ {n} -> (t : T n) -> i ◃ t ≡ t
open Fact1 ⦃ … ⦄ public
mutual
instance Fact1Term : Fact1 Term
Fact1.fact1 Fact1Term (i x) = refl
Fact1.fact1 Fact1Term leaf = refl
Fact1.fact1 Fact1Term (s fork t) = cong₂ _fork_ (fact1 s) (fact1 t)
Fact1.fact1 Fact1Term (function fn ts) = cong (function fn) (fact1 ts)
instance Fact1TermVec : ∀ {N} → Fact1 (flip Vec N ∘ Term)
Fact1.fact1 Fact1TermVec [] = refl
Fact1.fact1 Fact1TermVec (t ∷ ts) = cong₂ _∷_ (fact1 t) (fact1 ts)
record Fact2 (T : ℕ → Set) ⦃ _ : Substitution T ⦄ : Set where
field
-- ⦃ s ⦄ : Substitution T
fact2 : ∀ {l m n} -> {f : Fin m -> Term n} {g : _} (t : T l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
open Fact2 ⦃ … ⦄ public
mutual
instance Fact2Term : Fact2 Term
-- Fact2.s Fact2Term = SubstitutionTerm
Fact2.fact2 Fact2Term (i x) = refl
Fact2.fact2 Fact2Term leaf = refl
Fact2.fact2 Fact2Term (s fork t) = cong₂ _fork_ (fact2 s) (fact2 t)
Fact2.fact2 Fact2Term {f = f} {g = g} (function fn ts) = cong (function fn) (fact2 {f = f} {g = g} ts) -- fact2 ts
instance Fact2TermVec : ∀ {N} → Fact2 (flip Vec N ∘ Term)
-- Fact2.s Fact2TermVec = SubstitutionVecTerm
Fact2.fact2 Fact2TermVec [] = refl
Fact2.fact2 Fact2TermVec (t ∷ ts) = cong₂ _∷_ (fact2 t) (fact2 ts)
fact3 : ∀ {l m n} (f : Fin m -> Term n) (r : Fin l -> Fin m) -> (f ◇ (▹ r)) ≡ (f ∘ r)
fact3 f r = refl
◃ext' : ∀ {m n o} {f : Fin m -> Term n}{g : Fin m -> Term o}{h} -> f ≐ (h ◇ g) -> ∀ (t : Term _) -> f ◃ t ≡ h ◃ (g ◃ t)
◃ext' p t = trans (◃ext p t) (Sub.fact2 t)
open import Data.Maybe using (Maybe; nothing; just; functor; maybe′)
open import Category.Monad
import Level
open RawMonad (Data.Maybe.monad {Level.zero})
record Check (T : ℕ → Set) : Set where
field
check : ∀{n} (x : Fin (suc n)) (t : T (suc n)) -> Maybe (T n)
open Check ⦃ … ⦄ public
_<*>_ = _⊛_
mutual
instance CheckTerm : Check Term
Check.check CheckTerm x (i y) = i <$> thick? x y
Check.check CheckTerm x leaf = just leaf
Check.check CheckTerm x (s fork t) = _fork_ <$> check x s ⊛ check x t
Check.check CheckTerm x (function fn ts) = ⦇ (function fn) (check x ts) ⦈
instance CheckTermVec : ∀ {N} → Check (flip Vec N ∘ Term)
Check.check CheckTermVec x [] = just []
Check.check CheckTermVec x (t ∷ ts) = ⦇ check x t ∷ check x ts ⦈
_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
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 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} () _
-- module Scratch where
-- open import Prelude
-- open import Agda.Builtin.Size
-- open import Tactic.Nat
-- postulate
-- Domain : Set
-- record Interpretation : Set where
-- field
-- V : Nat → Domain
-- F : (arity name : Nat) → Vec Domain arity → Domain
-- P : (arity name : Nat) → Vec Domain arity → Bool
-- data Term {i : Size} : Set where
-- variable : Nat → Term
-- function : (arity name : Nat) → {j : Size< i} → Vec (Term {j}) arity → Term {i}
-- interpretTerm : Interpretation → {i : Size} → Term {i} → Domain
-- interpretTerm I (variable v) = Interpretation.V I v
-- interpretTerm I (function arity name {j} domA) = Interpretation.F I arity name (interpretTerm I <$> domA)
-- data Formula : Set where
-- atomic : (arity name : Nat) → Vec Term arity → Formula
-- logical : Formula →
-- Formula →
-- Formula
-- quantified : Nat → Formula → Formula
-- infix 40 _⊗_
-- _⊗_ : Formula → Formula → Formula
-- _⊗_ a b = logical a b
-- ~ : Formula → Formula
-- ~ a = logical a a
-- infix 50 _⊃_
-- _⊃_ : Formula → Formula → Formula
-- _⊃_ p q = ~ (~ p ⊗ q)
-- data Literal : Formula → Set where
-- Latomic : (arity name : Nat) → (terms : Vec Term arity) → Literal (atomic arity name terms)
-- logical : (arity name : Nat) → (terms : Vec Term arity) → Literal (logical (atomic arity name terms) (atomic arity name terms))
-- record Sequent : Set where
-- constructor _⊢_
-- field
-- premises : List Formula
-- conclusion : Formula
-- data _∈_ {A : Set} (a : A) : List A → Set where
-- here : (as : List A) → a ∈ (a ∷ as)
-- there : (x : A) (as : List A) → a ∈ (x ∷ as)
-- record SimpleNDProblem (s : Sequent) : Set where
-- field
-- simpleConclusion : Literal (Sequent.conclusion s)
-- simplePremises : ∀ p → p ∈ Sequent.premises s → Literal p
-- record _≞_/_ (I : Interpretation) (I₀ : Interpretation) (v₀ : Nat) : Set where
-- field
-- lawV : (v : Nat) → (v ≡ v₀ → ⊥) → Interpretation.V I v ≡ Interpretation.V I₀ v
-- lawF : (arity name : Nat) → (domA : Vec Domain arity) → Interpretation.F I arity name domA ≡ Interpretation.F I₀ arity name domA
-- lawP : (arity name : Nat) → (domA : Vec Domain arity) → Interpretation.P I arity name domA ≡ Interpretation.P I₀ arity name domA
-- record Satisfaction (A : Set) : Set₁ where
-- field
-- _⊨_ : Interpretation → A → Set
-- postulate _⊨?_ : (I : Interpretation) → (φ : A) → Dec (I ⊨ φ)
-- _⊭_ : Interpretation → A → Set
-- I ⊭ x = I ⊨ x → ⊥
-- open Satisfaction ⦃ … ⦄
-- instance
-- SatisfactionFormula : Satisfaction Formula
-- Satisfaction._⊨_ SatisfactionFormula = _⊨ᴹ_ where
-- _⊨ᴹ_ : Interpretation → Formula → Set
-- _⊨ᴹ_ I₀ (quantified v₀ φ) = (I : Interpretation) → I ≞ I₀ / v₀ → I ⊨ᴹ φ
-- _⊨ᴹ_ I₀ (atomic arity name domA) = Interpretation.P I₀ arity name (interpretTerm I₀ <$> domA) ≡ true
-- _⊨ᴹ_ I₀ (logical φ₁ φ₂) = (I₀ ⊨ᴹ φ₁ → ⊥) × (I₀ ⊨ᴹ φ₂ → ⊥)
-- {-# DISPLAY _⊨ᴹ_ I f = I ⊨ f #-}
-- record Validity (A : Set) : Set₁ where
-- field
-- ⊨_ : A → Set
-- ⊭_ : A → Set
-- ⊭ x = ⊨ x → ⊥
-- open Validity ⦃ … ⦄
-- instance
-- ValidityFormula : Validity Formula
-- Validity.⊨_ ValidityFormula φ = (I : Interpretation) → I ⊨ φ
-- instance
-- SatisfactionSequent : Satisfaction Sequent
-- Satisfaction._⊨_ SatisfactionSequent I (premises ⊢ conclusion) = (_ : (premise : Formula) → premise ∈ premises → I ⊨ premise) → I ⊨ conclusion
-- ValiditySequent : Validity Sequent
-- Validity.⊨_ ValiditySequent sequent = (I : Interpretation) → I ⊨ sequent
-- negationElimination : (I : Interpretation) (φ : Formula) → I ⊨ (φ ⊗ φ) ⊗ (φ ⊗ φ) → I ⊨ φ
-- negationElimination I φ (x , y) with I ⊨? φ
-- negationElimination I φ (x₁ , y) | yes x = x
-- negationElimination I φ (x₁ , y) | no x = ⊥-elim (x₁ (x , x))
-- -- logical (logical (logical p p) q) (logical (logical p p) q)
-- conditionalization : (I : Interpretation) (p q : Formula) → I ⊨ q → I ⊨ ((p ∷ []) ⊢ p ⊃ q)
-- conditionalization I p q ⊨q -⊨p = let ⊨p = -⊨p p (here []) in (λ { (x , ~q) → ~q ⊨q}) , (λ { (x , y) → y ⊨q})
-- modusPonens : (I : Interpretation) (p q : Formula) → I ⊨ p → I ⊨ ((p ⊗ p) ⊗ q) ⊗ ((p ⊗ p) ⊗ q) → I ⊨ q
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) with I ⊨? q
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | yes x = x
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | no x = ⊥-elim (~[~p&~p&~q] ((λ { (x₁ , y) → y P}) , (λ x₁ → x x₁)))
-- theorem1a : (s : Sequent) → SimpleNDProblem s → ⊨ s → Either (Sequent.conclusion s ∈ Sequent.premises s) (Σ _ λ q → q ∈ Sequent.premises s × ~ q ∈ Sequent.premises s)
-- theorem1a ([] ⊢ atomic arity name x) record { simpleConclusion = (Latomic .arity .name .x) ; simplePremises = simplePremises } x₂ = {!!}
-- theorem1a ((x₁ ∷ premises) ⊢ atomic arity name x) record { simpleConclusion = (Latomic .arity .name .x) ; simplePremises = simplePremises } x₂ = {!!}
-- theorem1a (premises ⊢ logical .(atomic arity name terms) .(atomic arity name terms)) record { simpleConclusion = (logical arity name terms) ; simplePremises = simplePremises } x₁ = {!!}
-- theorem1a (premises ⊢ quantified x conclusion) record { simpleConclusion = () ; simplePremises = simplePremises } x₂
-- theorem1b : (s : Sequent) → SimpleNDProblem s → Either (Sequent.conclusion s ∈ Sequent.premises s) (Σ _ λ q → q ∈ Sequent.premises s × ~ q ∈ Sequent.premises s) → ⊨ s
-- theorem1b s x (left x₁) I x₂ = x₂ (Sequent.conclusion s) x₁
-- theorem1b s x (right (x₁ , x₂ , y)) I x₃ = let ~q = x₃ (~ x₁) y in let q = x₃ x₁ x₂ in ⊥-elim (fst ~q q)
-- {-
-- p ≡ q
-- p -> q & q -> p
-- (~p v q) & (~q v p)
-- ~(p & ~q) & ~(q & ~p)
-- ~(~~p & ~q) & ~(~~q & ~p)
-- bicondit elim is just simplification
-- modus ponens
-- p , (p ⊗ (q ⊗ q)) ⊗ (p ⊗ (q ⊗ q)) --> q
-- ~(~p & q)
-- p or ~q
-- p -> q
-- ~p v q
-- ~(p & ~q)
-- ~(p & ~q) & ~(p & ~q)
-- ~(~~p & ~q) & ~(~~p & ~q)
-- (~~p & ~q) ⊗ (~~p & ~q)
-- (~p ⊗ q) ⊗ (~p ⊗ q)
-- ((p ⊗ p) ⊗ q) ⊗ ((p ⊗ p) ⊗ q)
-- -}
-- {-
-- conditionalization p -> q from q, with discharge p
-- (p ∷ [] ⊢ q) ⊨ (∅ ⊢ q)
-- -}
-- --data ReasonerState : List Sequent → List Sequent → Set
-- {-
-- p <-> q
-- p -> q and q -> p
-- ~p v q and ~q or p
-- ~(p and ~q) and ~(q and ~p)
-- (p and ~q) ⊗ (q and ~p)
-- ((p ⊗ p) ⊗ q) ⊗ ((q ⊗ q) ⊗ p)
-- p -> q
-- ~p v q
-- ~(p and ~q)
-- ~(p and ~q) and ~(p and ~q)
-- ((p ⊗ p) ⊗ q) ⊗ ((p ⊗ p) ⊗ q)
-- but this is just simplification
-- p , p -> q ⊢ q
-- p , ((p ⊗ p) ⊗ q) ⊗ ((p ⊗ p) ⊗ q) ⊢ q
-- p , q <-- p & q
-- p <-- ~~p
-- p <-- (p ⊗ p) ⊗ (p ⊗ p)
-- -}
-- -- PorNotP : (I : Interpretation) (P : Formula) → I ⊨ (logical (logical P (logical P P)) (logical P (logical P P)))
-- -- PorNotP I P = (λ { (x , y) → y (x , x)}) , (λ { (x , y) → y (x , x)})
-- -- IFTHEN : Formula → Formula → Formula
-- -- IFTHEN P Q = logical (logical (logical P P) Q) (logical (logical P P) Q)
-- -- EXISTS : Nat → Formula → Formula
-- -- EXISTS n φ = (logical (quantified n (logical φ φ)) (quantified n (logical φ φ)))
-- -- F : Nat → Formula
-- -- F n = atomic 1 0 (variable n ∷ [])
-- -- Fa : Formula
-- -- Fa = F 0
-- -- ∃xFx : Formula
-- -- ∃xFx = EXISTS 1 (F 1)
-- -- IfFaThenExistsFa : (I : Interpretation) → I ⊨ (IFTHEN Fa ∃xFx)
-- -- IfFaThenExistsFa I = (λ { (I⊭~Fa , I⊭∃xFx) → I⊭~Fa ((λ x → I⊭∃xFx ((λ x₁ → fst (x₁ {!!} {!!}) {!!}) , (λ x₁ → {!!}))) , {!!})}) , (λ { (x , y) → {!!}})
-- -- NotPAndNotNotP : (I : Interpretation) (P : Formula) → I ⊨ (logical P (logical P P))
-- -- NotPAndNotNotP = {!!}
-- -- -- Valid : Formula → Set₁
-- -- -- Valid φ = (I : Interpretation) → I Satisfies φ
-- -- -- -- data SkolemFormula {ι : Size} (α : Alphabet) : Set where
-- -- -- -- atomic : Predication α → SkolemFormula α
-- -- -- -- logical : {ι¹ : Size< ι} → SkolemFormula {ι¹} α → {ι² : Size< ι} → SkolemFormula {ι²} α → SkolemFormula {ι} α
-- -- -- -- record Alphabet₊ᵥ (α : Alphabet) : Set where
-- -- -- -- constructor α₊ᵥ⟨_⟩
-- -- -- -- field
-- -- -- -- alphabet : Alphabet
-- -- -- -- .one-variable-is-added : (number ∘ variables $ alphabet) ≡ suc (number ∘ variables $ α)
-- -- -- -- .there-are-no-functions-of-maximal-arity : number (functions alphabet) zero ≡ zero
-- -- -- -- .shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → number (functions alphabet) (suc ytira₁) ≡ number (functions α) ytira₀
-- -- -- -- open Alphabet₊ᵥ
-- -- -- -- record Alphabet₊ₛ (α : Alphabet) : Set where
-- -- -- -- constructor α₊ₛ⟨_⟩
-- -- -- -- field
-- -- -- -- alphabet : Alphabet
-- -- -- -- open Alphabet₊ₛ
-- -- -- -- {-
-- -- -- -- toSkolemFormula
-- -- -- -- ∀x(F x v₀ v₁) ⟿ F v₀ v₁ v₂
-- -- -- -- ∃x(F x v₀ v₁) ⟿ F (s₀͍₂ v₀ v₁) v₀ v₁
-- -- -- -- ∀x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F v₀ (s₀͍₂ v₁ v₂) v₂
-- -- -- -- ∃x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F (s₀͍₂ v₀ v₁) (s₁͍₂ v₁ v₂) v₂
-- -- -- -- F v₀ ⊗ G v₀ ⟿ F v₀ ⊗ G v₀
-- -- -- -- ∀x(F x v₀ v₁) ⊗ ∀x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₂ v₃ ⊗ G v₁ (s₀͍₂ v₀ v₃) v₃
-- -- -- -- ∀x(F x v₀ v₁) ⊗ ∃x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₁ v₂ ⊗ G (s₀͍₁ v₂) (s₁͍₂ (s₀͍₂ v₂) v₂) v₂
-- -- -- -- Φ₀ = ∃x(G x (s₀͍₂ x v₁) v₁) has alphabet of 2 variables, skolem functions: 0, 0, 1
-- -- -- -- this is existential {α₊ₛ} Φ₁, where
-- -- -- -- Φ₁ = G (s₀͍₂ v₀ v₁) (s₁͍₂ (s₀͍₂ v₀ v₁)) v₁
-- -- -- -- α₊ₛ = ⟨ 2 , 0 ∷ 0 ∷ 2 ∷ [] ⟩
-- -- -- -- maybe Φ₋₁ = ∀y∃x(G x (s₀͍₂ x v₀) v₀)
-- -- -- -- and Φ₋₂ = ∀z∀y∃x(G x (s₀͍₂ x z) z), finally having no free variables, but nevertheless having skolem functions! these are user-defined functions, so this notion of Alphabet is somehow wrong. we have also left out constants (i.e. user-defined skolem-functions of arity 0)
-- -- -- -- Instead, take the alphabet as defining
-- -- -- -- a stack of free variables
-- -- -- -- a matrix (triangle?) of skolem functions
-- -- -- -- Let's try to reverse Φ₁ from a Skolem to a 1st-order formula. Is there a unique way to do it?
-- -- -- -- Φ₀' = ∀x(G (s₀͍₂ x v₀) (s₁͍₂ (s₀͍₂ x v₀)) v₀
-- -- -- -- Nope!
-- -- -- -- toSkolemFormula of
-- -- -- -- -}
-- -- -- -- -- toSkolemFormula (logical Φ₁ Φ₂) ⟿
-- -- -- -- -- let α' , φ₁ = toSkolemFormula Φ₁
-- -- -- -- -- Φ₂' = transcodeToAugmentedAlphabet Φ₂ α'
-- -- -- -- -- α'' , φ₂' = toSkolemFormula Φ₂'
-- -- -- -- -- φ₁' = transcodeToAugmentedAlphabet φ₁ α''
-- -- -- -- {-
-- -- -- -- given Δv = #varibles α' - #variables α
-- -- -- -- for every variable v in α, v in Φ, v stays the same in Φ'
-- -- -- -- for the added variable v⁺ in α₊ - α, v⁺ in Φ, v⁺ ⟿ v⁺ + Δv in transcode (universal {α₊} Φ)
-- -- -- -- α'₊ = α' + 1 variable
-- -- -- -- -}
-- -- -- -- -- record AddVariable (A : Alphabet → Set) : Set where
-- -- -- -- -- field
-- -- -- -- -- addVariableToAlphabet : {α : Alphabet} → A α → {α₊ : Alphabet} → Alphabet₊ᵥ α₊ → A α₊
-- -- -- -- -- instance
-- -- -- -- -- AddVariableFirstOrderFormula : AddVariable FirstOrderFormula
-- -- -- -- -- AddVariableFirstOrderFormula = {!!}
-- -- -- -- -- #variables = number ∘ variables
-- -- -- -- -- #functions_ofArity_ : Alphabet → Nat → Nat
-- -- -- -- -- #functions α⟨ V⟨ #variables ⟩ , S⟨ #functions ⟩ ⟩ ofArity arity = if′ lessNat arity (suc #variables) then #functions (natToFin arity) else 0
-- -- -- -- -- record _⊇_ (α' α : Alphabet) : Set where
-- -- -- -- -- field
-- -- -- -- -- at-least-as-many-variables : #variables α' ≥ #variables α
-- -- -- -- -- at-least-as-many-functions : ∀ {arity} → arity < #variables α → #functions α' ofArity arity ≥ #functions α ofArity arity
-- -- -- -- -- record AddAlphabet (α-top α-bottom : Alphabet) : Set where
-- -- -- -- -- field
-- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- record Transcodeable (A : Alphabet → Set) : Set where
-- -- -- -- -- field
-- -- -- -- -- transcode : {α' α : Alphabet} → ⦃ _ : α' ⊇ α ⦄ → A α → A α'
-- -- -- -- -- open Transcodeable ⦃ … ⦄
-- -- -- -- -- record TransferAlphabet {α' α : Alphabet} (α'⊇α : α' ⊇ α) (α₊ : Alphabet₊ᵥ α) (Φ : FirstOrderFormula (alphabet α₊)) : Set where
-- -- -- -- -- field
-- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- firstOrderFormula : FirstOrderFormula alphabet
-- -- -- -- -- instance
-- -- -- -- -- TranscodeablePredication : Transcodeable Predication
-- -- -- -- -- TranscodeablePredication = {!!}
-- -- -- -- -- TranscodeableAlphabet+Variable : Transcodeable Alphabet₊ᵥ
-- -- -- -- -- TranscodeableAlphabet+Variable = {!!}
-- -- -- -- -- TranscodeableSkolemFormula : Transcodeable SkolemFormula
-- -- -- -- -- TranscodeableSkolemFormula = {!!}
-- -- -- -- -- TranscodeableFirstOrderFormula : Transcodeable FirstOrderFormula
-- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (atomic p) = atomic (transcode p)
-- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (logical Φ₁ Φ₂) = logical (transcode Φ₁) (transcode Φ₂)
-- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula {α'} {α} ⦃ α'⊇α ⦄ (universal {α₊} Φ) = {!!} -- universal {_} {_} {transcode α₊} (transcode Φ)
-- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (existential Φ) = {!!}
-- -- -- -- -- --(α' α : Alphabet) (α'⊇α : α' ⊇ α) (α₊ : Alphabet+Variable α) (Φ : FirstOrderFormula (alphabet α₊)) → Σ _ λ (α''' : Alphabet) → FirstOrderFormula α'''
-- -- -- -- -- --FirstOrderFormula (alphabet α₊)
-- -- -- -- -- {-
-- -- -- -- -- -}
-- -- -- -- -- -- --transcodeIntoAugmentedAlphabet :
-- -- -- -- -- -- --toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- --record IsEquivalentFormulas {α₀ : Alphabet} (φ₀ : SkolemFormula α₀) {α₁ : Alphabet} (Φ₁ : FirstOrderFormula α₁) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- .atomicCase : {p : Predication α₀} → φ₀ ≡ atomic p → Φ₁ ≡ atomic p
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- record Alphabet+Alphabet (α₀ α₁ α₂ : Alphabet) : Set where
-- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- alphabet :
-- -- -- -- -- -- -- -- ∀xφ₁(x) ⊗ φ₂ ⟿ ∀x(φ₁ ⊗ φ₂)
-- -- -- -- -- -- -- -- hasQuantifiers : FirstOrderFormula α → Bool
-- -- -- -- -- -- -- --record Skolemization {α : Alphabet} (φ : FirstOrderFormula α) : Set where
-- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- -- skolemization : SkolemFormula alphabet
-- -- -- -- -- -- -- record _IsAugmentationOf_ (α₁ α₀ : Alphabet) : Set where
-- -- -- -- -- -- -- record AugmentedAlphabet (α : Alphabet) : Set where
-- -- -- -- -- -- -- constructor ⟨_⟩
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- ..laws : alphabet ≡ α
-- -- -- -- -- -- -- open AugmentedAlphabet
-- -- -- -- -- -- -- trivialAugmentation : (α : Alphabet) → AugmentedAlphabet α
-- -- -- -- -- -- -- trivialAugmentation = {!!}
-- -- -- -- -- -- -- record DisjointRelativeUnion {α : Alphabet} (α¹ α² : AugmentedAlphabet α) : Set where
-- -- -- -- -- -- -- constructor ⟨_⟩
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- augmentation : AugmentedAlphabet α
-- -- -- -- -- -- -- .laws : {!!}
-- -- -- -- -- -- -- open DisjointRelativeUnion
-- -- -- -- -- -- -- disjointRelativeUnion : {α : Alphabet} → (α¹ α² : AugmentedAlphabet α) → DisjointRelativeUnion α¹ α²
-- -- -- -- -- -- -- disjointRelativeUnion = {!!}
-- -- -- -- -- -- -- -- inAugmentedAlphabet : {α : Alphabet} → (α¹ : AugmentedAlphabet α) → SkolemFormula α → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- inAugmentedAlphabet = {!!}
-- -- -- -- -- -- -- -- toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- toSkolemFormula {α₀} (atomic 𝑃) = trivialAugmentation α₀ , atomic 𝑃
-- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) with toSkolemFormula φ₁ | toSkolemFormula φ₂
-- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) | α¹ , Φ₁ | α² , Φ₂ = augmentation (disjointRelativeUnion α¹ α²) , logical {!inAugmentedAlphabet (augmentation (disjointRelativeUnion α¹ α²)) Φ₁!} {!Φ₂!}
-- -- -- -- -- -- -- -- toSkolemFormula {α₀} (universal x) = {!!}
-- -- -- -- -- -- -- -- toSkolemFormula {α₀} (existential x) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ... | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- --VariableName = Fin ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- --FunctionArity = Fin ∘ suc ∘ size
-- -- -- -- -- -- -- -- -- -- -- --FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira)
-- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- |v| : Nat -- number of variables
-- -- -- -- -- -- -- -- -- -- -- -- |f| : Fin (suc |v|) → Nat -- number of functions of each arity, |v| through 0
-- -- -- -- -- -- -- -- -- -- -- -- open Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- VariableName = Fin ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- FunctionArity = Fin ∘ suc ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- variable : VariableName alphabet → Term alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {arity : FunctionArity alphabet} →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName alphabet (natToFin (|v| alphabet) - arity) →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀ {j : Size< i} → Vec (Term {j} alphabet) (finToNat arity) →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- Term {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateArity = Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateName = Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a zeroth-order formula? (i.e. no quantifiers)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- data NQFormula {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → NQFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → NQFormula {j} alphabet → {k : Size< i} → NQFormula {k} alphabet → NQFormula {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedByVariable (alphabet₀ alphabet₁ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- one-variable-is-added : |v| alphabet₁ ≡ suc (|v| alphabet₀)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- function-domain-is-zero-at-new-variable : |f| alphabet₁ zero ≡ 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → |f| alphabet₁ (suc ytira₁) ≡ |f| alphabet₀ ytira₀
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentVariables (alphabet₀ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet₁ : Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentation : AugmentedByVariable alphabet₀ alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- open AugmentVariables
-- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : (alphabet : Alphabet) → AugmentVariables alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables ⟨ |v| , |f| ⟩ =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record
-- -- -- -- -- -- -- -- -- -- -- -- -- -- { alphabet₁ = ⟨ suc |v| , (λ { zero → zero ; (suc ytira) → |f| ytira}) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ; augmentation =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record
-- -- -- -- -- -- -- -- -- -- -- -- -- -- { one-variable-is-added = refl
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ; function-domain-is-zero-at-new-variable = refl
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ; shifted-function-matches = cong |f| ∘ finToNat-inj } }
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |f|₀ = |f|₀ + 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions ⟨ |v| , |f| ⟩ = ⟨ |v| , (λ { zero → suc (|f| zero) ; (suc ytira) → |f| (suc ytira) }) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- data QFormula {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → QFormula {j} alphabet → {k : Size< i} → QFormula {k} alphabet → QFormula {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- universal : QFormula (alphabet₁ (augmentVariables alphabet)) → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- existential : QFormula (augmentFunctions alphabet) → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record Assignment (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- μ : VariableName alphabet → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑓 : ∀ {arity} → FunctionName alphabet arity → Vec Domain (finToNat arity) → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm : ∀ {i alphabet} → Assignment alphabet → Term {i} alphabet → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm ⟨ μ , _ ⟩ (variable x) = μ x
-- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm 𝑎@(⟨ μ , 𝑓 ⟩) (function f x) = 𝑓 f (evaluateTerm 𝑎 <$> x)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record Interpretation (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- open Assignment
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑎 : Assignment alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑃 : PredicateName → ∀ {arity} → Vec Domain arity → Bool
-- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula : ∀ {i alphabet} → Interpretation alphabet → NQFormula {i} alphabet → Bool
-- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula ⟨ 𝑎 , 𝑃 ⟩ (atomic name terms) = 𝑃 name $ evaluateTerm 𝑎 <$> terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula I (logical formula₁ formula₂) = not (evaluateNQFormula I formula₁) && not (evaluateNQFormula I formula₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ... | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record IsADisjointUnionOfNQFormulas
-- -- -- -- -- -- -- -- -- -- -- -- -- -- {alphabet₁ alphabet₂ alphabet₁₊₂ : Alphabet}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁ : NQFormula alphabet₁)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₂ : NQFormula alphabet₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁₊₂ : NQFormula alphabet₁₊₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet-size : |v| alphabet₁₊₂ ≡ |v| alphabet₁ + |v| alphabet₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --|f| alphabet₁₊₂ ytira
-- -- -- -- -- -- -- -- -- -- -- -- -- -- ----record AlphabetSummed (alphabet₀ alphabet₁ : Alphabet)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets : Alphabet → Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets ⟨ |v|₁ , |f|₁ ⟩ ⟨ |v|₂ , |f|₂ ⟩ = ⟨ (|v|₁ + |v|₂) , (λ x → if′ finToNat x ≤? |v|₁ && finToNat x ≤? |v|₂ then {!!} else {!!}) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup : ∀ {alphabet₁} → Formula alphabet₁ → ∀ {alphabet₂} → Formula alphabet₂ → Σ _ λ alphabet₁₊₂ → Formula alphabet₁₊₂ × Formula alphabet₁₊₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup {⟨ |v|₁ , |a|₁ , |f|₁ ⟩} φ₁ {⟨ |v|₂ , |a|₂ , |f|₂ ⟩} φ₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf : ∀ {alphabet} → Formula alphabet → Σ _ λ alphabet+ → Formula₀ alphabet+
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --universal (P 0) = ∀ x → P x
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (∀ x ∃ y (P x y)) ∨ (∀ x ∃ y (P x y))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- P x₀ (s₀͍₁ x₀) ∨ P x₁ (s₁͍₁ x₁)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| : (arity : Arity) → Vec ℕ (suc |a|) → Vec ℕ (++arity (max arity |a|))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a variable to the alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN : ∀ {n} → Fin n → (Fin n → Nat) → Fin n → Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedFunctions {|a| : Arity} (arity : Arity) (|f| : Vec ℕ (++arity |a|)) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA : ℕ
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA-law : max arity |a| ≡ maxA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ++|f| : Vec ℕ maxA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- f-law : increaseTabulationAt arity (indexVec |f|)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- define
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ⊗ b ≡ False a and False b
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- now, we can define
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ¬a = a ⊗ a ≡ False a and False a
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∨ b = ¬(a ⊗ b) ≡ False (False a and False b) and False (False a and False b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∧ b = ¬(¬a ∨ ¬b) = ¬(¬(¬a ⊗ ¬b)) = ¬a ⊗ ¬b = False (False a and False a) and False (False b and False b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a → b = ¬a ∨ b = (a ⊗ a) ∨ b = ¬((a ⊗ a) ⊗ b) = ((a ⊗ a) ⊗ b) ⊗ ((a ⊗ a) ⊗ b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- conversion to prenex
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀xF ⊗ G ⟿ ∃x(F ⊗ wk(G))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∃xF ⊗ G ⟿ ∀x(F ⊗ wk(G))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∀xG ⟿ ∃x(wk(F) ⊗ G)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∃xG ⟿ ∀x(wk(F) ⊗ G)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ========================
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (a ⊗ ∀xB) ⊗ c ⟿ ∃x(wk(a) ⊗ B) ⊗ c ⟿ ∀x((wk(a) ⊗ B) ⊗ wk(c))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF : (arity : Arity) → ∀ {|a| : Arity} → Vec ℕ (++arity |a|) → Vec ℕ (++arity (max arity |a|))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- with decBool (lessNat |a| arity)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x with compare arity |a|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.(suc (k + arity))} |f| | yes x | less (diff k refl) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl with lessNat arity arity
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl | false = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF zero {.zero} |f| | yes true | equal refl | true = {!!} ∷ []
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF (suc arity) {.(suc arity)} |f| | yes true | equal refl | true = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x | greater gt = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x with decBool (lessNat arity |a|)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | yes x = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | no x = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- = case arity <? |a| of λ { false → {!!} ; true → {!!} }
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a function of a given arity to the alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Arity → Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions arity ⟨ |v| , |a| , |f| ⟩ = ⟨ |v| , max arity |a| , augmentF arity |f| ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data DomainSignifier : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- free : Nat → DomainSignifier
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartiallyAppliedFunction : Nat → Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constant : PartiallyAppliedFunction 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {n} → PartiallyAppliedFunction 0 → PartiallyAppliedFunction (suc n)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term = PartiallyAppliedFunction 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartialyAppliedPredicate : Nat → Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- statement : PartialyAppliedPredicate 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- partial : ∀
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Language : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Name = String
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Function : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- name : Name
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- number-of-arguments : Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Vec
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Function : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : Function →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Sentence : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- predication : Name →
-- -- -- -- {-
-- -- -- -- record Variables : Set where
-- -- -- -- constructor V⟨_⟩
-- -- -- -- field
-- -- -- -- number : Nat
-- -- -- -- open Variables
-- -- -- -- record Functions (υ : Variables) : Set where
-- -- -- -- constructor S⟨_⟩
-- -- -- -- field
-- -- -- -- number : Fin (suc (number υ)) → Nat
-- -- -- -- open Functions
-- -- -- -- record Alphabet : Set where
-- -- -- -- constructor α⟨_,_⟩
-- -- -- -- field
-- -- -- -- variables : Variables
-- -- -- -- functions : Functions variables
-- -- -- -- open Alphabet
-- -- -- -- record Variable (α : Alphabet) : Set where
-- -- -- -- constructor v⟨_⟩
-- -- -- -- field
-- -- -- -- name : Fin (number (variables α))
-- -- -- -- open Variable
-- -- -- -- record Function (α : Alphabet) : Set where
-- -- -- -- constructor s⟨_,_⟩
-- -- -- -- field
-- -- -- -- arity : Fin ∘ suc ∘ number ∘ variables $ α
-- -- -- -- name : Fin $ number (functions α) arity
-- -- -- -- open Function
-- -- -- -- data Term (𝑽 : Nat) : Set where
-- -- -- -- variable : Fin 𝑽 → Term 𝑽
-- -- -- -- function : (𝑓 : Function α) → {ι₋₁ : Size< ι₀} → Vec (Term {ι₋₁} α) (finToNat (arity 𝑓)) →
-- -- -- -- Term {ι₀} α
-- -- -- -- record Predication (alphabet : Alphabet) : Set where
-- -- -- -- constructor P⟨_,_,_⟩
-- -- -- -- field
-- -- -- -- name : Nat
-- -- -- -- arity : Nat
-- -- -- -- terms : Vec (Term alphabet) arity
-- -- -- -- open Predication
-- -- -- -- -}
| 46.070407
| 286
| 0.456326
|
0399f5bba390b7c0ca0176d4820316b2dccfa1b7
| 4,520
|
agda
|
Agda
|
src/Tactic/Nat/Subtract/Reflect.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Tactic/Nat/Subtract/Reflect.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Tactic/Nat/Subtract/Reflect.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Tactic.Nat.Subtract.Reflect where
open import Prelude
import Agda.Builtin.Nat as Builtin
open import Builtin.Reflection
open import Control.Monad.State
open import Control.Monad.Transformer
open import Tactic.Reflection
open import Tactic.Reflection.Quote
open import Tactic.Nat.Reflect
open import Tactic.Nat.Subtract.Exp
⟨suc⟩s : SubExp → SubExp
⟨suc⟩s (lit n) = lit (suc n)
⟨suc⟩s (lit n ⟨+⟩ e) = lit (suc n) ⟨+⟩ e
⟨suc⟩s e = lit 1 ⟨+⟩ e
freshS : Term → R SubExp
freshS t =
get >>= uncurry′ λ i Γ →
var i <$ put (suc i , (t , i) ∷ Γ)
pattern _`-_ x y = def (quote Builtin._-_) (vArg x ∷ vArg y ∷ [])
private
forceInstance : Name → Term → R ⊤
forceInstance i v = lift $ unify v (def₀ i)
forceNumber = forceInstance (quote NumberNat)
forceSemiring = forceInstance (quote SemiringNat)
forceSubtractive = forceInstance (quote SubtractiveNat)
termToSubExpR : Term → R SubExp
termToSubExpR (a `+ b) = _⟨+⟩_ <$> termToSubExpR a <*> termToSubExpR b
termToSubExpR (a `* b) = _⟨*⟩_ <$> termToSubExpR a <*> termToSubExpR b
termToSubExpR (a `- b) = _⟨-⟩_ <$> termToSubExpR a <*> termToSubExpR b
-- Handle unsolved instances
termToSubExpR (def (quote Semiring._+_) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ vArg a ∷ vArg b ∷ [])) = do
forceSemiring i
⦇ termToSubExpR a ⟨+⟩ termToSubExpR b ⦈
termToSubExpR (def (quote Semiring._*_) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ vArg a ∷ vArg b ∷ [])) = do
lift $ unify i (def₀ (quote SemiringNat))
⦇ termToSubExpR a ⟨*⟩ termToSubExpR b ⦈
termToSubExpR (def (quote Subtractive._-_) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ vArg a ∷ vArg b ∷ [])) = do
forceSubtractive i
⦇ termToSubExpR a ⟨-⟩ termToSubExpR b ⦈
termToSubExpR (def (quote Semiring.zro) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ [])) = do
forceSemiring i
pure (lit 0)
termToSubExpR (def (quote Semiring.one) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ [])) = do
forceSemiring i
pure (lit 1)
termToSubExpR (def (quote Number.fromNat) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ vArg a ∷ _ ∷ [])) = do
forceNumber i
termToSubExpR a
termToSubExpR `0 = pure (lit 0)
termToSubExpR (`suc a) = ⟨suc⟩s <$> termToSubExpR a
termToSubExpR (meta x _) = lift (blockOnMeta x)
termToSubExpR (lit (nat n)) = pure (lit n)
termToSubExpR unknown = fail
termToSubExpR t = do
lift $ ensureNoMetas t
just i ← gets (flip lookup t ∘ snd)
where nothing → freshS t
pure (var i)
termToSubEqR : Term → R (SubExp × SubExp)
termToSubEqR (lhs `≡ rhs) = _,_ <$> termToSubExpR lhs <*> termToSubExpR rhs
termToSubEqR (def (quote _≡_) (_ ∷ hArg (meta x _) ∷ _)) = lift (blockOnMeta x)
termToSubEqR _ = fail
termToSubEq : Term → TC (Maybe ((SubExp × SubExp) × List Term))
termToSubEq t = runR (termToSubEqR t)
pattern _`<_ a b = def (quote LessNat) (vArg a ∷ vArg b ∷ [])
termToSubEqnR : Term → R Eqn
termToSubEqnR (def (quote Ord._<_) (_ ∷ _ ∷ vArg i@(meta _ _) ∷ vArg lhs ∷ vArg rhs ∷ [])) = do
forceInstance (quote OrdNat) i
⦇ termToSubExpR lhs :< termToSubExpR rhs ⦈
termToSubEqnR (lhs `< rhs) = _:<_ <$> termToSubExpR lhs <*> termToSubExpR rhs
termToSubEqnR (lhs `≡ rhs) = _:≡_ <$> termToSubExpR lhs <*> termToSubExpR rhs
termToSubEqnR (def (quote _≡_) (_ ∷ hArg (meta x _) ∷ _)) = lift (blockOnMeta x)
termToSubEqnR t = lift (ensureNoMetas t) *> fail
termToSubEqn : Term → TC (Maybe (Eqn × List Term))
termToSubEqn t = runR (termToSubEqnR t)
private
lower : Nat → Term → R Term
lower 0 = pure
lower i = liftMaybe ∘ strengthen i
termToSubHypsR′ : Nat → Term → R (List Eqn)
termToSubHypsR′ i (pi (vArg hyp) (abs _ a)) =
_∷_ <$> (termToSubEqnR =<< lower i hyp) <*> termToSubHypsR′ (suc i) a
termToSubHypsR′ _ (meta x _) = lift (blockOnMeta x)
termToSubHypsR′ i a = [_] <$> (termToSubEqnR =<< lower i a)
termToSubHypsR : Term → R (List Eqn)
termToSubHypsR = termToSubHypsR′ 0
termToSubHyps : Term → TC (Maybe (List Eqn × List Term))
termToSubHyps t = runR (termToSubHypsR t)
instance
QuotableSubExp : Quotable SubExp
` {{QuotableSubExp}} (var x) = con (quote SubExp.var) (vArg (` x) ∷ [])
` {{QuotableSubExp}} (lit n) = con (quote SubExp.lit) (vArg (` n) ∷ [])
` {{QuotableSubExp}} (e ⟨+⟩ e₁) = con (quote SubExp._⟨+⟩_) (map defaultArg $ ` e ∷ ` e₁ ∷ [])
` {{QuotableSubExp}} (e ⟨-⟩ e₁) = con (quote SubExp._⟨-⟩_) (map defaultArg $ ` e ∷ ` e₁ ∷ [])
` {{QuotableSubExp}} (e ⟨*⟩ e₁) = con (quote SubExp._⟨*⟩_) (map defaultArg $ ` e ∷ ` e₁ ∷ [])
QuotableEqn : Quotable Eqn
` {{QuotableEqn}} (a :≡ b) = con (quote _:≡_) (vArg (` a) ∷ vArg (` b) ∷ [])
` {{QuotableEqn}} (a :< b) = con (quote _:<_) (vArg (` a) ∷ vArg (` b) ∷ [])
| 38.305085
| 99
| 0.645796
|
210619529f42c28a94de6efa1b5df1c1f6b3a439
| 1,164
|
agda
|
Agda
|
notes/code-sketches/agda/src/Punctaffy/Hypersnippet/Dim.agda
|
rocketnia/lexmeta
|
2a958bf3987459e9197eb5963fe5107ea2e2e912
|
[
"Apache-2.0"
] | 1
|
2020-02-03T21:26:07.000Z
|
2020-02-03T21:26:07.000Z
|
notes/code-sketches/agda/src/Punctaffy/Hypersnippet/Dim.agda
|
rocketnia/lexmeta
|
2a958bf3987459e9197eb5963fe5107ea2e2e912
|
[
"Apache-2.0"
] | 13
|
2021-03-12T03:11:01.000Z
|
2022-03-06T14:40:21.000Z
|
notes/code-sketches/agda/src/Punctaffy/Hypersnippet/Dim.agda
|
rocketnia/lexmeta
|
2a958bf3987459e9197eb5963fe5107ea2e2e912
|
[
"Apache-2.0"
] | null | null | null |
module Punctaffy.Hypersnippet.Dim where
open import Level using (Level; suc; _⊔_)
open import Algebra.Bundles using (IdempotentCommutativeMonoid)
open import Algebra.Morphism using (IsIdempotentCommutativeMonoidMorphism)
-- For all the purposes we have for it so far, a `DimSys` is a bounded
-- semilattice. The `agda-stdlib` library calls this an idempotent commutative
-- monoid.
record DimSys {n l : Level} : Set (suc (n ⊔ l)) where
field
dimIdempotentCommutativeMonoid : IdempotentCommutativeMonoid n l
open IdempotentCommutativeMonoid dimIdempotentCommutativeMonoid public
record DimSysMorphism {n₀ n₁ l₀ l₁ : Level} : Set (suc (n₀ ⊔ n₁ ⊔ l₀ ⊔ l₁)) where
field
From : DimSys {n₀} {l₀}
To : DimSys {n₁} {l₁}
private
module F = DimSys From
module T = DimSys To
field
morphDim : F.Carrier → T.Carrier
isIdempotentCommutativeMonoidMorphism :
IsIdempotentCommutativeMonoidMorphism F.dimIdempotentCommutativeMonoid T.dimIdempotentCommutativeMonoid morphDim
dimLte : {n l : Level} → {ds : DimSys {n} {l}} → DimSys.Carrier ds → DimSys.Carrier ds → Set l
dimLte {n} {l} {ds} a b = DimSys._≈_ ds (DimSys._∙_ ds a b) b
| 36.375
| 118
| 0.736254
|
582e5e3be2c5b1d05a11c5c9d398b8dad795eb98
| 1,470
|
agda
|
Agda
|
src/Categories/Adjoint/AFT/SolutionSet.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Adjoint/AFT/SolutionSet.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Adjoint/AFT/SolutionSet.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor
module Categories.Adjoint.AFT.SolutionSet {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Functor C D) where
open import Level
private
module C = Category C
module D = Category D
module F = Functor F
open D
open F
record SolutionSet i : Set (o ⊔ ℓ ⊔ o′ ⊔ ℓ′ ⊔ e′ ⊔ (suc i)) where
field
I : Set i
S : I → C.Obj
S₀ : ∀ {A X} → X ⇒ F₀ A → I
S₁ : ∀ {A X} (f : X ⇒ F₀ A) → S (S₀ f) C.⇒ A
ϕ : ∀ {A X} (f : X ⇒ F₀ A) → X ⇒ F₀ (S (S₀ f))
commute : ∀ {A X} (f : X ⇒ F₀ A) → F₁ (S₁ f) ∘ ϕ f ≈ f
record SolutionSet′ : Set (o ⊔ ℓ ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
S₀ : ∀ {A X} → X ⇒ F₀ A → C.Obj
S₁ : ∀ {A X} (f : X ⇒ F₀ A) → S₀ f C.⇒ A
ϕ : ∀ {A X} (f : X ⇒ F₀ A) → X ⇒ F₀ (S₀ f)
commute : ∀ {A X} (f : X ⇒ F₀ A) → F₁ (S₁ f) ∘ ϕ f ≈ f
SolutionSet⇒SolutionSet′ : ∀ {i} → SolutionSet i → SolutionSet′
SolutionSet⇒SolutionSet′ s = record
{ S₀ = λ f → S (S₀ f)
; S₁ = S₁
; ϕ = ϕ
; commute = commute
}
where open SolutionSet s
SolutionSet′⇒SolutionSet : ∀ i → SolutionSet′ → SolutionSet (o ⊔ i)
SolutionSet′⇒SolutionSet i s = record
{ I = Lift i C.Obj
; S = lower
; S₀ = λ f → lift (S₀ f)
; S₁ = S₁
; ϕ = ϕ
; commute = commute
}
where open SolutionSet′ s
| 27.222222
| 103
| 0.485034
|
29124991e6cbd6c1f02c6e916c0b714521b46fee
| 297
|
agda
|
Agda
|
test/Succeed/Issue2302.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue2302.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2302.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Equality
postulate
A : Set
x0 : A
f : A → A → A
{-# BUILTIN REWRITE _≡_ #-}
postulate
fxx : (x : A) → (f x x) ≡ x
{-# REWRITE fxx #-}
meta : A
meta-reveal : meta ≡ x0
test : f x0 meta ≡ x0
meta = _
test = refl
meta-reveal = refl
| 12.375
| 33
| 0.572391
|
2193a8a9997e570154564ab397a2b4abd64e7227
| 187
|
agda
|
Agda
|
test/Fail/PatternSynonymOverloaded.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/PatternSynonymOverloaded.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/PatternSynonymOverloaded.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module PatternSynonymOverloaded where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
pattern ss x = suc (suc x)
pattern ss x = suc x
foo : Nat → Nat
foo (ss n) = n
foo _ = zero
| 14.384615
| 37
| 0.647059
|
5e419cacf5de1ec1de80e6e8e373ca309dc0b92f
| 49,970
|
agda
|
Agda
|
src/FOmegaInt/Kinding/Canonical.agda
|
Blaisorblade/f-omega-int-agda
|
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
|
[
"MIT"
] | 12
|
2017-06-13T16:05:35.000Z
|
2021-09-27T05:53:06.000Z
|
src/FOmegaInt/Kinding/Canonical.agda
|
Blaisorblade/f-omega-int-agda
|
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
|
[
"MIT"
] | 1
|
2021-05-14T08:09:40.000Z
|
2021-05-14T08:54:39.000Z
|
src/FOmegaInt/Kinding/Canonical.agda
|
Blaisorblade/f-omega-int-agda
|
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
|
[
"MIT"
] | 2
|
2021-05-13T22:29:48.000Z
|
2021-05-14T10:25:05.000Z
|
------------------------------------------------------------------------
-- Canonical kinding of Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Kinding.Canonical where
open import Data.Context.WellFormed
open import Data.Fin using (Fin; zero; suc)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Fin.Substitution.Typed
open import Data.List using ([]; _∷_; _∷ʳ_)
open import Data.Product using (∃; _,_; _×_)
open import Data.Vec as Vec using ([])
open import Level using () renaming (zero to lzero)
open import Relation.Binary.PropositionalEquality
open import FOmegaInt.Syntax
open import FOmegaInt.Syntax.HereditarySubstitution
open import FOmegaInt.Syntax.Normalization
import FOmegaInt.Kinding.Simple as SimpleKinding
------------------------------------------------------------------------
-- Canonical kinding derivations.
--
-- TODO: explain the point of this and how "canonical" kinding differs
-- from "algorithmic" kinding.
--
-- NOTE. In the rules below, we use (singleton) kind synthesis
-- judgments of the form `Γ ⊢Nf a ⇉ a ⋯ a' to ensure that `a' is a
-- well-kinded proper type rather than kind checking judgments of the
-- form `Γ ⊢Nf a ⇇ *'. While the latter may seem more natural, it
-- involves the use of subsumption/subtyping to ensure that `Γ ⊢ a ⋯ a
-- <∷ *'. As we will show, this is always true (if `a' is indeed a
-- proper type) but the extra use of subsumption complicates the
-- proofs of properties that require (partial) inversion of kinding
-- derivations. See e.g. the Nf⇉-⋯-* and Nf⇇-⋯-* lemmas.
module Kinding where
open ElimCtx
open Syntax
infix 4 _⊢_wf _ctx _⊢_kd
infix 4 _⊢Nf_⇉_ _⊢Ne_∈_ _⊢Var_∈_ _⊢_⇉∙_⇉_ _⊢Nf_⇇_
infix 4 _⊢_<∷_ _⊢_<:_ _⊢_<:_⇇_
infix 4 _⊢_≅_ _⊢_≃_⇇_ _⊢_⇉∙_≃_⇉_
mutual
-- Well-formed type/kind ascriptions in typing contexts.
--
-- A raw kind ascriptions is considered well-formed if it
-- corresponds to a well-formed normal kind. Raw type ascriptions
-- are are considered well-formed if they correspond to proper
-- normal types.
data _⊢_wf {n} (Γ : Ctx n) : ElimAsc n → Set where
wf-kd : ∀ {a} → Γ ⊢ a kd → Γ ⊢ kd a wf
wf-tp : ∀ {a} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢ tp a wf
-- Well-formed typing contexts.
--
-- Contexts and context extensions are well-formed if all the
-- ascriptions they contain are well-formed.
_ctx : ∀ {n} → Ctx n → Set
Γ ctx = ContextFormation._wf _⊢_wf Γ
-- Well-formedness checking for η-long β-normal kinds.
data _⊢_kd {n} (Γ : Ctx n) : Kind Elim n → Set where
kd-⋯ : ∀ {a b} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢Nf b ⇉ b ⋯ b → Γ ⊢ a ⋯ b kd
kd-Π : ∀ {j k} → Γ ⊢ j kd → kd j ∷ Γ ⊢ k kd → Γ ⊢ Π j k kd
-- Kind synthesis for η-long β-normal types.
data _⊢Nf_⇉_ {n} (Γ : Ctx n) : Elim n → Kind Elim n → Set where
⇉-⊥-f : Γ ctx → Γ ⊢Nf ⊥∙ ⇉ ⊥∙ ⋯ ⊥∙
⇉-⊤-f : Γ ctx → Γ ⊢Nf ⊤∙ ⇉ ⊤∙ ⋯ ⊤∙
⇉-∀-f : ∀ {k a} → Γ ⊢ k kd → kd k ∷ Γ ⊢Nf a ⇉ a ⋯ a →
Γ ⊢Nf ∀∙ k a ⇉ ∀∙ k a ⋯ ∀∙ k a
⇉-→-f : ∀ {a b} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢Nf b ⇉ b ⋯ b →
Γ ⊢Nf a ⇒∙ b ⇉ a ⇒∙ b ⋯ a ⇒∙ b
⇉-Π-i : ∀ {j a k} → Γ ⊢ j kd → kd j ∷ Γ ⊢Nf a ⇉ k → Γ ⊢Nf Λ∙ j a ⇉ Π j k
⇉-s-i : ∀ {a b c} → Γ ⊢Ne a ∈ b ⋯ c → Γ ⊢Nf a ⇉ a ⋯ a
-- Canonical kinding of neutral types.
--
-- NOTE. This is *not* a kind synthesis judgment! See the
-- comment on canonical variable kinding for an explanation.
data _⊢Ne_∈_ {n} (Γ : Ctx n) : Elim n → Kind Elim n → Set where
∈-∙ : ∀ {x j k} {as : Spine n} → Γ ⊢Var x ∈ j →
Γ ⊢ j ⇉∙ as ⇉ k → Γ ⊢Ne var x ∙ as ∈ k
-- Canonical kinding of variables.
--
-- NOTE. This would be a kind synthesis judgment if it weren't
-- for the subsumption rule (⇇-⇑). Thanks to this rule, the proof
-- of the "context narrowing" property is easy to establish for
-- canonical typing (see the ContextNarrowing module below).
-- Without a proof of this property, the various lemmas about
-- kinded hereditary substitutions become difficult to establish
-- (see Kinding.HereditarySubstitution). Unfortunately, proving
-- that context narrowing is admissible *without* (⇇-⇑) would
-- require precisely these substitution lemmas, leading to a
-- cyclic dependency. Introducing the subsumption rule for
-- variables thus allows us to break that cycle. On the other
-- hand, the subsumption rule breaks functionality of the
-- canonical kinding relations for variables and neutral types,
-- i.e. their canonical kinds are no longer unique. This is
-- partly remedied by the singleton-introduction rule (⇉-s-i) in
-- the kind synthesis judgment for normal types: neutrals have
-- unique (singleton) kinds when viewed as normal forms. However,
-- neutral kinding is also used in subtyping, in particular by the
-- bound projection rules (<:-⟨|) and (<:-|⟩). Because the kinds
-- of neutrals are not unique, neither are the bounds projected by
-- these subtyping rules, and eliminating adjacent instances of
-- (<:-⟨|) and (<:-|⟩) becomes difficult. This, in turn,
-- complicates transitivity elimination (i.e. a proof that
-- transitivity of subtyping is admissible) in arbitrary contexts.
-- However, it does not affect elimination of *top-level*
-- occurrences of the transitivity rule (<:-trans), i.e. those in
-- the empty contexts, because there are no closed neutral terms,
-- and therefore no instances of the bound projection rules in
-- top-level subtyping statements.
data _⊢Var_∈_ {n} (Γ : Ctx n) : Fin n → Kind Elim n → Set where
⇉-var : ∀ {k} x → Γ ctx → lookup Γ x ≡ kd k → Γ ⊢Var x ∈ k
⇇-⇑ : ∀ {x j k} → Γ ⊢Var x ∈ j → Γ ⊢ j <∷ k → Γ ⊢ k kd →
Γ ⊢Var x ∈ k
-- Kind synthesis for spines: given the kind of the head and a
-- spine, synthesize the overall kind of the elimination.
data _⊢_⇉∙_⇉_ {n} (Γ : Ctx n)
: Kind Elim n → Spine n → Kind Elim n → Set where
⇉-[] : ∀ {k} → Γ ⊢ k ⇉∙ [] ⇉ k
⇉-∷ : ∀ {a as j k l} → Γ ⊢Nf a ⇇ j → Γ ⊢ j kd →
Γ ⊢ k Kind[ a ∈ ⌊ j ⌋ ] ⇉∙ as ⇉ l →
Γ ⊢ Π j k ⇉∙ a ∷ as ⇉ l
-- Kind checking for η-long β-normal types.
data _⊢Nf_⇇_ {n} (Γ : Ctx n) : Elim n → Kind Elim n → Set where
⇇-⇑ : ∀ {a j k} → Γ ⊢Nf a ⇉ j → Γ ⊢ j <∷ k → Γ ⊢Nf a ⇇ k
-- Canonical subkinding derivations.
data _⊢_<∷_ {n} (Γ : Ctx n) : Kind Elim n → Kind Elim n → Set where
<∷-⋯ : ∀ {a₁ a₂ b₁ b₂} →
Γ ⊢ a₂ <: a₁ → Γ ⊢ b₁ <: b₂ → Γ ⊢ a₁ ⋯ b₁ <∷ a₂ ⋯ b₂
<∷-Π : ∀ {j₁ j₂ k₁ k₂} →
Γ ⊢ j₂ <∷ j₁ → kd j₂ ∷ Γ ⊢ k₁ <∷ k₂ → Γ ⊢ Π j₁ k₁ kd →
Γ ⊢ Π j₁ k₁ <∷ Π j₂ k₂
-- Canonical subtyping of proper types.
data _⊢_<:_ {n} (Γ : Ctx n) : Elim n → Elim n → Set where
<:-trans : ∀ {a b c} → Γ ⊢ a <: b → Γ ⊢ b <: c → Γ ⊢ a <: c
<:-⊥ : ∀ {a} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢ ⊥∙ <: a
<:-⊤ : ∀ {a} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢ a <: ⊤∙
<:-∀ : ∀ {k₁ k₂ a₁ a₂} →
Γ ⊢ k₂ <∷ k₁ → kd k₂ ∷ Γ ⊢ a₁ <: a₂ →
Γ ⊢Nf ∀∙ k₁ a₁ ⇉ ∀∙ k₁ a₁ ⋯ ∀∙ k₁ a₁ →
Γ ⊢ ∀∙ k₁ a₁ <: ∀∙ k₂ a₂
<:-→ : ∀ {a₁ a₂ b₁ b₂} →
Γ ⊢ a₂ <: a₁ → Γ ⊢ b₁ <: b₂ → Γ ⊢ a₁ ⇒∙ b₁ <: a₂ ⇒∙ b₂
<:-∙ : ∀ {x as₁ as₂ k b c} →
Γ ⊢Var x ∈ k → Γ ⊢ k ⇉∙ as₁ ≃ as₂ ⇉ b ⋯ c →
Γ ⊢ var x ∙ as₁ <: var x ∙ as₂
<:-⟨| : ∀ {a b c} → Γ ⊢Ne a ∈ b ⋯ c → Γ ⊢ b <: a
<:-|⟩ : ∀ {a b c} → Γ ⊢Ne a ∈ b ⋯ c → Γ ⊢ a <: c
-- Checked/kind-driven subtyping.
data _⊢_<:_⇇_ {n} (Γ : Ctx n) : Elim n → Elim n → Kind Elim n → Set where
<:-⇇ : ∀ {a b c d} → Γ ⊢Nf a ⇇ c ⋯ d → Γ ⊢Nf b ⇇ c ⋯ d →
Γ ⊢ a <: b → Γ ⊢ a <: b ⇇ c ⋯ d
<:-λ : ∀ {j₁ j₂ a₁ a₂ j k} → kd j ∷ Γ ⊢ a₁ <: a₂ ⇇ k →
Γ ⊢Nf Λ∙ j₁ a₁ ⇇ Π j k → Γ ⊢Nf Λ∙ j₂ a₂ ⇇ Π j k →
Γ ⊢ Λ∙ j₁ a₁ <: Λ∙ j₂ a₂ ⇇ Π j k
-- Canonical kind equality.
data _⊢_≅_ {n} (Γ : Ctx n) : Kind Elim n → Kind Elim n → Set where
<∷-antisym : ∀ {j k} → Γ ⊢ j kd → Γ ⊢ k kd →
Γ ⊢ j <∷ k → Γ ⊢ k <∷ j → Γ ⊢ j ≅ k
-- Canonical type equality derivations with checked kinds.
data _⊢_≃_⇇_ {n} (Γ : Ctx n) : Elim n → Elim n → Kind Elim n → Set where
<:-antisym : ∀ {a b k} →
Γ ⊢ k kd → Γ ⊢ a <: b ⇇ k → Γ ⊢ b <: a ⇇ k → Γ ⊢ a ≃ b ⇇ k
-- Canonical equality of spines.
data _⊢_⇉∙_≃_⇉_ {n} (Γ : Ctx n)
: Kind Elim n → Spine n → Spine n → Kind Elim n → Set where
≃-[] : ∀ {k} → Γ ⊢ k ⇉∙ [] ≃ [] ⇉ k
≃-∷ : ∀ {a as b bs j k l} →
Γ ⊢ a ≃ b ⇇ j → Γ ⊢ k Kind[ a ∈ ⌊ j ⌋ ] ⇉∙ as ≃ bs ⇉ l →
Γ ⊢ Π j k ⇉∙ a ∷ as ≃ b ∷ bs ⇉ l
-- Well-formed context extensions.
open ContextFormation _⊢_wf public
hiding (_wf) renaming (_⊢_wfExt to _⊢_ext)
-- A wrapper for the _⊢Var_∈_ judgment that also provides term
-- variable bindings.
infix 4 _⊢Var′_∈_
data _⊢Var′_∈_ {n} (Γ : Ctx n) : Fin n → ElimAsc n → Set where
∈-tp : ∀ {x k} → Γ ⊢Var x ∈ k → Γ ⊢Var′ x ∈ kd k
∈-tm : ∀ x {a} → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢Var′ x ∈ tp a
-- A derived variable rule.
∈-var′ : ∀ {n} {Γ : Ctx n} x → Γ ctx → Γ ⊢Var′ x ∈ lookup Γ x
∈-var′ {Γ = Γ} x Γ-ctx with lookup Γ x | inspect (lookup Γ) x
∈-var′ x Γ-ctx | kd k | [ Γ[x]≡kd-k ] = ∈-tp (⇉-var x Γ-ctx Γ[x]≡kd-k)
∈-var′ x Γ-ctx | tp a | [ Γ[x]≡tp-a ] = ∈-tm x Γ-ctx Γ[x]≡tp-a
------------------------------------------------------------------------
-- Simple properties of canonical kindings
open Syntax
open ElimCtx
open SimpleCtx using (kd; tp; ⌊_⌋Asc)
open Kinding
open ContextConversions using (⌊_⌋Ctx; module ⌊⌋Ctx-Lemmas)
-- An inversion lemma for _⊢_wf.
wf-kd-inv : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ kd k wf → Γ ⊢ k kd
wf-kd-inv (wf-kd k-kd) = k-kd
-- Subkinds have the same shape.
<∷-⌊⌋ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → ⌊ j ⌋ ≡ ⌊ k ⌋
<∷-⌊⌋ (<∷-⋯ _ _) = refl
<∷-⌊⌋ (<∷-Π j₂<∷j₁ k₁<∷k₂ _) = cong₂ _⇒_ (sym (<∷-⌊⌋ j₂<∷j₁)) (<∷-⌊⌋ k₁<∷k₂)
-- Equal kinds have the same shape.
≅-⌊⌋ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → ⌊ j ⌋ ≡ ⌊ k ⌋
≅-⌊⌋ (<∷-antisym j-kd k-kd j<∷k k<∷j) = <∷-⌊⌋ j<∷k
-- Kind and type equality imply subkinding and subtyping, respectively.
≅⇒<∷ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j <∷ k
≅⇒<∷ (<∷-antisym j-kd k-kd j<∷k k<∷j) = j<∷k
≃⇒<: : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ⇇ k → Γ ⊢ a <: b ⇇ k
≃⇒<: (<:-antisym k-kd a<:b⇇k b<:a⇇k) = a<:b⇇k
≃⇒<:-⋯ : ∀ {n} {Γ : Ctx n} {a b c d} → Γ ⊢ a ≃ b ⇇ c ⋯ d → Γ ⊢ a <: b
≃⇒<:-⋯ (<:-antisym c⋯d-kd (<:-⇇ a⇇c⋯d b⇇c⋯d a<:b) b<:a⇇c⋯d) = a<:b
-- Symmetry of kind and type equality.
≅-sym : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ k ≅ j
≅-sym (<∷-antisym j-kd k-kd j<:k k<∷j) = <∷-antisym k-kd j-kd k<∷j j<:k
≃-sym : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ⇇ k → Γ ⊢ b ≃ a ⇇ k
≃-sym (<:-antisym k-kd a<:b b<:a) = <:-antisym k-kd b<:a a<:b
-- Transitivity of checked subtyping and type equality are admissible.
<:⇇-trans : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢ a <: b ⇇ k → Γ ⊢ b <: c ⇇ k → Γ ⊢ a <: c ⇇ k
<:⇇-trans (<:-⇇ a₁⇇b⋯c _ a₁<:a₂) (<:-⇇ _ a₃⇇b⋯c a₂<:a₃) =
<:-⇇ a₁⇇b⋯c a₃⇇b⋯c (<:-trans a₁<:a₂ a₂<:a₃)
<:⇇-trans (<:-λ a₁<:a₂ Λj₁a₁⇇Πjk _) (<:-λ a₂<:a₃ _ Λj₃a₃⇇Πjk) =
<:-λ (<:⇇-trans a₁<:a₂ a₂<:a₃) Λj₁a₁⇇Πjk Λj₃a₃⇇Πjk
≃-trans : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢ a ≃ b ⇇ k → Γ ⊢ b ≃ c ⇇ k → Γ ⊢ a ≃ c ⇇ k
≃-trans (<:-antisym k-kd a<:b⇇k b<:a⇇k) (<:-antisym _ b<:c⇇k c<:b⇇k) =
<:-antisym k-kd (<:⇇-trans a<:b⇇k b<:c⇇k) (<:⇇-trans c<:b⇇k b<:a⇇k)
-- The synthesized kind of a normal proper type is exactly the singleton
-- containing that type.
Nf⇉-≡ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → a ≡ b × a ≡ c
Nf⇉-≡ (⇉-⊥-f Γ-ctx) = refl , refl
Nf⇉-≡ (⇉-⊤-f Γ-ctx) = refl , refl
Nf⇉-≡ (⇉-∀-f k-kd b⇉b⋯b) = refl , refl
Nf⇉-≡ (⇉-→-f a⇉a⋯a b⇉b⋯b) = refl , refl
Nf⇉-≡ (⇉-s-i a∈b⋯c) = refl , refl
-- Derived singleton introduction rules where the premises are
-- well-kinded normal forms rather than neutrals.
Nf⇉-s-i : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢Nf a ⇉ a ⋯ a
Nf⇉-s-i a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
Nf⇉-s-i a⇉a⋯a | refl , refl = a⇉a⋯a
Nf⇇-s-i : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢Nf a ⇉ a ⋯ a
Nf⇇-s-i (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂)) = Nf⇉-s-i a⇉b₁⋯c₁
-- Inhabitants of interval kinds are proper types.
Nf⇉-⋯-* : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢Nf a ⇇ ⌜*⌝
Nf⇉-⋯-* a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
Nf⇉-⋯-* a⇉a⋯a | refl , refl = ⇇-⇑ a⇉a⋯a (<∷-⋯ (<:-⊥ a⇉a⋯a) (<:-⊤ a⇉a⋯a))
Nf⇇-⋯-* : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢Nf a ⇇ ⌜*⌝
Nf⇇-⋯-* (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂)) = Nf⇉-⋯-* a⇉b₁⋯c₁
-- Validity of synthesized kinds: synthesized kinds are well-formed.
Nf⇉-valid : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → Γ ⊢ k kd
Nf⇉-valid (⇉-⊥-f Γ-ctx) = kd-⋯ (⇉-⊥-f Γ-ctx) (⇉-⊥-f Γ-ctx)
Nf⇉-valid (⇉-⊤-f Γ-ctx) = kd-⋯ (⇉-⊤-f Γ-ctx) (⇉-⊤-f Γ-ctx)
Nf⇉-valid (⇉-∀-f k-kd a⇉a⋯a) = kd-⋯ (⇉-∀-f k-kd a⇉a⋯a) (⇉-∀-f k-kd a⇉a⋯a)
Nf⇉-valid (⇉-→-f a⇉a⋯a b⇉b⋯b) = kd-⋯ (⇉-→-f a⇉a⋯a b⇉b⋯b) (⇉-→-f a⇉a⋯a b⇉b⋯b)
Nf⇉-valid (⇉-Π-i j-kd a⇉k) = kd-Π j-kd (Nf⇉-valid a⇉k)
Nf⇉-valid (⇉-s-i a∈b⋯c) = kd-⋯ (⇉-s-i a∈b⋯c) (⇉-s-i a∈b⋯c)
-- Validity of checked subtyping: the checked subtyping judgment
-- relates well-kinded types.
<:⇇-valid : ∀ {n} {Γ : Ctx n} {a b k} →
Γ ⊢ a <: b ⇇ k → Γ ⊢Nf a ⇇ k × Γ ⊢Nf b ⇇ k
<:⇇-valid (<:-⇇ a⇇k b⇇k a<:b) = a⇇k , b⇇k
<:⇇-valid (<:-λ a₁<:a₂ Λj₁a₁⇇Πjk Λj₂a₂⇇Πjk) = Λj₁a₁⇇Πjk , Λj₂a₂⇇Πjk
-- Validity of kind and type equality: the equality judgments relate
-- well-formed kinds, resp. well-kinded types.
≅-valid : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j kd × Γ ⊢ k kd
≅-valid (<∷-antisym j-kd k-kd j<∷k k<∷j) = j-kd , k-kd
≃-valid : ∀ {n} {Γ : Ctx n} {a b k} →
Γ ⊢ a ≃ b ⇇ k → Γ ⊢Nf a ⇇ k × Γ ⊢Nf b ⇇ k
≃-valid (<:-antisym k-kd a<:b⇇k b<:a⇇k) = <:⇇-valid a<:b⇇k
≃-valid-kd : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ⇇ k → Γ ⊢ k kd
≃-valid-kd (<:-antisym k-kd a<:b b<:a) = k-kd
-- NOTE. In order to prove validity for the remainder of the kinding,
-- subkinding and subtyping judgments, we first need to prove that
-- hereditary substitutions preserve well-formedness of kinds (see
-- Kinding.Canonical.HereditarySubstitution). See the definition of
-- `Var∈-valid' below and the module Kinding.Canonical.Validity for
-- the remaining (strong) validity lemmas.
-- The synthesized kinds of neutrals kind-check.
Nf⇇-ne : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Ne a ∈ b ⋯ c → Γ ⊢Nf a ⇇ b ⋯ c
Nf⇇-ne (∈-∙ x∈k k⇉as⇉b⋯c) =
⇇-⇑ (⇉-s-i (∈-∙ x∈k k⇉as⇉b⋯c))
(<∷-⋯ (<:-⟨| (∈-∙ x∈k k⇉as⇉b⋯c)) (<:-|⟩ (∈-∙ x∈k k⇉as⇉b⋯c)))
-- The contexts of (most of) the above judgments are well-formed.
--
-- NOTE. The exceptions are kinding and equality of spines, as the
-- ⇉-[] and ≃-[] rules offer no guarantee that the enclosing context
-- is well-formed. This is not a problem in practice, since
-- well-kinded spines are used in the kinding of neutral types, the
-- head of which is guaranteed to be kinded in a well-formed context.
mutual
kd-ctx : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ctx
kd-ctx (kd-⋯ a⇉a⋯a b⇉b⋯b) = Nf⇉-ctx a⇉a⋯a
kd-ctx (kd-Π j-kd k-kd) = kd-ctx j-kd
Nf⇉-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → Γ ctx
Nf⇉-ctx (⇉-⊥-f Γ-ctx) = Γ-ctx
Nf⇉-ctx (⇉-⊤-f Γ-ctx) = Γ-ctx
Nf⇉-ctx (⇉-∀-f k-kd a⇉a⋯a) = kd-ctx k-kd
Nf⇉-ctx (⇉-→-f a⇉a⋯a b⇉b⋯b) = Nf⇉-ctx a⇉a⋯a
Nf⇉-ctx (⇉-Π-i j-kd a⇉k) = kd-ctx j-kd
Nf⇉-ctx (⇉-s-i a∈b⋯c) = Ne∈-ctx a∈b⋯c
Ne∈-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Ne a ∈ k → Γ ctx
Ne∈-ctx (∈-∙ x∈j j⇉as⇉k) = Var∈-ctx x∈j
Var∈-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Var a ∈ k → Γ ctx
Var∈-ctx (⇉-var x Γ-ctx _) = Γ-ctx
Var∈-ctx (⇇-⇑ x∈j j<∷k k-kd) = Var∈-ctx x∈j
Nf⇇-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇇ k → Γ ctx
Nf⇇-ctx (⇇-⇑ a⇉j j<∷k) = Nf⇉-ctx a⇉j
mutual
<∷-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ctx
<∷-ctx (<∷-⋯ b₁<:a₁ a₂<:b₂) = <:-ctx b₁<:a₁
<∷-ctx (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) = <∷-ctx j₂<∷j₁
<:-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a <: b → Γ ctx
<:-ctx (<:-trans a<:b b<:c) = <:-ctx a<:b
<:-ctx (<:-⊥ a⇉a⋯a) = Nf⇉-ctx a⇉a⋯a
<:-ctx (<:-⊤ a⇉a⋯a) = Nf⇉-ctx a⇉a⋯a
<:-ctx (<:-∀ k₂<∷k₁ a₁<:a₂ _) = <∷-ctx k₂<∷k₁
<:-ctx (<:-→ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁
<:-ctx (<:-∙ x∈j as<:bs) = Var∈-ctx x∈j
<:-ctx (<:-⟨| a∈b⋯c) = Ne∈-ctx a∈b⋯c
<:-ctx (<:-|⟩ a∈b⋯c) = Ne∈-ctx a∈b⋯c
≅-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ctx
≅-ctx (<∷-antisym j-kd k-kd j<∷k k<∷j) = <∷-ctx j<∷k
wf-ctx : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → Γ ctx
wf-ctx (wf-kd k-kd) = kd-ctx k-kd
wf-ctx (wf-tp a⇉a⋯a) = Nf⇉-ctx a⇉a⋯a
<:⇇-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ⇇ k → Γ ctx
<:⇇-ctx (<:-⇇ a⇇k b⇇k a<:b) = Nf⇇-ctx a⇇k
<:⇇-ctx (<:-λ a₁<:a₂ Λj₁a₁⇇Πjk Λj₂a₂⇇Πjk) = Nf⇇-ctx Λj₁a₁⇇Πjk
≃-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ⇇ k → Γ ctx
≃-ctx (<:-antisym k-kd a<:b b<:a) = <:⇇-ctx a<:b
Var′∈-ctx : ∀ {n} {Γ : Ctx n} {x a} → Γ ⊢Var′ x ∈ a → Γ ctx
Var′∈-ctx (∈-tp x∈k) = Var∈-ctx x∈k
Var′∈-ctx (∈-tm _ Γ-ctx _) = Γ-ctx
-- An admissible formation rule for the kind of proper types.
kd-⌜*⌝ : ∀ {n} {Γ : Ctx n} → Γ ctx → Γ ⊢ ⌜*⌝ kd
kd-⌜*⌝ Γ-ctx = kd-⋯ (⇉-⊥-f Γ-ctx) (⇉-⊤-f Γ-ctx)
-- Admissible formation rules for canonically kinded proper types.
Nf⇇-∀-f : ∀ {n} {Γ : Ctx n} {k a} →
Γ ⊢ k kd → kd k ∷ Γ ⊢Nf a ⇇ ⌜*⌝ → Γ ⊢Nf ∀∙ k a ⇇ ⌜*⌝
Nf⇇-∀-f k-kd a⇇* =
let a⇉a⋯a = Nf⇇-s-i a⇇*
in Nf⇉-⋯-* (⇉-∀-f k-kd a⇉a⋯a)
Nf⇇-→-f : ∀ {n} {Γ : Ctx n} {a b} →
Γ ⊢Nf a ⇇ ⌜*⌝ → Γ ⊢Nf b ⇇ ⌜*⌝ → Γ ⊢Nf a ⇒∙ b ⇇ ⌜*⌝
Nf⇇-→-f a⇇* b⇇* =
let a⇉a⋯a = Nf⇇-s-i a⇇*
b⇉b⋯b = Nf⇇-s-i b⇇*
in Nf⇉-⋯-* (⇉-→-f a⇉a⋯a b⇉b⋯b)
-- Admissible kinding and equality rules for appending a normal form
-- to a spine.
⇉-∷ʳ : ∀ {n} {Γ : Ctx n} {as : Spine n} {a j k l} →
Γ ⊢ j ⇉∙ as ⇉ Π k l → Γ ⊢Nf a ⇇ k → Γ ⊢ k kd →
Γ ⊢ j ⇉∙ as ∷ʳ a ⇉ l Kind[ a ∈ ⌊ k ⌋ ]
⇉-∷ʳ ⇉-[] a⇇k k-kd = ⇉-∷ a⇇k k-kd ⇉-[]
⇉-∷ʳ (⇉-∷ a⇇j j-kd k[a]⇉as⇉Πlm) b⇇l l-kd =
⇉-∷ a⇇j j-kd (⇉-∷ʳ k[a]⇉as⇉Πlm b⇇l l-kd)
≃-∷ʳ : ∀ {n} {Γ : Ctx n} {as bs : Spine n} {a b j k l} →
Γ ⊢ j ⇉∙ as ≃ bs ⇉ Π k l → Γ ⊢ a ≃ b ⇇ k →
Γ ⊢ j ⇉∙ as ∷ʳ a ≃ bs ∷ʳ b ⇉ l Kind[ a ∈ ⌊ k ⌋ ]
≃-∷ʳ ≃-[] a≃b = ≃-∷ a≃b ≃-[]
≃-∷ʳ (≃-∷ a≃b as≃bs) c≃d = ≃-∷ a≃b (≃-∷ʳ as≃bs c≃d)
----------------------------------------------------------------------
-- Well-kinded variable substitutions in canonically kinded types
--
-- We define two different kinds of well-kinded variable
-- substitutions:
--
-- 1. well-kinded renamings, which don't change kinds of variables,
--
-- 2. variable substitutions that also allow conversion/subsumption.
--
-- The first kind are used to prove e.g. that weakening preserve
-- (canonical) well-kindedness, while the second kind are used to
-- prove context conversion/narrowing preserves well-kindedness. The
-- two definitions share a common generic core, which is instantiated
-- to obtain the concrete definitions. The two separate definitions
-- are necessary because the latter requires the weakening lemma,
-- which in turn depends on the former.
-- Liftings between variable typings
record LiftTo-Var′∈ (_⊢V_∈_ : Typing ElimAsc Fin ElimAsc lzero) : Set₁ where
open Substitution using (weakenElimAsc; _ElimAsc/Var_)
typedSub : TypedSub ElimAsc Fin lzero
typedSub = record
{ _⊢_wf = _⊢_wf
; _⊢_∈_ = _⊢V_∈_
; typeExtension = record { weaken = weakenElimAsc }
; typeTermApplication = record { _/_ = _ElimAsc/Var_ }
; termSimple = VarSubst.simple
}
open TypedSub typedSub public
renaming (_⊢/_∈_ to _⊢/Var_∈_) hiding (_⊢_wf; _⊢_∈_; typeExtension)
-- Simple typed variable substitutions.
field typedSimple : TypedSimple typedSub
open TypedSimple typedSimple public renaming (lookup to /∈-lookup)
-- Lifts well-typed Term₁-terms to well-typed Term₂-terms.
field ∈-lift : ∀ {n} {Γ : Ctx n} {x a} → Γ ⊢V x ∈ a → Γ ⊢Var′ x ∈ a
module TypedVarSubstApp (_⊢V_∈_ : Typing ElimAsc Fin ElimAsc lzero)
(liftTyped : LiftTo-Var′∈ _⊢V_∈_)
where
open LiftTo-Var′∈ liftTyped
open Substitution hiding (subst; _/Var_) renaming (_Elim/Var_ to _/Var_)
open RenamingCommutes using (Kind[∈⌊⌋]-/Var)
-- A helper.
∈-↑′ : ∀ {m n} {Δ : Ctx n} {Γ : Ctx m} {k ρ} →
Δ ⊢ k Kind′/Var ρ kd → Δ ⊢/Var ρ ∈ Γ →
kd (k Kind′/Var ρ) ∷ Δ ⊢/Var ρ VarSubst.↑ ∈ kd k ∷ Γ
∈-↑′ k/ρ-kd ρ∈Γ = ∈-↑ (wf-kd k/ρ-kd) ρ∈Γ
-- Convert between well-kindedness judgments for variables.
V∈-Var∈ : ∀ {n} {Γ : Ctx n} {x a k} → a ≡ kd k →
Γ ⊢V x ∈ a → Γ ⊢Var x ∈ k
V∈-Var∈ refl xT∈kd-k with ∈-lift xT∈kd-k
V∈-Var∈ refl xT∈kd-k | ∈-tp x∈k = x∈k
mutual
-- Renamings preserve well-formedness of ascriptions.
wf-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a ρ} →
Γ ⊢ a wf → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ a ElimAsc/Var ρ wf
wf-/Var (wf-kd k-kd) ρ∈Γ = wf-kd (kd-/Var k-kd ρ∈Γ)
wf-/Var (wf-tp a⇉a⋯a) ρ∈Γ = wf-tp (Nf⇉-/Var a⇉a⋯a ρ∈Γ)
-- Renamings preserve well-formedness of kinds.
kd-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {k ρ} →
Γ ⊢ k kd → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ k Kind′/Var ρ kd
kd-/Var (kd-⋯ a⇉a⋯a b⇉b⋯b) ρ∈Γ =
kd-⋯ (Nf⇉-/Var a⇉a⋯a ρ∈Γ) (Nf⇉-/Var b⇉b⋯b ρ∈Γ)
kd-/Var (kd-Π j-kd k-kd) ρ∈Γ =
let j/ρ-kd = kd-/Var j-kd ρ∈Γ
in kd-Π j/ρ-kd (kd-/Var k-kd (∈-↑′ j/ρ-kd ρ∈Γ))
-- Renamings preserve synthesized kinds of normal types.
Nf⇉-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k ρ} →
Γ ⊢Nf a ⇉ k → Δ ⊢/Var ρ ∈ Γ → Δ ⊢Nf a /Var ρ ⇉ k Kind′/Var ρ
Nf⇉-/Var (⇉-⊥-f Γ-ctx) ρ∈Γ = ⇉-⊥-f (/∈-wf ρ∈Γ)
Nf⇉-/Var (⇉-⊤-f Γ-ctx) ρ∈Γ = ⇉-⊤-f (/∈-wf ρ∈Γ)
Nf⇉-/Var (⇉-∀-f k-kd a⇉a⋯a) ρ∈Γ =
let k/ρ-kd = kd-/Var k-kd ρ∈Γ
in ⇉-∀-f k/ρ-kd (Nf⇉-/Var a⇉a⋯a (∈-↑′ k/ρ-kd ρ∈Γ))
Nf⇉-/Var (⇉-→-f a⇉a⋯a b⇉b⋯b) ρ∈Γ =
⇉-→-f (Nf⇉-/Var a⇉a⋯a ρ∈Γ) (Nf⇉-/Var b⇉b⋯b ρ∈Γ)
Nf⇉-/Var (⇉-Π-i j-kd a⇉k) ρ∈Γ =
let j/ρ-kd = kd-/Var j-kd ρ∈Γ
in ⇉-Π-i j/ρ-kd (Nf⇉-/Var a⇉k (∈-↑′ j/ρ-kd ρ∈Γ))
Nf⇉-/Var (⇉-s-i a∈b⋯c) ρ∈Γ = ⇉-s-i (Ne∈-/Var a∈b⋯c ρ∈Γ)
-- Renamings preserve the kinds of variables.
Var∈-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {x k ρ} →
Γ ⊢Var x ∈ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢Var (Vec.lookup ρ x) ∈ k Kind′/Var ρ
Var∈-/Var {ρ = ρ} (⇉-var x Γ-ctx Γ[x]≡kd-k) ρ∈Γ =
V∈-Var∈ (cong (_ElimAsc/Var ρ) Γ[x]≡kd-k) (/∈-lookup ρ∈Γ x)
Var∈-/Var (⇇-⇑ x∈j j<∷k k-kd) ρ∈Γ =
⇇-⇑ (Var∈-/Var x∈j ρ∈Γ) (<∷-/Var j<∷k ρ∈Γ) (kd-/Var k-kd ρ∈Γ)
-- Renamings preserve synthesized kinds of neutral types.
Ne∈-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k ρ} →
Γ ⊢Ne a ∈ k → Δ ⊢/Var ρ ∈ Γ → Δ ⊢Ne a /Var ρ ∈ k Kind′/Var ρ
Ne∈-/Var (∈-∙ x∈j k⇉as⇉l) ρ∈Γ =
∈-∙ (Var∈-/Var x∈j ρ∈Γ) (Sp⇉-/Var k⇉as⇉l ρ∈Γ)
-- Renamings preserve spine kindings.
Sp⇉-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {as j k ρ} →
Γ ⊢ j ⇉∙ as ⇉ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ j Kind′/Var ρ ⇉∙ as //Var ρ ⇉ k Kind′/Var ρ
Sp⇉-/Var ⇉-[] ρ∈Γ = ⇉-[]
Sp⇉-/Var (⇉-∷ {a} {_} {j} {k} a⇇j j-kd k[a]⇉as⇉l) ρ∈Γ =
⇉-∷ (Nf⇇-/Var a⇇j ρ∈Γ) (kd-/Var j-kd ρ∈Γ)
(subst (_ ⊢_⇉∙ _ ⇉ _) (Kind[∈⌊⌋]-/Var k a j)
(Sp⇉-/Var k[a]⇉as⇉l ρ∈Γ))
-- Renamings preserve checked kinds of neutral types.
Nf⇇-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k ρ} →
Γ ⊢Nf a ⇇ k → Δ ⊢/Var ρ ∈ Γ → Δ ⊢Nf a /Var ρ ⇇ k Kind′/Var ρ
Nf⇇-/Var (⇇-⇑ a⇉j j<∷k) ρ∈Γ = ⇇-⇑ (Nf⇉-/Var a⇉j ρ∈Γ) (<∷-/Var j<∷k ρ∈Γ)
-- Renamings preserve subkinding.
<∷-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k ρ} →
Γ ⊢ j <∷ k → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ j Kind′/Var ρ <∷ k Kind′/Var ρ
<∷-/Var (<∷-⋯ a₂<:a₁ b₁<:b₂) ρ∈Γ =
<∷-⋯ (<:-/Var a₂<:a₁ ρ∈Γ) (<:-/Var b₁<:b₂ ρ∈Γ)
<∷-/Var (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) ρ∈Γ =
<∷-Π (<∷-/Var j₂<∷j₁ ρ∈Γ)
(<∷-/Var k₁<∷k₂ (∈-↑ (<∷-/Var-wf k₁<∷k₂ ρ∈Γ) ρ∈Γ))
(kd-/Var Πj₁k₁-kd ρ∈Γ)
-- Renamings preserve subtyping.
<:-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b ρ} →
Γ ⊢ a <: b → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ a /Var ρ <: b /Var ρ
<:-/Var (<:-trans a<:b b<:c) ρ∈Γ =
<:-trans (<:-/Var a<:b ρ∈Γ) (<:-/Var b<:c ρ∈Γ)
<:-/Var (<:-⊥ a⇉a⋯a) ρ∈Γ = <:-⊥ (Nf⇉-/Var a⇉a⋯a ρ∈Γ)
<:-/Var (<:-⊤ a⇉a⋯a) ρ∈Γ = <:-⊤ (Nf⇉-/Var a⇉a⋯a ρ∈Γ)
<:-/Var (<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁) ρ∈Γ =
<:-∀ (<∷-/Var k₂<∷k₁ ρ∈Γ)
(<:-/Var a₁<:a₂ (∈-↑ (<:-/Var-wf a₁<:a₂ ρ∈Γ) ρ∈Γ))
(Nf⇉-/Var Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁ ρ∈Γ)
<:-/Var (<:-→ a₂<:a₁ b₁<:b₂) ρ∈Γ =
<:-→ (<:-/Var a₂<:a₁ ρ∈Γ) (<:-/Var b₁<:b₂ ρ∈Γ)
<:-/Var (<:-∙ x∈j j⇉as₁<:as₂⇉k) ρ∈Γ =
<:-∙ (Var∈-/Var x∈j ρ∈Γ) (Sp≃-/Var j⇉as₁<:as₂⇉k ρ∈Γ)
<:-/Var (<:-⟨| a∈b⋯c) ρ∈Γ = <:-⟨| (Ne∈-/Var a∈b⋯c ρ∈Γ)
<:-/Var (<:-|⟩ a∈b⋯c) ρ∈Γ = <:-|⟩ (Ne∈-/Var a∈b⋯c ρ∈Γ)
<:⇇-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k ρ} →
Γ ⊢ a <: b ⇇ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ a /Var ρ <: b /Var ρ ⇇ k Kind′/Var ρ
<:⇇-/Var (<:-⇇ a⇇k b⇇k a<:b) ρ∈Γ =
<:-⇇ (Nf⇇-/Var a⇇k ρ∈Γ) (Nf⇇-/Var b⇇k ρ∈Γ) (<:-/Var a<:b ρ∈Γ)
<:⇇-/Var (<:-λ a₁<:a₂ Λj₁a₁⇇Πjk Λj₂a₂⇇Πjk) ρ∈Γ =
<:-λ (<:⇇-/Var a₁<:a₂ (∈-↑ (<:⇇-/Var-wf a₁<:a₂ ρ∈Γ) ρ∈Γ))
(Nf⇇-/Var Λj₁a₁⇇Πjk ρ∈Γ) (Nf⇇-/Var Λj₂a₂⇇Πjk ρ∈Γ)
-- Renamings preserve type equality.
≃-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k ρ} →
Γ ⊢ a ≃ b ⇇ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ a /Var ρ ≃ b /Var ρ ⇇ k Kind′/Var ρ
≃-/Var (<:-antisym k-kd a<:b b<:a) ρ∈Γ =
<:-antisym (kd-/Var k-kd ρ∈Γ) (<:⇇-/Var a<:b ρ∈Γ) (<:⇇-/Var b<:a ρ∈Γ)
Sp≃-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {as bs j k ρ} →
Γ ⊢ j ⇉∙ as ≃ bs ⇉ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ j Kind′/Var ρ ⇉∙ as //Var ρ ≃ bs //Var ρ ⇉ k Kind′/Var ρ
Sp≃-/Var ≃-[] ρ∈Γ = ≃-[]
Sp≃-/Var (≃-∷ {a} {_} {_} {_} {j} {k} a≃b as≃bs) ρ∈Γ =
≃-∷ (≃-/Var a≃b ρ∈Γ)
(subst (_ ⊢_⇉∙ _ ≃ _ ⇉ _) (Kind[∈⌊⌋]-/Var k a j)
(Sp≃-/Var as≃bs ρ∈Γ))
-- Helpers (to satisfy the termination checker).
--
-- These are simply (manual) expansions of the form
--
-- XX-/Var-wf x ρ∈Γ = wf-/Var (wf-∷₁ (XX-ctx x)) ρ∈Γ
--
-- to ensure the above definitions remain structurally recursive
-- in the various derivations.
kd-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k ρ} →
kd j ∷ Γ ⊢ k kd → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ kd (j Kind′/Var ρ) wf
kd-/Var-wf (kd-⋯ a∈a⋯a _) ρ∈Γ = Nf⇉-/Var-wf a∈a⋯a ρ∈Γ
kd-/Var-wf (kd-Π j-kd _) ρ∈Γ = kd-/Var-wf j-kd ρ∈Γ
Nf⇉-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k ρ} →
kd j ∷ Γ ⊢Nf a ⇉ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ kd (j Kind′/Var ρ) wf
Nf⇉-/Var-wf (⇉-⊥-f (j-wf ∷ _)) ρ∈Γ = wf-/Var j-wf ρ∈Γ
Nf⇉-/Var-wf (⇉-⊤-f (j-wf ∷ _)) ρ∈Γ = wf-/Var j-wf ρ∈Γ
Nf⇉-/Var-wf (⇉-∀-f k-kd _) ρ∈Γ = kd-/Var-wf k-kd ρ∈Γ
Nf⇉-/Var-wf (⇉-→-f a⇉a⋯a _) ρ∈Γ = Nf⇉-/Var-wf a⇉a⋯a ρ∈Γ
Nf⇉-/Var-wf (⇉-Π-i j-kd _) ρ∈Γ = kd-/Var-wf j-kd ρ∈Γ
Nf⇉-/Var-wf (⇉-s-i a∈b⋯c) ρ∈Γ = Ne∈-/Var-wf a∈b⋯c ρ∈Γ
Ne∈-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k ρ} →
kd j ∷ Γ ⊢Ne a ∈ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ kd (j Kind′/Var ρ) wf
Ne∈-/Var-wf (∈-∙ x∈k _) ρ∈Γ = Var∈-/Var-wf x∈k ρ∈Γ
Var∈-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k ρ} →
kd j ∷ Γ ⊢Var a ∈ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ kd (j Kind′/Var ρ) wf
Var∈-/Var-wf (⇉-var x (j-wf ∷ _) _) ρ∈Γ = wf-/Var j-wf ρ∈Γ
Var∈-/Var-wf (⇇-⇑ x∈j _ _) ρ∈Γ = Var∈-/Var-wf x∈j ρ∈Γ
Nf⇇-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k ρ} →
kd j ∷ Γ ⊢Nf a ⇇ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ kd (j Kind′/Var ρ) wf
Nf⇇-/Var-wf (⇇-⇑ a⇉j _) ρ∈Γ = Nf⇉-/Var-wf a⇉j ρ∈Γ
<∷-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k l ρ} →
kd j ∷ Γ ⊢ k <∷ l → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ kd (j Kind′/Var ρ) wf
<∷-/Var-wf (<∷-⋯ a₂<:a₁ _) ρ∈Γ = <:-/Var-wf a₂<:a₁ ρ∈Γ
<∷-/Var-wf (<∷-Π j₂<∷j₁ _ _) ρ∈Γ = <∷-/Var-wf j₂<∷j₁ ρ∈Γ
<:-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b j ρ} →
kd j ∷ Γ ⊢ a <: b → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ kd (j Kind′/Var ρ) wf
<:-/Var-wf (<:-trans a<:b _) ρ∈Γ = <:-/Var-wf a<:b ρ∈Γ
<:-/Var-wf (<:-⊥ a⇉a⋯a) ρ∈Γ = Nf⇉-/Var-wf a⇉a⋯a ρ∈Γ
<:-/Var-wf (<:-⊤ a⇉a⋯a) ρ∈Γ = Nf⇉-/Var-wf a⇉a⋯a ρ∈Γ
<:-/Var-wf (<:-∀ k₂<∷k₁ _ _) ρ∈Γ = <∷-/Var-wf k₂<∷k₁ ρ∈Γ
<:-/Var-wf (<:-→ a₂<:a₁ _) ρ∈Γ = <:-/Var-wf a₂<:a₁ ρ∈Γ
<:-/Var-wf (<:-∙ x∈j _) ρ∈Γ = Var∈-/Var-wf x∈j ρ∈Γ
<:-/Var-wf (<:-⟨| a∈b⋯c) ρ∈Γ = Ne∈-/Var-wf a∈b⋯c ρ∈Γ
<:-/Var-wf (<:-|⟩ a∈b⋯c) ρ∈Γ = Ne∈-/Var-wf a∈b⋯c ρ∈Γ
<:⇇-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b j k ρ} →
kd j ∷ Γ ⊢ a <: b ⇇ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢ kd (j Kind′/Var ρ) wf
<:⇇-/Var-wf (<:-⇇ a⇇k _ _) ρ∈Γ = Nf⇇-/Var-wf a⇇k ρ∈Γ
<:⇇-/Var-wf (<:-λ _ Λj₁a₁⇇Πjk _) ρ∈Γ = Nf⇇-/Var-wf Λj₁a₁⇇Πjk ρ∈Γ
≅-/Var-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k l ρ} →
kd j ∷ Γ ⊢ k ≅ l → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ kd (j Kind′/Var ρ) wf
≅-/Var-wf (<∷-antisym _ _ j<∷k _) ρ∈Γ = <∷-/Var-wf j<∷k ρ∈Γ
-- Renamings preserve kind equality.
≅-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k ρ} →
Γ ⊢ j ≅ k → Δ ⊢/Var ρ ∈ Γ → Δ ⊢ j Kind′/Var ρ ≅ k Kind′/Var ρ
≅-/Var (<∷-antisym j-kd k-kd j<∷k k<∷j) ρ∈Γ =
<∷-antisym (kd-/Var j-kd ρ∈Γ) (kd-/Var k-kd ρ∈Γ)
(<∷-/Var j<∷k ρ∈Γ) (<∷-/Var k<∷j ρ∈Γ)
-- Renamings preserve wrapped variable typing
Var′∈-/Var : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {x k ρ} →
Γ ⊢Var′ x ∈ k → Δ ⊢/Var ρ ∈ Γ →
Δ ⊢Var′ (Vec.lookup ρ x) ∈ k ElimAsc/Var ρ
Var′∈-/Var (∈-tp x∈k) ρ∈Γ = ∈-tp (Var∈-/Var x∈k ρ∈Γ)
Var′∈-/Var {ρ = ρ} (∈-tm x Γ-ctx Γ[x]≡tp-t) ρ∈Γ =
subst (_ ⊢Var′ _ ∈_) (cong (_ElimAsc/Var ρ) Γ[x]≡tp-t)
(∈-lift (/∈-lookup ρ∈Γ x))
-- Well-kinded renamings in canonically kinded types, i.e. lemmas
-- showing that renaming preserves kinding.
--
-- Note that these are pure renamings that cannot change the kinds of
-- variables (i.e. they cannot be used to implement context conversion
-- or narrowing).
module KindedRenaming where
open Substitution using (termLikeLemmasElimAsc)
typedVarSubst : TypedVarSubst ElimAsc lzero
typedVarSubst = record
{ _⊢_wf = _⊢_wf
; typeExtension = ElimCtx.weakenOps
; typeVarApplication = AppLemmas.application appLemmas
; wf-wf = wf-ctx
; /-wk = refl
; id-vanishes = id-vanishes
; /-⊙ = /-⊙
}
where
open TermLikeLemmas termLikeLemmasElimAsc using (varLiftAppLemmas)
open LiftAppLemmas varLiftAppLemmas
open TypedVarSubst typedVarSubst
hiding (_⊢_wf) renaming (_⊢Var_∈_ to _⊢GenVar_∈_)
-- Liftings from generic variable typings to variable kindings.
liftTyped : LiftTo-Var′∈ _⊢GenVar_∈_
liftTyped = record
{ typedSimple = typedSimple
; ∈-lift = ∈-lift
}
where
∈-lift : ∀ {n} {Γ : Ctx n} {x a} → Γ ⊢GenVar x ∈ a → Γ ⊢Var′ x ∈ a
∈-lift (∈-var x Γ-ctx) = ∈-var′ x Γ-ctx
open TypedVarSubstApp _⊢GenVar_∈_ liftTyped public
open Substitution hiding (subst)
-- Weakening preserves well-formedness of kinds.
kd-weaken : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢ a wf → Γ ⊢ k kd → a ∷ Γ ⊢ weakenKind′ k kd
kd-weaken a-wf k-kd = kd-/Var k-kd (∈-wk a-wf)
-- Weakening preserves variable kinding.
Var∈-weaken : ∀ {n} {Γ : Ctx n} {a x k} → Γ ⊢ a wf →
Γ ⊢Var x ∈ k →
a ∷ Γ ⊢Var Vec.lookup VarSubst.wk x ∈ weakenKind′ k
Var∈-weaken a-wf x∈k = Var∈-/Var x∈k (∈-wk a-wf)
Var′∈-weaken : ∀ {n} {Γ : Ctx n} {a x b} → Γ ⊢ a wf →
Γ ⊢Var′ x ∈ b → a ∷ Γ ⊢Var′ suc x ∈ weakenElimAsc b
Var′∈-weaken a-wf x∈b =
subst (_ ⊢Var′_∈ _) VarLemmas./-wk (Var′∈-/Var x∈b (∈-wk a-wf))
-- Weakening preserves spine kinding.
Sp⇉-weaken : ∀ {n} {Γ : Ctx n} {a bs j k} → Γ ⊢ a wf → Γ ⊢ j ⇉∙ bs ⇉ k →
a ∷ Γ ⊢ weakenKind′ j ⇉∙ weakenSpine bs ⇉ weakenKind′ k
Sp⇉-weaken a-wf j⇉bs⇉k = Sp⇉-/Var j⇉bs⇉k (∈-wk a-wf)
-- Weakening preserves checked kinding.
Nf⇇-weaken : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a wf →
Γ ⊢Nf b ⇇ k → (a ∷ Γ) ⊢Nf weakenElim b ⇇ weakenKind′ k
Nf⇇-weaken a-wf b⇇k = Nf⇇-/Var b⇇k (∈-wk a-wf)
-- Weakening preserves subkinding.
<∷-weaken : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ a wf →
Γ ⊢ j <∷ k → (a ∷ Γ) ⊢ weakenKind′ j <∷ weakenKind′ k
<∷-weaken a-wf j<∷k = <∷-/Var j<∷k (∈-wk a-wf)
-- Weakening preserves subtyping.
<:-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b <: c →
a ∷ Γ ⊢ weakenElim b <: weakenElim c
<:-weaken a-wf b<:c = <:-/Var b<:c (∈-wk a-wf)
<:⇇-weaken : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a wf → Γ ⊢ b <: c ⇇ k →
a ∷ Γ ⊢ weakenElim b <: weakenElim c ⇇ weakenKind′ k
<:⇇-weaken a-wf b<:c = <:⇇-/Var b<:c (∈-wk a-wf)
-- Weakening preserves well-formedness of ascriptions.
wf-weaken : ∀ {n} {Γ : Ctx n} {a b} →
Γ ⊢ a wf → Γ ⊢ b wf → a ∷ Γ ⊢ weakenElimAsc b wf
wf-weaken a-wf b-wf = wf-/Var b-wf (∈-wk a-wf)
-- Weakening preserves kind and type equality.
≃-weaken : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a wf → Γ ⊢ b ≃ c ⇇ k →
a ∷ Γ ⊢ weakenElim b ≃ weakenElim c ⇇ weakenKind′ k
≃-weaken a-wf b≃c = ≃-/Var b≃c (∈-wk a-wf)
≅-weaken : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ a wf → Γ ⊢ j ≅ k →
a ∷ Γ ⊢ weakenKind′ j ≅ weakenKind′ k
≅-weaken a-wf j≅k = ≅-/Var j≅k (∈-wk a-wf)
Sp≃-weaken : ∀ {n} {Γ : Ctx n} {a bs cs j k} → Γ ⊢ a wf →
Γ ⊢ j ⇉∙ bs ≃ cs ⇉ k →
a ∷ Γ ⊢ weakenKind′ j ⇉∙ weakenSpine bs ≃ weakenSpine cs ⇉
weakenKind′ k
Sp≃-weaken a-wf bs≃cs = Sp≃-/Var bs≃cs (∈-wk a-wf)
-- Operations on well-formed contexts that require weakening of
-- well-formedness judgments.
module WfCtxOps where
open KindedRenaming using (wf-weaken)
wfWeakenOps : WellFormedWeakenOps weakenOps
wfWeakenOps = record { wf-weaken = wf-weaken }
open WellFormedWeakenOps wfWeakenOps public
hiding (wf-weaken) renaming (lookup to lookup-wf)
-- Lookup the kind of a type variable in a well-formed context.
lookup-kd : ∀ {m} {Γ : Ctx m} {k} x →
Γ ctx → ElimCtx.lookup Γ x ≡ kd k → Γ ⊢ k kd
lookup-kd x Γ-ctx Γ[x]≡kd-k =
wf-kd-inv (subst (_ ⊢_wf) Γ[x]≡kd-k (lookup-wf Γ-ctx x))
open WfCtxOps
-- A corollary (validity of variable kinding): the kinds of variables
-- are well-formed.
Var∈-valid : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Var a ∈ k → Γ ⊢ k kd
Var∈-valid (⇉-var x Γ-ctx Γ[x]≡kd-k) = lookup-kd x Γ-ctx Γ[x]≡kd-k
Var∈-valid (⇇-⇑ x∈j j<∷k k-kd) = k-kd
----------------------------------------------------------------------
-- Context narrowing
--
-- The various judgments are preserved by narrowing of kind
-- ascriptions in their contexts.
module ContextNarrowing where
open Substitution
using (termLikeLemmasElim; termLikeLemmasKind′; termLikeLemmasElimAsc)
open TermLikeLemmas termLikeLemmasElimAsc using (varLiftAppLemmas)
open LiftAppLemmas varLiftAppLemmas
open KindedRenaming using (kd-weaken; <∷-weaken; Var′∈-weaken)
private
module EL = LiftAppLemmas
(TermLikeLemmas.varLiftAppLemmas termLikeLemmasElim)
module KL = LiftAppLemmas
(TermLikeLemmas.varLiftAppLemmas termLikeLemmasKind′)
-- NOTE. Rather than proving context narrowing directly by induction
-- on typing derivations, we instead define a more flexible variant
-- of well-typed variable substitutions based on the canonical
-- variable kinding judgment (_⊢Var_∈_). This judgment features a
-- subsumption rule (∈-⇑), which is not available in the generic
-- variable judgment from Data.Fin.Substitutions.Typed that we used
-- to define basic typed renamings. With support for subsumption in
-- typed renamings, we get context narrowing "for free", as it is
-- just another variable substitution (one that happens to change
-- the kind rather than the name of a variable). This way of
-- proving context narrowing is more convenient since we can reuse
-- the generic lemmas proven for typed variable substitution and
-- avoid some explicit fiddling with context.
--
-- Note also that we could not have defined typed renamings
-- directly using the _⊢Var_∈_ judgment since that would have
-- required a weakening lemma for subkiding, which in turn is
-- implemented via typed renamings.
-- The trivial lifting from _⊢Var′_∈_ to itself, and simple typed
-- variable substitutions.
liftTyped : LiftTo-Var′∈ _⊢Var′_∈_
liftTyped = record
{ typedSimple = record
{ typedWeakenOps = record
{ ∈-weaken = Var′∈-weaken
; ∈-wf = Var′∈-ctx
; /-wk = refl
; /-weaken = /-weaken
; weaken-/-∷ = weaken-/-∷
}
; ∈-var = ∈-var′
; wf-wf = wf-ctx
; id-vanishes = id-vanishes
}
; ∈-lift = λ x∈a → x∈a
}
where
weakenLemmas : WeakenLemmas ElimAsc Fin
weakenLemmas = record { appLemmas = appLemmas ; /-wk = refl }
open WeakenLemmas weakenLemmas
open LiftTo-Var′∈ liftTyped
open TypedVarSubstApp _⊢Var′_∈_ liftTyped
-- A typed renaming that narrows the kind of the first type
-- variable.
∈-<∷-sub : ∀ {n} {Γ : Ctx n} {j k} →
Γ ⊢ j kd → Γ ⊢ j <∷ k → (kd k ∷ Γ) ctx →
kd j ∷ Γ ⊢/Var id ∈ kd k ∷ Γ
∈-<∷-sub j-kd j<∷k k∷Γ-ctx =
∈-tsub (∈-tp (⇇-⇑ x∈k (<∷-weaken j-wf j<∷k) k-kd))
where
j-wf = wf-kd j-kd
Γ-ctx = kd-ctx j-kd
x∈k = ⇉-var zero (j-wf ∷ Γ-ctx) refl
k-kd = kd-weaken j-wf (wf-kd-inv (wf-∷₁ k∷Γ-ctx))
-- Narrowing the kind of the first type variable preserves
-- well-formedness of kinds.
⇓-kd : ∀ {n} {Γ : Ctx n} {j₁ j₂ k} →
Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ k kd → kd j₁ ∷ Γ ⊢ k kd
⇓-kd j₁-kd j₁<∷j₂ k-kd =
subst (_ ⊢_kd) (KL.id-vanishes _)
(kd-/Var k-kd (∈-<∷-sub j₁-kd j₁<∷j₂ (kd-ctx k-kd)))
-- Narrowing the kind of the first type variable preserves
-- well-kindedness.
⇓-Nf⇉ : ∀ {n} {Γ : Ctx n} {j₁ j₂ a k} →
Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢Nf a ⇉ k → kd j₁ ∷ Γ ⊢Nf a ⇉ k
⇓-Nf⇉ j₁-kd j₁<∷j₂ a⇉k =
subst₂ (_ ⊢Nf_⇉_) (EL.id-vanishes _) (KL.id-vanishes _)
(Nf⇉-/Var a⇉k (∈-<∷-sub j₁-kd j₁<∷j₂ (Nf⇉-ctx a⇉k)))
-- Narrowing the kind of the first type variable preserves
-- subkinding and subtyping.
⇓-<∷ : ∀ {n} {Γ : Ctx n} {j₁ j₂ k₁ k₂} →
Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ k₁ <∷ k₂ → kd j₁ ∷ Γ ⊢ k₁ <∷ k₂
⇓-<∷ j₁-kd j₁<∷j₂ k₁<∷k₂ =
subst₂ (_ ⊢_<∷_) (KL.id-vanishes _) (KL.id-vanishes _)
(<∷-/Var k₁<∷k₂ (∈-<∷-sub j₁-kd j₁<∷j₂ (<∷-ctx k₁<∷k₂)))
⇓-<: : ∀ {n} {Γ : Ctx n} {j₁ j₂ a₁ a₂} →
Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ a₁ <: a₂ → kd j₁ ∷ Γ ⊢ a₁ <: a₂
⇓-<: j₁-kd j₁<∷j₂ a₁<:a₂ =
subst₂ (_ ⊢_<:_) (EL.id-vanishes _) (EL.id-vanishes _)
(<:-/Var a₁<:a₂ (∈-<∷-sub j₁-kd j₁<∷j₂ (<:-ctx a₁<:a₂)))
⇓-<:⇇ : ∀ {n} {Γ : Ctx n} {j₁ j₂ a₁ a₂ k} →
Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ a₁ <: a₂ ⇇ k →
kd j₁ ∷ Γ ⊢ a₁ <: a₂ ⇇ k
⇓-<:⇇ j₁-kd j₁<∷j₂ a₁<:a₂∈k =
subst (_ ⊢ _ <: _ ⇇_) (KL.id-vanishes _)
(subst₂ (_ ⊢_<:_⇇ _) (EL.id-vanishes _) (EL.id-vanishes _)
(<:⇇-/Var a₁<:a₂∈k
(∈-<∷-sub j₁-kd j₁<∷j₂ (<:⇇-ctx a₁<:a₂∈k))))
open KindedRenaming
open ContextNarrowing
open Substitution hiding (subst)
private module TV = TypedVarSubst typedVarSubst
-- Some corollaries of context narrowing: transitivity of subkinding
-- and kind equality are admissible.
<∷-trans : ∀ {n} {Γ : Ctx n} {j k l} → Γ ⊢ j <∷ k → Γ ⊢ k <∷ l → Γ ⊢ j <∷ l
<∷-trans (<∷-⋯ a₂<:a₁ b₁<:b₂) (<∷-⋯ a₃<:a₂ b₂<:b₃) =
<∷-⋯ (<:-trans a₃<:a₂ a₂<:a₁) (<:-trans b₁<:b₂ b₂<:b₃)
<∷-trans (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) (<∷-Π j₃<∷j₂ k₂<∷k₃ _) =
let j₃-kd = wf-kd-inv (wf-∷₁ (<∷-ctx k₂<∷k₃))
in <∷-Π (<∷-trans j₃<∷j₂ j₂<∷j₁)
(<∷-trans (⇓-<∷ j₃-kd j₃<∷j₂ k₁<∷k₂) k₂<∷k₃) Πj₁k₁-kd
≅-trans : ∀ {n} {Γ : Ctx n} {j k l} → Γ ⊢ j ≅ k → Γ ⊢ k ≅ l → Γ ⊢ j ≅ l
≅-trans (<∷-antisym j-kd _ j<∷k k<∷j) (<∷-antisym _ l-kd k<∷l l<∷k) =
<∷-antisym j-kd l-kd (<∷-trans j<∷k k<∷l) (<∷-trans l<∷k k<∷j)
-- Some more corollaries: subsumption is admissible in canonical kind
-- checking, checked subtyping and kind equality.
--
-- NOTE. The proof of (<:⇇-⇑) is by induction on subkinding
-- derivations (the second hypothesis) rather than kinding derivations
-- (the first hypothesis).
Nf⇇-⇑ : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Nf a ⇇ j → Γ ⊢ j <∷ k → Γ ⊢Nf a ⇇ k
Nf⇇-⇑ (⇇-⇑ a⇇j₁ j₁<∷j₂) j₂<∷j₃ = ⇇-⇑ a⇇j₁ (<∷-trans j₁<∷j₂ j₂<∷j₃)
<:⇇-⇑ : ∀ {n} {Γ : Ctx n} {a b j k} →
Γ ⊢ a <: b ⇇ j → Γ ⊢ j <∷ k → Γ ⊢ k kd → Γ ⊢ a <: b ⇇ k
<:⇇-⇑ (<:-⇇ a⇇c₁⋯d₁ b⇇c₁⋯d₁ a<:b) (<∷-⋯ c₂<:c₁ d₁<:d₂) _ =
<:-⇇ (Nf⇇-⇑ a⇇c₁⋯d₁ (<∷-⋯ c₂<:c₁ d₁<:d₂))
(Nf⇇-⇑ b⇇c₁⋯d₁ (<∷-⋯ c₂<:c₁ d₁<:d₂)) a<:b
<:⇇-⇑ (<:-λ a₁<:a₂ Λj₁a₁⇇Πk₁l₁ Λj₂a₂⇇Πk₁l₁) (<∷-Π k₂<∷k₁ l₁<∷l₂ Πk₁l₁-kd)
(kd-Π k₂-kd l₂-kd) =
<:-λ (<:⇇-⇑ (⇓-<:⇇ k₂-kd k₂<∷k₁ a₁<:a₂) l₁<∷l₂ l₂-kd)
(Nf⇇-⇑ Λj₁a₁⇇Πk₁l₁ (<∷-Π k₂<∷k₁ l₁<∷l₂ Πk₁l₁-kd))
(Nf⇇-⇑ Λj₂a₂⇇Πk₁l₁ (<∷-Π k₂<∷k₁ l₁<∷l₂ Πk₁l₁-kd))
≃-⇑ : ∀ {n} {Γ : Ctx n} {a b j k} →
Γ ⊢ a ≃ b ⇇ j → Γ ⊢ j <∷ k → Γ ⊢ k kd → Γ ⊢ a ≃ b ⇇ k
≃-⇑ (<:-antisym j-kd a<:b b<:a) j<∷k k-kd =
<:-antisym k-kd (<:⇇-⇑ a<:b j<∷k k-kd) (<:⇇-⇑ b<:a j<∷k k-kd)
------------------------------------------------------------------------
-- Reflexivity of the various relations.
--
-- NOTE. The proof is by mutual induction in the structure of the
-- types and kinds being related to themselves, and then by
-- case-analysis on formation/kinding derivations (rather than
-- induction on the typing/kinding derivations directly). For
-- example, the proof of (<:⇇-reflNf⇉-⇑) is not decreasing in the
-- kinding derivation of `a' in the type abstraction (Π-intro) case.
-- To avoid clutter, we do not make the corresponding type/kind
-- parameters explicit in the implementations below: thanks to the
-- structure of canonical formation/kinding, every kind/type
-- constructor corresponds to exactly one kinding/typing rule
-- (i.e. the rules are syntax directed).
mutual
-- Reflexivity of canonical subkinding.
<∷-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ k
<∷-refl (kd-⋯ a⇉a⋯a b⇉b⋯b) = <∷-⋯ (<:-reflNf⇉ a⇉a⋯a) (<:-reflNf⇉ b⇉b⋯b)
<∷-refl (kd-Π j-kd k-kd) =
<∷-Π (<∷-refl j-kd) (<∷-refl k-kd) (kd-Π j-kd k-kd)
-- Reflexivity of canonical subtyping.
<:-reflNf⇉ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢ a <: a
<:-reflNf⇉ (⇉-⊥-f Γ-ctx) = <:-⊥ (⇉-⊥-f Γ-ctx)
<:-reflNf⇉ (⇉-⊤-f Γ-ctx) = <:-⊤ (⇉-⊤-f Γ-ctx)
<:-reflNf⇉ (⇉-∀-f k-kd a⇉a⋯a) =
<:-∀ (<∷-refl k-kd) (<:-reflNf⇉ a⇉a⋯a) (⇉-∀-f k-kd a⇉a⋯a)
<:-reflNf⇉ (⇉-→-f a⇉a⋯a b⇉b⋯b) =
<:-→ (<:-reflNf⇉ a⇉a⋯a) (<:-reflNf⇉ b⇉b⋯b)
<:-reflNf⇉ (⇉-s-i (∈-∙ x∈j j⇉as⇉k)) = <:-∙ x∈j (≃-reflSp⇉ j⇉as⇉k)
<:⇇-reflNf⇉-⇑ : ∀ {n} {Γ : Ctx n} {a j k} →
Γ ⊢Nf a ⇉ j → Γ ⊢ j <∷ k → Γ ⊢ k kd → Γ ⊢ a <: a ⇇ k
<:⇇-reflNf⇉-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂) _ =
let a⇇b₂⋯c₂ = ⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂)
in <:-⇇ a⇇b₂⋯c₂ a⇇b₂⋯c₂ (<:-reflNf⇉ a⇉b₁⋯c₁)
<:⇇-reflNf⇉-⇑ (⇉-Π-i j₁-kd a⇉k₁) (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd)
(kd-Π j₂-kd k₂-kd) =
let a<:a⇇k₂ = <:⇇-reflNf⇉-⇑ (⇓-Nf⇉ j₂-kd j₂<∷j₁ a⇉k₁) k₁<∷k₂ k₂-kd
Λj₁a⇇Πj₂k₂ = ⇇-⇑ (⇉-Π-i j₁-kd a⇉k₁) (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd)
in <:-λ a<:a⇇k₂ Λj₁a⇇Πj₂k₂ Λj₁a⇇Πj₂k₂
<:⇇-reflNf⇇ : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Nf a ⇇ k → Γ ⊢ k kd → Γ ⊢ a <: a ⇇ k
<:⇇-reflNf⇇ (⇇-⇑ a⇉k j<∷k) k-kd = <:⇇-reflNf⇉-⇑ a⇉k j<∷k k-kd
-- Reflexivity of canonical spine equality.
≃-reflSp⇉ : ∀ {n} {Γ : Ctx n} {as j k} →
Γ ⊢ j ⇉∙ as ⇉ k → Γ ⊢ j ⇉∙ as ≃ as ⇉ k
≃-reflSp⇉ ⇉-[] = ≃-[]
≃-reflSp⇉ (⇉-∷ a⇇j j-kd k[a]⇉as⇉l) =
≃-∷ (≃-reflNf⇇ a⇇j j-kd) (≃-reflSp⇉ k[a]⇉as⇉l)
-- A checked variant of reflexivity.
≃-reflNf⇇ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇇ k → Γ ⊢ k kd → Γ ⊢ a ≃ a ⇇ k
≃-reflNf⇇ a⇇k k-kd =
<:-antisym k-kd (<:⇇-reflNf⇇ a⇇k k-kd) (<:⇇-reflNf⇇ a⇇k k-kd)
-- Reflexivity of canonical kind equality.
≅-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k ≅ k
≅-refl k-kd = <∷-antisym k-kd k-kd (<∷-refl k-kd) (<∷-refl k-kd)
-- A shorthand.
<:⇇-reflNf⇉ : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Nf a ⇉ k → Γ ⊢ k kd → Γ ⊢ a <: a ⇇ k
<:⇇-reflNf⇉ a⇉k k-kd = <:⇇-reflNf⇉-⇑ a⇉k (<∷-refl k-kd) k-kd
-- Some corollaryies of reflexivity.
-- The synthesized kinds of normal forms kind-check.
Nf⇉⇒Nf⇇ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → Γ ⊢Nf a ⇇ k
Nf⇉⇒Nf⇇ a⇉k = ⇇-⇑ a⇉k (<∷-refl (Nf⇉-valid a⇉k))
-- An admissible operator introduction rule accepting a checked body.
Nf⇇-Π-i : ∀ {n} {Γ : Ctx n} {j a k} →
Γ ⊢ j kd → kd j ∷ Γ ⊢Nf a ⇇ k → Γ ⊢Nf Λ∙ j a ⇇ Π j k
Nf⇇-Π-i j-kd (⇇-⇑ a⇉l l<∷k) =
⇇-⇑ (⇉-Π-i j-kd a⇉l) (<∷-Π (<∷-refl j-kd) l<∷k (kd-Π j-kd (Nf⇉-valid a⇉l)))
-- Admissible projection rules for canonically kinded proper types.
<:-⟨|-Nf⇉ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢ b <: a
<:-⟨|-Nf⇉ a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
<:-⟨|-Nf⇉ a⇉a⋯a | refl , refl = <:-reflNf⇉ a⇉a⋯a
<:-⟨|-Nf⇇ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢ b <: a
<:-⟨|-Nf⇇ (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂)) =
<:-trans b₂<:b₁ (<:-⟨|-Nf⇉ a⇉b₁⋯c₁)
<:-|⟩-Nf⇉ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢ a <: c
<:-|⟩-Nf⇉ a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
<:-|⟩-Nf⇉ a⇉a⋯a | refl , refl = <:-reflNf⇉ a⇉a⋯a
<:-|⟩-Nf⇇ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢ a <: c
<:-|⟩-Nf⇇ (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂)) =
<:-trans (<:-|⟩-Nf⇉ a⇉b₁⋯c₁) c₁<:c₂
-- An admissible interval rule for checked subtyping.
<:⇇-⋯-i : ∀ {n} {Γ : Ctx n} {a b c d} →
Γ ⊢ a <: b ⇇ c ⋯ d → Γ ⊢ a <: b ⇇ a ⋯ b
<:⇇-⋯-i (<:-⇇ a⇇c⋯d b⇇c⋯d a<:b) =
let a⇉a⋯a = Nf⇇-s-i a⇇c⋯d
b⇉b⋯b = Nf⇇-s-i b⇇c⋯d
in <:-⇇ (⇇-⇑ a⇉a⋯a (<∷-⋯ (<:-reflNf⇉ a⇉a⋯a) a<:b))
(⇇-⇑ b⇉b⋯b (<∷-⋯ a<:b (<:-reflNf⇉ b⇉b⋯b))) a<:b
-- An inversion lemma about variable kinding.
Var∈-inv : ∀ {n} {Γ : Ctx n} {x k} → Γ ⊢Var x ∈ k →
∃ λ j → lookup Γ x ≡ kd j × Γ ⊢ j <∷ k × Γ ⊢ j kd × Γ ⊢ k kd
Var∈-inv (⇉-var x Γ-ctx Γ[x]≡kd-j) =
let j-kd = lookup-kd x Γ-ctx Γ[x]≡kd-j
in _ , Γ[x]≡kd-j , <∷-refl j-kd , j-kd , j-kd
Var∈-inv (⇇-⇑ x∈j j<∷k k-kd) =
let l , Γ[x]≡kd-l , l<∷j , l-kd , _ = Var∈-inv x∈j
in l , Γ[x]≡kd-l , <∷-trans l<∷j j<∷k , l-kd , k-kd
-- A "canonical forms" lemma for operator equality.
≃-Π-can : ∀ {n} {Γ : Ctx n} {a₁ a₂ j k} → Γ ⊢ a₁ ≃ a₂ ⇇ Π j k →
∃ λ j₁ → ∃ λ b₁ → ∃ λ j₂ → ∃ λ b₂ →
Γ ⊢Nf Λ∙ j₁ b₁ ⇇ Π j k × Γ ⊢Nf Λ∙ j₂ b₂ ⇇ Π j k × Γ ⊢ Π j k kd ×
Γ ⊢ j <∷ j₁ × Γ ⊢ j <∷ j₂ ×
kd j ∷ Γ ⊢ b₁ <: b₂ ⇇ k × kd j ∷ Γ ⊢ b₂ <: b₁ ⇇ k ×
a₁ ≡ Λ∙ j₁ b₁ × a₂ ≡ Λ∙ j₂ b₂
≃-Π-can (<:-antisym Πjk-kd
(<:-λ a₁<:a₂
(⇇-⇑ (⇉-Π-i j₁-kd a₁⇉k₁) (<∷-Π j<∷j₁ k₁<∷k Πj₁k₁-kd))
(⇇-⇑ (⇉-Π-i j₂-kd a₂⇉k₂) (<∷-Π j<∷j₂ k₂<∷k Πj₂k₂-kd)))
(<:-λ a₂<:a₁ _ _)) =
_ , _ , _ , _ ,
(⇇-⇑ (⇉-Π-i j₁-kd a₁⇉k₁) (<∷-Π j<∷j₁ k₁<∷k Πj₁k₁-kd)) ,
(⇇-⇑ (⇉-Π-i j₂-kd a₂⇉k₂) (<∷-Π j<∷j₂ k₂<∷k Πj₂k₂-kd)) ,
Πjk-kd , j<∷j₁ , j<∷j₂ , a₁<:a₂ , a₂<:a₁ , refl , refl
------------------------------------------------------------------------
-- Simplification of well-formed kinding.
module _ where
open SimpleKinding
open SimpleKinding.Kinding
renaming (_⊢Var_∈_ to _⊢sVar_∈_; _⊢Ne_∈_ to _⊢sNe_∈_)
open KindedHereditarySubstitution
open ≡-Reasoning
-- Simplification of well-formedness and kinding: well-formed kinds
-- resp. well-kinded normal forms, neutrals and spines are also
-- simply well-formed resp. well-kinded.
Var∈-sVar∈ : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Var a ∈ k → ⌊ Γ ⌋Ctx ⊢sVar a ∈ ⌊ k ⌋
Var∈-sVar∈ {_} {Γ} {_} {k} (⇉-var x Γ-ctx Γ[x]≡kd-k) = ∈-var x (begin
SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡⟨ ⌊⌋Asc-lookup Γ x ⟩
⌊ ElimCtx.lookup Γ x ⌋Asc ≡⟨ cong ⌊_⌋Asc Γ[x]≡kd-k ⟩
kd ⌊ k ⌋ ∎)
where open ContextConversions
Var∈-sVar∈ (⇇-⇑ x∈j j<∷k k-kd) =
subst (_ ⊢sVar _ ∈_) (<∷-⌊⌋ j<∷k) (Var∈-sVar∈ x∈j)
mutual
kd-kds : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → ⌊ Γ ⌋Ctx ⊢ k kds
kd-kds (kd-⋯ a∈a⋯a b∈b⋯b) = kds-⋯ (Nf⇉-Nf∈ a∈a⋯a) (Nf⇉-Nf∈ b∈b⋯b)
kd-kds (kd-Π j-kd k-kd) = kds-Π (kd-kds j-kd) (kd-kds k-kd)
Nf⇉-Nf∈ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → ⌊ Γ ⌋Ctx ⊢Nf a ∈ ⌊ k ⌋
Nf⇉-Nf∈ (⇉-⊥-f Γ-ctx) = ∈-⊥-f
Nf⇉-Nf∈ (⇉-⊤-f Γ-ctx) = ∈-⊤-f
Nf⇉-Nf∈ (⇉-∀-f k-kd a⇉a⋯a) = ∈-∀-f (kd-kds k-kd) (Nf⇉-Nf∈ a⇉a⋯a)
Nf⇉-Nf∈ (⇉-→-f a∈a⋯a b∈b⋯b) = ∈-→-f (Nf⇉-Nf∈ a∈a⋯a) (Nf⇉-Nf∈ b∈b⋯b)
Nf⇉-Nf∈ (⇉-Π-i j-kd a⇉k) = ∈-Π-i (kd-kds j-kd) (Nf⇉-Nf∈ a⇉k)
Nf⇉-Nf∈ (⇉-s-i a∈b⋯c) = ∈-ne (Ne∈-sNe∈ a∈b⋯c)
Ne∈-sNe∈ : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Ne a ∈ k → ⌊ Γ ⌋Ctx ⊢sNe a ∈ ⌊ k ⌋
Ne∈-sNe∈ (∈-∙ x∈j j⇉as⇉k) = ∈-∙ (Var∈-sVar∈ x∈j) (Sp⇉-Sp∈ j⇉as⇉k)
Sp⇉-Sp∈ : ∀ {n} {Γ : Ctx n} {as j k} → Γ ⊢ j ⇉∙ as ⇉ k →
⌊ Γ ⌋Ctx ⊢ ⌊ j ⌋ ∋∙ as ∈ ⌊ k ⌋
Sp⇉-Sp∈ ⇉-[] = ∈-[]
Sp⇉-Sp∈ (⇉-∷ a⇇j j-kd k[a]⇉as⇉l) =
∈-∷ (Nf⇇-Nf∈ a⇇j)
(subst (_ ⊢_∋∙ _ ∈ _) (⌊⌋-Kind/⟨⟩ _) (Sp⇉-Sp∈ k[a]⇉as⇉l))
Nf⇇-Nf∈ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇇ k → ⌊ Γ ⌋Ctx ⊢Nf a ∈ ⌊ k ⌋
Nf⇇-Nf∈ (⇇-⇑ a⇉j j<∷k) = subst (_ ⊢Nf _ ∈_) (<∷-⌊⌋ j<∷k) (Nf⇉-Nf∈ a⇉j)
| 41.059984
| 79
| 0.487432
|
5e0fff5b75e6878d3dea047e87002bb751ad4f67
| 578
|
agda
|
Agda
|
agda-stdlib/src/Relation/Binary/SymmetricClosure.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Relation/Binary/SymmetricClosure.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Relation/Binary/SymmetricClosure.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 the
-- Relation.Binary.Construct.Closure.Symmetric module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.SymmetricClosure where
open import Relation.Binary.Construct.Closure.Symmetric public
{-# WARNING_ON_IMPORT
"Relation.Binary.SymmetricClosure was deprecated in v0.16.
Use Relation.Binary.Construct.Closure.Symmetric instead."
#-}
| 32.111111
| 72
| 0.586505
|
9a097f81d25944405d0e754a4c098c6e01adbc06
| 5,432
|
agda
|
Agda
|
Cubical/Homotopy/Freudenthal.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Homotopy/Freudenthal.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Homotopy/Freudenthal.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-
Freudenthal suspension theorem
-}
{-# OPTIONS --safe #-}
module Cubical.Homotopy.Freudenthal where
open import Cubical.Foundations.Everything
-- open import Cubical.Data.HomotopyGroup
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.HITs.Nullification
open import Cubical.HITs.Susp
open import Cubical.HITs.Truncation as Trunc renaming (rec to trRec ; elim to trElim)
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.WedgeConnectivity
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.SmashProduct
open import Cubical.HITs.S1 hiding (encode)
open import Cubical.HITs.Sn
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.Foundations.Equiv.HalfAdjoint
module _ {ℓ} (n : HLevel) {A : Pointed ℓ} (connA : isConnected (suc (suc n)) (typ A)) where
σ : typ A → typ (Ω (∙Susp (typ A)))
σ a = merid a ∙ merid (pt A) ⁻¹
private
2n+2 = suc n + suc n
module WC (p : north ≡ north) =
WedgeConnectivity (suc n) (suc n) A connA A connA
(λ a b →
( (σ b ≡ p → hLevelTrunc 2n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p))
, isOfHLevelΠ 2n+2 λ _ → isOfHLevelTrunc 2n+2
))
(λ a r → ∣ a , (rCancel' (merid a) ∙ rCancel' (merid (pt A)) ⁻¹) ∙ r ∣)
(λ b r → ∣ b , r ∣)
(funExt λ r →
cong′ (λ w → ∣ pt A , w ∣)
(cong (_∙ r) (rCancel' (rCancel' (merid (pt A))))
∙ lUnit r ⁻¹))
fwd : (p : north ≡ north) (a : typ A)
→ hLevelTrunc 2n+2 (fiber σ p)
→ hLevelTrunc 2n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p)
fwd p a = Trunc.rec (isOfHLevelTrunc 2n+2) (uncurry (WC.extension p a))
isEquivFwd : (p : north ≡ north) (a : typ A) → isEquiv (fwd p a)
isEquivFwd p a .equiv-proof =
elim.isEquivPrecompose (λ _ → pt A) (suc n)
(λ a →
( (∀ t → isContr (fiber (fwd p a) t))
, isProp→isOfHLevelSuc n (isPropΠ λ _ → isPropIsContr)
))
(isConnectedPoint (suc n) connA (pt A))
.equiv-proof
(λ _ → Trunc.elim
(λ _ → isProp→isOfHLevelSuc (n + suc n) isPropIsContr)
(λ fib →
subst (λ k → isContr (fiber k ∣ fib ∣))
(cong (Trunc.rec (isOfHLevelTrunc 2n+2) ∘ uncurry)
(funExt (WC.right p) ⁻¹))
(subst isEquiv
(funExt (Trunc.mapId) ⁻¹)
(idIsEquiv _)
.equiv-proof ∣ fib ∣)
))
.fst .fst a
interpolate : (a : typ A)
→ PathP (λ i → typ A → north ≡ merid a i) (λ x → merid x ∙ merid a ⁻¹) merid
interpolate a i x j = compPath-filler (merid x) (merid a ⁻¹) (~ i) j
Code : (y : Susp (typ A)) → north ≡ y → Type ℓ
Code north p = hLevelTrunc 2n+2 (fiber σ p)
Code south q = hLevelTrunc 2n+2 (fiber merid q)
Code (merid a i) p =
Glue
(hLevelTrunc 2n+2 (fiber (interpolate a i) p))
(λ
{ (i = i0) → _ , (fwd p a , isEquivFwd p a)
; (i = i1) → _ , idEquiv _
})
encode : (y : Susp (typ A)) (p : north ≡ y) → Code y p
encode y = J Code ∣ pt A , rCancel' (merid (pt A)) ∣
encodeMerid : (a : typ A) → encode south (merid a) ≡ ∣ a , refl ∣
encodeMerid a =
cong (transport (λ i → gluePath i))
(funExt⁻ (WC.left refl a) _ ∙ λ i → ∣ a , lem (rCancel' (merid a)) (rCancel' (merid (pt A))) i ∣)
∙ transport (PathP≡Path gluePath _ _)
(λ i → ∣ a , (λ j k → rCancel-filler' (merid a) i j k) ∣)
where
gluePath : I → Type _
gluePath i = hLevelTrunc 2n+2 (fiber (interpolate a i) (λ j → merid a (i ∧ j)))
lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y) → (p ∙ q ⁻¹) ∙ q ≡ p
lem p q = assoc p (q ⁻¹) q ⁻¹ ∙∙ cong (p ∙_) (lCancel q) ∙∙ rUnit p ⁻¹
contractCodeSouth : (p : north ≡ south) (c : Code south p) → encode south p ≡ c
contractCodeSouth p =
Trunc.elim
(λ _ → isOfHLevelPath 2n+2 (isOfHLevelTrunc 2n+2) _ _)
(uncurry λ a →
J (λ p r → encode south p ≡ ∣ a , r ∣) (encodeMerid a))
isConnectedMerid : isConnectedFun 2n+2 (merid {A = typ A})
isConnectedMerid p = encode south p , contractCodeSouth p
isConnectedσ : isConnectedFun 2n+2 σ
isConnectedσ =
transport (λ i → isConnectedFun 2n+2 (interpolate (pt A) (~ i))) isConnectedMerid
isConn→isConnSusp : ∀ {ℓ} {A : Pointed ℓ} → isConnected 2 (typ A) → isConnected 2 (Susp (typ A))
isConn→isConnSusp {A = A} iscon = ∣ north ∣
, trElim (λ _ → isOfHLevelSuc 1 (isOfHLevelTrunc 2 _ _))
(suspToPropElim (pt A) (λ _ → isOfHLevelTrunc 2 _ _)
refl)
FreudenthalEquiv : ∀ {ℓ} (n : HLevel) (A : Pointed ℓ)
→ isConnected (2 + n) (typ A)
→ hLevelTrunc ((suc n) + (suc n)) (typ A)
≃ hLevelTrunc ((suc n) + (suc n)) (typ (Ω (Susp (typ A) , north)))
FreudenthalEquiv n A iscon = connectedTruncEquiv _
(σ n {A = A} iscon)
(isConnectedσ _ iscon)
FreudenthalIso : ∀ {ℓ} (n : HLevel) (A : Pointed ℓ)
→ isConnected (2 + n) (typ A)
→ Iso (hLevelTrunc ((suc n) + (suc n)) (typ A))
(hLevelTrunc ((suc n) + (suc n)) (typ (Ω (Susp (typ A) , north))))
FreudenthalIso n A iscon = connectedTruncIso _ (σ n {A = A} iscon) (isConnectedσ _ iscon)
| 39.079137
| 103
| 0.547496
|
4371a7ea2f0a5d85b59dca5b39a7e86745127f4a
| 1,540
|
agda
|
Agda
|
Cubical/HITs/TypeQuotients/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/HITs/TypeQuotients/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/HITs/TypeQuotients/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-
Type quotients:
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.TypeQuotients.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.HITs.TypeQuotients.Base
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ'
B : A /ₜ R → Type ℓ''
C : A /ₜ R → A /ₜ R → Type ℓ''
elim : (f : (a : A) → (B [ a ]))
→ ((a b : A) (r : R a b) → PathP (λ i → B (eq/ a b r i)) (f a) (f b))
------------------------------------------------------------------------
→ (x : A /ₜ R) → B x
elim f feq [ a ] = f a
elim f feq (eq/ a b r i) = feq a b r i
rec : {X : Type ℓ''}
→ (f : A → X)
→ (∀ (a b : A) → R a b → f a ≡ f b)
-------------------------------------
→ A /ₜ R → X
rec f feq [ a ] = f a
rec f feq (eq/ a b r i) = feq a b r i
elimProp : ((x : A /ₜ R ) → isProp (B x))
→ ((a : A) → B ( [ a ]))
---------------------------------
→ (x : A /ₜ R) → B x
elimProp Bprop f [ a ] = f a
elimProp Bprop f (eq/ a b r i) = isOfHLevel→isOfHLevelDep 1 Bprop (f a) (f b) (eq/ a b r) i
elimProp2 : ((x y : A /ₜ R ) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
--------------------------------------
→ (x y : A /ₜ R) → C x y
elimProp2 Cprop f = elimProp (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp (λ y → Cprop [ x ] y) (f x))
| 28
| 91
| 0.438961
|
038e8f8610511ff21833c44e873ebe595b4c7979
| 7,919
|
agda
|
Agda
|
Cubical/Structures/Group.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Group.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Group.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.Group where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.FunExtEquiv
open import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_)
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Structures.Monoid
private
variable
ℓ ℓ' : Level
group-axiom : (X : Type ℓ) → monoid-structure X → Type ℓ
group-axiom G ((e , _·_) , _) = ((x : G) → Σ G (λ x' → (x · x' ≡ e) × (x' · x ≡ e)))
group-structure : Type ℓ → Type ℓ
group-structure = add-to-structure (monoid-structure) group-axiom
Groups : Type (ℓ-suc ℓ)
Groups {ℓ} = TypeWithStr ℓ group-structure
-- Extracting components of a group
⟨_⟩ : Groups {ℓ} → Type ℓ
⟨ (G , _) ⟩ = G
id : (G : Groups {ℓ}) → ⟨ G ⟩
id (_ , ((e , _) , _) , _) = e
group-operation : (G : Groups {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩ → ⟨ G ⟩
group-operation (_ , ((_ , f) , _) , _) = f
infixl 20 group-operation
syntax group-operation G x y = x ·⟨ G ⟩ y
group-is-set : (G : Groups {ℓ}) → isSet ⟨ G ⟩
group-is-set (_ , (_ , (P , _)) , _) = P
group-assoc : (G : Groups {ℓ})
→ (x y z : ⟨ G ⟩) → (x ·⟨ G ⟩ (y ·⟨ G ⟩ z)) ≡ ((x ·⟨ G ⟩ y) ·⟨ G ⟩ z)
group-assoc (_ , (_ , (_ , P , _)) , _) = P
group-runit : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → x ·⟨ G ⟩ (id G) ≡ x
group-runit (_ , (_ , (_ , _ , P , _)) , _) = P
group-lunit : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → (id G) ·⟨ G ⟩ x ≡ x
group-lunit (_ , (_ , (_ , _ , _ , P)) , _) = P
group-Σinv : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → Σ (⟨ G ⟩) (λ x' → (x ·⟨ G ⟩ x' ≡ (id G)) × (x' ·⟨ G ⟩ x ≡ (id G)))
group-Σinv (_ , _ , P) = P
-- Defining the inverse function
inv : (G : Groups {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩
inv (_ , _ , P) x = fst (P x)
group-rinv : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → x ·⟨ G ⟩ (inv G x) ≡ id G
group-rinv (_ , _ , P) x = fst (snd (P x))
group-linv : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → (inv G x) ·⟨ G ⟩ x ≡ id G
group-linv (_ , _ , P) x = snd (snd (P x))
-- Iso for groups are those for monoids
group-iso : StrIso group-structure ℓ
group-iso = add-to-iso monoid-structure monoid-iso group-axiom
-- Auxiliary lemmas for subtypes (taken from Escardo)
to-Σ-≡ : {X : Type ℓ} {A : X → Type ℓ'} {σ τ : Σ X A}
→ (Σ (fst σ ≡ fst τ) λ p → PathP (λ i → A (p i)) (snd σ) (snd τ))
→ σ ≡ τ
to-Σ-≡ (eq , p) = λ i → eq i , p i
to-subtype-≡ : {X : Type ℓ} {A : X → Type ℓ'} {x y : X}
{a : A x} {b : A y}
→ ((x : X) → isProp (A x))
→ x ≡ y
→ Path (Σ X (λ x → A x)) (x , a) (y , b)
to-subtype-≡ {x = x} {y} {a} {b} f eq = to-Σ-≡ (eq , toPathP (f y _ b))
-- TODO: this proof without toPathP?
-- Group axiom isProp
group-axiom-isProp : (X : Type ℓ)
→ (s : monoid-structure X)
→ isProp (group-axiom X s)
group-axiom-isProp X (((e , _·_) , s@(isSet , assoc , rid , lid))) = isPropPi γ
where
γ : (x : X) → isProp (Σ X (λ x' → (x · x' ≡ e) × (x' · x ≡ e)))
γ x (y , a , q) (z , p , b) = to-subtype-≡ u t
where
t : y ≡ z
t = inv-lemma X e _·_ s x y z q p
u : (x' : X) → isProp ((x · x' ≡ e) × (x' · x ≡ e))
u x' = isPropΣ (isSet _ _)
(λ _ → isSet _ _)
-- Group paths equivalent to equality
group-is-SNS : SNS {ℓ} group-structure group-iso
group-is-SNS = add-axioms-SNS monoid-structure monoid-iso
group-axiom group-axiom-isProp monoid-is-SNS
GroupPath : (M N : Groups {ℓ}) → (M ≃[ group-iso ] N) ≃ (M ≡ N)
GroupPath M N = SIP group-structure group-iso group-is-SNS M N
-- Trying to improve isomorphisms to only have to preserve
-- _·_
group-iso' : StrIso group-structure ℓ
group-iso' G S f =
(x y : ⟨ G ⟩) → equivFun f (x ·⟨ G ⟩ y) ≡ equivFun f x ·⟨ S ⟩ equivFun f y
-- Trying to reduce isomorphisms to simpler ones
-- First we prove that both notions of group-iso are equal
-- since both are props and there is are functions from
-- one to the other
-- Functions
group-iso→group-iso' : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩)
→ group-iso G S f → group-iso' G S f
group-iso→group-iso' G S f γ = snd γ
group-iso'→group-iso : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩)
→ group-iso' G S f → group-iso G S f
group-iso'→group-iso G S f γ = η , γ
where
g : ⟨ G ⟩ → ⟨ S ⟩
g = equivFun f
e : ⟨ G ⟩
e = id G
d : ⟨ S ⟩
d = id S
δ : g e ≡ g e ·⟨ S ⟩ g e
δ = g e ≡⟨ cong g (sym (group-lunit G _)) ⟩
g (e ·⟨ G ⟩ e) ≡⟨ γ e e ⟩
g e ·⟨ S ⟩ g e ∎
η : g e ≡ d
η = g e ≡⟨ sym (group-runit S _) ⟩
g e ·⟨ S ⟩ d ≡⟨ cong (λ - → g e ·⟨ S ⟩ -) (sym (group-rinv S _)) ⟩
g e ·⟨ S ⟩ (g e ·⟨ S ⟩ (inv S (g e))) ≡⟨ group-assoc S _ _ _ ⟩
(g e ·⟨ S ⟩ g e) ·⟨ S ⟩ (inv S (g e)) ≡⟨ cong (λ - → group-operation S - (inv S (g e))) (sym δ) ⟩
g e ·⟨ S ⟩ (inv S (g e)) ≡⟨ group-rinv S _ ⟩
d ∎
-- Both are Props
isProp-Iso : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩) → isProp (group-iso G S f)
isProp-Iso G S f = isPropΣ (group-is-set S _ _)
(λ _ → isPropPi (λ x → isPropPi λ y → group-is-set S _ _))
isProp-Iso' : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩) → isProp (group-iso' G S f)
isProp-Iso' G S f = isPropPi (λ x → isPropPi λ y → group-is-set S _ _)
-- Propositional equality
to-Prop-≡ : {X Y : Type ℓ} (f : X → Y) (g : Y → X)
→ isProp X → isProp Y
→ X ≡ Y
to-Prop-≡ {ℓ} {X} {Y} f g p q = isoToPath (iso f g aux₂ aux₁)
where
aux₁ : (x : X) → g (f x) ≡ x
aux₁ x = p _ _
aux₂ : (y : Y) → f (g y) ≡ y
aux₂ y = q _ _
-- Finally both are equal
group-iso'≡group-iso : group-iso' {ℓ} ≡ group-iso
group-iso'≡group-iso = funExt₃ γ
where
γ : ∀ (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩)
→ group-iso' G S f ≡ group-iso G S f
γ G S f = to-Prop-≡ (group-iso'→group-iso G S f)
(group-iso→group-iso' G S f)
(isProp-Iso' G S f)
(isProp-Iso G S f)
-- And Finally we have what we wanted
group-is-SNS' : SNS {ℓ} group-structure group-iso'
group-is-SNS' = transport γ group-is-SNS
where
γ : SNS {ℓ} group-structure group-iso ≡ SNS {ℓ} group-structure group-iso'
γ = cong (SNS group-structure) (sym group-iso'≡group-iso)
GroupPath' : (M N : Groups {ℓ}) → (M ≃[ group-iso' ] N) ≃ (M ≡ N)
GroupPath' M N = SIP group-structure group-iso' group-is-SNS' M N
---------------------------------------------------------------------
-- Abelians group (just add one axiom and prove that it is a hProp)
---------------------------------------------------------------------
abelian-group-axiom : (X : Type ℓ) → group-structure X → Type ℓ
abelian-group-axiom G (((_ , _·_), _), _) = (x y : G) → x · y ≡ y · x
abelian-group-structure : Type ℓ → Type ℓ
abelian-group-structure = add-to-structure (group-structure) abelian-group-axiom
AbGroups : Type (ℓ-suc ℓ)
AbGroups {ℓ} = TypeWithStr ℓ abelian-group-structure
abelian-group-iso : StrIso abelian-group-structure ℓ
abelian-group-iso = add-to-iso group-structure group-iso abelian-group-axiom
abelian-group-axiom-isProp : (X : Type ℓ)
→ (s : group-structure X)
→ isProp (abelian-group-axiom X s)
abelian-group-axiom-isProp X ((_ , (group-isSet , _)) , _) =
isPropPi (λ x → isPropPi λ y → group-isSet _ _)
abelian-group-is-SNS : SNS {ℓ} abelian-group-structure abelian-group-iso
abelian-group-is-SNS = add-axioms-SNS group-structure group-iso
abelian-group-axiom abelian-group-axiom-isProp group-is-SNS
AbGroupPath : (M N : AbGroups {ℓ}) → (M ≃[ abelian-group-iso ] N) ≃ (M ≡ N)
AbGroupPath M N = SIP abelian-group-structure abelian-group-iso abelian-group-is-SNS M N
| 33.133891
| 103
| 0.519636
|
222304ad04ae5ba648d6f7bc0a355fc4e17cf0d2
| 12,068
|
agda
|
Agda
|
src/Implicits/Substitutions/Lemmas.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Implicits/Substitutions/Lemmas.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Implicits/Substitutions/Lemmas.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
open import Prelude
module Implicits.Substitutions.Lemmas where
open import Implicits.Syntax.Type
open import Implicits.Syntax.Term hiding (var)
open import Implicits.Syntax.Context
open import Implicits.WellTyped
open import Implicits.Substitutions
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Vec.Properties
open import Extensions.Substitution
import Category.Applicative.Indexed as Applicative
open Applicative.Morphism using (op-<$>)
module TypeLemmas where
open import Implicits.Substitutions.Lemmas.Type public
open import Implicits.Substitutions.Lemmas.MetaType public
{-
module SubstLemmas (_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set) where
open TypingRules _⊢ᵣ_
private
⊢subst : ∀ {m n} {Γ₁ Γ₂ : Ktx n m} {t₁ t₂ : Term n m} {a₁ a₂ : Type n} →
Γ₁ ≡ Γ₂ → t₁ ≡ t₂ → a₁ ≡ a₂ → Γ₁ ⊢ t₁ ∈ a₁ → Γ₂ ⊢ t₂ ∈ a₂
⊢subst refl refl refl hyp = hyp
⊢substCtx : ∀ {m n} {Γ₁ Γ₂ : Ktx n m} {t : Term n m} {a : Type n} →
Γ₁ ≡ Γ₂ → Γ₁ ⊢ t ∈ a → Γ₂ ⊢ t ∈ a
⊢substCtx refl hyp = hyp
⊢substTp : ∀ {m n} {Γ : Ktx n m} {t : Term n m} {a₁ a₂ : Type n} →
a₁ ≡ a₂ → Γ ⊢ t ∈ a₁ → Γ ⊢ t ∈ a₂
⊢substTp refl hyp = hyp
module WtTermLemmas where
weaken : ∀ {ν n} {K : Ktx ν n} {t : Term ν n} {a b : Type ν} →
K ⊢ t ∈ a → b ∷Γ K ⊢ tmtm-weaken t ∈ a
-- weaken {Γ = Γ} {b = b} ⊢t = Var.wk /Var ⊢substCtx (C.wkVar-/Var-∷ Γ b) ⊢t
module TermTypeLemmas where
open TermTypeSubst
private module T = TypeLemmas
private module TS = TypeSubst
private module V = VarLemmas
/-↑⋆ :
∀ {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} →
let open TS.Lifted lift₁ using () renaming (_↑⋆_ to _↑⋆₁_; _/_ to _/tp₁_)
open Lifted lift₁ using () renaming (_/_ to _/₁_)
open TS.Lifted lift₂ using () renaming (_↑⋆_ to _↑⋆₂_; _/_ to _/tp₂_)
open Lifted lift₂ using () renaming (_/_ to _/₂_)
in
∀ {n k} (ρ₁ : Sub T₁ n k) (ρ₂ : Sub T₂ n k) →
(∀ i x → tvar x /tp₁ ρ₁ ↑⋆₁ i ≡ tvar x /tp₂ ρ₂ ↑⋆₂ i) →
∀ i {m} (t : Term (i N+ n) m) → t /₁ ρ₁ ↑⋆₁ i ≡ t /₂ ρ₂ ↑⋆₂ i
/-↑⋆ ρ₁ ρ₂ hyp i (new x) = refl
/-↑⋆ ρ₁ ρ₂ hyp i (var x) = refl
/-↑⋆ ρ₁ ρ₂ hyp i (Λ t) = cong Λ (/-↑⋆ ρ₁ ρ₂ hyp (1 N+ i) t)
/-↑⋆ ρ₁ ρ₂ hyp i (λ' a t) =
cong₂ λ' (T./-↑⋆ ρ₁ ρ₂ hyp i a) (/-↑⋆ ρ₁ ρ₂ hyp i t)
/-↑⋆ ρ₁ ρ₂ hyp i (t [ b ]) =
cong₂ _[_] (/-↑⋆ ρ₁ ρ₂ hyp i t) (T./-↑⋆ ρ₁ ρ₂ hyp i b)
/-↑⋆ ρ₁ ρ₂ hyp i (s · t) =
cong₂ _·_ (/-↑⋆ ρ₁ ρ₂ hyp i s) (/-↑⋆ ρ₁ ρ₂ hyp i t)
/-↑⋆ ρ₁ ρ₂ hyp i (x) = {!!}
/-wk : ∀ {m n} (t : Term m n) → t / TypeSubst.wk ≡ weaken t
/-wk t = /-↑⋆ TypeSubst.wk VarSubst.wk (λ k x → begin
tvar x T./ T.wk T.↑⋆ k ≡⟨ T.var-/-wk-↑⋆ k x ⟩
tvar (finlift k suc x) ≡⟨ cong tvar (sym (V.var-/-wk-↑⋆ k x)) ⟩
tvar (lookup x (V.wk V.↑⋆ k)) ≡⟨ refl ⟩
tvar x TS./Var V.wk V.↑⋆ k ∎) 0 t
module KtxLemmas where
open KtxSubst hiding (ktx-map)
private module Tp = TypeLemmas
private module Var = VarSubst
ktx-map-cong : ∀ {ν μ n} {f g : Type ν → Type μ} →
f ≗ g → _≗_ {A = Ktx ν n} (ktx-map f) (ktx-map g)
ktx-map-cong K = ?
-- Term variable substitution (renaming) commutes with type
-- substitution.
{-
/Var-/ : ∀ {m ν n l} (ρ : Sub Fin m n) (Γ : Ktx ν n) (σ : Sub Type ν l) →
(Γ /Var ρ) / σ ≡ Γ /Var (ρ / σ)
/Var-/ ρ Γ σ = begin
(ρ /Var Γ) / σ
≡⟨ sym (map-∘ _ _ ρ) ⟩
map (λ x → (lookup x Γ) Tp./ σ) ρ
≡⟨ map-cong (λ x → sym (Tp.lookup-⊙ x)) ρ ⟩
map (λ x → lookup x (Γ / σ)) ρ
∎
-- Term variable substitution (renaming) commutes with weakening of
-- typing contexts with an additional type variable.
/Var-weaken : ∀ {m n k} (ρ : Sub Fin m k) (Γ : Ctx n k) →
weaken (ρ /Var Γ) ≡ ρ /Var (weaken Γ)
/Var-weaken ρ Γ = begin
(ρ /Var Γ) / Tp.wk ≡⟨ ? ⟩ --/Var-/ ρ Γ Tp.wk
ρ /Var (weaken Γ) ∎
-}
-- Term variable substitution (renaming) commutes with term variable
-- lookup in typing context.
{-
/Var-lookup : ∀ {m n k} (x : Fin m) (ρ : Sub Fin m k) (Γ : Ctx n k) →
lookup x (ρ /Var Γ) ≡ lookup (lookup x ρ) Γ
/Var-lookup x ρ Γ = op-<$> (lookup-morphism x) _ _
-- Term variable substitution (renaming) commutes with weakening of
-- typing contexts with an additional term variable.
/Var-∷ : ∀ {m n k} (a : Type n) (ρ : Sub Fin m k) (Γ : Ctx n k) →
a ∷ (ρ /Var Γ) ≡ (ρ Var.↑) /Var (a ∷ Γ)
/Var-∷ a [] Γ = refl
/Var-∷ a (x ∷ ρ) Γ = cong (_∷_ a) (cong (_∷_ (lookup x Γ)) (begin
map (λ x → lookup x Γ) ρ ≡⟨ refl ⟩
map (λ x → lookup (suc x) (a ∷ Γ)) ρ ≡⟨ map-∘ _ _ ρ ⟩
map (λ x → lookup x (a ∷ Γ)) (map suc ρ) ∎))
-- Invariants of term variable substitution (renaming)
idVar-/Var : ∀ {m n} (Γ : Ctx n m) → Γ ≡ (Var.id /Var Γ)
wkVar-/Var-∷ : ∀ {m n} (Γ : Ctx n m) (a : Type n) → Γ ≡ (Var.wk /Var (a ∷ Γ))
idVar-/Var [] = refl
idVar-/Var (a ∷ Γ) = cong (_∷_ a) (wkVar-/Var-∷ Γ a)
wkVar-/Var-∷ Γ a = begin
Γ ≡⟨ idVar-/Var Γ ⟩
Var.id /Var Γ ≡⟨ map-∘ _ _ VarSubst.id ⟩
Var.wk /Var (a ∷ Γ) ∎
ctx-weaken-sub-vanishes : ∀ {ν n} {Γ : Ktx ν n} {a} → (ktx-weaken Γ) / (Tp.sub a) ≡ Γ
ctx-weaken-sub-vanishes {Γ = Γ} {a} = begin
(Γ / Tp.wk) / (Tp.sub a)
≡⟨ sym $ map-∘ (λ s → s tp/tp Tp.sub a) (λ s → s tp/tp Tp.wk) Γ ⟩
(map (λ s → s tp/tp Tp.wk tp/tp (Tp.sub a)) Γ)
≡⟨ map-cong (TypeLemmas.wk-sub-vanishes) Γ ⟩
(map (λ s → s) Γ) ≡⟨ map-id Γ ⟩
Γ ∎
-}
module WtTypeLemmas where
open TypeLemmas hiding (_/_; weaken)
private
module Tp = TypeLemmas
module TmTp = TermTypeLemmas
module C = KtxLemmas
infixl 8 _/_
-- Type substitutions lifted to well-typed terms
_/_ : ∀ {m n k} {Γ : Ktx n m} {t : Term n m} {a : Type n} →
Γ ⊢ t ∈ a → (σ : Sub Type n k) → Γ ktx/ σ ⊢ t tm/tp σ ∈ a Tp./ σ
new c / σ = new c
var x / σ = ⊢substTp (lookup-⊙ x) (var x)
_/_ {Γ = Γ} (Λ ⊢t) σ = Λ (⊢substCtx eq (⊢t / σ ↑))
where
eq : (ktx-weaken Γ) ktx/ (σ Tp.↑) ≡ ktx-weaken (Γ ktx/ σ)
{-
eq = begin
(ktx-map (λ s → s tp/tp Tp.wk) Γ) ktx/ (σ Tp.↑)
≡⟨ KtxLemmas.ktx-map-cong (λ a → a ktx/ (σ Tp.↑))
(KtxLemmas.ktx-map-cong (λ a → Tp./-wk {t = a}) Γ) ⟩
(ktx-map Tp.weaken Γ) ⊙ (σ Tp.↑)
≡⟨ sym $ map-weaken-⊙ Γ σ ⟩
map Tp.weaken (Γ ⊙ σ)
≡⟨ (map-cong (λ a → sym $ Tp./-wk {t = a}) (Γ ⊙ σ)) ⟩
ktx-weaken (Γ ktx/ σ) ∎
-}
λ' a ⊢t / σ = λ' (a Tp./ σ) (⊢t / σ)
_[_] {a = a} ⊢t b / σ = ⊢substTp (sym (sub-commutes a)) ((⊢t / σ) [ b Tp./ σ ])
⊢s · ⊢t / σ = (⊢s / σ) · (⊢t / σ)
x / σ = ?
-- Weakening of terms with additional type variables lifted to
-- well-typed terms.
weaken : ∀ {m n} {Γ : Ktx n m} {t : Term n m} {a : Type n} →
Γ ⊢ t ∈ a → ktx-weaken Γ ⊢ tm-weaken t ∈ Tp.weaken a
weaken {t = t} {a = a} ⊢t = ⊢subst refl (TmTp./-wk t) (/-wk {t = a}) (⊢t / wk)
-- Weakening of terms with additional type variables lifted to
-- collections of well-typed terms.
weakenAll : ∀ {m n k} {Γ : Ktx n m} {ts : Vec (Term n m) k}
{as : Vec (Type n) k} → Γ ⊢ⁿ ts ∈ as →
ktx-weaken Γ ⊢ⁿ map tm-weaken ts ∈ map Tp.weaken as
weakenAll {ts = []} {[]} [] = []
weakenAll {ts = _ ∷ _} {_ ∷ _} (⊢t ∷ ⊢ts) = weaken ⊢t ∷ weakenAll ⊢ts
-- Shorthand for single-variable type substitutions in well-typed
-- terms.
_[/_] : ∀ {m n} {Γ : Ktx (1 N+ n) m} {t a} →
Γ ⊢ t ∈ a → (b : Type n) → Γ ktx/ sub b ⊢ t tm/tp sub b ∈ a Tp./ sub b
⊢t [/ b ] = ⊢t / sub b
{-
tm[/tp]-preserves : ∀ {ν n} {Γ : Ctx ν n} {t τ} → Γ ⊢ Λ t ∈ ∀' τ → ∀ a → Γ ⊢ (t tm[/tp a ]) ∈ τ tp[/tp a ]
tm[/tp]-preserves {Γ = Γ} {t} {τ} (Λ p) a = ctx-subst C.ctx-weaken-sub-vanishes (p / (Tp.sub a))
where
ctx-subst = Prelude.subst (λ c → c ⊢ t tm[/tp a ] ∈ τ tp[/tp a ])
-}
module WtTermLemmas where
private
module Tp = TypeLemmas
module TmTp = TermTypeLemmas
module TmTm = TermTermSubst
module Var = VarSubst
module C = KtxLemmas
TmSub = TmTm.TermSub Term
infix 4 _⇒_⊢_
-- Well-typed term substitutions are collections of well-typed terms.
_⇒_⊢_ : ∀ {ν m k} → Ktx ν m → Ktx ν k → TmSub ν m k → Set
Γ ⇒ Δ ⊢ s = Δ ⊢ⁿ s ∈ (proj₁ Γ)
infixl 8 _/_ _/Var_
infix 10 _↑
-- Application of term variable substitutions (renaming) lifted to
-- well-typed terms.
_/Var_ : ∀ {ν m n} {K : Ktx ν n} {t : Term ν m} {a : Type ν}
(s : Sub Fin m n) → s ktx/Var K ⊢ t ∈ a → K ⊢ t TmTm./Var s ∈ a
_/Var_ {K = K} s (new c) = new c
_/Var_ {K = K} s (var x) = ?
-- ⊢substTp (sym (ktx/Var-lookup x ρ Γ)) (var (lookup x ρ))
_/Var_ {K = K} s (Λ ⊢t) = ?
-- Λ (ρ /Var ⊢substCtx (ktx/Var-weaken ρ Γ) ⊢t)
_/Var_ {K = K} s (λ' a ⊢t) = ?
-- λ' a (ρ Var.↑ /Var ⊢substCtx (ktx/Var-∷ a ρ Γ) ⊢t)
s /Var (⊢t [ b ]) = (s /Var ⊢t) [ b ]
s /Var (⊢s · ⊢t) = (s /Var ⊢s) · (s /Var ⊢t)
s /Var (x) = ?
-- Weakening of terms with additional term variables lifted to
-- well-typed terms.
weaken : ∀ {ν n} {K : Ktx ν n} {t : Term ν n} {a b : Type ν} →
K ⊢ t ∈ a → b ∷Γ K ⊢ TmTm.weaken t ∈ a
weaken {K = K} {b = b} ⊢t = ? -- Var.wk /Var ⊢substCtx (C.wkVar-/Var-∷ Γ b) ⊢t
-- Weakening of terms with additional term variables lifted to
-- collections of well-typed terms.
weakenAll : ∀ {ν n k} {K : Ktx ν n} {ts : Vec (Term ν n) k}
{as : Vec (Type ν) k} {b : Type ν} →
K ⊢ⁿ ts ∈ as → (b ∷Γ K) ⊢ⁿ map TmTm.weaken ts ∈ as
weakenAll {ts = []} {[]} [] = []
weakenAll {ts = _ ∷ _} {_ ∷ _} (⊢t ∷ ⊢ts) = weaken ⊢t ∷ weakenAll ⊢ts
-- Lifting of well-typed term substitutions.
_↑ : ∀ {ν n} {Γ : Ktx ν n} {Δ : Ktx ν n} {ρ b} →
Γ ⇒ Δ ⊢ ρ → b ∷Γ Γ ⇒ b ∷Γ Δ ⊢ ρ TmTm.↑
⊢ρ ↑ = var zero ∷ weakenAll ⊢ρ
-- The well-typed identity substitution.
id : ∀ {ν n} {K : Ktx ν n} → K ⇒ K ⊢ TmTm.id
id {K = K} = ?
-- id {zero} {._} {K = [] , _} = []
-- id {suc _} {._} {K = a ∷ Γ , _} = id ↑
-- Well-typed weakening (as a substitution).
wk : ∀ {m n} {Γ : Ktx n m} {a} → Γ ⇒ a ∷Γ Γ ⊢ TmTm.wk
wk = weakenAll id
-- A well-typed substitution which only replaces the first variable.
sub : ∀ {ν n} {K : Ktx ν n} {t a} → K ⊢ t ∈ a → a ∷Γ K ⇒ K ⊢ TmTm.sub t
sub ⊢t = ⊢t ∷ id
-- Application of term substitutions lifted to well-typed terms
_/_ : ∀ {ν n} {K : Ktx ν n} {Δ : Ktx ν n} {t a s} →
K ⊢ t ∈ a → K ⇒ Δ ⊢ s → Δ ⊢ t TmTm./ s ∈ a
new c / ⊢ρ = new c
var x / ⊢ρ = lookup-⊢ x ⊢ρ
_/_ {K = K} {Δ = Δ} {s = s} (Λ ⊢t) ⊢ρ = Λ (⊢t / weaken-⊢p)
where
weaken-⊢p : ktx-weaken K ⇒ ktx-weaken Δ ⊢ map tm-weaken s
weaken-⊢p = (WtTypeLemmas.weakenAll ⊢ρ)
λ' a ⊢t / ⊢ρ = λ' a (⊢t / ⊢ρ ↑)
(⊢t [ a ]) / ⊢ρ = (⊢t / ⊢ρ) [ a ]
(⊢s · ⊢t) / ⊢ρ = (⊢s / ⊢ρ) · (⊢t / ⊢ρ)
-- Shorthand for well-typed single-variable term substitutions.
_[/_] : ∀ {m n} {Γ : Ctx n m} {s t a b} →
b ∷ Γ ⊢ s ∈ a → Γ ⊢ t ∈ b → Γ ⊢ s TmTm./ TmTm.sub t ∈ a
⊢s [/ ⊢t ] = ⊢s / sub ⊢t
tm[/tm]-preserves : ∀ {ν n} {Γ : Ctx ν n} {t u a b} →
b ∷ Γ ⊢ t ∈ a → Γ ⊢ u ∈ b → Γ ⊢ (t tm[/tm u ]) ∈ a
tm[/tm]-preserves ⊢s ⊢t = ⊢s / sub ⊢t
open WtTypeLemmas public using ()
renaming (weaken to ⊢tp-weaken)
open WtTermLemmas public using ()
renaming (_/_ to _⊢/tp_; _[/_] to _⊢[/_]; weaken to ⊢weaken)
-}
| 39.567213
| 110
| 0.481936
|
350c260bace00e0f4d23b468abe033840940f151
| 1,481
|
agda
|
Agda
|
test/Succeed/DataRecordInductive.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/DataRecordInductive.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/DataRecordInductive.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module DataRecordInductive where
module NotMutual where
record Nil (A : Set) : Set where
constructor []
record Cons (A X : Set) : Set where
constructor _∷_
field head : A
tail : X
open Cons
data List (A : Set) : Set where
nil : Nil A → List A
cons : Cons A (List A) → List A
-- works
module Constr where
map : {A B : Set} → (A → B) → List A → List B
map f (nil []) = nil []
map f (cons (x ∷ xs)) = cons (f x ∷ map f xs)
-- works, since projections are size preserving
module Proj where
map : {A B : Set} → (A → B) → List A → List B
map f (nil _) = nil []
map f (cons p) = cons (f (head p) ∷ map f (tail p))
module Mutual where
mutual
data List (A : Set) : Set where
nil : Nil A → List A
cons : Cons A → List A
record Nil (A : Set) : Set where
constructor []
-- since Cons is inductive, we are not creating colists
record Cons (A : Set) : Set where
inductive
constructor _∷_
field head : A
tail : List A
open Cons
-- works
module Constr where
map : {A B : Set} → (A → B) → List A → List B
map f (nil []) = nil []
map f (cons (x ∷ xs)) = cons (f x ∷ map f xs)
-- works, since projections of an inductive record are size-preserving
module Proj where
map : {A B : Set} → (A → B) → List A → List B
map f (nil _) = nil []
map f (cons p) = cons (f (head p) ∷ map f (tail p))
| 22.439394
| 72
| 0.540176
|
43d973e1752627e585df4a6379fa6ecae73e0798
| 292
|
agda
|
Agda
|
test/Succeed/Issue708.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue708.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue708.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
postulate
String : Set
{-# BUILTIN STRING String #-}
record ⊤ : Set where
constructor tt
data Bool : Set where
true false : Bool
nonEmpty : String → Set
nonEmpty "" = Bool
nonEmpty _ = ⊤
foo : ∀ s → nonEmpty s → Bool
foo "" true = true
foo "" false = false
foo s p = false
| 13.904762
| 29
| 0.623288
|
19688adbc28545d38471f0549a3b9e22f21ccb26
| 517
|
agda
|
Agda
|
test/Fail/Issue1974.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/Issue1974.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue1974.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
record R₁ (F : Set → Set) : Set₁ where
constructor mkR₁
field
f₁ : ∀ {A} → A → F A
open R₁ {{...}}
record R₂ (F : Set → Set) : Set₁ where
constructor mkR₂
field
instance
r₁ : R₁ F
record R₃ (_ : Set) : Set where
constructor mkR₃
postulate
instance
r₃ : R₂ R₃
A : Set
a : A
record R₄ : Set where
constructor c
field
f₂ : A
postulate
F : (r₄ : R₄) → c a ≡ r₄ → Set
G : Set → Set
G _ = F _ (refl {x = f₁ a})
| 13.605263
| 42
| 0.541586
|
343c645c216a8355e3e7ea3a9575893f95772fac
| 832
|
agda
|
Agda
|
test/Fail/Issue503.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue503.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue503.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- div shouldn't termination check, but it also shouldn't make the termination
-- checker loop.
module Issue503 where
data Bool : Set where
true : Bool
false : Bool
if_then_else_ : {C : Set} -> Bool -> C -> C -> C
if true then a else b = a
if false then a else b = b
data Nat : Set where
zero : Nat
succ : Nat -> Nat
pred : Nat -> Nat
pred zero = zero
pred (succ n) = n
_+_ : Nat -> Nat -> Nat
zero + b = b
succ a + b = succ (a + b)
_*_ : Nat -> Nat -> Nat
zero * _ = zero
succ a * b = (a * b) + b
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
_-_ : Nat -> Nat -> Nat
a - zero = a
a - succ b = pred (a - b)
_<_ : Nat -> Nat -> Bool
a < zero = false
zero < succ b = true
succ a < succ b = a < b
div : Nat -> Nat -> Nat
div m n = if (m < n) then zero else succ (div (m - n) n)
| 18.909091
| 78
| 0.570913
|
34fc866f73b8900a2e1d80e718a797433fc14ed6
| 1,203
|
agda
|
Agda
|
test/bugs/SizedTypesMergeSort.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/bugs/SizedTypesMergeSort.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/bugs/SizedTypesMergeSort.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS --sized-types #-}
module SizedTypesMergeSort where
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
-- sized lists
data List (A : Set) : {_ : Size} -> Set where
[] : {size : Size} -> List A {size ^}
_::_ : {size : Size} -> A -> List A {size} -> List A {size ^}
-- CPS split
split : {A : Set}{i : Size} -> List A {i} ->
{C : Set} -> (List A {i} -> List A {i} -> C) -> C
split [] k = k [] []
split (x :: xs) k = split xs (\ l r -> k (x :: r) l)
module Sort (A : Set) (compare : A -> A -> {B : Set} -> B -> B -> B) where
{- merge is currently rejected by the termination checker
it would be nice if it worked
see test/succeed/SizedTypesMergeSort.agda
-}
merge : List A -> List A -> List A
merge [] ys = ys
merge xs [] = xs
merge (x :: xs) (y :: ys) =
compare x y (x :: merge xs (y :: ys))
(y :: merge (x :: xs) ys)
sort : {i : Size} -> List A {i} -> List A
sort [] = []
sort (x :: []) = x :: []
sort (x :: (y :: xs)) = split xs (\ l r -> merge (sort (x :: l))
(sort (y :: r)))
| 26.152174
| 74
| 0.467165
|
345e1cf559045dd78cfed971f643962d3afdde6a
| 248
|
agda
|
Agda
|
test/Fail/Issue3810a.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue3810a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue3810a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
postulate
A : Set
a b : A
f : A → A
rew₁ : f a ≡ b
rew₂ : f ≡ λ _ → a
{-# REWRITE rew₁ #-}
{-# REWRITE rew₂ #-}
| 16.533333
| 46
| 0.612903
|
04e6bbd610bb29a7d72dda52fb06c38ec16bac54
| 533
|
agda
|
Agda
|
agda-stdlib/src/Data/Vec/All/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Vec/All/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Vec/All/Properties.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.Vec.Relation.Unary.All.Properties directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.All.Properties where
open import Data.Vec.Relation.Unary.All.Properties public
{-# WARNING_ON_IMPORT
"Data.Vec.All.Properties was deprecated in v1.0.
Use Data.Vec.Relation.Unary.All.Properties instead."
#-}
| 29.611111
| 72
| 0.545966
|
c7b55ecd6bacf1fb6d27a0ad1291b4dc1337b30c
| 363
|
agda
|
Agda
|
test/Fail/Issue5294.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue5294.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue5294.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₁ (_ : Set) where
postulate
A : Set
record R : Set₁ where
field
A : Set
module M₂ (r : R) where
open M₁ (R.A r) public
module Unused (A : Set) (_ : Set) where
open M₁ A public
postulate
r : R
open M₂ r
postulate
P : A → Set
data D : Set where
c : D
F : D → Set
F c = A
_ : ∀ x → F x → Set
_ = λ _ r → P r
| 10.083333
| 39
| 0.559229
|
5e30bc20cf17ed2db0399c26a9291d5dc1445cf6
| 768
|
agda
|
Agda
|
src/fot/Common/FOL/FOL-Eq.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/Common/FOL/FOL-Eq.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/Common/FOL/FOL-Eq.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- First-order logic with equality
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module exported all the logical constants and the
-- propositional equality. This module is re-exported by the "base"
-- modules whose theories are defined on first-order logic + equality.
module Common.FOL.FOL-Eq where
-- First-order logic (without equality).
open import Common.FOL.FOL public
-- Propositional equality.
open import Common.FOL.Relation.Binary.PropositionalEquality public
| 36.571429
| 78
| 0.552083
|
34df05fcfee1e8b7b0114d0d49b56de9dba58593
| 2,729
|
agda
|
Agda
|
src/Optics/Example.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Optics/Example.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Optics/Example.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 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 Data.Nat
open import Data.Maybe
open import Data.Char
open import Data.String
open import Data.List hiding (product)
open import Relation.Binary.PropositionalEquality
import Relation.Binary.PropositionalEquality as PE
using (_≡_; refl)
import Relation.Binary.Definitions as BD
import Relation.Binary as RB
------------------------------------------------------------------------------
open import Function
open import Optics.All
module Optics.Example where
infixl 1 _&_
_&_ = Function._|>_
-- First we declare a record; which must be EXACTLY
-- like the record 'Person' below.
-- that is; must contain a constructor and
-- a number of /simple/ fields (of type Set; no proofs please!)
record Person : Set where
constructor person
field
pName : String
pAge : ℕ
-- Then, we do some template agda:
-- Yes,I know it looks weird; but it says:
-- Put 'pName' and 'pAge' into scope as
-- new identifiers; and run the metacomputation mkLens
-- passing this newly created identifiers; the mkLens
-- will then bind these identifiers to their respective
-- generated lenses for the record Person
--
-- IMPORTANT: Note how I did NOT /open Person/; otherwise, we'd
-- have to give different names to the lenses.
--
-- IMPORTANT: the list of names passed to unquoteDecl must come
-- in the same order as the fields of Person.
unquoteDecl pName pAge = mkLens (quote Person) (pName ∷ pAge ∷ [])
-- Ok; lets do more recors for fun
record Store : Set where
constructor store
field
sId : ℕ
sManager : Person
unquoteDecl sId sManager = mkLens (quote Store) (sId ∷ sManager ∷ [])
record Product : Set where
constructor product
field
pId : ℕ
pTag : String
pStore : Store
unquoteDecl pId pTag pStore = mkLens (quote Product)
(pId ∷ pTag ∷ pStore ∷ [])
-- Let's now do a simple example:
mary : Person
mary = person "Mary" 41
compilers-from-mary : Store
compilers-from-mary = store 0 mary
ghc : Product
ghc = product 13 "v8.0.0" compilers-from-mary
-- Now say mary turns 42 years old;
ghc-from-older-mary : Product
ghc-from-older-mary = ghc & pStore ∙ sManager ∙ pAge ∙~ 42
same-ghc-from-mary : Product
same-ghc-from-mary = ghc & pStore ∙ sManager ∙ pAge %~ suc
all-is-fine : ghc-from-older-mary ≡ same-ghc-from-mary
all-is-fine = refl
mary's-age-was-updated : ghc-from-older-mary ^∙ pStore ∙ sManager ∙ pAge ≡ 42
mary's-age-was-updated = refl
| 28.427083
| 111
| 0.679736
|
4172c9d030e847a9349a32e38ab33174d2718228
| 44,796
|
agda
|
Agda
|
Agda/08-fundamental-theorem.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/08-fundamental-theorem.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/08-fundamental-theorem.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split #-}
module 08-fundamental-theorem where
import 07-contractible-types
open 07-contractible-types public
-- Section 8.1 Families of equivalences
{- Any family of maps induces a map on the total spaces. -}
tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → ( Σ A B → Σ A C)
tot f t = pair (pr1 t) (f (pr1 t) (pr2 t))
{- We show that for any family of maps, the fiber of the induced map on total
spaces are equivalent to the fibers of the maps in the family. -}
fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (tot f) t → fib (f (pr1 t)) (pr2 t)
fib-ftr-fib-tot f .(pair x (f x y)) (pair (pair x y) refl) = pair y refl
fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (f (pr1 t)) (pr2 t) → fib (tot f) t
fib-tot-fib-ftr F (pair a .(F a y)) (pair y refl) = pair (pair a y) refl
issec-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-ftr-fib-tot f t) ∘ (fib-tot-fib-ftr f t)) ~ id
issec-fib-tot-fib-ftr f (pair x .(f x y)) (pair y refl) = refl
isretr-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-tot-fib-ftr f t) ∘ (fib-ftr-fib-tot f t)) ~ id
isretr-fib-tot-fib-ftr f .(pair x (f x y)) (pair (pair x y) refl) = refl
abstract
is-equiv-fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-ftr-fib-tot f t)
is-equiv-fib-ftr-fib-tot f t =
is-equiv-has-inverse
( fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
( isretr-fib-tot-fib-ftr f t)
abstract
is-equiv-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-tot-fib-ftr f t)
is-equiv-fib-tot-fib-ftr f t =
is-equiv-has-inverse
( fib-ftr-fib-tot f t)
( isretr-fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
{- Now that we have shown that the fibers of the induced map on total spaces
are equivalent to the fibers of the maps in the family, it follows that
the induced map on total spaces is an equivalence if and only if each map
in the family is an equivalence. -}
is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → UU (i ⊔ (j ⊔ k))
is-fiberwise-equiv f = (x : _) → is-equiv (f x)
abstract
is-equiv-tot-is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
{f : (x : A) → B x → C x} → is-fiberwise-equiv f →
is-equiv (tot f )
is-equiv-tot-is-fiberwise-equiv {f = f} H =
is-equiv-is-contr-map
( λ t → is-contr-is-equiv _
( fib-ftr-fib-tot f t)
( is-equiv-fib-ftr-fib-tot f t)
( is-contr-map-is-equiv (H _) (pr2 t)))
abstract
is-fiberwise-equiv-is-equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → is-equiv (tot f) →
is-fiberwise-equiv f
is-fiberwise-equiv-is-equiv-tot {A = A} {B} {C} f is-equiv-tot-f x =
is-equiv-is-contr-map
( λ z → is-contr-is-equiv'
( fib (tot f) (pair x z))
( fib-ftr-fib-tot f (pair x z))
( is-equiv-fib-ftr-fib-tot f (pair x z))
( is-contr-map-is-equiv is-equiv-tot-f (pair x z)))
equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x ≃ C x) → (Σ A B) ≃ (Σ A C)
equiv-tot e =
pair
( tot (λ x → map-equiv (e x)))
( is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-map-equiv (e x)))
{- In the second part of this section we show that any equivalence f on base
types also induces an equivalence on total spaces. -}
Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
Σ A (λ x → C (f x)) → Σ B C
Σ-map-base-map f C s = pair (f (pr1 s)) (pr2 s)
{- The proof is similar to the previous part: we show that the fibers of f
and Σ-kap-base-map f C are equivalent. -}
fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib f (pr1 t) → fib (Σ-map-base-map f C) t
fib-Σ-map-base-map-fib f C (pair .(f x) z) (pair x refl) =
pair (pair x z) refl
fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib (Σ-map-base-map f C) t → fib f (pr1 t)
fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
pair x refl
issec-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-Σ-map-base-map-fib f C t) ∘ (fib-fib-Σ-map-base-map f C t)) ~ id
issec-fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
refl
isretr-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-fib-Σ-map-base-map f C t) ∘ (fib-Σ-map-base-map-fib f C t)) ~ id
isretr-fib-fib-Σ-map-base-map f C (pair .(f x) z) (pair x refl) = refl
abstract
is-equiv-fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → is-equiv (fib-Σ-map-base-map-fib f C t)
is-equiv-fib-Σ-map-base-map-fib f C t =
is-equiv-has-inverse
( fib-fib-Σ-map-base-map f C t)
( issec-fib-fib-Σ-map-base-map f C t)
( isretr-fib-fib-Σ-map-base-map f C t)
abstract
is-contr-map-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-contr-map f → is-contr-map (Σ-map-base-map f C)
is-contr-map-Σ-map-base-map C f is-contr-f (pair y z) =
is-contr-is-equiv'
( fib f y)
( fib-Σ-map-base-map-fib f C (pair y z))
( is-equiv-fib-Σ-map-base-map-fib f C (pair y z))
( is-contr-f y)
abstract
is-equiv-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-equiv f → is-equiv (Σ-map-base-map f C)
is-equiv-Σ-map-base-map C f is-equiv-f =
is-equiv-is-contr-map
( is-contr-map-Σ-map-base-map C f (is-contr-map-is-equiv is-equiv-f))
{- Now we combine the two parts of this section. -}
toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
Σ A C → Σ B D
toto D f g t = pair (f (pr1 t)) (g (pr1 t) (pr2 t))
triangle-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
(toto D f g) ~ ((Σ-map-base-map f D) ∘ (tot g))
triangle-toto D f g t = refl
abstract
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → (is-fiberwise-equiv g) →
is-equiv (toto D f g)
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map
D f g is-equiv-f is-fiberwise-equiv-g =
is-equiv-comp
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
equiv-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (e : A ≃ B) (g : (x : A) → C x ≃ D (map-equiv e x)) →
Σ A C ≃ Σ B D
equiv-toto D e g =
pair
( toto D (map-equiv e) (λ x → map-equiv (g x)))
( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map D
( map-equiv e)
( λ x → map-equiv (g x))
( is-equiv-map-equiv e)
( λ x → is-equiv-map-equiv (g x)))
abstract
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → is-equiv (toto D f g) → is-fiberwise-equiv g
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map
D f g is-equiv-f is-equiv-toto-fg =
is-fiberwise-equiv-is-equiv-tot g
( is-equiv-right-factor
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
( is-equiv-toto-fg))
-- Section 8.2 The fundamental theorem
-- The general form of the fundamental theorem of identity types
abstract
fundamental-theorem-id :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → (f : (x : A) → Id a x → B x) → is-fiberwise-equiv f
fundamental-theorem-id {A = A} a b is-contr-AB f =
is-fiberwise-equiv-is-equiv-tot f
( is-equiv-is-contr (tot f) (is-contr-total-path a) is-contr-AB)
abstract
fundamental-theorem-id' :
{i j : Level} {A : UU i} {B : A → UU j}
(a : A) (b : B a) (f : (x : A) → Id a x → B x) →
is-fiberwise-equiv f → is-contr (Σ A B)
fundamental-theorem-id' {A = A} {B = B} a b f is-fiberwise-equiv-f =
is-contr-is-equiv'
( Σ A (Id a))
( tot f)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-f)
( is-contr-total-path a)
-- The canonical form of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → is-fiberwise-equiv (ind-Id a (λ x p → B x) b)
fundamental-theorem-id-J {i} {j} {A} {B} a b is-contr-AB =
fundamental-theorem-id a b is-contr-AB (ind-Id a (λ x p → B x) b)
-- The converse of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J' :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-fiberwise-equiv (ind-Id a (λ x p → B x) b)) → is-contr (Σ A B)
fundamental-theorem-id-J' {i} {j} {A} {B} a b H =
is-contr-is-equiv'
( Σ A (Id a))
( tot (ind-Id a (λ x p → B x) b))
( is-equiv-tot-is-fiberwise-equiv H)
( is-contr-total-path a)
-- As an application we show that equivalences are embeddings.
is-emb :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-emb f = (x y : _) → is-equiv (ap f {x} {y})
_↪_ :
{i j : Level} → UU i → UU j → UU (i ⊔ j)
A ↪ B = Σ (A → B) is-emb
map-emb :
{i j : Level} {A : UU i} {B : UU j} → A ↪ B → A → B
map-emb f = pr1 f
is-emb-map-emb :
{ i j : Level} {A : UU i} {B : UU j} (f : A ↪ B) → is-emb (map-emb f)
is-emb-map-emb f = pr2 f
abstract
is-emb-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → is-equiv f → is-emb f
is-emb-is-equiv {i} {j} {A} {B} f is-equiv-f x =
fundamental-theorem-id x refl
( is-contr-equiv
( fib f (f x))
( equiv-tot (λ y → equiv-inv (f x) (f y)))
( is-contr-map-is-equiv is-equiv-f (f x)))
( λ y p → ap f p)
equiv-ap :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x y : A) →
(Id x y) ≃ (Id (map-equiv e x) (map-equiv e y))
equiv-ap e x y =
pair
( ap (map-equiv e) {x} {y})
( is-emb-is-equiv (map-equiv e) (is-equiv-map-equiv e) x y)
-- Section 7.3 Identity systems
IND-identity-system :
{i j : Level} (k : Level) {A : UU i} (B : A → UU j) (a : A) (b : B a) → UU _
IND-identity-system k {A} B a b =
( P : (x : A) (y : B x) → UU k) →
sec (λ (h : (x : A) (y : B x) → P x y) → h a b)
fam-Σ :
{i j k : Level} {A : UU i} {B : A → UU j} (C : (x : A) → B x → UU k) →
Σ A B → UU k
fam-Σ C (pair x y) = C x y
abstract
ind-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) (P : (x : A) → B x → UU k) →
P a b → (x : A) (y : B x) → P x y
ind-identity-system a b is-contr-AB P p x y =
tr
( fam-Σ P)
( is-prop-is-contr' is-contr-AB (pair a b) (pair x y))
( p)
comp-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
(P : (x : A) → B x → UU k) (p : P a b) →
Id (ind-identity-system a b is-contr-AB P p a b) p
comp-identity-system a b is-contr-AB P p =
ap
( λ t → tr (fam-Σ P) t p)
( is-prop-is-contr'
( is-prop-is-contr is-contr-AB (pair a b) (pair a b))
( is-prop-is-contr' is-contr-AB (pair a b) (pair a b))
( refl))
Ind-identity-system :
{i j : Level} (k : Level) {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
IND-identity-system k B a b
Ind-identity-system k a b is-contr-AB P =
pair
( ind-identity-system a b is-contr-AB P)
( comp-identity-system a b is-contr-AB P)
contraction-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(t : Σ A B) → Id (pair a b) t
contraction-total-space-IND-identity-system a b ind (pair x y) =
pr1 (ind (λ x' y' → Id (pair a b) (pair x' y'))) refl x y
abstract
is-contr-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b → is-contr (Σ A B)
is-contr-total-space-IND-identity-system a b ind =
pair
( pair a b)
( contraction-total-space-IND-identity-system a b ind)
abstract
fundamental-theorem-id-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(f : (x : A) → Id a x → B x) → (x : A) → is-equiv (f x)
fundamental-theorem-id-IND-identity-system a b ind f =
fundamental-theorem-id a b (is-contr-total-space-IND-identity-system a b ind) f
-- Section 7.4 Disjointness of coproducts
-- Raising universe levels
postulate Raise : {l1 : Level} (l2 : Level) → (A : UU l1) → Σ (UU (l1 ⊔ l2)) (λ X → A ≃ X)
abstract
raise :
{l1 : Level} (l2 : Level) → UU l1 → UU (l1 ⊔ l2)
raise l2 A = pr1 (Raise l2 A)
equiv-raise :
{l1 : Level} (l2 : Level) (A : UU l1) → A ≃ raise l2 A
equiv-raise l2 A = pr2 (Raise l2 A)
map-raise :
{l1 : Level} (l2 : Level) (A : UU l1) → A → raise l2 A
map-raise l2 A = map-equiv (equiv-raise l2 A)
is-equiv-map-raise :
{l1 : Level} (l2 : Level) (A : UU l1) →
is-equiv (map-raise l2 A)
is-equiv-map-raise l2 A = is-equiv-map-equiv (equiv-raise l2 A)
-- Lemmas about coproducts
left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) → Σ (coprod A B) C →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
left-distributive-coprod-Σ-map A B C (pair (inl x) z) = inl (pair x z)
left-distributive-coprod-Σ-map A B C (pair (inr y) z) = inr (pair y z)
inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y))) → Σ (coprod A B) C
inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = pair (inl x) z
inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = pair (inr y) z
issec-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (left-distributive-coprod-Σ-map A B C) ∘
(inv-left-distributive-coprod-Σ-map A B C)) ~ id
issec-inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = refl
issec-inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = refl
isretr-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (inv-left-distributive-coprod-Σ-map A B C) ∘
(left-distributive-coprod-Σ-map A B C)) ~ id
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inl x) z) = refl
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inr y) z) = refl
abstract
is-equiv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
is-equiv (left-distributive-coprod-Σ-map A B C)
is-equiv-left-distributive-coprod-Σ-map A B C =
is-equiv-has-inverse
( inv-left-distributive-coprod-Σ-map A B C)
( issec-inv-left-distributive-coprod-Σ-map A B C)
( isretr-inv-left-distributive-coprod-Σ-map A B C)
equiv-left-distributive-coprod-Σ :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
Σ (coprod A B) C ≃ coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
equiv-left-distributive-coprod-Σ A B C =
pair ( left-distributive-coprod-Σ-map A B C)
( is-equiv-left-distributive-coprod-Σ-map A B C)
abstract
is-equiv-map-to-empty :
{l : Level} {A : UU l} (f : A → empty) → is-equiv f
is-equiv-map-to-empty f =
is-equiv-has-inverse
ind-empty
ind-empty
( λ x → ind-empty {P = λ t → Id (ind-empty (f x)) x} (f x))
map-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) → empty
map-Σ-empty-fam A (pair x ())
abstract
is-equiv-map-Σ-empty-fam :
{l : Level} (A : UU l) → is-equiv (map-Σ-empty-fam A)
is-equiv-map-Σ-empty-fam A = is-equiv-map-to-empty (map-Σ-empty-fam A)
equiv-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) ≃ empty
equiv-Σ-empty-fam A =
pair (map-Σ-empty-fam A) (is-equiv-map-Σ-empty-fam A)
inv-inl-coprod-empty : {l : Level} (A : UU l) → coprod A empty → A
inv-inl-coprod-empty A (inl x) = x
inv-inl-coprod-empty A (inr ())
issec-inv-inl-coprod-empty :
{l : Level} (A : UU l) → (inl ∘ (inv-inl-coprod-empty A)) ~ id
issec-inv-inl-coprod-empty A (inl x) = refl
issec-inv-inl-coprod-empty A (inr ())
abstract
is-equiv-inl-coprod-empty :
{l : Level} (A : UU l) → is-equiv (inl {A = A} {B = empty})
is-equiv-inl-coprod-empty A =
is-equiv-has-inverse
( inv-inl-coprod-empty A)
( issec-inv-inl-coprod-empty A)
( λ x → refl)
equiv-inl :
{l : Level} (A : UU l) → A ≃ coprod A empty
equiv-inl A = pair inl (is-equiv-inl-coprod-empty A)
inv-inr-coprod-empty :
{l : Level} (B : UU l) → coprod empty B → B
inv-inr-coprod-empty B (inl ())
inv-inr-coprod-empty B (inr x) = x
issec-inv-inr-coprod-empty :
{l : Level} (B : UU l) → (inr ∘ (inv-inr-coprod-empty B)) ~ id
issec-inv-inr-coprod-empty B (inl ())
issec-inv-inr-coprod-empty B (inr x) = refl
abstract
is-equiv-inr-coprod-empty :
{l : Level} (B : UU l) → is-equiv (inr {A = empty} {B = B})
is-equiv-inr-coprod-empty B =
is-equiv-has-inverse
( inv-inr-coprod-empty B)
( issec-inv-inr-coprod-empty B)
( λ x → refl)
equiv-inr :
{l : Level} (B : UU l) → B ≃ coprod empty B
equiv-inr B = pair inr (is-equiv-inr-coprod-empty B)
-- The identity types of coproducts
Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
coprod A B → coprod A B → UU (l1 ⊔ l2)
Eq-coprod {l1} {l2} A B (inl x) (inl y) = raise (l1 ⊔ l2) (Id x y)
Eq-coprod {l1} {l2} A B (inl x) (inr y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inl y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inr y) = raise (l1 ⊔ l2) (Id x y)
reflexive-Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(t : coprod A B) → Eq-coprod A B t t
reflexive-Eq-coprod {l1} {l2} A B (inl x) = map-raise (l1 ⊔ l2) (Id x x) refl
reflexive-Eq-coprod {l1} {l2} A B (inr x) = map-raise (l1 ⊔ l2) (Id x x) refl
Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(s t : coprod A B) → Id s t → Eq-coprod A B s t
Eq-coprod-eq A B s .s refl = reflexive-Eq-coprod A B s
abstract
is-contr-total-Eq-coprod-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inl x)))
is-contr-total-Eq-coprod-inl A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inl x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inl x)))
( is-contr-equiv'
( coprod
( Σ A (Id x))
( Σ B (λ y → empty)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( equiv-tot (λ y → equiv-raise _ empty)))
( is-contr-equiv
( coprod (Σ A (Id x)) empty)
( equiv-functor-coprod
( equiv-id (Σ A (Id x)))
( equiv-Σ-empty-fam B))
( is-contr-equiv'
( Σ A (Id x))
( equiv-inl (Σ A (Id x)))
( is-contr-total-path x))))
abstract
is-contr-total-Eq-coprod-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inr x)))
is-contr-total-Eq-coprod-inr A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inr x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inr x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inr x)))
( is-contr-equiv'
( coprod (Σ A (λ y → empty)) (Σ B (Id x)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ empty))
( equiv-tot (λ y → equiv-raise _ (Id x y))))
( is-contr-equiv
( coprod empty (Σ B (Id x)))
( equiv-functor-coprod
( equiv-Σ-empty-fam A)
( equiv-id (Σ B (Id x))))
( is-contr-equiv'
( Σ B (Id x))
( equiv-inr (Σ B (Id x)))
( is-contr-total-path x))))
abstract
is-equiv-Eq-coprod-eq-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-fiberwise-equiv (Eq-coprod-eq A B (inl x))
is-equiv-Eq-coprod-eq-inl A B x =
fundamental-theorem-id
( inl x)
( reflexive-Eq-coprod A B (inl x))
( is-contr-total-Eq-coprod-inl A B x)
( Eq-coprod-eq A B (inl x))
abstract
is-equiv-Eq-coprod-eq-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-fiberwise-equiv (Eq-coprod-eq A B (inr x))
is-equiv-Eq-coprod-eq-inr A B x =
fundamental-theorem-id
( inr x)
( reflexive-Eq-coprod A B (inr x))
( is-contr-total-Eq-coprod-inr A B x)
( Eq-coprod-eq A B (inr x))
abstract
is-equiv-Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2)
(s : coprod A B) → is-fiberwise-equiv (Eq-coprod-eq A B s)
is-equiv-Eq-coprod-eq A B (inl x) = is-equiv-Eq-coprod-eq-inl A B x
is-equiv-Eq-coprod-eq A B (inr x) = is-equiv-Eq-coprod-eq-inr A B x
map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → Id (inl {B = B} x) (inl {B = B} x') → Id x x'
map-compute-eq-coprod-inl-inl x x' =
( inv-is-equiv (is-equiv-map-raise _ (Id x x'))) ∘
( Eq-coprod-eq _ _ (inl x) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → is-equiv (map-compute-eq-coprod-inl-inl {B = B} x x')
is-equiv-map-compute-eq-coprod-inl-inl x x' =
is-equiv-comp
( map-compute-eq-coprod-inl-inl x x')
( inv-is-equiv (is-equiv-map-raise _ (Id x x')))
( Eq-coprod-eq _ _ (inl x) (inl x'))
( htpy-refl)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id x x')))
compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → (Id (inl {B = B} x) (inl x')) ≃ (Id x x')
compute-eq-coprod-inl-inl x x' =
pair
( map-compute-eq-coprod-inl-inl x x')
( is-equiv-map-compute-eq-coprod-inl-inl x x')
map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → Id (inl x) (inr y') → empty
map-compute-eq-coprod-inl-inr x y' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inl x) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → is-equiv (map-compute-eq-coprod-inl-inr x y')
is-equiv-map-compute-eq-coprod-inl-inr x y' =
is-equiv-comp
( map-compute-eq-coprod-inl-inr x y')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inl x) (inr y'))
( htpy-refl)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → (Id (inl x) (inr y')) ≃ empty
compute-eq-coprod-inl-inr x y' =
pair
( map-compute-eq-coprod-inl-inr x y')
( is-equiv-map-compute-eq-coprod-inl-inr x y')
map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr {A = A} y) (inl x')) → empty
map-compute-eq-coprod-inr-inl y x' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inr y) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → is-equiv (map-compute-eq-coprod-inr-inl y x')
is-equiv-map-compute-eq-coprod-inr-inl y x' =
is-equiv-comp
( map-compute-eq-coprod-inr-inl y x')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inr y) (inl x'))
( htpy-refl)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr y) (inl x')) ≃ empty
compute-eq-coprod-inr-inl y x' =
pair
( map-compute-eq-coprod-inr-inl y x')
( is-equiv-map-compute-eq-coprod-inr-inl y x')
map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) → Id y y'
map-compute-eq-coprod-inr-inr y y' =
( inv-is-equiv (is-equiv-map-raise _ (Id y y'))) ∘
( Eq-coprod-eq _ _ (inr y) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → is-equiv (map-compute-eq-coprod-inr-inr {A = A} y y')
is-equiv-map-compute-eq-coprod-inr-inr y y' =
is-equiv-comp
( map-compute-eq-coprod-inr-inr y y')
( inv-is-equiv (is-equiv-map-raise _ (Id y y')))
( Eq-coprod-eq _ _ (inr y) (inr y'))
( htpy-refl)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id y y')))
compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) ≃ (Id y y')
compute-eq-coprod-inr-inr y y' =
pair
( map-compute-eq-coprod-inr-inr y y')
( is-equiv-map-compute-eq-coprod-inr-inr y y')
-- Exercises
-- Exercise 7.1
abstract
is-emb-empty :
{i : Level} (A : UU i) → is-emb (ind-empty {P = λ x → A})
is-emb-empty A = ind-empty
-- Exercise 7.2
path-adjointness-equiv :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x : A) (y : B) →
(Id (map-equiv e x) y) ≃ (Id x (inv-map-equiv e y))
path-adjointness-equiv e x y =
( inv-equiv (equiv-ap e x (inv-map-equiv e y))) ∘e
( equiv-concat'
( map-equiv e x)
( inv (issec-inv-is-equiv (is-equiv-map-equiv e) y)))
-- Exercise 7.3
abstract
is-equiv-top-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
is-equiv i → is-equiv f → is-equiv g → is-equiv h
is-equiv-top-is-equiv-left-square f g h i H Ei Ef Eg =
is-equiv-right-factor (i ∘ f) g h H Eg
( is-equiv-comp (i ∘ f) i f htpy-refl Ef Ei)
abstract
is-emb-htpy :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb g → is-emb f
is-emb-htpy f g H is-emb-g x y =
is-equiv-top-is-equiv-left-square
( ap g)
( concat' (f x) (H y))
( ap f)
( concat (H x) (g y))
( htpy-nat H)
( is-equiv-concat (H x) (g y))
( is-emb-g x y)
( is-equiv-concat' (f x) (H y))
abstract
is-emb-htpy' :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb f → is-emb g
is-emb-htpy' f g H is-emb-f =
is-emb-htpy g f (htpy-inv H) is-emb-f
-- Exercise 7.4
abstract
is-emb-comp :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb h → is-emb f
is-emb-comp f g h H is-emb-g is-emb-h =
is-emb-htpy f (g ∘ h) H
( λ x y → is-equiv-comp (ap (g ∘ h)) (ap g) (ap h) (ap-comp g h)
( is-emb-h x y)
( is-emb-g (h x) (h y)))
abstract
is-emb-right-factor :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb f → is-emb h
is-emb-right-factor f g h H is-emb-g is-emb-f x y =
is-equiv-right-factor
( ap (g ∘ h))
( ap g)
( ap h)
( ap-comp g h)
( is-emb-g (h x) (h y))
( is-emb-htpy (g ∘ h) f (htpy-inv H) is-emb-f x y)
abstract
is-emb-triangle-is-equiv :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb g → is-emb f
is-emb-triangle-is-equiv f g e H is-equiv-e is-emb-g =
is-emb-comp f g e H is-emb-g (is-emb-is-equiv e is-equiv-e)
abstract
is-emb-triangle-is-equiv' :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb f → is-emb g
is-emb-triangle-is-equiv' f g e H is-equiv-e is-emb-f =
is-emb-triangle-is-equiv g f
( inv-is-equiv is-equiv-e)
( triangle-section f g e H
( pair
( inv-is-equiv is-equiv-e)
( issec-inv-is-equiv is-equiv-e)))
( is-equiv-inv-is-equiv is-equiv-e)
( is-emb-f)
-- Exercise 7.5
abstract
is-emb-inl :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inl {A = A} {B = B})
is-emb-inl A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( tot (λ y → Eq-coprod-eq A B (inl x) (inl y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inl x) (inl y)))
( is-contr-equiv'
( Σ A (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inl)
abstract
is-emb-inr :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inr {A = A} {B = B})
is-emb-inr A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ B (λ y → Eq-coprod A B (inr x) (inr y)))
( tot (λ y → Eq-coprod-eq A B (inr x) (inr y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inr x) (inr y)))
( is-contr-equiv'
( Σ B (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inr)
-- Exercise 7.6
-- Exercise 7.7
tot-htpy :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k}
{f g : (x : A) → B x → C x} → (H : (x : A) → f x ~ g x) → tot f ~ tot g
tot-htpy H (pair x y) = eq-pair refl (H x y)
tot-id :
{i j : Level} {A : UU i} (B : A → UU j) →
(tot (λ x (y : B x) → y)) ~ id
tot-id B (pair x y) = refl
tot-comp :
{i j j' j'' : Level}
{A : UU i} {B : A → UU j} {B' : A → UU j'} {B'' : A → UU j''}
(f : (x : A) → B x → B' x) (g : (x : A) → B' x → B'' x) →
tot (λ x → (g x) ∘ (f x)) ~ ((tot g) ∘ (tot f))
tot-comp f g (pair x y) = refl
-- Exercise 7.8
abstract
fundamental-theorem-id-retr :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) →
(i : (x : A) → B x → Id a x) → (R : (x : A) → retr (i x)) →
is-fiberwise-equiv i
fundamental-theorem-id-retr {_} {_} {A} {B} a i R =
is-fiberwise-equiv-is-equiv-tot i
( is-equiv-is-contr (tot i)
( is-contr-retract-of (Σ _ (λ y → Id a y))
( pair (tot i)
( pair (tot λ x → pr1 (R x))
( ( htpy-inv (tot-comp i (λ x → pr1 (R x)))) ∙h
( ( tot-htpy λ x → pr2 (R x)) ∙h (tot-id B)))))
( is-contr-total-path a))
( is-contr-total-path a))
abstract
is-equiv-sec-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (sec-f : sec f) →
is-equiv (pr1 sec-f) → is-equiv f
is-equiv-sec-is-equiv {A = A} {B = B} f (pair g issec-g) is-equiv-sec-f =
let h : A → B
h = inv-is-equiv is-equiv-sec-f
in
is-equiv-htpy h
( ( htpy-left-whisk f (htpy-inv (issec-inv-is-equiv is-equiv-sec-f))) ∙h
( htpy-right-whisk issec-g h))
( is-equiv-inv-is-equiv is-equiv-sec-f)
abstract
fundamental-theorem-id-sec :
{i j : Level} {A : UU i} {B : A → UU j} (a : A)
(f : (x : A) → Id a x → B x) → ((x : A) → sec (f x)) →
is-fiberwise-equiv f
fundamental-theorem-id-sec {A = A} {B = B} a f sec-f x =
let i : (x : A) → B x → Id a x
i = λ x → pr1 (sec-f x)
retr-i : (x : A) → retr (i x)
retr-i = λ x → pair (f x) (pr2 (sec-f x))
is-fiberwise-equiv-i : is-fiberwise-equiv i
is-fiberwise-equiv-i = fundamental-theorem-id-retr a i retr-i
in is-equiv-sec-is-equiv (f x) (sec-f x) (is-fiberwise-equiv-i x)
-- Exercise 7.9
abstract
is-emb-sec-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) →
((x y : A) → sec (ap f {x = x} {y = y})) → is-emb f
is-emb-sec-ap f sec-ap-f x =
fundamental-theorem-id-sec x (λ y → ap f {y = y}) (sec-ap-f x)
-- Exercise 7.10
coherence-is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (g : B → A)
(G : (f ∘ g) ~ id) (H : (g ∘ f) ~ id) → UU (l1 ⊔ l2)
coherence-is-half-adjoint-equivalence f g G H =
( htpy-right-whisk G f) ~ (htpy-left-whisk f H)
is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-half-adjoint-equivalence {A = A} {B = B} f =
Σ (B → A)
( λ g → Σ ((f ∘ g) ~ id)
( λ G → Σ ((g ∘ f) ~ id) (coherence-is-half-adjoint-equivalence f g G)))
is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-path-split {A = A} {B = B} f =
sec f × ((x y : A) → sec (ap f {x = x} {y = y}))
abstract
is-path-split-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-path-split f
is-path-split-is-equiv f is-equiv-f =
pair (pr1 is-equiv-f) (λ x y → pr1 (is-emb-is-equiv f is-equiv-f x y))
abstract
is-half-adjoint-equivalence-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-path-split {A = A} {B = B} f
( pair (pair g issec-g) sec-ap-f) =
let φ : ((x : A) → fib (ap f) (issec-g (f x))) →
Σ ((g ∘ f) ~ id)
( λ H → (htpy-right-whisk issec-g f) ~ (htpy-left-whisk f H))
φ = ( tot (λ H' → htpy-inv)) ∘
( λ s → pair (λ x → pr1 (s x)) (λ x → pr2 (s x)))
in
pair g
( pair issec-g
( φ (λ x → pair
( pr1 (sec-ap-f (g (f x)) x) (issec-g (f x)))
( pr2 (sec-ap-f (g (f x)) x) (issec-g (f x))))))
abstract
is-equiv-is-half-adjoint-equivalence :
{ l1 l2 : Level} {A : UU l1} {B : UU l2}
(f : A → B) → is-half-adjoint-equivalence f → is-equiv f
is-equiv-is-half-adjoint-equivalence f (pair g (pair G (pair H K))) =
is-equiv-has-inverse g G H
abstract
is-equiv-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-equiv f
is-equiv-is-path-split f =
( is-equiv-is-half-adjoint-equivalence f) ∘
( is-half-adjoint-equivalence-is-path-split f)
abstract
is-half-adjoint-equivalence-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-equiv f =
( is-half-adjoint-equivalence-is-path-split f) ∘ (is-path-split-is-equiv f)
-- Exercise 7.11
abstract
is-equiv-top-is-equiv-bottom-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv i) → (is-equiv h)
is-equiv-top-is-equiv-bottom-square
f g h i H is-equiv-f is-equiv-g is-equiv-i =
is-equiv-right-factor (i ∘ f) g h H is-equiv-g
( is-equiv-comp' i f is-equiv-f is-equiv-i)
abstract
is-equiv-bottom-is-equiv-top-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv h) → (is-equiv i)
is-equiv-bottom-is-equiv-top-square
f g h i H is-equiv-f is-equiv-g is-equiv-h =
is-equiv-left-factor' i f
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g) is-equiv-f
abstract
is-equiv-left-is-equiv-right-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv g) → (is-equiv f)
is-equiv-left-is-equiv-right-square
f g h i H is-equiv-h is-equiv-i is-equiv-g =
is-equiv-right-factor' i f is-equiv-i
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g)
abstract
is-equiv-right-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv f) → (is-equiv g)
is-equiv-right-is-equiv-left-square
f g h i H is-equiv-h is-equiv-i is-equiv-f =
is-equiv-left-factor (i ∘ f) g h H
( is-equiv-comp' i f is-equiv-f is-equiv-i)
( is-equiv-h)
fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h))
(x : X) → (fib f x) → (fib g x)
fib-triangle f g h H .(f a) (pair a refl) = pair (h a) (inv (H a))
square-tot-fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(h ∘ (Σ-fib-to-domain f)) ~
((Σ-fib-to-domain g) ∘ (tot (fib-triangle f g h H)))
square-tot-fib-triangle f g h H (pair .(f a) (pair a refl)) = refl
abstract
is-fiberwise-equiv-is-equiv-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-equiv h) → is-fiberwise-equiv (fib-triangle f g h H)
is-fiberwise-equiv-is-equiv-triangle f g h H E =
is-fiberwise-equiv-is-equiv-tot
( fib-triangle f g h H)
( is-equiv-top-is-equiv-bottom-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( E))
abstract
is-equiv-triangle-is-fiberwise-equiv :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-fiberwise-equiv (fib-triangle f g h H)) → is-equiv h
is-equiv-triangle-is-fiberwise-equiv f g h H E =
is-equiv-bottom-is-equiv-top-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( is-equiv-tot-is-fiberwise-equiv E)
-- Extra material
{- In order to show that the total space of htpy-cone is contractible, we give
a general construction that helps us characterize the identity type of
a structure. This construction is called
is-contr-total-Eq-structure.
We first give some definitions that help us with the construction of
is-contr-total-Eq-structure. -}
swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))) →
Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t)))
swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) =
pair (pair a c) (pair b d)
htpy-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
( ( swap-total-Eq-structure B C D) ∘
( swap-total-Eq-structure C B (λ x z y → D x y z))) ~ id
htpy-swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) = refl
abstract
is-equiv-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
is-equiv (swap-total-Eq-structure B C D)
is-equiv-swap-total-Eq-structure B C D =
is-equiv-has-inverse
( swap-total-Eq-structure C B (λ x z y → D x y z))
( htpy-swap-total-Eq-structure B C D)
( htpy-swap-total-Eq-structure C B (λ x z y → D x y z))
abstract
is-contr-Σ :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → ((x : A) → is-contr (B x)) → is-contr (Σ A B)
is-contr-Σ {A = A} {B = B} is-contr-A is-contr-B =
is-contr-equiv'
( B (center is-contr-A))
( left-unit-law-Σ B is-contr-A)
( is-contr-B (center is-contr-A))
abstract
is-contr-Σ' :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → (a : A) → is-contr (B a) → is-contr (Σ A B)
is-contr-Σ' {A = A} {B} is-contr-A a is-contr-B =
is-contr-is-equiv'
( B a)
( left-unit-law-Σ-map-gen B is-contr-A a)
( is-equiv-left-unit-law-Σ-map-gen B is-contr-A a)
( is-contr-B)
abstract
is-contr-total-Eq-structure :
{ l1 l2 l3 l4 : Level} { A : UU l1} {B : A → UU l2} {C : A → UU l3}
( D : (x : A) → B x → C x → UU l4) →
( is-contr-AC : is-contr (Σ A C)) →
( t : Σ A C) →
is-contr (Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))) →
is-contr (Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))))
is-contr-total-Eq-structure
{A = A} {B = B} {C = C} D is-contr-AC t is-contr-BD =
is-contr-is-equiv
( Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))))
( swap-total-Eq-structure B C D)
( is-equiv-swap-total-Eq-structure B C D)
( is-contr-Σ' is-contr-AC t is-contr-BD)
-- Characterizing the identity type of a fiber as the fiber of the action on
-- paths
fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) {b : B} (s t : fib f b) (p : Id (pr1 s) (pr1 t)) →
(Id (tr (λ (a : A) → Id (f a) b) p (pr2 s)) (pr2 t)) →
(Id (ap f p) ((pr2 s) ∙ (inv (pr2 t))))
fib-ap-eq-fib-fiberwise f (pair .x' p) (pair x' refl) refl =
inv ∘ (concat right-unit refl)
abstract
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B} (s t : fib f b) →
is-fiberwise-equiv (fib-ap-eq-fib-fiberwise f s t)
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise
f (pair x y) (pair .x refl) refl =
is-equiv-comp
( fib-ap-eq-fib-fiberwise f (pair x y) (pair x refl) refl)
( inv)
( concat right-unit refl)
( htpy-refl)
( is-equiv-concat right-unit refl)
( is-equiv-inv (y ∙ refl) refl)
fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → Id s t →
fib (ap f {x = pr1 s} {y = pr1 t}) ((pr2 s) ∙ (inv (pr2 t)))
fib-ap-eq-fib f s .s refl = pair refl (inv (right-inv (pr2 s)))
triangle-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B)
{b : B} (s t : fib f b) →
(fib-ap-eq-fib f s t) ~ ((tot (fib-ap-eq-fib-fiberwise f s t)) ∘ (pair-eq {s = s} {t}))
triangle-fib-ap-eq-fib f (pair x refl) .(pair x refl) refl = refl
abstract
is-equiv-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → is-equiv (fib-ap-eq-fib f s t)
is-equiv-fib-ap-eq-fib f s t =
is-equiv-comp
( fib-ap-eq-fib f s t)
( tot (fib-ap-eq-fib-fiberwise f s t))
( pair-eq {s = s} {t})
( triangle-fib-ap-eq-fib f s t)
( is-equiv-pair-eq s t)
( is-equiv-tot-is-fiberwise-equiv
( is-fiberwise-equiv-fib-ap-eq-fib-fiberwise f s t))
eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) →
Id (pair x q) (pair y (refl {x = f y})) → fib (ap f {x = x} {y = y}) q
eq-fib-fib-ap f x y q = (tr (fib (ap f)) right-unit) ∘ (fib-ap-eq-fib f (pair x q) (pair y refl))
abstract
is-equiv-eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) → is-equiv (eq-fib-fib-ap f x y q)
is-equiv-eq-fib-fib-ap f x y q =
is-equiv-comp
( eq-fib-fib-ap f x y q)
( tr (fib (ap f)) right-unit)
( fib-ap-eq-fib f (pair x q) (pair y refl))
( htpy-refl)
( is-equiv-fib-ap-eq-fib f (pair x q) (pair y refl))
( is-equiv-tr (fib (ap f)) right-unit)
-- Comparing fib and fib'
fib'-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
fib f y → fib' f y
fib'-fib f y t = tot (λ x → inv) t
abstract
is-equiv-fib'-fib :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) → is-fiberwise-equiv (fib'-fib f)
is-equiv-fib'-fib f y =
is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-inv (f x) y)
| 35.439873
| 97
| 0.532012
|
30e13c94b33f428d3665b174bb4922c25b436e06
| 89
|
agda
|
Agda
|
archive/agda-2/Oscar/Data/Nat.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-2/Oscar/Data/Nat.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-2/Oscar/Data/Nat.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Oscar.Data.Nat where
open import Agda.Builtin.Nat public using (Nat; zero; suc)
| 17.8
| 58
| 0.764045
|
5269c19790ef64c337477691ad2cfa2f59901444
| 494
|
agda
|
Agda
|
Chapter2/#4.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
Chapter2/#4.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
Chapter2/#4.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
module #4 where
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Nat
{-
Exercise 2.4. Define, by induction on n, a general notion of n-dimensional path in a
type A, simultaneously with the type of boundaries for such paths.
-}
-- We need pointed sets for this part
Set• : ∀ i → Set _
Set• i = Σ (Set i) λ X → X
Ω₁ : ∀ {i} → Set• i → Set• i
Ω₁ (X , x) = ((x ≡ x) , refl)
Ωⁿ : ∀ {i} → ℕ → Set• i → Set• _
Ωⁿ 0 x = x
Ωⁿ (suc n) x = Ωⁿ n (Ω₁ x)
| 22.454545
| 87
| 0.633603
|
21050c3085cd46965965f74b57c7b22f0a118a45
| 165
|
agda
|
Agda
|
test/Succeed/Issue3618.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3618.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3618.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --prop --allow-unsolved-metas #-}
postulate
A : Set
P : A → Prop
a : A
c : P a
Q : Prop
x : Q
x = _ where
b : A
b = a
d : P b
d = c
| 9.705882
| 45
| 0.460606
|
34ca2514ca0168f9cd4cfe8fa7da4cd71698856f
| 1,967
|
agda
|
Agda
|
examples/AIM6/HelloAgda/Basics.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/AIM6/HelloAgda/Basics.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/Basics.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-
Agda Implementors' Meeting VI
Göteborg
May 24 - 30, 2007
Hello Agda!
Ulf Norell
-}
{-
Getting your hands on Agda
http://www.cs.chalmers.se/~ulfn/Agda
darcs get --partial http://www.cs.chalmers.se/~ulfn/darcs/Agda2
-}
-- Each Agda file contains a top-level module, whose
-- name corresponds to the file name.
module Basics where
{-
Expressions (types and terms)
-}
-- The expression language of Agda is your favorite dependently
-- typed λ-calculus.
-- For instance:
id₁ : (A : Set) -> A -> A
id₁ = \ A x -> x
id₂ : (A : Set) -> A -> A
id₂ = \ A x -> id₁ A (id₁ A x)
-- Note: Agda likes white space. This is not correct:
-- id:(A:Set)->A->A
-- Why not? In Agda the following strings are valid identifiers:
-- id:
-- A:Set
-- ->A->A
-- Another useful function, featuring telescopes
-- and typed λs.
compose : (A B C : Set)(f : B -> C)(g : A -> B) -> A -> C
compose = \(A B C : Set) -> \ f g x -> f (g x)
{-
Implicit arguments
-}
-- Writing down type arguments explicitly soon gets old.
-- Enter implicit arguments.
-- Note the curlies in the telescope. And A mysteriously disappeared
-- in the definition.
id₃ : {A : Set} -> A -> A
id₃ = \ x -> x
-- And it's not there when applying the function.
id₄ : {A : Set} -> A -> A
id₄ = \ x -> (id₃ (id₃ x))
-- You can give implicit arguments explicitly.
id₅ : {A : Set} -> A -> A
id₅ {A} x = id₄ {A} x
-- If you want to give a particular implicit argument, you can refer
-- to it by name.
const : {A B : Set} -> A -> B -> A
const = \ x y -> x
const' : (A : Set) -> A -> A -> A
const' = \ A -> const {B = A}
-- It also works the other way around. If you think the type checker
-- should figure out the value of something explicit, you write _.
id₆ : {A : Set} -> A -> A
id₆ x = id₁ _ x
-- Interesting though it is, eventually you'll get bored
-- with the λ-calculus...
-- Move on to: Datatypes.agda
| 20.278351
| 68
| 0.594814
|
43d3323c1840b8a8f2c247c4dd5998ba48b3e904
| 6,452
|
agda
|
Agda
|
agda-rr/cast-cic.agda
|
CoqHott/exceptional-tt
|
c93256a11d59038998f09a01c5b42f6ffe42d5c4
|
[
"WTFPL"
] | 14
|
2017-10-13T01:31:56.000Z
|
2021-03-23T12:45:05.000Z
|
agda-rr/cast-cic.agda
|
CoqHott/exceptional-tt
|
c93256a11d59038998f09a01c5b42f6ffe42d5c4
|
[
"WTFPL"
] | 1
|
2019-02-28T16:35:41.000Z
|
2019-02-28T18:28:53.000Z
|
agda-rr/cast-cic.agda
|
CoqHott/exceptional-tt
|
c93256a11d59038998f09a01c5b42f6ffe42d5c4
|
[
"WTFPL"
] | 3
|
2018-04-23T17:34:44.000Z
|
2021-01-06T13:36:28.000Z
|
{-# OPTIONS --rewriting --prop --confluence-check --cumulativity #-}
open import Agda.Primitive
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat
open import Agda.Builtin.List
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
open import Agda.Builtin.Sigma
open import Agda.Builtin.Unit
open import Data.Vec.Base
open import Data.Bool
open import Data.Sum
open import Data.Product using (_×_)
open import ett-rr
{- Axiomatisation of the Cast calculus -}
{- diagonal cases -}
postulate cast : (A : Set ℓ) (B : Set ℓ₁) → A → B
postulate cast-set : (A : Set ℓ) → cast (Set ℓ) (Set ℓ) A ≡ A
{-# REWRITE cast-set #-}
postulate cast-prop : (A : Prop ℓ) → cast (Prop ℓ) (Prop ℓ) A ≡ A
{-# REWRITE cast-prop #-}
postulate cast-Pi : (A : Set ℓ) (B : A → Set ℓ₁) (A' : Set ℓ₂) (B' : A' → Set ℓ₃) (f : (a : A) → B a) →
cast ((a : A) → B a) ((a' : A') → B' a') f ≡
λ (a' : A') → cast _ _ (f (cast A' A a'))
{-# REWRITE cast-Pi #-}
postulate cast-Sigma : (A : Set ℓ) (B : A → Set ℓ₁) (A' : Set ℓ₂) (B' : A' → Set ℓ₃) (p : Σ {a = ℓ} {b = ℓ₁} A B) →
cast (Σ A B) (Σ A' B') p ≡ (cast {ℓ = ℓ} {ℓ₁ = ℓ₂} A A' (p .fst) , cast (B (p .fst)) (B' (cast A A' (p .fst))) (p .snd))
{-# REWRITE cast-Sigma #-}
postulate cast-Sum-inj₁ : (A A' : Set ℓ) (B B' : Set ℓ₁) (a : A) →
cast (A ⊎ B) (A' ⊎ B') (inj₁ a) ≡ inj₁ (cast A A' a)
postulate cast-Sum-inj₂ : (A A' : Set ℓ) (B B' : Set ℓ₁) (b : B) →
cast (A ⊎ B) (A' ⊎ B') (inj₂ b) ≡ inj₂ (cast B B' b)
postulate cast-Sum-raise : (A A' : Set ℓ) (B B' : Set ℓ₁) (a : A) →
cast (A ⊎ B) (A' ⊎ B') (raise _) ≡ raise _
postulate cast-Sum-unk : (A A' : Set ℓ) (B B' : Set ℓ₁) (a : A) →
cast (A ⊎ B) (A' ⊎ B') (unk _) ≡ unk _
{-# REWRITE cast-Sum-inj₁ #-}
{-# REWRITE cast-Sum-inj₂ cast-Sum-raise cast-Sum-unk #-}
postulate cast-List-nil : (A A' : Set ℓ) →
cast (List A) (List A') [] ≡ []
postulate cast-List-cons : (A A' : Set ℓ) (a : A) (l : List {a = ℓ} A) →
cast (List A) (List {a = ℓ} A') (a ∷ l) ≡
cast A A' a ∷ cast (List A) (List A') l
postulate cast-List-raise : (A A' : Set ℓ) →
cast (List A) (List A') (raise (List _)) ≡ raise (List _)
postulate cast-List-unk : (A A' : Set ℓ) →
cast (List A) (List A') (unk (List _)) ≡ unk (List _)
{-# REWRITE cast-List-nil #-}
{-# REWRITE cast-List-cons cast-List-raise cast-List-unk #-}
postulate cast-Nat-zero : cast Nat Nat 0 ≡ 0
postulate cast-Nat-suc : (n : Nat ) → cast Nat Nat (suc n) ≡ suc (cast _ _ n)
postulate cast-Nat-raise : cast Nat Nat (raise Nat) ≡ raise Nat
postulate cast-Nat-unk : cast Nat Nat (unk Nat) ≡ unk Nat
{-# REWRITE cast-Nat-zero cast-Nat-suc cast-Nat-raise cast-Nat-unk #-}
postulate cast-Bool-true : cast Bool Bool true ≡ true
postulate cast-Bool-false : cast Bool Bool false ≡ false
postulate cast-Bool-raise : cast Bool Bool (raise Bool) ≡ raise Bool
postulate cast-Bool-unk : cast Bool Bool (unk Bool) ≡ unk Bool
{-# REWRITE cast-Bool-true cast-Bool-false cast-Bool-raise cast-Bool-unk #-}
postulate cast-Unit : cast ⊤ ⊤ tt ≡ tt
{- Beware that raise ⊤ ≡ tt ≡ unk ⊤ because of definitional singleton -}
postulate cast-Unit-raise : cast ⊤ ⊤ (raise ⊤) ≡ raise ⊤
postulate cast-Unit-unk : cast ⊤ ⊤ (unk ⊤) ≡ unk ⊤
{-# REWRITE cast-Unit cast-Unit-raise cast-Unit-unk #-}
{- non-diagonal cases -}
postulate cast-Set-bad : (A : Set (lsuc ℓ)) → cast (Set (lsuc ℓ)) (Set ℓ) A ≡ raise _
{-# REWRITE cast-Set-bad #-}
postulate cast-raise : ∀ ℓ ℓ₁ → (x : raise {ℓ = lsuc ℓ} (Set ℓ)) (A : Set ℓ₁) → cast (raise {ℓ = lsuc ℓ} (Set ℓ)) A x ≡ raise _
{-# REWRITE cast-raise #-}
postulate cast-Pi-Sigma : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) (f : (a : A) → B a) →
cast ((a : A) → B a) (Σ {a = ℓ} {b = ℓ₁} A' B') f ≡ raise (Σ A' B')
{-# REWRITE cast-Pi-Sigma #-}
postulate cast-Pi-Nat : (A : Set ℓ) (B : A → Set ℓ₁) (f : (a : A) → B a) →
cast ((a : A) → B a) Nat f ≡ raise Nat
{-# REWRITE cast-Pi-Nat #-}
-- missing many conflict rules
{- Rules specific to Unk -}
{- unk-cast ℓ A a is just a copy of cast A (Unk ℓ) a
but we need to split it off for rewriting.
Making it private so that the only closed values we can create in Unk ℓ come from cast -}
private
postulate unk-cast : ∀ (A : Set ℓ) → A → Unk (lsuc ℓ)
postulate cast-Unk : (A : Set ℓ) (B : Set ℓ₁) (f : A) →
cast (Unk (lsuc ℓ)) B (unk-cast A f) ≡ cast A B f
{-# REWRITE cast-Unk #-}
postulate cast-Unk-raise : ∀ ℓ → (B : Set ℓ₁) →
cast (Unk ℓ) B (raise _) ≡ raise _
{-# REWRITE cast-Unk-raise #-}
postulate cast-Pi-Unk : (A : Set ℓ) (B : A → Set ℓ₁) (f : (a : A) → B a) →
cast ((a : A) → B a) (Unk (lsuc (ℓ ⊔ ℓ₁))) f ≡ unk-cast (Unk ℓ → Unk ℓ₁) (cast ((a : A) → B a) (Unk ℓ → Unk ℓ₁) f)
{-# REWRITE cast-Pi-Unk #-}
postulate cast-Pi-Unk-bad : (f : Unk ℓ → Unk ℓ₁) →
cast (Unk ℓ → Unk ℓ₁) (Unk (ℓ ⊔ ℓ₁)) f ≡ raise _
{-# REWRITE cast-Pi-Unk-bad #-}
postulate cast-Sigma-Unk : (A : Set ℓ) (B : A → Set ℓ₁) (x : Σ {a = ℓ} {b = ℓ₁} A B) →
cast (Σ A B) (Unk (lsuc (ℓ ⊔ ℓ₁))) x ≡ unk-cast (_×_ {a = ℓ} {b = ℓ₁} (Unk ℓ) (Unk ℓ₁)) (cast (Σ A B) (Unk ℓ × Unk ℓ₁) x)
{-# REWRITE cast-Sigma-Unk #-}
delta : Unk ℓ → Unk ℓ
delta {ℓ} x = cast (Unk ℓ) (Unk ℓ → Unk ℓ) x x
omega : Unk ℓ
omega {ℓ} = delta {ℓ = ℓ} (cast (Unk ℓ → Unk ℓ) (Unk ℓ) (delta {ℓ = ℓ}))
foo : Unk (lsuc lzero)
foo = cast (Nat → Nat → Nat) (Unk _) _+_
postulate cast-Nat-Unk : (n : Nat) → cast Nat (Unk (lsuc lzero)) n ≡ unk-cast Nat n
record i (A : Set ℓ) : Set (ℓ ⊔ ℓ₁) where
constructor inj
field
uninj : A
open i public
postulate cast-Nat-Unk' : (n : Nat) → cast (i {ℓ = ℓ} {ℓ₁ = ℓ₁} Nat) (Unk (lsuc ℓ)) (inj n) ≡ unk-cast Nat n
postulate cast-Nat-iNat : (n : Nat) → cast Nat (i {ℓ = ℓ} {ℓ₁ = ℓ₁} Nat) n ≡ inj n
{-# REWRITE cast-Nat-Unk cast-Nat-Unk' cast-Nat-iNat #-}
retr : (A : Set ℓ) (a : A) → A
retr {ℓ} A a = cast (Unk (lsuc ℓ)) A (cast A (Unk (lsuc ℓ)) a)
retr-0 : retr {lzero} Nat 0 ≡ 0
retr-0 = refl
retr-arr : (A : Set ℓ) (a : A) → A
retr-arr {ℓ} A = retr (A → A) (λ a → a)
zero' : Nat
zero' = uninj (retr-arr {lsuc lzero} (i {ℓ₁ = lsuc lzero} Nat) (inj 0))
| 33.430052
| 145
| 0.537818
|
9ab0868e26bdf8f8fd1d8dce6021539d79603225
| 388
|
agda
|
Agda
|
prototyping/FFI/Data/HaskellInt.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-11-06T08:03:00.000Z
|
2021-11-06T08:03:00.000Z
|
prototyping/FFI/Data/HaskellInt.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/FFI/Data/HaskellInt.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
module FFI.Data.HaskellInt where
open import Agda.Builtin.Int using (Int)
{-# FOREIGN GHC import qualified Data.Int #-}
postulate HaskellInt : Set
{-# COMPILE GHC HaskellInt = type Data.Int.Int #-}
postulate
intToHaskellInt : Int → HaskellInt
haskellIntToInt : HaskellInt → Int
{-# COMPILE GHC intToHaskellInt = fromIntegral #-}
{-# COMPILE GHC haskellIntToInt = fromIntegral #-}
| 25.866667
| 50
| 0.739691
|
9a32aaf5298accb372e877ab928ae334d8e43719
| 4,200
|
agda
|
Agda
|
Cubical/Algebra/CommAlgebra/Properties.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommAlgebra/Properties.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommAlgebra/Properties.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommAlgebra.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Reflection.StrictEquiv
open import Cubical.Structures.Axioms
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommAlgebra.Base
private
variable
ℓ ℓ′ : Level
-- An R-algebra is the same as a CommRing A with a CommRingHom φ : R → A
module CommAlgChar (R : CommRing ℓ) where
open Iso
open IsRingHom
open CommRingTheory
CommRingWithHom : Type (ℓ-suc ℓ)
CommRingWithHom = Σ[ A ∈ CommRing ℓ ] CommRingHom R A
toCommAlg : CommRingWithHom → CommAlgebra R ℓ
toCommAlg (A , φ , φIsHom) = ⟨ A ⟩ , ACommAlgStr
where
open CommRingStr (snd A)
ACommAlgStr : CommAlgebraStr R ⟨ A ⟩
CommAlgebraStr.0a ACommAlgStr = 0r
CommAlgebraStr.1a ACommAlgStr = 1r
CommAlgebraStr._+_ ACommAlgStr = _+_
CommAlgebraStr._·_ ACommAlgStr = _·_
CommAlgebraStr.- ACommAlgStr = -_
CommAlgebraStr._⋆_ ACommAlgStr r a = (φ r) · a
CommAlgebraStr.isCommAlgebra ACommAlgStr = makeIsCommAlgebra
is-set +Assoc +Rid +Rinv +Comm ·Assoc ·Lid ·Ldist+ ·-comm
(λ _ _ x → cong (λ y → y · x) (pres· φIsHom _ _) ∙ sym (·Assoc _ _ _))
(λ _ _ x → cong (λ y → y · x) (pres+ φIsHom _ _) ∙ ·Ldist+ _ _ _)
(λ _ _ _ → ·Rdist+ _ _ _)
(λ x → cong (λ y → y · x) (pres1 φIsHom) ∙ ·Lid x)
(λ _ _ _ → sym (·Assoc _ _ _))
fromCommAlg : CommAlgebra R ℓ → CommRingWithHom
fromCommAlg A = (CommAlgebra→CommRing A) , φ , φIsHom
where
open CommRingStr (snd R) renaming (_·_ to _·r_) hiding (·Lid)
open CommAlgebraStr (snd A)
open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A)
φ : ⟨ R ⟩ → ⟨ A ⟩
φ r = r ⋆ 1a
φIsHom : IsRingHom (CommRing→Ring R .snd) φ (CommRing→Ring (CommAlgebra→CommRing A) .snd)
φIsHom = makeIsRingHom (⋆-lid _) (λ _ _ → ⋆-ldist _ _ _)
λ x y → cong (λ a → (x ·r y) ⋆ a) (sym (·Lid _)) ∙ ⋆Dist· _ _ _ _
CommRingWithHomRoundTrip : (Aφ : CommRingWithHom) → fromCommAlg (toCommAlg Aφ) ≡ Aφ
CommRingWithHomRoundTrip (A , φ) = ΣPathP (APath , φPathP)
where
open CommRingStr
-- note that the proofs of the axioms might differ!
APath : fst (fromCommAlg (toCommAlg (A , φ))) ≡ A
fst (APath i) = ⟨ A ⟩
0r (snd (APath i)) = 0r (snd A)
1r (snd (APath i)) = 1r (snd A)
_+_ (snd (APath i)) = _+_ (snd A)
_·_ (snd (APath i)) = _·_ (snd A)
-_ (snd (APath i)) = -_ (snd A)
isCommRing (snd (APath i)) = isProp→PathP (λ i → isPropIsCommRing _ _ _ _ _ )
(isCommRing (snd (fst (fromCommAlg (toCommAlg (A , φ)))))) (isCommRing (snd A)) i
-- this only works because fst (APath i) = fst A definitionally!
φPathP : PathP (λ i → CommRingHom R (APath i)) (snd (fromCommAlg (toCommAlg (A , φ)))) φ
φPathP = RingHomPathP _ _ _ _ _ _ λ i x → ·Rid (snd A) (fst φ x) i
CommAlgRoundTrip : (A : CommAlgebra R ℓ) → toCommAlg (fromCommAlg A) ≡ A
CommAlgRoundTrip A = ΣPathP (refl , AlgStrPathP)
where
open CommAlgebraStr ⦃...⦄
instance
_ = snd A
AlgStrPathP : PathP (λ i → CommAlgebraStr R ⟨ A ⟩) (snd (toCommAlg (fromCommAlg A))) (snd A)
CommAlgebraStr.0a (AlgStrPathP i) = 0a
CommAlgebraStr.1a (AlgStrPathP i) = 1a
CommAlgebraStr._+_ (AlgStrPathP i) = _+_
CommAlgebraStr._·_ (AlgStrPathP i) = _·_
CommAlgebraStr.-_ (AlgStrPathP i) = -_
CommAlgebraStr._⋆_ (AlgStrPathP i) r x = (⋆-lassoc r 1a x ∙ cong (r ⋆_) (·Lid x)) i
CommAlgebraStr.isCommAlgebra (AlgStrPathP i) = isProp→PathP
(λ i → isPropIsCommAlgebra _ _ _ _ _ _ (CommAlgebraStr._⋆_ (AlgStrPathP i)))
(CommAlgebraStr.isCommAlgebra (snd (toCommAlg (fromCommAlg A)))) isCommAlgebra i
CommAlgIso : Iso (CommAlgebra R ℓ) CommRingWithHom
fun CommAlgIso = fromCommAlg
inv CommAlgIso = toCommAlg
rightInv CommAlgIso = CommRingWithHomRoundTrip
leftInv CommAlgIso = CommAlgRoundTrip
| 36.842105
| 94
| 0.689048
|
57fbc30c2c7d3c1add8e6208facfeda228164ca3
| 24
|
agda
|
Agda
|
test/Fail/InvalidNamePartEquals.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/InvalidNamePartEquals.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/InvalidNamePartEquals.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
test = forall _=_ → Set
| 12
| 23
| 0.625
|
13f263883784ee76b20546ac1c515de61d1168c6
| 1,741
|
agda
|
Agda
|
src/Categories/Diagram/Coend.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Coend.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Coend.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor.Bifunctor
module Categories.Diagram.Coend {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Bifunctor (Category.op C) C D) where
private
module C = Category C
module D = Category D
open D
open HomReasoning
variable
A B : Obj
f g : A ⇒ B
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation.Dinatural
open import Categories.Morphism.Reasoning D
open Functor F
record Cowedge : Set (levelOfTerm F) where
field
E : Obj
dinatural : DinaturalTransformation F (const E)
module dinatural = DinaturalTransformation dinatural
Cowedge-∘ : (W : Cowedge) → Cowedge.E W ⇒ A → Cowedge
Cowedge-∘ {A = A} W f = record
{ E = A
; dinatural = extranaturalˡ (λ X → f ∘ dinatural.α X)
(assoc ○ ∘-resp-≈ʳ (extranatural-commˡ dinatural) ○ sym-assoc)
}
where open Cowedge W
record Coend : Set (levelOfTerm F) where
field
cowedge : Cowedge
module cowedge = Cowedge cowedge
open cowedge public
open Cowedge
field
factor : (W : Cowedge) → cowedge.E ⇒ E W
universal : ∀ {W : Cowedge} {A} → factor W ∘ cowedge.dinatural.α A ≈ dinatural.α W A
unique : ∀ {W : Cowedge} {g : cowedge.E ⇒ E W} → (∀ {A} → g ∘ cowedge.dinatural.α A ≈ dinatural.α W A) → factor W ≈ g
η-id : factor cowedge ≈ D.id
η-id = unique identityˡ
unique′ :(∀ {A} → f ∘ cowedge.dinatural.α A ≈ g ∘ cowedge.dinatural.α A) → f ≈ g
unique′ {f = f} {g = g} eq = ⟺ (unique {W = Cowedge-∘ cowedge f} refl) ○ unique (⟺ eq)
| 28.540984
| 124
| 0.645606
|
1e9fde3f285516d4a9c0f6459fec836b8b544ec5
| 7,846
|
agda
|
Agda
|
Nat.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | 1
|
2019-12-19T23:42:31.000Z
|
2019-12-19T23:42:31.000Z
|
Nat.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
Nat.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
open import Prelude
module Nat where
-- definitions
data Nat : Set where
Z : Nat
1+ : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat → Nat → Nat
Z + m = m
1+ n + m = 1+ (n + m)
infixl 60 _+_
data _≤_ : Nat → Nat → Set where
≤refl : ∀{n} → n ≤ n
≤1+ : ∀{n m} → n ≤ m → n ≤ 1+ m
infix 40 _≤_
_<_ : Nat → Nat → Set
n < m = n ≤ m ∧ n ≠ m
infix 40 _<_
difference : ∀{n m} → n ≤ m → Nat
difference {n} {.n} ≤refl = Z
difference {n} {.(1+ _)} (≤1+ n≤m-1) = 1+ (difference n≤m-1)
-- basic theorems
-- the succ operation is injective
1+inj : ∀{n m} → 1+ n == 1+ m → n == m
1+inj refl = refl
1+ap : ∀{n m} → n == m → 1+ n == 1+ m
1+ap {n} {.n} refl = refl
1+ap-cp : ∀{n m} → 1+ n ≠ 1+ m → n ≠ m
1+ap-cp h1 h2 = h1 (1+ap h2)
1+inj-cp : ∀{n m} → n ≠ m → 1+ n ≠ 1+ m
1+inj-cp h1 h2 = h1 (1+inj h2)
-- equality of naturals is decidable. we represent this as computing a
-- choice of units, with inl <> meaning that the naturals are indeed the
-- same and inr <> that they are not.
natEQ : (x y : Nat) → ((x == y) ∨ ((x == y) → ⊥))
natEQ Z Z = Inl refl
natEQ Z (1+ y) = Inr (λ ())
natEQ (1+ x) Z = Inr (λ ())
natEQ (1+ x) (1+ y) with natEQ x y
natEQ (1+ x) (1+ .x) | Inl refl = Inl refl
... | Inr b = Inr (λ x₁ → b (1+inj x₁))
0≠1+n : ∀{n} → 0 ≠ 1+ n
0≠1+n = λ ()
-- _+_ theorems
n+Z==n : ∀{n} → n + Z == n
n+Z==n {Z} = refl
n+Z==n {1+ n} = 1+ap n+Z==n
n+1+m==1+n+m : ∀{n m} → n + 1+ m == 1+ (n + m)
n+1+m==1+n+m {Z} = refl
n+1+m==1+n+m {1+ n} = 1+ap n+1+m==1+n+m
n≠n+1+m : ∀{n m} → n ≠ n + 1+ m
n≠n+1+m {Z} {m} ()
n≠n+1+m {1+ n} {m} h = 1+inj-cp n≠n+1+m h
+comm : ∀{a b} → a + b == b + a
+comm {Z} {b} = ! n+Z==n
+comm {1+ a} {Z} = 1+ap n+Z==n
+comm {1+ a} {1+ b} with a + 1+ b | b + 1+ a | n+1+m==1+n+m {a} {b} | n+1+m==1+n+m {b} {a}
+comm {1+ a} {1+ b} | _ | _ | refl | refl = 1+ap (1+ap (+comm {a}))
+assc : ∀{a b c} → (a + b) + c == a + (b + c)
+assc {Z} = refl
+assc {1+ a} = 1+ap (+assc {a})
a+n==a+m→n==m : ∀{a n m} → a + n == a + m → n == m
a+n==a+m→n==m {Z} refl = refl
a+n==a+m→n==m {1+ a} a+n==a+m = a+n==a+m→n==m (1+inj a+n==a+m)
n+a==m+a→n==m : ∀{n m a} → n + a == m + a → n == m
n+a==m+a→n==m {n} {m} {a} n+a==m+a rewrite +comm {n} {a} | +comm {m} {a} = a+n==a+m→n==m n+a==m+a
-- _≤_ theorems
0≤n : ∀{n} → Z ≤ n
0≤n {Z} = ≤refl
0≤n {1+ n} = ≤1+ 0≤n
1+n≰0 : ∀{n} → 1+ n ≤ Z → ⊥
1+n≰0 = λ ()
n≤m→1+n≤1+m : ∀{n m} → n ≤ m → 1+ n ≤ 1+ m
n≤m→1+n≤1+m {n} {.n} ≤refl = ≤refl
n≤m→1+n≤1+m {n} {.(1+ _)} (≤1+ h) = ≤1+ (n≤m→1+n≤1+m h)
1+n≤1+m→n≤m : ∀{n m} → 1+ n ≤ 1+ m → n ≤ m
1+n≤1+m→n≤m {n} {.n} ≤refl = ≤refl
1+n≤1+m→n≤m {n} {Z} (≤1+ h) = abort (1+n≰0 h)
1+n≤1+m→n≤m {n} {1+ m} (≤1+ h) = ≤1+ (1+n≤1+m→n≤m h)
n+s≤m+s→n≤m : ∀{n m s} → n + s ≤ m + s → n ≤ m
n+s≤m+s→n≤m {n} {m} {s = Z} n+s≤m+s
rewrite n+Z==n {n} | n+Z==n {m} = n+s≤m+s
n+s≤m+s→n≤m {n} {m} {s = 1+ s} n+s≤m+s
rewrite n+1+m==1+n+m {n} {s} | n+1+m==1+n+m {m} {s}
= n+s≤m+s→n≤m (1+n≤1+m→n≤m n+s≤m+s)
1+n≰n : ∀{n} → 1+ n ≤ n → ⊥
1+n≰n {Z} h = abort (1+n≰0 h)
1+n≰n {1+ n} h = 1+n≰n (1+n≤1+m→n≤m h)
≤total : ∀{n m} → n ≤ m ∨ m ≤ n
≤total {Z} {m} = Inl 0≤n
≤total {1+ n} {Z} = Inr (≤1+ 0≤n)
≤total {1+ n} {1+ m} with ≤total {n} {m}
≤total {1+ n} {1+ m} | Inl h = Inl (n≤m→1+n≤1+m h)
≤total {1+ n} {1+ m} | Inr h = Inr (n≤m→1+n≤1+m h)
≤trans : ∀{a b c} → a ≤ b → b ≤ c → a ≤ c
≤trans ≤refl b≤c = b≤c
≤trans (≤1+ a≤b) ≤refl = ≤1+ a≤b
≤trans (≤1+ a≤b) (≤1+ b≤c) = ≤1+ (≤trans (≤1+ a≤b) b≤c)
≤antisym : ∀{n m} → n ≤ m → m ≤ n → n == m
≤antisym {n} {.n} ≤refl m≤n = refl
≤antisym {n} {.(1+ _)} (≤1+ h1) h2 = abort (1+n≰n (≤trans h2 h1))
n≤n+m : ∀{n m} → n ≤ n + m
n≤n+m {n} {Z} with n + Z | n+Z==n {n}
n≤n+m {_} {Z} | _ | refl = ≤refl
n≤n+m {n} {1+ m} with n + 1+ m | ! (n+1+m==1+n+m {n} {m})
n≤n+m {n} {1+ m} | _ | refl = ≤trans n≤n+m (≤1+ ≤refl)
n≤m+n : ∀{n m} → n ≤ m + n
n≤m+n {n} {m} rewrite +comm {m} {n} = n≤n+m
-- _<_ theorems
n≮0 : ∀{n} → n < Z → ⊥
n≮0 {Z} (π3 , π4) = π4 refl
n≮0 {1+ n} (π3 , π4) = 1+n≰0 π3
n<1+n : ∀{n} → n < 1+ n
π1 n<1+n = ≤1+ ≤refl
π2 n<1+n ()
1+n<1+m→n<m : ∀{n m} → 1+ n < 1+ m → n < m
π1 (1+n<1+m→n<m (π3 , π4)) = 1+n≤1+m→n≤m π3
π2 (1+n<1+m→n<m (π3 , π4)) = 1+ap-cp π4
<trans : ∀{a b c} → a < b → b < c → a < c
π1 (<trans (π3 , π4) (π5 , π6)) = ≤trans π3 π5
π2 (<trans (π3 , π4) (≤refl , π6)) = abort (π6 refl)
π2 (<trans (π3 , π4) (≤1+ π5 , π6)) refl = 1+n≰n (≤trans π3 π5)
<antisym : ∀{n m} → n < m → m < n → ⊥
<antisym (n≤m , n≠m) (m≤n , _) = n≠m (≤antisym n≤m m≤n)
<antirefl : ∀{n} → n < n → ⊥
<antirefl (_ , ne) = abort (ne refl)
n<m→n<s+m : ∀{n m s} → n < m → n < s + m
n<m→n<s+m {s = Z} n<m = n<m
n<m→n<s+m {s = 1+ s} n<m =
<trans (n<m→n<s+m {s = s} n<m) n<1+n
n<m→1+n<1+m : ∀{n m} → n < m → 1+ n < 1+ m
n<m→1+n<1+m (π3 , π4) = n≤m→1+n≤1+m π3 , 1+inj-cp π4
0<1+n : ∀{n} → 0 < 1+ n
0<1+n {Z} = ≤1+ ≤refl , (λ ())
0<1+n {1+ n} = 0≤n , (λ ())
1+n≤m→n<m : ∀{n m} → 1+ n ≤ m → n < m
1+n≤m→n<m ≤refl = n<1+n
1+n≤m→n<m (≤1+ 1+n≤m) = <trans (1+n≤m→n<m 1+n≤m) n<1+n
n≤m→n<1+m : ∀{n m} → n ≤ m → n < 1+ m
n≤m→n<1+m {Z} n≤m = 0<1+n
n≤m→n<1+m {1+ n} n≤m = n<m→1+n<1+m (1+n≤m→n<m n≤m)
n<m→1+n≤m : ∀{n m} → n < m → 1+ n ≤ m
n<m→1+n≤m (≤refl , ne) = abort (ne refl)
n<m→1+n≤m (≤1+ n≤m , _) = n≤m→1+n≤1+m n≤m
n<m→n≤m : ∀{n m} → n < m → n ≤ m
n<m→n≤m n<m = 1+n≤1+m→n≤m (≤1+ (n<m→1+n≤m n<m))
<dec : (n m : Nat) → n < m ∨ n == m ∨ m < n
<dec n m with natEQ n m
... | Inl refl = Inr (Inl refl)
... | Inr ne with ≤total {n} {m}
... | Inl ≤refl = abort (ne refl)
... | Inl (≤1+ n≤m) = Inl (n≤m→n<1+m n≤m)
... | Inr ≤refl = abort (ne refl)
... | Inr (≤1+ m≤n) = Inr (Inr (n≤m→n<1+m m≤n))
<dec-refl : (n : Nat) → <dec n n == Inr (Inl refl)
<dec-refl n with <dec n n
<dec-refl n | Inl (_ , ne) = abort (ne refl)
<dec-refl n | Inr (Inl refl) = refl
<dec-refl n | Inr (Inr (_ , ne)) = abort (ne refl)
-- difference theorems
m-n+n==m : ∀{n m} → (n≤m : n ≤ m) → difference n≤m + n == m
m-n+n==m ≤refl = refl
m-n+n==m (≤1+ n≤m) = 1+ap (m-n+n==m n≤m)
n+m-n==m : ∀{n m} → (n≤n+m : n ≤ n + m) → difference n≤n+m == m
n+m-n==m {n} n≤n+m =
n+a==m+a→n==m (m-n+n==m n≤n+m · +comm {n})
a+b==c→a==c-b : ∀{a b c} → a + b == c → (b≤c : b ≤ c) → a == difference b≤c
a+b==c→a==c-b a+b==c b≤c
= n+a==m+a→n==m (a+b==c · ! (m-n+n==m b≤c))
diff-proof-irrelevance : ∀{n m} →
(n≤m1 n≤m2 : n ≤ m) →
difference n≤m1 == difference n≤m2
diff-proof-irrelevance ≤refl ≤refl = refl
diff-proof-irrelevance ≤refl (≤1+ n≤m2) = abort (1+n≰n n≤m2)
diff-proof-irrelevance (≤1+ n≤m1) ≤refl = abort (1+n≰n n≤m1)
diff-proof-irrelevance (≤1+ n≤m1) (≤1+ n≤m2) = 1+ap (diff-proof-irrelevance n≤m1 n≤m2)
m-n==1+m-1+n : ∀{n m} →
(n≤m : n ≤ m) →
(1+n≤1+m : 1+ n ≤ 1+ m) →
difference n≤m == difference 1+n≤1+m
m-n==1+m-1+n {n} {.n} ≤refl ≤refl = refl
m-n==1+m-1+n {n} {.n} ≤refl (≤1+ 1+n≤n) = abort (1+n≰n 1+n≤n)
m-n==1+m-1+n {.(1+ _)} {.(1+ _)} (≤1+ 1+m≤m) ≤refl = abort (1+n≰n 1+m≤m)
m-n==1+m-1+n {n} {.(1+ _)} (≤1+ n≤m) (≤1+ 1+n≤1+m) = 1+ap (m-n==1+m-1+n n≤m 1+n≤1+m)
m-n==m+s-n+s : ∀{n m s} →
(n≤m : n ≤ m) →
(n+s≤m+s : n + s ≤ m + s) →
difference n≤m == difference n+s≤m+s
m-n==m+s-n+s {n} {m} {s = Z} n≤m n+s≤m+s
rewrite n+Z==n {n} | n+Z==n {m}
= diff-proof-irrelevance n≤m n+s≤m+s
m-n==m+s-n+s {n} {m} {s = 1+ s} n≤m n+s≤m+s
rewrite n+1+m==1+n+m {n} {s} | n+1+m==1+n+m {m} {s}
= (m-n==m+s-n+s n≤m (1+n≤1+m→n≤m n+s≤m+s)) · (m-n==1+m-1+n (1+n≤1+m→n≤m n+s≤m+s) n+s≤m+s)
| 30.768627
| 99
| 0.410273
|
13dcc442cf818e82bf901114ab71cf52694cdf16
| 9,397
|
agda
|
Agda
|
src/Algebra/Graph/Theorems.agda
|
algebraic-graphs/alga-theory
|
0fdb96c0233d9be83eba637f0434d0fd22aefb1d
|
[
"MIT"
] | 60
|
2017-12-27T14:57:04.000Z
|
2022-03-22T23:05:29.000Z
|
src/Algebra/Graph/Theorems.agda
|
algebraic-graphs/alga-theory
|
0fdb96c0233d9be83eba637f0434d0fd22aefb1d
|
[
"MIT"
] | 3
|
2018-04-12T16:25:13.000Z
|
2018-06-23T13:54:02.000Z
|
src/Algebra/Graph/Theorems.agda
|
algebraic-graphs/alga-theory
|
0fdb96c0233d9be83eba637f0434d0fd22aefb1d
|
[
"MIT"
] | 6
|
2017-12-17T20:48:20.000Z
|
2019-05-09T23:53:28.000Z
|
module Algebra.Graph.Theorems where
open import Algebra.Graph
open import Algebra.Graph.Reasoning
+pre-idempotence : ∀ {A} {x : Graph A} -> x + x + ε ≡ x
+pre-idempotence {_} {x} =
begin
(x + x) + ε ≡⟨ L (L (symmetry *right-identity)) ⟩
(x * ε + x) + ε ≡⟨ L (R (symmetry *right-identity)) ⟩
(x * ε + x * ε) + ε ≡⟨ R (symmetry *right-identity) ⟩
(x * ε + x * ε) + ε * ε ≡⟨ symmetry decomposition ⟩
(x * ε) * ε ≡⟨ *right-identity ⟩
x * ε ≡⟨ *right-identity ⟩
x
∎
+identity : ∀ {A} {x : Graph A} -> x + ε ≡ x
+identity {_} {x} =
begin
x + ε ≡⟨ symmetry +pre-idempotence ⟩
((x + ε) + (x + ε)) + ε ≡⟨ L +associativity ⟩
(((x + ε) + x) + ε) + ε ≡⟨ L (L (symmetry +associativity)) ⟩
((x + (ε + x)) + ε) + ε ≡⟨ L (L (R +commutativity)) ⟩
((x + (x + ε)) + ε) + ε ≡⟨ L (L +associativity) ⟩
(((x + x) + ε) + ε) + ε ≡⟨ L (symmetry +associativity) ⟩
((x + x) + (ε + ε)) + ε ≡⟨ symmetry +associativity ⟩
(x + x) + ((ε + ε) + ε) ≡⟨ R +pre-idempotence ⟩
(x + x) + ε ≡⟨ +pre-idempotence ⟩
x
∎
+idempotence : ∀ {A} {x : Graph A} -> x + x ≡ x
+idempotence = transitivity (symmetry +identity) +pre-idempotence
saturation : ∀ {A} {x : Graph A} -> x * x * x ≡ x * x
saturation {_} {x} =
begin
(x * x) * x ≡⟨ decomposition ⟩
(x * x + x * x) + x * x ≡⟨ L +idempotence ⟩
x * x + x * x ≡⟨ +idempotence ⟩
x * x
∎
absorption : ∀ {A} {x y : Graph A} -> x * y + x + y ≡ x * y
absorption {_} {x} {y} =
begin
(x * y + x) + y ≡⟨ L (R (symmetry *right-identity)) ⟩
(x * y + x * ε) + y ≡⟨ R (symmetry *right-identity) ⟩
(x * y + x * ε) + y * ε ≡⟨ symmetry decomposition ⟩
(x * y) * ε ≡⟨ *right-identity ⟩
x * y
∎
-- Subgraph relation
⊆reflexivity : ∀ {A} {x : Graph A} -> x ⊆ x
⊆reflexivity = +idempotence
⊆antisymmetry : ∀ {A} {x y : Graph A} -> x ⊆ y -> y ⊆ x -> x ≡ y
⊆antisymmetry p q = symmetry q -- x = y + x
>> +commutativity -- y + x = x + y
>> p -- x + y = y
⊆transitivity : ∀ {A} {x y z : Graph A} -> x ⊆ y -> y ⊆ z -> x ⊆ z
⊆transitivity p q = symmetry
(symmetry q -- z = y + z
>> L (symmetry p) -- y + z = (x + y) + z
>> symmetry +associativity -- (x + y) + z = x + (y + z)
>> R q) -- x + (y + z) = x + z
⊆least-element : ∀ {A} {x : Graph A} -> ε ⊆ x
⊆least-element = +commutativity >> +identity
⊆overlay : ∀ {A} {x y : Graph A} -> x ⊆ (x + y)
⊆overlay = +associativity >> L +idempotence
⊆connect : ∀ {A} {x y : Graph A} -> (x + y) ⊆ (x * y)
⊆connect = +commutativity >> +associativity >> absorption
⊆left-overlay-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (x + z) ⊆ (y + z)
⊆left-overlay-monotony {_} {x} {y} {z} p =
begin
(x + z) + (y + z) ≡⟨ symmetry +associativity ⟩
x + (z + (y + z)) ≡⟨ R +commutativity ⟩
x + ((y + z) + z) ≡⟨ R (symmetry +associativity) ⟩
x + (y + (z + z)) ≡⟨ R (R +idempotence) ⟩
x + (y + z) ≡⟨ +associativity ⟩
(x + y) + z ≡⟨ L p ⟩
y + z
∎
⊆right-overlay-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (z + x) ⊆ (z + y)
⊆right-overlay-monotony {_} {x} {y} {z} p =
begin
(z + x) + (z + y) ≡⟨ +associativity ⟩
((z + x) + z) + y ≡⟨ L +commutativity ⟩
(z + (z + x)) + y ≡⟨ L +associativity ⟩
((z + z) + x) + y ≡⟨ L (L +idempotence) ⟩
(z + x) + y ≡⟨ symmetry +associativity ⟩
z + (x + y) ≡⟨ R p ⟩
z + y
∎
⊆left-connect-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (x * z) ⊆ (y * z)
⊆left-connect-monotony {_} {x} {y} {z} p =
begin
(x * z) + (y * z) ≡⟨ symmetry right-distributivity ⟩
(x + y) * z ≡⟨ L p ⟩
y * z
∎
⊆right-connect-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (z * x) ⊆ (z * y)
⊆right-connect-monotony {_} {x} {y} {z} p =
begin
(z * x) + (z * y) ≡⟨ symmetry left-distributivity ⟩
z * (x + y) ≡⟨ R p ⟩
z * y
∎
⊆left-monotony : ∀ {A} {op : BinaryOperator} {x y z : Graph A} -> x ⊆ y -> apply op x z ⊆ apply op y z
⊆left-monotony {_} {+op} {x} {y} {z} p = ⊆left-overlay-monotony p
⊆left-monotony {_} {*op} {x} {y} {z} p = ⊆left-connect-monotony p
⊆right-monotony : ∀ {A} {op : BinaryOperator} {x y z : Graph A} -> x ⊆ y -> apply op z x ⊆ apply op z y
⊆right-monotony {_} {+op} {x} {y} {z} p = ⊆right-overlay-monotony p
⊆right-monotony {_} {*op} {x} {y} {z} p = ⊆right-connect-monotony p
-- | Helper theorems
flip-end : ∀ {A} {x y z : Graph A} -> (x + y + z) ≡ (x + z + y)
flip-end = symmetry +associativity >> R +commutativity >> +associativity
*+ltriple : ∀ {A} {x y z : Graph A} -> (x * (y + z)) ≡ (x * y) + (x * z) + (y + z)
*+ltriple {_} {x} {y} {z} =
begin
(x * (y + z)) ≡⟨ left-distributivity ⟩
(x * y + x * z) ≡⟨ L (symmetry absorption) ⟩
(x * y + x + y + x * z) ≡⟨ R (symmetry absorption) ⟩
((x * y + x + y) + (x * z + x + z)) ≡⟨ symmetry +associativity ⟩
((x * y + x) + (y + (x * z + x + z))) ≡⟨ R +commutativity ⟩
((x * y + x) + ((x * z + x + z) + y)) ≡⟨ symmetry +associativity ⟩
(x * y + (x + (x * z + x + z + y))) ≡⟨ R +commutativity ⟩
(x * y + (x * z + x + z + y + x)) ≡⟨ R flip-end ⟩
(x * y + (x * z + x + z + x + y)) ≡⟨ R (L flip-end) ⟩
(x * y + (x * z + x + x + z + y)) ≡⟨ R (L (L (symmetry +associativity >> R +idempotence))) ⟩
(x * y + (x * z + x + z + y)) ≡⟨ R (L (L (L (symmetry absorption)))) ⟩
(x * y + (x * z + x + z + x + z + y)) ≡⟨ R (L (L flip-end)) ⟩
(x * y + (x * z + x + x + z + z + y)) ≡⟨ R (L (L (L (symmetry +associativity >> R +idempotence)))) ⟩
(x * y + (x * z + x + z + z + y)) ≡⟨ R (L (L absorption)) ⟩
(x * y + (x * z + z + y)) ≡⟨ R (symmetry +associativity) ⟩
(x * y + (x * z + (z + y))) ≡⟨ +associativity ⟩
(x * y + (x * z) + (z + y)) ≡⟨ +right-congruence +commutativity ⟩
(x * y) + (x * z) + (y + z)
∎
+*ltriple : ∀ {A} {x y z : Graph A} -> (x + (y * z)) ≡ (x + y) + (x + z) + (y * z)
+*ltriple {_} {x} {y} {z} =
begin
(x + (y * z)) ≡⟨ R (symmetry absorption) ⟩
(x + (y * z + y + z)) ≡⟨ R (symmetry +associativity >> +commutativity) ⟩
(x + (y + z + y * z)) ≡⟨ L (symmetry +idempotence) ⟩
(x + x + (y + z + y * z)) ≡⟨ +associativity ⟩
(x + x + (y + z) + y * z) ≡⟨ L (+associativity) ⟩
(x + x + y + z + y * z) ≡⟨ L (L flip-end) ⟩
(x + y + x + z + y * z) ≡⟨ L (symmetry +associativity) ⟩
(x + y + (x + z) + (y * z))
∎
++ltriple : ∀ {A} {x y z : Graph A} -> (x + (y + z)) ≡ (x + y) + (x + z) + (y + z)
++ltriple {_} {x} {y} {z} =
begin
(x + (y + z)) ≡⟨ +associativity ⟩
(x + y + z) ≡⟨ L (symmetry +idempotence) ⟩
(x + y + (x + y) + z) ≡⟨ symmetry +associativity ⟩
(x + y + (x + y + z)) ≡⟨ R flip-end ⟩
(x + y + (x + z + y)) ≡⟨ R (L (R (symmetry +idempotence))) ⟩
(x + y + (x + (z + z) + y)) ≡⟨ R (L (+associativity)) ⟩
(x + y + (x + z + z + y)) ≡⟨ R (symmetry +associativity) ⟩
(x + y + ((x + z) + (z + y))) ≡⟨ +associativity ⟩
(x + y + (x + z) + (z + y)) ≡⟨ R (+commutativity) ⟩
(x + y + (x + z) + (y + z))
∎
*+rtriple : ∀ {A} {x y z : Graph A} -> ((x * y) + z) ≡ (x * y) + (x + z) + (y + z)
*+rtriple {_} {x} {y} {z} =
begin
(x * y + z) ≡⟨ L (symmetry absorption) ⟩
(x * y + x + y + z) ≡⟨ R (symmetry +idempotence) ⟩
(x * y + x + y + (z + z)) ≡⟨ +associativity ⟩
(x * y + x + y + z + z) ≡⟨ L flip-end ⟩
(x * y + x + z + y + z) ≡⟨ symmetry +associativity ⟩
(x * y + x + z + (y + z)) ≡⟨ L (symmetry +associativity) ⟩
(x * y + (x + z) + (y + z))
∎
+*rtriple : ∀ {A} {x y z : Graph A} -> ((x + y) * z) ≡ (x + y) + (x * z) + (y * z)
+*rtriple {_} {x} {y} {z} =
begin
((x + y) * z) ≡⟨ right-distributivity ⟩
(x * z + y * z) ≡⟨ L (symmetry absorption) ⟩
(x * z + x + z + y * z) ≡⟨ R (symmetry absorption) ⟩
(x * z + x + z + (y * z + y + z)) ≡⟨ symmetry (R +associativity) ⟩
(x * z + x + z + (y * z + (y + z))) ≡⟨ R +commutativity ⟩
(x * z + x + z + (y + z + y * z)) ≡⟨ +associativity ⟩
(x * z + x + z + (y + z) + y * z) ≡⟨ L +associativity ⟩
(x * z + x + z + y + z + y * z) ≡⟨ L flip-end ⟩
(x * z + x + z + z + y + y * z) ≡⟨ L (L (symmetry +associativity)) ⟩
(x * z + x + (z + z) + y + y * z) ≡⟨ L (L (R +idempotence)) ⟩
(x * z + x + z + y + y * z) ≡⟨ L (L (L (R (symmetry +idempotence)))) ⟩
(x * z + (x + x) + z + y + y * z) ≡⟨ L (L (L +associativity)) ⟩
(x * z + x + x + z + y + y * z) ≡⟨ L (L (symmetry +associativity)) ⟩
(x * z + x + (x + z) + y + y * z) ≡⟨ L (L (R +commutativity)) ⟩
(x * z + x + (z + x) + y + y * z) ≡⟨ L (L +associativity)⟩
(x * z + x + z + x + y + y * z) ≡⟨ L (L (L absorption)) ⟩
(x * z + x + y + y * z) ≡⟨ symmetry (L +associativity) ⟩
(x * z + (x + y) + y * z) ≡⟨ L +commutativity ⟩
(x + y + (x * z) + (y * z))
∎
++rtriple : ∀ {A} {x y z : Graph A} -> ((x + y) + z) ≡ (x + y) + (x + z) + (y + z)
++rtriple {_} {x} {y} {z} = symmetry +associativity >> ++ltriple
| 42.139013
| 104
| 0.406832
|
30f1a10312ebfa0b0952ddf4c085616489747915
| 2,010
|
agda
|
Agda
|
lib/Haskell/Prim/Foldable.agda
|
JonathanBrouwer/agda2hs
|
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
|
[
"MIT"
] | 55
|
2020-10-20T13:36:25.000Z
|
2022-03-26T21:57:56.000Z
|
lib/Haskell/Prim/Foldable.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 63
|
2020-10-22T05:19:27.000Z
|
2022-02-25T15:47:30.000Z
|
lib/Haskell/Prim/Foldable.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 18
|
2020-10-21T22:19:09.000Z
|
2022-03-12T11:42:52.000Z
|
module Haskell.Prim.Foldable where
open import Haskell.Prim
open import Haskell.Prim.Num
open import Haskell.Prim.Eq
open import Haskell.Prim.List
open import Haskell.Prim.Int
open import Haskell.Prim.Bool
open import Haskell.Prim.Maybe
open import Haskell.Prim.Either
open import Haskell.Prim.Tuple
open import Haskell.Prim.Monoid
--------------------------------------------------
-- Foldable
record Foldable (t : Set → Set) : Set₁ where
field
foldMap : ⦃ Monoid b ⦄ → (a → b) → t a → b
foldr : (a → b → b) → b → t a → b
foldr f z t = foldMap ⦃ MonoidEndo ⦄ f t z
foldl : (b → a → b) → b → t a → b
foldl f z t = foldMap ⦃ MonoidEndoᵒᵖ ⦄ (flip f) t z
any : (a → Bool) → t a → Bool
any = foldMap ⦃ MonoidDisj ⦄
all : (a → Bool) → t a → Bool
all = foldMap ⦃ MonoidConj ⦄
and : t Bool → Bool
and = all id
or : t Bool → Bool
or = any id
null : t a → Bool
null = all (const false)
concat : t (List a) → List a
concat = foldMap id
concatMap : (a → List b) → t a → List b
concatMap = foldMap
elem : ⦃ Eq a ⦄ → a → t a → Bool
elem x = foldMap ⦃ MonoidDisj ⦄ (x ==_)
notElem : ⦃ Eq a ⦄ → a → t a → Bool
notElem x t = not (elem x t)
toList : t a → List a
toList = foldr _∷_ []
sum : ⦃ iNum : Num a ⦄ → t a → a
sum = foldMap ⦃ MonoidSum ⦄ id
product : ⦃ iNum : Num a ⦄ → t a → a
product = foldMap ⦃ MonoidProduct ⦄ id
length : t a → Int
length = foldMap ⦃ MonoidSum ⦄ (const 1)
open Foldable ⦃ ... ⦄ public
{-# COMPILE AGDA2HS Foldable existing-class #-}
instance
iFoldableList : Foldable List
iFoldableList .foldMap f [] = mempty
iFoldableList .foldMap f (x ∷ xs) = f x <> foldMap f xs
iFoldableMaybe : Foldable Maybe
iFoldableMaybe .foldMap _ Nothing = mempty
iFoldableMaybe .foldMap f (Just x) = f x
iFoldableEither : Foldable (Either a)
iFoldableEither .foldMap _ (Left _) = mempty
iFoldableEither .foldMap f (Right x) = f x
iFoldablePair : Foldable (a ×_)
iFoldablePair .foldMap f (_ , x) = f x
| 23.372093
| 57
| 0.612935
|
ade92643573af00d4c2d664d70cd380c9d93fa03
| 961
|
agda
|
Agda
|
examples/outdated-and-incorrect/cat/Terminal.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/cat/Terminal.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/cat/Terminal.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Terminal where
open import Base
open import Category
open import Unique
open import Dual
import Iso
module Term (ℂ : Cat) where
private ℂ' = η-Cat ℂ
private open module C = Cat ℂ'
private open module U = Uniq ℂ'
private open module I = Iso ℂ'
Terminal : (A : Obj) -> Set1
Terminal A = (B : Obj) -> ∃! \(f : B ─→ A) -> True
toTerminal : {A B : Obj} -> Terminal A -> B ─→ A
toTerminal term = getWitness (term _)
terminalIso : {A B : Obj} -> Terminal A -> Terminal B -> A ≅ B
terminalIso tA tB = iso (toTerminal tB)
(toTerminal tA)
p q
where
p : toTerminal tB ∘ toTerminal tA == id
p = witnessEqual (tB _) tt tt
q : toTerminal tA ∘ toTerminal tB == id
q = witnessEqual (tA _) tt tt
module Init (ℂ : Cat) = Term (η-Cat ℂ op)
renaming
( Terminal to Initial
; toTerminal to fromInitial
; terminalIso to initialIso
)
| 23.439024
| 64
| 0.577523
|
5ec7c02e47dc7dc040ab8ab4430fb9e4f77c4924
| 2,115
|
agda
|
Agda
|
agda/hott/core/univalence.agda
|
piyush-kurur/hott
|
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
|
[
"BSD-3-Clause"
] | null | null | null |
agda/hott/core/univalence.agda
|
piyush-kurur/hott
|
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
|
[
"BSD-3-Clause"
] | null | null | null |
agda/hott/core/univalence.agda
|
piyush-kurur/hott
|
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module hott.core.univalence where
open import hott.core.universe
open import hott.functions
open import hott.core.equality
open import hott.core.sigma
-- The core idea of univalence is to "identify" isomorphic types as
-- equal. Of course the normal definition of isomorphism is that there
-- should be a map from A to B that is witnesses the equivalence of the
-- two type. This is captured by the following record.
record _≃_ {a b : Level}(A : Type a)(B : Type b) : Type (a ⊔ b) where
constructor IdentifyTypesVia
field
equiv : (A → B) -- The equivalence
left-inv : (B → A) -- its left inverse
right-inv : (B → A) -- and its right inverse
-- The proofs of the fact that the left and right inverses are actually
-- left and right inverses.
left-inv∘equiv~idA : left-inv ∘ equiv ~ id
iso∘right-equiv~idB : equiv ∘ right-inv ~ id
-- Of course a type should be equivalent to itself via identity.
A≃A : {ℓ : Level}{A : Type ℓ} → A ≃ A
A≃A {ℓ} {A} = IdentifyTypesVia id id id (λ _ → refl) (λ _ → refl)
-- Equal types are equivalent.
≡→≃ : {ℓ : Level}{A B : Type ℓ} → A ≡ B → A ≃ B
≡→≃ refl = A≃A
-- For the converse we need the univalence. However Univalence says
-- something. Not only can we infer A ≡ B from A ≃ B via the postulate
-- ua, this map together with ≡→≃ gives an equivalence of types.
module Univalence {ℓ : Level}{A B : Type ℓ} where
-- The main axiom is to identify A ≃ B with A ≡ B
postulate ua : A ≃ B → A ≡ B
-- Now we are ready for the univalence axiom.
UnivalenceAxiom : (A ≃ B) ≃ (A ≡ B)
UnivalenceAxiom = IdentifyTypesVia ua ≡→≃ ≡→≃ linv-prf rinv-prf
where postulate rinv-prf : ua ∘ ≡→≃ ~ id
postulate linv-prf : ≡→≃ ∘ ua ~ id
-- The next function helps in clean use of the univalence
-- axioms in equational reasoning.
--
--
-- begin ...
-- ≡ B by univalence
-- ...
--
-- provided an appropriate instance of A ≃ B is available in the
-- vicinity.
--
univalence : ⦃ a≃b : A ≃ B ⦄ → A ≡ B
univalence ⦃ a≃b ⦄ = ua a≃b
open Univalence public
| 32.045455
| 75
| 0.636879
|
433b401bf47f86ccaba69c64dd0df87b177299bf
| 5,519
|
agda
|
Agda
|
RevNoRepeat.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
RevNoRepeat.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
RevNoRepeat.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
import Level as L
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Empty
open import Data.Nat
open import Data.Nat.Properties
open import RevMachine
module RevNoRepeat {ℓ} (M : RevMachine {ℓ}) where
infix 99 _ᵣₑᵥ
infixr 10 _∷_
infixr 10 _++↦_
open RevMachine.RevMachine M
is-stuck : State → Set _
is-stuck st = ∄[ st' ] (st ↦ st')
is-initial : State → Set _
is-initial st = ∄[ st' ] (st' ↦ st)
data _↦ᵣₑᵥ_ : State → State → Set (L.suc ℓ) where
_ᵣₑᵥ : ∀ {st₁ st₂} → st₁ ↦ st₂ → st₂ ↦ᵣₑᵥ st₁
data _↦*_ : State → State → Set (L.suc ℓ) where
◾ : {st : State} → st ↦* st
_∷_ : {st₁ st₂ st₃ : State} → st₁ ↦ st₂ → st₂ ↦* st₃ → st₁ ↦* st₃
_++↦_ : {st₁ st₂ st₃ : State} → st₁ ↦* st₂ → st₂ ↦* st₃ → st₁ ↦* st₃
◾ ++↦ st₁↦*st₂ = st₁↦*st₂
(st₁↦st₁' ∷ st₁'↦*st₂) ++↦ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ st₂'↦*st₃)
len↦ : ∀ {st st'} → st ↦* st' → ℕ
len↦ ◾ = 0
len↦ (_ ∷ r) = 1 + len↦ r
data _↦ᵣₑᵥ*_ : State → State → Set (L.suc ℓ) where
◾ : ∀ {st} → st ↦ᵣₑᵥ* st
_∷_ : ∀ {st₁ st₂ st₃} → st₁ ↦ᵣₑᵥ st₂ → st₂ ↦ᵣₑᵥ* st₃ → st₁ ↦ᵣₑᵥ* st₃
_++↦ᵣₑᵥ_ : ∀ {st₁ st₂ st₃} → st₁ ↦ᵣₑᵥ* st₂ → st₂ ↦ᵣₑᵥ* st₃ → st₁ ↦ᵣₑᵥ* st₃
◾ ++↦ᵣₑᵥ st₁↦ᵣₑᵥ*st₂ = st₁↦ᵣₑᵥ*st₂
(st₁↦ᵣₑᵥst₁' ∷ st₁'↦ᵣₑᵥ*st₂) ++↦ᵣₑᵥ st₂'↦ᵣₑᵥ*st₃ = st₁↦ᵣₑᵥst₁' ∷ (st₁'↦ᵣₑᵥ*st₂ ++↦ᵣₑᵥ st₂'↦ᵣₑᵥ*st₃)
Rev↦ : ∀ {st₁ st₂} → st₁ ↦* st₂ → st₂ ↦ᵣₑᵥ* st₁
Rev↦ ◾ = ◾
Rev↦ (r ∷ rs) = Rev↦ rs ++↦ᵣₑᵥ ((r ᵣₑᵥ) ∷ ◾)
Rev↦ᵣₑᵥ : ∀ {st₁ st₂} → st₁ ↦ᵣₑᵥ* st₂ → st₂ ↦* st₁
Rev↦ᵣₑᵥ ◾ = ◾
Rev↦ᵣₑᵥ ((r ᵣₑᵥ) ∷ rs) = Rev↦ᵣₑᵥ rs ++↦ (r ∷ ◾)
deterministic* : ∀ {st st₁ st₂} → st ↦* st₁ → st ↦* st₂
→ is-stuck st₁ → is-stuck st₂
→ st₁ ≡ st₂
deterministic* ◾ ◾ stuck₁ stuck₂ = refl
deterministic* ◾ (r ∷ ↦*₂) stuck₁ stuck₂ = ⊥-elim (stuck₁ (_ , r))
deterministic* (r ∷ ↦*₁) ◾ stuck₁ stuck₂ = ⊥-elim (stuck₂ (_ , r))
deterministic* (r₁ ∷ ↦*₁) (r₂ ∷ ↦*₂) stuck₁ stuck₂ with deterministic r₁ r₂
... | refl = deterministic* ↦*₁ ↦*₂ stuck₁ stuck₂
deterministic*' : ∀ {st st₁ st'} → (rs₁ : st ↦* st₁) → (rs : st ↦* st')
→ is-stuck st'
→ Σ[ rs' ∈ st₁ ↦* st' ] (len↦ rs ≡ len↦ rs₁ + len↦ rs')
deterministic*' ◾ rs stuck = rs , refl
deterministic*' (r ∷ rs₁) ◾ stuck = ⊥-elim (stuck (_ , r))
deterministic*' (r ∷ rs₁) (r' ∷ rs) stuck with deterministic r r'
... | refl with deterministic*' rs₁ rs stuck
... | (rs' , eq) = rs' , cong suc eq
deterministicᵣₑᵥ* : ∀ {st st₁ st₂} → st ↦ᵣₑᵥ* st₁ → st ↦ᵣₑᵥ* st₂
→ is-initial st₁ → is-initial st₂
→ st₁ ≡ st₂
deterministicᵣₑᵥ* ◾ ◾ initial₁ initial₂ = refl
deterministicᵣₑᵥ* ◾ (r ᵣₑᵥ ∷ ↦ᵣₑᵥ*₂) initial₁ initial₂ = ⊥-elim (initial₁ (_ , r))
deterministicᵣₑᵥ* (r ᵣₑᵥ ∷ ↦ᵣₑᵥ*₁) ◾ initial₁ initial₂ = ⊥-elim (initial₂ (_ , r))
deterministicᵣₑᵥ* (r₁ ᵣₑᵥ ∷ ↦ᵣₑᵥ*₁) (r₂ ᵣₑᵥ ∷ ↦ᵣₑᵥ*₂) initial₁ initial₂ with deterministicᵣₑᵥ r₁ r₂
... | refl = deterministicᵣₑᵥ* ↦ᵣₑᵥ*₁ ↦ᵣₑᵥ*₂ initial₁ initial₂
data _↦[_]_ : State → ℕ → State → Set (L.suc ℓ) where
◾ : ∀ {st} → st ↦[ 0 ] st
_∷_ : ∀ {st₁ st₂ st₃ n} → st₁ ↦ st₂ → st₂ ↦[ n ] st₃ → st₁ ↦[ suc n ] st₃
_++↦ⁿ_ : ∀ {st₁ st₂ st₃ n m} → st₁ ↦[ n ] st₂ → st₂ ↦[ m ] st₃ → st₁ ↦[ n + m ] st₃
◾ ++↦ⁿ st₁↦*st₂ = st₁↦*st₂
(st₁↦st₁' ∷ st₁'↦*st₂) ++↦ⁿ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ⁿ st₂'↦*st₃)
data _↦ᵣₑᵥ[_]_ : State → ℕ → State → Set (L.suc ℓ) where
◾ : ∀ {st} → st ↦ᵣₑᵥ[ 0 ] st
_∷_ : ∀ {st₁ st₂ st₃ n} → st₁ ↦ᵣₑᵥ st₂ → st₂ ↦ᵣₑᵥ[ n ] st₃ → st₁ ↦ᵣₑᵥ[ suc n ] st₃
_++↦ᵣₑᵥⁿ_ : ∀ {st₁ st₂ st₃ n m} → st₁ ↦ᵣₑᵥ[ n ] st₂ → st₂ ↦ᵣₑᵥ[ m ] st₃ → st₁ ↦ᵣₑᵥ[ n + m ] st₃
◾ ++↦ᵣₑᵥⁿ st₁↦*st₂ = st₁↦*st₂
(st₁↦st₁' ∷ st₁'↦*st₂) ++↦ᵣₑᵥⁿ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ᵣₑᵥⁿ st₂'↦*st₃)
deterministicⁿ : ∀ {st st₁ st₂ n} → st ↦[ n ] st₁ → st ↦[ n ] st₂
→ st₁ ≡ st₂
deterministicⁿ ◾ ◾ = refl
deterministicⁿ (r₁ ∷ rs₁) (r₂ ∷ rs₂) with deterministic r₁ r₂
... | refl = deterministicⁿ rs₁ rs₂
deterministicᵣₑᵥⁿ : ∀ {st st₁ st₂ n} → st ↦ᵣₑᵥ[ n ] st₁ → st ↦ᵣₑᵥ[ n ] st₂
→ st₁ ≡ st₂
deterministicᵣₑᵥⁿ ◾ ◾ = refl
deterministicᵣₑᵥⁿ (r₁ ᵣₑᵥ ∷ rs₁) (r₂ ᵣₑᵥ ∷ rs₂) with deterministicᵣₑᵥ r₁ r₂
... | refl = deterministicᵣₑᵥⁿ rs₁ rs₂
private
split↦ⁿ : ∀ {st st'' n m} → st ↦ᵣₑᵥ[ n + m ] st''
→ ∃[ st' ] (st ↦ᵣₑᵥ[ n ] st' × st' ↦ᵣₑᵥ[ m ] st'')
split↦ⁿ {n = 0} {m} rs = _ , ◾ , rs
split↦ⁿ {n = suc n} {m} (r ∷ rs) with split↦ⁿ {n = n} {m} rs
... | st' , st↦ⁿst' , st'↦ᵐst'' = st' , (r ∷ st↦ⁿst') , st'↦ᵐst''
diff : ∀ {n m} → n < m → ∃[ k ] (0 < k × n + k ≡ m)
diff {0} {(suc m)} (s≤s z≤n) = suc m , s≤s z≤n , refl
diff {(suc n)} {(suc (suc m))} (s≤s (s≤s n≤m)) with diff {n} {suc m} (s≤s n≤m)
... | k , 0<k , eq = k , 0<k , cong suc eq
Revⁿ : ∀ {st st' n} → st ↦[ n ] st' → st' ↦ᵣₑᵥ[ n ] st
Revⁿ {n = 0} ◾ = ◾
Revⁿ {n = suc n} (r ∷ rs) rewrite +-comm 1 n = Revⁿ rs ++↦ᵣₑᵥⁿ (r ᵣₑᵥ ∷ ◾)
NoRepeat : ∀ {st₀ stₙ stₘ n m}
→ is-initial st₀
→ n < m
→ st₀ ↦[ n ] stₙ
→ st₀ ↦[ m ] stₘ
→ stₙ ≢ stₘ
NoRepeat {stₙ = st} {_} {m} st₀-is-init n<m st₀↦ᵐst st₀↦ᵐ⁺ᵏ⁺¹st refl with diff n<m
... | suc k , 0<k , refl with (Revⁿ st₀↦ᵐst , Revⁿ st₀↦ᵐ⁺ᵏ⁺¹st)
... | st'↦ᵐst₀' , st'↦ᵐ⁺ᵏ⁺¹st₀' with split↦ⁿ {n = m} {suc k} st'↦ᵐ⁺ᵏ⁺¹st₀'
... | st′ , st'↦ᵐst′ , st′↦ᵏ⁺¹st₀' with deterministicᵣₑᵥⁿ st'↦ᵐst₀' st'↦ᵐst′
... | refl with st′↦ᵏ⁺¹st₀'
... | r ᵣₑᵥ ∷ rs = ⊥-elim (st₀-is-init (_ , r))
| 40.284672
| 101
| 0.517485
|
1d9ff406bca8a54a2d9fbb71f5b642bef7f6e66c
| 256
|
agda
|
Agda
|
test/fail/BadTermination.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/fail/BadTermination.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/BadTermination.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- {-# OPTIONS -v term:20 #-}
module BadTermination where
data N : Set where
zero : N
suc : N -> N
postulate inf : N
data D : N -> Set where
d₁ : D (suc inf)
d₂ : D inf
f : (n : N) -> D n -> N
f .inf d₂ = zero
f .(suc inf) d₁ = f inf d₂
| 15.058824
| 29
| 0.527344
|
2262c612d0307ae31beef48227b9266395f6af13
| 10,894
|
agda
|
Agda
|
src/Categories/Functor/Power.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
src/Categories/Functor/Power.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Power.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Power Functors, Exponentials over a Category C
-- Mainly categories where the objects are functions (Fin n -> Obj) considered pointwise
-- and then upgraded to Functors.
module Categories.Functor.Power {o ℓ e} (C : Category o ℓ e) where
open Category C
open HomReasoning
open Equiv
open import Level using (Level; _⊔_)
open import Data.Nat.Base using (ℕ; _+_; zero; suc; _<_)
open import Data.Product using (_,_)
open import Data.Fin.Base using (Fin; inject+; raise; zero; suc; fromℕ<)
open import Data.Sum using (_⊎_; inj₁; inj₂; map) renaming ([_,_] to ⟦_,_⟧; [_,_]′ to ⟦_,_⟧′)
open import Data.Vec.N-ary hiding (curryⁿ)
open import Function.Base as Fun using (flip; _$_) renaming (_∘_ to _∙_; id to idf)
open import Categories.Category.Product using (Product; _⁂_)
open import Categories.Functor hiding (id)
open import Categories.Functor.Bifunctor using (Bifunctor; overlap-×)
private
variable
i j k : Level
I I′ J J′ : Set i
D E : Category i j k
n n′ m m′ : ℕ
Exp : Set i → Category _ _ _
Exp I = record
{ Obj = I → Obj
; _⇒_ = λ x y → ∀ i → x i ⇒ y i
; _≈_ = λ f g → ∀ i → f i ≈ g i
; id = λ _ → id
; _∘_ = λ f g i → f i ∘ g i
; assoc = λ _ → assoc
; sym-assoc = λ _ → sym-assoc
; identityˡ = λ _ → identityˡ
; identityʳ = λ _ → identityʳ
; identity² = λ _ → identity²
; equiv = record
{ refl = λ _ → refl
; sym = λ eq i → sym $ eq i
; trans = λ eq₁ eq₂ i → trans (eq₁ i) (eq₂ i)
}
; ∘-resp-≈ = λ eq₁ eq₂ i → ∘-resp-≈ (eq₁ i) (eq₂ i)
}
Power : (n : ℕ) → Category o ℓ e
Power n = Exp (Fin n)
-- Convention: the ′ version is for a general index set, unprimed for a ℕ
-- representing Fin n. So Powerfunctor D n is Exp C (Fin n) ⇒ D, i.e.
-- essentially C ^ n ⇒ D.
Powerfunctor′ : (D : Category o ℓ e) (I : Set i) → Set (i ⊔ e ⊔ ℓ ⊔ o)
Powerfunctor′ D I = Functor (Exp I) D
Powerfunctor : (D : Category o ℓ e) (n : ℕ) → Set (e ⊔ ℓ ⊔ o)
Powerfunctor D n = Powerfunctor′ D (Fin n)
-- With C = D, so Powerendo n is C ^ n => C
Powerendo′ : (I : Set i) → Set (i ⊔ e ⊔ ℓ ⊔ o)
Powerendo′ I = Powerfunctor′ C I
Powerendo : (n : ℕ) → Set (e ⊔ ℓ ⊔ o)
Powerendo n = Powerfunctor C n
-- Hyperendo n m is C ^ n ⇒ C ^ m
Hyperendo : (n m : ℕ) → Set (e ⊔ ℓ ⊔ o)
Hyperendo n m = Functor (Power n) (Power m)
-- Hyperendo′ I J is C ^ I → C ^ J
Hyperendo′ : (I : Set i) (J : Set j) → Set (i ⊔ j ⊔ e ⊔ ℓ ⊔ o)
Hyperendo′ I J = Functor (Exp I) (Exp J)
-- Parallel composition of Hyperendo′ (via disjoint union of index sets)
infixr 9 _par_
_par_ : (F : Hyperendo′ I I′) (G : Hyperendo′ J J′) → Hyperendo′ (I ⊎ J) (I′ ⊎ J′)
F par G = record
{ F₀ = λ xs → ⟦ F.F₀ (xs ∙ inj₁) , G.F₀ (xs ∙ inj₂) ⟧′
; F₁ = λ fs → ⟦ F.F₁ (fs ∙ inj₁) , G.F₁ (fs ∙ inj₂) ⟧
; identity = ⟦ F.identity , G.identity ⟧
; homomorphism = ⟦ F.homomorphism , G.homomorphism ⟧
; F-resp-≈ = λ fs≈gs → ⟦ F.F-resp-≈ (fs≈gs ∙ inj₁) , G.F-resp-≈ (fs≈gs ∙ inj₂) ⟧
}
where module F = Functor F
module G = Functor G
-- "flattening" means going from a general disjoint union of Fin to a single Fin,
-- which has the effect of doing from Powerfunctor′ to Powerfunctor
flattenP : (F : Powerfunctor′ D (Fin n ⊎ Fin m)) → Powerfunctor D (n + m)
flattenP {n = n} {m = m} F = record
{ F₀ = λ As → F₀ (As ∙ pack)
; F₁ = λ fs → F₁ (fs ∙ pack)
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = λ fs≈gs → F-resp-≈ (fs≈gs ∙ pack)
}
where open Functor F
pack = ⟦ inject+ m , raise n ⟧′
-- TODO unpackFun (and pack above) should be in stdlib
private
unpackFin : ∀ n → Fin (n + m) → Fin n ⊎ Fin m
unpackFin zero f = inj₂ f
unpackFin (suc n) zero = inj₁ zero
unpackFin (suc n) (suc f) = map suc idf (unpackFin n f)
-- needs a better name?
unflattenP : Powerfunctor D (n + m) → Powerfunctor′ D (Fin n ⊎ Fin m)
unflattenP {n = n} {m = m} F = record
{ F₀ = λ As → F₀ (As ∙ unpackFin _)
; F₁ = λ fs → F₁ (fs ∙ unpackFin _)
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = λ fs≈gs → F-resp-≈ (fs≈gs ∙ unpackFin _)
}
where open Functor F
-- flatten a Hyperendo′ "on the right" when over a union of Fin
flattenHʳ : (F : Hyperendo′ I (Fin n ⊎ Fin m)) → Hyperendo′ I (Fin (n + m))
flattenHʳ {n = n} {m = m} F = record
{ F₀ = λ As → F₀ As ∙ unpackFin n
; F₁ = λ fs → F₁ fs ∙ unpackFin n
; identity = identity ∙ unpackFin n
; homomorphism = homomorphism ∙ unpackFin n
; F-resp-≈ = λ fs≈gs → F-resp-≈ fs≈gs ∙ unpackFin n
}
where open Functor F
-- flatten on both sides.
flattenH : (F : Hyperendo′ (Fin n ⊎ Fin m) (Fin n′ ⊎ Fin m′)) → Hyperendo (n + m) (n′ + m′)
flattenH = flattenHʳ ∙ flattenP
-- Pretty syntax for flattening of parallel composition of Hyperendo
infixr 9 _∥_
_∥_ : (F : Hyperendo n n′) (G : Hyperendo m m′) → Hyperendo (n + m) (n′ + m′)
F ∥ G = flattenH (F par G)
-- split is C ^ (I ⊎ J) to C ^ I × C ^ J, as a Functor
split : Functor (Exp (I ⊎ J)) (Product (Exp I) (Exp J))
split = record
{ F₀ = λ As → As ∙ inj₁ , As ∙ inj₂
; F₁ = λ fs → fs ∙ inj₁ , fs ∙ inj₂
; identity = (λ _ → refl) , λ _ → refl
; homomorphism = (λ _ → refl) , λ _ → refl
; F-resp-≈ = λ eq → (λ i → eq (inj₁ i)) , λ i → eq (inj₂ i)
}
reduce′ : (H : Bifunctor C C C) (F : Powerendo′ I) (G : Powerendo′ J) → Powerendo′ (I ⊎ J)
reduce′ H F G = H ∘F (F ⁂ G) ∘F split
reduce : ∀ (H : Bifunctor C C C) {n m} (F : Powerendo n) (G : Powerendo m) → Powerendo (n + m)
reduce H F G = flattenP $ reduce′ H F G
flattenP-assocʳ : ∀ {n₁ n₂ n₃} (F : Powerendo′ (Fin n₁ ⊎ Fin n₂ ⊎ Fin n₃)) → Powerendo (n₁ + n₂ + n₃)
flattenP-assocʳ {n₁} {n₂} {n₃} F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ fs → F.F₁ (fs ∙ pack)
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≈ = λ fs≈gs → F.F-resp-≈ (fs≈gs ∙ pack)
}
where module F = Functor F
pack = ⟦ inject+ n₃ ∙ inject+ n₂ , ⟦ inject+ n₃ ∙ raise n₁ , raise (n₁ + n₂) ⟧′ ⟧′
reduce2ʳ : ∀ (G : Bifunctor C C C) {n₁ n₂ n₃} (F₁ : Powerendo n₁) (F₂ : Powerendo n₂) (F₃ : Powerendo n₃) → Powerendo ((n₁ + n₂) + n₃)
reduce2ʳ G F₁ F₂ F₃ = flattenP-assocʳ $ reduce′ G F₁ $ reduce′ G F₂ F₃
overlaps : (H : Bifunctor D D E) (F G : Powerfunctor′ D I) → Powerfunctor′ E I
overlaps = overlap-×
overlap2ʳ : (G : Bifunctor C C C) (F₁ F₂ F₃ : Powerendo n) → Powerendo n
overlap2ʳ G F₁ F₂ F₃ = overlaps G F₁ (overlaps G F₂ F₃)
-- select′ i always evaluates at i
select′ : (i : I) → Powerendo′ I
select′ i = record
{ F₀ = _$ i
; F₁ = _$ i
; identity = refl
; homomorphism = refl
; F-resp-≈ = _$ i
}
-- select (m < n) is really select′ (Fin n), but only for m < n
select : m < n → Powerendo n
select m<n = select′ (fromℕ< m<n)
triv : (n : ℕ) → Hyperendo n n
triv n = record
{ F₀ = idf
; F₁ = idf
; identity = λ _ → refl
; homomorphism = λ _ → refl
; F-resp-≈ = idf
}
-- pad a Hyperendo on the left and right by trivial (i.e. identity) endofunctors
pad : ∀ (l r : ℕ) (F : Hyperendo n m) → Hyperendo ((l + n) + r) ((l + m) + r)
pad l r F = (triv l ∥ F) ∥ triv r
padˡ : ∀ (l : ℕ) (F : Hyperendo n m) → Hyperendo (l + n) (l + m)
padˡ l F = triv l ∥ F
padʳ : ∀ (r : ℕ) (F : Hyperendo n m) → Hyperendo (n + r) (m + r)
padʳ r F = F ∥ triv r
unary : Endofunctor C → Powerendo 1
unary F = record
{ F₀ = λ As → F.F₀ (As zero)
; F₁ = λ fs → F.F₁ (fs zero)
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≈ = λ fs≈gs → F.F-resp-≈ (fs≈gs zero)
}
where module F = Functor F
unaryH : Endofunctor C → Hyperendo 1 1
unaryH F = record
{ F₀ = λ As → F.F₀ ∙ As
; F₁ = λ fs → F.F₁ ∙ fs
; identity = λ _ → F.identity
; homomorphism = λ _ → F.homomorphism
; F-resp-≈ = λ fs≈gs → F.F-resp-≈ ∙ fs≈gs
}
where module F = Functor F
-- "constant"
nullary : Obj → Powerendo 0
nullary X = record
{ F₀ = λ _ → X
; F₁ = λ _ → id
; identity = refl
; homomorphism = sym identity²
; F-resp-≈ = λ _ → refl
}
nullaryH : Obj → Hyperendo 0 1
nullaryH X = record
{ F₀ = λ _ _ → X
; F₁ = λ _ _ → id
; identity = λ _ → refl
; homomorphism = λ _ → sym identity²
; F-resp-≈ = λ _ _ → refl
}
binary : Bifunctor C C C → Powerendo 2
binary F = record
{ F₀ = λ As → F.F₀ (As zero , As (suc zero))
; F₁ = λ fs → F.F₁ (fs zero , fs (suc zero))
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≈ = λ fs≈gs → F.F-resp-≈ (fs≈gs zero , fs≈gs (suc zero))
}
where module F = Functor F
binaryH : Bifunctor C C C → Hyperendo 2 1
binaryH F = record
{ F₀ = λ As _ → F.F₀ (As zero , As (suc zero))
; F₁ = λ fs _ → F.F₁ (fs zero , fs (suc zero))
; identity = λ _ → F.identity
; homomorphism = λ _ → F.homomorphism
; F-resp-≈ = λ fs≈gs _ → F.F-resp-≈ (fs≈gs zero , fs≈gs (suc zero))
}
where module F = Functor F
hyp : Powerendo n → Hyperendo n 1
hyp F = record
{ F₀ = λ As _ → F.F₀ As
; F₁ = λ fs _ → F.F₁ fs
; identity = λ _ → F.identity
; homomorphism = λ _ → F.homomorphism
; F-resp-≈ = λ fs≈gs _ → F.F-resp-≈ fs≈gs
}
where module F = Functor F
private
curryⁿ : ∀ n {a b} {A : Set a} {B : Set b} → ((Fin n → A) → B) → N-ary n A B
curryⁿ zero f = f (λ ())
curryⁿ (suc n) {A = A} f = λ x → curryⁿ n (f ∙ addon x)
where addon : A → (Fin n → A) → Fin (suc n) → A
addon x _ zero = x
addon _ g (suc i) = g i
plex′ : (J → Powerendo′ I) → Hyperendo′ I J
plex′ Fs = record
{ F₀ = flip (Functor.F₀ ∙ Fs)
; F₁ = flip (λ j → Functor.F₁ (Fs j))
; identity = λ j → Functor.identity (Fs j)
; homomorphism = λ j → Functor.homomorphism (Fs j)
; F-resp-≈ = flip (λ j → Functor.F-resp-≈ (Fs j))
}
plex : N-ary n (Powerendo′ I) (Hyperendo′ I (Fin n))
plex {n = n} = curryⁿ n plex′
-- like pad, but for Powerendo -- on left or right.
widenˡ : ∀ (l : ℕ) (F : Powerendo n) → Powerendo (l + n)
widenˡ l F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ {As Bs} fs → F.F₁ (fs ∙ pack)
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≈ = λ fs≈gs → F.F-resp-≈ (fs≈gs ∙ pack)
}
where module F = Functor F
pack = raise l
widenʳ : ∀ (r : ℕ) (F : Powerendo n) → Powerendo (n + r)
widenʳ r F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ fs → F.F₁ (fs ∙ pack)
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≈ = λ fs≈gs → F.F-resp-≈ (fs≈gs ∙ pack)
}
where module F = Functor F
pack = inject+ r
| 33.314985
| 134
| 0.549385
|
52a3a5be7c5817829116a51d64007826a5723da6
| 272
|
agda
|
Agda
|
test/Fail/Issue4784b.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Fail/Issue4784b.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Fail/Issue4784b.agda
|
antoinevanmuylder/agda
|
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --cubical-compatible #-}
open import Agda.Builtin.Equality
postulate
A : Set
B : A → Set
data H (@0 A : Set) : Set where
con : (@0 x : A) → H A
data G : Set where
con : (@0 x : A) → (@0 b : B x) → G
data D : Set where
con : (@0 x : A) → B x → D
| 17
| 37
| 0.525735
|
35f3bad3b78ba194f63d74659a285901b54fa365
| 604
|
agda
|
Agda
|
test/succeed/Issue106.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/succeed/Issue106.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | null | null | null |
test/succeed/Issue106.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | null | null | null |
module Issue106 where
data ℕ : Set where
zero : ℕ
suc : ℕ -> ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
_+_ : ℕ -> ℕ -> ℕ
zero + m = m
suc n + m = suc (n + m)
record ⊤ : Set where
data C : ℕ -> Set where
c : C 0
data D : Set where
d : forall s (x : C s) (xs : D) -> D
f : D -> ℕ -> ⊤
f (d zero c x) (suc n) = f (d 0 c x) n
f (d .zero c x) n = f x (suc n)
g : D -> ℕ -> ⊤
g (d .zero c x) (suc n) = g (d zero c x) n
g (d .zero c x) n = g x (suc n)
h : D -> ℕ -> ⊤
h (d .zero c x) (suc n) = h (d 0 c x) n
h (d .zero c x) n = h x (suc n)
| 17.764706
| 42
| 0.456954
|
52be8ad8641c446700fa31128360b73bb006f442
| 14,009
|
agda
|
Agda
|
src/Delay-monad/Sized/Partial-order.agda
|
nad/delay-monad
|
495f9996673d0f1f34ce202902daaa6c39f8925e
|
[
"MIT"
] | null | null | null |
src/Delay-monad/Sized/Partial-order.agda
|
nad/delay-monad
|
495f9996673d0f1f34ce202902daaa6c39f8925e
|
[
"MIT"
] | null | null | null |
src/Delay-monad/Sized/Partial-order.agda
|
nad/delay-monad
|
495f9996673d0f1f34ce202902daaa6c39f8925e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A partial order
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
open import Prelude.Size
module Delay-monad.Sized.Partial-order {a} {A : Size → Type a} where
open import Equality.Propositional as E
open import Logical-equivalence using (_⇔_)
open import Bijection equality-with-J using (_↔_)
open import Double-negation equality-with-J
open import Excluded-middle equality-with-J
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Monad equality-with-J
open import Delay-monad.Sized
open import Delay-monad.Sized.Bisimilarity as B
hiding (reflexive; symmetric; laterˡ⁻¹; laterʳ⁻¹)
open import Delay-monad.Sized.Bisimilarity.Alternative
open import Delay-monad.Sized.Bisimilarity.Negative
import Delay-monad.Sized.Termination as T
-- An ordering relation.
--
-- Capretta defines a logically equivalent relation in "General
-- Recursion via Coinductive Types".
--
-- Benton, Kennedy and Varming define a relation that is perhaps
-- logically equivalent in "Some Domain Theory and Denotational
-- Semantics in Coq".
infix 4 [_]_⊑_ [_]_⊑′_ _⊑_ _⊑′_
mutual
data [_]_⊑_ (i : Size) : Delay A ∞ → Delay A ∞ → Type a where
now : ∀ {x} → [ i ] now x ⊑ now x
laterʳ : ∀ {x y} → [ i ] x ⊑ force y → [ i ] x ⊑ later y
laterˡ : ∀ {x y} → [ i ] force x ⊑′ y → [ i ] later x ⊑ y
record [_]_⊑′_ (i : Size) (x y : Delay A ∞) : Type a where
coinductive
field
force : {j : Size< i} → [ j ] x ⊑ y
open [_]_⊑′_ public
_⊑_ : Delay A ∞ → Delay A ∞ → Type a
_⊑_ = [ ∞ ]_⊑_
_⊑′_ : Delay A ∞ → Delay A ∞ → Type a
_⊑′_ = [ ∞ ]_⊑′_
-- A derived "constructor".
later-cong : ∀ {i x y} →
[ i ] force x ⊑′ force y → [ i ] later x ⊑ later y
later-cong p = laterʳ (laterˡ p)
-- Termination predicates.
Terminates : Size → Delay A ∞ → A ∞ → Type a
Terminates i x y = [ i ] now y ⊑ x
_⇓_ : Delay A ∞ → A ∞ → Type a
_⇓_ = Terminates ∞
-- If x terminates with the values y and z, then y is equal to z.
⇓→⇓→≡ : ∀ {i x y z} → Terminates i x y → Terminates i x z → y ≡ z
⇓→⇓→≡ now now = refl
⇓→⇓→≡ (laterʳ p) (laterʳ q) = ⇓→⇓→≡ p q
-- If x is smaller than or equal to now y, and x terminates, then
-- x terminates with the value y.
⊑now→⇓→⇓ : ∀ {i x} {y z : A ∞} →
x ⊑ now y → Terminates i x z → Terminates i x y
⊑now→⇓→⇓ now now = now
⊑now→⇓→⇓ (laterˡ p) (laterʳ q) = laterʳ (⊑now→⇓→⇓ (force p) q)
-- The notion of termination defined here is pointwise isomorphic to
-- the one defined in Delay-monad.Sized.Weak-bisimilarity.
⇓↔⇓ : ∀ {i x y} → Terminates i x y ↔ T.Terminates i x y
⇓↔⇓ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
to : ∀ {i x y} → Terminates i x y → T.Terminates i x y
to now = now
to (laterʳ p) = laterʳ (to p)
from : ∀ {i x y} → T.Terminates i x y → Terminates i x y
from now = now
from (laterʳ p) = laterʳ (from p)
from∘to : ∀ {i x y} (p : Terminates i x y) → from (to p) ≡ p
from∘to now = refl
from∘to (laterʳ p) = cong laterʳ (from∘to p)
to∘from : ∀ {i x y} (p : T.Terminates i x y) → to (from p) ≡ p
to∘from now = refl
to∘from (laterʳ p) = cong laterʳ (to∘from p)
-- Terminates i is pointwise isomorphic to Terminates ∞.
Terminates↔⇓ : ∀ {i x y} → Terminates i x y ↔ x ⇓ y
Terminates↔⇓ {i} {x} {y} =
Terminates i x y ↝⟨ ⇓↔⇓ ⟩
T.Terminates i x y ↝⟨ T.Terminates↔⇓ ⟩
x T.⇓ y ↝⟨ inverse ⇓↔⇓ ⟩□
x ⇓ y □
-- The computation never is smaller than or equal to all other
-- computations.
never⊑ : ∀ {i} x → [ i ] never ⊑ x
never⊑ (now x) = laterˡ λ { .force → never⊑ (now x) }
never⊑ (later x) = later-cong λ { .force → never⊑ (force x) }
-- The computation never does not terminate.
now⋢never : ∀ {i x} → ¬ Terminates i never x
now⋢never (laterʳ p) = now⋢never p
-- One can remove later constructors.
laterˡ⁻¹ : ∀ {i} {j : Size< i} {x y} →
[ i ] later x ⊑ y →
[ j ] force x ⊑ y
laterˡ⁻¹ (laterʳ p) = laterʳ (laterˡ⁻¹ p)
laterˡ⁻¹ (laterˡ p) = force p
laterʳ⁻¹ : ∀ {i x y} →
[ i ] x ⊑ later y →
[ i ] x ⊑ force y
laterʳ⁻¹ (laterʳ p) = p
laterʳ⁻¹ (laterˡ p) = laterˡ λ { .force → laterʳ⁻¹ (force p) }
later-cong⁻¹ : ∀ {i} {j : Size< i} {x y} →
[ i ] later x ⊑ later y →
[ j ] force x ⊑ force y
later-cong⁻¹ p = laterʳ⁻¹ (laterˡ⁻¹ p)
-- Weak bisimilarity is contained in the ordering relation.
≈→⊑ : ∀ {i x y} → [ i ] x ≈ y → [ i ] x ⊑ y
≈→⊑ now = now
≈→⊑ (later p) = later-cong λ { .force → ≈→⊑ (force p) }
≈→⊑ (laterˡ p) = laterˡ λ { .force → ≈→⊑ p }
≈→⊑ (laterʳ p) = laterʳ (≈→⊑ p)
-- The ordering relation is antisymmetric (with respect to weak
-- bisimilarity).
antisymmetric : ∀ {i x y} →
[ i ] x ⊑ y → [ i ] y ⊑ x → [ i ] x ≈ y
antisymmetric {x = now x} {y = now .x} now _ = now
antisymmetric {x = now x} {y = later y} (laterʳ p) q = laterʳ (_↔_.to ⇓↔⇓ p)
antisymmetric {x = later x} {y = now y} p (laterʳ q) = laterˡ (B.symmetric (_↔_.to ⇓↔⇓ q))
antisymmetric {x = later x} {y = later y} p q =
later λ { .force → antisymmetric (later-cong⁻¹ p) (later-cong⁻¹ q) }
-- An alternative characterisation of weak bisimilarity.
≈⇔⊑×⊒ : ∀ {i x y} → [ i ] x ≈ y ⇔ ([ i ] x ⊑ y × [ i ] y ⊑ x)
≈⇔⊑×⊒ = record
{ to = λ p → ≈→⊑ p , ≈→⊑ (B.symmetric p)
; from = uncurry antisymmetric
}
-- The ordering relation is reflexive.
reflexive : ∀ {i} x → [ i ] x ⊑ x
reflexive (now x) = now
reflexive (later x) = later-cong λ { .force → reflexive (force x) }
-- Certain instances of symmetry also hold.
symmetric : ∀ {i} {x : A ∞} {y} →
Terminates i y x → [ i ] y ⊑ now x
symmetric now = now
symmetric (laterʳ p) = laterˡ λ { .force → symmetric p }
-- The ordering relation is transitive.
transitive : ∀ {i} {x y z : Delay A ∞} →
[ i ] x ⊑ y → y ⊑ z → [ i ] x ⊑ z
transitive p now = p
transitive p (laterʳ q) = laterʳ (transitive p q)
transitive (laterʳ p) (laterˡ q) = transitive p (force q)
transitive (laterˡ p) q = laterˡ λ { .force →
transitive (force p) q }
-- The termination relation respects weak bisimilarity.
⇓-respects-≈ : ∀ {i x y z} → Terminates i x z → x ≈ y → Terminates i y z
⇓-respects-≈ now q = ≈→⊑ q
⇓-respects-≈ (laterʳ p) q = ⇓-respects-≈ p (B.laterˡ⁻¹ q)
-- The ordering relation respects weak bisimilarity.
transitive-≈⊑ : ∀ {i x y z} → [ i ] x ≈ y → y ⊑ z → [ i ] x ⊑ z
transitive-≈⊑ p q = transitive (≈→⊑ p) q
transitive-⊑≈ : ∀ {i x y z} → [ i ] x ⊑ y → y ≈ z → [ i ] x ⊑ z
transitive-⊑≈ p now = p
transitive-⊑≈ (laterʳ p) (later q) = laterʳ (transitive-⊑≈ p (force q))
transitive-⊑≈ (laterˡ p) q = laterˡ λ { .force →
transitive-⊑≈ (force p) q }
transitive-⊑≈ (laterʳ p) (laterˡ q) = transitive-⊑≈ p q
transitive-⊑≈ p (laterʳ q) = laterʳ (transitive-⊑≈ p q)
-- If there is a transitivity-like function that produces an ordering
-- proof from one weak bisimilarity proof and one ordering proof, in
-- such a way that the size of the ordering proof is preserved, then
-- ∀ i → A i is uninhabited.
Transitivity-≈⊑ʳ =
∀ {i} {x y z : Delay A ∞} → x ≈ y → [ i ] y ⊑ z → [ i ] x ⊑ z
size-preserving-transitivity-≈⊑ʳ→uninhabited :
Transitivity-≈⊑ʳ → ¬ (∀ i → A i)
size-preserving-transitivity-≈⊑ʳ→uninhabited =
Transitivity-≈⊑ʳ ↝⟨ (λ trans {i} x →
[ i ] later (record { force = λ {j} → now (x j) }) ∼ never ↝⟨ ≈→⊑ ∘ ∼→ ⟩
[ i ] later (record { force = λ {j} → now (x j) }) ⊑ never ↝⟨ trans (laterʳ now) ⟩
[ i ] now (x ∞) ⊑ never ↝⟨ _↔_.to ⇓↔⇓ ⟩□
[ i ] now (x ∞) ≈ never □) ⟩
Laterˡ⁻¹-∼≈′ ↝⟨ _⇔_.from size-preserving-laterˡ⁻¹-∼≈⇔size-preserving-laterˡ⁻¹-∼≈′ ⟩
Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈→uninhabited ⟩
¬ (∀ i → A i) □
-- If A ∞ is uninhabited, then there is a transitivity proof of the
-- kind discussed above (Transitivity-≈⊑ʳ).
uninhabited→size-preserving-transitivity-≈⊑ʳ : ¬ A ∞ → Transitivity-≈⊑ʳ
uninhabited→size-preserving-transitivity-≈⊑ʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial _ _ → ≈→⊑ (trivial _ _)) ⟩
(∀ x y → x ⊑ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈⊑ʳ □
-- If transitivity can be made size-preserving in the second argument,
-- then ∀ i → A i is uninhabited.
Transitivityʳ =
∀ {i} {x y z : Delay A ∞} → x ⊑ y → [ i ] y ⊑ z → [ i ] x ⊑ z
size-preserving-transitivityʳ→uninhabited :
Transitivityʳ → ¬ (∀ i → A i)
size-preserving-transitivityʳ→uninhabited =
Transitivityʳ ↝⟨ _∘ ≈→⊑ ⟩
Transitivity-≈⊑ʳ ↝⟨ size-preserving-transitivity-≈⊑ʳ→uninhabited ⟩□
¬ (∀ i → A i) □
-- If A ∞ is uninhabited, then transitivity can be made
-- size-preserving in the second argument.
uninhabited→size-preserving-transitivityʳ : ¬ A ∞ → Transitivityʳ
uninhabited→size-preserving-transitivityʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial _ _ → ≈→⊑ (trivial _ _)) ⟩
(∀ x y → x ⊑ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivityʳ □
-- If there is a transitivity-like function that produces an ordering
-- proof from one ordering proof and one weak bisimilarity proof, in
-- such a way that the size of the weak bisimilarity proof is
-- preserved, then ∀ i → A i is uninhabited.
Transitivity-⊑≈ʳ =
∀ {i} {x y z : Delay A ∞} → x ⊑ y → [ i ] y ≈ z → [ i ] x ⊑ z
size-preserving-transitivity-⊑≈ʳ→uninhabited :
Transitivity-⊑≈ʳ → ¬ (∀ i → A i)
size-preserving-transitivity-⊑≈ʳ→uninhabited =
Transitivity-⊑≈ʳ ↝⟨ (λ trans {i} x →
[ i ] later (record { force = λ {j} → now (x j) }) ∼ never ↝⟨ ∼→ ⟩
[ i ] later (record { force = λ {j} → now (x j) }) ≈ never ↝⟨ trans (laterʳ now) ⟩
[ i ] now (x ∞) ⊑ never ↝⟨ _↔_.to ⇓↔⇓ ⟩□
[ i ] now (x ∞) ≈ never □) ⟩
Laterˡ⁻¹-∼≈′ ↝⟨ _⇔_.from size-preserving-laterˡ⁻¹-∼≈⇔size-preserving-laterˡ⁻¹-∼≈′ ⟩
Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈→uninhabited ⟩
¬ (∀ i → A i) □
-- If A ∞ is uninhabited, then there is a transitivity-like function of the
-- kind discussed above (Transitivity-⊑≈ʳ).
uninhabited→size-preserving-transitivity-⊑≈ʳ : ¬ A ∞ → Transitivity-⊑≈ʳ
uninhabited→size-preserving-transitivity-⊑≈ʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial _ _ → ≈→⊑ (trivial _ _)) ⟩
(∀ x y → x ⊑ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-⊑≈ʳ □
-- An alternative characterisation of the ordering relation.
--
-- Capretta proves a similar result in "General Recursion via
-- Coinductive Types".
--
-- One might wonder if the equivalence can be made size-preserving in
-- some way. However, note that x ⇓ y is in bijective correspondence
-- with Terminates i x y for any size i (see Terminates↔⇓).
⊑⇔⇓→⇓ : ∀ {x y} → x ⊑ y ⇔ (∀ z → x ⇓ z → y ⇓ z)
⊑⇔⇓→⇓ = record
{ to = to
; from = from _
}
where
to : ∀ {x y} → x ⊑ y → ∀ z → x ⇓ z → y ⇓ z
to p z now = p
to (laterʳ p) z q = laterʳ (to p z q)
to (laterˡ p) z (laterʳ q) = to (force p) z q
from : ∀ {i} x {y} → (∀ z → x ⇓ z → y ⇓ z) → [ i ] x ⊑ y
from (now x) p = p x now
from (later x) p = laterˡ λ { .force →
from (force x) (λ z q → p z (laterʳ q)) }
-- An alternative characterisation of weak bisimilarity.
--
-- Capretta proves a similar result in "General Recursion via
-- Coinductive Types".
≈⇔≈₂ : {x y : Delay A ∞} → x ≈ y ⇔ x ≈₂ y
≈⇔≈₂ {x} {y} =
x ≈ y ↝⟨ ≈⇔⊑×⊒ ⟩
x ⊑ y × y ⊑ x ↝⟨ ⊑⇔⇓→⇓ ×-cong ⊑⇔⇓→⇓ ⟩
(∀ z → x ⇓ z → y ⇓ z) × (∀ z → y ⇓ z → x ⇓ z) ↝⟨ ∀-cong _ (λ _ → →-cong _ (from-bijection ⇓↔⇓) (from-bijection ⇓↔⇓))
×-cong
∀-cong _ (λ _ → →-cong _ (from-bijection ⇓↔⇓) (from-bijection ⇓↔⇓)) ⟩
(∀ z → x T.⇓ z → y T.⇓ z) × (∀ z → y T.⇓ z → x T.⇓ z) ↝⟨ record { to = uncurry λ to from z → record { to = to z; from = from z }
; from = λ hyp → _⇔_.to ∘ hyp , _⇔_.from ∘ hyp
} ⟩□
(∀ z → x T.⇓ z ⇔ y T.⇓ z) □
-- If A ∞ is a set, then every computation is weakly bisimilar to
-- never or now something (assuming excluded middle and
-- extensionality).
⇑⊎⇓ :
Excluded-middle a → E.Extensionality a a →
Is-set (A ∞) → (x : Delay A ∞) → never ≈ x ⊎ ∃ λ y → x T.⇓ y
⇑⊎⇓ em ext A-set x =
⊎-map (_⇔_.from ≈⇔≈₂) id $
Excluded-middle→Double-negation-elimination em
(⊎-closure-propositional
(λ { x⇑ (y , x⇓y) →
now≉never (now y ≈⟨ x⇓y ⟩
x ≈⟨ B.symmetric (_⇔_.from ≈⇔≈₂ x⇑) ⟩∎
never ∎) })
(≈₂-propositional ext A-set)
(T.∃-Terminates-propositional A-set))
(⊎-map (_⇔_.to ≈⇔≈₂) id ⟨$⟩ T.¬¬[⇑⊎⇓] x)
| 36.865789
| 136
| 0.515312
|
43de6de64cae4e1e8a3e680018640649b4d1dd58
| 4,561
|
agda
|
Agda
|
Cubical/Algebra/Group/GroupPath.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/Group/GroupPath.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/Group/GroupPath.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
-- The SIP applied to groups
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.GroupPath where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.GroupoidLaws hiding (assoc)
open import Cubical.Data.Sigma
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
private
variable
ℓ ℓ' ℓ'' : Level
open Iso
open GroupStr
open IsGroupHom
𝒮ᴰ-Group : DUARel (𝒮-Univ ℓ) GroupStr ℓ
𝒮ᴰ-Group =
𝒮ᴰ-Record (𝒮-Univ _) IsGroupEquiv
(fields:
data[ _·_ ∣ autoDUARel _ _ ∣ pres· ]
data[ 1g ∣ autoDUARel _ _ ∣ pres1 ]
data[ inv ∣ autoDUARel _ _ ∣ presinv ]
prop[ isGroup ∣ (λ _ _ → isPropIsGroup _ _ _) ])
where
open GroupStr
open IsGroupHom
GroupPath : (M N : Group ℓ) → GroupEquiv M N ≃ (M ≡ N)
GroupPath = ∫ 𝒮ᴰ-Group .UARel.ua
-- TODO: Induced structure results are temporarily inconvenient while we transition between algebra
-- representations
module _ (G : Group ℓ) {A : Type ℓ} (m : A → A → A)
(e : ⟨ G ⟩ ≃ A)
(p· : ∀ x y → e .fst (G .snd ._·_ x y) ≡ m (e .fst x) (e .fst y))
where
private
module G = GroupStr (G .snd)
FamilyΣ : Σ[ B ∈ Type ℓ ] (B → B → B) → Type ℓ
FamilyΣ (B , n) =
Σ[ e ∈ B ]
Σ[ i ∈ (B → B) ]
IsGroup e n i
inducedΣ : FamilyΣ (A , m)
inducedΣ =
subst FamilyΣ
(UARel.≅→≡ (autoUARel (Σ[ B ∈ Type ℓ ] (B → B → B))) (e , p·))
(G.1g , G.inv , G.isGroup)
InducedGroup : Group ℓ
InducedGroup .fst = A
InducedGroup .snd ._·_ = m
InducedGroup .snd .1g = inducedΣ .fst
InducedGroup .snd .inv = inducedΣ .snd .fst
InducedGroup .snd .isGroup = inducedΣ .snd .snd
InducedGroupPath : G ≡ InducedGroup
InducedGroupPath = GroupPath _ _ .fst (e , makeIsGroupHom p·)
uaGroup : {G H : Group ℓ} → GroupEquiv G H → G ≡ H
uaGroup {G = G} {H = H} = equivFun (GroupPath G H)
-- Group-ua functoriality
Group≡ : (G H : Group ℓ) → (
Σ[ p ∈ ⟨ G ⟩ ≡ ⟨ H ⟩ ]
Σ[ q ∈ PathP (λ i → p i) (1g (snd G)) (1g (snd H)) ]
Σ[ r ∈ PathP (λ i → p i → p i → p i) (_·_ (snd G)) (_·_ (snd H)) ]
Σ[ s ∈ PathP (λ i → p i → p i) (inv (snd G)) (inv (snd H)) ]
PathP (λ i → IsGroup (q i) (r i) (s i)) (isGroup (snd G)) (isGroup (snd H)))
≃ (G ≡ H)
Group≡ G H = isoToEquiv theIso
where
theIso : Iso _ _
fun theIso (p , q , r , s , t) i = p i , groupstr (q i) (r i) (s i) (t i)
inv theIso x = cong ⟨_⟩ x , cong (1g ∘ snd) x , cong (_·_ ∘ snd) x , cong (inv ∘ snd) x , cong (isGroup ∘ snd) x
rightInv theIso _ = refl
leftInv theIso _ = refl
caracGroup≡ : {G H : Group ℓ} (p q : G ≡ H) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracGroup≡ {G = G} {H = H} p q P =
sym (transportTransport⁻ (ua (Group≡ G H)) p)
∙∙ cong (transport (ua (Group≡ G H))) helper
∙∙ transportTransport⁻ (ua (Group≡ G H)) q
where
helper : transport (sym (ua (Group≡ G H))) p ≡ transport (sym (ua (Group≡ G H))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set (snd H)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd H)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd H)) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsGroup _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaGroupId : (G : Group ℓ) → uaGroup (idGroupEquiv {G = G}) ≡ refl
uaGroupId G = caracGroup≡ _ _ uaIdEquiv
uaCompGroupEquiv : {F G H : Group ℓ} (f : GroupEquiv F G) (g : GroupEquiv G H)
→ uaGroup (compGroupEquiv f g) ≡ uaGroup f ∙ uaGroup g
uaCompGroupEquiv f g = caracGroup≡ _ _ (
cong ⟨_⟩ (uaGroup (compGroupEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
cong ⟨_⟩ (uaGroup f) ∙ cong ⟨_⟩ (uaGroup g)
≡⟨ sym (cong-∙ ⟨_⟩ (uaGroup f) (uaGroup g)) ⟩
cong ⟨_⟩ (uaGroup f ∙ uaGroup g) ∎)
| 35.084615
| 114
| 0.607761
|
38ed2e84eb287722a86f03b1e6feb7c4359e5281
| 775
|
agda
|
Agda
|
src/Categories/Category/Cartesian/Bundle.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Cartesian/Bundle.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Cartesian/Bundle.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
-- Bundled version of a Cartesian Category
module Categories.Category.Cartesian.Bundle where
open import Level
open import Categories.Category.Core using (Category)
open import Categories.Category.Cartesian using (Cartesian)
open import Categories.Category.Cartesian.Monoidal using (module CartesianMonoidal)
open import Categories.Category.Monoidal using (MonoidalCategory)
record CartesianCategory o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where
field
U : Category o ℓ e -- U for underlying
cartesian : Cartesian U
open Category U public
open Cartesian cartesian public
monoidalCategory : MonoidalCategory o ℓ e
monoidalCategory = record
{ U = U
; monoidal = CartesianMonoidal.monoidal cartesian
}
| 29.807692
| 83
| 0.743226
|
0375270be769013c641492cb27474c5ee3189a69
| 4,151
|
agda
|
Agda
|
agda/MoreLogic/Reasoning.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
agda/MoreLogic/Reasoning.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
agda/MoreLogic/Reasoning.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module MoreLogic.Reasoning where -- hProp logic
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ)
open import Cubical.Data.Sigma renaming (_×_ to infixr 4 _×_)
-- "implicational" reaoning
-- infix 3 _◼ᵖ
-- infixr 2 _⇒ᵖ⟨_⟩_
--
-- _⇒ᵖ⟨_⟩_ : ∀{ℓ ℓ' ℓ''} {Q : hProp ℓ'} {R : hProp ℓ''} → (P : hProp ℓ) → [ P ⇒ Q ] → [ Q ⇒ R ] → [ P ⇒ R ]
-- _ ⇒ᵖ⟨ pq ⟩ qr = qr ∘ pq
--
-- _◼ᵖ : ∀{ℓ} (A : hProp ℓ) → [ A ] → [ A ]
-- _ ◼ᵖ = λ x → x
infix 3 _◼
infixr 2 _⇒⟨_⟩_
infix 3 _◼ᵖ
infixr 2 ⇒ᵖ⟨⟩-syntax -- _⇒ᵖ⟨_⟩_
infix 3 _∎ᵖ
infixr 2 ⇔⟨⟩-syntax -- _⇔⟨_⟩_
⇔⟨⟩-syntax : ∀{ℓ ℓ' ℓ''} → (P : hProp ℓ'') → (((Q , R) , _) : Σ[ (Q , R) ∈ hProp ℓ' × hProp ℓ ] [ Q ⇔ R ]) → [ P ⇔ Q ] → Σ[ (P , R) ∈ hProp ℓ'' × hProp ℓ ] [ P ⇔ R ]
⇔⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .fst = P , R -- x⇔y ∙ y⇔z
⇔⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .snd .fst = fst q⇔r ∘ fst p⇔q
⇔⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .snd .snd = snd p⇔q ∘ snd q⇔r
syntax ⇔⟨⟩-syntax P QRq⇔r p⇔q = P ⇔⟨ p⇔q ⟩ QRq⇔r
_∎ᵖ : ∀{ℓ} → (P : hProp ℓ) → Σ[ (Q , R) ∈ hProp ℓ × hProp ℓ ] [ Q ⇔ R ]
_∎ᵖ P .fst = P , P
_∎ᵖ P .snd .fst x = x
_∎ᵖ P .snd .snd x = x
⇒ᵖ⟨⟩-syntax : ∀{ℓ ℓ' ℓ''} → (P : hProp ℓ'') → (((Q , R) , _) : Σ[ (Q , R) ∈ hProp ℓ' × hProp ℓ ] [ Q ⇒ R ]) → [ P ⇒ Q ] → Σ[ (P , R) ∈ hProp ℓ'' × hProp ℓ ] [ P ⇒ R ]
⇒ᵖ⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .fst = P , R -- x⇔y ∙ y⇔z
⇒ᵖ⟨⟩-syntax P ((Q , R) , q⇒r) p⇒q .snd = q⇒r ∘ p⇒q
_◼ᵖ : ∀{ℓ} → (P : hProp ℓ) → Σ[ (Q , R) ∈ hProp ℓ × hProp ℓ ] [ Q ⇒ R ]
_◼ᵖ P .fst = P , P
_◼ᵖ P .snd x = x
syntax ⇒ᵖ⟨⟩-syntax P QRq⇒r p⇒q = P ⇒ᵖ⟨ p⇒q ⟩ QRq⇒r
_⇒⟨_⟩_ : ∀{ℓ ℓ' ℓ''} {Q : Type ℓ'} {R : Type ℓ''} → (P : Type ℓ) → (P → Q) → (Q → R) → (P → R)
_ ⇒⟨ p⇒q ⟩ q⇒r = q⇒r ∘ p⇒q
_◼ : ∀{ℓ} (A : Type ℓ) → A → A
_ ◼ = λ x → x
-- ⊎⇒⊔ : ∀ {ℓ ℓ'} (P : hProp ℓ) (Q : hProp ℓ') → [ P ] ⊎ [ Q ] → [ P ⊔ Q ]
-- ⊎⇒⊔ P Q (inl x) = inlᵖ x
-- ⊎⇒⊔ P Q (inr x) = inrᵖ x
--
-- case[_⊔_]_return_of_ : ∀ {ℓ ℓ'} (P : hProp ℓ) (Q : hProp ℓ')
-- → (z : [ P ⊔ Q ])
-- → (R : [ P ⊔ Q ] → hProp ℓ'')
-- → (S : (x : [ P ] ⊎ [ Q ]) → [ R (⊎⇒⊔ P Q x) ] )
-- → [ R z ]
-- case[_⊔_]_return_of_ P Q z R S = ⊔-elim P Q R (λ p → S (inl p)) (λ q → S (inr q)) z
{- NOTE: in the CHANGELOG.md of the v1.3 non-cubical standard library, it is explained:
* Previously all equational reasoning combinators (e.g. `_≈⟨_⟩_`, `_≡⟨_⟩_`, `_≤⟨_⟩_`)
were defined in the following style:
```agda
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : ∀ x {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
```
The type checker therefore infers the RHS of the equational step from the LHS + the
type of the proof. For example for `x ≈⟨ x≈y ⟩ y ∎` it is inferred that `y ∎`
must have type `y IsRelatedTo y` from `x : A` and `x≈y : x ≈ y`.
* There are two problems with this. Firstly, it means that the reasoning combinators are
not compatible with macros (i.e. tactics) that attempt to automatically generate proofs
for `x≈y`. This is because the reflection machinary does not have access to the type of RHS
as it cannot be inferred. In practice this meant that the new reflective solvers
`Tactic.RingSolver` and `Tactic.MonoidSolver` could not be used inside the equational
reasoning. Secondly the inference procedure itself is slower as described in this
[exchange](https://lists.chalmers.se/pipermail/agda/2016/009090.html)
on the Agda mailing list.
* Therefore, as suggested on the mailing list, the order of arguments to the combinators
have been reversed so that instead the type of the proof is inferred from the LHS + RHS.
```agda
infixr -2 step-≡
step-≡ : ∀ x {y z : A} → y ≡ z → x ≡ y → x ≡ z
step-≡ y≡z x≡y = trans x≡y y≡z
syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z
```
where the `syntax` declaration is then used to recover the original order of the arguments.
This change enables the use of macros and anecdotally speeds up type checking by a
factor of 5.
-} -- TODO: that might be "correct" the way to implement these reasoning operators
| 38.794393
| 166
| 0.540834
|
2113997fefcd048c8de5076e6473db414d916367
| 2,539
|
agda
|
Agda
|
Cubical/Data/Prod/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Prod/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Prod/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Prod.Properties where
open import Cubical.Core.Everything
open import Cubical.Data.Prod.Base
open import Cubical.Data.Sigma
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
-- Swapping is an equivalence
swap : A × B → B × A
swap (x , y) = (y , x)
swap-invol : (xy : A × B) → swap (swap xy) ≡ xy
swap-invol (_ , _) = refl
isEquivSwap : (A : Type ℓ) (B : Type ℓ') → isEquiv (λ (xy : A × B) → swap xy)
isEquivSwap A B = isoToIsEquiv (iso swap swap swap-invol swap-invol)
swapEquiv : (A : Type ℓ) (B : Type ℓ') → A × B ≃ B × A
swapEquiv A B = (swap , isEquivSwap A B)
swapEq : (A : Type ℓ) (B : Type ℓ') → A × B ≡ B × A
swapEq A B = ua (swapEquiv A B)
private
open import Cubical.Data.Nat
-- As × is defined as a datatype this computes as expected
-- (i.e. "C-c C-n test1" reduces to (2 , 1)). If × is implemented
-- using Sigma this would be "transp (λ i → swapEq ℕ ℕ i) i0 (1 , 2)"
test : ℕ × ℕ
test = transp (λ i → swapEq ℕ ℕ i) i0 (1 , 2)
testrefl : test ≡ (2 , 1)
testrefl = refl
-- equivalence between the sigma-based definition and the inductive one
A×B≃A×ΣB : A × B ≃ A ×Σ B
A×B≃A×ΣB = isoToEquiv (iso (λ { (a , b) → (a , b)})
(λ { (a , b) → (a , b)})
(λ _ → refl)
(λ { (a , b) → refl }))
A×B≡A×ΣB : A × B ≡ A ×Σ B
A×B≡A×ΣB = ua A×B≃A×ΣB
swapΣEquiv : (A : Type ℓ) (B : Type ℓ') → A ×Σ B ≃ B ×Σ A
swapΣEquiv A B = compEquiv (compEquiv (invEquiv A×B≃A×ΣB) (swapEquiv A B)) A×B≃A×ΣB
-- truncation for products
isOfHLevelProd : (n : ℕ) → isOfHLevel n A → isOfHLevel n B → isOfHLevel n (A × B)
isOfHLevelProd {A = A} {B = B} n h1 h2 =
let h : isOfHLevel n (A ×Σ B)
h = isOfHLevelΣ n h1 (λ _ → h2)
in transport (λ i → isOfHLevel n (A×B≡A×ΣB {A = A} {B = B} (~ i))) h
×-≃ : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} {A : Type ℓ₁} {B : Type ℓ₂} {C : Type ℓ₃} {D : Type ℓ₄}
→ A ≃ C → B ≃ D → A × B ≃ C × D
×-≃ {A = A} {B = B} {C = C} {D = D} f g = isoToEquiv (iso φ ψ η ε)
where
φ : A × B → C × D
φ (a , b) = equivFun f a , equivFun g b
ψ : C × D → A × B
ψ (c , d) = equivFun (invEquiv f) c , equivFun (invEquiv g) d
η : section φ ψ
η (c , d) i = retEq f c i , retEq g d i
ε : retract φ ψ
ε (a , b) i = secEq f a i , secEq g b i
| 29.523256
| 83
| 0.563608
|
38627a8a9d1de54c8a32babc90199589403e1452
| 671
|
agda
|
Agda
|
src/Pi-calculus.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | 2
|
2021-03-12T18:31:14.000Z
|
2021-05-04T09:35:36.000Z
|
src/Pi-calculus.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | null | null | null |
src/Pi-calculus.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | null | null | null |
module Pi-Calculus where
-- Local modules ---------------------------------------------------------------
open import Common
using (Id)
-- π-process definition --------------------------------------------------------
data π-process : Set where
recv_from_∙_ : Id → Id → π-process → π-process -- Receive
send_to_∙_ : Id → Id → π-process → π-process -- Send
_||_ : π-process → π-process → π-process -- Composition
ν_∙_ : Id → π-process → π-process -- Restriction
!_ : π-process → π-process -- Repetition
Zero : π-process -- Inactivity
| 39.470588
| 80
| 0.421759
|
a01f8262bef18a8364c9200e12475c734d1f74d5
| 2,124
|
agda
|
Agda
|
test/Compiler/simple/Issue2918.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Issue2918.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/Issue2918.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- A memoised implementation of the Fibonacci sequence, following
-- Hinze's "Memo functions, polytypically!".
module Issue2918 where
open import Agda.Builtin.IO
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.Size
open import Agda.Builtin.Unit
record _×_ (A B : Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B
open _×_ public
mutual
data Nat (i : Size) : Set where
zero : Nat i
suc : Nat′ i → Nat i
data Nat′ (i : Size) : Set where
[_] : {j : Size< i} → Nat j → Nat′ i
mutual
ℕ→Nat : ℕ → Nat ∞
ℕ→Nat zero = zero
ℕ→Nat (suc n) = suc (ℕ→Nat′ n)
ℕ→Nat′ : ℕ → Nat′ ∞
ℕ→Nat′ n = [ ℕ→Nat n ]
mutual
Nat′[_]→ : Size → Set → Set
Nat′[ i ]→ A = A × Nat′[ i ]→′ A
record Nat′[_]→′ (i : Size) (A : Set) : Set where
coinductive
field
force : {j : Size< i} → Nat′[ j ]→ A
open Nat′[_]→′ public
tabulate : ∀ {i} {A : Set} → (Nat′ i → A) → Nat′[ i ]→′ A
force (tabulate f) = f [ zero ] , tabulate (λ n → f [ suc n ])
lookup : ∀ {i} {A : Set} → Nat′[ i ]→′ A → Nat′ i → A
lookup t [ zero ] = proj₁ (force t)
lookup t [ suc n ] = lookup (proj₂ (force t)) n
memo-fix :
{A : Set} →
(∀ {i} → (Nat′ i → A) → (Nat i → A)) →
∀ {i} → Nat′ i → A
memo-fix f =
wrapper λ { [ n ] → f (lookup (tabulate (memo-fix f))) n }
where
wrapper : ∀ {i} {A : Set} → (Nat′ i → A) → (Nat′ i → A)
wrapper f [ n ] = f [ n ]
fib-step : ∀ {i} → (Nat′ i → ℕ) → (Nat i → ℕ)
fib-step fib zero = 0
fib-step fib (suc [ zero ]) = 1
fib-step fib (suc [ suc n ]) = fib n + fib [ suc n ]
fib : ℕ → ℕ
fib n = memo-fix fib-step [ ℕ→Nat n ]
postulate
crash-after-ten-seconds : ℕ → IO ⊤
{-# FOREIGN GHC
import qualified Control.Exception
import qualified System.Timeout
crashAfterTenSeconds c = do
r <- System.Timeout.timeout (10 * 10^6)
(Control.Exception.evaluate c)
case r of
Nothing -> error "The computation timed out"
Just _ -> return ()
#-}
{-# COMPILE GHC crash-after-ten-seconds = crashAfterTenSeconds #-}
main : IO ⊤
main = crash-after-ten-seconds (fib 300)
| 22.83871
| 66
| 0.555556
|
5e6184b6c52e76ec77da9c82e2c70a9ff3642129
| 290
|
agda
|
Agda
|
test/Fail/Issue1976-constraints3.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1976-constraints3.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1976-constraints3.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-12-31, re issue #1976
-- Allow projection pattern disambiguation by parameters
postulate
A B : Set
module M (_ : Set) where
record R : Set₂ where
field
F : Set₁
open R public
module ShouldFail where
open M _
open M _
test : M.R B
F test = Set
| 13.809524
| 56
| 0.651724
|
d176a37a0cede51d183024573a2d2d325622b15c
| 345
|
agda
|
Agda
|
test/Succeed/WithoutKDisjointSum.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/WithoutKDisjointSum.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/WithoutKDisjointSum.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K #-}
-- Issue raised by Martin Escardo 2012-12-13
-- on the Agda list "no longer type checks"
module WithoutKDisjointSum where
open import Common.Equality
data ⊥ : Set where
data _⊎_ (A B : Set) : Set where
inl : A → A ⊎ B
inr : B → A ⊎ B
distinct : {A B : Set} (a : A) (b : B) → inl a ≡ inr b → ⊥
distinct a b ()
| 21.5625
| 58
| 0.614493
|
3453d6f46cdcce3cd50269890b104d1c85237e09
| 13,946
|
agda
|
Agda
|
HoTT/Exercises/Chapter2.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
HoTT/Exercises/Chapter2.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
HoTT/Exercises/Chapter2.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --without-K #-}
module HoTT.Exercises.Chapter2 where
open import HoTT.Base
module Exercise1 {i} {A : 𝒰 i} where
module _ {x y z : A} (p : x == y) (q : y == z) where
-- Induction over p
_∙₁_ : x == z
_∙₁_ = =-ind D d p z q where
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → x == z
d : (x : A) → D x x refl
d x z q = q
-- Induction over q
_∙₂_ : x == z
_∙₂_ = =-ind D d q x p where
D : (y z : A) → y == z → 𝒰 i
D y z q = (x : A) → (p : x == y) → x == z
d : (y : A) → D y y refl
d y x p = p
-- Induction over p then q
_∙₃_ : x == z
_∙₃_ = =-ind D d p z q where
E : (x z : A) → (q : x == z) → 𝒰 i
E x z q = x == z
e : (x : A) → E x x refl
e x = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → x == z
d : (x : A) → D x x refl
d x z q = =-ind E e q
module _ {x y z : A} (p : x == y) (q : y == z) where
prop₁₌₂ : p ∙₁ q == p ∙₂ q
prop₁₌₂ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₁ q == refl ∙₂ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₁ q == p ∙₂ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
prop₂₌₃ : p ∙₂ q == p ∙₃ q
prop₂₌₃ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₂ q == refl ∙₃ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₂ q == p ∙₃ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
prop₁₌₃ : p ∙₁ q == p ∙₃ q
prop₁₌₃ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₁ q == refl ∙₃ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₁ q == p ∙₃ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
module Exercise2 {i} {A : 𝒰 i} {x y z : A} {p : x == y} {q : y == z} where
open Exercise1
_ : prop₁₌₂ p q ∙ prop₂₌₃ p q == prop₁₌₃ p q
_ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = prop₁₌₂ refl q ∙ prop₂₌₃ refl q == prop₁₌₃ refl q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → prop₁₌₂ p q ∙ prop₂₌₃ p q == prop₁₌₃ p q
d : (x : A) → D x x refl
d x z q = =-ind E e q
module Exercise3 {i} {A : 𝒰 i} where
open Exercise1 using (_∙₁_)
-- Induction over q then p
_∙₄_ : {x y z : A} → x == y → y == z → x == z
_∙₄_ {x} {y} {z} p q = =-ind D d q x p where
E : (x y : A) → (p : x == y) → 𝒰 i
E x y _ = x == y
e : (x : A) → E x x refl
e x = refl
D : (y z : A) → y == z → 𝒰 i
D y z q = (x : A) → (p : x == y) → x == z
d : (y : A) → D y y refl
d y x p = =-ind E e p
prop₁₌₄ : {x y z : A} (p : x == y) (q : y == z) → p ∙₁ q == p ∙₄ q
prop₁₌₄ {x} {y} {z} p q = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₁ q == refl ∙₄ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₁ q == p ∙₄ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
module Exercise4 {i} (A : 𝒰 i) where
n-path : ℕ → 𝒰 i
n-path = ℕ-rec A (λ n P → Σ[ x ∶ P ] (Σ[ y ∶ P ] (x == y)))
module Exercise5 {i} {A B : 𝒰 i} {x y : A} {p : x == y} {f : A → B} where
open import HoTT.Identity
open import HoTT.Equivalence
_ : f x == f y ≃ transport _ p (f x) == f y
_ = g , qinv→isequiv (h , η , ε)
where
-- 2.3.6
g : f x == f y → transport _ p (f x) == f y
g = transportconst p (f x) ∙_
-- 2.3.7
h : transport _ p (f x) == f y → f x == f y
h = transportconst p (f x) ⁻¹ ∙_
η : (h ∘ g) ~ id
η q = assoc ∙ (invₗ ∙ᵣ q ∙ unitₗ ⁻¹)
ε : (g ∘ h) ~ id
ε q = assoc ∙ (invᵣ ∙ᵣ q ∙ unitₗ ⁻¹)
module Exercise6 {i} {A : 𝒰 i} {x y z : A} {p : x == y} where
open import HoTT.Equivalence
open import HoTT.Identity
_ : y == z ≃ x == z
_ = f , qinv→isequiv (g , η , ε)
where
f = p ∙_
g = p ⁻¹ ∙_
η : g ∘ f ~ id
η q = assoc ∙ (invₗ ∙ᵣ q ∙ unitₗ ⁻¹)
ε : f ∘ g ~ id
ε q = assoc ∙ (invᵣ ∙ᵣ q ∙ unitₗ ⁻¹)
module Exercise7 {i j k l} {A : 𝒰 i} {A' : 𝒰 j} {B : A → 𝒰 k} {B' : A' → 𝒰 l}
{g : A → A'} {h : {x : A} → B x → B' (g x)} where
open import HoTT.Identity
open import HoTT.Identity.Sigma
prop : {x y : Σ A B} (p : pr₁ x == pr₁ y) (q : transport B p (pr₂ x) == (pr₂ y)) →
ap (λ x → g (pr₁ x) , h (pr₂ x)) (pair⁼ {x = x} {y} (p , q)) ==
pair⁼ (ap g p , transport-ap B' g p (h (pr₂ x)) ∙ transport-∘ h p (pr₂ x) ∙ ap h q)
prop {x = _ , _} {_ , _} refl refl = refl
module Exercise8 {i j k l} {A : 𝒰 i} {B : 𝒰 j} {A' : 𝒰 k} {B' : 𝒰 l}
{g : A → A'} {h : B → B'} where
open import HoTT.Identity.Coproduct
private variable x y : A + B
f : A + B → A' + B'
f = +-rec (inl ∘ g) (inr ∘ h)
ap-gh : (p : x =+ y) → f x =+ f y
ap-gh {inl _} {inl _} (lift p) = lift (ap g p)
ap-gh {inl _} {inr _} ()
ap-gh {inr _} {inl _} ()
ap-gh {inr _} {inr _} (lift p) = lift (ap h p)
prop : (p : x =+ y) → ap f (=+-intro p) == =+-intro (ap-gh p)
prop {inl _} {inl _} (lift refl) = refl
prop {inl _} {inr _} ()
prop {inr _} {inl _} ()
prop {inr _} {inr _} (lift refl) = refl
module Exercise9 {i j k} {A : 𝒰 i} {B : 𝒰 j} where
open import HoTT.Equivalence
open import HoTT.Identity.Pi
prop₁ : {X : 𝒰 k} → (A + B → X) ≃ (A → X) × (B → X)
prop₁ {X} = f , qinv→isequiv (g , β , α)
where
f : (A + B → X) → (A → X) × (B → X)
f h = h ∘ inl , h ∘ inr
g : (A → X) × (B → X) → (A + B → X)
g (h , _) (inl a) = h a
g (_ , h) (inr b) = h b
α : f ∘ g ~ id
α (_ , _) = refl
β : g ∘ f ~ id
β _ = funext λ{(inl _) → refl ; (inr _) → refl}
prop₂ : {P : A + B → 𝒰 k} →
((x : A + B) → P x) ≃ ((a : A) → P (inl a)) × ((b : B) → P (inr b))
prop₂ {P} = f , qinv→isequiv (g , β , α)
where
f : ((x : A + B) → P x) → ((a : A) → P (inl a)) × ((b : B) → P (inr b))
f h = (h ∘ inl) , h ∘ inr
g : ((a : A) → P (inl a)) × ((b : B) → P (inr b)) → ((x : A + B) → P x)
g (h , _) (inl a) = h a
g (_ , h) (inr b) = h b
α : f ∘ g ~ id
α (_ , _) = refl
β : g ∘ f ~ id
β _ = funext λ{(inl _) → refl ; (inr _) → refl}
module Exercise10 {i j k} {A : 𝒰 i} {B : A → 𝒰 j} {C : Σ A B → 𝒰 k}
where
open import HoTT.Equivalence
_ : Σ[ x ∶ A ] Σ[ y ∶ B x ] C (x , y) ≃ Σ[ p ∶ Σ A B ] C p
_ = f , qinv→isequiv (g , η , ε)
where
f : Σ[ x ∶ A ] Σ[ y ∶ B x ] C (x , y) → Σ[ p ∶ Σ A B ] C p
f (x , y , z) = (x , y) , z
g : Σ[ p ∶ Σ A B ] C p → Σ[ x ∶ A ] Σ[ y ∶ B x ] C (x , y)
g ((x , y) , z) = x , y , z
η : g ∘ f ~ id
η (_ , _ , _) = refl
ε : f ∘ g ~ id
ε ((_ , _) , _) = refl
import HoTT.Exercises.Chapter2.Exercise11
import HoTT.Exercises.Chapter2.Exercise12
module Exercise13
where
open import HoTT.Equivalence
open import HoTT.Equivalence.Proposition
open import HoTT.Identity.Pi
open import HoTT.Identity.Sigma
not : 𝟐 → 𝟐
not = 𝟐-rec 1₂ 0₂
-- There are two possibilities for 𝟐 ≃ 𝟐, id and not. In our
-- equivalence (𝟐 ≃ 𝟐) ≃ 𝟐, we associate `id` with 0₂, and `not`
-- with 1₂. For some f : 𝟐 ≃ 𝟐, we have f 0₂ = 0₂ when f is id,
-- and f 0₂ = 1₂ when f is not, so we can use f 0₂ in the forward
-- direction.
_ : (𝟐 ≃ 𝟐) ≃ 𝟐
_ = to , qinv→isequiv (from , β , α)
where
to : 𝟐 ≃ 𝟐 → 𝟐
to (f , _) = f 0₂
from : 𝟐 → 𝟐 ≃ 𝟐
from 0₂ = id , qinv→isequiv (id , (λ _ → refl) , λ _ → refl)
from 1₂ = not , qinv→isequiv (not , 𝟐-ind _ refl refl , 𝟐-ind _ refl refl)
-- The first homotopy is easy, we just do 𝟐-induction on the
-- input to determine whether we have `id` or `not`. Once we
-- know that, it is just a matter of showing 0₂ = 0₂ or 1₂ = 1₂,
-- both of which are true by reflection.
α : to ∘ from ~ id
α = 𝟐-ind _ refl refl
-- The second homotopy is much trickier since we have to show
-- that these two complex structures are the same. The approach
-- we use is to induct on the four possibilities for f 0₂ and
-- f 1₂ (0₂ 0₂, 0₂ 1₂, 1₂ 0₂, or 1₂ 1₂). In the induction goals,
-- we require proofs that the boolean we induct on is equal
-- to f 0₂ or f 1₂ respectively. These proofs can be used
-- directly for the case where f = id or f = not. The other two
-- cases are impossible unless 0₂ = 1₂, and we can use the
-- proofs together with the equivalence inverse function and
-- homotopy to show the desired behavior of f.
β : from ∘ to ~ id
β (f , e) =
pair⁼ (𝟐-ind (λ x → x == f 0₂ → pr₁ (from x) == f)
(λ p → 𝟐-ind (λ x → x == f 1₂ → id == f)
(λ q → funext (𝟐-ind _ p (η 1₂ ⁻¹ ∙ ap g (q ⁻¹ ∙ p) ∙ η 0₂ ∙ q)))
(λ q → funext (𝟐-ind _ p q))
(f 1₂) refl)
(λ p → 𝟐-ind (λ x → x == f 1₂ → not == f)
(λ q → funext (𝟐-ind _ p q))
(λ q → funext (𝟐-ind _ p (η 0₂ ⁻¹ ∙ ap g (p ⁻¹ ∙ q) ∙ η 1₂ ∙ q)))
(f 1₂) refl)
(f 0₂) refl , isequiv-prop _ _)
where open qinv (isequiv→qinv e)
module Exercise14 {i} {A : 𝒰 i} {x : A}
where
-- In chapter 1 exercise 14, we showed that we couldn't use path
-- induction to prove (x : A) → (p : x = x) → p = reflₓ since,
-- given q : x = y, q = reflₓ is not well-typed (reflₓ : x = x,
-- while q : x = y). However, using the equality reflection rule
-- we have x ≡ y, so we can say reflₓ : x = y. Therefore, we can
-- define
--
-- C : (x s : A) → x = y → 𝒰
-- C x y q :≡ q = reflₓ
--
-- c : (x : A) → C x x reflₓ
-- c x :≡ refl {reflₓ}
--
-- Using path induction we have ind₌ C c x x p : p = reflₓ. By
-- applying the equality reflection rule again, we arrive at the
-- desired definitional equality, p ≡ reflₓ.
module Exercise15 {i j} {A : 𝒰 i} {B : A → 𝒰 j} {x y : A} {p : x == y} {u : B x}
where
_ : transport _ p == transport id (ap B p)
_ = =-ind (λ _ _ p → transport _ p == transport id (ap B p)) (λ _ → refl) p
module Exercise16 {i} {j} {A : 𝒰 i} {B : A → 𝒰 j} (f g : Π A B) where
open import HoTT.Identity
open import HoTT.Identity.Sigma
open import HoTT.Identity.Pi using (funext)
open import HoTT.Equivalence
=Π-equiv : f == g ≃ f ~ g
=Π-equiv = happly , qinv→isequiv (funext' , η , ε)
where
-- Define funext' in such a way that funext (happly refl) ≡
-- funext (λ x. refl) can cancel.
funext' : {g : Π A B} → f ~ g → f == g
funext' α = funext α ∙ funext (λ _ → refl) ⁻¹
η : funext' ∘ happly ~ id
η refl = invᵣ
ε : happly ∘ funext' ~ id
ε α = transport P p (ap happly invᵣ)
where
P : Π[ x ∶ A ] Σ[ y ∶ B x ] f x == y → 𝒰 _
P h = let α = pr₂ ∘ h in happly (funext' α) == α
-- The trick here is to use funext to simultaneously show
-- that λ x. (f x , refl) = λ x. (g x , α x). Then, we can
-- transport a path made by canceling the funext with its
-- inverse to get the desired equality.
p : (λ x → f x , refl) == (λ x → g x , α x)
p = funext λ x → pair⁼ (α x , =-ind (λ _ _ p → transport _ p refl == p) (λ _ → refl) (α x))
module Exercise17 {i} where
open import HoTT.Equivalence
open import HoTT.Equivalence.Proposition
open import HoTT.Identity.Product
open import HoTT.Identity.Sigma
open import HoTT.Identity.Universe
open import HoTT.Identity.Pi
variable
A A' B B' : 𝒰 i
P : A → 𝒰 i
P' : A' → 𝒰 i
prop : (_◆_ : 𝒰 i → 𝒰 i → 𝒰 i) → A == A' → B == B' → (A ◆ B) ≃ (A' ◆ B')
prop {A} {A'} {B} {B'} (_◆_) p q =
transport (λ{ (A' , B') → A ◆ B ≃ A' ◆ B' })
(×-pair⁼ {x = A , B} {y = A' , B'} (p , q)) reflₑ
module _ (e₁ : A ≃ A') (e₂ : B ≃ B')
where
open Iso (eqv→iso e₁) renaming (f to f₁ ; g to g₁ ; η to η₁ ; ε to ε₁)
open Iso (eqv→iso e₂) renaming (f to f₂ ; g to g₂ ; η to η₂ ; ε to ε₂)
-- (i) Proof without using univalence
prop-×' : A × B ≃ A' × B'
prop-×' = let open Iso in iso→eqv λ where
.f (a , b) → f₁ a , f₂ b
.g (a' , b') → g₁ a' , g₂ b'
.η (a , b) → ×-pair⁼ (η₁ a , η₂ b)
.ε (a' , b') → ×-pair⁼ (ε₁ a' , ε₂ b')
-- (ii) Proof using univalence (for general operator)
prop-× = prop _×_ (ua e₁) (ua e₂)
-- (iii) Proof for non-dependent type formers (→, +)
prop-→ = prop (λ A B → A → B) (ua e₁) (ua e₂)
prop-+ = prop _+_ (ua e₁) (ua e₂)
-- Proof that (i) and (ii) are equal
propᵢ₌ᵢᵢ : (e₁ : A ≃ A') (e₂ : B ≃ B') → prop-×' e₁ e₂ == prop-× e₁ e₂
propᵢ₌ᵢᵢ e₁ e₂ = ap² prop-×' (=𝒰-β e₁ ⁻¹) (=𝒰-β e₂ ⁻¹) ∙ lemma
where
lemma : prop-×' (idtoeqv (ua e₁)) (idtoeqv (ua e₂)) == prop-× e₁ e₂
lemma rewrite ua e₁ rewrite ua e₂ =
pair⁼ (funext (λ{ (a , b) → refl }) , isequiv-prop _ _)
module _ (e₁ : A ≃ A') (e₂ : (x : A') → transport (λ A' → A' → 𝒰 i) (ua e₁) P x ≃ P' x)
where
prop-dep : (_◆_ : (A : 𝒰 i) → (A → 𝒰 i) → 𝒰 i) → (A ◆ P) ≃ (A' ◆ P')
prop-dep _◆_ = transport (λ{ (A' , P') → A ◆ P ≃ A' ◆ P' })
(pair⁼ {x = A , P} {y = A' , P'} (ua e₁ , funext (ua ∘ e₂))) reflₑ
-- (iii) Proof for dependent type formers (Σ, Π)
prop-Σ = prop-dep Σ
prop-Π = prop-dep Π
module Exercise18 {i} {A : 𝒰 i} {B : A → 𝒰 i} {f g : Π A B} {H : f ~ g}
{x y : A} {p : x == y}
where
-- We first induct on p, changing our goal to
--
-- ap (transport refl) (H x) ∙ apd g refl = apd f refl ∙ H y
--
-- This reduces to
--
-- ap id (H x) ∙ refl = refl ∙ H x
--
-- Now, we just need one final induction on H x, after which our goal
-- reduces to refl : refl = refl.
_ : ap (transport _ p) (H x) ∙ apd g p == apd f p ∙ H y
_ = =-ind' (λ y p → ap (transport _ p) (H x) ∙ apd g p == apd f p ∙ H y)
(=-ind' (λ _ Hₓ → ap id Hₓ ∙ refl == refl ∙ Hₓ) refl (H x)) p
| 34.434568
| 97
| 0.467661
|
031826651a3dab05451847119f7848589dd85a38
| 4,548
|
agda
|
Agda
|
Cubical/Codata/Conat/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Codata/Conat/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Codata/Conat/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{- Conatural number properties (Tesla Ice Zhang et al., Feb. 2019)
This file defines operations and properties on conatural numbers:
- Infinity (∞).
- Proof that ∞ + 1 is equivalent to ∞.
- Proof that conatural is an hSet.
- Bisimulation on conatural
- Proof that bisimulation is equivalent to equivalence (Coinductive Proof
Principle).
- Proof that this bisimulation is prop valued
The standard library also defines bisimulation on conaturals:
https://github.com/agda/agda-stdlib/blob/master/src/Codata/Conat/Bisimilarity.agda
-}
{-# OPTIONS --cubical --safe --guardedness #-}
module Cubical.Codata.Conat.Properties where
open import Cubical.Data.Unit
open import Cubical.Data.Sum
open import Cubical.Data.Empty
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
open import Cubical.Codata.Conat.Base
Unwrap-prev : Conat′ → Type₀
Unwrap-prev zero = Unit
Unwrap-prev (suc _) = Conat
unwrap-prev : (n : Conat′) -> Unwrap-prev n
unwrap-prev zero = _
unwrap-prev (suc x) = x
private -- tests
𝟘 = conat zero
𝟙 = succ 𝟘
𝟚 = succ 𝟙
succ𝟙≡𝟚 : succ 𝟙 ≡ 𝟚
succ𝟙≡𝟚 i = 𝟚
pred𝟚≡𝟙 : unwrap-prev (force 𝟚) ≡ 𝟙
pred𝟚≡𝟙 i = 𝟙
∞ : Conat
force ∞ = suc ∞
∞+1≡∞ : succ ∞ ≡ ∞
force (∞+1≡∞ _) = suc ∞
∞+2≡∞ : succ (succ ∞) ≡ ∞
∞+2≡∞ = (cong succ ∞+1≡∞) ∙ ∞+1≡∞
_+_ : Conat → Conat → Conat
_+′_ : Conat′ → Conat → Conat′
force (x + y) = force x +′ y
zero +′ y = force y
suc x +′ y = suc (x + y)
n+∞≡∞ : ∀ n → n + ∞ ≡ ∞
n+′∞≡∞′ : ∀ n → n +′ ∞ ≡ suc ∞
force (n+∞≡∞ n i) = n+′∞≡∞′ (force n) i
n+′∞≡∞′ zero = refl
n+′∞≡∞′ (suc n) = λ i → suc (n+∞≡∞ n i)
∞+∞≡∞ : ∞ + ∞ ≡ ∞
force (∞+∞≡∞ i) = suc (∞+∞≡∞ i)
conat-absurd : ∀ {y : Conat} {ℓ} {Whatever : Type ℓ} → zero ≡ suc y → Whatever
conat-absurd eq = ⊥-elim (transport (cong diag eq) tt)
where
diag : Conat′ → Type₀
diag zero = Unit
diag (suc _) = ⊥
module IsSet where
≡-stable : {x y : Conat} → Stable (x ≡ y)
≡′-stable : {x y : Conat′} → Stable (x ≡ y)
force (≡-stable ¬¬p i) = ≡′-stable (λ ¬p → ¬¬p (λ p → ¬p (cong force p))) i
≡′-stable {zero} {zero} ¬¬p′ = refl
≡′-stable {suc x} {suc y} ¬¬p′ =
cong′ suc (≡-stable λ ¬p → ¬¬p′ λ p → ¬p (cong pred′′ p))
≡′-stable {zero} {suc y} ¬¬p′ = ⊥-elim (¬¬p′ conat-absurd)
≡′-stable {suc x} {zero} ¬¬p′ = ⊥-elim (¬¬p′ λ p → conat-absurd (sym p))
isSetConat : isSet Conat
isSetConat _ _ = Stable≡→isSet (λ _ _ → ≡-stable) _ _
isSetConat′ : isSet Conat′
isSetConat′ m n p′ q′ = cong (cong force) (isSetConat (conat m) (conat n) p q)
where p = λ where i .force → p′ i
q = λ where i .force → q′ i
module Bisimulation where
open IsSet using (isSetConat)
record _≈_ (x y : Conat) : Type₀
data _≈′_ (x y : Conat′) : Type₀
_≈′′_ : Conat′ → Conat′ → Type₀
zero ≈′′ zero = Unit
suc x ≈′′ suc y = x ≈ y
-- So impossible proofs are preserved
x ≈′′ y = ⊥
record _≈_ x y where
coinductive
field prove : force x ≈′ force y
data _≈′_ x y where
con : x ≈′′ y → x ≈′ y
open _≈_ public
bisim : ∀ {x y} → x ≈ y → x ≡ y
bisim′ : ∀ {x y} → x ≈′ y → x ≡ y
bisim′ {zero} {zero} (con tt) = refl
bisim′ {zero} {suc x} (con ())
bisim′ {suc x} {zero} (con ())
bisim′ {suc x} {suc y} (con eq) i = suc (bisim eq i)
force (bisim eq i) = bisim′ (prove eq) i
misib : ∀ {x y} → x ≡ y → x ≈ y
misib′ : ∀ {x y} → x ≡ y → x ≈′ y
misib′ {zero} {zero} _ = con tt
misib′ {zero} {suc x} = conat-absurd
misib′ {suc x} {zero} p = conat-absurd (sym p)
-- misib′ {suc x} {suc y} p = con λ where .prove → misib′ (cong pred′ p)
misib′ {suc x} {suc y} p = con (misib (cong pred′′ p))
prove (misib x≡y) = misib′ (cong force x≡y)
iso″ : ∀ {x y} → (p : x ≈ y) → misib (bisim p) ≡ p
iso′ : ∀ {x y} → (p : x ≈′ y) → misib′ (bisim′ p) ≡ p
iso′ {zero} {zero} (con p) = refl
iso′ {zero} {suc x} (con ())
iso′ {suc x} {zero} (con ())
iso′ {suc x} {suc y} (con p) = cong con (iso″ p)
prove (iso″ p i) = iso′ (prove p) i
osi : ∀ {x y} → (p : x ≡ y) → bisim (misib p) ≡ p
osi p = isSetConat _ _ _ p
path≃bisim : ∀ {x y} → (x ≡ y) ≃ (x ≈ y)
path≃bisim = isoToEquiv (iso misib bisim iso″ osi)
path≡bisim : ∀ {x y} → (x ≡ y) ≡ (x ≈ y)
path≡bisim = ua path≃bisim
isProp≈ : ∀ {x y} → isProp (x ≈ y)
isProp≈ = subst isProp path≡bisim (isSetConat _ _)
| 26.44186
| 82
| 0.578276
|
2114942395d512788d0d8892a8f1d3f5df9315c9
| 11,698
|
agda
|
Agda
|
Cubical/Structures/Poset.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Poset.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Poset.agda
|
RobertHarper/cubical
|
d13941587a58895b65f714f1ccc9c1f5986b109c
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Poset where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Logic
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv renaming (_■ to _QED)
open import Cubical.Foundations.SIP
open import Cubical.Functions.FunExtEquiv
open import Cubical.Foundations.Function
open import Cubical.Core.Primitives
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.Sigma.Properties
open import Cubical.Structures.Axioms
-- We will adopt the convention of denoting the level of the carrier
-- set by ℓ₀ and the level of the relation result by ℓ₁.
private
variable
ℓ ℓ₀ ℓ₁ ℓ₀′ ℓ₁′ ℓ₀′′ ℓ₁′′ : Level
Order : (ℓ₁ : Level) → Type ℓ₀ → Type (ℓ-max ℓ₀ (ℓ-suc ℓ₁))
Order ℓ₁ A = A → A → hProp ℓ₁
isSetOrder : (ℓ₁ : Level) (A : Type ℓ₀) → isSet (Order ℓ₁ A)
isSetOrder ℓ₁ A = isSetΠ2 λ _ _ → isSetHProp
-- We first start by defining what it means a for a function to be
-- order-preserving. The name "monotonic" is reserved for partial orders.
isOrderPreserving : (M : TypeWithStr ℓ₀ (Order ℓ₁)) (N : TypeWithStr ℓ₀′ (Order ℓ₁′))
→ (fst M → fst N) → Type _
isOrderPreserving (A , _⊑₀_) (B , _⊑₁_) f =
(x y : A) → [ x ⊑₀ y ] → [ f x ⊑₁ f y ]
isPropIsOrderPreserving : (M : TypeWithStr ℓ₀ (Order ℓ₁))
(N : TypeWithStr ℓ₀′ (Order ℓ₁′))
→ (f : fst M → fst N)
→ isProp (isOrderPreserving M N f)
isPropIsOrderPreserving M (_ , _⊑₁_) f = isPropΠ3 λ x y p → snd (f x ⊑₁ f y)
-- We then define what it means for an equivalence to order-preserving which is
-- nothing but the property that both directions of the equivalence are
-- order-preserving.
isAnOrderPreservingEqv : (M : TypeWithStr ℓ₀ (Order ℓ₁))
(N : TypeWithStr ℓ₀′ (Order ℓ₁′))
→ fst M ≃ fst N → Type _
isAnOrderPreservingEqv M N e@(f , _) =
isOrderPreserving M N f × isOrderPreserving N M g
where
g = equivFun (invEquiv e)
orderUnivalentStr : SNS {ℓ} (Order ℓ₁) isAnOrderPreservingEqv
orderUnivalentStr {ℓ = ℓ} {ℓ₁ = ℓ₁} {X = X} _⊑₀_ _⊑₁_ =
f , record { equiv-proof = f-equiv }
where
f : isAnOrderPreservingEqv (X , _⊑₀_) (X , _⊑₁_) (idEquiv X) → _⊑₀_ ≡ _⊑₁_
f e@(φ , ψ) = funExt₂ λ x y → ⇔toPath (φ x y) (ψ x y)
g : _⊑₀_ ≡ _⊑₁_ → isAnOrderPreservingEqv (X , _⊑₀_) (X , _⊑₁_) (idEquiv X)
g p =
subst
(λ _⊑_ → isAnOrderPreservingEqv (X , _⊑₀_) (X , _⊑_) (idEquiv X))
p
((λ _ _ x⊑₁y → x⊑₁y) , λ _ _ x⊑₁y → x⊑₁y)
ret-f-g : retract f g
ret-f-g (φ , ψ) =
isPropΣ
(isPropIsOrderPreserving (X , _⊑₀_) (X , _⊑₁_) (idfun X))
(λ _ → isPropIsOrderPreserving (X , _⊑₁_) (X , _⊑₀_) (idfun X))
(g (f (φ , ψ))) (φ , ψ)
f-equiv : (p : _⊑₀_ ≡ _⊑₁_) → isContr (fiber f p)
f-equiv p = ((to , from) , eq) , NTS
where
to : isOrderPreserving (X , _⊑₀_) (X , _⊑₁_) (idfun _)
to x y = subst (λ _⊑_ → [ x ⊑₀ y ] → [ x ⊑ y ]) p (idfun _)
from : isOrderPreserving (X , _⊑₁_) (X , _⊑₀_) (idfun _)
from x y = subst (λ _⊑_ → [ x ⊑ y ] → [ x ⊑₀ y ]) p (idfun _)
eq : f (to , from) ≡ p
eq = isSetOrder ℓ₁ X _⊑₀_ _⊑₁_ (f (to , from)) p
NTS : (fib : fiber f p) → ((to , from) , eq) ≡ fib
NTS ((φ , ψ) , eq) =
Σ≡Prop
(λ i′ → isOfHLevelSuc 2 (isSetOrder ℓ₁ X) _⊑₀_ _⊑₁_ (f i′) p)
(Σ≡Prop
(λ _ → isPropIsOrderPreserving (X , _⊑₁_) (X , _⊑₀_) (idfun _))
(isPropIsOrderPreserving (X , _⊑₀_) (X , _⊑₁_) (idfun _) to φ))
-- We now write down the axioms for a partial order and define posets on top of
-- raw ordered structures.
isReflexive : {A : Type ℓ₀} → Order ℓ₁ A → hProp (ℓ-max ℓ₀ ℓ₁)
isReflexive {A = X} _⊑_ = ((x : X) → [ x ⊑ x ]) , isPropΠ λ x → snd (x ⊑ x)
isTransitive : {A : Type ℓ₀} → Order ℓ₁ A → hProp (ℓ-max ℓ₀ ℓ₁)
isTransitive {ℓ₀ = ℓ₀} {ℓ₁ = ℓ₁} {A = X} _⊑_ = φ , φ-prop
where
φ : Type (ℓ-max ℓ₀ ℓ₁)
φ = ((x y z : X) → [ x ⊑ y ⇒ y ⊑ z ⇒ x ⊑ z ])
φ-prop : isProp φ
φ-prop = isPropΠ3 λ x y z → snd (x ⊑ y ⇒ y ⊑ z ⇒ x ⊑ z)
isAntisym : {A : Type ℓ₀} → isSet A → Order ℓ₁ A → hProp (ℓ-max ℓ₀ ℓ₁)
isAntisym {ℓ₀ = ℓ₀} {ℓ₁ = ℓ₁} {A = X} A-set _⊑_ = φ , φ-prop
where
φ : Type (ℓ-max ℓ₀ ℓ₁)
φ = ((x y : X) → [ x ⊑ y ] → [ y ⊑ x ] → x ≡ y)
φ-prop : isProp φ
φ-prop = isPropΠ3 λ x y z → isPropΠ λ _ → A-set x y
-- The predicate expressing that a given order satisfies the partial order
-- axioms.
satPosetAx : (ℓ₁ : Level) (A : Type ℓ₀) → Order ℓ₁ A → hProp (ℓ-max ℓ₀ ℓ₁)
satPosetAx {ℓ₀ = ℓ₀} ℓ₁ A _⊑_ = φ , φ-prop
where
isPartial : isSet A → hProp (ℓ-max ℓ₀ ℓ₁)
isPartial A-set = isReflexive _⊑_ ⊓ isTransitive _⊑_ ⊓ isAntisym A-set _⊑_
φ = Σ[ A-set ∈ isSet A ] [ isPartial A-set ]
φ-prop = isOfHLevelΣ 1 isPropIsSet (λ x → snd (isPartial x))
-- The poset structure.
PosetStructure : (ℓ₁ : Level) → Type ℓ₀ → Type (ℓ-max ℓ₀ (ℓ-suc ℓ₁))
PosetStructure ℓ₁ = AxiomsStructure (Order ℓ₁) λ A _⊑_ → [ satPosetAx ℓ₁ A _⊑_ ]
isSetPosetStructure : (ℓ₁ : Level) (A : Type ℓ₀) → isSet (PosetStructure ℓ₁ A)
isSetPosetStructure ℓ₁ A =
isSetΣ
(isSetΠ2 λ _ _ → isSetHProp) λ _⊑_ →
isProp→isSet (snd (satPosetAx ℓ₁ A _⊑_))
Poset : (ℓ₀ ℓ₁ : Level) → Type (ℓ-max (ℓ-suc ℓ₀) (ℓ-suc ℓ₁))
Poset ℓ₀ ℓ₁ = TypeWithStr ℓ₀ (PosetStructure ℓ₁)
-- Some projections for syntactic convenience.
-- Carrier set of a poset.
∣_∣ₚ : Poset ℓ₀ ℓ₁ → Type ℓ₀
∣ X , _ ∣ₚ = X
strₚ : (P : Poset ℓ₀ ℓ₁) → PosetStructure ℓ₁ ∣ P ∣ₚ
strₚ (_ , s) = s
rel : (P : Poset ℓ₀ ℓ₁) → ∣ P ∣ₚ → ∣ P ∣ₚ → hProp ℓ₁
rel (_ , _⊑_ , _) = _⊑_
syntax rel P x y = x ⊑[ P ] y
⊑[_]-refl : (P : Poset ℓ₀ ℓ₁) → (x : ∣ P ∣ₚ) → [ x ⊑[ P ] x ]
⊑[_]-refl (_ , _ , _ , ⊑-refl , _) = ⊑-refl
⊑[_]-trans : (P : Poset ℓ₀ ℓ₁) (x y z : ∣ P ∣ₚ)
→ [ x ⊑[ P ] y ] → [ y ⊑[ P ] z ] → [ x ⊑[ P ] z ]
⊑[_]-trans (_ , _ , _ , _ , ⊑-trans , _) = ⊑-trans
⊑[_]-antisym : (P : Poset ℓ₀ ℓ₁) (x y : ∣ P ∣ₚ)
→ [ x ⊑[ P ] y ] → [ y ⊑[ P ] x ] → x ≡ y
⊑[_]-antisym (_ , _ , _ , _ , _ , ⊑-antisym) = ⊑-antisym
carrier-is-set : (P : Poset ℓ₀ ℓ₁) → isSet ∣ P ∣ₚ
carrier-is-set (_ , _ , is-set , _) = is-set
-- Definition of a monotonic map amounts to forgetting the partial order axioms.
isMonotonic : (P : Poset ℓ₀ ℓ₁) (Q : Poset ℓ₀′ ℓ₁′) → (∣ P ∣ₚ → ∣ Q ∣ₚ) → Type _
isMonotonic (A , (_⊑₀_ , _)) (B , (_⊑₁_ , _)) =
isOrderPreserving (A , _⊑₀_) (B , _⊑₁_)
isPropIsMonotonic : (P : Poset ℓ₀ ℓ₁) (Q : Poset ℓ₀′ ℓ₁′)
→ (f : ∣ P ∣ₚ → ∣ Q ∣ₚ)
→ isProp (isMonotonic P Q f)
isPropIsMonotonic (A , (_⊑₀_ , _)) (B , (_⊑₁_ , _)) f =
isPropIsOrderPreserving (A , _⊑₀_) (B , _⊑₁_) f
-- We collect the type of monotonic maps between two posets in the following
-- type.
_─m→_ : Poset ℓ₀ ℓ₁ → Poset ℓ₀′ ℓ₁′ → Type _
_─m→_ P Q = Σ[ f ∈ (∣ P ∣ₚ → ∣ Q ∣ₚ) ] (isMonotonic P Q f)
-- The identity monotonic map and composition of monotonic maps.
𝟏m : (P : Poset ℓ₀ ℓ₁) → P ─m→ P
𝟏m P = idfun ∣ P ∣ₚ , (λ x y x⊑y → x⊑y)
_∘m_ : {P : Poset ℓ₀ ℓ₁} {Q : Poset ℓ₀′ ℓ₁′} {R : Poset ℓ₀′′ ℓ₁′′}
→ (Q ─m→ R) → (P ─m→ Q) → (P ─m→ R)
(g , pg) ∘m (f , pf) = g ∘ f , λ x y p → pg (f x) (f y) (pf x y p)
forget-mono : (P : Poset ℓ₀ ℓ₁) (Q : Poset ℓ₀′ ℓ₁′)
((f , f-mono) (g , g-mono) : P ─m→ Q)
→ f ≡ g
→ (f , f-mono) ≡ (g , g-mono)
forget-mono P Q (f , f-mono) (g , g-mono) =
Σ≡Prop (λ f → isPropΠ3 λ x y x⊑y → snd (f x ⊑[ Q ] f y))
module PosetReasoning (P : Poset ℓ₀ ℓ₁) where
_⊑⟨_⟩_ : (x : ∣ P ∣ₚ) {y z : ∣ P ∣ₚ}
→ [ x ⊑[ P ] y ] → [ y ⊑[ P ] z ] → [ x ⊑[ P ] z ]
_ ⊑⟨ p ⟩ q = ⊑[ P ]-trans _ _ _ p q
_■ : (x : ∣ P ∣ₚ) → [ x ⊑[ P ] x ]
_■ = ⊑[ P ]-refl
infixr 0 _⊑⟨_⟩_
infix 1 _■
-- Univalence for posets.
isAMonotonicEqv : (P : Poset ℓ₀ ℓ₁) (Q : Poset ℓ₀′ ℓ₁′)
→ ∣ P ∣ₚ ≃ ∣ Q ∣ₚ → Type _
isAMonotonicEqv (A , (_⊑₀_ , _)) (B , (_⊑₁_ , _)) =
isAnOrderPreservingEqv (A , _⊑₀_) (B , _⊑₁_)
isPropIsAMonotonicEqv : (P : Poset ℓ₀ ℓ₁) (Q : Poset ℓ₀ ℓ₁′)
→ (eqv : ∣ P ∣ₚ ≃ ∣ Q ∣ₚ)
→ isProp (isAMonotonicEqv P Q eqv)
isPropIsAMonotonicEqv P Q e@(f , _) =
isPropΣ (isPropIsMonotonic P Q f) λ _ → isPropIsMonotonic Q P g
where
g = equivFun (invEquiv e)
-- We denote by `_≃ₚ_` the type of monotonic poset equivalences.
_≃ₚ_ : Poset ℓ₀ ℓ₁ → Poset ℓ₀ ℓ₁ → Type _
_≃ₚ_ P Q = Σ[ i ∈ ∣ P ∣ₚ ≃ ∣ Q ∣ₚ ] isAMonotonicEqv P Q i
-- From this, we can already establish that posets form an SNS and prove that
-- the category of posets is univalent.
posetUnivalentStr : SNS {ℓ} (PosetStructure ℓ₁) isAMonotonicEqv
posetUnivalentStr {ℓ₁ = ℓ₁} =
UnivalentStr→SNS
(PosetStructure ℓ₁)
isAMonotonicEqv
(axiomsUnivalentStr _ NTS (SNS→UnivalentStr isAnOrderPreservingEqv orderUnivalentStr))
where
NTS : (A : Type ℓ) (_⊑_ : Order ℓ₁ A) → isProp [ satPosetAx ℓ₁ A _⊑_ ]
NTS A _⊑_ = snd (satPosetAx ℓ₁ A _⊑_)
poset-univ₀ : (P Q : Poset ℓ₀ ℓ₁) → (P ≃ₚ Q) ≃ (P ≡ Q)
poset-univ₀ = SIP (SNS→UnivalentStr isAMonotonicEqv posetUnivalentStr)
-- This result is almost what we want but it is better talk directly about poset
-- _isomorphisms_ rather than equivalences. In the case when types `A` and `B`
-- are sets, the type of isomorphisms between `A` and `B` is equivalent to the
-- type of equivalences betwee them.
-- Let us start by writing down what a poset isomorphisms is.
isPosetIso : (P Q : Poset ℓ₀ ℓ₁) → (P ─m→ Q) → Type _
isPosetIso P Q (f , _) = Σ[ (g , _) ∈ (Q ─m→ P) ] section f g × retract f g
isPosetIso-prop : (P Q : Poset ℓ₀ ℓ₁) (f : P ─m→ Q)
→ isProp (isPosetIso P Q f)
isPosetIso-prop P Q (f , f-mono) (g₀ , sec₀ , ret₀) (g₁ , sec₁ , ret₁) =
Σ≡Prop NTS g₀=g₁
where
NTS : ((g , _) : Q ─m→ P) → isProp (section f g × retract f g)
NTS (g , g-mono) = isPropΣ
(isPropΠ λ x → carrier-is-set Q (f (g x)) x) λ _ →
isPropΠ λ x → carrier-is-set P (g (f x)) x
g₀=g₁ : g₀ ≡ g₁
g₀=g₁ =
forget-mono Q P g₀ g₁ (funExt λ x →
fst g₀ x ≡⟨ sym (cong (λ - → fst g₀ -) (sec₁ x)) ⟩
fst g₀ (f (fst g₁ x)) ≡⟨ ret₀ (fst g₁ x) ⟩
fst g₁ x ∎)
-- We will denote by `P ≅ₚ Q` the type of isomorphisms between posets `P` and
-- `Q`.
_≅ₚ_ : Poset ℓ₀ ℓ₁ → Poset ℓ₀ ℓ₁ → Type _
P ≅ₚ Q = Σ[ f ∈ P ─m→ Q ] isPosetIso P Q f
-- ≅ₚ is equivalent to ≃ₚ.
≃ₚ≃≅ₚ : (P Q : Poset ℓ₀ ℓ₁) → (P ≅ₚ Q) ≃ (P ≃ₚ Q)
≃ₚ≃≅ₚ P Q = isoToEquiv (iso from to ret sec)
where
to : P ≃ₚ Q → P ≅ₚ Q
to (e@(f , _) , (f-mono , g-mono)) =
(f , f-mono) , (g , g-mono) , sec-f-g , ret-f-g
where
is = equivToIso e
g = equivFun (invEquiv e)
sec-f-g : section f g
sec-f-g = Iso.rightInv (equivToIso e)
ret-f-g : retract f g
ret-f-g = Iso.leftInv (equivToIso e)
from : P ≅ₚ Q → P ≃ₚ Q
from ((f , f-mono) , ((g , g-mono) , sec , ret)) =
isoToEquiv is , f-mono , g-mono
where
is : Iso ∣ P ∣ₚ ∣ Q ∣ₚ
is = iso f g sec ret
sec : section to from
sec (f , _) = Σ≡Prop (isPosetIso-prop P Q) refl
ret : retract to from
ret (e , _) = Σ≡Prop (isPropIsAMonotonicEqv P Q) (Σ≡Prop isPropIsEquiv refl)
-- Once we have this equivalence, the main result is then: the type of poset
-- isomorphisms between `P` and `Q` is equivalent to the type of identity proofs
-- between `P` and `Q`
poset-univ : (P Q : Poset ℓ₀ ℓ₁) → (P ≅ₚ Q) ≃ (P ≡ Q)
poset-univ P Q = P ≅ₚ Q ≃⟨ ≃ₚ≃≅ₚ P Q ⟩ P ≃ₚ Q ≃⟨ poset-univ₀ P Q ⟩ P ≡ Q QED
| 36.329193
| 90
| 0.55642
|
3401ef5d5334a83bd2f34862e3383abe1a2ebdbc
| 6,605
|
agda
|
Agda
|
src/Ambient.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | 2
|
2021-03-12T18:31:14.000Z
|
2021-05-04T09:35:36.000Z
|
src/Ambient.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | null | null | null |
src/Ambient.agda
|
d-plaindoux/colca
|
a81447af3ab2ba898bb7d57be71369abbba12d81
|
[
"MIT"
] | null | null | null |
module Ambient where
open import Relation.Nullary
using (yes; no)
open import Data.String
using (String; _≟_)
open import Data.Bool
using (Bool; true; false)
open import Relation.Binary.PropositionalEquality
using (_≢_; refl)
renaming (_≡_ to _≡≡_)
open import Data.List
using (List; []; _∷_; _++_; filter)
-- Local modules ---------------------------------------------------------------
open import Common
using (Id)
open import Capability
using (Capability; `_; In; Out; Open; ε; _∙_)
renaming (_[_/_] to _[_/_]-capa; freeVar to freeVar-capa)
-- Process Definition ----------------------------------------------------------
infix 40 _[_/_]
infixr 30 Λ_∙_
infix 20 _[_]
infixr 10 _||_
data Process : Set where
ν_∙_ : Id → Process → Process -- Restriction
Zero : Process -- Inactivity
_||_ : Process → Process → Process -- Composition
!_ : Process → Process -- Replication
_[_] : Capability → Process → Process -- Ambient
_∙_ : Capability → Process → Process -- Action
Λ_∙_ : Id → Process → Process -- Input Action
<_> : Capability → Process -- Message
-- Free variable ---------------------------------------------------------------
_-_ : List Id → Id → List Id
[] - _ = []
(x ∷ xs) - y with x ≟ y
... | yes _ = xs - y
... | no _ = x ∷ (xs - y)
freeVar : Process → List Id
freeVar (ν x ∙ P) = freeVar P
freeVar Zero = []
freeVar (P || Q) = (freeVar P) ++ (freeVar Q)
freeVar (! P) = freeVar P
freeVar (M [ P ]) = (freeVar-capa M) ++ (freeVar P)
freeVar (M ∙ P) = (freeVar-capa M) ++ (freeVar P)
freeVar (Λ x ∙ P) = (freeVar P) - x
freeVar (< M >) = freeVar-capa M
_∉_ : Id → List Id → Set
y ∉ l = member y l ≡≡ false
where member : Id → List Id → Bool -- Should propably use the List filter instead!
member y [] = false
member y (x ∷ xs) with x ≟ y
... | yes _ = true
... | no _ = member y xs
-- Process substitution --------------------------------------------------------
_[_/_] : Process → Id → Capability → Process
Zero [ _ / _ ] = Zero
(P || Q) [ x / M ] = P [ x / M ] || Q [ x / M ]
(! P) [ x / M ] = ! (P [ x / M ])
(x [ P ]) [ y / M ] = (x [ y / M ]-capa) [ P [ y / M ] ]
(ν x ∙ P) [ y / M ] with x ≟ y
... | yes _ = ν x ∙ P
... | no _ = ν x ∙ (P [ y / M ])
< N > [ x / M ] = < N [ x / M ]-capa >
(Λ x ∙ P) [ y / M ] with x ≟ y
... | yes _ = Λ x ∙ P
... | no _ = Λ x ∙ (P [ y / M ])
( N ∙ P) [ x / M ] = (N [ x / M ]-capa) ∙ (P [ x / M ])
module Test where
a = "a"
b = "b"
------------------------------------------------------------------------------
_ : (` a [ < ` b > ]) [ b / Open a ] ≡≡ ` a [ < Open a > ]
_ = refl
_ : (< ` a > || < ` b >) [ b / Open a ] ≡≡ < ` a > || < Open a >
_ = refl
-- Congruence ------------------------------------------------------------------
infix 5 _≡_
data _≡_ : Process → Process → Set where
Struct-Refl : ∀ {P}
-----
→ P ≡ P
Struct-Symm : ∀ {P Q}
→ P ≡ Q
-----
→ Q ≡ P
Struct-Trans : ∀ {P Q R}
→ P ≡ Q → Q ≡ R
-------------
→ P ≡ R
Struct-Res : ∀ {n P Q}
→ P ≡ Q
-----------------
→ ν n ∙ P ≡ ν n ∙ Q
Struct-Par : ∀ {P Q R}
→ P ≡ Q
---------------
→ P || R ≡ Q || R
Struct-Repl : ∀ {P Q}
→ P ≡ Q
---------
→ ! P ≡ ! Q
Struct-Amb : ∀ {M P Q}
→ P ≡ Q
-----------------
→ M [ P ] ≡ M [ Q ]
Struct-Action : ∀ {M P Q}
→ P ≡ Q
-------------
→ M ∙ P ≡ M ∙ Q
Struct-Input : ∀ {x P Q}
→ P ≡ Q
---------------------
→ Λ x ∙ P ≡ Λ x ∙ Q
Struct-Comm : ∀ {P Q}
→ P ≡ Q
-----
→ Q ≡ P
Struct-Assoc : ∀ {P Q R}
-----------------------------
→ (P || Q) || R ≡ P || (Q || R)
Struct-ResRes : ∀ {n m P}
→ n ≢ m
-----------------------------
→ ν n ∙ ν m ∙ P ≡ ν m ∙ ν n ∙ P
Struct-ResPar : ∀ {n P Q}
→ n ∉ freeVar(P)
-----------------------------
→ ν n ∙ (P || Q) ≡ P || ν n ∙ Q
Struct-ResAmb : ∀ {n m P}
→ n ≢ m
-----------------------------------
→ ν n ∙ (` m [ P ]) ≡ ` m [ ν n ∙ P ]
Struct-ZeroPar : ∀ {P}
-------------
→ P || Zero ≡ P
Struct-ZeroRes : ∀ {n}
-----------------
→ ν n ∙ Zero ≡ Zero
Struct-ZeroRep : ! Zero ≡ Zero
Struct-ε : ---------------
ε ∙ Zero ≡ Zero
Struct-∙ : ∀ {M M' P}
---------------------------
→ (M ∙ M') ∙ P ≡ M ∙ (M' ∙ P)
-- Reduction rules -------------------------------------------------------------
infix 5 _~>_
data _~>_ : Process → Process → Set where
Red-In : ∀ {m n P Q R}
-----------------------------------------------------------------
→ ` m [ In n ∙ P || Q ] || ` n [ R ] ~> ` n [ ` m [ P || Q ] || R ]
Red-Out : ∀ {m n P Q R}
------------------------------------------------------------------
→ ` m [ ` n [ Out m ∙ P || R ] || Q ] ~> ` m [ Q ] || ` n [ P || R ]
Red-Open : ∀ {m P Q}
---------------------------------
→ ` m [ P ] || Open m ∙ Q ~> P || Q
Red-I/O : ∀ {M x P}
---------------------------------
→ < M > || Λ x ∙ P ~> P [ x / M ]
Red-Par : ∀ {P Q R}
→ P ~> Q
------------------
→ P || R ~> Q || R
Red-Res : ∀ {n P Q}
→ P ~> Q
--------------------
→ ν n ∙ P ~> ν n ∙ Q
Red-Amb : ∀ {M P Q}
→ P ~> Q
--------------------
→ M [ P ] ~> M [ Q ]
Red-≡ : ∀ {P P' Q Q'}
→ P' ≡ P → P ~> Q → Q ≡ Q'
-------------------------
→ P' ~> Q'
--------------------------------------------------------------------------------
| 28.469828
| 87
| 0.284481
|
c7f95b8d6369cf7773decba0c5528f399ffbe2c2
| 1,129
|
agda
|
Agda
|
archive/agda-3/src/Test/SurjidentityI.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Test/SurjidentityI.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Test/SurjidentityI.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Everything
module Test.SurjidentityI where
module _
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔯₁} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
{𝔯₂} (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼₂2_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
{𝔯₂'} (_∼₂'_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂')
{ℓ₂} (_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(_∼̇₂'_ : ∀ {x y} → x ∼₂' y → x ∼₂' y → Ø ℓ₂)
(_∼̇₂2_ : ∀ {x y} → x ∼₂2 y → x ∼₂2 y → Ø ℓ₂)
where
postulate
instance `𝓢urjection : Surjection.class 𝔒₁ 𝔒₂
instance `𝓢urjectivity : Smap!.class _∼₁_ _∼₂_
instance `𝓢urjectextensivity : Smap!.class _∼₁_ _∼₂'_
instance `𝓢urjectivity2 : Smap!.class _∼₁_ _∼₂2_
instance `𝓡eflexivity₁ : Reflexivity.class _∼₁_
instance `𝓡eflexivity₂ : Reflexivity.class _∼₂_
instance `𝓡eflexivity₂' : Reflexivity.class _∼₂'_
instance `𝓡eflexivity₂2 : Reflexivity.class _∼₂2_
instance `𝒮urjidentity : Surjidentity!.class _∼₁_ _∼₂_ _∼̇₂_
instance `𝒮urjidentity' : Surjidentity!.class _∼₁_ _∼₂'_ _∼̇₂'_
instance `𝒮urjidentity2 : Surjidentity!.class _∼₁_ _∼₂2_ _∼̇₂2_
test-surj : Surjidentity!.type _∼₁_ _∼₂_ _∼̇₂_
test-surj = surjidentity
| 35.28125
| 67
| 0.601417
|
417646a62200e62f40fbd3c72ff634435e46395a
| 4,312
|
agda
|
Agda
|
Cubical/Categories/Category/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Categories/Category/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Category/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Category.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Powerset
private
variable
ℓ ℓ' : Level
-- Categories with hom-sets
record Category ℓ ℓ' : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
-- no-eta-equality ; NOTE: need eta equality for `opop`
field
ob : Type ℓ
Hom[_,_] : ob → ob → Type ℓ'
id : ∀ {x} → Hom[ x , x ]
_⋆_ : ∀ {x y z} (f : Hom[ x , y ]) (g : Hom[ y , z ]) → Hom[ x , z ]
⋆IdL : ∀ {x y} (f : Hom[ x , y ]) → id ⋆ f ≡ f
⋆IdR : ∀ {x y} (f : Hom[ x , y ]) → f ⋆ id ≡ f
⋆Assoc : ∀ {x y z w} (f : Hom[ x , y ]) (g : Hom[ y , z ]) (h : Hom[ z , w ])
→ (f ⋆ g) ⋆ h ≡ f ⋆ (g ⋆ h)
isSetHom : ∀ {x y} → isSet Hom[ x , y ]
-- composition: alternative to diagramatic order
_∘_ : ∀ {x y z} (g : Hom[ y , z ]) (f : Hom[ x , y ]) → Hom[ x , z ]
g ∘ f = f ⋆ g
infixr 9 _⋆_
infixr 9 _∘_
open Category
-- Helpful syntax/notation
_[_,_] : (C : Category ℓ ℓ') → (x y : C .ob) → Type ℓ'
_[_,_] = Hom[_,_]
-- Needed to define this in order to be able to make the subsequence syntax declaration
seq' : ∀ (C : Category ℓ ℓ') {x y z} (f : C [ x , y ]) (g : C [ y , z ]) → C [ x , z ]
seq' = _⋆_
infixl 15 seq'
syntax seq' C f g = f ⋆⟨ C ⟩ g
-- composition
comp' : ∀ (C : Category ℓ ℓ') {x y z} (g : C [ y , z ]) (f : C [ x , y ]) → C [ x , z ]
comp' = _∘_
infixr 16 comp'
syntax comp' C g f = g ∘⟨ C ⟩ f
-- Isomorphisms and paths in categories
record CatIso (C : Category ℓ ℓ') (x y : C .ob) : Type ℓ' where
constructor catiso
field
mor : C [ x , y ]
inv : C [ y , x ]
sec : inv ⋆⟨ C ⟩ mor ≡ C .id
ret : mor ⋆⟨ C ⟩ inv ≡ C .id
idCatIso : {C : Category ℓ ℓ'} {x : C .ob} → CatIso C x x
idCatIso {C = C} = (catiso (C .id) (C .id) (C .⋆IdL (C .id)) (C .⋆IdL (C .id)))
isSet-CatIso : {C : Category ℓ ℓ'} → ∀ x y → isSet (CatIso C x y)
isSet-CatIso {C = C} x y F G p q = w
where
w : _
CatIso.mor (w i j) = isSetHom C _ _ (cong CatIso.mor p) (cong CatIso.mor q) i j
CatIso.inv (w i j) = isSetHom C _ _ (cong CatIso.inv p) (cong CatIso.inv q) i j
CatIso.sec (w i j) =
isSet→SquareP
(λ i j → isProp→isSet {A = CatIso.inv (w i j) ⋆⟨ C ⟩ CatIso.mor (w i j) ≡ C .id} (isSetHom C _ _))
(cong CatIso.sec p) (cong CatIso.sec q) (λ _ → CatIso.sec F) (λ _ → CatIso.sec G) i j
CatIso.ret (w i j) =
isSet→SquareP
(λ i j → isProp→isSet {A = CatIso.mor (w i j) ⋆⟨ C ⟩ CatIso.inv (w i j) ≡ C .id} (isSetHom C _ _))
(cong CatIso.ret p) (cong CatIso.ret q) (λ _ → CatIso.ret F) (λ _ → CatIso.ret G) i j
pathToIso : {C : Category ℓ ℓ'} {x y : C .ob} (p : x ≡ y) → CatIso C x y
pathToIso {C = C} p = J (λ z _ → CatIso _ _ z) idCatIso p
pathToIso-refl : {C : Category ℓ ℓ'} {x : C .ob} → pathToIso {C = C} {x} refl ≡ idCatIso
pathToIso-refl {C = C} {x} = JRefl (λ z _ → CatIso C x z) (idCatIso)
-- Univalent Categories
record isUnivalent (C : Category ℓ ℓ') : Type (ℓ-max ℓ ℓ') where
field
univ : (x y : C .ob) → isEquiv (pathToIso {C = C} {x = x} {y = y})
-- package up the univalence equivalence
univEquiv : ∀ (x y : C .ob) → (x ≡ y) ≃ (CatIso _ x y)
univEquiv x y = pathToIso , univ x y
-- The function extracting paths from category-theoretic isomorphisms.
CatIsoToPath : {x y : C .ob} (p : CatIso _ x y) → x ≡ y
CatIsoToPath {x = x} {y = y} p =
equivFun (invEquiv (univEquiv x y)) p
isGroupoid-ob : isGroupoid (C .ob)
isGroupoid-ob = isOfHLevelPath'⁻ 2 (λ _ _ → isOfHLevelRespectEquiv 2 (invEquiv (univEquiv _ _)) (isSet-CatIso _ _))
-- Opposite category
_^op : Category ℓ ℓ' → Category ℓ ℓ'
ob (C ^op) = ob C
Hom[_,_] (C ^op) x y = C [ y , x ]
id (C ^op) = id C
_⋆_ (C ^op) f g = g ⋆⟨ C ⟩ f
⋆IdL (C ^op) = C .⋆IdR
⋆IdR (C ^op) = C .⋆IdL
⋆Assoc (C ^op) f g h = sym (C .⋆Assoc _ _ _)
isSetHom (C ^op) = C .isSetHom
ΣPropCat : (C : Category ℓ ℓ') (P : ℙ (ob C)) → Category ℓ ℓ'
ob (ΣPropCat C P) = Σ[ x ∈ ob C ] x ∈ P
Hom[_,_] (ΣPropCat C P) x y = C [ fst x , fst y ]
id (ΣPropCat C P) = id C
_⋆_ (ΣPropCat C P) = _⋆_ C
⋆IdL (ΣPropCat C P) = ⋆IdL C
⋆IdR (ΣPropCat C P) = ⋆IdR C
⋆Assoc (ΣPropCat C P) = ⋆Assoc C
isSetHom (ΣPropCat C P) = isSetHom C
| 34.222222
| 117
| 0.545455
|
216f60bbd1a7101ed4cb8b2929bc018a37186d85
| 494
|
agda
|
Agda
|
test/Fail/Issue2429.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/Issue2429.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue2429.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2017-01-24, issue #2429
-- ..-annotation in lambdas should be taken seriously
-- A ≤ ..A ≤ .A
-- (.A → B) ≤ (..A → B) ≤ A → B
should-fail : ∀{A B : Set} → (.A → B) → (.A → B)
should-fail f = λ ..a → f a
-- Expected error:
-- Found a non-strict lambda where a irrelevant lambda was expected
-- when checking that the expression λ ..a → f a has type ..A → .B
-- Note: Since A and B are not in scope, they are printed as .A and .B
-- This makes this error message super confusing.
| 30.875
| 70
| 0.615385
|
43075093a52f23019d612733aca65ed8cde74ab5
| 12,051
|
agda
|
Agda
|
core/lib/types/Truncation.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Truncation.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Truncation.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.types.TLevel
open import lib.types.Pi
open import lib.types.Sigma
open import lib.NType2
module lib.types.Truncation where
module _ {i} where
postulate -- HIT
Trunc : (n : ℕ₋₂) (A : Type i) → Type i
[_] : {n : ℕ₋₂} {A : Type i} → A → Trunc n A
Trunc-level : {n : ℕ₋₂} {A : Type i} → has-level n (Trunc n A)
module TruncElim {n : ℕ₋₂} {A : Type i} {j} {P : Trunc n A → Type j}
(p : (x : Trunc n A) → has-level n (P x)) (d : (a : A) → P [ a ]) where
postulate -- HIT
f : Π (Trunc n A) P
[_]-β : ∀ a → f [ a ] ↦ d a
{-# REWRITE [_]-β #-}
open TruncElim public renaming (f to Trunc-elim)
module TruncRec {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (p : has-level n B)
(d : A → B) where
private
module M = TruncElim (λ x → p) d
f : Trunc n A → B
f = M.f
open TruncRec public renaming (f to Trunc-rec)
module TruncRecType {i j} {n : ℕ₋₂} {A : Type i} (d : A → n -Type j) where
open TruncRec (n -Type-level j) d public
flattening-Trunc : Σ (Trunc (S n) A) (fst ∘ f) ≃ Trunc (S n) (Σ A (fst ∘ d))
flattening-Trunc = equiv to from to-from from-to where
to-aux : (x : Trunc (S n) A) → (fst (f x) → Trunc (S n) (Σ A (fst ∘ d)))
to-aux = Trunc-elim (λ _ → →-level Trunc-level)
(λ a b → [ (a , b) ])
to : Σ (Trunc (S n) A) (fst ∘ f) → Trunc (S n) (Σ A (fst ∘ d))
to (x , y) = to-aux x y
from-aux : Σ A (fst ∘ d) → Σ (Trunc (S n) A) (fst ∘ f)
from-aux (a , b) = ([ a ] , b)
from : Trunc (S n) (Σ A (fst ∘ d)) → Σ (Trunc (S n) A) (fst ∘ f)
from = Trunc-rec (Σ-level Trunc-level (λ x → raise-level _ (snd (f x))))
from-aux
to-from : (x : Trunc (S n) (Σ A (fst ∘ d))) → to (from x) == x
to-from = Trunc-elim (λ _ → =-preserves-level Trunc-level)
(λ _ → idp)
from-to-aux : (a : Trunc (S n) A) (b : fst (f a)) → from (to-aux a b) == (a , b)
from-to-aux = Trunc-elim (λ _ → Π-level (λ _ → =-preserves-level (Σ-level Trunc-level (λ x → raise-level _ (snd (f x))))))
(λ a b → idp)
from-to : (x : Σ (Trunc (S n) A) (fst ∘ f)) → from (to x) == x
from-to (a , b) = from-to-aux a b
⊙Trunc : ∀ {i} → ℕ₋₂ → Ptd i → Ptd i
⊙Trunc n ⊙[ A , a ] = ⊙[ Trunc n A , [ a ] ]
module _ {i} {n : ℕ₋₂} {A : Type i} where
Trunc= : (a b : Trunc (S n) A) → n -Type i
Trunc= = Trunc-elim (λ _ → →-level (n -Type-level i))
(λ a → Trunc-elim (λ _ → n -Type-level i)
((λ b → (Trunc n (a == b) , Trunc-level))))
Trunc=-equiv : (a b : Trunc (S n) A) → (a == b) ≃ fst (Trunc= a b)
Trunc=-equiv a b = equiv (to a b) (from a b) (to-from a b) (from-to a b) where
to-aux : (a : Trunc (S n) A) → fst (Trunc= a a)
to-aux = Trunc-elim (λ x → raise-level _ (snd (Trunc= x x)))
(λ a → [ idp ])
to : (a b : Trunc (S n) A) → (a == b → fst (Trunc= a b))
to a .a idp = to-aux a
from-aux : (a b : A) → a == b → [ a ] == [ b ] :> Trunc (S n) A
from-aux a .a idp = idp
from : (a b : Trunc (S n) A) → (fst (Trunc= a b) → a == b)
from = Trunc-elim (λ _ → Π-level (λ _ → →-level (=-preserves-level Trunc-level)))
(λ a → Trunc-elim (λ _ → →-level (=-preserves-level Trunc-level))
(λ b → Trunc-rec (Trunc-level {n = S n} _ _)
(from-aux a b)))
to-from-aux : (a b : A) → (p : a == b) → to _ _ (from-aux a b p) == [ p ]
to-from-aux a .a idp = idp
to-from : (a b : Trunc (S n) A) (x : fst (Trunc= a b)) → to a b (from a b x) == x
to-from = Trunc-elim (λ x → Π-level (λ y → Π-level (λ _ → =-preserves-level (raise-level _ (snd (Trunc= x y))))))
(λ a → Trunc-elim (λ x → Π-level (λ _ → raise-level _ (=-preserves-level (snd (Trunc= [ a ] x)))))
(λ b → Trunc-elim (λ _ → =-preserves-level Trunc-level)
(to-from-aux a b)))
from-to-aux : (a : Trunc (S n) A) → from a a (to-aux a) == idp
from-to-aux = Trunc-elim (λ x → =-preserves-level (=-preserves-level Trunc-level)) (λ _ → idp)
from-to : (a b : Trunc (S n) A) (p : a == b) → from a b (to a b p) == p
from-to a .a idp = from-to-aux a
Trunc=-path : (a b : Trunc (S n) A) → (a == b) == fst (Trunc= a b)
Trunc=-path a b = ua (Trunc=-equiv a b)
{- Universal property -}
abstract
Trunc-rec-is-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)
(p : has-level n B) → is-equiv (Trunc-rec p :> ((A → B) → (Trunc n A → B)))
Trunc-rec-is-equiv n A B p = is-eq _ (λ f → f ∘ [_])
(λ f → λ= (Trunc-elim (λ _ → =-preserves-level p) (λ a → idp))) (λ f → idp)
Trunc-preserves-level : ∀ {i} {A : Type i} {n : ℕ₋₂} (m : ℕ₋₂)
→ has-level n A → has-level n (Trunc m A)
Trunc-preserves-level {n = ⟨-2⟩} _ (a₀ , p) =
([ a₀ ] , Trunc-elim (λ _ → =-preserves-level Trunc-level)
(λ a → ap [_] (p a)))
Trunc-preserves-level ⟨-2⟩ _ = contr-has-level Trunc-level
Trunc-preserves-level {n = (S n)} (S m) c = λ t₁ t₂ →
Trunc-elim
(λ s₁ → prop-has-level-S {A = has-level n (s₁ == t₂)} has-level-is-prop)
(λ a₁ → Trunc-elim
(λ s₂ → prop-has-level-S {A = has-level n ([ a₁ ] == s₂)} has-level-is-prop)
(λ a₂ → equiv-preserves-level
((Trunc=-equiv [ a₁ ] [ a₂ ])⁻¹)
(Trunc-preserves-level {n = n} m (c a₁ a₂)))
t₂)
t₁
{- an n-type is equivalent to its n-truncation -}
unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (A : Type i)
→ has-level n A → Trunc n A ≃ A
unTrunc-equiv A nA = equiv f [_] (λ _ → idp) g-f where
f = Trunc-rec nA (idf _)
g-f = Trunc-elim (λ _ → =-preserves-level Trunc-level) (λ _ → idp)
⊙unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (X : Ptd i)
→ has-level n (de⊙ X) → ⊙Trunc n X ⊙≃ X
⊙unTrunc-equiv {n = n} X nX = ≃-to-⊙≃ (unTrunc-equiv (de⊙ X) nX) idp
-- Equivalence associated to the universal property
Trunc-extend-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)
(p : has-level n B) → (A → B) ≃ (Trunc n A → B)
Trunc-extend-equiv n A B p = (Trunc-rec p , Trunc-rec-is-equiv n A B p)
Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → ((A → B) → (Trunc n A → Trunc n B))
Trunc-fmap f = Trunc-rec Trunc-level ([_] ∘ f)
Trunc-fmap2 : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}
→ ((A → B → C) → (Trunc n A → Trunc n B → Trunc n C))
Trunc-fmap2 f = Trunc-rec (Π-level (λ _ → Trunc-level)) (λ a → Trunc-fmap (f a))
-- XXX What is the naming convention?
Trunc-fpmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {f g : A → B} (h : (a : A) → f a == g a)
→ ((a : Trunc n A) → Trunc-fmap f a == Trunc-fmap g a)
Trunc-fpmap h = Trunc-elim (λ _ → =-preserves-level Trunc-level)
(ap [_] ∘ h)
Trunc-fmap-idf : ∀ {i} {n : ℕ₋₂} {A : Type i}
→ ∀ x → Trunc-fmap {n = n} (idf A) x == x
Trunc-fmap-idf =
Trunc-elim (λ _ → =-preserves-level Trunc-level) (λ _ → idp)
Trunc-fmap-∘ : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}
→ (g : B → C) → (f : A → B)
→ ∀ x → Trunc-fmap {n = n} g (Trunc-fmap f x) == Trunc-fmap (g ∘ f) x
Trunc-fmap-∘ g f =
Trunc-elim (λ _ → =-preserves-level Trunc-level) (λ _ → idp)
{- Pushing concatentation through Trunc= -}
module _ {i} {n : ℕ₋₂} {A : Type i} where
{- concatenation in Trunc= -}
Trunc=-∙ : {ta tb tc : Trunc (S n) A}
→ fst (Trunc= ta tb) → fst (Trunc= tb tc) → fst (Trunc= ta tc)
Trunc=-∙ {ta = ta} {tb = tb} {tc = tc} =
Trunc-elim {P = λ ta → C ta tb tc}
(λ ta → level ta tb tc)
(λ a → Trunc-elim {P = λ tb → C [ a ] tb tc}
(λ tb → level [ a ] tb tc)
(λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc}
(λ tc → level [ a ] [ b ] tc)
(λ c → Trunc-fmap2 _∙_)
tc)
tb)
ta
where
C : (ta tb tc : Trunc (S n) A) → Type i
C ta tb tc = fst (Trunc= ta tb) → fst (Trunc= tb tc) → fst (Trunc= ta tc)
level : (ta tb tc : Trunc (S n) A) → has-level (S n) (C ta tb tc)
level ta tb tc = raise-level _ $
Π-level (λ _ → Π-level (λ _ → snd (Trunc= ta tc)))
Trunc=-∙-comm : {x y z : Trunc (S n) A }
(p : x == y) (q : y == z)
→ –> (Trunc=-equiv x z) (p ∙ q)
== Trunc=-∙ {ta = x} (–> (Trunc=-equiv x y) p) (–> (Trunc=-equiv y z) q)
Trunc=-∙-comm {x = x} idp idp =
Trunc-elim
{P = λ x → –> (Trunc=-equiv x x) idp
== Trunc=-∙ {ta = x} (–> (Trunc=-equiv x x) idp)
(–> (Trunc=-equiv x x) idp)}
(λ x → raise-level _ $ =-preserves-level (snd (Trunc= x x)))
(λ a → idp)
x
{- Truncation preserves equivalences - more convenient than univalence+ap
- when we need to know the forward or backward function explicitly -}
module _ {i j} (n : ℕ₋₂) {A : Type i} {B : Type j} where
Trunc-isemap : {f : A → B} → is-equiv f → is-equiv (Trunc-fmap {n = n} f)
Trunc-isemap {f-orig} ie = is-eq f g f-g g-f where
f = Trunc-fmap f-orig
g = Trunc-fmap (is-equiv.g ie)
f-g : ∀ tb → f (g tb) == tb
f-g = Trunc-elim (λ _ → =-preserves-level Trunc-level)
(ap [_] ∘ is-equiv.f-g ie)
g-f : ∀ ta → g (f ta) == ta
g-f = Trunc-elim (λ _ → =-preserves-level Trunc-level)
(ap [_] ∘ is-equiv.g-f ie)
Trunc-emap : A ≃ B → Trunc n A ≃ Trunc n B
Trunc-emap (f , f-ie) = Trunc-fmap f , Trunc-isemap f-ie
transport-Trunc : ∀ {i j} {A : Type i} {n : ℕ₋₂} (P : A → Type j)
{x y : A} (p : x == y) (b : P x)
→ transport (Trunc n ∘ P) p [ b ] == [ transport P p b ]
transport-Trunc _ idp _ = idp
Trunc-fuse : ∀ {i} (A : Type i) (m n : ℕ₋₂)
→ Trunc m (Trunc n A) ≃ Trunc (minT m n) A
Trunc-fuse A m n = equiv
(Trunc-rec (raise-level-≤T (minT≤l m n) Trunc-level)
(Trunc-rec (raise-level-≤T (minT≤r m n) Trunc-level)
[_]))
(Trunc-rec l ([_] ∘ [_]))
(Trunc-elim (λ _ → =-preserves-level Trunc-level) (λ _ → idp))
(Trunc-elim (λ _ → =-preserves-level Trunc-level)
(Trunc-elim
(λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level))
(λ _ → idp)))
where l : has-level (minT m n) (Trunc m (Trunc n A))
l with (minT-out m n)
l | inl p = transport (λ k → has-level k (Trunc m (Trunc n A)))
(! p) Trunc-level
l | inr q = Trunc-preserves-level _
(transport (λ k → has-level k (Trunc n A))
(! q) Trunc-level)
Trunc-fuse-≤ : ∀ {i} (A : Type i) {m n : ℕ₋₂} (m≤n : m ≤T n)
→ Trunc m (Trunc n A) ≃ Trunc m A
Trunc-fuse-≤ A m≤n = equiv
(Trunc-rec Trunc-level
(Trunc-rec (raise-level-≤T m≤n Trunc-level)
[_]))
(Trunc-rec Trunc-level ([_] ∘ [_]))
(Trunc-elim (λ _ → =-preserves-level Trunc-level) (λ _ → idp))
(Trunc-elim (λ _ → =-preserves-level Trunc-level)
(Trunc-elim
(λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level))
(λ _ → idp)))
{- Truncating a binary product is equivalent to truncating its components -}
Trunc-×-econv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)
→ Trunc n (A × B) ≃ Trunc n A × Trunc n B
Trunc-×-econv n A B = equiv f g f-g g-f
where
f : Trunc n (A × B) → Trunc n A × Trunc n B
f = Trunc-rec (×-level Trunc-level Trunc-level)
(λ {(a , b) → [ a ] , [ b ]})
g : Trunc n A × Trunc n B → Trunc n (A × B)
g (ta , tb) = Trunc-rec Trunc-level
(λ a → Trunc-rec Trunc-level
(λ b → [ a , b ])
tb)
ta
f-g : ∀ p → f (g p) == p
f-g (ta , tb) = Trunc-elim
{P = λ ta → f (g (ta , tb)) == (ta , tb)}
(λ _ → =-preserves-level (×-level Trunc-level Trunc-level))
(λ a → Trunc-elim
{P = λ tb → f (g ([ a ] , tb)) == ([ a ] , tb)}
(λ _ → =-preserves-level (×-level Trunc-level Trunc-level))
(λ b → idp)
tb)
ta
g-f : ∀ tab → g (f tab) == tab
g-f = Trunc-elim
{P = λ tab → g (f tab) == tab}
(λ _ → =-preserves-level Trunc-level)
(λ ab → idp)
Trunc-×-conv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)
→ Trunc n (A × B) == Trunc n A × Trunc n B
Trunc-×-conv n A B = ua (Trunc-×-econv n A B)
| 37.896226
| 126
| 0.500871
|
43db40ef6eeb5f41661d64e1d30cc93583b6fd0d
| 5,891
|
agda
|
Agda
|
homotopy/JoinAssoc.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
homotopy/JoinAssoc.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
homotopy/JoinAssoc.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
-- Associativity of the join (work in progress)
module homotopy.JoinAssoc {i j k} (A : Type i) (B : Type j) (C : Type k) where
{- First map -}
to : (A * B) * C → A * (B * C)
to = To.f module ToM where
to-left-glue : (ab : A × B) → left (fst ab) == right (left (snd ab)) :> A * (B * C)
to-left-glue (a , b) = glue (a , left b)
{-
(to∘inl)(inl(a)) :≡ inl(a)
(to∘inl)(inr(b)) :≡ inr(inl(b))
ap (to∘inl) (glue(a,b)) := glue(a,inl(b))
-}
module ToLeft = PushoutRec left (right ∘ left) to-left-glue
to-left : A * B → A * (B * C)
to-left = ToLeft.f
to-glue-left : (c : C) (a : A) → to-left (left a) == right (right c)
to-glue-left c a = glue (a , right c)
to-glue-right : (c : C) (b : B) → to-left (right b) == right (right c)
to-glue-right c b = ap right (glue (b , c))
to-glue-glue : (c : C) (ab : A × B) → to-glue-left c (fst ab) == to-glue-right c (snd ab) [ (λ x → to-left x == right (right c)) ↓ glue ab ]
to-glue-glue c (a , b) = ↓-swap to-left right _ idp
(ToLeft.glue-β (a , b) ◃ apd (λ x → glue (a , x)) (glue (b , c)))
module ToGlue (c : C) = PushoutElim (to-glue-left c) (to-glue-right c) (to-glue-glue c)
to-glue : (ab-c : (A * B) × C) → to-left (fst ab-c) == right (right (snd ab-c))
to-glue (ab , c) = M.f ab where module M = ToGlue c
{-
to(inr(c)) :≡ inr(inr(c))
ap to (glue(inl(a),c)) := glue(a,inr(c))
ap to (glue(inr(b),c)) := ap inr (glue(b,c))
-}
module To = PushoutRec {d = *-span (A * B) C} to-left (right ∘ right) to-glue
{- Second map -}
from : A * (B * C) → (A * B) * C
from = From.f module MM where
from-right-glue : (bc : B × C) → left (right (fst bc)) == right (snd bc)
from-right-glue (b , c) = glue (right b , c)
{-
(from∘inr)(inl(b)) :≡ inl(inr(b))
(from∘inr)(inr(c)) :≡ inr(c)
ap (from∘inr) (glue(b,c)) := glue(lnr(b),c)
-}
module FromRight = PushoutRec (left ∘ right) right from-right-glue
from-right : B * C → (A * B) * C
from-right = FromRight.f
from-glue-left : (a : A) (b : B) → left (left a) == from-right (left b)
from-glue-left a b = ap left (glue (a , b))
from-glue-right : (a : A) (c : C) → left (left a) == from-right (right c)
from-glue-right a c = glue (left a , c)
from-glue-glue : (a : A) (bc : B × C) → from-glue-left a (fst bc) == from-glue-right a (snd bc) [ (λ x → left (left a) == from-right x) ↓ glue bc ]
from-glue-glue a (b , c) = ↓-swap! left from-right _ idp
(apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c)))
module FromGlue (a : A) = PushoutElim (from-glue-left a) (from-glue-right a) (from-glue-glue a)
from-glue : (a-bc : A × (B * C)) → left (left (fst a-bc)) == from-right (snd a-bc)
from-glue (a , bc) = M.f bc where module M = FromGlue a
{-
(from∘inl)(a) :≡ inl(inl(a))
ap from (glue(a,inr(c)) := glue(inl(a),c)
ap from (glue(a,inl(b)) := ap inl (glue(a,b))
-}
module From = PushoutRec {d = *-span A (B * C)} (left ∘ left) from-right from-glue
open MM public
{- First composite -}
to-from-right-glue' : (b : B) (c : C) → ap (to ∘ from-right) (glue (b , c)) =-= ap right (glue (b , c))
to-from-right-glue' b c =
ap (λ z → to (from-right z)) (glue (b , c)) =⟪ ap-∘ to from-right (glue (b , c)) ⟫
ap to (ap from-right (glue (b , c))) =⟪ FromRight.glue-β (b , c) |in-ctx ap to ⟫
ap to (glue ((right b , c) :> ((A * B) × C))) =⟪ To.glue-β (right b , c)⟫
ap right (glue (b , c)) ∎∎
to-from-right-glue : (bc : B × C) → idp == idp [ (λ x → to (from (right x)) == right x) ↓ glue bc ]
to-from-right-glue (b , c) = ↓-='-in (! (↯ to-from-right-glue' b c))
module ToFromRight = PushoutElim (λ _ → idp) (λ _ → idp) to-from-right-glue
to-from-right : (bc : B * C) → to (from (right bc)) == right bc
to-from-right = ToFromRight.f
to-from-glue-left' : (a : A) (b : B) → ap to (ap from (glue (a , left b))) =-= glue (a , left b)
to-from-glue-left' a b =
ap to (ap from (glue (a , left b))) =⟪ From.glue-β (a , left b) |in-ctx ap to ⟫
ap to (ap left (glue (a , b))) =⟪ ∘-ap to left (glue (a , b)) ⟫
ap ToM.to-left (glue (a , b)) =⟪ ToM.ToLeft.glue-β (a , b) ⟫
glue (a , left b) ∎∎
to-from-glue-left : (a : A) (b : B) → idp == to-from-right (left b) [ (λ x → to (from x) == x) ↓ glue (a , left b) ]
to-from-glue-left a b = ↓-∘=idf-in to from (↯ to-from-glue-left' a b)
to-from-glue-right' : (a : A) (c : C) → ap to (ap from (glue (a , right c))) =-= glue (a , right c)
to-from-glue-right' a c =
ap to (ap from (glue (a , right c))) =⟪ From.glue-β (a , right c) |in-ctx ap to ⟫
ap to (glue (left a , c)) =⟪ ToM.To.glue-β (left a , c) ⟫
glue (a , right c) ∎∎
to-from-glue-right : (a : A) (c : C) → idp == to-from-right (right c) [ (λ x → to (from x) == x) ↓ glue (a , right c) ]
to-from-glue-right a c = ↓-∘=idf-in to from (↯ to-from-glue-right' a c)
{-
to-from-left-glue' : (a : A) → ap (to ∘ from-left) a =-= ap right (a)
to-from-left-glue' a =
ap (λ z → to (from-right z)) (glue (b , c)) =⟪ ap-∘ to from-right (glue (b , c)) ⟫
ap to (ap from-right (glue (b , c))) =⟪ FromRight.glue-β (b , c) |in-ctx ap to ⟫
ap to (glue ((right b , c) :> (A * B) × C)) =⟪ ToM.To.glue-β (right b , c) ⟫
ap right (glue (b , c)) ∎∎
to-from-left-glue : (a : A) → idp == idp [ (λ x → to (from (left x)) == left x) ↓ glue a ]
to-from-left-glue (a) = ↓-='-in (! (↯ to-from-right-glue' b c))
module ToFromLeft = PushoutElim (λ _ → idp) (λ _ → idp) to-from-left-glue
-}
postulate -- Not proved yet. Some of it is being worked on at JoinAssoc2
*-assoc : ((A * B) * C) ≃ (A * (B * C))
| 40.07483
| 151
| 0.504838
|
216d7fafe9199139129adfb3fc91e50eeda15f63
| 200
|
agda
|
Agda
|
test/Fail/BuiltinMustBeConstructor.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/BuiltinMustBeConstructor.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/BuiltinMustBeConstructor.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module BuiltinMustBeConstructor where
data Bool : Set where
true : Bool
other : Bool
false : Bool
false = true
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
| 14.285714
| 37
| 0.665
|
c7f9f404c7d6ad394e8c10391f94aa9aa444e723
| 2,209
|
agda
|
Agda
|
vendor/stdlib/src/Relation/Binary/FunctionSetoid.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Relation/Binary/FunctionSetoid.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Relation/Binary/FunctionSetoid.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Function setoids and related constructions
------------------------------------------------------------------------
module Relation.Binary.FunctionSetoid where
open import Data.Function
open import Relation.Binary
infixr 0 _↝_ _⟶_ _⇨_ _≡⇨_
-- A logical relation (i.e. a relation which relates functions which
-- map related things to related things).
_↝_ : ∀ {A B} → (∼₁ : Rel A) (∼₂ : Rel B) → Rel (A → B)
_∼₁_ ↝ _∼₂_ = λ f g → ∀ {x y} → x ∼₁ y → f x ∼₂ g y
-- Functions which preserve equality.
record _⟶_ (From To : Setoid) : Set where
open Setoid
infixl 5 _⟨$⟩_
field
_⟨$⟩_ : carrier From → carrier To
pres : _⟨$⟩_ Preserves _≈_ From ⟶ _≈_ To
open _⟶_ public
↝-isEquivalence : ∀ {A B C} {∼₁ : Rel A} {∼₂ : Rel B}
(fun : C → (A → B)) →
(∀ f → fun f Preserves ∼₁ ⟶ ∼₂) →
IsEquivalence ∼₁ → IsEquivalence ∼₂ →
IsEquivalence ((∼₁ ↝ ∼₂) on₁ fun)
↝-isEquivalence _ pres eq₁ eq₂ = record
{ refl = λ {f} x∼₁y → pres f x∼₁y
; sym = λ f∼g x∼y → sym eq₂ (f∼g (sym eq₁ x∼y))
; trans = λ f∼g g∼h x∼y → trans eq₂ (f∼g (refl eq₁)) (g∼h x∼y)
} where open IsEquivalence
-- Function setoids.
_⇨_ : Setoid → Setoid → Setoid
S₁ ⇨ S₂ = record
{ carrier = S₁ ⟶ S₂
; _≈_ = (_≈_ S₁ ↝ _≈_ S₂) on₁ _⟨$⟩_
; isEquivalence =
↝-isEquivalence _⟨$⟩_ pres (isEquivalence S₁) (isEquivalence S₂)
} where open Setoid; open _⟶_
-- A generalised variant of (_↝_ _≡_).
≡↝ : ∀ {A} {B : A → Set} → (∀ x → Rel (B x)) → Rel ((x : A) → B x)
≡↝ R = λ f g → ∀ x → R x (f x) (g x)
≡↝-isEquivalence : {A : Set} {B : A → Set} {R : ∀ x → Rel (B x)} →
(∀ x → IsEquivalence (R x)) → IsEquivalence (≡↝ R)
≡↝-isEquivalence eq = record
{ refl = λ _ → refl
; sym = λ f∼g x → sym (f∼g x)
; trans = λ f∼g g∼h x → trans (f∼g x) (g∼h x)
} where open module Eq {x} = IsEquivalence (eq x)
_≡⇨_ : (A : Set) → (A → Setoid) → Setoid
A ≡⇨ S = record
{ carrier = (x : A) → carrier (S x)
; _≈_ = ≡↝ (λ x → _≈_ (S x))
; isEquivalence = ≡↝-isEquivalence (λ x → isEquivalence (S x))
} where open Setoid
| 32.014493
| 72
| 0.499321
|
fd370a13e943a9841621f3b290f567ca18ac8965
| 6,573
|
agda
|
Agda
|
Cubical/Foundations/Equiv.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Foundations/Equiv.agda
|
rei1024/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Equiv.agda
|
rei1024/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
{-
Theory about equivalences
Definitions are in Core/Glue.agda but re-exported by this module
- isEquiv is a proposition ([isPropIsEquiv])
- Any isomorphism is an equivalence ([isoToEquiv])
There are more statements about equivalences in Equiv/Properties.agda:
- if f is an equivalence then (cong f) is an equivalence
- if f is an equivalence then precomposition with f is an equivalence
- if f is an equivalence then postcomposition with f is an equivalence
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Equiv where
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv.Base public
private
variable
ℓ ℓ' ℓ'' : Level
A B C : Type ℓ
fiber : ∀ {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ')
fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y
equivIsEquiv : ∀ {A : Type ℓ} {B : Type ℓ'} (e : A ≃ B) → isEquiv (equivFun e)
equivIsEquiv e = snd e
equivCtr : ∀ {A : Type ℓ} {B : Type ℓ'} (e : A ≃ B) (y : B) → fiber (equivFun e) y
equivCtr e y = e .snd .equiv-proof y .fst
equivCtrPath : ∀ {A : Type ℓ} {B : Type ℓ'} (e : A ≃ B) (y : B) →
(v : fiber (equivFun e) y) → Path _ (equivCtr e y) v
equivCtrPath e y = e .snd .equiv-proof y .snd
-- Proof using isPropIsContr. This is slow and the direct proof below is better
isPropIsEquiv' : (f : A → B) → isProp (isEquiv f)
equiv-proof (isPropIsEquiv' f u0 u1 i) y =
isPropIsContr (u0 .equiv-proof y) (u1 .equiv-proof y) i
-- Direct proof that computes quite ok (can be optimized further if
-- necessary, see:
-- https://github.com/mortberg/cubicaltt/blob/pi4s3_dimclosures/examples/brunerie2.ctt#L562
isPropIsEquiv : (f : A → B) → isProp (isEquiv f)
equiv-proof (isPropIsEquiv f p q i) y =
let p2 = p .equiv-proof y .snd
q2 = q .equiv-proof y .snd
in p2 (q .equiv-proof y .fst) i
, λ w j → hcomp (λ k → λ { (i = i0) → p2 w j
; (i = i1) → q2 w (j ∨ ~ k)
; (j = i0) → p2 (q2 w (~ k)) i
; (j = i1) → w })
(p2 w (i ∨ j))
equivEq : (e f : A ≃ B) → (h : e .fst ≡ f .fst) → e ≡ f
equivEq e f h = λ i → (h i) , isProp→PathP (λ i → isPropIsEquiv (h i)) (e .snd) (f .snd) i
module _ (w : A ≃ B) where
invEq : B → A
invEq y = fst (fst (snd w .equiv-proof y))
secEq : section invEq (w .fst)
secEq x = λ i → fst (snd (snd w .equiv-proof (fst w x)) (x , (λ j → fst w x)) i)
retEq : retract invEq (w .fst)
retEq y = λ i → snd (fst (snd w .equiv-proof y)) i
equivToIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → A ≃ B → Iso A B
equivToIso {A = A} {B = B} e = iso (e .fst) (invEq e ) (retEq e) (secEq e)
invEquiv : A ≃ B → B ≃ A
invEquiv f = isoToEquiv (iso (invEq f) (fst f) (secEq f) (retEq f))
invEquivIdEquiv : (A : Type ℓ) → invEquiv (idEquiv A) ≡ idEquiv A
invEquivIdEquiv _ = equivEq _ _ refl
compEquiv : A ≃ B → B ≃ C → A ≃ C
compEquiv f g = isoToEquiv
(iso (λ x → g .fst (f .fst x))
(λ x → invEq f (invEq g x))
(λ y → (cong (g .fst) (retEq f (invEq g y))) ∙ (retEq g y))
(λ y → (cong (invEq f) (secEq g (f .fst y))) ∙ (secEq f y)))
compEquivIdEquiv : {A B : Type ℓ} (e : A ≃ B) → compEquiv (idEquiv A) e ≡ e
compEquivIdEquiv e = equivEq _ _ refl
compEquivEquivId : {A B : Type ℓ} (e : A ≃ B) → compEquiv e (idEquiv B) ≡ e
compEquivEquivId e = equivEq _ _ refl
invEquiv-is-rinv : {A B : Type ℓ} (e : A ≃ B) → compEquiv e (invEquiv e) ≡ idEquiv A
invEquiv-is-rinv e = equivEq _ _ (funExt (secEq e))
invEquiv-is-linv : {A B : Type ℓ} (e : A ≃ B) → compEquiv (invEquiv e) e ≡ idEquiv B
invEquiv-is-linv e = equivEq _ _ (funExt (retEq e))
compEquiv-assoc : {A B C D : Type ℓ} (f : A ≃ B) (g : B ≃ C) (h : C ≃ D)
→ compEquiv f (compEquiv g h) ≡ compEquiv (compEquiv f g) h
compEquiv-assoc f g h = equivEq _ _ refl
LiftEquiv : {A : Type ℓ} → A ≃ Lift {i = ℓ} {j = ℓ'} A
LiftEquiv = isoToEquiv (iso lift lower (λ _ → refl) (λ _ → refl))
-- module _ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where
-- invEquivInvol : (f : A ≃ B) → invEquiv (invEquiv f) ≡ f
-- invEquivInvol f i .fst = fst f
-- invEquivInvol f i .snd = propIsEquiv (fst f) (snd (invEquiv (invEquiv f))) (snd f) i
Contr→Equiv : isContr A → isContr B → A ≃ B
Contr→Equiv Actr Bctr = isoToEquiv (iso (λ _ → fst Bctr) (λ _ → fst Actr) (snd Bctr) (snd Actr))
PropEquiv→Equiv : (Aprop : isProp A) (Bprop : isProp B) (f : A → B) (g : B → A) → (A ≃ B)
PropEquiv→Equiv Aprop Bprop f g = isoToEquiv (iso f g (λ b → Bprop (f (g b)) b) λ a → Aprop (g (f a)) a)
homotopyNatural : {f g : A → B} (H : ∀ a → f a ≡ g a) {x y : A} (p : x ≡ y) →
H x ∙ cong g p ≡ cong f p ∙ H y
homotopyNatural {f = f} {g = g} H {x} {y} p i j =
hcomp (λ k → λ { (i = i0) → compPath-filler (H x) (cong g p) k j
; (i = i1) → compPath-filler' (cong f p) (H y) k j
; (j = i0) → cong f p (i ∧ (~ k))
; (j = i1) → cong g p (i ∨ k) })
(H (p i) j)
Hfa≡fHa : ∀ {A : Type ℓ} (f : A → A) → (H : ∀ a → f a ≡ a) → ∀ a → H (f a) ≡ cong f (H a)
Hfa≡fHa {A = A} f H a =
H (f a) ≡⟨ rUnit (H (f a)) ⟩
H (f a) ∙ refl ≡⟨ cong (_∙_ (H (f a))) (sym (rCancel (H a))) ⟩
H (f a) ∙ H a ∙ sym (H a) ≡⟨ assoc _ _ _ ⟩
(H (f a) ∙ H a) ∙ sym (H a) ≡⟨ cong (λ x → x ∙ (sym (H a))) (homotopyNatural H (H a)) ⟩
(cong f (H a) ∙ H a) ∙ sym (H a) ≡⟨ sym (assoc _ _ _) ⟩
cong f (H a) ∙ H a ∙ sym (H a) ≡⟨ cong (_∙_ (cong f (H a))) (rCancel _) ⟩
cong f (H a) ∙ refl ≡⟨ sym (rUnit _) ⟩
cong f (H a) ∎
invEq≡→equivFun≡ : ∀ (e : A ≃ B) {x y} → invEq e x ≡ y → equivFun e y ≡ x
invEq≡→equivFun≡ e {x} p = cong (equivFun e) (sym p) ∙ retEq e x
equivPi
: ∀{F : A → Set ℓ} {G : A → Set ℓ'}
→ ((x : A) → F x ≃ G x) → (((x : A) → F x) ≃ ((x : A) → G x))
equivPi k .fst f x = k x .fst (f x)
equivPi k .snd .equiv-proof f
.fst .fst x = equivCtr (k x) (f x) .fst
equivPi k .snd .equiv-proof f
.fst .snd i x = equivCtr (k x) (f x) .snd i
equivPi k .snd .equiv-proof f
.snd (g , p) i .fst x = equivCtrPath (k x) (f x) (g x , λ j → p j x) i .fst
equivPi k .snd .equiv-proof f
.snd (g , p) i .snd j x = equivCtrPath (k x) (f x) (g x , λ k → p k x) i .snd j
-- Some helpful notation:
_≃⟨_⟩_ : (X : Type ℓ) → (X ≃ B) → (B ≃ C) → (X ≃ C)
_ ≃⟨ f ⟩ g = compEquiv f g
_■ : (X : Type ℓ) → (X ≃ X)
_■ = idEquiv
infixr 0 _≃⟨_⟩_
infix 1 _■
| 38.438596
| 104
| 0.544348
|
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.