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
199476c1802e31da8805087f59e1079b7870c558
107
agda
Agda
Either.agda
brunoczim/ual
ea0260e1a0612ba581e4283dfb187f531a944dfd
[ "MIT" ]
null
null
null
Either.agda
brunoczim/ual
ea0260e1a0612ba581e4283dfb187f531a944dfd
[ "MIT" ]
null
null
null
Either.agda
brunoczim/ual
ea0260e1a0612ba581e4283dfb187f531a944dfd
[ "MIT" ]
null
null
null
module Ual.Either where infix 10 _∨_ data _∨_ (A B : Set) : Set where orL : A → A ∨ B orR : B → A ∨ B
15.285714
32
0.560748
30a21a6b7dc9943d0426a6f68c00798b400e1e10
2,363
agda
Agda
test/interaction/AutoMisc.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/interaction/AutoMisc.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/interaction/AutoMisc.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module AutoMisc where -- prelude postulate Level : Set lzero : Level lsuc : (i : Level) → Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO lzero #-} {-# BUILTIN LEVELSUC lsuc #-} data _≡_ {a} {A : Set a} (x : A) : A → Set where refl : x ≡ x trans : ∀ {a} {A : Set a} → {x y z : A} → x ≡ y → y ≡ z → x ≡ z trans refl refl = refl sym : ∀ {a} {A : Set a} → {x y : A} → x ≡ y → y ≡ x sym refl = refl cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y cong f refl = refl data _IsRelatedTo_ {a : Level} {Carrier : Set a} (x y : Carrier) : Set a where relTo : (x∼y : x ≡ y) → x IsRelatedTo y begin_ : {a : Level} {Carrier : Set a} → {x y : Carrier} → x IsRelatedTo y → x ≡ y begin relTo x∼y = x∼y _∎ : {a : Level} {Carrier : Set a} → (x : Carrier) → x IsRelatedTo x _∎ _ = relTo refl _≡⟨_⟩_ : {a : Level} {Carrier : Set a} → (x : Carrier) {y z : Carrier} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z _ ≡⟨ x∼y ⟩ relTo y∼z = relTo (trans x∼y y∼z) data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ _+_ : ℕ → ℕ → ℕ zero + n = n suc m + n = suc (m + n) data ⊥ : Set where ¬ : Set → Set ¬ A = A → ⊥ data Π (A : Set) (F : A → Set) : Set where fun : ((a : A) → F a) → Π A F data Σ (A : Set) (F : A → Set) : Set where ΣI : (a : A) → (F a) → Σ A F data Fin : ℕ → Set where zero : ∀ {n} → Fin (suc n) suc : ∀ {n} → Fin n → Fin (suc n) data List (X : Set) : Set where [] : List X _∷_ : X → List X → List X _++_ : {X : Set} → List X → List X → List X [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) data Vec (X : Set) : ℕ → Set where [] : Vec X zero _∷_ : ∀ {n} → X → Vec X n → Vec X (suc n) module AdditionCommutative where lemma : ∀ n m → (n + suc m) ≡ suc (n + m) lemma n m = {!!} lemma' : ∀ n m → (n + suc m) ≡ suc (n + m) lemma' zero m = refl lemma' (suc n) m = cong suc (lemma' n m) addcommut : ∀ n m → (n + m) ≡ (m + n) addcommut n m = {!!} module Drink where postulate RAA : (A : Set) → (¬ A → ⊥) → A drink : (A : Set) → (a : A) → (Drink : A → Set) → Σ A (λ x → (Drink x) → Π A Drink) drink A a Drink = {!!} module VecMap where map : {X Y : Set} → {n : ℕ} → (X → Y) → Vec X n → Vec Y n map f xs = {!!} module Disproving where p : {X : Set} → (xs ys : List X) → (xs ++ ys) ≡ (ys ++ xs) p = {!!}
21.678899
114
0.489209
30b954ce2c5ebbf9bec299e6002632cf1b79c11a
774
agda
Agda
test/asset/agda-stdlib-1.0/Data/Product/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Product/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Product/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of products ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Product.Properties where open import Data.Product open import Function using (_∘_) open import Relation.Binary using (Decidable) open import Relation.Binary.PropositionalEquality open import Relation.Nullary using (yes; no) ------------------------------------------------------------------------ -- Equality module _ {a b} {A : Set a} {B : A → Set b} where ,-injectiveˡ : ∀ {a c} {b : B a} {d : B c} → (a , b) ≡ (c , d) → a ≡ c ,-injectiveˡ refl = refl -- See also Data.Product.Properties.WithK.,-injectiveʳ.
29.769231
72
0.484496
1ba9cecf657dac6c1571ad4379c1723096014f03
3,964
agda
Agda
theorems/cw/cohomology/reconstructed/FirstGroup.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/cw/cohomology/reconstructed/FirstGroup.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/cw/cohomology/reconstructed/FirstGroup.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import cohomology.Theory open import cohomology.PtdMapSequence open import groups.ExactSequence open import groups.Exactness open import groups.HomSequence open import groups.KernelImageUniqueFactorization open import cw.CW module cw.cohomology.reconstructed.FirstGroup {i} (OT : OrdinaryTheory i) (⊙skel : ⊙Skeleton {i} 2) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where open OrdinaryTheory OT open import cohomology.LongExactSequence cohomology-theory open import cw.cohomology.WedgeOfCells OT open import cw.cohomology.grid.PtdMap (⊙cw-incl-last (⊙cw-init ⊙skel)) (⊙cw-incl-last ⊙skel) open import cw.cohomology.reconstructed.TipAndAugment OT (⊙cw-take (lteSR lteS) ⊙skel) open import cw.cohomology.reconstructed.TipCoboundary OT (⊙cw-init ⊙skel) open import cw.cohomology.reconstructed.HigherCoboundary OT ⊙skel open import cw.cohomology.reconstructed.HigherCoboundaryGrid OT ⊙skel ac open import cw.cohomology.reconstructed.TipGrid OT (⊙cw-init ⊙skel) (⊙init-has-cells-with-choice ⊙skel ac) open import cw.cohomology.reconstructed.TopGrid OT 1 (⊙cw-incl-last (⊙cw-init ⊙skel)) (⊙cw-incl-last ⊙skel) private 0≤2 : 0 ≤ 2 0≤2 = lteSR lteS ac₀ = ⊙take-has-cells-with-choice 0≤2 ⊙skel ac {- H Coker ≃ C(X₁)<------C(X₂) = C(X) ^ ^ | | | | C(X₁/X₀)<---C(X₂/X₀) ≃ Ker WoC G WoC := Wedges of Cells -} private G : Group i G = C 1 (⊙Cofiber (⊙cw-incl-tail 0≤2 ⊙skel)) G-iso-Ker : G ≃ᴳ Ker.grp cw-co∂-last G-iso-Ker = Ker-cw-co∂-last H : Group i H = C 1 ⊙⟦ ⊙cw-init ⊙skel ⟧ Coker-iso-H : CokerCo∂Head.grp ≃ᴳ H Coker-iso-H = Coker-cw-co∂-head G-to-C-cw : G →ᴳ C 1 ⊙⟦ ⊙skel ⟧ G-to-C-cw = C-fmap 1 (⊙cfcod' (⊙cw-incl-tail 0≤2 ⊙skel)) abstract G-to-C-cw-is-surj : is-surjᴳ G-to-C-cw G-to-C-cw-is-surj = Exact.K-trivial-implies-φ-is-surj (exact-seq-index 2 $ C-cofiber-exact-seq 0 (⊙cw-incl-tail 0≤2 ⊙skel)) (CX₀-≠-is-trivial (pos-≠ (ℕ-S≠O 0)) ac₀) C-cw-to-H : C 1 ⊙⟦ ⊙skel ⟧ →ᴳ H C-cw-to-H = C-fmap 1 (⊙cw-incl-last ⊙skel) abstract C-cw-to-H-is-inj : is-injᴳ C-cw-to-H C-cw-to-H-is-inj = Exact.G-trivial-implies-ψ-is-inj (exact-seq-index 2 $ C-cofiber-exact-seq 0 (⊙cw-incl-last ⊙skel)) (CXₙ/Xₙ₋₁-<-is-trivial ⊙skel ltS ac) C-WoC : Group i C-WoC = C 1 (⊙Cofiber (⊙cw-incl-last (⊙cw-init ⊙skel))) G-to-C-WoC : G →ᴳ C-WoC G-to-C-WoC = C-fmap 1 Y/X-to-Z/X C-WoC-to-H : C-WoC →ᴳ H C-WoC-to-H = C-fmap 1 (⊙cfcod' (⊙cw-incl-last (⊙cw-init ⊙skel))) open import groups.KernelImage cw-co∂-last cw-co∂-head CX₁/X₀-is-abelian C-cw-iso-ker/im : C 1 ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im C-cw-iso-ker/im = H-iso-Ker/Im cw-co∂-last cw-co∂-head CX₁/X₀-is-abelian φ₁ φ₁-is-surj φ₂ φ₂-is-inj lemma-comm where φ₁ = G-to-C-cw ∘ᴳ GroupIso.g-hom G-iso-Ker abstract φ₁-is-surj : is-surjᴳ φ₁ φ₁-is-surj = ∘-is-surj G-to-C-cw-is-surj (equiv-is-surj (GroupIso.g-is-equiv G-iso-Ker)) φ₂ = GroupIso.g-hom Coker-iso-H ∘ᴳ C-cw-to-H abstract φ₂-is-inj : is-injᴳ φ₂ φ₂-is-inj = ∘-is-inj (equiv-is-inj (GroupIso.g-is-equiv Coker-iso-H)) C-cw-to-H-is-inj abstract lemma-comm : ∀ g → GroupIso.g Coker-iso-H (GroupHom.f (C-cw-to-H ∘ᴳ G-to-C-cw) (GroupIso.g G-iso-Ker g)) == q[ fst g ] lemma-comm g = GroupIso.g Coker-iso-H (GroupHom.f C-cw-to-H (GroupHom.f G-to-C-cw (GroupIso.g G-iso-Ker g))) =⟨ ap (GroupIso.g Coker-iso-H) (! (C-top-grid-commutes □$ᴳ GroupIso.g G-iso-Ker g)) ⟩ GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (GroupHom.f G-to-C-WoC (GroupIso.g G-iso-Ker g))) =⟨ ap (GroupIso.g Coker-iso-H ∘ GroupHom.f C-WoC-to-H ∘ fst) (GroupIso.f-g G-iso-Ker g) ⟩ GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (fst g)) =⟨ GroupIso.g-f Coker-iso-H q[ fst g ] ⟩ q[ fst g ] =∎
34.469565
107
0.619576
0bf2bce784d25e884f8d7332c8915cf08369e137
13,653
agda
Agda
docs/fomega/mutual-type-level-recursion/MutualData.agda
robkorn/plutus
727151dcf8bce8d7b7ef50b63652c926b3a722ef
[ "MIT" ]
null
null
null
docs/fomega/mutual-type-level-recursion/MutualData.agda
robkorn/plutus
727151dcf8bce8d7b7ef50b63652c926b3a722ef
[ "MIT" ]
null
null
null
docs/fomega/mutual-type-level-recursion/MutualData.agda
robkorn/plutus
727151dcf8bce8d7b7ef50b63652c926b3a722ef
[ "MIT" ]
null
null
null
-- In this document we'll consider various encodings of mutual data types, -- including those that are System Fω compatible. module MutualData where open import Function open import Data.Unit.Base open import Data.Sum open import Data.Product -- In the first part of this document we'll demostrate how various encodings work taking -- the rose tree data type as an example: mutual data Tree₀ (A : Set) : Set where node₀ : A -> Forest₀ A -> Tree₀ A data Forest₀ (A : Set) : Set where nil₀ : Forest₀ A cons₀ : Tree₀ A -> Forest₀ A -> Forest₀ A module Joined where -- For encoding a family of mutually recursive data types in terms of a single data type we can -- create the type of tags each of which denotes a particular data type from the family, then -- merge all constructors of the original data types together into a single data type and index -- each of the constructors by the tag representing the data type it constructs. -- Since we encode a family consisting of two data types, the type of tags has two inhabitants: data TreeForestᵗ : Set where Treeᵗ Forestᵗ : TreeForestᵗ -- The encoding: mutual -- There is nothing inherently mutual about these data types. -- `Tree` and `Forest` are just aliases defined for convenience and readability. Tree : Set -> Set Tree A = TreeForest A Treeᵗ Forest : Set -> Set Forest A = TreeForest A Forestᵗ -- Now we have one big data type that contains all constructors of the `Tree`-`Forest` family: data TreeForest (A : Set) : TreeForestᵗ -> Set where node : A -> Forest A -> Tree A nil : Forest A cons : Tree A -> Forest A -> Forest A -- Note that the constructors have exactly the same type signatures as before, -- but now `Tree` and `Forest` are instances of the same data type. -- As a sanity check we show one side (just to save space and because it's demonstrative enough) -- of the isomorphism between the original family and its encoded version: mutual toTree₀ : ∀ {A} -> Tree A -> Tree₀ A toTree₀ (node x forest) = node₀ x (toForest₀ forest) toForest₀ : ∀ {A} -> Forest A -> Forest₀ A toForest₀ nil = nil₀ toForest₀ (cons tree forest) = cons₀ (toTree₀ tree) (toForest₀ forest) -- The encoding technique described in this module is fairly well-known. module JoinedCompute where -- In this section we'll make `TreeForest` a data type with a single constructor, -- the contents of which depends on the type being constructed. data TreeForestᵗ : Set where Treeᵗ Forestᵗ : TreeForestᵗ mutual -- Again, `Tree` and `Forest` are just aliases. Tree : Set -> Set Tree A = TreeForest A Treeᵗ Forest : Set -> Set Forest A = TreeForest A Forestᵗ -- `TreeForestF` matches on the `TreeForestᵗ` index in order to figure out which data type -- from the original family is being constructed. -- Like in the previous section `TreeForest` defines both the `Tree` and `Forest` data types, -- but now it contains a single constructor that only captures the notion of recursion. -- What data to store in this constructor is determined by the `TreeForestF` function. TreeForestF : Set -> TreeForestᵗ -> Set TreeForestF A Treeᵗ = A × Forest A -- The only constructor of `Tree` is `node` which -- carries an `A` and a `Forest A`. TreeForestF A Forestᵗ = ⊤ ⊎ Tree A × Forest A -- There are two constructors of `Forest`: -- `nil` and `cons`. The former one doesn't -- carry any information while the latter one -- receives a `Tree` and a `Forest`. data TreeForest (A : Set) (tfᵗ : TreeForestᵗ) : Set where treeForest : TreeForestF A tfᵗ -> TreeForest A tfᵗ -- For convenience, we'll be using pattern synonyms in this module and the modules below. pattern node x forest = treeForest (x , forest) pattern nil = treeForest (inj₁ tt) pattern cons tree forest = treeForest (inj₂ (tree , forest)) -- The sanity check. mutual toTree₀ : ∀ {A} -> Tree A -> Tree₀ A toTree₀ (node x forest) = node₀ x (toForest₀ forest) toForest₀ : ∀ {A} -> Forest A -> Forest₀ A toForest₀ nil = nil₀ toForest₀ (cons tree forest) = cons₀ (toTree₀ tree) (toForest₀ forest) -- In the previous section we had the `TreeForest` data type and its `treeForest` constructor -- which together captured the notion of recursion. This pattern can be abstracted, so that we can -- tie knots in arbitrary other data types -- not just `Tree` and `Forest`. Enter `IFix`: {-# NO_POSITIVITY_CHECK #-} data IFix {α β} {A : Set α} (B : (A -> Set β) -> A -> Set β) (x : A) : Set β where wrap : B (IFix B) x -> IFix B x module JoinedComputeIFix where -- In this module we define the `TreeForest` data type using `IFix`. -- The type of tags is as before: data TreeForestᵗ : Set where Treeᵗ Forestᵗ : TreeForestᵗ -- The definition of `TreeForest` is similar to the definition from the previous section: -- we again have the `Tree` and `Forest` type aliases, they're just local now, -- and as before we dispatch on `tfᵗ` and describe the constructors of the `Tree` and `Forest` -- data types using the sum-of-products representation: TreeForest : Set -> TreeForestᵗ -> Set TreeForest A = IFix λ Rec tfᵗ -> let Tree = Rec Treeᵗ Forest = Rec Forestᵗ in case tfᵗ of λ { Treeᵗ -> A × Forest ; Forestᵗ -> ⊤ ⊎ Tree × Forest } -- We've cheated a little bit here by keeping `A` outside of the pattern functor. -- That's just for simplicity, there is no fundamental limitation that prevents us -- from taking fixed points of pattern functors of arbitrary arity. -- Which is a topic for another document. Tree : Set -> Set Tree A = TreeForest A Treeᵗ Forest : Set -> Set Forest A = TreeForest A Forestᵗ pattern node x forest = wrap (x , forest) pattern nil = wrap (inj₁ tt) pattern cons tree forest = wrap (inj₂ (tree , forest)) -- The sanity check. mutual toTree₀ : ∀ {A} -> Tree A -> Tree₀ A toTree₀ (node x forest) = node₀ x (toForest₀ forest) toForest₀ : ∀ {A} -> Forest A -> Forest₀ A toForest₀ nil = nil₀ toForest₀ (cons tree forest) = cons₀ (toTree₀ tree) (toForest₀ forest) module JoinedComputeIFixFω where -- The types we had previously are not System Fω compatible, because we matched on tags at the -- type level. Can we avoid this? Yes, easily. Instead of defining data types representing tags -- we can just lambda-encode them, because we do have lambdas at the type level in System Fω. -- The Church-encoded version of `TreeForestᵗ` at the type level looks like this: -- ∀ R -> (Set -> Set -> R) -> R -- However this is still not System Fω compatible, because here we quantify over `R` which in -- System Fω is a kind and we can't quatify over kinds there. But looking at -- TreeForestF : Set -> TreeForestᵗ -> Set -- TreeForestF A Treeᵗ = A × Forest A -- TreeForestF A Forestᵗ = ⊤ ⊎ Tree A × Forest A -- we see that we match on a `TreeForestᵗ` only to return a `Set`. Hence we can just instantiate -- `R` to `Set` right away as we do not do anything else with tags. We arrive at TreeForestᵗ : Set₁ TreeForestᵗ = Set -> Set -> Set Treeᵗ : TreeForestᵗ Treeᵗ A B = A Forestᵗ : TreeForestᵗ Forestᵗ A B = B -- Where `TreeForestᵗ` is the type of inlined matchers which always return a `Set` and -- `Treeᵗ` and `Forestᵗ` are such matchers. The rest is straightforward: TreeForest : Set -> TreeForestᵗ -> Set TreeForest A = IFix λ Rec tfᵗ -> let Tree = Rec Treeᵗ Forest = Rec Forestᵗ in tfᵗ (A × Forest) -- Returned when `tfᵗ` is `Treeᵗ`. (⊤ ⊎ Tree × Forest) -- Returned when `tfᵗ` is `Forestᵗ`. Tree : Set -> Set Tree A = TreeForest A Treeᵗ Forest : Set -> Set Forest A = TreeForest A Forestᵗ -- All types are System Fω compatible (except the definition of `TreeForestᵗ` has to be inlined) -- as System Fω does not support kind aliases. pattern node x forest = wrap (x , forest) pattern nil = wrap (inj₁ tt) pattern cons tree forest = wrap (inj₂ (tree , forest)) -- The sanity check. mutual toTree₀ : ∀ {A} -> Tree A -> Tree₀ A toTree₀ (node x forest) = node₀ x (toForest₀ forest) toForest₀ : ∀ {A} -> Forest A -> Forest₀ A toForest₀ nil = nil₀ toForest₀ (cons tree forest) = cons₀ (toTree₀ tree) (toForest₀ forest) -- An additional test: mutual mapTree : ∀ {A B} -> (A -> B) -> Tree A -> Tree B mapTree f (node x forest) = node (f x) (mapForest f forest) mapForest : ∀ {A B} -> (A -> B) -> Forest A -> Forest B mapForest f nil = nil mapForest f (cons tree forest) = cons (mapTree f tree) (mapForest f forest) -- The first part ends here. We've just seen how to encode mutual data types in pure System Fω -- with build-in isorecursive `IFix :: ((k -> *) -> k -> *) -> k -> *`. -- In the second part we'll see how to encode mutual data types with distinct kind signatures. -- Due to my lack of imagination, we'll take the following family as an example: mutual data M₀ (A : Set) : Set where p₀ : A -> M₀ A n₀ : N₀ -> M₀ A data N₀ : Set where m₀ : M₀ ⊤ -> N₀ -- `M₀` is of kind `Set -> Set` while `N₀` is of kind `Set`. module DistinctParamsJoined where -- As in the first part we start with a single data type that contains all the constructors of -- the family of data types being encoded. -- The only thing we need to do, is to add all the parameters to the constructors of the type -- of tags. The rest just follows. data MNᵗ : Set₁ where Mᵗ : Set -> MNᵗ -- `M` is parameterized by a `Set`, hence one `Set` argument. Nᵗ : MNᵗ -- `N` is not parameterized, hence no arguments. -- The encoding itself follows the same pattern we've seen previously: mutual M : Set -> Set M A = MN (Mᵗ A) N : Set N = MN Nᵗ data MN : MNᵗ -> Set where -- `∀ {A} -> ...` is an artifact of this particular encoding, it'll disappear later. p : ∀ {A} -> A -> M A n : ∀ {A} -> N -> M A m : M ⊤ -> N -- The sanity check. mutual toM₀ : ∀ {A} -> M A -> M₀ A toM₀ (p x) = p₀ x toM₀ (n y) = n₀ (toN₀ y) toN₀ : N -> N₀ toN₀ (m y) = m₀ (toM₀ y) module DistinctParamsJoinedComputeIFix where -- We skip the `JoinedCompute` stage and jump straight to `JoinedComputeIFix`. -- Again, we just add arguments to tags and the rest follows: data MNᵗ : Set₁ where Mᵗ : Set -> MNᵗ Nᵗ : MNᵗ MN : MNᵗ -> Set MN = IFix λ Rec mnᵗ -> let M A = Rec (Mᵗ A) N = Rec Nᵗ in case mnᵗ of λ { (Mᵗ A) -> A ⊎ N -- `M` has two constructors: one receives an `A` and -- the other receives an `N`. ; Nᵗ -> M ⊤ -- `N` has one constructor which receives an `M ⊤`. } M : Set -> Set M A = MN (Mᵗ A) N : Set N = MN Nᵗ pattern p x = wrap (inj₁ x) pattern n y = wrap (inj₂ y) pattern m y = wrap y -- The sanity check. mutual toM₀ : ∀ {A} -> M A -> M₀ A toM₀ (p x) = p₀ x toM₀ (n y) = n₀ (toN₀ y) toN₀ : N -> N₀ toN₀ (m y) = m₀ (toM₀ y) module DistinctParamsJoinedComputeIFixFω where -- Mechanically performing the restricted Church-encoding transformation that allows to bring -- the types into the realms of System Fω, we get MNᵗ : Set₁ MNᵗ = (Set -> Set) -> Set -> Set Mᵗ : Set -> MNᵗ Mᵗ A = λ rM rN -> rM A Nᵗ : MNᵗ Nᵗ = λ rM rN -> rN -- Nothing new here: MN : MNᵗ -> Set MN = IFix λ Rec mnᵗ -> let M A = Rec (Mᵗ A) N = Rec Nᵗ in mnᵗ (λ A -> A ⊎ N) (M ⊤) M : Set -> Set M A = MN (Mᵗ A) N : Set N = MN Nᵗ pattern p x = wrap (inj₁ x) pattern n y = wrap (inj₂ y) pattern m y = wrap y -- The sanity check. mutual toM₀ : ∀ {A} -> M A -> M₀ A toM₀ (p x) = p₀ x toM₀ (n y) = n₀ (toN₀ y) toN₀ : N -> N₀ toN₀ (m y) = m₀ (toM₀ y) module FakingFix where -- We can look at encoding mutual data types from entirely distinct perspective. -- One of the standard approaches is to have kind-level products and use `Fix :: (k -> k) -> k` -- over them. There is no such `Fix` in Agda, but we can pretend it exists: postulate Fix : ∀ {α} {A : Set α} -> (A -> A) -> A -- Then we can encode `MN` as MN : (Set -> Set) × Set MN = Fix λ Rec -> let M A = proj₁ Rec A N = proj₂ Rec in (λ A -> A ⊎ N) , M ⊤ -- This all is very similar to what we've seen in the previous section: the local definitions -- of `M` and `N` differ and we construct a type-level tuple rather than a `Set`, but the -- pattern is the same. -- The global definitions of `M` and `N` are M : Set -> Set M = proj₁ MN N : Set N = proj₂ MN -- And now we can perform the same restricted Church-encoding trick again and use -- `((Set -> Set) -> Set -> Set) -> Set` instead of `(Set -> Set) × Set`. -- Note that the new type then is exactly the same as the one of `MN` from the previous section: -- MN : MNᵗ -> Set -- which being inlined becomes: -- MN : ((Set -> Set) -> Set -> Set) -> Set -- Hence we arrived at the same encoding taking a folklore technique as a starting point.
32.584726
100
0.62272
5e61d5837325517d6c0071636379581e50a97fe1
14,679
agda
Agda
models/RevisedHutton.agda
dataronio/epigram2
17b7858f51a35b3becb8433028c3f1ba25fbba9a
[ "MIT" ]
48
2016-01-09T17:36:19.000Z
2022-02-11T01:55:28.000Z
models/RevisedHutton.agda
seanwallawalla-forks/Epigram
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
[ "MIT" ]
null
null
null
models/RevisedHutton.agda
seanwallawalla-forks/Epigram
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
[ "MIT" ]
12
2016-08-14T21:36:35.000Z
2022-02-11T01:57:40.000Z
{-# OPTIONS --type-in-type #-} module RevisedHutton where --******************************************** -- Prelude --******************************************** -- Some preliminary stuffs, to avoid relying on the stdlib --**************** -- Sigma and friends --**************** data Sigma (A : Set) (B : A -> Set) : Set where _,_ : (x : A) (y : B x) -> Sigma A B _*_ : (A : Set)(B : Set) -> Set A * B = Sigma A \_ -> B fst : {A : Set}{B : A -> Set} -> Sigma A B -> A fst (a , _) = a snd : {A : Set}{B : A -> Set} (p : Sigma A B) -> B (fst p) snd (a , b) = b data Zero : Set where data Unit : Set where Void : Unit --**************** -- Sum and friends --**************** data _+_ (A : Set)(B : Set) : Set where l : A -> A + B r : B -> A + B --**************** -- Equality --**************** data _==_ {A : Set}(x : A) : A -> Set where refl : x == x subst : forall {x y} -> x == y -> x -> y subst refl x = x cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y cong f refl = refl cong2 : {A B C : Set}(f : A -> B -> C){x y : A}{z t : B} -> x == y -> z == t -> f x z == f y t cong2 f refl refl = refl postulate reflFun : {A B : Set}(f : A -> B)(g : A -> B)-> ((a : A) -> f a == g a) -> f == g --**************** -- Meta-language --**************** -- Note that we could define Nat, Bool, and the related operations in -- IDesc. But it is awful to code with them, in Agda. data Nat : Set where ze : Nat su : Nat -> Nat data Bool : Set where true : Bool false : Bool plus : Nat -> Nat -> Nat plus ze n' = n' plus (su n) n' = su (plus n n') le : Nat -> Nat -> Bool le ze _ = true le (su _) ze = false le (su n) (su n') = le n n' data Vec (A : Set) : Nat -> Set where vnil : Vec A ze vcons : {n : Nat} -> A -> Vec A n -> Vec A (su n) data Fin : Nat -> Set where fze : {n : Nat} -> Fin (su n) fsu : {n : Nat} -> Fin n -> Fin (su n) --******************************************** -- Desc code --******************************************** data IDesc (I : Set) : Set where var : I -> IDesc I const : Set -> IDesc I prod : IDesc I -> IDesc I -> IDesc I sigma : (S : Set) -> (S -> IDesc I) -> IDesc I pi : (S : Set) -> (S -> IDesc I) -> IDesc I --******************************************** -- Desc interpretation --******************************************** [|_|] : {I : Set} -> IDesc I -> (I -> Set) -> Set [| var i |] P = P i [| const X |] P = X [| prod D D' |] P = [| D |] P * [| D' |] P [| sigma S T |] P = Sigma S (\s -> [| T s |] P) [| pi S T |] P = (s : S) -> [| T s |] P --******************************************** -- Fixpoint construction --******************************************** data IMu {I : Set}(R : I -> IDesc I)(i : I) : Set where con : [| R i |] (\j -> IMu R j) -> IMu R i --******************************************** -- Predicate: All --******************************************** All : {I : Set}(D : IDesc I)(P : I -> Set) -> [| D |] P -> IDesc (Sigma I P) All (var i) P x = var (i , x) All (const X) P x = const Unit All (prod D D') P (d , d') = prod (All D P d) (All D' P d') All (sigma S T) P (a , b) = All (T a) P b All (pi S T) P f = pi S (\s -> All (T s) P (f s)) --******************************************** -- Elimination principle: induction --******************************************** module Elim {I : Set} (R : I -> IDesc I) (P : Sigma I (IMu R) -> Set) (m : (i : I) (xs : [| R i |] (IMu R)) (hs : [| All (R i) (IMu R) xs |] P) -> P ( i , con xs )) where mutual indI : (i : I)(x : IMu R i) -> P (i , x) indI i (con xs) = m i xs (hyps (R i) xs) hyps : (D : IDesc I) -> (xs : [| D |] (IMu R)) -> [| All D (IMu R) xs |] P hyps (var i) x = indI i x hyps (const X) x = Void hyps (prod D D') (d , d') = hyps D d , hyps D' d' hyps (pi S R) f = \ s -> hyps (R s) (f s) hyps (sigma S R) ( a , b ) = hyps (R a) b indI : {I : Set} (R : I -> IDesc I) (P : Sigma I (IMu R) -> Set) (m : (i : I) (xs : [| R i |] (IMu R)) (hs : [| All (R i) (IMu R) xs |] P) -> P ( i , con xs)) -> (i : I)(x : IMu R i) -> P ( i , x ) indI = Elim.indI --******************************************** -- Enumerations (hard-coded) --******************************************** -- Unlike in Desc.agda, we don't carry the levitation of finite sets -- here. We hard-code them and manipulate with standard Agda -- machinery. Both presentation are isomorph but, in Agda, the coded -- one quickly gets unusable. data EnumU : Set where nilE : EnumU consE : EnumU -> EnumU data EnumT : (e : EnumU) -> Set where EZe : {e : EnumU} -> EnumT (consE e) ESu : {e : EnumU} -> EnumT e -> EnumT (consE e) spi : (e : EnumU)(P : EnumT e -> Set) -> Set spi nilE P = Unit spi (consE e) P = P EZe * spi e (\e -> P (ESu e)) switch : (e : EnumU)(P : EnumT e -> Set)(b : spi e P)(x : EnumT e) -> P x switch nilE P b () switch (consE e) P b EZe = fst b switch (consE e) P b (ESu n) = switch e (\e -> P (ESu e)) (snd b) n _++_ : EnumU -> EnumU -> EnumU nilE ++ e' = e' (consE e) ++ e' = consE (e ++ e') -- A special switch, for tagged descriptions. Switching on a -- concatenation of finite sets: sswitch : (e : EnumU)(e' : EnumU)(P : Set) (b : spi e (\_ -> P))(b' : spi e' (\_ -> P))(x : EnumT (e ++ e')) -> P sswitch nilE nilE P b b' () sswitch nilE (consE e') P b b' EZe = fst b' sswitch nilE (consE e') P b b' (ESu n) = sswitch nilE e' P b (snd b') n sswitch (consE e) e' P b b' EZe = fst b sswitch (consE e) e' P b b' (ESu n) = sswitch e e' P (snd b) b' n --******************************************** -- Tagged indexed description --******************************************** FixMenu : Set -> Set FixMenu I = Sigma EnumU (\e -> (i : I) -> spi e (\_ -> IDesc I)) SensitiveMenu : Set -> Set SensitiveMenu I = Sigma (I -> EnumU) (\F -> (i : I) -> spi (F i) (\_ -> IDesc I)) TagIDesc : Set -> Set TagIDesc I = FixMenu I * SensitiveMenu I toIDesc : (I : Set) -> TagIDesc I -> (I -> IDesc I) toIDesc I ((E , ED) , (F , FD)) i = sigma (EnumT (E ++ F i)) (\x -> sswitch E (F i) (IDesc I) (ED i) (FD i) x) --******************************************** -- Catamorphism --******************************************** cata : (I : Set) (R : I -> IDesc I) (T : I -> Set) -> ((i : I) -> [| R i |] T -> T i) -> (i : I) -> IMu R i -> T i cata I R T phi i x = indI R (\it -> T (fst it)) (\i xs ms -> phi i (replace (R i) T xs ms)) i x where replace : (D : IDesc I)(T : I -> Set) (xs : [| D |] (IMu R)) (ms : [| All D (IMu R) xs |] (\it -> T (fst it))) -> [| D |] T replace (var i) T x y = y replace (const Z) T z z' = z replace (prod D D') T (x , x') (y , y') = replace D T x y , replace D' T x' y' replace (sigma A B) T (a , b) t = a , replace (B a) T b t replace (pi A B) T f t = \s -> replace (B s) T (f s) (t s) --******************************************** -- Hutton's razor --******************************************** --******************************** -- Types code --******************************** data Type : Set where nat : Type bool : Type pair : Type -> Type -> Type --******************************************** -- Free monad construction --******************************************** _**_ : {I : Set} (R : TagIDesc I)(X : I -> Set) -> TagIDesc I ((E , ED) , FFD) ** X = ((( consE E , \ i -> ( const (X i) , ED i ))) , FFD) --******************************************** -- Substitution --******************************************** apply : {I : Set} (R : TagIDesc I)(X Y : I -> Set) -> ((i : I) -> X i -> IMu (toIDesc I (R ** Y)) i) -> (i : I) -> [| toIDesc I (R ** X) i |] (IMu (toIDesc I (R ** Y))) -> IMu (toIDesc I (R ** Y)) i apply (( E , ED) , (F , FD)) X Y sig i (EZe , x) = sig i x apply (( E , ED) , (F , FD)) X Y sig i (ESu n , t) = con (ESu n , t) substI : {I : Set} (X Y : I -> Set)(R : TagIDesc I) (sigma : (i : I) -> X i -> IMu (toIDesc I (R ** Y)) i) (i : I)(D : IMu (toIDesc I (R ** X)) i) -> IMu (toIDesc I (R ** Y)) i substI {I} X Y R sig i term = cata I (toIDesc I (R ** X)) (IMu (toIDesc I (R ** Y))) (apply R X Y sig) i term --******************************************** -- Hutton's razor is free monad --******************************************** -- Fix menu: exprFreeFixMenu : FixMenu Type exprFreeFixMenu = ( consE nilE , \ty -> (prod (var bool) (prod (var ty) (var ty)), -- if b then t1 else t2 Void)) -- Index-dependent menu: choiceFreeMenu : Type -> EnumU choiceFreeMenu nat = consE nilE choiceFreeMenu bool = consE nilE choiceFreeMenu (pair x y) = nilE choiceFreeDessert : (ty : Type) -> spi (choiceFreeMenu ty) (\ _ -> IDesc Type) choiceFreeDessert nat = (prod (var nat) (var nat) , Void) -- plus x y choiceFreeDessert bool = (prod (var nat) (var nat) , Void ) -- le x y choiceFreeDessert (pair x y) = Void exprFreeSensitiveMenu : SensitiveMenu Type exprFreeSensitiveMenu = ( choiceFreeMenu , choiceFreeDessert ) -- Tagged description of expressions exprFree : TagIDesc Type exprFree = exprFreeFixMenu , exprFreeSensitiveMenu -- Free monadic expressions exprFreeC : (Type -> Set) -> TagIDesc Type exprFreeC X = exprFree ** X --******************************** -- Closed terms --******************************** Val : Type -> Set Val nat = Nat Val bool = Bool Val (pair x y) = (Val x) * (Val y) closeTerm : Type -> IDesc Type closeTerm = toIDesc Type (exprFree ** Val) --******************************** -- Closed term evaluation --******************************** eval : {ty : Type} -> IMu closeTerm ty -> Val ty eval {ty} term = cata Type closeTerm Val evalOneStep ty term where evalOneStep : (ty : Type) -> [| closeTerm ty |] Val -> Val ty evalOneStep _ (EZe , t) = t evalOneStep _ ((ESu EZe) , (true , ( x , _))) = x evalOneStep _ ((ESu EZe) , (false , ( _ , y ))) = y evalOneStep nat ((ESu (ESu EZe)) , (x , y)) = plus x y evalOneStep nat ((ESu (ESu (ESu ()))) , t) evalOneStep bool ((ESu (ESu EZe)) , (x , y) ) = le x y evalOneStep bool ((ESu (ESu (ESu ()))) , _) evalOneStep (pair x y) (ESu (ESu ()) , _) --******************************** -- [Open terms] --******************************** -- A context is a snoc-list of types -- put otherwise, a context is a type telescope data Context : Set where [] : Context _,_ : Context -> Type -> Context -- The environment realizes the context, having a value for each type Env : Context -> Set Env [] = Unit Env (G , S) = Env G * Val S -- A typed-variable indexes into the context, obtaining a proof that -- what we get is what you want (WWGIWYW) Var : Context -> Type -> Set Var [] T = Zero Var (G , S) T = Var G T + (S == T) -- The lookup gets into the context to extract the value lookup : (G : Context) -> Env G -> (T : Type) -> Var G T -> Val T lookup [] _ T () lookup (G , .T) (g , t) T (r refl) = t lookup (G , S) (g , t) T (l x) = lookup G g T x -- Open term: holes are either values or variables in a context openTerm : Context -> Type -> IDesc Type openTerm c = toIDesc Type (exprFree ** (\ty -> Val ty + Var c ty)) --******************************** -- Evaluation of open terms --******************************** -- |discharge| is the local substitution expected by |substI|. It is -- just sugar around context lookup discharge : (context : Context) -> Env context -> (ty : Type) -> (Val ty + Var context ty) -> IMu closeTerm ty discharge ctxt env ty (l value) = con (EZe , value) discharge ctxt env ty (r variable) = con (EZe , lookup ctxt env ty variable ) -- |substExpr| is the specialized |substI| to expressions. We get it -- generically from the free monad construction. substExpr : {ty : Type} (context : Context) (sigma : (ty : Type) -> (Val ty + Var context ty) -> IMu closeTerm ty) -> IMu (openTerm context) ty -> IMu closeTerm ty substExpr {ty} c sig term = substI (\ty -> Val ty + Var c ty) Val exprFree sig ty term -- By first doing substitution to close the term, we can use -- evaluation of closed terms, obtaining evaluation of open terms -- under a valid context. evalOpen : {ty : Type}(context : Context) -> Env context -> IMu (openTerm context) ty -> Val ty evalOpen ctxt env tm = eval (substExpr ctxt (discharge ctxt env) tm) --******************************** -- Tests --******************************** -- Test context: -- V 0 :-> true, V 1 :-> 2, V 2 :-> ( false , 1 ) testContext : Context testContext = (([] , bool) , nat) , pair bool nat testEnv : Env testContext testEnv = ((Void , true ) , su (su ze)) , (false , su ze) -- V 1 test1 : IMu (openTerm testContext) nat test1 = con (EZe , r ( l (r refl) ) ) testSubst1 : IMu closeTerm nat testSubst1 = substExpr testContext (discharge testContext testEnv) test1 -- = 2 testEval1 : Val nat testEval1 = evalOpen testContext testEnv test1 -- add 1 (V 1) test2 : IMu (openTerm testContext) nat test2 = con (ESu (ESu EZe) , (con (EZe , l (su ze)) , con ( EZe , r (l (r refl)) )) ) testSubst2 : IMu closeTerm nat testSubst2 = substExpr testContext (discharge testContext testEnv) test2 -- = 3 testEval2 : Val nat testEval2 = evalOpen testContext testEnv test2 -- if (V 0) then (V 1) else 0 test3 : IMu (openTerm testContext) nat test3 = con (ESu EZe , (con (EZe , r (l (l (r refl)))) , (con (EZe , r (l (r refl))) , con (EZe , l ze)))) testSubst3 : IMu closeTerm nat testSubst3 = substExpr testContext (discharge testContext testEnv) test3 -- = 2 testEval3 : Val nat testEval3 = evalOpen testContext testEnv test3 -- V 2 test4 : IMu (openTerm testContext) (pair bool nat) test4 = con (EZe , r ( r refl ) ) testSubst4 : IMu closeTerm (pair bool nat) testSubst4 = substExpr testContext (discharge testContext testEnv) test4 -- = (false , 1) testEval4 : Val (pair bool nat) testEval4 = evalOpen testContext testEnv test4
30.58125
110
0.462702
35562b7d57093a1be93439cdb73567c0b7299d63
8,293
agda
Agda
src/Nat.agda
myuon/agda-cate
59004994acdbc65fb4f8abf0baa1777a8dbe758e
[ "MIT" ]
2
2018-07-28T04:59:31.000Z
2019-11-02T07:30:47.000Z
src/Nat.agda
myuon/agda-cate
59004994acdbc65fb4f8abf0baa1777a8dbe758e
[ "MIT" ]
null
null
null
src/Nat.agda
myuon/agda-cate
59004994acdbc65fb4f8abf0baa1777a8dbe758e
[ "MIT" ]
null
null
null
module Nat where open import Function hiding (_∘_; id) open import Level open import Basic open import Category import Functor open Category.Category open Functor.Functor record Nat {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} (F G : Functor.Functor C D) : Set (suc (C₀ ⊔ C₁ ⊔ ℓ ⊔ D₀ ⊔ D₁ ⊔ ℓ′)) where field component : (X : Obj C) → Hom D (fobj F X) (fobj G X) field naturality : {a b : Obj C} {f : Hom C a b} → D [ D [ component b ∘ fmap F f ] ≈ D [ fmap G f ∘ component a ] ] open Nat identity : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} → (F : Functor.Functor C D) → Nat F F identity {D = D} F = record { component = λ X → id D ; naturality = λ {a} {b} {f} → trans-hom D (leftId D) (sym-hom D (rightId D)) } compose : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} → {F G H : Functor.Functor C D} → Nat G H → Nat F G → Nat F H compose {C = C} {D} {F} {G} {H} η ε = record { component = λ X → D [ component η X ∘ component ε X ] ; naturality = λ {a} {b} {f} → (begin⟨ D ⟩ D [ (D [ component η b ∘ component ε b ]) ∘ fmap F f ] ≈⟨ assoc D ⟩ D [ component η b ∘ (D [ component ε b ∘ fmap F f ]) ] ≈⟨ ≈-composite D (refl-hom D) (naturality ε) ⟩ D [ component η b ∘ (D [ fmap G f ∘ component ε a ]) ] ≈⟨ sym-hom D (assoc D) ⟩ D [ (D [ component η b ∘ fmap G f ]) ∘ component ε a ] ≈⟨ ≈-composite D (naturality η) (refl-hom D) ⟩ D [ (D [ fmap H f ∘ component η a ]) ∘ component ε a ] ≈⟨ assoc D ⟩ D [ fmap H f ∘ (D [ component η a ∘ component ε a ]) ] ∎) } composeNF : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′ E₀ E₁ ℓ″} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {E : Category E₀ E₁ ℓ″} {A B : Functor.Functor D E} → Nat A B → (F : Functor.Functor C D) → Nat (Functor.compose A F) (Functor.compose B F) composeNF {C = C} {D} {E} {A} {B} η F = record { component = λ X → component η (fobj F X) ; naturality = λ {a} {b} {f} → naturality η } composeFN : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′ E₀ E₁ ℓ″} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {E : Category E₀ E₁ ℓ″} {A B : Functor.Functor C D} (F : Functor.Functor D E) → Nat A B → Nat (Functor.compose F A) (Functor.compose F B) composeFN {C = C} {D} {E} {A} {B} F η = record { component = λ X → fmap F (component η X) ; naturality = λ {a} {b} {f} → begin⟨ E ⟩ E [ fmap F (component η b) ∘ fmap (Functor.compose F A) f ] ≈⟨ sym-hom E (preserveComp F) ⟩ fmap F (D [ component η b ∘ fmap A f ]) ≈⟨ Functor.preserveEq F (naturality η) ⟩ fmap F (D [ fmap B f ∘ component η a ]) ≈⟨ preserveComp F ⟩ E [ fmap (Functor.compose F B) f ∘ fmap F (component η a) ] ∎ } equality : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F G : Functor.Functor C D} → (η τ : Nat F G) → Set _ equality {C = C} {D} η τ = ∀ {a : Obj C} → D [ component η a ≈ component τ a ] subst : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F G : Functor.Functor C D} {η τ : Nat F G} → (a : Obj C) → equality η τ → D [ component η a ≈ component τ a ] subst a eq = eq {a} HomFunctor : ∀ {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) (X : Obj C) → Functor.Functor C Setoids HomFunctor C X = record { fobj = λ x → (Homsetoid C X x) ; fmapsetoid = record { mapping = λ x → record { mapping = λ x₁ → C [ x ∘ x₁ ] ; preserveEq = ≈-composite C (refl-hom C) } ; preserveEq = λ x₁ x₂ → ≈-composite C x₁ (refl-hom C) } ; preserveId = λ x → leftId C ; preserveComp = λ x → assoc C } HomNat : ∀ {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) {A B : Obj C} (f : Hom C A B) → Nat (HomFunctor C B) (HomFunctor C A) HomNat C {A} {B} f = record { component = component-map ; naturality = λ {a} {b} {x} → λ x₁ → begin⟨ C ⟩ Map.mapping (Setoids [ component-map b ∘ fmap (HomFunctor C B) x ]) x₁ ≈⟨ refl-hom C ⟩ C [ C [ x ∘ x₁ ] ∘ f ] ≈⟨ assoc C ⟩ C [ x ∘ C [ x₁ ∘ f ] ] ≈⟨ refl-hom C ⟩ Map.mapping (Setoids [ fmap (HomFunctor C A) x ∘ component-map a ]) x₁ ∎ } where component-map = λ X → record { mapping = λ x → C [ x ∘ f ] ; preserveEq = λ x₁ → ≈-composite C x₁ (refl-hom C) } HomFunctorOp : ∀ {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) (X : Obj C) → Functor.Functor (op C) Setoids HomFunctorOp C X = record { fobj = λ x → (Homsetoid C x X) ; fmapsetoid = record { mapping = λ x → record { mapping = λ x₁ → C [ x₁ ∘ x ] ; preserveEq = ≈-composite (op C) (refl-hom C) } ; preserveEq = λ x₁ x₂ → ≈-composite (op C) x₁ (refl-hom C) } ; preserveId = λ x → leftId (op C) ; preserveComp = λ x → assoc (op C) } HomNatOp : ∀ {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) {A B : Obj C} (f : Hom C A B) → Nat (HomFunctorOp C A) (HomFunctorOp C B) HomNatOp C {A} {B} f = record { component = component-map ; naturality = λ {a} {b} {x} → λ x₁ → begin⟨ C ⟩ Map.mapping (Setoids [ component-map b ∘ fmap (HomFunctorOp C A) x ]) x₁ ≈⟨ refl-hom C ⟩ C [ f ∘ C [ x₁ ∘ x ] ] ≈⟨ sym-hom C (assoc C) ⟩ C [ C [ f ∘ x₁ ] ∘ x ] ≈⟨ refl-hom C ⟩ Map.mapping (Setoids [ fmap (HomFunctorOp C B) x ∘ component-map a ]) x₁ ∎ } where component-map = λ X → record { mapping = λ x → C [ f ∘ x ] ; preserveEq = λ x₁ → ≈-composite C (refl-hom C) x₁ } FunCat : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} → (Category C₀ C₁ ℓ) → (Category D₀ D₁ ℓ′) → Category _ _ _ FunCat C D = record { Obj = Functor.Functor C D; Homsetoid = λ F G → record { Carrier = Nat F G ; _≈_ = equality ; isEquivalence = record { refl = λ {x} {a} → refl-hom D ; sym = λ x → λ {a} → sym-hom D x ; trans = λ x x₁ → λ {a} → trans-hom D x x₁ } }; comp = compose; id = λ {A} → identity A; leftId = λ {A} {B} {f} {a} → leftId D; rightId = λ {A} {B} {f} {a} → rightId D; assoc = λ {A} {B} {C₁} {D₁} {f} {g} {h} {a} → assoc D; ≈-composite = λ x x₁ → ≈-composite D x x₁ } assocNat→ : ∀{B₀ B₁ ℓ‴ C₀ C₁ ℓ D₀ D₁ ℓ′ E₀ E₁ ℓ″} {B : Category B₀ B₁ ℓ‴} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {E : Category E₀ E₁ ℓ″} {F : Functor.Functor B C} {G : Functor.Functor C D} {H : Functor.Functor D E} → Nat (Functor.compose (Functor.compose H G) F) (Functor.compose H (Functor.compose G F)) assocNat→ {C = C} {D} {E} {F} = record { component = λ X → id E ; naturality = λ {a} {b} {f} → trans-hom E (leftId E) (sym-hom E (rightId E)) } assocNat← : ∀{B₀ B₁ ℓ‴ C₀ C₁ ℓ D₀ D₁ ℓ′ E₀ E₁ ℓ″} {B : Category B₀ B₁ ℓ‴} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {E : Category E₀ E₁ ℓ″} {F : Functor.Functor B C} {G : Functor.Functor C D} {H : Functor.Functor D E} → Nat (Functor.compose H (Functor.compose G F)) (Functor.compose (Functor.compose H G) F) assocNat← {C = C} {D} {E} {F} = record { component = λ X → id E ; naturality = λ {a} {b} {f} → trans-hom E (leftId E) (sym-hom E (rightId E)) } leftIdNat→ : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} → Nat (Functor.compose (Functor.identity D) F) F leftIdNat→ {C = C} {D} {F} = record { component = λ X → id D ; naturality = λ {a} {b} {f} → trans-hom D (leftId D) (sym-hom D (rightId D)) } leftIdNat← : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} → Nat F (Functor.compose (Functor.identity D) F) leftIdNat← {C = C} {D} {F} = record { component = λ X → id D ; naturality = λ {a} {b} {f} → trans-hom D (leftId D) (sym-hom D (rightId D)) } rightIdNat→ : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} → Nat (Functor.compose F (Functor.identity C)) F rightIdNat→ {C = C} {D} {F} = record { component = λ X → id D ; naturality = λ {a} {b} {f} → trans-hom D (leftId D) (sym-hom D (rightId D)) } rightIdNat← : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} → Nat F (Functor.compose F (Functor.identity C)) rightIdNat← {C = C} {D} {F} = record { component = λ X → id D ; naturality = λ {a} {b} {f} → trans-hom D (leftId D) (sym-hom D (rightId D)) } module Export where infixl 6 _F∘N_ _N∘F_ _F∘N_ = composeFN _N∘F_ = composeNF Hom[_][_,-] = HomFunctor Hom[_][-,_] = HomFunctorOp HomNat[_][_,-] = HomNat HomNat[_][-,_] = HomNatOp [_,_] : ∀{C₀ C₁ ℓ D₀ D₁ ℓ′} (C : Category C₀ C₁ ℓ) → (D : Category D₀ D₁ ℓ′) → Category _ _ _ [_,_] = FunCat PSh[_] : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) → Category _ _ _ PSh[_] {_} {C₁} {ℓ} C = [ op C , Setoids {C₁} {ℓ} ]
50.260606
312
0.568311
570b2d81b6460a5ee6200973f293205731aa9bd7
3,961
agda
Agda
test/asset/agda-stdlib-1.0/Function/LeftInverse.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
test/asset/agda-stdlib-1.0/Function/LeftInverse.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Function/LeftInverse.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Left inverses ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Function.LeftInverse where open import Data.Product open import Level import Relation.Binary.Reasoning.Setoid as EqReasoning open import Relation.Binary open import Function.Equality as Eq using (_⟶_; _⟨$⟩_) renaming (_∘_ to _⟪∘⟫_) open import Function.Equivalence using (Equivalence) open import Function.Injection using (Injective; Injection) open import Relation.Binary.PropositionalEquality as P using (_≡_) ------------------------------------------------------------------------ -- Left and right inverses. _LeftInverseOf_ : ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} → To ⟶ From → From ⟶ To → Set _ _LeftInverseOf_ {From = From} f g = ∀ x → f ⟨$⟩ (g ⟨$⟩ x) ≈ x where open Setoid From _RightInverseOf_ : ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} → To ⟶ From → From ⟶ To → Set _ f RightInverseOf g = g LeftInverseOf f ------------------------------------------------------------------------ -- The set of all left inverses between two setoids. record LeftInverse {f₁ f₂ t₁ t₂} (From : Setoid f₁ f₂) (To : Setoid t₁ t₂) : Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where field to : From ⟶ To from : To ⟶ From left-inverse-of : from LeftInverseOf to private open module F = Setoid From open module T = Setoid To open EqReasoning From injective : Injective to injective {x} {y} eq = begin x ≈⟨ F.sym (left-inverse-of x) ⟩ from ⟨$⟩ (to ⟨$⟩ x) ≈⟨ Eq.cong from eq ⟩ from ⟨$⟩ (to ⟨$⟩ y) ≈⟨ left-inverse-of y ⟩ y ∎ injection : Injection From To injection = record { to = to; injective = injective } equivalence : Equivalence From To equivalence = record { to = to ; from = from } to-from : ∀ {x y} → to ⟨$⟩ x T.≈ y → from ⟨$⟩ y F.≈ x to-from {x} {y} to-x≈y = begin from ⟨$⟩ y ≈⟨ Eq.cong from (T.sym to-x≈y) ⟩ from ⟨$⟩ (to ⟨$⟩ x) ≈⟨ left-inverse-of x ⟩ x ∎ -- The set of all right inverses between two setoids. RightInverse : ∀ {f₁ f₂ t₁ t₂} (From : Setoid f₁ f₂) (To : Setoid t₁ t₂) → Set _ RightInverse From To = LeftInverse To From ------------------------------------------------------------------------ -- The set of all left inverses from one set to another (i.e. left -- inverses with propositional equality). -- -- Read A ↞ B as "surjection from B to A". infix 3 _↞_ _↞_ : ∀ {f t} → Set f → Set t → Set _ From ↞ To = LeftInverse (P.setoid From) (P.setoid To) leftInverse : ∀ {f t} {From : Set f} {To : Set t} → (to : From → To) (from : To → From) → (∀ x → from (to x) ≡ x) → From ↞ To leftInverse to from invˡ = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ from ; left-inverse-of = invˡ } ------------------------------------------------------------------------ -- Identity and composition. id : ∀ {s₁ s₂} {S : Setoid s₁ s₂} → LeftInverse S S id {S = S} = record { to = Eq.id ; from = Eq.id ; left-inverse-of = λ _ → Setoid.refl S } infixr 9 _∘_ _∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂} {F : Setoid f₁ f₂} {M : Setoid m₁ m₂} {T : Setoid t₁ t₂} → LeftInverse M T → LeftInverse F M → LeftInverse F T _∘_ {F = F} f g = record { to = to f ⟪∘⟫ to g ; from = from g ⟪∘⟫ from f ; left-inverse-of = λ x → begin from g ⟨$⟩ (from f ⟨$⟩ (to f ⟨$⟩ (to g ⟨$⟩ x))) ≈⟨ Eq.cong (from g) (left-inverse-of f (to g ⟨$⟩ x)) ⟩ from g ⟨$⟩ (to g ⟨$⟩ x) ≈⟨ left-inverse-of g x ⟩ x ∎ } where open LeftInverse open EqReasoning F
31.436508
109
0.485988
2158082d93cb2a806b96979d1878432f7e17b0fd
16,763
agda
Agda
Lambda/Closure/Functional/Non-deterministic/No-workarounds.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
1
2021-02-13T14:48:45.000Z
2021-02-13T14:48:45.000Z
Lambda/Closure/Functional/Non-deterministic/No-workarounds.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
Lambda/Closure/Functional/Non-deterministic/No-workarounds.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Functional semantics for a non-deterministic untyped λ-calculus -- with constants ------------------------------------------------------------------------ {-# OPTIONS --no-termination-check #-} module Lambda.Closure.Functional.Non-deterministic.No-workarounds where open import Category.Monad.Partiality as Pa using (_⊥; now; later) open import Codata.Musical.Notation open import Data.Fin using (Fin; zero; suc; #_) open import Data.List hiding (lookup) open import Data.Maybe hiding (_>>=_) open import Data.Nat open import Data.Vec using ([]; _∷_; lookup) open import Function open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Relation.Nullary open import Relation.Nullary.Decidable open import Lambda.Syntax using (Ty; Ctxt) open Lambda.Syntax.Closure using (con; ƛ) open Lambda.Syntax.Ty open import Lambda.VirtualMachine hiding (comp; comp-val; comp-env; lookup-hom) open Functional private module VM = Lambda.Syntax.Closure Code ------------------------------------------------------------------------ -- A monad with partiality, failure and non-determinism -- This is basically the maybe monad transformer applied to the -- partiality monad transformer applied to the non-determinism monad -- N A = μX. A ⊎ X × X. Unfortunately it is somewhat awkward to -- implement the partiality monad transformer in Agda: the definition -- -- data Partiality′ (M : Set → Set) (A : Set) : Set where -- now-or-later : M (A ⊎ Partiality′ M A) → Partiality′ M A -- -- is rejected, because M might use its argument negatively. infixr 6 _∣_ data D (A : Set) : Set where fail : D A return : (x : A) → D A _∣_ : (x y : D A) → D A later : (x : ∞ (D A)) → D A -- The function force n removes (up to) n layers of later -- constructors. force : {A : Set} → ℕ → D A → D A force (suc n) (later x) = force n (♭ x) force n (x₁ ∣ x₂) = force n x₁ ∣ force n x₂ force _ x = x -- Bind. infixl 5 _>>=_ _>>=_ : {A B : Set} → D A → (A → D B) → D B fail >>= f = fail return x >>= f = f x (x₁ ∣ x₂) >>= f = (x₁ >>= f) ∣ (x₂ >>= f) later x >>= f = later (♯ (♭ x >>= f)) -- A deterministic non-terminating computation. never : {A : Set} → D A never = later (♯ never) -- Strong bisimilarity. infix 4 _≅_ data _≅_ {A : Set} : D A → D A → Set where fail : fail ≅ fail return : ∀ {x} → return x ≅ return x _∣_ : ∀ {x₁ x₂ y₁ y₂} (x₁≅y₁ : x₁ ≅ y₁) (x₂≅y₂ : x₂ ≅ y₂) → x₁ ∣ x₂ ≅ y₁ ∣ y₂ later : ∀ {x y} (x≅y : ∞ (♭ x ≅ ♭ y)) → later x ≅ later y -- Strong bisimilarity is reflexive. infixr 3 _∎ _∎ : {A : Set} (x : D A) → x ≅ x fail ∎ = fail return x ∎ = return x₁ ∣ x₂ ∎ = (x₁ ∎) ∣ (x₂ ∎) later x ∎ = later (♯ (♭ x ∎)) -- Strong bisimilarity is symmetric. sym : {A : Set} {x y : D A} → x ≅ y → y ≅ x sym fail = fail sym return = return sym (x₁≅y₁ ∣ x₂≅y₂) = sym x₁≅y₁ ∣ sym x₂≅y₂ sym (later x≅y) = later (♯ sym (♭ x≅y)) -- Strong bisimilarity is transitive. infixr 2 _≅⟨_⟩_ _≅⟨_⟩_ : ∀ {A : Set} (x : D A) {y z} → x ≅ y → y ≅ z → x ≅ z ._ ≅⟨ fail ⟩ fail = fail ._ ≅⟨ return ⟩ return = return ._ ≅⟨ x₁≅y₁ ∣ x₂≅y₂ ⟩ y₁≅z₁ ∣ y₂≅z₂ = (_ ≅⟨ x₁≅y₁ ⟩ y₁≅z₁) ∣ (_ ≅⟨ x₂≅y₂ ⟩ y₂≅z₂) ._ ≅⟨ later x≅y ⟩ later y≅z = later (♯ (_ ≅⟨ ♭ x≅y ⟩ ♭ y≅z)) -- The monad laws hold up to strong bisimilarity. left-identity : {A B : Set} {x : A} {f : A → D B} → return x >>= f ≅ f x left-identity {x = x} {f} = f x ∎ right-identity : {A : Set} (x : D A) → x >>= return ≅ x right-identity fail = fail right-identity (return x) = return right-identity (x₁ ∣ x₂) = right-identity x₁ ∣ right-identity x₂ right-identity (later x) = later (♯ right-identity (♭ x)) associative : {A B C : Set} (x : D A) {f : A → D B} {g : B → D C} → x >>= f >>= g ≅ x >>= λ y → f y >>= g associative fail = fail associative (return x) {f} {g} = f x >>= g ∎ associative (x₁ ∣ x₂) = associative x₁ ∣ associative x₂ associative (later x) = later (♯ associative (♭ x)) -- Bind respects strong bisimilarity. infixl 5 _>>=-cong_ _>>=-cong_ : {A B : Set} {x₁ x₂ : D A} {f₁ f₂ : A → D B} → x₁ ≅ x₂ → (∀ y → f₁ y ≅ f₂ y) → x₁ >>= f₁ ≅ x₂ >>= f₂ fail >>=-cong f₁≅f₂ = fail return >>=-cong f₁≅f₂ = f₁≅f₂ _ later x≅y >>=-cong f₁≅f₂ = later (♯ (♭ x≅y >>=-cong f₁≅f₂)) x₁≅x₂ ∣ y₁≅y₂ >>=-cong f₁≅f₂ = (x₁≅x₂ >>=-cong f₁≅f₂) ∣ (y₁≅y₂ >>=-cong f₁≅f₂) -- More laws. never-left-zero : {A B : Set} {f : A → D B} → never >>= f ≅ never never-left-zero = later (♯ never-left-zero) fail-left-zero : {A B : Set} {f : A → D B} → fail >>= f ≅ fail fail-left-zero = fail ∎ ------------------------------------------------------------------------ -- Syntax infixl 9 _·_ data Tm (n : ℕ) : Set where con : (i : ℕ) → Tm n var : (x : Fin n) → Tm n ƛ : (t : Tm (suc n)) → Tm n _·_ : (t₁ t₂ : Tm n) → Tm n _∣_ : (t₁ t₂ : Tm n) → Tm n -- Convenient helper. vr : ∀ m {n} {m<n : True (suc m ≤? n)} → Tm n vr _ {m<n = m<n} = var (#_ _ {m<n = m<n}) open Lambda.Syntax.Closure Tm hiding (con; ƛ) ------------------------------------------------------------------------ -- Semantics infix 9 _∙_ mutual ⟦_⟧ : ∀ {n} → Tm n → Env n → D Value ⟦ con i ⟧ ρ = return (con i) ⟦ var x ⟧ ρ = return (lookup ρ x) ⟦ ƛ t ⟧ ρ = return (ƛ t ρ) ⟦ t₁ · t₂ ⟧ ρ = ⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ ⟦ t₁ ∣ t₂ ⟧ ρ = ⟦ t₁ ⟧ ρ ∣ ⟦ t₂ ⟧ ρ _∙_ : Value → Value → D Value con i ∙ v₂ = fail ƛ t₁ ρ ∙ v₂ = later (♯ (⟦ t₁ ⟧ (v₂ ∷ ρ))) -- An abbreviation. infix 9 _⟦·⟧_ _⟦·⟧_ : D Value → D Value → D Value v₁ ⟦·⟧ v₂ = v₁ >>= λ v₁ → v₂ >>= λ v₂ → v₁ ∙ v₂ ------------------------------------------------------------------------ -- Compiler -- The compiler takes a code continuation. -- -- Non-determinism is resolved by always picking the left choice. comp : ∀ {n} → Tm n → Code n → Code n comp (con i) c = con i ∷ c comp (var x) c = var x ∷ c comp (ƛ t) c = clo (comp t [ ret ]) ∷ c comp (t₁ · t₂) c = comp t₁ (comp t₂ (app ∷ c)) comp (t₁ ∣ t₂) c = comp t₁ c -- Environments and values can also be compiled. mutual comp-env : ∀ {n} → Env n → VM.Env n comp-env [] = [] comp-env (v ∷ ρ) = comp-val v ∷ comp-env ρ comp-val : Value → VM.Value comp-val (con i) = con i comp-val (ƛ t ρ) = ƛ (comp t [ ret ]) (comp-env ρ) -- lookup x is homomorphic with respect to comp-env/comp-val. lookup-hom : ∀ {n} (x : Fin n) ρ → lookup (comp-env ρ) x ≡ comp-val (lookup ρ x) lookup-hom zero (v ∷ ρ) = P.refl lookup-hom (suc x) (v ∷ ρ) = lookup-hom x ρ ------------------------------------------------------------------------ -- Examples -- A non-terminating term. Ω : Tm 0 Ω = ω · ω where ω = ƛ (vr 0 · vr 0) Ω-loops : ⟦ Ω ⟧ [] ≅ never Ω-loops = later (♯ Ω-loops) -- A call-by-value fix-point combinator. Z : {n : ℕ} → Tm n Z = ƛ (t · t) where t = ƛ (vr 1 · ƛ (vr 1 · vr 1 · vr 0)) -- A non-deterministically non-terminating term. ! : Tm 0 ! = Z · ƛ (ƛ (vr 1 · vr 0 ∣ vr 1 · vr 0)) · con 0 -- Its semantics. !-sem : D Value !-sem = later (♯ later (♯ later (♯ later (♯ (!-sem ∣ !-sem))))) ⟦!⟧≅!-sem : ⟦ ! ⟧ [] ≅ !-sem ⟦!⟧≅!-sem = later (♯ lem) where lem : force 1 (⟦ ! ⟧ []) ≅ force 1 !-sem lem = later (♯ later (♯ later (♯ (later (♯ lem) ∣ later (♯ lem))))) -- How did I come up with this proof term? Through a manual -- calculation... -- -- Let us first define some abbreviations: -- -- t₀ = vr 1 · vr 1 · vr 0 -- t₁ = ƛ t₀ -- t₂ = vr 1 · t₁ -- t₃ = ƛ t₂ -- -- u₀ = vr 1 · vr 0 -- u₁ = u₀ ∣ u₀ -- u₂ = ƛ u₁ -- u₃ = ƛ u₂ -- -- c₀ = ƛ u₂ [] -- c₁ = ƛ t₂ (c₀ ∷ []) -- c₂ = ƛ t₀ (c₁ ∷ c₀ ∷ []) -- -- Now we can calculate as follows (ignoring ♯): -- -- ⟦ Z · u₃ · con 0 ⟧ [] -- = ⟦ Z · u₃ ⟧ [] ⟦·⟧ return (con 0) -- = ƛ (t₃ · t₃) [] ∙ c₀ ⟦·⟧ return (con 0) -- = later (⟦ t₃ · t₃ ⟧ (c₀ ∷ []) ⟦·⟧ return (con 0)) -- = later (c₁ ∙ c₁ ⟦·⟧ return (con 0)) -- -- = c₁ ∙ c₁ ⟦·⟧ return (con 0) -- = later (⟦ t₂ ⟧ (c₁ ∷ c₀ ∷ []) ⟦·⟧ return (con 0)) -- = later (c₀ ∙ c₂ ⟦·⟧ return (con 0)) -- = later (later (⟦ u₂ ⟧ (c₂ ∷ []) ⟦·⟧ return (con 0))) -- = later (later (ƛ u₁ (c₂ ∷ []) ∙ con 0)) -- = later (later (later (⟦ u₁ ⟧ (con 0 ∷ c₂ ∷ [])))) -- = later (later (later (⟦ u₀ ⟧ (con 0 ∷ c₂ ∷ []) ∣ -- ⟦ u₀ ⟧ (con 0 ∷ c₂ ∷ [])))) -- = later (later (later (c₂ ∙ con 0 ∣ c₂ ∙ con 0))) -- = later (later (later (⟦ t₀ ⟧ (con 0 ∷ c₁ ∷ c₀ ∷ []) ∣ -- ⟦ t₀ ⟧ (con 0 ∷ c₁ ∷ c₀ ∷ [])))) -- = later (later (later (later (c₁ ∙ c₁ ⟦·⟧ return (con 0)) ∣ -- later (c₁ ∙ c₁ ⟦·⟧ return (con 0))))) ------------------------------------------------------------------------ -- A relation relating deterministic and non-deterministic -- computations -- x ≈∈ y means that x implements /one/ possible semantics of y (up to -- weak bisimilarity). infix 4 _≈∈_ data _≈∈_ {A : Set} : Maybe A ⊥ → D A → Set where fail : now nothing ≈∈ fail return : ∀ {x} → now (just x) ≈∈ return x ∣ˡ : ∀ {x y₁ y₂} (x≈∈y₁ : x ≈∈ y₁) → x ≈∈ y₁ ∣ y₂ ∣ʳ : ∀ {x y₁ y₂} (x≈∈y₂ : x ≈∈ y₂) → x ≈∈ y₁ ∣ y₂ later : ∀ {x y} (x≈∈y : ∞ (♭ x ≈∈ ♭ y)) → later x ≈∈ later y laterˡ : ∀ {x y} (x≈∈y : ♭ x ≈∈ y ) → later x ≈∈ y laterʳ : ∀ {x y} (x≈∈y : x ≈∈ ♭ y ) → x ≈∈ later y -- A transitivity-like result for _≡_ and _≈∈_. infixr 2 _≡⟨_⟩_ _≡⟨_⟩_ : ∀ {A : Set} (x : Maybe A ⊥) {y z} → x ≡ y → y ≈∈ z → x ≈∈ z _ ≡⟨ P.refl ⟩ y≈z = y≈z -- A transitivity-like result for _≈∈_ and _≅_. infixr 2 _≈∈⟨_⟩_ _≈∈⟨_⟩_ : ∀ {A : Set} (x : Maybe A ⊥) {y z} → x ≈∈ y → y ≅ z → x ≈∈ z ._ ≈∈⟨ fail ⟩ fail = fail ._ ≈∈⟨ return ⟩ return = return _ ≈∈⟨ ∣ˡ x₁≈∈y₁ ⟩ y₁≅z₁ ∣ y₂≅z₂ = ∣ˡ (_ ≈∈⟨ x₁≈∈y₁ ⟩ y₁≅z₁) _ ≈∈⟨ ∣ʳ x₂≈∈y₂ ⟩ y₁≅z₁ ∣ y₂≅z₂ = ∣ʳ (_ ≈∈⟨ x₂≈∈y₂ ⟩ y₂≅z₂) ._ ≈∈⟨ later x≈∈y ⟩ later y≅z = later (♯ (_ ≈∈⟨ ♭ x≈∈y ⟩ ♭ y≅z)) ._ ≈∈⟨ laterˡ x≈∈y ⟩ y≅z = laterˡ (_ ≈∈⟨ x≈∈y ⟩ y≅z) _ ≈∈⟨ laterʳ x≈∈y ⟩ later y≅z = laterʳ (_ ≈∈⟨ x≈∈y ⟩ ♭ y≅z) -- An example. lemma : Pa.never ≈∈ !-sem lemma = later (♯ later (♯ later (♯ later (♯ ∣ˡ lemma)))) ------------------------------------------------------------------------ -- Compiler correctness module Correctness where mutual correct : ∀ {n} t {ρ : Env n} {c s} {k : Value → D VM.Value} → (∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈∈ k v) → exec ⟨ comp t c , s , comp-env ρ ⟩ ≈∈ (⟦ t ⟧ ρ >>= k) correct (con i) {ρ} {c} {s} {k} hyp = laterˡ ( exec ⟨ c , val (con i) ∷ s , comp-env ρ ⟩ ≈∈⟨ hyp (con i) ⟩ k (con i) ∎) correct (var x) {ρ} {c} {s} {k} hyp = laterˡ ( exec ⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → exec ⟨ c , val v ∷ s , comp-env ρ ⟩) (lookup-hom x ρ) ⟩ exec ⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ≈∈⟨ hyp (lookup ρ x) ⟩ k (lookup ρ x) ∎) correct (ƛ t) {ρ} {c} {s} {k} hyp = laterˡ ( exec ⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≈∈⟨ hyp (ƛ t ρ) ⟩ k (ƛ t ρ) ∎) correct (t₁ · t₂) {ρ} {c} {s} {k} hyp = exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≈∈⟨ correct t₁ (λ v₁ → correct t₂ (λ v₂ → ∙-correct v₁ v₂ hyp)) ⟩ (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ≅⟨ ((⟦ t₁ ⟧ ρ ∎) >>=-cong λ _ → sym $ associative (⟦ t₂ ⟧ ρ)) ⟩ (⟦ t₁ ⟧ ρ >>= λ v₁ → (⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂) >>= k) ≅⟨ sym $ associative (⟦ t₁ ⟧ ρ) ⟩ (⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ >>= k) ≅⟨ _ ∎ ⟩ (⟦ t₁ · t₂ ⟧ ρ >>= k) ∎ correct (t₁ ∣ t₂) {ρ} {c} {s} {k} hyp = exec ⟨ comp t₁ c , s , comp-env ρ ⟩ ≈∈⟨ ∣ˡ (correct t₁ hyp) ⟩ (⟦ t₁ ⟧ ρ >>= k) ∣ (⟦ t₂ ⟧ ρ >>= k) ∎ ∙-correct : ∀ {n} v₁ v₂ {ρ : Env n} {c s} {k : Value → D VM.Value} → (∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈∈ k v) → exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , comp-env ρ ⟩ ≈∈ v₁ ∙ v₂ >>= k ∙-correct (con i) v₂ _ = fail ∙-correct (ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp = exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ≈∈⟨ later (♯ ( exec ⟨ comp t₁ [ ret ] , ret c (comp-env ρ) ∷ s , comp-env (v₂ ∷ ρ₁) ⟩ ≈∈⟨ correct t₁ (λ v → laterˡ (hyp v)) ⟩ (⟦ t₁ ⟧ (v₂ ∷ ρ₁) >>= k) ∎)) ⟩ (ƛ t₁ ρ₁ ∙ v₂ >>= k) ∎ correct : ∀ t → exec ⟨ comp t [] , [] , [] ⟩ ≈∈ ⟦ t ⟧ [] >>= λ v → return (comp-val v) correct t = Correctness.correct t (λ _ → return) ------------------------------------------------------------------------ -- Type system (following Leroy and Grall) infix 4 _⊢_∈_ data _⊢_∈_ {n} (Γ : Ctxt n) : Tm n → Ty → Set where con : ∀ {i} → Γ ⊢ con i ∈ nat var : ∀ {x} → Γ ⊢ var x ∈ lookup Γ x ƛ : ∀ {t σ τ} (t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) → Γ ⊢ ƛ t ∈ σ ⇾ τ _·_ : ∀ {t₁ t₂ σ τ} (t₁∈ : Γ ⊢ t₁ ∈ σ ⇾ τ) (t₂∈ : Γ ⊢ t₂ ∈ ♭ σ) → Γ ⊢ t₁ · t₂ ∈ ♭ τ _∣_ : ∀ {t₁ t₂ σ} (t₁∈ : Γ ⊢ t₁ ∈ σ) (t₂∈ : Γ ⊢ t₂ ∈ σ) → Γ ⊢ t₁ ∣ t₂ ∈ σ -- Ω is well-typed. Ω-well-typed : (τ : Ty) → [] ⊢ Ω ∈ τ Ω-well-typed τ = _·_ {σ = ♯ σ} {τ = ♯ τ} (ƛ (var · var)) (ƛ (var · var)) where σ = ♯ σ ⇾ ♯ τ -- The call-by-value fix-point combinator is also well-typed. fix-well-typed : ∀ {σ τ} → [] ⊢ Z ∈ ♯ (♯ (σ ⇾ τ) ⇾ ♯ (σ ⇾ τ)) ⇾ ♯ (σ ⇾ τ) fix-well-typed = ƛ (_·_ {σ = υ} {τ = ♯ _} (ƛ (var · ƛ (var · var · var))) (ƛ (var · ƛ (var · var · var)))) where υ : ∞ Ty υ = ♯ (υ ⇾ ♯ _) ------------------------------------------------------------------------ -- Type soundness -- WF-Value, WF-Env and WF-DV specify when a -- value/environment/computation is well-formed with respect to a -- given context (and type). mutual data WF-Value : Ty → Value → Set where con : ∀ {i} → WF-Value nat (con i) ƛ : ∀ {n Γ σ τ} {t : Tm (1 + n)} {ρ} (t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) (ρ-wf : WF-Env Γ ρ) → WF-Value (σ ⇾ τ) (ƛ t ρ) infixr 5 _∷_ data WF-Env : ∀ {n} → Ctxt n → Env n → Set where [] : WF-Env [] [] _∷_ : ∀ {n} {Γ : Ctxt n} {ρ σ v} (v-wf : WF-Value σ v) (ρ-wf : WF-Env Γ ρ) → WF-Env (σ ∷ Γ) (v ∷ ρ) data WF-DV (σ : Ty) : D Value → Set where return : ∀ {v} (v-wf : WF-Value σ v) → WF-DV σ (return v) _∣_ : ∀ {x y} (x-wf : WF-DV σ x) (y-wf : WF-DV σ y) → WF-DV σ (x ∣ y) later : ∀ {x} (x-wf : ∞ (WF-DV σ (♭ x))) → WF-DV σ (later x) -- Variables pointing into a well-formed environment refer to -- well-formed values. lookup-wf : ∀ {n Γ ρ} (x : Fin n) → WF-Env Γ ρ → WF-Value (lookup Γ x) (lookup ρ x) lookup-wf zero (v-wf ∷ ρ-wf) = v-wf lookup-wf (suc x) (v-wf ∷ ρ-wf) = lookup-wf x ρ-wf -- If we can prove WF-DV σ x, then x does not "go wrong". does-not-go-wrong : ∀ {σ x} → WF-DV σ x → ¬ now nothing ≈∈ x does-not-go-wrong (return v-wf) () does-not-go-wrong (x-wf ∣ y-wf) (∣ˡ x↯) = does-not-go-wrong x-wf x↯ does-not-go-wrong (x-wf ∣ y-wf) (∣ʳ y↯) = does-not-go-wrong y-wf y↯ does-not-go-wrong (later x-wf) (laterʳ x↯) = does-not-go-wrong (♭ x-wf) x↯ -- Bind preserves WF-DV in the following way: _>>=-cong-WF_ : ∀ {σ τ x f} → WF-DV σ x → (∀ {v} → WF-Value σ v → WF-DV τ (f v)) → WF-DV τ (x >>= f) return v-wf >>=-cong-WF f-wf = f-wf v-wf (x-wf ∣ y-wf) >>=-cong-WF f-wf = (x-wf >>=-cong-WF f-wf) ∣ (y-wf >>=-cong-WF f-wf) later x-wf >>=-cong-WF f-wf = later (♯ (♭ x-wf >>=-cong-WF f-wf)) -- Well-typed programs do not "go wrong". mutual ⟦⟧-wf : ∀ {n Γ} (t : Tm n) {σ} → Γ ⊢ t ∈ σ → ∀ {ρ} → WF-Env Γ ρ → WF-DV σ (⟦ t ⟧ ρ) ⟦⟧-wf (con i) con ρ-wf = return con ⟦⟧-wf (var x) var ρ-wf = return (lookup-wf x ρ-wf) ⟦⟧-wf (ƛ t) (ƛ t∈) ρ-wf = return (ƛ t∈ ρ-wf) ⟦⟧-wf (t₁ ∣ t₂) (t₁∈ ∣ t₂∈) ρ-wf = ⟦⟧-wf t₁ t₁∈ ρ-wf ∣ ⟦⟧-wf t₂ t₂∈ ρ-wf ⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) {ρ} ρ-wf = ⟦⟧-wf t₁ t₁∈ ρ-wf >>=-cong-WF λ f-wf → ⟦⟧-wf t₂ t₂∈ ρ-wf >>=-cong-WF λ v-wf → ∙-wf f-wf v-wf ∙-wf : ∀ {σ τ f v} → WF-Value (σ ⇾ τ) f → WF-Value (♭ σ) v → WF-DV (♭ τ) (f ∙ v) ∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf = later (♯ ⟦⟧-wf _ t₁∈ (v₂-wf ∷ ρ₁-wf)) type-soundness : ∀ {t : Tm 0} {σ} → [] ⊢ t ∈ σ → ¬ now nothing ≈∈ ⟦ t ⟧ [] type-soundness t∈ = does-not-go-wrong (⟦⟧-wf _ t∈ [])
32.423598
137
0.45326
58cc47d828d3cf479d56e1c0823b4d7d35229879
877
agda
Agda
Cubical/Data/NatMinusTwo/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Data/NatMinusTwo/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Data/NatMinusTwo/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-exact-split --safe #-} module Cubical.Data.NatMinusTwo.Base where open import Cubical.Core.Primitives open import Cubical.Data.Nat open import Cubical.Data.Empty record ℕ₋₂ : Type₀ where constructor -2+_ field n : ℕ pattern neg2 = -2+ zero pattern neg1 = -2+ (suc zero) pattern ℕ→ℕ₋₂ n = -2+ (suc (suc n)) pattern -1+_ n = -2+ (suc n) 2+_ : ℕ₋₂ → ℕ 2+ (-2+ n) = n suc₋₂ : ℕ₋₂ → ℕ₋₂ suc₋₂ (-2+ n) = -2+ (suc n) -- Natural number and negative integer literals for ℕ₋₂ open import Cubical.Data.Nat.Literals public instance fromNatℕ₋₂ : HasFromNat ℕ₋₂ fromNatℕ₋₂ = record { Constraint = λ _ → Unit ; fromNat = ℕ→ℕ₋₂ } instance fromNegℕ₋₂ : HasFromNeg ℕ₋₂ fromNegℕ₋₂ = record { Constraint = λ { (suc (suc (suc _))) → ⊥ ; _ → Unit } ; fromNeg = λ { zero → 0 ; (suc zero) → neg1 ; (suc (suc zero)) → neg2 } }
24.361111
97
0.619156
03106a480cad0c6309ac6c51045cd7f78739a526
2,679
agda
Agda
Cubical/Structures/Relational/Product.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Structures/Relational/Product.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Structures/Relational/Product.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{- Product of structures S and T: X ↦ S X × T X -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Structures.Relational.Product where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Foundations.RelationalStructure open import Cubical.Foundations.SIP open import Cubical.Foundations.Univalence open import Cubical.Data.Sigma open import Cubical.HITs.SetQuotients open import Cubical.Structures.Product private variable ℓ ℓ₁ ℓ₁' ℓ₂ ℓ₂' : Level -- Structured relations preservesSetsProduct : {S₁ : Type ℓ → Type ℓ₁} {S₂ : Type ℓ → Type ℓ₂} → preservesSets S₁ → preservesSets S₂ → preservesSets (ProductStructure S₁ S₂) preservesSetsProduct p₁ p₂ setX = isSet× (p₁ setX) (p₂ setX) ProductRelStr : {S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁') {S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂') → StrRel (ProductStructure S₁ S₂) (ℓ-max ℓ₁' ℓ₂') ProductRelStr ρ₁ ρ₂ R (s₁ , s₂) (t₁ , t₂) = ρ₁ R s₁ t₁ × ρ₂ R s₂ t₂ open SuitableStrRel productSuitableRel : {S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'} {S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'} → SuitableStrRel S₁ ρ₁ → SuitableStrRel S₂ ρ₂ → SuitableStrRel (ProductStructure S₁ S₂) (ProductRelStr ρ₁ ρ₂) productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .fst .fst = θ₁ .quo (X , s₁) R r₁ .fst .fst , θ₂ .quo (X , s₂) R r₂ .fst .fst productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .fst .snd = θ₁ .quo (X , s₁) R r₁ .fst .snd , θ₂ .quo (X , s₂) R r₂ .fst .snd productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .snd ((q₁ , q₂) , (c₁ , c₂)) i .fst = θ₁ .quo (X , s₁) R r₁ .snd (q₁ , c₁) i .fst , θ₂ .quo (X , s₂) R r₂ .snd (q₂ , c₂) i .fst productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .snd ((q₁ , q₂) , (c₁ , c₂)) i .snd = θ₁ .quo (X , s₁) R r₁ .snd (q₁ , c₁) i .snd , θ₂ .quo (X , s₂) R r₂ .snd (q₂ , c₂) i .snd productSuitableRel θ₁ θ₂ .symmetric R (r₁ , r₂) = θ₁ .symmetric R r₁ , θ₂ .symmetric R r₂ productSuitableRel θ₁ θ₂ .transitive R R' (r₁ , r₂) (r₁' , r₂') = θ₁ .transitive R R' r₁ r₁' , θ₂ .transitive R R' r₂ r₂' productSuitableRel θ₁ θ₂ .prop propR (s₁ , s₂) (t₁ , t₂) = isProp× (θ₁ .prop propR s₁ t₁) (θ₂ .prop propR s₂ t₂) productRelMatchesEquiv : {S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁') {ι₁ : StrEquiv S₁ ℓ₁'} {S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂') {ι₂ : StrEquiv S₂ ℓ₂'} → StrRelMatchesEquiv ρ₁ ι₁ → StrRelMatchesEquiv ρ₂ ι₂ → StrRelMatchesEquiv (ProductRelStr ρ₁ ρ₂) (ProductEquivStr ι₁ ι₂) productRelMatchesEquiv ρ₁ ρ₂ μ₁ μ₂ A B e = Σ-cong-equiv (μ₁ _ _ e) (λ _ → μ₂ _ _ e)
39.985075
93
0.662187
2ea1a5f038cc03043aae2d312093de28a5fd66b7
10,635
agda
Agda
Cubical/Algebra/RingSolver/EvaluationHomomorphism.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Algebra/RingSolver/EvaluationHomomorphism.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Algebra/RingSolver/EvaluationHomomorphism.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.RingSolver.EvaluationHomomorphism where open import Cubical.Foundations.Prelude open import Cubical.Data.Nat using (ℕ) open import Cubical.Data.FinData open import Cubical.Data.Vec open import Cubical.Algebra.RingSolver.RawRing open import Cubical.Algebra.RingSolver.AlmostRing renaming (⟨_⟩ to ⟨_⟩ᵣ) open import Cubical.Algebra.RingSolver.HornerForms private variable ℓ : Level module HomomorphismProperties (R : AlmostRing {ℓ}) where private νR = AlmostRing→RawRing R open AlmostRing R open Theory R open IteratedHornerOperations νR evalHom+0 : (n : ℕ) (P : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n) → eval n (0ₕ +ₕ P) xs ≡ eval n P xs evalHom+0 ℕ.zero (const x) [] = +Lid _ evalHom+0 (ℕ.suc n) P xs = refl eval0H : (n : ℕ) (xs : Vec ⟨ νR ⟩ n) → eval {R = νR} n 0ₕ xs ≡ 0r eval0H .ℕ.zero [] = refl eval0H .(ℕ.suc _) (x ∷ xs) = refl eval1ₕ : (n : ℕ) (xs : Vec ⟨ νR ⟩ n) → eval {R = νR} n 1ₕ xs ≡ 1r eval1ₕ .ℕ.zero [] = refl eval1ₕ (ℕ.suc n) (x ∷ xs) = eval (ℕ.suc n) 1ₕ (x ∷ xs) ≡⟨ refl ⟩ eval (ℕ.suc n) (0H ·X+ 1ₕ) (x ∷ xs) ≡⟨ refl ⟩ eval {R = νR} (ℕ.suc n) 0H (x ∷ xs) · x + eval n 1ₕ xs ≡⟨ cong (λ u → u · x + eval n 1ₕ xs) (eval0H _ (x ∷ xs)) ⟩ 0r · x + eval n 1ₕ xs ≡⟨ cong (λ u → 0r · x + u) (eval1ₕ _ xs) ⟩ 0r · x + 1r ≡⟨ cong (λ u → u + 1r) (0LeftAnnihilates _) ⟩ 0r + 1r ≡⟨ +Lid _ ⟩ 1r ∎ -evalDist : (n : ℕ) (P : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n) → eval n (-ₕ P) xs ≡ - eval n P xs -evalDist .ℕ.zero (const x) [] = refl -evalDist n 0H xs = eval n (-ₕ 0H) xs ≡⟨ eval0H n xs ⟩ 0r ≡⟨ sym 0IsSelfinverse ⟩ - 0r ≡⟨ cong -_ (sym (eval0H n xs)) ⟩ - eval n 0H xs ∎ -evalDist .(ℕ.suc _) (P ·X+ Q) (x ∷ xs) = eval (ℕ.suc _) (-ₕ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩ eval (ℕ.suc _) ((-ₕ P) ·X+ (-ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩ (eval (ℕ.suc _) (-ₕ P) (x ∷ xs)) · x + eval _ (-ₕ Q) xs ≡⟨ cong (λ u → u · x + eval _ (-ₕ Q) xs) (-evalDist _ P _) ⟩ (- eval (ℕ.suc _) P (x ∷ xs)) · x + eval _ (-ₕ Q) xs ≡⟨ cong (λ u → (- eval (ℕ.suc _) P (x ∷ xs)) · x + u) (-evalDist _ Q _) ⟩ (- eval (ℕ.suc _) P (x ∷ xs)) · x + - eval _ Q xs ≡⟨ cong (λ u → u + - eval _ Q xs) (sym (-Comm· _ _)) ⟩ - (eval (ℕ.suc _) P (x ∷ xs)) · x + - eval _ Q xs ≡⟨ sym (-Dist+ _ _) ⟩ - ((eval (ℕ.suc _) P (x ∷ xs)) · x + eval _ Q xs) ≡⟨ refl ⟩ - eval (ℕ.suc _) (P ·X+ Q) (x ∷ xs) ∎ +Homeval : (n : ℕ) (P Q : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n) → eval n (P +ₕ Q) xs ≡ (eval n P xs) + (eval n Q xs) +Homeval .ℕ.zero (const x) (const y) [] = refl +Homeval n 0H Q xs = eval n (0H +ₕ Q) xs ≡⟨ refl ⟩ eval n Q xs ≡⟨ sym (+Lid _) ⟩ 0r + eval n Q xs ≡⟨ cong (λ u → u + eval n Q xs) (sym (eval0H n xs)) ⟩ eval n 0H xs + eval n Q xs ∎ +Homeval .(ℕ.suc _) (P ·X+ Q) 0H xs = eval (ℕ.suc _) ((P ·X+ Q) +ₕ 0H) xs ≡⟨ refl ⟩ eval (ℕ.suc _) (P ·X+ Q) xs ≡⟨ sym (+Rid _) ⟩ eval (ℕ.suc _) (P ·X+ Q) xs + 0r ≡⟨ cong (λ u → eval (ℕ.suc _) (P ·X+ Q) xs + u) (sym (eval0H _ xs)) ⟩ eval (ℕ.suc _) (P ·X+ Q) xs + eval (ℕ.suc _) 0H xs ∎ +Homeval .(ℕ.suc _) (P ·X+ Q) (S ·X+ T) (x ∷ xs) = eval (ℕ.suc _) ((P ·X+ Q) +ₕ (S ·X+ T)) (x ∷ xs) ≡⟨ refl ⟩ eval (ℕ.suc _) ((P +ₕ S) ·X+ (Q +ₕ T)) (x ∷ xs) ≡⟨ refl ⟩ (eval (ℕ.suc _) (P +ₕ S) (x ∷ xs)) · x + eval _ (Q +ₕ T) xs ≡⟨ cong (λ u → (eval (ℕ.suc _) (P +ₕ S) (x ∷ xs)) · x + u) (+Homeval _ Q T xs) ⟩ (eval (ℕ.suc _) (P +ₕ S) (x ∷ xs)) · x + (eval _ Q xs + eval _ T xs) ≡⟨ cong (λ u → u · x + (eval _ Q xs + eval _ T xs)) (+Homeval (ℕ.suc _) P S (x ∷ xs)) ⟩ (eval (ℕ.suc _) P (x ∷ xs) + eval (ℕ.suc _) S (x ∷ xs)) · x + (eval _ Q xs + eval _ T xs) ≡⟨ cong (λ u → u + (eval _ Q xs + eval _ T xs)) (·DistL+ _ _ _) ⟩ (eval (ℕ.suc _) P (x ∷ xs)) · x + (eval (ℕ.suc _) S (x ∷ xs)) · x + (eval _ Q xs + eval _ T xs) ≡⟨ +ShufflePairs _ _ _ _ ⟩ ((eval (ℕ.suc _) P (x ∷ xs)) · x + eval _ Q xs) + ((eval (ℕ.suc _) S (x ∷ xs)) · x + eval _ T xs) ≡⟨ refl ⟩ eval (ℕ.suc _) (P ·X+ Q) (x ∷ xs) + eval (ℕ.suc _) (S ·X+ T) (x ∷ xs) ∎ ⋆Homeval : (n : ℕ) (r : IteratedHornerForms νR n) (P : IteratedHornerForms νR (ℕ.suc n)) (x : ⟨ νR ⟩) (xs : Vec ⟨ νR ⟩ n) → eval (ℕ.suc n) (r ⋆ P) (x ∷ xs) ≡ eval n r xs · eval (ℕ.suc n) P (x ∷ xs) ⋆0LeftAnnihilates : (n : ℕ) (P : IteratedHornerForms νR (ℕ.suc n)) (xs : Vec ⟨ νR ⟩ (ℕ.suc n)) → eval (ℕ.suc n) (0ₕ ⋆ P) xs ≡ 0r ·Homeval : (n : ℕ) (P Q : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n) → eval n (P ·ₕ Q) xs ≡ (eval n P xs) · (eval n Q xs) ⋆0LeftAnnihilates n 0H xs = eval0H (ℕ.suc n) xs ⋆0LeftAnnihilates n (P ·X+ Q) (x ∷ xs) = eval (ℕ.suc n) (0ₕ ⋆ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩ eval (ℕ.suc n) ((0ₕ ⋆ P) ·X+ (0ₕ ·ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩ (eval (ℕ.suc n) (0ₕ ⋆ P) (x ∷ xs)) · x + eval n (0ₕ ·ₕ Q) xs ≡⟨ cong (λ u → (u · x) + eval _ (0ₕ ·ₕ Q) _) (⋆0LeftAnnihilates n P (x ∷ xs)) ⟩ 0r · x + eval n (0ₕ ·ₕ Q) xs ≡⟨ cong (λ u → u + eval _ (0ₕ ·ₕ Q) _) (0LeftAnnihilates _) ⟩ 0r + eval n (0ₕ ·ₕ Q) xs ≡⟨ +Lid _ ⟩ eval n (0ₕ ·ₕ Q) xs ≡⟨ ·Homeval n 0ₕ Q _ ⟩ eval n 0ₕ xs · eval n Q xs ≡⟨ cong (λ u → u · eval n Q xs) (eval0H _ xs) ⟩ 0r · eval n Q xs ≡⟨ 0LeftAnnihilates _ ⟩ 0r ∎ ⋆Homeval n r 0H x xs = eval (ℕ.suc n) (r ⋆ 0H) (x ∷ xs) ≡⟨ refl ⟩ 0r ≡⟨ sym (0RightAnnihilates _) ⟩ eval n r xs · 0r ≡⟨ refl ⟩ eval n r xs · eval {R = νR} (ℕ.suc n) 0H (x ∷ xs) ∎ ⋆Homeval n r (P ·X+ Q) x xs = eval (ℕ.suc n) (r ⋆ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩ eval (ℕ.suc n) ((r ⋆ P) ·X+ (r ·ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩ (eval (ℕ.suc n) (r ⋆ P) (x ∷ xs)) · x + eval n (r ·ₕ Q) xs ≡⟨ cong (λ u → u · x + eval n (r ·ₕ Q) xs) (⋆Homeval n r P x xs) ⟩ (eval n r xs · eval (ℕ.suc n) P (x ∷ xs)) · x + eval n (r ·ₕ Q) xs ≡⟨ cong (λ u → (eval n r xs · eval (ℕ.suc n) P (x ∷ xs)) · x + u) (·Homeval n r Q xs) ⟩ (eval n r xs · eval (ℕ.suc n) P (x ∷ xs)) · x + eval n r xs · eval n Q xs ≡⟨ cong (λ u → u + eval n r xs · eval n Q xs) (sym (·Assoc _ _ _)) ⟩ eval n r xs · (eval (ℕ.suc n) P (x ∷ xs) · x) + eval n r xs · eval n Q xs ≡⟨ sym (·DistR+ _ _ _) ⟩ eval n r xs · ((eval (ℕ.suc n) P (x ∷ xs) · x) + eval n Q xs) ≡⟨ refl ⟩ eval n r xs · eval (ℕ.suc n) (P ·X+ Q) (x ∷ xs) ∎ combineCases : (n : ℕ) (Q : IteratedHornerForms νR n) (P S : IteratedHornerForms νR (ℕ.suc n)) (xs : Vec ⟨ νR ⟩ (ℕ.suc n)) → eval (ℕ.suc n) ((P ·X+ Q) ·ₕ S) xs ≡ eval (ℕ.suc n) (((P ·ₕ S) ·X+ 0ₕ) +ₕ (Q ⋆ S)) xs combineCases n Q P S (x ∷ xs) with (P ·ₕ S) ... | 0H = eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ sym (+Lid _) ⟩ 0r + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ cong (λ u → u + eval _ (Q ⋆ S) (x ∷ xs)) lemma ⟩ eval (ℕ.suc n) (0H ·X+ 0ₕ) (x ∷ xs) + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ sym (+Homeval (ℕ.suc n) (0H ·X+ 0ₕ) (Q ⋆ S) (x ∷ xs)) ⟩ eval (ℕ.suc n) ((0H ·X+ 0ₕ) +ₕ (Q ⋆ S)) (x ∷ xs) ∎ where lemma : 0r ≡ eval (ℕ.suc n) (0H ·X+ 0ₕ) (x ∷ xs) lemma = 0r ≡⟨ sym (+Rid _) ⟩ 0r + 0r ≡⟨ cong (λ u → u + 0r) (sym (0LeftAnnihilates _)) ⟩ 0r · x + 0r ≡⟨ cong (λ u → 0r · x + u) (sym (eval0H _ xs)) ⟩ 0r · x + eval n 0ₕ xs ≡⟨ cong (λ u → u · x + eval n 0ₕ xs) (sym (eval0H _ (x ∷ xs))) ⟩ eval {R = νR} (ℕ.suc n) 0H (x ∷ xs) · x + eval n 0ₕ xs ≡⟨ refl ⟩ eval (ℕ.suc n) (0H ·X+ 0ₕ) (x ∷ xs) ∎ ... | (_ ·X+ _) = refl ·Homeval .ℕ.zero (const x) (const y) [] = refl ·Homeval (ℕ.suc n) 0H Q xs = eval (ℕ.suc n) (0H ·ₕ Q) xs ≡⟨ eval0H _ xs ⟩ 0r ≡⟨ sym (0LeftAnnihilates _) ⟩ 0r · eval (ℕ.suc n) Q xs ≡⟨ cong (λ u → u · eval _ Q xs) (sym (eval0H _ xs)) ⟩ eval (ℕ.suc n) 0H xs · eval (ℕ.suc n) Q xs ∎ ·Homeval (ℕ.suc n) (P ·X+ Q) S (x ∷ xs) = eval (ℕ.suc n) ((P ·X+ Q) ·ₕ S) (x ∷ xs) ≡⟨ combineCases n Q P S (x ∷ xs) ⟩ eval (ℕ.suc n) (((P ·ₕ S) ·X+ 0ₕ) +ₕ (Q ⋆ S)) (x ∷ xs) ≡⟨ +Homeval (ℕ.suc n) ((P ·ₕ S) ·X+ 0ₕ) (Q ⋆ S) (x ∷ xs) ⟩ eval (ℕ.suc n) ((P ·ₕ S) ·X+ 0ₕ) (x ∷ xs) + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ refl ⟩ (eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + eval n 0ₕ xs) + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ cong (λ u → u + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs)) ((eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + eval n 0ₕ xs) ≡⟨ cong (λ u → eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + u) (eval0H _ xs) ⟩ (eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + 0r) ≡⟨ +Rid _ ⟩ (eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x) ≡⟨ cong (λ u → u · x) (·Homeval (ℕ.suc n) P S (x ∷ xs)) ⟩ ((eval (ℕ.suc n) P (x ∷ xs) · eval (ℕ.suc n) S (x ∷ xs)) · x) ≡⟨ sym (·Assoc _ _ _) ⟩ (eval (ℕ.suc n) P (x ∷ xs) · (eval (ℕ.suc n) S (x ∷ xs) · x)) ≡⟨ cong (λ u → eval (ℕ.suc n) P (x ∷ xs) · u) (·Comm _ _) ⟩ (eval (ℕ.suc n) P (x ∷ xs) · (x · eval (ℕ.suc n) S (x ∷ xs))) ≡⟨ ·Assoc _ _ _ ⟩ (eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs) ∎) ⟩ (eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs) + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ cong (λ u → (eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs) + u) (⋆Homeval n Q S x xs) ⟩ (eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs) + eval n Q xs · eval (ℕ.suc n) S (x ∷ xs) ≡⟨ sym (·DistL+ _ _ _) ⟩ ((eval (ℕ.suc n) P (x ∷ xs) · x) + eval n Q xs) · eval (ℕ.suc n) S (x ∷ xs) ≡⟨ refl ⟩ eval (ℕ.suc n) (P ·X+ Q) (x ∷ xs) · eval (ℕ.suc n) S (x ∷ xs) ∎
46.441048
102
0.415515
34186832c7dea24631de716a23da00046c20e4db
2,542
agda
Agda
src/MLib/Matrix/Equality.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
src/MLib/Matrix/Equality.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
src/MLib/Matrix/Equality.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
open import MLib.Algebra.PropertyCode open import MLib.Algebra.PropertyCode.Structures module MLib.Matrix.Equality {c ℓ} (struct : Struct bimonoidCode c ℓ) where open import MLib.Prelude open import MLib.Matrix.Core import Relation.Binary.Indexed as I module S = Struct struct renaming (Carrier to S; _≈_ to _≈′_) open S hiding (isEquivalence; setoid; refl; sym; trans) public module _ {m n} where -- Pointwise equality -- infix 4 _≈_ _≈_ : Rel (Matrix S m n) _ A ≈ B = ∀ i j → A i j ≈′ B i j isEquivalence : IsEquivalence _≈_ isEquivalence = record { Proofs } where module Proofs where refl : Reflexive _≈_ refl _ _ = S.refl sym : Symmetric _≈_ sym p = λ i j → S.sym (p i j) trans : Transitive _≈_ trans p q = λ i j → S.trans (p i j) (q i j) setoid : Setoid _ _ setoid = record { isEquivalence = isEquivalence } open Setoid setoid public using (refl; sym; trans) module FunctionProperties = Algebra.FunctionProperties _≈_ -- Size-heterogeneous pointwise equality infix 4 _≃_ record _≃_ {m n p q} (A : Matrix S m n) (B : Matrix S p q) : Set (c ⊔ˡ ℓ) where field m≡p : m ≡ p n≡q : n ≡ q equal : ∀ {i i′ j j′} → i ≅ i′ → j ≅ j′ → A i j ≈′ B i′ j′ open _≃_ ≃-refl : ∀ {m n} {A : Matrix S m n} → A ≃ A ≃-refl .m≡p = ≡.refl ≃-refl .n≡q = ≡.refl ≃-refl .equal ≅.refl ≅.refl = S.refl ≃-trans : ∀ {m n p q r s} {A : Matrix S m n} {B : Matrix S p q} {C : Matrix S r s} → A ≃ B → B ≃ C → A ≃ C ≃-trans x y .m≡p = ≡.trans (x .m≡p) (y .m≡p) ≃-trans x y .n≡q = ≡.trans (x .n≡q) (y .n≡q) ≃-trans {m} {n} {p} {q} {r} {s} x y .equal i≅i′′ j≅j′′ = let i≅i′ = ≅.sym (≅.≡-subst-removable Fin (x .m≡p) _) i′≅i′′ = ≅.trans (≅.sym i≅i′) i≅i′′ j≅j′ = ≅.sym (≅.≡-subst-removable Fin (x .n≡q) _) j′≅j′′ = ≅.trans (≅.sym j≅j′) j≅j′′ in S.trans (x .equal i≅i′ j≅j′) (y .equal i′≅i′′ j′≅j′′) ≃-sym : ∀ {m n p q} {A : Matrix S m n} {B : Matrix S p q} → A ≃ B → B ≃ A ≃-sym A≃B .m≡p = ≡.sym (A≃B .m≡p) ≃-sym A≃B .n≡q = ≡.sym (A≃B .n≡q) ≃-sym A≃B .equal i≅i′ j≅j′ = S.sym (A≃B .equal (≅.sym i≅i′) (≅.sym j≅j′)) ≃-setoid : I.Setoid (ℕ × ℕ) _ _ ≃-setoid = record { Carrier = uncurry (Matrix S) ; _≈_ = _≃_ ; isEquivalence = record { refl = ≃-refl ; sym = ≃-sym ; trans = ≃-trans } } ≡-subst-≃₁ : ∀ {m n p} {A : Matrix S m n} (m≡p : m ≡ p) → ≡.subst (λ h → Matrix S h n) m≡p A ≃ A ≡-subst-≃₁ ≡.refl = ≃-refl ≡-subst-≃₂ : ∀ {m n q} {A : Matrix S m n} (n≡q : n ≡ q) → ≡.subst (Matrix S m) n≡q A ≃ A ≡-subst-≃₂ ≡.refl = ≃-refl
27.042553
96
0.542093
30a088bb794d0d365bd70cc716656ec1a7d1229b
8,289
agda
Agda
Cubical/Foundations/Equiv.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
Cubical/Foundations/Equiv.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
Cubical/Foundations/Equiv.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
{- Theory about equivalences Definitions are in Core/Glue.agda but re-exported by this module - isEquiv is a proposition ([isPropIsEquiv]) - Any isomorphism is an equivalence ([isoToEquiv]) There are more statements about equivalences in Equiv/Properties.agda: - if f is an equivalence then (cong f) is an equivalence - if f is an equivalence then precomposition with f is an equivalence - if f is an equivalence then postcomposition with f is an equivalence -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Equiv where open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv.Base public open import Cubical.Data.Sigma.Base private variable ℓ ℓ' ℓ'' : Level A B C D : Type ℓ equivIsEquiv : (e : A ≃ B) → isEquiv (equivFun e) equivIsEquiv e = snd e equivCtr : (e : A ≃ B) (y : B) → fiber (equivFun e) y equivCtr e y = e .snd .equiv-proof y .fst equivCtrPath : (e : A ≃ B) (y : B) → (v : fiber (equivFun e) y) → Path _ (equivCtr e y) v equivCtrPath e y = e .snd .equiv-proof y .snd -- Proof using isPropIsContr. This is slow and the direct proof below is better isPropIsEquiv' : (f : A → B) → isProp (isEquiv f) equiv-proof (isPropIsEquiv' f u0 u1 i) y = isPropIsContr (u0 .equiv-proof y) (u1 .equiv-proof y) i -- Direct proof that computes quite ok (can be optimized further if -- necessary, see: -- https://github.com/mortberg/cubicaltt/blob/pi4s3_dimclosures/examples/brunerie2.ctt#L562 isPropIsEquiv : (f : A → B) → isProp (isEquiv f) equiv-proof (isPropIsEquiv f p q i) y = let p2 = p .equiv-proof y .snd q2 = q .equiv-proof y .snd in p2 (q .equiv-proof y .fst) i , λ w j → hcomp (λ k → λ { (i = i0) → p2 w j ; (i = i1) → q2 w (j ∨ ~ k) ; (j = i0) → p2 (q2 w (~ k)) i ; (j = i1) → w }) (p2 w (i ∨ j)) equivEq : {e f : A ≃ B} → (h : e .fst ≡ f .fst) → e ≡ f equivEq {e = e} {f = f} h = λ i → (h i) , isProp→PathP (λ i → isPropIsEquiv (h i)) (e .snd) (f .snd) i module _ {f : A → B} (equivF : isEquiv f) where funIsEq : A → B funIsEq = f invIsEq : B → A invIsEq y = equivF .equiv-proof y .fst .fst secIsEq : section f invIsEq secIsEq y = equivF .equiv-proof y .fst .snd retIsEq : retract f invIsEq retIsEq a i = equivF .equiv-proof (f a) .snd (a , refl) i .fst commSqIsEq : ∀ a → Square (secIsEq (f a)) refl (cong f (retIsEq a)) refl commSqIsEq a i = equivF .equiv-proof (f a) .snd (a , refl) i .snd module _ (w : A ≃ B) where invEq : B → A invEq = invIsEq (snd w) secEq : section invEq (w .fst) secEq = retIsEq (snd w) retEq : retract invEq (w .fst) retEq = secIsEq (snd w) open Iso equivToIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → A ≃ B → Iso A B fun (equivToIso e) = e .fst inv (equivToIso e) = invEq e rightInv (equivToIso e) = retEq e leftInv (equivToIso e) = secEq e -- TODO: there should be a direct proof of this that doesn't use equivToIso invEquiv : A ≃ B → B ≃ A invEquiv e = isoToEquiv (invIso (equivToIso e)) invEquivIdEquiv : (A : Type ℓ) → invEquiv (idEquiv A) ≡ idEquiv A invEquivIdEquiv _ = equivEq refl -- TODO: there should be a direct proof of this that doesn't use equivToIso compEquiv : A ≃ B → B ≃ C → A ≃ C compEquiv f g = isoToEquiv (compIso (equivToIso f) (equivToIso g)) compEquivIdEquiv : (e : A ≃ B) → compEquiv (idEquiv A) e ≡ e compEquivIdEquiv e = equivEq refl compEquivEquivId : (e : A ≃ B) → compEquiv e (idEquiv B) ≡ e compEquivEquivId e = equivEq refl invEquiv-is-rinv : (e : A ≃ B) → compEquiv e (invEquiv e) ≡ idEquiv A invEquiv-is-rinv e = equivEq (funExt (secEq e)) invEquiv-is-linv : (e : A ≃ B) → compEquiv (invEquiv e) e ≡ idEquiv B invEquiv-is-linv e = equivEq (funExt (retEq e)) compEquiv-assoc : (f : A ≃ B) (g : B ≃ C) (h : C ≃ D) → compEquiv f (compEquiv g h) ≡ compEquiv (compEquiv f g) h compEquiv-assoc f g h = equivEq refl LiftEquiv : A ≃ Lift {i = ℓ} {j = ℓ'} A LiftEquiv .fst a .lower = a LiftEquiv .snd .equiv-proof = strictContrFibers lower Lift≃Lift : (e : A ≃ B) → Lift {j = ℓ'} A ≃ Lift {j = ℓ''} B Lift≃Lift e .fst a .lower = e .fst (a .lower) Lift≃Lift e .snd .equiv-proof b .fst .fst .lower = invEq e (b .lower) Lift≃Lift e .snd .equiv-proof b .fst .snd i .lower = e .snd .equiv-proof (b .lower) .fst .snd i Lift≃Lift e .snd .equiv-proof b .snd (a , p) i .fst .lower = e .snd .equiv-proof (b .lower) .snd (a .lower , cong lower p) i .fst Lift≃Lift e .snd .equiv-proof b .snd (a , p) i .snd j .lower = e .snd .equiv-proof (b .lower) .snd (a .lower , cong lower p) i .snd j isContr→Equiv : isContr A → isContr B → A ≃ B isContr→Equiv Actr Bctr = isoToEquiv (isContr→Iso Actr Bctr) propBiimpl→Equiv : (Aprop : isProp A) (Bprop : isProp B) (f : A → B) (g : B → A) → A ≃ B propBiimpl→Equiv Aprop Bprop f g = f , hf where hf : isEquiv f hf .equiv-proof y .fst = (g y , Bprop (f (g y)) y) hf .equiv-proof y .snd h i .fst = Aprop (g y) (h .fst) i hf .equiv-proof y .snd h i .snd = isProp→isSet' Bprop (Bprop (f (g y)) y) (h .snd) (cong f (Aprop (g y) (h .fst))) refl i isEquivPropBiimpl→Equiv : isProp A → isProp B → ((A → B) × (B → A)) ≃ (A ≃ B) isEquivPropBiimpl→Equiv {A = A} {B = B} Aprop Bprop = isoToEquiv isom where isom : Iso (Σ (A → B) (λ _ → B → A)) (A ≃ B) isom .fun (f , g) = propBiimpl→Equiv Aprop Bprop f g isom .inv e = equivFun e , invEq e isom .rightInv e = equivEq refl isom .leftInv _ = refl equivΠCod : ∀ {F : A → Type ℓ} {G : A → Type ℓ'} → ((x : A) → F x ≃ G x) → ((x : A) → F x) ≃ ((x : A) → G x) equivΠCod k .fst f x = k x .fst (f x) equivΠCod k .snd .equiv-proof f .fst .fst x = equivCtr (k x) (f x) .fst equivΠCod k .snd .equiv-proof f .fst .snd i x = equivCtr (k x) (f x) .snd i equivΠCod k .snd .equiv-proof f .snd (g , p) i .fst x = equivCtrPath (k x) (f x) (g x , λ j → p j x) i .fst equivΠCod k .snd .equiv-proof f .snd (g , p) i .snd j x = equivCtrPath (k x) (f x) (g x , λ k → p k x) i .snd j equivImplicitΠCod : ∀ {F : A → Type ℓ} {G : A → Type ℓ'} → ({x : A} → F x ≃ G x) → ({x : A} → F x) ≃ ({x : A} → G x) equivImplicitΠCod k .fst f {x} = k {x} .fst (f {x}) equivImplicitΠCod k .snd .equiv-proof f .fst .fst {x} = equivCtr (k {x}) (f {x}) .fst equivImplicitΠCod k .snd .equiv-proof f .fst .snd i {x} = equivCtr (k {x}) (f {x}) .snd i equivImplicitΠCod k .snd .equiv-proof f .snd (g , p) i .fst {x} = equivCtrPath (k {x}) (f {x}) (g {x} , λ j → p j {x}) i .fst equivImplicitΠCod k .snd .equiv-proof f .snd (g , p) i .snd j {x} = equivCtrPath (k {x}) (f {x}) (g {x} , λ k → p k {x}) i .snd j equiv→Iso : (A ≃ B) → (C ≃ D) → Iso (A → C) (B → D) equiv→Iso h k .Iso.fun f b = equivFun k (f (invEq h b)) equiv→Iso h k .Iso.inv g a = invEq k (g (equivFun h a)) equiv→Iso h k .Iso.rightInv g = funExt λ b → retEq k _ ∙ cong g (retEq h b) equiv→Iso h k .Iso.leftInv f = funExt λ a → secEq k _ ∙ cong f (secEq h a) equiv→ : (A ≃ B) → (C ≃ D) → (A → C) ≃ (B → D) equiv→ h k = isoToEquiv (equiv→Iso h k) equivCompIso : (A ≃ B) → (C ≃ D) → Iso (A ≃ C) (B ≃ D) equivCompIso h k .Iso.fun f = compEquiv (compEquiv (invEquiv h) f) k equivCompIso h k .Iso.inv g = compEquiv (compEquiv h g) (invEquiv k) equivCompIso h k .Iso.rightInv g = equivEq (equiv→Iso h k .Iso.rightInv (equivFun g)) equivCompIso h k .Iso.leftInv f = equivEq (equiv→Iso h k .Iso.leftInv (equivFun f)) equivComp : (A ≃ B) → (C ≃ D) → (A ≃ C) ≃ (B ≃ D) equivComp h k = isoToEquiv (equivCompIso h k) -- Some helpful notation: _≃⟨_⟩_ : (X : Type ℓ) → (X ≃ B) → (B ≃ C) → (X ≃ C) _ ≃⟨ f ⟩ g = compEquiv f g _■ : (X : Type ℓ) → (X ≃ X) _■ = idEquiv infixr 0 _≃⟨_⟩_ infix 1 _■ composesToId→Equiv : (f : A → B) (g : B → A) → f ∘ g ≡ idfun B → isEquiv f → isEquiv g composesToId→Equiv f g id iseqf = isoToIsEquiv (iso g f (λ b → (λ i → equiv-proof iseqf (f b) .snd (g (f b) , cong (λ h → h (f b)) id) (~ i) .fst) ∙∙ cong (λ x → equiv-proof iseqf (f b) .fst .fst) id ∙∙ λ i → equiv-proof iseqf (f b) .snd (b , refl) i .fst) λ a i → id i a)
37.677273
102
0.596453
1b590e535685cab5ae8703f917a64e57623cd924
157
agda
Agda
test/Fail/Issue5434-4.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue5434-4.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue5434-4.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K #-} mutual record R : Set₁ where constructor c field @0 A : Set x : _ _ : (@0 A : Set) → A → R _ = c
12.076923
27
0.452229
34117b6278388f2a06e28e8cacbe02c5b76f228a
9,048
agda
Agda
src/Categories/Diagram/Pullback.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Diagram/Pullback.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Diagram/Pullback.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category.Core using (Category) module Categories.Diagram.Pullback {o ℓ e} (C : Category o ℓ e) where open Category C open HomReasoning open Equiv open import Level open import Data.Product using (_,_; ∃) open import Function using (flip; _$_) renaming (_∘_ to _●_) open import Categories.Morphism C open import Categories.Object.Product C hiding (up-to-iso; repack; repack∘; repack-cancel) open import Categories.Diagram.Equalizer C hiding (up-to-iso) open import Categories.Morphism.Reasoning C as Square renaming (glue to glue-square) hiding (id-unique) private variable A B X Y Z : Obj f g h h₁ h₂ i i₁ i₂ j k : A ⇒ B -- Proof that a given square is a pullback record IsPullback {P : Obj} (p₁ : P ⇒ X) (p₂ : P ⇒ Y) (f : X ⇒ Z) (g : Y ⇒ Z) : Set (o ⊔ ℓ ⊔ e) where field commute : f ∘ p₁ ≈ g ∘ p₂ universal : ∀ {h₁ : A ⇒ X} {h₂ : A ⇒ Y} → f ∘ h₁ ≈ g ∘ h₂ → A ⇒ P unique : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} → p₁ ∘ i ≈ h₁ → p₂ ∘ i ≈ h₂ → i ≈ universal eq p₁∘universal≈h₁ : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} → p₁ ∘ universal eq ≈ h₁ p₂∘universal≈h₂ : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} → p₂ ∘ universal eq ≈ h₂ unique′ : (eq eq′ : f ∘ h₁ ≈ g ∘ h₂) → universal eq ≈ universal eq′ unique′ eq eq′ = unique p₁∘universal≈h₁ p₂∘universal≈h₂ id-unique : id ≈ universal commute id-unique = unique identityʳ identityʳ universal-resp-≈ : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} {eq′ : f ∘ i₁ ≈ g ∘ i₂} → h₁ ≈ i₁ → h₂ ≈ i₂ → universal eq ≈ universal eq′ universal-resp-≈ h₁≈i₁ h₂≈i₂ = unique (p₁∘universal≈h₁ ○ h₁≈i₁) (p₂∘universal≈h₂ ○ h₂≈i₂) unique-diagram : p₁ ∘ h ≈ p₁ ∘ i → p₂ ∘ h ≈ p₂ ∘ i → h ≈ i unique-diagram {h = h} {i = i} eq₁ eq₂ = begin h ≈⟨ unique eq₁ eq₂ ⟩ universal eq ≈˘⟨ unique refl refl ⟩ i ∎ where eq = extendʳ commute -- Pullback of two arrows with a common codomain record Pullback (f : X ⇒ Z) (g : Y ⇒ Z) : Set (o ⊔ ℓ ⊔ e) where field {P} : Obj p₁ : P ⇒ X p₂ : P ⇒ Y isPullback : IsPullback p₁ p₂ f g open IsPullback isPullback public up-to-iso : (pullback pullback′ : Pullback f g) → Pullback.P pullback ≅ Pullback.P pullback′ up-to-iso pullback pullback′ = record { from = repack pullback pullback′ ; to = repack pullback′ pullback ; iso = record { isoˡ = repack-cancel pullback′ pullback ; isoʳ = repack-cancel pullback pullback′ } } where open Pullback repack : (pullback pullback′ : Pullback f g) → P pullback ⇒ P pullback′ repack pullback pullback′ = universal pullback′ (commute pullback) repack∘ : (pullback pullback′ pullback″ : Pullback f g) → repack pullback′ pullback″ ∘ repack pullback pullback′ ≈ repack pullback pullback″ repack∘ pullback pullback′ pullback″ = unique pullback″ (glueTrianglesʳ (p₁∘universal≈h₁ pullback″) (p₁∘universal≈h₁ pullback′)) (glueTrianglesʳ (p₂∘universal≈h₂ pullback″) (p₂∘universal≈h₂ pullback′)) repack-cancel : (pullback pullback′ : Pullback f g) → repack pullback pullback′ ∘ repack pullback′ pullback ≈ id repack-cancel pullback pullback′ = repack∘ pullback′ pullback pullback′ ○ ⟺ (id-unique pullback′) swap : Pullback f g → Pullback g f swap p = record { p₁ = p₂ ; p₂ = p₁ ; isPullback = record { commute = ⟺ commute ; universal = universal ● ⟺ ; unique = flip unique ; p₁∘universal≈h₁ = p₂∘universal≈h₂ ; p₂∘universal≈h₂ = p₁∘universal≈h₁ } } where open Pullback p glue : (p : Pullback f g) → Pullback h (Pullback.p₁ p) → Pullback (f ∘ h) g glue {h = h} p q = record { p₁ = q.p₁ ; p₂ = p.p₂ ∘ q.p₂ ; isPullback = record { commute = glue-square p.commute q.commute ; universal = λ eq → q.universal (⟺ (p.p₁∘universal≈h₁ {eq = sym-assoc ○ eq})) ; unique = λ {_ h₁ h₂ i} eq eq′ → q.unique eq (p.unique (begin p.p₁ ∘ q.p₂ ∘ i ≈˘⟨ extendʳ q.commute ⟩ h ∘ q.p₁ ∘ i ≈⟨ refl⟩∘⟨ eq ⟩ h ∘ h₁ ∎) (sym-assoc ○ eq′)) ; p₁∘universal≈h₁ = q.p₁∘universal≈h₁ ; p₂∘universal≈h₂ = assoc ○ ∘-resp-≈ʳ q.p₂∘universal≈h₂ ○ p.p₂∘universal≈h₂ } } where module p = Pullback p module q = Pullback q unglue : (p : Pullback f g) → Pullback (f ∘ h) g → Pullback h (Pullback.p₁ p) unglue {f = f} {g = g} {h = h} p q = record { p₁ = q.p₁ ; p₂ = p₂′ ; isPullback = record { commute = ⟺ p.p₁∘universal≈h₁ ; universal = λ {_ h₁ h₂} eq → q.universal $ begin (f ∘ h) ∘ h₁ ≈⟨ pullʳ eq ⟩ f ∘ p.p₁ ∘ h₂ ≈⟨ extendʳ p.commute ⟩ g ∘ p.p₂ ∘ h₂ ∎ ; unique = λ {_ h₁ h₂ i} eq eq′ → q.unique eq $ begin q.p₂ ∘ i ≈⟨ pushˡ (⟺ p.p₂∘universal≈h₂) ⟩ p.p₂ ∘ p₂′ ∘ i ≈⟨ refl⟩∘⟨ eq′ ⟩ p.p₂ ∘ h₂ ∎ ; p₁∘universal≈h₁ = q.p₁∘universal≈h₁ ; p₂∘universal≈h₂ = λ {_ _ _ eq} → p.unique-diagram ((pullˡ p.p₁∘universal≈h₁) ○ pullʳ q.p₁∘universal≈h₁ ○ eq) (pullˡ p.p₂∘universal≈h₂ ○ q.p₂∘universal≈h₂) } } where module p = Pullback p module q = Pullback q p₂′ = p.universal (sym-assoc ○ q.commute) -- used twice above Product×Equalizer⇒Pullback : (p : Product A B) → Equalizer (f ∘ Product.π₁ p) (g ∘ Product.π₂ p) → Pullback f g Product×Equalizer⇒Pullback {f = f} {g = g} p e = record { p₁ = π₁ ∘ arr ; p₂ = π₂ ∘ arr ; isPullback = record { commute = sym-assoc ○ equality ○ assoc ; universal = λ {_ h₁ h₂} eq → equalize $ begin (f ∘ π₁) ∘ ⟨ h₁ , h₂ ⟩ ≈⟨ pullʳ project₁ ⟩ f ∘ h₁ ≈⟨ eq ⟩ g ∘ h₂ ≈˘⟨ pullʳ project₂ ⟩ (g ∘ π₂) ∘ ⟨ h₁ , h₂ ⟩ ∎ ; unique = λ eq eq′ → e.unique (p.unique (sym-assoc ○ eq) (sym-assoc ○ eq′)) ; p₁∘universal≈h₁ = pullʳ (⟺ e.universal) ○ project₁ ; p₂∘universal≈h₂ = pullʳ (⟺ e.universal) ○ project₂ } } where module p = Product p module e = Equalizer e open p open e Product×Pullback⇒Equalizer : (p : Product A B) → Pullback f g → Equalizer (f ∘ Product.π₁ p) (g ∘ Product.π₂ p) Product×Pullback⇒Equalizer {f = f} {g = g} p pu = record { arr = ⟨ p₁ , p₂ ⟩ ; isEqualizer = record { equality = begin (f ∘ π₁) ∘ ⟨ p₁ , p₂ ⟩ ≈⟨ pullʳ project₁ ⟩ f ∘ p₁ ≈⟨ commute ⟩ g ∘ p₂ ≈˘⟨ pullʳ project₂ ⟩ (g ∘ π₂) ∘ ⟨ p₁ , p₂ ⟩ ∎ ; equalize = λ eq → pu.universal (sym-assoc ○ eq ○ assoc) ; universal = λ {_ h} → begin h ≈˘⟨ p.unique (⟺ p₁∘universal≈h₁) (⟺ p₂∘universal≈h₂) ⟩ ⟨ p₁ ∘ _ , p₂ ∘ _ ⟩ ≈⟨ p.unique (pullˡ project₁) (pullˡ project₂) ⟩ ⟨ p₁ , p₂ ⟩ ∘ _ ∎ ; unique = λ eq → pu.unique (pushˡ (⟺ project₁) ○ ⟺ (∘-resp-≈ʳ eq)) (pushˡ (⟺ project₂) ○ ⟺ (∘-resp-≈ʳ eq)) } } where module p = Product p module pu = Pullback pu open p open pu module _ (p : Pullback f g) where open Pullback p Pullback-resp-≈ : h ≈ f → i ≈ g → Pullback h i Pullback-resp-≈ eq eq′ = record { p₁ = p₁ ; p₂ = p₂ ; isPullback = record { commute = ∘-resp-≈ˡ eq ○ commute ○ ⟺ (∘-resp-≈ˡ eq′) ; universal = λ eq″ → universal (∘-resp-≈ˡ (⟺ eq) ○ eq″ ○ ∘-resp-≈ˡ eq′) ; unique = unique ; p₁∘universal≈h₁ = p₁∘universal≈h₁ ; p₂∘universal≈h₂ = p₂∘universal≈h₂ } } Pullback-resp-Mono : Mono g → Mono p₁ Pullback-resp-Mono mg h i eq = unique-diagram eq (mg _ _ eq′) where eq′ : g ∘ p₂ ∘ h ≈ g ∘ p₂ ∘ i eq′ = begin g ∘ p₂ ∘ h ≈⟨ extendʳ (sym commute) ⟩ f ∘ p₁ ∘ h ≈⟨ refl⟩∘⟨ eq ⟩ f ∘ p₁ ∘ i ≈⟨ extendʳ commute ⟩ g ∘ p₂ ∘ i ∎ Pullback-resp-Iso : Iso g h → ∃ λ i → Iso p₁ i Pullback-resp-Iso {h = h} iso = universal eq , record { isoˡ = unique-diagram eq₁ eq₂ ; isoʳ = p₁∘universal≈h₁ } where open Iso iso eq = begin f ∘ id ≈⟨ introˡ refl ⟩ id ∘ f ∘ id ≈⟨ pushˡ (⟺ isoʳ) ⟩ g ∘ h ∘ f ∘ id ∎ eq₁ = begin p₁ ∘ universal eq ∘ p₁ ≈⟨ cancelˡ p₁∘universal≈h₁ ⟩ p₁ ≈˘⟨ identityʳ ⟩ p₁ ∘ id ∎ eq₂ = begin p₂ ∘ universal eq ∘ p₁ ≈⟨ extendʳ p₂∘universal≈h₂ ⟩ h ∘ (f ∘ id) ∘ p₁ ≈⟨ refl ⟩∘⟨ identityʳ ⟩∘⟨ refl ⟩ h ∘ f ∘ p₁ ≈⟨ refl ⟩∘⟨ commute ⟩ h ∘ g ∘ p₂ ≈⟨ cancelˡ isoˡ ⟩ p₂ ≈˘⟨ identityʳ ⟩ p₂ ∘ id ∎
36.930612
144
0.507184
8bff814f1eb6fd1dbcfbd48503d2c53bb0fcf39a
261
agda
Agda
Data/Integer/Literals.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Integer/Literals.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Integer/Literals.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} module Data.Integer.Literals where open import Data.Integer open import Literals.Number open import Data.Unit instance numberNat : Number ℤ numberNat = record { Constraint = λ _ → ⊤ ; fromNat = λ n → ⁺ n }
17.4
34
0.659004
353c955e693cf343801e0234a6cb7f1e94ed9da0
594
agda
Agda
agda-stdlib/src/Data/List/Relation/Permutation/Inductive.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Permutation/Inductive.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Permutation/Inductive.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Permutation.Inductive directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Permutation.Inductive where open import Data.List.Relation.Binary.Permutation.Inductive public {-# WARNING_ON_IMPORT "Data.List.Relation.Permutation.Inductive was deprecated in v1.0. Use Data.List.Relation.Binary.Permutation.Inductive instead." #-}
33
72
0.589226
30c453883fcf19383fa3084379b2c011379c35f1
5,654
agda
Agda
prototyping/Luau/Type.agda
EtiTheSpirit/luau
d37d0c857ba543ea47f0b8fce5678f7aadf5239e
[ "MIT" ]
null
null
null
prototyping/Luau/Type.agda
EtiTheSpirit/luau
d37d0c857ba543ea47f0b8fce5678f7aadf5239e
[ "MIT" ]
null
null
null
prototyping/Luau/Type.agda
EtiTheSpirit/luau
d37d0c857ba543ea47f0b8fce5678f7aadf5239e
[ "MIT" ]
null
null
null
module Luau.Type where open import FFI.Data.Maybe using (Maybe; just; nothing; just-inv) open import Agda.Builtin.Equality using (_≡_; refl) open import Properties.Dec using (Dec; yes; no) open import Properties.Equality using (cong) open import FFI.Data.Maybe using (Maybe; just; nothing) data Type : Set where nil : Type _⇒_ : Type → Type → Type never : Type unknown : Type boolean : Type number : Type string : Type _∪_ : Type → Type → Type _∩_ : Type → Type → Type data Scalar : Type → Set where number : Scalar number boolean : Scalar boolean string : Scalar string nil : Scalar nil lhs : Type → Type lhs (T ⇒ _) = T lhs (T ∪ _) = T lhs (T ∩ _) = T lhs nil = nil lhs never = never lhs unknown = unknown lhs number = number lhs boolean = boolean lhs string = string rhs : Type → Type rhs (_ ⇒ T) = T rhs (_ ∪ T) = T rhs (_ ∩ T) = T rhs nil = nil rhs never = never rhs unknown = unknown rhs number = number rhs boolean = boolean rhs string = string _≡ᵀ_ : ∀ (T U : Type) → Dec(T ≡ U) nil ≡ᵀ nil = yes refl nil ≡ᵀ (S ⇒ T) = no (λ ()) nil ≡ᵀ never = no (λ ()) nil ≡ᵀ unknown = no (λ ()) nil ≡ᵀ number = no (λ ()) nil ≡ᵀ boolean = no (λ ()) nil ≡ᵀ (S ∪ T) = no (λ ()) nil ≡ᵀ (S ∩ T) = no (λ ()) nil ≡ᵀ string = no (λ ()) (S ⇒ T) ≡ᵀ string = no (λ ()) never ≡ᵀ string = no (λ ()) unknown ≡ᵀ string = no (λ ()) boolean ≡ᵀ string = no (λ ()) number ≡ᵀ string = no (λ ()) (S ∪ T) ≡ᵀ string = no (λ ()) (S ∩ T) ≡ᵀ string = no (λ ()) (S ⇒ T) ≡ᵀ nil = no (λ ()) (S ⇒ T) ≡ᵀ (U ⇒ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ⇒ T) ≡ᵀ (S ⇒ T) | yes refl | yes refl = yes refl (S ⇒ T) ≡ᵀ (U ⇒ V) | _ | no p = no (λ q → p (cong rhs q)) (S ⇒ T) ≡ᵀ (U ⇒ V) | no p | _ = no (λ q → p (cong lhs q)) (S ⇒ T) ≡ᵀ never = no (λ ()) (S ⇒ T) ≡ᵀ unknown = no (λ ()) (S ⇒ T) ≡ᵀ number = no (λ ()) (S ⇒ T) ≡ᵀ boolean = no (λ ()) (S ⇒ T) ≡ᵀ (U ∪ V) = no (λ ()) (S ⇒ T) ≡ᵀ (U ∩ V) = no (λ ()) never ≡ᵀ nil = no (λ ()) never ≡ᵀ (U ⇒ V) = no (λ ()) never ≡ᵀ never = yes refl never ≡ᵀ unknown = no (λ ()) never ≡ᵀ number = no (λ ()) never ≡ᵀ boolean = no (λ ()) never ≡ᵀ (U ∪ V) = no (λ ()) never ≡ᵀ (U ∩ V) = no (λ ()) unknown ≡ᵀ nil = no (λ ()) unknown ≡ᵀ (U ⇒ V) = no (λ ()) unknown ≡ᵀ never = no (λ ()) unknown ≡ᵀ unknown = yes refl unknown ≡ᵀ number = no (λ ()) unknown ≡ᵀ boolean = no (λ ()) unknown ≡ᵀ (U ∪ V) = no (λ ()) unknown ≡ᵀ (U ∩ V) = no (λ ()) number ≡ᵀ nil = no (λ ()) number ≡ᵀ (T ⇒ U) = no (λ ()) number ≡ᵀ never = no (λ ()) number ≡ᵀ unknown = no (λ ()) number ≡ᵀ number = yes refl number ≡ᵀ boolean = no (λ ()) number ≡ᵀ (T ∪ U) = no (λ ()) number ≡ᵀ (T ∩ U) = no (λ ()) boolean ≡ᵀ nil = no (λ ()) boolean ≡ᵀ (T ⇒ U) = no (λ ()) boolean ≡ᵀ never = no (λ ()) boolean ≡ᵀ unknown = no (λ ()) boolean ≡ᵀ boolean = yes refl boolean ≡ᵀ number = no (λ ()) boolean ≡ᵀ (T ∪ U) = no (λ ()) boolean ≡ᵀ (T ∩ U) = no (λ ()) string ≡ᵀ nil = no (λ ()) string ≡ᵀ (x ⇒ x₁) = no (λ ()) string ≡ᵀ never = no (λ ()) string ≡ᵀ unknown = no (λ ()) string ≡ᵀ boolean = no (λ ()) string ≡ᵀ number = no (λ ()) string ≡ᵀ string = yes refl string ≡ᵀ (U ∪ V) = no (λ ()) string ≡ᵀ (U ∩ V) = no (λ ()) (S ∪ T) ≡ᵀ nil = no (λ ()) (S ∪ T) ≡ᵀ (U ⇒ V) = no (λ ()) (S ∪ T) ≡ᵀ never = no (λ ()) (S ∪ T) ≡ᵀ unknown = no (λ ()) (S ∪ T) ≡ᵀ number = no (λ ()) (S ∪ T) ≡ᵀ boolean = no (λ ()) (S ∪ T) ≡ᵀ (U ∪ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ∪ T) ≡ᵀ (S ∪ T) | yes refl | yes refl = yes refl (S ∪ T) ≡ᵀ (U ∪ V) | _ | no p = no (λ q → p (cong rhs q)) (S ∪ T) ≡ᵀ (U ∪ V) | no p | _ = no (λ q → p (cong lhs q)) (S ∪ T) ≡ᵀ (U ∩ V) = no (λ ()) (S ∩ T) ≡ᵀ nil = no (λ ()) (S ∩ T) ≡ᵀ (U ⇒ V) = no (λ ()) (S ∩ T) ≡ᵀ never = no (λ ()) (S ∩ T) ≡ᵀ unknown = no (λ ()) (S ∩ T) ≡ᵀ number = no (λ ()) (S ∩ T) ≡ᵀ boolean = no (λ ()) (S ∩ T) ≡ᵀ (U ∪ V) = no (λ ()) (S ∩ T) ≡ᵀ (U ∩ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ∩ T) ≡ᵀ (U ∩ V) | yes refl | yes refl = yes refl (S ∩ T) ≡ᵀ (U ∩ V) | _ | no p = no (λ q → p (cong rhs q)) (S ∩ T) ≡ᵀ (U ∩ V) | no p | _ = no (λ q → p (cong lhs q)) _≡ᴹᵀ_ : ∀ (T U : Maybe Type) → Dec(T ≡ U) nothing ≡ᴹᵀ nothing = yes refl nothing ≡ᴹᵀ just U = no (λ ()) just T ≡ᴹᵀ nothing = no (λ ()) just T ≡ᴹᵀ just U with T ≡ᵀ U (just T ≡ᴹᵀ just T) | yes refl = yes refl (just T ≡ᴹᵀ just U) | no p = no (λ q → p (just-inv q)) data Mode : Set where strict : Mode nonstrict : Mode src : Mode → Type → Type src m nil = never src m number = never src m boolean = never src m string = never src m (S ⇒ T) = S -- In nonstrict mode, functions are covaraiant, in strict mode they're contravariant src strict (S ∪ T) = (src strict S) ∩ (src strict T) src nonstrict (S ∪ T) = (src nonstrict S) ∪ (src nonstrict T) src strict (S ∩ T) = (src strict S) ∪ (src strict T) src nonstrict (S ∩ T) = (src nonstrict S) ∩ (src nonstrict T) src strict never = unknown src nonstrict never = never src strict unknown = never src nonstrict unknown = unknown tgt : Type → Type tgt nil = never tgt (S ⇒ T) = T tgt never = never tgt unknown = unknown tgt number = never tgt boolean = never tgt string = never tgt (S ∪ T) = (tgt S) ∪ (tgt T) tgt (S ∩ T) = (tgt S) ∩ (tgt T) optional : Type → Type optional nil = nil optional (T ∪ nil) = (T ∪ nil) optional T = (T ∪ nil) normalizeOptional : Type → Type normalizeOptional (S ∪ T) with normalizeOptional S | normalizeOptional T normalizeOptional (S ∪ T) | (S′ ∪ nil) | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | S′ | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | (S′ ∪ nil) | T′ = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | S′ | nil = optional S′ normalizeOptional (S ∪ T) | nil | T′ = optional T′ normalizeOptional (S ∪ T) | S′ | T′ = S′ ∪ T′ normalizeOptional T = T
29.14433
84
0.532366
12c7332d8fd455de1bc8129caf32d7f2ed7905cc
1,154
agda
Agda
Numeral/Natural/Prime/Proofs/Product.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/Natural/Prime/Proofs/Product.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/Natural/Prime/Proofs/Product.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.Natural.Prime.Proofs.Product where import Lvl open import Data.Either as Either using () open import Functional open import Lang.Instance open import Logic.Propositional open import Numeral.Natural open import Numeral.Natural.Relation.Divisibility.Proofs open import Numeral.Natural.Oper open import Numeral.Natural.Prime open import Numeral.Natural.Relation.Divisibility.Proofs.Product open import Sets.PredicateSet renaming (_≡_ to _≡ₛ_) open import Type private variable a b : ℕ -- The prime factors of a product is the prime factors of its factors. product-primeFactors : PrimeFactor(a ⋅ b) ≡ₛ (PrimeFactor(a) ∪ PrimeFactor(b)) product-primeFactors = [↔]-intro l r where l : PrimeFactor(a ⋅ b) ⊇ (PrimeFactor(a) ∪ PrimeFactor(b)) l{a}{b}{x} (Either.Left intro) = intro ⦃ factor = divides-with-[⋅] {x}{a}{b} ([∨]-introₗ infer) ⦄ l{a}{b}{x} (Either.Right intro) = intro ⦃ factor = divides-with-[⋅] {x}{a}{b} ([∨]-introᵣ infer) ⦄ r : PrimeFactor(a ⋅ b) ⊆ (PrimeFactor(a) ∪ PrimeFactor(b)) r{a}{b}{x} intro = Either.map (p ↦ intro ⦃ factor = p ⦄) (p ↦ intro ⦃ factor = p ⦄) (prime-divides-of-[⋅] {x}{a}{b} infer infer)
42.740741
130
0.707106
d155a61bc5577c54e1f0e97a5bc5b60a0c4c9e68
13,166
agda
Agda
LC/stash/STLC4.agda
banacorn/bidirectional
0c9a6e79c23192b28ddb07315b200a94ee900ca6
[ "MIT" ]
2
2020-08-25T07:34:40.000Z
2020-08-25T14:05:01.000Z
LC/stash/STLC4.agda
banacorn/bidirectional
0c9a6e79c23192b28ddb07315b200a94ee900ca6
[ "MIT" ]
null
null
null
LC/stash/STLC4.agda
banacorn/bidirectional
0c9a6e79c23192b28ddb07315b200a94ee900ca6
[ "MIT" ]
null
null
null
module STLC4 where open import Data.Nat open import Data.Nat.Properties using (≤-antisym; ≤-trans; ≰⇒>; ≤-step) -- open import Data.List open import Data.Empty using (⊥-elim) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; cong₂; subst) open import Relation.Nullary.Decidable using (map) open import Relation.Nullary open import Data.Product -- de Bruijn indexed lambda calculus infix 5 ƛ_ infixl 7 _∙_ infix 9 var_ data Term : Set where var_ : (x : ℕ) → Term ƛ_ : Term → Term _∙_ : Term → Term → Term shift : (n i : ℕ) → Term → Term shift free i (var x) with x ≥? free shift free i (var x) | yes p = var (x + i) -- free shift free i (var x) | no ¬p = var x -- bound shift free i (ƛ M) = ƛ shift (suc free) i M shift free i (M ∙ N) = shift free i M ∙ shift free i N infixl 10 _[_/_] _[_/_] : Term → Term → ℕ → Term (var x) [ N / i ] with compare x i ((var x) [ N / .(suc (x + k)) ]) | less .x k = var x ((var x) [ N / .x ]) | equal .x = shift 0 x N ((var .(suc (i + k))) [ N / i ]) | greater .i k = var (i + k) (ƛ M) [ N / i ] = ƛ (M [ N / suc i ]) (L ∙ M) [ N / i ] = L [ N / i ] ∙ M [ N / i ] -- substitute the 0th var in M for N infixl 10 _[_] _[_] : Term → Term → Term M [ N ] = M [ N / 0 ] -- β reduction infix 3 _β→_ data _β→_ : Term → Term → Set where β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ]) β-ƛ : ∀ {M N} → M β→ N → ƛ M β→ ƛ N β-∙-l : ∀ {L M N} → M β→ N → M ∙ L β→ N ∙ L β-∙-r : ∀ {L M N} → M β→ N → L ∙ M β→ L ∙ N module TransRefl where -- the reflexive and transitive closure of _β→_ infix 2 _β→*_ infixr 2 _→*_ data _β→*_ : Term → Term → Set where ∎ : ∀ {M} → M β→* M _→*_ : ∀ {L M N} → L β→ M → M β→* N -------------- → L β→* N infixl 3 _<β>_ _<β>_ : ∀ {M N O} → M β→* N → N β→* O → M β→* O _<β>_ {M} {.M} {O} ∎ N→O = N→O _<β>_ {M} {N} {O} (L→M →* M→N) N→O = L→M →* M→N <β> N→O infixr 2 _→⟨⟩_ _→⟨⟩_ : ∀ {M} → ∀ N → N β→* M -------------- → N β→* M M →⟨⟩ Q = Q infixr 2 _→⟨_⟩_ _→⟨_⟩_ : ∀ {M N} → ∀ L → L β→ M → M β→* N -------------- → L β→* N L →⟨ P ⟩ Q = P →* Q infixr 2 _→*⟨_⟩_ _→*⟨_⟩_ : ∀ {M N} → ∀ L → L β→* M → M β→* N -------------- → L β→* N L →*⟨ P ⟩ Q = P <β> Q infix 3 _→∎ _→∎ : ∀ M → M β→* M M →∎ = ∎ hop : ∀ {M N} → M β→ N → M β→* N hop {M} {N} M→N = M→N →* ∎ open TransRefl -- the symmetric closure of _β→*_ module Eq where infix 1 _β≡_ data _β≡_ : Term → Term → Set where β-sym : ∀ {M N} → M β→* N → N β→* M ------- → M β≡ N infixr 2 _=*⟨_⟩_ _=*⟨_⟩_ : ∀ {M N} → ∀ L → L β≡ M → M β≡ N -------------- → L β≡ N L =*⟨ β-sym A B ⟩ β-sym C D = β-sym (A <β> C) (D <β> B) infixr 2 _=*⟨⟩_ _=*⟨⟩_ : ∀ {N} → ∀ L → L β≡ N -------------- → L β≡ N L =*⟨⟩ β-sym C D = β-sym C D infix 3 _=∎ _=∎ : ∀ M → M β≡ M M =∎ = β-sym ∎ ∎ forward : ∀ {M N} → M β≡ N → M β→* N forward (β-sym A _) = A backward : ∀ {M N} → M β≡ N → N β→* M backward (β-sym _ B) = B module Example where test-1 : ƛ (ƛ var 1) ∙ var 0 β→* ƛ var 0 test-1 = ƛ (ƛ var 1) ∙ var 0 →⟨ β-ƛ β-ƛ-∙ ⟩ ƛ var 0 →∎ test-0 : ƛ (ƛ var 0 ∙ var 1) ∙ (ƛ var 0 ∙ var 1) β→* ƛ var 0 ∙ var 0 test-0 = ƛ (ƛ var 0 ∙ var 1) ∙ (ƛ var 0 ∙ var 1) →⟨ β-ƛ β-ƛ-∙ ⟩ ƛ (var 0 ∙ var 1) [ ƛ var 0 ∙ var 1 ] →⟨⟩ ƛ (var 0 ∙ var 1) [ ƛ var 0 ∙ var 1 / 0 ] →⟨⟩ ƛ (var 0) [ ƛ var 0 ∙ var 1 / 0 ] ∙ (var 1) [ ƛ var 0 ∙ var 1 / 0 ] →⟨⟩ ƛ shift 0 0 (ƛ var 0 ∙ var 1) ∙ var 0 →⟨⟩ ƛ (ƛ shift 1 0 (var 0 ∙ var 1)) ∙ var 0 →⟨⟩ ƛ (ƛ shift 1 0 (var 0) ∙ shift 1 0 (var 1)) ∙ var 0 →⟨⟩ ƛ ((ƛ var 0 ∙ var 1) ∙ var 0) →⟨ β-ƛ β-ƛ-∙ ⟩ ƛ (var 0 ∙ var 1) [ var 0 / 0 ] →⟨⟩ ƛ var 0 ∙ var 0 →∎ Z : Term Z = ƛ ƛ var 0 SZ : Term SZ = ƛ ƛ var 1 ∙ var 0 PLUS : Term PLUS = ƛ ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0) test-2 : PLUS ∙ Z ∙ SZ β→* SZ test-2 = PLUS ∙ Z ∙ SZ →⟨ β-∙-l β-ƛ-∙ ⟩ (ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 0 ] ∙ SZ →⟨⟩ (ƛ ((ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 1 ])) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 2 ])) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ ((var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 3 ])))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (ƛ (ƛ var 0)) ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨ β-∙-l (β-ƛ (β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)))) ⟩ (ƛ (ƛ (ƛ (ƛ var 0) [ var 1 / 0 ] ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (ƛ (var 0) [ var 1 / 1 ]) ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (ƛ var 0) ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨ β-∙-l (β-ƛ (β-ƛ (β-ƛ β-ƛ-∙))) ⟩ (ƛ (ƛ (ƛ (var 0) [ var 2 ∙ var 1 ∙ var 0 / 0 ]))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨ β-ƛ-∙ ⟩ (ƛ (ƛ (var 2 ∙ var 1 ∙ var 0))) [ SZ / 0 ] →⟨⟩ ƛ (ƛ (var 2 ∙ var 1 ∙ var 0) [ SZ / 2 ]) →⟨⟩ ƛ (ƛ shift 0 2 SZ ∙ var 1 ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ ƛ var 1 ∙ var 0) ∙ var 1 ∙ var 0) →⟨ β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)) ⟩ ƛ (ƛ (ƛ var 1 ∙ var 0) [ var 1 / 0 ] ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ ((var 1 ∙ var 0) [ var 1 / 1 ])) ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ ((var 1) [ var 1 / 1 ] ∙ (var 0) [ var 1 / 1 ])) ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ (shift 0 1 (var 1) ∙ var 0)) ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ (var 2 ∙ var 0)) ∙ var 0) →⟨ β-ƛ (β-ƛ β-ƛ-∙) ⟩ ƛ (ƛ (var 2 ∙ var 0) [ var 0 / 0 ]) →⟨⟩ ƛ (ƛ (var 2) [ var 0 / 0 ] ∙ var 0) →⟨⟩ ƛ (ƛ var 1 ∙ var 0) →∎ -- lemmas cong-ƛ : {M N : Term} → M β→* N → ƛ M β→* ƛ N cong-ƛ ∎ = ∎ cong-ƛ (M→N →* N→O) = β-ƛ M→N →* cong-ƛ N→O cong-∙-l : {L M N : Term} → M β→* N → M ∙ L β→* N ∙ L cong-∙-l ∎ = ∎ cong-∙-l (M→N →* N→O) = β-∙-l M→N →* cong-∙-l N→O cong-∙-r : {L M N : Term} → M β→* N → L ∙ M β→* L ∙ N cong-∙-r ∎ = ∎ cong-∙-r (M→N →* N→O) = β-∙-r M→N →* cong-∙-r N→O -- shift-subst : ∀ freeM i n M N → (shift (suc (suc free)) i M) [ shift free i N / n ] β→* shift (suc free) i (M [ N / n ]) -- -- N ---- shfit n ---> N' -- | | -- M[_] shfit n+2 [_] -- | | -- M[N] ---- shfit n+1 ---> N' -- shift-subst : ∀ free i n M N → (shift (suc (suc free)) i M) [ shift free i N / n ] β→* shift (suc free) i (M [ N / n ]) shift-subst free i n (var x) N with compare x n shift-subst free i .(suc (x + k)) (var x) N | less .x k with x ≥? suc free shift-subst free i .(suc (x + k)) (var x) N | less .x k | yes p with suc (suc free) ≤? x shift-subst free i .(suc (x + k)) (var x) N | less .x k | yes p | yes q = {! !} shift-subst free i .(suc (x + k)) (var x) N | less .x k | yes p | no ¬q = {! !} shift-subst free i .(suc (x + k)) (var x) N | less .x k | no ¬p = {! !} shift-subst free i n (var .n) N | equal .n = {! !} shift-subst free i n (var .(suc (n + k))) N | greater .n k = {! !} shift-subst free i n (ƛ M) N = ƛ (shift (suc (suc (suc free))) i M [ shift free i N / suc n ]) →*⟨ cong-ƛ {! shift-subst (suc free) i (suc n) M N !} ⟩ {! !} →*⟨ {! !} ⟩ ƛ (shift (suc (suc (suc free))) i M [ shift (suc free) i N / suc n ]) →*⟨ cong-ƛ (shift-subst (suc free) i (suc n) M N) ⟩ ƛ (shift (suc (suc free)) i (M [ N / suc n ])) →∎ shift-subst free i n (M ∙ L) N = shift (suc (suc free)) i M [ shift free i N / n ] ∙ shift (suc (suc free)) i L [ shift free i N / n ] →*⟨ cong-∙-l (shift-subst free i n M N) ⟩ shift (suc free) i (M [ N / n ]) ∙ shift (suc (suc free)) i L [ shift free i N / n ] →*⟨ cong-∙-r (shift-subst free i n L N) ⟩ shift (suc free) i (M [ N / n ]) ∙ shift (suc free) i (L [ N / n ]) →∎ cong-shift-app0 : (free i : ℕ) → (M N : Term) → shift free i ((ƛ M) ∙ N) β→* shift free i (M [ N ]) cong-shift-app0 free i (var x) N = {! !} cong-shift-app0 free i (ƛ M) N = (ƛ (ƛ shift (suc (suc free)) i M)) ∙ shift free i N →*⟨ hop β-ƛ-∙ ⟩ (ƛ shift (suc (suc free)) i M) [ shift free i N / 0 ] →⟨⟩ ƛ (shift (suc (suc free)) i M) [ shift free i N / 1 ] →*⟨ cong-ƛ (shift-subst free i _ M N) ⟩ ƛ shift (suc free) i (M [ N / 1 ]) →∎ cong-shift-app0 free i (M ∙ L) N = (ƛ shift (suc free) i M ∙ shift (suc free) i L) ∙ shift free i N →*⟨ cong-∙-l {! cong-shift-app0 free i M L !} ⟩ {! !} ∙ shift free i N →*⟨ {! !} ⟩ {! !} →*⟨ {! !} ⟩ {! !} →*⟨ {! !} ⟩ shift free i (M [ N ]) ∙ shift free i (L [ N ]) →∎ -- cong-shift-app : (free i : ℕ) → (M N : Term) → shift free i ((ƛ M) ∙ N) β→* shift free i (M [ N ]) -- cong-shift-app free i (var x) (var y) = {! !} -- cong-shift-app free i (var x) (ƛ N) = {! !} -- cong-shift-app free i (var x) (N ∙ O) = {! !} -- cong-shift-app free i (ƛ M) (var y) = {! !} -- cong-shift-app free i (ƛ M) (ƛ N) = {! !} -- cong-shift-app free i (ƛ M) (N ∙ O) = {! !} -- cong-shift-app free i (M ∙ L) (var y) = {! !} -- cong-shift-app free i (M ∙ L) (ƛ N) = {! !} -- cong-shift-app free i (M ∙ L) (N ∙ O) = {! !} cong-shift : (free i : ℕ) → (M N : Term) → M β→ N → shift free i M β→* shift free i N cong-shift free i (ƛ M) (ƛ N) (β-ƛ M→N) = cong-ƛ (cong-shift (suc free) i M N M→N) cong-shift free i (.(ƛ M) ∙ N) .(M [ N / 0 ]) (β-ƛ-∙ {M}) = cong-shift-app0 free i M N cong-shift free i (M ∙ L) .(N ∙ L) (β-∙-l {N = N} M→N) = cong-∙-l (cong-shift free i M N M→N) cong-shift free i (M ∙ L) .(M ∙ N) (β-∙-r {N = N} M→N) = cong-∙-r (cong-shift free i L N M→N) cong-[] : ∀ {i M N} (L : Term) → M β→ N → L [ M / i ] β→* L [ N / i ] cong-[] {i} (var x) M→N with compare x i cong-[] {.(suc (x + k))} (var x) M→N | less .x k = ∎ cong-[] {.x} {M} {N} (var x) M→N | equal .x = cong-shift 0 x M N M→N cong-[] {.m} (var .(suc (m + k))) M→N | greater m k = ∎ cong-[] (ƛ L) M→N = cong-ƛ (cong-[] L M→N) cong-[] {i} {M} {N} (L ∙ K) M→N = L [ M / i ] ∙ K [ M / i ] →*⟨ cong-∙-l (cong-[] L M→N) ⟩ L [ N / i ] ∙ K [ M / i ] →*⟨ cong-∙-r (cong-[] K M→N) ⟩ L [ N / i ] ∙ K [ N / i ] →∎ lemma : ∀ {M N O} → ƛ M β→ N → M [ O ] β→* N ∙ O lemma {ƛ M} (β-ƛ {N = ƛ N} M→N) = {! !} lemma {M ∙ L} (β-ƛ {N = var x} M→N) = {! !} lemma {M ∙ L} (β-ƛ {N = ƛ N} M→N) = {! !} lemma {M ∙ L} (β-ƛ {N = N ∙ K} M→N) = {! !} -- single-step β→confluent : ∀ {M N O} → (M β→ N) → (M β→ O) → ∃ (λ P → (N β→* P) × (O β→* P)) β→confluent (β-ƛ-∙ {M} {N}) β-ƛ-∙ = M [ N ] , ∎ , ∎ β→confluent (β-ƛ-∙ {M} {N}) (β-∙-l {N = O} M→O) = {! !} -- O ∙ N , lemma M→O , ∎ β→confluent (β-ƛ-∙ {M} {N}) (β-∙-r {N = O} M→O) = M [ O ] , cong-[] M M→O , hop β-ƛ-∙ β→confluent (β-ƛ {M} {N} M→N) (β-ƛ {N = O} M→O) with β→confluent M→N M→O β→confluent (β-ƛ {M} {N} M→N) (β-ƛ {N = O} M→O) | P , N→P , O→P = ƛ P , cong-ƛ N→P , cong-ƛ O→P β→confluent (β-∙-l {L} {N = N} M→N) (β-ƛ-∙ {M}) = N ∙ L , ∎ , lemma M→N β→confluent (β-∙-l {L} {M} {N} M→N) (β-∙-l {N = O} M→O) with β→confluent M→N M→O β→confluent (β-∙-l {L} {M} {N} M→N) (β-∙-l {N = O} M→O) | P , N→P , O→P = P ∙ L , cong-∙-l N→P , cong-∙-l O→P β→confluent (β-∙-l {L} {M} {N} M→N) (β-∙-r {N = O} L→O) = N ∙ O , hop (β-∙-r L→O) , hop (β-∙-l M→N) β→confluent (β-∙-r {M = M} {N} M→N) (β-ƛ-∙ {L}) = L [ N ] , (hop β-ƛ-∙) , cong-[] L M→N β→confluent (β-∙-r {L} {M} {N} M→N) (β-∙-l {N = O} M→O) = O ∙ N , hop (β-∙-l M→O) , hop (β-∙-r M→N) β→confluent (β-∙-r {M = M} {N} M→N) (β-∙-r {N = O} M→O) with β→confluent M→N M→O β→confluent (β-∙-r {L} {M} {N} M→N) (β-∙-r {N = O} M→O) | P , N→P , O→P = (L ∙ P) , cong-∙-r N→P , cong-∙-r O→P -- β→confluent : (M N O : Term) → (M β→ N) → (M β→ O) → ∃ (λ P → (N β→* P) × (O β→* P)) -- β→confluent .((ƛ _) ∙ _) ._ ._ β-ƛ-∙ β-ƛ-∙ = {! !} -- β→confluent .((ƛ _) ∙ _) ._ .(_ ∙ _) β-ƛ-∙ (β-∙-l M→O) = {! !} -- β→confluent .((ƛ _) ∙ _) ._ .((ƛ _) ∙ _) β-ƛ-∙ (β-∙-r M→O) = {! !} -- β→confluent .(ƛ _) .(ƛ _) .(ƛ _) (β-ƛ M→N) (β-ƛ M→O) = {! !} -- β→confluent .((ƛ _) ∙ _) .(_ ∙ _) ._ (β-∙-l M→N) β-ƛ-∙ = {! !} -- β→confluent .(_ ∙ _) .(_ ∙ _) .(_ ∙ _) (β-∙-l M→N) (β-∙-l M→O) = {! !} -- β→confluent .(_ ∙ _) .(_ ∙ _) .(_ ∙ _) (β-∙-l M→N) (β-∙-r M→O) = {! !} -- β→confluent .((ƛ _) ∙ _) .((ƛ _) ∙ _) ._ (β-∙-r M→N) β-ƛ-∙ = {! !} -- β→confluent .(_ ∙ _) .(_ ∙ _) .(_ ∙ _) (β-∙-r M→N) (β-∙-l M→O) = {! !} -- β→confluent .(_ ∙ M) .(_ ∙ N) .(_ ∙ O) (β-∙-r {M = M} {N} M→N) (β-∙-r {N = O} M→O) with β→confluent M N O M→N M→O -- β→confluent .(_ ∙ M) .(_ ∙ N) .(_ ∙ O) (β-∙-r {M = M} {N} M→N) (β-∙-r {N = O} M→O) | P , N→P , O→P = {! !}
33.331646
130
0.394957
3436b22a246581bbfdc6102895b4455826aeba37
1,208
agda
Agda
test/Succeed/Issue2549.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2549.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2549.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K --rewriting --confluence-check #-} postulate _↦_ : {A : Set} → A → A → Set {-# BUILTIN REWRITE _↦_ #-} data _==_ {A : Set} (a : A) : A → Set where idp : a == a PathOver : {A : Set} (B : A → Set) {x y : A} (p : x == y) (u : B x) (v : B y) → Set PathOver B idp u v = (u == v) infix 30 PathOver syntax PathOver B p u v = u == v [ B ↓ p ] apd : {A : Set} {B : A → Set} (f : (a : A) → B a) {x y : A} → (p : x == y) → f x == f y [ B ↓ p ] apd f idp = idp module Disk where module _ where postulate -- HIT Disk : Set baseD : Disk loopD : baseD == baseD drumD : loopD == idp module DiskElim {P : Disk → Set} (baseD* : P baseD ) (loopD* : baseD* == baseD* [ P ↓ loopD ] ) (drumD* : loopD* == idp [ ((λ p → baseD* == baseD* [ P ↓ p ] ) ) ↓ drumD ] ) where postulate f : (x : Disk) → P x baseD-β : f baseD ↦ baseD* {-# REWRITE baseD-β #-} postulate loopD-ι : apd f loopD ↦ loopD* {-# REWRITE loopD-ι #-} postulate drumD-ι : apd (apd f) drumD ↦ drumD* {-# REWRITE drumD-ι #-} loopD-β : apd f loopD == loopD* loopD-β = idp drumD-β : apd (apd f) drumD == drumD* drumD-β = idp
21.963636
86
0.491722
d1f0f6dddd836c1c782562858a7d934688b5c60d
8,253
agda
Agda
LibraBFT/Abstract/Records.agda
haroldcarr/bft-consensus-agda
34e4627855fb198665d0c98f377403a906ba75d7
[ "UPL-1.0" ]
null
null
null
LibraBFT/Abstract/Records.agda
haroldcarr/bft-consensus-agda
34e4627855fb198665d0c98f377403a906ba75d7
[ "UPL-1.0" ]
null
null
null
LibraBFT/Abstract/Records.agda
haroldcarr/bft-consensus-agda
34e4627855fb198665d0c98f377403a906ba75d7
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Base.Types open import LibraBFT.Abstract.Types.EpochConfig open WithAbsVote -- This module defines abstract records (the initial or "genesis" record, blocks, and quorum -- certificates), along with related definitions and properties. module LibraBFT.Abstract.Records (UID : Set) (_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁)) -- Needed to prove ≟Block and ≈?QC (NodeId : Set) (𝓔 : EpochConfig UID NodeId) (𝓥 : VoteEvidence UID NodeId 𝓔) where open import LibraBFT.Abstract.Types UID NodeId open EpochConfig 𝓔 -- Abstract blocks do /not/ need to carry the state hash. Since the -- state hash of a concrete block is supposed to be hashed in the -- UID of an abstract one; the connection between states is implicit. -- Our proofs all work modulo injectivity of UID anyway. record Block : Set where constructor mkBlock field bRound : Round bId : UID bPrevQC : Maybe UID -- 'nothing' indicates it extends the genesis block. open Block public Block-η : {b b' : Block} → bRound b ≡ bRound b' → bId b ≡ bId b' → bPrevQC b ≡ bPrevQC b' → b ≡ b' Block-η refl refl refl = refl -- We define a Vote as an AbsVoteData applied -- to the correct parameters; This helps in defining -- and manipulating the 𝓥 vote evidence predicate. Vote : Set Vote = AbsVoteData UID NodeId 𝓔 vRound : Vote → Round vRound = abs-vRound vMember : Vote → EpochConfig.Member 𝓔 vMember = abs-vMember vBlockUID : Vote → UID vBlockUID = abs-vBlockUID Vote-η : {v v' : Vote} → vRound v ≡ vRound v' → vMember v ≡ vMember v' → vBlockUID v ≡ vBlockUID v' → v ≡ v' Vote-η refl refl refl = refl -- * Quorum Certificates -- -- A valid quorum certificate contains at least 'QuorumSize ec' -- votes from different authors. record QC : Set where constructor mkQC field qRound : Round qCertBlockId : UID -- this is the id for the block it certifies. qVotes : List Vote -- The voters form a quorum qVotes-C1 : IsQuorum (List-map vMember qVotes) -- All votes are for the same blockId qVotes-C2 : All (λ v → vBlockUID v ≡ qCertBlockId) qVotes -- Likewise for rounds qVotes-C3 : All (λ v → vRound v ≡ qRound) qVotes -- And we have evidence for all votes qVotes-C4 : All 𝓥 qVotes open QC public ------------------------ -- QC's make a setoid -- ------------------------ -- Two QC's are said to be equivalent if they have the same ID; -- that is, they certify the same block. As we are talking about -- /abstract/ QCs, we have proofs that both have at least QuorumSize -- votes for /the same block/! -- -- It might be tempting to want qRound q₀ ≡ qRound q₁ in here, -- but the proof of ←-≈Rec in LibraBFT.Abstract.Records.Extends -- would be impossible. _≈QC_ : QC → QC → Set q₀ ≈QC q₁ = qCertBlockId q₀ ≡ qCertBlockId q₁ _≈QC?_ : (q₀ q₁ : QC) → Dec (q₀ ≈QC q₁) q₀ ≈QC? q₁ with qCertBlockId q₀ ≟UID qCertBlockId q₁ ...| yes refl = yes refl ...| no neq = no λ x → neq x ≈QC-refl : Reflexive _≈QC_ ≈QC-refl = refl ≈QC-sym : Symmetric _≈QC_ ≈QC-sym refl = refl ≈QC-trans : Transitive _≈QC_ ≈QC-trans refl x = x QC-setoid : Setoid ℓ0 ℓ0 QC-setoid = record { Carrier = QC ; _≈_ = _≈QC_ ; isEquivalence = record { refl = λ {q} → ≈QC-refl {q} ; sym = λ {q} {u} → ≈QC-sym {q} {u} ; trans = λ {q} {u} {l} → ≈QC-trans {q} {u} {l} } } -- Accessing common fields in different Records types is a nuissance; yet, Blocks, -- votes and QC's all have three important common fields: author, round and maybe the -- ID of a previous record. Therefore we declare a type-class that provide "getters" -- for commonly used fields. record HasRound (A : Set) : Set where constructor is-librabft-record field getRound : A → Round open HasRound {{...}} public instance block-is-record : HasRound Block block-is-record = is-librabft-record bRound vote-is-record : HasRound Vote vote-is-record = is-librabft-record vRound qc-is-record : HasRound QC qc-is-record = is-librabft-record qRound _≟Block_ : (b₀ b₁ : Block) → Dec (b₀ ≡ b₁) b₀ ≟Block b₁ with bRound b₀ ≟ bRound b₁ ...| no neq = no λ x → neq (cong bRound x) ...| yes r≡ with (bId b₀) ≟UID (bId b₁) ...| no neq = no λ x → neq (cong bId x) ...| yes i≡ with Maybe-≡-dec {A = UID} _≟UID_ (bPrevQC b₀) (bPrevQC b₁) ...| no neq = no λ x → neq (cong bPrevQC x) ...| yes p≡ = yes (Block-η r≡ i≡ p≡) qcVotes : QC → List Vote qcVotes = qVotes -- Now we can state whether an author has voted in a given QC. _∈QC_ : Member → QC → Set a ∈QC qc = Any (λ v → vMember v ≡ a) (qcVotes qc) ∈QC-Member : ∀{α}(q : QC)(v : α ∈QC q) → α ≡ vMember (List-lookup (qcVotes q) (Any-index v)) ∈QC-Member {α} q v = aux v where aux : ∀{vs}(p : Any (λ v → vMember v ≡ α) vs) → α ≡ vMember (List-lookup vs (Any-index p)) aux (here px) = sym px aux (there p) = aux p -- Gets the vote of a ∈QC -- TODO-1: make q explicit; a implicit ∈QC-Vote : {a : Member} (q : QC) → (a ∈QC q) → Vote ∈QC-Vote q a∈q = Any-lookup a∈q ∈QC-Vote-correct : ∀ q → {a : Member} → (p : a ∈QC q) → (∈QC-Vote {a} q p) ∈ qcVotes q ∈QC-Vote-correct q a∈q = Any-lookup-correct a∈q -- Same vote in two QC's means the QCs are equivalent ∈QC-Vote-≈ : {v : Vote}{q q' : QC} → v ∈ qcVotes q → v ∈ qcVotes q' → q ≈QC q' ∈QC-Vote-≈ {v} {q} {q'} vq vq' = trans (sym (All-lookup (qVotes-C2 q) vq)) (All-lookup (qVotes-C2 q') vq') -- A record is either one of the types introduced above or the initial/genesis record. data Record : Set where I : Record B : Block → Record Q : QC → Record -- Records are equivalent if and only if they are either not -- QCs and propositionally equal or they are equivalent qcs. data _≈Rec_ : Record → Record → Set where eq-I : I ≈Rec I eq-Q : ∀{q₀ q₁} → q₀ ≈QC q₁ → Q q₀ ≈Rec Q q₁ eq-B : ∀{b₀ b₁} → b₀ ≡ b₁ → B b₀ ≈Rec B b₁ ≈Rec-refl : Reflexive _≈Rec_ ≈Rec-refl {I} = eq-I ≈Rec-refl {B x} = eq-B refl ≈Rec-refl {Q x} = eq-Q (≈QC-refl {x}) ≈Rec-sym : Symmetric _≈Rec_ ≈Rec-sym {I} eq-I = eq-I ≈Rec-sym {B x} (eq-B prf) = eq-B (sym prf) ≈Rec-sym {Q x} {Q y} (eq-Q prf) = eq-Q (≈QC-sym {x} {y} prf) ≈Rec-trans : Transitive _≈Rec_ ≈Rec-trans {I} eq-I eq-I = eq-I ≈Rec-trans {B x} (eq-B p₀) (eq-B p₁) = eq-B (trans p₀ p₁) ≈Rec-trans {Q x} {Q y} {Q z} (eq-Q p₀) (eq-Q p₁) = eq-Q (≈QC-trans {x} {y} {z} p₀ p₁) Rec-setoid : Setoid ℓ0 ℓ0 Rec-setoid = record { Carrier = Record ; _≈_ = _≈Rec_ ; isEquivalence = record { refl = λ {q} → ≈Rec-refl {q} ; sym = λ {q} {u} → ≈Rec-sym {q} {u} ; trans = λ {q} {u} {l} → ≈Rec-trans {q} {u} {l} } } -- Record unique ids carry whether the abstract id was assigned -- to a QC or a Block; this can be useful to avoid having to deal -- with 'blockId ≟ initialAgreedID' in order to decide whether -- a block is the genesis block or not. data TypedUID : Set where id-I : TypedUID id-B∨Q : UID -> TypedUID id-I≢id-B∨Q : ∀{id} → id-I ≡ id-B∨Q id → ⊥ id-I≢id-B∨Q () id-B∨Q-inj : ∀{u₁ u₂} → id-B∨Q u₁ ≡ id-B∨Q u₂ → u₁ ≡ u₂ id-B∨Q-inj refl = refl uid : Record → TypedUID uid I = id-I uid (B b) = id-B∨Q (bId b) uid (Q q) = id-B∨Q (qCertBlockId q) -- Each record has a round round : Record → Round round I = 0 round (B b) = getRound b round (Q q) = getRound q
32.620553
111
0.581122
19a3a6ca277f2c8a5502ee37f6f4c069f8a21d4d
9,557
agda
Agda
nicolai/anonymousExistence/library/Base.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
nicolai/anonymousExistence/library/Base.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
nicolai/anonymousExistence/library/Base.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} {- This file contains a bunch of basic stuff which is needed early. Maybe it should be organised better. -} module library.Base where {- Universes and typing Agda has explicit universe polymorphism, which means that there is an actual type of universe levels on which you can quantify. This type is called [ULevel] and comes equipped with the following operations: - [lzero] : [ULevel] (in order to have at least one universe) - [lsucc] : [ULevel → ULevel] (the [i]th universe level is a term in the [lsucc i]th universe) - [lmax] : [ULevel → ULevel → ULevel] (in order to type dependent products (where the codomain is in a uniform universe level) This type is postulated below and linked to Agda’s universe polymorphism mechanism via the BUILTIN commands (it’s the way it works). In plain Agda, the [i]th universe is called [Set i], which is not a very good name from the point of view of HoTT, so we define [Type] as a synonym of [Set] and [Set] should never be used again. -} open import Agda.Primitive renaming (lzero to lzero-pre) ULevel : Set ULevel = Level lzero : ULevel lzero = lzero-pre lsucc : ULevel → ULevel lsucc = lsuc lmax : ULevel → ULevel → ULevel lmax = _⊔_ Type : (i : ULevel) → Set (lsucc i) Type i = Set i Type₀ = Type lzero Type0 = Type lzero Type₁ = Type (lsucc lzero) Type1 = Type (lsucc lzero) {- There is no built-in or standard way to coerce an ambiguous term to a given type (like [u : A] in ML), the symbol [:] is reserved, and the Unicode [∶] is really a bad idea. So we’re using the symbol [_:>_], which has the advantage that it can micmic Coq’s [u = v :> A]. -} infix 10 of-type of-type : ∀ {i} (A : Type i) (u : A) → A of-type A u = u syntax of-type A u = u :> A {- Identity type The identity type is called [Path] and [_==_] because the symbol [=] is reserved in Agda. The constant path is [idp]. Note that all arguments of [idp] are implicit. -} infix 3 _==_ data _==_ {i} {A : Type i} (a : A) : A → Type i where idp : a == a Path = _==_ {-# BUILTIN EQUALITY _==_ #-} {-# BUILTIN REFL idp #-} {- Paulin-Mohring J rule At the time I’m writing this (July 2013), the identity type is somehow broken in Agda dev, it behaves more or less as the Martin-Löf identity type instead of behaving like the Paulin-Mohring identity type. So here is the Paulin-Mohring J rule -} J : ∀ {i j} {A : Type i} {a : A} (B : (a' : A) (p : a == a') → Type j) (d : B a idp) {a' : A} (p : a == a') → B a' p J B d idp = d {- Unit type The unit type is defined as record so that we also get the η-rule definitionally. -} record Unit : Type₀ where constructor unit {- Dependent paths The notion of dependent path is a very important notion. If you have a dependent type [B] over [A], a path [p : x == y] in [A] and two points [u : B x] and [v : B y], there is a type [u == v [ B ↓ p ]] of paths from [u] to [v] lying over the path [p]. By definition, if [p] is a constant path, then [u == v [ B ↓ p ]] is just an ordinary path in the fiber. -} PathOver : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y) (u : B x) (v : B y) → Type j PathOver B idp u v = (u == v) syntax PathOver B p u v = u == v [ B ↓ p ] {- Ap, coe and transport Given two fibrations over a type [A], a fiberwise map between the two fibrations can be applied to any dependent path in the first fibration ([ap↓]). As a special case, when [A] is [Unit], we find the familiar [ap] ([ap] is defined in terms of [ap↓] because it shouldn’t change anything for the user and this is helpful in some rare cases) -} ap : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y : A} → (x == y → f x == f y) ap f idp = idp ap↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} (g : {a : A} → B a → C a) {x y : A} {p : x == y} {u : B x} {v : B y} → (u == v [ B ↓ p ] → g u == g v [ C ↓ p ]) ap↓ g {p = idp} p = ap g p {- [apd↓] is defined in library.PathOver. Unlike [ap↓] and [ap], [apd] is not definitionally a special case of [apd↓] -} apd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A} → (p : x == y) → f x == f y [ B ↓ p ] apd f idp = idp {- An equality between types gives two maps back and forth -} coe : ∀ {i} {A B : Type i} (p : A == B) → A → B coe idp x = x coe! : ∀ {i} {A B : Type i} (p : A == B) → B → A coe! idp x = x {- The operations of transport forward and backward are defined in terms of [ap] and [coe], because this is more convenient in practice. -} transport : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y) → (B x → B y) transport B p = coe (ap B p) transport! : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y) → (B y → B x) transport! B p = coe! (ap B p) {- Π-types Shorter notation for Π-types. -} Π : ∀ {i j} (A : Type i) (P : A → Type j) → Type (lmax i j) Π A P = (x : A) → P x {- Σ-types Σ-types are defined as a record so that we have definitional η. -} infixr 1 _,_ record Σ {i j} (A : Type i) (B : A → Type j) : Type (lmax i j) where constructor _,_ field fst : A snd : B fst open Σ public pair= : ∀ {i j} {A : Type i} {B : A → Type j} {a a' : A} (p : a == a') {b : B a} {b' : B a'} (q : b == b' [ B ↓ p ]) → (a , b) == (a' , b') pair= idp q = ap (_,_ _) q pair×= : ∀ {i j} {A : Type i} {B : Type j} {a a' : A} (p : a == a') {b b' : B} (q : b == b') → (a , b) == (a' , b') pair×= idp q = pair= idp q {- Empty type We define the eliminator of the empty type using an absurd pattern. Given that absurd patterns are not consistent with HIT, we will not use empty patterns anymore after that. -} data Empty : Type₀ where Empty-elim : ∀ {i} {A : Empty → Type i} → ((x : Empty) → A x) Empty-elim () {- Negation and disequality -} ¬ : ∀ {i} (A : Type i) → Type i ¬ A = A → Empty _≠_ : ∀ {i} {A : Type i} → (A → A → Type i) x ≠ y = ¬ (x == y) {- Lifting to a higher universe level The operation of lifting enjoys both β and η definitionally. It’s a bit annoying to use, but it’s not used much (for now). -} record Lift {i j} (A : Type i) : Type (lmax i j) where constructor lift field lower : A open Lift public {- Equational reasoning Equational reasoning is a way to write readable chains of equalities. The idea is that you can write the following: t : a == e t = a =⟨ p ⟩ b =⟨ q ⟩ c =⟨ r ⟩ d =⟨ s ⟩ e ∎ where [p] is a path from [a] to [b], [q] is a path from [b] to [c], and so on. You often have to apply some equality in some context, for instance [p] could be [ap ctx thm] where [thm] is the interesting theorem used to prove that [a] is equal to [b], and [ctx] is the context. In such cases, you can use instead [thm |in-ctx ctx]. The advantage is that [ctx] is usually boring whereas the first word of [thm] is the most interesting part. _=⟨_⟩ is not definitionally the same thing as concatenation of paths _∙_ because we haven’t defined concatenation of paths yet, and also you probably shouldn’t reason on paths constructed with equational reasoning. If you do want to reason on paths constructed with equational reasoning, check out library.types.PathSeq instead. -} infix 2 _∎ infixr 2 _=⟨_⟩_ _=⟨_⟩_ : ∀ {i} {A : Type i} (x : A) {y z : A} → x == y → y == z → x == z _ =⟨ idp ⟩ idp = idp _∎ : ∀ {i} {A : Type i} (x : A) → x == x _ ∎ = idp syntax ap f p = p |in-ctx f {- Various basic functions and function operations The identity function on a type [A] is [idf A] and the constant function at some point [b] is [cst b]. Composition of functions ([_∘_]) can handle dependent functions. -} idf : ∀ {i} (A : Type i) → (A → A) idf A = λ x → x cst : ∀ {i j} {A : Type i} {B : Type j} (b : B) → (A → B) cst b = λ _ → b infixr 4 _∘_ _∘_ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → (B a → Type k)} → (g : {a : A} → Π (B a) (C a)) → (f : Π A B) → Π A (λ a → C a (f a)) g ∘ f = λ x → g (f x) -- Application infixr 0 _$_ _$_ : ∀ {i j} {A : Type i} {B : A → Type j} → (∀ x → B x) → (∀ x → B x) f $ x = f x -- (Un)curryfication curry : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Σ A B → Type k} → (∀ s → C s) → (∀ x y → C (x , y)) curry f x y = f (x , y) uncurry : ∀ {i j k} {A : Type i} {B : A → Type j} {C : ∀ x → B x → Type k} → (∀ x y → C x y) → (∀ s → C (fst s) (snd s)) uncurry f (x , y) = f x y -- (Un)curryfication with the first argument made implicit curryi : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Σ A B → Type k} → (∀ s → C s) → (∀ {x} y → C (x , y)) curryi f y = f (_ , y) uncurryi : ∀ {i j k} {A : Type i} {B : A → Type j} {C : ∀ x → B x → Type k} → (∀ {x} y → C x y) → (∀ s → C (fst s) (snd s)) uncurryi f (x , y) = f y {- Truncation levels The type of truncation levels is isomorphic to the type of natural numbers but "starts at -2". -} data TLevel : Type₀ where ⟨-2⟩ : TLevel S : (n : TLevel) → TLevel ℕ₋₂ = TLevel ⟨-1⟩ : TLevel ⟨-1⟩ = S ⟨-2⟩ ⟨0⟩ : TLevel ⟨0⟩ = S ⟨-1⟩ {- Coproducts and case analysis -} data Coprod {i j} (A : Type i) (B : Type j) : Type (lmax i j) where inl : A → Coprod A B inr : B → Coprod A B match_withl_withr_ : ∀ {i j k} {A : Type i} {B : Type j} {C : Coprod A B → Type k} (x : Coprod A B) (l : (a : A) → C (inl a)) (r : (b : B) → C (inr b)) → C x match (inl a) withl l withr r = l a match (inr b) withl l withr r = r b {- Used in a hack to make HITs maybe consistent. This is just a parametrized unit type (positively) -} data Phantom {i} {A : Type i} (a : A) : Type₀ where phantom : Phantom a {- -- When you want to cheat module ADMIT where postulate ADMIT : ∀ {i} {A : Type i} → A -}
25.899729
84
0.589202
fd5cce160ff8699e690d56ed27daa4eb1514c33c
11,954
agda
Agda
core/lib/types/Group.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/types/Group.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/types/Group.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.NType2 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-equiv : El ≃ El inv-equiv = equiv inv inv inv-inv inv-inv inv-is-equiv : is-equiv inv inv-is-equiv = snd inv-equiv 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 is-abelian-is-prop : ∀ {i} (G : Group i) → is-prop (is-abelian G) is-abelian-is-prop G = Π-level $ λ a → Π-level $ λ b → has-level-apply (Group.El-level G) _ _ 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 _ _ abgroup= : ∀ {i} (G H : AbGroup i) → AbGroup.grp G == AbGroup.grp H → G == H abgroup= {i} G H = Subtype=-out (is-abelian , is-abelian-is-prop) {- 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.366864
97
0.475155
30bd9361df0b673f9ee0314193b289e807691a6e
4,712
agda
Agda
sheaves.agda
jonsterling/Agda-Sheaves
8a06162a8f0f7df308458db91d720cf8f7345d69
[ "CC-BY-4.0" ]
1
2015-05-08T22:58:35.000Z
2015-05-08T22:58:35.000Z
sheaves.agda
jonsterling/Agda-Sheaves
8a06162a8f0f7df308458db91d720cf8f7345d69
[ "CC-BY-4.0" ]
null
null
null
sheaves.agda
jonsterling/Agda-Sheaves
8a06162a8f0f7df308458db91d720cf8f7345d69
[ "CC-BY-4.0" ]
null
null
null
{-# OPTIONS --type-in-type #-} record ⊤ : Set where constructor tt data ⊥ : Set where data _==_ {A : Set} (x : A) : A → Set where refl : x == x module _ (A : Set) (B : A → Set) where record Σ : Set where constructor _,_ field π₁ : A π₂ : B π₁ open Σ public syntax Σ A (λ x → B) = Σ[ x ∶ A ] B isContr : Set → Set isContr A = Σ[ x ∶ A ] (∀ y → x == y) Σ! : (A : Set) (B : A → Set) → Set Σ! A B = isContr (Σ A B) syntax Σ! A (λ x → B) = Σ![ x ∶ A ] B _×_ : (A B : Set) → Set A × B = Σ A λ _ → B P : Set → Set P A = A → Set module _ {A : Set} where empty : P A empty = λ x → ⊥ full : P A full = λ x → ⊤ _∩_ : P A → P A → P A U ∩ V = λ x → (U x) × (V x) _⊆_ : P A → P A → Set U ⊆ V = ∀ x → U x → V x ⋃[_] : P (P A) → P A ⋃[_] S = λ x → Σ[ U ∶ P A ] S U × U x record Topology (X : Set) : Set where field O : P (P X) empty-open : O empty full-open : O full inter-open : ∀ {U V} → O U → O V → O (U ∩ V) union-open : ∀ {S} → S ⊆ O → O ⋃[ S ] record Equivalence {A : Set} (R : A → A → Set) : Set where field reflexivity : {x : A} → R x x !_ : {x y : A} → R x y → R y x _∙_ : {x y z : A} → R y z → R x y → R x z infixr 9 _∙_ instance ==-equiv : ∀ {A} → Equivalence (_==_ {A}) ==-equiv = record { reflexivity = refl ; !_ = λ { {_} {._} refl → refl }; _∙_ = λ { {_} {._} {_} refl q → q } } record Category : Set where field Ob : Set Hom : Ob → Ob → Set _~_ : ∀ {A B} → Hom A B → Hom A B → Set ~-equiv : ∀ {A B} → Equivalence (_~_ {A} {B}) id : ∀ {A} → Hom A A _∘_ : ∀ {A B C} → Hom B C → Hom A B → Hom A C left-id : ∀ {A B} {f : Hom A B} → (id ∘ f) ~ f right-id : ∀ {A B} {f : Hom A B} → (f ∘ id) ~ f assoc : ∀ {A B C D} {f : Hom A B} {g : Hom B C} {h : Hom C D} → ((h ∘ g) ∘ f) ~ (h ∘ (g ∘ f)) instance ~-equiv-instance = ~-equiv opposite : Category opposite = let open Equivalence {{...}} in record { Ob = Ob ; Hom = λ A B → Hom B A ; _~_ = _~_ ; ~-equiv = ~-equiv ; id = id ; _∘_ = λ f g → g ∘ f ; left-id = λ {A} {B} → right-id ; right-id = λ {A} {B} → left-id ; assoc = λ {A} {B} {C} {D} {f} {g} {h} → ! assoc } record Functor (C D : Category) : Set where module C = Category C module D = Category D field apply : C.Ob → D.Ob map : ∀ {A B} → C.Hom A B → D.Hom (apply A) (apply B) id-law : ∀ {A} → map (C.id {A}) D.~ D.id comp-law : ∀ {A B C} (f : C.Hom B C) (g : C.Hom A B) → map (f C.∘ g) D.~ (map f D.∘ map g) instance open Equivalence {{...}} Types : Category Types = record { Ob = Set ; Hom = λ A B → A → B ; _~_ = λ f g → ∀ x → f x == g x ; ~-equiv = record { reflexivity = λ x → refl ; !_ = λ {f} {g} p x → ! p x ; _∙_ = λ {f} {g} {h} p q r → p r ∙ q r } ; id = λ {A} z → z ; _∘_ = λ {A} {B} {C} f g x → f (g x) ; left-id = λ {A} {B} {f} x → refl ; right-id = λ {A} {B} {f} x → refl ; assoc = λ x → refl } module _ (X : Set) (T : Topology X) where private module T = Topology T instance OpenSets : Category OpenSets = record { Ob = Σ _ T.O ; Hom = λ U V → π₁ U ⊆ π₁ V ; _~_ = _==_ ; ~-equiv = ==-equiv ; id = λ x z → z ; _∘_ = λ z z₁ x z₂ → z x (z₁ x z₂) ; left-id = refl ; right-id = refl ; assoc = refl } Presheaf : Set Presheaf = Functor (Category.opposite OpenSets) Types module _ (U : P X) (U-open : T.O U) where record Cover : Set where field Index : Set at : (i : Index) → P X at-open : (i : Index) → T.O (at i) at-subset : (i : Index) → at i ⊆ U covering : (x : X) → U x → Σ[ i ∶ Index ] at i x module _ (F : Presheaf) (<U> : Cover) where private module F = Functor F module <U> = Cover <U> Section : Set Section = ∀ i → F.apply (<U>.at i , <U>.at-open i) Coherence : Section → Set Coherence <s> = ∀ i j → let <U>ij = (<U>.at i ∩ <U>.at j) , (T.inter-open (<U>.at-open i) (<U>.at-open j) ) in F.map {<U>.at i , <U>.at-open i} {<U>ij} (λ _ → π₁) (<s> i) == F.map {<U>.at j , <U>.at-open j} {<U>ij} (λ _ → π₂) (<s> j) Sheaf : Presheaf → Set Sheaf F = let module F = Functor F in (U : P X) (U-open : T.O U) (<U> : Cover U U-open) (<s> : Section U _ F <U>) (coh : Coherence U _ F <U> <s>) → let module <U> = Cover _ _ <U> in Σ![ s ∶ F.apply (U , U-open) ] (∀ i → F.map {U , U-open} (<U>.at-subset i) s == <s> i)
23.918782
113
0.431452
1ceb60596b9e9e96fa6e550243f5bea2f706296b
482
agda
Agda
src/Category/Monad/Monotone/Identity.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
10
2017-11-17T17:10:36.000Z
2021-09-24T08:02:33.000Z
src/Category/Monad/Monotone/Identity.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2019-01-13T13:03:47.000Z
2020-10-14T13:41:58.000Z
src/Category/Monad/Monotone/Identity.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2021-12-28T17:38:05.000Z
2021-12-28T17:38:05.000Z
open import Relation.Binary open import Relation.Binary.PropositionalEquality module Category.Monad.Monotone.Identity {i}(pre : Preorder i i i) where open Preorder pre renaming (Carrier to I; _∼_ to _≤_; refl to ≤-refl) open import Relation.Unary.PredicateTransformer using (Pt) open import Category.Monad.Monotone pre open RawMPMonad Identity : Pt I i Identity = λ P i → P i instance id-monad : RawMPMonad Identity return id-monad px = px _≥=_ id-monad c f = f ≤-refl c
25.368421
71
0.753112
4b04b0339c0950d9864beeaad9f90327100591a9
207
agda
Agda
prototyping/FFI/Data/Bool.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
1
2022-02-11T21:30:17.000Z
2022-02-11T21:30:17.000Z
prototyping/FFI/Data/Bool.agda
FreakingBarbarians/luau
5187e64f88953f34785ffe58acd0610ee5041f5f
[ "MIT" ]
null
null
null
prototyping/FFI/Data/Bool.agda
FreakingBarbarians/luau
5187e64f88953f34785ffe58acd0610ee5041f5f
[ "MIT" ]
null
null
null
module FFI.Data.Bool where {-# FOREIGN GHC import qualified Data.Bool #-} data Bool : Set where false : Bool true : Bool {-# COMPILE GHC Bool = data Data.Bool.Bool (Data.Bool.False|Data.Bool.True) #-}
23
79
0.690821
1be4ede685cf02564cf7978c5b3b3aac8b060122
7,790
agda
Agda
Mockingbird/Problems/Chapter13.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
1
2022-02-28T23:44:42.000Z
2022-02-28T23:44:42.000Z
Mockingbird/Problems/Chapter13.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
Mockingbird/Problems/Chapter13.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
open import Mockingbird.Forest using (Forest) -- A Gallery of Sage Birds module Mockingbird.Problems.Chapter13 {b ℓ} (forest : Forest {b} {ℓ}) where open import Function using (_$_) open import Data.Product using (proj₂) open import Mockingbird.Forest.Birds forest import Mockingbird.Problems.Chapter09 forest as Chapter₉ import Mockingbird.Problems.Chapter10 forest as Chapter₁₀ import Mockingbird.Problems.Chapter11 forest as Chapter₁₁ import Mockingbird.Problems.Chapter12 forest as Chapter₁₂ open Forest forest problem₁ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasRobin ⦄ → HasSageBird problem₁ = record { Θ = B ∙ M ∙ (R ∙ M ∙ B) ; isSageBird = λ x → begin x ∙ (B ∙ M ∙ (R ∙ M ∙ B) ∙ x) ≈⟨ congˡ lemma ⟩ x ∙ (M ∙ (B ∙ x ∙ M)) ≈⟨ isFond ⟩ M ∙ (B ∙ x ∙ M) ≈˘⟨ lemma ⟩ B ∙ M ∙ (R ∙ M ∙ B) ∙ x ∎ } where isFond = λ {x} → proj₂ (Chapter₁₁.problem₂ x) lemma : ∀ {x} → B ∙ M ∙ (R ∙ M ∙ B) ∙ x ≈ M ∙ (B ∙ x ∙ M) lemma {x} = begin B ∙ M ∙ (R ∙ M ∙ B) ∙ x ≈⟨ isBluebird M (R ∙ M ∙ B) x ⟩ M ∙ (R ∙ M ∙ B ∙ x) ≈⟨ congˡ $ isRobin M B x ⟩ M ∙ (B ∙ x ∙ M) ∎ problem₂ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasCardinal ⦄ → HasSageBird problem₂ = record { Θ = B ∙ M ∙ (C ∙ B ∙ M) ; isSageBird = λ x → begin x ∙ (B ∙ M ∙ (C ∙ B ∙ M) ∙ x) ≈⟨ congˡ lemma ⟩ x ∙ (M ∙ (B ∙ x ∙ M)) ≈⟨ isFond ⟩ M ∙ (B ∙ x ∙ M) ≈˘⟨ lemma ⟩ B ∙ M ∙ (C ∙ B ∙ M) ∙ x ∎ } where isFond = λ {x} → proj₂ (Chapter₁₁.problem₂ x) lemma : ∀ {x} → B ∙ M ∙ (C ∙ B ∙ M) ∙ x ≈ M ∙ (B ∙ x ∙ M) lemma {x} = begin B ∙ M ∙ (C ∙ B ∙ M) ∙ x ≈⟨ isBluebird M (C ∙ B ∙ M) x ⟩ M ∙ (C ∙ B ∙ M ∙ x) ≈⟨ congˡ $ isCardinal B M x ⟩ M ∙ (B ∙ x ∙ M) ∎ problem₃ : ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasBluebird ⦄ ⦃ _ : HasLark ⦄ → HasSageBird problem₃ = record { Θ = B ∙ M ∙ L ; isSageBird = isSageBird ⦃ Chapter₁₀.hasSageBird ⦄ } where instance hasComposition = Chapter₁₁.problem₁ problem₄ : ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasBluebird ⦄ ⦃ _ : HasWarbler ⦄ → HasSageBird problem₄ = record { Θ = B ∙ M ∙ (B ∙ W ∙ B) ; isSageBird = isSageBird ⦃ problem₃ ⦄ } where instance hasLark = Chapter₁₂.problem₃ problem₆ : ⦃ _ : HasQueerBird ⦄ ⦃ _ : HasLark ⦄ ⦃ _ : HasWarbler ⦄ → HasSageBird problem₆ = record { Θ = W ∙ (Q ∙ L ∙ (Q ∙ L)) ; isSageBird = λ x → begin x ∙ (W ∙ (Q ∙ L ∙ (Q ∙ L)) ∙ x) ≈⟨ congˡ lemma ⟩ x ∙ (L ∙ x ∙ (L ∙ x)) ≈⟨ isFond ⟩ L ∙ x ∙ (L ∙ x) ≈˘⟨ lemma ⟩ W ∙ (Q ∙ L ∙ (Q ∙ L)) ∙ x ∎ } where isFond = λ {x} → proj₂ (Chapter₉.problem₂₅ x) lemma : ∀ {x} → W ∙ (Q ∙ L ∙ (Q ∙ L)) ∙ x ≈ L ∙ x ∙ (L ∙ x) lemma {x} = begin W ∙ (Q ∙ L ∙ (Q ∙ L)) ∙ x ≈⟨ isWarbler (Q ∙ L ∙ (Q ∙ L)) x ⟩ Q ∙ L ∙ (Q ∙ L) ∙ x ∙ x ≈⟨ congʳ $ isQueerBird L (Q ∙ L) x ⟩ Q ∙ L ∙ (L ∙ x) ∙ x ≈⟨ isQueerBird L (L ∙ x) x ⟩ L ∙ x ∙ (L ∙ x) ∎ problem₅ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasWarbler ⦄ → HasSageBird problem₅ = problem₆ where instance hasQueerBird = Chapter₁₁.problem₃₇′ hasLark = Chapter₁₂.problem₃ problem₇ = problem₅ problem₈ : ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasQueerBird ⦄ → HasSageBird problem₈ = record { Θ = Q ∙ (Q ∙ M) ∙ M ; isSageBird = λ x → sym $ begin Q ∙ (Q ∙ M) ∙ M ∙ x ≈⟨ isQueerBird (Q ∙ M) M x ⟩ M ∙ (Q ∙ M ∙ x) ≈⟨ isMockingbird (Q ∙ M ∙ x) ⟩ Q ∙ M ∙ x ∙ (Q ∙ M ∙ x) ≈⟨ isQueerBird M x (Q ∙ M ∙ x) ⟩ x ∙ (M ∙ (Q ∙ M ∙ x)) ≈˘⟨ congˡ $ isQueerBird (Q ∙ M) M x ⟩ x ∙ (Q ∙ (Q ∙ M) ∙ M ∙ x) ∎ } -- TODO: formalise regularity. problem₉ : ⦃ _ : HasStarling ⦄ ⦃ _ : HasLark ⦄ → HasSageBird problem₉ = record { Θ = S ∙ L ∙ L ; isSageBird = λ x → begin x ∙ (S ∙ L ∙ L ∙ x) ≈⟨ congˡ $ isStarling L L x ⟩ x ∙ (L ∙ x ∙ (L ∙ x)) ≈⟨ isFond ⟩ L ∙ x ∙ (L ∙ x) ≈˘⟨ isStarling L L x ⟩ S ∙ L ∙ L ∙ x ∎ } where isFond = λ {x} → proj₂ (Chapter₉.problem₂₅ x) problem₁₀ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasWarbler ⦄ ⦃ _ : HasStarling ⦄ → HasSageBird problem₁₀ = record { Θ = W ∙ S ∙ (B ∙ W ∙ B) ; isSageBird = λ x → begin x ∙ (W ∙ S ∙ (B ∙ W ∙ B) ∙ x) ≈⟨⟩ x ∙ (W ∙ S ∙ L ∙ x) ≈⟨ congˡ $ congʳ $ isWarbler S L ⟩ x ∙ (S ∙ L ∙ L ∙ x) ≈⟨ isSageBird ⦃ problem₉ ⦄ x ⟩ S ∙ L ∙ L ∙ x ≈˘⟨ congʳ $ isWarbler S L ⟩ W ∙ S ∙ L ∙ x ≈⟨⟩ W ∙ S ∙ (B ∙ W ∙ B) ∙ x ∎ } where instance hasLark = Chapter₁₂.problem₃ problem₁₁ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasThrush ⦄ → HasTuringBird problem₁₁ = record { U = B ∙ (B ∙ W ∙ (C ∙ B)) ∙ M ; isTuringBird = λ x y → begin B ∙ (B ∙ W ∙ (C ∙ B)) ∙ M ∙ x ∙ y ≈⟨ congʳ $ isBluebird (B ∙ W ∙ (C ∙ B)) M x ⟩ B ∙ W ∙ (C ∙ B) ∙ (M ∙ x) ∙ y ≈⟨ congʳ $ isBluebird W (C ∙ B) (M ∙ x) ⟩ W ∙ (C ∙ B ∙ (M ∙ x)) ∙ y ≈⟨ isWarbler (C ∙ B ∙ (M ∙ x)) y ⟩ C ∙ B ∙ (M ∙ x) ∙ y ∙ y ≈⟨ congʳ $ isCardinal B (M ∙ x) y ⟩ B ∙ y ∙ (M ∙ x) ∙ y ≈⟨ isBluebird y (M ∙ x) y ⟩ y ∙ (M ∙ x ∙ y) ≈⟨ congˡ $ congʳ $ isMockingbird x ⟩ y ∙ (x ∙ x ∙ y) ∎ } where instance hasCardinal = Chapter₁₁.problem₂₁′ hasLark = Chapter₁₂.problem₇ problem₁₂ : ⦃ _ : HasTuringBird ⦄ → HasSageBird problem₁₂ = record { Θ = U ∙ U ; isSageBird = λ x → sym $ isTuringBird U x } problem₁₃ : ⦃ _ : HasQueerBird ⦄ ⦃ _ : HasWarbler ⦄ → HasOwl problem₁₃ = record { O = Q ∙ Q ∙ W ; isOwl = λ x y → begin Q ∙ Q ∙ W ∙ x ∙ y ≈⟨ congʳ $ isQueerBird Q W x ⟩ W ∙ (Q ∙ x) ∙ y ≈⟨ isWarbler (Q ∙ x) y ⟩ Q ∙ x ∙ y ∙ y ≈⟨ isQueerBird x y y ⟩ y ∙ (x ∙ y) ∎ } problem₁₄ : ⦃ _ : HasOwl ⦄ ⦃ _ : HasLark ⦄ → HasTuringBird problem₁₄ = record { U = L ∙ O ; isTuringBird = λ x y → begin L ∙ O ∙ x ∙ y ≈⟨ congʳ $ isLark O x ⟩ O ∙ (x ∙ x) ∙ y ≈⟨ isOwl (x ∙ x) y ⟩ y ∙ (x ∙ x ∙ y) ∎ } problem₁₅ : ⦃ _ : HasOwl ⦄ ⦃ _ : HasIdentity ⦄ → HasMockingbird problem₁₅ = record { M = O ∙ I ; isMockingbird = λ x → begin O ∙ I ∙ x ≈⟨ isOwl I x ⟩ x ∙ (I ∙ x) ≈⟨ congˡ $ isIdentity x ⟩ x ∙ x ∎ } problem₁₆ : ⦃ _ : HasStarling ⦄ ⦃ _ : HasIdentity ⦄ → HasOwl problem₁₆ = record { O = S ∙ I ; isOwl = λ x y → begin S ∙ I ∙ x ∙ y ≈⟨ isStarling I x y ⟩ I ∙ y ∙ (x ∙ y) ≈⟨ congʳ $ isIdentity y ⟩ y ∙ (x ∙ y) ∎ } problem₁₇ : ∀ x y → x IsFondOf y → x IsFondOf x ∙ y problem₁₇ x y xy≈y = begin x ∙ (x ∙ y) ≈⟨ congˡ xy≈y ⟩ x ∙ y ∎ problem₁₈ : ⦃ _ : HasOwl ⦄ ⦃ _ : HasSageBird ⦄ → IsSageBird (O ∙ Θ) problem₁₈ x = begin x ∙ (O ∙ Θ ∙ x) ≈⟨ congˡ $ isOwl Θ x ⟩ x ∙ (x ∙ (Θ ∙ x)) ≈⟨ isFond ⟩ x ∙ (Θ ∙ x) ≈˘⟨ isOwl Θ x ⟩ O ∙ Θ ∙ x ∎ where isFond : x IsFondOf (x ∙ (Θ ∙ x)) isFond = problem₁₇ x (Θ ∙ x) (isSageBird x) problem₁₉ : ⦃ _ : HasOwl ⦄ ⦃ _ : HasSageBird ⦄ → IsSageBird (Θ ∙ O) problem₁₉ x = sym $ begin Θ ∙ O ∙ x ≈˘⟨ congʳ $ isSageBird O ⟩ O ∙ (Θ ∙ O) ∙ x ≈⟨ isOwl (Θ ∙ O) x ⟩ x ∙ (Θ ∙ O ∙ x) ∎ problem₂₀ : ⦃ _ : HasOwl ⦄ → ∀ A → O IsFondOf A → IsSageBird A problem₂₀ A OA≈A x = begin x ∙ (A ∙ x) ≈˘⟨ isOwl A x ⟩ O ∙ A ∙ x ≈⟨ congʳ OA≈A ⟩ A ∙ x ∎ problem₂₁ : ⦃ _ : HasSageBird ⦄ → ∀ A → IsChoosy A → IsSageBird (Θ ∙ A) problem₂₁ A isChoosy = isChoosy (Θ ∙ A) $ isSageBird A open import Mockingbird.Forest.Extensionality forest problem₂₂ : ⦃ _ : HasOwl ⦄ ⦃ _ : HasSageBird ⦄ → O ∙ Θ ≋ Θ problem₂₂ x = begin O ∙ Θ ∙ x ≈⟨ isOwl Θ x ⟩ x ∙ (Θ ∙ x) ≈⟨ isSageBird x ⟩ Θ ∙ x ∎ problem₂₃ : ⦃ _ : Extensional ⦄ ⦃ _ : HasOwl ⦄ ⦃ _ : HasSageBird ⦄ → O IsFondOf Θ problem₂₃ = ext problem₂₂
34.469027
88
0.479076
fd7e1d1806d3b77763ebef1094a1ae63c0da358d
628
agda
Agda
agda/Data/Bool/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Data/Bool/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Data/Bool/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe --postfix-projections #-} module Data.Bool.Properties where open import Prelude open import Data.Bool open import Data.Unit.Properties T? : ∀ x → Dec (T x) T? x .does = x T? false .why = ofⁿ id T? true .why = ofʸ tt isPropT : ∀ x → isProp (T x) isPropT false = isProp⊥ isPropT true = isProp⊤ discreteBool : Discrete Bool discreteBool false y .does = not y discreteBool true y .does = y discreteBool false false .why = ofʸ refl discreteBool false true .why = ofⁿ λ p → subst (bool ⊤ ⊥) p tt discreteBool true false .why = ofⁿ λ p → subst (bool ⊥ ⊤) p tt discreteBool true true .why = ofʸ refl
25.12
62
0.694268
21417e081c21bb108e35c79f8c1c2a033ed16574
867
agda
Agda
test/LibSucceed/InstanceArguments/05-equality-std1.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/LibSucceed/InstanceArguments/05-equality-std1.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
null
null
null
test/LibSucceed/InstanceArguments/05-equality-std1.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --universe-polymorphism #-} -- {-# OPTIONS --verbose tc.records.ifs:15 #-} -- {-# OPTIONS --verbose tc.constr.findInScope:15 #-} -- {-# OPTIONS --verbose tc.term.args.ifs:15 #-} module InstanceArguments.05-equality-std1 where open import Relation.Binary.PropositionalEquality hiding (decSetoid) open import Relation.Nullary open import Relation.Binary using (IsDecEquivalence; module IsDecEquivalence; Reflexive; module DecSetoid) open import Data.Bool using (false; true; decSetoid) open DecSetoid decSetoid using (isDecEquivalence) open module IsDecEquivalenceWithImplicits = IsDecEquivalence {{...}} using (_≟_) instance boolInstance = isDecEquivalence test : Dec (false ≡ true) test = false ≟ true test2 : ∀ {a ℓ} {A : Set a} {_≈_} → {{ide : IsDecEquivalence {a} {ℓ} {A} _≈_}} → Reflexive _≈_ test2 = IsDecEquivalenceWithImplicits.refl
34.68
106
0.732411
fdc64be9acc5d83cca96acca233d29ebd776c972
80,714
agda
Agda
lib/Haskell/RangedSetsProp/RangedSetProperties.agda
ioanasv/agda2hs
17cdbeb36af3d0b735c5db83bb811034c39a19cd
[ "MIT" ]
1
2021-05-25T09:41:34.000Z
2021-05-25T09:41:34.000Z
lib/Haskell/RangedSetsProp/RangedSetProperties.agda
ioanasv/agda2hs
17cdbeb36af3d0b735c5db83bb811034c39a19cd
[ "MIT" ]
null
null
null
lib/Haskell/RangedSetsProp/RangedSetProperties.agda
ioanasv/agda2hs
17cdbeb36af3d0b735c5db83bb811034c39a19cd
[ "MIT" ]
null
null
null
module Haskell.RangedSetsProp.RangedSetProperties where open import Haskell.RangedSetsProp.library open import Haskell.RangedSetsProp.RangesProperties open import Agda.Builtin.Equality open import Agda.Builtin.Bool open import Haskell.Prim open import Haskell.Prim.Ord open import Haskell.Prim.Bool open import Haskell.Prim.Maybe open import Haskell.Prim.Enum open import Haskell.Prim.Eq open import Haskell.Prim.List open import Haskell.Prim.Integer open import Haskell.Prim.Double open import Haskell.Prim.Foldable open import Haskell.RangedSets.Boundaries open import Haskell.RangedSets.Ranges open import Haskell.RangedSets.RangedSet prop_empty : ⦃ o : Ord a ⦄ → ⦃ d : DiscreteOrdered a ⦄ → (v : a) → (not (rSetHas rSetEmpty {empty ⦃ o ⦄ ⦃ d ⦄} v)) ≡ true prop_empty v = refl prop_full : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (v : a) → (rSetHas rSetFull {full0 ⦃ o ⦄ ⦃ dio ⦄} v) ≡ true prop_full v = refl prop_validNormalised : ⦃ o : Ord a ⦄ → ⦃ d : DiscreteOrdered a ⦄ → (ls : List (Range a)) → (validRangeList (normaliseRangeList ls)) ≡ true prop_validNormalised ⦃ o ⦄ ⦃ dio ⦄ [] = refl prop_validNormalised ⦃ o ⦄ ⦃ dio ⦄ ls@(r1 ∷ rs) = begin (validRangeList (normaliseRangeList ls)) =⟨⟩ (validRangeList (normalise (sort (filter (λ r → (rangeIsEmpty r) == false) ls)) ⦃ sortedList ls ⦄ ⦃ validRangesList ls ⦄)) =⟨ propIsTrue (validRangeList (normalise (sort (filter (λ r → (rangeIsEmpty r) == false) ls)) ⦃ sortedList ls ⦄ ⦃ validRangesList ls ⦄)) (normalisedSortedList (sort (filter (λ r → (rangeIsEmpty r) == false) ls)) (sortedList ls) (validRangesList ls)) ⟩ true end postulate rangeSetCreation : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {prf : IsTrue (validRangeList (rSetRanges rs))} → (RS ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs) {prf}) ≡ rs rangesEqiv : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {rs1 rs2 : RSet a} → rSetRanges rs1 ≡ rSetRanges rs2 → rs1 ≡ rs2 rangesEqiv2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {rs1 rs2 : List (Range a)} → (prf1 : IsTrue (sortedRangeList rs1)) → (prf2 : IsTrue (validRanges rs1)) → (prf3 : IsTrue (sortedRangeList rs2)) → (prf4 : IsTrue (validRanges rs2)) → rs1 ≡ rs2 → normalise rs1 ⦃ prf1 ⦄ ⦃ prf2 ⦄ ≡ normalise rs2 ⦃ prf3 ⦄ ⦃ prf4 ⦄ singletonRangeSetHas : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r : Range a) → (v : a) → {prf : IsTrue (validRangeList (r ∷ []))} → (rSetHas (RS (r ∷ []) {prf}) {prf} v) ≡ rangeHas r v singletonRangeSetHas r v {prf} = begin (rSetHas (RS (r ∷ []) {prf}) {prf} v) =⟨⟩ rangeHas r v end rSetHasHelper : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → a → (rs : List (Range a)) → {prf : IsTrue (validRangeList rs)} → Bool rSetHasHelper ⦃ o ⦄ ⦃ dio ⦄ value rs {prf} = rSetHas ⦃ o ⦄ ⦃ dio ⦄ (RS rs {prf}) {prf} value -- rangeHasSym : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r : Range a) → (rs : RSet a) → (v : a) -- → {prf1 : IsTrue (validRangeList (r ∷ (rSetRanges rs)))} -- → (rSetHas (RS (r ∷ (rSetRanges rs)) {prf1}) {prf1} v) ≡ -- ((rangeHas r v) || (rSetHas rs {headandtail (RS (r ∷ (rSetRanges rs)) {prf1}) prf1} v)) -- rangeHasSym ⦃ o ⦄ ⦃ dio ⦄ r rs@(RS []) v {prf1} = -- begin -- (rSetHas (RS (r ∷ []) {prf1}) {prf1} v) -- =⟨⟩ -- (rangeHas r v) -- =⟨ sym (prop_or_false2 (rangeHas r v)) ⟩ -- ((rangeHas r v) || false) -- =⟨⟩ -- ((rangeHas r v) || (rSetHas (RS [] {empty ⦃ o ⦄ ⦃ dio ⦄}) {empty ⦃ o ⦄ ⦃ dio ⦄} v)) -- end -- rangeHasSym ⦃ o ⦄ ⦃ d ⦄ r rs@(RS ranges@(r1 ∷ r2) {prf}) v {prf1} = -- begin -- ((RS (r ∷ (rSetRanges rs)) {prf1}) -?- v) -- =⟨⟩ -- ((rangeHas r v) || (rSetHas (RS (rSetRanges rs) {headandtail (RS (r ∷ (rSetRanges rs)) {prf1}) prf1}) v)) -- =⟨ cong ((rangeHas r v) ||_) (cong (rSetHasHelper v) (rangesEqiv refl)) ⟩ -- ((rangeHas r v) || (rSetHas rs v)) -- end postulate -- the following postulates hold when the boundaries are ordered emptyIntersection : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b1 b2 b3 : Boundary a) → IsFalse (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false) emptyIntersection2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b1 b2 b3 : Boundary a) → IsFalse (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) orderedBoundaries2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b1 b2 : Boundary a) → IsFalse (b2 < b1) -- used for easing the proofs, the true value should be IsTrue (b1 <= b2) orderedBoundaries3 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b1 b2 : Boundary a) → IsTrue (b1 < b2) {-# TERMINATING #-} lemma0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {prf : IsTrue (validRangeList (rSetRanges rs))} → (ranges1 (bounds1 (rSetRanges rs))) ≡ (rSetRanges rs) lemma0 ⦃ o ⦄ ⦃ dio ⦄ rs@(RS []) {_} = begin (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs))) =⟨⟩ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ [])) =⟨⟩ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ []) =⟨⟩ [] =⟨⟩ rSetRanges rs end lemma0 ⦃ o ⦄ ⦃ dio ⦄ rs@(RS (r@(Rg l u) ∷ rgs)) {prf} = begin (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs))) =⟨⟩ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (r ∷ rgs))) =⟨⟩ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ ((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r) ∷ ((rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r) ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rgs)))) =⟨⟩ ((Rg l u) ∷ ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rgs)) =⟨⟩ (r ∷ ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rgs)) =⟨ cong (r ∷_) (lemma0 ⦃ o ⦄ ⦃ dio ⦄ (RS rgs {headandtail rs prf}) {headandtail rs prf}) ⟩ (r ∷ rgs) =⟨⟩ rSetRanges rs end rangeEmpty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : Boundary a) → rangeIsEmpty (Rg x x) ≡ true rangeEmpty ⦃ o ⦄ ⦃ dio ⦄ BoundaryBelowAll = refl rangeEmpty ⦃ o ⦄ ⦃ dio ⦄ BoundaryAboveAll = refl rangeEmpty ⦃ o ⦄ ⦃ dio ⦄ b@(BoundaryBelow m) = begin rangeIsEmpty (Rg b b) =⟨⟩ ((BoundaryBelow m) <= (BoundaryBelow m)) =⟨⟩ ((compare b b == LT) || (compare b b == EQ)) =⟨⟩ ((compare m m == LT) || (compare m m == EQ)) =⟨ cong ((compare m m == LT) ||_) (eq4 ⦃ o ⦄ refl) ⟩ ((compare m m == LT) || true) =⟨⟩ ((compare m m == LT) || true) =⟨ prop_or_false3 (compare m m == LT) ⟩ true end rangeEmpty ⦃ o ⦄ ⦃ dio ⦄ b@(BoundaryAbove m) = begin rangeIsEmpty (Rg b b) =⟨⟩ ((BoundaryBelow m) <= (BoundaryBelow m)) =⟨⟩ ((compare b b == LT) || (compare b b == EQ)) =⟨⟩ ((compare m m == LT) || (compare m m == EQ)) =⟨ cong ((compare m m == LT) ||_) (eq4 ⦃ o ⦄ refl) ⟩ ((compare m m == LT) || true) =⟨⟩ ((compare m m == LT) || true) =⟨ prop_or_false3 (compare m m == LT) ⟩ true end merge2Empty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (bs : List (Boundary a)) → ⦃ ne : NonEmpty bs ⦄ → filter (λ x → rangeIsEmpty x == false) (merge2 (ranges1 (tail bs ⦃ ne ⦄)) (ranges1 bs)) ≡ [] merge2Empty2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (bs : List (Boundary a)) → ⦃ ne : NonEmpty bs ⦄ → filter (λ x → rangeIsEmpty x == false) (merge2 (ranges1 bs) (ranges1 (tail bs ⦃ ne ⦄))) ≡ [] merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryAboveAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b ∷ [])) (ranges1 [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] []) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryAbove x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b ∷ [])) (ranges1 [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) []) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryBelow x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b ∷ [])) (ranges1 [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) []) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryBelowAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b ∷ [])) (ranges1 [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) []) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAboveAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ [])) (ranges1 (b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 [])) []) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAboveAll) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ bs)) (ranges1 (b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) ((Rg b2 b3) ∷ (ranges1 bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (if_then_else_ (b2 < b3) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))) (merge2 (ranges1 bounds) (ranges1 bss)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷_) (propIf2 (b2 < b3) (orderedBoundaries3 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ propIf3' ⦃ o ⦄ {((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))))} {(filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))))} (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ merge2Empty ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelowAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ [])) (ranges1 (b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 [])) ((Rg b2 BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ []) ((Rg b2 BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (if_then_else_ (b2 < BoundaryAboveAll) (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ [])) (merge2 ((Rg b1 b2) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (if_then_else_ false (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ [])) (merge2 ((Rg b1 b2) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (merge2 ((Rg b1 b2) ∷ []) [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 ((rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) == false)) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelowAll) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ bs)) (ranges1 (b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) ((Rg b2 b3) ∷ (ranges1 bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (if_then_else_ (b2 < b3) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) (ranges1 bss) ))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷_) (propIf2 (b2 < b3) (orderedBoundaries3 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ merge2Empty ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAbove x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ [])) (ranges1 (b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 [])) ((Rg b2 BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ []) ((Rg b2 BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (if_then_else_ (b2 < BoundaryAboveAll) (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ [])) (merge2 ((Rg b1 b2) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (if_then_else_ true (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ [])) (merge2 ((Rg b1 b2) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 ((rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) == false)) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAbove x) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ bs)) (ranges1 (b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) ((Rg b2 b3) ∷ (ranges1 bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (if_then_else_ (b2 < b3) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) (ranges1 bss)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷_) (propIf2 (b2 < b3) (orderedBoundaries3 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ merge2Empty ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelow x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ [])) (ranges1 (b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 [])) ((Rg b2 BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ []) ((Rg b2 BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (if_then_else_ (b2 < BoundaryAboveAll) (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ [])) (merge2 ((Rg b1 b2) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (if_then_else_ true (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ [])) (merge2 ((Rg b1 b2) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (merge2 [] ((Rg b2 BoundaryAboveAll) ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 ((rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 BoundaryAboveAll)) == false)) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelow x) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bounds) (ranges1 (tail bounds ⦃ ne ⦄))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b1 ∷ b2 ∷ bs)) (ranges1 (b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) ((Rg b2 b3) ∷ (ranges1 bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (if_then_else_ (b2 < b3) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))) (merge2 ((Rg b1 b2) ∷ (ranges1 bs)) (ranges1 bss)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷_) (propIf2 (b2 < b3) (orderedBoundaries3 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) ((rangeIntersection (Rg b1 b2) (Rg b2 b3)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b1 b2) (Rg b2 b3)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b2 ∷ bs)))) =⟨ merge2Empty ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryBelowAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryBelow x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryAbove x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b@(BoundaryAboveAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAboveAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ [])) (ranges1 (b1 ∷ b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] ((Rg b1 b2) ∷ (ranges1 []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAboveAll) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 (b1 ∷ b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 b3) ∷ (ranges1 bss)) ((Rg b1 b2) ∷ (ranges1 bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (if_then_else_ (b3 < b2) (merge2 (ranges1 bss) ((Rg b1 b2) ∷ (ranges1 bs))) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷_) (propIf3 (b3 < b2) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ propIf3' ⦃ o ⦄ {((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))))} {(filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))} (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelowAll) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ [])) (ranges1 (b1 ∷ b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) ((Rg b1 b2) ∷ (ranges1 []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) ((Rg b1 b2) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (if_then_else_ (BoundaryAboveAll < b2) (merge2 [] ((Rg b1 b2) ∷ [])) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (if_then_else_ false (merge2 [] ((Rg b1 b2) ∷ [])) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 ((rangeIsEmpty (rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) == false)) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelowAll) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 (b1 ∷ b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 b3) ∷ (ranges1 bss)) ((Rg b1 b2) ∷ (ranges1 bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (if_then_else_ (b3 < b2) (merge2 (ranges1 bss) ((Rg b1 b2) ∷ (ranges1 bs))) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷_) (propIf3 (b3 < b2) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false)(emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAbove x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ [])) (ranges1 (b1 ∷ b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) ((Rg b1 b2) ∷ (ranges1 []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) ((Rg b1 b2) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (if_then_else_ (BoundaryAboveAll < b2) (merge2 [] ((Rg b1 b2) ∷ [])) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (if_then_else_ false (merge2 [] ((Rg b1 b2) ∷ [])) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 ((rangeIsEmpty (rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) == false)) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryAbove x) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 (b1 ∷ b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 b3) ∷ (ranges1 bss)) ((Rg b1 b2) ∷ (ranges1 bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (if_then_else_ (b3 < b2) (merge2 (ranges1 bss) ((Rg b1 b2) ∷ (ranges1 bs))) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷_) (propIf3 (b3 < b2) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false)(emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelow x) ∷ []) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ [])) (ranges1 (b1 ∷ b2 ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) ((Rg b1 b2) ∷ (ranges1 []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) ((Rg b1 b2) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (if_then_else_ (BoundaryAboveAll < b2) (merge2 [] ((Rg b1 b2) ∷ [])) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (if_then_else_ false (merge2 [] ((Rg b1 b2) ∷ [])) (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (merge2 ((Rg b2 BoundaryAboveAll) ∷ []) [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 ((rangeIsEmpty (rangeIntersection (Rg b2 BoundaryAboveAll) (Rg b1 b2)) == false)) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2Empty ⦃ o ⦄ ⦃ dio ⦄ bounds@(b1 ∷ b2@(BoundaryBelow x) ∷ bs@(b3 ∷ bss)) ⦃ ne ⦄ = begin filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (tail bounds ⦃ ne ⦄)) (ranges1 bounds)) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 (b1 ∷ b2 ∷ bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b2 b3) ∷ (ranges1 bss)) ((Rg b1 b2) ∷ (ranges1 bs))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (if_then_else_ (b3 < b2) (merge2 (ranges1 bss) ((Rg b1 b2) ∷ (ranges1 bs))) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷_) (propIf3 (b3 < b2) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ b2 b3))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false) ((rangeIntersection (Rg b2 b3) (Rg b1 b2)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs)))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b2 b3) (Rg b1 b2)) == false)(emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ b1 b2 b3) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 (b2 ∷ bs)) (ranges1 bs))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs) ⟩ -- induction here!!!! merge2Empty .. [] end lemma2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (bs : List (Boundary a)) → (filter (λ x → rangeIsEmpty x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) ≡ [] lemma2 ⦃ o ⦄ ⦃ dio ⦄ [] = begin (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 []) (ranges1 (setBounds1 [])))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] (ranges1 (BoundaryBelowAll ∷ [])))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ []))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(BoundaryBelowAll ∷ []) = begin (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ []) (ranges1 (setBounds1 (BoundaryBelowAll ∷ []))))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ []) (ranges1 []))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ []) [])) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(BoundaryAboveAll ∷ []) = begin (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)(merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 [] (ranges1 (setBounds1 (BoundaryAboveAll ∷ []))))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(b@(BoundaryBelow x) ∷ []) = begin (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) (ranges1 (setBounds1 ((BoundaryBelow x) ∷ []))))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) (ranges1 (BoundaryBelowAll ∷ (b ∷ []))))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) ((Rg BoundaryBelowAll b) ∷ []))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (if_then_else_ (BoundaryAboveAll < b) (merge2 [] ((Rg BoundaryBelowAll b) ∷ [])) (merge2 ((Rg b BoundaryAboveAll) ∷ []) [])))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (if_then_else_ false (merge2 [] ((Rg BoundaryBelowAll b) ∷ [])) (merge2 ((Rg b BoundaryAboveAll) ∷ []) [])))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (merge2 ((Rg b BoundaryAboveAll) ∷ []) []))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ [])) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) == false) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ BoundaryBelowAll b BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(b@(BoundaryAbove x) ∷ []) = begin (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) (ranges1 (setBounds1 (b ∷ []))))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) (ranges1 (BoundaryBelowAll ∷ (b ∷ []))))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg b BoundaryAboveAll) ∷ []) ((Rg BoundaryBelowAll b) ∷ []))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (if_then_else_ (BoundaryAboveAll < b) (merge2 [] ((Rg BoundaryBelowAll b) ∷ [])) (merge2 ((Rg b BoundaryAboveAll) ∷ []) [])))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (if_then_else_ false (merge2 [] ((Rg BoundaryBelowAll b) ∷ [])) (merge2 ((Rg b BoundaryAboveAll) ∷ []) [])))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (merge2 ((Rg b BoundaryAboveAll) ∷ []) []))) =⟨⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ [])) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) == false) ((rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg b BoundaryAboveAll) (Rg BoundaryBelowAll b)) == false) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ BoundaryBelowAll b BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryAboveAll) ∷ (b ∷ bss)) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) (ranges1 (setBounds1 (a ∷ (b ∷ bss))))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) (ranges1 (BoundaryBelowAll ∷ (a ∷ (b ∷ bss))))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) ((Rg BoundaryBelowAll a) ∷ ranges1 (b ∷ bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (if_then_else_ (b < a) (merge2 (ranges1 bss) (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷_) (propIf3 (b < a) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ a b))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨ propIf3' ⦃ o ⦄ {((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))))} {(filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))} (rangeIsEmpty (rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) == false) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ BoundaryBelowAll a b) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bs ⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryBelow x) ∷ (b ∷ bss)) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) (ranges1 (setBounds1 (a ∷ (b ∷ bss))))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) (ranges1 (BoundaryBelowAll ∷ (a ∷ (b ∷ bss))))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) ((Rg BoundaryBelowAll a) ∷ ranges1 (b ∷ bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (if_then_else_ (b < a) (merge2 (ranges1 bss) (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷_) (propIf3 (b < a) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ a b))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) == false) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ BoundaryBelowAll a b) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bs ⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryAbove x) ∷ (b ∷ bss)) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) (ranges1 (setBounds1 (a ∷ (b ∷ bss))))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) (ranges1 (BoundaryBelowAll ∷ (a ∷ (b ∷ bss))))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bss)) ((Rg BoundaryBelowAll a) ∷ ranges1 (b ∷ bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (if_then_else_ (b < a) (merge2 (ranges1 bss) (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷_) (propIf3 (b < a) (orderedBoundaries2 ⦃ o ⦄ ⦃ dio ⦄ a b))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) == false) ((rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg a b) (Rg BoundaryBelowAll a)) == false) (emptyIntersection ⦃ o ⦄ ⦃ dio ⦄ BoundaryBelowAll a b) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (b ∷ bss)))) =⟨ merge2Empty2 ⦃ o ⦄ ⦃ dio ⦄ bs ⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryBelowAll) ∷ b ∷ bs2@(c ∷ bss)) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bs2)) (ranges1 (b ∷ bs2))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 bs2)) ((Rg b c) ∷ (ranges1 bss))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b c)) ∷ (if_then_else_ (b < c) (merge2 (ranges1 bs2) (ranges1 (b ∷ bs2))) (merge2 (ranges1 bs) (ranges1 bss)))) =⟨ cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong ((rangeIntersection (Rg a b) (Rg b c)) ∷_) (propIf2 (b < c) (orderedBoundaries3 ⦃ o ⦄ ⦃ dio ⦄ b c))) ⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b c)) ∷ (merge2 (ranges1 bs2) (ranges1 (b ∷ bs2)))) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b c)) == false) ((rangeIntersection (Rg a b) (Rg b c)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs2) (ranges1 (b ∷ bs2))))) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs2) (ranges1 (b ∷ bs2)))) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b c)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ a b c) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs2) (ranges1 (b ∷ bs2)))) =⟨ merge2Empty ⦃ o ⦄ ⦃ dio ⦄ (b ∷ bs2) ⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryBelowAll) ∷ b@(BoundaryAboveAll) ∷ []) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 [])) (ranges1 (setBounds1 (a ∷ b ∷ [])))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)(merge2 ((Rg a b) ∷ []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) []) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [] =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryBelowAll) ∷ b@(BoundaryBelowAll) ∷ []) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 [])) (ranges1 (setBounds1 (a ∷ b ∷ [])))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) ((Rg b BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (if_then_else_ (b < BoundaryAboveAll) (merge2 [] (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (if_then_else_ true (merge2 [] (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (merge2 [] (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3' ⦃ o ⦄ {((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []))} {(filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) } (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ a b BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryBelowAll) ∷ b@(BoundaryAbove x) ∷ []) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 [])) (ranges1 (setBounds1 (a ∷ b ∷ [])))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) ((Rg b BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (if_then_else_ (b < BoundaryAboveAll) (merge2 [] (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (if_then_else_ true (merge2 [] (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (merge2 [] (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ a b BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end lemma2 ⦃ o ⦄ ⦃ dio ⦄ bs@(a@(BoundaryBelowAll) ∷ b@(BoundaryBelow x) ∷ []) = (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 bs) (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ (ranges1 [])) (ranges1 (setBounds1 (a ∷ b ∷ [])))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) (ranges1 (b ∷ []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ((Rg a b) ∷ []) ((Rg b BoundaryAboveAll) ∷ [])) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (if_then_else_ (b < BoundaryAboveAll) (merge2 [] (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (if_then_else_ true (merge2 [] (ranges1 (setBounds1 bs))) (merge2 (ranges1 bs) []))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (merge2 [] (ranges1 (setBounds1 bs)))) =⟨⟩ filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ []) =⟨⟩ if_then_else_ (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) == false) ((rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) ∷ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) [])) (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨ propIf3 (rangeIsEmpty (rangeIntersection (Rg a b) (Rg b BoundaryAboveAll)) == false) (emptyIntersection2 ⦃ o ⦄ ⦃ dio ⦄ a b BoundaryAboveAll) ⟩ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) []) =⟨⟩ [] end merge2' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → List (Range a) → List (Range a) merge2' ms1 ms2 = merge2 ms2 ms1 prop_empty_intersection : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {prf : IsTrue (validRangeList (rSetRanges rs))} → rSetIsEmpty (rSetIntersection rs {prf} (rSetNegation rs {prf}) {negation2 rs (negation rs prf)}) ≡ true prop_empty_intersection ⦃ o ⦄ ⦃ dio ⦄ rs@(RS ranges) {prf} = begin rSetIsEmpty (rSetIntersection rs {prf} (rSetNegation rs {prf}) {negation2 rs {prf} (negation rs prf)}) =⟨⟩ rSetIsEmpty (rSetIntersection rs {prf} (RS (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges))) {negation rs prf}) {negation2 rs {prf} (negation rs prf)} ) =⟨⟩ rSetIsEmpty (RS (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ranges (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges))))) {intersection0 rs (RS (ranges1 (setBounds1 (bounds1 ranges))) {negation rs prf}) prf (negation rs prf)}) =⟨⟩ rangesAreEmpty (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ranges (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges))))) =⟨ cong rangesAreEmpty (cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (cong (merge2' (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges)))) (sym (lemma0 rs {prf})))) ⟩ rangesAreEmpty (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges)) (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges))))) =⟨ cong rangesAreEmpty (lemma2 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges)) ⟩ rangesAreEmpty ⦃ o ⦄ ⦃ dio ⦄ [] =⟨⟩ true end prop_subset : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {prf : IsTrue (validRangeList (rSetRanges rs))} → rSetIsSubset rs {prf} rs {prf} ≡ true prop_subset ⦃ o ⦄ ⦃ dio ⦄ rs {prf} = begin rSetIsSubset rs {prf} rs {prf} =⟨⟩ rSetIsEmpty (rSetDifference rs {prf} rs {prf}) =⟨⟩ rSetIsEmpty (rSetIntersection rs {prf} (rSetNegation rs {prf}) {negation2 rs (negation rs prf)}) =⟨ prop_empty_intersection ⦃ o ⦄ ⦃ dio ⦄ rs {prf} ⟩ true end prop_strictSubset : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {prf : IsTrue (validRangeList (rSetRanges rs))} → rSetIsSubsetStrict rs {prf} rs {prf} ≡ false prop_strictSubset ⦃ o ⦄ ⦃ dio ⦄ rs {prf} = begin rSetIsSubsetStrict rs {prf} rs {prf} =⟨⟩ rSetIsEmpty (rSetDifference rs {prf} rs {prf}) && (not (rSetIsEmpty (rSetDifference rs {prf} rs {prf}))) =⟨⟩ rSetIsEmpty (rSetIntersection rs {prf} (rSetNegation rs {prf}) {negation2 rs (negation rs prf)}) && (not (rSetIsEmpty (rSetDifference rs {prf} rs {prf}))) =⟨ cong (_&& (not (rSetIsEmpty (rSetDifference rs {prf} rs {prf})))) (prop_empty_intersection ⦃ o ⦄ ⦃ dio ⦄ rs {prf}) ⟩ true && (not (rSetIsEmpty (rSetIntersection rs {prf} (rSetNegation rs {prf}) {negation2 rs (negation rs prf)}))) =⟨⟩ (not (rSetIsEmpty (rSetIntersection rs {prf} (rSetNegation rs {prf}) {negation2 rs (negation rs prf)}))) =⟨ cong not (prop_empty_intersection ⦃ o ⦄ ⦃ dio ⦄ rs {prf}) ⟩ not true =⟨⟩ false end -- prop_union : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a) -- → {prf1 : IsTrue (validRangeList (rSetRanges rs1))} → {prf2 : IsTrue (validRangeList (rSetRanges rs2))} -- → (v : a) → (rSetHas rs1 {prf1} v || rSetHas rs2 {prf2} v) ≡ -- (rSetHas (rSetUnion rs1 {prf1} rs2 {prf2}) {union2 rs1 rs2 prf1 prf2 (unionn rs1 rs2 prf1 prf2)} v) -- prop_union ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS []) {prf1} {prf2} v = -- begin -- (rSetHas rs1 {prf1} v || rSetHas rs2 {prf2} v) -- =⟨⟩ -- (false || false) -- =⟨⟩ -- false -- =⟨⟩ -- (rSetHas (RS [] {empty ⦃ o ⦄ ⦃ dio ⦄}) {empty ⦃ o ⦄ ⦃ dio ⦄} v) -- =⟨⟩ -- (rSetHas (rSetUnion rs1 {prf1} rs2 {prf2}) {unionn rs1 rs2 prf1 prf2} v) -- end -- prop_union ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS rg1@(r1 ∷ rss1)) {prf1} {prf2} v = -- begin -- (rSetHas rs1 {prf1} v || rSetHas rs2 {prf2} v) -- =⟨⟩ -- (false || rSetHas rs2 {prf2} v) -- =⟨⟩ -- rSetHas rs2 {prf2} v -- =⟨⟩ -- (rSetHas (rSetUnion rs1 {prf1} rs2 {prf2}) {unionn rs1 rs2 prf1 prf2} v) -- end -- prop_union ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS rg@(r1 ∷ rss1)) rs2@(RS []) {prf1} {prf2} v = -- begin -- (rSetHas rs1 {prf1} v || rSetHas rs2 {prf2} v) -- =⟨⟩ -- (rSetHas rs1 {prf1} v || false) -- =⟨ prop_or_false2 (rSetHas rs1 {prf1} v) ⟩ -- (rSetHas rs1 {prf1} v) -- =⟨⟩ -- (rSetHas (rSetUnion rs1 {prf1} rs2 {prf2}) {unionn rs1 rs2 prf1 prf2} v) -- end -- prop_union ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS rg1@(r1 ∷ rss1)) rs2@(RS rg2@(r2 ∷ rss2)) {prf1} {prf2} v = -- begin -- (rSetHas rs1 {prf1} v || rSetHas rs2 {prf2} v) -- =⟨ cong (_|| (rSetHas rs2 {prf2} v)) (rangeHasSym r1 (RS rss1 {headandtail rs1 prf1}) v {prf1}) ⟩ -- (((rangeHas r1 v) || (rSetHas (RS rss1 {headandtail rs1 prf1}) {headandtail rs1 prf1} v)) || (rSetHas rs2 {prf2} v)) -- =⟨ prop_or_assoc (rangeHas r1 v) (rSetHas (RS rss1 {headandtail rs1 prf1}) {headandtail rs1 prf1} v) (rSetHas rs2 {prf2} v) ⟩ -- ((rangeHas r1 v) || (rSetHas (RS rss1 {headandtail rs1 prf1}) {headandtail rs1 prf1} v) || (rSetHas rs2 {prf2} v)) -- =⟨ cong ((rangeHas r1 v) ||_) (prop_union (RS rss1) rs2 {headandtail rs1 prf1} {prf2} v) ⟩ -- ((rangeHas r1 v) || -- (rSetHas (rSetUnion (RS rss1) {headandtail rs1 prf1} rs2 {prf2}) -- {(union2 (RS rss1) rs2 (headandtail rs1 prf1) prf2 (unionn (RS rss1) rs2 (headandtail rs1 prf1) prf2))} v)) -- =⟨ sym (rangeHasSym r1 (rSetUnion (RS rss1) {headandtail rs1 prf1} rs2 {prf2}) v -- {union2 (RS rss1) rs2 (headandtail rs1 prf1) prf2 (unionn (RS rss1) rs2 (headandtail rs1 prf1) prf2)}) ⟩ -- RS (r1 ∷ (rSetRanges ((RS rss1) -\/- rs2))) -?- v -- =⟨ cong (_-?- v) (cong RS (union0 r1 (RS rss1) rs2)) ⟩ -- RS (rSetRanges ((RS (r1 ∷ rss1)) -\/- rs2)) -?- v -- =⟨ cong (_-?- v) (sym (rangeSetCreation ((RS (r1 ∷ rss1)) -\/- rs2))) ⟩ -- (rSetHas (rSetUnion rs1 {prf1} rs2 {prf2}) {union2 rs1 rs2 prf1 prf2 (unionn rs1 rs2 prf1 prf2)} v) -- end -- prop_union_has_sym : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ -- → (rs1 : RSet a) → (rs2 : RSet a) → (v : a) -- → ((rs1 -\/- rs2) -?- v) ≡ ((rs2 -\/- rs1) -?- v) -- prop_union_has_sym ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1) rs2@(RS ranges2) v = -- begin -- ((rs1 -\/- rs2) -?- v) -- =⟨ sym (prop_union rs1 rs2 v) ⟩ -- ((rs1 -?- v) || (rs2 -?- v)) -- =⟨ prop_or_sym (rs1 -?- v) (rs2 -?- v) ⟩ -- ((rs2 -?- v) || (rs1 -?- v)) -- =⟨ prop_union rs2 rs1 v ⟩ -- ((rs2 -\/- rs1) -?- v) -- end -- prop_union_same_set : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (v : a) → ((rs1 -\/- rs1) -?- v) ≡ (rs1 -?- v) -- prop_union_same_set ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1) v = -- begin -- ((rs1 -\/- rs1) -?- v) -- =⟨ sym (prop_union rs1 rs1 v) ⟩ -- ((rs1 -?- v) || (rs1 -?- v)) -- =⟨ prop_or_same_value (rs1 -?- v) ⟩ -- (rs1 -?- v) -- end prop_validNormalisedEmpty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → validRangeList ⦃ o ⦄ ⦃ dio ⦄ (normaliseRangeList ⦃ o ⦄ ⦃ dio ⦄ []) ≡ true prop_validNormalisedEmpty ⦃ o ⦄ ⦃ dio ⦄ = begin validRangeList ⦃ o ⦄ ⦃ dio ⦄ (normaliseRangeList ⦃ o ⦄ ⦃ dio ⦄ []) =⟨⟩ validRangeList ⦃ o ⦄ ⦃ dio ⦄ [] =⟨⟩ true end postulate -- these postulates hold when r1 == r2 does not hold, used for easing the proofs for union/intersection commutes equalityRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r1 : Range a) → (r2 : Range a) → (r1 < r2) ≡ (not (r2 < r1)) equalityRanges2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r1 : Range a) → (r2 : Range a) → (rangeUpper r1 < rangeUpper r2) ≡ (not (rangeUpper r2 < rangeUpper r1)) prop_sym_merge1' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : List (Range a)) → (rs2 : List (Range a)) → ⦃ ne1 : NonEmpty rs1 ⦄ → ⦃ ne2 : NonEmpty rs2 ⦄ → (b : Bool) → if_then_else_ b ((head rs1 ⦃ ne1 ⦄) ∷ (merge1 (tail rs1 ⦃ ne1 ⦄) rs2)) ((head rs2 ⦃ ne2 ⦄) ∷ (merge1 rs1 (tail rs2 ⦃ ne2 ⦄))) ≡ if_then_else_ (not b) ((head rs2 ⦃ ne2 ⦄) ∷ (merge1 (tail rs2 ⦃ ne2 ⦄) rs1)) ((head rs1 ⦃ ne1 ⦄) ∷ (merge1 rs2 (tail rs1 ⦃ ne1 ⦄))) prop_sym_merge1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : List (Range a)) → (rs2 : List (Range a)) → merge1 rs1 rs2 ≡ merge1 rs2 rs1 prop_sym_merge1 ⦃ o ⦄ ⦃ dio ⦄ [] [] = refl prop_sym_merge1 ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) [] = refl prop_sym_merge1 ⦃ o ⦄ ⦃ dio ⦄ [] ms2@(h2 ∷ t2) = refl prop_sym_merge1 ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) = begin merge1 ms1 ms2 =⟨⟩ if_then_else_ (h1 < h2) (h1 ∷ (merge1 t1 ms2)) (h2 ∷ (merge1 ms1 t2)) =⟨ prop_sym_merge1' ⦃ o ⦄ ⦃ dio ⦄ ms1 ms2 (h1 < h2) ⟩ if_then_else_ (not (h1 < h2)) (h2 ∷ (merge1 t2 ms1)) (h1 ∷ (merge1 ms2 t1)) =⟨ cong (ifThenElseHelper (h2 ∷ (merge1 t2 ms1)) (h1 ∷ (merge1 ms2 t1))) (sym (equalityRanges h2 h1)) ⟩ if_then_else_ (h2 < h1) (h2 ∷ (merge1 t2 ms1)) (h1 ∷ (merge1 ms2 t1)) =⟨⟩ merge1 ms2 ms1 end prop_sym_merge1' ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) true = begin if_then_else_ true (h1 ∷ (merge1 t1 ms2)) (h2 ∷ (merge1 ms1 t2)) =⟨⟩ (h1 ∷ (merge1 t1 ms2)) =⟨ cong (h1 ∷_) (prop_sym_merge1 ⦃ o ⦄ ⦃ dio ⦄ t1 ms2) ⟩ (h1 ∷ (merge1 ms2 t1)) =⟨⟩ if_then_else_ false (h2 ∷ (merge1 t2 ms1)) (h1 ∷ (merge1 ms2 t1)) end prop_sym_merge1' ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) false = begin if_then_else_ false (h1 ∷ (merge1 t1 ms2)) (h2 ∷ (merge1 ms1 t2)) =⟨⟩ (h2 ∷ (merge1 ms1 t2)) =⟨ cong (h2 ∷_) (prop_sym_merge1 ⦃ o ⦄ ⦃ dio ⦄ ms1 t2) ⟩ (h2 ∷ (merge1 t2 ms1)) =⟨⟩ if_then_else_ true (h2 ∷ (merge1 t2 ms1)) (h1 ∷ (merge1 ms2 t1)) end prop_sym_sortedRangeList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (ls1 ls2 : List (Range a)) → (sortedRangeList (merge1 ls1 ls2)) ≡ (sortedRangeList (merge1 ls2 ls1)) prop_sym_sortedRangeList ⦃ o ⦄ ⦃ dio ⦄ ls1 ls2 = (cong sortedRangeList (prop_sym_merge1 ls1 ls2)) prop_sym_validRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (ls1 ls2 : List (Range a)) → (validRanges (merge1 ls1 ls2)) ≡ (validRanges (merge1 ls2 ls1)) prop_sym_validRanges ⦃ o ⦄ ⦃ dio ⦄ ls1 ls2 = (cong validRanges (prop_sym_merge1 ls1 ls2)) prop_union_commutes : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a) → {prf1 : IsTrue (validRangeList (rSetRanges rs1))} → {prf2 : IsTrue (validRangeList (rSetRanges rs2))} → (rSetUnion rs1 {prf1} rs2 {prf2}) ≡ (rSetUnion rs2 {prf2} rs1 {prf1}) prop_union_commutes (RS []) (RS []) = refl prop_union_commutes (RS ranges@(r ∷ rs)) (RS []) = refl prop_union_commutes (RS []) (RS ranges@(r ∷ rs)) = refl prop_union_commutes ⦃ o ⦄ ⦃ dio ⦄ RS1@(RS ls1@(r1 ∷ rs1)) RS2@(RS ls2@(r2 ∷ rs2)) {prf1} {prf2} = begin (rSetUnion RS1 {prf1} RS2 {prf2}) =⟨⟩ RS ⦃ o ⦄ ⦃ dio ⦄ (normalise ⦃ o ⦄ ⦃ dio ⦄ (merge1 ⦃ o ⦄ ⦃ dio ⦄ ls1 ls2) ⦃ merge1Sorted RS1 RS2 prf1 prf2 ⦄ ⦃ merge1HasValidRanges RS1 RS2 prf1 prf2 ⦄) {unionHolds RS1 RS2 prf1 prf2} =⟨ rangesEqiv (rangesEqiv2 (merge1Sorted RS1 RS2 prf1 prf2) (merge1HasValidRanges RS1 RS2 prf1 prf2) (merge1Sorted RS2 RS1 prf2 prf1) (merge1HasValidRanges RS2 RS1 prf2 prf1) (prop_sym_merge1 ls1 ls2)) ⟩ RS ⦃ o ⦄ ⦃ dio ⦄ (normalise ⦃ o ⦄ ⦃ dio ⦄ (merge1 ⦃ o ⦄ ⦃ dio ⦄ ls2 ls1) ⦃ merge1Sorted RS2 RS1 prf2 prf1 ⦄ ⦃ merge1HasValidRanges RS2 RS1 prf2 prf1 ⦄) {unionHolds RS2 RS1 prf2 prf1} =⟨⟩ (rSetUnion RS2 {prf2} RS1 {prf1}) end prop_sym_merge2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : List (Range a)) → (rs2 : List (Range a)) → merge2 rs1 rs2 ≡ merge2 rs2 rs1 prop_sym_merge2' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : List (Range a)) → (rs2 : List (Range a)) → ⦃ ne1 : NonEmpty rs1 ⦄ → ⦃ ne2 : NonEmpty rs2 ⦄ → (b : Bool) → (if_then_else_ b (merge2 (tail rs1 ⦃ ne1 ⦄) rs2) (merge2 rs1 (tail rs2 ⦃ ne2 ⦄))) ≡ (if_then_else_ (not b) (merge2 (tail rs2 ⦃ ne2 ⦄) rs1) (merge2 rs2 (tail rs1 ⦃ ne1 ⦄))) prop_sym_merge2' ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) true = begin (if_then_else_ true (merge2 t1 ms2) (merge2 ms1 t2)) =⟨⟩ (merge2 t1 ms2) =⟨ prop_sym_merge2 t1 ms2 ⟩ (merge2 ms2 t1) =⟨⟩ if_then_else_ false (merge2 t2 ms1) (merge2 ms2 t1) end prop_sym_merge2' ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) false = begin (if_then_else_ false (merge2 t1 ms2) (merge2 ms1 t2)) =⟨⟩ (merge2 ms1 t2) =⟨ prop_sym_merge2 ms1 t2 ⟩ (merge2 t2 ms1) =⟨⟩ if_then_else_ true (merge2 t2 ms1) (merge2 ms2 t1) end prop_sym_merge2 ⦃ o ⦄ ⦃ dio ⦄ [] [] = refl prop_sym_merge2 ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) [] = refl prop_sym_merge2 ⦃ o ⦄ ⦃ dio ⦄ [] ms2@(h2 ∷ t2) = refl prop_sym_merge2 ⦃ o ⦄ ⦃ dio ⦄ ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) = begin merge2 ms1 ms2 =⟨⟩ (rangeIntersection h1 h2) ∷ (if_then_else_ (rangeUpper h1 < rangeUpper h2) (merge2 t1 ms2) (merge2 ms1 t2)) =⟨ cong ((rangeIntersection h1 h2) ∷_) (prop_sym_merge2' ⦃ o ⦄ ⦃ dio ⦄ ms1 ms2 (rangeUpper h1 < rangeUpper h2)) ⟩ (rangeIntersection h1 h2) ∷ (if_then_else_ (not (rangeUpper h1 < rangeUpper h2)) (merge2 t2 ms1) (merge2 ms2 t1)) =⟨ cong ((rangeIntersection h1 h2) ∷_) (cong (ifThenElseHelper (merge2 t2 ms1) (merge2 ms2 t1)) (sym (equalityRanges2 h2 h1))) ⟩ ((rangeIntersection h1 h2) ∷ (if_then_else_ (rangeUpper h2 < rangeUpper h1) (merge2 t2 ms1) (merge2 ms2 t1))) =⟨ cong (_∷ (if_then_else_ (rangeUpper h2 < rangeUpper h1) (merge2 t2 ms1) (merge2 ms2 t1))) (prop_intersection_sym h1 h2) ⟩ ((rangeIntersection h2 h1) ∷ (if_then_else_ (rangeUpper h2 < rangeUpper h1) (merge2 t2 ms1) (merge2 ms2 t1))) =⟨⟩ merge2 ms2 ms1 end prop_intersection_commutes : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a) → {prf1 : IsTrue (validRangeList (rSetRanges rs1))} → {prf2 : IsTrue (validRangeList (rSetRanges rs2))} → (rSetIntersection rs1 {prf1} rs2 {prf2}) ≡ (rSetIntersection rs2 {prf2} rs1 {prf1}) prop_intersection_commutes (RS []) (RS []) = refl prop_intersection_commutes (RS ranges@(r ∷ rs)) (RS []) = refl prop_intersection_commutes (RS []) (RS ranges@(r ∷ rs)) = refl prop_intersection_commutes ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ls1@(r1 ∷ rss1)) rs2@(RS ls2@(r2 ∷ rss2)) {prf1} {prf2} = begin (rSetIntersection rs1 {prf1} rs2 {prf2}) =⟨⟩ RS ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ls1 ls2)) {intersection0 rs1 rs2 prf1 prf2} =⟨ rangesEqiv (cong (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (prop_sym_merge2 ls1 ls2)) ⟩ RS ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ls2 ls1)) {intersection0 rs2 rs1 prf2 prf1} =⟨⟩ (rSetIntersection rs2 {prf2} rs1 {prf1}) end -- if x is strict subset of y, y is not strict subset of x -- prop_subset_not1 asserts that rSetIsSubstrict x y is true -- this means that rSetIsEmpty (rSetDifference x y) is true -- and rSetEmpty (rSetDifference x y) is false prop_subset_not1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 rs2 : RSet a) → {prf1 : IsTrue (validRangeList (rSetRanges rs1))} → {prf2 : IsTrue (validRangeList (rSetRanges rs2))} -> (a1 : IsTrue (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) -> (a2 : IsTrue (not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})))) → (rSetIsSubsetStrict rs1 {prf1} rs2 {prf2}) ≡ (not (rSetIsSubsetStrict rs2 {prf2} rs1 {prf1})) prop_subset_not1 {{ o }} {{ dio }} rs1 rs2 {prf1} {prf2} a1 a2 = begin rSetIsSubsetStrict rs1 {prf1} rs2 {prf2} =⟨⟩ (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) =⟨ not-not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) ⟩ not (not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})))) =⟨ cong not (prop_demorgan (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2})) (not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})))) ⟩ not ((not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) || (not (not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))))) =⟨ cong not (cong ((not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) ||_) (sym (not-not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))))) ⟩ not ((not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) || (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) =⟨ cong not (prop_or_sym (not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) ⟩ not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}) || not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) =⟨ cong not (prop_or_and_eqiv_false (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})) (not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) (isTrueAndIsFalse2 a2) (isTrueAndIsFalse1 a1)) ⟩ not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}) && not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) =⟨⟩ not (rSetIsSubsetStrict rs2 {prf2} rs1 {prf1}) end -- if x is strict subset of y, y is not strict subset of x -- prop_subset_not2 asserts that rSetIsSubstrict x y is false -- this means that rSetIsEmpty (rSetDifference x y) is false -- and rSetEmpty (rSetDifference x y) is true prop_subset_not2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 rs2 : RSet a) → {prf1 : IsTrue (validRangeList (rSetRanges rs1))} → {prf2 : IsTrue (validRangeList (rSetRanges rs2))} -> (a1 : IsFalse (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) -> (a2 : IsFalse (not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})))) → (rSetIsSubsetStrict rs1 {prf1} rs2 {prf2}) ≡ (not (rSetIsSubsetStrict rs2 {prf2} rs1 {prf1})) prop_subset_not2 {{ o }} {{ dio }} rs1 rs2 {prf1} {prf2} a1 a2 = begin rSetIsSubsetStrict rs1 {prf1} rs2 {prf2} =⟨⟩ (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) =⟨ not-not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) ⟩ not (not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})))) =⟨ cong not (prop_demorgan (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2})) (not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})))) ⟩ not ((not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) || (not (not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))))) =⟨ cong not (cong ((not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) ||_) (sym (not-not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))))) ⟩ not ((not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) || (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) =⟨ cong not (prop_or_sym (not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))) ⟩ not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}) || not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) =⟨ cong not (prop_or_and_eqiv_true (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1})) (not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) (isTrueAndIsFalse3 a2) (isTrueAndIsFalse4 a1)) ⟩ not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}) && not (rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2}))) =⟨⟩ not (rSetIsSubsetStrict rs2 {prf2} rs1 {prf1}) end prop_strictSubset_means_subset : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 rs2 : RSet a) → {prf1 : IsTrue (validRangeList (rSetRanges rs1))} → {prf2 : IsTrue (validRangeList (rSetRanges rs2))} → IsTrue (rSetIsSubsetStrict rs1 {prf1} rs2 {prf2}) -> IsTrue (rSetIsSubset rs1 {prf1} rs2 {prf2}) prop_strictSubset_means_subset {{ o }} {{ dio }} rs1 rs2 {prf1} {prf2} prf = isTrue&&₁ {(rSetIsSubset rs1 {prf1} rs2 {prf2})} prf
57.001412
257
0.547984
52ec9edab979c3196f0cba35fada6ea4cf4a950e
272
agda
Agda
test/interaction/Issue3289.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3289.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3289.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --postfix-projections #-} open import Agda.Builtin.Nat record R : Set where field x : Nat → Nat open R {{...}} f : R f .x = {!!} -- WAS: Case splitting on result produces the following nonsense: -- f ⦃ .x ⦄ x₁ = ? -- SHOULD: produce -- f .x x₁ = ?
14.315789
65
0.580882
039861aade1ea7e6ffb4b2dde566d820749f17ed
3,243
agda
Agda
src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --erased-cubical --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.Cubical.HCompU where open import Agda.Primitive open import Agda.Builtin.Sigma open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_; primHComp to hcomp; primTransp to transp; primComp to comp; itIsOne to 1=1) open import Agda.Builtin.Cubical.Path open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to outS; inc to inS) module Helpers where -- Homogeneous filling hfill : ∀ {ℓ} {A : Set ℓ} {φ : I} (u : ∀ i → Partial φ A) (u0 : A [ φ ↦ u i0 ]) (i : I) → A hfill {φ = φ} u u0 i = hcomp (λ j → \ { (φ = i1) → u (i ∧ j) 1=1 ; (i = i0) → outS u0 }) (outS u0) -- Heterogeneous filling defined using comp fill : ∀ {ℓ : I → Level} (A : ∀ i → Set (ℓ i)) {φ : I} (u : ∀ i → Partial φ (A i)) (u0 : A i0 [ φ ↦ u i0 ]) → ∀ i → A i fill A {φ = φ} u u0 i = comp (λ j → A (i ∧ j)) (λ j → \ { (φ = i1) → u (i ∧ j) 1=1 ; (i = i0) → outS u0 }) (outS {φ = φ} u0) module _ {ℓ} {A : Set ℓ} where refl : {x : A} → x ≡ x refl {x = x} = λ _ → x sym : {x y : A} → x ≡ y → y ≡ x sym p = λ i → p (~ i) cong : ∀ {ℓ'} {B : A → Set ℓ'} {x y : A} (f : (a : A) → B a) (p : x ≡ y) → PathP (λ i → B (p i)) (f x) (f y) cong f p = λ i → f (p i) isContr : ∀ {ℓ} → Set ℓ → Set ℓ isContr A = Σ A \ x → (∀ y → x ≡ y) fiber : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) (y : B) → Set (ℓ ⊔ ℓ') fiber {A = A} f y = Σ A \ x → f x ≡ y open Helpers primitive prim^glueU : {la : Level} {φ : I} {T : I → Partial φ (Set la)} {A : Set la [ φ ↦ T i0 ]} → PartialP φ (T i1) → outS A → hcomp T (outS A) prim^unglueU : {la : Level} {φ : I} {T : I → Partial φ (Set la)} {A : Set la [ φ ↦ T i0 ]} → hcomp T (outS A) → outS A -- Needed for transp. primFaceForall : (I → I) → I transpProof : ∀ {l} → (e : I → Set l) → (φ : I) → (a : Partial φ (e i0)) → (b : e i1 [ φ ↦ (\ o → transp (\ i → e i) i0 (a o)) ] ) → fiber (transp (\ i → e i) i0) (outS b) transpProof e φ a b = f , \ j → comp (\ i → e i) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ i)) (~ i) (a 1=1) ; (j = i0) → transp (\ j → e (j ∧ i)) (~ i) f ; (j = i1) → g (~ i) }) f where b' = outS {u = (\ o → transp (\ i → e i) i0 (a o))} b g : (k : I) → e (~ k) g k = fill (\ i → e (~ i)) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ ~ i)) i (a 1=1) ; (φ = i0) → transp (\ j → e (~ j ∨ ~ i)) (~ i) b' }) (inS b') k f = comp (\ i → e (~ i)) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ ~ i)) i (a 1=1); (φ = i0) → transp (\ j → e (~ j ∨ ~ i)) (~ i) b' }) b' {-# BUILTIN TRANSPPROOF transpProof #-}
41.050633
171
0.384212
431ed2e02cd9c50e22c0d25dec8c03d334ba0802
3,230
agda
Agda
Agda/Gradual Security/lambdasyntax.agda
kellino/TypeSystems
acf5a153e14a7bdc0c9332fa602fa369fe7add46
[ "MIT" ]
2
2016-10-27T08:05:40.000Z
2017-05-26T23:06:17.000Z
Agda/Gradual Security/lambdasyntax.agda
kellino/TypeSystems
acf5a153e14a7bdc0c9332fa602fa369fe7add46
[ "MIT" ]
null
null
null
Agda/Gradual Security/lambdasyntax.agda
kellino/TypeSystems
acf5a153e14a7bdc0c9332fa602fa369fe7add46
[ "MIT" ]
null
null
null
module lambdasyntax where open import Data.Nat using (ℕ) open import Data.Bool using (Bool; true; false) open import Data.Vec using (Vec; []; lookup) open import Relation.Nullary open import Data.Empty hiding (⊥) open import Relation.Binary.PropositionalEquality data Label : Set where ⊤ ⊥ ✭ : Label data GType : Set where bool : Label → GType _⇒_ : GType → Label → GType → GType err : GType infixr 4 _∙_ infixl 6 _∨_ _∧_ data Term : Set where var : ℕ → Term litBool : Bool → Label → Term lam : GType → Term → Label → Term _∧_ : Term → Term → Term _∨_ : Term → Term → Term _∙_ : Term → Term → Term if_then_else_ : Term → Term → Term → Term error : Term Ctx : ℕ → Set Ctx = Vec GType getLabel : GType → Label getLabel (bool ℓ) = ℓ getLabel ((g ⇒ ℓ) g₁) = ℓ getLabel err = ✭ -- lazy propagation setLabel : GType → Label → GType setLabel (bool _) ℓ = bool ℓ setLabel ((t ⇒ x) t₁) ℓ = (t ⇒ ℓ) t₁ setLabel err _ = err -- gradual join _~⋎~_ : (ℓ₁ ℓ₂ : Label) → Label ⊤ ~⋎~ ⊤ = ⊤ ⊤ ~⋎~ ⊥ = ⊤ ⊤ ~⋎~ ✭ = ⊤ ⊥ ~⋎~ ⊤ = ⊤ ⊥ ~⋎~ ⊥ = ⊥ ⊥ ~⋎~ ✭ = ✭ ✭ ~⋎~ ⊤ = ⊤ ✭ ~⋎~ ⊥ = ✭ ✭ ~⋎~ ✭ = ✭ -- gradual meet _~⋏~_ : ∀ (ℓ₁ ℓ₂ : Label) → Label ⊥ ~⋏~ ✭ = ⊥ ✭ ~⋏~ ⊥ = ⊥ ℓ₁ ~⋏~ ✭ = ✭ ✭ ~⋏~ ℓ₂ = ✭ ⊤ ~⋏~ ⊤ = ⊤ ⊤ ~⋏~ ⊥ = ⊥ ⊥ ~⋏~ ⊤ = ⊥ ⊥ ~⋏~ ⊥ = ⊥ _:∧:_ : ∀ (t₁ t₂ : GType) → GType _:∨:_ : ∀ (t₁ t₂ : GType) → GType bool ℓ₁ :∧: bool ℓ₂ = bool (ℓ₁ ~⋏~ ℓ₂) (s₁₁ ⇒ ℓ₁) s₁₂ :∧: (s₂₁ ⇒ ℓ₂) s₂₂ = ((s₁₁ :∨: s₂₁) ⇒ (ℓ₁ ~⋏~ ℓ₂)) (s₁₂ :∧: s₂₂) _ :∧: _ = err -- _:∨:_ : ∀ (t₁ t₂ : gtype) → gtype bool ℓ₁ :∨: bool ℓ₂ = bool (ℓ₁ ~⋎~ ℓ₂) (s₁₁ ⇒ ℓ₁) s₁₂ :∨: (s₂₁ ⇒ ℓ₂) s₂₂ = ((s₁₁ :∧: s₂₁) ⇒ (ℓ₁ ~⋎~ ℓ₂)) (s₁₂ :∨: s₂₂) _ :∨: _ = err data _≤_ : Label → Label → Set where ⊥≤⊤ : ⊥ ≤ ⊤ ⊤≤⊤ : ⊤ ≤ ⊤ ⊥≤⊥ : ⊥ ≤ ⊥ ℓ≤✭ : ∀ {ℓ} → ℓ ≤ ✭ ✭≤ℓ : ∀ {ℓ} → ✭ ≤ ℓ _≤?_ : (ℓ₁ ℓ₂ : Label) → Dec (ℓ₁ ≤ ℓ₂) ⊤ ≤? ⊤ = yes ⊤≤⊤ ⊤ ≤? ⊥ = no (λ ()) ⊤ ≤? ✭ = yes (ℓ≤✭) ⊥ ≤? ⊤ = yes ⊥≤⊤ ⊥ ≤? ⊥ = yes ⊥≤⊥ ⊥ ≤? ✭ = yes (ℓ≤✭) ✭ ≤? ⊤ = yes (✭≤ℓ) ✭ ≤? ⊥ = yes (✭≤ℓ) ✭ ≤? ✭ = yes (ℓ≤✭) data _≾_ : GType → GType → Set where yes : (t₁ t₂ : GType) → t₁ ≾ t₂ no : (t₁ t₂ : GType) → t₁ ≾ t₂ _≾?_ : (t₁ t₂ : GType) → t₁ ≾ t₂ bool ℓ ≾? bool ℓ₁ with ℓ ≤? ℓ₁ ... | yes p = yes (bool ℓ) (bool ℓ₁) ... | no ¬p = no (bool ℓ) (bool ℓ₁) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ with t₃ ≾? t₁ | t₂ ≾? t₄ | ℓ ≤? ℓ₁ (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | yes .t₃ .t₁ | (yes .t₂ .t₄) | (yes p) = yes ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | yes .t₃ .t₁ | (yes .t₂ .t₄) | (no ¬p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | yes .t₃ .t₁ | (no .t₂ .t₄) | (yes p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | yes .t₃ .t₁ | (no .t₂ .t₄) | (no ¬p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | no .t₃ .t₁ | (yes .t₂ .t₄) | (yes p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | no .t₃ .t₁ | (yes .t₂ .t₄) | (no ¬p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | no .t₃ .t₁ | (no .t₂ .t₄) | (yes p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) (t₁ ⇒ ℓ) t₂ ≾? (t₃ ⇒ ℓ₁) t₄ | no .t₃ .t₁ | (no .t₂ .t₄) | (no ¬p) = no ((t₁ ⇒ ℓ) t₂) ((t₃ ⇒ ℓ₁) t₄) -- everything else is no t₁ ≾? t₂ = no t₁ t₂
28.086957
102
0.439628
3d760b0c650f5eaa93b6ea465af94e354174f711
304
agda
Agda
test/Fail/Issue3846.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue3846.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue3846.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --rewriting #-} open import Agda.Builtin.Equality open import Agda.Builtin.Bool open import Agda.Builtin.Nat {-# BUILTIN REWRITE _≡_ #-} not : Bool → Bool not true = false not false = true postulate rew : Nat ≡ Bool {-# REWRITE rew #-} 0' : Bool 0' = 0 test : not 0' ≡ true test = refl
14.47619
33
0.661184
fdb796c951b2066a55ca1d1f0668bbb171f21226
19,427
agda
Agda
Univalence/Obsolete/FinVecProperties.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
Univalence/Obsolete/FinVecProperties.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
Univalence/Obsolete/FinVecProperties.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 FinVecProperties where open import Data.Nat using (ℕ; _+_; _*_) open import Data.Fin using (Fin; zero; suc; inject+; raise) open import Data.Sum using (inj₁; inj₂; [_,_]′) open import Data.Product using (_×_; proj₁; proj₂; _,′_) open import Data.Vec using (Vec; []; _∷_; tabulate; allFin) renaming (_++_ to _++V_; concat to concatV; map to mapV) open import Data.Vec.Properties using (tabulate∘lookup; lookup∘tabulate; lookup-allFin; lookup-++-inject+; tabulate-∘) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; cong₂; module ≡-Reasoning) open import Function using (_∘_; id) -- open import Equiv using (_∼_; p∘!p≡id) open import FinEquiv using (module Plus; module Times; module PlusTimes) open import FinVec using (FinVec; 0C; 1C; _∘̂_; _⊎c_; _×c_; unite+; uniti+; unite+r; uniti+r; swap+cauchy; assocl+; assocr+; unite*; uniti*; unite*r; uniti*r; swap⋆cauchy; assocl*; assocr*; dist*+; factor*+; distl*+; factorl*+; right-zero*l; right-zero*r ) open import Proofs using ( -- FiniteFunctions finext; -- VectorLemmas _!!_; lookupassoc; unSplit; lookup-++-raise; tabulate-split; concat-map; left!!; right!!; map-map-map; lookup-map; map-∘ ) ------------------------------------------------------------------------------ -- Two ways for reasoning about permutations: we use whichever is more -- convenient in each context -- I: we can reason about permutations by looking at their action at -- every index. This exposes the underlying raw vectors... infix 4 _∼p_ _∼p_ : {n m : ℕ} (p₁ p₂ : Vec (Fin m) n) → Set _∼p_ {n} p₁ p₂ = (i : Fin n) → p₁ !! i ≡ p₂ !! i ∼p⇒≡ : {n : ℕ} {p₁ p₂ : Vec (Fin n) n} → (p₁ ∼p p₂) → p₁ ≡ p₂ ∼p⇒≡ {n} {p₁} {p₂} eqv = begin ( p₁ ≡⟨ sym (tabulate∘lookup p₁) ⟩ tabulate (_!!_ p₁) ≡⟨ finext eqv ⟩ tabulate (_!!_ p₂) ≡⟨ tabulate∘lookup p₂ ⟩ p₂ ∎) where open ≡-Reasoning cauchyext : {m n : ℕ} (π : FinVec m n) → tabulate (_!!_ π) ≡ π -- this is just tabulate∘lookup, but it hides the details; should this -- be called 'join' or 'flatten' ? cauchyext π = tabulate∘lookup π 1C!!i≡i : ∀ {m} {i : Fin m} → 1C {m} !! i ≡ i 1C!!i≡i = lookup∘tabulate id _ !!⇒∘̂ : {n₁ n₂ n₃ : ℕ} → (π₁ : Vec (Fin n₁) n₂) → (π₂ : Vec (Fin n₂) n₃) → (i : Fin n₃) → π₁ !! (π₂ !! i) ≡ (π₂ ∘̂ π₁) !! i !!⇒∘̂ π₁ π₂ i = begin ( π₁ !! (π₂ !! i) ≡⟨ sym (lookup∘tabulate (λ j → (π₁ !! (π₂ !! j))) i) ⟩ tabulate (λ i → π₁ !! (π₂ !! i)) !! i ≡⟨ refl ⟩ (π₂ ∘̂ π₁) !! i ∎) where open ≡-Reasoning -- II: we can relate compositions of permutations of type equivalences -- and pull back properties of permutations from properties of -- equivalences ∘̂⇒∘ : {m n o : ℕ} → (f : Fin m → Fin n) → (g : Fin n → Fin o) → tabulate f ∘̂ tabulate g ∼p tabulate (g ∘ f) -- note the flip! ∘̂⇒∘ f g i = begin ( (tabulate f ∘̂ tabulate g) !! i ≡⟨ lookup∘tabulate _ i ⟩ (tabulate g) !! (tabulate f !! i) ≡⟨ lookup∘tabulate _ (tabulate f !! i) ⟩ g (tabulate f !! i) ≡⟨ cong g (lookup∘tabulate f i) ⟩ g (f i) ≡⟨ sym (lookup∘tabulate (g ∘ f) i) ⟩ tabulate (g ∘ f) !! i ∎) where open ≡-Reasoning -- we could go through ~p, but this works better in practice ~⇒≡ : {m n : ℕ} {f : Fin m → Fin n} {g : Fin n → Fin m} → (f ∘ g ∼ id) → (tabulate g ∘̂ tabulate f ≡ 1C) ~⇒≡ {f = f} {g} β = ∼p⇒≡ (λ i → trans (∘̂⇒∘ g f i) (cong (λ x → x !! i) (finext β))) ------------------------------------------------------------------------------ -- A permutation and its inverse compose to the identity -- -- Here we just exploit the connection to type equivalences to get all -- the properties for free. -- additives unite+∘̂uniti+~id : ∀ {m} → (unite+ {m}) ∘̂ uniti+ ≡ 1C {m} unite+∘̂uniti+~id {m} = ~⇒≡ {m} {n = m} (p∘!p≡id {p = Plus.unite+ {m}}) uniti+∘̂unite+~id : ∀ {m} → (uniti+ {m}) ∘̂ unite+ ≡ 1C {m} uniti+∘̂unite+~id {m} = ~⇒≡ {m} {n = m} (p∘!p≡id {p = Plus.uniti+}) unite+r∘̂uniti+r~id : ∀ {m} → (unite+r {m}) ∘̂ uniti+r ≡ 1C {m + 0} unite+r∘̂uniti+r~id {m} = ~⇒≡ {m} (p∘!p≡id {p = Plus.unite+r {m}}) uniti+r∘̂unite+r~id : ∀ {m} → (uniti+r {m}) ∘̂ unite+r ≡ 1C {m} uniti+r∘̂unite+r~id {m} = ~⇒≡ (p∘!p≡id {p = Plus.uniti+r}) swap+-inv : ∀ {m n} → swap+cauchy m n ∘̂ swap+cauchy n m ≡ 1C swap+-inv {m} {n} = ~⇒≡ (Plus.swap-inv m n) assocl+∘̂assocr+~id : ∀ {m n o} → assocl+ {m} {n} {o} ∘̂ assocr+ {m} ≡ 1C assocl+∘̂assocr+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Plus.assocl+ {m}}) assocr+∘̂assocl+~id : ∀ {m n o} → assocr+ {m} {n} {o} ∘̂ assocl+ {m} ≡ 1C assocr+∘̂assocl+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Plus.assocr+ {m}}) -- multiplicatives unite*∘̂uniti*~id : ∀ {m} → (unite* {m}) ∘̂ uniti* ≡ 1C {1 * m} unite*∘̂uniti*~id {m} = ~⇒≡ {m} {n = 1 * m} (p∘!p≡id {p = Times.unite* {m}}) uniti*∘̂unite*~id : ∀ {m} → (uniti* {m}) ∘̂ unite* ≡ 1C {m} uniti*∘̂unite*~id {m} = ~⇒≡ {1 * m} {n = m} (p∘!p≡id {p = Times.uniti* {m}}) unite*r∘̂uniti*r~id : ∀ {m} → (unite*r {m}) ∘̂ uniti*r ≡ 1C {m * 1} unite*r∘̂uniti*r~id {m} = ~⇒≡ {m} {n = m * 1} (p∘!p≡id {p = Times.unite*r {m}}) uniti*r∘̂unite*r~id : ∀ {m} → (uniti*r {m}) ∘̂ unite*r ≡ 1C {m} uniti*r∘̂unite*r~id {m} = ~⇒≡ {m * 1} {n = m} (p∘!p≡id {p = Times.uniti*r {m}}) swap*-inv : ∀ {m n} → swap⋆cauchy m n ∘̂ swap⋆cauchy n m ≡ 1C swap*-inv {m} {n} = ~⇒≡ (Times.swap-inv m n) assocl*∘̂assocr*~id : ∀ {m n o} → assocl* {m} {n} {o} ∘̂ assocr* {m} ≡ 1C assocl*∘̂assocr*~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Times.assocl* {m}}) assocr*∘̂assocl*~id : ∀ {m n o} → assocr* {m} {n} {o} ∘̂ assocl* {m} ≡ 1C assocr*∘̂assocl*~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Times.assocr* {m}}) -- Distributivity right-zero*l∘̂right-zero*r~id : ∀ {m} → right-zero*l {m} ∘̂ right-zero*r {m} ≡ 1C {m * 0} right-zero*l∘̂right-zero*r~id {m} = ~⇒≡ {f = proj₁ (PlusTimes.factorzr {m})} (p∘!p≡id {p = PlusTimes.distzr {m}}) right-zero*r∘̂right-zero*l~id : ∀ {m} → right-zero*r {m} ∘̂ right-zero*l {m} ≡ 1C right-zero*r∘̂right-zero*l~id {m} = ~⇒≡ { f = proj₁ (PlusTimes.factorz {m})} (p∘!p≡id {p = PlusTimes.distz {m}}) dist*+∘̂factor*+~id : ∀ {m n o} → dist*+ {m} {n} {o} ∘̂ factor*+ {m} ≡ 1C dist*+∘̂factor*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.dist {m}}) factor*+∘̂dist*+~id : ∀ {m n o} → factor*+ {m} {n} {o} ∘̂ dist*+ {m} ≡ 1C factor*+∘̂dist*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.factor {m}}) distl*+∘̂factorl*+~id : ∀ {m n o} → distl*+ {m} {n} {o} ∘̂ factorl*+ {m} ≡ 1C distl*+∘̂factorl*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.distl {m}}) factorl*+∘̂distl*+~id : ∀ {m n o} → factorl*+ {m} {n} {o} ∘̂ distl*+ {m} ≡ 1C factorl*+∘̂distl*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.factorl {m}}) ------------------------------------------------------------------------------ -- Now the main properties of sequential composition 0C∘̂0C≡0C : 1C {0} ∘̂ 1C {0} ≡ 1C {0} 0C∘̂0C≡0C = refl ∘̂-assoc : {m₁ m₂ m₃ m₄ : ℕ} → (a : Vec (Fin m₂) m₁) (b : Vec (Fin m₃) m₂) (c : Vec (Fin m₄) m₃) → a ∘̂ (b ∘̂ c) ≡ (a ∘̂ b) ∘̂ c ∘̂-assoc a b c = finext (lookupassoc a b c) ∘̂-rid : {m n : ℕ} → (π : Vec (Fin m) n) → π ∘̂ 1C ≡ π ∘̂-rid π = trans (finext (λ i → lookup-allFin (π !! i))) (cauchyext π) ∘̂-lid : {m n : ℕ} → (π : Vec (Fin m) n) → 1C ∘̂ π ≡ π ∘̂-lid π = trans (finext (λ i → cong (_!!_ π) (lookup-allFin i))) (cauchyext π) -- 1C₀⊎x≡x : ∀ {m n} {x : FinVec m n} → 1C {0} ⊎c x ≡ x 1C₀⊎x≡x {x = x} = cauchyext x unite+∘[0⊎x]≡x∘unite+ : ∀ {m n} {x : FinVec m n} → unite+ ∘̂ (1C {0} ⊎c x) ≡ x ∘̂ unite+ unite+∘[0⊎x]≡x∘unite+ {m} {n} {x} = finext pf where pf : (i : Fin n) → (0C ⊎c x) !! (unite+ !! i) ≡ unite+ !! (x !! i) pf i = begin ( tabulate (λ y → x !! y) !! (tabulate id !! i) ≡⟨ cong (λ j → tabulate (λ y → x !! y) !! j) (lookup∘tabulate id i) ⟩ tabulate (λ y → x !! y) !! i ≡⟨ lookup∘tabulate (_!!_ x) i ⟩ x !! i ≡⟨ sym (lookup∘tabulate id (x !! i)) ⟩ tabulate id !! (x !! i) ∎) where open ≡-Reasoning uniti+∘x≡[0⊎x]∘uniti+ : ∀ {m n} {x : FinVec m n} → uniti+ ∘̂ x ≡ (1C {0} ⊎c x) ∘̂ uniti+ uniti+∘x≡[0⊎x]∘uniti+ {m} {n} {x} = finext pf where pf : (i : Fin n) → x !! (uniti+ !! i) ≡ uniti+ !! ((0C ⊎c x) !! i) pf i = begin ( x !! (tabulate id !! i) ≡⟨ cong (_!!_ x) (lookup∘tabulate id i) ⟩ x !! i ≡⟨ sym (lookup∘tabulate (λ y → x !! y) i) ⟩ tabulate (λ y → x !! y) !! i ≡⟨ sym (lookup∘tabulate id _) ⟩ tabulate id !! (tabulate (λ y → x !! y) !! i) ∎) where open ≡-Reasoning 1C⊎1C≡1C : ∀ {m n} → 1C {m} ⊎c 1C {n} ≡ 1C 1C⊎1C≡1C {m} {n} = begin ( tabulate {m} (inject+ n ∘ _!!_ 1C) ++V tabulate {n} (raise m ∘ _!!_ 1C) ≡⟨ cong₂ (_++V_ {m = m}) (finext (λ i → cong (inject+ n) (lookup-allFin i))) (finext (λ i → cong (raise m) (lookup-allFin i))) ⟩ tabulate {m} (inject+ n) ++V tabulate {n} (raise m) ≡⟨ unSplit {m} id ⟩ tabulate {m + n} id ∎) where open ≡-Reasoning idˡ⊕ : ∀ {m n} {x : FinVec m n} → uniti+ ∘̂ (1C {0} ⊎c x) ≡ x ∘̂ uniti+ idˡ⊕ {m} {n} {x} = finext pf where open ≡-Reasoning pf : (i : Fin n) → (1C {0} ⊎c x) !! (uniti+ !! i) ≡ (uniti+ !! (x !! i)) pf i = begin ( tabulate (λ y → x !! y) !! (tabulate id !! i) ≡⟨ cong (_!!_ (tabulate λ y → x !! y)) (lookup∘tabulate id i) ⟩ (tabulate (λ y → x !! y)) !! i ≡⟨ lookup∘tabulate (λ y → x !! y) i ⟩ x !! i ≡⟨ sym (lookup∘tabulate id (x !! i)) ⟩ tabulate id !! (x !! i) ∎) -- [,]-commute : {A B C D E : Set} → {f : A → C} → {g : B → C} → {h : C → D} → -- ∀ x → h ([ f , g ]′ x) ≡ [ (h ∘ f) , (h ∘ g) ]′ x -- [,]-commute (inj₁ x) = refl -- [,]-commute (inj₂ y) = refl -- private left⊎⊎!! : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → (p₁ : FinVec m₁ n₁) → (p₂ : FinVec m₂ n₂) → (p₃ : FinVec m₃ m₁) → (p₄ : FinVec m₄ m₂) → (i : Fin n₁) → (p₃ ⊎c p₄) !! ( (p₁ ⊎c p₂) !! inject+ n₂ i ) ≡ inject+ m₄ ( (p₁ ∘̂ p₃) !! i) left⊎⊎!! {m₁} {m₂} {_} {m₄} {_} {n₂} p₁ p₂ p₃ p₄ i = let pp = p₃ ⊎c p₄ in let qq = p₁ ⊎c p₂ in begin ( pp !! (qq !! inject+ n₂ i) ≡⟨ cong (_!!_ pp) (lookup-++-inject+ (tabulate (inject+ m₂ ∘ _!!_ p₁)) (tabulate (raise m₁ ∘ _!!_ p₂)) i) ⟩ pp !! (tabulate (inject+ m₂ ∘ _!!_ p₁ ) !! i) ≡⟨ cong (_!!_ pp) (lookup∘tabulate _ i) ⟩ pp !! (inject+ m₂ (p₁ !! i)) ≡⟨ left!! (p₁ !! i) (inject+ m₄ ∘ (_!!_ p₃)) ⟩ inject+ m₄ (p₃ !! (p₁ !! i)) ≡⟨ cong (inject+ m₄) (sym (lookup∘tabulate _ i)) ⟩ inject+ m₄ ((p₁ ∘̂ p₃) !! i) ∎ ) where open ≡-Reasoning right⊎⊎!! : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → (p₁ : FinVec m₁ n₁) → (p₂ : FinVec m₂ n₂) → (p₃ : FinVec m₃ m₁) → (p₄ : FinVec m₄ m₂) → (i : Fin n₂) → (p₃ ⊎c p₄) !! ( (p₁ ⊎c p₂) !! raise n₁ i ) ≡ raise m₃ ( (p₂ ∘̂ p₄) !! i) right⊎⊎!! {m₁} {m₂} {m₃} {_} {n₁} {_} p₁ p₂ p₃ p₄ i = let pp = p₃ ⊎c p₄ in let qq = p₁ ⊎c p₂ in begin ( pp !! (qq !! raise n₁ i) ≡⟨ cong (_!!_ pp) (lookup-++-raise (tabulate (inject+ m₂ ∘ _!!_ p₁)) (tabulate (raise m₁ ∘ _!!_ p₂)) i) ⟩ pp !! (tabulate (raise m₁ ∘ _!!_ p₂) !! i) ≡⟨ cong (_!!_ pp) (lookup∘tabulate _ i) ⟩ pp !! raise m₁ (p₂ !! i) ≡⟨ right!! {m₁} (p₂ !! i) (raise m₃ ∘ (_!!_ p₄)) ⟩ raise m₃ (p₄ !! (p₂ !! i)) ≡⟨ cong (raise m₃) (sym (lookup∘tabulate _ i)) ⟩ raise m₃ ((p₂ ∘̂ p₄) !! i) ∎ ) where open ≡-Reasoning ⊎c-distrib : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → {p₁ : FinVec m₁ n₁} → {p₂ : FinVec m₂ n₂} → {p₃ : FinVec m₃ m₁} → {p₄ : FinVec m₄ m₂} → (p₁ ⊎c p₂) ∘̂ (p₃ ⊎c p₄) ≡ (p₁ ∘̂ p₃) ⊎c (p₂ ∘̂ p₄) ⊎c-distrib {m₁} {m₂} {m₃} {m₄} {n₁} {n₂} {p₁} {p₂} {p₃} {p₄} = let p₃₄ = p₃ ⊎c p₄ in let p₁₂ = p₁ ⊎c p₂ in let lhs = λ i → p₃₄ !! (p₁₂ !! i) in begin ( tabulate lhs ≡⟨ tabulate-split {n₁} {n₂} ⟩ tabulate {n₁} (lhs ∘ inject+ n₂) ++V tabulate {n₂} (lhs ∘ raise n₁) ≡⟨ cong₂ _++V_ (finext (left⊎⊎!! p₁ _ _ _)) (finext (right⊎⊎!! p₁ _ _ _)) ⟩ tabulate {n₁} (λ i → inject+ m₄ ((p₁ ∘̂ p₃) !! i)) ++V tabulate {n₂} (λ i → raise m₃ ((p₂ ∘̂ p₄) !! i)) ≡⟨ refl ⟩ (p₁ ∘̂ p₃) ⊎c (p₂ ∘̂ p₄) ∎) where open ≡-Reasoning private concat!! : {A : Set} {m n : ℕ} → (a : Fin m) → (b : Fin n) → (xss : Vec (Vec A n) m) → concatV xss !! (Times.fwd (a ,′ b)) ≡ (xss !! a) !! b concat!! zero b (xs ∷ xss) = lookup-++-inject+ xs (concatV xss) b concat!! (suc a) b (xs ∷ xss) = trans (lookup-++-raise xs (concatV xss) (Times.fwd (a ,′ b))) (concat!! a b xss) ×c-equiv : {m₁ m₂ n₁ n₂ : ℕ} (p₁ : FinVec m₁ n₁) (p₂ : FinVec m₂ n₂) → (p₁ ×c p₂) ≡ concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) ×c-equiv p₁ p₂ = let zss = mapV (λ b → mapV (λ x → b ,′ x) p₂) p₁ in begin ( (p₁ ×c p₂) ≡⟨ refl ⟩ mapV Times.fwd (concatV zss) ≡⟨ sym (concat-map zss Times.fwd) ⟩ concatV (mapV (mapV Times.fwd) zss) ≡⟨ cong concatV (map-map-map Times.fwd (λ b → mapV (λ x → b ,′ x) p₂) p₁) ⟩ concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) ∎) where open ≡-Reasoning lookup-2d : {A : Set} (m n : ℕ) → (k : Fin (m * n)) → {f : Fin m × Fin n → A} → concatV (tabulate {m} (λ i → tabulate {n} (λ j → f (i ,′ j)))) !! k ≡ f (Times.bwd k) lookup-2d m n k {f} = let lhs = concatV (tabulate {m} (λ i → tabulate {n} (λ j → f (i ,′ j)))) a = proj₁ (Times.bwd {m} {n} k) b = proj₂ (Times.bwd {m} {n} k) in begin ( lhs !! k ≡⟨ cong (_!!_ lhs) (sym (Times.fwd∘bwd~id {m} k)) ⟩ lhs !! (Times.fwd (a ,′ b)) ≡⟨ concat!! a b _ ⟩ (tabulate {m} (λ i → tabulate {n} (λ j → f (i ,′ j))) !! a) !! b ≡⟨ cong (λ x → x !! b) (lookup∘tabulate _ a) ⟩ tabulate {n} (λ j → f (a ,′ j)) !! b ≡⟨ lookup∘tabulate _ b ⟩ f (a ,′ b) ≡⟨ refl ⟩ f (Times.bwd k) ∎) where open ≡-Reasoning ×c!! : {m₁ m₂ n₁ n₂ : ℕ} (p₁ : FinVec m₁ n₁) (p₂ : FinVec m₂ n₂) (k : Fin (n₁ * n₂)) → (p₁ ×c p₂) !! k ≡ Times.fwd (p₁ !! proj₁ (Times.bwd k) ,′ p₂ !! proj₂ (Times.bwd {n₁} k)) ×c!! {n₁ = n₁} p₁ p₂ k = let a = proj₁ (Times.bwd {n₁} k) in let b = proj₂ (Times.bwd {n₁} k) in begin ( (p₁ ×c p₂) !! k ≡⟨ cong₂ _!!_ (×c-equiv p₁ p₂) (sym (Times.fwd∘bwd~id {n₁} k)) ⟩ concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) !! Times.fwd (a ,′ b) ≡⟨ concat!! a b _ ⟩ ((mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) !! a) !! b ≡⟨ cong (λ x → x !! b) (lookup-map a _ p₁) ⟩ mapV Times.fwd (mapV (λ x → p₁ !! a ,′ x) p₂) !! b ≡⟨ cong (λ x → x !! b) (sym (map-∘ Times.fwd _ p₂)) ⟩ mapV (Times.fwd ∘ (λ x → p₁ !! a ,′ x)) p₂ !! b ≡⟨ lookup-map b _ p₂ ⟩ Times.fwd (p₁ !! a ,′ p₂ !! b) ∎) where open ≡-Reasoning ×c-distrib : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → {p₁ : FinVec m₁ n₁} → {p₂ : FinVec m₂ n₂} → {p₃ : FinVec m₃ m₁} → {p₄ : FinVec m₄ m₂} → (p₁ ×c p₂) ∘̂ (p₃ ×c p₄) ≡ (p₁ ∘̂ p₃) ×c (p₂ ∘̂ p₄) ×c-distrib {m₁} {m₂} {m₃} {m₄} {n₁} {n₂} {p₁} {p₂} {p₃} {p₄} = let p₃₄ = p₃ ×c p₄ in let p₁₂ = p₁ ×c p₂ in let p₂₄ = p₂ ∘̂ p₄ in let p₁₃ = p₁ ∘̂ p₃ in let lhs = λ i → p₃₄ !! (p₁₂ !! i) in let zss = mapV (λ b → mapV (λ x → b ,′ x) (p₂ ∘̂ p₄)) (p₁ ∘̂ p₃) in begin ( tabulate {n₁ * n₂} (λ i → p₃₄ !! (p₁₂ !! i)) ≡⟨ finext (λ j → cong (_!!_ p₃₄) (×c!! p₁ p₂ j)) ⟩ tabulate {n₁ * n₂} (λ i → p₃₄ !! Times.fwd (p₁ !! proj₁ (Times.bwd i) ,′ p₂ !! proj₂ (Times.bwd i))) ≡⟨ finext (λ j → ×c!! p₃ p₄ _) ⟩ tabulate (λ i → let k = Times.fwd (p₁ !! proj₁ (Times.bwd i) ,′ p₂ !! proj₂ (Times.bwd i)) in Times.fwd (p₃ !! proj₁ (Times.bwd k) ,′ p₄ !! proj₂ (Times.bwd k))) ≡⟨ finext (λ i → cong₂ (λ x y → Times.fwd (p₃ !! proj₁ x ,′ p₄ !! proj₂ y)) (Times.bwd∘fwd~id {m₁} {m₂} (p₁ !! proj₁ (Times.bwd i) ,′ _)) (Times.bwd∘fwd~id (_ ,′ p₂ !! proj₂ (Times.bwd i)))) ⟩ tabulate (λ i → Times.fwd (p₃ !! (p₁ !! proj₁ (Times.bwd i)) ,′ (p₄ !! (p₂ !! proj₂ (Times.bwd i))))) ≡⟨ finext (λ k → sym (lookup-2d n₁ n₂ k)) ⟩ tabulate (λ k → concatV (tabulate {n₁} (λ z → tabulate {n₂} (λ w → Times.fwd ((p₃ !! (p₁ !! z)) ,′ (p₄ !! (p₂ !! w)))))) !! k) ≡⟨ tabulate∘lookup _ ⟩ concatV (tabulate {n₁} (λ z → tabulate {n₂} (λ w → Times.fwd ((p₃ !! (p₁ !! z)) ,′ (p₄ !! (p₂ !! w)))))) ≡⟨ cong concatV (finext (λ i → tabulate-∘ Times.fwd (λ w → ((p₃ !! (p₁ !! i)) ,′ (p₄ !! (p₂ !! w)))))) ⟩ concatV (tabulate (λ z → mapV Times.fwd (tabulate (λ w → (p₃ !! (p₁ !! z)) ,′ (p₄ !! (p₂ !! w)))))) ≡⟨ cong concatV (finext (λ i → cong (mapV Times.fwd) (tabulate-∘ (λ x → (p₃ !! (p₁ !! i)) ,′ x) (_!!_ p₄ ∘ _!!_ p₂)))) ⟩ concatV (tabulate (λ z → mapV Times.fwd (mapV (λ x → (p₃ !! (p₁ !! z)) ,′ x) p₂₄))) ≡⟨ cong concatV (tabulate-∘ _ (_!!_ p₃ ∘ _!!_ p₁)) ⟩ concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂₄)) p₁₃) ≡⟨ sym (×c-equiv p₁₃ p₂₄) ⟩ (p₁ ∘̂ p₃) ×c (p₂ ∘̂ p₄) ∎) where open ≡-Reasoning -- there might be a simpler proofs of this using tablate∘lookup 1C×1C≡1C : ∀ {m n} → (1C {m} ×c 1C {n}) ≡ 1C {m * n} 1C×1C≡1C {m} {n} = begin ( 1C {m} ×c 1C ≡⟨ ×c-equiv 1C 1C ⟩ concatV (mapV (λ y → mapV Times.fwd (mapV (_,′_ y) (1C {n}))) (1C {m})) ≡⟨ cong (concatV {n = m}) (sym (tabulate-∘ _ id)) ⟩ concatV {n = m} (tabulate (λ y → mapV Times.fwd (mapV (_,′_ y) (1C {n})))) ≡⟨ cong (concatV {n = m}) (finext (λ y → sym (map-∘ Times.fwd (λ x → y ,′ x) 1C))) ⟩ concatV (tabulate {n = m} (λ y → mapV (Times.fwd ∘ (_,′_ y)) (1C {n}))) ≡⟨ cong (concatV {m = n} {m}) (finext (λ y → sym (tabulate-∘ (Times.fwd ∘ (_,′_ y)) id))) ⟩ concatV (tabulate {n = m} (λ a → tabulate {n = n} (λ b → Times.fwd (a ,′ b)))) ≡⟨ sym (tabulate∘lookup _) ⟩ tabulate (λ k → concatV (tabulate {n = m} (λ a → tabulate {n = n} (λ b → Times.fwd (a ,′ b)))) !! k) ≡⟨ finext (λ k → lookup-2d m n k) ⟩ tabulate (λ k → Times.fwd {m} {n} (Times.bwd k)) ≡⟨ finext (Times.fwd∘bwd~id {m} {n}) ⟩ 1C {m * n} ∎ ) where open ≡-Reasoning ------------------------------------------------------------------------------ -- A few "reveal" functions, to let us peek into the representation reveal1C : ∀ {m} → allFin m ≡ 1C reveal1C = refl reveal0C : [] ≡ 1C {0} reveal0C = refl reveal⊎c : ∀ {m₁ n₁ m₂ n₂} → {α : FinVec m₁ m₂} → {β : FinVec n₁ n₂} → α ⊎c β ≡ tabulate (Plus.fwd ∘ inj₁ ∘ _!!_ α) ++V tabulate (Plus.fwd {m₁} ∘ inj₂ ∘ _!!_ β) reveal⊎c = refl ------------------------------------------------------------------------------
37.074427
81
0.460545
52405cd380a6f4f2394427efcc097e387287b08d
1,312
agda
Agda
base/agda/Base/Free/Instance/Maybe/Properties.agda
FreeProving/free-compiler
6931b9ca652a185a92dd824373f092823aea4ea9
[ "BSD-3-Clause" ]
36
2020-02-06T11:03:34.000Z
2021-08-21T13:38:23.000Z
base/agda/Base/Free/Instance/Maybe/Properties.agda
FreeProving/free-compiler
6931b9ca652a185a92dd824373f092823aea4ea9
[ "BSD-3-Clause" ]
120
2020-04-09T09:40:39.000Z
2020-12-08T07:46:01.000Z
base/agda/Base/Free/Instance/Maybe/Properties.agda
FreeProving/free-compiler
6931b9ca652a185a92dd824373f092823aea4ea9
[ "BSD-3-Clause" ]
3
2020-04-08T11:23:46.000Z
2021-05-14T07:48:41.000Z
module Base.Free.Instance.Maybe.Properties where open import Relation.Binary.PropositionalEquality using (refl; cong) open import Base.Free using (Free; pure; impure; _>>=_) open import Base.Free.Instance.Maybe using (Just; Nothing) renaming (Maybe to MaybeF) open import Base.Isomorphism using (_≃_) open _≃_ open import Base.Extensionality using (ext) open import Data.Unit using (tt) import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong) -- The usual `Maybe` monad representation an the free version are isomorphic. data Maybe (A : Set) : Set where just : A → Maybe A nothing : Maybe A Maybe≃MaybeF : ∀ {A} → Maybe A ≃ MaybeF A to Maybe≃MaybeF (just x) = Just x to Maybe≃MaybeF nothing = Nothing from Maybe≃MaybeF (pure x) = just x from Maybe≃MaybeF (impure tt _) = nothing from∘to Maybe≃MaybeF (just x) = refl from∘to Maybe≃MaybeF nothing = refl to∘from Maybe≃MaybeF (pure x) = refl to∘from Maybe≃MaybeF (impure tt x) = cong (impure tt) (ext λ()) Nothing>>=k≡Nothing : ∀ {A B} → (k : A → MaybeF B) → (Nothing >>= k) ≡ Nothing Nothing>>=k≡Nothing k = cong (impure tt) (ext (λ ()))
38.588235
110
0.612805
431eed9ec9b64db0c05af31bbdd43dba40dfe7b5
219
agda
Agda
test/Fail/Issue413.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue413.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue413.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue413 where data Bool : Set where data ℕ : Set where zero : ℕ data Type : (A : Set) → Set where isBool : Type Bool isℕ : Type ℕ g : (A : Set) → Type A → Type A → ℕ g .Bool isBool isBool = zero
14.6
35
0.60274
ad7dcd21bac55434c9d49c30d108aa35b3f04790
3,464
agda
Agda
src/LibraBFT/Impl/Consensus/BlockStorage/BlockRetriever.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/BlockStorage/BlockRetriever.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/BlockStorage/BlockRetriever.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Haskell.Modules.RWS.RustAnyHow import LibraBFT.Impl.Consensus.ConsensusTypes.BlockRetrieval as BlockRetrieval import LibraBFT.Impl.IO.OBM.ObmNeedFetch as ObmNeedFetch open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Consensus.Types.EpochIndep open import LibraBFT.ImplShared.Util.Dijkstra.All open import Optics.All import Util.KVMap as Map open import Util.Prelude ------------------------------------------------------------------------------ import Data.String as String module LibraBFT.Impl.Consensus.BlockStorage.BlockRetriever where pickPeer : ℕ → List Author → Either ErrLog (Author × List Author) -- LBFT-OBM-DIFF : this lives in sync_manager.rs (in this file to isolate IO) -- TODO-1 PROVE IT TERMINATES {-# TERMINATING #-} retrieveBlockForQCM : BlockRetriever → QuorumCert → U64 → LBFT (Either ErrLog (List Block)) retrieveBlockForQCM _retriever qc numBlocks = loop (qc ^∙ qcCertifiedBlock ∙ biId) 0 (Map.kvm-keys (qc ^∙ qcLedgerInfo ∙ liwsSignatures)) where doLoop : HashValue → ℕ → List Author → LBFT (Either ErrLog (List Block)) logIt : InfoLog → LBFT Unit here' : List String.String → List String.String loop : HashValue → ℕ → List Author → LBFT (Either ErrLog (List Block)) loop blockId attempt = λ where [] → bail fakeErr -- [ "failed to fetch block, no more peers available" -- , lsHV blockId, show attempt ] peers0@(_ ∷ _) → do mme ← use (lRoundManager ∙ rmObmMe) maybeSD mme (bail fakeErr) $ λ me → do nf ← use lObmNeedFetch eitherS (pickPeer attempt peers0) bail $ λ (peer , peers) → do let request = BlockRetrievalRequest∙new me blockId numBlocks logIt fakeInfo -- ["to", lsA peer, lsBRQ request] let response = ObmNeedFetch.writeRequestReadResponseUNSAFE nf me peer request -- TODO : sign response and check sig on response case response ^∙ brpStatus of λ where BRSSucceeded → do logIt fakeInfo -- (here [lsBRP response]) vv ← use (lRoundManager ∙ rmEpochState ∙ esVerifier) -- LBFT-OBM-DIFF/TODO : this should live in a "network" module case BlockRetrieval.verify response (request ^∙ brqBlockId) (request ^∙ brqNumBlocks) vv of λ where (Left e) → bail (withErrCtx (here' []) e) (Right _) → ok (response ^∙ brpBlocks) BRSIdNotFound → doLoop blockId attempt peers BRSNotEnoughBlocks → doLoop blockId attempt peers doLoop blockId attempt peers = do logIt fakeInfo -- (here' ["trying another peer", lsBRP response]) loop blockId (attempt + 1) peers here' t = "BlockRetriever" ∷ "retrieveBlockForQCM" ∷ "NeedFetch" ∷ t logIt l = -- do logInfo l -- let x = Unsafe.unsafePerformIO (putStrLn @Text (show l)) -- x `seq` pure x pickPeer _ = λ where [] → Left fakeErr -- ["no more peers"] (p ∷ ps) → pure (p , ps)
46.810811
113
0.637413
57fa7ed22d035c5e15afdea0847bf7ed00048133
1,410
agda
Agda
test/Fail/HoTTCompatibleWithSizeBasedTerminationMaximeDenes.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/HoTTCompatibleWithSizeBasedTerminationMaximeDenes.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/HoTTCompatibleWithSizeBasedTerminationMaximeDenes.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-01-08, following Maxime Denes 2014-01-06 -- This file demonstrates that size-based termination does -- not lead to incompatibility with HoTT. {-# OPTIONS --sized-types #-} open import Common.Size open import Common.Equality data Empty : Set where data Box : Size → Set where wrap : ∀ i → (Empty → Box i) → Box (↑ i) -- Box is inhabited at each stage > 0: gift : ∀ {i} → Empty → Box i gift () box : ∀ {i} → Box (↑ i) box {i} = wrap i gift -- wrap has an inverse: unwrap : ∀ i → Box (↑ i) → (Empty → Box i) unwrap .i (wrap i f) = f -- There is an isomorphism between (Empty → Box ∞) and (Box ∞) -- but none between (Empty → Box i) and (Box i). -- We only get the following, but it is not sufficient to -- produce the loop. postulate iso : ∀ i → (Empty → Box i) ≡ Box (↑ i) -- Since Agda's termination checker uses the structural order -- in addition to sized types, we need to conceal the subterm. postulate conceal : {A : Set} → A → A mutual loop : ∀ i → Box i → Empty loop .(↑ i) (wrap i x) = loop' (↑ i) (Empty → Box i) (iso i) (conceal x) -- We would like to write loop' i instead of loop' (↑ i) -- but this is ill-typed. Thus, we cannot achieve something -- well-founded wrt. to sized types. loop' : ∀ i A → A ≡ Box i → A → Empty loop' i .(Box i) refl x = loop i x -- The termination checker complains here, rightfully! bug : Empty bug = loop ∞ box
24.736842
74
0.631206
3534de0eff1bef19987253152ef623b54cec9593
6,560
agda
Agda
Ex3.agda
m-schmidt/CS410-17-Exercises
5db8e95bbcbe8dc0eec810f3e73130ecd78d207c
[ "BSD-3-Clause" ]
null
null
null
Ex3.agda
m-schmidt/CS410-17-Exercises
5db8e95bbcbe8dc0eec810f3e73130ecd78d207c
[ "BSD-3-Clause" ]
null
null
null
Ex3.agda
m-schmidt/CS410-17-Exercises
5db8e95bbcbe8dc0eec810f3e73130ecd78d207c
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --type-in-type #-} -- yes, I will let you cheat in this exercise {-# OPTIONS --allow-unsolved-metas #-} -- allows import, unfinished ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- CS410 2017/18 Exercise 3 WINDOWS AND OTHER STORIES (worth 25%) ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Dependencies ------------------------------------------------------------------------------ open import CS410-Prelude open import CS410-Categories open import Ex2 ------------------------------------------------------------------------------ -- PART I: Splittings ------------------------------------------------------------------------------ -- The type ls <[ ms ]> rs -- is similar to that found in Lec2.agda, but it works on lists, not numbers. -- It provides the evidence that a list ms can be split into a left sublist ls -- and a right sublist rs. In effect, it's a vector of bits that say which -- elements of ms go left and which go right. data _<[_]>_ {X : Set} : List X -> List X -> List X -> Set where sz : [] <[ [] ]> [] sl : forall {l ls ms rs} -> ls <[ ms ]> rs -> (l ,- ls) <[ l ,- ms ]> rs sr : forall {r ls ms rs} -> ls <[ ms ]> rs -> ls <[ r ,- ms ]> (r ,- rs) --??--3.1--------------------------------------------------------------------- -- Adapt _>[_]<_ from Lec2 to work for All. Given a P for each element of -- ls and rs, riffle them together to get Ps for all the ms. _>[_]<_ : {X : Set}{ls ms rs : List X} -> {P : X -> Set} -> All P ls -> ls <[ ms ]> rs -> All P rs -> All P ms pl >[ s ]< pr = {!!} -- Now, buikd the view that shows riffling can be inverted, using a splitting -- as the instructions to discover how to split an All in two. data IsRiffle {X : Set}{ls ms rs : List X}(s : ls <[ ms ]> rs){P : X -> Set} : All P ms -> Set where mkRiffle : (pl : All P ls)(pr : All P rs) -> IsRiffle s (pl >[ s ]< pr) isRiffle : {X : Set}{ls ms rs : List X}(s : ls <[ ms ]> rs) {P : X -> Set}(pm : All P ms) -> IsRiffle s pm isRiffle s pm = {!!} --??-------------------------------------------------------------------------- --??--3.2--------------------------------------------------------------------- -- Construct the "all on the right" splitting. srs : forall {X : Set}{xs : List X} -> [] <[ xs ]> xs srs = {!!} -- Construct a view to show that any "none on the left" splitting is -- "all on the right". Come up with the type yourself. -- Construct the splitting that corresponds to concatenation. slrs : forall {X : Set}(xs ys : List X) -> xs <[ xs +L ys ]> ys slrs xs ys = {!!} --??-------------------------------------------------------------------------- --??--3.3--------------------------------------------------------------------- -- Invent other useful operations which transform splittings. -- You will need some to do later parts of the exercise, so maybe -- wait until you see what you need. -- I expect you will need at least something that takes a pair of splittings -- that make a tree, like -- -- ms -- <[ ]> -- ls rs -- <[ ]> -- lrs rrs -- -- and compute a "rotated" pair of splittings like -- -- ms -- <[ ]> -- ?? rrs -- <[ ]> -- ls lrs -- HINT: Sg is your friend -- You'll probably need some other stuff, too. --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- PART II: Permutations ------------------------------------------------------------------------------ -- When is one list a permutation of another? data _~_ {X : Set} : List X -> List X -> Set where -- [] is a permutation of [] [] : [] ~ [] -- if xs ~ ys, then (x ,- xs) is a permutation of any list made by -- shoving x somewhere into ys _,-_ : forall {x xs ys' ys} -> (x ,- []) <[ ys' ]> ys -> xs ~ ys -> (x ,- xs) ~ ys' --??--3.4--------------------------------------------------------------------- -- Show that every list is a permutation of itself. reflP : {X : Set}{xs : List X} -> xs ~ xs reflP = {!!} --??-------------------------------------------------------------------------- --??--3.5--------------------------------------------------------------------- -- Construct an "unbiased" insertion operator which lets you grow a -- permutation by inserting a new element anywhere, left and right insP : forall {X : Set}{z : X}{xs xs' ys ys'} -> (z ,- []) <[ xs' ]> xs -> (z ,- []) <[ ys' ]> ys -> xs ~ ys -> xs' ~ ys' insP l r p = {!!} -- Now show that, given a permutation, and any element on the left, -- you can find out where it ended up on the right, and why the -- remaining elements form a permutation. findLonR : forall {X : Set}{z : X}{xs xs' ys'} -> (z ,- []) <[ xs' ]> xs -> xs' ~ ys' -> {!!} findLonR l p = {!!} -- HINT: again, you may need Sg to give a sensible return type. --??-------------------------------------------------------------------------- --??--3.6--------------------------------------------------------------------- -- Show that permutation is transitive. transP : {X : Set}{xs ys zs : List X} -> xs ~ ys -> ys ~ zs -> xs ~ zs transP p q = {!!} -- HINT: you will need to define some useful operations on splittings to -- get this to work. -- HINT: this may help you figure out what you need for findLonR -- For a small bonus, show that permutations are the morphisms of a -- Category. -- Show that permutation is symmetric. symP : {X : Set}{xs ys : List X} -> xs ~ ys -> ys ~ xs symP p = {!!} -- A category where all morphisms are invertible is called a "groupoid". --??-------------------------------------------------------------------------- --??--3.7--------------------------------------------------------------------- -- Make permutations act on All. permute : {X : Set}{xs ys : List X} -> xs ~ ys -> {Q : X -> Set} -> All Q xs -> All Q ys permute p qs = {!!} --??-------------------------------------------------------------------------- -- MORE TO FOLLOW
32.636816
78
0.397256
34eb6a106e7753e3a36699c5f76784f7c9beed78
2,401
agda
Agda
typ-dec.agda
hazelgrove/hazel-palette-agda
c3225acc3c94c56376c6842b82b8b5d76912df2a
[ "MIT" ]
4
2020-10-04T06:45:06.000Z
2021-12-19T15:38:31.000Z
typ-dec.agda
hazelgrove/hazel-palette-agda
c3225acc3c94c56376c6842b82b8b5d76912df2a
[ "MIT" ]
9
2020-09-30T20:27:56.000Z
2020-10-20T20:44:13.000Z
typ-dec.agda
hazelgrove/hazelnut-livelits-agda
c3225acc3c94c56376c6842b82b8b5d76912df2a
[ "MIT" ]
null
null
null
open import Nat open import Prelude open import core open import contexts module typ-dec where lemma-arr-l : ∀{t1 t2 t4} → t1 ==> t2 == t1 ==> t4 → t2 == t4 lemma-arr-l refl = refl lemma-arr-r : ∀{t1 t2 t3} → t1 ==> t2 == t3 ==> t2 → t1 == t3 lemma-arr-r refl = refl lemma-arr-b : ∀{t1 t2 t3 t4} → t1 ==> t2 == t3 ==> t4 → t1 == t3 lemma-arr-b refl = refl lemma-prod-l : ∀{t1 t2 t4} → t1 ⊗ t2 == t1 ⊗ t4 → t2 == t4 lemma-prod-l refl = refl lemma-prod-r : ∀{t1 t2 t3} → t1 ⊗ t2 == t3 ⊗ t2 → t1 == t3 lemma-prod-r refl = refl lemma-prod-b : ∀{t1 t2 t3 t4} → t1 ⊗ t2 == t3 ⊗ t4 → t1 == t3 lemma-prod-b refl = refl -- types are decidable typ-dec : dec typ typ-dec b b = Inl refl typ-dec b ⦇·⦈ = Inr (λ ()) typ-dec b (t2 ==> t3) = Inr (λ ()) typ-dec ⦇·⦈ b = Inr (λ ()) typ-dec ⦇·⦈ ⦇·⦈ = Inl refl typ-dec ⦇·⦈ (t2 ==> t3) = Inr (λ ()) typ-dec (t1 ==> t2) b = Inr (λ ()) typ-dec (t1 ==> t2) ⦇·⦈ = Inr (λ ()) typ-dec (t1 ==> t2) (t3 ==> t4) with typ-dec t1 t3 | typ-dec t2 t4 typ-dec (t1 ==> t2) (.t1 ==> .t2) | Inl refl | Inl refl = Inl refl typ-dec (t1 ==> t2) (.t1 ==> t4) | Inl refl | Inr x₁ = Inr (λ x → x₁ (lemma-arr-l x)) typ-dec (t1 ==> t2) (t3 ==> .t2) | Inr x | Inl refl = Inr (λ x₁ → x (lemma-arr-r x₁)) typ-dec (t1 ==> t2) (t3 ==> t4) | Inr x | Inr x₁ = Inr (λ x₂ → x (lemma-arr-b x₂)) typ-dec b (t2 ⊗ t3) = Inr (λ ()) typ-dec ⦇·⦈ (t2 ⊗ t3) = Inr (λ ()) typ-dec (t1 ==> t2) (t3 ⊗ t4) = Inr (λ ()) typ-dec (t1 ⊗ t2) b = Inr (λ ()) typ-dec (t1 ⊗ t2) ⦇·⦈ = Inr (λ ()) typ-dec (t1 ⊗ t2) (t3 ==> t4) = Inr (λ ()) typ-dec (t1 ⊗ t2) (t3 ⊗ t4) with typ-dec t1 t3 | typ-dec t2 t4 typ-dec (t1 ⊗ t2) (.t1 ⊗ .t2) | Inl refl | Inl refl = Inl refl typ-dec (t1 ⊗ t2) (.t1 ⊗ t4) | Inl refl | Inr x₁ = Inr (λ x → x₁ (lemma-prod-l x)) typ-dec (t1 ⊗ t2) (t3 ⊗ .t2) | Inr x | Inl refl = Inr (λ x' → x (lemma-prod-r x')) typ-dec (t1 ⊗ t2) (t3 ⊗ t4) | Inr x | Inr x₁ = Inr (λ x' → x (lemma-prod-b x')) -- if an arrow is disequal, it disagrees in the first or second argument ne-factor : ∀{τ1 τ2 τ3 τ4} → (τ1 ==> τ2) ≠ (τ3 ==> τ4) → (τ1 ≠ τ3) + (τ2 ≠ τ4) ne-factor {τ1} {τ2} {τ3} {τ4} ne with typ-dec τ1 τ3 | typ-dec τ2 τ4 ne-factor ne | Inl refl | Inl refl = Inl (λ x → ne refl) ne-factor ne | Inl x | Inr x₁ = Inr x₁ ne-factor ne | Inr x | Inl x₁ = Inl x ne-factor ne | Inr x | Inr x₁ = Inl x
40.694915
91
0.507289
1b2f42291f295f715615122d9b6c334a62f58840
93
agda
Agda
test/Fail/Issue4784a.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Fail/Issue4784a.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Fail/Issue4784a.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --cubical-compatible #-} postulate A : Set B : A → Set T = (@0 x : A) → B x
13.285714
36
0.516129
fd27ebe9c4b64b87f501a5295cd3112f10c91254
1,239
agda
Agda
src/Categories/NaturalTransformation/Equivalence.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/NaturalTransformation/Equivalence.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/NaturalTransformation/Equivalence.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} -- define a less-than-great equivalence on natural transformations module Categories.NaturalTransformation.Equivalence where open import Level open import Relation.Binary using (Rel; IsEquivalence; Setoid) open import Categories.Category open import Categories.Functor open import Categories.NaturalTransformation.Core private variable o ℓ e o′ ℓ′ e′ : Level C D E : Category o ℓ e -- This ad hoc equivalence for NaturalTransformation should really be 'modification' -- (yep, tricategories!). What is below is only part of the definition of a 'modification'. TODO infix 4 _≃_ _≃_ : ∀ {F G : Functor C D} → Rel (NaturalTransformation F G) _ _≃_ {D = D} X Y = ∀ {x} → D [ NaturalTransformation.η X x ≈ NaturalTransformation.η Y x ] ≃-isEquivalence : ∀ {F G : Functor C D} → IsEquivalence (_≃_ {F = F} {G}) ≃-isEquivalence {D = D} {F} {G} = record { refl = refl ; sym = λ f → sym f -- need to eta-expand to get things to line up properly ; trans = λ f g → trans f g } where open Category.Equiv D ≃-setoid : ∀ (F G : Functor C D) → Setoid _ _ ≃-setoid F G = record { Carrier = NaturalTransformation F G ; _≈_ = _≃_ ; isEquivalence = ≃-isEquivalence }
31.769231
98
0.677159
216685119fee4c540020c7a8da72d038c0e51e15
810
agda
Agda
examples/outdated-and-incorrect/cat/Product.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/cat/Product.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/cat/Product.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Product where open import Base open import Category open import Unique open import Dual module Prod (ℂ : Cat) where private ℂ' = η-Cat ℂ open module C = Cat ℂ' open module U = Uniq ℂ' data _×_ (A B : Obj) : Set1 where prod : (AB : Obj) (π₀ : AB ─→ A) (π₁ : AB ─→ B) -> ((X : Obj)(f : X ─→ A)(g : X ─→ B) -> ∃! \(h : X ─→ AB) -> π₀ ∘ h == f /\ π₁ ∘ h == g ) -> A × B Product : {A B : Obj} -> A × B -> Obj Product (prod AB _ _ _) = AB π₀ : {A B : Obj}(p : A × B) -> Product p ─→ A π₀ (prod _ p _ _) = p π₁ : {A B : Obj}(p : A × B) -> Product p ─→ B π₁ (prod _ _ q _) = q module Sum (ℂ : Cat) = Prod (η-Cat ℂ op) renaming ( _×_ to _+_ ; prod to sum ; Product to Sum ; π₀ to inl ; π₁ to inr )
19.756098
52
0.461728
fdc8422334b66a1a8a7f48000bc808b2f720ca4a
571
agda
Agda
test/Succeed/Issue1914.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1914.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1914.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS -v tc.size:100 #-} -- {-# OPTIONS -v tc.meta:100 #-} {-# OPTIONS --sized-types #-} open import Common.Size using (Size; Size<_) postulate A : Set record R (i₀ : Size) (x : A) : Set where coinductive field force : (j : Size< i₀) → R j x postulate P : (A → Set) → Set f : (Q : A → Set) (x : A) {{ c : P Q }} → Q x → Q x g : (i₁ : Size) (x : A) → R i₁ x → R i₁ x instance c : {i₂ : Size} → P (R i₂) accepted rejected : A → (x : A) (i₃ : Size) → R i₃ x → R i₃ x accepted y x i r = g _ _ (f _ _ r) rejected y x i r = g _ _ (f _ x r)
19.689655
61
0.509632
1eec33d74308bece44f5ebc2fe0229e838cbfa7e
451
agda
Agda
test/Succeed/Issue2626.agda
MxmUrw/agda
6ede01fa854c5472e54f7d1799ca2c08ed316129
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2626.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2626.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-07-05, issue #2626 raised by cartazio -- shrunk by gallais -- There was an assignTerm inspite of -- dontAssignMetas (issued by checking inequations involving ⊔ˢ) -- {-# OPTIONS -v tc:45 #-} {-# OPTIONS --allow-unsolved-metas --sized-types #-} module Issue2626 where open import Agda.Builtin.Equality open import Agda.Builtin.Size data D : (sz : Size) → Set where c : (q s : Size) → D (q ⊔ˢ s) postulate foo : c _ _ ≡ c _ _
21.47619
64
0.676275
1bb26fd9736409da86a171d2c015390676f88ce7
3,678
agda
Agda
src/Examples/Gcd/Euclid.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
29
2021-07-14T03:18:28.000Z
2022-03-22T20:35:11.000Z
src/Examples/Gcd/Euclid.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
null
null
null
src/Examples/Gcd/Euclid.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
2
2021-10-06T10:28:24.000Z
2022-01-29T08:12:01.000Z
{-# OPTIONS --prop --rewriting #-} module Examples.Gcd.Euclid where open import Calf.CostMonoid import Calf.CostMonoids as CM {- This file defines the parameters of the analysis of Euclid's algorithm for gcd and its cost recurrence relation. -} open import Calf CM.ℕ-CostMonoid open import Calf.Types.Nat open import Data.Nat open import Relation.Binary.PropositionalEquality as P open import Induction.WellFounded open import Induction open import Data.Nat.Properties open import Data.Nat.DivMod open import Relation.Nullary.Decidable using (False) open import Data.Nat.Induction using (<-wellFounded) open import Data.Product open import Agda.Builtin.Nat using (div-helper; mod-helper) open import Relation.Binary using (Rel) open import Relation.Unary using (Pred; _⊆′_) mod-tp : (x y : val nat) → cmp (meta (False (y ≟ 0))) → tp pos mod-tp x y h = Σ++ nat λ z → (U (meta (z ≡ _%_ x y {h}))) mod : cmp ( Π nat λ x → Π nat λ y → Π (U (meta (False (y ≟ 0)))) λ h → F (mod-tp x y h)) mod x y h = step (F (mod-tp x y h)) 1 (ret {mod-tp x y h} (_%_ x y {h} , refl)) gcd/depth/helper : ∀ n → ((m : ℕ) → m < n → (k : ℕ) → (k > m) → ℕ) → (m : ℕ) → (m > n) → ℕ gcd/depth/helper zero h m h' = 0 gcd/depth/helper n@(suc n') h m h' = suc (h (m % n) (m%n<n m n') n (m%n<n m n')) gcd/i = Σ++ nat λ x → Σ++ nat λ y → U (meta (x > y)) m>n = val gcd/i gcd/depth : m>n → ℕ gcd/depth (x , (y , g)) = All.wfRec <-wellFounded _ (λ y → (x : ℕ) → x > y → ℕ) gcd/depth/helper y x g gcd/depth/helper-ext : (x₁ : ℕ) {IH IH′ : WfRec _<_ (λ y₁ → (x₂ : ℕ) → x₂ > y₁ → ℕ) x₁} → ({y = y₁ : ℕ} (y<x : y₁ < x₁) → IH y₁ y<x ≡ IH′ y₁ y<x) → gcd/depth/helper x₁ IH ≡ gcd/depth/helper x₁ IH′ gcd/depth/helper-ext zero h = refl gcd/depth/helper-ext (suc x) h = funext λ m → funext λ h1 → P.cong suc ( let g = h {m % suc x} (m%n<n m x) in P.cong-app (P.cong-app g _) _ ) module irr {a r ℓ} {A : Set a} {_<_ : Rel A r} (wf : WellFounded _<_) (P : Pred A ℓ) (f : WfRec _<_ P ⊆′ P) (f-ext : (x : A) {IH IH′ : WfRec _<_ P x} → (∀ {y} y<x → IH y y<x ≡ IH′ y y<x) → f x IH ≡ f x IH′) where some-wfRecBuilder-irrelevant : ∀ x → (q q′ : Acc _<_ x) → Some.wfRecBuilder P f x q ≡ Some.wfRecBuilder P f x q′ some-wfRecBuilder-irrelevant = All.wfRec wf _ ((λ x → (q q′ : Acc _<_ x) → Some.wfRecBuilder P f x q ≡ Some.wfRecBuilder P f x q′)) ((λ { x IH (acc rs) (acc rs') → funext λ y → funext λ h → f-ext y λ {y'} h' → let g = IH y h (rs y h) (rs' y h) in P.cong-app (P.cong-app g y') h' })) gcd/depth-unfold-zero : ∀ {x h} → gcd/depth (x , 0 , h) ≡ 0 gcd/depth-unfold-zero = refl gcd/depth-unfold-suc : ∀ {x y h} → gcd/depth (x , suc y , h) ≡ suc (gcd/depth (suc y , x % suc y , m%n<n x y)) gcd/depth-unfold-suc {x} {y} {h} = P.cong suc ( P.subst (λ ih → gcd/depth/helper (mod-helper 0 y x y) (ih) (suc y) (m%n<n x y) ≡ gcd/depth/helper (mod-helper 0 y x y) (All.wfRecBuilder <-wellFounded _ (λ y₁ → (x₁ : ℕ) → x₁ > y₁ → ℕ) gcd/depth/helper (mod-helper 0 y x y)) (suc y) (m%n<n x y)) (irr.some-wfRecBuilder-irrelevant <-wellFounded (λ y → (x : ℕ) → x > y → ℕ) gcd/depth/helper (gcd/depth/helper-ext) (x % suc y) (<-wellFounded (mod-helper 0 y x y)) (Subrelation.accessible ≤⇒≤′ (Data.Nat.Induction.<′-wellFounded′ (suc y) (mod-helper 0 y x y) (≤⇒≤′ (m%n<n x y))))) refl ) m%n<n' : ∀ m n h → _%_ m n {h} < n m%n<n' m (suc n) h = m%n<n m n
36.78
119
0.542414
7c1cdae157db482d8494baf8a447d5f43d6d4161
368
agda
Agda
test/Succeed/Issue2597.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2597.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2597.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 Overlap : Set where constructor mk field overlap {{a}} : A record NoOverlap : Set where constructor mk field {{a}} : A ok : A → NoOverlap ok a = mk {{a}} bad : A → Overlap bad a = mk {{a}} -- Function does not accept argument {{a}} -- when checking that {{a}} is a valid argument to a function of type -- {{a = a₁ : A}} → Overlap
18.4
69
0.627717
d040ea0250e3795a6b16e2d9ea7b09969760e37c
441
agda
Agda
agda/Data/List/Sugar.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Data/List/Sugar.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Data/List/Sugar.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe #-} module Data.List.Sugar where open import Data.List.Base open import Prelude [_] : A → List A [ x ] = x ∷ [] pure : A → List A pure = [_] _>>=_ : List A → (A → List B) → List B _>>=_ = flip concatMap _>>_ : List A → List B → List B xs >> ys = xs >>= const ys _<*>_ : List (A → B) → List A → List B fs <*> xs = do f ← fs x ← xs [ f x ] guard : Bool → List ⊤ guard false = [] guard true = [ tt ]
15.206897
38
0.530612
4be7d25195cacedc5258cd64aa48cceb14a1ead3
5,722
agda
Agda
Cubical/Foundations/Equiv/PathSplit.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/Equiv/PathSplit.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Foundations/Equiv/PathSplit.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{- Theory about path split equivalences. They are convenient to construct localization HITs as in (the "modalities paper") https://arxiv.org/abs/1706.07526 - there are construction from and to equivalences ([pathSplitToEquiv] , [equivToPathSplit]) - the structure of a path split equivalence is actually a proposition ([isPropIsPathSplitEquiv]) The module starts with a couple of general facts about equivalences: - if f is an equivalence then (cong f) is an equivalence ([equivCong]) - if f is an equivalence then pre- and postcomposition with f are equivalences ([preCompEquiv], [postCompEquiv]) (those are not in 'Equiv.agda' because they need Univalence.agda (which imports Equiv.agda)) -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Equiv.PathSplit where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv.Properties open import Cubical.Data.Sigma record isPathSplitEquiv {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where field sec : hasSection f secCong : (x y : A) → hasSection (λ (p : x ≡ y) → cong f p) PathSplitEquiv : ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ') PathSplitEquiv A B = Σ[ f ∈ (A → B) ] isPathSplitEquiv f open isPathSplitEquiv idIsPathSplitEquiv : ∀ {ℓ} {A : Type ℓ} → isPathSplitEquiv (λ (x : A) → x) sec idIsPathSplitEquiv = (λ x → x) , (λ _ → refl) secCong idIsPathSplitEquiv = λ _ _ → (λ p → p) , λ p _ → p module _ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where open Iso toIso : (f : A → B) → isPathSplitEquiv f → Iso A B fun (toIso f _) = f inv (toIso _ p) = p .sec .fst rightInv (toIso _ p) = p .sec .snd leftInv (toIso f p) x = p .secCong (p .sec .fst (f x)) x .fst (p .sec .snd (f x)) toIsEquiv : (f : A → B) → isPathSplitEquiv f → isEquiv f toIsEquiv f p = isoToIsEquiv (toIso f p) sectionOfEquiv' : (f : A → B) → isEquiv f → B → A sectionOfEquiv' f isEqv x = isEqv .equiv-proof x .fst .fst isSec : (f : A → B) → (pf : isEquiv f) → section f (sectionOfEquiv' f pf) isSec f isEqv x = isEqv .equiv-proof x .fst .snd sectionOfEquiv : (f : A → B) → isEquiv f → hasSection f sectionOfEquiv f e = sectionOfEquiv' f e , isSec f e module _ {ℓ} {A B : Type ℓ} where fromIsEquiv : (f : A → B) → isEquiv f → isPathSplitEquiv f sec (fromIsEquiv f pf) = sectionOfEquiv' f pf , isSec f pf secCong (fromIsEquiv f pf) x y = sectionOfEquiv (cong f) (isEquivCong (f , pf)) pathSplitToEquiv : PathSplitEquiv A B → A ≃ B fst (pathSplitToEquiv (f , _)) = f snd (pathSplitToEquiv (_ , e)) = toIsEquiv _ e equivToPathSplit : A ≃ B → PathSplitEquiv A B fst (equivToPathSplit (f , _)) = f snd (equivToPathSplit (_ , e)) = fromIsEquiv _ e equivHasUniqueSection : (f : A → B) → isEquiv f → ∃![ g ∈ (B → A) ] section f g equivHasUniqueSection f eq = helper' where helper : isContr (fiber (λ (φ : B → A) → f ∘ φ) (idfun B)) helper = (equiv-proof (snd (postCompEquiv (f , eq)))) (idfun B) helper' : ∃![ φ ∈ (B → A) ] ((x : B) → f (φ x) ≡ x) fst helper' = (helper .fst .fst , λ x i → helper .fst .snd i x) snd helper' y i = (fst (η i) , λ b j → snd (η i) j b) where η = helper .snd (fst y , λ i b → snd y b i) {- PathSplitEquiv is a proposition and the type of path split equivs is equivalent to the type of equivalences -} isPropIsPathSplitEquiv : ∀ {ℓ} {A B : Type ℓ} (f : A → B) → isProp (isPathSplitEquiv f) isPropIsPathSplitEquiv {_} {A} {B} f record { sec = sec-φ ; secCong = secCong-φ } record { sec = sec-ψ ; secCong = secCong-ψ } i = record { sec = sectionsAreEqual i ; secCong = λ x y → congSectionsAreEqual x y (secCong-φ x y) (secCong-ψ x y) i } where φ' = record { sec = sec-φ ; secCong = secCong-φ } ψ' = record { sec = sec-ψ ; secCong = secCong-ψ } sectionsAreEqual : sec-φ ≡ sec-ψ sectionsAreEqual = (sym (contraction sec-φ)) ∙ (contraction sec-ψ) where contraction = snd (equivHasUniqueSection f (toIsEquiv f φ')) congSectionsAreEqual : (x y : A) (l u : hasSection (λ (p : x ≡ y) → cong f p)) → l ≡ u congSectionsAreEqual x y l u = (sym (contraction l)) ∙ (contraction u) where contraction = snd (equivHasUniqueSection (λ (p : x ≡ y) → cong f p) (isEquivCong (pathSplitToEquiv (f , φ')))) module _ {ℓ} {A B : Type ℓ} where isEquivIsPathSplitToIsEquiv : (f : A → B) → isEquiv (fromIsEquiv f) isEquivIsPathSplitToIsEquiv f = isoToIsEquiv (iso (fromIsEquiv f) (toIsEquiv f) (λ b → isPropIsPathSplitEquiv f _ _) (λ a → isPropIsEquiv f _ _ )) isEquivPathSplitToEquiv : isEquiv (pathSplitToEquiv {A = A} {B = B}) isEquivPathSplitToEquiv = isoToIsEquiv (iso pathSplitToEquiv equivToPathSplit (λ {(f , e) i → (f , isPropIsEquiv f (toIsEquiv f (fromIsEquiv f e)) e i)}) (λ {(f , e) i → (f , isPropIsPathSplitEquiv f (fromIsEquiv f (toIsEquiv f e)) e i)})) equivPathSplitToEquiv : (PathSplitEquiv A B) ≃ (A ≃ B) equivPathSplitToEquiv = (pathSplitToEquiv , isEquivPathSplitToEquiv) secCongDep : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} {C : A → Type ℓ''} → (f : ∀ a → B a → C a) {a a' : A} (q : a ≡ a') → (∀ a (x y : B a) → hasSection (λ (p : x ≡ y) → cong (f a) p)) → (∀ (x : B a) (y : B a') → hasSection (λ (p : PathP (λ i → B (q i)) x y) → cong₂ f q p)) secCongDep {B = B} f {a} p secCong = J (λ a' q → (x : B a) (y : B a') → hasSection (λ (p : PathP (λ i → B (q i)) x y) → cong₂ f q p)) (secCong a) p
40.58156
112
0.622859
1b05377a3f6d6dbe285aa9616964f13937efaea6
2,992
agda
Agda
examples/outdated-and-incorrect/lattice/SemiLattice.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
examples/outdated-and-incorrect/lattice/SemiLattice.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/lattice/SemiLattice.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module SemiLattice where open import Prelude open import PartialOrder as PO import Chain private module IsSemiLat {A : Set}(po : PartialOrder A)(_⊓_ : A -> A -> A) where private open module PO = PartialOrder po record IsSemiLattice : Set where field ⊓-lbL : forall {x y} -> (x ⊓ y) ≤ x ⊓-lbR : forall {x y} -> (x ⊓ y) ≤ y ⊓-glb : forall {x y z} -> z ≤ x -> z ≤ y -> z ≤ (x ⊓ y) open IsSemiLat public record SemiLattice (A : Set) : Set1 where field po : PartialOrder A _⊓_ : A -> A -> A prf : IsSemiLattice po _⊓_ module SemiLat {A : Set}(L : SemiLattice A) where private module SL = SemiLattice L private module SLPO = POrder SL.po private module IsSL = IsSemiLattice SL.po SL._⊓_ SL.prf open SLPO public open SL public hiding (prf) open IsSL public private open module C≤ = Chain _≤_ (\x -> ≤-refl) (\x y z -> ≤-trans) renaming (_===_ to _-≤-_; chain>_ to trans>_) ⊓-commute : forall {x y} -> (x ⊓ y) == (y ⊓ x) ⊓-commute = ≤-antisym lem lem where lem : forall {x y} -> (x ⊓ y) ≤ (y ⊓ x) lem = ⊓-glb ⊓-lbR ⊓-lbL ⊓-assoc : forall {x y z} -> (x ⊓ (y ⊓ z)) == ((x ⊓ y) ⊓ z) ⊓-assoc = ≤-antisym lem₁ lem₂ where lem₁ : forall {x y z} -> (x ⊓ (y ⊓ z)) ≤ ((x ⊓ y) ⊓ z) lem₁ = ⊓-glb (⊓-glb ⊓-lbL (≤-trans ⊓-lbR ⊓-lbL)) (≤-trans ⊓-lbR ⊓-lbR) lem₂ : forall {x y z} -> ((x ⊓ y) ⊓ z) ≤ (x ⊓ (y ⊓ z)) lem₂ = ⊓-glb (≤-trans ⊓-lbL ⊓-lbL) (⊓-glb (≤-trans ⊓-lbL ⊓-lbR) ⊓-lbR) ⊓-idem : forall {x} -> (x ⊓ x) == x ⊓-idem = ≤-antisym ⊓-lbL (⊓-glb ≤-refl ≤-refl) ≤⊓-L : forall {x y} -> (x ≤ y) ⇐⇒ ((x ⊓ y) == x) ≤⊓-L = (fwd , bwd) where fwd = \x≤y -> ≤-antisym ⊓-lbL (⊓-glb ≤-refl x≤y) bwd = \x⊓y=x -> ≤-trans (==≤-R x⊓y=x) ⊓-lbR ≤⊓-R : forall {x y} -> (y ≤ x) ⇐⇒ ((x ⊓ y) == y) ≤⊓-R {x}{y} = (fwd , bwd) where lem : (y ≤ x) ⇐⇒ ((y ⊓ x) == y) lem = ≤⊓-L fwd = \y≤x -> ==-trans ⊓-commute (fst lem y≤x) bwd = \x⊓y=y -> snd lem (==-trans ⊓-commute x⊓y=y) ⊓-monotone-R : forall {a} -> Monotone (\x -> a ⊓ x) ⊓-monotone-R x≤y = ⊓-glb ⊓-lbL (≤-trans ⊓-lbR x≤y) ⊓-monotone-L : forall {a} -> Monotone (\x -> x ⊓ a) ⊓-monotone-L {a}{x}{y} x≤y = trans> x ⊓ a -≤- a ⊓ x by ==≤-L ⊓-commute -≤- a ⊓ y by ⊓-monotone-R x≤y -≤- y ⊓ a by ==≤-L ⊓-commute ≤⊓-compat : forall {w x y z} -> w ≤ y -> x ≤ z -> (w ⊓ x) ≤ (y ⊓ z) ≤⊓-compat {w}{x}{y}{z} w≤y x≤z = trans> w ⊓ x -≤- w ⊓ z by ⊓-monotone-R x≤z -≤- y ⊓ z by ⊓-monotone-L w≤y ⊓-cong : forall {w x y z} -> w == y -> x == z -> (w ⊓ x) == (y ⊓ z) ⊓-cong wy xz = ≤-antisym (≤⊓-compat (==≤-L wy) (==≤-L xz)) (≤⊓-compat (==≤-R wy) (==≤-R xz)) ⊓-cong-L : forall {x y z} -> x == y -> (x ⊓ z) == (y ⊓ z) ⊓-cong-L xy = ⊓-cong xy ==-refl ⊓-cong-R : forall {x y z} -> x == y -> (z ⊓ x) == (z ⊓ y) ⊓-cong-R xy = ⊓-cong ==-refl xy
29.92
71
0.45254
c7d858851eb672939265e4244a9b1b5a61147ea6
406
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Lex/Strict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Lex/Strict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Lex/Strict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Lex.Strict directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Lex.Strict where open import Data.List.Relation.Binary.Lex.Strict public
31.230769
72
0.477833
199066435e481109ae3c061a1ec8325251fe7956
2,088
agda
Agda
src/MLib/Matrix/SemiTensor/Core.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
src/MLib/Matrix/SemiTensor/Core.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
src/MLib/Matrix/SemiTensor/Core.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
open import MLib.Algebra.PropertyCode open import MLib.Algebra.PropertyCode.Structures module MLib.Matrix.SemiTensor.Core {c ℓ} (struct : Struct bimonoidCode c ℓ) where open import MLib.Prelude open import MLib.Matrix.Core open import MLib.Matrix.Equality struct open import MLib.Matrix.Mul struct open import MLib.Matrix.Tensor struct open import MLib.Algebra.Operations struct open Nat using () renaming (_+_ to _+ℕ_; _*_ to _*ℕ_) open import MLib.Fin.Parts.Simple open import Data.Nat.LCM open import Data.Nat.Divisibility chunkVec : ∀ {m n} → Table S (m *ℕ n) → Table (Table S n) m chunkVec {m} {n} t .lookup i .lookup j = lookup t (fromParts (i , j)) -- Case 1 of semi-tensor inner product of vectors _⋉ᵥ₁_ : ∀ {n t} → Table S (t *ℕ n) → Table S t → Table S n (_⋉ᵥ₁_ {n} {t} X Y) .lookup i = ∑[ k < t ] (X′ .lookup k .lookup i *′ Y .lookup k) where X′ = chunkVec {t} X -- Case 2 of semi-tensor inner product of vector _⋉ᵥ₂_ : ∀ {n s} → Table S s → Table S (s *ℕ n) → Table S n (_⋉ᵥ₂_ {n} {s} X Y) .lookup i = ∑[ k < s ] (X .lookup k *′ Y′ .lookup k .lookup i) where Y′ = chunkVec {s} Y module Defn {n p t : ℕ} (lcm : LCM n p t) where -- Left semi-Tensor product n∣t = LCM.commonMultiple lcm .proj₁ p∣t = LCM.commonMultiple lcm .proj₂ t/n = quotient n∣t t/p = quotient p∣t Iₜₙ = 1● {t/n} Iₜₚ = 1● {t/p} module _ where open ≡.Reasoning abstract lem₁ : n *ℕ t/n ≡ t lem₁ = begin n *ℕ t/n ≡⟨ Nat.*-comm n _ ⟩ t/n *ℕ n ≡⟨ ≡.sym (_∣_.equality n∣t) ⟩ t ∎ lem₂ : p *ℕ t/p ≡ t lem₂ = begin p *ℕ t/p ≡⟨ Nat.*-comm p _ ⟩ t/p *ℕ p ≡⟨ ≡.sym (_∣_.equality p∣t) ⟩ t ∎ module _ {m q} (A : Matrix S m n) (B : Matrix S p q) where A′ = A ⊠ Iₜₙ B′ = B ⊠ Iₜₚ A′′ = ≡.subst (Matrix S (m *ℕ t/n)) {y = t} lem₁ A′ B′′ = ≡.subst (λ h → Matrix S h (q *ℕ t/p)) {y = t} lem₂ B′ stp : Matrix S (m *ℕ t/n) (q *ℕ t/p) stp = A′′ ⊗ B′′ infixl 7 _⋉_ _⋉_ : ∀ {m n p q} → Matrix S m n → Matrix S p q → Matrix S _ _ _⋉_ {m} {n} {p} {q} = Defn.stp {n} {p} (lcm n p .proj₂)
27.116883
82
0.577586
d1bf45276266f2787c5fb923a3196931852ce7e8
1,321
agda
Agda
src/Human/Float.agda
MaisaMilena/JuiceMaker
b509eb4c4014605facfb4ee5c807cd07753d4477
[ "MIT" ]
6
2019-03-29T17:35:20.000Z
2020-11-28T05:46:27.000Z
src/Human/Float.agda
MaisaMilena/AgdaCalculator
e977a5f2a005682cee123568b49462dd7d7b11ad
[ "MIT" ]
null
null
null
src/Human/Float.agda
MaisaMilena/AgdaCalculator
e977a5f2a005682cee123568b49462dd7d7b11ad
[ "MIT" ]
null
null
null
module Human.Float where open import Human.Bool open import Human.Nat open import Human.Int open import Human.String postulate Float : Set {-# BUILTIN FLOAT Float #-} primitive primFloatEquality : Float → Float → Bool primFloatLess : Float → Float → Bool primFloatNumericalEquality : Float → Float → Bool primFloatNumericalLess : Float → Float → Bool primNatToFloat : Nat → Float primFloatPlus : Float → Float → Float primFloatMinus : Float → Float → Float primFloatTimes : Float → Float → Float primFloatNegate : Float → Float primFloatDiv : Float → Float → Float primFloatSqrt : Float → Float primRound : Float → Int primFloor : Float → Int primCeiling : Float → Int primExp : Float → Float primLog : Float → Float primSin : Float → Float primCos : Float → Float primTan : Float → Float primASin : Float → Float primACos : Float → Float primATan : Float → Float primATan2 : Float → Float → Float primShowFloat : Float → String
36.694444
52
0.527631
5e950782b61c16c9e808e83f1c6e1a51f321c63a
1,099
agda
Agda
proglangs-learning/Agda/sv20/assign2/Second_old.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
proglangs-learning/Agda/sv20/assign2/Second_old.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
4
2020-03-10T19:20:21.000Z
2021-06-07T15:39:48.000Z
proglangs-learning/Agda/sv20/assign2/Second_old.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
{-# OPTIONS --cubical #-} --open import Data.Nat using (ℕ; zero; suc; _+_) open import Cubical.Data.Nat using (ℕ; zero; suc; _+_) open import Cubical.Foundations.Prelude using (refl; _≡_; subst; cong; transport; transp; ℓ-zero; ℓ-suc) -- hiding (_≡⟨_⟩_) open import Cubical.Foundations.Function using (_∘_) data Captured {a} (A : Set a) : Set a where cap : A → Captured A Id : ∀ {a} {A} → Captured A → Set a Id {_} {A} (cap _) = A id : ∀ {a} {A} → (n : Captured A) → Id {a} n id (cap n) = n data ⟨Set⟩ {a} (A : Set a) : Set a where empty : ⟨Set⟩ A insert : A → ⟨Set⟩ A → ⟨Set⟩ A dup : ∀ a sa → insert a (insert a sa) ≡ insert a sa com : ∀ a b sa → insert a (insert b sa) ≡ insert b (insert a sa) rem-dup () --_in_ : A → ⟨Set⟩ A → --insert 3 (insert 3 empty) --transport (dup 3 empty)) --transport (dup {ℓ-zero} 3 empty) --insert 3 (insert 3 empty) --subst {A = insert 3 (insert 3 empty)} (dup 3 empty) --transport {ℓ-zero} {ℕ} refl --cong cap (dup 3 empty) --transport (cong (Id ∘ cap) (dup 3 empty)) (id (cap (insert 3 (insert 3 empty)))) --id (cap (insert 3 (insert 3 empty)))
29.702703
123
0.601456
fdc609563a0452c919bd941b47b1f88673b67f5b
331
agda
Agda
Cubical/Data/Empty/Properties.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Data/Empty/Properties.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Data/Empty/Properties.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Empty.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Data.Empty.Base isProp⊥ : isProp ⊥ isProp⊥ () isContr⊥→A : ∀ {ℓ} {A : Type ℓ} → isContr (⊥ → A) fst isContr⊥→A () snd isContr⊥→A f i ()
20.6875
50
0.691843
fdc79ec0cfa2c76d0bcdde36e7941263d928e762
6,886
agda
Agda
src/Categories/Diagram/Duality.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Diagram/Duality.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Diagram/Duality.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Diagram.Duality {o ℓ e} (C : Category o ℓ e) where open Category C open import Level open import Function using (_$_) open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Categories.Functor open import Categories.Functor.Bifunctor open import Categories.NaturalTransformation.Dinatural open import Categories.Object.Initial open import Categories.Object.Terminal open import Categories.Object.Duality open import Categories.Diagram.Equalizer op open import Categories.Diagram.Coequalizer C open import Categories.Diagram.Pullback op open import Categories.Diagram.Pushout C open import Categories.Diagram.Cone as Cone open import Categories.Diagram.Cocone as Cocone open import Categories.Diagram.End as End open import Categories.Diagram.Coend as Coend open import Categories.Diagram.Cowedge as Cowedge open import Categories.Diagram.Limit as Limit open import Categories.Diagram.Colimit as Colimit open import Categories.Diagram.Wedge as Wedge open import Categories.Category.Construction.Cocones using (Cocones) private variable o′ ℓ′ e′ : Level D J : Category o′ ℓ′ e′ A B : Obj f g : A ⇒ B -- note that what would be called -- terminal⇒coInitial and initial⇒coTerminal are in -- Categories.Object.Duality Coequalizer⇒coEqualizer : Coequalizer f g → Equalizer f g Coequalizer⇒coEqualizer coe = record { arr = arr ; isEqualizer = record { equality = equality ; equalize = coequalize ; universal = universal ; unique = unique } } where open Coequalizer coe coEqualizer⇒Coequalizer : Equalizer f g → Coequalizer f g coEqualizer⇒Coequalizer e = record { arr = arr ; isCoequalizer = record { equality = equality ; coequalize = equalize ; universal = universal ; unique = unique } } where open Equalizer e coPullback⇒Pushout : Pullback f g → Pushout f g coPullback⇒Pushout p = record { i₁ = p₁ ; i₂ = p₂ ; commute = commute ; universal = universal ; unique = unique ; universal∘i₁≈h₁ = p₁∘universal≈h₁ ; universal∘i₂≈h₂ = p₂∘universal≈h₂ } where open Pullback p Pushout⇒coPullback : Pushout f g → Pullback f g Pushout⇒coPullback p = record { p₁ = i₁ ; p₂ = i₂ ; isPullback = record { commute = commute ; universal = universal ; unique = unique ; p₁∘universal≈h₁ = universal∘i₁≈h₁ ; p₂∘universal≈h₂ = universal∘i₂≈h₂ } } where open Pushout p module _ {F : Functor J C} where open Functor F renaming (op to Fop) coApex⇒Coapex : ∀ X → Apex Fop X → Coapex F X coApex⇒Coapex X apex = record { ψ = ψ ; commute = commute } where open Cone.Apex apex coCone⇒Cocone : Cone Fop → Cocone F coCone⇒Cocone c = record { coapex = coApex⇒Coapex _ apex } where open Cone.Cone c Coapex⇒coApex : ∀ X → Coapex F X → Apex Fop X Coapex⇒coApex X coapex = record { ψ = ψ ; commute = commute } where open Cocone.Coapex coapex Cocone⇒coCone : Cocone F → Cone Fop Cocone⇒coCone c = record { apex = Coapex⇒coApex _ coapex } where open Cocone.Cocone c coCone⇒⇒Cocone⇒ : ∀ {K K′} → Cone⇒ Fop K K′ → Cocone⇒ F (coCone⇒Cocone K′) (coCone⇒Cocone K) coCone⇒⇒Cocone⇒ f = record { arr = arr ; commute = commute } where open Cone⇒ f Cocone⇒⇒coCone⇒ : ∀ {K K′} → Cocone⇒ F K K′ → Cone⇒ Fop (Cocone⇒coCone K′) (Cocone⇒coCone K) Cocone⇒⇒coCone⇒ f = record { arr = arr ; commute = commute } where open Cocone⇒ f coLimit⇒Colimit : Limit Fop → Colimit F coLimit⇒Colimit lim = record { initial = op⊤⇒⊥ (Cocones F) $ record { ⊤ = coCone⇒Cocone ⊤ ; ⊤-is-terminal = record { ! = coCone⇒⇒Cocone⇒ ! ; !-unique = λ f → !-unique (Cocone⇒⇒coCone⇒ f) } } } where open Limit.Limit lim open Terminal terminal Colimit⇒coLimit : Colimit F → Limit Fop Colimit⇒coLimit colim = record { terminal = record { ⊤ = Cocone⇒coCone ⊥ ; ⊤-is-terminal = record { ! = Cocone⇒⇒coCone⇒ ! ; !-unique = λ f → !-unique (coCone⇒⇒Cocone⇒ f) } } } where open Colimit.Colimit colim open Initial initial module _ {F : Bifunctor (Category.op D) D C} where open HomReasoning open Functor F renaming (op to Fop) coWedge⇒Cowedge : Wedge Fop → Cowedge F coWedge⇒Cowedge W = record { E = E ; dinatural = DinaturalTransformation.op dinatural } where open Wedge.Wedge W Cowedge⇒coWedge : Cowedge F → Wedge Fop Cowedge⇒coWedge W = record { E = E ; dinatural = DinaturalTransformation.op dinatural } where open Cowedge.Cowedge W coEnd⇒Coend : End Fop → Coend F coEnd⇒Coend e = record { cowedge = coWedge⇒Cowedge wedge ; factor = λ W → factor (Cowedge⇒coWedge W) ; universal = universal ; unique = unique } where open End.End e Coend⇒coEnd : Coend F → End Fop Coend⇒coEnd e = record { wedge = Cowedge⇒coWedge cowedge ; factor = λ W → factor (coWedge⇒Cowedge W) ; universal = universal ; unique = unique } where open Coend.Coend e module DiagramDualityConversionProperties where private Coequalizer⇔coEqualizer : ∀ (coequalizer : Coequalizer f g) → coEqualizer⇒Coequalizer (Coequalizer⇒coEqualizer coequalizer) ≡ coequalizer Coequalizer⇔coEqualizer _ = refl coPullback⇔Pushout : ∀ (coPullback : Pullback f g) → Pushout⇒coPullback (coPullback⇒Pushout coPullback) ≡ coPullback coPullback⇔Pushout _ = refl module _ {F : Functor J C} where open Functor F renaming (op to Fop) coApex⇔Coapex : ∀ X → (coApex : Apex Fop X) → Coapex⇒coApex X (coApex⇒Coapex X coApex) ≡ coApex coApex⇔Coapex _ _ = refl coCone⇔Cocone : ∀ (coCone : Cone Fop) → Cocone⇒coCone (coCone⇒Cocone coCone) ≡ coCone coCone⇔Cocone _ = refl coCone⇒⇔Cocone⇒ : ∀ {K K′} → (coCone⇒ : Cone⇒ Fop K K′) → Cocone⇒⇒coCone⇒ (coCone⇒⇒Cocone⇒ coCone⇒) ≡ coCone⇒ coCone⇒⇔Cocone⇒ _ = refl coLimit⇔Colimit : ∀ (coLimit : Limit Fop) → Colimit⇒coLimit (coLimit⇒Colimit coLimit) ≡ coLimit coLimit⇔Colimit _ = refl module _ {F : Bifunctor (Category.op D) D C} where open Functor F renaming (op to Fop) coWedge⇔Cowedge : ∀ (coWedge : Wedge Fop) → Cowedge⇒coWedge (coWedge⇒Cowedge coWedge) ≡ coWedge coWedge⇔Cowedge _ = refl coEnd⇔Coend : ∀ (coEnd : End Fop) → Coend⇒coEnd (coEnd⇒Coend coEnd) ≡ coEnd coEnd⇔Coend _ = refl
28.221311
94
0.628376
35628935d383ea19a87a9dabba496d144b554fe4
472
agda
Agda
test/Succeed/TacticModality.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/TacticModality.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/TacticModality.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.Reflection open import Agda.Builtin.Unit open import Agda.Builtin.Nat open import Agda.Builtin.Equality variable A : Set super-tac : Term → TC ⊤ super-tac hole = unify hole (lit (nat 101)) solver : Nat → Term → TC ⊤ solver n hole = unify hole (lit (nat (n + 1))) foo : {@(tactic super-tac) n : Nat} {@(tactic solver n) x : A} → A foo {n = n} {x = x} = x number : Nat number = foo check : number ≡ 102 check = refl
17.481481
46
0.648305
5283e54464aaa79d0fd12821d9cc1636ba986eca
10,482
agda
Agda
proofs/AKS/Polynomial/Base.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
1
2020-12-01T22:38:27.000Z
2020-12-01T22:38:27.000Z
proofs/AKS/Polynomial/Base.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
null
null
null
proofs/AKS/Polynomial/Base.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
null
null
null
open import Level using () renaming (_⊔_ to _⊔ˡ_) open import Data.Product using (_,_; proj₁) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Relation.Nullary using (yes; no; ¬_) open import Relation.Nullary.Negation using (contradiction) open import Relation.Binary using (Reflexive; Symmetric; Transitive; Setoid; Tri) open Tri open import Relation.Binary.PropositionalEquality using (_≡_; _≢_) renaming (refl to ≡-refl; sym to ≡-sym) open import Algebra.Bundles using (RawRing) open import AKS.Algebra.Bundles using (DecField) module AKS.Polynomial.Base {c ℓ} (F : DecField c ℓ) where open import Data.Unit using (⊤; tt) open import Agda.Builtin.FromNat using (Number) open import AKS.Nat using (ℕ; _∸_; _≤_; _<_; lte; pred) renaming (_+_ to _+ℕ_; _⊔_ to _⊔ℕ_) open ℕ open import AKS.Nat using (≢⇒¬≟; <-cmp; ≤-totalOrder; m<n⇒n∸m≢0) open import AKS.Nat using (ℕ⁺; ⟅_⇓⟆; ⟅_⇑⟆) open import AKS.Nat.WellFounded using (Acc; acc; <-well-founded) open DecField F using (0#; 1#; _+_; _*_; -_; _-_; _⁻¹; _/_; C/0) renaming (Carrier to C) open DecField F using (_≈_; _≈?_; setoid) open Setoid setoid using (refl; sym; trans) open DecField F using (*-commutativeMonoid; 1#-nonzero; -1#-nonzero; _*-nonzero_; _/-nonzero_) open import AKS.Exponentiation *-commutativeMonoid using (_^_; _^⁺_) data Spine : Set (c ⊔ˡ ℓ) where K : C/0 → Spine _+x^_∙_ : C/0 → ℕ⁺ → Spine → Spine data Polynomial : Set (c ⊔ˡ ℓ) where 0ᵖ : Polynomial x^_∙_ : ℕ → Spine → Polynomial ⟦_⟧ˢ : Spine → C → C ⟦ K c ⟧ˢ x = proj₁ c ⟦ c +x^ n ∙ p ⟧ˢ x = proj₁ c + x ^⁺ n * ⟦ p ⟧ˢ x ⟦_⟧ : Polynomial → C → C ⟦ 0ᵖ ⟧ x = 0# ⟦ x^ n ∙ p ⟧ x = x ^ n * ⟦ p ⟧ˢ x 1ᵖ : Polynomial 1ᵖ = x^ 0 ∙ K 1#-nonzero _+?_ : ∀ (k₁ k₂ : C/0) → (proj₁ k₁ + proj₁ k₂ ≈ 0#) ⊎ C/0 k₁ +? k₂ with proj₁ k₁ + proj₁ k₂ ≈? 0# ... | yes k₁+k₂≈0 = inj₁ k₁+k₂≈0 ... | no k₁+k₂≉0 = inj₂ (proj₁ k₁ + proj₁ k₂ , k₁+k₂≉0) +ᵖ-spine-≡-K : ℕ → C/0 → Spine → Polynomial +ᵖ-spine-≡-K n c₁ (K c₂) with c₁ +? c₂ ... | inj₁ _ = 0ᵖ ... | inj₂ c₁+c₂ = x^ n ∙ K c₁+c₂ +ᵖ-spine-≡-K n c₁ (c₂ +x^ i₂ ∙ q) with c₁ +? c₂ ... | inj₁ _ = x^ (n +ℕ ⟅ i₂ ⇓⟆) ∙ q ... | inj₂ c₁+c₂ = x^ n ∙ (c₁+c₂ +x^ i₂ ∙ q) +ᵖ-spine-≡ : ℕ → Spine → Spine → Polynomial +ᵖ-spine-< : (n : ℕ) → Spine → (m : ℕ) → Spine → n < m → Polynomial +ᵖ-spine : ℕ → Spine → ℕ → Spine → Polynomial +ᵖ-spine-≡ n (K c₁) q = +ᵖ-spine-≡-K n c₁ q +ᵖ-spine-≡ n (c₁ +x^ i₁ ∙ p) (K c₂) = +ᵖ-spine-≡-K n c₂ (c₁ +x^ i₁ ∙ p) +ᵖ-spine-≡ n (c₁ +x^ i₁ ∙ p) (c₂ +x^ i₂ ∙ q) with c₁ +? c₂ ... | inj₁ _ = +ᵖ-spine (n +ℕ ⟅ i₁ ⇓⟆) p (n +ℕ ⟅ i₂ ⇓⟆) q ... | inj₂ c₁+c₂ with +ᵖ-spine ⟅ i₁ ⇓⟆ p ⟅ i₂ ⇓⟆ q ... | 0ᵖ = x^ n ∙ K c₁+c₂ ... | x^ zero ∙ r = +ᵖ-spine-≡-K n c₁+c₂ r ... | x^ suc n₃ ∙ r = x^ n ∙ (c₁+c₂ +x^ ⟅ suc n₃ ⇑⟆ ∙ r) +ᵖ-spine-< n₁ (K c₁) n₂ q n₁<n₂ = x^ n₁ ∙ (c₁ +x^ ⟅ n₂ ∸ n₁ ⇑⟆ {≢⇒¬≟ (m<n⇒n∸m≢0 n₁<n₂)} ∙ q) +ᵖ-spine-< n₁ (c₁ +x^ i₁ ∙ p) n₂ q n₁<n₂ with +ᵖ-spine ⟅ i₁ ⇓⟆ p (n₂ ∸ n₁) q ... | 0ᵖ = x^ n₁ ∙ K c₁ ... | x^ zero ∙ r = +ᵖ-spine-≡-K n₁ c₁ r ... | x^ suc n₃ ∙ r = x^ n₁ ∙ (c₁ +x^ ⟅ suc n₃ ⇑⟆ ∙ r) +ᵖ-spine n₁ p n₂ q with <-cmp n₁ n₂ ... | tri< n₁<n₂ _ _ = +ᵖ-spine-< n₁ p n₂ q n₁<n₂ ... | tri≈ _ n₁≡n₂ _ = +ᵖ-spine-≡ n₁ p q ... | tri> _ _ n₁>n₂ = +ᵖ-spine-< n₂ q n₁ p n₁>n₂ infixl 6 _+ᵖ_ _+ᵖ_ : Polynomial → Polynomial → Polynomial 0ᵖ +ᵖ q = q (x^ n₁ ∙ p) +ᵖ 0ᵖ = x^ n₁ ∙ p (x^ n₁ ∙ p) +ᵖ (x^ n₂ ∙ q) = +ᵖ-spine n₁ p n₂ q _∙𝑋^_ : C/0 → ℕ → Polynomial c ∙𝑋^ n = x^ n ∙ K c 𝑋^_ : ℕ → Polynomial 𝑋^ n = 1#-nonzero ∙𝑋^ n 𝑋 : Polynomial 𝑋 = 𝑋^ 1 𝐾 : C → Polynomial 𝐾 c with c ≈? 0# ... | yes _ = 0ᵖ ... | no c≉0 = (c , c≉0) ∙𝑋^ 0 ∙ᵖ-spine : C/0 → Spine → Spine ∙ᵖ-spine c₁ (K c₂) = K (c₁ *-nonzero c₂) ∙ᵖ-spine c₁ (c₂ +x^ n ∙ p) = (c₁ *-nonzero c₂) +x^ n ∙ (∙ᵖ-spine c₁ p) infixl 7 _∙ᵖ_ _∙ᵖ_ : C/0 → Polynomial → Polynomial c ∙ᵖ 0ᵖ = 0ᵖ c ∙ᵖ (x^ n ∙ p) = x^ n ∙ (∙ᵖ-spine c p) *ᵖ-spine : ℕ → Spine → ℕ → Spine → Polynomial *ᵖ-spine o₁ (K c₁) o₂ q = x^ (o₁ +ℕ o₂) ∙ (∙ᵖ-spine c₁ q) *ᵖ-spine o₁ (c₁ +x^ n₁ ∙ p) o₂ (K c₂) = x^ (o₁ +ℕ o₂) ∙ (∙ᵖ-spine c₂ (c₁ +x^ n₁ ∙ p)) *ᵖ-spine o₁ (c₁ +x^ n₁ ∙ p) o₂ (c₂ +x^ n₂ ∙ q) = x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ (x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p) +ᵖ *ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q -- (c₁ + x ^ n₁ * p[x]) * (c₂ + x ^ n₂ * q[x]) = (c₁ * c₂) + (c₁ * x ^ n₂ * q[x]) + (x ^ n₁ * p[x] * c₂) + (x ^ n₁ * p[x] * x ^ n₂ * q[x]) infixl 7 _*ᵖ_ _*ᵖ_ : Polynomial → Polynomial → Polynomial 0ᵖ *ᵖ q = 0ᵖ (x^ n₁ ∙ p) *ᵖ 0ᵖ = 0ᵖ (x^ n₁ ∙ p) *ᵖ (x^ n₂ ∙ q) = *ᵖ-spine n₁ p n₂ q infix 6 -ᵖ_ -ᵖ_ : Polynomial → Polynomial -ᵖ p = -1#-nonzero ∙ᵖ p infixl 6 _-ᵖ_ _-ᵖ_ : Polynomial → Polynomial → Polynomial p -ᵖ q = p +ᵖ (-ᵖ q) data Polynomialⁱ : Set c where 0ⁱ : Polynomialⁱ _+x∙_ : C → Polynomialⁱ → Polynomialⁱ 1ⁱ : Polynomialⁱ 1ⁱ = 1# +x∙ 0ⁱ infixl 6 _+ⁱ_ _+ⁱ_ : Polynomialⁱ → Polynomialⁱ → Polynomialⁱ 0ⁱ +ⁱ q = q (c₁ +x∙ p) +ⁱ 0ⁱ = c₁ +x∙ p (c₁ +x∙ p) +ⁱ (c₂ +x∙ q) = (c₁ + c₂) +x∙ (p +ⁱ q) infixl 7 _∙ⁱ_ _∙ⁱ_ : C → Polynomialⁱ → Polynomialⁱ a ∙ⁱ 0ⁱ = 0ⁱ a ∙ⁱ (c +x∙ p) = (a * c) +x∙ (a ∙ⁱ p) infix 8 x∙_ x∙_ : Polynomialⁱ → Polynomialⁱ x∙ p = 0# +x∙ p infixl 7 _*ⁱ_ _*ⁱ_ : Polynomialⁱ → Polynomialⁱ → Polynomialⁱ 0ⁱ *ⁱ q = 0ⁱ (c₁ +x∙ p) *ⁱ 0ⁱ = 0ⁱ (c₁ +x∙ p) *ⁱ (c₂ +x∙ q) = (c₁ * c₂) +x∙ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) -ⁱ_ : Polynomialⁱ → Polynomialⁱ -ⁱ p = (- 1#) ∙ⁱ p infixl 6 _-ⁱ_ _-ⁱ_ : Polynomialⁱ → Polynomialⁱ → Polynomialⁱ p -ⁱ q = p +ⁱ (-ⁱ q) expandˢ : ℕ → Spine → Polynomialⁱ expandˢ zero (K c) = proj₁ c +x∙ 0ⁱ expandˢ zero (c +x^ n ∙ s) = proj₁ c +x∙ expandˢ (pred ⟅ n ⇓⟆) s expandˢ (suc n) s = 0# +x∙ expandˢ n s expand : Polynomial → Polynomialⁱ expand 0ᵖ = 0ⁱ expand (x^ n ∙ p) = expandˢ n p constant : C → Polynomial constant c with c ≈? 0# ... | yes _ = 0ᵖ ... | no c≉0 = (c , c≉0) ∙𝑋^ 0 simplify : Polynomialⁱ → Polynomial simplify 0ⁱ = 0ᵖ simplify (c₁ +x∙ p) with c₁ ≈? 0# | simplify p ... | yes _ | 0ᵖ = 0ᵖ ... | yes _ | x^ n ∙ q = x^ suc n ∙ q ... | no c₁≉0 | 0ᵖ = x^ 0 ∙ (K (c₁ , c₁≉0)) ... | no c₁≉0 | x^ n ∙ q = x^ 0 ∙ ((c₁ , c₁≉0) +x^ ⟅ suc n ⇑⟆ ∙ q) data _≈ˢ_ : Spine → Spine → Set (c ⊔ˡ ℓ) where K≈ : ∀ {c₁ c₂} → proj₁ c₁ ≈ proj₁ c₂ → K c₁ ≈ˢ K c₂ +≈ : ∀ {c₁ c₂} {n₁ n₂} {p q} → proj₁ c₁ ≈ proj₁ c₂ → n₁ ≡ n₂ → p ≈ˢ q → (c₁ +x^ n₁ ∙ p) ≈ˢ (c₂ +x^ n₂ ∙ q) infix 4 _≈ᵖ_ data _≈ᵖ_ : Polynomial → Polynomial → Set (c ⊔ˡ ℓ) where 0ᵖ≈ : 0ᵖ ≈ᵖ 0ᵖ 0ᵖ≉ : ∀ {o₁ o₂} {p q} → o₁ ≡ o₂ → p ≈ˢ q → x^ o₁ ∙ p ≈ᵖ x^ o₂ ∙ q infix 4 _≉ᵖ_ _≉ᵖ_ : Polynomial → Polynomial → Set (c ⊔ˡ ℓ) p ≉ᵖ q = ¬ (p ≈ᵖ q) ≈ᵖ-refl : Reflexive _≈ᵖ_ ≈ᵖ-refl {0ᵖ} = 0ᵖ≈ ≈ᵖ-refl {x^ n ∙ p} = 0ᵖ≉ ≡-refl ≈ˢ-refl where ≈ˢ-refl : Reflexive _≈ˢ_ ≈ˢ-refl {K c} = K≈ refl ≈ˢ-refl {c +x^ n ∙ p} = +≈ refl ≡-refl ≈ˢ-refl ≈ᵖ-sym : Symmetric _≈ᵖ_ ≈ᵖ-sym {0ᵖ} {0ᵖ} 0ᵖ≈ = 0ᵖ≈ ≈ᵖ-sym {x^ n ∙ p} {x^ n ∙ q} (0ᵖ≉ ≡-refl p≈ˢq) = 0ᵖ≉ ≡-refl (≈ˢ-sym p≈ˢq) where ≈ˢ-sym : Symmetric _≈ˢ_ ≈ˢ-sym {K c₁} {K c₂} (K≈ c₁≈c₂) = K≈ (sym c₁≈c₂) ≈ˢ-sym {c₁ +x^ n ∙ p} {c₂ +x^ n ∙ q} (+≈ c₁≈c₂ ≡-refl p≈ˢq) = +≈ (sym c₁≈c₂) ≡-refl (≈ˢ-sym p≈ˢq) ≈ᵖ-trans : Transitive _≈ᵖ_ ≈ᵖ-trans {0ᵖ} {0ᵖ} {0ᵖ} 0ᵖ≈ 0ᵖ≈ = 0ᵖ≈ ≈ᵖ-trans {_} {_} {_} (0ᵖ≉ ≡-refl p≈ˢq) (0ᵖ≉ ≡-refl q≈ˢr) = 0ᵖ≉ ≡-refl (≈ˢ-trans p≈ˢq q≈ˢr) where ≈ˢ-trans : Transitive _≈ˢ_ ≈ˢ-trans (K≈ c₁≈c₂) (K≈ c₂≈c₃) = K≈ (trans c₁≈c₂ c₂≈c₃) ≈ˢ-trans (+≈ c₁≈c₂ ≡-refl p≈ˢq) (+≈ c₂≈c₃ ≡-refl q≈ˢr) = +≈ (trans c₁≈c₂ c₂≈c₃) ≡-refl (≈ˢ-trans p≈ˢq q≈ˢr) infix 4 _≈ⁱ_ data _≈ⁱ_ : Polynomialⁱ → Polynomialⁱ → Set (c ⊔ˡ ℓ) where 0≈0 : 0ⁱ ≈ⁱ 0ⁱ 0≈+ : ∀ {c} {p} → c ≈ 0# → 0ⁱ ≈ⁱ p → 0ⁱ ≈ⁱ c +x∙ p +≈0 : ∀ {c} {p} → c ≈ 0# → 0ⁱ ≈ⁱ p → c +x∙ p ≈ⁱ 0ⁱ +≈+ : ∀ {c₁ c₂} {p q} → c₁ ≈ c₂ → p ≈ⁱ q → c₁ +x∙ p ≈ⁱ c₂ +x∙ q infix 4 _≉ⁱ_ _≉ⁱ_ : Polynomialⁱ → Polynomialⁱ → Set (c ⊔ˡ ℓ) p ≉ⁱ q = ¬ (p ≈ⁱ q) ≈ⁱ-refl : Reflexive _≈ⁱ_ ≈ⁱ-refl {0ⁱ} = 0≈0 ≈ⁱ-refl {c +x∙ p} = +≈+ refl ≈ⁱ-refl ≈ⁱ-sym : Symmetric _≈ⁱ_ ≈ⁱ-sym 0≈0 = 0≈0 ≈ⁱ-sym (0≈+ c≈0 0≈p) = +≈0 c≈0 0≈p ≈ⁱ-sym (+≈0 c≈0 0≈p) = 0≈+ c≈0 0≈p ≈ⁱ-sym (+≈+ c₁≈c₂ p≈q) = +≈+ (sym c₁≈c₂) (≈ⁱ-sym p≈q) ≈ⁱ-trans : Transitive _≈ⁱ_ ≈ⁱ-trans 0≈0 q = q ≈ⁱ-trans (0≈+ c₁≈0 0≈p) (+≈0 c₂≈0 0≈q) = 0≈0 ≈ⁱ-trans (0≈+ c₁≈0 0≈p) (+≈+ c₁≈c₂ p≈q) = 0≈+ (trans (sym c₁≈c₂) c₁≈0) (≈ⁱ-trans 0≈p p≈q) ≈ⁱ-trans (+≈0 c₁≈0 0≈p) 0≈0 = +≈0 c₁≈0 0≈p ≈ⁱ-trans (+≈0 c₁≈0 0≈p) (0≈+ c₂≈0 0≈q) = +≈+ (trans c₁≈0 (sym c₂≈0)) (≈ⁱ-trans (≈ⁱ-sym 0≈p) 0≈q) ≈ⁱ-trans (+≈+ c₁≈c₂ p≈q) (+≈0 c₂≈0 0≈q) = +≈0 (trans c₁≈c₂ c₂≈0) (≈ⁱ-trans 0≈q (≈ⁱ-sym p≈q)) ≈ⁱ-trans (+≈+ c₁≈c₂ p≈q) (+≈+ c₂≈c₃ q≈r) = +≈+ (trans c₁≈c₂ c₂≈c₃) (≈ⁱ-trans p≈q q≈r) +ᵖ-*ᵖ-rawRing : RawRing (c ⊔ˡ ℓ) (c ⊔ˡ ℓ) +ᵖ-*ᵖ-rawRing = record { Carrier = Polynomial ; _≈_ = _≈ᵖ_ ; _+_ = _+ᵖ_ ; _*_ = _*ᵖ_ ; -_ = -ᵖ_ ; 0# = 0ᵖ ; 1# = 1ᵖ } +ⁱ-*ⁱ-rawRing : RawRing c (c ⊔ˡ ℓ) +ⁱ-*ⁱ-rawRing = record { Carrier = Polynomialⁱ ; _≈_ = _≈ⁱ_ ; _+_ = _+ⁱ_ ; _*_ = _*ⁱ_ ; -_ = -ⁱ_ ; 0# = 0ⁱ ; 1# = 1ⁱ } open import AKS.Extended ≤-totalOrder using (module ≤ᵉ-Reasoning) renaming ( Extended to Degree ; _≤ᵉ_ to _≤ᵈ_ ; ≤ᵉ-refl to ≤ᵈ-refl ; ≤ᵉ-trans to ≤ᵈ-trans ) public open Degree public open _≤ᵈ_ public module ≤ᵈ-Reasoning where open ≤ᵉ-Reasoning renaming (_∼⟨_⟩_ to _≤ᵈ⟨_⟩_; _∎ to _∎ᵈ; _≡⟨_⟩_ to _≡ᵈ⟨_⟩_) public instance Degree-number : Number Degree Degree-number = record { Constraint = λ _ → ⊤ ; fromNat = λ n → ⟨ n ⟩ } infixl 5 _⊔ᵈ_ _⊔ᵈ_ : Degree → Degree → Degree -∞ ⊔ᵈ d₂ = d₂ ⟨ d₁ ⟩ ⊔ᵈ -∞ = ⟨ d₁ ⟩ ⟨ d₁ ⟩ ⊔ᵈ ⟨ d₂ ⟩ = ⟨ d₁ ⊔ℕ d₂ ⟩ infixl 5 _+ᵈ_ _+ᵈ_ : Degree → Degree → Degree -∞ +ᵈ d₂ = -∞ ⟨ d₁ ⟩ +ᵈ -∞ = -∞ ⟨ d₁ ⟩ +ᵈ ⟨ d₂ ⟩ = ⟨ d₁ +ℕ d₂ ⟩ degreeˢ : Spine → ℕ degreeˢ (K c) = 0 degreeˢ (c +x^ n ∙ p) = ⟅ n ⇓⟆ +ℕ degreeˢ p degree : Polynomial → Degree degree 0ᵖ = -∞ degree (x^ n ∙ p) = ⟨ n +ℕ degreeˢ p ⟩ deg : ∀ p {p≉0 : p ≉ᵖ 0ᵖ} → ℕ deg 0ᵖ {p≉0} = contradiction ≈ᵖ-refl p≉0 deg (x^ n ∙ p) {p≉0} = n +ℕ degreeˢ p degreeⁱ : Polynomialⁱ → Degree degreeⁱ 0ⁱ = -∞ degreeⁱ (c +x∙ p) with degreeⁱ p ... | ⟨ n ⟩ = ⟨ suc n ⟩ ... | -∞ with c ≈? 0# ... | yes _ = -∞ ... | no _ = 0 open import Data.String using (String; _++_) open import Data.Nat.Show using () renaming (show to show-ℕ) show-Polynomial : (C → String) → Polynomial → String show-Polynomial show-c 0ᵖ = "0" show-Polynomial show-c (x^ n ∙ p) = loop n p where loop : ℕ → Spine → String loop zero (K c) = show-c (proj₁ c) loop zero (c +x^ n ∙ p) = show-c (proj₁ c) ++ " + " ++ loop ⟅ n ⇓⟆ p loop (suc n) (K c) = show-c (proj₁ c) ++ " * X^" ++ show-ℕ (suc n) loop (suc n) (c +x^ m ∙ p) = show-c (proj₁ c) ++ " * X^" ++ show-ℕ (suc n) ++ " + " ++ loop (suc n +ℕ ⟅ m ⇓⟆) p
29.526761
138
0.526903
359e2f56bb82bea98d2cca8d1c4675ae6765c536
692
agda
Agda
test/Fail/Issue118Comment9.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/Issue118Comment9.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/Issue118Comment9.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
module Issue118Comment9 where open import Common.Level open import Common.Coinduction data Box (A : Set) : Set where [_] : A → Box A postulate I : Set data P : I → Set where c : ∀ {i} → Box (∞ (P i)) → P i F : ∀ {i} → P i → I F (c x) = _ G : ∀ {i} → Box (∞ (P i)) → I G [ x ] = _ mutual f : ∀ {i} (x : P i) → P (F x) f (c x) = c (g x) g : ∀ {i} (x : Box (∞ (P i))) → Box (∞ (P (G x))) g [ x ] = [ ♯ f (♭ x) ] -- The code above type checks, but the termination checker should -- complain because the inferred definitions of F and G are -- F (c x) = G x and G [ x ] = F (♭ x), respectively. -- 2011-04-12 freezing: now the meta-variables remain uninstantiated. -- good.
19.771429
69
0.543353
353a9321a6fb64d3b1860d29c2c2bf01212d8f82
1,729
agda
Agda
agda-stdlib/src/Text/Tree/Linear.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Text/Tree/Linear.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Text/Tree/Linear.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- 1 dimensional pretty printing of rose trees ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Text.Tree.Linear where open import Level using (Level) open import Size open import Data.Bool.Base using (Bool; true; false; if_then_else_; _∧_) open import Data.DifferenceList as DList renaming (DiffList to DList) using () open import Data.List.Base as List using (List; []; [_]; _∷_; _∷ʳ_) open import Data.Nat.Base using (ℕ; _∸_) open import Data.Product using (_×_; _,_) open import Data.String.Base open import Data.Tree.Rose using (Rose; node) open import Function.Base using (flip) private variable a : Level A : Set a i : Size display : Rose (List String) i → List String display t = DList.toList (go (([] , t) ∷ [])) where padding : Bool → List Bool → String → String padding dir? [] str = str padding dir? (b ∷ bs) str = (if dir? ∧ List.null bs then if b then " ├ " else " └ " else if b then " │ " else " ") ++ padding dir? bs str nodePrefixes : List A → List Bool nodePrefixes as = true ∷ List.replicate (List.length as ∸ 1) false childrenPrefixes : List A → List Bool childrenPrefixes as = List.replicate (List.length as ∸ 1) true ∷ʳ false go : List (List Bool × Rose (List String) i) → DList String go [] = DList.[] go ((bs , node a ts₁) ∷ ts) = let bs′ = List.reverse bs in DList.fromList (List.zipWith (flip padding bs′) (nodePrefixes a) a) DList.++ go (List.zip (List.map (_∷ bs) (childrenPrefixes ts₁)) ts₁) DList.++ go ts
33.25
78
0.589358
adc127c6ce2d76464bea40347e1bf88ea4490bdd
155
agda
Agda
test/Fail/PureLambda.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/PureLambda.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/PureLambda.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module PureLambda where data D : Set where lam : (D -> D) -> D _·_ : D -> D -> D lam f · x = f x δ : D δ = lam (\x -> x · x) loop : D loop = δ · δ
9.6875
23
0.464516
30af30eb4ba21e494972196eacfc0305d30c8310
1,225
agda
Agda
src/fot/PA/Axiomatic/Standard/README.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/PA/Axiomatic/Standard/README.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/PA/Axiomatic/Standard/README.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- First-order Peano arithmetic ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module PA.Axiomatic.Standard.README where -- Formalization of first-order Peano arithmetic using Agda postulates -- for the non-logical constants and the Peano's axioms, and using -- axioms based on the propositional equality (see, for example, -- (Machover 1996, p. 263), (Hájek and Pudlák 1998, p. 28). ------------------------------------------------------------------------------ -- The axioms open import PA.Axiomatic.Standard.Base -- Some properties open import PA.Axiomatic.Standard.PropertiesATP open import PA.Axiomatic.Standard.PropertiesI ------------------------------------------------------------------------------ -- References -- -- Machover, Moshé (1996). Set theory, Logic and their -- Limitations. Cambridge University Press. -- Hájek, Petr and Pudlák, Pavel (1998). Metamathematics of -- First-Order Arithmetic. 2nd printing. Springer.
37.121212
78
0.524898
5e67d9308ad6e5dd2202cb802fe6f8bccffe890b
2,377
agda
Agda
Cubical/Categories/Presheaves.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
Cubical/Categories/Presheaves.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
Cubical/Categories/Presheaves.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --postfix-projections --safe #-} module Cubical.Categories.Presheaves where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.HITs.PropositionalTruncation open import Cubical.Categories.Category open import Cubical.Categories.Functor open import Cubical.Categories.NaturalTransformation open import Cubical.Categories.Sets module _ (ℓ ℓ' : Level) where PreShv : Precategory ℓ ℓ' → Precategory (ℓ-max (ℓ-suc ℓ) ℓ') (ℓ-max (ℓ-suc ℓ) ℓ') PreShv C = FUNCTOR (C ^op) (SET ℓ) private variable ℓ : Level module Yoneda (C : Precategory ℓ ℓ) ⦃ C-cat : isCategory C ⦄ where open Functor open NatTrans open Precategory C yo : ob → Functor (C ^op) (SET ℓ) yo x .F-ob y .fst = C [ y , x ] yo x .F-ob y .snd = C-cat .isSetHom yo x .F-hom f g = f ⋆⟨ C ⟩ g yo x .F-id i f = ⋆IdL f i yo x .F-seq f g i h = ⋆Assoc g f h i YO : Functor C (PreShv ℓ ℓ C) YO .F-ob = yo YO .F-hom f .N-ob z g = g ⋆⟨ C ⟩ f YO .F-hom f .N-hom g i h = ⋆Assoc g h f i YO .F-id = makeNatTransPath λ i _ → λ f → ⋆IdR f i YO .F-seq f g = makeNatTransPath λ i _ → λ h → ⋆Assoc h f g (~ i) module _ {x} (F : Functor (C ^op) (SET ℓ)) where yo-yo-yo : NatTrans (yo x) F → F .F-ob x .fst yo-yo-yo α = α .N-ob _ (id _) no-no-no : F .F-ob x .fst → NatTrans (yo x) F no-no-no a .N-ob y f = F .F-hom f a no-no-no a .N-hom f = funExt λ g i → F .F-seq g f i a yoIso : Iso (NatTrans (yo x) F) (F .F-ob x .fst) yoIso .Iso.fun = yo-yo-yo yoIso .Iso.inv = no-no-no yoIso .Iso.rightInv b i = F .F-id i b yoIso .Iso.leftInv a = makeNatTransPath (funExt λ _ → funExt rem) where rem : ∀ {z} (x₁ : C [ z , x ]) → F .F-hom x₁ (yo-yo-yo a) ≡ (a .N-ob z) x₁ rem g = F .F-hom g (yo-yo-yo a) ≡[ i ]⟨ a .N-hom g (~ i) (id x) ⟩ a .N-hom g i0 (id x) ≡[ i ]⟨ a .N-ob _ (⋆IdR g i) ⟩ (a .N-ob _) g ∎ yoEquiv : NatTrans (yo x) F ≃ F .F-ob x .fst yoEquiv = isoToEquiv yoIso isFullYO : isFull YO isFullYO x y F[f] = ∣ yo-yo-yo _ F[f] , yoIso {x} (yo y) .Iso.leftInv F[f] ∣ isFaithfulYO : isFaithful YO isFaithfulYO x y f g p i = hcomp (λ j → λ{ (i = i0) → ⋆IdL f j; (i = i1) → ⋆IdL g j}) (yo-yo-yo _ (p i))
30.474359
83
0.574253
4348889aa1be552adbf61d0b495e0ab549e78f7b
1,483
agda
Agda
test/Succeed/UsingEq.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/UsingEq.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/UsingEq.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
1
2021-04-01T18:30:09.000Z
2021-04-01T18:30:09.000Z
{-# OPTIONS --with-K #-} open import Agda.Builtin.Equality open import Agda.Builtin.Nat single : {m n : Nat} → suc m ≡ suc n → n ≡ m single p with refl ← p = refl double : {m n p : Nat} → suc m ≡ n → suc n ≡ 2 + p → m ≡ p double p q with refl ← p | refl ← q = refl _∋_ : (A : Set) → A → A A ∋ a = a -- The second equality proof is only well-typed -- after the first one has been used tele : {m n : Nat} → suc m ≡ suc n → m ≡ n tele {m} {n} p with refl ← p | refl ← (n ≡ m) ∋ refl = refl tele' : {m n : Nat} → m ≡ n → m ≡ n tele' {m} {n} p with refl ← p with (n ≡ m) ∋ refl ... | q = refl -- Further splitting after a using & with tele'' : {m n : Nat} → m ≡ n → Nat → Nat tele'' {m} {n} p r with refl ← p | (n ≡ m) ∋ refl tele'' {m} {m} p zero | q = m tele'' {m} {m} p (suc r) | q = r data Vec {a} (A : Set a) : Nat → Set a where [] : Vec A 0 _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) module _ {a} {A : Set a} {n} (xs : Vec A (suc n)) where head : A head with (x ∷ _) ← xs = x tail : Vec A n tail with (_ ∷ xs) ← xs = xs -- pattern shadows variable with'd on castVec : ∀ {m n} → m ≡ n → Vec Nat m → Vec Nat n castVec eq ms with refl ← eq = ms data All (P : Nat → Set) : ∀ {n} → Vec Nat n → Set where [] : All P [] _∷_ : ∀ {n x xs} → P x → All P {n} xs → All P (x ∷ xs) open import Agda.Builtin.Sigma castAll : ∀ {P m n xs ys} → Σ (m ≡ n) (λ eq → castVec eq xs ≡ ys) → All P xs → All P ys castAll (refl , refl) all = all
25.135593
68
0.515846
43bf72b8c3f5908bfe99310c706247a93594289d
556
agda
Agda
agda-stdlib/src/Data/ReflexiveClosure.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/ReflexiveClosure.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/ReflexiveClosure.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use the -- Relation.Binary.Construct.Closure.Reflexive module directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.ReflexiveClosure where open import Relation.Binary.Construct.Closure.Reflexive public {-# WARNING_ON_IMPORT "Data.ReflexiveClosure was deprecated in v0.16. Use Relation.Binary.Construct.Closure.Reflexive instead." #-}
30.888889
72
0.573741
59a5e238f58bd71c58e5535ad8e820e56333348a
29,156
agda
Agda
Cubical/Experiments/ZCohomologyOld/Properties.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Experiments/ZCohomologyOld/Properties.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Experiments/ZCohomologyOld/Properties.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{-# OPTIONS --safe #-} module Cubical.Experiments.ZCohomologyOld.Properties where open import Cubical.ZCohomology.Base open import Cubical.HITs.S1 open import Cubical.HITs.Sn open import Cubical.Foundations.HLevels open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed hiding (id) open import Cubical.Foundations.Transport open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Univalence open import Cubical.Data.Empty open import Cubical.Data.Sigma hiding (_×_) open import Cubical.HITs.Susp open import Cubical.HITs.Wedge open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim ; elim2 to sElim2 ; setTruncIsSet to §) open import Cubical.Data.Int renaming (_+_ to _ℤ+_) hiding (-_) open import Cubical.Data.Nat open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec ; elim3 to trElim3) hiding (map2) open import Cubical.Homotopy.Loopspace open import Cubical.Homotopy.Connected open import Cubical.Homotopy.Freudenthal open import Cubical.Algebra.Group renaming (Unit to trivialGroup ; Int to IntGroup) open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Data.NatMinusOne open import Cubical.HITs.Pushout open import Cubical.Data.Sum.Base open import Cubical.Data.HomotopyGroup open import Cubical.Experiments.ZCohomologyOld.KcompPrelims open Iso renaming (inv to inv') private variable ℓ ℓ' : Level A : Type ℓ B : Type ℓ' A' : Pointed ℓ infixr 34 _+ₖ_ infixr 34 _+ₕ_ is2ConnectedKn : (n : ℕ) → isConnected 2 (coHomK (suc n)) is2ConnectedKn zero = ∣ ∣ base ∣ ∣ , trElim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _) (trElim (λ _ → isOfHLevelPath 3 (isOfHLevelSuc 2 (isOfHLevelTrunc 2)) _ _) (toPropElim (λ _ → isOfHLevelTrunc 2 _ _) refl)) is2ConnectedKn (suc n) = ∣ ∣ north ∣ ∣ , trElim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _) (trElim (λ _ → isProp→isOfHLevelSuc (3 + n) (isOfHLevelTrunc 2 _ _)) (suspToPropElim (ptSn (suc n)) (λ _ → isOfHLevelTrunc 2 _ _) refl)) isConnectedKn : (n : ℕ) → isConnected (2 + n) (coHomK (suc n)) isConnectedKn n = isOfHLevelRetractFromIso 0 (invIso (truncOfTruncIso (2 + n) 1)) (sphereConnected (suc n)) -- Induction principles for cohomology groups -- If we want to show a proposition about some x : Hⁿ(A), it suffices to show it under the -- assumption that x = ∣f∣₂ and that f is pointed coHomPointedElim : {A : Type ℓ} (n : ℕ) (a : A) {B : coHom (suc n) A → Type ℓ'} → ((x : coHom (suc n) A) → isProp (B x)) → ((f : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → B ∣ f ∣₂) → (x : coHom (suc n) A) → B x coHomPointedElim {ℓ' = ℓ'} {A = A} n a isprop indp = sElim (λ _ → isOfHLevelSuc 1 (isprop _)) λ f → helper n isprop indp f (f a) refl where helper : (n : ℕ) {B : coHom (suc n) A → Type ℓ'} → ((x : coHom (suc n) A) → isProp (B x)) → ((f : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → B ∣ f ∣₂) → (f : A → coHomK (suc n)) → (x : coHomK (suc n)) → f a ≡ x → B ∣ f ∣₂ -- pattern matching a bit extra to avoid isOfHLevelPlus' helper zero isprop ind f = trElim (λ _ → isOfHLevelPlus {n = 1} 2 (isPropΠ λ _ → isprop _)) (toPropElim (λ _ → isPropΠ λ _ → isprop _) (ind f)) helper (suc zero) isprop ind f = trElim (λ _ → isOfHLevelPlus {n = 1} 3 (isPropΠ λ _ → isprop _)) (suspToPropElim base (λ _ → isPropΠ λ _ → isprop _) (ind f)) helper (suc (suc zero)) isprop ind f = trElim (λ _ → isOfHLevelPlus {n = 1} 4 (isPropΠ λ _ → isprop _)) (suspToPropElim north (λ _ → isPropΠ λ _ → isprop _) (ind f)) helper (suc (suc (suc n))) isprop ind f = trElim (λ _ → isOfHLevelPlus' {n = 5 + n} 1 (isPropΠ λ _ → isprop _)) (suspToPropElim north (λ _ → isPropΠ λ _ → isprop _) (ind f)) coHomPointedElim2 : {A : Type ℓ} (n : ℕ) (a : A) {B : coHom (suc n) A → coHom (suc n) A → Type ℓ'} → ((x y : coHom (suc n) A) → isProp (B x y)) → ((f g : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → g a ≡ coHom-pt (suc n) → B ∣ f ∣₂ ∣ g ∣₂) → (x y : coHom (suc n) A) → B x y coHomPointedElim2 {ℓ' = ℓ'} {A = A} n a isprop indp = sElim2 (λ _ _ → isOfHLevelSuc 1 (isprop _ _)) λ f g → helper n a isprop indp f g (f a) (g a) refl refl where helper : (n : ℕ) (a : A) {B : coHom (suc n) A → coHom (suc n) A → Type ℓ'} → ((x y : coHom (suc n) A) → isProp (B x y)) → ((f g : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → g a ≡ coHom-pt (suc n) → B ∣ f ∣₂ ∣ g ∣₂) → (f g : A → coHomK (suc n)) → (x y : coHomK (suc n)) → f a ≡ x → g a ≡ y → B ∣ f ∣₂ ∣ g ∣₂ helper zero a isprop indp f g = elim2 (λ _ _ → isOfHLevelPlus {n = 1} 2 (isPropΠ2 λ _ _ → isprop _ _)) (toPropElim2 (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g)) helper (suc zero) a isprop indp f g = elim2 (λ _ _ → isOfHLevelPlus {n = 1} 3 (isPropΠ2 λ _ _ → isprop _ _)) (suspToPropElim2 base (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g)) helper (suc (suc zero)) a isprop indp f g = elim2 (λ _ _ → isOfHLevelPlus {n = 1} 4 (isPropΠ2 λ _ _ → isprop _ _)) (suspToPropElim2 north (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g)) helper (suc (suc (suc n))) a isprop indp f g = elim2 (λ _ _ → isOfHLevelPlus' {n = 5 + n} 1 (isPropΠ2 λ _ _ → isprop _ _)) (suspToPropElim2 north (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g)) {- Equivalence between cohomology of A and reduced cohomology of (A + 1) -} coHomRed+1Equiv : (n : ℕ) → (A : Type ℓ) → (coHom n A) ≡ (coHomRed n ((A ⊎ Unit , inr (tt)))) coHomRed+1Equiv zero A i = ∥ helpLemma {C = (_ , pos 0)} i ∥₂ module coHomRed+1 where helpLemma : {C : Pointed ℓ} → ( (A → (typ C)) ≡ ((((A ⊎ Unit) , inr (tt)) →∙ C))) helpLemma {C = C} = isoToPath (iso map1 map2 (λ b → linvPf b) (λ _ → refl)) where map1 : (A → typ C) → ((((A ⊎ Unit) , inr (tt)) →∙ C)) map1 f = map1' , refl module helpmap where map1' : A ⊎ Unit → fst C map1' (inl x) = f x map1' (inr x) = pt C map2 : ((((A ⊎ Unit) , inr (tt)) →∙ C)) → (A → typ C) map2 (g , pf) x = g (inl x) linvPf : (b :((((A ⊎ Unit) , inr (tt)) →∙ C))) → map1 (map2 b) ≡ b linvPf (f , snd) i = (λ x → helper x i) , λ j → snd ((~ i) ∨ j) where helper : (x : A ⊎ Unit) → ((helpmap.map1') (map2 (f , snd)) x) ≡ f x helper (inl x) = refl helper (inr tt) = sym snd coHomRed+1Equiv (suc zero) A i = ∥ coHomRed+1.helpLemma A i {C = (coHomK 1 , ∣ base ∣)} i ∥₂ coHomRed+1Equiv (suc (suc n)) A i = ∥ coHomRed+1.helpLemma A i {C = (coHomK (2 + n) , ∣ north ∣)} i ∥₂ ----------- Kn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n))) Kn→ΩKn+1 n = Iso.fun (Iso-Kn-ΩKn+1 n) ΩKn+1→Kn : (n : ℕ) → typ (Ω (coHomK-ptd (suc n))) → coHomK n ΩKn+1→Kn n = Iso.inv (Iso-Kn-ΩKn+1 n) Kn≃ΩKn+1 : {n : ℕ} → coHomK n ≃ typ (Ω (coHomK-ptd (suc n))) Kn≃ΩKn+1 {n = n} = isoToEquiv (Iso-Kn-ΩKn+1 n) ---------- Algebra/Group stuff -------- 0ₖ : (n : ℕ) → coHomK n 0ₖ = coHom-pt _+ₖ_ : {n : ℕ} → coHomK n → coHomK n → coHomK n _+ₖ_ {n = n} x y = ΩKn+1→Kn n (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) -ₖ_ : {n : ℕ} → coHomK n → coHomK n -ₖ_ {n = n} x = ΩKn+1→Kn n (sym (Kn→ΩKn+1 n x)) -- subtraction as a binary operator _-ₖ_ : {n : ℕ} → coHomK n → coHomK n → coHomK n _-ₖ_ {n = n} x y = ΩKn+1→Kn n (Kn→ΩKn+1 n x ∙ sym (Kn→ΩKn+1 n y)) +ₖ-syntax : (n : ℕ) → coHomK n → coHomK n → coHomK n +ₖ-syntax n = _+ₖ_ {n = n} -ₖ-syntax : (n : ℕ) → coHomK n → coHomK n -ₖ-syntax n = -ₖ_ {n = n} -'ₖ-syntax : (n : ℕ) → coHomK n → coHomK n → coHomK n -'ₖ-syntax n = _-ₖ_ {n = n} syntax +ₖ-syntax n x y = x +[ n ]ₖ y syntax -ₖ-syntax n x = -[ n ]ₖ x syntax -'ₖ-syntax n x y = x -[ n ]ₖ y Kn→ΩKn+10ₖ : (n : ℕ) → Kn→ΩKn+1 n (0ₖ n) ≡ refl Kn→ΩKn+10ₖ zero = sym (rUnit refl) Kn→ΩKn+10ₖ (suc zero) i j = ∣ (rCancel (merid base) i j) ∣ Kn→ΩKn+10ₖ (suc (suc n)) i j = ∣ (rCancel (merid north) i j) ∣ ΩKn+1→Kn-refl : (n : ℕ) → ΩKn+1→Kn n refl ≡ 0ₖ n ΩKn+1→Kn-refl zero = refl ΩKn+1→Kn-refl (suc zero) = refl ΩKn+1→Kn-refl (suc (suc zero)) = refl ΩKn+1→Kn-refl (suc (suc (suc zero))) = refl ΩKn+1→Kn-refl (suc (suc (suc (suc zero)))) = refl ΩKn+1→Kn-refl (suc (suc (suc (suc (suc n))))) = refl -0ₖ : {n : ℕ} → -[ n ]ₖ (0ₖ n) ≡ (0ₖ n) -0ₖ {n = n} = (λ i → ΩKn+1→Kn n (sym (Kn→ΩKn+10ₖ n i))) ∙∙ (λ i → ΩKn+1→Kn n (Kn→ΩKn+10ₖ n (~ i))) ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) (0ₖ n) +ₖ→∙ : (n : ℕ) (a b : coHomK n) → Kn→ΩKn+1 n (a +[ n ]ₖ b) ≡ Kn→ΩKn+1 n a ∙ Kn→ΩKn+1 n b +ₖ→∙ n a b = Iso.rightInv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n a ∙ Kn→ΩKn+1 n b) lUnitₖ : (n : ℕ) (x : coHomK n) → (0ₖ n) +[ n ]ₖ x ≡ x lUnitₖ 0 x = Iso.leftInv (Iso-Kn-ΩKn+1 zero) x lUnitₖ (suc zero) = trElim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) λ x → Iso.leftInv (Iso-Kn-ΩKn+1 1) ∣ x ∣ lUnitₖ (suc (suc n)) x = (λ i → ΩKn+1→Kn (2 + n) (Kn→ΩKn+10ₖ (2 + n) i ∙ Kn→ΩKn+1 (2 + n) x)) ∙∙ (cong (ΩKn+1→Kn (2 + n)) (sym (lUnit (Kn→ΩKn+1 (2 + n) x)))) ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 (2 + n)) x rUnitₖ : (n : ℕ) (x : coHomK n) → x +[ n ]ₖ (0ₖ n) ≡ x rUnitₖ 0 x = Iso.leftInv (Iso-Kn-ΩKn+1 zero) x rUnitₖ (suc zero) = trElim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) λ x → Iso.leftInv (Iso-Kn-ΩKn+1 1) ∣ x ∣ rUnitₖ (suc (suc n)) x = (λ i → ΩKn+1→Kn (2 + n) (Kn→ΩKn+1 (2 + n) x ∙ Kn→ΩKn+10ₖ (2 + n) i)) ∙∙ (cong (ΩKn+1→Kn (2 + n)) (sym (rUnit (Kn→ΩKn+1 (2 + n) x)))) ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 (2 + n)) x rCancelₖ : (n : ℕ) (x : coHomK n) → x +[ n ]ₖ (-[ n ]ₖ x) ≡ (0ₖ n) rCancelₖ zero x = (λ i → ΩKn+1→Kn 0 (Kn→ΩKn+1 zero x ∙ Iso.rightInv (Iso-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i)) ∙ cong (ΩKn+1→Kn 0) (rCancel (Kn→ΩKn+1 zero x)) rCancelₖ (suc n) x = (λ i → ΩKn+1→Kn (suc n) (Kn→ΩKn+1 (1 + n) x ∙ Iso.rightInv (Iso-Kn-ΩKn+1 (1 + n)) (sym (Kn→ΩKn+1 (1 + n) x)) i)) ∙ cong (ΩKn+1→Kn (suc n)) (rCancel (Kn→ΩKn+1 (1 + n) x)) ∙ (λ i → ΩKn+1→Kn (suc n) (Kn→ΩKn+10ₖ (suc n) (~ i))) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 (suc n)) (0ₖ (suc n)) lCancelₖ : (n : ℕ) (x : coHomK n) → (-[ n ]ₖ x) +[ n ]ₖ x ≡ (0ₖ n) lCancelₖ 0 x = (λ i → ΩKn+1→Kn 0 (Iso.rightInv (Iso-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i ∙ Kn→ΩKn+1 zero x)) ∙ cong (ΩKn+1→Kn 0) (lCancel (Kn→ΩKn+1 zero x)) lCancelₖ (suc n) x = (λ i → ΩKn+1→Kn (suc n) (Iso.rightInv (Iso-Kn-ΩKn+1 (1 + n)) (sym (Kn→ΩKn+1 (1 + n) x)) i ∙ Kn→ΩKn+1 (1 + n) x)) ∙ cong (ΩKn+1→Kn (suc n)) (lCancel (Kn→ΩKn+1 (1 + n) x)) ∙ (λ i → (ΩKn+1→Kn (suc n)) (Kn→ΩKn+10ₖ (suc n) (~ i))) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 (suc n)) (0ₖ (suc n)) assocₖ : (n : ℕ) (x y z : coHomK n) → ((x +[ n ]ₖ y) +[ n ]ₖ z) ≡ (x +[ n ]ₖ (y +[ n ]ₖ z)) assocₖ n x y z = ((λ i → ΩKn+1→Kn n (Kn→ΩKn+1 n (ΩKn+1→Kn n (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)) ∙ Kn→ΩKn+1 n z)) ∙∙ (λ i → ΩKn+1→Kn n (Iso.rightInv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i ∙ Kn→ΩKn+1 n z)) ∙∙ (λ i → ΩKn+1→Kn n (assoc (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) (Kn→ΩKn+1 n z) (~ i)))) ∙ (λ i → ΩKn+1→Kn n ((Kn→ΩKn+1 n x) ∙ Iso.rightInv (Iso-Kn-ΩKn+1 n) ((Kn→ΩKn+1 n y ∙ Kn→ΩKn+1 n z)) (~ i))) cancelₖ : (n : ℕ) (x : coHomK n) → x -[ n ]ₖ x ≡ (0ₖ n) cancelₖ zero x = cong (ΩKn+1→Kn 0) (rCancel (Kn→ΩKn+1 zero x)) cancelₖ (suc zero) x = cong (ΩKn+1→Kn 1) (rCancel (Kn→ΩKn+1 1 x)) cancelₖ (suc (suc zero)) x = cong (ΩKn+1→Kn 2) (rCancel (Kn→ΩKn+1 2 x)) cancelₖ (suc (suc (suc zero))) x = cong (ΩKn+1→Kn 3) (rCancel (Kn→ΩKn+1 3 x)) cancelₖ (suc (suc (suc (suc zero)))) x = cong (ΩKn+1→Kn 4) (rCancel (Kn→ΩKn+1 4 x)) cancelₖ (suc (suc (suc (suc (suc n))))) x = cong (ΩKn+1→Kn (5 + n)) (rCancel (Kn→ΩKn+1 (5 + n) x)) -rUnitₖ : (n : ℕ) (x : coHomK n) → x -[ n ]ₖ 0ₖ n ≡ x -rUnitₖ zero x = rUnitₖ zero x -rUnitₖ (suc n) x = cong (λ y → ΩKn+1→Kn (suc n) (Kn→ΩKn+1 (suc n) x ∙ sym y)) (Kn→ΩKn+10ₖ (suc n)) ∙∙ cong (ΩKn+1→Kn (suc n)) (sym (rUnit (Kn→ΩKn+1 (suc n) x))) ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 (suc n)) x abstract isCommΩK1 : (n : ℕ) → isComm∙ ((Ω^ n) (coHomK-ptd 1)) isCommΩK1 zero = isCommA→isCommTrunc 2 comm-ΩS¹ isGroupoidS¹ isCommΩK1 (suc n) = Eckmann-Hilton n open Iso renaming (inv to inv') isCommΩK : (n : ℕ) → isComm∙ (coHomK-ptd n) isCommΩK zero p q = isSetInt _ _ (p ∙ q) (q ∙ p) isCommΩK (suc zero) = isCommA→isCommTrunc 2 comm-ΩS¹ isGroupoidS¹ isCommΩK (suc (suc n)) = subst isComm∙ (λ i → coHomK (2 + n) , ΩKn+1→Kn-refl (2 + n) i) (ptdIso→comm {A = (_ , _)} (invIso (Iso-Kn-ΩKn+1 (2 + n))) (Eckmann-Hilton 0)) commₖ : (n : ℕ) (x y : coHomK n) → (x +[ n ]ₖ y) ≡ (y +[ n ]ₖ x) commₖ 0 x y i = ΩKn+1→Kn 0 (isCommΩK1 0 (Kn→ΩKn+1 0 x) (Kn→ΩKn+1 0 y) i) commₖ 1 x y i = ΩKn+1→Kn 1 (ptdIso→comm {A = ((∣ north ∣ ≡ ∣ north ∣) , snd ((Ω^ 1) (coHomK 3 , ∣ north ∣)))} {B = coHomK 2} (invIso (Iso-Kn-ΩKn+1 2)) (Eckmann-Hilton 0) (Kn→ΩKn+1 1 x) (Kn→ΩKn+1 1 y) i) commₖ 2 x y i = ΩKn+1→Kn 2 (ptdIso→comm {A = (∣ north ∣ ≡ ∣ north ∣) , snd ((Ω^ 1) (coHomK 4 , ∣ north ∣))} {B = coHomK 3} (invIso (Iso-Kn-ΩKn+1 3)) (Eckmann-Hilton 0) (Kn→ΩKn+1 2 x) (Kn→ΩKn+1 2 y) i) commₖ 3 x y i = ΩKn+1→Kn 3 (ptdIso→comm {A = (∣ north ∣ ≡ ∣ north ∣) , snd ((Ω^ 1) (coHomK 5 , ∣ north ∣))} {B = coHomK 4} (invIso (Iso-Kn-ΩKn+1 4)) (Eckmann-Hilton 0) (Kn→ΩKn+1 3 x) (Kn→ΩKn+1 3 y) i) commₖ (suc (suc (suc (suc n)))) x y i = ΩKn+1→Kn (4 + n) (ptdIso→comm {A = (∣ north ∣ ≡ ∣ north ∣) , snd ((Ω^ 1) (coHomK (6 + n) , ∣ north ∣))} {B = coHomK (5 + n)} (invIso (Iso-Kn-ΩKn+1 (5 + n))) (Eckmann-Hilton 0) (Kn→ΩKn+1 (4 + n) x) (Kn→ΩKn+1 (4 + n) y) i) rUnitₖ' : (n : ℕ) (x : coHomK n) → x +[ n ]ₖ (0ₖ n) ≡ x rUnitₖ' n x = commₖ n x (0ₖ n) ∙ lUnitₖ n x -distrₖ : (n : ℕ) (x y : coHomK n) → -[ n ]ₖ (x +[ n ]ₖ y) ≡ (-[ n ]ₖ x) +[ n ]ₖ (-[ n ]ₖ y) -distrₖ n x y = ((λ i → ΩKn+1→Kn n (sym (Kn→ΩKn+1 n (ΩKn+1→Kn n (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y))))) ∙∙ (λ i → ΩKn+1→Kn n (sym (Iso.rightInv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i))) ∙∙ (λ i → ΩKn+1→Kn n (symDistr (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i))) ∙∙ (λ i → ΩKn+1→Kn n (Iso.rightInv (Iso-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n y)) (~ i) ∙ (Iso.rightInv (Iso-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n x)) (~ i)))) ∙∙ commₖ n (-[ n ]ₖ y) (-[ n ]ₖ x) private rCancelLem : (n : ℕ) (x : coHomK n) → ΩKn+1→Kn n ((Kn→ΩKn+1 n x) ∙ refl) ≡ ΩKn+1→Kn n (Kn→ΩKn+1 n x) rCancelLem zero x = refl rCancelLem (suc n) x = cong (ΩKn+1→Kn (suc n)) (sym (rUnit (Kn→ΩKn+1 (suc n) x))) lCancelLem : (n : ℕ) (x : coHomK n) → ΩKn+1→Kn n (refl ∙ (Kn→ΩKn+1 n x)) ≡ ΩKn+1→Kn n (Kn→ΩKn+1 n x) lCancelLem zero x = refl lCancelLem (suc n) x = cong (ΩKn+1→Kn (suc n)) (sym (lUnit (Kn→ΩKn+1 (suc n) x))) -cancelRₖ : (n : ℕ) (x y : coHomK n) → (y +[ n ]ₖ x) -[ n ]ₖ x ≡ y -cancelRₖ n x y = (cong (ΩKn+1→Kn n) ((cong (_∙ sym (Kn→ΩKn+1 n x)) (+ₖ→∙ n y x)) ∙∙ sym (assoc _ _ _) ∙∙ cong (Kn→ΩKn+1 n y ∙_) (rCancel _))) ∙∙ rCancelLem n y ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) y -cancelLₖ : (n : ℕ) (x y : coHomK n) → (x +[ n ]ₖ y) -[ n ]ₖ x ≡ y -cancelLₖ n x y = cong (λ z → z -[ n ]ₖ x) (commₖ n x y) ∙ -cancelRₖ n x y -+cancelₖ : (n : ℕ) (x y : coHomK n) → (x -[ n ]ₖ y) +[ n ]ₖ y ≡ x -+cancelₖ n x y = (cong (ΩKn+1→Kn n) ((cong (_∙ (Kn→ΩKn+1 n y)) (Iso.rightInv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ sym (Kn→ΩKn+1 n y)))) ∙∙ sym (assoc _ _ _) ∙∙ cong (Kn→ΩKn+1 n x ∙_) (lCancel _))) ∙∙ rCancelLem n x ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) x ---- Group structure of cohomology groups --- _+ₕ_ : {n : ℕ} → coHom n A → coHom n A → coHom n A _+ₕ_ {n = n} = sRec2 § λ a b → ∣ (λ x → a x +[ n ]ₖ b x) ∣₂ -ₕ_ : {n : ℕ} → coHom n A → coHom n A -ₕ_ {n = n} = sRec § λ a → ∣ (λ x → -[ n ]ₖ a x) ∣₂ _-ₕ_ : {n : ℕ} → coHom n A → coHom n A → coHom n A _-ₕ_ {n = n} = sRec2 § λ a b → ∣ (λ x → a x -[ n ]ₖ b x) ∣₂ +ₕ-syntax : (n : ℕ) → coHom n A → coHom n A → coHom n A +ₕ-syntax n = _+ₕ_ {n = n} -ₕ-syntax : (n : ℕ) → coHom n A → coHom n A -ₕ-syntax n = -ₕ_ {n = n} -ₕ'-syntax : (n : ℕ) → coHom n A → coHom n A → coHom n A -ₕ'-syntax n = _-ₕ_ {n = n} syntax +ₕ-syntax n x y = x +[ n ]ₕ y syntax -ₕ-syntax n x = -[ n ]ₕ x syntax -ₕ'-syntax n x y = x -[ n ]ₕ y 0ₕ : (n : ℕ) → coHom n A 0ₕ n = ∣ (λ _ → (0ₖ n)) ∣₂ rUnitₕ : (n : ℕ) (x : coHom n A) → x +[ n ]ₕ (0ₕ n) ≡ x rUnitₕ n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → rUnitₖ n (a x)) i ∣₂ lUnitₕ : (n : ℕ) (x : coHom n A) → (0ₕ n) +[ n ]ₕ x ≡ x lUnitₕ n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → lUnitₖ n (a x)) i ∣₂ rCancelₕ : (n : ℕ) (x : coHom n A) → x +[ n ]ₕ (-[ n ]ₕ x) ≡ 0ₕ n rCancelₕ n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → rCancelₖ n (a x)) i ∣₂ lCancelₕ : (n : ℕ) (x : coHom n A) → (-[ n ]ₕ x) +[ n ]ₕ x ≡ 0ₕ n lCancelₕ n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → lCancelₖ n (a x)) i ∣₂ assocₕ : (n : ℕ) (x y z : coHom n A) → ((x +[ n ]ₕ y) +[ n ]ₕ z) ≡ (x +[ n ]ₕ (y +[ n ]ₕ z)) assocₕ n = elim3 (λ _ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b c i → ∣ funExt (λ x → assocₖ n (a x) (b x) (c x)) i ∣₂ commₕ : (n : ℕ) (x y : coHom n A) → (x +[ n ]ₕ y) ≡ (y +[ n ]ₕ x) commₕ n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ funExt (λ x → commₖ n (a x) (b x)) i ∣₂ cancelₕ : (n : ℕ) (x : coHom n A) → x -[ n ]ₕ x ≡ 0ₕ n cancelₕ n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → cancelₖ n (a x)) i ∣₂ -ₖ-ₖ : (n : ℕ) (x : coHomK n) → (-[ n ]ₖ (-[ n ]ₖ x)) ≡ x -ₖ-ₖ n x = cong ((ΩKn+1→Kn n) ∘ sym) (Iso.rightInv (Iso-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n x))) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) x -- Proof that rUnitₖ and lUnitₖ agree on 0ₖ. Needed for Mayer-Vietoris. private rUnitlUnitGen : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {b : B} (e : Iso A (b ≡ b)) (0A : A) (0fun : fun e 0A ≡ refl) → Path (inv' e (fun e 0A ∙ fun e 0A) ≡ 0A) (cong (inv' e) (cong (_∙ fun e 0A) 0fun) ∙∙ cong (inv' e) (sym (lUnit (fun e 0A))) ∙∙ Iso.leftInv e 0A) (cong (inv' e) (cong (fun e 0A ∙_) 0fun) ∙∙ cong (inv' e) (sym (rUnit (fun e 0A))) ∙∙ Iso.leftInv e 0A) rUnitlUnitGen e 0A 0fun = (λ i → cong (inv' e) (cong (_∙ fun e 0A) 0fun) ∙∙ rUnit (cong (inv' e) (sym (lUnit (fun e 0A)))) i ∙∙ Iso.leftInv e 0A) ∙ ((λ i → (λ j → inv' e (0fun (~ i ∧ j) ∙ 0fun (j ∧ i))) ∙∙ ((λ j → inv' e (0fun (~ i ∨ j) ∙ 0fun i)) ∙∙ cong (inv' e) (sym (lUnit (0fun i))) ∙∙ λ j → inv' e (0fun (i ∧ (~ j)))) ∙∙ Iso.leftInv e 0A) ∙∙ (λ i → (λ j → inv' e (fun e 0A ∙ 0fun j)) ∙∙ (λ j → inv' e (0fun (j ∧ ~ i) ∙ refl)) ∙∙ cong (inv' e) (sym (rUnit (0fun (~ i)))) ∙∙ (λ j → inv' e (0fun (~ i ∧ ~ j))) ∙∙ Iso.leftInv e 0A) ∙∙ λ i → cong (inv' e) (cong (fun e 0A ∙_) 0fun) ∙∙ rUnit (cong (inv' e) (sym (rUnit (fun e 0A)))) (~ i) ∙∙ Iso.leftInv e 0A) rUnitlUnit0 : (n : ℕ) → rUnitₖ n (0ₖ n) ≡ lUnitₖ n (0ₖ n) rUnitlUnit0 0 = refl rUnitlUnit0 (suc zero) = refl rUnitlUnit0 (suc (suc n)) = sym (rUnitlUnitGen (Iso-Kn-ΩKn+1 (2 + n)) (0ₖ (2 + n)) (Kn→ΩKn+10ₖ (2 + n))) -cancelLₕ : (n : ℕ) (x y : coHom n A) → (x +[ n ]ₕ y) -[ n ]ₕ x ≡ y -cancelLₕ n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ (λ x → -cancelLₖ n (a x) (b x) i) ∣₂ -cancelRₕ : (n : ℕ) (x y : coHom n A) → (y +[ n ]ₕ x) -[ n ]ₕ x ≡ y -cancelRₕ n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ (λ x → -cancelRₖ n (a x) (b x) i) ∣₂ -+cancelₕ : (n : ℕ) (x y : coHom n A) → (x -[ n ]ₕ y) +[ n ]ₕ y ≡ x -+cancelₕ n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ (λ x → -+cancelₖ n (a x) (b x) i) ∣₂ -- Group structure of reduced cohomology groups (in progress - might need K to compute properly first) --- +ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A → coHomRed n A +ₕ∙ zero = sRec2 § λ { (a , pa) (b , pb) → ∣ (λ x → a x +[ zero ]ₖ b x) , (λ i → (pa i +[ zero ]ₖ pb i)) ∣₂ } +ₕ∙ (suc zero) = sRec2 § λ { (a , pa) (b , pb) → ∣ (λ x → a x +[ 1 ]ₖ b x) , (λ i → pa i +[ 1 ]ₖ pb i) ∙ lUnitₖ 1 (0ₖ 1) ∣₂ } +ₕ∙ (suc (suc n)) = sRec2 § λ { (a , pa) (b , pb) → ∣ (λ x → a x +[ (2 + n) ]ₖ b x) , (λ i → pa i +[ (2 + n) ]ₖ pb i) ∙ lUnitₖ (2 + n) (0ₖ (2 + n)) ∣₂ } open IsSemigroup open IsMonoid open GroupStr open IsGroupHom coHomGr : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → Group ℓ coHomGr n A = coHom n A , coHomGrnA where coHomGrnA : GroupStr (coHom n A) 1g coHomGrnA = 0ₕ n GroupStr._·_ coHomGrnA = λ x y → x +[ n ]ₕ y inv coHomGrnA = λ x → -[ n ]ₕ x isGroup coHomGrnA = helper where abstract helper : IsGroup {G = coHom n A} (0ₕ n) (λ x y → x +[ n ]ₕ y) (λ x → -[ n ]ₕ x) helper = makeIsGroup § (λ x y z → sym (assocₕ n x y z)) (rUnitₕ n) (lUnitₕ n) (rCancelₕ n) (lCancelₕ n) ×coHomGr : (n : ℕ) (A : Type ℓ) (B : Type ℓ') → Group _ ×coHomGr n A B = DirProd (coHomGr n A) (coHomGr n B) coHomFun : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n : ℕ) (f : A → B) → coHom n B → coHom n A coHomFun n f = sRec § λ β → ∣ β ∘ f ∣₂ -distrLemma : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : ℕ) (f : GroupHom (coHomGr n A) (coHomGr m B)) (x y : coHom n A) → fst f (x -[ n ]ₕ y) ≡ fst f x -[ m ]ₕ fst f y -distrLemma n m f' x y = sym (-cancelRₕ m (f y) (f (x -[ n ]ₕ y))) ∙∙ cong (λ x → x -[ m ]ₕ f y) (sym (f' .snd .pres· (x -[ n ]ₕ y) y)) ∙∙ cong (λ x → x -[ m ]ₕ f y) ( cong f (-+cancelₕ n _ _)) where f = fst f' --- the loopspace of Kₙ is commutative regardless of base addIso : (n : ℕ) (x : coHomK n) → Iso (coHomK n) (coHomK n) fun (addIso n x) y = y +[ n ]ₖ x inv' (addIso n x) y = y -[ n ]ₖ x rightInv (addIso n x) y = -+cancelₖ n y x leftInv (addIso n x) y = -cancelRₖ n x y isCommΩK-based : (n : ℕ) (x : coHomK n) → isComm∙ (coHomK n , x) isCommΩK-based zero x p q = isSetInt _ _ (p ∙ q) (q ∙ p) isCommΩK-based (suc zero) x = subst isComm∙ (λ i → coHomK 1 , lUnitₖ 1 x i) (ptdIso→comm {A = (_ , 0ₖ 1)} (addIso 1 x) (isCommΩK 1)) isCommΩK-based (suc (suc n)) x = subst isComm∙ (λ i → coHomK (suc (suc n)) , lUnitₖ (suc (suc n)) x i) (ptdIso→comm {A = (_ , 0ₖ (suc (suc n)))} (addIso (suc (suc n)) x) (isCommΩK (suc (suc n)))) addLemma : (a b : Int) → a +[ 0 ]ₖ b ≡ (a ℤ+ b) addLemma a b = (cong (ΩKn+1→Kn 0) (sym (congFunct ∣_∣ (intLoop a) (intLoop b)))) ∙∙ (λ i → ΩKn+1→Kn 0 (cong ∣_∣ (intLoop-hom a b i))) ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 0) (a ℤ+ b) --- -- hidden versions of cohom stuff using the "lock" hack. The locked versions can be used when proving things. -- Swapping "key" for "tt*" will then give computing functions. Unit' : Type₀ Unit' = lockUnit {ℓ-zero} lock : ∀ {ℓ} {A : Type ℓ} → Unit' → A → A lock unlock = λ x → x module lockedCohom (key : Unit') where +K : (n : ℕ) → coHomK n → coHomK n → coHomK n +K n = lock key (_+ₖ_ {n = n}) -K : (n : ℕ) → coHomK n → coHomK n -K n = lock key (-ₖ_ {n = n}) -Kbin : (n : ℕ) → coHomK n → coHomK n → coHomK n -Kbin n = lock key (_-ₖ_ {n = n}) rUnitK : (n : ℕ) (x : coHomK n) → +K n x (0ₖ n) ≡ x rUnitK n x = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) x (0ₖ n) ≡ x pm unlock = rUnitₖ n x lUnitK : (n : ℕ) (x : coHomK n) → +K n (0ₖ n) x ≡ x lUnitK n x = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) (0ₖ n) x ≡ x pm unlock = lUnitₖ n x rCancelK : (n : ℕ) (x : coHomK n) → +K n x (-K n x) ≡ 0ₖ n rCancelK n x = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) x (lock t (-ₖ_ {n = n}) x) ≡ 0ₖ n pm unlock = rCancelₖ n x lCancelK : (n : ℕ) (x : coHomK n) → +K n (-K n x) x ≡ 0ₖ n lCancelK n x = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) (lock t (-ₖ_ {n = n}) x) x ≡ 0ₖ n pm unlock = lCancelₖ n x -cancelRK : (n : ℕ) (x y : coHomK n) → -Kbin n (+K n y x) x ≡ y -cancelRK n x y = pm key where pm : (t : Unit') → lock t (_-ₖ_ {n = n}) (lock t (_+ₖ_ {n = n}) y x) x ≡ y pm unlock = -cancelRₖ n x y -cancelLK : (n : ℕ) (x y : coHomK n) → -Kbin n (+K n x y) x ≡ y -cancelLK n x y = pm key where pm : (t : Unit') → lock t (_-ₖ_ {n = n}) (lock t (_+ₖ_ {n = n}) x y) x ≡ y pm unlock = -cancelLₖ n x y -+cancelK : (n : ℕ) (x y : coHomK n) → +K n (-Kbin n x y) y ≡ x -+cancelK n x y = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) (lock t (_-ₖ_ {n = n}) x y) y ≡ x pm unlock = -+cancelₖ n x y cancelK : (n : ℕ) (x : coHomK n) → -Kbin n x x ≡ 0ₖ n cancelK n x = pm key where pm : (t : Unit') → (lock t (_-ₖ_ {n = n}) x x) ≡ 0ₖ n pm unlock = cancelₖ n x assocK : (n : ℕ) (x y z : coHomK n) → +K n (+K n x y) z ≡ +K n x (+K n y z) assocK n x y z = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) (lock t (_+ₖ_ {n = n}) x y) z ≡ lock t (_+ₖ_ {n = n}) x (lock t (_+ₖ_ {n = n}) y z) pm unlock = assocₖ n x y z commK : (n : ℕ) (x y : coHomK n) → +K n x y ≡ +K n y x commK n x y = pm key where pm : (t : Unit') → lock t (_+ₖ_ {n = n}) x y ≡ lock t (_+ₖ_ {n = n}) y x pm unlock = commₖ n x y -- cohom +H : (n : ℕ) (x y : coHom n A) → coHom n A +H n = sRec2 § λ a b → ∣ (λ x → +K n (a x) (b x)) ∣₂ -H : (n : ℕ) (x : coHom n A) → coHom n A -H n = sRec § λ a → ∣ (λ x → -K n (a x)) ∣₂ -Hbin : (n : ℕ) → coHom n A → coHom n A → coHom n A -Hbin n = sRec2 § λ a b → ∣ (λ x → -Kbin n (a x) (b x)) ∣₂ rUnitH : (n : ℕ) (x : coHom n A) → +H n x (0ₕ n) ≡ x rUnitH n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → rUnitK n (a x)) i ∣₂ lUnitH : (n : ℕ) (x : coHom n A) → +H n (0ₕ n) x ≡ x lUnitH n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → lUnitK n (a x)) i ∣₂ rCancelH : (n : ℕ) (x : coHom n A) → +H n x (-H n x) ≡ 0ₕ n rCancelH n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → rCancelK n (a x)) i ∣₂ lCancelH : (n : ℕ) (x : coHom n A) → +H n (-H n x) x ≡ 0ₕ n lCancelH n = sElim (λ _ → isOfHLevelPath 1 (§ _ _)) λ a i → ∣ funExt (λ x → lCancelK n (a x)) i ∣₂ assocH : (n : ℕ) (x y z : coHom n A) → (+H n (+H n x y) z) ≡ (+H n x (+H n y z)) assocH n = elim3 (λ _ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b c i → ∣ funExt (λ x → assocK n (a x) (b x) (c x)) i ∣₂ commH : (n : ℕ) (x y : coHom n A) → (+H n x y) ≡ (+H n y x) commH n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ funExt (λ x → commK n (a x) (b x)) i ∣₂ -cancelRH : (n : ℕ) (x y : coHom n A) → -Hbin n (+H n y x) x ≡ y -cancelRH n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ (λ x → -cancelRK n (a x) (b x) i) ∣₂ -cancelLH : (n : ℕ) (x y : coHom n A) → -Hbin n (+H n x y) x ≡ y -cancelLH n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ (λ x → -cancelLK n (a x) (b x) i) ∣₂ -+cancelH : (n : ℕ) (x y : coHom n A) → +H n (-Hbin n x y) y ≡ x -+cancelH n = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _)) λ a b i → ∣ (λ x → -+cancelK n (a x) (b x) i) ∣₂ +K→∙ : (key : Unit') (n : ℕ) (a b : coHomK n) → Kn→ΩKn+1 n (lockedCohom.+K key n a b) ≡ Kn→ΩKn+1 n a ∙ Kn→ΩKn+1 n b +K→∙ unlock = +ₖ→∙ +H≡+ₕ : (key : Unit') (n : ℕ) → lockedCohom.+H key {A = A} n ≡ _+ₕ_ {n = n} +H≡+ₕ unlock _ = refl rUnitlUnit0K : (key : Unit') (n : ℕ) → lockedCohom.rUnitK key n (0ₖ n) ≡ lockedCohom.lUnitK key n (0ₖ n) rUnitlUnit0K unlock = rUnitlUnit0
45.914961
168
0.496604
7c3aaba3c81865926290b27b713c90ead5ba3362
360
agda
Agda
RefactorAgdaEngine/Test/Tests/input/ExtractFunction.agda
omega12345/RefactorAgda
52d1034aed14c578c9e077fb60c3db1d0791416b
[ "BSD-3-Clause" ]
5
2019-01-31T14:10:18.000Z
2019-05-03T10:03:36.000Z
RefactorAgdaEngine/Test/Tests/input/ExtractFunction.agda
omega12345/RefactorAgda
52d1034aed14c578c9e077fb60c3db1d0791416b
[ "BSD-3-Clause" ]
3
2019-01-31T08:03:07.000Z
2019-02-05T12:53:36.000Z
RefactorAgdaEngine/Test/Tests/input/ExtractFunction.agda
omega12345/RefactorAgda
52d1034aed14c578c9e077fb60c3db1d0791416b
[ "BSD-3-Clause" ]
1
2019-01-31T08:40:41.000Z
2019-01-31T08:40:41.000Z
{-# OPTIONS --allow-unsolved-metas #-} module ExtractFunction where open import Agda.Builtin.Nat open import Agda.Builtin.Bool plus : Nat -> Nat -> Nat plus = {! !} function1 : (x : Nat) -> (y : Nat) -> Nat function1 x y = plus x y pickTheFirst : Nat -> Bool -> Nat pickTheFirst x y = x function2 : Nat -> Bool -> Nat function2 x y = pickTheFirst x y
20
41
0.652778
52f82ec0f040e5c6f3ad47a06f901d742fb34ad5
2,244
agda
Agda
src/fot/FOTC/Program/Mirror/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Program/Mirror/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Program/Mirror/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Properties of the mirror function ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.Mirror.PropertiesATP where open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.List open import FOTC.Data.List.PropertiesATP using ( reverse-[x]≡[x] ) open import FOTC.Program.Mirror.Forest.PropertiesATP open import FOTC.Program.Mirror.Forest.TotalityATP open import FOTC.Program.Mirror.Mirror open import FOTC.Program.Mirror.Tree.TotalityATP open import FOTC.Program.Mirror.Type ------------------------------------------------------------------------------ mirror-involutive : ∀ {t} → Tree t → mirror · (mirror · t) ≡ t helper : ∀ {ts} → Forest ts → reverse (map mirror (reverse (map mirror ts))) ≡ ts mirror-involutive (tree d fnil) = prf where postulate prf : mirror · (mirror · node d []) ≡ node d [] {-# ATP prove prf #-} mirror-involutive (tree d (fcons {t} {ts} Tt Fts)) = prf where postulate prf : mirror · (mirror · node d (t ∷ ts)) ≡ node d (t ∷ ts) {-# ATP prove prf helper #-} helper fnil = prf where postulate prf : reverse (map mirror (reverse (map mirror []))) ≡ [] {-# ATP prove prf #-} helper (fcons {t} {ts} Tt Fts) = prf (map-++ mirror mirror-Tree (reverse-Forest (map-Forest mirror mirror-Tree Fts)) (mirror · t ∷ [])) (mirror-involutive Tt) (helper Fts) where postulate -- We help the ATPs proving the first hypothesis. prf : (map mirror (reverse (map mirror ts) ++ (mirror · t ∷ [])) ≡ map mirror (reverse (map mirror ts)) ++ (map mirror (mirror · t ∷ []))) → mirror · (mirror · t) ≡ t → reverse (map mirror (reverse (map mirror ts))) ≡ ts → reverse (map mirror (reverse (map mirror (t ∷ ts)))) ≡ t ∷ ts {-# ATP prove prf reverse-∷ mirror-Tree map-Forest reverse-++ reverse-Forest reverse-[x]≡[x] #-}
38.689655
78
0.533422
2e42267ccc5d3f4ad4c73f7c1c36323121e9b8fb
1,134
agda
Agda
src/Data/Natural/Primitive.agda
agda/agda-system-io
121d6c66cba34b4c15b437366b80c65dd2b02a8d
[ "MIT" ]
10
2015-01-04T13:45:16.000Z
2021-09-15T04:35:41.000Z
src/Data/Natural/Primitive.agda
agda/agda-system-io
121d6c66cba34b4c15b437366b80c65dd2b02a8d
[ "MIT" ]
null
null
null
src/Data/Natural/Primitive.agda
agda/agda-system-io
121d6c66cba34b4c15b437366b80c65dd2b02a8d
[ "MIT" ]
2
2017-08-10T06:12:54.000Z
2022-03-12T11:40:23.000Z
open import Data.Nat using ( ℕ ) renaming ( zero to zero' ; suc to suc' ) open import Data.Nat.GeneralisedArithmetic using ( fold ) open import Data.String using ( String ) module Data.Natural.Primitive where infixl 6 _+_ postulate Natural : Set zero : Natural suc : Natural → Natural _+_ : Natural → Natural → Natural show : Natural → String foldl : {A : Set} → (A → A) → A → Natural → A foldl' : {A : Set} → (A → A) → A → Natural → A foldr : {A : Set} → (A → A) → A → Natural → A {-# FOREIGN GHC import qualified Data.Natural.AgdaFFI #-} {-# COMPILE GHC Natural = type Data.Natural.AgdaFFI.Natural #-} {-# COMPILE GHC zero = 0 #-} {-# COMPILE GHC suc = succ #-} {-# COMPILE GHC _+_ = (+) #-} {-# COMPILE GHC show = show #-} {-# COMPILE GHC foldl = (\ _ -> Data.Natural.AgdaFFI.nfoldl) #-} {-# COMPILE GHC foldl' = (\ _ -> Data.Natural.AgdaFFI.nfoldl') #-} {-# COMPILE GHC foldr = (\ _ -> Data.Natural.AgdaFFI.nfoldr) #-} private postulate # : ∀ {i} {A : Set i} → A → Natural {-# COMPILE GHC # = (\ _ _ -> Data.Natural.AgdaFFI.convert MAlonzo.Data.Nat.mazNatToInteger) #-} fromℕ : ℕ → Natural fromℕ = #
31.5
96
0.616402
198a0f14dd3e85319ae7eb32dc62844f9c0b795a
1,763
agda
Agda
src/MJ/Examples/Exceptions.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
10
2017-11-17T17:10:36.000Z
2021-09-24T08:02:33.000Z
src/MJ/Examples/Exceptions.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2019-01-13T13:03:47.000Z
2020-10-14T13:41:58.000Z
src/MJ/Examples/Exceptions.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2021-12-28T17:38:05.000Z
2021-12-28T17:38:05.000Z
module MJ.Examples.Exceptions where open import Prelude open import Data.Star import Data.Vec.All as Vec∀ open import Data.List open import Data.List.Any open import Data.List.Membership.Propositional open import Data.List.All hiding (lookup) open import Data.Product hiding (Σ) open import Relation.Binary.PropositionalEquality open import MJ.Examples.Integer open import MJ.Types open import MJ.Classtable open import MJ.Classtable.Code Σ open import MJ.Syntax Σ open import MJ.Syntax.Program Σ open import MJ.Semantics Σ Lib open import MJ.Semantics.Values Σ -- Integer class body caught : Prog int caught = Lib , let x = (here refl) y = (there (here refl)) v = (there (there (here refl))) in body ( loc int ◅ loc (ref INT) ◅ loc (ref INT) ◅ asgn v (num 0) ◅ asgn x (new INT (num 9 ∷ [])) ◅ asgn y (new INT (num 18 ∷ [])) ◅ (try (block ( -- perform a side effect on the heap: writing 18 to x's int field run (call (var x) "set" {_}{void} (var y ∷ [])) -- raise the exception ◅ raise ◅ ε )) catch (block ( -- read the 18 from x's field asgn v (call (var x) "get" []) ◅ ε ))) ◅ ε ) (var v) uncaught : Prog int uncaught = Lib , let x = (here refl) y = (there (here refl)) v = (there (there (here refl))) in body ( loc int ◅ loc (ref INT) ◅ loc (ref INT) ◅ asgn v (num 0) ◅ asgn x (new INT (num 9 ∷ [])) ◅ asgn y (new INT (num 18 ∷ [])) ◅ asgn v (call (var x) "get" []) ◅ raise ◅ ε ) (var v) test : caught ⇓⟨ 100 ⟩ (λ v → v ≡ num 18) test = refl test₂ : uncaught ⇓⟨ 100 ⟩! (λ μ e → e ≡ other) test₂ = refl
22.896104
75
0.567782
d170ddc7711bdb7bae18410019e46be789402e20
3,682
agda
Agda
agda/Itse/Checking.agda
Riib11/itse
4ee714b707b72e4ed8373c49ee739d576aafb70a
[ "BSD-3-Clause" ]
1
2021-04-14T15:09:19.000Z
2021-04-14T15:09:19.000Z
agda/Itse/Checking.agda
Riib11/itse
4ee714b707b72e4ed8373c49ee739d576aafb70a
[ "BSD-3-Clause" ]
null
null
null
agda/Itse/Checking.agda
Riib11/itse
4ee714b707b72e4ed8373c49ee739d576aafb70a
[ "BSD-3-Clause" ]
null
null
null
module Itse.Checking where open import Itse.Grammar open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Data.Unit open import Data.Bool open import Data.List hiding (lookup) open import Data.Product open import Data.Maybe {- # Checking -} {- ## Context -} data Context : Set Closure : Set infixr 6 _⦂_,_ [_],_ data Context where ∅ : Context _⦂_,_ : ∀ {e} → Name e → Expr (TypeOf e) → Context → Context [_],_ : Closure → Context → Context {- ## Closure -} Closure = List (∃[ e ] (Name e × Expr e × Expr (TypeOf e))) lookup-μ : ∀ {e} → Name e → Closure → Maybe (Expr e × Expr (TypeOf e)) lookup-μ {p} ξ [] = nothing lookup-μ {p} ξ ((p , υ , α , A) ∷ μ) with ξ ≟-Name υ lookup-μ {p} ξ ((p , υ , α , A) ∷ μ) | yes refl = just (α , A) lookup-μ {p} ξ ((p , υ , α , A) ∷ μ) | no _ = lookup-μ ξ μ lookup-μ {p} ξ ((t , _) ∷ μ) = lookup-μ ξ μ lookup-μ {t} x [] = nothing lookup-μ {t} x ((p , _) ∷ μ) = lookup-μ x μ lookup-μ {t} x ((t , y , a , α) ∷ μ) with x ≟-Name y lookup-μ {t} x ((t , y , a , α) ∷ μ) | yes refl = just (a , α) lookup-μ {t} x ((t , y , a , α) ∷ μ) | no _ = lookup-μ x μ lookup : ∀ {e} → Name e → Context → Maybe (Expr e × Expr (TypeOf e)) lookup x ∅ = nothing lookup x (_ ⦂ _ , Γ) = lookup x Γ lookup x ([ μ ], Γ) = lookup-μ x μ {- ## Substitution -} infix 6 ⟦_↦_⟧_ ⟦_↦_⟧_ : ∀ {e e′} → Name e → Expr e → Expr e′ → Expr e′ ⟦_↦_⟧_ = {!!} {- ## Wellformed-ness -} infix 5 _⊢wf _⊢_ok _⊢_⦂_ data _⊢wf : Context → Set data _⊢_ok : Context → Closure → Set data _⊢_⦂_ : ∀ {e} → Context → Expr e → Expr (TypeOf e) → Set data _⊢wf where ∅⊢wf : ∅ ⊢wf judgeₚ : ∀ {Γ} {X : Kind} {ξ} → Γ ⊢wf → Γ ⊢ X ⦂ `□ₛ → ---- ξ ⦂ X , Γ ⊢wf judgeₜ : ∀ {Γ} {ξ : Type} {x : Nameₜ} → Γ ⊢wf → Γ ⊢ ξ ⦂ `●ₖ → ---- x ⦂ ξ , Γ ⊢wf closure : ∀ {Γ} {μ} → Γ ⊢wf → Γ ⊢ μ ok → [ μ ], Γ ⊢wf -- Closure = List (∃[ e ] ∃[ e≢k ] (Name e × Expr e × Expr (TypeOf e {e≢k}))) data _⊢_ok where -- type : -- Γ ⊢ μ ok → -- [ μ ], Γ ⊢ data _⊢_⦂_ where -- sorting (well-formed kinds) ●ₖ : ∀ {Γ} → Γ ⊢ `●ₖ ⦂ `□ₛ λₖₚ-intro : ∀ {Γ} {ξ} {X A} → ξ ⦂ X , Γ ⊢ A ⦂ `□ₛ → Γ ⊢ X ⦂ `□ₛ → ---- Γ ⊢ `λₖₚ[ ξ ⦂ X ] A ⦂ `□ₛ λₖₜ-intro : ∀ {Γ} {ξ} {A} {x} → x ⦂ ξ , Γ ⊢ A ⦂ `□ₛ → Γ ⊢ ξ ⦂ `●ₖ → ---- Γ ⊢ `λₖₜ[ x ⦂ ξ ] A ⦂ `□ₛ -- kinding λₚₚ-intro : ∀ {Γ} {X} {β} {ξ} → Γ ⊢ X ⦂ `□ₛ → ξ ⦂ X , Γ ⊢ β ⦂ `●ₖ → ---- Γ ⊢ `λₚₚ[ ξ ⦂ X ] β ⦂ `λₖₚ[ ξ ⦂ X ] `●ₖ λₚₜ-intro : ∀ {Γ} {ξ} {β} {x} → Γ ⊢ ξ ⦂ `●ₖ → x ⦂ ξ , Γ ⊢ β ⦂ `●ₖ → ---- Γ ⊢ `λₚₜ[ x ⦂ ξ ] β ⦂ `λₖₜ[ x ⦂ ξ ] `●ₖ λₚₚ-elim : ∀ {Γ} {A B} {ξ φ α} → Γ ⊢ φ ⦂ `λₖₚ[ ξ ⦂ A ] B → Γ ⊢ α ⦂ A → ---- Γ ⊢ φ `∙ₚₚ α ⦂ B λₚₜ-elim : ∀ {Γ} {B} {φ α} {a} {x} → Γ ⊢ φ ⦂ `λₖₜ[ x ⦂ α ] B → Γ ⊢ a ⦂ α → ---- Γ ⊢ φ `∙ₚₜ a ⦂ B -- typing λₜₚ-intro : ∀ {Γ} {X} {α} {a} {ξ} → Γ ⊢ X ⦂ `□ₛ → ξ ⦂ X , Γ ⊢ a ⦂ α → ---- Γ ⊢ `λₜₚ[ ξ ⦂ X ] a ⦂ `λₚₚ[ ξ ⦂ X ] α λₜₜ-intro : ∀ {Γ} {α ξ} {a} {x} → Γ ⊢ α ⦂ `●ₖ → x ⦂ ξ , Γ ⊢ a ⦂ α → ---- Γ ⊢ `λₜₜ[ x ⦂ ξ ] a ⦂ `λₚₜ[ x ⦂ ξ ] α λₜₚ-elim : ∀ {Γ} {A} {α β} {f} {ξ} → Γ ⊢ f ⦂ `λₚₚ[ ξ ⦂ A ] β → Γ ⊢ α ⦂ A → ---- Γ ⊢ f `∙ₜₚ α ⦂ β λₜₜ-elim : ∀ {Γ} {α β} {f a x} → Γ ⊢ f ⦂ `λₚₜ[ x ⦂ α ] β → Γ ⊢ a ⦂ α → ---- Γ ⊢ f `∙ₜₜ a ⦂ β -- "SelfGen" ι-intro : ∀ {Γ} {α} {a} {x} → Γ ⊢ a ⦂ ⟦ x ↦ a ⟧ α → Γ ⊢ `ι[ x ] α ⦂ `●ₖ → ---- Γ ⊢ a ⦂ `ι[ x ] α -- "SelfInst" ι-elim : ∀ {Γ} {α} {a} {x} → Γ ⊢ a ⦂ `ι[ x ] α → ---- Γ ⊢ a ⦂ ⟦ x ↦ a ⟧ α
19.07772
77
0.400598
a0080d258a51ab759e20cf92131ac1be0cffd94f
1,286
agda
Agda
LibraBFT/Impl/Consensus/Liveness/ExponentialTimeInterval.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/Liveness/ExponentialTimeInterval.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/Liveness/ExponentialTimeInterval.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types open import LibraBFT.Impl.OBM.Rust.Duration as Duration open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Util.Util open import LibraBFT.Prelude open import Optics.All module LibraBFT.Impl.Consensus.Liveness.ExponentialTimeInterval where new : Duration → F64 → Usize → ExponentialTimeInterval new base exponentBase maxExponent = {- TODO-1 if | maxExponent >= 32 -> errorExit [ "ExponentialTimeInterval", "new" , "maxExponent for PacemakerTimeInterval should be < 32", show maxExponent ] | ceiling (exponentBase ** fromIntegral maxExponent) >= {-F64-} (maxBound::Int) -> errorExit [ "ExponentialTimeInterval", "new" , "maximum interval multiplier should be less then u32::Max"] | otherwise -> -} mkExponentialTimeInterval (Duration.asMillis base) exponentBase maxExponent
38.969697
111
0.716174
5299cc1868c0b08308b2341160e3573fc3be2548
610
agda
Agda
Cubical/HITs/FreeGroup/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/HITs/FreeGroup/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/HITs/FreeGroup/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- This file contains: - An implementation of the free group of a type of generators as a HIT -} {-# OPTIONS --safe #-} module Cubical.HITs.FreeGroup.Base where open import Cubical.Foundations.Prelude private variable ℓ : Level data FreeGroup (A : Type ℓ) : Type ℓ where η : A → FreeGroup A _·_ : FreeGroup A → FreeGroup A → FreeGroup A ε : FreeGroup A inv : FreeGroup A → FreeGroup A assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z idr : ∀ x → x ≡ x · ε idl : ∀ x → x ≡ ε · x invr : ∀ x → x · (inv x) ≡ ε invl : ∀ x → (inv x) · x ≡ ε trunc : isSet (FreeGroup A)
21.034483
70
0.57377
4b7d81f09dd91334a9cc3ff1a94d710dff4c07cb
88
agda
Agda
test/epic/Prelude/Bot.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/epic/Prelude/Bot.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/epic/Prelude/Bot.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Prelude.Bot where data Bot : Set where magic : ∀{A : Set} -> Bot -> A magic ()
12.571429
30
0.613636
19c5ecb46e7ca7809000b75cdc9d5005992b2dbb
442
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Equality/Propositional.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Equality/Propositional.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Equality/Propositional.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Equality.Propositional directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Equality.Propositional where open import Data.List.Relation.Binary.Equality.Propositional public
34
72
0.520362
52a82c75a0baeb8af035242f4278f306ad3c7afb
7,288
agda
Agda
Cubical/Categories/TypesOfCategories/TypeCategory.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Categories/TypesOfCategories/TypeCategory.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Categories/TypesOfCategories/TypeCategory.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Categories.TypesOfCategories.TypeCategory where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Data.Sigma import Cubical.Functions.Fibration as Fibration open import Cubical.Categories.Category open import Cubical.Categories.Functor open import Cubical.Categories.Presheaf open import Cubical.Categories.Limits.Pullback open import Cubical.Categories.NaturalTransformation open import Cubical.Categories.Instances.Sets open Fibration.ForSets record isTypeCategory {ℓ ℓ' ℓ''} (C : Category ℓ ℓ') : Type (ℓ-max ℓ (ℓ-max ℓ' (ℓ-suc ℓ''))) where open Category C open Cospan field -- a Type of types over a context Ty[_] : ob → Type ℓ'' -- extend a context with a type cext : ∀ (Γ : _) → (A : Ty[ Γ ]) → Σ[ ΓA ∈ ob ] (C [ ΓA , Γ ]) -- the new object from a context extension _⍮_ : (Γ : _) → (A : Ty[ Γ ]) → ob Γ ⍮ A = fst (cext Γ A) -- the projection from the extended context to the original π : (Γ : _) → (A : Ty[ Γ ]) → C [ Γ ⍮ A , Γ ] π Γ A = snd (cext Γ A) field -- pullback over context extentions reindex : ∀ {Γ' Γ} → C [ Γ' , Γ ] → (Ty[ Γ ] → Ty[ Γ' ]) q⟨_,_⟩ : ∀ {Γ' Γ} → (f : C [ Γ' , Γ ]) → (A : Ty[ Γ ]) → C [ Γ' ⍮ (reindex f A) , Γ ⍮ A ] sq : ∀ {Γ' Γ : ob} (f : C [ Γ' , Γ ]) (A : Ty[ Γ ]) → π Γ' (reindex f A) ⋆ f ≡ q⟨ f , A ⟩ ⋆ π Γ A isPB : ∀ {Γ' Γ : ob} (f : C [ Γ' , Γ ]) (A : Ty[ Γ ]) → isPullback C (cospan Γ' Γ (Γ ⍮ A) f (π Γ A)) (π Γ' (reindex f A)) (q⟨ f , A ⟩) (sq f A) -- presheaves are type contexts module _ {ℓ ℓ' ℓ'' : Level} (C : Category ℓ ℓ') where open isTypeCategory open Category open Functor open NatTrans private isSurjSET : ∀ {ℓ} {A B : SET ℓ .ob} → (f : SET ℓ [ A , B ]) → Type _ isSurjSET {A = A} {B} f = ∀ (b : fst B) → Σ[ a ∈ fst A ] f a ≡ b -- types over Γ are types with a "projection" (aka surjection) to Γ PSTy[_] : PreShv C ℓ'' .ob → Type _ PSTy[ Γ ] = Σ[ ΓA ∈ PreShv C ℓ'' .ob ] Σ[ π ∈ ΓA ⇒ Γ ] (∀ (c : C .ob) → isSurjSET {A = ΓA ⟅ c ⟆} {Γ ⟅ c ⟆} (π ⟦ c ⟧)) -- just directly use types from above as context extensions PSCext : (Γ : _) → PSTy[ Γ ] → Σ[ ΓA ∈ PreShv C ℓ'' .ob ] ΓA ⇒ Γ PSCext Γ (ΓA , π , _) = ΓA , π -- the pullback or reindexed set is the disjoint union of the fibers -- from the projection module _ {Δ Γ : PreShv C ℓ'' .ob} (γ : Δ ⇒ Γ) (A'@(ΓA , π , isSurjπ) : PSTy[ Γ ]) where ΔA : PreShv C ℓ'' .ob ΔA .F-ob c = ΔATy , isSetΔA where ΔATy = (Σ[ x ∈ fst (Δ ⟅ c ⟆) ] fiber (π ⟦ c ⟧) ((γ ⟦ c ⟧) x)) isSetΔA : isSet ΔATy isSetΔA = isOfHLevelΣ 2 (snd (Δ ⟅ c ⟆)) λ Γc → isOfHLevelΣ 2 (snd (ΓA ⟅ c ⟆)) λ ΓAc → isProp→isSet (snd (Γ ⟅ c ⟆) _ _) -- for morphisms, we apply Δ ⟪ f ⟫ to the first component -- and ΓA ⟪ f ⟫ to the second -- the fiber rule ΔA .F-hom {c} {d} f (δax , γax , eq) = ((Δ ⟪ f ⟫) δax) , (((ΓA ⟪ f ⟫) γax) , ((π ⟦ d ⟧) ((ΓA ⟪ f ⟫) γax) ≡[ i ]⟨ π .N-hom f i γax ⟩ (Γ ⟪ f ⟫) ((π ⟦ c ⟧) γax) ≡[ i ]⟨ (Γ ⟪ f ⟫) (eq i) ⟩ (Γ ⟪ f ⟫) ((γ ⟦ c ⟧) δax) ≡[ i ]⟨ γ .N-hom f (~ i) δax ⟩ (γ ⟦ d ⟧) ((Δ ⟪ f ⟫) δax) ∎)) ΔA .F-id {x = c} = funExt λ (δax , γax , eq) → ΣPathP ((λ i → Δ .F-id i δax) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ (λ i → ΓA .F-id i γax)) ΔA .F-seq {a} {b} {c} f g = funExt λ (δax , γax , eq) → ΣPathP ((λ i → Δ .F-seq f g i δax) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ λ i → ΓA .F-seq f g i γax) π' : ΔA ⇒ Δ π' .N-ob c (x , snd) = x π' .N-hom f = refl PSReindex : PSTy[ Δ ] PSReindex = ΔA , (π' , isSurj) where isSurj : ∀ (c : C .ob) → isSurjSET {A = ΔA ⟅ c ⟆} {B = Δ ⟅ c ⟆} (π' ⟦ c ⟧) isSurj c δx = (δx , isSurjπ c ((γ ⟦ c ⟧) δx)) , refl PSq : ΔA ⇒ ΓA PSq .N-ob c (δax , γax , eq) = γax PSq .N-hom {c} {d} f = funExt λ (δax , γax , eq) → refl PSSq : (PreShv C ℓ'' ⋆ snd (PSCext Δ (PSReindex))) γ ≡ (PreShv C ℓ'' ⋆ PSq) (snd (PSCext Γ A')) PSSq = makeNatTransPath (funExt sqExt) where sqExt : ∀ (c : C .ob) → _ sqExt c = funExt λ (δax , γax , eq) → sym eq PSIsPB : isPullback (PreShv C ℓ'') (cospan Δ Γ (fst (PSCext Γ A')) γ (snd (PSCext Γ A'))) (snd (PSCext Δ PSReindex)) PSq PSSq PSIsPB {Θ} p₁ p₂ sq = (α , eq) , unique where α : Θ ⇒ ΔA α .N-ob c t = ((p₁ ⟦ c ⟧) t) , (((p₂ ⟦ c ⟧) t) , (λ i → (sq (~ i) ⟦ c ⟧) t)) α .N-hom {d} {c} f = funExt αHomExt where αHomExt : ∀ (t : fst (Θ ⟅ d ⟆)) → ((p₁ ⟦ c ⟧) ((Θ ⟪ f ⟫) t) , (p₂ ⟦ c ⟧) ((Θ ⟪ f ⟫) t), _) ≡ ((Δ ⟪ f ⟫) ((p₁ ⟦ d ⟧) t) , (ΓA ⟪ f ⟫) ((p₂ ⟦ d ⟧) t) , _) αHomExt t = ΣPathP ((λ i → p₁ .N-hom f i t) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ (λ i → p₂ .N-hom f i t)) eq : _ eq = makeNatTransPath (funExt (λ _ → funExt λ _ → refl)) , makeNatTransPath (funExt (λ _ → funExt λ _ → refl)) unique : ∀ (βeq : Σ[ β ∈ Θ ⇒ ΔA ] _) → (α , eq) ≡ βeq unique (β , eqβ) = ΣPathP (α≡β , eq≡eqβ) where α≡β : α ≡ β α≡β = makeNatTransPath (funExt λ c → funExt λ t → eqExt c t) where eqβ1 = eqβ .fst eqβ2 = eqβ .snd eqExt : ∀ (c : C .ob) → (t : fst (Θ ⟅ c ⟆)) → (α ⟦ c ⟧) t ≡ (β ⟦ c ⟧) t eqExt c t = ΣPathP ((λ i → (eqβ1 i ⟦ c ⟧) t) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ (λ i → (eqβ2 i ⟦ c ⟧) t)) eq≡eqβ : PathP (λ i → (p₁ ≡ (α≡β i) ●ᵛ π') × (p₂ ≡ (α≡β i) ●ᵛ PSq)) eq eqβ eq≡eqβ = ΣPathP ( isPropNatP1 (eq .fst) (eqβ .fst) α≡β , isPropNatP2 (eq .snd) (eqβ .snd) α≡β) where isPropNatP1 : isOfHLevelDep 1 (λ γ → p₁ ≡ γ ●ᵛ π') isPropNatP1 = isOfHLevel→isOfHLevelDep 1 (λ _ → isSetNat _ _) isPropNatP2 : isOfHLevelDep 1 (λ γ → p₂ ≡ γ ●ᵛ PSq) isPropNatP2 = isOfHLevel→isOfHLevelDep 1 (λ _ → isSetNat _ _) -- putting everything together isTypeCategoryPresheaf : isTypeCategory (PreShv C ℓ'') isTypeCategoryPresheaf .Ty[_] Γ = PSTy[ Γ ] isTypeCategoryPresheaf .cext = PSCext isTypeCategoryPresheaf .reindex = PSReindex isTypeCategoryPresheaf .q⟨_,_⟩ = PSq isTypeCategoryPresheaf .sq = PSSq isTypeCategoryPresheaf .isPB = PSIsPB
37.958333
128
0.445252
41c17bad87ababa75a9ce56d69e140ed9e2f6656
184
agda
Agda
Cubical/HITs/SequentialColimit.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/HITs/SequentialColimit.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/HITs/SequentialColimit.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.HITs.SequentialColimit where open import Cubical.HITs.SequentialColimit.Base public open import Cubical.HITs.SequentialColimit.Properties public
30.666667
60
0.826087
199a9bf8d66d8e653ad68937a51f2eeb93ed04f2
959
agda
Agda
archive/agda-1/Membership.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-1/Membership.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-1/Membership.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module Membership where open import OscarPrelude open import Successor record Membership {ℓ} (m : Set ℓ) (M : Set ℓ) : Set (⊹ ℓ) where field _∈_ : m → M → Set ℓ _∉_ : m → M → Set ℓ xor-membership : ∀ {x : m} {X : M} → x ∈ X ←⊗→ x ∉ X open Membership ⦃ … ⦄ public data _∈List_ {ℓ} {A : Set ℓ} (a : A) : List A → Set ℓ where zero : {as : List A} → a ∈List (a ∷ as) suc : {x : A} {as : List A} → a ∈List as → a ∈List (x ∷ as) instance MembershipList : ∀ {ℓ} {A : Set ℓ} → Membership A $ List A Membership._∈_ MembershipList = _∈List_ Membership._∉_ MembershipList x X = ¬ x ∈ X Membership.xor-membership MembershipList = (λ x x₁ → x₁ x) , (λ x x₁ → x x₁) instance SuccessorMembershipList : ∀ {ℓ} {A : Set ℓ} {a : A} {x : A} {as : List A} → Successor (a ∈ as) $ a ∈ (x List.∷ as) Successor.⊹ SuccessorMembershipList = suc _⊆_ : ∀ {ℓ} {m M : Set ℓ} ⦃ _ : Membership m M ⦄ → M → M → Set ℓ _⊆_ {m = m} M₁ M₂ = ∀ {x : m} → x ∈ M₁ → x ∈ M₂
30.935484
123
0.565172
a0175e3274dfe8203a003332c102357b0a3a4a87
775
agda
Agda
test/Succeed/Issue2603.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2603.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2603.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-06-14, issue #2603 -- reported by rfindler, shrunk test case by Ulf -- {-# OPTIONS -v tc.conv:40 -v tc.conv.atom:50 -v tc:80 -v tc.meta.assign:70 #-} {-# OPTIONS --allow-unsolved-metas #-} open import Agda.Builtin.Equality data List (A : Set) : Set where [] : List A postulate Signal : Set data Any (xs : List Signal) : Set where no : Any xs any : ∀ xs → Any xs any [] = no record Env : Set where field sig : List Signal open Env Can : (θ : Env) → Any (sig θ) → Set Can θ no = Signal postulate elephant : ∀ θ → Can θ (any (sig θ)) ≡ Signal lemma2 : Set lemma2 rewrite elephant _ = Signal -- Should succeed. -- This lead to an internal error when the conversion checker -- tried to eta expand a meta variable but dontAssignMetas was on.
20.394737
81
0.661935
21767844e61b004b4cb871a036c3c19cd59f3169
6,559
agda
Agda
Cubical/ZCohomology/Groups/Wedge.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/Wedge.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/Wedge.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-} module Cubical.ZCohomology.Groups.Wedge where open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.Properties open import Cubical.ZCohomology.MayerVietorisUnreduced open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Function open import Cubical.HITs.Wedge open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁) open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2) open import Cubical.Data.Nat open import Cubical.Algebra.Group open import Cubical.ZCohomology.Groups.Unit open import Cubical.ZCohomology.Groups.Sn open import Cubical.HITs.Pushout open import Cubical.Data.Sigma open import Cubical.Foundations.Isomorphism open import Cubical.Homotopy.Connected open import Cubical.HITs.Susp open import Cubical.HITs.S1 open import Cubical.HITs.Sn open import Cubical.Foundations.Equiv module _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') where module I = MV (typ A) (typ B) Unit (λ _ → pt A) (λ _ → pt B) Hⁿ-⋁ : (n : ℕ) → GroupIso (coHomGr (suc n) (A ⋁ B)) (×coHomGr (suc n) (typ A) (typ B)) Hⁿ-⋁ zero = BijectionIsoToGroupIso bijIso where surj-helper : (x : coHom 0 Unit) → isInIm _ _ (I.Δ 0) x surj-helper = sElim (λ _ → isOfHLevelSuc 1 propTruncIsProp) λ f → ∣ (∣ (λ _ → f tt) ∣₂ , 0ₕ 0) , cong ∣_∣₂ (funExt λ _ → -rUnitₖ 0 (f tt)) ∣₁ helper : (x : coHom 1 (A ⋁ B)) → isInIm _ _ (I.d 0) x → x ≡ 0ₕ 1 helper x inim = pRec (setTruncIsSet _ _) (λ p → sym (snd p) ∙ MV.Im-Δ⊂Ker-d _ _ Unit (λ _ → pt A) (λ _ → pt B) 0 (fst p) (surj-helper (fst p))) inim bijIso : BijectionIso (coHomGr 1 (A ⋁ B)) (×coHomGr 1 (typ A) (typ B)) BijectionIso.map' bijIso = I.i 1 BijectionIso.inj bijIso = sElim (λ _ → isSetΠ λ _ → isProp→isSet (setTruncIsSet _ _)) λ f inker → helper ∣ f ∣₂ (I.Ker-i⊂Im-d 0 ∣ f ∣₂ inker) BijectionIso.surj bijIso p = I.Ker-Δ⊂Im-i 1 p (isContr→isProp (isContrHⁿ-Unit 0) _ _) Hⁿ-⋁ (suc n) = Iso+Hom→GrIso mainIso (sElim2 (λ _ _ → isOfHLevelPath 2 (isOfHLevel× 2 setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl) where helpIso : ∀ {ℓ'''} {C : Type ℓ'''} → Iso (A ⋁ B → C) (Σ[ f ∈ (typ A → C) × (typ B → C) ] (fst f) (pt A) ≡ (snd f) (pt B)) Iso.fun helpIso f = ((λ x → f (inl x)) , λ x → f (inr x)) , cong f (push tt) Iso.inv helpIso ((f , g) , p) (inl x) = f x Iso.inv helpIso ((f , g) , p) (inr x) = g x Iso.inv helpIso ((f , g) , p) (push a i) = p i Iso.rightInv helpIso ((f , g) , p) = ΣPathP (ΣPathP (refl , refl) , refl) Iso.leftInv helpIso f = funExt λ {(inl a) → refl ; (inr a) → refl ; (push a i) → refl} mainIso : Iso (coHom (2 + n) (A ⋁ B)) (coHom (2 + n) (typ A) × coHom (2 + n) (typ B)) mainIso = compIso (setTruncIso helpIso) (compIso theIso setTruncOfProdIso) where forget : ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂ → ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂ forget = sMap (λ {((f , g) , _) → f , g}) isEq : (f : ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂) → isContr (fiber forget f) isEq = sElim (λ _ → isOfHLevelSuc 1 isPropIsContr) (uncurry λ f g → helper f g (f (pt A)) (g (pt B)) refl refl) where helper : (f : (typ A → coHomK (2 + n))) (g : (typ B → coHomK (2 + n))) (x y : coHomK (2 + n)) → f (pt A) ≡ x → g (pt B) ≡ y → isContr (fiber forget ∣ f , g ∣₂) helper f g = trElim2 (λ _ _ → isProp→isOfHLevelSuc (3 + n) (isPropΠ2 λ _ _ → isPropIsContr)) (suspToPropElim2 (ptSn (suc n)) (λ _ _ → isPropΠ2 λ _ _ → isPropIsContr) λ p q → (∣ (f , g) , (p ∙ sym q) ∣₂ , refl) , uncurry (sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 (isOfHLevelΣ 2 setTruncIsSet λ _ → isOfHLevelPath 2 setTruncIsSet _ _) _ _) λ { ((f' , g') , id1) y → Σ≡Prop (λ _ → setTruncIsSet _ _) (pRec (setTruncIsSet _ _) (λ id2 → trRec (setTruncIsSet _ _) (λ pathp → cong ∣_∣₂ (ΣPathP ((sym id2) , pathp))) (isConnectedPathP 1 {A = λ i → (fst (id2 (~ i)) (pt A) ≡ snd (id2 (~ i)) (pt B))} (isConnectedPath 2 (isConnectedSubtr 3 n (subst (λ m → isConnected m (coHomK (2 + n))) (+-comm 3 n) (isConnectedKn (suc n)))) _ _) (p ∙ sym q) id1 .fst)) (Iso.fun PathIdTrunc₀Iso y))})) theIso : Iso ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂ ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂ theIso = equivToIso (forget , record { equiv-proof = isEq }) {- Alternative, less direct proof : vSES→GroupIso _ _ (ses (isOfHLevelSuc 0 (isContrHⁿ-Unit n)) (isOfHLevelSuc 0 (isContrHⁿ-Unit (suc n))) (I.d (suc n)) (I.Δ (suc (suc n))) (I.i (suc (suc n))) (I.Ker-i⊂Im-d (suc n)) (I.Ker-Δ⊂Im-i (suc (suc n)))) -} wedgeConnected : ((x : typ A) → ∥ pt A ≡ x ∥) → ((x : typ B) → ∥ pt B ≡ x ∥) → (x : A ⋁ B) → ∥ inl (pt A) ≡ x ∥ wedgeConnected conA conB = PushoutToProp (λ _ → propTruncIsProp) (λ a → pRec propTruncIsProp (λ p → ∣ cong inl p ∣₁) (conA a)) λ b → pRec propTruncIsProp (λ p → ∣ push tt ∙ cong inr p ∣₁) (conB b)
53.325203
154
0.49596
fdf9ff56bb9889c5bc4d75d0cbe4a6b58b6dc88d
471
agda
Agda
test/Succeed/Issue2034.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2034.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2034.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 postulate T : Set C₁ : Set instance I₁ : C₁ C₂ : Nat → Set instance I₂ : ∀ {n} → C₂ n it : {A : Set} {{_ : A}} → A it {{x}} = x postulate f₁ : {{_ : {_ : Nat} → C₁}} → T f₂ : {{_ : ∀ {n} → C₂ n}} → T works₁ : T works₁ = f₁ -- f₁ {{λ _ → I₁}} fails₁ : T fails₁ = f₁ {{it}} -- internal error works₂ : T works₂ = f₂ -- f₂ {{λ n → I₂ {n}}} fails₂ : T fails₂ = f₂ {{it}} -- internal error
14.272727
42
0.490446
58e68ea03ad6bec43c8d3521ca19c2f1279a4e13
342
agda
Agda
agda/BBHeap/Order.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/BBHeap/Order.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/BBHeap/Order.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
module BBHeap.Order {A : Set}(_≤_ : A → A → Set) where open import BBHeap _≤_ open import Bound.Lower A open import Bound.Lower.Order _≤_ open import Data.Nat _≺_ : {b b' : Bound} → BBHeap b → BBHeap b' → Set h ≺ h' = # h <′ # h' data Acc {b' : Bound}(h' : BBHeap b') : Set where acc : (∀ {b} h → (_≺_ {b} {b'} h h') → Acc h) → Acc h'
24.428571
56
0.567251
3443791935b2130ee2a9a73d1aa5ed53f04793fa
2,991
agda
Agda
Cubical/HITs/Ints/IsoInt/Base.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/IsoInt/Base.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/IsoInt/Base.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{- The naive, but incorrect, way to define the integers as a HIT. This file mainly contains a proof that IsoInt ≢ Int, and ends with a demonstration of how the same proof strategy fails for BiInvInt. -} {-# OPTIONS --safe #-} module Cubical.HITs.Ints.IsoInt.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Data.Int open import Cubical.Data.Nat open import Cubical.Data.Empty open import Cubical.Relation.Nullary data IsoInt : Type₀ where zero : IsoInt suc : IsoInt -> IsoInt -- suc is an isomorphism: pred : IsoInt -> IsoInt suc-pred : ∀ z -> suc (pred z) ≡ z pred-suc : ∀ z -> pred (suc z) ≡ z suc-iso : Iso IsoInt IsoInt suc-iso = record { fun = suc ; inv = pred ; rightInv = suc-pred ; leftInv = pred-suc } -- this submodule is adapted from Section 5 of -- http://www.cs.ru.nl/~herman/PUBS/HIT-programming.pdf module NonTrivial where -- these two paths are distinct! p₁ p₂ : Path IsoInt (suc (pred (suc zero))) (suc zero) p₁ i = suc-pred (suc zero) i p₂ i = suc (pred-suc zero i) -- to prove this we map into S¹, sending p₁ to refl and p₂ to loop open import Cubical.HITs.S1 toS¹ : IsoInt → S¹ toS¹ zero = base toS¹ (suc x) = toS¹ x toS¹ (pred x) = toS¹ x toS¹ (suc-pred x i) = refl {x = toS¹ x} i toS¹ (pred-suc x i) = rotLoop (toS¹ x) i p₁≡refl : cong toS¹ p₁ ≡ refl p₁≡refl = refl p₂≡loop : cong toS¹ p₂ ≡ loop p₂≡loop = refl -- this is enough to show that p₁ and p₂ cannot be equal p₁≢p₂ : ¬ (p₁ ≡ p₂) p₁≢p₂ eq = znots 0≡1 where -- using winding numbers, p₁ ≡ p₂ implies 0 ≡ 1 0≡1 : 0 ≡ 1 0≡1 = injPos (cong (winding ∘ cong toS¹) eq) ¬isSet-IsoInt : ¬ (isSet IsoInt) ¬isSet-IsoInt pf = NonTrivial.p₁≢p₂ (pf _ _ NonTrivial.p₁ NonTrivial.p₂) ¬Int≡IsoInt : ¬ (Int ≡ IsoInt) ¬Int≡IsoInt p = ¬isSet-IsoInt (subst isSet p isSetInt) private -- Note: this same proof strategy fails for BiInvInt! open import Cubical.HITs.Ints.BiInvInt hiding (zero; suc; pred; suc-pred; pred-suc) import Cubical.HITs.Ints.BiInvInt as BiI p₁ p₂ : Path BiInvInt (BiI.suc (BiI.pred (BiI.suc BiI.zero))) (BiI.suc BiI.zero) p₁ i = BiI.suc-pred (BiI.suc BiI.zero) i p₂ i = BiI.suc (BiI.pred-suc BiI.zero i) open import Cubical.HITs.S1 toS¹ : BiInvInt → S¹ toS¹ BiI.zero = base toS¹ (BiI.suc x) = toS¹ x toS¹ (BiI.predr x) = toS¹ x toS¹ (BiI.predl x) = toS¹ x toS¹ (BiI.suc-predr x i) = refl {x = toS¹ x} i toS¹ (BiI.predl-suc x i) = rotLoop (toS¹ x) i -- still p₂ maps to loop... p₂≡loop : cong toS¹ p₂ ≡ loop p₂≡loop = refl open import Cubical.Foundations.GroupoidLaws -- ...but now so does p₁! p₁≡loop : cong toS¹ p₁ ≡ loop p₁≡loop = sym (decodeEncode base (cong toS¹ p₁)) ∙ sym (lUnit loop) -- if we use BiI.predr instead of BiI.pred (≡ BiI.predl) in p₁ and p₂, -- both paths in S¹ are refl
26.469027
86
0.65229
34ebc3cea8ee93b271bc4a971c10e4cda200e882
2,033
agda
Agda
theorems/groups/KernelSndImageInl.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/groups/KernelSndImageInl.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/groups/KernelSndImageInl.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT module groups.KernelSndImageInl {i j k} (G : Group i) {H : Group j} {K : Group k} -- the argument [φ-snd], which is intended to be [φ ∘ᴳ ×-snd], -- gives the possibility of making the second part -- (the proof of being a group homomorphism) abstract. (φ : H →ᴳ K) (φ-snd : G ×ᴳ H →ᴳ K) (φ-snd-β : ∀ x → GroupHom.f φ-snd x == GroupHom.f φ (snd x)) (G×H-is-abelian : is-abelian (G ×ᴳ H)) where open import groups.KernelImage φ-snd (×ᴳ-inl {G = G} {H = H}) G×H-is-abelian private module G = Group G module H = Group H Ker-φ-snd-quot-Im-inl : Ker φ ≃ᴳ Ker/Im Ker-φ-snd-quot-Im-inl = to-hom , is-eq to from to-from from-to where to : Ker.El φ → Ker/Im.El to (h , h-in-ker) = q[ (G.ident , h) , lemma ] where abstract lemma = φ-snd-β (G.ident , h) ∙ h-in-ker abstract to-pres-comp : ∀ k₁ k₂ → to (Ker.comp φ k₁ k₂) == Ker/Im.comp (to k₁) (to k₂) to-pres-comp _ _ = ap q[_] $ Ker.El=-out φ-snd $ pair×= (! (G.unit-l G.ident)) idp to-hom : Ker φ →ᴳ Ker/Im to-hom = group-hom to to-pres-comp abstract from' : Ker.El φ-snd → Ker.El φ from' ((g , h) , h-in-ker) = h , ! (φ-snd-β (g , h)) ∙ h-in-ker from-rel : ∀ {gh₁ gh₂} → ker/im-rel gh₁ gh₂ → from' gh₁ == from' gh₂ from-rel {gh₁} {gh₂} = Trunc-rec (Ker.El-is-set φ _ _) (λ{(g , inl-g=h₁h₂⁻¹) → Ker.El=-out φ (H.zero-diff-same (snd (fst gh₁)) (snd (fst gh₂)) (! (snd×= inl-g=h₁h₂⁻¹)))}) from : Ker/Im.El → Ker.El φ from = SetQuot-rec (Ker.El-is-set φ) from' from-rel abstract to-from : ∀ g → to (from g) == g to-from = SetQuot-elim {P = λ g → to (from g) == g} (λ _ → =-preserves-set Ker/Im.El-is-set) (λ{((g , h) , h-in-ker) → quot-rel [ G.inv g , ap2 _,_ (! (G.unit-l (G.inv g))) (! (H.inv-r h)) ]}) (λ _ → prop-has-all-paths-↓ (Ker/Im.El-is-set _ _)) from-to : ∀ g → from (to g) == g from-to _ = Ker.El=-out φ idp
34.457627
87
0.533694
4398784152302987ae759b8b6dd328095140b9af
52,711
agda
Agda
src/classify.agda
mb64/cedille
d0f69cc6fbfb69d7ef83a436b623d612328eb016
[ "MIT" ]
328
2018-09-14T20:06:09.000Z
2022-03-26T10:33:07.000Z
src/classify.agda
mb64/cedille
d0f69cc6fbfb69d7ef83a436b623d612328eb016
[ "MIT" ]
123
2018-09-17T10:53:20.000Z
2022-01-12T03:51:28.000Z
src/classify.agda
mb64/cedille
d0f69cc6fbfb69d7ef83a436b623d612328eb016
[ "MIT" ]
34
2018-09-17T11:51:36.000Z
2022-02-20T18:33:16.000Z
import cedille-options open import general-util module classify (options : cedille-options.options) {mF : Set → Set} ⦃ mFm : monad mF ⦄ (write-to-log : string → mF ⊤) where open import cedille-types open import constants open import conversion (cedille-options.options.disable-conv options) using (conv-term ; conv-t ; conv-tpkd ; hnf ; unfold-head-elab ; inconv ; conv-type ; hanf ; unfold-head ; ctxt-term-def ; ctxt-type-def ; unfold-no-defs ; ctxt-datatype-decl ; ctxt-datatype-undef) open import ctxt open import datatype-util open import elab-util options open import free-vars open import meta-vars options {mF} ⦃ mFm ⦄ open import rename open import resugar open import rewriting open import spans options {mF} ⦃ mFm ⦄ open import subst open import syntax-util open import type-util open import to-string options open import untyped-spans options {mF} ⦃ mFm ⦄ span-error-t : Set span-error-t = (string × 𝕃 tagged-val) {-# TERMINATING #-} check-term : ctxt → ex-tm → (T? : maybe type) → spanM (check-ret T? term) check-type : ctxt → ex-tp → (k? : maybe kind) → spanM (check-ret k? type) check-kind : ctxt → ex-kd → spanM kind check-tpkd : ctxt → ex-tk → spanM tpkd check-args : ctxt → ex-args → params → spanM args check-let : ctxt → ex-def → erased? → posinfo → posinfo → spanM (ctxt × var × tagged-val × (∀ {ed : exprd} → ⟦ ed ⟧ → ⟦ ed ⟧) × (term → term)) check-mu : ctxt → posinfo → posinfo → var → ex-tm → maybe ex-tp → posinfo → ex-cases → posinfo → (T? : maybe type) → spanM (check-ret T? term) check-sigma : ctxt → posinfo → maybe ex-tm → ex-tm → maybe ex-tp → posinfo → ex-cases → posinfo → (T? : maybe type) → spanM (check-ret T? term) get-datatype-info-from-head-type : ctxt → var → 𝕃 tmtp → spanM (span-error-t ⊎ datatype-info) check-sigma-evidence : ctxt → maybe ex-tm → var → 𝕃 tmtp → spanM (span-error-t ⊎ (term × (term → term) × datatype-info)) check-cases : ctxt → ex-cases → (Dₓ : var) → (ctrs : trie type) → renamectxt → (ctr-ps : args) → (drop-as : ℕ) → type → (ctxt → term → type → term) → (ctxt → type → kind → type) → spanM (cases × err-m) check-case : ctxt → ex-case → (earlier : stringset) → (Dₓ : var) → (ctrs : trie (type × params × 𝕃 tmtp)) → renamectxt → (ctr-ps : args) → (drop-as : ℕ) → type → (ctxt → term → type → term) → (ctxt → type → kind → type) → spanM (case × trie (type × params × 𝕃 tmtp)) check-refinement : ctxt → type → kind → spanM (type × 𝕃 tagged-val × err-m) synth-tmtp' : ∀ {b X} → ctxt → if b then ex-tm else ex-tp → (if b then term else type → if b then type else kind → spanM X) → spanM X synth-tmtp' {tt} Γ t f = check-term Γ t nothing >>= uncurry f synth-tmtp' {ff} Γ T f = check-type Γ T nothing >>= uncurry f check-tmtp' : ∀ {b X} → ctxt → if b then ex-tm else ex-tp → if b then type else kind → (if b then term else type → spanM X) → spanM X check-tmtp' {tt} Γ t T f = check-term Γ t (just T) >>= f check-tmtp' {ff} Γ T k f = check-type Γ T (just k) >>= f check-tpkd' : ∀ {b X} → ctxt → if b then ex-kd else ex-tk → (if b then kind else tpkd → spanM X) → spanM X check-tpkd' {tt} Γ k f = check-kind Γ k >>= f check-tpkd' {ff} Γ k f = check-tpkd Γ k >>= f lambda-bound-conv? : ctxt → var → tpkd → tpkd → 𝕃 tagged-val → 𝕃 tagged-val × err-m lambda-bound-conv? Γ x tk tk' ts with conv-tpkd Γ tk tk' ...| tt = ts , nothing ...| ff = (to-string-tag-tk "declared classifier" Γ tk' :: to-string-tag-tk "expected classifier" Γ tk :: ts) , just "The classifier given for a λ-bound variable is not the one we expected" id' = id hnf-of : ∀ {X : Set} {ed} → ctxt → ⟦ ed ⟧ → (⟦ ed ⟧ → X) → X hnf-of Γ t f = f (hnf Γ unfold-head-elab t) -- "⊢" = "\vdash" or "\|-" -- "⇒" = "\r=" -- "⇐" = "\l=" infixr 2 hnf-of id' check-tpkd' check-tmtp' synth-tmtp' syntax synth-tmtp' Γ t (λ t~ → f) = Γ ⊢ t ↝ t~ ⇒ f syntax check-tmtp' Γ t T f = Γ ⊢ t ⇐ T ↝ f syntax check-tpkd' Γ k f = Γ ⊢ k ↝ f syntax id' (λ x → f) = x / f -- Supposed to look like a horizontal bar (as in typing rules) syntax hnf-of Γ t f = Γ ⊢ t =β= f -- t [-]t' check-term Γ (ExApp t e t') Tₑ? = check-term-spine Γ (ExApp t e t') (proto-maybe Tₑ?) tt on-fail return-when (Hole (term-start-pos t)) (TpHole (term-start-pos t)) >>=m (uncurry return-when ∘ check-term-spine-elim Γ) where open import type-inf options {mF} check-term check-type -- t ·T check-term Γ (ExAppTp tₕ Tₐ) Tₑ? = -- "Γ ⊢ tₕ ↝ tₕ~ ⇒ Tₕ~ /" desugars to "synth-tmtp' Γ tₕ λ tₕ~ Tₕ~ →" Γ ⊢ tₕ ↝ tₕ~ ⇒ Tₕ~ / Γ ⊢ Tₕ~ =β= λ where (TpAbs tt x (Tkk kₐ) Tᵣ) → Γ ⊢ Tₐ ⇐ kₐ ↝ Tₐ~ / let Tᵣ = [ Γ - Tₐ~ / x ] Tᵣ in [- AppTp-span tt (term-start-pos tₕ) (type-end-pos Tₐ) (maybe-to-checking Tₑ?) (head-type Γ Tₕ~ :: type-data Γ Tᵣ :: expected-type-if Γ Tₑ?) (check-for-type-mismatch-if Γ "synthesized" Tₑ? Tᵣ) -] return-when (AppTp tₕ~ Tₐ~) Tᵣ Tₕ'~ → untyped-type Γ Tₐ >>= λ Tₐ~ → [- AppTp-span tt (term-start-pos tₕ) (type-end-pos Tₐ) (maybe-to-checking Tₑ?) (head-type Γ Tₕ'~ :: arg-type Γ Tₐ~ :: expected-type-if Γ Tₑ?) (unless (is-hole Tₕ'~) ("The type synthesized from the head does not allow it to be applied" ^ " to a type argument")) -] return-when (AppTp tₕ~ Tₐ~) (TpHole (term-start-pos tₕ)) -- β[<t?>][{t?'}] check-term Γ (ExBeta pi t? t?') Tₑ? = maybe-map (λ {(PosTm t _) → untyped-term Γ t}) t? >>=? λ t?~ → maybe-map (λ {(PosTm t _) → untyped-term Γ t}) t?' >>=? λ t?'~ → let t'~ = maybe-else' t?'~ id-term id e-t~ = maybe-else' Tₑ? (maybe-else' t?~ (inj₁ ([] , "When synthesizing, specify what equality to prove with β<...>")) (λ t → inj₂ (t , nothing))) λ Tₑ → Γ ⊢ Tₑ =β= (λ where (TpEq t₁ t₂) → if conv-term Γ t₁ t₂ then maybe-else' (t?~ >>= λ t~ → check-for-type-mismatch Γ "computed" (TpEq t~ t~) (TpEq t₁ t₂) >>= λ e → just (e , t~)) (inj₂ (t₁ , just t₂)) (uncurry λ e t~ → inj₁ ([ type-data Γ (TpEq t~ t~) ] , e)) else inj₁ ([] , "The two terms in the equation are not β-equal") Tₕ → inj₁ ([] , "The expected type is not an equation")) e? = either-else' e-t~ (map-snd just) λ _ → [] , nothing fₓ = fresh-var Γ "x" t~T~ = either-else' e-t~ (λ _ → Hole pi , TpEq (Hole pi) (Hole pi)) $ uncurry λ t₁ → maybe-else (Beta t₁ t'~ , TpEq t₁ t₁) λ t₂ → (Beta t₁ t'~) , TpEq t₁ t₂ in [- uncurry (λ tvs → Beta-span pi (term-end-pos (ExBeta pi t? t?')) (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ? ++ tvs)) e? -] uncurry return-when t~T~ -- χ [T?] - t check-term Γ (ExChi pi T? t) Tₑ? = (maybe-else' T? (check-term Γ t nothing) λ T → Γ ⊢ T ⇐ KdStar ↝ T~ / Γ ⊢ t ⇐ T~ ↝ t~ / return2 t~ T~ ) >>= uncurry λ t~ T~ → [- Chi-span Γ pi (just T~) t (maybe-to-checking Tₑ?) (type-data Γ T~ :: expected-type-if Γ Tₑ?) (check-for-type-mismatch-if Γ (maybe-else' T? "synthesized" (const "computed")) Tₑ? T~) -] return-when t~ T~ -- δ [T?] - t check-term Γ (ExDelta pi T? t) Tₑ? = Γ ⊢ t ↝ t~ ⇒ Tcontra / maybe-else' T? (return (maybe-else' Tₑ? (TpAbs Erased "X" (Tkk KdStar) (TpVar "X")) id)) (λ T → Γ ⊢ T ⇐ KdStar ↝ return) >>= λ T~' → let b = Γ ⊢ Tcontra =β= λ {(TpEq t₁ t₂) → when (inconv Γ t₁ t₂) (t₁ , t₂); _ → nothing} b? = unless (conv-type Γ Tcontra (TpEq tt-term ff-term)) triv >> b in [- Delta-span pi t (maybe-to-checking Tₑ?) (to-string-tag "the contradiction" Γ Tcontra :: type-data Γ T~' :: expected-type-if Γ Tₑ?) (maybe-not b >> just "We could not find a contradiction in the synthesized type of the subterm") -] return-when (Delta b? T~' t~) T~' -- ε[lr][-?] t check-term Γ (ExEpsilon pi lr -? t) Tₑ? = let hnf-from = if -? then hanf Γ tt else hnf Γ unfold-head update-eq : term → term → type update-eq = λ t₁ t₂ → uncurry TpEq $ maybe-else' lr (hnf-from t₁ , hnf-from t₂) λ lr → if lr then (t₁ , hnf-from t₂) else (hnf-from t₁ , t₂) in case-ret {m = Tₑ?} (Γ ⊢ t ↝ t~ ⇒ T~ / Γ ⊢ T~ =β= λ where (TpEq t₁ t₂) → let Tᵣ = update-eq t₁ t₂ in [- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?) [ type-data Γ Tᵣ ] nothing -] return2 t~ Tᵣ Tₕ → [- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?) [ to-string-tag "synthesized type" Γ Tₕ ] (unless (is-hole Tₕ) "The synthesized type of the body is not an equation") -] return2 t~ Tₕ) λ Tₑ → Γ ⊢ Tₑ =β= λ where (TpEq t₁ t₂) → [- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?) [ expected-type Γ (TpEq t₁ t₂) ] nothing -] Γ ⊢ t ⇐ update-eq t₁ t₂ ↝ return Tₕ → [- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?) [ expected-type Γ Tₕ ] (unless (is-hole Tₕ) "The expected type is not an equation") -] untyped-term Γ t -- ● check-term Γ (ExHole pi) Tₑ? = [- hole-span Γ pi Tₑ? (maybe-to-checking Tₑ?) [] -] return-when (Hole pi) (TpHole pi) -- [ t₁ , t₂ [@ Tₘ,?] ] check-term Γ (ExIotaPair pi t₁ t₂ Tₘ? pi') Tₑ? = maybe-else' {B = spanM (err-m × 𝕃 tagged-val × term × term × term × type)} Tₑ? (maybe-else' Tₘ? (untyped-term Γ t₁ >>= λ t₁~ → untyped-term Γ t₂ >>= λ t₂~ → return (just "Iota pairs require a specified type when synthesizing" , [] , t₁~ , t₁~ , t₂~ , TpHole pi)) λ {(ExGuide pi'' x T₂) → Γ ⊢ t₁ ↝ t₁~ ⇒ T₁~ / (Γ , pi'' - x :` Tkt T₁~) ⊢ T₂ ⇐ KdStar ↝ T₂~ / Γ ⊢ t₂ ⇐ [ Γ - t₁~ / (pi'' % x) ] T₂~ ↝ t₂~ / let T₂~ = [ Γ - Var x / (pi'' % x) ] T₂~ bd = binder-data Γ pi'' x (Tkt T₁~) ff nothing (type-start-pos T₂) (type-end-pos T₂) in [- Var-span Γ pi'' x checking [ type-data Γ T₁~ ] nothing -] return (nothing , (type-data Γ (TpIota x T₁~ T₂~) :: [ bd ]) , IotaPair t₁~ t₂~ x T₂~ , t₁~ , t₂~ , TpIota x T₁~ T₂~)}) (λ Tₑ → Γ ⊢ Tₑ =β= λ where (TpIota x T₁ T₂) → Γ ⊢ t₁ ⇐ T₁ ↝ t₁~ / maybe-else' Tₘ? (Γ ⊢ t₂ ⇐ [ Γ - t₁~ / x ] T₂ ↝ t₂~ / return (nothing , (type-data Γ (TpIota x T₁ T₂) :: [ expected-type Γ Tₑ ]) , IotaPair t₁~ t₂~ x T₂ , t₁~ , t₂~ , TpIota x T₁ T₂)) λ {(ExGuide pi'' x' Tₘ) → (Γ , pi'' - x' :` Tkt T₁) ⊢ Tₘ ⇐ KdStar ↝ Tₘ~ / let Tₘ~ = [ Γ - Var x' / (pi'' % x') ] Tₘ~ T₂ = [ Γ - Var x' / x ] T₂ Tₛ = TpIota x' T₁ Tₘ~ in Γ ⊢ t₂ ⇐ [ Γ - t₁~ / x' ] Tₘ~ ↝ t₂~ / [- Var-span Γ pi'' x checking [ type-data Γ T₁ ] nothing -] return (check-for-type-mismatch Γ "computed" Tₘ~ T₂ , (type-data Γ Tₛ :: expected-type Γ (TpIota x' T₁ T₂) :: [ binder-data Γ pi'' x' (Tkt T₁) ff nothing (type-start-pos Tₘ) (type-end-pos Tₘ) ]) , IotaPair t₁~ t₂~ x' Tₘ~ , t₁~ , t₂~ , Tₛ)} Tₕ → untyped-term Γ t₁ >>= λ t₁~ → untyped-term Γ t₂ >>= λ t₂~ → return (unless (is-hole Tₕ) "The expected type is not an iota-type" , [ expected-type Γ Tₕ ] , t₁~ , t₁~ , t₂~ , Tₕ)) >>= λ where (err? , tvs , t~ , t₁~ , t₂~ , T~) → let conv-e = "The two components of the iota-pair are not convertible (as required)" conv-e? = unless (conv-term Γ t₁~ t₂~) conv-e conv-tvs = maybe-else' conv-e? [] λ _ → to-string-tag "hnf of the first component" Γ (hnf Γ unfold-head t₁~) :: [ to-string-tag "hnf of the second component" Γ (hnf Γ unfold-head t₂~) ] in [- IotaPair-span pi pi' (maybe-to-checking Tₑ?) (conv-tvs ++ tvs) (conv-e? ||-maybe err?) -] return-when t~ T~ -- t.(1 / 2) check-term Γ (ExIotaProj t n pi) Tₑ? = Γ ⊢ t ↝ t~ ⇒ T~ / let n? = case n of λ {"1" → just ι1; "2" → just ι2; _ → nothing} in maybe-else' n? ([- IotaProj-span t pi (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ?) (just "Iota-projections must use .1 or .2 only") -] return-when t~ (TpHole pi)) λ n → Γ ⊢ T~ =β= λ where (TpIota x T₁ T₂) → let Tᵣ = if n iff ι1 then T₁ else ([ Γ - t~ / x ] T₂) in [- IotaProj-span t pi (maybe-to-checking Tₑ?) (type-data Γ Tᵣ :: expected-type-if Γ Tₑ?) (check-for-type-mismatch-if Γ "synthesized" Tₑ? Tᵣ) -] return-when (IotaProj t~ n) Tᵣ Tₕ~ → [- IotaProj-span t pi (maybe-to-checking Tₑ?) (head-type Γ Tₕ~ :: expected-type-if Γ Tₑ?) (unless (is-hole Tₕ~) "The synthesized type of the head is not an iota-type") -] return-when (IotaProj t~ n) (TpHole pi) -- λ/Λ x [: T?]. t check-term Γ (ExLam pi e pi' x tk? t) Tₑ? = [- punctuation-span "Lambda" pi (posinfo-plus pi 1) -] let erase-err : (exp act : erased?) → tpkd → term → err-m × 𝕃 tagged-val erase-err = λ where Erased NotErased tk t → just ("The expected type is a ∀-abstraction (implicit input), " ^ "but the term is a λ-abstraction (explicit input)") , [] NotErased Erased tk t → just ("The expected type is a Π-abstraction (explicit input), " ^ "but the term is a Λ-abstraction (implicit input)") , [] Erased Erased tk t → maybe-else (nothing , []) (λ e-tv → just (fst e-tv) , [ snd e-tv ]) (trie-lookup (free-vars (erase t)) x >> just ("The Λ-bound variable occurs free in the erasure of the body" , erasure Γ t)) NotErased NotErased (Tkk _) t → just "λ-terms must bind a term, not a type (use Λ instead)" , [] NotErased NotErased (Tkt _) t → nothing , [] in case-ret {m = Tₑ?} (maybe-else' tk? (untyped-term (Γ , pi' - x :` Tkt (TpHole pi')) t >>= λ t~ → [- Lam-span Γ synthesizing pi pi' e x (Tkt (TpHole pi')) t [] (just ("We are not checking this abstraction against a type, " ^ "so a classifier must be given for the bound variable " ^ x)) -] return2 (Lam e x nothing (rename-var Γ (pi' % x) x t~)) (TpHole pi')) λ tk → Γ ⊢ tk ↝ tk~ / (Γ , pi' - x :` tk~) ⊢ t ↝ t~ ⇒ T~ / let T~ = rename-var Γ (pi' % x) x T~ t~ = rename-var Γ (pi' % x) x t~ Tᵣ = TpAbs e x tk~ T~ in [- var-span e (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -] [- uncurry (λ tvs → Lam-span Γ synthesizing pi pi' e x tk~ t (type-data Γ Tᵣ :: tvs)) (twist-× (erase-err e e tk~ t~)) -] return2 (Lam e x (just tk~) t~) Tᵣ) λ Tₑ → Γ ⊢ Tₑ =β= λ where (TpAbs e' x' tk T) → maybe-map (check-tpkd Γ) tk? >>=? tk~? / let tk~ = maybe-else' tk~? tk id in --maybe-else' tk? (return tk) (λ tk → Γ ⊢ tk ↝ return) >>= tk~ / (Γ , pi' - x :` tk~) ⊢ t ⇐ rename-var Γ x' (pi' % x) T ↝ t~ / let xₙ = if x =string ignored-var && is-free-in x' T then x' else x t~ = rename-var Γ (pi' % x) xₙ t~ T = rename-var Γ x' xₙ T Tₛ = TpAbs e xₙ tk~ T Tₑ = TpAbs e' xₙ tk T vₑ = check-for-tpkd-mismatch-if Γ "computed" tk~? tk in [- var-span e (Γ , pi' - x :` tk~) pi' x (maybe-to-checking tk?) tk~ nothing -] [- uncurry (λ err tvs → Lam-span Γ checking pi pi' e x tk~ t (type-data Γ Tₛ :: expected-type Γ Tₑ :: tvs) (err ||-maybe vₑ)) (erase-err e' e tk~ t~) -] return (Lam e xₙ (just tk~) t~) Tₕ → maybe-else' tk? (return (Tkt (TpHole pi'))) (check-tpkd Γ) >>= tk~ / untyped-term (Γ , pi' - x :` tk~) t >>= t~ / [- Lam-span Γ checking pi pi' e x (Tkt (TpHole pi')) t [ expected-type Γ Tₕ ] (just "The expected type is not a ∀- or a Π-type") -] return (Lam e x (unless (is-hole -tk' tk~) tk~) (rename-var Γ (pi' % x) x t~)) -- [d] - t check-term Γ (ExLet pi e? d t) Tₑ? = check-let Γ d e? (term-start-pos t) (term-end-pos t) >>= λ where (Γ' , x , tv , σ , f) → case-ret-body {m = Tₑ?} (check-term Γ' t Tₑ?) λ t~ T~ → [- punctuation-span "Parens (let)" pi (term-end-pos t) -] [- Let-span e? pi (term-end-pos t) (maybe-to-checking Tₑ?) (maybe-else' Tₑ? (type-data Γ T~) (expected-type Γ) :: [ tv ]) (when (e? && is-free-in x (erase t~)) (unqual-local x ^ "occurs free in the body of the term")) -] return-when (f t~) (σ T~) -- open/close x - t check-term Γ (ExOpen pi o pi' x t) Tₑ? = let Γ? = ctxt-clarify-def Γ o x e? = maybe-not Γ? >> just (x ^ " does not have a definition that can be " ^ (if o then "opened" else "closed")) in [- Var-span Γ pi' x (maybe-to-checking Tₑ?) [ not-for-navigation ] nothing -] [- Open-span o pi x t (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ?) e? -] check-term (maybe-else' Γ? Γ id) t Tₑ? -- (t) check-term Γ (ExParens pi t pi') Tₑ? = [- punctuation-span "Parens (term)" pi pi' -] check-term Γ t Tₑ? -- φ t₌ - t₁ {t₂} check-term Γ (ExPhi pi t₌ t₁ t₂ pi') Tₑ? = case-ret-body {m = Tₑ?} (check-term Γ t₁ Tₑ?) λ t₁~ T~ → untyped-term Γ t₂ >>= λ t₂~ → Γ ⊢ t₌ ⇐ TpEq t₁~ t₂~ ↝ t₌~ / [- Phi-span pi pi' (maybe-to-checking Tₑ?) [ maybe-else' Tₑ? (type-data Γ T~) (expected-type Γ)] nothing -] return-when (Phi t₌~ t₁~ t₂~) T~ -- ρ[+]<ns> t₌ [@ Tₘ?] - t check-term Γ (ExRho pi ρ+ <ns> t₌ Tₘ? t) Tₑ? = Γ ⊢ t₌ ↝ t₌~ ⇒ T₌ / Γ ⊢ T₌ =β= λ where (TpEq t₁ t₂) → let tₗ = if isJust Tₑ? then t₁ else t₂ tᵣ = if isJust Tₑ? then t₂ else t₁ tvs = λ T~ Tᵣ → to-string-tag "equation" Γ (TpEq t₁ t₂) :: maybe-else' Tₑ? (to-string-tag "type of second subterm" Γ T~) (expected-type Γ) :: [ to-string-tag "rewritten type" Γ Tᵣ ] in maybe-else' Tₘ? (elim-pair (optNums-to-stringset <ns>) λ ns ns-e? → let x = fresh-var Γ "x" Γ' = ctxt-var-decl x Γ T-f = λ T → rewrite-type T Γ' ρ+ ns (just t₌~) tₗ x 0 Tᵣ-f = fst ∘ T-f nn-f = snd ∘ T-f Tₚ-f = map-fst (post-rewrite Γ' x t₌~ tᵣ) ∘ T-f in maybe-else' Tₑ? (Γ ⊢ t ↝ t~ ⇒ T~ / return2 t~ T~) (λ Tₑ → Γ ⊢ t ⇐ fst (Tₚ-f Tₑ) ↝ t~ / return2 t~ Tₑ) >>=c λ t~ T~ → elim-pair (Tₚ-f T~) λ Tₚ nn → [- Rho-span pi t₌ t (maybe-to-checking Tₑ?) ρ+ (inj₁ (fst nn)) (tvs T~ Tₚ) (ns-e? (snd nn)) -] return-when (Rho t₌~ x (erase (Tᵣ-f T~)) t~) Tₚ) λ where (ExGuide pi' x Tₘ) → [- Var-span Γ pi' x untyped [] nothing -] let Γ' = Γ , pi' - x :` Tkt (TpHole pi') in untyped-type Γ' Tₘ >>= λ Tₘ~ → let Tₘ~ = [ Γ' - Var x / (pi' % x) ] Tₘ~ T' = [ Γ' - tₗ / x ] Tₘ~ T'' = post-rewrite Γ' x t₌~ tᵣ (rewrite-at Γ' x (just t₌~) tt T' Tₘ~) check-str = if isJust Tₑ? then "computed" else "synthesized" in maybe-else' Tₑ? (check-term Γ t nothing) (λ Tₑ → Γ ⊢ t ⇐ T'' ↝ t~ / return2 t~ Tₑ) >>=c λ t~ T~ → [- Rho-span pi t₌ t (maybe-to-checking Tₑ?) ρ+ (inj₂ x) (tvs T~ T'') (check-for-type-mismatch Γ check-str T' T~) -] return-when (Rho t₌~ x Tₘ~ t~) T'' Tₕ → Γ ⊢ t ↝ t~ ⇒ λ T~ → [- Rho-span pi t₌ t (maybe-to-checking Tₑ?) ρ+ (inj₁ 1) (to-string-tag "type of first subterm" Γ Tₕ :: [ to-string-tag "type of second subterm" Γ T~ ]) (unless (is-hole Tₕ) "We could not synthesize an equation from the first subterm") -] return-when t~ T~ -- ς t check-term Γ (ExVarSigma pi t) Tₑ? = case-ret (Γ ⊢ t ↝ t~ ⇒ T / Γ ⊢ T =β= λ where (TpEq t₁ t₂) → [- VarSigma-span pi t synthesizing [ type-data Γ (TpEq t₂ t₁) ] nothing -] return2 (VarSigma t~) (TpEq t₂ t₁) Tₕ → [- VarSigma-span pi t synthesizing [ type-data Γ Tₕ ] (unless (is-hole Tₕ) "The synthesized type of the body is not an equation") -] return2 (VarSigma t~) Tₕ) λ Tₑ → Γ ⊢ Tₑ =β= λ where (TpEq t₁ t₂) → Γ ⊢ t ⇐ TpEq t₂ t₁ ↝ t~ / [- VarSigma-span pi t checking [ expected-type Γ (TpEq t₁ t₂) ] nothing -] return (VarSigma t~) Tₕ → [- VarSigma-span pi t checking [ expected-type Γ Tₕ ] (unless (is-hole Tₕ) "The expected type is not an equation") -] untyped-term Γ t -- θ t ts check-term Γ (ExTheta pi θ t ts) Tₑ? = case-ret {m = Tₑ?} ([- Theta-span Γ pi θ t ts synthesizing [] (just "Theta-terms can only be used when checking (and we are synthesizing here)") -] return2 (Hole pi) (TpHole pi)) λ Tₑ → Γ ⊢ t ↝ t~ ⇒ T / let x = case hnf Γ unfold-head t~ of λ {(Var x) → x; _ → "x"} x' = fresh-var Γ x in Γ ⊢ T =β= λ where (TpAbs me x (Tkk kd) tp) → (case θ of λ where (AbstractVars vs) → either-else' (wrap-vars vs Tₑ) (return2 (TpHole pi) ∘ just) λ Tₘ → return2 Tₘ nothing Abstract → return2 (TpLam x' (Tkt T) (rename-var Γ x x' Tₑ)) nothing AbstractEq → return2 (TpLam x' (Tkt T) (TpAbs Erased ignored-var (Tkt (TpEq t~ (Var x'))) (rename-var Γ x x' Tₑ))) nothing) >>=c λ Tₘ e₁ → check-refinement Γ Tₘ kd >>=c λ Tₘ → uncurry λ tvs e₂ → let tp' = [ Γ - Tₘ / x ] tp in check-lterms ts (AppTp t~ Tₘ) tp' >>=c λ t~ T~ → let e₃ = check-for-type-mismatch Γ "synthesized" T~ Tₑ t~ = case θ of λ {AbstractEq → AppEr t~ (Beta (erase t~) id-term); _ → t~} in [- Theta-span Γ pi θ t ts checking (type-data Γ T~ :: expected-type Γ Tₑ :: tvs) (e₁ ||-maybe (e₂ ||-maybe e₃)) -] return t~ Tₕ → [- Theta-span Γ pi θ t ts checking (head-type Γ Tₕ :: expected-type Γ Tₑ :: []) (unless (is-hole Tₕ) "The synthesized type of the head is not a type-forall") -] return (Hole pi) where check-lterms : 𝕃 lterm → term → type → spanM (term × type) check-lterms [] tm tp = return2 tm tp check-lterms (Lterm me t :: ts) tm tp = Γ ⊢ tp =β= λ where (TpAbs me' x (Tkt T) T') → Γ ⊢ t ⇐ T ↝ t~ / (if me iff me' then return triv else spanM-add (Theta-span Γ pi θ t [] checking [] (just "Mismatched erasure of theta arg"))) >> check-lterms ts (if me then AppEr tm t~ else App tm t~) ([ Γ - t~ / x ] T') Tₕ → (if is-hole Tₕ then id else [- Theta-span Γ pi θ t [] checking [ expected-type Γ Tₕ ] (just "The expected type is not an arrow type") -]_) (untyped-term Γ t >>= λ t~ → check-lterms ts (if me then AppEr tm t~ else App tm t~) Tₕ) var-not-in-scope : var → string var-not-in-scope x = "We could not compute a motive from the given term because " ^ "the abstracted variable " ^ x ^ " is not in scope" wrap-var : var → type → string ⊎ type wrap-var x T = let x' = fresh-var Γ x in maybe-else' (ctxt-lookup-tpkd-var Γ x) (inj₁ (var-not-in-scope x)) λ {(qx , as , tk) → inj₂ (TpLam x' tk (rename-var Γ qx x' T))} wrap-vars : 𝕃 var → type → var ⊎ type wrap-vars [] T = inj₂ T wrap-vars (x :: xs) T = wrap-vars xs T >>= wrap-var x motive : var → var → type → type → theta → term → type motive x x' T T' Abstract t = TpLam x' (Tkt T') (rename-var Γ x x' T) motive x x' T T' AbstractEq t = TpLam x' (Tkt T') (TpAbs Erased ignored-var (Tkt (TpEq t (Var x'))) (rename-var Γ x x' T)) motive x x' T T' (AbstractVars vs) t = T -- Shouldn't happen -- μ(' / rec.) t [@ Tₘ?] {ms...} check-term Γ (ExMu pi1 pi2 x t Tₘ? pi' ms pi'') Tₑ? = check-mu Γ pi1 pi2 x t Tₘ? pi' ms pi'' Tₑ? check-term Γ (ExSigma pi t? t Tₘ? pi' ms pi'') Tₑ? = check-sigma Γ pi t? t Tₘ? pi' ms pi'' Tₑ? -- x check-term Γ (ExVar pi x) Tₑ? = maybe-else' (ctxt-lookup-term-var Γ x) ([- Var-span Γ pi x (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ?) (just "Missing a type for a term variable") -] return-when (Var x) (TpHole pi)) λ {(qx , as , T) → [- Var-span Γ pi x (maybe-to-checking Tₑ?) (type-data Γ T :: expected-type-if Γ Tₑ?) (check-for-type-mismatch-if Γ "computed" Tₑ? T) -] return-when (apps-term (Var qx) as) T} -- ∀/Π x : tk. T check-type Γ (ExTpAbs pi e pi' x tk T) kₑ? = Γ ⊢ tk ↝ tk~ / (Γ , pi' - x :` tk~) ⊢ T ⇐ KdStar ↝ T~ / let T~ = rename-var Γ (pi' % x) x T~ in [- punctuation-span "Forall" pi (posinfo-plus pi 1) -] [- var-span ff (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -] [- TpQuant-span Γ e pi pi' x tk~ T (maybe-to-checking kₑ?) (kind-data Γ KdStar :: expected-kind-if Γ kₑ?) (check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -] return-when (TpAbs e x tk~ T~) KdStar -- ι x : T₁. T₂ check-type Γ (ExTpIota pi pi' x T₁ T₂) kₑ? = Γ ⊢ T₁ ⇐ KdStar ↝ T₁~ / (Γ , pi' - x :` Tkt T₁~) ⊢ T₂ ⇐ KdStar ↝ T₂~ / let T₂~ = rename-var Γ (pi' % x) x T₂~ in [- punctuation-span "Iota" pi (posinfo-plus pi 1) -] [- Var-span (Γ , pi' - x :` Tkt T₁~) pi' x checking [ type-data Γ T₁~ ] nothing -] [- Iota-span Γ pi pi' x T₁~ T₂ (maybe-to-checking kₑ?) (kind-data Γ KdStar :: expected-kind-if Γ kₑ?) (check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -] return-when (TpIota x T₁~ T₂~) KdStar -- {^ T ^} (generated by theta) check-type Γ (ExTpNoSpans T pi) kₑ? = check-type Γ T kₑ? >>=spand return -- [d] - T check-type Γ (ExTpLet pi d T) kₑ? = check-let Γ d ff (type-start-pos T) (type-end-pos T) >>= λ where (Γ' , x , tv , σ , f) → case-ret-body {m = kₑ?} (check-type Γ' T kₑ?) λ T~ k~ → [- punctuation-span "Parens (let)" pi (type-end-pos T) -] [- TpLet-span pi (type-end-pos T) (maybe-to-checking kₑ?) (maybe-else' kₑ? (kind-data Γ k~) (expected-kind Γ) :: [ tv ]) -] return-when (σ T~) (σ k~) -- T · T' check-type Γ (ExTpApp T T') kₑ? = Γ ⊢ T ↝ T~ ⇒ kₕ / Γ ⊢ kₕ =β= λ where (KdAbs x (Tkk dom) cod) → Γ ⊢ T' ⇐ dom ↝ T'~ / let cod' = [ Γ - T'~ / x ] cod in [- TpApp-span (type-start-pos T) (type-end-pos T') (maybe-to-checking kₑ?) (kind-data Γ cod' :: expected-kind-if Γ kₑ?) (check-for-kind-mismatch-if Γ "synthesized" kₑ? cod') -] return-when (TpAppTp T~ T'~) cod' kₕ' → untyped-type Γ T' >>= T'~ / [- TpApp-span (type-start-pos T) (type-end-pos T') (maybe-to-checking kₑ?) (head-kind Γ kₕ' :: expected-kind-if Γ kₑ?) (unless (is-hole kₕ') $ "The synthesized kind of the head does not allow it to be applied" ^ " to a type argument") -] return-when (TpAppTp T~ T'~) (KdHole (type-start-pos T)) -- T t check-type Γ (ExTpAppt T t) kₑ? = Γ ⊢ T ↝ T~ ⇒ kₕ / Γ ⊢ kₕ =β= λ where (KdAbs x (Tkt dom) cod) → Γ ⊢ t ⇐ dom ↝ t~ / let cod' = [ Γ - t~ / x ] cod in [- TpAppt-span (type-start-pos T) (term-end-pos t) (maybe-to-checking kₑ?) (kind-data Γ cod' :: expected-kind-if Γ kₑ?) (check-for-kind-mismatch-if Γ "synthesized" kₑ? cod') -] return-when (TpAppTm T~ t~) cod' kₕ' → untyped-term Γ t >>= t~ / [- TpAppt-span (type-start-pos T) (term-end-pos t) (maybe-to-checking kₑ?) (head-kind Γ kₕ' :: expected-kind-if Γ kₑ?) (unless (is-hole kₕ') $ "The synthesized kind of the head does not allow it to be applied" ^ " to a term argument") -] return-when (TpAppTm T~ t~) (KdHole (type-start-pos T)) -- T ➔/➾ T' check-type Γ (ExTpArrow T e T') kₑ? = Γ ⊢ T ⇐ KdStar ↝ T~ / Γ ⊢ T' ⇐ KdStar ↝ T'~ / [- TpArrow-span T T' (maybe-to-checking kₑ?) (kind-data Γ KdStar :: expected-kind-if Γ kₑ?) (check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -] return-when (TpAbs e ignored-var (Tkt T~) T'~) KdStar -- { t₁ ≃ t₂ } check-type Γ (ExTpEq pi t₁ t₂ pi') kₑ? = untyped-term Γ t₁ >>= t₁~ / untyped-term Γ t₂ >>= t₂~ / [- punctuation-span "Parens (equation)" pi pi' -] [- TpEq-span pi pi' (maybe-to-checking kₑ?) (kind-data Γ KdStar :: expected-kind-if Γ kₑ?) (check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -] return-when (TpEq t₁~ t₂~) KdStar -- ● check-type Γ (ExTpHole pi) kₑ? = [- tp-hole-span Γ pi kₑ? (maybe-to-checking kₑ?) [] -] return-when (TpHole pi) (KdHole pi) -- λ x : tk. T check-type Γ (ExTpLam pi pi' x tk T) kₑ? = [- punctuation-span "Lambda (type)" pi (posinfo-plus pi 1) -] Γ ⊢ tk ↝ tk~ / case-ret ((Γ , pi' - x :` tk~) ⊢ T ↝ T~ ⇒ k / let kₛ = KdAbs x tk~ (rename-var Γ (pi' % x) x k) in [- var-span ff (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -] [- TpLambda-span Γ pi pi' x tk~ T synthesizing [ kind-data Γ kₛ ] nothing -] return2 (TpLam x tk~ (rename-var Γ (pi' % x) x T~)) kₛ) λ kₑ → (Γ ⊢ kₑ =β= λ where (KdAbs x' tk' k) → (Γ , pi' - x :` tk~) ⊢ T ⇐ (rename-var Γ x' (pi' % x) k) ↝ T~ / let xₙ = if x =string ignored-var && is-free-in x' k then x' else x in return (xₙ , rename-var Γ (pi' % x) xₙ T~ , lambda-bound-conv? Γ x tk' tk~ []) kₕ → (Γ , pi' - x :` tk~) ⊢ T ↝ T~ ⇒ _ / return (x , rename-var Γ (pi' % x) x T~ , [] , unless (is-hole kₕ) "The expected kind is not an arrow- or Pi-kind") ) >>= λ where (xₙ , T~ , tvs , e?) → [- var-span ff (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -] [- TpLambda-span Γ pi pi' x tk~ T checking (expected-kind Γ kₑ :: tvs) e? -] return (TpLam xₙ tk~ T~) -- (T) check-type Γ (ExTpParens pi T pi') kₑ? = [- punctuation-span "Parens (type)" pi pi' -] check-type Γ T kₑ? -- x check-type Γ (ExTpVar pi x) kₑ? = maybe-else' (ctxt-lookup-type-var Γ x) ([- TpVar-span Γ pi x (maybe-to-checking kₑ?) (expected-kind-if Γ kₑ?) (just "Undefined type variable") -] return-when (TpVar x) (KdHole pi)) λ where (qx , as , k) → [- TpVar-span Γ pi x (maybe-to-checking kₑ?) (expected-kind-if Γ kₑ? ++ [ kind-data Γ k ]) (check-for-kind-mismatch-if Γ "computed" kₑ? k) -] return-when (apps-type (TpVar qx) as) k -- Π x : tk. k check-kind Γ (ExKdAbs pi pi' x tk k) = Γ ⊢ tk ↝ tk~ / Γ , pi' - x :` tk~ ⊢ k ↝ k~ / [- KdAbs-span Γ pi pi' x tk~ k checking nothing -] [- var-span ff Γ pi' x checking tk~ nothing -] [- punctuation-span "Pi (kind)" pi (posinfo-plus pi 1) -] return (KdAbs x tk~ (rename-var Γ (pi' % x) x k~)) -- tk ➔ k check-kind Γ (ExKdArrow tk k) = Γ ⊢ tk ↝ tk~ / Γ ⊢ k ↝ k~ / [- KdArrow-span tk k checking nothing -] return (KdAbs ignored-var tk~ k~) -- ● check-kind Γ (ExKdHole pi) = [- kd-hole-span pi checking -] return (KdHole pi) -- (k) check-kind Γ (ExKdParens pi k pi') = [- punctuation-span "Parens (kind)" pi pi' -] check-kind Γ k -- ★ check-kind Γ (ExKdStar pi) = [- Star-span pi checking nothing -] return KdStar -- κ as... check-kind Γ (ExKdVar pi κ as) = case ctxt-lookup-kind-var-def Γ κ of λ where nothing → [- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as) [] checking [] (just "Undefined kind variable") -] return (KdHole pi) (just (ps , k)) → check-args Γ as ps >>= λ as~ → [- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as) ps checking (params-data Γ ps) (when (length as < length ps) ("Needed " ^ ℕ-to-string (length ps ∸ length as) ^ " further argument(s)")) -] return (fst (subst-params-args' Γ ps as~ k)) check-tpkd Γ (ExTkt T) = Tkt <$> check-type Γ T (just KdStar) check-tpkd Γ (ExTkk k) = Tkk <$> check-kind Γ k check-args Γ (ExTmArg me t :: as) (Param me' x (Tkt T) :: ps) = Γ ⊢ t ⇐ T ↝ t~ / let e-s = mk-span "Argument" (term-start-pos t) (term-end-pos t) [ expected-type Γ T ] (just "Mismatched argument erasure") e-m = λ r → if me iff me' then return {F = spanM} r else ([- e-s -] return {F = spanM} r) in check-args Γ as (subst-params Γ t~ x ps) >>= λ as~ → e-m ((if me then inj₂ (inj₁ t~) else inj₁ t~) :: as~) check-args Γ (ExTpArg T :: as) (Param _ x (Tkk k) :: ps) = Γ ⊢ T ⇐ k ↝ T~ / check-args Γ as (subst-params Γ T~ x ps) >>= λ as~ → return (inj₂ (inj₂ T~) :: as~) check-args Γ (ExTmArg me t :: as) (Param _ x (Tkk k) :: ps) = [- mk-span "Argument" (term-start-pos t) (term-end-pos t) [ expected-kind Γ k ] (just "Expected a type argument") -] return [] check-args Γ (ExTpArg T :: as) (Param me x (Tkt T') :: ps) = [- mk-span "Argument" (type-start-pos T) (type-end-pos T) [ expected-type Γ T' ] (just ("Expected a" ^ (if me then "n erased" else "") ^ " term argument")) -] return [] check-args Γ (a :: as) [] = let range = case a of λ {(ExTmArg me t) → term-start-pos t , term-end-pos t; (ExTpArg T) → type-start-pos T , type-end-pos T} in check-args Γ as [] >>= λ as~ → [- mk-span "Argument" (fst range) (snd range) [] (just "Too many arguments given") -] return [] check-args Γ [] _ = return [] check-erased-margs : ctxt → posinfo → posinfo → term → maybe type → spanM ⊤ check-erased-margs Γ pi pi' t T? = let psₑ = foldr (λ {(Param me x tk) psₑ → if me then x :: psₑ else psₑ}) [] (ctxt.ps Γ) fvs = free-vars (erase t) e = list-any (stringset-contains fvs) psₑ in if e then spanM-add (erased-marg-span Γ pi pi' T?) else spanMok check-let Γ (ExDefTerm pi x (just Tₑ) t) e? fm to = Γ ⊢ Tₑ ⇐ KdStar ↝ Tₑ~ / Γ ⊢ t ⇐ Tₑ~ ↝ t~ / elim-pair (compileFail-in Γ t~) λ tvs e → [- Var-span (Γ , pi - x :` Tkt Tₑ~) pi x checking (type-data Γ Tₑ~ :: tvs) e -] return (ctxt-term-def pi localScope opacity-open x (just t~) Tₑ~ Γ , pi % x , binder-data Γ pi x (Tkt Tₑ~) e? (just t~) fm to , (λ {ed} T' → [ Γ - t~ / (pi % x) ] T') , (λ t' → LetTm (e? || ~ is-free-in (pi % x) (erase t')) x nothing t~ ([ Γ - Var x / (pi % x) ] t'))) check-let Γ (ExDefTerm pi x nothing t) e? fm to = Γ ⊢ t ↝ t~ ⇒ Tₛ~ / elim-pair (compileFail-in Γ t~) λ tvs e → let Γ' = ctxt-term-def pi localScope opacity-open x (just t~) Tₛ~ Γ in [- Var-span Γ' pi x synthesizing (type-data Γ Tₛ~ :: tvs) e -] return (Γ' , pi % x , binder-data Γ pi x (Tkt Tₛ~) e? (just t~) fm to , (λ {ed} T' → [ Γ - t~ / (pi % x) ] T') , (λ t' → LetTm (e? || ~ is-free-in (pi % x) (erase t')) x nothing t~ ([ Γ - Var x / (pi % x) ] t'))) check-let Γ (ExDefType pi x k T) e? fm to = Γ ⊢ k ↝ k~ / Γ ⊢ T ⇐ k~ ↝ T~ / [- TpVar-span (Γ , pi - x :` Tkk k~) pi x checking [ kind-data Γ k~ ] nothing -] return (ctxt-type-def pi localScope opacity-open x (just T~) k~ Γ , pi % x , binder-data Γ pi x (Tkk k~) e? (just T~) fm to , (λ {ed} T' → [ Γ - T~ / (pi % x) ] T') , (λ t' → LetTp x k~ T~ ([ Γ - TpVar x / (pi % x) ] t'))) check-case Γ (ExCase pi x cas t) es Dₓ cs ρₒ as dps Tₘ cast-tm cast-tp = [- pattern-span pi x cas -] maybe-else' (trie-lookup (ctxt.qual Γ) x >>= uncurry λ x' _ → trie-lookup cs x' >>= λ T → just (x' , T)) (let e = maybe-else' (trie-lookup es x) ("This is not a constructor of " ^ unqual-local (unqual-all (ctxt.qual Γ) Dₓ)) λ _ → "This case is unreachable" in [- pattern-ctr-span Γ pi x [] [] (just e) -] return2 (Case x [] (Hole pi) []) cs) λ where (x' , Tₕ , ps , is) → decl-args Γ cas ps empty-trie ρₒ [] (const spanMok) >>= λ where (Γ' , cas' , e , σ , ρ , tvs , sm) → let rs = tmtps-to-args' Γ' σ (drop dps is) Tₘ' = TpAppTm (apps-type Tₘ rs) (app-caseArgs (cast-tm Γ') (cast-tp Γ') (recompose-apps as (Var x')) (zip cas cas')) Tₘ' = hnf Γ' unfold-no-defs Tₘ' in Γ' ⊢ t ⇐ Tₘ' ↝ t~ / sm t~ >> [- pattern-clause-span pi t (reverse tvs) -] [- pattern-ctr-span Γ' pi x cas' [] e -] return2 (Case x' (subst-case-args cas' Γ ρₒ) (subst-renamectxt Γ ρ t~) (args-to-tmtps (as ++ (subst-renamectxt Γ ρ -arg_ <$> rs)))) (trie-remove cs x') where subst-case-args : case-args → ctxt → renamectxt → case-args subst-case-args [] Γ ρ = [] subst-case-args (CaseArg e x tk? :: cs) Γ ρ = CaseArg e x (subst-renamectxt Γ ρ -tk_ <$> tk?) :: subst-case-args cs (ctxt-var-decl x Γ) (renamectxt-insert ρ x x) free-in-term : var → term → err-m free-in-term x t = when (is-free-in x (erase t)) "Erased argument occurs free in the body of the term" tmtp-to-arg' : ctxt → trie (Σi exprd ⟦_⟧) → tmtp → arg tmtp-to-arg' = λ Γ σ → either-else (Arg ∘ substs Γ σ) (ArgTp ∘ substs Γ σ) tmtps-to-args' : ctxt → trie (Σi exprd ⟦_⟧) → 𝕃 tmtp → args tmtps-to-args' = λ Γ σ → tmtp-to-arg' Γ σ <$>_ app-caseArgs : (term → type → term) → (type → kind → type) → term → 𝕃 (ex-case-arg × case-arg) → term app-caseArgs tf Tf = foldl λ where (ExCaseArg _ pi x , CaseArg me _ tk?) t → elim-pair (me , tk?) λ where tt (just (Tkt T)) → AppEr t (tf (Var (pi % x)) T) tt (just (Tkk k)) → AppTp t (Tf (TpVar (pi % x)) k) ff (just (Tkt T)) → App t (tf (Var (pi % x)) T) _ _ → t spos = term-start-pos t epos = term-end-pos t add-case-arg : ∀ {X Y} → ctxt → var → var → case-arg → spanM (X × case-args × Y) → spanM (X × case-args × Y) add-case-arg Γ x xₙ ca m = m >>=c λ X → return2 X ∘ map-fst λ cas → ca :: subst-case-args cas Γ (renamectxt-single x xₙ) decl-args : ctxt → ex-case-args → params → trie (Σi exprd ⟦_⟧) → renamectxt → 𝕃 tagged-val → (term → spanM ⊤) → spanM (ctxt × case-args × err-m × trie (Σi exprd ⟦_⟧) × renamectxt × 𝕃 tagged-val × (term → spanM ⊤)) decl-args Γ (ExCaseArg ExCaseArgTp pi x :: as) (Param me x' (Tkt T) :: ps) σ ρ xs sm = let T' = substs Γ σ T Γ' = ctxt-var-decl-loc pi x Γ xₙ = if x =string ignored-var then x' else x in add-case-arg Γ' (pi % x) xₙ (CaseArg tt xₙ (just (Tkt T'))) $ decl-args Γ' as ps (trie-insert σ x' (, TpVar (pi % x))) (renamectxt-insert ρ (pi % x) xₙ) (binder-data Γ' pi x (Tkt T') Erased nothing spos epos :: xs) λ t → [- TpVar-span Γ' pi x checking [ expected-type Γ T' ] (just ("This type argument should be a" ^ (if me then "n erased term" else " term"))) -] sm t decl-args Γ (ExCaseArg ExCaseArgTp pi x :: as) (Param _ x' (Tkk k) :: ps) σ ρ xs sm = let k' = substs Γ σ k Γ' = ctxt-type-decl pi x k' Γ xₙ = if x =string ignored-var then x' else x in add-case-arg Γ' (pi % x) xₙ (CaseArg tt xₙ (just (Tkk k'))) $ decl-args Γ' as ps (trie-insert σ x' (, TpVar (pi % x))) (renamectxt-insert ρ (pi % x) xₙ) (binder-data Γ' pi x (Tkk k') Erased nothing spos epos :: xs) λ t → [- TpVar-span Γ' pi x checking [ kind-data Γ k' ] (free-in-term x t) -] sm t decl-args Γ (ExCaseArg me pi x :: as) (Param me' x' (Tkt T) :: ps) σ ρ xs sm = let T' = substs Γ σ T e₁ = when (ex-case-arg-erased me xor me') "Mismatched erasure of term argument" e₂ = λ t → ifMaybe (ex-case-arg-erased me) $ free-in-term x t Γ' = Γ , pi - x :` (Tkt T') xₙ = if x =string ignored-var then x' else x in (add-case-arg Γ' (pi % x) xₙ (CaseArg me' xₙ (just (Tkt T'))) $ decl-args Γ' as ps (trie-insert σ x' (, Var (pi % x))) (renamectxt-insert ρ (pi % x) xₙ) (binder-data Γ' pi x (Tkt T') (ex-case-arg-erased me) nothing spos epos :: xs) λ t → [- Var-span Γ' pi x checking [ type-data Γ T' ] (e₁ ||-maybe e₂ t) -] sm t) decl-args Γ (ExCaseArg me pi x :: as) (Param me' x' (Tkk k) :: ps) σ ρ xs sm = let k' = substs Γ σ k Γ' = ctxt-var-decl-loc pi x Γ xₙ = if x =string ignored-var then x' else x in add-case-arg Γ' (pi % x) xₙ (CaseArg tt xₙ (just (Tkk k'))) $ decl-args Γ' as ps (trie-insert σ x' (, Var (pi % x))) (renamectxt-insert ρ (pi % x) xₙ) (binder-data Γ' pi x (Tkk k') (ex-case-arg-erased me) nothing spos epos :: xs) λ t → [- Var-span Γ' pi x checking [ expected-kind Γ k' ] (just "This term argument should be a type") -] sm t decl-args Γ [] [] σ ρ xs sm = return (Γ , [] , nothing , σ , ρ , xs , sm) decl-args Γ as [] σ ρ xs sm = return (Γ , [] , just (ℕ-to-string (length as) ^ " too many arguments supplied") , σ , ρ , xs , sm) decl-args Γ [] ps σ ρ xs sm = return (Γ , params-to-case-args (substs-params Γ σ ps) , just (ℕ-to-string (length ps) ^ " more arguments expected") , σ , ρ , xs , sm) check-cases Γ ms Dₓ cs ρ as dps Tₘ cast-tm cast-tp = foldr {B = stringset → trie (type × params × 𝕃 tmtp) → spanM (cases × trie (type × params × 𝕃 tmtp))} (λ m x es cs' → check-case Γ m es Dₓ cs' ρ as dps Tₘ cast-tm cast-tp >>=c λ m~ cs → x (stringset-insert es (ex-case-ctr m)) cs >>=c λ ms~ → return2 (m~ :: ms~)) (λ es → return2 []) ms empty-stringset (trie-map (decompose-ctr-type Γ) cs) >>=c λ ms~ missing-cases → let xs = map (map-snd snd) $ trie-mappings missing-cases csf = uncurry₂ λ Tₕ ps as → rope-to-string $ strRun Γ $ strVar (unqual-all (ctxt.qual Γ) Tₕ) >>str args-to-string (params-to-args ps) e = "Missing patterns: " ^ 𝕃-to-string csf ", " xs in return2 ms~ (unless (iszero (length xs)) e) check-refinement Γ Tₘ kₘ s = check-type (qualified-ctxt Γ) (resugar Tₘ) (just kₘ) empty-spans >>= uncurry λ Tₘ' s' → return $ (λ x → x , s) $ Tₘ' , [ to-string-tag "computed motive" Γ Tₘ ] , (when (spans-have-error s') "We could not compute a well-kinded motive") get-datatype-info-from-head-type Γ X as = return $ maybe-else' (data-lookup Γ X as) (inj₁ $ "The head type of the subterm is not a datatype" , [ head-type Γ (TpVar X) ]) (λ μ → inj₂ μ) check-sigma-evidence Γ tₑ? X as = maybe-else' tₑ? (get-datatype-info-from-head-type Γ X as >>=s λ d → return $ inj₂ (sigma-build-evidence X d , id , d)) (λ tₑ → Γ ⊢ tₑ ↝ tₑ~ ⇒ T / let ev-err = inj₁ $ ("The synthesized type of the evidence does not prove " ^ unqual-local (unqual-all (ctxt.qual Γ) X) ^ " is a datatype") , [ to-string-tag "evidence type" Γ T ] in case decompose-tpapps (hnf Γ unfold-head-elab T) of λ where (TpVar X' , as') → case reverse as' of λ where (Ttp T :: as') → return $ if ~ conv-type Γ T (TpVar X) then ev-err else maybe-else ev-err (λ {d@(mk-data-info X Xₒ asₚ asᵢ mps kᵢ k cs csₚₛ eds gds) → inj₂ (tₑ~ , (App $ recompose-apps (asₚ ++ tmtps-to-args Erased asᵢ) $ Var $ data-to/ X) , d)}) -- AS: it looks like we are reversing as' twice, so not reversing at all? (data-lookup-mu Γ X X' $ reverse as' ++ as) -- TODO: Make sure "X" isn't a _defined_ type, but a _declared_ one! -- This way we avoid the possibility that "as" has arguments -- to parameters in it, but only to indices. -- Also TODO: Make sure that parameters are equal in above conversion check! _ → return ev-err _ → return ev-err ) ctxt-mu-decls : ctxt → term → indices → type → datatype-info → posinfo → posinfo → posinfo → var → (cases → spanM ⊤) × ctxt × 𝕃 tagged-val × renamectxt × (ctxt → term → type → term) × (ctxt → type → kind → type) ctxt-mu-decls Γ t is Tₘ (mk-data-info X Xₒ asₚ asᵢ ps kᵢ k cs csₚₛ eds gds) pi₁ pi₂ pi₃ x = let X' = mu-Type/ x xₘᵤ = mu-isType/ x qXₘᵤ = data-Is/ X qXₜₒ = data-to/ X qX' = pi₁ % X' qxₘᵤ = pi₁ % xₘᵤ qx = pi₁ % x Tₘᵤ = TpAppTp (flip apps-type asₚ $ TpVar qXₘᵤ) $ TpVar qX' Γ' = ctxt-term-def pi₁ localScope opacity-open xₘᵤ nothing Tₘᵤ $ ctxt-datatype-decl X qx asₚ $ ctxt-type-decl pi₁ X' k Γ freshₓ = fresh-var (add-indices-to-ctxt is Γ') (maybe-else "x" id (is-var (Ttm t))) Tₓ = hnf Γ' unfold-no-defs (indices-to-alls is $ TpAbs ff freshₓ (Tkt $ indices-to-tpapps is $ TpVar qX') $ TpAppTm (indices-to-tpapps is Tₘ) $ Phi (Beta (Var freshₓ) (Var freshₓ)) (App (indices-to-apps is $ AppEr (AppTp (flip apps-term asₚ $ Var qXₜₒ) $ TpVar qX') $ Var qxₘᵤ) $ Var freshₓ) (Var freshₓ)) Γ'' = ctxt-term-decl pi₁ x Tₓ Γ' e₂? = unless (X =string Xₒ) "Abstract datatypes can only be pattern matched by σ" e₃ = λ x → just $ x ^ " occurs free in the erasure of the body (not allowed)" cs-fvs = stringset-contains ∘' free-vars-cases ∘' erase-cases e₃ₓ? = λ cs x → ifMaybe (cs-fvs cs x) $ e₃ x e₃? = λ cs → e₃ₓ? cs (mu-isType/ x) ||-maybe e₃ₓ? cs (mu-Type/ x) in (λ cs → [- var-span NotErased Γ'' pi₁ x checking (Tkt Tₓ) (e₂? ||-maybe e₃? cs) -] spanMok) , Γ'' , (binder-data Γ'' pi₁ X' (Tkk k) Erased nothing pi₂ pi₃ :: binder-data Γ'' pi₁ xₘᵤ (Tkt Tₘᵤ) Erased nothing pi₂ pi₃ :: binder-data Γ'' pi₁ x (Tkt Tₓ) NotErased nothing pi₂ pi₃ :: to-string-tag X' Γ'' k :: to-string-tag xₘᵤ Γ'' Tₘᵤ :: to-string-tag x Γ'' Tₓ :: []) , renamectxt-insert* empty-renamectxt ((qX' , X') :: (qxₘᵤ , xₘᵤ) :: (qx , x) :: []) , let cg = qX' , recompose-tpapps (args-to-tmtps asₚ) (TpVar qx) , AppEr (AppTp (recompose-apps asₚ (Var qXₜₒ)) (TpVar qX')) (Var qxₘᵤ) in flip (mk-ctr-fmap-η? ff ∘ ctxt-datatype-undef qX') cg , flip (mk-ctr-fmapₖ-η? ff ∘ ctxt-datatype-undef qX') cg check-mu Γ pi pi' x t Tₘ? pi'' cs pi''' Tₑ? = check-term Γ t nothing >>=c λ t~ T → let no-motive-err = just "A motive is required when synthesizing" no-motive = return (nothing , [] , no-motive-err) in case decompose-tpapps (hnf Γ unfold-head-elab T) of λ where (TpVar X , as) → get-datatype-info-from-head-type Γ X as on-fail (uncurry λ e tvs → spanM-add (Mu-span Γ pi pi''' nothing (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ? ++ tvs) $ just e) >> return-when {m = Tₑ?} (Hole pi) (TpHole pi)) >>=s λ where (d @ (mk-data-info Xₒ _ asₚ asᵢ ps kᵢ k cs' csₚₛ eds gds)) → let Rₓ = mu-Type/ x; qRₓ = pi' % Rₓ Γₘ = data-highlight (ctxt-type-decl pi' Rₓ k Γ) qRₓ ρₘ = subst Γₘ (recompose-tpapps (args-to-tmtps asₚ) (TpVar Xₒ)) qRₓ ρₘ' = subst Γₘ (TpVar Rₓ) qRₓ eₘ = λ Tₘ → when (negₒ (extract-pos (positivity.type+ qRₓ Γₘ (hnf-ctr Γₘ qRₓ Tₘ)))) (Rₓ ^ " occurs negatively in the motive") in maybe-map (λ Tₘ → check-type Γₘ Tₘ (just kᵢ)) Tₘ? >>=? λ Tₘ?' → let is = kind-to-indices Γ kᵢ eₘ = Tₘ?' >>= eₘ ret-tp = λ ps as t → maybe-else' Tₘ?' Tₑ? (λ Tₘ → just $ hnf Γ unfold-head-elab (TpAppTm (apps-type (ρₘ Tₘ) $ tmtps-to-args NotErased (drop (length ps) as)) t)) in (maybe-else' Tₘ?' (return Tₑ? on-fail no-motive >>=m λ Tₑ → let Tₘ = refine-motive Γ is (asᵢ ++ [ Ttm t~ ]) Tₑ in check-refinement Γ Tₘ kᵢ >>=c λ Tₘ → return2 (just Tₘ)) λ Tₘ → return (just Tₘ , [] , nothing)) >>=c λ Tₘ → uncurry λ tvs₁ e₁ → let Tₘ = maybe-else' Tₘ (TpHole pi) id is = drop-last 1 is reduce-cs = map λ {(Ctr x T) → Ctr x $ hnf Γ unfold-no-defs T} fcs = λ y → inst-ctrs Γ ps asₚ (map-snd (rename-var {TYPE} Γ Xₒ y) <$> cs') cs' = reduce-cs $ fcs (mu-Type/ (pi' % x)) in case (ctxt-mu-decls Γ t~ is Tₘ d pi' pi'' pi''' x) of λ where (sm , Γ' , bds , ρ , cast-tm , cast-tp) → let cs'' = foldl (λ {(Ctr x T) σ → trie-insert σ x T}) empty-trie cs' drop-ps = 0 scrutinee = t~ Tᵣ = ret-tp ps (args-to-tmtps asₚ ++ asᵢ) scrutinee in check-cases Γ' cs Xₒ cs'' ρ asₚ drop-ps Tₘ cast-tm cast-tp >>=c λ cs~ e₂ → let e₃ = maybe-else' Tᵣ (just "A motive is required when synthesizing") (check-for-type-mismatch-if Γ "synthesized" Tₑ?) in [- Mu-span Γ pi pi''' Tₘ?' (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ? ++ maybe-else' Tᵣ [] (λ Tᵣ → [ type-data Γ Tᵣ ]) ++ tvs₁ ++ bds) (e₁ ||-maybe (e₂ ||-maybe (e₃ ||-maybe eₘ))) -] sm cs~ >> return-when {m = Tₑ?} (subst-renamectxt Γ ρ (Mu x t~ (just (ρₘ' Tₘ)) d cs~)) (maybe-else' Tᵣ (TpHole pi) id) (Tₕ , as) → [- Mu-span Γ pi pi''' nothing (maybe-to-checking Tₑ?) [ head-type Γ Tₕ ] (just "The head type of the subterm is not a datatype") -] return-when {m = Tₑ?} (Hole pi) (TpHole pi) check-sigma Γ pi t? t Tₘ? pi'' cs pi''' Tₑ? = check-term Γ t nothing >>=c λ t~ T → let no-motive-err = just "A motive is required when synthesizing" no-motive = return (nothing , [] , no-motive-err) in case decompose-tpapps (hnf Γ unfold-head-elab T) of λ where (TpVar X , as) → check-sigma-evidence Γ t? X as on-fail (uncurry λ e tvs → spanM-add (Sigma-span Γ pi pi''' nothing (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ? ++ tvs) $ just e) >> return-when {m = Tₑ?} (Hole pi) (TpHole pi)) >>=s λ where (tₑ~ , cast , d @ (mk-data-info Xₒ _ asₚ asᵢ ps kᵢ k cs' csₚₛ eds gds)) → maybe-map (λ Tₘ → check-type Γ Tₘ (just kᵢ)) Tₘ? >>=? λ Tₘ?' → let is = kind-to-indices Γ kᵢ ret-tp = λ ps as t → maybe-else' Tₘ?' Tₑ? (λ Tₘ → just $ hnf Γ unfold-head-elab (TpAppTm (apps-type Tₘ $ tmtps-to-args NotErased (drop (length ps) as)) t)) in (maybe-else' Tₘ?' (return Tₑ? on-fail no-motive >>=m λ Tₑ → let Tₘ = refine-motive Γ is (asᵢ ++ [ Ttm t~ ]) Tₑ in check-refinement Γ Tₘ kᵢ >>=c λ Tₘ → return2 (just Tₘ)) λ Tₘ → return (just Tₘ , [] , nothing)) >>=c λ Tₘ → uncurry λ tvs₁ e₁ → let Tₘ = maybe-else' Tₘ (TpHole pi) id reduce-cs = map λ {(Ctr x T) → Ctr x $ hnf Γ unfold-no-defs T} fcs = λ y → inst-ctrs Γ ps asₚ (map-snd (rename-var {TYPE} Γ Xₒ y) <$> cs') cs' = reduce-cs $ if Xₒ =string X then csₚₛ else fcs X in let sm = const spanMok ρ = empty-renamectxt cast-tm = (λ Γ t T → t) cast-tp = (λ Γ T k → T) cs'' = foldl (λ {(Ctr x T) σ → trie-insert σ x T}) empty-trie cs' drop-ps = maybe-else 0 length (when (Xₒ =string X) ps) scrutinee = cast t~ Tᵣ = ret-tp ps (args-to-tmtps asₚ ++ asᵢ) scrutinee in check-cases Γ cs Xₒ cs'' ρ asₚ drop-ps Tₘ cast-tm cast-tp >>=c λ cs~ e₂ → let e₃ = maybe-else' Tᵣ (just "A motive is required when synthesizing") (check-for-type-mismatch-if Γ "synthesized" Tₑ?) in [- Sigma-span Γ pi pi''' Tₘ?' (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ? ++ maybe-else' Tᵣ [] (λ Tᵣ → [ type-data Γ Tᵣ ]) ++ tvs₁) (e₁ ||-maybe (e₂ ||-maybe e₃)) -] sm cs~ >> return-when {m = Tₑ?} (subst-renamectxt Γ ρ (Sigma (just tₑ~) t~ (just Tₘ) d cs~)) (maybe-else' Tᵣ (TpHole pi) id) (Tₕ , as) → [- Sigma-span Γ pi pi''' nothing (maybe-to-checking Tₑ?) [ head-type Γ Tₕ ] (just "The head type of the subterm is not a datatype") -] return-when {m = Tₑ?} (Hole pi) (TpHole pi)
47.105451
311
0.521732
13a911209d16576207eb474cebfd04eaa25e5c02
248
agda
Agda
examples/examplesPaperJFP/Equality.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
examples/examplesPaperJFP/Equality.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
examples/examplesPaperJFP/Equality.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module examplesPaperJFP.Equality where infix 4 _≡_ data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x -- obsolete, now in Agda.Builtin.Equality: {-# BUILTIN EQUALITY _≡_ #-} -- No longer exists in Agda: {-# BUILTIN REFL refl #-}
24.8
71
0.633065
fd1f5994531d569cb4864695a4da9c4b184a6c7a
621
agda
Agda
Categories/Object/Terminal/Exponentiating.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Object/Terminal/Exponentiating.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Object/Terminal/Exponentiating.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
{-# OPTIONS --universe-polymorphism #-} open import Categories.Category open import Categories.Object.Products open import Categories.Object.Terminal open import Level module Categories.Object.Terminal.Exponentiating {o ℓ e : Level} (C : Category o ℓ e) (P : Products C) where open Category C open Products P open Terminal terminal open import Categories.Object.Exponentiating import Categories.Object.Terminal.Exponentials open Categories.Object.Terminal.Exponentials C terminal ⊤-exponentiating : Exponentiating C binary ⊤ ⊤-exponentiating = record { exponential = λ {X : Obj} → [⊤↑ X ]-exponential }
24.84
64
0.768116
5299d434f1f90a7129bb14942e06583063272c00
474
agda
Agda
test/asset/agda-stdlib-1.0/Data/Vec/Relation/Equality/Setoid.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Vec/Relation/Equality/Setoid.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Vec/Relation/Equality/Setoid.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.Vec.Relation.Binary.Equality.Setoid directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Data.Vec.Relation.Equality.Setoid {a ℓ} (S : Setoid a ℓ) where open import Data.Vec.Relation.Binary.Equality.Setoid S public
29.625
72
0.510549
1b4f8857a629f4124000af51b09e7948bcbf0020
6,724
agda
Agda
STLC/Operational/Eager.agda
TypesLogicsCats/STLC
59bc9648f326b7359801fb31ff6f957a166876fc
[ "MIT" ]
1
2020-03-16T23:53:48.000Z
2020-03-16T23:53:48.000Z
STLC/Operational/Eager.agda
TypesLogicsCats/STLC
59bc9648f326b7359801fb31ff6f957a166876fc
[ "MIT" ]
null
null
null
STLC/Operational/Eager.agda
TypesLogicsCats/STLC
59bc9648f326b7359801fb31ff6f957a166876fc
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module STLC.Operational.Eager where open import STLC.Syntax open import STLC.Operational.Base open import Data.Empty using (⊥-elim) open import Data.Product using (∃-syntax; _,_) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Nat using (ℕ; zero; suc; _+_) open import Data.Fin using (Fin; _≟_) renaming (zero to fzero; suc to fsuc) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong) open import Relation.Nullary using (yes; no; ¬_) private variable m n : ℕ L M M' N N' : Term n A B C : Type Γ Δ : Ctx n v : Fin n data Value {n} : Term n → Set where abs-value ----------------- : Value (abs A M) ⋆-value ----------------- : Value ⋆ pair-value : Value M → Value N ----------------- → Value (pair M N) infix 6 _↦_ data _↦_ : Term n → Term n → Set where red-head : M ↦ M' ------------------ → app M N ↦ app M' N red-arg : Value M → N ↦ N' ------------------ → app M N ↦ app M N' red-β : Value N --------------------------------- → app (abs A M) N ↦ M [ fzero ≔ N ] red-left : M ↦ M' -------------------- → pair M N ↦ pair M' N red-right : Value M → N ↦ N' -------------------- → pair M N ↦ pair M N' red-projₗ-inner : M ↦ M' ------------------ → projₗ M ↦ projₗ M' red-projₗ : Value M → Value N -------------------- → projₗ (pair M N) ↦ M red-projᵣ-inner : M ↦ M' ------------------ → projᵣ M ↦ projᵣ M' red-projᵣ : Value M → Value N -------------------- → projᵣ (pair M N) ↦ N data _↦*_ : Term n → Term n → Set where pure : M ↦ N → M ↦* N id : M ↦* M comp : L ↦* M → M ↦* N → L ↦* N open import STLC.Typing progress : ● ⊢ M ⦂ A → Value M ⊎ (∃[ N ] (M ↦ N)) progress (ty-abs _) = inj₁ abs-value progress (ty-app {f = f} {x = x} t u) with progress u | progress t ... | inj₁ u-value | inj₁ (abs-value {M = M}) = inj₂ (M [ fzero ≔ x ] , red-β u-value) ... | inj₂ (u' , u-step) | inj₁ t-value = inj₂ (app f u' , red-arg t-value u-step) ... | inj₁ _ | inj₂ (t' , t-step) = inj₂ (app t' x , red-head t-step) ... | inj₂ _ | inj₂ (t' , t-step) = inj₂ (app t' x , red-head t-step) progress ty-⋆ = inj₁ ⋆-value progress (ty-pair {a = a} {b = b} t u) with progress t | progress u ... | inj₁ t-value | inj₁ u-value = inj₁ (pair-value t-value u-value) ... | inj₁ t-value | inj₂ (u' , u-step) = inj₂ (pair a u' , red-right t-value u-step) ... | inj₂ (t' , t-step) | _ = inj₂ (pair t' b , red-left t-step) progress (ty-projₗ t) with progress t ... | inj₁ (pair-value {M = M} M-value N-value) = inj₂ (M , red-projₗ M-value N-value) ... | inj₂ (t' , t-step) = inj₂ (projₗ t' , red-projₗ-inner t-step) progress (ty-projᵣ t) with progress t ... | inj₁ (pair-value {N = N} M-value N-value) = inj₂ (N , red-projᵣ M-value N-value) ... | inj₂ (t' , t-step) = inj₂ (projᵣ t' , red-projᵣ-inner t-step) weakening-var : ∀ {Γ : Ctx n} {v' : Fin (suc n)} → Γ ∋ v ⦂ A → liftΓ Γ v' B ∋ Data.Fin.punchIn v' v ⦂ A weakening-var {v' = fzero} vzero = vsuc vzero weakening-var {v' = fsuc n} vzero = vzero weakening-var {v' = fzero} (vsuc v) = vsuc (vsuc v) weakening-var {v' = fsuc n} (vsuc v) = vsuc (weakening-var v) -- | The weakening lemma: A term typeable in a context is typeable in an extended context. -- -- https://www.seas.upenn.edu/~sweirich/dsss17/html/Stlc.Lec2.html weakening : ∀ {Γ : Ctx n} {v : Fin (suc n)} {t : Type} → Γ ⊢ M ⦂ A → liftΓ Γ v t ⊢ lift M v ⦂ A weakening (ty-abs body) = ty-abs (weakening body) weakening (ty-app f x) = ty-app (weakening f) (weakening x) weakening (ty-var v) = ty-var (weakening-var v) weakening ty-⋆ = ty-⋆ weakening (ty-pair l r) = ty-pair (weakening l) (weakening r) weakening (ty-projₗ p) = ty-projₗ (weakening p) weakening (ty-projᵣ p) = ty-projᵣ (weakening p) lemma : ∀ {Γ : Ctx n} → (v : Fin (suc n)) → liftΓ Γ v B ∋ v ⦂ A → A ≡ B lemma fzero vzero = refl lemma {Γ = _ ,- _} (fsuc fin) (vsuc v) = lemma fin v subst-eq : (v : Fin (suc n)) → liftΓ Γ v B ∋ v ⦂ A → Γ ⊢ M ⦂ B → Γ ⊢ var v [ v ≔ M ] ⦂ A subst-eq fzero vzero typing = typing subst-eq {Γ = Γ ,- C} (fsuc fin) (vsuc v) typing with fin ≟ fin ... | yes refl rewrite lemma fin v = typing ... | no neq = ⊥-elim (neq refl) subst-neq : (v v' : Fin (suc n)) → liftΓ Γ v B ∋ v' ⦂ A → (prf : ¬ v ≡ v') → Γ ∋ (Data.Fin.punchOut prf) ⦂ A subst-neq v v' v-typing neq with v ≟ v' ... | yes refl = ⊥-elim (neq refl) subst-neq fzero fzero _ _ | no neq = ⊥-elim (neq refl) subst-neq {Γ = Γ ,- C} fzero (fsuc fin) (vsuc v-typing) _ | no neq = v-typing subst-neq {Γ = Γ ,- C} (fsuc fin) fzero vzero _ | no neq = vzero subst-neq {Γ = Γ ,- C} (fsuc fin) (fsuc fin') (vsuc v-typing) neq | no _ = vsuc (subst-neq fin fin' v-typing λ { assump → neq (cong fsuc assump) }) -- | The substitution lemma: Substitution preserves typing. subst : ∀ {Γ : Ctx n} → liftΓ Γ v B ⊢ M ⦂ A → Γ ⊢ N ⦂ B → Γ ⊢ M [ v ≔ N ] ⦂ A subst (ty-abs body) typing = ty-abs (subst body (weakening typing)) subst (ty-app f x) typing = ty-app (subst f typing) (subst x typing) subst {v = v} {Γ = _} (ty-var {v = v'} v-typing) typing with v' ≟ v ... | yes refl = subst-eq v v-typing typing subst {v = fzero} (ty-var {v = fzero} v-typing) typing | no neq = ⊥-elim (neq refl) subst {v = fzero} (ty-var {v = fsuc v'} (vsuc v-typing)) typing | no neq = ty-var v-typing subst {v = fsuc v} {Γ = Γ ,- C} (ty-var {v = fzero} vzero) typing | no neq = ty-var vzero subst {v = fsuc v} {Γ = Γ ,- C} (ty-var {v = fsuc v'} (vsuc v-typing)) typing | no neq with v ≟ v' ... | yes eq = ⊥-elim (neq (cong fsuc (sym eq))) ... | no neq' = ty-var (vsuc (subst-neq v v' v-typing _)) subst ty-⋆ _ = ty-⋆ subst (ty-pair l r) typing = ty-pair (subst l typing) (subst r typing) subst (ty-projₗ p) typing = ty-projₗ (subst p typing) subst (ty-projᵣ p) typing = ty-projᵣ (subst p typing) preservation : ● ⊢ M ⦂ A → M ↦ N → ● ⊢ N ⦂ A preservation (ty-app M-ty N-ty) (red-head M-step) = ty-app (preservation M-ty M-step) N-ty preservation (ty-app M-ty N-ty) (red-arg M-val N-step) = ty-app M-ty (preservation N-ty N-step) preservation (ty-app (ty-abs body-ty) N-ty) (red-β N-value) = subst body-ty N-ty preservation (ty-pair M-ty N-ty) (red-left M-step) = ty-pair (preservation M-ty M-step) N-ty preservation (ty-pair M-ty N-ty) (red-right _ N-step) = ty-pair M-ty (preservation N-ty N-step) preservation (ty-projₗ M-ty) (red-projₗ-inner M-step) = ty-projₗ (preservation M-ty M-step) preservation (ty-projₗ (ty-pair M-ty _)) (red-projₗ _ _) = M-ty preservation (ty-projᵣ M-ty) (red-projᵣ-inner M-step) = ty-projᵣ (preservation M-ty M-step) preservation (ty-projᵣ (ty-pair _ N-ty)) (red-projᵣ _ _) = N-ty
37.355556
92
0.567519
1bd3eeda7decb54c99cbbd619e4ec44aa961abc4
793
agda
Agda
test/Compiler/simple/Issue2469.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Issue2469.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/Issue2469.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue2469 where open import Agda.Builtin.Nat open import Agda.Builtin.Unit open import Agda.Builtin.IO renaming (IO to BIO) open import Agda.Builtin.String open import Agda.Builtin.IO open import Common.IO open import Common.Prelude open import Common.Sum open import Common.Product data F : Nat → Set where [] : F zero _∷1 : ∀ {n} → F n → F (suc n) _∷2 : ∀ {n} → F n → F (suc (suc n)) f : ∀ k → F (suc k) → F k ⊎ Maybe ⊥ f zero a = inj₂ nothing f k (xs ∷1) = inj₂ nothing -- to (suc k) xs = inj₂ nothing -- This is fine f (suc k) = λ xs → inj₂ nothing -- This segfaults myshow : F 1 ⊎ Maybe ⊥ → String -- myshow (inj₁ b) = "" -- This is fine myshow (inj₁ (b ∷1)) = "bla" -- This segfaults myshow _ = "blub" main : IO ⊤ main = putStrLn (myshow (f 1 ([] ∷2)))
24.78125
51
0.627995
9a36a5f360b7c65aa6566ed4a77ec95b7313814f
455
agda
Agda
HoTT/Product/Universal.agda
michaelforney/hott
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
[ "0BSD" ]
null
null
null
HoTT/Product/Universal.agda
michaelforney/hott
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
[ "0BSD" ]
null
null
null
HoTT/Product/Universal.agda
michaelforney/hott
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
[ "0BSD" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT.Base open import HoTT.Equivalence open import HoTT.Identity.Pi open import HoTT.Identity.Product module HoTT.Product.Universal where ×-univ : ∀ {i j k} {X : 𝒰 i} (A : X → 𝒰 j) (B : X → 𝒰 k) → ((c : X) → A c × B c) ≃ Π X A × Π X B ×-univ {X = X} A B = let open Iso in iso→eqv λ where .f f → pr₁ ∘ f , pr₂ ∘ f .g f x → pr₁ f x , pr₂ f x .η f → funext (×-uniq ∘ f) .ε f → ×-pair⁼ (refl , refl)
28.4375
58
0.558242
fbb8c8018468ede3ababf89f81c4973e310e376c
1,785
agda
Agda
TypeTheory/Lecture/StreamPredicates.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/Lecture/StreamPredicates.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/Lecture/StreamPredicates.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
module StreamPredicates where open import PropsAsTypes open import Stream module Modalities (A : Set) where private Aω : Set Aω = Stream A record Always (P : Pred Aω) (s : Stream A) : Prop where coinductive field valid : P s step : Always P (tl s) open Always public data Eventually (P : Pred Aω) (s : Stream A) : Prop where now : P s → Eventually P s later : Eventually P (tl s) → Eventually P s GE : Pred Aω → Pred Aω GE P = Always (Eventually P) EG : Pred Aω → Pred Aω EG P = Eventually (Always P) Always⇒GE : ∀{P : Pred Aω} → Always P ⊆ GE P Always⇒GE s p .valid = now (p .valid) Always⇒GE s p .step = Always⇒GE (s .tl) (p .step) EG⇒Eventually : ∀{P : Pred Aω} → EG P ⊆ Eventually P EG⇒Eventually s (now p) = now (p .valid) EG⇒Eventually s (later Evs') = later (EG⇒Eventually (s .tl) Evs') EG⇒GE : ∀{P : Pred Aω} → EG P ⊆ GE P EG⇒GE s p .valid = EG⇒Eventually s p EG⇒GE s (now p) .step = Always⇒GE (tl s) (p .step) EG⇒GE s (later p) .step = EG⇒GE (tl s) p module ModalitiesExamples where open import Data.Nat open import Relation.Binary.PropositionalEquality as PE exP : Pred (Stream ℕ) exP s = s .hd ≡ 0 alt : Stream ℕ alt .hd = 0 alt .tl .hd = 1 alt .tl .tl = alt open Modalities ℕ exP-holds-on-alt-GE : GE exP alt exP-holds-on-alt-GE .valid = now refl exP-holds-on-alt-GE .step .valid = later (now refl) exP-holds-on-alt-GE .step .step = exP-holds-on-alt-GE exP-holds-not-on-alt-EG : ¬ (EG exP alt) exP-holds-not-on-alt-EG (now p) = zero-not-suc 0 (p .step .valid) exP-holds-not-on-alt-EG (later (now p)) = zero-not-suc 0 (p .valid) exP-holds-not-on-alt-EG (later (later EGalt'')) = exP-holds-not-on-alt-EG EGalt''
27.045455
75
0.610084
21aa6fc10d7d5fd1844e71adc12108d98f1c2c57
679
agda
Agda
Cubical/Data/Sum/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/Sum/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/Sum/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Sum.Base where open import Cubical.Core.Everything private variable ℓ ℓ' : Level A B C D : Type ℓ data _⊎_ (A : Type ℓ)(B : Type ℓ') : Type (ℓ-max ℓ ℓ') where inl : A → A ⊎ B inr : B → A ⊎ B infixr 5 _⊎_ rec : {C : Type ℓ} → (A → C) → (B → C) → A ⊎ B → C rec f _ (inl x) = f x rec _ g (inr y) = g y elim : {C : A ⊎ B → Type ℓ} → ((a : A) → C (inl a)) → ((b : B) → C (inr b)) → (x : A ⊎ B) → C x elim f _ (inl x) = f x elim _ g (inr y) = g y map : (A → C) → (B → D) → A ⊎ B → C ⊎ D map f _ (inl x) = inl (f x) map _ g (inr y) = inr (g y) swap : A ⊎ B → B ⊎ A swap = elim inr inl
21.21875
76
0.486009
34395692706a7e2be7a5e79ec4504d4eaeeabcd7
259
agda
Agda
test/succeed/RecordInParModule.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/succeed/RecordInParModule.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/RecordInParModule.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module RecordInParModule (a : Set) where record Setoid : Set1 where field el : Set postulate S : Setoid A : Setoid.el S postulate X : Set module M (x : X) where record R : Set where module E {x : X} (r : M.R x) where open module M' = M.R x r
13.631579
40
0.633205
ad492116f1723f8f3dabcf4169b72b073e06c42d
1,306
agda
Agda
test/js/TestList.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/js/TestList.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/js/TestList.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
open import Common.Prelude open import TestHarness open import TestBool using ( not; _∧_ ; _↔_ ) module TestList where _++_ : ∀ {X} → List X → List X → List X [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) revApp : ∀ {X} → List X → List X → List X revApp [] ys = ys revApp (x ∷ xs) ys = revApp xs (x ∷ ys) reverse : ∀ {X} → List X → List X reverse xs = revApp xs [] _≟_ : List Bool → List Bool → Bool [] ≟ [] = true (x ∷ xs) ≟ (y ∷ ys) = (x ↔ y) ∧ (xs ≟ ys) _ ≟ - = false [tt] = true ∷ [] [ff] = false ∷ [] [tt,ff] = true ∷ [ff] [ff,tt] = false ∷ [tt] [ff,tt,ff] = false ∷ [tt,ff] tests : Tests tests _ = ( assert ([] ≟ []) "[]=[]" , assert (not ([tt] ≟ [ff])) "[tt]≠[ff]" , assert (([] ++ [tt]) ≟ [tt]) "[]++[tt]=[tt]" , assert (([tt] ++ []) ≟ [tt]) "[tt]++[]=[tt]" , assert (([tt] ++ [ff]) ≟ [tt,ff]) "[tt]++[ff]=[tt,ff]" , assert (([ff,tt] ++ [ff]) ≟ [ff,tt,ff]) "[ff,tt]++[ff]=[ff,tt,ff]" , assert (not (([ff] ++ [tt]) ≟ [tt,ff])) "[ff]++[tt]≠[tt,ff]" , assert (not (([tt] ++ [tt]) ≟ [tt,ff])) "[tt]++[tt]≠[tt,ff]" , assert (reverse [tt,ff] ≟ [ff,tt]) "rev[tt,ff]=[ff,tt]" , assert (reverse (reverse [tt,ff]) ≟ [tt,ff]) "rev(rev[tt,ff])=[tt,ff]" , assert (not (reverse [tt,ff] ≟ [tt,ff])) "rev[tt,ff]≠[tt,ff]" )
30.372093
76
0.447933
ada7dd48895f352f0cbbac51a74e9b35eba45820
1,110
agda
Agda
src/Generic/Lib/Data/Pow.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
30
2016-07-19T21:10:54.000Z
2022-02-05T10:19:38.000Z
src/Generic/Lib/Data/Pow.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
9
2017-04-06T18:58:09.000Z
2022-01-04T15:43:14.000Z
src/Generic/Lib/Data/Pow.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
4
2017-07-17T07:23:39.000Z
2021-01-27T12:57:09.000Z
module Generic.Lib.Data.Pow where open import Generic.Lib.Intro open import Generic.Lib.Data.Nat open import Generic.Lib.Data.Product infixl 6 _^_ _^_ : ∀ {α} -> Set α -> ℕ -> Set α A ^ 0 = ⊤ A ^ suc n = A × A ^ n elimPow : ∀ {n α} {A : Set α} {b : ∀ {n} -> A ^ n -> Level} -> (B : ∀ {n} -> (xs : A ^ n) -> Set (b xs)) -> (∀ {n} {xs : A ^ n} x -> B xs -> B (x , xs)) -> B tt -> (xs : A ^ n) -> B xs elimPow {0} B f z tt = z elimPow {suc n} B f z (x , xs) = f x (elimPow B f z xs) foldPow : ∀ {n α β} {A : Set α} -> (B : ℕ -> Set β) -> (∀ {n} -> A -> B n -> B (suc n)) -> B 0 -> A ^ n -> B n foldPow B f z xs = elimPow (λ {n} _ -> B n) (λ x y -> f x y) z xs foldPow₁ : ∀ {n α} {A : Set α} -> (A -> A -> A) -> A ^ suc n -> A foldPow₁ {0} f (x , []) = x foldPow₁ {suc n} f (x , xs) = f x (foldPow₁ f xs) mapPow : ∀ {n α β} {A : Set α} {B : Set β} -> (A -> B) -> A ^ n -> B ^ n mapPow f = foldPow (_ ^_) (_,_ ∘ f) tt replicatePow : ∀ {α} {A : Set α} n -> A -> A ^ n replicatePow 0 x = tt replicatePow (suc n) x = x , replicatePow n x
30.833333
86
0.445946
5e84f8b9b8ee9d9f79d801bbd7e85d174af2006e
1,572
agda
Agda
Cubical/Functions/Fixpoint.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Functions/Fixpoint.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Functions/Fixpoint.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{- Definition of function fixpoint and Kraus' lemma -} {-# OPTIONS --safe #-} module Cubical.Functions.Fixpoint where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Path private variable ℓ : Level A : Type ℓ Fixpoint : (A → A) → Type _ Fixpoint {A = A} f = Σ A (λ x → f x ≡ x) fixpoint : {f : A → A} → Fixpoint f → A fixpoint = fst fixpointPath : {f : A → A} → (p : Fixpoint f) → f (fixpoint p) ≡ fixpoint p fixpointPath = snd -- Kraus' lemma -- a version not using cubical features can be found at -- https://www.cs.bham.ac.uk/~mhe/GeneralizedHedberg/html/GeneralizedHedberg.html#21576 2-Constant→isPropFixpoint : (f : A → A) → 2-Constant f → isProp (Fixpoint f) 2-Constant→isPropFixpoint f fconst (x , p) (y , q) i = s i , t i where noose : ∀ x y → f x ≡ f y noose x y = sym (fconst x x) ∙ fconst x y -- the main idea is that for any path p, cong f p does not depend on p -- but only on its endpoints and the structure of 2-Constant f KrausInsight : ∀ {x y} → (p : x ≡ y) → noose x y ≡ cong f p KrausInsight {x} = J (λ y p → noose x y ≡ cong f p) (lCancel (fconst x x)) -- Need to solve for a path s : x ≡ y, such that: -- transport (λ i → cong f s i ≡ s i) p ≡ q s : x ≡ y s = sym p ∙∙ noose x y ∙∙ q t' : PathP (λ i → noose x y i ≡ s i) p q t' i j = doubleCompPath-filler (sym p) (noose x y) q j i t : PathP (λ i → cong f s i ≡ s i) p q t = subst (λ kraus → PathP (λ i → kraus i ≡ s i) p q) (KrausInsight s) t'
34.933333
87
0.633588