Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Sets where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open Category
module _ ℓ where
SET : Category (ℓ-suc ℓ) ℓ
ob SET = hSet ℓ
Hom[_,_] SET (A , _) (B , _) = A → B
id SET x = x
_⋆_ SET f g x = g (f x)
⋆IdL SET f = refl
⋆IdR SET f = refl
⋆Assoc SET f g h = refl
isSetHom SET {A} {B} = isSetΠ (λ _ → snd B)
private
variable
ℓ ℓ' : Level
open Functor
-- Hom functors
_[-,_] : (C : Category ℓ ℓ') → (c : C .ob) → Functor (C ^op) (SET ℓ')
(C [-, c ]) .F-ob x = (C [ x , c ]) , C .isSetHom
(C [-, c ]) .F-hom f k = f ⋆⟨ C ⟩ k
(C [-, c ]) .F-id = funExt λ _ → C .⋆IdL _
(C [-, c ]) .F-seq _ _ = funExt λ _ → C .⋆Assoc _ _ _
_[_,-] : (C : Category ℓ ℓ') → (c : C .ob)→ Functor C (SET ℓ')
(C [ c ,-]) .F-ob x = (C [ c , x ]) , C .isSetHom
(C [ c ,-]) .F-hom f k = k ⋆⟨ C ⟩ f
(C [ c ,-]) .F-id = funExt λ _ → C .⋆IdR _
(C [ c ,-]) .F-seq _ _ = funExt λ _ → sym (C .⋆Assoc _ _ _)
module _ {C : Category ℓ ℓ'} {F : Functor C (SET ℓ')} where
open NatTrans
-- natural transformations by pre/post composition
preComp : {x y : C .ob}
→ (f : C [ x , y ])
→ C [ x ,-] ⇒ F
→ C [ y ,-] ⇒ F
preComp f α .N-ob c k = (α ⟦ c ⟧) (f ⋆⟨ C ⟩ k)
preComp f α .N-hom {x = c} {d} k
= (λ l → (α ⟦ d ⟧) (f ⋆⟨ C ⟩ (l ⋆⟨ C ⟩ k)))
≡[ i ]⟨ (λ l → (α ⟦ d ⟧) (⋆Assoc C f l k (~ i))) ⟩
(λ l → (α ⟦ d ⟧) (f ⋆⟨ C ⟩ l ⋆⟨ C ⟩ k))
≡[ i ]⟨ (λ l → (α .N-hom k) i (f ⋆⟨ C ⟩ l)) ⟩
(λ l → (F ⟪ k ⟫) ((α ⟦ c ⟧) (f ⋆⟨ C ⟩ l)))
∎
-- properties
-- TODO: move to own file
open CatIso renaming (inv to cInv)
open Iso
Iso→CatIso : ∀ {A B : (SET ℓ) .ob}
→ Iso (fst A) (fst B)
→ CatIso (SET ℓ) A B
Iso→CatIso is .mor = is .fun
Iso→CatIso is .cInv = is .inv
Iso→CatIso is .sec = funExt λ b → is .rightInv b -- is .rightInv
Iso→CatIso is .ret = funExt λ b → is .leftInv b -- is .rightInv
| {
"alphanum_fraction": 0.5151798225,
"avg_line_length": 29.3287671233,
"ext": "agda",
"hexsha": "a76f6a3616bafcbf1027358d01ac67813eb30010",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mzeuner/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/Sets.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mzeuner/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/Sets.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mzeuner/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/Sets.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 932,
"size": 2141
} |
------------------------------------------------------------------------
-- Another implementation of the Fibonacci sequence using tail, along
-- with some other examples
------------------------------------------------------------------------
module ArbitraryChunks where
open import Codata.Musical.Notation
open import Codata.Musical.Stream as S using (Stream; _≈_; _∷_)
open import Data.Bool
open import Data.Nat
open import Data.Vec as V using (Vec; []; _∷_)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; [_])
------------------------------------------------------------------------
-- Stream programs
-- StreamP m n A encodes programs generating streams in chunks of size
-- (at least) m, where the first chunk has size (at least) n.
infixr 5 _∷_
data StreamP (m : ℕ) : ℕ → Set → Set₁ where
[_] : ∀ {A} (xs : ∞ (StreamP m m A)) → StreamP m 0 A
_∷_ : ∀ {n A} (x : A) (xs : StreamP m n A) → StreamP m (suc n) A
forget : ∀ {n A} (xs : StreamP m (suc n) A) → StreamP m n A
tail : ∀ {n A} (xs : StreamP m (suc n) A) → StreamP m n A
zipWith : ∀ {n A B C} (f : A → B → C)
(xs : StreamP m n A) (ys : StreamP m n B) → StreamP m n C
map : ∀ {n A B} (f : A → B) (xs : StreamP m n A) → StreamP m n B
data StreamW (m : ℕ) : ℕ → Set → Set₁ where
[_] : ∀ {A} (xs : StreamP m m A) → StreamW m 0 A
_∷_ : ∀ {n A} (x : A) (xs : StreamW m n A) → StreamW m (suc n) A
forgetW : ∀ {m n A} → StreamW (suc m) (suc n) A → StreamW (suc m) n A
forgetW {n = zero} (x ∷ [ xs ]) = [ x ∷ forget xs ]
forgetW {n = suc n} (x ∷ xs) = x ∷ forgetW xs
tailW : ∀ {m n A} → StreamW m (suc n) A → StreamW m n A
tailW (x ∷ xs) = xs
zipWithW : ∀ {m n A B C} → (A → B → C) →
StreamW m n A → StreamW m n B → StreamW m n C
zipWithW f [ xs ] [ ys ] = [ zipWith f xs ys ]
zipWithW f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWithW f xs ys
mapW : ∀ {m n A B} → (A → B) → StreamW m n A → StreamW m n B
mapW f [ xs ] = [ map f xs ]
mapW f (x ∷ xs) = f x ∷ mapW f xs
whnf : ∀ {m n A} → StreamP (suc m) n A → StreamW (suc m) n A
whnf [ xs ] = [ ♭ xs ]
whnf (x ∷ xs) = x ∷ whnf xs
whnf (forget xs) = forgetW (whnf xs)
whnf (tail xs) = tailW (whnf xs)
whnf (zipWith f xs ys) = zipWithW f (whnf xs) (whnf ys)
whnf (map f xs) = mapW f (whnf xs)
mutual
⟦_⟧W : ∀ {m n A} → StreamW (suc m) (suc n) A → Stream A
⟦ x ∷ [ xs ] ⟧W = x ∷ ♯ ⟦ xs ⟧P
⟦ x ∷ (y ∷ xs) ⟧W = x ∷ ♯ ⟦ y ∷ xs ⟧W
⟦_⟧P : ∀ {m n A} → StreamP (suc m) (suc n) A → Stream A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
------------------------------------------------------------------------
-- Some examples
-- The Fibonacci sequence.
fib : StreamP 1 1 ℕ
fib = 0 ∷ [ ♯ (1 ∷ zipWith _+_ (forget fib) (tail fib)) ]
-- Some sequence which is defined using (tail ∘ tail).
someSequence : StreamP 2 2 ℕ
someSequence =
0 ∷ 1 ∷ [ ♯ (1 ∷ 2 ∷ zipWith _+_ (tail (tail someSequence))
(forget (forget someSequence))) ]
------------------------------------------------------------------------
-- The definition of fib is correct
-- ⟦_⟧ is homomorphic with respect to zipWith/S.zipWith.
mutual
zipWithW-hom :
∀ {m n A B C} (_∙_ : A → B → C)
(xs : StreamW (suc m) (suc n) A) ys →
⟦ zipWithW _∙_ xs ys ⟧W ≈ S.zipWith _∙_ ⟦ xs ⟧W ⟦ ys ⟧W
zipWithW-hom _∙_ (x ∷ [ xs ]) (y ∷ [ ys ]) =
refl ∷ ♯ zipWith-hom _∙_ xs ys
zipWithW-hom _∙_ (x ∷ x′ ∷ xs) (y ∷ y′ ∷ ys) =
refl ∷ ♯ zipWithW-hom _∙_ (x′ ∷ xs) (y′ ∷ ys)
zipWith-hom : ∀ {m n A B C} (_∙_ : A → B → C)
(xs : StreamP (suc m) (suc n) A) ys →
⟦ zipWith _∙_ xs ys ⟧P ≈ S.zipWith _∙_ ⟦ xs ⟧P ⟦ ys ⟧P
zipWith-hom _∙_ xs ys = zipWithW-hom _∙_ (whnf xs) (whnf ys)
-- forget is the identity on streams.
open import MapIterate using (_≈P_; _∷_; _≈⟨_⟩_; _∎; soundP)
mutual
forgetW-lemma : ∀ {m n A} x (xs : StreamW (suc m) (suc n) A) →
⟦ x ∷ forgetW xs ⟧W ≈P x ∷ ♯ ⟦ xs ⟧W
forgetW-lemma x (x′ ∷ [ xs ]) = x ∷ ♯ (_ ≈⟨ forget-lemma x′ xs ⟩ x′ ∷ ♯ (_ ∎))
forgetW-lemma x (x′ ∷ x″ ∷ xs) = x ∷ ♯ (_ ≈⟨ forgetW-lemma x′ (x″ ∷ xs) ⟩ x′ ∷ ♯ (_ ∎) )
forget-lemma : ∀ {m n A} x (xs : StreamP (suc m) (suc n) A) →
⟦ x ∷ forget xs ⟧P ≈P x ∷ ♯ ⟦ xs ⟧P
forget-lemma x xs with whnf xs | P.inspect whnf xs
... | y ∷ y′ ∷ ys | [ eq ] = x ∷ ♯ helper eq
where
helper : whnf xs ≡ y ∷ y′ ∷ ys →
⟦ y ∷ forgetW (y′ ∷ ys) ⟧W ≈P ⟦ xs ⟧P
helper eq rewrite eq = _ ≈⟨ forgetW-lemma y (y′ ∷ ys) ⟩ y ∷ ♯ (_ ∎)
... | y ∷ [ ys ] | [ eq ] = x ∷ ♯ helper eq
where
helper : whnf xs ≡ y ∷ [ ys ] →
⟦ y ∷ forget ys ⟧P ≈P ⟦ xs ⟧P
helper eq rewrite eq = _ ≈⟨ forget-lemma y ys ⟩ y ∷ ♯ (_ ∎)
-- The stream ⟦ fib ⟧P satisfies its intended defining equation.
open import Relation.Binary
module SS {A : Set} = Setoid (S.setoid A)
fib-correct :
⟦ fib ⟧P ≈ 0 ∷ ♯ (1 ∷ ♯ S.zipWith _+_ ⟦ fib ⟧P (S.tail ⟦ fib ⟧P))
fib-correct =
refl ∷ ♯ (refl ∷ ♯ SS.trans
(zipWith-hom _+_ (0 ∷ forget fib′) fib′)
(S.zipWith-cong _+_ (SS.trans (soundP (forget-lemma 0 fib′))
(refl ∷ ♯ SS.refl)) SS.refl))
where fib′ = 1 ∷ zipWith _+_ (forget fib) (tail fib)
------------------------------------------------------------------------
-- map₂
-- A variant of S.map which processes streams in chunks of size 2.
map₂ : {A B : Set} → (A → B) → Stream A → Stream B
map₂ f (x ∷ xs) with ♭ xs
map₂ f (x ∷ xs) | y ∷ ys = f x ∷ ♯ (f y ∷ ♯ map₂ f (♭ ys))
-- This function is extensionally equal to S.map.
map≈map₂ : ∀ {A B} →
(f : A → B) → (xs : Stream A) → S.map f xs ≈ map₂ f xs
map≈map₂ f (x ∷ xs) with ♭ xs | P.inspect ♭ xs
map≈map₂ f (x ∷ xs) | y ∷ ys | [ eq ] = refl ∷ ♯ helper eq
where
map-f-y∷ys = _
helper : ∀ {xs} → xs ≡ y ∷ ys → S.map f xs ≈ map-f-y∷ys
helper refl = refl ∷ ♯ map≈map₂ f (♭ ys)
-- However, as explained in "Beating the Productivity Checker Using
-- Embedded Languages", the two functions are not interchangeable
-- (assuming that pattern matching is evaluated strictly). Let us see
-- what happens when we use the language above. We can define the
-- stream of natural numbers using chunks of size 1 and 2.
nats : StreamP 1 1 ℕ
nats = 0 ∷ [ ♯ map suc nats ]
nats₂ : StreamP 2 2 ℕ
nats₂ = 0 ∷ 1 ∷ [ ♯ map suc nats₂ ]
-- The first use of map corresponds to S.map, and the second to map₂.
-- If we try to use map₂ in the first definition, then we get a type
-- error. The following code is not accepted.
-- nats : StreamP 2 1 ℕ
-- nats = 0 ∷ [ ♯ map suc nats ]
| {
"alphanum_fraction": 0.5082990711,
"avg_line_length": 35.6902173913,
"ext": "agda",
"hexsha": "abde59e26b1ddb908c0edc1b1730182832057ea4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "ArbitraryChunks.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "ArbitraryChunks.agda",
"max_line_length": 90,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "ArbitraryChunks.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 2559,
"size": 6567
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Terms that operate on changes with the Nehemiah plugin.
------------------------------------------------------------------------
module Nehemiah.Change.Term where
open import Data.Integer
open import Nehemiah.Syntax.Type public
open import Nehemiah.Syntax.Term public
open import Nehemiah.Change.Type public
import Parametric.Change.Term Const ΔBase as ChangeTerm
apply-base : ChangeTerm.ApplyStructure
apply-base {base-int} = absV 2 (λ Δx x → add x Δx)
apply-base {base-bag} = absV 2 (λ Δx x → union x Δx)
diff-base : ChangeTerm.DiffStructure
diff-base {base-int} = absV 2 (λ x y → add x (minus y))
diff-base {base-bag} = absV 2 (λ x y → union x (negate y))
nil-base : ChangeTerm.NilStructure
nil-base {base-int} = absV 1 (λ x → intlit (+ 0))
nil-base {base-bag} = absV 1 (λ x → empty)
open ChangeTerm.Structure apply-base diff-base nil-base public
| {
"alphanum_fraction": 0.6220145379,
"avg_line_length": 32.1,
"ext": "agda",
"hexsha": "b2e349402ba7dd270f13d2eebd576c32ccaae7e8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Nehemiah/Change/Term.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Nehemiah/Change/Term.agda",
"max_line_length": 72,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Nehemiah/Change/Term.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 243,
"size": 963
} |
module Numeral.Finite.Equiv where
open import Numeral.Finite
open import Relator.Equals.Proofs.Equiv
open import Structure.Setoid
instance
𝕟-equiv : ∀{n} → Equiv(𝕟(n))
𝕟-equiv = [≡]-equiv
| {
"alphanum_fraction": 0.7422680412,
"avg_line_length": 19.4,
"ext": "agda",
"hexsha": "cf8306e7a70bab4dff8187b21b96f9cb0ab65193",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Finite/Equiv.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Finite/Equiv.agda",
"max_line_length": 39,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Finite/Equiv.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 65,
"size": 194
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra
open import Bundles
open import Structures
module Properties.RingWithoutOne {r₁ r₂} (R : RingWithoutOne r₁ r₂) where
open RingWithoutOne R
import Algebra.Properties.AbelianGroup as AbelianGroupProperties
open import Function.Base using (_$_)
open import Relation.Binary.Reasoning.Setoid setoid
| {
"alphanum_fraction": 0.8016997167,
"avg_line_length": 25.2142857143,
"ext": "agda",
"hexsha": "fa818697c1d4a13782c413a5586f2ddf5acfac3a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/Agda-Algebra",
"max_forks_repo_path": "src/Properties/RingWithoutOne.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_issues_repo_issues_event_max_datetime": "2022-01-31T18:19:52.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-02T20:50:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/Agda-Algebra",
"max_issues_repo_path": "src/Properties/RingWithoutOne.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/Agda-Algebra",
"max_stars_repo_path": "src/Properties/RingWithoutOne.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 85,
"size": 353
} |
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
postulate
A B : Set
@0 a : A
tac : Term → TC ⊤
tac = unify (def (quote a) [])
postulate
f : {@0 @(tactic tac) x : A} → B
test : B
test = f
| {
"alphanum_fraction": 0.6382113821,
"avg_line_length": 13.6666666667,
"ext": "agda",
"hexsha": "3ed277e427be8af328df7646c38bf4aaa050ee2e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "Issue5789.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "Issue5789.agda",
"max_line_length": 35,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6b13364d36eeb60d8ec15eaf8effe23c73401900",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "sseefried/agda",
"max_stars_repo_path": "Issue5789.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 89,
"size": 246
} |
module StateSizedIO.GUI.WxBindingsFFI where
open import Data.Bool.Base
open import Data.Integer
open import Data.Nat
open import Data.Product hiding (map)
open import NativeIO
{-# FOREIGN GHC import qualified GHC.Conc.Sync #-}
{-# FOREIGN GHC import qualified Control.Concurrent #-}
{-# FOREIGN GHC import qualified Data.IORef #-}
{-# FOREIGN GHC import qualified Graphics.UI.WX #-}
{-# FOREIGN GHC import qualified Graphics.UI.WX.Timer #-}
{-# FOREIGN GHC import qualified Graphics.UI.WXCore #-}
{-# FOREIGN GHC import qualified Graphics.UI.WXCore.Events #-}
postulate Frame : Set
{-# COMPILE GHC Frame = type (Graphics.UI.WX.Frame ()) #-}
postulate Button : Set
{-# COMPILE GHC Button = type (Graphics.UI.WX.Button ()) #-}
postulate TextCtrl : Set
{-# COMPILE GHC TextCtrl = type (Graphics.UI.WX.TextCtrl ()) #-}
postulate Timer : Set
{-# COMPILE GHC Timer = type Graphics.UI.WX.Timer.Timer #-}
postulate nativeNewFrame : String -> NativeIO Frame
{-# COMPILE GHC nativeNewFrame = (\s -> Graphics.UI.WX.frame [Graphics.UI.WX.text Graphics.UI.WX.:= "Window"]) #-}
--
-- Frame Layout
--
{-# FOREIGN GHC
setChildrenLayout' :: Graphics.UI.WX.Frame () -> Integer -> Integer -> Integer -> Integer -> IO ()
setChildrenLayout' win rowWidth' marginWidth' vspa' hspa' = do
let rowWidth = fromIntegral rowWidth'
let marginWidth = fromIntegral marginWidth'
let vspa = fromIntegral vspa'
let hspa = fromIntegral hspa'
let list2Matrix n xs = map (\(x ,y)-> (take n) $ (drop (n*x)) y) $ zip [0..] $ replicate (div (length xs) n) xs
blist <- Graphics.UI.WXCore.windowChildren win
putStrLn ("Layout of frame, got " ++ (show $ length $ blist) ++ "children")
let blist' = list2Matrix rowWidth blist
let blist'' = (map . map) Graphics.UI.WX.widget blist'
Graphics.UI.WX.set win [ Graphics.UI.WX.layout Graphics.UI.WX.:= Graphics.UI.WX.margin marginWidth $ Graphics.UI.WX.dynamic $ Graphics.UI.WX.grid vspa hspa $ blist'']
#-}
postulate nativeSetChildredLayout : Frame → ℕ → ℕ → ℕ → ℕ → NativeIO Unit
{-# COMPILE GHC nativeSetChildredLayout = setChildrenLayout' #-}
postulate nativeDoThreadDelay : NativeIO Bool
{-# COMPILE GHC nativeDoThreadDelay = ((Control.Concurrent.threadDelay 100) >>= (\x -> return True)) #-}
postulate nativeSetIdle : Frame -> NativeIO Bool -> NativeIO Unit
{-# COMPILE GHC nativeSetIdle = (\fra prog -> Graphics.UI.WX.set fra [Graphics.UI.WX.on Graphics.UI.WX.idle Graphics.UI.WX.:= prog]) #-}
nativeCreateFrame : NativeIO Frame
nativeCreateFrame =
nativeNewFrame "Start Text" native>>= (\f ->
nativeSetIdle f nativeDoThreadDelay native>>= (\x ->
nativeReturn f))
postulate nativeMakeButton : Frame → String → NativeIO Button
{-# COMPILE GHC nativeMakeButton = (\myFrame str -> Graphics.UI.WX.button myFrame [Graphics.UI.WX.text Graphics.UI.WX.:= (Data.Text.unpack str)]) #-}
postulate nativeMakeTextCtrl : Frame → String → NativeIO TextCtrl
{-# COMPILE GHC nativeMakeTextCtrl = (\myFrame str -> Graphics.UI.WX.entry myFrame [Graphics.UI.WX.text Graphics.UI.WX.:= (Data.Text.unpack str)]) #-}
postulate nativeAddButton : Frame → Button → NativeIO Unit
{-# COMPILE GHC nativeAddButton = (\myFrame bt -> Graphics.UI.WX.set myFrame [Graphics.UI.WX.layout Graphics.UI.WX.:= Graphics.UI.WX.minsize (Graphics.UI.WX.sz 500 400) $ Graphics.UI.WX.column 1 [Graphics.UI.WX.hfill (Graphics.UI.WX.widget bt)]]) #-}
postulate WxColor : Set
{-# COMPILE GHC WxColor = type Graphics.UI.WX.Color #-}
postulate nativeSetColorButton : Button → WxColor → NativeIO Unit
{-# COMPILE GHC nativeSetColorButton = (\ bt co -> Graphics.UI.WX.set bt [ Graphics.UI.WX.color Graphics.UI.WX.:= co] ) #-}
postulate nativeSetColorTextCtrl : TextCtrl → WxColor → NativeIO Unit
{-# COMPILE GHC nativeSetColorTextCtrl = (\ txt co -> Graphics.UI.WX.set txt [ Graphics.UI.WX.color Graphics.UI.WX.:= co] ) #-}
postulate rgb : ℕ → ℕ → ℕ → WxColor
{-# COMPILE GHC rgb = (\ r b g -> Graphics.UI.WX.rgb r g b) #-}
postulate TVar : Set → Set
{-# COMPILE GHC TVar = type Control.Concurrent.STM.TVar.TVar #-}
postulate MVar : Set → Set
{-# COMPILE GHC MVar = type Control.Concurrent.MVar #-}
Var : Set → Set
Var = MVar
postulate
nativeNewVar : {A : Set} → A → NativeIO (Var A)
nativeTakeVar : {A : Set} → Var A → NativeIO A
nativePutVar : {A : Set} → Var A → A → NativeIO Unit
{-# COMPILE GHC nativeNewVar = (\ _ -> Control.Concurrent.newMVar ) #-}
{-# COMPILE GHC nativeTakeVar = (\ _ -> Control.Concurrent.takeMVar ) #-}
{-# COMPILE GHC nativePutVar = (\ _ -> Control.Concurrent.putMVar ) #-}
-- Fire Custom Event
--
postulate nativeFireCustomEvent : Frame → NativeIO Unit
{-# COMPILE GHC nativeFireCustomEvent = (\f -> Graphics.UI.WXCore.commandEventCreate Graphics.UI.WXCore.wxEVT_COMMAND_MENU_SELECTED (Graphics.UI.WXCore.wxID_HIGHEST+1) >>= (\ev -> fmap (\x -> ()) (Graphics.UI.WXCore.evtHandlerProcessEvent f ev))) #-}
postulate nativeRegisterCustomEvent : Frame → NativeIO Unit → NativeIO Unit
{-# COMPILE GHC nativeRegisterCustomEvent = (\win prog -> Graphics.UI.WXCore.evtHandlerOnMenuCommand win (Graphics.UI.WXCore.wxID_HIGHEST+1) (putStrLn " >>> CUSTOM EVENT FIRED <<<" >> Control.Concurrent.forkIO prog >> return ())) #-}
{-
for debugging
postulate nativeRegisterDummyCustomEvent : Frame → NativeIO Unit
{-# COMPILE GHC nativeRegisterDummyCustomEvent = (\win -> Graphics.UI.WXCore.evtHandlerOnMenuCommand win (Graphics.UI.WXCore.wxID_HIGHEST+1) (putStrLn " >>> CUSTOM EVENT FIRED <<<")) #-}
-}
postulate nativeSetButtonHandler : Button → NativeIO Unit → NativeIO Unit
{-# COMPILE GHC nativeSetButtonHandler = (\ bt prog -> Graphics.UI.WX.set bt [Graphics.UI.WX.on Graphics.UI.WX.command Graphics.UI.WX.:= prog ]) #-}
postulate prog : NativeIO Unit
{-# COMPILE GHC prog = (putStrLn "timer goes off!") #-}
postulate nativeSetTimer : Frame → ℤ → NativeIO Unit → NativeIO Timer
{-# COMPILE GHC nativeSetTimer = (\ fra x prog -> Graphics.UI.WX.timer fra [ Graphics.UI.WX.interval Graphics.UI.WX.:= (fromInteger x) , Graphics.UI.WX.on Graphics.UI.WX.command Graphics.UI.WX.:= prog ]) #-}
postulate ThreadId : Set
{-# COMPILE GHC ThreadId = type GHC.Conc.Sync.ThreadId #-}
postulate forkIO : NativeIO Unit → NativeIO ThreadId
{-# COMPILE GHC forkIO = GHC.Conc.Sync.forkIO #-}
postulate Bitmap : Set
{-# COMPILE GHC Bitmap = type (Graphics.UI.WXCore.Bitmap ()) #-}
postulate bitmap : String → Bitmap
{-# COMPILE GHC bitmap = (\s -> Graphics.UI.WX.bitmap (Data.Text.unpack s)) #-}
postulate DC : Set
{-# COMPILE GHC DC = type (Graphics.UI.WXCore.DC ()) #-}
postulate Rect : Set
{-# COMPILE GHC Rect = type Graphics.UI.WXCore.Rect #-}
postulate nativeSetClickRight : Frame → NativeIO Unit → NativeIO Unit
{-# COMPILE GHC nativeSetClickRight = (\ fra prog -> Graphics.UI.WX.set fra [Graphics.UI.WX.on Graphics.UI.WX.clickRight Graphics.UI.WX.:= (\x -> prog)]) #-}
postulate nativeSetOnPaint : Frame → (DC → Rect → NativeIO Unit) → NativeIO Unit
{-# COMPILE GHC nativeSetOnPaint = (\ fra prog -> Graphics.UI.WX.set fra [Graphics.UI.WX.on Graphics.UI.WX.paint Graphics.UI.WX.:= prog]) #-}
postulate nativeRepaint : Frame → NativeIO Unit
{-# COMPILE GHC nativeRepaint = Graphics.UI.WX.repaint #-}
Point : Set
Point = (ℤ × ℤ)
postulate NativePoint : Set
{-# COMPILE GHC NativePoint = type Graphics.UI.WXCore.Point #-}
postulate nativePoint : ℤ → ℤ → NativePoint
{-# COMPILE GHC nativePoint = (\ x y -> Graphics.UI.WXCore.point (fromInteger x) (fromInteger y)) #-}
postulate nativeDrawBitmapNativePoint : DC → Bitmap → NativePoint → Bool → NativeIO Unit
{-# COMPILE GHC nativeDrawBitmapNativePoint = (\ d bi p bo -> Graphics.UI.WX.drawBitmap d bi p bo [] ) #-}
nativeDrawBitmap : DC → Bitmap → Point → Bool → NativeIO Unit
nativeDrawBitmap d bi (x , y) bo = nativeDrawBitmapNativePoint d bi (nativePoint x y) bo
{-# FOREIGN GHC import Graphics.UI.WXCore.WxcClassesAL #-}
postulate nativeBitmapGetWidth : Bitmap → NativeIO ℤ
{-# COMPILE GHC nativeBitmapGetWidth = (\ b -> fmap fromIntegral (Graphics.UI.WXCore.WxcClassesAL.bitmapGetWidth b)) #-}
postulate start : NativeIO Unit → NativeIO Unit
{-# COMPILE GHC start = Graphics.UI.WX.start #-}
--
-- Note: we add the "key pressed" event to a button
-- and not to a frame, because of a bug in wxHaskell that prevents
-- adding a key pressed event to a frame (at least on linux plattforms).
--
postulate
Key : Set
showKey : Key -> String
nativeSetKeyHandler : Button → (Key → NativeIO Unit) → NativeIO Unit
{-# COMPILE GHC Key = type Graphics.UI.WXCore.Events.Key #-}
{-# COMPILE GHC showKey = (\ k -> (Data.Text.pack (Graphics.UI.WXCore.Events.showKey k))) #-}
{-# COMPILE GHC nativeSetKeyHandler = (\bt prog -> Graphics.UI.WX.set bt [Graphics.UI.WX.on Graphics.UI.WX.anyKey Graphics.UI.WX.:= prog]) #-}
--
-- Delete Objects
--
-- note: can be solved with instance arguments in the future
postulate objectDeleteFrame : Frame → NativeIO Unit
{-# COMPILE GHC objectDeleteFrame = (\f -> Graphics.UI.WX.objectDelete f) #-}
postulate nativeDeleteButton : Button → NativeIO Unit
{-# COMPILE GHC nativeDeleteButton = (\f -> Graphics.UI.WX.objectDelete f) #-}
postulate nativeDeleteTextCtrl : TextCtrl → NativeIO Unit
{-# COMPILE GHC nativeDeleteTextCtrl = (\f -> Graphics.UI.WX.objectDelete f) #-}
| {
"alphanum_fraction": 0.7065758166,
"avg_line_length": 37.2822580645,
"ext": "agda",
"hexsha": "8b16b8ac024729d3b450378d5f98d0334945af97",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "stephanadls/state-dependent-gui",
"max_forks_repo_path": "src/StateSizedIO/GUI/WxBindingsFFI.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "stephanadls/state-dependent-gui",
"max_issues_repo_path": "src/StateSizedIO/GUI/WxBindingsFFI.agda",
"max_line_length": 250,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "stephanadls/state-dependent-gui",
"max_stars_repo_path": "src/StateSizedIO/GUI/WxBindingsFFI.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z",
"num_tokens": 2461,
"size": 9246
} |
{-# OPTIONS --type-in-type #-}
module BialgebraSorting where
import Relation.Binary.PropositionalEquality
open Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Function
open import Data.Product using (Σ; _,_; proj₁; proj₂)
record Functor (F : Set → Set) : Set where
field
map : {A B : Set} → (A → B) → F A → F B
map-∘ : {A B C : Set} {f : A → B} {g : B → C} → map g ∘ map f ≡ map (g ∘ f)
map-id : {A : Set} → map (id {A = A}) ≡ id
postulate
extensionality : {S : Set}{T : S -> Set}
{f g : (x : S) -> T x} ->
((x : S) -> f x ≡ g x) ->
f ≡ g
record InitialAlgebra {F : Set → Set} (F-Functor : Functor F) : Set where
open Functor F-Functor
field
Mu : Set
In : F Mu → Mu
inᵒ : Mu → F Mu
In-inᵒ : In ∘ inᵒ ≡ id
inᵒ-In : inᵒ ∘ In ≡ id
fold
: {A : Set} (f : F A → A)
→ Mu
→ A
fold-∘
: {A : Set} (f : F A → A)
→ (x : F Mu)
→ fold f (In x) ≡ f (map (fold f) x)
fold-unique
: {A : Set} {f : F A → A}
→ (h : Mu → A)
→ ((y : F Mu) → h (In y) ≡ f (map h y))
→ (x : Mu)
→ h x ≡ fold f x
record TerminalCoalgebra {F : Set → Set} (F-Functor : Functor F) : Set where
open Functor F-Functor
field
Nu : Set
Out : Nu → F Nu
outᵒ : F Nu → Nu
Out-outᵒ : Out ∘ outᵒ ≡ id
outᵒ-Out : outᵒ ∘ Out ≡ id
unfold : {A : Set} → (A → F A) → A → Nu
unfold-∘
: {A : Set} (f : A → F A)
→ (x : A)
→ Out (unfold f x) ≡ map (unfold f) (f x)
unfold-unique
: {A : Set} {f : A → F A}
→ (h : A → Nu)
→ ((y : A) → Out (unfold f y) ≡ map (unfold f) (f y))
→ (x : A)
→ h x ≡ unfold f x
module Example {F : Set → Set} {F-Functor : Functor F} (alg : InitialAlgebra F-Functor) where
open Functor F-Functor
open InitialAlgebra alg
{-# TERMINATING #-}
in-is-in
: inᵒ ≡ fold (map In)
in-is-in = extensionality $ \ x →
let f = map In in
begin
inᵒ x
≡⟨⟩
id (inᵒ x)
≡⟨ cong (_$ inᵒ x) $ sym map-id ⟩
map id (inᵒ x)
≡⟨ cong (\p → map p (inᵒ x)) $ sym In-inᵒ ⟩
map (In ∘ inᵒ) (inᵒ x)
≡⟨ cong (_$ inᵒ x) $ sym map-∘ ⟩
map In (map inᵒ (inᵒ x))
≡⟨ cong (\p → map In ((map p) (inᵒ x))) in-is-in ⟩
map In (map (fold (map In)) (inᵒ x))
≡⟨⟩
map In (map (fold f) (inᵒ x))
≡⟨⟩
f (map (fold f) (inᵒ x))
≡⟨ sym $ fold-∘ f (inᵒ x) ⟩
fold f (In (inᵒ x))
≡⟨ cong (\p → fold f (p x)) In-inᵒ ⟩
fold f x
≡⟨⟩
fold (map In) x
∎
module Paper
{F : Set → Set}
{F-Functor : Functor F}
(alg : InitialAlgebra F-Functor)
(coalg : TerminalCoalgebra F-Functor) where
open Functor F-Functor public
open InitialAlgebra alg public
open TerminalCoalgebra coalg public
{-# TERMINATING #-}
downcast : Nu → Mu
downcast = In ∘ map downcast ∘ Out
upcast : Mu → Nu
upcast = fold outᵒ
data List (A : Set) (K : Set) : Set where
Nil : List A K
Cons : A → K → List A K
data Ordering : Set where
LT : Ordering
EQ : Ordering
GT : Ordering
record Ord (A : Set) : Set where
field
compare : A → A → Ordering
data Bool : Set where
false : Bool
true : Bool
_&&_ : Bool → Bool → Bool
false && _ = false
true && b = b
not : Bool → Bool
not false = true
not true = false
_==_ : Ordering → Ordering → Bool
_==_ EQ EQ = true
_==_ LT LT = true
_==_ GT GT = true
_==_ _ _ = false
_!=_ : Ordering → Ordering → Bool
_!=_ a b = not (a == b)
data Maybe (A : Set) : Set where
just : A → Maybe A
nothing : Maybe A
module Paper₂
{A : Set}
(Ord-A : Ord A)
(List-Functor : Functor (List A))
(alg : InitialAlgebra List-Functor)
(coalg : TerminalCoalgebra List-Functor) where
open Paper alg coalg
open Ord Ord-A public
is-sorted : Nu → Bool
is-sorted = proj₂ ∘ fold (\ { Nil → nothing , true
; (Cons a (nothing , x)) → just a , x
; (Cons a (just a' , x)) → just a' , (x && (compare a a' != GT))
} ) ∘ downcast
-- SortedList : {A : Set} → Ord A → Set
-- SortedList ord = Σ Nu is-sorted
open Functor
record Bialgebra
{F G : Set → Set}
{F-functor : Functor F}
{G-functor : Functor G}
(f : {X : Set} → F (G X) → G (F X)) : Set where
field
a : {X : Set} → F X → X
c : {X : Set} → X → G X
bialgebra-proof
: {X : Set}
→ c {X} ∘ a ≡ map G-functor a ∘ f ∘ map F-functor c
bubbleSort : Bialgebra ?
bubbleSort = ?
| {
"alphanum_fraction": 0.5002180549,
"avg_line_length": 24.3936170213,
"ext": "agda",
"hexsha": "ba2efd44d7a9e94039f303df8de777b4881a9fec",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-02-17T08:46:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-02-17T08:46:57.000Z",
"max_forks_repo_head_hexsha": "cf6faf7103acd54c67f3464b1968387a98dd8fa2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "dominiquedevriese/reviews",
"max_forks_repo_path": "agda-src/BialgebraSorting.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "cf6faf7103acd54c67f3464b1968387a98dd8fa2",
"max_issues_repo_issues_event_max_datetime": "2022-02-17T16:51:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-02-17T09:10:00.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "dominiquedevriese/reviews",
"max_issues_repo_path": "agda-src/BialgebraSorting.agda",
"max_line_length": 94,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "cf6faf7103acd54c67f3464b1968387a98dd8fa2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "dominiquedevriese/reviews",
"max_stars_repo_path": "agda-src/BialgebraSorting.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-22T15:07:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-08T00:57:08.000Z",
"num_tokens": 1757,
"size": 4586
} |
------------------------------------------------------------------------------
-- Testing the use of various options using only an OPTIONS pragma
------------------------------------------------------------------------------
{-# OPTIONS --exact-split
--no-sized-types
--no-universe-polymorphism
--without-K
#-}
-- (24 January 2014) From the Agda implementation, the above list of
-- options is saved in the interface file as an one element list,
-- where the element is a list of the three options.
module OptionsLList where
postulate
D : Set
∃ : (A : D → Set) → Set
postulate foo : (A : D → Set) → ∃ A → ∃ A
{-# ATP prove foo #-}
| {
"alphanum_fraction": 0.4837278107,
"avg_line_length": 29.3913043478,
"ext": "agda",
"hexsha": "6dd4bf4318dfa204c43bd2e0117bb292eef8f2fc",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/non-fol-theorems/OptionsLList.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/non-fol-theorems/OptionsLList.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/non-fol-theorems/OptionsLList.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 144,
"size": 676
} |
------------------------------------------------------------------------
-- The All predicate, defined using _∈_
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module List.All {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bag-equivalence eq
open import Bijection eq as Bijection using (_↔_)
import Equality.Groupoid eq as EG
open import Function-universe eq as F hiding (id; _∘_)
open import Groupoid eq
open import H-level eq
open import H-level.Closure eq
open import List eq as L using (_++_)
open import Monad eq hiding (map)
open import Vec.Function eq as Vec using (Vec)
private
variable
a b ℓ p q : Level
A B : Type a
P : A → Type p
Q : A → Type q
k x y : A
n : ℕ
xs ys : List A
-- All P xs means that P holds for every element of xs.
All : {A : Type a} → (A → Type p) → List A → Type (a ⊔ p)
All P xs = ∀ x → x ∈ xs → P x
-- The type xs ⊆ ys means that every element of xs is also an element
-- of ys.
infix 4 _⊆_
_⊆_ : {A : Type a} → List A → List A → Type a
xs ⊆ ys = All (_∈ ys) xs
-- The _⊆_ relation matches _∼[ implication ]_.
⊆↔∼[implication] : xs ⊆ ys ↔ xs ∼[ implication ] ys
⊆↔∼[implication] {xs = xs} {ys = ys} =
xs ⊆ ys ↔⟨⟩
All (_∈ ys) xs ↔⟨⟩
(∀ x → x ∈ xs → x ∈ ys) ↔⟨⟩
xs ∼[ implication ] ys □
-- Some rearrangement lemmas.
All-[] :
∀ {k} {A : Type a} (P : A → Type p) →
Extensionality? k a (a ⊔ p) →
All P [] ↝[ k ] ⊤
All-[] {a = a} {k = k} {A} P ext =
All P [] ↔⟨⟩
(∀ y → y ∈ [] → P y) ↔⟨⟩
(∀ y → ⊥ → P y) ↝⟨ (∀-cong ext λ _ → Π⊥↔⊤ (lower-extensionality? k a a ext)) ⟩
(A → ⊤) ↔⟨ →-right-zero ⟩□
⊤ □
module _ {k} {A : Type a} {P : A → Type p}
(ext : Extensionality? k a (a ⊔ p)) where
private
ext′ : Extensionality? k a p
ext′ = lower-extensionality? k a a ext
All-∷ : All P (x ∷ xs) ↝[ k ] P x × All P xs
All-∷ {x = x} {xs = xs} =
All P (x ∷ xs) ↔⟨⟩
(∀ y → y ∈ x ∷ xs → P y) ↔⟨⟩
(∀ y → y ≡ x ⊎ y ∈ xs → P y) ↝⟨ ∀-cong ext (λ _ → Π⊎↔Π×Π ext′) ⟩
(∀ y → (y ≡ x → P y) × (y ∈ xs → P y)) ↔⟨ ΠΣ-comm ⟩
(∀ y → y ≡ x → P y) × (∀ y → y ∈ xs → P y) ↝⟨ (×-cong₁ λ _ → ∀-cong ext λ _ → →-cong₁ ext′ ≡-comm) ⟩
(∀ y → x ≡ y → P y) × (∀ y → y ∈ xs → P y) ↝⟨ inverse-ext? (λ ext → ∀-intro _ ext) ext ×-cong F.id ⟩□
P x × All P xs □
All-++ : All P (xs ++ ys) ↝[ k ] All P xs × All P ys
All-++ {xs = xs} {ys = ys} =
All P (xs ++ ys) ↔⟨⟩
(∀ x → x ∈ xs ++ ys → P x) ↝⟨ (∀-cong ext λ _ → →-cong₁ ext′ (Any-++ _ _ _)) ⟩
(∀ x → x ∈ xs ⊎ x ∈ ys → P x) ↝⟨ (∀-cong ext λ _ → Π⊎↔Π×Π ext′) ⟩
(∀ x → (x ∈ xs → P x) × (x ∈ ys → P x)) ↔⟨ ΠΣ-comm ⟩
(∀ x → x ∈ xs → P x) × (∀ x → x ∈ ys → P x) ↔⟨⟩
All P xs × All P ys □
All-concat : All P (L.concat xs) ↝[ k ] All (All P) xs
All-concat {xs = xss} =
(∀ x → x ∈ L.concat xss → P x) ↝⟨ ∀-cong ext (λ _ → →-cong₁ ext′ (Any-concat _ _)) ⟩
(∀ x → Any (x ∈_) xss → P x) ↝⟨ ∀-cong ext (λ _ → →-cong₁ ext′ (Any-∈ _ _)) ⟩
(∀ x → (∃ λ xs → x ∈ xs × xs ∈ xss) → P x) ↝⟨ ∀-cong ext (λ _ → from-bijection currying) ⟩
(∀ x → ∀ xs → x ∈ xs × xs ∈ xss → P x) ↔⟨ Π-comm ⟩
(∀ xs → ∀ x → x ∈ xs × xs ∈ xss → P x) ↝⟨ ∀-cong ext (λ _ → ∀-cong ext λ _ → from-bijection currying) ⟩
(∀ xs → ∀ x → x ∈ xs → xs ∈ xss → P x) ↝⟨ ∀-cong ext (λ _ → ∀-cong ext λ _ → from-bijection Π-comm) ⟩
(∀ xs → ∀ x → xs ∈ xss → x ∈ xs → P x) ↝⟨ ∀-cong ext (λ _ → from-bijection Π-comm) ⟩□
(∀ xs → xs ∈ xss → ∀ x → x ∈ xs → P x) □
All-map :
∀ {k} {A : Type a} {B : Type b} {P : B → Type p}
{f : A → B} {xs : List A} →
(ext : Extensionality? k (a ⊔ b) (a ⊔ b ⊔ p)) →
All P (L.map f xs) ↝[ k ] All (P ∘ f) xs
All-map {a = a} {b = b} {p = p} {k = k} {P = P} {f} {xs} ext =
(∀ x → x ∈ L.map f xs → P x) ↝⟨ (∀-cong ext₁ λ _ → →-cong₁ ext₂ (Any-map _ _ _)) ⟩
(∀ x → Any (λ y → x ≡ f y) xs → P x) ↝⟨ (∀-cong ext₃ λ _ → →-cong₁ ext₄ (Any-∈ _ _)) ⟩
(∀ x → (∃ λ y → x ≡ f y × y ∈ xs) → P x) ↝⟨ (∀-cong ext₃ λ _ → from-bijection currying) ⟩
(∀ x → ∀ y → x ≡ f y × y ∈ xs → P x) ↝⟨ (∀-cong ext₃ λ _ → ∀-cong ext₅ λ _ → from-bijection currying) ⟩
(∀ x → ∀ y → x ≡ f y → y ∈ xs → P x) ↔⟨ Π-comm ⟩
(∀ x → ∀ y → y ≡ f x → x ∈ xs → P y) ↝⟨ (∀-cong ext₅ λ _ → ∀-cong ext₃ λ _ → →-cong₁ ext₆ ≡-comm) ⟩
(∀ x → ∀ y → f x ≡ y → x ∈ xs → P y) ↝⟨ (∀-cong ext₅ λ _ → inverse-ext? (λ ext → ∀-intro _ ext) ext₃) ⟩□
(∀ x → x ∈ xs → P (f x)) □
where
ext₁ = lower-extensionality? k a a ext
ext₂ = lower-extensionality? k a (a ⊔ b) ext
ext₃ = lower-extensionality? k a lzero ext
ext₄ = lower-extensionality? k lzero (a ⊔ b) ext
ext₅ = lower-extensionality? k b lzero ext
ext₆ = lower-extensionality? k a b ext
All->>= :
∀ {k} {A B : Type ℓ} {P : B → Type p} {f : A → List B} {xs : List A} →
(ext : Extensionality? k ℓ (ℓ ⊔ p)) →
All P (xs >>= f) ↝[ k ] All (All P ∘ f) xs
All->>= {P = P} {f = f} {xs = xs} ext =
All P (L.concat (L.map f xs)) ↝⟨ All-concat ext ⟩
All (All P) (L.map f xs) ↝⟨ All-map ext ⟩□
All (All P ∘ f) xs □
All-const :
{A : Type a} {B : Type b} {xs : List B} →
Extensionality? k b a →
All (const A) xs ↝[ k ] Vec A (L.length xs)
All-const {A = A} {xs = xs} ext =
(∀ x → x ∈ xs → A) ↔⟨ inverse currying ⟩
(∃ (_∈ xs) → A) ↝⟨ →-cong₁ ext (Fin-length _) ⟩□
(Fin (L.length xs) → A) □
private
-- The following lemma that relates All-const and Fin-length holds
-- by definition.
All-const-Fin-length :
∀ {xs : List A} {bs : All (const B) xs} {i} →
All-const _ bs i ≡
uncurry bs (_↔_.from (Fin-length xs) i)
All-const-Fin-length = refl _
All-const-replicate :
{A : Type a} →
Extensionality? k lzero a →
All (const A) (L.replicate n tt) ↝[ k ] Vec A n
All-const-replicate {n = n} {A = A} ext =
All (const A) (L.replicate n tt) ↝⟨ All-const ext ⟩
Vec A (L.length (L.replicate n tt)) ↝⟨ →-cong₁ ext $ ≡⇒↝ bijection $ cong Fin (L.length-replicate _) ⟩□
Vec A n □
All-Σ :
{A : Type a} {P : A → Type p} {Q : ∀ x → P x → Type q} {xs : List A} →
Extensionality? k a (a ⊔ p ⊔ q) →
All (λ x → Σ (P x) (Q x)) xs ↝[ k ]
∃ λ (ps : All P xs) → ∀ x (x∈xs : x ∈ xs) → Q x (ps x x∈xs)
All-Σ {P = P} {Q = Q} {xs = xs} ext =
All (λ x → Σ (P x) (Q x)) xs ↔⟨⟩
(∀ x → x ∈ xs → Σ (P x) (Q x)) ↝⟨ (∀-cong ext λ _ → from-isomorphism ΠΣ-comm) ⟩
(∀ x → ∃ λ (ps : x ∈ xs → P x) →
(x∈xs : x ∈ xs) → Q x (ps x∈xs)) ↔⟨ ΠΣ-comm ⟩
(∃ λ (ps : ∀ x → x ∈ xs → P x) →
∀ x (x∈xs : x ∈ xs) → Q x (ps x x∈xs)) ↔⟨⟩
(∃ λ (ps : All P xs) → ∀ x (x∈xs : x ∈ xs) → Q x (ps x x∈xs)) □
-- Some abbreviations.
nil : All P []
nil {P = P} = _⇔_.from (All-[] P _) _
cons : P x → All P xs → All P (x ∷ xs)
cons = curry (_⇔_.from (All-∷ _))
head : All P (x ∷ xs) → P x
head = proj₁ ∘ _⇔_.to (All-∷ _)
tail : All P (x ∷ xs) → All P xs
tail = proj₂ ∘ _⇔_.to (All-∷ _)
append : All P xs → All P ys → All P (xs ++ ys)
append = curry (_⇔_.from (All-++ _))
-- All preserves h-levels (assuming extensionality).
H-level-All :
{A : Type a} {P : A → Type p} →
Extensionality a (a ⊔ p) →
∀ n →
(∀ x → H-level n (P x)) →
(∀ xs → H-level n (All P xs))
H-level-All {a = a} ext n h xs =
Π-closure ext n λ _ →
Π-closure (lower-extensionality a a ext) n λ _ →
h _
-- Some lemmas related to append.
append-Any-++-inj₁ :
∀ {xs ys} {ps : All P xs} {qs : All P ys}
(x∈xs : x ∈ xs) →
append ps qs _ (_↔_.from (Any-++ _ _ _) (inj₁ x∈xs)) ≡
ps _ x∈xs
append-Any-++-inj₁ {P = P} {x = x} {ps = ps} {qs} x∈xs =
append ps qs _ (_↔_.from (Any-++ _ _ _) (inj₁ x∈xs)) ≡⟨⟩
[ ps _ , qs _ ] (_↔_.to (Any-++ _ _ _)
(_↔_.from (Any-++ _ _ _) (inj₁ x∈xs))) ≡⟨ cong [ ps _ , qs _ ] (_↔_.right-inverse-of (Any-++ _ _ _) _) ⟩
[_,_] {C = λ _ → P x} (ps _) (qs _) (inj₁ x∈xs) ≡⟨⟩
ps _ x∈xs ∎
append-Any-++-inj₂ :
∀ xs {ys} {ps : All P xs} {qs : All P ys} {y∈ys : y ∈ ys} →
append ps qs _ (_↔_.from (Any-++ _ xs _) (inj₂ y∈ys)) ≡
qs _ y∈ys
append-Any-++-inj₂ {P = P} {y = y} xs {ps = ps} {qs} {y∈ys} =
append ps qs _ (_↔_.from (Any-++ _ xs _) (inj₂ y∈ys)) ≡⟨⟩
[ ps _ , qs _ ] (_↔_.to (Any-++ _ _ _)
(_↔_.from (Any-++ _ xs _) (inj₂ y∈ys))) ≡⟨ cong [ ps _ , qs _ ] (_↔_.right-inverse-of (Any-++ _ _ _) _) ⟩
[_,_] {C = λ _ → P y} (ps _) (qs _) (inj₂ y∈ys) ≡⟨⟩
qs _ y∈ys ∎
-- Some congruence lemmas.
All-cong :
∀ {k} {A : Type a} {P : A → Type p} {Q : A → Type q} {xs ys} →
Extensionality? ⌊ k ⌋-sym a (a ⊔ p ⊔ q) →
(∀ x → P x ↝[ ⌊ k ⌋-sym ] Q x) →
xs ∼[ ⌊ k ⌋-sym ] ys →
All P xs ↝[ ⌊ k ⌋-sym ] All Q ys
All-cong {a = a} {k = k} {P = P} {Q} {xs} {ys} ext P↝Q xs∼ys =
All P xs ↔⟨⟩
(∀ x → x ∈ xs → P x) ↝⟨ ∀-cong ext (λ _ → →-cong (lower-extensionality? ⌊ k ⌋-sym a a ext) (xs∼ys _) (P↝Q _)) ⟩
(∀ x → x ∈ ys → Q x) ↔⟨⟩
All Q ys □
All-cong-→ :
(∀ x → P x → Q x) →
ys ∼[ implication ] xs →
All P xs → All Q ys
All-cong-→ {P = P} {Q = Q} {ys = ys} {xs = xs} P→Q ys∼xs =
All P xs ↔⟨⟩
(∀ x → x ∈ xs → P x) ↝⟨ ∀-cong _ (λ _ → →-cong-→ (ys∼xs _) (P→Q _)) ⟩
(∀ x → x ∈ ys → Q x) ↔⟨⟩
All Q ys □
map : (∀ x → P x → Q x) → ys ⊆ xs → All P xs → All Q ys
map P→Q ys∼xs = All-cong-→ P→Q ys∼xs
map₁ : (∀ x → P x → Q x) → All P xs → All Q xs
map₁ P→Q = map P→Q (λ _ → id)
map₂ : ys ⊆ xs → All P xs → All P ys
map₂ ys⊆xs = map (λ _ → id) ys⊆xs
private
map₁-∘ :
∀ {P : A → Type p} {xs} {f : ∀ x → P x → Q x} {ps : All P xs} →
map₁ f ps ≡ λ _ → f _ ∘ ps _
map₁-∘ = refl _
map₂-∘ :
∀ {xs ys} {ys⊆xs : ys ⊆ xs} {ps : All P xs} →
map₂ ys⊆xs ps ≡ λ _ → ps _ ∘ ys⊆xs _
map₂-∘ = refl _
-- Some properties that hold by definition.
map₂∘map₂ :
∀ {xs ys zs} {xs⊆ys : xs ⊆ ys} {ys⊆zs : ys ⊆ zs} {ps : All P zs} →
map₂ xs⊆ys (map₂ ys⊆zs ps) ≡ map₂ (map₁ ys⊆zs xs⊆ys) ps
map₂∘map₂ = refl _
map₂-inj₂-∘ :
∀ {xs ys} {f : ys ⊆ xs} {p : P x} {ps : All P xs} →
map₂ (λ _ → inj₂ ∘ f _) (cons p ps) ≡ map₂ f ps
map₂-inj₂-∘ = refl _
map₂-id :
∀ {xs} {ps : All P xs} →
map₂ (λ _ → id) ps ≡ ps
map₂-id = refl _
map₂-inj₂ :
∀ {xs} {p : P x} {ps : All P xs} →
map₂ (λ _ → inj₂) (cons p ps) ≡ ps
map₂-inj₂ = refl _
-- Some rearrangement lemmas for map₂.
map₂-⊎-map-id :
{A : Type a} {P : A → Type p} →
Extensionality a (a ⊔ p) →
∀ {x xs ys} {f : ys ⊆ xs} {p : P x} {ps : All P xs} →
map₂ (λ _ → ⊎-map id (f _)) (cons p ps) ≡ cons p (map₂ f ps)
map₂-⊎-map-id {a = a} ext {f = f} {p} {ps} =
apply-ext ext λ _ →
apply-ext (lower-extensionality lzero a ext)
[ (λ _ → refl _) , (λ _ → refl _) ]
map₂-⊎-map-id-inj₂ :
{A : Type a} {P : A → Type p} →
Extensionality a (a ⊔ p) →
∀ {x y xs} {p : P x} {q : P y} {ps : All P xs} →
map₂ (λ _ → ⊎-map id inj₂) (cons p (cons q ps)) ≡ cons p ps
map₂-⊎-map-id-inj₂ ext {p = p} {q} {ps} =
map₂ (λ _ → ⊎-map id inj₂) (cons p (cons q ps)) ≡⟨ map₂-⊎-map-id ext ⟩
cons p (map₂ (λ _ → inj₂) (cons q ps)) ≡⟨⟩
cons p ps ∎
map₂-++-cong :
{A : Type a} {P : A → Type p} →
Extensionality a (a ⊔ p) →
∀ xs₁ {ys₁ xs₂ ys₂} {ps : All P xs₂} {qs : All P ys₂}
{f : xs₁ ⊆ xs₂} {g : ys₁ ⊆ ys₂} →
map₂ (++-cong f g) (append ps qs) ≡
append (map₂ f ps) (map₂ g qs)
map₂-++-cong {a = a} ext _ {ps = ps} {qs} {f} {g} =
apply-ext ext λ _ →
apply-ext (lower-extensionality lzero a ext) λ x∈ →
let lemma : ∀ x → [ ps _ , qs _ ] (⊎-map (f _) (g _) x) ≡
[ ps _ ∘ f _ , qs _ ∘ g _ ] x
lemma = [ (λ _ → refl _) , (λ _ → refl _) ]
in
[ ps _ , qs _ ] (_↔_.to (Any-++ _ _ _) (_↔_.from (Any-++ _ _ _)
(⊎-map (f _) (g _) (_↔_.to (Any-++ _ _ _) x∈)))) ≡⟨ cong [ ps _ , qs _ ] (_↔_.right-inverse-of (Any-++ _ _ _) _) ⟩
[ ps _ , qs _ ] (⊎-map (f _) (g _) (_↔_.to (Any-++ _ _ _) x∈)) ≡⟨ lemma (_↔_.to (Any-++ _ _ _) x∈) ⟩∎
[ ps _ ∘ f _ , qs _ ∘ g _ ] (_↔_.to (Any-++ _ _ _) x∈) ∎
| {
"alphanum_fraction": 0.440830721,
"avg_line_length": 35.5431754875,
"ext": "agda",
"hexsha": "3c34c445c3bc8e5700dd45dd8261bf7018da4323",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/List/All.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/List/All.agda",
"max_line_length": 138,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/List/All.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 5704,
"size": 12760
} |
open import Common.Prelude
test : Nat → Nat
test = _Common.Prelude.+ 2
| {
"alphanum_fraction": 0.7222222222,
"avg_line_length": 14.4,
"ext": "agda",
"hexsha": "a1f4d2f1fa29b4385c7178576122f8828abdcdba",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Sections-5.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Sections-5.agda",
"max_line_length": 26,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Sections-5.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 22,
"size": 72
} |
module UniDB.Core where
open import Data.Nat public using (ℕ; suc; zero)
open import Data.Fin public using (Fin; suc; zero)
open import Function public using (id; _∘_)
open import Relation.Binary.PropositionalEquality as PropEq public
using (_≡_; _≢_; refl; sym; cong; cong₂; trans; subst; module ≡-Reasoning)
open ≡-Reasoning public
Inj : {A B : Set} (f : A → B) → Set
Inj {A} f = {x y : A} → f x ≡ f y → x ≡ y
--------------------------------------------------------------------------------
Dom : Set
Dom = ℕ
infixl 10 _∪_
_∪_ : Dom → Dom → Dom
γ ∪ zero = γ
γ ∪ suc δ = suc (γ ∪ δ)
∪-assoc : (γ₁ γ₂ γ₃ : Dom) → γ₁ ∪ (γ₂ ∪ γ₃) ≡ (γ₁ ∪ γ₂) ∪ γ₃
∪-assoc γ₁ γ₂ zero = refl
∪-assoc γ₁ γ₂ (suc γ₃) = cong suc (∪-assoc γ₁ γ₂ γ₃)
--------------------------------------------------------------------------------
STX : Set₁
STX = Dom → Set
MOR : Set₁
MOR = Dom → Dom → Set
--------------------------------------------------------------------------------
Ix : STX
Ix = Fin
| {
"alphanum_fraction": 0.4573170732,
"avg_line_length": 24,
"ext": "agda",
"hexsha": "8225c6b924bbca26ee1d1e1388d6ccd8e5f066a3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Core.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 325,
"size": 984
} |
module hcio where
-- https://github.com/alhassy/AgdaCheatSheet#interacting-with-the-real-world-compilation-haskell-and-io
open import Agda.Builtin.Coinduction using (♯_)
open import Agda.Builtin.Unit using (⊤)
open import Codata.Musical.Colist as CL using (take)
open import Codata.Musical.Costring using (Costring)
open import Data.String as S using (String; fromList)
open import Data.Vec.Bounded as B using (toList)
open import Function using (const; _∘_)
open import IO as IO using ()
import IO.Primitive as Primitive
infixr 1 _>>=_ _>>_
_>>=_ : ∀ {ℓ} {α β : Set ℓ} → IO.IO α → (α → IO.IO β) → IO.IO β
this >>= f = ♯ this IO.>>= λ x → ♯ f x
_>>_ : ∀{ℓ} {α β : Set ℓ} → IO.IO α → IO.IO β → IO.IO β
x >> y = x >>= const y
postulate
getLine∞ : Primitive.IO Costring
{-# FOREIGN GHC
toColist :: [a] -> MAlonzo.Code.Codata.Musical.Colist.AgdaColist a
toColist [] = MAlonzo.Code.Codata.Musical.Colist.Nil
toColist (x : xs) = MAlonzo.Code.Codata.Musical.Colist.Cons x (MAlonzo.RTE.Sharp (toColist xs))
#-}
{-# FOREIGN GHC import Prelude as Haskell #-} -- rename for clarity
{-# COMPILE GHC getLine∞ = fmap toColist Haskell.getLine #-}
getLine : IO.IO String
getLine =
IO.lift (getLine∞ Primitive.>>= (Primitive.return ∘ S.fromList ∘ B.toList ∘ CL.take 100))
| {
"alphanum_fraction": 0.6435354273,
"avg_line_length": 34.225,
"ext": "agda",
"hexsha": "02e0811d08bab08af98cd95f7bc7ab5b34182ee3",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/examples-that-run/xxx/src-agda/hcio.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/examples-that-run/xxx/src-agda/hcio.agda",
"max_line_length": 103,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/examples-that-run/xxx/src-agda/hcio.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 431,
"size": 1369
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.SuspensionMap where
open import Cubical.Homotopy.Group.Base
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Freudenthal
open import Cubical.Homotopy.Connected
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Functions.Morphism
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp renaming (toSusp to σ ; toSuspPointed to σ∙)
open import Cubical.HITs.S1
open import Cubical.Data.Bool hiding (_≟_)
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.HITs.PropositionalTruncation
renaming (rec to pRec ; rec2 to pRec2 ; elim to pElim)
open import Cubical.HITs.SetTruncation
renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim
; elim2 to sElim2 ; elim3 to sElim3 ; map to sMap)
open import Cubical.HITs.Truncation
renaming (rec to trRec)
open Iso
open IsGroup
open IsSemigroup
open IsMonoid
open GroupStr
{-
This file concerns the suspension maps
suspMapΩ : πₙA → πₙ₊₁ΣA and
suspMap : π'ₙA → π'ₙ₊₁ΣA
For instance, we want to transport freudenthal
for suspMapΩ to suspMap by establishing a dependent
path between the two functions.
This gives, in particular, surjectivity of
πₙ₊₁(Sⁿ) → πₙ₊₂(Sⁿ⁺¹) for n ≥ 2.
-}
-- Definition of the suspension functions
suspMap : ∀ {ℓ} {A : Pointed ℓ}(n : ℕ)
→ S₊∙ (suc n) →∙ A
→ S₊∙ (suc (suc n)) →∙ Susp∙ (typ A)
fst (suspMap n f) north = north
fst (suspMap n f) south = north
fst (suspMap {A = A} n f) (merid a i) =
(merid (fst f a) ∙ sym (merid (pt A))) i
snd (suspMap n f) = refl
suspMapΩ∙ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ ((Ω^ n) A)
→∙ ((Ω^ (suc n)) (Susp∙ (typ A)))
fst (suspMapΩ∙ {A = A} zero) a = merid a ∙ sym (merid (pt A))
snd (suspMapΩ∙ {A = A} zero) = rCancel (merid (pt A))
suspMapΩ∙ {A = A} (suc n) = Ω→ (suspMapΩ∙ {A = A} n)
suspMapΩ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ typ ((Ω^ n) A) → typ ((Ω^ (suc n)) (Susp∙ (typ A)))
suspMapΩ {A = A} n = suspMapΩ∙ {A = A} n .fst
suspMapπ' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ π' (suc n) A
→ π' (suc (suc n)) (Susp∙ (typ A))
suspMapπ' n = sMap (suspMap n)
suspMapπ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ π n A → π (suc n) (Susp∙ (typ A))
suspMapπ n = sMap (suspMapΩ n)
{- suspMapΩ
Ωⁿ A --------------------> Ω¹⁺ⁿ (Susp A)
| |
| = | ≃ flipΩ
| Ωⁿ→ σ v
Ωⁿ A -------------------> Ωⁿ (Ω (Susp A))
| |
| |
| ≃ Ω→SphereMap | ≃ Ω→SphereMap
| |
v post∘∙ . σ v
(Sⁿ →∙ A) -------------- > (Sⁿ →∙ Ω (Susp A))
| |
| = | ≃ botᵣ
| |
v suspMap v
(Sⁿ →∙ A) -------------- > (Sⁿ⁺¹→∙ Susp A)
-}
botᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (S₊∙ n →∙ Ω (Susp∙ (typ A)))
→ S₊∙ (suc n) →∙ Susp∙ (typ A)
fst (botᵣ zero (f , p)) base = north
fst (botᵣ zero (f , p)) (loop i) = f false i
snd (botᵣ zero (f , p)) = refl
fst (botᵣ (suc n) (f , p)) north = north
fst (botᵣ (suc n) (f , p)) south = north
fst (botᵣ (suc n) (f , p)) (merid a i) = f a i
snd (botᵣ (suc n) (f , p)) = refl
----- Top square filler -----
top□ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Ω^→ (suc n) (σ∙ A)
≡ (((Iso.fun (flipΩIso (suc n))) , flipΩrefl n)
∘∙ suspMapΩ∙ (suc n))
top□ {A = A} zero =
→∙Homogeneous≡ (isHomogeneousPath _ _)
(funExt λ p → sym (transportRefl _))
top□ {A = A} (suc n) =
cong Ω→ (top□ {A = A} n)
∙ →∙Homogeneous≡
(isHomogeneousPath _ _)
(funExt λ x
→ Ω→∘ (fun (flipΩIso (suc n)) , flipΩrefl n) (suspMapΩ∙ (suc n)) x)
----- Middle square filler -----
module _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ')
(homogB : isHomogeneous B) (f : A →∙ B) where
nat = isNaturalΩSphereMap A B homogB f
mutual
isNatural-Ω→SphereMap : ∀ n p → f ∘∙ Ω→SphereMap n p
≡ Ω→SphereMap n (Ω^→ n f .fst p)
isNatural-Ω→SphereMap 0 p =
→∙Homogeneous≡ homogB (funExt λ {true → f .snd; false → refl})
isNatural-Ω→SphereMap (n@(suc n')) p =
cong (f ∘∙_) (Ω→SphereMap-split n' p)
∙ nat n' (Ω→SphereMapSplit₁ n' p)
∙ cong (ΩSphereMap n') inner
∙ sym (Ω→SphereMap-split n' (Ω^→ n f .fst p))
where
inner : Ω→ (post∘∙ (S₊∙ n') f) .fst (Ω→ (Ω→SphereMap∙ n') .fst p)
≡ Ω→ (Ω→SphereMap∙ n') .fst (Ω^→ (suc n') f .fst p)
inner =
sym (Ω→∘ (post∘∙ (S₊∙ n') f) (Ω→SphereMap∙ n') p)
∙ cong (λ g∙ → Ω→ g∙ .fst p) (isNatural-Ω→SphereMap∙ n')
∙ Ω→∘ (Ω→SphereMap∙ n') (Ω^→ n' f) p
isNatural-Ω→SphereMap∙ : ∀ n
→ post∘∙ (S₊∙ n) f ∘∙ (Ω→SphereMap∙ n)
≡ (Ω→SphereMap∙ n {A = B} ∘∙ Ω^→ n f)
isNatural-Ω→SphereMap∙ n =
→∙Homogeneous≡ (isHomogeneous→∙ homogB)
(funExt (isNatural-Ω→SphereMap n))
mid□ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (p : typ ((Ω^ (suc n)) A))
→ fst (post∘∙ (S₊∙ (suc n)) (σ∙ A)) (Ω→SphereMap (suc n) p)
≡ Ω→SphereMap (suc n) (fst (Ω^→ (suc n) (σ∙ A)) p)
mid□ {A = A} n p =
funExt⁻
(cong fst
(isNatural-Ω→SphereMap∙
A (Ω (Susp∙ (typ A)))
(isHomogeneousPath _ _)
(σ∙ A) (suc n))) p
----- Bottom square filler -----
bot□ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f : (S₊∙ (suc n) →∙ A))
→ suspMap n f
≡ botᵣ {A = A} (suc n) (post∘∙ (S₊∙ (suc n)) (σ∙ A) .fst f)
bot□ {A = A} n f =
ΣPathP ((funExt (λ { north → refl
; south → refl
; (merid a i) → refl}))
, refl)
-- We prove that botᵣ is an equivalence
botᵣ⁻' : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ S₊∙ (suc n) →∙ Susp∙ (typ A) → (S₊ n → typ (Ω (Susp∙ (typ A))))
botᵣ⁻' zero f false =
sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f
botᵣ⁻' zero f true = refl
botᵣ⁻' (suc n) f x =
sym (snd f)
∙∙ cong (fst f) (merid x ∙ sym (merid (ptSn (suc n))))
∙∙ snd f
botᵣ⁻ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ S₊∙ (suc n) →∙ Susp∙ (typ A)
→ (S₊∙ n →∙ Ω (Susp∙ (typ A)))
fst (botᵣ⁻ {A = A} n f) = botᵣ⁻' {A = A} n f
snd (botᵣ⁻ {A = A} zero f) = refl
snd (botᵣ⁻ {A = A} (suc n) f) =
cong (sym (snd f) ∙∙_∙∙ snd f)
(cong (cong (fst f)) (rCancel (merid (ptSn _))))
∙ ∙∙lCancel (snd f)
botᵣIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (S₊∙ n →∙ Ω (Susp∙ (typ A)))
(S₊∙ (suc n) →∙ Susp∙ (typ A))
botᵣIso {A = A} n = (iso (botᵣ {A = A} n) (botᵣ⁻ {A = A} n) (h n) (retr n))
where
h : (n : ℕ) → section (botᵣ {A = A} n) (botᵣ⁻ {A = A} n)
h zero (f , p) =
ΣPathP (funExt (λ { base → sym p
; (loop i) j → doubleCompPath-filler
(sym p) (cong f loop) p (~ j) i})
, λ i j → p (~ i ∨ j))
h (suc n) (f , p) =
ΣPathP (funExt (λ { north → sym p
; south → sym p ∙ cong f (merid (ptSn _))
; (merid a i) j
→ hcomp (λ k
→ λ { (i = i0) → p (~ j ∧ k)
; (i = i1) → compPath-filler'
(sym p) (cong f (merid (ptSn _))) k j
; (j = i1) → f (merid a i)})
(f (compPath-filler
(merid a) (sym (merid (ptSn _))) (~ j) i))})
, λ i j → p (~ i ∨ j))
retr : (n : ℕ) → retract (botᵣ {A = A} n) (botᵣ⁻ {A = A} n)
retr zero (f , p) =
ΣPathP ((funExt (λ { false → sym (rUnit _) ; true → sym p}))
, λ i j → p (~ i ∨ j))
retr (suc n) (f , p) =
→∙Homogeneous≡ (isHomogeneousPath _ _)
(funExt λ x → (λ i
→ rUnit (cong-∙ (fst ((botᵣ {A = A}(suc n) (f , p))))
(merid x)
(sym (merid (ptSn (suc n)))) i) (~ i))
∙∙ (λ i → f x ∙ sym (p i) )
∙∙ sym (rUnit (f x)))
-- Right hand composite iso
IsoΩSphereMapᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (typ ((Ω^ (suc n)) (Susp∙ (typ A)))) ((S₊∙ (suc n) →∙ Susp∙ (typ A)))
IsoΩSphereMapᵣ {A = A} n =
compIso (flipΩIso n)
(compIso (IsoΩSphereMap n) (botᵣIso {A = A} n))
-- The dependent path between the two suspension functions
suspMapPathP : ∀ {ℓ} (A : Pointed ℓ) (n : ℕ)
→ (typ ((Ω^ (suc n)) A) → (typ ((Ω^ (suc (suc n))) (Susp∙ (typ A)))))
≡ ((S₊∙ (suc n) →∙ A) → S₊∙ (suc (suc n)) →∙ (Susp∙ (typ A)))
suspMapPathP A n i =
isoToPath (IsoΩSphereMap {A = A} (suc n)) i
→ isoToPath (IsoΩSphereMapᵣ {A = A} (suc n)) i
Ωσ→suspMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ PathP (λ i → suspMapPathP A n i)
(suspMapΩ (suc n))
(suspMap n)
Ωσ→suspMap {A = A} n =
toPathP (funExt (λ p →
(λ i → transportRefl
(Iso.fun (IsoΩSphereMapᵣ {A = A} (suc n))
(suspMapΩ {A = A} (suc n)
(Iso.inv (IsoΩSphereMap {A = A} (suc n))
(transportRefl p i)))) i)
∙∙ cong (botᵣ {A = A} (suc n))
(cong (Ω→SphereMap (suc n) {A = Ω (Susp∙ (typ A)) })
((sym (funExt⁻ (cong fst (top□ {A = A} n))
(invEq (Ω→SphereMap (suc n)
, isEquiv-Ω→SphereMap (suc n)) p))))
∙ (sym (mid□ n (invEq (Ω→SphereMap (suc n)
, isEquiv-Ω→SphereMap (suc n)) p))
∙ cong (σ∙ (fst A , snd A) ∘∙_)
(secEq (Ω→SphereMap (suc n)
, isEquiv-Ω→SphereMap (suc n)) p)))
∙∙ sym (bot□ n p)))
-- Connectedness of suspFunΩ (Freudenthal)
suspMapΩ-connected : ∀ {ℓ} (n : HLevel) (m : ℕ) {A : Pointed ℓ}
(connA : isConnected (suc (suc n)) (typ A))
→ isConnectedFun ((suc n + suc n) ∸ m) (suspMapΩ {A = A} m)
suspMapΩ-connected n zero {A = A} connA = isConnectedσ n connA
suspMapΩ-connected n (suc m) {A = A} connA with ((n + suc n) ≟ m)
... | (lt p) = subst (λ x → isConnectedFun x (suspMapΩ {A = A} (suc m)))
(sym (n∸m≡0 _ m (<-weaken p)))
λ b → tt* , (λ {tt* → refl})
... | (eq q) = subst (λ x → isConnectedFun x (suspMapΩ {A = A} (suc m)))
(sym (n∸n≡0 m) ∙ cong (_∸ m) (sym q))
λ b → tt* , (λ {tt* → refl})
... | (gt p) = isConnectedCong' (n + suc n ∸ m) (suspMapΩ {A = A} m)
(subst (λ x → isConnectedFun x (suspMapΩ {A = A} m))
(sym (suc∸-fst (n + suc n) m p))
(suspMapΩ-connected n m connA))
(snd (suspMapΩ∙ m))
-- We prove that the right iso is structure preserving
private
invComp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ S₊∙ n →∙ Ω (Susp∙ (typ A))
→ S₊∙ n →∙ Ω (Susp∙ (typ A))
→ S₊∙ n →∙ Ω (Susp∙ (typ A))
fst (invComp n f g) x = (fst f x) ∙ (fst g x)
snd (invComp n f g) = cong₂ _∙_ (snd f) (snd g) ∙ sym (rUnit refl)
-- We prove that it agrees with ∙Π
∙Π≡invComp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (f g : S₊∙ (suc n) →∙ Ω (Susp∙ (typ A)))
→ ∙Π f g ≡ invComp {A = A} (suc n) f g
∙Π≡invComp zero f g =
→∙Homogeneous≡ (isHomogeneousPath _ _)
(funExt (λ { base → rUnit refl
∙ sym (cong (_∙ fst g (snd (S₊∙ 1))) (snd f)
∙ cong (refl ∙_) (snd g))
; (loop i) j →
hcomp (λ k →
λ { (i = i0) → (rUnit refl
∙ sym (cong (_∙ fst g (snd (S₊∙ 1))) (snd f)
∙ cong (refl ∙_) (snd g))) j
; (i = i1) → (rUnit refl
∙ sym (cong (_∙ fst g (snd (S₊∙ 1))) (snd f)
∙ cong (refl ∙_) (snd g))) j
; (j = i0) → ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)
∙ (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i
; (j = i1) → cong₂Funct _∙_
(cong (fst f) loop) (cong (fst g) loop) (~ k) i})
(hcomp (λ k →
λ { (i = i0) → (rUnit refl
∙ sym (cong (_∙ snd g (~ k)) (λ j → snd f (j ∨ ~ k))
∙ cong (refl ∙_) (λ j → snd g (j ∨ ~ k)))) j
; (i = i1) → (rUnit refl
∙ sym (cong (_∙ snd g (~ k)) (λ j → snd f (j ∨ ~ k))
∙ cong (refl ∙_) (λ j → snd g (j ∨ ~ k)))) j
; (j = i0) → ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)
∙ (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i
; (j = i1) → (cong (_∙ snd g (~ k))
(doubleCompPath-filler (sym (snd f))
(cong (fst f) loop)
(snd f) (~ k)) ∙
cong ((snd f (~ k)) ∙_)
(doubleCompPath-filler (sym (snd g))
(cong (fst g) loop) (snd g) (~ k))) i})
(hcomp (λ k →
λ { (i = i0) → (rUnit (rUnit refl)
∙ cong (rUnit refl ∙_) (cong sym (rUnit refl))) k j
; (i = i1) → (rUnit (rUnit refl)
∙ cong (rUnit refl ∙_) (cong sym (rUnit refl))) k j
; (j = i0) → ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)
∙ (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i
; (j = i1) → (cong (_∙ refl)
((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f))
∙ cong (refl ∙_)
(sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i})
((cong (λ x → rUnit x j)
(sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)
∙ cong (λ x → lUnit x j)
(sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i)))}))
∙Π≡invComp {A = A} (suc n) f g =
→∙Homogeneous≡ (isHomogeneousPath _ _)
(funExt λ { north → rUnit refl
∙ sym (cong (fst f north ∙_) (snd g)
∙ cong (_∙ refl) (snd f))
; south → rUnit refl
∙ sym (cong₂ _∙_
(cong (fst f) (sym (merid (ptSn _))) ∙ snd f)
(cong (fst g) (sym (merid (ptSn _))) ∙ snd g))
; (merid a i) j → p a i j})
where
module _ (a : S₊ (suc n)) where
f-n = fst f north
g-n = fst g north
cong-f = (cong (fst f) (merid a ∙ sym (merid (ptSn _))))
cong-g = (cong (fst g) (merid a ∙ sym (merid (ptSn _))))
c-f = sym (snd f) ∙∙ cong-f ∙∙ snd f
c-g = sym (snd g) ∙∙ cong-g ∙∙ snd g
p : I → I → fst (Ω (Susp∙ (typ A)))
p i j =
hcomp (λ k →
λ { (i = i0) → (rUnit (λ _ → snd (Susp∙ (typ A)))
∙ sym ((cong (fst f north ∙_) (snd g)
∙ cong (_∙ refl) (snd f)))) j
; (i = i1) → (rUnit refl
∙ sym (cong₂ _∙_
(compPath-filler'
(cong (fst f) (sym (merid (ptSn _)))) (snd f) k)
(compPath-filler'
(cong (fst g) (sym (merid (ptSn _)))) (snd g) k))) j
; (j = i0) → (c-f ∙ c-g) i
; (j = i1) → fst f (compPath-filler
(merid a)
(sym (merid (ptSn _))) (~ k) i)
∙ fst g (compPath-filler
(merid a)
(sym (merid (ptSn _))) (~ k) i)})
(hcomp (λ k →
λ {(i = i0) → (rUnit (λ _ → snd (Susp∙ (typ A)))
∙ sym ((cong (fst f north ∙_) (snd g)
∙ cong (_∙ refl) (snd f)))) j
; (i = i1) → (rUnit refl ∙ sym (cong₂ _∙_ (snd f) (snd g))) j
; (j = i0) → (c-f ∙ c-g) i
; (j = i1) → cong₂Funct _∙_ cong-f cong-g (~ k) i})
(hcomp (λ k →
λ {(i = i0) → (rUnit refl
∙ sym (compPath-filler'
((cong (fst f north ∙_) (snd g)))
(cong (_∙ refl) (snd f)) k)) j
; (i = i1) → (rUnit refl
∙ sym (cong₂ _∙_ (λ i → snd f (i ∨ ~ k)) (snd g))) j
; (j = i0) → (c-f ∙ c-g) i
; (j = i1) → (cong (λ x → x ∙ snd g (~ k))
(doubleCompPath-filler refl
cong-f (snd f) (~ k))
∙ cong ((snd f (~ k)) ∙_)
(doubleCompPath-filler
(sym (snd g)) cong-g refl (~ k))) i})
(hcomp (λ k →
λ {(i = i0) → compPath-filler
(rUnit (λ _ → snd (Susp∙ (typ A))))
(sym ((cong (_∙ refl) (snd f)))) k j
; (i = i1) → compPath-filler
(rUnit refl)
(sym (cong (refl ∙_) (snd g))) k j
; (j = i0) → (c-f ∙ c-g) i
; (j = i1) → (cong (_∙ refl)
((λ j → snd f (~ j ∧ ~ k)) ∙∙ cong-f ∙∙ snd f)
∙ cong (refl ∙_)
(sym (snd g) ∙∙ cong-g ∙∙ (λ j → snd g (j ∧ ~ k)))) i})
(((cong (λ x → rUnit x j) c-f) ∙ (cong (λ x → lUnit x j) c-g)) i))))
hom-botᵣ⁻ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (f g : S₊∙ (suc n) →∙ Susp∙ (typ A))
→ botᵣ⁻ {A = A} n (∙Π f g)
≡ invComp {A = A} n (botᵣ⁻ {A = A} n f) (botᵣ⁻ {A = A} n g)
hom-botᵣ⁻ zero f g =
ΣPathP ((funExt (λ { false → sym (rUnit _)
; true → (rUnit _)}))
, ((λ i j → rUnit refl (i ∧ ~ j))
▷ lUnit (sym (rUnit refl))))
hom-botᵣ⁻ (suc n) f g =
→∙Homogeneous≡ (isHomogeneousPath _ _)
(funExt (λ x → (sym (rUnit (cong (fst (∙Π f g)) (merid x ∙ sym (merid (ptSn _))))))
∙∙ cong-∙ (fst (∙Π f g)) (merid x) (sym (merid (ptSn _)))
∙∙ cong (cong (fst (∙Π f g)) (merid x) ∙_) (cong sym lem)
∙ sym (rUnit (cong (fst (∙Π f g)) (merid x)))))
where
lem : cong (fst (∙Π f g)) (merid (ptSn (suc n))) ≡ refl
lem = (λ i → (sym (snd f) ∙∙ cong (fst f) (rCancel (merid (ptSn _)) i) ∙∙ snd f)
∙ (sym (snd g) ∙∙ cong (fst g) (rCancel (merid (ptSn _)) i) ∙∙ snd g))
∙ (λ i → ∙∙lCancel (snd f) i ∙ ∙∙lCancel (snd g) i)
∙ sym (rUnit refl)
-- We get that botᵣ⁻ (and hence botᵣ) is homomorphism
hom-botᵣ⁻' : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (f g : S₊∙ (suc (suc n)) →∙ Susp∙ (typ A))
→ botᵣ⁻ {A = A} (suc n) (∙Π f g)
≡ ∙Π (botᵣ⁻ {A = A} (suc n) f) (botᵣ⁻ {A = A} (suc n) g)
hom-botᵣ⁻' {A = A} n f g =
hom-botᵣ⁻ {A = A} (suc n) f g
∙ sym (∙Π≡invComp {A = A} _ (botᵣ⁻ {A = A} _ f) (botᵣ⁻ {A = A} _ g))
hom-botᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (f g : S₊∙ (suc n) →∙ Ω (Susp∙ (typ A)))
→ botᵣ {A = A} (suc n) (∙Π f g)
≡ ∙Π (botᵣ {A = A} (suc n) f) (botᵣ {A = A} (suc n) g)
hom-botᵣ {A = A} n f g =
morphLemmas.isMorphInv ∙Π ∙Π (botᵣ⁻ {A = A} (suc n))
(hom-botᵣ⁻' {A = A} n)
(botᵣ {A = A} (suc n))
(leftInv (botᵣIso {A = A} (suc n)))
(rightInv (botᵣIso {A = A} (suc n)))
f g
isHom-IsoΩSphereMapᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
(p q : typ ((Ω^ (2 + n)) (Susp∙ (typ A))))
→ Iso.fun (IsoΩSphereMapᵣ (suc n)) (p ∙ q)
≡ ∙Π (Iso.fun (IsoΩSphereMapᵣ (suc n)) p)
(Iso.fun (IsoΩSphereMapᵣ (suc n)) q)
isHom-IsoΩSphereMapᵣ {A = A} n p q =
cong (botᵣ {A = A} (suc n))
(cong (Ω→SphereMap (suc n) {A = Ω (Susp∙ (typ A))})
(flipΩIsopres· n p q)
∙ isHom-Ω→SphereMap n (fun (flipΩIso (suc n)) p)
(fun (flipΩIso (suc n)) q))
∙ hom-botᵣ n _ _
suspMapΩ→hom : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p q : typ ((Ω^ (suc n)) A))
→ suspMapΩ (suc n) (p ∙ q)
≡ suspMapΩ (suc n) p ∙ suspMapΩ (suc n) q
suspMapΩ→hom {A = A} n p q =
cong (sym (snd (suspMapΩ∙ {A = A} n)) ∙∙_∙∙ snd (suspMapΩ∙ {A = A} n))
(cong-∙ (fst (suspMapΩ∙ {A = A} n)) p q)
∙ help (snd (suspMapΩ∙ {A = A} n)) _ _
where
help : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) (q s : x ≡ x)
→ sym p ∙∙ (q ∙ s) ∙∙ p
≡ (sym p ∙∙ q ∙∙ p) ∙ (sym p ∙∙ s ∙∙ p)
help {x = x} =
J (λ y p → (q s : x ≡ x)
→ sym p ∙∙ (q ∙ s) ∙∙ p
≡ (sym p ∙∙ q ∙∙ p ) ∙ (sym p ∙∙ s ∙∙ p))
λ q s → sym (rUnit (q ∙ s))
∙ cong₂ _∙_ (rUnit q) (rUnit s)
private
transportLem : ∀ {ℓ} {A B : Type ℓ}
(_+A_ : A → A → A) (_+B_ : B → B → B)
→ (e : Iso A B)
→ ((x y : A) → fun e (x +A y) ≡ fun e x +B fun e y)
→ PathP (λ i → isoToPath e i → isoToPath e i → isoToPath e i)
_+A_ _+B_
transportLem _+A_ _+B_ e hom =
toPathP (funExt (λ p → funExt λ q →
(λ i → transportRefl
(fun e (inv e (transportRefl p i)
+A inv e (transportRefl q i))) i)
∙∙ hom (inv e p) (inv e q)
∙∙ cong₂ _+B_ (rightInv e p) (rightInv e q)))
pₗ : ∀ {ℓ} (A : Pointed ℓ) (n : ℕ)
→ typ (Ω ((Ω^ n) A)) ≡ (S₊∙ (suc n) →∙ A)
pₗ A n = isoToPath (IsoΩSphereMap {A = A} (suc n))
pᵣ : ∀ {ℓ} (A : Pointed ℓ) (n : ℕ)
→ typ ((Ω^ (2 + n)) (Susp∙ (typ A)))
≡ (S₊∙ (suc (suc n)) →∙ Susp∙ (typ A))
pᵣ A n = isoToPath (IsoΩSphereMapᵣ {A = A} (suc n))
∙Π→∙ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ PathP (λ i → pₗ A n i → pₗ A n i → pₗ A n i) _∙_ ∙Π
∙Π→∙ {A = A} n =
transportLem _∙_ ∙Π (IsoΩSphereMap {A = A} (suc n)) (isHom-Ω→SphereMap n)
∙Π→∙ᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ PathP (λ i → pᵣ A n i → pᵣ A n i → pᵣ A n i) _∙_ ∙Π
∙Π→∙ᵣ {A = A} n =
transportLem _∙_ ∙Π (IsoΩSphereMapᵣ {A = A} (suc n)) (isHom-IsoΩSphereMapᵣ n)
isHom-suspMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f g : S₊∙ (suc n) →∙ A)
→ suspMap n (∙Π f g)
≡ ∙Π (suspMap n f) (suspMap n g)
isHom-suspMap {A = A} n =
transport (λ i → (f g : isoToPath (IsoΩSphereMap {A = A} (suc n)) i)
→ Ωσ→suspMap n i (∙Π→∙ n i f g)
≡ ∙Π→∙ᵣ n i (Ωσ→suspMap n i f) (Ωσ→suspMap n i g))
(suspMapΩ→hom n)
suspMapπHom : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ GroupHom (πGr n A) (πGr (suc n) (Susp∙ (typ A)))
fst (suspMapπHom {A = A} n) = suspMapπ (suc n)
snd (suspMapπHom {A = A} n) =
makeIsGroupHom
(sElim2 (λ _ _ → isSetPathImplicit)
λ p q → cong ∣_∣₂ (suspMapΩ→hom n p q))
suspMapπ'Hom : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ GroupHom (π'Gr n A) (π'Gr (suc n) (Susp∙ (typ A)))
fst (suspMapπ'Hom {A = A} n) = suspMapπ' n
snd (suspMapπ'Hom {A = A} n) =
makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit)
λ f g → cong ∣_∣₂ (isHom-suspMap n f g))
πGr≅π'Grᵣ : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ)
→ GroupIso (πGr (suc n) (Susp∙ (typ A)))
(π'Gr (suc n) (Susp∙ (typ A)))
fst (πGr≅π'Grᵣ n A) = setTruncIso (IsoΩSphereMapᵣ (suc n))
snd (πGr≅π'Grᵣ n A) =
makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit)
λ f g → cong ∣_∣₂ (isHom-IsoΩSphereMapᵣ n f g))
private
isConnectedPres : ∀ {ℓ} {A : Pointed ℓ} (con n : ℕ)
→ isConnectedFun con (suspMapΩ∙ {A = A} (suc n) .fst)
→ isConnectedFun con (suspMap {A = A} n)
isConnectedPres {A = A} con n hyp =
transport (λ i → isConnectedFun con (Ωσ→suspMap {A = A} n i)) hyp
isConnectedSuspMap : (n m : ℕ)
→ isConnectedFun ((m + suc m) ∸ n) (suspMap {A = S₊∙ (suc m)} n)
isConnectedSuspMap n m =
isConnectedPres _ _ (suspMapΩ-connected m (suc n) (sphereConnected (suc m)))
isSurjectiveSuspMap : (n : ℕ)
→ isSurjective (suspMapπ'Hom {A = S₊∙ (2 + n)} (2 + n))
isSurjectiveSuspMap n =
sElim (λ _ → isProp→isSet squash₁)
λ f →
trRec
((subst (λ x → isOfHLevel x (isInIm (suspMapπ'Hom (2 + n)) ∣ f ∣₂))
(sym (snd (lem n n)))
(isProp→isOfHLevelSuc {A = isInIm (suspMapπ'Hom (2 + n)) ∣ f ∣₂}
(fst (lem n n)) squash₁)))
(λ p → ∣ ∣ fst p ∣₂ , (cong ∣_∣₂ (snd p)) ∣₁)
(fst (isConnectedSuspMap (2 + n) (suc n) f))
where
lem : (m n : ℕ) → Σ[ x ∈ ℕ ] ((m + suc (suc n) ∸ suc n) ≡ suc x)
lem zero zero = 0 , refl
lem (suc m) zero = suc m , +-comm m 2
lem zero (suc n) = lem zero n
lem (suc m) (suc n) = fst (lem (suc m) n) , (cong (_∸ (suc n)) (+-comm m (3 + n))
∙∙ cong (_∸ n) (+-comm (suc (suc n)) m)
∙∙ snd (lem (suc m) n))
| {
"alphanum_fraction": 0.442146628,
"avg_line_length": 41.232405892,
"ext": "agda",
"hexsha": "768171a5cfcadf93823587833b2c3d3de4fdc85c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Homotopy/Group/SuspensionMap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Homotopy/Group/SuspensionMap.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Homotopy/Group/SuspensionMap.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 10404,
"size": 25193
} |
module PiFrac.Category where
open import Categories.Category.Monoidal
open import Categories.Category.Monoidal.Braided
open import Categories.Category.Monoidal.Symmetric
open import Categories.Category.Monoidal.Rigid
open import Categories.Category.Monoidal.CompactClosed
open import Categories.Functor.Bifunctor
open import Categories.Category
open import Categories.Category.Product
open import Categories.Category.Groupoid
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Data.Maybe
open import Relation.Binary.Core
open import Relation.Binary hiding (Symmetric)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Function using (_∘_)
open import PiFrac.Syntax
open import PiFrac.Opsem
open import PiFrac.Interp
open import PiFrac.Properties
Pi∙ : Category _ _ _
Pi∙ = record
{ Obj = Σ[ t ∈ 𝕌 ] ⟦ t ⟧
; _⇒_ = λ (A , a) (B , b) → Σ[ c ∈ (A ↔ B) ] (interp c a ≡ just b)
; _≈_ = λ {(A , a)} {(B , b)} (c , eq) (c' , eq) → ⊤
; id = id↔ , refl
; _∘_ = λ (c₂ , eq₂) (c₁ , eq₁) → comp (c₁ , eq₁) (c₂ , eq₂)
; assoc = tt
; sym-assoc = tt
; identityˡ = tt
; identityʳ = tt
; identity² = tt
; equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt }
; ∘-resp-≈ = λ _ _ → tt
}
where
comp : ∀ {A B C a b c} → Σ[ c₁ ∈ (A ↔ B) ] (interp c₁ a ≡ just b) → Σ[ c₂ ∈ (B ↔ C) ] (interp c₂ b ≡ just c)
→ Σ[ c' ∈ (A ↔ C) ] (interp c' a ≡ just c)
comp {c = c} (c₁ , eq₁) (c₂ , eq₂) = (c₁ ⨾ c₂) , subst (λ x → (x >>= interp c₂) ≡ just c) (sym eq₁) eq₂
Pi∙Groupoid : Groupoid _ _ _
Pi∙Groupoid = record { category = Pi∙
; isGroupoid = record { _⁻¹ = λ (c , eq) → ! c , interp! c _ _ eq
; iso = record { isoˡ = tt
; isoʳ = tt } } }
Pi∙Monoidal : Monoidal Pi∙
Pi∙Monoidal = record
{ ⊗ = record
{ F₀ = λ ((A , a) , (B , b)) → (A ×ᵤ B) , (a , b)
; F₁ = λ {((A , a) , (B , b))} {((C , c) , (D , d))} ((c₁ , eq₁) , (c₂ , eq₂)) →
(c₁ ⊗ c₂) , subst (λ x → (x >>= (λ v₁' → interp c₂ b >>= λ v₂' → just (v₁' , v₂'))) ≡ just (c , d))
(sym eq₁) (subst (λ x → (x >>= λ v₂' → just (c , v₂')) ≡ just (c , d)) (sym eq₂) refl)
; identity = tt
; homomorphism = tt
; F-resp-≈ = λ _ → tt
}
; unit = (𝟙 , tt)
; unitorˡ = record { from = unite⋆l , refl
; to = uniti⋆l , refl
; iso = record { isoˡ = tt ; isoʳ = tt } }
; unitorʳ = record { from = unite⋆r , refl
; to = uniti⋆r , refl
; iso = record { isoˡ = tt ; isoʳ = tt } }
; associator = record { from = assocr⋆ , refl
; to = assocl⋆ , refl
; iso = record { isoˡ = tt ; isoʳ = tt } }
; unitorˡ-commute-from = tt
; unitorˡ-commute-to = tt
; unitorʳ-commute-from = tt
; unitorʳ-commute-to = tt
; assoc-commute-from = tt
; assoc-commute-to = tt
; triangle = tt
; pentagon = tt
}
Pi∙Braided : Braided Pi∙Monoidal
Pi∙Braided = record { braiding = record { F⇒G = record { η = λ _ → swap⋆ , refl
; commute = λ _ → tt
; sym-commute = λ _ → tt }
; F⇐G = record { η = λ _ → swap⋆ , refl
; commute = λ _ → tt
; sym-commute = λ _ → tt }
; iso = λ X → record { isoˡ = tt ; isoʳ = tt } }
; hexagon₁ = tt
; hexagon₂ = tt }
Pi∙Symmetric : Symmetric Pi∙Monoidal
Pi∙Symmetric = record { braided = Pi∙Braided
; commutative = tt}
Pi∙Rigid : LeftRigid Pi∙Monoidal
Pi∙Rigid = record { _⁻¹ = λ {(A , a) → 𝟙/ a , ↻}
; η = λ {(X , x)} → ηₓ x , refl
; ε = λ {(X , x)} → (swap⋆ ⨾ εₓ x) , εₓ≡
; snake₁ = tt
; snake₂ = tt}
where
εₓ≡ : ∀ {X} {x : ⟦ X ⟧} → interp (swap⋆ ⨾ εₓ x) (↻ , x) ≡ just tt
εₓ≡ {X} {x} with x ≟ x
... | yes refl = refl
... | no neq = ⊥-elim (neq refl)
Pi∙CompactClosed : CompactClosed Pi∙Monoidal
Pi∙CompactClosed = record { symmetric = Pi∙Symmetric
; rigid = inj₁ Pi∙Rigid }
| {
"alphanum_fraction": 0.4450617284,
"avg_line_length": 43.0088495575,
"ext": "agda",
"hexsha": "1812d3eff3ee73c3d37ba8dc96e38937fe856be2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "PiFrac/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "PiFrac/Category.agda",
"max_line_length": 129,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "PiFrac/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1548,
"size": 4860
} |
{-
Types Summer School 2007
Bertinoro
Aug 19 - 31, 2007
Agda
Ulf Norell
-}
{-
Learn more about Agda on the Agda wiki:
http://www.cs.chalmers.se/~ulfn/Agda
This is where you find the exercises for the afternoon.
-}
-- Each Agda file contains a top-level module, whose
-- name corresponds to the file name.
module Basics where
{-
Expressions (types and terms)
-}
-- The expression language of Agda is your favorite dependently
-- typed λ-calculus.
-- For instance:
id₁ : (A : Set) -> A -> A
id₁ = \ A x -> x
id₂ : (A : Set) -> A -> A
id₂ = \ A x -> id₁ A (id₁ A x)
-- Note: Agda likes white space. This is not correct:
-- id:(A:Set)->A->A
-- Why not? In Agda the following strings are valid identifiers:
-- id:
-- A:Set
-- ->A->A
-- Another useful function, featuring telescopes
-- and typed λs.
compose : (A B C : Set) -> (B -> C) -> (A -> B) -> A -> C
compose = \(A B C : Set) f g x -> f (g x)
compose' : (A B : Set)(C : B -> Set)
(f : (x : B) -> C x)(g : A -> B) ->
(x : A) -> C (g x)
compose' = \A B C f g x -> f (g x)
{-
Implicit arguments
-}
-- Writing down type arguments explicitly soon gets old.
-- Enter implicit arguments.
-- Note the curlies in the telescope. And A mysteriously disappeares
-- in the definition.
id₃ : {A : Set} -> A -> A
id₃ = \ x -> x
-- And it's not there when applying the function.
id₄ : {A : Set} -> A -> A
id₄ = \ x -> (id₃ (id₃ x))
-- If you think the type checker should figure out the value of
-- something explicit, you write _.
id₆ : {A : Set} -> A -> A
id₆ x = id₁ _ x
-- Interesting though it is, eventually you'll get bored
-- with the λ-calculus...
-- Move on to: Datatypes.agda
| {
"alphanum_fraction": 0.5753811406,
"avg_line_length": 19.4615384615,
"ext": "agda",
"hexsha": "8c5e08ebe8e50a82b9ac4f88a7cce743acc79d05",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/SummerSchool07/Lecture/Basics.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/SummerSchool07/Lecture/Basics.agda",
"max_line_length": 68,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/SummerSchool07/Lecture/Basics.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 556,
"size": 1771
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Basic lemmas showing that various types are related (isomorphic or
-- equivalent or…)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function.Related.TypeIsomorphisms where
open import Algebra
import Algebra.FunctionProperties as FP
open import Axiom.Extensionality.Propositional using (Extensionality)
open import Algebra.Structures
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Product as Prod hiding (swap)
open import Data.Product.Function.NonDependent.Propositional
open import Data.Sum as Sum
open import Data.Sum.Properties using (swap-involutive)
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Data.Unit using (⊤)
open import Level using (Level; Lift; lower; 0ℓ; suc)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence as Eq using (_⇔_; Equivalence)
open import Function.Inverse as Inv using (_↔_; Inverse; inverse)
open import Function.Related
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≗_)
open import Relation.Nullary using (Dec; ¬_; yes; no)
open import Relation.Nullary.Decidable using (True)
------------------------------------------------------------------------
-- Properties of Σ and _×_
-- Σ is associative
Σ-assoc : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : (a : A) → B a → Set c} →
Σ (Σ A B) (uncurry C) ↔ Σ A (λ a → Σ (B a) (C a))
Σ-assoc = inverse (λ where ((a , b) , c) → (a , b , c))
(λ where (a , b , c) → ((a , b) , c))
(λ _ → P.refl) (λ _ → P.refl)
-- × is commutative
×-comm : ∀ {a b} (A : Set a) (B : Set b) → (A × B) ↔ (B × A)
×-comm _ _ = inverse Prod.swap Prod.swap (λ _ → P.refl) λ _ → P.refl
-- × has ⊤ as its identity
×-identityˡ : ∀ ℓ → FP.LeftIdentity _↔_ (Lift ℓ ⊤) _×_
×-identityˡ _ _ = inverse proj₂ -,_ (λ _ → P.refl) (λ _ → P.refl)
×-identityʳ : ∀ ℓ → FP.RightIdentity _↔_ (Lift ℓ ⊤) _×_
×-identityʳ _ _ = inverse proj₁ (_, _) (λ _ → P.refl) (λ _ → P.refl)
×-identity : ∀ ℓ → FP.Identity _↔_ (Lift ℓ ⊤) _×_
×-identity ℓ = ×-identityˡ ℓ , ×-identityʳ ℓ
-- × has ⊥ has its zero
×-zeroˡ : ∀ ℓ → FP.LeftZero _↔_ (Lift ℓ ⊥) _×_
×-zeroˡ ℓ A = inverse proj₁ (⊥-elim ∘′ lower)
(⊥-elim ∘ lower ∘ proj₁) (⊥-elim ∘ lower)
×-zeroʳ : ∀ ℓ → FP.RightZero _↔_ (Lift ℓ ⊥) _×_
×-zeroʳ ℓ A = inverse proj₂ (⊥-elim ∘′ lower)
(⊥-elim ∘ lower ∘ proj₂) (⊥-elim ∘ lower)
×-zero : ∀ ℓ → FP.Zero _↔_ (Lift ℓ ⊥) _×_
×-zero ℓ = ×-zeroˡ ℓ , ×-zeroʳ ℓ
------------------------------------------------------------------------
-- Properties of ⊎
-- ⊎ is associative
⊎-assoc : ∀ ℓ → FP.Associative {ℓ = ℓ} _↔_ _⊎_
⊎-assoc ℓ _ _ _ = inverse
[ [ inj₁ , inj₂ ∘′ inj₁ ]′ , inj₂ ∘′ inj₂ ]′
[ inj₁ ∘′ inj₁ , [ inj₁ ∘′ inj₂ , inj₂ ]′ ]′
[ [ (λ _ → P.refl) , (λ _ → P.refl) ] , (λ _ → P.refl) ]
[ (λ _ → P.refl) , [ (λ _ → P.refl) , (λ _ → P.refl) ] ]
-- ⊎ is commutative
⊎-comm : ∀ {a b} (A : Set a) (B : Set b) → (A ⊎ B) ↔ (B ⊎ A)
⊎-comm _ _ = inverse swap swap swap-involutive swap-involutive
-- ⊎ has ⊥ as its identity
⊎-identityˡ : ∀ ℓ → FP.LeftIdentity _↔_ (Lift ℓ ⊥) _⊎_
⊎-identityˡ _ _ = inverse [ (λ ()) , id ]′ inj₂
[ (λ ()) , (λ _ → P.refl) ] (λ _ → P.refl)
⊎-identityʳ : ∀ ℓ → FP.RightIdentity _↔_ (Lift ℓ ⊥) _⊎_
⊎-identityʳ _ _ = inverse [ id , (λ ()) ]′ inj₁
[ (λ _ → P.refl) , (λ ()) ] (λ _ → P.refl)
⊎-identity : ∀ ℓ → FP.Identity _↔_ (Lift ℓ ⊥) _⊎_
⊎-identity ℓ = ⊎-identityˡ ℓ , ⊎-identityʳ ℓ
------------------------------------------------------------------------
-- Properties of × and ⊎
-- × distributes over ⊎
×-distribˡ-⊎ : ∀ ℓ → FP._DistributesOverˡ_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distribˡ-⊎ ℓ _ _ _ = inverse
(uncurry λ x → [ inj₁ ∘′ (x ,_) , inj₂ ∘′ (x ,_) ]′)
[ Prod.map₂ inj₁ , Prod.map₂ inj₂ ]′
(uncurry λ _ → [ (λ _ → P.refl) , (λ _ → P.refl) ])
[ (λ _ → P.refl) , (λ _ → P.refl) ]
×-distribʳ-⊎ : ∀ ℓ → FP._DistributesOverʳ_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distribʳ-⊎ ℓ _ _ _ = inverse
(uncurry [ curry inj₁ , curry inj₂ ]′)
[ Prod.map₁ inj₁ , Prod.map₁ inj₂ ]′
(uncurry [ (λ _ _ → P.refl) , (λ _ _ → P.refl) ])
[ (λ _ → P.refl) , (λ _ → P.refl) ]
×-distrib-⊎ : ∀ ℓ → FP._DistributesOver_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distrib-⊎ ℓ = ×-distribˡ-⊎ ℓ , ×-distribʳ-⊎ ℓ
------------------------------------------------------------------------
-- ⊥, ⊤, _×_ and _⊎_ form a commutative semiring
-- ⊤, _×_ form a commutative monoid
×-isMagma : ∀ k ℓ → IsMagma {Level.suc ℓ} (Related ⌊ k ⌋) _×_
×-isMagma k ℓ = record
{ isEquivalence = SK-isEquivalence k ℓ
; ∙-cong = _×-cong_
}
×-magma : Symmetric-kind → (ℓ : Level) → Magma _ _
×-magma k ℓ = record
{ isMagma = ×-isMagma k ℓ
}
×-isSemigroup : ∀ k ℓ → IsSemigroup {Level.suc ℓ} (Related ⌊ k ⌋) _×_
×-isSemigroup k ℓ = record
{ isMagma = ×-isMagma k ℓ
; assoc = λ _ _ _ → ↔⇒ Σ-assoc
}
×-semigroup : Symmetric-kind → (ℓ : Level) → Semigroup _ _
×-semigroup k ℓ = record
{ isSemigroup = ×-isSemigroup k ℓ
}
×-isMonoid : ∀ k ℓ → IsMonoid (Related ⌊ k ⌋) _×_ (Lift ℓ ⊤)
×-isMonoid k ℓ = record
{ isSemigroup = ×-isSemigroup k ℓ
; identity = (↔⇒ ∘ ×-identityˡ ℓ) , (↔⇒ ∘ ×-identityʳ ℓ)
}
×-monoid : Symmetric-kind → (ℓ : Level) → Monoid _ _
×-monoid k ℓ = record
{ isMonoid = ×-isMonoid k ℓ
}
×-isCommutativeMonoid : ∀ k ℓ → IsCommutativeMonoid (Related ⌊ k ⌋) _×_ (Lift ℓ ⊤)
×-isCommutativeMonoid k ℓ = record
{ isSemigroup = ×-isSemigroup k ℓ
; identityˡ = ↔⇒ ∘ ×-identityˡ ℓ
; comm = λ _ _ → ↔⇒ (×-comm _ _)
}
×-commutativeMonoid : Symmetric-kind → (ℓ : Level) → CommutativeMonoid _ _
×-commutativeMonoid k ℓ = record
{ isCommutativeMonoid = ×-isCommutativeMonoid k ℓ
}
-- ⊥, _⊎_ form a commutative monoid
⊎-isMagma : ∀ k ℓ → IsMagma {Level.suc ℓ} (Related ⌊ k ⌋) _⊎_
⊎-isMagma k ℓ = record
{ isEquivalence = SK-isEquivalence k ℓ
; ∙-cong = _⊎-cong_
}
⊎-magma : Symmetric-kind → (ℓ : Level) → Magma _ _
⊎-magma k ℓ = record
{ isMagma = ⊎-isMagma k ℓ
}
⊎-isSemigroup : ∀ k ℓ → IsSemigroup {Level.suc ℓ} (Related ⌊ k ⌋) _⊎_
⊎-isSemigroup k ℓ = record
{ isMagma = ⊎-isMagma k ℓ
; assoc = λ A B C → ↔⇒ (⊎-assoc ℓ A B C)
}
⊎-semigroup : Symmetric-kind → (ℓ : Level) → Semigroup _ _
⊎-semigroup k ℓ = record
{ isSemigroup = ⊎-isSemigroup k ℓ
}
⊎-isMonoid : ∀ k ℓ → IsMonoid (Related ⌊ k ⌋) _⊎_ (Lift ℓ ⊥)
⊎-isMonoid k ℓ = record
{ isSemigroup = ⊎-isSemigroup k ℓ
; identity = (↔⇒ ∘ ⊎-identityˡ ℓ) , (↔⇒ ∘ ⊎-identityʳ ℓ)
}
⊎-monoid : Symmetric-kind → (ℓ : Level) → Monoid _ _
⊎-monoid k ℓ = record
{ isMonoid = ⊎-isMonoid k ℓ
}
⊎-isCommutativeMonoid : ∀ k ℓ → IsCommutativeMonoid (Related ⌊ k ⌋) _⊎_ (Lift ℓ ⊥)
⊎-isCommutativeMonoid k ℓ = record
{ isSemigroup = ⊎-isSemigroup k ℓ
; identityˡ = ↔⇒ ∘ ⊎-identityˡ ℓ
; comm = λ _ _ → ↔⇒ (⊎-comm _ _)
}
⊎-commutativeMonoid : Symmetric-kind → (ℓ : Level) →
CommutativeMonoid _ _
⊎-commutativeMonoid k ℓ = record
{ isCommutativeMonoid = ⊎-isCommutativeMonoid k ℓ
}
×-⊎-isCommutativeSemiring : ∀ k ℓ →
IsCommutativeSemiring (Related ⌊ k ⌋) _⊎_ _×_ (Lift ℓ ⊥) (Lift ℓ ⊤)
×-⊎-isCommutativeSemiring k ℓ = record
{ +-isCommutativeMonoid = ⊎-isCommutativeMonoid k ℓ
; *-isCommutativeMonoid = ×-isCommutativeMonoid k ℓ
; distribʳ = λ A B C → ↔⇒ (×-distribʳ-⊎ ℓ A B C)
; zeroˡ = ↔⇒ ∘ ×-zeroˡ ℓ
}
×-⊎-commutativeSemiring : Symmetric-kind → (ℓ : Level) →
CommutativeSemiring (Level.suc ℓ) ℓ
×-⊎-commutativeSemiring k ℓ = record
{ isCommutativeSemiring = ×-⊎-isCommutativeSemiring k ℓ
}
------------------------------------------------------------------------
-- Some reordering lemmas
ΠΠ↔ΠΠ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) →
((x : A) (y : B) → P x y) ↔ ((y : B) (x : A) → P x y)
ΠΠ↔ΠΠ _ = inverse flip flip (λ _ → P.refl) (λ _ → P.refl)
∃∃↔∃∃ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) →
(∃₂ λ x y → P x y) ↔ (∃₂ λ y x → P x y)
∃∃↔∃∃ P = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
to : (∃₂ λ x y → P x y) → (∃₂ λ y x → P x y)
to (x , y , Pxy) = (y , x , Pxy)
from : (∃₂ λ y x → P x y) → (∃₂ λ x y → P x y)
from (y , x , Pxy) = (x , y , Pxy)
------------------------------------------------------------------------
-- Implicit and explicit function spaces are isomorphic
Π↔Π : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) ↔ ({x : A} → B x)
Π↔Π = inverse (λ f {x} → f x) (λ f x → f) (λ _ → P.refl) (λ _ → P.refl)
------------------------------------------------------------------------
-- _→_ preserves the symmetric relations
_→-cong-⇔_ :
∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
A ⇔ B → C ⇔ D → (A → C) ⇔ (B → D)
A⇔B →-cong-⇔ C⇔D = Eq.equivalence
(λ f x → Equivalence.to C⇔D ⟨$⟩ f (Equivalence.from A⇔B ⟨$⟩ x))
(λ f x → Equivalence.from C⇔D ⟨$⟩ f (Equivalence.to A⇔B ⟨$⟩ x))
→-cong :
∀ {a b c d} →
Extensionality a c → Extensionality b d →
∀ {k} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
A ∼[ ⌊ k ⌋ ] B → C ∼[ ⌊ k ⌋ ] D → (A → C) ∼[ ⌊ k ⌋ ] (B → D)
→-cong extAC extBD {equivalence} A⇔B C⇔D = A⇔B →-cong-⇔ C⇔D
→-cong extAC extBD {bijection} A↔B C↔D = record
{ to = Equivalence.to A→C⇔B→D
; from = Equivalence.from A→C⇔B→D
; inverse-of = record
{ left-inverse-of = λ f → extAC λ x → begin
Inverse.from C↔D ⟨$⟩ (Inverse.to C↔D ⟨$⟩
f (Inverse.from A↔B ⟨$⟩ (Inverse.to A↔B ⟨$⟩ x))) ≡⟨ Inverse.left-inverse-of C↔D _ ⟩
f (Inverse.from A↔B ⟨$⟩ (Inverse.to A↔B ⟨$⟩ x)) ≡⟨ P.cong f $ Inverse.left-inverse-of A↔B x ⟩
f x ∎
; right-inverse-of = λ f → extBD λ x → begin
Inverse.to C↔D ⟨$⟩ (Inverse.from C↔D ⟨$⟩
f (Inverse.to A↔B ⟨$⟩ (Inverse.from A↔B ⟨$⟩ x))) ≡⟨ Inverse.right-inverse-of C↔D _ ⟩
f (Inverse.to A↔B ⟨$⟩ (Inverse.from A↔B ⟨$⟩ x)) ≡⟨ P.cong f $ Inverse.right-inverse-of A↔B x ⟩
f x ∎
}
}
where
open P.≡-Reasoning
A→C⇔B→D = ↔⇒ A↔B →-cong-⇔ ↔⇒ C↔D
------------------------------------------------------------------------
-- ¬_ preserves the symmetric relations
¬-cong-⇔ : ∀ {a b} {A : Set a} {B : Set b} →
A ⇔ B → (¬ A) ⇔ (¬ B)
¬-cong-⇔ A⇔B = A⇔B →-cong-⇔ (⊥ ∎)
where open EquationalReasoning
¬-cong : ∀ {a b} → Extensionality a 0ℓ → Extensionality b 0ℓ →
∀ {k} {A : Set a} {B : Set b} →
A ∼[ ⌊ k ⌋ ] B → (¬ A) ∼[ ⌊ k ⌋ ] (¬ B)
¬-cong extA extB A≈B = →-cong extA extB A≈B (⊥ ∎)
where open EquationalReasoning
------------------------------------------------------------------------
-- _⇔_ preserves _⇔_
-- The type of the following proof is a bit more general.
Related-cong :
∀ {k a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
A ∼[ ⌊ k ⌋ ] B → C ∼[ ⌊ k ⌋ ] D → (A ∼[ ⌊ k ⌋ ] C) ⇔ (B ∼[ ⌊ k ⌋ ] D)
Related-cong {A = A} {B} {C} {D} A≈B C≈D =
Eq.equivalence (λ A≈C → B ∼⟨ SK-sym A≈B ⟩
A ∼⟨ A≈C ⟩
C ∼⟨ C≈D ⟩
D ∎)
(λ B≈D → A ∼⟨ A≈B ⟩
B ∼⟨ B≈D ⟩
D ∼⟨ SK-sym C≈D ⟩
C ∎)
where open EquationalReasoning
------------------------------------------------------------------------
-- A lemma relating True dec and P, where dec : Dec P
True↔ : ∀ {p} {P : Set p}
(dec : Dec P) → ((p₁ p₂ : P) → p₁ ≡ p₂) → True dec ↔ P
True↔ (yes p) irr = inverse (λ _ → p) (λ _ → _) (λ _ → P.refl) (irr p)
True↔ (no ¬p) _ = inverse (λ()) ¬p (λ()) (⊥-elim ∘ ¬p)
------------------------------------------------------------------------
-- Equality between pairs can be expressed as a pair of equalities
Σ-≡,≡↔≡ : ∀ {a b} {A : Set a} {B : A → Set b} {p₁ p₂ : Σ A B} →
(∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) →
P.subst B p (proj₂ p₁) ≡ proj₂ p₂) ↔
(p₁ ≡ p₂)
Σ-≡,≡↔≡ {A = A} {B} = inverse to from left-inverse-of right-inverse-of
where
to : {p₁ p₂ : Σ A B} →
Σ (proj₁ p₁ ≡ proj₁ p₂)
(λ p → P.subst B p (proj₂ p₁) ≡ proj₂ p₂) →
p₁ ≡ p₂
to (P.refl , P.refl) = P.refl
from : {p₁ p₂ : Σ A B} →
p₁ ≡ p₂ →
Σ (proj₁ p₁ ≡ proj₁ p₂)
(λ p → P.subst B p (proj₂ p₁) ≡ proj₂ p₂)
from P.refl = P.refl , P.refl
left-inverse-of : {p₁ p₂ : Σ A B}
(p : Σ (proj₁ p₁ ≡ proj₁ p₂)
(λ x → P.subst B x (proj₂ p₁) ≡ proj₂ p₂)) →
from (to p) ≡ p
left-inverse-of (P.refl , P.refl) = P.refl
right-inverse-of : {p₁ p₂ : Σ A B} (p : p₁ ≡ p₂) → to (from p) ≡ p
right-inverse-of P.refl = P.refl
×-≡,≡↔≡ : ∀ {a b} {A : Set a} {B : Set b} {p₁ p₂ : A × B} →
(proj₁ p₁ ≡ proj₁ p₂ × proj₂ p₁ ≡ proj₂ p₂) ↔ p₁ ≡ p₂
×-≡,≡↔≡ {A = A} {B} = inverse to from left-inverse-of right-inverse-of
where
to : {p₁ p₂ : A × B} →
(proj₁ p₁ ≡ proj₁ p₂) × (proj₂ p₁ ≡ proj₂ p₂) → p₁ ≡ p₂
to (P.refl , P.refl) = P.refl
from : {p₁ p₂ : A × B} → p₁ ≡ p₂ →
(proj₁ p₁ ≡ proj₁ p₂) × (proj₂ p₁ ≡ proj₂ p₂)
from P.refl = P.refl , P.refl
left-inverse-of : {p₁ p₂ : A × B} →
(p : (proj₁ p₁ ≡ proj₁ p₂) × (proj₂ p₁ ≡ proj₂ p₂)) →
from (to p) ≡ p
left-inverse-of (P.refl , P.refl) = P.refl
right-inverse-of : {p₁ p₂ : A × B} (p : p₁ ≡ p₂) → to (from p) ≡ p
right-inverse-of P.refl = P.refl
×-≡×≡↔≡,≡ : ∀ {a b} {A : Set a} {B : Set b} {x y} (p : A × B) →
(x ≡ proj₁ p × y ≡ proj₂ p) ↔ (x , y) ≡ p
×-≡×≡↔≡,≡ {x = x} {y} p = inverse to from from∘to to∘from
where
to : (x ≡ proj₁ p × y ≡ proj₂ p) → (x , y) ≡ p
to = uncurry $ P.cong₂ _,_
from : (x , y) ≡ p → (x ≡ proj₁ p × y ≡ proj₂ p)
from = < P.cong proj₁ , P.cong proj₂ >
from∘to : ∀ v → from (to v) ≡ v
from∘to (P.refl , P.refl) = P.refl
to∘from : ∀ v → to (from v) ≡ v
to∘from P.refl = P.refl
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.17
×-CommutativeMonoid = ×-commutativeMonoid
{-# WARNING_ON_USAGE ×-CommutativeMonoid
"Warning: ×-CommutativeMonoid was deprecated in v0.17.
Please use ×-commutativeMonoid instead."
#-}
⊎-CommutativeMonoid = ⊎-commutativeMonoid
{-# WARNING_ON_USAGE ⊎-CommutativeMonoid
"Warning: ⊎-CommutativeMonoid was deprecated in v0.17.
Please use ⊎-commutativeMonoid instead."
#-}
×⊎-CommutativeSemiring = ×-⊎-commutativeSemiring
{-# WARNING_ON_USAGE ×⊎-CommutativeSemiring
"Warning: ×⊎-CommutativeSemiring was deprecated in v0.17.
Please use ×-⊎-commutativeSemiring instead."
#-}
| {
"alphanum_fraction": 0.494875549,
"avg_line_length": 35.0256410256,
"ext": "agda",
"hexsha": "e7aaf2ba8b964d403040b04509ee5a7eca65d163",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Function/Related/TypeIsomorphisms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Function/Related/TypeIsomorphisms.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Function/Related/TypeIsomorphisms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6289,
"size": 15026
} |
{-
Types Summer School 2007
Bertinoro
Aug 19 - 31, 2007
Agda
Ulf Norell
-}
-- This is where the fun begins.
-- Unleashing datatypes, pattern matching and recursion.
module Datatypes where
{-
Simple datatypes.
-}
-- Let's define natural numbers.
data Nat : Set where
zero : Nat
suc : Nat -> Nat
-- A simple function.
pred : Nat -> Nat
pred zero = zero
pred (suc n) = n
-- Now let's do recursion.
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
infixl 60 _+_
-- An aside on infix operators:
-- Any name containing _ can be used as a mixfix operator.
-- The arguments simply go in place of the _. For instance:
data Bool : Set where
true : Bool
false : Bool
if_then_else_ : {A : Set} -> Bool -> A -> A -> A
if true then x else y = x
-- if false then x else y = y
if_then_else_ false x y = y
{-
Parameterised datatypes
-}
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
-- The parameters are implicit arguments to the constructors.
nil : (A : Set) -> List A
nil A = [] {A}
map : {A B : Set} -> (A -> B) -> List A -> List B
map f [] = []
map f (x :: xs) = f x :: map f xs
{-
Empty datatypes
-}
-- A very useful guy is the empty datatype.
data False : Set where
-- When pattern matching on an element of an empty type, something
-- interesting happens:
elim-False : {A : Set} -> False -> A
elim-False () -- Look Ma, no right hand side!
-- The pattern () is called an absurd pattern and matches elements
-- of an empty type.
{-
What's next?
-}
-- The Curry-Howard isomorphism.
-- CurryHoward.agda
| {
"alphanum_fraction": 0.5953516091,
"avg_line_length": 16.6138613861,
"ext": "agda",
"hexsha": "25035f930ae8e4f67e0afb63a1bce787dced2448",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/SummerSchool07/Lecture/Datatypes.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/SummerSchool07/Lecture/Datatypes.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/SummerSchool07/Lecture/Datatypes.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 494,
"size": 1678
} |
module Oscar.Definition where
{-
unpack : AList m n → Fin m → Term n -- sub
substitute : (Fin m → Term n) → Term m → Term n -- _◃_
substitutes : ∀ N → (Fin m → Term n) → Terms N m → Terms N n -- _◃s_
stepify : (Term m → Term n) → Step m → Step n -- fmapS
collapse : (List ∘ Step) n → Term n → Term n -- _⊹_
Substitist =
Substitunction = Fin m → Term n
Oscar.Data.Proposequality
Oscar.Data.Proposextensequality
Oscar.Data.Term
Oscar.Data.Terms
Oscar.Data.PropositionalEquality
setoidPropositionalEquality : Set → Setoid
Oscar.Data.IndexedPropositionalEquality
setoidIndexedPropEq : ∀ {A : Set} {B : A → Set} → ((x : A) → B x) → ((x : A) → B x) → Setoid
Oscar.Data.Substitist
Oscar.Setoid.PropositionalEquality
Oscar.Morphism.Substitist
Oscar.Unification
Oscar.Data.Substitunction
Substitunction m n = Fin m → Term n
: Morphism ℕ
:
Oscar.Definition.Substitist
: Morphism ℕ
= alistSetoid
: IsSemigroupoid
: Semigroupoid _++_
: IsCategory
: Category
Oscar.Definition.Substitist.internal
AList
alistSetoid : ℕ → ℕ → Setoid
ε = anil
_++_
-}
| {
"alphanum_fraction": 0.6813996317,
"avg_line_length": 21.72,
"ext": "agda",
"hexsha": "0e2e033592b1c31e03db63387d8afc9bbc9c08d3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Definition.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Definition.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Definition.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 371,
"size": 1086
} |
{- 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
-}
module Haskell.Prelude where
open import Haskell.Modules.Either public
open import Haskell.Modules.Eq public
open import Haskell.Modules.FunctorApplicativeMonad public
open import Haskell.Modules.ToBool public
------------------------------------------------------------------------------
open import Level
renaming (suc to ℓ+1; zero to ℓ0; _⊔_ to _ℓ⊔_)
open import Data.Bool
hiding (not; _≟_; _<_; _<?_; _≤_; _≤?_)
public
open import Data.List
hiding (map; filter; lookup; tabulate; foldl; fromMaybe; [_])
public
import Data.Nat as DN
import Data.Nat.DivMod as DivMod
import Data.Nat.Properties as DNP
open import Data.Maybe
using (Maybe; just; nothing)
renaming (_>>=_ to _Maybe->>=_)
public
import Data.Product as DP
open import Data.Unit.NonEta
using (Unit; unit)
public
open import Function
using (_∘_; id; typeOf; flip; const; _$_)
public
import Relation.Binary.PropositionalEquality as PE
using (_≡_; refl)
import Relation.Binary.Definitions as BD
import Relation.Binary as RB
------------------------------------------------------------------------------
infixl 1 _&_
_&_ = Function._|>_
-- An approximation of Haskell's backtick notation for making infix operators.
-- In Agda, there must be spaces between f and backticks
flip' : _ -- Avoids warning about definition and syntax declaration being in different scopes.
flip' = flip
syntax flip' f = ` f `
------------------------------------------------------------------------------
-- Guard Syntax --
--
-- Example Usage:
--
-- > f : ℕ → ℕ
-- > f x = grd‖ x ≟ℕ 10 ≔ 12
-- > ‖ otherwise≔ 40 + 2
--
--
-- > g : ℕ ⊎ ℕ → ℕ
-- > g x = case x of λ
-- > { (inj₁ x) → grd‖ x ≤? 10 ≔ 2 * x
-- > ‖ otherwise≔ 42
-- > ; (inj₂ y) → y
-- > }
--
-- To type: ‖ --> \Vert
-- ≔ --> \:=
infix 3 _≔_
data GuardClause {a}{b}(A : Set a) : Set (a ℓ⊔ ℓ+1 b) where
_≔_ : {B : Set b}{{ bb : ToBool B }} → B → A → GuardClause A
infix 3 otherwise≔_
data Guards {a}{b}(A : Set a) : Set (a ℓ⊔ ℓ+1 b) where
otherwise≔_ : A → Guards A
clause : GuardClause{a}{b} A → Guards{a}{b} A → Guards A
infixr 2 _‖_
_‖_ : ∀{a}{b}{A : Set a} → GuardClause{a}{b} A → Guards A → Guards A
_‖_ = clause
infix 1 grd‖_
grd‖_ : ∀{a}{b}{A : Set a} → Guards{a}{b} A → A
grd‖_ (otherwise≔ a) = a
grd‖_ (clause (b ≔ a) g) = if toBool b then a else (grd‖ g)
------------------------------------------------------------------------------
-- List
infixl 9 _!?_
_!?_ : {A : Set} → List A → DN.ℕ → Maybe A
[] !? _ = nothing
(x ∷ _ ) !? 0 = just x
(_ ∷ xs) !? (DN.suc n) = xs !? n
find' : ∀ {A B : Set} → (A → Maybe B) → List A → Maybe B
find' f [] = nothing
find' f (a ∷ xs) = Data.Maybe.maybe′ f (find' f xs) (just a)
foldl' = Data.List.foldl
------------------------------------------------------------------------------
-- Maybe
maybe : ∀ {A B : Set} → B → (A → B) → Maybe A → B
maybe b a→b = Data.Maybe.maybe′ a→b b
------------------------------------------------------------------------------
-- Nat
div = DivMod._/_
data Ordering : Set where
LT EQ GT : Ordering
compare : DN.ℕ → DN.ℕ → Ordering
compare m n
with DNP.<-cmp m n
... | BD.tri< a ¬b ¬c = LT
... | BD.tri≈ ¬a b ¬c = EQ
... | BD.tri> ¬a ¬b c = GT
------------------------------------------------------------------------------
-- Product
fst = DP.proj₁
snd = DP.proj₂
------------------------------------------------------------------------------
-- Monad
foldlM : ∀ {ℓ₁ ℓ₂} {A B : Set ℓ₁} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄
→ (B → A → M B) → B → List A → M B
foldlM _ z [] = pure z
foldlM f z (x ∷ xs) = do
z' ← f z x
foldlM f z' xs
foldrM : ∀ {ℓ₁ ℓ₂} {A B : Set ℓ₁} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄
→ (A → B → M B) → B → List A → M B
foldrM _ b [] = return b
foldrM f b (a ∷ as) = foldrM f b as >>= f a
foldM = foldlM
foldM_ : {A B : Set} {M : Set → Set} ⦃ _ : Monad M ⦄ → (B → A → M B) → B → List A → M Unit
foldM_ f a xs = foldlM f a xs >> pure unit
fromMaybeM : ∀ {ℓ} {A : Set} {m : Set → Set ℓ} ⦃ _ : Monad m ⦄ → m A → m (Maybe A) → m A
fromMaybeM ma mma = do
mma >>= λ where
nothing → ma
(just a) → pure a
-- NOTE: because 'forM_' is defined above, it is necessary to
-- call 'forM' with parenthesis (e.g., recursive call in definition)
-- to disambiguate it for the Agda parser.
forM : ∀ {ℓ} {A B : Set} {M : Set → Set ℓ} ⦃ _ : Monad M ⦄ → List A → (A → M B) → M (List B)
forM [] _ = return []
forM (x ∷ xs) f = do
fx ← f x
fxs ← (forM) xs f
return (fx ∷ fxs)
forM_ : ∀ {ℓ} {A B : Set} {M : Set → Set ℓ} ⦃ _ : Monad M ⦄ → List A → (A → M B) → M Unit
forM_ [] _ = return unit
forM_ (x ∷ xs) f = f x >> forM_ xs f
| {
"alphanum_fraction": 0.498408277,
"avg_line_length": 29.2209302326,
"ext": "agda",
"hexsha": "e20da97548e0580b684b0caae121d6669836b39e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/Haskell/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/Haskell/Prelude.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/Haskell/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1736,
"size": 5026
} |
module Ex6AgdaSetup where
{- This file contains all the basic types you need for the editor. You should
read and understand the Agda in this file, but not bother too much about
the funny compiler directives. -}
open import CS410-Prelude
open import CS410-Nat
record _**_ (S T : Set) : Set where
constructor _,_
field
outl : S
outr : T
open _**_
{-# COMPILED_DATA _**_ (,) (,) #-}
infixr 4 _**_ _,_
_<=_ : Nat -> Nat -> Two
zero <= y = tt
suc x <= zero = ff
suc x <= suc y = x <= y
_++_ : {A : Set} -> List A -> List A -> List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
{- Here are backward lists, which are useful when the closest element is
conceptually at the right end. They aren't really crucial as you could use
ordinary lists but think of the data as being reversed, but I prefer to
keep my thinking straight and use data which look like what I have in mind. -}
data Bwd (X : Set) : Set where
[] : Bwd X
_<:_ : Bwd X -> X -> Bwd X
infixl 3 _<:_
{- You will need access to characters, imported from Haskell. You can write
character literals like 'c'. You also get strings, with String literals like
"fred" -}
postulate -- Haskell has a monad for doing IO, which we use at the top level
IO : Set -> Set
return : {A : Set} -> A -> IO A
_>>=_ : {A B : Set} -> IO A -> (A -> IO B) -> IO B
infixl 1 _>>=_
{-# BUILTIN IO IO #-}
{-# COMPILED_TYPE IO IO #-}
{-# COMPILED return (\ _ -> return) #-}
{-# COMPILED _>>=_ (\ _ _ -> (>>=)) #-}
{- Here's the characterization of keys I give you -}
data Direction : Set where up down left right : Direction
data Modifier : Set where normal shift control : Modifier
data Key : Set where
char : Char -> Key
arrow : Modifier -> Direction -> Key
enter : Key
backspace : Key
delete : Key
escape : Key
tab : Key
data Event : Set where
key : (k : Key) -> Event
resize : (w h : Nat) -> Event
{- This type classifies the difference between two editor states. -}
data Change : Set where
allQuiet : Change -- the buffer should be exactly the same
cursorMove : Change -- the cursor has moved but the text is the same
lineEdit : Change -- only the text on the current line has changed
bigChange : Change -- goodness knows!
{- This type collects the things you're allowed to do with the text window. -}
data Action : Set where
goRowCol : Nat -> Nat -> Action -- send the cursor somewhere
sendText : List Char -> Action -- send some text
move : Direction -> Nat -> Action -- which way and how much
fgText : Colour -> Action
bgText : Colour -> Action
{- I wire all of that stuff up to its Haskell counterpart. -}
{-# IMPORT ANSIEscapes #-}
{-# IMPORT HaskellSetup #-}
{-# COMPILED_DATA Direction
ANSIEscapes.Dir
ANSIEscapes.DU ANSIEscapes.DD ANSIEscapes.DL ANSIEscapes.DR #-}
{-# COMPILED_DATA Modifier
HaskellSetup.Modifier
HaskellSetup.Normal HaskellSetup.Shift HaskellSetup.Control #-}
{-# COMPILED_DATA Key
HaskellSetup.Key
HaskellSetup.Char HaskellSetup.Arrow HaskellSetup.Enter
HaskellSetup.Backspace HaskellSetup.Delete HaskellSetup.Escape
HaskellSetup.Tab #-}
{-# COMPILED_DATA Event
HaskellSetup.Event
HaskellSetup.Key HaskellSetup.Resize #-}
{-# COMPILED_DATA Change
HaskellSetup.Change
HaskellSetup.AllQuiet HaskellSetup.CursorMove HaskellSetup.LineEdit
HaskellSetup.BigChange #-}
{-# COMPILED_DATA Action HaskellSetup.Action
HaskellSetup.GoRowCol HaskellSetup.SendText HaskellSetup.Move
HaskellSetup.FgText HaskellSetup.BgText #-}
{- This is the bit of code I wrote to animate your code. -}
postulate
mainLoop : {B : Set} -> -- buffer type
-- INITIALIZER
(List (List Char) -> B) -> -- make a buffer from some lines of text
-- KEYSTROKE HANDLER
(Key -> B -> -- keystroke and buffer in
Change ** B) -> -- change report and buffer out
-- RENDERER
((Nat ** Nat) -> -- height and width of screen
(Nat ** Nat) -> -- top line number, left column number
(Change ** B) -> -- change report and buffer to render
(List Action ** -- how to update the display
(Nat ** Nat))) -> -- new top line number, left column number
-- PUT 'EM TOGETHER AND YOU'VE GOT AN EDITOR!
IO One
{-# COMPILED mainLoop (\ _ -> HaskellSetup.mainLoop) #-}
{- You can use this to put noisy debug messages in Agda code. So
trace "fred" tt
evaluates to tt, but prints "fred" in the process. -}
postulate
trace : {A : Set} -> String -> A -> A
{-# IMPORT Debug.Trace #-}
{-# COMPILED trace (\ _ -> Debug.Trace.trace) #-}
{- You can use this to print an error message when you don't know what else to do.
It's very useful for filling in unfinished holes to persuade the compiler to
compile your code even though it isn't finished: you get an error if you try
to run a missing bit. -}
postulate
error : {A : Set} -> String -> A
{-# COMPILED error (\ _ -> error) #-}
{- Equality -}
{- x == y is a type whenever x and y are values in the same type -}
{-
data _==_ {X : Set}(x : X) : X -> Set where
refl : x == x -- and x == y has a constructor only when y actually is x!
infixl 1 _==_
-- {-# BUILTIN EQUALITY _==_ #-}
-- {-# BUILTIN REFL refl #-}
{-# COMPILED_DATA _==_ HaskellSetup.EQ HaskellSetup.Refl #-}
within_turn_into_because_ :
{X Y : Set}(f : X -> Y)(x x' : X) ->
x == x' -> f x == f x'
within f turn x into .x because refl = refl
-- the dot tells Agda that *only* x can go there
symmetry : {X : Set}{x x' : X} -> x == x' -> x' == x
symmetry refl = refl
transitivity : {X : Set}{x0 x1 x2 : X} -> x0 == x1 -> x1 == x2 -> x0 == x2
transitivity refl refl = refl
-}
within_turn_into_because_ :
{X Y : Set}(f : X -> Y)(x x' : X) ->
x == x' -> f x == f x'
within f turn x into .x because refl = refl
{-
postulate
_==_ : {X : Set} -> X -> X -> Set -- the evidence that two X-values are equal
refl : {X : Set}{x : X} -> x == x
symmetry : {X : Set}{x x' : X} -> x == x' -> x' == x
transitivity : {X : Set}{x0 x1 x2 : X} -> x0 == x1 -> x1 == x2 -> x0 == x2
within_turn_into_because_ :
{X Y : Set}(f : X -> Y)(x x' : X) ->
x == x' -> f x == f x'
infix 1 _==_
{-# COMPILED_TYPE _==_ HaskellSetup.EQ #-}
{- Here's an example. -}
additionAssociative : (x y z : Nat) -> (x + y) + z == x + (y + z)
additionAssociative zero y z = refl
additionAssociative (suc x) y z
= within suc turn ((x + y) + z) into (x + (y + z))
because additionAssociative x y z
-}
| {
"alphanum_fraction": 0.6069681245,
"avg_line_length": 34.9481865285,
"ext": "agda",
"hexsha": "3dbd896d2b21a89d97152f7523d609c90fea7db2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "Ex6AgdaSetup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "clarkdm/CS410",
"max_issues_repo_path": "Ex6AgdaSetup.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "Ex6AgdaSetup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1961,
"size": 6745
} |
------------------------------------------------------------------------
-- The partiality monads in Partiality-monad.Inductive and
-- Partiality-monad.Coinductive are pointwise equivalent, for sets,
-- assuming extensionality and countable choice
------------------------------------------------------------------------
{-# OPTIONS --cubical --sized-types #-}
open import Prelude hiding (⊥; ↑)
module Partiality-monad.Equivalence {a} {A : Type a} where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Bijection equality-with-J using (_↔_)
open import Embedding equality-with-J
using (Is-embedding; Injective≃Is-embedding)
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
as Trunc
open import Injection equality-with-J using (Injective)
open import Quotient equality-with-paths as Quotient hiding ([_])
open import Univalence-axiom equality-with-J
import Delay-monad as D
open import Delay-monad.Alternative as A using (_↓_; _↑)
import Delay-monad.Alternative.Equivalence as A
import Delay-monad.Alternative.Partial-order as A
import Delay-monad.Alternative.Termination as A
import Delay-monad.Alternative.Weak-bisimilarity as A
import Delay-monad.Bisimilarity as B
import Partiality-monad.Coinductive as C
import Partiality-monad.Coinductive.Alternative as CA
open import Partiality-monad.Inductive as I
hiding (_⊥; _⊑_; Increasing-sequence; _⇓_)
open import Partiality-monad.Inductive.Alternative-order
open import Partiality-monad.Inductive.Eliminators
------------------------------------------------------------------------
-- A function from the partiality monad defined in
-- Partiality-monad.Coinductive.Alternative to the inductive
-- partiality monad
-- Turns potential values into partial values.
Maybe→⊥ : Maybe A → A I.⊥
Maybe→⊥ nothing = never
Maybe→⊥ (just y) = now y
-- Maybe→⊥ is monotone.
Maybe→⊥-mono : ∀ {x y} → A.LE x y → Maybe→⊥ x I.⊑ Maybe→⊥ y
Maybe→⊥-mono (inj₁ refl) = ⊑-refl _
Maybe→⊥-mono (inj₂ (refl , y≢n)) = never⊑ _
-- Maybe→⊥ can be used to turn increasing sequences of one kind into
-- increasing sequences of another kind.
Delay→Inc-seq : A.Delay A → I.Increasing-sequence A
Delay→Inc-seq (f , inc) = Maybe→⊥ ∘ f , Maybe→⊥-mono ∘ inc
-- Turns increasing sequences of potential values into partial values.
Delay→⊥ : A.Delay A → A I.⊥
Delay→⊥ = ⨆ ∘ Delay→Inc-seq
-- Delay→⊥ is monotone (if A is a set).
Delay→⊥-mono :
Is-set A → ∀ x y → x A.∥⊑∥ y → Delay→⊥ x I.⊑ Delay→⊥ y
Delay→⊥-mono A-set x@(f , _) y@(g , _) x⊑y = ∃⊑→⨆⊑⨆ inc
where
inc : ∀ m → ∃ λ n → Maybe→⊥ (f m) I.⊑ Maybe→⊥ (g n)
inc m with inspect (f m)
inc m | nothing , fm↑ = 0 , (Maybe→⊥ (f m) ≡⟨ cong Maybe→⊥ fm↑ ⟩⊑
never ⊑⟨ never⊑ _ ⟩■
Maybe→⊥ (g 0) ■)
inc m | just z , fm↓z =
k , (Maybe→⊥ (f m) ≡⟨ cong Maybe→⊥ fm↓z ⟩⊑
Maybe→⊥ (just z) ≡⟨ cong Maybe→⊥ (sym $ proj₂ y⇓z) ⟩⊑
Maybe→⊥ (g k) ■)
where
y⇓z = $⟨ ∣ m , fm↓z ∣ ⟩
x A.∥⇓∥ z ↝⟨ x⊑y z ⟩
y A.∥⇓∥ z ↝⟨ _⇔_.from (A.⇓⇔∥⇓∥ A-set y) ⟩□
y A.⇓ z □
k : ℕ
k = proj₁ y⇓z
-- Delay→⊥ maps weakly bisimilar values to equal values (if A is a
-- set).
Delay→⊥-≈→≡ : Is-set A → ∀ x y → x A.≈ y → Delay→⊥ x ≡ Delay→⊥ y
Delay→⊥-≈→≡ A-set x y =
x A.≈ y ↝⟨ Σ-map (Delay→⊥-mono A-set x y) (Delay→⊥-mono A-set y x) ⟩
Delay→⊥ x I.⊑ Delay→⊥ y × Delay→⊥ x I.⊒ Delay→⊥ y ↝⟨ uncurry antisymmetry ⟩□
Delay→⊥ x ≡ Delay→⊥ y □
-- If A is a set, then values in A CA.⊥ can be mapped to values in the
-- inductive partiality monad.
⊥→⊥ : Is-set A → A CA.⊥ → A I.⊥
⊥→⊥ A-set = Quotient.rec λ where
.[]ʳ → Delay→⊥
.[]-respects-relationʳ {x = x} {y = y} → Delay→⊥-≈→≡ A-set x y
.is-setʳ → ⊥-is-set
------------------------------------------------------------------------
-- A lemma
-- I._⇓_ and A._∥⇓∥_ are pointwise logically equivalent (via Delay→⊥),
-- for sets.
⇓⇔∥⇓∥ :
Is-set A →
∀ x {y} → Delay→⊥ x I.⇓ y ⇔ x A.∥⇓∥ y
⇓⇔∥⇓∥ A-set x@(f , _) {y} =
Delay→⊥ x I.⇓ y ↔⟨⟩
⨆ (Delay→Inc-seq x) I.⇓ y ↔⟨ ⨆⇓≃∥∃⇓∥ ⟩
∥ (∃ λ n → Maybe→⊥ (f n) I.⇓ y) ∥ ↝⟨ ∥∥-cong-⇔ (∃-cong λ _ → record { to = to _; from = cong Maybe→⊥ }) ⟩
∥ (∃ λ n → f n ↓ y) ∥ ↝⟨ F.id ⟩□
x A.∥⇓∥ y □
where
to : ∀ n → Maybe→⊥ (f n) I.⇓ y → f n ↓ y
to n f⇓y with f n
... | nothing = ⊥-elim $ now≢never _ (sym f⇓y)
... | just y′ =
just y′ ≡⟨ cong just y′≡y ⟩∎
just y ∎
where
y′≡y = $⟨ f⇓y ⟩
now y′ ≡ now y ↔⟨ now≡now≃∥≡∥ ⟩
∥ y′ ≡ y ∥ ↝⟨ ∥∥↔ A-set ⟩□
y′ ≡ y □
------------------------------------------------------------------------
-- ⊥→⊥ is injective
-- Delay→⊥ is (kind of) injective (if A is a set).
Delay→⊥-injective :
Is-set A →
∀ x y → Delay→⊥ x ≡ Delay→⊥ y → x A.≈ y
Delay→⊥-injective A-set x y x≡y =
lemma A-set x y (≡→⊑ x≡y)
, lemma A-set y x (≡→⊑ (sym x≡y))
where
≡→⊑ : ∀ {x y} → x ≡ y → x I.⊑ y
≡→⊑ refl = ⊑-refl _
lemma :
Is-set A →
∀ x y → Delay→⊥ x I.⊑ Delay→⊥ y → x A.∥⊑∥ y
lemma A-set x y x⊑y z =
x A.∥⇓∥ z ↝⟨ _⇔_.from (⇓⇔∥⇓∥ A-set x) ⟩
Delay→⊥ x I.⇓ z ↔⟨ ⇓≃now⊑ ⟩
now z I.⊑ Delay→⊥ x ↝⟨ flip ⊑-trans x⊑y ⟩
now z I.⊑ Delay→⊥ y ↔⟨ inverse ⇓≃now⊑ ⟩
Delay→⊥ y I.⇓ z ↝⟨ _⇔_.to (⇓⇔∥⇓∥ A-set y) ⟩□
y A.∥⇓∥ z □
-- ⊥→⊥ A-set is injective.
⊥→⊥-injective :
(A-set : Is-set A) →
Injective (⊥→⊥ A-set)
⊥→⊥-injective A-set {x} {y} = Quotient.elim-prop
{P = λ x → ⊥→⊥ A-set x ≡ ⊥→⊥ A-set y → x ≡ y}
(λ where
.[]ʳ x → Quotient.elim-prop
{P = λ y → Delay→⊥ x ≡ ⊥→⊥ A-set y → Quotient.[ x ] ≡ y}
(λ where
.[]ʳ y → []-respects-relation ∘
Delay→⊥-injective A-set x y
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
/-is-set)
y
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
/-is-set)
x
------------------------------------------------------------------------
-- ⊥→⊥ is surjective
-- Delay→⊥ is surjective (if A is a set, assuming countable choice).
Delay→⊥-surjective :
Is-set A →
Axiom-of-countable-choice a →
Surjective Delay→⊥
Delay→⊥-surjective A-set cc =
⊥-rec-⊥ (record
{ pe = constant-sequence nothing
; po = constant-sequence ∘ just
; pl = λ s →
(∀ n → ∥ (∃ λ x → Delay→⊥ x ≡ s [ n ]) ∥) ↝⟨ cc ⟩
∥ (∀ n → ∃ λ x → Delay→⊥ x ≡ s [ n ]) ∥ ↔⟨ ∥∥-cong ΠΣ-comm ⟩
∥ (∃ λ f → ∀ n → Delay→⊥ (f n) ≡ s [ n ]) ∥ ↝⟨ ∥∥-map (uncurry $ flip construct s) ⟩□
∥ (∃ λ x → Delay→⊥ x ≡ ⨆ s) ∥ □
; pp = λ _ → truncation-is-proposition
})
where
-- The increasing sequences (of type A.Delay A) returned by this
-- function are constant.
constant-sequence : ∀ x → ∥ (∃ λ y → Delay→⊥ y ≡ Maybe→⊥ x) ∥
constant-sequence x = ∣ (const x , const (inj₁ refl)) , ⨆-const ∣
-- Given a sequence and an increasing sequence s that are pointwise
-- equal (via Delay→⊥) one can construct an increasing sequence that
-- is equal (via Delay→⊥) to ⨆ s.
construct :
(f : ℕ → A.Delay A)
(s : I.Increasing-sequence A) →
(∀ n → Delay→⊥ (f n) ≡ s [ n ]) →
∃ λ x → Delay→⊥ x ≡ ⨆ s
construct f s h = x , x-correct
where
-- We use f and an isomorphism between ℕ and ℕ × ℕ to construct a
-- function from ℕ to Maybe A.
f₂ : ℕ → ℕ → Maybe A
f₂ m n = proj₁ (f m) n
f₁ : ℕ → Maybe A
f₁ =
ℕ ↔⟨ ℕ↔ℕ² ⟩
ℕ × ℕ ↝⟨ uncurry f₂ ⟩□
Maybe A □
-- All values that this function can terminate with are equal.
termination-value-unique-f₂ :
∀ {m n y m′ n′ y′} →
f₂ m n ↓ y × f₂ m′ n′ ↓ y′ →
y ≡ y′
termination-value-unique-f₂ {m} {n} {y} {m′} {n′} {y′} =
f₂ m n ↓ y × f₂ m′ n′ ↓ y′ ↝⟨ f₂↓→⨆s⇓ ×-cong f₂↓→⨆s⇓ ⟩
⨆ s I.⇓ y × ⨆ s I.⇓ y′ ↝⟨ uncurry termination-value-merely-unique ⟩
∥ y ≡ y′ ∥ ↔⟨ ∥∥↔ A-set ⟩□
y ≡ y′ □
where
f₂↓→⨆s⇓ : ∀ {y m n} → f₂ m n ↓ y → ⨆ s I.⇓ y
f₂↓→⨆s⇓ {y} {m} f₂↓ =
terminating-element-is-⨆ s
(s [ m ] ≡⟨ sym (h m) ⟩
Delay→⊥ (f m) ≡⟨ _⇔_.from (⇓⇔∥⇓∥ A-set (f m)) ∣ _ , f₂↓ ∣ ⟩∎
now y ∎)
termination-value-unique-f₁ :
∀ {y y′} →
(∃ λ n → f₁ n ↓ y) →
(∃ λ n → f₁ n ↓ y′) →
y ≡ y′
termination-value-unique-f₁ (_ , ↓y) (_ , ↓y′) =
termination-value-unique-f₂ (↓y , ↓y′)
abstract
-- Thus the function can be completed to an increasing sequence.
completed-f₁ : ∃ λ x → ∀ {y} → x A.⇓ y ⇔ ∃ λ n → f₁ n ↓ y
completed-f₁ = A.complete-function f₁ termination-value-unique-f₁
-- The increasing sequence that is returned above.
x : A.Delay A
x = proj₁ completed-f₁
-- Every potential value in the increasing sequence x is smaller
-- than or equal to (via Maybe→⊥) some value in s.
x⊑s : ∀ m → ∃ λ n → Maybe→⊥ (proj₁ x m) I.⊑ s [ n ]
x⊑s m with inspect (proj₁ x m)
x⊑s m | nothing , x↑ =
zero
, (Maybe→⊥ (proj₁ x m) ≡⟨ cong Maybe→⊥ x↑ ⟩⊑
never ⊑⟨ never⊑ _ ⟩■
s [ 0 ] ■)
x⊑s m | just y , x↓ =
n₁
, (Maybe→⊥ (proj₁ x m) ≡⟨ cong Maybe→⊥ x↓ ⟩⊑
now y ≡⟨ sym f⇓ ⟩⊑
Delay→⊥ (f n₁) ≡⟨ h n₁ ⟩⊑
s [ n₁ ] ■)
where
f₁↓ : ∃ λ n → f₁ n ↓ y
f₁↓ = _⇔_.to (proj₂ completed-f₁) (_ , x↓)
n = proj₁ f₁↓
n₁ = proj₁ (_↔_.to ℕ↔ℕ² n)
n₂ = proj₂ (_↔_.to ℕ↔ℕ² n)
f⇓ : Delay→⊥ (f n₁) I.⇓ y
f⇓ =
_≃_.from ⇓≃now⊑
(now y ≡⟨ cong Maybe→⊥ $ sym $ proj₂ f₁↓ ⟩⊑
Maybe→⊥ (f₁ n) ⊑⟨⟩
Maybe→⊥ (f₂ n₁ n₂) ⊑⟨⟩
Maybe→⊥ (proj₁ (f n₁) n₂) ⊑⟨⟩
Delay→Inc-seq (f n₁) [ n₂ ] ⊑⟨ upper-bound (Delay→Inc-seq (f n₁)) _ ⟩■
Delay→⊥ (f n₁) ■)
-- Furthermore every potential value in f is smaller than or equal
-- to x.
f⊑x : ∀ m → f m A.⊑ x
f⊑x m y =
f m A.⇓ y ↝⟨ Σ-map (_↔_.from ℕ↔ℕ² ∘ (m ,_)) (λ {n} →
f₂ m n ↓ y ↝⟨ ≡⇒→ (cong ((_↓ y) ∘ uncurry f₂) $ sym $ _↔_.right-inverse-of ℕ↔ℕ² (m , n)) ⟩
uncurry f₂ (_↔_.to ℕ↔ℕ² (_↔_.from ℕ↔ℕ² (m , n))) ↓ y ↝⟨ F.id ⟩□
f₁ (_↔_.from ℕ↔ℕ² (m , n)) ↓ y □) ⟩
(∃ λ n → f₁ n ↓ y) ↝⟨ _⇔_.from (proj₂ completed-f₁) ⟩□
x A.⇓ y □
-- Thus x is correctly defined.
x-correct : Delay→⊥ x ≡ ⨆ s
x-correct = antisymmetry
(⊑→⨆⊑⨆ λ n →
Delay→Inc-seq x [ n ] ⊑⟨ proj₂ (x⊑s n) ⟩■
s [ proj₁ (x⊑s n) ] ■)
(least-upper-bound _ _ λ m →
s [ m ] ≡⟨ sym (h m) ⟩⊑
Delay→⊥ (f m) ⊑⟨ Delay→⊥-mono A-set (f m) x (∥∥-map ∘ f⊑x m) ⟩■
Delay→⊥ x ■)
-- ⊥→⊥ A-set is surjective (assuming countable choice).
⊥→⊥-surjective :
(A-set : Is-set A) →
Axiom-of-countable-choice a →
Surjective (⊥→⊥ A-set)
⊥→⊥-surjective A-set cc x =
∥∥-map (λ { (pre , can-pre≡x) → Quotient.[ pre ] , can-pre≡x })
(Delay→⊥-surjective A-set cc x)
------------------------------------------------------------------------
-- ⊥→⊥ is an equivalence
-- ⊥→⊥ A-set is an equivalence (assuming countable choice).
⊥→⊥-equiv :
(A-set : Is-set A) →
Axiom-of-countable-choice a →
Is-equivalence (⊥→⊥ A-set)
⊥→⊥-equiv A-set cc = $⟨ _,_ {B = const _}
(⊥→⊥-surjective A-set cc)
(λ {_ _} → ⊥→⊥-injective A-set) ⟩
Surjective (⊥→⊥ A-set) × Injective (⊥→⊥ A-set) ↝⟨ Σ-map id (_≃_.to (Injective≃Is-embedding ext /-is-set ⊥-is-set _)) ⟩
Surjective (⊥→⊥ A-set) × Is-embedding (⊥→⊥ A-set) ↝⟨ _≃_.to surjective×embedding≃equivalence ⟩□
Is-equivalence (⊥→⊥ A-set) □
-- Thus the inductive definition of the partiality monad is equivalent
-- to the definition in Partiality-monad.Coinductive.Alternative, for
-- sets, assuming countable choice.
⊥≃⊥′ :
Is-set A →
Axiom-of-countable-choice a →
A CA.⊥ ≃ A I.⊥
⊥≃⊥′ A-set choice = Eq.⟨ _ , ⊥→⊥-equiv A-set choice ⟩
------------------------------------------------------------------------
-- The two definitions of the partiality monad are equivalent
-- The inductive and coinductive definitions of the partiality monad
-- are pointwise equivalent, for sets, assuming extensionality and
-- countable choice.
⊥≃⊥ :
Is-set A →
B.Extensionality a →
Axiom-of-countable-choice a →
A I.⊥ ≃ A C.⊥
⊥≃⊥ A-set delay-ext choice =
A I.⊥ ↝⟨ inverse (⊥≃⊥′ A-set choice) ⟩
A CA.⊥ ↔⟨ CA.⊥↔⊥ A-set delay-ext ⟩□
A C.⊥ □
-- The previous result has a number of preconditions. None of these
-- preconditions are needed to translate from the delay monad to the
-- quotient inductive-inductive partiality monad.
Delay→⊥′ : D.Delay A ∞ → A I.⊥
Delay→⊥′ =
D.Delay A ∞ ↝⟨ _⇔_.from A.Delay⇔Delay ⟩
A.Delay A ↝⟨ Delay→⊥ ⟩□
A I.⊥ □
-- This translation turns weakly bisimilar computations into equal
-- computations, assuming that the underlying type is a set.
Delay→⊥′-≈→≡ :
Is-set A →
∀ {x y} → x B.≈ y → Delay→⊥′ x ≡ Delay→⊥′ y
Delay→⊥′-≈→≡ A-set {x} {y} =
x B.≈ y ↝⟨ _⇔_.to (A.≈⇔≈′ A-set) ⟩
_⇔_.from A.Delay⇔Delay x A.≈ _⇔_.from A.Delay⇔Delay y ↝⟨ Delay→⊥-≈→≡ A-set (_⇔_.from A.Delay⇔Delay x) (_⇔_.from A.Delay⇔Delay y) ⟩□
Delay→⊥′ x ≡ Delay→⊥′ y □
-- One can also translate from the coinductive to the inductive
-- partiality monad, as long as the underlying type is a set.
⊥→⊥′ : Is-set A → A C.⊥ → A I.⊥
⊥→⊥′ A-set = Quotient.rec λ where
.[]ʳ → Delay→⊥′
.[]-respects-relationʳ → Trunc.rec I.⊥-is-set (Delay→⊥′-≈→≡ A-set)
.is-setʳ → I.⊥-is-set
| {
"alphanum_fraction": 0.481583099,
"avg_line_length": 34.5473933649,
"ext": "agda",
"hexsha": "a583edf50e55859f8cc5d905b6d36f39f2733f33",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Equivalence.agda",
"max_line_length": 148,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 6075,
"size": 14579
} |
{-# OPTIONS --universe-polymorphism #-}
-- {-# OPTIONS --verbose tc.rec:15 #-}
-- {-# OPTIONS --verbose tc.records.ifs:15 #-}
-- {-# OPTIONS --verbose tc.constr.findInScope:15 #-}
-- {-# OPTIONS --verbose tc.term.args.ifs:15 #-}
module InstanceArguments.05-equality-std2 where
open import Agda.Primitive
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Data.Bool hiding (_≟_)
open DecSetoid {{...}}
instance
decBool = Data.Bool.decSetoid
test : IsDecEquivalence (_≡_ {A = Bool})
test = isDecEquivalence
test2 = false ≟ false
| {
"alphanum_fraction": 0.7164179104,
"avg_line_length": 25.125,
"ext": "agda",
"hexsha": "8d6b85d608f44837a99a2d6f0b06b08b89d1ce49",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/LibSucceed/InstanceArguments/05-equality-std2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/LibSucceed/InstanceArguments/05-equality-std2.agda",
"max_line_length": 53,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/LibSucceed/InstanceArguments/05-equality-std2.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 160,
"size": 603
} |
module Syntax.Substitution where
open import Syntax.Substitution.Kits public
open import Syntax.Substitution.Instances public
open import Syntax.Substitution.Lemmas public
| {
"alphanum_fraction": 0.8620689655,
"avg_line_length": 24.8571428571,
"ext": "agda",
"hexsha": "a6e6cbb92571ca0a711a78b4be1ff46759d3cfa0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/Syntax/Substitution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/Syntax/Substitution.agda",
"max_line_length": 48,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/Syntax/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 35,
"size": 174
} |
------------------------------------------------------------------------
-- Properties related to Any
------------------------------------------------------------------------
-- The other modules under Data.List.Any also contain properties
-- related to Any.
module Any where
open import Algebra
import Algebra.Definitions as FP
open import Effect.Monad
open import Data.Bool
open import Data.Bool.Properties
open import Data.Empty
open import Data.List as List
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
import Data.List.Effectful
open import Data.Product as Prod hiding (swap)
open import Data.Product.Function.NonDependent.Propositional
using (_×-cong_)
open import Data.Product.Relation.Binary.Pointwise.NonDependent
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Data.Sum.Relation.Binary.Pointwise
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Function using (_$_; _$′_; _∘_; id; flip; const)
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence as Eq using (_⇔_; module Equivalence)
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Function.Related as Related using (Related; SK-sym)
open import Function.Related.TypeIsomorphisms
open import Level
open import Relation.Binary hiding (_⇔_)
import Relation.Binary.HeterogeneousEquality as H
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; inspect) renaming ([_] to P[_])
open import Relation.Unary using (_⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_)
open import Data.List.Membership.Propositional
open import Data.List.Relation.Binary.BagAndSetEquality
open Related.EquationalReasoning
private
module ×⊎ {k ℓ} = CommutativeSemiring (×-⊎-commutativeSemiring k ℓ)
open module ListMonad {ℓ} =
RawMonad (Data.List.Effectful.monad {ℓ = ℓ})
------------------------------------------------------------------------
-- Some lemmas related to map, find and lose
-- Any.map is functorial.
map-id : ∀ {a p} {A : Set a} {P : A → Set p} (f : P ⋐ P) {xs} →
(∀ {x} (p : P x) → f p ≡ p) →
(p : Any P xs) → Any.map f p ≡ p
map-id f hyp (here p) = P.cong here (hyp p)
map-id f hyp (there p) = P.cong there $ map-id f hyp p
map-∘ : ∀ {a p q r}
{A : Set a} {P : A → Set p} {Q : A → Set q} {R : A → Set r}
(f : Q ⋐ R) (g : P ⋐ Q)
{xs} (p : Any P xs) →
Any.map (f ∘ g) p ≡ Any.map f (Any.map g p)
map-∘ f g (here p) = refl
map-∘ f g (there p) = P.cong there $ map-∘ f g p
-- Lemmas relating map and find.
map∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs}
(p : Any P xs) → let p′ = find p in
{f : _≡_ (proj₁ p′) ⋐ P} →
f refl ≡ proj₂ (proj₂ p′) →
Any.map f (proj₁ (proj₂ p′)) ≡ p
map∘find (here p) hyp = P.cong here hyp
map∘find (there p) hyp = P.cong there (map∘find p hyp)
find∘map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs : List A} (p : Any P xs) (f : P ⋐ Q) →
find (Any.map f p) ≡ Prod.map id (Prod.map id f) (find p)
find∘map (here p) f = refl
find∘map (there p) f rewrite find∘map p f = refl
-- find satisfies a simple equality when the predicate is a
-- propositional equality.
find-∈ : ∀ {a} {A : Set a} {x : A} {xs : List A} (x∈xs : x ∈ xs) →
find x∈xs ≡ (x , x∈xs , refl)
find-∈ (here refl) = refl
find-∈ (there x∈xs) rewrite find-∈ x∈xs = refl
private
-- find and lose are inverses (more or less).
lose∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A}
(p : Any P xs) →
uncurry′ lose (proj₂ (find p)) ≡ p
lose∘find p = map∘find p P.refl
find∘lose : ∀ {a p} {A : Set a} (P : A → Set p) {x xs}
(x∈xs : x ∈ xs) (pp : P x) →
find {P = P} (lose x∈xs pp) ≡ (x , x∈xs , pp)
find∘lose P x∈xs p
rewrite find∘map x∈xs (flip (P.subst P) p)
| find-∈ x∈xs
= refl
-- Any can be expressed using _∈_.
Any↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} →
(∃ λ x → x ∈ xs × P x) ↔ Any P xs
Any↔ {P = P} {xs} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ (find {P = P})
; inverse-of = record
{ left-inverse-of = λ p →
find∘lose P (proj₁ (proj₂ p)) (proj₂ (proj₂ p))
; right-inverse-of = lose∘find
}
}
where
to : (∃ λ x → x ∈ xs × P x) → Any P xs
to = uncurry′ lose ∘ proj₂
------------------------------------------------------------------------
-- Any is a congruence
Any-cong : ∀ {k ℓ} {A : Set ℓ} {P₁ P₂ : A → Set ℓ} {xs₁ xs₂ : List A} →
(∀ x → Related k (P₁ x) (P₂ x)) → xs₁ ∼[ k ] xs₂ →
Related k (Any P₁ xs₁) (Any P₂ xs₂)
Any-cong {P₁ = P₁} {P₂} {xs₁} {xs₂} P₁↔P₂ xs₁≈xs₂ =
Any P₁ xs₁ ↔⟨ SK-sym $ Any↔ {P = P₁} ⟩
(∃ λ x → x ∈ xs₁ × P₁ x) ∼⟨ Σ.cong Inv.id (xs₁≈xs₂ ×-cong P₁↔P₂ _) ⟩
(∃ λ x → x ∈ xs₂ × P₂ x) ↔⟨ Any↔ {P = P₂} ⟩
Any P₂ xs₂ ∎
------------------------------------------------------------------------
-- Swapping
-- Nested occurrences of Any can sometimes be swapped. See also ×↔.
swap : ∀ {ℓ} {A B : Set ℓ} {P : A → B → Set ℓ} {xs ys} →
Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys
swap {ℓ} {P = P} {xs} {ys} =
Any (λ x → Any (P x) ys) xs ↔⟨ SK-sym Any↔ ⟩
(∃ λ x → x ∈ xs × Any (P x) ys) ↔⟨ SK-sym $ Σ.cong Inv.id (Σ.cong Inv.id Any↔) ⟩
(∃ λ x → x ∈ xs × ∃ λ y → y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (∃∃↔∃∃ _) ⟩
(∃₂ λ x y → x ∈ xs × y ∈ ys × P x y) ↔⟨ ∃∃↔∃∃ _ ⟩
(∃₂ λ y x → x ∈ xs × y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (Σ.cong Inv.id (∃∃↔∃∃ _)) ⟩
(∃₂ λ y x → y ∈ ys × x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (∃∃↔∃∃ _) ⟩
(∃ λ y → y ∈ ys × ∃ λ x → x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (Σ.cong Inv.id Any↔) ⟩
(∃ λ y → y ∈ ys × Any (flip P y) xs) ↔⟨ Any↔ ⟩
Any (λ y → Any (flip P y) xs) ys ∎
------------------------------------------------------------------------
-- Lemmas relating Any to ⊥
⊥↔Any⊥ : ∀ {a} {A : Set a} {xs : List A} → ⊥ ↔ Any (const ⊥) xs
⊥↔Any⊥ {A = A} = record
{ to = P.→-to-⟶ (λ ())
; from = P.→-to-⟶ (λ p → from p)
; inverse-of = record
{ left-inverse-of = λ ()
; right-inverse-of = λ p → from p
}
}
where
from : {xs : List A} → Any (const ⊥) xs → ∀ {b} {B : Set b} → B
from (here ())
from (there p) = from p
⊥↔Any[] : ∀ {a} {A : Set a} {P : A → Set} → ⊥ ↔ Any P []
⊥↔Any[] = record
{ to = P.→-to-⟶ (λ ())
; from = P.→-to-⟶ (λ ())
; inverse-of = record
{ left-inverse-of = λ ()
; right-inverse-of = λ ()
}
}
------------------------------------------------------------------------
-- Lemmas relating Any to sums and products
-- Sums commute with Any (for a fixed list).
⊎↔ : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {xs} →
(Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs
⊎↔ {P = P} {Q} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = to∘from
}
}
where
to : ∀ {xs} → Any P xs ⊎ Any Q xs → Any (λ x → P x ⊎ Q x) xs
to = [ Any.map inj₁ , Any.map inj₂ ]′
from : ∀ {xs} → Any (λ x → P x ⊎ Q x) xs → Any P xs ⊎ Any Q xs
from (here (inj₁ p)) = inj₁ (here p)
from (here (inj₂ q)) = inj₂ (here q)
from (there p) = Sum.map there there (from p)
from∘to : ∀ {xs} (p : Any P xs ⊎ Any Q xs) → from (to p) ≡ p
from∘to (inj₁ (here p)) = P.refl
from∘to (inj₁ (there p)) rewrite from∘to (inj₁ p) = P.refl
from∘to (inj₂ (here q)) = P.refl
from∘to (inj₂ (there q)) rewrite from∘to (inj₂ q) = P.refl
to∘from : ∀ {xs} (p : Any (λ x → P x ⊎ Q x) xs) →
to (from p) ≡ p
to∘from (here (inj₁ p)) = P.refl
to∘from (here (inj₂ q)) = P.refl
to∘from (there p) with from p | to∘from p
to∘from (there .(Any.map inj₁ p)) | inj₁ p | P.refl = P.refl
to∘from (there .(Any.map inj₂ q)) | inj₂ q | P.refl = P.refl
-- Products "commute" with Any.
×↔ : {A B : Set} {P : A → Set} {Q : B → Set}
{xs : List A} {ys : List B} →
(Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs
×↔ {P = P} {Q} {xs} {ys} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = to∘from
}
}
where
to : Any P xs × Any Q ys → Any (λ x → Any (λ y → P x × Q y) ys) xs
to (p , q) = Any.map (λ p → Any.map (λ q → (p , q)) q) p
from : Any (λ x → Any (λ y → P x × Q y) ys) xs → Any P xs × Any Q ys
from pq with Prod.map id (Prod.map id find) (find pq)
... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q)
from∘to : ∀ pq → from (to pq) ≡ pq
from∘to (p , q)
rewrite find∘map {Q = λ x → Any (λ y → P x × Q y) ys}
p (λ p → Any.map (λ q → (p , q)) q)
| find∘map {Q = λ y → P (proj₁ (find p)) × Q y}
q (λ q → proj₂ (proj₂ (find p)) , q)
| lose∘find p
| lose∘find q
= refl
to∘from : ∀ pq → to (from pq) ≡ pq
to∘from pq
with find pq
| (λ (f : _≡_ (proj₁ (find pq)) ⋐ _) → map∘find pq {f})
... | (x , x∈xs , pq′) | lem₁
with find pq′
| (λ (f : _≡_ (proj₁ (find pq′)) ⋐ _) → map∘find pq′ {f})
... | (y , y∈ys , p , q) | lem₂
rewrite P.sym $ map-∘ {R = λ x → Any (λ y → P x × Q y) ys}
(λ p → Any.map (λ q → p , q) (lose y∈ys q))
(λ y → P.subst P y p)
x∈xs
= lem₁ _ helper
where
helper : Any.map (λ q → p , q) (lose y∈ys q) ≡ pq′
helper rewrite P.sym $ map-∘ {R = λ y → P x × Q y}
(λ q → p , q)
(λ y → P.subst Q y q)
y∈ys
= lem₂ _ refl
------------------------------------------------------------------------
-- Invertible introduction (⁺) and elimination (⁻) rules for various
-- list functions
-- map.
private
map⁺ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
{f : A → B} {xs} →
Any (P ∘ f) xs → Any P (List.map f xs)
map⁺ (here p) = here p
map⁺ (there p) = there $ map⁺ p
map⁻ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
{f : A → B} {xs} →
Any P (List.map f xs) → Any (P ∘ f) xs
map⁻ {xs = []} ()
map⁻ {xs = x ∷ xs} (here p) = here p
map⁻ {xs = x ∷ xs} (there p) = there $ map⁻ p
map⁺∘map⁻ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
{f : A → B} {xs} →
(p : Any P (List.map f xs)) →
map⁺ (map⁻ p) ≡ p
map⁺∘map⁻ {xs = []} ()
map⁺∘map⁻ {xs = x ∷ xs} (here p) = refl
map⁺∘map⁻ {xs = x ∷ xs} (there p) = P.cong there (map⁺∘map⁻ p)
map⁻∘map⁺ : ∀ {a b p} {A : Set a} {B : Set b} (P : B → Set p)
{f : A → B} {xs} →
(p : Any (P ∘ f) xs) →
map⁻ {P = P} (map⁺ p) ≡ p
map⁻∘map⁺ P (here p) = refl
map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p)
map↔ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
{f : A → B} {xs} →
Any (P ∘ f) xs ↔ Any P (List.map f xs)
map↔ {P = P} {f = f} = record
{ to = P.→-to-⟶ $ map⁺ {P = P} {f = f}
; from = P.→-to-⟶ $ map⁻ {P = P} {f = f}
; inverse-of = record
{ left-inverse-of = map⁻∘map⁺ P
; right-inverse-of = map⁺∘map⁻
}
}
-- _++_.
private
++⁺ˡ : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} →
Any P xs → Any P (xs ++ ys)
++⁺ˡ (here p) = here p
++⁺ˡ (there p) = there (++⁺ˡ p)
++⁺ʳ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} →
Any P ys → Any P (xs ++ ys)
++⁺ʳ [] p = p
++⁺ʳ (x ∷ xs) p = there (++⁺ʳ xs p)
++⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} →
Any P (xs ++ ys) → Any P xs ⊎ Any P ys
++⁻ [] p = inj₂ p
++⁻ (x ∷ xs) (here p) = inj₁ (here p)
++⁻ (x ∷ xs) (there p) = Sum.map there id (++⁻ xs p)
++⁺∘++⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys}
(p : Any P (xs ++ ys)) →
[ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs p) ≡ p
++⁺∘++⁻ [] p = refl
++⁺∘++⁻ (x ∷ xs) (here p) = refl
++⁺∘++⁻ (x ∷ xs) (there p) with ++⁻ xs p | ++⁺∘++⁻ xs p
++⁺∘++⁻ (x ∷ xs) (there p) | inj₁ p′ | ih = P.cong there ih
++⁺∘++⁻ (x ∷ xs) (there p) | inj₂ p′ | ih = P.cong there ih
++⁻∘++⁺ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys}
(p : Any P xs ⊎ Any P ys) →
++⁻ xs ([ ++⁺ˡ , ++⁺ʳ xs ]′ p) ≡ p
++⁻∘++⁺ [] (inj₁ ())
++⁻∘++⁺ [] (inj₂ p) = refl
++⁻∘++⁺ (x ∷ xs) (inj₁ (here p)) = refl
++⁻∘++⁺ (x ∷ xs) {ys} (inj₁ (there p)) rewrite ++⁻∘++⁺ xs {ys} (inj₁ p) = refl
++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl
++↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} →
(Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys)
++↔ {P = P} {xs = xs} = record
{ to = P.→-to-⟶ [ ++⁺ˡ {P = P}, ++⁺ʳ {P = P} xs ]′
; from = P.→-to-⟶ $ ++⁻ {P = P} xs
; inverse-of = record
{ left-inverse-of = ++⁻∘++⁺ xs
; right-inverse-of = ++⁺∘++⁻ xs
}
}
-- return.
private
return⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {x} →
P x → Any P (return x)
return⁺ = here
return⁻ : ∀ {a p} {A : Set a} {P : A → Set p} {x} →
Any P (return x) → P x
return⁻ (here p) = p
return⁻ (there ())
return⁺∘return⁻ : ∀ {a p} {A : Set a} {P : A → Set p} {x}
(p : Any P (return x)) →
return⁺ (return⁻ p) ≡ p
return⁺∘return⁻ (here p) = refl
return⁺∘return⁻ (there ())
return⁻∘return⁺ : ∀ {a p} {A : Set a} (P : A → Set p) {x} (p : P x) →
return⁻ {P = P} (return⁺ p) ≡ p
return⁻∘return⁺ P p = refl
return↔ : ∀ {a p} {A : Set a} {P : A → Set p} {x} →
P x ↔ Any P (return x)
return↔ {P = P} = record
{ to = P.→-to-⟶ $ return⁺ {P = P}
; from = P.→-to-⟶ $ return⁻ {P = P}
; inverse-of = record
{ left-inverse-of = return⁻∘return⁺ P
; right-inverse-of = return⁺∘return⁻
}
}
-- _∷_.
∷↔ : ∀ {a p} {A : Set a} (P : A → Set p) {x xs} →
(P x ⊎ Any P xs) ↔ Any P (x ∷ xs)
∷↔ P {x} {xs} =
(P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩
(Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩
Any P (x ∷ xs) ∎
-- concat.
private
concat⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} →
Any (Any P) xss → Any P (concat xss)
concat⁺ (here p) = ++⁺ˡ p
concat⁺ (there {x = xs} p) = ++⁺ʳ xs (concat⁺ p)
concat⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xss →
Any P (concat xss) → Any (Any P) xss
concat⁻ [] ()
concat⁻ ([] ∷ xss) p = there $ concat⁻ xss p
concat⁻ ((x ∷ xs) ∷ xss) (here p) = here (here p)
concat⁻ ((x ∷ xs) ∷ xss) (there p)
with concat⁻ (xs ∷ xss) p
... | here p′ = here (there p′)
... | there p′ = there p′
concat⁻∘++⁺ˡ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} xss (p : Any P xs) →
concat⁻ (xs ∷ xss) (++⁺ˡ p) ≡ here p
concat⁻∘++⁺ˡ xss (here p) = refl
concat⁻∘++⁺ˡ xss (there p) rewrite concat⁻∘++⁺ˡ xss p = refl
concat⁻∘++⁺ʳ : ∀ {a p} {A : Set a} {P : A → Set p} xs xss (p : Any P (concat xss)) →
concat⁻ (xs ∷ xss) (++⁺ʳ xs p) ≡ there (concat⁻ xss p)
concat⁻∘++⁺ʳ [] xss p = refl
concat⁻∘++⁺ʳ (x ∷ xs) xss p rewrite concat⁻∘++⁺ʳ xs xss p = refl
concat⁺∘concat⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xss (p : Any P (concat xss)) →
concat⁺ (concat⁻ xss p) ≡ p
concat⁺∘concat⁻ [] ()
concat⁺∘concat⁻ ([] ∷ xss) p = concat⁺∘concat⁻ xss p
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (here p) = refl
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there p)
with concat⁻ (xs ∷ xss) p | concat⁺∘concat⁻ (xs ∷ xss) p
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ˡ p′)) | here p′ | refl = refl
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ʳ xs (concat⁺ p′))) | there p′ | refl = refl
concat⁻∘concat⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} (p : Any (Any P) xss) →
concat⁻ xss (concat⁺ p) ≡ p
concat⁻∘concat⁺ (here p) = concat⁻∘++⁺ˡ _ p
concat⁻∘concat⁺ (there {x = xs} {xs = xss} p)
rewrite concat⁻∘++⁺ʳ xs xss (concat⁺ p) =
P.cong there $ concat⁻∘concat⁺ p
concat↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} →
Any (Any P) xss ↔ Any P (concat xss)
concat↔ {P = P} {xss = xss} = record
{ to = P.→-to-⟶ $ concat⁺ {P = P}
; from = P.→-to-⟶ $ concat⁻ {P = P} xss
; inverse-of = record
{ left-inverse-of = concat⁻∘concat⁺
; right-inverse-of = concat⁺∘concat⁻ xss
}
}
-- _>>=_.
>>=↔ : ∀ {ℓ p} {A B : Set ℓ} {P : B → Set p} {xs} {f : A → List B} →
Any (Any P ∘ f) xs ↔ Any P (xs >>= f)
>>=↔ {P = P} {xs} {f} =
Any (Any P ∘ f) xs ↔⟨ map↔ {P = Any P} {f = f} ⟩
Any (Any P) (List.map f xs) ↔⟨ concat↔ {P = P} ⟩
Any P (xs >>= f) ∎
-- _⊛_.
⊛↔ : ∀ {ℓ} {A B : Set ℓ} {P : B → Set ℓ}
{fs : List (A → B)} {xs : List A} →
Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs)
⊛↔ {ℓ} {P = P} {fs} {xs} =
Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → return↔ {a = ℓ} {p = ℓ}) (_ ∎)) (_ ∎) ⟩
Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ {ℓ = ℓ} {p = ℓ}) (_ ∎) ⟩
Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩
Any P (fs ⊛ xs) ∎
-- An alternative introduction rule for _⊛_.
⊛⁺′ : ∀ {ℓ} {A B : Set ℓ} {P : A → Set ℓ} {Q : B → Set ℓ}
{fs : List (A → B)} {xs} →
Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs)
⊛⁺′ {ℓ} pq p =
Inverse.to (⊛↔ {ℓ = ℓ}) ⟨$⟩
Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq
-- _⊗_.
⊗↔ : ∀ {ℓ} {A B : Set ℓ} {P : A × B → Set ℓ}
{xs : List A} {ys : List B} →
Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys)
⊗↔ {ℓ} {P = P} {xs} {ys} =
Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ return↔ {a = ℓ} {p = ℓ} ⟩
Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩
Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩
Any P (xs ⊗ ys) ∎
⊗↔′ : {A B : Set} {P : A → Set} {Q : B → Set}
{xs : List A} {ys : List B} →
(Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys)
⊗↔′ {P = P} {Q} {xs} {ys} =
(Any P xs × Any Q ys) ↔⟨ ×↔ ⟩
Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩
Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎
-- map-with-∈.
map-with-∈↔ :
∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {xs : List A}
{f : ∀ {x} → x ∈ xs → B} →
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (mapWith∈ xs f)
map-with-∈↔ {A = A} {B} {P} = record
{ to = P.→-to-⟶ (map-with-∈⁺ _)
; from = P.→-to-⟶ (map-with-∈⁻ _ _)
; inverse-of = record
{ left-inverse-of = from∘to _
; right-inverse-of = to∘from _ _
}
}
where
map-with-∈⁺ : ∀ {xs : List A}
(f : ∀ {x} → x ∈ xs → B) →
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
Any P (mapWith∈ xs f)
map-with-∈⁺ f (_ , here refl , p) = here p
map-with-∈⁺ f (_ , there x∈xs , p) =
there $ map-with-∈⁺ (f ∘ there) (_ , x∈xs , p)
map-with-∈⁻ : ∀ (xs : List A)
(f : ∀ {x} → x ∈ xs → B) →
Any P (mapWith∈ xs f) →
∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)
map-with-∈⁻ [] f ()
map-with-∈⁻ (y ∷ xs) f (here p) = (y , here refl , p)
map-with-∈⁻ (y ∷ xs) f (there p) =
Prod.map id (Prod.map there id) $ map-with-∈⁻ xs (f ∘ there) p
from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B)
(p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
map-with-∈⁻ xs f (map-with-∈⁺ f p) ≡ p
from∘to f (_ , here refl , p) = refl
from∘to f (_ , there x∈xs , p)
rewrite from∘to (f ∘ there) (_ , x∈xs , p) = refl
to∘from : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B)
(p : Any P (mapWith∈ xs f)) →
map-with-∈⁺ f (map-with-∈⁻ xs f p) ≡ p
to∘from [] f ()
to∘from (y ∷ xs) f (here p) = refl
to∘from (y ∷ xs) f (there p) =
P.cong there $ to∘from xs (f ∘ there) p
------------------------------------------------------------------------
-- Any and any are related via T
-- These introduction and elimination rules are not inverses, though.
private
any⁺ : ∀ {a} {A : Set a} (p : A → Bool) {xs} →
Any (T ∘ p) xs → T (any p xs)
any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px
any⁺ p (there {x = x} pxs) with p x
... | true = _
... | false = any⁺ p pxs
any⁻ : ∀ {a} {A : Set a} (p : A → Bool) xs →
T (any p xs) → Any (T ∘ p) xs
any⁻ p [] ()
any⁻ p (x ∷ xs) px∷xs with p x | inspect p x
any⁻ p (x ∷ xs) px∷xs | true | P[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq)
any⁻ p (x ∷ xs) px∷xs | false | _ = there (any⁻ p xs px∷xs)
any⇔ : ∀ {a} {A : Set a} {p : A → Bool} {xs} →
Any (T ∘ p) xs ⇔ T (any p xs)
any⇔ = Eq.equivalence (any⁺ _) (any⁻ _ _)
------------------------------------------------------------------------
-- _++_ is commutative
private
++-comm : ∀ {a p} {A : Set a} {P : A → Set p} xs ys →
Any P (xs ++ ys) → Any P (ys ++ xs)
++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs
++-comm∘++-comm : ∀ {a p} {A : Set a} {P : A → Set p}
xs {ys} (p : Any P (xs ++ ys)) →
++-comm ys xs (++-comm xs ys p) ≡ p
++-comm∘++-comm [] {ys} p
rewrite ++⁻∘++⁺ ys {ys = []} (inj₁ p) = P.refl
++-comm∘++-comm {P = P} (x ∷ xs) {ys} (here p)
rewrite ++⁻∘++⁺ {P = P} ys {ys = x ∷ xs} (inj₂ (here p)) = P.refl
++-comm∘++-comm (x ∷ xs) (there p) with ++⁻ xs p | ++-comm∘++-comm xs p
++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ʳ ys p))))
| inj₁ p | P.refl
rewrite ++⁻∘++⁺ ys (inj₂ p)
| ++⁻∘++⁺ ys (inj₂ $′ there {x = x} p) = refl
++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ˡ p))))
| inj₂ p | P.refl
rewrite ++⁻∘++⁺ ys {ys = xs} (inj₁ p)
| ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = P.refl
++↔++ : ∀ {a p} {A : Set a} {P : A → Set p} xs ys →
Any P (xs ++ ys) ↔ Any P (ys ++ xs)
++↔++ {P = P} xs ys = record
{ to = P.→-to-⟶ $ ++-comm {P = P} xs ys
; from = P.→-to-⟶ $ ++-comm {P = P} ys xs
; inverse-of = record
{ left-inverse-of = ++-comm∘++-comm xs
; right-inverse-of = ++-comm∘++-comm ys
}
}
| {
"alphanum_fraction": 0.4292844523,
"avg_line_length": 36.1661341853,
"ext": "agda",
"hexsha": "cb232f2584a137eda2f82e1ec19cc4a033e6e988",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "benchmark/std-lib/Any.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "benchmark/std-lib/Any.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "benchmark/std-lib/Any.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9774,
"size": 22640
} |
------------------------------------------------------------------------
-- A variant of Coherently that is defined without the use of
-- coinduction
------------------------------------------------------------------------
{-# OPTIONS --cubical #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Coherently.Not-coinductive
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Prelude
open import Container.Indexed equality-with-J
open import Container.Indexed.M.Function equality-with-J
open import H-level.Truncation.Propositional.One-step eq using (∥_∥¹)
private
variable
a b p : Level
-- A container that is used to define Coherently.
Coherently-container :
{B : Type b}
(P : {A : Type a} → (A → B) → Type p)
(step : {A : Type a} (f : A → B) → P f → ∥ A ∥¹ → B) →
Container (∃ λ (A : Type a) → A → B) p lzero
Coherently-container P step = λ where
.Shape (_ , f) → P f
.Position _ → ⊤
.index {o = A , f} {s = p} _ → ∥ A ∥¹ , step f p
-- A variant of Coherently, defined using an indexed container.
Coherently :
{A : Type a} {B : Type b}
(P : {A : Type a} → (A → B) → Type p)
(step : {A : Type a} (f : A → B) → P f → ∥ A ∥¹ → B) →
(f : A → B) →
Type (lsuc a ⊔ b ⊔ p)
Coherently P step f =
M (Coherently-container P step) (_ , f)
| {
"alphanum_fraction": 0.5395213923,
"avg_line_length": 29.3404255319,
"ext": "agda",
"hexsha": "a904ba847e74f863e251a28779d9bcef2839def9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher/Coherently/Not-coinductive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher/Coherently/Not-coinductive.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher/Coherently/Not-coinductive.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 430,
"size": 1379
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Maps from keys to values, based on AVL trees
-- This modules provides a simpler map interface, without a dependency
-- between the key and value types.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (StrictTotalOrder)
module Data.AVL.Map
{a ℓ₁ ℓ₂} (strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂)
where
open import Data.Bool.Base using (Bool)
open import Data.List.Base using (List)
open import Data.Maybe.Base using (Maybe)
open import Data.Product using (_×_)
open import Level using (_⊔_)
import Data.AVL strictTotalOrder as AVL
open StrictTotalOrder strictTotalOrder renaming (Carrier to Key)
------------------------------------------------------------------------
-- The map type
Map : ∀ {v} → (V : Set v) → Set (a ⊔ v ⊔ ℓ₂)
Map v = AVL.Tree (AVL.const v)
------------------------------------------------------------------------
-- Repackaged functions
module _ {v} {V : Set v} where
empty : Map V
empty = AVL.empty
singleton : Key → V → Map V
singleton = AVL.singleton
insert : Key → V → Map V → Map V
insert = AVL.insert
insertWith : Key → (Maybe V → V) → Map V → Map V
insertWith = AVL.insertWith
delete : Key → Map V → Map V
delete = AVL.delete
lookup : Key → Map V → Maybe V
lookup = AVL.lookup
module _ {v w} {V : Set v} {W : Set w} where
map : (V → W) → Map V → Map W
map f = AVL.map f
module _ {v} {V : Set v} where
infix 4 _∈?_
_∈?_ : Key → Map V → Bool
_∈?_ = AVL._∈?_
headTail : Map V → Maybe ((Key × V) × Map V)
headTail = AVL.headTail
initLast : Map V → Maybe (Map V × (Key × V))
initLast = AVL.initLast
fromList : List (Key × V) → Map V
fromList = AVL.fromList
toList : Map V → List (Key × V)
toList = AVL.toList
module _ {v w} {V : Set v} {W : Set w} where
unionWith : (V → Maybe W → W) →
Map V → Map W → Map W
unionWith f = AVL.unionWith f
module _ {v} {V : Set v} where
union : Map V → Map V → Map V
union = AVL.union
unionsWith : (V → Maybe V → V) → List (Map V) → Map V
unionsWith f = AVL.unionsWith f
unions : List (Map V) → Map V
unions = AVL.unions
| {
"alphanum_fraction": 0.5504146661,
"avg_line_length": 24.1157894737,
"ext": "agda",
"hexsha": "4ec7f3b73bef12b373d687882a96fd76861dc20d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/AVL/Map.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/AVL/Map.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/AVL/Map.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 660,
"size": 2291
} |
open import Agda.Builtin.IO
open import Agda.Builtin.List
open import Agda.Builtin.Size
open import Agda.Builtin.String
record Thunk (F : Size → Set) (i : Size) : Set where
coinductive
field force : {j : Size< i} → F j
open Thunk public
FilePath = String
-- A directory tree is rooted in the current directory; it comprises:
-- * a list of files in the current directory
-- * an IO action returning a list of subdirectory trees
-- This definition does not typecheck if IO is not marked as strictly positive
data DirectoryTree (i : Size) : Set where
_:<_ : List FilePath → IO (List (Thunk DirectoryTree i)) →
DirectoryTree i
| {
"alphanum_fraction": 0.7247278383,
"avg_line_length": 30.619047619,
"ext": "agda",
"hexsha": "e7a3a9ddf3d9eca0528753e33afcd7f155116d09",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/strictlypositiveio.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/strictlypositiveio.agda",
"max_line_length": 78,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/strictlypositiveio.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 170,
"size": 643
} |
module Issue358 where
postulate Sigma : Set -> (Set -> Set) -> Set
syntax Sigma A (\x -> B) = x colon A operator B
postulate T : Set
test = x colon T operator {!!}
| {
"alphanum_fraction": 0.6331360947,
"avg_line_length": 16.9,
"ext": "agda",
"hexsha": "441e00c6f8ad011d7e466003a6a712bb7cf1c102",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/interaction/Issue358.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/interaction/Issue358.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/interaction/Issue358.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 49,
"size": 169
} |
module Data.Variant where
open import Data.List using (List) renaming ([_] to [_]ₗ)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.Product using (∃; ∃-syntax; _,_)
open import Data.Maybe using (Maybe; _>>=_; just)
open import Data.Union using (Union; here) renaming (inj to injᵤ; proj to projᵤ)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Level using (Level)
-- ----------------------------------------------------------------------
-- Definitions
-- A variant is tagged tag. It is motiviated by the existence
-- of familys of tags.
data Variant {a} (A : Set a) : A → Set a where
-- injects a into a Variant indexed by a
[_] : (a : A) → Variant A a
-- A polymorphic variant is a open union of variants
Variants : ∀ {a} (A : Set a) → List A → Set a
Variants A ts = Union A (Variant A) ts
-- ----------------------------------------------------------------------
-- Injections and projects to (and from) variants
private
variable
a b : Level
A : Set a
t : A
ts ts′ : List A
inj : (t : A) → t ∈ ts → Variants A ts
inj t t∈ts = injᵤ t∈ts ([ t ])
`_ : (t : A) → ⦃ t ∈ ts ⦄ → Variants A ts
`_ t ⦃ t∈ts ⦄ = inj t t∈ts
Proj : ∀ {a} (A : Set a) → (t : A) → Set a
Proj A t = ∃ λ t′ → t ≡ t′
proj : t ∈ ts → Variants A ts → Maybe (Proj A t)
proj t∈ts x = projᵤ t∈ts x >>= λ{ [ t ] → just (t , refl)}
`proj : ⦃ t ∈ ts ⦄ → Variants A ts → Maybe (Proj A t)
`proj ⦃ t∈ts ⦄ x = proj t∈ts x
proj₀ : Variants A [ t ]ₗ → Proj A t
proj₀ (here [ t ]) = t , refl
| {
"alphanum_fraction": 0.5539057456,
"avg_line_length": 26.2542372881,
"ext": "agda",
"hexsha": "675c9014e4498e6e26c319acb51b6215419644a5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "johnyob/agda-union",
"max_forks_repo_path": "src/Data/Variant.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "johnyob/agda-union",
"max_issues_repo_path": "src/Data/Variant.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "johnyob/agda-union",
"max_stars_repo_path": "src/Data/Variant.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 518,
"size": 1549
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Cocomplete.Properties {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Data.Product using (_,_)
open import Categories.Adjoint.Properties
open import Categories.Category.Complete
open import Categories.Category.Complete.Properties
open import Categories.Category.Cocomplete
open import Categories.Category.Cocomplete.Finitely
open import Categories.Category.Duality
open import Categories.Category.Construction.Functors
open import Categories.Functor
open import Categories.Functor.Cocontinuous
open import Categories.Functor.Duality
open import Categories.NaturalTransformation as N
open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_)
open import Categories.Diagram.Limit
open import Categories.Diagram.Limit.Properties
open import Categories.Diagram.Colimit
open import Categories.Diagram.Duality
import Categories.Morphism.Reasoning as MR
private
variable
o′ ℓ′ e′ o″ ℓ″ e″ : Level
module C = Category C
Cocomplete⇒FinitelyCocomplete : Cocomplete o′ ℓ′ e′ C → FinitelyCocomplete C
Cocomplete⇒FinitelyCocomplete Coc =
coFinitelyComplete⇒FinitelyCocomplete C (Complete⇒FinitelyComplete C.op (Cocomplete⇒coComplete C Coc))
module _ {D : Category o′ ℓ′ e′} (Coc : Cocomplete o″ ℓ″ e″ D) where
private
module D = Category D
Functors-Cocomplete : Cocomplete o″ ℓ″ e″ (Functors C D)
Functors-Cocomplete {J} F = coLimit⇒Colimit (Functors C D) LFop
where module J = Category J
module F = Functor F
open Functor F
F′ : Functor J.op (Functors C.op D.op)
F′ = opF⇒ ∘F F.op
L : (H : Functor J.op (Functors C.op D.op)) → Limit H
L = Functors-Complete C.op {D = D.op} (λ G → Colimit⇒coLimit D (Coc (Functor.op G)))
LF′ : Limit F′
LF′ = L F′
LF″ : Limit (opF⇐ ∘F F′)
LF″ = rapl (Functorsᵒᵖ-equiv.L⊣R C.op D.op) F′ LF′
iso : opF⇐ ∘F F′ ≃ F.op
iso = record
{ F⇒G = ntHelper record
{ η = λ _ → N.id
; commute = λ f → id-comm
}
; F⇐G = ntHelper record
{ η = λ _ → N.id
; commute = λ f → id-comm
}
; iso = λ j → record
{ isoˡ = D.identity²
; isoʳ = D.identity²
}
}
where open MR D
LFop : Limit op
LFop = ≃-resp-lim iso LF″
-- TODO: need to refactor the where block above to show cocontinuous. there is no need to do it now.
--
-- evalF-Cocontinuous : ∀ X → Cocontinuous o″ ℓ″ e″ (evalF C D X)
-- evalF-Cocontinuous X {J} {F} L = Coc (evalF C D X ∘F F) , {!!}
-- where
| {
"alphanum_fraction": 0.6292577985,
"avg_line_length": 33.2023809524,
"ext": "agda",
"hexsha": "81fc8691ca0d1ad041fd43dc3bab11b775de8b88",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Cocomplete/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Cocomplete/Properties.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Cocomplete/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 802,
"size": 2789
} |
module STLCRef.Examples where
-- This file contains a few example programs for the definitional
-- interpreter for STLC+Ref using monadic strength, defined in Section
-- 3.
open import STLCRef.Semantics
open import Data.List
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Unary.All
open import Relation.Binary.PropositionalEquality
open import Data.Integer hiding (suc)
open import Agda.Builtin.Nat hiding (_+_)
open import Data.Maybe
open import Data.Product
-------------------
-- STLC FRAGMENT --
-------------------
-- The identity function: λ x . x
idexpr : Expr [] (unit ⇒ unit)
idexpr = ƛ (var (here refl))
-- id () = ()
test-idexpr : eval 2 (idexpr · unit) [] [] ≡ just (_ , [] , unit , _)
test-idexpr = refl
-- curried addition: λ x . λ y . y + x
curry+ : Expr [] (int ⇒ (int ⇒ int))
curry+ = ƛ (ƛ (iop _+_ (var (here refl)) (var (there (here refl)))))
-- 1 + 1 = 2
test-curry+ : eval 3 ((curry+ · (num (+ (suc zero)))) · (num (+ (suc zero)))) [] []
≡ just (_ , [] , num (+ (suc (suc zero))) , _)
test-curry+ = refl
------------------
-- REF FRAGMENT --
------------------
-- Sugar for let: LET e1 e2 = (λ x . e2) e1
LET : ∀ {Γ a b} → Expr Γ a → Expr (a ∷ Γ) b → Expr Γ b
LET bnd bod = (ƛ bod) · bnd
-- Factorial function, defined via Landin's knot:
--
-- let r = ref (λ x . x) in
-- let f = λ n . ifz n then 1 else n * (!r (n - 1)) in
-- let _ = r := f in
-- f 4
landin-fac : Expr [] int
landin-fac =
LET (ref {t = int ⇒ int} (ƛ (var (here refl))))
(LET (ƛ {a = int} (ifz (var (here refl))
(num (+ 1))
(iop (Data.Integer._*_) (var (here refl))
((! (var (there (here refl)))) · (iop (Data.Integer._-_) (var (here refl)) (num (+ 1)))))))
(LET ((var (there (here refl))) ≔ var (here refl))
(var (there (here refl))) · (num (+ 4))))
test-landin-fac : eval 20 landin-fac [] [] ≡ just (_ , _ , num (+ 24) , _)
test-landin-fac = refl
-- Divergence via Landin's knot:
--
-- let r = ref (λ x . x) in
-- let f = λ x . !r 0 in
-- let _ = r := f in
-- f 0
landin-div : Expr [] int
landin-div =
LET (ref {t = int ⇒ int} (ƛ (var (here refl))))
(LET (ƛ {a = int} ((! (var (there (here refl)))) · num (+ zero)))
(LET ((var (there (here refl))) ≔ var (here refl))
(var (there (here refl))) · (num (+ zero))))
test-landin-div : eval 1337 landin-div [] [] ≡ nothing
test-landin-div = refl
| {
"alphanum_fraction": 0.5472861842,
"avg_line_length": 28.9523809524,
"ext": "agda",
"hexsha": "3c280d0ebb37dd45c9ef0ca35bdf514b1eadf2cf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/STLCRef/Examples.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/STLCRef/Examples.agda",
"max_line_length": 121,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/STLCRef/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 813,
"size": 2432
} |
-- Proof: if we non-deterministically select an element
-- which is less-than-or-equal than all other elements,
-- such a result is the minimum of the list.
-- This holds for any non-deterministically selected element.
-- Basically, this is the translation of the Curry rule:
--
-- min-nd xs@(_++[x]++_) | all (x<=) xs = x
--
open import bool
module minlist-is-correct
(Choice : Set)
(choose : Choice → 𝔹)
(lchoice : Choice → Choice)
(rchoice : Choice → Choice)
where
open import eq
open import bool-thms
open import bool-thms2
open import nat
open import nat-thms
open import list
open import maybe
open import inspect
----------------------------------------------------------------------
-- Some auxiliaries:
-- We define our own less-or-equal since the standard definition with
-- if-then-else produces too many branches:
_<=_ : ℕ → ℕ → 𝔹
0 <= y = tt
(suc x) <= 0 = ff
(suc x) <= (suc y) = x <= y
-- Some properties about less-or-equal:
<=-refl : ∀ (x : ℕ) → x <= x ≡ tt
<=-refl 0 = refl
<=-refl (suc x) = <=-refl x
<=-trans : ∀ (x y z : ℕ) → x <= y ≡ tt → y <= z ≡ tt → x <= z ≡ tt
<=-trans zero y z p1 p2 = refl
<=-trans (suc x) zero z p1 p2 = 𝔹-contra p1
<=-trans (suc x) (suc y) zero p1 p2 = 𝔹-contra p2
<=-trans (suc x) (suc y) (suc z) p1 p2 = <=-trans x y z p1 p2
<=-< : ∀ (x y : ℕ) → x <= y ≡ ff → y < x ≡ tt
<=-< zero x ()
<=-< (suc x) zero p = refl
<=-< (suc x) (suc y) p = <=-< x y p
<-<= : ∀ (x y : ℕ) → x < y ≡ tt → y <= x ≡ ff
<-<= x zero p rewrite <-0 x = 𝔹-contra p
<-<= zero (suc y) p = refl
<-<= (suc x) (suc y) p = <-<= x y p
<-<=-ff : ∀ (x y : ℕ) → x < y ≡ ff → y <= x ≡ tt
<-<=-ff zero zero p = refl
<-<=-ff zero (suc y) p = 𝔹-contra (sym p)
<-<=-ff (suc x) zero p = refl
<-<=-ff (suc x) (suc y) p = <-<=-ff x y p
<-<=-trans : ∀ (x y z : ℕ) → x < y ≡ tt → y <= z ≡ tt → x < z ≡ tt
<-<=-trans zero zero z p1 p2 = 𝔹-contra p1
<-<=-trans zero (suc y) zero p1 p2 = 𝔹-contra p2
<-<=-trans zero (suc y) (suc z) p1 p2 = refl
<-<=-trans (suc x) zero z p1 p2 = 𝔹-contra p1
<-<=-trans (suc x) (suc y) zero p1 p2 = 𝔹-contra p2
<-<=-trans (suc x) (suc y) (suc z) p1 p2 = <-<=-trans x y z p1 p2
----------------------------------------------------------------------
-- More lemmas about ordering relations:
leq-if : ∀ (x y z : ℕ)
→ y <= x && y <= z ≡ (if x <= z then y <= x else y <= z)
leq-if x y z with inspect (y <= x)
leq-if x y z | it tt p1 with inspect (x <= z)
... | it tt p2 rewrite p1 | p2 | <=-trans y x z p1 p2 = refl
... | it ff p2 rewrite p1 | p2 = refl
leq-if x y z | it ff p1 with inspect (x <= z)
... | it tt p2 rewrite p1 | p2 = refl
... | it ff p2 rewrite p1 | p2
| <-<= z y (<-trans {z} {x} {y} (<=-< x z p2) (<=-< y x p1)) = refl
le-if : ∀ (x y z : ℕ)
→ y < x && y < z ≡ (if x <= z then y < x else y < z)
le-if x y z with inspect (y < x)
le-if x y z | it tt p1 with inspect (x <= z)
... | it tt p2 rewrite p1 | p2 | <-<=-trans y x z p1 p2 = refl
... | it ff p2 rewrite p1 | p2 = refl
le-if x y z | it ff p1 with inspect (x <= z)
... | it tt p2 rewrite p1 | p2 = refl
... | it ff p2 rewrite p1 | p2
| <-asym {z} {y} (<-<=-trans z x y (<=-< x z p2) (<-<=-ff y x p1))
= refl
----------------------------------------------------------------------
-- A lemma relating equality and orderings:
=ℕ-not-le : ∀ (m n : ℕ) → m =ℕ n ≡ ~ (m < n) && m <= n
=ℕ-not-le zero zero = refl
=ℕ-not-le zero (suc m) = refl
=ℕ-not-le (suc n) zero = refl
=ℕ-not-le (suc n) (suc m) = =ℕ-not-le n m
----------------------------------------------------------------------
-- This is the translation of the Curry program:
-- Check whether all elements of a list satisfy a given predicate:
all : {A : Set} → (A → 𝔹) → 𝕃 A → 𝔹
all _ [] = tt
all p (x :: xs) = p x && all p xs
-- Deterministic min-d:
min-d : (l : 𝕃 ℕ) → is-empty l ≡ ff → ℕ
min-d [] ()
min-d (x :: []) _ = x
min-d (x :: y :: xs) _ =
--if x <= min-d (y :: xs) refl then x else min-d (y :: xs) refl
let z = min-d (y :: xs) refl
in if x <= z then x else z
-- Select some element from a list:
select : {A : Set} → Choice → 𝕃 A -> maybe A
select _ [] = nothing
select ch (x :: xs) = if choose ch then just x
else select (lchoice ch) xs
-- Select elements with a property from a list:
select-with : {A : Set} → Choice → (A → 𝔹) → 𝕃 A → maybe A
select-with _ p [] = nothing
select-with ch p (x :: xs) =
if choose ch then (if p x then just x else nothing)
else select-with (lchoice ch) p xs
{-
-- more or less original definition:
min-nd : Choice → 𝕃 ℕ -> maybe ℕ
min-nd ch xs = (select ch xs) ≫=maybe
(λ y → if all (_<=_ y) xs then just y else nothing)
-}
min-nd : Choice → (xs : 𝕃 ℕ) → maybe ℕ
min-nd ch xs = select-with ch (λ x → all (_<=_ x) xs) xs
----------------------------------------------------------------------
-- Proof of the correctness of the operation select-with:
select-with-correct : ∀ {A : Set}
→ (ch : Choice) (p : A → 𝔹) (xs : 𝕃 A) (z : A)
→ select-with ch p xs ≡ just z → p z ≡ tt
select-with-correct ch p [] z ()
select-with-correct ch p (x :: xs) z u with choose ch
select-with-correct ch p (x :: xs) z u | tt with inspect (p x)
select-with-correct ch p (x :: xs) z u | tt | it tt v rewrite v | u | down-≡ u
= v
select-with-correct ch p (x :: xs) z u | tt | it ff v rewrite v with u
select-with-correct ch p (x :: xs) z u | tt | it ff v | ()
select-with-correct ch p (x :: xs) z u | ff =
select-with-correct (lchoice ch) p xs z u
----------------------------------------------------------------------
-- First step: if y smaller than all elements, y is smaller than the minimum:
all-leq-min : ∀ (y x : ℕ) (xs : 𝕃 ℕ)
→ all (_<=_ y) (x :: xs) ≡ y <= min-d (x :: xs) refl
all-leq-min y x [] = &&-tt (y <= x)
all-leq-min y x (z :: zs)
rewrite all-leq-min y z zs
| ite-arg (_<=_ y) (x <= min-d (z :: zs) refl) x (min-d (z :: zs) refl)
= leq-if x y (min-d (z :: zs) refl)
-- Now we can prove:
-- if min-nd selects an element, it is smaller or equal than the minimum:
min-nd-select-min-d : ∀ (ch : Choice) (x : ℕ) (xs : 𝕃 ℕ) (z : ℕ)
→ min-nd ch (x :: xs) ≡ just z → z <= min-d (x :: xs) refl ≡ tt
min-nd-select-min-d ch x xs z u
rewrite sym (all-leq-min z x xs)
| select-with-correct ch (λ y → all (_<=_ y) (x :: xs)) (x :: xs) z u
= refl
----------------------------------------------------------------------
-- Next step: if y smaller than all elements, y is smaller than the minimum:
all-less-min : ∀ (y x : ℕ) (xs : 𝕃 ℕ)
→ all (_<_ y) (x :: xs) ≡ y < min-d (x :: xs) refl
all-less-min y x [] rewrite &&-tt (y < x) = refl
all-less-min y x (z :: zs)
rewrite all-less-min y z zs
| ite-arg (_<_ y) (x <= min-d (z :: zs) refl) x (min-d (z :: zs) refl)
= le-if x y (min-d (z :: zs) refl)
-- Next want to prove that the element selected by min-nd cannot be smaller
-- than the minimum.
-- For this purpose, we prove an auxiliary lemma:
-- If an element is selected from a list, it cannot be smaller than all elements
select-with-all<-ff : ∀ (ch : Choice) (p : ℕ → 𝔹) (xs : 𝕃 ℕ) (z : ℕ)
→ select-with ch p xs ≡ just z → all (_<_ z) xs ≡ ff
select-with-all<-ff ch _ [] z ()
select-with-all<-ff ch p (x :: xs) z u with (choose ch)
select-with-all<-ff ch p (x :: xs) z u | tt with (p x)
select-with-all<-ff ch p (x :: xs) z u | tt | tt rewrite down-≡ u | <-irrefl z
= refl
select-with-all<-ff ch p (x :: xs) z () | tt | ff
select-with-all<-ff ch p (x :: xs) z u | ff
rewrite select-with-all<-ff (lchoice ch) p xs z u | &&-ff (z < x) = refl
-- Now we can prove: if min-nd selects an element, it cannot be smaller
-- than all other elements:
min-nd-select-all<-ff : ∀ (ch : Choice) (xs : 𝕃 ℕ) (z : ℕ)
→ min-nd ch xs ≡ just z → all (_<_ z) xs ≡ ff
min-nd-select-all<-ff ch xs z u
rewrite select-with-all<-ff ch (λ y → all (_<=_ y) xs) xs z u = refl
----------------------------------------------------------------------
-- This is the main theorem:
min-nd-theorem : ∀ (ch : Choice) (x : ℕ) (xs : 𝕃 ℕ) (z : ℕ)
→ min-nd ch (x :: xs) ≡ just z → z =ℕ min-d (x :: xs) refl ≡ tt
min-nd-theorem ch x xs z u
rewrite
=ℕ-not-le z (min-d (x :: xs) refl) -- split equality into no less and leq
| min-nd-select-min-d ch x xs z u -- min-nd selects leq min. elements
| sym (all-less-min z x xs) -- less-than min. elements satisfy all<
| min-nd-select-all<-ff ch (x :: xs) z u -- min-nd can't select any all< element
= refl
----------------------------------------------------------------------
| {
"alphanum_fraction": 0.5105465563,
"avg_line_length": 36.514893617,
"ext": "agda",
"hexsha": "141e6baaf47f1d29d10b75ae32c0e7713ca3f192",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "mihanus/curry-agda",
"max_forks_repo_path": "choices/minlist-is-correct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "mihanus/curry-agda",
"max_issues_repo_path": "choices/minlist-is-correct.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "mihanus/curry-agda",
"max_stars_repo_path": "choices/minlist-is-correct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3001,
"size": 8581
} |
{-
A Cubical proof of Blakers-Massey Theorem (KANG Rongji, Oct. 2021)
Based on the previous type-theoretic proof described in
Kuen-Bang Hou (Favonia), Eric Finster, Dan Licata, Peter LeFanu Lumsdaine,
"A Mechanization of the Blakers–Massey Connectivity Theorem in Homotopy Type Theory"
(https://arxiv.org/abs/1605.03227)
Also the HoTT-Agda formalization by Favonia:
(https://github.com/HoTT/HoTT-Agda/blob/master/theorems/homotopy/BlakersMassey.agda)
Using cubes explicitly as much as possible.
-}
{-# OPTIONS --safe #-}
module Cubical.Homotopy.BlakersMassey where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.HITs.Truncation renaming (hLevelTrunc to Trunc)
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.WedgeConnectivity
module BlakersMassey {ℓ₁ ℓ₂ ℓ₃ : Level}
(X : Type ℓ₁)(Y : Type ℓ₂)(Q : X → Y → Type ℓ₃)
{m : HLevel} (leftConn : (x : X) → isConnected (1 + m) (Σ[ y ∈ Y ] Q x y))
{n : HLevel} (rightConn : (y : Y) → isConnected (1 + n) (Σ[ x ∈ X ] Q x y))
where
ℓ : Level
ℓ = ℓ-max (ℓ-max ℓ₁ ℓ₂) ℓ₃
leftFiber : X → Type (ℓ-max ℓ₂ ℓ₃)
leftFiber x = Σ[ y ∈ Y ] Q x y
rightFiber : Y → Type (ℓ-max ℓ₁ ℓ₃)
rightFiber y = Σ[ x ∈ X ] Q x y
{- An alternative formulation of pushout with fewer parameters -}
data Pushout : Type ℓ
where
inl : X → Pushout
inr : Y → Pushout
push : {x : X}{y : Y} → Q x y → inl x ≡ inr y
{- Some preliminary definitions for convenience -}
fiberSquare :
{x₀ x₁ : X}{y₀ : Y}{p : Pushout}(q₀₀ : Q x₀ y₀)(q₁₀ : Q x₁ y₀)
→ inl x₁ ≡ p → inl x₀ ≡ p → Type ℓ
fiberSquare q₀₀ q₁₀ r' r = PathP (λ i → push q₀₀ (~ i) ≡ r' i) (sym (push q₁₀)) r
fiberSquarePush :
{x₀ x₁ : X}{y₀ y₁ : Y}(q₀₀ : Q x₀ y₀)(q₁₀ : Q x₁ y₀)(q₁₁ : Q x₁ y₁)
→ inl x₀ ≡ inr y₁ → Type ℓ
fiberSquarePush q₀₀ q₁₀ q₁₁ = fiberSquare q₀₀ q₁₀ (push q₁₁)
fiber' : {x₀ : X}{y₀ : Y}(q₀₀ : Q x₀ y₀){x₁ : X}{p : Pushout} → inl x₁ ≡ p → inl x₀ ≡ p → Type ℓ
fiber' {y₀ = y₀} q₀₀ {x₁ = x₁} r' r = Σ[ q₁₀ ∈ Q x₁ y₀ ] fiberSquare q₀₀ q₁₀ r' r
fiber'Push : {x₀ x₁ : X}{y₀ y₁ : Y}(q₀₀ : Q x₀ y₀)(q₁₁ : Q x₁ y₁) → inl x₀ ≡ inr y₁ → Type ℓ
fiber'Push q₀₀ q₁₁ = fiber' q₀₀ (push q₁₁)
leftCodeExtended :
{x₀ : X}{y₀ : Y}(q₀₀ : Q x₀ y₀)
→ (x₁ : X){p : Pushout} → inl x₁ ≡ p → inl x₀ ≡ p → Type ℓ
leftCodeExtended {y₀ = y₀} q₀₀ x₁ r' r = Trunc (m + n) (fiber' q₀₀ r' r)
rightCode : {x₀ : X}(y : Y) → inl x₀ ≡ inr y → Type ℓ
rightCode y r = Trunc (m + n) (fiber push r)
{- Bunch of coherence data that will be used to construct Code -}
{- Definitions of fiber→ -}
module _
{x₁ : X}{y₀ : Y}(q₁₀ : Q x₁ y₀) where
{- (x₀ , q₀₀) = (x₁ , q₁₀) -}
module _
{y₁ : Y}(q₁₁ : Q x₁ y₁)
(r : inl x₁ ≡ inr y₁)
(p : fiberSquarePush q₁₀ q₁₀ q₁₁ r) where
fiber→[q₀₀=q₁₀]-filler : (i j k : I) → Pushout
fiber→[q₀₀=q₁₀]-filler i j k' =
hfill (λ k → λ { (i = i0) → push q₁₁ (j ∧ k)
; (i = i1) → p k j
; (j = i0) → push q₁₀ (i ∧ ~ k)
; (j = i1) → push q₁₁ k })
(inS (push q₁₀ (i ∧ ~ j))) k'
fiber→[q₀₀=q₁₀] : fiber push r
fiber→[q₀₀=q₁₀] .fst = q₁₁
fiber→[q₀₀=q₁₀] .snd i j = fiber→[q₀₀=q₁₀]-filler i j i1
∣fiber→[q₀₀=q₁₀]∣ : rightCode _ r
∣fiber→[q₀₀=q₁₀]∣ = ∣ fiber→[q₀₀=q₁₀] ∣ₕ
{- (y₁ , q₁₁) = (y₀ , q₁₀) -}
module _
{x₀ : X}(q₀₀ : Q x₀ y₀)
(r : inl x₀ ≡ inr y₀)
(p : fiberSquarePush q₀₀ q₁₀ q₁₀ r) where
fiber→[q₁₁=q₁₀]-filler : (i j k : I) → Pushout
fiber→[q₁₁=q₁₀]-filler i j k' =
hfill (λ k → λ { (i = i0) → push q₀₀ (j ∨ ~ k)
; (i = i1) → p k j
; (j = i0) → push q₀₀ (~ k)
; (j = i1) → push q₁₀ (~ i ∨ k) })
(inS (push q₁₀ (~ i ∨ ~ j))) k'
fiber→[q₁₁=q₁₀] : fiber push r
fiber→[q₁₁=q₁₀] .fst = q₀₀
fiber→[q₁₁=q₁₀] .snd i j = fiber→[q₁₁=q₁₀]-filler i j i1
∣fiber→[q₁₁=q₁₀]∣ : rightCode _ r
∣fiber→[q₁₁=q₁₀]∣ = ∣ fiber→[q₁₁=q₁₀] ∣ₕ
{- q₀₀ = q₁₁ = q₁₀ -}
fiber→[q₀₀=q₁₀=q₁₁]-filler :
(r : inl x₁ ≡ inr y₀)
→ (p : fiberSquarePush q₁₀ q₁₀ q₁₀ r)
→ (i j k l : I) → Pushout
fiber→[q₀₀=q₁₀=q₁₁]-filler r p i j k l' =
hfill (λ l → λ { (i = i0) → fiber→[q₀₀=q₁₀]-filler q₁₀ r p j k l
; (i = i1) → fiber→[q₁₁=q₁₀]-filler q₁₀ r p j k l
; (j = i0) → push q₁₀ ((i ∨ (k ∧ l)) ∧ (k ∨ (i ∧ ~ l)))
; (j = i1) → p l k
; (k = i0) → push q₁₀ ((i ∨ j) ∧ ~ l)
; (k = i1) → push q₁₀ ((i ∧ ~ j) ∨ l) })
(inS (push q₁₀ ((i ∨ (~ k ∧ j)) ∧ (~ k ∨ (i ∧ ~ j))))) l'
fiber→[q₀₀=q₁₀=q₁₁] : fiber→[q₀₀=q₁₀] q₁₀ ≡ fiber→[q₁₁=q₁₀] q₁₀
fiber→[q₀₀=q₁₀=q₁₁] i r p .fst = q₁₀
fiber→[q₀₀=q₁₀=q₁₁] i r p .snd j k = fiber→[q₀₀=q₁₀=q₁₁]-filler r p i j k i1
∣fiber→[q₀₀=q₁₀=q₁₁]∣ : ∣fiber→[q₀₀=q₁₀]∣ q₁₀ ≡ ∣fiber→[q₁₁=q₁₀]∣ q₁₀
∣fiber→[q₀₀=q₁₀=q₁₁]∣ i r p = ∣ fiber→[q₀₀=q₁₀=q₁₁] i r p ∣ₕ
{- Definitions of fiber← -}
module _
{x₀ : X}{y₁ : Y}(q₀₁ : Q x₀ y₁) where
{- (x₁ , q₁₁) = (x₀ , q₀₁) -}
module _
{y₀ : Y}(q₀₀ : Q x₀ y₀)
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
fiber←[q₁₁=q₀₁]-filler : (i j k : I) → Pushout
fiber←[q₁₁=q₀₁]-filler i j k' =
hfill (λ k → λ { (i = i0) → push q₀₀ (~ j ∧ k)
; (i = i1) → p k j
; (j = i0) → push q₀₀ (~ i ∧ k)
; (j = i1) → push q₀₁ i })
(inS (push q₀₁ (i ∧ j))) k'
fiber←[q₁₁=q₀₁] : fiber'Push q₀₀ q₀₁ r
fiber←[q₁₁=q₀₁] .fst = q₀₀
fiber←[q₁₁=q₀₁] .snd i j = fiber←[q₁₁=q₀₁]-filler i j i1
∣fiber←[q₁₁=q₀₁]∣ : leftCodeExtended q₀₀ _ (push q₀₁) r
∣fiber←[q₁₁=q₀₁]∣ = ∣ fiber←[q₁₁=q₀₁] ∣ₕ
{- (y₀ , q₀₀) = (y₁ , q₀₁) -}
module _
{x₁ : X}(q₁₁ : Q x₁ y₁)
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
fiber←[q₀₀=q₀₁]-filler : (i j k : I) → Pushout
fiber←[q₀₀=q₀₁]-filler i j k' =
hfill (λ k → λ { (i = i0) → push q₁₁ (~ j ∨ ~ k)
; (i = i1) → p k j
; (j = i0) → push q₀₁ (~ i)
; (j = i1) → push q₁₁ (i ∨ ~ k) })
(inS (push q₀₁ (~ i ∨ j))) k'
fiber←[q₀₀=q₀₁] : fiber'Push q₀₁ q₁₁ r
fiber←[q₀₀=q₀₁] .fst = q₁₁
fiber←[q₀₀=q₀₁] .snd i j = fiber←[q₀₀=q₀₁]-filler i j i1
∣fiber←[q₀₀=q₀₁]∣ : leftCodeExtended q₀₁ _ (push q₁₁) r
∣fiber←[q₀₀=q₀₁]∣ = ∣ fiber←[q₀₀=q₀₁] ∣ₕ
{- q₀₀ = q₀₁ = q₁₁ -}
fiber←[q₀₀=q₀₁=q₁₁]-filler :
(r : inl x₀ ≡ inr y₁)
→ (p : push q₀₁ ≡ r)
→ (i j k l : I) → Pushout
fiber←[q₀₀=q₀₁=q₁₁]-filler r p i j k l' =
hfill (λ l → λ { (i = i0) → fiber←[q₁₁=q₀₁]-filler q₀₁ r p j k l
; (i = i1) → fiber←[q₀₀=q₀₁]-filler q₀₁ r p j k l
; (j = i0) → push q₀₁ ((i ∨ (~ k ∧ l)) ∧ (~ k ∨ (i ∧ ~ l)))
; (j = i1) → p l k
; (k = i0) → push q₀₁ ((i ∨ l) ∧ ~ j)
; (k = i1) → push q₀₁ ((i ∧ ~ l) ∨ j) })
(inS (push q₀₁ ((i ∨ (k ∧ j)) ∧ (k ∨ (i ∧ ~ j))))) l'
fiber←[q₀₀=q₀₁=q₁₁] : fiber←[q₁₁=q₀₁] q₀₁ ≡ fiber←[q₀₀=q₀₁] q₀₁
fiber←[q₀₀=q₀₁=q₁₁] i r p .fst = q₀₁
fiber←[q₀₀=q₀₁=q₁₁] i r p .snd j k = fiber←[q₀₀=q₀₁=q₁₁]-filler r p i j k i1
∣fiber←[q₀₀=q₀₁=q₁₁]∣ : ∣fiber←[q₁₁=q₀₁]∣ q₀₁ ≡ ∣fiber←[q₀₀=q₀₁]∣ q₀₁
∣fiber←[q₀₀=q₀₁=q₁₁]∣ i r p = ∣ fiber←[q₀₀=q₀₁=q₁₁] i r p ∣ₕ
{- Definitions of fiber→← -}
module _
{x₁ : X}{y₀ : Y}(q₁₀ : Q x₁ y₀) where
{- (x₀ , q₀₀) = (x₁ , q₁₀) -}
module _
{y₁ : Y}(q₁₁ : Q x₁ y₁)
(r : inl x₁ ≡ inr y₁)
(p : fiberSquarePush q₁₀ q₁₀ q₁₁ r) where
fiber→←[q₀₀=q₁₀]-filler : (i j k l : I) → Pushout
fiber→←[q₀₀=q₁₀]-filler i j k l' =
let p' = fiber→[q₀₀=q₁₀] q₁₀ q₁₁ r p .snd in
hfill (λ l → λ { (i = i0) → fiber←[q₁₁=q₀₁]-filler q₁₁ q₁₀ r p' j k l
; (i = i1) → fiber→[q₀₀=q₁₀]-filler q₁₀ q₁₁ r p l k j
; (j = i0) → push q₁₀ (~ k ∧ l)
; (j = i1) → p' l k
; (k = i0) → push q₁₀ (~ j ∧ l)
; (k = i1) → push q₁₁ j })
(inS (push q₁₁ (j ∧ k))) l'
fiber→←[q₀₀=q₁₀] : fiber←[q₁₁=q₀₁] q₁₁ q₁₀ r (fiber→[q₀₀=q₁₀] q₁₀ q₁₁ r p .snd) .snd ≡ p
fiber→←[q₀₀=q₁₀] i j k = fiber→←[q₀₀=q₁₀]-filler i j k i1
{- (y₁ , q₁₁) = (y₀ , q₁₀) -}
module _
{x₀ : X}(q₀₀ : Q x₀ y₀)
(r : inl x₀ ≡ inr y₀)
(p : fiberSquarePush q₀₀ q₁₀ q₁₀ r) where
fiber→←[q₁₁=q₁₀]-filler : (i j k l : I) → Pushout
fiber→←[q₁₁=q₁₀]-filler i j k l' =
let p' = fiber→[q₁₁=q₁₀] q₁₀ q₀₀ r p .snd in
hfill (λ l → λ { (i = i0) → fiber←[q₀₀=q₀₁]-filler q₀₀ q₁₀ r p' j k l
; (i = i1) → fiber→[q₁₁=q₁₀]-filler q₁₀ q₀₀ r p l k j
; (j = i0) → push q₁₀ (~ k ∨ ~ l)
; (j = i1) → p' l k
; (k = i0) → push q₀₀ (~ j)
; (k = i1) → push q₁₀ (j ∨ ~ l) })
(inS (push q₀₀ (~ j ∨ k))) l'
fiber→←[q₁₁=q₁₀] : fiber←[q₀₀=q₀₁] q₀₀ q₁₀ r (fiber→[q₁₁=q₁₀] q₁₀ q₀₀ r p .snd) .snd ≡ p
fiber→←[q₁₁=q₁₀] i j k = fiber→←[q₁₁=q₁₀]-filler i j k i1
{- q₀₀ = q₁₀ = q₁₁ -}
fiber→←hypercube :
(r : inl x₁ ≡ inr y₀)
→ (p : fiberSquarePush q₁₀ q₁₀ q₁₀ r)
→ PathP (λ i → fiber←[q₀₀=q₀₁=q₁₁] q₁₀ i r (fiber→[q₀₀=q₁₀=q₁₁] q₁₀ i r p .snd) .snd ≡ p)
(fiber→←[q₀₀=q₁₀] q₁₀ r p) (fiber→←[q₁₁=q₁₀] q₁₀ r p)
fiber→←hypercube r p i j u v =
hcomp (λ l → λ { (i = i0) → fiber→←[q₀₀=q₁₀]-filler q₁₀ r p j u v l
; (i = i1) → fiber→←[q₁₁=q₁₀]-filler q₁₀ r p j u v l
; (j = i0) → fiber←[q₀₀=q₀₁=q₁₁]-filler q₁₀ r (fiber→[q₀₀=q₁₀=q₁₁] q₁₀ i r p .snd) i u v l
; (j = i1) → fiber→[q₀₀=q₁₀=q₁₁]-filler q₁₀ r p i l v u
; (u = i0) → push q₁₀ ((i ∨ (~ v ∧ l)) ∧ (~ v ∨ (i ∧ ~ l)))
; (u = i1) → fiber→[q₀₀=q₁₀=q₁₁] q₁₀ i r p .snd l v
; (v = i0) → push q₁₀ ((i ∨ l) ∧ ~ u)
; (v = i1) → push q₁₀ ((i ∧ ~ l) ∨ u) })
(push q₁₀ ((i ∨ (v ∧ u)) ∧ (v ∨ (i ∧ ~ u))))
{- Definitions of fiber←→ -}
module _
{x₀ : X}{y₁ : Y}(q₀₁ : Q x₀ y₁) where
{- (x₁ , q₁₁) = (x₀ , q₀₁) -}
module _
{y₀ : Y}(q₀₀ : Q x₀ y₀)
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
fiber←→[q₁₁=q₀₁]-filler : (i j k l : I) → Pushout
fiber←→[q₁₁=q₀₁]-filler i j k l' =
let p' = fiber←[q₁₁=q₀₁] q₀₁ q₀₀ r p .snd in
hfill (λ l → λ { (i = i0) → fiber→[q₀₀=q₁₀]-filler q₀₀ q₀₁ r p' j k l
; (i = i1) → fiber←[q₁₁=q₀₁]-filler q₀₁ q₀₀ r p l k j
; (j = i0) → push q₀₁ (k ∧ l)
; (j = i1) → p' l k
; (k = i0) → push q₀₀ (j ∧ ~ l)
; (k = i1) → push q₀₁ l })
(inS (push q₀₀ (j ∧ ~ k))) l'
fiber←→[q₁₁=q₀₁] : fiber→[q₀₀=q₁₀] q₀₀ q₀₁ r (fiber←[q₁₁=q₀₁] q₀₁ q₀₀ r p .snd) .snd ≡ p
fiber←→[q₁₁=q₀₁] i j k = fiber←→[q₁₁=q₀₁]-filler i j k i1
{- (y₀ , q₀₀) = (y₁ , q₀₁) -}
module _
{x₁ : X}(q₁₁ : Q x₁ y₁)
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
fiber←→[q₀₀=q₀₁]-filler : (i j k l : I) → Pushout
fiber←→[q₀₀=q₀₁]-filler i j k l' =
let p' = fiber←[q₀₀=q₀₁] q₀₁ q₁₁ r p .snd in
hfill (λ l → λ { (i = i0) → fiber→[q₁₁=q₁₀]-filler q₁₁ q₀₁ r p' j k l
; (i = i1) → fiber←[q₀₀=q₀₁]-filler q₀₁ q₁₁ r p l k j
; (j = i0) → push q₀₁ (k ∨ ~ l)
; (j = i1) → p' l k
; (k = i0) → push q₀₁ (~ l)
; (k = i1) → push q₁₁ (~ j ∨ l) })
(inS (push q₁₁ (~ j ∨ ~ k))) l'
fiber←→[q₀₀=q₀₁] : fiber→[q₁₁=q₁₀] q₁₁ q₀₁ r (fiber←[q₀₀=q₀₁] q₀₁ q₁₁ r p .snd) .snd ≡ p
fiber←→[q₀₀=q₀₁] i j k = fiber←→[q₀₀=q₀₁]-filler i j k i1
{- q₀₀ = q₀₁ = q₁₁ -}
fiber←→hypercube :
(r : inl x₀ ≡ inr y₁)
→ (p : push q₀₁ ≡ r)
→ PathP (λ i → fiber→[q₀₀=q₁₀=q₁₁] q₀₁ i r (fiber←[q₀₀=q₀₁=q₁₁] q₀₁ i r p .snd) .snd ≡ p)
(fiber←→[q₁₁=q₀₁] q₀₁ r p) (fiber←→[q₀₀=q₀₁] q₀₁ r p)
fiber←→hypercube r p i j u v =
hcomp (λ l → λ { (i = i0) → fiber←→[q₁₁=q₀₁]-filler q₀₁ r p j u v l
; (i = i1) → fiber←→[q₀₀=q₀₁]-filler q₀₁ r p j u v l
; (j = i0) → fiber→[q₀₀=q₁₀=q₁₁]-filler q₀₁ r (fiber←[q₀₀=q₀₁=q₁₁] q₀₁ i r p .snd) i u v l
; (j = i1) → fiber←[q₀₀=q₀₁=q₁₁]-filler q₀₁ r p i l v u
; (u = i0) → push q₀₁ ((i ∨ (v ∧ l)) ∧ (v ∨ (i ∧ ~ l)))
; (u = i1) → fiber←[q₀₀=q₀₁=q₁₁] q₀₁ i r p .snd l v
; (v = i0) → push q₀₁ ((i ∨ u) ∧ ~ l)
; (v = i1) → push q₀₁ ((i ∧ ~ u) ∨ l) })
(push q₀₁ ((i ∨ (~ v ∧ u)) ∧ (~ v ∨ (i ∧ ~ u))))
module Fiber→
{x₁ : X}{y₀ : Y}(q₁₀ : Q x₁ y₀) =
WedgeConnectivity m n
(leftFiber x₁ , (y₀ , q₁₀)) (leftConn x₁)
(rightFiber y₀ , (x₁ , q₁₀)) (rightConn y₀)
(λ (y₁ , q₁₁) (x₀ , q₀₀) →
(((r : inl x₀ ≡ inr y₁) → fiberSquarePush q₀₀ q₁₀ q₁₁ r → rightCode _ r)
, isOfHLevelΠ2 _ (λ x y → isOfHLevelTrunc _)))
(λ (y₁ , q₁₁) → ∣fiber→[q₀₀=q₁₀]∣ q₁₀ q₁₁)
(λ (x₀ , q₀₀) → ∣fiber→[q₁₁=q₁₀]∣ q₁₀ q₀₀)
(∣fiber→[q₀₀=q₁₀=q₁₁]∣ q₁₀)
fiber→ :
{x₁ : X}{y₀ : Y}(q₁₀ : Q x₁ y₀)
→ {x₀ : X}(q₀₀ : Q x₀ y₀) → {y₁ : Y}(q₁₁ : Q x₁ y₁)
→ (r : inl x₀ ≡ inr y₁)
→ fiberSquarePush q₀₀ q₁₀ q₁₁ r → rightCode _ r
fiber→ q₁₀ q₀₀ q₁₁ = Fiber→.extension q₁₀ (_ , q₁₁) (_ , q₀₀)
module Fiber←
{x₀ : X}{y₁ : Y}(q₀₁ : Q x₀ y₁) =
WedgeConnectivity m n
(leftFiber x₀ , (y₁ , q₀₁)) (leftConn x₀)
(rightFiber y₁ , (x₀ , q₀₁)) (rightConn y₁)
(λ (y₀ , q₀₀) (x₁ , q₁₁) →
(((r : inl x₀ ≡ inr y₁) → push q₀₁ ≡ r → leftCodeExtended q₀₀ _ (push q₁₁) r)
, isOfHLevelΠ2 _ (λ x y → isOfHLevelTrunc _)))
(λ (y₀ , q₀₀) → ∣fiber←[q₁₁=q₀₁]∣ q₀₁ q₀₀)
(λ (x₁ , q₁₁) → ∣fiber←[q₀₀=q₀₁]∣ q₀₁ q₁₁)
(∣fiber←[q₀₀=q₀₁=q₁₁]∣ q₀₁)
fiber← :
{x₀ : X}{y₁ : Y}(q₀₁ : Q x₀ y₁)
→ {y₀ : Y}(q₀₀ : Q x₀ y₀) → {x₁ : X}(q₁₁ : Q x₁ y₁)
→ (r : inl x₀ ≡ inr y₁)
→ push q₀₁ ≡ r → leftCodeExtended q₀₀ _ (push q₁₁) r
fiber← q₀₁ q₀₀ q₁₁ = Fiber←.extension q₀₁ (_ , q₀₀) (_ , q₁₁)
module _
{x₀ x₁ : X}{y₀ y₁ : Y}
(q₀₀ : Q x₀ y₀)(q₁₁ : Q x₁ y₁)
(r : inl x₀ ≡ inr y₁) where
left→rightCodeExtended : leftCodeExtended q₀₀ _ (push q₁₁) r → rightCode _ r
left→rightCodeExtended =
rec (isOfHLevelTrunc _) (λ (q₁₀ , p) → fiber→ q₁₀ q₀₀ q₁₁ r p)
right→leftCodeExtended : rightCode _ r → leftCodeExtended q₀₀ _ (push q₁₁) r
right→leftCodeExtended =
rec (isOfHLevelTrunc _) (λ (q₀₁ , p) → fiber← q₀₁ q₀₀ q₁₁ r p)
{- Definition of one-side homotopy -}
module _
{x₁ : X}{y₀ : Y}(q₁₀ : Q x₁ y₀) where
{- (x₀ , q₀₀) = (x₁ , q₁₀) -}
module _
{y₁ : Y}(q₁₁ : Q x₁ y₁)
(r : inl x₁ ≡ inr y₁)
(p : fiberSquarePush q₁₀ q₁₀ q₁₁ r) where
∣fiber→←[q₀₀=q₁₀]∣ : right→leftCodeExtended q₁₀ q₁₁ r (fiber→ q₁₀ q₁₀ q₁₁ r p) ≡ ∣ q₁₀ , p ∣ₕ
∣fiber→←[q₀₀=q₁₀]∣ =
(λ i → right→leftCodeExtended q₁₀ q₁₁ r (Fiber→.left q₁₀ (_ , q₁₁) i r p))
∙ recUniq {n = m + n} _ _ _
∙ (λ i → Fiber←.left q₁₁ (_ , q₁₀) i r (fiber→[q₀₀=q₁₀] q₁₀ q₁₁ r p .snd))
∙ (λ i → ∣ q₁₀ , fiber→←[q₀₀=q₁₀] q₁₀ q₁₁ r p i ∣ₕ)
{- (y₁ , q₁₁) = (y₀ , q₁₀) -}
module _
{x₀ : X}(q₀₀ : Q x₀ y₀)
(r : inl x₀ ≡ inr y₀)
(p : fiberSquarePush q₀₀ q₁₀ q₁₀ r) where
∣fiber→←[q₁₁=q₁₀]∣ : right→leftCodeExtended q₀₀ q₁₀ r (fiber→ q₁₀ q₀₀ q₁₀ r p) ≡ ∣ q₁₀ , p ∣ₕ
∣fiber→←[q₁₁=q₁₀]∣ =
(λ i → right→leftCodeExtended q₀₀ q₁₀ r (Fiber→.right q₁₀ (_ , q₀₀) i r p))
∙ recUniq {n = m + n} _ _ _
∙ (λ i → Fiber←.right q₀₀ (_ , q₁₀) i r (fiber→[q₁₁=q₁₀] q₁₀ q₀₀ r p .snd))
∙ (λ i → ∣ q₁₀ , fiber→←[q₁₁=q₁₀] q₁₀ q₀₀ r p i ∣ₕ)
{- q₀₀ = q₁₁ = q₁₀ -}
module _
(r : inl x₁ ≡ inr y₀)
(p : fiberSquarePush q₁₀ q₁₀ q₁₀ r) where
path→←Square =
(λ i j → right→leftCodeExtended q₁₀ q₁₀ r (Fiber→.homSquare q₁₀ i j r p))
∙₂ (λ i → recUniq {n = m + n} _ _ _)
∙₂ (λ i j → Fiber←.homSquare q₁₀ i j r (fiber→[q₀₀=q₁₀=q₁₁] q₁₀ i r p .snd))
∙₂ (λ i j → ∣ (q₁₀ , fiber→←hypercube q₁₀ r p i j) ∣ₕ)
∣fiber→←[q₀₀=q₁₀=q₁₁]∣ : ∣fiber→←[q₀₀=q₁₀]∣ q₁₀ ≡ ∣fiber→←[q₁₁=q₁₀]∣ q₁₀
∣fiber→←[q₀₀=q₁₀=q₁₁]∣ i r p = path→←Square r p i
fiber→← :
{x₁ : X}{y₀ : Y}(q₁₀ : Q x₁ y₀)
→ {x₀ : X}(q₀₀ : Q x₀ y₀) → {y₁ : Y}(q₁₁ : Q x₁ y₁)
→ (r : inl x₀ ≡ inr y₁)
→ (p : fiberSquarePush q₀₀ q₁₀ q₁₁ r)
→ right→leftCodeExtended q₀₀ q₁₁ r (fiber→ q₁₀ q₀₀ q₁₁ r p) ≡ ∣ q₁₀ , p ∣ₕ
fiber→← {x₁ = x₁} {y₀ = y₀} q₁₀ q₀₀' q₁₁' =
WedgeConnectivity.extension m n
(leftFiber x₁ , (y₀ , q₁₀)) (leftConn x₁)
(rightFiber y₀ , (x₁ , q₁₀)) (rightConn y₀)
(λ (y₁ , q₁₁) (x₀ , q₀₀) →
(( (r : inl x₀ ≡ inr y₁) → (p : fiberSquarePush q₀₀ q₁₀ q₁₁ r)
→ right→leftCodeExtended q₀₀ q₁₁ r (fiber→ q₁₀ q₀₀ q₁₁ r p) ≡ ∣ q₁₀ , p ∣ₕ )
, isOfHLevelΠ2 _ (λ x y → isOfHLevelTruncPath)))
(λ (y₁ , q₁₁) → ∣fiber→←[q₀₀=q₁₀]∣ q₁₀ q₁₁)
(λ (x₀ , q₀₀) → ∣fiber→←[q₁₁=q₁₀]∣ q₁₀ q₀₀)
(∣fiber→←[q₀₀=q₁₀=q₁₁]∣ q₁₀)
(_ , q₁₁') (_ , q₀₀')
{- Definition of the other side homotopy -}
module _
{x₀ : X}{y₁ : Y}(q₀₁ : Q x₀ y₁) where
{- (x₁ , q₁₁) = (x₀ , q₀₁) -}
module _
{y₀ : Y}(q₀₀ : Q x₀ y₀)
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
∣fiber←→[q₁₁=q₀₁]∣ : left→rightCodeExtended q₀₀ q₀₁ r (fiber← q₀₁ q₀₀ q₀₁ r p) ≡ ∣ q₀₁ , p ∣ₕ
∣fiber←→[q₁₁=q₀₁]∣ =
(λ i → left→rightCodeExtended q₀₀ q₀₁ r (Fiber←.left q₀₁ (_ , q₀₀) i r p))
∙ recUniq {n = m + n} _ _ _
∙ (λ i → Fiber→.left q₀₀ (_ , q₀₁) i r (fiber←[q₁₁=q₀₁] q₀₁ q₀₀ r p .snd))
∙ (λ i → ∣ q₀₁ , fiber←→[q₁₁=q₀₁] q₀₁ q₀₀ r p i ∣ₕ)
{- (y₀ , q₀₀) = (y₁ , q₀₁) -}
module _
{x₁ : X}(q₁₁ : Q x₁ y₁)
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
∣fiber←→[q₀₀=q₀₁]∣ : left→rightCodeExtended q₀₁ q₁₁ r (fiber← q₀₁ q₀₁ q₁₁ r p) ≡ ∣ q₀₁ , p ∣ₕ
∣fiber←→[q₀₀=q₀₁]∣ =
(λ i → left→rightCodeExtended q₀₁ q₁₁ r (Fiber←.right q₀₁ (_ , q₁₁) i r p))
∙ recUniq {n = m + n} _ _ _
∙ (λ i → Fiber→.right q₁₁ (_ , q₀₁) i r (fiber←[q₀₀=q₀₁] q₀₁ q₁₁ r p .snd))
∙ (λ i → ∣ q₀₁ , fiber←→[q₀₀=q₀₁] q₀₁ q₁₁ r p i ∣ₕ)
{- q₀₀ = q₀₁ = q₁₁ -}
module _
(r : inl x₀ ≡ inr y₁)
(p : push q₀₁ ≡ r) where
path←→Square =
(λ i j → left→rightCodeExtended q₀₁ q₀₁ r (Fiber←.homSquare q₀₁ i j r p))
∙₂ (λ i → recUniq {n = m + n} _ _ _)
∙₂ (λ i j → Fiber→.homSquare q₀₁ i j r (fiber←[q₀₀=q₀₁=q₁₁] q₀₁ i r p .snd))
∙₂ (λ i j → ∣ q₀₁ , fiber←→hypercube q₀₁ r p i j ∣ₕ)
∣fiber←→[q₀₀=q₀₁=q₁₁]∣ : ∣fiber←→[q₁₁=q₀₁]∣ q₀₁ ≡ ∣fiber←→[q₀₀=q₀₁]∣ q₀₁
∣fiber←→[q₀₀=q₀₁=q₁₁]∣ i r p = path←→Square r p i
fiber←→ :
{x₀ : X}{y₁ : Y}(q₀₁ : Q x₀ y₁)
→ {y₀ : Y}(q₀₀ : Q x₀ y₀) → {x₁ : X}(q₁₁ : Q x₁ y₁)
→ (r : inl x₀ ≡ inr y₁)
→ (p : push q₀₁ ≡ r)
→ left→rightCodeExtended q₀₀ q₁₁ r (fiber← q₀₁ q₀₀ q₁₁ r p) ≡ ∣ q₀₁ , p ∣ₕ
fiber←→ {x₀ = x₀} {y₁ = y₁} q₀₁ q₀₀' q₁₁' =
WedgeConnectivity.extension m n
(leftFiber x₀ , (y₁ , q₀₁)) (leftConn x₀)
(rightFiber y₁ , (x₀ , q₀₁)) (rightConn y₁)
(λ (y₀ , q₀₀) (x₁ , q₁₁) →
(( (r : inl x₀ ≡ inr y₁) → (p : push q₀₁ ≡ r)
→ left→rightCodeExtended q₀₀ q₁₁ r (fiber← q₀₁ q₀₀ q₁₁ r p) ≡ ∣ q₀₁ , p ∣ₕ )
, isOfHLevelΠ2 _ (λ x y → isOfHLevelTruncPath)))
(λ (y₀ , q₀₀) → ∣fiber←→[q₁₁=q₀₁]∣ q₀₁ q₀₀)
(λ (x₁ , q₁₁) → ∣fiber←→[q₀₀=q₀₁]∣ q₀₁ q₁₁)
(∣fiber←→[q₀₀=q₀₁=q₁₁]∣ q₀₁)
(_ , q₀₀') (_ , q₁₁')
module _
{x₀ x₁ : X}{y₀ y₁ : Y}
(q₀₀ : Q x₀ y₀)(q₁₁ : Q x₁ y₁)
(r : inl x₀ ≡ inr y₁) where
left→right→leftCodeExtended :
(a : leftCodeExtended q₀₀ _ (push q₁₁) r)
→ right→leftCodeExtended q₀₀ q₁₁ r (left→rightCodeExtended q₀₀ q₁₁ r a) ≡ a
left→right→leftCodeExtended a =
sym (∘rec _ _ _ (right→leftCodeExtended q₀₀ q₁₁ r) a) ∙
(λ i → recId _ (λ (q₁₀ , p) → fiber→← q₁₀ q₀₀ q₁₁ r p) i a)
right→left→rightCodeExtended :
(a : rightCode _ r)
→ left→rightCodeExtended q₀₀ q₁₁ r (right→leftCodeExtended q₀₀ q₁₁ r a) ≡ a
right→left→rightCodeExtended a =
sym (∘rec _ _ _ (left→rightCodeExtended q₀₀ q₁₁ r) a) ∙
(λ i → recId _ (λ (q₀₁ , p) → fiber←→ q₀₁ q₀₀ q₁₁ r p) i a)
left≃rightCodeExtended : leftCodeExtended q₀₀ _ (push q₁₁) r ≃ rightCode y₁ r
left≃rightCodeExtended =
isoToEquiv (iso (left→rightCodeExtended _ _ _) (right→leftCodeExtended _ _ _)
right→left→rightCodeExtended left→right→leftCodeExtended)
{- Definition and properties of Code -}
module _ (x₀ : X)(y₀ : Y)(q₀₀ : Q x₀ y₀) where
leftCode' : (x : X){p : Pushout} → inl x ≡ p → inl x₀ ≡ p → Type ℓ
leftCode' x r' = leftCodeExtended q₀₀ x r'
leftCode : (x : X) → inl x₀ ≡ inl x → Type ℓ
leftCode x = leftCode' x refl
fiberPath : {x : X}{y : Y} → (q : Q x y) → leftCode' x (push q) ≡ rightCode y
fiberPath q i r = ua (left≃rightCodeExtended q₀₀ q r) i
pushCode :
{x : X}{y : Y} → (q : Q x y)
→ PathP (λ i → inl x₀ ≡ push q i → Type ℓ) (leftCode x) (rightCode y)
pushCode q i =
hcomp (λ j → λ { (i = i0) → leftCode _
; (i = i1) → fiberPath q j })
(leftCode' _ (λ j → push q (i ∧ j)))
Code : (p : Pushout) → inl x₀ ≡ p → Type ℓ
Code (inl x) = leftCode x
Code (inr y) = rightCode y
Code (push q i) = pushCode q i
{- Transportation rule of pushCode -}
transpLeftCode : (y : Y) → (q : Q x₀ y) → (q' : leftCodeExtended q₀₀ _ refl refl) → leftCode' _ (push q) (push q)
transpLeftCode y q q' =
transport (λ i → leftCode' _ (λ j → push q (i ∧ j)) (λ j → push q (i ∧ j))) q'
transpPushCodeβ' :
(y : Y) → (q : Q x₀ y) → (q' : leftCodeExtended q₀₀ _ refl refl)
→ transport (λ i → pushCode q i (λ j → push q (i ∧ j))) q' ≡ left→rightCodeExtended _ _ _ (transpLeftCode y q q')
transpPushCodeβ' y q q' i = transportRefl (left→rightCodeExtended _ _ _ (transpLeftCode y q (transportRefl q' i))) i
module _
{p : Pushout}(r : inl x₀ ≡ p) where
fiber-filler : I → Type ℓ
fiber-filler i = fiber' q₀₀ (λ j → r (i ∧ j)) (λ j → r (i ∧ j))
module _
(q : fiberSquare q₀₀ q₀₀ refl refl) where
transpLeftCode-filler : (i j k : I) → Pushout
transpLeftCode-filler i j k' =
hfill (λ k → λ { (i = i0) → push q₀₀ (~ j)
; (i = i1) → r (j ∧ k)
; (j = i0) → push q₀₀ (~ i)
; (j = i1) → r (i ∧ k) })
(inS (q i j)) k'
transpLeftCodeβ' :
{p : Pushout} → (r : inl x₀ ≡ p) → (q : fiberSquare q₀₀ q₀₀ refl refl)
→ transport (λ i → fiber-filler r i) (q₀₀ , q) ≡ (q₀₀ , λ i j → transpLeftCode-filler r q i j i1)
transpLeftCodeβ' r q =
J (λ p r → transport (λ i → fiber-filler r i) (q₀₀ , q) ≡ (q₀₀ , λ i j → transpLeftCode-filler r q i j i1))
(transportRefl _ ∙ (λ k → (q₀₀ , λ i j → transpLeftCode-filler refl q i j k))) r
transpLeftCodeβ :
(y : Y) → (q : Q x₀ y) → (q' : fiberSquare q₀₀ q₀₀ refl refl)
→ transpLeftCode y q ∣ q₀₀ , q' ∣ₕ ≡ ∣ q₀₀ , (λ i j → transpLeftCode-filler (push q) q' i j i1) ∣ₕ
transpLeftCodeβ y q q' = transportTrunc _ ∙ (λ i → ∣ transpLeftCodeβ' _ q' i ∣ₕ)
transpPushCodeβ :
(y : Y) → (q : Q x₀ y) → (q' : fiberSquare q₀₀ q₀₀ refl refl)
→ transport (λ i → pushCode q i (λ j → push q (i ∧ j))) ∣ q₀₀ , q' ∣ₕ
≡ ∣fiber→[q₀₀=q₁₀]∣ q₀₀ q (push q) (λ i j → transpLeftCode-filler (push q) q' i j i1)
transpPushCodeβ y q q' =
transpPushCodeβ' _ _ _
∙ (λ i → left→rightCodeExtended _ _ _ (transpLeftCodeβ _ _ q' i))
∙ recUniq {n = m + n} _ _ _
∙ (λ i' → Fiber→.left q₀₀ (_ , q) i' (push q) (λ i j → transpLeftCode-filler (push q) q' i j i1))
{- The contractibility of Code -}
centerCode : {p : Pushout} → (r : inl x₀ ≡ p) → Code p r
centerCode r =
transport (λ i → Code _ (λ j → r (i ∧ j))) ∣ q₀₀ , (λ i j → push q₀₀ (~ i ∧ ~ j)) ∣ₕ
module _
(y : Y)(q : Q x₀ y) where
transp-filler : (i j k : I) → Pushout
transp-filler = transpLeftCode-filler (push q) (λ i' j' → push q₀₀ (~ i' ∧ ~ j'))
transp-square : fiberSquare q₀₀ q₀₀ (push q) (push q)
transp-square i j = transp-filler i j i1
contractionCodeRefl' :
fiber→[q₀₀=q₁₀] q₀₀ q (push q) transp-square .snd ≡ refl
contractionCodeRefl' i j k =
hcomp (λ l → λ { (i = i0) → fiber→[q₀₀=q₁₀]-filler q₀₀ q (push q) transp-square j k l
; (i = i1) → transp-square (~ j ∨ l) k
; (j = i0) → push q (k ∧ (i ∨ l))
; (j = i1) → transp-square l k
; (k = i0) → push q₀₀ (j ∧ ~ l)
; (k = i1) → push q ((i ∧ ~ j) ∨ l) })
(transp-filler (~ j) k i)
contractionCodeRefl : centerCode (push q) ≡ ∣ q , refl ∣ₕ
contractionCodeRefl = transpPushCodeβ _ _ _ ∙ (λ i → ∣ q , contractionCodeRefl' i ∣ₕ)
module _
(y : Y)(r : inl x₀ ≡ inr y) where
contractionCode' : (a : fiber push r) → centerCode r ≡ ∣ a ∣ₕ
contractionCode' (q , p') = J (λ r' p → centerCode r' ≡ ∣ q , p ∣ₕ) (contractionCodeRefl _ q) p'
contractionCode : (a : Code _ r) → centerCode r ≡ a
contractionCode = elim (λ _ → isOfHLevelTruncPath) contractionCode'
isContrCode : isContr (Code _ r)
isContrCode = centerCode r , contractionCode
excision-helper :
(x : X) → Trunc (1 + m) (Σ[ y₀ ∈ Y ] Q x y₀)
→ (y : Y) → (r : inl x ≡ inr y) → isContr (Trunc (m + n) (fiber push r))
excision-helper x y' y r = rec (isProp→isOfHLevelSuc m isPropIsContr) (λ (y₀ , q₀₀) → isContrCode x y₀ q₀₀ y r ) y'
{- The Main Result : Blakers-Massey Homotopy Excision Theorem -}
Excision : (x : X)(y : Y) → isConnectedFun (m + n) (push {x = x} {y = y})
Excision x y = excision-helper x (leftConn x .fst) y
| {
"alphanum_fraction": 0.4954250787,
"avg_line_length": 39.9925925926,
"ext": "agda",
"hexsha": "77ddeacd11e4d6ba19c70dddd50398ba28bf4d4a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ecavallo/cubical",
"max_forks_repo_path": "Cubical/Homotopy/BlakersMassey.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ecavallo/cubical",
"max_issues_repo_path": "Cubical/Homotopy/BlakersMassey.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ecavallo/cubical",
"max_stars_repo_path": "Cubical/Homotopy/BlakersMassey.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 12296,
"size": 26995
} |
{-# OPTIONS --rewriting #-}
open import Agda.Primitive
postulate
_↦_ : ∀{i j}{A : Set i}{B : Set j} → A → B → Set (i ⊔ j)
{-# BUILTIN REWRITE _↦_ #-} -- currently fails a sanity check
postulate
resize : ∀{i j} → Set i → Set j
resize-id : ∀{i} {j} {A : Set i} → resize {i} {j} A ↦ A
{-# REWRITE resize-id #-}
-- Impredicative quantification
Forall : ∀{i} (F : Set i → Set) → Set
Forall {i} F = resize ((X : Set i) → F X)
-- Example: Impredicative encoding of natural numbers
Nat = Forall λ X → (X → X) → X → X
zero : Nat
zero X s z = z
suc : Nat → Nat
suc n X s z = s (n X s z)
-- requires impredicativity:
id : Nat → Nat
id n = n Nat suc zero
| {
"alphanum_fraction": 0.5761689291,
"avg_line_length": 18.9428571429,
"ext": "agda",
"hexsha": "22648cd63d1de3a6957823f9a4b8efdd055c4ba8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/HeterogeneousRewriting.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/HeterogeneousRewriting.agda",
"max_line_length": 62,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/HeterogeneousRewriting.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 248,
"size": 663
} |
module Data.Num.Increment where
open import Data.Num.Core
open import Data.Num.Bounded
open import Data.Num.Maximum
open import Data.Num.Next
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Fin as Fin
using (Fin; fromℕ≤; inject≤)
renaming (zero to z; suc to s)
open import Data.Fin.Properties using (toℕ-fromℕ≤; bounded)
open import Data.Product
open import Function
open import Relation.Nullary.Decidable
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
------------------------------------------------------------------------
-- a number is incrementable if there exists some n' : Numeral b d o such that ⟦ n' ⟧ℕ ≡ suc ⟦ n ⟧ℕ
Incrementable : ∀ {b d o} → (xs : Numeral b d o) → Set
Incrementable {b} {d} {o} xs = Σ[ xs' ∈ Numeral b d o ] ⟦ xs' ⟧ ≡ suc ⟦ xs ⟧
m≡1+n⇒m>n : ∀ {m n} → m ≡ suc n → m > n
m≡1+n⇒m>n {zero} {n} ()
m≡1+n⇒m>n {suc m} {.m} refl = s≤s ≤-refl
Maximum⇒¬Incrementable : ∀ {b d o}
→ (xs : Numeral b d o)
→ (max : Maximum xs)
→ ¬ (Incrementable xs)
Maximum⇒¬Incrementable xs max (evidence , claim)
= contradiction (max evidence) (>⇒≰ (m≡1+n⇒m>n claim))
Interval⇒Incrementable : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (¬greatest : ¬ (Greatest (lsd xs)))
→ (proper : 2 ≤ suc (d + o))
→ Incrementable xs
Interval⇒Incrementable {b} {d} {o} xs ¬greatest proper
= (next-numeral-Proper xs proper) , (begin
⟦ next-numeral-Proper xs proper ⟧
≡⟨ cong ⟦_⟧ (next-numeral-Proper-refine xs proper (Interval b d o ¬greatest)) ⟩
⟦ next-numeral-Proper-Interval xs ¬greatest proper ⟧
≡⟨ next-numeral-Proper-Interval-lemma xs ¬greatest proper ⟩
suc ⟦ xs ⟧
∎)
GappedEndpoint⇒¬Incrementable : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (greatest : Greatest (lsd xs))
→ (proper : 2 ≤ suc (d + o))
→ (gapped : Gapped xs proper)
→ ¬ (Incrementable xs)
GappedEndpoint⇒¬Incrementable {b} {d} {o} xs greatest proper gapped (incremented , claim)
= contradiction ⟦next⟧>⟦incremented⟧ ⟦next⟧≯⟦incremented⟧
where
next : Numeral (suc b) (suc d) o
next = next-numeral-Proper xs proper
⟦next⟧>⟦incremented⟧ : ⟦ next ⟧ > ⟦ incremented ⟧
⟦next⟧>⟦incremented⟧ =
start
suc ⟦ incremented ⟧
≈⟨ cong suc claim ⟩
suc (suc ⟦ xs ⟧)
≤⟨ next-numeral-Proper-GappedEndpoint-lemma xs greatest proper gapped ⟩
⟦ next-numeral-Proper-GappedEndpoint xs proper gapped ⟧
≈⟨ cong ⟦_⟧ (sym (next-numeral-Proper-refine xs proper (GappedEndpoint b d o greatest gapped))) ⟩
⟦ next-numeral-Proper xs proper ⟧
□
⟦next⟧≯⟦incremented⟧ : ⟦ next ⟧ ≯ ⟦ incremented ⟧
⟦next⟧≯⟦incremented⟧ = ≤⇒≯ $ next-numeral-is-immediate-Proper xs incremented proper (m≡1+n⇒m>n claim)
UngappedEndpoint⇒Incrementable : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (greatest : Greatest (lsd xs))
→ (proper : 2 ≤ suc (d + o))
→ (¬gapped : ¬ (Gapped xs proper))
→ Incrementable xs
UngappedEndpoint⇒Incrementable {b} {d} {o} xs greatest proper ¬gapped
= (next-numeral-Proper xs proper) , (begin
⟦ next-numeral-Proper xs proper ⟧
≡⟨ cong ⟦_⟧ (next-numeral-Proper-refine xs proper (UngappedEndpoint b d o greatest ¬gapped)) ⟩
⟦ next-numeral-Proper-UngappedEndpoint xs greatest proper ¬gapped ⟧
≡⟨ next-numeral-Proper-UngappedEndpoint-lemma xs greatest proper ¬gapped ⟩
suc ⟦ xs ⟧
∎)
¬Gapped⇒Incrementable : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (proper : 2 ≤ suc (d + o))
→ (¬gapped : ¬ (Gapped xs proper))
→ Incrementable xs
¬Gapped⇒Incrementable xs proper ¬gapped with nextView xs proper
¬Gapped⇒Incrementable xs proper ¬gapped | Interval b d o ¬greatest
= Interval⇒Incrementable xs ¬greatest proper
¬Gapped⇒Incrementable xs proper ¬gapped | GappedEndpoint b d o greatest gapped
= contradiction gapped ¬gapped
¬Gapped⇒Incrementable xs proper ¬gapped | UngappedEndpoint b d o greatest _
= UngappedEndpoint⇒Incrementable xs greatest proper ¬gapped
Incrementable?-Proper : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (proper : 2 ≤ suc (d + o))
→ Dec (Incrementable xs)
Incrementable?-Proper xs proper with nextView xs proper
Incrementable?-Proper xs proper | Interval b d o ¬greatest
= yes (Interval⇒Incrementable xs ¬greatest proper)
Incrementable?-Proper xs proper | GappedEndpoint b d o greatest gapped
= no (GappedEndpoint⇒¬Incrementable xs greatest proper gapped)
Incrementable?-Proper xs proper | UngappedEndpoint b d o greatest ¬gapped
= yes (UngappedEndpoint⇒Incrementable xs greatest proper ¬gapped)
Incrementable? : ∀ {b d o}
→ (xs : Numeral b d o)
→ Dec (Incrementable xs)
Incrementable? xs with Maximum? xs
Incrementable? xs | yes max = no (Maximum⇒¬Incrementable xs max)
Incrementable? {b} {d} {o} xs | no ¬max with numView b d o
Incrementable? xs | no ¬max | NullBase d o
= yes ((next-numeral-NullBase xs ¬max) , (next-numeral-NullBase-lemma xs ¬max))
Incrementable? xs | no ¬max | NoDigits b o
= yes (NoDigits-explode xs)
Incrementable? xs | no ¬max | AllZeros b
= no (contradiction (Maximum-AllZeros xs) ¬max)
Incrementable? xs | no ¬max | Proper b d o proper
= Incrementable?-Proper xs proper
increment : ∀ {b d o}
→ (xs : Numeral b d o)
→ (incr : True (Incrementable? xs))
→ Numeral b d o
increment xs incr = proj₁ $ toWitness incr
increment-next-numeral-Proper : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (proper : 2 ≤ suc (d + o))
→ (incr : True (Incrementable?-Proper xs proper))
→ proj₁ (toWitness incr) ≡ next-numeral-Proper xs proper
increment-next-numeral-Proper xs proper incr with nextView xs proper
increment-next-numeral-Proper xs proper incr | Interval b d o ¬greatest = begin
next-numeral-Proper xs proper
≡⟨ next-numeral-Proper-refine xs proper (Interval b d o ¬greatest) ⟩
next-numeral-Proper-Interval xs ¬greatest proper
∎
increment-next-numeral-Proper xs proper () | GappedEndpoint b d o greatest gapped
increment-next-numeral-Proper xs proper incr | UngappedEndpoint b d o greatest ¬gapped = begin
next-numeral-Proper xs proper
≡⟨ next-numeral-Proper-refine xs proper (UngappedEndpoint b d o greatest ¬gapped) ⟩
next-numeral-Proper-UngappedEndpoint xs greatest proper ¬gapped
∎
increment-next-numeral : ∀ {b d o}
→ (xs : Numeral b d o)
→ (¬max : ¬ (Maximum xs))
→ (incr : True (Incrementable? xs))
→ increment xs incr ≡ next-numeral xs ¬max
increment-next-numeral xs ¬max incr with Maximum? xs
increment-next-numeral xs ¬max () | yes max
increment-next-numeral {b} {d} {o} xs ¬max incr | no _ with numView b d o
increment-next-numeral xs _ incr | no ¬max | NullBase d o = refl
increment-next-numeral xs _ incr | no ¬max | NoDigits b o = NoDigits-explode xs
increment-next-numeral xs _ () | no ¬max | AllZeros b
increment-next-numeral xs _ incr | no ¬max | Proper b d o proper
= increment-next-numeral-Proper xs proper incr
| {
"alphanum_fraction": 0.6502008032,
"avg_line_length": 40.597826087,
"ext": "agda",
"hexsha": "b2e1efd2a00d1d5851e318e72cbae145f0048fbe",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Increment.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Increment.agda",
"max_line_length": 109,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Increment.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 2427,
"size": 7470
} |
module Haskell.RangedSets.RangedSet where
open import Agda.Builtin.Equality
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.Num
open import Haskell.Prim.Eq
open import Haskell.Prim.Foldable
open import Haskell.Prim.Monoid
open import Haskell.Prim.Int
open import Haskell.Prim.List
open import Haskell.Prim.Integer
open import Haskell.Prim.Real
open import Haskell.RangedSets.Boundaries
open import Haskell.RangedSets.Ranges
open import Haskell.RangedSetsProp.library
open import Haskell.RangedSetsProp.BoundariesProperties
{-# FOREIGN AGDA2HS
import Haskell.RangedSets.Boundaries
#-}
{-# FOREIGN AGDA2HS
import Haskell.RangedSets.Ranges
#-}
{-# FOREIGN AGDA2HS
import Data.List
#-}
infixl 7 _-/\-_
infixl 6 _-\/-_ _-!-_
infixl 5 _-<=-_ _-<-_ _-?-_
okAdjacent : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → Bool
okAdjacent r@(Rg lower1 upper1) r2@(Rg lower2 upper2) = rangeLower r <= rangeUpper r && rangeUpper r <= rangeLower r2 && rangeLower r2 <= rangeUpper r2
{-# COMPILE AGDA2HS okAdjacent #-}
validRangeList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → Bool
validRangeList [] = true
validRangeList (x ∷ []) = (rangeLower x) <= (rangeUpper x)
validRangeList (x ∷ rs@(r1 ∷ rss)) = (okAdjacent x r1) && (validRangeList rs)
{-# COMPILE AGDA2HS validRangeList #-}
validBoundaryList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Boundary a) → Bool
validBoundaryList [] = true
validBoundaryList (x ∷ []) = true
validBoundaryList (x ∷ rs@(r1 ∷ rss)) = (x <= r1) && (validBoundaryList rs)
data RSet (a : Set) ⦃ o : Ord a ⦄ ⦃ dio : DiscreteOrdered a ⦄ : Set where
RS : (rg : List (Range a)) → {IsTrue (validRangeList rg)} → RSet a
{-# COMPILE AGDA2HS RSet #-}
rSetRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → RSet a → List (Range a)
rSetRanges (RS ranges) = ranges
{-# COMPILE AGDA2HS rSetRanges #-}
overlap1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → Bool
overlap1 (Rg _ upper1) (Rg lower2 _) = (upper1 >= lower2)
{-# COMPILE AGDA2HS overlap1 #-}
sortedRangeList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → Bool
sortedRangeList [] = true
sortedRangeList (r ∷ []) = true
sortedRangeList (r1 ∷ r2 ∷ rs) = (r1 <= r2) && (sortedRangeList (r2 ∷ rs))
validRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → Bool
validRanges [] = true
validRanges (r ∷ rs) = (rangeLower r <= rangeUpper r) && (validRanges rs)
headandtailSorted : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a))
→ ⦃ ne : NonEmpty rs ⦄ → (IsTrue (sortedRangeList rs))
→ (IsTrue (sortedRangeList (tail rs ⦃ ne ⦄)))
headandtailValidRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a))
→ ⦃ ne : NonEmpty rs ⦄ → (IsTrue (validRanges rs))
→ (IsTrue (validRanges (tail rs ⦃ ne ⦄)))
normalise : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rg : List (Range a))
→ ⦃ IsTrue (sortedRangeList rg) ⦄
→ ⦃ IsTrue (validRanges rg) ⦄
→ List (Range a)
postulate
sortedList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a))
-> IsTrue (sortedRangeList (sort (filter (λ r → (rangeIsEmpty r) == false) rs)))
validRangesList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a))
-> IsTrue (validRanges (sort (filter (λ r → (rangeIsEmpty r) == false) rs)))
unsafeRangedSet : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rg : List (Range a))
→ ⦃ IsTrue (validRangeList ⦃ o ⦄ ⦃ dio ⦄ rg) ⦄ → RSet a
unsafeRangedSet rs ⦃ prf ⦄ = RS rs {prf}
{-# COMPILE AGDA2HS unsafeRangedSet #-}
validFunction2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a) → (f : Boundary a → Boundary a) → Bool
validFunction2 b f = (f b) > b
validFunction : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a) → (g : Boundary a → Maybe (Boundary a)) → Bool
validFunction b g with (g b)
... | Nothing = true
... | Just b2 = (b2 > b)
ranges3 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ →
Maybe (Boundary a) → (f : Boundary a → Boundary a) → (g : Boundary a → Maybe (Boundary a))
→ List (Range a)
{-# TERMINATING #-}
ranges2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (f : Boundary a → Boundary a) → (g : Boundary a → Maybe (Boundary a))
→ List (Range a)
ranges2 b upperFunc succFunc = (Rg b (upperFunc b)) ∷ (ranges3 (succFunc b) upperFunc succFunc)
ranges3 (Just b1) upperFunc succFunc = if ((validFunction2 b1 upperFunc) && (validFunction b1 succFunc)) then
(ranges2 b1 upperFunc succFunc) else []
ranges3 Nothing _ _ = []
{-# COMPILE AGDA2HS ranges2 #-}
{-# COMPILE AGDA2HS ranges3 #-}
setBounds1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (xs : List (Boundary a))
→ List (Boundary a)
setBounds1 (BoundaryBelowAll ∷ xs) = xs
setBounds1 xs = (BoundaryBelowAll ∷ xs)
{-# COMPILE AGDA2HS setBounds1 #-}
bounds1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ List (Range a) → List (Boundary a)
bounds1 (r ∷ rs) = (rangeLower r) ∷ (rangeUpper r) ∷ (bounds1 rs)
bounds1 [] = []
{-# COMPILE AGDA2HS bounds1 #-}
ranges1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Boundary a)
→ List (Range a)
ranges1 (b1 ∷ b2 ∷ bs) = (Rg b1 b2) ∷ (ranges1 bs)
ranges1 (BoundaryAboveAll ∷ []) = []
ranges1 (b ∷ []) = (Rg b BoundaryAboveAll) ∷ []
ranges1 _ = []
{-# COMPILE AGDA2HS ranges1 #-}
merge1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → List (Range a) → List (Range a)
merge1 [] [] = []
merge1 ms1@(h1 ∷ t1) [] = ms1
merge1 [] ms2@(h2 ∷ t2) = ms2
merge1 ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) = if_then_else_ (h1 < h2) (h1 ∷ (merge1 t1 ms2)) (h2 ∷ (merge1 ms1 t2))
{-# COMPILE AGDA2HS merge1 #-}
merge2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ List (Range a) → List (Range a) → List (Range a)
merge2 [] [] = []
merge2 ms1@(h1 ∷ t1) [] = []
merge2 [] ms2@(h2 ∷ t2) = []
merge2 ms1@(h1 ∷ t1) ms2@(h2 ∷ t2) =
(rangeIntersection h1 h2) ∷
(if_then_else_ (rangeUpper h1 < rangeUpper h2) (merge2 t1 ms2) (merge2 ms1 t2))
{-# COMPILE AGDA2HS merge2 #-}
postulate
sortedListComposed : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (r1 r2 : Range a) → (ranges : List (Range a))
→ IsTrue (sortedRangeList (r1 ∷ r2 ∷ ranges))
→ IsTrue (sortedRangeList ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ ranges))
validRangesComposed : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (r1 r2 : Range a) → (ranges : List (Range a))
→ IsTrue (sortedRangeList (r1 ∷ r2 ∷ ranges))
→ IsTrue (validRanges (r1 ∷ r2 ∷ ranges))
→ IsTrue (validRanges ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ ranges))
rangesLTEQ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b : Boundary a)
→ (f : Boundary a → Boundary a) → IsTrue (f b > b) → IsTrue (b <= f b)
stupid1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b b1 : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ IsTrue (validFunction2 b f) → IsTrue (validFunction b g)
→ (cond : Bool) -- this condition is (validFunction2 b1 f) && (validFunction b1 g)
→ IsTrue cond
→ IsTrue (validFunction2 b1 f)
stupid2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b b1 : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ IsTrue (validFunction2 b f) → IsTrue (validFunction b g)
→ (cond : Bool) -- this condition is (validFunction2 b1 f) && (validFunction b1 g)
→ IsTrue cond
→ IsTrue (validFunction b1 g)
-- used only when h <= h3
okSorted : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (h h3 : Range a)
→ sortedRangeList (h ∷ h3 ∷ []) ≡ true
-- holds only when upper h <= lower(head ms)
validList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (h : Range a) → (ms : List (Range a))
→ IsTrue (validRangeList ms)
→ validRangeList (h ∷ ms) ≡ true
validIsSorted : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (ms : List (Range a))
→ IsTrue (validRangeList ms) → IsTrue (sortedRangeList ms)
-- holds only when h < (head ms)
validSortedList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (h : Range a) → (ms : List (Range a))
→ IsTrue (sortedRangeList ms)
→ sortedRangeList (h ∷ ms) ≡ true
normalise (r1 ∷ r2 ∷ rs) ⦃ prf ⦄ ⦃ prf2 ⦄ =
if_then_else_ (overlap1 r1 r2)
(normalise ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs)
⦃ sortedListComposed r1 r2 rs prf ⦄ ⦃ validRangesComposed r1 r2 rs prf prf2 ⦄ )
(r1 ∷ (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄ ))
normalise rs = rs
{-# COMPILE AGDA2HS normalise #-}
-- some useful proofs
headandtail : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ ⦃ ne : NonEmpty (rSetRanges rs) ⦄ → (IsTrue (validRangeList (rSetRanges rs)))
→ (IsTrue (validRangeList (tail (rSetRanges rs) ⦃ ne ⦄)))
okAdjValid : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a)) → (r : Range a)
→ ⦃ ne : NonEmpty rs ⦄ → (IsTrue (validRangeList (r ∷ rs))) → IsTrue (okAdjacent r (head rs ⦃ ne ⦄))
headandtail2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a))
→ ⦃ ne : NonEmpty rs ⦄ → (IsTrue (validRangeList rs))
→ (IsTrue (validRangeList (tail rs ⦃ ne ⦄)))
tailandhead : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ ⦃ ne : NonEmpty (rSetRanges rs) ⦄ → (IsTrue (validRangeList (rSetRanges rs)))
→ (IsTrue (validRangeList ((head (rSetRanges rs) ⦃ ne ⦄) ∷ [])))
tailandhead2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : List (Range a))
→ ⦃ ne : NonEmpty rs ⦄ → (IsTrue (validRangeList rs))
→ (IsTrue (validRangeList ((head rs ⦃ ne ⦄) ∷ [])))
okAdjIsTrue : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r : Range a) → (r2 : Range a)
→ okAdjacent r r2 ≡ ((rangeLower r <= rangeUpper r) && (rangeUpper r <= rangeLower r2) && (rangeLower r2 <= rangeUpper r2))
normalisedSortedList0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (ms : List (Range a))
→ (prf : IsTrue (sortedRangeList ms))
→ (prf2 : IsTrue (validRanges ms))
→ validRangeList (normalise ms ⦃ prf ⦄ ⦃ prf2 ⦄) ≡ true
normalisedSortedList00 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs : List (Range a))
→ (r1 r2 : Range a) → (prf : IsTrue (sortedRangeList (r1 ∷ r2 ∷ rs))) → (prf2 : IsTrue (validRanges (r1 ∷ r2 ∷ rs)))
→ (b : Bool)
→ validRangeList (if_then_else_ b
(normalise ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs) ⦃ sortedListComposed r1 r2 rs prf ⦄ ⦃ validRangesComposed r1 r2 rs prf prf2 ⦄)
(r1 ∷ (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄))) ≡ true
normalisedSortedList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (ms : List (Range a))
→ (prf : IsTrue (sortedRangeList ms))
→ (prf2 : IsTrue (validRanges ms))
→ IsTrue (validRangeList (normalise ms ⦃ prf ⦄ ⦃ prf2 ⦄))
merge1HasValidRanges0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 rs2 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1)) → IsTrue (validRangeList (rSetRanges rs2))
→ (validRanges (merge1 (rSetRanges rs1) (rSetRanges rs2))) ≡ true
merge1HasValidRanges00 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 rs2 : RSet a) → (h1 h2 : Range a)
→ IsTrue (validRangeList (h1 ∷ (rSetRanges rs1))) → IsTrue (validRangeList (h2 ∷ (rSetRanges rs2)))
→ (b : Bool)
→ validRanges (if_then_else_ b
(h1 ∷ (merge1 (rSetRanges rs1) (h2 ∷ (rSetRanges rs2))))
(h2 ∷ (merge1 (h1 ∷ (rSetRanges rs1)) (rSetRanges rs2)))) ≡ true
validListMeansValidRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1))
→ (validRanges (rSetRanges rs1)) ≡ true
merge1HasValidRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 rs2 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1))
→ IsTrue (validRangeList (rSetRanges rs2))
→ IsTrue (validRanges (merge1 (rSetRanges rs1) (rSetRanges rs2)))
ranges2HasValidRanges0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ IsTrue (validFunction2 b f) → IsTrue (validFunction b g)
→ (validRanges (ranges2 b f g)) ≡ true
ranges2HasValidRanges00 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ (mb : Maybe (Boundary a))
→ IsTrue (validFunction2 b f) → IsTrue (validFunction b g)
→ (validRanges ((Rg b (f b)) ∷ (ranges3 mb f g))) ≡ true
ranges2HasValidRanges000 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b b1 : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ (cond : Bool)
→ IsTrue (validFunction2 b f) → IsTrue (validFunction b g)
→ (validRanges ((Rg b (f b)) ∷ (if cond then (ranges2 b1 f g) else []))) ≡ true
ranges2HasValidRanges : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ IsTrue (validFunction2 b f) → IsTrue (validFunction b g)
→ IsTrue (validRanges (ranges2 b f g))
unfoldSorted : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ IsTrue (sortedRangeList (ranges2 b f g))
unfoldIsSorted00 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ (b1 : Boundary a) → (cond : Bool)
→ sortedRangeList ((Rg b (f b)) ∷ (if_then_else_ cond (ranges2 b1 f g) [])) ≡ true
unfoldIsSorted0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ (mb : Maybe (Boundary a)) → sortedRangeList ((Rg b (f b)) ∷ (ranges3 mb f g)) ≡ true
unfoldIsSorted : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ sortedRangeList (ranges2 b f g) ≡ true
-- the following proofs are used for proving that intersection is valid
intersection2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ ⦃ ne1 : NonEmpty (rSetRanges rs1) ⦄ → ⦃ ne2 : NonEmpty (rSetRanges rs2) ⦄
→ IsTrue (validRangeList (rSetRanges rs1)) → IsTrue (validRangeList (rSetRanges rs2))
→ (b : Bool)
→ validRangeList (
if_then_else_ b
((rangeIntersection (head (rSetRanges rs1) ⦃ ne1 ⦄) (head (rSetRanges rs2) ⦃ ne2 ⦄))
∷ (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper (head (rSetRanges rs1) ⦃ ne1 ⦄) < rangeUpper (head (rSetRanges rs2) ⦃ ne2 ⦄))
(merge2 (tail (rSetRanges rs1) ⦃ ne1 ⦄) (rSetRanges rs2))
(merge2 (rSetRanges rs1) (tail (rSetRanges rs2) ⦃ ne2 ⦄)))))
(filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper (head (rSetRanges rs1) ⦃ ne1 ⦄) < rangeUpper (head (rSetRanges rs2) ⦃ ne2 ⦄))
(merge2 (tail (rSetRanges rs1) ⦃ ne1 ⦄) (rSetRanges rs2))
(merge2 (rSetRanges rs1) (tail (rSetRanges rs2) ⦃ ne2 ⦄)))) ) ≡ true
intersection3 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ ⦃ ne1 : NonEmpty (rSetRanges rs1) ⦄ → ⦃ ne2 : NonEmpty (rSetRanges rs2) ⦄
→ IsTrue (validRangeList (rSetRanges rs1)) → IsTrue (validRangeList (rSetRanges rs2))
→ (b : Bool)
→ validRangeList ((filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ b
(merge2 (tail (rSetRanges rs1) ⦃ ne1 ⦄) (rSetRanges rs2))
(merge2 (rSetRanges rs1) (tail (rSetRanges rs2) ⦃ ne2 ⦄))))) ≡ true
intersectionHolds : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1)) → IsTrue (validRangeList (rSetRanges rs2))
→ validRangeList (filter (λ x → (rangeIsEmpty x == false)) (merge2 (rSetRanges rs1) (rSetRanges rs2))) ≡ true
-- intersection of two valid ranged sets is also valid range set
intersection0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1)) → IsTrue (validRangeList (rSetRanges rs2))
→ IsTrue (validRangeList (filter (λ x → (rangeIsEmpty x == false))
(merge2 (rSetRanges rs1) (rSetRanges rs2))))
intersection0 ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2 = subst IsTrue (sym (intersectionHolds ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2)) IsTrue.itsTrue
-- used for proving that union is valid (merge1 returns a valid range list)
merge1IsSorted0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (h1 h2 : Range a) → (t1 t2 : RSet a) → (b : Bool)
→ IsTrue (validRangeList (h1 ∷ (rSetRanges t1))) → IsTrue (validRangeList (h2 ∷ (rSetRanges t2)))
→ sortedRangeList (if_then_else_ b (h1 ∷ (merge1 (rSetRanges t1) (h2 ∷ (rSetRanges t2))))
(h2 ∷ (merge1 (h1 ∷ (rSetRanges t1)) (rSetRanges t2)))) ≡ true
merge1IsSorted1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1)) → IsTrue (validRangeList (rSetRanges rs2))
→ sortedRangeList (merge1 (rSetRanges rs1) (rSetRanges rs2)) ≡ true
merge1Sorted : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → (rs2 : RSet a)
→ IsTrue (validRangeList (rSetRanges rs1))
→ IsTrue (validRangeList (rSetRanges rs2))
→ IsTrue (sortedRangeList (merge1 (rSetRanges rs1) (rSetRanges rs2)))
merge1Sorted ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2 = subst IsTrue (sym (merge1IsSorted1 rs1 rs2 prf1 prf2)) IsTrue.itsTrue
-- union of two valid ranged sets is also valid range set
unionHolds : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → (rs2 : RSet a)
→ (prf1 : IsTrue (validRangeList (rSetRanges rs1)))
→ (prf2 : IsTrue (validRangeList (rSetRanges rs2)))
→ IsTrue (validRangeList (normalise (merge1 (rSetRanges rs1) (rSetRanges rs2))
⦃ merge1Sorted rs1 rs2 prf1 prf2 ⦄ ⦃ merge1HasValidRanges rs1 rs2 prf1 prf2 ⦄))
unionHolds ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2 = normalisedSortedList
(merge1 (rSetRanges rs1) (rSetRanges rs2)) (merge1Sorted rs1 rs2 prf1 prf2)
(merge1HasValidRanges rs1 rs2 prf1 prf2)
-- used for proving negation is valid
{-# TERMINATING #-}
valid : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ {IsTrue (validRangeList (rSetRanges rs))}
→ (validRangeList (rSetRanges rs)) ≡ (validBoundaryList (bounds1 (rSetRanges rs)))
validSetBounds : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (bs : List (Boundary a)) → validBoundaryList (setBounds1 bs) ≡ validBoundaryList bs
validRanges1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (bs : List (Boundary a))
→ validRangeList (ranges1 bs) ≡ validBoundaryList bs
-- negation of valid ranged set is also valid
prop3 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ IsTrue (validRangeList (rSetRanges rs))
→ validRangeList (rSetRanges rs) ≡ validBoundaryList (setBounds1 (bounds1 (rSetRanges rs)))
prop3 ⦃ o ⦄ ⦃ dio ⦄ rs prf = trans (valid rs {prf}) (sym (validSetBounds (bounds1 (rSetRanges rs))))
prop4 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ IsTrue (validRangeList (rSetRanges rs))
→ validRangeList (rSetRanges rs) ≡ validRangeList (ranges1 (setBounds1 (bounds1 (rSetRanges rs))))
prop4 ⦃ o ⦄ ⦃ dio ⦄ rs prf = trans (prop3 rs prf) (sym (validRanges1 (setBounds1 (bounds1 (rSetRanges rs)))))
negation : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ (IsTrue (validRangeList (rSetRanges rs)))
→ (IsTrue (validRangeList (ranges1 (setBounds1 (bounds1 (rSetRanges rs))))))
negation ⦃ o ⦄ ⦃ dio ⦄ rs prf = subst IsTrue (prop4 rs prf) prf
-- empty range is valid
emptyRangeValid : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (validRangeList ⦃ o ⦄ ⦃ dio ⦄ []) ≡ true
emptyRangeValid = refl
empty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → IsTrue (validRangeList ⦃ o ⦄ ⦃ dio ⦄ [])
empty ⦃ o ⦄ ⦃ dio ⦄ = subst IsTrue (sym (emptyRangeValid ⦃ o ⦄ ⦃ dio ⦄)) IsTrue.itsTrue
-- full range is valid
fullRangeValid : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ →
(validRangeList ⦃ o ⦄ ⦃ dio ⦄ (fullRange ⦃ o ⦄ ⦃ dio ⦄ ∷ [])) ≡ true
full0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ →
IsTrue (validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ []))
full0 ⦃ o ⦄ ⦃ dio ⦄ = subst IsTrue (sym (fullRangeValid ⦃ o ⦄ ⦃ dio ⦄)) IsTrue.itsTrue
-- any singleton range is valid
singletonRangeValid0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (x : a) → (validRangeList ((singletonRange x) ∷ [])) ≡ true
singletonRangeValid : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (x : a) → IsTrue (validRangeList ((singletonRange x) ∷ []))
singletonRangeValid x = subst IsTrue (sym (singletonRangeValid0 x)) IsTrue.itsTrue
rSingleton : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → a → RSet a
rSingleton ⦃ o ⦄ ⦃ dio ⦄ a = RS ((singletonRange a) ∷ []) {singletonRangeValid a}
{-# COMPILE AGDA2HS rSingleton #-}
normaliseRangeList : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ List (Range a) → List (Range a)
normaliseRangeList [] = []
normaliseRangeList rs@(r1 ∷ rss) =
normalise (sort (filter (λ r → (rangeIsEmpty r) == false) rs))
⦃ sortedList rs ⦄ ⦃ validRangesList rs ⦄
{-# COMPILE AGDA2HS normaliseRangeList #-}
makeRangedSet : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ List (Range a) → RSet a
makeRangedSet ⦃ o ⦄ ⦃ dio ⦄ [] = RS [] {empty ⦃ o ⦄ ⦃ dio ⦄}
makeRangedSet ⦃ o ⦄ ⦃ dio ⦄ rs@(r1 ∷ rss) = RS (normaliseRangeList rs)
{ normalisedSortedList (sort (filter (λ r → (rangeIsEmpty r) == false) rs)) (sortedList rs) (validRangesList rs) }
{-# COMPILE AGDA2HS makeRangedSet #-}
rangesAreEmpty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → Bool
rangesAreEmpty [] = true
rangesAreEmpty (r ∷ rs) = false
{-# COMPILE AGDA2HS rangesAreEmpty #-}
rSetIsEmpty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → Bool
rSetIsEmpty ⦃ o ⦄ ⦃ dio ⦄ rset@(RS ranges) = rangesAreEmpty ⦃ o ⦄ ⦃ dio ⦄ ranges
{-# COMPILE AGDA2HS rSetIsEmpty #-}
rSetNegation : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rg : RSet a) → {(IsTrue (validRangeList (rSetRanges rg)))} → RSet a
rSetNegation ⦃ o ⦄ ⦃ dio ⦄ set@(RS ranges) {prf} =
RS (ranges1 (setBounds1 (bounds1 ranges))) {negation set prf}
{-# COMPILE AGDA2HS rSetNegation #-}
rSetIsFull : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ {IsTrue (validRangeList (rSetRanges rs))} → Bool
rSetIsFull set {prf} = rSetIsEmpty (rSetNegation set {prf})
{-# COMPILE AGDA2HS rSetIsFull #-}
rSetEmpty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → RSet a
rSetEmpty ⦃ o ⦄ ⦃ dio ⦄ = RS [] {empty ⦃ o ⦄ ⦃ dio ⦄}
{-# COMPILE AGDA2HS rSetEmpty #-}
rSetFull : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → RSet a
rSetFull ⦃ o ⦄ ⦃ dio ⦄ = RS ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ []) {full0 ⦃ o ⦄ ⦃ dio ⦄}
{-# COMPILE AGDA2HS rSetFull #-}
rSetHas : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {IsTrue (validRangeList (rSetRanges rs))} → a → Bool
rSetHas (RS []) _ = false
rSetHas ⦃ o ⦄ ⦃ dio ⦄ (RS ls@(r ∷ [])) value = rangeHas ⦃ o ⦄ r value
rSetHas ⦃ o ⦄ ⦃ dio ⦄ rst@(RS ls@(r ∷ rs)) {prf} value = (rangeHas ⦃ o ⦄ r value) || (rSetHas (RS rs {headandtail rst prf}) {headandtail rst prf} value)
{-# COMPILE AGDA2HS rSetHas #-}
_-?-_ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a) → {IsTrue (validRangeList (rSetRanges rs))} → a → Bool
_-?-_ rs {prf} = rSetHas rs {prf}
{-# COMPILE AGDA2HS _-?-_ #-}
negationHelper : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ {tr0 : IsTrue (validRangeList (rSetRanges rs))}
→ validRangeList (rSetRanges (rSetNegation rs {tr0})) ≡ validRangeList (ranges1 (setBounds1 (bounds1 (rSetRanges rs))))
negation2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs : RSet a)
→ {tr0 : IsTrue (validRangeList (rSetRanges rs))}
→ (tr : IsTrue (validRangeList (ranges1 (setBounds1 (bounds1 (rSetRanges rs))))))
→ IsTrue (validRangeList (rSetRanges (rSetNegation rs {tr0})))
negation2 rs {prf0} prf = subst IsTrue (sym (negationHelper rs {prf0})) prf
rSetUnion : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → RSet a
rSetUnion ⦃ o ⦄ ⦃ dio ⦄ r1@(RS ls1) {prf1} r2@(RS ls2) {prf2} =
RS (normalise (merge1 ls1 ls2) ⦃ merge1Sorted r1 r2 prf1 prf2 ⦄
⦃ merge1HasValidRanges r1 r2 prf1 prf2 ⦄)
{unionHolds r1 r2 prf1 prf2}
{-# COMPILE AGDA2HS rSetUnion #-}
_-\/-_ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → RSet a
_-\/-_ rs1 {prf1} rs2 {prf2} = rSetUnion rs1 {prf1} rs2 {prf2}
{-# COMPILE AGDA2HS _-\/-_ #-}
unionHelper : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ (prf1 : IsTrue (validRangeList (rSetRanges rs1))) → (prf2 : IsTrue (validRangeList (rSetRanges rs2)))
→ validRangeList (rSetRanges (rSetUnion rs1 {prf1} rs2 {prf2}))
≡ validRangeList (normalise (merge1 (rSetRanges rs1) (rSetRanges rs2)) ⦃ merge1Sorted rs1 rs2 prf1 prf2 ⦄ ⦃ merge1HasValidRanges rs1 rs2 prf1 prf2 ⦄)
unionHelper ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ls1) rs2@(RS ls2) prf1 prf2 =
begin
validRangeList (rSetRanges (rSetUnion rs1 {prf1} rs2 {prf2}))
=⟨⟩
validRangeList (rSetRanges (RS (normalise (merge1 (rSetRanges rs1) (rSetRanges rs2)) ⦃ merge1Sorted rs1 rs2 prf1 prf2 ⦄ ⦃ merge1HasValidRanges rs1 rs2 prf1 prf2 ⦄) {unionHolds rs1 rs2 prf1 prf2}))
=⟨⟩
validRangeList (normalise (merge1 (rSetRanges rs1) (rSetRanges rs2)) ⦃ merge1Sorted rs1 rs2 prf1 prf2 ⦄ ⦃ merge1HasValidRanges rs1 rs2 prf1 prf2 ⦄)
end
union2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ (prf1 : IsTrue (validRangeList (rSetRanges rs1))) → (prf2 : IsTrue (validRangeList (rSetRanges rs2)))
→ IsTrue (validRangeList (normalise (merge1 (rSetRanges rs1) (rSetRanges rs2)) ⦃ merge1Sorted rs1 rs2 prf1 prf2 ⦄ ⦃ merge1HasValidRanges rs1 rs2 prf1 prf2 ⦄))
→ IsTrue (validRangeList (rSetRanges (rSetUnion rs1 {prf1} rs2 {prf2})))
union2 rs1 rs2 prf1 prf2 prf = subst IsTrue (sym (unionHelper rs1 rs2 prf1 prf2)) prf
rSetIntersection : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → RSet a
rSetIntersection ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ls1) {prf1} rs2@(RS ls2) {prf2} =
RS ⦃ o ⦄ ⦃ dio ⦄
(filter (λ x → rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ls1 ls2))
{intersection0 rs1 rs2 prf1 prf2}
{-# COMPILE AGDA2HS rSetIntersection #-}
_-/\-_ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → RSet a
_-/\-_ rs1 {prf1} rs2 {prf2} = rSetIntersection rs1 {prf1} rs2 {prf2}
{-# COMPILE AGDA2HS _-/\-_ #-}
intersectHelper : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ (prf1 : IsTrue (validRangeList (rSetRanges rs1))) → (prf2 : IsTrue (validRangeList (rSetRanges rs2)))
→ validRangeList (rSetRanges (rSetIntersection rs1 {prf1} rs2 {prf2})) ≡ validRangeList (filter (λ r → (rangeIsEmpty r) == false) (merge2 (rSetRanges rs1) (rSetRanges rs2)))
intersection22 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (rs1 : RSet a) → (rs2 : RSet a)
→ (prf1 : IsTrue (validRangeList (rSetRanges rs1))) → (prf2 : IsTrue (validRangeList (rSetRanges rs2)))
→ IsTrue (validRangeList (filter (λ r → (rangeIsEmpty r) == false) (merge2 (rSetRanges rs1) (rSetRanges rs2))))
→ IsTrue (validRangeList (rSetRanges (rSetIntersection rs1 {prf1} rs2 {prf2})))
intersection22 ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2 prf = subst IsTrue (sym (intersectHelper rs1 rs2 prf1 prf2)) prf
rSetDifference : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → RSet a
rSetDifference ⦃ o ⦄ ⦃ dio ⦄ rs1 {prf1} rs2 {prf2} =
rSetIntersection rs1 {prf1} (rSetNegation rs2 {prf2}) {negation2 rs2 (negation rs2 prf2)}
{-# COMPILE AGDA2HS rSetDifference #-}
_-!-_ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → RSet a
_-!-_ rs1 {prf1} rs2 {prf2} = rSetDifference rs1 {prf1} rs2 {prf2}
{-# COMPILE AGDA2HS _-!-_ #-}
rSetIsSubset : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → Bool
rSetIsSubset rs1 {prf1} rs2 {prf2} = rSetIsEmpty (rSetDifference rs1 {prf1} rs2 {prf2})
{-# COMPILE AGDA2HS rSetIsSubset #-}
_-<=-_ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → Bool
_-<=-_ rs1 {prf1} rs2 {prf2} = rSetIsSubset rs1 {prf1} rs2 {prf2}
{-# COMPILE AGDA2HS _-<=-_ #-}
rSetIsSubsetStrict : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → Bool
rSetIsSubsetStrict rs1 {prf1} rs2 {prf2} = rSetIsEmpty
(rSetDifference rs1 {prf1} rs2 {prf2}) && not (rSetIsEmpty (rSetDifference rs2 {prf2} rs1 {prf1}))
{-# COMPILE AGDA2HS rSetIsSubsetStrict #-}
_-<-_ : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄
→ (rs1 : RSet a) → {IsTrue (validRangeList (rSetRanges rs1))}
→ (rs2 : RSet a) → {IsTrue (validRangeList (rSetRanges rs2))} → Bool
_-<-_ rs1 {prf1} rs2 {prf2} = rSetIsSubsetStrict rs1 {prf1} rs2 {prf2}
{-# COMPILE AGDA2HS _-<-_ #-}
instance
isRangedSetSemigroup : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Semigroup (RSet a)
isRangedSetSemigroup ._<>_ r1@(RS l1 {prf1}) r2@(RS l2 {prf2}) = rSetUnion r1 {prf1} r2 {prf2}
isRangedSetMonoid : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Monoid (RSet a)
isRangedSetMonoid .mempty = rSetEmpty
rSetUnfold : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (f : Boundary a → Boundary a)
→ (g : Boundary a → Maybe (Boundary a))
→ ⦃ IsTrue (validFunction2 b f) ⦄
→ ⦃ IsTrue (validFunction b g) ⦄ → RSet a
rSetUnfold ⦃ o ⦄ ⦃ dio ⦄ bound upperFunc succFunc ⦃ fValid ⦄ ⦃ gValid ⦄ =
RS (normalise (ranges2 bound upperFunc succFunc)
⦃ unfoldSorted bound upperFunc succFunc ⦄ ⦃ ranges2HasValidRanges bound upperFunc succFunc fValid gValid ⦄)
{ normalisedSortedList (ranges2 bound upperFunc succFunc)
(unfoldSorted bound upperFunc succFunc) (ranges2HasValidRanges bound upperFunc succFunc fValid gValid) }
{-# COMPILE AGDA2HS rSetUnfold #-}
okAdjIsTrue ⦃ o ⦄ ⦃ dio ⦄ r@(Rg l1 u1) r2@(Rg l2 u2) = refl
headandtailSorted rs@(r ∷ []) prf = IsTrue.itsTrue
headandtailSorted rs@(r ∷ rss@(r2 ∷ rsss)) prf = isTrue&&₂ {r <= r2} prf
headandtail rs@(RS (r ∷ [])) prf = IsTrue.itsTrue
headandtail rs@(RS (r ∷ rss@(r2 ∷ rsss))) prf = isTrue&&₂ {okAdjacent r r2} prf
tailandhead rs@(RS (r ∷ [])) prf = prf
tailandhead rs@(RS (r ∷ rss@(r2 ∷ rsss))) prf = isTrue&&₁ {rangeLower r <= rangeUpper r}
(subst IsTrue (okAdjIsTrue r r2) (isTrue&&₁ {okAdjacent r r2} prf))
okAdjValid rs@(r2 ∷ rss) r prf = isTrue&&₁ {okAdjacent r r2} prf
tailandhead2 rs@(r ∷ []) prf = prf
tailandhead2 rs@(r ∷ rss@(r2 ∷ rsss)) prf = isTrue&&₁ {rangeLower r <= rangeUpper r}
(subst IsTrue (okAdjIsTrue r r2) (isTrue&&₁ {okAdjacent r r2} prf))
headandtail2 rs@(r ∷ []) prf = IsTrue.itsTrue
headandtail2 rs@(r ∷ rss@(r2 ∷ rsss)) prf = isTrue&&₂ {okAdjacent r r2} prf
headandtailValidRanges rs@(r ∷ []) prf = IsTrue.itsTrue
headandtailValidRanges rs@(r ∷ rss@(r2 ∷ rsss)) prf = isTrue&&₂ {rangeLower r <= rangeUpper r} prf
ranges2HasValidRanges ⦃ o ⦄ ⦃ dio ⦄ b f g prf1 prf2 = subst IsTrue (sym (ranges2HasValidRanges0 b f g prf1 prf2)) IsTrue.itsTrue
ranges2HasValidRanges000 ⦃ o ⦄ ⦃ dio ⦄ b b1 f g false prf1 prf2 =
begin
(validRanges ⦃ o ⦄ ⦃ dio ⦄ ((Rg b (f b)) ∷ []))
=⟨⟩
b <= (f b) && (validRanges ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
b <= (f b) && true
=⟨ prop_and_true (b <= (f b)) ⟩
b <= (f b)
=⟨ propIsTrue (b <= (f b)) (rangesLTEQ b f prf1) ⟩
true
end
ranges2HasValidRanges000 ⦃ o ⦄ ⦃ dio ⦄ b b1 f g true prf1 prf2 =
begin
(validRanges ((Rg b (f b)) ∷ (ranges2 b1 f g)))
=⟨⟩
b <= (f b) && (validRanges (ranges2 b1 f g))
=⟨ cong (b <= (f b) &&_) (ranges2HasValidRanges0 b1 f g (stupid1 b b1 f g prf1 prf2 true IsTrue.itsTrue)
(stupid2 b b1 f g prf1 prf2 true IsTrue.itsTrue) ) ⟩
b <= (f b) && true
=⟨ prop_and_true (b <= (f b)) ⟩
b <= (f b)
=⟨ propIsTrue (b <= (f b)) (rangesLTEQ b f prf1) ⟩
true
end
ranges2HasValidRanges00 ⦃ o ⦄ ⦃ dio ⦄ b f g Nothing prf1 prf2 =
begin
(validRanges ⦃ o ⦄ ⦃ dio ⦄ ((Rg b (f b)) ∷ (ranges3 Nothing f g)))
=⟨⟩
validRanges ⦃ o ⦄ ⦃ dio ⦄ ((Rg b (f b)) ∷ [])
=⟨⟩
(b <= (f b)) && (validRanges ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
(b <= (f b)) && true
=⟨ prop_and_true (b <= (f b)) ⟩
b <= (f b)
=⟨ propIsTrue (b <= (f b)) (rangesLTEQ b f prf1) ⟩
true
end
ranges2HasValidRanges00 ⦃ o ⦄ ⦃ dio ⦄ b f g (Just b1) prf1 prf2 =
begin
(validRanges ((Rg b (f b)) ∷ (ranges3 (Just b1) f g)))
=⟨⟩
validRanges ((Rg b (f b)) ∷ (if ((validFunction2 b1 f) && (validFunction b1 g)) then (ranges2 b1 f g) else []))
=⟨ ranges2HasValidRanges000 b b1 f g ((validFunction2 b1 f) && (validFunction b1 g)) prf1 prf2 ⟩
true
end
ranges2HasValidRanges0 ⦃ o ⦄ ⦃ dio ⦄ b f g prf1 prf2 =
begin
(validRanges (ranges2 b f g))
=⟨⟩
validRanges ((Rg b (f b)) ∷ (ranges3 (g b) f g))
=⟨ ranges2HasValidRanges00 b f g (g b) prf1 prf2 ⟩
true
end
merge1HasValidRanges ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2 = subst IsTrue (sym (merge1HasValidRanges0 rs1 rs2 prf1 prf2)) IsTrue.itsTrue
validListMeansValidRanges ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) prf =
begin
(validRanges ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
true
end
validListMeansValidRanges ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS (r1 ∷ [])) prf =
begin
(validRanges (r1 ∷ []))
=⟨⟩
(rangeLower r1 <= rangeUpper r1) && (validRanges ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
(rangeLower r1 <= rangeUpper r1) && true
=⟨ prop_and_true (rangeLower r1 <= rangeUpper r1) ⟩
(rangeLower r1 <= rangeUpper r1)
=⟨ propIsTrue (rangeLower r1 <= rangeUpper r1) prf ⟩
true
end
validListMeansValidRanges ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges@(r1 ∷ r2 ∷ r3)) prf =
begin
(validRanges ranges)
=⟨⟩
(rangeLower r1 <= rangeUpper r1) && (validRanges ⦃ o ⦄ ⦃ dio ⦄ (r2 ∷ r3))
=⟨ cong ((rangeLower r1 <= rangeUpper r1) &&_) (validListMeansValidRanges (RS (r2 ∷ r3) {headandtail rs1 prf}) (headandtail rs1 prf)) ⟩
(rangeLower r1 <= rangeUpper r1) && true
=⟨ prop_and_true (rangeLower r1 <= rangeUpper r1) ⟩
(rangeLower r1 <= rangeUpper r1)
=⟨ propIsTrue (rangeLower r1 <= rangeUpper r1) (tailandhead rs1 prf) ⟩
true
end
merge1HasValidRanges00 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS t1) rs2@(RS t2) h1 h2 prf1 prf2 true =
begin
validRanges (h1 ∷ (merge1 (rSetRanges rs1) (h2 ∷ (rSetRanges rs2))))
=⟨⟩
(rangeLower h1 <= rangeUpper h1) && (validRanges (merge1 t1 (h2 ∷ t2)))
=⟨ cong ((rangeLower h1 <= rangeUpper h1) &&_)
(merge1HasValidRanges0 rs1 (RS (h2 ∷ t2) {prf2}) (headandtail (RS (h1 ∷ t1) {prf1}) prf1) prf2) ⟩
(rangeLower h1 <= rangeUpper h1) && true
=⟨ prop_and_true (rangeLower h1 <= rangeUpper h1) ⟩
(rangeLower h1 <= rangeUpper h1)
=⟨ propIsTrue (rangeLower h1 <= rangeUpper h1) (tailandhead (RS (h1 ∷ t1) {prf1}) prf1) ⟩
true
end
merge1HasValidRanges00 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS t1) rs2@(RS t2) h1 h2 prf1 prf2 false =
begin
validRanges (h2 ∷ (merge1 (h1 ∷ t1) t2))
=⟨⟩
(rangeLower h2 <= rangeUpper h2) && (validRanges (merge1 (h1 ∷ t1) t2))
=⟨ cong ((rangeLower h2 <= rangeUpper h2) &&_)
(merge1HasValidRanges0 (RS (h1 ∷ t1) {prf1}) rs2 prf1 (headandtail (RS (h2 ∷ t2) {prf2}) prf2)) ⟩
(rangeLower h2 <= rangeUpper h2) && true
=⟨ prop_and_true (rangeLower h2 <= rangeUpper h2) ⟩
(rangeLower h2 <= rangeUpper h2)
=⟨ propIsTrue (rangeLower h2 <= rangeUpper h2) (tailandhead (RS (h2 ∷ t2) {prf2}) prf2) ⟩
true
end
merge1HasValidRanges0 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS []) prf1 prf2 =
begin
(validRanges (merge1 (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRanges ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
end
merge1HasValidRanges0 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS (h1 ∷ t1)) rs2@(RS []) prf1 prf2 =
begin
(validRanges (merge1 (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRanges (h1 ∷ t1)
=⟨ validListMeansValidRanges rs1 prf1 ⟩
true
end
merge1HasValidRanges0 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS (h2 ∷ t2)) prf1 prf2 =
begin
(validRanges (merge1 (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRanges (h2 ∷ t2)
=⟨ validListMeansValidRanges rs2 prf2 ⟩
true
end
merge1HasValidRanges0 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS (h1 ∷ t1)) rs2@(RS (h2 ∷ t2)) prf1 prf2 =
begin
(validRanges (merge1 (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRanges (if_then_else_ (h1 < h2) (h1 ∷ (merge1 t1 (h2 ∷ t2))) (h2 ∷ (merge1 (h1 ∷ t1) (t2))))
=⟨ merge1HasValidRanges00 (RS t1 {headandtail rs1 prf1}) (RS t2 {headandtail rs2 prf2}) h1 h2 prf1 prf2 (h1 < h2) ⟩
true
end
normalisedSortedList ⦃ o ⦄ ⦃ dio ⦄ ms prf prf2 = subst IsTrue (sym (normalisedSortedList0 ms prf prf2)) IsTrue.itsTrue
normalisedSortedList00 ⦃ o ⦄ ⦃ dio ⦄ rs r1 r2 prf prf2 true =
begin
validRangeList (if_then_else_ true
(normalise ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs) ⦃ sortedListComposed r1 r2 rs prf ⦄ ⦃ validRangesComposed r1 r2 rs prf prf2 ⦄)
(r1 ∷ (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄)))
=⟨⟩
validRangeList ((normalise ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs) ⦃ sortedListComposed r1 r2 rs prf ⦄ ⦃ validRangesComposed r1 r2 rs prf prf2 ⦄) )
=⟨ normalisedSortedList0 ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs) (sortedListComposed r1 r2 rs prf) (validRangesComposed r1 r2 rs prf prf2) ⟩
true
end
normalisedSortedList00 ⦃ o ⦄ ⦃ dio ⦄ rs r1 r2 prf prf2 false =
begin
validRangeList (if_then_else_ false
(normalise ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs) ⦃ sortedListComposed r1 r2 rs prf ⦄ ⦃ validRangesComposed r1 r2 rs prf prf2 ⦄)
(r1 ∷ (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄)))
=⟨⟩
validRangeList (r1 ∷ (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄))
=⟨ validList r1 (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄)
(normalisedSortedList (r2 ∷ rs) (headandtailSorted (r1 ∷ r2 ∷ rs) prf) (headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2)) ⟩
true
end
normalisedSortedList0 ⦃ o ⦄ ⦃ dio ⦄ ms@([]) prf prf2 =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (normalise [] ⦃ prf ⦄ ⦃ prf2 ⦄)
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
end
normalisedSortedList0 ⦃ o ⦄ ⦃ dio ⦄ ms@(m ∷ []) prf prf2 =
begin
validRangeList (normalise ms ⦃ prf ⦄ ⦃ prf2 ⦄)
=⟨⟩
validRangeList (m ∷ [])
=⟨⟩
(rangeLower m <= rangeUpper m)
=⟨ sym (prop_and_true (rangeLower m <= rangeUpper m)) ⟩
(rangeLower m <= rangeUpper m) && true
=⟨⟩
(rangeLower m <= rangeUpper m) && (validRanges ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
validRanges ms
=⟨ propIsTrue (validRanges ms) prf2 ⟩
true
end
normalisedSortedList0 ⦃ o ⦄ ⦃ dio ⦄ ms@(r1 ∷ r2 ∷ rs) prf prf2 =
begin
validRangeList (normalise ms ⦃ prf ⦄ ⦃ prf2 ⦄)
=⟨⟩
validRangeList (if_then_else_ (overlap1 r1 r2)
(normalise ((Rg (rangeLower r1) (max (rangeUpper r1) (rangeUpper r2))) ∷ rs) ⦃ sortedListComposed r1 r2 rs prf ⦄ ⦃ validRangesComposed r1 r2 rs prf prf2 ⦄)
(r1 ∷ (normalise (r2 ∷ rs) ⦃ headandtailSorted (r1 ∷ r2 ∷ rs) prf ⦄ ⦃ headandtailValidRanges (r1 ∷ r2 ∷ rs) prf2 ⦄)))
=⟨ normalisedSortedList00 rs r1 r2 prf prf2 (overlap1 r1 r2) ⟩
true
end
unfoldIsSorted00 ⦃ o ⦄ ⦃ dio ⦄ b f g b1 false =
begin
sortedRangeList ((Rg b (f b)) ∷ (if_then_else_ false (ranges2 b1 f g) []))
=⟨⟩
sortedRangeList ((Rg b (f b)) ∷ [])
=⟨⟩
true
end
unfoldIsSorted00 ⦃ o ⦄ ⦃ dio ⦄ b f g b1 true =
begin
sortedRangeList ((Rg b (f b)) ∷ (if_then_else_ true (ranges2 b1 f g) []))
=⟨⟩
sortedRangeList ((Rg b (f b)) ∷ (ranges2 b1 f g))
=⟨ validSortedList (Rg b (f b)) (ranges2 b1 f g) (unfoldSorted b1 f g) ⟩
true
end
unfoldIsSorted0 ⦃ o ⦄ ⦃ dio ⦄ b f g Nothing =
begin
sortedRangeList ((Rg b (f b)) ∷ (ranges3 Nothing f g))
=⟨⟩
sortedRangeList ((Rg b (f b)) ∷ [])
=⟨⟩
true
end
unfoldIsSorted0 ⦃ o ⦄ ⦃ dio ⦄ b f g mb@(Just b1) =
begin
sortedRangeList ((Rg b (f b)) ∷ (ranges3 mb f g))
=⟨⟩
sortedRangeList ((Rg b (f b)) ∷ (if_then_else_ ((validFunction2 b1 f) && (validFunction b1 g)) (ranges2 b1 f g) []))
=⟨ unfoldIsSorted00 b f g b1 ((validFunction2 b1 f) && (validFunction b1 g)) ⟩
true
end
unfoldIsSorted ⦃ o ⦄ ⦃ dio ⦄ b f g =
begin
sortedRangeList (ranges2 b f g)
=⟨⟩
sortedRangeList ((Rg b (f b)) ∷ (ranges3 (g b) f g))
=⟨ unfoldIsSorted0 b f g (g b) ⟩
true
end
unfoldSorted ⦃ o ⦄ ⦃ dio ⦄ b f g = subst IsTrue (sym (unfoldIsSorted b f g)) IsTrue.itsTrue
merge1IsSorted0 ⦃ o ⦄ ⦃ dio ⦄ h1 h2 rs1@(RS []) rs2@(RS []) true prf1 prf2 =
begin
sortedRangeList (h1 ∷ (merge1 [] (h2 ∷ [])))
=⟨⟩
sortedRangeList (h1 ∷ h2 ∷ [])
=⟨ okSorted h1 h2 ⟩
true
end
merge1IsSorted0 ⦃ o ⦄ ⦃ dio ⦄ h1 h2 rs1@(RS []) rs2@(RS t2@(h4 ∷ tt2)) true prf1 prf2 =
begin
sortedRangeList (h1 ∷ (merge1 [] (h2 ∷ t2)))
=⟨⟩
sortedRangeList (h1 ∷ (h2 ∷ t2))
=⟨ validSortedList h1 (h2 ∷ t2) (validIsSorted (h2 ∷ t2) prf2) ⟩
true
end
merge1IsSorted0 ⦃ o ⦄ ⦃ dio ⦄ h1 h2 rs1@(RS t1@(h3 ∷ tt1)) rs2@(RS t2) true prf1 prf2 =
begin
sortedRangeList (h1 ∷ (merge1 t1 (h2 ∷ t2)))
=⟨ validSortedList h1 (merge1 t1 (h2 ∷ t2)) (merge1Sorted rs1 (RS (h2 ∷ t2) {prf2}) (headandtail (RS (h1 ∷ t1) {prf1}) prf1) prf2) ⟩
true
end
merge1IsSorted0 ⦃ o ⦄ ⦃ dio ⦄ h1 h2 rs1@(RS []) rs2@(RS []) false prf1 prf2 =
begin
sortedRangeList (h2 ∷ (merge1 (h1 ∷ []) []))
=⟨⟩
sortedRangeList (h2 ∷ h1 ∷ [])
=⟨ okSorted h2 h1 ⟩
true
end
merge1IsSorted0 ⦃ o ⦄ ⦃ dio ⦄ h1 h2 rs1@(RS t1@(h3 ∷ tt1)) rs2@(RS []) false prf1 prf2 =
begin
sortedRangeList (h2 ∷ (merge1 (h1 ∷ t1) []))
=⟨⟩
sortedRangeList (h2 ∷ h1 ∷ t1)
=⟨ validSortedList h2 (h1 ∷ t1) (validIsSorted (h1 ∷ t1) prf1) ⟩
true
end
merge1IsSorted0 ⦃ o ⦄ ⦃ dio ⦄ h1 h2 rs1@(RS t1) rs2@(RS t2@(h4 ∷ tt2)) false prf1 prf2 =
begin
sortedRangeList (h2 ∷ (merge1 (h1 ∷ t1) t2))
=⟨ validSortedList h2 (merge1 (h1 ∷ t1) t2) (merge1Sorted (RS (h1 ∷ t1) {prf1}) rs2 prf1 (headandtail (RS (h2 ∷ t2) {prf2}) prf2)) ⟩
true
end
merge1IsSorted1 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS []) prf1 prf2 = refl
merge1IsSorted1 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ms1@(h1 ∷ t1)) rs2@(RS []) prf1 prf2 = propIsTrue (sortedRangeList (merge1 (rSetRanges rs1) (rSetRanges rs2))) (validIsSorted (merge1 (rSetRanges rs1) (rSetRanges rs2)) prf1)
merge1IsSorted1 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS ms1@(h1 ∷ t1)) prf1 prf2 = propIsTrue (sortedRangeList (merge1 (rSetRanges rs1) (rSetRanges rs2))) (validIsSorted (merge1 (rSetRanges rs1) (rSetRanges rs2)) prf2)
merge1IsSorted1 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ms1@(h1 ∷ t1)) rs2@(RS ms2@(h2 ∷ t2)) prf1 prf2 =
begin
sortedRangeList (merge1 (rSetRanges rs1) (rSetRanges rs2))
=⟨⟩
sortedRangeList (if_then_else_ (h1 < h2) (h1 ∷ (merge1 t1 ms2)) (h2 ∷ (merge1 ms1 t2)))
=⟨ merge1IsSorted0 h1 h2 (RS t1 {headandtail rs1 prf1}) (RS t2 {headandtail rs2 prf2}) (h1 < h2) prf1 prf2 ⟩
true
end
singletonRangeValid0 ⦃ o ⦄ ⦃ dio ⦄ x =
begin
validRangeList ((singletonRange x) ∷ [])
=⟨⟩
((rangeLower (singletonRange x)) <= (rangeUpper (singletonRange x)))
=⟨⟩
((rangeLower (Rg (BoundaryBelow x) (BoundaryAbove x))) <= (rangeUpper (Rg (BoundaryBelow x) (BoundaryAbove x))))
=⟨⟩
(BoundaryBelow x <= BoundaryAbove x)
=⟨⟩
((compare (BoundaryBelow x) (BoundaryAbove x) == LT) || (compare (BoundaryBelow x) (BoundaryAbove x) == EQ))
=⟨⟩
(((if_then_else_ (x > x) (if_then_else_ (adjacent x x) EQ GT) LT) == LT) || (compare (BoundaryBelow x) (BoundaryAbove x) == EQ))
=⟨ cong (_|| (compare (BoundaryBelow x) (BoundaryAbove x) == EQ)) (cong (_== LT) (propIf3 (x > x) (lt x x refl))) ⟩
((LT == LT) || (compare (BoundaryBelow x) (BoundaryAbove x) == EQ))
=⟨⟩
(true || (compare (BoundaryBelow x) (BoundaryAbove x) == EQ))
=⟨⟩
true
end
intersectHelper ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ls1) rs2@(RS ls2) prf1 prf2 =
begin
validRangeList (rSetRanges (rSetIntersection rs1 {prf1} rs2 {prf2}))
=⟨⟩
validRangeList (rSetRanges (RS (filter (λ r → (rangeIsEmpty r) == false) (merge2 (rSetRanges rs1) (rSetRanges rs2))) {intersection0 rs1 rs2 prf1 prf2}))
=⟨⟩
validRangeList (filter (λ r → (rangeIsEmpty r) == false) (merge2 (rSetRanges rs1) (rSetRanges rs2)))
end
negationHelper ⦃ o ⦄ ⦃ dio ⦄ rs@(RS ranges) {prf} =
begin
validRangeList (rSetRanges (rSetNegation rs {prf}))
=⟨⟩
validRangeList (rSetRanges (RS ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges))) {negation rs prf}))
=⟨⟩
validRangeList (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges)))
=⟨⟩
validRangeList (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs))))
end
fullRangeValid ⦃ o ⦄ ⦃ dio ⦄ =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (fullRange ⦃ o ⦄ ⦃ dio ⦄ ∷ [])
=⟨⟩
((rangeLower (fullRange ⦃ o ⦄ ⦃ dio ⦄)) <= (rangeUpper (fullRange ⦃ o ⦄ ⦃ dio ⦄)))
=⟨⟩
true
end
intersection3 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1@(r1 ∷ rss1)) rs2@(RS ranges2@(r2 ∷ rss2)) ⦃ ne1 ⦄ ⦃ ne2 ⦄ prf1 prf2 true =
begin
validRangeList (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ true
(merge2 rss1 ranges2) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ranges1 rss2)))
=⟨⟩
validRangeList (filter (λ x → (rangeIsEmpty x == false)) (merge2 rss1 ranges2))
=⟨ intersectionHolds
⦃ o ⦄ ⦃ dio ⦄ (RS rss1 {headandtail rs1 ⦃ NonEmpty.itsNonEmpty ⦄ prf1}) rs2 (headandtail ⦃ o ⦄ ⦃ dio ⦄ rs1 ⦃ ne1 ⦄ prf1) prf2 ⟩
true
end
intersection3 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1@(r1 ∷ rss1)) rs2@(RS ranges2@(r2 ∷ rss2)) ⦃ ne1 ⦄ ⦃ ne2 ⦄ prf1 prf2 false =
begin
validRangeList (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ false
(merge2 ⦃ o ⦄ ⦃ dio ⦄ rss1 ranges2) (merge2 ranges1 rss2)))
=⟨⟩
validRangeList (filter (λ x → (rangeIsEmpty x == false)) (merge2 ranges1 rss2))
=⟨ intersectionHolds
⦃ o ⦄ ⦃ dio ⦄ rs1 (RS rss2 {headandtail rs2 ⦃ NonEmpty.itsNonEmpty ⦄ prf2}) prf1 (headandtail ⦃ o ⦄ ⦃ dio ⦄ rs2 ⦃ ne2 ⦄ prf2) ⟩
true
end
intersection2 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1@(r1 ∷ rss1)) rs2@(RS ranges2@(r2 ∷ rss2)) ⦃ ne1 ⦄ ⦃ ne2 ⦄ prf1 prf2 false =
begin
validRangeList (
if_then_else_ false
((rangeIntersection ⦃ o ⦄ ⦃ dio ⦄ r1 r2) ∷ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false))
(if_then_else_ ((rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1) < (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2))
(merge2 ⦃ o ⦄ ⦃ dio ⦄ rss1 ranges2) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ranges1 rss2))))
(filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)
(merge2 rss1 ranges2) (merge2 ranges1 rss2)))
)
=⟨⟩
validRangeList (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)
(merge2 rss1 ranges2) (merge2 ranges1 rss2)))
=⟨ intersection3 ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 ⦃ ne1 ⦄ ⦃ ne2 ⦄ prf1 prf2 (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2) ⟩
true
end
intersection2 ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1@(r1 ∷ rss1)) rs2@(RS ranges2@(r2 ∷ rss2)) ⦃ ne1 ⦄ ⦃ ne2 ⦄ prf1 prf2 true =
begin
validRangeList (
if_then_else_ true
((rangeIntersection ⦃ o ⦄ ⦃ dio ⦄ r1 r2) ∷ (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)
(merge2 rss1 ranges2) (merge2 ranges1 rss2))))
(filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)
(merge2 ⦃ o ⦄ ⦃ dio ⦄ rss1 ranges2) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ranges1 rss2)))
)
=⟨⟩
validRangeList ((rangeIntersection ⦃ o ⦄ ⦃ dio ⦄ r1 r2) ∷ (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)
(merge2 rss1 ranges2) (merge2 ranges1 rss2))))
=⟨ validList (rangeIntersection ⦃ o ⦄ ⦃ dio ⦄ r1 r2) (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)
(merge2 rss1 ranges2) (merge2 ranges1 rss2)))
(subst IsTrue (sym
(intersection3 ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 ⦃ ne1 ⦄ ⦃ ne2 ⦄ prf1 prf2 (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2)))
IsTrue.itsTrue) ⟩
true
end
intersectionHolds ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS []) _ _ =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (merge2 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (merge2 ⦃ o ⦄ ⦃ dio ⦄ [] []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) [])
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
end
intersectionHolds ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges@(r ∷ rs)) rs2@(RS []) _ _ =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (merge2 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (merge2 ⦃ o ⦄ ⦃ dio ⦄ ranges []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) [])
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
end
intersectionHolds ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS []) rs2@(RS ranges@(r ∷ rs)) _ _ =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (merge2 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) (merge2 ⦃ o ⦄ ⦃ dio ⦄ [] ranges))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (filter (λ x → (rangeIsEmpty ⦃ o ⦄ ⦃ dio ⦄ x == false)) [])
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
end
intersectionHolds ⦃ o ⦄ ⦃ dio ⦄ rs1@(RS ranges1@(r1 ∷ rss1)) rs2@(RS ranges2@(r2 ∷ rss2)) prf1 prf2 =
begin
validRangeList (filter (λ x → (rangeIsEmpty x == false)) (merge2 (rSetRanges rs1) (rSetRanges rs2)))
=⟨⟩
validRangeList (filter (λ x → (rangeIsEmpty x == false))
((rangeIntersection r1 r2) ∷ (if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2) (merge2 rss1 ranges2) (merge2 ranges1 rss2))))
=⟨⟩
validRangeList (
if_then_else_ (rangeIsEmpty (rangeIntersection r1 r2) == false)
((rangeIntersection r1 r2) ∷ (filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2) (merge2 rss1 ranges2) (merge2 ranges1 rss2))))
(filter (λ x → (rangeIsEmpty x == false))
(if_then_else_ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r1 < rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2) (merge2 rss1 ranges2) (merge2 ranges1 rss2)))
)
=⟨ intersection2 ⦃ o ⦄ ⦃ dio ⦄ rs1 rs2 prf1 prf2 (rangeIsEmpty (rangeIntersection r1 r2) == false) ⟩
true
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ [] =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 [])
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ []
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (BoundaryAboveAll ∷ []) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (BoundaryAboveAll ∷ []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (BoundaryAboveAll ∷ [])
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (BoundaryBelowAll ∷ []) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (BoundaryBelowAll ∷ []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg BoundaryBelowAll BoundaryAboveAll) ∷ [])
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (BoundaryBelowAll ∷ [])
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ ((BoundaryAbove x) ∷ []) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ ((BoundaryAbove x) ∷ []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg (BoundaryAbove x) BoundaryAboveAll) ∷ [])
=⟨⟩
(BoundaryAbove x) <= BoundaryAboveAll
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ ((BoundaryAbove x) ∷ [])
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ ((BoundaryBelow x) ∷ []) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ ((BoundaryBelow x) ∷ []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg (BoundaryBelow x) (BoundaryAboveAll)) ∷ [])
=⟨⟩
(BoundaryBelow x) <= BoundaryAboveAll
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ ((BoundaryBelow x) ∷ [])
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ []) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ []))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ ranges1([]))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ [])
=⟨⟩
(b1 <= b2)
=⟨ sym (prop_and_true (b1 <= b2)) ⟩
((b1 <= b2) && true)
=⟨⟩
((b1 <= b2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ []))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ [])
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs@(b3@(BoundaryBelow x) ∷ [])) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (Rg b3 (BoundaryAboveAll)) ∷ [])
=⟨⟩
((okAdjacent (Rg b1 b2) (Rg b3 (BoundaryAboveAll))) && (validRangeList ⦃ o ⦄ ⦃ dio ⦄ []))
=⟨⟩
((okAdjacent (Rg b1 b2) (Rg b3 BoundaryAboveAll)) && true)
=⟨⟩
(((b1 <= b2) && (b2 <= b3) && (b3 <= BoundaryAboveAll)) && true)
=⟨ prop_and_true ((b1 <= b2) && (b2 <= b3) && (b3 <= BoundaryAboveAll)) ⟩
((b1 <= b2) && (b2 <= b3) && true)
=⟨⟩
((b1 <= b2) && (b2 <= b3) && (validBoundaryList (b3 ∷ [])))
=⟨⟩
((b1 <= b2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ b3 ∷ [])))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs)
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs@(b3@(BoundaryAbove x) ∷ [])) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (Rg b3 (BoundaryAboveAll)) ∷ [])
=⟨⟩
((okAdjacent (Rg b1 b2) (Rg b3 BoundaryAboveAll)) && (validRangeList ⦃ o ⦄ ⦃ dio ⦄ []))
=⟨⟩
((okAdjacent (Rg b1 b2) (Rg b3 BoundaryAboveAll)) && true)
=⟨⟩
(((b1 <= b2) && (b2 <= b3) && (b3 <= BoundaryAboveAll)) && true)
=⟨ prop_and_true ((b1 <= b2) && (b2 <= b3) && (b3 <= BoundaryAboveAll)) ⟩
((b1 <= b2) && (b2 <= b3) && true)
=⟨⟩
((b1 <= b2) && (b2 <= b3) && (validBoundaryList (b3 ∷ [])))
=⟨⟩
((b1 <= b2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ b3 ∷ [])))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs)
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs@(b3@(BoundaryBelowAll) ∷ [])) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (Rg b3 (BoundaryAboveAll)) ∷ [])
=⟨⟩
((okAdjacent (Rg b1 b2) (Rg b3 (BoundaryAboveAll))) && (validRangeList ⦃ o ⦄ ⦃ dio ⦄ []))
=⟨⟩
((okAdjacent (Rg b1 b2) (Rg b3 (BoundaryAboveAll))) && true)
=⟨⟩
(((b1 <= b2) && (b2 <= b3) && (b3 <= (BoundaryAboveAll))) && true)
=⟨ prop_and_true ((b1 <= b2) && (b2 <= b3) && (b3 <= (BoundaryAboveAll))) ⟩
((b1 <= b2) && (b2 <= b3) && true)
=⟨⟩
((b1 <= b2) && (b2 <= b3) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b3 ∷ [])))
=⟨⟩
((b1 <= b2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ b3 ∷ [])))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs)
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs@(b3@(BoundaryAboveAll) ∷ [])) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ [])
=⟨⟩
(b1 <= b2)
=⟨ sym (prop_and_true (b1 <= b2)) ⟩
((b1 <= b2) && true)
=⟨⟩
((b1 <= b2) && (b2 <= b3))
=⟨ sym (prop_and_true ((b1 <= b2) && (b2 <= b3))) ⟩
(((b1 <= b2) && (b2 <= b3)) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b3 ∷ [])))
=⟨ prop_and_assoc (b1 <= b2) (b2 <= b3) (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b3 ∷ [])) ⟩
((b1 <= b2) && (b2 <= b3) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b3 ∷ [])))
=⟨⟩
((b1 <= b2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ b3 ∷ [])))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs)
end
validRanges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs@(b3 ∷ bss@(b4 ∷ bsss))) =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ ((Rg b1 b2) ∷ (Rg b3 b4) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bsss))
=⟨⟩
(okAdjacent (Rg b1 b2) (Rg b3 b4)) && validRangeList ((Rg b3 b4) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bsss))
=⟨⟩
(((b1 <= b2) && (b2 <= b3) && (b3 <= b4)) && (validRangeList ((Rg b3 b4) ∷ (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bsss))))
=⟨⟩
(((b1 <= b2) && (b2 <= b3) && (b3 <= b4)) && (validRangeList (ranges1 ⦃ o ⦄ ⦃ dio ⦄ bs)))
=⟨ cong (((b1 <= b2) && (b2 <= b3) && (b3 <= b4)) &&_) (validRanges1 ⦃ o ⦄ ⦃ dio ⦄ bs) ⟩
(((b1 <= b2) && ((b2 <= b3) && (b3 <= b4))) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨ prop_and_assoc (b1 <= b2) ((b2 <= b3) && (b3 <= b4)) (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs) ⟩
((b1 <= b2) && (((b2 <= b3) && (b3 <= b4)) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs)))
=⟨ cong ((b1 <= b2) &&_) (prop_and_assoc (b2 <= b3) (b3 <= b4) (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs)) ⟩
((b1 <= b2) && ((b2 <= b3) && (b3 <= b4) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs)))
=⟨⟩
((b1 <= b2) && ((b2 <= b3) && (b3 <= b4) && (b3 <= b4 && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bss))))
=⟨ cong ((b1 <= b2) &&_) (cong (b2 <= b3 &&_) (prop_and_cancel (b3 <= b4))) ⟩
((b1 <= b2) && (b2 <= b3) && (b3 <= b4) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bss))
=⟨⟩
((b1 <= b2) && (b2 <= b3) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs))
=⟨⟩
((b1 <= b2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b2 ∷ bs)))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (b1 ∷ b2 ∷ bs)
end
validSetBounds ⦃ o ⦄ ⦃ dio ⦄ [] =
begin
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ []
end
validSetBounds ⦃ o ⦄ ⦃ dio ⦄ bs@(BoundaryBelowAll ∷ []) =
begin
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ bs)
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bs
end
validSetBounds ⦃ o ⦄ ⦃ dio ⦄ bs@(b0@(BoundaryBelowAll) ∷ bss@(b1 ∷ b2)) =
begin
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ bs)
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bss
=⟨⟩
(true && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bss))
=⟨ cong (_&& (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ bss)) (sym (BoundaryBelowAllSmaller ⦃ o ⦄ ⦃ dio ⦄ b1)) ⟩
((BoundaryBelowAll <= b1) && (validBoundaryList bss))
=⟨⟩
validBoundaryList bs
end
validSetBounds ⦃ o ⦄ ⦃ dio ⦄ bs@(b@(BoundaryBelow x) ∷ bss) =
begin
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ bs)
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (BoundaryBelowAll ∷ bs)
=⟨⟩
((BoundaryBelowAll <= b) && (validBoundaryList bs))
=⟨⟩
(true && (validBoundaryList bs))
=⟨⟩
(validBoundaryList bs)
end
validSetBounds ⦃ o ⦄ ⦃ dio ⦄ bs@(b@(BoundaryAboveAll) ∷ bss) =
begin
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ bs)
=⟨⟩
validBoundaryList (BoundaryBelowAll ∷ bs)
=⟨⟩
((BoundaryBelowAll <= b) && (validBoundaryList bs))
=⟨⟩
(true && (validBoundaryList bs))
=⟨⟩
(validBoundaryList bs)
end
validSetBounds ⦃ o ⦄ ⦃ dio ⦄ bs@(b@(BoundaryAbove x) ∷ bss) =
begin
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (setBounds1 ⦃ o ⦄ ⦃ dio ⦄ bs)
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (BoundaryBelowAll ∷ bs)
=⟨⟩
((BoundaryBelowAll <= b) && (validBoundaryList bs))
=⟨⟩
(true && (validBoundaryList bs))
=⟨⟩
(validBoundaryList bs)
end
valid ⦃ o ⦄ ⦃ dio ⦄ rs@(RS []) {_} =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs)
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
true
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ []
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ [])
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs))
end
valid ⦃ o ⦄ ⦃ dio ⦄ rs@(RS (r ∷ [])) {_} =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs)
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (r ∷ [])
=⟨⟩
((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r) <= (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r))
=⟨ sym (prop_and_true ((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r) <= (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r))) ⟩
(((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r) <= (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r)) && true)
=⟨⟩
(((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r) <= (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r)) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ []))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ ((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r) ∷ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r) ∷ [])
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (r ∷ []))
=⟨⟩
validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs))
end
valid ⦃ o ⦄ ⦃ dio ⦄ rs@(RS ranges@(r@(Rg l1 u1) ∷ r1@(r2@(Rg l2 u2) ∷ rss))) {prf} =
begin
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (rSetRanges rs)
=⟨⟩
validRangeList ⦃ o ⦄ ⦃ dio ⦄ (r ∷ (r2 ∷ rss))
=⟨⟩
((okAdjacent r r2) && (validRangeList ⦃ o ⦄ ⦃ dio ⦄ r1))
=⟨⟩
((l1 <= u1 && (u1 <= l2 && l2 <= u2)) && (validRangeList ⦃ o ⦄ ⦃ dio ⦄ r1))
=⟨ cong ((l1 <= u1 && u1 <= l2 && l2 <= u2) &&_) (valid ⦃ o ⦄ ⦃ dio ⦄ (RS r1 {headandtail rs prf}) {headandtail rs prf}) ⟩
((l1 <= u1 && (u1 <= l2 && l2 <= u2)) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ r1)))
=⟨ prop_and_assoc (l1 <= u1) (u1 <= l2 && l2 <= u2) (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ r1)) ⟩
(l1 <= u1 && ((u1 <= l2 && l2 <= u2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ r1))))
=⟨ cong (l1 <= u1 &&_) (prop_and_assoc (u1 <= l2) (l2 <= u2) (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ r1))) ⟩
(l1 <= u1 && u1 <= l2 && (l2 <= u2 && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ r1))))
=⟨⟩
(l1 <= u1 && u1 <= l2 && (l2 <= u2
&& (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ ((rangeLower ⦃ o ⦄ ⦃ dio ⦄ r2) ∷ (rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2) ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rss)))))
=⟨⟩
(l1 <= u1 && u1 <= l2 && l2 <= u2 && l2 <= u2
&& (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ ((rangeUpper ⦃ o ⦄ ⦃ dio ⦄ r2) ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rss))))
=⟨ cong (l1 <= u1 &&_) (cong (u1 <= l2 &&_) (prop_and_cancel (l2 <= u2))) ⟩
(l1 <= u1 && u1 <= l2 && ((l2 <= u2) && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (u2 ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rss)))))
=⟨⟩
(l1 <= u1 && u1 <= l2 && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (l2 ∷ (u2 ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rss)))))
=⟨⟩
(l1 <= u1 && (validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (u1 ∷ l2 ∷ u2 ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rss))))
=⟨⟩
(validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (l1 ∷ u1 ∷ l2 ∷ u2 ∷ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ rss)))
=⟨⟩
(validBoundaryList ⦃ o ⦄ ⦃ dio ⦄ (bounds1 ⦃ o ⦄ ⦃ dio ⦄ ranges))
end
| {
"alphanum_fraction": 0.5556056158,
"avg_line_length": 45.7182724252,
"ext": "agda",
"hexsha": "cc50309d489585ab37b4467625d27a1dcee4d824",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ioanasv/agda2hs",
"max_forks_repo_path": "lib/Haskell/RangedSets/RangedSet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ioanasv/agda2hs",
"max_issues_repo_path": "lib/Haskell/RangedSets/RangedSet.agda",
"max_line_length": 212,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ioanasv/agda2hs",
"max_stars_repo_path": "lib/Haskell/RangedSets/RangedSet.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:41:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:41:34.000Z",
"num_tokens": 29216,
"size": 68806
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Bags with negative multiplicities, for Nehemiah.
--
-- Instead of implementing bags (with negative multiplicities,
-- like in the paper) in Agda, we postulate that a group of such
-- bags exist. Note that integer bags with integer multiplicities
-- are actually the free group given a singleton operation
-- `Integer -> Bag`, so this should be easy to formalize in
-- principle.
------------------------------------------------------------------------
module Postulate.Bag-Nehemiah where
-- Postulates about bags of integers, version Nehemiah
--
-- This module postulates bags of integers with negative
-- multiplicities as a group under additive union.
open import Relation.Binary.PropositionalEquality
open import Algebra.Structures
open import Data.Integer
-- postulate Bag as an abelion group
postulate Bag : Set
-- singleton
postulate singletonBag : ℤ → Bag
-- union
postulate _++_ : Bag → Bag → Bag
infixr 5 _++_
-- negate = mapMultiplicities (λ z → - z)
postulate negateBag : Bag → Bag
postulate emptyBag : Bag
instance
postulate abelian-bag : IsAbelianGroup _≡_ _++_ emptyBag negateBag
-- Naming convention follows Algebra.Morphism
-- Homomorphic₁ : morphism preserves negation
Homomorphic₁ :
{A B : Set} (f : A → B) (negA : A → A) (negB : B → B) → Set
Homomorphic₁ {A} {B} f negA negB = ∀ {x} → f (negA x) ≡ negB (f x)
-- Homomorphic₂ : morphism preserves binary operation.
Homomorphic₂ :
{A B : Set} (f : A → B) (_+_ : A → A → A) (_*_ : B → B → B) → Set
Homomorphic₂ {A} {B} f _+_ _*_ = ∀ {x y} → f (x + y) ≡ f x * f y
-- postulate map, flatmap and sum to be homomorphisms
postulate mapBag : (f : ℤ → ℤ) (b : Bag) → Bag
postulate flatmapBag : (f : ℤ → Bag) (b : Bag) → Bag
postulate sumBag : Bag → ℤ
postulate homo-map : ∀ {f} → Homomorphic₂ (mapBag f) _++_ _++_
postulate homo-flatmap : ∀ {f} → Homomorphic₂ (flatmapBag f) _++_ _++_
postulate homo-sum : Homomorphic₂ sumBag _++_ _+_
postulate neg-map : ∀ {f} → Homomorphic₁ (mapBag f) negateBag negateBag
postulate neg-flatmap : ∀ {f} → Homomorphic₁ (flatmapBag f) negateBag negateBag
| {
"alphanum_fraction": 0.6537216828,
"avg_line_length": 37.9473684211,
"ext": "agda",
"hexsha": "fc4f6ef8e3a4cc174f20ed0b008e65d7585dfcc5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Postulate/Bag-Nehemiah.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Postulate/Bag-Nehemiah.agda",
"max_line_length": 79,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Postulate/Bag-Nehemiah.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 633,
"size": 2163
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of functions, such as associativity and commutativity
------------------------------------------------------------------------
-- These properties can (for instance) be used to define algebraic
-- structures.
open import Level
open import Relation.Binary
-- The properties are specified using the following relation as
-- "equality".
module Algebra.FunctionProperties
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Data.Product
------------------------------------------------------------------------
-- Unary and binary operations
open import Algebra.FunctionProperties.Core public
------------------------------------------------------------------------
-- Properties of operations
Associative : Op₂ A → Set _
Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z))
Commutative : Op₂ A → Set _
Commutative _∙_ = ∀ x y → (x ∙ y) ≈ (y ∙ x)
LeftIdentity : A → Op₂ A → Set _
LeftIdentity e _∙_ = ∀ x → (e ∙ x) ≈ x
RightIdentity : A → Op₂ A → Set _
RightIdentity e _∙_ = ∀ x → (x ∙ e) ≈ x
Identity : A → Op₂ A → Set _
Identity e ∙ = LeftIdentity e ∙ × RightIdentity e ∙
LeftZero : A → Op₂ A → Set _
LeftZero z _∙_ = ∀ x → (z ∙ x) ≈ z
RightZero : A → Op₂ A → Set _
RightZero z _∙_ = ∀ x → (x ∙ z) ≈ z
Zero : A → Op₂ A → Set _
Zero z ∙ = LeftZero z ∙ × RightZero z ∙
LeftInverse : A → Op₁ A → Op₂ A → Set _
LeftInverse e _⁻¹ _∙_ = ∀ x → (x ⁻¹ ∙ x) ≈ e
RightInverse : A → Op₁ A → Op₂ A → Set _
RightInverse e _⁻¹ _∙_ = ∀ x → (x ∙ (x ⁻¹)) ≈ e
Inverse : A → Op₁ A → Op₂ A → Set _
Inverse e ⁻¹ ∙ = LeftInverse e ⁻¹ ∙ × RightInverse e ⁻¹ ∙
_DistributesOverˡ_ : Op₂ A → Op₂ A → Set _
_*_ DistributesOverˡ _+_ =
∀ x y z → (x * (y + z)) ≈ ((x * y) + (x * z))
_DistributesOverʳ_ : Op₂ A → Op₂ A → Set _
_*_ DistributesOverʳ _+_ =
∀ x y z → ((y + z) * x) ≈ ((y * x) + (z * x))
_DistributesOver_ : Op₂ A → Op₂ A → Set _
* DistributesOver + = (* DistributesOverˡ +) × (* DistributesOverʳ +)
_IdempotentOn_ : Op₂ A → A → Set _
_∙_ IdempotentOn x = (x ∙ x) ≈ x
Idempotent : Op₂ A → Set _
Idempotent ∙ = ∀ x → ∙ IdempotentOn x
IdempotentFun : Op₁ A → Set _
IdempotentFun f = ∀ x → f (f x) ≈ f x
_Absorbs_ : Op₂ A → Op₂ A → Set _
_∙_ Absorbs _∘_ = ∀ x y → (x ∙ (x ∘ y)) ≈ x
Absorptive : Op₂ A → Op₂ A → Set _
Absorptive ∙ ∘ = (∙ Absorbs ∘) × (∘ Absorbs ∙)
Involutive : Op₁ A → Set _
Involutive f = ∀ x → f (f x) ≈ x
| {
"alphanum_fraction": 0.5296506905,
"avg_line_length": 27.3555555556,
"ext": "agda",
"hexsha": "1d49422474c1181033fb9d7678a311a3ff552f56",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Algebra/FunctionProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Algebra/FunctionProperties.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Algebra/FunctionProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 866,
"size": 2462
} |
------------------------------------------------------------------------------
-- Properties of the divisibility relation
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.Divisibility.By0.Properties where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Properties
open import LTC-PCF.Data.Nat.Divisibility.By0
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Inequalities.Properties
open import LTC-PCF.Data.Nat.Properties
open import LTC-PCF.Data.Nat.UnaryNumbers
open import LTC-PCF.Data.Nat.UnaryNumbers.Totality
------------------------------------------------------------------------------
-- Any positive number divides 0.
S∣0 : ∀ {n} → N n → succ₁ n ∣ zero
S∣0 {n} Nn = zero , nzero , sym (*-leftZero (succ₁ n))
-- 0 divides 0.
0∣0 : zero ∣ zero
0∣0 = zero , nzero , sym (*-leftZero zero)
-- The divisibility relation is reflexive.
∣-refl : ∀ {n} → N n → n ∣ n
∣-refl {n} Nn = [1] , 1-N , sym (*-leftIdentity Nn)
-- If x divides y and z then x divides y ∸ z.
x∣y→x∣z→x∣y∸z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * m →
o ≡ k' * m →
n ∸ o ≡ (k ∸ k') * m
x∣y→x∣z→x∣y∸z-helper Nm Nk Nk' refl refl = sym (*∸-leftDistributive Nk Nk' Nm)
x∣y→x∣z→x∣y∸z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n ∸ o
x∣y→x∣z→x∣y∸z Nm Nn No (k , Nk , h₁) (k' , Nk' , h₂) =
k ∸ k' , ∸-N Nk Nk' , x∣y→x∣z→x∣y∸z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and z then x divides y + z.
x∣y→x∣z→x∣y+z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * m →
o ≡ k' * m →
n + o ≡ (k + k') * m
x∣y→x∣z→x∣y+z-helper Nm Nk Nk' refl refl = sym (*+-leftDistributive Nk Nk' Nm)
x∣y→x∣z→x∣y+z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n + o
x∣y→x∣z→x∣y+z Nm Nn No (k , Nk , h₁) (k' , Nk' , h₂) =
k + k' , +-N Nk Nk' , x∣y→x∣z→x∣y+z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and y is positive, then x ≤ y.
x∣S→x≤S : ∀ {m n} → N m → N n → m ∣ (succ₁ n) → m ≤ succ₁ n
x∣S→x≤S {m} Nm Nn (.zero , nzero , Sn≡0*m) =
⊥-elim (0≢S (trans (sym (*-leftZero m)) (sym Sn≡0*m)))
x∣S→x≤S {m} Nm Nn (.(succ₁ k) , nsucc {k} Nk , Sn≡Sk*m) =
subst (λ t₁ → m ≤ t₁)
(sym Sn≡Sk*m)
(subst (λ t₂ → m ≤ t₂)
(sym (*-Sx k m))
(x≤x+y Nm (*-N Nk Nm)))
0∣x→x≡0 : ∀ {m} → N m → zero ∣ m → m ≡ zero
0∣x→x≡0 nzero _ = refl
0∣x→x≡0 (nsucc {m} Nm) (k , Nk , Sm≡k*0) =
⊥-elim (0≢S (trans (sym (*-leftZero k))
(trans (*-comm nzero Nk) (sym Sm≡k*0))))
| {
"alphanum_fraction": 0.4742584385,
"avg_line_length": 38.5921052632,
"ext": "agda",
"hexsha": "1ee9d99af0b2fb32ef3ef52d2ad0c8d66e0910cc",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Data/Nat/Divisibility/By0/Properties.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Data/Nat/Divisibility/By0/Properties.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Data/Nat/Divisibility/By0/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1194,
"size": 2933
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Pi
open import lib.types.Group
{-
The definition of G-sets. Thanks to Daniel Grayson.
-}
module lib.types.GroupSet {i} where
-- The right group action with respect to the group [grp].
record GsetStructure (grp : Group i) {j} (El : Type j)
(_ : is-set El) : Type (lmax i j) where
constructor gset-structure
private
module G = Group grp
module GS = GroupStructure G.group-struct
field
act : El → G.El → El
unit-r : ∀ x → act x GS.ident == x
assoc : ∀ x g₁ g₂ → act (act x g₁) g₂ == act x (GS.comp g₁ g₂)
-- The definition of a G-set. A set [El] equipped with
-- a right group action with respect to [grp].
record Gset (grp : Group i) j : Type (lsucc (lmax i j)) where
constructor gset
field
El : Type j
El-level : is-set El
gset-struct : GsetStructure grp El El-level
open GsetStructure gset-struct public
El-is-set = El-level
-- A helper function to establish equivalence between two G-sets.
-- Many data are just props and this function do the coversion for them
-- for you. You only need to show the non-trivial parts.
module _ {grp : Group i} {j} {El : Type j} {El-level : is-set El} where
private
module G = Group grp
module GS = GroupStructure G.group-struct
open GsetStructure
private
gset-structure=' : ∀ {gss₁ gss₂ : GsetStructure grp El El-level}
→ (act= : act gss₁ == act gss₂)
→ unit-r gss₁ == unit-r gss₂
[ (λ act → ∀ x → act x GS.ident == x) ↓ act= ]
→ assoc gss₁ == assoc gss₂
[ (λ act → ∀ x g₁ g₂ →
act (act x g₁) g₂ == act x (GS.comp g₁ g₂)) ↓ act= ]
→ gss₁ == gss₂
gset-structure=' {gset-structure _ _ _} {gset-structure ._ ._ ._}
idp idp idp = idp
gset-structure= : ∀ {gss₁ gss₂ : GsetStructure grp El El-level}
→ (∀ x g → act gss₁ x g == act gss₂ x g)
→ gss₁ == gss₂
gset-structure= act= = gset-structure='
(λ= λ x → λ= λ g → act= x g)
(prop-has-all-paths-↓ (Π-level λ _ → El-level _ _))
(prop-has-all-paths-↓
(Π-level λ _ → Π-level λ _ → Π-level λ _ → El-level _ _))
module _ {grp : Group i} {j : ULevel} where
private
module G = Group grp
module GS = GroupStructure G.group-struct
open Gset {grp} {j}
private
gset='' : ∀ {gs₁ gs₂ : Gset grp j}
→ (El= : El gs₁ == El gs₂)
→ (El-level : El-level gs₁ == El-level gs₂ [ is-set ↓ El= ])
→ gset-struct gs₁ == gset-struct gs₂
[ uncurry (GsetStructure grp) ↓ pair= El= El-level ]
→ gs₁ == gs₂
gset='' {gset _ _ _} {gset ._ ._ ._} idp idp idp = idp
gset=' : ∀ {gs₁ gs₂ : Gset grp j}
→ (El= : El gs₁ == El gs₂)
→ (El-level : El-level gs₁ == El-level gs₂ [ is-set ↓ El= ])
→ (∀ {x₁} {x₂} (p : x₁ == x₂ [ idf _ ↓ El= ]) g
→ act gs₁ x₁ g == act gs₂ x₂ g [ idf _ ↓ El= ])
→ gs₁ == gs₂
gset=' {gset _ _ _} {gset ._ ._ _} idp idp act= =
gset='' idp idp (gset-structure= λ x g → act= idp g)
gset= : ∀ {gs₁ gs₂ : Gset grp j}
→ (El≃ : El gs₁ ≃ El gs₂)
→ (∀ {x₁} {x₂}
→ –> El≃ x₁ == x₂
→ ∀ g → –> El≃ (act gs₁ x₁ g) == act gs₂ x₂ g)
→ gs₁ == gs₂
gset= El≃ act= =
gset='
(ua El≃)
(prop-has-all-paths-↓ is-set-is-prop)
(λ x= g → ↓-idf-ua-in El≃ $ act= (↓-idf-ua-out El≃ x=) g)
-- The Gset homomorphism.
record GsetHom {grp : Group i} {j}
(gset₁ gset₂ : Gset grp j) : Type (lmax i j) where
constructor gset-hom
open Gset
field
f : El gset₁ → El gset₂
pres-act : ∀ g x → f (act gset₁ x g) == act gset₂ (f x) g
private
gset-hom=' : ∀ {grp : Group i} {j} {gset₁ gset₂ : Gset grp j}
{gsh₁ gsh₂ : GsetHom gset₁ gset₂}
→ (f= : GsetHom.f gsh₁ == GsetHom.f gsh₂)
→ (GsetHom.pres-act gsh₁ == GsetHom.pres-act gsh₂
[ (λ f → ∀ g x → f (Gset.act gset₁ x g) == Gset.act gset₂ (f x) g) ↓ f= ] )
→ gsh₁ == gsh₂
gset-hom=' idp idp = idp
gset-hom= : ∀ {grp : Group i} {j} {gset₁ gset₂ : Gset grp j}
{gsh₁ gsh₂ : GsetHom gset₁ gset₂}
→ (∀ x → GsetHom.f gsh₁ x == GsetHom.f gsh₂ x)
→ gsh₁ == gsh₂
gset-hom= {gset₂ = gset₂} f= =
gset-hom='
(λ= f=)
(prop-has-all-paths-↓ $
Π-level λ _ → Π-level λ _ → Gset.El-level gset₂ _ _)
| {
"alphanum_fraction": 0.5423956931,
"avg_line_length": 34.828125,
"ext": "agda",
"hexsha": "d85019e6eb1ea6f14b72d0ee41112cb59f9e3131",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/types/GroupSet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/types/GroupSet.agda",
"max_line_length": 83,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/GroupSet.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1637,
"size": 4458
} |
module StratSigma where
data Sigma0 (A : Set0) (B : A -> Set0) : Set0 where
_,_ : (x : A) (y : B x) -> Sigma0 A B
_*0_ : (A : Set0)(B : Set0) -> Set0
A *0 B = Sigma0 A \_ -> B
fst0 : {A : Set0}{B : A -> Set0} -> Sigma0 A B -> A
fst0 (a , _) = a
snd0 : {A : Set0}{B : A -> Set0} (p : Sigma0 A B) -> B (fst0 p)
snd0 (a , b) = b
data Zero0 : Set0 where
data Unit0 : Set0 where
Void : Unit0
data Sigma1 (A : Set1) (B : A -> Set1) : Set1 where
_,_ : (x : A) (y : B x) -> Sigma1 A B
_*1_ : (A : Set1)(B : Set1) -> Set1
A *1 B = Sigma1 A \_ -> B
fst1 : {A : Set1}{B : A -> Set1} -> Sigma1 A B -> A
fst1 (a , _) = a
snd1 : {A : Set1}{B : A -> Set1} (p : Sigma1 A B) -> B (fst1 p)
snd1 (a , b) = b
data Zero1 : Set1 where
data Unit1 : Set1 where
Void : Unit1
data Sigma2 (A : Set2) (B : A -> Set2) : Set2 where
_,_ : (x : A) (y : B x) -> Sigma2 A B
_*2_ : (A : Set2)(B : Set2) -> Set2
A *2 B = Sigma2 A \_ -> B
fst2 : {A : Set2}{B : A -> Set2} -> Sigma2 A B -> A
fst2 (a , _) = a
snd2 : {A : Set2}{B : A -> Set2} (p : Sigma2 A B) -> B (fst2 p)
snd2 (a , b) = b
data Zero2 : Set2 where
data Unit2 : Set2 where
Void : Unit2
data Sigma3 (A : Set3) (B : A -> Set3) : Set3 where
_,_ : (x : A) (y : B x) -> Sigma3 A B
_*3_ : (A : Set3)(B : Set3) -> Set3
A *3 B = Sigma3 A \_ -> B
fst3 : {A : Set3}{B : A -> Set3} -> Sigma3 A B -> A
fst3 (a , _) = a
snd3 : {A : Set3}{B : A -> Set3} (p : Sigma3 A B) -> B (fst3 p)
snd3 (a , b) = b
data Zero3 : Set3 where
data Unit3 : Set3 where
Void : Unit3
data Sigma4 (A : Set4) (B : A -> Set4) : Set4 where
_,_ : (x : A) (y : B x) -> Sigma4 A B
_*4_ : (A : Set4)(B : Set4) -> Set4
A *4 B = Sigma4 A \_ -> B
fst4 : {A : Set4}{B : A -> Set4} -> Sigma4 A B -> A
fst4 (a , _) = a
snd4 : {A : Set4}{B : A -> Set4} (p : Sigma4 A B) -> B (fst4 p)
snd4 (a , b) = b
data Zero4 : Set4 where
data Unit4 : Set4 where
Void : Unit4
data Sigma5 (A : Set5) (B : A -> Set5) : Set5 where
_,_ : (x : A) (y : B x) -> Sigma5 A B
_*5_ : (A : Set5)(B : Set5) -> Set5
A *5 B = Sigma5 A \_ -> B
fst5 : {A : Set5}{B : A -> Set5} -> Sigma5 A B -> A
fst5 (a , _) = a
snd5 : {A : Set5}{B : A -> Set5} (p : Sigma5 A B) -> B (fst5 p)
snd5 (a , b) = b
data Zero5 : Set5 where
data Unit5 : Set5 where
Void : Unit5
data Sigma6 (A : Set6) (B : A -> Set6) : Set6 where
_,_ : (x : A) (y : B x) -> Sigma6 A B
_*6_ : (A : Set6)(B : Set6) -> Set6
A *6 B = Sigma6 A \_ -> B
fst6 : {A : Set6}{B : A -> Set6} -> Sigma6 A B -> A
fst6 (a , _) = a
snd6 : {A : Set6}{B : A -> Set6} (p : Sigma6 A B) -> B (fst6 p)
snd6 (a , b) = b
data Zero6 : Set6 where
data Unit6 : Set6 where
Void : Unit6
data Sigma7 (A : Set7) (B : A -> Set7) : Set7 where
_,_ : (x : A) (y : B x) -> Sigma7 A B
_*7_ : (A : Set7)(B : Set7) -> Set7
A *7 B = Sigma7 A \_ -> B
fst7 : {A : Set7}{B : A -> Set7} -> Sigma7 A B -> A
fst7 (a , _) = a
snd7 : {A : Set7}{B : A -> Set7} (p : Sigma7 A B) -> B (fst7 p)
snd7 (a , b) = b
data Zero7 : Set7 where
data Unit7 : Set7 where
Void : Unit7
data Sigma8 (A : Set8) (B : A -> Set8) : Set8 where
_,_ : (x : A) (y : B x) -> Sigma8 A B
_*8_ : (A : Set8)(B : Set8) -> Set8
A *8 B = Sigma8 A \_ -> B
fst8 : {A : Set8}{B : A -> Set8} -> Sigma8 A B -> A
fst8 (a , _) = a
snd8 : {A : Set8}{B : A -> Set8} (p : Sigma8 A B) -> B (fst8 p)
snd8 (a , b) = b
data Zero8 : Set8 where
data Unit8 : Set8 where
Void : Unit8
data Sigma9 (A : Set9) (B : A -> Set9) : Set9 where
_,_ : (x : A) (y : B x) -> Sigma9 A B
_*9_ : (A : Set9)(B : Set9) -> Set9
A *9 B = Sigma9 A \_ -> B
fst9 : {A : Set9}{B : A -> Set9} -> Sigma9 A B -> A
fst9 (a , _) = a
snd9 : {A : Set9}{B : A -> Set9} (p : Sigma9 A B) -> B (fst9 p)
snd9 (a , b) = b
data Zero9 : Set9 where
data Unit9 : Set9 where
Void : Unit9
data Sigma10 (A : Set10) (B : A -> Set10) : Set10 where
_,_ : (x : A) (y : B x) -> Sigma10 A B
_*10_ : (A : Set10)(B : Set10) -> Set10
A *10 B = Sigma10 A \_ -> B
fst10 : {A : Set10}{B : A -> Set10} -> Sigma10 A B -> A
fst10 (a , _) = a
snd10 : {A : Set10}{B : A -> Set10} (p : Sigma10 A B) -> B (fst10 p)
snd10 (a , b) = b
data Zero10 : Set10 where
data Unit10 : Set10 where
Void : Unit10
data Sigma11 (A : Set11) (B : A -> Set11) : Set11 where
_,_ : (x : A) (y : B x) -> Sigma11 A B
_*11_ : (A : Set11)(B : Set11) -> Set11
A *11 B = Sigma11 A \_ -> B
fst11 : {A : Set11}{B : A -> Set11} -> Sigma11 A B -> A
fst11 (a , _) = a
snd11 : {A : Set11}{B : A -> Set11} (p : Sigma11 A B) -> B (fst11 p)
snd11 (a , b) = b
data Zero11 : Set11 where
data Unit11 : Set11 where
Void : Unit11
data Sigma12 (A : Set12) (B : A -> Set12) : Set12 where
_,_ : (x : A) (y : B x) -> Sigma12 A B
_*12_ : (A : Set12)(B : Set12) -> Set12
A *12 B = Sigma12 A \_ -> B
fst12 : {A : Set12}{B : A -> Set12} -> Sigma12 A B -> A
fst12 (a , _) = a
snd12 : {A : Set12}{B : A -> Set12} (p : Sigma12 A B) -> B (fst12 p)
snd12 (a , b) = b
data Zero12 : Set12 where
data Unit12 : Set12 where
Void : Unit12
data Sigma13 (A : Set13) (B : A -> Set13) : Set13 where
_,_ : (x : A) (y : B x) -> Sigma13 A B
_*13_ : (A : Set13)(B : Set13) -> Set13
A *13 B = Sigma13 A \_ -> B
fst13 : {A : Set13}{B : A -> Set13} -> Sigma13 A B -> A
fst13 (a , _) = a
snd13 : {A : Set13}{B : A -> Set13} (p : Sigma13 A B) -> B (fst13 p)
snd13 (a , b) = b
data Zero13 : Set13 where
data Unit13 : Set13 where
Void : Unit13
data Sigma14 (A : Set14) (B : A -> Set14) : Set14 where
_,_ : (x : A) (y : B x) -> Sigma14 A B
_*14_ : (A : Set14)(B : Set14) -> Set14
A *14 B = Sigma14 A \_ -> B
fst14 : {A : Set14}{B : A -> Set14} -> Sigma14 A B -> A
fst14 (a , _) = a
snd14 : {A : Set14}{B : A -> Set14} (p : Sigma14 A B) -> B (fst14 p)
snd14 (a , b) = b
data Zero14 : Set14 where
data Unit14 : Set14 where
Void : Unit14
data Sigma15 (A : Set15) (B : A -> Set15) : Set15 where
_,_ : (x : A) (y : B x) -> Sigma15 A B
_*15_ : (A : Set15)(B : Set15) -> Set15
A *15 B = Sigma15 A \_ -> B
fst15 : {A : Set15}{B : A -> Set15} -> Sigma15 A B -> A
fst15 (a , _) = a
snd15 : {A : Set15}{B : A -> Set15} (p : Sigma15 A B) -> B (fst15 p)
snd15 (a , b) = b
data Zero15 : Set15 where
data Unit15 : Set15 where
Void : Unit15
data Sigma16 (A : Set16) (B : A -> Set16) : Set16 where
_,_ : (x : A) (y : B x) -> Sigma16 A B
_*16_ : (A : Set16)(B : Set16) -> Set16
A *16 B = Sigma16 A \_ -> B
fst16 : {A : Set16}{B : A -> Set16} -> Sigma16 A B -> A
fst16 (a , _) = a
snd16 : {A : Set16}{B : A -> Set16} (p : Sigma16 A B) -> B (fst16 p)
snd16 (a , b) = b
data Zero16 : Set16 where
data Unit16 : Set16 where
Void : Unit16
data Sigma17 (A : Set17) (B : A -> Set17) : Set17 where
_,_ : (x : A) (y : B x) -> Sigma17 A B
_*17_ : (A : Set17)(B : Set17) -> Set17
A *17 B = Sigma17 A \_ -> B
fst17 : {A : Set17}{B : A -> Set17} -> Sigma17 A B -> A
fst17 (a , _) = a
snd17 : {A : Set17}{B : A -> Set17} (p : Sigma17 A B) -> B (fst17 p)
snd17 (a , b) = b
data Zero17 : Set17 where
data Unit17 : Set17 where
Void : Unit17
data Sigma18 (A : Set18) (B : A -> Set18) : Set18 where
_,_ : (x : A) (y : B x) -> Sigma18 A B
_*18_ : (A : Set18)(B : Set18) -> Set18
A *18 B = Sigma18 A \_ -> B
fst18 : {A : Set18}{B : A -> Set18} -> Sigma18 A B -> A
fst18 (a , _) = a
snd18 : {A : Set18}{B : A -> Set18} (p : Sigma18 A B) -> B (fst18 p)
snd18 (a , b) = b
data Zero18 : Set18 where
data Unit18 : Set18 where
Void : Unit18
data Sigma19 (A : Set19) (B : A -> Set19) : Set19 where
_,_ : (x : A) (y : B x) -> Sigma19 A B
_*19_ : (A : Set19)(B : Set19) -> Set19
A *19 B = Sigma19 A \_ -> B
fst19 : {A : Set19}{B : A -> Set19} -> Sigma19 A B -> A
fst19 (a , _) = a
snd19 : {A : Set19}{B : A -> Set19} (p : Sigma19 A B) -> B (fst19 p)
snd19 (a , b) = b
data Zero19 : Set19 where
data Unit19 : Set19 where
Void : Unit19
data Sigma20 (A : Set20) (B : A -> Set20) : Set20 where
_,_ : (x : A) (y : B x) -> Sigma20 A B
_*20_ : (A : Set20)(B : Set20) -> Set20
A *20 B = Sigma20 A \_ -> B
fst20 : {A : Set20}{B : A -> Set20} -> Sigma20 A B -> A
fst20 (a , _) = a
snd20 : {A : Set20}{B : A -> Set20} (p : Sigma20 A B) -> B (fst20 p)
snd20 (a , b) = b
data Zero20 : Set20 where
data Unit20 : Set20 where
Void : Unit20
data Sigma21 (A : Set21) (B : A -> Set21) : Set21 where
_,_ : (x : A) (y : B x) -> Sigma21 A B
_*21_ : (A : Set21)(B : Set21) -> Set21
A *21 B = Sigma21 A \_ -> B
fst21 : {A : Set21}{B : A -> Set21} -> Sigma21 A B -> A
fst21 (a , _) = a
snd21 : {A : Set21}{B : A -> Set21} (p : Sigma21 A B) -> B (fst21 p)
snd21 (a , b) = b
data Zero21 : Set21 where
data Unit21 : Set21 where
Void : Unit21
data Sigma22 (A : Set22) (B : A -> Set22) : Set22 where
_,_ : (x : A) (y : B x) -> Sigma22 A B
_*22_ : (A : Set22)(B : Set22) -> Set22
A *22 B = Sigma22 A \_ -> B
fst22 : {A : Set22}{B : A -> Set22} -> Sigma22 A B -> A
fst22 (a , _) = a
snd22 : {A : Set22}{B : A -> Set22} (p : Sigma22 A B) -> B (fst22 p)
snd22 (a , b) = b
data Zero22 : Set22 where
data Unit22 : Set22 where
Void : Unit22
data Sigma23 (A : Set23) (B : A -> Set23) : Set23 where
_,_ : (x : A) (y : B x) -> Sigma23 A B
_*23_ : (A : Set23)(B : Set23) -> Set23
A *23 B = Sigma23 A \_ -> B
fst23 : {A : Set23}{B : A -> Set23} -> Sigma23 A B -> A
fst23 (a , _) = a
snd23 : {A : Set23}{B : A -> Set23} (p : Sigma23 A B) -> B (fst23 p)
snd23 (a , b) = b
data Zero23 : Set23 where
data Unit23 : Set23 where
Void : Unit23
data Sigma24 (A : Set24) (B : A -> Set24) : Set24 where
_,_ : (x : A) (y : B x) -> Sigma24 A B
_*24_ : (A : Set24)(B : Set24) -> Set24
A *24 B = Sigma24 A \_ -> B
fst24 : {A : Set24}{B : A -> Set24} -> Sigma24 A B -> A
fst24 (a , _) = a
snd24 : {A : Set24}{B : A -> Set24} (p : Sigma24 A B) -> B (fst24 p)
snd24 (a , b) = b
data Zero24 : Set24 where
data Unit24 : Set24 where
Void : Unit24
data Sigma25 (A : Set25) (B : A -> Set25) : Set25 where
_,_ : (x : A) (y : B x) -> Sigma25 A B
_*25_ : (A : Set25)(B : Set25) -> Set25
A *25 B = Sigma25 A \_ -> B
fst25 : {A : Set25}{B : A -> Set25} -> Sigma25 A B -> A
fst25 (a , _) = a
snd25 : {A : Set25}{B : A -> Set25} (p : Sigma25 A B) -> B (fst25 p)
snd25 (a , b) = b
data Zero25 : Set25 where
data Unit25 : Set25 where
Void : Unit25
data Sigma26 (A : Set26) (B : A -> Set26) : Set26 where
_,_ : (x : A) (y : B x) -> Sigma26 A B
_*26_ : (A : Set26)(B : Set26) -> Set26
A *26 B = Sigma26 A \_ -> B
fst26 : {A : Set26}{B : A -> Set26} -> Sigma26 A B -> A
fst26 (a , _) = a
snd26 : {A : Set26}{B : A -> Set26} (p : Sigma26 A B) -> B (fst26 p)
snd26 (a , b) = b
data Zero26 : Set26 where
data Unit26 : Set26 where
Void : Unit26
data Sigma27 (A : Set27) (B : A -> Set27) : Set27 where
_,_ : (x : A) (y : B x) -> Sigma27 A B
_*27_ : (A : Set27)(B : Set27) -> Set27
A *27 B = Sigma27 A \_ -> B
fst27 : {A : Set27}{B : A -> Set27} -> Sigma27 A B -> A
fst27 (a , _) = a
snd27 : {A : Set27}{B : A -> Set27} (p : Sigma27 A B) -> B (fst27 p)
snd27 (a , b) = b
data Zero27 : Set27 where
data Unit27 : Set27 where
Void : Unit27
data Sigma28 (A : Set28) (B : A -> Set28) : Set28 where
_,_ : (x : A) (y : B x) -> Sigma28 A B
_*28_ : (A : Set28)(B : Set28) -> Set28
A *28 B = Sigma28 A \_ -> B
fst28 : {A : Set28}{B : A -> Set28} -> Sigma28 A B -> A
fst28 (a , _) = a
snd28 : {A : Set28}{B : A -> Set28} (p : Sigma28 A B) -> B (fst28 p)
snd28 (a , b) = b
data Zero28 : Set28 where
data Unit28 : Set28 where
Void : Unit28
data Sigma29 (A : Set29) (B : A -> Set29) : Set29 where
_,_ : (x : A) (y : B x) -> Sigma29 A B
_*29_ : (A : Set29)(B : Set29) -> Set29
A *29 B = Sigma29 A \_ -> B
fst29 : {A : Set29}{B : A -> Set29} -> Sigma29 A B -> A
fst29 (a , _) = a
snd29 : {A : Set29}{B : A -> Set29} (p : Sigma29 A B) -> B (fst29 p)
snd29 (a , b) = b
data Zero29 : Set29 where
data Unit29 : Set29 where
Void : Unit29
data Sigma30 (A : Set30) (B : A -> Set30) : Set30 where
_,_ : (x : A) (y : B x) -> Sigma30 A B
_*30_ : (A : Set30)(B : Set30) -> Set30
A *30 B = Sigma30 A \_ -> B
fst30 : {A : Set30}{B : A -> Set30} -> Sigma30 A B -> A
fst30 (a , _) = a
snd30 : {A : Set30}{B : A -> Set30} (p : Sigma30 A B) -> B (fst30 p)
snd30 (a , b) = b
data Zero30 : Set30 where
data Unit30 : Set30 where
Void : Unit30
data Sigma31 (A : Set31) (B : A -> Set31) : Set31 where
_,_ : (x : A) (y : B x) -> Sigma31 A B
_*31_ : (A : Set31)(B : Set31) -> Set31
A *31 B = Sigma31 A \_ -> B
fst31 : {A : Set31}{B : A -> Set31} -> Sigma31 A B -> A
fst31 (a , _) = a
snd31 : {A : Set31}{B : A -> Set31} (p : Sigma31 A B) -> B (fst31 p)
snd31 (a , b) = b
data Zero31 : Set31 where
data Unit31 : Set31 where
Void : Unit31
data Sigma32 (A : Set32) (B : A -> Set32) : Set32 where
_,_ : (x : A) (y : B x) -> Sigma32 A B
_*32_ : (A : Set32)(B : Set32) -> Set32
A *32 B = Sigma32 A \_ -> B
fst32 : {A : Set32}{B : A -> Set32} -> Sigma32 A B -> A
fst32 (a , _) = a
snd32 : {A : Set32}{B : A -> Set32} (p : Sigma32 A B) -> B (fst32 p)
snd32 (a , b) = b
data Zero32 : Set32 where
data Unit32 : Set32 where
Void : Unit32
data Sigma33 (A : Set33) (B : A -> Set33) : Set33 where
_,_ : (x : A) (y : B x) -> Sigma33 A B
_*33_ : (A : Set33)(B : Set33) -> Set33
A *33 B = Sigma33 A \_ -> B
fst33 : {A : Set33}{B : A -> Set33} -> Sigma33 A B -> A
fst33 (a , _) = a
snd33 : {A : Set33}{B : A -> Set33} (p : Sigma33 A B) -> B (fst33 p)
snd33 (a , b) = b
data Zero33 : Set33 where
data Unit33 : Set33 where
Void : Unit33
data Sigma34 (A : Set34) (B : A -> Set34) : Set34 where
_,_ : (x : A) (y : B x) -> Sigma34 A B
_*34_ : (A : Set34)(B : Set34) -> Set34
A *34 B = Sigma34 A \_ -> B
fst34 : {A : Set34}{B : A -> Set34} -> Sigma34 A B -> A
fst34 (a , _) = a
snd34 : {A : Set34}{B : A -> Set34} (p : Sigma34 A B) -> B (fst34 p)
snd34 (a , b) = b
data Zero34 : Set34 where
data Unit34 : Set34 where
Void : Unit34
data Sigma35 (A : Set35) (B : A -> Set35) : Set35 where
_,_ : (x : A) (y : B x) -> Sigma35 A B
_*35_ : (A : Set35)(B : Set35) -> Set35
A *35 B = Sigma35 A \_ -> B
fst35 : {A : Set35}{B : A -> Set35} -> Sigma35 A B -> A
fst35 (a , _) = a
snd35 : {A : Set35}{B : A -> Set35} (p : Sigma35 A B) -> B (fst35 p)
snd35 (a , b) = b
data Zero35 : Set35 where
data Unit35 : Set35 where
Void : Unit35
data Sigma36 (A : Set36) (B : A -> Set36) : Set36 where
_,_ : (x : A) (y : B x) -> Sigma36 A B
_*36_ : (A : Set36)(B : Set36) -> Set36
A *36 B = Sigma36 A \_ -> B
fst36 : {A : Set36}{B : A -> Set36} -> Sigma36 A B -> A
fst36 (a , _) = a
snd36 : {A : Set36}{B : A -> Set36} (p : Sigma36 A B) -> B (fst36 p)
snd36 (a , b) = b
data Zero36 : Set36 where
data Unit36 : Set36 where
Void : Unit36
data Sigma37 (A : Set37) (B : A -> Set37) : Set37 where
_,_ : (x : A) (y : B x) -> Sigma37 A B
_*37_ : (A : Set37)(B : Set37) -> Set37
A *37 B = Sigma37 A \_ -> B
fst37 : {A : Set37}{B : A -> Set37} -> Sigma37 A B -> A
fst37 (a , _) = a
snd37 : {A : Set37}{B : A -> Set37} (p : Sigma37 A B) -> B (fst37 p)
snd37 (a , b) = b
data Zero37 : Set37 where
data Unit37 : Set37 where
Void : Unit37
data Sigma38 (A : Set38) (B : A -> Set38) : Set38 where
_,_ : (x : A) (y : B x) -> Sigma38 A B
_*38_ : (A : Set38)(B : Set38) -> Set38
A *38 B = Sigma38 A \_ -> B
fst38 : {A : Set38}{B : A -> Set38} -> Sigma38 A B -> A
fst38 (a , _) = a
snd38 : {A : Set38}{B : A -> Set38} (p : Sigma38 A B) -> B (fst38 p)
snd38 (a , b) = b
data Zero38 : Set38 where
data Unit38 : Set38 where
Void : Unit38
data Sigma39 (A : Set39) (B : A -> Set39) : Set39 where
_,_ : (x : A) (y : B x) -> Sigma39 A B
_*39_ : (A : Set39)(B : Set39) -> Set39
A *39 B = Sigma39 A \_ -> B
fst39 : {A : Set39}{B : A -> Set39} -> Sigma39 A B -> A
fst39 (a , _) = a
snd39 : {A : Set39}{B : A -> Set39} (p : Sigma39 A B) -> B (fst39 p)
snd39 (a , b) = b
data Zero39 : Set39 where
data Unit39 : Set39 where
Void : Unit39
data Sigma40 (A : Set40) (B : A -> Set40) : Set40 where
_,_ : (x : A) (y : B x) -> Sigma40 A B
_*40_ : (A : Set40)(B : Set40) -> Set40
A *40 B = Sigma40 A \_ -> B
fst40 : {A : Set40}{B : A -> Set40} -> Sigma40 A B -> A
fst40 (a , _) = a
snd40 : {A : Set40}{B : A -> Set40} (p : Sigma40 A B) -> B (fst40 p)
snd40 (a , b) = b
data Zero40 : Set40 where
data Unit40 : Set40 where
Void : Unit40
data Sigma41 (A : Set41) (B : A -> Set41) : Set41 where
_,_ : (x : A) (y : B x) -> Sigma41 A B
_*41_ : (A : Set41)(B : Set41) -> Set41
A *41 B = Sigma41 A \_ -> B
fst41 : {A : Set41}{B : A -> Set41} -> Sigma41 A B -> A
fst41 (a , _) = a
snd41 : {A : Set41}{B : A -> Set41} (p : Sigma41 A B) -> B (fst41 p)
snd41 (a , b) = b
data Zero41 : Set41 where
data Unit41 : Set41 where
Void : Unit41
data Sigma42 (A : Set42) (B : A -> Set42) : Set42 where
_,_ : (x : A) (y : B x) -> Sigma42 A B
_*42_ : (A : Set42)(B : Set42) -> Set42
A *42 B = Sigma42 A \_ -> B
fst42 : {A : Set42}{B : A -> Set42} -> Sigma42 A B -> A
fst42 (a , _) = a
snd42 : {A : Set42}{B : A -> Set42} (p : Sigma42 A B) -> B (fst42 p)
snd42 (a , b) = b
data Zero42 : Set42 where
data Unit42 : Set42 where
Void : Unit42
| {
"alphanum_fraction": 0.5227723929,
"avg_line_length": 23.3642564802,
"ext": "agda",
"hexsha": "53be2e775dfd58baff4df5726227d2ea0cb2b18f",
"lang": "Agda",
"max_forks_count": 12,
"max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z",
"max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mietek/epigram",
"max_forks_repo_path": "models/StratSigma.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mietek/epigram",
"max_issues_repo_path": "models/StratSigma.agda",
"max_line_length": 68,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mietek/epigram",
"max_stars_repo_path": "models/StratSigma.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z",
"num_tokens": 7358,
"size": 17126
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Maybe.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Empty
open import Cubical.Data.Unit
open import Cubical.Data.Nat
open import Cubical.Relation.Nullary
open import Cubical.Data.Sum
open import Cubical.Data.Maybe.Base
-- Path space of Maybe type
module MaybePath {ℓ} {A : Type ℓ} where
Cover : Maybe A → Maybe A → Type ℓ
Cover nothing nothing = Lift Unit
Cover nothing (just _) = Lift ⊥
Cover (just _) nothing = Lift ⊥
Cover (just a) (just a') = a ≡ a'
reflCode : (c : Maybe A) → Cover c c
reflCode nothing = lift tt
reflCode (just b) = refl
encode : ∀ c c' → c ≡ c' → Cover c c'
encode c _ = J (λ c' _ → Cover c c') (reflCode c)
encodeRefl : ∀ c → encode c c refl ≡ reflCode c
encodeRefl c = JRefl (λ c' _ → Cover c c') (reflCode c)
decode : ∀ c c' → Cover c c' → c ≡ c'
decode nothing nothing _ = refl
decode (just _) (just _) p = cong just p
decodeRefl : ∀ c → decode c c (reflCode c) ≡ refl
decodeRefl nothing = refl
decodeRefl (just _) = refl
decodeEncode : ∀ c c' → (p : c ≡ c') → decode c c' (encode c c' p) ≡ p
decodeEncode c _ =
J (λ c' p → decode c c' (encode c c' p) ≡ p)
(cong (decode c c) (encodeRefl c) ∙ decodeRefl c)
isOfHLevelCover : (n : ℕ)
→ isOfHLevel (suc (suc n)) A
→ ∀ c c' → isOfHLevel (suc n) (Cover c c')
isOfHLevelCover n p nothing nothing = isOfHLevelLift (suc n) (isOfHLevelUnit (suc n))
isOfHLevelCover n p nothing (just a') = isOfHLevelLift (suc n)
(subst (λ m → isOfHLevel m ⊥) (+-comm n 1) (hLevelLift n isProp⊥))
isOfHLevelCover n p (just a) nothing = isOfHLevelLift (suc n)
(subst (λ m → isOfHLevel m ⊥) (+-comm n 1) (hLevelLift n isProp⊥))
isOfHLevelCover n p (just a) (just a') = p a a'
isOfHLevelMaybe : ∀ {ℓ} (n : ℕ) {A : Type ℓ}
→ isOfHLevel (suc (suc n)) A
→ isOfHLevel (suc (suc n)) (Maybe A)
isOfHLevelMaybe n lA c c' =
retractIsOfHLevel (suc n)
(MaybePath.encode c c')
(MaybePath.decode c c')
(MaybePath.decodeEncode c c')
(MaybePath.isOfHLevelCover n lA c c')
private
variable
ℓ : Level
A : Type ℓ
fromJust-def : A → Maybe A → A
fromJust-def a nothing = a
fromJust-def _ (just a) = a
just-inj : (x y : A) → just x ≡ just y → x ≡ y
just-inj x _ eq = cong (fromJust-def x) eq
¬nothing≡just : ∀ {x : A} → ¬ (nothing ≡ just x)
¬nothing≡just {A = A} {x = x} p = lower (subst (caseMaybe (Maybe A) (Lift ⊥)) p (just x))
¬just≡nothing : ∀ {x : A} → ¬ (just x ≡ nothing)
¬just≡nothing {A = A} {x = x} p = lower (subst (caseMaybe (Lift ⊥) (Maybe A)) p (just x))
discreteMaybe : Discrete A → Discrete (Maybe A)
discreteMaybe eqA nothing nothing = yes refl
discreteMaybe eqA nothing (just a') = no ¬nothing≡just
discreteMaybe eqA (just a) nothing = no ¬just≡nothing
discreteMaybe eqA (just a) (just a') with eqA a a'
... | yes p = yes (cong just p)
... | no ¬p = no (λ p → ¬p (just-inj _ _ p))
module SumUnit where
Maybe→SumUnit : Maybe A → Unit ⊎ A
Maybe→SumUnit nothing = inl tt
Maybe→SumUnit (just a) = inr a
SumUnit→Maybe : Unit ⊎ A → Maybe A
SumUnit→Maybe (inl _) = nothing
SumUnit→Maybe (inr a) = just a
Maybe→SumUnit→Maybe : (x : Maybe A) → SumUnit→Maybe (Maybe→SumUnit x) ≡ x
Maybe→SumUnit→Maybe nothing = refl
Maybe→SumUnit→Maybe (just _) = refl
SumUnit→Maybe→SumUnit : (x : Unit ⊎ A) → Maybe→SumUnit (SumUnit→Maybe x) ≡ x
SumUnit→Maybe→SumUnit (inl _) = refl
SumUnit→Maybe→SumUnit (inr _) = refl
Maybe≡SumUnit : Maybe A ≡ Unit ⊎ A
Maybe≡SumUnit = isoToPath (iso SumUnit.Maybe→SumUnit SumUnit.SumUnit→Maybe SumUnit.SumUnit→Maybe→SumUnit SumUnit.Maybe→SumUnit→Maybe)
| {
"alphanum_fraction": 0.6481286241,
"avg_line_length": 33.875,
"ext": "agda",
"hexsha": "3f09b9c13ea55d501a46c34681bfe961c049191c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Data/Maybe/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Data/Maybe/Properties.agda",
"max_line_length": 133,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Data/Maybe/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1397,
"size": 3794
} |
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Weakening {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening as T hiding (wk; wkEq; wkTerm; wkEqTerm)
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Tools.Product
import Tools.PropositionalEquality as PE
import Data.Nat as Nat
-- Weakening of neutrals in WHNF
wkTermNe : ∀ {ρ Γ Δ k A rA} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Γ ⊩neNf k ∷ A ^ rA → Δ ⊩neNf U.wk ρ k ∷ U.wk ρ A ^ rA
wkTermNe {ρ} [ρ] ⊢Δ (neNfₜ neK ⊢k k≡k) =
neNfₜ (wkNeutral ρ neK) (T.wkTerm [ρ] ⊢Δ ⊢k) (~-wk [ρ] ⊢Δ k≡k)
wkEqTermNe : ∀ {ρ Γ Δ k k′ A rA} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Γ ⊩neNf k ≡ k′ ∷ A ^ rA → Δ ⊩neNf U.wk ρ k ≡ U.wk ρ k′ ∷ U.wk ρ A ^ rA
wkEqTermNe {ρ} [ρ] ⊢Δ (neNfₜ₌ neK neM k≡m) =
neNfₜ₌ (wkNeutral ρ neK) (wkNeutral ρ neM) (~-wk [ρ] ⊢Δ k≡m)
-- Weakening of reducible natural numbers
mutual
wkTermℕ : ∀ {ρ Γ Δ n} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Γ ⊩ℕ n ∷ℕ → Δ ⊩ℕ U.wk ρ n ∷ℕ
wkTermℕ {ρ} [ρ] ⊢Δ (ℕₜ n d n≡n prop) =
ℕₜ (U.wk ρ n) (wkRed:*:Term [ρ] ⊢Δ d)
(≅ₜ-wk [ρ] ⊢Δ n≡n)
(wkNatural-prop [ρ] ⊢Δ prop)
wkNatural-prop : ∀ {ρ Γ Δ n} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Natural-prop Γ n
→ Natural-prop Δ (U.wk ρ n)
wkNatural-prop ρ ⊢Δ (sucᵣ n) = sucᵣ (wkTermℕ ρ ⊢Δ n)
wkNatural-prop ρ ⊢Δ zeroᵣ = zeroᵣ
wkNatural-prop ρ ⊢Δ (ne nf) = ne (wkTermNe ρ ⊢Δ nf)
mutual
wkEqTermℕ : ∀ {ρ Γ Δ t u} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Γ ⊩ℕ t ≡ u ∷ℕ
→ Δ ⊩ℕ U.wk ρ t ≡ U.wk ρ u ∷ℕ
wkEqTermℕ {ρ} [ρ] ⊢Δ (ℕₜ₌ k k′ d d′ t≡u prop) =
ℕₜ₌ (U.wk ρ k) (U.wk ρ k′) (wkRed:*:Term [ρ] ⊢Δ d)
(wkRed:*:Term [ρ] ⊢Δ d′) (≅ₜ-wk [ρ] ⊢Δ t≡u)
(wk[Natural]-prop [ρ] ⊢Δ prop)
wk[Natural]-prop : ∀ {ρ Γ Δ n n′} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ [Natural]-prop Γ n n′
→ [Natural]-prop Δ (U.wk ρ n) (U.wk ρ n′)
wk[Natural]-prop ρ ⊢Δ (sucᵣ [n≡n′]) = sucᵣ (wkEqTermℕ ρ ⊢Δ [n≡n′])
wk[Natural]-prop ρ ⊢Δ zeroᵣ = zeroᵣ
wk[Natural]-prop ρ ⊢Δ (ne x) = ne (wkEqTermNe ρ ⊢Δ x)
-- Empty
wkTermEmpty : ∀ {ρ Γ Δ l n} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Γ ⊩Empty n ∷Empty^ l → Δ ⊩Empty U.wk ρ n ∷Empty^ l
wkTermEmpty {ρ} [ρ] ⊢Δ (Emptyₜ (ne d)) = Emptyₜ (ne (T.wkTerm [ρ] ⊢Δ d))
wk[Empty]-prop : ∀ {ρ Γ Δ n l n′} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ [Empty]-prop Γ n n′ l
→ [Empty]-prop Δ (U.wk ρ n) (U.wk ρ n′) l
wk[Empty]-prop {ρ} [ρ] ⊢Δ (ne d d') = ne (T.wkTerm [ρ] ⊢Δ d) (T.wkTerm [ρ] ⊢Δ d')
wkEqTermEmpty : ∀ {ρ Γ Δ t u l } → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ)
→ Γ ⊩Empty t ≡ u ∷Empty^ l
→ Δ ⊩Empty U.wk ρ t ≡ U.wk ρ u ∷Empty^ l
wkEqTermEmpty {ρ} [ρ] ⊢Δ (Emptyₜ₌ (ne d d')) = Emptyₜ₌ (ne (T.wkTerm [ρ] ⊢Δ d) (T.wkTerm [ρ] ⊢Δ d'))
-- Weakening of the logical relation
wk : ∀ {ρ Γ Δ A rA l} → ρ ∷ Δ ⊆ Γ → ⊢ Δ → Γ ⊩⟨ l ⟩ A ^ rA → Δ ⊩⟨ l ⟩ U.wk ρ A ^ rA
wk ρ ⊢Δ (Uᵣ (Uᵣ r l′ l< eq d)) = Uᵣ (Uᵣ r l′ l< eq (wkRed:*: ρ ⊢Δ d))
wk ρ ⊢Δ (ℕᵣ D) = ℕᵣ (wkRed:*: ρ ⊢Δ D)
wk ρ ⊢Δ (Emptyᵣ D) = Emptyᵣ (wkRed:*: ρ ⊢Δ D)
wk {ρ} [ρ] ⊢Δ (ne′ K D neK K≡K) =
ne′ (U.wk ρ K) (wkRed:*: [ρ] ⊢Δ D) (wkNeutral ρ neK) (~-wk [ρ] ⊢Δ K≡K)
wk {ρ} {Γ} {Δ} {A} {rA} {l} [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) =
let ⊢ρF = T.wk [ρ] ⊢Δ ⊢F
iF = [ rF , ι lF ]
iG = [ TypeInfo.r rA , ι lG ]
[F]′ : ∀ {ρ ρ′ E} ([ρ] : ρ ∷ E ⊆ Δ) ([ρ′] : ρ′ ∷ Δ ⊆ Γ) (⊢E : ⊢ E)
→ E ⊩⟨ l ⟩ U.wk ρ (U.wk ρ′ F) ^ iF
[F]′ {ρ} {ρ′} [ρ] [ρ′] ⊢E = irrelevance′
(PE.sym (wk-comp ρ ρ′ F))
([F] ([ρ] •ₜ [ρ′]) ⊢E)
[a]′ : ∀ {ρ ρ′ E a} ([ρ] : ρ ∷ E ⊆ Δ) ([ρ′] : ρ′ ∷ Δ ⊆ Γ) (⊢E : ⊢ E)
([a] : E ⊩⟨ l ⟩ a ∷ U.wk ρ (U.wk ρ′ F) ^ iF / [F]′ [ρ] [ρ′] ⊢E)
→ E ⊩⟨ l ⟩ a ∷ U.wk (ρ • ρ′) F ^ iF / [F] ([ρ] •ₜ [ρ′]) ⊢E
[a]′ {ρ} {ρ′} [ρ] [ρ′] ⊢E [a] = irrelevanceTerm′ (wk-comp ρ ρ′ F) PE.refl PE.refl
([F]′ [ρ] [ρ′] ⊢E) ([F] ([ρ] •ₜ [ρ′]) ⊢E) [a]
[G]′ : ∀ {ρ ρ′ E a} ([ρ] : ρ ∷ E ⊆ Δ) ([ρ′] : ρ′ ∷ Δ ⊆ Γ) (⊢E : ⊢ E)
([a] : E ⊩⟨ l ⟩ a ∷ U.wk ρ (U.wk ρ′ F) ^ iF / [F]′ [ρ] [ρ′] ⊢E)
→ E ⊩⟨ l ⟩ U.wk (lift (ρ • ρ′)) G [ a ] ^ iG
[G]′ η η′ ⊢E [a] = [G] (η •ₜ η′) ⊢E ([a]′ η η′ ⊢E [a])
in Πᵣ′ rF lF lG lF≤ lG≤ (U.wk ρ F) (U.wk (lift ρ) G) (T.wkRed:*: [ρ] ⊢Δ D) ⊢ρF
(T.wk (lift [ρ]) (⊢Δ ∙ ⊢ρF) ⊢G)
(≅-wk [ρ] ⊢Δ A≡A)
(λ {ρ₁} [ρ₁] ⊢Δ₁ → irrelevance′ (PE.sym (wk-comp ρ₁ ρ F))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] → irrelevance′ (wk-comp-subst ρ₁ ρ G)
([G]′ [ρ₁] [ρ] ⊢Δ₁ [a]))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] [b] [a≡b] →
let [a≡b]′ = irrelevanceEqTerm′ (wk-comp ρ₁ ρ F) PE.refl PE.refl
([F]′ [ρ₁] [ρ] ⊢Δ₁)
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁)
[a≡b]
in irrelevanceEq″ (wk-comp-subst ρ₁ ρ G)
(wk-comp-subst ρ₁ ρ G) PE.refl PE.refl
([G]′ [ρ₁] [ρ] ⊢Δ₁ [a])
(irrelevance′
(wk-comp-subst ρ₁ ρ G)
([G]′ [ρ₁] [ρ] ⊢Δ₁ [a]))
(G-ext ([ρ₁] •ₜ [ρ]) ⊢Δ₁
([a]′ [ρ₁] [ρ] ⊢Δ₁ [a])
([a]′ [ρ₁] [ρ] ⊢Δ₁ [b])
[a≡b]′))
wk {ρ} {Γ} {Δ} {A} {rA} {l} [ρ] ⊢Δ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) =
let ⊢ρF = T.wk [ρ] ⊢Δ ⊢F
iF = [ % , TypeInfo.l rA ]
[F]′ : ∀ {ρ ρ′ E} ([ρ] : ρ ∷ E ⊆ Δ) ([ρ′] : ρ′ ∷ Δ ⊆ Γ) (⊢E : ⊢ E)
→ E ⊩⟨ l ⟩ U.wk ρ (U.wk ρ′ F) ^ iF
[F]′ {ρ} {ρ′} [ρ] [ρ′] ⊢E = irrelevance′
(PE.sym (wk-comp ρ ρ′ F))
([F] ([ρ] •ₜ [ρ′]) ⊢E)
[a]′ : ∀ {ρ ρ′ E a} ([ρ] : ρ ∷ E ⊆ Δ) ([ρ′] : ρ′ ∷ Δ ⊆ Γ) (⊢E : ⊢ E)
([a] : E ⊩⟨ l ⟩ a ∷ U.wk ρ (U.wk ρ′ F) ^ iF / [F]′ [ρ] [ρ′] ⊢E)
→ E ⊩⟨ l ⟩ a ∷ U.wk (ρ • ρ′) F ^ iF / [F] ([ρ] •ₜ [ρ′]) ⊢E
[a]′ {ρ} {ρ′} [ρ] [ρ′] ⊢E [a] = irrelevanceTerm′ (wk-comp ρ ρ′ F) PE.refl PE.refl
([F]′ [ρ] [ρ′] ⊢E) ([F] ([ρ] •ₜ [ρ′]) ⊢E) [a]
[G]′ : ∀ {ρ ρ′ E a} ([ρ] : ρ ∷ E ⊆ Δ) ([ρ′] : ρ′ ∷ Δ ⊆ Γ) (⊢E : ⊢ E)
([a] : E ⊩⟨ l ⟩ a ∷ U.wk ρ (U.wk ρ′ F) ^ iF / [F]′ [ρ] [ρ′] ⊢E)
→ E ⊩⟨ l ⟩ U.wk (lift (ρ • ρ′)) G [ a ] ^ rA
[G]′ η η′ ⊢E [a] = [G] (η •ₜ η′) ⊢E ([a]′ η η′ ⊢E [a])
in ∃ᵣ′ (U.wk ρ F) (U.wk (lift ρ) G) (T.wkRed:*: [ρ] ⊢Δ D) ⊢ρF
(T.wk (lift [ρ]) (⊢Δ ∙ ⊢ρF) ⊢G)
(≅-wk [ρ] ⊢Δ A≡A)
(λ {ρ₁} [ρ₁] ⊢Δ₁ → irrelevance′ (PE.sym (wk-comp ρ₁ ρ F))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] → irrelevance′ (wk-comp-subst ρ₁ ρ G)
([G]′ [ρ₁] [ρ] ⊢Δ₁ [a]))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] [b] [a≡b] →
let [a≡b]′ = irrelevanceEqTerm′ (wk-comp ρ₁ ρ F) PE.refl PE.refl
([F]′ [ρ₁] [ρ] ⊢Δ₁)
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁)
[a≡b]
in irrelevanceEq″ (wk-comp-subst ρ₁ ρ G)
(wk-comp-subst ρ₁ ρ G) PE.refl PE.refl
([G]′ [ρ₁] [ρ] ⊢Δ₁ [a])
(irrelevance′
(wk-comp-subst ρ₁ ρ G)
([G]′ [ρ₁] [ρ] ⊢Δ₁ [a]))
(G-ext ([ρ₁] •ₜ [ρ]) ⊢Δ₁
([a]′ [ρ₁] [ρ] ⊢Δ₁ [a])
([a]′ [ρ₁] [ρ] ⊢Δ₁ [b])
[a≡b]′))
wk {l = ι ¹} ρ ⊢Δ (emb l< X) = emb l< (wk ρ ⊢Δ X)
wk {l = ∞} ρ ⊢Δ (emb l< X) = emb l< (wk ρ ⊢Δ X)
wkEq : ∀ {ρ Γ Δ A B r l} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
([A] : Γ ⊩⟨ l ⟩ A ^ r)
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Δ ⊩⟨ l ⟩ U.wk ρ A ≡ U.wk ρ B ^ r / wk [ρ] ⊢Δ [A]
wkEq ρ ⊢Δ (Uᵣ (Uᵣ r l′ l< eq d)) D = wkRed* ρ ⊢Δ D
wkEq ρ ⊢Δ (ℕᵣ D) A≡B = wkRed* ρ ⊢Δ A≡B
wkEq ρ ⊢Δ (Emptyᵣ D) A≡B = wkRed* ρ ⊢Δ A≡B
wkEq {ρ} [ρ] ⊢Δ (ne′ _ _ _ _) (ne₌ M D′ neM K≡M) =
ne₌ (U.wk ρ M) (wkRed:*: [ρ] ⊢Δ D′)
(wkNeutral ρ neM) (~-wk [ρ] ⊢Δ K≡M)
wkEq {ρ} [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
Π₌ (U.wk ρ F′) (U.wk (lift ρ) G′) (T.wkRed* [ρ] ⊢Δ D′) (≅-wk [ρ] ⊢Δ A≡B)
(λ {ρ₁} [ρ₁] ⊢Δ₁ → irrelevanceEq″ (PE.sym (wk-comp ρ₁ ρ F))
(PE.sym (wk-comp ρ₁ ρ F′)) PE.refl PE.refl
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁)
(irrelevance′ (PE.sym (wk-comp ρ₁ ρ F))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
([F≡F′] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] →
let [a]′ = irrelevanceTerm′ (wk-comp ρ₁ ρ F) PE.refl PE.refl
(irrelevance′ (PE.sym (wk-comp ρ₁ ρ F))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁) [a]
in irrelevanceEq″ (wk-comp-subst ρ₁ ρ G)
(wk-comp-subst ρ₁ ρ G′) PE.refl PE.refl
([G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′)
(irrelevance′ (wk-comp-subst ρ₁ ρ G)
([G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′))
([G≡G′] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′))
wkEq {ρ} [ρ] ⊢Δ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
∃₌ (U.wk ρ F′) (U.wk (lift ρ) G′) (T.wkRed* [ρ] ⊢Δ D′) (≅-wk [ρ] ⊢Δ A≡B)
(λ {ρ₁} [ρ₁] ⊢Δ₁ → irrelevanceEq″ (PE.sym (wk-comp ρ₁ ρ F))
(PE.sym (wk-comp ρ₁ ρ F′)) PE.refl PE.refl
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁)
(irrelevance′ (PE.sym (wk-comp ρ₁ ρ F))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
([F≡F′] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] →
let [a]′ = irrelevanceTerm′ (wk-comp ρ₁ ρ F) PE.refl PE.refl
(irrelevance′ (PE.sym (wk-comp ρ₁ ρ F))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁))
([F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁) [a]
in irrelevanceEq″ (wk-comp-subst ρ₁ ρ G)
(wk-comp-subst ρ₁ ρ G′) PE.refl PE.refl
([G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′)
(irrelevance′ (wk-comp-subst ρ₁ ρ G)
([G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′))
([G≡G′] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′))
wkEq {l = ι ¹} ρ ⊢Δ (emb l< X) A≡B = wkEq ρ ⊢Δ X A≡B
wkEq {l = ∞} ρ ⊢Δ (emb l< X) A≡B = wkEq ρ ⊢Δ X A≡B
wkTerm : ∀ {ρ Γ Δ A t r l} ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
([A] : Γ ⊩⟨ l ⟩ A ^ r)
→ Γ ⊩⟨ l ⟩ t ∷ A ^ r / [A]
→ Δ ⊩⟨ l ⟩ U.wk ρ t ∷ U.wk ρ A ^ r / wk [ρ] ⊢Δ [A]
wkTerm {ρ} {Δ = Δ} {t = t} {l = ι ¹} [ρ] ⊢Δ (Uᵣ (Uᵣ r ⁰ l< eq d)) (Uₜ K d₁ typeK K≡K [t]) =
let
-- this code is a bit of a mess tbh
-- it is mostly about using irrelevance back and forth between proofs of
-- reducibility using U.wk ρ′ (U.wk ρ t) and proofs using U.wk (ρ′ • ρ) t
[t]′ = λ {ρ′} {Δ′} [ρ′] (⊢Δ′ : ⊢ Δ′) →
irrelevance′ (PE.sym (wk-comp ρ′ ρ t)) ([t] ([ρ′] •ₜ [ρ]) ⊢Δ′)
[t]′_to_[t] = λ {ρ′} {Δ′} {a} [ρ′] (⊢Δ′ : ⊢ Δ′)
([a] : Δ′ ⊩⟨ ι ⁰ ⟩ a ∷ U.wk ρ′ (U.wk ρ t) ^ [ r , ι ⁰ ] / [t]′ [ρ′] ⊢Δ′) →
irrelevanceTerm′ (wk-comp ρ′ ρ t) PE.refl PE.refl ([t]′ [ρ′] ⊢Δ′) ([t] ([ρ′] •ₜ [ρ]) ⊢Δ′) [a]
[t]′_to_[t]_eq = λ {ρ′} {Δ′} {a} {a′} [ρ′] (⊢Δ′ : ⊢ Δ′)
(a≡a′ : Δ′ ⊩⟨ ι ⁰ ⟩ a ≡ a′ ∷ U.wk ρ′ (U.wk ρ t) ^ [ r , ι ⁰ ] / [t]′ [ρ′] ⊢Δ′) →
irrelevanceEqTerm′ (wk-comp ρ′ ρ t) PE.refl PE.refl ([t]′ [ρ′] ⊢Δ′) ([t] ([ρ′] •ₜ [ρ]) ⊢Δ′) a≡a′
[t]′_to_[t]_id = λ {ρ′} {Δ′} {e} {B} [e] →
(PE.subst (λ X → Δ′ ⊢ e ∷ Id (U ⁰) X B ^ [ % , ι ¹ ]) (wk-comp ρ′ ρ t) [e])
in
Uₜ (U.wk ρ K) (wkRed:*:Term [ρ] ⊢Δ d₁) (wkType ρ typeK) (≅ₜ-wk [ρ] ⊢Δ K≡K) [t]′
-- this is a duplicate of the above code (because we need logRelRec to compute)
-- surely there is a way to avoid this redundancy
wkTerm {ρ} {Δ = Δ} {t = t} {l = ∞} [ρ] ⊢Δ (Uᵣ (Uᵣ r ¹ l< eq d)) (Uₜ K d₁ typeK K≡K [t]) =
let
[t]′ = λ {ρ′} {Δ′} [ρ′] (⊢Δ′ : ⊢ Δ′) →
irrelevance′ (PE.sym (wk-comp ρ′ ρ t)) ([t] ([ρ′] •ₜ [ρ]) ⊢Δ′)
[t]′_to_[t] = λ {ρ′} {Δ′} {a} [ρ′] (⊢Δ′ : ⊢ Δ′)
([a] : Δ′ ⊩⟨ ι ¹ ⟩ a ∷ U.wk ρ′ (U.wk ρ t) ^ [ r , ι ¹ ] / [t]′ [ρ′] ⊢Δ′) →
irrelevanceTerm′ (wk-comp ρ′ ρ t) PE.refl PE.refl ([t]′ [ρ′] ⊢Δ′) ([t] ([ρ′] •ₜ [ρ]) ⊢Δ′) [a]
[t]′_to_[t]_eq = λ {ρ′} {Δ′} {a} {a′} [ρ′] (⊢Δ′ : ⊢ Δ′)
(a≡a′ : Δ′ ⊩⟨ ι ¹ ⟩ a ≡ a′ ∷ U.wk ρ′ (U.wk ρ t) ^ [ r , ι ¹ ] / [t]′ [ρ′] ⊢Δ′) →
irrelevanceEqTerm′ (wk-comp ρ′ ρ t) PE.refl PE.refl ([t]′ [ρ′] ⊢Δ′) ([t] ([ρ′] •ₜ [ρ]) ⊢Δ′) a≡a′
[t]′_to_[t]_id = λ {ρ′} {Δ′} {e} {B} [e] →
(PE.subst (λ X → Δ′ ⊢ e ∷ Id (U ⁰) X B ^ [ % , ι ¹ ]) (wk-comp ρ′ ρ t) [e])
in
Uₜ (U.wk ρ K) (wkRed:*:Term [ρ] ⊢Δ d₁) (wkType ρ typeK) (≅ₜ-wk [ρ] ⊢Δ K≡K) [t]′
wkTerm ρ ⊢Δ (ℕᵣ D) [t] = wkTermℕ ρ ⊢Δ [t]
wkTerm ρ ⊢Δ (Emptyᵣ D) [t] = wkTermEmpty ρ ⊢Δ [t]
wkTerm {ρ} {r = [ ! , l′ ]} [ρ] ⊢Δ (ne′ K D neK K≡K) (neₜ k d nf) =
neₜ (U.wk ρ k) (wkRed:*:Term [ρ] ⊢Δ d) (wkTermNe [ρ] ⊢Δ nf)
wkTerm {ρ} {r = [ % , l′ ]} [ρ] ⊢Δ (ne′ K D neK K≡K) (neₜ d) = neₜ ( T.wkTerm [ρ] ⊢Δ d)
wkTerm {ρ} {r = [ ! , l′ ]} [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =
Πₜ (U.wk ρ f) (wkRed:*:Term [ρ] ⊢Δ d) (wkFunction ρ funcF)
(≅ₜ-wk [ρ] ⊢Δ f≡f)
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] [b] [a≡b] →
let F-compEq = wk-comp ρ₁ ρ F
G-compEq = wk-comp-subst ρ₁ ρ G
[F]₁ = [F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁
[F]₂ = irrelevance′ (PE.sym (wk-comp ρ₁ ρ F)) [F]₁
[a]′ = irrelevanceTerm′ F-compEq PE.refl PE.refl [F]₂ [F]₁ [a]
[b]′ = irrelevanceTerm′ F-compEq PE.refl PE.refl [F]₂ [F]₁ [b]
[G]₁ = [G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′
[G]₂ = irrelevance′ G-compEq [G]₁
[a≡b]′ = irrelevanceEqTerm′ F-compEq PE.refl PE.refl [F]₂ [F]₁ [a≡b]
in irrelevanceEqTerm″ PE.refl PE.refl (PE.cong (λ x → x ∘ _ ^ _ ) (PE.sym (wk-comp ρ₁ ρ _)))
(PE.cong (λ x → x ∘ _ ^ _) (PE.sym (wk-comp ρ₁ ρ _)))
G-compEq
[G]₁ [G]₂
([f] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′ [b]′ [a≡b]′))
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] →
let [F]₁ = [F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁
[F]₂ = irrelevance′ (PE.sym (wk-comp ρ₁ ρ F)) [F]₁
[a]′ = irrelevanceTerm′ (wk-comp ρ₁ ρ F) PE.refl PE.refl [F]₂ [F]₁ [a]
[G]₁ = [G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′
[G]₂ = irrelevance′ (wk-comp-subst ρ₁ ρ G) [G]₁
in irrelevanceTerm″ (wk-comp-subst ρ₁ ρ G) PE.refl PE.refl
(PE.cong (λ x → x ∘ _ ^ _ ) (PE.sym (wk-comp ρ₁ ρ _)))
[G]₁ [G]₂ ([f]₁ ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′))
wkTerm {ρ} {r = [ % , l′ ]} [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) d = T.wkTerm [ρ] ⊢Δ d
wkTerm {ρ} [ρ] ⊢Δ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) d = T.wkTerm [ρ] ⊢Δ d
wkTerm {l = ι ¹} ρ ⊢Δ (emb l< X) t = wkTerm ρ ⊢Δ X t
wkTerm {l = ∞} ρ ⊢Δ (emb l< X) t = wkTerm ρ ⊢Δ X t
wkEqTerm : ∀ {ρ Γ Δ A t u r l} ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
([A] : Γ ⊩⟨ l ⟩ A ^ r)
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ r / [A]
→ Δ ⊩⟨ l ⟩ U.wk ρ t ≡ U.wk ρ u ∷ U.wk ρ A ^ r / wk [ρ] ⊢Δ [A]
wkEqTerm {ρ} {Γ} {Δ} {A} {t} {u} {r} {l = ι ¹} [ρ] ⊢Δ (Uᵣ (Uᵣ ti ⁰ l< eq d)) (Uₜ₌ [t] [u] A≡B [t≡u]) =
let
[t]′ = λ {ρ′} {Δ′} ([ρ′] : ρ′ ∷ Δ′ ⊆ Δ) (⊢Δ′ : ⊢ Δ′) →
irrelevance′ (PE.sym (wk-comp ρ′ ρ t)) (LogRel._⊩¹U_∷_^_/_.[t] [t] ([ρ′] •ₜ [ρ]) ⊢Δ′)
[t]″ = λ {ρ′} {Δ′} ([ρ′] : ρ′ ∷ Δ′ ⊆ Δ) (⊢Δ′ : ⊢ Δ′) →
LogRel._⊩¹U_∷_^_/_.[t] [t] ([ρ′] •ₜ [ρ]) ⊢Δ′
[t]′_to_[t]″ = λ {ρ′} {Δ′} {a} [ρ′] (⊢Δ′ : ⊢ Δ′)
([a] : Δ′ ⊩⟨ ι ⁰ ⟩ a ∷ U.wk ρ′ (U.wk ρ t) ^ [ ti , ι ⁰ ] / [t]′ [ρ′] ⊢Δ′) →
(irrelevanceTerm′ (wk-comp ρ′ ρ t) PE.refl PE.refl ([t]′ [ρ′] ⊢Δ′) ([t]″ [ρ′] ⊢Δ′) [a])
[t≡u]′ = λ {ρ′} {Δ′} [ρ′] (⊢Δ′ : ⊢ Δ′) →
irrelevanceEq″ (PE.sym (wk-comp ρ′ ρ t)) (PE.sym (wk-comp ρ′ ρ u)) PE.refl PE.refl ([t]″ [ρ′] ⊢Δ′)
((LogRel._⊩¹U_∷_^_/_.[t] (wkTerm [ρ] ⊢Δ (Uᵣ (Uᵣ ti ⁰ l< eq d)) [t]) [ρ′] ⊢Δ′))
([t≡u] ([ρ′] •ₜ [ρ]) ⊢Δ′)
in
Uₜ₌ (wkTerm [ρ] ⊢Δ (Uᵣ (Uᵣ ti ⁰ l< eq d)) [t]) (wkTerm [ρ] ⊢Δ (Uᵣ (Uᵣ ti ⁰ l< eq d)) [u])
(≅ₜ-wk [ρ] ⊢Δ A≡B) [t≡u]′
-- this is a duplicate of the above code (because we need logRelRec to compute)
-- surely there is a way to avoid this redundancy
wkEqTerm {ρ} {Γ} {Δ} {A} {t} {u} {r} {l = ∞} [ρ] ⊢Δ (Uᵣ (Uᵣ ti ¹ l< eq d)) (Uₜ₌ [t] [u] A≡B [t≡u]) =
let
[t]′ = λ {ρ′} {Δ′} ([ρ′] : ρ′ ∷ Δ′ ⊆ Δ) (⊢Δ′ : ⊢ Δ′) →
irrelevance′ (PE.sym (wk-comp ρ′ ρ t)) (LogRel._⊩¹U_∷_^_/_.[t] [t] ([ρ′] •ₜ [ρ]) ⊢Δ′)
[t]″ = λ {ρ′} {Δ′} ([ρ′] : ρ′ ∷ Δ′ ⊆ Δ) (⊢Δ′ : ⊢ Δ′) →
LogRel._⊩¹U_∷_^_/_.[t] [t] ([ρ′] •ₜ [ρ]) ⊢Δ′
[t]′_to_[t]″ = λ {ρ′} {Δ′} {a} [ρ′] (⊢Δ′ : ⊢ Δ′)
([a] : Δ′ ⊩⟨ ι ¹ ⟩ a ∷ U.wk ρ′ (U.wk ρ t) ^ [ ti , ι ¹ ] / [t]′ [ρ′] ⊢Δ′) →
(irrelevanceTerm′ (wk-comp ρ′ ρ t) PE.refl PE.refl ([t]′ [ρ′] ⊢Δ′) ([t]″ [ρ′] ⊢Δ′) [a])
[t≡u]′ = λ {ρ′} {Δ′} [ρ′] (⊢Δ′ : ⊢ Δ′) →
irrelevanceEq″ (PE.sym (wk-comp ρ′ ρ t)) (PE.sym (wk-comp ρ′ ρ u)) PE.refl PE.refl ([t]″ [ρ′] ⊢Δ′)
((LogRel._⊩¹U_∷_^_/_.[t] (wkTerm [ρ] ⊢Δ (Uᵣ (Uᵣ ti ¹ l< eq d)) [t]) [ρ′] ⊢Δ′))
([t≡u] ([ρ′] •ₜ [ρ]) ⊢Δ′)
in
Uₜ₌ (wkTerm [ρ] ⊢Δ (Uᵣ (Uᵣ ti ¹ l< eq d)) [t]) (wkTerm [ρ] ⊢Δ (Uᵣ (Uᵣ ti ¹ l< eq d)) [u])
(≅ₜ-wk [ρ] ⊢Δ A≡B) [t≡u]′
wkEqTerm ρ ⊢Δ (ℕᵣ D) [t≡u] = wkEqTermℕ ρ ⊢Δ [t≡u]
wkEqTerm ρ ⊢Δ (Emptyᵣ D) [t≡u] = wkEqTermEmpty ρ ⊢Δ [t≡u]
wkEqTerm {ρ} {r = [ ! , l′ ]} [ρ] ⊢Δ (ne′ K D neK K≡K) (neₜ₌ k m d d′ nf) =
neₜ₌ (U.wk ρ k) (U.wk ρ m)
(wkRed:*:Term [ρ] ⊢Δ d) (wkRed:*:Term [ρ] ⊢Δ d′)
(wkEqTermNe [ρ] ⊢Δ nf)
wkEqTerm {ρ} {r = [ % , l′ ]}[ρ] ⊢Δ (ne′ K D neK K≡K) (neₜ₌ d d′) = neₜ₌ (T.wkTerm [ρ] ⊢Δ d) (T.wkTerm [ρ] ⊢Δ d′)
wkEqTerm {ρ} {r = [ ! , l′ ]} [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πₜ₌ f g d d′ funcF funcG f≡g [t] [u] [f≡g]) =
let [A] = Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext
in Πₜ₌ (U.wk ρ f) (U.wk ρ g) (wkRed:*:Term [ρ] ⊢Δ d) (wkRed:*:Term [ρ] ⊢Δ d′)
(wkFunction ρ funcF) (wkFunction ρ funcG)
(≅ₜ-wk [ρ] ⊢Δ f≡g) (wkTerm [ρ] ⊢Δ [A] [t]) (wkTerm [ρ] ⊢Δ [A] [u])
(λ {ρ₁} [ρ₁] ⊢Δ₁ [a] →
let [F]₁ = [F] ([ρ₁] •ₜ [ρ]) ⊢Δ₁
[F]₂ = irrelevance′ (PE.sym (wk-comp ρ₁ ρ F)) [F]₁
[a]′ = irrelevanceTerm′ (wk-comp ρ₁ ρ F) PE.refl PE.refl [F]₂ [F]₁ [a]
[G]₁ = [G] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′
[G]₂ = irrelevance′ (wk-comp-subst ρ₁ ρ G) [G]₁
in irrelevanceEqTerm″ PE.refl PE.refl (PE.cong (λ y → y ∘ _ ^ _) (PE.sym (wk-comp ρ₁ ρ _)))
(PE.cong (λ y → y ∘ _ ^ _) (PE.sym (wk-comp ρ₁ ρ _)))
(wk-comp-subst ρ₁ ρ G)
[G]₁ [G]₂
([f≡g] ([ρ₁] •ₜ [ρ]) ⊢Δ₁ [a]′))
wkEqTerm {ρ} {r = [ % , l′ ]} [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(d , d′) = T.wkTerm [ρ] ⊢Δ d , T.wkTerm [ρ] ⊢Δ d′
wkEqTerm {ρ} {r = [ % , l′ ]} [ρ] ⊢Δ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(d , d′) = T.wkTerm [ρ] ⊢Δ d , T.wkTerm [ρ] ⊢Δ d′
wkEqTerm {l = ι ¹} ρ ⊢Δ (emb l< X) t≡u = wkEqTerm ρ ⊢Δ X t≡u
wkEqTerm {l = ∞} ρ ⊢Δ (emb l< X) t≡u = wkEqTerm ρ ⊢Δ X t≡u
| {
"alphanum_fraction": 0.3715528319,
"avg_line_length": 55.1335149864,
"ext": "agda",
"hexsha": "9d9bbeb553f0e139e2086b5d6aae3b9655bace68",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Weakening.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Weakening.agda",
"max_line_length": 117,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Weakening.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 10812,
"size": 20234
} |
{-# OPTIONS --without-K #-}
module function.extensionality.strong where
open import level
open import sum
open import function.core
open import equality.core
open import function.isomorphism
open import function.extensionality.core
open import function.extensionality.proof
open import hott.level.core
open import hott.level.closure.core
open import hott.equivalence.core
private
module Dummy {i j}{X : Set i}{Y : X → Set j} where
_~_ : (f g : (x : X) → Y x) → Set (i ⊔ j)
f ~ g = ∀ x → f x ≡ g x
infix 5 _~_
R : (f : (x : X) → Y x) → f ~ f
R f x = refl
iso₁ : {f g : (x : X) → Y x} (p : f ≡ g)
→ funext (funext-inv p) ≡ p
iso₁ {f} refl = funext-id f
iso₂ : (f g : (x : X) → Y x) (h : f ~ g)
→ funext-inv (funext h) ≡ h
iso₂ f g h = subst (λ {(g , h) → funext-inv (funext h) ≡ h})
(e-contr' (g , h))
strong-id
where
E : Set (i ⊔ j)
E = Σ ((x : X) → Y x) λ g → f ~ g
e-contr : contr E
e-contr = retract-level
(λ u → proj₁ ∘' u , proj₂ ∘' u)
(λ {(g , h) x → g x , h x})
(λ {(g , h) → refl})
(Π-contr (λ x → singl-contr (f x)))
e-contr' : (u : E) → (f , R f) ≡ u
e-contr' u = contr⇒prop e-contr (f , R f) u
strong-id : funext-inv (funext (R f)) ≡ R f
strong-id = ap funext-inv (funext-id f)
strong-funext-iso : {f g : (x : X) → Y x}
→ (f ~ g) ≅ (f ≡ g)
strong-funext-iso {f}{g} = iso funext funext-inv (iso₂ f g) iso₁
strong-funext : {f g : (x : X) → Y x} → (f ~ g) ≡ (f ≡ g)
strong-funext = ≅⇒≡ strong-funext-iso
open Dummy public using (strong-funext; strong-funext-iso)
| {
"alphanum_fraction": 0.505787037,
"avg_line_length": 29.7931034483,
"ext": "agda",
"hexsha": "f70506a15f87eee364cd7b6ee5404f6b6f3a59fd",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "function/extensionality/strong.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "function/extensionality/strong.agda",
"max_line_length": 68,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "function/extensionality/strong.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 632,
"size": 1728
} |
module ConstructorsInstance where
record UnitRC : Set where
instance
constructor tt
data UnitD : Set where
instance
tt : UnitD
postulate
fRC : {{_ : UnitRC}} → Set
fD : {{_ : UnitD}} → Set
tryRC : Set
tryRC = fRC
tryD : Set
tryD = fD
data D : Set where
a : D
instance
b : D
c : D
postulate
g : {{_ : D}} → Set
-- This should work because instance search will choose [b]
try2 : Set
try2 = g
| {
"alphanum_fraction": 0.62004662,
"avg_line_length": 12.6176470588,
"ext": "agda",
"hexsha": "19943cf29a26a04d930dfa91c5e0c79386a7db2c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/ConstructorsInstance.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/ConstructorsInstance.agda",
"max_line_length": 59,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/ConstructorsInstance.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 148,
"size": 429
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Everything where
open import Cubical.HITs.Cylinder public
open import Cubical.HITs.Hopf public
open import Cubical.HITs.Interval public
open import Cubical.HITs.Ints.BiInvInt public hiding ( pred ; suc-pred ; pred-suc )
open import Cubical.HITs.Ints.DeltaInt public hiding ( pred ; succ ; zero )
open import Cubical.HITs.Ints.HAEquivInt public hiding ( suc-haequiv )
open import Cubical.HITs.Ints.IsoInt public
open import Cubical.HITs.Ints.QuoInt public
open import Cubical.HITs.Join public
open import Cubical.HITs.ListedFiniteSet public
open import Cubical.HITs.Pushout public
open import Cubical.HITs.Modulo public
open import Cubical.HITs.S1 public
open import Cubical.HITs.S2 public
open import Cubical.HITs.S3 public
open import Cubical.HITs.Rational public
open import Cubical.HITs.Susp public
open import Cubical.HITs.SmashProduct public renaming (comm to Smash-comm)
open import Cubical.HITs.Torus public
open import Cubical.HITs.PropositionalTruncation public
open import Cubical.HITs.SetTruncation public
open import Cubical.HITs.GroupoidTruncation public
open import Cubical.HITs.2GroupoidTruncation public
open import Cubical.HITs.SetQuotients public
open import Cubical.HITs.FiniteMultiset public hiding ( _++_ ; [_] ; assoc-++ )
open import Cubical.HITs.Colimit
| {
"alphanum_fraction": 0.8198198198,
"avg_line_length": 44.4,
"ext": "agda",
"hexsha": "0882b4eefa40eaf22ed9bffbfa771f44dff50fb9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/HITs/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/HITs/Everything.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/HITs/Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 384,
"size": 1332
} |
{-# OPTIONS -WShadowingInTelescope #-}
bad : Set → Set → Set
bad = λ x x → x
| {
"alphanum_fraction": 0.6025641026,
"avg_line_length": 15.6,
"ext": "agda",
"hexsha": "22dbd04070eeb6cd04afb5ef4b81345777f96942",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2284.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2284.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2284.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 26,
"size": 78
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.FreeCommAlgebra.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Function hiding (const)
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Sigma.Properties using (Σ≡Prop)
open import Cubical.HITs.SetTruncation
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommAlgebra.FreeCommAlgebra.Base
open import Cubical.Algebra.Ring using ()
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.Instances.Initial
open import Cubical.Algebra.Algebra
open import Cubical.Data.Empty
open import Cubical.Data.Sigma
private
variable
ℓ ℓ' ℓ'' : Level
module Theory {R : CommRing ℓ} {I : Type ℓ'} where
open CommRingStr (snd R)
using (0r; 1r)
renaming (_·_ to _·r_; _+_ to _+r_; ·Comm to ·r-comm; ·Rid to ·r-rid)
module _ (A : CommAlgebra R ℓ'') (φ : I → ⟨ A ⟩) where
open CommAlgebraStr (A .snd)
open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A)
open Construction using (var; const) renaming (_+_ to _+c_; -_ to -c_; _·_ to _·c_)
imageOf0Works : 0r ⋆ 1a ≡ 0a
imageOf0Works = 0-actsNullifying 1a
imageOf1Works : 1r ⋆ 1a ≡ 1a
imageOf1Works = ⋆-lid 1a
inducedMap : ⟨ R [ I ] ⟩ → ⟨ A ⟩
inducedMap (var x) = φ x
inducedMap (const r) = r ⋆ 1a
inducedMap (P +c Q) = (inducedMap P) + (inducedMap Q)
inducedMap (-c P) = - inducedMap P
inducedMap (Construction.+-assoc P Q S i) = +-assoc (inducedMap P) (inducedMap Q) (inducedMap S) i
inducedMap (Construction.+-rid P i) =
let
eq : (inducedMap P) + (inducedMap (const 0r)) ≡ (inducedMap P)
eq = (inducedMap P) + (inducedMap (const 0r)) ≡⟨ refl ⟩
(inducedMap P) + (0r ⋆ 1a) ≡⟨ cong
(λ u → (inducedMap P) + u)
(imageOf0Works) ⟩
(inducedMap P) + 0a ≡⟨ +-rid _ ⟩
(inducedMap P) ∎
in eq i
inducedMap (Construction.+-rinv P i) =
let eq : (inducedMap P - inducedMap P) ≡ (inducedMap (const 0r))
eq = (inducedMap P - inducedMap P) ≡⟨ +-rinv _ ⟩
0a ≡⟨ sym imageOf0Works ⟩
(inducedMap (const 0r))∎
in eq i
inducedMap (Construction.+-comm P Q i) = +-comm (inducedMap P) (inducedMap Q) i
inducedMap (P ·c Q) = inducedMap P · inducedMap Q
inducedMap (Construction.·-assoc P Q S i) = ·Assoc (inducedMap P) (inducedMap Q) (inducedMap S) i
inducedMap (Construction.·-lid P i) =
let eq = inducedMap (const 1r) · inducedMap P ≡⟨ cong (λ u → u · inducedMap P) imageOf1Works ⟩
1a · inducedMap P ≡⟨ ·Lid (inducedMap P) ⟩
inducedMap P ∎
in eq i
inducedMap (Construction.·-comm P Q i) = ·-comm (inducedMap P) (inducedMap Q) i
inducedMap (Construction.ldist P Q S i) = ·Ldist+ (inducedMap P) (inducedMap Q) (inducedMap S) i
inducedMap (Construction.+HomConst s t i) = ⋆-ldist s t 1a i
inducedMap (Construction.·HomConst s t i) =
let eq = (s ·r t) ⋆ 1a ≡⟨ cong (λ u → u ⋆ 1a) (·r-comm _ _) ⟩
(t ·r s) ⋆ 1a ≡⟨ ⋆-assoc t s 1a ⟩
t ⋆ (s ⋆ 1a) ≡⟨ cong (λ u → t ⋆ u) (sym (·Rid _)) ⟩
t ⋆ ((s ⋆ 1a) · 1a) ≡⟨ ⋆-rassoc t (s ⋆ 1a) 1a ⟩
(s ⋆ 1a) · (t ⋆ 1a) ∎
in eq i
inducedMap (Construction.0-trunc P Q p q i j) =
isSetAlgebra (CommAlgebra→Algebra A) (inducedMap P) (inducedMap Q) (cong _ p) (cong _ q) i j
module _ where
open IsAlgebraHom
inducedHom : AlgebraHom (CommAlgebra→Algebra (R [ I ])) (CommAlgebra→Algebra A)
inducedHom .fst = inducedMap
inducedHom .snd .pres0 = 0-actsNullifying _
inducedHom .snd .pres1 = imageOf1Works
inducedHom .snd .pres+ x y = refl
inducedHom .snd .pres· x y = refl
inducedHom .snd .pres- x = refl
inducedHom .snd .pres⋆ r x =
(r ⋆ 1a) · inducedMap x ≡⟨ ⋆-lassoc r 1a (inducedMap x) ⟩
r ⋆ (1a · inducedMap x) ≡⟨ cong (λ u → r ⋆ u) (·Lid (inducedMap x)) ⟩
r ⋆ inducedMap x ∎
module _ (A : CommAlgebra R ℓ'') where
open CommAlgebraStr (A .snd)
open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A)
open Construction using (var; const) renaming (_+_ to _+c_; -_ to -c_; _·_ to _·c_)
Hom = CommAlgebraHom (R [ I ]) A
open IsAlgebraHom
evaluateAt : Hom → I → ⟨ A ⟩
evaluateAt φ x = φ .fst (var x)
mapRetrievable : ∀ (φ : I → ⟨ A ⟩)
→ evaluateAt (inducedHom A φ) ≡ φ
mapRetrievable φ = refl
proveEq : ∀ {X : Type ℓ''} (isSetX : isSet X) (f g : ⟨ R [ I ] ⟩ → X)
→ (var-eq : (x : I) → f (var x) ≡ g (var x))
→ (const-eq : (r : ⟨ R ⟩) → f (const r) ≡ g (const r))
→ (+-eq : (x y : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → (eq-y : f y ≡ g y)
→ f (x +c y) ≡ g (x +c y))
→ (·-eq : (x y : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → (eq-y : f y ≡ g y)
→ f (x ·c y) ≡ g (x ·c y))
→ (-eq : (x : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x)
→ f (-c x) ≡ g (-c x))
→ f ≡ g
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (var x) = var-eq x i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (const x) = const-eq x i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (x +c y) =
+-eq x y
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i y)
i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (-c x) =
-eq x ((λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)) i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (x ·c y) =
·-eq x y
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i y)
i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-assoc x y z j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c (y +c z)) ≡ g (x +c (y +c z))
a₀₋ = +-eq _ _ (rec x) (+-eq _ _ (rec y) (rec z))
a₁₋ : f ((x +c y) +c z) ≡ g ((x +c y) +c z)
a₁₋ = +-eq _ _ (+-eq _ _ (rec x) (rec y)) (rec z)
a₋₀ : f (x +c (y +c z)) ≡ f ((x +c y) +c z)
a₋₀ = cong f (Construction.+-assoc x y z)
a₋₁ : g (x +c (y +c z)) ≡ g ((x +c y) +c z)
a₋₁ = cong g (Construction.+-assoc x y z)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-rid x j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c (const 0r)) ≡ g (x +c (const 0r))
a₀₋ = +-eq _ _ (rec x) (const-eq 0r)
a₁₋ : f x ≡ g x
a₁₋ = rec x
a₋₀ : f (x +c (const 0r)) ≡ f x
a₋₀ = cong f (Construction.+-rid x)
a₋₁ : g (x +c (const 0r)) ≡ g x
a₋₁ = cong g (Construction.+-rid x)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-rinv x j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c (-c x)) ≡ g (x +c (-c x))
a₀₋ = +-eq x (-c x) (rec x) (-eq x (rec x))
a₁₋ : f (const 0r) ≡ g (const 0r)
a₁₋ = const-eq 0r
a₋₀ : f (x +c (-c x)) ≡ f (const 0r)
a₋₀ = cong f (Construction.+-rinv x)
a₋₁ : g (x +c (-c x)) ≡ g (const 0r)
a₋₁ = cong g (Construction.+-rinv x)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-comm x y j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c y) ≡ g (x +c y)
a₀₋ = +-eq x y (rec x) (rec y)
a₁₋ : f (y +c x) ≡ g (y +c x)
a₁₋ = +-eq y x (rec y) (rec x)
a₋₀ : f (x +c y) ≡ f (y +c x)
a₋₀ = cong f (Construction.+-comm x y)
a₋₁ : g (x +c y) ≡ g (y +c x)
a₋₁ = cong g (Construction.+-comm x y)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-assoc x y z j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x ·c (y ·c z)) ≡ g (x ·c (y ·c z))
a₀₋ = ·-eq _ _ (rec x) (·-eq _ _ (rec y) (rec z))
a₁₋ : f ((x ·c y) ·c z) ≡ g ((x ·c y) ·c z)
a₁₋ = ·-eq _ _ (·-eq _ _ (rec x) (rec y)) (rec z)
a₋₀ : f (x ·c (y ·c z)) ≡ f ((x ·c y) ·c z)
a₋₀ = cong f (Construction.·-assoc x y z)
a₋₁ : g (x ·c (y ·c z)) ≡ g ((x ·c y) ·c z)
a₋₁ = cong g (Construction.·-assoc x y z)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-lid x j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f ((const 1r) ·c x) ≡ g ((const 1r) ·c x)
a₀₋ = ·-eq _ _ (const-eq 1r) (rec x)
a₁₋ : f x ≡ g x
a₁₋ = rec x
a₋₀ : f ((const 1r) ·c x) ≡ f x
a₋₀ = cong f (Construction.·-lid x)
a₋₁ : g ((const 1r) ·c x) ≡ g x
a₋₁ = cong g (Construction.·-lid x)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-comm x y j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x ·c y) ≡ g (x ·c y)
a₀₋ = ·-eq _ _ (rec x) (rec y)
a₁₋ : f (y ·c x) ≡ g (y ·c x)
a₁₋ = ·-eq _ _ (rec y) (rec x)
a₋₀ : f (x ·c y) ≡ f (y ·c x)
a₋₀ = cong f (Construction.·-comm x y)
a₋₁ : g (x ·c y) ≡ g (y ·c x)
a₋₁ = cong g (Construction.·-comm x y)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.ldist x y z j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f ((x +c y) ·c z) ≡ g ((x +c y) ·c z)
a₀₋ = ·-eq (x +c y) z
(+-eq _ _ (rec x) (rec y))
(rec z)
a₁₋ : f ((x ·c z) +c (y ·c z)) ≡ g ((x ·c z) +c (y ·c z))
a₁₋ = +-eq _ _ (·-eq _ _ (rec x) (rec z)) (·-eq _ _ (rec y) (rec z))
a₋₀ : f ((x +c y) ·c z) ≡ f ((x ·c z) +c (y ·c z))
a₋₀ = cong f (Construction.ldist x y z)
a₋₁ : g ((x +c y) ·c z) ≡ g ((x ·c z) +c (y ·c z))
a₋₁ = cong g (Construction.ldist x y z)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+HomConst s t j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (const (s +r t)) ≡ g (const (s +r t))
a₀₋ = const-eq (s +r t)
a₁₋ : f (const s +c const t) ≡ g (const s +c const t)
a₁₋ = +-eq _ _ (const-eq s) (const-eq t)
a₋₀ : f (const (s +r t)) ≡ f (const s +c const t)
a₋₀ = cong f (Construction.+HomConst s t)
a₋₁ : g (const (s +r t)) ≡ g (const s +c const t)
a₋₁ = cong g (Construction.+HomConst s t)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·HomConst s t j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (const (s ·r t)) ≡ g (const (s ·r t))
a₀₋ = const-eq (s ·r t)
a₁₋ : f (const s ·c const t) ≡ g (const s ·c const t)
a₁₋ = ·-eq _ _ (const-eq s) (const-eq t)
a₋₀ : f (const (s ·r t)) ≡ f (const s ·c const t)
a₋₀ = cong f (Construction.·HomConst s t)
a₋₁ : g (const (s ·r t)) ≡ g (const s ·c const t)
a₋₁ = cong g (Construction.·HomConst s t)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.0-trunc x y p q j k) =
let
P : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
P x i = proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x
Q : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
Q x i = proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x
in isOfHLevel→isOfHLevelDep 2
(λ z → isProp→isSet (isSetX (f z) (g z))) _ _
(cong P p)
(cong Q q)
(Construction.0-trunc x y p q) j k i
homRetrievable : ∀ (f : Hom)
→ inducedMap A (evaluateAt f) ≡ fst f
homRetrievable f =
proveEq
(isSetAlgebra (CommAlgebra→Algebra A))
(inducedMap A (evaluateAt f))
(λ x → f $a x)
(λ x → refl)
(λ r → r ⋆ 1a ≡⟨ cong (λ u → r ⋆ u) (sym f.pres1) ⟩
r ⋆ (f $a (const 1r)) ≡⟨ sym (f.pres⋆ r _) ⟩
f $a (const r ·c const 1r) ≡⟨ cong (λ u → f $a u) (sym (Construction.·HomConst r 1r)) ⟩
f $a (const (r ·r 1r)) ≡⟨ cong (λ u → f $a (const u)) (·r-rid r) ⟩
f $a (const r) ∎)
(λ x y eq-x eq-y →
ι (x +c y) ≡⟨ refl ⟩
(ι x + ι y) ≡⟨ cong (λ u → u + ι y) eq-x ⟩
((f $a x) + ι y) ≡⟨
cong (λ u → (f $a x) + u) eq-y ⟩
((f $a x) + (f $a y)) ≡⟨ sym (f.pres+ _ _) ⟩ (f $a (x +c y)) ∎)
(λ x y eq-x eq-y →
ι (x ·c y) ≡⟨ refl ⟩
ι x · ι y ≡⟨ cong (λ u → u · ι y) eq-x ⟩
(f $a x) · (ι y) ≡⟨ cong (λ u → (f $a x) · u) eq-y ⟩
(f $a x) · (f $a y) ≡⟨ sym (f.pres· _ _) ⟩
f $a (x ·c y) ∎)
(λ x eq-x →
ι (-c x) ≡⟨ refl ⟩
- ι x ≡⟨ cong (λ u → - u) eq-x ⟩
- (f $a x) ≡⟨ sym (f.pres- x) ⟩
f $a (-c x) ∎)
where
ι = inducedMap A (evaluateAt f)
module f = IsAlgebraHom (f .snd)
evaluateAt : {R : CommRing ℓ} {I : Type ℓ'} (A : CommAlgebra R ℓ'')
(f : CommAlgebraHom (R [ I ]) A)
→ (I → fst A)
evaluateAt A f x = f $a (Construction.var x)
inducedHom : {R : CommRing ℓ} {I : Type ℓ'} (A : CommAlgebra R ℓ'')
(φ : I → fst A )
→ CommAlgebraHom (R [ I ]) A
inducedHom A φ = Theory.inducedHom A φ
homMapIso : {R : CommRing ℓ} {I : Type ℓ} (A : CommAlgebra R ℓ')
→ Iso (CommAlgebraHom (R [ I ]) A) (I → (fst A))
Iso.fun (homMapIso A) = evaluateAt A
Iso.inv (homMapIso A) = inducedHom A
Iso.rightInv (homMapIso A) = λ ϕ → Theory.mapRetrievable A ϕ
Iso.leftInv (homMapIso {R = R} {I = I} A) =
λ f → Σ≡Prop (λ f → isPropIsCommAlgebraHom {M = R [ I ]} {N = A} f)
(Theory.homRetrievable A f)
homMapPath : {R : CommRing ℓ} {I : Type ℓ} (A : CommAlgebra R ℓ')
→ CommAlgebraHom (R [ I ]) A ≡ (I → fst A)
homMapPath A = isoToPath (homMapIso A)
module _ {R : CommRing ℓ} {A B : CommAlgebra R ℓ''} where
open AlgebraHoms
A′ = CommAlgebra→Algebra A
B′ = CommAlgebra→Algebra B
R′ = (CommRing→Ring R)
ν : AlgebraHom A′ B′ → (⟨ A ⟩ → ⟨ B ⟩)
ν φ = φ .fst
{-
Hom(R[I],A) → (I → A)
↓ ↓
Hom(R[I],B) → (I → B)
-}
naturalR : {I : Type ℓ'} (ψ : CommAlgebraHom A B)
(f : CommAlgebraHom (R [ I ]) A)
→ (fst ψ) ∘ evaluateAt A f ≡ evaluateAt B (ψ ∘a f)
naturalR ψ f = refl
{-
Hom(R[I],A) → (I → A)
↓ ↓
Hom(R[J],A) → (J → A)
-}
naturalL : {I J : Type ℓ'} (φ : J → I)
(f : CommAlgebraHom (R [ I ]) A)
→ (evaluateAt A f) ∘ φ
≡ evaluateAt A (f ∘a (inducedHom (R [ I ]) (λ x → Construction.var (φ x))))
naturalL φ f = refl
module _ {R : CommRing ℓ} where
{-
Prove that the FreeCommAlgebra over R on zero generators is
isomorphic to the initial R-Algebra - R itsself.
-}
freeOn⊥ : CommAlgebraEquiv (R [ ⊥ ]) (initialCAlg R)
freeOn⊥ =
equivByInitiality
R (R [ ⊥ ])
{- Show that R[⊥] has the universal property of the
initial R-Algbera and conclude that those are isomorphic -}
λ B → let to : CommAlgebraHom (R [ ⊥ ]) B → (⊥ → fst B)
to = evaluateAt B
from : (⊥ → fst B) → CommAlgebraHom (R [ ⊥ ]) B
from = inducedHom B
from-to : (x : _) → from (to x) ≡ x
from-to x =
Σ≡Prop (λ f → isPropIsCommAlgebraHom {M = R [ ⊥ ]} {N = B} f)
(Theory.homRetrievable B x)
equiv : CommAlgebraHom (R [ ⊥ ]) B ≃ (⊥ → fst B)
equiv =
isoToEquiv
(iso to from (λ x → isContr→isOfHLevel 1 isContr⊥→A _ _) from-to)
in isOfHLevelRespectEquiv 0 (invEquiv equiv) isContr⊥→A
| {
"alphanum_fraction": 0.4792174653,
"avg_line_length": 42.4939759036,
"ext": "agda",
"hexsha": "e02ddc0e7f46d17ba799a046defa42d5c6f48558",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommAlgebra/FreeCommAlgebra/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommAlgebra/FreeCommAlgebra/Properties.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommAlgebra/FreeCommAlgebra/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7165,
"size": 17635
} |
------------------------------------------------------------------------
-- Encoders and decoders
------------------------------------------------------------------------
open import Atom
module Coding (atoms : χ-atoms) where
open import Equality.Propositional
open import Prelude hiding (const)
open import Tactic.By.Propositional
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equality.Decision-procedures equality-with-J
open import Function-universe equality-with-J hiding (id; _∘_)
open import Injection equality-with-J using (Injective)
open import List equality-with-J using (foldr)
open import Maybe equality-with-J
open import Monad equality-with-J
open import Chi atoms
open import Constants atoms
open import Free-variables atoms
open import Values atoms
open χ-atoms atoms
------------------------------------------------------------------------
-- General definitions
-- Representation functions.
record Rep {a b} (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
-- Representation function.
⌜_⌝ : A → B
-- ⌜_⌝ is injective.
rep-injective : Injective ⌜_⌝
open Rep ⦃ … ⦄ public
-- An identity encoder.
id-rep : ∀ {a} {A : Type a} → Rep A A
id-rep = record
{ ⌜_⌝ = id
; rep-injective = id
}
-- Composition of representation functions.
infixr 9 _∘-rep_
_∘-rep_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
Rep B C → Rep A B → Rep A C
r₁ ∘-rep r₂ = record
{ ⌜_⌝ = R₁.⌜_⌝ ∘ R₂.⌜_⌝
; rep-injective = λ {x y} →
R₁.⌜ R₂.⌜ x ⌝ ⌝ ≡ R₁.⌜ R₂.⌜ y ⌝ ⌝ ↝⟨ R₁.rep-injective ⟩
R₂.⌜ x ⌝ ≡ R₂.⌜ y ⌝ ↝⟨ R₂.rep-injective ⟩□
x ≡ y □
}
where
module R₁ = Rep r₁
module R₂ = Rep r₂
-- Encoder/decoder pairs.
record Code {a b} (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
-- Encoder.
code : A → B
-- Partial decoder.
decode : B → Maybe A
-- The decoder must decode encoded values successfully.
decode∘code : ∀ x → decode (code x) ≡ just x
-- The encoder is injective.
code-injective : Injective code
code-injective {x} {y} eq = ⊎.cancel-inj₂ (
just x ≡⟨ by decode∘code ⟩
decode (code x) ≡⟨ by eq ⟩
decode (code y) ≡⟨ by decode∘code ⟩∎
just y ∎)
-- Encoder/decoder pairs can be turned into representation
-- functions.
rep : Rep A B
rep = record
{ ⌜_⌝ = code
; rep-injective = code-injective
}
open Code ⦃ … ⦄ public
-- Converts bijections to encoders.
↔→Code : ∀ {a b} {A : Type a} {B : Type b} → A ↔ B → Code A B
↔→Code A↔B = record
{ code = to
; decode = λ b → just (from b)
; decode∘code = λ a →
just (from (to a)) ≡⟨ cong just (left-inverse-of a) ⟩
just a ∎
}
where
open _↔_ A↔B
-- An identity encoder.
id-code : ∀ {a} {A : Type a} → Code A A
id-code = ↔→Code Bijection.id
-- Composition of encoders.
infixr 9 _∘-code_
_∘-code_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
Code B C → Code A B → Code A C
c₁ ∘-code c₂ = record
{ code = C₁.code ∘ C₂.code
; decode = λ c → C₁.decode c >>=′ C₂.decode
; decode∘code = λ a →
C₁.decode (C₁.code (C₂.code a)) >>=′ C₂.decode ≡⟨ cong (_>>=′ _) (C₁.decode∘code (C₂.code a)) ⟩
return (C₂.code a) >>=′ C₂.decode ≡⟨⟩
C₂.decode (C₂.code a) ≡⟨ by C₂.decode∘code ⟩∎
return a ∎
}
where
module C₁ = Code c₁
module C₂ = Code c₂
------------------------------------------------------------------------
-- Some general definitions related to χ
-- Constructor applications can be encoded as expressions (that are
-- also constructor applications).
code-Consts : ∃ λ (cd : Code Consts Exp) →
∀ c → Constructor-application (Code.code cd c)
code-Consts = record
{ code = cd
; decode = dc
; decode∘code = dc∘cd
} , cd-cs
where
mutual
cd : Consts → Exp
cd (const c cs) = const c (cd⋆ cs)
cd⋆ : List Consts → List Exp
cd⋆ [] = []
cd⋆ (c ∷ cs) = cd c ∷ cd⋆ cs
mutual
cd-cs : ∀ c → Constructor-application (cd c)
cd-cs (const c cs) = const c (cd⋆-cs cs)
cd⋆-cs : ∀ cs → Constructor-applications (cd⋆ cs)
cd⋆-cs [] = []
cd⋆-cs (c ∷ cs) = cd-cs c ∷ cd⋆-cs cs
mutual
dc : Exp → Maybe Consts
dc (const c es) = const c ⟨$⟩ dc⋆ es
dc _ = nothing
dc⋆ : List Exp → Maybe (List Consts)
dc⋆ [] = return []
dc⋆ (e ∷ es) = _∷_ ⟨$⟩ dc e ⊛ dc⋆ es
mutual
dc∘cd : ∀ c → dc (cd c) ≡ just c
dc∘cd (const c cs) =
const c ⟨$⟩ ⟨ dc⋆ (cd⋆ cs) ⟩ ≡⟨ ⟨by⟩ (dc∘cd⋆ cs) ⟩
const c ⟨$⟩ return cs ≡⟨ refl ⟩∎
return (const c cs) ∎
dc∘cd⋆ : ∀ cs → dc⋆ (cd⋆ cs) ≡ just cs
dc∘cd⋆ [] = refl
dc∘cd⋆ (c ∷ cs) =
_∷_ ⟨$⟩ ⟨ dc (cd c) ⟩ ⊛ dc⋆ (cd⋆ cs) ≡⟨ ⟨by⟩ (dc∘cd c) ⟩
_∷_ ⟨$⟩ return c ⊛ ⟨ dc⋆ (cd⋆ cs) ⟩ ≡⟨ ⟨by⟩ (dc∘cd⋆ cs) ⟩
_∷_ ⟨$⟩ return c ⊛ return cs ≡⟨⟩
return (c ∷ cs) ∎
-- Converts instances of the form Rep A Consts to Rep A Exp.
rep-Consts-Exp : ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ →
Rep A Exp
rep-Consts-Exp ⦃ r ⦄ = rep ⦃ proj₁ code-Consts ⦄ ∘-rep r
-- Represents something as an expression.
rep-as-Exp : ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ → A → Exp
rep-as-Exp = ⌜_⌝ ⦃ rep-Consts-Exp ⦄
-- rep-as-Exp returns constructor applications.
rep-const :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄
(x : A) → Constructor-application (rep-as-Exp x)
rep-const = proj₂ code-Consts ∘ ⌜_⌝
-- rep-as-Exp returns closed expressions.
rep-closed :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄
(x : A) → Closed (rep-as-Exp x)
rep-closed = const→closed ∘ rep-const
-- Constructor applications can be encoded as closed expressions.
code-Consts-Closed : Code Consts Closed-exp
Code.code code-Consts-Closed c =
code ⦃ r = proj₁ code-Consts ⦄ c , const→closed (proj₂ code-Consts c)
Code.decode code-Consts-Closed (e , _) =
decode ⦃ r = proj₁ code-Consts ⦄ e
Code.decode∘code code-Consts-Closed c =
decode ⦃ r = proj₁ code-Consts ⦄ (code ⦃ r = proj₁ code-Consts ⦄ c) ≡⟨ decode∘code ⦃ r = proj₁ code-Consts ⦄ c ⟩∎
just c ∎
-- Converts instances of the form Rep A Consts to Rep A Closed-exp.
rep-Consts-Closed-exp :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ → Rep A Closed-exp
rep-Consts-Closed-exp ⦃ r ⦄ = rep ⦃ r = code-Consts-Closed ⦄ ∘-rep r
-- rep-as-Exp returns values.
rep-value :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄
(x : A) → Value (rep-as-Exp x)
rep-value = const→value ∘ rep-const
-- Some derived lemmas.
subst-rep :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ (x : A) {y e} →
rep-as-Exp x [ y ← e ] ≡ rep-as-Exp x
subst-rep x = subst-closed _ _ (rep-closed x)
substs-rep :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ (x : A) ps →
foldr (λ ye → _[ proj₁ ye ← proj₂ ye ]) (rep-as-Exp x) ps ≡
rep-as-Exp x
substs-rep x = substs-closed (rep-as-Exp x) (rep-closed x)
rep⇓rep :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄
(x : A) → rep-as-Exp x ⇓ rep-as-Exp x
rep⇓rep x = values-compute-to-themselves (rep-value x)
rep⇓≡rep :
∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ {v}
(x : A) → rep-as-Exp x ⇓ v → rep-as-Exp x ≡ v
rep⇓≡rep x = values-only-compute-to-themselves (rep-value x)
------------------------------------------------------------------------
-- Specifications of how a number of types are encoded as χ
-- constructor applications
-- Encoder for booleans.
code-Bool : Code Bool Consts
code-Bool = record
{ code = cd
; decode = dc
; decode∘code = dc∘cd
}
where
cd : Bool → Consts
cd true = const c-true []
cd false = const c-false []
dc : Consts → Maybe Bool
dc (const c args) with c-true C.≟ c | c-false C.≟ c
dc (const c []) | yes _ | _ = return true
dc (const c []) | _ | yes _ = return false
dc (const c _) | _ | _ = nothing
dc∘cd : ∀ b → dc (cd b) ≡ just b
dc∘cd true with c-true C.≟ c-true
... | yes _ = refl
... | no t≢t = ⊥-elim (t≢t refl)
dc∘cd false with c-true C.≟ c-false | c-false C.≟ c-false
... | no _ | no f≢f = ⊥-elim (f≢f refl)
... | yes t≡f | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) t≡f)
... | no _ | yes _ = refl
-- Encoder for natural numbers.
code-ℕ : Code ℕ Consts
code-ℕ = record
{ code = cd
; decode = dc
; decode∘code = dc∘cd
}
where
cd : ℕ → Consts
cd zero = const c-zero []
cd (suc n) = const c-suc (cd n ∷ [])
dc : Consts → Maybe ℕ
dc (const c args) with c-zero C.≟ c | c-suc C.≟ c
dc (const c []) | yes eq | _ = return zero
dc (const c (n ∷ [])) | _ | yes eq = map suc (dc n)
dc (const c _) | _ | _ = nothing
dc∘cd : ∀ n → dc (cd n) ≡ just n
dc∘cd zero with c-zero C.≟ c-zero
... | yes _ = refl
... | no z≢z = ⊥-elim (z≢z refl)
dc∘cd (suc n) with c-zero C.≟ c-suc | c-suc C.≟ c-suc
... | no _ | no s≢s = ⊥-elim (s≢s refl)
... | yes z≡s | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) z≡s)
... | no _ | yes _ =
map suc ⟨ dc (cd n) ⟩ ≡⟨ ⟨by⟩ (dc∘cd n) ⟩
map suc (return n) ≡⟨ refl ⟩∎
return (suc n) ∎
-- Encoder for variables.
code-Var : Code Var Consts
code-Var = code-ℕ ∘-code ↔→Code V.countably-infinite
-- Encoder for constants.
code-Const : Code Const Consts
code-Const = code-ℕ ∘-code ↔→Code C.countably-infinite
-- Encoders for products.
module _ {a b} {A : Type a} {B : Type b} where
private
encode : (A → Consts) → (B → Consts) → A × B → Consts
encode encA encB (x , y) = const c-pair (encA x ∷ encB y ∷ [])
rep-× : ⦃ r : Rep A Consts ⦄ ⦃ s : Rep B Consts ⦄ →
Rep (A × B) Consts
rep-× ⦃ r ⦄ ⦃ s ⦄ = record
{ ⌜_⌝ = encode ⌜_⌝ ⌜_⌝
; rep-injective = λ { {x₁ , x₂} {y₁ , y₂} →
const c-pair (⌜ x₁ ⌝ ∷ ⌜ x₂ ⌝ ∷ []) ≡
const c-pair (⌜ y₁ ⌝ ∷ ⌜ y₂ ⌝ ∷ []) ↝⟨ lemma ⟩
⌜ x₁ ⌝ ≡ ⌜ y₁ ⌝ × ⌜ x₂ ⌝ ≡ ⌜ y₂ ⌝ ↝⟨ Σ-map rep-injective rep-injective ⟩
x₁ ≡ y₁ × x₂ ≡ y₂ ↝⟨ uncurry (cong₂ _,_) ⟩□
(x₁ , x₂) ≡ (y₁ , y₂) □ }
}
where
lemma :
∀ {c₁ c₂ x₁ x₂ y₁ y₂} →
Consts.const c₁ (x₁ ∷ x₂ ∷ []) ≡ const c₂ (y₁ ∷ y₂ ∷ []) →
x₁ ≡ y₁ × x₂ ≡ y₂
lemma refl = refl , refl
code-× : ⦃ c : Code A Consts ⦄ ⦃ d : Code B Consts ⦄ →
Code (A × B) Consts
code-× = record
{ code = cd
; decode = dc
; decode∘code = dc∘cd
}
where
cd : A × B → Consts
cd = encode code code
dc : Consts → Maybe (A × B)
dc (const c args) with c-pair C.≟ c
dc (const c (x ∷ y ∷ [])) | yes _ = decode x >>=′ λ x →
decode y >>=′ λ y →
just (x , y)
dc (const c args) | _ = nothing
dc∘cd : ∀ x → dc (cd x) ≡ just x
dc∘cd (x , y) with c-pair C.≟ c-pair
... | no p≢p = ⊥-elim (p≢p refl)
... | yes _ =
(⟨ decode (code x) ⟩ >>=′ λ x →
decode (code y) >>=′ λ y →
just (x , y)) ≡⟨ ⟨by⟩ decode∘code ⟩
(return x >>=′ λ x →
decode (code y) >>=′ λ y →
just (x , y)) ≡⟨⟩
(⟨ decode (code y) ⟩ >>=′ λ y →
just (x , y)) ≡⟨ ⟨by⟩ decode∘code ⟩
(return y >>=′ λ y → just (x , y)) ≡⟨ refl ⟩∎
return (x , y) ∎
-- Encoders for lists.
module _ {a} {A : Type a} where
private
encode : (A → Consts) → List A → Consts
encode enc [] = const c-nil []
encode enc (x ∷ xs) = const c-cons (enc x ∷ encode enc xs ∷ [])
rep-List : ⦃ r : Rep A Consts ⦄ → Rep (List A) Consts
rep-List = record
{ ⌜_⌝ = encode ⌜_⌝
; rep-injective = injective
}
where
injective : ∀ {xs ys} → encode ⌜_⌝ xs ≡ encode ⌜_⌝ ys → xs ≡ ys
injective {[]} {[]} = λ _ → refl
injective {[]} {_ ∷ _} = λ ()
injective {_ ∷ _} {[]} = λ ()
injective {x ∷ xs} {y ∷ ys} =
const c-cons (⌜ x ⌝ ∷ encode ⌜_⌝ xs ∷ []) ≡
const c-cons (⌜ y ⌝ ∷ encode ⌜_⌝ ys ∷ []) ↝⟨ lemma ⟩
⌜ x ⌝ ≡ ⌜ y ⌝ × encode ⌜_⌝ xs ≡ encode ⌜_⌝ ys ↝⟨ Σ-map rep-injective injective ⟩
x ≡ y × xs ≡ ys ↝⟨ uncurry (cong₂ _∷_) ⟩□
x ∷ xs ≡ y ∷ ys □
where
lemma :
∀ {c₁ x₁ y₁ c₂ x₂ y₂} →
Consts.const c₁ (x₁ ∷ y₁ ∷ []) ≡ const c₂ (x₂ ∷ y₂ ∷ []) →
x₁ ≡ x₂ × y₁ ≡ y₂
lemma refl = refl , refl
code-List : ⦃ c : Code A Consts ⦄ → Code (List A) Consts
code-List = record
{ code = cd
; decode = dc
; decode∘code = dc∘cd
}
where
cd : List A → Consts
cd = encode code
dc : Consts → Maybe (List A)
dc (const c args) with c-nil C.≟ c | c-cons C.≟ c
dc (const c []) | yes eq | _ = return []
dc (const c′ (x ∷ xs ∷ [])) | _ | yes eq =
_∷_ ⟨$⟩ decode x ⊛ dc xs
dc (const c args) | _ | _ = nothing
dc∘cd : ∀ x → dc (cd x) ≡ just x
dc∘cd [] with c-nil C.≟ c-nil
... | yes _ = refl
... | no n≢n = ⊥-elim (n≢n refl)
dc∘cd (x ∷ xs) with c-nil C.≟ c-cons | c-cons C.≟ c-cons
... | no _ | no c≢c = ⊥-elim (c≢c refl)
... | yes n≡c | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) n≡c)
... | no _ | yes _ =
_∷_ ⟨$⟩ ⟨ decode (code x) ⟩ ⊛ dc (cd xs) ≡⟨ ⟨by⟩ decode∘code ⟩
_∷_ ⟨$⟩ return x ⊛ ⟨ dc (cd xs) ⟩ ≡⟨ ⟨by⟩ (dc∘cd xs) ⟩
_∷_ ⟨$⟩ return x ⊛ return xs ≡⟨⟩
return (x ∷ xs) ∎
-- Encoder for lists of variables.
code-Var⋆ : Code (List Var) Consts
code-Var⋆ = code-List ⦃ code-Var ⦄
private
module Var = Code code-Var
module Var⋆ = Code code-Var⋆
module Const = Code code-Const
-- Encoder for the abstract syntax.
mutual
code-E : Exp → Consts
code-E (apply e₁ e₂) = const c-apply (code-E e₁ ∷ code-E e₂ ∷ [])
code-E (lambda x e) = const c-lambda (code ⦃ code-Var ⦄ x ∷ code-E e ∷ [])
code-E (case e bs) = const c-case (code-E e ∷ code-B⋆ bs ∷ [])
code-E (rec x e) = const c-rec (code ⦃ code-Var ⦄ x ∷ code-E e ∷ [])
code-E (var x) = const c-var (code ⦃ code-Var ⦄ x ∷ [])
code-E (const c es) = const c-const (code ⦃ code-Const ⦄ c ∷ code-⋆ es ∷ [])
code-B : Br → Consts
code-B (branch c xs e) =
const c-branch
(code ⦃ code-Const ⦄ c ∷ code ⦃ code-Var⋆ ⦄ xs ∷ code-E e ∷ [])
-- TODO: One could presumably use sized types to avoid repetitive
-- code. However, I did not want to use sized types in the
-- specification of χ.
code-⋆ : List Exp → Consts
code-⋆ [] = const c-nil []
code-⋆ (e ∷ es) = const c-cons (code-E e ∷ code-⋆ es ∷ [])
code-B⋆ : List Br → Consts
code-B⋆ [] = const c-nil []
code-B⋆ (b ∷ bs) = const c-cons (code-B b ∷ code-B⋆ bs ∷ [])
mutual
decode-E : Consts → Maybe Exp
decode-E (const c args) with c-apply C.≟ c
| c-lambda C.≟ c
| c-case C.≟ c
| c-rec C.≟ c
| c-var C.≟ c
| c-const C.≟ c
decode-E (const c (e₁ ∷ e₂ ∷ [])) | yes eq | _ | _ | _ | _ | _ =
apply ⟨$⟩ decode-E e₁ ⊛ decode-E e₂
decode-E (const c (x ∷ e ∷ [])) | _ | yes eq | _ | _ | _ | _ =
lambda ⟨$⟩ decode ⦃ code-Var ⦄ x ⊛ decode-E e
decode-E (const c (e ∷ bs ∷ [])) | _ | _ | yes eq | _ | _ | _ =
case ⟨$⟩ decode-E e ⊛ decode-B⋆ bs
decode-E (const c (x ∷ e ∷ [])) | _ | _ | _ | yes eq | _ | _ =
rec ⟨$⟩ decode ⦃ code-Var ⦄ x ⊛ decode-E e
decode-E (const c (x ∷ [])) | _ | _ | _ | _ | yes eq | _ =
var ⟨$⟩ decode ⦃ code-Var ⦄ x
decode-E (const c (c′ ∷ es ∷ [])) | _ | _ | _ | _ | _ | yes eq =
const ⟨$⟩ decode ⦃ code-Const ⦄ c′ ⊛ decode-⋆ es
decode-E (const c args) | _ | _ | _ | _ | _ | _ = nothing
decode-B : Consts → Maybe Br
decode-B (const c args) with c-branch C.≟ c
decode-B (const c (c′ ∷ xs ∷ e ∷ [])) | yes eq =
branch ⟨$⟩ decode ⦃ code-Const ⦄ c′
⊛ decode ⦃ code-Var⋆ ⦄ xs
⊛ decode-E e
decode-B (const c args) | _ = nothing
decode-⋆ : Consts → Maybe (List Exp)
decode-⋆ (const c args) with c-nil C.≟ c | c-cons C.≟ c
decode-⋆ (const c []) | yes eq | _ = return []
decode-⋆ (const c′ (e ∷ es ∷ [])) | _ | yes eq =
_∷_ ⟨$⟩ decode-E e ⊛ decode-⋆ es
decode-⋆ (const c args) | _ | _ = nothing
decode-B⋆ : Consts → Maybe (List Br)
decode-B⋆ (const c args) with c-nil C.≟ c | c-cons C.≟ c
decode-B⋆ (const c []) | yes eq | _ = return []
decode-B⋆ (const c′ (b ∷ bs ∷ [])) | _ | yes eq =
_∷_ ⟨$⟩ decode-B b ⊛ decode-B⋆ bs
decode-B⋆ (const c args) | _ | _ = nothing
mutual
decode∘code-E : ∀ e → decode-E (code-E e) ≡ just e
decode∘code-E (apply e₁ e₂) with c-apply C.≟ c-apply
... | no c≢c = ⊥-elim (c≢c refl)
... | yes _ =
apply ⟨$⟩ ⟨ decode-E (code-E e₁) ⟩ ⊛ decode-E (code-E e₂) ≡⟨ ⟨by⟩ (decode∘code-E e₁) ⟩
apply ⟨$⟩ return e₁ ⊛ ⟨ decode-E (code-E e₂) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e₂) ⟩
apply ⟨$⟩ return e₁ ⊛ return e₂ ≡⟨⟩
return (apply e₁ e₂) ∎
decode∘code-E (lambda x e) with c-apply C.≟ c-lambda
| c-lambda C.≟ c-lambda
... | _ | no l≢l = ⊥-elim (l≢l refl)
... | yes a≡l | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) a≡l)
... | no _ | yes _ =
lambda ⟨$⟩ ⟨ Var.decode (code ⦃ code-Var ⦄ x) ⟩ ⊛ decode-E (code-E e) ≡⟨ ⟨by⟩ Var.decode∘code ⟩
lambda ⟨$⟩ return x ⊛ ⟨ decode-E (code-E e) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩
lambda ⟨$⟩ return x ⊛ return e ≡⟨⟩
return (lambda x e) ∎
decode∘code-E (case e bs) with c-apply C.≟ c-case
| c-lambda C.≟ c-case
| c-case C.≟ c-case
... | _ | _ | no c≢c = ⊥-elim (c≢c refl)
... | _ | yes l≡c | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) l≡c)
... | yes a≡c | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) a≡c)
... | no _ | no _ | yes _ =
case ⟨$⟩ ⟨ decode-E (code-E e) ⟩ ⊛ decode-B⋆ (code-B⋆ bs) ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩
case ⟨$⟩ return e ⊛ ⟨ decode-B⋆ (code-B⋆ bs) ⟩ ≡⟨ ⟨by⟩ (decode∘code-B⋆ bs) ⟩
case ⟨$⟩ return e ⊛ return bs ≡⟨⟩
return (case e bs) ∎
decode∘code-E (rec x e) with c-apply C.≟ c-rec
| c-lambda C.≟ c-rec
| c-case C.≟ c-rec
| c-rec C.≟ c-rec
... | _ | _ | _ | no r≢r = ⊥-elim (r≢r refl)
... | _ | _ | yes c≡r | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) c≡r)
... | _ | yes l≡r | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) l≡r)
... | yes a≡r | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) a≡r)
... | no _ | no _ | no _ | yes _ =
rec ⟨$⟩ ⟨ Var.decode (code ⦃ code-Var ⦄ x) ⟩ ⊛ decode-E (code-E e) ≡⟨ ⟨by⟩ Var.decode∘code ⟩
rec ⟨$⟩ return x ⊛ ⟨ decode-E (code-E e) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩
rec ⟨$⟩ return x ⊛ return e ≡⟨⟩
return (rec x e) ∎
decode∘code-E (var x) with c-apply C.≟ c-var
| c-lambda C.≟ c-var
| c-case C.≟ c-var
| c-rec C.≟ c-var
| c-var C.≟ c-var
... | _ | _ | _ | _ | no v≢v = ⊥-elim (v≢v refl)
... | _ | _ | _ | yes r≡v | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) r≡v)
... | _ | _ | yes c≡v | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) c≡v)
... | _ | yes l≡v | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) l≡v)
... | yes a≡v | _ | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) a≡v)
... | no _ | no _ | no _ | no _ | yes _ =
var ⟨$⟩ ⟨ Var.decode (code ⦃ code-Var ⦄ x) ⟩ ≡⟨ ⟨by⟩ Var.decode∘code ⟩
var ⟨$⟩ return x ≡⟨ refl ⟩∎
return (var x) ∎
decode∘code-E (const c es) with c-apply C.≟ c-const
| c-lambda C.≟ c-const
| c-case C.≟ c-const
| c-rec C.≟ c-const
| c-var C.≟ c-const
| c-const C.≟ c-const
... | _ | _ | _ | _ | _ | no c≢c = ⊥-elim (c≢c refl)
... | _ | _ | _ | _ | yes v≡c | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) v≡c)
... | _ | _ | _ | yes r≡c | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) r≡c)
... | _ | _ | yes c≡c | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) c≡c)
... | _ | yes l≡c | _ | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) l≡c)
... | yes a≡c | _ | _ | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) a≡c)
... | no _ | no _ | no _ | no _ | no _ | yes _ =
const ⟨$⟩ ⟨ Const.decode (code ⦃ code-Const ⦄ c) ⟩ ⊛
decode-⋆ (code-⋆ es) ≡⟨ ⟨by⟩ Const.decode∘code ⟩
const ⟨$⟩ return c ⊛ ⟨ decode-⋆ (code-⋆ es) ⟩ ≡⟨ ⟨by⟩ (decode∘code-⋆ es) ⟩
const ⟨$⟩ return c ⊛ return es ≡⟨⟩
return (const c es) ∎
decode∘code-B : ∀ b → decode-B (code-B b) ≡ just b
decode∘code-B (branch c xs e) with c-branch C.≟ c-branch
... | no b≢b = ⊥-elim (b≢b refl)
... | yes _ =
branch ⟨$⟩ ⟨ Const.decode (code ⦃ code-Const ⦄ c) ⟩ ⊛
Var⋆.decode (code ⦃ code-Var⋆ ⦄ xs) ⊛
decode-E (code-E e) ≡⟨ ⟨by⟩ Const.decode∘code ⟩
branch ⟨$⟩ return c ⊛
⟨ Var⋆.decode (code ⦃ code-Var⋆ ⦄ xs) ⟩ ⊛
decode-E (code-E e) ≡⟨ ⟨by⟩ Var⋆.decode∘code ⟩
branch ⟨$⟩ return c ⊛ return xs ⊛ ⟨ decode-E (code-E e) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩
branch ⟨$⟩ return c ⊛ return xs ⊛ return e ≡⟨⟩
return (branch c xs e) ∎
decode∘code-⋆ : ∀ es → decode-⋆ (code-⋆ es) ≡ just es
decode∘code-⋆ [] with c-nil C.≟ c-nil
... | no n≢n = ⊥-elim (n≢n refl)
... | yes _ = refl
decode∘code-⋆ (e ∷ es) with c-nil C.≟ c-cons | c-cons C.≟ c-cons
... | no _ | no c≢c = ⊥-elim (c≢c refl)
... | yes n≡c | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) n≡c)
... | no _ | yes _ =
_∷_ ⟨$⟩ ⟨ decode-E (code-E e) ⟩ ⊛ decode-⋆ (code-⋆ es) ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩
_∷_ ⟨$⟩ return e ⊛ ⟨ decode-⋆ (code-⋆ es) ⟩ ≡⟨ ⟨by⟩ (decode∘code-⋆ es) ⟩
_∷_ ⟨$⟩ return e ⊛ return es ≡⟨⟩
return (e ∷ es) ∎
decode∘code-B⋆ : ∀ bs → decode-B⋆ (code-B⋆ bs) ≡ just bs
decode∘code-B⋆ [] with c-nil C.≟ c-nil
... | no n≢n = ⊥-elim (n≢n refl)
... | yes _ = refl
decode∘code-B⋆ (b ∷ bs) with c-nil C.≟ c-cons | c-cons C.≟ c-cons
... | no _ | no c≢c = ⊥-elim (c≢c refl)
... | yes n≡c | _ = ⊥-elim (C.distinct-codes→distinct-names
(λ ()) n≡c)
... | no _ | yes _ =
_∷_ ⟨$⟩ ⟨ decode-B (code-B b) ⟩ ⊛ decode-B⋆ (code-B⋆ bs) ≡⟨ ⟨by⟩ (decode∘code-B b) ⟩
_∷_ ⟨$⟩ return b ⊛ ⟨ decode-B⋆ (code-B⋆ bs) ⟩ ≡⟨ ⟨by⟩ (decode∘code-B⋆ bs) ⟩
_∷_ ⟨$⟩ return b ⊛ return bs ≡⟨⟩
return (b ∷ bs) ∎
code-Exp : Code Exp Consts
Code.code code-Exp = code-E
Code.decode code-Exp = decode-E
Code.decode∘code code-Exp = decode∘code-E
code-Br : Code Br Consts
Code.code code-Br = code-B
Code.decode code-Br = decode-B
Code.decode∘code code-Br = decode∘code-B
code-Exps : Code (List Exp) Consts
Code.code code-Exps = code-⋆
Code.decode code-Exps = decode-⋆
Code.decode∘code code-Exps = decode∘code-⋆
code-Brs : Code (List Br) Consts
Code.code code-Brs = code-B⋆
Code.decode code-Brs = decode-B⋆
Code.decode∘code code-Brs = decode∘code-B⋆
-- Encoder for closed expressions.
code-Closed : Code Closed-exp Consts
Code.code code-Closed = code ⦃ code-Exp ⦄ ∘ proj₁
Code.decode code-Closed c with decode ⦃ code-Exp ⦄ c
... | nothing = nothing
... | just e with closed? e
... | yes cl = just (e , cl)
... | no _ = nothing
Code.decode∘code code-Closed (c , cl)
with decode ⦃ r = code-Exp ⦄ (code ⦃ code-Exp ⦄ c)
| decode∘code ⦃ r = code-Exp ⦄ c
... | .(just c) | refl with closed? c
... | no ¬cl = ⊥-elim (¬cl cl)
... | yes cl′ =
cong just (closed-equal-if-expressions-equal refl)
| {
"alphanum_fraction": 0.4356647484,
"avg_line_length": 36,
"ext": "agda",
"hexsha": "ee18ca6e4f56d3cb4ab7bb0a94d3fd089931d27d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Coding.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Coding.agda",
"max_line_length": 116,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Coding.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 9983,
"size": 27108
} |
-- Hilbert-style formalisation of closed syntax.
-- Sequences of terms.
module OldBasicILP.Syntax.ClosedHilbertSequential where
open import OldBasicILP.Syntax.Common public
-- Mutually-recursive declarations.
data Ty : Set
record Proof (Ξ : Cx Ty) (A : Ty) : Set
data ⊢ᴰ_ : Cx Ty → Set
_⧺ᴰ_ : ∀ {Ξ₁ Ξ₂} → ⊢ᴰ Ξ₁ → ⊢ᴰ Ξ₂ → ⊢ᴰ Ξ₁ ⧺ Ξ₂
-- Types parametrised by closed derivations.
infixr 10 _⦂_
infixl 9 _∧_
infixr 7 _▻_
data Ty where
α_ : Atom → Ty
_▻_ : Ty → Ty → Ty
_⦂_ : ∀ {Ξ A} → Proof Ξ A → Ty → Ty
_∧_ : Ty → Ty → Ty
⊤ : Ty
-- Anti-bug wrappers.
record Proof (Ξ : Cx Ty) (A : Ty) where
inductive
constructor [_]
field
der : ⊢ᴰ Ξ , A
-- More mutually-recursive declarations.
appᴰ : ∀ {Ξ₁ Ξ₂ A B} → ⊢ᴰ Ξ₁ , A ▻ B → ⊢ᴰ Ξ₂ , A → ⊢ᴰ (Ξ₂ , A) ⧺ (Ξ₁ , A ▻ B) , B
boxᴰ : ∀ {Ξ A} → (d : ⊢ᴰ Ξ , A) → ⊢ᴰ ∅ , [ d ] ⦂ A
-- Derivations.
infix 3 ⊢ᴰ_
data ⊢ᴰ_ where
nil : ⊢ᴰ ∅
mp : ∀ {Ξ A B} → A ▻ B ∈ Ξ → A ∈ Ξ → ⊢ᴰ Ξ → ⊢ᴰ Ξ , B
ci : ∀ {Ξ A} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , A ▻ A
ck : ∀ {Ξ A B} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , A ▻ B ▻ A
cs : ∀ {Ξ A B C} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
nec : ∀ {Ξ A} → ∀ {`Ξ} → (`d : ⊢ᴰ `Ξ , A)
→ ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d ] ⦂ A
cdist : ∀ {Ξ A B} → ∀ {`Ξ₁ `Ξ₂} → {`d₁ : ⊢ᴰ `Ξ₁ , A ▻ B} → {`d₂ : ⊢ᴰ `Ξ₂ , A}
→ ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d₁ ] ⦂ (A ▻ B) ▻ [ `d₂ ] ⦂ A ▻ [ appᴰ `d₁ `d₂ ] ⦂ B
cup : ∀ {Ξ A} → ∀ {`Ξ} → {`d : ⊢ᴰ `Ξ , A}
→ ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d ] ⦂ A ▻ [ boxᴰ `d ] ⦂ [ `d ] ⦂ A
cdown : ∀ {Ξ A} → ∀ {`Ξ} → {`d : ⊢ᴰ `Ξ , A}
→ ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d ] ⦂ A ▻ A
cpair : ∀ {Ξ A B} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , A ▻ B ▻ A ∧ B
cfst : ∀ {Ξ A B} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , A ∧ B ▻ A
csnd : ∀ {Ξ A B} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , A ∧ B ▻ B
unit : ∀ {Ξ} → ⊢ᴰ Ξ → ⊢ᴰ Ξ , ⊤
-- Anti-bug wrappers.
infix 3 ⊢_
⊢_ : Ty → Set
⊢ A = ∃ (λ Ξ → ⊢ᴰ Ξ , A)
-- Concatenation of derivations.
d₁ ⧺ᴰ nil = d₁
d₁ ⧺ᴰ mp i j d₂ = mp (mono∈ weak⊆⧺₂ i) (mono∈ weak⊆⧺₂ j) (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ ci d₂ = ci (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ ck d₂ = ck (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ cs d₂ = cs (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ nec `d d₂ = nec `d (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ cdist d₂ = cdist (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ cup d₂ = cup (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ cdown d₂ = cdown (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ cpair d₂ = cpair (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ cfst d₂ = cfst (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ csnd d₂ = csnd (d₁ ⧺ᴰ d₂)
d₁ ⧺ᴰ unit d₂ = unit (d₁ ⧺ᴰ d₂)
-- Modus ponens and necessitation in nested form.
appᴰ {Ξ₁} {Ξ₂} {A} {B} d₁ d₂ = mp top (mono∈ (weak⊆⧺₁ (Ξ₁ , A ▻ B)) top) (d₂ ⧺ᴰ d₁)
boxᴰ {Ξ} {A} d = nec d nil
app : ∀ {A B} → ⊢ A ▻ B → ⊢ A → ⊢ B
app {A} {B} (Ξ₁ , d₁) (Ξ₂ , d₂) = Ξ₃ , d₃
where Ξ₃ = (Ξ₂ , A) ⧺ (Ξ₁ , A ▻ B)
d₃ = appᴰ d₁ d₂
box : ∀ {A} → (t : ⊢ A) → ⊢ [ π₂ t ] ⦂ A
box (Ξ , d) = ∅ , boxᴰ d
| {
"alphanum_fraction": 0.4323348971,
"avg_line_length": 24.3070175439,
"ext": "agda",
"hexsha": "cac2c8f5ad6f10de8e51bf6a5e1ef8492a368b0b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "OldBasicILP/Syntax/ClosedHilbertSequential.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "OldBasicILP/Syntax/ClosedHilbertSequential.agda",
"max_line_length": 92,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "OldBasicILP/Syntax/ClosedHilbertSequential.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1725,
"size": 2771
} |
------------------------------------------------------------------------
-- Some types and functions used by several parser variants
------------------------------------------------------------------------
module Utilities where
open import Data.Product
open import Data.List
open import Data.Function using (flip)
------------------------------------------------------------------------
-- Associativity
-- Used to specify how chain₁, chain and chain≥ should apply the
-- parsed operators: left or right associatively.
data Assoc : Set where
left : Assoc
right : Assoc
------------------------------------------------------------------------
-- Post-processing for the chain parsers
-- Application.
appʳ : forall {r} -> r × (r -> r -> r) -> r -> r
appʳ (x , _•_) y = x • y
appˡ : forall {r} -> r -> (r -> r -> r) × r -> r
appˡ x (_•_ , y) = x • y
-- Shifting. See Examples below for an illuminating example.
shiftˡ : forall {a b} -> List (a × b) -> a -> a × List (b × a)
shiftˡ [] x = (x , [])
shiftˡ ((x₁ , x₂) ∷ xs₃) x₄ = (x₁ , (x₂ , proj₁ x₃xs₄) ∷ proj₂ x₃xs₄)
where x₃xs₄ = shiftˡ xs₃ x₄
-- The post-processing function. See Examples below for some
-- illuminating examples.
chain₁-combine : forall {r} ->
Assoc -> List (r × (r -> r -> r)) -> r -> r
chain₁-combine right xs y = foldr appʳ y xs
chain₁-combine left xs y with shiftˡ xs y
... | (x , ys) = foldl appˡ x ys
-- Variants.
shiftʳ : forall {a b} -> a -> List (b × a) -> List (a × b) × a
shiftʳ x [] = ([] , x)
shiftʳ x₁ ((x₂ , x₃) ∷ xs₄) = ((x₁ , x₂) ∷ proj₁ xs₃x₄ , proj₂ xs₃x₄)
where xs₃x₄ = shiftʳ x₃ xs₄
chain≥-combine : forall {r} ->
Assoc -> r -> List ((r -> r -> r) × r) -> r
chain≥-combine left x ys = foldl appˡ x ys
chain≥-combine right x ys with shiftʳ x ys
... | (xs , y) = foldr appʳ y xs
private
module Examples {r s : Set}
(x y z : r)
(A B : s)
(_+_ _*_ : r -> r -> r)
where
open import Relation.Binary.PropositionalEquality
ex₁ : shiftˡ ((x , A) ∷ (y , B) ∷ []) z ≡ (x , ((A , y) ∷ (B , z) ∷ []))
ex₁ = refl
ex₁ʳ : chain₁-combine right ((x , _+_) ∷ (y , _*_) ∷ []) z ≡ x + (y * z)
ex₁ʳ = refl
ex₁ˡ : chain₁-combine left ((x , _+_) ∷ (y , _*_) ∷ []) z ≡ (x + y) * z
ex₁ˡ = refl
ex≥ : shiftʳ x ((A , y) ∷ (B , z) ∷ []) ≡ ((x , A) ∷ (y , B) ∷ [] , z)
ex≥ = refl
ex≥ʳ : chain≥-combine right x ((_+_ , y) ∷ (_*_ , z) ∷ []) ≡ x + (y * z)
ex≥ʳ = refl
ex≥ˡ : chain≥-combine left x ((_+_ , y) ∷ (_*_ , z) ∷ []) ≡ (x + y) * z
ex≥ˡ = refl
------------------------------------------------------------------------
-- Some suitably typed composition operators
infixr 9 _∘′_ _∘₂_
_∘′_ : {a c : Set} {b : a -> Set1} ->
(forall {x} -> b x -> c) -> ((x : a) -> b x) -> (a -> c)
f ∘′ g = \x -> f (g x)
_∘₂_ : {a b c : Set2} -> (b -> c) -> (a -> b) -> (a -> c)
f ∘₂ g = \x -> f (g x)
| {
"alphanum_fraction": 0.445799458,
"avg_line_length": 29.8181818182,
"ext": "agda",
"hexsha": "5d7bfbf8b14f2b6a0b3448c3889c6b30d3f08940",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/Utilities.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/Utilities.agda",
"max_line_length": 74,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/Utilities.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 1052,
"size": 2952
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Pointed.Base where
open import Cubical.Foundations.Prelude
Pointed : (ℓ : Level) → Type (ℓ-suc ℓ)
Pointed ℓ = Σ[ A ∈ Type ℓ ] A
typ : ∀ {ℓ} (A∙ : Pointed ℓ) → Type ℓ
typ = fst
pt : ∀ {ℓ} (A∙ : Pointed ℓ) → typ A∙
pt = snd
| {
"alphanum_fraction": 0.6153846154,
"avg_line_length": 20.4285714286,
"ext": "agda",
"hexsha": "83ac03040699a5c6ad46c57c1131b9d958a0d1d5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a01973ef7264f9454a40697313a2073c51a6b77a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/cubical",
"max_forks_repo_path": "Cubical/Foundations/Pointed/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a01973ef7264f9454a40697313a2073c51a6b77a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/cubical",
"max_issues_repo_path": "Cubical/Foundations/Pointed/Base.agda",
"max_line_length": 45,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a01973ef7264f9454a40697313a2073c51a6b77a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/cubical",
"max_stars_repo_path": "Cubical/Foundations/Pointed/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 118,
"size": 286
} |
module Oscar.Class.Substitution where
open import Oscar.Data.Equality
open import Oscar.Function
open import Oscar.Relation
open import Oscar.Level
record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
field
ε : ∀ {m} → B m → C m
_◇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n
◇-left-identity : ∀ {m n} → (f : B m → C n) → ε ◇ f ≡̇ f
◇-right-identity : ∀ {m n} → (f : B m → C n) → f ◇ ε ≡̇ f
◇-associativity : ∀ {k l m n} (f : B k → C l) (g : B l → C m) (h : B m → C n) → h ◇ (g ◇ f) ≡̇ (h ◇ g) ◇ f
open Substitution ⦃ … ⦄ public
{-# DISPLAY Substitution._◇_ _ = _◇_ #-}
instance Substitution-id : ∀ {a} {A : Set a} {bc} {BC : A → Set bc} → Substitution BC BC
Substitution.ε Substitution-id = id
Substitution._◇_ Substitution-id g f = g ∘ f
Substitution.◇-left-identity Substitution-id _ _ = refl
Substitution.◇-right-identity Substitution-id _ _ = refl
Substitution.◇-associativity Substitution-id _ _ _ _ = refl
| {
"alphanum_fraction": 0.5832502493,
"avg_line_length": 37.1481481481,
"ext": "agda",
"hexsha": "34d399fa8c0ef9b0c5e3c8f11a4add28679d6599",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Class/Substitution.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Class/Substitution.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Class/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 404,
"size": 1003
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Multiplication
open import Numbers.Integers.Order
open import Numbers.Integers.RingStructure.Ring
open import Numbers.Integers.RingStructure.IntegralDomain
open import Semirings.Definition
open import Rings.EuclideanDomains.Definition
open import Orders.Total.Definition
open import Numbers.Naturals.EuclideanAlgorithm
module Numbers.Integers.RingStructure.EuclideanDomain where
private
norm : ℤ → ℕ
norm (nonneg x) = x
norm (negSucc x) = succ x
norm' : {a : ℤ} → (a!=0 : (a ≡ nonneg 0) → False) → ℕ
norm' {a} _ = norm a
multiplyIncreasesSuccLemma : (a b : ℕ) → succ (succ a) <N (succ (succ a)) *N (succ (succ b))
multiplyIncreasesSuccLemma a b with multiplyIncreases (succ (succ b)) (succ (succ a)) (le b (applyEquality succ (Semiring.commutative ℕSemiring b 1))) (le (succ a) (applyEquality (λ i → succ (succ i)) (Semiring.sumZeroRight ℕSemiring a)))
... | bl rewrite multiplicationNIsCommutative (succ (succ b)) (succ (succ a)) = bl
multiplyIncreasesSucc : (a b : ℕ) → succ a ≤N (succ a) *N (succ b)
multiplyIncreasesSucc zero zero = inr refl
multiplyIncreasesSucc zero (succ b) = inl (le (b +N 0) (Semiring.commutative ℕSemiring (succ (b +N 0)) 1))
multiplyIncreasesSucc (succ a) zero = inr (applyEquality (λ i → succ (succ i)) (equalityCommutative (productWithOneRight a)))
multiplyIncreasesSucc (succ a) (succ b) = inl (multiplyIncreasesSuccLemma a b)
multiplyIncreasesSuccLemma' : (a b : ℕ) → succ (succ a) <N succ ((succ (succ a)) *N succ b) +N succ a
multiplyIncreasesSuccLemma' a b = succPreservesInequality (le (b +N succ (b +N a *N succ b)) refl)
multiplyIncreasesSucc' : (a b : ℕ) → succ a ≤N succ ((b +N a *N b) +N a)
multiplyIncreasesSucc' zero zero = inr refl
multiplyIncreasesSucc' zero (succ b) = inl (le b (applyEquality succ (transitivity (Semiring.commutative ℕSemiring b 1) (transitivity (equalityCommutative (Semiring.sumZeroRight ℕSemiring (succ b))) (equalityCommutative (Semiring.sumZeroRight ℕSemiring _))))))
multiplyIncreasesSucc' (succ a) zero rewrite multiplicationNIsCommutative a zero = inr refl
multiplyIncreasesSucc' (succ a) (succ b) = inl (multiplyIncreasesSuccLemma' a b)
normSize : {a b : ℤ} → (a!=0 : (a ≡ nonneg 0) → False) → (b!=0 : (b ≡ nonneg 0) → False) → (c : ℤ) → b ≡ (a *Z c) → (norm a) ≤N (norm b)
normSize {nonneg a} {nonneg b} a!=0 b!=0 (nonneg zero) b=ac rewrite nonnegInjective b=ac | multiplicationNIsCommutative a 0 = exFalso (b!=0 refl)
normSize {nonneg a} {nonneg b} a!=0 b!=0 (nonneg (succ 0)) b=ac rewrite nonnegInjective b=ac | multiplicationNIsCommutative a 1 = inr (equalityCommutative (Semiring.sumZeroRight ℕSemiring a))
normSize {nonneg 0} {nonneg b} a!=0 b!=0 (nonneg (succ (succ c))) b=ac = exFalso (a!=0 refl)
normSize {nonneg (succ a)} {nonneg (succ b)} a!=0 b!=0 (nonneg (succ (succ c))) b=ac rewrite nonnegInjective b=ac = multiplyIncreasesSucc a (succ c)
normSize {nonneg 0} {nonneg b} a!=0 b!=0 (negSucc c) bad = exFalso (a!=0 refl)
normSize {nonneg (succ a)} {nonneg b} a!=0 b!=0 (negSucc c) ()
normSize {nonneg a} {negSucc b} a!=0 b!=0 (nonneg c) ()
normSize {nonneg (succ a)} {negSucc b} a!=0 b!=0 (negSucc c) pr rewrite negSuccInjective pr = multiplyIncreasesSucc' a c
normSize {negSucc a} {nonneg zero} _ b!=0 c pr = exFalso (b!=0 refl)
normSize {negSucc a} {nonneg (succ b)} _ _ (nonneg zero) ()
normSize {negSucc a} {nonneg (succ b)} _ _ (nonneg (succ x)) ()
normSize {negSucc a} {nonneg (succ b)} _ _ (negSucc c) pr rewrite nonnegInjective pr = multiplyIncreasesSucc a c
normSize {negSucc a} {negSucc b} _ _ (nonneg (succ c)) pr rewrite negSuccInjective pr | multiplicationNIsCommutative c a | Semiring.commutative ℕSemiring (a +N a *N c) c | Semiring.+Associative ℕSemiring c a (a *N c) | Semiring.commutative ℕSemiring c a | equalityCommutative (Semiring.+Associative ℕSemiring a c (a *N c)) | Semiring.commutative ℕSemiring a (c +N a *N c) = multiplyIncreasesSucc' a c
divAlg : {a b : ℤ} → (a!=0 : (a ≡ nonneg 0) → False) → (b!=0 : (b ≡ nonneg 0) → False) → DivisionAlgorithmResult ℤRing norm' a!=0 b!=0
divAlg {nonneg zero} {b} a!=0 b!=0 = exFalso (a!=0 refl)
divAlg {nonneg (succ a)} {nonneg zero} a!=0 b!=0 = exFalso (b!=0 refl)
divAlg {nonneg (succ a)} {nonneg (succ b)} a!=0 b!=0 with divisionAlg (succ b) (succ a)
divAlg {nonneg (succ a)} {nonneg (succ b)} a!=0 b!=0 | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } = record { quotient = nonneg quot ; rem = nonneg rem ; remSmall = u ; divAlg = transitivity (applyEquality nonneg (equalityCommutative pr)) t }
where
t : nonneg ((quot +N b *N quot) +N rem) ≡ nonneg (quot *N succ b) +Z nonneg rem
t rewrite multiplicationNIsCommutative (succ b) quot = +Zinherits (quot *N succ b) rem
u : (nonneg rem ≡ nonneg 0) || Sg ((nonneg rem ≡ nonneg 0) → False) (λ pr → rem <N succ b)
u with TotalOrder.totality ℤOrder (nonneg 0) (nonneg rem)
u | inl (inl 0<rem) = inr ((λ p → TotalOrder.irreflexive ℤOrder (TotalOrder.<WellDefined ℤOrder refl p 0<rem)) , remIsSmall)
u | inr 0=rem rewrite 0=rem = inl refl
divAlg {nonneg (succ a)} {negSucc b} _ _ with divisionAlg (succ b) (succ a)
divAlg {nonneg (succ a)} {negSucc b} _ _ | record { quot = zero ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = inl quotSmall } rewrite multiplicationNIsCommutative b 0 = record { quotient = nonneg 0 ; rem = nonneg rem ; remSmall = inr (p , remIsSmall) ; divAlg = applyEquality nonneg (equalityCommutative pr) }
where
p : (nonneg rem ≡ nonneg 0) → False
p pr2 rewrite pr = naughtE (equalityCommutative (nonnegInjective pr2))
divAlg {nonneg (succ a)} {negSucc b} _ _ | record { quot = succ quot ; rem = zero ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = inl quotSmall } = record { quotient = negSucc quot ; rem = nonneg zero ; remSmall = inl refl ; divAlg = applyEquality nonneg (transitivity (equalityCommutative pr) (applyEquality (λ i → i +N 0) (multiplicationNIsCommutative (succ b) (succ quot)))) }
divAlg {nonneg (succ a)} {negSucc b} _ _ | record { quot = succ quot ; rem = succ rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = inl quotSmall } = record { quotient = negSucc quot ; rem = nonneg (succ rem) ; remSmall = inr ((λ ()) , remIsSmall) ; divAlg = applyEquality nonneg (transitivity (equalityCommutative pr) (applyEquality (λ i → i +N succ rem) (multiplicationNIsCommutative (succ b) (succ quot)))) }
divAlg {negSucc a} {nonneg zero} _ b!=0 = exFalso (b!=0 refl)
divAlg {negSucc a} {nonneg (succ b)} _ _ with divisionAlg (succ b) (succ a)
divAlg {negSucc a} {nonneg (succ b)} _ _ | record { quot = zero ; rem = zero ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } = exFalso (naughtE (transitivity (equalityCommutative (transitivity (Semiring.sumZeroRight ℕSemiring _) (multiplicationNIsCommutative b 0))) pr))
divAlg {negSucc a} {nonneg (succ b)} _ _ | record { quot = succ quot ; rem = zero ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } = record { quotient = negSucc quot ; rem = nonneg 0 ; remSmall = inl refl ; divAlg = applyEquality negSucc (succInjective (transitivity (equalityCommutative pr) t)) }
where
t : succ (quot +N b *N succ quot) +N 0 ≡ succ ((quot +N b *N quot) +N b)
t rewrite Semiring.sumZeroRight ℕSemiring (succ (quot +N b *N succ quot)) | Semiring.commutative ℕSemiring (quot +N b *N quot) b | Semiring.+Associative ℕSemiring b quot (b *N quot) | Semiring.commutative ℕSemiring b quot | equalityCommutative (Semiring.+Associative ℕSemiring quot b (b *N quot)) | multiplicationNIsCommutative b (succ quot) | multiplicationNIsCommutative quot b = refl
divAlg {negSucc a} {nonneg (succ b)} _ _ | record { quot = zero ; rem = succ rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } rewrite multiplicationNIsCommutative b 0 | equalityCommutative (succInjective pr) = record { quotient = nonneg zero ; rem = negSucc rem ; remSmall = inr (((λ ()) , remIsSmall)) ; divAlg = refl }
divAlg {negSucc a} {nonneg (succ b)} _ _ | record { quot = succ quot ; rem = succ rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } = record { quotient = negSucc quot ; rem = negSucc rem ; remSmall = inr ((λ ()) , remIsSmall) ; divAlg = applyEquality negSucc (succInjective (transitivity (equalityCommutative pr) t)) }
where
t : succ b *N succ quot +N succ rem ≡ succ (succ (succ b *N quot +N b) +N rem)
t rewrite Semiring.commutative ℕSemiring ((quot +N b *N quot) +N b) rem | Semiring.commutative ℕSemiring (succ rem) ((quot +N b *N quot) +N b) | multiplicationNIsCommutative b (succ quot) | equalityCommutative (Semiring.+Associative ℕSemiring quot (b *N quot) b) | Semiring.commutative ℕSemiring b (quot *N b) | multiplicationNIsCommutative b quot = refl
divAlg {negSucc a} {negSucc b} _ _ with divisionAlg (succ b) (succ a)
divAlg {negSucc a} {negSucc b} _ _ | record { quot = zero ; rem = zero ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } = exFalso (naughtE (transitivity (equalityCommutative (transitivity (Semiring.sumZeroRight ℕSemiring (b *N 0)) (multiplicationNIsCommutative b 0))) pr))
divAlg {negSucc a} {negSucc b} _ _ | record { quot = zero ; rem = succ rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } rewrite multiplicationNIsCommutative b 0 | equalityCommutative (succInjective pr) = record { quotient = nonneg 0 ; rem = negSucc rem ; remSmall = inr ((λ ()) , remIsSmall) ; divAlg = refl }
divAlg {negSucc a} {negSucc b} _ _ | record { quot = succ quot ; rem = zero ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } rewrite Semiring.sumZeroRight ℕSemiring (quot +N b *N succ quot) | Semiring.commutative ℕSemiring b (succ quot) = record { quotient = nonneg (succ quot) ; rem = nonneg 0 ; remSmall = inl refl ; divAlg = applyEquality negSucc (succInjective (transitivity (equalityCommutative pr) t)) }
where
t : succ (quot +N b *N succ quot) ≡ succ ((b +N quot *N b) +N quot)
t rewrite Semiring.commutative ℕSemiring quot (b *N succ quot) | multiplicationNIsCommutative b (succ quot) = refl
divAlg {negSucc a} {negSucc b} _ _ | record { quot = succ quot ; rem = succ rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = quotSmall } rewrite multiplicationNIsCommutative b (succ quot) | Semiring.commutative ℕSemiring quot (b +N quot *N b) | Semiring.commutative ℕSemiring ((b +N quot *N b) +N quot) (succ rem) | Semiring.commutative ℕSemiring rem ((b +N quot *N b) +N quot) = record { quotient = nonneg (succ quot) ; rem = negSucc rem ; remSmall = inr (((λ ()) , remIsSmall)) ; divAlg = applyEquality negSucc (equalityCommutative (succInjective pr)) }
ℤEuclideanDomain : EuclideanDomain ℤRing
EuclideanDomain.isIntegralDomain ℤEuclideanDomain = ℤIntDom
EuclideanDomain.norm ℤEuclideanDomain = norm'
EuclideanDomain.normSize ℤEuclideanDomain = normSize
EuclideanDomain.divisionAlg ℤEuclideanDomain {a} {b} a!=0 b!=0 = divAlg {a} {b} a!=0 b!=0
| {
"alphanum_fraction": 0.6966921572,
"avg_line_length": 107.1047619048,
"ext": "agda",
"hexsha": "d25f4770363dcd66d86a2e9d8fd21102ffeef4e7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Integers/RingStructure/EuclideanDomain.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Integers/RingStructure/EuclideanDomain.agda",
"max_line_length": 566,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Integers/RingStructure/EuclideanDomain.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 3764,
"size": 11246
} |
{-# OPTIONS --without-K --safe #-}
data D : Set where
c : D → D
variable
x y : D
data P : D → D → Set where
c : P (c x) (c y)
record Q (y : D) : Set where
G : .(Q y) → P x y → Set₁
G _ c = Set
| {
"alphanum_fraction": 0.4901960784,
"avg_line_length": 12.75,
"ext": "agda",
"hexsha": "2d9857d6038696178188ca700e7cc05a59fa2246",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue5611.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue5611.agda",
"max_line_length": 34,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue5611.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 83,
"size": 204
} |
{-# OPTIONS --without-K #-}
module hott.loop.sum where
open import sum
open import equality
open import function.core
open import function.extensionality
open import function.isomorphism
open import function.overloading
open import sets.nat
open import pointed
open import hott.equivalence
open import hott.level.core
open import hott.loop.core
open import hott.loop.properties
private
abstract
loop-sum' : ∀ {i}{j}{A : Set i}{B : A → Set j}(n : ℕ)
→ (hB : (a : A) → h n (B a))
→ {a₀ : A}{b₀ : B a₀}
→ Ω n {Σ A B} (a₀ , b₀) ≅ Ω n a₀
loop-sum' 0 hB {a₀}{b₀} = Σ-ap-iso refl≅ (λ a → contr-⊤-iso (hB a)) ·≅ ×-right-unit
loop-sum' {A = A}{B = B} (suc n) hB {a₀}{b₀} = Ω-iso n (sym≅ Σ-split-iso) refl
·≅ loop-sum' n λ p → hB _ _ _
loop-sum-β : ∀ {i}{j}{A : Set i}{B : A → Set j}(n : ℕ)
→ (hB : (a : A) → h n (B a))
→ {a₀ : A}{b₀ : B a₀}
→ (p : Ω n {Σ A B} (a₀ , b₀))
→ apply≅ (loop-sum' n hB) p ≡ mapΩ n proj₁ p
loop-sum-β zero hB p = refl
loop-sum-β (suc n) hB p
= loop-sum-β n _ (mapΩ n apΣ p)
· mapΩ-hom n apΣ proj₁ p
· funext-inv (ap proj₁ (ap (mapΩP n) lem)) p
where
lem : ∀ {i}{j}{A : Set i}{B : A → Set j}{a₀ : A}{b₀ : B a₀}
→ _≡_ {A = PMap (_≡_ {A = Σ A B} (a₀ , b₀) (a₀ , b₀) , refl) ((a₀ ≡ a₀) , refl)}
(proj₁ ∘ apΣ , refl)
(ap proj₁ , refl)
lem = apply≅ pmap-eq ((λ _ → refl) , refl)
loop-sum : ∀ {i}{j}{A : Set i}{B : A → Set j}(n : ℕ)
→ (hB : (a : A) → h n (B a))
→ {a₀ : A}{b₀ : B a₀}
→ Ω n {Σ A B} (a₀ , b₀) ≅ Ω n a₀
loop-sum n hB {a₀}{b₀} = ≈⇒≅ (mapΩ n proj₁ , subst weak-equiv eq we)
where
abstract
we : weak-equiv (apply (loop-sum' n hB {a₀}{b₀}))
we = proj₂ (≅⇒≈ (loop-sum' n hB))
eq : apply (loop-sum' n hB {a₀}{b₀}) ≡ mapΩ n proj₁
eq = funext (loop-sum-β n hB)
| {
"alphanum_fraction": 0.4844689379,
"avg_line_length": 35.0175438596,
"ext": "agda",
"hexsha": "dead2df931861e74d992cfcb5dbd6378c9ba339c",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/loop/sum.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/hott/loop/sum.agda",
"max_line_length": 92,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/hott/loop/sum.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 798,
"size": 1996
} |
module Oscar.Property.Associativity where
open import Oscar.Level
record Associativity
{𝔬} {⋆ : Set 𝔬}
{𝔪} {_⇒_ : ⋆ → ⋆ → Set 𝔪}
(_∙_ : ∀ {y z} → y ⇒ z → ∀ {x} → x ⇒ y → x ⇒ z)
{𝔮} (_≤_ : ∀ {x y} → x ⇒ y → x ⇒ y → Set 𝔮)
: Set (𝔬 ⊔ 𝔪 ⊔ 𝔮) where
field
associativity : ∀ {w x} (f : w ⇒ x) {y} (g : x ⇒ y) {z} (h : y ⇒ z) → ((h ∙ g) ∙ f) ≤ (h ∙ (g ∙ f))
open Associativity ⦃ … ⦄ public
association : ∀
{𝔬} {⋆ : Set 𝔬}
{𝔪} {_⇒_ : ⋆ → ⋆ → Set 𝔪}
(_∙_ : ∀ {y z} → y ⇒ z → ∀ {x} → x ⇒ y → x ⇒ z)
{𝔮} (_≤_ : ∀ {x y} → x ⇒ y → x ⇒ y → Set 𝔮)
⦃ _ : Associativity _∙_ _≤_ ⦄
→ ∀ {w x} (f : w ⇒ x) {y} (g : x ⇒ y) {z} (h : y ⇒ z) → ((h ∙ g) ∙ f) ≤ (h ∙ (g ∙ f))
association _∙_ _≤_ = associativity {_∙_ = _∙_} {_≤_ = _≤_}
| {
"alphanum_fraction": 0.4083557951,
"avg_line_length": 29.68,
"ext": "agda",
"hexsha": "c9836f2c5e23a421a45a0f5e02c58c939af50b7c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Property/Associativity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Property/Associativity.agda",
"max_line_length": 103,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Property/Associativity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 423,
"size": 742
} |
------------------------------------------------------------------------
-- Universe levels
------------------------------------------------------------------------
module Imports.Level where
postulate
Level : Set
zero : Level
suc : (i : Level) → Level
_⊔_ : Level -> Level -> Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
infixl 6 _⊔_
| {
"alphanum_fraction": 0.399543379,
"avg_line_length": 21.9,
"ext": "agda",
"hexsha": "6b173f9f82a29c67ca819f63bf807828a7116624",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/fail/Imports/Level.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/fail/Imports/Level.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/Imports/Level.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 99,
"size": 438
} |
module Mockingbird.Forest where
open import Mockingbird.Forest.Base public
| {
"alphanum_fraction": 0.8552631579,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "5bbef510aee552bc4fe9985285c7c0d29459c54d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Forest.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Forest.agda",
"max_line_length": 42,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Forest.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 18,
"size": 76
} |
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.lhs.unify:65 -v tc.irr:50 #-}
open import Agda.Builtin.Nat
data B {A : Set} : A → Set where
b : (a : A) → B a
data C {A : Set} : ∀ a → B {A} a → Set where
c : (a : A) → C a (b a)
id : ∀ x → C _ x → B 0
id x (c y) = {!!}
| {
"alphanum_fraction": 0.4753521127,
"avg_line_length": 20.2857142857,
"ext": "agda",
"hexsha": "490ded96b4af3479ed073fe910f238cb27a07d58",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/interaction/Issue2620.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/interaction/Issue2620.agda",
"max_line_length": 50,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/interaction/Issue2620.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 121,
"size": 284
} |
{-# OPTIONS --without-K #-}
module hw2 where
open import Level using (_⊔_)
open import Function using (id)
open import Data.Nat using (ℕ; suc; _+_; _*_)
open import Data.Empty using (⊥)
open import Data.Sum using (_⊎_; inj₁; inj₂)
import Level
infix 4 _≡_
recℕ : ∀ {ℓ} → (C : Set ℓ) → C → (ℕ → C → C) → ℕ → C
recℕ C z f 0 = z
recℕ C z f (suc n) = f n (recℕ C z f n)
indℕ : ∀ {ℓ}
→ (C : ℕ → Set ℓ)
→ C 0
→ ((n : ℕ) → C n → C (suc n))
→ (n : ℕ)
→ C n
indℕ C z f 0 = z
indℕ C z f (suc n) = f n (indℕ C z f n)
------------------------------------------------------------------------------
-- ≡
data _≡_ {ℓ} {A : Set ℓ} : (x y : A) → Set ℓ where
refl : (x : A) → x ≡ x
rec≡ : {A : Set} →
(R : A → A → Set) {reflexiveR : {a : A} → R a a} →
({x y : A} (p : x ≡ y) → R x y)
rec≡ R {reflR} (refl y) = reflR {y}
------------------------------------------------------------------------------
-- subst
subst : ∀ {ℓ} {A : Set ℓ} {C : A → Set ℓ} →
({x y : A} (p : x ≡ y) → C x → C y)
subst (refl x) = id
------------------------------------------------------------------------------
-- ∘
_∘_ : {A B C : Set} → (f : B → C) → (g : A → B) → A → C
f ∘ g = (λ a → f (g a))
module Circle1 where
private
data S¹* : Set where
base* : S¹*
S¹ : Set
S¹ = S¹*
base : S¹
base = base*
postulate
loop : base ≡ base
recS¹ : {C : Set} → (cbase : C) → (cloop : cbase ≡ cbase) → S¹ → C
recS¹ cbase cloop base* = cbase
-- postulate
-- βrecS¹ : {C : Set} → (cbase : C) → (cloop : cbase ≡ cbase)
-- → ap (recS¹ cbase cloop) loop ≡ cloop
-- indS¹ : {C : S¹ → Set}
-- → (cbase : C base) → (cloop : transport C look cbase ≡ cbase)
-- → apd (indS¹ {C} cbase cloop) loop ≡ cloop
| {
"alphanum_fraction": 0.4123303167,
"avg_line_length": 23.5733333333,
"ext": "agda",
"hexsha": "afb0f85544a5bfadc78b1923b4bdc0a1bb28e345",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andmkent/misc-HoTT",
"max_forks_repo_path": "hw2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andmkent/misc-HoTT",
"max_issues_repo_path": "hw2.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andmkent/misc-HoTT",
"max_stars_repo_path": "hw2.agda",
"max_stars_repo_stars_event_max_datetime": "2016-01-26T18:17:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-26T18:17:16.000Z",
"num_tokens": 705,
"size": 1768
} |
{- 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.ImplShared.Consensus.Types
------------------------------------------------------------------------------
open import Data.String using (String)
module LibraBFT.Impl.IO.OBM.Messages where
record ECPWire : Set where
constructor ECPWire∙new
field
--_ecpwWhy : Text -- for log visualization
--_ecpwEpoch : Epoch -- for log visualization; epoch of sender
--_ecpwRound : Round -- for log visualization; round of sender
_ecpwECP : EpochChangeProof
-- instance S.Serialize ECPWire
record EpRRqWire : Set where
constructor EpRRqWire∙new
field
--_eprrqwWhy : Text -- for log visualization
--_eprrqEpoch : Epoch -- for log visualization; epoch of sender
--_eprrqRound : Round -- for log visualization; round of sender
_eprrqEpRRq : EpochRetrievalRequest
-- instance S.Serialize EpRRqWire
data Input : Set where
IBlockRetrievalRequest : Instant → BlockRetrievalRequest → Input
IBlockRetrievalResponse : Instant → BlockRetrievalResponse → Input
IEpochChangeProof : AccountAddress → ECPWire → Input
IEpochRetrievalRequest : AccountAddress → EpRRqWire → Input
IInit : Instant → Input
IProposal : Instant → AccountAddress → ProposalMsg → Input
IReconfigLocalEpochChange : ReconfigEventEpochChange → Input
ISyncInfo : Instant → AccountAddress → SyncInfo → Input
ITimeout : Instant → String {-String is ThreadId-} → Epoch → Round → Input
IVote : Instant → AccountAddress → VoteMsg → Input
| {
"alphanum_fraction": 0.5682539683,
"avg_line_length": 50.1136363636,
"ext": "agda",
"hexsha": "16cc37fd3f48f690f6c239b32ffde98c6b6de50c",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z",
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/IO/OBM/Messages.agda",
"max_issues_count": 72,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/IO/OBM/Messages.agda",
"max_line_length": 111,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/IO/OBM/Messages.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z",
"num_tokens": 496,
"size": 2205
} |
------------------------------------------------------------------------------
-- Totality properties of the division
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Division.TotalityATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Program.Division.Division
open import FOTC.Program.Division.Specification
------------------------------------------------------------------------------
-- The division is total when the dividend is less than the divisor.
postulate div-x<y-N : ∀ {i j} → i < j → N (div i j)
{-# ATP prove div-x<y-N #-}
-- The division is total when the dividend is greater or equal than
-- the divisor.
-- N (div (i ∸ j) j) i ≮j → div i j ≡ succ (div (i ∸ j) j)
------------------------------------------------------------------
-- N (div i j)
postulate div-x≮y-N : ∀ {i j} →
(divSpec (i ∸ j) j (div (i ∸ j) j)) →
i ≮ j →
N (div i j)
{-# ATP prove div-x≮y-N #-}
| {
"alphanum_fraction": 0.4299287411,
"avg_line_length": 36.0857142857,
"ext": "agda",
"hexsha": "36bf6eaba4c26b72ef60d6002668c154bf377e14",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Division/TotalityATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Division/TotalityATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Division/TotalityATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 280,
"size": 1263
} |
module L0E where
open import Common
-- Syntax
data Conj : Set where
and or : Conj
data N : Set where
Saddie Liz Hank : N
data Vᵢ : Set where
snores sleeps is-boring : Vᵢ
data Vₜ : Set where
loves hates is-taller-than : Vₜ
data Neg : Set where
it-is-not-the-case-that : Neg
data VP : Set where
iv : Vᵢ -> VP
tv : Vₜ -> N -> VP
data S : Set where
sconjs : S -> Conj -> S -> S
negs : Neg -> S -> S
predvp : N -> VP -> S
example1 : S
example1 = predvp Saddie (iv snores)
example2 : S
example2 = predvp Liz (iv sleeps)
example3 : S
example3 = negs it-is-not-the-case-that (predvp Hank (iv snores))
example41 example42 : S
example41 = sconjs (sconjs (predvp Saddie (iv sleeps)) or (predvp Liz (iv is-boring))) and (predvp Hank (iv snores))
example42 = sconjs (predvp Saddie (iv sleeps)) or (sconjs (predvp Liz (iv is-boring)) and (predvp Hank (iv snores)))
example5 : S
example5 = negs it-is-not-the-case-that (negs it-is-not-the-case-that (predvp Saddie (iv sleeps)))
-- Semantics
data Individual : Set where
Anwar_Sadat : Individual
Queen_Elizabeth_II : Individual
Henry_Kissinger : Individual
⟦_⟧N : N -> Individual
⟦ Saddie ⟧N = Anwar_Sadat
⟦ Liz ⟧N = Queen_Elizabeth_II
⟦ Hank ⟧N = Henry_Kissinger
⟦_⟧̬̬̌Vᵢ : Vᵢ -> Individual -> Bool
⟦ snores ⟧̬̬̌Vᵢ Anwar_Sadat = true
⟦ snores ⟧̬̬̌Vᵢ Queen_Elizabeth_II = true
⟦ snores ⟧̬̬̌Vᵢ Henry_Kissinger = false
⟦ sleeps ⟧̬̬̌Vᵢ Anwar_Sadat = true
⟦ sleeps ⟧̬̬̌Vᵢ Queen_Elizabeth_II = false
⟦ sleeps ⟧̬̬̌Vᵢ Henry_Kissinger = false
⟦ is-boring ⟧̬̬̌Vᵢ Anwar_Sadat = true
⟦ is-boring ⟧̬̬̌Vᵢ Queen_Elizabeth_II = true
⟦ is-boring ⟧̬̬̌Vᵢ Henry_Kissinger = true
⟦_⟧Vₜ : Vₜ -> Individual -> Individual -> Bool
⟦ loves ⟧Vₜ Anwar_Sadat _ = true
⟦ loves ⟧Vₜ Queen_Elizabeth_II Anwar_Sadat = false
⟦ loves ⟧Vₜ Queen_Elizabeth_II Queen_Elizabeth_II = true
⟦ loves ⟧Vₜ Queen_Elizabeth_II Henry_Kissinger = false
⟦ loves ⟧Vₜ Henry_Kissinger Anwar_Sadat = true
⟦ loves ⟧Vₜ Henry_Kissinger Queen_Elizabeth_II = false
⟦ loves ⟧Vₜ Henry_Kissinger Henry_Kissinger = true
⟦ hates ⟧Vₜ Anwar_Sadat _ = false
⟦ hates ⟧Vₜ Queen_Elizabeth_II Anwar_Sadat = true
⟦ hates ⟧Vₜ Queen_Elizabeth_II Queen_Elizabeth_II = false
⟦ hates ⟧Vₜ Queen_Elizabeth_II Henry_Kissinger = true
⟦ hates ⟧Vₜ Henry_Kissinger Anwar_Sadat = false
⟦ hates ⟧Vₜ Henry_Kissinger Queen_Elizabeth_II = true
⟦ hates ⟧Vₜ Henry_Kissinger Henry_Kissinger = false
⟦ is-taller-than ⟧Vₜ Anwar_Sadat Anwar_Sadat = false
⟦ is-taller-than ⟧Vₜ Anwar_Sadat Queen_Elizabeth_II = true
⟦ is-taller-than ⟧Vₜ Anwar_Sadat Henry_Kissinger = false
⟦ is-taller-than ⟧Vₜ Queen_Elizabeth_II _ = false
⟦ is-taller-than ⟧Vₜ Henry_Kissinger Anwar_Sadat = true
⟦ is-taller-than ⟧Vₜ Henry_Kissinger Queen_Elizabeth_II = true
⟦ is-taller-than ⟧Vₜ Henry_Kissinger Henry_Kissinger = false
⟦_⟧VP : VP -> Individual -> Bool
⟦ iv v ⟧VP = ⟦ v ⟧̬̬̌Vᵢ
⟦ tv v n ⟧VP = ⟦ v ⟧Vₜ ⟦ n ⟧N
⟦_⟧S : S -> Bool
⟦ sconjs x and x₂ ⟧S = ⟦ x ⟧S && ⟦ x₂ ⟧S
⟦ sconjs x or x₂ ⟧S = ⟦ x ⟧S || ⟦ x₂ ⟧S
⟦ negs x x₁ ⟧S = neg ⟦ x₁ ⟧S
⟦ predvp x x₁ ⟧S = ⟦ x₁ ⟧VP ⟦ x ⟧N
| {
"alphanum_fraction": 0.6985850609,
"avg_line_length": 28.4018691589,
"ext": "agda",
"hexsha": "1c4813e7422fc37b1d25a2dc5eddb6a0e927ed2e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9f8bbff7248dbeb54919e03957daf9b35ec1ac23",
"max_forks_repo_licenses": [
"Artistic-2.0"
],
"max_forks_repo_name": "daherb/Agda-Montague",
"max_forks_repo_path": "L0E.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f8bbff7248dbeb54919e03957daf9b35ec1ac23",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Artistic-2.0"
],
"max_issues_repo_name": "daherb/Agda-Montague",
"max_issues_repo_path": "L0E.agda",
"max_line_length": 116,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9f8bbff7248dbeb54919e03957daf9b35ec1ac23",
"max_stars_repo_licenses": [
"Artistic-2.0"
],
"max_stars_repo_name": "daherb/Agda-Montague",
"max_stars_repo_path": "L0E.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-18T11:56:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-18T11:56:24.000Z",
"num_tokens": 1308,
"size": 3039
} |
-- There was a problem with open public in parameterised modules.
module Issue165 where
postulate X : Set
module M where
postulate P : Set
module R₀ (X : Set) where
open M public
module R₁ (X : Set) where
open R₀ X public
open R₁ X
postulate p : P
| {
"alphanum_fraction": 0.7115384615,
"avg_line_length": 14.4444444444,
"ext": "agda",
"hexsha": "c9c4589a656323fa5e0bec16f50bfb4f69637d12",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue165.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue165.agda",
"max_line_length": 65,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue165.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 79,
"size": 260
} |
-- In this file we consider the special of localising at a single
-- element f : R (or rather the set of powers of f). This is also
-- known as inverting f.
-- We then prove that localising first at an element f and at an element
-- g (or rather the image g/1) is the same as localising at the product f·g
-- This fact has an important application in algebraic geometry where it's
-- used to define the structure sheaf of a commutative ring.
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Localisation.InvertingElements where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
module _(R' : CommRing ℓ) where
open isMultClosedSubset
private R = fst R'
open CommRingStr (snd R')
open Exponentiation R'
[_ⁿ|n≥0] : R → ℙ R
[ f ⁿ|n≥0] g = (∃[ n ∈ ℕ ] g ≡ f ^ n) , isPropPropTrunc
-- Σ[ n ∈ ℕ ] (s ≡ f ^ n) × (∀ m → s ≡ f ^ m → n ≤ m) maybe better, this isProp:
-- (n,s≡fⁿ,p) (m,s≡fᵐ,q) then n≤m by p and m≤n by q => n≡m
powersFormMultClosedSubset : (f : R) → isMultClosedSubset R' [ f ⁿ|n≥0]
powersFormMultClosedSubset f .containsOne = PT.∣ zero , refl ∣
powersFormMultClosedSubset f .multClosed =
PT.map2 λ (m , p) (n , q) → (m +ℕ n) , (λ i → (p i) · (q i)) ∙ ·-of-^-is-^-of-+ f m n
R[1/_] : R → Type ℓ
R[1/ f ] = Loc.S⁻¹R R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
R[1/_]AsCommRing : R → CommRing ℓ
R[1/ f ]AsCommRing = Loc.S⁻¹RAsCommRing R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
-- A useful lemma: (gⁿ/1)≡(g/1)ⁿ in R[1/f]
^-respects-/1 : {f g : R} (n : ℕ) → [ (g ^ n) , 1r , PT.∣ 0 , (λ _ → 1r) ∣ ] ≡
Exponentiation._^_ R[1/ f ]AsCommRing [ g , 1r , powersFormMultClosedSubset _ .containsOne ] n
^-respects-/1 zero = refl
^-respects-/1 {f} {g} (suc n) = eq/ _ _ ( (1r , powersFormMultClosedSubset f .containsOne)
, cong (1r · (g · (g ^ n)) ·_) (·Lid 1r))
∙ cong (CommRingStr._·_ (R[1/ f ]AsCommRing .snd)
[ g , 1r , powersFormMultClosedSubset f .containsOne ]) (^-respects-/1 n)
-- A slight improvement for eliminating into propositions
InvElPropElim : {f : R} {P : R[1/ f ] → Type ℓ'}
→ (∀ x → isProp (P x))
→ (∀ (r : R) (n : ℕ) → P [ r , (f ^ n) , PT.∣ n , refl ∣ ]) -- ∀ r n → P (r/fⁿ)
----------------------------------------------------------
→ (∀ x → P x)
InvElPropElim {f = f} {P = P} PisProp base = elimProp (λ _ → PisProp _) []-case
where
S[f] = Loc.S R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
[]-case : (a : R × S[f]) → P [ a ]
[]-case (r , s , s∈S[f]) = PT.rec (PisProp _) Σhelper s∈S[f]
where
Σhelper : Σ[ n ∈ ℕ ] s ≡ f ^ n → P [ r , s , s∈S[f] ]
Σhelper (n , p) = subst P (cong [_] (≡-× refl (Σ≡Prop (λ _ → isPropPropTrunc) (sym p)))) (base r n)
-- For predicates over the set of powers
powersPropElim : {f : R} {P : R → Type ℓ'}
→ (∀ x → isProp (P x))
→ (∀ n → P (f ^ n))
------------------------------
→ ∀ s → s ∈ [ f ⁿ|n≥0] → P s
powersPropElim {f = f} {P = P} PisProp base s =
PT.rec (PisProp s) λ (n , p) → subst P (sym p) (base n)
module DoubleLoc (R' : CommRing ℓ) (f g : (fst R')) where
open isMultClosedSubset
open CommRingStr (snd R')
open CommRingTheory R'
open Exponentiation R'
open RingTheory (CommRing→Ring R')
open CommRingStr (snd (R[1/_]AsCommRing R' f)) renaming ( _·_ to _·ᶠ_ ; 1r to 1ᶠ
; _+_ to _+ᶠ_ ; 0r to 0ᶠ
; ·Lid to ·ᶠ-lid ; ·Rid to ·ᶠ-rid
; ·Assoc to ·ᶠ-assoc ; ·-comm to ·ᶠ-comm)
open IsRingHom
private
R = fst R'
R[1/f] = R[1/_] R' f
R[1/f]AsCommRing = R[1/_]AsCommRing R' f
R[1/fg] = R[1/_] R' (f · g)
R[1/fg]AsCommRing = R[1/_]AsCommRing R' (f · g)
R[1/f][1/g] = R[1/_] (R[1/_]AsCommRing R' f)
[ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
R[1/f][1/g]AsCommRing = R[1/_]AsCommRing (R[1/_]AsCommRing R' f)
[ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
R[1/f][1/g]ˣ = R[1/f][1/g]AsCommRing ˣ
_/1/1 : R → R[1/f][1/g]
r /1/1 = [ [ r , 1r , PT.∣ 0 , refl ∣ ] , 1ᶠ , PT.∣ 0 , refl ∣ ]
/1/1AsCommRingHom : CommRingHom R' R[1/f][1/g]AsCommRing
fst /1/1AsCommRingHom = _/1/1
snd /1/1AsCommRingHom = makeIsRingHom refl lem+ lem·
where
lem+ : _
lem+ r r' =
cong [_]
(≡-×
(cong [_]
(≡-×
(cong₂ _+_
(sym (·Rid _) ∙ (λ i → (·Rid r (~ i)) · (·Rid 1r (~ i))))
(sym (·Rid _) ∙ (λ i → (·Rid r' (~ i)) · (·Rid 1r (~ i)))))
(Σ≡Prop (λ _ → isPropPropTrunc)
(sym (·Lid _) ∙ (λ i → (·Lid 1r (~ i)) · (·Lid 1r (~ i)))))))
(Σ≡Prop (λ _ → isPropPropTrunc) (sym (·ᶠ-lid 1ᶠ))))
lem· : _
lem· r r' =
cong [_]
(≡-×
(cong [_] (≡-× refl (Σ≡Prop (λ _ → isPropPropTrunc) (sym (·Lid _)))))
(Σ≡Prop (λ _ → isPropPropTrunc) (sym (·ᶠ-lid 1ᶠ))))
-- this will give us a map R[1/fg] → R[1/f][1/g] by the universal property of localisation
fⁿgⁿ/1/1∈R[1/f][1/g]ˣ : (s : R) → s ∈ ([_ⁿ|n≥0] R' (f · g)) → s /1/1 ∈ R[1/f][1/g]ˣ
fⁿgⁿ/1/1∈R[1/f][1/g]ˣ = powersPropElim R' (λ s → R[1/f][1/g]ˣ (s /1/1) .snd) ℕcase
where
ℕcase : (n : ℕ) → ((f · g) ^ n) /1/1 ∈ R[1/f][1/g]ˣ
ℕcase n = [ [ 1r , (f ^ n) , PT.∣ n , refl ∣ ]
, [ (g ^ n) , 1r , PT.∣ 0 , refl ∣ ] --denominator
, PT.∣ n , ^-respects-/1 _ n ∣ ]
, eq/ _ _ ((1ᶠ , powersFormMultClosedSubset _ _ .containsOne)
, eq/ _ _ ((1r , powersFormMultClosedSubset _ _ .containsOne) , path))
where
eq1 : ∀ x → 1r · (1r · (x · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡ x
eq1 = solve R'
eq2 : ∀ x y → x · y ≡ 1r · (1r · 1r · (1r · y)) · (1r · (1r · x) · 1r)
eq2 = solve R'
path : 1r · (1r · ((f · g) ^ n · 1r) · 1r) · (1r · 1r · (1r · 1r))
≡ 1r · (1r · 1r · (1r · g ^ n)) · (1r · (1r · f ^ n) · 1r)
path = 1r · (1r · ((f · g) ^ n · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡⟨ eq1 ((f · g) ^ n) ⟩
(f · g) ^ n ≡⟨ ^-ldist-· _ _ _ ⟩
f ^ n · g ^ n ≡⟨ eq2 (f ^ n) (g ^ n) ⟩
1r · (1r · 1r · (1r · g ^ n)) · (1r · (1r · f ^ n) · 1r) ∎
-- the main result: localising at one element and then at another is
-- the same as localising at the product.
-- takes forever to compute without experimental lossy unification
R[1/fg]≡R[1/f][1/g] : R[1/fg]AsCommRing ≡ R[1/f][1/g]AsCommRing
R[1/fg]≡R[1/f][1/g] = S⁻¹RChar R' ([_ⁿ|n≥0] R' (f · g))
(powersFormMultClosedSubset R' (f · g)) _ /1/1AsCommRingHom pathtoR[1/fg]
where
open PathToS⁻¹R
pathtoR[1/fg] : PathToS⁻¹R R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
R[1/f][1/g]AsCommRing /1/1AsCommRingHom
φS⊆Aˣ pathtoR[1/fg] = fⁿgⁿ/1/1∈R[1/f][1/g]ˣ
kerφ⊆annS pathtoR[1/fg] r p = toGoal helperR[1/f]
where
open RingTheory (CommRing→Ring R[1/f]AsCommRing) renaming ( 0RightAnnihilates to 0ᶠRightAnnihilates
; 0LeftAnnihilates to 0ᶠ-leftNullifies)
open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^ᶠ_)
hiding (·-of-^-is-^-of-+ ; ^-ldist-·)
S[f] = Loc.S R' ([_ⁿ|n≥0] R' f) (powersFormMultClosedSubset R' f)
S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
g/1 : R[1/_] R' f
g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
S[g/1] = Loc.S R[1/f]AsCommRing
([_ⁿ|n≥0] R[1/f]AsCommRing g/1)
(powersFormMultClosedSubset R[1/f]AsCommRing g/1)
r/1 : R[1/_] R' f
r/1 = [ r , 1r , powersFormMultClosedSubset R' f .containsOne ]
-- this is the crucial step, modulo truncation we can take p to be generated
-- by the quotienting relation of localisation. Note that we wouldn't be able
-- to prove our goal if kerφ⊆annS was formulated with a Σ instead of a ∃
∥r/1,1/1≈0/1,1/1∥ : ∃[ u ∈ S[g/1] ] fst u ·ᶠ r/1 ·ᶠ 1ᶠ ≡ fst u ·ᶠ 0ᶠ ·ᶠ 1ᶠ
∥r/1,1/1≈0/1,1/1∥ = Iso.fun (SQ.isEquivRel→TruncIso (Loc.locIsEquivRel _ _ _) _ _) p
helperR[1/f] : ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ
helperR[1/f] = PT.rec isPropPropTrunc
(uncurry (uncurry (powersPropElim R[1/f]AsCommRing
(λ _ → isPropΠ (λ _ → isPropPropTrunc)) baseCase)))
∥r/1,1/1≈0/1,1/1∥
where
baseCase : ∀ n → g/1 ^ᶠ n ·ᶠ r/1 ·ᶠ 1ᶠ ≡ g/1 ^ᶠ n ·ᶠ 0ᶠ ·ᶠ 1ᶠ
→ ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ
baseCase n q = PT.∣ n , path ∣
where
path : [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ
path = [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ]
≡⟨ cong [_] (≡-× refl (Σ≡Prop (λ _ → isPropPropTrunc) (sym (·Rid _)))) ⟩
[ g ^ n , 1r , PT.∣ 0 , refl ∣ ] ·ᶠ r/1
≡⟨ cong (_·ᶠ r/1) (^-respects-/1 _ n) ⟩
g/1 ^ᶠ n ·ᶠ r/1
≡⟨ sym (·ᶠ-rid _) ⟩
g/1 ^ᶠ n ·ᶠ r/1 ·ᶠ 1ᶠ
≡⟨ q ⟩
g/1 ^ᶠ n ·ᶠ 0ᶠ ·ᶠ 1ᶠ
≡⟨ cong (_·ᶠ 1ᶠ) (0ᶠRightAnnihilates _) ∙ 0ᶠ-leftNullifies 1ᶠ ⟩
0ᶠ ∎
toGoal : ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ
→ ∃[ u ∈ S[fg] ] fst u · r ≡ 0r
toGoal = PT.rec isPropPropTrunc Σhelper
where
Σhelper : Σ[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ
→ ∃[ u ∈ S[fg] ] fst u · r ≡ 0r
Σhelper (n , q) = PT.map Σhelper2 helperR
where
-- now, repeat the above strategy with q
∥gⁿr≈0∥ : ∃[ u ∈ S[f] ] fst u · (g ^ n · r) · 1r ≡ fst u · 0r · 1r
∥gⁿr≈0∥ = Iso.fun (SQ.isEquivRel→TruncIso (Loc.locIsEquivRel _ _ _) _ _) q
helperR : ∃[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r
helperR = PT.rec isPropPropTrunc
(uncurry (uncurry (powersPropElim R'
(λ _ → isPropΠ (λ _ → isPropPropTrunc)) baseCase)))
∥gⁿr≈0∥
where
baseCase : (m : ℕ) → f ^ m · (g ^ n · r) · 1r ≡ f ^ m · 0r · 1r
→ ∃[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r
baseCase m q' = PT.∣ m , path ∣
where
path : f ^ m · g ^ n · r ≡ 0r
path = (λ i → ·Rid (·Assoc (f ^ m) (g ^ n) r (~ i)) (~ i))
∙∙ q' ∙∙ (λ i → ·Rid (0RightAnnihilates (f ^ m) i) i)
Σhelper2 : Σ[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r
→ Σ[ u ∈ S[fg] ] fst u · r ≡ 0r
Σhelper2 (m , q') = (((f · g) ^ l) , PT.∣ l , refl ∣) , path
where
l = max m n
path : (f · g) ^ l · r ≡ 0r
path = (f · g) ^ l · r
≡⟨ cong (_· r) (^-ldist-· _ _ _) ⟩
f ^ l · g ^ l · r
≡⟨ cong₂ (λ x y → f ^ x · g ^ y · r) (sym (≤-∸-+-cancel {m = m} left-≤-max))
(sym (≤-∸-+-cancel {m = n} right-≤-max)) ⟩
f ^ (l ∸ m +ℕ m) · g ^ (l ∸ n +ℕ n) · r
≡⟨ cong₂ (λ x y → x · y · r) (sym (·-of-^-is-^-of-+ _ _ _))
(sym (·-of-^-is-^-of-+ _ _ _)) ⟩
f ^ (l ∸ m) · f ^ m · (g ^ (l ∸ n) · g ^ n) · r
≡⟨ cong (_· r) (·-commAssocSwap _ _ _ _) ⟩
f ^ (l ∸ m) · g ^ (l ∸ n) · (f ^ m · g ^ n) · r
≡⟨ sym (·Assoc _ _ _) ⟩
f ^ (l ∸ m) · g ^ (l ∸ n) · (f ^ m · g ^ n · r)
≡⟨ cong (f ^ (l ∸ m) · g ^ (l ∸ n) ·_) q' ⟩
f ^ (l ∸ m) · g ^ (l ∸ n) · 0r
≡⟨ 0RightAnnihilates _ ⟩
0r ∎
surχ pathtoR[1/fg] = InvElPropElim _ (λ _ → isPropPropTrunc) toGoal
where
open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^ᶠ_)
hiding (·-of-^-is-^-of-+ ; ^-ldist-·)
open CommRingStr (snd R[1/f][1/g]AsCommRing) renaming (_·_ to _·R[1/f][1/g]_)
hiding (1r ; ·Lid ; ·Rid ; ·Assoc)
open Units R[1/f][1/g]AsCommRing
g/1 : R[1/_] R' f
g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
baseCase : (r : R) (m n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1)
≡ [ [ r , f ^ m , PT.∣ m , refl ∣ ]
, [ g ^ n , 1r , PT.∣ 0 , refl ∣ ] , PT.∣ n , ^-respects-/1 _ n ∣ ]
·R[1/f][1/g] (x .snd .fst /1/1)
baseCase r m n = PT.∣ ((r · f ^ (l ∸ m) · g ^ (l ∸ n)) -- x .fst
, (f · g) ^ l , PT.∣ l , refl ∣) -- x .snd
, eq/ _ _ ((1ᶠ , PT.∣ 0 , refl ∣) , eq/ _ _ ((1r , PT.∣ 0 , refl ∣) , path)) ∣
-- reduce equality of double fractions into equality in R
where
eq1 : ∀ r flm gln gn fm
→ 1r · (1r · (r · flm · gln) · (gn · 1r)) · (1r · (fm · 1r) · 1r)
≡ r · flm · (gln · gn) · fm
eq1 = solve R'
eq2 : ∀ r flm gl fm → r · flm · gl · fm ≡ r · (flm · fm ) · gl
eq2 = solve R'
eq3 : ∀ r fgl → r · fgl ≡ 1r · (1r · (r · fgl) · 1r) · (1r · 1r · (1r · 1r))
eq3 = solve R'
l = max m n
path : 1r · (1r · (r · f ^ (l ∸ m) · g ^ (l ∸ n)) · (g ^ n · 1r)) · (1r · (f ^ m · 1r) · 1r)
≡ 1r · (1r · (r · (f · g) ^ l) · 1r) · (1r · 1r · (1r · 1r))
path = 1r · (1r · (r · f ^ (l ∸ m) · g ^ (l ∸ n)) · (g ^ n · 1r)) · (1r · (f ^ m · 1r) · 1r)
≡⟨ eq1 r (f ^ (l ∸ m)) (g ^ (l ∸ n)) (g ^ n) (f ^ m) ⟩
r · f ^ (l ∸ m) · (g ^ (l ∸ n) · g ^ n) · f ^ m
≡⟨ cong (λ x → r · f ^ (l ∸ m) · x · f ^ m) (·-of-^-is-^-of-+ _ _ _) ⟩
r · f ^ (l ∸ m) · g ^ (l ∸ n +ℕ n) · f ^ m
≡⟨ cong (λ x → r · f ^ (l ∸ m) · g ^ x · f ^ m) (≤-∸-+-cancel right-≤-max) ⟩
r · f ^ (l ∸ m) · g ^ l · f ^ m
≡⟨ eq2 r (f ^ (l ∸ m)) (g ^ l) (f ^ m) ⟩
r · (f ^ (l ∸ m) · f ^ m) · g ^ l
≡⟨ cong (λ x → r · x · g ^ l) (·-of-^-is-^-of-+ _ _ _) ⟩
r · f ^ (l ∸ m +ℕ m) · g ^ l
≡⟨ cong (λ x → r · f ^ x · g ^ l) (≤-∸-+-cancel left-≤-max) ⟩
r · f ^ l · g ^ l
≡⟨ sym (·Assoc _ _ _) ⟩
r · (f ^ l · g ^ l)
≡⟨ cong (r ·_) (sym (^-ldist-· _ _ _)) ⟩
r · (f · g) ^ l
≡⟨ eq3 r ((f · g) ^ l) ⟩
1r · (1r · (r · (f · g) ^ l) · 1r) · (1r · 1r · (1r · 1r)) ∎
base-^ᶠ-helper : (r : R) (m n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1)
≡ [ [ r , f ^ m , PT.∣ m , refl ∣ ]
, g/1 ^ᶠ n , PT.∣ n , refl ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1)
base-^ᶠ-helper r m n = subst (λ y → ∃[ x ∈ R × S[fg] ] (x .fst /1/1)
≡ [ [ r , f ^ m , PT.∣ m , refl ∣ ] , y ] ·R[1/f][1/g] (x .snd .fst /1/1))
(Σ≡Prop (λ _ → isPropPropTrunc) (^-respects-/1 _ n)) (baseCase r m n)
indStep : (r : R[1/_] R' f) (n : ℕ) → ∃[ x ∈ R × S[fg] ]
(x .fst /1/1) ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1)
indStep = InvElPropElim _ (λ _ → isPropΠ λ _ → isPropPropTrunc) base-^ᶠ-helper
toGoal : (r : R[1/_] R' f) (n : ℕ) → ∃[ x ∈ R × S[fg] ]
(x .fst /1/1) ·R[1/f][1/g]
((x .snd .fst /1/1) ⁻¹) ⦃ φS⊆Aˣ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) ⦄
≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ]
toGoal r n = PT.map Σhelper (indStep r n)
where
Σhelper : Σ[ x ∈ R × S[fg] ]
(x .fst /1/1) ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1)
→ Σ[ x ∈ R × S[fg] ]
(x .fst /1/1) ·R[1/f][1/g] ((x .snd .fst /1/1) ⁻¹)
⦃ φS⊆Aˣ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) ⦄
≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ]
Σhelper ((r' , s , s∈S[fg]) , p) = (r' , s , s∈S[fg])
, ⁻¹-eq-elim ⦃ φS⊆Aˣ pathtoR[1/fg] s s∈S[fg] ⦄ p
-- In this module we construct the map R[1/fg]→R[1/f][1/g] directly
-- and show that it is equal (although not judgementally) to the map induced
-- by the universal property of localisation, i.e. transporting along the path
-- constructed above. Given that this is the easier direction, we can see that
-- it is pretty cumbersome to prove R[1/fg]≡R[1/f][1/g] directly,
-- which illustrates the usefulness of S⁻¹RChar quite well.
private
module check where
φ : R[1/fg] → R[1/f][1/g]
φ = SQ.rec squash/ ϕ ϕcoh
where
S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
curriedϕΣ : (r s : R) → Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n → R[1/f][1/g]
curriedϕΣ r s (n , s≡fg^n) = [ [ r , (f ^ n) , PT.∣ n , refl ∣ ]
, [ (g ^ n) , 1r , PT.∣ 0 , refl ∣ ] --denominator
, PT.∣ n , ^-respects-/1 R' n ∣ ]
curriedϕ : (r s : R) → ∃[ n ∈ ℕ ] s ≡ (f · g) ^ n → R[1/f][1/g]
curriedϕ r s = elim→Set (λ _ → squash/) (curriedϕΣ r s) coh
where
coh : (x y : Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n) → curriedϕΣ r s x ≡ curriedϕΣ r s y
coh (n , s≡fg^n) (m , s≡fg^m) = eq/ _ _ ((1ᶠ , PT.∣ 0 , refl ∣) ,
eq/ _ _ ( (1r , powersFormMultClosedSubset R' f .containsOne)
, path))
where
eq1 : ∀ r gm fm → 1r · (1r · r · gm) · (1r · fm · 1r) ≡ r · (gm · fm)
eq1 = solve R'
path : 1r · (1r · r · (g ^ m)) · (1r · (f ^ m) · 1r)
≡ 1r · (1r · r · (g ^ n)) · (1r · (f ^ n) · 1r)
path = 1r · (1r · r · (g ^ m)) · (1r · (f ^ m) · 1r)
≡⟨ eq1 r (g ^ m) (f ^ m) ⟩
r · (g ^ m · f ^ m)
≡⟨ cong (r ·_) (sym (^-ldist-· g f m)) ⟩
r · ((g · f) ^ m)
≡⟨ cong (λ x → r · (x ^ m)) (·-comm _ _) ⟩
r · ((f · g) ^ m)
≡⟨ cong (r ·_) ((sym s≡fg^m) ∙ s≡fg^n) ⟩
r · ((f · g) ^ n)
≡⟨ cong (λ x → r · (x ^ n)) (·-comm _ _) ⟩
r · ((g · f) ^ n)
≡⟨ cong (r ·_) (^-ldist-· g f n) ⟩
r · (g ^ n · f ^ n)
≡⟨ sym (eq1 r (g ^ n) (f ^ n)) ⟩
1r · (1r · r · (g ^ n)) · (1r · (f ^ n) · 1r) ∎
ϕ : R × S[fg] → R[1/f][1/g]
ϕ = uncurry2 curriedϕ -- λ (r / (fg)ⁿ) → ((r / fⁿ) / gⁿ)
curriedϕcohΣ : (r s r' s' u : R) → (p : u · r · s' ≡ u · r' · s)
→ (α : Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n)
→ (β : Σ[ m ∈ ℕ ] s' ≡ (f · g) ^ m)
→ (γ : Σ[ l ∈ ℕ ] u ≡ (f · g) ^ l)
→ ϕ (r , s , PT.∣ α ∣) ≡ ϕ (r' , s' , PT.∣ β ∣)
curriedϕcohΣ r s r' s' u p (n , s≡fgⁿ) (m , s'≡fgᵐ) (l , u≡fgˡ) =
eq/ _ _ ( ( [ (g ^ l) , 1r , powersFormMultClosedSubset R' f .containsOne ]
, PT.∣ l , ^-respects-/1 R' l ∣)
, eq/ _ _ ((f ^ l , PT.∣ l , refl ∣) , path))
where
eq1 : ∀ fl gl r gm fm
→ fl · (gl · r · gm) · (1r · fm · 1r) ≡ fl · gl · r · (gm · fm)
eq1 = solve R'
path : f ^ l · (g ^ l · transp (λ i → R) i0 r · transp (λ i → R) i0 (g ^ m))
· (1r · transp (λ i → R) i0 (f ^ m) · transp (λ i → R) i0 1r)
≡ f ^ l · (g ^ l · transp (λ i → R) i0 r' · transp (λ i → R) i0 (g ^ n))
· (1r · transp (λ i → R) i0 (f ^ n) · transp (λ i → R) i0 1r)
path = f ^ l · (g ^ l · transp (λ i → R) i0 r · transp (λ i → R) i0 (g ^ m))
· (1r · transp (λ i → R) i0 (f ^ m) · transp (λ i → R) i0 1r)
≡⟨ (λ i → f ^ l · (g ^ l · transportRefl r i · transportRefl (g ^ m) i)
· (1r · transportRefl (f ^ m) i · transportRefl 1r i)) ⟩
f ^ l · (g ^ l · r · g ^ m) · (1r · f ^ m · 1r)
≡⟨ eq1 (f ^ l) (g ^ l) r (g ^ m) (f ^ m) ⟩
f ^ l · g ^ l · r · (g ^ m · f ^ m)
≡⟨ (λ i → ^-ldist-· f g l (~ i) · r · ^-ldist-· g f m (~ i)) ⟩
(f · g) ^ l · r · (g · f) ^ m
≡⟨ cong (λ x → (f · g) ^ l · r · x ^ m) (·-comm _ _) ⟩
(f · g) ^ l · r · (f · g) ^ m
≡⟨ (λ i → u≡fgˡ (~ i) · r · s'≡fgᵐ (~ i)) ⟩
u · r · s'
≡⟨ p ⟩
u · r' · s
≡⟨ (λ i → u≡fgˡ i · r' · s≡fgⁿ i) ⟩
(f · g) ^ l · r' · (f · g) ^ n
≡⟨ cong (λ x → (f · g) ^ l · r' · x ^ n) (·-comm _ _) ⟩
(f · g) ^ l · r' · (g · f) ^ n
≡⟨ (λ i → ^-ldist-· f g l i · r' · ^-ldist-· g f n i) ⟩
f ^ l · g ^ l · r' · (g ^ n · f ^ n)
≡⟨ sym (eq1 (f ^ l) (g ^ l) r' (g ^ n) (f ^ n)) ⟩
f ^ l · (g ^ l · r' · g ^ n) · (1r · f ^ n · 1r)
≡⟨ (λ i → f ^ l · (g ^ l · transportRefl r' (~ i) · transportRefl (g ^ n) (~ i))
· (1r · transportRefl (f ^ n) (~ i) · transportRefl 1r (~ i))) ⟩
f ^ l · (g ^ l · transp (λ i → R) i0 r' · transp (λ i → R) i0 (g ^ n))
· (1r · transp (λ i → R) i0 (f ^ n) · transp (λ i → R) i0 1r) ∎
curriedϕcoh : (r s r' s' u : R) → (p : u · r · s' ≡ u · r' · s)
→ (α : ∃[ n ∈ ℕ ] s ≡ (f · g) ^ n)
→ (β : ∃[ m ∈ ℕ ] s' ≡ (f · g) ^ m)
→ (γ : ∃[ l ∈ ℕ ] u ≡ (f · g) ^ l)
→ ϕ (r , s , α) ≡ ϕ (r' , s' , β)
curriedϕcoh r s r' s' u p = PT.elim (λ _ → isPropΠ2 (λ _ _ → squash/ _ _))
λ α → PT.elim (λ _ → isPropΠ (λ _ → squash/ _ _))
λ β → PT.rec (squash/ _ _)
λ γ → curriedϕcohΣ r s r' s' u p α β γ
ϕcoh : (a b : R × S[fg])
→ Loc._≈_ R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) a b
→ ϕ a ≡ ϕ b
ϕcoh (r , s , α) (r' , s' , β) ((u , γ) , p) = curriedϕcoh r s r' s' u p α β γ
-- the map induced by the universal property
open S⁻¹RUniversalProp R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g))
χ : R[1/fg] → R[1/f][1/g]
χ = S⁻¹RHasUniversalProp R[1/f][1/g]AsCommRing /1/1AsCommRingHom fⁿgⁿ/1/1∈R[1/f][1/g]ˣ .fst .fst .fst
-- the sanity check:
-- both maps send a fraction r/(fg)ⁿ to a double fraction,
-- where numerator and denominator are almost the same fraction respectively.
-- unfortunately the proofs that the denominators are powers are quite different for
-- the two maps, but of course we can ignore them.
-- The definition of χ introduces a lot of (1r ·_). Perhaps most surprisingly,
-- we have to give the path eq1 for the equality of the numerator of the numerator.
φ≡χ : ∀ r → φ r ≡ χ r
φ≡χ = InvElPropElim _ (λ _ → squash/ _ _) ℕcase
where
ℕcase : (r : R) (n : ℕ)
→ φ [ r , (f · g) ^ n , PT.∣ n , refl ∣ ] ≡ χ [ r , (f · g) ^ n , PT.∣ n , refl ∣ ]
ℕcase r n = cong [_] (ΣPathP --look into the components of the double-fractions
( cong [_] (ΣPathP (eq1 , Σ≡Prop (λ x → S'[f] x .snd) (sym (·Lid _))))
, Σ≡Prop (λ x → S'[f][g] x .snd) --ignore proof that denominator is power of g/1
( cong [_] (ΣPathP (sym (·Lid _) , Σ≡Prop (λ x → S'[f] x .snd) (sym (·Lid _)))))))
where
S'[f] = ([_ⁿ|n≥0] R' f)
S'[f][g] = ([_ⁿ|n≥0] R[1/f]AsCommRing [ g , 1r , powersFormMultClosedSubset R' f .containsOne ])
eq1 : transp (λ i → fst R') i0 r ≡ r · transp (λ i → fst R') i0 1r
eq1 = transportRefl r ∙∙ sym (·Rid r) ∙∙ cong (r ·_) (sym (transportRefl 1r))
| {
"alphanum_fraction": 0.4375452134,
"avg_line_length": 41.0594059406,
"ext": "agda",
"hexsha": "54f99ce12c17122de5241d774c797924c604e1ec",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8d687c1a6237ad2db1396c6b0af6667bd203f548",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dolio/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Localisation/InvertingElements.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8d687c1a6237ad2db1396c6b0af6667bd203f548",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dolio/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Localisation/InvertingElements.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8d687c1a6237ad2db1396c6b0af6667bd203f548",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dolio/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Localisation/InvertingElements.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 10683,
"size": 24882
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.HITs.SetQuotients.Base
open import Cubical.HITs.PropositionalTruncation.Base
Rel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
Rel A B ℓ' = A → B → Type ℓ'
PropRel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
PropRel A B ℓ' = Σ[ R ∈ Rel A B ℓ' ] ∀ a b → isProp (R a b)
idPropRel : ∀ {ℓ} (A : Type ℓ) → PropRel A A ℓ
idPropRel A .fst a a' = ∥ a ≡ a' ∥
idPropRel A .snd _ _ = squash
invPropRel : ∀ {ℓ ℓ'} {A B : Type ℓ}
→ PropRel A B ℓ' → PropRel B A ℓ'
invPropRel R .fst b a = R .fst a b
invPropRel R .snd b a = R .snd a b
compPropRel : ∀ {ℓ ℓ' ℓ''} {A B C : Type ℓ}
→ PropRel A B ℓ' → PropRel B C ℓ'' → PropRel A C (ℓ-max ℓ (ℓ-max ℓ' ℓ''))
compPropRel R S .fst a c = ∥ Σ[ b ∈ _ ] (R .fst a b × S .fst b c) ∥
compPropRel R S .snd _ _ = squash
graphRel : ∀ {ℓ} {A B : Type ℓ} → (A → B) → Rel A B ℓ
graphRel f a b = f a ≡ b
module BinaryRelation {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') where
isRefl : Type (ℓ-max ℓ ℓ')
isRefl = (a : A) → R a a
isSym : Type (ℓ-max ℓ ℓ')
isSym = (a b : A) → R a b → R b a
isTrans : Type (ℓ-max ℓ ℓ')
isTrans = (a b c : A) → R a b → R b c → R a c
record isEquivRel : Type (ℓ-max ℓ ℓ') where
constructor equivRel
field
reflexive : isRefl
symmetric : isSym
transitive : isTrans
isPropValued : Type (ℓ-max ℓ ℓ')
isPropValued = (a b : A) → isProp (R a b)
isEffective : Type (ℓ-max ℓ ℓ')
isEffective =
(a b : A) → isEquiv (eq/ {R = R} a b)
EquivRel : ∀ {ℓ} (A : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
EquivRel A ℓ' = Σ[ R ∈ Rel A A ℓ' ] BinaryRelation.isEquivRel R
EquivPropRel : ∀ {ℓ} (A : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
EquivPropRel A ℓ' = Σ[ R ∈ PropRel A A ℓ' ] BinaryRelation.isEquivRel (R .fst)
| {
"alphanum_fraction": 0.5892504931,
"avg_line_length": 31.2,
"ext": "agda",
"hexsha": "be51c02b7d27169d2918a6db3250cfc876bc93e6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "apabepa10/cubical",
"max_forks_repo_path": "Cubical/Relation/Binary/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "apabepa10/cubical",
"max_issues_repo_path": "Cubical/Relation/Binary/Base.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "apabepa10/cubical",
"max_stars_repo_path": "Cubical/Relation/Binary/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 879,
"size": 2028
} |
{-# OPTIONS --exact-split #-}
-- {-# OPTIONS -v tc.cover:10 #-}
postulate
A : Set
record I : Set where
constructor i
field
f : A
data Wrap : (j : I) → Set where
con : (j : I) → Wrap j
postulate
C : Set
anything : C
test : (X : I) -> Wrap X -> C
test (i ._) (con x) = anything
| {
"alphanum_fraction": 0.5420875421,
"avg_line_length": 14.1428571429,
"ext": "agda",
"hexsha": "f419544a4a91c8c3e5f294f954983b9059739b3d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1380a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1380a.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1380a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 105,
"size": 297
} |
{-# OPTIONS --cubical-compatible #-}
open import Common.Prelude
open import Common.Equality
KNat : {x : Nat} (e : x ≡ x) → e ≡ refl
KNat refl = refl
KEqNat : {x : Nat} {e : x ≡ x} (p : e ≡ e) → p ≡ refl
KEqNat refl = refl
KListNat : {x : List Nat} (e : x ≡ x) → e ≡ refl
KListNat refl = refl
data D (A : Set) : Nat → Set where
c : (x : A)(y : Nat) → D A y
-- Jesper 2015-12-18: this test case doesn't work yet with the new unifier
-- We need generalization of indices when applying the injectivity rule
--test : {A : Set} {x₁ x₂ : A} {y : Nat} → c x₁ y ≡ c x₂ y → Set
--test refl = Nat
| {
"alphanum_fraction": 0.6037099494,
"avg_line_length": 28.2380952381,
"ext": "agda",
"hexsha": "f05f01da3c0a13fec18bb20962946fd106d4b68c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/SetDetection.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/SetDetection.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/SetDetection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 226,
"size": 593
} |
{-# OPTIONS --without-K #-}
open import Base
open import Integers
open import Homotopy.Truncation
open import Spaces.Spheres
open import Spaces.Suspension
open import Homotopy.Connected
open import Homotopy.ConnectedSuspension
open import Homotopy.Pointed
open import Homotopy.HomotopyGroups
module Spaces.PikSn where
abstract
Sⁿ-S-is-connected : (n : ℕ) → is-connected ⟨ n ⟩ (Sⁿ (S n))
Sⁿ-S-is-connected n =
suspension-is-connected-S (Sⁿ n) ind-hyp (proj (⋆Sⁿ n)) where
ind-hyp : is-connected (n -1) (Sⁿ n)
ind-hyp with n
ind-hyp | O = inhab-prop-is-contr (proj true) (τ-is-truncated _ _)
ind-hyp | S n = Sⁿ-S-is-connected n
Sⁿ⋆ : (n : ℕ) → pType₀
Sⁿ⋆ n = ⋆[ Sⁿ n , ⋆Sⁿ n ]
abstract
πk-Sⁿ-is-contr : (k n : ℕ) (lt : k < n)
→ is-contr⋆ (πⁿ k (Sⁿ⋆ n))
πk-Sⁿ-is-contr k O ()
πk-Sⁿ-is-contr k (S n) lt = connected-πⁿ k n lt _ (Sⁿ-S-is-connected n)
| {
"alphanum_fraction": 0.6547085202,
"avg_line_length": 27.875,
"ext": "agda",
"hexsha": "3eea826b92026d846c1aca87544720b7eca3f4d7",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Spaces/PikSn.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Spaces/PikSn.agda",
"max_line_length": 73,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/PikSn.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 347,
"size": 892
} |
{-# OPTIONS --rewriting #-}
module RewritingNat where
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
_+_ : Nat → Nat → Nat
zero + n = n
(suc m) + n = suc (m + n)
plusAssoc : ∀ x {y z : Nat} → ((x + y) + z) ≡ (x + (y + z))
plusAssoc zero = refl
plusAssoc (suc x) {y} {z} rewrite plusAssoc x {y} {z} = refl
plus0T : Set
plus0T = ∀{x} → (x + zero) ≡ x
plusSucT : Set
plusSucT = ∀{x y} → (x + (suc y)) ≡ suc (x + y)
postulate
plus0p : plus0T
{-# REWRITE plus0p #-}
plusSucp : plusSucT
{-# REWRITE plusSucp plusAssoc #-}
plus0 : plus0T
plus0 = refl
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
_∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)
-- Needs REWRITE plus0p plusSucp
reverseAcc : ∀{A n m} → Vec A n → Vec A m → Vec A (n + m)
reverseAcc [] acc = acc
reverseAcc (x ∷ xs) acc = reverseAcc xs (x ∷ acc)
append : ∀{A n m} → Vec A n → Vec A m → Vec A (n + m)
append [] ys = ys
append (x ∷ xs) ys = x ∷ append xs ys
-- Note: appendAssoc needs REWRITE plusAssoc to be well-typed.
appendAssoc : ∀{A n m l} (u : Vec A n) {v : Vec A m}{w : Vec A l} →
append (append u v) w ≡ append u (append v w)
appendAssoc [] = refl
appendAssoc (x ∷ xs) {v} {w} rewrite appendAssoc xs {v} {w} = refl
| {
"alphanum_fraction": 0.5750972763,
"avg_line_length": 22.9464285714,
"ext": "agda",
"hexsha": "8d79d148d068a5e866b5ca4a4d3d91c0c291fb16",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/RewritingNat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/RewritingNat.agda",
"max_line_length": 67,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/RewritingNat.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 501,
"size": 1285
} |
{- 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 Dijkstra.EitherD
open import LibraBFT.Impl.Consensus.EpochManagerTypes
open import LibraBFT.Impl.Handle
open InitHandler
import LibraBFT.Impl.IO.OBM.GenKeyFile as GenKeyFile
import LibraBFT.Impl.IO.OBM.Properties.Start as Start
import LibraBFT.Impl.Properties.Util as Util
import LibraBFT.Impl.Types.BlockInfo as BlockInfo
import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochIndep
open import LibraBFT.ImplShared.Interface.Output
open import Optics.All
open import Util.Prelude
open import Yasm.Types as YT
module LibraBFT.Impl.Handle.InitProperties where
------------------------------------------------------------------------------
------------------------------------------------------------------------------
open Util.Invariants
open Util.InitProofDefs
module getEmRmSpec
(em : EpochManager)
where
Contract : EitherD-Post ErrLog RoundManager
Contract (Left x) = ⊤
Contract (Right rm) = rm IsNormalRoundManagerOf em
contract' : EitherD-weakestPre (getEmRm-ed-abs em) Contract
contract' rewrite getEmRm-ed-abs≡
with em ^∙ emProcessor | inspect (_^∙ emProcessor) em
...| nothing | _ = tt
...| just (RoundProcessorRecovery x) | _ = tt
...| just (RoundProcessorNormal x) | [ refl ] = refl
module initializeSpec
(now : Instant)
(nfl : GenKeyFile.NfLiwsVsVvPe)
where
contract' : EitherD-weakestPre (initialize-ed-abs now nfl) (InitContract nothing)
contract' rewrite initialize-ed-abs≡ =
Start.startViaConsensusProviderSpec.contract'
now
nfl
(TxTypeDependentStuffForNetwork∙new proposalGenerator (StateComputer∙new BlockInfo.gENESIS_VERSION))
module initEMWithOutputSpec
(bsi : BootstrapInfo)
(vs : ValidatorSigner)
where
contract' : EitherD-weakestPre (initEMWithOutput-ed-abs bsi vs) (InitContract nothing)
contract' rewrite initEMWithOutput-ed-abs≡ = initializeSpec.contract' now (mkNfLiwsVsVvPe bsi vs)
module initRMWithOutputSpec
(bsi : BootstrapInfo)
(vs : ValidatorSigner)
where
Contract : EitherD-Post ErrLog (RoundManager × List Output)
Contract (Left x) = ⊤
Contract (Right (rm , outs)) = InitContractOk nothing rm outs
open initRMWithOutput-ed bsi vs
contract-step₁ : ∀ {em lo}
→ EMInitCond nothing (em , lo)
→ EitherD-weakestPre (step₁ (em , lo)) Contract
contract-step₁ {em} {lo} (rm , inrm , cntrctOk) =
EitherD-⇒-bind (getEmRm-ed-abs em)
(getEmRmSpec.contract' em)
P⇒Q
where
P⇒Q : EitherD-Post-⇒ (getEmRmSpec.Contract em)
(EitherD-weakestPre-bindPost (λ rm → RightD (rm , lo)) Contract)
P⇒Q (Left x) _ = tt
P⇒Q (Right rm') pf .rm' refl rewrite IsNormalRoundManagerOf-inj {em} inrm pf = cntrctOk
contract' : EitherD-weakestPre (initRMWithOutput-ed-abs bsi vs) Contract
contract' rewrite initRMWithOutput-ed-abs≡ =
EitherD-⇒-bind (initEMWithOutput-ed-abs bsi vs)
(initEMWithOutputSpec.contract' bsi vs)
P⇒Q
where
P⇒Q : EitherD-Post-⇒ (InitContract nothing) _
P⇒Q (Left x) _ = tt
P⇒Q (Right (em , lo)) pf .(em , lo) refl = contract-step₁ pf
contract : Contract (initRMWithOutput-e-abs bsi vs)
contract rewrite initRMWithOutput≡ {bsi} {vs} =
EitherD-contract (initRMWithOutput-ed-abs bsi vs) Contract contract'
------------------------------------------------------------------------------
module initHandlerSpec
(pid : Author)
(bsi : BootstrapInfo)
where
record ContractOk (rm : RoundManager) (acts : List (YT.Action NetworkMsg)) : Set where
constructor mkContractOk
field
rmInv : Util.Invariants.RoundManagerInv rm
sdLVnothing : InitSdLV≡ rm nothing
sigs∈bs : InitSigs∈bs rm
isInitPM : InitIsInitPM acts
-- TODO-3: We will eventually need to know that our ValidatorSigner is for the correct peer,
-- because it will be needed to prove impl-sps-avp : StepPeerState-AllValidParts
Contract : Maybe (RoundManager × List (YT.Action NetworkMsg)) → Set
Contract nothing = ⊤
Contract (just (rm , acts)) = ContractOk rm acts
-- TODO-2: this property is more succinctly/elegantly stated as Contract (initHandler pid bsi),
-- and can be proved by starting the proof as follows:
--
-- contract : Contract (initHandler pid bsi)
-- contract with initHandler pid bsi | inspect (initHandler pid) bsi
-- ...| nothing | _ = tt
-- ...| just (rm , acts) | [ hndl≡just ]
--
-- However, this breaks a bunch of proofs that use this, so not doing it for now.
contract : ∀ {x} → initHandler pid bsi ≡ x → Contract x
contract {nothing} hndl≡nothing rewrite sym hndl≡nothing = tt
contract {just (rm , acts)} hndl≡just
with ValidatorSigner.obmGetValidatorSigner pid (bsi ^∙ bsiVSS)
...| Left _ = absurd nothing ≡ just _ case hndl≡just of λ ()
...| Right vs
with initRMWithOutputSpec.contract bsi vs
...| initRMWithOutputContractOk
with initRMWithOutput-e-abs bsi vs
...| Left _ = absurd nothing ≡ just (rm , acts) case hndl≡just of λ ()
...| Right rm×outs rewrite sym (cong proj₂ (just-injective hndl≡just)) |
(cong proj₁ (just-injective hndl≡just)) =
mkContractOk
(InitContractOk.rmInv initRMWithOutputContractOk)
(InitContractOk.sdLV≡ initRMWithOutputContractOk)
(InitContractOk.sigs∈bs initRMWithOutputContractOk)
(InitContractOk.isInitPM initRMWithOutputContractOk)
| {
"alphanum_fraction": 0.6566012414,
"avg_line_length": 39.2171052632,
"ext": "agda",
"hexsha": "d974ac40ec8e4f9db9abc6d1efdfa285f8e5a578",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Handle/InitProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Handle/InitProperties.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Handle/InitProperties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1684,
"size": 5961
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Generalised notion of interleaving two lists into one in an
-- order-preserving manner
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Ternary.Interleaving where
open import Level
open import Data.List.Base as List using (List; []; _∷_; _++_)
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_)
open import Data.Product as Prod using (∃; ∃₂; _×_; uncurry; _,_; -,_; proj₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Definition
module _ {a b c l r} {A : Set a} {B : Set b} {C : Set c}
(L : REL A C l) (R : REL B C r) where
data Interleaving : List A → List B → List C → Set (a ⊔ b ⊔ c ⊔ l ⊔ r) where
[] : Interleaving [] [] []
_∷ˡ_ : ∀ {a c l r cs} → L a c → Interleaving l r cs → Interleaving (a ∷ l) r (c ∷ cs)
_∷ʳ_ : ∀ {b c l r cs} → R b c → Interleaving l r cs → Interleaving l (b ∷ r) (c ∷ cs)
------------------------------------------------------------------------
-- Operations
module _ {a b c l r} {A : Set a} {B : Set b} {C : Set c}
{L : REL A C l} {R : REL B C r} where
-- injections
left : ∀ {as cs} → Pointwise L as cs → Interleaving L R as [] cs
left [] = []
left (l ∷ pw) = l ∷ˡ left pw
right : ∀ {bs cs} → Pointwise R bs cs → Interleaving L R [] bs cs
right [] = []
right (r ∷ pw) = r ∷ʳ right pw
-- swap
swap : ∀ {cs l r} → Interleaving L R l r cs → Interleaving R L r l cs
swap [] = []
swap (l ∷ˡ sp) = l ∷ʳ swap sp
swap (r ∷ʳ sp) = r ∷ˡ swap sp
-- extract the "proper" equality split from the pointwise relations
break : ∀ {cs l r} → Interleaving L R l r cs → ∃ $ uncurry $ λ csl csr →
Interleaving _≡_ _≡_ csl csr cs × Pointwise L l csl × Pointwise R r csr
break [] = -, [] , [] , []
break (l ∷ˡ sp) = let (_ , eq , pwl , pwr) = break sp in
-, P.refl ∷ˡ eq , l ∷ pwl , pwr
break (r ∷ʳ sp) = let (_ , eq , pwl , pwr) = break sp in
-, P.refl ∷ʳ eq , pwl , r ∷ pwr
-- map
module _ {a b c l r p q} {A : Set a} {B : Set b} {C : Set c}
{L : REL A C l} {R : REL B C r} {P : REL A C p} {Q : REL B C q} where
map : ∀ {cs l r} → L ⇒ P → R ⇒ Q → Interleaving L R l r cs → Interleaving P Q l r cs
map L⇒P R⇒Q [] = []
map L⇒P R⇒Q (l ∷ˡ sp) = L⇒P l ∷ˡ map L⇒P R⇒Q sp
map L⇒P R⇒Q (r ∷ʳ sp) = R⇒Q r ∷ʳ map L⇒P R⇒Q sp
module _ {a b c l r p} {A : Set a} {B : Set b} {C : Set c}
{L : REL A C l} {R : REL B C r} where
map₁ : ∀ {P : REL A C p} {as l r} → L ⇒ P →
Interleaving L R l r as → Interleaving P R l r as
map₁ L⇒P = map L⇒P id
map₂ : ∀ {P : REL B C p} {as l r} → R ⇒ P →
Interleaving L R l r as → Interleaving L P l r as
map₂ = map id
------------------------------------------------------------------------
-- Special case: The second and third list have the same type
module _ {a b l r} {A : Set a} {B : Set b} {L : REL A B l} {R : REL A B r} where
-- converting back and forth with pointwise
split : ∀ {as bs} → Pointwise (λ a b → L a b ⊎ R a b) as bs →
∃₂ λ asr asl → Interleaving L R asl asr bs
split [] = [] , [] , []
split (inj₁ l ∷ pw) = Prod.map _ (Prod.map _ (l ∷ˡ_)) (split pw)
split (inj₂ r ∷ pw) = Prod.map _ (Prod.map _ (r ∷ʳ_)) (split pw)
unsplit : ∀ {l r as} → Interleaving L R l r as →
∃ λ bs → Pointwise (λ a b → L a b ⊎ R a b) bs as
unsplit [] = -, []
unsplit (l ∷ˡ sp) = Prod.map _ (inj₁ l ∷_) (unsplit sp)
unsplit (r ∷ʳ sp) = Prod.map _ (inj₂ r ∷_) (unsplit sp)
| {
"alphanum_fraction": 0.4905903583,
"avg_line_length": 37.2980769231,
"ext": "agda",
"hexsha": "aec8505cee0b32e2d37c9bab8feaa317d19eca32",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1410,
"size": 3879
} |
module Plain.Terms where
open import Data.Nat
open import Data.Fin
record Signature (n : ℕ) : Set where
field
-- symbols are encoded as numbers in Fin n
-- arity
ar : Fin n → ℕ
open Signature public
-- | Countable set of Variables
Var : Set
Var = ℕ
open import Data.Vec as V
open import Size
-- | Term in with a signature Σ with variables var
data Term {i : Size} {j : Size< i} {n : ℕ}
(Σ : Signature n) (var : Set) : Set where
FNode : {k : Size< j}
→ (f : Fin n) → Vec (Term {j} {k} {n} Σ var) (ar Σ f)
→ Term {i} {j} {n} Σ var
VNode : (v : var) → Term {i} {j} {n} Σ var
open import Data.Empty
-- | Ground Terms
GTerm : {n : ℕ} → (Σ : Signature n) → Set
GTerm Σ = Term Σ ⊥
open import Data.List as L
-- | Horn clause
--
data Clause {n : ℕ} (Σ : Signature n) : Set where
_:-_ : (Term Σ Var) → List (Term Σ Var) → Clause Σ
cHead : {n : ℕ} → {Σ : Signature n} → Clause Σ → Term Σ Var
cHead (a :- _) = a
cBody : {n : ℕ} → {Σ : Signature n} → Clause Σ → List (Term Σ Var)
cBody (_ :- bs) = bs
record Program {n : ℕ} (Σ : Signature n) : Set where
field
prg : List (Clause Σ) -- → Program Σ
--unPrg : {n : ℕ} → {Σ : Signature n} → Program Σ → List (Clause Σ)
--unPrg (prg cls) = cls
record GSubst {n : ℕ} (Σ : Signature n) : Set₁ where
field
subst : (Var → GTerm Σ)
open GSubst
-- | substitution application
app : {i : Size} → {j : Size< i} →
{n : ℕ} → {Σ : Signature n}
→ GSubst Σ → Term {i} {j} Σ Var → GTerm Σ
app σ (FNode f fs) = FNode f (V.map (app σ) fs)
app σ (VNode v) = subst σ v
| {
"alphanum_fraction": 0.5768488746,
"avg_line_length": 22.5362318841,
"ext": "agda",
"hexsha": "b934394caa2e325577bb20b81ff5e93069be1669",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "411ca7970b6f64857a36ebcf648c9a58b90bb4b2",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "frantisekfarka/lp-mod",
"max_forks_repo_path": "Plain/Terms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "411ca7970b6f64857a36ebcf648c9a58b90bb4b2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "frantisekfarka/lp-mod",
"max_issues_repo_path": "Plain/Terms.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "411ca7970b6f64857a36ebcf648c9a58b90bb4b2",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "frantisekfarka/lp-mod",
"max_stars_repo_path": "Plain/Terms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 600,
"size": 1555
} |
module spaceShipSimpleVar where
open import Unit
open import Data.List.Base hiding ([])
open import Data.Bool.Base
open import Data.Integer
open import Data.Product hiding (map)
open import NativeIO
open import StateSizedIO.GUI.WxBindingsFFI
open import StateSizedIO.GUI.WxGraphicsLib
open import StateSized.GUI.ShipBitMap
open import SizedIO.Base
open import StateSizedIO.GUI.BaseStateDependent
open import StateSizedIO.GUI.VariableList
VarType = ℤ
varInit : VarType
varInit = (+ 150)
onPaint : ∀{i} → VarType → DC → Rect → IO GuiLev1Interface i VarType
onPaint z dc rect = do (drawBitmap dc ship (z , (+ 150)) true) λ _ →
return z
moveSpaceShip : ∀{i} → Frame → VarType → IO GuiLev1Interface i VarType
moveSpaceShip fra z = return (z + + 20)
callRepaint : ∀{i} → Frame → VarType → IO GuiLev1Interface i VarType
callRepaint fra z = do (repaint fra) λ _ → return z
buttonHandler : ∀{i} → Frame → List (VarType → IO GuiLev1Interface i VarType)
buttonHandler fra = moveSpaceShip fra ∷ [ callRepaint fra ]
program : ∀{i} → IOˢ GuiLev2Interface i (λ _ → Unit) []
program = doˢ (level1C makeFrame) λ fra →
doˢ (level1C (makeButton fra)) λ bt →
doˢ (level1C (addButton fra bt)) λ _ →
doˢ (createVar varInit) λ _ →
doˢ (setButtonHandler bt (buttonHandler fra)) λ _ →
doˢ (setOnPaint fra [ onPaint ])
returnˢ
main : NativeIO Unit
main = start (translateLev2 program)
| {
"alphanum_fraction": 0.6717305152,
"avg_line_length": 32.9130434783,
"ext": "agda",
"hexsha": "a9c8b79789fd1cd857dd5d33412f15e8792512cc",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/spaceShipSimpleVar.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/spaceShipSimpleVar.agda",
"max_line_length": 78,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/spaceShipSimpleVar.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 458,
"size": 1514
} |
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Data.Empty
open import Data.Sum
open import Data.Fin using (Fin; toℕ ; fromℕ ; fromℕ≤)
open import Data.Fin.Properties using (toℕ<n; toℕ-injective)
open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_)
open import Data.Nat.Properties
open import Data.List renaming (map to List-map)
open import Data.List.Relation.Unary.Any
open import Function
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
-- This module pulls in the definitions from AAOSL.Hops and uses
-- them to construct a DepRel based on the dependency relation
-- defined there, showing that this concrete AAOSL enjoys the
-- properties we have proved for abstract ones
module AAOSL.Concrete where
open import Data.Nat.Even
open import Data.Nat.Encode
open import AAOSL.Lemmas
open import AAOSL.Hops
open import AAOSL.Abstract.Hash
open import AAOSL.Abstract.DepRel
---------------------------------------------------
-- Translating the proofs about Hops into a DepRel,
-- as required by AAOSL.Abstract.Advancement
getHop : ∀{j}(h : Fin (lvlOf j)) → H (toℕ h) j (j ∸ 2 ^ toℕ h)
getHop {j} h = h-correct j (toℕ h) (toℕ<n {lvlOf j} h)
hop-prog : {m : ℕ} (h : Fin (lvlOf m)) → m ∸ (2 ^ toℕ h) ≢ m
hop-prog {zero} ()
hop-prog {suc m} h = ∸-≢ (2 ^ toℕ h) (1≤2^n (toℕ h)) (lvlOf-correct (toℕ<n h))
hop-≤ : {m : ℕ} (h : Fin (lvlOf m)) → m ∸ (2 ^ toℕ h) ≤ m
hop-≤ {zero} ()
hop-≤ {suc m} h = m∸n≤m (suc m) (2 ^ toℕ h)
lvlOfsuc : ∀ m → 0 < lvlOf (suc m)
lvlOfsuc m with even? (suc m)
...| yes _ = s≤s z≤n
...| no _ = s≤s z≤n
-- This proves that ℕ makes a skiplog dependency relation
-- by connecting the indexes by their largest power of two.
skiplog-dep-rel : DepRel
skiplog-dep-rel = record
{ lvlof = lvlOf
; lvlof-z = refl
; lvlof-s = lvlOfsuc
; hop-tgt = λ {m} h → m ∸ 2 ^ toℕ h
; hop-tgt-inj = λ {m} {h} {h'} prf
→ toℕ-injective (2^-injective {toℕ h} {toℕ h'}
(∸-inj (2 ^ toℕ h) (2 ^ toℕ h')
(lvlOf-correct (toℕ<n h))
(lvlOf-correct (toℕ<n h'))
prf))
; hop-< = λ h → ≤∧≢⇒< (hop-≤ h) (hop-prog h)
; hops-nested-or-nonoverlapping
= λ {h₁} {h₂} {h₃} {h₄} a b
→ no-overlap-< (getHop h₃) (getHop h₄) a b
}
-- This, in turn, enables us to bring the abstract module into
-- scope with everything instantiated minus the hash functions.
module _
(hash : ByteString → Hash)
(hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y)
where
open import AAOSL.Abstract.Advancement hash hash-cr encodeℕ encodeℕ-inj skiplog-dep-rel
open import AAOSL.Abstract.EvoCR hash hash-cr encodeℕ encodeℕ-inj skiplog-dep-rel
| {
"alphanum_fraction": 0.6078494972,
"avg_line_length": 38.0617283951,
"ext": "agda",
"hexsha": "057f0527ca6dd1b070031334832f02ade0bbf094",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T04:33:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-22T00:01:03.000Z",
"max_forks_repo_head_hexsha": "318881fb24af06bbaafa33edeea0745eca1873f0",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/aaosl-agda",
"max_forks_repo_path": "AAOSL/Concrete.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "318881fb24af06bbaafa33edeea0745eca1873f0",
"max_issues_repo_issues_event_max_datetime": "2021-02-12T04:16:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-01-04T03:45:34.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/aaosl-agda",
"max_issues_repo_path": "AAOSL/Concrete.agda",
"max_line_length": 111,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "318881fb24af06bbaafa33edeea0745eca1873f0",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/aaosl-agda",
"max_stars_repo_path": "AAOSL/Concrete.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-31T10:16:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-22T00:01:00.000Z",
"num_tokens": 1023,
"size": 3083
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Algebra.SymmetricGroup where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ ; suc ; zero)
open import Cubical.Data.Fin using (Fin ; isSetFin)
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary using (¬_)
open import Cubical.Structures.Group
open import Cubical.Structures.NAryOp
private
variable
ℓ ℓ' : Level
Symmetric-Group : (X : Type ℓ) → isSet X → Group
Symmetric-Group X isSetX =
(X ≃ X) ,
compEquiv ,
(isOfHLevel≃ 2 isSetX isSetX , compEquiv-assoc) ,
idEquiv X , (λ f → compEquivEquivId f , compEquivIdEquiv f) , λ f → invEquiv f , invEquiv-is-rinv f , invEquiv-is-linv f
-- Finite symmetrics groups
Sym : ℕ → Group
Sym n = Symmetric-Group (Fin n) isSetFin
| {
"alphanum_fraction": 0.7432432432,
"avg_line_length": 28.6451612903,
"ext": "agda",
"hexsha": "de2908886476c491b896946aa2c5c917920712f3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmester0/cubical",
"max_forks_repo_path": "Cubical/Algebra/SymmetricGroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmester0/cubical",
"max_issues_repo_path": "Cubical/Algebra/SymmetricGroup.agda",
"max_line_length": 122,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmester0/cubical",
"max_stars_repo_path": "Cubical/Algebra/SymmetricGroup.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 284,
"size": 888
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Sigma
open import Cubical.Data.Vec
open import Cubical.Data.Vec.OperationsNat
open import Cubical.Algebra.Monoid.Instances.NatVec
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.GradedRing.DirectSumHIT
open import Cubical.Algebra.GradedRing.Instances.Polynomials
open import Cubical.Algebra.CommRing.Instances.Int
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- General Nth polynome
open GradedRing-⊕HIT-index
open GradedRing-⊕HIT-⋆
open ExtensionCommRing
module _
(ACommRing@(A , Astr) : CommRing ℓ)
(n : ℕ)
where
open CommRingStr Astr
open RingTheory (CommRing→Ring ACommRing)
PolyCommRing : CommRing ℓ
PolyCommRing = ⊕HITgradedRing-CommRing
(NatVecMonoid n)
(λ _ → A)
(λ _ → snd (Ring→AbGroup (CommRing→Ring ACommRing)))
1r _·_ 0LeftAnnihilates 0RightAnnihilates
(λ a b c → ΣPathP ((+n-vec-assoc _ _ _) , (·Assoc _ _ _)))
(λ a → ΣPathP ((+n-vec-rid _) , (·IdR _)))
(λ a → ΣPathP((+n-vec-lid _) , (·IdL _)))
·DistR+
·DistL+
λ x y → ΣPathP ((+n-vec-comm _ _) , (·Comm _ _))
-----------------------------------------------------------------------------
-- Notation and syntax in the case 1,2,3 and ℤ
module _
(Ar@(A , Astr) : CommRing ℓ)
(n : ℕ)
where
Poly : Type ℓ
Poly = fst (PolyCommRing Ar n)
-- Possible renaming when you import
-- (PolyCommRing to A[X1,···,Xn] ; Poly to A[x1,···,xn])
| {
"alphanum_fraction": 0.5957792208,
"avg_line_length": 29.3333333333,
"ext": "agda",
"hexsha": "90e1be9faf8bad5d4eecf5fa8236b5823a1e30fe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/Polynomials/MultivariatePoly.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/Polynomials/MultivariatePoly.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/Polynomials/MultivariatePoly.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 539,
"size": 1848
} |
{-
This file contains:
- Definitions equivalences
- Glue types
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Core.Glue where
open import Cubical.Core.Primitives
open import Agda.Builtin.Cubical.Glue public
using ( isEquiv -- ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ ⊔ ℓ')
; equiv-proof -- ∀ (y : B) → isContr (fiber f y)
; _≃_ -- ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ ⊔ ℓ')
; equivFun -- ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → A ≃ B → A → B
; equivProof -- ∀ {ℓ ℓ'} (T : Type ℓ) (A : Type ℓ') (w : T ≃ A) (a : A) φ →
-- Partial φ (fiber (equivFun w) a) → fiber (equivFun w) a
; primGlue -- ∀ {ℓ ℓ'} (A : Type ℓ) {φ : I} (T : Partial φ (Type ℓ'))
-- → (e : PartialP φ (λ o → T o ≃ A)) → Type ℓ'
; prim^unglue -- ∀ {ℓ ℓ'} {A : Type ℓ} {φ : I} {T : Partial φ (Type ℓ')}
-- → {e : PartialP φ (λ o → T o ≃ A)} → primGlue A T e → A
-- The ∀ operation on I. This is commented out as it is not currently used for anything
-- ; primFaceForall -- (I → I) → I
)
renaming ( prim^glue to glue -- ∀ {ℓ ℓ'} {A : Type ℓ} {φ : I} {T : Partial φ (Type ℓ')}
-- → {e : PartialP φ (λ o → T o ≃ A)}
-- → PartialP φ T → A → primGlue A T e
; pathToEquiv to lineToEquiv -- ∀ {ℓ : I → Level} (P : (i : I) → Type (ℓ i)) → P i0 ≃ P i1
)
private
variable
ℓ ℓ' : Level
-- Uncurry Glue to make it more pleasant to use
Glue : (A : Type ℓ) {φ : I}
→ (Te : Partial φ (Σ[ T ∈ Type ℓ' ] T ≃ A))
→ Type ℓ'
Glue A Te = primGlue A (λ x → Te x .fst) (λ x → Te x .snd)
-- Make the φ argument of prim^unglue explicit
unglue : {A : Type ℓ} (φ : I) {T : Partial φ (Type ℓ')}
{e : PartialP φ (λ o → T o ≃ A)} → primGlue A T e → A
unglue φ = prim^unglue {φ = φ}
-- People unfamiliar with [Glue], [glue] and [uglue] can find the types below more
-- informative as they demonstrate the computational behavior.
--
-- Full inference rules can be found in Section 6 of CCHM:
-- https://arxiv.org/pdf/1611.02108.pdf
-- Cubical Type Theory: a constructive interpretation of the univalence axiom
-- Cyril Cohen, Thierry Coquand, Simon Huber, Anders Mörtberg
private
Glue-S : (A : Type ℓ) {φ : I}
→ (Te : Partial φ (Σ[ T ∈ Type ℓ' ] T ≃ A))
→ Sub (Type ℓ') φ (λ { (φ = i1) → Te 1=1 .fst })
Glue-S A Te = inS (Glue A Te)
glue-S :
∀ {A : Type ℓ} {φ : I}
→ {T : Partial φ (Type ℓ')} {e : PartialP φ (λ o → T o ≃ A)}
→ (t : PartialP φ T)
→ Sub A φ (λ { (φ = i1) → e 1=1 .fst (t 1=1) })
→ Sub (primGlue A T e) φ (λ { (φ = i1) → t 1=1 })
glue-S t s = inS (glue t (outS s))
unglue-S :
∀ {A : Type ℓ} (φ : I)
{T : Partial φ (Type ℓ')} {e : PartialP φ (λ o → T o ≃ A)}
→ (x : primGlue A T e)
→ Sub A φ (λ { (φ = i1) → e 1=1 .fst x })
unglue-S φ x = inS (prim^unglue {φ = φ} x)
| {
"alphanum_fraction": 0.4874470166,
"avg_line_length": 35.6627906977,
"ext": "agda",
"hexsha": "b22f7b2cce9342e57965d6713e5400154f5ee3cd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Core/Glue.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Core/Glue.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Core/Glue.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1162,
"size": 3067
} |
-- Andreas, 2018-03-03, termination bug found by Nisse
-- caused by a missing call to `instantiate`.
-- {-# OPTIONS -vtc:20 -vterm:20 #-}
{-# BUILTIN SIZEUNIV SizeU #-}
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZELT Size<_ #-}
{-# BUILTIN SIZEINF ∞ #-}
record Unit (i : Size) : Set where
coinductive
field
force : (j : Size< i) → Unit j
postulate
tail : Unit ∞ → Unit ∞
id : ∀ i → Unit i → Unit i
u : ∀ i → Unit i
u i = tail (id _ λ { .Unit.force j → u j })
-- Should not termination check.
| {
"alphanum_fraction": 0.5793499044,
"avg_line_length": 21.7916666667,
"ext": "agda",
"hexsha": "9ce5e445127b6ca79ee58ff4cf48bf07d55b61a4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2985.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2985.agda",
"max_line_length": 54,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2985.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 173,
"size": 523
} |
-- Andreas, 2019-05-30, issue #3823
-- Named where module M should be in scope in rhs.
-- This enables to use it in expressions like record{M}.
open import Agda.Builtin.Equality
record R : Set₂ where
field
A : Set₁
r : R
r = record {M}
module M where
A = Set
-- ERROR WAS:
-- No module M in scope
-- when scope checking record { M }
test : r ≡ record {A = Set}
test = refl
-- Should succeed.
-- Should also work with module parameters.
s : Set₁ → R
s B = record {L}
module L where
A = B
-- With rewrite:
postulate
B : Set
a b : B
a≡b : a ≡ b
P : B → Set
record W : Set where
field
wrap : P b
w : P a → W
w p rewrite a≡b = record {N}
module N where
wrap = p
-- Should also succeed in the presence of `rewrite`.
module N' = N -- See issue #3824.
| {
"alphanum_fraction": 0.6160602258,
"avg_line_length": 15.3269230769,
"ext": "agda",
"hexsha": "468dbd960408df780edcf4151e1c7e493e644583",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Succeed/Issue3823.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/Issue3823.agda",
"max_line_length": 56,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/Issue3823.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 261,
"size": 797
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Empty type
------------------------------------------------------------------------
module Data.Empty where
open import Level
data ⊥ : Set where
{-# IMPORT Data.FFI #-}
{-# COMPILED_DATA ⊥ Data.FFI.AgdaEmpty #-}
⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever
⊥-elim ()
| {
"alphanum_fraction": 0.3880208333,
"avg_line_length": 21.3333333333,
"ext": "agda",
"hexsha": "b32d11b5cb21f365328ae2b27164dc4f776d7d11",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Empty.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 80,
"size": 384
} |
module Relation.Equivalence.Univalence where
open import Basics
open import Level
open import Relation.Equality
open import Data.Product
-- For any A and B, a quasi-inverse of f is a triple with
-- ∘ A way back (an inverse for the homomorphism)
-- ∘ Homotopies:
-- ⊚ α : f ∘ g ∼ id
-- ⊚ β : g ∘ f ∼ id
-- For now, because I am lazy, the presence of a quasi-inverse will count
-- as our definition of equivalence for now. Sorry.
record IsEquiv {i j}{A : Set i}{B : Set j}(to : A → B) : Set (i ⊔ j) where
field
from : B → A
iso₁ : (x : A) → from (to x) ≡ x
iso₂ : (y : B) → to (from y) ≡ y
-- Example 2.4.7: Identity is an equivalence.
id-is-equiv : ∀ {i} (A : Set i) → IsEquiv (id {i}{A})
id-is-equiv {i} A = record
{ from = id {i}{A}
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl
}
-- Type equivalence is also an equivalence, just on the Universe because:
-- ∘ id-is-equiv works for it, therefore A ≃ A
-- ∘ With A ≃ B, we can always make B ≃ A
-- ∘ With A ≃ B and B ≃ C we have A ≃ C
_≃_ : ∀ {i j} (A : Set i) (B : Set j) → Set (i ⊔ j)
A ≃ B = Σ (A → B) IsEquiv
postulate -- Just kidding
ua : ∀ {i} {{A : Set i}}{{B : Set i}} → (A ≃ B) ≃ (A ≡ B)
-- ^This says "equivalent types may be identified"
| {
"alphanum_fraction": 0.5786113328,
"avg_line_length": 31.325,
"ext": "agda",
"hexsha": "76f3b09eb476b05d6580b17b601cd83d6b4b8e0e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Relation/Equivalence/Univalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Relation/Equivalence/Univalence.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Relation/Equivalence/Univalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 458,
"size": 1253
} |
module Example where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
postulate
case-Nat : (P : Nat -> Set) -> P zero ->
((n:Nat) -> P (suc n)) ->
(n : Nat) -> P n
-- test : Nat -> Nat
test = case-Nat _ zero (\n -> n)
{-
data Size : Set where
empty : Size
nonempty : Size
whatever : Size
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data List (A:Set) : Set where
nil : List A
(::) : A -> List A -> List A
data Monad (M:Set -> Set) : Set1 where
monad : Monad M
postulate
build : {M:Set -> Set} -> Monad M -> {C:Size -> Set} -> (A:Set) ->
(A -> C nonempty) ->
((n:Size) -> List (C n) -> M (List A)) ->
List A -> M (C whatever)
test : (A:Set) -> Nat
test A = build monad A (\x -> x) (\n xs -> xs) nil
-}
| {
"alphanum_fraction": 0.5130548303,
"avg_line_length": 18.2380952381,
"ext": "agda",
"hexsha": "4d18d98a3c4e99cae6d7b6b804c5affb4fc1e49c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "notes/papers/implicit/examples/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "notes/papers/implicit/examples/Example.agda",
"max_line_length": 68,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "notes/papers/implicit/examples/Example.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 276,
"size": 766
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Functions.Definition
open import Functions.Lemmas
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Integers.Integers
open import Numbers.Rationals.Definition
open import Sets.FinSet.Definition
open import Sets.FinSet.Lemmas
open import Sets.Cardinality.Finite.Definition
open import Groups.Definition
open import Groups.Groups
open import Groups.Abelian.Definition
open import Groups.FiniteGroups.Definition
open import Rings.Definition
open import Numbers.Modulo.Group
open import Numbers.Modulo.Definition
open import Semirings.Definition
module Groups.LectureNotes.Lecture1 where
ℤIsGroup : _
ℤIsGroup = ℤGroup
ℚIsGroup : _
ℚIsGroup = Ring.additiveGroup ℚRing
-- TODO: R is a group with +
integersMinusNotGroup : Group (reflSetoid ℤ) (_-Z_) → False
integersMinusNotGroup record { +WellDefined = wellDefined ; 0G = identity ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } with multAssoc {nonneg 3} {nonneg 2} {nonneg 1}
integersMinusNotGroup record { +WellDefined = wellDefined ; 0G = identity ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } | ()
negSuccInjective : {a b : ℕ} → (negSucc a ≡ negSucc b) → a ≡ b
negSuccInjective {a} {.a} refl = refl
nonnegInjective : {a b : ℕ} → (nonneg a ≡ nonneg b) → a ≡ b
nonnegInjective {a} {.a} refl = refl
integersTimesNotGroup : Group (reflSetoid ℤ) (_*Z_) → False
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (nonneg zero) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } with multIdentLeft {negSucc 1}
... | ()
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (nonneg (succ zero)) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } with invLeft {nonneg zero}
... | bl with inverse (nonneg zero)
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (nonneg (succ zero)) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } | () | nonneg zero
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (nonneg (succ zero)) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } | p | nonneg (succ x) = naughtE (nonnegInjective (transitivity (applyEquality nonneg (equalityCommutative (Semiring.productZeroRight ℕSemiring x))) p))
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (nonneg (succ zero)) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } | () | negSucc x
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (nonneg (succ (succ x))) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } with succInjective (negSuccInjective (multIdentLeft {negSucc 1}))
... | ()
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (negSucc x) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } with multIdentLeft {nonneg 2}
integersTimesNotGroup record { +WellDefined = wellDefined ; 0G = (negSucc x) ; inverse = inverse ; +Associative = multAssoc ; identRight = multIdentRight ; identLeft = multIdentLeft ; invLeft = invLeft ; invRight = invRight } | ()
-- TODO: Q is not a group with *Q
-- TODO: Q without 0 is a group with *Q
-- TODO: {1, -1} is a group with *
ℤnIsGroup : (n : ℕ) → (0<n : 0 <N n) → _
ℤnIsGroup n pr = ℤnGroup n pr
-- Groups example 8.9 from lecture 1
data Weird : Set where
e : Weird
a : Weird
b : Weird
c : Weird
_+W_ : Weird → Weird → Weird
e +W t = t
a +W e = a
a +W a = e
a +W b = c
a +W c = b
b +W e = b
b +W a = c
b +W b = e
b +W c = a
c +W e = c
c +W a = b
c +W b = a
c +W c = e
+WAssoc : {x y z : Weird} → (x +W (y +W z)) ≡ (x +W y) +W z
+WAssoc {e} {y} {z} = refl
+WAssoc {a} {e} {z} = refl
+WAssoc {a} {a} {e} = refl
+WAssoc {a} {a} {a} = refl
+WAssoc {a} {a} {b} = refl
+WAssoc {a} {a} {c} = refl
+WAssoc {a} {b} {e} = refl
+WAssoc {a} {b} {a} = refl
+WAssoc {a} {b} {b} = refl
+WAssoc {a} {b} {c} = refl
+WAssoc {a} {c} {e} = refl
+WAssoc {a} {c} {a} = refl
+WAssoc {a} {c} {b} = refl
+WAssoc {a} {c} {c} = refl
+WAssoc {b} {e} {z} = refl
+WAssoc {b} {a} {e} = refl
+WAssoc {b} {a} {a} = refl
+WAssoc {b} {a} {b} = refl
+WAssoc {b} {a} {c} = refl
+WAssoc {b} {b} {e} = refl
+WAssoc {b} {b} {a} = refl
+WAssoc {b} {b} {b} = refl
+WAssoc {b} {b} {c} = refl
+WAssoc {b} {c} {e} = refl
+WAssoc {b} {c} {a} = refl
+WAssoc {b} {c} {b} = refl
+WAssoc {b} {c} {c} = refl
+WAssoc {c} {e} {z} = refl
+WAssoc {c} {a} {e} = refl
+WAssoc {c} {a} {a} = refl
+WAssoc {c} {a} {b} = refl
+WAssoc {c} {a} {c} = refl
+WAssoc {c} {b} {e} = refl
+WAssoc {c} {b} {a} = refl
+WAssoc {c} {b} {b} = refl
+WAssoc {c} {b} {c} = refl
+WAssoc {c} {c} {e} = refl
+WAssoc {c} {c} {a} = refl
+WAssoc {c} {c} {b} = refl
+WAssoc {c} {c} {c} = refl
weirdGroup : Group (reflSetoid Weird) _+W_
Group.+WellDefined weirdGroup = reflGroupWellDefined
Group.0G weirdGroup = e
Group.inverse weirdGroup t = t
Group.+Associative weirdGroup {r} {s} {t} = +WAssoc {r} {s} {t}
Group.identRight weirdGroup {e} = refl
Group.identRight weirdGroup {a} = refl
Group.identRight weirdGroup {b} = refl
Group.identRight weirdGroup {c} = refl
Group.identLeft weirdGroup {e} = refl
Group.identLeft weirdGroup {a} = refl
Group.identLeft weirdGroup {b} = refl
Group.identLeft weirdGroup {c} = refl
Group.invLeft weirdGroup {e} = refl
Group.invLeft weirdGroup {a} = refl
Group.invLeft weirdGroup {b} = refl
Group.invLeft weirdGroup {c} = refl
Group.invRight weirdGroup {e} = refl
Group.invRight weirdGroup {a} = refl
Group.invRight weirdGroup {b} = refl
Group.invRight weirdGroup {c} = refl
weirdAb : AbelianGroup weirdGroup
AbelianGroup.commutative weirdAb {e} {e} = refl
AbelianGroup.commutative weirdAb {e} {a} = refl
AbelianGroup.commutative weirdAb {e} {b} = refl
AbelianGroup.commutative weirdAb {e} {c} = refl
AbelianGroup.commutative weirdAb {a} {e} = refl
AbelianGroup.commutative weirdAb {a} {a} = refl
AbelianGroup.commutative weirdAb {a} {b} = refl
AbelianGroup.commutative weirdAb {a} {c} = refl
AbelianGroup.commutative weirdAb {b} {e} = refl
AbelianGroup.commutative weirdAb {b} {a} = refl
AbelianGroup.commutative weirdAb {b} {b} = refl
AbelianGroup.commutative weirdAb {b} {c} = refl
AbelianGroup.commutative weirdAb {c} {e} = refl
AbelianGroup.commutative weirdAb {c} {a} = refl
AbelianGroup.commutative weirdAb {c} {b} = refl
AbelianGroup.commutative weirdAb {c} {c} = refl
weirdProjection : Weird → FinSet 4
weirdProjection a = ofNat 0 (le 3 refl)
weirdProjection b = ofNat 1 (le 2 refl)
weirdProjection c = ofNat 2 (le 1 refl)
weirdProjection e = ofNat 3 (le zero refl)
weirdProjectionSurj : Surjection weirdProjection
weirdProjectionSurj fzero = a , refl
weirdProjectionSurj (fsucc fzero) = b , refl
weirdProjectionSurj (fsucc (fsucc fzero)) = c , refl
weirdProjectionSurj (fsucc (fsucc (fsucc fzero))) = e , refl
weirdProjectionSurj (fsucc (fsucc (fsucc (fsucc ()))))
weirdProjectionInj : (x y : Weird) → weirdProjection x ≡ weirdProjection y → Setoid._∼_ (reflSetoid Weird) x y
weirdProjectionInj e e fx=fy = refl
weirdProjectionInj e a ()
weirdProjectionInj e b ()
weirdProjectionInj e c ()
weirdProjectionInj a e ()
weirdProjectionInj a a fx=fy = refl
weirdProjectionInj a b ()
weirdProjectionInj a c ()
weirdProjectionInj b e ()
weirdProjectionInj b a ()
weirdProjectionInj b b fx=fy = refl
weirdProjectionInj b c ()
weirdProjectionInj c e ()
weirdProjectionInj c a ()
weirdProjectionInj c b ()
weirdProjectionInj c c fx=fy = refl
weirdFinite : FiniteGroup weirdGroup (FinSet 4)
SetoidToSet.project (FiniteGroup.toSet weirdFinite) = weirdProjection
SetoidToSet.wellDefined (FiniteGroup.toSet weirdFinite) x y = applyEquality weirdProjection
SetoidToSet.surj (FiniteGroup.toSet weirdFinite) = weirdProjectionSurj
SetoidToSet.inj (FiniteGroup.toSet weirdFinite) = weirdProjectionInj
FiniteSet.size (FiniteGroup.finite weirdFinite) = 4
FiniteSet.mapping (FiniteGroup.finite weirdFinite) = id
FiniteSet.bij (FiniteGroup.finite weirdFinite) = idIsBijective
weirdOrder : groupOrder weirdFinite ≡ 4
weirdOrder = refl
-- TODO: dihedral groups
-- TODO: matrix groups on R
-- TODO: general linear groups on R
| {
"alphanum_fraction": 0.7110342519,
"avg_line_length": 41.8831775701,
"ext": "agda",
"hexsha": "cfbf7733befd7b7245fb59862b15103ec46e6124",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/LectureNotes/Lecture1.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/LectureNotes/Lecture1.agda",
"max_line_length": 386,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/LectureNotes/Lecture1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 3016,
"size": 8963
} |
-- The empty type; also used as absurd proposition (``Falsity'').
{-# OPTIONS --without-K --safe #-}
module Tools.Empty where
data ⊥ : Set where
-- Ex falsum quod libet.
⊥-elim : ∀ {a} {A : Set a} → ⊥ → A
⊥-elim ()
⊥-elimω : ∀ {A : Agda.Primitive.Setω} → ⊥ → A
⊥-elimω ()
| {
"alphanum_fraction": 0.571942446,
"avg_line_length": 17.375,
"ext": "agda",
"hexsha": "7e123e3bc8bbc11fed8d0ed4adb50bd3dd957f6c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Tools/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Tools/Empty.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Tools/Empty.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 106,
"size": 278
} |
module Lib where
-- Natural numbers
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat -> Nat -> Nat
zero + n = n
suc k + n = suc (k + n)
-- Finite sets
data Fin : Nat -> Set where
fzero : forall {n} -> Fin (suc n)
fsuc : forall {n} -> Fin n -> Fin (suc n)
fin : forall {n} (k : Nat) -> Fin (suc (k + n))
fin zero = fzero
fin (suc i) = fsuc (fin i)
-- Lists
infixl 0 _,_
data List (X : Set) : Set where
[] : List X
_,_ : List X -> X -> List X
-- List membership
data LMem {X : Set} (a : X) : List X -> Set where
lzero : forall {l} -> LMem a (l , a)
lsuc : forall {l b} -> LMem a l -> LMem a (l , b)
-- Vectors
data Vec (X : Set) : Nat -> Set where
[] : Vec X zero
_,_ : forall {n} -> Vec X n -> X -> Vec X (suc n)
proj : forall {X n} -> Vec X n -> Fin n -> X
proj [] ()
proj (_ , a) fzero = a
proj (v , _) (fsuc i) = proj v i
-- Vector membership
data VMem {X : Set} (a : X) : forall {n} -> Fin n -> Vec X n -> Set where
mzero : forall {n} {v : Vec X n} -> VMem a fzero (v , a)
msuc : forall {n i b} {v : Vec X n} -> VMem a i v -> VMem a (fsuc i) (v , b)
fmem : forall {X n} -> (i : Fin n) -> {v : Vec X n} -> VMem (proj v i) i v
fmem {_} {zero} ()
fmem {_} {suc n} fzero {_ , a} = mzero
fmem {_} {suc n} (fsuc i) {v , _} = msuc (fmem i)
mem : forall {X n} -> (k : Nat) -> {v : Vec X (suc (k + n))} -> VMem (proj v (fin k)) (fin k) v
mem i = fmem (fin i)
| {
"alphanum_fraction": 0.4746632457,
"avg_line_length": 22.5942028986,
"ext": "agda",
"hexsha": "1ea71170036f6dc08f1cfb317a695c1805f97225",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Lib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Lib.agda",
"max_line_length": 95,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Lib.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 597,
"size": 1559
} |
------------------------------------------------------------------------------
-- Agda-Prop Library.
-- Deep Embedding for Propositional Logic.
------------------------------------------------------------------------------
open import Data.Nat using ( ℕ )
module Data.PropFormula ( n : ℕ ) where
------------------------------------------------------------------------------
open import Data.PropFormula.Dec n public
open import Data.PropFormula.Properties n public
open import Data.PropFormula.Syntax n public
open import Data.PropFormula.Theorems n public
open import Data.Bool public
using ( Bool; true; false; not )
renaming ( _∧_ to _&&_; _∨_ to _||_ )
open import Data.Fin public using ( Fin; zero; suc; #_ )
open import Data.List public using ( List; []; _∷_; _++_; [_] )
open import Data.Vec public using ( Vec; lookup )
open import Function public using ( _$_ )
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4720812183,
"avg_line_length": 35.1785714286,
"ext": "agda",
"hexsha": "ea4ae66e257a0b406b148ce9dc709fc245037324",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z",
"max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jonaprieto/agda-prop",
"max_forks_repo_path": "src/Data/PropFormula.agda",
"max_issues_count": 18,
"max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jonaprieto/agda-prop",
"max_issues_repo_path": "src/Data/PropFormula.agda",
"max_line_length": 78,
"max_stars_count": 13,
"max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jonaprieto/agda-prop",
"max_stars_repo_path": "src/Data/PropFormula.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z",
"num_tokens": 185,
"size": 985
} |
module W where
open import Function using (_∘_)
open import Data.Bool using (Bool; true; false)
open import Data.Product
open import Data.Unit using (⊤; tt)
open import Data.Empty using (⊥; ⊥-elim)
data W (S : Set) (P : S → Set) : Set where
max : (s : S) → (f : P s → W S P) → W S P
-- data ℕ : Set where
-- zero : ℕ _^0
-- succ : ℕ → ℕ ∣ℕ∣
ℕ : Set
ℕ = W Bool f
where f : Bool → Set
f true = ⊤ -- 1
f false = ⊥ -- 0
zero : ℕ
zero = max false ⊥-elim
succ : ℕ → ℕ
succ n = max true (λ _ → n)
_+_ : ℕ → ℕ → ℕ
(max true f) + y = max true (λ _ → f tt + y)
(max false f) + y = y
-- data Tree : Set where
-- leaf : Tree _^0
-- node : Tree → Tree → Tree |ℕ| x |ℕ|
Tree : Set
Tree = W Bool λ { true → Bool ; false → ⊥ }
leaf : Tree
leaf = max false ⊥-elim -- _^0
node : Tree → Tree → Tree
node l r = max true λ { true → l -- ∣Tree∣^2
; false → r }
data LW (S : Set) (LP : S → Set × Set) : Set where
lmax : (s : Σ S (proj₁ ∘ LP)) → (proj₂ (LP (proj₁ s)) → LW S LP) → LW S LP
List : (X : Set) → Set
List X = LW Bool (λ { true → X , ⊤ -- cons
; false → ⊤ , ⊥ }) -- nil
nil : {X : Set} → List X
nil = lmax (false , tt) ⊥-elim
cons : {X : Set} → (x : X) → List X → List X
cons {X} x xs = lmax (true , x) λ _ → xs
-- induction principle on W-types
indW : (S : Set)
→ (P : S → Set)
→ (C : W S P → Set) -- property
→ (c : (s : S) -- given a shape
→ (f : P s → W S P) -- and a bunch of kids
→ (h : (p : P s) → C (f p)) -- if C holds for all kids
→ C (max s f)) -- C holds for (max s f)
→ (x : W S P)
→ C x
indW S P C step (max s f) = step s f (λ p → {! !} S P C step (f p))
indℕ : (C : ℕ → Set) → C zero → ((n : ℕ) → C n → C (succ n)) → (x : ℕ) → C x
indℕ C base step (max true f) = step (f tt) (indℕ C base step (f tt))
indℕ C base step (max false f) = {! base !}
| {
"alphanum_fraction": 0.4532019704,
"avg_line_length": 26.0256410256,
"ext": "agda",
"hexsha": "c8f125ea9ae5ee3dd974b47f36237a1e2f37ee42",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Sandbox/W.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Sandbox/W.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Sandbox/W.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 758,
"size": 2030
} |
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures
-1 : Set1
-1 = Set
| {
"alphanum_fraction": 0.7065217391,
"avg_line_length": 18.4,
"ext": "agda",
"hexsha": "9b01d15f1a71aa733e9d37af52842497af8681d6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1609-negative-literal.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1609-negative-literal.agda",
"max_line_length": 71,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1609-negative-literal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 30,
"size": 92
} |
------------------------------------------------------------------------
-- The one-step truncation HIT with an erased higher constructor
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining the one-step truncation operator
-- uses path equality, but the supplied notion of equality is used for
-- many other things.
import Equality.Path as P
module H-level.Truncation.Propositional.One-step.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Decidable-UIP equality-with-J using (Constant)
import Equality.Decidable-UIP P.equality-with-J as PD
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Equivalence.Erased.Cubical eq as EEq using (_≃ᴱ_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level.Closure equality-with-J
open import Surjection equality-with-J using (_↠_)
private
variable
a b p : Level
A B : Type a
P : A → Type p
e r x y : A
n : ℕ
------------------------------------------------------------------------
-- The type
-- One-step truncation.
--
-- This definition is based on that in van Doorn's "Constructing the
-- Propositional Truncation using Non-recursive HITs", but has an
-- erased higher constructor.
data ∥_∥¹ᴱ (A : Type a) : Type a where
∣_∣ : A → ∥ A ∥¹ᴱ
@0 ∣∣-constantᴾ : PD.Constant (∣_∣ {A = A})
-- The function ∣_∣ is constant (in erased contexts).
@0 ∣∣-constant : Constant (∣_∣ {A = A})
∣∣-constant x y = _↔_.from ≡↔≡ (∣∣-constantᴾ x y)
------------------------------------------------------------------------
-- Eliminators
-- A dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : ∥ A ∥¹ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
@0 ∣∣-constantʳ :
(x y : A) →
P.[ (λ i → P (∣∣-constantᴾ x y i)) ] ∣∣ʳ x ≡ ∣∣ʳ y
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : ∥ A ∥¹ᴱ) → P x
elimᴾ {A = A} {P = P} e = helper
where
module E = Elimᴾ e
helper : (x : ∥ A ∥¹ᴱ) → P x
helper ∣ x ∣ = E.∣∣ʳ x
helper (∣∣-constantᴾ x y i) = E.∣∣-constantʳ x y i
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
@0 ∣∣-constantʳ : PD.Constant ∣∣ʳ
open Recᴾ public
recᴾ : Recᴾ A B → ∥ A ∥¹ᴱ → B
recᴾ r = elimᴾ λ where
.∣∣ʳ → R.∣∣ʳ
.∣∣-constantʳ → R.∣∣-constantʳ
where
module R = Recᴾ r
-- A dependent eliminator.
record Elim {A : Type a} (P : ∥ A ∥¹ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
@0 ∣∣-constantʳ :
(x y : A) → subst P (∣∣-constant x y) (∣∣ʳ x) ≡ ∣∣ʳ y
open Elim public
elim : Elim P → (x : ∥ A ∥¹ᴱ) → P x
elim e = elimᴾ λ where
.∣∣ʳ → E.∣∣ʳ
.∣∣-constantʳ x y → subst≡→[]≡ (E.∣∣-constantʳ x y)
where
module E = Elim e
-- A "computation" rule.
@0 elim-∣∣-constant :
dcong (elim e) (∣∣-constant x y) ≡ Elim.∣∣-constantʳ e x y
elim-∣∣-constant = dcong-subst≡→[]≡ (refl _)
-- A non-dependent eliminator.
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
@0 ∣∣-constantʳ : Constant ∣∣ʳ
open Rec public
rec : Rec A B → ∥ A ∥¹ᴱ → B
rec r = recᴾ λ where
.∣∣ʳ → R.∣∣ʳ
.∣∣-constantʳ x y → _↔_.to ≡↔≡ (R.∣∣-constantʳ x y)
where
module R = Rec r
-- A "computation" rule.
@0 rec-∣∣-constant :
cong (rec r) (∣∣-constant x y) ≡ Rec.∣∣-constantʳ r x y
rec-∣∣-constant = cong-≡↔≡ (refl _)
-- A variant of rec.
rec′ : (f : A → B) → @0 Constant f → ∥ A ∥¹ᴱ → B
rec′ f c = rec λ where
.Rec.∣∣ʳ → f
.Rec.∣∣-constantʳ → c
------------------------------------------------------------------------
-- Some preservation lemmas
-- A map function for ∥_∥¹ᴱ.
∥∥¹ᴱ-map : (A → B) → ∥ A ∥¹ᴱ → ∥ B ∥¹ᴱ
∥∥¹ᴱ-map f = rec λ where
.∣∣ʳ x → ∣ f x ∣
.∣∣-constantʳ x y → ∣∣-constant (f x) (f y)
-- The truncation operator preserves logical equivalences.
∥∥¹ᴱ-cong-⇔ : A ⇔ B → ∥ A ∥¹ᴱ ⇔ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-⇔ A⇔B = record
{ to = ∥∥¹ᴱ-map (_⇔_.to A⇔B)
; from = ∥∥¹ᴱ-map (_⇔_.from A⇔B)
}
private
-- A lemma used below.
@0 ∥∥¹ᴱ-cong-lemma :
(f : A → B) (g : B → A) (eq : ∀ x → f (g x) ≡ x) →
subst (λ z → ∥∥¹ᴱ-map f (∥∥¹ᴱ-map g z) ≡ z)
(∣∣-constant x y) (cong ∣_∣ (eq x)) ≡
cong ∣_∣ (eq y)
∥∥¹ᴱ-cong-lemma {x = x} {y = y} f g eq =
subst
(λ z → ∥∥¹ᴱ-map f (∥∥¹ᴱ-map g z) ≡ z)
(∣∣-constant x y) (cong ∣_∣ (eq x)) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (∥∥¹ᴱ-map f ∘ ∥∥¹ᴱ-map g) (∣∣-constant x y)))
(trans (cong ∣_∣ (eq x)) (cong id (∣∣-constant x y))) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (cong ∣_∣ (eq x)) q))
(trans (sym $ cong-∘ _ _ _) $
trans (cong (cong (∥∥¹ᴱ-map f)) rec-∣∣-constant) $
rec-∣∣-constant)
(sym $ cong-id _) ⟩
trans (sym (∣∣-constant (f (g x)) (f (g y))))
(trans (cong ∣_∣ (eq x)) (∣∣-constant x y)) ≡⟨ cong (λ f → trans _ (trans (cong ∣_∣ (f _)) _)) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) eq ⟩
trans (sym (∣∣-constant (f (g x)) (f (g y))))
(trans (cong ∣_∣ (ext⁻¹ (⟨ext⟩ eq) x)) (∣∣-constant x y)) ≡⟨ elim₁
(λ {f} eq → trans (sym (∣∣-constant (f x) (f y)))
(trans (cong ∣_∣ (ext⁻¹ eq x)) (∣∣-constant x y)) ≡
cong ∣_∣ (ext⁻¹ eq y))
(
trans (sym (∣∣-constant x y))
(trans (cong ∣_∣ (ext⁻¹ (refl id) x)) (∣∣-constant x y)) ≡⟨ cong (trans _) $
trans (cong (flip trans _) $
trans (cong (cong _) $ cong-refl _) $
cong-refl _) $
trans-reflˡ _ ⟩
trans (sym (∣∣-constant x y)) (∣∣-constant x y) ≡⟨ trans-symˡ _ ⟩
refl _ ≡⟨ trans (sym $ cong-refl _) $
cong (cong _) $ sym $ cong-refl _ ⟩∎
cong ∣_∣ (ext⁻¹ (refl _) y) ∎)
_ ⟩
cong ∣_∣ (ext⁻¹ (⟨ext⟩ eq) y) ≡⟨ cong (λ f → cong ∣_∣ (f _)) $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) eq ⟩∎
cong ∣_∣ (eq y) ∎
-- The truncation operator preserves split surjections.
∥∥¹ᴱ-cong-↠ : A ↠ B → ∥ A ∥¹ᴱ ↠ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-↠ A↠B = record
{ logical-equivalence = ∥∥¹ᴱ-cong-⇔ (_↠_.logical-equivalence A↠B)
; right-inverse-of = elim λ where
.∣∣ʳ x → cong ∣_∣ (_↠_.right-inverse-of A↠B x)
.∣∣-constantʳ x y →
∥∥¹ᴱ-cong-lemma (_↠_.to A↠B) (_↠_.from A↠B)
(_↠_.right-inverse-of A↠B)
}
-- The truncation operator preserves bijections.
∥∥¹ᴱ-cong-↔ : A ↔ B → ∥ A ∥¹ᴱ ↔ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-↔ A↔B = record
{ surjection = ∥∥¹ᴱ-cong-↠ (_↔_.surjection A↔B)
; left-inverse-of = elim λ where
.∣∣ʳ x → cong ∣_∣ (_↔_.left-inverse-of A↔B x)
.∣∣-constantʳ x y →
∥∥¹ᴱ-cong-lemma (_↔_.from A↔B) (_↔_.to A↔B)
(_↔_.left-inverse-of A↔B)
}
-- The truncation operator preserves equivalences.
∥∥¹ᴱ-cong-≃ : A ≃ B → ∥ A ∥¹ᴱ ≃ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-≃ = from-isomorphism ∘ ∥∥¹ᴱ-cong-↔ ∘ from-isomorphism
-- The truncation operator preserves equivalences with erased proofs.
∥∥¹ᴱ-cong-≃ᴱ : A ≃ᴱ B → ∥ A ∥¹ᴱ ≃ᴱ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-≃ᴱ A≃B =
EEq.[≃]→≃ᴱ (EEq.[proofs] (∥∥¹ᴱ-cong-≃ (EEq.≃ᴱ→≃ A≃B)))
------------------------------------------------------------------------
-- Iterated applications of the one-step truncation operator
-- Applies the one-step truncation the given number of times, from the
-- "outside".
--
-- This definition and the next one are taken from van Doorn's
-- "Constructing the Propositional Truncation using Non-recursive
-- HITs".
∥_∥¹ᴱ-out-^ : Type a → ℕ → Type a
∥ A ∥¹ᴱ-out-^ zero = A
∥ A ∥¹ᴱ-out-^ (suc n) = ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ
-- A "constructor" for ∥_∥¹ᴱ-out-^.
∣_∣-out-^ : A → ∀ n → ∥ A ∥¹ᴱ-out-^ n
∣ x ∣-out-^ zero = x
∣ x ∣-out-^ (suc n) = ∣ ∣ x ∣-out-^ n ∣
-- A rearrangement lemma.
∥∥¹ᴱ-out-^+≃ :
∀ m → ∥ A ∥¹ᴱ-out-^ (m + n) ≃ ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ-out-^ m
∥∥¹ᴱ-out-^+≃ zero = F.id
∥∥¹ᴱ-out-^+≃ {A = A} {n = n} (suc m) =
∥ ∥ A ∥¹ᴱ-out-^ (m + n) ∥¹ᴱ ↝⟨ ∥∥¹ᴱ-cong-≃ (∥∥¹ᴱ-out-^+≃ m) ⟩□
∥ ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ-out-^ m ∥¹ᴱ □
-- ∥_∥¹ᴱ commutes with ∥_∥¹ᴱ-out-^ n.
∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute :
∀ n → ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ↔ ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-out-^ n
∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute zero = F.id
∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute {A = A} (suc n) =
∥ ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ∥¹ᴱ ↝⟨ ∥∥¹ᴱ-cong-↔ (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) ⟩□
∥ ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-out-^ n ∥¹ᴱ □
private
-- The lemma above is defined using _↔_ rather than _≃_ because the
-- following equalities hold by definition when _↔_ is used, but (at
-- the time of writing) the second one does not hold when _≃_ is
-- used.
_ :
{x : A} →
_↔_.left-inverse-of (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute 0) ∣ x ∣ ≡ refl ∣ x ∣
_ = refl _
_ :
{A : Type a} {x : ∥ A ∥¹ᴱ-out-^ (suc n)} →
_↔_.left-inverse-of (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n)) ∣ x ∣ ≡
cong ∣_∣ (_↔_.left-inverse-of (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) x)
_ = refl _
-- A variant of ∥_∥¹ᴱ-out-^ which applies the one-step truncation the
-- given number of times from the "inside".
∥_∥¹ᴱ-in-^ : Type a → ℕ → Type a
∥ A ∥¹ᴱ-in-^ zero = A
∥ A ∥¹ᴱ-in-^ (suc n) = ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n
-- The two variants of ∥_∥¹ᴱ^ are pointwise equivalent.
∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ : ∀ n → ∥ A ∥¹ᴱ-out-^ n ≃ ∥ A ∥¹ᴱ-in-^ n
∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ zero = F.id
∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ {A = A} (suc n) =
∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ↔⟨ ∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n ⟩
∥ ∥ A ∥¹ᴱ ∥¹ᴱ-out-^ n ↝⟨ ∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n ⟩□
∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n □
-- ∥_∥¹ᴱ commutes with ∥_∥¹ᴱ-in-^ n.
∥∥¹ᴱ-∥∥¹ᴱ-in-^-commute : ∀ n → ∥ ∥ A ∥¹ᴱ-in-^ n ∥¹ᴱ ≃ ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n
∥∥¹ᴱ-∥∥¹ᴱ-in-^-commute {A = A} n =
∥ ∥ A ∥¹ᴱ-in-^ n ∥¹ᴱ ↝⟨ ∥∥¹ᴱ-cong-≃ (inverse $ ∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) ⟩
∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ↔⟨⟩
∥ A ∥¹ᴱ-out-^ (suc n) ↝⟨ ∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (suc n) ⟩
∥ A ∥¹ᴱ-in-^ (suc n) ↔⟨⟩
∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n □
-- A "constructor" for ∥_∥¹ᴱ-in-^.
∣_,_∣-in-^ : ∀ n → ∥ A ∥¹ᴱ-in-^ n → ∥ A ∥¹ᴱ-in-^ (suc n)
∣ zero , x ∣-in-^ = ∣ x ∣
∣ suc n , x ∣-in-^ = ∣ n , x ∣-in-^
-- ∣_,_∣-in-^ is related to ∣_∣.
∣∣≡∣,∣-in-^ :
∀ n {x : ∥ A ∥¹ᴱ-out-^ n} →
_≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (suc n)) ∣ x ∣ ≡
∣ n , _≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) x ∣-in-^
∣∣≡∣,∣-in-^ zero {x = x} = ∣ x ∣ ∎
∣∣≡∣,∣-in-^ (suc n) {x = x} =
_≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (2 + n)) ∣ x ∣ ≡⟨⟩
_≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (1 + n))
∣ _↔_.to (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) x ∣ ≡⟨ ∣∣≡∣,∣-in-^ n ⟩∎
∣ n , _≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n)
(_↔_.to (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) x) ∣-in-^ ∎
-- A variant of ∣∣≡∣,∣-in-^.
∣,∣-in-^≡∣∣ :
∀ n {x : ∥ A ∥¹ᴱ-in-^ n} →
_≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (suc n)) ∣ n , x ∣-in-^ ≡
∣ _≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) x ∣
∣,∣-in-^≡∣∣ zero {x = x} = ∣ x ∣ ∎
∣,∣-in-^≡∣∣ (suc n) {x = x} =
_≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (2 + n)) ∣ 1 + n , x ∣-in-^ ≡⟨⟩
_↔_.from (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n))
(_≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (1 + n)) ∣ n , x ∣-in-^) ≡⟨ cong (_↔_.from (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n))) $ ∣,∣-in-^≡∣∣ n ⟩∎
_↔_.from (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n))
∣ _≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) x ∣ ∎
| {
"alphanum_fraction": 0.4401943395,
"avg_line_length": 34.8575268817,
"ext": "agda",
"hexsha": "293715f0f73b952beb23af5cb3fb49e97094a1bc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/H-level/Truncation/Propositional/One-step/Erased.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/H-level/Truncation/Propositional/One-step/Erased.agda",
"max_line_length": 138,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/H-level/Truncation/Propositional/One-step/Erased.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 6069,
"size": 12967
} |
{-# OPTIONS --universe-polymorphism #-}
module Coind where
open import Common.IO
open import Common.Level
open import Common.Nat
open import Common.Unit
open import Common.Coinduction renaming (♯_ to sharp; ♭ to flat)
{-
infix 1000 sharp_
postulate
Infinity : ∀ {a} (A : Set a) → Set a
sharp_ : ∀ {a} {A : Set a} → A → Infinity A
flat : ∀ {a} {A : Set a} → Infinity A → A
{-# BUILTIN INFINITY Infinity #-}
{-# BUILTIN SHARP sharp_ #-}
{-# BUILTIN FLAT flat #-}
-}
data Stream (A : Set) : Set where
_::_ : (x : A) (xs : ∞ (Stream A)) → Stream A
ones : Stream Nat
ones = 1 :: (sharp ones)
twos : Stream Nat
twos = 2 :: (sharp twos)
incr : Nat -> Stream Nat
incr n = n :: (sharp (incr (n + 1)))
printStream : Nat -> Stream Nat -> IO Unit
printStream zero _ = putStrLn ""
printStream (suc steps) (n :: ns) =
printNat n ,,
printStream steps (flat ns)
main : IO Unit
main =
printStream 10 twos ,,
printStream 10 ones ,,
printStream 10 (incr zero)
| {
"alphanum_fraction": 0.6202020202,
"avg_line_length": 21.5217391304,
"ext": "agda",
"hexsha": "302b52143b713e8a731fb0447e838c45d21708d8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Compiler/simple/Coind.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": "2017-02-24T19:38:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-02-24T19:27:31.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Compiler/simple/Coind.agda",
"max_line_length": 64,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Compiler/simple/Coind.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-23T04:56:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-02-24T16:53:22.000Z",
"num_tokens": 316,
"size": 990
} |
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Definition of Bool datatype, which represents logical true and --
-- false. --
----------------------------------------------------------------------
module Basics.Bool where
data Bool : Set where
false : Bool
true : Bool
| {
"alphanum_fraction": 0.3454038997,
"avg_line_length": 44.875,
"ext": "agda",
"hexsha": "62423a6c4dbc59953ec4f5dbd8fb3dd8b72cde92",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/Basics/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/Basics/Bool.agda",
"max_line_length": 70,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/Basics/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 103,
"size": 718
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidable propositional membership over lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality using (_≡_; decSetoid)
module Data.List.Membership.DecPropositional
{a} {A : Set a} (_≟_ : Decidable (_≡_ {A = A})) where
------------------------------------------------------------------------
-- Re-export contents of propositional membership
open import Data.List.Membership.Propositional {A = A} public
open import Data.List.Membership.DecSetoid (decSetoid _≟_) public
using (_∈?_)
| {
"alphanum_fraction": 0.5278514589,
"avg_line_length": 34.2727272727,
"ext": "agda",
"hexsha": "9909301188fdd290ebc409079c9054e07fd881dc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/DecPropositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/DecPropositional.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/DecPropositional.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 147,
"size": 754
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Fun.Facts.Product where
open import Data.Product using (_,_)
open import Cats.Category
open import Cats.Category.Fun as Fun using (_↝_)
open import Cats.Category.Constructions.Product using (HasBinaryProducts)
open import Cats.Functor using (Functor)
open import Cats.Trans using (Trans)
import Cats.Category.Fun.Facts.Terminal as Terminal
open Functor
open Trans
module Build {lo la l≈ lo′ la′ l≈′}
(C : Category lo la l≈) (D : Category lo′ la′ l≈′)
{{D× : HasBinaryProducts D}}
where
infixr 2 _×_ _×′_ ⟨_,_⟩
private
module D = Category D
module D× = HasBinaryProducts D×
open D.≈
open Category (C ↝ D)
_×_ : (F G : Obj) → Obj
F × G = record
{ fobj = λ c → fobj F c D×.× fobj G c
; fmap = λ f → D×.⟨ fmap F f × fmap G f ⟩
; fmap-resp = λ f≈g → D×.⟨×⟩-resp (fmap-resp F f≈g) (fmap-resp G f≈g)
; fmap-id = trans (D×.⟨×⟩-resp (fmap-id F) (fmap-id G)) D×.⟨×⟩-id
; fmap-∘ = trans D×.⟨×⟩-∘ (D×.⟨×⟩-resp (fmap-∘ F) (fmap-∘ G))
}
projl : ∀ {F G} → F × G ⇒ F
projl = record
{ component = λ c → D×.projl
; natural = D×.⟨×⟩-projl
}
projr : ∀ {F G} → F × G ⇒ G
projr = record
{ component = λ c → D×.projr
; natural = D×.⟨×⟩-projr
}
⟨_,_⟩ : ∀ {F G X} → X ⇒ F → X ⇒ G → X ⇒ F × G
⟨_,_⟩ α β = record
{ component = λ c → D×.⟨ component α c , component β c ⟩
; natural = λ {c} {d} {f} →
trans D×.⟨,⟩-∘
(trans (D×.⟨,⟩-resp (natural α) (natural β))
(sym D×.⟨×⟩-⟨,⟩))
}
⟨,⟩-projl : ∀ {F G X} {α : X ⇒ F} (β : X ⇒ G)
→ α ≈ projl ∘ ⟨ α , β ⟩
⟨,⟩-projl β = Fun.≈-intro (sym D×.⟨,⟩-projl)
⟨,⟩-projr : ∀ {F G X} (α : X ⇒ F) {β : X ⇒ G}
→ β ≈ projr ∘ ⟨ α , β ⟩
⟨,⟩-projr α = Fun.≈-intro (sym D×.⟨,⟩-projr)
⟨,⟩-unique : ∀ {F G X} {α : X ⇒ F} {β : X ⇒ G} {u}
→ α ≈ projl ∘ u
→ β ≈ projr ∘ u
→ ⟨ α , β ⟩ ≈ u
⟨,⟩-unique (Fun.≈-intro pl) (Fun.≈-intro pr)
= Fun.≈-intro (D×.⟨,⟩-unique pl pr)
isBinaryProduct : ∀ {F G} → IsBinaryProduct (F × G) projl projr
isBinaryProduct α β = record
{ arr = ⟨ α , β ⟩
; prop = (⟨,⟩-projl β , ⟨,⟩-projr α)
; unique = λ { (eql , eqr) → ⟨,⟩-unique eql eqr }
}
_×′_ : (F G : Obj) → BinaryProduct F G
F ×′ G = mkBinaryProduct projl projr isBinaryProduct
private
open module Build′ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
= Build C D
public
instance
hasBinaryProducts : ∀ {lo la l≈ lo′ la′ l≈′}
→ {C : Category lo la l≈} {D : Category lo′ la′ l≈′}
→ {{D× : HasBinaryProducts D}}
→ HasBinaryProducts (C ↝ D)
hasBinaryProducts = record { _×′_ = _×′_ }
hasFiniteProducts : ∀ {lo la l≈ lo′ la′ l≈′}
→ {C : Category lo la l≈} {D : Category lo′ la′ l≈′}
→ {{D× : HasFiniteProducts D}}
→ HasFiniteProducts (C ↝ D)
hasFiniteProducts = record { hasTerminal = Terminal.hasTerminal }
-- record {} doesn't work for some reason.
| {
"alphanum_fraction": 0.5223631509,
"avg_line_length": 25.6068376068,
"ext": "agda",
"hexsha": "1a4dcaca22fdf6d7c42777b9501e20c8cc8b6209",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Fun/Facts/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Fun/Facts/Product.agda",
"max_line_length": 73,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Fun/Facts/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 1238,
"size": 2996
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.FiberedProduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
private
variable
ℓ : Level
module _ (A B C : CommRing ℓ) (α : CommRingHom A C) (β : CommRingHom B C) where
private
module A = CommRingStr (snd A)
module B = CommRingStr (snd B)
module C = CommRingStr (snd C)
module α = IsRingHom (snd α)
module β = IsRingHom (snd β)
open CommRingStr
open CommRingHoms
open IsRingHom
fbT : Type ℓ
fbT = Σ[ ab ∈ fst A × fst B ] (fst α (fst ab) ≡ fst β (snd ab))
fbT≡ : {x y : fbT} → fst (fst x) ≡ fst (fst y) → snd (fst x) ≡ snd (fst y) → x ≡ y
fbT≡ h1 h2 = Σ≡Prop (λ _ → is-set (snd C) _ _) λ i → (h1 i) , (h2 i)
0fbT : fbT
0fbT = (A.0r , B.0r) , α.pres0 ∙ sym β.pres0
1fbT : fbT
1fbT = (A.1r , B.1r) , α.pres1 ∙ sym β.pres1
_+fbT_ : fbT → fbT → fbT
((a1 , b1) , hab1) +fbT ((a2 , b2) , hab2) =
(a1 A.+ a2 , b1 B.+ b2) , α.pres+ a1 a2 ∙∙ (λ i → hab1 i C.+ hab2 i) ∙∙ sym (β.pres+ b1 b2)
_·fbT_ : fbT → fbT → fbT
((a1 , b1) , hab1) ·fbT ((a2 , b2) , hab2) =
(a1 A.· a2 , b1 B.· b2) , α.pres· a1 a2 ∙∙ (λ i → hab1 i C.· hab2 i) ∙∙ sym (β.pres· b1 b2)
-fbT_ : fbT → fbT
-fbT ((a , b) , hab) = (A.- a , B.- b) , α.pres- a ∙∙ cong C.-_ hab ∙∙ sym (β.pres- b)
fiberedProduct : CommRing ℓ
fst fiberedProduct = fbT
0r (snd fiberedProduct) = 0fbT
1r (snd fiberedProduct) = 1fbT
_+_ (snd fiberedProduct) = _+fbT_
_·_ (snd fiberedProduct) = _·fbT_
-_ (snd fiberedProduct) = -fbT_
isCommRing (snd fiberedProduct) =
makeIsCommRing (isSetΣSndProp (isSet× (is-set (snd A)) (is-set (snd B))) λ x → is-set (snd C) _ _)
(λ _ _ _ → fbT≡ (A.+Assoc _ _ _) (B.+Assoc _ _ _))
(λ _ → fbT≡ (A.+Rid _) (B.+Rid _))
(λ _ → fbT≡ (A.+Rinv _) (B.+Rinv _))
(λ _ _ → fbT≡ (A.+Comm _ _) (B.+Comm _ _))
(λ _ _ _ → fbT≡ (A.·Assoc _ _ _) (B.·Assoc _ _ _))
(λ _ → fbT≡ (A.·Rid _) (B.·Rid _))
(λ _ _ _ → fbT≡ (A.·Rdist+ _ _ _) (B.·Rdist+ _ _ _))
(λ _ _ → fbT≡ (A.·Comm _ _) (B.·Comm _ _))
fiberedProductPr₁ : CommRingHom fiberedProduct A
fst fiberedProductPr₁ = fst ∘ fst
snd fiberedProductPr₁ = makeIsRingHom refl (λ _ _ → refl) (λ _ _ → refl)
fiberedProductPr₂ : CommRingHom fiberedProduct B
fst fiberedProductPr₂ = snd ∘ fst
snd fiberedProductPr₂ = makeIsRingHom refl (λ _ _ → refl) (λ _ _ → refl)
fiberedProductPr₁₂Commutes : compCommRingHom fiberedProduct A C fiberedProductPr₁ α
≡ compCommRingHom fiberedProduct B C fiberedProductPr₂ β
fiberedProductPr₁₂Commutes = RingHom≡ (funExt (λ x → x .snd))
fiberedProductUnivProp :
(D : CommRing ℓ) (h : CommRingHom D A) (k : CommRingHom D B) →
compCommRingHom D A C h α ≡ compCommRingHom D B C k β →
∃![ l ∈ CommRingHom D fiberedProduct ]
(h ≡ compCommRingHom D fiberedProduct A l fiberedProductPr₁)
× (k ≡ compCommRingHom D fiberedProduct B l fiberedProductPr₂)
fiberedProductUnivProp D (h , hh) (k , hk) H =
uniqueExists f (RingHom≡ refl , RingHom≡ refl)
(λ _ → isProp× (isSetRingHom _ _ _ _) (isSetRingHom _ _ _ _))
(λ { (g , _) (Hh , Hk) →
RingHom≡ (funExt (λ d → fbT≡ (funExt⁻ (cong fst Hh) d)
(funExt⁻ (cong fst Hk) d))) })
where
f : CommRingHom D fiberedProduct
fst f d = (h d , k d) , funExt⁻ (cong fst H) d
snd f = makeIsRingHom (fbT≡ (hh .pres1) (hk .pres1))
(λ _ _ → fbT≡ (hh .pres+ _ _) (hk .pres+ _ _))
(λ _ _ → fbT≡ (hh .pres· _ _) (hk .pres· _ _))
| {
"alphanum_fraction": 0.5615738375,
"avg_line_length": 38.3725490196,
"ext": "agda",
"hexsha": "8325782ee771980a6c738ba0007fb7c8b6669e71",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lpw25/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/FiberedProduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lpw25/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/FiberedProduct.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lpw25/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/FiberedProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1539,
"size": 3914
} |
{-# OPTIONS --without-K #-}
module sets.nat.ordering.leq.decide where
open import decidable
open import sets.core
open import sets.nat.core
open import sets.nat.ordering.leq.core
open import sets.nat.ordering.lt.core
_≤?_ : (n m : ℕ) → Dec (n ≤ m)
0 ≤? m = yes z≤n
suc n ≤? 0 = no λ ()
suc n ≤? suc m with n ≤? m
suc n ≤? suc m | yes p = yes (s≤s p)
suc n ≤? suc m | no u = no λ p → u (ap-pred-≤ p)
| {
"alphanum_fraction": 0.6259351621,
"avg_line_length": 25.0625,
"ext": "agda",
"hexsha": "b7615da29bf1f03112de0bc2f6e10f5dae161829",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/nat/ordering/leq/decide.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/nat/ordering/leq/decide.agda",
"max_line_length": 48,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/nat/ordering/leq/decide.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 154,
"size": 401
} |
-- records are allowed in mutual blocks
module Issue138 where
mutual
B = Set
record Foo : Set where
| {
"alphanum_fraction": 0.712962963,
"avg_line_length": 10.8,
"ext": "agda",
"hexsha": "da1037159f7665c1ab8527a38cdc333fc6038164",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue138.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue138.agda",
"max_line_length": 39,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue138.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 28,
"size": 108
} |
-- This file tests that record constructors are used in error
-- messages, if possible.
module RecordConstructorsInErrorMessages where
record R : Set₁ where
constructor con
field
{A} : Set
f : A → A
{B C} D {E} : Set
g : B → C → E
postulate
A : Set
r₁ : R
r₂ : R
r₂ = record
{ A = A
; f = λ x → x
; B = A
; C = A
; D = A
; g = λ x _ → x
}
data _≡_ {A : Set₁} (x : A) : A → Set where
refl : x ≡ x
foo : r₁ ≡ r₂
foo = refl
| {
"alphanum_fraction": 0.5040322581,
"avg_line_length": 15.0303030303,
"ext": "agda",
"hexsha": "034b6d4f1dcda6a5d3cd942d0720aec4949afc45",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/RecordConstructorsInErrorMessages.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/RecordConstructorsInErrorMessages.agda",
"max_line_length": 61,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/RecordConstructorsInErrorMessages.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 192,
"size": 496
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.