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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
30ba881226548e8ca5953c8bc24d2c2238c0cf32
| 11,666
|
agda
|
Agda
|
src/Categories/Category/CartesianClosed.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/CartesianClosed.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/CartesianClosed.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
module Categories.Category.CartesianClosed {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level
open import Function using (_$_; flip)
open import Data.Product using (Σ; _,_; uncurry)
open import Categories.Category.BinaryProducts 𝒞
open import Categories.Category.Cartesian 𝒞
open import Categories.Category.Cartesian.Monoidal using (module CartesianMonoidal)
open import Categories.Category.Monoidal.Closed using (Closed)
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor
open import Categories.NaturalTransformation hiding (id)
open import Categories.NaturalTransformation.Properties
open import Categories.Object.Product 𝒞
hiding (repack≡id; repack∘; repack-cancel; up-to-iso; transport-by-iso)
open import Categories.Object.Exponential 𝒞 hiding (repack)
open import Categories.Object.Terminal using (Terminal)
open import Categories.Morphism 𝒞
open import Categories.Morphism.Reasoning 𝒞
private
module 𝒞 = Category 𝒞
open Category 𝒞
open HomReasoning
open Equiv
variable
A B C : Obj
f g h i : A ⇒ B
-- Cartesian closed category
-- is a category with all products and exponentials
record CartesianClosed : Set (levelOfTerm 𝒞) where
infixr 9 _^_
-- an alternative notation for exponential, which emphasizes its internal hom natural
infixr 5 _⇨_
field
cartesian : Cartesian
exp : Exponential A B
module exp {A B} = Exponential (exp {A} {B})
_^_ : Obj → Obj → Obj
B ^ A = exp.B^A {A} {B}
_⇨_ : Obj → Obj → Obj
_⇨_ = flip _^_
private
module cartesian = Cartesian cartesian
open CartesianMonoidal cartesian using (A×⊤≅A)
open BinaryProducts cartesian.products using (_×_; product; π₁; π₂; ⟨_,_⟩;
project₁; project₂; η; ⟨⟩-cong₂; ⟨⟩∘; _⁂_; ⟨⟩-congˡ;
first∘first; firstid; first; second; first↔second; second∘second; ⁂-cong₂; -×_)
open Terminal cartesian.terminal using (⊤; !; !-unique₂; ⊤-id)
B^A×A : ∀ B A → Product (B ^ A) A
B^A×A B A = exp.product {A} {B}
eval : Product.A×B (B^A×A B A) ⇒ B
eval = exp.eval
λg : C × A ⇒ B → C ⇒ B ^ A
λg f = exp.λg product f
λ-cong : f ≈ g → λg f ≈ λg g
λ-cong eq = exp.λ-cong product eq
_×id : (f : C ⇒ B ^ A) → C × A ⇒ [[ B^A×A B A ]]
f ×id = [ product ⇒ exp.product ] f ×id
β : eval ∘ λg f ×id ≈ f
β = exp.β product
η-exp : λg (eval ∘ f ×id) ≈ f
η-exp = exp.η product
λ-unique : eval ∘ f ×id ≈ g → f ≈ λg g
λ-unique = exp.λ-unique product
λ-unique₂ : eval ∘ f ×id ≈ eval ∘ g ×id → f ≈ g
λ-unique₂ = exp.λ-unique′ product
-- the annoying detail is that B^A×A is NOT the same as B ^ A × A, but they are isomorphic.
-- make some infra so that the latter (which is more intuitive) can be used.
B^A×A-iso : Product.A×B (B^A×A B A) ≅ B ^ A × A
B^A×A-iso {B = B} {A = A} = record
{ from = repack exp.product product
; to = repack product exp.product
; iso = record
{ isoˡ = begin
repack product exp.product ∘ repack exp.product product
≈⟨ [ exp.product ]⟨⟩∘ ⟩
[ exp.product ]⟨ π₁ ∘ repack exp.product product , π₂ ∘ repack exp.product product ⟩
≈⟨ Product.⟨⟩-cong₂ exp.product project₁ project₂ ⟩
[ exp.product ]⟨ [ exp.product ]π₁ , [ exp.product ]π₂ ⟩
≈⟨ Product.η exp.product ⟩
id
∎
; isoʳ = begin
repack exp.product product ∘ repack product exp.product
≈⟨ ⟨⟩∘ ⟩
⟨ [ exp.product ]π₁ ∘ repack product exp.product , [ exp.product ]π₂ ∘ repack product exp.product ⟩
≈⟨ ⟨⟩-cong₂ (Product.project₁ exp.product) (Product.project₂ exp.product) ⟩
⟨ π₁ , π₂ ⟩
≈⟨ η ⟩
id
∎
}
}
eval′ : B ^ A × A ⇒ B
eval′ = eval ∘ to
where open _≅_ B^A×A-iso
λ-unique′ : eval′ ∘ (f ⁂ id) ≈ g → f ≈ λg g
λ-unique′ eq = exp.λ-unique product (⟺ (pullʳ [ product ⇒ product ⇒ exp.product ]repack∘×) ○ eq)
λ-unique₂′ : eval′ ∘ (f ⁂ id) ≈ eval′ ∘ (g ⁂ id) → f ≈ g
λ-unique₂′ eq = (λ-unique′ eq) ○ ⟺ (λ-unique′ refl)
β′ : eval′ ∘ (λg f ⁂ id) ≈ f
β′ {f = f} = begin
eval′ ∘ (λg f ⁂ id) ≈⟨ pullʳ [ product ⇒ product ⇒ exp.product ]repack∘× ⟩
eval ∘ λg f ×id ≈⟨ β ⟩
f ∎
η-exp′ : λg (eval′ ∘ (f ⁂ id)) ≈ f
η-exp′ = sym (λ-unique′ refl)
η-id′ : λg (eval′ {B = B} {A = A}) ≈ id
η-id′ = sym (λ-unique′ (elimʳ (id×id product)))
⊤^A≅⊤ : ⊤ ^ A ≅ ⊤
⊤^A≅⊤ = record
{ from = !
; to = λg !
; iso = record
{ isoˡ = λ-unique₂ !-unique₂
; isoʳ = ⊤-id _
}
}
A^⊤≅A : A ^ ⊤ ≅ A
A^⊤≅A = record
{ from = let open _≅_ A×⊤≅A in eval′ ∘ to
; to = let open _≅_ A×⊤≅A in λg from
; iso = record
{ isoˡ = λ-unique₂′ $ begin
eval′ ∘ ((λg π₁ ∘ eval′ ∘ ⟨ id , ! ⟩) ⁂ id) ≈˘⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ ((λg π₁ ⁂ id) ∘ ((eval′ ∘ ⟨ id , ! ⟩) ⁂ id)) ≈⟨ pullˡ β′ ⟩
π₁ ∘ ((eval′ ∘ ⟨ id , ! ⟩) ⁂ id) ≈⟨ helper ⟩
eval′ ∘ (id ⁂ id) ∎
; isoʳ = firstid ! $ begin
((eval′ ∘ ⟨ id , ! ⟩) ∘ λg π₁) ⁂ id ≈˘⟨ first∘first ⟩
(eval′ ∘ ⟨ id , ! ⟩ ⁂ id) ∘ (λg π₁ ⁂ id) ≈⟨ helper′ ⟩∘⟨refl ⟩
(⟨ id , ! ⟩ ∘ eval′) ∘ (λg π₁ ⁂ id) ≈⟨ pullʳ β′ ⟩
⟨ id , ! ⟩ ∘ π₁ ≈⟨ ⟨⟩∘ ⟩
⟨ id ∘ π₁ , ! ∘ π₁ ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ !-unique₂ ⟩
⟨ π₁ , π₂ ⟩ ≈⟨ η ⟩
id ∎
}
}
where helper = begin
π₁ ∘ ((eval′ ∘ ⟨ id , ! ⟩) ⁂ id) ≈⟨ project₁ ⟩
(eval′ ∘ ⟨ id , ! ⟩) ∘ π₁ ≈⟨ pullʳ ⟨⟩∘ ⟩
eval′ ∘ ⟨ id ∘ π₁ , ! ∘ π₁ ⟩ ≈⟨ refl⟩∘⟨ ⟨⟩-congˡ !-unique₂ ⟩
eval′ ∘ (id ⁂ id) ∎
helper′ = let open _≅_ A×⊤≅A in begin
(eval′ ∘ ⟨ id , ! ⟩) ⁂ id ≈⟨ introˡ isoˡ ⟩
(⟨ id , ! ⟩ ∘ π₁) ∘ ((eval′ ∘ ⟨ id , ! ⟩) ⁂ id) ≈⟨ pullʳ helper ⟩
⟨ id , ! ⟩ ∘ (eval′ ∘ (id ⁂ id)) ≈⟨ refl⟩∘⟨ elimʳ (id×id product) ⟩
⟨ id , ! ⟩ ∘ eval′ ∎
-- we use -⇨- to represent the bifunctor.
-- -^- would generate a bifunctor of type Bifunctor 𝒞 𝒞.op 𝒞 which is not very typical.
-⇨- : Bifunctor 𝒞.op 𝒞 𝒞
-⇨- = record
{ F₀ = uncurry _⇨_
; F₁ = λ where
(f , g) → λg (g ∘ eval′ ∘ second f)
; identity = λ-cong (identityˡ ○ (elimʳ (id×id product))) ○ η-id′
; homomorphism = λ-unique₂′ helper
; F-resp-≈ = λ where
(eq₁ , eq₂) → λ-cong (∘-resp-≈ eq₂ (∘-resp-≈ʳ (⁂-cong₂ refl eq₁)))
}
where helper : eval′ ∘ first (λg ((g ∘ f) ∘ eval′ ∘ second (h ∘ i)))
≈ eval′ ∘ first (λg (g ∘ eval′ ∘ second i) ∘ λg (f ∘ eval′ ∘ second h))
helper {g = g} {f = f} {h = h} {i = i} = begin
eval′ ∘ first (λg ((g ∘ f) ∘ eval′ ∘ second (h ∘ i))) ≈⟨ β′ ⟩
(g ∘ f) ∘ eval′ ∘ second (h ∘ i) ≈˘⟨ refl⟩∘⟨ pullʳ second∘second ⟩
(g ∘ f) ∘ (eval′ ∘ second h) ∘ second i ≈⟨ center refl ⟩
g ∘ (f ∘ eval′ ∘ second h) ∘ second i ≈˘⟨ refl⟩∘⟨ pullˡ β′ ⟩
g ∘ eval′ ∘ first (λg (f ∘ eval′ ∘ second h)) ∘ second i ≈⟨ refl⟩∘⟨ pushʳ first↔second ⟩
g ∘ (eval′ ∘ second i) ∘ first (λg (f ∘ eval′ ∘ second h)) ≈⟨ sym-assoc ⟩
(g ∘ eval′ ∘ second i) ∘ first (λg (f ∘ eval′ ∘ second h)) ≈˘⟨ pullˡ β′ ⟩
eval′ ∘ first (λg (g ∘ eval′ ∘ second i)) ∘ first (λg (f ∘ eval′ ∘ second h)) ≈⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ first (λg (g ∘ eval′ ∘ second i) ∘ λg (f ∘ eval′ ∘ second h)) ∎
_⇨- : Obj → Endofunctor 𝒞
_⇨- = appˡ -⇨-
-⇨_ : Obj → Functor 𝒞.op 𝒞
-⇨_ = appʳ -⇨-
-- The cartesian closed structure induces a monoidal closed one:
-- 𝒞 is cartesian monoidal closed.
module CartesianMonoidalClosed (cartesianClosed : CartesianClosed) where
open CartesianClosed cartesianClosed
open CartesianMonoidal cartesian using (monoidal)
open BinaryProducts (Cartesian.products cartesian)
using (-×_; first; first∘first; second; first↔second; product)
private
A⇨[-×A] : Obj → Endofunctor 𝒞
A⇨[-×A] A = A ⇨- ∘F -× A
module A⇨[-×A] {A} = Functor (A⇨[-×A] A)
[A⇨-]×A : Obj → Endofunctor 𝒞
[A⇨-]×A A = -× A ∘F A ⇨-
module [A⇨-]×A {A} = Functor ([A⇨-]×A A)
closedMonoidal : Closed monoidal
closedMonoidal = record
{ [-,-] = -⇨-
; adjoint = λ {A} → record
{ unit = ntHelper record
{ η = λ _ → λg id
; commute = λ f → λ-unique₂′ $ begin
eval′ ∘ first (λg id ∘ f) ≈˘⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ first (λg id) ∘ first f ≈⟨ cancelˡ β′ ⟩
first f ≈˘⟨ cancelʳ β′ ⟩
(first f ∘ eval′) ∘ first (λg id) ≈˘⟨ ∘-resp-≈ʳ (elimʳ (id×id product)) ⟩∘⟨refl ⟩
(first f ∘ eval′ ∘ first id) ∘ first (λg id) ≈˘⟨ pullˡ β′ ⟩
eval′ ∘ first (A⇨[-×A].F₁ f) ∘ first (λg id) ≈⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ first (A⇨[-×A].F₁ f ∘ λg id) ∎
}
; counit = ntHelper record
{ η = λ _ → eval′
; commute = λ f → begin
eval′ ∘ [A⇨-]×A.F₁ f ≈⟨ β′ ⟩
f ∘ eval′ ∘ first id ≈⟨ refl⟩∘⟨ elimʳ (id×id product) ⟩
f ∘ eval′ ∎
}
; zig = β′
; zag = λ-unique₂′ $ begin
eval′ ∘ first (λg (eval′ ∘ eval′ ∘ second id) ∘ λg id)
≈˘⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ first (λg (eval′ ∘ eval′ ∘ second id)) ∘ first (λg id)
≈⟨ pullˡ β′ ⟩
(eval′ ∘ eval′ ∘ second id) ∘ first (λg id)
≈⟨ ∘-resp-≈ʳ (elimʳ (id×id product)) ⟩∘⟨refl ⟩
(eval′ ∘ eval′) ∘ first (λg id) ≈⟨ cancelʳ β′ ⟩
eval′ ≈˘⟨ elimʳ (id×id product) ⟩
eval′ ∘ first id ∎
}
; mate = λ {X Y} f → record
{ commute₁ = λ-unique₂′ $ begin
eval′ ∘ first (λg (second f ∘ eval′ ∘ second id) ∘ λg id) ≈˘⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ first (λg (second f ∘ eval′ ∘ second id)) ∘ first (λg id) ≈⟨ pullˡ β′ ⟩
(second f ∘ eval′ ∘ second id) ∘ first (λg id) ≈⟨ ∘-resp-≈ʳ (elimʳ (id×id product)) ⟩∘⟨refl ⟩
(second f ∘ eval′) ∘ first (λg id) ≈⟨ cancelʳ β′ ⟩
second f ≈˘⟨ cancelˡ β′ ⟩
eval′ ∘ first (λg id) ∘ second f ≈⟨ pushʳ first↔second ⟩
(eval′ ∘ second f) ∘ first (λg id) ≈˘⟨ identityˡ ⟩∘⟨refl ⟩
(id ∘ eval′ ∘ second f) ∘ first (λg id) ≈˘⟨ pullˡ β′ ⟩
eval′ ∘ first (λg (id ∘ eval′ ∘ second f)) ∘ first (λg id) ≈⟨ refl⟩∘⟨ first∘first ⟩
eval′ ∘ first (λg (id ∘ eval′ ∘ second f) ∘ λg id) ∎
; commute₂ = begin
eval′ ∘ first (λg (id ∘ eval′ ∘ second f)) ≈⟨ β′ ⟩
id ∘ eval′ ∘ second f ≈⟨ identityˡ ⟩
eval′ ∘ second f ∎
}
}
open Closed closedMonoidal public
| 40.79021
| 123
| 0.468455
|
5206ea2c778c4fd845ecd782270323251943f540
| 104
|
agda
|
Agda
|
test/fail/Imports/ATP-A.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
test/fail/Imports/ATP-A.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | null | null | null |
test/fail/Imports/ATP-A.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
module Imports.ATP-A where
postulate
D : Set
_≡_ : D → D → Set
a b : D
postulate p : a ≡ b
| 11.555556
| 26
| 0.548077
|
19961a68045d0d6b7bb88d939ce85957d0e3c4fc
| 351
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/Bool/Show.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | 1
|
2016-10-20T15:52:05.000Z
|
2016-10-20T15:52:05.000Z
|
agda-stdlib-0.9/src/Data/Bool/Show.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/Bool/Show.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Showing booleans
------------------------------------------------------------------------
module Data.Bool.Show where
open import Data.Bool
open import Data.String hiding (show)
show : Bool → String
show true = "true"
show false = "false"
| 23.4
| 72
| 0.421652
|
5246085eff18e37ea57af89c3f20bca1d80b9197
| 718
|
agda
|
Agda
|
metatheory/test/StringLiteral.agda
|
wenkokke/plutus
|
684fa810c0ffdde68f11ff64a7b2eefd6f2fc8d2
|
[
"Apache-2.0"
] | 3
|
2021-02-18T02:21:36.000Z
|
2022-01-31T20:20:05.000Z
|
metatheory/test/StringLiteral.agda
|
wenkokke/plutus
|
684fa810c0ffdde68f11ff64a7b2eefd6f2fc8d2
|
[
"Apache-2.0"
] | null | null | null |
metatheory/test/StringLiteral.agda
|
wenkokke/plutus
|
684fa810c0ffdde68f11ff64a7b2eefd6f2fc8d2
|
[
"Apache-2.0"
] | null | null | null |
module test.StringLiteral where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
-- plutus/plutus-core/test/data/stringLiteral.plc
postulate str1 : ByteString
{-# FOREIGN GHC import qualified Data.ByteString.Lazy.Char8 as BS #-}
{-# COMPILE GHC str1 = BS.pack "4321758fabce1aa4780193f" #-}
open import Relation.Binary.PropositionalEquality
open import Agda.Builtin.TrustMe
lemma1 : length str1 ≡ 23
lemma1 = primTrustMe
open import Data.Nat
lemma1' : BoundedB 100 str1
lemma1' rewrite lemma1 = gen _ _ _
stringLit : ∀{Γ} → Γ ⊢ con bytestring (size⋆ 100)
stringLit = con (bytestring 100 str1 lemma1')
| 25.642857
| 69
| 0.764624
|
387d6b9597faed03459ec34aec86d745137bcdb9
| 5,865
|
agda
|
Agda
|
theorems/homotopy/EilenbergMacLane.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/EilenbergMacLane.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/EilenbergMacLane.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 HoTT
open import homotopy.HSpace renaming (HSpaceStructure to HSS)
open import homotopy.Freudenthal
open import homotopy.IterSuspensionStable
open import homotopy.Pi2HSusp
open import homotopy.EM1HSpace
open import homotopy.EilenbergMacLane1
module homotopy.EilenbergMacLane where
-- EM(G,n) when G is π₁(A,a₀)
module EMImplicit {i} {X : Ptd i} (cA : is-connected 0 (de⊙ X))
(gA : has-level 1 (de⊙ X)) (H-X : HSS X) where
private
A = de⊙ X
a₀ = pt X
⊙EM : (n : ℕ) → Ptd i
⊙EM O = ⊙Ω X
⊙EM (S n) = ⊙Trunc ⟨ S n ⟩ (⊙Susp^ n X)
module _ (n : ℕ) where
EM = de⊙ (⊙EM n)
EM-level : (n : ℕ) → has-level ⟨ n ⟩ (EM n)
EM-level O = gA a₀ a₀
EM-level (S n) = Trunc-level
EM-conn : (n : ℕ) → is-connected ⟨ n ⟩ (EM (S n))
EM-conn n = Trunc-preserves-conn ⟨ S n ⟩
(transport (λ t → is-connected t (de⊙ (⊙Susp^ n X)))
(+2+0 ⟨ n ⟩₋₂) (⊙Susp^-conn n cA))
{-
π (S k) (EM (S n)) (embase (S n)) == π k (EM n) (embase n)
where k > 0 and n = S (S n')
-}
module Stable (k n : ℕ) (indexing : S k ≤ S (S n))
where
private
SSn : ℕ
SSn = S (S n)
lte : ⟨ S k ⟩ ≤T ⟨ SSn ⟩
lte = ⟨⟩-monotone-≤ $ indexing
Skle : S k ≤ (S n) *2
Skle = ≤-trans indexing (lemma n)
where lemma : (n' : ℕ) → S (S n') ≤ (S n') *2
lemma O = inl idp
lemma (S n') = ≤-trans (≤-ap-S (lemma n')) (inr ltS)
private
module SS = Susp^StableSucc X cA k (S n) Skle
abstract
stable : πS (S k) (⊙EM (S SSn)) ≃ᴳ πS k (⊙EM SSn)
stable =
πS (S k) (⊙EM (S SSn))
≃ᴳ⟨ πS-Trunc-fuse-≤-iso _ _ _ (≤T-ap-S lte) ⟩
πS (S k) (⊙Susp^ SSn X)
≃ᴳ⟨ SS.stable ⟩
πS k (⊙Susp^ (S n) X)
≃ᴳ⟨ πS-Trunc-fuse-≤-iso _ _ _ lte ⁻¹ᴳ ⟩
πS k (⊙EM SSn)
≃ᴳ∎
module BelowDiagonal where
π₁ : (n : ℕ) → πS 0 (⊙EM (S (S n))) ≃ᴳ 0ᴳ
π₁ n =
contr-iso-0ᴳ (πS 0 (⊙EM (S (S n))))
(connected-at-level-is-contr
(raise-level-≤T (≤T-ap-S (≤T-ap-S (-2≤T ⟨ n ⟩₋₂)))
(Trunc-level {n = 0}))
(Trunc-preserves-conn 0 (path-conn (EM-conn (S n)))))
-- some clutter here arises from the definition of <;
-- any simple way to avoid this?
πS-below : (k n : ℕ) → (S k < n)
→ πS k (⊙EM n) ≃ᴳ 0ᴳ
πS-below 0 .2 ltS = π₁ 0
πS-below 0 .3 (ltSR ltS) = π₁ 1
πS-below 0 (S (S n)) (ltSR (ltSR _)) = π₁ n
πS-below (S k) ._ ltS =
πS-below k _ ltS
∘eᴳ Stable.stable k k (inr ltS)
πS-below (S k) ._ (ltSR ltS) =
πS-below k _ (ltSR ltS)
∘eᴳ Stable.stable k (S k) (inr (ltSR ltS))
πS-below (S k) ._ (ltSR (ltSR ltS)) =
πS-below k _ (ltSR (ltSR ltS))
∘eᴳ Stable.stable k (S (S k)) (inr (ltSR (ltSR ltS)))
πS-below (S k) (S (S (S n))) (ltSR (ltSR (ltSR lt))) =
πS-below k _ (<-cancel-S (ltSR (ltSR (ltSR lt))))
∘eᴳ Stable.stable k n (inr (<-cancel-S (ltSR (ltSR (ltSR lt)))))
module OnDiagonal where
π₁ : πS 0 (⊙EM 1) ≃ᴳ πS 0 X
π₁ = πS-Trunc-fuse-≤-iso 0 1 X ≤T-refl
private
module Π₂ = Pi2HSusp gA cA H-X
π₂ : πS 1 (⊙EM 2) ≃ᴳ πS 0 X
π₂ = Π₂.π₂-Susp
∘eᴳ πS-Trunc-fuse-≤-iso 1 2 (⊙Susp X) ≤T-refl
πS-diag : (n : ℕ) → πS n (⊙EM (S n)) ≃ᴳ πS 0 X
πS-diag 0 = π₁
πS-diag 1 = π₂
πS-diag (S (S n)) = πS-diag (S n)
∘eᴳ Stable.stable (S n) n ≤-refl
module AboveDiagonal where
πS-above : ∀ (k n : ℕ) → (n < S k)
→ πS k (⊙EM n) ≃ᴳ 0ᴳ
πS-above k n lt =
contr-iso-0ᴳ (πS k (⊙EM n))
(inhab-prop-is-contr
[ idp^ (S k) ]
(Trunc-preserves-level 0 (Ω^-level -1 (S k) _
(raise-level-≤T (lemma lt) (EM-level n)))))
where lemma : {k n : ℕ} → n < k → ⟨ n ⟩ ≤T (⟨ k ⟩₋₂ +2+ -1)
lemma ltS = inl (! (+2+-comm _ -1))
lemma (ltSR lt) = ≤T-trans (lemma lt) (inr ltS)
module Spectrum where
private
module Π₂ = Pi2HSusp gA cA H-X
spectrum0 : ⊙Ω (⊙EM 1) ⊙≃ ⊙EM 0
spectrum0 =
⊙Ω (⊙EM 1)
⊙≃⟨ ≃-to-⊙≃ (Trunc=-equiv _ _) idp ⟩
⊙Trunc 0 (⊙Ω X)
⊙≃⟨ ≃-to-⊙≃ (unTrunc-equiv _ (gA a₀ a₀)) idp ⟩
⊙Ω X ⊙≃∎
spectrum1 : ⊙Ω (⊙EM 2) ⊙≃ ⊙EM 1
spectrum1 =
⊙Ω (⊙EM 2)
⊙≃⟨ ≃-to-⊙≃ (Trunc=-equiv _ _) idp ⟩
⊙Trunc 1 (⊙Ω (⊙Susp X))
⊙≃⟨ Π₂.⊙main-lemma ⟩
X
⊙≃⟨ ≃-to-⊙≃ (unTrunc-equiv _ gA) idp ⊙⁻¹ ⟩
⊙EM 1 ⊙≃∎
private
sconn : (n : ℕ) → is-connected ⟨ S n ⟩ (de⊙ (⊙Susp^ (S n) X))
sconn n = transport (λ t → is-connected t (de⊙ (⊙Susp^ (S n) X)))
(+2+0 ⟨ n ⟩₋₁) (⊙Susp^-conn (S n) cA)
kle : (n : ℕ) → ⟨ S (S n) ⟩ ≤T ⟨ n ⟩ +2+ ⟨ n ⟩
kle O = inl idp
kle (S n) = ≤T-trans (≤T-ap-S (kle n))
(≤T-trans (inl (! (+2+-βr ⟨ n ⟩ ⟨ n ⟩)))
(inr ltS))
module FS (n : ℕ) =
FreudenthalEquiv ⟨ n ⟩₋₁ ⟨ S (S n) ⟩ (kle n)
(⊙Susp^ (S n) X) (sconn n)
spectrumSS : (n : ℕ)
→ ⊙Ω (⊙EM (S (S (S n)))) ⊙≃ ⊙EM (S (S n))
spectrumSS n =
⊙Ω (⊙EM (S (S (S n))))
⊙≃⟨ ≃-to-⊙≃ (Trunc=-equiv _ _) idp ⟩
⊙Trunc ⟨ S (S n) ⟩ (⊙Ω (⊙Susp^ (S (S n)) X))
⊙≃⟨ FS.⊙eq n ⊙⁻¹ ⟩
⊙EM (S (S n)) ⊙≃∎
abstract
spectrum : (n : ℕ) → ⊙Ω (⊙EM (S n)) ⊙≃ ⊙EM n
spectrum 0 = spectrum0
spectrum 1 = spectrum1
spectrum (S (S n)) = spectrumSS n
module EMExplicit {i} (G : AbGroup i) where
module HSpace = EM₁HSpace G
open EMImplicit EM₁-conn EM₁-level HSpace.H-⊙EM₁ public
open BelowDiagonal public using (πS-below)
πS-diag : (n : ℕ) → πS n (⊙EM (S n)) ≃ᴳ AbGroup.grp G
πS-diag n = π₁-EM₁ (AbGroup.grp G) ∘eᴳ OnDiagonal.πS-diag n
open AboveDiagonal public using (πS-above)
open Spectrum public using (spectrum)
| 29.472362
| 71
| 0.482012
|
1e70f60cbfa946449563c4d70695119a698a03c4
| 8,570
|
agda
|
Agda
|
theorems/cw/cohomology/reconstructed/cochain/Complex.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/cw/cohomology/reconstructed/cochain/Complex.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/cw/cohomology/reconstructed/cochain/Complex.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 cohomology.ChainComplex
open import cohomology.Theory
open import groups.KernelImage
open import cw.CW
module cw.cohomology.reconstructed.cochain.Complex {i : ULevel} (OT : OrdinaryTheory i) where
open OrdinaryTheory OT
open import cw.cohomology.WedgeOfCells OT
import cw.cohomology.reconstructed.TipAndAugment OT as TAA
import cw.cohomology.reconstructed.TipCoboundary OT as TC
import cw.cohomology.reconstructed.HigherCoboundary OT as HC
cochain-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n) {m}
→ Dec (m ≤ n) → AbGroup i
cochain-template ⊙skel (inr _) = Lift-abgroup {j = i} Unit-abgroup
cochain-template ⊙skel {m = 0} (inl 0≤n) = TAA.C2×CX₀-abgroup (⊙cw-take 0≤n ⊙skel) 0
cochain-template ⊙skel {m = S m} (inl Sm≤n) = CXₙ/Xₙ₋₁-abgroup (⊙cw-take Sm≤n ⊙skel) (ℕ-to-ℤ (S m))
cochain-is-abelian-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n) {m} m≤n?
→ is-abelian (AbGroup.grp (cochain-template ⊙skel {m} m≤n?))
cochain-is-abelian-template ⊙skel m≤n? = AbGroup.comm (cochain-template ⊙skel m≤n?)
abstract
private
coboundary-first-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n)
→ (0≤n : 0 ≤ n) (1≤n : 1 ≤ n)
→ ⊙cw-init (⊙cw-take 1≤n ⊙skel) == ⊙cw-take (≤-trans lteS 1≤n) ⊙skel
→ ⊙cw-take (≤-trans lteS 1≤n) ⊙skel == ⊙cw-take 0≤n ⊙skel
→ TAA.C2×CX₀ (⊙cw-take 0≤n ⊙skel) 0 →ᴳ CXₙ/Xₙ₋₁ (⊙cw-take 1≤n ⊙skel) 1
coboundary-first-template ⊙skel 0≤n 1≤n path₀ path₁ =
TC.cw-co∂-head (⊙cw-take 1≤n ⊙skel)
∘ᴳ transport!ᴳ (λ ⊙skel → TAA.C2×CX₀ ⊙skel 0) (path₀ ∙ path₁)
coboundary-higher-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n)
→ {m : ℕ} (Sm≤n : S m ≤ n) (SSm≤n : S (S m) ≤ n)
→ ⊙cw-init (⊙cw-take SSm≤n ⊙skel) == ⊙cw-take (≤-trans lteS SSm≤n) ⊙skel
→ ⊙cw-take (≤-trans lteS SSm≤n) ⊙skel == ⊙cw-take Sm≤n ⊙skel
→ CXₙ/Xₙ₋₁ (⊙cw-take Sm≤n ⊙skel) (ℕ-to-ℤ (S m))
→ᴳ CXₙ/Xₙ₋₁ (⊙cw-take SSm≤n ⊙skel) (ℕ-to-ℤ (S (S m)))
coboundary-higher-template ⊙skel {m} Sm≤n SSm≤n path₀ path₁ =
HC.cw-co∂-last (⊙cw-take SSm≤n ⊙skel)
∘ᴳ transport!ᴳ (λ ⊙skel → CXₙ/Xₙ₋₁ ⊙skel (ℕ-to-ℤ (S m))) (path₀ ∙ path₁)
coboundary-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n)
→ {m : ℕ} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n))
→ AbGroup.grp (cochain-template ⊙skel m≤n?)
→ᴳ AbGroup.grp (cochain-template ⊙skel Sm≤n?)
coboundary-template ⊙skel _ (inr _) = cst-hom
coboundary-template ⊙skel (inr m≰n) (inl Sm≤n) = ⊥-rec $ m≰n (≤-trans lteS Sm≤n)
coboundary-template ⊙skel {m = 0} (inl 0≤n) (inl 1≤n) =
coboundary-first-template ⊙skel 0≤n 1≤n (⊙cw-init-take 1≤n ⊙skel)
(ap (λ 0≤n → ⊙cw-take 0≤n ⊙skel) (≤-has-all-paths (≤-trans lteS 1≤n) 0≤n))
coboundary-template ⊙skel {m = S m} (inl Sm≤n) (inl SSm≤n) =
coboundary-higher-template ⊙skel Sm≤n SSm≤n (⊙cw-init-take SSm≤n ⊙skel)
(ap (λ Sm≤n → ⊙cw-take Sm≤n ⊙skel) (≤-has-all-paths (≤-trans lteS SSm≤n) Sm≤n))
cochain-complex : ∀ {n} → ⊙Skeleton {i} n → CochainComplex i
cochain-complex {n} ⊙skel = record {M} where
module M where
head : AbGroup i
head = C-abgroup 0 (⊙Lift ⊙Bool)
cochain : ℕ → AbGroup i
cochain m = cochain-template ⊙skel (≤-dec m n)
augment : C 0 (⊙Lift ⊙Bool) →ᴳ AbGroup.grp (cochain 0)
augment = TAA.cw-coε (⊙cw-take (O≤ n) ⊙skel)
coboundary : ∀ m → (AbGroup.grp (cochain m) →ᴳ AbGroup.grp (cochain (S m)))
coboundary m = coboundary-template ⊙skel (≤-dec m n) (≤-dec (S m) n)
{- Properties of coboundaries -}
{- lemmas of paths -}
private
abstract
path-lemma₀ : ∀ {n} (⊙skel : ⊙Skeleton {i} (S n)) {m} (m<n : m < n) (Sm<n : S m < n)
→ ap (λ m≤Sn → ⊙cw-take m≤Sn ⊙skel) (≤-has-all-paths (≤-trans lteS (lteSR (inr Sm<n))) (lteSR (inr m<n)))
== ap (λ m≤n → ⊙cw-take m≤n (⊙cw-init ⊙skel)) (≤-has-all-paths (≤-trans lteS (inr Sm<n)) (inr m<n))
path-lemma₀ ⊙skel m<n Sm<n =
ap (λ m≤Sn → ⊙cw-take m≤Sn ⊙skel) (≤-has-all-paths (≤-trans lteS (lteSR (inr Sm<n))) (lteSR (inr m<n)))
=⟨ ap (ap (λ m≤Sn → ⊙cw-take m≤Sn ⊙skel)) (contr-has-all-paths _ _) ⟩
ap (λ m≤Sn → ⊙cw-take m≤Sn ⊙skel) (ap (lteSR ∘ inr) (<-has-all-paths (<-trans ltS Sm<n) m<n))
=⟨ ∘-ap (λ m≤Sn → ⊙cw-take m≤Sn ⊙skel) (lteSR ∘ inr) _ ⟩
ap (λ Sm<n → ⊙cw-take (lteSR (inr Sm<n)) ⊙skel) (<-has-all-paths (<-trans ltS Sm<n) m<n)
=⟨ ap-∘ (λ m≤n → ⊙cw-take m≤n (⊙cw-init ⊙skel)) inr _ ⟩
ap (λ m≤n → ⊙cw-take m≤n (⊙cw-init ⊙skel)) (ap inr (<-has-all-paths (<-trans ltS Sm<n) m<n))
=⟨ ap (ap (λ m≤n → ⊙cw-take m≤n (⊙cw-init ⊙skel))) (contr-has-all-paths _ _) ⟩
ap (λ m≤n → ⊙cw-take m≤n (⊙cw-init ⊙skel)) (≤-has-all-paths (≤-trans lteS (inr Sm<n)) (inr m<n))
=∎
-- would be trivial with [≤-has-all-paths] defined with the set detection (issue #2003)
path-lemma₁ : ∀ {n} (⊙skel : ⊙Skeleton {i} (S (S n)))
→ ap (λ n≤SSn → ⊙cw-take n≤SSn ⊙skel) (≤-has-all-paths (lteSR lteS) (lteSR lteS))
== ap (λ n≤Sn → ⊙cw-take n≤Sn (⊙cw-init ⊙skel)) (≤-has-all-paths lteS lteS)
path-lemma₁ ⊙skel =
ap (λ n≤SSn → ⊙cw-take n≤SSn ⊙skel) (≤-has-all-paths (lteSR lteS) (lteSR lteS))
=⟨ ap (ap (λ n≤SSn → ⊙cw-take n≤SSn ⊙skel)) (contr-has-all-paths _ _) ⟩
idp
=⟨ ap (ap (λ n≤Sn → ⊙cw-take n≤Sn (⊙cw-init ⊙skel))) (contr-has-all-paths _ _) ⟩
ap (λ n≤Sn → ⊙cw-take n≤Sn (⊙cw-init ⊙skel)) (≤-has-all-paths lteS lteS)
=∎
-- would be trivial with [≤-has-all-paths] defined with the set detection (issue #2003)
path-lemma₂ : ∀ {n} (⊙skel : ⊙Skeleton {i} (S n))
→ ap (λ n≤Sn → ⊙cw-take n≤Sn ⊙skel) (≤-has-all-paths lteS lteS) == idp
path-lemma₂ ⊙skel =
ap (λ n≤Sn → ⊙cw-take n≤Sn ⊙skel) (≤-has-all-paths lteS lteS)
=⟨ ap (ap (λ n≤Sn → ⊙cw-take n≤Sn ⊙skel)) (contr-has-all-paths _ _) ⟩
idp
=∎
{- properties of coboundary-template -}
abstract
{- lemmas of the first coboundary -}
coboundary-first-template-descend-from-far : ∀ {n} (⊙skel : ⊙Skeleton {i} (S n)) 0<n 1<n
→ coboundary-template {n = S n} ⊙skel {0} (inl (lteSR (inr 0<n))) (inl (lteSR (inr 1<n)))
== coboundary-template {n = n} (⊙cw-init ⊙skel) (inl (inr 0<n)) (inl (inr 1<n))
coboundary-first-template-descend-from-far ⊙skel 0<n 1<n =
ap (coboundary-first-template ⊙skel (lteSR (inr 0<n)) (lteSR (inr 1<n)) (⊙cw-init-take (lteSR (inr 1<n)) ⊙skel))
(path-lemma₀ ⊙skel 0<n 1<n)
coboundary-first-template-descend-from-two : ∀ (⊙skel : ⊙Skeleton {i} 2)
→ coboundary-template {n = 2} ⊙skel (inl (lteSR lteS)) (inl lteS)
== coboundary-template {n = 1} (⊙cw-init ⊙skel) (inl lteS) (inl lteE)
coboundary-first-template-descend-from-two ⊙skel =
ap (coboundary-first-template ⊙skel (lteSR lteS) lteS idp) (path-lemma₁ ⊙skel)
coboundary-first-template-β : ∀ (⊙skel : ⊙Skeleton {i} 1)
→ coboundary-template {n = 1} ⊙skel (inl lteS) (inl lteE)
== TC.cw-co∂-head ⊙skel
coboundary-first-template-β ⊙skel = group-hom= $
ap (GroupHom.f ∘ coboundary-first-template ⊙skel lteS lteE idp) (path-lemma₂ ⊙skel)
{- lemmas of higher coboundaries -}
coboundary-higher-template-descend-from-far : ∀ {n} (⊙skel : ⊙Skeleton {i} (S n)) {m} Sm<n SSm<n
→ coboundary-template {n = S n} ⊙skel {m = S m} (inl (lteSR (inr Sm<n))) (inl (lteSR (inr SSm<n)))
== coboundary-template {n = n} (⊙cw-init ⊙skel) {m = S m} (inl (inr Sm<n)) (inl (inr SSm<n))
coboundary-higher-template-descend-from-far ⊙skel {m} Sm<n SSm<n =
ap (coboundary-higher-template ⊙skel (lteSR (inr Sm<n)) (lteSR (inr SSm<n)) (⊙cw-init-take (lteSR (inr SSm<n)) ⊙skel))
(path-lemma₀ ⊙skel Sm<n SSm<n)
coboundary-higher-template-descend-from-one-above : ∀ {n} (⊙skel : ⊙Skeleton {i} (S (S (S n))))
→ coboundary-template {n = S (S (S n))} ⊙skel {m = S n} (inl (lteSR lteS)) (inl lteS)
== coboundary-template {n = S (S n)} (⊙cw-init ⊙skel) {m = S n} (inl lteS) (inl lteE)
coboundary-higher-template-descend-from-one-above ⊙skel =
ap (coboundary-higher-template ⊙skel (lteSR lteS) lteS idp) (path-lemma₁ ⊙skel)
coboundary-higher-template-β : ∀ {n} (⊙skel : ⊙Skeleton {i} (S (S n)))
→ coboundary-template {n = S (S n)} ⊙skel {m = S n} (inl lteS) (inl lteE)
== HC.cw-co∂-last ⊙skel
coboundary-higher-template-β ⊙skel = group-hom= $
ap (GroupHom.f ∘ coboundary-higher-template ⊙skel lteS lteE idp) (path-lemma₂ ⊙skel)
| 54.240506
| 124
| 0.578063
|
135230a1056a1bfe05451aa7e21d23817914c392
| 1,681
|
agda
|
Agda
|
Graphs/UnionGraph.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Graphs/UnionGraph.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Graphs/UnionGraph.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Functions.Definition
open import Setoids.Setoids
open import Setoids.DirectSum
open import Setoids.Subset
open import Graphs.Definition
open import Sets.FinSet.Definition
open import Sets.FinSet.Lemmas
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Sets.EquivalenceRelations
open import Graphs.PathGraph
module Graphs.UnionGraph where
unionGraph : {a b c d e f : _} {V' : Set a} {V : Setoid {a} {b} V'} (G : Graph c V) {W' : Set d} {W : Setoid {d} {e} W'} (H : Graph f W) → Graph (c ⊔ f) (directSumSetoid V W)
Graph._<->_ (unionGraph {c = c} {f = f} G H) (inl v) (inl v2) = embedLevel {c} {f} (Graph._<->_ G v v2)
Graph._<->_ (unionGraph G H) (inl v) (inr w) = False'
Graph._<->_ (unionGraph G H) (inr w) (inl v) = False'
Graph._<->_ (unionGraph {c = c} {f = f} G H) (inr w) (inr w2) = embedLevel {f} {c} (Graph._<->_ H w w2)
Graph.noSelfRelation (unionGraph G H) (inl v) (v=v ,, _) = Graph.noSelfRelation G v v=v
Graph.noSelfRelation (unionGraph G H) (inr w) (w=w ,, _) = Graph.noSelfRelation H w w=w
Graph.symmetric (unionGraph G H) {inl x} {inl y} (x=y ,, _) = Graph.symmetric G x=y ,, record {}
Graph.symmetric (unionGraph G H) {inr x} {inr y} (x=y ,, _) = Graph.symmetric H x=y ,, record {}
Graph.wellDefined (unionGraph G H) {inl x} {inl y} {inl z} {inl w} (x=y ,, _) (y=z ,, _) (z=w ,, _) = Graph.wellDefined G x=y y=z z=w ,, record {}
Graph.wellDefined (unionGraph G H) {inr x} {inr y} {inr z} {inr w} (x=y ,, _) (y=z ,, _) (z=w ,, _) = Graph.wellDefined H x=y y=z z=w ,, record {}
| 56.033333
| 174
| 0.654372
|
d118426f8f5a0856957f99009daafb49e55c83b6
| 3,122
|
agda
|
Agda
|
old/Structure/Logic/Classical/SetTheory/ZFC/FunctionSet.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
old/Structure/Logic/Classical/SetTheory/ZFC/FunctionSet.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
old/Structure/Logic/Classical/SetTheory/ZFC/FunctionSet.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Functional hiding (Domain)
import Structure.Logic.Classical.NaturalDeduction
import Structure.Logic.Classical.SetTheory.ZFC
module Structure.Logic.Classical.SetTheory.ZFC.FunctionSet {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic : _ ⦄ (_∈_ : Domain → Domain → Formula) ⦃ signature : _ ⦄ where
open Structure.Logic.Classical.NaturalDeduction.ClassicalLogic {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} (classicLogic)
open Structure.Logic.Classical.SetTheory.ZFC.Signature {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic ⦄ {_∈_} (signature)
open import Structure.Logic.Classical.SetTheory.SetBoundedQuantification ⦃ classicLogic ⦄ (_∈_)
open import Structure.Logic.Classical.SetTheory.ZFC.BinaryRelatorSet ⦃ classicLogic ⦄ (_∈_) ⦃ signature ⦄
-- The set s can be interpreted as a function.
FunctionSet : Domain → Formula
FunctionSet(s) = ∀ₗ(x ↦ Unique(y ↦ (x , y) ∈ s))
-- TODO: Maybe also define something that states ∀ₗ(x ↦ (x ∈ A) ↔ ∃ₗ(y ↦ (x , y) ∈ s)) so that a set representation of a function with domains becomes unique? But I think when (s ∈ (B ^ A)) is satisfied, this is implied? So try to prove that (FunctionSet(f) ∧ Total(A)(f) ∧ (the thing I mentioned earlier)) ↔ (f ∈ (B ^ A))
-- The set s can be interpreted as a function with a specified domain.
-- The following describes the relation to the standard notation of functions:
-- • ∀(x∊A)∀y. ((x,y) ∈ S) ⇔ (S(x) = y)
Total : Domain → Domain → Formula
Total(A)(s) = ∀ₛ(A)(x ↦ ∃ₗ(y ↦ (x , y) ∈ s))
Injective' : Domain → Formula
Injective'(f) = ∀ₗ(y ↦ Unique(x ↦ (x , y) ∈ f))
Surjective' : Domain → Domain → Formula
Surjective'(B)(f) = ∀ₛ(B)(y ↦ ∃ₗ(x ↦ (x , y) ∈ f))
Bijective' : Domain → Domain → Formula
Bijective'(B)(f) =
Injective'(f)
∧ Surjective'(B)(f)
-- The set of total function sets. All sets which can be interpreted as a total function.
_^_ : Domain → Domain → Domain
B ^ A = filter(℘(A ⨯ B)) (f ↦ FunctionSet(f) ∧ Total(A)(f))
_→ₛₑₜ_ = swap _^_
⊷ : Domain → Domain
⊷ = lefts
⊶ : Domain → Domain
⊶ = rights
map' : Domain → Domain → Domain
map' = rightsOfMany
unmap' : Domain → Domain → Domain
unmap' = leftsOfMany
apply-set : Domain → Domain → Domain
apply-set = rightsOf
unapply-set : Domain → Domain → Domain
unapply-set = leftsOf
_∘'_ : Domain → Domain → Domain
_∘'_ f g = filter((⊷ f) ⨯ (⊶ g)) (a ↦ ∃ₗ(x ↦ ∃ₗ(y ↦ ∃ₗ(a₁ ↦ ((a₁ , y) ∈ f) ∧ ((x , a₁) ∈ g)) ∧ (a ≡ (x , y)))))
-- inv : Domain → Domain
-- inv f = filter(?) (yx ↦ ∃ₗ(x ↦ ∃ₗ(y ↦ ((x , y) ∈ f) ∧ (yx ≡ (y , x)))))
module Cardinality where
-- Injection
_≼_ : Domain → Domain → Formula
_≼_ (a)(b) = ∃ₛ(a →ₛₑₜ b)(Injective')
-- Surjection
_≽_ : Domain → Domain → Formula
_≽_ (a)(b) = ∃ₛ(a →ₛₑₜ b)(Surjective'(b))
-- Bijection
_≍_ : Domain → Domain → Formula
_≍_ (a)(b) = ∃ₛ(a →ₛₑₜ b)(Bijective'(b))
-- Strict injection
_≺_ : Domain → Domain → Formula
_≺_ A B = (A ≼ B) ∧ ¬(A ≍ B)
-- Strict surjection
_≻_ : Domain → Domain → Formula
_≻_ A B = (A ≽ B) ∧ ¬(A ≍ B)
-- TODO: Definition of a "cardinality object" requires ordinals, which requires axiom of choice
-- # : Domain → Domain
| 35.885057
| 322
| 0.632607
|
298fb4ef2b780c3ed7d9b023dcba25f617d35094
| 7,720
|
agda
|
Agda
|
Cubical/Algebra/Polynomials/Multivariate/EquivCarac/A[X]X-A.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/Polynomials/Multivariate/EquivCarac/A[X]X-A.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Polynomials/Multivariate/EquivCarac/A[X]X-A.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Polynomials.Multivariate.EquivCarac.A[X]X-A where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Vec
open import Cubical.Data.Sigma
open import Cubical.Data.FinData
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.QuotientRing
open import Cubical.Algebra.Polynomials.Multivariate.Base
open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR)
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-notationZ
open import Cubical.Relation.Nullary
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- Functions
module Properties-Equiv-QuotientXn-A
(Ar@(A , Astr) : CommRing ℓ)
where
private
A[X] : CommRing ℓ
A[X] = A[X1,···,Xn] Ar 1
A[x] : Type ℓ
A[x] = A[x1,···,xn] Ar 1
A[X]/X : CommRing ℓ
A[X]/X = A[X1,···,Xn]/<Xkʲ> Ar 1 0 1
A[x]/x : Type ℓ
A[x]/x = A[x1,···,xn]/<xkʲ> Ar 1 0 1
open CommRingStr Astr using ()
renaming
( 0r to 0A
; 1r to 1A
; _+_ to _+A_
; -_ to -A_
; _·_ to _·A_
; +Assoc to +AAssoc
; +Identity to +AIdentity
; +Lid to +ALid
; +Rid to +ARid
; +Inv to +AInv
; +Linv to +ALinv
; +Rinv to +ARinv
; +Comm to +AComm
; ·Assoc to ·AAssoc
; ·Identity to ·AIdentity
; ·Lid to ·ALid
; ·Rid to ·ARid
; ·Rdist+ to ·ARdist+
; ·Ldist+ to ·ALdist+
; is-set to isSetA )
open CommRingStr (snd A[X] ) using ()
renaming
( 0r to 0PA
; 1r to 1PA
; _+_ to _+PA_
; -_ to -PA_
; _·_ to _·PA_
; +Assoc to +PAAssoc
; +Identity to +PAIdentity
; +Lid to +PALid
; +Rid to +PARid
; +Inv to +PAInv
; +Linv to +PALinv
; +Rinv to +PARinv
; +Comm to +PAComm
; ·Assoc to ·PAAssoc
; ·Identity to ·PAIdentity
; ·Lid to ·PALid
; ·Rid to ·PARid
; ·Comm to ·PAComm
; ·Rdist+ to ·PARdist+
; ·Ldist+ to ·PALdist+
; is-set to isSetPA )
open CommRingStr (snd A[X]/X) using ()
renaming
( 0r to 0PAI
; 1r to 1PAI
; _+_ to _+PAI_
; -_ to -PAI_
; _·_ to _·PAI_
; +Assoc to +PAIAssoc
; +Identity to +PAIIdentity
; +Lid to +PAILid
; +Rid to +PAIRid
; +Inv to +PAIInv
; +Linv to +PAILinv
; +Rinv to +PAIRinv
; +Comm to +PAIComm
; ·Assoc to ·PAIAssoc
; ·Identity to ·PAIIdentity
; ·Lid to ·PAILid
; ·Rid to ·PAIRid
; ·Rdist+ to ·PAIRdist+
; ·Ldist+ to ·PAILdist+
; is-set to isSetPAI )
open RingTheory
-----------------------------------------------------------------------------
-- Direct sens
A[x]→A : A[x] → A
A[x]→A = Poly-Rec-Set.f _ _ _ isSetA
0A
base-trad
_+A_
+AAssoc
+ARid
+AComm
base-neutral-eq
base-add-eq
where
base-trad : _
base-trad (zero ∷ []) a = a
base-trad (suc k ∷ []) a = 0A
base-neutral-eq : _
base-neutral-eq (zero ∷ []) = refl
base-neutral-eq (suc k ∷ []) = refl
base-add-eq : _
base-add-eq (zero ∷ []) a b = refl
base-add-eq (suc k ∷ []) a b = +ARid _
A[x]→A-pres1 : A[x]→A 1PA ≡ 1A
A[x]→A-pres1 = refl
A[x]→A-pres+ : (x y : A[x]) → (A[x]→A (x +PA y)) ≡ A[x]→A x +A A[x]→A y
A[x]→A-pres+ x y = refl
A[x]→A-pres· : (x y : A[x]) → (A[x]→A (x ·PA y)) ≡ A[x]→A x ·A A[x]→A y
A[x]→A-pres· = Poly-Ind-Prop.f _ _ _
(λ x u v i y → isSetA _ _ (u y) (v y) i)
(λ y → sym (0LeftAnnihilates (CommRing→Ring Ar) _))
(λ v a → Poly-Ind-Prop.f _ _ _ (λ _ → isSetA _ _)
(sym (0RightAnnihilates (CommRing→Ring Ar) _))
(λ v' a' → base-eq a a' v v')
(λ {U V} ind-U ind-V → cong₂ _+A_ ind-U ind-V ∙ sym (·ARdist+ _ _ _)))
λ {U V} ind-U ind-V y → cong₂ _+A_ (ind-U y) (ind-V y) ∙ sym (·ALdist+ _ _ _)
where
base-eq : (a a' : A) → (v v' : Vec ℕ 1) → (A[x]→A (base v a ·PA base v' a')) ≡ A[x]→A (base v a) ·A A[x]→A (base v' a')
base-eq a a' (zero ∷ []) (zero ∷ []) = refl
base-eq a a' (zero ∷ []) (suc k' ∷ []) = sym (0RightAnnihilates (CommRing→Ring Ar) _)
base-eq a a' (suc k ∷ []) (k' ∷ []) = sym (0LeftAnnihilates (CommRing→Ring Ar) _)
A[X]→A : CommRingHom A[X] Ar
fst A[X]→A = A[x]→A
snd A[X]→A = makeIsRingHom A[x]→A-pres1 A[x]→A-pres+ A[x]→A-pres·
A[x]→A-cancel : (k : Fin 1) → A[x]→A (<Xkʲ> Ar 1 0 1 k) ≡ 0A
A[x]→A-cancel zero = refl
A[X]/X→A : CommRingHom A[X]/X Ar
A[X]/X→A = Quotient-FGideal-CommRing-CommRing.inducedHom A[X] Ar A[X]→A (<Xkʲ> Ar 1 0 1) A[x]→A-cancel
A[x]/x→A : A[x]/x → A
A[x]/x→A = fst A[X]/X→A
-----------------------------------------------------------------------------
-- Converse sens
A→A[x] : A → A[x]
A→A[x] a = base (0 ∷ []) a
A→A[x]-pres+ : (a a' : A) → A→A[x] (a +A a') ≡ A→A[x] a +PA A→A[x] a'
A→A[x]-pres+ a a' = sym (base-poly+ (0 ∷ []) a a')
A→A[x]/x : A → A[x]/x
A→A[x]/x = [_] ∘ A→A[x]
A→A[x]/x-pres+ : (a a' : A) → A→A[x]/x (a +A a') ≡ A→A[x]/x a +PAI A→A[x]/x a'
A→A[x]/x-pres+ a a' = cong [_] (A→A[x]-pres+ a a')
-----------------------------------------------------------------------------
-- Section sens
e-sect : (a : A) → A[x]→A (A→A[x] a) ≡ a
e-sect a = refl
-----------------------------------------------------------------------------
-- Retraction sens
open IsRing
e-retr : (x : A[x]/x) → A→A[x]/x (A[x]/x→A x) ≡ x
e-retr = SQ.elimProp (λ x → isSetPAI _ _)
(Poly-Ind-Prop.f _ _ _ (λ x → isSetPAI _ _)
(cong [_] (base-0P _))
(λ v a → base-eq a v)
λ {U V} ind-U ind-V → cong [_] ((A→A[x]-pres+ _ _)) ∙ cong₂ _+PAI_ ind-U ind-V)
where
base-eq : (a : A) → (v : Vec ℕ 1) → A→A[x]/x (A[x]/x→A [ (base v a) ]) ≡ [ (base v a) ]
base-eq a (zero ∷ []) = cong [_] refl
base-eq a (suc k ∷ []) = eq/ (base (0 ∷ []) 0A) (base (suc k ∷ []) a) ∣ ((λ x → base (k ∷ []) (-A a)) , helper) ∣₁
where
helper : _
helper = cong (λ X → X poly+ base (suc k ∷ []) (-A a)) (base-0P _)
∙ +PALid _
∙ sym (+PARid _
∙ cong₂ base
(cong (λ X → X ∷ []) (+-suc _ _ ∙ +-zero _))
(·ARid _))
module _
(Ar@(A , Astr) : CommRing ℓ)
where
open Iso
open Properties-Equiv-QuotientXn-A Ar
Equiv-A[X]/X-A : CommRingEquiv (A[X1,···,Xn]/<Xkʲ> Ar 1 0 1) Ar
fst Equiv-A[X]/X-A = isoToEquiv is
where
is : Iso (A[x1,···,xn]/<xkʲ> Ar 1 0 1) A
fun is = A[x]/x→A
inv is = A→A[x]/x
rightInv is = e-sect
leftInv is = e-retr
snd Equiv-A[X]/X-A = snd A[X]/X→A
Equiv-ℤ[X]/X-ℤ : RingEquiv (CommRing→Ring ℤ[X]/X) (CommRing→Ring ℤCR)
Equiv-ℤ[X]/X-ℤ = Equiv-A[X]/X-A ℤCR
| 29.922481
| 131
| 0.479793
|
13735595825f6bbfc2b33e6c5a3d6411cb8ca387
| 400
|
agda
|
Agda
|
test/interaction/Issue800.agda
|
hborum/agda
|
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Issue800.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue800.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2013-02-18 problem with 'with'-display, see also issue 295
-- {-# OPTIONS -v tc.with:50 #-}
module Issue800 where
data ⊤ : Set where
tt : ⊤
data I⊤ : ⊤ → Set where
itt : ∀ r → I⊤ r
bug : ∀ l → ∀ k → I⊤ l → ⊤
bug .l k (itt l) with itt k
... | foo = {! foo!}
{-
Current rewriting:
bug .l l (itt k) | itt .k = ?
Desired rewriting:
bug .l k (itt l) | itt .k = ?
-}
| 18.181818
| 70
| 0.52
|
30a657e6267b5945a2f911eece2280e4c071af3e
| 2,624
|
agda
|
Agda
|
Cubical/Data/Fin/Base.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/Data/Fin/Base.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Data/Fin/Base.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Fin.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat using (ℕ; zero; suc)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Sigma
open import Cubical.Data.Sum using (_⊎_; _⊎?_; inl; inr)
open import Cubical.Relation.Nullary
-- Finite types.
--
-- Currently it is most convenient to define these as a subtype of the
-- natural numbers, because indexed inductive definitions don't behave
-- well with cubical Agda. This definition also has some more general
-- attractive properties, of course, such as easy conversion back to
-- ℕ.
Fin : ℕ → Type₀
Fin n = Σ[ k ∈ ℕ ] k < n
private
variable
ℓ : Level
k : ℕ
fzero : Fin (suc k)
fzero = (0 , suc-≤-suc zero-≤)
-- It is easy, using this representation, to take the successor of a
-- number as a number in the next largest finite type.
fsuc : Fin k → Fin (suc k)
fsuc (k , l) = (suc k , suc-≤-suc l)
-- Conversion back to ℕ is trivial...
toℕ : Fin k → ℕ
toℕ = fst
-- ... and injective.
toℕ-injective : ∀{fj fk : Fin k} → toℕ fj ≡ toℕ fk → fj ≡ fk
toℕ-injective {fj = fj} {fk} = Σ≡Prop (λ _ → m≤n-isProp)
-- A case analysis helper for induction.
fsplit
: ∀(fj : Fin (suc k))
→ (fzero ≡ fj) ⊎ (Σ[ fk ∈ Fin k ] fsuc fk ≡ fj)
fsplit (0 , k<sn) = inl (toℕ-injective refl)
fsplit (suc k , k<sn) = inr ((k , pred-≤-pred k<sn) , toℕ-injective refl)
inject< : ∀ {m n} (m<n : m < n) → Fin m → Fin n
inject< m<n (k , k<m) = k , <-trans k<m m<n
-- Fin 0 is empty
¬Fin0 : ¬ Fin 0
¬Fin0 (k , k<0) = ¬-<-zero k<0
-- The full inductive family eliminator for finite types.
elim
: ∀(P : ∀{k} → Fin k → Type ℓ)
→ (∀{k} → P {suc k} fzero)
→ (∀{k} {fn : Fin k} → P fn → P (fsuc fn))
→ {k : ℕ} → (fn : Fin k) → P fn
elim P fz fs {zero} = ⊥.rec ∘ ¬Fin0
elim P fz fs {suc k} fj
= case fsplit fj return (λ _ → P fj) of λ
{ (inl p) → subst P p fz
; (inr (fk , p)) → subst P p (fs (elim P fz fs fk))
}
any? : ∀ {n} {P : Fin n → Type ℓ} → (∀ i → Dec (P i)) → Dec (Σ (Fin n) P)
any? {n = zero} {P = _} P? = no (λ (x , _) → ¬Fin0 x)
any? {n = suc n} {P = P} P? =
mapDec
(λ
{ (inl P0) → fzero , P0
; (inr (x , Px)) → fsuc x , Px
}
)
(λ n h → n (helper h))
(P? fzero ⊎? any? (P? ∘ fsuc))
where
helper : Σ (Fin (suc n)) P → P fzero ⊎ Σ (Fin n) λ z → P (fsuc z)
helper (x , Px) with fsplit x
... | inl x≡0 = inl (subst P (sym x≡0) Px)
... | inr (k , x≡sk) = inr (k , subst P (sym x≡sk) Px)
| 28.835165
| 73
| 0.585747
|
529f9679cdd258b1a93ad7970cdf7859a646f90c
| 1,910
|
agda
|
Agda
|
agda-stdlib/src/Codata/Delay/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Codata/Delay/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Codata/Delay/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on the Delay type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Delay.Properties where
open import Size
import Data.Sum.Base as Sum
open import Codata.Thunk using (Thunk; force)
open import Codata.Conat
open import Codata.Conat.Bisimilarity as Coℕ using (zero ; suc)
open import Codata.Delay
open import Codata.Delay.Bisimilarity
open import Function
open import Relation.Binary.PropositionalEquality as Eq using (_≡_)
module _ {a} {A : Set a} where
length-never : ∀ {i} → i Coℕ.⊢ length (never {A = A}) ≈ infinity
length-never = suc λ where .force → length-never
module _ {a b} {A : Set a} {B : Set b} where
length-map : ∀ (f : A → B) da {i} → i Coℕ.⊢ length (map f da) ≈ length da
length-map f (now a) = zero
length-map f (later da) = suc λ where .force → length-map f (da .force)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
length-zipWith : ∀ (f : A → B → C) da db {i} →
i Coℕ.⊢ length (zipWith f da db) ≈ length da ⊔ length db
length-zipWith f (now a) db = length-map (f a) db
length-zipWith f da@(later _) (now b) = length-map (λ a → f a b) da
length-zipWith f (later da) (later db) =
suc λ where .force → length-zipWith f (da .force) (db .force)
map-map-fusion : ∀ (f : A → B) (g : B → C) da {i} →
i ⊢ map g (map f da) ≈ map (g ∘′ f) da
map-map-fusion f g (now a) = now Eq.refl
map-map-fusion f g (later da) = later λ where .force → map-map-fusion f g (da .force)
map-unfold-fusion : ∀ (f : B → C) n (s : A) {i} →
i ⊢ map f (unfold n s) ≈ unfold (Sum.map id f ∘′ n) s
map-unfold-fusion f n s with n s
... | Sum.inj₁ s′ = later λ where .force → map-unfold-fusion f n s′
... | Sum.inj₂ b = now Eq.refl
| 37.45098
| 86
| 0.57801
|
9a002968f50a0fb6b8bd8f9967ad28646545d03e
| 853
|
agda
|
Agda
|
notes/FOT/FOTC/Relation/Binary/Bisimilarity/Type.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Relation/Binary/Bisimilarity/Type.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Relation/Binary/Bisimilarity/Type.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- A stronger (maybe invalid) principle for ≈-coind
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Relation.Binary.Bisimilarity.Type where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
-- A stronger (maybe invalid) principle for ≈-coind.
postulate
≈-stronger-coind :
∀ (B : D → D → Set) {xs ys} →
(B xs ys → ∃[ x' ] ∃[ xs' ] ∃[ ys' ]
xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys') →
B xs ys → xs ≈ ys
| 35.541667
| 78
| 0.415006
|
a0a77a822f43c297c91b6a5aa411f14a0ea49922
| 6,622
|
agda
|
Agda
|
Structure/Relator/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Relator/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Relator/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Relator.Proofs where
import Data.Either as Either
import Data.Tuple as Tuple
open import Functional
open import Function.Proofs
open import Logic
open import Logic.Propositional.Proofs.Structures
open import Logic.Propositional
open import Logic.Predicate
import Lvl
open import Structure.Function
open import Structure.Operator
open import Structure.Setoid
open import Structure.Relator.Properties
open import Structure.Relator
open import Syntax.Transitivity
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ ℓₗ₄ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ : Lvl.Level
private variable A B A₁ A₂ B₁ B₂ : Type{ℓ}
[≡]-binaryRelator : ∀ ⦃ equiv : Equiv{ℓₗ}(A) ⦄ → BinaryRelator ⦃ equiv ⦄ (_≡_)
BinaryRelator.substitution [≡]-binaryRelator {x₁} {y₁} {x₂} {y₂} xy1 xy2 x1x2 =
y₁ 🝖-[ xy1 ]-sym
x₁ 🝖-[ x1x2 ]
x₂ 🝖-[ xy2 ]
y₂ 🝖-end
reflexive-binaryRelator-sub : ∀ ⦃ equiv : Equiv{ℓₗ}(A) ⦄ {_▫_ : A → A → Type{ℓ}} ⦃ refl : Reflexivity(_▫_) ⦄ ⦃ rel : BinaryRelator ⦃ equiv ⦄ (_▫_) ⦄ → ((_≡_) ⊆₂ (_▫_))
_⊆₂_.proof (reflexive-binaryRelator-sub {_▫_ = _▫_}) xy = substitute₂ᵣ(_▫_) xy (reflexivity(_▫_))
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} ⦃ func : Function(f) ⦄
{P : B → Stmt{ℓₗ₃}} ⦃ rel : UnaryRelator(P) ⦄
where
[∘]-unaryRelator : UnaryRelator(P ∘ f)
[∘]-unaryRelator = [↔]-to-[←] relator-function₁ ([∘]-function ⦃ equiv-c = [↔]-equiv ⦄ ⦃ func-f = [↔]-to-[→] relator-function₁ rel ⦄)
module _
⦃ equiv-A₁ : Equiv{ℓₑ₁}(A₁) ⦄
⦃ equiv-B₁ : Equiv{ℓₑ₂}(B₁) ⦄
⦃ equiv-A₂ : Equiv{ℓₑ₃}(A₂) ⦄
⦃ equiv-B₂ : Equiv{ℓₑ₄}(B₂) ⦄
{f : A₁ → A₂} ⦃ func-f : Function(f) ⦄
{g : B₁ → B₂} ⦃ func-g : Function(g) ⦄
{_▫_ : A₂ → B₂ → Stmt{ℓₗ}} ⦃ rel : BinaryRelator(_▫_) ⦄
where
[∘]-binaryRelator : BinaryRelator(x ↦ y ↦ f(x) ▫ g(y))
BinaryRelator.substitution [∘]-binaryRelator xy1 xy2 = substitute₂(_▫_) (congruence₁(f) xy1) (congruence₁(g) xy2)
module _
⦃ equiv-A : Equiv{ℓₑ}(A) ⦄
{P : A → Stmt{ℓₗ₁}} ⦃ rel-P : UnaryRelator(P) ⦄
{▫ : Stmt{ℓₗ₁} → Stmt{ℓₗ₂}} ⦃ rel : Function ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄ ▫ ⦄
where
unaryRelator-sub : UnaryRelator(▫ ∘ P)
unaryRelator-sub = [∘]-unaryRelator
⦃ equiv-B = [↔]-equiv ⦄
⦃ func = [↔]-to-[→] relator-function₁ rel-P ⦄
⦃ rel = [↔]-to-[←] (relator-function₁ ⦃ [↔]-equiv ⦄) rel ⦄
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{P : A → Stmt{ℓₗ₁}} ⦃ rel-P : UnaryRelator(P) ⦄
{Q : B → Stmt{ℓₗ₂}} ⦃ rel-Q : UnaryRelator(Q) ⦄
{_▫_ : Stmt{ℓₗ₁} → Stmt{ℓₗ₂} → Stmt{ℓₗ₃}} ⦃ rel : BinaryOperator ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄ (_▫_) ⦄
where
binaryRelator-sub : BinaryRelator(x ↦ y ↦ P(x) ▫ Q(y))
binaryRelator-sub = [∘]-binaryRelator
⦃ equiv-A₂ = [↔]-equiv ⦄
⦃ equiv-B₂ = [↔]-equiv ⦄
⦃ func-f = [↔]-to-[→] relator-function₁ rel-P ⦄
⦃ func-g = [↔]-to-[→] relator-function₁ rel-Q ⦄
⦃ rel = [↔]-to-[←] (relator-function₂ ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄) rel ⦄
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{P : A → Stmt{ℓₗ₁}} ⦃ rel-P : UnaryRelator(P) ⦄
{Q : B → Stmt{ℓₗ₂}} ⦃ rel-Q : UnaryRelator(Q) ⦄
where
[→]-binaryRelator : BinaryRelator(x ↦ y ↦ (P(x) → Q(y)))
[→]-binaryRelator = binaryRelator-sub{_▫_ = _→ᶠ_}
[↔]-binaryRelator : BinaryRelator(x ↦ y ↦ (P(x) ↔ Q(y)))
[↔]-binaryRelator = binaryRelator-sub{_▫_ = _↔_}
[→]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : A → Stmt{ℓₗ₁}}{Q : A → Stmt{ℓₗ₂}} → ⦃ rel-P : UnaryRelator(P) ⦄ → ⦃ rel-Q : UnaryRelator(Q) ⦄ → UnaryRelator(\x → P(x) → Q(x))
UnaryRelator.substitution ([→]-unaryRelator {P = P}{Q = Q}) xy pxqx py = substitute₁(Q) xy (pxqx(substitute₁(P) (symmetry(_≡_) xy) py))
[∀]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : B → A → Stmt{ℓₗ₁}} → ⦃ rel-P : ∀{x} → UnaryRelator(P(x)) ⦄ → UnaryRelator(\y → ∀{x} → P(x)(y))
UnaryRelator.substitution ([∀]-unaryRelator {P = P}) {x} {a} xy px {b} = substitute₁ (P b) xy px
[∃]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : B → A → Stmt{ℓₗ₁}} → ⦃ rel-P : ∀{x} → UnaryRelator(P(x)) ⦄ → UnaryRelator(\y → ∃(x ↦ P(x)(y)))
UnaryRelator.substitution ([∃]-unaryRelator {P = P}) xy = [∃]-map-proof (substitute₁(P _) xy)
instance
const-unaryRelator : ∀{P : Stmt{ℓₗ₁}} → ⦃ _ : Equiv{ℓₗ}(A) ⦄ → UnaryRelator{A = A}(const P)
UnaryRelator.substitution const-unaryRelator = const id
[¬]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ {P : A → Stmt{ℓₗ₁}} → ⦃ rel-P : UnaryRelator(P) ⦄ → UnaryRelator(\x → ¬ P(x))
[¬]-unaryRelator {P = P} = [→]-unaryRelator
[∧]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : A → Stmt{ℓₗ₁}}{Q : A → Stmt{ℓₗ₂}} → ⦃ rel-P : UnaryRelator(P) ⦄ → ⦃ rel-Q : UnaryRelator(Q) ⦄ → UnaryRelator(x ↦ P(x) ∧ Q(x))
UnaryRelator.substitution [∧]-unaryRelator xy = Tuple.map (substitute₁(_) xy) (substitute₁(_) xy)
[∨]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : A → Stmt{ℓₗ₁}}{Q : A → Stmt{ℓₗ₂}} → ⦃ rel-P : UnaryRelator(P) ⦄ → ⦃ rel-Q : UnaryRelator(Q) ⦄ → UnaryRelator(x ↦ P(x) ∨ Q(x))
UnaryRelator.substitution [∨]-unaryRelator xy = Either.map (substitute₁(_) xy) (substitute₁(_) xy)
binary-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ {P : A → A → Stmt{ℓₗ₁}} → ⦃ rel-P : BinaryRelator(P) ⦄ → UnaryRelator(P $₂_)
UnaryRelator.substitution (binary-unaryRelator {P = P}) xy pxx = substitute₂(P) xy xy pxx
binary-unaryRelatorₗ : ∀ ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ {_▫_ : A → B → Stmt{ℓₗ₃}} → ⦃ rel-P : BinaryRelator(_▫_) ⦄ → ∀{x} → UnaryRelator(x ▫_)
UnaryRelator.substitution binary-unaryRelatorₗ xy x1x2 = substitute₂ _ (reflexivity(_≡_)) xy x1x2
binary-unaryRelatorᵣ : ∀ ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ {_▫_ : A → B → Stmt{ℓₗ₃}} → ⦃ rel-P : BinaryRelator(_▫_) ⦄ → ∀{x} → UnaryRelator(_▫ x)
UnaryRelator.substitution binary-unaryRelatorᵣ xy x1x2 = substitute₂ _ xy (reflexivity(_≡_)) x1x2
binaryRelator-from-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ {_▫_ : A → A → Stmt{ℓₗ₁}} → ⦃ relₗ : ∀{x} → UnaryRelator(_▫ x) ⦄ → ⦃ relᵣ : ∀{x} → UnaryRelator(x ▫_) ⦄ → BinaryRelator(_▫_)
BinaryRelator.substitution binaryRelator-from-unaryRelator xy1 xy2 = substitute₁ _ xy1 ∘ substitute₁ _ xy2
instance
const-binaryRelator : ∀{P : Stmt{ℓₗ}} → ⦃ equiv-A : Equiv{ℓₗ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₗ₂}(B) ⦄ → BinaryRelator{A = A}{B = B}((const ∘ const) P)
BinaryRelator.substitution const-binaryRelator = (const ∘ const) id
-- TODO: Temporary until substitution is a specialization of congruence
[¬]-binaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ ⦃ _ : Equiv{ℓₗ₃}(B) ⦄ {P : A → B → Stmt{ℓₗ₁}} → ⦃ rel-P : BinaryRelator(P) ⦄ → BinaryRelator(\x y → ¬ P(x)(y))
BinaryRelator.substitution ([¬]-binaryRelator {P = P}) xy₁ xy₂ npx py = npx(substitute₂(P) (symmetry(_≡_) xy₁) (symmetry(_≡_) xy₂) py)
| 47.985507
| 182
| 0.60752
|
38c3919c242189b4a5dce1ca6bde8eabbfffb444
| 13,970
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Algebra/Structures.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Algebra/Structures.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Algebra/Structures.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some algebraic structures (not packed up with sets, operations,
-- etc.)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
-- The structures are parameterised by an equivalence relation
module Algebra.Structures {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Algebra.FunctionProperties _≈_
import Algebra.FunctionProperties.Consequences as Consequences
open import Data.Product using (_,_; proj₁; proj₂)
open import Level using (_⊔_)
------------------------------------------------------------------------
-- Semigroups
record IsMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
∙-cong : Congruent₂ ∙
open IsEquivalence isEquivalence public
setoid : Setoid a ℓ
setoid = record { isEquivalence = isEquivalence }
∙-congˡ : LeftCongruent ∙
∙-congˡ y≈z = ∙-cong refl y≈z
∙-congʳ : RightCongruent ∙
∙-congʳ y≈z = ∙-cong y≈z refl
record IsSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isMagma : IsMagma ∙
assoc : Associative ∙
open IsMagma isMagma public
record IsBand (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
idem : Idempotent ∙
open IsSemigroup isSemigroup public
record IsSemilattice (∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isBand : IsBand ∧
comm : Commutative ∧
open IsBand isBand public
renaming (∙-cong to ∧-cong; ∙-congˡ to ∧-congˡ; ∙-congʳ to ∧-congʳ)
------------------------------------------------------------------------
-- Monoids
record IsMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identity : Identity ε ∙
open IsSemigroup isSemigroup public
identityˡ : LeftIdentity ε ∙
identityˡ = proj₁ identity
identityʳ : RightIdentity ε ∙
identityʳ = proj₂ identity
record IsCommutativeMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identityˡ : LeftIdentity ε ∙
comm : Commutative ∙
open IsSemigroup isSemigroup public
identityʳ : RightIdentity ε ∙
identityʳ = Consequences.comm+idˡ⇒idʳ setoid comm identityˡ
identity : Identity ε ∙
identity = (identityˡ , identityʳ)
isMonoid : IsMonoid ∙ ε
isMonoid = record
{ isSemigroup = isSemigroup
; identity = identity
}
record IsIdempotentCommutativeMonoid (∙ : Op₂ A)
(ε : A) : Set (a ⊔ ℓ) where
field
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
idem : Idempotent ∙
open IsCommutativeMonoid isCommutativeMonoid public
------------------------------------------------------------------------
-- Groups
record IsGroup (_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where
field
isMonoid : IsMonoid _∙_ ε
inverse : Inverse ε _⁻¹ _∙_
⁻¹-cong : Congruent₁ _⁻¹
open IsMonoid isMonoid public
infixl 7 _-_
_-_ : Op₂ A
x - y = x ∙ (y ⁻¹)
inverseˡ : LeftInverse ε _⁻¹ _∙_
inverseˡ = proj₁ inverse
inverseʳ : RightInverse ε _⁻¹ _∙_
inverseʳ = proj₂ inverse
uniqueˡ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → x ≈ (y ⁻¹)
uniqueˡ-⁻¹ = Consequences.assoc+id+invʳ⇒invˡ-unique
setoid ∙-cong assoc identity inverseʳ
uniqueʳ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → y ≈ (x ⁻¹)
uniqueʳ-⁻¹ = Consequences.assoc+id+invˡ⇒invʳ-unique
setoid ∙-cong assoc identity inverseˡ
record IsAbelianGroup (∙ : Op₂ A)
(ε : A) (⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where
field
isGroup : IsGroup ∙ ε ⁻¹
comm : Commutative ∙
open IsGroup isGroup public
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isSemigroup = isSemigroup
; identityˡ = identityˡ
; comm = comm
}
------------------------------------------------------------------------
-- Semirings
record IsNearSemiring (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isMonoid : IsMonoid + 0#
*-isSemigroup : IsSemigroup *
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
open IsMonoid +-isMonoid public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
)
open IsSemigroup *-isSemigroup public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; isMagma to *-isMagma
)
record IsSemiringWithoutOne (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isSemigroup : IsSemigroup *
distrib : * DistributesOver +
zero : Zero 0# *
open IsCommutativeMonoid +-isCommutativeMonoid public
using ()
renaming
( isMonoid to +-isMonoid
; comm to +-comm
)
zeroˡ : LeftZero 0# *
zeroˡ = proj₁ zero
zeroʳ : RightZero 0# *
zeroʳ = proj₂ zero
isNearSemiring : IsNearSemiring + * 0#
isNearSemiring = record
{ +-isMonoid = +-isMonoid
; *-isSemigroup = *-isSemigroup
; distribʳ = proj₂ distrib
; zeroˡ = zeroˡ
}
open IsNearSemiring isNearSemiring public
hiding (+-isMonoid; zeroˡ)
record IsSemiringWithoutAnnihilatingZero (+ * : Op₂ A)
(0# 1# : A) : Set (a ⊔ ℓ) where
field
-- Note that these structures do have an additive unit, but this
-- unit does not necessarily annihilate multiplication.
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
distribˡ : * DistributesOverˡ +
distribˡ = proj₁ distrib
distribʳ : * DistributesOverʳ +
distribʳ = proj₂ distrib
open IsCommutativeMonoid +-isCommutativeMonoid public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
record IsSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isSemiringWithoutAnnihilatingZero :
IsSemiringWithoutAnnihilatingZero + * 0# 1#
zero : Zero 0# *
open IsSemiringWithoutAnnihilatingZero
isSemiringWithoutAnnihilatingZero public
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
isSemiringWithoutOne = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isSemigroup = *-isSemigroup
; distrib = distrib
; zero = zero
}
open IsSemiringWithoutOne isSemiringWithoutOne public
using
( isNearSemiring
; zeroˡ
; zeroʳ
)
record IsCommutativeSemiringWithoutOne
(+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
*-comm : Commutative *
open IsSemiringWithoutOne isSemiringWithoutOne public
record IsCommutativeSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
private
module +-CM = IsCommutativeMonoid +-isCommutativeMonoid
open module *-CM = IsCommutativeMonoid *-isCommutativeMonoid public
using () renaming (comm to *-comm)
distribˡ : * DistributesOverˡ +
distribˡ = Consequences.comm+distrʳ⇒distrˡ
+-CM.setoid +-CM.∙-cong *-comm distribʳ
distrib : * DistributesOver +
distrib = (distribˡ , distribʳ)
zeroʳ : RightZero 0# *
zeroʳ = Consequences.comm+zeˡ⇒zeʳ +-CM.setoid *-comm zeroˡ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isSemiring : IsSemiring + * 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-CM.isMonoid
; distrib = distrib
}
; zero = zero
}
open IsSemiring isSemiring public
hiding
( distrib; distribʳ; distribˡ
; zero; zeroˡ; zeroʳ
; +-isCommutativeMonoid
)
isCommutativeSemiringWithoutOne :
IsCommutativeSemiringWithoutOne + * 0#
isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = isSemiringWithoutOne
; *-comm = *-CM.comm
}
------------------------------------------------------------------------
-- Rings
record IsRing (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isAbelianGroup : IsAbelianGroup + 0# -_
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
open IsAbelianGroup +-isAbelianGroup public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; inverse to -‿inverse
; inverseˡ to -‿inverseˡ
; inverseʳ to -‿inverseʳ
; ⁻¹-cong to -‿cong
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isCommutativeMonoid to +-isCommutativeMonoid
; isGroup to +-isGroup
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
zeroˡ : LeftZero 0# *
zeroˡ = Consequences.assoc+distribʳ+idʳ+invʳ⇒zeˡ setoid
+-cong *-cong +-assoc (proj₂ distrib) +-identityʳ -‿inverseʳ
zeroʳ : RightZero 0# *
zeroʳ = Consequences.assoc+distribˡ+idʳ+invʳ⇒zeʳ setoid
+-cong *-cong +-assoc (proj₁ distrib) +-identityʳ -‿inverseʳ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isSemiringWithoutAnnihilatingZero
: IsSemiringWithoutAnnihilatingZero + * 0# 1#
isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-isMonoid
; distrib = distrib
}
isSemiring : IsSemiring + * 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero =
isSemiringWithoutAnnihilatingZero
; zero = zero
}
open IsSemiring isSemiring public
using (distribˡ; distribʳ; isNearSemiring; isSemiringWithoutOne)
record IsCommutativeRing
(+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isRing : IsRing + * - 0# 1#
*-comm : Commutative *
open IsRing isRing public
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
*-isCommutativeMonoid = record
{ isSemigroup = *-isSemigroup
; identityˡ = *-identityˡ
; comm = *-comm
}
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isCommutativeMonoid = *-isCommutativeMonoid
; distribʳ = distribʳ
; zeroˡ = zeroˡ
}
open IsCommutativeSemiring isCommutativeSemiring public
using ( isCommutativeSemiringWithoutOne )
------------------------------------------------------------------------
-- Lattices
-- Note that this record is not defined in terms of IsSemilattice
-- because the idempotence laws of ∨ and ∧ can be derived from the
-- absorption laws, which makes the corresponding "idem" fields
-- redundant. The derived idempotence laws are stated and proved in
-- Algebra.Properties.Lattice along with the fact that every lattice
-- consists of two semilattices.
record IsLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
∨-comm : Commutative ∨
∨-assoc : Associative ∨
∨-cong : Congruent₂ ∨
∧-comm : Commutative ∧
∧-assoc : Associative ∧
∧-cong : Congruent₂ ∧
absorptive : Absorptive ∨ ∧
open IsEquivalence isEquivalence public
∨-absorbs-∧ : ∨ Absorbs ∧
∨-absorbs-∧ = proj₁ absorptive
∧-absorbs-∨ : ∧ Absorbs ∨
∧-absorbs-∨ = proj₂ absorptive
∧-congˡ : LeftCongruent ∧
∧-congˡ y≈z = ∧-cong refl y≈z
∧-congʳ : RightCongruent ∧
∧-congʳ y≈z = ∧-cong y≈z refl
∨-congˡ : LeftCongruent ∨
∨-congˡ y≈z = ∨-cong refl y≈z
∨-congʳ : RightCongruent ∨
∨-congʳ y≈z = ∨-cong y≈z refl
record IsDistributiveLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isLattice : IsLattice ∨ ∧
∨-∧-distribʳ : ∨ DistributesOverʳ ∧
open IsLattice isLattice public
record IsBooleanAlgebra
(∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ) where
field
isDistributiveLattice : IsDistributiveLattice ∨ ∧
∨-complementʳ : RightInverse ⊤ ¬ ∨
∧-complementʳ : RightInverse ⊥ ¬ ∧
¬-cong : Congruent₁ ¬
open IsDistributiveLattice isDistributiveLattice public
| 28.222222
| 74
| 0.579599
|
2e714243fd3fc13c6d03b09a1d4a0a25dc89bc3c
| 1,157
|
agda
|
Agda
|
Categories/Monoidal/Braided.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 1
|
2018-12-29T21:51:57.000Z
|
2018-12-29T21:51:57.000Z
|
Categories/Monoidal/Braided.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | null | null | null |
Categories/Monoidal/Braided.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Monoidal.Braided where
open import Level
open import Level using (_⊔_)
open import Categories.Category
open import Categories.Bifunctor using (Bifunctor)
open import Categories.NaturalIsomorphism
open import Categories.NaturalTransformation using (_∘₁_) renaming (_≡_ to _≡ⁿ_)
open import Categories.Monoidal.Helpers
open import Categories.Monoidal.Braided.Helpers
open import Categories.Monoidal
record Braided {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) : Set (o ⊔ ℓ ⊔ e) where
private module C = Category C
private module M = Monoidal M
open C hiding (id; identityˡ; identityʳ; assoc)
open M
open MonoidalHelperFunctors C ⊗ id
open BraidedHelperFunctors C ⊗ id
field
braid : NaturalIsomorphism x⊗y y⊗x
open Braiding identityˡ identityʳ assoc braid
field
-- NB: Triangle is redundant, proof coming soon...
.hexagon₁ : (Hexagon1SideB ∘₁ (Hexagon1TopB ∘₁ Hexagon1TopA)) ≡ⁿ (Hexagon1BottomB ∘₁ (Hexagon1BottomA ∘₁ Hexagon1SideA))
.hexagon₂ : (Hexagon2SideB ∘₁ (Hexagon2TopB ∘₁ Hexagon2TopA)) ≡ⁿ (Hexagon2BottomB ∘₁ (Hexagon2BottomA ∘₁ Hexagon2SideA))
| 33.057143
| 124
| 0.751945
|
52424fd906612fc38f54e7623ef6b9b4cce06ad7
| 138
|
agda
|
Agda
|
src/higher/circle.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 20
|
2015-06-12T12:20:17.000Z
|
2022-02-01T11:25:54.000Z
|
src/higher/circle.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
src/higher/circle.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T12:17:00.000Z
|
2019-05-04T19:31:00.000Z
|
{-# OPTIONS --without-K #-}
module higher.circle where
open import higher.circle.core public
open import higher.circle.properties public
| 23
| 43
| 0.782609
|
1afaeabbcc979a323e7e8eedaf0648c48c157833
| 355
|
agda
|
Agda
|
src/rtn.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 328
|
2018-09-14T20:06:09.000Z
|
2022-03-26T10:33:07.000Z
|
src/rtn.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 123
|
2018-09-17T10:53:20.000Z
|
2022-01-12T03:51:28.000Z
|
src/rtn.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 34
|
2018-09-17T11:51:36.000Z
|
2022-02-20T18:33:16.000Z
|
open import ial
module rtn (gratr2-nt : Set) where
gratr2-rule : Set
gratr2-rule = maybe string × maybe string × maybe gratr2-nt × 𝕃 (gratr2-nt ⊎ char)
record gratr2-rtn : Set where
field
start : gratr2-nt
_eq_ : gratr2-nt → gratr2-nt → 𝔹
gratr2-start : gratr2-nt → 𝕃 gratr2-rule
gratr2-return : maybe gratr2-nt → 𝕃 gratr2-rule
| 25.357143
| 83
| 0.667606
|
8bb35e8d0dbcdb57e8a62304811ae37afa3b0756
| 7,653
|
agda
|
Agda
|
core/lib/NType2.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/NType2.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/NType2.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.Equivalence2
open import lib.Relation2
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.TLevel
module lib.NType2 where
module _ {i} {A : Type i} where
abstract
has-dec-onesided-eq-is-prop : {x : A} → is-prop (has-dec-onesided-eq x)
has-dec-onesided-eq-is-prop {x = x} = inhab-to-prop-is-prop λ dec →
Π-is-prop λ y → Dec-level (dec-onesided-eq-is-prop x dec y)
has-dec-eq-is-prop : is-prop (has-dec-eq A)
has-dec-eq-is-prop = Π-is-prop λ _ → has-dec-onesided-eq-is-prop
module _ {i j} {A : Type i} {B : A → Type j} where
abstract
↓-level : {a b : A} {p : a == b} {u : B a} {v : B b} {n : ℕ₋₂}
→ has-level (S n) (B b) → has-level n (u == v [ B ↓ p ])
↓-level {p = idp} k = k _ _
↓-preserves-level : {a b : A} {p : a == b} {u : B a} {v : B b} {n : ℕ₋₂}
→ has-level n (B b) → has-level n (u == v [ B ↓ p ])
↓-preserves-level {p = idp} = =-preserves-level
↓-preserves-set : {a b : A} {p : a == b} {u : B a} {v : B b}
→ has-level 0 (B b) → has-level 0 (u == v [ B ↓ p ])
↓-preserves-set = ↓-preserves-level
prop-has-all-paths-↓ : {x y : A} {p : x == y} {u : B x} {v : B y}
→ (is-prop (B y) → u == v [ B ↓ p ])
prop-has-all-paths-↓ {p = idp} k = prop-has-all-paths k _ _
set-↓-has-all-paths-↓ : ∀ {k} {C : Type k}
{x y : C → A} {p : (t : C) → x t == y t} {u : (t : C) → B (x t)} {v : (t : C) → B (y t)}
{a b : C} {q : a == b} {α : u a == v a [ B ↓ p a ]} {β : u b == v b [ B ↓ p b ]}
→ (is-set (B (y a)) → α == β [ (λ t → u t == v t [ B ↓ p t ]) ↓ q ])
set-↓-has-all-paths-↓ {q = idp} = lemma _
where
lemma : {x y : A} (p : x == y) {u : B x} {v : B y} {α β : u == v [ B ↓ p ]}
→ is-set (B y) → α == β
lemma idp k = fst (k _ _ _ _)
abstract
-- Every map between contractible types is an equivalence
contr-to-contr-is-equiv : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
→ (is-contr A → is-contr B → is-equiv f)
contr-to-contr-is-equiv f cA cB =
is-eq f (λ _ → fst cA) (λ b → ! (snd cB _) ∙ snd cB b) (snd cA)
is-contr-is-prop : ∀ {i} {A : Type i} → is-prop (is-contr A)
is-contr-is-prop {A = A} = all-paths-is-prop (λ x y →
pair= (snd x (fst y))
(↓-Π-cst-app-in (λ a → ↓-idf=cst-in' (lemma x (fst y) a (snd y a))))) where
lemma : (x : is-contr A) (b a : A) (p : b == a)
→ snd x a == snd x b ∙' p
lemma x b ._ idp = idp
has-level-is-prop : ∀ {i} {n : ℕ₋₂} {A : Type i}
→ is-prop (has-level n A)
has-level-is-prop {n = ⟨-2⟩} = is-contr-is-prop
has-level-is-prop {n = S n} =
Π-level (λ x → Π-level (λ y → has-level-is-prop))
is-prop-is-prop : ∀ {i} {A : Type i} → is-prop (is-prop A)
is-prop-is-prop = has-level-is-prop
is-set-is-prop : ∀ {i} {A : Type i} → is-prop (is-set A)
is-set-is-prop = has-level-is-prop
{- Subtypes. -}
module _ {i j} {A : Type i} (P : SubtypeProp A j) where
private
module P = SubtypeProp P
Subtype-level : ∀ {n : ℕ₋₂}
→ has-level (S n) A
→ has-level (S n) (Subtype P)
Subtype-level p = Σ-level p (λ x → prop-has-level-S (P.level x))
Subtype= : (x y : Subtype P) → Type i
Subtype= x y = fst x == fst y
Subtype=-out : ∀ {x y : Subtype P} → Subtype= x y → x == y
Subtype=-out p = pair= p (prop-has-all-paths-↓ (P.level _))
Subtype=-β : {x y : Subtype P} (p : Subtype= x y)
→ fst= (Subtype=-out {x = x} {y = y} p) == p
Subtype=-β idp = fst=-β idp _
Subtype=-η : {x y : Subtype P} (p : x == y)
→ Subtype=-out (fst= p) == p
Subtype=-η idp = ap (pair= idp)
(contr-has-all-paths (P.level _ _ _) _ _)
Subtype=-econv : (x y : Subtype P) → (Subtype= x y) ≃ (x == y)
Subtype=-econv x y = equiv Subtype=-out fst= Subtype=-η Subtype=-β
abstract
Subtype-∙ : ∀ {x y z : Subtype P}
(p : Subtype= x y) (q : Subtype= y z)
→ (Subtype=-out {x} {y} p ∙ Subtype=-out {y} {z} q)
== Subtype=-out {x} {z} (p ∙ q)
Subtype-∙ {x} {y} {z} p q =
Subtype=-out p ∙ Subtype=-out q
=⟨ Σ-∙ {p = p} {p' = q} (prop-has-all-paths-↓ (P.level (fst y))) (prop-has-all-paths-↓ (P.level (fst z))) ⟩
pair= (p ∙ q) (prop-has-all-paths-↓ {p = p} (P.level (fst y)) ∙ᵈ prop-has-all-paths-↓ (P.level (fst z)))
=⟨ contr-has-all-paths (↓-level (P.level (fst z))) _ (prop-has-all-paths-↓ (P.level (fst z)))
|in-ctx pair= (p ∙ q) ⟩
Subtype=-out (p ∙ q)
=∎
-- Groupoids
is-gpd : {i : ULevel} → Type i → Type i
is-gpd = has-level 1
-- Type of all n-truncated types
has-level-prop : ∀ {i} → ℕ₋₂ → SubtypeProp (Type i) i
has-level-prop n = has-level n , λ _ → has-level-is-prop
_-Type_ : (n : ℕ₋₂) (i : ULevel) → Type (lsucc i)
n -Type i = Subtype (has-level-prop {i} n)
hProp : (i : ULevel) → Type (lsucc i)
hProp i = -1 -Type i
hSet : (i : ULevel) → Type (lsucc i)
hSet i = 0 -Type i
_-Type₀ : (n : ℕ₋₂) → Type₁
n -Type₀ = n -Type lzero
hProp₀ = hProp lzero
hSet₀ = hSet lzero
-- [n -Type] is an (n+1)-type
abstract
≃-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j}
→ (has-level n A → has-level n B → has-level n (A ≃ B))
≃-level {n = ⟨-2⟩} pA pB =
((cst (fst pB) , contr-to-contr-is-equiv _ pA pB)
, (λ e → pair= (λ= (λ _ → snd pB _))
(from-transp is-equiv _ (fst (is-equiv-is-prop _ _)))))
≃-level {n = S n} pA pB =
Σ-level (→-level pB) (λ _ → prop-has-level-S is-equiv-is-prop)
≃-is-set : ∀ {i j} {A : Type i} {B : Type j}
→ is-set A → is-set B → is-set (A ≃ B)
≃-is-set = ≃-level
universe-=-level : ∀ {i} {n : ℕ₋₂} {A B : Type i}
→ (has-level n A → has-level n B → has-level n (A == B))
universe-=-level pA pB = equiv-preserves-level ua-equiv (≃-level pA pB)
universe-=-is-set : ∀ {i} {A B : Type i}
→ (is-set A → is-set B → is-set (A == B))
universe-=-is-set = universe-=-level
module _ {i} {n} where
private
prop : SubtypeProp {lsucc i} (Type i) i
prop = has-level-prop n
nType= : (A B : n -Type i) → Type (lsucc i)
nType= = Subtype= prop
nType=-out : {A B : n -Type i} → nType= A B → A == B
nType=-out = Subtype=-out prop
abstract
nType=-β : {A B : n -Type i} (p : nType= A B)
→ fst= (nType=-out {A = A} {B = B} p) == p
nType=-β = Subtype=-β prop
nType=-η : {A B : n -Type i} (p : A == B)
→ nType=-out (fst= p) == p
nType=-η = Subtype=-η prop
nType=-econv : (A B : n -Type i) → (nType= A B) ≃ (A == B)
nType=-econv = Subtype=-econv prop
nType-∙ : {A B C : n -Type i}
(p : nType= A B) (q : nType= B C)
→ (nType=-out {A = A} p ∙ nType=-out {A = B} q)
== nType=-out {A = A} {B = C} (p ∙ q)
nType-∙ = Subtype-∙ prop
abstract
_-Type-level_ : (n : ℕ₋₂) (i : ULevel)
→ has-level (S n) (n -Type i)
(n -Type-level i) A B =
equiv-preserves-level (nType=-econv A B)
(universe-=-level (snd A) (snd B))
hProp-is-set : (i : ULevel) → is-set (hProp i)
hProp-is-set i = -1 -Type-level i
hSet-level : (i : ULevel) → has-level 1 (hSet i)
hSet-level i = 0 -Type-level i
{- The following two lemmas are in NType2 instead of NType because of cyclic
dependencies -}
module _ {i} {A : Type i} where
abstract
raise-level-<T : {m n : ℕ₋₂} → (m <T n) → has-level m A → has-level n A
raise-level-<T ltS = raise-level _
raise-level-<T (ltSR lt) = raise-level _ ∘ raise-level-<T lt
raise-level-≤T : {m n : ℕ₋₂} → (m ≤T n) → has-level m A → has-level n A
raise-level-≤T (inl p) = transport (λ t → has-level t A) p
raise-level-≤T (inr lt) = raise-level-<T lt
| 34.013333
| 115
| 0.519404
|
a0d1a92542f481b9b47bf5895efe094dbb23a051
| 827
|
agda
|
Agda
|
test/api/Issue1168.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/api/Issue1168.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/api/Issue1168.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
-- {-# OPTIONS -v 20 #-}
-- {-# OPTIONS -v tc.polarity:30 #-}
-- {-# OPTIONS -v tc.decl:30 #-}
-- {-# OPTIONS -v tc.term:30 #-}
-- {-# OPTIONS -v tc.conv.coerce:20 #-}
-- {-# OPTIONS -v tc.signature:30 #-}
-- {-# OPTIONS -v import.iface:100 #-}
module Issue1168 where
open import Agda.Primitive
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
id : ∀{a} {A : Set a} → A → A
id {A = A} a = a
id2 : ∀{A : id Set} → id A → A
id2 x = x
plus0 : ∀ x → x + 0 ≡ x
plus0 zero = refl
plus0 (suc x) rewrite plus0 x = refl
Identity : ∀{a} {A : Set a} (f : A → A) → Set a
Identity f = ∀ x → f x ≡ x
plus-0 : Identity (_+ 0)
plus-0 = plus0
my-Fun : ∀{a b} (A : Set a) (F : A → Set b) → Set (a ⊔ b)
my-Fun A F = (x : A) → F x
syntax my-Fun A (λ x → B) = [ x ∷ A ]=> B
my-id : [ A ∷ Set ]=> [ x ∷ A ]=> A
my-id A x = x
| 21.763158
| 57
| 0.524788
|
043a388613eb1afe6150280f9ffe73ef73487bec
| 1,340
|
agda
|
Agda
|
src/LibraBFT/Impl/OBM/Util.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/OBM/Util.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/OBM/Util.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochIndep
open import Util.Prelude
module LibraBFT.Impl.OBM.Util where
-- To tolerate f failures, cluster must contain at least n ≥ 3f + 1 nodes,
-- where n − f nodes form a quorum, assuming 1 vote per node.
-- Note: our Haskell implementation and our model of it support non-uniform voting power,
-- that is NOT reflected in these functions, but is reflected in functions in ValidatorVerifier.
numNodesNeededForNFailures : U64 -> U64
numNodesNeededForNFailures numFaultsAllowed = 3 * numFaultsAllowed + 1
checkBftAndRun : ∀ {names : Set} {b : Set}
→ U64 → List names → (U64 → List names → b)
→ Either ErrLog b
checkBftAndRun numFailures authors f =
if-dec length authors <? numNodesNeededForNFailures numFailures
then Left fakeErr --(ErrL [ "checkBftAndRun: not enough authors for given number of failures"
-- , show numFailures, show (length authors) ])
else pure (f numFailures authors)
| 44.666667
| 111
| 0.73806
|
d155cd11101f76197bb4c72c3a7a153ad3f18768
| 785
|
agda
|
Agda
|
src/Lambda/Simplified/Delay-monad/Virtual-machine.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | 2
|
2020-05-21T22:59:18.000Z
|
2020-07-03T08:56:08.000Z
|
src/Lambda/Simplified/Delay-monad/Virtual-machine.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
src/Lambda/Simplified/Delay-monad/Virtual-machine.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A virtual machine
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Lambda.Simplified.Delay-monad.Virtual-machine where
open import Equality.Propositional
open import Prelude
open import Monad equality-with-J
open import Delay-monad
open import Delay-monad.Monad
open import Lambda.Simplified.Delay-monad.Interpreter
open import Lambda.Simplified.Syntax
open import Lambda.Simplified.Virtual-machine
open Closure Code
-- A functional semantics for the VM.
exec : ∀ {i} → State → Delay (Maybe Value) i
exec s with step s
... | continue s′ = later λ { .force → exec s′ }
... | done v = return (just v)
... | crash = return nothing
| 26.166667
| 72
| 0.592357
|
41016caf5a662e986166cce8b41908617ff86398
| 404
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Vec/All/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Vec/All/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Vec/All/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- 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
| 31.076923
| 72
| 0.477723
|
1abc1eda74d2cb0808d4d7bc2cc3c525e770f867
| 3,871
|
agda
|
Agda
|
prototyping/Luau/TypeCheck.agda
|
Libertus-Lab/luau
|
f1b46f4b967f11fabe666da1de0e71b225368260
|
[
"MIT"
] | 1
|
2021-11-06T08:03:00.000Z
|
2021-11-06T08:03:00.000Z
|
prototyping/Luau/TypeCheck.agda
|
sthagen/Roblox-luau
|
39fbd2146a379fb0878369b48764cd7e8772c0fb
|
[
"MIT"
] | null | null | null |
prototyping/Luau/TypeCheck.agda
|
sthagen/Roblox-luau
|
39fbd2146a379fb0878369b48764cd7e8772c0fb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Luau.TypeCheck where
open import Agda.Builtin.Equality using (_≡_)
open import FFI.Data.Either using (Either; Left; Right)
open import FFI.Data.Maybe using (Maybe; just)
open import Luau.ResolveOverloads using (resolve)
open import Luau.Syntax using (Expr; Stat; Block; BinaryOperator; yes; nil; addr; number; bool; string; val; var; var_∈_; _⟨_⟩∈_; function_is_end; _$_; block_is_end; binexp; local_←_; _∙_; done; return; name; +; -; *; /; <; >; ==; ~=; <=; >=; ··)
open import Luau.Var using (Var)
open import Luau.Addr using (Addr)
open import Luau.Heap using (Heap; Object; function_is_end) renaming (_[_] to _[_]ᴴ)
open import Luau.Type using (Type; nil; unknown; number; boolean; string; _⇒_)
open import Luau.VarCtxt using (VarCtxt; ∅; _⋒_; _↦_; _⊕_↦_; _⊝_) renaming (_[_] to _[_]ⱽ)
open import FFI.Data.Vector using (Vector)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import Properties.DecSubtyping using (dec-subtyping)
open import Properties.Product using (_×_; _,_)
orUnknown : Maybe Type → Type
orUnknown nothing = unknown
orUnknown (just T) = T
srcBinOp : BinaryOperator → Type
srcBinOp + = number
srcBinOp - = number
srcBinOp * = number
srcBinOp / = number
srcBinOp < = number
srcBinOp > = number
srcBinOp == = unknown
srcBinOp ~= = unknown
srcBinOp <= = number
srcBinOp >= = number
srcBinOp ·· = string
tgtBinOp : BinaryOperator → Type
tgtBinOp + = number
tgtBinOp - = number
tgtBinOp * = number
tgtBinOp / = number
tgtBinOp < = boolean
tgtBinOp > = boolean
tgtBinOp == = boolean
tgtBinOp ~= = boolean
tgtBinOp <= = boolean
tgtBinOp >= = boolean
tgtBinOp ·· = string
data _⊢ᴮ_∈_ : VarCtxt → Block yes → Type → Set
data _⊢ᴱ_∈_ : VarCtxt → Expr yes → Type → Set
data _⊢ᴮ_∈_ where
done : ∀ {Γ} →
---------------
Γ ⊢ᴮ done ∈ nil
return : ∀ {M B T U Γ} →
Γ ⊢ᴱ M ∈ T →
Γ ⊢ᴮ B ∈ U →
---------------------
Γ ⊢ᴮ return M ∙ B ∈ T
local : ∀ {x M B T U V Γ} →
Γ ⊢ᴱ M ∈ U →
(Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V →
--------------------------------
Γ ⊢ᴮ local var x ∈ T ← M ∙ B ∈ V
function : ∀ {f x B C T U V W Γ} →
(Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V →
(Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W →
-------------------------------------------------
Γ ⊢ᴮ function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B ∈ W
data _⊢ᴱ_∈_ where
nil : ∀ {Γ} →
--------------------
Γ ⊢ᴱ (val nil) ∈ nil
var : ∀ {x T Γ} →
T ≡ orUnknown(Γ [ x ]ⱽ) →
----------------
Γ ⊢ᴱ (var x) ∈ T
addr : ∀ {a Γ} T →
-----------------
Γ ⊢ᴱ val(addr a) ∈ T
number : ∀ {n Γ} →
---------------------------
Γ ⊢ᴱ val(number n) ∈ number
bool : ∀ {b Γ} →
--------------------------
Γ ⊢ᴱ val(bool b) ∈ boolean
string : ∀ {x Γ} →
---------------------------
Γ ⊢ᴱ val(string x) ∈ string
app : ∀ {M N T U Γ} →
Γ ⊢ᴱ M ∈ T →
Γ ⊢ᴱ N ∈ U →
----------------------------
Γ ⊢ᴱ (M $ N) ∈ (resolve T U)
function : ∀ {f x B T U V Γ} →
(Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V →
-----------------------------------------------------
Γ ⊢ᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) ∈ (T ⇒ U)
block : ∀ {b B T U Γ} →
Γ ⊢ᴮ B ∈ U →
------------------------------------
Γ ⊢ᴱ (block var b ∈ T is B end) ∈ T
binexp : ∀ {op Γ M N T U} →
Γ ⊢ᴱ M ∈ T →
Γ ⊢ᴱ N ∈ U →
----------------------------------
Γ ⊢ᴱ (binexp M op N) ∈ tgtBinOp op
data ⊢ᴼ_ : Maybe(Object yes) → Set where
nothing :
---------
⊢ᴼ nothing
function : ∀ {f x T U V B} →
(x ↦ T) ⊢ᴮ B ∈ V →
----------------------------------------------
⊢ᴼ (just function f ⟨ var x ∈ T ⟩∈ U is B end)
⊢ᴴ_ : Heap yes → Set
⊢ᴴ H = ∀ a {O} → (H [ a ]ᴴ ≡ O) → (⊢ᴼ O)
_⊢ᴴᴱ_▷_∈_ : VarCtxt → Heap yes → Expr yes → Type → Set
(Γ ⊢ᴴᴱ H ▷ M ∈ T) = (⊢ᴴ H) × (Γ ⊢ᴱ M ∈ T)
_⊢ᴴᴮ_▷_∈_ : VarCtxt → Heap yes → Block yes → Type → Set
(Γ ⊢ᴴᴮ H ▷ B ∈ T) = (⊢ᴴ H) × (Γ ⊢ᴮ B ∈ T)
| 24.043478
| 246
| 0.484629
|
8b01fae9fdd139a3ec364fd9c0af9eff8be5694b
| 35
|
agda
|
Agda
|
test/LaTeXAndHTML/succeed/%41.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/LaTeXAndHTML/succeed/%41.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/LaTeXAndHTML/succeed/%41.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module %41 where
A : Set₁
A = Set
| 7
| 16
| 0.628571
|
382280e6e83b50aa3aedf2c953473e64356b8f7e
| 961
|
agda
|
Agda
|
test/Fail/Issue2059i.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2059i.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2059i.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-06-26, issue #2059 reported by IanOrton
-- An irrelevant parameter in a rewrite rule should still
-- be bound by the lhs.
{-# OPTIONS --rewriting #-}
-- {-# OPTIONS -v tc.pos:10 #-}
-- {-# OPTIONS -v tc.polarity:10 #-}
open import Common.Equality
open import Common.Bool
data ⊥ : Set where
⊥-elim : ∀{a}{A : Set a} → .⊥ → A
⊥-elim ()
_∧_ : (a b : Bool) → Bool
true ∧ b = b
false ∧ _ = false
obvious : (b b' : Bool) .(p : b ≡ b' → ⊥) → (b ∧ b') ≡ false
obvious false b' notEq = refl
obvious true false notEq = refl
obvious true true notEq = ⊥-elim (notEq refl)
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE obvious #-}
-- Should give error:
-- obvious is not a legal rewrite rule,
-- since the following variables are not bound by the left hand side: p
-- when checking the pragma REWRITE obvious
oops : (b : Bool) → b ∧ b ≡ false
oops b = refl
true≢false : true ≡ false → ⊥
true≢false ()
bot : ⊥
bot = true≢false (oops true)
| 21.355556
| 72
| 0.620187
|
039618c668be326ae990c69f6f6bae5aca099dc9
| 2,512
|
agda
|
Agda
|
agda-stdlib/src/Codata/Conat.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Codata/Conat.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Codata/Conat.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The Conat type and some operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Conat where
open import Size
open import Codata.Thunk
open import Data.Nat.Base using (ℕ ; zero ; suc)
open import Relation.Nullary
------------------------------------------------------------------------
-- Definition and first values
data Conat (i : Size) : Set where
zero : Conat i
suc : Thunk Conat i → Conat i
infinity : ∀ {i} → Conat i
infinity = suc λ where .force → infinity
fromℕ : ℕ → Conat ∞
fromℕ zero = zero
fromℕ (suc n) = suc λ where .force → fromℕ n
------------------------------------------------------------------------
-- Arithmetic operations
pred : ∀ {i} {j : Size< i} → Conat i → Conat j
pred zero = zero
pred (suc n) = n .force
infixl 6 _∸_ _+_
infixl 7 _*_
_∸_ : Conat ∞ → ℕ → Conat ∞
m ∸ zero = m
m ∸ suc n = pred m ∸ n
_ℕ+_ : ℕ → ∀ {i} → Conat i → Conat i
zero ℕ+ n = n
suc m ℕ+ n = suc λ where .force → m ℕ+ n
_+ℕ_ : ∀ {i} → Conat i → ℕ → Conat i
zero +ℕ n = fromℕ n
suc m +ℕ n = suc λ where .force → (m .force) +ℕ n
_+_ : ∀ {i} → Conat i → Conat i → Conat i
zero + n = n
suc m + n = suc λ where .force → (m .force) + n
_*_ : ∀ {i} → Conat i → Conat i → Conat i
m * zero = zero
zero * n = zero
suc m * suc n = suc λ where .force → n .force + (m .force * suc n)
-- Max and Min
infixl 6 _⊔_
infixl 7 _⊓_
_⊔_ : ∀ {i} → Conat i → Conat i → Conat i
zero ⊔ n = n
m ⊔ zero = m
suc m ⊔ suc n = suc λ where .force → m .force ⊔ n .force
_⊓_ : ∀ {i} → Conat i → Conat i → Conat i
zero ⊓ n = zero
m ⊓ zero = zero
suc m ⊓ suc n = suc λ where .force → m .force ⊓ n .force
------------------------------------------------------------------------
-- Finiteness
data Finite : Conat ∞ → Set where
zero : Finite zero
suc : ∀ {n} → Finite (n .force) → Finite (suc n)
toℕ : ∀ {n} → Finite n → ℕ
toℕ zero = zero
toℕ (suc n) = suc (toℕ n)
¬Finite∞ : ¬ (Finite infinity)
¬Finite∞ (suc p) = ¬Finite∞ p
------------------------------------------------------------------------
-- Order wrt to Nat
data _ℕ≤_ : ℕ → Conat ∞ → Set where
zℕ≤n : ∀ {n} → zero ℕ≤ n
sℕ≤s : ∀ {k n} → k ℕ≤ n .force → suc k ℕ≤ suc n
_ℕ<_ : ℕ → Conat ∞ → Set
k ℕ< n = suc k ℕ≤ n
_ℕ≤infinity : ∀ k → k ℕ≤ infinity
zero ℕ≤infinity = zℕ≤n
suc k ℕ≤infinity = sℕ≤s (k ℕ≤infinity)
| 24.153846
| 72
| 0.472532
|
03aa341f6e05b1444481106d69c2dd334c6abd8a
| 12,088
|
agda
|
Agda
|
Cubical/HITs/PropositionalTruncation/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/HITs/PropositionalTruncation/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/HITs/PropositionalTruncation/Properties.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"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 ℓ
∥∥-isPropDep : (P : A → Type ℓ) → isOfHLevelDep 1 (λ x → ∥ P x ∥)
∥∥-isPropDep P = isOfHLevel→isOfHLevelDep 1 (λ _ → squash)
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 → B → P) → ∥ A ∥ → ∥ B ∥ → 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
squashᵗ
: ∀(x y z : A)
→ Square (squash ∣ x ∣ ∣ y ∣) (squash ∣ x ∣ ∣ z ∣) refl (squash ∣ y ∣ ∣ z ∣)
squashᵗ x y z i = squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i)
elim→Gpd
: (P : ∥ A ∥ → Type ℓ)
→ (∀ t → isGroupoid (P t))
→ (f : (x : A) → P ∣ x ∣)
→ (kf : ∀ x y → PathP (λ i → P (squash ∣ x ∣ ∣ y ∣ i)) (f x) (f y))
→ (3kf : ∀ x y z
→ SquareP (λ i j → P (squashᵗ x y z i j)) (kf x y) (kf x z) refl (kf y z))
→ (t : ∥ A ∥) → P t
elim→Gpd {A = A} P Pgpd f kf 3kf t = rec→Gpd (Pgpd t) g 3kg t
where
g : A → P t
g x = transp (λ i → P (squash ∣ x ∣ t i)) i0 (f x)
open 3-Constant
3kg : 3-Constant g
3kg .link x y i
= transp (λ j → P (squash (squash ∣ x ∣ ∣ y ∣ i) t j)) i0 (kf x y i)
3kg .coh₁ x y z i j
= transp (λ k → P (squash (squashᵗ x y z i j) t k)) i0 (3kf x y z i j)
RecHSet : (P : A → TypeOfHLevel ℓ 2) → 3-Constant P → ∥ A ∥ → TypeOfHLevel ℓ 2
RecHSet P 3kP = rec→Gpd (isOfHLevelTypeOfHLevel 2) P 3kP
| 31.978836
| 89
| 0.50091
|
d1bd7cbd060bef3bbe5ea5ac637870f2f0e2069c
| 6,998
|
agda
|
Agda
|
nicolai/thesis/Anonymous_Existence.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
nicolai/thesis/Anonymous_Existence.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
nicolai/thesis/Anonymous_Existence.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.NType2
open import Preliminaries
open import Truncation_Level_Criteria
module Anonymous_Existence_CollSplit where
-- CHAPTER 4
-- SECTION 4.1
-- Lemma 4.1.2, part 1
constant-implies-path-constant : ∀ {i j} {X : Type i} {Y : Type j} → (f : X → Y) → (const f)
→ (x₁ x₂ : X) → const (ap f {x = x₁} {y = x₂})
constant-implies-path-constant {X = X} f c x₁ x₂ p₁ p₂ = claim-cor where
claim : {x₃ x₄ : X} → {p : x₃ == x₄} → (ap f p) == ! (c x₃ x₃) ∙ (c x₃ x₄)
claim {x₃} {p = idp} = ! (!-inv-l (c x₃ x₃))
claim-cor : ap f p₁ == ap f p₂
claim-cor =
ap f p₁ =⟨ claim ⟩
! (c x₁ x₁) ∙ (c x₁ x₂) =⟨ ! claim ⟩
ap f p₂ ∎
-- Lemma 4.1.2, part 2
constant-refl : ∀ {i j} {X : Type i} {Y : Type j} → (f : X → Y) → (const f)
→ (x : X) → (p : x == x) → ap f p == idp
constant-refl f c x p = constant-implies-path-constant f c x x p idp
-- todo: this is not in the library?
-- We also need the following very simple lemma:
ap-id-trivial : ∀ {i} {X : Type i} → {x₁ x₂ : X} → (p : x₁ == x₂) → ap (idf X) p == p
ap-id-trivial idp = idp
-- Main Lemma 4.1.1 needs a bit of preparation.
fix : ∀ {i} {X : Type i} → (f : X → X) → Type i
fix {X = X} f = Σ X λ x → x == f x
-- let us give a name to the map X → fix f:
to-fix : ∀ {i} {X : Type i} → (f : X → X) → (const f) → X → fix f
to-fix f c x₀ = f x₀ , c _ _
-- the other direction is just projection:
from-fix : ∀ {i} {X : Type i} → (f : X → X) → fix f → X
from-fix f (x₀ , p₀) = x₀
-- let us structure the proof of the fixed point lemma a bit:
module fixedpoint {i : ULevel} {X : Type i} (f : X → X) (c : const f) where
-- let us show that (x , p) == (x , q) first
module _ (x : X) (p q : x == f x) where
t : x == x
t = p ∙ ! q
r : f x == f x
r = ap f t
r-is-triv : r == idp
r-is-triv = constant-refl f c x t
t' : x == x
t' = ap (idf X) t
t'-is-t : t' == t
t'-is-t = ap-id-trivial t
trans-t-p-is-q : transport (λ y → y == f y) t p == q
trans-t-p-is-q =
transport (λ y → y == f y) t p =⟨ transport-is-comp (idf X) f t p ⟩
! t' ∙ p ∙ r =⟨ ap (λ s → ! s ∙ p ∙ r) t'-is-t ⟩
! t ∙ p ∙ r =⟨ ! (∙-assoc (! t) _ _) ⟩
(! t ∙ p) ∙ r =⟨ ap (λ s → (! t ∙ p) ∙ s) r-is-triv ⟩
(! t ∙ p) ∙ idp =⟨ ∙-unit-r _ ⟩
! t ∙ p =⟨ ap (λ s → s ∙ p) (!-∙ p (! q)) ⟩
(! (! q) ∙ ! p) ∙ p =⟨ ∙-assoc (! (! q)) _ _ ⟩
! (! q) ∙ ! p ∙ p =⟨ ap (λ s → ! (! q) ∙ s) (!-inv-l p) ⟩
! (! q) ∙ idp =⟨ ∙-unit-r _ ⟩
! (! q) =⟨ !-! _ ⟩
q ∎
single-x-claim : (x , p) == (x , q)
single-x-claim = pair= t (from-transp _ _ trans-t-p-is-q)
-- Now, we can prove that (x₁ , p₁) and (x₂ , p₂) are always equal:
fix-paths : has-all-paths (fix f)
fix-paths (x₁ , p₁) (x₂ , p₂) =
(x₁ , p₁) =⟨ pair= (p₁ ∙ c x₁ x₂ ∙ ! p₂) (from-transp _ (p₁ ∙ c x₁ x₂ ∙ ! p₂) idp) ⟩
(x₂ , _) =⟨ single-x-claim x₂ _ _ ⟩
(x₂ , p₂) ∎
-- finally, the proof of the fixed point lemma
fixed-point : ∀ {i} {X : Type i} → (f : X → X) → (const f) → is-prop (fix f)
fixed-point {X = X} f c = all-paths-is-prop (fixedpoint.fix-paths f c)
-- Sattler's argument
fixed-point-alt : ∀ {i} {X : Type i} → (f : X → X) → (const f) → is-prop (fix f)
fixed-point-alt {X = X} f c = inhab-to-contr-is-prop inh→contr where
inh→contr : fix f → is-contr (fix f)
inh→contr (x₀ , p₀) = equiv-preserves-level {A = Σ X λ x → x == f x₀} {B = fix f} claim-Σ (pathto-is-contr _) where
claim : (x : X) → (x == f x₀) ≃ (x == f x)
claim x = (λ p → p ∙ c x₀ x) , post∙-is-equiv _
claim-Σ : (Σ X λ x → x == f x₀) ≃ fix f
claim-Σ = equiv-Σ-snd claim
--from here, we need truncation
module with-weak-trunc where
open wtrunc
-- Corollary 4.1.3
-- let us define the following map:
trunc-to-fix : ∀ {i} {X : Type i} → (fc : coll X) → ∣∣ X ∣∣ → fix (fst fc)
trunc-to-fix (f , c) z = tr-rec (fixed-point f c) (to-fix f c) z
coll→splitSup : ∀ {i} {X : Type i} → coll X → splitSup X
coll→splitSup (f , c) = (from-fix f) ∘ trunc-to-fix (f , c)
-- Theorem 4.1.4
coll↔splitSup : ∀ {i} {X : Type i} → coll X ↔ splitSup X
coll↔splitSup {X = X} = coll→splitSup , splitSup→coll where
splitSup→coll : splitSup X → coll X
splitSup→coll hst = f , c where
f = hst ∘ ∣_∣
c : const f
c x₁ x₂ =
f x₁ =⟨ idp ⟩
hst ∣ x₁ ∣ =⟨ ap hst (prop-has-all-paths tr-is-prop _ _) ⟩
hst ∣ x₂ ∣ =⟨ idp ⟩
f x₂ ∎
-- preparation for Statement 4.1.5 - we need to prove that
-- f : X → X with an inhabitant of ∣∣ const f ∣∣ is enough
-- to show that fix f is propositional.
fixed-point-strong : ∀ {i} {X : Type i} → (f : X → X) → ∣∣ const f ∣∣ → is-prop (fix f)
fixed-point-strong {X = X} f = tr-rec {X = const f} {P = is-prop(fix f)} is-prop-is-prop (fixed-point f)
-- Statement 4.1.5 (we exclude the part which is already included in Theorem 4.1.4)
-- to get an easy proof of the addendum, we structure it in the following way:
module thm46 {i : ULevel} {X : Type i} where
module _ (fhc : Σ (X → X) (λ f → ∣∣ const f ∣∣)) where
f = fst fhc
hc = snd fhc
trunc-const-fix : ∣∣ X ∣∣ → ∣∣ const f ∣∣ → fix f
trunc-const-fix z = tr-rec {X = const f} {P = fix f} (fixed-point-strong f hc) (λ c → trunc-to-fix (f , c) z)
trunc-fix : ∣∣ X ∣∣ → fix f
trunc-fix z = trunc-const-fix z hc
g : X → X
g = fst ∘ trunc-fix ∘ ∣_∣
g-const : const g
g-const x₁ x₂ = ap (fst ∘ trunc-fix) (prop-has-all-paths tr-is-prop _ _)
coll↔hideProof : ∀ {i} {X : Type i} → coll X ↔ Σ (X → X) (λ f → ∣∣ const f ∣∣)
coll↔hideProof {X = X} = one , two where
one : coll X → Σ (X → X) (λ f → ∣∣ const f ∣∣)
one (f , c) = f , ∣ c ∣
two : (Σ (X → X) (λ f → ∣∣ const f ∣∣)) → coll X
two fhc = thm46.g fhc , thm46.g-const fhc
-- Statement 4.1.5 addendum
merely-equal : ∀ {i} {X : Type i} → (fhc : Σ (X → X) (λ f → ∣∣ const f ∣∣)) → ∣∣ ((x : X) → fst fhc x == thm46.g fhc x) ∣∣
merely-equal {X = X} (f , hc) = tr-rec tr-is-prop (∣_∣ ∘ const-equal) hc where
open thm46
const-equal : const f → (x : X) → f x == thm46.g (f , hc) x
const-equal c x =
f x =⟨ idp ⟩
fst (to-fix f c x) =⟨ ap fst (! (trunc-β _ _ x)) ⟩
fst (trunc-to-fix (f , c) ∣ x ∣) =⟨ ap fst (! (trunc-β _ _ c)) ⟩
fst (trunc-const-fix (f , hc) ∣ x ∣ ∣ c ∣) =⟨ ap (λ hc' → fst (trunc-const-fix (f , hc) ∣ x ∣ hc')) (prop-has-all-paths tr-is-prop _ _) ⟩
fst (trunc-const-fix (f , hc) ∣ x ∣ hc) =⟨ idp ⟩
fst (trunc-fix (f , hc) ∣ x ∣) =⟨ idp ⟩
g (f , hc) x ∎
| 39.536723
| 144
| 0.481566
|
13dcc9fd443005f7723679c182d80df9803136dd
| 23,462
|
agda
|
Agda
|
Sets/FinSet/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Sets/FinSet/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Sets/FinSet/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Functions.Definition
open import Functions.Lemmas
open import LogicalFormulae
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Order
open import Sets.FinSet.Definition
module Sets.FinSet.Lemmas where
fneSymmetric : {n : ℕ} → {a b : FinSet (succ n)} → FinNotEquals a b → FinNotEquals b a
fneSymmetric {.1} {.a1} {.b1} (fne2 a1 b1 (inl x)) = fne2 b1 a1 (inr x)
fneSymmetric {.1} {.a1} {.b1} (fne2 a1 b1 (inr x)) = fne2 b1 a1 (inl x)
fneSymmetric {.(succ (succ _))} {.fzero} {b} (fneN .fzero b (inl (inl (refl ,, snd)))) = fneN b fzero (inl (inr (snd ,, refl)))
fneSymmetric {.(succ (succ _))} {a} {.fzero} (fneN a .fzero (inl (inr (fst ,, refl)))) = fneN fzero a (inl (inl (refl ,, fst)))
fneSymmetric {.(succ (succ _))} {a} {b} (fneN a b (inr ((fst ,, snd) , record { one = o ; two = p ; three = q }))) = fneN b a (inr ((snd ,, fst) , record { one = p ; two = o ; three = fneSymmetric q }))
private
underlyingProof : {l m : _} {L : Set l} {pr : L → Set m} → (a : Sg L pr) → pr (underlying a)
underlyingProof (a , b) = b
finSetNotEquals : {n : ℕ} → {a b : FinSet (succ n)} → (a ≡ b → False) → FinNotEquals {n} a b
finSetNotEquals {zero} {fzero} {fzero} pr = exFalso (pr refl)
finSetNotEquals {zero} {fzero} {fsucc ()} pr
finSetNotEquals {zero} {fsucc ()} {b} pr
finSetNotEquals {succ zero} {fzero} {fzero} pr = exFalso (pr refl)
finSetNotEquals {succ zero} {fzero} {fsucc fzero} pr = fne2 fzero (fsucc fzero) (inl (refl ,, refl))
finSetNotEquals {succ zero} {fzero} {fsucc (fsucc ())} pr
finSetNotEquals {succ zero} {fsucc fzero} {fzero} pr = fne2 (fsucc fzero) fzero (inr (refl ,, refl))
finSetNotEquals {succ zero} {fsucc fzero} {fsucc fzero} pr = exFalso (pr refl)
finSetNotEquals {succ zero} {fsucc fzero} {fsucc (fsucc ())} pr
finSetNotEquals {succ zero} {fsucc (fsucc ())}
finSetNotEquals {succ (succ n)} {fzero} {fzero} pr = exFalso (pr refl)
finSetNotEquals {succ (succ n)} {fzero} {fsucc b} pr = fneN fzero (fsucc b) (inl (inl (refl ,, (b , refl))))
finSetNotEquals {succ (succ n)} {fsucc a} {fzero} pr = fneN (fsucc a) fzero (inl (inr ((a , refl) ,, refl)))
finSetNotEquals {succ (succ n)} {fsucc a} {fsucc b} pr = fneN (fsucc a) (fsucc b) (inr ans)
where
q : a ≡ b → False
q refl = pr refl
t : FinNotEquals {succ n} a b
t = finSetNotEquals {succ n} {a} {b} q
ans : Sg (FinSet (succ (succ n)) && FinSet (succ (succ n))) (λ x → (fsucc a ≡ fsucc (_&&_.fst x)) & fsucc b ≡ fsucc (_&&_.snd x) & FinNotEquals (_&&_.fst x) (_&&_.snd x))
ans with t
ans | fne2 .fzero .(fsucc fzero) (inl (refl ,, refl)) = (a ,, b) , record { one = refl ; two = refl ; three = fne2 fzero (fsucc fzero) (inl (refl ,, refl)) }
ans | fne2 .(fsucc fzero) .fzero (inr (refl ,, refl)) = (a ,, b) , record { one = refl ; two = refl ; three = fne2 (fsucc fzero) fzero (inr (refl ,, refl)) }
ans | fneN a b _ = (a ,, b) , record { one = refl ; two = refl ; three = t }
fzeroNotFsucc : {n : ℕ} → {a : _} → fzero ≡ fsucc {succ n} a → False
fzeroNotFsucc ()
finSetNotEqualsSame : {n : ℕ} → {a : FinSet (succ n)} → FinNotEquals a a → False
finSetNotEqualsSame {.1} {fzero} (fne2 .fzero .fzero (inl (fst ,, ())))
finSetNotEqualsSame {.1} {fzero} (fne2 .fzero .fzero (inr (fst ,, ())))
finSetNotEqualsSame {.(succ (succ _))} {fzero} (fneN .fzero .fzero (inl (inl (refl ,, (a , ())))))
finSetNotEqualsSame {.(succ (succ _))} {fzero} (fneN .fzero .fzero (inl (inr ((a , ()) ,, refl))))
finSetNotEqualsSame {.(succ (succ _))} {fzero} (fneN .fzero .fzero (inr ((fst ,, snd) , record { one = () ; two = p ; three = q })))
finSetNotEqualsSame {.1} {fsucc a} (fne2 .(fsucc a) .(fsucc a) (inl (() ,, snd)))
finSetNotEqualsSame {.1} {fsucc a} (fne2 .(fsucc a) .(fsucc a) (inr (() ,, snd)))
finSetNotEqualsSame {.(succ (succ _))} {fsucc a} (fneN .(fsucc a) .(fsucc a) (inl (inl (() ,, snd))))
finSetNotEqualsSame {.(succ (succ _))} {fsucc a} (fneN .(fsucc a) .(fsucc a) (inl (inr (fst ,, ()))))
finSetNotEqualsSame {.(succ (succ _))} {fsucc a} (fneN .(fsucc a) .(fsucc a) (inr ((.a ,, .a) , record { one = refl ; two = refl ; three = q }))) = finSetNotEqualsSame q
finNotEqualsFsucc : {n : ℕ} → {a b : FinSet (succ n)} → FinNotEquals (fsucc a) (fsucc b) → FinNotEquals a b
finNotEqualsFsucc {.0} {a} {b} (fne2 .(fsucc a) .(fsucc b) (inl (() ,, snd)))
finNotEqualsFsucc {.0} {a} {b} (fne2 .(fsucc a) .(fsucc b) (inr (() ,, snd)))
finNotEqualsFsucc {n} {a} {b} (fneN .(fsucc a) .(fsucc b) (inl (inl (() ,, snd))))
finNotEqualsFsucc {n} {a} {b} (fneN .(fsucc a) .(fsucc b) (inl (inr (fst ,, ()))))
finNotEqualsFsucc {n} {a} {b} (fneN .(fsucc a) .(fsucc b) (inr ((fst ,, snd) , prf))) = identityOfIndiscernablesRight FinNotEquals ans (equalityCommutative b=snd)
where
a=fst : a ≡ fst
a=fst = fsuccInjective (_&_&_.one prf)
b=snd : b ≡ snd
b=snd = fsuccInjective (_&_&_.two prf)
ans : FinNotEquals a snd
ans = identityOfIndiscernablesLeft FinNotEquals (_&_&_.three prf) (equalityCommutative a=fst)
finSetNotEquals' : {n : ℕ} → {a b : FinSet (succ n)} → FinNotEquals a b → (a ≡ b → False)
finSetNotEquals' {n} {a} {.a} fne refl = finSetNotEqualsSame fne
finset0Empty : FinSet zero → False
finset0Empty ()
finset1OnlyOne : (a b : FinSet 1) → a ≡ b
finset1OnlyOne fzero fzero = refl
finset1OnlyOne fzero (fsucc ())
finset1OnlyOne (fsucc ()) b
intoSmaller : {n m : ℕ} → .(n <N m) → (FinSet n → FinSet m)
intoSmaller {zero} {m} n<m = t
where
t : FinSet 0 → FinSet m
t ()
intoSmaller {succ n} {zero} ()
intoSmaller {succ n} {succ m} n<m with intoSmaller (canRemoveSuccFrom<N n<m)
intoSmaller {succ n} {succ m} n<m | prev = t
where
t : FinSet (succ n) → FinSet (succ m)
t fzero = fzero
t (fsucc arg) = fsucc (prev arg)
intoSmallerInj : {n m : ℕ} → (n<m : n <N m) → Injection (intoSmaller n<m)
intoSmallerInj {zero} {zero} (le x ())
intoSmallerInj {zero} {succ m} n<m = inj
where
t : FinSet 0 → FinSet (succ m)
t ()
inj : {x y : FinSet zero} → intoSmaller (succIsPositive m) x ≡ intoSmaller (succIsPositive m) y → x ≡ y
inj {()} {y}
intoSmallerInj {succ n} {zero} ()
intoSmallerInj {succ n} {succ m} n<m with intoSmallerInj (canRemoveSuccFrom<N n<m)
intoSmallerInj {succ n} {succ m} n<m | prevInj = inj
where
inj : Injection (intoSmaller n<m)
inj {fzero} {fzero} pr = refl
inj {fzero} {fsucc y} ()
inj {fsucc x} {fzero} ()
inj {fsucc x} {fsucc y} pr = applyEquality fsucc (prevInj (fsuccInjective pr))
toNat : {n : ℕ} → (a : FinSet n) → ℕ
toNat {.(succ _)} fzero = 0
toNat {.(succ _)} (fsucc a) = succ (toNat a)
toNatSmaller : {n : ℕ} → (a : FinSet n) → toNat a <N n
toNatSmaller {zero} ()
toNatSmaller {succ n} fzero = succIsPositive n
toNatSmaller {succ n} (fsucc a) = succPreservesInequality (toNatSmaller a)
ofNat : {n : ℕ} → (m : ℕ) → .(m <N n) → FinSet n
ofNat {zero} zero ()
ofNat {succ n} zero m<n = fzero
ofNat {zero} (succ m) ()
ofNat {succ n} (succ m) m<n = fsucc (ofNat {n} m (canRemoveSuccFrom<N m<n))
ofNatInjective : {n : ℕ} → (x y : ℕ) → .(pr : x <N n) → .(pr2 : y <N n) → ofNat x pr ≡ ofNat y pr2 → x ≡ y
ofNatInjective {zero} zero zero () y<n pr
ofNatInjective {zero} zero (succ y) () y<n pr
ofNatInjective {zero} (succ x) zero x<n () pr
ofNatInjective {zero} (succ x) (succ y) () y<n pr
ofNatInjective {succ n} zero zero x<n y<n pr = refl
ofNatInjective {succ n} zero (succ y) x<n y<n ()
ofNatInjective {succ n} (succ x) zero x<n y<n ()
ofNatInjective {succ n} (succ x) (succ y) x<n y<n pr = applyEquality succ (ofNatInjective x y (canRemoveSuccFrom<N x<n) (canRemoveSuccFrom<N y<n) (fsuccInjective pr))
toNatInjective : {n : ℕ} → (x y : FinSet n) → toNat x ≡ toNat y → x ≡ y
toNatInjective fzero fzero pr = refl
toNatInjective (fsucc x) (fsucc y) pr = applyEquality fsucc (toNatInjective x y (succInjective pr))
toNatOfNat : {n : ℕ} → (a : ℕ) → (a<n : a <N n) → toNat (ofNat a a<n) ≡ a
toNatOfNat {zero} zero (le x ())
toNatOfNat {zero} (succ a) (le x ())
toNatOfNat {succ n} zero a<n = refl
toNatOfNat {succ n} (succ a) a<n = applyEquality succ (toNatOfNat a (canRemoveSuccFrom<N a<n))
intoSmallerLemm : {n m : ℕ} → {n<m : n <N (succ m)} → {m<sm : m <N succ m} → (b : FinSet n) → intoSmaller n<m b ≡ ofNat m m<sm → False
intoSmallerLemm {.(succ _)} {m} {n<m} fzero pr with intoSmaller (canRemoveSuccFrom<N n<m)
intoSmallerLemm {.(succ _)} {zero} {n<m} fzero refl | bl = zeroNeverGreater (canRemoveSuccFrom<N n<m)
intoSmallerLemm {.(succ _)} {succ m} {n<m} fzero () | bl
intoSmallerLemm {.(succ _)} {m} {n<m} (fsucc b) pr with inspect (intoSmaller (canRemoveSuccFrom<N n<m))
intoSmallerLemm {.(succ _)} {zero} {n<m} (fsucc b) pr | bl with≡ _ = zeroNeverGreater (canRemoveSuccFrom<N n<m)
intoSmallerLemm {.(succ _)} {succ m} {n<m} {m<sm} (fsucc b) pr | bl with≡ p = intoSmallerLemm {n<m = canRemoveSuccFrom<N n<m} {m<sm = canRemoveSuccFrom<N m<sm} b (fsuccInjective pr)
intoSmallerNotSurj : {n m : ℕ} → {n<m : n <N m} → Surjection (intoSmaller n<m) → False
intoSmallerNotSurj {n} {zero} {le x ()} property
intoSmallerNotSurj {zero} {succ zero} {n<m} property with property fzero
... | () , _
intoSmallerNotSurj {succ n} {succ zero} {n<m} property = zeroNeverGreater (canRemoveSuccFrom<N n<m)
intoSmallerNotSurj {0} {succ (succ m)} {n<m} property with property fzero
... | () , _
intoSmallerNotSurj {succ n} {succ (succ m)} {n<m} property = problem
where
notHit : FinSet (succ (succ m))
notHit = ofNat (succ m) (le zero refl)
hitting : Sg (FinSet (succ n)) (λ i → intoSmaller n<m i ≡ notHit)
hitting = property notHit
problem : False
problem with hitting
... | a , pr = intoSmallerLemm {succ n} {succ m} {n<m} {le 0 refl} a pr
finsetDecidableEquality : {n : ℕ} → (x y : FinSet n) → (x ≡ y) || ((x ≡ y) → False)
finsetDecidableEquality fzero fzero = inl refl
finsetDecidableEquality fzero (fsucc y) = inr λ ()
finsetDecidableEquality (fsucc x) fzero = inr λ ()
finsetDecidableEquality (fsucc x) (fsucc y) with finsetDecidableEquality x y
finsetDecidableEquality (fsucc x) (fsucc y) | inl pr rewrite pr = inl refl
finsetDecidableEquality (fsucc x) (fsucc y) | inr pr = inr (λ f → pr (fsuccInjective f))
subInjection : {n : ℕ} → {f : FinSet (succ (succ n)) → FinSet (succ (succ n))} → Injection f → (FinSet (succ n) → FinSet (succ n))
subInjection {n} {f} inj x with inspect (f (fsucc x))
subInjection {f = f} inj x | fzero with≡ _ with inspect (f fzero)
subInjection {f = f} inj x | fzero with≡ pr | fzero with≡ pr2 = exFalso (fzeroNotFsucc (inj (transitivity pr2 (equalityCommutative pr))))
subInjection {f = f} inj x | fzero with≡ _ | fsucc bl with≡ _ = bl
subInjection {f = f} inj x | fsucc bl with≡ _ = bl
subInjIsInjective : {n : ℕ} → {f : FinSet (succ (succ n)) → FinSet (succ (succ n))} → (inj : Injection f) → Injection (subInjection inj)
subInjIsInjective {f = f} inj {x} {y} pr with inspect (f (fsucc x))
subInjIsInjective {f = f} inj {x} {y} pr | fzero with≡ _ with inspect (f (fzero))
subInjIsInjective {f = f} inj {x} {y} pr | fzero with≡ pr1 | fzero with≡ pr2 = exFalso (fzeroNotFsucc (inj (transitivity pr2 (equalityCommutative pr1))))
subInjIsInjective {f = f} inj {x} {y} pr | fzero with≡ pr1 | fsucc bl with≡ _ with inspect (f (fsucc y))
subInjIsInjective {f = f} inj {x} {y} pr | fzero with≡ pr1 | fsucc bl with≡ _ | fzero with≡ x₁ with inspect (f (fzero))
subInjIsInjective {f = f} inj {x} {y} pr | fzero with≡ pr1 | fsucc bl with≡ _ | fzero with≡ x1 | fzero with≡ x2 = exFalso (fzeroNotFsucc (inj (transitivity x2 (equalityCommutative x1))))
subInjIsInjective {f = f} inj {x} {y} refl | fzero with≡ pr1 | fsucc .bl2 with≡ _ | fzero with≡ x1 | fsucc bl2 with≡ _ = fsuccInjective (inj (transitivity pr1 (equalityCommutative x1)))
subInjIsInjective {f = f} inj {x} {y} refl | fzero with≡ pr1 | fsucc .bl2 with≡ pr2 | fsucc bl2 with≡ pr3 = exFalso (fzeroNotFsucc (inj (transitivity pr2 (equalityCommutative pr3))))
subInjIsInjective {f = f} inj {x} {y} pr | fsucc bl with≡ _ with inspect (f (fsucc y))
subInjIsInjective {f = f} inj {x} {y} pr | fsucc bl with≡ _ | fzero with≡ x₁ with inspect (f fzero)
subInjIsInjective {f = f} inj {x} {y} pr | fsucc bl with≡ _ | fzero with≡ x1 | fzero with≡ x2 = exFalso (fzeroNotFsucc (inj (transitivity x2 (equalityCommutative x1))))
subInjIsInjective {f = f} inj {x} {y} refl | fsucc .bl2 with≡ x1 | fzero with≡ x₁ | fsucc bl2 with≡ x2 = exFalso (fzeroNotFsucc (inj (transitivity x2 (equalityCommutative x1))))
subInjIsInjective {f = f} inj {x} {y} refl | fsucc .y1 with≡ pr1 | fsucc y1 with≡ pr2 = fsuccInjective (inj (transitivity pr1 (equalityCommutative pr2)))
onepointBij : (f : FinSet 1 → FinSet 1) → Bijection f
Bijection.inj (onepointBij f) {x} {y} _ = finset1OnlyOne x y
Bijection.surj (onepointBij f) fzero with inspect (f fzero)
... | fzero with≡ pr = fzero , pr
... | fsucc () with≡ _
Bijection.surj (onepointBij f) (fsucc ())
nopointBij : (f : FinSet 0 → FinSet 0) → Bijection f
Bijection.inj (nopointBij f) {()}
Bijection.surj (nopointBij f) ()
private
flip : {n : ℕ} → (f : FinSet (succ n) → FinSet (succ n)) → FinSet (succ n) → FinSet (succ n)
flip {n} f fzero = f fzero
flip {n} f (fsucc a) with inspect (f fzero)
flip {n} f (fsucc a) | fzero with≡ x = fsucc a
flip {n} f (fsucc a) | fsucc y with≡ x with finsetDecidableEquality a y
flip {n} f (fsucc a) | fsucc y with≡ x | inl a=y = fzero
flip {n} f (fsucc a) | fsucc y with≡ x | inr a!=y = fsucc a
flipSwapsF0 : {n : ℕ} → {f : FinSet (succ n) → FinSet (succ n)} → (flip f (f fzero)) ≡ fzero
flipSwapsF0 {zero} {f} with inspect (f fzero)
flipSwapsF0 {zero} {f} | fzero with≡ x rewrite x = x
flipSwapsF0 {zero} {f} | fsucc () with≡ x
flipSwapsF0 {succ n} {f = f} with inspect (f fzero)
flipSwapsF0 {succ n} {f = f} | fzero with≡ pr rewrite pr = pr
flipSwapsF0 {succ n} {f = f} | fsucc b with≡ pr rewrite pr = ans
where
ans : flip f (fsucc b) ≡ fzero
ans with inspect (f fzero)
ans | fzero with≡ x = exFalso (fzeroNotFsucc (transitivity (equalityCommutative x) pr))
ans | fsucc y with≡ x with finsetDecidableEquality b y
ans | fsucc y with≡ x | inl b=y = refl
ans | fsucc y with≡ x | inr b!=y = exFalso (b!=y (fsuccInjective (transitivity (equalityCommutative pr) x)))
flipSwapsZero : {n : ℕ} → {f : FinSet (succ n) → FinSet (succ n)} → (flip f fzero) ≡ f fzero
flipSwapsZero {n} {f} = refl
flipMaintainsEverythingElse : {n : ℕ} → {f : FinSet (succ n) → FinSet (succ n)} → (x : FinSet n) → ((fsucc x ≡ f fzero) → False) → flip f (fsucc x) ≡ fsucc x
flipMaintainsEverythingElse {n} {f} x x!=f0 with inspect (f fzero)
flipMaintainsEverythingElse {n} {f} x x!=f0 | fzero with≡ pr = refl
flipMaintainsEverythingElse {n} {f} x x!=f0 | fsucc bl with≡ pr with finsetDecidableEquality x bl
flipMaintainsEverythingElse {n} {f} x x!=f0 | fsucc bl with≡ pr | inl x=bl = exFalso (x!=f0 (transitivity (applyEquality fsucc x=bl) (equalityCommutative pr)))
flipMaintainsEverythingElse {n} {f} x x!=f0 | fsucc bl with≡ pr | inr x!=bl = refl
bijFlip : {n : ℕ} → {f : FinSet (succ n) → FinSet (succ n)} → Bijection (flip f)
bijFlip {zero} {f} = onepointBij (flip f)
Bijection.inj (bijFlip {succ n} {f}) {fzero} {fzero} flx=fly = refl
Bijection.inj (bijFlip {succ n} {f}) {fzero} {fsucc y} flx=fly with inspect (f fzero)
Bijection.inj (bijFlip {succ n} {f}) {fzero} {fsucc y} flx=fly | fzero with≡ x rewrite x = exFalso (fzeroNotFsucc flx=fly)
Bijection.inj (bijFlip {succ n} {f}) {fzero} {fsucc y} flx=fly | fsucc f0 with≡ x with finsetDecidableEquality y f0
Bijection.inj (bijFlip {succ n} {f}) {fzero} {fsucc y} flx=fly | fsucc f0 with≡ x | inl x₁ = exFalso (fzeroNotFsucc (transitivity (equalityCommutative flx=fly) x))
Bijection.inj (bijFlip {succ n} {f}) {fzero} {fsucc y} flx=fly | fsucc f0 with≡ x | inr pr = exFalso (pr (fsuccInjective (transitivity (equalityCommutative flx=fly) x)))
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fzero} flx=fly with inspect (f fzero)
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fzero} flx=fly | fzero with≡ pr = transitivity flx=fly pr
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fzero} flx=fly | fsucc f0 with≡ x₁ with finsetDecidableEquality x f0
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fzero} flx=fly | fsucc f0 with≡ pr | inl x₂ = exFalso (fzeroNotFsucc (transitivity flx=fly pr))
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fzero} flx=fly | fsucc f0 with≡ x1 | inr x!=f0 = exFalso (x!=f0 (fsuccInjective (transitivity flx=fly x1)))
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly with inspect (f fzero)
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly | fzero with≡ x₁ = flx=fly
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly | fsucc f0 with≡ x₁ with finsetDecidableEquality y f0
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly | fsucc f0 with≡ x₁ | inl y=f0 with finsetDecidableEquality x f0
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly | fsucc f0 with≡ x₁ | inl y=f0 | inl x=f0 = applyEquality fsucc (transitivity x=f0 (equalityCommutative y=f0))
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} () | fsucc f0 with≡ x₁ | inl y=f0 | inr x!=f0
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly | fsucc f0 with≡ x₁ | inr y!=f0 with finsetDecidableEquality x f0
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} () | fsucc f0 with≡ x₁ | inr y!=f0 | inl x=f0
Bijection.inj (bijFlip {succ n} {f}) {fsucc x} {fsucc y} flx=fly | fsucc f0 with≡ x₁ | inr y!=f0 | inr x!=f0 = flx=fly
Bijection.surj (bijFlip {succ n} {f}) fzero = f fzero , flipSwapsF0 {f = f}
Bijection.surj (bijFlip {succ n} {f}) (fsucc b) with inspect (f fzero)
Bijection.surj (bijFlip {succ n} {f}) (fsucc b) | fzero with≡ x = fsucc b , flipMaintainsEverythingElse {f = f} b λ pr → fzeroNotFsucc (transitivity (equalityCommutative x) (equalityCommutative pr))
Bijection.surj (bijFlip {succ n} {f}) (fsucc b) | fsucc y with≡ x with finsetDecidableEquality y b
Bijection.surj (bijFlip {succ n} {f}) (fsucc b) | fsucc y with≡ x | inl y=b = fzero , transitivity x (applyEquality fsucc y=b)
Bijection.surj (bijFlip {succ n} {f}) (fsucc b) | fsucc y with≡ x | inr y!=b = fsucc b , flipMaintainsEverythingElse {f = f} b λ pr → y!=b (fsuccInjective (transitivity (equalityCommutative x) (equalityCommutative pr)))
injectionIsBijectionFinset : {n : ℕ} → {f : FinSet n → FinSet n} → Injection f → Bijection f
injectionIsBijectionFinset {zero} {f} inj = record { inj = inj ; surj = λ () }
injectionIsBijectionFinset {succ zero} {f} inj = record { inj = inj ; surj = ans }
where
ans : (b : FinSet (succ zero)) → Sg (FinSet (succ zero)) (λ a → f a ≡ b)
ans fzero with inspect (f fzero)
ans fzero | fzero with≡ x = fzero , x
ans fzero | fsucc () with≡ x
ans (fsucc ())
injectionIsBijectionFinset {succ (succ n)} {f} inj with injectionIsBijectionFinset {succ n} (subInjIsInjective inj)
... | sb = ans
where
subSurj : Surjection (subInjection inj)
subSurj = Bijection.surj sb
tweakedF : FinSet (succ (succ n)) → FinSet (succ (succ n))
tweakedF fzero = fzero
tweakedF (fsucc x) = fsucc (subInjection inj x)
tweakedBij : Bijection tweakedF
Bijection.inj tweakedBij {fzero} {fzero} f'x=f'y = refl
Bijection.inj tweakedBij {fzero} {fsucc y} ()
Bijection.inj tweakedBij {fsucc x} {fzero} ()
Bijection.inj tweakedBij {fsucc x} {fsucc y} f'x=f'y = applyEquality fsucc ((subInjIsInjective inj) (fsuccInjective f'x=f'y))
Bijection.surj tweakedBij fzero = fzero , refl
Bijection.surj tweakedBij (fsucc b) with subSurj b
... | ans , prop = fsucc ans , applyEquality fsucc prop
compBij : Bijection (λ i → flip f (tweakedF i))
compBij = bijectionComp tweakedBij bijFlip
undoTweakMakesF : {x : FinSet (succ (succ n))} → flip f (tweakedF x) ≡ f x
undoTweakMakesF {fzero} = refl
undoTweakMakesF {fsucc x} with inspect (f fzero)
undoTweakMakesF {fsucc x} | fzero with≡ x₁ with inspect (f (fsucc x))
undoTweakMakesF {fsucc x} | fzero with≡ x₁ | fzero with≡ x₂ with inspect (f fzero)
undoTweakMakesF {fsucc x} | fzero with≡ x₁ | fzero with≡ x2 | fzero with≡ x3 = exFalso (fzeroNotFsucc (inj (transitivity x3 (equalityCommutative x2))))
undoTweakMakesF {fsucc x} | fzero with≡ x1 | fzero with≡ x2 | fsucc y with≡ x3 = exFalso (fzeroNotFsucc (inj (transitivity x1 (equalityCommutative x2))))
undoTweakMakesF {fsucc x} | fzero with≡ x1 | fsucc y with≡ x2 = equalityCommutative x2
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ with inspect (f (fsucc x))
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ | fzero with≡ x₂ with inspect (f fzero)
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ | fzero with≡ x2 | fzero with≡ x3 = exFalso (fzeroNotFsucc (inj (transitivity x3 (equalityCommutative x2))))
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ | fzero with≡ x₂ | fsucc pr with≡ x₃ with finsetDecidableEquality pr y
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ | fzero with≡ x2 | fsucc pr with≡ x₃ | inl x₄ = equalityCommutative x2
undoTweakMakesF {fsucc x} | fsucc y with≡ x1 | fzero with≡ x₂ | fsucc pr with≡ x3 | inr pr!=y = exFalso (pr!=y (fsuccInjective (transitivity (equalityCommutative x3) x1)))
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ | fsucc thi with≡ x₂ with finsetDecidableEquality thi y
undoTweakMakesF {fsucc x} | fsucc .thi with≡ x1 | fsucc thi with≡ x2 | inl refl = exFalso false
where
p : f fzero ≡ f (fsucc x)
p = transitivity x1 (equalityCommutative x2)
q : fzero ≡ fsucc x
q = inj p
false : False
false = fzeroNotFsucc q
undoTweakMakesF {fsucc x} | fsucc y with≡ x₁ | fsucc thi with≡ x2 | inr thi!=y = equalityCommutative x2
ans : Bijection f
ans = bijectionPreservedUnderExtensionalEq compBij undoTweakMakesF
pigeonhole : {n m : ℕ} → (m <N n) → {f : FinSet n → FinSet m} → Injection f → False
pigeonhole {zero} {zero} () {f} property
pigeonhole {zero} {succ m} () {f} property
pigeonhole {succ n} {zero} m<n {f} property = finset0Empty (f fzero)
pigeonhole {succ zero} {succ m} m<n {f} property with canRemoveSuccFrom<N m<n
pigeonhole {succ zero} {succ m} m<n {f} property | le x ()
pigeonhole {succ (succ n)} {succ zero} m<n {f} property = fzeroNotFsucc (property (transitivity f0 (equalityCommutative f1)))
where
f0 : f (fzero) ≡ fzero
f0 with inspect (f fzero)
... | fzero with≡ x = x
... | fsucc () with≡ _
f1 : f (fsucc fzero) ≡ fzero
f1 with inspect (f (fsucc fzero))
... | fzero with≡ x = x
... | fsucc () with≡ _
pigeonhole {succ (succ n)} {succ (succ m)} m<n {f} injF = intoSmallerNotSurj {_}{_} {m<n} surj
where
inj : Injection ((intoSmaller m<n) ∘ f)
inj = injComp injF (intoSmallerInj m<n)
bij : Bijection ((intoSmaller m<n) ∘ f)
bij = injectionIsBijectionFinset inj
surj : Surjection (intoSmaller m<n)
surj = compSurjLeftSurj (Bijection.surj bij)
--surjectionIsBijectionFinset : {n : ℕ} → {f : FinSet n → FinSet n} → Surjection f → Bijection f
--surjectionIsBijectionFinset {zero} {f} surj = nopointBij f
--surjectionIsBijectionFinset {succ zero} {f} surj = onepointBij f
--surjectionIsBijectionFinset {succ (succ n)} {f} record { property = property } = {!!}
ofNatToNat : {n : ℕ} → (a : FinSet n) → ofNat (toNat a) (toNatSmaller a) ≡ a
ofNatToNat {zero} ()
ofNatToNat {succ n} fzero = refl
ofNatToNat {succ n} (fsucc a) = applyEquality fsucc (ofNatToNat a)
| 62.233422
| 221
| 0.65182
|
52ad424e5c6b06c136aad24d77539c9dea0ab442
| 454
|
agda
|
Agda
|
test/Succeed/EtaContractToMillerPattern.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/EtaContractToMillerPattern.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/EtaContractToMillerPattern.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2011-04-05
module EtaContractToMillerPattern where
data _==_ {A : Set}(a : A) : A -> Set where
refl : a == a
record Prod (A B : Set) : Set where
constructor _,_
field fst : A
snd : B
open Prod
postulate A B C : Set
test : let X : (Prod A B -> C) -> (Prod A B -> C)
X = _
in (x : Prod A B -> C) ->
X (\ z -> x (fst z , snd z)) == x
test x = refl
-- eta contracts unification problem to X x = x
| 21.619048
| 49
| 0.530837
|
d19fe0599dedebce84a45fdbadc4f044064e0846
| 426
|
agda
|
Agda
|
part1/negation/irreflexive.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | 1
|
2020-07-07T09:42:22.000Z
|
2020-07-07T09:42:22.000Z
|
part1/negation/irreflexive.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
part1/negation/irreflexive.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
module irreflexive where
open import Data.Nat using (ℕ; zero; suc)
open import Negation using (¬_)
infix 4 _<_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ}
------------
→ zero < suc n
s<s : ∀ {m n : ℕ}
→ m < n
-------------
→ suc m < suc n
-- n が非反射律 ∀ n ∈ ℕ, ¬(n < n) を満たすことの証明
<-irreflexive : ∀ (n : ℕ) → ¬ (n < n)
<-irreflexive zero ()
<-irreflexive (suc n) (s<s n<n) = <-irreflexive n n<n
| 19.363636
| 53
| 0.49061
|
3044004f66adc0053010d8b4016de52087a34aa3
| 1,947
|
agda
|
Agda
|
src/System/IO/Transducers/Bytes.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | 10
|
2015-01-04T13:45:16.000Z
|
2021-09-15T04:35:41.000Z
|
src/System/IO/Transducers/Bytes.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | null | null | null |
src/System/IO/Transducers/Bytes.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | 2
|
2017-08-10T06:12:54.000Z
|
2022-03-12T11:40:23.000Z
|
open import Coinduction using ( ♯_ )
open import Data.Bool using ( Bool ; true ; false ; not )
open import Data.ByteString using ( null ) renaming ( span to #span )
open import Data.Natural using ( Natural )
open import Data.Product using ( _×_ ; _,_ )
open import Data.Word using ( Byte )
open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ; _⟫_ ; π₁ ; π₂ ; _[&]_ )
open import System.IO.Transducers.Weight using ( weight )
open import System.IO.Transducers.Stateful using ( loop )
open import System.IO.Transducers.Session using ( ⟨_⟩ ; _&_ ; ¿ ; * ; _&*_ )
open import System.IO.Transducers.Strict using ( _⇛_ )
module System.IO.Transducers.Bytes where
open System.IO.Transducers.Session public using ( Bytes ; Bytes' )
mutual
span' : (Byte → Bool) → Bytes' ⇛ (Bytes & Bytes)
span' φ x with #span φ x
span' φ x | (x₁ , x₂) with null x₁ | null x₂
span' φ x | (x₁ , x₂) | true | true = inp (♯ span φ)
span' φ x | (x₁ , x₂) | true | false = out false (out true (out x₂ done))
span' φ x | (x₁ , x₂) | false | true = out true (out x₁ (inp (♯ span φ)))
span' φ x | (x₁ , x₂) | false | false = out true (out x₁ (out false (out true (out x₂ done))))
span : (Byte → Bool) → Bytes ⇛ (Bytes & Bytes)
span φ false = out false (out false done)
span φ true = inp (♯ span' φ)
break : (Byte → Bool) → Bytes ⇛ (Bytes & Bytes)
break φ = span (λ x → not (φ x))
mutual
nonempty' : Bytes' & Bytes ⇛ ¿ Bytes & Bytes
nonempty' x with null x
nonempty' x | true = inp (♯ nonempty)
nonempty' x | false = out true (out true (out x done))
nonempty : Bytes & Bytes ⇛ ¿ Bytes & Bytes
nonempty true = inp (♯ nonempty')
nonempty false = out false done
split? : (Byte → Bool) → Bytes ⇒ (¿ Bytes & Bytes)
split? φ = inp (♯ span φ) ⟫ π₂ {Bytes} ⟫ inp (♯ break φ) ⟫ inp (♯ nonempty)
split : (Byte → Bool) → Bytes ⇒ * Bytes
split φ = loop {Bytes} (split? φ) ⟫ π₁
bytes : Bytes ⇒ ⟨ Natural ⟩
bytes = weight
| 36.735849
| 96
| 0.626605
|
0325ae714671a739259624cafc9f048a26372ce0
| 809
|
agda
|
Agda
|
Cubical/Foundations/Pointed/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Pointed/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Foundations/Pointed/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Pointed.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Structure using (typ) public
open import Cubical.Foundations.GroupoidLaws
Pointed : (ℓ : Level) → Type (ℓ-suc ℓ)
Pointed ℓ = TypeWithStr ℓ (λ x → x)
pt : ∀ {ℓ} (A∙ : Pointed ℓ) → typ A∙
pt = str
Pointed₀ = Pointed ℓ-zero
{- Pointed functions -}
_→∙_ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ')
_→∙_ A B = Σ[ f ∈ (typ A → typ B) ] f (pt A) ≡ pt B
_→∙_∙ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
A →∙ B ∙ = (A →∙ B) , (λ x → pt B) , refl
idfun∙ : ∀ {ℓ} (A : Pointed ℓ) → A →∙ A
idfun∙ A = (λ x → x) , refl
| 28.892857
| 73
| 0.618047
|
5e70d56688ef61c7de448fb2ce972bd52a718393
| 2,184
|
agda
|
Agda
|
vendor/stdlib/src/Category/Monad/Partiality.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Category/Monad/Partiality.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Category/Monad/Partiality.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- The partiality monad
------------------------------------------------------------------------
module Category.Monad.Partiality where
open import Coinduction
open import Category.Monad
open import Data.Nat
open import Data.Bool
-- The partiality monad.
data _⊥ (A : Set) : Set where
now : (x : A) → A ⊥
later : (x : ∞ (A ⊥)) → A ⊥
monad : RawMonad _⊥
monad = record
{ return = now
; _>>=_ = _>>=_
}
where
_>>=_ : ∀ {A B} → A ⊥ → (A → B ⊥) → B ⊥
now x >>= f = f x
later x >>= f = later (♯ ♭ x >>= f)
-- run x for n steps peels off at most n "later" constructors from x.
run_for_steps : ∀ {A} → A ⊥ → ℕ → A ⊥
run now x for n steps = now x
run later x for zero steps = later x
run later x for suc n steps = run ♭ x for n steps
-- Is the computation done?
isNow : ∀ {A} → A ⊥ → Bool
isNow (now x) = true
isNow (later x) = false
------------------------------------------------------------------------
-- Productivity checker workaround
-- The monad can be awkward to use, due to the limitations of guarded
-- coinduction. The following code provides a (limited) workaround.
infixl 1 _>>=_
data _⊥-prog : Set → Set₁ where
now : ∀ {A} (x : A) → A ⊥-prog
later : ∀ {A} (x : ∞₁ (A ⊥-prog)) → A ⊥-prog
_>>=_ : ∀ {A B} (x : A ⊥-prog) (f : A → B ⊥-prog) → B ⊥-prog
data _⊥-whnf : Set → Set₁ where
now : ∀ {A} (x : A) → A ⊥-whnf
later : ∀ {A} (x : A ⊥-prog) → A ⊥-whnf
whnf : ∀ {A} → A ⊥-prog → A ⊥-whnf
whnf (now x) = now x
whnf (later x) = later (♭₁ x)
whnf (x >>= f) with whnf x
whnf (x >>= f) | now x′ = whnf (f x′)
whnf (x >>= f) | later x′ = later (x′ >>= f)
mutual
value : ∀ {A} → A ⊥-whnf → A ⊥
value (now x) = now x
value (later x) = later (♯ run x)
run : ∀ {A} → A ⊥-prog → A ⊥
run x = value (whnf x)
------------------------------------------------------------------------
-- Examples
module Examples where
open import Relation.Nullary
-- McCarthy's f91:
f91′ : ℕ → ℕ ⊥-prog
f91′ n with n ≤? 100
... | yes _ = later (♯₁ (f91′ (11 + n) >>= f91′))
... | no _ = now (n ∸ 10)
f91 : ℕ → ℕ ⊥
f91 n = run (f91′ n)
| 24.266667
| 72
| 0.468407
|
1a7c130749c9b12ca483c231615717c043beb905
| 3,203
|
agda
|
Agda
|
Money.agda
|
neosimsim/money-typed
|
f875dfb5f191e6a4a041a8aa4d08f98acdc5ab53
|
[
"BSD-3-Clause"
] | null | null | null |
Money.agda
|
neosimsim/money-typed
|
f875dfb5f191e6a4a041a8aa4d08f98acdc5ab53
|
[
"BSD-3-Clause"
] | null | null | null |
Money.agda
|
neosimsim/money-typed
|
f875dfb5f191e6a4a041a8aa4d08f98acdc5ab53
|
[
"BSD-3-Clause"
] | null | null | null |
module Money where
import Agda.Builtin.IO as Builtin using (IO)
import Data.Rational as ℚ using (_+_; _*_)
open import Codata.Musical.Notation using (♯_)
open import Data.Nat using (ℕ; suc)
open import Data.Integer as ℤ using (+_)
open import Data.List using (List; []; _∷_)
open import Data.Rational as ℚ using (ℚ; 0ℚ; _/_)
open import Data.String using (String)
open import Data.Unit using (⊤)
open import Function using (_∘_) renaming (_$_ to _$$_)
open import IO using (putStrLn; IO; _>>_; run; sequence)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; _≢_)
open import Relation.Binary using (Decidable)
open import Relation.Nullary using (yes; no)
open import Codata.Musical.Colist as Colist using (fromList)
open Colist renaming (_∷_ to _::_)
data Currency : Set where
€ : Currency
£ : Currency
$ : Currency
¥ : Currency
data Money : Currency → Set where
mkMoney : {c : Currency} → ℚ → Money c
noMoney : Money $
noMoney = mkMoney (+ 0 / 1)
_+_ : {c : Currency} → Money c → Money c → Money c
mkMoney x₁ + mkMoney x₂ = mkMoney (x₁ ℚ.+ x₂)
infix 30 _+_
_*_ : {c : Currency} → ℚ → Money c → Money c
x * mkMoney y = mkMoney (x ℚ.* y)
record SomeMoney : Set where
field
currency : Currency
money : Money currency
mkSomeMoney : Currency → ℚ → SomeMoney
mkSomeMoney currency amount = record { currency = currency; money = mkMoney amount }
record Trade : Set where
constructor mkTrade
field
tPrice : SomeMoney
tQty : ℚ
data Equal? (c₁ c₂ : Currency) : Set where
eq : c₁ ≡ c₂ → Equal? c₁ c₂
neq : c₁ ≢ c₂ → Equal? c₁ c₂
infix 4 _≟_
_≟_ : Decidable {A = Currency} _≡_
€ ≟ € = yes refl
€ ≟ £ = no (λ ())
€ ≟ $ = no (λ ())
€ ≟ ¥ = no (λ ())
£ ≟ € = no (λ ())
£ ≟ £ = yes refl
£ ≟ $ = no (λ ())
£ ≟ ¥ = no (λ ())
$ ≟ € = no (λ ())
$ ≟ £ = no (λ ())
$ ≟ $ = yes refl
$ ≟ ¥ = no (λ ())
¥ ≟ € = no (λ ())
¥ ≟ £ = no (λ ())
¥ ≟ $ = no (λ ())
¥ ≟ ¥ = yes refl
sumNotions : {c : Currency} → List Trade → Money c
sumNotions [] = mkMoney 0ℚ
sumNotions {c} (record { tPrice = record { currency = currency; money = money }; tQty = tQty } ∷ xs) with c ≟ currency
... | yes refl = (tQty * money) + sumNotions xs
... | no _ = sumNotions xs
_/1 : ℕ → ℚ
n /1 = + n / 1
testTrades : List Trade
testTrades =
mkTrade (mkSomeMoney £ (1 /1)) (100 /1)
∷ mkTrade (mkSomeMoney £ (2 /1)) (200 /1)
∷ mkTrade (mkSomeMoney $ (3 /1)) (300 /1)
∷ mkTrade (mkSomeMoney ¥ (5 /1)) (50 /1)
∷ []
open import Text.Printf using (printf)
showℚ : ℚ → String
showℚ record {numerator = n; denominator-1 = 0} = printf "%d" n
showℚ record {numerator = n; denominator-1 = d} = printf "%d/%u" n (suc d)
showCurrency : Currency → String
showCurrency € = "€"
showCurrency £ = "£"
showCurrency $ = "$"
showCurrency ¥ = "¥"
showMoney : {c : Currency} → Money c → String
showMoney {c} (mkMoney amount) = (printf "%s %s") (showCurrency c) (showℚ amount)
main : Builtin.IO (Colist ⊤)
main = run ∘ sequence ∘ fromList $$
putStrLn "Hello, World!"
∷ putStrLn (showMoney $$ sumNotions {€} testTrades)
∷ putStrLn (showMoney $$ sumNotions {£} testTrades)
∷ putStrLn (showMoney $$ sumNotions {$} testTrades)
∷ putStrLn (showMoney $$ sumNotions {¥} testTrades)
∷ []
| 27.612069
| 119
| 0.621917
|
13fac4ef0b1b08c0e6df0ec4084f8e6af184b34d
| 312
|
agda
|
Agda
|
test/Succeed/NoPatternMatching.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/NoPatternMatching.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/NoPatternMatching.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --no-pattern-matching #-}
id : {A : Set} (x : A) → A
id x = x
const : {A B : Set} (x : A) (y : B) → A
const x y = x
happ : {A B C : Set} (f : A → B → C) (g : A → B) (x : A) → C
happ f g x = f x (g x)
K = const
S = happ
I : {A : Set} (x : A) → A
I {A} = S K (K {B = A})
-- Mmh, pretty boring...
| 16.421053
| 60
| 0.423077
|
3033241692107d6a9b0fe7c7479f72fcf1f5631c
| 2,691
|
agda
|
Agda
|
Hazelnut-checks.agda
|
hazelgrove/agda-tfp16
|
86a755ca6749e080f9a03287e34d1cda889f1edb
|
[
"MIT"
] | 2
|
2016-06-10T04:35:39.000Z
|
2016-06-10T04:35:42.000Z
|
Hazelnut-checks.agda
|
hazelgrove/agda-tfp16
|
86a755ca6749e080f9a03287e34d1cda889f1edb
|
[
"MIT"
] | null | null | null |
Hazelnut-checks.agda
|
hazelgrove/agda-tfp16
|
86a755ca6749e080f9a03287e34d1cda889f1edb
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import List
open import Hazelnut-core
module Hazelnut-checks where
-----------------------------------------------------------------------------
-- these theorems aren't listed in the draft, but have been discussed
-- since submission. broadly speaking, they act as sanity checks on the
-- rules. if these properties can't be proven for any extensions to the
-- language, then the rules are not good.
-----------------------------------------------------------------------------
-- movement doesn't change the term other than moving the focus around.
moveerase : {e e' : ê} {δ : direction} {t : τ̇} →
(e + move δ +>e e') →
(e ◆e) == (e' ◆e)
moveerase EMAscFirstChild = refl
moveerase EMAscParent1 = refl
moveerase EMAscParent2 = refl
moveerase EMAscNextSib = refl
moveerase EMAscPrevSib = refl
moveerase EMLamFirstChild = refl
moveerase EMLamParent = refl
moveerase EMPlusFirstChild = refl
moveerase EMPlusParent1 = refl
moveerase EMPlusParent2 = refl
moveerase EMPlusNextSib = refl
moveerase EMPlusPrevSib = refl
moveerase EMApFirstChild = refl
moveerase EMApParent1 = refl
moveerase EMApParent2 = refl
moveerase EMApNextSib = refl
moveerase EMApPrevSib = refl
moveerase EMFHoleFirstChild = refl
moveerase EMFHoleParent = refl
-- describes lists of action whose semantics are composable
data iterok : Set where
-- iterates a list of actions that can be composed
data iterate : iterok → ê → ê → Set where
--constructability
mutual
constructable1 : {Γ : ·ctx} {e : ê} {t : τ̇} →
(wt : Γ ⊢ (e ◆e) => t) →
Σ[ αs ∈ iterok ]
(Σ[ e' ∈ ê ] ((iterate αs (▹ <||> ◃) e') ×
((e ◆e) == (e' ◆e))))
constructable1 = {!!}
constructable2 : {Γ : ·ctx} {e : ê} {t : τ̇} →
(wt : Γ ⊢ (e ◆e) <= t) →
Σ[ αs ∈ iterok ]
(Σ[ e' ∈ ê ] ((iterate αs (▹ <||> ◃) e') ×
((e ◆e) == (e' ◆e))))
constructable2 = {!!}
--reachability
mutual
reachable1 : {Γ : ·ctx} {e e' : ê} {t : τ̇}
(wt : Γ ⊢ (e ◆e) <= t) →
(wt' : Γ ⊢ (e' ◆e) <= t) →
(p : (e ◆e) == (e' ◆e)) →
Σ[ αs ∈ iterok ] (iterate αs e e')
reachable1 = {!!}
reachable2 : {Γ : ·ctx} {e e' : ê} {t : τ̇}
(wt : Γ ⊢ (e ◆e) => t) →
(wt' : Γ ⊢ (e' ◆e) => t) →
(p : (e ◆e) == (e' ◆e)) →
Σ[ αs ∈ iterok ] (iterate αs e e')
reachable2 = {!!}
| 34.948052
| 79
| 0.487179
|
22c3ea751a6040242164aeac58b92775e89dd1fc
| 19,658
|
agda
|
Agda
|
core/lib/types/Wedge.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/types/Wedge.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/types/Wedge.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 lib.Basics
open import lib.types.Coproduct
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Pushout
open import lib.types.PushoutFlattening
open import lib.types.PushoutFmap
open import lib.types.Sigma
open import lib.types.Span
open import lib.types.Unit
-- Wedge of two pointed types is defined as a particular case of pushout
module lib.types.Wedge where
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙∨-span : ⊙Span
⊙∨-span = ⊙span X Y ⊙Unit ⊙cst ⊙cst
⊙wedge-span = ⊙∨-span
∨-span : Span
∨-span = ⊙Span-to-Span ⊙∨-span
wedge-span = ∨-span
Wedge : Type (lmax i j)
Wedge = Pushout wedge-span
infix 80 _∨_
_∨_ = Wedge
⊙Wedge : Ptd (lmax i j)
⊙Wedge = ⊙Pushout ⊙wedge-span
infix 80 _⊙∨_
_⊙∨_ = ⊙Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
winl : de⊙ X → X ∨ Y
winl x = left x
winr : de⊙ Y → X ∨ Y
winr y = right y
wglue : winl (pt X) == winr (pt Y)
wglue = glue tt
⊙winl : X ⊙→ X ⊙∨ Y
⊙winl = (winl , idp)
⊙winr : Y ⊙→ X ⊙∨ Y
⊙winr = (winr , ! wglue)
module WedgeElim {k} {P : X ∨ Y → Type k}
(winl* : (x : de⊙ X) → P (winl x)) (winr* : (y : de⊙ Y) → P (winr y))
(glue* : winl* (pt X) == winr* (pt Y) [ P ↓ wglue ]) where
private
module M = PushoutElim winl* winr* (λ _ → glue*)
f = M.f
glue-β = M.glue-β unit
∨-elim = WedgeElim.f
Wedge-elim = WedgeElim.f
module WedgeRec {k} {C : Type k} (winl* : de⊙ X → C) (winr* : de⊙ Y → C)
(glue* : winl* (pt X) == winr* (pt Y)) where
private
module M = PushoutRec {d = wedge-span X Y} winl* winr* (λ _ → glue*)
f = M.f
glue-β = M.glue-β unit
∨-rec = WedgeRec.f
Wedge-rec = WedgeRec.f
module ⊙WedgeRec {k} {Z : Ptd k} (g : X ⊙→ Z) (h : Y ⊙→ Z) where
open WedgeRec (fst g) (fst h) (snd g ∙ ! (snd h)) public
⊙f : X ⊙∨ Y ⊙→ Z
⊙f = (f , snd g)
⊙winl-β : ⊙f ⊙∘ ⊙winl == g
⊙winl-β = idp
⊙winr-β : ⊙f ⊙∘ ⊙winr == h
⊙winr-β = ⊙λ=' (λ _ → idp) lemma where
abstract
lemma : snd (⊙f ⊙∘ ⊙winr) == snd h
lemma =
ap (_∙ snd g)
(ap-! f wglue ∙ ap ! glue-β ∙ !-∙ (snd g) (! (snd h)))
∙ ∙-assoc (! (! (snd h))) (! (snd g)) (snd g)
∙ ap (! (! (snd h)) ∙_) (!-inv-l (snd g))
∙ ∙-unit-r (! (! (snd h)))
∙ !-! (snd h)
⊙∨-rec = ⊙WedgeRec.⊙f
⊙Wedge-rec = ⊙WedgeRec.⊙f
⊙Wedge-rec-post∘ : ∀ {k l} {Z : Ptd k} {W : Ptd l}
(k : Z ⊙→ W) (g : X ⊙→ Z) (h : Y ⊙→ Z)
→ k ⊙∘ ⊙Wedge-rec g h ⊙∼ ⊙Wedge-rec (k ⊙∘ g) (k ⊙∘ h)
⊙Wedge-rec-post∘ k g h =
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in' $ ⊙WedgeRec.glue-β (k ⊙∘ g) (k ⊙∘ h)
∙ lemma (fst k) (snd g) (snd h) (snd k)
∙ ! (ap (ap (fst k)) (⊙WedgeRec.glue-β g h))
∙ ∘-ap (fst k) (fst (⊙Wedge-rec g h)) wglue)) ,
idp
where
lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z : A} {w : B}
(p : x == z) (q : y == z) (r : f z == w)
→ (ap f p ∙ r) ∙ ! (ap f q ∙ r) == ap f (p ∙ ! q)
lemma f idp idp idp = idp
⊙∨-rec-post∘ = ⊙Wedge-rec-post∘
⊙Wedge-rec-η : ⊙Wedge-rec ⊙winl ⊙winr == ⊙idf (X ⊙∨ Y)
⊙Wedge-rec-η = ⊙λ='
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in' $ ap-idf wglue
∙ ! (!-! wglue)
∙ ! (⊙WedgeRec.glue-β ⊙winl ⊙winr)))
idp
⊙∨-rec-η = ⊙Wedge-rec-η
add-wglue : de⊙ (X ⊙⊔ Y) → X ∨ Y
add-wglue (inl x) = winl x
add-wglue (inr y) = winr y
⊙add-wglue : X ⊙⊔ Y ⊙→ X ⊙∨ Y
⊙add-wglue = add-wglue , idp
module Projl = ⊙WedgeRec (⊙idf X) (⊙cst {X = Y})
module Projr = ⊙WedgeRec (⊙cst {X = X}) (⊙idf Y)
projl = Projl.f
projr = Projr.f
⊙projl = Projl.⊙f
⊙projr = Projr.⊙f
module WedgeToProduct = ⊙WedgeRec ((_, pt Y) , idp) ((pt X ,_), idp)
∨-⊙to-× : X ⊙∨ Y ⊙→ X ⊙× Y
∨-⊙to-× = WedgeToProduct.⊙f
∨-to-× : X ∨ Y → de⊙ (X ⊙× Y)
∨-to-× = WedgeToProduct.f
∨-to-×-glue-β : ap ∨-to-× wglue == idp
∨-to-×-glue-β = WedgeToProduct.glue-β
abstract
↓-∨to×=cst-in : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}
→ p == p'
→ p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ]
↓-∨to×=cst-in {p' = idp} q =
↓-app=cst-in' (q ∙ ! WedgeToProduct.glue-β)
↓-∨to×=cst-out : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}
→ p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ]
→ p == p'
↓-∨to×=cst-out {p' = idp} q =
↓-app=cst-out' q ∙ WedgeToProduct.glue-β
↓-∨to×=cst-β : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}
(q : p == p')
→ ↓-∨to×=cst-out (↓-∨to×=cst-in q) == q
↓-∨to×=cst-β {p' = idp} idp =
ap (_∙ WedgeToProduct.glue-β) (↓-app=cst-β' {p = wglue} (! WedgeToProduct.glue-β))
∙ !-inv-l WedgeToProduct.glue-β
↓-∨to×=cst-η : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}
(q : p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ])
→ ↓-∨to×=cst-in (↓-∨to×=cst-out q) == q
↓-∨to×=cst-η {p = p} {p' = idp} q =
ap ↓-app=cst-in'
( ∙-assoc (↓-app=cst-out' q) WedgeToProduct.glue-β (! WedgeToProduct.glue-β)
∙ ap (↓-app=cst-out' q ∙_) (!-inv-r WedgeToProduct.glue-β)
∙ ∙-unit-r (↓-app=cst-out' q))
∙ ↓-app=cst-η' q
module Fold {i} {X : Ptd i} = ⊙WedgeRec (⊙idf X) (⊙idf X)
fold = Fold.f
⊙fold = Fold.⊙f
module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}
(fX : X ⊙→ X') (fY : Y ⊙→ Y') where
wedge-span-map : SpanMap (wedge-span X Y) (wedge-span X' Y')
wedge-span-map = span-map (fst fX) (fst fY) (idf _)
(comm-sqr λ _ → snd fX)
(comm-sqr λ _ → snd fY)
module WedgeFmap where
private
module M = PushoutFmap wedge-span-map
f = M.f
glue-β = M.glue-β unit
∨-fmap : X ∨ Y → X' ∨ Y'
∨-fmap = WedgeFmap.f
⊙∨-fmap : X ⊙∨ Y ⊙→ X' ⊙∨ Y'
⊙∨-fmap = ∨-fmap , ap winl (snd fX)
Wedge-fmap = ∨-fmap
⊙Wedge-fmap = ⊙∨-fmap
module _ {i₀ i₁ i₂ j₀ j₁ j₂} {X₀ : Ptd i₀} {X₁ : Ptd i₁} {X₂ : Ptd i₂}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {Y₂ : Ptd j₂}
where
∨-fmap-∘ :
(gX : X₁ ⊙→ X₂) (fX : X₀ ⊙→ X₁)
(gY : Y₁ ⊙→ Y₂) (fY : Y₀ ⊙→ Y₁)
→ ∨-fmap (gX ⊙∘ fX) (gY ⊙∘ fY) ∼ ∨-fmap gX gY ∘ ∨-fmap fX fY
∨-fmap-∘ (gX , idp) (fX , idp) (gY , idp) (fY , idp) =
Pushout-fmap-∘ (wedge-span-map (gX , idp) (gY , idp)) (wedge-span-map (fX , idp) (fY , idp))
⊙∨-fmap-∘ :
(gX : X₁ ⊙→ X₂) (fX : X₀ ⊙→ X₁)
(gY : Y₁ ⊙→ Y₂) (fY : Y₀ ⊙→ Y₁)
→ ⊙∨-fmap (gX ⊙∘ fX) (gY ⊙∘ fY) ⊙∼ ⊙∨-fmap gX gY ⊙∘ ⊙∨-fmap fX fY
⊙∨-fmap-∘ (gX , idp) (fX , idp) (gY , idp) (fY , idp) =
∨-fmap-∘ (gX , idp) (fX , idp) (gY , idp) (fY , idp) , idp
Wedge-fmap-∘ = ∨-fmap-∘
⊙Wedge-fmap-∘ = ⊙∨-fmap-∘
module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}
(eqX : X ⊙≃ X') (eqY : Y ⊙≃ Y') where
wedge-span-emap : SpanEquiv (wedge-span X Y) (wedge-span X' Y')
wedge-span-emap = wedge-span-map (⊙–> eqX) (⊙–> eqY)
, snd eqX , snd eqY , idf-is-equiv _
∨-emap : X ∨ Y ≃ X' ∨ Y'
∨-emap = Pushout-emap wedge-span-emap
⊙∨-emap : X ⊙∨ Y ⊙≃ X' ⊙∨ Y'
⊙∨-emap = ≃-to-⊙≃ ∨-emap (ap winl (⊙–>-pt eqX))
Wedge-emap = ∨-emap
⊙Wedge-emap = ⊙∨-emap
module _ {i i' j j' k} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j}
{Y' : Ptd j'} {Z : Ptd k} (winl* : X' ⊙→ Z) (winr* : Y' ⊙→ Z)
(f : X ⊙→ X') (g : Y ⊙→ Y') where
⊙Wedge-rec-fmap :
⊙Wedge-rec winl* winr* ⊙∘ ⊙∨-fmap f g
⊙∼ ⊙Wedge-rec (winl* ⊙∘ f) (winr* ⊙∘ g)
⊙Wedge-rec-fmap =
Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ winl* winr* f g) ,
lemma₁ winl* winr* f
where
abstract
lemma₀ : ∀ {X' Y' Z} (winl* : X' ⊙→ Z) (winr* : Y' ⊙→ Z)
(f : X ⊙→ X') (g : Y ⊙→ Y')
→ ap (⊙WedgeRec.f winl* winr* ∘ ∨-fmap f g) wglue
== ap (⊙WedgeRec.f (winl* ⊙∘ f) (winr* ⊙∘ g)) wglue
lemma₀ (winl* , idp) (winr* , winr*-pt) (f , idp) (g , idp) =
ap (Wedge-rec winl* winr* (! winr*-pt) ∘ ∨-fmap (f , idp) (g , idp)) wglue
=⟨ ap-∘ (Wedge-rec winl* winr* (! winr*-pt)) (∨-fmap (f , idp) (g , idp)) wglue ⟩
ap (Wedge-rec winl* winr* (! winr*-pt)) (ap (∨-fmap (f , idp) (g , idp)) wglue)
=⟨ ap (ap (Wedge-rec winl* winr* (! winr*-pt))) $ WedgeFmap.glue-β (f , idp) (g , idp) ⟩
ap (Wedge-rec winl* winr* (! winr*-pt)) wglue
=⟨ WedgeRec.glue-β winl* winr* (! winr*-pt) ⟩
! winr*-pt
=⟨ ! $ WedgeRec.glue-β (winl* ∘ f) (winr* ∘ g) (! winr*-pt) ⟩
ap (Wedge-rec (winl* ∘ f) (winr* ∘ g) (! winr*-pt)) wglue
=∎
lemma₁ : ∀ {X' Z} (winl* : X' ⊙→ Z) (winr* : Y' ⊙→ Z) (f : X ⊙→ X')
→ snd (⊙Wedge-rec winl* winr* ⊙∘ ⊙∨-fmap f g)
== snd (⊙Wedge-rec (winl* ⊙∘ f) (winr* ⊙∘ g))
lemma₁ (f , idp) _ (winl* , idp) = idp
⊙∨-rec-fmap = ⊙Wedge-rec-fmap
module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j}
{Y' : Ptd j'} (f : X ⊙→ X') (g : Y ⊙→ Y') where
⊙projl-fmap : ⊙projl ⊙∘ ⊙∨-fmap f g ⊙∼ ⊙Wedge-rec f ⊙cst
⊙projl-fmap =
Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ f g) , lemma₁ f g
where
abstract
lemma₀ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')
→ ap (projl ∘ ∨-fmap f g) wglue
== ap (⊙WedgeRec.f f ⊙cst) wglue
lemma₀ (f , idp) (g , idp) =
ap (projl ∘ ∨-fmap (f , idp) (g , idp)) wglue
=⟨ ap-∘ projl (∨-fmap (f , idp) (g , idp)) wglue ⟩
ap projl (ap (∨-fmap (f , idp) (g , idp)) wglue)
=⟨ ap (ap projl) (WedgeFmap.glue-β (f , idp) (g , idp)) ⟩
ap projl wglue
=⟨ Projl.glue-β ⟩
idp
=⟨ ! $ ⊙WedgeRec.glue-β (f , idp) ⊙cst ⟩
ap (⊙WedgeRec.f (f , idp) ⊙cst) wglue
=∎
lemma₁ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')
→ snd (⊙projl ⊙∘ ⊙∨-fmap f g)
== snd (⊙Wedge-rec {Y = Y} f ⊙cst)
lemma₁ (f , idp) (g , idp) = idp
⊙projr-fmap : ⊙projr ⊙∘ ⊙∨-fmap f g ⊙∼ ⊙Wedge-rec ⊙cst g
⊙projr-fmap =
Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ f g) , lemma₁ f g
where
abstract
lemma₀ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')
→ ap (projr ∘ ∨-fmap f g) wglue
== ap (⊙WedgeRec.f ⊙cst g) wglue
lemma₀ (f , idp) (g , idp) =
ap (projr ∘ ∨-fmap (f , idp) (g , idp)) wglue
=⟨ ap-∘ projr (∨-fmap (f , idp) (g , idp)) wglue ⟩
ap projr (ap (∨-fmap (f , idp) (g , idp)) wglue)
=⟨ ap (ap projr) (WedgeFmap.glue-β (f , idp) (g , idp)) ⟩
ap projr wglue
=⟨ Projr.glue-β ⟩
idp
=⟨ ! $ ⊙WedgeRec.glue-β ⊙cst (g , idp) ⟩
ap (⊙WedgeRec.f ⊙cst (g , idp)) wglue
=∎
lemma₁ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')
→ snd (⊙projr ⊙∘ ⊙∨-fmap f g)
== snd (⊙Wedge-rec {X = X} ⊙cst g)
lemma₁ (f , idp) (g , idp) = idp
module _ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : X ⊙→ Z) (g : Y ⊙→ Z) where
{- favonia: This is a special case, but still proved separately to make sure
it has good computational content. (Maybe this is overkilling.) -}
⊙fold-fmap : ⊙fold ⊙∘ ⊙∨-fmap f g ⊙∼ ⊙Wedge-rec f g
⊙fold-fmap =
Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ f g) , lemma₁ f g
where
abstract
lemma₀ : ∀ {Z} (f : X ⊙→ Z) (g : Y ⊙→ Z)
→ ap (⊙WedgeRec.f (⊙idf _) (⊙idf _) ∘ ∨-fmap f g) wglue
== ap (⊙WedgeRec.f f g) wglue
lemma₀ (f , idp) (g , g-pt) =
ap (⊙WedgeRec.f (⊙idf _) (⊙idf _) ∘ ∨-fmap (f , idp) (g , g-pt)) wglue
=⟨ ap-∘
(⊙WedgeRec.f (⊙idf _) (⊙idf _))
(∨-fmap (f , idp) (g , g-pt))
wglue ⟩
ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) (ap (∨-fmap (f , idp) (g , g-pt)) wglue)
=⟨ ap (ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)))
(WedgeFmap.glue-β (f , idp) (g , g-pt)) ⟩
ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) (wglue ∙' ap winr (! g-pt))
=⟨ ap-∙' (⊙WedgeRec.f (⊙idf _) (⊙idf _)) wglue (ap winr (! g-pt)) ⟩
ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) wglue
∙' ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) (ap winr (! g-pt))
=⟨ ap2 _∙'_
(⊙WedgeRec.glue-β (⊙idf _) (⊙idf _))
( ∘-ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) winr (! g-pt)
∙ ap-idf (! g-pt)) ⟩
idp ∙' ! g-pt
=⟨ ∙'-unit-l (! g-pt) ⟩
! g-pt
=⟨ ! $ ⊙WedgeRec.glue-β (f , idp) (g , g-pt) ⟩
ap (⊙WedgeRec.f (f , idp) (g , g-pt) ) wglue
=∎
lemma₁ : ∀ {Z} (f : X ⊙→ Z) (g : Y ⊙→ Z)
→ snd (⊙Wedge-rec (⊙idf _) (⊙idf _) ⊙∘ ⊙∨-fmap f g)
== snd (⊙Wedge-rec f g)
lemma₁ (f , idp) (g , g-pt) = idp
module _ {i j k} (X : Ptd i) (Y : Ptd j) (Z : Ptd k) where
module WedgeAssocInl = WedgeRec {C = X ∨ (Y ⊙∨ Z)} winl (winr ∘ winl) wglue
module WedgeAssoc = WedgeRec {X = X ⊙∨ Y} WedgeAssocInl.f (winr ∘ winr) (wglue ∙ ap winr wglue)
∨-assoc : (X ⊙∨ Y) ∨ Z ≃ X ∨ (Y ⊙∨ Z)
∨-assoc = equiv to from to-from from-to where
to : (X ⊙∨ Y) ∨ Z → X ∨ (Y ⊙∨ Z)
to = WedgeAssoc.f
module FromInr = WedgeRec {C = (X ⊙∨ Y) ∨ Z} (winl ∘ winr) winr (! (ap winl wglue) ∙ wglue)
module From = WedgeRec {Y = Y ⊙∨ Z} (winl ∘ winl) FromInr.f (ap winl wglue)
from : X ∨ (Y ⊙∨ Z) → (X ⊙∨ Y) ∨ Z
from = From.f
abstract
to-from : ∀ x → to (from x) == x
to-from = Wedge-elim
(λ x → idp)
(Wedge-elim (λ y → idp) (λ z → idp) $ ↓-='-in' $ ! $
ap (to ∘ FromInr.f) wglue
=⟨ ap-∘ to FromInr.f wglue ⟩
ap to (ap FromInr.f wglue)
=⟨ ap (ap to) FromInr.glue-β ⟩
ap to (! (ap winl wglue) ∙ wglue)
=⟨ ap-∙ to (! (ap winl wglue)) wglue ⟩
ap to (! (ap winl wglue)) ∙ ap to wglue
=⟨ _∙2_ (ap-! to (ap winl wglue) ∙ ap ! (∘-ap to winl wglue ∙ WedgeAssocInl.glue-β)) WedgeAssoc.glue-β ⟩
! wglue ∙ wglue ∙ ap winr wglue
=⟨ ! $ ∙-assoc (! wglue) wglue (ap winr wglue) ⟩
(! wglue ∙ wglue) ∙ ap winr wglue
=⟨ ap (_∙ ap winr wglue) (!-inv-l wglue) ⟩
ap winr wglue
=∎)
(↓-∘=idf-in' to from (ap (ap to) From.glue-β ∙ ∘-ap to winl wglue ∙ WedgeAssocInl.glue-β))
from-to : ∀ x → from (to x) == x
from-to = Wedge-elim
(Wedge-elim (λ x → idp) (λ y → idp) $ ↓-='-in' $ ! $
ap-∘ from WedgeAssocInl.f wglue ∙ ap (ap from) WedgeAssocInl.glue-β ∙ From.glue-β)
(λ z → idp)
(↓-∘=idf-in' from to $
ap from (ap to wglue)
=⟨ ap (ap from) WedgeAssoc.glue-β ⟩
ap from (wglue ∙ ap winr wglue)
=⟨ ap-∙ from wglue (ap winr wglue) ⟩
ap from wglue ∙ ap from (ap winr wglue)
=⟨ From.glue-β ∙2 (∘-ap from winr wglue ∙ FromInr.glue-β) ⟩
ap winl wglue ∙ ! (ap winl wglue) ∙ wglue
=⟨ ! $ ∙-assoc (ap winl wglue) (! (ap winl wglue)) wglue ⟩
(ap winl wglue ∙ ! (ap winl wglue)) ∙ wglue
=⟨ ap (_∙ wglue) (!-inv-r (ap winl wglue)) ⟩
wglue
=∎)
⊙∨-assoc : (X ⊙∨ Y) ⊙∨ Z ⊙≃ X ⊙∨ (Y ⊙∨ Z)
⊙∨-assoc = ≃-to-⊙≃ ∨-assoc idp
{-
module _ {i₀ i₁ j₀ j₁ k₀ k₁}
{X₀ : Ptd i₀} {Y₀ : Ptd j₀} {Z₀ : Ptd k₀}
{X₁ : Ptd i₁} {Y₁ : Ptd j₁} {Z₁ : Ptd k₁}
where
⊙∨-assoc-nat : ∀ (f : X₀ ⊙→ X₁) (g : Y₀ ⊙→ Y₁) (h : Z₀ ⊙→ Z₁)
→ ⊙–> (⊙∨-assoc X₁ Y₁ Z₁) ⊙∘ ⊙∨-fmap (⊙∨-fmap f g) h
⊙∼ ⊙∨-fmap f (⊙∨-fmap g h) ⊙∘ ⊙–> (⊙∨-assoc X₀ Y₀ Z₀)
⊙∨-assoc-nat (f , idp) (g , idp) (h , idp) =
(Wedge-elim
-- {P = –> (∨-assoc X₁ Y₁ Z₁) ∘ ∨-fmap (⊙∨-fmap f g) h ∼ ∨-fmap f (⊙∨-fmap g h) ∘ –> (∨-assoc X₀ Y₀ Z₀)}
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in' $
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)) ∘ WedgeAssocInl.f X₀ Y₀ Z₀) wglue
=⟨ ap-∘ (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (WedgeAssocInl.f X₀ Y₀ Z₀) wglue ⟩
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (ap (WedgeAssocInl.f X₀ Y₀ Z₀) wglue)
=⟨ ap (ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)))) (WedgeAssocInl.glue-β X₀ Y₀ Z₀) ⟩
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) wglue
=⟨ WedgeFmap.glue-β (f , idp) (⊙∨-fmap (g , idp) (h , idp)) ⟩
wglue
=⟨ ! $ WedgeAssocInl.glue-β X₁ Y₁ Z₁ ⟩
ap (WedgeAssocInl.f X₁ Y₁ Z₁) wglue
=⟨ ! $ ap (ap (WedgeAssocInl.f X₁ Y₁ Z₁)) $ WedgeFmap.glue-β (f , idp) (g , idp) ⟩
ap (WedgeAssocInl.f X₁ Y₁ Z₁) (ap (∨-fmap (f , idp) (g , idp)) wglue)
=⟨ ∘-ap (WedgeAssocInl.f X₁ Y₁ Z₁) (∨-fmap (f , idp) (g , idp)) wglue ⟩
ap (WedgeAssocInl.f X₁ Y₁ Z₁ ∘ ∨-fmap (f , idp) (g , idp)) wglue
=∎))
(λ _ → idp)
(↓-='-in' $
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)) ∘ WedgeAssoc.f X₀ Y₀ Z₀) wglue
=⟨ ap-∘ (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (WedgeAssoc.f X₀ Y₀ Z₀) wglue ⟩
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (ap (WedgeAssoc.f X₀ Y₀ Z₀) wglue)
=⟨ ap (ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)))) (WedgeAssoc.glue-β X₀ Y₀ Z₀) ⟩
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (wglue ∙ ap winr wglue)
=⟨ ap-∙ (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) wglue (ap winr wglue) ⟩
ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) wglue
∙ ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (ap winr wglue)
=⟨ ap2 _∙_
(WedgeFmap.glue-β (f , idp) (⊙∨-fmap (g , idp) (h , idp)))
( ∘-ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) winr wglue
∙ ap-∘ winr (∨-fmap (g , idp) (h , idp)) wglue
∙ ap (ap winr) (WedgeFmap.glue-β (g , idp) (h , idp))) ⟩
wglue ∙ ap winr wglue
=⟨ ! $ WedgeAssoc.glue-β X₁ Y₁ Z₁ ⟩
ap (WedgeAssoc.f X₁ Y₁ Z₁) wglue
=⟨ ! $ ap (ap (WedgeAssoc.f X₁ Y₁ Z₁)) $ WedgeFmap.glue-β (⊙∨-fmap (f , idp) (g , idp)) (h , idp) ⟩
ap (WedgeAssoc.f X₁ Y₁ Z₁) (ap (∨-fmap (⊙∨-fmap (f , idp) (g , idp)) (h , idp)) wglue)
=⟨ ∘-ap (WedgeAssoc.f X₁ Y₁ Z₁) (∨-fmap (⊙∨-fmap (f , idp) (g , idp)) (h , idp)) wglue ⟩
ap (WedgeAssoc.f X₁ Y₁ Z₁ ∘ ∨-fmap (⊙∨-fmap (f , idp) (g , idp)) (h , idp)) wglue
=∎))
,
idp
-}
module _ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(f : X ⊙→ W) (g : Y ⊙→ W) (h : Z ⊙→ W) where
⊙Wedge-rec-assoc : ⊙Wedge-rec (⊙Wedge-rec f g) h
⊙∼ ⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘ ⊙–> (⊙∨-assoc X Y Z)
⊙Wedge-rec-assoc =
(Wedge-elim
(Wedge-elim (λ x → idp) (λ y → idp)
(↓-='-in' $
ap-∘ (⊙WedgeRec.f f (⊙Wedge-rec g h)) (WedgeAssocInl.f X Y Z) wglue
∙ ap (ap (⊙WedgeRec.f f (⊙Wedge-rec g h))) (WedgeAssocInl.glue-β X Y Z)
∙ ⊙WedgeRec.glue-β f (⊙Wedge-rec g h)
∙ ! (⊙WedgeRec.glue-β f g)))
(λ z → idp)
(↓-='-in' $
ap-∘ (⊙WedgeRec.f f (⊙Wedge-rec g h)) (WedgeAssoc.f X Y Z) wglue
∙ ap (ap (⊙WedgeRec.f f (⊙Wedge-rec g h))) (WedgeAssoc.glue-β X Y Z)
∙ ap-∙ (⊙WedgeRec.f f (⊙Wedge-rec g h)) wglue (ap winr wglue)
∙ _∙2_ (⊙WedgeRec.glue-β f (⊙Wedge-rec g h))
( ∘-ap (⊙WedgeRec.f f (⊙Wedge-rec g h)) winr wglue
∙ ⊙WedgeRec.glue-β g h)
∙ ∙-assoc (snd f) (! (snd g)) (snd g ∙ ! (snd h))
∙ ap (snd f ∙_) (! $ ∙-assoc (! (snd g)) (snd g) (! (snd h)))
∙ ap (λ p → snd f ∙ p ∙ ! (snd h)) (!-inv-l (snd g))
∙ ! (⊙WedgeRec.glue-β (⊙Wedge-rec f g) h)))
,
idp
⊙∨-rec-assoc = ⊙Wedge-rec-assoc
| 37.44381
| 116
| 0.448469
|
1a276be7495fc14b1af17d24bcd328f9920e6f95
| 10,706
|
agda
|
Agda
|
core/lib/PathOver.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/PathOver.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/PathOver.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.PathFunctor
open import lib.PathGroupoid
open import lib.Equivalence
{- Structural lemmas about paths over paths
The lemmas here have the form
[↓-something-in] : introduction rule for the something
[↓-something-out] : elimination rule for the something
[↓-something-β] : β-reduction rule for the something
[↓-something-η] : η-reduction rule for the something
The possible somethings are:
[cst] : constant fibration
[cst2] : fibration constant in the second argument
[cst2×] : fibration constant and nondependent in the second argument
[ap] : the path below is of the form [ap f p]
[fst×] : the fibration is [fst] (nondependent product)
[snd×] : the fibration is [snd] (nondependent product)
The rule of prime: The above lemmas should choose
between [_∙_] and [_∙'_] in a way that, if the underlying path is [idp],
then the entire lemma reduces to an identity function.
Otherwise, the lemma would have the suffix [in'] or [out'], meaning that
all the choices of [_∙_] or [_∙'_] are exactly the opposite ones.
You can also go back and forth between dependent paths and homogeneous paths
with a transport on one side with the functions
[to-transp], [from-transp], [to-transp-β]
[to-transp!], [from-transp!], [to-transp!-β]
More lemmas about paths over paths are present in the lib.types.* modules
(depending on the type constructor of the fibration)
-}
module lib.PathOver where
{- Dependent paths in a constant fibration -}
module _ {i j} {A : Type i} {B : Type j} where
↓-cst-in : {x y : A} {p : x == y} {u v : B}
→ u == v
→ u == v [ (λ _ → B) ↓ p ]
↓-cst-in {p = idp} q = q
↓-cst-out : {x y : A} {p : x == y} {u v : B}
→ u == v [ (λ _ → B) ↓ p ]
→ u == v
↓-cst-out {p = idp} q = q
↓-cst-β : {x y : A} (p : x == y) {u v : B} (q : u == v)
→ (↓-cst-out (↓-cst-in {p = p} q) == q)
↓-cst-β idp q = idp
{- Interaction of [↓-cst-in] with [_∙_] -}
↓-cst-in-∙ : {x y z : A} (p : x == y) (q : y == z) {u v w : B}
(p' : u == v) (q' : v == w)
→ ↓-cst-in {p = p ∙ q} (p' ∙ q')
== ↓-cst-in {p = p} p' ∙ᵈ ↓-cst-in {p = q} q'
↓-cst-in-∙ idp idp idp idp = idp
{- Interaction of [↓-cst-in] with [_∙'_] -}
↓-cst-in-∙' : {x y z : A} (p : x == y) (q : y == z) {u v w : B}
(p' : u == v) (q' : v == w)
→ ↓-cst-in {p = p ∙' q} (p' ∙' q')
== ↓-cst-in {p = p} p' ∙'ᵈ ↓-cst-in {p = q} q'
↓-cst-in-∙' idp idp idp idp = idp
{- Introduction of an equality between [↓-cst-in]s (used to deduce the
recursor from the eliminator in HIT with 2-paths) -}
↓-cst-in2 : {a a' : A} {u v : B}
{p₀ : a == a'} {p₁ : a == a'} {q₀ q₁ : u == v} {q : p₀ == p₁}
→ q₀ == q₁
→ (↓-cst-in {p = p₀} q₀ == ↓-cst-in {p = p₁} q₁ [ (λ p → u == v [ (λ _ → B) ↓ p ]) ↓ q ])
↓-cst-in2 {p₀ = idp} {p₁ = .idp} {q₀} {q₁} {idp} k = k
-- Dependent paths in a fibration constant in the second argument
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where
↓-cst2-in : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ u == v [ B ↓ p ]
→ u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ]
↓-cst2-in idp idp r = r
↓-cst2-out : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ]
→ u == v [ B ↓ p ]
↓-cst2-out idp idp r = r
-- Dependent paths in a fibration constant and non dependent in the
-- second argument
module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} where
↓-cst2×-in : {x y : A} (p : x == y) {b c : C}
(q : b == c) {u : B x} {v : B y}
→ u == v [ B ↓ p ]
→ u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ]
↓-cst2×-in idp idp r = r
↓-cst2×-out : {x y : A} (p : x == y) {b c : C}
(q : b == c) {u : B x} {v : B y}
→ u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ]
→ u == v [ B ↓ p ]
↓-cst2×-out idp idp r = r
-- Dependent paths in the universal fibration over the universe
↓-idf-out : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B}
→ u == v [ (λ x → x) ↓ p ]
→ coe p u == v
↓-idf-out idp = idf _
↓-idf-in : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B}
→ coe p u == v
→ u == v [ (λ x → x) ↓ p ]
↓-idf-in idp = idf _
-- Dependent paths over [ap f p]
module _ {i j k} {A : Type i} {B : Type j} (C : B → Type k) (f : A → B) where
↓-ap-in : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}
→ u == v [ C ∘ f ↓ p ]
→ u == v [ C ↓ ap f p ]
↓-ap-in {p = idp} idp = idp
↓-ap-out : {x y : A} (p : x == y) {u : C (f x)} {v : C (f y)}
→ u == v [ C ↓ ap f p ]
→ u == v [ C ∘ f ↓ p ]
↓-ap-out idp idp = idp
-- Dependent paths over [ap2 f p q]
module _ {i j k l} {A : Type i} {B : Type j} {C : Type k} (D : C → Type l)
(f : A → B → C) where
↓-ap2-in : {x y : A} {p : x == y} {w z : B} {q : w == z}
{u : D (f x w)} {v : D (f y z)}
→ u == v [ D ∘ uncurry f ↓ pair×= p q ]
→ u == v [ D ↓ ap2 f p q ]
↓-ap2-in {p = idp} {q = idp} α = α
↓-ap2-out : {x y : A} {p : x == y} {w z : B} {q : w == z}
{u : D (f x w)} {v : D (f y z)}
→ u == v [ D ↓ ap2 f p q ]
→ u == v [ D ∘ uncurry f ↓ pair×= p q ]
↓-ap2-out {p = idp} {q = idp} α = α
apd↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
(f : {a : A} (b : B a) → C a b) {x y : A} {p : x == y}
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ f u == f v [ (λ xy → C (fst xy) (snd xy)) ↓ pair= p q ]
apd↓ f {p = idp} idp = idp
apd↓=apd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A}
(p : x == y) → (apd f p == ↓-ap-out _ _ p (apd↓ {A = Unit} f {p = idp} p))
apd↓=apd f idp = idp
-- Paths in the fibrations [fst] and [snd]
module _ {i j} where
↓-fst×-out : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B')
{u : A} {v : A'}
→ u == v [ fst ↓ pair×= p q ]
→ u == v [ (λ X → X) ↓ p ]
↓-fst×-out idp idp h = h
↓-snd×-in : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B')
{u : B} {v : B'}
→ u == v [ (λ X → X) ↓ q ]
→ u == v [ snd ↓ pair×= p q ]
↓-snd×-in idp idp h = h
-- Mediating dependent paths with the transport version
module _ {i j} {A : Type i} where
from-transp : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (transport B p u == v)
→ (u == v [ B ↓ p ])
from-transp B idp idp = idp
to-transp : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (transport B p u == v)
to-transp {p = idp} idp = idp
to-transp-β : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : transport B p u == v)
→ to-transp (from-transp B p q) == q
to-transp-β B idp idp = idp
to-transp-η : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
(q : u == v [ B ↓ p ])
→ from-transp B p (to-transp q) == q
to-transp-η {p = idp} idp = idp
to-transp-equiv : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (transport B p u == v)
to-transp-equiv B p =
equiv to-transp (from-transp B p) (to-transp-β B p) (to-transp-η)
from-transp! : (B : A → Type j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (u == transport! B p v)
→ (u == v [ B ↓ p ])
from-transp! B idp idp = idp
to-transp! : {B : A → Type j}
{a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (u == transport! B p v)
to-transp! {p = idp} idp = idp
to-transp!-β : (B : A → Type j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : u == transport! B p v)
→ to-transp! (from-transp! B p q) == q
to-transp!-β B idp idp = idp
to-transp!-η : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
(q : u == v [ B ↓ p ])
→ from-transp! B p (to-transp! q) == q
to-transp!-η {p = idp} idp = idp
to-transp!-equiv : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (u == transport! B p v)
to-transp!-equiv B p =
equiv to-transp! (from-transp! B p) (to-transp!-β B p) (to-transp!-η)
{- Various other lemmas -}
{- Used for defining the recursor from the eliminator for 1-HIT -}
apd=cst-in : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}
{a a' : A} {p : a == a'} {q : f a == f a'}
→ apd f p == ↓-cst-in q → ap f p == q
apd=cst-in {p = idp} x = x
↓-apd-out : ∀ {i j k} {A : Type i} {B : A → Type j} (C : (a : A) → B a → Type k)
{f : Π A B} {x y : A} {p : x == y}
{q : f x == f y [ B ↓ p ]} (r : apd f p == q)
{u : C x (f x)} {v : C y (f y)}
→ u == v [ uncurry C ↓ pair= p q ]
→ u == v [ (λ z → C z (f z)) ↓ p ]
↓-apd-out C {p = idp} idp idp = idp
↓-ap-out= : ∀ {i j k} {A : Type i} {B : Type j} (C : (b : B) → Type k)
(f : A → B) {x y : A} (p : x == y)
{q : f x == f y} (r : ap f p == q)
{u : C (f x)} {v : C (f y)}
→ u == v [ C ↓ q ]
→ u == v [ (λ z → C (f z)) ↓ p ]
↓-ap-out= C f idp idp idp = idp
-- No idea what that is
to-transp-weird : ∀ {i j} {A : Type i} {B : A → Type j}
{u v : A} {d : B u} {d' d'' : B v} {p : u == v}
(q : d == d' [ B ↓ p ]) (r : transport B p d == d'')
→ (from-transp B p r ∙'ᵈ (! r ∙ to-transp q)) == q
to-transp-weird {p = idp} idp idp = idp
-- Something not really clear yet
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → C) (g : B → C)
where
↓-swap : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
→ (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
→ (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
↓-swap {p = idp} {q = idp} r s t = (! t) ∙ ∙'-unit-l s ∙ ! (∙-unit-r s)
↓-swap! : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
→ (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
→ (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
↓-swap! {p = idp} {q = idp} r s t = ∙'-unit-l s ∙ ! (∙-unit-r s) ∙ (! t)
↓-swap-β : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
(t : ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
→ ↓-swap! r s (↓-swap r s t) == t
↓-swap-β {p = idp} {q = idp} r s t = coh (∙'-unit-l s) (∙-unit-r s) t where
coh : ∀ {i} {X : Type i} {x y z t : X} (p : x == y) (q : z == y) (r : x == t)
→ p ∙ ! q ∙ ! (! r ∙ p ∙ ! q) == r
coh idp idp idp = idp
transp-↓ : ∀ {i j} {A : Type i} (P : A → Type j) {a₁ a₂ : A}
(p : a₁ == a₂) (y : P a₂) → transport P (! p) y == y [ P ↓ p ]
transp-↓ _ idp _ = idp
transp-ap-↓ : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) (h : A → B)
{a₁ a₂ : A} (p : a₁ == a₂) (y : P (h a₂))
→ transport P (! (ap h p)) y == y [ P ∘ h ↓ p ]
transp-ap-↓ _ _ idp _ = idp
| 34.647249
| 93
| 0.441341
|
0611058d4dba5379ad330dbf7deec75b6b811f6f
| 1,267
|
agda
|
Agda
|
Cats/Category/Fun/Facts.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Fun/Facts.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Fun/Facts.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
module Cats.Category.Fun.Facts where
open import Cats.Category
open import Cats.Category.Cat using (_≈_)
open import Cats.Category.Fun using (Trans ; Fun ; ≈-intro ; ≈-elim)
open import Cats.Functor using (Functor)
open import Cats.Trans.Iso using (NatIso ; iso ; forth-natural ; back-natural)
open import Level using (_⊔_)
open Functor
open Trans
open Category._≅_
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈}
{D : Category lo′ la′ l≈′}
{F G : Functor C D}
where
private
module C = Category C
module D = Category D
open D.≈-Reasoning
open Category (Fun C D) using (_≅_)
NatIso→≅ : NatIso F G → F ≅ G
NatIso→≅ i = record
{ forth = Forth i
; back = Back i
; back-forth = ≈-intro (back-forth (iso i))
; forth-back = ≈-intro (forth-back (iso i))
}
where
open NatIso
≅→NatIso : F ≅ G → NatIso F G
≅→NatIso i = record
{ iso = λ {c} → record
{ forth = component (forth i) c
; back = component (back i) c
; back-forth = ≈-elim (back-forth i)
; forth-back = ≈-elim (forth-back i)
}
; forth-natural = natural (forth i)
}
≈→≅ : F ≈ G → F ≅ G
≈→≅ eq = NatIso→≅ eq
≅→≈ : F ≅ G → F ≈ G
≅→≈ i = ≅→NatIso i
| 21.844828
| 78
| 0.562747
|
a0a7c84b653976f1d841c01b66587da2827a2870
| 14,695
|
agda
|
Agda
|
Numbers/BinaryNaturals/Addition.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Numbers/BinaryNaturals/Addition.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Numbers/BinaryNaturals/Addition.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Lists.Lists
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Order
open import Numbers.BinaryNaturals.Definition
open import Semirings.Definition
open import Orders.Total.Definition
module Numbers.BinaryNaturals.Addition where
-- Define the monoid structure, and show that it's the same as ℕ's
_+Binherit_ : BinNat → BinNat → BinNat
a +Binherit b = NToBinNat (binNatToN a +N binNatToN b)
_+B_ : BinNat → BinNat → BinNat
[] +B b = b
(x :: a) +B [] = x :: a
(zero :: xs) +B (y :: ys) = y :: (xs +B ys)
(one :: xs) +B (zero :: ys) = one :: (xs +B ys)
(one :: xs) +B (one :: ys) = zero :: incr (xs +B ys)
+BCommutative : (a b : BinNat) → a +B b ≡ b +B a
+BCommutative [] [] = refl
+BCommutative [] (x :: b) = refl
+BCommutative (x :: a) [] = refl
+BCommutative (zero :: as) (zero :: bs) rewrite +BCommutative as bs = refl
+BCommutative (zero :: as) (one :: bs) rewrite +BCommutative as bs = refl
+BCommutative (one :: as) (zero :: bs) rewrite +BCommutative as bs = refl
+BCommutative (one :: as) (one :: bs) rewrite +BCommutative as bs = refl
private
+BIsInherited[] : (b : BinNat) (prB : b ≡ canonical b) → [] +Binherit b ≡ [] +B b
+BIsInherited[] [] prB = refl
+BIsInherited[] (zero :: b) prB = t
where
refine : (b : BinNat) → zero :: b ≡ canonical (zero :: b) → b ≡ canonical b
refine b pr with canonical b
refine b pr | x :: bl = ::Inj pr
t : NToBinNat (0 +N binNatToN (zero :: b)) ≡ zero :: b
t with TotalOrder.totality ℕTotalOrder 0 (binNatToN b)
t | inl (inl pos) = transitivity (doubleIsBitShift (binNatToN b) pos) (applyEquality (zero ::_) (transitivity (binToBin b) (equalityCommutative (refine b prB))))
t | inl (inr ())
... | inr eq with binNatToNZero b (equalityCommutative eq)
... | u with canonical b
t | inr eq | u | [] = exFalso (bad b prB)
where
bad : (c : BinNat) → zero :: c ≡ [] → False
bad c ()
t | inr eq | () | x :: bl
+BIsInherited[] (one :: b) prB = ans
where
ans : NToBinNat (binNatToN (one :: b)) ≡ one :: b
ans = transitivity (binToBin (one :: b)) (equalityCommutative prB)
-- Show that the monoid structure of ℕ is the same as that of BinNat
+BIsInherited : (a b : BinNat) (prA : a ≡ canonical a) (prB : b ≡ canonical b) → a +Binherit b ≡ a +B b
+BinheritLemma : (a : BinNat) (b : BinNat) (prA : a ≡ canonical a) (prB : b ≡ canonical b) → incr (NToBinNat ((binNatToN a +N binNatToN b) +N ((binNatToN a +N binNatToN b) +N zero))) ≡ one :: (a +B b)
+BIsInherited' : (a b : BinNat) → a +Binherit b ≡ canonical (a +B b)
+BinheritLemma a b prA prB with TotalOrder.totality ℕTotalOrder 0 (binNatToN a +N binNatToN b)
+BinheritLemma a b prA prB | inl (inl x) rewrite doubleIsBitShift (binNatToN a +N binNatToN b) x = applyEquality (one ::_) (+BIsInherited a b prA prB)
+BinheritLemma a b prA prB | inr x with sumZeroImpliesSummandsZero (equalityCommutative x)
+BinheritLemma a b prA prB | inr x | fst ,, snd = ans2
where
bad : b ≡ []
bad = transitivity prB (binNatToNZero b snd)
bad2 : a ≡ []
bad2 = transitivity prA (binNatToNZero a fst)
ans2 : incr (NToBinNat ((binNatToN a +N binNatToN b) +N ((binNatToN a +N binNatToN b) +N zero))) ≡ one :: (a +B b)
ans2 rewrite bad | bad2 = refl
+BIsInherited [] b _ prB = +BIsInherited[] b prB
+BIsInherited (x :: a) [] prA _ = transitivity (applyEquality NToBinNat (Semiring.commutative ℕSemiring (binNatToN (x :: a)) 0)) (transitivity (binToBin (x :: a)) (equalityCommutative prA))
+BIsInherited (zero :: as) (zero :: b) prA prB with TotalOrder.totality ℕTotalOrder 0 (binNatToN as +N binNatToN b)
... | inl (inl 0<) rewrite Semiring.commutative ℕSemiring (binNatToN as) 0 | Semiring.commutative ℕSemiring (binNatToN b) 0 | Semiring.+Associative ℕSemiring (binNatToN as +N binNatToN as) (binNatToN b) (binNatToN b) | equalityCommutative (Semiring.+Associative ℕSemiring (binNatToN as) (binNatToN as) (binNatToN b)) | Semiring.commutative ℕSemiring (binNatToN as) (binNatToN b) | Semiring.+Associative ℕSemiring (binNatToN as) (binNatToN b) (binNatToN as) | equalityCommutative (Semiring.+Associative ℕSemiring (binNatToN as +N binNatToN b) (binNatToN as) (binNatToN b)) | Semiring.commutative ℕSemiring 0 ((binNatToN as +N binNatToN b) +N (binNatToN as +N binNatToN b)) | equalityCommutative (Semiring.+Associative ℕSemiring (binNatToN as +N binNatToN b) (binNatToN as +N binNatToN b) 0) = transitivity (doubleIsBitShift (binNatToN as +N binNatToN b) (identityOfIndiscernablesRight _<N_ 0< (Semiring.commutative ℕSemiring (binNatToN b) _))) (applyEquality (zero ::_) (+BIsInherited as b (canonicalDescends as prA) (canonicalDescends b prB)))
+BIsInherited (zero :: as) (zero :: b) prA prB | inl (inr ())
... | inr p with sumZeroImpliesSummandsZero {binNatToN as} (equalityCommutative p)
+BIsInherited (zero :: as) (zero :: b) prA prB | inr p | as=0 ,, b=0 rewrite as=0 | b=0 = exFalso ans
where
bad : (b : BinNat) → (pr : b ≡ canonical b) → (pr2 : binNatToN b ≡ 0) → b ≡ []
bad b pr pr2 = transitivity pr (binNatToNZero b pr2)
t : b ≡ canonical b
t with canonical b
t | x :: bl = ::Inj prB
u : b ≡ []
u = bad b t b=0
nono : {A : Set} → {a : A} → {as : List A} → a :: as ≡ [] → False
nono ()
ans : False
ans with inspect (canonical b)
ans | [] with≡ x rewrite x = nono prB
ans | (x₁ :: y) with≡ x = nono (transitivity (equalityCommutative x) (transitivity (equalityCommutative t) u))
+BIsInherited (zero :: as) (one :: b) prA prB rewrite Semiring.commutative ℕSemiring (binNatToN as +N (binNatToN as +N zero)) (succ (binNatToN b +N (binNatToN b +N zero))) | Semiring.commutative ℕSemiring (binNatToN b +N (binNatToN b +N zero)) (binNatToN as +N (binNatToN as +N zero)) | equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN b)) = +BinheritLemma as b (canonicalDescends as prA) (canonicalDescends b prB)
+BIsInherited (one :: as) (zero :: bs) prA prB rewrite equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN bs)) = +BinheritLemma as bs (canonicalDescends as prA) (canonicalDescends bs prB)
+BIsInherited (one :: as) (one :: bs) prA prB rewrite Semiring.commutative ℕSemiring (binNatToN as +N (binNatToN as +N zero)) (succ (binNatToN bs +N (binNatToN bs +N zero))) | Semiring.commutative ℕSemiring (binNatToN bs +N (binNatToN bs +N zero)) (2 *N binNatToN as) | equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN bs)) | +BinheritLemma as bs (canonicalDescends as prA) (canonicalDescends bs prB) = refl
+BIsInherited'[] : (b : BinNat) → [] +Binherit b ≡ canonical ([] +B b)
+BIsInherited'[] [] = refl
+BIsInherited'[] (zero :: b) with inspect (canonical b)
+BIsInherited'[] (zero :: b) | [] with≡ pr rewrite binNatToNZero' b pr | pr = refl
+BIsInherited'[] (zero :: b) | (x :: bl) with≡ pr rewrite pr = ans
where
contr : {a : _} {A : Set a} {l1 l2 : List A} → {x : A} → l1 ≡ [] → l1 ≡ x :: l2 → False
contr {l1 = []} p1 ()
contr {l1 = x :: l1} () p2
ans : NToBinNat (binNatToN b +N (binNatToN b +N zero)) ≡ zero :: x :: bl
ans with inspect (binNatToN b)
ans | zero with≡ th rewrite th = exFalso (contr (binNatToNZero b th) pr)
ans | succ th with≡ blah rewrite blah | doubleIsBitShift' th = applyEquality (zero ::_) (transitivity (equalityCommutative u) pr)
where
u : canonical b ≡ incr (NToBinNat th)
u = transitivity (equalityCommutative (binToBin b)) (applyEquality NToBinNat blah)
+BIsInherited'[] (one :: b) with inspect (binNatToN b)
... | zero with≡ pr rewrite pr = applyEquality (one ::_) (equalityCommutative (binNatToNZero b pr))
... | (succ bl) with≡ pr = ans
where
u : NToBinNat (2 *N binNatToN b) ≡ zero :: canonical b
u with doubleIsBitShift' bl
... | t = transitivity (identityOfIndiscernablesLeft _≡_ t (applyEquality (λ i → NToBinNat (2 *N i)) (equalityCommutative pr))) (applyEquality (zero ::_) (transitivity (applyEquality NToBinNat (equalityCommutative pr)) (binToBin b)))
ans : incr (NToBinNat (binNatToN b +N (binNatToN b +N zero))) ≡ one :: canonical b
ans = applyEquality incr u
+BIsInherited' [] b = +BIsInherited'[] b
+BIsInherited' (zero :: a) [] with inspect (binNatToN a)
+BIsInherited' (zero :: a) [] | zero with≡ x rewrite x | binNatToNZero a x = refl
+BIsInherited' (zero :: a) [] | succ y with≡ x rewrite x | Semiring.commutative ℕSemiring (y +N succ (y +N 0)) 0 = transitivity (doubleIsBitShift' y) (transitivity (applyEquality (λ i → (zero :: NToBinNat i)) (equalityCommutative x)) (transitivity (applyEquality (λ i → zero :: i) (binToBin a)) (canonicalAscends' {zero} a bad)))
where
bad : canonical a ≡ [] → False
bad pr with transitivity (equalityCommutative x) (transitivity (equalityCommutative (binNatToNIsCanonical a)) (applyEquality binNatToN pr))
bad pr | ()
+BIsInherited' (one :: a) [] with inspect (binNatToN a)
+BIsInherited' (one :: a) [] | 0 with≡ x rewrite x | binNatToNZero a x = refl
+BIsInherited' (one :: a) [] | succ n with≡ x rewrite x | doubleIsBitShift' n = applyEquality incr {_} {zero :: canonical a} (transitivity {x = _} {NToBinNat (2 *N succ n)} bl (transitivity (doubleIsBitShift' n) (applyEquality (zero ::_) (transitivity (applyEquality NToBinNat (equalityCommutative x)) (binToBin a)))))
where
bl : incr (NToBinNat ((n +N succ (n +N 0)) +N 0)) ≡ NToBinNat (succ (n +N succ (n +N 0)))
bl rewrite equalityCommutative x | Semiring.commutative ℕSemiring (n +N succ (n +N 0)) 0 = refl
+BIsInherited' (zero :: as) (zero :: bs) rewrite equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN bs)) = ans
where
ans : NToBinNat (2 *N (binNatToN as +N binNatToN bs)) ≡ canonical (zero :: (as +B bs))
ans with inspect (binNatToN as +N binNatToN bs)
ans | zero with≡ x with sumZeroImpliesSummandsZero {binNatToN as} x
... | as=0 ,, bs=0 rewrite as=0 | bs=0 = foo
where
u : canonical (as +Binherit bs) ≡ []
u rewrite as=0 | bs=0 = refl
foo : [] ≡ canonical (zero :: (as +B bs))
foo = transitivity (transitivity b (applyEquality (λ i → canonical (zero :: i)) (+BIsInherited' as bs))) (canonicalAscends'' {zero} (as +B bs))
where
b : [] ≡ canonical (zero :: (as +Binherit bs))
b rewrite u = refl
ans | succ y with≡ x rewrite x | doubleIsBitShift' y = transitivity (applyEquality (λ i → zero :: NToBinNat i) (equalityCommutative x)) ans2
where
u : 0 <N binNatToN (as +B bs)
u rewrite equalityCommutative (binNatToNIsCanonical (as +B bs)) | equalityCommutative (+BIsInherited' as bs) | x | nToN (succ y) = succIsPositive y
ans2 : zero :: NToBinNat (binNatToN as +N binNatToN bs) ≡ canonical (zero :: (as +B bs))
ans2 rewrite +BIsInherited' as bs = canonicalAscends (as +B bs) u
+BIsInherited' (zero :: as) (one :: bs) rewrite Semiring.commutative ℕSemiring (2 *N binNatToN as) (succ (2 *N binNatToN bs)) | Semiring.commutative ℕSemiring (2 *N binNatToN bs) (2 *N binNatToN as) | equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN bs)) = ans2
where
ans2 : incr (NToBinNat (2 *N (binNatToN as +N binNatToN bs))) ≡ one :: canonical (as +B bs)
ans2 with inspect (binNatToN as +N binNatToN bs)
ans2 | zero with≡ x with sumZeroImpliesSummandsZero {binNatToN as} x
ans2 | zero with≡ x | as=0 ,, bs=0 rewrite as=0 | bs=0 = applyEquality (one ::_) (transitivity t (+BIsInherited' as bs))
where
t : [] ≡ as +Binherit bs
t rewrite as=0 | bs=0 = refl
ans2 | succ y with≡ x rewrite x | doubleIsBitShift' y = applyEquality (one ::_) (transitivity (applyEquality NToBinNat (equalityCommutative x)) (+BIsInherited' as bs))
+BIsInherited' (one :: as) (zero :: bs) rewrite equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN bs)) = ans
where
ans : incr (NToBinNat (2 *N (binNatToN as +N binNatToN bs))) ≡ one :: canonical (as +B bs)
ans with inspect (binNatToN as +N binNatToN bs)
ans | zero with≡ x with sumZeroImpliesSummandsZero {binNatToN as} x
... | as=0 ,, bs=0 rewrite as=0 | bs=0 = applyEquality (one ::_) (transitivity t (+BIsInherited' as bs))
where
t : [] ≡ NToBinNat (binNatToN as +N binNatToN bs)
t rewrite as=0 | bs=0 = refl
ans | succ y with≡ x rewrite x | doubleIsBitShift' y = applyEquality (one ::_) (transitivity (applyEquality NToBinNat (equalityCommutative x)) (+BIsInherited' as bs))
+BIsInherited' (one :: as) (one :: bs) rewrite Semiring.commutative ℕSemiring (2 *N binNatToN as) (succ (2 *N binNatToN bs)) | Semiring.commutative ℕSemiring (2 *N binNatToN bs) (2 *N binNatToN as) | equalityCommutative (Semiring.+DistributesOver* ℕSemiring 2 (binNatToN as) (binNatToN bs)) = ans
where
ans : incr (incr (NToBinNat (2 *N (binNatToN as +N binNatToN bs)))) ≡ canonical (zero :: incr (as +B bs))
ans with inspect (binNatToN as +N binNatToN bs)
... | zero with≡ x with sumZeroImpliesSummandsZero {binNatToN as} x
ans | zero with≡ x | as=0 ,, bs=0 rewrite as=0 | bs=0 = bar
where
u' : canonical (as +Binherit bs) ≡ []
u' rewrite as=0 | bs=0 = refl
u : canonical (as +B bs) ≡ []
u rewrite equalityCommutative (+BIsInherited' as bs) = transitivity (NToBinNatIsCanonical (binNatToN as +N binNatToN bs)) u'
t : canonical (incr (as +B bs)) ≡ one :: []
t rewrite incrPreservesCanonical' (as +B bs) | u = refl
bar : zero :: one :: [] ≡ canonical (zero :: incr (as +B bs))
bar rewrite t = refl
ans | succ y with≡ x rewrite x | doubleIsBitShift' y = transitivity (applyEquality (λ i → zero :: incr (NToBinNat i)) (equalityCommutative x)) ans2
where
ans2 : zero :: incr (as +Binherit bs) ≡ canonical (zero :: incr (as +B bs))
ans2 rewrite +BIsInherited' as bs | equalityCommutative (incrPreservesCanonical' (as +B bs)) | canonicalAscends' {zero} (incr (as +B bs)) (incrNonzero (as +B bs)) = refl
+BIsHom : (a b : BinNat) → binNatToN (a +B b) ≡ (binNatToN a) +N (binNatToN b)
+BIsHom a b = transitivity (equalityCommutative (binNatToNIsCanonical (a +B b))) (transitivity (equalityCommutative (applyEquality binNatToN (+BIsInherited' a b))) (nToN _))
sumCanonical : (a b : BinNat) → canonical a ≡ a → canonical b ≡ b → canonical (a +B b) ≡ a +B b
sumCanonical a b a=a b=b = transitivity (equalityCommutative (+BIsInherited' a b)) (+BIsInherited a b (equalityCommutative a=a) (equalityCommutative b=b))
| 70.649038
| 1,043
| 0.660088
|
58f14596118a77fd037f41983143702cf988c784
| 26,868
|
agda
|
Agda
|
src/Categories/Category/Monoidal/Interchange.agda
|
o1lo01ol1o/agda-categories
|
5fc007768264a270b8ff319570225986773da601
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Monoidal/Interchange.agda
|
o1lo01ol1o/agda-categories
|
5fc007768264a270b8ff319570225986773da601
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Monoidal/Interchange.agda
|
o1lo01ol1o/agda-categories
|
5fc007768264a270b8ff319570225986773da601
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category; module Commutation)
open import Categories.Category.Monoidal.Core using (Monoidal)
-- The "four middle interchange" for monoidal categories.
--
-- Aka the "interchange law" or "exchange law" (though those terms are
-- more comonly used in the more general context of composition in
-- 2-categories).
module Categories.Category.Monoidal.Interchange
{o ℓ e} {C : Category o ℓ e} where
open import Level using (_⊔_)
open import Data.Product using (_,_)
import Categories.Category.Monoidal.Construction.Product as MonoidalProduct
open import Categories.Category.Monoidal.Braided using (Braided)
open import Categories.Category.Monoidal.Braided.Properties
using (braiding-coherence; inv-Braided; inv-braiding-coherence)
open import Categories.Category.Monoidal.Properties using (module Kelly's)
import Categories.Category.Monoidal.Reasoning as MonoidalReasoning
open import Categories.Category.Monoidal.Symmetric using (Symmetric)
import Categories.Category.Monoidal.Utilities as MonoidalUtilities
open import Categories.Category.Product using (_⁂_; assocˡ)
open import Categories.Functor using (_∘F_)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (_≃_; niHelper)
open import Categories.Morphism C using (_≅_; module ≅)
open import Categories.Morphism.IsoEquiv C using (module _≃_)
open import Categories.Morphism.Reasoning C
private module C = Category C
open C
open Commutation C
private
variable
W W₁ W₂ X X₁ X₂ Y Y₁ Y₂ Z Z₁ Z₂ : Obj
f g h i : X ⇒ Y
-- An abstract definition of an interchange map with the minimal set
-- of coherence laws required to make the tensor product ⊗ of C a
-- monoidal functor. (See also Categories.Functor.Monoidal.Tensor.)
record HasInterchange (M : Monoidal C) : Set (o ⊔ ℓ ⊔ e) where
open Monoidal M
open MonoidalUtilities.Shorthands M
-- The "four middle interchange" for tensor products.
field swapInner : ∀ {W X Y Z} → (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z)
module swapInner {W X Y Z} = _≅_ (swapInner {W} {X} {Y} {Z})
private
i⇒ = swapInner.from
i⇐ = swapInner.to
-- Naturality and coherence laws of the interchange.
field
natural : i⇒ ∘ (f ⊗₁ g) ⊗₁ (h ⊗₁ i) ≈ (f ⊗₁ h) ⊗₁ (g ⊗₁ i) ∘ i⇒
assoc : [ ((X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂)) ⊗₀ (Z₁ ⊗₀ Z₂) ⇒
(X₁ ⊗₀ (Y₁ ⊗₀ Z₁)) ⊗₀ (X₂ ⊗₀ (Y₂ ⊗₀ Z₂)) ]⟨
i⇒ ⊗₁ id ⇒⟨ ((X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂)) ⊗₀ (Z₁ ⊗₀ Z₂) ⟩
i⇒ ⇒⟨ ((X₁ ⊗₀ Y₁) ⊗₀ Z₁) ⊗₀ ((X₂ ⊗₀ Y₂) ⊗₀ Z₂) ⟩
α⇒ ⊗₁ α⇒
≈ α⇒ ⇒⟨ (X₁ ⊗₀ X₂) ⊗₀ ((Y₁ ⊗₀ Y₂) ⊗₀ (Z₁ ⊗₀ Z₂)) ⟩
id ⊗₁ i⇒ ⇒⟨ (X₁ ⊗₀ X₂) ⊗₀ ((Y₁ ⊗₀ Z₁) ⊗₀ (Y₂ ⊗₀ Z₂)) ⟩
i⇒
⟩
unitˡ : [ unit ⊗₀ (X ⊗₀ Y) ⇒ (X ⊗₀ Y) ]⟨
λ⇐ ⊗₁ id ⇒⟨ (unit ⊗₀ unit) ⊗₀ (X ⊗₀ Y) ⟩
i⇒ ⇒⟨ (unit ⊗₀ X) ⊗₀ (unit ⊗₀ Y) ⟩
λ⇒ ⊗₁ λ⇒
≈ λ⇒
⟩
unitʳ : [ (X ⊗₀ Y) ⊗₀ unit ⇒ (X ⊗₀ Y) ]⟨
id ⊗₁ λ⇐ ⇒⟨ (X ⊗₀ Y) ⊗₀ (unit ⊗₀ unit) ⟩
i⇒ ⇒⟨ (X ⊗₀ unit) ⊗₀ (Y ⊗₀ unit) ⟩
ρ⇒ ⊗₁ ρ⇒
≈ ρ⇒
⟩
-- The interchange is a natural isomorphism.
naturalIso : ⊗ ∘F (⊗ ⁂ ⊗) ≃ ⊗ ∘F MonoidalProduct.⊗ M M
naturalIso = niHelper (record
{ η = λ _ → i⇒
; η⁻¹ = λ _ → i⇐
; commute = λ _ → natural
; iso = λ _ → swapInner.iso
})
-- Shorthands for composing and inverting isomorphisms.
open ≅ using () renaming (refl to idᵢ; sym to _⁻¹)
private
infixr 9 _∘ᵢ_
_∘ᵢ_ = λ {X Y Z} f g → ≅.trans {X} {Y} {Z} g f
-- Braided monoidal categories have an interchange map.
module BraidedInterchange {M : Monoidal C} (B : Braided M) where
open MonoidalReasoning M
open MonoidalUtilities M
open Braided B renaming (associator to α)
open Shorthands
-- Shorthands for braiding.
private
σ : X ⊗₀ Y ≅ Y ⊗₀ X
σ = braiding.FX≅GX
module σ {X Y} = _≅_ (σ {X} {Y})
σ⇒ = σ.from
σ⇐ = σ.to
-- The "four middle interchange" for braided tensor products.
swapInner : (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z)
swapInner = α ⁻¹ ∘ᵢ idᵢ ⊗ᵢ (α ∘ᵢ σ ⊗ᵢ idᵢ ∘ᵢ α ⁻¹) ∘ᵢ α
module swapInner {W X Y Z} = _≅_ (swapInner {W} {X} {Y} {Z})
private
i⇒ = swapInner.from
i⇐ = swapInner.to
-- The interchange is a natural isomorphism.
swapInner-natural : i⇒ ∘ (f ⊗₁ g) ⊗₁ (h ⊗₁ i) ≈ (f ⊗₁ h) ⊗₁ (g ⊗₁ i) ∘ i⇒
swapInner-natural {f = f} {g = g} {h = h} {i = i} = begin
(α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ (f ⊗₁ g) ⊗₁ (h ⊗₁ i)
≈⟨ pullʳ (pullʳ assoc-commute-from) ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ f ⊗₁ g ⊗₁ (h ⊗₁ i) ∘ α⇒
≈⟨ refl⟩∘⟨ extendʳ (parallel id-comm-sym (begin
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ g ⊗₁ (h ⊗₁ i)
≈⟨ pullʳ (pullʳ assoc-commute-to) ⟩
α⇒ ∘ σ⇒ ⊗₁ id ∘ (g ⊗₁ h) ⊗₁ i ∘ α⇐
≈⟨ refl⟩∘⟨ extendʳ (parallel (braiding.⇒.commute _) id-comm-sym) ⟩
α⇒ ∘ (h ⊗₁ g) ⊗₁ i ∘ σ⇒ ⊗₁ id ∘ α⇐
≈⟨ extendʳ assoc-commute-from ⟩
h ⊗₁ (g ⊗₁ i) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐
∎)) ⟩
α⇐ ∘ f ⊗₁ h ⊗₁ (g ⊗₁ i) ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ extendʳ assoc-commute-to ⟩
(f ⊗₁ h) ⊗₁ (g ⊗₁ i) ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
∎
swapInner-naturalIsomorphism : ⊗ ∘F (⊗ ⁂ ⊗) ≃ ⊗ ∘F MonoidalProduct.⊗ M M
swapInner-naturalIsomorphism = niHelper (record
{ η = λ _ → i⇒
; η⁻¹ = λ _ → i⇐
; commute = λ _ → swapInner-natural
; iso = λ _ → swapInner.iso
})
-- Another version of the interchange that associates differently.
--
-- Why are there two versions and what's the difference? The domain
-- (X₁ ⊗ X₂) ⊗₀ (Y₁ ⊗ Y₂) and codomain (X₁ ⊗ Y₁) ⊗₀ (X₁ ⊗ Y₂) of the
-- interchange map are perfectly symmetric/balanced. But in order to
-- apply the braiding to the middle X₂ and Y₁, we need to
-- re-associate and that breaks the symmetry. We must first
-- re-associate the whole expression in one direction and then the
-- larger subterm in the other. This can be done in two ways,
-- associate to the right first, then to the left, resulting in X₁ ⊗
-- ((Y₂ ⊗₀ X₁) ⊗ Y₂), or vice versa, resulting in (X₁ ⊗ (Y₂ ⊗₀ X₁))
-- ⊗ Y₂. The choice is arbitrary and results in two distinct
-- interchange maps that behave the same way (as witnessed by
-- swapInner-coherent below).
--
-- Why define both? Because the proofs of some coherence laws become
-- easier when the core of the expression is associated in one
-- direction vs. the other. For example swapInner-unitˡ is easier to
-- prove for the second definition, while swapInner-unitʳ is easier
-- to prove for the first; swapInner-assoc uses both.
swapInner′ : (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z)
swapInner′ = α ∘ᵢ (α ⁻¹ ∘ᵢ idᵢ ⊗ᵢ σ ∘ᵢ α) ⊗ᵢ idᵢ ∘ᵢ α ⁻¹
module swapInner′ {W X Y Z} = _≅_ (swapInner′ {W} {X} {Y} {Z})
private
j⇒ = swapInner′.from
j⇐ = swapInner′.to
-- Derived coherence laws.
swapInner-coherent : [ (X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ⇒ (X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂) ]⟨
i⇒
≈ j⇒
⟩
swapInner-coherent = begin
α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
α⇐ ∘ id ⊗₁ α⇒ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ refl⟩∘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
α⇐ ∘ id ⊗₁ α⇒ ∘ id ⊗₁ (σ⇒ ⊗₁ id) ∘ id ⊗₁ α⇐ ∘ α⇒
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ conjugate-from α (idᵢ ⊗ᵢ α) (⟺ pentagon) ⟩
α⇐ ∘ id ⊗₁ α⇒ ∘ id ⊗₁ (σ⇒ ⊗₁ id) ∘ (α⇒ ∘ α⇒ ⊗₁ id) ∘ α⇐
≈˘⟨ pullʳ (pullʳ (extendʳ (pushˡ assoc-commute-from))) ⟩
(α⇐ ∘ id ⊗₁ α⇒ ∘ α⇒ ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐
≈⟨ pushʳ sym-assoc ⟩∘⟨refl ⟩
((α⇐ ∘ id ⊗₁ α⇒ ∘ α⇒) ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐
≈⟨ pushˡ (conjugate-from (α ⊗ᵢ idᵢ) α (assoc ○ pentagon)) ⟩∘⟨refl ⟩
(α⇒ ∘ α⇐ ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐
≈˘⟨ pushʳ (pushʳ (pushˡ split₁ˡ)) ⟩
α⇒ ∘ α⇐ ⊗₁ id ∘ (id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
≈˘⟨ refl⟩∘⟨ pushˡ split₁ˡ ⟩
α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
∎
swapInner-assoc : [ ((X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂)) ⊗₀ (Z₁ ⊗₀ Z₂) ⇒
(X₁ ⊗₀ (Y₁ ⊗₀ Z₁)) ⊗₀ (X₂ ⊗₀ (Y₂ ⊗₀ Z₂)) ]⟨
i⇒ ⊗₁ id ⇒⟨ ((X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂)) ⊗₀ (Z₁ ⊗₀ Z₂) ⟩
i⇒ ⇒⟨ ((X₁ ⊗₀ Y₁) ⊗₀ Z₁) ⊗₀ ((X₂ ⊗₀ Y₂) ⊗₀ Z₂) ⟩
α⇒ ⊗₁ α⇒
≈ α⇒ ⇒⟨ (X₁ ⊗₀ X₂) ⊗₀ ((Y₁ ⊗₀ Y₂) ⊗₀ (Z₁ ⊗₀ Z₂)) ⟩
id ⊗₁ i⇒ ⇒⟨ (X₁ ⊗₀ X₂) ⊗₀ ((Y₁ ⊗₀ Z₁) ⊗₀ (Y₂ ⊗₀ Z₂)) ⟩
i⇒
⟩
swapInner-assoc = begin
α⇒ ⊗₁ α⇒ ∘ i⇒ ∘ i⇒ ⊗₁ id
≈⟨ (begin
α⇒ ⊗₁ α⇒
≈⟨ serialize₂₁ ⟩
id ⊗₁ α⇒ ∘ α⇒ ⊗₁ id
≈⟨ refl⟩∘⟨ switch-fromtoˡ α (switch-fromtoˡ (idᵢ ⊗ᵢ α) pentagon) ⟩
id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ α⇐ ∘ α⇒ ∘ α⇒
≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩⊗⟨ cancelˡ α.isoʳ ⟩∘⟨refl ⟩
id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ∘ α⇐) ∘ α⇒ ∘ α⇒
≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩⊗⟨ pullʳ inv-pentagon ⟩∘⟨refl ⟩
id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ ((α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ α⇐) ∘ α⇒ ∘ α⇒
≈⟨ refl⟩∘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘
id ⊗₁ (id ⊗₁ α⇐) ∘ α⇒ ∘ α⇒
≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ extendʳ assoc-commute-from ⟩
id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘
α⇒ ∘ (id ⊗₁ id) ⊗₁ α⇐ ∘ α⇒
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩∘⟨refl ⟩
id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒
∎) ⟩∘⟨refl ⟩
(id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒) ∘
i⇒ ∘ i⇒ ⊗₁ id
≈˘⟨ pullˡ (pushˡ (⊗.identity ⟩⊗⟨refl ⟩∘⟨refl)) ⟩
((id ⊗₁ id) ⊗₁ α⇒ ∘ α⇐) ∘
(id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒) ∘
(α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘
i⇒ ⊗₁ id
≈⟨ ⟺ assoc-commute-to ⟩∘⟨
pullʳ (pullʳ (pushʳ (pushˡ (pushʳ (pushˡ split₂ˡ))))) ⟩
(α⇐ ∘ id ⊗₁ (id ⊗₁ α⇒)) ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘
((id ⊗₁ α⇐ ∘ α⇒) ∘ α⇐ ∘ id ⊗₁ α⇒) ∘
(id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘
(α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id
≈⟨ pullʳ (refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ elimˡ (_≅_.isoˡ (α ⁻¹ ∘ᵢ idᵢ ⊗ᵢ α))) ⟩
α⇐ ∘ id ⊗₁ (id ⊗₁ α⇒) ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘
(id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘
(α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id
≈⟨ refl⟩∘⟨ merge₂ sym-assoc ⟩∘⟨
pushʳ ((⟺ ⊗.identity ⟩⊗⟨refl) ⟩∘⟨refl ⟩∘⟨ split₁ˡ) ⟩
α⇐ ∘ id ⊗₁ ((id ⊗₁ α⇒ ∘ α⇒) ∘ α⇐ ⊗₁ id ∘ α⇐) ∘
(α⇒ ∘ (id ⊗₁ id) ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘
α⇐ ⊗₁ id ∘ (id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id
≈⟨ refl⟩∘⟨ refl⟩⊗⟨
extendʳ (pushˡ (switch-fromtoʳ (α ⊗ᵢ idᵢ) (assoc ○ pentagon))) ⟩∘⟨
extendʳ assoc-commute-from ⟩∘⟨refl ⟩
α⇐ ∘ id ⊗₁ ((α⇒ ∘ α⇒) ∘ (α⇐ ⊗₁ id ∘ α⇐ ⊗₁ id) ∘ α⇐) ∘
(id ⊗₁ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ (α⇒ ∘ α⇒)) ∘ α⇐ ⊗₁ id ∘
(id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id
≈˘⟨ refl⟩∘⟨ refl⟩⊗⟨ pushʳ (refl⟩∘⟨ split₁ˡ ⟩∘⟨refl) ⟩∘⟨
pushʳ (extendʳ (switch-fromtoʳ (α ⊗ᵢ idᵢ) (assoc ○ pentagon))) ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐) ∘
id ⊗₁ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ id ⊗₁ α⇒ ∘ α⇒ ∘
(id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ split₁ˡ ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐) ∘
id ⊗₁ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ id ⊗₁ α⇒ ∘ α⇒ ∘
(id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐)) ⊗₁ id ∘ α⇒ ⊗₁ id
≈⟨ refl⟩∘⟨ merge₂ assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ assoc) ⟩∘⟨
refl⟩∘⟨ extendʳ assoc-commute-from ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘
id ⊗₁ α⇒ ∘
id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ∘ α⇒ ∘ α⇒ ⊗₁ id
≈⟨ refl⟩∘⟨ merge₂ (assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ assoc²')) ⟩∘⟨
refl⟩∘⟨ switch-fromtoˡ (idᵢ ⊗ᵢ α) pentagon ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘
id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ∘ id ⊗₁ α⇐ ∘ α⇒ ∘ α⇒
≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
α⇐ ∘ id ⊗₁
(α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘
id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ α⇒
≈⟨ refl⟩∘⟨ merge₂ assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ (assoc²' ○
(refl⟩∘⟨ refl⟩∘⟨ assoc))) ⟩∘⟨ Equiv.refl ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘
α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ α⇒
≈⟨ refl⟩∘⟨ refl⟩⊗⟨ pushʳ (begin
α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ extendʳ (pushˡ split₂ˡ) ⟩
α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id) ∘ (id ⊗₁ α⇐ ∘ α⇒) ∘
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈⟨ refl⟩∘⟨ refl⟩∘⟨ (extendʳ assoc-commute-to ○ (refl⟩∘⟨ sym-assoc)) ⟩
α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id ∘ (α⇐ ∘ (id ⊗₁ α⇐ ∘ α⇒)) ∘
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ (sym-assoc ○
(conjugate-to α (α ⊗ᵢ idᵢ) (sym-assoc ○ inv-pentagon))) ⟩∘⟨refl ⟩
α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id ∘ (α⇒ ⊗₁ id ∘ α⇐) ∘
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈˘⟨ refl⟩∘⟨ split₁ Equiv.refl ⟩∘⟨
pushʳ (refl⟩∘⟨ refl⟩⊗⟨ ⊗.identity ⟩∘⟨refl) ⟩
α⇒ ∘ ((α⇐ ∘ α⇐) ∘ id ⊗₁ σ⇒) ⊗₁ id ∘ α⇒ ⊗₁ id ∘ α⇐ ∘
(α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ α⇐
≈⟨ refl⟩∘⟨ merge₁ assoc² ⟩∘⟨ extendʳ assoc-commute-to ⟩
α⇒ ∘ (α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘
((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ⊗₁ id ∘ α⇐ ∘ α⇐
≈˘⟨ refl⟩∘⟨ pushˡ split₁ˡ ⟩
α⇒ ∘ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ⊗₁ id ∘
α⇐ ∘ α⇐
≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ (sym-assoc ○ inv-pentagon) ⟩
α⇒ ∘ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ⊗₁ id ∘
α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐
≈⟨ refl⟩∘⟨ pullˡ (⟺ split₁ˡ ○ (assoc ⟩⊗⟨refl)) ⟩
α⇒ ∘
((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐) ⊗₁ id ∘
α⇐ ∘ id ⊗₁ α⇐
≈⟨ refl⟩∘⟨ (begin
(α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈⟨ pushˡ (pushʳ sym-assoc) ⟩
(α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒ ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈⟨ (refl⟩∘⟨ extendʳ (pushʳ split₁ˡ)) ⟩
(α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒) ∘ (α⇒ ∘ α⇒ ⊗₁ id) ∘ (σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐
≈⟨ pushʳ (switch-fromtoˡ (idᵢ ⊗ᵢ α) pentagon ⟩∘⟨ pushˡ split₁ˡ) ⟩
((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒) ∘ (id ⊗₁ α⇐ ∘ α⇒ ∘ α⇒)) ∘
(σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐ ⊗₁ id ∘ α⇐
≈⟨ pushˡ (sym-assoc ○ (pullˡ (pullʳ assoc ⟩∘⟨refl))) ⟩
((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ id ⊗₁ α⇐) ∘ α⇒) ∘
α⇒ ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐ ⊗₁ id ∘ α⇐
≈⟨ pullʳ (refl⟩∘⟨ extendʳ assoc-commute-from) ⟩
(α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ id ⊗₁ α⇐) ∘ α⇒ ∘
σ⇒ ⊗₁ (id ⊗₁ id) ∘ α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐
≈⟨ (refl⟩∘⟨ refl⟩∘⟨ ⟺ split₂ˡ) ⟩∘⟨ refl⟩∘⟨ (refl⟩⊗⟨ ⊗.identity ⟩∘⟨
conjugate-from (idᵢ ⊗ᵢ (α ⁻¹)) (α ⁻¹) inv-pentagon) ⟩
(α⇐ ∘ α⇐ ∘ id ⊗₁ (σ⇒ ∘ α⇐)) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈˘⟨ extendʳ (sym-assoc ○ inv-pentagon) ⟩∘⟨refl ⟩
(α⇐ ⊗₁ id ∘ (α⇐ ∘ id ⊗₁ α⇐) ∘ id ⊗₁ (σ⇒ ∘ α⇐)) ∘
α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈˘⟨ (refl⟩∘⟨ pushʳ split₂ˡ) ⟩∘⟨refl ⟩
(α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ σ⇒ ∘ α⇐)) ∘
α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈˘⟨ pushˡ ((refl⟩∘⟨ refl⟩∘⟨ refl⟩⊗⟨
(sym-assoc ○ hexagon₂ ○ assoc)) ⟩∘⟨refl) ⟩
((α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ σ⇒)) ∘ α⇒) ∘
σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ pushˡ (pushʳ (pushʳ split₂ˡ)) ⟩∘⟨refl ⟩
((α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ σ⇒ ⊗₁ id) ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ∘
σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ pushʳ (pushˡ split₂ˡ) ⟩∘⟨refl ⟩
(((α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ σ⇒ ⊗₁ id) ∘ id ⊗₁ α⇐) ∘
id ⊗₁ id ⊗₁ σ⇒ ∘ α⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ ((pushˡ (pushʳ assoc-commute-to) ⟩∘⟨
⟺ assoc-commute-from) ○ (pullʳ sym-assoc)) ⟩∘⟨refl ⟩
((α⇐ ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ ((α⇐ ∘ id ⊗₁ α⇐) ∘ α⇒) ∘
(id ⊗₁ id) ⊗₁ σ⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ pullˡ (⟺ split₁ˡ ⟩∘⟨
conjugate-from α (idᵢ ⊗ᵢ α ∘ᵢ α) (⟺ (assoc ○ pentagon)))
⟩∘⟨refl ⟩
(((α⇐ ∘ id ⊗₁ σ⇒) ⊗₁ id ∘ α⇒ ⊗₁ id ∘ α⇐) ∘ (id ⊗₁ id) ⊗₁ σ⇒) ∘
σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ (pullˡ (⟺ split₁ˡ) ⟩∘⟨ ⊗.identity ⟩⊗⟨refl) ⟩∘⟨refl ⟩
((((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ σ⇒) ∘
σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ extend² (⟺ serialize₂₁ ○ serialize₁₂) ⟩
((((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ σ⇒ ⊗₁ id) ∘
id ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ α⇒
≈˘⟨ pushʳ (refl⟩∘⟨ refl⟩⊗⟨ ⊗.identity) ⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩∘⟨refl ⟩
(((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐ ∘ σ⇒ ⊗₁ id ⊗₁ id) ∘
(id ⊗₁ id) ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ α⇒
≈⟨ pushʳ assoc-commute-to ⟩∘⟨ extendʳ (⟺ assoc-commute-to) ⟩
((((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ (σ⇒ ⊗₁ id) ⊗₁ id) ∘ α⇐) ∘
α⇐ ∘ id ⊗₁ id ⊗₁ σ⇒ ∘ id ⊗₁ α⇒
≈˘⟨ ((sym-assoc ○ sym-assoc) ⟩⊗⟨refl ○ split₁ˡ) ⟩∘⟨refl ⟩∘⟨
refl⟩∘⟨ split₂ˡ ⟩
(((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ⊗₁ id) ∘ α⇐) ∘
α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒ ∘ α⇒)
≈˘⟨ extend² (sym-assoc ○ inv-pentagon) ⟩
(((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ⊗₁ id) ∘ α⇐ ⊗₁ id) ∘
(α⇐ ∘ id ⊗₁ α⇐) ∘ id ⊗₁ (id ⊗₁ σ⇒ ∘ α⇒)
≈˘⟨ split₁ˡ ⟩∘⟨ pushʳ split₂ˡ ⟩
((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘
α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒)
∎) ⟩⊗⟨refl ⟩∘⟨refl ⟩
α⇒ ∘ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐ ∘
id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒)) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐
≈⟨ (refl⟩∘⟨ pushˡ ((sym-assoc ⟩⊗⟨refl) ○ split₁ˡ)) ⟩
α⇒ ∘ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐) ⊗₁ id ∘
(id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒)) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐
≈⟨ (refl⟩∘⟨ split₁ˡ ⟩∘⟨ extendʳ (⟺ assoc-commute-to)) ○ pushʳ assoc ⟩
(α⇒ ∘ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id) ⊗₁ id) ∘
α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ id ⊗₁ α⇐
≈⟨ pushˡ assoc-commute-from ⟩
((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ α⇒ ∘
α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ id ⊗₁ α⇐
≈˘⟨ refl⟩∘⟨ pullʳ (pullʳ (refl⟩∘⟨ split₂ˡ)) ⟩
((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘
(α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐)
≈˘⟨ pullʳ (pullˡ (conjugate-from (α ∘ᵢ α ⊗ᵢ idᵢ) α pentagon)) ⟩
(((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ α⇐) ∘
id ⊗₁ α⇒ ∘ id ⊗₁ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐)
≈⟨ refl⟩⊗⟨ ⊗.identity ⟩∘⟨refl ⟩∘⟨ ⟺ split₂ˡ ⟩
(((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐) ∘
id ⊗₁ (α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐)
≡⟨⟩
(((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ j⇒
≈˘⟨ switch-fromtoʳ α (switch-fromtoˡ α (⟺ hexagon₁))
⟩⊗⟨refl ⟩∘⟨refl ⟩∘⟨refl ⟩
(σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ j⇒
∎) ⟩∘⟨refl ⟩
α⇐ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ j⇒) ∘ α⇒ ∘ α⇒
≈⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ id ⊗₁ j⇒ ∘ α⇒ ∘ α⇒
≈˘⟨ pullʳ (pullʳ (extendʳ assoc-commute-from)) ⟩
(α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ (id ⊗₁ id) ⊗₁ j⇒ ∘ α⇒
≡⟨⟩
i⇒ ∘ (id ⊗₁ id) ⊗₁ j⇒ ∘ α⇒
≈⟨ refl⟩∘⟨ ⊗.identity ⟩⊗⟨ ⟺ swapInner-coherent ⟩∘⟨refl ⟩
i⇒ ∘ id ⊗₁ i⇒ ∘ α⇒
∎
where inv-pentagon = λ {W X Y Z} → _≃_.to-≈ (pentagon-iso {W} {X} {Y} {Z})
swapInner-unitˡ : [ unit ⊗₀ (X ⊗₀ Y) ⇒ (X ⊗₀ Y) ]⟨
λ⇐ ⊗₁ id ⇒⟨ (unit ⊗₀ unit) ⊗₀ (X ⊗₀ Y) ⟩
i⇒ ⇒⟨ (unit ⊗₀ X) ⊗₀ (unit ⊗₀ Y) ⟩
λ⇒ ⊗₁ λ⇒
≈ λ⇒
⟩
swapInner-unitˡ = begin
λ⇒ ⊗₁ λ⇒ ∘ i⇒ ∘ λ⇐ ⊗₁ id
≈⟨ refl⟩∘⟨ swapInner-coherent ⟩∘⟨ (Kelly₃′ ⟩⊗⟨refl) ⟩
λ⇒ ⊗₁ λ⇒ ∘ j⇒ ∘ ρ⇐ ⊗₁ id
≡⟨⟩
λ⇒ ⊗₁ λ⇒ ∘ (α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ ρ⇐ ⊗₁ id
≈⟨ pullˡ (pushˡ serialize₁₂) ⟩
(λ⇒ ⊗₁ id ∘ id ⊗₁ λ⇒ ∘ α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ ρ⇐ ⊗₁ id
≈⟨ (refl⟩∘⟨ (begin
id ⊗₁ λ⇒ ∘ α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
≈⟨ pullˡ triangle ⟩
ρ⇒ ⊗₁ id ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
≈˘⟨ pushˡ split₁ˡ ⟩
(ρ⇒ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
≈⟨ (pullˡ Kelly₂′ ⟩⊗⟨refl ⟩∘⟨refl) ⟩
(id ⊗₁ ρ⇒ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
≈˘⟨ pushˡ split₂ˡ ⟩⊗⟨refl ⟩∘⟨refl ⟩
(id ⊗₁ (ρ⇒ ∘ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐
≈⟨ (refl⟩⊗⟨ σ⁻¹-coherence ⟩∘⟨refl) ⟩⊗⟨refl ⟩∘⟨refl ⟩
(id ⊗₁ λ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐
≈⟨ triangle ⟩⊗⟨refl ⟩∘⟨refl ⟩
(ρ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐
≈˘⟨ assoc-commute-to ⟩
α⇐ ∘ ρ⇒ ⊗₁ (id ⊗₁ id)
∎)) ⟩∘⟨refl ⟩
(λ⇒ ⊗₁ id ∘ α⇐ ∘ ρ⇒ ⊗₁ (id ⊗₁ id)) ∘ ρ⇐ ⊗₁ id
≈⟨ (sym-assoc ○ (Kelly₁′ ⟩∘⟨ refl⟩⊗⟨ ⊗.identity)) ⟩∘⟨refl ⟩
(λ⇒ ∘ ρ⇒ ⊗₁ id) ∘ ρ⇐ ⊗₁ id
≈⟨ cancelʳ (_≅_.isoʳ (unitorʳ ⊗ᵢ idᵢ)) ⟩
λ⇒
∎
where
Kelly₁′ = ⟺ (switch-fromtoʳ α (Kelly's.coherence₁ M))
Kelly₂′ = ⟺ (switch-fromtoʳ α (Kelly's.coherence₂ M))
Kelly₃′ = _≃_.to-≈ (Kelly's.coherence-iso₃ M)
σ⁻¹-coherence = inv-braiding-coherence (inv-Braided B)
swapInner-unitʳ : [ (X ⊗₀ Y) ⊗₀ unit ⇒ (X ⊗₀ Y) ]⟨
id ⊗₁ λ⇐ ⇒⟨ (X ⊗₀ Y) ⊗₀ (unit ⊗₀ unit) ⟩
i⇒ ⇒⟨ (X ⊗₀ unit) ⊗₀ (Y ⊗₀ unit) ⟩
ρ⇒ ⊗₁ ρ⇒
≈ ρ⇒
⟩
swapInner-unitʳ = begin
ρ⇒ ⊗₁ ρ⇒ ∘ i⇒ ∘ id ⊗₁ λ⇐
≡⟨⟩
ρ⇒ ⊗₁ ρ⇒ ∘ (α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ id ⊗₁ λ⇐
≈⟨ pullˡ (pushˡ serialize₂₁) ⟩
(id ⊗₁ ρ⇒ ∘ ρ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ id ⊗₁ λ⇐
≈⟨ (refl⟩∘⟨ (begin
ρ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ pushˡ (switch-fromtoʳ α triangle) ⟩
id ⊗₁ λ⇒ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ pushˡ split₂ˡ ⟩
id ⊗₁ (λ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ refl⟩⊗⟨ pullˡ (Kelly's.coherence₁ M) ⟩∘⟨refl ⟩
id ⊗₁ (λ⇒ ⊗₁ id ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ refl⟩⊗⟨ pushˡ split₁ˡ ⟩∘⟨refl ⟩
id ⊗₁ ((λ⇒ ∘ σ⇒) ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ refl⟩⊗⟨ (braiding-coherence B ⟩⊗⟨refl ⟩∘⟨refl) ⟩∘⟨refl ⟩
id ⊗₁ (ρ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ refl⟩⊗⟨ switch-fromtoʳ α triangle ⟩∘⟨refl ⟩
id ⊗₁ (id ⊗₁ λ⇒) ∘ α⇒
≈˘⟨ assoc-commute-from ⟩
α⇒ ∘ (id ⊗₁ id) ⊗₁ λ⇒
∎)) ⟩∘⟨refl ⟩
(id ⊗₁ ρ⇒ ∘ α⇒ ∘ (id ⊗₁ id) ⊗₁ λ⇒) ∘ id ⊗₁ λ⇐
≈⟨ (sym-assoc ○ (Kelly's.coherence₂ M ⟩∘⟨ ⊗.identity ⟩⊗⟨refl)) ⟩∘⟨refl ⟩
(ρ⇒ ∘ id ⊗₁ λ⇒) ∘ id ⊗₁ λ⇐
≈⟨ cancelʳ (_≅_.isoʳ (idᵢ ⊗ᵢ unitorˡ)) ⟩
ρ⇒
∎
swapInner-braiding : [ (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ⇒ (Y ⊗₀ Z) ⊗₀ (W ⊗₀ X) ]⟨
i⇒ ⇒⟨ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) ⟩
σ⇒ ⊗₁ σ⇒ ⇒⟨ (Y ⊗₀ W) ⊗₀ (Z ⊗₀ X) ⟩
i⇒
≈ σ⇒
⟩
swapInner-braiding = begin
i⇒ ∘ σ⇒ ⊗₁ σ⇒ ∘ i⇒
≡⟨⟩
i⇒ ∘ σ⇒ ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ swapInner-coherent ⟩∘⟨ pushˡ serialize₁₂ ⟩
j⇒ ∘ σ⇒ ⊗₁ id ∘ id ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ ((refl⟩∘⟨ refl⟩⊗⟨ ⊗.identity) ⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩∘⟨refl) ○ assoc ⟩
((α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ σ⇒ ⊗₁ (id ⊗₁ id)) ∘
(id ⊗₁ id) ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ pullʳ (pullʳ assoc-commute-to) ⟩∘⟨ extendʳ (⟺ assoc-commute-to) ⟩
(α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐) ∘
α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒) ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ (refl⟩∘⟨ pushˡ split₁ˡ) ⟩∘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
(α⇒ ∘ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐) ∘
α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ (refl⟩∘⟨ pullʳ (assoc ○ hexagon₁) ⟩⊗⟨refl ⟩∘⟨refl) ⟩∘⟨
refl⟩∘⟨ refl⟩⊗⟨ (⟺ assoc ○ (pullˡ (assoc ○ hexagon₁))) ⟩∘⟨refl ⟩
(α⇒ ∘ (α⇐ ∘ α⇒ ∘ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ∘
α⇐ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ∘ α⇒) ∘ α⇐) ∘ α⇒
≈⟨ (refl⟩∘⟨ cancelˡ α.isoˡ ⟩⊗⟨refl ⟩∘⟨refl) ⟩∘⟨
refl⟩∘⟨ refl⟩⊗⟨ pullʳ (cancelʳ α.isoʳ) ⟩∘⟨refl ⟩
(α⇒ ∘ (σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒) ∘ α⇒
≈⟨ extendʳ (pushʳ split₁ˡ) ⟩∘⟨ extendʳ (pushʳ split₂ˡ) ⟩
((α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐) ∘ (α⇐ ∘ id ⊗₁ α⇒) ∘ id ⊗₁ σ⇒ ∘ α⇒
≈˘⟨ extendʳ (pushʳ (pushʳ assoc)) ⟩
(α⇒ ∘ σ⇒ ⊗₁ id) ∘ (α⇒ ⊗₁ id ∘ (α⇐ ∘ α⇐) ∘ id ⊗₁ α⇒) ∘ id ⊗₁ σ⇒ ∘ α⇒
≈˘⟨ refl⟩∘⟨ switch-tofromˡ (α ⊗ᵢ idᵢ)
(switch-tofromʳ (idᵢ ⊗ᵢ α) inv-pentagon) ⟩∘⟨refl ⟩
(α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒
≈⟨ pullʳ (sym-assoc ○ pullˡ hexagon₂) ⟩
α⇒ ∘ ((α⇐ ∘ σ⇒) ∘ α⇐) ∘ α⇒
≈⟨ (refl⟩∘⟨ cancelʳ α.isoˡ) ⟩
α⇒ ∘ (α⇐ ∘ σ⇒)
≈⟨ cancelˡ α.isoʳ ⟩
σ⇒
∎
where inv-pentagon = _≃_.to-≈ pentagon-iso
-- Braided monoidal categories have an interchange.
hasInterchange : HasInterchange M
hasInterchange = record
{ swapInner = swapInner
; natural = swapInner-natural
; assoc = swapInner-assoc
; unitˡ = swapInner-unitˡ
; unitʳ = swapInner-unitʳ
}
open HasInterchange hasInterchange public using (naturalIso)
-- Extra identities that hold only for symmetric monoidal categories.
module SymmetricInterchange {M : Monoidal C} (S : Symmetric M) where
open MonoidalReasoning M
open MonoidalUtilities M
open Symmetric S renaming (associator to α)
open Shorthands
open BraidedInterchange braided public
private
i⇒ = swapInner.from
i⇐ = swapInner.to
σ⇒ = λ {X Y} → braiding.⇒.η (X , Y)
σ⇐ = λ {X Y} → braiding.⇐.η (X , Y)
swapInner-commutative : [ (X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ⇒
(X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ]⟨
i⇒ ⇒⟨ (X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂) ⟩
i⇒
≈ id
⟩
swapInner-commutative = begin
i⇒ ∘ i⇒
≈⟨ pullʳ (cancelInner α.isoʳ) ⟩
α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈˘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
α⇐ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒
≈⟨ refl⟩∘⟨ refl⟩⊗⟨ (∘-resp-≈ʳ sym-assoc ○ α[σ⊗1]α⁻¹.isoʳ) ⟩∘⟨refl ⟩
α⇐ ∘ id ⊗₁ id ∘ α⇒
≈⟨ refl⟩∘⟨ ⊗.identity ⟩∘⟨refl ⟩
α⇐ ∘ id ∘ α⇒
≈⟨ ∘-resp-≈ʳ identityˡ ○ α.isoˡ ⟩
id
∎
where module α[σ⊗1]α⁻¹ = _≅_ (α ∘ᵢ braided-iso ⊗ᵢ idᵢ ∘ᵢ α ⁻¹)
swapInner-iso : (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z)
swapInner-iso = record
{ from = i⇒
; to = i⇒
; iso = record
{ isoˡ = swapInner-commutative
; isoʳ = swapInner-commutative
}
}
swapInner-braiding′ : [ (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ⇒ (Y ⊗₀ W) ⊗₀ (Z ⊗₀ X) ]⟨
i⇒ ⇒⟨ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) ⟩
σ⇒ ⊗₁ σ⇒
≈ σ⇒ ⇒⟨ (Y ⊗₀ Z) ⊗₀ (W ⊗₀ X) ⟩
i⇒
⟩
swapInner-braiding′ = switch-fromtoˡ swapInner-iso swapInner-braiding
| 43.057692
| 80
| 0.424222
|
03848c103252c2ab83db2291458bf18409840d74
| 15,050
|
agda
|
Agda
|
Cubical/Homotopy/HopfInvariant/Brunerie.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/HopfInvariant/Brunerie.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/HopfInvariant/Brunerie.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-
This file contains a proof of the fact that the Brunerie number,
i.e. absolute value of the Hopf invariant of [e , e] : π₃S², is 2.
Here, e is the generator of π₂S² and [_,_] denotes the Whitehead
product. The proof follows Proposition 5.4.4. in Brunerie (2016)
closely, but, for simplicity, considers only the case n = 2.
-}
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.HopfInvariant.Brunerie where
open import Cubical.Homotopy.HopfInvariant.Base
open import Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
open import Cubical.Homotopy.Group.Pi4S3.S3PushoutIso
open import Cubical.Homotopy.Whitehead
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.Groups.Wedge
open import Cubical.ZCohomology.Groups.SphereProduct
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.RingLaws
open import Cubical.ZCohomology.RingStructure.GradedCommutativity
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Data.Int hiding (_+'_)
open import Cubical.Data.Nat hiding (_+_)
open import Cubical.Data.Unit
open import Cubical.Data.Sum renaming (rec to ⊎rec)
open import Cubical.HITs.Pushout
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.Join
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
open import Cubical.HITs.Truncation
open import Cubical.HITs.SetTruncation
renaming (elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation
renaming (map to pMap ; rec to pRec)
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.ZAction
open import Cubical.Algebra.Group.Exact
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.Unit
open Iso
open IsGroupHom
open PlusBis
-- Some abstract versions of imported lemmas/definitions from
-- ZCohomology.Groups.SphereProduct for faster type checking.
abstract
H²-genₗabs : coHom 2 (S₊ 2 × S₊ 2)
H²-genₗabs = H²-S²×S²-genₗ
H²-genᵣabs : coHom 2 (S₊ 2 × S₊ 2)
H²-genᵣabs = H²-S²×S²-genᵣ
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs : (n m : ℕ)
→ GroupIso (coHomGr ((suc n) +' (suc m))
(S₊ (suc n) × S₊ (suc m)))
ℤGroup
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs = Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs≡ : (n m : ℕ)
→ Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs n m ≡ Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ n m
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs≡ n m = refl
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-⌣ :
fun (fst (Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs 1 1))
(H²-S²×S²-genₗ ⌣ H²-S²×S²-genᵣ)
≡ 1
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-⌣ =
fun (fst (Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs 1 1)) (H²-S²×S²-genₗ ⌣ H²-S²×S²-genᵣ)
≡⟨ cong (fun (fst (Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs 1 1))) (sym H²-S²≅H⁴-S²×S²⌣) ⟩
fun (fst (Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs 1 1)) (fun (fst (H²-S²≅H⁴-S²×S²)) ∣ ∣_∣ₕ ∣₂)
≡⟨ speedUp ∣_∣ₕ ⟩
fun (fst (Hⁿ-Sⁿ≅ℤ 1)) ∣ ∣_∣ₕ ∣₂
≡⟨ refl ⟩ -- Computation! :-)
1 ∎
where
speedUp : (f : _) →
fun (fst (Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs 1 1)) (fun (fst (H²-S²≅H⁴-S²×S²)) ∣ f ∣₂)
≡ fun (fst (Hⁿ-Sⁿ≅ℤ 1)) ∣ f ∣₂
speedUp f i =
fun (fst (Hⁿ-Sⁿ≅ℤ 1)) (leftInv (fst H²-S²≅H⁴-S²×S²) ∣ f ∣₂ i)
-- Some abbreviations
private
inl' : S₊ 2 × S₊ 2 → Pushout⋁↪fold⋁ (S₊∙ 2)
inl' = inl
qHom : GroupHom (coHomGr 4 (Pushout⋁↪fold⋁ (S₊∙ 2)))
(coHomGr 4 (S₊ 2 × S₊ 2))
qHom = coHomMorph 4 inl'
qHomGen : (n : ℕ) →
GroupHom (coHomGr n (Pushout⋁↪fold⋁ (S₊∙ 2)))
(coHomGr n (S₊ 2 × S₊ 2))
qHomGen n = coHomMorph n inl'
-- The type C and generator α, β in dim 2 and 4 respectively
-- Recall, the goal is to prove that α ⌣ α = ±2 β
CHopf : Type
CHopf = HopfInvariantPush 0 fold∘W
Hopfαfold∘W = Hopfα 0 (fold∘W , refl)
Hopfβfold∘W = Hopfβ 0 (fold∘W , refl)
-- Rewriting CHopf as our favourite pushout
-- S²×S² ← S²∨S² → S²
CHopfIso : Iso CHopf (Pushout⋁↪fold⋁ (S₊∙ 2))
CHopfIso =
compIso (invIso (equivToIso
(compEquiv (compEquiv pushoutSwitchEquiv
(isoToEquiv (PushoutDistr.PushoutDistrIso fold⋁ W λ _ → tt)))
pushoutSwitchEquiv)))
(equivToIso Pushout-coFibW-fold⋁≃Pushout⋁↪fold⋁)
-- Cohomology group version of the Iso
coHomCHopfIso : (n : ℕ)
→ GroupIso (coHomGr n CHopf) (coHomGr n (Pushout⋁↪fold⋁ (S₊∙ 2)))
coHomCHopfIso n = invGroupIso (coHomIso n CHopfIso)
-- We instantiate Mayer-Vietoris for the pushout
module MV-⋁↪-fold⋁ = MV _ _ (S₊∙ 2 ⋁ S₊∙ 2) ⋁↪ fold⋁
-- This give us an iso H⁴(S²×S² ← S²∨S² → S²) ≅ H⁴(S²×S²)
isEquiv-qHom : GroupEquiv (coHomGr 4 (Pushout⋁↪fold⋁ (S₊∙ 2)))
(coHomGr 4 (S₊ 2 × S₊ 2))
fst (fst isEquiv-qHom) = qHom .fst
snd (fst isEquiv-qHom) =
subst isEquiv
(funExt (sElim (λ _ → isSetPathImplicit) (λ _ → refl)))
(×UnitEquiv (isoToPath
(invIso
(fst (Hⁿ-Sᵐ≅0 3 1 λ p → snotz (cong predℕ p)))))
_ isEquiv-i)
where
×UnitEquiv : {A B C : Type}
→ Unit ≡ C
→ (f : A → B × C)
→ isEquiv f
→ isEquiv (fst ∘ f)
×UnitEquiv {A = A} {B = B} =
J (λ C _ → (f : A → B × C) → isEquiv f → isEquiv (fst ∘ f))
λ f eq → record { equiv-proof =
λ b → ((fst (fst (equiv-proof eq (b , tt))))
, cong fst (fst (equiv-proof eq (b , tt)) .snd))
, λ y → ΣPathP ((cong fst (equiv-proof eq (b , tt)
.snd ((fst y)
, ΣPathP ((snd y) , refl))))
, λ i j → equiv-proof eq (b , tt) .snd ((fst y)
, ΣPathP ((snd y) , refl)) i .snd j .fst) }
isEquiv-i : isEquiv (fst (MV-⋁↪-fold⋁.i 4))
isEquiv-i =
SES→isEquiv
(isContr→≡UnitGroup
(isOfHLevelRetractFromIso 0
(compIso
(fst (Hⁿ-⋁ (S₊∙ 2) (S₊∙ 2) 2))
(compIso
(prodIso (fst (Hⁿ-Sᵐ≅0 2 1 λ p → snotz (cong predℕ p)))
(fst (Hⁿ-Sᵐ≅0 2 1 λ p → snotz (cong predℕ p))))
rUnit×Iso))
isContrUnit))
((isContr→≡UnitGroup
(isOfHLevelRetractFromIso 0
(compIso
(fst (Hⁿ-⋁ (S₊∙ 2) (S₊∙ 2) 3))
(compIso
(prodIso (fst (Hⁿ-Sᵐ≅0 3 1 λ p → snotz (cong predℕ p)))
(fst (Hⁿ-Sᵐ≅0 3 1 λ p → snotz (cong predℕ p))))
rUnit×Iso))
isContrUnit)))
(MV-⋁↪-fold⋁.d 3)
(MV-⋁↪-fold⋁.i 4)
(MV-⋁↪-fold⋁.Δ 4)
(MV-⋁↪-fold⋁.Ker-i⊂Im-d 3)
(MV-⋁↪-fold⋁.Ker-Δ⊂Im-i 4)
snd isEquiv-qHom = qHom .snd
-- The goal now is reducing α ⌣ α = ±2 β to gₗ ⌣ gᵣ = e for
-- gₗ, gᵣ generators of H²(S²×S²) ≅ ℤ × ℤ and e generator of
-- H⁴(S²×S²) ≅ ℤ. This essentially just elementary linear algebra at
-- this point. We do it for an arbitrary (well-behaved) iso
-- H⁴(S²×S²) ≅ ℤ in order to speed up type checking.
module BrunerieNumLem
(is : GroupIso (coHomGr 4 (S₊ 2 × S₊ 2)) ℤGroup)
(isEq : (fun (fst is) (H²-S²×S²-genₗ ⌣ H²-S²×S²-genᵣ) ≡ 1)) where
x = H²-S²×S²-genₗ
y = H²-S²×S²-genᵣ
α = Hopfαfold∘W
β = Hopfβfold∘W
α' : coHom 2 (Pushout⋁↪fold⋁ (S₊∙ 2))
α' = fun (fst (coHomCHopfIso 2)) α
β' : coHom 4 (Pushout⋁↪fold⋁ (S₊∙ 2))
β' = fun (fst (coHomCHopfIso 4)) β
rewriteEquation :
(α' ⌣ α' ≡ β' +ₕ β') ⊎ (α' ⌣ α' ≡ -ₕ (β' +ₕ β'))
→ (α ⌣ α ≡ β +ₕ β) ⊎ (α ⌣ α ≡ -ₕ (β +ₕ β))
rewriteEquation (inl x) =
inl ((λ i → leftInv (fst (coHomCHopfIso 2)) α (~ i)
⌣ leftInv (fst (coHomCHopfIso 2)) α (~ i))
∙∙ cong (inv (fst (coHomCHopfIso 4))) x
∙∙ leftInv (fst (coHomCHopfIso 4)) (β +ₕ β))
rewriteEquation (inr x) =
inr ((λ i → leftInv (fst (coHomCHopfIso 2)) α (~ i)
⌣ leftInv (fst (coHomCHopfIso 2)) α (~ i))
∙∙ cong (inv (fst (coHomCHopfIso 4))) x
∙∙ leftInv (fst (coHomCHopfIso 4))
(-ₕ (β +ₕ β)))
rewriteEquation2 : (qHom .fst β' ≡ x ⌣ y) ⊎ (qHom .fst β' ≡ -ₕ (x ⌣ y))
rewriteEquation2 =
⊎rec
(λ p → inl (sym (leftInv (fst is) (qHom .fst β'))
∙∙ cong (inv (fst is)) (p ∙ sym isEq)
∙∙ leftInv (fst is) (x ⌣ y)))
(λ p → inr (sym (leftInv (fst is) (qHom .fst β'))
∙∙ cong (inv (fst is))
(p ∙ sym (cong (GroupStr.inv (snd ℤGroup)) isEq))
∙∙ (presinv (invGroupIso is .snd) (fun (fst is) (x ⌣ y))
∙ cong -ₕ_ (leftInv (fst is) (x ⌣ y)))))
eqs
where
grIso : GroupEquiv (coHomGr 4 (HopfInvariantPush 0 fold∘W)) ℤGroup
grIso = compGroupEquiv (GroupIso→GroupEquiv (coHomCHopfIso 4))
(compGroupEquiv
isEquiv-qHom
(GroupIso→GroupEquiv is))
eqs : (fst (fst grIso) β ≡ 1) ⊎ (fst (fst grIso) β ≡ -1)
eqs = groupEquivPresGen _ (GroupIso→GroupEquiv (Hopfβ-Iso 0 (fold∘W , refl)))
β (inl (Hopfβ↦1 0 (fold∘W , refl))) grIso
qpres⌣ : (x y : coHom 2 _)
→ fst qHom (x ⌣ y) ≡ fst (qHomGen 2) x ⌣ fst (qHomGen 2) y
qpres⌣ = sElim2 (λ _ _ → isSetPathImplicit) λ _ _ → refl
α'↦x+y : fst (qHomGen 2) α' ≡ x +ₕ y
α'↦x+y = lem ((coHomFun 2 (inv CHopfIso) α)) refl
where
lem : (x' : coHom 2 (Pushout⋁↪fold⋁ (S₊∙ 2)))
→ coHomFun 2 inr x' ≡ ∣ ∣_∣ ∣₂
→ fst (qHomGen 2) x' ≡ x +ₕ y
lem = sElim (λ _ → isSetΠ λ _ → isSetPathImplicit)
λ f p → Cubical.HITs.PropositionalTruncation.rec
(squash₂ _ _)
(λ r → cong ∣_∣₂ (funExt (uncurry
(wedgeconFun 1 1 (λ _ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _)
(λ x → cong f (push (inr x)) ∙∙ funExt⁻ r x ∙∙ refl)
((λ x → cong f (push (inl x)) ∙∙ funExt⁻ r x ∙∙ sym (rUnitₖ 2 ∣ x ∣ₕ)))
(cong (_∙∙ funExt⁻ r north ∙∙ refl)
(cong (cong f) λ j i → push (push tt j) i))))))
(fun PathIdTrunc₀Iso p)
mainEq : ((fst qHom) (α' ⌣ α') ≡ qHom .fst (β' +ₕ β'))
⊎ ((fst qHom) (α' ⌣ α') ≡ qHom .fst (-ₕ (β' +ₕ β')))
mainEq =
⊎rec
(λ id → inl (lem₁ ∙ lem₂
∙ cong (λ x → x +ₕ x) (sym id)
∙ sym (pres· (snd qHom) β' β')))
(λ id → inr (lem₁ ∙ lem₂
∙ ((sym (distLem (x ⌣ y))
∙ cong -ₕ_ (cong (λ x → x +ₕ x) (sym id)))
∙ cong (-ₕ_) (pres· (snd qHom) β' β'))
∙ sym (presinv (snd qHom) (β' +ₕ β'))))
rewriteEquation2
where
triv⌣ : (a : S¹)
→ cong₂ (_⌣ₖ_ {n = 2} {m = 2}) (cong ∣_∣ₕ (merid a)) (cong ∣_∣ₕ (merid a))
≡ λ _ → ∣ north ∣ₕ
triv⌣ a =
cong₂Funct (_⌣ₖ_ {n = 2} {m = 2})
(cong ∣_∣ₕ (merid a)) (cong ∣_∣ₕ (merid a))
∙ sym (rUnit λ j → _⌣ₖ_ {n = 2} {m = 2} ∣ merid a j ∣ₕ ∣ north ∣)
∙ (λ i j → ⌣ₖ-0ₖ 2 2 ∣ merid a j ∣ₕ i)
distLem : (x : coHom 4 (S₊ 2 × S₊ 2)) → -ₕ ((-ₕ x) +ₕ (-ₕ x)) ≡ x +ₕ x
distLem =
sElim (λ _ → isSetPathImplicit)
λ f → cong ∣_∣₂ (funExt λ x → cong -ₖ_ (sym (-distrₖ 4 (f x) (f x)))
∙ -ₖ^2 (f x +ₖ f x))
x⌣x≡0 : x ⌣ x ≡ 0ₕ 4
x⌣x≡0 =
cong ∣_∣₂
(funExt (uncurry λ { north y → refl
; south y → refl
; (merid a i) y j → triv⌣ a j i}))
y⌣y≡0 : y ⌣ y ≡ 0ₕ 4
y⌣y≡0 =
cong ∣_∣₂
(funExt (uncurry λ { x north → refl
; x south → refl
; x (merid a i) j → triv⌣ a j i}))
-ₕ'Id : (x : coHom 4 (S₊ 2 × S₊ 2)) → (-ₕ'^ 2 · 2) x ≡ x
-ₕ'Id =
sElim (λ _ → isSetPathImplicit)
λ f → cong ∣_∣₂ (funExt λ x → -ₖ'-gen-inl-left 2 2 tt (inl tt) (f x))
y⌣x≡x⌣y : y ⌣ x ≡ x ⌣ y
y⌣x≡x⌣y =
y ⌣ x ≡⟨ gradedComm'-⌣ 2 2 y x ⟩
(-ₕ'^ 2 · 2) (transport refl (x ⌣ y)) ≡⟨ -ₕ'Id (transport refl (x ⌣ y)) ⟩
transport refl (x ⌣ y) ≡⟨ transportRefl (x ⌣ y) ⟩
x ⌣ y ∎
lem₂ : (x +ₕ y) ⌣ (x +ₕ y) ≡ (x ⌣ y) +ₕ (x ⌣ y)
lem₂ =
(x +ₕ y) ⌣ (x +ₕ y) ≡⟨ leftDistr-⌣ 2 2 (x +ₕ y) x y ⟩
((x +ₕ y) ⌣ x) +ₕ ((x +ₕ y) ⌣ y) ≡⟨ cong₂ _+ₕ_ (rightDistr-⌣ 2 2 x y x) (rightDistr-⌣ 2 2 x y y) ⟩
((x ⌣ x +ₕ y ⌣ x)) +ₕ (x ⌣ y +ₕ y ⌣ y) ≡⟨ cong₂ _+ₕ_ (cong (_+ₕ y ⌣ x) x⌣x≡0 ∙ lUnitₕ 4 (y ⌣ x))
(cong (x ⌣ y +ₕ_) y⌣y≡0 ∙ rUnitₕ 4 (x ⌣ y)) ⟩
y ⌣ x +ₕ x ⌣ y ≡⟨ cong (_+ₕ (x ⌣ y)) y⌣x≡x⌣y ⟩
((x ⌣ y) +ₕ (x ⌣ y)) ∎
lem₁ : (fst qHom) (α' ⌣ α') ≡ (x +ₕ y) ⌣ (x +ₕ y)
lem₁ =
fst qHom (α' ⌣ α') ≡⟨ refl ⟩
fst (qHomGen 2) α' ⌣ fst (qHomGen 2) α' ≡⟨ cong (λ x → x ⌣ x) α'↦x+y ⟩
((x +ₕ y) ⌣ (x +ₕ y)) ∎
main⊎ : (HopfInvariant 0 (fold∘W , refl) ≡ 2)
⊎ (HopfInvariant 0 (fold∘W , refl) ≡ -2)
main⊎ =
⊎rec (λ p → inl (lem₁
∙ cong (fun (fst (Hopfβ-Iso 0 (fold∘W , refl)))) p
∙ pres· (Hopfβ-Iso 0 (fold∘W , refl) .snd) β β
∙ cong (λ x → x + x) (Hopfβ↦1 0 (fold∘W , refl))))
(λ p → inr (lem₁
∙ cong (fun (fst (Hopfβ-Iso 0 (fold∘W , refl)))) p
∙ presinv (Hopfβ-Iso 0 (fold∘W , refl) .snd) (β +ₕ β)
∙ cong (GroupStr.inv (snd ℤGroup))
(pres· (Hopfβ-Iso 0 (fold∘W , refl) .snd) β β
∙ cong (λ x → x + x) (Hopfβ↦1 0 (fold∘W , refl)))))
lem₂
where
lem₁ : HopfInvariant 0 (fold∘W , refl)
≡ fun (fst (Hopfβ-Iso 0 (fold∘W , refl))) (α ⌣ α)
lem₁ =
cong (fun (fst (Hopfβ-Iso 0 (fold∘W , refl)))) (transportRefl (α ⌣ α))
lem₂ : (α ⌣ α ≡ β +ₕ β) ⊎ (α ⌣ α ≡ -ₕ (β +ₕ β))
lem₂ =
rewriteEquation
(⊎rec (λ p → inl (sym (retEq (fst isEquiv-qHom) (α' ⌣ α'))
∙∙ cong (invEq (fst isEquiv-qHom)) p
∙∙ retEq (fst isEquiv-qHom) (β' +ₕ β')))
(λ p → inr ((sym (retEq (fst isEquiv-qHom) (α' ⌣ α'))
∙∙ cong (invEq (fst isEquiv-qHom)) p
∙∙ retEq (fst isEquiv-qHom) (-ₕ (β' +ₕ β')))))
mainEq)
main : abs (HopfInvariant 0 (fold∘W , refl)) ≡ 2
main = ⊎→abs _ 2 main⊎
-- We instantiate the module
Brunerie'≡2 : abs (HopfInvariant 0 (fold∘W , refl)) ≡ 2
Brunerie'≡2 = BrunerieNumLem.main (Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-abs 1 1) Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ-⌣
-- We rewrite the it slightly, to get the definition of the Brunerie
-- number in Brunerie (2016)
Brunerie'≡Brunerie : [ ∣ idfun∙ (S₊∙ 2) ∣₂ ∣ ∣ idfun∙ (S₊∙ 2) ∣₂ ]π' ≡ ∣ fold∘W , refl ∣₂
Brunerie'≡Brunerie =
cong ∣_∣₂ ([]≡[]₂ (idfun∙ (S₊∙ 2)) (idfun∙ (S₊∙ 2)) )
∙ sym fold∘W≡Whitehead
∙ cong ∣_∣₂ (∘∙-idˡ (fold∘W , refl))
-- And we get the main result
Brunerie≡2 : Brunerie ≡ 2
Brunerie≡2 =
cong abs (cong (HopfInvariant-π' 0) Brunerie'≡Brunerie)
∙ Brunerie'≡2
| 37.344913
| 112
| 0.530365
|
0b9fc65cf5e0b2142464fe06146903cd2c5effd9
| 2,954
|
agda
|
Agda
|
src/Categories/Diagram/Equalizer.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Diagram/Equalizer.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Diagram/Equalizer.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core using (Category)
-- Equalizers in a Category C
module Categories.Diagram.Equalizer {o ℓ e} (C : Category o ℓ e) where
open Category C
open HomReasoning
open Equiv
open import Level
open import Data.Product as Σ
open import Function using (_$_)
open import Categories.Morphism C
open import Categories.Morphism.Reasoning C
private
variable
A B X : Obj
h i j k : A ⇒ B
record IsEqualizer {E} (arr : E ⇒ A) (f g : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where
field
equality : f ∘ arr ≈ g ∘ arr
equalize : ∀ {h : X ⇒ A} → f ∘ h ≈ g ∘ h → X ⇒ E
universal : ∀ {eq : f ∘ h ≈ g ∘ h} → h ≈ arr ∘ equalize eq
unique : ∀ {eq : f ∘ h ≈ g ∘ h} → h ≈ arr ∘ i → i ≈ equalize eq
unique′ : (eq eq′ : f ∘ h ≈ g ∘ h) → equalize eq ≈ equalize eq′
unique′ eq eq′ = unique universal
id-equalize : id ≈ equalize equality
id-equalize = unique (sym identityʳ)
equalize-resp-≈ : ∀ {eq : f ∘ h ≈ g ∘ h} {eq′ : f ∘ i ≈ g ∘ i} →
h ≈ i → equalize eq ≈ equalize eq′
equalize-resp-≈ {h = h} {i = i} {eq = eq} {eq′ = eq′} h≈i = unique $ begin
i ≈˘⟨ h≈i ⟩
h ≈⟨ universal ⟩
arr ∘ equalize eq ∎
equalize-resp-≈′ : (eq : f ∘ h ≈ g ∘ h) → (eq′ : f ∘ i ≈ g ∘ i) →
h ≈ i → j ≈ equalize eq → k ≈ equalize eq′ → j ≈ k
equalize-resp-≈′ {j = j} {k = k} eq eq′ h≈i eqj eqk = begin
j ≈⟨ eqj ⟩
equalize eq ≈⟨ equalize-resp-≈ h≈i ⟩
equalize eq′ ≈˘⟨ eqk ⟩
k ∎
equality-∘ : f ∘ arr ∘ h ≈ g ∘ arr ∘ h
equality-∘ {h = h} = begin
f ∘ arr ∘ h ≈⟨ pullˡ equality ⟩
(g ∘ arr) ∘ h ≈⟨ assoc ⟩
g ∘ arr ∘ h ∎
unique-diagram : arr ∘ h ≈ arr ∘ i → h ≈ i
unique-diagram {h = h} {i = i} eq = begin
h ≈⟨ unique (sym eq) ⟩
equalize (extendʳ equality) ≈˘⟨ unique refl ⟩
i ∎
record Equalizer (f g : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where
field
{obj} : Obj
arr : obj ⇒ A
isEqualizer : IsEqualizer arr f g
open IsEqualizer isEqualizer public
Equalizer⇒Mono : (e : Equalizer h i) → Mono (Equalizer.arr e)
Equalizer⇒Mono e f g eq =
equalize-resp-≈′ equality-∘ equality-∘ eq (unique refl) (unique refl)
where open Equalizer e
up-to-iso : (e₁ e₂ : Equalizer h i) → Equalizer.obj e₁ ≅ Equalizer.obj e₂
up-to-iso e₁ e₂ = record
{ from = repack e₁ e₂
; to = repack e₂ e₁
; iso = record
{ isoˡ = repack-cancel e₂ e₁
; isoʳ = repack-cancel e₁ e₂
}
}
where
open Equalizer
repack : (e₁ e₂ : Equalizer h i) → obj e₁ ⇒ obj e₂
repack e₁ e₂ = equalize e₂ (equality e₁)
repack∘ : (e₁ e₂ e₃ : Equalizer h i) → repack e₂ e₃ ∘ repack e₁ e₂ ≈ repack e₁ e₃
repack∘ e₁ e₂ e₃ = unique e₃ (⟺ (glueTrianglesʳ (⟺ (universal e₃)) (⟺ (universal e₂))))
repack-cancel : (e₁ e₂ : Equalizer h i) → repack e₁ e₂ ∘ repack e₂ e₁ ≈ id
repack-cancel e₁ e₂ = repack∘ e₂ e₁ e₂ ○ ⟺ (id-equalize e₂)
| 31.094737
| 91
| 0.551794
|
d1f6908ea2209c507a5aa73e684b862edd5d5b63
| 1,751
|
agda
|
Agda
|
examples/examplesPaperJFP/loadAllOOAgdaPart2.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/examplesPaperJFP/loadAllOOAgdaPart2.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/examplesPaperJFP/loadAllOOAgdaPart2.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module examplesPaperJFP.loadAllOOAgdaPart2 where
-- This is a continuation of the file loadAllOOAgdaPart1
-- giving the code from the ooAgda paper
-- This file was split into two because of a builtin IO which
-- makes loading files from part1 and part2 incompatible.
-- Note that some files which are directly in the libary can be found
-- in loadAllOOAgdaFilesAsInLibrary
-- Sect 1 - 7 are in loadAllOOAgdaPart1.agda
-- 8. State-Dependent Objects and IO
-- 8.1 State-Dependent Interfaces
import examplesPaperJFP.StatefulObject
-- 8.2 State-Dependent Objects
-- 8.2.1. Example of Use of Safe Stack
import examplesPaperJFP.safeFibStackMachineObjectOriented
-- 8.3 Reasoning About Stateful Objects
import examplesPaperJFP.StackBisim
-- 8.3.1. Bisimilarity
-- 8.3.2. Verifying stack laws}
-- 8.3.3. Bisimilarity of different stack implementations
-- 8.4. State-Dependent IO
import examplesPaperJFP.StateDependentIO
-- 9. A Drawing Program in Agda
-- code as in paper adapted to new Agda
open import examplesPaperJFP.IOGraphicsLib
-- code as in library see loadAllOOAgdaFilesAsInLibrary.agda
-- open import SizedIO.IOGraphicsLib
open import examplesPaperJFP.ExampleDrawingProgram
-- 10. A Graphical User Interface using an Object
-- 10.1. wxHaskell
-- 10.2. A Library for Object-Based GUIs in Agda
open import examplesPaperJFP.VariableList
open import examplesPaperJFP.WxGraphicsLib
open import examplesPaperJFP.VariableListForDispatchOnly
-- 10.3 Example: A GUI controlling a Space Ship in Agda
open import examplesPaperJFP.SpaceShipSimpleVar
open import examplesPaperJFP.SpaceShipCell
open import examplesPaperJFP.SpaceShipAdvanced
-- 11. Related Work
open import examplesPaperJFP.agdaCodeBrady
-- 12. Conclusion
-- Bibliography
| 26.530303
| 69
| 0.801256
|
524ffe052e9c73a3e79c828dd1131a61d78b350f
| 435
|
agda
|
Agda
|
negation.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
negation.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
negation.agda
|
heades/AUGL
|
b33c6a59d664aed46cac8ef77d34313e148fecc2
|
[
"MIT"
] | null | null | null |
module negation where
open import level
open import empty
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infix 7 ¬
----------------------------------------------------------------------
-- defined types
----------------------------------------------------------------------
¬ : ∀{ℓ}(x : Set ℓ) → Set ℓ
¬ {ℓ} x = x → (⊥ {ℓ})
| 22.894737
| 70
| 0.2
|
1a96ef7860f5ac48f7b28f9e6ae82ec0378ef776
| 1,281
|
agda
|
Agda
|
Vectors.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 21
|
2015-07-30T01:25:12.000Z
|
2021-02-13T18:02:18.000Z
|
Vectors.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 3
|
2019-01-13T13:12:33.000Z
|
2019-05-29T09:50:26.000Z
|
Vectors.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 1
|
2019-11-04T21:33:13.000Z
|
2019-11-04T21:33:13.000Z
|
record SemiRing : Set1 where
field
R : Set
_+_ : R -> R -> R
zero : R
_*_ : R -> R -> R
one : R
module Vectors (S : SemiRing) where
open SemiRing S
open import Data.Nat renaming (ℕ to Nat; zero to z; _*_ to times; _+_ to plus)
open import Data.Fin renaming (zero to z) hiding (_+_)
open import RMonads
open import Functors.Fin
open import Data.Bool
open import Function
open import Relation.Binary.HeterogeneousEquality
Vec : Nat -> Set
Vec n = Fin n -> R
Matrix : Nat -> Nat -> Set
Matrix m n = Fin m -> Vec n
-- unit
delta : forall {n} -> Matrix n n
delta i j = if feq i j then one else zero
transpose : forall {m n} -> Matrix m n -> Matrix n m
transpose A = λ j i -> A i j
dot : forall {n} -> Vec n -> Vec n -> R
dot {z} x y = zero
dot {suc n} x y = (x z * y z) + dot (x ∘ suc) (y ∘ suc)
mult : forall {m n} -> Matrix m n -> Vec m -> Vec n
mult A x = λ j -> dot (transpose A j) x
VecRMon : RMonad FinF
VecRMon = rmonad
Vec
delta
mult
{!!}
{!!}
{!!}
where
{-
lem : forall {n}(x : Vec n)(j : Fin n) -> dot (λ i → if feq i j then one else zero) x ≅ x j
lem {z} x ()
lem {suc n} x z = {!lem {n} (x ∘ suc) !}
lem {suc n} x (suc j) = {!!}
-}
| 21.711864
| 95
| 0.539422
|
434efc7c2ca1a94e3fe7e6bf899c4debcbd66d92
| 20,073
|
agda
|
Agda
|
Cubical/Algebra/Structures.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Structures.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Structures.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
module Cubical.Algebra.Structures {a} (A : Type a) where
-- The file is divided into sections depending on the arities of the
-- components of the algebraic structure.
open import Cubical.Foundations.Prelude using (isSet; cong; _∙_)
open import Cubical.Foundations.HLevels using (hSet)
open import Cubical.Algebra.Base
open import Cubical.Algebra.Definitions
open import Cubical.Algebra.Properties
open import Cubical.Data.Sigma using (_,_; fst; snd)
open import Cubical.Data.Nat.Base renaming (zero to ℕ-zero; suc to ℕ-suc)
open import Cubical.Data.Int.Base
open import Cubical.Data.NatPlusOne.Base
open import Cubical.Relation.Nullary using (¬_)
open import Cubical.Relation.Binary.Reasoning.Equality
_NotEqualTo_ : A → Type a
_NotEqualTo_ z = Σ[ x ∈ A ] ¬ (x ≡ z)
------------------------------------------------------------------------
-- Algebra with 1 binary operation
------------------------------------------------------------------------
record IsMagma (_•_ : Op₂ A) : Type a where
constructor ismagma
field
is-set : isSet A
set : hSet a
set = A , is-set
record IsSemigroup (_•_ : Op₂ A) : Type a where
constructor issemigroup
field
isMagma : IsMagma _•_
assoc : Associative _•_
open IsMagma isMagma public
infixl 10 _^_
_^_ : A → ℕ₊₁ → A
x ^ one = x
x ^ (2+ n) = x • (x ^ 1+ n)
record IsBand (_•_ : Op₂ A) : Type a where
constructor isband
field
isSemigroup : IsSemigroup _•_
idem : Idempotent _•_
open IsSemigroup isSemigroup public
record IsCommutativeSemigroup (_•_ : Op₂ A) : Type a where
constructor iscommsemigroup
field
isSemigroup : IsSemigroup _•_
comm : Commutative _•_
open IsSemigroup isSemigroup public
record IsSemilattice (_•_ : Op₂ A) : Type a where
constructor issemilattice
field
isBand : IsBand _•_
comm : Commutative _•_
open IsBand isBand public
record IsSelectiveMagma (_•_ : Op₂ A) : Type a where
constructor isselmagma
field
isMagma : IsMagma _•_
sel : Selective _•_
open IsMagma isMagma public
------------------------------------------------------------------------
-- Algebra with 1 binary operation & 1 element
------------------------------------------------------------------------
record IsMonoid (_•_ : Op₂ A) (ε : A) : Type a where
constructor ismonoid
field
isSemigroup : IsSemigroup _•_
identity : Identity ε _•_
open IsSemigroup isSemigroup public hiding (_^_)
identityˡ : LeftIdentity ε _•_
identityˡ = fst identity
identityʳ : RightIdentity ε _•_
identityʳ = snd identity
ε-uniqueʳ : ∀ {e} → RightIdentity e _•_ → ε ≡ e
ε-uniqueʳ idʳ = id-unique′ identityˡ idʳ
ε-uniqueˡ : ∀ {e} → LeftIdentity e _•_ → e ≡ ε
ε-uniqueˡ idˡ = id-unique′ idˡ identityʳ
infixl 10 _^_
_^_ : A → ℕ → A
_ ^ ℕ-zero = ε
x ^ (ℕ-suc n) = x • (x ^ n)
record IsCommutativeMonoid (_•_ : Op₂ A) (ε : A) : Type a where
constructor iscommmonoid
field
isMonoid : IsMonoid _•_ ε
comm : Commutative _•_
open IsMonoid isMonoid public
isCommutativeSemigroup : IsCommutativeSemigroup _•_
isCommutativeSemigroup = record
{ isSemigroup = isSemigroup
; comm = comm
}
record IsIdempotentCommutativeMonoid (_•_ : Op₂ A) (ε : A) : Type a where
constructor isidemcommmonoid
field
isCommutativeMonoid : IsCommutativeMonoid _•_ ε
idem : Idempotent _•_
open IsCommutativeMonoid isCommutativeMonoid public
-- Idempotent commutative monoids are also known as bounded lattices.
-- Note that the BoundedLattice necessarily uses the notation inherited
-- from monoids rather than lattices.
IsBoundedLattice = IsIdempotentCommutativeMonoid
pattern isboundedlattice = isidemcommmonoid
module IsBoundedLattice {_•_ : Op₂ A}
{ε : A}
(isIdemCommMonoid : IsIdempotentCommutativeMonoid _•_ ε) =
IsIdempotentCommutativeMonoid isIdemCommMonoid
------------------------------------------------------------------------
-- Algebra with 1 binary operation, 1 unary operation & 1 element
------------------------------------------------------------------------
record IsGroup (_•_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Type a where
constructor isgroup
field
isMonoid : IsMonoid _•_ ε
inverse : Inverse ε _⁻¹ _•_
open IsMonoid isMonoid public hiding (_^_)
infixl 10 _^_
_^_ : A → ℤ → A
x ^ pos ℕ-zero = ε
x ^ pos (ℕ-suc n) = x • (x ^ pos n)
x ^ negsuc ℕ-zero = x ⁻¹
x ^ negsuc (ℕ-suc n) = (x ⁻¹) • (x ^ negsuc n)
-- Right division
infixl 6 _/_
_/_ : Op₂ A
x / y = x • (y ⁻¹)
-- Left division
infixr 6 _/ˡ_
_/ˡ_ : Op₂ A
x /ˡ y = (x ⁻¹) • y
inverseˡ : LeftInverse ε _⁻¹ _•_
inverseˡ = fst inverse
inverseʳ : RightInverse ε _⁻¹ _•_
inverseʳ = snd inverse
inv-uniqueʳ : ∀ x y → (x • y) ≡ ε → x ≡ (y ⁻¹)
inv-uniqueʳ = assoc+id+invʳ⇒invʳ-unique assoc identity inverseʳ
inv-uniqueˡ : ∀ x y → (x • y) ≡ ε → y ≡ (x ⁻¹)
inv-uniqueˡ = assoc+id+invˡ⇒invˡ-unique assoc identity inverseˡ
cancelˡ : LeftCancellative _•_
cancelˡ = assoc+idˡ+invˡ⇒cancelˡ assoc identityˡ inverseˡ
cancelʳ : RightCancellative _•_
cancelʳ = assoc+idʳ+invʳ⇒cancelʳ assoc identityʳ inverseʳ
record IsAbelianGroup (_+_ : Op₂ A) (ε : A) (-_ : Op₁ A) : Type a where
constructor isabgroup
field
isGroup : IsGroup _+_ ε -_
comm : Commutative _+_
open IsGroup isGroup public hiding (_/ˡ_) renaming (_/_ to _-_; _^_ to _*_)
isCommutativeMonoid : IsCommutativeMonoid _+_ ε
isCommutativeMonoid = record
{ isMonoid = isMonoid
; comm = comm
}
open IsCommutativeMonoid isCommutativeMonoid public
using (isCommutativeSemigroup)
------------------------------------------------------------------------
-- Algebra with 2 binary operations
------------------------------------------------------------------------
-- Note that `IsLattice` is not defined in terms of `IsSemilattice`
-- because the idempotence laws of ⋀ and ⋁ can be derived from the
-- absorption laws, which makes the corresponding "idem" fields
-- redundant. The derived idempotence laws are stated and proved in
-- `Algebra.Properties.Lattice` along with the fact that every lattice
-- consists of two semilattices.
record IsLattice (_⋀_ _⋁_ : Op₂ A) : Type a where
constructor islattice
field
⋀-comm : Commutative _⋀_
⋀-assoc : Associative _⋀_
⋁-comm : Commutative _⋁_
⋁-assoc : Associative _⋁_
absorptive : Absorptive _⋀_ _⋁_
⋀-absorbs-⋁ : _⋀_ Absorbs _⋁_
⋀-absorbs-⋁ = fst absorptive
⋁-absorbs-⋀ : _⋁_ Absorbs _⋀_
⋁-absorbs-⋀ = snd absorptive
record IsDistributiveLattice (_⋀_ _⋁_ : Op₂ A) : Type a where
constructor isdistrlattice
field
isLattice : IsLattice _⋀_ _⋁_
⋀-distribʳ-⋁ : _⋀_ DistributesOverʳ _⋁_
open IsLattice isLattice public
------------------------------------------------------------------------
-- Algebra with 2 binary operations & 1 element
------------------------------------------------------------------------
record IsNearSemiring (_+_ _*_ : Op₂ A) (0# : A) : Type a where
constructor isnearsemiring
field
+-isMonoid : IsMonoid _+_ 0#
*-isSemigroup : IsSemigroup _*_
distribˡ : _*_ DistributesOverˡ _+_
zeroˡ : LeftZero 0# _*_
open IsMonoid +-isMonoid public
renaming
( assoc to +-assoc
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; ε-uniqueˡ to 0#-uniqueˡ
; ε-uniqueʳ to 0#-uniqueʳ
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; _^_ to _**_
)
open IsSemigroup *-isSemigroup public
using (_^_)
renaming
( assoc to *-assoc
; isMagma to *-isMagma
)
record IsSemiringWithoutOne (_+_ _*_ : Op₂ A) (0# : A) : Type a where
constructor issemiringwo1
field
+-isCommutativeMonoid : IsCommutativeMonoid _+_ 0#
*-isSemigroup : IsSemigroup _*_
distrib : _*_ DistributesOver _+_
zero : Zero 0# _*_
open IsCommutativeMonoid +-isCommutativeMonoid public
using ()
renaming
( comm to +-comm
; isMonoid to +-isMonoid
; isCommutativeSemigroup to +-isCommutativeSemigroup
)
zeroˡ : LeftZero 0# _*_
zeroˡ = fst zero
zeroʳ : RightZero 0# _*_
zeroʳ = snd zero
distribˡ : _*_ DistributesOverˡ _+_
distribˡ = fst distrib
distribʳ : _*_ DistributesOverʳ _+_
distribʳ = snd distrib
isNearSemiring : IsNearSemiring _+_ _*_ 0#
isNearSemiring = record
{ +-isMonoid = +-isMonoid
; *-isSemigroup = *-isSemigroup
; distribˡ = distribˡ
; zeroˡ = zeroˡ
}
open IsNearSemiring isNearSemiring public
hiding (+-isMonoid; zeroˡ; *-isSemigroup; distribˡ)
record IsCommutativeSemiringWithoutOne (_+_ _*_ : Op₂ A) (0# : A) : Type a where
constructor iscommsemiringwo1
field
isSemiringWithoutOne : IsSemiringWithoutOne _+_ _*_ 0#
*-comm : Commutative _*_
open IsSemiringWithoutOne isSemiringWithoutOne public
------------------------------------------------------------------------
-- Algebra with 2 binary operations & 2 elements
------------------------------------------------------------------------
record IsSemiringWithoutAnnihilatingZero (_+_ _*_ : Op₂ A)
(0# 1# : A) : Type a where
constructor issemiringwoa0
field
-- Note that these Algebra do have an additive unit, but this
-- unit does not necessarily annihilate multiplication.
+-isCommutativeMonoid : IsCommutativeMonoid _+_ 0#
*-isMonoid : IsMonoid _*_ 1#
distrib : _*_ DistributesOver _+_
distribˡ : _*_ DistributesOverˡ _+_
distribˡ = fst distrib
distribʳ : _*_ DistributesOverʳ _+_
distribʳ = snd distrib
open IsCommutativeMonoid +-isCommutativeMonoid public
renaming
( assoc to +-assoc
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; ε-uniqueˡ to 0#-uniqueˡ
; ε-uniqueʳ to 0#-uniqueʳ
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isCommutativeSemigroup to +-isCommutativeSemigroup
; _^_ to _**_
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; ε-uniqueˡ to 1#-uniqueˡ
; ε-uniqueʳ to 1#-uniqueʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
record IsSemiring (_+_ _*_ : Op₂ A) (0# 1# : A) : Type a where
constructor issemiring
field
isSemiringWithoutAnnihilatingZero :
IsSemiringWithoutAnnihilatingZero _+_ _*_ 0# 1#
zero : Zero 0# _*_
open IsSemiringWithoutAnnihilatingZero
isSemiringWithoutAnnihilatingZero public
isSemiringWithoutOne : IsSemiringWithoutOne _+_ _*_ 0#
isSemiringWithoutOne = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isSemigroup = *-isSemigroup
; distrib = distrib
; zero = zero
}
open IsSemiringWithoutOne isSemiringWithoutOne public
using
( isNearSemiring
; zeroˡ
; zeroʳ
)
record IsCommutativeSemiring (_+_ _*_ : Op₂ A) (0# 1# : A) : Type a where
constructor iscommsemiring
field
isSemiring : IsSemiring _+_ _*_ 0# 1#
*-comm : Commutative _*_
open IsSemiring isSemiring public
isCommutativeSemiringWithoutOne :
IsCommutativeSemiringWithoutOne _+_ _*_ 0#
isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = isSemiringWithoutOne
; *-comm = *-comm
}
*-isCommutativeSemigroup : IsCommutativeSemigroup _*_
*-isCommutativeSemigroup = record
{ isSemigroup = *-isSemigroup
; comm = *-comm
}
*-isCommutativeMonoid : IsCommutativeMonoid _*_ 1#
*-isCommutativeMonoid = record
{ isMonoid = *-isMonoid
; comm = *-comm
}
------------------------------------------------------------------------
-- Algebra with 2 binary operations, 1 unary operation & 2 elements
------------------------------------------------------------------------
record IsRing (_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Type a where
constructor isring
field
+-isAbelianGroup : IsAbelianGroup _+_ 0# -_
*-isMonoid : IsMonoid _*_ 1#
distrib : _*_ DistributesOver _+_
open IsAbelianGroup +-isAbelianGroup public
renaming
( assoc to +-assoc
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; ε-uniqueˡ to 0#-uniqueˡ
; ε-uniqueʳ to 0#-uniqueʳ
; inverse to +-inverse
; inverseˡ to +-inverseˡ
; inverseʳ to +-inverseʳ
; inv-uniqueˡ to neg-uniqueˡ
; inv-uniqueʳ to neg-uniqueʳ
; cancelˡ to +-cancelˡ
; cancelʳ to +-cancelʳ
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isCommutativeMonoid to +-isCommutativeMonoid
; isCommutativeSemigroup to +-isCommutativeSemigroup
; isGroup to +-isGroup
; _*_ to _**_
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; ε-uniqueˡ to 1#-uniqueˡ
; ε-uniqueʳ to 1#-uniqueʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
distribˡ : _*_ DistributesOverˡ _+_
distribˡ = fst distrib
distribʳ : _*_ DistributesOverʳ _+_
distribʳ = snd distrib
zeroˡ : LeftZero 0# _*_
zeroˡ = assoc+distribʳ+idʳ+invʳ⇒zeˡ {_+_ = _+_} {_*_ = _*_} { -_} +-assoc distribʳ +-identityʳ +-inverseʳ
zeroʳ : RightZero 0# _*_
zeroʳ = assoc+distribˡ+idʳ+invʳ⇒zeʳ {_+_ = _+_} {_*_ = _*_} { -_} +-assoc distribˡ +-identityʳ +-inverseʳ
zero : Zero 0# _*_
zero = zeroˡ , zeroʳ
isSemiringWithoutAnnihilatingZero
: IsSemiringWithoutAnnihilatingZero _+_ _*_ 0# 1#
isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-isMonoid
; distrib = distrib
}
isSemiring : IsSemiring _+_ _*_ 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero =
isSemiringWithoutAnnihilatingZero
; zero = zero
}
open IsSemiring isSemiring public
using (isNearSemiring; isSemiringWithoutOne)
record IsCommutativeRing (_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Type a where
constructor iscommring
field
isRing : IsRing _+_ _*_ -_ 0# 1#
*-comm : Commutative _*_
open IsRing isRing public
*-isCommutativeMonoid : IsCommutativeMonoid _*_ 1#
*-isCommutativeMonoid = record
{ isMonoid = *-isMonoid
; comm = *-comm
}
isCommutativeSemiring : IsCommutativeSemiring _+_ _*_ 0# 1#
isCommutativeSemiring = record
{ isSemiring = isSemiring
; *-comm = *-comm
}
open IsCommutativeSemiring isCommutativeSemiring public
using ( isCommutativeSemiringWithoutOne )
record IsIntegralDomain {ℓ} (Cancellable : A → Type ℓ) (_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Type (ℓ-max a ℓ) where
constructor isintegraldomain
Cancellables : Type (ℓ-max a ℓ)
Cancellables = Σ A Cancellable
field
isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0# 1#
*-cancelˡ : ∀ (x : Cancellables) {y z} → (x .fst) * y ≡ (x .fst) * z → y ≡ z
open IsCommutativeRing isCommutativeRing public
*-cancelʳ : ∀ {x y} (z : Cancellables) → x * (z .fst) ≡ y * (z .fst) → x ≡ y
*-cancelʳ {x} {y} zᵖ@(z , _) eq = *-cancelˡ zᵖ (
z * x ≡⟨ *-comm z x ⟩
x * z ≡⟨ eq ⟩
y * z ≡⟨ *-comm y z ⟩
z * y ∎)
record IsBooleanAlgebra (_⋀_ _⋁_ : Op₂ A) (¬_ : Op₁ A) (⊤ ⊥ : A) : Type a where
constructor isbooleanalgebra
field
isDistributiveLattice : IsDistributiveLattice _⋀_ _⋁_
⋀-identityʳ : RightIdentity ⊤ _⋀_
⋁-identityʳ : RightIdentity ⊥ _⋁_
⋀-complementʳ : RightInverse ⊥ ¬_ _⋀_
⋁-complementʳ : RightInverse ⊤ ¬_ _⋁_
open IsDistributiveLattice isDistributiveLattice public
⋀-identityˡ : LeftIdentity ⊤ _⋀_
⋀-identityˡ x = ⋀-comm _ _ ∙ ⋀-identityʳ x
⋀-identity : Identity ⊤ _⋀_
⋀-identity = ⋀-identityˡ , ⋀-identityʳ
⋁-identityˡ : LeftIdentity ⊥ _⋁_
⋁-identityˡ x = ⋁-comm _ _ ∙ ⋁-identityʳ x
⋁-identity : Identity ⊥ _⋁_
⋁-identity = ⋁-identityˡ , ⋁-identityʳ
⋀-complementˡ : LeftInverse ⊥ ¬_ _⋀_
⋀-complementˡ = comm+invʳ⇒invˡ ⋀-comm ⋀-complementʳ
⋀-complement : Inverse ⊥ ¬_ _⋀_
⋀-complement = ⋀-complementˡ , ⋀-complementʳ
⋁-complementˡ : LeftInverse ⊤ ¬_ _⋁_
⋁-complementˡ = comm+invʳ⇒invˡ ⋁-comm ⋁-complementʳ
⋁-complement : Inverse ⊤ ¬_ _⋁_
⋁-complement = ⋁-complementˡ , ⋁-complementʳ
------------------------------------------------------------------------
-- Algebra with 2 binary operations, 2 unary operations & 2 elements
------------------------------------------------------------------------
-- The standard definition of division rings excludes the zero ring, but such a restriction is rarely important
record IsDivisionRing {ℓ} (Invertible : A → Type ℓ) (_+_ _*_ : Op₂ A) (-_ : Op₁ A) (_⁻¹ : Σ A Invertible → A) (0# 1# : A) : Type (ℓ-max a ℓ) where
constructor isdivring
Invertibles : Type (ℓ-max a ℓ)
Invertibles = Σ A Invertible
field
isRing : IsRing _+_ _*_ -_ 0# 1#
*-inverseˡ : (x : Invertibles) → (x ⁻¹) * (x .fst) ≡ 1#
*-inverseʳ : (x : Invertibles) → (x .fst) * (x ⁻¹) ≡ 1#
open IsRing isRing public
infixl 6 _/_
_/_ : A → Invertibles → A
x / y = x * (y ⁻¹)
infixr 6 _/ˡ_
_/ˡ_ : Invertibles → A → A
x /ˡ y = (x ⁻¹) * y
*-cancelˡ : ∀ (x : Invertibles) {y z} → (x .fst) * y ≡ (x .fst) * z → y ≡ z
*-cancelˡ xᵖ@(x , _) {y} {z} eq =
y ≡˘⟨ *-identityˡ y ⟩
1# * y ≡˘⟨ cong (_* y) (*-inverseˡ xᵖ) ⟩
((xᵖ ⁻¹) * x) * y ≡⟨ *-assoc (xᵖ ⁻¹) x y ⟩
(xᵖ ⁻¹) * (x * y) ≡⟨ cong ((xᵖ ⁻¹) *_) eq ⟩
(xᵖ ⁻¹) * (x * z) ≡˘⟨ *-assoc (xᵖ ⁻¹) x z ⟩
((xᵖ ⁻¹) * x) * z ≡⟨ cong (_* z) (*-inverseˡ xᵖ) ⟩
1# * z ≡⟨ *-identityˡ z ⟩
z ∎
*-cancelʳ : ∀ {x y} (z : Invertibles) → x * (z .fst) ≡ y * (z .fst) → x ≡ y
*-cancelʳ {x} {y} zᵖ@(z , _) eq =
x ≡˘⟨ *-identityʳ x ⟩
x * 1# ≡˘⟨ cong (x *_) (*-inverseʳ zᵖ) ⟩
x * (z * (zᵖ ⁻¹)) ≡˘⟨ *-assoc x z (zᵖ ⁻¹) ⟩
(x * z) * (zᵖ ⁻¹) ≡⟨ cong (_* (zᵖ ⁻¹)) eq ⟩
(y * z) * (zᵖ ⁻¹) ≡⟨ *-assoc y z (zᵖ ⁻¹) ⟩
y * (z * (zᵖ ⁻¹)) ≡⟨ cong (y *_) (*-inverseʳ zᵖ) ⟩
y * 1# ≡⟨ *-identityʳ y ⟩
y ∎
record IsField {ℓ} (Invertible : A → Type ℓ) (_+_ _*_ : Op₂ A) (-_ : Op₁ A) (_⁻¹ : Σ A Invertible → A) (0# 1# : A) : Type (ℓ-max a ℓ) where
constructor isfield
field
isDivisionRing : IsDivisionRing Invertible _+_ _*_ -_ _⁻¹ 0# 1#
*-comm : Commutative _*_
open IsDivisionRing isDivisionRing public hiding (_/ˡ_)
isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0# 1#
isCommutativeRing = record
{ isRing = isRing
; *-comm = *-comm
}
isIntegralDomain : IsIntegralDomain Invertible _+_ _*_ -_ 0# 1#
isIntegralDomain = record
{ isCommutativeRing = isCommutativeRing
; *-cancelˡ = *-cancelˡ
}
open IsIntegralDomain isIntegralDomain public
using (*-isCommutativeMonoid; isCommutativeSemiring; isCommutativeSemiringWithoutOne)
| 29.693787
| 146
| 0.581727
|
9ab5cc82a2636bb33b6f952052d337ce75a79c54
| 8,663
|
agda
|
Agda
|
src/Pushout.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Pushout.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Pushout.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Pushouts, defined using a HIT
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- This module follows the HoTT book rather closely.
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining pushouts uses path equality, but
-- the supplied notion of equality is used for many other things.
import Equality.Path as P
module Pushout
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J hiding (id; _∘_)
import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import Pointed-type equality-with-J using (Pointed-type)
import Suspension eq as S
private
variable
a b l ℓ m p r : Level
A B : Type a
S : A
-- Spans.
record Span l r m : Type (lsuc (l ⊔ r ⊔ m)) where
field
{Left} : Type l
{Right} : Type r
{Middle} : Type m
left : Middle → Left
right : Middle → Right
-- Pushouts.
data Pushout (S : Span l r m) : Type (l ⊔ r ⊔ m) where
inl : Span.Left S → Pushout S
inr : Span.Right S → Pushout S
glueᴾ : (x : Span.Middle S) →
inl (Span.left S x) P.≡ inr (Span.right S x)
-- Glue.
glue : (x : Span.Middle S) →
_≡_ {A = Pushout S} (inl (Span.left S x)) (inr (Span.right S x))
glue x = _↔_.from ≡↔≡ (glueᴾ x)
-- A dependent eliminator, expressed using paths.
elimᴾ :
{S : Span l r m} (open Span S)
(P : Pushout S → Type p)
(h₁ : (x : Left) → P (inl x))
(h₂ : (x : Right) → P (inr x)) →
(∀ x → P.[ (λ i → P (glueᴾ x i)) ] h₁ (left x) ≡ h₂ (right x)) →
(x : Pushout S) → P x
elimᴾ P h₁ h₂ g = λ where
(inl x) → h₁ x
(inr x) → h₂ x
(glueᴾ x i) → g x i
-- A non-dependent eliminator.
recᴾ :
{S : Span l r m} (open Span S)
(h₁ : Left → A)
(h₂ : Right → A) →
(∀ x → h₁ (left x) P.≡ h₂ (right x)) →
Pushout S → A
recᴾ = elimᴾ _
-- A dependent eliminator.
elim :
{S : Span l r m} (open Span S)
(P : Pushout S → Type p)
(h₁ : (x : Left) → P (inl x))
(h₂ : (x : Right) → P (inr x)) →
(∀ x → subst P (glue x) (h₁ (left x)) ≡ h₂ (right x)) →
(x : Pushout S) → P x
elim P h₁ h₂ g = elimᴾ P h₁ h₂ (subst≡→[]≡ ∘ g)
elim-glue :
{S : Span l r m} (open Span S) {P : Pushout S → Type p}
{h₁ : (x : Left) → P (inl x)}
{h₂ : (x : Right) → P (inr x)}
{g : ∀ x → subst P (glue x) (h₁ (left x)) ≡ h₂ (right x)}
{x : Middle} →
dcong (elim P h₁ h₂ g) (glue x) ≡ g x
elim-glue = dcong-subst≡→[]≡ (refl _)
-- A non-dependent eliminator.
rec :
{S : Span l r m} (open Span S)
(h₁ : Left → A)
(h₂ : Right → A) →
(∀ x → h₁ (left x) ≡ h₂ (right x)) →
Pushout S → A
rec h₁ h₂ g = recᴾ h₁ h₂ (_↔_.to ≡↔≡ ∘ g)
rec-glue :
{S : Span l r m} (open Span S)
{h₁ : Left → A} {h₂ : Right → A}
{g : ∀ x → h₁ (left x) ≡ h₂ (right x)}
{x : Middle} →
cong (rec h₁ h₂ g) (glue x) ≡ g x
rec-glue = cong-≡↔≡ (refl _)
-- Cocones.
Cocone : Span l r m → Type a → Type (a ⊔ l ⊔ r ⊔ m)
Cocone S A =
∃ λ (left : Left → A) →
∃ λ (right : Right → A) →
(x : Middle) → left (Span.left S x) ≡ right (Span.right S x)
where
open Span S using (Left; Right; Middle)
-- Some projection functions for cocones.
module Cocone (c : Cocone S A) where
open Span S using (Left; Right; Middle)
left : Left → A
left = proj₁ c
right : Right → A
right = proj₁ (proj₂ c)
left-left≡right-right :
(x : Middle) → left (Span.left S x) ≡ right (Span.right S x)
left-left≡right-right = proj₂ (proj₂ c)
-- A universal property for pushouts.
Pushout→↔Cocone : (Pushout S → A) ↔ Cocone S A
Pushout→↔Cocone {S = S} {A = A} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to-from
}
; left-inverse-of = from-to
}
where
open Span S
to : (Pushout S → A) → Cocone S A
to f = f ∘ inl , f ∘ inr , cong f ∘ glue
from : Cocone S A → (Pushout S → A)
from c = rec
(Cocone.left c)
(Cocone.right c)
(Cocone.left-left≡right-right c)
to-from : ∀ c → to (from c) ≡ c
to-from c = cong (λ x → _ , _ , x) $ ⟨ext⟩ λ x →
cong (from c) (glue x) ≡⟨ rec-glue ⟩∎
Cocone.left-left≡right-right c x ∎
from-to : ∀ f → from (to f) ≡ f
from-to f = ⟨ext⟩ $ elim
_
(λ _ → refl _)
(λ _ → refl _)
(λ x →
subst (λ y → from (to f) y ≡ f y) (glue x) (refl _) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (from (to f)) (glue x)))
(trans (refl _) (cong f (glue x))) ≡⟨ cong (trans _) $ trans-reflˡ _ ⟩
trans (sym (cong (from (to f)) (glue x))) (cong f (glue x)) ≡⟨ cong (λ eq → trans (sym eq) (cong f (glue x))) rec-glue ⟩
trans (sym (Cocone.left-left≡right-right (to f) x)) (cong f (glue x)) ≡⟨⟩
trans (sym (cong f (glue x))) (cong f (glue x)) ≡⟨ trans-symˡ _ ⟩∎
refl _ ∎)
-- Joins.
Join : Type a → Type b → Type (a ⊔ b)
Join A B = Pushout (record
{ Middle = A × B
; left = proj₁
; right = proj₂
})
-- Join is symmetric.
Join-symmetric : Join A B ≃ Join B A
Join-symmetric = Eq.↔→≃
to
to
to-to
to-to
where
to : Join A B → Join B A
to = rec inr inl (sym ∘ glue ∘ swap)
to-to : (x : Join A B) → to (to x) ≡ x
to-to =
elim _ (λ _ → refl _) (λ _ → refl _)
(λ p →
subst (λ x → to (to x) ≡ x) (glue p) (refl _) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (to ∘ to) (glue p)))
(trans (refl _) (cong id (glue p))) ≡⟨ cong₂ (trans ∘ sym)
(sym $ cong-∘ _ _ _)
(trans (trans-reflˡ _) $
sym $ cong-id _) ⟩
trans (sym (cong to (cong to (glue p)))) (glue p) ≡⟨ cong (flip trans _) $ cong (sym ∘ cong to) rec-glue ⟩
trans (sym (cong to (sym (glue (swap p))))) (glue p) ≡⟨ cong (flip trans _) $ cong sym $ cong-sym _ _ ⟩
trans (sym (sym (cong to (glue (swap p))))) (glue p) ≡⟨ cong (flip trans _) $ sym-sym _ ⟩
trans (cong to (glue (swap p))) (glue p) ≡⟨ cong (flip trans _) rec-glue ⟩
trans (sym (glue (swap (swap p)))) (glue p) ≡⟨⟩
trans (sym (glue p)) (glue p) ≡⟨ trans-symˡ _ ⟩∎
refl _ ∎)
-- The empty type is a right identity for Join.
Join-⊥ʳ : Join A (⊥ {ℓ = ℓ}) ≃ A
Join-⊥ʳ = Eq.↔→≃
(rec id ⊥-elim (λ { (_ , ()) }))
inl
refl
(elim _ (λ _ → refl _) (λ ()) (λ { (_ , ()) }))
-- The empty type is a left identity for Join.
Join-⊥ˡ : Join (⊥ {ℓ = ℓ}) A ≃ A
Join-⊥ˡ {A = A} =
Join ⊥ A ↝⟨ Join-symmetric ⟩
Join A ⊥ ↝⟨ Join-⊥ʳ ⟩□
A □
-- Cones.
Cone : {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b)
Cone f = Pushout (record
{ Left = ⊤
; right = f
})
-- Wedges.
Wedge : Pointed-type a → Pointed-type b → Type (a ⊔ b)
Wedge (A , a) (B , b) =
Pushout (record
{ Middle = ⊤
; left = const a
; right = const b
})
-- Smash products.
Smash-product : Pointed-type a → Pointed-type b → Type (a ⊔ b)
Smash-product PA@(A , a) PB@(B , b) = Cone f
where
f : Wedge PA PB → A × B
f = rec (_, b) (a ,_) (λ _ → refl _)
-- Suspensions.
Susp : Type a → Type a
Susp A = Pushout (record
{ Left = ⊤
; Middle = A
; Right = ⊤
})
-- These suspensions are equivalent to the ones defined in Suspension.
Susp≃Susp : Susp A ≃ S.Susp A
Susp≃Susp = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
})
where
to : Susp A → S.Susp A
to = recᴾ (λ _ → S.north) (λ _ → S.south) S.meridianᴾ
from : S.Susp A → Susp A
from = S.recᴾ (inl _) (inr _) glueᴾ
to∘from : ∀ x → to (from x) ≡ x
to∘from =
_↔_.from ≡↔≡ ∘
S.elimᴾ _ P.refl P.refl (λ a i _ → S.meridianᴾ a i)
from∘to : ∀ x → from (to x) ≡ x
from∘to =
_↔_.from ≡↔≡ ∘
elimᴾ _ (λ _ → P.refl) (λ _ → P.refl) (λ a i _ → glueᴾ a i)
| 26.655385
| 138
| 0.503521
|
0389d61de892cd29057fec8c2f1d174b5e55bb43
| 445
|
agda
|
Agda
|
Cubical/Relation/Binary/Raw/Construct/Never.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Raw/Construct/Never.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Raw/Construct/Never.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Raw.Construct.Never where
open import Cubical.Core.Everything
open import Cubical.Relation.Binary.Raw
open import Cubical.Relation.Binary.Raw.Construct.Constant
open import Cubical.Data.Empty.Polymorphic using (⊥)
------------------------------------------------------------------------
-- Definition
Never : ∀ {a ℓ} {A : Type a} → RawRel A ℓ
Never = Const ⊥
| 29.666667
| 72
| 0.626966
|
fb2626f472ddc52d316b885344616ed80a2e10bc
| 4,559
|
agda
|
Agda
|
examples/outdated-and-incorrect/univ/proofs.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/univ/proofs.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/univ/proofs.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module proofs where
open import univ
open import cwf
open import Base
open import Nat
open import help
{-
lem-id∘ : {Γ Δ : Con}(σ : Γ ─→ Δ) -> id ∘ σ == σ
lem-id∘ (el < σ , pσ >) = eq \x -> ref
lem-∘id : {Γ Δ : Con}(σ : Γ ─→ Δ) -> σ ∘ id == σ
lem-∘id (el < σ , pσ >) = eq \x -> ref
lem-∘assoc : {Γ Δ Θ Ξ : Con}(σ : Θ ─→ Ξ)(δ : Δ ─→ Θ)(θ : Γ ─→ Δ) ->
(σ ∘ δ) ∘ θ == σ ∘ (δ ∘ θ)
lem-∘assoc (el < σ , pσ >) (el < δ , pδ >) (el < θ , pθ >) = eq \x -> ref
-}
lem-/∘ : {Γ Δ Θ : Con}(A : Type Γ)(σ : Δ ─→ Γ)(δ : Θ ─→ Δ) ->
A / σ ∘ δ =Ty A / σ / δ
lem-/∘ A (el < _ , _ >) (el < _ , _ >) = eqTy \x -> refS
{-
lem-//id : {Γ : Con}{A : Type Γ}{u : Elem Γ A} -> u // id =El castElem lem-/id u
lem-//id {Γ}{A}{elem (el < u , pu >)} = eqEl (eq prf)
where
prf : (x : El Γ) -> _
prf x =
chain> u x
=== _ << u (refS << x) by pu (sym (ref<< x))
=== _ << u (refS << x) by pfi _ _ _
where open module C11 = Chain _==_ (ref {_}) (trans {_})
lem-//∘ : {Γ Δ Θ : Con}{A : Type Γ}(u : Elem Γ A)(σ : Δ ─→ Γ)(δ : Θ ─→ Δ) ->
u // σ ∘ δ =El castElem (lem-/∘ A σ δ) (u // σ // δ)
lem-//∘ {Γ}{Δ}{Θ} (elem (el < u , pu >)) σ'@(el < σ , _ >) δ'@(el < δ , _ >) = eqEl (eq prf)
where
prf : (x : El Θ) -> _
prf x =
chain> u (σ (δ x))
=== _ << u (σ (δ (refS << x))) by pu (p─→ σ' (p─→ δ' (sym (ref<< x))))
=== _ << u (σ (δ (refS << x))) by pfi _ _ _
where open module C12 = Chain _==_ (ref {_}) (trans {_})
lem-wk∘σ,,u : {Γ Δ : Con}{A : Type Γ}(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->
wk ∘ (σ ,, u) == σ
lem-wk∘σ,,u (el < σ , pσ >) (elem (el < u , pu >)) = eq \x -> ref
lem-/wk∘σ,,u : {Γ Δ : Con}(A : Type Γ)(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->
A / wk / (σ ,, u) =Ty A / σ
lem-/wk∘σ,,u A (el < σ , pσ >) (elem (el < u , pu >)) = eqTy \x -> refS
lem-vz/σ,,u : {Γ Δ : Con}{A : Type Γ}(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->
vz // (σ ,, u) =El castElem (lem-/wk∘σ,,u A σ u) u
lem-vz/σ,,u (el < σ , pσ >) (elem (el < u , pu >)) = eqEl (eq \x -> prf x)
where
prf : (x : El _) -> u x == _ << u (refS << x)
prf x =
chain> u x
=== _ << u (refS << x) by pu (sym (ref<< x))
=== _ << u (refS << x) by pfi _ _ _
where open module C15 = Chain _==_ (ref {_}) (trans {_})
lem-σ,,u∘ : {Γ Δ Θ : Con}{A : Type Γ}
(σ : Δ ─→ Γ)(u : Elem Δ (A / σ))(δ : Θ ─→ Δ) ->
(σ ,, u) ∘ δ == (σ ∘ δ ,, castElem (lem-/∘ A σ δ) (u // δ))
lem-σ,,u∘ (el < σ , _ >) (elem (el < u , pu >)) δ'@(el < δ , _ >) =
eq \x -> eq < ref , prf x >
where
prf : (x : El _) -> u (δ x) == _ << _ << u (δ (refS << x))
prf x =
chain> u (δ x)
=== _ << u (δ (refS << x)) by pu (p─→ δ' (sym (ref<< x)))
=== _ << _ << u (δ (refS << x)) by sym (casttrans _ _ _ _)
where open module C15 = Chain _==_ (ref {_}) (trans {_})
lem-wk,,vz : {Γ : Con}{A : Type Γ} -> (wk ,, vz) == id {Γ , A}
lem-wk,,vz {Γ}{A} = eq prf
where
prf : (x : El (Γ , A)) -> _
prf (el < x , y >) = ref
-}
lem-Π/ : {Γ Δ : Con}{A : Type Γ}(B : Type (Γ , A))(σ : Δ ─→ Γ) ->
Π A B / σ =Ty Π (A / σ) (B / (σ ∘ wk ,, castElem (lem-/∘ A σ wk) vz))
lem-Π/ B (el < σ , pσ >) =
eqTy \x -> eqS < refS , (\y -> pFam B (eq < ref , prf x y >)) >
where
postulate prf : (x : El _)(y : El _) -> y == _ << _ << _ << _ << y
-- prf x y =
-- chain> y
-- === _ << _ << y by sym (castref2 _ _ y)
-- === _ << _ << _ << y by trans<< _ _ _
-- === _ << _ << _ << _ << y by trans<< _ _ _
-- where open module C16 = Chain _==_ (ref {_}) (trans {_})
{-
lem-β : {Γ : Con}{A : Type Γ}{B : Type (Γ , A)}
(v : Elem (Γ , A) B)(u : Elem Γ A) ->
(ƛ v) ∙ u =El v // [ u ]
lem-β {Γ}{A}{B} (elem (el < v , pv >)) (elem (el < u , pu >)) = eqEl (eq \x -> prf x _ _)
where
prf : (x : El Γ)(q : _ =S _)(p : _ =S _) ->
p << v (el < x , u x >) == v (el < x , q << u (refS << x) >)
prf x q p =
chain> p << v (el < x , u x >)
=== p << q0 << v (el < x , q1 << u (refS << x) >)
by p<< p (pv (eqSnd (pu (sym (ref<< x)))))
=== q2 << v (el < x , q1 << u (refS << x) >)
by sym (trans<< p q0 _)
=== q2 << q3 << v (el < x , q << u (refS << x) >)
by p<< q2 (pv (eqSnd (pfi q1 q _)))
=== v (el < x , q << u (refS << x) >)
by castref2 q2 q3 _
where
open module C17 = Chain _==_ (ref {_}) (trans {_})
q0 = _
q1 = _
q2 = _
q3 = _
-}
| 36.18254
| 92
| 0.37596
|
ad16b0998653ede4fd2d68abc8c33af6e1c6e43b
| 78
|
agda
|
Agda
|
src/HelloWorld.agda
|
notogawa/agda-haskell-example
|
9ad77d2aed8f950151e009135a9dfc02bc32ce65
|
[
"BSD-3-Clause"
] | 5
|
2015-07-28T05:04:58.000Z
|
2017-11-07T01:35:46.000Z
|
src/HelloWorld.agda
|
notogawa/agda-haskell-example
|
9ad77d2aed8f950151e009135a9dfc02bc32ce65
|
[
"BSD-3-Clause"
] | null | null | null |
src/HelloWorld.agda
|
notogawa/agda-haskell-example
|
9ad77d2aed8f950151e009135a9dfc02bc32ce65
|
[
"BSD-3-Clause"
] | null | null | null |
module HelloWorld where
open import IO
main = run (putStrLn "Hello,World!")
| 13
| 36
| 0.74359
|
1a6df4c66394435539f2e6639e27be43b8278948
| 5,011
|
agda
|
Agda
|
README.agda
|
loic-p/logrel-mltt
|
2251b8da423be0c6fb916f2675d7bd8537e4cd96
|
[
"MIT"
] | null | null | null |
README.agda
|
loic-p/logrel-mltt
|
2251b8da423be0c6fb916f2675d7bd8537e4cd96
|
[
"MIT"
] | null | null | null |
README.agda
|
loic-p/logrel-mltt
|
2251b8da423be0c6fb916f2675d7bd8537e4cd96
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module README where
-- Formalization for "Decidability of Conversion for Type Theory in Type Theory"
-- Git repository: https://github.com/mr-ohman/logrel-mltt
------------------
-- INTRODUCTION --
------------------
-- A minimal library necessary for formalization:
-- Embedding types into larger universes
import Tools.Embedding
-- The empty type and its elimination rule.
import Tools.Empty
-- The unit type.
import Tools.Unit
-- Sum type.
import Tools.Sum
-- Product type.
import Tools.Product
-- Identity function and composition.
import Tools.Function
-- Negation and decidability type.
import Tools.Nullary
-- Propositional equality and its properties.
import Tools.PropositionalEquality
-- Natural numbers and decidability of equality.
import Tools.Nat
---------------------------
-- LANGUAGE INTRODUCTION --
---------------------------
-- Syntax and semantics of weakening and substitution.
import Definition.Untyped
-- Propositional equality properties: Equalities between expressions,
-- weakenings, substitutions and their combined composition.
-- (These lemmas are not in the paper.)
import Definition.Untyped.Properties
-- Judgements: Typing rules, conversion, reduction rules
-- and well-formed substitutions and respective equality.
import Definition.Typed
-- Well-formed context extraction and reduction properties.
import Definition.Typed.Properties
-- Well-formed weakening and its properties.
import Definition.Typed.Weakening
------------------------------
-- KRIPKE LOGICAL RELATIONS --
------------------------------
-- Generic equality relation definition.
import Definition.Typed.EqualityRelation
-- The judgemental instance of the generic equality.
import Definition.Typed.EqRelInstance
-- Logical relations definitions.
import Definition.LogicalRelation
-- Properties of logical relation:
-- Reflexivity of the logical relation.
import Definition.LogicalRelation.Properties.Reflexivity
-- Escape lemma for the logical relation.
import Definition.LogicalRelation.Properties.Escape
-- Shape view of two or more types.
import Definition.LogicalRelation.ShapeView
-- Proof irrelevance for the logical relation.
import Definition.LogicalRelation.Irrelevance
-- Weakening of logical relation judgements.
import Definition.LogicalRelation.Weakening
-- Conversion of the logical relation.
import Definition.LogicalRelation.Properties.Conversion
-- Symmetry of the logical relation.
import Definition.LogicalRelation.Properties.Symmetry
-- Transitvity of the logical relation.
import Definition.LogicalRelation.Properties.Transitivity
-- Neutral introduction in the logical relation.
import Definition.LogicalRelation.Properties.Neutral
-- Weak head expansion of the logical relation.
import Definition.LogicalRelation.Properties.Reduction
-- Application in the logical relation.
import Definition.LogicalRelation.Application
-- Validity judgements definitions
import Definition.LogicalRelation.Substitution
-- Properties of validity judgements:
-- Proof irrelevance for the validity judgements.
import Definition.LogicalRelation.Substitution.Irrelevance
-- Properties about valid substitutions:
-- * Substitution well-formedness.
-- * Substitution weakening.
-- * Substitution lifting.
-- * Identity substitution.
-- * Reflexivity, symmetry and transitivity of substitution equality.
import Definition.LogicalRelation.Substitution.Properties
-- Single term substitution of validity judgements.
import Definition.LogicalRelation.Substitution.Introductions.SingleSubst
-- The fundamental theorem.
import Definition.LogicalRelation.Fundamental
-- Certain cases of the logical relation:
-- Validity of Π-types.
import Definition.LogicalRelation.Substitution.Introductions.Pi
-- Validity of applications.
import Definition.LogicalRelation.Substitution.Introductions.Application
-- Validity of λ-terms.
import Definition.LogicalRelation.Substitution.Introductions.Lambda
-- Validity of natural recursion of natural numbers.
import Definition.LogicalRelation.Substitution.Introductions.Natrec
-- Reducibility of well-formedness.
import Definition.LogicalRelation.Fundamental.Reducibility
-- Consequences of the fundamental theorem:
-- Canonicity of the system.
import Definition.Typed.Consequences.Canonicity
-- Injectivity of Π-types.
import Definition.Typed.Consequences.Injectivity
-- Syntactic validitiy of the system.
import Definition.Typed.Consequences.Syntactic
-- All types and terms fully reduce to WHNF.
import Definition.Typed.Consequences.Reduction
-- Strong equality of types.
import Definition.Typed.Consequences.Equality
-- Substiution in judgements and substitution composition.
import Definition.Typed.Consequences.Substitution
-- Uniqueness of the types of neutral terms.
import Definition.Typed.Consequences.NeTypeEq
-- Universe membership of types.
import Definition.Typed.Consequences.InverseUniv
-- Consistency of the type theory.
import Definition.Typed.Consequences.Consistency
| 27.532967
| 80
| 0.790661
|
2eab347236c3aaeb4189029ba24e83a87031c4c5
| 747
|
agda
|
Agda
|
test/Succeed/Issue2827.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2827.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2827.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ (C Dummy : Set) where
data Maybe : Set where
nothing : Maybe
IfJust : Maybe → Set → Set
IfJust nothing P = P
postulate
qCtx : C
inferRes : Maybe
-- v-- Implicit is important here
inferResBest : IfJust inferRes ({G : Maybe} → C)
inferResBest with inferRes
inferResBest | nothing = qCtx -- Error: Dummy != C when checking qCtx : C
-- Test also with an existing implicit argument
inferResBest₁ : {A : Set} → IfJust inferRes ({G : Maybe} → C)
inferResBest₁ with inferRes
inferResBest₁ | nothing = qCtx -- Error: Dummy != C when checking qCtx : C
-- Make sure it does break down on underapplied clauses
underapplied : Maybe → C
underapplied with inferRes
underapplied | nothing = λ _ → qCtx
| 26.678571
| 77
| 0.676037
|
5e26c417e47425324bfe84733fe98aecfd7eed53
| 417
|
agda
|
Agda
|
test/interaction/Long.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Long.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/interaction/Long.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
module Long where
data Nat : Set where
z : Nat
s : (n : Nat) → Nat
data Exp : Set where
val : (n : Nat) → Exp
throw : Exp
data Maybe (A : Set) : Set where
Just : A → Maybe A
Nothing : Maybe A
abstract
s′ : Nat → Nat
s′ = s
eval : Exp → Maybe Nat
eval (val n) = ?
eval throw = ?
data D : Nat → Set where
d : D z
foo : D {!!}
foo = {!!}
bar : D z
bar = {!!}
baz : Maybe {!!}
baz = {!!}
| 11.914286
| 32
| 0.513189
|
040cfa56a89b548ce7f5ee554c2524b71a8f00e3
| 575
|
agda
|
Agda
|
test/Succeed/Positivity.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Positivity.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Positivity.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Positivity where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
data Tree : Set where
node : List Tree -> Tree
data Loop (A : Set) : Set where
loop : Loop (Loop A) -> Loop A
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
data PList (A : Set) : Set where
leaf : A -> PList A
succ : PList (A × A) -> PList A
data Bush (A : Set) : Set where
nil : Bush A
cons : A -> Bush (Bush A) -> Bush A
F : Set -> Set
F A = A
data Ok : Set where
ok : F Ok -> Ok
| 16.428571
| 37
| 0.542609
|
4b92e09ab3002be8c0dbddfc84e45374cf49fefc
| 8,624
|
agda
|
Agda
|
Definition/Typed/Consequences/Injectivity.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/Typed/Consequences/Injectivity.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/Typed/Consequences/Injectivity.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
module Definition.Typed.Consequences.Injectivity where
open import Definition.Untyped hiding (wk)
import Definition.Untyped as U
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Helper function of injectivity for specific reducible Π-types
injectivity′ : ∀ {F G H E rF lF rH lH rΠ lG lE Γ lΠ l}
([ΠFG] : Γ ⊩⟨ l ⟩Π Π F ^ rF ° lF ▹ G ° lG ° lΠ ^[ rΠ , lΠ ] )
→ Γ ⊩⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≡ Π H ^ rH ° lH ▹ E ° lE ° lΠ ^ [ rΠ , ι lΠ ] / Π-intr [ΠFG]
→ Γ ⊢ F ≡ H ^ [ rF , ι lF ]
× rF PE.≡ rH
× lF PE.≡ lH
× lG PE.≡ lE
× Γ ∙ F ^ [ rF , ι lF ] ⊢ G ≡ E ^ [ rΠ , ι lG ]
injectivity′ {F₁} {G₁} {H} {E} {lF = lF₁} {rΠ = rΠ} {Γ = Γ}
(noemb (Πᵣ ! lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let F≡F₁ , rF≡rF₁ , lF≡lF₁ , G≡G₁ , lG≡lG₁ , _ = Π-PE-injectivity (whnfRed* (red D) Πₙ)
H≡F′ , rH≡rF′ , lH≡lF′ , E≡G′ , lE≡lG′ , _ = Π-PE-injectivity (whnfRed* D′ Πₙ)
⊢Γ = wf ⊢F
[F]₁ = [F] id ⊢Γ
[F]′ = irrelevance′ (PE.trans (wk-id _) (PE.sym F≡F₁)) [F]₁
[x∷F] = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var 0) (var (⊢Γ ∙ ⊢F) here)
(refl (var (⊢Γ ∙ ⊢F) here))
[G]₁ = [G] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G]′ = PE.subst₂ (λ x y → _ ∙ y ^ _ ⊩⟨ _ ⟩ x ^ _)
(PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.sym F≡F₁) [G]₁
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]′ = irrelevanceEq″ (PE.trans (wk-id _) (PE.sym F≡F₁))
(PE.trans (wk-id _) (PE.sym H≡F′))
PE.refl PE.refl
[F]₁ [F]′ [F≡H]₁
[G≡E]₁ = [G≡G′] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G≡E]′ = irrelevanceEqLift″ (PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.trans (wkSingleSubstId _) (PE.sym E≡G′))
(PE.sym F≡F₁) [G]₁ [G]′ [G≡E]₁
in PE.subst (λ r → Γ ⊢ _ ≡ _ ^ [ r , ι lF₁ ] ) (PE.sym rF≡rF₁)
(PE.subst (λ l → Γ ⊢ F₁ ≡ H ^ [ ! , l ] ) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [F]′ [F≡H]′)) ,
( PE.trans rF≡rF₁ (PE.sym rH≡rF′) ,
( PE.trans lF≡lF₁ (PE.sym lH≡lF′) ,
( PE.trans lG≡lG₁ (PE.sym lE≡lG′) ,
PE.subst (λ r → (_ ∙ _ ^ [ r , _ ] ) ⊢ _ ≡ _ ^ _) (PE.sym rF≡rF₁)
(PE.subst (λ l → (Γ ∙ F₁ ^ [ ! , ι lF₁ ] ) ⊢ G₁ ≡ E ^ [ rΠ , l ]) (PE.cong ι (PE.sym lG≡lG₁))
(PE.subst (λ l → (Γ ∙ F₁ ^ [ ! , l ] ) ⊢ G₁ ≡ E ^ [ rΠ , ι lG ]) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [G]′ [G≡E]′))))))
injectivity′ {F₁} {G₁} {H} {E} {lF = lF₁} {rΠ = rΠ} {Γ = Γ}
(noemb (Πᵣ % lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let F≡F₁ , rF≡rF₁ , lF≡lF₁ , G≡G₁ , lG≡lG₁ , _ = Π-PE-injectivity (whnfRed* (red D) Πₙ)
H≡F′ , rH≡rF′ , lH≡lF′ , E≡G′ , lE≡lG′ , _ = Π-PE-injectivity (whnfRed* D′ Πₙ)
⊢Γ = wf ⊢F
[F]₁ = [F] id ⊢Γ
[F]′ = irrelevance′ (PE.trans (wk-id _) (PE.sym F≡F₁)) [F]₁
[x∷F] = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var 0) (var (⊢Γ ∙ ⊢F) here)
(proof-irrelevance (var (⊢Γ ∙ ⊢F) here) (var (⊢Γ ∙ ⊢F) here))
[G]₁ = [G] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G]′ = PE.subst₂ (λ x y → _ ∙ y ^ _ ⊩⟨ _ ⟩ x ^ _)
(PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.sym F≡F₁) [G]₁
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]′ = irrelevanceEq″ (PE.trans (wk-id _) (PE.sym F≡F₁))
(PE.trans (wk-id _) (PE.sym H≡F′))
PE.refl PE.refl
[F]₁ [F]′ [F≡H]₁
[G≡E]₁ = [G≡G′] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G≡E]′ = irrelevanceEqLift″ (PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.trans (wkSingleSubstId _) (PE.sym E≡G′))
(PE.sym F≡F₁) [G]₁ [G]′ [G≡E]₁
in PE.subst (λ r → Γ ⊢ _ ≡ _ ^ [ r , ι lF₁ ] ) (PE.sym rF≡rF₁)
(PE.subst (λ l → Γ ⊢ F₁ ≡ H ^ [ % , l ] ) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [F]′ [F≡H]′)) ,
( PE.trans rF≡rF₁ (PE.sym rH≡rF′) ,
( PE.trans lF≡lF₁ (PE.sym lH≡lF′) ,
( PE.trans lG≡lG₁ (PE.sym lE≡lG′) ,
PE.subst (λ r → (_ ∙ _ ^ [ r , _ ] ) ⊢ _ ≡ _ ^ _) (PE.sym rF≡rF₁)
(PE.subst (λ l → (Γ ∙ F₁ ^ [ % , ι lF₁ ] ) ⊢ G₁ ≡ E ^ [ rΠ , l ]) (PE.cong ι (PE.sym lG≡lG₁))
(PE.subst (λ l → (Γ ∙ F₁ ^ [ % , l ] ) ⊢ G₁ ≡ E ^ [ rΠ , ι lG ]) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [G]′ [G≡E]′))))))
injectivity′ (emb emb< x) [ΠFG≡ΠHE] = injectivity′ x [ΠFG≡ΠHE]
injectivity′ (emb ∞< x) [ΠFG≡ΠHE] = injectivity′ x [ΠFG≡ΠHE]
-- Injectivity of Π
injectivity : ∀ {Γ F G H E rF lF lH lG lE rH rΠ lΠ} →
Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≡ Π H ^ rH ° lH ▹ E ° lE ° lΠ ^ [ rΠ , ι lΠ ]
→ Γ ⊢ F ≡ H ^ [ rF , ι lF ]
× rF PE.≡ rH
× lF PE.≡ lH
× lG PE.≡ lE
× Γ ∙ F ^ [ rF , ι lF ] ⊢ G ≡ E ^ [ rΠ , ι lG ]
injectivity ⊢ΠFG≡ΠHE =
let [ΠFG] , _ , [ΠFG≡ΠHE] = reducibleEq ⊢ΠFG≡ΠHE
in injectivity′ (Π-elim [ΠFG])
(irrelevanceEq [ΠFG] (Π-intr (Π-elim [ΠFG])) [ΠFG≡ΠHE])
Uinjectivity′ : ∀ {Γ r₁ r₂ l₁ l₂ lU l}
([U] : Γ ⊩⟨ l ⟩U Univ r₁ l₁ ^ lU)
→ Γ ⊩⟨ l ⟩ Univ r₁ l₁ ≡ Univ r₂ l₂ ^ [ ! , lU ] / U-intr [U]
→ r₁ PE.≡ r₂ × l₁ PE.≡ l₂
Uinjectivity′ (noemb (Uᵣ r l′ l< eq d)) D =
let A , B = Univ-PE-injectivity (whnfRed* D Uₙ)
A' , B' = Univ-PE-injectivity (whnfRed* (red d) Uₙ)
in (PE.trans A' (PE.sym A)) , (PE.trans B' (PE.sym B))
Uinjectivity′ (emb emb< a) b = Uinjectivity′ a b
Uinjectivity′ (emb ∞< a) b = Uinjectivity′ a b
Uinjectivity : ∀ {Γ r₁ r₂ l₁ l₂ lU} →
Γ ⊢ Univ r₁ l₁ ≡ Univ r₂ l₂ ^ [ ! , lU ] →
r₁ PE.≡ r₂ × l₁ PE.≡ l₂
Uinjectivity ⊢U≡U =
let [U] , _ , [U≡U] = reducibleEq ⊢U≡U
in Uinjectivity′ (U-elim [U]) (irrelevanceEq [U] (U-intr (U-elim [U])) [U≡U])
-- injectivity of ∃
∃injectivity′ : ∀ {F G H E Γ l∃ l}
([∃FG] : Γ ⊩⟨ l ⟩∃ ∃ F ▹ G ^ l∃ )
→ Γ ⊩⟨ l ⟩ ∃ F ▹ G ≡ ∃ H ▹ E ^ [ % , ι l∃ ] / ∃-intr [∃FG]
→ Γ ⊢ F ≡ H ^ [ % , ι l∃ ]
× Γ ∙ F ^ [ % , ι l∃ ] ⊢ G ≡ E ^ [ % , ι l∃ ]
∃injectivity′ {F₁} {G₁} {H} {E} {Γ = Γ}
(noemb (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let F≡F₁ , G≡G₁ = ∃-PE-injectivity (whnfRed* (red D) ∃ₙ)
H≡F′ , E≡G′ = ∃-PE-injectivity (whnfRed* D′ ∃ₙ)
⊢Γ = wf ⊢F
[F]₁ = [F] id ⊢Γ
[F]′ = irrelevance′ (PE.trans (wk-id _) (PE.sym F≡F₁)) [F]₁
[x∷F] = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var 0) (var (⊢Γ ∙ ⊢F) here) (proof-irrelevance (var (⊢Γ ∙ ⊢F) here) (var (⊢Γ ∙ ⊢F) here))
[G]₁ = [G] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G]′ = PE.subst₂ (λ x y → _ ∙ y ^ _ ⊩⟨ _ ⟩ x ^ _)
(PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.sym F≡F₁) [G]₁
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]′ = irrelevanceEq″ (PE.trans (wk-id _) (PE.sym F≡F₁))
(PE.trans (wk-id _) (PE.sym H≡F′))
PE.refl PE.refl
[F]₁ [F]′ [F≡H]₁
[G≡E]₁ = [G≡G′] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G≡E]′ = irrelevanceEqLift″ (PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.trans (wkSingleSubstId _) (PE.sym E≡G′))
(PE.sym F≡F₁) [G]₁ [G]′ [G≡E]₁
in escapeEq [F]′ [F≡H]′ , escapeEq [G]′ [G≡E]′
∃injectivity′ (emb emb< x) [∃FG≡∃HE] = ∃injectivity′ x [∃FG≡∃HE]
∃injectivity′ (emb ∞< x) [∃FG≡∃HE] = ∃injectivity′ x [∃FG≡∃HE]
-- Injectivity of ∃
∃injectivity : ∀ {Γ F G H E l∃} →
Γ ⊢ ∃ F ▹ G ≡ ∃ H ▹ E ^ [ % , ι l∃ ]
→ Γ ⊢ F ≡ H ^ [ % , ι l∃ ]
× Γ ∙ F ^ [ % , ι l∃ ] ⊢ G ≡ E ^ [ % , ι l∃ ]
∃injectivity ⊢∃FG≡∃HE =
let [∃FG] , _ , [∃FG≡∃HE] = reducibleEq ⊢∃FG≡∃HE
in ∃injectivity′ (∃-elim [∃FG])
(irrelevanceEq [∃FG] (∃-intr (∃-elim [∃FG])) [∃FG≡∃HE])
| 47.384615
| 140
| 0.437384
|
03cd4e63c3a51daac1a65f8ed6c305acf8dc2424
| 328
|
agda
|
Agda
|
test/Succeed/Issue26.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue26.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue26.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- There was a bug where f (suc n) didn't reduce for neutral n.
module Issue26 where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
f : Nat -> Nat
f 0 = 0
f (suc n) = f n
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
lem : (n : Nat) -> f (suc n) == f n
lem n = refl
| 16.4
| 63
| 0.536585
|
d13d7c7dc90158a38568a0580d31c881b32f3d28
| 1,988
|
agda
|
Agda
|
LibraBFT/Concrete/Properties/LockedRound.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/Properties/LockedRound.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/Properties/LockedRound.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Hash
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle sha256 sha256-cr
open import LibraBFT.Concrete.System.Parameters
open EpochConfig
open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK
-- This module contains placeholders for the future analog of the
-- corresponding VotesOnce property. Defining the implementation
-- obligation and proving that it is an invariant of an implementation
-- is a substantial undertaking. We are working first on proving the
-- simpler VotesOnce property to settle down the structural aspects
-- before tackling the harder semantic issues.
module LibraBFT.Concrete.Properties.LockedRound where
-- TODO-3: define the implementation obligation
ImplObligation₁ : Set
ImplObligation₁ = Unit
-- Next, we prove that given the necessary obligations,
module Proof
(sps-corr : StepPeerState-AllValidParts)
(Impl-LR1 : ImplObligation₁)
where
-- Any reachable state satisfies the LR rule for any epoch in the system.
module _ {e}(st : SystemState e)(r : ReachableSystemState st)(eid : Fin e) where
-- Bring in 'unwind', 'ext-unforgeability' and friends
open Structural sps-corr
-- Bring in IntSystemState
open import LibraBFT.Concrete.System sps-corr
open PerState st r
open PerEpoch eid
open import LibraBFT.Concrete.Obligations.LockedRound 𝓔 (ConcreteVoteEvidence 𝓔) as LR
postulate -- TODO-3: prove it
lrr : LR.Type IntSystemState
| 40.571429
| 111
| 0.774648
|
5e2c42c81e6630e2435112b024656fde68b4d76c
| 412
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/IsEquivalence.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/IsEquivalence.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/IsEquivalence.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class.Reflexivity
open import Oscar.Class.Symmetry
open import Oscar.Class.Transitivity
module Oscar.Class.IsEquivalence where
record IsEquivalence
{𝔬} {𝔒 : Ø 𝔬}
{ℓ} (_≈_ : 𝔒 → 𝔒 → Ø ℓ)
: Ø 𝔬 ∙̂ ℓ where
constructor ∁
field
⦃ `𝓡eflexivity ⦄ : Reflexivity.class _≈_
⦃ `𝓢ymmetry ⦄ : Symmetry.class _≈_
⦃ `𝓣ransitivity ⦄ : Transitivity.class _≈_
| 22.888889
| 47
| 0.68932
|
52fb06fae80e92039df97af7fdbb93888573d42d
| 34,925
|
agda
|
Agda
|
progress.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | 1
|
2019-12-19T23:42:31.000Z
|
2019-12-19T23:42:31.000Z
|
progress.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
progress.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import List
open import contexts
open import core
open import lemmas-env
open import lemmas-progress
open import decidability
open import results-checks
-- TODO we're forced to prove this weaker version, since the strong version is
-- unprovable. That said, this weak version is still disappointing, so we
-- should come up with some more thoerems to shore up its deficiencies -
-- in particular, we should do something to mitigate the fact that an e
-- may succeed for every even n and fail for every odd n
-- - also, that evaluation may return different results for different n
-- TODO complete, then delete
-- e => r → ∀{n} e [n]=> r
-- something similar for =>∅ ?
-- (Σ[r] (e => r) ∧ e => ∅) → ⊥
-- ∀{k} → Σ[r] (e [k]=> r) ∨ e [k]=> ∅
module progress where
progress : ∀{Δ Σ' Γ E e τ n} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ e :: τ →
-- Either there's some properly-typed result that e will eval to ...
Σ[ r ∈ result ] Σ[ k ∈ constraints ] (
(E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒ r ⊣ k) ∧
Δ , Σ' ⊢ r ·: τ)
-- ... or evaluation will have a constraint failure
∨ E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒∅
xc-progress : ∀{Δ Σ' r1 r2 τ n} →
Δ , Σ' ⊢ r1 ·: τ →
Δ , Σ' ⊢ r2 ·: τ →
Σ[ k ∈ constraints ] Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:= k
∨ Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:=∅
xb-progress : ∀{Δ Σ' r ex τ n} →
Δ , Σ' ⊢ r ·: τ →
Δ , Σ' ⊢ ex :· τ →
Σ[ k ∈ constraints ] (r ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:= k)
∨ r ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:=∅
rule-fails : {n↓ : Nat} {E : env} {r : result} {ex : ex} → Set
rule-fails {n↓} {E} {r} {ex} =
Σ[ c-j ∈ Nat ] Σ[ x-j ∈ Nat ] Σ[ e-j ∈ exp ] (
r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ 1+ n↓ ⟩ ⌋:=∅
∨ Σ[ k1 ∈ constraints ] (
r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ 1+ n↓ ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒∅)
∨ Σ[ k1 ∈ constraints ] Σ[ k2 ∈ constraints ] Σ[ r-j ∈ result ] (
r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ 1+ n↓ ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒ r-j ⊣ k2 ∧ r-j ⇐ ex ⌊ ⛽⟨ n↓ ⟩ ⌋:=∅))
lemma-xb-progress-case : ∀{Δ Σ' E r rules ex τ n n↓} →
(n == 1+ n↓) →
(len : Nat) →
(unchecked : rule ctx) →
len == ∥ unchecked ∥ →
(failed : (rule-fails {n↓} {E} {r} {ex}) ctx) →
(∀{c rule} → (c , rule) ∈ unchecked → (c , rule) ∈ rules) →
(∀{c c-j x-j e-j p-j} →
(c , c-j , x-j , e-j , p-j) ∈ failed →
c == c-j ∧ (c , |C x-j => e-j) ∈ rules) →
(∀{c} → dom rules c → dom unchecked c ∨ dom failed c) →
Δ , Σ' ⊢ [ E ]case r of⦃· rules ·⦄ ·: τ →
Δ , Σ' ⊢ ex :· τ →
ex ≠ ¿¿ →
Σ[ k ∈ constraints ] ([ E ]case r of⦃· rules ·⦄ ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:= k)
∨ [ E ]case r of⦃· rules ·⦄ ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:=∅
progress {n = Z} Γ⊢E ta
= Inl (_ , _ , ELimit , π2 (typ-inhabitance-pres Γ⊢E ta))
progress {n = 1+ n} Γ⊢E ta'@(TAFix ta) = Inl (_ , _ , EFix , TAFix Γ⊢E ta')
progress {n = 1+ n} Γ⊢E (TAVar x∈Γ)
with env-all-Γ Γ⊢E x∈Γ
... | _ , x∈E , ta = Inl (_ , _ , EVar x∈E , ta)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg)
with progress Γ⊢E ta-arg
... | Inr arg-fails = Inr (EFAppArg arg-fails)
... | Inl (rarg , _ , arg-evals , ta-rarg)
with progress Γ⊢E ta-f
... | Inr f-fails = Inr (EFAppFun f-fails)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ([ E' ]fix f ⦇·λ x => ef ·⦈ , _ , f-evals , ta'@(TAFix Γ'⊢E' (TAFix ta-ef)))
with progress {n = n} (EnvInd (EnvInd Γ'⊢E' ta') ta-rarg) ta-ef
... | Inr ef-fails = Inr (EFAppFixEval CF⛽ refl f-evals arg-evals ef-fails)
... | Inl (ref , _ , ef-evals , ta-ref) = Inl (_ , _ , EAppFix CF⛽ refl f-evals arg-evals ef-evals , ta-ref)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ([ E' ]??[ u ] , _ , f-evals , ta-rf)
= Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ((rf-f ∘ rf-arg) , _ , f-evals , ta-rf)
= Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl (fst _ , _ , f-evals , ta-rf)
= Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl (snd _ , _ , f-evals , ta-rf)
= Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ([ E' ]case rf of⦃· rules ·⦄ , _ , f-evals , ta-rf)
= Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)
progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ((C⁻[ _ ] _) , _ , f-evals , ta-rf)
= Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)
progress {n = 1+ n} Γ⊢E TAUnit = Inl (_ , _ , EUnit , TAUnit)
progress {n = 1+ n} Γ⊢E (TAPair _ ta1 ta2)
with progress Γ⊢E ta1
... | Inr fails = Inr (EFPair1 fails)
... | Inl (_ , _ , evals1 , ta-r1)
with progress Γ⊢E ta2
... | Inr fails = Inr (EFPair2 fails)
... | Inl (_ , _ , evals2 , ta-r2) = Inl (_ , _ , EPair evals1 evals2 , TAPair ta-r1 ta-r2)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta)
with progress Γ⊢E ta
... | Inr fails = Inr (EFFst fails)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl (⟨ r1 , r2 ⟩ , _ , evals , TAPair ta-r1 ta-r2)
= Inl (_ , _ , EFst evals , ta-r1)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , _ , evals , TAFix _ ())
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ((C⁻[ x ] q) , _ , evals , ta-r)
= Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ([ x ]??[ x₁ ] , _ , evals , ta-r)
= Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ((q ∘ q₁) , _ , evals , ta-r)
= Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl (fst q , _ , evals , ta-r)
= Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl (snd q , _ , evals , ta-r)
= Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ([ x ]case q of⦃· x₁ ·⦄ , _ , evals , ta-r)
= Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta)
with progress Γ⊢E ta
... | Inr fails = Inr (EFSnd fails)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl (⟨ r1 , r2 ⟩ , _ , evals , TAPair ta-r1 ta-r2)
= Inl (_ , _ , ESnd evals , ta-r2)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , _ , evals , TAFix _ ())
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ((C⁻[ x ] q) , _ , evals , ta-r)
= Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ([ x ]??[ x₁ ] , _ , evals , ta-r)
= Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ((q ∘ q₁) , _ , evals , ta-r)
= Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl (fst q , _ , evals , ta-r)
= Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl (snd q , _ , evals , ta-r)
= Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)
progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ([ x ]case q of⦃· x₁ ·⦄ , _ , evals , ta-r)
= Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)
progress {n = 1+ n} Γ⊢E (TACtor d∈Σ' c∈d ta)
with progress Γ⊢E ta
... | Inr e-fails = Inr (EFCtor e-fails)
... | Inl (_ , _ , e-evals , ta-r) = Inl (_ , _ , ECtor e-evals , TACtor d∈Σ' c∈d ta-r)
progress {Σ' = Σ'} {n = 1+ n} Γ⊢E (TACase d∈σ' e-ta cctx⊆rules h-rules)
with progress Γ⊢E e-ta
... | Inr e-fails = Inr (EFMatchScrut e-fails)
... | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , _ , e-evals , TAFix _ ())
... | Inl ([ x ]??[ x₁ ] , _ , e-evals , ta-re)
= Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →
let _ , _ , _ , c∈cctx , ec-ta = h-rules form in
_ , c∈cctx , ec-ta))
... | Inl ((re ∘ re₁) , _ , e-evals , ta-re)
= Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →
let _ , _ , _ , c∈cctx , ec-ta = h-rules form in
_ , c∈cctx , ec-ta))
... | Inl (fst _ , _ , e-evals , ta-re)
= Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →
let _ , _ , _ , c∈cctx , ec-ta = h-rules form in
_ , c∈cctx , ec-ta))
... | Inl (snd _ , _ , e-evals , ta-re)
= Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →
let _ , _ , _ , c∈cctx , ec-ta = h-rules form in
_ , c∈cctx , ec-ta))
... | Inl ([ x ]case re of⦃· x₁ ·⦄ , _ , e-evals , ta-re)
= Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →
let _ , _ , _ , c∈cctx , ec-ta = h-rules form in
_ , c∈cctx , ec-ta))
... | Inl ((C⁻[ _ ] _) , _ , e-evals , ta-re)
= Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →
let _ , _ , _ , c∈cctx , ec-ta = h-rules form in
_ , c∈cctx , ec-ta))
... | Inl ((C[ c ] re) , _ , e-evals , TACtor d∈'σ' c∈cctx' ta-re)
rewrite ctxunicity d∈'σ' d∈σ'
with π2 (cctx⊆rules (_ , c∈cctx'))
... | form
with h-rules form
... | _ , _ , _ , c∈cctx , ec-ta
rewrite ctxunicity c∈cctx c∈cctx'
with progress {n = n} (EnvInd Γ⊢E ta-re) ec-ta
... | Inr ec-fails = Inr (EFMatchRule CF⛽ form e-evals ec-fails)
... | Inl (_ , _ , ec-evals , ta-rec) = Inl (_ , _ , EMatch CF⛽ form e-evals ec-evals , ta-rec)
progress {n = 1+ n} Γ⊢E (TAHole u∈Δ) = Inl (_ , _ , EHole , TAHole u∈Δ Γ⊢E)
progress {n = 1+ n} Γ⊢E (TAAsrt _ ta1 ta2)
with progress Γ⊢E ta1
... | Inr e1-fails = Inr (EFAsrtL e1-fails)
... | Inl (r1 , _ , e1-evals , ta-r1)
with progress Γ⊢E ta2
... | Inr e2-fails = Inr (EFAsrtR e2-fails)
... | Inl (r2 , _ , e2-evals , ta-r2)
with xc-progress ta-r1 ta-r2
... | Inl (_ , c-succ) = Inl (_ , _ , EAsrt e1-evals e2-evals c-succ , TAUnit)
... | Inr c-fail = Inr (EFAsrt e1-evals e2-evals c-fail)
lemma-xc-no-coerce : ∀{Δ Σ' r1 r2 τ n} →
Δ , Σ' ⊢ r1 ·: τ →
Δ , Σ' ⊢ r2 ·: τ →
r1 ≠ r2 →
(∀{ex} → Coerce r1 := ex → ⊥) →
r1 ≠ ⟨⟩ →
(∀{r'1 r'2} → r1 ≠ ⟨ r'1 , r'2 ⟩) →
(∀{c r} → r1 ≠ (C[ c ] r)) →
Σ[ k ∈ constraints ] Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:= k
∨ Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:=∅
lemma-xc-no-coerce ta1 (TAFix x x₁) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
lemma-xc-no-coerce ta1 (TAApp ta2 ta3) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
lemma-xc-no-coerce ta1 TAUnit r1≠r2 no-coerce not-unit not-pair not-ctor
with xb-progress ta1 TAUnit
... | Inl (_ , xb) = Inl (_ , (XCBackProp1 r1≠r2 (Inl not-pair) (Inl not-ctor) CoerceUnit xb))
... | Inr xb-fails = Inr (XCFXB1 r1≠r2 (Inl not-pair) (Inl not-ctor) CoerceUnit xb-fails)
lemma-xc-no-coerce ta1 ta2@(TAPair _ _) r1≠r2 no-coerce not-unit not-pair not-ctor
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ {c-r2 → nc (_ , c-r2)})
... | Inl (_ , c-r2)
with xb-progress ta1 (Coerce-preservation ta2 c-r2)
... | Inr xb-fails = Inr (XCFXB1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb))
lemma-xc-no-coerce ta1 (TAFst ta2) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
lemma-xc-no-coerce ta1 (TASnd ta2) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
lemma-xc-no-coerce ta1 ta2@(TACtor _ _ _) r1≠r2 no-coerce not-unit not-pair not-ctor
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ {c-r2 → nc (_ , c-r2)})
... | Inl (_ , c-r2)
with xb-progress ta1 (Coerce-preservation ta2 c-r2)
... | Inr xb-fails = Inr (XCFXB1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb))
lemma-xc-no-coerce ta1 (TAUnwrapCtor x x₁ ta2) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
lemma-xc-no-coerce ta1 (TACase x x₁ ta2 x₂ x₃) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
lemma-xc-no-coerce ta1 (TAHole x x₁) r1≠r2 no-coerce not-unit not-pair not-ctor
= Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())
xc-progress {r1 = r1} {r2} ta1 ta2
with result-==-dec r1 r2
... | Inl refl = Inl (_ , XCExRefl)
xc-progress {r1 = _} {_} ta1@(TAFix x x₁) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xc-progress {r1 = _} {_} ta1@(TAApp _ _) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xc-progress {r1 = _} {_} TAUnit ta2 | Inr r1≠r2
with xb-progress ta2 TAUnit
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inl (λ ())) (Inl (λ ())) CoerceUnit xb))
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inl (λ ())) (Inl (λ ())) CoerceUnit xb-fails)
xc-progress (TAPair ta1a ta1b) (TAPair ta2a ta2b) | Inr r1≠r2
with xc-progress ta1a ta2a
... | Inr xca-fails = Inr (XCFPair1 xca-fails)
... | Inl (_ , xca)
with xc-progress ta1b ta2b
... | Inr xcb-fails = Inr (XCFPair2 xcb-fails)
... | Inl (_ , xcb) = Inl (_ , XCPair r1≠r2 xca xcb)
xc-progress ta1@(TAPair _ _) ta2@(TAApp _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TAPair _ _) ta2@(TAFst _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TAPair _ _) ta2@(TASnd _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TAPair _ _) ta2@(TAUnwrapCtor _ _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TAPair _ _) ta2@(TACase _ _ _ _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TAPair _ _) ta2@(TAHole _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TAFst _) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xc-progress {r1 = _} {_} ta1@(TASnd _) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xc-progress (TACtor {c = c1} d∈σ1 c1∈cctx ta1) (TACtor {c = c2} d∈σ2 c2∈cctx ta2) | Inr r1≠r2
with natEQ c1 c2
... | Inr ne = Inr (XCFCtorMM ne)
... | Inl refl
rewrite ctxunicity d∈σ1 d∈σ2 | ctxunicity c1∈cctx c2∈cctx
with xc-progress ta1 ta2
... | Inr xc-fails = Inr (XCFCtor xc-fails)
... | Inl (_ , xc) = Inl (_ , XCCtor (λ where refl → r1≠r2 refl) xc)
xc-progress ta1@(TACtor _ _ _) ta2@(TAApp _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TACtor _ _ _) ta2@(TAFst _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TACtor _ _ _) ta2@(TASnd _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TACtor _ _ _) ta2@(TAUnwrapCtor _ _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TACtor _ _ _) ta2@(TACase _ _ _ _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress ta1@(TACtor _ _ _) ta2@(TAHole _ _) | Inr r1≠r2
with Coerce-dec
... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())
... | Inl (_ , c-r1)
with xb-progress ta2 (Coerce-preservation ta1 c-r1)
... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)
... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))
xc-progress {r1 = _} {_} ta1@(TAUnwrapCtor _ _ _) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xc-progress {r1 = _} {_} ta1@(TACase _ _ _ _ _) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xc-progress {r1 = _} {_} ta1@(TAHole _ _) ta2 | Inr r1≠r2
= lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()
xb-progress {n = Z} _ _ = Inl (_ , XBLimit)
xb-progress {ex = ex} {n = 1+ n} ta-r ta-ex
with ex-¿¿-dec {ex}
... | Inl refl = Inl (_ , XBNone)
xb-progress {n = 1+ n} ta-f@(TAFix Γ⊢E (TAFix ta-e)) (TAMap _ ta-v ta-ex) | Inr ne
with progress {n = n} (EnvInd (EnvInd Γ⊢E ta-f) ta-v) ta-e
... | Inr fails = Inr (XBFFixEval CF⛽ refl fails)
... | Inl (_ , _ , evals , ta)
with xb-progress {n = n} ta ta-ex
... | Inr fails = Inr (XBFFix CF⛽ refl evals fails)
... | Inl (_ , xb) = Inl (_ , XBFix CF⛽ refl evals xb)
xb-progress (TAFix x (TAFix _)) TADC | Inr ne = Inl (_ , XBNone)
xb-progress (TAApp {arg = v} ta-rf ta-rarg) ta-ex | Inr ne
with value-dec {v}
... | Inr nv = Inr (XBFAppNonVal ne nv)
... | Inl val
with xb-progress ta-rf (TAMap val ta-rarg ta-ex)
... | Inr fails = Inr (XBFApp ne val fails)
... | Inl (_ , xb) = Inl (_ , XBApp ne val xb)
xb-progress TAUnit TAUnit | Inr ne = Inl (_ , XBUnit)
xb-progress TAUnit TADC | Inr ne = Inl (_ , XBNone)
xb-progress (TAPair ta-r1 ta-r2) (TAPair ta-ex1 ta-ex2) | Inr ne
with xb-progress ta-r1 ta-ex1
... | Inr fails = Inr (XBFPair1 fails)
... | Inl (_ , xb1)
with xb-progress ta-r2 ta-ex2
... | Inr fails = Inr (XBFPair2 fails)
... | Inl (_ , xb2) = Inl (_ , XBPair xb1 xb2)
xb-progress (TAPair ta-r1 ta-r2) TADC | Inr ne = Inl (_ , XBNone)
xb-progress (TAFst ta-r) ta-ex | Inr ne
with xb-progress ta-r (TAPair ta-ex TADC)
... | Inr fails = Inr (XBFFst ne fails)
... | Inl (_ , xb) = Inl (_ , XBFst ne xb)
xb-progress (TASnd ta-r) ta-ex | Inr ne
with xb-progress ta-r (TAPair TADC ta-ex)
... | Inr fails = Inr (XBFSnd ne fails)
... | Inl (_ , xb) = Inl (_ , XBSnd ne xb)
xb-progress (TACtor {c = c1} h1a h1b ta-r) (TACtor {c = c2} h2a h2b ta-ex) | Inr ne
with natEQ c1 c2
... | Inr ne' = Inr (XBFCtorMM ne')
... | Inl refl
rewrite ctxunicity h1a h2a | ctxunicity h1b h2b
with xb-progress ta-r ta-ex
... | Inr fails = Inr (XBFCtor fails)
... | Inl (_ , xb) = Inl (_ , XBCtor xb)
xb-progress (TACtor x x₁ ta-r) TADC | Inr ne = Inl (_ , XBNone)
xb-progress (TAUnwrapCtor h1 h2 ta-r) ta-ex | Inr ne
with xb-progress ta-r (TACtor h1 h2 ta-ex)
... | Inr fails = Inr (XBFUnwrapCtor ne fails)
... | Inl (_ , xb) = Inl (_ , XBUnwrapCtor ne xb)
xb-progress {n = 1+ n} ta-C@(TACase {rules = rules} x x₁ ta-r x₂ x₃) ta-ex | Inr ne
= lemma-xb-progress-case {n = 1+ n} {n} refl ∥ rules ∥ rules refl ∅ (λ y → y) (λ ()) Inl ta-C ta-ex ne
xb-progress (TAHole x x₁) TAUnit | Inr ne
= Inl (_ , XBHole ne λ ())
xb-progress (TAHole x x₁) (TAPair ta-ex ta-ex₁) | Inr ne
= Inl (_ , XBHole ne λ ())
xb-progress (TAHole x x₁) (TACtor x₂ x₃ ta-ex) | Inr ne
= Inl (_ , XBHole ne λ ())
xb-progress (TAHole x x₁) TADC | Inr ne = Inl (_ , XBNone)
xb-progress (TAHole x x₁) (TAMap x₂ x₃ ta-ex) | Inr ne
= Inr XBFHole
lemma-xb-progress-case {E = E} {r} {rules} {ex} {n = n} {n↓} refl Z [] len-unchecked failed unchecked-wf failed-wf exh ta-C ta-ex n¿¿
= Inr (XBFMatch CF⛽ n¿¿ all-failed)
where
all-failed : ∀{c-j x-j : Nat} {e-j : exp} →
(c-j , |C x-j => e-j) ∈ rules →
r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ n ⟩ ⌋:=∅
∨ Σ[ k1 ∈ constraints ] (
r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ n ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒∅)
∨ Σ[ k1 ∈ constraints ] Σ[ k2 ∈ constraints ] Σ[ r-j ∈ result ] (
r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ n ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒ r-j ⊣ k2 ∧ r-j ⇐ ex ⌊ ⛽⟨ n↓ ⟩ ⌋:=∅)
all-failed c-j∈rules
with exh (_ , c-j∈rules)
... | Inl (_ , ())
... | Inr ((c-j , x-j , e-j , p-j) , c-j∈f)
with failed-wf c-j∈f
... | refl , c-j∈'rules
with ctxunicity c-j∈rules c-j∈'rules
... | refl = p-j
lemma-xb-progress-case {n = 1+ n↓} {n↓} refl (1+ len) unchecked len-unchecked failed unchecked-wf failed-wf exh ta-C@(TACase {rules = rules} d∈σ' Γ⊢E ta-r _ ta-rules) ta-ex n¿¿
with ctx-elim {Γ = unchecked}
... | Inl refl = abort (0≠1+n (! len-unchecked))
... | Inr (c , |C x-j => e-j , unchecked' , refl , c#unchecked')
with unchecked-wf (x,a∈Γ,,x,a {Γ = unchecked'})
... | c∈rules
with ta-rules c∈rules
... | _ , c∈cctx , ta-be
with xb-progress ta-r (TACtor d∈σ' c∈cctx TADC)
... | Inr fails
= lemma-xb-progress-case
refl
len
unchecked'
(1+inj (len-unchecked · ctx-decreasing c#unchecked'))
(failed ,, (c , fail))
unchecked-wf' failed-wf' exh' ta-C ta-ex n¿¿
where
fail = c , x-j , e-j , (Inl fails)
unchecked-wf' : ∀{c' rule'} → (c' , rule') ∈ unchecked' → (c' , rule') ∈ rules
unchecked-wf' {c' = c'} c'∈uc'
with natEQ c c'
... | Inl refl = abort (c#unchecked' (_ , c'∈uc'))
... | Inr cne = unchecked-wf (x∈Γ→x∈Γ+ (flip cne) c'∈uc')
failed-wf' : ∀{c' c-j' x-j' e-j' p-j'} →
(c' , c-j' , x-j' , e-j' , p-j') ∈ (failed ,, (c , fail)) →
c' == c-j' ∧ ((c' , (|C x-j' => e-j')) ∈ rules)
failed-wf' {c' = c'} {c-j'} c'∈f+
with natEQ c c'
... | Inr cne = failed-wf (x∈Γ+→x∈Γ (flip cne) c'∈f+)
... | Inl refl
with ctxunicity c'∈f+ (x,a∈Γ,,x,a {Γ = failed})
... | refl = refl , c∈rules
exh' : ∀{c'} → dom rules c' → dom unchecked' c' ∨ dom (failed ,, (c , fail)) c'
exh' {c' = c'} c'∈rules
with natEQ c c'
... | Inl refl = Inr (_ , x,a∈Γ,,x,a {Γ = failed})
... | Inr cne
with exh c'∈rules
... | Inl (_ , c'∈uc) = Inl (_ , (x∈Γ+→x∈Γ (flip cne) c'∈uc))
... | Inr (_ , c'∈f) = Inr (_ , x∈Γ→x∈Γ+ (flip cne) c'∈f)
... | Inl (_ , xb-r)
with progress {n = n↓} (EnvInd Γ⊢E (TAUnwrapCtor d∈σ' c∈cctx ta-r)) ta-be
... | Inr fails
= lemma-xb-progress-case
refl
len
unchecked'
(1+inj (len-unchecked · ctx-decreasing c#unchecked'))
(failed ,, (c , fail))
unchecked-wf' failed-wf' exh' ta-C ta-ex n¿¿
where
fail = c , x-j , e-j , (Inr (Inl (_ , xb-r , fails)))
unchecked-wf' : ∀{c' rule'} → (c' , rule') ∈ unchecked' → (c' , rule') ∈ rules
unchecked-wf' {c' = c'} c'∈uc'
with natEQ c c'
... | Inl refl = abort (c#unchecked' (_ , c'∈uc'))
... | Inr cne = unchecked-wf (x∈Γ→x∈Γ+ (flip cne) c'∈uc')
failed-wf' : ∀{c' c-j' x-j' e-j' p-j'} →
(c' , c-j' , x-j' , e-j' , p-j') ∈ (failed ,, (c , fail)) →
c' == c-j' ∧ ((c' , (|C x-j' => e-j')) ∈ rules)
failed-wf' {c' = c'} {c-j'} c'∈f+
with natEQ c c'
... | Inr cne = failed-wf (x∈Γ+→x∈Γ (flip cne) c'∈f+)
... | Inl refl
with ctxunicity c'∈f+ (x,a∈Γ,,x,a {Γ = failed})
... | refl = refl , c∈rules
exh' : ∀{c'} → dom rules c' → dom unchecked' c' ∨ dom (failed ,, (c , fail)) c'
exh' {c' = c'} c'∈rules
with natEQ c c'
... | Inl refl = Inr (_ , x,a∈Γ,,x,a {Γ = failed})
... | Inr cne
with exh c'∈rules
... | Inl (_ , c'∈uc) = Inl (_ , (x∈Γ+→x∈Γ (flip cne) c'∈uc))
... | Inr (_ , c'∈f) = Inr (_ , x∈Γ→x∈Γ+ (flip cne) c'∈f)
... | Inl (_ , _ , evals , ta-br)
with xb-progress {n = n↓} ta-br ta-ex
... | Inr fails
= lemma-xb-progress-case
refl
len
unchecked'
(1+inj (len-unchecked · ctx-decreasing c#unchecked'))
(failed ,, (c , fail))
unchecked-wf' failed-wf' exh' ta-C ta-ex n¿¿
where
fail = c , x-j , e-j , (Inr (Inr (_ , _ , _ , xb-r , evals , fails)))
unchecked-wf' : ∀{c' rule'} → (c' , rule') ∈ unchecked' → (c' , rule') ∈ rules
unchecked-wf' {c' = c'} c'∈uc'
with natEQ c c'
... | Inl refl = abort (c#unchecked' (_ , c'∈uc'))
... | Inr cne = unchecked-wf (x∈Γ→x∈Γ+ (flip cne) c'∈uc')
failed-wf' : ∀{c' c-j' x-j' e-j' p-j'} →
(c' , c-j' , x-j' , e-j' , p-j') ∈ (failed ,, (c , fail)) →
c' == c-j' ∧ ((c' , (|C x-j' => e-j')) ∈ rules)
failed-wf' {c' = c'} {c-j'} c'∈f+
with natEQ c c'
... | Inr cne = failed-wf (x∈Γ+→x∈Γ (flip cne) c'∈f+)
... | Inl refl
with ctxunicity c'∈f+ (x,a∈Γ,,x,a {Γ = failed})
... | refl = refl , c∈rules
exh' : ∀{c'} → dom rules c' → dom unchecked' c' ∨ dom (failed ,, (c , fail)) c'
exh' {c' = c'} c'∈rules
with natEQ c c'
... | Inl refl = Inr (_ , x,a∈Γ,,x,a {Γ = failed})
... | Inr cne
with exh c'∈rules
... | Inl (_ , c'∈uc) = Inl (_ , (x∈Γ+→x∈Γ (flip cne) c'∈uc))
... | Inr (_ , c'∈f) = Inr (_ , x∈Γ→x∈Γ+ (flip cne) c'∈f)
... | Inl (_ , xb)
= Inl (_ , (XBMatch CF⛽ n¿¿ c∈rules xb-r evals xb))
{- TODO delete - this strong version is unprovable
module progress where
progress : ∀{Δ Σ' Γ E e τ} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ e :: τ →
-- Either there's some properly-typed result that e will eval to
-- for any beta reduction limit ...
Σ[ r ∈ result ] (
Δ , Σ' ⊢ r ·: τ ∧
∀{n} → Σ[ k ∈ constraints ] (E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒ r ⊣ k))
∨
-- ... or evaluation will have a constraint failure for any
-- beta reduction limit
(∀{n} → E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒∅)
progress Γ⊢E ta'@(TALam _ ta) = Inl (_ , TALam Γ⊢E ta' , (_ , EFun))
progress Γ⊢E ta'@(TAFix _ _ ta) = Inl (_ , TAFix Γ⊢E ta' , (_ , EFix))
progress Γ⊢E (TAVar x∈Γ)
with env-all-Γ Γ⊢E x∈Γ
... | _ , x∈E , ta = Inl (_ , ta , (_ , EVar x∈E))
progress Γ⊢E (TAApp _ ta-f ta-arg)
with progress Γ⊢E ta-arg
... | Inr arg-fails = Inr (EFAppArg arg-fails)
... | Inl (_ , ta-rarg , arg-evals)
with progress Γ⊢E ta-f
... | Inr f-fails = Inr (EFAppFun f-fails)
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl (([ E' ]λ x => ef) , TALam Γ'⊢E' (TALam x#Γ' ta-ef) , f-evals)
with progress (EnvInd Γ'⊢E' ta-rarg) ta-ef
... | q = {!!}
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ([ E' ]fix f ⦇·λ x => ef ·⦈ , ta-rf , f-evals) = {!!}
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ([ x ]??[ x₁ ] , ta-rf , f-evals) = {!!}
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ((rf ∘ rf₁) , ta-rf , f-evals) = {!!}
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ((get[ x th-of x₁ ] rf) , ta-rf , f-evals) = {!!}
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ([ x ]case rf of⦃· x₁ ·⦄ , ta-rf , f-evals) = {!!}
progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl (PF x , ta-rf , f-evals) = {!!}
progress Γ⊢E (TATpl ∥es∥==∥τs∥ _ tas) = {!!}
progress {Δ} {Σ'} {E = E} {τ = τ} Γ⊢E (TAGet {i = i} {len} {e} len==∥τs∥ i<∥τs∥ ta)
with progress Γ⊢E ta
... | Inr e-fails = Inr (EFGet e-fails)
... | Inl (⟨ rs ⟩ , TATpl ∥rs∥==∥τs∥ tas , e-evals)
= let i<∥rs∥ = tr (λ y → i < y) (! ∥rs∥==∥τs∥) i<∥τs∥ in
Inl (_ , tas i<∥rs∥ i<∥τs∥ , _ , EGet (len==∥τs∥ · ! ∥rs∥==∥τs∥) i<∥rs∥ (π2 e-evals))
... | Inl (([ x ]λ x₁ => x₂) , TALam _ () , e-evals)
... | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , TAFix _ () , e-evals)
... | Inl ([ x ]??[ x₁ ] , ta-r , e-evals)
rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())
... | Inl ((r ∘ r₁) , ta-r , e-evals)
rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())
... | Inl ((get[ x th-of x₁ ] r) , ta-r , e-evals)
rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())
... | Inl ([ x ]case r of⦃· x₁ ·⦄ , ta-r , e-evals)
rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())
... | Inl (PF x , TAPF () , e-evals)
progress Γ⊢E (TACtor d∈Σ' c∈d ta)
with progress Γ⊢E ta
... | Inl (_ , ta-r , e-evals) = Inl (_ , TACtor d∈Σ' c∈d ta-r , _ , ECtor (π2 e-evals))
... | Inr e-fails = Inr (EFCtor e-fails)
progress Γ⊢E (TACase x ta x₁ x₂) = {!!}
progress Γ⊢E (TAHole u∈Δ) = Inl (_ , TAHole u∈Δ Γ⊢E , (_ , EHole))
progress Γ⊢E (TAPF ta) = Inl (_ , TAPF ta , (_ , EPF))
progress Γ⊢E (TAAsrt x ta ta₁) = {!!}
-}
| 56.696429
| 178
| 0.478712
|
0425308326011f57c57df965c1c81f52baa4c101
| 12,284
|
agda
|
Agda
|
homotopy/JoinAssocCubical.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/JoinAssocCubical.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/JoinAssocCubical.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
{- A proof that (A * B) * C ≃ (C * B) * A, which combined with commutativity
- proves associativity.
-
- Agda has a hard time compiling this but sometimes it succeeds. -}
module homotopy.JoinAssocCubical where
{- Square and cube lemmas. Some of these are probably generally useful -}
private
app=cst-square : ∀ {i j} {A : Type i} {B : Type j}
{b : B} {f : A → B} (p : ∀ a → f a == b)
{a₁ a₂ : A} (q : a₁ == a₂)
→ Square (p a₁) (ap f q) idp (p a₂)
app=cst-square p idp = hid-square
app=cst-square= : ∀ {i j} {A : Type i} {B : Type j}
{b : B} {f : A → B} {p₁ p₂ : ∀ a → f a == b}
(α : ∀ a → p₁ a == p₂ a) {a₁ a₂ : A} (q : a₁ == a₂)
→ Cube (app=cst-square p₁ q)
(app=cst-square p₂ q)
(horiz-degen-square $ α a₁)
hid-square
hid-square
(horiz-degen-square $ α a₂)
app=cst-square= α idp = y-degen-cube idp
app=cst-square-β : ∀ {i j} {A : Type i} {B : Type j} {b : B} {f : A → B}
(g : (a : A) → f a == b) {x y : A} (p : x == y)
{sq : Square (g x) (ap f p) idp (g y)}
→ apd g p == ↓-app=cst-from-square sq
→ app=cst-square g p == sq
app=cst-square-β g idp α =
! horiz-degen-square-idp ∙ ap horiz-degen-square α ∙ horiz-degen-square-β _
ap-∘-app=cst-square : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
{b : B} {f : A → B} (h : B → C) (g : (a : A) → f a == b)
{x y : A} (p : x == y)
→ Cube (app=cst-square (ap h ∘ g) p)
(ap-square h (app=cst-square g p))
hid-square
(horiz-degen-square $ ap-∘ h f p)
ids
hid-square
ap-∘-app=cst-square h g idp =
cube-shift-right (! ap-square-hid) $
cube-shift-top (! horiz-degen-square-idp) $
x-degen-cube idp
cube-to-↓-rtriangle : ∀ {i j} {A : Type i} {B : Type j}
{b₀ b₁ : A → B} {b : B} {p₀₁ : (a : A) → b₀ a == b₁ a}
{p₀ : (a : A) → b₀ a == b} {p₁ : (a : A) → b₁ a == b}
{x y : A} {q : x == y}
{sqx : Square (p₀₁ x) (p₀ x) (p₁ x) idp}
{sqy : Square (p₀₁ y) (p₀ y) (p₁ y) idp}
→ Cube sqx sqy (natural-square p₀₁ q) (app=cst-square p₀ q)
(app=cst-square p₁ q) ids
→ sqx == sqy [ (λ z → Square (p₀₁ z) (p₀ z) (p₁ z) idp) ↓ q ]
cube-to-↓-rtriangle {q = idp} cu = x-degen-cube-out cu
{- approximately, [massage] describes the action of
- [switch : (A * B) * C → (C * B) * A] on the level of squares -}
private
massage : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square (! p₀₋) (p₋₁ ∙ ! p₁₋) idp (! p₋₀)
massage ids = ids
massage-massage : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₀₁}
(sq : Square p₀₋ p₋₀ idp p₁₋)
→ Cube (massage (massage sq)) sq
(horiz-degen-square (!-! p₀₋)) (horiz-degen-square (!-! p₋₀))
ids (horiz-degen-square (!-! p₁₋))
massage-massage = square-bot-J
(λ sq → Cube (massage (massage sq)) sq
(horiz-degen-square (!-! _)) (horiz-degen-square (!-! _))
ids (horiz-degen-square (!-! _)))
idc
ap-square-massage : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₀₀ a₀₁ a₁₀ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₀₁}
(sq : Square p₀₋ p₋₀ idp p₁₋)
→ Cube (ap-square f (massage sq)) (massage (ap-square f sq))
(horiz-degen-square (ap-! f p₀₋))
(horiz-degen-square (ap-! f p₁₋))
ids
(horiz-degen-square (ap-! f p₋₀))
ap-square-massage f = square-bot-J
(λ sq → Cube (ap-square f (massage sq)) (massage (ap-square f sq))
(horiz-degen-square (ap-! f _))
(horiz-degen-square (ap-! f _))
ids
(horiz-degen-square (ap-! f _)))
idc
massage-cube : ∀ {i} {A : Type i}
{a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube (massage sq₋₋₀) (massage sq₋₋₁)
(!□v sq₀₋₋) (sq₋₁₋ ⊡v !□v sq₁₋₋) vid-square (!□v sq₋₀₋)
massage-cube idc = idc
private
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where
{- Define an involutive map [switch] -}
module SwitchLeft = PushoutRec {d = *-span A B} {D = (C * B) * A}
(λ a → right a)
(λ b → left (right b))
(λ {(a , b) → ! (glue (right b , a))})
switch-coh-fill : (a : A) (b : B) (c : C) → Σ
(Square (! (glue (left c , a))) (ap SwitchLeft.f (glue (a , b)))
idp (! (ap left (glue (c , b)))))
(λ sq → Cube
sq (massage $ app=cst-square (λ j → glue (j , a)) (glue (c , b)))
hid-square (horiz-degen-square (SwitchLeft.glue-β (a , b)))
ids hid-square)
switch-coh-fill a b c = fill-cube-left _ _ _ _ _
module SwitchCoh (c : C) = PushoutElim {d = *-span A B}
{P = λ k → SwitchLeft.f k == left (left c)}
(λ a → ! (glue (left c , a)))
(λ b → ! (ap left (glue (c , b))))
(↓-app=cst-from-square ∘ λ {(a , b) → fst (switch-coh-fill a b c)})
module Switch = PushoutRec {d = *-span (A * B) C} {D = (C * B) * A}
SwitchLeft.f
(λ c → left (left c))
(λ {(k , c) → SwitchCoh.f c k})
switch = Switch.f
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where
{- Proof that [switch] is involutive. There are three squares involved:
- one indexed by A × B, one indexed by A × C, and one by B × C.
- These are related by a cube indexed by A × B × C.
- We get the squares for free by defining the cube, as long as
- we make sure the right faces are dependent on the right types. -}
{- Three big square terms follow; unfortunately Agda can't figure out
- what these have to be on its own. Don't worry about the defns. -}
switch-inv-left-square : (a : A) (b : B)
→ Square idp (ap (switch {A = C} ∘ SwitchLeft.f) (glue (a , b)))
(ap left (glue (a , b))) idp
switch-inv-left-square a b = square-symmetry $
(horiz-degen-square (ap-∘ switch SwitchLeft.f (glue (a , b))))
⊡h ap-square switch (horiz-degen-square (SwitchLeft.glue-β (a , b)))
⊡h horiz-degen-square (ap-! switch (glue (right b , a)))
⊡h !□v (!□h hid-square)
⊡h !□v (horiz-degen-square (Switch.glue-β (right b , a)))
⊡h !□v hid-square
⊡h horiz-degen-square (!-! _)
switch-inv-coh-left : (c : C) (a : A)
→ Square idp (ap (switch {B = B}) (SwitchCoh.f c (left a)))
(glue (left a , c)) idp
switch-inv-coh-left c a = square-symmetry $
hid-square
⊡h ap-square switch hid-square
⊡h horiz-degen-square (ap-! switch (glue (left c , a)))
⊡h !□v (!□h hid-square)
⊡h !□v (horiz-degen-square (Switch.glue-β (left c , a)))
⊡h !□v hid-square
⊡h horiz-degen-square (!-! _)
switch-inv-coh-right : (c : C) (b : B)
→ Square idp (ap (switch {C = A}) (SwitchCoh.f c (right b)))
(glue (right b , c)) idp
switch-inv-coh-right c b = square-symmetry $
hid-square
⊡h ap-square switch hid-square
⊡h horiz-degen-square (ap-! switch (ap left (glue (c , b))))
⊡h !□v (!□h (horiz-degen-square (ap-∘ switch left (glue (c , b)))))
⊡h !□v hid-square
⊡h !□v (horiz-degen-square (SwitchLeft.glue-β (c , b)))
⊡h horiz-degen-square (!-! _)
module SwitchInvLeft = PushoutElim {d = *-span A B}
{P = λ k → switch {A = C} (switch (left k)) == left k}
(λ a → idp)
(λ b → idp)
(↓-='-from-square ∘ uncurry switch-inv-left-square)
{- In very small steps, build up the cube -}
module Coh (a : A) (b : B) (c : C) where
step₁ : Cube
(app=cst-square (ap switch ∘ SwitchCoh.f c) (glue (a , b)))
(ap-square switch (app=cst-square (SwitchCoh.f c) (glue (a , b))))
_ _ _ _
step₁ = ap-∘-app=cst-square switch (SwitchCoh.f c) (glue (a , b))
step₂ : Cube
(ap-square switch (app=cst-square (SwitchCoh.f c) (glue (a , b))))
(ap-square switch $ massage $
app=cst-square (λ j → glue (j , a)) (glue (c , b)))
_ _ _ _
step₂ =
cube-shift-left
(! (ap (ap-square switch)
(app=cst-square-β (SwitchCoh.f c) (glue (a , b))
(SwitchCoh.glue-β c (a , b)))))
(ap-cube switch (snd (switch-coh-fill a b c)))
step₃ : Cube
(ap-square switch $ massage $
app=cst-square (λ j → glue (j , a)) (glue (c , b)))
(massage $ ap-square switch $
app=cst-square (λ j → glue (j , a)) (glue (c , b)))
_ _ _ _
step₃ = ap-square-massage switch
(app=cst-square (λ j → glue (j , a)) (glue (c , b)))
step₄ : Cube
(massage $ ap-square switch $
app=cst-square (λ j → glue (j , a)) (glue (c , b)))
(massage $
app=cst-square (λ j → ap switch (glue (j , a))) (glue (c , b)))
_ _ _ _
step₄ = massage-cube $ cube-!-x $
ap-∘-app=cst-square switch (λ j → glue (j , a)) (glue (c , b))
step₅ : Cube
(massage $
app=cst-square (λ j → ap switch (glue (j , a))) (glue (c , b)))
(massage $ app=cst-square (SwitchCoh.f a) (glue (c , b)))
_ _ _ _
step₅ = massage-cube $
app=cst-square= (λ j → Switch.glue-β (j , a)) (glue (c , b))
step₆ : Cube
(massage $ app=cst-square (SwitchCoh.f a) (glue (c , b)))
(massage $ massage $
app=cst-square (λ k → glue (k , c)) (glue (a , b)))
_ _ _ _
step₆ = massage-cube $
cube-shift-left
(! (app=cst-square-β (SwitchCoh.f a) (glue (c , b))
(SwitchCoh.glue-β a (c , b))))
(snd (switch-coh-fill c b a))
step₇ : Cube
(massage $ massage $
app=cst-square (λ k → glue {d = *-span (A * B) C} (k , c))
(glue (a , b)))
(app=cst-square (λ k → glue (k , c)) (glue (a , b)))
_ _ _ _
step₇ = massage-massage _
switch-inv-cube : Cube
(switch-inv-coh-left c a) (switch-inv-coh-right c b)
(switch-inv-left-square a b)
(app=cst-square (ap switch ∘ SwitchCoh.f c) (glue (a , b)))
(app=cst-square (λ k → glue (k , c)) (glue (a , b)))
ids
switch-inv-cube = cube-rotate-x→z $
step₁ ∙³x step₂ ∙³x step₃ ∙³x step₄ ∙³x step₅ ∙³x step₆ ∙³x step₇
module SwitchInvCoh (c : C) = PushoutElim {d = *-span A B}
{P = λ k → Square (SwitchInvLeft.f k) (ap switch (SwitchCoh.f c k))
(glue (k , c)) idp}
(switch-inv-coh-left c)
(switch-inv-coh-right c)
(cube-to-↓-rtriangle ∘ λ {(a , b) →
cube-shift-back
(! (natural-square-β SwitchInvLeft.f (glue (a , b))
(SwitchInvLeft.glue-β (a , b))))
(Coh.switch-inv-cube a b c)})
abstract
switch-inv : (l : (A * B) * C) → switch (switch l) == l
switch-inv = Pushout-elim
SwitchInvLeft.f
(λ c → idp)
(↓-∘=idf-from-square switch switch ∘ λ {(k , c) →
ap (ap switch) (Switch.glue-β (k , c)) ∙v⊡ SwitchInvCoh.f c k})
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where
join-rearrange-equiv : (A * B) * C ≃ (C * B) * A
join-rearrange-equiv = equiv switch switch switch-inv switch-inv
join-rearrange-path : (A * B) * C == (C * B) * A
join-rearrange-path = ua join-rearrange-equiv
module _ {i j k} (X : Ptd i) (Y : Ptd j) (Z : Ptd k) where
join-rearrange-⊙path : (X ⊙* Y) ⊙* Z == (Z ⊙* Y) ⊙* X
join-rearrange-⊙path =
⊙ua join-rearrange-equiv (! (glue (left (snd Z), snd X)))
| 38.628931
| 79
| 0.503582
|
520acc88c581f4874f9233e6bd2b65d3f09f8eed
| 945
|
agda
|
Agda
|
src/API/Theorems.agda
|
asr/alga
|
01f5f9f53ea81f692215300744aa77e26d8bf332
|
[
"MIT"
] | null | null | null |
src/API/Theorems.agda
|
asr/alga
|
01f5f9f53ea81f692215300744aa77e26d8bf332
|
[
"MIT"
] | null | null | null |
src/API/Theorems.agda
|
asr/alga
|
01f5f9f53ea81f692215300744aa77e26d8bf332
|
[
"MIT"
] | null | null | null |
module API.Theorems where
open import Algebra
open import Algebra.Theorems
open import API
open import Prelude
open import Reasoning
-- vertices [x] == vertex x
vertices-vertex : ∀ {A} {x : A} -> vertices [ x ] ≡ vertex x
vertices-vertex = +identity >> reflexivity
-- edge x y == clique [x, y]
edge-clique : ∀ {A} {x y : A} -> edge x y ≡ clique (x :: [ y ])
edge-clique = symmetry (R *right-identity)
-- vertices xs ⊆ clique xs
vertices-clique : ∀ {A} {xs : List A} -> vertices xs ⊆ clique xs
vertices-clique {_} {[]} = ⊆reflexivity
vertices-clique {a} {_ :: t} = ⊆transitivity (⊆right-monotony (vertices-clique {a} {t})) ⊆connect
-- clique (xs ++ ys) == connect (clique xs) (clique ys)
connect-clique : ∀ {A} {xs ys : List A} -> clique (xs ++ ys) ≡ connect (clique xs) (clique ys)
connect-clique {_} {[]} = symmetry *left-identity
connect-clique {a} {_ :: t} = R (connect-clique {a} {t}) >> *associativity
| 36.346154
| 98
| 0.620106
|
19a91cb4927c49ec13974e9811c9a1fec42c3987
| 2,748
|
agda
|
Agda
|
Categories/Categories.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Categories.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Categories.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Categories where
open import Level
open import Categories.Category
open import Categories.Functor
Categories : ∀ o ℓ e → Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e)
Categories o ℓ e = record
{ Obj = Category o ℓ e
; _⇒_ = Functor
; _≡_ = _≡_
; _∘_ = _∘_
; id = id
; assoc = λ {_} {_} {_} {_} {F} {G} {H} → assoc {F = F} {G} {H}
; identityˡ = λ {_} {_} {F} → identityˡ {F = F}
; identityʳ = λ {_} {_} {F} → identityʳ {F = F}
; equiv = λ {X} {Y} → equiv {C = X} {D = Y}
; ∘-resp-≡ = λ {_} {_} {_} {f} {h} {g} {i} → ∘-resp-≡ {F = f} {h} {g} {i}
}
{-
module Agda where
open import Category.Agda
open import Category.Discrete
D : ∀ o → Functor (Agda o) (Categories o o zero)
D o = record
{ F₀ = Discrete
; F₁ = λ f → record
{ F₀ = λ x → f x
; F₁ = ≣-cong f
; identity = tt
; homomorphism = tt
; F-resp-≡ = λ _ → tt
}
; identity = λ _ → refl tt
; homomorphism = λ _ → refl tt
; F-resp-≡ = F-resp-≡′
}
where
F-resp-≡′ : {A B : Set o} {F G : A → B} → (∀ x → F x ≣ G x) → ∀ {X Y : A} (f : X ≣ Y) → [ Discrete B ] ≣-cong F f ∼ ≣-cong G f
F-resp-≡′ {A} {B} {F} {G} f {x} ≣-refl = helper {F = F} {G} (f x)
where
helper : {F G : A → B} → {p q : B} → p ≣ q → [ Discrete B ] ≣-refl {x = p} ∼ ≣-refl {x = q}
helper ≣-refl = refl tt
Ob : ∀ o → Functor (Categories o o zero) (Agda o)
Ob o = record
{ F₀ = Category.Obj
; F₁ = Functor.F₀
; identity = λ _ → ≣-refl
; homomorphism = λ _ → ≣-refl
; F-resp-≡ = λ {_} {_} {F} {G} → F-resp-≡′ {F = F} {G}
}
where
F-resp-≡′ : {A B : Category o o zero} {F G : Functor A B}
→ ({X Y : Category.Obj A} (f : Category.Hom A X Y) → [ B ] Functor.F₁ F f ∼ Functor.F₁ G f)
→ ((x : Category.Obj A) → Functor.F₀ F x ≣ Functor.F₀ G x)
F-resp-≡′ {A} {B} {F} {G} F∼G x = helper (F∼G (Category.id A {x}))
where
helper : ∀ {X Y} {p : Category.Hom B X X} {q : Category.Hom B Y Y} → [ B ] p ∼ q → X ≣ Y
helper (refl q) = ≣-refl
open import Category.Adjunction
D⊣Ob : ∀ o → Adjunction (D o) (Ob o)
D⊣Ob o = record
{ unit = record
{ η = λ _ x → x
; commute = λ _ _ → ≣-refl
}
; counit = record
{ η = λ X → record
{ F₀ = λ x → x
; F₁ = counit-id′ {X}
; identity = IsEquivalence.refl (Category.equiv X)
; homomorphism = {!!}
; F-resp-≡ = {!!}
}
; commute = {!!}
}
; zig = {!!}
; zag = λ _ → ≣-refl
}
where
counit-id′ : {X : Category o o zero} → {A B : Category.Obj X} → A ≣ B → Category.Hom X A B
counit-id′ {X} ≣-refl = Category.id X
-}
| 30.533333
| 130
| 0.467249
|
30d715821f429608ac859b8acb6d3f5c50f127b0
| 6,397
|
agda
|
Agda
|
src/Automata/Composition/Union.agda
|
armkeh/agda-computability
|
f6a6845a54aed7ecc6841ff5ad89643b553cbd77
|
[
"MIT"
] | null | null | null |
src/Automata/Composition/Union.agda
|
armkeh/agda-computability
|
f6a6845a54aed7ecc6841ff5ad89643b553cbd77
|
[
"MIT"
] | null | null | null |
src/Automata/Composition/Union.agda
|
armkeh/agda-computability
|
f6a6845a54aed7ecc6841ff5ad89643b553cbd77
|
[
"MIT"
] | null | null | null |
module Automata.Composition.Union (Σ : Set) where
-- Standard libraries imports ----------------------------------------
open import Data.Empty using (⊥ ; ⊥-elim)
open import Data.Nat using (ℕ)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
open import Data.Product using (_,_)
open import Data.Vec using (Vec ; [] ; _∷_)
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl)
----------------------------------------------------------------------
-- Thesis imports ----------------------------------------------------
open import Automata.Nondeterministic
----------------------------------------------------------------------
_∪_ : (M : NDA Σ) → (N : NDA Σ) → NDA Σ
⟨ Q₁ , S₁ , F₁ , Δ₁ ⟩ ∪ ⟨ Q₂ , S₂ , F₂ , Δ₂ ⟩ = ⟨ Q , S , F , Δ ⟩
where
Q : Set _
Q = Q₁ ⊎ Q₂
S : Q → Set _
S (inj₁ q) = S₁ q
S (inj₂ q) = S₂ q
F : Q → Set
F (inj₁ q) = F₁ q
F (inj₂ q) = F₂ q
Δ : Q → Σ → Q → Set
Δ (inj₁ q) c (inj₁ q′) = Δ₁ q c q′
Δ (inj₂ q) c (inj₂ q′) = Δ₂ q c q′
{-# CATCHALL #-}
Δ _ _ _ = ⊥ -- No connections between the machines
M-Δ*⇒M∪N-Δ* : {M N : NDA Σ}
→ let Q₁ = NDA.Q M
Δ₁* = NDA.Δ* M
Δ* = NDA.Δ* (M ∪ N) in
(q : Q₁) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₁)
→ Δ₁* q xs q′
→ Δ* (inj₁ q) xs (inj₁ q′)
M-Δ*⇒M∪N-Δ* q [] .q refl = refl
M-Δ*⇒M∪N-Δ* q (x ∷ xs) q′ (q₀ , Δ₁-q-x-q₀ , Δ₁*-q₀-xs-q′) =
inj₁ q₀ , Δ₁-q-x-q₀ , M-Δ*⇒M∪N-Δ* q₀ xs q′ Δ₁*-q₀-xs-q′
N-Δ*⇒M∪N-Δ* : {M N : NDA Σ}
→ let Q₂ = NDA.Q N
Δ₂* = NDA.Δ* N
Δ* = NDA.Δ* (M ∪ N) in
(q : Q₂) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₂)
→ Δ₂* q xs q′
→ Δ* (inj₂ q) xs (inj₂ q′)
N-Δ*⇒M∪N-Δ* q [] .q refl = refl
N-Δ*⇒M∪N-Δ* q (x ∷ xs) q′ (q₀ , Δ₂-q-x-q₀ , Δ₂*-q₀-xs-q′) =
inj₂ q₀ , Δ₂-q-x-q₀ , N-Δ*⇒M∪N-Δ* q₀ xs q′ Δ₂*-q₀-xs-q′
M∪N-Δ*⇒M-Δ* : {M N : NDA Σ}
→ let Q₁ = NDA.Q M
Δ₁* = NDA.Δ* M
Δ* = NDA.Δ* (M ∪ N) in
(q : Q₁) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₁)
→ Δ* (inj₁ q) xs (inj₁ q′)
→ Δ₁* q xs q′
M∪N-Δ*⇒M-Δ* q [] .q refl = refl
M∪N-Δ*⇒M-Δ* q (x ∷ xs) q′ (inj₁ q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) =
q₀ , Δ-q-x-q₀ , M∪N-Δ*⇒M-Δ* q₀ xs q′ Δ*-q₀-xs-q′
M∪N-Δ*⇒N-Δ* : {M N : NDA Σ}
→ let Q₂ = NDA.Q N
Δ₂* = NDA.Δ* N
Δ* = NDA.Δ* (M ∪ N) in
(q : Q₂) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₂)
→ Δ* (inj₂ q) xs (inj₂ q′)
→ Δ₂* q xs q′
M∪N-Δ*⇒N-Δ* q [] .q refl = refl
M∪N-Δ*⇒N-Δ* q (x ∷ xs) q′ (inj₂ q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) =
q₀ , Δ-q-x-q₀ , M∪N-Δ*⇒N-Δ* q₀ xs q′ Δ*-q₀-xs-q′
M∪N-Δ*-disconnectedˡ : {M N : NDA Σ}
→ let Q₁ = NDA.Q M
Q₂ = NDA.Q N
Δ* = NDA.Δ* (M ∪ N) in
(q : Q₁) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₂)
→ ¬ (Δ* (inj₁ q) xs (inj₂ q′))
M∪N-Δ*-disconnectedˡ q (x ∷ xs) q′ (inj₁ q₀ , _ , Δ*-q₀-xs-q′) =
M∪N-Δ*-disconnectedˡ q₀ xs q′ Δ*-q₀-xs-q′
M∪N-Δ*-disconnectedʳ : {M N : NDA Σ}
→ let Q₁ = NDA.Q M
Q₂ = NDA.Q N
Δ* = NDA.Δ* (M ∪ N) in
(q : Q₂) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₁)
→ ¬ (Δ* (inj₂ q) xs (inj₁ q′))
M∪N-Δ*-disconnectedʳ q (x ∷ xs) q′ (inj₂ q₀ , _ , Δ*-q₀-xs-q′) =
M∪N-Δ*-disconnectedʳ q₀ xs q′ Δ*-q₀-xs-q′
M-Accepts⇒M∪N-Accepts : {M N : NDA Σ}
→ {n : ℕ} → (xs : Vec Σ n)
→ NDA.Accepts M xs
→ NDA.Accepts (M ∪ N) xs
M-Accepts⇒M∪N-Accepts [] (q , S-q , .q , F-q , refl) =
inj₁ q , S-q , inj₁ q , F-q , refl
M-Accepts⇒M∪N-Accepts (x ∷ xs)
( q , S-q -- The beginning state
, q′ , F-q′ -- The ending state
, q₀ , Δ₁-q-x-q₀ -- The first step
, Δ₁*-q₀-xs-q′) = -- The remaining steps
-- Translate to the union:
(inj₁ q , S-q -- The beginning state
, inj₁ q′ , F-q′ -- The ending state
, inj₁ q₀ , Δ₁-q-x-q₀ -- The first step
, M-Δ*⇒M∪N-Δ* q₀ xs q′ Δ₁*-q₀-xs-q′) -- The remaining steps (applying I.H.)
N-Accepts⇒M∪N-Accepts : {M N : NDA Σ}
→ {n : ℕ} → (xs : Vec Σ n)
→ NDA.Accepts N xs
→ NDA.Accepts (M ∪ N) xs
N-Accepts⇒M∪N-Accepts [] (q , S-q , .q , F-q , refl) =
inj₂ q , S-q , inj₂ q , F-q , refl
N-Accepts⇒M∪N-Accepts (x ∷ xs)
( q , S-q
, q′ , F-q′
, q₀ , Δ-q-x-q₀
, Δ*-q₀-xs-q′) =
( inj₂ q , S-q
, inj₂ q′ , F-q′
, inj₂ q₀ , Δ-q-x-q₀
, N-Δ*⇒M∪N-Δ* q₀ xs q′ Δ*-q₀-xs-q′ )
----------------------------------------------------------------------
M∪N-Accepts⇒M-Accepts∨N-Accepts : {M N : NDA Σ}
→ {n : ℕ} → (xs : Vec Σ n)
→ NDA.Accepts (M ∪ N) xs
→ NDA.Accepts M xs ⊎ NDA.Accepts N xs
-- Base cases.
M∪N-Accepts⇒M-Accepts∨N-Accepts []
(inj₁ q , S-q , .(inj₁ q) , F-q , refl) =
inj₁ (q , S-q , q , F-q , refl)
M∪N-Accepts⇒M-Accepts∨N-Accepts []
(inj₂ q , S-q , .(inj₂ q) , F-q , refl) =
inj₂ (q , S-q , q , F-q , refl)
-- Induction step 1: both the start and final state are in M.
M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs)
( inj₁ q , S-q
, inj₁ q′ , F-q′
, inj₁ q₀ , Δ-q-x-q₀
, Δ*-q₀-xs-q′) =
inj₁ ( q , S-q
, q′ , F-q′
, q₀ , Δ-q-x-q₀
, M∪N-Δ*⇒M-Δ* q₀ xs q′ Δ*-q₀-xs-q′)
-- Induction step 2: both the start and final state are in N.
M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs)
( inj₂ q , S-q
, inj₂ q′ , F-q′
, inj₂ q₀ , Δ-q-x-q₀
, Δ*-q₀-xs-q′) =
inj₂ ( q , S-q
, q′ , F-q′
, q₀ , Δ-q-x-q₀
, M∪N-Δ*⇒N-Δ* q₀ xs q′ Δ*-q₀-xs-q′)
-- Unreachable cases: the proof of “Accepts (M ∪ N) xs”
-- asserts M and N are connected.
M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs)
(inj₁ q , _ , inj₂ q′ , _ , inj₁ q₀ , _ , Δ*-q₀-xs-q′) =
⊥-elim (M∪N-Δ*-disconnectedˡ q₀ xs q′ Δ*-q₀-xs-q′)
M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs)
(inj₂ q , _ , inj₁ q′ , _ , inj₂ q₀ , _ , Δ*-q₀-xs-q′) =
⊥-elim (M∪N-Δ*-disconnectedʳ q₀ xs q′ Δ*-q₀-xs-q′)
----------------------------------------------------------------------
| 34.578378
| 81
| 0.401751
|
2ef0cc10a98e74390a5fa8f801b220633c38c2ed
| 790
|
agda
|
Agda
|
test/succeed/Issue292.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/Issue292.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue292.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- Fixed on AIM XIV 2011-09-09 AA, UN
-- {-# OPTIONS -v tc.lhs.unify:50 #-}
module Issue292 where
data ⊥ : Set where
infix 3 ¬_
¬_ : Set → Set
¬ P = P → ⊥
infix 4 _≅_
data _≅_ {A : Set} (x : A) : ∀ {B : Set} → B → Set where
refl : x ≅ x
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
data Bool : Set where true false : Bool
data D : Bool -> Set where
tt : D true
ff : D false
P : Set -> Set
P S = Σ S (\s → s ≅ tt)
pbool : P (D true)
pbool = tt , refl
¬pbool2 : ¬ P (D false)
¬pbool2 ( ff , () )
-- Andreas, 2011-09-13 fix of fix: should work again
{- WAS: expected error
ff ≅ tt should be empty, but that's not obvious to me
when checking that the clause ¬pbool2 (ff , ()) has type
¬ P (D false)
-}
| 17.555556
| 56
| 0.582278
|
03313b33e091d7e9d71327b418fcfa7a2425b354
| 449
|
agda
|
Agda
|
Cats/Category/Presheaves.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Category/Presheaves.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Category/Presheaves.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 1
|
2019-03-18T15:35:07.000Z
|
2019-03-18T15:35:07.000Z
|
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Presheaves where
open import Level using (_⊔_ ; suc)
open import Cats.Category
open import Cats.Category.Fun using (Fun)
open import Cats.Category.Op using (_ᵒᵖ)
open import Cats.Category.Setoids using (Setoids)
Presheaves : ∀ {lo la l≈} (C : Category lo la l≈) l l′
→ Category (lo ⊔ la ⊔ l≈ ⊔ suc (l ⊔ l′)) (lo ⊔ la ⊔ l ⊔ l′) (lo ⊔ l ⊔ l′)
Presheaves C l l′ = Fun (C ᵒᵖ) (Setoids l l′)
| 29.933333
| 75
| 0.650334
|
5e5b881e35232863c05deade2b1283c23ea8acb5
| 197
|
agda
|
Agda
|
Data/Bool/Truth.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Data/Bool/Truth.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Data/Bool/Truth.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --without-K --safe #-}
module Data.Bool.Truth where
open import Data.Empty
open import Data.Unit
open import Level
open import Data.Bool.Base
T : Bool → Type
T true = ⊤
T false = ⊥
| 15.153846
| 34
| 0.695431
|
342e26ece44e074c961cc0fa467b4e010798d648
| 376
|
agda
|
Agda
|
test/fail/Issue619.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/fail/Issue619.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/fail/Issue619.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
import Common.Reflect
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
data Bool : Set where
true false : Bool
data True : Set where
true : True
-- Should print names as "quote Bool.true" (making sure to disambiguate)
-- and "quote false" rather than "Issue619.Bool.true/false" in error message.
not-true : quote Bool.true ≡ quote Bool.false
not-true = refl
| 22.117647
| 77
| 0.683511
|
5ee4851cfcf99d209bb4f1cf4ecfff0ab56ba03d
| 1,554
|
agda
|
Agda
|
agda/Text/Greek/SBLGNT.agda
|
scott-fleischman/GreekGrammar
|
915c46c27c7f8aad5907474d8484f2685a4cd6a7
|
[
"MIT"
] | 44
|
2015-05-29T14:48:51.000Z
|
2022-03-06T15:41:57.000Z
|
agda/Text/Greek/SBLGNT.agda
|
scott-fleischman/GreekGrammar
|
915c46c27c7f8aad5907474d8484f2685a4cd6a7
|
[
"MIT"
] | 13
|
2015-05-28T20:04:08.000Z
|
2020-09-07T11:58:38.000Z
|
agda/Text/Greek/SBLGNT.agda
|
scott-fleischman/GreekGrammar
|
915c46c27c7f8aad5907474d8484f2685a4cd6a7
|
[
"MIT"
] | 5
|
2015-02-27T22:34:13.000Z
|
2017-06-11T11:25:09.000Z
|
module Text.Greek.SBLGNT where
open import Data.List
open import Text.Greek.Bible
open import Text.Greek.SBLGNT.Matt
open import Text.Greek.SBLGNT.Mark
open import Text.Greek.SBLGNT.Luke
open import Text.Greek.SBLGNT.John
open import Text.Greek.SBLGNT.Acts
open import Text.Greek.SBLGNT.Rom
open import Text.Greek.SBLGNT.1Cor
open import Text.Greek.SBLGNT.2Cor
open import Text.Greek.SBLGNT.Gal
open import Text.Greek.SBLGNT.Eph
open import Text.Greek.SBLGNT.Phil
open import Text.Greek.SBLGNT.Col
open import Text.Greek.SBLGNT.1Thess
open import Text.Greek.SBLGNT.2Thess
open import Text.Greek.SBLGNT.1Tim
open import Text.Greek.SBLGNT.2Tim
open import Text.Greek.SBLGNT.Titus
open import Text.Greek.SBLGNT.Phlm
open import Text.Greek.SBLGNT.Heb
open import Text.Greek.SBLGNT.Jas
open import Text.Greek.SBLGNT.1Pet
open import Text.Greek.SBLGNT.2Pet
open import Text.Greek.SBLGNT.1John
open import Text.Greek.SBLGNT.2John
open import Text.Greek.SBLGNT.3John
open import Text.Greek.SBLGNT.Jude
open import Text.Greek.SBLGNT.Rev
books : List (List (Word))
books =
ΚΑΤΑ-ΜΑΘΘΑΙΟΝ
∷ ΚΑΤΑ-ΜΑΡΚΟΝ
∷ ΚΑΤΑ-ΛΟΥΚΑΝ
∷ ΚΑΤΑ-ΙΩΑΝΝΗΝ
∷ ΠΡΑΞΕΙΣ-ΑΠΟΣΤΟΛΩΝ
∷ ΠΡΟΣ-ΡΩΜΑΙΟΥΣ
∷ ΠΡΟΣ-ΚΟΡΙΝΘΙΟΥΣ-Α
∷ ΠΡΟΣ-ΚΟΡΙΝΘΙΟΥΣ-Β
∷ ΠΡΟΣ-ΓΑΛΑΤΑΣ
∷ ΠΡΟΣ-ΕΦΕΣΙΟΥΣ
∷ ΠΡΟΣ-ΦΙΛΙΠΠΗΣΙΟΥΣ
∷ ΠΡΟΣ-ΚΟΛΟΣΣΑΕΙΣ
∷ ΠΡΟΣ-ΘΕΣΣΑΛΟΝΙΚΕΙΣ-Α
∷ ΠΡΟΣ-ΘΕΣΣΑΛΟΝΙΚΕΙΣ-Β
∷ ΠΡΟΣ-ΤΙΜΟΘΕΟΝ-Α
∷ ΠΡΟΣ-ΤΙΜΟΘΕΟΝ-Β
∷ ΠΡΟΣ-ΤΙΤΟΝ
∷ ΠΡΟΣ-ΦΙΛΗΜΟΝΑ
∷ ΠΡΟΣ-ΕΒΡΑΙΟΥΣ
∷ ΙΑΚΩΒΟΥ
∷ ΠΕΤΡΟΥ-Α
∷ ΠΕΤΡΟΥ-Β
∷ ΙΩΑΝΝΟΥ-Α
∷ ΙΩΑΝΝΟΥ-Β
∷ ΙΩΑΝΝΟΥ-Γ
∷ ΙΟΥΔΑ
∷ ΑΠΟΚΑΛΥΨΙΣ-ΙΩΑΝΝΟΥ
∷ []
| 24.666667
| 36
| 0.765766
|
52c10e931dc94459d132eda1454365a8a47ddb2a
| 4,462
|
agda
|
Agda
|
agda-stdlib/src/Text/Tabular/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Text/Tabular/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Text/Tabular/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Fancy display functions for List-based tables
--
-- The functions in this module assume some (unenforced) invariants.
-- If you cannot guarantee that your data respects these invariants,
-- you should instead use Text.Tabular.List.
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Text.Tabular.Base where
open import Data.Bool.Base using (if_then_else_)
open import Data.Char.Base using (Char)
open import Data.List.Base as List
using (List; []; _∷_; _?∷_; _++_; _∷ʳ?_; null; map; intersperse)
open import Data.Maybe.Base as Maybe using (Maybe; nothing; just; maybe)
open import Data.Nat.Base
open import Data.String.Base as String
using (String; fromChar; unlines; replicate; length)
open import Function.Base
open import Agda.Builtin.Equality
open String
using ( Alignment
; Left
; Center
; Right
) public
record TabularLine : Set where
field
left : Maybe String
cont : Maybe Char
sep : String
right : Maybe String
open TabularLine
record TabularConfig : Set where
field
top : Maybe TabularLine
sep : Maybe TabularLine
row : TabularLine
bot : Maybe TabularLine
open TabularConfig
unicode : TabularConfig
unicode .top = just λ where
.left → just "┌"
.cont → just '─'
.sep → "┬"
.right → just "┐"
unicode .sep = just λ where
.left → just "├"
.cont → just '─'
.sep → "┼"
.right → just "┤"
unicode .row = λ where
.left → just "│"
.cont → nothing
.sep → "│"
.right → just "│"
unicode .bot = just λ where
.left → just "└"
.cont → just '─'
.sep → "┴"
.right → just "┘"
ascii : TabularConfig
ascii .top = just λ where
.left → just "+"
.cont → just '-'
.sep → "-"
.right → just "+"
ascii .sep = just λ where
.left → just "|"
.cont → just '-'
.sep → "+"
.right → just "|"
ascii .row = λ where
.left → just "|"
.cont → nothing
.sep → "|"
.right → just "|"
ascii .bot = just λ where
.left → just "+"
.cont → just '-'
.sep → "-"
.right → just "+"
compact : TabularConfig → TabularConfig
compact c = record c { sep = nothing }
private
dropBorder : TabularLine → TabularLine
dropBorder l = record l { left = nothing; right = nothing }
noBorder : TabularConfig → TabularConfig
noBorder c .top = nothing
noBorder c .sep = Maybe.map dropBorder (c .sep)
noBorder c .row = dropBorder (c .row)
noBorder c .bot = nothing
private
space : TabularLine → TabularLine
space l = let pad = maybe fromChar " " (l .cont) in λ where
.left → Maybe.map (String._++ pad) (l .left)
.cont → l .cont
.sep → pad String.++ l .sep String.++ pad
.right → Maybe.map (pad String.++_) (l .right)
addSpace : TabularConfig → TabularConfig
addSpace c .top = Maybe.map space (c .top)
addSpace c .sep = Maybe.map space (c .sep)
addSpace c .row = space (c .row)
addSpace c .bot = Maybe.map space (c .bot)
whitespace : TabularConfig
whitespace .top = nothing
whitespace .sep = nothing
whitespace .row = λ where
.left → nothing
.cont → nothing
.sep → " "
.right → nothing
whitespace .bot = nothing
-- /!\ Invariants:
-- * the table is presented as a list of rows
-- * header has the same length as each one of the rows
-- i.e. we have a rectangular table
-- * all of the strings in a given column have the same length
unsafeDisplay : TabularConfig → List (List String) → List String
unsafeDisplay _ [] = []
unsafeDisplay c (header ∷ rows) =
map String.concat $ th ++ (trs ∷ʳ? lbot) where
cellsOf : Maybe Char → List String → List String
cellsOf nothing = id
cellsOf (just c) = map (λ cell → replicate (length cell) c)
lineOf : TabularLine → List String → List String
lineOf l xs = l .left
?∷ intersperse (l .sep) (cellsOf (l .cont) xs)
∷ʳ? l .right
mlineOf : Maybe TabularLine → List String → Maybe (List String)
mlineOf l xs = Maybe.map (λ l → lineOf l xs) l
ltop : Maybe (List String)
lsep : Maybe (List String)
tr : List String → List String
lbot : Maybe (List String)
ltop = mlineOf (c. top) header
lsep = mlineOf (c. sep) header
tr = lineOf (c. row)
lbot = mlineOf (c. bot) header
th = ltop ?∷ tr header ∷ []
trs = if null rows then id else (maybe _∷_ id lsep)
$ maybe intersperse id lsep
$ map tr rows
| 26.559524
| 72
| 0.613178
|
1ea187bda3def386d77269c01888dfc30f15f716
| 1,247
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Injectivity/Vec.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Injectivity/Vec.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/Injectivity/Vec.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class.Successor₀
open import Oscar.Class.Injectivity
open import Oscar.Data.¶
open import Oscar.Data.Vec
open import Oscar.Data.Proposequality
import Oscar.Property.Thickandthin.FinFinProposequalityMaybeProposequality
module Oscar.Class.Injectivity.Vec where
instance
𝓘njection₂Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → 𝓘njection₂ (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N))
𝓘njection₂Vec .𝓘njection₂.injection₂ = _,_
[𝓘njectivity₂,₀,₁]Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → [𝓘njectivity₂,₀,₁] (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality
[𝓘njectivity₂,₀,₁]Vec = ∁
𝓘njectivity₂,₀,₁Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → 𝓘njectivity₂,₀,₁ (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality
𝓘njectivity₂,₀,₁Vec .𝓘njectivity₂,₀,₁.injectivity₂,₀,₁ ∅ = ∅
[𝓘njectivity₂,₀,₂]Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → [𝓘njectivity₂,₀,₂] (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality
[𝓘njectivity₂,₀,₂]Vec = ∁
𝓘njectivity₂,₀,₂Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → 𝓘njectivity₂,₀,₂ (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality
𝓘njectivity₂,₀,₂Vec .𝓘njectivity₂,₀,₂.injectivity₂,₀,₂ ∅ = ∅
| 44.535714
| 149
| 0.635926
|
1a5fecbbd8f24dba85be9882a80052a07a2a1735
| 2,174
|
agda
|
Agda
|
src/System/IO/Transducers/UTF8.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | 10
|
2015-01-04T13:45:16.000Z
|
2021-09-15T04:35:41.000Z
|
src/System/IO/Transducers/UTF8.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | null | null | null |
src/System/IO/Transducers/UTF8.agda
|
ilya-fiveisky/agda-system-io
|
d06c219c7b7afc85aae3b1d4d66951b889aa7371
|
[
"MIT"
] | 2
|
2017-08-10T06:12:54.000Z
|
2022-03-12T11:40:23.000Z
|
open import Coinduction using ( ♯_ )
open import Data.Bool using ( Bool ; true ; false ; not )
open import Data.ByteString using ( null )
open import Data.ByteString.UTF8 using ( fromString ) renaming ( span to #span )
open import Data.Natural using ( Natural )
open import Data.Product using ( _×_ ; _,_ )
open import Data.Char using ( Char )
open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ; _⟫_ ; π₁ ; π₂ ; _[&]_ )
open import System.IO.Transducers.Weight using ( weight )
open import System.IO.Transducers.Stateful using ( loop )
open import System.IO.Transducers.Session using ( ⟨_⟩ ; _&_ ; ¿ ; * ; _&*_ ; Bytes ; Bytes' ; Strings )
open import System.IO.Transducers.Strict using ( _⇛_ )
module System.IO.Transducers.UTF8 where
mutual
-- TODO: span isn't doing the right thing when char boundaries fail to line up with bytestring boundaries
span+ : (Char → Bool) → Bytes' ⇛ (Bytes & Bytes)
span+ φ x with #span φ x
span+ φ x | (x₁ , x₂) with null x₁ | null x₂
span+ φ x | (x₁ , x₂) | true | true = inp (♯ span φ)
span+ φ x | (x₁ , x₂) | true | false = out false (out true (out x₂ done))
span+ φ x | (x₁ , x₂) | false | true = out true (out x₁ (inp (♯ span φ)))
span+ φ x | (x₁ , x₂) | false | false = out true (out x₁ (out false (out true (out x₂ done))))
span : (Char → Bool) → Bytes ⇛ (Bytes & Bytes)
span φ false = out false (out false done)
span φ true = inp (♯ span+ φ)
break : (Char → Bool) → Bytes ⇛ (Bytes & Bytes)
break φ = span (λ x → not (φ x))
mutual
nonempty+ : Bytes' & Bytes ⇛ ¿ Bytes & Bytes
nonempty+ x with null x
nonempty+ x | true = inp (♯ nonempty)
nonempty+ x | false = out true (out true (out x done))
nonempty : Bytes & Bytes ⇛ ¿ Bytes & Bytes
nonempty true = inp (♯ nonempty+)
nonempty false = out false done
split? : (Char → Bool) → Bytes ⇒ (¿ Bytes & Bytes)
split? φ = inp (♯ span φ) ⟫ π₂ {Bytes} ⟫ inp (♯ break φ) ⟫ inp (♯ nonempty)
split : (Char → Bool) → Bytes ⇒ * Bytes
split φ = loop {Bytes} (split? φ) ⟫ π₁
-- TODO: decode
encode : Strings ⇛ Bytes
encode true = out true (inp (♯ λ s → out (fromString s) (inp (♯ encode))))
encode false = out false done
| 37.482759
| 107
| 0.634775
|
300b2523404c7481b8725c0b1be6c28a85692bd8
| 2,896
|
agda
|
Agda
|
bindings/stdlib/Light/Implementation/Standard/Relation/Decidable.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | 1
|
2019-12-20T21:33:05.000Z
|
2019-12-20T21:33:05.000Z
|
bindings/stdlib/Light/Implementation/Standard/Relation/Decidable.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
bindings/stdlib/Light/Implementation/Standard/Relation/Decidable.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Implementation.Standard.Relation.Decidable where
open import Light.Variable.Sets
import Light.Implementation.Standard.Data.Empty
import Light.Implementation.Standard.Data.Unit
open import Light.Library.Data.Empty as Empty using (Empty)
open import Light.Library.Data.Unit as Unit using (Unit ; unit)
open import Light.Library.Relation.Decidable using (Library ; Dependencies)
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record
{
Implementation ;
to‐witness = λ ⦃ a ⦄ → Implementation.to‐witness a ;
to‐false‐witness = λ ⦃ a ⦄ → Implementation.to‐false‐witness a ;
from‐witness = λ ⦃ a ⦄ → Implementation.from‐witness a ;
from‐false‐witness = λ ⦃ a ⦄ → Implementation.from‐false‐witness a
}
where
module Implementation where
open import Relation.Nullary using (yes ; no) renaming (Dec to Decidable) public
open Relation.Nullary using (does)
open import Function using (_∘_)
import Data.Bool as Boolean
open import Function using (id)
open import Relation.Nullary.Decidable
renaming (
toWitness to to‐witness ;
fromWitness to from‐witness ;
toWitnessFalse to to‐false‐witness ;
fromWitnessFalse to from‐false‐witness
)
public
open import Light.Implementation.Standard.Relation.Sets using (base) public
ℓf = id
if′_then_else_ : Decidable 𝕒 → 𝕓 → 𝕓 → 𝕓
if′_then_else_ = Boolean.if_then_else_ ∘ does
if_then_else_ :
∀ (a : Decidable 𝕒)
→ (∀ ⦃ witness : 𝕒 ⦄ → 𝕓)
→ (∀ ⦃ witness : 𝕒 → Empty ⦄ → 𝕓)
→ 𝕓
if yes w then a else _ = a ⦃ witness = w ⦄
if no w then _ else a = a ⦃ witness = w ⦄
module Style where
open import Relation.Nullary.Decidable using (True ; False) public
open import Relation.Nullary.Negation using () renaming (¬? to ¬_) public
open import Relation.Nullary.Product using () renaming (_×-dec_ to _∧_) public
open import Relation.Nullary.Sum using () renaming (_⊎-dec_ to _∨_) public
open import Relation.Nullary.Implication using () renaming (_→-dec_ to _⇢_) public
true : Decidable Unit
true = yes unit
false : Decidable Empty
false = no λ ()
style = record { Style }
| 42.588235
| 100
| 0.557666
|
344b77163f73c18e4a32fcbc49822240e82fa685
| 614
|
agda
|
Agda
|
examples/sinatra/Prelude.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
examples/sinatra/Prelude.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/sinatra/Prelude.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module Prelude where
infixr 50 _,_
infixl 40 _◄_
infix 30 _∈_
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
data List (A : Set) : Set where
ε : List A
_◄_ : List A -> A -> List A
data _∈_ {A : Set}(x : A) : List A -> Set where
hd : forall {xs} -> x ∈ xs ◄ x
tl : forall {y xs} -> x ∈ xs -> x ∈ xs ◄ y
data Box {A : Set}(P : A -> Set) : List A -> Set where
⟨⟩ : Box P ε
_◃_ : forall {xs x} -> Box P xs -> P x -> Box P (xs ◄ x)
_!_ : {A : Set}{P : A -> Set}{xs : List A}{x : A} ->
Box P xs -> x ∈ xs -> P x
⟨⟩ ! ()
(_ ◃ v) ! hd = v
(ρ ◃ _) ! tl x = ρ ! x
| 21.172414
| 58
| 0.441368
|
5e069bc891730d505c3e215c2be5256afa192a40
| 911
|
agda
|
Agda
|
notes/FOT/FOTC/Data/Fun.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Data/Fun.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Data/Fun.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- An inductive predicate for representing functions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.Fun where
open import FOTC.Base
------------------------------------------------------------------------------
-- 2012-03-13. I don't see how we can distinguish between data
-- elements and functions in FOTC. The following inductive predicate
-- is true for any element d : D.
data Fun : D → Set where
fun : (f : D) → Fun f
-- But using a λ-abstraction we could make a distinguish:
postulate lam : (D → D) → D -- LTC-PCF λ-abstraction.
data Fun₁ : D → Set where
fun₁ : (f : D → D) → Fun₁ (lam f)
| 35.038462
| 78
| 0.465423
|
229146af0e1f89e9647baa0366c30c4f72729e16
| 8,115
|
agda
|
Agda
|
Cubical/Data/DescendingList/Strict/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/DescendingList/Strict/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/DescendingList/Strict/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.Everything
module Cubical.Data.DescendingList.Strict.Properties
(A : Type₀)
(_>_ : A → A → Type₀)
where
open import Cubical.Data.DescendingList.Strict A _>_
open import Cubical.HITs.ListedFiniteSet as LFSet renaming (_∈_ to _∈ʰ_)
import Cubical.Data.Empty as ⊥
open import Cubical.Relation.Nullary.DecidableEq
open import Cubical.Relation.Nullary using (Dec; Discrete) renaming (¬_ to Type¬_)
unsort : SDL → LFSet A
unsort [] = []
unsort (cons x xs x>xs) = x ∷ unsort xs
module _ where
open import Cubical.Relation.Nullary
data Tri (A B C : Type) : Type where
tri-< : A → ¬ B → ¬ C → Tri A B C
tri-≡ : ¬ A → B → ¬ C → Tri A B C
tri-> : ¬ A → ¬ B → C → Tri A B C
module IsoToLFSet
(A-discrete : Discrete A)
(>-isProp : ∀ {x y} → isProp (x > y))
(tri : ∀ x y → Tri (y > x) (x ≡ y) (x > y))
(>-trans : ∀ {x y z} → x > y → y > z → x > z)
(>-irreflexive : ∀ {x} → Type¬ x > x)
where
Tri' : A → A → Type
Tri' x y = Tri (y > x) (x ≡ y) (x > y)
open import Cubical.Foundations.Logic
open import Cubical.HITs.PropositionalTruncation as PropTrunc
-- Membership is defined via `LFSet`.
-- This computes just as well as a direct inductive definition,
-- and additionally lets us use the extra `comm` and `dup` paths to prove
-- things about membership.
_∈ˡ_ : A → SDL → hProp ℓ-zero
a ∈ˡ l = a ∈ʰ unsort l
Memˡ : SDL → A → hProp ℓ-zero
Memˡ l a = a ∈ˡ l
Memʰ : LFSet A → A → hProp ℓ-zero
Memʰ l a = a ∈ʰ l
>ᴴ-trans : ∀ x y zs → x > y → y >ᴴ zs → x >ᴴ zs
>ᴴ-trans x y [] x>y y>zs = >ᴴ[]
>ᴴ-trans x y (cons z zs _) x>y (>ᴴcons y>z) = >ᴴcons (>-trans x>y y>z)
≡ₚ-sym : ∀ {A : Type} {x y : A} → [ x ≡ₚ y ] → [ y ≡ₚ x ]
≡ₚ-sym p = PropTrunc.rec squash (λ p → ∣ sym p ∣) p
>-all : ∀ x l → x >ᴴ l → ∀ a → [ a ∈ˡ l ] → x > a
>-all x (cons y zs y>zs) (>ᴴcons x>y) a a∈l =
⊔-elim (a ≡ₚ y) (a ∈ˡ zs) (λ _ → (x > a) , >-isProp {x} {a})
(λ a≡ₚy → substₚ (λ q → x > q , >-isProp) (≡ₚ-sym a≡ₚy) x>y)
(λ a∈zs → >-all x zs (>ᴴ-trans x y zs x>y y>zs) a a∈zs)
a∈l
>-absent : ∀ x l → x >ᴴ l → [ ¬ (x ∈ˡ l) ]
>-absent x l x>l x∈l = ⊥.rec (>-irreflexive (>-all x l x>l x x∈l))
>ᴴ-isProp : ∀ x xs → isProp (x >ᴴ xs)
>ᴴ-isProp x _ >ᴴ[] >ᴴ[] = refl
>ᴴ-isProp x _ (>ᴴcons p) (>ᴴcons q) = cong >ᴴcons (>-isProp p q)
SDL-isSet : isSet SDL
SDL-isSet = isSetDL.isSetDL A _>_ >-isProp A-discrete where
open import Cubical.Data.DescendingList.Properties
insert : A → SDL → SDL
>ᴴinsert : {x y : A} {u : SDL} → y >ᴴ u → (y > x) → y >ᴴ insert x u
insert x [] = cons x [] >ᴴ[]
insert x (cons y zs good) with tri x y
insert x (cons y zs good) | tri-< x<y _ _ = cons y (insert x zs) (>ᴴinsert good x<y)
insert x (cons y zs good) | tri-≡ _ x≡y _ = cons y zs good
insert x (cons y zs good) | tri-> _ _ x>y = cons x (cons y zs good) (>ᴴcons x>y)
>ᴴinsert >ᴴ[] y>x = >ᴴcons y>x
>ᴴinsert {x} (>ᴴcons {y} y>ys) y>x with tri x y
>ᴴinsert {x} {y} (>ᴴcons {z} z>zs) y>x | tri-< _ _ e = >ᴴcons z>zs
>ᴴinsert {x} (>ᴴcons {y} y>ys) y>x | tri-≡ _ _ e = >ᴴcons y>ys
>ᴴinsert {x} (>ᴴcons {y} y>ys) y>x | tri-> _ _ _ = >ᴴcons y>x
insert-correct : ∀ x ys → unsort (insert x ys) ≡ (x ∷ unsort ys)
insert-correct x [] = refl
insert-correct x (cons y zs y>zs) with tri x y
... | tri-< _ _ _ =
y ∷ unsort (insert x zs) ≡⟨ (λ i → y ∷ (insert-correct x zs i)) ⟩
y ∷ x ∷ unsort zs ≡⟨ comm _ _ _ ⟩
x ∷ y ∷ unsort zs ∎
... | tri-≡ _ x≡y _ = sym (dup y (unsort zs)) ∙ (λ i → (x≡y (~ i)) ∷ y ∷ unsort zs)
... | tri-> _ _ _ = refl
insert-correct₂ : ∀ x y zs → unsort (insert x (insert y zs)) ≡ (x ∷ y ∷ unsort zs)
insert-correct₂ x y zs =
insert-correct x (insert y zs)
∙ cong (λ q → x ∷ q) (insert-correct y zs)
abstract
-- for some reason, making [exclude] non-abstract makes
-- typechecking noticeably slower
exclude : A → (A → hProp ℓ-zero) → (A → hProp ℓ-zero)
exclude x h a = ¬ a ≡ₚ x ⊓ h a
>-excluded : ∀ x xs → x >ᴴ xs → exclude x (Memʰ (x ∷ unsort xs)) ≡ Memˡ xs
>-excluded x xs x>xs = funExt (λ a → ⇔toPath (to a) (from a)) where
import Cubical.Data.Sigma as D
import Cubical.Data.Sum as D
from : ∀ a → [ a ∈ˡ xs ] → [ ¬ a ≡ₚ x ⊓ (a ≡ₚ x ⊔ a ∈ˡ xs) ]
from a a∈xs = (PropTrunc.rec (snd ⊥) a≢x) D., inr a∈xs where
a≢x : Type¬ (a ≡ x)
a≢x = λ a≡x → (>-absent x xs x>xs (transport (λ i → [ a≡x i ∈ˡ xs ]) a∈xs ))
to : ∀ a → [ ¬ a ≡ₚ x ⊓ (a ≡ₚ x ⊔ a ∈ˡ xs) ] → [ a ∈ˡ xs ]
to a (a≢x D., x) = PropTrunc.rec (snd (a ∈ˡ xs)) (λ {
(D.inl a≡x) → ⊥.rec (a≢x a≡x);
(D.inr x) → x }) x
cons-eq : ∀ x xs x>xs y ys y>ys → x ≡ y → xs ≡ ys → cons x xs x>xs ≡ cons y ys y>ys
cons-eq x xs x>xs y ys y>ys x≡y xs≡ys i = cons (x≡y i) (xs≡ys i)
(>ᴴ-isProp (x≡y i) (xs≡ys i)
(transp (λ j → (x≡y (i ∧ j)) >ᴴ (xs≡ys) (i ∧ j)) (~ i) x>xs)
(transp (λ j → (x≡y (i ∨ ~ j)) >ᴴ (xs≡ys) (i ∨ ~ j)) i y>ys)
i)
Memˡ-inj-cons : ∀ x xs x>xs y ys y>ys → x ≡ y → Memˡ (cons x xs x>xs) ≡ Memˡ (cons y ys y>ys) → Memˡ xs ≡ Memˡ ys
Memˡ-inj-cons x xs x>xs y ys y>ys x≡y e =
Memˡ xs ≡⟨
sym (>-excluded x xs x>xs)
⟩ exclude x (Memʰ (x ∷ unsort xs)) ≡⟨
(λ i → exclude (x≡y i) (e i))
⟩ exclude y (Memʰ (y ∷ unsort ys)) ≡⟨
(>-excluded y ys y>ys)
⟩ Memˡ ys ∎
Memˡ-inj : ∀ l₁ l₂ → Memˡ l₁ ≡ Memˡ l₂ → l₁ ≡ l₂
Memˡ-inj [] [] eq = refl
Memˡ-inj [] (cons y ys y>ys) eq = ⊥.rec (transport (λ i → [ eq (~ i) y ]) (inl ∣ refl ∣))
Memˡ-inj (cons y ys y>ys) [] eq = ⊥.rec (transport (λ i → [ eq i y ]) (inl ∣ refl ∣))
Memˡ-inj (cons x xs x>xs) (cons y ys y>ys) e =
⊔-elim (x ≡ₚ y) (x ∈ʰ unsort ys)
(λ _ → ((cons x xs x>xs) ≡ (cons y ys y>ys)) , SDL-isSet _ _)
(PropTrunc.rec (SDL-isSet _ _) with-x≡y)
(⊥.rec ∘ x∉ys)
(transport (λ i → [ e i x ]) (inl ∣ refl ∣)) where
xxs = cons x xs x>xs
x∉ys : [ ¬ x ∈ˡ ys ]
x∉ys x∈ys = ⊥.rec (>-irreflexive y>y) where
y>x : y > x
y>x = (>-all y ys y>ys x x∈ys)
y∈xxs : [ y ∈ˡ (cons x xs x>xs) ]
y∈xxs = (transport (λ i → [ e (~ i) y ]) (inl ∣ refl ∣))
y>y : y > y
y>y = >-all y xxs (>ᴴcons y>x) y y∈xxs
with-x≡y : x ≡ y → (cons x xs x>xs) ≡ (cons y ys y>ys)
with-x≡y x≡y = cons-eq x xs x>xs y ys y>ys x≡y r where
r : xs ≡ ys
r = Memˡ-inj _ _ (Memˡ-inj-cons x xs x>xs y ys y>ys x≡y e)
unsort-inj : ∀ x y → unsort x ≡ unsort y → x ≡ y
unsort-inj x y e = Memˡ-inj x y λ i a → a ∈ʰ (e i)
insert-swap : (x y : A) (zs : SDL) → insert x (insert y zs) ≡ insert y (insert x zs)
insert-swap x y zs =
unsort-inj (insert x (insert y zs)) (insert y (insert x zs))
(unsort (insert x (insert y zs))
≡⟨ (λ i → insert-correct₂ x y zs i) ⟩
x ∷ y ∷ unsort zs
≡⟨ (λ i → comm x y (unsort zs) i) ⟩
y ∷ x ∷ unsort zs
≡⟨ (λ i → insert-correct₂ y x zs (~ i)) ⟩
unsort (insert y (insert x zs)) ∎)
insert-dup : (x : A) (ys : SDL) → insert x (insert x ys) ≡ insert x ys
insert-dup x ys = unsort-inj (insert x (insert x ys)) (insert x ys)
(
unsort (insert x (insert x ys))
≡⟨ (λ i → insert-correct₂ x x ys i) ⟩
x ∷ x ∷ unsort ys
≡⟨ dup x (unsort ys) ⟩
x ∷ unsort ys
≡⟨ (λ i → insert-correct x ys (~ i)) ⟩
unsort (insert x ys) ∎
)
sort : LFSet A → SDL
sort = LFSet.Rec.f [] insert insert-swap insert-dup SDL-isSet
unsort∘sort : ∀ x → unsort (sort x) ≡ x
unsort∘sort =
LFSet.PropElim.f (λ x → unsort (sort x) ≡ x)
refl
(λ x {ys} ys-hyp → insert-correct x (sort ys) ∙ cong (λ q → x ∷ q) ys-hyp)
(λ xs → trunc (unsort (sort xs)) xs)
sort∘unsort : ∀ x → sort (unsort x) ≡ x
sort∘unsort x = unsort-inj (sort (unsort x)) x (unsort∘sort (unsort x))
SDL-LFSet-iso : Iso SDL (LFSet A)
SDL-LFSet-iso = (iso unsort sort unsort∘sort sort∘unsort)
SDL≡LFSet : SDL ≡ LFSet A
SDL≡LFSet = ua (isoToEquiv SDL-LFSet-iso)
| 36.390135
| 115
| 0.524707
|
43d93abc59bc66541e29e5e099089e0fe565b159
| 1,005
|
agda
|
Agda
|
Light/Library/Action.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | 1
|
2019-12-20T21:33:05.000Z
|
2019-12-20T21:33:05.000Z
|
Light/Library/Action.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
Light/Library/Action.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Action where
open import Light.Level using (Level ; Setω)
open import Light.Library.Data.Unit as Unit using (Unit)
open import Light.Library.Data.Natural as Natural using (ℕ)
open import Light.Variable.Sets
open import Light.Variable.Levels
open import Light.Package using (Package)
record Dependencies : Setω where
field ⦃ unit‐package ⦄ : Package record { Unit }
field ⦃ natural‐package ⦄ : Package record { Natural }
record Library (dependencies : Dependencies) : Setω where
field
main‐ℓ : Level
Action : Set aℓ → Set aℓ
pure : 𝕒 → Action 𝕒
_>>=_ : Action 𝕒 → (𝕒 → Action 𝕓) → Action 𝕓
_>>_ : Action 𝕒 → Action 𝕓 → Action 𝕓
log : 𝕒 → Action Unit
Main : Set main‐ℓ
run : Action Unit → Main
prompt : Action ℕ
alert : 𝕒 → Action Unit
open Library ⦃ ... ⦄ public
| 34.655172
| 79
| 0.623881
|
43460983d822c3bf8c912e334980fc67cad77b60
| 36
|
agda
|
Agda
|
test/interaction/Issue3428.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3428.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3428.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
kk : ∀ {ℓ} → Set ℓ
kk = {!∀ B → B!}
| 12
| 18
| 0.305556
|
8b2bc41cf9f1d0cbedbddd083332139e699a3f7d
| 2,077
|
agda
|
Agda
|
lib/types/Span.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Span.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Span.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pi
open import lib.types.Pointed
module lib.types.Span where
record Span {i j k : ULevel} : Type (lsucc (lmax (lmax i j) k)) where
constructor span
field
A : Type i
B : Type j
C : Type k
f : C → A
g : C → B
private
span=-raw : ∀ {i j k} {A A' : Type i} (p : A == A')
{B B' : Type j} (q : B == B') {C C' : Type k} (r : C == C')
{f : C → A} {f' : C' → A'}
(s : f == f' [ (λ CA → fst CA → snd CA) ↓ pair×= r p ])
{g : C → B} {g' : C' → B'}
(t : g == g' [ (λ CB → fst CB → snd CB) ↓ pair×= r q ])
→ (span A B C f g) == (span A' B' C' f' g')
span=-raw idp idp idp idp idp = idp
abstract
span= : ∀ {i j k} {A A' : Type i} (p : A ≃ A')
{B B' : Type j} (q : B ≃ B') {C C' : Type k} (r : C ≃ C')
{f : C → A} {f' : C' → A'} (s : (a : C) → (–> p) (f a) == f' (–> r a))
{g : C → B} {g' : C' → B'} (t : (b : C) → (–> q) (g b) == g' (–> r b))
→ (span A B C f g) == (span A' B' C' f' g')
span= p q r {f} {f'} s {g} {g'} t = span=-raw
(ua p)
(ua q)
(ua r)
(↓-→-in (λ α → ↓-snd×-in (ua r) (ua p) (↓-idf-ua-in p (
s _
∙ ap f' (↓-idf-ua-out r (↓-fst×-out (ua r) (ua p) α))))))
(↓-→-in (λ β → ↓-snd×-in (ua r) (ua q) (↓-idf-ua-in q (
t _
∙ ap g' (↓-idf-ua-out r (↓-fst×-out (ua r) (ua q) β))))))
record ⊙Span {i j k : ULevel} : Type (lsucc (lmax (lmax i j) k)) where
constructor ⊙span
field
X : Ptd i
Y : Ptd j
Z : Ptd k
f : fst (Z ⊙→ X)
g : fst (Z ⊙→ Y)
⊙span-out : ∀ {i j k} → ⊙Span {i} {j} {k} → Span {i} {j} {k}
⊙span-out (⊙span X Y Z f g) = span (fst X) (fst Y) (fst Z) (fst f) (fst g)
{- Helper for path induction on pointed spans -}
⊙span-J : ∀ {i j k l} (P : ⊙Span {i} {j} {k} → Type l)
→ ({A : Type i} {B : Type j} {Z : Ptd k} (f : fst Z → A) (g : fst Z → B)
→ P (⊙span (A , f (snd Z)) (B , g (snd Z)) Z (f , idp) (g , idp)))
→ Π ⊙Span P
⊙span-J P t (⊙span (A , ._) (B , ._) Z (f , idp) (g , idp)) = t f g
| 32.968254
| 76
| 0.413577
|
52bfdc76e510bce52b4b9de76a2ace6664fe90f7
| 2,130
|
agda
|
Agda
|
nicolai/anonymousExistence/Sec6hasConstToDecEq.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
nicolai/anonymousExistence/Sec6hasConstToDecEq.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
nicolai/anonymousExistence/Sec6hasConstToDecEq.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import library.Basics hiding (Type ; Σ)
open import library.types.Sigma
open import library.types.Bool
open import Sec2preliminaries
open import Sec4hasConstToSplit
module Sec6hasConstToDecEq where
-- Lemma 6.1
hasConst-family-dec : {X : Type} → (x₁ x₂ : X) → ((x : X) → hasConst ((x₁ == x) + (x₂ == x))) → (x₁ == x₂) + ¬(x₁ == x₂)
hasConst-family-dec {X} x₁ x₂ hasConst-fam = solution where
f₋ : (x : X) → (x₁ == x) + (x₂ == x) → (x₁ == x) + (x₂ == x)
f₋ x = fst (hasConst-fam x)
E₋ : X → Type
E₋ x = fix (f₋ x)
E : Type
E = Σ X λ x → (E₋ x)
E-fst-determines-eq : (e₁ e₂ : E) → (fst e₁ == fst e₂) → e₁ == e₂
E-fst-determines-eq e₁ e₂ p = second-comp-triv (λ x → fixed-point (f₋ x) (snd (hasConst-fam x))) _ _ p
r : Bool → E
r true = x₁ , to-fix (f₋ x₁) (snd (hasConst-fam x₁)) (inl idp)
r false = x₂ , to-fix (f₋ x₂) (snd (hasConst-fam x₂)) (inr idp)
about-r : (r true == r false) ↔ (x₁ == x₂)
about-r = (λ p → ap fst p) , (λ p → E-fst-determines-eq _ _ p)
s : E → Bool
s (_ , inl _ , _) = true
s (_ , inr _ , _) = false
s-section-of-r : (e : E) → r(s e) == e
s-section-of-r (x , inl p , q) = E-fst-determines-eq _ _ p
s-section-of-r (x , inr p , q) = E-fst-determines-eq _ _ p
about-s : (e₁ e₂ : E) → (s e₁ == s e₂) ↔ (e₁ == e₂)
about-s e₁ e₂ = one , two where
one : (s e₁ == s e₂) → (e₁ == e₂)
one p =
e₁ =⟨ ! (s-section-of-r e₁) ⟩
r(s(e₁)) =⟨ ap r p ⟩
r(s(e₂)) =⟨ s-section-of-r e₂ ⟩
e₂ ∎
two : (e₁ == e₂) → (s e₁ == s e₂)
two p = ap s p
combine : (s (r true) == s (r false)) ↔ (x₁ == x₂)
combine = (about-s _ _) ◎ about-r
check-bool : (s (r true) == s (r false)) + ¬(s (r true) == s (r false))
check-bool = Bool-has-dec-eq _ _
solution : (x₁ == x₂) + ¬(x₁ == x₂)
solution with check-bool
solution | inl p = inl (fst combine p)
solution | inr np = inr (λ p → np (snd combine p))
-- Theorem 6.2
all-hasConst→dec-eq : ((X : Type) → hasConst X) → (X : Type) → has-dec-eq X
all-hasConst→dec-eq all-hasConst X x₁ x₂ = hasConst-family-dec x₁ x₂ (λ x → all-hasConst _)
| 31.323529
| 120
| 0.537559
|
ad3aa0042f83bc6938c3f8c07befbb203352e977
| 653
|
agda
|
Agda
|
Cats/Category/Setoids/Facts.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Category/Setoids/Facts.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Category/Setoids/Facts.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 1
|
2019-03-18T15:35:07.000Z
|
2019-03-18T15:35:07.000Z
|
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Setoids.Facts where
open import Cats.Category.Setoids.Facts.Exponential public using
(hasExponentials)
open import Cats.Category.Setoids.Facts.Initial public using
(hasInitial)
open import Cats.Category.Setoids.Facts.Limit public using
(complete)
open import Cats.Category.Setoids.Facts.Product public using
(hasProducts ; hasBinaryProducts ; hasFiniteProducts)
open import Cats.Category.Setoids.Facts.Terminal public using
(hasTerminal)
open import Cats.Category
open import Cats.Category.Setoids using (Setoids)
instance
isCCC : ∀ {l} → IsCCC (Setoids l l)
isCCC = record {}
| 27.208333
| 64
| 0.777948
|
a02e8ec3d1f5954329d9c4a60c4ea9a214a38fe7
| 1,482
|
agda
|
Agda
|
stdlib-exts/Monads/ExceptT.agda
|
WhatisRT/meta-cedille
|
62fa6f36e4555360d94041113749bbb6d291691c
|
[
"MIT"
] | 35
|
2019-06-13T07:44:50.000Z
|
2021-10-12T22:59:10.000Z
|
stdlib-exts/Monads/ExceptT.agda
|
WhatisRT/meta-cedille
|
62fa6f36e4555360d94041113749bbb6d291691c
|
[
"MIT"
] | 10
|
2019-06-13T17:44:43.000Z
|
2020-04-25T15:29:17.000Z
|
stdlib-exts/Monads/ExceptT.agda
|
WhatisRT/meta-cedille
|
62fa6f36e4555360d94041113749bbb6d291691c
|
[
"MIT"
] | 2
|
2019-06-27T23:12:48.000Z
|
2021-10-20T10:46:20.000Z
|
module Monads.ExceptT where
open import Class.Monad
open import Class.Monad.Except
open import Class.Monad.State
open import Class.MonadTrans
open import Data.Sum
open import Function
open import Level
private
variable
a : Level
ExceptT : (M : Set a -> Set a) -> Set a -> Set a -> Set a
ExceptT M E A = M (E ⊎ A)
ExceptT-MonadTrans : {E : Set a} -> MonadTrans (λ (M : Set a -> Set a) -> ExceptT M E)
ExceptT-MonadTrans = record { embed = λ x -> x >>= (return ∘ inj₂) }
module _ {M : Set a -> Set a} {{_ : Monad M}} {E : Set a} where
ExceptT-Monad : Monad (ExceptT M E)
ExceptT-Monad = record { _>>=_ = helper ; return = λ x → (return $ inj₂ x) }
where
helper : ∀ {A B} -> ExceptT M E A -> (A -> ExceptT M E B) -> ExceptT M E B
helper x f = x >>= λ { (inj₁ y) -> return $ inj₁ y ; (inj₂ y) -> f y }
private
throwError' : ∀ {A : Set a} -> E -> ExceptT M E A
throwError' = return ∘ inj₁
catchError' : ∀ {A} -> ExceptT M E A -> (E -> ExceptT M E A) -> ExceptT M E A
catchError' x f = x >>= λ { (inj₁ x) → f x ; (inj₂ y) → return {{ExceptT-Monad}} y }
ExceptT-MonadExcept : MonadExcept (ExceptT M E) {{ExceptT-Monad}} E
ExceptT-MonadExcept = record { throwError = throwError' ; catchError = catchError' }
ExceptT-MonadState : ∀ {S} {{_ : MonadState M S}} -> MonadState (ExceptT M E) {{ExceptT-Monad}} S
ExceptT-MonadState = record
{ get = embed {{ExceptT-MonadTrans}} get
; put = embed {{ExceptT-MonadTrans}} ∘ put }
| 34.465116
| 99
| 0.608637
|
19943cf29a26a04d930dfa91c5e0c79386a7db2c
| 429
|
agda
|
Agda
|
test/Succeed/ConstructorsInstance.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/ConstructorsInstance.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/ConstructorsInstance.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module ConstructorsInstance where
record UnitRC : Set where
instance
constructor tt
data UnitD : Set where
instance
tt : UnitD
postulate
fRC : {{_ : UnitRC}} → Set
fD : {{_ : UnitD}} → Set
tryRC : Set
tryRC = fRC
tryD : Set
tryD = fD
data D : Set where
a : D
instance
b : D
c : D
postulate
g : {{_ : D}} → Set
-- This should work because instance search will choose [b]
try2 : Set
try2 = g
| 12.617647
| 59
| 0.620047
|
a038ce27028642f6c678c6aa0f0a747e8c3ce276
| 2,493
|
agda
|
Agda
|
vendor/stdlib/src/Relation/Unary.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Relation/Unary.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Relation/Unary.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Unary relations
------------------------------------------------------------------------
module Relation.Unary where
open import Data.Empty
open import Data.Function
open import Data.Unit
open import Data.Product
open import Data.Sum
open import Relation.Nullary
------------------------------------------------------------------------
-- Unary relations
Pred : Set → Set₁
Pred a = a → Set
------------------------------------------------------------------------
-- Unary relations can be seen as sets
-- I.e., they can be seen as subsets of the universe of discourse.
private
module Dummy {a : Set} -- The universe of discourse.
where
-- Set membership.
infix 4 _∈_ _∉_
_∈_ : a → Pred a → Set
x ∈ P = P x
_∉_ : a → Pred a → Set
x ∉ P = ¬ x ∈ P
-- The empty set.
∅ : Pred a
∅ = λ _ → ⊥
-- The property of being empty.
Empty : Pred a → Set
Empty P = ∀ x → x ∉ P
∅-Empty : Empty ∅
∅-Empty x ()
-- The universe, i.e. the subset containing all elements in a.
U : Pred a
U = λ _ → ⊤
-- The property of being universal.
Universal : Pred a → Set
Universal P = ∀ x → x ∈ P
U-Universal : Universal U
U-Universal = λ _ → _
-- Set complement.
∁ : Pred a → Pred a
∁ P = λ x → x ∉ P
∁∅-Universal : Universal (∁ ∅)
∁∅-Universal = λ x x∈∅ → x∈∅
∁U-Empty : Empty (∁ U)
∁U-Empty = λ x x∈∁U → x∈∁U _
-- P ⊆ Q means that P is a subset of Q. _⊆′_ is a variant of _⊆_.
infix 4 _⊆_ _⊇_ _⊆′_ _⊇′_
_⊆_ : Pred a → Pred a → Set
P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
_⊆′_ : Pred a → Pred a → Set
P ⊆′ Q = ∀ x → x ∈ P → x ∈ Q
_⊇_ : Pred a → Pred a → Set
Q ⊇ P = P ⊆ Q
_⊇′_ : Pred a → Pred a → Set
Q ⊇′ P = P ⊆′ Q
∅-⊆ : (P : Pred a) → ∅ ⊆ P
∅-⊆ P ()
⊆-U : (P : Pred a) → P ⊆ U
⊆-U P _ = _
-- Set union.
infixl 6 _∪_
_∪_ : Pred a → Pred a → Pred a
P ∪ Q = λ x → x ∈ P ⊎ x ∈ Q
-- Set intersection.
infixl 7 _∩_
_∩_ : Pred a → Pred a → Pred a
P ∩ Q = λ x → x ∈ P × x ∈ Q
open Dummy public
------------------------------------------------------------------------
-- Unary relation combinators
infixr 2 _⟨×⟩_
infixr 1 _⟨⊎⟩_
infixr 0 _⟨→⟩_
_⟨×⟩_ : ∀ {A B} → Pred A → Pred B → Pred (A × B)
(P ⟨×⟩ Q) p = P (proj₁ p) × Q (proj₂ p)
_⟨⊎⟩_ : ∀ {A B} → Pred A → Pred B → Pred (A ⊎ B)
(P ⟨⊎⟩ Q) (inj₁ p) = P p
(P ⟨⊎⟩ Q) (inj₂ q) = Q q
_⟨→⟩_ : ∀ {A B} → Pred A → Pred B → Pred (A → B)
(P ⟨→⟩ Q) f = P ⊆ Q ∘₀ f
| 19.176923
| 72
| 0.440032
|
1a2ff3bd724016bf1ae3061c76c5cd660c0a05a3
| 12,738
|
agda
|
Agda
|
Cubical/ZCohomology/Groups/Torus.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Groups/Torus.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Groups/Torus.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Torus where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Connected
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.Groups.Prelims
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma
open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +-comm to +ℤ-comm ; +-assoc to +ℤ-assoc)
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
open import Cubical.HITs.Pushout
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2) hiding (map)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim2 to pElim2 ; ∣_∣ to ∣_∣₁) hiding (map)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Truncation renaming (elim to trElim ; elim2 to trElim2 ; map to trMap ; rec to trRec)
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Loopspace
open GroupHom
open GroupIso
-- The following section contains stengthened induction principles for cohomology groups of T². They are particularly useful for showing that
-- that some Isos are morphisms. They make things type-check faster, but should probably not be used for computations.
-- We first need some functions
elimFunT² : (n : ℕ) (p q : typ (Ω (coHomK-ptd (suc n))))
→ Square q q p p
→ S¹ × S¹ → coHomK (suc n)
elimFunT² n p q P (base , base) = ∣ ptSn (suc n) ∣
elimFunT² n p q P (base , loop i) = q i
elimFunT² n p q P (loop i , base) = p i
elimFunT² n p q P (loop i , loop j) = P i j
elimFunT²' : (n : ℕ) → Square (refl {ℓ-zero} {coHomK (suc n)} {∣ ptSn (suc n) ∣}) refl refl refl
→ S¹ × S¹ → coHomK (suc n)
elimFunT²' n P (x , base) = ∣ ptSn (suc n) ∣
elimFunT²' n P (base , loop j) = ∣ ptSn (suc n) ∣
elimFunT²' n P (loop i , loop j) = P i j
elimFunT²'≡elimFunT² : (n : ℕ) → (P : _) → elimFunT²' n P ≡ elimFunT² n refl refl P
elimFunT²'≡elimFunT² n P i (base , base) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (base , loop k) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (loop j , base) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (loop j , loop k) = P j k
{-
The first induction principle says that when proving a proposition for some x : Hⁿ(T²), n ≥ 1, it suffices to show that it holds for
(elimFunT² p q P) for any paths p q : ΩKₙ, and square P : Square q q p p. This is useful because elimFunT² p q P (base , base) recudes to 0
-}
coHomPointedElimT² : ∀ {ℓ} (n : ℕ) {B : coHom (suc n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (suc n) (S¹ × S¹)) → isProp (B x))
→ ((p q : _) (P : _) → B ∣ elimFunT² n p q P ∣₂)
→ (x : coHom (suc n) (S¹ × S¹)) → B x
coHomPointedElimT² n {B = B} isprop indp =
coHomPointedElim _ (base , base) isprop
λ f fId → subst B (cong ∣_∣₂ (funExt (λ { (base , base) → sym fId
; (base , loop i) j → helper f fId i1 i (~ j)
; (loop i , base) j → helper f fId i i1 (~ j)
; (loop i , loop j) k → helper f fId i j (~ k)})))
(indp (λ i → helper f fId i i1 i1)
(λ i → helper f fId i1 i i1)
λ i j → helper f fId i j i1)
where
helper : (f : S¹ × S¹ → coHomK (suc n)) → f (base , base) ≡ ∣ ptSn (suc n) ∣
→ I → I → I → coHomK (suc n)
helper f fId i j k =
hfill (λ k → λ {(i = i0) → doubleCompPath-filler (sym fId) (cong f (λ i → (base , loop i))) fId k j
; (i = i1) → doubleCompPath-filler (sym fId) (cong f (λ i → (base , loop i))) fId k j
; (j = i0) → doubleCompPath-filler (sym fId) (cong f (λ i → (loop i , base))) fId k i
; (j = i1) → doubleCompPath-filler (sym fId) (cong f (λ i → (loop i , base))) fId k i})
(inS (f ((loop i) , (loop j))))
k
private
lem : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((P : _) → B ∣ elimFunT² (suc n) refl refl P ∣₂)
→ (p : _) → (refl ≡ p)
→ (q : _) → (refl ≡ q)
→ (P : _)
→ B ∣ elimFunT² (suc n) p q P ∣₂
lem n {B = B} elimP p =
J (λ p _ → (q : _) → (refl ≡ q)
→ (P : _)
→ B ∣ elimFunT² (suc n) p q P ∣₂)
λ q →
J (λ q _ → (P : _) → B ∣ elimFunT² (suc n) refl q P ∣₂)
elimP
{- When working with Hⁿ(T²) , n ≥ 2, we are, in the case described above, allowed to assume that any f : Hⁿ(T²) is
elimFunT² n refl refl P -}
coHomPointedElimT²' : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (2 + n) (S¹ × S¹)) → isProp (B x))
→ ((P : _) → B ∣ elimFunT² (suc n) refl refl P ∣₂)
→ (x : coHom (2 + n) (S¹ × S¹)) → B x
coHomPointedElimT²' n {B = B} prop ind =
coHomPointedElimT² (suc n) prop
λ p q P → trRec (isProp→isOfHLevelSuc n (prop _))
(λ p-refl → trRec (isProp→isOfHLevelSuc n (prop _))
(λ q-refl → lem n {B = B} ind p (sym p-refl) q (sym q-refl) P)
(isConnectedPath _ (isConnectedPathKn (suc n) _ _) q refl .fst))
(isConnectedPath _ (isConnectedPathKn (suc n) _ _) p refl .fst)
{- A slight variation of the above which gives definitional equalities for all points (x , base) -}
private
coHomPointedElimT²'' : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (2 + n) (S¹ × S¹)) → isProp (B x))
→ ((P : _) → B ∣ elimFunT²' (suc n) P ∣₂)
→ (x : coHom (2 + n) (S¹ × S¹)) → B x
coHomPointedElimT²'' n {B = B} prop ind =
coHomPointedElimT²' n prop λ P → subst (λ x → B ∣ x ∣₂)
(elimFunT²'≡elimFunT² (suc n) P) (ind P)
--------- H⁰(T²) ------------
H⁰-T²≅ℤ : GroupIso (coHomGr 0 (S₊ 1 × S₊ 1)) intGroup
H⁰-T²≅ℤ =
H⁰-connected (base , base)
λ (a , b) → pRec propTruncIsProp
(λ id1 → pRec propTruncIsProp
(λ id2 → ∣ ΣPathP (id1 , id2) ∣₁)
(Sn-connected 0 b) )
(Sn-connected 0 a)
--------- H¹(T²) -------------------------------
H¹-T²≅ℤ×ℤ : GroupIso (coHomGr 1 ((S₊ 1) × (S₊ 1))) (dirProd intGroup intGroup)
H¹-T²≅ℤ×ℤ = theIso □ dirProdGroupIso (Hⁿ-Sⁿ≅ℤ 0) (H⁰-Sⁿ≅ℤ 0)
where
typIso : Iso _ _
typIso = setTruncIso (curryIso ⋄ codomainIso S1→K₁≡S1×Int ⋄ toProdIso)
⋄ setTruncOfProdIso
theIso : GroupIso _ _
fun (map theIso) = Iso.fun (typIso)
isHom (map theIso) =
coHomPointedElimT² _ (λ _ → isPropΠ λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ pf qf Pf →
coHomPointedElimT² _ (λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ pg qg Pg i → ∣ funExt (helperFst pf qf pg qg Pg Pf) i ∣₂
, ∣ funExt (helperSnd pf qf pg qg Pg Pf) i ∣₂
where
module _ (pf qf pg qg : 0ₖ 1 ≡ 0ₖ 1) (Pg : Square qg qg pg pg) (Pf : Square qf qf pf pf) where
helperFst : (x : S¹)
→ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .fst
≡ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pf qf Pf (x , y)) .fst
+ₖ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pg qg Pg (x , y)) .fst
helperFst base = refl
helperFst (loop i) j = loopLem j i
where
loopLem : cong (λ x → Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .fst) loop
≡ cong (λ x → Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pf qf Pf (x , y)) .fst
+ₖ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pg qg Pg (x , y)) .fst) loop
loopLem = (λ i j → S¹map-id (pf j +ₖ pg j) i)
∙ (λ i j → S¹map-id (pf j) (~ i) +ₖ S¹map-id (pg j) (~ i))
helperSnd : (x : S¹)
→ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .snd
≡ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pf qf Pf (x , y)) .snd +ℤ Iso.fun S1→K₁≡S1×Int (λ y → elimFunT² 0 pg qg Pg (x , y)) .snd
helperSnd =
toPropElim (λ _ → isSetInt _ _)
((λ i → winding (basechange2⁻ base λ j → S¹map (∙≡+₁ qf qg (~ i) j)))
∙∙ cong (winding ∘ basechange2⁻ base) (congFunct S¹map qf qg)
∙∙ (cong winding (basechange2⁻-morph base (cong S¹map qf) (cong S¹map qg))
∙ winding-hom (basechange2⁻ base (cong S¹map qf)) (basechange2⁻ base (cong S¹map qg))))
inv theIso = Iso.inv typIso
rightInv theIso = Iso.rightInv typIso
leftInv theIso = Iso.leftInv typIso
----------------------- H²(T²) ------------------------------
open import Cubical.Foundations.Equiv
H²-T²≅ℤ : GroupIso (coHomGr 2 (S₊ 1 × S₊ 1)) intGroup
H²-T²≅ℤ = compGroupIso helper2 (Hⁿ-Sⁿ≅ℤ 0)
where
helper : Iso (∥ ((a : S¹) → coHomK 2) ∥₂ × ∥ ((a : S¹) → coHomK 1) ∥₂) (coHom 1 S¹)
Iso.inv helper s = 0ₕ _ , s
Iso.fun helper = snd
Iso.leftInv helper _ =
ΣPathP (isOfHLevelSuc 0 (isOfHLevelRetractFromIso 0 (GroupIso→Iso (Hⁿ-S¹≅0 0)) (isContrUnit)) _ _
, refl)
Iso.rightInv helper _ = refl
theIso : Iso (coHom 2 (S¹ × S¹)) (coHom 1 S¹)
theIso = setTruncIso (curryIso ⋄ codomainIso S1→K2≡K2×K1 ⋄ toProdIso)
⋄ setTruncOfProdIso
⋄ helper
helper2 : GroupIso (coHomGr 2 (S¹ × S¹)) (coHomGr 1 S¹)
helper2 = Iso+Hom→GrIso theIso (
coHomPointedElimT²'' 0 (λ _ → isPropΠ λ _ → setTruncIsSet _ _)
λ P → coHomPointedElimT²'' 0 (λ _ → setTruncIsSet _ _)
λ Q → (λ i → ∣ (λ a → ΩKn+1→Kn 1 (transportRefl refl i
∙∙ cong (λ x → (elimFunT²' 1 P (a , x) +ₖ elimFunT²' 1 Q (a , x)) -ₖ ∣ north ∣) loop
∙∙ transportRefl refl i)) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 P (a , x) +ₖ elimFunT²' 1 Q (a , x)) i) loop) (~ i))) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn 1 (∙≡+₂ 0 (cong (λ x → elimFunT²' 1 P (a , x)) loop) (cong (λ x → elimFunT²' 1 Q (a , x)) loop) (~ i))) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn-hom 1 (cong (λ x → elimFunT²' 1 P (a , x)) loop) (cong (λ x → elimFunT²' 1 Q (a , x)) loop) i) ∣₂)
∙∙ (λ i → ∣ ((λ a → ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 P (a , x)) (~ i)) loop) i)
+ₖ ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 Q (a , x)) (~ i)) loop) i))) ∣₂)
∙ (λ i → ∣ ((λ a → ΩKn+1→Kn 1 (transportRefl refl (~ i)
∙∙ cong (λ x → elimFunT²' 1 P (a , x) +ₖ ∣ north ∣) loop
∙∙ transportRefl refl (~ i))
+ₖ ΩKn+1→Kn 1 (transportRefl refl (~ i)
∙∙ cong (λ x → elimFunT²' 1 Q (a , x) +ₖ ∣ north ∣) loop
∙∙ transportRefl refl (~ i)))) ∣₂))
private
to₂ : coHom 2 (S₊ 1 × S₊ 1) → Int
to₂ = fun (map H²-T²≅ℤ)
from₂ : Int → coHom 2 (S₊ 1 × S₊ 1)
from₂ = inv H²-T²≅ℤ
to₁ : coHom 1 (S₊ 1 × S₊ 1) → Int × Int
to₁ = fun (map H¹-T²≅ℤ×ℤ)
from₁ : Int × Int → coHom 1 (S₊ 1 × S₊ 1)
from₁ = inv H¹-T²≅ℤ×ℤ
to₀ : coHom 0 (S₊ 1 × S₊ 1) → Int
to₀ = fun (map H⁰-T²≅ℤ)
from₀ : Int → coHom 0 (S₊ 1 × S₊ 1)
from₀ = inv H⁰-T²≅ℤ
{-
-- Compute fast:
test : to₁ (from₁ (0 , 1) +ₕ from₁ (1 , 0)) ≡ (1 , 1)
test = refl
test2 : to₁ (from₁ (5 , 1) +ₕ from₁ (-2 , 3)) ≡ (3 , 4)
test2 = refl
-- Compute pretty fast
test3 : to₂ (from₂ 1) ≡ 1
test3 = refl
test4 : to₂ (from₂ 2) ≡ 2
test4 = refl
test5 : to₂ (from₂ 3) ≡ 3
test5 = refl
-- Compute, but slower
test6 : to₂ (from₂ 0 +ₕ from₂ 0) ≡ 0
test6 = refl
test6 : to₂ (from₂ 0 +ₕ from₂ 1) ≡ 1
test6 = refl
-- Does not compute
test7 : to₂ (from₂ 1 +ₕ from₂ 0) ≡ 1
test7 = refl
-}
| 46.32
| 147
| 0.533914
|
19618846125ce393b585847bc61f77257573b920
| 425
|
agda
|
Agda
|
test/Fail/Issue1077.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1077.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1077.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-07-28, issue #1077
-- Agda's reconstruction of the top-level module can be confusing
-- in case the user puts some illegal declarations before the
-- top level module in error.
foo = Set
module Issue1077 where
bar = Set
-- WAS: accepted, creating modules Issue1077 and Issue1077.Issue1077
-- with Issue1077.foo and Issue1077.Issue1077.bar
-- NOW: Error
-- Illegal declarations before top-level module
| 25
| 68
| 0.755294
|
1e842938634c7b6ccbd0a017609fd36e183bf89f
| 1,355
|
agda
|
Agda
|
notes/FOT/FOTC/Data/Stream/TypeSL.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Data/Stream/TypeSL.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Data/Stream/TypeSL.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Definition of FOTC streams using the Agda co-inductive combinators
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.Stream.TypeSL where
open import Codata.Musical.Notation
open import Data.Product renaming ( _×_ to _∧_ )
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------------
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Data/List.agda).
infixr 8 _∷_
data D : Set where
_∷_ : D → D → D
data Stream : D → Set where
consS : ∀ x {xs} → ∞ (Stream xs) → Stream (x ∷ xs)
Stream-out : ∀ {xs} → Stream xs →
∃ λ x' → ∃ λ xs' → Stream xs' ∧ xs ≡ x' ∷ xs'
Stream-out (consS x' {xs'} Sxs') = x' , xs' , ♭ Sxs' , refl
{-# NON_TERMINATING #-}
Stream-coind :
(A : D → Set) →
(∀ {xs} → A xs → ∃ λ x' → ∃ λ xs' → xs ≡ x' ∷ xs' ∧ A xs') →
∀ {xs} → A xs → Stream xs
Stream-coind A h Axs with h Axs
... | x' , xs' , prf₁ , Axs' = subst Stream (sym prf₁) prf₂
where
prf₂ : Stream (x' ∷ xs')
prf₂ = consS x' (♯ Stream-coind A h Axs')
| 32.261905
| 78
| 0.474539
|
1d6430c8e62015c24a861dfa9431415ec03c21cd
| 257
|
agda
|
Agda
|
test/bugs/Lambda.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/bugs/Lambda.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/bugs/Lambda.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- forcePi should be allowed to generate constraints
module Lambda where
data Bool : Set where
true : Bool
false : Bool
T : Bool -> Set
T true = Bool -> Bool
T false = Bool
id : {x : Bool} -> T x -> T x
id y = y
f : Bool -> Bool
f = id (\x -> x)
| 13.526316
| 52
| 0.595331
|
5e9462060e2001bb14bc3e54774675319c92efb4
| 768
|
agda
|
Agda
|
models/Prob.agda
|
dataronio/epigram2
|
17b7858f51a35b3becb8433028c3f1ba25fbba9a
|
[
"MIT"
] | 48
|
2016-01-09T17:36:19.000Z
|
2022-02-11T01:55:28.000Z
|
models/Prob.agda
|
seanwallawalla-forks/Epigram
|
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
|
[
"MIT"
] | null | null | null |
models/Prob.agda
|
seanwallawalla-forks/Epigram
|
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
|
[
"MIT"
] | 12
|
2016-08-14T21:36:35.000Z
|
2022-02-11T01:57:40.000Z
|
{-# OPTIONS --type-in-type #-}
module Prob where
open import DescTT
mutual
data Sch : Set where
ty : (S : Set) -> Sch
exPi : (s : Sch)(T : toType s -> Sch) -> Sch
imPi : (S : Set)(T : S -> Sch) -> Sch
toType : Sch -> Set
toType (ty S) = S
toType (exPi s T) = (x : toType s) -> toType (T x)
toType (imPi S T) = (x : S) -> toType (T x)
Args : Sch -> Set
Args (ty _) = Unit
Args (exPi s T) = Sigma (toType s) \ x -> Args (T x)
Args (imPi S T) = Sigma S \ x -> Args (T x)
postulate
UId : Set
Prp : Set
Prf : Prp -> Set
data Prob : Set where
label : (u : UId)(s : Sch)(a : Args s) -> Prob
patPi : (u : UId)(S : Set)(p : Prob) -> Prob
hypPi : (p : Prp)(T : Prf p -> Prob) -> Prob
recPi : (rec : Prob)(p : Prob) -> Prob
| 22.588235
| 52
| 0.514323
|
520841b7d5d06549b07ff7c2f5b25b4be908a75d
| 1,441
|
agda
|
Agda
|
Numeral/Natural/Oper/FlooredDivision.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Oper/FlooredDivision.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Oper/FlooredDivision.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Oper.FlooredDivision where
import Lvl
open import Data
open import Data.Boolean.Stmt
open import Logic.Propositional.Theorems
open import Numeral.Natural
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Comparisons.Proofs
open import Numeral.Natural.Relation.Order
open import Relator.Equals
infixl 10100 _⌊/⌋_
-- Inductive definition of an algorithm for division.
-- `[ d , b ] a' div b'` should be interpreted as following:
-- `d` is the result of the algorithm that is being incremented as it runs.
-- `b` is the predecessor of the original denominator. This is constant throughout the whole process.
-- `a'` is the numerator. This is decremented as it runs.
-- `b'` is the predecessor of the temporary denominator. This is decremented as it runs.
-- By decrementing both `a'` and `b'`, and incrementing `d` when 'b`' reaches 0, it counts how many times `b` "fits into" `a`.
-- Note: See Numeral.Natural.Oper.Modulo for a similiar algorithm used to determine the modulo.
[_,_]_div_ : ℕ → ℕ → ℕ → ℕ → ℕ
[ d , _ ] 𝟎 div _ = d
[ d , b ] 𝐒(a') div 𝟎 = [ 𝐒(d) , b ] a' div b
[ d , b ] 𝐒(a') div 𝐒(b') = [ d , b ] a' div b'
{-# BUILTIN NATDIVSUCAUX [_,_]_div_ #-}
-- Floored division operation.
_⌊/⌋_ : ℕ → (m : ℕ) → .⦃ _ : IsTrue(positive?(m)) ⦄ → ℕ
a ⌊/⌋ 𝐒(m) = [ 𝟎 , m ] a div m
_⌊/⌋₀_ : ℕ → ℕ → ℕ
_ ⌊/⌋₀ 𝟎 = 𝟎
a ⌊/⌋₀ 𝐒(m) = a ⌊/⌋ 𝐒(m)
{-# INLINE _⌊/⌋₀_ #-}
| 38.945946
| 127
| 0.659264
|
139cb0004d1a393ebf2cf6222fe6510ad1418c37
| 3,365
|
agda
|
Agda
|
Common/UntypedContext.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
Common/UntypedContext.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
Common/UntypedContext.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module Common.UntypedContext where
open import Common.Context public
-- Naturals, as a projection of contexts.
ᴺ⌊_⌋ : ∀ {U} → Cx U → ℕ
ᴺ⌊ ∅ ⌋ = zero
ᴺ⌊ Γ , A ⌋ = suc ᴺ⌊ Γ ⌋
-- Inversion principle for naturals.
invsuc : ∀ {n n′} → ℕ.suc n ≡ suc n′ → n ≡ n′
invsuc refl = refl
-- Finite naturals, or nameless untyped de Bruijn indices, as a projection of context membership.
ⁱ⌊_⌋ : ∀ {U} {A : U} {Γ} → A ∈ Γ → Fin ᴺ⌊ Γ ⌋
ⁱ⌊ top ⌋ = zero
ⁱ⌊ pop i ⌋ = suc ⁱ⌊ i ⌋
-- Preorder on naturals, as a projection of context inclusion.
infix 3 _≤_
data _≤_ : ℕ → ℕ → Set where
done : zero ≤ zero
skip : ∀ {n n′} → n ≤ n′ → n ≤ suc n′
keep : ∀ {n n′} → n ≤ n′ → suc n ≤ suc n′
≤⌊_⌋ : ∀ {U} {Γ Γ′ : Cx U} → Γ ⊆ Γ′ → ᴺ⌊ Γ ⌋ ≤ ᴺ⌊ Γ′ ⌋
≤⌊ done ⌋ = done
≤⌊ skip η ⌋ = skip ≤⌊ η ⌋
≤⌊ keep η ⌋ = keep ≤⌊ η ⌋
refl≤ : ∀ {n} → n ≤ n
refl≤ {zero} = done
refl≤ {suc n} = keep refl≤
trans≤ : ∀ {n n′ n″} → n ≤ n′ → n′ ≤ n″ → n ≤ n″
trans≤ η done = η
trans≤ η (skip η′) = skip (trans≤ η η′)
trans≤ (skip η) (keep η′) = skip (trans≤ η η′)
trans≤ (keep η) (keep η′) = keep (trans≤ η η′)
unskip≤ : ∀ {n n′} → suc n ≤ n′ → n ≤ n′
unskip≤ (skip η) = skip (unskip≤ η)
unskip≤ (keep η) = skip η
unkeep≤ : ∀ {n n′} → suc n ≤ suc n′ → n ≤ n′
unkeep≤ (skip η) = unskip≤ η
unkeep≤ (keep η) = η
weak≤ : ∀ {n} → n ≤ suc n
weak≤ = skip refl≤
bot≤ : ∀ {n} → zero ≤ n
bot≤ {zero} = done
bot≤ {suc n} = skip bot≤
-- Monotonicity of finite naturals with respect to preorder on naturals.
monoFin : ∀ {n n′} → n ≤ n′ → Fin n → Fin n′
monoFin done ()
monoFin (skip η) i = suc (monoFin η i)
monoFin (keep η) zero = zero
monoFin (keep η) (suc i) = suc (monoFin η i)
reflmonoFin : ∀ {n} → (i : Fin n) → i ≡ monoFin refl≤ i
reflmonoFin zero = refl
reflmonoFin (suc i) = cong suc (reflmonoFin i)
transmonoFin : ∀ {n n′ n″} → (η : n ≤ n′) (η′ : n′ ≤ n″) (i : Fin n)
→ monoFin η′ (monoFin η i) ≡ monoFin (trans≤ η η′) i
transmonoFin done η′ ()
transmonoFin η (skip η′) i = cong suc (transmonoFin η η′ i)
transmonoFin (skip η) (keep η′) i = cong suc (transmonoFin η η′ i)
transmonoFin (keep η) (keep η′) zero = refl
transmonoFin (keep η) (keep η′) (suc i) = cong suc (transmonoFin η η′ i)
-- Addition of naturals, as a projection of context concatenation.
_+_ : ℕ → ℕ → ℕ
n + zero = n
n + (suc n′) = suc (n + n′)
id+₁ : ∀ {n} → n + zero ≡ n
id+₁ = refl
id+₂ : ∀ {n} → zero + n ≡ n
id+₂ {zero} = refl
id+₂ {suc n} = cong suc id+₂
weak≤+₁ : ∀ {n} n′ → n ≤ n + n′
weak≤+₁ zero = refl≤
weak≤+₁ (suc n′) = skip (weak≤+₁ n′)
weak≤+₂ : ∀ {n n′} → n′ ≤ n + n′
weak≤+₂ {n} {zero} = bot≤
weak≤+₂ {n} {suc n′} = keep weak≤+₂
-- Subtraction of naturals, as a projection of context thinning.
_-_ : (n : ℕ) → Fin n → ℕ
zero - ()
suc n - zero = n
suc n - suc i = suc (n - i)
thin≤ : ∀ {n} → (i : Fin n) → n - i ≤ n
thin≤ zero = weak≤
thin≤ (suc i) = keep (thin≤ i)
-- Decidable equality of finite naturals.
data _=Fin_ {n} (i : Fin n) : Fin n → Set where
same : i =Fin i
diff : (j : Fin (n - i)) → i =Fin monoFin (thin≤ i) j
_≟Fin_ : ∀ {n} → (i j : Fin n) → i =Fin j
zero ≟Fin zero = same
zero ≟Fin suc j rewrite reflmonoFin j = diff j
suc i ≟Fin zero = diff zero
suc i ≟Fin suc j with i ≟Fin j
suc i ≟Fin suc .i | same = same
suc i ≟Fin suc ._ | diff j = diff (suc j)
| 25.300752
| 97
| 0.534324
|
413ff184849b348eb82f57f9e41d58bf8017ec31
| 4,391
|
agda
|
Agda
|
Numeral/Natural/Coprime/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Coprime/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Coprime/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Coprime.Proofs where
open import Functional
open import Logic
open import Logic.Classical
open import Logic.Propositional
open import Logic.Propositional.Theorems
import Lvl
open import Numeral.Finite
open import Numeral.Natural
open import Numeral.Natural.Coprime
open import Numeral.Natural.Decidable
open import Numeral.Natural.Function.GreatestCommonDivisor
open import Numeral.Natural.Relation.Divisibility.Proofs
open import Numeral.Natural.Oper
open import Numeral.Natural.Prime
open import Numeral.Natural.Prime.Proofs
open import Numeral.Natural.Relation.Divisibility
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Structure.Relator.Properties
open import Type.Properties.Decidable.Proofs
open import Type
private variable n x y d p : ℕ
-- 1 is the only number coprime to itself because it does not have any divisors except for itself.
Coprime-reflexivity-condition : Coprime(n)(n) ↔ (n ≡ 1)
Coprime-reflexivity-condition {n} = [↔]-intro l (r{n}) where
l : Coprime(n)(n) ← (n ≡ 1)
Coprime.proof(l [≡]-intro) {a} a1 _ = [1]-only-divides-[1] (a1)
r : ∀{n} → Coprime(n)(n) → (n ≡ 1)
r {𝟎} (intro z1) = z1 Div𝟎 Div𝟎
r {𝐒(𝟎)} _ = [≡]-intro
r {𝐒(𝐒(n))} (intro ssn1) = ssn1 {𝐒(𝐒(n))} divides-reflexivity divides-reflexivity
instance
Coprime-symmetry : Symmetry(Coprime)
Coprime.proof(Symmetry.proof Coprime-symmetry (intro proof)) {n} nx ny = proof {n} ny nx
-- The only number coprime to 0 is 1 because while all numbers divide 0, only 1 divides 1.
Coprime-of-0-condition : ∀{x} → Coprime(0)(x) → (x ≡ 1)
Coprime-of-0-condition {0} (intro n1) = n1 Div𝟎 Div𝟎
Coprime-of-0-condition {1} (intro n1) = [≡]-intro
Coprime-of-0-condition {𝐒(𝐒(x))} (intro n1) = n1 Div𝟎 divides-reflexivity
-- 1 is coprime to all numbers because only 1 divides 1.
Coprime-of-1 : Coprime(1)(x)
Coprime.proof (Coprime-of-1 {x}) {n} n1 nx = [1]-only-divides-[1] n1
Coprime-of-[+] : Coprime(x)(y) → Coprime(x)(x + y)
Coprime.proof (Coprime-of-[+] {x}{y} (intro proof)) {n} nx nxy = proof {n} nx ([↔]-to-[→] (divides-without-[+] nxy) nx)
-- Coprimality is obviously equivalent to the greatest common divisor being 1 by definition.
Coprime-gcd : Coprime(x)(y) ↔ (gcd(x)(y) ≡ 1)
Coprime-gcd = [↔]-transitivity ([↔]-intro l r) Gcd-gcd-value where
l : Coprime(x)(y) ← Gcd(x)(y) 1
Coprime.proof (l p) nx ny = [1]-only-divides-[1] (Gcd.maximum₂ p nx ny)
r : Coprime(x)(y) → Gcd(x)(y) 1
Gcd.divisor(r (intro coprim)) 𝟎 = [1]-divides
Gcd.divisor(r (intro coprim)) (𝐒 𝟎) = [1]-divides
Gcd.maximum(r (intro coprim)) dv with [≡]-intro ← coprim (dv 𝟎) (dv(𝐒 𝟎)) = [1]-divides
-- A smaller number and a greater prime number is coprime.
-- If the greater number is prime, then no smaller number will divide it except for 1, and greater numbers never divide smaller ones.
-- Examples (y = 7):
-- The prime factors of 7 is only itself (because it is prime).
-- Then the only alternatives for x are:
-- x ∈ {1,2,3,4,5,6}
-- None of them is able to have 7 as a prime factor because it is greater:
-- 1=1, 2=2, 3=3, 4=2⋅2, 5=5, 6=2⋅3
Coprime-of-Prime : (𝐒(x) < y) → Prime(y) → Coprime(𝐒(x))(y)
Coprime.proof (Coprime-of-Prime (succ(succ lt)) prim) nx ny with prime-only-divisors prim ny
Coprime.proof (Coprime-of-Prime (succ(succ lt)) prim) nx ny | [∨]-introₗ n1 = n1
Coprime.proof (Coprime-of-Prime (succ(succ lt)) prim) nx ny | [∨]-introᵣ [≡]-intro with () ← [≤]-to-[≯] lt ([≤]-without-[𝐒] (divides-upper-limit nx))
-- A prime number either divides a number or forms a coprime pair.
-- If a prime number does not divide a number, then it cannot share any divisors because by definition, a prime only has 1 as a divisor.
Prime-to-div-or-coprime : Prime(x) → ((x ∣ y) ∨ Coprime(x)(y))
Prime-to-div-or-coprime {y = y} (intro {x} prim) = [¬→]-disjunctive-formᵣ ⦃ decider-to-classical ⦄ (intro ∘ coprim) where
coprim : (𝐒(𝐒(x)) ∤ y) → ∀{n} → (n ∣ 𝐒(𝐒(x))) → (n ∣ y) → (n ≡ 1)
coprim nxy {𝟎} nx ny with () ← [0]-divides-not nx
coprim nxy {𝐒 n} nx ny with prim nx
... | [∨]-introₗ [≡]-intro = [≡]-intro
... | [∨]-introᵣ [≡]-intro with () ← nxy ny
divides-to-converse-coprime : ∀{x y z} → (x ∣ y) → Coprime(y)(z) → Coprime(x)(z)
divides-to-converse-coprime xy (intro yz) = intro(nx ↦ nz ↦ yz (transitivity(_∣_) nx xy) nz)
| 47.728261
| 149
| 0.673195
|
1ac24f5806f9bf2b1396abc4a4361eee0c9392de
| 1,474
|
agda
|
Agda
|
out/CommGroup/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/CommGroup/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/CommGroup/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order equational theory was created from the following second-order syntax description:
syntax CommGroup | CG
type
* : 0-ary
term
unit : * | ε
add : * * -> * | _⊕_ l20
neg : * -> * | ⊖_ r40
theory
(εU⊕ᴸ) a |> add (unit, a) = a
(εU⊕ᴿ) a |> add (a, unit) = a
(⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))
(⊖N⊕ᴸ) a |> add (neg (a), a) = unit
(⊖N⊕ᴿ) a |> add (a, neg (a)) = unit
(⊕C) a b |> add(a, b) = add(b, a)
-}
module CommGroup.Equality where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Families.Build
open import SOAS.ContextMaps.Inductive
open import CommGroup.Signature
open import CommGroup.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution CG:Syn
open import SOAS.Metatheory.SecondOrder.Equality CG:Syn
private
variable
α β γ τ : *T
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ CG) α Γ → (𝔐 ▷ CG) α Γ → Set where
εU⊕ᴸ : ⁅ * ⁆̣ ▹ ∅ ⊢ ε ⊕ 𝔞 ≋ₐ 𝔞
⊕A : ⁅ * ⁆ ⁅ * ⁆ ⁅ * ⁆̣ ▹ ∅ ⊢ (𝔞 ⊕ 𝔟) ⊕ 𝔠 ≋ₐ 𝔞 ⊕ (𝔟 ⊕ 𝔠)
⊖N⊕ᴸ : ⁅ * ⁆̣ ▹ ∅ ⊢ (⊖ 𝔞) ⊕ 𝔞 ≋ₐ ε
⊕C : ⁅ * ⁆ ⁅ * ⁆̣ ▹ ∅ ⊢ 𝔞 ⊕ 𝔟 ≋ₐ 𝔟 ⊕ 𝔞
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
-- Derived equations
εU⊕ᴿ : ⁅ * ⁆̣ ▹ ∅ ⊢ 𝔞 ⊕ ε ≋ 𝔞
εU⊕ᴿ = tr (ax ⊕C with《 𝔞 ◃ ε 》) (ax εU⊕ᴸ with《 𝔞 》)
⊖N⊕ᴿ : ⁅ * ⁆̣ ▹ ∅ ⊢ 𝔞 ⊕ (⊖ 𝔞) ≋ ε
⊖N⊕ᴿ = tr (ax ⊕C with《 𝔞 ◃ (⊖ 𝔞) 》) (ax ⊖N⊕ᴸ with《 𝔞 》)
| 24.566667
| 99
| 0.527815
|
52aaba0a71d0adeb83d41d54ba610aa7c54a6df2
| 7,670
|
agda
|
Agda
|
Cubical/Categories/NaturalTransformation/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:02.000Z
|
2022-02-05T01:25:02.000Z
|
Cubical/Categories/NaturalTransformation/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Categories/NaturalTransformation/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.NaturalTransformation.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism renaming (iso to iIso)
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Functor.Base
open import Cubical.Categories.Functor.Properties
open import Cubical.Categories.Commutativity
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
private
variable
ℓA ℓA' ℓB ℓB' ℓC ℓC' ℓD ℓD' : Level
module _ {C : Category ℓC ℓC'} {D : Category ℓD ℓD'} where
-- syntax for sequencing in category D
infixl 15 _⋆ᴰ_
private
_⋆ᴰ_ : ∀ {x y z} (f : D [ x , y ]) (g : D [ y , z ]) → D [ x , z ]
f ⋆ᴰ g = f ⋆⟨ D ⟩ g
open Category
open Functor
-- type aliases because it gets tedious typing it out all the time
N-ob-Type : (F G : Functor C D) → Type _
N-ob-Type F G = (x : C .ob) → D [(F .F-ob x) , (G .F-ob x)]
N-hom-Type : (F G : Functor C D) → N-ob-Type F G → Type _
N-hom-Type F G ϕ = {x y : C .ob} (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (ϕ y) ≡ (ϕ x) ⋆ᴰ (G .F-hom f)
record NatTrans (F G : Functor C D) : Type (ℓ-max (ℓ-max ℓC ℓC') ℓD') where
constructor natTrans
field
-- components of the natural transformation
N-ob : N-ob-Type F G
-- naturality condition
N-hom : N-hom-Type F G N-ob
record NatIso (F G : Functor C D): Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where
field
trans : NatTrans F G
open NatTrans trans
field
nIso : ∀ (x : C .ob) → isIsoC D (N-ob x)
open isIsoC
-- the three other commuting squares
sqRL : ∀ {x y : C .ob} {f : C [ x , y ]}
→ F ⟪ f ⟫ ≡ (N-ob x) ⋆ᴰ G ⟪ f ⟫ ⋆ᴰ (nIso y) .inv
sqRL {x} {y} {f} = invMoveR (isIso→areInv (nIso y)) (N-hom f)
sqLL : ∀ {x y : C .ob} {f : C [ x , y ]}
→ G ⟪ f ⟫ ⋆ᴰ (nIso y) .inv ≡ (nIso x) .inv ⋆ᴰ F ⟪ f ⟫
sqLL {x} {y} {f} = invMoveL (isIso→areInv (nIso x)) (sym sqRL')
where
sqRL' : F ⟪ f ⟫ ≡ (N-ob x) ⋆ᴰ ( G ⟪ f ⟫ ⋆ᴰ (nIso y) .inv )
sqRL' = sqRL ∙ (D .⋆Assoc _ _ _)
sqLR : ∀ {x y : C .ob} {f : C [ x , y ]}
→ G ⟪ f ⟫ ≡ (nIso x) .inv ⋆ᴰ F ⟪ f ⟫ ⋆ᴰ (N-ob y)
sqLR {x} {y} {f} = invMoveR (symAreInv (isIso→areInv (nIso y))) sqLL
open NatTrans
open NatIso
infix 10 NatTrans
syntax NatTrans F G = F ⇒ G
infix 9 NatIso
syntax NatIso F G = F ≅ᶜ G -- c superscript to indicate that this is in the context of categories
-- component of a natural transformation
infix 30 _⟦_⟧
_⟦_⟧ : ∀ {F G : Functor C D} → F ⇒ G → (x : C .ob) → D [ F .F-ob x , G .F-ob x ]
_⟦_⟧ = N-ob
idTrans : (F : Functor C D) → NatTrans F F
idTrans F .N-ob x = D .id
idTrans F .N-hom f =
(F .F-hom f) ⋆ᴰ (idTrans F .N-ob _)
≡⟨ D .⋆IdR _ ⟩
F .F-hom f
≡⟨ sym (D .⋆IdL _) ⟩
(D .id) ⋆ᴰ (F .F-hom f)
∎
syntax idTrans F = 1[ F ]
-- vertical sequencing
seqTrans : {F G H : Functor C D} (α : NatTrans F G) (β : NatTrans G H) → NatTrans F H
seqTrans α β .N-ob x = (α .N-ob x) ⋆ᴰ (β .N-ob x)
seqTrans {F} {G} {H} α β .N-hom f =
(F .F-hom f) ⋆ᴰ ((α .N-ob _) ⋆ᴰ (β .N-ob _))
≡⟨ sym (D .⋆Assoc _ _ _) ⟩
((F .F-hom f) ⋆ᴰ (α .N-ob _)) ⋆ᴰ (β .N-ob _)
≡[ i ]⟨ (α .N-hom f i) ⋆ᴰ (β .N-ob _) ⟩
((α .N-ob _) ⋆ᴰ (G .F-hom f)) ⋆ᴰ (β .N-ob _)
≡⟨ D .⋆Assoc _ _ _ ⟩
(α .N-ob _) ⋆ᴰ ((G .F-hom f) ⋆ᴰ (β .N-ob _))
≡[ i ]⟨ (α .N-ob _) ⋆ᴰ (β .N-hom f i) ⟩
(α .N-ob _) ⋆ᴰ ((β .N-ob _) ⋆ᴰ (H .F-hom f))
≡⟨ sym (D .⋆Assoc _ _ _) ⟩
((α .N-ob _) ⋆ᴰ (β .N-ob _)) ⋆ᴰ (H .F-hom f)
∎
compTrans : {F G H : Functor C D} (β : NatTrans G H) (α : NatTrans F G) → NatTrans F H
compTrans β α = seqTrans α β
infixl 8 seqTrans
syntax seqTrans α β = α ●ᵛ β
-- vertically sequence natural transformations whose
-- common functor is not definitional equal
seqTransP : {F G G' H : Functor C D} (p : G ≡ G')
→ (α : NatTrans F G) (β : NatTrans G' H)
→ NatTrans F H
seqTransP {F} {G} {G'} {H} p α β .N-ob x
-- sequence morphisms with non-judgementally equal (co)domain
= seqP {C = D} {p = Gx≡G'x} (α ⟦ x ⟧) (β ⟦ x ⟧)
where
Gx≡G'x : ∀ {x} → G ⟅ x ⟆ ≡ G' ⟅ x ⟆
Gx≡G'x {x} i = F-ob (p i) x
seqTransP {F} {G} {G'} {H} p α β .N-hom {x = x} {y} f
-- compose the two commuting squares
-- 1. α's commuting square
-- 2. β's commuting square, but extended to G since β is only G' ≡> H
= compSq {C = D} (α .N-hom f) βSq
where
-- functor equality implies equality of actions on objects and morphisms
Gx≡G'x : G ⟅ x ⟆ ≡ G' ⟅ x ⟆
Gx≡G'x i = F-ob (p i) x
Gy≡G'y : G ⟅ y ⟆ ≡ G' ⟅ y ⟆
Gy≡G'y i = F-ob (p i) y
Gf≡G'f : PathP (λ i → D [ Gx≡G'x i , Gy≡G'y i ]) (G ⟪ f ⟫) (G' ⟪ f ⟫)
Gf≡G'f i = p i ⟪ f ⟫
-- components of β extended out to Gx and Gy respectively
βx' = subst (λ a → D [ a , H ⟅ x ⟆ ]) (sym Gx≡G'x) (β ⟦ x ⟧)
βy' = subst (λ a → D [ a , H ⟅ y ⟆ ]) (sym Gy≡G'y) (β ⟦ y ⟧)
-- extensions are equal to originals
βy'≡βy : PathP (λ i → D [ Gy≡G'y i , H ⟅ y ⟆ ]) βy' (β ⟦ y ⟧)
βy'≡βy = symP (toPathP {A = λ i → D [ Gy≡G'y (~ i) , H ⟅ y ⟆ ]} refl)
βx≡βx' : PathP (λ i → D [ Gx≡G'x (~ i) , H ⟅ x ⟆ ]) (β ⟦ x ⟧) βx'
βx≡βx' = toPathP refl
-- left wall of square
left : PathP (λ i → D [ Gx≡G'x i , H ⟅ y ⟆ ]) (G ⟪ f ⟫ ⋆⟨ D ⟩ βy') (G' ⟪ f ⟫ ⋆⟨ D ⟩ β ⟦ y ⟧)
left i = Gf≡G'f i ⋆⟨ D ⟩ βy'≡βy i
-- right wall of square
right : PathP (λ i → D [ Gx≡G'x (~ i) , H ⟅ y ⟆ ]) (β ⟦ x ⟧ ⋆⟨ D ⟩ H ⟪ f ⟫) (βx' ⋆⟨ D ⟩ H ⟪ f ⟫)
right i = βx≡βx' i ⋆⟨ D ⟩ refl {x = H ⟪ f ⟫} i
-- putting it all together
βSq : G ⟪ f ⟫ ⋆⟨ D ⟩ βy' ≡ βx' ⋆⟨ D ⟩ H ⟪ f ⟫
βSq i = comp (λ k → D [ Gx≡G'x (~ k) , H ⟅ y ⟆ ])
(λ j → λ { (i = i0) → left (~ j)
; (i = i1) → right j })
(β .N-hom f i)
module _ {F G : Functor C D} {α β : NatTrans F G} where
open Category
open Functor
open NatTrans
makeNatTransPath : α .N-ob ≡ β .N-ob → α ≡ β
makeNatTransPath p i .N-ob = p i
makeNatTransPath p i .N-hom f = rem i
where
rem : PathP (λ i → (F .F-hom f) ⋆ᴰ (p i _) ≡ (p i _) ⋆ᴰ (G .F-hom f))
(α .N-hom f) (β .N-hom f)
rem = toPathP (D .isSetHom _ _ _ _)
module _ {F F' G G' : Functor C D} {α : NatTrans F G} {β : NatTrans F' G'} where
open Category
open Functor
open NatTrans
makeNatTransPathP : ∀ (p : F ≡ F') (q : G ≡ G')
→ PathP (λ i → (x : C .ob) → D [ (p i) .F-ob x , (q i) .F-ob x ])
(α .N-ob) (β .N-ob)
→ PathP (λ i → NatTrans (p i) (q i)) α β
makeNatTransPathP p q P i .N-ob = P i
makeNatTransPathP p q P i .N-hom f = rem i
where
rem : PathP (λ i → ((p i) .F-hom f) ⋆ᴰ (P i _) ≡ (P i _) ⋆ᴰ ((q i) .F-hom f))
(α .N-hom f) (β .N-hom f)
rem = toPathP (D .isSetHom _ _ _ _)
module _ {B : Category ℓB ℓB'} {C : Category ℓC ℓC'} {D : Category ℓD ℓD'} where
open NatTrans
-- whiskering
-- αF
_∘ˡ_ : ∀ {G H : Functor C D} (α : NatTrans G H) → (F : Functor B C)
→ NatTrans (G ∘F F) (H ∘F F)
(_∘ˡ_ {G} {H} α F) .N-ob x = α ⟦ F ⟅ x ⟆ ⟧
(_∘ˡ_ {G} {H} α F) .N-hom f = (α .N-hom) _
-- Kβ
_∘ʳ_ : ∀ (K : Functor C D) → {G H : Functor B C} (β : NatTrans G H)
→ NatTrans (K ∘F G) (K ∘F H)
(_∘ʳ_ K {G} {H} β) .N-ob x = K ⟪ β ⟦ x ⟧ ⟫
(_∘ʳ_ K {G} {H} β) .N-hom f = preserveCommF {C = C} {D = D} {K} (β .N-hom f)
| 35.345622
| 102
| 0.494263
|
adee8eda95577cdb53a2b384459c2c8c4c03a4b4
| 681
|
agda
|
Agda
|
Rings/Primes/Definition.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Rings/Primes/Definition.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Rings/Primes/Definition.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Rings.Definition
open import Rings.IntegralDomains.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Rings.Primes.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) where
open import Rings.Divisible.Definition R
open Ring R
open Setoid S
open import Rings.Units.Definition R
record Prime (x : A) : Set (a ⊔ b) where
field
isPrime : (r s : A) → (x ∣ (r * s)) → ((x ∣ r) → False) → (x ∣ s)
nonzero : (x ∼ 0R) → False
nonunit : Unit x → False
| 30.954545
| 152
| 0.653451
|
2ebb999f040658076f172ff72c93098a04fa9b90
| 9,519
|
agda
|
Agda
|
Cubical/Algebra/IntegerMatrix/Diagonalization.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/IntegerMatrix/Diagonalization.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/IntegerMatrix/Diagonalization.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-
This file contains a diagonalization procedure simpler than Smith normalization.
For any matrix M, it provides two invertible matrices P, Q, one diagonal matrix D and an equality M = P·D·Q.
The only difference from Smith is, the numbers in D are allowed to be arbitrary, instead of being consecutively divisible.
But it is enough to establish important properties of finitely presented abelian groups.
Also, it can be computed much more efficiently (than Smith, only).
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.IntegerMatrix.Diagonalization where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat
hiding (_·_)
renaming (_+_ to _+ℕ_ ; +-assoc to +Assocℕ)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Nat.Divisibility
using (m∣n→m≤n)
renaming (∣-trans to ∣ℕ-trans ; ∣-refl to ∣-reflℕ)
open import Cubical.Data.Int
hiding (_+_ ; _·_ ; _-_ ; -_ ; addEq)
open import Cubical.Data.Int.Divisibility
open import Cubical.Data.FinData
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Unit as Unit
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.List
open import Cubical.Algebra.Matrix
open import Cubical.Algebra.Matrix.CommRingCoefficient
open import Cubical.Algebra.Matrix.Elementaries
open import Cubical.Algebra.IntegerMatrix.Base
open import Cubical.Algebra.IntegerMatrix.Elementaries
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int
renaming (ℤ to ℤRing)
open import Cubical.Relation.Nullary
open import Cubical.Induction.WellFounded
private
variable
m n k : ℕ
open CommRingStr (ℤRing .snd)
open Coefficient ℤRing
open Sim
open ElemTransformation ℤRing
open ElemTransformationℤ
open SwapPivot
open RowsImproved
open ColsImproved
-- Sequence of non-zero integers
isNonZero : List ℤ → Type
isNonZero [] = Unit
isNonZero (x ∷ xs) = (¬ x ≡ 0) × isNonZero xs
isPropIsNonZero : (xs : List ℤ) → isProp (isNonZero xs)
isPropIsNonZero [] = isPropUnit
isPropIsNonZero (x ∷ xs) = isProp× (isPropΠ (λ _ → isProp⊥)) (isPropIsNonZero xs)
NonZeroList : Type
NonZeroList = Σ[ xs ∈ List ℤ ] isNonZero xs
cons : (n : ℤ)(xs : NonZeroList) → ¬ n ≡ 0 → NonZeroList
cons n (xs , _) _ .fst = n ∷ xs
cons n ([] , _) p .snd = p , tt
cons n (x ∷ xs , q) p .snd = p , q
-- Smith normal matrix
_+length_ : NonZeroList → ℕ → ℕ
xs +length n = length (xs .fst) +ℕ n
diagMat : (xs : List ℤ)(m n : ℕ) → Mat (length xs +ℕ m) (length xs +ℕ n)
diagMat [] _ _ = 𝟘
diagMat (x ∷ xs) _ _ = x ⊕ diagMat xs _ _
diagMat⊕ :
(a : ℤ)(xs : NonZeroList){m n : ℕ}
→ (p : ¬ a ≡ 0)
→ a ⊕ diagMat (xs .fst) m n ≡ diagMat (cons a xs p .fst) m n
diagMat⊕ _ _ _ = refl
-- Diagonal matrix with non-zero diagonal elements
-- Notice that we allow non-square matrices.
record isDiagonal (M : Mat m n) : Type where
field
divs : NonZeroList
rowNull : ℕ
colNull : ℕ
rowEq : divs +length rowNull ≡ m
colEq : divs +length colNull ≡ n
matEq : PathP (λ t → Mat (rowEq t) (colEq t)) (diagMat (divs .fst) rowNull colNull) M
open isDiagonal
row col : {M : Mat m n} → isDiagonal M → ℕ
row isNorm = isNorm .divs +length isNorm .rowNull
col isNorm = isNorm .divs +length isNorm .colNull
isDiagonal𝟘 : isDiagonal (𝟘 {m = m} {n = n})
isDiagonal𝟘 .divs = [] , tt
isDiagonal𝟘 {m = m} .rowNull = m
isDiagonal𝟘 {n = n} .colNull = n
isDiagonal𝟘 .rowEq = refl
isDiagonal𝟘 .colEq = refl
isDiagonal𝟘 .matEq = refl
isDiagonalEmpty : (M : Mat 0 n) → isDiagonal M
isDiagonalEmpty _ .divs = [] , tt
isDiagonalEmpty _ .rowNull = 0
isDiagonalEmpty {n = n} _ .colNull = n
isDiagonalEmpty _ .rowEq = refl
isDiagonalEmpty _ .colEq = refl
isDiagonalEmpty _ .matEq = isContr→isProp isContrEmpty _ _
isDiagonalEmptyᵗ : (M : Mat m 0) → isDiagonal M
isDiagonalEmptyᵗ _ .divs = [] , tt
isDiagonalEmptyᵗ {m = m} _ .rowNull = m
isDiagonalEmptyᵗ _ .colNull = 0
isDiagonalEmptyᵗ _ .rowEq = refl
isDiagonalEmptyᵗ _ .colEq = refl
isDiagonalEmptyᵗ _ .matEq = isContr→isProp isContrEmptyᵗ _ _
-- Induction step towards diagonalization
data DivStatus (a : ℤ)(M : Mat (suc m) (suc n)) : Type where
badCol : (i : Fin m)(p : ¬ a ∣ M (suc i) zero) → DivStatus a M
badRow : (j : Fin n)(p : ¬ a ∣ M zero (suc j)) → DivStatus a M
allDone : ((i : Fin m) → a ∣ M (suc i) zero)
→ ((j : Fin n) → a ∣ M zero (suc j)) → DivStatus a M
divStatus : (a : ℤ)(M : Mat (suc m) (suc n)) → DivStatus a M
divStatus a M =
let col? = ∀Dec (λ i → a ∣ M (suc i) zero) (λ _ → dec∣ _ _)
row? = ∀Dec (λ j → a ∣ M zero (suc j)) (λ _ → dec∣ _ _) in
case col?
return (λ _ → DivStatus a M) of λ
{ (inr p) → badCol (p .fst) (p .snd)
; (inl p) →
case row?
return (λ _ → DivStatus a M) of λ
{ (inr q) → badRow (q .fst) (q .snd)
; (inl q) → allDone p q }}
record DiagStep (M : Mat (suc m) (suc n)) : Type where
field
sim : Sim M
firstColClean : (i : Fin m) → sim .result (suc i) zero ≡ 0
firstRowClean : (j : Fin n) → sim .result zero (suc j) ≡ 0
nonZero : ¬ sim .result zero zero ≡ 0
open DiagStep
simDiagStep : {M : Mat (suc m) (suc n)}(sim : Sim M) → DiagStep (sim .result) → DiagStep M
simDiagStep simM diag .sim = compSim simM (diag .sim)
simDiagStep _ diag .firstColClean = diag .firstColClean
simDiagStep _ diag .firstRowClean = diag .firstRowClean
simDiagStep _ diag .nonZero = diag .nonZero
private
diagStep-helper :
(M : Mat (suc m) (suc n))
→ (p : ¬ M zero zero ≡ 0)(h : Norm (M zero zero))
→ (div? : DivStatus (M zero zero) M)
→ DiagStep M
diagStep-helper M p (acc ind) (badCol i q) =
let improved = improveRows M p
normIneq =
ind _ (stDivIneq p q (improved .div zero) (improved .div (suc i)))
in simDiagStep (improved .sim)
(diagStep-helper _ (improved .nonZero) normIneq (divStatus _ _))
diagStep-helper M p (acc ind) (badRow j q) =
let improved = improveCols M p
normIneq =
ind _ (stDivIneq p q (improved .div zero) (improved .div (suc j)))
in simDiagStep (improved .sim)
(diagStep-helper _ (improved .nonZero) normIneq (divStatus _ _))
diagStep-helper M p (acc ind) (allDone div₁ div₂) =
let improveColM = improveCols M p
invCol = bézoutRows-inv _ p div₂
divCol = (λ i → transport (λ t → invCol t zero ∣ invCol t (suc i)) (div₁ i))
improveRowM = improveRows (improveColM .sim .result) (improveColM .nonZero)
invCol = bézoutRows-inv _ (improveColM .nonZero) divCol
in record
{ sim = compSim (improveColM .sim) (improveRowM .sim)
; firstColClean = improveRowM .vanish
; firstRowClean = (λ j → (λ t → invCol (~ t) (suc j)) ∙ improveColM .vanish j)
; nonZero = improveRowM .nonZero }
diagStep-getStart : (M : Mat (suc m) (suc n)) → NonZeroOrNot M → DiagStep M ⊎ (M ≡ 𝟘)
diagStep-getStart _ (allZero p) = inr p
diagStep-getStart M (hereIs i j p) =
let swapM = swapPivot i j M
swapNonZero = (λ r → p (swapM .swapEq ∙ r))
diagM = diagStep-helper _ swapNonZero (<-wellfounded _) (divStatus _ _)
in inl (simDiagStep (swapM .sim) diagM)
diagStep : (M : Mat (suc m) (suc n)) → DiagStep M ⊎ (M ≡ 𝟘)
diagStep _ = diagStep-getStart _ (findNonZero _)
-- The diagonalization
record Diag (M : Mat m n) : Type where
field
sim : Sim M
isdiag : isDiagonal (sim .result)
open Diag
simDiag : {M : Mat m n}(sim : Sim M) → Diag (sim .result) → Diag M
simDiag simM diag .sim = compSim simM (diag .sim)
simDiag _ diag .isdiag = diag .isdiag
diag𝟘 : Diag (𝟘 {m = m} {n = n})
diag𝟘 .sim = idSim _
diag𝟘 .isdiag = isDiagonal𝟘
diagEmpty : (M : Mat 0 n) → Diag M
diagEmpty _ .sim = idSim _
diagEmpty M .isdiag = isDiagonalEmpty M
diagEmptyᵗ : (M : Mat m 0) → Diag M
diagEmptyᵗ _ .sim = idSim _
diagEmptyᵗ M .isdiag = isDiagonalEmptyᵗ M
decompDiagStep :
(M : Mat (suc m) (suc n))(step : DiagStep M)
→ step .sim .result ≡ step .sim .result zero zero ⊕ sucMat (step .sim .result)
decompDiagStep M step t zero zero = step .sim .result zero zero
decompDiagStep M step t zero (suc j) = step .firstRowClean j t
decompDiagStep M step t (suc i) zero = step .firstColClean i t
decompDiagStep M step t (suc i) (suc j) = step .sim .result (suc i) (suc j)
consIsDiagonal :
(a : ℤ)(M : Mat m n)
→ (p : ¬ a ≡ 0)
→ isDiagonal M → isDiagonal (a ⊕ M)
consIsDiagonal a _ p diag .divs = cons a (diag .divs) p
consIsDiagonal _ _ _ diag .rowNull = diag .rowNull
consIsDiagonal _ _ _ diag .colNull = diag .colNull
consIsDiagonal _ _ _ diag .rowEq = (λ t → suc (diag .rowEq t))
consIsDiagonal _ _ _ diag .colEq = (λ t → suc (diag .colEq t))
consIsDiagonal a _ _ diag .matEq = (λ t → a ⊕ diag .matEq t)
diagReduction :
(a : ℤ)(M : Mat m n)
→ (p : ¬ a ≡ 0)
→ Diag M → Diag (a ⊕ M)
diagReduction a _ _ diag .sim = ⊕Sim a (diag .sim)
diagReduction a _ p diag .isdiag = consIsDiagonal a _ p (diag .isdiag)
-- The Existence of Diagonalization
diagonalize : (M : Mat m n) → Diag M
diagonalize {m = 0} = diagEmpty
diagonalize {m = suc m} {n = 0} = diagEmptyᵗ
diagonalize {m = suc m} {n = suc n} M = helper (diagStep _)
where
helper : DiagStep M ⊎ (M ≡ 𝟘) → Diag M
helper (inr p) = subst Diag (sym p) diag𝟘
helper (inl stepM) =
let sucM = sucMat (stepM .sim .result)
diagM = diagReduction _ _ (stepM .nonZero) (diagonalize sucM)
in simDiag (compSim (stepM .sim) (≡Sim (decompDiagStep _ stepM))) diagM
| 33.4
| 122
| 0.658262
|
43fb3dd079ddee5e344a43fe48590b814deaa3be
| 13,916
|
agda
|
Agda
|
src/Divergence.agda
|
boystrange/FairSubtypingAgda
|
c4b78e70c3caf68d509f4360b9171d9f80ecb825
|
[
"MIT"
] | 4
|
2021-07-29T14:32:30.000Z
|
2022-01-24T14:38:47.000Z
|
src/Divergence.agda
|
boystrange/FairSubtypingAgda
|
c4b78e70c3caf68d509f4360b9171d9f80ecb825
|
[
"MIT"
] | null | null | null |
src/Divergence.agda
|
boystrange/FairSubtypingAgda
|
c4b78e70c3caf68d509f4360b9171d9f80ecb825
|
[
"MIT"
] | null | null | null |
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS --guardedness --sized-types #-}
open import Data.Empty
open import Data.Unit
open import Data.Product
open import Data.Maybe
open import Data.Sum
open import Data.List using (_++_; []; _∷_; _∷ʳ_; length)
open import Data.List.Properties using (∷-injective)
open import Relation.Nullary
open import Relation.Nullary.Negation using (contraposition)
open import Relation.Unary using (_∈_; _⊆_)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym; subst; cong)
open import Function.Base using (case_of_)
open import Common
module Divergence {ℙ : Set} (message : Message ℙ)
where
open import SessionType message
open import Session message
open import Trace message
open import HasTrace message
open import TraceSet message
open import Transitions message
open import Semantics message
open import Subtyping message
DivergeForward : SessionType -> SessionType -> Trace -> Set
record _↑_ (T : SessionType) (S : SessionType) : Set where
coinductive
field
trace : Trace
with-trace : T HasTrace trace
without-trace : ¬ S HasTrace trace
divergence : DivergeForward T S trace
DivergeForward T S φ =
∀{ψ x}
(pre : ψ ⊑ φ)
(tψx : T HasTrace (ψ ∷ʳ O x))
(sψx : S HasTrace (ψ ∷ʳ O x)) -> after tψx ↑ after sψx
diverge-before-input : ∀{f g x} -> f x .force ↑ g x .force -> inp f ↑ inp g
_↑_.trace (diverge-before-input {_} {_} {x} div) = I x ∷ _↑_.trace div
_↑_.with-trace (diverge-before-input div) = inp-has-trace (_↑_.with-trace div)
_↑_.without-trace (diverge-before-input div) = inp-has-no-trace (_↑_.without-trace div)
_↑_.divergence (diverge-before-input div) none (_ , _ , step () _) _
_↑_.divergence (diverge-before-input div) (some le) (_ , tdef , step inp tr) (_ , sdef , step inp sr) =
_↑_.divergence div le (_ , tdef , tr) (_ , sdef , sr)
DivergeBackward : ∀{T S φ} -> T HasTrace φ -> S HasTrace φ -> Set
DivergeBackward {_} {_} {φ} tφ sφ =
∀{ψ} (pre : ψ ⊑ φ) -> after (⊑-has-trace pre tφ) ↑ after (⊑-has-trace pre sφ)
⊑-diverge-backward :
∀{T S φ ψ}
{tφ : T HasTrace φ}
{sφ : S HasTrace φ}
(pre : ψ ⊑ φ) ->
DivergeBackward tφ sφ ->
DivergeBackward (⊑-has-trace pre tφ) (⊑-has-trace pre sφ)
⊑-diverge-backward {_} {_} {_} {_} {tφ} {sφ} pre div pre' rewrite ⊑-tran-has-trace pre' pre tφ | ⊑-tran-has-trace pre' pre sφ =
div (⊑-tran pre' pre)
data DiscSet : SessionType -> SessionType -> Trace -> Set where
inc : ∀{T S φ}
(tφ : T HasTrace φ)
(sφ : S HasTrace φ)
(div←φ : DivergeBackward tφ sφ) -> DiscSet T S φ
exc : ∀{T S φ ψ x}
(eq : φ ≡ ψ ∷ʳ O x)
(tψ : T HasTrace ψ)
(sψ : S HasTrace ψ)
(tφ : T HasTrace φ)
(nsφ : ¬ S HasTrace φ)
(div←ψ : DivergeBackward tψ sψ) -> DiscSet T S φ
⊑-proper : ∀{φ ψ α} -> φ ⊑ (ψ ∷ʳ α) -> φ ⊑ ψ ⊎ φ ≡ ψ ∷ʳ α
⊑-proper {[]} {[]} none = inj₁ none
⊑-proper {_ ∷ []} {[]} (some none) = inj₂ refl
⊑-proper {[]} {_ ∷ _} none = inj₁ none
⊑-proper {_} {_ ∷ _} (some pre) with ⊑-proper pre
... | inj₁ pre' = inj₁ (some pre')
... | inj₂ refl = inj₂ refl
disc-set->closed : (T S : SessionType) -> PrefixClosed (DiscSet T S)
disc-set->closed T S pre (inc tφ sφ div←φ) =
inc (⊑-has-trace pre tφ) (⊑-has-trace pre sφ) (⊑-diverge-backward pre div←φ)
disc-set->closed T S pre (exc refl tψ sψ tφ nsφ div←ψ) with ⊑-proper pre
... | inj₁ pre' = inc (⊑-has-trace pre' tψ) (⊑-has-trace pre' sψ) (⊑-diverge-backward pre' div←ψ)
... | inj₂ refl = exc refl tψ sψ tφ nsφ div←ψ
input-lemma : ∀{φ x ψ χ y} -> φ ++ I x ∷ ψ ≡ χ ∷ʳ O y -> (φ ∷ʳ I x) ⊑ χ
input-lemma {[]} {_} {_} {I x ∷ χ} refl = some none
input-lemma {x ∷ φ} {_} {_} {[]} eq with ∷-injective eq
... | (_ , eq') = ⊥-elim (absurd-++-≡ eq')
input-lemma {x ∷ φ} {_} {_} {y ∷ χ} eq with ∷-injective eq
... | (refl , eq'') = some (input-lemma eq'')
disc-set-input : ∀{φ x ψ} {T S : SessionType} -> DiscSet T S (φ ++ I x ∷ ψ) ->
T HasTrace (φ ∷ʳ I x) × S HasTrace (φ ∷ʳ I x)
disc-set-input {φ} {x} {ψ} (inc tφ sφ div←φ) with ⊑-precong-++ {φ} {I x ∷ []} {I x ∷ ψ} (some none)
... | pre = ⊑-has-trace pre tφ , ⊑-has-trace pre sφ
disc-set-input (exc eq tχ sχ _ _ _) with input-lemma eq
... | pre = ⊑-has-trace pre tχ , ⊑-has-trace pre sχ
disc-set-output : ∀{φ x ψ} {T S : SessionType} -> DiscSet T S (φ ++ O x ∷ ψ) -> T HasTrace (φ ∷ʳ O x)
disc-set-output {φ} {x} {ψ} (inc tφx sφx _) =
let pre = ⊑-precong-++ {φ} {O x ∷ []} {O x ∷ ψ} (some none) in
⊑-has-trace pre tφx
disc-set-output {φ} {x} {ψ} (exc _ _ _ tφx _ _) =
let pre = ⊑-precong-++ {φ} {O x ∷ []} {O x ∷ ψ} (some none) in
⊑-has-trace pre tφx
disc-set->coherent : (T S : SessionType) -> Coherent (DiscSet T S)
disc-set->coherent T S ti to =
let (ti[] , _) = disc-set-input ti in
let to[] = disc-set-output to in
⊥-elim (coherent (sem-sound T) ti[] to[])
disc-set->semantics : (T S : SessionType) -> Semantics (DiscSet T S)
closed (disc-set->semantics T S) = disc-set->closed T S
coherent (disc-set->semantics T S) = disc-set->coherent T S
disc-set-subset : ∀{T S} -> DiscSet T S ⊆ ⟦ T ⟧
disc-set-subset (inc tφ _ _) = tφ
disc-set-subset (exc _ _ _ tφ _ _) = tφ
disc-set-disjoint :
∀{T S φ} ->
φ ∈ DiscSet T S ->
¬ S HasTrace φ ->
∃[ ψ ] ∃[ x ] (φ ≡ ψ ∷ʳ O x × S HasTrace ψ)
disc-set-disjoint (inc _ sφ _) nsφ = ⊥-elim (nsφ sφ)
disc-set-disjoint (exc eq _ sψ _ _ _) nsφ = _ , _ , eq , sψ
-- --| BEGIN MAXIMAL TRACES |--
diverge-forward-input :
∀{f g x φ} -> DivergeForward (inp f) (inp g) (I x ∷ φ)
-> DivergeForward (f x .force) (g x .force) φ
diverge-forward-input div pre (_ , tdef , tr) (_ , sdef , sr) = div (some pre) (_ , tdef , step inp tr) (_ , sdef , step inp sr)
diverge-forward-input' :
∀{f g x φ} -> DivergeForward (f x .force) (g x .force) φ
-> DivergeForward (inp f) (inp g) (I x ∷ φ)
diverge-forward-input' div none (_ , _ , step () _) (_ , _ , _)
diverge-forward-input' div (some le) (_ , tdef , step inp tr) (_ , sdef , step inp sr) = div le (_ , tdef , tr) (_ , sdef , sr)
diverge-forward-output :
∀{f g x φ} -> DivergeForward (out f) (out g) (O x ∷ φ)
-> DivergeForward (f x .force) (g x .force) φ
diverge-forward-output div pre (_ , tdef , tr) (_ , sdef , sr) =
div (some pre)
(_ , tdef , step (out (transitions+defined->defined tr tdef)) tr)
(_ , sdef , step (out (transitions+defined->defined sr sdef)) sr)
-- the next lemma says that if T ↑ S and φ is the trace that
-- discriminates between them, then we have divergence along any
-- common prefix of φ shared by both T and S
diverge-forward->backward :
∀{T S φ ψ}
(tφ : T HasTrace φ)
(nsφ : ¬ S HasTrace φ)
(div : DivergeForward T S φ)
(pre : ψ ⊑ φ)
(tψ : T HasTrace ψ)
(sψ : S HasTrace ψ) ->
DivergeBackward tψ sψ
_↑_.trace (diverge-forward->backward tφ nsφ div pre tψ sψ none) = _
_↑_.with-trace (diverge-forward->backward tφ nsφ div pre tψ sψ none) = tφ
_↑_.without-trace (diverge-forward->backward tφ nsφ div pre tψ sψ none) = nsφ
_↑_.divergence (diverge-forward->backward tφ nsφ div pre tψ sψ none) = div
diverge-forward->backward (_ , tdef , step inp tr) nsφ div (some pre) (_ , tdef' , step (inp {f}) tr') (_ , sdef , step (inp {g}) sr) (some pre') =
diverge-forward->backward (_ , tdef , tr) (contraposition inp-has-trace nsφ) (diverge-forward-input {f} {g} div) pre (_ , tdef' , tr') (_ , sdef , sr) pre'
diverge-forward->backward (_ , tdef , step (out _) tr) nsφ div (some pre) (_ , tdef' , step (out {f} _) tr') (_ , sdef , step (out {g} _) sr) (some pre') =
diverge-forward->backward (_ , tdef , tr) (contraposition out-has-trace nsφ) (diverge-forward-output {f} {g} div) pre (_ , tdef' , tr') (_ , sdef , sr) pre'
prefix-last-element : ∀{φ φ' ψ ψ' x y} -> φ ⊑ ψ -> φ ≡ φ' ++ O x ∷ [] -> ψ ≡ ψ' ∷ʳ O y -> ψ ≡ φ ⊎ φ ⊑ ψ'
prefix-last-element none e1 e2 = inj₂ none
prefix-last-element {φ' = []} {ψ' = []} (some pre) e1 e2 with ∷-injective e1 | ∷-injective e2
... | (_ , e1') | (_ , e2') rewrite e1' | e2' = inj₁ refl
prefix-last-element {φ' = []} {ψ' = x ∷ ψ'} (some _) e1 e2 with ∷-injective e1 | ∷-injective e2
... | (eq1 , e1') | (eq2 , e2') rewrite eq1 | eq2 | e1' | e2' = inj₂ (some none)
prefix-last-element {φ' = x ∷ φ'} {ψ' = []} (some pre) e1 e2 with ∷-injective e1 | ∷-injective e2
... | (eq1 , e1') | (eq2 , e2') rewrite e1' | e2' = ⊥-elim (absurd-++-⊑ pre)
prefix-last-element {φ' = x ∷ φ'} {ψ' = x₁ ∷ ψ'} (some pre) e1 e2 with ∷-injective e1 | ∷-injective e2
... | (eq1 , e1') | (eq2 , e2') rewrite eq1 | eq2 with prefix-last-element pre e1' e2'
... | inj₁ eq rewrite eq = inj₁ refl
... | inj₂ pre' = inj₂ (some pre')
disc-set-maximal-1 :
∀{T S φ} ->
φ ∈ DiscSet T S ->
¬ S HasTrace φ ->
φ ∈ Maximal (DiscSet T S)
disc-set-maximal-1 dsφ nsφ with disc-set-disjoint dsφ nsφ
... | _ , _ , refl , sψ =
maximal dsφ λ le ds' ->
let _ , _ , eq , sψ' = disc-set-disjoint ds' (contraposition (⊑-has-trace le) nsφ) in
case prefix-last-element le refl eq of λ
{ (inj₁ refl) → refl
; (inj₂ le') → ⊥-elim (contraposition (⊑-has-trace le') nsφ sψ') }
has-trace-after : ∀{T φ ψ} (tφ : T HasTrace φ) -> after tφ HasTrace ψ -> T HasTrace (φ ++ ψ)
has-trace-after (_ , _ , refl) tφψ = tφψ
has-trace-after (_ , tdef , step inp tr) tφψ = inp-has-trace (has-trace-after (_ , tdef , tr) tφψ)
has-trace-after (_ , tdef , step (out _) tr) tφψ = out-has-trace (has-trace-after (_ , tdef , tr) tφψ)
has-no-trace-after : ∀{T φ ψ} (tφ : T HasTrace φ) -> ¬ after tφ HasTrace ψ -> ¬ T HasTrace (φ ++ ψ)
has-no-trace-after (_ , _ , refl) tφ/nψ = tφ/nψ
has-no-trace-after (_ , tdef , step inp tr) tφ/nψ = inp-has-no-trace (has-no-trace-after (_ , tdef , tr) tφ/nψ)
has-no-trace-after (_ , tdef , step (out _) tr) tφ/nψ = out-has-no-trace (has-no-trace-after (_ , tdef , tr) tφ/nψ)
append-diverge-backward :
∀{T S φ ψ}
(tφ : T HasTrace φ)
(sφ : S HasTrace φ)
(tφ/ψ : after tφ HasTrace ψ)
(sφ/ψ : after sφ HasTrace ψ)
(div←φ : DivergeBackward tφ sφ)
(divφ←ψ : DivergeBackward tφ/ψ sφ/ψ) ->
DivergeBackward (has-trace-after tφ tφ/ψ) (has-trace-after sφ sφ/ψ)
append-diverge-backward (_ , tdef , refl) (_ , sdef , refl) tφ/ψ sφ/ψ div←φ divφ←ψ pre = divφ←ψ pre
append-diverge-backward (_ , tdef , step t tr) (_ , sdef , step s sr) tφ/ψ sφ/ψ div←φ divφ←ψ none = div←φ none
append-diverge-backward (_ , tdef , step inp tr) (_ , sdef , step inp sr) tφ/ψ sφ/ψ div←φ divφ←ψ (some pre) =
append-diverge-backward (_ , tdef , tr) (_ , sdef , sr) tφ/ψ sφ/ψ (λ pre -> div←φ (some pre)) divφ←ψ pre
append-diverge-backward (_ , tdef , step (out _) tr) (_ , sdef , step (out _) sr) tφ/ψ sφ/ψ div←φ divφ←ψ (some pre) =
append-diverge-backward (_ , tdef , tr) (_ , sdef , sr) tφ/ψ sφ/ψ (λ pre -> div←φ (some pre)) divφ←ψ pre
append-snoc : ∀{φ ψ : Trace}{α : Action} -> φ ++ (ψ ∷ʳ α) ≡ (φ ++ ψ) ∷ʳ α
append-snoc {[]} = refl
append-snoc {β ∷ φ} = cong (β ∷_) (append-snoc {φ})
completion :
∀{φ T S} ->
T <: S ->
φ ∈ DiscSet T S ->
(∃[ ψ ] (φ ⊏ ψ × ψ ∈ Maximal (DiscSet T S))) ⊎ (φ ∈ Maximal (DiscSet T S) × ¬ S HasTrace φ)
completion {φ} sub (inc tφ sφ div←φ) with div←φ (⊑-refl _)
... | div rewrite ⊑-has-trace-after tφ | ⊑-has-trace-after sφ =
let χ = _↑_.trace div in
let tφ/χ = _↑_.with-trace div in
let sφ/nχ = _↑_.without-trace div in
let divφ→χ = _↑_.divergence div in
let subφ = sub-after tφ sφ sub in
let ψ , x , ψ⊑χ , tφ/ψ , sφ/ψ , tφ/ψx , sφ/nψx = sub-excluded subφ tφ/χ sφ/nχ in
let tφψ = has-trace-after tφ tφ/ψ in
let sφψ = has-trace-after sφ sφ/ψ in
let tφψx = has-trace-after tφ tφ/ψx in
let sφnψx = has-no-trace-after sφ sφ/nψx in
let divφ←ψ = diverge-forward->backward tφ/χ sφ/nχ divφ→χ ψ⊑χ tφ/ψ sφ/ψ in
let div←ψ = append-diverge-backward tφ sφ tφ/ψ sφ/ψ div←φ divφ←ψ in
let ds = exc {_} {_} {φ ++ (ψ ∷ʳ O x)} {φ ++ ψ} {x} (append-snoc {φ} {ψ} {O x}) tφψ sφψ tφψx sφnψx div←ψ in
inj₁ (φ ++ (ψ ∷ʳ O x) , ⊏-++ , disc-set-maximal-1 ds sφnψx)
completion sub ds@(exc _ _ _ _ nsφ _) =
inj₂ (disc-set-maximal-1 ds nsφ , nsφ)
disc-set-maximal-2 :
∀{T S φ} ->
T <: S ->
φ ∈ Maximal (DiscSet T S) ->
¬ S HasTrace φ
disc-set-maximal-2 sub (maximal dφ F) sφ with completion sub dφ
... | inj₁ (ψ , φ⊏ψ , maximal dψ _) = ⊏->≢ φ⊏ψ (sym (F (⊏->⊑ φ⊏ψ) dψ))
... | inj₂ (_ , nsφ) = nsφ sφ
--| END MAXIMAL TRACES |--
-- Sia R il session type determinato da disc-set T S quando T ↑
-- S. L'obiettivo è dimostrare che R |- T e ¬ R |- S
--
-- R |- T
--
-- Ogni riduzione di (R # T) può essere completata a (R' # T') in
-- cui Win R' e Defined T'
--
-- Siccome le tracce di R sono incluse in quelle di T, basta
-- dimostrare che ogni traccia di R può essere completata, cioè che
-- ogni traccia di disc-set T S è prefisso di una traccia completa
-- di disc-set T S.
--
-- ∀ φ ∈ R => ∃ ψ : φ ++ ψ ∈ Maximal R
--
-- ¬ R |- S
--
-- Dimostrare che ogni traccia completa di R non è una traccia di S.
--
-- Maximal R ∩ ⟦ S ⟧ ≡ ∅
| 43.352025
| 158
| 0.615982
|
2282e1017923041a2ad2186e11e44a17efde8659
| 8,754
|
agda
|
Agda
|
src/Tree-sort/Full.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Tree-sort/Full.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Tree-sort/Full.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A correct implementation of tree sort
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- The algorithm and the treatment of ordering information is taken
-- from Conor McBride's talk "Pivotal pragmatism".
-- The module is parametrised by a total relation.
open import Equality
open import Prelude hiding (id; _∘_; lower)
module Tree-sort.Full
{c⁺}
(eq : ∀ {a p} → Equality-with-J a p c⁺)
{A : Type}
(le : A → A → Type)
(total : ∀ x y → le x y ⊎ le y x)
where
open Derived-definitions-and-properties eq
open import Bag-equivalence eq using () renaming (Any to AnyL)
open import Bijection eq using (_↔_)
open import Function-universe eq hiding (Kind; module Kind)
open import List eq
------------------------------------------------------------------------
-- Extending the order with new minimum and maximum elements
-- A extended with a new minimum and maximum.
data Extended : Type where
min max : Extended
[_] : (x : A) → Extended
infix 4 _≤_
_≤_ : Extended → Extended → Type
min ≤ y = ⊤
[ x ] ≤ [ y ] = le x y
x ≤ max = ⊤
_ ≤ _ = ⊥
-- A pair of ordering constraints (written as a record type to aid
-- type inference).
infix 4 _,_
record _≤[_]≤_ (l : Extended) (x : A) (u : Extended) : Type where
constructor _,_
field
lower : l ≤ [ x ]
upper : [ x ] ≤ u
------------------------------------------------------------------------
-- Ordered lists
data Ordered-list (l u : Extended) : Type where
nil : (l≤u : l ≤ u) → Ordered-list l u
cons : (x : A) (xs : Ordered-list [ x ] u) (l≤x : l ≤ [ x ]) →
Ordered-list l u
-- Conversion to ordinary lists.
to-list : ∀ {l u} → Ordered-list l u → List A
to-list (nil l≤u) = []
to-list (cons x xs l≤x) = x ∷ to-list xs
------------------------------------------------------------------------
-- Unbalanced binary search trees
infix 5 node
syntax node x lx xu = lx -[ x ]- xu
data Search-tree (l u : Extended) : Type where
leaf : (l≤u : l ≤ u) → Search-tree l u
node : (x : A) (lx : Search-tree l [ x ]) (xu : Search-tree [ x ] u) →
Search-tree l u
-- Any.
AnyT : ∀ {l u} → (A → Type) → Search-tree l u → Type
AnyT P (leaf _) = ⊥
AnyT P (node x l r) = AnyT P l ⊎ P x ⊎ AnyT P r
------------------------------------------------------------------------
-- An ad-hoc universe consisting of lists, ordered lists and search
-- trees
-- The purpose of this universe is to allow overloading of Any, _∈_
-- and _≈-bag_.
-- Codes.
data Kind : Type where
list ordered-list search-tree : Kind
-- Index type.
--
-- Note that Agda infers values of type ⊤ automatically.
Index : Kind → Type
Index list = ⊤
Index _ = Extended
-- Interpretation.
⟦_⟧ : (k : Kind) → (Index k → Index k → Type)
⟦ list ⟧ _ _ = List A
⟦ ordered-list ⟧ l u = Ordered-list l u
⟦ search-tree ⟧ l u = Search-tree l u
-- Any.
Any : ∀ {k l u} → (A → Type) → (⟦ k ⟧ l u → Type)
Any {list} = AnyL
Any {ordered-list} = λ P → AnyL P ∘ to-list
Any {search-tree} = AnyT
-- Membership.
infix 4 _∈_
_∈_ : ∀ {k l u} → A → ⟦ k ⟧ l u → Type
x ∈ xs = Any (λ y → x ≡ y) xs
-- Bag equivalence.
infix 4 _≈-bag_
_≈-bag_ : ∀ {k₁ k₂ l₁ u₁ l₂ u₂} → ⟦ k₁ ⟧ l₁ u₁ → ⟦ k₂ ⟧ l₂ u₂ → Type
xs ≈-bag ys = ∀ z → z ∈ xs ↔ z ∈ ys
------------------------------------------------------------------------
-- Singleton trees
singleton : ∀ {l u} (x : A) → l ≤[ x ]≤ u → Search-tree l u
singleton x (l≤x , x≤u) = leaf l≤x -[ x ]- leaf x≤u
-- Any lemma for singleton.
Any-singleton : ∀ (P : A → Type) {l u x} (l≤x≤u : l ≤[ x ]≤ u) →
Any P (singleton x l≤x≤u) ↔ P x
Any-singleton P {x = x} l≤x≤u =
Any P (singleton x l≤x≤u) ↔⟨⟩
⊥ ⊎ P x ⊎ ⊥ ↔⟨ ⊎-left-identity ⟩
P x ⊎ ⊥ ↔⟨ ⊎-right-identity ⟩
P x □
------------------------------------------------------------------------
-- Insertion into a search tree
insert : ∀ {l u} (x : A) → Search-tree l u → l ≤[ x ]≤ u →
Search-tree l u
insert x (leaf _) l≤x≤u = singleton x l≤x≤u
insert x (ly -[ y ]- yu) (l≤x , x≤u) with total x y
... | inj₁ x≤y = insert x ly (l≤x , x≤y) -[ y ]- yu
... | inj₂ y≤x = ly -[ y ]- insert x yu (y≤x , x≤u)
-- Any lemma for insert.
Any-insert : ∀ (P : A → Type) {l u} x t (l≤x≤u : l ≤[ x ]≤ u) →
Any P (insert x t l≤x≤u) ↔ P x ⊎ Any P t
Any-insert P {l} {u} x (leaf l≤u) l≤x≤u =
Any P (singleton x l≤x≤u) ↔⟨ Any-singleton P l≤x≤u ⟩
P x ↔⟨ inverse ⊎-right-identity ⟩
P x ⊎ ⊥ ↔⟨⟩
P x ⊎ Any P (leaf {l = l} {u = u} l≤u) □
Any-insert P x (ly -[ y ]- yu) (l≤x , x≤u) with total x y
... | inj₁ x≤y =
Any P (insert x ly (l≤x , x≤y)) ⊎ P y ⊎ Any P yu ↔⟨ Any-insert P x ly (l≤x , x≤y) ⊎-cong id ⟩
(P x ⊎ Any P ly) ⊎ P y ⊎ Any P yu ↔⟨ inverse ⊎-assoc ⟩
P x ⊎ Any P ly ⊎ P y ⊎ Any P yu □
... | inj₂ y≤x =
Any P ly ⊎ P y ⊎ Any P (insert x yu (y≤x , x≤u)) ↔⟨ id ⊎-cong id ⊎-cong Any-insert P x yu (y≤x , x≤u) ⟩
Any P ly ⊎ P y ⊎ P x ⊎ Any P yu ↔⟨ lemma _ _ _ _ ⟩
P x ⊎ Any P ly ⊎ P y ⊎ Any P yu □
where
-- The following lemma is easy to prove automatically (for
-- instance by using a ring solver).
lemma : (A B C D : Type) → A ⊎ B ⊎ C ⊎ D ↔ C ⊎ A ⊎ B ⊎ D
lemma A B C D =
A ⊎ B ⊎ C ⊎ D ↔⟨ id ⊎-cong ⊎-assoc ⟩
A ⊎ (B ⊎ C) ⊎ D ↔⟨ id ⊎-cong ⊎-comm ⊎-cong id ⟩
A ⊎ (C ⊎ B) ⊎ D ↔⟨ ⊎-assoc ⟩
(A ⊎ C ⊎ B) ⊎ D ↔⟨ ⊎-assoc ⊎-cong id ⟩
((A ⊎ C) ⊎ B) ⊎ D ↔⟨ (⊎-comm ⊎-cong id) ⊎-cong id ⟩
((C ⊎ A) ⊎ B) ⊎ D ↔⟨ inverse ⊎-assoc ⊎-cong id ⟩
(C ⊎ A ⊎ B) ⊎ D ↔⟨ inverse ⊎-assoc ⟩
C ⊎ (A ⊎ B) ⊎ D ↔⟨ id ⊎-cong inverse ⊎-assoc ⟩
C ⊎ A ⊎ B ⊎ D □
------------------------------------------------------------------------
-- Turning an unordered list into a search tree
to-search-tree : List A → Search-tree min max
to-search-tree = foldr (λ x t → insert x t _) (leaf _)
-- No elements are added or removed.
to-search-tree-lemma : ∀ xs → to-search-tree xs ≈-bag xs
to-search-tree-lemma [] = λ z →
z ∈ leaf {l = min} {u = max} _ ↔⟨⟩
z ∈ [] □
to-search-tree-lemma (x ∷ xs) = λ z →
z ∈ insert x (to-search-tree xs) _ ↔⟨ Any-insert (λ x → z ≡ x) _ _ _ ⟩
z ≡ x ⊎ z ∈ to-search-tree xs ↔⟨ id ⊎-cong to-search-tree-lemma xs z ⟩
z ∈ x ∷ xs □
------------------------------------------------------------------------
-- Appending two ordered lists with an extra element in between
infixr 5 append
syntax append x lx xu = lx -⁅ x ⁆- xu
append : ∀ {l u} (x : A) →
Ordered-list l [ x ] → Ordered-list [ x ] u → Ordered-list l u
nil l≤x -⁅ x ⁆- xu = cons x xu l≤x
cons y yx l≤y -⁅ x ⁆- xu = cons y (yx -⁅ x ⁆- xu) l≤y
-- Any lemma for append.
Any-append : ∀ (P : A → Type) {l u} x
(lx : Ordered-list l [ x ]) (xu : Ordered-list [ x ] u) →
Any P (lx -⁅ x ⁆- xu) ↔ Any P lx ⊎ P x ⊎ Any P xu
Any-append P x (nil l≤x) xu =
P x ⊎ Any P xu ↔⟨ inverse ⊎-left-identity ⟩
⊥ ⊎ P x ⊎ Any P xu □
Any-append P x (cons y yx l≤y) xu =
P y ⊎ Any P (append x yx xu) ↔⟨ id ⊎-cong Any-append P x yx xu ⟩
P y ⊎ Any P yx ⊎ P x ⊎ Any P xu ↔⟨ ⊎-assoc ⟩
(P y ⊎ Any P yx) ⊎ P x ⊎ Any P xu □
------------------------------------------------------------------------
-- Inorder flattening of a tree
flatten : ∀ {l u} → Search-tree l u → Ordered-list l u
flatten (leaf l≤u) = nil l≤u
flatten (l -[ x ]- r) = flatten l -⁅ x ⁆- flatten r
-- Flatten does not add or remove any elements.
flatten-lemma : ∀ {l u} (t : Search-tree l u) → flatten t ≈-bag t
flatten-lemma {l} {u} (leaf l≤u) = λ z →
z ∈ nil {l = l} {u = u} l≤u ↔⟨⟩
z ∈ leaf {l = l} {u = u} l≤u □
flatten-lemma (l -[ x ]- r) = λ z →
z ∈ flatten l -⁅ x ⁆- flatten r ↔⟨ Any-append (λ x → z ≡ x) _ _ _ ⟩
z ∈ flatten l ⊎ z ≡ x ⊎ z ∈ flatten r ↔⟨ flatten-lemma l z ⊎-cong id ⊎-cong flatten-lemma r z ⟩
z ∈ l ⊎ z ≡ x ⊎ z ∈ r ↔⟨⟩
z ∈ l -[ x ]- r □
------------------------------------------------------------------------
-- Sorting
-- Sorts a list.
tree-sort : List A → Ordered-list min max
tree-sort = flatten ∘ to-search-tree
-- The result is a permutation of the input.
tree-sort-permutes : ∀ xs → tree-sort xs ≈-bag xs
tree-sort-permutes xs = λ z →
z ∈ tree-sort xs ↔⟨⟩
z ∈ flatten (to-search-tree xs) ↔⟨ flatten-lemma (to-search-tree xs) _ ⟩
z ∈ to-search-tree xs ↔⟨ to-search-tree-lemma xs _ ⟩
z ∈ xs □
| 31.717391
| 106
| 0.465844
|
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.