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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2221e38c5f302b043cf9231b157f42bd82c030d2
| 2,257
|
agda
|
Agda
|
src/Categories/Functor/Monoidal.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Monoidal.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Monoidal.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Monoidal where
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Category
open import Categories.Category.Product
open import Categories.Category.Monoidal
open import Categories.Functor hiding (id)
open import Categories.NaturalTransformation hiding (id)
private
variable
o ℓ e : Level
C D : Category o ℓ e
module _ (MC : Monoidal C) (MD : Monoidal D) where
private
module C = Category C
module D = Category D
module MC = Monoidal MC
module MD = Monoidal MD
record MonoidalFunctor : Set (levelOfTerm MC ⊔ levelOfTerm MD) where
field
F : Functor C D
open Functor F public
field
ε : D [ MD.unit , F₀ MC.unit ]
⊗-homo : NaturalTransformation (MD.⊗ ∘F (F ⁂ F)) (F ∘F MC.⊗)
module ⊗-homo = NaturalTransformation ⊗-homo
-- coherence condition
open D
open MD
open Commutation D
field
associativity : ∀ {X Y Z} →
[ (F₀ X ⊗₀ F₀ Y) ⊗₀ F₀ Z ⇒ F₀ (X MC.⊗₀ Y MC.⊗₀ Z) ]⟨
⊗-homo.η (X , Y) ⊗₁ id ⇒⟨ F₀ (X MC.⊗₀ Y) ⊗₀ F₀ Z ⟩
⊗-homo.η (X MC.⊗₀ Y , Z) ⇒⟨ F₀ ((X MC.⊗₀ Y) MC.⊗₀ Z) ⟩
F₁ MC.associator.from
≈ associator.from ⇒⟨ F₀ X ⊗₀ F₀ Y ⊗₀ F₀ Z ⟩
id ⊗₁ ⊗-homo.η (Y , Z) ⇒⟨ F₀ X ⊗₀ F₀ (Y MC.⊗₀ Z) ⟩
⊗-homo.η (X , Y MC.⊗₀ Z)
⟩
unitaryˡ : ∀ {X} →
[ unit ⊗₀ F₀ X ⇒ F₀ X ]⟨
ε ⊗₁ id ⇒⟨ F₀ MC.unit ⊗₀ F₀ X ⟩
⊗-homo.η (MC.unit , X) ⇒⟨ F₀ (MC.unit MC.⊗₀ X) ⟩
F₁ MC.unitorˡ.from
≈ unitorˡ.from
⟩
unitaryʳ : ∀ {X} →
[ F₀ X ⊗₀ unit ⇒ F₀ X ]⟨
id ⊗₁ ε ⇒⟨ F₀ X ⊗₀ F₀ MC.unit ⟩
⊗-homo.η (X , MC.unit) ⇒⟨ F₀ (X MC.⊗₀ MC.unit) ⟩
F₁ MC.unitorʳ.from
≈ unitorʳ.from
⟩
| 33.191176
| 101
| 0.435534
|
3881a435e75d21e014eee77d5cef2addfd4d3fdc
| 3,978
|
agda
|
Agda
|
a3.agda
|
felixwellen/adventOfCode
|
834bc9e291a76bdbcd58cbff9805161f1b1cfe71
|
[
"MIT"
] | null | null | null |
a3.agda
|
felixwellen/adventOfCode
|
834bc9e291a76bdbcd58cbff9805161f1b1cfe71
|
[
"MIT"
] | null | null | null |
a3.agda
|
felixwellen/adventOfCode
|
834bc9e291a76bdbcd58cbff9805161f1b1cfe71
|
[
"MIT"
] | null | null | null |
{-
Day 3, 1st part
-}
module a3 where
open import Agda.Builtin.IO using (IO)
open import Agda.Builtin.Unit using (⊤)
open import Agda.Builtin.String using (String; primShowNat)
open import Agda.Builtin.Equality
open import Data.Nat
open import Data.Bool
open import Data.List hiding (lookup;allFin)
renaming (map to mapList)
open import Data.Vec
open import Data.Fin hiding (_+_)
open import Data.Maybe renaming (map to maybeMap)
open import a3-input
postulate putStrLn : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text as T #-}
{-# COMPILE GHC putStrLn = putStrLn . T.unpack #-}
-- helper
showMaybeNat : Maybe ℕ → String
showMaybeNat (just n) = primShowNat n
showMaybeNat nothing = "nothing"
data Bit : Set where
one : Bit
zero : Bit
BitVec = Vec Bit
Vecℕ→BitVec : {n : ℕ} → Vec ℕ n → Maybe (BitVec n)
Vecℕ→BitVec [] = just []
Vecℕ→BitVec (x ∷ v) with Vecℕ→BitVec v
... | just v' with x
... | 0 = just (zero ∷ v')
... | 1 = just (one ∷ v')
... | suc (suc _) = nothing
Vecℕ→BitVec (x ∷ v) | nothing = nothing
findMostCommonBit : {n : ℕ} (index : Fin n) → List (BitVec n) → Bit
findMostCommonBit {n = n} index input = iterate 0 0 input
where
iterate : (zeros : ℕ) (ones : ℕ) → List (BitVec n) → Bit
iterate zeros ones [] =
if zeros <ᵇ ones then one else zero
iterate zeros ones (bitVec ∷ list) with lookup bitVec index
... | zero = iterate (1 + zeros) ones list
... | one = iterate zeros (1 + ones) list
bitVecToℕ : {n : ℕ} → BitVec n → ℕ
bitVecToℕ [] = 0
bitVecToℕ (zero ∷ v) = bitVecToℕ v
bitVecToℕ {n = suc n} (one ∷ v) = 2 ^ n + (bitVecToℕ v)
invertBitVec : {n : ℕ} → BitVec n → BitVec n
invertBitVec [] = []
invertBitVec (zero ∷ v) = one ∷ invertBitVec v
invertBitVec (one ∷ v) = zero ∷ invertBitVec v
listMaybe : {A : Set} → List (Maybe A) → Maybe (List A)
listMaybe [] = just []
listMaybe (just x ∷ list) with listMaybe list
... | just proccessedList = just (x ∷ proccessedList)
... | nothing = nothing
listMaybe (nothing ∷ list) = nothing
doTask : List (BitVec 12) → ℕ
doTask input = gamma * epsilon
where
bitVecGamma = map (λ index → findMostCommonBit index input) (allFin 12)
gamma : ℕ
gamma = bitVecToℕ bitVecGamma
epsilon = bitVecToℕ (invertBitVec bitVecGamma)
main : IO ⊤
main = putStrLn (showMaybeNat ((maybeMap doTask) (listMaybe (mapList Vecℕ→BitVec input))))
private
-- checks from the exercise text
testInput : Maybe (List (BitVec 5))
testInput = listMaybe (mapList Vecℕ→BitVec
((0 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ []) ∷
(1 ∷ 1 ∷ 1 ∷ 1 ∷ 0 ∷ []) ∷
(1 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ []) ∷
(1 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ []) ∷
(1 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ []) ∷
(0 ∷ 1 ∷ 1 ∷ 1 ∷ 1 ∷ []) ∷
(0 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ []) ∷
(1 ∷ 1 ∷ 1 ∷ 0 ∷ 0 ∷ []) ∷
(1 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ []) ∷
(1 ∷ 1 ∷ 0 ∷ 0 ∷ 1 ∷ []) ∷
(0 ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ []) ∷
(0 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ []) ∷
[]))
_ : maybeMap (findMostCommonBit Fin.zero) testInput ≡ just one
_ = refl
_ : maybeMap (findMostCommonBit (Fin.suc Fin.zero)) testInput ≡ just zero
_ = refl
_ : maybeMap (findMostCommonBit (Fin.suc (Fin.suc Fin.zero))) testInput ≡ just one
_ = refl
_ : maybeMap (findMostCommonBit (Fin.suc (Fin.suc (Fin.suc Fin.zero)))) testInput ≡ just one
_ = refl
_ : maybeMap (findMostCommonBit (fromℕ 4)) testInput ≡ just zero
_ = refl
-- test bitVecToℕ
_ : bitVecToℕ (one ∷ zero ∷ one ∷ one ∷ zero ∷ []) ≡ 22
_ = refl
_ : Vecℕ→BitVec (1 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ []) ≡ just (one ∷ zero ∷ one ∷ one ∷ zero ∷ [])
_ = refl
_ : Vecℕ→BitVec (1 ∷ 0 ∷ 1 ∷ 5 ∷ 0 ∷ []) ≡ nothing
_ = refl
| 31.571429
| 94
| 0.538462
|
1ed7f786a85901ad4c75427a0f01d8d07191e3aa
| 156
|
agda
|
Agda
|
Bool.agda
|
mjhopkins/PowerOfPi
|
76743baacba0f07992bac5234ba8045d18706893
|
[
"Apache-2.0"
] | 1
|
2018-07-25T13:12:15.000Z
|
2018-07-25T13:12:15.000Z
|
Bool.agda
|
mjhopkins/PowerOfPi
|
76743baacba0f07992bac5234ba8045d18706893
|
[
"Apache-2.0"
] | null | null | null |
Bool.agda
|
mjhopkins/PowerOfPi
|
76743baacba0f07992bac5234ba8045d18706893
|
[
"Apache-2.0"
] | null | null | null |
module Bool where
data Bool : Set where
true : Bool
false : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
| 15.6
| 27
| 0.608974
|
5ed898faf4b37460fd04e9075cd70db2ac2f5297
| 390
|
agda
|
Agda
|
test/interaction/Issue3110.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3110.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3110.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Unexpected context for generalized type #3110
postulate
Nat : Set
Fin : Nat → Set
Foo : (n : Nat) → Fin n → Set
private
module M where
variable
n : Nat
m : Fin _
postulate
Bar : Foo n m → Set
open M public using (Bar)
variable
n : Nat
m : Fin _
l : Foo n m
before : Bar l
before {n} {m} {l} = {!C-c C-e!}
after : Bar l
after {n} {m} {l} = {!C-c C-e!}
| 13.448276
| 48
| 0.561538
|
a01e88b8e51d59dc94e3d6675506f82451fdcca7
| 127
|
agda
|
Agda
|
test/Fail/RecordPattern2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/RecordPattern2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/RecordPattern2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
postulate A : Set
record R : Set where
field f : A
record S : Set where
field g : A
test : R → A
test record{g = a} = a
| 11.545455
| 22
| 0.598425
|
d1a05e7286f8dded99ed5d957001f5a1e61ddaef
| 2,397
|
agda
|
Agda
|
src/agda/FRP/JS/JSON.agda
|
agda/agda-frp-js
|
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
|
[
"MIT",
"BSD-3-Clause"
] | 63
|
2015-04-20T21:47:00.000Z
|
2022-02-28T09:46:14.000Z
|
src/agda/FRP/JS/JSON.agda
|
agda/agda-frp-js
|
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
|
[
"MIT",
"BSD-3-Clause"
] | null | null | null |
src/agda/FRP/JS/JSON.agda
|
agda/agda-frp-js
|
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
|
[
"MIT",
"BSD-3-Clause"
] | 7
|
2016-11-07T21:50:58.000Z
|
2022-03-12T11:39:38.000Z
|
{-# OPTIONS --sized-types #-}
open import FRP.JS.Bool using ( Bool ; true ; false ) renaming ( _≟_ to _≟b_ )
open import FRP.JS.Nat using ( ℕ )
open import FRP.JS.Float using ( ℝ ) renaming ( _≟_ to _≟n_ )
open import FRP.JS.String using ( String ) renaming ( _≟_ to _≟s_ )
open import FRP.JS.Array using ( Array ) renaming ( lookup? to alookup? ; _≟[_]_ to _≟a[_]_ )
open import FRP.JS.Object using ( Object ) renaming ( lookup? to olookup? ; _≟[_]_ to _≟o[_]_ )
open import FRP.JS.Maybe using ( Maybe ; just ; nothing )
open import FRP.JS.Size using ( Size ; ↑_ )
module FRP.JS.JSON where
data JSON : {σ : Size} → Set where
null : ∀ {σ} → JSON {σ}
string : ∀ {σ} → String → JSON {σ}
float : ∀ {σ} → ℝ → JSON {σ}
bool : ∀ {σ} → Bool → JSON {σ}
array : ∀ {σ} → Array (JSON {σ}) → JSON {↑ σ}
object : ∀ {σ} → Object (JSON {σ}) → JSON {↑ σ}
{-# COMPILED_JS JSON function(x,v) {
if (x === null) { return v.null(null); }
else if (x.constructor === String) { return v.string(null,x); }
else if (x.constructor === Number) { return v.float(null,x); }
else if (x.constructor === Boolean) { return v.bool(null,x); }
else if (x.constructor === Array) { return v.array(null,x); }
else { return v.object(null,x); }
} #-}
{-# COMPILED_JS null function() { return null; } #-}
{-# COMPILED_JS string function() { return function(x) { return x; }; } #-}
{-# COMPILED_JS float function() { return function(x) { return x; }; } #-}
{-# COMPILED_JS bool function() { return function(x) { return x; }; } #-}
{-# COMPILED_JS array function() { return function(x) { return x; }; } #-}
{-# COMPILED_JS object function() { return function(x) { return x; }; } #-}
postulate
show : JSON → String
parse : String → Maybe JSON
{-# COMPILED_JS show JSON.stringify #-}
{-# COMPILED_JS parse require("agda.box").handle(JSON.parse) #-}
Key : Bool → Set
Key true = String
Key false = ℕ
lookup? : ∀ {σ} → Maybe (JSON {↑ σ}) → ∀ {b} → Key b → Maybe (JSON {σ})
lookup? (just (object js)) {true} k = olookup? js k
lookup? (just (array js)) {false} i = alookup? js i
lookup? _ _ = nothing
_≟_ : ∀ {σ τ} → JSON {σ} → JSON {τ} → Bool
null ≟ null = true
string s ≟ string t = s ≟s t
float m ≟ float n = m ≟n n
bool b ≟ bool c = b ≟b c
array js ≟ array ks = js ≟a[ _≟_ ] ks
object js ≟ object ks = js ≟o[ _≟_ ] ks
_ ≟ _ = false
| 39.295082
| 95
| 0.584063
|
309d954a8377dcbe390fd55fed3585e48651c692
| 327
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Apply.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Apply.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/Apply.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
module Oscar.Class.Apply where
module _
(𝔉 : ∀ {𝔣} → Ø 𝔣 → Ø 𝔣)
𝔬₁ 𝔬₂
where
𝓪pply = ∀ {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} → 𝔉 (𝔒₁ → 𝔒₂) → 𝔉 𝔒₁ → 𝔉 𝔒₂
record 𝓐pply : Ø ↑̂ (𝔬₁ ∙̂ 𝔬₂) where
infixl 4 apply
field apply : 𝓪pply
syntax apply f x = f <*> x
open 𝓐pply ⦃ … ⦄ public
_<*>_ = apply
| 18.166667
| 63
| 0.553517
|
a0375ce7d7ac4e68781ff42b29dba42d6fe441d8
| 19,534
|
agda
|
Agda
|
agda/PLRTree/Insert/Complete.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/PLRTree/Insert/Complete.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/PLRTree/Insert/Complete.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module PLRTree.Insert.Complete {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.Empty
open import Data.Sum renaming (_⊎_ to _∨_)
open import PLRTree {A}
open import PLRTree.Compound {A}
open import PLRTree.Insert _≤_ tot≤
open import PLRTree.Insert.Properties _≤_ tot≤
open import PLRTree.Complete {A}
open import PLRTree.Complete.Properties {A}
open import PLRTree.Equality {A}
open import PLRTree.Equality.Properties {A}
lemma-≃-⊥ : {l : PLRTree}(x : A) → l ≃ insert x l → ⊥
lemma-≃-⊥ {leaf} _ ()
lemma-≃-⊥ {node perfect x' l' r'} x l≃lᵢ
with tot≤ x x' | l' | r' | l≃lᵢ
... | inj₁ x≤x' | leaf | leaf | ()
... | inj₁ x≤x' | leaf | node _ _ _ _ | ()
... | inj₁ x≤x' | node _ _ _ _ | leaf | ()
... | inj₁ x≤x' | node _ _ _ _ | node _ _ _ _ | ()
... | inj₂ x'≤x | leaf | leaf | ()
... | inj₂ x'≤x | leaf | node _ _ _ _ | ()
... | inj₂ x'≤x | node _ _ _ _ | leaf | ()
... | inj₂ x'≤x | node _ _ _ _ | node _ _ _ _ | ()
lemma-≃-⊥ {node left _ _ _} _ ()
lemma-≃-⊥ {node right _ _ _} _ ()
lemma-⋗-⊥ : {l : PLRTree}(x : A) → l ⋗ insert x l → ⊥
lemma-⋗-⊥ {leaf} _ ()
lemma-⋗-⊥ {node perfect x' l' r'} x l⋗lᵢ
with tot≤ x x' | l' | r' | l⋗lᵢ
... | inj₁ x≤x' | leaf | leaf | ()
... | inj₁ x≤x' | leaf | node _ _ _ _ | ()
... | inj₁ x≤x' | node _ _ _ _ | leaf | ()
... | inj₁ x≤x' | node _ _ _ _ | node _ _ _ _ | ()
... | inj₂ x'≤x | leaf | leaf | ()
... | inj₂ x'≤x | leaf | node _ _ _ _ | ()
... | inj₂ x'≤x | node _ _ _ _ | leaf | ()
... | inj₂ x'≤x | node _ _ _ _ | node _ _ _ _ | ()
lemma-⋗-⊥ {node left _ _ _} _ ()
lemma-⋗-⊥ {node right _ _ _} _ ()
lemma-⋙-⊥ : {l r : PLRTree}(x : A) → l ⋙ r → l ⋗ insert x r → ⊥
lemma-⋙-⊥ x (⋙p l⋗r) l⋗rᵢ = lemma-≃-⊥ x (lemma-⋗* l⋗r l⋗rᵢ)
lemma-⋙-⊥ x (⋙l {l' = l''} y' y'' l'≃r' l''⋘r'' l'⋗r'') l⋗rᵢ
with tot≤ x y''
... | inj₁ x≤y''
with insert y'' l'' | lemma-insert-compound y'' l'' | l⋗rᵢ
... | node perfect _ _ _ | compound | ()
... | node left _ _ _ | compound | ()
... | node right _ _ _ | compound | ()
lemma-⋙-⊥ x (⋙l {l' = l''} y' y'' l'≃r' l''⋘r'' l'⋗r'') l⋗rᵢ | inj₂ y''≤x
with insert x l'' | lemma-insert-compound x l'' | l⋗rᵢ
... | node perfect _ _ _ | compound | ()
... | node left _ _ _ | compound | ()
... | node right _ _ _ | compound | ()
lemma-⋙-⊥ x (⋙r {r' = r''} y' y'' l'≃r' l''⋙r'' l'≃l'') l⋗rᵢ
with tot≤ x y''
... | inj₁ x≤y''
with insert y'' r'' | lemma-insert-compound y'' r'' | l⋗rᵢ
... | node perfect _ _ _ | compound | ⋗nd .y' .x _ l''≃r''ᵢ l'⋗l'' = lemma-⋗refl-⊥ (lemma-⋗-≃ l'⋗l'' (sym≃ l'≃l''))
... | node left _ _ _ | compound | ()
... | node right _ _ _ | compound | ()
lemma-⋙-⊥ x (⋙r {r' = r''} y' y'' l'≃r' l''⋙r'' l'≃l'') l⋗rᵢ | inj₂ y''≤x
with insert x r'' | lemma-insert-compound x r'' | l⋗rᵢ
... | node perfect _ _ _ | compound | ⋗nd .y' .y'' _ l''≃r''ᵢ l'⋗l'' = lemma-⋗refl-⊥ (lemma-⋗-≃ l'⋗l'' (sym≃ l'≃l''))
... | node left _ _ _ | compound | ()
... | node right _ _ _ | compound | ()
lemma-insert-≃ : {l r : PLRTree}{x : A} → Compound l → l ≃ r → insert x l ⋘ r
lemma-insert-≃ {node perfect y l r} {node perfect y' l' r'} {x} compound (≃nd .y .y' l≃r l'≃r' l≃l')
with tot≤ x y | l | r | l≃r | l' | l≃l'
... | inj₁ x≤y | leaf | leaf | ≃lf | leaf | ≃lf = r⋘ x y' (⋙p (⋗lf y)) l'≃r' (⋗lf y)
... | inj₁ x≤y | node perfect z₁ _ _ | node perfect z₂ _ _ | ≃nd .z₁ .z₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ | node perfect z₃ _ _ | ≃nd .z₁ .z₃ _ l₃≃r₃ l₁≃l₃
= l⋘ x y' (lemma-insert-≃ compound (≃nd z₁ z₂ l₁≃r₁ l₂≃r₂ l₁≃l₂)) l'≃r' (≃nd z₂ z₃ l₂≃r₂ l₃≃r₃ (trans≃ (sym≃ l₁≃l₂) l₁≃l₃))
... | inj₂ y≤x | leaf | leaf | ≃lf | leaf | ≃lf = r⋘ y y' (⋙p (⋗lf x)) l'≃r' (⋗lf x)
... | inj₂ y≤x | node perfect z₁ _ _ | node perfect z₂ _ _ | ≃nd .z₁ .z₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ | node perfect z₃ _ _ | ≃nd .z₁ .z₃ _ l₃≃r₃ l₁≃l₃
= l⋘ y y' (lemma-insert-≃ compound (≃nd z₁ z₂ l₁≃r₁ l₂≃r₂ l₁≃l₂)) l'≃r' (≃nd z₂ z₃ l₂≃r₂ l₃≃r₃ (trans≃ (sym≃ l₁≃l₂) l₁≃l₃))
lemma-insert-⋗' : {l r : PLRTree}(x : A) → l ⋗ r → Compound r → l ⋙ (insert x r)
lemma-insert-⋗' x (⋗nd {l} {r} {l'} {r'} y y' l≃r l'≃r' l⋗l') compound
with tot≤ x y' | l' | r' | l'≃r' | l | l⋗l'
... | inj₁ x≤y' | leaf | leaf | ≃lf | node perfect x₁ leaf leaf | ⋗lf .x₁ = ⋙r y x l≃r (⋙p (⋗lf y')) (≃nd x₁ y' ≃lf ≃lf ≃lf)
... | inj₁ x≤y' | node perfect x₃ l₃ r₃ | node perfect x₄ l₄ r₄ | ≃nd .x₃ .x₄ l₃≃r₃ l₄≃r₄ l₃≃l₄ | node perfect x₁ l₁ r₁ | ⋗nd .x₁ .x₃ l₁≃r₁ _ l₁⋗l₃
with tot≤ y' x₃ | l₃ | r₃ | l₃≃r₃ | l₁ | l₁⋗l₃
... | inj₁ y'≤x₃ | leaf | leaf | ≃lf | node perfect x'₁ leaf leaf | ⋗lf .x'₁
with l₄ | l₃≃l₄
... | leaf | ≃lf =
let _l'ᵢ⋘r' = r⋘ y' x₄ (⋙p (⋗lf x₃)) l₄≃r₄ (⋗lf x₃) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ y' l₁≃r₁ ≃lf (⋗lf x'₁)) (≃nd y' x₄ ≃lf l₄≃r₄ ≃lf)
in ⋙l y x l≃r _l'ᵢ⋘r' _l⋗r'
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₁ x≤y' | node perfect x₃ _ _ | node perfect x₄ _ _ | ≃nd .x₃ .x₄ _ l₄≃r₄ l₃≃l₄ | node perfect x₁ _ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ _ | inj₁ y'≤x₃ | node perfect x'₅ _ _ | node perfect x'₆ _ _ | ≃nd .x'₅ .x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ | node perfect x'₁ _ _ | ⋗nd .x'₁ .x'₅ l'₁≃r'₁ _ l'₁⋗l'₅
with lemma-⋙-⋗ (lemma-insert-⋗' x₃ (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) compound) (lemma-⋗-≃ (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆))
... | inj₁ _l₃ᵢ⋘r₃ =
let _l₁⋗l₃ = ⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅ ;
_l₃≃r₃ = ≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ;
_l'ᵢ⋘r' = l⋘ y' x₄ _l₃ᵢ⋘r₃ l₄≃r₄ (trans≃ (sym≃ _l₃≃r₃) l₃≃l₄) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x₃ l₁≃r₁ _l₃≃r₃ _l₁⋗l₃) (≃nd x₃ x₄ _l₃≃r₃ l₄≃r₄ l₃≃l₄)
in ⋙l y x l≃r _l'ᵢ⋘r' _l⋗r'
... | inj₂ _l₃ᵢ≃r₃
with lemma-≃-⊥ x₃ (trans≃ (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ) (sym≃ _l₃ᵢ≃r₃))
... | ()
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₁ x≤y' | node perfect x₃ _ _ | node perfect x₄ l₄ _ | ≃nd .x₃ .x₄ _ l₄≃r₄ l₃≃l₄ | node perfect x₁ _ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ l₁⋗l₃ | inj₂ x₃≤y' | leaf | leaf | ≃lf | node perfect x'₁ leaf leaf | ⋗lf .x'₁
with l₄ | l₃≃l₄
... | leaf | ≃lf =
let _l'ᵢ⋘r' = r⋘ x₃ x₄ (⋙p (⋗lf y')) l₄≃r₄ (⋗lf y') ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x₃ l₁≃r₁ ≃lf (⋗lf x'₁)) (≃nd x₃ x₄ ≃lf l₄≃r₄ ≃lf)
in ⋙l y x l≃r _l'ᵢ⋘r' _l⋗r'
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₁ x≤y' | node perfect x₃ _ _ | node perfect x₄ _ _ | ≃nd .x₃ .x₄ l₃≃r₃ l₄≃r₄ l₃≃l₄ | node perfect x₁ _ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ l₁⋗l₃ | inj₂ x₃≤y' | node perfect x'₅ _ _ | node perfect x'₆ _ _ | ≃nd .x'₅ .x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ | node perfect x'₁ _ _ | ⋗nd .x'₁ .x'₅ l'₁≃r'₁ _ l'₁⋗l'₅
with lemma-⋙-⋗ (lemma-insert-⋗' y' (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) compound) (lemma-⋗-≃ (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆))
... | inj₁ _l₃ᵢ⋘r₃ =
let _l₁⋗l₃ = ⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅ ;
_l₃≃r₃ = ≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ;
_l'ᵢ⋘r' = l⋘ x₃ x₄ _l₃ᵢ⋘r₃ l₄≃r₄ (trans≃ (sym≃ _l₃≃r₃) l₃≃l₄) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x₃ l₁≃r₁ _l₃≃r₃ _l₁⋗l₃) (≃nd x₃ x₄ _l₃≃r₃ l₄≃r₄ l₃≃l₄)
in ⋙l y x l≃r _l'ᵢ⋘r' _l⋗r'
... | inj₂ _l₃ᵢ≃r₃
with lemma-≃-⊥ y' (trans≃ (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ) (sym≃ _l₃ᵢ≃r₃))
... | ()
lemma-insert-⋗' x (⋗nd y y' l≃r l'≃r' l⋗l') compound | inj₂ y'≤x | leaf | leaf | ≃lf | node perfect x₁ leaf leaf | ⋗lf .x₁ = ⋙r y y' l≃r (⋙p (⋗lf x)) (≃nd x₁ x ≃lf ≃lf ≃lf)
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₂ y'≤x | node perfect x₃ l₃ r₃ | node perfect x₄ l₄ _ | ≃nd .x₃ .x₄ l₃≃r₃ l₄≃r₄ l₃≃l₄ | node perfect x₁ l₁ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ l₁⋗l₃
with tot≤ x x₃ | l₃ | r₃ | l₃≃r₃ | l₁ | l₁⋗l₃
... | inj₁ x≤x₃ | leaf | leaf | ≃lf | node perfect x'₁ leaf leaf | ⋗lf .x'₁
with l₄ | l₃≃l₄
... | leaf | ≃lf =
let _l'ᵢ⋘r' = r⋘ x x₄ (⋙p (⋗lf x₃)) l₄≃r₄ (⋗lf x₃) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x l₁≃r₁ ≃lf (⋗lf x'₁)) (≃nd x x₄ ≃lf l₄≃r₄ ≃lf)
in ⋙l y y' l≃r _l'ᵢ⋘r' _l⋗r'
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₂ y'≤x | node perfect x₃ _ _ | node perfect x₄ _ _ | ≃nd .x₃ .x₄ _ l₄≃r₄ l₃≃l₄ | node perfect x₁ _ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ _ | inj₁ x≤x₃ | node perfect x'₅ _ _ | node perfect x'₆ _ _ | ≃nd .x'₅ .x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ | node perfect x'₁ _ _ | ⋗nd .x'₁ .x'₅ l'₁≃r'₁ _ l'₁⋗l'₅
with lemma-⋙-⋗ (lemma-insert-⋗' x₃ (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) compound) (lemma-⋗-≃ (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆))
... | inj₁ _l₃ᵢ⋘r₃ =
let _l₁⋗l₃ = ⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅ ;
_l₃≃r₃ = ≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ;
_l'ᵢ⋘r' = l⋘ x x₄ _l₃ᵢ⋘r₃ l₄≃r₄ (trans≃ (sym≃ _l₃≃r₃) l₃≃l₄) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x₃ l₁≃r₁ _l₃≃r₃ _l₁⋗l₃) (≃nd x₃ x₄ _l₃≃r₃ l₄≃r₄ l₃≃l₄)
in ⋙l y y' l≃r _l'ᵢ⋘r' _l⋗r'
... | inj₂ _l₃ᵢ≃r₃
with lemma-≃-⊥ x₃ (trans≃ (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ) (sym≃ _l₃ᵢ≃r₃))
... | ()
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₂ y'≤x | node perfect x₃ _ _ | node perfect x₄ l₄ _ | ≃nd .x₃ .x₄ _ l₄≃r₄ l₃≃l₄ | node perfect x₁ _ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ _ | inj₂ x₃≤x | leaf | leaf | ≃lf | node perfect x'₁ leaf leaf | ⋗lf .x'₁
with l₄ | l₃≃l₄
... | leaf | ≃lf =
let _l'ᵢ⋘r' = r⋘ x₃ x₄ (⋙p (⋗lf x)) l₄≃r₄ (⋗lf x) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x₃ l₁≃r₁ ≃lf (⋗lf x'₁)) (≃nd x₃ x₄ ≃lf l₄≃r₄ ≃lf)
in ⋙l y y' l≃r _l'ᵢ⋘r' _l⋗r'
lemma-insert-⋗' x (⋗nd y y' l≃r _ _) compound | inj₂ y'≤x | node perfect x₃ _ _ | node perfect x₄ _ _ | ≃nd .x₃ .x₄ _ l₄≃r₄ l₃≃l₄ | node perfect x₁ _ _ | ⋗nd .x₁ .x₃ l₁≃r₁ _ _ | inj₂ x₃≤x | node perfect x'₅ _ _ | node perfect x'₆ _ _ | ≃nd .x'₅ .x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ | node perfect x'₁ _ _ | ⋗nd .x'₁ .x'₅ l'₁≃r'₁ _ l'₁⋗l'₅
with lemma-⋙-⋗ (lemma-insert-⋗' x (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) compound) (lemma-⋗-≃ (⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅) (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆))
... | inj₁ _l₃ᵢ⋘r₃ =
let _l₁⋗l₃ = ⋗nd x'₁ x'₅ l'₁≃r'₁ l'₅≃r'₅ l'₁⋗l'₅ ;
_l₃≃r₃ = ≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆ ;
_l'ᵢ⋘r' = l⋘ x₃ x₄ _l₃ᵢ⋘r₃ l₄≃r₄ (trans≃ (sym≃ _l₃≃r₃) l₃≃l₄) ;
_l⋗r' = lemma-⋗-≃ (⋗nd x₁ x₃ l₁≃r₁ _l₃≃r₃ _l₁⋗l₃) (≃nd x₃ x₄ _l₃≃r₃ l₄≃r₄ l₃≃l₄)
in ⋙l y y' l≃r _l'ᵢ⋘r' _l⋗r'
... | inj₂ _l₃ᵢ≃r₃
with lemma-≃-⊥ x (trans≃ (≃nd x'₅ x'₆ l'₅≃r'₅ l'₆≃r'₆ l'₅≃l'₆) (sym≃ _l₃ᵢ≃r₃))
... | ()
lemma-insert-⋗ : {l r : PLRTree}(x : A) → l ⋗ r → l ⋙ (insert x r) ∨ l ≃ (insert x r)
lemma-insert-⋗ x (⋗lf y) = inj₂ (≃nd y x ≃lf ≃lf ≃lf)
lemma-insert-⋗ x (⋗nd y y' l≃r l'≃r' l⋗l') = inj₁ (lemma-insert-⋗' x (⋗nd y y' l≃r l'≃r' l⋗l') compound)
mutual
lemma-insert-⋘ : {l r : PLRTree}(x : A) → l ⋘ r → (insert x l) ⋘ r ∨ (insert x l) ⋗ r
lemma-insert-⋘ x (x⋘ u v w)
with tot≤ x u
... | inj₁ x≤u = inj₂ (⋗nd x w (≃nd v u ≃lf ≃lf ≃lf) ≃lf (⋗lf v))
... | inj₂ u≤x = inj₂ (⋗nd u w (≃nd v x ≃lf ≃lf ≃lf) ≃lf (⋗lf v))
lemma-insert-⋘ x (l⋘ {l = l} y y' l⋘r l'≃r' r≃l')
with tot≤ x y
... | inj₁ x≤y
with insert y l | lemma-insert-compound y l | lemma-insert-⋘ y l⋘r
... | node left _ _ _ | compound | inj₁ lᵢ⋘r = inj₁ (l⋘ x y' lᵢ⋘r l'≃r' r≃l')
... | node left _ _ _ | compound | inj₂ ()
... | node right _ _ _ | compound | inj₁ lᵢ⋙r = inj₁ (l⋘ x y' lᵢ⋙r l'≃r' r≃l')
... | node right _ _ _ | compound | inj₂ ()
... | node perfect _ _ _ | compound | inj₂ lᵢ⋗r = inj₁ (r⋘ x y' (⋙p lᵢ⋗r) l'≃r' (lemma-⋗-≃ lᵢ⋗r r≃l'))
... | node perfect _ _ _ | compound | inj₁ ()
lemma-insert-⋘ x (l⋘ {l = l} y y' l⋘r l'≃r' r≃l') | inj₂ y≤x
with insert x l | lemma-insert-compound x l | lemma-insert-⋘ x l⋘r
... | node left _ _ _ | compound | inj₁ lᵢ⋘r = inj₁ (l⋘ y y' lᵢ⋘r l'≃r' r≃l')
... | node left _ _ _ | compound | inj₂ ()
... | node right _ _ _ | compound | inj₁ lᵢ⋘r = inj₁ (l⋘ y y' lᵢ⋘r l'≃r' r≃l')
... | node right _ _ _ | compound | inj₂ ()
... | node perfect _ _ _ | compound | inj₂ lᵢ⋗r = inj₁ (r⋘ y y' (⋙p lᵢ⋗r) l'≃r' (lemma-⋗-≃ lᵢ⋗r r≃l'))
... | node perfect _ _ _ | compound | inj₁ ()
lemma-insert-⋘ x (r⋘ {r = r} y y' l⋙r l'≃r' l⋗l')
with tot≤ x y
... | inj₁ x≤y
with insert y r | lemma-insert-compound y r | lemma-insert-⋙ y l⋙r | lemma-⋙-⊥ y l⋙r
... | node left _ _ _ | compound | inj₁ l⋙rᵢ | _ = inj₁ (r⋘ x y' l⋙rᵢ l'≃r' l⋗l')
... | node left _ _ _ | compound | inj₂ () | _
... | node right _ _ _ | compound | inj₁ l⋙rᵢ | _ = inj₁ (r⋘ x y' l⋙rᵢ l'≃r' l⋗l')
... | node right _ _ _ | compound | inj₂ () | _
... | node perfect _ _ _ | compound | inj₂ l≃rᵢ | _ = inj₂ (⋗nd x y' l≃rᵢ l'≃r' l⋗l')
... | node perfect _ _ _ | compound | inj₁ (⋙p l⋗rᵢ) | lemma-⋙-⊥'
with lemma-⋙-⊥' l⋗rᵢ
... | ()
lemma-insert-⋘ x (r⋘ {r = r} y y' l⋙r l'≃r' l⋗l') | inj₂ y'≤x
with insert x r | lemma-insert-compound x r | lemma-insert-⋙ x l⋙r | lemma-⋙-⊥ x l⋙r
... | node left _ _ _ | compound | inj₁ l⋙rᵢ | _ = inj₁ (r⋘ y y' l⋙rᵢ l'≃r' l⋗l')
... | node left _ _ _ | compound | inj₂ () | _
... | node right _ _ _ | compound | inj₁ l⋙rᵢ | _ = inj₁ (r⋘ y y' l⋙rᵢ l'≃r' l⋗l')
... | node right _ _ _ | compound | inj₂ () | _
... | node perfect _ _ _ | compound | inj₂ l≃rᵢ | _ = inj₂ (⋗nd y y' l≃rᵢ l'≃r' l⋗l')
... | node perfect _ _ _ | compound | inj₁ (⋙p l⋗rᵢ) | lemma-⋙-⊥'
with lemma-⋙-⊥' l⋗rᵢ
... | ()
lemma-insert-⋙ : {l r : PLRTree}(x : A) → l ⋙ r → l ⋙ (insert x r) ∨ l ≃ (insert x r)
lemma-insert-⋙ x (⋙p l⋗r) = lemma-insert-⋗ x l⋗r
lemma-insert-⋙ x (⋙l {l' = l'} y y' l≃r l'⋘r' l⋗r')
with tot≤ x y'
... | inj₁ x≤y'
with insert y' l' | lemma-insert-compound y' l' | lemma-insert-⋘ y' l'⋘r'
... | node left _ _ _ | compound | inj₁ l'ᵢ⋘r' = inj₁ (⋙l y x l≃r l'ᵢ⋘r' l⋗r')
... | node left _ _ _ | compound | inj₂ ()
... | node right _ _ _ | compound | inj₁ l'ᵢ⋙r' = inj₁ (⋙l y x l≃r l'ᵢ⋙r' l⋗r')
... | node right _ _ _ | compound | inj₂ ()
... | node perfect _ _ _ | compound | inj₂ l'ᵢ⋗r' = inj₁ (⋙r y x l≃r (⋙p l'ᵢ⋗r') (lemma-*⋗ l⋗r' l'ᵢ⋗r'))
... | node perfect _ _ _ | compound | inj₁ ()
lemma-insert-⋙ x (⋙l {l' = l'} y y' l≃r l'⋘r' l⋗r') | inj₂ y'≤x
with insert x l' | lemma-insert-compound x l' | lemma-insert-⋘ x l'⋘r'
... | node left _ _ _ | compound | inj₁ l'ᵢ⋘r' = inj₁ (⋙l y y' l≃r l'ᵢ⋘r' l⋗r')
... | node left _ _ _ | compound | inj₂ ()
... | node right _ _ _ | compound | inj₁ l'ᵢ⋘r' = inj₁ (⋙l y y' l≃r l'ᵢ⋘r' l⋗r')
... | node right _ _ _ | compound | inj₂ ()
... | node perfect _ _ _ | compound | inj₂ l'ᵢ⋗r' = inj₁ (⋙r y y' l≃r (⋙p l'ᵢ⋗r') (lemma-*⋗ l⋗r' l'ᵢ⋗r'))
... | node perfect _ _ _ | compound | inj₁ ()
lemma-insert-⋙ x (⋙r {r' = r'} y y' l≃r l'⋙r' l≃l')
with tot≤ x y'
... | inj₁ x≤y'
with insert y' r' | lemma-insert-compound y' r' | lemma-insert-⋙ y' l'⋙r' | lemma-⋙-⊥ y' l'⋙r'
... | node left _ _ _ | compound | inj₁ l'⋙r'ᵢ | _ = inj₁ (⋙r y x l≃r l'⋙r'ᵢ l≃l')
... | node left _ _ _ | compound | inj₂ () | _
... | node right _ _ _ | compound | inj₁ l'⋙r'ᵢ | _ = inj₁ (⋙r y x l≃r l'⋙r'ᵢ l≃l')
... | node right _ _ _ | compound | inj₂ () | _
... | node perfect _ _ _ | compound | inj₂ l'≃r'ᵢ | _ = inj₂ (≃nd y x l≃r l'≃r'ᵢ l≃l')
... | node perfect _ _ _ | compound | inj₁ (⋙p l'⋗r'ᵢ) | lemma-⋙-⊥'
with lemma-⋙-⊥' l'⋗r'ᵢ
... | ()
lemma-insert-⋙ x (⋙r {r' = r'} y y' l≃r l'⋙r' l≃l') | inj₂ y'≤x
with insert x r' | lemma-insert-compound x r' | lemma-insert-⋙ x l'⋙r' | lemma-⋙-⊥ x l'⋙r'
... | node left _ _ _ | compound | inj₁ l'⋙r'ᵢ | _ = inj₁ (⋙r y y' l≃r l'⋙r'ᵢ l≃l')
... | node left _ _ _ | compound | inj₂ () | _
... | node right _ _ _ | compound | inj₁ l'⋙r'ᵢ | _ = inj₁ (⋙r y y' l≃r l'⋙r'ᵢ l≃l')
... | node right _ _ _ | compound | inj₂ () | _
... | node perfect _ _ _ | compound | inj₂ l'≃r'ᵢ | _ = inj₂ (≃nd y y' l≃r l'≃r'ᵢ l≃l')
... | node perfect _ _ _ | compound | inj₁ (⋙p l'⋗r'ᵢ) | lemma-⋙-⊥'
with lemma-⋙-⊥' l'⋗r'ᵢ
... | ()
lemma-insert-complete : {t : PLRTree}(x : A) → Complete t → Complete (insert x t)
lemma-insert-complete x leaf = perfect x leaf leaf ≃lf
lemma-insert-complete x (perfect {l} {r} y cl cr l≃r)
with tot≤ x y | l | r | l≃r | lemma-insert-complete y cl | lemma-insert-complete x cl
... | inj₁ x≤y | leaf | leaf | ≃lf | _ | _ = right x (perfect y cr cr ≃lf) cr (⋙p (⋗lf y))
... | inj₁ x≤y | node perfect z' _ _ | node perfect z'' _ _ | ≃nd .z' .z'' l'≃r' l''≃r'' l'≃l'' | clᵢ | _ = left x clᵢ cr (lemma-insert-≃ compound (≃nd z' z'' l'≃r' l''≃r'' l'≃l''))
... | inj₂ y≤x | leaf | leaf | ≃lf | _ | _ = right y (perfect x cr cr ≃lf) cr (⋙p (⋗lf x))
... | inj₂ y≤x | node perfect z' _ _ | node perfect z'' _ _ | ≃nd .z' .z'' l'≃r' l''≃r'' l'≃l'' | _ | clᵢ = left y clᵢ cr (lemma-insert-≃ compound (≃nd z' z'' l'≃r' l''≃r'' l'≃l''))
lemma-insert-complete x (left {l} {r} y cl cr l⋘r)
with tot≤ x y
... | inj₁ x≤y
with insert y l | lemma-insert-complete y cl | lemma-insert-⋘ y l⋘r | lemma-insert-compound y l
... | node left _ _ _ | clᵢ | inj₁ lᵢ⋘r | compound = left x clᵢ cr lᵢ⋘r
... | node right _ _ _ | clᵢ | inj₁ lᵢ⋘r | compound = left x clᵢ cr lᵢ⋘r
... | node left _ _ _ | _ | inj₂ () | compound
... | node right _ _ _ | _ | inj₂ () | compound
... | node perfect _ _ _ | clᵢ | inj₂ lᵢ⋗r | compound = right x clᵢ cr (⋙p lᵢ⋗r)
... | node perfect x' l' r' | perfect .x' cl' cr' l'≃r' | inj₁ () | compound
lemma-insert-complete x (left {l} {r} y cl cr l⋘r) | inj₂ y≤x
with insert x l | lemma-insert-complete x cl | lemma-insert-⋘ x l⋘r | lemma-insert-compound x l
... | node left _ _ _ | clᵢ | inj₁ lᵢ⋘r | compound = left y clᵢ cr lᵢ⋘r
... | node right _ _ _ | clᵢ | inj₁ lᵢ⋘r | compound = left y clᵢ cr lᵢ⋘r
... | node left _ _ _ | _ | inj₂ () | compound
... | node right _ _ _ | _ | inj₂ () | compound
... | node perfect _ _ _ | clᵢ | inj₂ lᵢ⋗r | compound = right y clᵢ cr (⋙p lᵢ⋗r)
... | node perfect x' l' r' | perfect .x' cl' cr' l'≃r' | inj₁ () | compound
lemma-insert-complete x (right {l} {r} y cl cr l⋙r)
with tot≤ x y
... | inj₁ x≤y
with insert y r | lemma-insert-complete y cr | lemma-insert-⋙ y l⋙r | lemma-insert-compound y r | lemma-⋙-⊥ y l⋙r
... | node left _ _ _ | crᵢ | inj₁ l⋙rᵢ | compound | _ = right x cl crᵢ l⋙rᵢ
... | node right _ _ _ | crᵢ | inj₁ l⋙rᵢ | compound | _ = right x cl crᵢ l⋙rᵢ
... | node left _ _ _ | _ | inj₂ () | compound | _
... | node right _ _ _ | _ | inj₂ () | compound | _
... | node perfect _ _ _ | crᵢ | inj₂ l≃rᵢ | compound | _ = perfect x cl crᵢ l≃rᵢ
... | node perfect x'' l'' r'' | perfect .x'' cl'' cr'' l''≃r'' | inj₁ (⋙p l⋗rᵢ) | compound | lemma-⋙-⊥'
with lemma-⋙-⊥' l⋗rᵢ
... | ()
lemma-insert-complete x (right {l} {r} y cl cr l⋙r) | inj₂ y≤x
with insert x r | lemma-insert-complete x cr | lemma-insert-⋙ x l⋙r | lemma-insert-compound x r | lemma-⋙-⊥ x l⋙r
... | node left _ _ _ | crᵢ | inj₁ l⋙rᵢ | compound | _ = right y cl crᵢ l⋙rᵢ
... | node right _ _ _ | crᵢ | inj₁ l⋙rᵢ | compound | _ = right y cl crᵢ l⋙rᵢ
... | node left _ _ _ | _ | inj₂ () | compound | _
... | node right _ _ _ | _ | inj₂ () | compound | _
... | node perfect _ _ _ | crᵢ | inj₂ l≃rᵢ | compound | _ = perfect y cl crᵢ l≃rᵢ
... | node perfect x'' l'' r'' | perfect .x'' cl'' cr'' l''≃r'' | inj₁ (⋙p l⋗rᵢ) | compound | lemma-⋙-⊥'
with lemma-⋙-⊥' l⋗rᵢ
... | ()
| 63.836601
| 340
| 0.50041
|
d134905631a17b8205017df8243cd026520b1e73
| 336
|
agda
|
Agda
|
test/Fail/Errors/SnapshotSameDirectory.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Fail/Errors/SnapshotSameDirectory.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Fail/Errors/MissingSnapshotFile.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
-- See the .flags file.
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
postulate
D : Set
_≡_ : D → D → Set
a b : D
postulate p : a ≡ b
{-# ATP axiom p #-}
postulate foo : a ≡ b
{-# ATP prove foo #-}
| 18.666667
| 42
| 0.488095
|
38b632d0a9230175bc9df6b176f685800d8ff9df
| 260
|
agda
|
Agda
|
test/Fail/ScopeIrrelevantRecordField.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/fail/ScopeIrrelevantRecordField.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/ScopeIrrelevantRecordField.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS --no-irrelevant-projections #-}
module ScopeIrrelevantRecordField where
record Bla : Set1 where
constructor mkBla
field
.bla0 bla1 .{bla2 bla3} {bla4 .bla5} : Set
bla0' : Bla -> Set
bla0' = Bla.bla0 -- should fail with bla0 not in scope
| 23.636364
| 55
| 0.7
|
d19830b7765e29cdd8d9547bb5e698fdd16f44fc
| 7,045
|
agda
|
Agda
|
Categories/Category/Equivalence.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Equivalence.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Equivalence.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Equivalence where
-- Strong equivalence of categories. Same as ordinary equivalence in Cat.
-- May not include everything we'd like to think of as equivalences, namely
-- the full, faithful functors that are essentially surjective on objects.
open import Level
open import Relation.Binary using (IsEquivalence; Setoid)
open import Categories.Adjoint.Equivalence
open import Categories.Category
import Categories.Morphism.Reasoning as MR
import Categories.Morphism.Properties as MP
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Properties
open import Categories.NaturalTransformation using (ntHelper; _∘ᵥ_; _∘ˡ_; _∘ʳ_)
open import Categories.NaturalTransformation.NaturalIsomorphism as NI
using (NaturalIsomorphism ; unitorˡ; unitorʳ; associator; _ⓘᵥ_; _ⓘˡ_; _ⓘʳ_)
renaming (sym to ≃-sym)
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
private
variable
o ℓ e : Level
C D E : Category o ℓ e
record WeakInverse (F : Functor C D) (G : Functor D C) : Set (levelOfTerm F ⊔ levelOfTerm G) where
field
F∘G≈id : NaturalIsomorphism (F ∘F G) idF
G∘F≈id : NaturalIsomorphism (G ∘F F) idF
module F∘G≈id = NaturalIsomorphism F∘G≈id
module G∘F≈id = NaturalIsomorphism G∘F≈id
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
-- adjoint equivalence
F⊣G : ⊣Equivalence F G
F⊣G = record
{ unit = ≃-sym G∘F≈id
; counit =
let open D
open HomReasoning
open MR D
open MP D
in record
{ F⇒G = ntHelper record
{ η = λ X → F∘G≈id.⇒.η X ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
; commute = λ {X Y} f → begin
(F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ Y))) ∘ F.F₁ (G.F₁ f)
≈⟨ pull-last (F∘G≈id.⇐.commute (F.F₁ (G.F₁ f))) ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y)) ∘ (F.F₁ (G.F₁ (F.F₁ (G.F₁ f))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X)))
≈˘⟨ refl⟩∘⟨ pushˡ F.homomorphism ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y) C.∘ G.F₁ (F.F₁ (G.F₁ f))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ refl ⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇒.commute (G.F₁ f)) ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G.F₁ f C.∘ G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ refl ⟩∘⟨ F.homomorphism ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η Y ∘ (F.F₁ (G.F₁ f) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ center⁻¹ (F∘G≈id.⇒.commute f) refl ⟩
(f ∘ F∘G≈id.⇒.η X) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ assoc ⟩
f ∘ F∘G≈id.⇒.η X ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
∎
}
; F⇐G = ntHelper record
{ η = λ X → (F∘G≈id.⇒.η (F.F₀ (G.F₀ X)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
; commute = λ {X Y} f → begin
((F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y))) ∘ F∘G≈id.⇐.η Y) ∘ f
≈⟨ pullʳ (F∘G≈id.⇐.commute f) ⟩
(F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y))) ∘ F.F₁ (G.F₁ f) ∘ F∘G≈id.⇐.η X
≈⟨ center (⟺ F.homomorphism) ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y) C.∘ G.F₁ f) ∘ F∘G≈id.⇐.η X
≈⟨ refl ⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇐.commute (G.F₁ f)) ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G.F₁ (F.F₁ (G.F₁ f)) C.∘ G∘F≈id.⇐.η (G.F₀ X)) ∘ F∘G≈id.⇐.η X
≈⟨ refl ⟩∘⟨ F.homomorphism ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ (F.F₁ (G.F₁ (F.F₁ (G.F₁ f))) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
≈⟨ center⁻¹ (F∘G≈id.⇒.commute _) refl ⟩
(F.F₁ (G.F₁ f) ∘ F∘G≈id.⇒.η (F.F₀ (G.F₀ X))) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X)) ∘ F∘G≈id.⇐.η X
≈⟨ center refl ⟩
F.F₁ (G.F₁ f) ∘ (F∘G≈id.⇒.η (F.F₀ (G.F₀ X)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
∎
}
; iso = λ X → Iso-∘ (Iso-∘ (Iso-swap (F∘G≈id.iso _)) ([ F ]-resp-Iso (G∘F≈id.iso _)))
(F∘G≈id.iso X)
}
; zig = λ {A} →
let open D
open HomReasoning
open MR D
in begin
(F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ (F.F₀ A))))
∘ F.F₁ (G∘F≈id.⇐.η A)
≈⟨ pull-last (F∘G≈id.⇐.commute (F.F₁ (G∘F≈id.⇐.η A))) ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A))) ∘
F.F₁ (G.F₁ (F.F₁ (G∘F≈id.⇐.η A))) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈˘⟨ refl⟩∘⟨ pushˡ F.homomorphism ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A)) C.∘ G.F₁ (F.F₁ (G∘F≈id.⇐.η A))) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ refl ⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇒.commute (G∘F≈id.⇐.η A)) ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇐.η A C.∘ G∘F≈id.⇒.η A) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ refl ⟩∘⟨ elimˡ ((F.F-resp-≈ (G∘F≈id.iso.isoˡ _)) ○ F.identity) ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ F∘G≈id.iso.isoʳ _ ⟩
id
∎
}
module F⊣G = ⊣Equivalence F⊣G
record StrongEquivalence {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
F : Functor C D
G : Functor D C
weak-inverse : WeakInverse F G
open WeakInverse weak-inverse public
refl : StrongEquivalence C C
refl = record
{ F = idF
; G = idF
; weak-inverse = record
{ F∘G≈id = unitorˡ
; G∘F≈id = unitorˡ
}
}
sym : StrongEquivalence C D → StrongEquivalence D C
sym e = record
{ F = G
; G = F
; weak-inverse = record
{ F∘G≈id = G∘F≈id
; G∘F≈id = F∘G≈id
}
}
where open StrongEquivalence e
trans : StrongEquivalence C D → StrongEquivalence D E → StrongEquivalence C E
trans {C = C} {D = D} {E = E} e e′ = record
{ F = e′.F ∘F e.F
; G = e.G ∘F e′.G
; weak-inverse = record
{ F∘G≈id = let module S = Setoid (NI.Functor-NI-setoid E E)
in S.trans (S.trans (associator (e.G ∘F e′.G) e.F e′.F)
(e′.F ⓘˡ (unitorˡ ⓘᵥ (e.F∘G≈id ⓘʳ e′.G) ⓘᵥ NI.sym (associator e′.G e.G e.F))))
e′.F∘G≈id
; G∘F≈id = let module S = Setoid (NI.Functor-NI-setoid C C)
in S.trans (S.trans (associator (e′.F ∘F e.F) e′.G e.G)
(e.G ⓘˡ (unitorˡ ⓘᵥ (e′.G∘F≈id ⓘʳ e.F) ⓘᵥ NI.sym (associator e.F e′.F e′.G))))
e.G∘F≈id
}
}
where module e = StrongEquivalence e
module e′ = StrongEquivalence e′
isEquivalence : ∀ {o ℓ e} → IsEquivalence (StrongEquivalence {o} {ℓ} {e})
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
setoid : ∀ o ℓ e → Setoid _ _
setoid o ℓ e = record
{ Carrier = Category o ℓ e
; _≈_ = StrongEquivalence
; isEquivalence = isEquivalence
}
| 40.257143
| 125
| 0.489993
|
30e54c9f65815448b0e61499545369a36899f543
| 9,492
|
agda
|
Agda
|
Cubical/Algebra/ZariskiLattice/BasicOpens.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/ZariskiLattice/BasicOpens.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/ZariskiLattice/BasicOpens.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.ZariskiLattice.BasicOpens where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.CommRing.Localisation.InvertingElements
open import Cubical.Algebra.CommAlgebra.Base
open import Cubical.Algebra.CommAlgebra.Properties
open import Cubical.Algebra.CommAlgebra.Localisation
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.Semilattice
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
open BinaryRelation
open isEquivRel
private
variable
ℓ ℓ' : Level
module Presheaf (A' : CommRing ℓ) where
open CommRingStr (snd A') renaming (_·_ to _·r_ ; ·-comm to ·r-comm ; ·Assoc to ·rAssoc
; ·Lid to ·rLid ; ·Rid to ·rRid)
open Exponentiation A'
open CommRingTheory A'
open isMultClosedSubset
open CommAlgebraStr ⦃...⦄
private
A = fst A'
A[1/_] : A → CommAlgebra A' ℓ
A[1/ x ] = AlgLoc.S⁻¹RAsCommAlg A' ([_ⁿ|n≥0] A' x) (powersFormMultClosedSubset _ _)
A[1/_]ˣ : (x : A) → ℙ (fst A[1/ x ])
A[1/ x ]ˣ = (CommAlgebra→CommRing A[1/ x ]) ˣ
_≼_ : A → A → Type ℓ
x ≼ y = ∃[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y -- rad(x) ⊆ rad(y)
-- ≼ is a pre-order:
Refl≼ : isRefl _≼_
Refl≼ x = PT.∣ 1 , 1r , ·r-comm _ _ ∣
Trans≼ : isTrans _≼_
Trans≼ x y z = map2 Trans≼Σ
where
Trans≼Σ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] y ^ n ≡ a ·r z
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r z
Trans≼Σ (n , a , p) (m , b , q) = n ·ℕ m , (a ^ m ·r b) , path
where
path : x ^ (n ·ℕ m) ≡ a ^ m ·r b ·r z
path = x ^ (n ·ℕ m) ≡⟨ ^-rdist-·ℕ x n m ⟩
(x ^ n) ^ m ≡⟨ cong (_^ m) p ⟩
(a ·r y) ^ m ≡⟨ ^-ldist-· a y m ⟩
a ^ m ·r y ^ m ≡⟨ cong (a ^ m ·r_) q ⟩
a ^ m ·r (b ·r z) ≡⟨ ·rAssoc _ _ _ ⟩
a ^ m ·r b ·r z ∎
R : A → A → Type ℓ
R x y = x ≼ y × y ≼ x -- rad(x) ≡ rad(y)
RequivRel : isEquivRel R
RequivRel .reflexive x = Refl≼ x , Refl≼ x
RequivRel .symmetric _ _ Rxy = (Rxy .snd) , (Rxy .fst)
RequivRel .transitive _ _ _ Rxy Ryz = Trans≼ _ _ _ (Rxy .fst) (Ryz .fst)
, Trans≼ _ _ _ (Ryz .snd) (Rxy .snd)
RpropValued : isPropValued R
RpropValued x y = isProp× isPropPropTrunc isPropPropTrunc
powerIs≽ : (x a : A) → x ∈ ([_ⁿ|n≥0] A' a) → a ≼ x
powerIs≽ x a = map powerIs≽Σ
where
powerIs≽Σ : Σ[ n ∈ ℕ ] (x ≡ a ^ n) → Σ[ n ∈ ℕ ] Σ[ z ∈ A ] (a ^ n ≡ z ·r x)
powerIs≽Σ (n , p) = n , 1r , sym p ∙ sym (·rLid _)
module ≼ToLoc (x y : A) where
private
instance
_ = snd A[1/ x ]
lemma : x ≼ y → y ⋆ 1a ∈ A[1/ x ]ˣ -- y/1 ∈ A[1/x]ˣ
lemma = PT.rec (A[1/ x ]ˣ (y ⋆ 1a) .snd) lemmaΣ
where
path1 : (y z : A) → 1r ·r (y ·r 1r ·r z) ·r 1r ≡ z ·r y
path1 = solve A'
path2 : (xn : A) → xn ≡ 1r ·r 1r ·r (1r ·r 1r ·r xn)
path2 = solve A'
lemmaΣ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y → y ⋆ 1a ∈ A[1/ x ]ˣ
lemmaΣ (n , z , p) = [ z , (x ^ n) , PT.∣ n , refl ∣ ] -- xⁿ≡zy → y⁻¹ ≡ z/xⁿ
, eq/ _ _ ((1r , powersFormMultClosedSubset _ _ .containsOne)
, (path1 _ _ ∙∙ sym p ∙∙ path2 _))
module ≼PowerToLoc (x y : A) (x≼y : x ≼ y) where
private
[yⁿ|n≥0] = [_ⁿ|n≥0] A' y
instance
_ = snd A[1/ x ]
lemma : ∀ (s : A) → s ∈ [yⁿ|n≥0] → s ⋆ 1a ∈ A[1/ x ]ˣ
lemma _ s∈[yⁿ|n≥0] = ≼ToLoc.lemma _ _ (Trans≼ _ y _ x≼y (powerIs≽ _ _ s∈[yⁿ|n≥0]))
𝓞ᴰ : A / R → CommAlgebra A' ℓ
𝓞ᴰ = rec→Gpd.fun isGroupoidCommAlgebra (λ a → A[1/ a ]) RCoh LocPathProp
where
RCoh : ∀ a b → R a b → A[1/ a ] ≡ A[1/ b ]
RCoh a b (a≼b , b≼a) = fst (isContrS₁⁻¹R≡S₂⁻¹R (≼PowerToLoc.lemma _ _ b≼a)
(≼PowerToLoc.lemma _ _ a≼b))
where
open AlgLocTwoSubsets A' ([_ⁿ|n≥0] A' a) (powersFormMultClosedSubset _ _)
([_ⁿ|n≥0] A' b) (powersFormMultClosedSubset _ _)
LocPathProp : ∀ a b → isProp (A[1/ a ] ≡ A[1/ b ])
LocPathProp a b = isPropS₁⁻¹R≡S₂⁻¹R
where
open AlgLocTwoSubsets A' ([_ⁿ|n≥0] A' a) (powersFormMultClosedSubset _ _)
([_ⁿ|n≥0] A' b) (powersFormMultClosedSubset _ _)
-- The quotient A/R corresponds to the basic opens of the Zariski topology.
-- Multiplication lifts to the quotient and corresponds to intersection
-- of basic opens, i.e. we get a meet-semilattice with:
_∧/_ : A / R → A / R → A / R
_∧/_ = setQuotSymmBinOp (RequivRel .reflexive) (RequivRel .transitive) _·r_ ·r-comm ·r-lcoh
where
·r-lcoh-≼ : (x y z : A) → x ≼ y → (x ·r z) ≼ (y ·r z)
·r-lcoh-≼ x y z = map ·r-lcoh-≼Σ
where
path : (x z a y zn : A) → x ·r z ·r (a ·r y ·r zn) ≡ x ·r zn ·r a ·r (y ·r z)
path = solve A'
·r-lcoh-≼Σ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] (x ·r z) ^ n ≡ a ·r (y ·r z)
·r-lcoh-≼Σ (n , a , p) = suc n , (x ·r z ^ n ·r a) , (cong (x ·r z ·r_) (^-ldist-· _ _ _)
∙∙ cong (λ v → x ·r z ·r (v ·r z ^ n)) p
∙∙ path _ _ _ _ _)
·r-lcoh : (x y z : A) → R x y → R (x ·r z) (y ·r z)
·r-lcoh x y z Rxy = ·r-lcoh-≼ x y z (Rxy .fst) , ·r-lcoh-≼ y x z (Rxy .snd)
BasicOpens : Semilattice ℓ
BasicOpens = makeSemilattice [ 1r ] _∧/_ squash/
(elimProp3 (λ _ _ _ → squash/ _ _) λ _ _ _ → cong [_] (·rAssoc _ _ _))
(elimProp (λ _ → squash/ _ _) λ _ → cong [_] (·rRid _))
(elimProp (λ _ → squash/ _ _) λ _ → cong [_] (·rLid _))
(elimProp2 (λ _ _ → squash/ _ _) λ _ _ → cong [_] (·r-comm _ _))
(elimProp (λ _ → squash/ _ _) λ a → eq/ _ _ -- R a a²
(∣ 1 , a , ·rRid _ ∣ , ∣ 2 , 1r , cong (a ·r_) (·rRid a) ∙ sym (·rLid _) ∣))
-- The induced partial order
open MeetSemilattice BasicOpens renaming (_≤_ to _≼/_ ; IndPoset to BasicOpensAsPoset)
-- coincides with our ≼
≼/CoincidesWith≼ : ∀ (x y : A) → [ x ] ≼/ [ y ] ≡ x ≼ y
≼/CoincidesWith≼ x y = [ x ] ≼/ [ y ] -- ≡⟨ refl ⟩ [ x ·r y ] ≡ [ x ]
≡⟨ isoToPath (isEquivRel→effectiveIso RpropValued RequivRel _ _) ⟩
R (x ·r y) x
≡⟨ isoToPath Σ-swap-Iso ⟩
R x (x ·r y)
≡⟨ hPropExt (RpropValued _ _) isPropPropTrunc ·To≼ ≼To· ⟩
x ≼ y ∎
where
x≼xy→x≼yΣ : Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r (x ·r y)
→ Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y
x≼xy→x≼yΣ (n , z , p) = n , (z ·r x) , p ∙ ·rAssoc _ _ _
·To≼ : R x (x ·r y) → x ≼ y
·To≼ (x≼xy , _) = PT.map x≼xy→x≼yΣ x≼xy
x≼y→x≼xyΣ : Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y
→ Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r (x ·r y)
x≼y→x≼xyΣ (n , z , p) = suc n , z , cong (x ·r_) p ∙ ·-commAssocl _ _ _
≼To· : x ≼ y → R x ( x ·r y)
≼To· x≼y = PT.map x≼y→x≼xyΣ x≼y , PT.∣ 1 , y , ·rRid _ ∙ ·r-comm _ _ ∣
open IsPoset
open PosetStr
Refl≼/ : isRefl _≼/_
Refl≼/ = BasicOpensAsPoset .snd .isPoset .is-refl
Trans≼/ : isTrans _≼/_
Trans≼/ = BasicOpensAsPoset .snd .isPoset .is-trans
-- The restrictions:
ρᴰᴬ : (a b : A) → a ≼ b → isContr (CommAlgebraHom A[1/ b ] A[1/ a ])
ρᴰᴬ _ b a≼b = A[1/b]HasUniversalProp _ (≼PowerToLoc.lemma _ _ a≼b)
where
open AlgLoc A' ([_ⁿ|n≥0] A' b) (powersFormMultClosedSubset _ _)
renaming (S⁻¹RHasAlgUniversalProp to A[1/b]HasUniversalProp)
ρᴰᴬId : ∀ (a : A) (r : a ≼ a) → ρᴰᴬ a a r .fst ≡ idAlgHom
ρᴰᴬId a r = ρᴰᴬ a a r .snd _
ρᴰᴬComp : ∀ (a b c : A) (l : a ≼ b) (m : b ≼ c)
→ ρᴰᴬ a c (Trans≼ _ _ _ l m) .fst ≡ ρᴰᴬ a b l .fst ∘a ρᴰᴬ b c m .fst
ρᴰᴬComp a _ c l m = ρᴰᴬ a c (Trans≼ _ _ _ l m) .snd _
ρᴰ : (x y : A / R) → x ≼/ y → CommAlgebraHom (𝓞ᴰ y) (𝓞ᴰ x)
ρᴰ = elimContr2 λ _ _ → isContrΠ
λ [a]≼/[b] → ρᴰᴬ _ _ (transport (≼/CoincidesWith≼ _ _) [a]≼/[b])
ρᴰId : ∀ (x : A / R) (r : x ≼/ x) → ρᴰ x x r ≡ idAlgHom
ρᴰId = SQ.elimProp (λ _ → isPropΠ (λ _ → isSetAlgebraHom _ _ _ _))
λ a r → ρᴰᴬId a (transport (≼/CoincidesWith≼ _ _) r)
ρᴰComp : ∀ (x y z : A / R) (l : x ≼/ y) (m : y ≼/ z)
→ ρᴰ x z (Trans≼/ _ _ _ l m) ≡ ρᴰ x y l ∘a ρᴰ y z m
ρᴰComp = SQ.elimProp3 (λ _ _ _ → isPropΠ2 (λ _ _ → isSetAlgebraHom _ _ _ _))
λ a b c _ _ → sym (ρᴰᴬ a c _ .snd _) ∙ ρᴰᴬComp a b c _ _
| 38.274194
| 95
| 0.533713
|
577fea15f745447d2e424edd31d7c4261e96afda
| 771
|
agda
|
Agda
|
LibraBFT/Impl/Consensus/TestUtils/MockSharedStorage.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Impl/Consensus/TestUtils/MockSharedStorage.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Impl/Consensus/TestUtils/MockSharedStorage.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
import LibraBFT.Base.KVMap as Map
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.Prelude
open import Optics.All
module LibraBFT.Impl.Consensus.TestUtils.MockSharedStorage where
new : ValidatorSet → MockSharedStorage
new = mkMockSharedStorage
Map.empty
Map.empty
Map.empty
nothing
nothing
newObmWithLIWS : ValidatorSet → LedgerInfoWithSignatures → MockSharedStorage
newObmWithLIWS vs obmLIWS =
new vs & mssLis ∙~ Map.singleton (obmLIWS ^∙ liwsVersion) obmLIWS
| 30.84
| 111
| 0.761349
|
ad6db68ea9c8a20712e0c5ae47896270475e3210
| 1,690
|
agda
|
Agda
|
examples/examplesPaperJFP/Object.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/examplesPaperJFP/Object.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/examplesPaperJFP/Object.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module examplesPaperJFP.Object where
open import Data.Product
open import Data.String.Base
open import examplesPaperJFP.NativeIOSafe
open import examplesPaperJFP.BasicIO hiding (main)
open import examplesPaperJFP.Console hiding (main)
record Interface : Set₁ where
field Method : Set
Result : (m : Method) → Set
open Interface public
record Object (I : Interface) : Set where
coinductive
field objectMethod : (m : Method I) → Result I m × Object I
open Object public
record IOObject (Iᵢₒ : IOInterface) (I : Interface) : Set where
coinductive
field method : (m : Method I) → IO Iᵢₒ (Result I m × IOObject Iᵢₒ I)
open IOObject public
data CellMethod A : Set where
get : CellMethod A
put : A → CellMethod A
CellResult : ∀{A} → CellMethod A → Set
CellResult {A} get = A
CellResult (put _) = Unit
cellJ : (A : Set) → Interface
Method (cellJ A) = CellMethod A
Result (cellJ A) m = CellResult m
CellC : Set
CellC = IOObject ConsoleInterface (cellJ String)
simpleCell : (s : String) → CellC
force (method (simpleCell s) get) =
exec′ (putStrLn ("getting (" ++ s ++ ")")) λ _ →
delay (return′ (s , simpleCell s))
force (method (simpleCell s) (put x)) =
exec′ (putStrLn ("putting (" ++ x ++ ")")) λ _ →
delay (return′ (unit , simpleCell x))
{-# TERMINATING #-}
program : IOConsole Unit
force program =
let c₁ = simpleCell "Start" in
exec′ getLine λ{ nothing → return unit; (just s) →
method c₁ (put s) >>= λ{ (_ , c₂) →
method c₂ get >>= λ{ (s′ , _ ) →
exec (putStrLn s′) λ _ →
program }}}
main : NativeIO Unit
main = translateIOConsole program
| 25.223881
| 70
| 0.636686
|
1daf19588ffb675488827f52b9f415a69530341f
| 13,361
|
agda
|
Agda
|
Cubical/Data/DiffInt/Properties.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
Cubical/Data/DiffInt/Properties.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
Cubical/Data/DiffInt/Properties.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.DiffInt.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Data.DiffInt.Base
open import Cubical.Data.Nat as ℕ using (suc; zero; isSetℕ; discreteℕ; ℕ) renaming (_+_ to _+ⁿ_; _·_ to _·ⁿ_)
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Data.Int as Int using (Int; sucInt)
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.Nullary
open import Cubical.HITs.SetQuotients
open BinaryRelation
relIsEquiv : isEquivRel rel
relIsEquiv = equivRel {A = ℕ × ℕ} relIsRefl relIsSym relIsTrans
where
open import Cubical.Data.Nat
relIsRefl : isRefl rel
relIsRefl (a0 , a1) = refl
relIsSym : isSym rel
relIsSym (a0 , a1) (b0 , b1) p = sym p
relIsTrans : isTrans rel
relIsTrans (a0 , a1) (b0 , b1) (c0 , c1) p0 p1 =
inj-m+ {m = (b0 + b1)} ((b0 + b1) + (a0 + c1) ≡⟨ +-assoc (b0 + b1) a0 c1 ⟩
((b0 + b1) + a0) + c1 ≡[ i ]⟨ +-comm b0 b1 i + a0 + c1 ⟩
((b1 + b0) + a0) + c1 ≡[ i ]⟨ +-comm (b1 + b0) a0 i + c1 ⟩
(a0 + (b1 + b0)) + c1 ≡[ i ]⟨ +-assoc a0 b1 b0 i + c1 ⟩
(a0 + b1) + b0 + c1 ≡⟨ sym (+-assoc (a0 + b1) b0 c1) ⟩
(a0 + b1) + (b0 + c1) ≡⟨ cong (λ p → p . fst + p .snd) (transport ΣPath≡PathΣ (p0 , p1))⟩
(b0 + a1) + (c0 + b1) ≡⟨ sym (+-assoc b0 a1 (c0 + b1))⟩
b0 + (a1 + (c0 + b1)) ≡[ i ]⟨ b0 + (a1 + +-comm c0 b1 i) ⟩
b0 + (a1 + (b1 + c0)) ≡[ i ]⟨ b0 + +-comm a1 (b1 + c0) i ⟩
b0 + ((b1 + c0) + a1) ≡[ i ]⟨ b0 + +-assoc b1 c0 a1 (~ i) ⟩
b0 + (b1 + (c0 + a1)) ≡⟨ +-assoc b0 b1 (c0 + a1)⟩
(b0 + b1) + (c0 + a1) ∎ )
relIsProp : BinaryRelation.isPropValued rel
relIsProp a b x y = isSetℕ _ _ _ _
discreteℤ : Discrete ℤ
discreteℤ = discreteSetQuotients (discreteΣ discreteℕ λ _ → discreteℕ) relIsProp relIsEquiv (λ _ _ → discreteℕ _ _)
isSetℤ : isSet ℤ
isSetℤ = Discrete→isSet discreteℤ
sucℤ' : ℕ × ℕ -> ℤ
sucℤ' (a⁺ , a⁻) = [ suc a⁺ , a⁻ ]
sucℤ'-respects-rel : (a b : ℕ × ℕ) → rel a b → sucℤ' a ≡ sucℤ' b
sucℤ'-respects-rel a@(a⁺ , a⁻) b@(b⁺ , b⁻) a~b = eq/ (suc a⁺ , a⁻) (suc b⁺ , b⁻) λ i → suc (a~b i)
sucℤ : ℤ -> ℤ
sucℤ = elim {R = rel} {B = λ _ → ℤ} (λ _ → isSetℤ) sucℤ' sucℤ'-respects-rel
predℤ' : ℕ × ℕ -> ℤ
predℤ' (a⁺ , a⁻) = [ a⁺ , suc a⁻ ]
⟦_⟧ : Int -> ℤ
⟦_⟧ (Int.pos n) = [ n , 0 ]
⟦_⟧ (Int.negsuc n) = [ 0 , suc n ]
fwd = ⟦_⟧
bwd' : ℕ × ℕ -> Int
bwd' (zero , a⁻) = Int.neg a⁻
bwd' (suc a⁺ , a⁻) = sucInt (bwd' (a⁺ , a⁻))
rel-suc : ∀ a⁺ a⁻ → rel (a⁺ , a⁻) (suc a⁺ , suc a⁻)
rel-suc a⁺ a⁻ = ℕ.+-suc a⁺ a⁻
bwd'-suc : ∀ a⁺ a⁻ → bwd' (a⁺ , a⁻) ≡ bwd' (suc a⁺ , suc a⁻)
bwd'-suc zero zero = refl
bwd'-suc zero (suc a⁻) = refl
bwd'-suc (suc a⁺) a⁻ i = sucInt (bwd'-suc a⁺ a⁻ i)
bwd'+ : ∀ m n → bwd' (m , m +ⁿ n) ≡ bwd' (0 , n)
bwd'+ zero n = refl
bwd'+ (suc m) n = sym (bwd'-suc m (m +ⁿ n)) ∙ bwd'+ m n
bwd'-respects-rel : (a b : ℕ × ℕ) → rel a b → bwd' a ≡ bwd' b
bwd'-respects-rel (zero , a⁻) ( b⁺ , b⁻) a~b = sym (bwd'+ b⁺ a⁻) ∙ (λ i → bwd' (b⁺ , a~b (~ i)))
bwd'-respects-rel (suc a⁺ , a⁻) (zero , b⁻) a~b = (λ i → bwd' (suc a⁺ , a~b (~ i))) ∙ sym (bwd'-suc a⁺ (a⁺ +ⁿ b⁻)) ∙ bwd'+ a⁺ b⁻
bwd'-respects-rel (suc a⁺ , a⁻) (suc b⁺ , b⁻) a~b i = sucInt (bwd'-respects-rel (a⁺ , a⁻) (b⁺ , b⁻) (ℕ.inj-m+ {1} {a⁺ +ⁿ b⁻} {b⁺ +ⁿ a⁻} a~b) i)
bwd : ℤ -> Int
bwd = elim {R = rel} {B = λ _ → Int} (λ _ → Int.isSetInt) bwd' bwd'-respects-rel
bwd-fwd : ∀ (x : Int) -> bwd (fwd x) ≡ x
bwd-fwd (Int.pos zero) = refl
bwd-fwd (Int.pos (suc n)) i = sucInt (bwd-fwd (Int.pos n) i)
bwd-fwd (Int.negsuc n) = refl
suc-⟦⟧ : ∀ x → sucℤ ⟦ x ⟧ ≡ ⟦ sucInt x ⟧
suc-⟦⟧ (Int.pos n) = refl
suc-⟦⟧ (Int.negsuc zero) = eq/ {R = rel} (1 , 1) (0 , 0) refl
suc-⟦⟧ (Int.negsuc (suc n)) = eq/ {R = rel} (1 , 2 +ⁿ n) (0 , 1 +ⁿ n) refl
fwd-bwd' : (a : ℕ × ℕ) → fwd (bwd [ a ]) ≡ [ a ]
fwd-bwd' a@(zero , zero) = refl
fwd-bwd' a@(zero , suc a⁻) = refl
fwd-bwd' a@(suc a⁺ , a⁻) = sym (suc-⟦⟧ (bwd [ a⁺ , a⁻ ])) ∙ (λ i → sucℤ (fwd-bwd' (a⁺ , a⁻) i))
fwd-bwd : ∀ (z : ℤ) -> fwd (bwd z) ≡ z
fwd-bwd = elimProp {R = rel} (λ _ → isSetℤ _ _) fwd-bwd'
Int≡ℤ : Int ≡ ℤ
Int≡ℤ = isoToPath (iso fwd bwd fwd-bwd bwd-fwd)
infix 8 -_
infixl 7 _·_
infixl 6 _+_
_+'_ : (a b : ℕ × ℕ) → ℤ
(a⁺ , a⁻) +' (b⁺ , b⁻) = [ a⁺ +ⁿ b⁺ , a⁻ +ⁿ b⁻ ]
private
commˡⁿ : ∀ a b c → a +ⁿ b +ⁿ c ≡ a +ⁿ c +ⁿ b
commˡⁿ a b c = sym (ℕ.+-assoc a b c) ∙ (λ i → a +ⁿ ℕ.+-comm b c i) ∙ ℕ.+-assoc a c b
lem0 : ∀ a b c d → (a +ⁿ b) +ⁿ (c +ⁿ d) ≡ (a +ⁿ c) +ⁿ (b +ⁿ d)
lem0 a b c d = ℕ.+-assoc (a +ⁿ b) c d ∙ (λ i → commˡⁿ a b c i +ⁿ d) ∙ sym (ℕ.+-assoc (a +ⁿ c) b d)
+ⁿ-creates-rel-≡ : ∀ a⁺ a⁻ x → _≡_ {A = ℤ} [ a⁺ , a⁻ ] [ a⁺ +ⁿ x , a⁻ +ⁿ x ]
+ⁿ-creates-rel-≡ a⁺ a⁻ x = eq/ (a⁺ , a⁻) (a⁺ +ⁿ x , a⁻ +ⁿ x) ((λ i → a⁺ +ⁿ ℕ.+-comm a⁻ x i) ∙ ℕ.+-assoc a⁺ x a⁻)
+-respects-relʳ : (a b c : ℕ × ℕ) → rel a b → (a +' c) ≡ (b +' c)
+-respects-relʳ a@(a⁺ , a⁻) b@(b⁺ , b⁻) c@(c⁺ , c⁻) p = eq/ {R = rel} (a⁺ +ⁿ c⁺ , a⁻ +ⁿ c⁻) (b⁺ +ⁿ c⁺ , b⁻ +ⁿ c⁻) (
(a⁺ +ⁿ c⁺) +ⁿ (b⁻ +ⁿ c⁻) ≡⟨ lem0 a⁺ c⁺ b⁻ c⁻ ⟩
(a⁺ +ⁿ b⁻) +ⁿ (c⁺ +ⁿ c⁻) ≡[ i ]⟨ p i +ⁿ (c⁺ +ⁿ c⁻) ⟩
(b⁺ +ⁿ a⁻) +ⁿ (c⁺ +ⁿ c⁻) ≡⟨ sym (lem0 b⁺ c⁺ a⁻ c⁻) ⟩
(b⁺ +ⁿ c⁺) +ⁿ (a⁻ +ⁿ c⁻) ∎)
+-respects-relˡ : (a b c : ℕ × ℕ) → rel b c → (a +' b) ≡ (a +' c)
+-respects-relˡ a@(a⁺ , a⁻) b@(b⁺ , b⁻) c@(c⁺ , c⁻) p = eq/ {R = rel} (a⁺ +ⁿ b⁺ , a⁻ +ⁿ b⁻) (a⁺ +ⁿ c⁺ , a⁻ +ⁿ c⁻) (
(a⁺ +ⁿ b⁺) +ⁿ (a⁻ +ⁿ c⁻) ≡⟨ lem0 a⁺ b⁺ a⁻ c⁻ ⟩
(a⁺ +ⁿ a⁻) +ⁿ (b⁺ +ⁿ c⁻) ≡[ i ]⟨ (a⁺ +ⁿ a⁻) +ⁿ p i ⟩
(a⁺ +ⁿ a⁻) +ⁿ (c⁺ +ⁿ b⁻) ≡⟨ sym (lem0 a⁺ c⁺ a⁻ b⁻) ⟩
(a⁺ +ⁿ c⁺) +ⁿ (a⁻ +ⁿ b⁻) ∎)
_+''_ : ℤ → ℤ → ℤ
_+''_ = rec2 {R = rel} {B = ℤ} φ _+'_ +-respects-relʳ +-respects-relˡ
where abstract φ = isSetℤ
-- normalization of isSetℤ explodes. Therefore we wrap this with expanded cases
_+_ : ℤ → ℤ → ℤ
x@([ _ ]) + y@([ _ ]) = x +'' y
x@([ _ ]) + y@(eq/ _ _ _ _) = x +'' y
x@(eq/ _ _ _ _) + y@([ _ ]) = x +'' y
x@(eq/ _ _ _ _) + y@(eq/ _ _ _ _) = x +'' y
x@(eq/ _ _ _ _) + y@(squash/ a b p q i j) = isSetℤ _ _ (cong (x +_) p) (cong (x +_) q) i j
x@([ _ ]) + y@(squash/ a b p q i j) = isSetℤ _ _ (cong (x +_) p) (cong (x +_) q) i j
x@(squash/ a b p q i j) + y = isSetℤ _ _ (cong (_+ y) p) (cong (_+ y) q) i j
-'_ : ℕ × ℕ → ℤ
-' (a⁺ , a⁻) = [ a⁻ , a⁺ ]
neg-respects-rel'-≡ : (a b : ℕ × ℕ) → rel a b → (-' a) ≡ (-' b)
neg-respects-rel'-≡ a@(a⁺ , a⁻) b@(b⁺ , b⁻) p = eq/ {R = rel} (a⁻ , a⁺) (b⁻ , b⁺) (ℕ.+-comm a⁻ b⁺ ∙ sym p ∙ ℕ.+-comm a⁺ b⁻)
-_ : ℤ → ℤ
-_ = rec {R = rel} {B = ℤ} isSetℤ -'_ neg-respects-rel'-≡
_·'_ : (a b : ℕ × ℕ) → ℤ
(a⁺ , a⁻) ·' (b⁺ , b⁻) = [ a⁺ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ b⁻ , a⁺ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ b⁺ ]
private
lem1 : ∀ a b c d → (a +ⁿ b) +ⁿ (c +ⁿ d) ≡ (a +ⁿ d) +ⁿ (b +ⁿ c)
lem1 a b c d = (λ i → (a +ⁿ b) +ⁿ ℕ.+-comm c d i) ∙ ℕ.+-assoc (a +ⁿ b) d c ∙ (λ i → commˡⁿ a b d i +ⁿ c) ∙ sym (ℕ.+-assoc (a +ⁿ d) b c)
·-respects-relʳ : (a b c : ℕ × ℕ) → rel a b → (a ·' c) ≡ (b ·' c)
·-respects-relʳ a@(a⁺ , a⁻) b@(b⁺ , b⁻) c@(c⁺ , c⁻) p = eq/ {R = rel} (a⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ c⁻ , a⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ c⁺) (b⁺ ·ⁿ c⁺ +ⁿ b⁻ ·ⁿ c⁻ , b⁺ ·ⁿ c⁻ +ⁿ b⁻ ·ⁿ c⁺) (
(a⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ c⁻) +ⁿ (b⁺ ·ⁿ c⁻ +ⁿ b⁻ ·ⁿ c⁺) ≡⟨ lem1 (a⁺ ·ⁿ c⁺) (a⁻ ·ⁿ c⁻) (b⁺ ·ⁿ c⁻) (b⁻ ·ⁿ c⁺) ⟩
(a⁺ ·ⁿ c⁺ +ⁿ b⁻ ·ⁿ c⁺) +ⁿ (a⁻ ·ⁿ c⁻ +ⁿ b⁺ ·ⁿ c⁻) ≡[ i ]⟨ ℕ.·-distribʳ a⁺ b⁻ c⁺ i +ⁿ ℕ.·-distribʳ a⁻ b⁺ c⁻ i ⟩
((a⁺ +ⁿ b⁻) ·ⁿ c⁺) +ⁿ ((a⁻ +ⁿ b⁺) ·ⁿ c⁻) ≡[ i ]⟨ p i ·ⁿ c⁺ +ⁿ (ℕ.+-comm a⁻ b⁺ ∙ sym p ∙ ℕ.+-comm a⁺ b⁻) i ·ⁿ c⁻ ⟩
((b⁺ +ⁿ a⁻) ·ⁿ c⁺) +ⁿ ((b⁻ +ⁿ a⁺) ·ⁿ c⁻) ≡[ i ]⟨ ℕ.·-distribʳ b⁺ a⁻ c⁺ (~ i) +ⁿ ℕ.·-distribʳ b⁻ a⁺ c⁻ (~ i) ⟩
(b⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ c⁺) +ⁿ (b⁻ ·ⁿ c⁻ +ⁿ a⁺ ·ⁿ c⁻) ≡⟨ sym (lem1 (b⁺ ·ⁿ c⁺) (b⁻ ·ⁿ c⁻) (a⁺ ·ⁿ c⁻) (a⁻ ·ⁿ c⁺)) ⟩
(b⁺ ·ⁿ c⁺ +ⁿ b⁻ ·ⁿ c⁻) +ⁿ (a⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ c⁺) ∎)
·-respects-relˡ : (a b c : ℕ × ℕ) → rel b c → (a ·' b) ≡ (a ·' c)
·-respects-relˡ a@(a⁺ , a⁻) b@(b⁺ , b⁻) c@(c⁺ , c⁻) p = eq/ {R = rel} (a⁺ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ b⁻ , a⁺ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ b⁺) (a⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ c⁻ , a⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ c⁺) (
(a⁺ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ b⁻) +ⁿ (a⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ c⁺) ≡⟨ lem0 (a⁺ ·ⁿ b⁺) (a⁻ ·ⁿ b⁻) (a⁺ ·ⁿ c⁻) (a⁻ ·ⁿ c⁺) ⟩
(a⁺ ·ⁿ b⁺ +ⁿ a⁺ ·ⁿ c⁻) +ⁿ (a⁻ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ c⁺) ≡[ i ]⟨ ℕ.·-distribˡ a⁺ b⁺ c⁻ i +ⁿ ℕ.·-distribˡ a⁻ b⁻ c⁺ i ⟩
(a⁺ ·ⁿ (b⁺ +ⁿ c⁻)) +ⁿ (a⁻ ·ⁿ (b⁻ +ⁿ c⁺)) ≡[ i ]⟨ a⁺ ·ⁿ p i +ⁿ a⁻ ·ⁿ (ℕ.+-comm b⁻ c⁺ ∙ sym p ∙ ℕ.+-comm b⁺ c⁻) i ⟩
(a⁺ ·ⁿ (c⁺ +ⁿ b⁻)) +ⁿ (a⁻ ·ⁿ (c⁻ +ⁿ b⁺)) ≡[ i ]⟨ ℕ.·-distribˡ a⁺ c⁺ b⁻ (~ i) +ⁿ ℕ.·-distribˡ a⁻ c⁻ b⁺ (~ i) ⟩
(a⁺ ·ⁿ c⁺ +ⁿ a⁺ ·ⁿ b⁻) +ⁿ (a⁻ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ b⁺) ≡⟨ sym (lem0 (a⁺ ·ⁿ c⁺) (a⁻ ·ⁿ c⁻) (a⁺ ·ⁿ b⁻) (a⁻ ·ⁿ b⁺)) ⟩
(a⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ c⁻) +ⁿ (a⁺ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ b⁺) ∎)
_·''_ : ℤ → ℤ → ℤ
_·''_ = rec2 {R = rel} {B = ℤ} isSetℤ _·'_ ·-respects-relʳ ·-respects-relˡ
-- normalization of isSetℤ explodes. Therefore we wrap this with expanded cases
_·_ : ℤ → ℤ → ℤ
x@([ _ ]) · y@([ _ ]) = x ·'' y
x@([ _ ]) · y@(eq/ _ _ _ _) = x ·'' y
x@(eq/ _ _ _ _) · y@([ _ ]) = x ·'' y
x@(eq/ _ _ _ _) · y@(eq/ _ _ _ _) = x ·'' y
x@(eq/ _ _ _ _) · y@(squash/ a b p q i j) = isSetℤ _ _ (cong (x ·_) p) (cong (x ·_) q) i j
x@([ _ ]) · y@(squash/ a b p q i j) = isSetℤ _ _ (cong (x ·_) p) (cong (x ·_) q) i j
x@(squash/ a b p q i j) · y = isSetℤ _ _ (cong (_· y) p) (cong (_· y) q) i j
+-identityʳ : (x : ℤ) → x + 0 ≡ x
+-identityʳ = elimProp {R = rel} (λ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) i → [ ℕ.+-comm a⁺ 0 i , ℕ.+-comm a⁻ 0 i ] }
+-comm : (x y : ℤ) → x + y ≡ y + x
+-comm = elimProp2 {R = rel} (λ _ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) (b⁺ , b⁻) i → [ ℕ.+-comm a⁺ b⁺ i , ℕ.+-comm a⁻ b⁻ i ] }
+-inverseʳ : (x : ℤ) → x + (- x) ≡ 0
+-inverseʳ = elimProp {R = rel} (λ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) → eq/ {R = rel} (a⁺ +ⁿ a⁻ , a⁻ +ⁿ a⁺) (0 , 0) (ℕ.+-zero (a⁺ +ⁿ a⁻) ∙ ℕ.+-comm a⁺ a⁻) }
+-assoc : (x y z : ℤ) → x + (y + z) ≡ x + y + z
+-assoc = elimProp3 {R = rel} (λ _ _ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) (b⁺ , b⁻) (c⁺ , c⁻) i → [ ℕ.+-assoc a⁺ b⁺ c⁺ i , ℕ.+-assoc a⁻ b⁻ c⁻ i ] }
·-identityʳ : (x : ℤ) → x · 1 ≡ x
·-identityʳ = elimProp {R = rel} (λ _ → isSetℤ _ _) γ
where
γ : (a : ℕ × ℕ) → _
γ (a⁺ , a⁻) i = [ p i , q i ]
where
p : a⁺ ·ⁿ 1 +ⁿ a⁻ ·ⁿ 0 ≡ a⁺
p i = ℕ.+-comm (ℕ.·-identityʳ a⁺ i) (ℕ.0≡m·0 a⁻ (~ i)) i
q : a⁺ ·ⁿ 0 +ⁿ a⁻ ·ⁿ 1 ≡ a⁻
q i = ℕ.0≡m·0 a⁺ (~ i) +ⁿ ℕ.·-identityʳ a⁻ i
·-comm : (x y : ℤ) → x · y ≡ y · x
·-comm = elimProp2 {R = rel} (λ _ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) (b⁺ , b⁻) i → [ ℕ.·-comm a⁺ b⁺ i +ⁿ ℕ.·-comm a⁻ b⁻ i , ℕ.+-comm (ℕ.·-comm a⁺ b⁻ i) (ℕ.·-comm a⁻ b⁺ i) i ] }
·-distribˡ : (x y z : ℤ) → x · (y + z) ≡ x · y + x · z
·-distribˡ = elimProp3 {R = rel} (λ _ _ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) (b⁺ , b⁻) (c⁺ , c⁻) →
[ a⁺ ·ⁿ (b⁺ +ⁿ c⁺) +ⁿ a⁻ ·ⁿ (b⁻ +ⁿ c⁻)
, a⁺ ·ⁿ (b⁻ +ⁿ c⁻) +ⁿ a⁻ ·ⁿ (b⁺ +ⁿ c⁺)
] ≡[ i ]⟨ [ ℕ.·-distribˡ a⁺ b⁺ c⁺ (~ i) +ⁿ ℕ.·-distribˡ a⁻ b⁻ c⁻ (~ i) , ℕ.·-distribˡ a⁺ b⁻ c⁻ (~ i) +ⁿ ℕ.·-distribˡ a⁻ b⁺ c⁺ (~ i) ] ⟩
[ (a⁺ ·ⁿ b⁺ +ⁿ a⁺ ·ⁿ c⁺) +ⁿ (a⁻ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ c⁻)
, (a⁺ ·ⁿ b⁻ +ⁿ a⁺ ·ⁿ c⁻) +ⁿ (a⁻ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ c⁺)
] ≡[ i ]⟨ [ lem0 (a⁺ ·ⁿ b⁺) (a⁻ ·ⁿ b⁻) (a⁺ ·ⁿ c⁺) (a⁻ ·ⁿ c⁻) (~ i), lem0 (a⁺ ·ⁿ b⁻) (a⁺ ·ⁿ c⁻) (a⁻ ·ⁿ b⁺) (a⁻ ·ⁿ c⁺) i ] ⟩
[ a⁺ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ b⁻ +ⁿ (a⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ c⁻)
, a⁺ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ b⁺ +ⁿ (a⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ c⁺)
] ∎
}
·-assoc : (x y z : ℤ) → x · (y · z) ≡ x · y · z
·-assoc = elimProp3 {R = rel} (λ _ _ _ → isSetℤ _ _)
λ{ (a⁺ , a⁻) (b⁺ , b⁻) (c⁺ , c⁻) →
[ a⁺ ·ⁿ (b⁺ ·ⁿ c⁺ +ⁿ b⁻ ·ⁿ c⁻) +ⁿ a⁻ ·ⁿ (b⁺ ·ⁿ c⁻ +ⁿ b⁻ ·ⁿ c⁺)
, a⁺ ·ⁿ (b⁺ ·ⁿ c⁻ +ⁿ b⁻ ·ⁿ c⁺) +ⁿ a⁻ ·ⁿ (b⁺ ·ⁿ c⁺ +ⁿ b⁻ ·ⁿ c⁻)
] ≡[ i ]⟨ [ ℕ.·-distribˡ a⁺ (b⁺ ·ⁿ c⁺) (b⁻ ·ⁿ c⁻) (~ i) +ⁿ ℕ.·-distribˡ a⁻ (b⁺ ·ⁿ c⁻) (b⁻ ·ⁿ c⁺) (~ i)
, ℕ.·-distribˡ a⁺ (b⁺ ·ⁿ c⁻) (b⁻ ·ⁿ c⁺) (~ i) +ⁿ ℕ.·-distribˡ a⁻ (b⁺ ·ⁿ c⁺) (b⁻ ·ⁿ c⁻) (~ i) ] ⟩
[ (a⁺ ·ⁿ (b⁺ ·ⁿ c⁺) +ⁿ a⁺ ·ⁿ (b⁻ ·ⁿ c⁻)) +ⁿ (a⁻ ·ⁿ (b⁺ ·ⁿ c⁻) +ⁿ a⁻ ·ⁿ (b⁻ ·ⁿ c⁺))
, (a⁺ ·ⁿ (b⁺ ·ⁿ c⁻) +ⁿ a⁺ ·ⁿ (b⁻ ·ⁿ c⁺)) +ⁿ (a⁻ ·ⁿ (b⁺ ·ⁿ c⁺) +ⁿ a⁻ ·ⁿ (b⁻ ·ⁿ c⁻))
] ≡[ i ]⟨ [ (ℕ.·-assoc a⁺ b⁺ c⁺ i +ⁿ ℕ.·-assoc a⁺ b⁻ c⁻ i) +ⁿ (ℕ.·-assoc a⁻ b⁺ c⁻ i +ⁿ ℕ.·-assoc a⁻ b⁻ c⁺ i)
, (ℕ.·-assoc a⁺ b⁺ c⁻ i +ⁿ ℕ.·-assoc a⁺ b⁻ c⁺ i) +ⁿ (ℕ.·-assoc a⁻ b⁺ c⁺ i +ⁿ ℕ.·-assoc a⁻ b⁻ c⁻ i) ] ⟩
[ (a⁺ ·ⁿ b⁺ ·ⁿ c⁺ +ⁿ a⁺ ·ⁿ b⁻ ·ⁿ c⁻) +ⁿ (a⁻ ·ⁿ b⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ b⁻ ·ⁿ c⁺)
, (a⁺ ·ⁿ b⁺ ·ⁿ c⁻ +ⁿ a⁺ ·ⁿ b⁻ ·ⁿ c⁺) +ⁿ (a⁻ ·ⁿ b⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ b⁻ ·ⁿ c⁻)
] ≡[ i ]⟨ [ lem1 (a⁺ ·ⁿ b⁺ ·ⁿ c⁺) (a⁺ ·ⁿ b⁻ ·ⁿ c⁻) (a⁻ ·ⁿ b⁺ ·ⁿ c⁻) (a⁻ ·ⁿ b⁻ ·ⁿ c⁺) i
, lem1 (a⁺ ·ⁿ b⁺ ·ⁿ c⁻) (a⁺ ·ⁿ b⁻ ·ⁿ c⁺) (a⁻ ·ⁿ b⁺ ·ⁿ c⁺) (a⁻ ·ⁿ b⁻ ·ⁿ c⁻) i ] ⟩
[ (a⁺ ·ⁿ b⁺ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ b⁻ ·ⁿ c⁺) +ⁿ (a⁺ ·ⁿ b⁻ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ b⁺ ·ⁿ c⁻)
, (a⁺ ·ⁿ b⁺ ·ⁿ c⁻ +ⁿ a⁻ ·ⁿ b⁻ ·ⁿ c⁻) +ⁿ (a⁺ ·ⁿ b⁻ ·ⁿ c⁺ +ⁿ a⁻ ·ⁿ b⁺ ·ⁿ c⁺)
] ≡[ i ]⟨ [ ℕ.·-distribʳ (a⁺ ·ⁿ b⁺) (a⁻ ·ⁿ b⁻) c⁺ i +ⁿ ℕ.·-distribʳ (a⁺ ·ⁿ b⁻) (a⁻ ·ⁿ b⁺) c⁻ i
, ℕ.·-distribʳ (a⁺ ·ⁿ b⁺) (a⁻ ·ⁿ b⁻) c⁻ i +ⁿ ℕ.·-distribʳ (a⁺ ·ⁿ b⁻) (a⁻ ·ⁿ b⁺) c⁺ i ] ⟩
[ (a⁺ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ b⁻) ·ⁿ c⁺ +ⁿ (a⁺ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ b⁺) ·ⁿ c⁻
, (a⁺ ·ⁿ b⁺ +ⁿ a⁻ ·ⁿ b⁻) ·ⁿ c⁻ +ⁿ (a⁺ ·ⁿ b⁻ +ⁿ a⁻ ·ⁿ b⁺) ·ⁿ c⁺
] ∎
}
private
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 6) ]) ≡ true
_ = refl
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 7) ]) ≡ false
_ = refl
| 46.716783
| 163
| 0.411122
|
41942a400ae45bab6f04d1d8f5ae106ae6e8bf81
| 575
|
agda
|
Agda
|
test/Succeed/Issue292-14.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue292-14.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue292-14.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2011-09-14 posted by Nisse
-- Andreas: this failed since SubstHH for Telescopes was wrong.
-- {-# OPTIONS --show-implicit -v tc.lhs.unify:15 #-}
module Issue292-14 where
data D : Set where
d : D
postulate T : D → D → Set
data T′ (x y : D) : Set where
c : T x y → T′ x y
F : D → D → Set
F x d = T′ x d -- blocking unfolding of F x y
record [F] : Set where
field
x y : D
f : F x y -- T′ x y works
data _≡_ (x : [F]) : [F] → Set where
refl : x ≡ x
Foo : ∀ {x} {t₁ t₂ : T x d} →
record { f = c t₁ } ≡ record { f = c t₂ } → Set₁
Foo refl = Set
| 20.535714
| 63
| 0.546087
|
3ddb12ebc6aa8b5b43b0ce8fba6c7ab4085700f9
| 836
|
agda
|
Agda
|
src/Everything.agda
|
andreasabel/ipl
|
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
|
[
"Unlicense"
] | 19
|
2018-05-16T08:08:51.000Z
|
2021-04-27T19:10:49.000Z
|
src/Everything.agda
|
andreasabel/ipl
|
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
|
[
"Unlicense"
] | null | null | null |
src/Everything.agda
|
andreasabel/ipl
|
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
|
[
"Unlicense"
] | 2
|
2018-11-13T16:01:46.000Z
|
2021-02-25T20:39:03.000Z
|
-- Normalization by Evaluation for Intuitionistic Predicate Logic (IPL)
module Everything where
-- Imports from the standard library and simple definitions
import Library
-- Types and terms of IPL
import Formulas
import Derivations
-- Beth model
import TermModel
import NfModel
-- A variant where Cover : PSh → PSh
import NfModelCaseTree -- Presented at ITC 2018-07-19
import NfModelCaseTreeConv
-- A generalization to any CoverMonad which includes the
-- continuation monad used in Danvy's algorithm
import NfModelMonad
import Consistency
-- A monadic interpreter using shift/reset and an optimization
import DanvyShiftReset
import DanvyShiftResetLiftable
-- SET-interpretation and soundness of NbE
import Interpretation
import NbeModel
-- A general theory of sheaves over preorders
import PresheavesAndSheaves
| 19.44186
| 71
| 0.801435
|
43287dfbbdcb28bf67cfc363d73923732b48aae3
| 4,747
|
agda
|
Agda
|
src/Categories/Functor/Monoidal.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Functor/Monoidal.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Functor/Monoidal.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Monoidal where
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Category
open import Categories.Category.Product
open import Categories.Category.Monoidal
open import Categories.Functor hiding (id)
open import Categories.NaturalTransformation hiding (id)
open import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.Morphism as Mor
private
variable
o o′ ℓ ℓ′ e e′ : Level
module _ (C : MonoidalCategory o ℓ e) (D : MonoidalCategory o′ ℓ′ e′) where
private
module C = MonoidalCategory C
module D = MonoidalCategory D
open Mor D.U
-- lax monoidal functor
record IsMonoidalFunctor (F : Functor C.U D.U) : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
open Functor F
field
ε : D.U [ D.unit , F₀ C.unit ]
⊗-homo : NaturalTransformation (D.⊗ ∘F (F ⁂ F)) (F ∘F C.⊗)
module ⊗-homo = NaturalTransformation ⊗-homo
-- coherence condition
open D
open Commutation D.U
field
associativity : ∀ {X Y Z} →
[ (F₀ X ⊗₀ F₀ Y) ⊗₀ F₀ Z ⇒ F₀ (X C.⊗₀ Y C.⊗₀ Z) ]⟨
⊗-homo.η (X , Y) ⊗₁ id ⇒⟨ F₀ (X C.⊗₀ Y) ⊗₀ F₀ Z ⟩
⊗-homo.η (X C.⊗₀ Y , Z) ⇒⟨ F₀ ((X C.⊗₀ Y) C.⊗₀ Z) ⟩
F₁ C.associator.from
≈ associator.from ⇒⟨ F₀ X ⊗₀ F₀ Y ⊗₀ F₀ Z ⟩
id ⊗₁ ⊗-homo.η (Y , Z) ⇒⟨ F₀ X ⊗₀ F₀ (Y C.⊗₀ Z) ⟩
⊗-homo.η (X , Y C.⊗₀ Z)
⟩
unitaryˡ : ∀ {X} →
[ unit ⊗₀ F₀ X ⇒ F₀ X ]⟨
ε ⊗₁ id ⇒⟨ F₀ C.unit ⊗₀ F₀ X ⟩
⊗-homo.η (C.unit , X) ⇒⟨ F₀ (C.unit C.⊗₀ X) ⟩
F₁ C.unitorˡ.from
≈ unitorˡ.from
⟩
unitaryʳ : ∀ {X} →
[ F₀ X ⊗₀ unit ⇒ F₀ X ]⟨
id ⊗₁ ε ⇒⟨ F₀ X ⊗₀ F₀ C.unit ⟩
⊗-homo.η (X , C.unit) ⇒⟨ F₀ (X C.⊗₀ C.unit) ⟩
F₁ C.unitorʳ.from
≈ unitorʳ.from
⟩
record MonoidalFunctor : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
F : Functor C.U D.U
isMonoidal : IsMonoidalFunctor F
open Functor F public
open IsMonoidalFunctor isMonoidal public
-- strong monoidal functor
record IsStrongMonoidalFunctor (F : Functor C.U D.U) : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
open Functor F
field
ε : D.unit ≅ F₀ C.unit
⊗-homo : D.⊗ ∘F (F ⁂ F) ≃ F ∘F C.⊗
module ε = _≅_ ε
module ⊗-homo = NaturalIsomorphism ⊗-homo
-- coherence condition
open D
open Commutation D.U
field
associativity : ∀ {X Y Z} →
[ (F₀ X ⊗₀ F₀ Y) ⊗₀ F₀ Z ⇒ F₀ (X C.⊗₀ Y C.⊗₀ Z) ]⟨
⊗-homo.⇒.η (X , Y) ⊗₁ id ⇒⟨ F₀ (X C.⊗₀ Y) ⊗₀ F₀ Z ⟩
⊗-homo.⇒.η (X C.⊗₀ Y , Z) ⇒⟨ F₀ ((X C.⊗₀ Y) C.⊗₀ Z) ⟩
F₁ C.associator.from
≈ associator.from ⇒⟨ F₀ X ⊗₀ F₀ Y ⊗₀ F₀ Z ⟩
id ⊗₁ ⊗-homo.⇒.η (Y , Z) ⇒⟨ F₀ X ⊗₀ F₀ (Y C.⊗₀ Z) ⟩
⊗-homo.⇒.η (X , Y C.⊗₀ Z)
⟩
unitaryˡ : ∀ {X} →
[ unit ⊗₀ F₀ X ⇒ F₀ X ]⟨
ε.from ⊗₁ id ⇒⟨ F₀ C.unit ⊗₀ F₀ X ⟩
⊗-homo.⇒.η (C.unit , X) ⇒⟨ F₀ (C.unit C.⊗₀ X) ⟩
F₁ C.unitorˡ.from
≈ unitorˡ.from
⟩
unitaryʳ : ∀ {X} →
[ F₀ X ⊗₀ unit ⇒ F₀ X ]⟨
id ⊗₁ ε.from ⇒⟨ F₀ X ⊗₀ F₀ C.unit ⟩
⊗-homo.⇒.η (X , C.unit) ⇒⟨ F₀ (X C.⊗₀ C.unit) ⟩
F₁ C.unitorʳ.from
≈ unitorʳ.from
⟩
isMonoidal : IsMonoidalFunctor F
isMonoidal = record
{ ε = ε.from
; ⊗-homo = ⊗-homo.F⇒G
; associativity = associativity
; unitaryˡ = unitaryˡ
; unitaryʳ = unitaryʳ
}
record StrongMonoidalFunctor : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
F : Functor C.U D.U
isStrongMonoidal : IsStrongMonoidalFunctor F
open Functor F public
open IsStrongMonoidalFunctor isStrongMonoidal public
monoidalFunctor : MonoidalFunctor
monoidalFunctor = record { F = F ; isMonoidal = isMonoidal }
| 35.162963
| 98
| 0.429745
|
d1c97a2ce6053c7a5b6190e81da9fa0b00ac8342
| 2,075
|
agda
|
Agda
|
Cubical/Data/Vec/Properties.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Data/Vec/Properties.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Data/Vec/Properties.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Data.Vec.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat
open import Cubical.Data.Vec.Base
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
private
variable
ℓ : Level
A : Type ℓ
-- This is really cool!
-- Compare with: https://github.com/agda/agda-stdlib/blob/master/src/Data/Vec/Properties/WithK.agda#L32
++-assoc : ∀ {m n k} (xs : Vec A m) (ys : Vec A n) (zs : Vec A k) →
PathP (λ i → Vec A (+-assoc m n k (~ i))) ((xs ++ ys) ++ zs) (xs ++ ys ++ zs)
++-assoc {m = zero} [] ys zs = refl
++-assoc {m = suc m} (x ∷ xs) ys zs i = x ∷ ++-assoc xs ys zs i
-- Equivalence between Fin n → A and Vec A n
FinVec : (A : Type ℓ) (n : ℕ) → Type ℓ
FinVec A n = Fin n → A
FinVec→Vec : {n : ℕ} → FinVec A n → Vec A n
FinVec→Vec {n = zero} xs = []
FinVec→Vec {n = suc _} xs = xs zero ∷ FinVec→Vec (λ x → xs (suc x))
Vec→FinVec : {n : ℕ} → Vec A n → FinVec A n
Vec→FinVec xs f = lookup f xs
FinVec→Vec→FinVec : {n : ℕ} (xs : FinVec A n) → Vec→FinVec (FinVec→Vec xs) ≡ xs
FinVec→Vec→FinVec {n = zero} xs = funExt λ f → ⊥.rec (¬Fin0 f)
FinVec→Vec→FinVec {n = suc n} xs = funExt goal
where
goal : (f : Fin (suc n))
→ Vec→FinVec (xs zero ∷ FinVec→Vec (λ x → xs (suc x))) f ≡ xs f
goal zero = refl
goal (suc f) i = FinVec→Vec→FinVec (λ x → xs (suc x)) i f
Vec→FinVec→Vec : {n : ℕ} (xs : Vec A n) → FinVec→Vec (Vec→FinVec xs) ≡ xs
Vec→FinVec→Vec {n = zero} [] = refl
Vec→FinVec→Vec {n = suc n} (x ∷ xs) i = x ∷ Vec→FinVec→Vec xs i
FinVecIsoVec : (n : ℕ) → Iso (FinVec A n) (Vec A n)
FinVecIsoVec n = iso FinVec→Vec Vec→FinVec Vec→FinVec→Vec FinVec→Vec→FinVec
FinVec≃Vec : (n : ℕ) → FinVec A n ≃ Vec A n
FinVec≃Vec n = isoToEquiv (FinVecIsoVec n)
FinVec≡Vec : (n : ℕ) → FinVec A n ≡ Vec A n
FinVec≡Vec n = ua (FinVec≃Vec n)
isContrVec0 : isContr (Vec A 0)
isContrVec0 = [] , λ { [] → refl }
| 31.923077
| 103
| 0.626506
|
034b6d4f1dcda6a5d3cd942d0720aec4949afc45
| 496
|
agda
|
Agda
|
test/fail/RecordConstructorsInErrorMessages.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/fail/RecordConstructorsInErrorMessages.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/RecordConstructorsInErrorMessages.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- This file tests that record constructors are used in error
-- messages, if possible.
module RecordConstructorsInErrorMessages where
record R : Set₁ where
constructor con
field
{A} : Set
f : A → A
{B C} D {E} : Set
g : B → C → E
postulate
A : Set
r₁ : R
r₂ : R
r₂ = record
{ A = A
; f = λ x → x
; B = A
; C = A
; D = A
; g = λ x _ → x
}
data _≡_ {A : Set₁} (x : A) : A → Set where
refl : x ≡ x
foo : r₁ ≡ r₂
foo = refl
| 15.030303
| 61
| 0.504032
|
4bbb29d51eeae6bf932e92594cc3e3d74d2d4b24
| 1,130
|
agda
|
Agda
|
src/sets/fin/core.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 20
|
2015-06-12T12:20:17.000Z
|
2022-02-01T11:25:54.000Z
|
src/sets/fin/core.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
src/sets/fin/core.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 sets.fin.core where
open import decidable
open import equality.core
open import sets.empty
open import sets.unit public
open import sets.nat.core
hiding (_≟_; pred)
open import sets.empty
data Fin : ℕ → Set where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} → Fin n → Fin (suc n)
raise : ∀ {n} → Fin n → Fin (suc n)
raise zero = zero
raise (suc i) = suc (raise i)
fin-disj : ∀ {n}(i : Fin n) → ¬ (zero ≡ suc i)
fin-disj {n} i = J' P tt (suc i)
where
P : (i : Fin (suc n)) → zero ≡ i → Set
P zero _ = ⊤
P (suc _) _ = ⊥
fin-suc-inj : ∀ {n} {i j : Fin n} → Fin.suc i ≡ suc j → i ≡ j
fin-suc-inj {n}{i}{j} = J' P refl (suc j)
where
P : (j : Fin (suc n)) → Fin.suc i ≡ j → Set
P zero _ = ⊤
P (suc j) _ = i ≡ j
_≟_ : ∀ {n} → (i j : Fin n) → Dec (i ≡ j)
_≟_ zero zero = yes refl
_≟_ zero (suc i) = no (fin-disj i)
_≟_ (suc i) zero = no (λ p → fin-disj i (sym p))
_≟_ {suc n} (suc i) (suc j) with i ≟ j
... | yes p = yes (ap suc p)
... | no a = no (λ p → a (fin-suc-inj p))
last-fin : {n : ℕ} → Fin (suc n)
last-fin {zero} = zero
last-fin {suc n} = suc last-fin
| 25.111111
| 61
| 0.538053
|
1e31af15ae24341e863925dcba5fd65a287a2a2c
| 498
|
agda
|
Agda
|
test/Succeed/Issue1221.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1221.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1221.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Common.Level
open import Common.Reflection
open import Common.Equality
open import Common.Prelude
postulate
f : ∀ a → Set a
pattern expectedType =
pi (vArg (def (quote Level) []))
(abs "a" (sort (set (var 0 []))))
ok : ⊤
ok = _
notOk : String
notOk = "not ok"
macro
isExpected : QName → Tactic
isExpected x hole =
bindTC (getType x) λ
{ expectedType → give (quoteTerm ok) hole
; t → give (quoteTerm notOk) hole }
thm : ⊤
thm = isExpected f
| 17.172414
| 50
| 0.63253
|
2e70963423a3796f1dadd782955c18048267fc97
| 1,509
|
agda
|
Agda
|
agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Parameters.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Parameters.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Parameters.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bundles of parameters for passing to the Ring Solver
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- This module packages up all the stuff that's passed to the other
-- modules in a convenient form.
module Tactic.RingSolver.Core.Polynomial.Parameters where
open import Algebra.Bundles using (RawRing)
open import Data.Bool.Base using (Bool; T)
open import Function
open import Level
open import Relation.Unary
open import Tactic.RingSolver.Core.AlmostCommutativeRing
-- This record stores all the stuff we need for the coefficients:
--
-- * A raw ring
-- * A (decidable) predicate on "zeroeness"
--
-- It's used for defining the operations on the Horner normal form.
record RawCoeff ℓ₁ ℓ₂ : Set (suc (ℓ₁ ⊔ ℓ₂)) where
field
rawRing : RawRing ℓ₁ ℓ₂
isZero : RawRing.Carrier rawRing → Bool
open RawRing rawRing public
-- This record stores the full information we need for converting
-- to the final ring.
record Homomorphism ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Set (suc (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ ℓ₄)) where
field
from : RawCoeff ℓ₁ ℓ₂
to : AlmostCommutativeRing ℓ₃ ℓ₄
module Raw = RawCoeff from
open AlmostCommutativeRing to public
field
morphism : Raw.rawRing -Raw-AlmostCommutative⟶ to
open _-Raw-AlmostCommutative⟶_ morphism renaming (⟦_⟧ to ⟦_⟧ᵣ) public
field
Zero-C⟶Zero-R : ∀ x → T (Raw.isZero x) → 0# ≈ ⟦ x ⟧ᵣ
| 30.795918
| 72
| 0.650099
|
03aeee38b261b17dceda848f7fc71b4e08132a7a
| 3,517
|
agda
|
Agda
|
Cat.agda
|
clarkdm/CS410
|
523a8749f49c914bcd28402116dcbe79a78dbbf4
|
[
"CC0-1.0"
] | null | null | null |
Cat.agda
|
clarkdm/CS410
|
523a8749f49c914bcd28402116dcbe79a78dbbf4
|
[
"CC0-1.0"
] | null | null | null |
Cat.agda
|
clarkdm/CS410
|
523a8749f49c914bcd28402116dcbe79a78dbbf4
|
[
"CC0-1.0"
] | null | null | null |
module Cat where
open import Agda.Primitive
open import CS410-Prelude
open import CS410-Nat
open import CS410-Monoid
open import CS410-Vec
record Cat {k}{l}(O : Set k)(_>>_ : O -> O -> Set l) : Set (lsuc (k ⊔ l)) where
field
-- OPERATIONS ---------------------------------------------------------
iden : {X : O} -> X >> X
comp : {R S T : O} -> S >> T -> R >> S -> R >> T
-- KLUDGE -------------------------------------------------------------
Eq : {S T : O} -> S >> T -> S >> T -> Set l
-- LAWS ---------------------------------------------------------------
idenL : {S T : O}(f : S >> T) -> Eq (comp iden f) f
idenR : {S T : O}(f : S >> T) -> Eq (comp f iden) f
assoc : {Q R S T : O}(f : S >> T)(g : R >> S)(h : Q >> R) ->
Eq (comp f (comp g h)) (comp (comp f g) h)
SetCat : Cat Set (\ S T -> S -> T)
SetCat = record
{ iden = id
; comp = _o_
; Eq = \ f g -> forall x -> f x == g x
; idenL = λ {S} {T} f x → refl
; idenR = λ {S} {T} f x → refl
; assoc = λ {Q} {R} {S} {T} f g h x → refl
}
N>=Cat : Cat Nat _N>=_
N>=Cat = record
{ iden = \ {n} -> N>=refl n
; comp = \ {l}{m}{n} -> N>=trans l m n
; Eq = \ _ _ -> One
; idenL = λ {S} {T} f → <>
; idenR = λ {S} {T} f → <>
; assoc = λ {Q} {R} {S} {T} f g h → <>
} where
N>=refl : (n : Nat) -> n N>= n
N>=refl zero = <>
N>=refl (suc n) = N>=refl n
N>=trans : forall l m n -> m N>= n -> l N>= m -> l N>= n
N>=trans l m zero mn lm = <>
N>=trans l zero (suc n) () lm
N>=trans zero (suc m) (suc n) mn ()
N>=trans (suc l) (suc m) (suc n) mn lm = N>=trans l m n mn lm
MonCat : forall {X} -> Monoid X -> Cat One \ _ _ -> X
MonCat M = record
{ iden = e
; comp = op
; Eq = _==_
; idenL = lunit
; idenR = runit
; assoc = assoc
} where open Monoid M
record Functor {k l}{ObjS : Set k}{_>S>_ : ObjS -> ObjS -> Set l}
{m n}{ObjT : Set m}{_>T>_ : ObjT -> ObjT -> Set n}
(CS : Cat ObjS _>S>_)(CT : Cat ObjT _>T>_)
: Set (lsuc (k ⊔ l ⊔ m ⊔ n)) where
open Cat
field
-- OPERATIONS ---------------------------------------------------------
Map : ObjS -> ObjT
map : {A B : ObjS} -> A >S> B -> Map A >T> Map B
-- LAWS ---------------------------------------------------------------
mapId : {A : ObjS} -> Eq CT (map (iden CS {A})) (iden CT {Map A})
mapComp : {A B C : ObjS}(f : B >S> C)(g : A >S> B) ->
Eq CT (map (comp CS f g)) (comp CT (map f) (map g))
mapEq : {A B : ObjS}{f g : A >S> B} ->
Eq CS f g -> Eq CT (map f) (map g)
data List (X : Set) : Set where -- X scopes over the whole declaration...
[] : List X -- ...so you can use it here...
_::_ : X -> List X -> List X -- ...and here.
infixr 3 _::_
listMap : {A B : Set} → (A → B) → List A → List B
listMap f [] = []
listMap f (a :: as) = f a :: listMap f as
list : Functor SetCat SetCat
list = record
{ Map = List
; map = listMap
; mapId = {!!}
; mapComp = {!!}
; mapEq = {!!}
}
{-
goo : Functor (MonCat +Mon) SetCat
goo = ?
-}
hoo : (X : Set) -> Functor N>=Cat SetCat
hoo X = record
{ Map = Vec X
; map = {!!}
; mapId = {!!}
; mapComp = {!!}
; mapEq = {!!}
}
| 31.972727
| 79
| 0.381291
|
43ad8cd399399439fe0a0465b075ea40fb227a4f
| 3,552
|
agda
|
Agda
|
Agda/03-natural-numbers.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/03-natural-numbers.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/03-natural-numbers.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split #-}
module 03-natural-numbers where
import 02-pi
open 02-pi public
-- Section 3.1 The formal specification of the type of natural numbers
data ℕ : UU lzero where
zero-ℕ : ℕ
succ-ℕ : ℕ → ℕ
{- We define the numbers one-ℕ to ten-ℕ -}
one-ℕ : ℕ
one-ℕ = succ-ℕ zero-ℕ
two-ℕ : ℕ
two-ℕ = succ-ℕ one-ℕ
three-ℕ : ℕ
three-ℕ = succ-ℕ two-ℕ
four-ℕ : ℕ
four-ℕ = succ-ℕ three-ℕ
five-ℕ : ℕ
five-ℕ = succ-ℕ four-ℕ
six-ℕ : ℕ
six-ℕ = succ-ℕ five-ℕ
seven-ℕ : ℕ
seven-ℕ = succ-ℕ six-ℕ
eight-ℕ : ℕ
eight-ℕ = succ-ℕ seven-ℕ
nine-ℕ : ℕ
nine-ℕ = succ-ℕ eight-ℕ
ten-ℕ : ℕ
ten-ℕ = succ-ℕ nine-ℕ
-- Remark 3.1.2
ind-ℕ : {i : Level} {P : ℕ → UU i} → P zero-ℕ → ((n : ℕ) → P n → P(succ-ℕ n)) → ((n : ℕ) → P n)
ind-ℕ p0 pS zero-ℕ = p0
ind-ℕ p0 pS (succ-ℕ n) = pS n (ind-ℕ p0 pS n)
-- Section 3.2 Addition on the natural numbers
-- Definition 3.2.1
add-ℕ : ℕ → ℕ → ℕ
add-ℕ x zero-ℕ = x
add-ℕ x (succ-ℕ y) = succ-ℕ (add-ℕ x y)
add-ℕ' : ℕ → ℕ → ℕ
add-ℕ' m n = add-ℕ n m
-- Exercises
-- Exercise 3.1
min-ℕ : ℕ → (ℕ → ℕ)
min-ℕ zero-ℕ n = zero-ℕ
min-ℕ (succ-ℕ m) zero-ℕ = zero-ℕ
min-ℕ (succ-ℕ m) (succ-ℕ n) = succ-ℕ (min-ℕ m n)
max-ℕ : ℕ → (ℕ → ℕ)
max-ℕ zero-ℕ n = n
max-ℕ (succ-ℕ m) zero-ℕ = succ-ℕ m
max-ℕ (succ-ℕ m) (succ-ℕ n) = succ-ℕ (max-ℕ m n)
-- Exercise 3.2
mul-ℕ : ℕ → (ℕ → ℕ)
mul-ℕ zero-ℕ n = zero-ℕ
mul-ℕ (succ-ℕ m) n = add-ℕ (mul-ℕ m n) n
-- Exercise 3.3
pow-ℕ : ℕ → (ℕ → ℕ)
pow-ℕ m zero-ℕ = one-ℕ
pow-ℕ m (succ-ℕ n) = mul-ℕ m (pow-ℕ m n)
-- Exercise 3.4
factorial : ℕ → ℕ
factorial zero-ℕ = one-ℕ
factorial (succ-ℕ m) = mul-ℕ (succ-ℕ m) (factorial m)
-- Exercise 3.5
_choose_ : ℕ → ℕ → ℕ
zero-ℕ choose zero-ℕ = one-ℕ
zero-ℕ choose succ-ℕ k = zero-ℕ
(succ-ℕ n) choose zero-ℕ = one-ℕ
(succ-ℕ n) choose (succ-ℕ k) = add-ℕ (n choose k) (n choose (succ-ℕ k))
-- Exercise 3.6
Fibonacci : ℕ → ℕ
Fibonacci zero-ℕ = zero-ℕ
Fibonacci (succ-ℕ zero-ℕ) = one-ℕ
Fibonacci (succ-ℕ (succ-ℕ n)) = add-ℕ (Fibonacci n) (Fibonacci (succ-ℕ n))
{- The above definition of the Fibonacci sequence uses Agda's rather strong
pattern matching definitions. Below, we will give a definition of the
Fibonacci sequence in terms of ind-ℕ. In particular, the following is a
solution that can be given in terms of the material in the book.
The problem with defining the Fibonacci sequence using ind-ℕ, is that ind-ℕ
doesn't give us a way to refer to both (F n) and (F (succ-ℕ n)). So, we have
to give a workaround, where we store two values in the Fibonacci sequence
at once.
The basic idea is that we define a sequence of pairs of integers, which will
be consecutive Fibonacci numbers. This would be a function of type
ℕ → ℕ².
Such a function is easy to give with induction, using the map ℕ² → ℕ² that
takes a pair (m,n) to the pair (n,n+m). Starting the iteration with (0,1)
we obtain the Fibonacci sequence by taking the first projection.
However, we haven't defined cartesian products or booleans yet. Therefore
we mimic the above idea, using ℕ → ℕ instead of ℕ². -}
shift-one : ℕ → (ℕ → ℕ) → (ℕ → ℕ)
shift-one n f = ind-ℕ n (λ x y → f x)
shift-two : ℕ → ℕ → (ℕ → ℕ) → (ℕ → ℕ)
shift-two m n f = shift-one m (shift-one n f)
Fibo-zero-ℕ : ℕ → ℕ
Fibo-zero-ℕ = shift-two zero-ℕ one-ℕ (const ℕ ℕ zero-ℕ)
Fibo-succ-ℕ : (ℕ → ℕ) → (ℕ → ℕ)
Fibo-succ-ℕ f =
shift-two (f one-ℕ) (add-ℕ (f one-ℕ) (f zero-ℕ)) (λ x → f (succ-ℕ (succ-ℕ x)))
Fibo-function : ℕ → ℕ → ℕ
Fibo-function =
ind-ℕ
( Fibo-zero-ℕ)
( λ n → Fibo-succ-ℕ)
Fibo : ℕ → ℕ
Fibo k = Fibo-function k zero-ℕ
| 23.064935
| 95
| 0.624155
|
df32c5a5f88ea231eafafeab25496a3779087ff7
| 22,381
|
agda
|
Agda
|
LibraBFT/Yasm/Properties.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Yasm/Properties.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Yasm/Properties.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 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 LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
import LibraBFT.Yasm.Base as LYB
import LibraBFT.Yasm.System as LYS
import LibraBFT.Yasm.Types as LYT
-- This module provides some definitions and properties that facilitate
-- proofs of properties about a distributed system modeled by Yasm.System
-- paramaterized by some SystemParameters.
module LibraBFT.Yasm.Properties
(ℓ-PeerState : Level)
(ℓ-VSFP : Level)
(parms : LYB.SystemTypeParameters ℓ-PeerState)
(iiah : LYB.SystemInitAndHandlers ℓ-PeerState parms)
-- In addition to the parameters used by the rest of the system model, this module
-- needs to relate Members to PKs and PeerIds, so that StepPeerState-AllValidParts
-- can be defined. This enables the application to prove that honest peers sign
-- new messages only for their own public key. The system model does not know that
-- directly.
-- A ValidPartForPK collects the assumptions about what a /part/ in the outputs of an honest verifier
-- satisfies: (i) the epoch field is consistent with the existent epochs and (ii) the verifier is
-- a member of the associated epoch config, and (iii) has the given PK in that epoch.
(ValidSenderForPK : LYS.WithInitAndHandlers.ValidSenderForPK-type ℓ-PeerState ℓ-VSFP parms iiah)
-- A valid part remains valid across state transitions (including cheat steps)
(ValidSenderForPK-stable : LYS.WithInitAndHandlers.ValidSenderForPK-stable-type ℓ-PeerState ℓ-VSFP parms iiah ValidSenderForPK)
where
open LYB.SystemTypeParameters parms
open LYB.SystemInitAndHandlers iiah
open import LibraBFT.Yasm.Base
open import LibraBFT.Yasm.System ℓ-PeerState ℓ-VSFP parms
open WithInitAndHandlers iiah
open import Util.FunctionOverride PeerId _≟PeerId_
-- A few handy properties for transporting information about whether a Signature is ∈BootstrapInfo to
-- another type containing the same signature
transp-∈BootstrapInfo₀ : ∀ {pk p1 p2}
→ (ver1 : WithVerSig {Part} ⦃ Part-sig ⦄ pk p1)
→ (ver2 : WithVerSig {Part} ⦃ Part-sig ⦄ pk p2)
→ ver-signature ver1 ≡ ver-signature ver2
→ ∈BootstrapInfo bootstrapInfo (ver-signature ver1)
→ ∈BootstrapInfo bootstrapInfo (ver-signature ver2)
transp-∈BootstrapInfo₀ ver1 ver2 sigs≡ init = subst (∈BootstrapInfo bootstrapInfo) sigs≡ init
transp-¬∈BootstrapInfo₁ : ∀ {pk pool sig}
→ ¬ ∈BootstrapInfo bootstrapInfo sig
→ (mws : MsgWithSig∈ pk sig pool)
→ ¬ ∈BootstrapInfo bootstrapInfo (ver-signature (msgSigned mws))
transp-¬∈BootstrapInfo₁ ¬init mws rewrite sym (msgSameSig mws) = ¬init
transp-¬∈BootstrapInfo₂ : ∀ {pk sig1 sig2 pool}
→ (mws1 : MsgWithSig∈ pk sig1 pool)
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature (msgSigned mws1)))
→ (mws2 : MsgWithSig∈ pk sig2 pool)
→ sig2 ≡ sig1
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature (msgSigned mws2)))
transp-¬∈BootstrapInfo₂ mws1 ¬init mws2 refl = ¬subst {P = ∈BootstrapInfo bootstrapInfo} ¬init (trans (msgSameSig mws2) (sym (msgSameSig mws1)))
¬cheatForgeNew : ∀ {pid pk vsig st' outs m}{st : SystemState}
→ (sp : StepPeer st pid st' outs)
→ outs ≡ LYT.send m ∷ []
→ (ic : isCheat sp)
→ Meta-Honest-PK pk
→ (mws : MsgWithSig∈ pk vsig ((pid , m) ∷ msgPool st))
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature (msgSigned mws)))
→ MsgWithSig∈ pk vsig (msgPool st)
¬cheatForgeNew {st = st} sc@(step-cheat isch) refl _ hpk mws ¬init
with msg∈pool mws
...| there m∈pool = mkMsgWithSig∈ (msgWhole mws) (msgPart mws) (msg⊆ mws) (msgSender mws) m∈pool (msgSigned mws) (msgSameSig mws)
...| here m∈pool
with cong proj₂ m∈pool
...| refl
with isch (msg⊆ mws) (msgSigned mws) ¬init
...| inj₁ dis = ⊥-elim (hpk dis)
...| inj₂ mws' rewrite msgSameSig mws = mws'
¬cheatForgeNewSig : ∀ {p m sndr pid pk st' outs}{st : SystemState}
→ (r : ReachableSystemState st)
→ (sp : StepPeer st pid st' outs)
→ (ic : isCheat sp)
→ Meta-Honest-PK pk
→ (sig : WithVerSig pk p)
→ p ⊂MsgG m → (sndr , m) ∈ msgPool (StepPeer-post sp)
→ ¬ ∈BootstrapInfo bootstrapInfo (ver-signature sig)
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
¬cheatForgeNewSig {p} {m} {sndr} r (step-cheat chConstraint) ic pkH sig p⊂m m∈pool ¬init
with m∈pool
... | there m∈preSt = mkMsgWithSig∈ m p p⊂m sndr m∈preSt sig refl
... | here refl
with chConstraint p⊂m sig ¬init
... | inj₁ dis = ⊥-elim (pkH dis)
... | inj₂ msv = msv
ValidSenderForPK-stable-* : ∀{st : SystemState}{st' : SystemState}
→ ReachableSystemState st
→ Step* st st' → ∀{part α pk}
→ ValidSenderForPK st part α pk
→ ValidSenderForPK st' part α pk
ValidSenderForPK-stable-* _ step-0 v = v
ValidSenderForPK-stable-* r (step-s {pre = st''} st''reach x) {part} {α} {pk} v =
ValidSenderForPK-stable (Step*-trans r st''reach) x
(ValidSenderForPK-stable-* r st''reach v)
-- We say that an implementation produces only valid parts iff all parts of every message in the
-- output of a 'StepPeerState' are either: (i) a valid new part (i.e., the part is valid and no
-- message with the same signature has been sent previously), or (ii) a message has been sent
-- with the same signature.
StepPeerState-AllValidParts : Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState)
StepPeerState-AllValidParts = ∀{s m part pk outs}{α}{st : SystemState}
→ (r : ReachableSystemState st)
→ Meta-Honest-PK pk
→ (sps : StepPeerState α (msgPool st) (initialised st) (peerStates st α) (s , outs))
→ LYT.send m ∈ outs → part ⊂MsgG m → (ver : WithVerSig pk part)
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature ver))
-- Note that we require that α can send for the PK according to the *post* state. This allows
-- sufficient generality to ensure that a peer can sign and send a message for an epoch even if
-- it changed to the epoch in the same step. If this is too painful, we could require that the
-- peer can sign for the PK already in the prestate, which would require, for example,
-- initialising a peer to be a separate step from sending its first signed message, which in
-- turn could preclude some valid implementations.
→ (ValidSenderForPK (StepPeer-post {pre = st} (step-honest sps)) part α pk × ¬ (MsgWithSig∈ pk (ver-signature ver) (msgPool st)))
⊎ MsgWithSig∈ pk (ver-signature ver) (msgPool st)
-- A /part/ was introduced by a specific step when:
IsValidNewPart : ∀{pre : SystemState}{post : SystemState} → Signature → PK → Step pre post → Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState)
-- said step is a /step-peer/ and
IsValidNewPart {pre} {post} sig pk (step-peer {pid = pid} pstep)
-- the part has never been seen before
= ReachableSystemState pre
× ¬ ∈BootstrapInfo bootstrapInfo sig
× ¬ (MsgWithSig∈ pk sig (msgPool pre))
× Σ (MsgWithSig∈ pk sig (msgPool (StepPeer-post pstep)))
(λ m → msgSender m ≡ pid × initialised post pid ≡ initd × ValidSenderForPK post (msgPart m) (msgSender m) pk)
mwsAndVspk-stable : ∀{st : SystemState}{st' : SystemState}
→ ReachableSystemState st
→ Step* st st'
→ ∀ {pk sig}
→ (mws : MsgWithSig∈ pk sig (msgPool st))
→ initialised st (msgSender mws) ≡ initd
→ ValidSenderForPK st (msgPart mws) (msgSender mws) pk
→ Σ (MsgWithSig∈ pk sig (msgPool st')) λ mws' →
ValidSenderForPK st' (msgPart mws') (msgSender mws') pk
mwsAndVspk-stable {_} {st'} r tr {pk} {sig} mws ini vpk = MsgWithSig∈-Step* tr mws
, subst₂ (λ p s → ValidSenderForPK st' p s pk)
(MsgWithSig∈-Step*-part tr mws)
(MsgWithSig∈-Step*-sender tr mws)
(ValidSenderForPK-stable-* r tr vpk)
-- When we can prove that the implementation provided by 'parms' at the
-- top of this module satisfies 'StepPeerState-AllValidParts', we can
-- prove a number of useful structural properties:
-- TODO-2: Refactor into a file (LibraBFT.Yasm.Properties.Structural) later on
-- if this grows too large.
module Structural (sps-avp : StepPeerState-AllValidParts) where
-- We can unwind the state and highlight the step where a part was
-- originally sent. This 'unwind' function combined with Any-Step-elim
-- enables a powerful form of reasoning. The 'honestVoteEpoch' below
-- exemplifies this well.
unwind : ∀{st : SystemState}(tr : ReachableSystemState st)
→ ∀{p m σ pk} → Meta-Honest-PK pk
→ p ⊂MsgG m → (σ , m) ∈ msgPool st → (ver : WithVerSig pk p)
→ ¬ ∈BootstrapInfo bootstrapInfo (ver-signature ver)
→ Any-Step (IsValidNewPart (ver-signature ver) pk) tr
unwind (step-s tr (step-peer {pid = β} {outs = outs} {pre = pre} sp)) hpk p⊂m m∈sm sig ¬init
with Any-++⁻ (actionsToSentMessages β outs) {msgPool pre} m∈sm
...| inj₂ furtherBack = step-there (unwind tr hpk p⊂m furtherBack sig ¬init)
...| inj₁ thisStep
with sp
...| step-cheat isCheat
with thisStep
...| here refl
with isCheat p⊂m sig ¬init
...| inj₁ abs = ⊥-elim (hpk abs)
...| inj₂ sentb4
with unwind tr {p = msgPart sentb4} hpk (msg⊆ sentb4) (msg∈pool sentb4) (msgSigned sentb4)
(transp-¬∈BootstrapInfo₁ ¬init sentb4)
...| res rewrite msgSameSig sentb4 = step-there res
unwind (step-s tr (step-peer {pid = β} {outs = outs} {pre = pre} sp)) hpk p⊂m m∈sm sig ¬init
| inj₁ thisStep
| step-honest x
with senderMsgPair∈⇒send∈ outs thisStep
...| m∈outs , refl
with sps-avp tr hpk x m∈outs p⊂m sig ¬init
...| inj₂ sentb4 with unwind tr {p = msgPart sentb4} hpk (msg⊆ sentb4) (msg∈pool sentb4) (msgSigned sentb4)
(¬subst {P = ∈BootstrapInfo bootstrapInfo} ¬init (msgSameSig sentb4))
...| res rewrite msgSameSig sentb4 = step-there res
unwind (step-s tr (step-peer {pid = β} {outs = outs} {pre = pre} sp)) {p} hpk p⊂m m∈sm sig ¬init
| inj₁ thisStep
| step-honest x
| m∈outs , refl
| inj₁ (valid-part , notBefore) = step-here tr (tr , ¬init , notBefore , mws∈pool , refl , override-target-≡ , valid-part)
where mws∈pool : MsgWithSig∈ _ (WithSig.signature Part-sig _ (isSigned sig)) (actionsToSentMessages β outs ++ msgPool pre)
mws∈pool = MsgWithSig∈-++ˡ (mkMsgWithSig∈ _ _ p⊂m β thisStep sig refl)
-- Unwind is inconvenient to use by itself because we have to do
-- induction on Any-Step-elim. The 'honestPartValid' property below
-- provides a fairly general result conveniently: for every part
-- verifiable with an honest PK, there is a msg with the same
-- signature that is valid for some pid.
honestPartValid : ∀ {st} → ReachableSystemState st → ∀ {pk nm v sender}
→ Meta-Honest-PK pk
→ v ⊂MsgG nm → (sender , nm) ∈ msgPool st → (ver : WithVerSig pk v)
→ ¬ ∈BootstrapInfo bootstrapInfo (ver-signature ver)
→ Σ (MsgWithSig∈ pk (ver-signature ver) (msgPool st))
(λ msg → (ValidSenderForPK st (msgPart msg) (msgSender msg) pk))
honestPartValid {st} r {pk = pk} hpk v⊂m m∈pool ver ¬init
-- We extract two pieces of important information from the place where the part 'v'
-- was first sent: (a) there is a message with the same signature /in the current pool/
-- and (b) its epoch is less than e.
= Any-Step-elim (λ { {st = step-peer {pid = pid} (step-honest sps)} (preReach , ¬init , ¬sentb4 , new , refl , ini , valid) tr
→ mwsAndVspk-stable (step-s preReach (step-peer (step-honest sps))) tr new ini valid
; {st = step-peer {pid = pid} {pre = pre} (step-cheat {pid} sps)} (preReach , ¬init , ¬sentb4 , new , refl , valid) tr
→ ⊥-elim (¬sentb4 (¬cheatForgeNew {st = pre} (step-cheat sps) refl unit hpk new (transp-¬∈BootstrapInfo₁ ¬init new)))
})
(unwind r hpk v⊂m m∈pool ver ¬init)
-- Unforgeability is also an important property stating that every part that is
-- verified with an honest public key has either been sent by α or is a replay
-- of another message sent before.
ext-unforgeability'
: ∀{α m part pk}{st : SystemState} → ReachableSystemState st
-- If a message m has been sent by α, containing part
→ (α , m) ∈ msgPool st → part ⊂MsgG m
-- And the part can be verified with an honest public key,
→ (sig : WithVerSig pk part) → ¬ ∈BootstrapInfo bootstrapInfo (ver-signature sig)
→ Meta-Honest-PK pk
-- then either the part is a valid part by α (meaning that α can
-- sign the part itself) or a message with the same signature has
-- been sent previously.
→ ValidSenderForPK st part α pk
⊎ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
ext-unforgeability' {part = part} (step-s st (step-peer {pid = β} {outs = outs} {pre = pre} sp)) m∈sm p⊆m sig ¬init hpk
with Any-++⁻ (actionsToSentMessages β outs) {msgPool pre} m∈sm
...| inj₂ furtherBack = MsgWithSig∈-++ʳ <⊎$> ⊎-map (ValidSenderForPK-stable st (step-peer sp)) id
(ext-unforgeability' st furtherBack p⊆m sig ¬init hpk)
...| inj₁ thisStep
with sp
...| step-cheat isCheat
with thisStep
...| here refl
with isCheat p⊆m sig ¬init
...| inj₁ abs = ⊥-elim (hpk abs)
...| inj₂ sentb4 = inj₂ (MsgWithSig∈-++ʳ sentb4)
ext-unforgeability' {α = α} {m = m} {part = part} (step-s st (step-peer {pid = β} {outs = outs} {pre = pre} sp)) m∈sm p⊆m sig ¬init hpk
| inj₁ thisStep
| step-honest x
with senderMsgPair∈⇒send∈ outs thisStep
...| m∈outs , refl = ⊎-map proj₁ MsgWithSig∈-++ʳ (sps-avp st hpk x m∈outs p⊆m sig ¬init)
-- The ext-unforgeability' property can be collapsed in a single clause.
-- TODO-2: so far, ext-unforgeability is used only to get a MsgWithSig∈ that is passed to
-- msgWithSigSentByAuthor, which duplicates some of the reasoning in the proof of
-- ext-unforgeability'; should these properties possibly be combined into one simpler proof?
ext-unforgeability
: ∀{α₀ m part pk}{st : SystemState} → ReachableSystemState st
→ (α₀ , m) ∈ msgPool st → part ⊂MsgG m
→ (sig : WithVerSig pk part) → ¬ ∈BootstrapInfo bootstrapInfo (ver-signature sig)
→ Meta-Honest-PK pk
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
ext-unforgeability {α₀} {m} {st = st} rst m∈sm p⊂m sig ¬init hpk
with ext-unforgeability' rst m∈sm p⊂m sig ¬init hpk
...| inj₁ p
= mkMsgWithSig∈ _ _ p⊂m α₀ m∈sm sig refl
...| inj₂ sentb4 = sentb4
msgWithSigSentByAuthor : ∀ {pk sig}{st : SystemState}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (mws : MsgWithSig∈ pk sig (msgPool st))
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature (msgSigned mws)))
→ (Σ (MsgWithSig∈ pk sig (msgPool st))
λ mws' → ValidSenderForPK st (msgPart mws') (msgSender mws') pk)
msgWithSigSentByAuthor step-0 _ ()
msgWithSigSentByAuthor {pk} {sig} (step-s {pre = pre} preach (step-peer theStep@(step-cheat cheatCons))) hpk mws ¬init
with (¬cheatForgeNew theStep refl unit hpk mws ¬init)
...| mws'
with msgWithSigSentByAuthor preach hpk mws' (transp-¬∈BootstrapInfo₂ mws ¬init (MsgWithSig∈-++ʳ mws') refl)
...| (mws'' , vpb'') = MsgWithSig∈-++ʳ mws'' , ValidSenderForPK-stable preach (step-peer theStep) vpb''
msgWithSigSentByAuthor (step-s {pre = pre} preach theStep@(step-peer {pid = pid} {outs = outs} (step-honest sps))) hpk mws ¬init
with Any-++⁻ (actionsToSentMessages pid outs) {msgPool pre} (msg∈pool mws)
...| inj₂ furtherBack
with msgWithSigSentByAuthor preach hpk (MsgWithSig∈-transp mws furtherBack) ¬init
...| (mws' , vpb') = MsgWithSig∈-++ʳ mws' , ValidSenderForPK-stable preach theStep vpb'
msgWithSigSentByAuthor (step-s {pre = pre} preach theStep@(step-peer {pid = pid} {outs = outs} (step-honest sps))) hpk mws ¬init
| inj₁ thisStep
with senderMsgPair∈⇒send∈ outs thisStep
...| m∈outs , refl
with sps-avp preach hpk sps m∈outs (msg⊆ mws) (msgSigned mws) ¬init
...| inj₁ (vpbα₀ , _) = mws , vpbα₀
...| inj₂ mws'
with msgWithSigSentByAuthor preach hpk mws' (transp-¬∈BootstrapInfo₂ mws ¬init (MsgWithSig∈-++ʳ mws') (msgSameSig mws))
...| (mws'' , vpb'') rewrite sym (msgSameSig mws) = MsgWithSig∈-++ʳ mws'' , ValidSenderForPK-stable preach theStep vpb''
newMsg⊎msgSentB4 : ∀ {pk v m pid sndr s' outs} {st : SystemState}
→ (r : ReachableSystemState st)
→ (stP : StepPeerState pid (msgPool st) (initialised st) (peerStates st pid) (s' , outs))
→ Meta-Honest-PK pk → (sig : WithVerSig pk v)
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig))
→ v ⊂MsgG m
→ (sndr , m) ∈ msgPool (StepPeer-post {pre = st} (step-honest stP))
→ ( LYT.send m ∈ outs
× ValidSenderForPK (StepPeer-post {pre = st} (step-honest stP)) v pid pk
× ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool st)))
⊎ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
newMsg⊎msgSentB4 {pk} {v} {m} {pid} {sndr} {s'} {outs} {st} r stP pkH sig ¬init v⊂m m∈post
with Any-++⁻ (actionsToSentMessages pid outs) m∈post
...| inj₂ m∈preSt = inj₂ (mkMsgWithSig∈ m v v⊂m sndr m∈preSt sig refl)
...| inj₁ nm∈outs
with senderMsgPair∈⇒send∈ outs nm∈outs
...| m∈outs , refl
with sps-avp r pkH stP m∈outs v⊂m sig ¬init
...| inj₁ newVote = inj₁ (m∈outs , newVote)
...| inj₂ msb4 = inj₂ msb4
-- This could potentially be more general, for example covering the whole SystemState, rather than
-- just one peer's state. However, this would put more burden on the user and is not required so
-- far.
CarrierProp : Set (1ℓ ℓ⊔ ℓ-PeerState)
CarrierProp = Part → PeerState → Set
module _ (P : CarrierProp) where
record PropCarrier (pk : PK) (sig : Signature) (st : SystemState) : Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState) where
constructor mkCarrier
field
carrStReach : ReachableSystemState st -- Enables use of invariants when proving that steps preserve carrProp
carrSent : MsgWithSig∈ pk sig (msgPool st)
carrInitd : initialised st (msgSender carrSent) ≡ initd
carrValid : ValidSenderForPK st (msgPart carrSent) (msgSender carrSent) pk
carrProp : P (msgPart carrSent) (peerStates st (msgSender carrSent))
open PropCarrier public
PeerStepPreserves : Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState)
PeerStepPreserves = ∀ {ps' outs pk sig}{pre : SystemState}
→ (r : ReachableSystemState pre)
→ (pc : PropCarrier pk sig pre)
→ (sps : StepPeerState (msgSender (carrSent pc))
(msgPool pre)
(initialised pre)
(peerStates pre (msgSender (carrSent pc)))
(ps' , outs))
→ P (msgPart (carrSent pc)) ps'
module _ (PSP : PeerStepPreserves) where
Carrier-transp : ∀ {pk sig} {pre : SystemState}{post : SystemState}
→ (theStep : Step pre post)
→ PropCarrier pk sig pre
→ PropCarrier pk sig post
Carrier-transp {pk} {pre = pre} {post} theStep@(step-peer {pid = pid} {st'} {pre = .pre} sps) pc@(mkCarrier r mws ini vpk prop)
with step-s r theStep
...| postReach
with sps
...| cheatStep@(step-cheat isch) = mkCarrier postReach (MsgWithSig∈-++ʳ mws)
(trans (cong (λ f → f (msgSender mws)) (cheatStepDNMInitialised cheatStep unit)) ini) -- PeerStates not changed by cheat steps
(ValidSenderForPK-stable {pre} r (step-peer cheatStep) vpk)
(subst (λ ps → P (msgPart mws) (ps (msgSender mws))) (sym (cheatStepDNMPeerStates {pre = pre} (step-cheat isch) unit)) prop)
...| honStep@(step-honest {st = st} sps')
with msgSender mws ≟PeerId pid
...| no neq = mkCarrier postReach (MsgWithSig∈-++ʳ mws) (trans (sym (override-target-≢ neq)) ini)
(ValidSenderForPK-stable {pre} r (step-peer (step-honest sps')) vpk)
(subst (λ ps → P (msgPart mws) ps) (override-target-≢ {f = peerStates pre} neq) prop)
...| yes refl = mkCarrier postReach (MsgWithSig∈-++ʳ mws) override-target-≡
(ValidSenderForPK-stable {part = msgPart mws} {pk = pk} r (step-peer honStep) vpk)
(subst (λ ps → P (msgPart mws) ps) (sym override-target-≡) (PSP r pc sps'))
| 58.897368
| 164
| 0.602207
|
1948d78d3d75ef95a7e58544b7f29f14f73ea431
| 2,857
|
agda
|
Agda
|
src/Optics/Functorial.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Optics/Functorial.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Optics/Functorial.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Category.Functor
open import Data.Maybe
open import Function
open import Level
open import Relation.Binary.PropositionalEquality
module Optics.Functorial where
Lens' : (F : Set → Set) → RawFunctor F → Set → Set → Set
Lens' F _ S A = (A → F A) → S → F S
data Lens (S A : Set) : Set₁ where
lens : ((F : Set → Set)(rf : RawFunctor F) → Lens' F rf S A)
→ Lens S A
private
cf : {A : Set} → RawFunctor {Level.zero} (const A)
cf = record { _<$>_ = λ x x₁ → x₁ }
if : RawFunctor {Level.zero} id
if = record { _<$>_ = λ x x₁ → x x₁ }
-- We can make lenses relatively painlessly without requiring reflection
-- by providing getter and setter functions
mkLens' : ∀ {A B : Set}
→ (B → A)
→ (B → A → B)
→ Lens B A
mkLens' {A} {B} get set =
lens (λ F rf f b → Category.Functor.RawFunctor._<$>_
{F = F} rf
{A = A}
{B = B}
(set b)
(f (get b)))
-- Getter:
-- this is typed as ^\.
_^∙_ : ∀{S A} → S → Lens S A → A
_^∙_ {_} {A} s (lens p) = p (const A) cf id s
-- Setter:
set : ∀{S A} → Lens S A → A → S → S
set (lens p) a s = p id if (const a) s
infixr 4 _∙~_
_∙~_ = set
-- _|>_ is renamed to _&_ by Util.Prelude
set? : ∀{S A} → Lens S (Maybe A) → A → S → S
set? l a s = s |> l ∙~ just a
infixr 4 _?~_
_?~_ = set?
-- Modifier:
over : ∀{S A} → Lens S A → (A → A) → S → S
over (lens p) f s = p id if f s
infixr 4 _%~_
_%~_ = over
-- Composition
infixr 30 _∙_
_∙_ : ∀{S A B} → Lens S A → Lens A B → Lens S B
(lens p) ∙ (lens q) = lens (λ F rf x x₁ → p F rf (q F rf x) x₁)
-- Relation between the same field of two states This most general form allows us to specify a
-- Lens S A, a function A → B, and a relation between two B's, and holds iff the relation holds
-- between the values yielded by applying the Lens to two S's and then applying the function to
-- the results; more specific variants are provided below
_[_]L_f=_at_ : ∀ {ℓ} {S A B : Set} → S → (B → B → Set ℓ) → S → (A → B) → Lens S A → Set ℓ
s₁ [ _~_ ]L s₂ f= f at l = f (s₁ ^∙ l) ~ f (s₂ ^∙ l)
_[_]L_at_ : ∀ {ℓ} {S A} → S → (A → A → Set ℓ) → S → Lens S A → Set ℓ
s₁ [ _~_ ]L s₂ at l = _[_]L_f=_at_ s₁ _~_ s₂ id l
infix 4 _≡L_f=_at_
_≡L_f=_at_ : ∀ {S A B : Set} → (s₁ s₂ : S) → (A → B) → Lens S A → Set
s₁ ≡L s₂ f= f at l = _[_]L_f=_at_ s₁ _≡_ s₂ f l
infix 4 _≡L_at_
_≡L_at_ : ∀ {S A} → (s₁ s₂ : S) → Lens S A → Set
s₁ ≡L s₂ at l = _[_]L_f=_at_ s₁ _≡_ s₂ id l
| 30.72043
| 111
| 0.540077
|
43c5fc6e30173470001f2bc1851aebd66789574d
| 2,442
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/BadPrintf2.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
examples/outdated-and-incorrect/Alonzo/BadPrintf2.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/Alonzo/BadPrintf2.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Printf2 where
import AlonzoPrelude
import PreludeList
import PreludeShow
import PreludeString
import PreludeNat
open AlonzoPrelude
open PreludeList, hiding (_++_)
open PreludeShow
open PreludeString
open PreludeNat
data Unit : Set where
unit : Unit
data Format : Set where
stringArg : Format
natArg : Format
intArg : Format
floatArg : Format
charArg : Format
litChar : Char -> Format
badFormat : Char -> Format
data BadFormat (c:Char) : Set where
format' : List Char -> List Format
format' ('%' :: 's' :: fmt) = stringArg :: format' fmt
format' ('%' :: 'n' :: fmt) = natArg :: format' fmt
-- format' ('%' :: 'd' :: fmt) = intArg :: format' fmt
format' ('%' :: 'f' :: fmt) = floatArg :: format' fmt
format' ('%' :: 'c' :: fmt) = charArg :: format' fmt
format' ('%' :: '%' :: fmt) = litChar '%' :: format' fmt
format' ('%' :: c :: fmt) = badFormat c :: format' fmt
format' (c :: fmt) = litChar c :: format' fmt
format' [] = []
format : String -> List Format
format s = format' (toList s)
-- format : String -> List Format
-- format = format' ∘ toList
Printf' : List Format -> Set
Printf' (stringArg :: fmt) = String × Printf' fmt
Printf' (natArg :: fmt) = Nat × Printf' fmt
Printf' (intArg :: fmt) = Int × Printf' fmt
Printf' (floatArg :: fmt) = Float × Printf' fmt
Printf' (charArg :: fmt) = Char × Printf' fmt
Printf' (badFormat c :: fmt) = BadFormat c
Printf' (litChar _ :: fmt) = Printf' fmt
Printf' [] = Unit × Unit
Printf : String -> Set
Printf fmt = Printf' (format fmt)
printf' : (fmt : List Format) -> Printf' fmt -> String
printf' (stringArg :: fmt) < s | args > = s ++ printf' fmt args
printf' (natArg :: fmt) < n | args > = showNat n ++ printf' fmt args
printf' (intArg :: fmt) < n | args > = showInt n ++ printf' fmt args
printf' (floatArg :: fmt) < x | args > = showFloat x ++ printf' fmt args
printf' (charArg :: fmt) < c | args > = showChar c ++ printf' fmt args
printf' (litChar c :: fmt) args = fromList (c :: []) ++ printf' fmt args
printf' (badFormat _ :: fmt) ()
printf' [] < unit | unit > = ""
-- printf' nil unit = ""
printf : (fmt : String) -> Printf fmt -> String
printf fmt = printf' (format fmt)
testFormat : List Format
testFormat = format ""
testArgs : Printf' testFormat
testArgs = < unit | unit >
mainS : String
mainS = printf "%s" < 42 | unit >
| 29.421687
| 76
| 0.593366
|
03a1c76dd9d39e1b86e9fc0b9ae05703171ba669
| 4,995
|
agda
|
Agda
|
CombinatoryLogic/Equality.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | 1
|
2022-02-28T23:44:42.000Z
|
2022-02-28T23:44:42.000Z
|
CombinatoryLogic/Equality.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | null | null | null |
CombinatoryLogic/Equality.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | null | null | null |
-- Kapitel 1, Abschnitt D (Die Eigenschaften der Gleichheit)
module CombinatoryLogic.Equality where
open import Algebra.Definitions using (Congruent₂; LeftCongruent; RightCongruent)
open import Data.Vec using (Vec; []; _∷_; foldr₁; lookup)
open import Function using (_$_)
open import Relation.Binary using (IsEquivalence; Setoid)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import CombinatoryLogic.Semantics
open import CombinatoryLogic.Syntax
private
-- A lemma used in the proofs of Propositions 1 and 2.
lemma-CQXX : ∀ {X} → ⊢ C ∙ Q ∙ X ∙ X
lemma-CQXX {X} =
let s₁ = ⊢ Π ∙ (W ∙ (C ∙ Q)) [ ax Q ]
s₂ = ⊢ W ∙ (C ∙ Q) ∙ X [ Π s₁ ]
s₃ = ⊢ Q ∙ (W ∙ (C ∙ Q) ∙ X) ∙ (C ∙ Q ∙ X ∙ X) [ W ]
s₄ = ⊢ C ∙ Q ∙ X ∙ X [ Q₁ s₂ s₃ ]
in s₄
-- Satz 1
prop₁ : ∀ {X} → ⊢ Q ∙ X ∙ X
prop₁ {X} = s₆ where
s₄ = ⊢ C ∙ Q ∙ X ∙ X [ lemma-CQXX ]
s₅ = ⊢ Q ∙ (C ∙ Q ∙ X ∙ X) ∙ (Q ∙ X ∙ X) [ C ]
s₆ = ⊢ Q ∙ X ∙ X [ Q₁ s₄ s₅ ]
-- Satz 2
prop₂ : ∀ {X Y} → ⊢ Q ∙ X ∙ Y → ⊢ Q ∙ Y ∙ X
prop₂ {X} {Y} ⊢QXY = s₅ where
s₁ = ⊢ Q ∙ X ∙ Y [ ⊢QXY ]
-- NOTE: Curry's proof contains a mistake: CQXX should be CQXY.
s₂ = ⊢ Q ∙ (C ∙ Q ∙ X ∙ X) ∙ (C ∙ Q ∙ X ∙ Y) [ Q₂ {Z = C ∙ Q ∙ X} s₁ ]
s₃ = ⊢ C ∙ Q ∙ X ∙ X [ lemma-CQXX ]
-- NOTE: Curry's proof uses rule Q, but there is no such rule.
s₄ = ⊢ C ∙ Q ∙ X ∙ Y [ Q₁ s₃ s₂ ]
s₅ = ⊢ Q ∙ Y ∙ X [ Q₁ s₄ C ]
-- Satz 3
prop₃ : ∀ {X Y Z} → ⊢ Q ∙ X ∙ Y → ⊢ Q ∙ Y ∙ Z → ⊢ Q ∙ X ∙ Z
prop₃ {X} {Y} {Z} ⊢QXY ⊢QYZ = s₃ where
s₁ = ⊢ Q ∙ Y ∙ Z [ ⊢QYZ ]
s₂ = ⊢ Q ∙ (Q ∙ X ∙ Y) ∙ (Q ∙ X ∙ Z) [ Q₂ {Z = Q ∙ X} s₁ ]
s₃ = ⊢ Q ∙ X ∙ Z [ Q₁ ⊢QXY s₂ ]
-- Satz 4
prop₄ : ∀ {X Y Z} → ⊢ Q ∙ X ∙ Y → ⊢ Q ∙ (X ∙ Z) ∙ (Y ∙ Z)
prop₄ {X} {Y} {Z} Hp = s₅ where
p₁ = λ {X} → ⊢ Q ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ X) ∙ (B ∙ (W ∙ K) ∙ X ∙ Z) [ C ]
p₂ = λ {X} → ⊢ Q ∙ (B ∙ (W ∙ K) ∙ X ∙ Z) ∙ (W ∙ K ∙ (X ∙ Z)) [ B ]
p₃ = λ {X} → ⊢ Q ∙ (W ∙ K ∙ (X ∙ Z)) ∙ (K ∙ (X ∙ Z) ∙ (X ∙ Z)) [ W ]
p₄ = λ {X} → ⊢ Q ∙ (K ∙ (X ∙ Z) ∙ (X ∙ Z)) ∙ (X ∙ Z) [ K ]
p₅ = λ {X} → ⊢ Q ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ X) ∙ (X ∙ Z) [ prop₃ p₁ $ prop₃ p₂ $ prop₃ p₃ p₄ ]
s₁ = ⊢ Q ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ X) ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ Y) [ Q₂ Hp ]
s₂ = ⊢ Q ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ X) ∙ (X ∙ Z) [ p₅ ]
s₃ = ⊢ Q ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ Y) ∙ (Y ∙ Z) [ p₅ ]
s₄ = ⊢ Q ∙ (X ∙ Z) ∙ (C ∙ (B ∙ (W ∙ K)) ∙ Z ∙ X) [ prop₂ s₂ ]
s₅ = ⊢ Q ∙ (X ∙ Z) ∙ (Y ∙ Z) [ prop₃ s₄ $ prop₃ s₁ s₃ ]
-- Satz 5
prop₅ : ∀ {X Y} → X ≡ Y → ⊢ Q ∙ X ∙ Y
prop₅ {X} {Y} refl = prop₁
-- Satz 6 (first part)
isEquivalence : IsEquivalence _≈_
isEquivalence = record
{ refl = prop₁
; sym = prop₂
; trans = prop₃
}
setoid : Setoid _ _
setoid = record
{ Carrier = Combinator
; _≈_ = _≈_
; isEquivalence = isEquivalence
}
module Reasoning where
module ≈ = IsEquivalence isEquivalence
import Relation.Binary.Reasoning.Base.Single _≈_ ≈.refl ≈.trans as Base
open Base using (begin_; _∎) public
infixr 2 _≈⟨⟩_ step-≈ step-≈˘
_≈⟨⟩_ : ∀ x {y} → x Base.IsRelatedTo y → x Base.IsRelatedTo y
_ ≈⟨⟩ x≈y = x≈y
step-≈ = Base.step-∼
syntax step-≈ x y≈z x≈y = x ≈⟨ x≈y ⟩ y≈z
step-≈˘ : ∀ x {y z} → y Base.IsRelatedTo z → y ≈ x → x Base.IsRelatedTo z
step-≈˘ x y∼z y≈x = x ≈⟨ ≈.sym y≈x ⟩ y∼z
syntax step-≈˘ x y≈z y≈x = x ≈˘⟨ y≈x ⟩ y≈z
-- Satz 6 (second part)
cong : Congruent₂ _≈_ _∙_
cong {X} {X′} {Y} {Y′} ⊢X==X′ ⊢Y==Y′ = s₃ where
s₁ = ⊢ X ∙ Y == X ∙ Y′ [ Q₂ ⊢Y==Y′ ]
s₂ = ⊢ X ∙ Y′ == X′ ∙ Y′ [ prop₄ ⊢X==X′ ]
s₃ = ⊢ X ∙ Y == X′ ∙ Y′ [ prop₃ s₁ s₂ ]
-- congˡ and congʳ follow from cong, but are also just different names for
-- Q₂ and prop₄, respectively.
congˡ : LeftCongruent _≈_ _∙_
congˡ = Q₂
congʳ : RightCongruent _≈_ _∙_
congʳ = prop₄
-- TODO: Satz 7, 8
prop₉ : ∀ {X} → ⊢ I ∙ X == X
prop₉ {X} = begin
I ∙ X ≈⟨⟩
W ∙ K ∙ X ≈⟨ W ⟩
K ∙ X ∙ X ≈⟨ K ⟩
X ∎
where open Reasoning
-- Note after the proof of Satz 9.
S : Combinator
S = B ∙ (B ∙ W) ∙ (B ∙ B ∙ C)
prop-S : ∀ {X} {Y} {Z} → ⊢ S ∙ X ∙ Y ∙ Z == X ∙ Z ∙ (Y ∙ Z)
prop-S {X} {Y} {Z} = begin
S ∙ X ∙ Y ∙ Z ≈⟨⟩
B ∙ (B ∙ W) ∙ (B ∙ B ∙ C) ∙ X ∙ Y ∙ Z ≈⟨ congʳ $ congʳ B ⟩
B ∙ W ∙ (B ∙ B ∙ C ∙ X) ∙ Y ∙ Z ≈⟨ congʳ B ⟩
W ∙ (B ∙ B ∙ C ∙ X ∙ Y) ∙ Z ≈⟨ W ⟩
B ∙ B ∙ C ∙ X ∙ Y ∙ Z ∙ Z ≈⟨ congʳ $ congʳ $ congʳ B ⟩
B ∙ (C ∙ X) ∙ Y ∙ Z ∙ Z ≈⟨ congʳ B ⟩
C ∙ X ∙ (Y ∙ Z) ∙ Z ≈⟨ C ⟩
X ∙ Z ∙ (Y ∙ Z) ∎
where open Reasoning
-- TODO: ⊢ B == S(KS)K, ⊢ C == S(BBS)(KK), ⊢ W == SS(SK), ⊢ I == SKK
| 35.678571
| 111
| 0.411612
|
433a56c7d531a89975bee3a4d67436a7d3190aef
| 16,607
|
agda
|
Agda
|
src/interactive-cmds.agda
|
CarlOlson/cedille
|
f5ce42258b7d9bc66f75cd679c785d6133b82b58
|
[
"MIT"
] | null | null | null |
src/interactive-cmds.agda
|
CarlOlson/cedille
|
f5ce42258b7d9bc66f75cd679c785d6133b82b58
|
[
"MIT"
] | null | null | null |
src/interactive-cmds.agda
|
CarlOlson/cedille
|
f5ce42258b7d9bc66f75cd679c785d6133b82b58
|
[
"MIT"
] | null | null | null |
import cedille-options
module interactive-cmds (options : cedille-options.options) where
open import lib
open import functions
open import cedille-types
open import conversion
open import ctxt
open import general-util
open import monad-instances
open import spans options {id}
open import subst
open import syntax-util
open import to-string options
open import toplevel-state options {IO}
open import untyped-spans options {IO}
open import parser
open import rewriting
open import rename
open import classify options {id}
import spans options {IO} as io-spans
open import datatype-functions
open import elaboration (record options {during-elaboration = ff})
open import elaboration-helpers (record options {during-elaboration = ff})
open import templates
open import erase
private
{- Parsing -}
ll-ind : ∀ {X : language-level → Set} → X ll-term → X ll-type → X ll-kind →
(ll : language-level) → X ll
ll-ind t T k ll-term = t
ll-ind t T k ll-type = T
ll-ind t T k ll-kind = k
ll-lift : language-level → Set
ll-lift = ⟦_⟧ ∘ ll-ind TERM TYPE KIND
ll-ind' : ∀ {X : Σ language-level ll-lift → Set} → (s : Σ language-level ll-lift) → ((t : term) → X (ll-term , t)) → ((T : type) → X (ll-type , T)) → ((k : kind) → X (ll-kind , k)) → X s
ll-ind' (ll-term , t) tf Tf kf = tf t
ll-ind' (ll-type , T) tf Tf kf = Tf T
ll-ind' (ll-kind , k) tf Tf kf = kf k
ll-disambiguate : ctxt → term → maybe type
ll-disambiguate Γ (Var pi x) = ctxt-lookup-type-var Γ x ≫=maybe λ _ → just (TpVar pi x)
ll-disambiguate Γ (App t NotErased t') = ll-disambiguate Γ t ≫=maybe λ T →
just (TpAppt T t')
ll-disambiguate Γ (AppTp t T') = ll-disambiguate Γ t ≫=maybe λ T → just (TpApp T T')
ll-disambiguate Γ (Lam pi KeptLambda pi' x (SomeClass atk) t) =
ll-disambiguate (ctxt-tk-decl pi' x atk Γ) t ≫=maybe λ T →
just (TpLambda pi pi' x atk T)
ll-disambiguate Γ (Parens pi t pi') = ll-disambiguate Γ t
ll-disambiguate Γ (Let pi _ d t) =
ll-disambiguate (Γ' d) t ≫=maybe λ T → just (TpLet pi d T)
where
Γ' : defTermOrType → ctxt
Γ' (DefTerm pi' x (SomeType T) t) = ctxt-term-def pi' localScope OpacTrans x (just t) T Γ
Γ' (DefTerm pi' x NoType t) = ctxt-term-udef pi' localScope OpacTrans x t Γ
Γ' (DefType pi' x k T) = ctxt-type-def pi' localScope OpacTrans x (just T) k Γ
ll-disambiguate Γ t = nothing
parse-string : (ll : language-level) → string → maybe (ll-lift ll)
parse-string ll s = case ll-ind {λ ll → string → Either string (ll-lift ll)}
parseTerm parseType parseKind ll s of λ {(Left e) → nothing; (Right e) → just e}
ttk = "term, type, or kind"
parse-err-msg : (failed-to-parse : string) → (as-a : string) → string
parse-err-msg failed-to-parse "" =
"Failed to parse \\\\\"" ^ failed-to-parse ^ "\\\\\""
parse-err-msg failed-to-parse as-a =
"Failed to parse \\\\\"" ^ failed-to-parse ^ "\\\\\" as a " ^ as-a
infixr 7 _≫nothing_ _-_!_≫parse_ _!_≫error_
_≫nothing_ : ∀{ℓ}{A : Set ℓ} → maybe A → maybe A → maybe A
(nothing ≫nothing m₂) = m₂
(m₁ ≫nothing m₂) = m₁
_-_!_≫parse_ : ∀{A B : Set} → (string → maybe A) → string →
(error-msg : string) → (A → string ⊎ B) → string ⊎ B
(f - s ! e ≫parse f') = maybe-else (inj₁ (parse-err-msg s e)) f' (f s)
_!_≫error_ : ∀{E A B : Set} → maybe A → E → (A → E ⊎ B) → E ⊎ B
(just a ! e ≫error f) = f a
(nothing ! e ≫error f) = inj₁ e
parse-try : ∀ {X : Set} → ctxt → string → maybe
(((ll : language-level) → ll-lift ll → X) → X)
parse-try Γ s =
maybe-map (λ t f → maybe-else (f ll-term t) (f ll-type) (ll-disambiguate Γ t))
(parse-string ll-term s) ≫nothing
maybe-map (λ T f → f ll-type T) (parse-string ll-type s) ≫nothing
maybe-map (λ k f → f ll-kind k) (parse-string ll-kind s)
string-to-𝔹 : string → maybe 𝔹
string-to-𝔹 "tt" = just tt
string-to-𝔹 "ff" = just ff
string-to-𝔹 _ = nothing
parse-ll : string → maybe language-level
parse-ll "term" = just ll-term
parse-ll "type" = just ll-type
parse-ll "kind" = just ll-kind
parse-ll _ = nothing
{- Local Context -}
record lci : Set where
constructor mk-lci
field ll : string; x : var; t : string; T : string; fn : string; pi : posinfo
data 𝕃ₛ {ℓ} (A : Set ℓ) : Set ℓ where
[_]ₛ : A → 𝕃ₛ A
_::ₛ_ : A → 𝕃ₛ A → 𝕃ₛ A
headₛ : ∀ {ℓ} {A : Set ℓ} → 𝕃ₛ A → A
headₛ [ a ]ₛ = a
headₛ (a ::ₛ as) = a
𝕃ₛ-to-𝕃 : ∀ {ℓ} {A : Set ℓ} → 𝕃ₛ A → 𝕃 A
𝕃ₛ-to-𝕃 [ a ]ₛ = [ a ]
𝕃ₛ-to-𝕃 (a ::ₛ as) = a :: 𝕃ₛ-to-𝕃 as
merge-lcis-ctxt : ctxt → 𝕃 string → ctxt
merge-lcis-ctxt c = foldl merge-lcis-ctxt' c ∘ (sort-lcis ∘ strings-to-lcis) where
strings-to-lcis : 𝕃 string → 𝕃 lci
strings-to-lcis ss = strings-to-lcis-h ss [] where
strings-to-lcis-h : 𝕃 string → 𝕃 lci → 𝕃 lci
strings-to-lcis-h (ll :: x :: t :: T :: fn :: pi :: tl) items =
strings-to-lcis-h tl (mk-lci ll x t T fn pi :: items)
strings-to-lcis-h _ items = items
-- TODO: Local context information does not pass Δ information!
-- When users are using BR-explorer to rewrite with the rec function,
-- if they call it upon "μ' [SUBTERM] {...}", it won't work unless they say
-- "μ'<rec/mu> [SUBTERM] {...}".
decl-lci : posinfo → var → ctxt → ctxt
decl-lci pi x (mk-ctxt (fn , mn , ps , q) ss is os Δ) =
mk-ctxt (fn , mn , ps , trie-insert q x (pi % x , [])) ss is os Δ
language-level-type-of : language-level → language-level
language-level-type-of ll-term = ll-type
language-level-type-of _ = ll-kind
merge-lci-ctxt : lci → ctxt → ctxt
merge-lci-ctxt (mk-lci ll v t T fn pi) Γ =
maybe-else Γ (λ Γ → Γ) (parse-ll ll ≫=maybe λ ll →
parse-string (language-level-type-of ll) T ≫=maybe h ll (parse-string ll t)) where
h : (ll : language-level) → maybe (ll-lift ll) →
ll-lift (language-level-type-of ll) → maybe ctxt
h ll-term (just t) T =
just (ctxt-term-def pi localScope OpacTrans v (just t) (qualif-type Γ T) Γ)
h ll-type (just T) k =
just (ctxt-type-def pi localScope OpacTrans v (just T) (qualif-kind Γ k) Γ)
h ll-term nothing T = just (ctxt-term-decl pi v T Γ)
h ll-type nothing k = just (ctxt-type-decl pi v k Γ)
h _ _ _ = nothing
merge-lcis-ctxt' : 𝕃ₛ lci → ctxt → ctxt
merge-lcis-ctxt' ls Γ =
let ls' = 𝕃ₛ-to-𝕃 ls in
foldr (merge-lci-ctxt) (foldr (λ l → decl-lci (lci.pi l) (lci.x l)) Γ ls') ls'
sort-eq : ∀ {ℓ} {A : Set ℓ} → (A → A → compare-t) → 𝕃 A → 𝕃 (𝕃ₛ A)
sort-eq {_} {A} c = foldr insert [] where
insert : A → 𝕃 (𝕃ₛ A) → 𝕃 (𝕃ₛ A)
insert n [] = [ [ n ]ₛ ]
insert n (a :: as) with c (headₛ a) n
...| compare-eq = n ::ₛ a :: as
...| compare-gt = [ n ]ₛ :: a :: as
...| compare-lt = a :: insert n as
sort-lcis : 𝕃 lci → 𝕃 (𝕃ₛ lci) -- 𝕃 lci
sort-lcis = sort-eq λ l₁ l₂ →
compare (posinfo-to-ℕ $ lci.pi l₁) (posinfo-to-ℕ $ lci.pi l₂)
{-
sort-lcis = list-merge-sort.merge-sort lci λ l l' →
posinfo-to-ℕ (lci.pi l) > posinfo-to-ℕ (lci.pi l')
where import list-merge-sort
-}
get-local-ctxt : ctxt → (pos : ℕ) → (local-ctxt : 𝕃 string) → ctxt
get-local-ctxt Γ @ (mk-ctxt (fn , mn , _) _ is _ Δ) pi =
merge-lcis-ctxt (foldr (flip ctxt-clear-symbol ∘ fst) Γ
(flip filter (trie-mappings is) λ {(x , ci , fn' , pi') →
fn =string fn' && posinfo-to-ℕ pi' > pi}))
{- Helpers -}
qualif-ed : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
qualif-ed{TERM} = qualif-term
qualif-ed{TYPE} = qualif-type
qualif-ed{KIND} = qualif-kind
qualif-ed Γ e = e
step-reduce : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
step-reduce Γ t =
let t' = erase t in maybe-else t' id (step-reduceh Γ t') where
step-reduceh : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → maybe ⟦ ed ⟧
step-reduceh{TERM} Γ (Var pi x) = ctxt-lookup-term-var-def Γ (qualif-var Γ x)
step-reduceh{TYPE} Γ (TpVar pi x) = ctxt-lookup-type-var-def Γ (qualif-var Γ x)
step-reduceh{TERM} Γ (App (Lam pi b pi' x oc t) me t') = just (subst Γ t' x t)
step-reduceh{TYPE} Γ (TpApp (TpLambda pi pi' x (Tkk _) T) T') = just (subst Γ T' x T)
step-reduceh{TYPE} Γ (TpAppt (TpLambda pi pi' x (Tkt _) T) t) = just (subst Γ t x T)
step-reduceh{TERM} Γ (App t me t') = step-reduceh Γ t ≫=maybe λ t → just (App t me t')
step-reduceh{TYPE} Γ (TpApp T T') = step-reduceh Γ T ≫=maybe λ T → just (TpApp T T')
step-reduceh{TYPE} Γ (TpAppt T t) = step-reduceh Γ T ≫=maybe λ T → just (TpAppt T t)
step-reduceh{TERM} Γ (Lam pi b pi' x oc t) = step-reduceh (ctxt-var-decl x Γ) t ≫=maybe λ t → just (Lam pi b pi' x oc t)
step-reduceh{TYPE} Γ (TpLambda pi pi' x atk T) = step-reduceh (ctxt-var-decl x Γ) T ≫=maybe λ T → just (TpLambda pi pi' x atk T)
step-reduceh{TERM} Γ (Let pi _ (DefTerm pi' x ot t') t) = just (subst Γ t' x t)
step-reduceh{TYPE} Γ (TpLet pi (DefTerm pi' x ot t) T) = just (subst Γ t x T)
step-reduceh{TYPE} Γ (TpLet pi (DefType pi' x k T') T) = just (subst Γ T' x T)
step-reduceh{TERM} Γ t @ (Mu _ _ _ _ _ _ _ _) = just $ hnf Γ unfold-head-one t tt
step-reduceh{TERM} Γ t @ (Mu' _ _ _ _ _ _ _) = just $ hnf Γ unfold-head-one t tt
step-reduceh Γ t = nothing
parse-norm : string → maybe (∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧)
parse-norm "all" = just λ Γ t → hnf Γ unfold-all t tt
parse-norm "head" = just λ Γ t → hnf Γ unfold-head t tt
parse-norm "once" = just λ Γ → step-reduce Γ ∘ erase
parse-norm _ = nothing
{- Command Executors -}
normalize-cmd : ctxt → (str ll pi norm : string) → 𝕃 string → string ⊎ tagged-val
normalize-cmd Γ str ll pi norm ls =
parse-ll - ll ! "language-level" ≫parse λ ll' →
string-to-ℕ - pi ! "natural number" ≫parse λ sp →
parse-norm - norm ! "normalization method (all, head, once)" ≫parse λ norm →
parse-string ll' - str ! ll ≫parse λ t →
let Γ' = get-local-ctxt Γ sp ls in
inj₂ (to-string-tag "" Γ' (norm Γ' (qualif-ed Γ' t)))
normalize-prompt : ctxt → (str norm : string) → 𝕃 string → string ⊎ tagged-val
normalize-prompt Γ str norm ls =
parse-norm - norm ! "normalization method (all, head, once)" ≫parse λ norm →
let Γ' = merge-lcis-ctxt Γ ls in
parse-try Γ' - str ! ttk ≫parse λ f → f λ ll t →
inj₂ (to-string-tag "" Γ' (norm Γ' (qualif-ed Γ' t)))
erase-cmd : ctxt → (str ll pi : string) → 𝕃 string → string ⊎ tagged-val
erase-cmd Γ str ll pi ls =
parse-ll - ll ! "language-level" ≫parse λ ll' →
string-to-ℕ - pi ! "natural number" ≫parse λ sp →
parse-string ll' - str ! ll ≫parse λ t →
let Γ' = get-local-ctxt Γ sp ls in
inj₂ (to-string-tag "" Γ' (erase (qualif-ed Γ' t)))
erase-prompt : ctxt → (str : string) → 𝕃 string → string ⊎ tagged-val
erase-prompt Γ str ls =
let Γ' = merge-lcis-ctxt Γ ls in
parse-try Γ' - str ! ttk ≫parse λ f → f λ ll t →
inj₂ (to-string-tag "" Γ' (erase (qualif-ed Γ' t)))
private
cmds-to-escaped-string : cmds → strM
cmds-to-escaped-string (c :: cs) = cmd-to-string c $ strAdd "\\n\\n" ≫str cmds-to-escaped-string cs
cmds-to-escaped-string [] = strEmpty
data-cmd : ctxt → (encoding name ps is cs : string) → string ⊎ tagged-val
data-cmd Γ encodingₛ x psₛ isₛ csₛ =
string-to-𝔹 - encodingₛ ! "boolean" ≫parse λ encoding →
parse-string ll-kind - psₛ ! "kind" ≫parse λ psₖ →
parse-string ll-kind - isₛ ! "kind" ≫parse λ isₖ →
parse-string ll-kind - csₛ ! "kind" ≫parse λ csₖ →
let ps = map (λ {(Index x atk) → Decl posinfo-gen posinfo-gen Erased x atk posinfo-gen}) $ kind-to-indices Γ psₖ
cs = map (λ {(Index x (Tkt T)) → Ctr posinfo-gen x T; (Index x (Tkk k)) → Ctr posinfo-gen x $ mtpvar "ErrorExpectedTypeNotKind"}) $ kind-to-indices empty-ctxt csₖ
is = kind-to-indices (add-ctrs-to-ctxt cs $ add-params-to-ctxt ps Γ) isₖ
picked-encoding = if encoding then mendler-encoding else mendler-simple-encoding
defs = datatype-encoding.mk-defs picked-encoding Γ $ Data x ps is cs in
inj₂ $ strRunTag "" Γ $ cmds-to-escaped-string $ fst defs
br-cmd : ctxt → (str qed : string) → 𝕃 string → IO ⊤
br-cmd Γ str qed ls =
let Γ' = merge-lcis-ctxt Γ ls in
maybe-else
(return (io-spans.spans-to-rope (io-spans.global-error "Parse error" nothing)))
(λ s → s >>= return ∘ io-spans.spans-to-rope)
(parse-try {maybe (IO io-spans.spans)} Γ' str ≫=maybe λ f → f λ where
ll-term t → just (untyped-term-spans t Γ' io-spans.empty-spans >>= return ∘ (snd ∘ snd))
ll-type T →
parse-string ll-term qed ≫=maybe λ q →
case check-term q (just $ qualif-type Γ' T) Γ' empty-spans of λ where
(triv , _ , ss @ (regular-spans nothing _)) →
just (putStrLn "inhabited: Type inhabited" >> untyped-type-spans T Γ' io-spans.empty-spans >>= return ∘ (snd ∘ snd))
(triv , _ , _) →
just (untyped-type-spans T Γ' io-spans.empty-spans >>= return ∘ (snd ∘ snd))
ll-kind k →
just (untyped-kind-spans k Γ' io-spans.empty-spans >>= return ∘ (snd ∘ snd)))
>>= putRopeLn
conv-cmd : ctxt → (ll str1 str2 : string) → 𝕃 string → string ⊎ tagged-val
conv-cmd Γ ll s1 s2 ls =
parse-ll - ll ! "language-level" ≫parse λ ll' →
parse-string ll' - s1 ! ll ≫parse λ t1 →
parse-string ll' - s2 ! ll ≫parse λ t2 →
let Γ' = merge-lcis-ctxt Γ ls; t2 = erase (qualif-ed Γ' t2) in
if ll-ind {λ ll → ctxt → ll-lift ll → ll-lift ll → 𝔹}
conv-term conv-type conv-kind ll' Γ' (qualif-ed Γ' t1) t2
then inj₂ (to-string-tag "" Γ' t2)
else inj₁ "Inconvertible"
rewrite-cmd : ctxt → (span-str : string) → (input-str : string) →
(use-hnf : string) → (local-ctxt : 𝕃 string) → string ⊎ tagged-val
rewrite-cmd Γ ss is hd ls =
string-to-𝔹 - hd ! "boolean" ≫parse λ use-hnf →
let Γ = merge-lcis-ctxt Γ ls in
parse-try Γ - ss ! ttk ≫parse λ f → f λ ll ss →
parse-try Γ - is ! ttk ≫parse λ f → (f λ where
ll-term t → (case check-term t nothing Γ empty-spans of λ
{(just T , _ , regular-spans nothing _) → just T; _ → nothing})
! "Error when synthesizing a type for the input term" ≫error λ where
(TpEq _ t₁ t₂ _) → inj₂ (t₁ , t₂)
_ → inj₁ "Synthesized a non-equational type from the input term"
ll-type (TpEq _ t₁ t₂ _) → inj₂ (t₁ , t₂)
ll-type _ → inj₁ "Expected the input expression to be a term, but got a type"
ll-kind _ → inj₁ "Expected the input expression to be a term, but got a kind")
≫=⊎ uncurry λ t₁ t₂ →
let x = fresh-var "x" (ctxt-binds-var Γ) empty-renamectxt
f = ll-ind {λ ll → ctxt → term → var → ll-lift ll → ll-lift ll}
subst subst subst ll Γ t₂ x in
case (ll-ind {λ ll → ll-lift ll → ctxt → 𝔹 → maybe stringset →
term → term → var → ℕ → ll-lift ll × ℕ × ℕ}
rewrite-term rewrite-type rewrite-kind ll (qualif-ed Γ ss) Γ
use-hnf nothing (Beta posinfo-gen NoTerm NoTerm) t₁ x 0) of λ where
(e , 0 , _) → inj₁ "No rewrites could be performed"
(e , _ , _) → inj₂ (strRunTag "" Γ
(to-stringh (erase (f e)) ≫str strAdd "§" ≫str strAdd x ≫str strAdd "§" ≫str to-stringh (erase e)))
{- Commands -}
tv-to-rope : string ⊎ tagged-val → rope
tv-to-rope (inj₁ s) = [[ "{\"error\":\"" ]] ⊹⊹ [[ s ]] ⊹⊹ [[ "\"}" ]]
tv-to-rope (inj₂ (_ , v , ts)) =
[[ "{" ]] ⊹⊹ tagged-val-to-rope 0 ("value" , v , ts) ⊹⊹ [[ "}" ]]
interactive-cmd-h : ctxt → 𝕃 string → string ⊎ tagged-val
interactive-cmd-h Γ ("normalize" :: input :: ll :: sp :: norm :: lc) =
normalize-cmd Γ input ll sp norm lc
interactive-cmd-h Γ ("erase" :: input :: ll :: sp :: lc) =
erase-cmd Γ input ll sp lc
interactive-cmd-h Γ ("normalizePrompt" :: input :: norm :: lc) =
normalize-prompt Γ input norm lc
interactive-cmd-h Γ ("erasePrompt" :: input :: lc) =
erase-prompt Γ input lc
interactive-cmd-h Γ ("conv" :: ll :: ss :: is :: lc) =
conv-cmd Γ ll ss is lc
interactive-cmd-h Γ ("rewrite" :: ss :: is :: head :: lc) =
rewrite-cmd Γ ss is head lc
interactive-cmd-h Γ ("data" :: encoding :: x :: ps :: is :: cs :: []) =
data-cmd Γ encoding x ps is cs
interactive-cmd-h Γ cs =
inj₁ ("Unknown interactive cmd: " ^ 𝕃-to-string (λ s → s) ", " cs)
interactive-cmd : 𝕃 string → toplevel-state → IO ⊤
interactive-cmd ("br" :: input :: qed :: lc) ts = br-cmd (toplevel-state.Γ ts) input qed lc
interactive-cmd ls ts = putRopeLn (tv-to-rope (interactive-cmd-h (toplevel-state.Γ ts) ls))
| 45.250681
| 188
| 0.590113
|
41968710a075acce19690e811738511e56cfb2e2
| 385
|
agda
|
Agda
|
tests/covered/ImplArg.agda
|
andrejtokarcik/agda-semantics
|
dc333ed142584cf52cc885644eed34b356967d8b
|
[
"MIT"
] | 3
|
2015-08-10T15:33:56.000Z
|
2018-12-06T17:24:25.000Z
|
tests/covered/ImplArg.agda
|
andrejtokarcik/agda-semantics
|
dc333ed142584cf52cc885644eed34b356967d8b
|
[
"MIT"
] | null | null | null |
tests/covered/ImplArg.agda
|
andrejtokarcik/agda-semantics
|
dc333ed142584cf52cc885644eed34b356967d8b
|
[
"MIT"
] | null | null | null |
-- https://github.com/bitonic/tog/wiki/Implicit-Arguments
-- aj s popisom checkingu od Andreasa Abela
module ImplArg where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Vec (A : Set) : Nat -> Set where
vnil : Vec A zero
vcons : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
Cons = {A : Set} (a : A) {n : Nat} -> Vec A n -> Vec A (suc n)
cons : Cons
cons a = vcons a
| 22.647059
| 62
| 0.6
|
2e43e1a375be7de453cce857b8f8936ce2732597
| 1,554
|
agda
|
Agda
|
Base/Equi.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
Base/Equi.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
Base/Equi.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import M-types.Base.Core
open import M-types.Base.Sum
open import M-types.Base.Prod
open import M-types.Base.Eq
module M-types.Base.Equi where
Qinv : {X : Ty ℓ₀} {Y : Ty ℓ₁} →
∏[ f ∈ (X → Y)] Ty (ℓ-max ℓ₀ ℓ₁)
Qinv {_} {_} {X} {Y} f = ∑[ g ∈ (Y → X) ]
(∏[ x ∈ X ] g (f x) ≡ x) ×
(∏[ y ∈ Y ] f (g y) ≡ y)
IsEqui : {X : Ty ℓ₀} {Y : Ty ℓ₁} →
∏[ f ∈ (X → Y) ] Ty (ℓ-max ℓ₀ ℓ₁)
IsEqui {_} {_} {X} {Y} f =
(∑[ g ∈ (Y → X) ] ∏[ x ∈ X ] g (f x) ≡ x) ×
(∑[ g ∈ (Y → X) ] ∏[ y ∈ Y ] f (g y) ≡ y)
infixr 8 _≃_
_≃_ : ∏[ X ∈ Ty ℓ₀ ] ∏[ Y ∈ Ty ℓ₁ ] Ty (ℓ-max ℓ₀ ℓ₁)
X ≃ Y = ∑[ f ∈ (X → Y) ] IsEqui f
Qinv→IsEqui : {X : Ty ℓ₀} {Y : Ty ℓ₁} {f : X → Y} →
Qinv f → IsEqui f
Qinv→IsEqui (g , hom₀ , hom₁) = ((g , hom₀) , (g , hom₁))
IsEqui→Qinv : {X : Ty ℓ₀} {Y : Ty ℓ₁} {f : X → Y} →
IsEqui f → Qinv f
IsEqui→Qinv {_} {_} {_} {_} {f} ((g₀ , hom₀) , (g₁ , hom₁)) =
(
g₀ ,
hom₀ ,
λ y → ap f (ap g₀ (hom₁ y)⁻¹ · hom₀ (g₁ y)) · hom₁ y
)
inv : {X : Ty ℓ₀} {Y : Ty ℓ₁} →
∏[ equi ∈ X ≃ Y ] (Y → X)
inv (fun , isEqui) = pr₀ (IsEqui→Qinv isEqui)
hom₀ : {X : Ty ℓ₀} {Y : Ty ℓ₁} →
∏[ equi ∈ X ≃ Y ] ∏[ x ∈ X ] inv equi (fun equi x) ≡ x
hom₀ (fun , isEqui) = pr₀ (pr₁ (IsEqui→Qinv isEqui))
hom₁ : {X : Ty ℓ₀} {Y : Ty ℓ₁} →
∏[ equi ∈ X ≃ Y ] ∏[ y ∈ Y ] fun equi (inv equi y) ≡ y
hom₁ (fun , isEqui) = pr₁ (pr₁ (IsEqui→Qinv isEqui))
| 29.320755
| 65
| 0.413127
|
1eec886a840b27e77fec8ef6de42632bfafdf811
| 3,271
|
agda
|
Agda
|
src/Categories/Category/Monoidal/Symmetric.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Monoidal/Symmetric.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Monoidal/Symmetric.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Monoidal
module Categories.Category.Monoidal.Symmetric {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Properties
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
open import Categories.Morphism C
open import Categories.Morphism.Properties C
open import Categories.Category.Monoidal.Braided M
open Category C
open Commutation
private
variable
X Y Z : Obj
-- symmetric monoidal category
-- commutative braided monoidal category
--
-- the reason why we define symmetric categories via braided monoidal categories could
-- be not obvious, but it is the right definition: it requires again a redundant
-- hexagon proof which allows achieves definitional equality of the opposite.
record Symmetric : Set (levelOfTerm M) where
field
braided : Braided
module braided = Braided braided
open braided public
private
B : ∀ {X Y} → X ⊗₀ Y ⇒ Y ⊗₀ X
B {X} {Y} = braiding.⇒.η (X , Y)
field
commutative : B {X} {Y} ∘ B {Y} {X} ≈ id
braided-iso : X ⊗₀ Y ≅ Y ⊗₀ X
braided-iso = record
{ from = B
; to = B
; iso = record
{ isoˡ = commutative
; isoʳ = commutative
}
}
module braided-iso {X Y} = _≅_ (braided-iso {X} {Y})
private
record Symmetric′ : Set (levelOfTerm M) where
open Monoidal M
field
braiding : NaturalIsomorphism ⊗ (flip-bifunctor ⊗)
module braiding = NaturalIsomorphism braiding
private
B : ∀ {X Y} → X ⊗₀ Y ⇒ Y ⊗₀ X
B {X} {Y} = braiding.⇒.η (X , Y)
field
commutative : B {X} {Y} ∘ B {Y} {X} ≈ id
hexagon : [ (X ⊗₀ Y) ⊗₀ Z ⇒ Y ⊗₀ Z ⊗₀ X ]⟨
B ⊗₁ id ⇒⟨ (Y ⊗₀ X) ⊗₀ Z ⟩
associator.from ⇒⟨ Y ⊗₀ X ⊗₀ Z ⟩
id ⊗₁ B
≈ associator.from ⇒⟨ X ⊗₀ Y ⊗₀ Z ⟩
B ⇒⟨ (Y ⊗₀ Z) ⊗₀ X ⟩
associator.from
⟩
braided-iso : X ⊗₀ Y ≅ Y ⊗₀ X
braided-iso = record
{ from = B
; to = B
; iso = record
{ isoˡ = commutative
; isoʳ = commutative
}
}
module braided-iso {X Y} = _≅_ (braided-iso {X} {Y})
-- we don't define [Symmetric] from [Braided] because we want to avoid asking
-- [hexagon₂], which can readily be proven using the [hexagon] and [commutative].
braided : Braided
braided = record
{ braiding = braiding
; hexagon₁ = hexagon
; hexagon₂ = λ {X Y Z} →
Iso-≈ hexagon
(Iso-∘ (Iso-∘ ([ -⊗ Y ]-resp-Iso braided-iso.iso) associator.iso)
([ X ⊗- ]-resp-Iso braided-iso.iso))
(Iso-∘ (Iso-∘ associator.iso braided-iso.iso)
associator.iso)
}
symmetricHelper : Symmetric′ → Symmetric
symmetricHelper S = record
{ braided = braided
; commutative = commutative
}
where open Symmetric′ S
| 28.443478
| 97
| 0.562519
|
5e97d4bf880da15b20d8163bf62b7ace73964090
| 234
|
agda
|
Agda
|
src/FRP/LTL/ISet/Empty.agda
|
agda/agda-frp-ltl
|
e88107d7d192cbfefd0a94505e6a5793afe1a7a5
|
[
"MIT"
] | 21
|
2015-07-02T20:25:05.000Z
|
2020-06-15T02:51:13.000Z
|
src/FRP/LTL/ISet/Empty.agda
|
agda/agda-frp-ltl
|
e88107d7d192cbfefd0a94505e6a5793afe1a7a5
|
[
"MIT"
] | 2
|
2015-03-01T07:01:31.000Z
|
2015-03-02T15:23:53.000Z
|
src/FRP/LTL/ISet/Empty.agda
|
agda/agda-frp-ltl
|
e88107d7d192cbfefd0a94505e6a5793afe1a7a5
|
[
"MIT"
] | 3
|
2015-03-01T07:33:00.000Z
|
2022-03-12T11:39:04.000Z
|
open import Data.Product using ( _,_ )
open import Data.Empty using ( ⊥ )
open import FRP.LTL.ISet.Core using ( ISet ; [_] ; _,_ )
module FRP.LTL.ISet.Empty where
F : ISet
F = [ (λ i → ⊥) , (λ i j i~j → λ ()) , (λ i j i⊑j → λ ()) ]
| 26
| 59
| 0.57265
|
1ada383eb52dd269dc675f02a3598ba2040b6143
| 9,475
|
agda
|
Agda
|
Globular-TT/Dec-Type-Checking.agda
|
thibautbenjamin/catt-formalization
|
3a02010a869697f4833c9bc6047d66ca27b87cf2
|
[
"MIT"
] | null | null | null |
Globular-TT/Dec-Type-Checking.agda
|
thibautbenjamin/catt-formalization
|
3a02010a869697f4833c9bc6047d66ca27b87cf2
|
[
"MIT"
] | null | null | null |
Globular-TT/Dec-Type-Checking.agda
|
thibautbenjamin/catt-formalization
|
3a02010a869697f4833c9bc6047d66ca27b87cf2
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
open import Prelude
import GSeTT.Rules
import GSeTT.Typed-Syntax
import Globular-TT.Syntax
import Globular-TT.Rules
{- Decidability of type cheking for the type theory for globular sets -}
module Globular-TT.Dec-Type-Checking {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index))
(assumption : Globular-TT.Rules.well-founded index rule)
(eqdec-index : eqdec index) where
open import Globular-TT.Syntax index
open import Globular-TT.Eqdec-syntax index eqdec-index
open import Globular-TT.Rules index rule
open import Globular-TT.CwF-Structure index rule
dec-∈ : ∀ (n : ℕ) (A : Pre-Ty) (Γ : Pre-Ctx) → dec (n # A ∈ Γ)
dec-∈ n A ⊘ = inr λ{()}
dec-∈ n A (Γ ∙ x # B) with dec-∈ n A Γ
... | inl n∈Γ = inl (inl n∈Γ)
... | inr n∉Γ with eqdecℕ n x | eqdec-Ty A B
... | inl idp | inl idp = inl (inr (idp , idp))
... | inr n≠x | _ = inr λ{(inl n∈Γ) → n∉Γ n∈Γ; (inr (idp , idp)) → n≠x idp}
... | inl idp | inr A≠B_ = inr λ{(inl n∈Γ) → n∉Γ n∈Γ; (inr (_ , A=B)) → A≠B A=B}
{- Decidability in the fragment of the theory with only globular contexts -}
-- termination is really tricky, and involves reasonning both on depth and dimension at the same time !
dec-G⊢T : ∀ (Γ : GSeTT.Typed-Syntax.Ctx) n A → dim A ≤ n → dec (GPre-Ctx (fst Γ) ⊢T A)
dec-G⊢t : ∀ (Γ : GSeTT.Typed-Syntax.Ctx) n d A t → dim A ≤ n → depth t ≤ d → dec (GPre-Ctx (fst Γ) ⊢t t # A)
dec-G⊢S : ∀ (Δ Γ : GSeTT.Typed-Syntax.Ctx) n d γ → dimC (GPre-Ctx (fst Γ)) ≤ n → depthS γ ≤ d → dec (GPre-Ctx (fst Δ) ⊢S γ > GPre-Ctx (fst Γ))
dec-G⊢T Γ _ ∗ _ = inl (ob (GCtx _ (snd Γ)))
dec-G⊢T Γ (S n) (⇒ A t u) (S≤ i) with dec-G⊢T Γ n A i | dec-G⊢t Γ n _ A t i (n≤n _) | dec-G⊢t Γ n _ A u i (n≤n _)
... | inl Γ⊢A | inl Γ⊢t:A | inl Γ⊢u:A = inl (ar Γ⊢A Γ⊢t:A Γ⊢u:A)
... | inr Γ⊬A | _ | _ = inr λ{(ar Γ⊢A _ _) → Γ⊬A Γ⊢A}
... | inl _ | inr Γ⊬t:A | _ = inr λ{(ar _ Γ⊢t:A _) → Γ⊬t:A Γ⊢t:A}
... | inl _ | inl _ | inr Γ⊬u:A = inr λ{(ar _ _ Γ⊢u:A) → Γ⊬u:A Γ⊢u:A}
dec-G⊢t Γ n _ A (Var x) _ (0≤ _) with dec-∈ x A (GPre-Ctx (fst Γ))
... | inl x∈Γ = inl (var (GCtx _ (snd Γ)) x∈Γ)
... | inr x∉Γ = inr λ {(var _ x∈Γ) → x∉Γ x∈Γ}
dec-G⊢t Γ n (S d) A (Tm-constructor i γ) dimA≤n (S≤ dγ≤d) with eqdec-Ty A (Ti i [ γ ]Pre-Ty )
... | inr A≠Ti = inr λ{(tm _ _ idp) → A≠Ti idp}
... | inl idp
with dec-G⊢T (fst (rule i)) n (Ti i) (=-≤ (dim[] _ _ ^) dimA≤n)
... | inr Ci⊬Ti = inr λ t → Ci⊬Ti (Γ⊢tm→Ci⊢Ti t)
... | inl Ci⊢Ti with dec-G⊢S Γ (fst (rule i)) n d γ
(≤T (≤-= (assumption i Ci⊢Ti) (dim[] _ _ ^)) dimA≤n) -- dim Ci ≤ dim A
dγ≤d -- depth γ ≤ d
... | inr Γ⊬γ = inr λ t → Γ⊬γ (Γ⊢tm→Γ⊢γ t)
... | inl Γ⊢γ = inl (tm Ci⊢Ti Γ⊢γ idp)
dec-G⊢S Δ (nil , _) _ _ <> (0≤ _) _ = inl (es (GCtx _ (snd Δ)))
dec-G⊢S Δ ((Γ :: _) , _) _ _ <> _ _ = inr λ {()}
dec-G⊢S Δ (nil , _) _ _ < γ , x ↦ t > _ _ = inr λ {()}
dec-G⊢S Δ ((Γ :: (y , A)) , Γ+⊢@(GSeTT.Rules.cc Γ⊢ Γ⊢A idp)) n d < γ , x ↦ t > dimΓ+≤n dγ+≤d with dec-G⊢S Δ (Γ , Γ⊢) n d γ
(≤T (n≤max (dimC (GPre-Ctx Γ)) (dim (GPre-Ty A))) dimΓ+≤n) -- dim Γ ≤ n
(≤T (n≤max (depthS γ) (depth t)) dγ+≤d) -- depth γ ≤ d
| dec-G⊢t Δ n d ((GPre-Ty A) [ γ ]Pre-Ty) t
((≤T (=-≤ (dim[] _ _) (m≤max (dimC (GPre-Ctx Γ)) (dim (GPre-Ty A)))) dimΓ+≤n)) -- dim A[γ] ≤ n
(≤T (m≤max (depthS γ) (depth t)) dγ+≤d) -- depth t ≤ d
| eqdecℕ y x
... | inl Δ⊢γ:Γ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ:Γ (GCtx _ Γ+⊢) Δ⊢t idp)
... | inr Δ⊬γ:Γ | _ | _ = inr λ {(sc Δ⊢γ:Γ _ _ idp) → Δ⊬γ:Γ Δ⊢γ:Γ}
... | inl _ | inr Δ⊬t | _ = inr λ {(sc _ _ Δ⊢t idp) → Δ⊬t Δ⊢t}
... | inl _ | inl _ | inr n≠x = inr λ {(sc _ _ _ idp) → n≠x idp}
{- Decidability of judgments for contexts, types, terms and substitution towards a glaobular context -}
dec-⊢C : ∀ Γ → dec (Γ ⊢C)
dec-⊢T : ∀ Γ A → dec (Γ ⊢T A)
dec-⊢t : ∀ Γ A t → dec (Γ ⊢t t # A)
dec-⊢S:G : ∀ Δ (Γ : GSeTT.Typed-Syntax.Ctx) γ → dec (Δ ⊢S γ > GPre-Ctx (fst Γ))
dec-⊢T Γ ∗ with dec-⊢C Γ
... | inl Γ⊢ = inl (ob Γ⊢)
... | inr Γ⊬ = inr λ {(ob Γ⊢) → Γ⊬ Γ⊢}
dec-⊢T Γ (⇒ A t u) with dec-⊢T Γ A | dec-⊢t Γ A t | dec-⊢t Γ A u
... | inl Γ⊢A | inl Γ⊢t:A | inl Γ⊢u:A = inl (ar Γ⊢A Γ⊢t:A Γ⊢u:A)
... | inr Γ⊬A | _ | _ = inr λ {(ar Γ⊢A _ _) → Γ⊬A Γ⊢A}
... | inl _ | inr Γ⊬t:A | _ = inr λ {(ar _ Γ⊢t:A _) → Γ⊬t:A Γ⊢t:A}
... | inl _ | inl _ | inr Γ⊬u:A = inr λ {(ar _ _ Γ⊢u:A) → Γ⊬u:A Γ⊢u:A}
dec-⊢t Γ A (Var x) with dec-⊢C Γ | dec-∈ x A Γ
... | inl Γ⊢ | inl x∈Γ = inl (var Γ⊢ x∈Γ)
... | inr Γ⊬ | _ = inr λ {(var Γ⊢ _) → Γ⊬ Γ⊢}
... | inl _ | inr x∉Γ = inr λ {(var _ x∈Γ) → x∉Γ x∈Γ}
dec-⊢t Γ A (Tm-constructor i γ) with eqdec-Ty A (Ti i [ γ ]Pre-Ty)
... | inr A≠Ti = inr λ{(tm _ _ idp) → A≠Ti idp}
... | inl idp
with dec-G⊢T (fst (rule i)) _ (Ti i) (n≤n _) | dec-⊢S:G Γ (fst (rule i)) γ
... | inl Ci⊢Ti | inl Γ⊢γ = inl (tm Ci⊢Ti Γ⊢γ idp)
... | inr Ci⊬Ti | _ = inr λ t → Ci⊬Ti (Γ⊢tm→Ci⊢Ti t)
... | inl _ | inr Γ⊬γ = inr λ t → Γ⊬γ (Γ⊢tm→Γ⊢γ t)
dec-⊢C ⊘ = inl ec
dec-⊢C (Γ ∙ n # A) with dec-⊢C Γ | dec-⊢T Γ A | eqdecℕ n (C-length Γ)
... | inl Γ⊢ | inl Γ⊢A | inl idp = inl (cc Γ⊢ Γ⊢A idp)
... | inr Γ⊬ | _ | _ = inr λ {(cc Γ⊢ _ idp) → Γ⊬ Γ⊢}
... | inl _ | inr Γ⊬A | _ = inr λ {(cc _ Γ⊢A idp) → Γ⊬A Γ⊢A}
... | inl _ | inl _ | inr n≠l = inr λ {(cc _ _ idp) → n≠l idp}
dec-⊢S:G Δ (nil , _) <> with (dec-⊢C Δ)
... | inl Δ⊢ = inl (es Δ⊢)
... | inr Δ⊬ = inr λ{(es Δ⊢) → Δ⊬ Δ⊢}
dec-⊢S:G Δ (nil , _) < γ , x ↦ x₁ > = inr λ{()}
dec-⊢S:G Δ ((Γ :: _) , _) <> = inr λ{()}
dec-⊢S:G Δ ((Γ :: (v , A)) , Γ+⊢@(GSeTT.Rules.cc Γ⊢ Γ⊢A idp)) < γ , x ↦ t > with dec-⊢S:G Δ (Γ , Γ⊢) γ | dec-⊢t Δ ((GPre-Ty A) [ γ ]Pre-Ty) t | eqdecℕ x (length Γ)
... | inl Δ⊢γ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ (GCtx _ Γ+⊢) Δ⊢t idp)
... | inr Δ⊬γ | _ | _ = inr λ{(sc Δ⊢γ _ _ idp) → Δ⊬γ Δ⊢γ}
... | inl _ | inr Δ⊬t | _ = inr λ{(sc _ _ Δ⊢t idp) → Δ⊬t Δ⊢t}
... | inl _ | inl _ | inr x≠x = inr λ{(sc _ _ _ idp) → x≠x idp}
{- Decidability of substitution -}
dec-⊢S : ∀ Δ Γ γ → dec (Δ ⊢S γ > Γ)
dec-⊢S Δ ⊘ <> with (dec-⊢C Δ)
... | inl Δ⊢ = inl (es Δ⊢)
... | inr Δ⊬ = inr λ{(es Δ⊢) → Δ⊬ Δ⊢}
dec-⊢S Δ ⊘ < γ , x ↦ x₁ > = inr λ{()}
dec-⊢S Δ (Γ ∙ _ # _) <> = inr λ{()}
dec-⊢S Δ (Γ ∙ v # A) < γ , x ↦ t > with dec-⊢S Δ Γ γ | dec-⊢C (Γ ∙ v # A) | dec-⊢t Δ (A [ γ ]Pre-Ty) t | eqdecℕ x v
... | inl Δ⊢γ | inl Γ+⊢ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ Γ+⊢ Δ⊢t idp)
... | inr Δ⊬γ | _ | _ | _ = inr λ{(sc Δ⊢γ _ _ idp) → Δ⊬γ Δ⊢γ}
... | inl _ | inr Γ+⊬ | _ | _ = inr λ{(sc _ Γ⊢ _ idp) → Γ+⊬ Γ⊢}
... | inl _ | inl _ | inr Δ⊬t | _ = inr λ{(sc _ _ Δ⊢t idp) → Δ⊬t Δ⊢t}
... | inl _ | inl _ | inl _ | inr x≠x = inr λ{(sc _ _ _ idp) → x≠x idp}
| 70.185185
| 196
| 0.344802
|
032a80c0de4f5d88c1e768ef05324a4e1f09703d
| 2,347
|
agda
|
Agda
|
src/CategoryTheory/Linear.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | 4
|
2018-05-31T20:37:04.000Z
|
2022-01-04T09:33:48.000Z
|
src/CategoryTheory/Linear.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
src/CategoryTheory/Linear.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
module CategoryTheory.Linear where
open import CategoryTheory.Categories
open import CategoryTheory.Functor
open import CategoryTheory.BCCCs
open import CategoryTheory.Monad
open import CategoryTheory.Instances.Kleisli
module L {n} {ℂ : Category n} (ℂ-BCCC : BicartesianClosed ℂ) (Mo : Monad ℂ) where
open Category ℂ
open BicartesianClosed ℂ-BCCC
open Monad Mo
open Functor T renaming (omap to M ; fmap to M-f)
Kl : Category n
Kl = Kleisli ℂ Mo
-- Linear product of two objects
_⊛_ : (A B : obj) -> obj
A ⊛ B = (A ⊗ M B) ⊕ (M A ⊗ B) ⊕ (A ⊗ B)
-- First projection from linear product
*π₁ : ∀{A B} -> A ⊛ B ~> M A
*π₁ {A}{B} = [ η.at A ∘ π₁ ⁏ π₁ ⁏ η.at A ∘ π₁ ]
-- Second projection from linear product
*π₂ : ∀{A B} -> A ⊛ B ~> M B
*π₂ {A}{B} = [ π₂ ⁏ η.at B ∘ π₂ ⁏ η.at B ∘ π₂ ]
-- Type class for linear products of type A ⊛ B. Need to provide
-- linear product of morphisms and product laws in order to establish
-- that the linear product is a product in the Kleisli category of the monad.
record LinearProduct (A B : obj) : Set (lsuc n) where
infix 10 ⟪_,_⟫
field
-- | Data
-- Linear product
⟪_,_⟫ : ∀{L} -> (L ~> M A) -> (L ~> M B) -> (L ~> M (A ⊛ B))
-- | Laws
*π₁-comm : ∀{L} -> {l₁ : L ~> M A} {l₂ : L ~> M B}
-> (μ.at A ∘ M-f *π₁) ∘ ⟪ l₁ , l₂ ⟫ ≈ l₁
*π₂-comm : ∀{L} -> {l₁ : L ~> M A} {l₂ : L ~> M B}
-> (μ.at B ∘ M-f *π₂) ∘ ⟪ l₁ , l₂ ⟫ ≈ l₂
⊛-unique : ∀{P} {p₁ : P ~> M A} {p₂ : P ~> M B} {m : P ~> M A⊕B}
-> (μ.at A ∘ M-f *π₁) ∘ m ≈ p₁ -> (μ.at B ∘ M-f *π₂) ∘ m ≈ p₂
-> ⟪ p₁ , p₂ ⟫ ≈ m
Kl-⊛ : Product Kl A B
Kl-⊛ = record
{ A⊗B = A ⊛ B
; π₁ = *π₁
; π₂ = *π₂
; ⟨_,_⟩ = ⟪_,_⟫
; π₁-comm = *π₁-comm
; π₂-comm = *π₂-comm
; ⊗-unique = ⊛-unique
}
-- Type class for linear categories
record Linear {n} {ℂ : Category n}
(ℂ-BCCC : BicartesianClosed ℂ) (Mo : Monad ℂ) : Set (lsuc n) where
open Category ℂ
open L ℂ-BCCC Mo
field
linprod : ∀(A B : obj) -> LinearProduct A B
open module Li {A} {B} = LinearProduct (linprod A B) public
| 33.056338
| 81
| 0.487431
|
31b1ef007ea97811c8be9e7d1dd1dd7cb4bea132
| 9,124
|
agda
|
Agda
|
src/TemporalOps/Delay.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | 4
|
2018-05-31T20:37:04.000Z
|
2022-01-04T09:33:48.000Z
|
src/TemporalOps/Delay.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
src/TemporalOps/Delay.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
{- Delay operator. -}
module TemporalOps.Delay where
open import CategoryTheory.Categories
open import CategoryTheory.Instances.Reactive
open import CategoryTheory.Functor
open import CategoryTheory.CartesianStrength
open import TemporalOps.Common
open import TemporalOps.Next
open import Data.Nat.Properties using (+-identityʳ ; +-comm ; +-assoc ; +-suc)
open import Relation.Binary.HeterogeneousEquality as ≅ using (_≅_ ; ≅-to-≡)
import Relation.Binary.PropositionalEquality as ≡
open import Data.Product
open import Data.Sum
-- General iteration
-- iter f n v = fⁿ(v)
iter : (τ -> τ) -> ℕ -> τ -> τ
iter F zero A = A
iter F (suc n) A = F (iter F n A)
-- Multi-step delay
delay_by_ : τ -> ℕ -> τ
delay A by zero = A
delay A by suc n = ▹ (delay A by n)
infix 67 delay_by_
-- || Lemmas for the delay operator
-- Extra delay is cancelled out by extra waiting.
delay-+ : ∀{A} -> (n l k : ℕ)
-> delay A by (n + l) at (n + k) ≡ delay A by l at k
delay-+ zero l k = refl
delay-+ (suc n) = delay-+ n
-- || Derived lemmas - they can all be expressed in terms of delay-+,
-- || but they are given explicitly for simplicity.
-- Delay by n is cancelled out by waiting n extra steps.
delay-+-left0 : ∀{A} -> (n k : ℕ)
-> delay A by n at (n + k) ≡ A at k
delay-+-left0 zero k = refl
delay-+-left0 (suc n) k = delay-+-left0 n k
-- delay-+-left0 can be converted to delay-+ (heterogeneously).
delay-+-left0-eq : ∀{A : τ} -> (n l : ℕ)
-> Proof-≡ (delay-+-left0 {A} n l) (delay-+ {A} n 0 l)
delay-+-left0-eq zero l v v′ pf = ≅-to-≡ pf
delay-+-left0-eq (suc n) l = delay-+-left0-eq n l
-- Extra delay by n steps is cancelled out by waiting for n steps.
delay-+-right0 : ∀{A} -> (n l : ℕ)
-> delay A by (n + l) at n ≡ delay A by l at 0
delay-+-right0 zero l = refl
delay-+-right0 (suc n) l = delay-+-right0 n l
-- Delaying by n is the same as delaying by (n + 0)
delay-+0-left : ∀{A} -> (k n : ℕ)
-> delay A by k at n ≡ delay A by (k + 0) at n
delay-+0-left {A} k n rewrite +-identityʳ k = refl
-- If the delay is greater than the wait amount, we get unit
delay-⊤ : ∀{A} -> (n k : ℕ)
-> ⊤ at n ≡ delay A by (n + suc k) at n
delay-⊤ {A} n k = sym (delay-+-right0 n (suc k))
-- Associativity of arguments in the delay lemma
delay-assoc-sym : ∀{A} (n k l j : ℕ)
-> Proof-≅ (sym (delay-+ {A} n (k + l) (k + j)))
(sym (delay-+ {A} (n + k) l j))
delay-assoc-sym zero zero l j v v′ pr = pr
delay-assoc-sym zero (suc k) l j = delay-assoc-sym zero k l j
delay-assoc-sym (suc n) k l j = delay-assoc-sym n k l j
-- Functor instance for delay
F-delay : ℕ -> Endofunctor ℝeactive
F-delay k = record
{ omap = delay_by k
; fmap = fmap-delay k
; fmap-id = λ {_ n a} -> fmap-delay-id k {_} {n} {a}
; fmap-∘ = fmap-delay-∘ k
; fmap-cong = fmap-delay-cong k
}
where
-- Lifting of delay
fmap-delay : {A B : τ} -> (k : ℕ) -> A ⇴ B -> delay A by k ⇴ delay B by k
fmap-delay zero f = f
fmap-delay (suc k) f = Functor.fmap F-▹ (fmap-delay k f)
-- Delay preserves identities
fmap-delay-id : ∀ (k : ℕ) {A : τ} {n : ℕ} {a : (delay A by k) n}
-> (fmap-delay k id at n) a ≡ a
fmap-delay-id zero = refl
fmap-delay-id (suc k) {A} {zero} = refl
fmap-delay-id (suc k) {A} {suc n} = fmap-delay-id k {A} {n}
-- Delay preserves composition
fmap-delay-∘ : ∀ (k : ℕ) {A B C : τ} {g : B ⇴ C} {f : A ⇴ B} {n : ℕ} {a : (delay A by k) n}
-> (fmap-delay k (g ∘ f) at n) a ≡ (fmap-delay k g ∘ fmap-delay k f at n) a
fmap-delay-∘ zero = refl
fmap-delay-∘ (suc k) {n = zero} = refl
fmap-delay-∘ (suc k) {n = suc n} = fmap-delay-∘ k {n = n}
-- Delay is congruent
fmap-delay-cong : ∀ (k : ℕ) {A B : τ} {f f′ : A ⇴ B}
-> ({n : ℕ} {a : A at n} -> f n a ≡ f′ n a)
-> ({n : ℕ} {a : delay A by k at n}
-> (fmap-delay k f at n) a
≡ (fmap-delay k f′ at n) a)
fmap-delay-cong zero e = e
fmap-delay-cong (suc k) e {zero} = refl
fmap-delay-cong (suc k) e {suc n} = fmap-delay-cong k e
-- || Lemmas for the interaction of fmap and delay-+
-- Lifted version of the delay-+ lemma
-- Arguments have different types, so we need heterogeneous equality
fmap-delay-+ : ∀ {A B : τ} {f : A ⇴ B} (n k l : ℕ)
-> Fun-≅ (Functor.fmap (F-delay (n + k)) f at (n + l))
(Functor.fmap (F-delay k) f at l)
fmap-delay-+ zero k l v .v ≅.refl = ≅.refl
fmap-delay-+ (suc n) k l v v′ pf = fmap-delay-+ n k l v v′ pf
-- Specialised version with v of type delay A by (n + k) at (n + l)
-- Uses explicit rewrites and homogeneous equality
fmap-delay-+-n+k : ∀ {A B : τ} {f : A ⇴ B} (n k l : ℕ)
-> (v : delay A by (n + k) at (n + l))
-> rew (delay-+ n k l) ((Functor.fmap (F-delay (n + k)) f at (n + l)) v)
≡ (Functor.fmap (F-delay k) f at l) (rew (delay-+ n k l) v)
fmap-delay-+-n+k {A} n k l v =
≅-to-rew-≡ (fmap-delay-+ n k l v v′ v≅v′) (delay-+ n k l)
where
v′ : delay A by k at l
v′ = rew (delay-+ n k l) v
v≅v′ : v ≅ v′
v≅v′ = rew-to-≅ (delay-+ n k l)
-- Lifted delay lemma with delay-+-left0
fmap-delay-+-n+0 : ∀ {A B : τ} {f : A ⇴ B} (n l : ℕ)
-> {v : delay A by n at (n + l)}
-> rew (delay-+-left0 n l) ((Functor.fmap (F-delay n) f at (n + l)) v)
≡ f l (rew (delay-+-left0 n l) v)
fmap-delay-+-n+0 {A} zero l = refl
fmap-delay-+-n+0 {A} (suc n) l = fmap-delay-+-n+0 n l
-- Specialised version with v of type delay A by k at l
-- Uses explicit rewrites and homogeneous equality
fmap-delay-+-k : ∀ {A B : τ} {f : A ⇴ B} (n k l : ℕ)
->(v : delay A by k at l)
-> Functor.fmap (F-delay (n + k)) f (n + l) (rew (sym (delay-+ n k l)) v)
≡ rew (sym (delay-+ n k l)) (Functor.fmap (F-delay k) f l v)
fmap-delay-+-k {A} {B} {f} n k l v =
sym (≅-to-rew-≡ (≅.sym (fmap-delay-+ n k l v′ v v≅v′)) (sym (delay-+ n k l)))
where
v′ : delay A by (n + k) at (n + l)
v′ = rew (sym (delay-+ n k l)) v
v≅v′ : v′ ≅ v
v≅v′ = ≅.sym (rew-to-≅ (sym (delay-+ n k l)))
-- Delay is a Cartesian functor
F-cart-delay : ∀ k -> CartesianFunctor (F-delay k) ℝeactive-cart ℝeactive-cart
F-cart-delay k = record
{ u = u-delay k
; m = m-delay k
; m-nat₁ = m-nat₁-delay k
; m-nat₂ = m-nat₂-delay k
; associative = assoc-delay k
; unital-right = unit-right-delay k
; unital-left = λ {B} {n} {a} -> unit-left-delay k {B} {n} {a}
}
where
open CartesianFunctor F-cart-▹
u-delay : ∀ k -> ⊤ ⇴ delay ⊤ by k
u-delay zero = λ n _ → top.tt
u-delay (suc k) zero top.tt = top.tt
u-delay (suc k) (suc n) top.tt = u-delay k n top.tt
m-delay : ∀ k (A B : τ) -> (delay A by k ⊗ delay B by k) ⇴ delay (A ⊗ B) by k
m-delay zero A B = λ n x → x
m-delay (suc k) A B = Functor.fmap F-▹ (m-delay k A B) ∘ m (delay A by k) (delay B by k)
m-nat₁-delay : ∀ k {A B C : τ} (f : A ⇴ B)
-> Functor.fmap (F-delay k) (f * id) ∘ m-delay k A C
≈ m-delay k B C ∘ Functor.fmap (F-delay k) f * id
m-nat₁-delay zero f = refl
m-nat₁-delay (suc k) f {zero} = refl
m-nat₁-delay (suc k) f {suc n} = m-nat₁-delay k f
m-nat₂-delay : ∀ k {A B C : τ} (f : A ⇴ B)
-> Functor.fmap (F-delay k) (id * f) ∘ m-delay k C A
≈ m-delay k C B ∘ id * Functor.fmap (F-delay k) f
m-nat₂-delay zero f = refl
m-nat₂-delay (suc k) f {zero} = refl
m-nat₂-delay (suc k) f {suc n} = m-nat₂-delay k f
assoc-delay : ∀ k {A B C : τ}
-> m-delay k A (B ⊗ C) ∘ id * m-delay k B C ∘ assoc-right
≈ Functor.fmap (F-delay k) assoc-right ∘ m-delay k (A ⊗ B) C ∘ m-delay k A B * id
assoc-delay zero = refl
assoc-delay (suc k) {A} {B} {C} {zero} = refl
assoc-delay (suc k) {A} {B} {C} {suc n} = assoc-delay k
unit-right-delay : ∀ k {A : τ} ->
Functor.fmap (F-delay k) unit-right ∘ m-delay k A ⊤ ∘ (id * u-delay k) ≈ unit-right
unit-right-delay zero {A} {n} = refl
unit-right-delay (suc k) {A} {zero} = refl
unit-right-delay (suc k) {A} {suc n} = unit-right-delay k
unit-left-delay : ∀ k {B : τ} ->
Functor.fmap (F-delay k) unit-left ∘ m-delay k ⊤ B ∘ (u-delay k * id) ≈ unit-left
unit-left-delay zero = refl
unit-left-delay (suc k) {B} {zero} = refl
unit-left-delay (suc k) {B} {suc n} = unit-left-delay k
m-delay-+-n+0 : ∀ {A B} k l {a b}
-> (rew (delay-+-left0 k l)
(CartesianFunctor.m (F-cart-delay k) A B (k + l) (a , b)))
≡ (rew (delay-+-left0 k l) a , rew (delay-+-left0 k l) b)
m-delay-+-n+0 zero l = refl
m-delay-+-n+0 (suc k) l = m-delay-+-n+0 k l
m-delay-+-sym : ∀ {A B} k l m{a b}
-> rew (sym (delay-+ k m l))
(CartesianFunctor.m (F-cart-delay m) A B l (a , b))
≡ CartesianFunctor.m (F-cart-delay (k + m)) A B (k + l)
((rew (sym (delay-+ k m l)) a) , (rew (sym (delay-+ k m l)) b))
m-delay-+-sym zero l m = refl
m-delay-+-sym (suc k) l m = m-delay-+-sym k l m
| 39.158798
| 95
| 0.536278
|
1ee8b52c3c76d22bc329446faccbf4527d45b045
| 1,133
|
agda
|
Agda
|
src/Categories/Category/Discrete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
src/Categories/Category/Discrete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Discrete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Discrete where
open import Level
open import Data.Unit
open import Function
open import Relation.Binary.PropositionalEquality as ≡
open import Categories.Category
open import Categories.Functor
Discrete : ∀ {a} (A : Set a) → Category a a a
Discrete A = record
{ Obj = A
; _⇒_ = _≡_
; _≈_ = _≡_
; id = refl
; _∘_ = flip ≡.trans
; assoc = λ {_ _ _ _ g} → sym (trans-assoc g)
; sym-assoc = λ {_ _ _ _ g} → trans-assoc g
; identityˡ = λ {_ _ f} → trans-reflʳ f
; identityʳ = refl
; identity² = refl
; equiv = isEquivalence
; ∘-resp-≈ = λ where
refl refl → refl
}
module _ {a o ℓ e} {A : Set a} (C : Category o ℓ e) where
open Category C renaming (id to one)
module _ (f : A → Obj) where
lift-func : Functor (Discrete A) C
lift-func = record
{ F₀ = f
; F₁ = λ { refl → one }
; identity = Equiv.refl
; homomorphism = λ { {_} {_} {_} {refl} {refl} → Equiv.sym identity² }
; F-resp-≈ = λ { {_} {_} {refl} refl → Equiv.refl }
}
| 26.97619
| 76
| 0.556929
|
192c50dc5c3b5c3d7590d3c77a5ad4ac51948b8a
| 478
|
agda
|
Agda
|
test/fail/NoSizedTypes.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/NoSizedTypes.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/fail/NoSizedTypes.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
{-# OPTIONS --no-sized-types #-}
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {size ^}
suc : {size : Size} -> Nat {size} -> Nat {size ^}
weak : {i : Size} -> Nat {i} -> Nat {∞}
weak x = x
-- Should give error without sized types.
-- .i != ∞ of type Size
-- when checking that the expression x has type Nat
| 20.782609
| 52
| 0.552301
|
04a639e52b12ada9f9fb0e89b3ea113b1d0112d3
| 3,079
|
agda
|
Agda
|
src/STLC2/Kovacs/Normalisation/Experimental.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
src/STLC2/Kovacs/Normalisation/Experimental.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
src/STLC2/Kovacs/Normalisation/Experimental.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
module STLC2.Kovacs.Normalisation.Experimental where
open import STLC2.Kovacs.NormalForm public
--------------------------------------------------------------------------------
-- (Tyᴺ)
infix 3 _⊩_
_⊩_ : 𝒞 → 𝒯 → Set
Γ ⊩ ⎵ = Γ ⊢ⁿᶠ ⎵
Γ ⊩ A ⇒ B = ∀ {Γ′} → (η : Γ′ ⊇ Γ) (a : Γ′ ⊩ A)
→ Γ′ ⊩ B
Γ ⊩ A ⩕ B = Γ ⊩ A × Γ ⊩ B
Γ ⊩ ⫪ = ⊤
Γ ⊩ ⫫ = Γ ⊢ⁿᵉ ⫫
Γ ⊩ A ⩖ B = Γ ⊢ⁿᵉ A ⩖ B ⊎ (Γ ⊩ A ⊎ Γ ⊩ B)
-- (Conᴺ ; ∙ ; _,_)
infix 3 _⊩⋆_
data _⊩⋆_ : 𝒞 → 𝒞 → Set
where
∅ : ∀ {Γ} → Γ ⊩⋆ ∅
_,_ : ∀ {Γ Ξ A} → (ρ : Γ ⊩⋆ Ξ) (a : Γ ⊩ A)
→ Γ ⊩⋆ Ξ , A
--------------------------------------------------------------------------------
-- (Tyᴺₑ)
acc : ∀ {A Γ Γ′} → Γ′ ⊇ Γ → Γ ⊩ A → Γ′ ⊩ A
acc {⎵} η M = renⁿᶠ η M
acc {A ⇒ B} η f = λ η′ a → f (η ○ η′) a
acc {A ⩕ B} η s = acc η (proj₁ s) , acc η (proj₂ s)
acc {⫪} η s = tt
acc {⫫} η M = renⁿᵉ η M
acc {A ⩖ B} η s = case⊎ s (λ M → renⁿᵉ η M)
(λ t → case⊎ t (λ a → acc η a)
(λ b → acc η b))
-- (Conᴺₑ)
-- NOTE: _⬖_ = acc⋆
_⬖_ : ∀ {Γ Γ′ Ξ} → Γ ⊩⋆ Ξ → Γ′ ⊇ Γ → Γ′ ⊩⋆ Ξ
∅ ⬖ η = ∅
(ρ , a) ⬖ η = ρ ⬖ η , acc η a
--------------------------------------------------------------------------------
mutual
-- (qᴺ)
reify : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ⁿᶠ A
reify {⎵} M = M
reify {A ⇒ B} f = ƛ (reify (f (wkₑ idₑ) (reflect 0)))
reify {A ⩕ B} s = reify (proj₁ s) , reify (proj₂ s)
reify {⫪} s = τ
reify {⫫} M = ne M
reify {A ⩖ B} s = elim⊎ s (λ M → ne M)
(λ t → elim⊎ t (λ a → ι₁ (reify a))
(λ b → ι₂ (reify b)))
-- (uᴺ)
reflect : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊩ A
reflect {⎵} M = ne M
reflect {A ⇒ B} M = λ η a → reflect (renⁿᵉ η M ∙ reify a)
reflect {A ⩕ B} M = reflect (π₁ M) , reflect (π₂ M)
reflect {⫪} M = tt
reflect {⫫} M = M
reflect {A ⩖ B} M = inj₁ M
-- (∈ᴺ)
getᵥ : ∀ {Γ Ξ A} → Γ ⊩⋆ Ξ → Ξ ∋ A → Γ ⊩ A
getᵥ (ρ , a) zero = a
getᵥ (ρ , a) (suc i) = getᵥ ρ i
-- (Tmᴺ)
eval : ∀ {Γ Ξ A} → Γ ⊩⋆ Ξ → Ξ ⊢ A → Γ ⊩ A
eval ρ (𝓋 i) = getᵥ ρ i
eval ρ (ƛ M) = λ η a → eval (ρ ⬖ η , a) M
eval ρ (M ∙ N) = eval ρ M idₑ (eval ρ N)
eval ρ (M , N) = eval ρ M , eval ρ N
eval ρ (π₁ M) = proj₁ (eval ρ M)
eval ρ (π₂ M) = proj₂ (eval ρ M)
eval ρ τ = tt
eval ρ (φ M) = reflect (φ (eval ρ M))
eval ρ (ι₁ M) = inj₂ (inj₁ (eval ρ M))
eval ρ (ι₂ M) = inj₂ (inj₂ (eval ρ M))
eval ρ (M ⁇ N₁ ∥ N₂)
= elim⊎ (eval ρ M)
(λ M′ →
reflect (M′ ⁇ reify (eval (ρ ⬖ wkₑ idₑ , reflect 0) N₁)
∥ reify (eval (ρ ⬖ wkₑ idₑ , reflect 0) N₂)))
(λ t →
elim⊎ t (λ a → eval (ρ , a) N₁)
(λ b → eval (ρ , b) N₂))
-- (uᶜᴺ)
idᵥ : ∀ {Γ} → Γ ⊩⋆ Γ
idᵥ {∅} = ∅
idᵥ {Γ , A} = idᵥ ⬖ wkₑ idₑ , reflect 0
-- (nf)
nf : ∀ {Γ A} → Γ ⊢ A → Γ ⊢ⁿᶠ A
nf M = reify (eval idᵥ M)
--------------------------------------------------------------------------------
| 25.446281
| 80
| 0.337122
|
a0fa76304d5d357533359b5b064d71d8a179d036
| 17,638
|
agda
|
Agda
|
src/main-old.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/main-old.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/main-old.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
module main-old where
import parse
import run
open import lib
open import cedille-types
-- for parser for Cedille source files
import cedille
module parsem = parse cedille.gratr2-nt ptr
open parsem.pnoderiv cedille.rrs cedille.cedille-rtn
module pr = run ptr
open pr.noderiv {- from run.agda -}
-- for parser for options files
import options
import options-types
module parsem2 = parse options.gratr2-nt options-types.ptr
module options-parse = parsem2.pnoderiv options.rrs options.options-rtn
module pr2 = run options-types.ptr
module options-run = pr2.noderiv
-- for parser for Cedille comments & whitespace
import cws
import cws-types
module parsem3 = parse cws.gratr2-nt cws-types.ptr
module cws-parse = parsem3.pnoderiv cws.rrs cws.cws-rtn
module pr3 = run cws.ptr
module cws-run = pr3.noderiv
--open import cedille-find
--open import classify
open import ctxt
open import constants
--open import conversion
open import general-util
open import process-cmd
open import spans
open import syntax-util
open import to-string
open import toplevel-state
import interactive-cmds
open import rkt
opts : Set
opts = options-types.opts
{-------------------------------------------------------------------------------
.cede support
-------------------------------------------------------------------------------}
dot-cedille-directory : string → string
dot-cedille-directory dir = combineFileNames dir ".cedille"
cede-filename : (ced-path : string) → string
cede-filename ced-path =
let dir = takeDirectory ced-path in
let unit-name = base-filename (takeFileName ced-path) in
combineFileNames (dot-cedille-directory dir) (unit-name ^ ".cede")
-- .cede files are just a dump of the spans, prefixed by 'e' if there is an error
write-cede-file : (ced-path : string) → (ie : include-elt) → IO ⊤
write-cede-file ced-path ie =
-- putStrLn ("write-cede-file " ^ ced-path ^ " : " ^ contents) >>
let dir = takeDirectory ced-path in
createDirectoryIfMissing ff (dot-cedille-directory dir) >>
writeFile (cede-filename ced-path)
((if (include-elt.err ie) then "e" else "") ^
(include-elt-spans-to-string ie))
-- we assume the cede file is known to exist at this point
read-cede-file : (ced-path : string) → IO (𝔹 × string)
read-cede-file ced-path =
get-file-contents (cede-filename ced-path) >>= λ c → finish c
where finish : maybe string → IO (𝔹 × string)
finish nothing = return (tt , global-error-string ("Could not read the file " ^ cede-filename ced-path ^ "."))
finish (just ss) with string-to-𝕃char ss
finish (just ss) | ('e' :: ss') = forceFileRead ss >> return (tt , 𝕃char-to-string ss')
finish (just ss) | _ = forceFileRead ss >> return (ff , ss)
add-cedille-extension : string → string
add-cedille-extension x = x ^ "." ^ cedille-extension
find-imported-file : (dirs : 𝕃 string) → (unit-name : string) → IO string
find-imported-file [] unit-name = return (add-cedille-extension unit-name) -- assume the current directory if the unit is not found
find-imported-file (dir :: dirs) unit-name =
let e = combineFileNames dir (add-cedille-extension unit-name) in
doesFileExist e >>= λ b →
if b then
return e
else
find-imported-file dirs unit-name
-- return a list of pairs (i,p) where i is the import string in the file, and p is the full path for that imported file
find-imported-files : (dirs : 𝕃 string) → (imports : 𝕃 string) → IO (𝕃 (string × string))
find-imported-files dirs (u :: us) =
find-imported-file dirs u >>= λ p →
find-imported-files dirs us >>= λ ps →
return ((u , p) :: ps)
find-imported-files dirs [] = return []
ced-file-up-to-date : (ced-path : string) → IO 𝔹
ced-file-up-to-date ced-path =
let e = cede-filename ced-path in
doesFileExist e >>= λ b →
if b then
fileIsOlder ced-path e
else
return ff
paths-to-𝕃string : options-types.paths → 𝕃 string
paths-to-𝕃string options-types.PathsNil = []
paths-to-𝕃string (options-types.PathsCons p ps) = p :: paths-to-𝕃string ps
opts-get-include-path : opts → 𝕃 string
opts-get-include-path options-types.OptsNil = []
opts-get-include-path (options-types.OptsCons (options-types.Lib ps) oo) = (paths-to-𝕃string ps) ++ opts-get-include-path oo
opts-get-include-path (options-types.OptsCons options-types.NoCedeFiles oo) = opts-get-include-path oo
opts-get-include-path (options-types.OptsCons options-types.NoRktFiles oo) = opts-get-include-path oo
--opts-get-include-path (options-types.OptsCons _ oo) = opts-get-include-path oo
{- see if "no-cede-files" is turned on in the options file -}
opts-get-no-cede-files : opts → 𝔹
opts-get-no-cede-files options-types.OptsNil = ff
opts-get-no-cede-files (options-types.OptsCons options-types.NoCedeFiles oo) = tt
opts-get-no-cede-files (options-types.OptsCons options-types.NoRktFiles oo) = opts-get-no-cede-files oo
opts-get-no-cede-files (options-types.OptsCons (options-types.Lib _) oo) = opts-get-no-cede-files oo
{- see if "no-rkt-files" is turned on in the options file -}
opts-get-no-rkt-files : opts → 𝔹
opts-get-no-rkt-files options-types.OptsNil = ff
opts-get-no-rkt-files (options-types.OptsCons options-types.NoCedeFiles oo) = opts-get-no-rkt-files oo
opts-get-no-rkt-files (options-types.OptsCons options-types.NoRktFiles oo) = tt
opts-get-no-rkt-files (options-types.OptsCons (options-types.Lib _) oo) = opts-get-no-rkt-files oo
{- reparse the given file, and update its include-elt in the toplevel-state appropriately -}
reparse : toplevel-state → (filename : string) → IO toplevel-state
reparse st filename =
-- putStrLn ("reparsing " ^ filename) >>
doesFileExist filename >>= λ b →
(if b then
(readFiniteFile filename >>= processText)
else return (error-include-elt ("The file " ^ filename ^ " could not be opened for reading."))) >>= λ ie →
return (set-include-elt st filename ie)
where processText : string → IO include-elt
processText x with string-to-𝕃char x
processText x | s with runRtn s
processText x | s | inj₁ cs = return (error-include-elt ("Parse error in file " ^ filename ^ " at position " ^ (ℕ-to-string (length s ∸ length cs)) ^ "."))
processText x | s | inj₂ r with rewriteRun r
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] with cws-parse.runRtn s
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₁ cs = return (error-include-elt ("This shouldn't happen in " ^ filename ^ " at position "
^ (ℕ-to-string (length s ∸ length cs)) ^ "."))
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₂ r2 with cws-parse.rewriteRun r2
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₂ r2 | cws-run.ParseTree (cws-types.parsed-start t2) :: [] = find-imported-files (toplevel-state.include-path st)
(get-imports t) >>= λ deps → return
(new-include-elt filename deps t t2)
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₂ r2 | _ = return (error-include-elt ("Parse error in file " ^ filename ^ "."))
processText x | s | inj₂ r | _ = return (error-include-elt ("Parse error in file " ^ filename ^ "."))
add-spans-if-up-to-date : (up-to-date : 𝔹) → (use-cede-files : 𝔹) → (filename : string) → include-elt → IO include-elt
add-spans-if-up-to-date up-to-date use-cede-files filename ie =
if up-to-date && use-cede-files then
(read-cede-file filename >>= finish)
else
return ie
where finish : 𝔹 × string → IO include-elt
finish (err , ss) = return (set-do-type-check-include-elt (set-spans-string-include-elt ie err ss) ff)
{- make sure that the current ast and dependencies are stored in the
toplevel-state, updating the state as needed. -}
ensure-ast-deps : toplevel-state → (filename : string) → IO toplevel-state
ensure-ast-deps s filename with get-include-elt-if s filename
ensure-ast-deps s filename | nothing =
let ucf = (toplevel-state.use-cede-files s) in
reparse s filename >>= λ s →
ced-file-up-to-date filename >>= λ up-to-date →
add-spans-if-up-to-date up-to-date ucf filename (get-include-elt s filename) >>= λ ie →
return (set-include-elt s filename ie)
ensure-ast-deps s filename | just ie =
let ucf = (toplevel-state.use-cede-files s) in
ced-file-up-to-date filename >>= λ up-to-date →
if up-to-date then
(add-spans-if-up-to-date up-to-date (toplevel-state.use-cede-files s) filename (get-include-elt s filename) >>= λ ie →
return (set-include-elt s filename ie))
else reparse s filename
{- helper function for update-asts, which keeps track of the files we have seen so
we avoid importing the same file twice, and also avoid following cycles in the import
graph. -}
{-# TERMINATING #-}
update-astsh : stringset {- seen already -} → toplevel-state → (filename : string) →
IO (stringset {- seen already -} × toplevel-state)
update-astsh seen s filename =
-- putStrLn ("update-astsh [filename = " ^ filename ^ "]") >>
if stringset-contains seen filename then return (seen , s)
else (ensure-ast-deps s filename >>= cont (stringset-insert seen filename))
where cont : stringset → toplevel-state → IO (stringset × toplevel-state)
cont seen s with get-include-elt s filename
cont seen s | ie with include-elt.deps ie
cont seen s | ie | ds =
proc seen s ds
where proc : stringset → toplevel-state → 𝕃 string → IO (stringset × toplevel-state)
proc seen s [] =
if (list-any (get-do-type-check s) ds)
then return (seen , set-include-elt s filename (set-do-type-check-include-elt ie tt))
else return (seen , s)
proc seen s (d :: ds) = update-astsh seen s d >>= λ p →
proc (fst p) (snd p) ds
{- this function updates the ast associated with the given filename in the toplevel state.
So if we do not have an up-to-date .cede file (i.e., there is no such file at all,
or it is older than the given file), reparse the file. We do this recursively for all
dependencies (i.e., imports) of the file. -}
update-asts : toplevel-state → (filename : string) → IO toplevel-state
update-asts s filename = update-astsh empty-stringset s filename >>= λ p →
return (snd p)
{- this function checks the given file (if necessary), updates .cede and .rkt files (again, if necessary), and replies on stdout if appropriate -}
checkFile : toplevel-state → (filename : string) → (should-print-spans : 𝔹) → IO toplevel-state
checkFile s filename should-print-spans =
-- putStrLn ("checkFile " ^ filename) >>
update-asts s filename >>= λ s →
finish (process-file s filename) -- ignore-errors s filename)
where reply : toplevel-state → IO ⊤
reply s with get-include-elt-if s filename
reply s | nothing = putStrLn (global-error-string ("Internal error looking up information for file " ^ filename ^ "."))
reply s | just ie =
if should-print-spans then
putStrLn (include-elt-spans-to-string ie)
else return triv
finish : toplevel-state × mod-info → IO toplevel-state
finish (s , m) with s
finish (s , m) | mk-toplevel-state use-cede make-rkt ip mod is Γ =
writeo mod >>
reply s >>
return (mk-toplevel-state use-cede make-rkt ip [] is (ctxt-set-current-mod Γ m))
where
writeo : 𝕃 string → IO ⊤
writeo [] = return triv
writeo (f :: us) =
let ie = get-include-elt s f in
(if use-cede then (write-cede-file f ie) else (return triv)) >>
(if make-rkt then (write-rkt-file f (toplevel-state.Γ s) ie) else (return triv)) >>
writeo us
remove-dup-include-paths : 𝕃 string → 𝕃 string
remove-dup-include-paths l = stringset-strings (stringset-insert* empty-stringset l)
-- this is the function that handles requests (from the frontend) on standard input
{-# TERMINATING #-}
readCommandsFromFrontend : toplevel-state → IO ⊤
readCommandsFromFrontend s =
getLine >>= λ input →
let input-list : 𝕃 string
input-list = (string-split (undo-escape-string input) delimiter)
in (handleCommands input-list s) >>= λ s →
readCommandsFromFrontend s
where
delimiter : char
delimiter = '§'
errorCommand : 𝕃 string → toplevel-state → IO toplevel-state
errorCommand ls s = putStrLn (global-error-string "Invalid command sequence \"" ^ (𝕃-to-string (λ x → x) ", " ls) ^ "\".") >>= λ x → return s
debugCommand : toplevel-state → IO toplevel-state
debugCommand s = putStrLn (escape-string (toplevel-state-to-string s)) >>= λ x → return s
checkCommand : 𝕃 string → toplevel-state → IO toplevel-state
checkCommand (input :: []) s = canonicalizePath input >>= λ input-filename →
checkFile (set-include-path s (remove-dup-include-paths (takeDirectory input-filename :: toplevel-state.include-path s)))
input-filename tt {- should-print-spans -}
checkCommand ls s = errorCommand ls s
interactiveCommand : 𝕃 string → toplevel-state → IO toplevel-state
interactiveCommand xs s = interactive-cmds.interactive-cmd xs s
{- findCommand : 𝕃 string → toplevel-state → IO toplevel-state
findCommand (symbol :: []) s = putStrLn (find-symbols-to-JSON symbol (toplevel-state-lookup-occurrences symbol s)) >>= λ x → return s
findCommand _ s = errorCommand s -}
handleCommands : 𝕃 string → toplevel-state → IO toplevel-state
handleCommands ("check" :: xs) s = checkCommand xs s
handleCommands ("debug" :: []) s = debugCommand s
handleCommands ("interactive" :: xs) s = interactiveCommand xs s
-- handleCommands ("find" :: xs) s = findCommand xs s
handleCommands ls s = errorCommand ls s
-- function to process command-line arguments
processArgs : opts → 𝕃 string → IO ⊤
-- this is the case for when we are called with a single command-line argument, the name of the file to process
processArgs oo (input-filename :: []) =
canonicalizePath input-filename >>= λ input-filename →
checkFile (new-toplevel-state (takeDirectory input-filename :: opts-get-include-path oo) (~ (opts-get-no-cede-files oo)) (~ (opts-get-no-rkt-files oo)) )
input-filename ff {- should-print-spans -} >>= finish input-filename
where finish : string → toplevel-state → IO ⊤
finish input-filename s =
let ie = get-include-elt s input-filename in
if include-elt.err ie then (putStrLn (include-elt-spans-to-string ie)) else return triv
-- this is the case where we will go into a loop reading commands from stdin, from the fronted
processArgs oo [] = readCommandsFromFrontend (new-toplevel-state (opts-get-include-path oo) (~ (opts-get-no-cede-files oo)) (~ (opts-get-no-rkt-files oo)))
-- all other cases are errors
processArgs oo xs = putStrLn ("Run with the name of one file to process, or run with no command-line arguments and enter the\n"
^ "names of files one at a time followed by newlines (this is for the emacs mode).")
-- helper function to try to parse the options file
processOptions : string → string → (string ⊎ options-types.opts)
processOptions filename s with string-to-𝕃char s
... | i with options-parse.runRtn i
... | inj₁ cs =
inj₁ ("Parse error in file " ^ filename ^ " at position " ^ (ℕ-to-string (length i ∸ length cs)) ^ ".")
... | inj₂ r with options-parse.rewriteRun r
... | options-run.ParseTree (options-types.parsed-start (options-types.File oo)) :: [] = inj₂ oo
... | _ = inj₁ ("Parse error in file " ^ filename ^ ". ")
-- read the ~/.cedille/options file
readOptions : IO (string ⊎ options-types.opts)
readOptions =
getHomeDirectory >>= λ homedir →
let homecedir = dot-cedille-directory homedir in
let optsfile = combineFileNames homecedir options-file-name in
createDirectoryIfMissing ff homecedir >>
doesFileExist optsfile >>= λ b →
if b then
(readFiniteFile optsfile >>= λ f → return (processOptions optsfile f))
else
(return (inj₂ options-types.OptsNil))
postulate
initializeStdinToUTF8 : IO ⊤
setStdinNewlineMode : IO ⊤
{-# COMPILED initializeStdinToUTF8 System.IO.hSetEncoding System.IO.stdin System.IO.utf8 #-}
{-# COMPILED setStdinNewlineMode System.IO.hSetNewlineMode System.IO.stdin System.IO.universalNewlineMode #-}
-- main entrypoint for the backend
main : IO ⊤
main = initializeStdoutToUTF8 >>
initializeStdinToUTF8 >>
setStdoutNewlineMode >>
setStdinNewlineMode >>
readOptions >>=
next
where next : string ⊎ options-types.opts → IO ⊤
next (inj₁ s) = putStrLn (global-error-string s)
next (inj₂ oo) = getArgs >>= processArgs oo
| 49.824859
| 188
| 0.637884
|
8b6f41df7af223bc7659fddded1cf1ad6a9d9047
| 1,359
|
agda
|
Agda
|
archive/agda-1/Interpretation.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/Interpretation.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/Interpretation.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Interpretation where
open import VariableName
open import FunctionName
open import PredicateName
open import Element
open import Elements
open import TruthValue
record Interpretation : Set
where
field
μ⟦_⟧ : VariableName → Element
𝑓⟦_⟧ : FunctionName → Elements → Element
𝑃⟦_⟧ : PredicateName → Elements → TruthValue
open Interpretation public
open import OscarPrelude
open import Term
open import Delay
open import Vector
mutual
τ⇑⟦_⟧ : Interpretation → {i : Size} → Term → Delay i Element
τ⇑⟦ I ⟧ (variable 𝑥) = now $ μ⟦ I ⟧ 𝑥
τ⇑⟦ I ⟧ (function 𝑓 τs) = 𝑓⟦ I ⟧ 𝑓 ∘ ⟨_⟩ <$> τs⇑⟦ I ⟧ τs
τs⇑⟦_⟧ : Interpretation → {i : Size} → (τs : Terms) → Delay i (Vector Element (arity τs))
τs⇑⟦ I ⟧ ⟨ ⟨ [] ⟩ ⟩ = now ⟨ [] ⟩
τs⇑⟦ I ⟧ ⟨ ⟨ τ ∷ τs ⟩ ⟩ = τ⇑⟦ I ⟧ τ >>= (λ t → τs⇑⟦ I ⟧ ⟨ ⟨ τs ⟩ ⟩ >>= λ ts → now ⟨ t ∷ vector ts ⟩)
τs⇓⟦_⟧ : (I : Interpretation) → (τs : Terms) → τs⇑⟦ I ⟧ τs ⇓
τs⇓⟦ I ⟧ ⟨ ⟨ [] ⟩ ⟩ = _ , now⇓
τs⇓⟦ I ⟧ ⟨ ⟨ variable 𝑥 ∷ τs ⟩ ⟩ = _ , τs⇓⟦ I ⟧ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ now⇓
τs⇓⟦ I ⟧ ⟨ ⟨ function 𝑓₁ τs₁ ∷ τs₂ ⟩ ⟩ =
_ , τs⇓⟦ I ⟧ τs₁ ⇓>>=⇓ now⇓ >>=⇓ (τs⇓⟦ I ⟧ ⟨ ⟨ τs₂ ⟩ ⟩ ⇓>>=⇓ now⇓)
τ⇓⟦_⟧ : (I : Interpretation) → (τ : Term) → τ⇑⟦ I ⟧ τ ⇓
τ⇓⟦ I ⟧ (variable 𝑥) = _ , now⇓
τ⇓⟦ I ⟧ (function 𝑓 τs) = _ , τs⇓⟦ I ⟧ τs ⇓>>=⇓ now⇓
τ⟦_⟧ : (I : Interpretation) → {i : Size} → (τ : Term) → Element
τ⟦ I ⟧ τ = fst (τ⇓⟦ I ⟧ τ)
| 28.914894
| 102
| 0.538631
|
18db204ee459d244d3352f9fb864451465b18c7a
| 12,884
|
agda
|
Agda
|
theorems/homotopy/vankampen/CodeBP.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/vankampen/CodeBP.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/vankampen/CodeBP.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
{- Remember to keep CodeAP.agda in sync. -}
open import HoTT
import homotopy.RelativelyConstantToSetExtendsViaSurjection as SurjExt
module homotopy.vankampen.CodeBP {i j k l}
(span : Span {i} {j} {k})
{D : Type l} (h : D → Span.C span) (h-is-surj : is-surj h) where
open Span span
data precodeBB (b₀ : B) : B → Type (lmax (lmax (lmax i j) k) l)
data precodeBA (b₀ : B) (a₁ : A) : Type (lmax (lmax (lmax i j) k) l)
data precodeBB b₀ where
pc-b : ∀ {b₁} (pB : b₀ =₀ b₁) → precodeBB b₀ b₁
pc-bab : ∀ d {b₁} (pc : precodeBA b₀ (f (h d))) (pB : g (h d) =₀ b₁) → precodeBB b₀ b₁
infix 66 pc-b
syntax pc-b p = ⟧b p
infixl 65 pc-bab
syntax pc-bab d pcBA pB = pcBA ba⟦ d ⟧b pB
data precodeBA b₀ a₁ where
pc-bba : ∀ d (pc : precodeBB b₀ (g (h d))) (pA : f (h d) =₀ a₁) → precodeBA b₀ a₁
infixl 65 pc-bba
syntax pc-bba d pcBB pA = pcBB bb⟦ d ⟧a pA
data precodeBB-rel {b₀ : B} : {b₁ : B}
→ precodeBB b₀ b₁ → precodeBB b₀ b₁ → Type (lmax (lmax (lmax i j) k) l)
data precodeBA-rel {b₀ : B} : {a₁ : A}
→ precodeBA b₀ a₁ → precodeBA b₀ a₁ → Type (lmax (lmax (lmax i j) k) l)
data precodeBB-rel {b₀} where
pcBBr-idp₀-idp₀ : ∀ {d} pcBB → precodeBB-rel (pcBB bb⟦ d ⟧a idp₀ ba⟦ d ⟧b idp₀) pcBB
pcBBr-switch : ∀ {d₀ d₁ : D} pcBB (pC : h d₀ =₀ h d₁)
→ precodeBB-rel (pcBB bb⟦ d₀ ⟧a ap₀ f pC ba⟦ d₁ ⟧b idp₀) (pcBB bb⟦ d₀ ⟧a idp₀ ba⟦ d₀ ⟧b ap₀ g pC)
pcBBr-cong : ∀ {d b₁ pcBA₁ pcBA₂} (r : precodeBA-rel pcBA₁ pcBA₂) (pB : g (h d) =₀ b₁)
→ precodeBB-rel (pcBA₁ ba⟦ d ⟧b pB) (pcBA₂ ba⟦ d ⟧b pB)
data precodeBA-rel {b₀} where
pcBAr-idp₀-idp₀ : ∀ {d} pcBA → precodeBA-rel (pcBA ba⟦ d ⟧b idp₀ bb⟦ d ⟧a idp₀) pcBA
pcBAr-cong : ∀ {d a₁ pcBB₁ pcBB₂} (r : precodeBB-rel pcBB₁ pcBB₂) (pA : f (h d) =₀ a₁)
→ precodeBA-rel (pcBB₁ bb⟦ d ⟧a pA) (pcBB₂ bb⟦ d ⟧a pA)
codeBB : B → B → Type (lmax (lmax (lmax i j) k) l)
codeBB b₀ b₁ = SetQuot (precodeBB-rel {b₀} {b₁})
codeBA : B → A → Type (lmax (lmax (lmax i j) k) l)
codeBA b₀ a₁ = SetQuot (precodeBA-rel {b₀} {a₁})
c-bba : ∀ {a₀} d {a₁} (pc : codeBB a₀ (g (h d))) (pA : f (h d) =₀ a₁) → codeBA a₀ a₁
c-bba d {a₁} c pA = SetQuot-rec SetQuot-is-set
(λ pc → q[ pc-bba d pc pA ])
(λ r → quot-rel $ pcBAr-cong r pA) c
c-bab : ∀ {a₀} d {b₁} (pc : codeBA a₀ (f (h d))) (pB : g (h d) =₀ b₁) → codeBB a₀ b₁
c-bab d {a₁} c pB = SetQuot-rec SetQuot-is-set
(λ pc → q[ pc-bab d pc pB ])
(λ r → quot-rel $ pcBBr-cong r pB) c
-- codeBP
abstract
pcBB-idp₀-idp₀-head : ∀ {d₀ b} (pB : g (h d₀) =₀ b)
→ q[ ⟧b idp₀ bb⟦ d₀ ⟧a idp₀ ba⟦ d₀ ⟧b pB ] == q[ ⟧b pB ] :> codeBB _ b
pcBB-idp₀-idp₀-head {d₀} = Trunc-elim (λ _ → =-preserves-set SetQuot-is-set) lemma where
lemma : ∀ {b} (pB : g (h d₀) == b)
→ q[ ⟧b idp₀ bb⟦ d₀ ⟧a idp₀ ba⟦ d₀ ⟧b [ pB ] ] == q[ ⟧b [ pB ] ] :> codeBB _ b
lemma idp = quot-rel $ pcBBr-idp₀-idp₀ (⟧b idp₀)
pcBA-prepend : ∀ {b₀} d₁ {b₂} → b₀ =₀ g (h d₁) → precodeBA (g (h d₁)) b₂ → precodeBA b₀ b₂
pcBB-prepend : ∀ {b₀} d₁ {a₂} → b₀ =₀ g (h d₁) → precodeBB (g (h d₁)) a₂ → precodeBB b₀ a₂
pcBA-prepend d₁ pB (pc-bba d pc pA) = pc-bba d (pcBB-prepend d₁ pB pc) pA
pcBB-prepend d₁ pB (pc-b pB₁) = pc-bab d₁ (pc-bba d₁ (pc-b pB) idp₀) pB₁
pcBB-prepend d₁ pB (pc-bab d pc pB₁) = pc-bab d (pcBA-prepend d₁ pB pc) pB₁
abstract
pcBA-prepend-idp₀ : ∀ {d₀ b₁} (pcBA : precodeBA (g (h d₀)) b₁)
→ q[ pcBA-prepend d₀ idp₀ pcBA ] == q[ pcBA ] :> codeBA (g (h d₀)) b₁
pcBB-prepend-idp₀ : ∀ {d₀ a₁} (pcBB : precodeBB (g (h d₀)) a₁)
→ q[ pcBB-prepend d₀ idp₀ pcBB ] == q[ pcBB ] :> codeBB (g (h d₀)) a₁
pcBA-prepend-idp₀ (pc-bba d pc pB) = pcBB-prepend-idp₀ pc |in-ctx λ c → c-bba d c pB
pcBB-prepend-idp₀ (pc-b pB) = pcBB-idp₀-idp₀-head pB
pcBB-prepend-idp₀ (pc-bab d pc pB) = pcBA-prepend-idp₀ pc |in-ctx λ c → c-bab d c pB
transp-cBA-l : ∀ d {b₀ a₁} (p : g (h d) == b₀) (pcBA : precodeBA (g (h d)) a₁)
→ transport (λ x → codeBA x a₁) p q[ pcBA ] == q[ pcBA-prepend d [ ! p ] pcBA ]
transp-cBA-l d idp pcBA = ! $ pcBA-prepend-idp₀ pcBA
transp-cBB-l : ∀ d {b₀ b₁} (p : g (h d) == b₀) (pcBB : precodeBB (g (h d)) b₁)
→ transport (λ x → codeBB x b₁) p q[ pcBB ] == q[ pcBB-prepend d [ ! p ] pcBB ]
transp-cBB-l d idp pcBB = ! $ pcBB-prepend-idp₀ pcBB
transp-cBA-r : ∀ d {b₀ a₁} (p : f (h d) == a₁) (pcBA : precodeBA b₀ (f (h d)))
→ transport (λ x → codeBA b₀ x) p q[ pcBA ] == q[ pcBA ba⟦ d ⟧b idp₀ bb⟦ d ⟧a [ p ] ]
transp-cBA-r d idp pcBA = ! $ quot-rel $ pcBAr-idp₀-idp₀ pcBA
transp-cBB-r : ∀ d {b₀ b₁} (p : g (h d) == b₁) (pcBB : precodeBB b₀ (g (h d)))
→ transport (λ x → codeBB b₀ x) p q[ pcBB ] == q[ pcBB bb⟦ d ⟧a idp₀ ba⟦ d ⟧b [ p ] ]
transp-cBB-r d idp pcBB = ! $ quot-rel $ pcBBr-idp₀-idp₀ pcBB
module CodeBAEquivCodeBB (b₀ : B) where
eqv-on-image : (d : D) → codeBA b₀ (f (h d)) ≃ codeBB b₀ (g (h d))
eqv-on-image d = equiv to from to-from from-to where
to = λ c → c-bab d c idp₀
from = λ c → c-bba d c idp₀
abstract
from-to : ∀ cBA → from (to cBA) == cBA
from-to = SetQuot-elim
(λ _ → =-preserves-set SetQuot-is-set)
(λ pcBA → quot-rel (pcBAr-idp₀-idp₀ pcBA))
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))
to-from : ∀ cBB → to (from cBB) == cBB
to-from = SetQuot-elim
(λ _ → =-preserves-set SetQuot-is-set)
(λ pcBB → quot-rel (pcBBr-idp₀-idp₀ pcBB))
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))
abstract
eqv-is-const : ∀ d₁ d₂ (p : h d₁ == h d₂)
→ eqv-on-image d₁ == eqv-on-image d₂
[ (λ c → codeBA b₀ (f c) ≃ codeBB b₀ (g c)) ↓ p ]
eqv-is-const d₁ d₂ p = ↓-Subtype-in (λ d → is-equiv-prop) $
↓-→-from-transp $ λ= $
SetQuot-elim (λ _ → =-preserves-set SetQuot-is-set)
(λ pcBA →
transport (λ c → codeBB b₀ (g c)) p q[ pcBA ba⟦ d₁ ⟧b idp₀ ]
=⟨ ap-∘ (codeBB b₀) g p |in-ctx (λ p → coe p q[ pcBA ba⟦ d₁ ⟧b idp₀ ]) ⟩
transport (codeBB b₀) (ap g p) q[ pcBA ba⟦ d₁ ⟧b idp₀ ]
=⟨ transp-cBB-r d₁ (ap g p) (pcBA ba⟦ d₁ ⟧b idp₀) ⟩
q[ pcBA ba⟦ d₁ ⟧b idp₀ bb⟦ d₁ ⟧a idp₀ ba⟦ d₁ ⟧b [ ap g p ] ]
=⟨ ! $ quot-rel $ pcBBr-switch (pcBA ba⟦ d₁ ⟧b idp₀) [ p ] ⟩
q[ pcBA ba⟦ d₁ ⟧b idp₀ bb⟦ d₁ ⟧a [ ap f p ] ba⟦ d₂ ⟧b idp₀ ]
=⟨ ! $ transp-cBA-r d₁ (ap f p) pcBA |in-ctx (λ c → c-bab d₂ c idp₀) ⟩
c-bab d₂ (transport (codeBA b₀) (ap f p) q[ pcBA ]) idp₀
=⟨ ∘-ap (codeBA b₀) f p |in-ctx (λ p → coe p q[ pcBA ]) |in-ctx (λ c → c-bab d₂ c idp₀) ⟩
c-bab d₂ (transport (λ c → codeBA b₀ (f c)) p q[ pcBA ]) idp₀
=∎)
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))
module SE = SurjExt
(λ c → ≃-is-set SetQuot-is-set SetQuot-is-set)
h h-is-surj
eqv-on-image
eqv-is-const
abstract
eqv : ∀ c → codeBA b₀ (f c) ≃ codeBB b₀ (g c)
eqv = SE.ext
eqv-β : ∀ d → eqv (h d) == eqv-on-image d
eqv-β = SE.β
module CodeBP (b₀ : B) = PushoutRec (codeBA b₀) (codeBB b₀)
(ua ∘ CodeBAEquivCodeBB.eqv b₀)
codeBP : B → Pushout span → Type (lmax (lmax (lmax i j) k) l)
codeBP = CodeBP.f
abstract
codeBP-level : ∀ {a₀ p₁} → is-set (codeBP a₀ p₁)
codeBP-level {a₀} {p₁} = Pushout-elim
{P = λ p₁ → is-set (codeBP a₀ p₁)}
(λ a₁ → SetQuot-is-set)
(λ b₁ → SetQuot-is-set)
(λ c₁ → prop-has-all-paths-↓ is-set-is-prop)
p₁
codeBP-is-set = codeBP-level
abstract
transp-cBP-glue : ∀ {b₀} d₁ (pcBA : precodeBA b₀ (f (h d₁)))
→ transport (codeBP b₀) (glue (h d₁)) q[ pcBA ] == q[ pcBA ba⟦ d₁ ⟧b idp₀ ]
transp-cBP-glue {b₀} d₁ pcBA =
transport (codeBP b₀) (glue (h d₁)) q[ pcBA ]
=⟨ ap (λ e → coe e q[ pcBA ]) (CodeBP.glue-β b₀ (h d₁) ∙ ap ua (CodeBAEquivCodeBB.eqv-β b₀ d₁)) ⟩
coe (ua (CodeBAEquivCodeBB.eqv-on-image b₀ d₁)) q[ pcBA ]
=⟨ coe-β (CodeBAEquivCodeBB.eqv-on-image b₀ d₁) q[ pcBA ] ⟩
q[ pcBA ba⟦ d₁ ⟧b idp₀ ]
=∎
transp-cBP-!glue : ∀ {b₀} d₁ (pcBB : precodeBB b₀ (g (h d₁)))
→ transport (codeBP b₀) (! (glue (h d₁))) q[ pcBB ] == q[ pcBB bb⟦ d₁ ⟧a idp₀ ]
transp-cBP-!glue {b₀} d₁ pcBB =
transport (codeBP b₀) (! (glue (h d₁))) q[ pcBB ]
=⟨ ap (λ e → coe e q[ pcBB ]) (ap-! (codeBP b₀) (glue (h d₁)))
∙ coe-! (ap (codeBP b₀) (glue (h d₁))) q[ pcBB ] ⟩
transport! (codeBP b₀) (glue (h d₁)) q[ pcBB ]
=⟨ ap (λ e → coe! e q[ pcBB ]) (CodeBP.glue-β b₀ (h d₁) ∙ ap ua (CodeBAEquivCodeBB.eqv-β b₀ d₁)) ⟩
coe! (ua (CodeBAEquivCodeBB.eqv-on-image b₀ d₁)) q[ pcBB ]
=⟨ coe!-β (CodeBAEquivCodeBB.eqv-on-image b₀ d₁) q[ pcBB ] ⟩
q[ pcBB bb⟦ d₁ ⟧a idp₀ ]
=∎
-- code to path
pcBA-to-path : ∀ {b₀ a₁} → precodeBA b₀ a₁ → right b₀ =₀ left a₁ :> Pushout span
pcBB-to-path : ∀ {b₀ b₁} → precodeBB b₀ b₁ → right b₀ =₀ right b₁ :> Pushout span
pcBA-to-path (pc-bba d pc pA) = pcBB-to-path pc ∙₀' !₀ [ glue (h d) ] ∙₀' ap₀ left pA
pcBB-to-path (pc-b pB) = ap₀ right pB
pcBB-to-path (pc-bab d pc pB) = pcBA-to-path pc ∙₀' [ glue (h d) ] ∙₀' ap₀ right pB
abstract
pcBA-to-path-rel : ∀ {b₀ a₁} {pcBA₀ pcBA₁ : precodeBA b₀ a₁}
→ precodeBA-rel pcBA₀ pcBA₁ → pcBA-to-path pcBA₀ == pcBA-to-path pcBA₁
pcBB-to-path-rel : ∀ {b₀ b₁} {pcBB₀ pcBB₁ : precodeBB b₀ b₁}
→ precodeBB-rel pcBB₀ pcBB₁ → pcBB-to-path pcBB₀ == pcBB-to-path pcBB₁
pcBA-to-path-rel (pcBAr-idp₀-idp₀ pcBA) =
∙₀'-assoc (pcBA-to-path pcBA) [ glue (h _) ] [ ! (glue (h _)) ]
∙ ap (λ p → pcBA-to-path pcBA ∙₀' [ p ]) (!-inv'-r (glue (h _)))
∙ ∙₀'-unit-r (pcBA-to-path pcBA)
pcBA-to-path-rel (pcBAr-cong pcBB pA) = pcBB-to-path-rel pcBB |in-ctx _∙₀' !₀ [ glue (h _) ] ∙₀' ap₀ left pA
pcBB-to-path-rel (pcBBr-idp₀-idp₀ pcBB) =
∙₀'-assoc (pcBB-to-path pcBB) [ ! (glue (h _)) ] [ glue (h _) ]
∙ ap (λ p → pcBB-to-path pcBB ∙₀' [ p ]) (!-inv'-l (glue (h _)))
∙ ∙₀'-unit-r (pcBB-to-path pcBB)
pcBB-to-path-rel (pcBBr-switch pcBB pC) =
ap (_∙₀' [ glue (h _) ]) (! (∙₀'-assoc (pcBB-to-path pcBB) [ ! (glue (h _)) ] (ap₀ left (ap₀ f pC))))
∙ ∙₀'-assoc (pcBB-to-path pcBB ∙₀' [ ! (glue (h _)) ]) (ap₀ left (ap₀ f pC)) [ glue (h _) ]
∙ ap ((pcBB-to-path pcBB ∙₀' [ ! (glue (h _)) ]) ∙₀'_) (natural₀ pC)
where
natural : ∀ {c₀ c₁} (p : c₀ == c₁)
→ (ap left (ap f p) ∙' glue c₁) == (glue c₀ ∙' ap right (ap g p))
:> (left (f c₀) == right (g c₁) :> Pushout span)
natural idp = ∙'-unit-l (glue _)
natural₀ : ∀ {c₀ c₁} (p : c₀ =₀ c₁)
→ (ap₀ left (ap₀ f p) ∙₀' [ glue c₁ ]) == ([ glue c₀ ] ∙₀' ap₀ right (ap₀ g p))
:> (left (f c₀) =₀ right (g c₁) :> Pushout span)
natural₀ = Trunc-elim (λ _ → =-preserves-set Trunc-level) (ap [_] ∘ natural)
pcBB-to-path-rel (pcBBr-cong pcBA pB) = pcBA-to-path-rel pcBA |in-ctx _∙₀' [ glue (h _) ] ∙₀' ap₀ right pB
decodeBA : ∀ {b₀ a₁} → codeBA b₀ a₁ → right b₀ =₀ left a₁ :> Pushout span
decodeBB : ∀ {b₀ b₁} → codeBB b₀ b₁ → right b₀ =₀ right b₁ :> Pushout span
decodeBA = SetQuot-rec Trunc-level pcBA-to-path pcBA-to-path-rel
decodeBB = SetQuot-rec Trunc-level pcBB-to-path pcBB-to-path-rel
abstract
decodeBA-is-decodeBB : ∀ {b₀} c₁ →
decodeBA {b₀} {f c₁} == decodeBB {b₀} {g c₁}
[ (λ p₁ → codeBP b₀ p₁ → right b₀ =₀ p₁) ↓ glue c₁ ]
decodeBA-is-decodeBB {b₀ = b₀} = SurjExt.ext
(λ _ → ↓-preserves-level $ Π-is-set λ _ → Trunc-level) h h-is-surj
(λ d₁ → ↓-→-from-transp $ λ= $ SetQuot-elim
{P = λ cBA → transport (right b₀ =₀_) (glue (h d₁)) (decodeBA cBA)
== decodeBB (transport (codeBP b₀) (glue (h d₁)) cBA)}
(λ _ → =-preserves-set Trunc-level)
(λ pcBA →
transport (right b₀ =₀_) (glue (h d₁)) (pcBA-to-path pcBA)
=⟨ transp₀-cst=₀idf [ glue (h d₁) ] (pcBA-to-path pcBA) ⟩
pcBA-to-path pcBA ∙₀' [ glue (h d₁) ]
=⟨ ! $ ap (λ e → decodeBB (–> e q[ pcBA ])) (CodeBAEquivCodeBB.eqv-β b₀ d₁) ⟩
decodeBB (–> (CodeBAEquivCodeBB.eqv b₀ (h d₁)) q[ pcBA ])
=⟨ ! $ ap decodeBB (coe-β (CodeBAEquivCodeBB.eqv b₀ (h d₁)) q[ pcBA ]) ⟩
decodeBB (coe (ua (CodeBAEquivCodeBB.eqv b₀ (h d₁))) q[ pcBA ])
=⟨ ! $ ap (λ p → decodeBB (coe p q[ pcBA ])) (CodeBP.glue-β b₀ (h d₁)) ⟩
decodeBB (transport (codeBP b₀) (glue (h d₁)) q[ pcBA ])
=∎)
(λ _ → prop-has-all-paths-↓ $ Trunc-level {n = 0} _ _))
(λ _ _ _ → prop-has-all-paths-↓ $ ↓-level $ Π-is-set λ _ → Trunc-level)
decodeBP : ∀ {b₀ p₁} → codeBP b₀ p₁ → right b₀ =₀ p₁
decodeBP {p₁ = p₁} = Pushout-elim
(λ a₁ → decodeBA) (λ b₁ → decodeBB)
decodeBA-is-decodeBB
p₁
| 47.718519
| 112
| 0.540748
|
8b973f9c44c456cf4e758d63532ab04004aba2ea
| 5,620
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:00.000Z
|
2022-03-05T00:29:00.000Z
|
Cubical/Algebra/CommRing/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring.Base
open Iso
private
variable
ℓ ℓ' : Level
record IsCommRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor iscommring
field
isRing : IsRing 0r 1r _+_ _·_ -_
·Comm : (x y : R) → x · y ≡ y · x
open IsRing isRing public
record CommRingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor commringstr
field
0r : A
1r : A
_+_ : A → A → A
_·_ : A → A → A
-_ : A → A
isCommRing : IsCommRing 0r 1r _+_ _·_ -_
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsCommRing isCommRing public
CommRing : ∀ ℓ → Type (ℓ-suc ℓ)
CommRing ℓ = TypeWithStr ℓ CommRingStr
makeIsCommRing : {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R}
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-comm : (x y : R) → x · y ≡ y · x)
→ IsCommRing 0r 1r _+_ _·_ -_
makeIsCommRing {_+_ = _+_} is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm =
iscommring (makeIsRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid
(λ x → ·-comm _ _ ∙ ·-rid x) ·-rdist-+
(λ x y z → ·-comm _ _ ∙∙ ·-rdist-+ z x y ∙∙ λ i → (·-comm z x i) + (·-comm z y i))) ·-comm
makeCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-comm : (x y : R) → x · y ≡ y · x)
→ CommRing ℓ
makeCommRing 0r 1r _+_ _·_ -_ is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm =
_ , commringstr _ _ _ _ _ (makeIsCommRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm)
CommRingStr→RingStr : {A : Type ℓ} → CommRingStr A → RingStr A
CommRingStr→RingStr (commringstr _ _ _ _ _ H) = ringstr _ _ _ _ _ (IsCommRing.isRing H)
CommRing→Ring : CommRing ℓ → Ring ℓ
CommRing→Ring (_ , commringstr _ _ _ _ _ H) = _ , ringstr _ _ _ _ _ (IsCommRing.isRing H)
CommRingHom : (R : CommRing ℓ) (S : CommRing ℓ') → Type (ℓ-max ℓ ℓ')
CommRingHom R S = RingHom (CommRing→Ring R) (CommRing→Ring S)
IsCommRingEquiv : {A : Type ℓ} {B : Type ℓ'}
(R : CommRingStr A) (e : A ≃ B) (S : CommRingStr B) → Type (ℓ-max ℓ ℓ')
IsCommRingEquiv R e S = IsRingHom (CommRingStr→RingStr R) (e .fst) (CommRingStr→RingStr S)
CommRingEquiv : (R : CommRing ℓ) (S : CommRing ℓ') → Type (ℓ-max ℓ ℓ')
CommRingEquiv R S = Σ[ e ∈ (R .fst ≃ S .fst) ] IsCommRingEquiv (R .snd) e (S .snd)
CommRingEquiv→CommRingHom : {A : CommRing ℓ} {B : CommRing ℓ'} → CommRingEquiv A B → CommRingHom A B
CommRingEquiv→CommRingHom (e , eIsHom) = e .fst , eIsHom
isPropIsCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
→ isProp (IsCommRing 0r 1r _+_ _·_ -_)
isPropIsCommRing 0r 1r _+_ _·_ -_ (iscommring RR RC) (iscommring SR SC) =
λ i → iscommring (isPropIsRing _ _ _ _ _ RR SR i)
(isPropComm RC SC i)
where
isSetR : isSet _
isSetR = RR .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropComm : isProp ((x y : _) → x · y ≡ y · x)
isPropComm = isPropΠ2 λ _ _ → isSetR _ _
𝒮ᴰ-CommRing : DUARel (𝒮-Univ ℓ) CommRingStr ℓ
𝒮ᴰ-CommRing =
𝒮ᴰ-Record (𝒮-Univ _) IsCommRingEquiv
(fields:
data[ 0r ∣ null ∣ pres0 ]
data[ 1r ∣ null ∣ pres1 ]
data[ _+_ ∣ bin ∣ pres+ ]
data[ _·_ ∣ bin ∣ pres· ]
data[ -_ ∣ autoDUARel _ _ ∣ pres- ]
prop[ isCommRing ∣ (λ _ _ → isPropIsCommRing _ _ _ _ _) ])
where
open CommRingStr
open IsRingHom
-- faster with some sharing
null = autoDUARel (𝒮-Univ _) (λ A → A)
bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A)
CommRingPath : (R S : CommRing ℓ) → CommRingEquiv R S ≃ (R ≡ S)
CommRingPath = ∫ 𝒮ᴰ-CommRing .UARel.ua
uaCommRing : {A B : CommRing ℓ} → CommRingEquiv A B → A ≡ B
uaCommRing {A = A} {B = B} = equivFun (CommRingPath A B)
isSetCommRing : ((R , str) : CommRing ℓ) → isSet R
isSetCommRing (R , str) = str .CommRingStr.is-set
isGroupoidCommRing : isGroupoid (CommRing ℓ)
isGroupoidCommRing _ _ = isOfHLevelRespectEquiv 2 (CommRingPath _ _) (isSetRingEquiv _ _)
| 36.493506
| 115
| 0.555516
|
5eeabf3420c904053d139410b8ff1d08517e75e2
| 1,287
|
agda
|
Agda
|
src/Prelude/Char.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Prelude/Char.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Prelude/Char.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Prelude.Char where
open import Prelude.Bool
open import Prelude.Nat
open import Prelude.Equality
open import Prelude.Equality.Unsafe
open import Prelude.Decidable
open import Prelude.Function
open import Prelude.Ord
open import Agda.Builtin.Char
open Agda.Builtin.Char public using (Char)
isLower = primIsLower
isDigit = primIsDigit
isSpace = primIsSpace
isAscii = primIsAscii
isLatin1 = primIsLatin1
isPrint = primIsPrint
isHexDigit = primIsHexDigit
isAlpha = primIsAlpha
toUpper = primToUpper
toLower = primToLower
isAlphaNum : Char → Bool
isAlphaNum c = isAlpha c || isDigit c
charToNat = primCharToNat
natToChar = primNatToChar
charToNat-inj : ∀ {x y} → charToNat x ≡ charToNat y → x ≡ y
charToNat-inj {x} p with charToNat x
charToNat-inj refl | ._ = unsafeEqual -- need to be strict in the proof!
--- Equality --
eqChar : Char → Char → Bool
eqChar = eqNat on charToNat
instance
EqChar : Eq Char
_==_ {{EqChar}} x y with eqChar x y
... | false = no unsafeNotEqual
... | true = yes unsafeEqual
-- Missing primitive isUpper
isUpper : Char → Bool
isUpper c = isNo (toLower c == c)
--- Ord ---
instance
OrdChar : Ord Char
OrdChar = OrdBy charToNat-inj
OrdLawsChar : Ord/Laws Char
OrdLawsChar = OrdLawsBy charToNat-inj
| 21.45
| 73
| 0.724942
|
41854654c0943b14c4ab3fdb35150f8fa0f3d669
| 6,917
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Integer/DivMod.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Integer/DivMod.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Integer/DivMod.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Integer division
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Integer.DivMod where
open import Data.Nat as ℕ using (ℕ)
import Data.Nat.Properties as NProp
import Data.Nat.DivMod as NDM
import Data.Sign as S
import Data.Sign.Properties as SProp
open import Data.Integer as ℤ
open import Data.Integer.Properties
open import Data.Fin as Fin using (Fin)
import Data.Fin.Properties as FProp
open import Function
open import Relation.Nullary.Decidable
open import Relation.Binary.PropositionalEquality
infixl 7 _divℕ_ _div_ _modℕ_ _mod_
_divℕ_ : (dividend : ℤ) (divisor : ℕ) {≢0 : False (divisor ℕ.≟ 0)} → ℤ
(+ n divℕ d) {d≠0} = + (n NDM.div d) {d≠0}
(-[1+ n ] divℕ d) {d≠0} with (ℕ.suc n NDM.divMod d) {d≠0}
... | NDM.result q Fin.zero eq = - (+ q)
... | NDM.result q (Fin.suc r) eq = -[1+ q ]
_div_ : (dividend divisor : ℤ) {≢0 : False (∣ divisor ∣ ℕ.≟ 0)} → ℤ
(n div d) {d≢0} = (sign d ◃ 1) ℤ.* (n divℕ ∣ d ∣) {d≢0}
_modℕ_ : (dividend : ℤ) (divisor : ℕ) {≠0 : False (divisor ℕ.≟ 0)} → ℕ
(+ n modℕ d) {d≠0} = (n NDM.% d) {d≠0}
(-[1+ n ] modℕ d) {d≠0} with (ℕ.suc n NDM.divMod d) {d≠0}
... | NDM.result q Fin.zero eq = 0
... | NDM.result q (Fin.suc r) eq = d ℕ.∸ ℕ.suc (Fin.toℕ r)
_mod_ : (dividend divisor : ℤ) {≠0 : False (∣ divisor ∣ ℕ.≟ 0)} → ℕ
(n mod d) {d≢0} = (n modℕ ∣ d ∣) {d≢0}
n%ℕd<d : ∀ n d {d≢0} → (n modℕ d) {d≢0} ℕ.< d
n%ℕd<d n ℕ.zero {()}
n%ℕd<d (+ n) sd@(ℕ.suc d) = NDM.a%n<n n d
n%ℕd<d -[1+ n ] sd@(ℕ.suc d) with ℕ.suc n NDM.divMod sd
... | NDM.result q Fin.zero eq = ℕ.s≤s ℕ.z≤n
... | NDM.result q (Fin.suc r) eq = ℕ.s≤s (NProp.n∸m≤n (Fin.toℕ r) d)
n%d<d : ∀ n d {d≢0} → (n mod d) {d≢0} ℕ.< ℤ.∣ d ∣
n%d<d n (+ 0) {()}
n%d<d n (+ ℕ.suc d) = n%ℕd<d n (ℕ.suc d)
n%d<d n -[1+ d ] = n%ℕd<d n (ℕ.suc d)
a≡a%ℕn+[a/ℕn]*n : ∀ n d {d≢0} → n ≡ + (n modℕ d) {d≢0} + (n divℕ d) {d≢0} * + d
a≡a%ℕn+[a/ℕn]*n _ ℕ.zero {()}
a≡a%ℕn+[a/ℕn]*n (+ n) sd@(ℕ.suc d) = let q = n NDM.div sd; r = n NDM.% sd in begin
+ n ≡⟨ cong +_ (NDM.a≡a%n+[a/n]*n n d) ⟩
+ (r ℕ.+ q ℕ.* sd) ≡⟨ pos-+-commute r (q ℕ.* sd) ⟩
+ r + + (q ℕ.* sd) ≡⟨ cong (_+_ (+ (+ n modℕ sd))) (sym (pos-distrib-* q sd)) ⟩
+ r + + q * + sd ∎ where open ≡-Reasoning
a≡a%ℕn+[a/ℕn]*n -[1+ n ] sd@(ℕ.suc d) with (ℕ.suc n) NDM.divMod (ℕ.suc d)
... | NDM.result q Fin.zero eq = begin
-[1+ n ] ≡⟨ cong (-_ ∘′ +_) eq ⟩
- + (q ℕ.* sd) ≡⟨ cong -_ (sym (pos-distrib-* q sd)) ⟩
- (+ q * + sd) ≡⟨ neg-distribˡ-* (+ q) (+ sd) ⟩
- (+ q) * + sd ≡⟨ sym (+-identityˡ (- (+ q) * + sd)) ⟩
+ 0 + - (+ q) * + sd ∎ where open ≡-Reasoning
... | NDM.result q (Fin.suc r) eq = begin
let sd = ℕ.suc d; sr = ℕ.suc (Fin.toℕ r); sq = ℕ.suc q in
-[1+ n ]
≡⟨ cong (-_ ∘′ +_) eq ⟩
- + (sr ℕ.+ q ℕ.* sd)
≡⟨ cong -_ (pos-+-commute sr (q ℕ.* sd)) ⟩
- (+ sr + + (q ℕ.* sd))
≡⟨ neg-distrib-+ (+ sr) (+ (q ℕ.* sd)) ⟩
- + sr - + (q ℕ.* sd)
≡⟨ cong (_-_ (- + sr)) (sym (pos-distrib-* q sd)) ⟩
- + sr - (+ q) * (+ sd)
≡⟨⟩
- + sr - pred (+ sq) * (+ sd)
≡⟨ cong (_-_ (- + sr)) (*-distribʳ-+ (+ sd) (- + 1) (+ sq)) ⟩
- + sr - (- (+ 1) * + sd + (+ sq * + sd))
≡⟨ cong (_+_ (- (+ sr))) (neg-distrib-+ (- (+ 1) * + sd) (+ sq * + sd)) ⟩
- + sr + (- (-[1+ 0 ] * + sd) + - (+ sq * + sd))
≡⟨ cong₂ (λ p q → - + sr + (- p + q)) (-1*n≡-n (+ sd))
(neg-distribˡ-* (+ sq) (+ sd)) ⟩
- + sr + ((- - + sd) + -[1+ q ] * + sd)
≡⟨ sym (+-assoc (- + sr) (- - + sd) (-[1+ q ] * + sd)) ⟩
(+ sd - + sr) + -[1+ q ] * + sd
≡⟨ cong (_+ -[1+ q ] * + sd) (fin-inv d r) ⟩
+ (sd ℕ.∸ sr) + -[1+ q ] * + sd
∎ where
open ≡-Reasoning
fin-inv : ∀ d (k : Fin d) → + (ℕ.suc d) - + ℕ.suc (Fin.toℕ k) ≡ + (d ℕ.∸ Fin.toℕ k)
fin-inv (ℕ.suc n) Fin.zero = refl
fin-inv (ℕ.suc n) (Fin.suc k) = ⊖-≥ {n} {Fin.toℕ k} (NProp.<⇒≤ (FProp.toℕ<n k))
[n/ℕd]*d≤n : ∀ n d {d≢0} → (n divℕ d) {d≢0} ℤ.* ℤ.+ d ℤ.≤ n
[n/ℕd]*d≤n n ℕ.zero {()}
[n/ℕd]*d≤n n (ℕ.suc d) = let q = n divℕ ℕ.suc d; r = n modℕ ℕ.suc d in begin
q ℤ.* ℤ.+ (ℕ.suc d) ≤⟨ n≤m+n r ⟩
ℤ.+ r ℤ.+ q ℤ.* ℤ.+ (ℕ.suc d) ≡⟨ sym (a≡a%ℕn+[a/ℕn]*n n (ℕ.suc d)) ⟩
n ∎ where open ≤-Reasoning
div-pos-is-divℕ : ∀ n d {d≢0} → (n div + d) {d≢0} ≡ (n divℕ d) {d≢0}
div-pos-is-divℕ n ℕ.zero {()}
div-pos-is-divℕ n (ℕ.suc d) = *-identityˡ (n divℕ ℕ.suc d)
div-neg-is-neg-divℕ : ∀ n d {d≢0} {∣d∣≢0} → (n div (- ℤ.+ d)) {∣d∣≢0} ≡ - (n divℕ d) {d≢0}
div-neg-is-neg-divℕ n ℕ.zero {()}
div-neg-is-neg-divℕ n (ℕ.suc d) = -1*n≡-n (n divℕ ℕ.suc d)
0≤n⇒0≤n/ℕd : ∀ n d {d≢0} → + 0 ℤ.≤ n → + 0 ℤ.≤ (n divℕ d) {d≢0}
0≤n⇒0≤n/ℕd (+ n) d (+≤+ m≤n) = +≤+ ℕ.z≤n
0≤n⇒0≤n/d : ∀ n d {d≢0} → + 0 ℤ.≤ n → + 0 ℤ.≤ d → + 0 ℤ.≤ (n div d) {d≢0}
0≤n⇒0≤n/d n (+ d) {d≢0} 0≤n (+≤+ 0≤d)
rewrite div-pos-is-divℕ n d {d≢0}
= 0≤n⇒0≤n/ℕd n d 0≤n
[n/d]*d≤n : ∀ n d {d≢0} → (n div d) {d≢0} ℤ.* d ℤ.≤ n
[n/d]*d≤n n (+ 0) {()}
[n/d]*d≤n n (+ ℕ.suc d) = begin let sd = ℕ.suc d in
n div + sd * + sd ≡⟨ cong (_* (+ sd)) (div-pos-is-divℕ n sd) ⟩
n divℕ sd * + sd ≤⟨ [n/ℕd]*d≤n n sd ⟩
n ∎ where open ≤-Reasoning
[n/d]*d≤n n -[1+ d ] = begin let sd = ℕ.suc d in
n div (- + sd) * - + sd ≡⟨ cong (_* (- + sd)) (div-neg-is-neg-divℕ n sd) ⟩
- (n divℕ sd) * - + sd ≡⟨ sym (neg-distribˡ-* (n divℕ sd) (- + sd)) ⟩
- (n divℕ sd * - + sd) ≡⟨ neg-distribʳ-* (n divℕ sd) (- + sd) ⟩
n divℕ sd * + sd ≤⟨ [n/ℕd]*d≤n n sd ⟩
n ∎ where open ≤-Reasoning
n<s[n/ℕd]*d : ∀ n d {d≢0} → n ℤ.< ℤ.suc ((n divℕ d) {d≢0}) ℤ.* ℤ.+ d
n<s[n/ℕd]*d n ℕ.zero {()}
n<s[n/ℕd]*d n sd@(ℕ.suc d) = begin
suc n ≡⟨ cong suc (a≡a%ℕn+[a/ℕn]*n n sd) ⟩
suc (ℤ.+ r ℤ.+ q ℤ.* +sd) ≤⟨ +-monoˡ-< (q ℤ.* +sd) {ℤ.+ r} (ℤ.+≤+ (n%ℕd<d n sd)) ⟩
+sd ℤ.+ q ℤ.* +sd ≡⟨ sym ([1+m]*n≡n+m*n q +sd) ⟩
ℤ.suc q ℤ.* +sd ∎ where
q = n divℕ sd; +sd = ℤ.+ sd; r = n modℕ sd
open ≤-Reasoning
a≡a%n+[a/n]*n : ∀ a n {≢0} → a ≡ + (a mod n) {≢0} + (a div n) {≢0} * n
a≡a%n+[a/n]*n n (+ 0) {()}
a≡a%n+[a/n]*n n (+ ℕ.suc d) = begin
let sd = ℕ.suc d; r = n modℕ sd; q = n divℕ sd; qsd = q * + sd in
n ≡⟨ a≡a%ℕn+[a/ℕn]*n n sd ⟩
+ r + qsd ≡⟨ cong (λ p → + r + p * + sd) (sym (div-pos-is-divℕ n sd)) ⟩
+ r + n div + sd * + sd ∎ where open ≡-Reasoning
a≡a%n+[a/n]*n n -[1+ d ] = begin
let sd = ℕ.suc d; r = n modℕ sd; q = n divℕ sd; qsd = q * + sd in
n ≡⟨ a≡a%ℕn+[a/ℕn]*n n sd ⟩
+ r + q * + sd ≡⟨⟩
+ r + q * - -[1+ d ] ≡⟨ cong (_+_ (+ r)) (sym (neg-distribʳ-* q -[1+ d ])) ⟩
+ r + - (q * -[1+ d ]) ≡⟨ cong (_+_ (+ r)) (neg-distribˡ-* q -[1+ d ]) ⟩
+ r + - q * -[1+ d ] ≡⟨ cong (_+_ (+ r) ∘′ (_* -[1+ d ])) (sym (-1*n≡-n q)) ⟩
+ r + n div -[1+ d ] * -[1+ d ] ∎ where open ≡-Reasoning
| 41.419162
| 90
| 0.431401
|
4aab197725fc3d963bcb4d4e3f8c37467bb6dac2
| 10,315
|
agda
|
Agda
|
Agda/localizations-rings.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/localizations-rings.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/localizations-rings.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split #-}
module localizations-rings where
import subrings
open subrings public
is-invertible-Ring :
{l1 : Level} (R : Ring l1) (x : type-Ring R) → UU l1
is-invertible-Ring R =
is-invertible-Monoid (multiplicative-monoid-Ring R)
is-prop-is-invertible-Ring :
{l1 : Level} (R : Ring l1) (x : type-Ring R) →
is-prop (is-invertible-Ring R x)
is-prop-is-invertible-Ring R =
is-prop-is-invertible-Monoid (multiplicative-monoid-Ring R)
--------------------------------------------------------------------------------
{- We introduce homomorphism that invert specific elements -}
inverts-element-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (x : type-Ring R1) →
(f : hom-Ring R1 R2) → UU l2
inverts-element-hom-Ring R1 R2 x f =
is-invertible-Ring R2 (map-hom-Ring R1 R2 f x)
is-prop-inverts-element-hom-Ring :
{l1 l2 : Level} (R : Ring l1) (S : Ring l2) (x : type-Ring R)
(f : hom-Ring R S) → is-prop (inverts-element-hom-Ring R S x f)
is-prop-inverts-element-hom-Ring R S x f =
is-prop-is-invertible-Ring S (map-hom-Ring R S f x)
inv-inverts-element-hom-Ring :
{l1 l2 : Level} (R : Ring l1) (S : Ring l2) (x : type-Ring R)
(f : hom-Ring R S) → inverts-element-hom-Ring R S x f → type-Ring S
inv-inverts-element-hom-Ring R S x f H = pr1 H
is-left-inverse-inv-inverts-element-hom-Ring :
{l1 l2 : Level} (R : Ring l1) (S : Ring l2) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
Id ( mul-Ring S
( inv-inverts-element-hom-Ring R S x f H)
( map-hom-Ring R S f x))
( unit-Ring S)
is-left-inverse-inv-inverts-element-hom-Ring R S x f H = pr1 (pr2 H)
is-right-inverse-inv-inverts-element-hom-Ring :
{l1 l2 : Level} (R : Ring l1) (S : Ring l2) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
Id ( mul-Ring S
( map-hom-Ring R S f x)
( inv-inverts-element-hom-Ring R S x f H))
( unit-Ring S)
is-right-inverse-inv-inverts-element-hom-Ring R S x f H = pr2 (pr2 H)
inverts-element-comp-hom-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(g : hom-Ring S T) (f : hom-Ring R S) → inverts-element-hom-Ring R S x f →
inverts-element-hom-Ring R T x (comp-hom-Ring R S T g f)
inverts-element-comp-hom-Ring R S T x g f H =
pair
( map-hom-Ring S T g (inv-inverts-element-hom-Ring R S x f H))
( pair
( ( inv
( preserves-mul-hom-Ring S T g
( inv-inverts-element-hom-Ring R S x f H)
( map-hom-Ring R S f x))) ∙
( ( ap
( map-hom-Ring S T g)
( is-left-inverse-inv-inverts-element-hom-Ring R S x f H)) ∙
( preserves-unit-hom-Ring S T g)))
( ( inv
( preserves-mul-hom-Ring S T g
( map-hom-Ring R S f x)
( inv-inverts-element-hom-Ring R S x f H))) ∙
( ( ap
( map-hom-Ring S T g)
( is-right-inverse-inv-inverts-element-hom-Ring R S x f H)) ∙
( preserves-unit-hom-Ring S T g))))
{- We state the universal property of the localization of a Ring at a single
element x ∈ R. -}
precomp-universal-property-localization-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
hom-Ring S T → Σ (hom-Ring R T) (inverts-element-hom-Ring R T x)
precomp-universal-property-localization-Ring R S T x f H g =
pair (comp-hom-Ring R S T g f) (inverts-element-comp-hom-Ring R S T x g f H)
universal-property-localization-Ring :
(l : Level) {l1 l2 : Level} (R : Ring l1) (S : Ring l2) (x : type-Ring R)
(f : hom-Ring R S) → inverts-element-hom-Ring R S x f → UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-localization-Ring l R S x f H =
(T : Ring l) →
is-equiv (precomp-universal-property-localization-Ring R S T x f H)
unique-extension-universal-property-localization-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
universal-property-localization-Ring l3 R S x f H →
(h : hom-Ring R T) (K : inverts-element-hom-Ring R T x h) →
is-contr
(Σ (hom-Ring S T) (λ g → htpy-hom-Ring R T (comp-hom-Ring R S T g f) h))
unique-extension-universal-property-localization-Ring R S T x f H up-f h K =
is-contr-equiv'
( fib (precomp-universal-property-localization-Ring R S T x f H) (pair h K))
( equiv-tot ( λ g →
( equiv-htpy-hom-Ring-eq R T (comp-hom-Ring R S T g f) h) ∘e
( equiv-Eq-total-subtype-eq
( is-prop-inverts-element-hom-Ring R T x)
( precomp-universal-property-localization-Ring R S T x f H g)
( pair h K))))
( is-contr-map-is-equiv (up-f T) (pair h K))
center-unique-extension-universal-property-localization-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
universal-property-localization-Ring l3 R S x f H →
(h : hom-Ring R T) (K : inverts-element-hom-Ring R T x h) →
Σ (hom-Ring S T) (λ g → htpy-hom-Ring R T (comp-hom-Ring R S T g f) h)
center-unique-extension-universal-property-localization-Ring R S T x f H up-f h K =
center
( unique-extension-universal-property-localization-Ring
R S T x f H up-f h K)
map-universal-property-localization-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
universal-property-localization-Ring l3 R S x f H →
(h : hom-Ring R T) (K : inverts-element-hom-Ring R T x h) → hom-Ring S T
map-universal-property-localization-Ring R S T x f H up-f h K =
pr1 ( center-unique-extension-universal-property-localization-Ring
R S T x f H up-f h K)
htpy-universal-property-localization-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(f : hom-Ring R S) (H : inverts-element-hom-Ring R S x f) →
(up-f : universal-property-localization-Ring l3 R S x f H) →
(h : hom-Ring R T) (K : inverts-element-hom-Ring R T x h) →
htpy-hom-Ring R T (comp-hom-Ring R S T (map-universal-property-localization-Ring R S T x f H up-f h K) f) h
htpy-universal-property-localization-Ring R S T x f H up-f h K =
pr2 ( center-unique-extension-universal-property-localization-Ring
R S T x f H up-f h K)
{- We show that the type of localizations of a ring R at an element x is
contractible. -}
is-equiv-up-localization-up-localization-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3) (x : type-Ring R)
(f : hom-Ring R S) (inverts-f : inverts-element-hom-Ring R S x f) →
(g : hom-Ring R T) (inverts-g : inverts-element-hom-Ring R T x g) →
(h : hom-Ring S T) (H : htpy-hom-Ring R T (comp-hom-Ring R S T h f) g) →
({l : Level} → universal-property-localization-Ring l R S x f inverts-f) →
({l : Level} → universal-property-localization-Ring l R T x g inverts-g) →
is-iso-hom-Ring S T h
is-equiv-up-localization-up-localization-Ring R S T x f inverts-f g inverts-g h H up-f up-g = {!is-iso-is-equiv-hom-Ring!}
--------------------------------------------------------------------------------
{- We introduce homomorphisms that invert all elements of a subset of a ring -}
inverts-subset-hom-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (P : subset-Ring l3 R) →
(f : hom-Ring R S) → UU (l1 ⊔ l2 ⊔ l3)
inverts-subset-hom-Ring R S P f =
(x : type-Ring R) (p : type-Prop (P x)) → inverts-element-hom-Ring R S x f
is-prop-inverts-subset-hom-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (P : subset-Ring l3 R) →
(f : hom-Ring R S) → is-prop (inverts-subset-hom-Ring R S P f)
is-prop-inverts-subset-hom-Ring R S P f =
is-prop-Π (λ x → is-prop-Π (λ p → is-prop-inverts-element-hom-Ring R S x f))
inv-inverts-subset-hom-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (P : subset-Ring l3 R)
(f : hom-Ring R S) (H : inverts-subset-hom-Ring R S P f)
(x : type-Ring R) (p : type-Prop (P x)) → type-Ring S
inv-inverts-subset-hom-Ring R S P f H x p =
inv-inverts-element-hom-Ring R S x f (H x p)
is-left-inverse-inv-inverts-subset-hom-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (P : subset-Ring l3 R)
(f : hom-Ring R S) (H : inverts-subset-hom-Ring R S P f)
(x : type-Ring R) (p : type-Prop (P x)) →
Id (mul-Ring S (inv-inverts-subset-hom-Ring R S P f H x p) (map-hom-Ring R S f x)) (unit-Ring S)
is-left-inverse-inv-inverts-subset-hom-Ring R S P f H x p =
is-left-inverse-inv-inverts-element-hom-Ring R S x f (H x p)
is-right-inverse-inv-inverts-subset-hom-Ring :
{l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2) (P : subset-Ring l3 R)
(f : hom-Ring R S) (H : inverts-subset-hom-Ring R S P f)
(x : type-Ring R) (p : type-Prop (P x)) →
Id (mul-Ring S (map-hom-Ring R S f x) (inv-inverts-subset-hom-Ring R S P f H x p)) (unit-Ring S)
is-right-inverse-inv-inverts-subset-hom-Ring R S P f H x p =
is-right-inverse-inv-inverts-element-hom-Ring R S x f (H x p)
inverts-subset-comp-hom-Ring :
{l1 l2 l3 l4 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3)
(P : subset-Ring l4 R) (g : hom-Ring S T) (f : hom-Ring R S) →
inverts-subset-hom-Ring R S P f →
inverts-subset-hom-Ring R T P (comp-hom-Ring R S T g f)
inverts-subset-comp-hom-Ring R S T P g f H x p =
inverts-element-comp-hom-Ring R S T x g f (H x p)
{- We state the universal property of the localization of a Ring at a subset
of R. -}
precomp-universal-property-localization-subset-Ring :
{l1 l2 l3 l4 : Level} (R : Ring l1) (S : Ring l2) (T : Ring l3)
(P : subset-Ring l4 R) →
(f : hom-Ring R S) (H : inverts-subset-hom-Ring R S P f) →
hom-Ring S T → Σ (hom-Ring R T) (inverts-subset-hom-Ring R T P)
precomp-universal-property-localization-subset-Ring R S T P f H g =
pair (comp-hom-Ring R S T g f) (inverts-subset-comp-hom-Ring R S T P g f H)
universal-property-localization-subset-Ring :
(l : Level) {l1 l2 l3 : Level} (R : Ring l1) (S : Ring l2)
(P : subset-Ring l3 R) (f : hom-Ring R S) →
inverts-subset-hom-Ring R S P f → UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)
universal-property-localization-subset-Ring l R S P f H =
(T : Ring l) →
is-equiv (precomp-universal-property-localization-subset-Ring R S T P f H)
| 45.241228
| 122
| 0.619777
|
d18072d5e13904ade06c3ee413d8a32acfb05f51
| 10,462
|
agda
|
Agda
|
Algebra.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Algebra.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Algebra.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Algebra where
open import Prelude
module _ {a} {A : Type a} (_∙_ : A → A → A) where
Associative : Type a
Associative = ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
Commutative : Type _
Commutative = ∀ x y → x ∙ y ≡ y ∙ x
Idempotent : Type _
Idempotent = ∀ x → x ∙ x ≡ x
Identityˡ : (A → B → B) → A → Type _
Identityˡ _∙_ x = ∀ y → x ∙ y ≡ y
Zeroˡ : (A → B → A) → A → Type _
Zeroˡ _∙_ x = ∀ y → x ∙ y ≡ x
Zeroʳ : (A → B → B) → B → Type _
Zeroʳ _∙_ x = ∀ y → y ∙ x ≡ x
Identityʳ : (A → B → A) → B → Type _
Identityʳ _∙_ x = ∀ y → y ∙ x ≡ y
_Distributesʳ_ : (A → B → B) → (B → B → B) → Type _
_⊗_ Distributesʳ _⊕_ = ∀ x y z → x ⊗ (y ⊕ z) ≡ (x ⊗ y) ⊕ (x ⊗ z)
_Distributesˡ_ : (B → A → B) → (B → B → B) → Type _
_⊗_ Distributesˡ _⊕_ = ∀ x y z → (x ⊕ y) ⊗ z ≡ (x ⊗ z) ⊕ (y ⊗ z)
Cancellableˡ : (A → B → C) → A → Type _
Cancellableˡ _⊗_ c = ∀ x y → c ⊗ x ≡ c ⊗ y → x ≡ y
Cancellableʳ : (A → B → C) → B → Type _
Cancellableʳ _⊗_ c = ∀ x y → x ⊗ c ≡ y ⊗ c → x ≡ y
Cancellativeˡ : (A → B → C) → Type _
Cancellativeˡ _⊗_ = ∀ c → Cancellableˡ _⊗_ c
Cancellativeʳ : (A → B → C) → Type _
Cancellativeʳ _⊗_ = ∀ c → Cancellableʳ _⊗_ c
record Semigroup ℓ : Type (ℓsuc ℓ) where
infixl 6 _∙_
field
𝑆 : Type ℓ
_∙_ : 𝑆 → 𝑆 → 𝑆
assoc : ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
record Monoid ℓ : Type (ℓsuc ℓ) where
infixl 6 _∙_
field
𝑆 : Type ℓ
_∙_ : 𝑆 → 𝑆 → 𝑆
ε : 𝑆
assoc : ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
ε∙ : ∀ x → ε ∙ x ≡ x
∙ε : ∀ x → x ∙ ε ≡ x
semigroup : Semigroup ℓ
semigroup = record
{ 𝑆 = 𝑆; _∙_ = _∙_; assoc = assoc }
record MonoidHomomorphism_⟶_
{ℓ₁ ℓ₂}
(from : Monoid ℓ₁)
(to : Monoid ℓ₂)
: Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
open Monoid from
open Monoid to
renaming ( 𝑆 to 𝑅
; _∙_ to _⊙_
; ε to ⓔ
)
field
f : 𝑆 → 𝑅
∙-homo : ∀ x y → f (x ∙ y) ≡ f x ⊙ f y
ε-homo : f ε ≡ ⓔ
record Group ℓ : Type (ℓsuc ℓ) where
field
monoid : Monoid ℓ
open Monoid monoid public
field
-_ : 𝑆 → 𝑆
∙⁻ : ∀ x → x ∙ - x ≡ ε
⁻∙ : ∀ x → - x ∙ x ≡ ε
open import Path.Reasoning
cancelˡ : Cancellativeˡ _∙_
cancelˡ x y z p =
y ≡˘⟨ ε∙ y ⟩
ε ∙ y ≡˘⟨ cong (_∙ y) (⁻∙ x) ⟩
(- x ∙ x) ∙ y ≡⟨ assoc (- x) x y ⟩
- x ∙ (x ∙ y) ≡⟨ cong (- x ∙_) p ⟩
- x ∙ (x ∙ z) ≡˘⟨ assoc (- x) x z ⟩
(- x ∙ x) ∙ z ≡⟨ cong (_∙ z) (⁻∙ x) ⟩
ε ∙ z ≡⟨ ε∙ z ⟩
z ∎
cancelʳ : Cancellativeʳ _∙_
cancelʳ x y z p =
y ≡˘⟨ ∙ε y ⟩
y ∙ ε ≡˘⟨ cong (y ∙_) (∙⁻ x) ⟩
y ∙ (x ∙ - x) ≡˘⟨ assoc y x (- x) ⟩
(y ∙ x) ∙ - x ≡⟨ cong (_∙ - x) p ⟩
(z ∙ x) ∙ - x ≡⟨ assoc z x (- x) ⟩
z ∙ (x ∙ - x) ≡⟨ cong (z ∙_) (∙⁻ x) ⟩
z ∙ ε ≡⟨ ∙ε z ⟩
z ∎
record CommutativeMonoid ℓ : Type (ℓsuc ℓ) where
field
monoid : Monoid ℓ
open Monoid monoid public
field
comm : Commutative _∙_
record Semilattice ℓ : Type (ℓsuc ℓ) where
field
commutativeMonoid : CommutativeMonoid ℓ
open CommutativeMonoid commutativeMonoid public
field
idem : Idempotent _∙_
record NearSemiring ℓ : Type (ℓsuc ℓ) where
infixl 6 _+_
infixl 7 _*_
field
𝑅 : Type ℓ
_+_ : 𝑅 → 𝑅 → 𝑅
_*_ : 𝑅 → 𝑅 → 𝑅
1# : 𝑅
0# : 𝑅
+-assoc : Associative _+_
*-assoc : Associative _*_
0+ : Identityˡ _+_ 0#
+0 : Identityʳ _+_ 0#
1* : Identityˡ _*_ 1#
*1 : Identityʳ _*_ 1#
0* : Zeroˡ _*_ 0#
⟨+⟩* : _*_ Distributesˡ _+_
record Semiring ℓ : Type (ℓsuc ℓ) where
field
nearSemiring : NearSemiring ℓ
open NearSemiring nearSemiring public
field
+-comm : Commutative _+_
*0 : Zeroʳ _*_ 0#
*⟨+⟩ : _*_ Distributesʳ _+_
record IdempotentSemiring ℓ : Type (ℓsuc ℓ) where
field
semiring : Semiring ℓ
open Semiring semiring public
field
+-idem : Idempotent _+_
record CommutativeSemiring ℓ : Type (ℓsuc ℓ) where
field
semiring : Semiring ℓ
open Semiring semiring public
field
*-comm : Commutative _*_
record LeftSemimodule {ℓ₁} (semiring : Semiring ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where
open Semiring semiring public
field
semimodule : CommutativeMonoid ℓ₂
open CommutativeMonoid semimodule renaming (_∙_ to _∪_) public
renaming (𝑆 to 𝑉
; assoc to ∪-assoc
; ε∙ to ∅∪
; ∙ε to ∪∅
; ε to ∅
)
infixr 7 _⋊_
field
_⋊_ : 𝑅 → 𝑉 → 𝑉
⟨*⟩⋊ : ∀ x y z → (x * y) ⋊ z ≡ x ⋊ (y ⋊ z)
⟨+⟩⋊ : ∀ x y z → (x + y) ⋊ z ≡ (x ⋊ z) ∪ (y ⋊ z)
⋊⟨∪⟩ : _⋊_ Distributesʳ _∪_
1⋊ : Identityˡ _⋊_ 1#
0⋊ : ∀ x → 0# ⋊ x ≡ ∅
⋊∅ : ∀ x → x ⋊ ∅ ≡ ∅
record SemimoduleHomomorphism[_]_⟶_
{ℓ₁ ℓ₂ ℓ₃}
(rng : Semiring ℓ₁)
(from : LeftSemimodule rng ℓ₂)
(to : LeftSemimodule rng ℓ₃) : Type (ℓ₁ ℓ⊔ ℓsuc (ℓ₂ ℓ⊔ ℓ₃)) where
open Semiring rng
open LeftSemimodule from using (_⋊_; monoid)
open LeftSemimodule to using () renaming (_⋊_ to _⋊′_; monoid to monoid′)
field mon-homo : MonoidHomomorphism monoid ⟶ monoid′
open MonoidHomomorphism_⟶_ mon-homo public
field ⋊-homo : ∀ r x → f (r ⋊ x) ≡ r ⋊′ f x
record StarSemiring ℓ : Type (ℓsuc ℓ) where
field
semiring : Semiring ℓ
open Semiring semiring public
field
_⋆ : 𝑅 → 𝑅
star-iterʳ : ∀ x → x ⋆ ≡ 1# + x * x ⋆
star-iterˡ : ∀ x → x ⋆ ≡ 1# + x ⋆ * x
_⁺ : 𝑅 → 𝑅
x ⁺ = x * x ⋆
record Functor ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
map : (A → B) → 𝐹 A → 𝐹 B
map-id : map (id {ℓ₁} {A}) ≡ id
map-comp : (f : B → C) → (g : A → B) → map (f ∘ g) ≡ map f ∘ map g
record Applicative ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
functor : Functor ℓ₁ ℓ₂
open Functor functor public
infixl 5 _<*>_
field
pure : A → 𝐹 A
_<*>_ : 𝐹 (A → B) → 𝐹 A → 𝐹 B
map-ap : (f : A → B) → map f ≡ pure f <*>_
pure-homo : (f : A → B) → (x : A) → map f (pure x) ≡ pure (f x)
<*>-interchange : (u : 𝐹 (A → B)) → (y : A) → u <*> pure y ≡ map (_$ y) u
<*>-comp : (u : 𝐹 (B → C)) → (v : 𝐹 (A → B)) → (w : 𝐹 A) → pure _∘′_ <*> u <*> v <*> w ≡ u <*> (v <*> w)
record IsMonad {ℓ₁} {ℓ₂} (𝐹 : Type ℓ₁ → Type ℓ₂) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂) where
infixl 1 _>>=_
field
_>>=_ : 𝐹 A → (A → 𝐹 B) → 𝐹 B
return : A → 𝐹 A
>>=-idˡ : (f : A → 𝐹 B) → (x : A) → (return x >>= f) ≡ f x
>>=-idʳ : (x : 𝐹 A) → (x >>= return) ≡ x
>>=-assoc : (xs : 𝐹 A) (f : A → 𝐹 B) (g : B → 𝐹 C) → ((xs >>= f) >>= g) ≡ (xs >>= (λ x → f x >>= g))
record Monad ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
isMonad : IsMonad 𝐹
open IsMonad isMonad public
record MonadHomomorphism_⟶_
{ℓ₁ ℓ₂ ℓ₃}
(from : Monad ℓ₁ ℓ₂)
(to : Monad ℓ₁ ℓ₃) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₃) where
module F = Monad from
module T = Monad to
field
f : F.𝐹 A → T.𝐹 A
>>=-homo : (xs : F.𝐹 A) (k : A → F.𝐹 B) → (f xs T.>>= (f ∘ k)) ≡ f (xs F.>>= k)
return-homo : (x : A) → f (F.return x) ≡ T.return x
record IsSetMonad {ℓ₁} {ℓ₂} (𝐹 : Type ℓ₁ → Type ℓ₂) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂) where
infixl 1 _>>=_
field
_>>=_ : 𝐹 A → (A → 𝐹 B) → 𝐹 B
return : A → 𝐹 A
trunc : isSet A → isSet (𝐹 A)
>>=-idˡ : isSet B → (f : A → 𝐹 B) → (x : A) → (return x >>= f) ≡ f x
>>=-idʳ : isSet A → (x : 𝐹 A) → (x >>= return) ≡ x
>>=-assoc : isSet C → (xs : 𝐹 A) (f : A → 𝐹 B) (g : B → 𝐹 C) → ((xs >>= f) >>= g) ≡ (xs >>= (λ x → f x >>= g))
record SetMonad ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
isSetMonad : IsSetMonad 𝐹
open IsSetMonad isSetMonad public
record SetMonadHomomorphism_⟶_
{ℓ₁ ℓ₂ ℓ₃}
(from : SetMonad ℓ₁ ℓ₂)
(to : SetMonad ℓ₁ ℓ₃) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₃) where
module F = SetMonad from
module T = SetMonad to
field
f : F.𝐹 A → T.𝐹 A
>>=-homo : (xs : F.𝐹 A) (k : A → F.𝐹 B) → (f xs T.>>= (f ∘ k)) ≡ f (xs F.>>= k)
return-homo : (x : A) → f (F.return x) ≡ T.return x
record Alternative ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
applicative : Applicative ℓ₁ ℓ₂
open Applicative applicative public
field
0# : 𝐹 A
_<|>_ : 𝐹 A → 𝐹 A → 𝐹 A
<|>-idˡ : (x : 𝐹 A) → 0# <|> x ≡ x
<|>-idʳ : (x : 𝐹 A) → x <|> 0# ≡ x
0-annˡ : (x : 𝐹 A) → 0# <*> x ≡ 0# {B}
<|>-distrib : (x y : 𝐹 (A → B)) → (z : 𝐹 A) → (x <|> y) <*> z ≡ (x <*> z) <|> (y <*> z)
record MonadPlus ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
monad : Monad ℓ₁ ℓ₂
open Monad monad public
field
0# : 𝐹 A
_<|>_ : 𝐹 A → 𝐹 A → 𝐹 A
<|>-idˡ : (x : 𝐹 A) → 0# <|> x ≡ x
<|>-idʳ : (x : 𝐹 A) → x <|> 0# ≡ x
0-annˡ : (x : A → 𝐹 B) → (0# >>= x) ≡ 0#
<|>-distrib : (x y : 𝐹 A) → (z : A → 𝐹 B) → ((x <|> y) >>= z) ≡ (x >>= z) <|> (y >>= z)
Endo : Type a → Type a
Endo A = A → A
endoMonoid : ∀ {a} → Type a → Monoid a
endoMonoid A .Monoid.𝑆 = Endo A
endoMonoid A .Monoid.ε x = x
endoMonoid A .Monoid._∙_ f g x = f (g x)
endoMonoid A .Monoid.assoc _ _ _ = refl
endoMonoid A .Monoid.ε∙ _ = refl
endoMonoid A .Monoid.∙ε _ = refl
record Foldable ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
open Monoid ⦃ ... ⦄
field
foldMap : {A : Type ℓ₁} ⦃ _ : Monoid ℓ₁ ⦄ → (A → 𝑆) → 𝐹 A → 𝑆
foldr : {A B : Type ℓ₁} → (A → B → B) → B → 𝐹 A → B
foldr f b xs = foldMap ⦃ endoMonoid _ ⦄ f xs b
record GradedMonad {ℓ₁} (monoid : Monoid ℓ₁) ℓ₂ ℓ₃ : Type (ℓ₁ ℓ⊔ ℓsuc (ℓ₂ ℓ⊔ ℓ₃)) where
open Monoid monoid
field
𝐹 : 𝑆 → Type ℓ₂ → Type ℓ₃
pure : A → 𝐹 ε A
_>>=_ : ∀ {x y} → 𝐹 x A → (A → 𝐹 y B) → 𝐹 (x ∙ y) B
>>=-idˡ : ∀ {s} (f : A → 𝐹 s B) → (x : A) → (pure x >>= f) ≡[ i ≔ 𝐹 (ε∙ s i) B ]≡ (f x)
>>=-idʳ : ∀ {s} (x : 𝐹 s A) → (x >>= pure) ≡[ i ≔ 𝐹 (∙ε s i) A ]≡ x
>>=-assoc : ∀ {x y z} (xs : 𝐹 x A) (f : A → 𝐹 y B) (g : B → 𝐹 z C) → ((xs >>= f) >>= g) ≡[ i ≔ 𝐹 (assoc x y z i) C ]≡ (xs >>= (λ x → f x >>= g))
infixr 0 proven-bind
proven-bind : ∀ {x y z} → 𝐹 x A → (A → 𝐹 y B) → (x ∙ y) ≡ z → 𝐹 z B
proven-bind xs f proof = subst (flip 𝐹 _) proof (xs >>= f)
syntax proven-bind xs f proof = xs >>=[ proof ] f
infixr 0 proven-do
proven-do : ∀ {x y z} → 𝐹 x A → (A → 𝐹 y B) → (x ∙ y) ≡ z → 𝐹 z B
proven-do = proven-bind
syntax proven-do xs (λ x → e) proof = x ← xs [ proof ] e
map : ∀ {x} → (A → B) → 𝐹 x A → 𝐹 x B
map f xs = xs >>=[ ∙ε _ ] (pure ∘ f)
_<*>_ : ∀ {x y} → 𝐹 x (A → B) → 𝐹 y A → 𝐹 (x ∙ y) B
fs <*> xs = fs >>= flip map xs
_>>=ε_ : ∀ {x} → 𝐹 x A → (A → 𝐹 ε B) → 𝐹 x B
xs >>=ε f = xs >>=[ ∙ε _ ] f
| 27.824468
| 148
| 0.48289
|
43a0924a6494fafb41bfbea1c1a6c8905ccff775
| 1,830
|
agda
|
Agda
|
Label.agda
|
elpinal/subtyping-agda
|
fca08c53394f72c63d1bd7260fabfd70f73040b3
|
[
"Apache-2.0"
] | 10
|
2022-01-16T07:11:04.000Z
|
2022-01-17T17:17:26.000Z
|
Label.agda
|
elpinal/subtyping-agda
|
fca08c53394f72c63d1bd7260fabfd70f73040b3
|
[
"Apache-2.0"
] | null | null | null |
Label.agda
|
elpinal/subtyping-agda
|
fca08c53394f72c63d1bd7260fabfd70f73040b3
|
[
"Apache-2.0"
] | 1
|
2022-01-24T10:47:09.000Z
|
2022-01-24T10:47:09.000Z
|
{-# OPTIONS --cubical --safe #-}
module Label where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude using (isProp; transport)
open import Cubical.Data.Nat using (ℕ; zero; suc; isSetℕ)
open import Cubical.Data.Nat.Order using (_<_; _≤_; ≤-refl; <-weaken; ≤<-trans; m≤n-isProp; <-asym)
open import Cubical.Data.Maybe using (Maybe; nothing; just)
open import Cubical.Data.Empty using () renaming (rec to ⊥-elim)
Label : Set
Label = ℕ
data Record (A : Set) : Label -> Set where
nil : forall {l} -> Record A l
cons : forall {l} -> Record A l -> (l' : Label) -> A -> .(l < l') -> Record A l'
data _∈_ {A : Set} (l₁ : Label) {l : Label} : Record A l -> Set where
here : forall {l'} {r : Record A l'} {x lt} -> l₁ ≡ l -> l₁ ∈ cons r l x lt
there : forall {l'} {r : Record A l'} {x lt} -> l₁ ∈ r -> l₁ ∈ cons r l x lt
find : forall {A} {l} -> (l₁ : Label) -> (r : Record A l) -> l₁ ∈ r -> A
find l₁ (cons _ _ x _) (here e) = x
find l₁ (cons r _ _ _) (there l₁∈r) = find l₁ r l₁∈r
∈-implies-≤ : forall {A} {l l'} {r : Record A l'} -> l ∈ r -> l ≤ l'
∈-implies-≤ {l = l} (here e) = transport (λ i -> l ≤ e i) ≤-refl
∈-implies-≤ (there {lt = lt} l∈r) = <-weaken (≤<-trans (∈-implies-≤ l∈r) lt)
l∈r-isProp : forall {A} l {l'} (r : Record A l') -> isProp (l ∈ r)
l∈r-isProp l {l'} (cons _ _ _ _) (here {lt = a} e1) (here {lt = b} e2) = λ i -> here {lt = m≤n-isProp a b i} (isSetℕ l l' e1 e2 i)
l∈r-isProp l (cons {l = l₁} r _ _ _) (here {lt = k} e) (there y) = ⊥-elim (<-asym k (transport (λ i -> e i ≤ l₁) (∈-implies-≤ y)))
l∈r-isProp l (cons {l = l₁} r _ _ _) (there {lt = k} x) (here e) = ⊥-elim (<-asym k (transport (λ i -> e i ≤ l₁) (∈-implies-≤ x)))
l∈r-isProp l (cons r _ _ _) (there {lt = k1} x) (there {lt = k2} y) = let a = l∈r-isProp l r x y in λ i → there {lt = m≤n-isProp k1 k2 i} (a i)
| 50.833333
| 143
| 0.562842
|
046db4e252b79bfed7551ff4edf5f3eb01ce9186
| 117
|
agda
|
Agda
|
test/interaction/Issue1842.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue1842.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue1842.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS -v interaction.case:65 #-}
data Bool : Set where
true false : Bool
test : Bool → Bool
test x = {!x!}
| 14.625
| 38
| 0.615385
|
520565ae25c850ee1bd6d726711cf8ff97480c64
| 2,384
|
agda
|
Agda
|
agda/Heapsort/Impl2/Correctness/Permutation.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/Heapsort/Impl2/Correctness/Permutation.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/Heapsort/Impl2/Correctness/Permutation.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module Heapsort.Impl2.Correctness.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_ hiding (forget) renaming (flatten to flatten')
open import BBHeap.Compound _≤_
open import BBHeap.Drop _≤_ tot≤ trans≤
open import BBHeap.Drop.Properties _≤_ tot≤ trans≤
open import BBHeap.Heapify _≤_ tot≤ trans≤
open import BBHeap.Insert _≤_ tot≤ trans≤
open import BBHeap.Insert.Properties _≤_ tot≤ trans≤
open import BBHeap.Order _≤_
open import BBHeap.Order.Properties _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.List
open import Heapsort.Impl2 _≤_ tot≤ trans≤
open import List.Permutation.Base A
open import List.Permutation.Base.Equivalence A
open import OList _≤_
open import Order.Total _≤_ tot≤
lemma-flatten-flatten' : {b : Bound}(h : BBHeap b)(accₕ : Acc h) → forget (flatten h accₕ) ∼ flatten' h
lemma-flatten-flatten' leaf _ = ∼[]
lemma-flatten-flatten' (left {l = l} {r = r} b≤x l⋘r) (acc rs) = ∼x /head /head (trans∼ (lemma-flatten-flatten' (drop⋘ b≤x l⋘r) (rs (drop⋘ b≤x l⋘r) (lemma-drop≤′ (cl b≤x l⋘r)))) (lemma-drop⋘∼ b≤x l⋘r))
lemma-flatten-flatten' (right {l = l} {r = r} b≤x l⋙r) (acc rs) = ∼x /head /head (trans∼ (lemma-flatten-flatten' (drop⋙ b≤x l⋙r) (rs (drop⋙ b≤x l⋙r) (lemma-drop≤′ (cr b≤x l⋙r)))) (lemma-drop⋙∼ b≤x l⋙r))
lemma-flatten'-flatten : {b : Bound}(h : BBHeap b)(accₕ : Acc h) → (flatten' h) ∼ (forget (flatten h accₕ))
lemma-flatten'-flatten h tₕ = sym∼ (lemma-flatten-flatten' h tₕ)
theorem-heapsort∼ : (xs : List A) → xs ∼ forget (heapsort xs)
theorem-heapsort∼ [] = ∼[]
theorem-heapsort∼ (x ∷ xs) =
let h = heapify xs ;
accₕ = ≺-wf h ;
hᵢ = insert lebx h ;
accₕᵢ = ≺-wf hᵢ ;
xs∼fh = theorem-heapsort∼ xs ;
fh∼f'h = lemma-flatten-flatten' h accₕ ;
xs∼f'h = trans∼ xs∼fh fh∼f'h ;
xxs∼xf'h = ∼x /head /head xs∼f'h ;
xf'h∼f'hᵢ = lemma-insert∼ lebx h ;
xxs∼f'hᵢ = trans∼ xxs∼xf'h xf'h∼f'hᵢ ;
f'hᵢ∼fhᵢ = lemma-flatten'-flatten hᵢ accₕᵢ
in trans∼ xxs∼f'hᵢ f'hᵢ∼fhᵢ
| 48.653061
| 202
| 0.574245
|
43853de0cae4f6ac6d710571383ecb4dbac973a5
| 659
|
agda
|
Agda
|
test/Fail/Issue2231.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/Issue2231.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Fail/Issue2231.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Andreas, 2016-10-01, issue #2231
-- The termination checker should not always see through abstract definitions.
abstract
data Nat : Set where
zero' : Nat
suc' : Nat → Nat
-- abstract hides constructor nature of zero and suc.
zero = zero'
suc = suc'
data D : Nat → Set where
c1 : ∀ n → D n → D (suc n)
c2 : ∀ n → D n → D n
-- To see that this is terminating the termination checker has to look at the
-- natural number index, which is in a dot pattern.
f : ∀ n → D n → Nat
f .(suc n) (c1 n d) = f n (c2 n (c2 n d))
f n (c2 .n d) = f n d
-- Termination checking based on dot patterns should fail,
-- since suc is abstract.
| 26.36
| 78
| 0.629742
|
1eb9e8a05172d10013f4fa9c8b1e6bba6d11a784
| 395
|
agda
|
Agda
|
test/Succeed/Issue1159.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1159.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1159.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-02-02, issues 480, 1159, 1811
data Unit : Set where
unit : Unit
-- To make it harder for Agda, we make constructor unit ambiguous.
data Ambiguous : Set where
unit : Ambiguous
postulate
f : ∀{A : Set} → (A → A) → A
test : Unit
test = f \{ unit → unit }
-- Extended lambda checking should be postponed until
-- type A has been instantiated to Unit.
-- Should succeed.
| 19.75
| 66
| 0.673418
|
19ee748e216b6c81cded149d4c55f8038d56e70c
| 17,509
|
agda
|
Agda
|
old/Paths.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
old/Paths.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
old/Paths.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K #-}
open import Types
open import Functions
module Paths where
-- Identity type
infix 4 _≡_ -- \equiv
data _≡_ {i} {A : Set i} (a : A) : A → Set i where
refl : a ≡ a
_==_ = _≡_
_≢_ : ∀ {i} {A : Set i} → (A → A → Set i)
x ≢ y = ¬ (x ≡ y)
-- -- This should not be provable
-- K : {A : Set} → (x : A) → (p : x ≡ x) → p ≡ refl x
-- K .x (refl x) = refl
-- Composition and opposite of paths
infixr 8 _∘_ -- \o
_∘_ : ∀ {i} {A : Set i} {x y z : A} → (x ≡ y → y ≡ z → x ≡ z)
refl ∘ q = q
-- Composition with the opposite definitional behaviour
_∘'_ : ∀ {i} {A : Set i} {x y z : A} → (x ≡ y → y ≡ z → x ≡ z)
q ∘' refl = q
! : ∀ {i} {A : Set i} {x y : A} → (x ≡ y → y ≡ x)
! refl = refl
-- Equational reasoning combinator
infix 2 _∎
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : ∀ {i} {A : Set i} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ p1 ⟩ p2 = p1 ∘ p2
_∎ : ∀ {i} {A : Set i} (x : A) → x ≡ x
_∎ _ = refl
-- Obsolete, for retrocompatibility only
infixr 2 _≡⟨_⟩∎_
_≡⟨_⟩∎_ : ∀ {i} {A : Set i} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_≡⟨_⟩∎_ = _≡⟨_⟩_
-- Transport and ap
ap : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A}
→ (x ≡ y → f x ≡ f y)
ap f refl = refl
-- Make equational reasoning much more readable
syntax ap f p = p |in-ctx f
transport : ∀ {i j} {A : Set i} (P : A → Set j) {x y : A}
→ (x ≡ y → P x → P y)
transport P refl t = t
apd : ∀ {i j} {A : Set i} {P : A → Set j} (f : (a : A) → P a) {x y : A}
→ (p : x ≡ y) → transport P p (f x) ≡ f y
apd f refl = refl
apd! : ∀ {i j} {A : Set i} {P : A → Set j} (f : (a : A) → P a) {x y : A}
→ (p : x ≡ y) → f x ≡ transport P (! p) (f y)
apd! f refl = refl
-- Paths in Sigma types
module _ {i j} {A : Set i} {P : A → Set j} where
ap2 : ∀ {k} {Q : Set k} (f : (a : A) → P a → Q)
{x y : A} (p : x ≡ y) {u : P x} {v : P y}
(q : transport P p u ≡ v) → f x u ≡ f y v
ap2 f refl refl = refl
Σ-eq : {x y : A} (p : x ≡ y) {u : P x} {v : P y}
(q : transport P p u ≡ v) → (x , u) ≡ (y , v)
Σ-eq = ap2 _,_
-- Same as [Σ-eq] but with only one argument
total-Σ-eq : {xu yv : Σ A P}
(q : Σ (π₁ xu ≡ π₁ yv) (λ p → transport P p (π₂ xu) ≡ (π₂ yv)))
→ xu ≡ yv
total-Σ-eq (p , q) = Σ-eq p q
base-path : {x y : Σ A P} (p : x ≡ y) → π₁ x ≡ π₁ y
base-path = ap π₁
trans-base-path : {x y : Σ A P} (p : x ≡ y)
→ transport P (base-path p) (π₂ x) ≡ π₂ y
trans-base-path {_} {._} refl = refl
fiber-path : {x y : Σ A P} (p : x ≡ y)
→ transport P (base-path p) (π₂ x) ≡ π₂ y
fiber-path {x} {.x} refl = refl
abstract
base-path-Σ-eq : {x y : A} (p : x ≡ y) {u : P x} {v : P y}
(q : transport P p u ≡ v) → base-path (Σ-eq p q) ≡ p
base-path-Σ-eq refl refl = refl
fiber-path-Σ-eq : {x y : A} (p : x ≡ y) {u : P x} {v : P y}
(q : transport P p u ≡ v)
→ transport (λ t → transport P t u ≡ v) (base-path-Σ-eq p q)
(fiber-path (Σ-eq p q))
≡ q
fiber-path-Σ-eq refl refl = refl
Σ-eq-base-path-fiber-path : {x y : Σ A P} (p : x ≡ y)
→ Σ-eq (base-path p) (fiber-path p) ≡ p
Σ-eq-base-path-fiber-path {x} {.x} refl = refl
-- Some of the ∞-groupoid structure
module _ {i} {A : Set i} where
concat-assoc : {x y z t : A} (p : x ≡ y) (q : y ≡ z) (r : z ≡ t)
→ (p ∘ q) ∘ r ≡ p ∘ (q ∘ r)
concat-assoc refl _ _ = refl
-- [refl-left-unit] for _∘_ and [refl-right-unit] for _∘'_ are definitional
refl-right-unit : {x y : A} (q : x ≡ y) → q ∘ refl ≡ q
refl-right-unit refl = refl
refl-left-unit : {x y : A} (q : x ≡ y) → refl ∘' q ≡ q
refl-left-unit refl = refl
opposite-left-inverse : {x y : A} (p : x ≡ y) → (! p) ∘ p ≡ refl
opposite-left-inverse refl = refl
opposite-right-inverse : {x y : A} (p : x ≡ y) → p ∘ (! p) ≡ refl
opposite-right-inverse refl = refl
-- This is useless in the presence of ap & equation reasioning combinators
whisker-left : {x y z : A} (p : x ≡ y) {q r : y ≡ z}
→ (q ≡ r → p ∘ q ≡ p ∘ r)
whisker-left p refl = refl
-- This is useless in the presence of ap & equation reasioning combinators
whisker-right : {x y z : A} (p : y ≡ z) {q r : x ≡ y}
→ (q ≡ r → q ∘ p ≡ r ∘ p)
whisker-right p refl = refl
anti-whisker-right : {x y z : A} (p : y ≡ z) {q r : x ≡ y}
→ (q ∘ p ≡ r ∘ p → q ≡ r)
anti-whisker-right refl {q} {r} h =
! (refl-right-unit q) ∘ (h ∘ refl-right-unit r)
anti-whisker-left : {x y z : A} (p : x ≡ y) {q r : y ≡ z}
→ (p ∘ q ≡ p ∘ r → q ≡ r)
anti-whisker-left refl h = h
-- [opposite-concat …] gives a result of the form [opposite (concat …) ≡ …],
-- and so on
opposite-concat : {x y z : A} (p : x ≡ y) (q : y ≡ z) → ! (p ∘ q) ≡ ! q ∘ ! p
opposite-concat refl q = ! (refl-right-unit (! q))
concat-opposite : {x y z : A} (q : y ≡ z) (p : x ≡ y) → ! q ∘ ! p ≡ ! (p ∘ q)
concat-opposite q refl = refl-right-unit (! q)
opposite-opposite : {x y : A} (p : x ≡ y) → ! (! p) ≡ p
opposite-opposite refl = refl
-- Reduction rules for transport
module _ {i} {A : Set i} where
-- This first part is about transporting something in a known fibration. In
-- the names, [x] represents the variable of the fibration, [a] is a constant
-- term, [A] is a constant type, and [f] and [g] are constant functions.
trans-id≡cst : {a b c : A} (p : b ≡ c) (q : b ≡ a)
→ transport (λ x → x ≡ a) p q ≡ (! p) ∘ q
trans-id≡cst refl q = refl
trans-cst≡id : {a b c : A} (p : b ≡ c) (q : a ≡ b)
→ transport (λ x → a ≡ x) p q ≡ q ∘ p
trans-cst≡id refl q = ! (refl-right-unit q)
trans-app≡app : ∀ {j} {B : Set j} (f g : A → B) {x y : A} (p : x ≡ y)
(q : f x ≡ g x)
→ transport (λ x → f x ≡ g x) p q ≡ ! (ap f p) ∘ (q ∘ ap g p)
trans-app≡app f g refl q = ! (refl-right-unit q)
trans-move-app≡app : ∀ {j} {B : Set j} (f g : A → B) {x y : A} (p : x ≡ y)
(q : f x ≡ g x) {r : f y ≡ g y}
→ (q ∘ ap g p ≡ ap f p ∘ r → transport (λ x → f x ≡ g x) p q ≡ r)
trans-move-app≡app f g refl q h = ! (refl-right-unit q) ∘ h
trans-cst≡app : ∀ {j} {B : Set j} (a : B) (f : A → B) {x y : A} (p : x ≡ y)
(q : a ≡ f x)
→ transport (λ x → a ≡ f x) p q ≡ q ∘ ap f p
trans-cst≡app a f refl q = ! (refl-right-unit q)
trans-app≡cst : ∀ {j} {B : Set j} (f : A → B) (a : B) {x y : A} (p : x ≡ y)
(q : f x ≡ a)
→ transport (λ x → f x ≡ a) p q ≡ ! (ap f p) ∘ q
trans-app≡cst f a refl q = refl
trans-id≡app : (f : A → A) {x y : A} (p : x ≡ y) (q : x ≡ f x)
→ transport (λ x → x ≡ f x) p q ≡ ! p ∘ (q ∘ ap f p)
trans-id≡app f refl q = ! (refl-right-unit q)
trans-app≡id : (f : A → A) {x y : A} (p : x ≡ y) (q : f x ≡ x)
→ transport (λ x → f x ≡ x) p q ≡ ! (ap f p) ∘ (q ∘ p)
trans-app≡id f refl q = ! (refl-right-unit q)
trans-id≡id : {x y : A} (p : x ≡ y) (q : x ≡ x)
→ transport (λ x → x ≡ x) p q ≡ ! p ∘ (q ∘ p)
trans-id≡id refl q = ! (refl-right-unit _)
trans-cst : ∀ {j} {B : Set j} {x y : A} (p : x ≡ y) (q : B)
→ transport (λ _ → B) p q ≡ q
trans-cst refl q = refl
trans-Π2 : ∀ {j k} (B : Set j) (P : (x : A) (y : B) → Set k)
{b c : A} (p : b ≡ c) (q : (y : B) → P b y) (a : B)
→ transport (λ x → ((y : B) → P x y)) p q a
≡ transport (λ u → P u a) p (q a)
trans-Π2 B P refl q a = refl
trans-Π2-dep : ∀ {j k} (B : A → Set j) (P : (x : A) (y : B x) → Set k)
{a₁ a₂ : A} (p : a₁ ≡ a₂) (q : (y : B a₁) → P a₁ y) (b : B a₂)
→ transport (λ x → ((y : B x) → P x y)) p q b
≡ transport (uncurry P) (! (Σ-eq (! p) $ refl)) (q (transport B (! p) b))
trans-Π2-dep B P refl q b = refl
trans-→-trans : ∀ {j k} (B : A → Set j) (P : A → Set k)
{b c : A} (p : b ≡ c) (q : B b → P b) (a : B b)
→ transport (λ x → B x → P x) p q (transport B p a)
≡ transport P p (q a)
trans-→-trans B P refl q a = refl
trans-→ : ∀ {j k} (B : A → Set j) (P : A → Set k)
{b c : A} (p : b ≡ c) (q : B b → P b) (a : B c)
→ transport (λ x → B x → P x) p q a
≡ transport P p (q $ transport B (! p) a)
trans-→ B P refl q a = refl
-- This second part is about transporting something along a known path
trans-diag : ∀ {j} (P : A → A → Set j) {x y : A} (p : x ≡ y) (q : P x x)
→ transport (λ x → P x x) p q ≡ transport (λ z → P z y) p (transport (P x) p q)
trans-diag P refl q = refl
trans-concat : ∀ {j} (P : A → Set j) {x y z : A} (p : y ≡ z) (q : x ≡ y)
(u : P x)
→ transport P (q ∘ p) u ≡ transport P p (transport P q u)
trans-concat P p refl u = refl
compose-trans : ∀ {j} (P : A → Set j) {x y z : A} (p : y ≡ z) (q : x ≡ y)
(u : P x)
→ transport P p (transport P q u) ≡ transport P (q ∘ p) u
compose-trans P p refl u = refl
trans-ap : ∀ {j k} {B : Set j} (P : B → Set k) (f : A → B)
{x y : A} (p : x ≡ y) (u : P (f x))
→ transport P (ap f p) u ≡ transport (P ◯ f) p u
trans-ap P f refl u = refl
-- Unreadable, should be removed
trans-totalpath : ∀ {j k} (P : A → Set j) (Q : Σ A P → Set k) {x y : Σ A P}
(p : π₁ x ≡ π₁ y) (q : transport P p (π₂ x) ≡ π₂ y)
(f : (t : P (π₁ x)) → Q (π₁ x , t))
→ transport Q (Σ-eq p q) (f (π₂ x)) ≡
transport (λ x' → Q (π₁ y , x')) q
(transport (λ x' → (t : P x') → Q (x' , t)) p f
(transport P p (π₂ x)))
trans-totalpath P Q {(x₁ , x₂)} {(y₁ , y₂)} p q f =
trans-totalpath' P Q {x₁} {y₁} {x₂} {y₂} p q f where
trans-totalpath' : ∀ {j k} (P : A → Set j) (Q : Σ A P → Set k) {x₁ y₁ : A}
{x₂ : P x₁} {y₂ : P y₁}
(p : x₁ ≡ y₁) (q : transport P p (x₂) ≡ y₂) (f : (t : P x₁) → Q (x₁ , t))
→ transport Q (Σ-eq p q) (f x₂) ≡
transport (λ x' → Q (y₁ , x')) q
(transport (λ x' → (t : P x') → Q (x' , t)) p f
(transport P p x₂))
trans-totalpath' P Q refl refl f = refl
-- This third part is about various other convenient properties
trans-trans-opposite : ∀ {j} (P : A → Set j) {x y : A} (p : x ≡ y) (u : P y)
→ transport P p (transport P (! p) u) ≡ u
trans-trans-opposite P refl u = refl
trans-opposite-trans : ∀ {j} (P : A → Set j) {x y : A} (p : x ≡ y) (u : P x)
→ transport P (! p) (transport P p u) ≡ u
trans-opposite-trans P refl u = refl
ap-dep-trivial : ∀ {j} {B : Set j} (f : A → B) {x y : A} (p : x ≡ y)
→ ap f p ≡ ! (trans-cst p (f x)) ∘ apd f p
ap-dep-trivial f refl = refl
homotopy-naturality : ∀ {j} {B : Set j} (f g : A → B)
(p : (x : A) → f x ≡ g x) {x y : A} (q : x ≡ y)
→ ap f q ∘ p y ≡ p x ∘ ap g q
homotopy-naturality f g p refl = ! (refl-right-unit _)
homotopy-naturality-toid : (f : A -> A) (p : (x : A) → f x ≡ x)
{x y : A} (q : x ≡ y) → ap f q ∘ p y ≡ p x ∘ q
homotopy-naturality-toid f p refl = ! (refl-right-unit _)
homotopy-naturality-fromid : (g : A -> A) (p : (x : A) → x ≡ g x)
{x y : A} (q : x ≡ y) → q ∘ p y ≡ p x ∘ ap g q
homotopy-naturality-fromid g p refl = ! (refl-right-unit _)
opposite-ap : ∀ {j} {B : Set j} (f : A → B) {x y : A} (p : x ≡ y)
→ ! (ap f p) ≡ ap f (! p)
opposite-ap f refl = refl
ap-opposite : ∀ {j} {B : Set j} (f : A → B) {x y : A} (p : x ≡ y)
→ ap f (! p) ≡ ! (ap f p)
ap-opposite f refl = refl
concat-ap : ∀ {j} {B : Set j} (f : A → B) {x y z : A} (p : x ≡ y) (q : y ≡ z)
→ ap f p ∘ ap f q ≡ ap f (p ∘ q)
concat-ap f refl _ = refl
ap-concat : ∀ {j} {B : Set j} (f : A → B) {x y z : A} (p : x ≡ y) (q : y ≡ z)
→ ap f (p ∘ q) ≡ ap f p ∘ ap f q
ap-concat f refl _ = refl
compose-ap : ∀ {j k} {B : Set j} {C : Set k} (g : B → C) (f : A → B)
{x y : A} (p : x ≡ y) → ap g (ap f p) ≡ ap (g ◯ f) p
compose-ap f g refl = refl
ap-compose : ∀ {j k} {B : Set j} {C : Set k} (g : B → C) (f : A → B)
{x y : A} (p : x ≡ y) → ap (g ◯ f) p ≡ ap g (ap f p)
ap-compose f g refl = refl
ap-cst : ∀ {j} {B : Set j} (b : B) {x y : A} (p : x ≡ y)
→ ap (cst b) p ≡ refl
ap-cst b refl = refl
ap-id : {u v : A} (p : u ≡ v) → ap (id A) p ≡ p
ap-id refl = refl
app-trans : ∀ {j k} (B : A → Set j) (C : A → Set k) (f : ∀ x → B x → C x)
{x y} (p : x ≡ y) (a : B x)
→ f y (transport B p a) ≡ transport C p (f x a)
app-trans B C f refl a = refl
-- Move functions
-- These functions are used when the goal is to show that path is a
-- concatenation of two other paths, and that you want to prove it by moving a
-- path to the other side
--
-- The first [left/right] is the side (with respect to ≡) where will be the
-- path after moving (“after” means “after replacing the conclusion of the
-- proposition by its premisse”), and the second [left/right] is the side
-- (with respect to ∘) where the path is (and will still be)
-- If you want to prove something of the form [p ≡ q ∘ r] by moving [q] or [r]
-- to the left, use the functions move-left-on-left and move-left-on-right
-- If you want to prove something of the form [p ∘ q ≡ r] by moving [p] or [q]
-- to the right, use the functions move-right-on-left and move-right-on-right
-- Add a [0] after [move] if the big path is constant, a [1] if the other
-- small path is constant and then a [!] if the path you will move is an
-- opposite.
--
-- I’m not sure all of these functions are useful, but it can’t hurt to have
-- them.
move-left-on-left : {x y z : A} (p : x ≡ z) (q : x ≡ y) (r : y ≡ z)
→ ((! q) ∘ p ≡ r → p ≡ q ∘ r)
move-left-on-left p refl r h = h
move-left-on-right : {x y z : A} (p : x ≡ z) (q : x ≡ y) (r : y ≡ z)
→ (p ∘ (! r) ≡ q → p ≡ q ∘ r)
move-left-on-right p q refl h = ! (refl-right-unit p)
∘ (h ∘ ! (refl-right-unit q))
move-right-on-left : {x y z : A} (p : x ≡ y) (q : y ≡ z) (r : x ≡ z)
→ (q ≡ (! p) ∘ r → p ∘ q ≡ r)
move-right-on-left refl q r h = h
move-right-on-right : {x y z : A} (p : x ≡ y) (q : y ≡ z) (r : x ≡ z)
→ (p ≡ r ∘ (! q) → p ∘ q ≡ r)
move-right-on-right p refl r h = refl-right-unit p
∘ (h ∘ refl-right-unit r)
move!-left-on-left : {x y z : A} (p : x ≡ z) (q : y ≡ x) (r : y ≡ z)
→ (q ∘ p ≡ r → p ≡ (! q) ∘ r)
move!-left-on-left p refl r h = h
move!-left-on-right : {x y z : A} (p : x ≡ z) (q : x ≡ y) (r : z ≡ y)
→ (p ∘ r ≡ q → p ≡ q ∘ (! r))
move!-left-on-right p q refl h = ! (refl-right-unit p)
∘ (h ∘ ! (refl-right-unit q))
move!-right-on-left : {x y z : A} (p : y ≡ x) (q : y ≡ z) (r : x ≡ z)
→ (q ≡ p ∘ r → (! p) ∘ q ≡ r)
move!-right-on-left refl q r h = h
move!-right-on-right : {x y z : A} (p : x ≡ y) (q : z ≡ y) (r : x ≡ z)
→ (p ≡ r ∘ q → p ∘ (! q) ≡ r)
move!-right-on-right p refl r h = refl-right-unit p
∘ (h ∘ refl-right-unit r)
move0-left-on-left : {x y : A} (q : x ≡ y) (r : y ≡ x)
→ (! q ≡ r → refl ≡ q ∘ r)
move0-left-on-left refl r h = h
move0-left-on-right : {x y : A} (q : x ≡ y) (r : y ≡ x)
→ (! r ≡ q → refl ≡ q ∘ r)
move0-left-on-right q refl h = h ∘ ! (refl-right-unit q)
move0-right-on-left : {x y : A} (p : x ≡ y) (q : y ≡ x)
→ (q ≡ ! p → p ∘ q ≡ refl)
move0-right-on-left refl q h = h
move0-right-on-right : {x y : A} (p : x ≡ y) (q : y ≡ x)
→ (p ≡ ! q → p ∘ q ≡ refl)
move0-right-on-right p refl h = refl-right-unit p ∘ h
move0!-left-on-left : {x y : A} (q : y ≡ x) (r : y ≡ x)
→ (q ≡ r → refl ≡ (! q) ∘ r)
move0!-left-on-left refl r h = h
move0!-left-on-right : {x y : A} (q : x ≡ y) (r : x ≡ y)
→ (r ≡ q → refl ≡ q ∘ (! r))
move0!-left-on-right q refl h = h ∘ ! (refl-right-unit q)
move0!-right-on-left : {x y : A} (p : y ≡ x) (q : y ≡ x)
→ (q ≡ p → (! p) ∘ q ≡ refl)
move0!-right-on-left refl q h = h
move0!-right-on-right : {x y : A} (p : x ≡ y) (q : x ≡ y)
→ (p ≡ q → p ∘ (! q) ≡ refl)
move0!-right-on-right p refl h = refl-right-unit p ∘ h
move1-left-on-left : {x y : A} (p : x ≡ y) (q : x ≡ y)
→ ((! q) ∘ p ≡ refl → p ≡ q)
move1-left-on-left p refl h = h
move1-left-on-right : {x y : A} (p : x ≡ y) (r : x ≡ y)
→ (p ∘ (! r) ≡ refl → p ≡ r)
move1-left-on-right p refl h = ! (refl-right-unit p) ∘ h
move1-right-on-left : {x y : A} (p : x ≡ y) (r : x ≡ y)
→ (refl ≡ (! p) ∘ r → p ≡ r)
move1-right-on-left refl r h = h
move1-right-on-right : {x y : A} (q : x ≡ y) (r : x ≡ y)
→ (refl ≡ r ∘ (! q) → q ≡ r)
move1-right-on-right refl r h = h ∘ refl-right-unit r
move1!-left-on-left : {x y : A} (p : x ≡ y) (q : y ≡ x)
→ (q ∘ p ≡ refl → p ≡ ! q)
move1!-left-on-left p refl h = h
move1!-left-on-right : {x y : A} (p : x ≡ y) (r : y ≡ x)
→ (p ∘ r ≡ refl → p ≡ ! r)
move1!-left-on-right p refl h = ! (refl-right-unit p) ∘ h
move1!-right-on-left : {x y : A} (p : y ≡ x) (r : x ≡ y)
→ (refl ≡ p ∘ r → ! p ≡ r)
move1!-right-on-left refl r h = h
move1!-right-on-right : {x y : A} (q : y ≡ x) (r : x ≡ y)
→ (refl ≡ r ∘ q → ! q ≡ r)
move1!-right-on-right refl r h = h ∘ refl-right-unit r
move-transp-left : ∀ {j} (P : A → Set j) {x y : A} (u : P y) (p : x ≡ y)
(v : P x)
→ transport P (! p) u ≡ v → u ≡ transport P p v
move-transp-left P _ refl _ p = p
move-transp-right : ∀ {j} (P : A → Set j) {x y : A} (p : y ≡ x) (u : P y)
(v : P x)
→ u ≡ transport P (! p) v → transport P p u ≡ v
move-transp-right P refl _ _ p = p
move!-transp-left : ∀ {j} (P : A → Set j) {x y : A} (u : P y) (p : y ≡ x)
(v : P x)
→ transport P p u ≡ v → u ≡ transport P (! p) v
move!-transp-left P _ refl _ p = p
move!-transp-right : ∀ {j} (P : A → Set j) {x y : A} (p : x ≡ y) (u : P y)
(v : P x)
→ u ≡ transport P p v → transport P (! p) u ≡ v
move!-transp-right P refl _ _ p = p
| 35.587398
| 83
| 0.4721
|
1acb6ac5c1a7d786d71be3b137491b01288e1fcc
| 691
|
agda
|
Agda
|
test/Succeed/Issue2422.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2422.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2422.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-01-21, issue #2422 overloading inherited projections
-- {-# OPTIONS -v tc.proj.amb:100 #-}
-- {-# OPTIONS -v tc.mod.apply:100 #-}
postulate
A : Set
record R : Set where
field f : A
record S : Set where
field r : R
open R r public
-- The inherited projection (in the eyes of the scope checker) S.f
-- is actually a composition of projections R.f ∘ S.r
-- s .S.f = s .S.r .R.f
open R -- works without this
open S
test : S → A
test s = f s
-- f is not really a projection, but a composition of projections
-- it would be nice if overloading is still allowed.
-- Error WAS:
-- Cannot resolve overloaded projection f because no matching candidate found
| 23.827586
| 77
| 0.672938
|
43f2470d19aec492fe80589ed4ceeff8eb0c919d
| 12,661
|
agda
|
Agda
|
agda/paper/2009-09-Algebra_of_programming_in_Agda/x.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/paper/2009-09-Algebra_of_programming_in_Agda/x.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/paper/2009-09-Algebra_of_programming_in_Agda/x.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module x where
{-
------------------------------------------------------------------------------
Abstract
Relational program derivation technique :
- stepwise refining a relational spec to a program by algebraic rules.
- program obtained is correct by construction
Dependent type theory rich enough to express correctness properties verified by type checker.
Library, Algebra of Programming in Agda (AoPA)
- http://www.iis.sinica.edu.tw/~scm/2008/aopa/
- encodes relational derivations
- A program is coupled with an algebraic derivation whose correctness is guaranteed by type system
------------------------------------------------------------------------------
1 Introduction
relational program derivation
- specs are input-output relations that are stepwise refined by an algebra of programs.
paper show how program derivation can be encoded in a type and its proof term.
- case study using Curry-Howard isomorphism
- modelled a many concepts that occur in relational program derivation
including relational folds, relational division, and converse-of-a-function.
- e.g., Minimum, is defined using division and intersection
- e.g., greedy theorem proved using the universal property of minimum.
- the theorem can be used to deal with a number of optimisation problems specified as folds.
• to ensure termination with unfolds and hylomorphisms, enable programmer to
model an unfold as the relational converse of a fold, but demand a proof of accessibility
before it is refined to a functional unfold.
------------------------------------------------------------------------------
2 Overview of Relational Program Derivation
Merit of functional programming : programs can be manipulated by equational reasoning.
Program derivation in Bird-Meertens style 1989b) typically start with a specification,
as a function, that is obviously correct but not efficient.
Algebraic identities are then applied, in successive steps,
to show that the specification equals another functional program that is more efficient.
Typical example : Maximum Segment Sum (Gries, 1989; Bird, 1989a), specification :
max · map sum · segs
where
- segs produces all consecutive segments of the input list of numbers
- map sum computes their summation
- maximum is picked by max
Specification can be shown, after transformation, to be equal a version using foldr (linear).
In 90’s there was a trend in the program derivation community to move from functions to relations.
- spec given in terms of an input/output relation
- relation is refined to smaller, more deterministic relations in each step,
- until obtaining a function
Relational derivation advantages:
- spec often more concise than corresponding functional specification
- optimisation problems can be specified using relations generating all possible solutions
- easier to talk about program inversion
The catch: *must reason in terms of inequalities rather than equalities*
denoted by R : B ← A
- relation R from A to B
- subset of set of pairs B × A
- A function f is seen as a special case where (b, a) ∈ f and (b' , a) ∈ f implies b = b'
converse R˘ : A ← B of R : B ← A
- defined by (a, b) ∈ R ˘ if (b, a) ∈ R
composition of two relations R : C ← B and S : B ← A
- defined by: (c, a) ∈ R ◦ S if ∃b : (c, b) ∈ R ∧ (b, a) ∈ S
power transpose ΛR of R : B ← A
- is a function from A to P B (subsets of B)
- ΛR a = { b | (b, a) ∈ R }.
relation ∈ : A ← P A
- maps a set to one of its arbitrary members
- converse: ∋ : P A ← A
product of two relations, R × S
- defined by ((c, d), (a, b)) ∈ R × S if (c, a) ∈ R and (d, b) ∈ S
-- step fun base input output
foldr : (A → B → B) → B → List A → B
generalisation to a relation, denote foldR
input step relation base cases
foldR R : B ← List A ← (B ← (A×B)) (set s : PB)
-- relation mapping a list to one of its arbitrary subsequences
subseq = foldR (cons ∪ outr) {[ ]}
where
cons (x, xs) = x :: xs -- cons keeps the current element
outr (x, xs) = xs -- outr drops the current element
Relational fold defined in terms of functional fold:
foldR R s = ∈ ◦ foldr Λ(R ◦ (id " ∈)) s
of type List A → P B that collects all the results in a set.
step function Λ(R ◦ (id " ∈)) : has type (A × P B) → P B
(id " ∈) : (A × B) ← (A × P B) : pairs current element with one of the results from previous step
before passing the pair to R
foldR R s satisfies the universal property:
foldR R s = S ⇔ R ◦ (id " S) = S ◦ cons ∧ s = ΛS [ ]
-- induction rule
-- states that foldR R s is the unique fixed-point of the monotonic function
λ X → (R ◦ (id " X) ◦ cons ˘) ∪ {(b, [ ]) | b ∈ s}
-- computation rule
-- foldR R s is also the least prefix-point, therefore
foldR R s ⊆ S ⇐ R ◦ (id " S) ⊆ S ◦ cons ∧ s ⊆ ΛS [ ],
R ◦ (id " foldR R s) ⊆ foldR R s ◦ cons ∧ s ⊆ Λ(foldR R s) [ ].
If an optimisation problem can be specified by generating all possible solutions using
foldR or converse of foldR before picking the best one, Bird and de Moor (1997) gave a
number of conditions under which the specification can be refined to a greedy algorithm, a
dynamic programming algorithm, or something in-between.
------------------------------------------------------------------------------
3 A Crash Course in Agda
-}
-- Fig. 2. Some examples of datatype definitions.
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
data _≤_ : ℕ → ℕ → Set where
≤-refl : {n : ℕ} → n ≤ n
≤-step : {m n : ℕ} → m ≤ n → m ≤ suc n
_<_ : ℕ → ℕ → Set
m < n = suc m ≤ n
-- Fig. 3. An encoding of first-order intuitionistic logic in Agda.
-- Truth : has one unique term — a record with no fields
record ⊤ : Set where
-- Falsity : type with no constructors therefore no inhabitants
data ⊥ : Set where
-- Disjunction : proof deduced either from a proof of P or a proof of Q
data _⨄_ (A B : Set) : Set where
inj1 : A → A ⨄ B
inj2 : B → A ⨄ B
-- Dependent Pair : type of 2nd may depend on the first component
data Σ (A : Set)(B : A → Set) : Set where
_,_ : (x : A) → (y : B x) → Σ A B
proj₁ : ∀ {A B} → Σ A B → A
proj₁ (x , y) = x
proj₂ : ∀ {A B} → (p : Σ A B) → B (proj₁ p)
proj₂ (x , y) = y
-- Conjunction
_×_ : (A B : Set) → Set
A × B = Σ A (λ _ → B)
-- Existential Quantification
-- to prove the proposition ∃ P, where P is a predicate on terms of type A
-- provide, in a pair, a witness w : A and a proof of P w.
∃ : {A : Set} (P : A → Set) → Set
∃ = Σ _
-- Universal Quantification
-- of predicate P on type A is encoded as a dependent function type
-- whose elements, given any x : A, must produce a proof of P x.
-- Agda provides a short hand ∀ x → P x in place of (x : A) → P x when A can be inferred.
-- Implication
-- P → Q is represented as a function taking a proof of P to a proof of Q
-- no new notation for it
-- Predicates
-- on type A are represented by A → Set.
-- e.g., (λ n → zero < n) : N → Set
-- is a predicate stating that a natural number is positive.
{-
3.2 Identity Type
term of type x ≡ y is proof x and y are equal
-}
data _≡_ {A : Set}(x : A) : A → Set where
≡-refl : x ≡ x
-- REFLEXIVE : by definition
-- SYMMETRIC
≡-sym : {A : Set}{x y : A} → x ≡ y → y ≡ x
≡-sym {A}{x}{.x} ≡-refl = ≡-refl
-- TRANSITIVE
≡-trans : {A : Set}{x y z : A} → x ≡ y → y ≡ z → x ≡ z
≡-trans {A}{x}{.x}{z} ≡-refl x≡z = x≡z -- could replace x≡z with ≡-refl
-- SUBSTITUTIVE — if x ≡ y, they are interchangeable in all contexts
≡-subst : {A : Set}(P : A → Set){x y : A} → x ≡ y → P x → P y
≡-subst P ≡-refl Px = Px
≡-cong : {A B : Set}(f : A → B){x y : A} → x ≡ y → f x ≡ f y
≡-cong f ≡-refl = ≡-refl
{-
≡ NOT EXTENSIONAL
Qquality of terms is checked by expanding them to normal forms.
Problem comparing higher-order values: e.g., sum·map sum and sum · concat
while defining the same function summing up a list of lists of numbers, are not “equal” under ≡ .
Can define extensional equality for (non-dependent) functions on first-order values:
-}
_≐_ : {A B : Set} → (A → B) → (A → B) → Set
f ≐ g = ∀ x → f x ≡ g x
{-
≐ NOT SUBSTITUTIVE : congruence of ≐ has to be proved for each context.
Refinement in preorder reasoning usually involves replacing terms in provably monotonic contexts.
This is a significant overhead; but given that this overhead
is incurred anyway, not having extensional equality is no extra trouble.
3.3 Preorder Reasoning
To prove e1 ≡ e2 is to construct a term having that type.
For any binary relation ∼ that is reflexive and transitive
- for which one can construct terms ∼-refl and ∼-trans having the types described in above
can derive a set of combinators, shown in Fig. 4,
which enables one to construct a term of type e₁ ∼ en in algebraic style.
-- Fig. 4. Combinators for preorder reasoning.
infixr 2 _∼⟨_⟩_
infix 2 _∼∎
_∼⟨_⟩_ : {A : Set}(x : A){y z : A} → x ∼ y → y ∼ z → x ∼ z
x ∼⟨ x∼y ⟩ y∼z = ∼-trans x∼y y∼z
_∼∎ : {A : Set}(x : A) → x ∼ x
x ∼∎ = ∼-refl
implication as a relation:
-}
_⇒_ : Set → Set → Set
P ⇒ Q = P → Q
_⇐_ : Set → Set → Set
P ⇐ Q = Q ⇒ P
{-
Reflexivity and transitivity of ⇐ , for example, can be simply given by ⇐-refl = id and
⇐-trans = · , where · is function composition. Therefore, they induce a pair of operators
_⇐⟨_⟩_ and ⇐∎ for logical reasoning.
Hierarchy of universes
- Set, the type of small types, is in sort Set1
When instantiating ∼ in Fig. 4 to ⇐ : Set → Set → Set
- notice that the type A : Set itself cannot be instantiated to Set, which is in Set1
We resolve this by using different module generators for different universes.
More on this in Sect. 4.1.
3.4 Functional Derivation
Since _≐_ is reflexive and transitive (not shown), it induces its preorder reasoning operators.
Fig. 5 shows a proof of the universal property of foldr.
The steps using ≡-refl are equivalences Agda proves by expanding definitions.
The inductive hypothesis is established by a recursive call to foldr-universal.
-}
infix 3 _≡∎
infixr 2 _≡⟨⟩_ _≡⟨_⟩_
infix 1 begin_
begin_ : {A : Set} {x y : A} → x ≡ y → x ≡ y
begin_ x≡y = x≡y
_≡⟨⟩_ : {A : Set} (x {y} : A) → x ≡ y → x ≡ y
_ ≡⟨⟩ x≡y = x≡y
_≡⟨_⟩_ : {A : Set} (x {y z} : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = ≡-trans x≡y y≡z
_≡∎ : {A : Set} (x : A) → x ≡ x
_≡∎ _ = ≡-refl
{-
Fig. 5. Proving the universal property for foldr
-}
foldr : {A B : Set}
→ (A → B → B) → B → List A
→ B
foldr f e [] = e
foldr f e (x ∷ xs) = f x (foldr f e xs)
{- https://www.cs.nott.ac.uk/~pszgmh/fold.pdf
For finite lists, the universal property of fold can be stated as the following equivalence
between two definitions for a function g that processes lists:
g [] = v
⇔ g = fold f v
g (x ∷ xs) = f x (g xs)
right-to-left : substituting g = fold f v into the two equations for g gives recursive fold def
left-to-right : two equations for g are the assumptions required to show that g = fold f v
using a simple proof by induction on finite lists (Bird, 1998)
universal property states that for finite lists the function fold f v is not just a
solution to its defining equations, but the unique solution.
Utility of universal property : makes explicit the two assumptions
required for a certain pattern of inductive proof.
For specific cases, by verifying the two assumptions (typically done without need for induction)
can then appeal to the universal property to complete the inductive proof that g = fold f v.
universal PROPERTY of fold : encapsulates a pattern of inductive proof concerning lists
just as the fold OPERATOR : encapsulates a pattern of recursion for processing lists
-}
foldr-universal : ∀ {A B} (h : List A → B) f e
→ (h [] ≡ e)
→ (∀ x xs → h (x ∷ xs) ≡ f x (h xs))
→ h ≐ foldr f e
foldr-universal h f e base step [] = base
foldr-universal h f e base step (x ∷ xs) =
begin
h (x ∷ xs)
≡⟨ step x xs ⟩
f x (h xs)
≡⟨ ≡-cong (f x) (foldr-universal h f e base step xs) ⟩
f x (foldr f e xs)
≡⟨ ≡-refl ⟩
foldr f e (x ∷ xs)
≡∎
{-
-- Can use the universal property to prove the foldr-fusion theorem:
_·_ : {A : Set} {B : A → Set} {C : (x : A) → B x → Set}
→ (f : {x : A} (y : B x) → C x y)
→ (g : (x : A) → B x)
→ (x : A) → C x (g x)
(f · g) x = f (g x)
-- TODO compile problems
foldr-fusion : ∀ {A B C} (h : B → C) {f : A → B → B} {g : A → C → C}
→ {e : B}
→ (∀ x y → h (f x y) ≡ g x (h y))
→ (h · foldr f e) ≐ (foldr g (h e))
foldr-fusion h {f} {g} e fuse =
foldr-universal (h · foldr f e) g (h e) ≡-refl (λ x xs → fuse x (foldr f e xs))
-}
| 34.218919
| 98
| 0.6351
|
59156249d15f2b8fefa2bfb9520215d6565520a1
| 863
|
agda
|
Agda
|
Categories/Lan.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Lan.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Lan.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.Lan where
open import Level
open import Categories.Category
open import Categories.Functor hiding (_≡_)
open import Categories.NaturalTransformation
record Lan {o₀ ℓ₀ e₀} {o₁ ℓ₁ e₁} {o₂ ℓ₂ e₂}
{A : Category o₀ ℓ₀ e₀} {B : Category o₁ ℓ₁ e₁} {C : Category o₂ ℓ₂ e₂}
(F : Functor A B) (X : Functor A C) : Set (o₀ ⊔ ℓ₀ ⊔ e₀ ⊔ o₁ ⊔ ℓ₁ ⊔ e₁ ⊔ o₂ ⊔ ℓ₂ ⊔ e₂) where
field
L : Functor B C
ε : NaturalTransformation X (L ∘ F)
σ : (M : Functor B C) → (α : NaturalTransformation X (M ∘ F)) → NaturalTransformation L M
.σ-unique : {M : Functor B C} → {α : NaturalTransformation X (M ∘ F)} →
(σ′ : NaturalTransformation L M) → α ≡ (σ′ ∘ʳ F) ∘₁ ε → σ′ ≡ σ M α
.commutes : (M : Functor B C) → (α : NaturalTransformation X (M ∘ F)) → α ≡ (σ M α ∘ʳ F) ∘₁ ε
| 41.095238
| 103
| 0.595597
|
c734b13e668d72691e952a9630abcef92ebe619d
| 5,279
|
agda
|
Agda
|
Cubical/Algebra/Group/GroupPath.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Algebra/Group/GroupPath.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/GroupPath.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
-- The SIP applied to groups
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.GroupPath where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.GroupoidLaws hiding (assoc)
open import Cubical.Data.Sigma
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
private
variable
ℓ ℓ' ℓ'' : Level
open Iso
open GroupStr
open IsGroupHom
𝒮ᴰ-Group : DUARel (𝒮-Univ ℓ) GroupStr ℓ
𝒮ᴰ-Group =
𝒮ᴰ-Record (𝒮-Univ _) IsGroupEquiv
(fields:
data[ _·_ ∣ autoDUARel _ _ ∣ pres· ]
data[ 1g ∣ autoDUARel _ _ ∣ pres1 ]
data[ inv ∣ autoDUARel _ _ ∣ presinv ]
prop[ isGroup ∣ (λ _ _ → isPropIsGroup _ _ _) ])
where
open GroupStr
open IsGroupHom
GroupPath : (M N : Group ℓ) → GroupEquiv M N ≃ (M ≡ N)
GroupPath = ∫ 𝒮ᴰ-Group .UARel.ua
-- TODO: Induced structure results are temporarily inconvenient while we transition between algebra
-- representations
module _ (G : Group ℓ) {A : Type ℓ} (m : A → A → A)
(e : ⟨ G ⟩ ≃ A)
(p· : ∀ x y → e .fst (G .snd ._·_ x y) ≡ m (e .fst x) (e .fst y))
where
private
module G = GroupStr (G .snd)
FamilyΣ : Σ[ B ∈ Type ℓ ] (B → B → B) → Type ℓ
FamilyΣ (B , n) =
Σ[ e ∈ B ]
Σ[ i ∈ (B → B) ]
IsGroup e n i
inducedΣ : FamilyΣ (A , m)
inducedΣ =
subst FamilyΣ
(UARel.≅→≡ (autoUARel (Σ[ B ∈ Type ℓ ] (B → B → B))) (e , p·))
(G.1g , G.inv , G.isGroup)
InducedGroup : Group ℓ
InducedGroup .fst = A
InducedGroup .snd ._·_ = m
InducedGroup .snd .1g = inducedΣ .fst
InducedGroup .snd .inv = inducedΣ .snd .fst
InducedGroup .snd .isGroup = inducedΣ .snd .snd
InducedGroupPath : G ≡ InducedGroup
InducedGroupPath = GroupPath _ _ .fst (e , makeIsGroupHom p·)
uaGroup : {G H : Group ℓ} → GroupEquiv G H → G ≡ H
uaGroup {G = G} {H = H} = equivFun (GroupPath G H)
-- Group-ua functoriality
Group≡ : (G H : Group ℓ) → (
Σ[ p ∈ ⟨ G ⟩ ≡ ⟨ H ⟩ ]
Σ[ q ∈ PathP (λ i → p i) (1g (snd G)) (1g (snd H)) ]
Σ[ r ∈ PathP (λ i → p i → p i → p i) (_·_ (snd G)) (_·_ (snd H)) ]
Σ[ s ∈ PathP (λ i → p i → p i) (inv (snd G)) (inv (snd H)) ]
PathP (λ i → IsGroup (q i) (r i) (s i)) (isGroup (snd G)) (isGroup (snd H)))
≃ (G ≡ H)
Group≡ G H = isoToEquiv theIso
where
theIso : Iso _ _
fun theIso (p , q , r , s , t) i = p i , groupstr (q i) (r i) (s i) (t i)
inv theIso x = cong ⟨_⟩ x , cong (1g ∘ snd) x , cong (_·_ ∘ snd) x , cong (inv ∘ snd) x , cong (isGroup ∘ snd) x
rightInv theIso _ = refl
leftInv theIso _ = refl
caracGroup≡ : {G H : Group ℓ} (p q : G ≡ H) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracGroup≡ {G = G} {H = H} p q P =
sym (transportTransport⁻ (ua (Group≡ G H)) p)
∙∙ cong (transport (ua (Group≡ G H))) helper
∙∙ transportTransport⁻ (ua (Group≡ G H)) q
where
helper : transport (sym (ua (Group≡ G H))) p ≡ transport (sym (ua (Group≡ G H))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set (snd H)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd H)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd H)) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsGroup _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaGroupId : (G : Group ℓ) → uaGroup (idGroupEquiv {G = G}) ≡ refl
uaGroupId G = caracGroup≡ _ _ uaIdEquiv
uaCompGroupEquiv : {F G H : Group ℓ} (f : GroupEquiv F G) (g : GroupEquiv G H)
→ uaGroup (compGroupEquiv f g) ≡ uaGroup f ∙ uaGroup g
uaCompGroupEquiv f g = caracGroup≡ _ _ (
cong ⟨_⟩ (uaGroup (compGroupEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
cong ⟨_⟩ (uaGroup f) ∙ cong ⟨_⟩ (uaGroup g)
≡⟨ sym (cong-∙ ⟨_⟩ (uaGroup f) (uaGroup g)) ⟩
cong ⟨_⟩ (uaGroup f ∙ uaGroup g) ∎)
-- J-rule for GroupEquivs
GroupEquivJ : {G : Group ℓ} (P : (H : Group ℓ) → GroupEquiv G H → Type ℓ')
→ P G idGroupEquiv
→ ∀ {H} e → P H e
GroupEquivJ {G = G} P p {H} e =
transport (λ i → P (GroupPath G H .fst e i)
(transp (λ j → GroupEquiv G (GroupPath G H .fst e (i ∨ ~ j))) i e))
(subst (P G) (sym lem) p)
where
lem : transport (λ j → GroupEquiv G (GroupPath G H .fst e (~ j))) e
≡ idGroupEquiv
lem = Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(Σ≡Prop (λ _ → isPropIsEquiv _)
(funExt λ x → (λ i → fst (fst (fst e .snd .equiv-proof
(transportRefl (fst (fst e) (transportRefl x i)) i))))
∙ retEq (fst e) x))
| 35.911565
| 114
| 0.594241
|
38f2e464a66d2a02a7e2bad8fb52b6971cb68246
| 8,952
|
agda
|
Agda
|
src/Structure-identity-principle.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Structure-identity-principle.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Structure-identity-principle.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Aczel's structure identity principle (for 1-categories), more or
-- less as found in "Homotopy Type Theory: Univalent Foundations of
-- Mathematics" (first edition)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Structure-identity-principle
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq using (_↔_; Σ-≡,≡↔≡)
open import Category eq
open Derived-definitions-and-properties eq
open import Equality.Decidable-UIP eq
open import Equivalence eq hiding (id; _∘_; inverse; lift-equality)
open import Function-universe eq hiding (id) renaming (_∘_ to _⊚_)
open import H-level eq
open import H-level.Closure eq
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (id)
-- Standard notions of structure.
record Standard-notion-of-structure
{c₁ c₂} ℓ₁ ℓ₂ (C : Precategory c₁ c₂) :
Type (c₁ ⊔ c₂ ⊔ lsuc (ℓ₁ ⊔ ℓ₂)) where
open Precategory C
field
P : Obj → Type ℓ₁
H : ∀ {X Y} (p : P X) (q : P Y) → Hom X Y → Type ℓ₂
H-prop : ∀ {X Y} {p : P X} {q : P Y}
(f : Hom X Y) → Is-proposition (H p q f)
H-id : ∀ {X} {p : P X} → H p p id
H-∘ : ∀ {X Y Z} {p : P X} {q : P Y} {r : P Z} {f g} →
H p q f → H q r g → H p r (g ∙ f)
H-antisymmetric : ∀ {X} (p q : P X) →
H p q id → H q p id → p ≡ q
-- P constructs sets. (The proof was suggested by Michael Shulman in
-- a mailing list post.)
P-set : ∀ A → Is-set (P A)
P-set A = propositional-identity⇒set
(λ p q → H p q id × H q p id)
(λ _ _ → ×-closure 1 (H-prop id) (H-prop id))
(λ _ → H-id , H-id)
(λ p q → uncurry (H-antisymmetric p q))
-- Two Str morphisms (see below) of equal type are equal if their
-- first components are equal.
lift-equality : {X Y : ∃ P} {f g : ∃ (H (proj₂ X) (proj₂ Y))} →
proj₁ f ≡ proj₁ g → f ≡ g
lift-equality eq = Σ-≡,≡→≡ eq (H-prop _ _ _)
-- A derived precategory.
Str : Precategory (c₁ ⊔ ℓ₁) (c₂ ⊔ ℓ₂)
Str = record { precategory =
∃ P ,
(λ { (X , p) (Y , q) →
∃ (H p q) ,
Σ-closure 2 Hom-is-set (λ f → mono₁ 1 (H-prop f)) }) ,
(id , H-id) ,
(λ { (f , hf) (g , hg) → f ∙ g , H-∘ hg hf }) ,
lift-equality left-identity ,
lift-equality right-identity ,
lift-equality assoc }
module Str = Precategory Str
-- A rearrangement lemma.
proj₁-≡→≅-¹ :
∀ {X Y} (X≡Y : X ≡ Y) →
proj₁ (Str.≡→≅ X≡Y Str.¹) ≡
elim (λ {X Y} _ → Hom X Y) (λ _ → id) (cong proj₁ X≡Y)
proj₁-≡→≅-¹ {X , p} = elim¹
(λ X≡Y → proj₁ (Str.≡→≅ X≡Y Str.¹) ≡
elim (λ {X Y} _ → Hom X Y) (λ _ → id) (cong proj₁ X≡Y))
(proj₁ (Str.≡→≅ (refl (X , p)) Str.¹) ≡⟨ cong (proj₁ ∘ Str._¹) $ elim-refl (λ {X Y} _ → X Str.≅ Y) _ ⟩
proj₁ (Str.id {X = X , p}) ≡⟨⟩
id {X = X} ≡⟨ sym $ elim-refl (λ {X Y} _ → Hom X Y) _ ⟩
elim (λ {X Y} _ → Hom X Y) (λ _ → id) (refl X) ≡⟨ cong (elim (λ {X Y} _ → Hom X Y) _) $ sym $ cong-refl proj₁ ⟩∎
elim (λ {X Y} _ → Hom X Y) (λ _ → id) (cong proj₁ (refl (X , p))) ∎)
-- The structure identity principle states that the precategory Str is
-- a category (assuming extensionality).
--
-- The proof below is based on (but not quite identical to) the one in
-- "Homotopy Type Theory: Univalent Foundations of Mathematics" (first
-- edition).
abstract
structure-identity-principle :
∀ {c₁ c₂ ℓ₁ ℓ₂} →
Extensionality (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂) →
(C : Category c₁ c₂) →
(S : Standard-notion-of-structure ℓ₁ ℓ₂ (Category.precategory C)) →
∀ {X Y} → Is-equivalence
(Precategory.≡→≅ (Standard-notion-of-structure.Str S)
{X} {Y})
structure-identity-principle ext C S =
Str.≡→≅-equivalence-lemma ≡≃≅ ≡≃≅-refl
where
open Standard-notion-of-structure S
module C = Category C
-- _≡_ is pointwise equivalent to Str._≅_.
module ≅HH≃≅ where
to : ∀ {X Y} {p : P X} {q : P Y} →
(∃ λ (f : X C.≅ Y) → H p q (f C.¹) × H q p (f C.⁻¹)) →
(X , p) Str.≅ (Y , q)
to ((f , f⁻¹ , f∙f⁻¹ , f⁻¹∙f) , Hf , Hf⁻¹) =
(f , Hf) , (f⁻¹ , Hf⁻¹) ,
lift-equality f∙f⁻¹ ,
lift-equality f⁻¹∙f
≅HH≃≅ : ∀ {X Y} {p : P X} {q : P Y} →
(∃ λ (f : X C.≅ Y) → H p q (f C.¹) × H q p (f C.⁻¹)) ≃
((X , p) Str.≅ (Y , q))
≅HH≃≅ {X} {Y} {p} {q} = ↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = ≅HH≃≅.to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
})
where
from : (X , p) Str.≅ (Y , q) →
∃ λ (f : X C.≅ Y) → H p q (f C.¹) × H q p (f C.⁻¹)
from ((f , Hf) , (f⁻¹ , Hf⁻¹) , f∙f⁻¹ , f⁻¹∙f) =
(f , f⁻¹ , cong proj₁ f∙f⁻¹ , cong proj₁ f⁻¹∙f) , Hf , Hf⁻¹
to∘from : ∀ p → ≅HH≃≅.to (from p) ≡ p
to∘from ((f , Hf) , (f⁻¹ , Hf⁻¹) , f∙f⁻¹ , f⁻¹∙f) =
cong₂ (λ f∙f⁻¹ f⁻¹∙f →
(f , Hf) , (f⁻¹ , Hf⁻¹) , f∙f⁻¹ , f⁻¹∙f)
(Str.Hom-is-set _ _)
(Str.Hom-is-set _ _)
from∘to : ∀ p → from (≅HH≃≅.to p) ≡ p
from∘to ((f , f⁻¹ , f∙f⁻¹ , f⁻¹∙f) , Hf , Hf⁻¹) =
cong₂ (λ f∙f⁻¹ f⁻¹∙f → (f , f⁻¹ , f∙f⁻¹ , f⁻¹∙f) , Hf , Hf⁻¹)
(C.Hom-is-set _ _)
(C.Hom-is-set _ _)
module ≡≡≃≅HH where
to : ∀ {X Y} {p : P X} {q : P Y} →
(X≡Y : X ≡ Y) → subst P X≡Y p ≡ q →
H p q (C.≡→≅ X≡Y C.¹) × H q p (C.≡→≅ X≡Y C.⁻¹)
to {X} {p = p} X≡Y p≡q = elim¹
(λ X≡Y → ∀ {q} → subst P X≡Y p ≡ q →
H p q (C.≡→≅ X≡Y C.¹) × H q p (C.≡→≅ X≡Y C.⁻¹))
(elim¹
(λ {q} _ → H p q (C.≡→≅ (refl X) C.¹) ×
H q p (C.≡→≅ (refl X) C.⁻¹))
( subst (λ { (q , f) → H p q f })
(sym $ cong₂ _,_
(subst P (refl X) p ≡⟨ subst-refl P _ ⟩∎
p ∎)
(C.≡→≅ (refl X) C.¹ ≡⟨ cong C._¹ C.≡→≅-refl ⟩∎
C.id ∎))
H-id
, subst (λ { (q , f) → H q p f })
(sym $ cong₂ _,_
(subst P (refl X) p ≡⟨ subst-refl P _ ⟩∎
p ∎)
(C.≡→≅ (refl X) C.⁻¹ ≡⟨ cong C._⁻¹ C.≡→≅-refl ⟩∎
C.id ∎))
H-id
))
X≡Y p≡q
to-refl : ∀ {X} {p : P X} →
subst (λ f → H p p (f C.¹) × H p p (f C.⁻¹))
C.≡→≅-refl
(to (refl X) (subst-refl P p)) ≡
(H-id , H-id)
to-refl = cong₂ _,_ (H-prop _ _ _) (H-prop _ _ _)
≡≡≃≅HH : ∀ {X Y} {p : P X} {q : P Y} →
(∃ λ (eq : X ≡ Y) → subst P eq p ≡ q) ≃
(∃ λ (f : X C.≅ Y) → H p q (f C.¹) × H q p (f C.⁻¹))
≡≡≃≅HH {X} {p = p} {q} =
Σ-preserves C.≡≃≅ λ X≡Y →
_↔_.to (⇔↔≃ ext (P-set _) (×-closure 1 (H-prop _) (H-prop _)))
(record { to = ≡≡≃≅HH.to X≡Y ; from = from X≡Y })
where
from : ∀ X≡Y → H p q (C.≡→≅ X≡Y C.¹) × H q p (C.≡→≅ X≡Y C.⁻¹) →
subst P X≡Y p ≡ q
from X≡Y (H¹ , H⁻¹) = elim¹
(λ {Y} X≡Y → ∀ {q} →
H p q (C.≡→≅ X≡Y C.¹) → H q p (C.≡→≅ X≡Y C.⁻¹) →
subst P X≡Y p ≡ q)
(λ {q} H¹ H⁻¹ →
subst P (refl X) p ≡⟨ subst-refl P _ ⟩
p ≡⟨ H-antisymmetric p q
(subst (H p q) (cong C._¹ C.≡→≅-refl) H¹)
(subst (H q p) (cong C._⁻¹ C.≡→≅-refl) H⁻¹) ⟩∎
q ∎)
X≡Y H¹ H⁻¹
≡≃≅ : ∀ {X Y} {p : P X} {q : P Y} →
_≡_ {A = ∃ P} (X , p) (Y , q) ≃ ((X , p) Str.≅ (Y , q))
≡≃≅ = ≅HH≃≅ ⊚ ≡≡≃≅HH ⊚ ↔⇒≃ (inverse Σ-≡,≡↔≡)
-- …and the proof maps reflexivity to the identity morphism.
≡≃≅-refl : ∀ {Xp} → _≃_.to ≡≃≅ (refl Xp) Str.¹ ≡ Str.id
≡≃≅-refl {X , p} = cong Str._¹ (
≅HH≃≅.to (_≃_.to ≡≡≃≅HH (Σ-≡,≡←≡ (refl (_,_ {B = P} X p)))) ≡⟨ cong (≅HH≃≅.to ∘ _≃_.to ≡≡≃≅HH) $ Σ-≡,≡←≡-refl {B = P} ⟩
≅HH≃≅.to (_≃_.to ≡≡≃≅HH (refl X , subst-refl P p)) ≡⟨⟩
≅HH≃≅.to (C.≡→≅ (refl X) , ≡≡≃≅HH.to (refl X) (subst-refl P p)) ≡⟨ cong ≅HH≃≅.to $ Σ-≡,≡→≡ C.≡→≅-refl ≡≡≃≅HH.to-refl ⟩
≅HH≃≅.to (C.id≅ , H-id , H-id) ≡⟨ refl _ ⟩∎
Str.id≅ ∎)
| 39.263158
| 137
| 0.402815
|
4367aa22bfa8b042b8e76ea90f8208854d950733
| 11,477
|
agda
|
Agda
|
core/lib/types/Group.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/types/Group.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/types/Group.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Fin
open import lib.types.Int
open import lib.types.Nat
open import lib.types.Pi
module lib.types.Group where
-- 1-approximation of groups without higher coherence conditions.
record GroupStructure {i} (El : Type i) --(El-level : has-level 0 El)
: Type i where
constructor group-structure
field
ident : El
inv : El → El
comp : El → El → El
unit-l : ∀ a → comp ident a == a
assoc : ∀ a b c → comp (comp a b) c == comp a (comp b c)
inv-l : ∀ a → (comp (inv a) a) == ident
⊙El : Ptd i
⊙El = ⊙[ El , ident ]
private
infix 80 _⊙_
_⊙_ = comp
abstract
inv-r : ∀ g → g ⊙ inv g == ident
inv-r g =
g ⊙ inv g =⟨ ! $ unit-l (g ⊙ inv g) ⟩
ident ⊙ (g ⊙ inv g) =⟨ ! $ inv-l (inv g) |in-ctx _⊙ (g ⊙ inv g) ⟩
(inv (inv g) ⊙ inv g) ⊙ (g ⊙ inv g) =⟨ assoc (inv (inv g)) (inv g) (g ⊙ inv g) ⟩
inv (inv g) ⊙ (inv g ⊙ (g ⊙ inv g)) =⟨ ! $ assoc (inv g) g (inv g) |in-ctx inv (inv g) ⊙_ ⟩
inv (inv g) ⊙ ((inv g ⊙ g) ⊙ inv g) =⟨ inv-l g |in-ctx (λ h → inv (inv g) ⊙ (h ⊙ inv g)) ⟩
inv (inv g) ⊙ (ident ⊙ inv g) =⟨ unit-l (inv g) |in-ctx inv (inv g) ⊙_ ⟩
inv (inv g) ⊙ inv g =⟨ inv-l (inv g) ⟩
ident =∎
unit-r : ∀ g → g ⊙ ident == g
unit-r g =
g ⊙ ident =⟨ ! (inv-l g) |in-ctx g ⊙_ ⟩
g ⊙ (inv g ⊙ g) =⟨ ! $ assoc g (inv g) g ⟩
(g ⊙ inv g) ⊙ g =⟨ inv-r g |in-ctx _⊙ g ⟩
ident ⊙ g =⟨ unit-l g ⟩
g =∎
inv-unique-l : (g h : El) → (g ⊙ h == ident) → inv h == g
inv-unique-l g h p =
inv h =⟨ ! (unit-l (inv h)) ⟩
ident ⊙ inv h =⟨ ! p |in-ctx (λ w → w ⊙ inv h) ⟩
(g ⊙ h) ⊙ inv h =⟨ assoc g h (inv h) ⟩
g ⊙ (h ⊙ inv h) =⟨ inv-r h |in-ctx (λ w → g ⊙ w) ⟩
g ⊙ ident =⟨ unit-r g ⟩
g =∎
inv-unique-r : (g h : El) → (g ⊙ h == ident) → inv g == h
inv-unique-r g h p =
inv g =⟨ ! (unit-r (inv g)) ⟩
inv g ⊙ ident =⟨ ! p |in-ctx (λ w → inv g ⊙ w) ⟩
inv g ⊙ (g ⊙ h) =⟨ ! (assoc (inv g) g h) ⟩
(inv g ⊙ g) ⊙ h =⟨ inv-l g |in-ctx (λ w → w ⊙ h) ⟩
ident ⊙ h =⟨ unit-l h ⟩
h =∎
inv-ident : inv ident == ident
inv-ident = inv-unique-l ident ident (unit-l ident)
inv-comp : (g₁ g₂ : El) → inv (g₁ ⊙ g₂) == inv g₂ ⊙ inv g₁
inv-comp g₁ g₂ =
inv-unique-r (g₁ ⊙ g₂) (inv g₂ ⊙ inv g₁) $
(g₁ ⊙ g₂) ⊙ (inv g₂ ⊙ inv g₁)
=⟨ assoc g₁ g₂ (inv g₂ ⊙ inv g₁) ⟩
g₁ ⊙ (g₂ ⊙ (inv g₂ ⊙ inv g₁))
=⟨ ! (assoc g₂ (inv g₂) (inv g₁)) |in-ctx (λ w → g₁ ⊙ w) ⟩
g₁ ⊙ ((g₂ ⊙ inv g₂) ⊙ inv g₁)
=⟨ inv-r g₂ |in-ctx (λ w → g₁ ⊙ (w ⊙ inv g₁)) ⟩
g₁ ⊙ (ident ⊙ inv g₁)
=⟨ unit-l (inv g₁) |in-ctx (λ w → g₁ ⊙ w) ⟩
g₁ ⊙ inv g₁
=⟨ inv-r g₁ ⟩
ident =∎
inv-inv : (g : El) → inv (inv g) == g
inv-inv g = inv-unique-r (inv g) g (inv-l g)
inv-is-inj : is-inj inv
inv-is-inj g₁ g₂ p = ! (inv-inv g₁) ∙ ap inv p ∙ inv-inv g₂
cancel-l : (g : El) {h k : El} → g ⊙ h == g ⊙ k → h == k
cancel-l g {h} {k} p =
h =⟨ ! (unit-l h) ⟩
ident ⊙ h =⟨ ap (λ w → w ⊙ h) (! (inv-l g)) ⟩
(inv g ⊙ g) ⊙ h =⟨ assoc (inv g) g h ⟩
inv g ⊙ (g ⊙ h) =⟨ ap (λ w → inv g ⊙ w) p ⟩
inv g ⊙ (g ⊙ k) =⟨ ! (assoc (inv g) g k) ⟩
(inv g ⊙ g) ⊙ k =⟨ ap (λ w → w ⊙ k) (inv-l g) ⟩
ident ⊙ k =⟨ unit-l k ⟩
k =∎
cancel-r : (g : El) {h k : El} → h ⊙ g == k ⊙ g → h == k
cancel-r g {h} {k} p =
h =⟨ ! (unit-r h) ⟩
h ⊙ ident =⟨ ap (λ w → h ⊙ w) (! (inv-r g)) ⟩
h ⊙ (g ⊙ inv g) =⟨ ! (assoc h g (inv g)) ⟩
(h ⊙ g) ⊙ inv g =⟨ ap (λ w → w ⊙ inv g) p ⟩
(k ⊙ g) ⊙ inv g =⟨ assoc k g (inv g) ⟩
k ⊙ (g ⊙ inv g) =⟨ ap (λ w → k ⊙ w) (inv-r g) ⟩
k ⊙ ident =⟨ unit-r k ⟩
k =∎
conj : El → El → El
conj g₁ g₂ = (g₁ ⊙ g₂) ⊙ inv g₁
abstract
conj-ident-r : ∀ g → conj g ident == ident
conj-ident-r g = ap (_⊙ inv g) (unit-r _) ∙ inv-r g
{- NOT USED
abstract
conj-unit-l : ∀ g → conj ident g == g
conj-unit-l g = ap2 _⊙_ (unit-l _) inv-ident ∙ unit-r _
conj-comp-l : ∀ g₁ g₂ g₃ → conj (g₁ ⊙ g₂) g₃ == conj g₁ (conj g₂ g₃)
conj-comp-l g₁ g₂ g₃ =
((g₁ ⊙ g₂) ⊙ g₃) ⊙ inv (g₁ ⊙ g₂)
=⟨ ap2 _⊙_ (assoc g₁ g₂ g₃) (inv-comp g₁ g₂) ⟩
(g₁ ⊙ (g₂ ⊙ g₃)) ⊙ (inv g₂ ⊙ inv g₁)
=⟨ ! $ assoc (g₁ ⊙ (g₂ ⊙ g₃)) (inv g₂) (inv g₁) ⟩
((g₁ ⊙ (g₂ ⊙ g₃)) ⊙ inv g₂) ⊙ inv g₁
=⟨ assoc g₁ (g₂ ⊙ g₃) (inv g₂) |in-ctx _⊙ inv g₁ ⟩
(g₁ ⊙ ((g₂ ⊙ g₃) ⊙ inv g₂)) ⊙ inv g₁
=∎
inv-conj : ∀ g₁ g₂ → inv (conj g₁ g₂) == conj g₁ (inv g₂)
inv-conj g₁ g₂ = inv-comp (g₁ ⊙ g₂) (inv g₁)
∙ ap2 _⊙_ (inv-inv g₁) (inv-comp g₁ g₂)
∙ ! (assoc g₁ (inv g₂) (inv g₁))
-}
exp : El → ℤ → El
exp g (pos 0) = ident
exp g (pos 1) = g
exp g (pos (S (S n))) = comp g (exp g (pos (S n)))
exp g (negsucc 0) = inv g
exp g (negsucc (S n)) = comp (inv g) (exp g (negsucc n))
abstract
exp-succ : ∀ g z → exp g (succ z) == comp g (exp g z)
exp-succ g (pos 0) = ! (unit-r g)
exp-succ g (pos 1) = idp
exp-succ g (pos (S (S n))) = idp
exp-succ g (negsucc 0) = ! (inv-r g)
exp-succ g (negsucc (S n)) =
! (unit-l (exp g (negsucc n)))
∙ ap (λ h → comp h (exp g (negsucc n))) (! (inv-r g))
∙ assoc g (inv g) (exp g (negsucc n))
exp-pred : ∀ g z → exp g (pred z) == comp (inv g) (exp g z)
exp-pred g (pos 0) = ! (unit-r (inv g))
exp-pred g (pos 1) = ! (inv-l g)
exp-pred g (pos (S (S n))) =
! (unit-l (exp g (pos (S n))))
∙ ap (λ h → comp h (exp g (pos (S n)))) (! (inv-l g))
∙ assoc (inv g) g (exp g (pos (S n)))
exp-pred g (negsucc 0) = idp
exp-pred g (negsucc (S n)) = idp
exp-+ : ∀ g z₁ z₂ → exp g (z₁ ℤ+ z₂) == comp (exp g z₁) (exp g z₂)
exp-+ g (pos 0) z₂ = ! (unit-l _)
exp-+ g (pos 1) z₂ = exp-succ g z₂
exp-+ g (pos (S (S n))) z₂ =
exp-succ g (pos (S n) ℤ+ z₂)
∙ ap (comp g) (exp-+ g (pos (S n)) z₂)
∙ ! (assoc g (exp g (pos (S n))) (exp g z₂))
exp-+ g (negsucc 0) z₂ = exp-pred g z₂
exp-+ g (negsucc (S n)) z₂ =
exp-pred g (negsucc n ℤ+ z₂)
∙ ap (comp (inv g)) (exp-+ g (negsucc n) z₂)
∙ ! (assoc (inv g) (exp g (negsucc n)) (exp g z₂))
exp-ident : ∀ z → exp ident z == ident
exp-ident (pos 0) = idp
exp-ident (pos 1) = idp
exp-ident (pos (S (S n))) = unit-l _ ∙ exp-ident (pos (S n))
exp-ident (negsucc 0) = inv-ident
exp-ident (negsucc (S n)) = ap2 comp inv-ident (exp-ident (negsucc n)) ∙ unit-l _
diff : El → El → El
diff g h = g ⊙ inv h
abstract
zero-diff-same : (g h : El) → diff g h == ident → g == h
zero-diff-same g h p = inv-is-inj g h $ inv-unique-r g (inv h) p
inv-diff : (g h : El) → inv (diff g h) == diff h g
inv-diff g h = inv-comp g (inv h) ∙ ap (_⊙ inv g) (inv-inv h)
sum : ∀ {I : ℕ} → (Fin I → El) → El
sum {I = O} f = ident
sum {I = S n} f = comp (sum (f ∘ Fin-S)) (f (n , ltS))
subsum-r : ∀ {j k} {I : ℕ} {A : Type j} {B : Type k}
→ (Fin I → Coprod A B) → (B → El) → El
subsum-r p f = sum (λ x → ⊔-rec (λ _ → ident) f (p x))
record Group i : Type (lsucc i) where
constructor group
field
El : Type i
{{El-level}} : has-level 0 El
group-struct : GroupStructure El
open GroupStructure group-struct public
Group₀ : Type (lsucc lzero)
Group₀ = Group lzero
is-abelian : ∀ {i} → Group i → Type i
is-abelian G = (a b : Group.El G) → Group.comp G a b == Group.comp G b a
AbGroup : ∀ i → Type (lsucc i)
AbGroup i = Σ (Group i) is-abelian
AbGroup₀ : Type (lsucc lzero)
AbGroup₀ = AbGroup lzero
module AbGroup {i} (G : AbGroup i) where
grp = fst G
comm = snd G
open Group grp public
abstract
interchange : (g₁ g₂ g₃ g₄ : El) →
comp (comp g₁ g₂) (comp g₃ g₄)
== comp (comp g₁ g₃) (comp g₂ g₄)
interchange g₁ g₂ g₃ g₄ =
comp (comp g₁ g₂) (comp g₃ g₄)
=⟨ assoc g₁ g₂ (comp g₃ g₄) ⟩
comp g₁ (comp g₂ (comp g₃ g₄))
=⟨ comm g₃ g₄ |in-ctx (λ g → (comp g₁ (comp g₂ g))) ⟩
comp g₁ (comp g₂ (comp g₄ g₃))
=⟨ ! (assoc g₂ g₄ g₃) |in-ctx comp g₁ ⟩
comp g₁ (comp (comp g₂ g₄) g₃)
=⟨ comm (comp g₂ g₄) g₃ |in-ctx comp g₁ ⟩
comp g₁ (comp g₃ (comp g₂ g₄))
=⟨ ! (assoc g₁ g₃ (comp g₂ g₄)) ⟩
comp (comp g₁ g₃) (comp g₂ g₄)
=∎
inv-comp' : ∀ g₁ g₂ → inv (comp g₁ g₂) == comp (inv g₁) (inv g₂)
inv-comp' g₁ g₂ = inv-comp g₁ g₂ ∙ comm (inv g₂) (inv g₁)
diff-comp : (g₁ g₂ g₃ g₄ : El) →
diff (comp g₁ g₂) (comp g₃ g₄)
== comp (diff g₁ g₃) (diff g₂ g₄)
diff-comp g₁ g₂ g₃ g₄ =
diff (comp g₁ g₂) (comp g₃ g₄)
=⟨ ap (comp (comp g₁ g₂)) (inv-comp' g₃ g₄) ⟩
comp (comp g₁ g₂) (comp (inv g₃) (inv g₄))
=⟨ interchange g₁ g₂ (inv g₃) (inv g₄) ⟩
comp (diff g₁ g₃) (diff g₂ g₄)
=∎
sum-comp : ∀ {I} (f g : Fin I → El)
→ sum (λ x → comp (f x) (g x)) == comp (sum f) (sum g)
sum-comp {I = O} f g = ! (unit-l _)
sum-comp {I = S I} f g =
ap (λ x → comp x (comp (f (I , ltS)) (g (I , ltS)))) (sum-comp (f ∘ Fin-S) (g ∘ Fin-S))
∙ interchange (sum (f ∘ Fin-S)) (sum (g ∘ Fin-S)) (f (I , ltS)) (g (I , ltS))
exp-comp : ∀ g₁ g₂ z → exp (comp g₁ g₂) z == comp (exp g₁ z) (exp g₂ z)
exp-comp g₁ g₂ (pos O) = ! (unit-l _)
exp-comp g₁ g₂ (pos (S O)) = idp
exp-comp g₁ g₂ (pos (S (S n))) =
ap (comp (comp g₁ g₂)) (exp-comp g₁ g₂ (pos (S n)))
∙ interchange g₁ g₂ (exp g₁ (pos (S n))) (exp g₂ (pos (S n)))
exp-comp g₁ g₂ (negsucc O) = inv-comp' g₁ g₂
exp-comp g₁ g₂ (negsucc (S n)) =
ap2 comp (inv-comp' g₁ g₂) (exp-comp g₁ g₂ (negsucc n))
∙ interchange (inv g₁) (inv g₂) (exp g₁ (negsucc n)) (exp g₂ (negsucc n))
is-trivialᴳ : ∀ {i} (G : Group i) → Type i
is-trivialᴳ G = ∀ g → g == Group.ident G
contr-is-trivialᴳ : ∀ {i} (G : Group i)
{{_ : is-contr (Group.El G)}} → is-trivialᴳ G
contr-is-trivialᴳ G g =
contr-has-all-paths _ _
{- group-structure= -}
module _ where
open GroupStructure
abstract
group-structure= : ∀ {i} {A : Type i} {{_ : is-set A}}
{id₁ id₂ : A} {inv₁ inv₂ : A → A} {comp₁ comp₂ : A → A → A}
→ ∀ {unit-l₁ unit-l₂ assoc₁ assoc₂ inv-l₁ inv-l₂}
→ (id₁ == id₂) → (inv₁ == inv₂) → (comp₁ == comp₂)
→ Path {A = GroupStructure A}
(group-structure id₁ inv₁ comp₁ unit-l₁ assoc₁ inv-l₁)
(group-structure id₂ inv₂ comp₂ unit-l₂ assoc₂ inv-l₂)
group-structure= {id₁ = id₁} {inv₁ = inv₁} {comp₁ = comp₁} idp idp idp =
ap3 (group-structure id₁ inv₁ comp₁)
(prop-has-all-paths _ _)
(prop-has-all-paths _ _)
(prop-has-all-paths _ _)
↓-group-structure= : ∀ {i} {A B : Type i}
{{_ : has-level 0 A}}
{GS : GroupStructure A} {HS : GroupStructure B} (p : A == B)
→ (ident GS == ident HS [ (λ C → C) ↓ p ])
→ (inv GS == inv HS [ (λ C → C → C) ↓ p ])
→ (comp GS == comp HS [ (λ C → C → C → C) ↓ p ])
→ GS == HS [ GroupStructure ↓ p ]
↓-group-structure= idp = group-structure=
| 35.978056
| 97
| 0.469809
|
43cac2311917d4521e62c669b58257bd6a55cfeb
| 58,053
|
agda
|
Agda
|
agda/Esterel/Lang/CanFunction/MergePotentialRuleLeftBase.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/Esterel/Lang/CanFunction/MergePotentialRuleLeftBase.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/Esterel/Lang/CanFunction/MergePotentialRuleLeftBase.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module Esterel.Lang.CanFunction.MergePotentialRuleLeftBase where
open import utility
renaming (_U̬_ to _∪_ ; _|̌_ to _-_)
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Base
open import Esterel.Lang.CanFunction.CanThetaContinuation
open import Esterel.Lang.CanFunction.MergePotentialRuleCan
open import Esterel.Context
using (EvaluationContext1 ; EvaluationContext ; _⟦_⟧e ; _≐_⟦_⟧e)
open import Esterel.Context.Properties
using (plug ; unplug)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open EvaluationContext1
open _≐_⟦_⟧e
open import Data.Bool
using (Bool ; not ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; [] ; _∷_ ; _++_ ; map ; concatMap ; foldr)
open import Data.List.Properties
using (map-id)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using (++⁻)
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _≟_ ; _+_)
open import Data.Nat.Properties.Simple
using (+-comm)
open import Data.Product
using (Σ ; proj₁ ; proj₂ ; ∃ ; _,_ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; _≢_ ; refl ; trans ; sym ; cong ; subst ; module ≡-Reasoning)
open ListSet Data.Nat._≟_
using (set-subtract ; set-subtract-[] ; set-subtract-split ; set-subtract-merge
; set-subtract-notin
; set-remove ; set-remove-mono-∈ ; set-remove-removed ; set-remove-not-removed
; set-subtract-[a]≡set-remove)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ≡-Reasoning
distinct'-S∷Ss⇒[S] : ∀ {xs S Ss} status →
distinct' xs (S ∷ Ss) →
distinct' xs (proj₁ (Dom [ (S ₛ) ↦ status ] ))
distinct'-S∷Ss⇒[S] {xs} {S} {Ss} status xs≠S∷Ss S' S'∈xs S'∈[S]
rewrite Env.sig-single-∈-eq (S' ₛ) (S ₛ) status S'∈[S]
= xs≠S∷Ss S S'∈xs (here refl)
canθₖ-mergeˡ-E-induction-base-par₁ : ∀ {E q E⟦nothin⟧∥q BV FV} sigs' S' r θ →
E⟦nothin⟧∥q ≐ (epar₁ q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧∥q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
Canθₖ sigs' S' ((E ⟦ r ⟧e) ∥ q) θ ≡
concatMap (λ k → map (Code._⊔_ k) (Canₖ q θ)) (Canθₖ sigs' S' (E ⟦ r ⟧e) θ)
canθₖ-mergeˡ-E-induction-base-par₁ [] S' r θ
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
= refl
canθₖ-mergeˡ-E-induction-base-par₁ (nothing ∷ sigs') S' r θ
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₖ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (depar₁ E⟦nothin⟧) cb FV≠sigs'
canθₖ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.present ∷ sigs') S' r θ
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r
(θ ← [S]-env-present (S' ₛ)) (depar₁ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
canθₖ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.absent ∷ sigs') S' r θ
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (depar₁ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
canθₖ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) ∥ q) (θ ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) (θ ← [S]-env (S' ₛ)))
... | yes S'∈canθ-sigs'-E⟦r⟧∥q-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S']
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r
(θ ← [S]-env (S' ₛ)) (depar₁ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
... | no S'∉canθ-sigs'-E⟦r⟧∥q-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (depar₁ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
... | yes S'∈canθ-sigs'-E⟦r⟧∥q-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←[S']
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← [S]-env (S' ₛ))
(depar₁ dehole) (CBpar CBnothing cbq distinct-empty-left distinct-empty-left
distinct-empty-left (λ _ ()))
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧∥q-θ←[S']))
... | no S'∉canθ-sigs'-E⟦r⟧∥q-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S'] =
⊥-elim
(S'∉canθ-sigs'-E⟦r⟧∥q-θ←[S']
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← [S]-env (S' ₛ))
(epar₁ q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←[S']))
canθₖ-mergeˡ-E-induction-base-par₂ : ∀ {E q q∥E⟦nothin⟧ BV FV} sigs' S' r θ →
q∥E⟦nothin⟧ ≐ (epar₂ q ∷ E) ⟦ nothin ⟧e →
CorrectBinding q∥E⟦nothin⟧ BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
Canθₖ sigs' S' (q ∥ (E ⟦ r ⟧e)) θ ≡
concatMap (λ k → map (Code._⊔_ k) (Canθₖ sigs' S' (E ⟦ r ⟧e) θ)) (Canₖ q θ)
canθₖ-mergeˡ-E-induction-base-par₂ [] S' r θ
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
= refl
canθₖ-mergeˡ-E-induction-base-par₂ (nothing ∷ sigs') S' r θ
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₖ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (depar₂ E⟦nothin⟧) cb FV≠sigs'
canθₖ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.present ∷ sigs') S' r θ
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left dist'++ˡ
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r
(θ ← [S]-env-present (S' ₛ)) (depar₂ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
canθₖ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.absent ∷ sigs') S' r θ
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left dist'++ˡ
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (depar₂ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
canθₖ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
with any (_≟_ S') (Canθₛ sigs' (suc S') (q ∥ (E ⟦ r ⟧e)) (θ ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) (θ ← [S]-env (S' ₛ)))
... | yes S'∈canθ-sigs'-q∥E⟦r⟧-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S']
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env (S' ₛ)) q cbq
(distinct'-to-left dist'++ˡ
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r
(θ ← [S]-env (S' ₛ)) (depar₂ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
... | no S'∉canθ-sigs'-q∥E⟦r⟧-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left dist'++ˡ
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (depar₂ E⟦nothin⟧)
cb (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')
= refl
... | yes S'∈canθ-sigs'-q∥E⟦r⟧-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←[S']
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← [S]-env (S' ₛ))
(depar₂ dehole) (CBpar cbq CBnothing distinct-empty-right distinct-empty-right
distinct-empty-right (λ _ _ ()))
(λ S' S'∈map-+-suc-S'-sigs' S'∈FVq++[] →
FV≠sigs' S' (++ˡ (x∈xs++[]→x∈xs {xs = proj₁ FVp} S'∈FVq++[]))
(there S'∈map-+-suc-S'-sigs'))
(S' ₛ)
(λ S'∈FVq++[] →
FV≠sigs' S' (++ˡ (x∈xs++[]→x∈xs {xs = proj₁ FVp} S'∈FVq++[])) (here refl))
S'∈canθ-sigs'-q∥E⟦r⟧-θ←[S']))
... | no S'∉canθ-sigs'-q∥E⟦r⟧-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S'] =
⊥-elim
(S'∉canθ-sigs'-q∥E⟦r⟧-θ←[S']
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← [S]-env (S' ₛ))
(epar₂ q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←[S']))
canθₖ-mergeˡ-E-induction-base-seq-notin : ∀ {E q E⟦nothin⟧>>q BV FV} sigs' S' r θ →
E⟦nothin⟧>>q ≐ (eseq q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧>>q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
Code.nothin ∉ Canθₖ sigs' S' (E ⟦ r ⟧e) θ →
Canθₖ sigs' S' ((E ⟦ r ⟧e) >> q) θ ≡
Canθₖ sigs' S' (E ⟦ r ⟧e) θ
canθₖ-mergeˡ-E-induction-base-seq-notin {E} [] S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∉canθ-sigs'-E⟦r⟧-θ
with any (Code._≟_ Code.nothin) (Canₖ (E ⟦ r ⟧e) θ)
... | no nothin∉can-E⟦r⟧-θ = refl
... | yes nothin∈can-E⟦r⟧-θ = ⊥-elim (nothin∉canθ-sigs'-E⟦r⟧-θ nothin∈can-E⟦r⟧-θ)
canθₖ-mergeˡ-E-induction-base-seq-notin (nothing ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∉canθ-sigs'-E⟦r⟧-θ
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| canθₖ-mergeˡ-E-induction-base-seq-notin sigs' (suc S') r
θ (deseq E⟦nothin⟧) cb FV≠sigs' nothin∉canθ-sigs'-E⟦r⟧-θ
= refl
canθₖ-mergeˡ-E-induction-base-seq-notin {E} (just Signal.present ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∉canθ-sigs'-E⟦r⟧-θ
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| canθₖ-mergeˡ-E-induction-base-seq-notin sigs' (suc S') r
(θ ← [S]-env-present (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs') nothin∉canθ-sigs'-E⟦r⟧-θ
= refl
canθₖ-mergeˡ-E-induction-base-seq-notin {E} (just Signal.absent ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∉canθ-sigs'-E⟦r⟧-θ
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| canθₖ-mergeˡ-E-induction-base-seq-notin sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs') nothin∉canθ-sigs'-E⟦r⟧-θ
= refl
canθₖ-mergeˡ-E-induction-base-seq-notin {E} {q} (just Signal.unknown ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∉canθ-sigs'-E⟦r⟧-θ
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) >> q) (θ ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) (θ ← [S]-env (S' ₛ)))
... | yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S']
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| canθₖ-mergeˡ-E-induction-base-seq-notin sigs' (suc S') r
(θ ← [S]-env (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs') nothin∉canθ-sigs'-E⟦r⟧-θ
= refl
... | no S'∉canθ-sigs'-E⟦r⟧>>q-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| canθₖ-mergeˡ-E-induction-base-seq-notin sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs') nothin∉canθ-sigs'-E⟦r⟧-θ
= refl
... | yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←[S']
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← [S]-env (S' ₛ))
(deseq dehole) (CBseq CBnothing cbq distinct-empty-left)
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧>>q-θ←[S']))
... | no S'∉canθ-sigs'-E⟦r⟧>>q-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S'] =
⊥-elim
(S'∉canθ-sigs'-E⟦r⟧>>q-θ←[S']
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← [S]-env (S' ₛ))
(eseq q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←[S']))
canθₖ-mergeˡ-E-induction-base-seq-in : ∀ {E q E⟦nothin⟧>>q BV FV} sigs' S' r θ →
E⟦nothin⟧>>q ≐ (eseq q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧>>q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
Code.nothin ∈ Canθₖ sigs' S' (E ⟦ r ⟧e) θ →
Canθₖ sigs' S' ((E ⟦ r ⟧e) >> q) θ ≡
CodeSet.set-remove (Canθₖ sigs' S' (E ⟦ r ⟧e) θ) Code.nothin ++ Canₖ q θ
canθₖ-mergeˡ-E-induction-base-seq-in {E} [] S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∈canθ-sigs'-E⟦r⟧-θ
with any (Code._≟_ Code.nothin) (Canₖ (E ⟦ r ⟧e) θ)
... | no nothin∉can-E⟦r⟧-θ = ⊥-elim (nothin∉can-E⟦r⟧-θ nothin∈canθ-sigs'-E⟦r⟧-θ)
... | yes nothin∈can-E⟦r⟧-θ = refl
canθₖ-mergeˡ-E-induction-base-seq-in (nothing ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∈canθ-sigs'-E⟦r⟧-θ
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| canθₖ-mergeˡ-E-induction-base-seq-in sigs' (suc S') r
θ (deseq E⟦nothin⟧) cb FV≠sigs' nothin∈canθ-sigs'-E⟦r⟧-θ
= refl
canθₖ-mergeˡ-E-induction-base-seq-in {E} {q} (just Signal.present ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∈canθ-sigs'-E⟦r⟧-θ
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-seq-in sigs' (suc S') r
(θ ← [S]-env-present (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' ∷ []} FV≠sigs') nothin∈canθ-sigs'-E⟦r⟧-θ
= refl
canθₖ-mergeˡ-E-induction-base-seq-in {E} {q} (just Signal.absent ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∈canθ-sigs'-E⟦r⟧-θ
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-seq-in sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' ∷ []} FV≠sigs') nothin∈canθ-sigs'-E⟦r⟧-θ
= refl
canθₖ-mergeˡ-E-induction-base-seq-in {E} {q} (just Signal.unknown ∷ sigs') S' r θ
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _) FV≠sigs' nothin∈canθ-sigs'-E⟦r⟧-θ
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) >> q) (θ ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) (θ ← [S]-env (S' ₛ)))
... | yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S']
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-seq-in sigs' (suc S') r
(θ ← [S]-env (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' ∷ []} FV≠sigs') nothin∈canθ-sigs'-E⟦r⟧-θ
= refl
... | no S'∉canθ-sigs'-E⟦r⟧>>q-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite +-comm S' 0
| map-+-compose-suc S' (SigMap.keys sigs')
| can-irr θ ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| canθₖ-mergeˡ-E-induction-base-seq-in sigs' (suc S') r
(θ ← [S]-env-absent (S' ₛ)) (deseq E⟦nothin⟧) cb
(dist'++ʳ {V2 = S' ∷ []} FV≠sigs') nothin∈canθ-sigs'-E⟦r⟧-θ
= refl
... | yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←[S']
rewrite map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←[S']
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← [S]-env (S' ₛ))
(deseq dehole) (CBseq CBnothing cbq distinct-empty-left)
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧>>q-θ←[S']))
... | no S'∉canθ-sigs'-E⟦r⟧>>q-θ←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←[S'] =
⊥-elim
(S'∉canθ-sigs'-E⟦r⟧>>q-θ←[S']
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← [S]-env (S' ₛ))
(eseq q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←[S']))
canθₛ-mergeˡ-E-induction-base-par₁ : ∀ {E q E⟦nothin⟧∥q BV FV} sigs' S' r θ θo →
E⟦nothin⟧∥q ≐ (epar₁ q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧∥q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
∀ S'' →
S'' ∈ Canθₛ sigs' S' ((E ⟦ r ⟧e) ∥ q) (θ ← θo) →
S'' ∈ Canθₛ sigs' S' (E ⟦ r ⟧e) (θ ← θo) ⊎ S'' ∈ Canₛ q (θ ← θo)
canθₛ-mergeˡ-E-induction-base-par₁ {E} [] S' r θ θo
E⟦nothin⟧∥q cb FV≠sigs' S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
with ++⁻ (Canₛ (E ⟦ r ⟧e) (θ ← θo)) S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ S''∈can-E⟦r⟧-θ←θo = inj₁ S''∈can-E⟦r⟧-θ←θo
... | inj₂ S''∈can-q-θ←θo = inj₂ S''∈can-q-θ←θo
canθₛ-mergeˡ-E-induction-base-par₁ (nothing ∷ sigs') S' r θ θo
E⟦nothin⟧∥q cb FV≠sigs' S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₛ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ θo E⟦nothin⟧∥q cb
FV≠sigs' S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.present ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-present (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env-present (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present]
... | inj₂ S''∈can-q-θ←θo←[S'↦present]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-present (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦present]
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.absent ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ S''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦absent]
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb FV≠sigs' S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) ∥ q) ((θ ← θo) ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) ((θ ← θo) ← [S]-env (S' ₛ)))
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown]
... | inj₂ S''∈can-q-θ←θo←[S'↦unknown]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| Env.←-assoc θ θo ([S]-env (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦unknown]
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ S''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦absent]
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧∥q-θ←θo←[S]
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(epar₁ q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]))
canθₛ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbp cbq _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(depar₁ dehole) (CBpar CBnothing cbq distinct-empty-left distinct-empty-left
distinct-empty-left (λ _ ()))
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧∥q-θ←θo←[S]))
canθₛ-mergeˡ-E-induction-base-par₂ : ∀ {E q q∥E⟦nothin⟧ BV FV} sigs' S' r θ θo →
q∥E⟦nothin⟧ ≐ (epar₂ q ∷ E) ⟦ nothin ⟧e →
CorrectBinding q∥E⟦nothin⟧ BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
∀ S'' →
S'' ∈ Canθₛ sigs' S' (q ∥ (E ⟦ r ⟧e)) (θ ← θo) →
S'' ∈ Canθₛ sigs' S' (E ⟦ r ⟧e) (θ ← θo) ⊎ S'' ∈ Canₛ q (θ ← θo)
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} [] S' r θ θo
q∥E⟦nothin⟧ cb FV≠sigs' S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
with ++⁻ (Canₛ q (θ ← θo)) S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₂ S''∈can-E⟦r⟧-θ←θo = inj₁ S''∈can-E⟦r⟧-θ←θo
... | inj₁ S''∈can-q-θ←θo = inj₂ S''∈can-q-θ←θo
canθₛ-mergeˡ-E-induction-base-par₂ (nothing ∷ sigs') S' r θ θo
q∥E⟦nothin⟧ cb FV≠sigs' S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₛ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ θo q∥E⟦nothin⟧ cb
FV≠sigs' S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.present ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-present (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env-present (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present]
... | inj₂ S''∈can-q-θ←θo←[S'↦present]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-present (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦present]
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.absent ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ S''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦absent]
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb FV≠sigs' S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
with any (_≟_ S') (Canθₛ sigs' (suc S') (q ∥ (E ⟦ r ⟧e)) ((θ ← θo) ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) ((θ ← θo) ← [S]-env (S' ₛ)))
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| yes S'∈canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown]
... | inj₂ S''∈can-q-θ←θo←[S'↦unknown]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| Env.←-assoc θ θo ([S]-env (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦unknown]
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| no S'∉canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ S''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ S''∈can-q-θ←θo←[S'↦absent]
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| no S'∉canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
= ⊥-elim
(S'∉canθ-sigs'-q∥E⟦r⟧-θ←θo←[S]
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(epar₂ q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]))
canθₛ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
S'' S''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| yes S'∈canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(depar₂ dehole) (CBpar cbq CBnothing distinct-empty-right distinct-empty-right
distinct-empty-right (λ _ _ ()))
(λ S''' S'''∈map-+-suc-S'-sigs' S'''∈FVq++[] →
FV≠sigs' S''' (++ˡ (x∈xs++[]→x∈xs {xs = proj₁ FVp} S'''∈FVq++[]))
(there S'''∈map-+-suc-S'-sigs'))
(S' ₛ) (λ S'∈FVq++[] → FV≠sigs' S' (++ˡ (x∈xs++[]→x∈xs {xs = proj₁ FVp} S'∈FVq++[])) (here refl))
S'∈canθ-sigs'-q∥E⟦r⟧-θ←θo←[S]))
canθₛ-mergeˡ-E-induction-base-seq : ∀ {E q E⟦nothin⟧>>q BV FV} sigs' S' r θ θo →
E⟦nothin⟧>>q ≐ (eseq q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧>>q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
∀ S'' →
S'' ∈ Canθₛ sigs' S' ((E ⟦ r ⟧e) >> q) (θ ← θo) →
S'' ∈ Canθₛ sigs' S' (E ⟦ r ⟧e) (θ ← θo) ⊎
(S'' ∈ Canₛ q (θ ← θo) × Code.nothin ∈ Canθₖ sigs' S' (E ⟦ r ⟧e) (θ ← θo))
canθₛ-mergeˡ-E-induction-base-seq {E} {q} [] S' r θ θo
E⟦nothin⟧>>q cb FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
with any (Code._≟_ Code.nothin) (Canₖ (E ⟦ r ⟧e) (θ ← θo))
... | no nothin∉can-E⟦r⟧-θ←θo = inj₁ S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | yes nothin∈can-E⟦r⟧-θ←θo
with ++⁻ (Canₛ (E ⟦ r ⟧e) (θ ← θo)) S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ S''∈can-E⟦r⟧-θ←θo = inj₁ S''∈can-E⟦r⟧-θ←θo
... | inj₂ S''∈can-q-θ←θo = inj₂ (S''∈can-q-θ←θo ,′ nothin∈can-E⟦r⟧-θ←θo)
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (nothing ∷ sigs') S' r θ θo E⟦nothin⟧>>q
cb FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₛ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ θo
E⟦nothin⟧>>q cb FV≠sigs' S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.present ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-present (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env-present (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present]
... | inj₂ (S''∈can-q-θ←θo←[S'↦present] , nothin∈can-E⟦r⟧-θ←θo←[S'↦present])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-present (S' ₛ))
= inj₂ (S''∈can-q-θ←θo←[S'↦present] , nothin∈can-E⟦r⟧-θ←θo←[S'↦present])
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.absent ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ (S''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ (S''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) >> q) ((θ ← θo) ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) ((θ ← θo) ← [S]-env (S' ₛ)))
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown]
... | inj₂ (S''∈can-q-θ←θo←[S'↦unknown] , nothin∈can-E⟦r⟧-θ←θo←[S'↦unknown])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| Env.←-assoc θ θo ([S]-env (S' ₛ))
= inj₂ (S''∈can-q-θ←θo←[S'↦unknown] , nothin∈can-E⟦r⟧-θ←θo←[S'↦unknown])
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ S''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ (S''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ (S''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧>>q-θ←θo←[S']
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(eseq q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S']))
canθₛ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
S'' S''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S']
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(deseq dehole) (CBseq CBnothing cbq distinct-empty-left)
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧>>q-θ←θo←[S']))
canθₛₕ-mergeˡ-E-induction-base-par₁ : ∀ {E q E⟦nothin⟧∥q BV FV} sigs' S' r θ θo →
E⟦nothin⟧∥q ≐ (epar₁ q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧∥q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
∀ s'' →
s'' ∈ Canθₛₕ sigs' S' ((E ⟦ r ⟧e) ∥ q) (θ ← θo) →
s'' ∈ Canθₛₕ sigs' S' (E ⟦ r ⟧e) (θ ← θo) ⊎ s'' ∈ Canₛₕ q (θ ← θo)
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} [] S' r θ θo
E⟦nothin⟧∥q cb FV≠sigs' s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
with ++⁻ (Canₛₕ (E ⟦ r ⟧e) (θ ← θo)) s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ s''∈can-E⟦r⟧-θ←θo = inj₁ s''∈can-E⟦r⟧-θ←θo
... | inj₂ s''∈can-q-θ←θo = inj₂ s''∈can-q-θ←θo
canθₛₕ-mergeˡ-E-induction-base-par₁ (nothing ∷ sigs') S' r θ θo
E⟦nothin⟧∥q cb FV≠sigs' s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₛₕ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ θo E⟦nothin⟧∥q cb
FV≠sigs' s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.present ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-present (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env-present (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present]
... | inj₂ s''∈can-q-θ←θo←[S'↦present]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-present (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦present]
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.absent ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ s''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦absent]
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb FV≠sigs' s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) ∥ q) ((θ ← θo) ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) ((θ ← θo) ← [S]-env (S' ₛ)))
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown]
... | inj₂ s''∈can-q-θ←θo←[S'↦unknown]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| Env.←-assoc θ θo ([S]-env (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦unknown]
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₁ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₁ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ s''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦absent]
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} _ cbq _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧∥q-θ←θo←[S]
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(epar₁ q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]))
canθₛₕ-mergeˡ-E-induction-base-par₁ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₁ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbp cbq _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧∥q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧∥q-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(depar₁ dehole) (CBpar CBnothing cbq distinct-empty-left distinct-empty-left
distinct-empty-left (λ _ ()))
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧∥q-θ←θo←[S]))
canθₛₕ-mergeˡ-E-induction-base-par₂ : ∀ {E q q∥E⟦nothin⟧ BV FV} sigs' S' r θ θo →
q∥E⟦nothin⟧ ≐ (epar₂ q ∷ E) ⟦ nothin ⟧e →
CorrectBinding q∥E⟦nothin⟧ BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
∀ s'' →
s'' ∈ Canθₛₕ sigs' S' (q ∥ (E ⟦ r ⟧e)) (θ ← θo) →
s'' ∈ Canθₛₕ sigs' S' (E ⟦ r ⟧e) (θ ← θo) ⊎ s'' ∈ Canₛₕ q (θ ← θo)
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} [] S' r θ θo
q∥E⟦nothin⟧ cb FV≠sigs' s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
with ++⁻ (Canₛₕ q (θ ← θo)) s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₂ s''∈can-E⟦r⟧-θ←θo = inj₁ s''∈can-E⟦r⟧-θ←θo
... | inj₁ s''∈can-q-θ←θo = inj₂ s''∈can-q-θ←θo
canθₛₕ-mergeˡ-E-induction-base-par₂ (nothing ∷ sigs') S' r θ θo
q∥E⟦nothin⟧ cb FV≠sigs' s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₛₕ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ θo q∥E⟦nothin⟧ cb
FV≠sigs' s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.present ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-present (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env-present (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present]
... | inj₂ s''∈can-q-θ←θo←[S'↦present]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-present (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦present]
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.absent ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ s''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦absent]
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb FV≠sigs' s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
with any (_≟_ S') (Canθₛ sigs' (suc S') (q ∥ (E ⟦ r ⟧e)) ((θ ← θo) ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) ((θ ← θo) ← [S]-env (S' ₛ)))
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| yes S'∈canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown]
... | inj₂ s''∈can-q-θ←θo←[S'↦unknown]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| Env.←-assoc θ θo ([S]-env (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦unknown]
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| no S'∉canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-par₂ sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(depar₂ E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ s''∈can-q-θ←θo←[S'↦absent]
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ˡ)
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ s''∈can-q-θ←θo←[S'↦absent]
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar cbq _ _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| no S'∉canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
= ⊥-elim
(S'∉canθ-sigs'-q∥E⟦r⟧-θ←θo←[S]
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(epar₂ q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S]))
canθₛₕ-mergeˡ-E-induction-base-par₂ {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(depar₂ E⟦nothin⟧) cb@(CBpar {FVp = FVp} cbq _ _ _ _ _) FV≠sigs'
s'' s''∈canθ-sigs'-q∥E⟦r⟧-θ←θo
| yes S'∈canθ-sigs'-q∥E⟦r⟧-θ←θo←[S] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S]
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(depar₂ dehole) (CBpar cbq CBnothing distinct-empty-right distinct-empty-right
distinct-empty-right (λ _ _ ()))
(λ s''' s'''∈map-+-suc-S'-sigs' s'''∈FVq++[] →
FV≠sigs' s''' (++ˡ (x∈xs++[]→x∈xs {xs = proj₁ FVp} s'''∈FVq++[]))
(there s'''∈map-+-suc-S'-sigs'))
(S' ₛ) (λ S'∈FVq++[] → FV≠sigs' S' (++ˡ (x∈xs++[]→x∈xs {xs = proj₁ FVp} S'∈FVq++[])) (here refl))
S'∈canθ-sigs'-q∥E⟦r⟧-θ←θo←[S]))
canθₛₕ-mergeˡ-E-induction-base-seq : ∀ {E q E⟦nothin⟧>>q BV FV} sigs' S' r θ θo →
E⟦nothin⟧>>q ≐ (eseq q ∷ E) ⟦ nothin ⟧e →
CorrectBinding E⟦nothin⟧>>q BV FV →
distinct' (proj₁ FV) (map (_+_ S') (SigMap.keys sigs')) →
∀ s'' →
s'' ∈ Canθₛₕ sigs' S' ((E ⟦ r ⟧e) >> q) (θ ← θo) →
s'' ∈ Canθₛₕ sigs' S' (E ⟦ r ⟧e) (θ ← θo) ⊎
(s'' ∈ Canₛₕ q (θ ← θo) × Code.nothin ∈ Canθₖ sigs' S' (E ⟦ r ⟧e) (θ ← θo))
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} [] S' r θ θo
E⟦nothin⟧>>q cb FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
with any (Code._≟_ Code.nothin) (Canₖ (E ⟦ r ⟧e) (θ ← θo))
... | no nothin∉can-E⟦r⟧-θ←θo = inj₁ s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | yes nothin∈can-E⟦r⟧-θ←θo
with ++⁻ (Canₛₕ (E ⟦ r ⟧e) (θ ← θo)) s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ s''∈can-E⟦r⟧-θ←θo = inj₁ s''∈can-E⟦r⟧-θ←θo
... | inj₂ s''∈can-q-θ←θo = inj₂ (s''∈can-q-θ←θo ,′ nothin∈can-E⟦r⟧-θ←θo)
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (nothing ∷ sigs') S' r θ θo E⟦nothin⟧>>q
cb FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
rewrite map-+-compose-suc S' (SigMap.keys sigs')
= canθₛₕ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ θo
E⟦nothin⟧>>q cb FV≠sigs' s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.present ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-present (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env-present (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦present]
... | inj₂ (s''∈can-q-θ←θo←[S'↦present] , nothin∈can-E⟦r⟧-θ←θo←[S'↦present])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-present (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.present FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-present (S' ₛ))
= inj₂ (s''∈can-q-θ←θo←[S'↦present] , nothin∈can-E⟦r⟧-θ←θo←[S'↦present])
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.absent ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ (s''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ (s''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
with any (_≟_ S') (Canθₛ sigs' (suc S') ((E ⟦ r ⟧e) >> q) ((θ ← θo) ← [S]-env (S' ₛ)))
| any (_≟_ S') (Canθₛ sigs' (suc S') (E ⟦ r ⟧e) ((θ ← θo) ← [S]-env (S' ₛ)))
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦unknown]
... | inj₂ (s''∈can-q-θ←θo←[S'↦unknown] , nothin∈can-E⟦r⟧-θ←θo←[S'↦unknown])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.unknown FV≠sigs'))
| Env.←-assoc θ θo ([S]-env (S' ₛ))
= inj₂ (s''∈can-q-θ←θo←[S'↦unknown] , nothin∈can-E⟦r⟧-θ←θo←[S'↦unknown])
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env-absent (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
with canθₛₕ-mergeˡ-E-induction-base-seq sigs' (suc S') r θ (θo ← [S]-env-absent (S' ₛ))
(deseq E⟦nothin⟧) cb (dist'++ʳ {V2 = S' + 0 ∷ []} FV≠sigs')
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
... | inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent] =
inj₁ s''∈canθ-sigs'-E⟦r⟧-θ←θo←[S'↦absent]
... | inj₂ (s''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
rewrite +-comm S' 0
| can-irr (θ ← θo) ([S]-env-absent (S' ₛ)) q cbq
(distinct'-to-left (dist'++ʳ {V2 = proj₁ FVp})
(distinct'-S∷Ss⇒[S] Signal.absent FV≠sigs'))
| Env.←-assoc θ θo ([S]-env-absent (S' ₛ))
= inj₂ (s''∈can-q-θ←θo←[S'↦absent] , nothin∈can-E⟦r⟧-θ←θo←[S'↦absent])
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| no S'∉canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | yes S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧>>q-θ←θo←[S']
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(eseq q) (E ⟦ r ⟧e) (S' ₛ) S'∈canθ-sigs'-E⟦r⟧-θ←θo←[S']))
canθₛₕ-mergeˡ-E-induction-base-seq {E} {q} (just Signal.unknown ∷ sigs') S' r θ θo
(deseq E⟦nothin⟧) cb@(CBseq {FVp = FVp} _ cbq _) FV≠sigs'
s'' s''∈canθ-sigs'-E⟦r⟧>>q-θ←θo
| yes S'∈canθ-sigs'-E⟦r⟧>>q-θ←θo←[S'] | no S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S']
rewrite sym (Env.←-assoc θ θo ([S]-env (S' ₛ)))
| map-+-compose-suc S' (SigMap.keys sigs')
| +-comm S' 0
= ⊥-elim
(S'∉canθ-sigs'-E⟦r⟧-θ←θo←[S']
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs' (suc S') (θ ← (θo ← [S]-env (S' ₛ)))
(deseq dehole) (CBseq CBnothing cbq distinct-empty-left)
(dist'++ʳ {V2 = proj₁ FVp} (distinct'-sym (dist'++ʳ {V2 = S' ∷ []} FV≠sigs')))
(S' ₛ) (λ S'∈FVq → FV≠sigs' S' (++ʳ (proj₁ FVp) S'∈FVq) (here refl))
S'∈canθ-sigs'-E⟦r⟧>>q-θ←θo←[S']))
| 52.631913
| 107
| 0.53384
|
d1345972aca5222273349cc82fd57c1e6f4774d0
| 827
|
agda
|
Agda
|
test/Succeed/Issue44.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue44.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue44.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.polarity:10 #-}
module Issue44 where
data Ty : Set where
ι : Ty
_⇒_ : Ty -> Ty -> Ty
data Con : Set where
ε : Con
_<_ : Con -> Ty -> Con
data Var : Con -> Ty -> Set where
vZ : forall {Γ σ} -> Var (Γ < σ) σ
vS : forall {Γ σ}{τ : Ty} -> Var Γ σ -> Var (Γ < τ) σ
{-
stren : forall {Γ σ} -> Var Γ σ -> Con
stren (vZ {Γ}) = Γ
stren (vS {τ = τ} v) = stren v < τ
_/_ : forall Γ {σ} -> Var Γ σ -> Con
Γ / v = stren v
-}
-- However if I make stren a local function:
_/_ : forall Γ {σ} -> Var Γ σ -> Con
Γ / v = stren v where
stren : forall {Γ σ} -> Var Γ σ -> Con
stren (vZ {Γ}) = Γ
stren (vS {τ = τ} v) = stren v < τ
thin : forall {Γ σ τ}(v : Var Γ σ) -> Var (Γ / v) τ -> Var Γ τ
thin vZ v' = vS v'
thin (vS v) vZ = vZ
thin (vS v) (vS v') = vS (thin v v')
| 21.763158
| 62
| 0.512696
|
5ead6bdd2f5349deb0d75395fb035f6d6e81a6d6
| 28
|
agda
|
Agda
|
test/interaction/Issue3082.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3082.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3082.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
A : Set
A = ?
B : Set
B = ?
| 5.6
| 7
| 0.357143
|
5e6bd7cecc022cd241762354fa152b1dc17fa54c
| 278
|
agda
|
Agda
|
test/Pragmas.agda
|
JonathanBrouwer/agda2hs
|
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
|
[
"MIT"
] | 55
|
2020-10-20T13:36:25.000Z
|
2022-03-26T21:57:56.000Z
|
test/Pragmas.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 63
|
2020-10-22T05:19:27.000Z
|
2022-02-25T15:47:30.000Z
|
test/Pragmas.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 18
|
2020-10-21T22:19:09.000Z
|
2022-03-12T11:42:52.000Z
|
module Pragmas where
-- Check that Haskell code is parsed with the correct language pragmas
{-# FOREIGN AGDA2HS
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE LambdaCase #-}
#-}
{-# FOREIGN AGDA2HS
foo :: Bool -> a -> (a, Int)
foo = \ case
False -> (, 0)
True -> (, 1)
#-}
| 17.375
| 70
| 0.618705
|
193dcfbc7d4617fef94fd1553b9764f9c9efbf4c
| 1,340
|
agda
|
Agda
|
test/Fail/TerminationRecordPatternListAppend.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Fail/TerminationRecordPatternListAppend.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Fail/TerminationRecordPatternListAppend.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- 2010-10-06 Andreas
module TerminationRecordPatternListAppend where
data Empty : Set where
record Unit : Set where
constructor unit
data Bool : Set where
true false : Bool
T : Bool -> Set
T true = Unit
T false = Empty
-- Thorsten suggests on the Agda list thread "Coinductive families"
-- to encode lists as records
record List (A : Set) : Set where
inductive
constructor list
field
isCons : Bool
head : T isCons -> A
tail : T isCons -> List A
open List public
-- if the record constructor list was counted as structural increase
-- Thorsten's function would not be rejected
-- UPDATE: and indeed it's not. Safe because we don't translate away
-- non-eta record patterns.
append : {A : Set} -> List A -> List A -> List A
append (list true h t) l' = list true h (\ _ -> append (t _) l')
append (list false _ _) l' = l'
-- but translating away the record pattern produces something
-- that is in any case rejected by the termination checker
append1 : {A : Set} -> List A -> List A -> List A
append1 {A} l' l = append1' (isCons l') (head l') (tail l') l
where
append1' : (isCons : Bool)
(head : T isCons -> A)
(tail : T isCons -> List A) ->
List A -> List A
append1' true h t l = list true h \ _ -> append1 (t _) l
append1' false h t l = l
| 27.916667
| 68
| 0.638806
|
3d4af1906cc1430e93c6293b5dad74b04b4f7801
| 1,490
|
agda
|
Agda
|
Cats/Category/Discrete.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Category/Discrete.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Category/Discrete.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 1
|
2019-03-18T15:35:07.000Z
|
2019-03-18T15:35:07.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.PropositionalEquality using
( _≡_ ; refl ; sym ; trans ; subst ; cong )
module Cats.Category.Discrete {li} {I : Set li}
(I-set : ∀ {i j : I} (p q : i ≡ j) → p ≡ q)
where
open import Data.Product using (Σ-syntax ; _,_ ; proj₁ ; proj₂)
open import Data.Unit using (⊤)
open import Level
open import Cats.Category.Base
open import Cats.Functor using (Functor)
Obj : Set li
Obj = I
data _⇒_ : Obj → Obj → Set li where
id : ∀ {A} → A ⇒ A
⇒-contr : ∀ {A B} (f : A ⇒ B)
→ Σ[ p ∈ A ≡ B ] (subst (_⇒ B) p f ≡ id)
⇒-contr id = refl , refl
⇒-contr′ : ∀ {A} (f : A ⇒ A)
→ f ≡ id
⇒-contr′ f with ⇒-contr f
... | A≡A , f≡id rewrite I-set A≡A refl = f≡id
⇒-prop : ∀ {A B} (f g : A ⇒ B) → f ≡ g
⇒-prop {A} {B} id g = sym (⇒-contr′ g)
_∘_ : ∀ {A B C} → B ⇒ C → A ⇒ B → A ⇒ C
id ∘ id = id
Discrete : Category li li zero
Discrete = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = λ _ _ → ⊤
; id = id
; _∘_ = _∘_
; equiv = _
; ∘-resp = _
; id-r = _
; id-l = _
; assoc = _
}
functor : ∀ {lo la l≈} {C : Category lo la l≈}
→ (I → Category.Obj C)
→ Functor Discrete C
functor {C = C} f = record
{ fobj = f
; fmap = fmap
; fmap-resp = λ {A} {B} {g} {h} _ → C.≈.reflexive (cong fmap (⇒-prop g h))
; fmap-id = C.≈.refl
; fmap-∘ = λ { {f = id} {id} → C.id-l }
}
where
module C = Category C
fmap : ∀ {A B} (g : A ⇒ B) → f A C.⇒ f B
fmap id = C.id
| 20.135135
| 78
| 0.497987
|
31ed25b9fa8973cafc749e904058ca84c5cd6234
| 341
|
agda
|
Agda
|
test/Succeed/Issue5191.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue5191.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue5191.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- This code is closely based on code due to Andy Morris.
data _≡⁰_ {A : Set} (@0 x : A) : @0 A → Set where refl : x ≡⁰ x
data _≡ʷ_ {A : Set} (@ω x : A) : @ω A → Set where refl : x ≡ʷ x
works : ∀ {A} {@0 x y : A} → x ≡⁰ y → x ≡ʷ y
works refl = refl
also-works : ∀ {A} {@0 x y : A} → x ≡⁰ y → x ≡ʷ y
also-works {x = x} refl = refl {x = x}
| 31
| 63
| 0.513196
|
4300b3edfe49b8b7f97511fd93bc10ed118a075b
| 421
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/SetoidReasoning.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/SetoidReasoning.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/SetoidReasoning.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use the
-- Relation.Binary.Reasoning.MultiSetoid module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.SetoidReasoning where
open import Relation.Binary.Reasoning.MultiSetoid public
| 32.384615
| 72
| 0.505938
|
1c63ca1bc8905f7ebedb9bb852c31905aeca7a32
| 2,777
|
agda
|
Agda
|
Cubical/Algebra/NatSolver/HornerForms.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/NatSolver/HornerForms.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/NatSolver/HornerForms.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.NatSolver.HornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat hiding (isZero)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool using (Bool; true; false; if_then_else_)
private
variable
ℓ : Level
{-
This defines the type of multivariate Polynomials over ℕ.
The construction is based on the algebraic fact
ℕ[X₀][X₁]⋯[Xₙ] ≅ ℕ[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n k' is identified
with 'Xₖ', what we construct should rather be denoted with
ℕ[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((ℕ[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms : ℕ → Type ℓ-zero where
const : ℕ → IteratedHornerForms ℕ.zero
0H : {n : ℕ} → IteratedHornerForms (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms (ℕ.suc n) → IteratedHornerForms n
→ IteratedHornerForms (ℕ.suc n)
eval : {n : ℕ} (P : IteratedHornerForms n)
→ Vec ℕ n → ℕ
eval (const r) [] = r
eval 0H (_ ∷ _) = 0
eval (P ·X+ Q) (x ∷ xs) =
(eval P (x ∷ xs)) · x + eval Q xs
module IteratedHornerOperations where
private
1H' : (n : ℕ) → IteratedHornerForms n
1H' ℕ.zero = const 1
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms n
0H' ℕ.zero = const 0
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms n
→ IteratedHornerForms n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) = (P +ₕ Q) ·X+ (r +ₕ s)
isZero : {n : ℕ} → IteratedHornerForms (ℕ.suc n)
→ Bool
isZero 0H = true
isZero (P ·X+ P₁) = false
_⋆_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms (ℕ.suc n)
→ IteratedHornerForms (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms n
→ IteratedHornerForms n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) = (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
Variable : (n : ℕ) (k : Fin n) → IteratedHornerForms n
Variable n k = IteratedHornerOperations.X n k
Constant : (n : ℕ) (r : ℕ) → IteratedHornerForms n
Constant ℕ.zero r = const r
Constant (ℕ.suc n) r = IteratedHornerOperations.0ₕ ·X+ Constant n r
| 27.49505
| 75
| 0.592006
|
439d235139ea839162478e6c8b49e6e37412370a
| 5,240
|
agda
|
Agda
|
core/lib/cubical/SquareOver.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/cubical/SquareOver.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/cubical/SquareOver.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.Base
open import lib.PathGroupoid
open import lib.PathOver
open import lib.cubical.Square
module lib.cubical.SquareOver where
SquareOver : ∀ {i j} {A : Type i} (B : A → Type j) {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
{b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}
(q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]) (q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ])
(q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]) (q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ])
→ Type j
SquareOver B ids = Square
apd-square : ∀ {i j} {A : Type i} {B : A → Type j} (f : Π A B)
{a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ SquareOver B sq (apd f p₀₋) (apd f p₋₀) (apd f p₋₁) (apd f p₁₋)
apd-square f ids = ids
↓-=-to-squareover : ∀ {i j} {A : Type i} {B : A → Type j}
{f g : Π A B} {x y : A} {p : x == y}
{u : f x == g x} {v : f y == g y}
→ u == v [ (λ z → f z == g z) ↓ p ]
→ SquareOver B vid-square u (apd f p) (apd g p) v
↓-=-to-squareover {p = idp} idp = hid-square
↓-=-from-squareover : ∀ {i j} {A : Type i} {B : A → Type j}
{f g : Π A B} {x y : A} {p : x == y}
{u : f x == g x} {v : f y == g y}
→ SquareOver B vid-square u (apd f p) (apd g p) v
→ u == v [ (λ z → f z == g z) ↓ p ]
↓-=-from-squareover {p = idp} sq = horiz-degen-path sq
squareover-cst-in : ∀ {i j} {A : Type i} {B : Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq : Square p₀₋ p₋₀ p₋₁ p₁₋}
{b₀₀ b₀₁ b₁₀ b₁₁ : B}
{q₀₋ : b₀₀ == b₀₁} {q₋₀ : b₀₀ == b₁₀} {q₋₁ : b₀₁ == b₁₁} {q₁₋ : b₁₀ == b₁₁}
(sq' : Square q₀₋ q₋₀ q₋₁ q₁₋)
→ SquareOver (λ _ → B) sq
(↓-cst-in q₀₋) (↓-cst-in q₋₀) (↓-cst-in q₋₁) (↓-cst-in q₁₋)
squareover-cst-in {sq = ids} sq' = sq'
↓↓-from-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k}
{x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)}
{p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂}
{α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]}
→ SquareOver B (natural-square p q)
α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β
→ α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ]
↓↓-from-squareover {q = idp} sq = lemma sq
where
lemma : ∀ {i j} {A : Type i} {B : A → Type j}
{x y : A} {u : B x} {v : B y} {p : x == y}
{α β : u == v [ B ↓ p ]}
→ SquareOver B hid-square α idp idp β
→ α == β
lemma {p = idp} sq = horiz-degen-path sq
↓↓-to-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k}
{x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)}
{p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂}
{α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]}
→ α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ]
→ SquareOver B (natural-square p q)
α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β
↓↓-to-squareover {q = idp} r = lemma r
where
lemma : ∀ {i j} {A : Type i} {B : A → Type j}
{x y : A} {u : B x} {v : B y} {p : x == y}
{α β : u == v [ B ↓ p ]}
→ α == β
→ SquareOver B hid-square α idp idp β
lemma {p = idp} r = horiz-degen-square r
infixr 80 _∙v↓⊡_ _∙h↓⊡_ _↓⊡v∙_ _↓⊡h∙_
_∙h↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq : Square p₀₋ p₋₀ p₋₁ p₁₋}
{b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}
{q₀₋ q₀₋' : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}
{q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}
→ q₀₋ == q₀₋'
→ SquareOver B sq q₀₋' q₋₀ q₋₁ q₁₋
→ SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋
_∙h↓⊡_ {sq = ids} = _∙h⊡_
_∙v↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq : Square p₀₋ p₋₀ p₋₁ p₁₋}
{b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}
{q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ q₋₀' : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}
{q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}
→ q₋₀ == q₋₀'
→ SquareOver B sq q₀₋ q₋₀' q₋₁ q₁₋
→ SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋
_∙v↓⊡_ {sq = ids} = _∙v⊡_
_↓⊡v∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq : Square p₀₋ p₋₀ p₋₁ p₁₋}
{b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}
{q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}
{q₋₁ q₋₁' : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}
→ SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋
→ q₋₁ == q₋₁'
→ SquareOver B sq q₀₋ q₋₀ q₋₁' q₁₋
_↓⊡v∙_ {sq = ids} = _⊡v∙_
_↓⊡h∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq : Square p₀₋ p₋₀ p₋₁ p₁₋}
{b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}
{q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}
{q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ q₁₋' : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}
→ SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋
→ q₁₋ == q₁₋'
→ SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋'
_↓⊡h∙_ {sq = ids} = _⊡h∙_
| 41.259843
| 77
| 0.447519
|
436170396f94e19be3baf0d60cec6ee4af88e65e
| 7,993
|
agda
|
Agda
|
Data/List/Permute.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Data/List/Permute.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Data/List/Permute.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical #-}
module Data.List.Permute where
open import Prelude
open import Data.Nat
open import Data.Nat.Properties using (_≤ᴮ_)
infixr 5 _∹_∷_
data Premuted {a} (A : Type a) : Type a where
[] : Premuted A
_∹_∷_ : ℕ → A → Premuted A → Premuted A
mutual
merge : Premuted A → Premuted A → Premuted A
merge [] = id
merge (n ∹ x ∷ xs) = mergeˡ n x (merge xs)
mergeˡ : ℕ → A → (Premuted A → Premuted A) → Premuted A → Premuted A
mergeˡ i x xs [] = i ∹ x ∷ xs []
mergeˡ i x xs (j ∹ y ∷ ys) = merge⁺ i x xs j y ys (i ≤ᴮ j)
merge⁺ : ℕ → A → (Premuted A → Premuted A) → ℕ → A → Premuted A → Bool → Premuted A
merge⁺ i x xs j y ys true = i ∹ x ∷ xs ((j ∸ i) ∹ y ∷ ys)
merge⁺ i x xs j y ys false = j ∹ y ∷ mergeˡ ((i ∸ j) ∸ 1) x xs ys
merge-idʳ : (xs : Premuted A) → merge xs [] ≡ xs
merge-idʳ [] = refl
merge-idʳ (i ∹ x ∷ xs) = cong (i ∹ x ∷_) (merge-idʳ xs)
open import Algebra
≤≡-trans : ∀ x y z → (x ≤ᴮ y) ≡ true → (y ≤ᴮ z) ≡ true → (x ≤ᴮ z) ≡ true
≤≡-trans zero y z p₁ p₂ = refl
≤≡-trans (suc x) zero z p₁ p₂ = ⊥-elim (subst (bool ⊤ ⊥) p₁ tt)
≤≡-trans (suc x) (suc y) zero p₁ p₂ = ⊥-elim (subst (bool ⊤ ⊥) p₂ tt)
≤≡-trans (suc x) (suc y) (suc z) p₁ p₂ = ≤≡-trans x y z p₁ p₂
<≡-trans : ∀ x y z → (x ≤ᴮ y) ≡ false → (y ≤ᴮ z) ≡ false → (x ≤ᴮ z) ≡ false
<≡-trans zero y z p₁ p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₁ tt)
<≡-trans (suc x) zero z p₁ p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)
<≡-trans (suc x) (suc y) zero p₁ p₂ = p₂
<≡-trans (suc x) (suc y) (suc z) p₁ p₂ = <≡-trans x y z p₁ p₂
≤≡-sub : ∀ i j k → (j ≤ᴮ k) ≡ true → (j ∸ i ≤ᴮ k ∸ i) ≡ true
≤≡-sub zero j k p = p
≤≡-sub (suc i) zero k p = refl
≤≡-sub (suc i) (suc j) zero p = ⊥-elim (subst (bool ⊤ ⊥) p tt)
≤≡-sub (suc i) (suc j) (suc k) p = ≤≡-sub i j k p
≥≡-sub : ∀ i j k → (j ≤ᴮ k) ≡ false → (i ≤ᴮ k) ≡ true → (j ∸ i ≤ᴮ k ∸ i) ≡ false
≥≡-sub i zero k p _ = ⊥-elim (subst (bool ⊥ ⊤) p tt)
≥≡-sub zero (suc j) k p _ = p
≥≡-sub (suc i) (suc j) zero p p₂ = ⊥-elim (subst (bool ⊤ ⊥) p₂ tt)
≥≡-sub (suc i) (suc j) (suc k) p p₂ = ≥≡-sub i j k p p₂
<≡-sub : ∀ i j k → (i ≤ᴮ j) ≡ false → (j ≤ᴮ k) ≡ false → (i ∸ k ∸ 1 ≤ᴮ j ∸ k ∸ 1) ≡ false
<≡-sub zero j k p _ = ⊥-elim (subst (bool ⊥ ⊤) p tt)
<≡-sub (suc i) zero k p p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)
<≡-sub (suc i) (suc j) zero p p₂ = p
<≡-sub (suc i) (suc j) (suc k) p p₂ = <≡-sub i j k p p₂
>≡-sub : ∀ i j k → (i ≤ᴮ j) ≡ true → (j ≤ᴮ k) ≡ false → (i ≤ᴮ k) ≡ false → (i ∸ k ∸ 1 ≤ᴮ j ∸ k ∸ 1) ≡ true
>≡-sub i zero k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)
>≡-sub zero (suc j) k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₃ tt)
>≡-sub (suc i) (suc j) zero p₁ p₂ p₃ = p₁
>≡-sub (suc i) (suc j) (suc k) p₁ p₂ p₃ = >≡-sub i j k p₁ p₂ p₃
zero-sub : ∀ n → zero ∸ n ≡ zero
zero-sub zero = refl
zero-sub (suc n) = refl
≤-sub-id : ∀ i j k → (i ≤ᴮ j) ≡ true → k ∸ i ∸ (j ∸ i) ≡ k ∸ j
≤-sub-id zero j k p = refl
≤-sub-id (suc i) zero k p = ⊥-elim (subst (bool ⊤ ⊥) p tt)
≤-sub-id (suc i) (suc j) zero p = zero-sub (j ∸ i)
≤-sub-id (suc i) (suc j) (suc k) p = ≤-sub-id i j k p
lemma₁ : ∀ i j k → (j ≤ᴮ k) ≡ false → i ∸ k ∸ 1 ∸ (j ∸ k ∸ 1) ∸ 1 ≡ i ∸ j ∸ 1
lemma₁ zero j k _ = cong (λ zk → zk ∸ 1 ∸ (j ∸ k ∸ 1) ∸ 1) (zero-sub k) ; cong (_∸ 1) (zero-sub (j ∸ k ∸ 1)) ; sym (cong (_∸ 1) (zero-sub j))
lemma₁ (suc i) zero k p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)
lemma₁ (suc i) (suc j) zero p₂ = refl
lemma₁ (suc i) (suc j) (suc k) p₂ = lemma₁ i j k p₂
lemma₂ : ∀ i j k → (i ≤ᴮ j) ≡ true → (j ≤ᴮ k) ≡ false → (i ≤ᴮ k) ≡ false → j ∸ i ≡ j ∸ k ∸ 1 ∸ (i ∸ k ∸ 1)
lemma₂ i zero k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)
lemma₂ zero (suc j) k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₃ tt)
lemma₂ (suc i) (suc j) zero p₁ p₂ p₃ = refl
lemma₂ (suc i) (suc j) (suc k) p₁ p₂ p₃ = lemma₂ i j k p₁ p₂ p₃
{-# TERMINATING #-}
merge-assoc : Associative (merge {A = A})
merge-assoc [] ys zs = refl
merge-assoc (i ∹ x ∷ xs) [] zs = cong (flip merge zs) (merge-idʳ (i ∹ x ∷ xs))
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) [] = merge-idʳ (merge (i ∹ x ∷ xs) (j ∹ y ∷ ys)) ; sym (cong (merge (i ∹ x ∷ xs)) (merge-idʳ (j ∹ y ∷ ys)))
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) with merge-assoc xs (j ∸ i ∹ y ∷ ys) (k ∸ i ∹ z ∷ zs) | merge-assoc (i ∸ k ∸ 1 ∹ x ∷ xs) (j ∸ k ∸ 1 ∹ y ∷ ys) zs | (merge-assoc (i ∸ j ∸ 1 ∹ x ∷ xs) ys (k ∸ j ∹ z ∷ zs)) | i ≤ᴮ j | inspect (i ≤ᴮ_) j | j ≤ᴮ k | inspect (j ≤ᴮ_) k
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | r | _ | _ | true | 〖 ij 〗 | true | 〖 jk 〗 = cong (merge⁺ i x (merge (merge xs (j ∸ i ∹ y ∷ ys))) k z zs) (≤≡-trans i j k ij jk) ;
cong (i ∹ x ∷_) (r ;
cong (merge xs) (cong (merge⁺ (j ∸ i) y (merge ys) (k ∸ i) z zs) (≤≡-sub i j k jk) ; cong (λ kij → j ∸ i ∹ y ∷ merge ys (kij ∹ z ∷ zs)) (≤-sub-id i j k ij))) ;
cong (merge⁺ i x (merge xs) j y (merge ys (k ∸ j ∹ z ∷ zs))) (sym ij)
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | r | _ | false | 〖 ij 〗 | false | 〖 jk 〗 = cong (merge⁺ j y (merge (mergeˡ (i ∸ j ∸ 1) x (merge xs) ys)) k z zs ) jk ;
cong (k ∹ z ∷_) (cong (λ s → mergeˡ (j ∸ k ∸ 1) y (merge (mergeˡ s x (merge xs) ys)) zs) (sym (lemma₁ i j k jk)) ;
cong (λ s → merge (merge⁺ (i ∸ k ∸ 1) x (merge xs) (j ∸ k ∸ 1) y ys s) zs) (sym (<≡-sub i j k ij jk)) ;
r) ;
cong (merge⁺ i x (merge xs) k z (mergeˡ (j ∸ k ∸ 1) y (merge ys) zs)) (sym (<≡-trans i j k ij jk))
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | _ | r | false | 〖 ij 〗 | true | 〖 jk 〗 = cong (merge⁺ j y (merge (mergeˡ (i ∸ j ∸ 1) x (merge xs) ys)) k z zs) jk ;
cong (j ∹ y ∷_) r ;
cong (merge⁺ i x (merge xs) j y (merge ys (k ∸ j ∹ z ∷ zs))) (sym ij)
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | _ | _ | true | ij | false | jk with i ≤ᴮ k | inspect (i ≤ᴮ_) k
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | r | _ | true | 〖 ij 〗 | false | 〖 jk 〗 | false | 〖 ik 〗 = cong (k ∹ z ∷_) ((cong (λ s → mergeˡ (i ∸ k ∸ 1) x (merge (merge xs (s ∹ y ∷ ys))) zs) (lemma₂ i j k ij jk ik) ;
cong (λ c → merge (merge⁺ (i ∸ k ∸ 1) x (merge xs) (j ∸ k ∸ 1) y ys c) zs) (sym (>≡-sub i j k ij jk ik ))) ;
r )
merge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | r | _ | _ | true | 〖 ij 〗 | false | 〖 jk 〗 | true | 〖 ik 〗 = cong (i ∹ x ∷_) (r ;
cong (merge xs) (cong (merge⁺ (j ∸ i) y (merge ys) (k ∸ i) z zs) (≥≡-sub i j k jk ik) ;
cong (λ s → k ∸ i ∹ z ∷ mergeˡ s y (merge ys) zs) (cong (_∸ 1) (≤-sub-id i k j ik)) ))
open import Data.List
index : List ℕ → List A → List (Premuted A)
index _ [] = []
index [] (x ∷ xs) = (0 ∹ x ∷ []) ∷ index [] xs
index (i ∷ is) (x ∷ xs) = (i ∹ x ∷ []) ∷ index is xs
unindex : Premuted A → List A
unindex [] = []
unindex (_ ∹ x ∷ xs) = x ∷ unindex xs
open import TreeFold
shuffle : List ℕ → List A → List A
shuffle is = unindex ∘ treeFold merge [] ∘ index is
open import Data.List.Syntax
e : List ℕ
e = shuffle [ 0 , 1 , 0 ] [ 1 , 2 , 3 ]
| 58.343066
| 278
| 0.423621
|
41bb1d998689d06e5622e14406f52e3c859ae8fc
| 495
|
agda
|
Agda
|
test/Fail/Issue2892.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2892.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2892.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Equality
test : (A : Set) (x y : A) → x ≡ y → Set
test A .y y refl with A
test A .y y refl | X = ?
-- Jesper, 2018-12-03, issue #2892:
-- Error message is:
-- Ill-typed pattern after with abstraction: y
-- (perhaps you can replace it by `_`?)
-- when checking that the clause ;Issue2892.with-14 A X y = ? has type
-- (A w : Set) (x : w) → Set
-- Implementing the suggestion makes the code typecheck, so this
-- behaviour is at least not obviously wrong.
| 30.9375
| 73
| 0.642424
|
52399363274a264466d29c9337e9b631a5c71160
| 420
|
agda
|
Agda
|
test/Fail/Issue1445-3.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1445-3.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1445-3.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
data Unit : Set where
unit : Unit
Foo : Unit → Set
Foo unit = Unit
Bar : Unit → Unit → Set
Bar unit = Foo
bar : ∀ x y → Bar x y ≡ Unit
bar unit unit = refl
{-# REWRITE bar #-}
test : ∀ x y → Bar x y
test _ _ = unit
works : ∀ x → Foo x
works x = test unit x
| 16.153846
| 46
| 0.654762
|
1379018306c7bd8e16c1d6f60b1cb5784ab72b57
| 979
|
agda
|
Agda
|
test/interaction/Issue2751.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/interaction/Issue2751.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/interaction/Issue2751.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Andreas, 2017-10-06, issue #2751
-- Highlighting for unsolved constraints
module _ where
open import Agda.Builtin.Size
module UnsolvedSizeConstraints where
mutual
data D (i : Size) (A : Set) : Set where
c : D′ i A → D i A
record D′ (i : Size) (A : Set) : Set where
inductive
field
size : Size< i
force : D size A
open D′
Map : (F : Set → Set) → Set₁
Map F = {A B : Set} → F A → F B
mutual
map-D : ∀ {i} → Map (D i)
map-D (c xs) = c (map-D′ xs)
map-D′ : ∀ {i} → Map (D′ i)
size (map-D′ t) = size t
force (map-D′ {i} t) = map-D {i = i} (force t) -- correct is i = size t
-- Problem WAS: no highlighting for unsolved constraints.
-- Now: yellow highlighting in last expression.
module UnsolvedLevelConstraints where
mutual
l = _
data D {a} (A : Set a) : Set l where
c : A → D A -- highlighted
data E (A : Set l) : Set1 where
c : A → E A -- highlighted
| 19.979592
| 79
| 0.552605
|
1e1537136e6cb01decf8eafdd9e180ce0a5ed8ee
| 2,782
|
agda
|
Agda
|
src/Categories/Adjoint/Construction/Adjunctions.agda
|
tetrapharmakon/agda-categories
|
cfa6aefd3069d4db995191b458c886edcfba8294
|
[
"MIT"
] | null | null | null |
src/Categories/Adjoint/Construction/Adjunctions.agda
|
tetrapharmakon/agda-categories
|
cfa6aefd3069d4db995191b458c886edcfba8294
|
[
"MIT"
] | null | null | null |
src/Categories/Adjoint/Construction/Adjunctions.agda
|
tetrapharmakon/agda-categories
|
cfa6aefd3069d4db995191b458c886edcfba8294
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Level
open import Categories.Category.Core using (Category)
open import Categories.Category
open import Categories.Monad
module Categories.Adjoint.Construction.Adjunctions {o ℓ e} {C : Category o ℓ e} (M : Monad C) where
open Category C
open import Categories.Adjoint
open import Categories.Functor
open import Categories.Morphism
open import Categories.Functor.Properties
open import Categories.NaturalTransformation.Core
open import Categories.NaturalTransformation.NaturalIsomorphism -- using (_≃_; unitorʳ; unitorˡ)
open import Categories.Morphism.Reasoning as MR
open import Categories.Tactic.Category
-- three things:
-- 1. the category of adjunctions splitting a given Monad
-- 2. the proof that EM(M) is the terminal object here
-- 3. the proof that KL(M) is the initial object here
record SplitObj : Set (suc o ⊔ suc ℓ ⊔ suc e) where
field
D : Category o ℓ e
F : Functor C D
G : Functor D C
adj : F ⊣ G
eqM : G ∘F F ≃ Monad.F M
record Split⇒ (X Y : SplitObj) : Set (suc o ⊔ suc ℓ ⊔ suc e) where
constructor Splitc⇒
private
module X = SplitObj X
module Y = SplitObj Y
field
H : Functor X.D Y.D
HF≃F' : H ∘F X.F ≃ Y.F
G'H≃G : Y.G ∘F H ≃ X.G
Split : Monad C → Category _ _ _
Split M = record
{ Obj = SplitObj
; _⇒_ = Split⇒
; _≈_ = λ U V → Split⇒.H U ≃ Split⇒.H V
; id = split-id
; _∘_ = comp
; assoc = λ { {f = f} {g = g} {h = h} → associator (Split⇒.H f) (Split⇒.H g) (Split⇒.H h) }
; sym-assoc = λ { {f = f} {g = g} {h = h} → sym-associator (Split⇒.H f) (Split⇒.H g) (Split⇒.H h) }
; identityˡ = unitorˡ
; identityʳ = unitorʳ
; identity² = unitor²
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = _ⓘₕ_
}
where
open NaturalTransformation
split-id : {A : SplitObj} → Split⇒ A A
split-id = record
{ H = Categories.Functor.id
; HF≃F' = unitorˡ
; G'H≃G = unitorʳ
}
comp : {A B X : SplitObj} → Split⇒ B X → Split⇒ A B → Split⇒ A X
comp {A = A} {B = B} {X = X} (Splitc⇒ Hᵤ HF≃F'ᵤ G'H≃Gᵤ) (Splitc⇒ Hᵥ HF≃F'ᵥ G'H≃Gᵥ) = record
{ H = Hᵤ ∘F Hᵥ
; HF≃F' = HF≃F'ᵤ ⓘᵥ (Hᵤ ⓘˡ HF≃F'ᵥ) ⓘᵥ associator (SplitObj.F A) Hᵥ Hᵤ
; G'H≃G = G'H≃Gᵥ ⓘᵥ (G'H≃Gᵤ ⓘʳ Hᵥ) ⓘᵥ sym-associator Hᵥ Hᵤ (SplitObj.G X)
}
open import Categories.Object.Terminal (Split M)
open import Categories.Object.Initial (Split M)
open import Categories.Category.Construction.EilenbergMoore
open import Categories.Category.Construction.Kleisli
EM-object : SplitObj
EM-object = record { D = {! EilenbergMoore M !}
; F = {! !}
; G = {! !}
; adj = {! !}
; eqM = {! !}
}
EM-terminal : IsTerminal EM-object
EM-terminal = {! !}
| 31.258427
| 101
| 0.614666
|
a0bc20a02967ecfb0a705e8bb96c270f00e4d051
| 1,408
|
agda
|
Agda
|
Structure/Sets/Relator.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Sets/Relator.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Sets/Relator.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Sets.Relator where
open import Functional
import Lvl
open import Logic
open import Logic.Propositional
open import Logic.Predicate
import Structure.Sets.Names as Names
open import Type
private variable ℓ ℓₗ ℓᵣ ℓᵣₑₗ : Lvl.Level
private variable S Sₗ Sᵣ E Eₗ Eᵣ : Type{ℓ}
private variable _∈ₗ_ : E → Sₗ → Stmt{ℓₗ}
private variable _∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}
module _ (_∈ₗ_ : E → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}) where
record SetEqualityRelation (_≡_ : Sₗ → Sᵣ → Stmt{ℓᵣₑₗ}) : Type{Lvl.of(E) Lvl.⊔ Lvl.of(Sₗ) Lvl.⊔ Lvl.of(Sᵣ) Lvl.⊔ ℓₗ Lvl.⊔ ℓᵣ Lvl.⊔ ℓᵣₑₗ} where
constructor intro
field membership : Names.SetEqualityMembership(_∈ₗ_)(_∈ᵣ_)(_≡_)
record SubsetRelation (_⊆_ : Sₗ → Sᵣ → Stmt{ℓᵣₑₗ}) : Type{Lvl.of(E) Lvl.⊔ Lvl.of(Sₗ) Lvl.⊔ Lvl.of(Sᵣ) Lvl.⊔ ℓₗ Lvl.⊔ ℓᵣ Lvl.⊔ ℓᵣₑₗ} where
constructor intro
field membership : Names.SubsetMembership(_∈ₗ_)(_∈ᵣ_)(_⊆_)
module _ ⦃ eq : ∃(SetEqualityRelation(_∈ₗ_)(_∈ᵣ_){ℓᵣₑₗ}) ⦄ where
open ∃(eq) using () renaming (witness to _≡_) public
open SetEqualityRelation([∃]-proof eq) using () renaming (membership to [≡]-membership) public
_≢_ = (¬_) ∘₂ (_≡_)
module _ ⦃ subset : ∃(SubsetRelation(_∈ₗ_)(_∈ᵣ_){ℓᵣ}) ⦄ where
open ∃(subset) using () renaming (witness to _⊆_) public
open SubsetRelation([∃]-proof subset) using () renaming (membership to [⊆]-membership) public
open Names.From-[⊆] (_⊆_) public
| 40.228571
| 144
| 0.676847
|
433d951b5d1f4a0abedd0f7804fa38a6d10d1436
| 690
|
agda
|
Agda
|
test/LibSucceed/InstanceArguments/09-higherOrderClasses.agda
|
KDr2/agda
|
98c9382a59f707c2c97d75919e389fc2a783ac75
|
[
"BSD-2-Clause"
] | null | null | null |
test/LibSucceed/InstanceArguments/09-higherOrderClasses.agda
|
KDr2/agda
|
98c9382a59f707c2c97d75919e389fc2a783ac75
|
[
"BSD-2-Clause"
] | null | null | null |
test/LibSucceed/InstanceArguments/09-higherOrderClasses.agda
|
KDr2/agda
|
98c9382a59f707c2c97d75919e389fc2a783ac75
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module InstanceArguments.09-higherOrderClasses where
open import Effect.Applicative
open import Effect.Monad
open import Effect.Monad.Indexed
open import Function
lift : ∀ {a b c} {A : Set a} {C : Set c} {B : A → Set b} →
({{x : A}} → B x) → (f : C → A) → {{x : C}} → B (f x)
lift m f {{x}} = m {{f x}}
monadToApplicative : ∀ {l} {M : Set l → Set l} → RawMonad M → RawApplicative M
monadToApplicative = RawIMonad.rawIApplicative
liftAToM : ∀ {l} {V : Set l} {M : Set l → Set l} → ({{appM : RawApplicative M}} → M V) →
{{monadM : RawMonad M}} → M V
liftAToM app {{x}} = lift (λ {{appM}} → app {{appM}}) monadToApplicative {{x}}
| 34.5
| 88
| 0.602899
|
9a128fbfd6fe7f1b3bc640ede1af71b50defcbb8
| 25,183
|
agda
|
Agda
|
Cubical/Foundations/HLevels.agda
|
fabianmasato/cubical
|
d5030a9c89070255fc575add4e9f37b97e6a0c0c
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/HLevels.agda
|
fabianmasato/cubical
|
d5030a9c89070255fc575add4e9f37b97e6a0c0c
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/HLevels.agda
|
fabianmasato/cubical
|
d5030a9c89070255fc575add4e9f37b97e6a0c0c
|
[
"MIT"
] | null | null | null |
{-
Basic theory about h-levels/n-types:
- Basic properties of isContr, isProp and isSet (definitions are in Prelude)
- Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.HLevels where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence using (ua ; univalenceIso)
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-zero; +-comm)
HLevel : Type₀
HLevel = ℕ
private
variable
ℓ ℓ' ℓ'' ℓ''' ℓ'''' ℓ''''' : Level
A : Type ℓ
B : A → Type ℓ
C : (x : A) → B x → Type ℓ
D : (x : A) (y : B x) → C x y → Type ℓ
E : (x : A) (y : B x) → (z : C x y) → D x y z → Type ℓ
w x y z : A
n : HLevel
isOfHLevel : HLevel → Type ℓ → Type ℓ
isOfHLevel 0 A = isContr A
isOfHLevel 1 A = isProp A
isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y)
isOfHLevelFun : (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isOfHLevelFun n f = ∀ b → isOfHLevel n (fiber f b)
isOfHLevelΩ→isOfHLevel :
∀ {ℓ} {A : Type ℓ} (n : ℕ)
→ ((x : A) → isOfHLevel (suc n) (x ≡ x)) → isOfHLevel (2 + n) A
isOfHLevelΩ→isOfHLevel zero hΩ x y =
J (λ y p → (q : x ≡ y) → p ≡ q) (hΩ x refl)
isOfHLevelΩ→isOfHLevel (suc n) hΩ x y =
J (λ y p → (q : x ≡ y) → isOfHLevel (suc n) (p ≡ q)) (hΩ x refl)
TypeOfHLevel : ∀ ℓ → HLevel → Type (ℓ-suc ℓ)
TypeOfHLevel ℓ n = TypeWithStr ℓ (isOfHLevel n)
hProp hSet hGroupoid h2Groupoid : ∀ ℓ → Type (ℓ-suc ℓ)
hProp ℓ = TypeOfHLevel ℓ 1
hSet ℓ = TypeOfHLevel ℓ 2
hGroupoid ℓ = TypeOfHLevel ℓ 3
h2Groupoid ℓ = TypeOfHLevel ℓ 4
-- lower h-levels imply higher h-levels
isOfHLevelSuc : (n : HLevel) → isOfHLevel n A → isOfHLevel (suc n) A
isOfHLevelSuc 0 = isContr→isProp
isOfHLevelSuc 1 = isProp→isSet
isOfHLevelSuc (suc (suc n)) h a b = isOfHLevelSuc (suc n) (h a b)
isSet→isGroupoid : isSet A → isGroupoid A
isSet→isGroupoid = isOfHLevelSuc 2
isGroupoid→is2Groupoid : isGroupoid A → is2Groupoid A
isGroupoid→is2Groupoid = isOfHLevelSuc 3
isOfHLevelPlus : (m : HLevel) → isOfHLevel n A → isOfHLevel (m + n) A
isOfHLevelPlus zero hA = hA
isOfHLevelPlus (suc m) hA = isOfHLevelSuc _ (isOfHLevelPlus m hA)
isContr→isOfHLevel : (n : HLevel) → isContr A → isOfHLevel n A
isContr→isOfHLevel zero cA = cA
isContr→isOfHLevel (suc n) cA = isOfHLevelSuc _ (isContr→isOfHLevel n cA)
isProp→isOfHLevelSuc : (n : HLevel) → isProp A → isOfHLevel (suc n) A
isProp→isOfHLevelSuc zero pA = pA
isProp→isOfHLevelSuc (suc n) pA = isOfHLevelSuc _ (isProp→isOfHLevelSuc n pA)
isOfHLevelPlus' : (m : HLevel) → isOfHLevel m A → isOfHLevel (m + n) A
isOfHLevelPlus' {n = n} 0 = isContr→isOfHLevel n
isOfHLevelPlus' {n = n} 1 = isProp→isOfHLevelSuc n
isOfHLevelPlus' {n = n} (suc (suc m)) hA a₀ a₁ = isOfHLevelPlus' (suc m) (hA a₀ a₁)
-- hlevel of path types
isProp→isContrPath : isProp A → (x y : A) → isContr (x ≡ y)
isProp→isContrPath h x y = h x y , isProp→isSet h x y _
isContr→isContrPath : isContr A → (x y : A) → isContr (x ≡ y)
isContr→isContrPath cA = isProp→isContrPath (isContr→isProp cA)
isOfHLevelPath' : (n : HLevel) → isOfHLevel (suc n) A → (x y : A) → isOfHLevel n (x ≡ y)
isOfHLevelPath' 0 = isProp→isContrPath
isOfHLevelPath' (suc n) h x y = h x y
isOfHLevelPath'⁻ : (n : HLevel) → ((x y : A) → isOfHLevel n (x ≡ y)) → isOfHLevel (suc n) A
isOfHLevelPath'⁻ zero h x y = h x y .fst
isOfHLevelPath'⁻ (suc n) h = h
isOfHLevelPath : (n : HLevel) → isOfHLevel n A → (x y : A) → isOfHLevel n (x ≡ y)
isOfHLevelPath 0 h x y = isContr→isContrPath h x y
isOfHLevelPath (suc n) h x y = isOfHLevelSuc n (isOfHLevelPath' n h x y)
-- h-level of isOfHLevel
isPropIsOfHLevel : (n : HLevel) → isProp (isOfHLevel n A)
isPropIsOfHLevel 0 = isPropIsContr
isPropIsOfHLevel 1 = isPropIsProp
isPropIsOfHLevel (suc (suc n)) f g i a b =
isPropIsOfHLevel (suc n) (f a b) (g a b) i
isPropIsSet : isProp (isSet A)
isPropIsSet = isPropIsOfHLevel 2
isPropIsGroupoid : isProp (isGroupoid A)
isPropIsGroupoid = isPropIsOfHLevel 3
isPropIs2Groupoid : isProp (is2Groupoid A)
isPropIs2Groupoid = isPropIsOfHLevel 4
TypeOfHLevel≡ : (n : HLevel) {X Y : TypeOfHLevel ℓ n} → ⟨ X ⟩ ≡ ⟨ Y ⟩ → X ≡ Y
TypeOfHLevel≡ n = Σ≡Prop (λ _ → isPropIsOfHLevel n)
-- hlevels are preserved by retracts (and consequently equivalences)
isContrRetract
: ∀ {B : Type ℓ}
→ (f : A → B) (g : B → A)
→ (h : retract f g)
→ (v : isContr B) → isContr A
fst (isContrRetract f g h (b , p)) = g b
snd (isContrRetract f g h (b , p)) x = (cong g (p (f x))) ∙ (h x)
isPropRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isProp B → isProp A
isPropRetract f g h p x y i =
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (p (f x) (f y) i))
isSetRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isSet B → isSet A
isSetRetract f g h set x y p q i j =
hcomp (λ k → λ { (i = i0) → h (p j) k
; (i = i1) → h (q j) k
; (j = i0) → h x k
; (j = i1) → h y k})
(g (set (f x) (f y)
(cong f p) (cong f q) i j))
isGroupoidRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isGroupoid B → isGroupoid A
isGroupoidRetract f g h grp x y p q P Q i j k =
hcomp ((λ l → λ { (i = i0) → h (P j k) l
; (i = i1) → h (Q j k) l
; (j = i0) → h (p k) l
; (j = i1) → h (q k) l
; (k = i0) → h x l
; (k = i1) → h y l}))
(g (grp (f x) (f y) (cong f p) (cong f q)
(cong (cong f) P) (cong (cong f) Q) i j k))
is2GroupoidRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ is2Groupoid B → is2Groupoid A
is2GroupoidRetract f g h grp x y p q P Q R S i j k l =
hcomp (λ r → λ { (i = i0) → h (R j k l) r
; (i = i1) → h (S j k l) r
; (j = i0) → h (P k l) r
; (j = i1) → h (Q k l) r
; (k = i0) → h (p l) r
; (k = i1) → h (q l) r
; (l = i0) → h x r
; (l = i1) → h y r})
(g (grp (f x) (f y) (cong f p) (cong f q)
(cong (cong f) P) (cong (cong f) Q)
(cong (cong (cong f)) R) (cong (cong (cong f)) S) i j k l))
isOfHLevelRetract
: (n : HLevel) {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isOfHLevel n B → isOfHLevel n A
isOfHLevelRetract 0 = isContrRetract
isOfHLevelRetract 1 = isPropRetract
isOfHLevelRetract 2 = isSetRetract
isOfHLevelRetract 3 = isGroupoidRetract
isOfHLevelRetract 4 = is2GroupoidRetract
isOfHLevelRetract (suc (suc (suc (suc (suc n))))) f g h ofLevel x y p q P Q R S =
isOfHLevelRetract (suc n) (cong (cong (cong (cong f))))
(λ s i j k l →
hcomp (λ r → λ { (i = i0) → h (R j k l) r
; (i = i1) → h (S j k l) r
; (j = i0) → h (P k l) r
; (j = i1) → h (Q k l) r
; (k = i0) → h (p l) r
; (k = i1) → h (q l) r
; (l = i0) → h x r
; (l = i1) → h y r})
(g (s i j k l)))
(λ s i j k l m →
hcomp (λ n → λ { (i = i1) → s j k l m
; (j = i0) → h (R k l m) (i ∨ n)
; (j = i1) → h (S k l m) (i ∨ n)
; (k = i0) → h (P l m) (i ∨ n)
; (k = i1) → h (Q l m) (i ∨ n)
; (l = i0) → h (p m) (i ∨ n)
; (l = i1) → h (q m) (i ∨ n)
; (m = i0) → h x (i ∨ n)
; (m = i1) → h y (i ∨ n) })
(h (s j k l m) i))
(ofLevel (f x) (f y)
(cong f p) (cong f q)
(cong (cong f) P) (cong (cong f) Q)
(cong (cong (cong f)) R) (cong (cong (cong f)) S))
isOfHLevelRetractFromIso : {A : Type ℓ} {B : Type ℓ'} (n : HLevel) → Iso A B → isOfHLevel n B → isOfHLevel n A
isOfHLevelRetractFromIso n e hlev = isOfHLevelRetract n (Iso.fun e) (Iso.inv e) (Iso.leftInv e) hlev
isOfHLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : HLevel) → A ≃ B → isOfHLevel n A → isOfHLevel n B
isOfHLevelRespectEquiv n eq = isOfHLevelRetract n (invEq eq) (eq .fst) (secEq eq)
isContrRetractOfConstFun : {A : Type ℓ} {B : Type ℓ'} (b₀ : B)
→ Σ[ f ∈ (B → A) ] ((x : A) → (f ∘ (λ _ → b₀)) x ≡ x)
→ isContr A
fst (isContrRetractOfConstFun b₀ ret) = ret .fst b₀
snd (isContrRetractOfConstFun b₀ ret) y = ret .snd y
-- h-level of dependent path types
isOfHLevelPathP' : {A : I → Type ℓ} (n : HLevel)
→ isOfHLevel (suc n) (A i1)
→ (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y)
isOfHLevelPathP' {A = A} n h x y =
isOfHLevelRetractFromIso n (PathPIsoPath _ x y) (isOfHLevelPath' n h _ _)
isOfHLevelPathP : {A : I → Type ℓ} (n : HLevel)
→ isOfHLevel n (A i1)
→ (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y)
isOfHLevelPathP {A = A} n h x y =
isOfHLevelRetractFromIso n (PathPIsoPath _ x y) (isOfHLevelPath n h _ _)
-- Fillers for cubes from h-level
isSet→isSet' : isSet A → isSet' A
isSet→isSet' Aset _ _ _ _ = toPathP (Aset _ _ _ _)
isSet'→isSet : isSet' A → isSet A
isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl
isSet→SquareP :
{A : I → I → Type ℓ}
(isSet : (i j : I) → isSet (A i j))
{a₀₀ : A i0 i0} {a₀₁ : A i0 i1} (a₀₋ : PathP (λ j → A i0 j) a₀₀ a₀₁)
{a₁₀ : A i1 i0} {a₁₁ : A i1 i1} (a₁₋ : PathP (λ j → A i1 j) a₁₀ a₁₁)
(a₋₀ : PathP (λ i → A i i0) a₀₀ a₁₀) (a₋₁ : PathP (λ i → A i i1) a₀₁ a₁₁)
→ SquareP A a₀₋ a₁₋ a₋₀ a₋₁
isSet→SquareP isset a₀₋ a₁₋ a₋₀ a₋₁ =
PathPIsoPath _ _ _ .Iso.inv (isOfHLevelPathP' 1 (isset _ _) _ _ _ _ )
isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A
isGroupoid→isGroupoid' {A = A} Agpd a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
PathPIsoPath (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋ .Iso.inv
(isGroupoid→isPropSquare _ _ _ _ _ _)
where
isGroupoid→isPropSquare :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ isProp (Square a₀₋ a₁₋ a₋₀ a₋₁)
isGroupoid→isPropSquare a₀₋ a₁₋ a₋₀ a₋₁ =
isOfHLevelRetractFromIso 1 (PathPIsoPath (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋) (Agpd _ _ _ _)
isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A
isGroupoid'→isGroupoid Agpd' x y p q r s = Agpd' r s refl refl refl refl
-- h-level of Σ-types
isContrΣ : isContr A → ((x : A) → isContr (B x)) → isContr (Σ A B)
isContrΣ {A = A} {B = B} (a , p) q =
let h : (x : A) (y : B x) → (q x) .fst ≡ y
h x y = (q x) .snd y
in (( a , q a .fst)
, ( λ x i → p (x .fst) i
, h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i))
isContrΣ′ : (ca : isContr A) → isContr (B (fst ca)) → isContr (Σ A B)
isContrΣ′ ca cb = isContrΣ ca (λ x → subst _ (snd ca x) cb)
section-Σ≡Prop
: (pB : (x : A) → isProp (B x)) {u v : Σ A B}
→ section (Σ≡Prop pB {u} {v}) (cong fst)
section-Σ≡Prop {A = A} pB {u} {v} p j i =
(p i .fst) , isProp→PathP (λ i → isOfHLevelPath 1 (pB (fst (p i)))
(Σ≡Prop pB {u} {v} (cong fst p) i .snd)
(p i .snd) )
refl refl i j
isEquiv-Σ≡Prop
: (pB : (x : A) → isProp (B x)) {u v : Σ A B}
→ isEquiv (Σ≡Prop pB {u} {v})
isEquiv-Σ≡Prop {A = A} pB {u} {v} = isoToIsEquiv (iso (Σ≡Prop pB) (cong fst) (section-Σ≡Prop pB) (λ _ → refl))
isPropΣ : isProp A → ((x : A) → isProp (B x)) → isProp (Σ A B)
isPropΣ pA pB t u = Σ≡Prop pB (pA (t .fst) (u .fst))
isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n (Σ A B)
isOfHLevelΣ 0 = isContrΣ
isOfHLevelΣ 1 = isPropΣ
isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y =
isOfHLevelRetractFromIso (suc n)
(invIso (IsoΣPathTransportPathΣ _ _))
(isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ x → h2 _ _ _)
isSetΣ : isSet A → ((x : A) → isSet (B x)) → isSet (Σ A B)
isSetΣ = isOfHLevelΣ 2
isGroupoidΣ : isGroupoid A → ((x : A) → isGroupoid (B x)) → isGroupoid (Σ A B)
isGroupoidΣ = isOfHLevelΣ 3
is2GroupoidΣ : is2Groupoid A → ((x : A) → is2Groupoid (B x)) → is2Groupoid (Σ A B)
is2GroupoidΣ = isOfHLevelΣ 4
-- h-level of ×
isProp× : {A : Type ℓ} {B : Type ℓ'} → isProp A → isProp B → isProp (A × B)
isProp× pA pB = isPropΣ pA (λ _ → pB)
isProp×2 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''}
→ isProp A → isProp B → isProp C → isProp (A × B × C)
isProp×2 pA pB pC = isProp× pA (isProp× pB pC)
isProp×3 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''}
→ isProp A → isProp B → isProp C → isProp D → isProp (A × B × C × D)
isProp×3 pA pB pC pD = isProp×2 pA pB (isProp× pC pD)
isProp×4 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''} {E : Type ℓ''''}
→ isProp A → isProp B → isProp C → isProp D → isProp E → isProp (A × B × C × D × E)
isProp×4 pA pB pC pD pE = isProp×3 pA pB pC (isProp× pD pE)
isProp×5 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''} {E : Type ℓ''''} {F : Type ℓ'''''}
→ isProp A → isProp B → isProp C → isProp D → isProp E → isProp F
→ isProp (A × B × C × D × E × F)
isProp×5 pA pB pC pD pE pF = isProp×4 pA pB pC pD (isProp× pE pF)
isOfHLevel× : ∀ {A : Type ℓ} {B : Type ℓ'} n → isOfHLevel n A → isOfHLevel n B
→ isOfHLevel n (A × B)
isOfHLevel× n hA hB = isOfHLevelΣ n hA (λ _ → hB)
isSet× : ∀ {A : Type ℓ} {B : Type ℓ'} → isSet A → isSet B → isSet (A × B)
isSet× = isOfHLevel× 2
isGroupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → isGroupoid A → isGroupoid B
→ isGroupoid (A × B)
isGroupoid× = isOfHLevel× 3
is2Groupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → is2Groupoid A → is2Groupoid B
→ is2Groupoid (A × B)
is2Groupoid× = isOfHLevel× 4
-- h-level of Π-types
isOfHLevelΠ : ∀ n → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n ((x : A) → B x)
isOfHLevelΠ 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i
isOfHLevelΠ 1 h f g i x = (h x) (f x) (g x) i
isOfHLevelΠ 2 h f g F G i j z = h z (f z) (g z) (funExt⁻ F z) (funExt⁻ G z) i j
isOfHLevelΠ 3 h f g p q P Q i j k z =
h z (f z) (g z)
(funExt⁻ p z) (funExt⁻ q z)
(cong (λ f → funExt⁻ f z) P) (cong (λ f → funExt⁻ f z) Q) i j k
isOfHLevelΠ 4 h f g p q P Q R S i j k l z =
h z (f z) (g z)
(funExt⁻ p z) (funExt⁻ q z)
(cong (λ f → funExt⁻ f z) P) (cong (λ f → funExt⁻ f z) Q)
(cong (cong (λ f → funExt⁻ f z)) R) (cong (cong (λ f → funExt⁻ f z)) S) i j k l
isOfHLevelΠ (suc (suc (suc (suc (suc n))))) h f g p q P Q R S =
isOfHLevelRetract (suc n)
(cong (cong (cong funExt⁻))) (cong (cong (cong funExt))) (λ _ → refl)
(isOfHLevelΠ (suc (suc (suc (suc n)))) (λ x → h x (f x) (g x))
(funExt⁻ p) (funExt⁻ q)
(cong funExt⁻ P) (cong funExt⁻ Q)
(cong (cong funExt⁻) R) (cong (cong funExt⁻) S))
isPropΠ : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x)
isPropΠ = isOfHLevelΠ 1
isPropΠ2 : (h : (x : A) (y : B x) → isProp (C x y))
→ isProp ((x : A) (y : B x) → C x y)
isPropΠ2 h = isPropΠ λ x → isPropΠ λ y → h x y
isPropΠ3 : (h : (x : A) (y : B x) (z : C x y) → isProp (D x y z))
→ isProp ((x : A) (y : B x) (z : C x y) → D x y z)
isPropΠ3 h = isPropΠ λ x → isPropΠ λ y → isPropΠ λ z → h x y z
isPropΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isProp (E x y z w))
→ isProp ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w)
isPropΠ4 h = isPropΠ λ _ → isPropΠ3 λ _ → h _ _
isPropImplicitΠ : (h : (x : A) → isProp (B x)) → isProp ({x : A} → B x)
isPropImplicitΠ h f g i {x} = h x (f {x}) (g {x}) i
isPropImplicitΠ2 : (h : (x : A) (y : B x) → isProp (C x y)) → isProp ({x : A} {y : B x} → C x y)
isPropImplicitΠ2 h = isPropImplicitΠ (λ x → isPropImplicitΠ (λ y → h x y))
isProp→ : {A : Type ℓ} {B : Type ℓ'} → isProp B → isProp (A → B)
isProp→ pB = isPropΠ λ _ → pB
isSetΠ : ((x : A) → isSet (B x)) → isSet ((x : A) → B x)
isSetΠ = isOfHLevelΠ 2
isSetΠ2 : (h : (x : A) (y : B x) → isSet (C x y))
→ isSet ((x : A) (y : B x) → C x y)
isSetΠ2 h = isSetΠ λ x → isSetΠ λ y → h x y
isSetΠ3 : (h : (x : A) (y : B x) (z : C x y) → isSet (D x y z))
→ isSet ((x : A) (y : B x) (z : C x y) → D x y z)
isSetΠ3 h = isSetΠ λ x → isSetΠ λ y → isSetΠ λ z → h x y z
isGroupoidΠ : ((x : A) → isGroupoid (B x)) → isGroupoid ((x : A) → B x)
isGroupoidΠ = isOfHLevelΠ 3
isGroupoidΠ2 : (h : (x : A) (y : B x) → isGroupoid (C x y)) → isGroupoid ((x : A) (y : B x) → C x y)
isGroupoidΠ2 h = isGroupoidΠ λ _ → isGroupoidΠ λ _ → h _ _
isGroupoidΠ3 : (h : (x : A) (y : B x) (z : C x y) → isGroupoid (D x y z))
→ isGroupoid ((x : A) (y : B x) (z : C x y) → D x y z)
isGroupoidΠ3 h = isGroupoidΠ λ _ → isGroupoidΠ2 λ _ → h _ _
isGroupoidΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isGroupoid (E x y z w))
→ isGroupoid ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w)
isGroupoidΠ4 h = isGroupoidΠ λ _ → isGroupoidΠ3 λ _ → h _ _
is2GroupoidΠ : ((x : A) → is2Groupoid (B x)) → is2Groupoid ((x : A) → B x)
is2GroupoidΠ = isOfHLevelΠ 4
isOfHLevelΠ⁻ : ∀ {A : Type ℓ} {B : Type ℓ'} n
→ isOfHLevel n (A → B) → (A → isOfHLevel n B)
isOfHLevelΠ⁻ 0 h x = fst h x , λ y → funExt⁻ (snd h (const y)) x
isOfHLevelΠ⁻ 1 h x y z = funExt⁻ (h (const y) (const z)) x
isOfHLevelΠ⁻ (suc (suc n)) h x y z =
isOfHLevelΠ⁻ (suc n) (isOfHLevelRetractFromIso (suc n) funExtIso (h _ _)) x
-- h-level of A ≃ B and A ≡ B
isOfHLevel≃
: ∀ n {A : Type ℓ} {B : Type ℓ'}
→ (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B)
isOfHLevel≃ zero {A = A} {B = B} hA hB = isContr→Equiv hA hB , contr
where
contr : (y : A ≃ B) → isContr→Equiv hA hB ≡ y
contr y = Σ≡Prop isPropIsEquiv (funExt (λ a → snd hB (fst y a)))
isOfHLevel≃ (suc n) {A = A} {B = B} hA hB =
isOfHLevelΣ (suc n) (isOfHLevelΠ _ λ _ → hB)
(λ f → isProp→isOfHLevelSuc n (isPropIsEquiv f))
isOfHLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) →
isOfHLevel n (A ≡ B)
isOfHLevel≡ n hA hB = isOfHLevelRetractFromIso n univalenceIso (isOfHLevel≃ n hA hB)
isOfHLevel⁺≃ₗ
: ∀ n {A : Type ℓ} {B : Type ℓ'}
→ isOfHLevel (suc n) A → isOfHLevel (suc n) (A ≃ B)
isOfHLevel⁺≃ₗ zero pA e = isOfHLevel≃ 1 pA (isOfHLevelRespectEquiv 1 e pA) e
isOfHLevel⁺≃ₗ (suc n) hA e = isOfHLevel≃ m hA (isOfHLevelRespectEquiv m e hA) e
where
m = suc (suc n)
isOfHLevel⁺≃ᵣ
: ∀ n {A : Type ℓ} {B : Type ℓ'}
→ isOfHLevel (suc n) B → isOfHLevel (suc n) (A ≃ B)
isOfHLevel⁺≃ᵣ zero pB e
= isOfHLevel≃ 1 (isPropRetract (e .fst) (invEq e) (retEq e) pB) pB e
isOfHLevel⁺≃ᵣ (suc n) hB e
= isOfHLevel≃ m (isOfHLevelRetract m (e .fst) (invEq e) (retEq e) hB) hB e
where
m = suc (suc n)
isOfHLevel⁺≡ₗ
: ∀ n → {A B : Type ℓ}
→ isOfHLevel (suc n) A → isOfHLevel (suc n) (A ≡ B)
isOfHLevel⁺≡ₗ zero pA P = isOfHLevel≡ 1 pA (subst isProp P pA) P
isOfHLevel⁺≡ₗ (suc n) hA P
= isOfHLevel≡ m hA (subst (isOfHLevel m) P hA) P
where
m = suc (suc n)
isOfHLevel⁺≡ᵣ
: ∀ n → {A B : Type ℓ}
→ isOfHLevel (suc n) B → isOfHLevel (suc n) (A ≡ B)
isOfHLevel⁺≡ᵣ zero pB P = isOfHLevel≡ 1 (subst⁻ isProp P pB) pB P
isOfHLevel⁺≡ᵣ (suc n) hB P
= isOfHLevel≡ m (subst⁻ (isOfHLevel m) P hB) hB P
where
m = suc (suc n)
-- h-level of TypeOfHLevel
isPropHContr : isProp (TypeOfHLevel ℓ 0)
isPropHContr x y = Σ≡Prop (λ _ → isPropIsContr) (isOfHLevel≡ 0 (x .snd) (y .snd) .fst)
isOfHLevelTypeOfHLevel : ∀ n → isOfHLevel (suc n) (TypeOfHLevel ℓ n)
isOfHLevelTypeOfHLevel zero = isPropHContr
isOfHLevelTypeOfHLevel (suc n) (X , a) (Y , b) =
isOfHLevelRetract (suc n) (cong fst) (Σ≡Prop λ _ → isPropIsOfHLevel (suc n))
(section-Σ≡Prop λ _ → isPropIsOfHLevel (suc n))
(isOfHLevel≡ (suc n) a b)
isSetHProp : isSet (hProp ℓ)
isSetHProp = isOfHLevelTypeOfHLevel 1
-- h-level of lifted type
isOfHLevelLift : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A)
isOfHLevelLift n = isOfHLevelRetract n lower lift λ _ → refl
----------------------------
-- More consequences of isProp and isContr
inhProp→isContr : A → isProp A → isContr A
inhProp→isContr x h = x , h x
extend : isContr A → (∀ φ → (u : Partial φ A) → Sub A φ u)
extend (x , p) φ u = inS (hcomp (λ { j (φ = i1) → p (u 1=1) j }) x)
isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ}
→ (extend : ∀ φ → Partial φ A → A)
→ (∀ u → u ≡ (extend i1 λ { _ → u}))
→ isContr A
isContrPartial→isContr {A = A} extend law
= ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y)
where ex = extend i0 empty
module Aux (y : A) (i : I) where
φ = ~ i ∨ i
u : Partial φ A
u = λ { (i = i0) → ex ; (i = i1) → y }
v = extend φ u
-- Dependent h-level over a type
isOfHLevelDep : HLevel → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
isOfHLevelDep 0 {A = A} B = {a : A} → Σ[ b ∈ B a ] ({a' : A} (b' : B a') (p : a ≡ a') → PathP (λ i → B (p i)) b b')
isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1
isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1)
isOfHLevel→isOfHLevelDep : (n : HLevel)
→ {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B
isOfHLevel→isOfHLevelDep 0 h {a} =
(h a .fst , λ b' p → isProp→PathP (λ i → isContr→isProp (h (p i))) (h a .fst) b')
isOfHLevel→isOfHLevelDep 1 h = λ b0 b1 p → isProp→PathP (λ i → h (p i)) b0 b1
isOfHLevel→isOfHLevelDep (suc (suc n)) {A = A} {B} h {a0} {a1} b0 b1 =
isOfHLevel→isOfHLevelDep (suc n) (λ p → helper a1 p b1)
where
helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) →
isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)
helper a1 p b1 = J (λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1))
(λ _ → h _ _ _) p b1
isContrDep→isPropDep : isOfHLevelDep 0 B → isOfHLevelDep 1 B
isContrDep→isPropDep {B = B} Bctr {a0 = a0} b0 b1 p i
= comp (λ k → B (p (i ∧ k))) (λ k → λ where
(i = i0) → Bctr .snd b0 refl k
(i = i1) → Bctr .snd b1 p k)
(c0 .fst)
where
c0 = Bctr {a0}
isPropDep→isSetDep : isOfHLevelDep 1 B → isOfHLevelDep 2 B
isPropDep→isSetDep {B = B} Bprp b0 b1 b2 b3 p i j
= comp (λ k → B (p (i ∧ k) (j ∧ k))) (λ k → λ where
(j = i0) → Bprp b0 b0 refl k
(i = i0) → Bprp b0 (b2 j) (λ k → p i0 (j ∧ k)) k
(i = i1) → Bprp b0 (b3 j) (λ k → p k (j ∧ k)) k
(j = i1) → Bprp b0 b1 (λ k → p (i ∧ k) (j ∧ k)) k)
b0
isOfHLevelDepSuc : (n : HLevel) → isOfHLevelDep n B → isOfHLevelDep (suc n) B
isOfHLevelDepSuc 0 = isContrDep→isPropDep
isOfHLevelDepSuc 1 = isPropDep→isSetDep
isOfHLevelDepSuc (suc (suc n)) Blvl b0 b1 = isOfHLevelDepSuc (suc n) (Blvl b0 b1)
isPropDep→isSetDep'
: isOfHLevelDep 1 B
→ {p : w ≡ x} {q : y ≡ z} {r : w ≡ y} {s : x ≡ z}
→ {tw : B w} {tx : B x} {ty : B y} {tz : B z}
→ (sq : Square p q r s)
→ (tp : PathP (λ i → B (p i)) tw tx)
→ (tq : PathP (λ i → B (q i)) ty tz)
→ (tr : PathP (λ i → B (r i)) tw ty)
→ (ts : PathP (λ i → B (s i)) tx tz)
→ SquareP (λ i j → B (sq i j)) tp tq tr ts
isPropDep→isSetDep' {B = B} Bprp {p} {q} {r} {s} {tw} sq tp tq tr ts i j
= comp (λ k → B (sq (i ∧ k) (j ∧ k))) (λ k → λ where
(i = i0) → Bprp tw (tp j) (λ k → p (k ∧ j)) k
(i = i1) → Bprp tw (tq j) (λ k → sq (i ∧ k) (j ∧ k)) k
(j = i0) → Bprp tw (tr i) (λ k → r (k ∧ i)) k
(j = i1) → Bprp tw (ts i) (λ k → sq (k ∧ i) (j ∧ k)) k)
tw
isOfHLevelΣ' : ∀ n → isOfHLevel n A → isOfHLevelDep n B → isOfHLevel n (Σ A B)
isOfHLevelΣ' 0 Actr Bctr .fst = (Actr .fst , Bctr .fst)
isOfHLevelΣ' 0 Actr Bctr .snd (x , y) i
= Actr .snd x i , Bctr .snd y (Actr .snd x) i
isOfHLevelΣ' 1 Alvl Blvl (w , y) (x , z) i .fst = Alvl w x i
isOfHLevelΣ' 1 Alvl Blvl (w , y) (x , z) i .snd = Blvl y z (Alvl w x) i
isOfHLevelΣ' {A = A} {B = B} (suc (suc n)) Alvl Blvl (w , y) (x , z)
= isOfHLevelRetract (suc n)
(λ p → (λ i → p i .fst) , λ i → p i .snd)
ΣPathP
(λ x → refl)
(isOfHLevelΣ' (suc n) (Alvl w x) (Blvl y z))
| 39.348438
| 150
| 0.532582
|
ad427e47db742b99c9084f315ed3e6dc7cdad518
| 14,950
|
agda
|
Agda
|
PointedTypes.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
PointedTypes.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
PointedTypes.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module PointedTypes where
open import Agda.Prim
open import Data.Unit
open import Data.Bool
open import Data.Nat hiding (_⊔_)
open import Data.Sum
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------------
-- Pointed types
-- We need pointed types because paths are ultimately between points. A path
-- between false and 0 for example would be expressed as a path between
-- (pt false) and (pt 0) which expand to •[ Bool , false ] and •[ ℕ , 0 ]
-- First we define a pointed set as a carrier with a distinguished point
record Set• (ℓ : Level) : Set (lsuc ℓ) where
constructor •[_,_]
field
∣_∣ : Set ℓ
• : ∣_∣
open Set• public
⊤• : Set• lzero
⊤• = •[ ⊤ , tt ]
_⊎•₁_ : {ℓ ℓ' : Level} → (A• : Set• ℓ) → (B• : Set• ℓ') → Set• (ℓ ⊔ ℓ')
A• ⊎•₁ B• = •[ ∣ A• ∣ ⊎ ∣ B• ∣ , inj₁ (• A•) ]
_⊎•₂_ : {ℓ ℓ' : Level} → (A• : Set• ℓ) → (B• : Set• ℓ') → Set• (ℓ ⊔ ℓ')
A• ⊎•₂ B• = •[ ∣ A• ∣ ⊎ ∣ B• ∣ , inj₂ (• B•) ]
_ו_ : {ℓ ℓ' : Level} → (A• : Set• ℓ) → (B• : Set• ℓ') → Set• (ℓ ⊔ ℓ')
A• ו B• = •[ ∣ A• ∣ × ∣ B• ∣ , (• A• , • B•) ]
test0 : Set• lzero
test0 = •[ ℕ , 3 ]
test1 : Set• (lsuc lzero)
test1 = •[ Set , ℕ ]
test2 : {ℓ ℓ' : Level} {A : Set ℓ} {B : Set ℓ'} {a : A} → Set• (ℓ ⊔ ℓ')
test2 {ℓ} {ℓ'} {A} {B} {a} = •[ A ⊎ B , inj₁ a ]
test3 : ∀ {ℓ} → Set• (lsuc (lsuc ℓ))
test3 {ℓ} = •[ Set (lsuc ℓ) , Set ℓ ]
test4 : Set• lzero
test4 = •[ (Bool → Bool) , not ]
-- Now we focus on the points and move the carriers to the background
pt : {ℓ : Level} {A : Set ℓ} → (a : A) → Set• ℓ
pt {ℓ} {A} a = •[ A , a ]
test5 : Set• lzero
test5 = pt 3
test6 : Set• (lsuc lzero)
test6 = pt ℕ
test7 : {ℓ : Level} → Set• (lsuc (lsuc ℓ))
test7 {ℓ} = pt (Set ℓ)
-- See:
-- http://homotopytypetheory.org/2012/11/21/on-heterogeneous-equality/
beta : {ℓ : Level} {A : Set ℓ} {a : A} → • •[ A , a ] ≡ a
beta {ℓ} {A} {a} = refl
eta : {ℓ : Level} → (A• : Set• ℓ) → •[ ∣ A• ∣ , • A• ] ≡ A•
eta {ℓ} A• = refl
------------------------------------------------------------------------------
-- Functions between pointed types; our focus is on how the functions affect
-- the basepoint. We don't care what the functions do on the rest of the type.
record _→•_ {ℓ ℓ' : Level} (A• : Set• ℓ) (B• : Set• ℓ') : Set (ℓ ⊔ ℓ') where
field
fun : ∣ A• ∣ → ∣ B• ∣
resp• : fun (• A•) ≡ • B•
open _→•_ public
id• : {ℓ : Level} {A• : Set• ℓ} → (A• →• A•)
id• = record { fun = id ; resp• = refl }
f1 : pt 2 →• pt 4
f1 = record { fun = suc ∘ suc ; resp• = refl }
f2 : pt 2 →• pt 4
f2 = record { fun = λ x → 2 * x ; resp• = refl }
-- composition of functions between pointed types
_⊚_ : {ℓ₁ ℓ₂ ℓ₃ : Level} {A• : Set• ℓ₁} {B• : Set• ℓ₂} {C• : Set• ℓ₃} →
(B• →• C•) → (A• →• B•) → (A• →• C•)
h ⊚ g = record {
fun = fun h ∘ fun g ;
resp• = trans (cong (fun h) (resp• g)) (resp• h)
}
f3 : pt 4 →• pt 2
f3 = record { fun = pred ∘ pred ; resp• = refl }
f1∘f3 : pt 4 →• pt 4
f1∘f3 = f1 ⊚ f3
-- two pointed functions are ∼ if they agree on the basepoints; we DON'T CARE
-- what they do on the rest of the type.
_∼•_ : {ℓ ℓ' : Level} {A• : Set• ℓ} {B• : Set• ℓ'} →
(f• g• : A• →• B•) → Set ℓ'
_∼•_ {ℓ} {ℓ'} {A•} {B•} f• g• = fun f• (• A•) ≡ fun g• (• A•)
f1∼f2 : f1 ∼• f2
f1∼f2 = refl
f1∘f3∼id : f1∘f3 ∼• id•
f1∘f3∼id = refl
-- quasi-inverses
record qinv• {ℓ ℓ'} {A• : Set• ℓ} {B• : Set• ℓ'} (f• : A• →• B•) :
Set (ℓ ⊔ ℓ') where
constructor mkqinv•
field
g• : B• →• A•
α• : (f• ⊚ g•) ∼• id•
β• : (g• ⊚ f•) ∼• id•
idqinv• : ∀ {ℓ} → {A• : Set• ℓ} → qinv• {ℓ} {ℓ} {A•} {A•} id•
idqinv• = record { g• = id• ; α• = refl ; β• = refl }
f1qinv : qinv• f1
f1qinv = record { g• = f3 ; α• = refl ; β• = refl }
-- equivalences
record isequiv• {ℓ ℓ'} {A• : Set• ℓ} {B• : Set• ℓ'} (f• : A• →• B•) :
Set (ℓ ⊔ ℓ') where
constructor mkisequiv•
field
g• : B• →• A•
α• : (f• ⊚ g•) ∼• id•
h• : B• →• A•
β• : (h• ⊚ f•) ∼• id•
equiv•₁ : ∀ {ℓ ℓ'} {A• : Set• ℓ} {B• : Set• ℓ'} {f• : A• →• B•} →
qinv• f• → isequiv• f•
equiv•₁ (mkqinv• qg qα qβ) = mkisequiv• qg qα qg qβ
f1equiv : isequiv• f1
f1equiv = equiv•₁ f1qinv
_≃•_ : ∀ {ℓ ℓ'} (A• : Set• ℓ) (B• : Set• ℓ') → Set (ℓ ⊔ ℓ')
A ≃• B = Σ (A →• B) isequiv•
idequiv• : ∀ {ℓ} {A• : Set• ℓ} → A• ≃• A•
idequiv• = ( id• , equiv•₁ idqinv•)
pt24equiv : pt 2 ≃• pt 4
pt24equiv = (f1 , f1equiv)
------------------------------------------------------------------------------
{-- old stuff which we might need again
idright : {A B : Set} {a : A} {b : B} {p : •[ A , a ] ⇛ •[ B , b ]} →
(trans⇛ p (id⇛ {B} {b})) 2⇛ p
idright = 2Path id⇛ id⇛
idleft : {A B : Set} {a : A} {b : B} {p : •[ A , a ] ⇛ •[ B , b ]} →
(trans⇛ (id⇛ {A} {a}) p) 2⇛ p
idleft = 2Path id⇛ id⇛
assoc : {A B C D : Set} {a : A} {b : B} {c : C} {d : D}
{p : •[ A , a ] ⇛ •[ B , b ]}
{q : •[ B , b ] ⇛ •[ C , c ]}
{r : •[ C , c ] ⇛ •[ D , d ]} →
(trans⇛ p (trans⇛ q r)) 2⇛ (trans⇛ (trans⇛ p q) r)
assoc = 2Path id⇛ id⇛
bifunctorid⋆ : {A B : Set} {a : A} {b : B} →
(times⇛ (id⇛ {A} {a}) (id⇛ {B} {b})) 2⇛ (id⇛ {A × B} {(a , b)})
bifunctorid⋆ = 2Path id⇛ id⇛
bifunctorid₊₁ : {A B : Set} {a : A} →
(plus₁⇛ {A} {B} {A} {B} (id⇛ {A} {a})) 2⇛ (id⇛ {A ⊎ B} {inj₁ a})
bifunctorid₊₁ = 2Path id⇛ id⇛
bifunctorid₊₂ : {A B : Set} {b : B} →
(plus₂⇛ {A} {B} {A} {B} (id⇛ {B} {b})) 2⇛ (id⇛ {A ⊎ B} {inj₂ b})
bifunctorid₊₂ = 2Path id⇛ id⇛
bifunctorC⋆ : {A B C D E F : Set}
{a : A} {b : B} {c : C} {d : D} {e : E} {f : F}
{p : •[ A , a ] ⇛ •[ B , b ]}
{q : •[ B , b ] ⇛ •[ C , c ]}
{r : •[ D , d ] ⇛ •[ E , e ]}
{s : •[ E , e ] ⇛ •[ F , f ]} →
(trans⇛ (times⇛ p r) (times⇛ q s)) 2⇛ (times⇛ (trans⇛ p q) (trans⇛ r s))
bifunctorC⋆ = 2Path id⇛ id⇛
bifunctorC₊₁₁ : {A B C D E F : Set}
{a : A} {b : B} {c : C}
{p : •[ A , a ] ⇛ •[ B , b ]}
{q : •[ B , b ] ⇛ •[ C , c ]} →
(trans⇛ (plus₁⇛ {A} {D} {B} {E} p) (plus₁⇛ {B} {E} {C} {F} q)) 2⇛
(plus₁⇛ {A} {D} {C} {F} (trans⇛ p q))
bifunctorC₊₁₁ = 2Path id⇛ id⇛
bifunctorC₊₂₂ : {A B C D E F : Set}
{d : D} {e : E} {f : F}
{r : •[ D , d ] ⇛ •[ E , e ]}
{s : •[ E , e ] ⇛ •[ F , f ]} →
(trans⇛ (plus₂⇛ {A} {D} {B} {E} r) (plus₂⇛ {B} {E} {C} {F} s)) 2⇛
(plus₂⇛ {A} {D} {C} {F} (trans⇛ r s))
bifunctorC₊₂₂ = 2Path id⇛ id⇛
triangle : {A B : Set} {a : A} {b : B} →
(trans⇛ (assocr⋆⇛ {A} {⊤} {B} {a} {tt} {b}) (times⇛ id⇛ unite⋆⇛)) 2⇛
(times⇛ (trans⇛ swap⋆⇛ unite⋆⇛) id⇛)
triangle = 2Path id⇛ id⇛
-- Now interpret a path (x ⇛ y) as a value of type (1/x , y)
Recip : {A : Set} → (x : • A) → Set₁
Recip {A} x = (x ⇛ x)
η : {A : Set} {x : • A} → ⊤ → Recip x × • A
η {A} {x} tt = (id⇛ x , x)
lower : {A : Set} {x : • A} → x ⇛ x -> ⊤
lower c = tt
-- The problem here is that we can't assert that y == x.
ε : {A : Set} {x : • A} → Recip x × • A → ⊤
ε {A} {x} (rx , y) = lower (id⇛ ( ↑ (fun (ap rx) (focus y)) )) -- makes insufficient sense
apr : {A B : Set} {x : • A} {y : • B} → (x ⇛ y) → Recip y → Recip x
apr {A} {B} {x} {y} q ry = trans⇛ q (trans⇛ ry (sym⇛ q))
x
≡⟨ q ⟩
y
≡⟨ ry ⟩
y
≡⟨ sym⇛ q ⟩
x ∎
ε : {A B : Set} {x : A} {y : B} → Recip x → Singleton y → x ⇛ y
ε rx (singleton y) = rx y
pathV : {A B : Set} {x : A} {y : B} → (x ⇛ y) → Recip x × Singleton y
pathV unite₊⇛ = {!!}
pathV uniti₊⇛ = {!!}
-- swap₁₊⇛ : {A B : Set} {x : A} → _⇛_ {A ⊎ B} {B ⊎ A} (inj₁ x) (inj₂ x)
pathV (swap₁₊⇛ {A} {B} {x}) = ((λ x' → {!!}) , singleton (inj₂ x))
pathV swap₂₊⇛ = {!!}
pathV assocl₁₊⇛ = {!!}
pathV assocl₂₁₊⇛ = {!!}
pathV assocl₂₂₊⇛ = {!!}
pathV assocr₁₁₊⇛ = {!!}
pathV assocr₁₂₊⇛ = {!!}
pathV assocr₂₊⇛ = {!!}
pathV unite⋆⇛ = {!!}
pathV uniti⋆⇛ = {!!}
pathV swap⋆⇛ = {!!}
pathV assocl⋆⇛ = {!!}
pathV assocr⋆⇛ = {!!}
pathV dist₁⇛ = {!!}
pathV dist₂⇛ = {!!}
pathV factor₁⇛ = {!!}
pathV factor₂⇛ = {!!}
pathV dist0⇛ = {!!}
pathV factor0⇛ = {!!}
pathV {A} {.A} {x} (id⇛ .x) = {!!}
pathV (sym⇛ p) = {!!}
pathV (trans⇛ p p₁) = {!!}
pathV (plus₁⇛ p) = {!!}
pathV (plus₂⇛ p) = {!!}
pathV (times⇛ p p₁) = {!!}
-- these are individual paths so to speak
-- should we represent a path like swap+ as a family explicitly:
-- swap+ : (x : A) -> x ⇛ swapF x
-- I guess we can: swap+ : (x : A) -> case x of inj1 -> swap1 x else swap2 x
If A={x0,x1,x2}, 1/A has three values:
(x0<-x0, x0<-x1, x0<-x2)
(x1<-x0, x1<-x1, x1<-x2)
(x2<-x0, x2<-x1, x2<-x2)
It is a fake choice between x0, x1, and x2 (some negative information). You base
yourself at x0 for example and enforce that any other value can be mapped to x0.
So think of a value of type 1/A as an uncertainty about which value of A we
have. It could be x0, x1, or x2 but at the end it makes no difference. There is
no choice.
You can manipulate a value of type 1/A (x0<-x0, x0<-x1, x0<-x2) by with a
path to some arbitrary path to b0 for example:
(b0<-x0<-x0, b0<-x0<-x1, b0<-x0<-x2)
eta_3 will give (x0<-x0, x0<-x1, x0<-x2, x0) for example but any other
combination is equivalent.
epsilon_3 will take (x0<-x0, x0<-x1, x0<-x2) and one actual xi which is now
certain; we can resolve our previous uncertainty by following the path from
xi to x0 thus eliminating the fake choice we seemed to have.
Explain connection to negative information.
Knowing head or tails is 1 bits. Giving you a choice between heads and tails
and then cooking this so that heads=tails takes away your choice.
-- transp⇛ : {A B : Set} {x y : • A} →
-- (f : A → B) → x ⇛ y → ↑ (f (focus x)) ⇛ ↑ (f (focus y))
-- Morphism of pointed space: contains a path!
record _⟶_ {A B : Set} (pA : • A) (pB : • B) : Set₁ where
field
fun : A → B
eq : ↑ (fun (focus pA)) ⇛ pB
open _⟶_
_○_ : {A B C : Set} {pA : • A} {pB : • B} {pC : • C} → pA ⟶ pB → pB ⟶ pC → pA ⟶ pC
f ○ g = record { fun = λ x → (fun g) ((fun f) x) ; eq = trans⇛ (transp⇛ (fun g) (eq f)) (eq g)}
mutual
ap : {A B : Set} {x : • A} {y : • B} → x ⇛ y → x ⟶ y
ap {y = y} unite₊⇛ = record { fun = λ { (inj₁ ())
; (inj₂ x) → x } ; eq = id⇛ y }
ap uniti₊⇛ (singleton x) = singleton (inj₂ x)
ap (swap₁₊⇛ {A} {B} {x}) (singleton .(inj₁ x)) = singleton (inj₂ x)
ap (swap₂₊⇛ {A} {B} {y}) (singleton .(inj₂ y)) = singleton (inj₁ y)
ap (assocl₁₊⇛ {A} {B} {C} {x}) (singleton .(inj₁ x)) =
singleton (inj₁ (inj₁ x))
ap (assocl₂₁₊⇛ {A} {B} {C} {y}) (singleton .(inj₂ (inj₁ y))) =
singleton (inj₁ (inj₂ y))
ap (assocl₂₂₊⇛ {A} {B} {C} {z}) (singleton .(inj₂ (inj₂ z))) =
singleton (inj₂ z)
ap (assocr₁₁₊⇛ {A} {B} {C} {x}) (singleton .(inj₁ (inj₁ x))) =
singleton (inj₁ x)
ap (assocr₁₂₊⇛ {A} {B} {C} {y}) (singleton .(inj₁ (inj₂ y))) =
singleton (inj₂ (inj₁ y))
ap (assocr₂₊⇛ {A} {B} {C} {z}) (singleton .(inj₂ z)) =
singleton (inj₂ (inj₂ z))
ap {.(⊤ × A)} {A} {.(tt , x)} {x} unite⋆⇛ (singleton .(tt , x)) =
singleton x
ap uniti⋆⇛ (singleton x) = singleton (tt , x)
ap (swap⋆⇛ {A} {B} {x} {y}) (singleton .(x , y)) = singleton (y , x)
ap (assocl⋆⇛ {A} {B} {C} {x} {y} {z}) (singleton .(x , (y , z))) =
singleton ((x , y) , z)
ap (assocr⋆⇛ {A} {B} {C} {x} {y} {z}) (singleton .((x , y) , z)) =
singleton (x , (y , z))
ap (dist₁⇛ {A} {B} {C} {x} {z}) (singleton .(inj₁ x , z)) =
singleton (inj₁ (x , z))
ap (dist₂⇛ {A} {B} {C} {y} {z}) (singleton .(inj₂ y , z)) =
singleton (inj₂ (y , z))
ap (factor₁⇛ {A} {B} {C} {x} {z}) (singleton .(inj₁ (x , z))) =
singleton (inj₁ x , z)
ap (factor₂⇛ {A} {B} {C} {y} {z}) (singleton .(inj₂ (y , z))) =
singleton (inj₂ y , z)
ap {.(⊥ × A)} {.⊥} {.(• , x)} {•} (dist0⇛ {A} {.•} {x}) (singleton .(• , x)) =
singleton •
ap factor0⇛ (singleton ())
ap {x = x} (id⇛ .x) = record { fun = λ x → x; eq = id⇛ x }
ap (sym⇛ c) = apI c
ap (trans⇛ c₁ c₂) = (ap c₁) ○ (ap c₂)
ap (transp⇛ f a) = record { fun = λ x → x; eq = transp⇛ f a }
ap (plus₁⇛ {A} {B} {C} {D} {x} {z} c) (singleton .(inj₁ x))
with ap c (singleton x)
... | singleton .z = singleton (inj₁ z)
ap (plus₂⇛ {A} {B} {C} {D} {y} {w} c) (singleton .(inj₂ y))
with ap c (singleton y)
... | singleton .w = singleton (inj₂ w)
ap (times⇛ {A} {B} {C} {D} {x} {y} {z} {w} c₁ c₂) (singleton .(x , y))
with ap c₁ (singleton x) | ap c₂ (singleton y)
... | singleton .z | singleton .w = singleton (z , w)
apI : {A B : Set} {x : • A} {y : • B} → x ⇛ y → y ⟶ x
apI {y = y} unite₊⇛ = record { fun = inj₂; eq = id⇛ (↑ (inj₂ (focus y))) }
apI {A} {.(⊥ ⊎ A)} {x} uniti₊⇛ (singleton .(inj₂ x)) = singleton x
apI (swap₁₊⇛ {A} {B} {x}) (singleton .(inj₂ x)) = singleton (inj₁ x)
apI (swap₂₊⇛ {A} {B} {y}) (singleton .(inj₁ y)) = singleton (inj₂ y)
apI (assocl₁₊⇛ {A} {B} {C} {x}) (singleton .(inj₁ (inj₁ x))) =
singleton (inj₁ x)
apI (assocl₂₁₊⇛ {A} {B} {C} {y}) (singleton .(inj₁ (inj₂ y))) =
singleton (inj₂ (inj₁ y))
apI (assocl₂₂₊⇛ {A} {B} {C} {z}) (singleton .(inj₂ z)) =
singleton (inj₂ (inj₂ z))
apI (assocr₁₁₊⇛ {A} {B} {C} {x}) (singleton .(inj₁ x)) =
singleton (inj₁ (inj₁ x))
apI (assocr₁₂₊⇛ {A} {B} {C} {y}) (singleton .(inj₂ (inj₁ y))) =
singleton (inj₁ (inj₂ y))
apI (assocr₂₊⇛ {A} {B} {C} {z}) (singleton .(inj₂ (inj₂ z))) =
singleton (inj₂ z)
apI unite⋆⇛ (singleton x) = singleton (tt , x)
apI {A} {.(⊤ × A)} {x} uniti⋆⇛ (singleton .(tt , x)) = singleton x
apI (swap⋆⇛ {A} {B} {x} {y}) (singleton .(y , x)) = singleton (x , y)
apI (assocl⋆⇛ {A} {B} {C} {x} {y} {z}) (singleton .((x , y) , z)) =
singleton (x , (y , z))
apI (assocr⋆⇛ {A} {B} {C} {x} {y} {z}) (singleton .(x , (y , z))) =
singleton ((x , y) , z)
apI (dist₁⇛ {A} {B} {C} {x} {z}) (singleton .(inj₁ (x , z))) =
singleton (inj₁ x , z)
apI (dist₂⇛ {A} {B} {C} {y} {z}) (singleton .(inj₂ (y , z))) =
singleton (inj₂ y , z)
apI (factor₁⇛ {A} {B} {C} {x} {z}) (singleton .(inj₁ x , z)) =
singleton (inj₁ (x , z))
apI (factor₂⇛ {A} {B} {C} {y} {z}) (singleton .(inj₂ y , z)) =
singleton (inj₂ (y , z))
apI dist0⇛ (singleton ())
apI {.⊥} {.(⊥ × A)} {•} (factor0⇛ {A} {.•} {x}) (singleton .(• , x)) =
singleton •
apI {x = x} (id⇛ .x) = record { fun = λ x → x; eq = id⇛ x }
apI (sym⇛ c) = ap c
apI (trans⇛ c₁ c₂) = (apI c₂) ○ (apI c₁)
apI (transp⇛ f a) = record { fun = λ x → x; eq = transp⇛ f (sym⇛ a) }
apI (plus₁⇛ {A} {B} {C} {D} {x} {z} c) (singleton .(inj₁ z))
with apI c (singleton z)
... | singleton .x = singleton (inj₁ x)
apI (plus₂⇛ {A} {B} {C} {D} {y} {w} c) (singleton .(inj₂ w))
with apI c (singleton w)
... | singleton .y = singleton (inj₂ y)
apI (times⇛ {A} {B} {C} {D} {x} {y} {z} {w} c₁ c₂) (singleton .(z , w))
with apI c₁ (singleton z) | apI c₂ (singleton w)
... | singleton .x | singleton .y = singleton (x , y)
--}
| 33.520179
| 95
| 0.474515
|
1977ce11f672caeb90809a2d215417dee9b2af6c
| 1,334
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/List/Reverse.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | 1
|
2016-10-20T15:52:05.000Z
|
2016-10-20T15:52:05.000Z
|
agda-stdlib-0.9/src/Data/List/Reverse.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/List/Reverse.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Reverse view
------------------------------------------------------------------------
module Data.List.Reverse where
open import Data.List
open import Data.Nat
import Data.Nat.Properties as Nat
open import Induction.Nat
open import Relation.Binary.PropositionalEquality
-- If you want to traverse a list from the end, then you can use the
-- reverse view of it.
infixl 5 _∶_∶ʳ_
data Reverse {A : Set} : List A → Set where
[] : Reverse []
_∶_∶ʳ_ : ∀ xs (rs : Reverse xs) (x : A) → Reverse (xs ∷ʳ x)
reverseView : ∀ {A} (xs : List A) → Reverse xs
reverseView {A} xs = <-rec Pred rev (length xs) xs refl
where
Pred : ℕ → Set
Pred n = (xs : List A) → length xs ≡ n → Reverse xs
lem : ∀ xs {x : A} → length xs <′ length (xs ∷ʳ x)
lem [] = ≤′-refl
lem (x ∷ xs) = Nat.s≤′s (lem xs)
rev : (n : ℕ) → <-Rec Pred n → Pred n
rev n rec xs eq with initLast xs
rev n rec .[] eq | [] = []
rev .(length (xs ∷ʳ x)) rec .(xs ∷ʳ x) refl | xs ∷ʳ' x
with rec (length xs) (lem xs) xs refl
rev ._ rec .([] ∷ʳ x) refl | ._ ∷ʳ' x | [] = _ ∶ [] ∶ʳ x
rev ._ rec .(ys ∷ʳ y ∷ʳ x) refl | ._ ∷ʳ' x | ys ∶ rs ∶ʳ y =
_ ∶ (_ ∶ rs ∶ʳ y) ∶ʳ x
| 31.761905
| 72
| 0.484258
|
2e3476bd6d2283b733136aafc0ec8dd3ad9c3ca8
| 295
|
agda
|
Agda
|
test/Succeed/IndexOnBuiltin.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/IndexOnBuiltin.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/IndexOnBuiltin.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.conv:40 #-}
module IndexOnBuiltin where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
data Fin : Nat -> Set where
fz : {n : Nat} -> Fin (suc n)
fs : {n : Nat} -> Fin n -> Fin (suc n)
f : Fin 2 -> Fin 1
f fz = fz
f (fs i) = i
| 16.388889
| 40
| 0.528814
|
1363685b97bfa7ead3003e729980e3dbd8c38919
| 22,950
|
agda
|
Agda
|
src/fot/FOTC/Program/SortList/Properties/Totality/OrdTreeI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/SortList/Properties/Totality/OrdTreeI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/SortList/Properties/Totality/OrdTreeI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Totality properties respect to OrdTree
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.Properties.Totality.OrdTreeI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Data.Bool
open import FOTC.Data.Bool.PropertiesI
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesI
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Program.SortList.SortList
open import FOTC.Program.SortList.Properties.Totality.BoolI
open import FOTC.Program.SortList.Properties.Totality.TreeI
------------------------------------------------------------------------------
-- Subtrees
-- If (node t₁ i t₂) is ordered then t₁ is ordered.
leftSubTree-OrdTree : ∀ {t₁ i t₂} → Tree t₁ → N i → Tree t₂ →
OrdTree (node t₁ i t₂) → OrdTree t₁
leftSubTree-OrdTree {t₁} {i} {t₂} Tt₁ Ni Tt₂ TOnode =
ordTree t₁
≡⟨ &&-list₂-t₁ (ordTree-Bool Tt₁)
(&&-Bool (ordTree-Bool Tt₂)
(&&-Bool (le-TreeItem-Bool Tt₁ Ni)
(le-ItemTree-Bool Ni Tt₂)))
(trans (sym (ordTree-node t₁ i t₂)) TOnode)
⟩
true ∎
-- If (node t₁ i t₂) is ordered then t₂ is ordered.
rightSubTree-OrdTree : ∀ {t₁ i t₂} → Tree t₁ → N i → Tree t₂ →
OrdTree (node t₁ i t₂) → OrdTree t₂
rightSubTree-OrdTree {t₁} {i} {t₂} Tt₁ Ni Tt₂ TOnode =
ordTree t₂
≡⟨ &&-list₂-t₁
(ordTree-Bool Tt₂)
(&&-Bool (le-TreeItem-Bool Tt₁ Ni)
(le-ItemTree-Bool Ni Tt₂))
(&&-list₂-t₂ (ordTree-Bool Tt₁)
(&&-Bool (ordTree-Bool Tt₂)
(&&-Bool (le-TreeItem-Bool Tt₁ Ni)
(le-ItemTree-Bool Ni Tt₂)))
(trans (sym (ordTree-node t₁ i t₂)) TOnode))
⟩
true ∎
------------------------------------------------------------------------------
-- Helper functions
toTree-OrdTree-helper₁ : ∀ {i₁ i₂ t} → N i₁ → N i₂ → i₁ > i₂ →
Tree t →
≤-TreeItem t i₁ →
≤-TreeItem (toTree · i₂ · t) i₁
toTree-OrdTree-helper₁ {i₁} {i₂} .{nil} Ni₁ Ni₂ i₁>i₂ tnil _ =
le-TreeItem (toTree · i₂ · nil) i₁
≡⟨ subst (λ t → le-TreeItem (toTree · i₂ · nil) i₁ ≡ le-TreeItem t i₁)
(toTree-nil i₂)
refl
⟩
le-TreeItem (tip i₂) i₁
≡⟨ le-TreeItem-tip i₂ i₁ ⟩
le i₂ i₁
≡⟨ x<y→x≤y Ni₂ Ni₁ i₁>i₂ ⟩
true ∎
toTree-OrdTree-helper₁ {i₁} {i₂} Ni₁ Ni₂ i₁>i₂ (ttip {j} Nj) t≤i₁ =
case prf₁ prf₂ (x>y∨x≤y Nj Ni₂)
where
prf₁ : j > i₂ → ≤-TreeItem (toTree · i₂ · tip j) i₁
prf₁ j>i₂ =
le-TreeItem (toTree · i₂ · tip j) i₁
≡⟨ subst (λ t → le-TreeItem (toTree · i₂ · tip j) i₁ ≡
le-TreeItem t i₁)
(toTree-tip i₂ j)
refl
⟩
le-TreeItem (if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁
≡⟨ subst (λ t → le-TreeItem
(if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁ ≡
le-TreeItem (if t
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁)
(x>y→x≰y Nj Ni₂ j>i₂)
refl
⟩
le-TreeItem (if false
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁
≡⟨ subst (λ t → le-TreeItem (if false
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁ ≡
le-TreeItem t i₁)
(if-false (node (tip i₂) j (tip j)))
refl
⟩
le-TreeItem (node (tip i₂) j (tip j)) i₁
≡⟨ le-TreeItem-node (tip i₂) j (tip j) i₁ ⟩
le-TreeItem (tip i₂) i₁ && le-TreeItem (tip j) i₁
≡⟨ subst (λ t → le-TreeItem (tip i₂) i₁ && le-TreeItem (tip j) i₁ ≡
t && le-TreeItem (tip j) i₁)
(le-TreeItem-tip i₂ i₁)
refl
⟩
le i₂ i₁ && le-TreeItem (tip j) i₁
≡⟨ subst (λ t → le i₂ i₁ && le-TreeItem (tip j) i₁ ≡
t && le-TreeItem (tip j) i₁)
(x<y→x≤y Ni₂ Ni₁ i₁>i₂)
refl
⟩
true && le-TreeItem (tip j) i₁
≡⟨ subst (λ t → true && le-TreeItem (tip j) i₁ ≡ true && t)
(le-TreeItem-tip j i₁)
refl
⟩
true && le j i₁
≡⟨ subst (λ t → true && le j i₁ ≡ true && t)
-- j ≤ i₁ because by hypothesis we have (tip j) ≤ i₁.
(trans (sym (le-TreeItem-tip j i₁)) t≤i₁)
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
prf₂ : j ≤ i₂ → ≤-TreeItem (toTree · i₂ · tip j) i₁
prf₂ j≤i₂ =
le-TreeItem (toTree · i₂ · tip j) i₁
≡⟨ subst (λ t → le-TreeItem (toTree · i₂ · tip j) i₁ ≡
le-TreeItem t i₁)
(toTree-tip i₂ j)
refl
⟩
le-TreeItem (if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁
≡⟨ subst (λ t → le-TreeItem
(if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁ ≡
le-TreeItem (if t
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁)
j≤i₂
refl
⟩
le-TreeItem (if true
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁
≡⟨ subst (λ t → le-TreeItem (if true
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) i₁ ≡
le-TreeItem t i₁)
(if-true (node (tip j) i₂ (tip i₂)))
refl
⟩
le-TreeItem (node (tip j) i₂ (tip i₂)) i₁
≡⟨ le-TreeItem-node (tip j) i₂ (tip i₂) i₁ ⟩
le-TreeItem (tip j) i₁ && le-TreeItem (tip i₂) i₁
≡⟨ subst (λ t → le-TreeItem (tip j) i₁ && le-TreeItem (tip i₂) i₁ ≡
t && le-TreeItem (tip i₂) i₁)
(le-TreeItem-tip j i₁)
refl
⟩
le j i₁ && le-TreeItem (tip i₂) i₁
≡⟨ subst (λ t → le j i₁ && le-TreeItem (tip i₂) i₁ ≡
t && le-TreeItem (tip i₂) i₁)
-- j ≤ i₁ because by hypothesis we have (tip j) ≤ i₁.
(trans (sym (le-TreeItem-tip j i₁)) t≤i₁)
refl
⟩
true && le-TreeItem (tip i₂) i₁
≡⟨ subst (λ t → true && le-TreeItem (tip i₂) i₁ ≡ true && t)
(le-TreeItem-tip i₂ i₁)
refl
⟩
true && le i₂ i₁
≡⟨ subst (λ t → true && le i₂ i₁ ≡ true && t)
(x<y→x≤y Ni₂ Ni₁ i₁>i₂)
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
toTree-OrdTree-helper₁ {i₁} {i₂} Ni₁ Ni₂ i₁>i₂
(tnode {t₁} {j} {t₂} Tt₁ Nj Tt₂) t≤i₁ =
case prf₁ prf₂ (x>y∨x≤y Nj Ni₂)
where
prf₁ : j > i₂ → ≤-TreeItem (toTree · i₂ · node t₁ j t₂) i₁
prf₁ j>i₂ =
le-TreeItem (toTree · i₂ · node t₁ j t₂) i₁
≡⟨ subst (λ t → le-TreeItem (toTree · i₂ · node t₁ j t₂) i₁ ≡
le-TreeItem t i₁)
(toTree-node i₂ t₁ j t₂)
refl
⟩
le-TreeItem (if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁
≡⟨ subst (λ t → le-TreeItem
(if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁ ≡
le-TreeItem
(if t
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁)
(x>y→x≰y Nj Ni₂ j>i₂)
refl
⟩
le-TreeItem (if false
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁
≡⟨ subst (λ t → le-TreeItem (if false
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁ ≡
le-TreeItem t i₁)
(if-false (node (toTree · i₂ · t₁) j t₂))
refl
⟩
le-TreeItem (node (toTree · i₂ · t₁) j t₂) i₁
≡⟨ le-TreeItem-node (toTree · i₂ · t₁) j t₂ i₁ ⟩
le-TreeItem (toTree · i₂ · t₁) i₁ && le-TreeItem t₂ i₁
≡⟨ subst (λ t → le-TreeItem (toTree · i₂ · t₁) i₁ &&
le-TreeItem t₂ i₁ ≡
t &&
le-TreeItem t₂ i₁)
-- Inductive hypothesis.
(toTree-OrdTree-helper₁ Ni₁ Ni₂ i₁>i₂ Tt₁
(&&-list₂-t₁ (le-TreeItem-Bool Tt₁ Ni₁)
(le-TreeItem-Bool Tt₂ Ni₁)
(trans (sym (le-TreeItem-node t₁ j t₂ i₁)) t≤i₁)))
refl
⟩
true && le-TreeItem t₂ i₁
≡⟨ subst (λ t → true && le-TreeItem t₂ i₁ ≡ true && t)
-- t₂ ≤ i₁ because by hypothesis we have (node t₁ j t₂) ≤ i₁.
(&&-list₂-t₂ (le-TreeItem-Bool Tt₁ Ni₁)
(le-TreeItem-Bool Tt₂ Ni₁)
(trans (sym (le-TreeItem-node t₁ j t₂ i₁)) t≤i₁))
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
prf₂ : j ≤ i₂ → ≤-TreeItem (toTree · i₂ · node t₁ j t₂) i₁
prf₂ j≤i₂ =
le-TreeItem (toTree · i₂ · node t₁ j t₂) i₁
≡⟨ subst (λ t → le-TreeItem (toTree · i₂ · node t₁ j t₂) i₁ ≡
le-TreeItem t i₁)
(toTree-node i₂ t₁ j t₂)
refl
⟩
le-TreeItem (if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁
≡⟨ subst (λ t → le-TreeItem
(if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁ ≡
le-TreeItem
(if t
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁)
(j≤i₂)
refl
⟩
le-TreeItem (if true
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁
≡⟨ subst (λ t → le-TreeItem (if true
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) i₁ ≡
le-TreeItem t i₁)
(if-true (node t₁ j (toTree · i₂ · t₂)))
refl
⟩
le-TreeItem (node t₁ j (toTree · i₂ · t₂)) i₁
≡⟨ le-TreeItem-node t₁ j (toTree · i₂ · t₂) i₁ ⟩
le-TreeItem t₁ i₁ && le-TreeItem (toTree · i₂ · t₂) i₁
≡⟨ subst (λ t → le-TreeItem t₁ i₁ && le-TreeItem (toTree · i₂ · t₂) i₁ ≡
t && le-TreeItem (toTree · i₂ · t₂) i₁)
-- t₁ ≤ i₁ because by hypothesis we have (node t₁ j t₂) ≤ i₁.
(&&-list₂-t₁ (le-TreeItem-Bool Tt₁ Ni₁)
(le-TreeItem-Bool Tt₂ Ni₁)
(trans (sym (le-TreeItem-node t₁ j t₂ i₁)) t≤i₁))
refl
⟩
true && le-TreeItem (toTree · i₂ · t₂) i₁
≡⟨ subst (λ t → true && le-TreeItem (toTree · i₂ · t₂) i₁ ≡
true && t)
-- Inductive hypothesis.
(toTree-OrdTree-helper₁ Ni₁ Ni₂ i₁>i₂ Tt₂
(&&-list₂-t₂ (le-TreeItem-Bool Tt₁ Ni₁)
(le-TreeItem-Bool Tt₂ Ni₁)
(trans (sym (le-TreeItem-node t₁ j t₂ i₁)) t≤i₁)))
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
------------------------------------------------------------------------------
toTree-OrdTree-helper₂ : ∀ {i₁ i₂ t} → N i₁ → N i₂ → i₁ ≤ i₂ →
Tree t →
≤-ItemTree i₁ t →
≤-ItemTree i₁ (toTree · i₂ · t)
toTree-OrdTree-helper₂ {i₁} {i₂} .{nil} _ _ i₁≤i₂ tnil _ =
le-ItemTree i₁ (toTree · i₂ · nil)
≡⟨ subst (λ t → le-ItemTree i₁ (toTree · i₂ · nil) ≡ le-ItemTree i₁ t)
(toTree-nil i₂)
refl
⟩
le-ItemTree i₁ (tip i₂)
≡⟨ le-ItemTree-tip i₁ i₂ ⟩
le i₁ i₂
≡⟨ i₁≤i₂ ⟩
true ∎
toTree-OrdTree-helper₂ {i₁} {i₂} Ni₁ Ni₂ i₁≤i₂ (ttip {j} Nj) i₁≤t =
case prf₁ prf₂ (x>y∨x≤y Nj Ni₂)
where
prf₁ : j > i₂ → ≤-ItemTree i₁ (toTree · i₂ · tip j)
prf₁ j>i₂ =
le-ItemTree i₁ (toTree · i₂ · tip j)
≡⟨ subst (λ t → le-ItemTree i₁ (toTree · i₂ · tip j) ≡
le-ItemTree i₁ t)
(toTree-tip i₂ j)
refl
⟩
le-ItemTree i₁ (if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j)))
≡⟨ subst (λ t → le-ItemTree i₁ (if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) ≡
le-ItemTree i₁ (if t
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))))
(x>y→x≰y Nj Ni₂ j>i₂)
refl
⟩
le-ItemTree i₁ (if false
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j)))
≡⟨ subst (λ t → le-ItemTree i₁ (if false
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) ≡
le-ItemTree i₁ t)
(if-false (node (tip i₂) j (tip j)))
refl
⟩
le-ItemTree i₁ (node (tip i₂) j (tip j))
≡⟨ le-ItemTree-node i₁ (tip i₂) j (tip j) ⟩
le-ItemTree i₁ (tip i₂) && le-ItemTree i₁ (tip j)
≡⟨ subst (λ t → le-ItemTree i₁ (tip i₂) && le-ItemTree i₁ (tip j) ≡
t && le-ItemTree i₁ (tip j))
(le-ItemTree-tip i₁ i₂)
refl
⟩
le i₁ i₂ && le-ItemTree i₁ (tip j)
≡⟨ subst (λ t → le i₁ i₂ && le-ItemTree i₁ (tip j) ≡
t && le-ItemTree i₁ (tip j))
i₁≤i₂
refl
⟩
true && le-ItemTree i₁ (tip j)
≡⟨ subst (λ t → true && le-ItemTree i₁ (tip j) ≡ true && t)
(le-ItemTree-tip i₁ j)
refl
⟩
true && le i₁ j
≡⟨ subst (λ t → true && le i₁ j ≡ true && t)
-- i₁ ≤ j because by hypothesis we have i₁ ≤ (tip j).
(trans (sym (le-ItemTree-tip i₁ j)) i₁≤t)
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
prf₂ : j ≤ i₂ → ≤-ItemTree i₁ (toTree · i₂ · tip j)
prf₂ j≤i₂ =
le-ItemTree i₁ (toTree · i₂ · tip j)
≡⟨ subst (λ t → le-ItemTree i₁ (toTree · i₂ · tip j) ≡
le-ItemTree i₁ t)
(toTree-tip i₂ j)
refl
⟩
le-ItemTree i₁ (if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j)))
≡⟨ subst (λ t → le-ItemTree i₁ (if (le j i₂)
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) ≡
le-ItemTree i₁ (if t
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))))
j≤i₂
refl
⟩
le-ItemTree i₁ (if true
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j)))
≡⟨ subst (λ t → le-ItemTree i₁ (if true
then (node (tip j) i₂ (tip i₂))
else (node (tip i₂) j (tip j))) ≡
le-ItemTree i₁ t)
(if-true (node (tip j) i₂ (tip i₂)))
refl
⟩
le-ItemTree i₁ (node (tip j) i₂ (tip i₂))
≡⟨ le-ItemTree-node i₁ (tip j) i₂ (tip i₂) ⟩
le-ItemTree i₁ (tip j) && le-ItemTree i₁ (tip i₂)
≡⟨ subst (λ t → le-ItemTree i₁ (tip j) && le-ItemTree i₁ (tip i₂) ≡
t && le-ItemTree i₁ (tip i₂))
(le-ItemTree-tip i₁ j)
refl
⟩
le i₁ j && le-ItemTree i₁ (tip i₂)
≡⟨ subst (λ t → le i₁ j && le-ItemTree i₁ (tip i₂) ≡
t && le-ItemTree i₁ (tip i₂))
-- i₁ ≤ j because by hypothesis we have i₁ ≤ (tip j).
(trans (sym (le-ItemTree-tip i₁ j)) i₁≤t)
refl
⟩
true && le-ItemTree i₁ (tip i₂)
≡⟨ subst (λ t → true && le-ItemTree i₁ (tip i₂) ≡ true && t)
(le-ItemTree-tip i₁ i₂)
refl
⟩
true && le i₁ i₂
≡⟨ subst (λ t → true && le i₁ i₂ ≡ true && t)
i₁≤i₂
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
toTree-OrdTree-helper₂ {i₁} {i₂} Ni₁ Ni₂ i₁≤i₂
(tnode {t₁} {j} {t₂} Tt₁ Nj Tt₂) i₁≤t =
case prf₁ prf₂ (x>y∨x≤y Nj Ni₂)
where
prf₁ : j > i₂ → ≤-ItemTree i₁ (toTree · i₂ · node t₁ j t₂)
prf₁ j>i₂ =
le-ItemTree i₁ (toTree · i₂ · node t₁ j t₂)
≡⟨ subst (λ t → le-ItemTree i₁ (toTree · i₂ · node t₁ j t₂) ≡
le-ItemTree i₁ t)
(toTree-node i₂ t₁ j t₂)
refl
⟩
le-ItemTree i₁ (if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂))
≡⟨ subst (λ t → le-ItemTree i₁ (if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) ≡
le-ItemTree i₁ (if t
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)))
(x>y→x≰y Nj Ni₂ j>i₂)
refl
⟩
le-ItemTree i₁ (if false
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂))
≡⟨ subst (λ t → le-ItemTree i₁ (if false
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) ≡
le-ItemTree i₁ t)
(if-false (node (toTree · i₂ · t₁) j t₂))
refl
⟩
le-ItemTree i₁ (node (toTree · i₂ · t₁) j t₂)
≡⟨ le-ItemTree-node i₁ (toTree · i₂ · t₁) j t₂ ⟩
le-ItemTree i₁ (toTree · i₂ · t₁) && le-ItemTree i₁ t₂
≡⟨ subst (λ t → le-ItemTree i₁ (toTree · i₂ · t₁) && le-ItemTree i₁ t₂ ≡
t && le-ItemTree i₁ t₂)
-- Inductive hypothesis.
(toTree-OrdTree-helper₂ Ni₁ Ni₂ i₁≤i₂ Tt₁
(&&-list₂-t₁ (le-ItemTree-Bool Ni₁ Tt₁)
(le-ItemTree-Bool Ni₁ Tt₂)
(trans (sym (le-ItemTree-node i₁ t₁ j t₂)) i₁≤t)))
refl
⟩
true && le-ItemTree i₁ t₂
≡⟨ subst (λ t → true && le-ItemTree i₁ t₂ ≡ true && t)
-- i₁ ≤ t₂ because by hypothesis we have i₁ ≤ (node t₁ j t₂).
(&&-list₂-t₂ (le-ItemTree-Bool Ni₁ Tt₁)
(le-ItemTree-Bool Ni₁ Tt₂)
(trans (sym (le-ItemTree-node i₁ t₁ j t₂)) i₁≤t))
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
prf₂ : j ≤ i₂ → ≤-ItemTree i₁ (toTree · i₂ · node t₁ j t₂)
prf₂ j≤i₂ =
le-ItemTree i₁ (toTree · i₂ · node t₁ j t₂)
≡⟨ subst (λ t → le-ItemTree i₁ (toTree · i₂ · node t₁ j t₂) ≡
le-ItemTree i₁ t)
(toTree-node i₂ t₁ j t₂)
refl
⟩
le-ItemTree i₁ (if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂))
≡⟨ subst (λ t → le-ItemTree i₁ (if (le j i₂)
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) ≡
le-ItemTree i₁ (if t
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)))
j≤i₂
refl
⟩
le-ItemTree i₁ (if true
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂))
≡⟨ subst (λ t → le-ItemTree i₁ (if true
then (node t₁ j (toTree · i₂ · t₂))
else (node (toTree · i₂ · t₁) j t₂)) ≡
le-ItemTree i₁ t)
(if-true (node t₁ j (toTree · i₂ · t₂)))
refl
⟩
le-ItemTree i₁ (node t₁ j (toTree · i₂ · t₂))
≡⟨ le-ItemTree-node i₁ t₁ j (toTree · i₂ · t₂) ⟩
le-ItemTree i₁ t₁ && le-ItemTree i₁ (toTree · i₂ · t₂)
≡⟨ subst (λ t → le-ItemTree i₁ t₁ && le-ItemTree i₁ (toTree · i₂ · t₂) ≡
t && le-ItemTree i₁ (toTree · i₂ · t₂))
-- i₁ ≤ t₁ because by hypothesis we have i₁ ≤ (node t₁ j t₂).
(&&-list₂-t₁ (le-ItemTree-Bool Ni₁ Tt₁)
(le-ItemTree-Bool Ni₁ Tt₂)
(trans (sym (le-ItemTree-node i₁ t₁ j t₂)) i₁≤t))
refl
⟩
true && le-ItemTree i₁ (toTree · i₂ · t₂)
≡⟨ subst (λ t → true && le-ItemTree i₁ (toTree · i₂ · t₂) ≡ true && t)
-- Inductive hypothesis.
(toTree-OrdTree-helper₂ Ni₁ Ni₂ i₁≤i₂ Tt₂
(&&-list₂-t₂ (le-ItemTree-Bool Ni₁ Tt₁)
(le-ItemTree-Bool Ni₁ Tt₂)
(trans (sym (le-ItemTree-node i₁ t₁ j t₂)) i₁≤t)))
refl
⟩
true && true
≡⟨ t&&x≡x true ⟩
true ∎
| 40.333919
| 80
| 0.414074
|
30d324d78e4d6bba8addb65cbc96075953e176b8
| 385
|
agda
|
Agda
|
test/Fail/WrongPrimitiveModality.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/WrongPrimitiveModality.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/WrongPrimitiveModality.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
postulate
String : Set
{-# BUILTIN STRING String #-}
primitive
@0 ⦃ primShowNat ⦄ : Nat → String
-- Wrong modality for primitive primShowNat
-- Got: instance, erased
-- Expected: visible, unrestricted
-- when checking that the type of the primitive function primShowNat
-- is Nat → String
| 20.263158
| 68
| 0.724675
|
03db1b2f073187f5d725615ee2c629ba930b67f0
| 634
|
agda
|
Agda
|
Cubical/Algebra/Group/Instances/Int.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/Group/Instances/Int.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/Group/Instances/Int.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Instances.Int where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Int renaming (ℤ to ℤType ; _+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_)
open import Cubical.Algebra.Group.Base
open GroupStr
ℤ : Group₀
fst ℤ = ℤType
1g (snd ℤ) = 0
_·_ (snd ℤ) = _+ℤ_
inv (snd ℤ) = _-ℤ_ 0
isGroup (snd ℤ) = isGroupℤ
where
abstract
isGroupℤ : IsGroup (pos 0) _+ℤ_ (_-ℤ_ (pos 0))
isGroupℤ = makeIsGroup isSetℤ +Assoc (λ _ → refl) (+Comm 0)
(λ x → +Comm x (pos 0 -ℤ x) ∙ minusPlus x 0)
(λ x → minusPlus x 0)
| 28.818182
| 103
| 0.600946
|
8bc5ac8149ed115474b22540841f842ed00804be
| 258
|
agda
|
Agda
|
test/Succeed/RelevanceSubtyping.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2021-06-14T11:08:59.000Z
|
2021-06-14T11:08:59.000Z
|
test/Succeed/RelevanceSubtyping.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T15:49:15.000Z
|
2015-09-15T15:49:15.000Z
|
test/Succeed/RelevanceSubtyping.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2021-06-14T11:07:38.000Z
|
2021-06-14T11:07:38.000Z
|
{-# OPTIONS --subtyping #-}
-- Andreas, 2012-09-13
module RelevanceSubtyping where
-- this naturally type-checks:
one : {A B : Set} → (.A → B) → A → B
one f x = f x
-- this type-checks because of subtyping
one' : {A B : Set} → (.A → B) → A → B
one' f = f
| 19.846154
| 40
| 0.585271
|
c792c7ef085894fcc34603160b1480b30e07a0fb
| 160
|
agda
|
Agda
|
test/succeed/PatternSynonymImports2.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/succeed/PatternSynonymImports2.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/PatternSynonymImports2.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module PatternSynonymImports2 where
open import PatternSynonyms
open import PatternSynonymImports
myzero' = z
myzero'' = myzero
list2 : List _
list2 = 1 ∷ []
| 16
| 35
| 0.775
|
cb16a7eca93e62d2f0ce622188d0ed1140f3c17d
| 699
|
agda
|
Agda
|
Cubical/Data/Everything.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Everything.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Everything.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Everything where
import Cubical.Data.BinNat
import Cubical.Data.Bool
import Cubical.Data.Empty
import Cubical.Data.Equality
import Cubical.Data.Fin
import Cubical.Data.Nat
import Cubical.Data.Nat.Algebra
import Cubical.Data.Nat.Order
import Cubical.Data.NatMinusOne
import Cubical.Data.NatMinusTwo
import Cubical.Data.NatPlusOne
import Cubical.Data.Int
import Cubical.Data.Sum
import Cubical.Data.Prod
import Cubical.Data.Unit
import Cubical.Data.Sigma
import Cubical.Data.DiffInt
import Cubical.Data.Group
import Cubical.Data.HomotopyGroup
import Cubical.Data.List
import Cubical.Data.Graph
import Cubical.Data.InfNat
import Cubical.Data.Queue
| 25.888889
| 36
| 0.835479
|
1a36117405a1006a2789cf4e55b22b283f0c7643
| 1,257
|
agda
|
Agda
|
prototyping/Luau/Substitution.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | 1
|
2022-02-11T21:30:17.000Z
|
2022-02-11T21:30:17.000Z
|
prototyping/Luau/Substitution.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Substitution.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | null | null | null |
module Luau.Substitution where
open import Luau.Syntax using (Expr; Stat; Block; nil; addr; var; function⟨_⟩_end; _$_; block_is_end; local_←_; _∙_; done; function_⟨_⟩_end; return)
open import Luau.Value using (Value; val)
open import Luau.Var using (Var; _≡ⱽ_)
open import Properties.Dec using (Dec; yes; no)
_[_/_]ᴱ : Expr → Value → Var → Expr
_[_/_]ᴮ : Block → Value → Var → Block
var_[_/_]ᴱwhenever_ : ∀ {P} → Var → Value → Var → (Dec P) → Expr
_[_/_]ᴮunless_ : ∀ {P} → Block → Value → Var → (Dec P) → Block
nil [ v / x ]ᴱ = nil
var y [ v / x ]ᴱ = var y [ v / x ]ᴱwhenever (x ≡ⱽ y)
addr a [ v / x ]ᴱ = addr a
(M $ N) [ v / x ]ᴱ = (M [ v / x ]ᴱ) $ (N [ v / x ]ᴱ)
function⟨ y ⟩ C end [ v / x ]ᴱ = function⟨ y ⟩ C [ v / x ]ᴮunless (x ≡ⱽ y) end
block b is C end [ v / x ]ᴱ = block b is C [ v / x ]ᴮ end
(function f ⟨ y ⟩ C end ∙ B) [ v / x ]ᴮ = function f ⟨ y ⟩ (C [ v / x ]ᴮunless (x ≡ⱽ y)) end ∙ (B [ v / x ]ᴮunless (x ≡ⱽ f))
(local y ← M ∙ B) [ v / x ]ᴮ = local y ← (M [ v / x ]ᴱ) ∙ (B [ v / x ]ᴮunless (x ≡ⱽ y))
(return M ∙ B) [ v / x ]ᴮ = return (M [ v / x ]ᴱ) ∙ (B [ v / x ]ᴮ)
done [ v / x ]ᴮ = done
var y [ v / x ]ᴱwhenever yes p = val v
var y [ v / x ]ᴱwhenever no p = var y
B [ v / x ]ᴮunless yes p = B
B [ v / x ]ᴮunless no p = B [ v / x ]ᴮ
| 40.548387
| 148
| 0.539379
|
4ba72218cc306d19d228f9e58c768fbafee358c8
| 1,753
|
agda
|
Agda
|
L0.agda
|
daherb/Agda-Montague
|
9f8bbff7248dbeb54919e03957daf9b35ec1ac23
|
[
"Artistic-2.0"
] | 1
|
2020-12-18T11:56:24.000Z
|
2020-12-18T11:56:24.000Z
|
L0.agda
|
daherb/Agda-Montague
|
9f8bbff7248dbeb54919e03957daf9b35ec1ac23
|
[
"Artistic-2.0"
] | null | null | null |
L0.agda
|
daherb/Agda-Montague
|
9f8bbff7248dbeb54919e03957daf9b35ec1ac23
|
[
"Artistic-2.0"
] | null | null | null |
module L0 where
open import Common
-- Syntax
data Name : Set where
d n j m : Name
data Pred1 : Set where
M B : Pred1
data Pred2 : Set where
K L : Pred2
data Expr : Set where
_⦅_⦆ : Pred1 -> Name -> Expr
_⦅_,_⦆ : Pred2 -> Name -> Name -> Expr
¬ : Expr -> Expr
[_∧_] : Expr -> Expr -> Expr
[_∨_] : Expr -> Expr -> Expr
[_⇒_] : Expr -> Expr -> Expr
[_⇔_] : Expr -> Expr -> Expr
example1 : Expr
example1 = [ K ⦅ d , j ⦆ ∧ M ⦅ d ⦆ ]
example2 : Expr
example2 = ¬ [ M ⦅ d ⦆ ∨ B ⦅ m ⦆ ]
example3 : Expr
example3 = [ L ⦅ n , j ⦆ ⇒ [ B ⦅ d ⦆ ∨ ¬ (K ⦅ m , m ⦆) ] ]
example4 : Expr
example4 = [ ¬ (¬ (¬ (B ⦅ n ⦆))) ⇔ ¬ (M ⦅ n ⦆) ]
-- Semantics
data Person : Set where
Richard_Nixon : Person
Noam_Chomsky : Person
John_Mitchell : Person
Muhammad_Ali : Person
instance
eqPerson : Eq Person
-- _==_ ⦃ eqPerson ⦄ x y = isEq x y (refl {!x y!})
_==_ ⦃ eqPerson ⦄ Richard_Nixon Richard_Nixon = true
_==_ ⦃ eqPerson ⦄ Noam_Chomsky Noam_Chomsky = true
_==_ ⦃ eqPerson ⦄ John_Mitchell John_Mitchell = true
_==_ ⦃ eqPerson ⦄ Muhammad_Ali Muhammad_Ali = true
_==_ ⦃ eqPerson ⦄ _ _ = false
_∈_ : {A : Set} {{_ : Eq A}} -> A -> PSet A -> Bool
x ∈ ⦃⦄ = false
x ∈ (x₁ :: xs) = (x == x₁) || (x ∈ xs)
⟦_⟧ₙ : Name -> Person
⟦ d ⟧ₙ = Richard_Nixon
⟦ n ⟧ₙ = Noam_Chomsky
⟦ j ⟧ₙ = John_Mitchell
⟦ m ⟧ₙ = Muhammad_Ali
⟦_⟧ₚ₁ : Pred1 -> PSet Person
⟦ x ⟧ₚ₁ = {!!}
⟦_⟧ₚ₂ : Pred2 -> PSet (Pair Person)
⟦ x ⟧ₚ₂ = {!!}
⟦_⟧ₑ : Expr -> Bool
{-# TERMINATING #-}
⟦ x ⦅ x₁ ⦆ ⟧ₑ = ⟦ x₁ ⟧ₙ ∈ ⟦ x ⟧ₚ₁
⟦ x ⦅ x₁ , x₂ ⦆ ⟧ₑ = < ⟦ x₁ ⟧ₙ , ⟦ x₂ ⟧ₙ > ∈ ⟦ x ⟧ₚ₂
⟦ ¬ x ⟧ₑ = neg ⟦ x ⟧ₑ
⟦ [ x ∧ x₁ ] ⟧ₑ = ⟦ x ⟧ₑ && ⟦ x₁ ⟧ₑ
⟦ [ x ∨ x₁ ] ⟧ₑ = ⟦ x ⟧ₑ || ⟦ x₁ ⟧ₑ
⟦ [ x ⇒ x₁ ] ⟧ₑ = (neg ⟦ x₁ ⟧ₑ) || ⟦ x ⟧ₑ
⟦ [ x ⇔ x₁ ] ⟧ₑ = ⟦ [ x ⇒ x₁ ] ⟧ₑ && ⟦ [ x₁ ⇒ x ] ⟧ₑ
| 23.065789
| 58
| 0.509412
|
5216954232310dc5aa62648ceac3a4cada316838
| 399
|
agda
|
Agda
|
test/fail/SizedTypesRigidVarClash.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/fail/SizedTypesRigidVarClash.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/fail/SizedTypesRigidVarClash.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
{-# OPTIONS --sized-types #-}
module SizedTypesRigidVarClash where
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {size ^}
suc : {size : Size} -> Nat {size} -> Nat {size ^}
inc : {i j : Size} -> Nat {i} -> Nat {j ^}
inc x = suc x
| 19.95
| 52
| 0.541353
|
522453afc150c4a6d116a0244f27ceea53ab38f8
| 7,496
|
agda
|
Agda
|
canonical-boxed-forms.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
canonical-boxed-forms.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
canonical-boxed-forms.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import contexts
open import dynamics-core
open import canonical-value-forms
module canonical-boxed-forms where
canonical-boxed-forms-num : ∀{Δ d} →
Δ , ∅ ⊢ d :: num →
d boxedval →
Σ[ n ∈ Nat ] (d == N n)
canonical-boxed-forms-num (TAVar _) (BVVal ())
canonical-boxed-forms-num wt (BVVal v) = canonical-value-forms-num wt v
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for boxed values at arrow type
data cbf-arr : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CBFALam : ∀{Δ d τ1 τ2} →
Σ[ x ∈ Nat ] Σ[ d' ∈ ihexp ]
((d == (·λ x ·[ τ1 ] d')) ×
(Δ , ■ (x , τ1) ⊢ d' :: τ2)
)
→ cbf-arr Δ d τ1 τ2
CBFACastArr : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == (d' ⟨ τ1' ==> τ2' ⇒ τ1 ==> τ2 ⟩)) ×
(τ1' ==> τ2' ≠ τ1 ==> τ2) ×
(Δ , ∅ ⊢ d' :: τ1' ==> τ2') ×
(d' boxedval)
)
→ cbf-arr Δ d τ1 τ2
canonical-boxed-forms-arr : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d boxedval →
cbf-arr Δ d τ1 τ2
canonical-boxed-forms-arr (TAVar x₁) (BVVal ())
canonical-boxed-forms-arr (TALam f wt) (BVVal v) = CBFALam (canonical-value-forms-arr (TALam f wt) v)
canonical-boxed-forms-arr (TAAp wt wt₁) (BVVal ())
canonical-boxed-forms-arr (TAEHole x x₁) (BVVal ())
canonical-boxed-forms-arr (TANEHole x wt x₁) (BVVal ())
canonical-boxed-forms-arr (TACast wt x) (BVVal ())
canonical-boxed-forms-arr (TACast wt x) (BVArrCast x₁ bv) = CBFACastArr (_ , _ , _ , refl , x₁ , wt , bv)
canonical-boxed-forms-arr (TAFailedCast x x₁ x₂ x₃) (BVVal ())
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for boxed values at sum type
data cbf-sum : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CBFSInl : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == (inl τ2 d')) ×
(Δ , ∅ ⊢ d' :: τ1) ×
(d boxedval)
)
→ cbf-sum Δ d τ1 τ2
CBFSInr : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == (inr τ1 d')) ×
(Δ , ∅ ⊢ d' :: τ2) ×
(d boxedval)
)
→ cbf-sum Δ d τ1 τ2
CBFSCastSum : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == (d' ⟨ τ1' ⊕ τ2' ⇒ τ1 ⊕ τ2 ⟩)) ×
(τ1' ⊕ τ2' ≠ τ1 ⊕ τ2) ×
(Δ , ∅ ⊢ d' :: τ1' ⊕ τ2') ×
(d' boxedval)
)
→ cbf-sum Δ d τ1 τ2
canonical-boxed-forms-sum : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ⊕ τ2) →
d boxedval →
cbf-sum Δ d τ1 τ2
canonical-boxed-forms-sum (TAInl wt) x = CBFSInl (_ , refl , wt , x)
canonical-boxed-forms-sum (TAInr wt) x = CBFSInr (_ , refl , wt , x)
canonical-boxed-forms-sum (TACast wt x₁) (BVSumCast x bv) = CBFSCastSum (_ , _ , _ , refl , x , wt , bv)
canonical-boxed-forms-sum (TAVar x₁) (BVVal ())
canonical-boxed-forms-sum (TAAp wt wt₁) (BVVal ())
canonical-boxed-forms-sum (TACase wt _ wt₁ _ wt₂) (BVVal ())
canonical-boxed-forms-sum (TAFst wt) (BVVal ())
canonical-boxed-forms-sum (TASnd wt) (BVVal ())
canonical-boxed-forms-sum (TAEHole x₁ x₂) (BVVal ())
canonical-boxed-forms-sum (TANEHole x₁ wt x₂) (BVVal ())
canonical-boxed-forms-sum (TACast wt x₁) (BVVal ())
canonical-boxed-forms-sum (TAFailedCast wt x₁ x₂ x₃) (BVVal ())
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for boxed values at product type
data cbf-prod : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CBFPPair : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]
((d == ⟨ d1 , d2 ⟩) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 boxedval) ×
(d2 boxedval)
)
→ cbf-prod Δ d τ1 τ2
CBFPCastProd : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == (d' ⟨ τ1' ⊠ τ2' ⇒ τ1 ⊠ τ2 ⟩)) ×
(τ1' ⊠ τ2' ≠ τ1 ⊠ τ2) ×
(Δ , ∅ ⊢ d' :: τ1' ⊠ τ2') ×
(d' boxedval)
)
→ cbf-prod Δ d τ1 τ2
canonical-boxed-forms-prod : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ⊠ τ2) →
d boxedval →
cbf-prod Δ d τ1 τ2
canonical-boxed-forms-prod (TAPair wt wt₁) (BVVal (VPair x x₁)) = CBFPPair (_ , _ , refl , wt , wt₁ , BVVal x , BVVal x₁)
canonical-boxed-forms-prod (TAPair wt wt₁) (BVPair bv bv₁) = CBFPPair (_ , _ , refl , wt , wt₁ , bv , bv₁)
canonical-boxed-forms-prod (TACast wt x) (BVProdCast x₁ bv) = CBFPCastProd (_ , _ , _ , refl , x₁ , wt , bv)
canonical-boxed-forms-hole : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇-⦈ →
d boxedval →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == d' ⟨ τ' ⇒ ⦇-⦈ ⟩) ×
(τ' ground) ×
(Δ , ∅ ⊢ d' :: τ'))
canonical-boxed-forms-hole (TAVar x₁) (BVVal ())
canonical-boxed-forms-hole (TAAp wt wt₁) (BVVal ())
canonical-boxed-forms-hole (TAEHole x x₁) (BVVal ())
canonical-boxed-forms-hole (TANEHole x wt x₁) (BVVal ())
canonical-boxed-forms-hole (TACast wt x) (BVVal ())
canonical-boxed-forms-hole (TACast wt x) (BVHoleCast x₁ bv) = _ , _ , refl , x₁ , wt
canonical-boxed-forms-hole (TAFailedCast x x₁ x₂ x₃) (BVVal ())
canonical-boxed-forms-coverage : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d boxedval →
τ ≠ num →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊕ τ2)) →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊠ τ2)) →
τ ≠ ⦇-⦈ →
⊥
canonical-boxed-forms-coverage TANum bv nn na ns np nh = nn refl
canonical-boxed-forms-coverage (TAPlus wt wt₁) bv nn na ns np nh = nn refl
canonical-boxed-forms-coverage (TALam x wt) bv nn na ns np nh = na _ _ refl
canonical-boxed-forms-coverage (TAAp wt wt₁) (BVVal ()) nn na ns np nh
canonical-boxed-forms-coverage (TAInl wt) bv nn na ns np nh = ns _ _ refl
canonical-boxed-forms-coverage (TAInr wt) bv nn na ns np nh = ns _ _ refl
canonical-boxed-forms-coverage (TACase wt _ wt₁ _ wt₂) (BVVal ()) nn na ns np nh
canonical-boxed-forms-coverage (TAEHole x x₁) (BVVal ()) nn na ns np nh
canonical-boxed-forms-coverage (TANEHole x wt x₁) (BVVal ()) nn na ns np nh
canonical-boxed-forms-coverage (TACast wt x) (BVArrCast x₁ bv) nn na ns np nh = na _ _ refl
canonical-boxed-forms-coverage (TACast wt x) (BVSumCast x₁ bv) nn na ns np nh = ns _ _ refl
canonical-boxed-forms-coverage (TACast wt x) (BVProdCast x₁ bv) nn na ns np nh = np _ _ refl
canonical-boxed-forms-coverage (TACast wt x) (BVHoleCast x₁ bv) nn na ns np nh = nh refl
canonical-boxed-forms-coverage (TAFailedCast wt x x₁ x₂) (BVVal ()) nn na ns np nh
canonical-boxed-forms-coverage (TAPair wt wt₁) bv nn na ns np nh = np _ _ refl
canonical-boxed-forms-coverage (TAFst wt) (BVVal ()) nn na ns np nh
canonical-boxed-forms-coverage (TASnd wt) (BVVal ()) nn na ns np nh
| 46.85
| 123
| 0.509072
|
1e9ce33a4e48ba1dc49589d8d29cd5ff99fd7789
| 201
|
agda
|
Agda
|
test/Fail/Issue4748c.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Fail/Issue4748c.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Fail/Issue4748c.agda
|
antoinevanmuylder/agda
|
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --cubical-compatible #-}
postulate
A : Set
B : A → Set
-- fine
record R₀ : Set where
field
@0 x : A
@0 y : B x
-- bad
record R : Set where
field
@0 x : A
y : B x
| 11.166667
| 36
| 0.512438
|
a07141485ea459985903d2f5681680e9a4678222
| 397
|
agda
|
Agda
|
test/Fail/PruneBadRigidDef.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/PruneBadRigidDef.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/PruneBadRigidDef.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2014-05-26 Andrea & Andreas
-- hasBadRigids (in pruning) should reduce term before checking.
open import Common.Equality
postulate
Fence : Set → Set
id : ∀{a}{A : Set a}(x : A) → A
id x = x
test : let H : Set; H = _; M : Set → Set; M = _ in
(A : Set) → H ≡ Fence (M (id A))
test A = refl
-- Expected output:
-- M remains unsolved,
-- but H is solved by pruning the argument of M!
| 20.894737
| 64
| 0.612091
|
30ed477ee6026383b9a780150bb09e59ed98b025
| 181
|
agda
|
Agda
|
test/Succeed/Issue4833.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4833.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4833.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
abstract
data Nat : Set where
Zero : Nat
Succ : Nat → Nat
countDown : Nat → Nat
countDown x with x
... | Zero = Zero
... | Succ n = countDown n
| 15.083333
| 28
| 0.58011
|
d190962ae0574b52f6c307cf9ed30cadc536c233
| 6,321
|
agda
|
Agda
|
Cubical/Algebra/Group/Subgroup.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/Group/Subgroup.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/Group/Subgroup.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-
This file contains basic theory about subgroups.
The definition is the same as the first definition of subgroups in:
https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#subgroups-sip
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Subgroup where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.GroupoidLaws hiding (assoc)
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
private
variable
ℓ : Level
-- We assume an ambient group
module _ (G' : Group ℓ) where
open GroupStr (snd G')
private G = ⟨ G' ⟩
record isSubgroup (H : ℙ G) : Type ℓ where
field
id-closed : (1g ∈ H)
op-closed : {x y : G} → x ∈ H → y ∈ H → x · y ∈ H
inv-closed : {x : G} → x ∈ H → inv x ∈ H
open isSubgroup
Subgroup : Type (ℓ-suc ℓ)
Subgroup = Σ[ H ∈ ℙ G ] isSubgroup H
isPropIsSubgroup : (H : ℙ G) → isProp (isSubgroup H)
id-closed (isPropIsSubgroup H h1 h2 i) =
∈-isProp H 1g (h1 .id-closed) (h2 .id-closed) i
op-closed (isPropIsSubgroup H h1 h2 i) Hx Hy =
∈-isProp H _ (h1 .op-closed Hx Hy) (h2 .op-closed Hx Hy) i
inv-closed (isPropIsSubgroup H h1 h2 i) Hx =
∈-isProp H _ (h1 .inv-closed Hx) (h2 .inv-closed Hx) i
isSetSubgroup : isSet Subgroup
isSetSubgroup = isSetΣ isSetℙ λ x → isProp→isSet (isPropIsSubgroup x)
Subgroup→Group : Subgroup → Group ℓ
Subgroup→Group (H , Hh) = makeGroup-right 1HG _·HG_ invHG isSetHG assocHG ridHG invrHG
where
HG = Σ[ x ∈ G ] ⟨ H x ⟩
isSetHG = isSetΣ is-set (λ x → isProp→isSet (H x .snd))
1HG : HG
1HG = (1g , (id-closed Hh))
_·HG_ : HG → HG → HG
(x , Hx) ·HG (y , Hy) = (x · y) , (op-closed Hh Hx Hy)
invHG : HG → HG
invHG (x , Hx) = inv x , inv-closed Hh Hx
assocHG : (x y z : HG) → x ·HG (y ·HG z) ≡ (x ·HG y) ·HG z
assocHG (x , Hx) (y , Hy) (z , Hz) =
ΣPathP (assoc x y z , isProp→PathP (λ i → H (assoc x y z i) .snd) _ _)
ridHG : (x : HG) → x ·HG 1HG ≡ x
ridHG (x , Hx) = ΣPathP (rid x , isProp→PathP (λ i → H (rid x i) .snd) _ _)
invrHG : (x : HG) → x ·HG invHG x ≡ 1HG
invrHG (x , Hx) = ΣPathP (invr x , isProp→PathP (λ i → H (invr x i) .snd) _ _)
⟪_⟫ : {G' : Group ℓ} → Subgroup G' → ℙ (G' .fst)
⟪ H , _ ⟫ = H
module _ {G' : Group ℓ} where
open GroupStr (snd G')
open isSubgroup
open GroupTheory G'
private G = ⟨ G' ⟩
isNormal : Subgroup G' → Type ℓ
isNormal H = (g h : G) → h ∈ ⟪ H ⟫ → g · h · inv g ∈ ⟪ H ⟫
isPropIsNormal : (H : Subgroup G') → isProp (isNormal H)
isPropIsNormal H = isPropΠ3 λ g h _ → ∈-isProp ⟪ H ⟫ (g · h · inv g)
·CommNormalSubgroup : (H : Subgroup G') (Hnormal : isNormal H) {x y : G}
→ x · y ∈ ⟪ H ⟫ → y · x ∈ ⟪ H ⟫
·CommNormalSubgroup H Hnormal {x = x} {y = y} Hxy =
subst-∈ ⟪ H ⟫ rem (Hnormal (inv x) (x · y) Hxy)
where
rem : inv x · (x · y) · inv (inv x) ≡ y · x
rem = inv x · (x · y) · inv (inv x) ≡⟨ assoc _ _ _ ⟩
(inv x · x · y) · inv (inv x) ≡⟨ (λ i → assoc (inv x) x y i · invInv x i) ⟩
((inv x · x) · y) · x ≡⟨ cong (λ z → (z · y) · x) (invl x) ⟩
(1g · y) · x ≡⟨ cong (_· x) (lid y) ⟩
y · x ∎
-- Examples of subgroups
-- We can view all of G as a subset of itself
groupSubset : ℙ G
groupSubset x = (x ≡ x) , is-set x x
isSubgroupGroup : isSubgroup G' groupSubset
id-closed isSubgroupGroup = refl
op-closed isSubgroupGroup _ _ = refl
inv-closed isSubgroupGroup _ = refl
groupSubgroup : Subgroup G'
groupSubgroup = groupSubset , isSubgroupGroup
-- The trivial subgroup
trivialSubset : ℙ G
trivialSubset x = (x ≡ 1g) , is-set x 1g
isSubgroupTrivialGroup : isSubgroup G' trivialSubset
id-closed isSubgroupTrivialGroup = refl
op-closed isSubgroupTrivialGroup hx hy = cong (_· _) hx ∙∙ lid _ ∙∙ hy
inv-closed isSubgroupTrivialGroup hx = cong inv hx ∙ inv1g
trivialSubgroup : Subgroup G'
trivialSubgroup = trivialSubset , isSubgroupTrivialGroup
isNormalTrivialSubgroup : isNormal trivialSubgroup
isNormalTrivialSubgroup g h h≡1 =
(g · h · inv g) ≡⟨ (λ i → g · h≡1 i · inv g) ⟩
(g · 1g · inv g) ≡⟨ assoc _ _ _ ∙ cong (_· inv g) (rid g) ⟩
(g · inv g) ≡⟨ invr g ⟩
1g ∎
NormalSubgroup : (G : Group ℓ) → Type _
NormalSubgroup G = Σ[ G ∈ Subgroup G ] isNormal G
-- Can one get this to work with different universes for G and H?
module _ {G H : Group ℓ} (ϕ : GroupHom G H) where
open isSubgroup
open GroupTheory
private
module G = GroupStr (snd G)
module H = GroupStr (snd H)
f = ϕ .fst
module ϕ = IsGroupHom (ϕ .snd)
imSubset : ℙ ⟨ H ⟩
imSubset x = isInIm ϕ x , isPropIsInIm ϕ x
isSubgroupIm : isSubgroup H imSubset
id-closed isSubgroupIm = ∣ G.1g , ϕ.pres1 ∣
op-closed isSubgroupIm =
map2 λ { (x , hx) (y , hy) → x G.· y , ϕ.pres· x y ∙ λ i → hx i H.· hy i }
inv-closed isSubgroupIm = map λ { (x , hx) → G.inv x , ϕ.presinv x ∙ cong H.inv hx }
imSubgroup : Subgroup H
imSubgroup = imSubset , isSubgroupIm
imGroup : Group ℓ
imGroup = Subgroup→Group _ imSubgroup
kerSubset : ℙ ⟨ G ⟩
kerSubset x = isInKer ϕ x , isPropIsInKer ϕ x
isSubgroupKer : isSubgroup G kerSubset
id-closed isSubgroupKer = ϕ.pres1
op-closed isSubgroupKer {x} {y} hx hy =
ϕ.pres· x y ∙∙ (λ i → hx i H.· hy i) ∙∙ H.rid _
inv-closed isSubgroupKer hx = ϕ.presinv _ ∙∙ cong H.inv hx ∙∙ inv1g H
kerSubgroup : Subgroup G
kerSubgroup = kerSubset , isSubgroupKer
isNormalKer : isNormal kerSubgroup
isNormalKer x y hy =
f (x G.· y G.· G.inv x) ≡⟨ ϕ.pres· _ _ ⟩
f x H.· f (y G.· G.inv x) ≡⟨ cong (f x H.·_) (ϕ.pres· _ _) ⟩
f x H.· f y H.· f (G.inv x) ≡⟨ (λ i → f x H.· hy i H.· f (G.inv x)) ⟩
f x H.· (H.1g H.· f (G.inv x)) ≡⟨ cong (f x H.·_) (H.lid _) ⟩
f x H.· f (G.inv x) ≡⟨ cong (f x H.·_) (ϕ.presinv x) ⟩
f x H.· H.inv (f x) ≡⟨ H.invr _ ⟩
H.1g ∎
| 32.086294
| 92
| 0.592311
|
3d072e6d546861564967fcaa791219dff0e66365
| 2,545
|
agda
|
Agda
|
agda-stdlib/src/Relation/Binary/Construct/Add/Point/Equality.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Relation/Binary/Construct/Add/Point/Equality.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Relation/Binary/Construct/Add/Point/Equality.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A pointwise lifting of a relation to incorporate an additional point.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- This module is designed to be used with
-- Relation.Nullary.Construct.Add.Point
open import Relation.Binary
module Relation.Binary.Construct.Add.Point.Equality
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Level using (_⊔_)
open import Function
import Relation.Binary.PropositionalEquality as P
open import Relation.Nullary hiding (Irrelevant)
open import Relation.Nullary.Construct.Add.Point
import Relation.Nullary.Decidable as Dec
------------------------------------------------------------------------
-- Definition
data _≈∙_ : Rel (Pointed A) (a ⊔ ℓ) where
∙≈∙ : ∙ ≈∙ ∙
[_] : {k l : A} → k ≈ l → [ k ] ≈∙ [ l ]
------------------------------------------------------------------------
-- Relational properties
[≈]-injective : ∀ {k l} → [ k ] ≈∙ [ l ] → k ≈ l
[≈]-injective [ k≈l ] = k≈l
≈∙-refl : Reflexive _≈_ → Reflexive _≈∙_
≈∙-refl ≈-refl {∙} = ∙≈∙
≈∙-refl ≈-refl {[ k ]} = [ ≈-refl ]
≈∙-sym : Symmetric _≈_ → Symmetric _≈∙_
≈∙-sym ≈-sym ∙≈∙ = ∙≈∙
≈∙-sym ≈-sym [ x≈y ] = [ ≈-sym x≈y ]
≈∙-trans : Transitive _≈_ → Transitive _≈∙_
≈∙-trans ≈-trans ∙≈∙ ∙≈z = ∙≈z
≈∙-trans ≈-trans [ x≈y ] [ y≈z ] = [ ≈-trans x≈y y≈z ]
≈∙-dec : Decidable _≈_ → Decidable _≈∙_
≈∙-dec _≟_ ∙ ∙ = yes ∙≈∙
≈∙-dec _≟_ ∙ [ l ] = no (λ ())
≈∙-dec _≟_ [ k ] ∙ = no (λ ())
≈∙-dec _≟_ [ k ] [ l ] = Dec.map′ [_] [≈]-injective (k ≟ l)
≈∙-irrelevant : Irrelevant _≈_ → Irrelevant _≈∙_
≈∙-irrelevant ≈-irr ∙≈∙ ∙≈∙ = P.refl
≈∙-irrelevant ≈-irr [ p ] [ q ] = P.cong _ (≈-irr p q)
≈∙-substitutive : ∀ {ℓ} → Substitutive _≈_ ℓ → Substitutive _≈∙_ ℓ
≈∙-substitutive ≈-subst P ∙≈∙ = id
≈∙-substitutive ≈-subst P [ p ] = ≈-subst (P ∘′ [_]) p
------------------------------------------------------------------------
-- Structures
≈∙-isEquivalence : IsEquivalence _≈_ → IsEquivalence _≈∙_
≈∙-isEquivalence ≈-isEquivalence = record
{ refl = ≈∙-refl refl
; sym = ≈∙-sym sym
; trans = ≈∙-trans trans
} where open IsEquivalence ≈-isEquivalence
≈∙-isDecEquivalence : IsDecEquivalence _≈_ → IsDecEquivalence _≈∙_
≈∙-isDecEquivalence ≈-isDecEquivalence = record
{ isEquivalence = ≈∙-isEquivalence isEquivalence
; _≟_ = ≈∙-dec _≟_
} where open IsDecEquivalence ≈-isDecEquivalence
| 32.628205
| 72
| 0.500982
|
8bd0ad40cf35779fc5d178edd013398feb764f4a
| 1,454
|
agda
|
Agda
|
agda-stdlib/src/Data/Vec/Bounded.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Vec/Bounded.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Vec/Bounded.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bounded vectors
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Bounded where
open import Level using (Level)
open import Data.Nat.Base
open import Data.Vec as Vec using (Vec)
open import Function
open import Relation.Binary using (_Preserves_⟶_)
open import Relation.Unary using (Pred; Decidable)
private
variable
a p : Level
A : Set a
------------------------------------------------------------------------
-- Publicly re-export the contents of the base module
open import Data.Vec.Bounded.Base public
------------------------------------------------------------------------
-- Additional operations
lift : ∀ {f} → f Preserves _≤_ ⟶ _≤_ →
(∀ {n} → Vec A n → Vec≤ A (f n)) →
∀ {n} → Vec≤ A n → Vec≤ A (f n)
lift incr f (as , p) = ≤-cast (incr p) (f as)
lift′ : (∀ {n} → Vec A n → Vec≤ A n) →
(∀ {n} → Vec≤ A n → Vec≤ A n)
lift′ = lift id
------------------------------------------------------------------------
-- Additional operations
module _ {P : Pred A p} (P? : Decidable P) where
filter : ∀ {n} → Vec≤ A n → Vec≤ A n
filter = lift′ (Vec.filter P?)
takeWhile : ∀ {n} → Vec≤ A n → Vec≤ A n
takeWhile = lift′ (Vec.takeWhile P?)
dropWhile : ∀ {n} → Vec≤ A n → Vec≤ A n
dropWhile = lift′ (Vec.dropWhile P?)
| 27.433962
| 72
| 0.454608
|
d1efe7c1611fab46d2433f4df4626e57a317e2b0
| 215
|
agda
|
Agda
|
src/Generic/Test.agda
|
iblech/Generic
|
380554b20e0991290d1864ddf81f0587ec1647ed
|
[
"MIT"
] | 30
|
2016-07-19T21:10:54.000Z
|
2022-02-05T10:19:38.000Z
|
src/Generic/Test.agda
|
iblech/Generic
|
380554b20e0991290d1864ddf81f0587ec1647ed
|
[
"MIT"
] | 9
|
2017-04-06T18:58:09.000Z
|
2022-01-04T15:43:14.000Z
|
src/Generic/Test.agda
|
iblech/Generic
|
380554b20e0991290d1864ddf81f0587ec1647ed
|
[
"MIT"
] | 4
|
2017-07-17T07:23:39.000Z
|
2021-01-27T12:57:09.000Z
|
module Generic.Test where
import Generic.Test.Data
import Generic.Test.DeriveEq
import Generic.Test.Elim
import Generic.Test.Eq
import Generic.Test.Experiment
import Generic.Test.ReadData
import Generic.Test.Reify
| 21.5
| 30
| 0.846512
|
431cc9c8d68cb15c1bc77bc987c1c9abffe2b3b3
| 588
|
agda
|
Agda
|
test/Compiler/simple/CompilingCoinduction.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/Compiler/simple/CompilingCoinduction.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/Compiler/simple/CompilingCoinduction.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
module CompilingCoinduction where
open import Common.Coinduction
open import Common.Char
open import Common.String
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
postulate
IO : Set → Set
{-# COMPILED_TYPE IO IO #-}
{-# BUILTIN IO IO #-}
{-# IMPORT Data.Text.IO #-}
postulate
putStrLn : ∞ String → IO Unit
{-# COMPILED putStrLn Data.Text.IO.putStrLn #-}
{-# COMPILED_UHC putStrLn (UHC.Agda.Builtins.primPutStrLn) #-}
{-# COMPILED_JS putStrLn function(x) { return function(cb) { process.stdout.write(x(0) + "\n"); cb(0); }; } #-}
main = putStrLn (♯ "a")
| 20.275862
| 111
| 0.668367
|
cbf14dd6a5fdd5c42b09974423fe85c9fc8027b6
| 163
|
agda
|
Agda
|
lib-safe.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
lib-safe.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
lib-safe.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module lib-safe where
open import datatypes-safe public
open import logic public
open import thms public
open import termination public
open import error public
| 18.111111
| 33
| 0.834356
|
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.