hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
a157f0b6d69709a08cb23ab91e499a55e86db89f
| 475
|
agda
|
Agda
|
test/Succeed/Issue4528.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4528.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4528.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.List
postulate
A : Set
nilA : A
consA : A → List A → A
w/e : {x y : A} → x ≡ y
data D : List A → Set where
nil : D []
cons : (x : A) (xs : List A) → D (x ∷ xs)
foo : ∀ {xs} (d : D xs)
(let f : D xs → A
f = λ where nil → nilA
(cons y ys) → consA y ys) →
f d ≡ nilA
foo nil = {!!}
foo (cons _ _) = w/e
| 21.590909
| 50
| 0.471579
|
ad138a0e90c06ee79ce757624e1872e4626699ad
| 612
|
agda
|
Agda
|
Cubical/Algebra/Semigroup/Construct/Empty.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semigroup/Construct/Empty.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semigroup/Construct/Empty.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Semigroup.Construct.Empty where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Semigroup
open import Cubical.Data.Empty
import Cubical.Algebra.Magma.Construct.Empty as ⊥Magma
open ⊥Magma public hiding (⊥-isMagma; ⊥-Magma)
◯-assoc : Associative _◯_
◯-assoc _ _ _ = isProp⊥ _ _
⊥-isSemigroup : IsSemigroup ⊥ _◯_
⊥-isSemigroup = record
{ isMagma = ⊥Magma.⊥-isMagma
; assoc = ◯-assoc
}
⊥-Semigroup : Semigroup ℓ-zero
⊥-Semigroup = record { isSemigroup = ⊥-isSemigroup }
| 24.48
| 54
| 0.730392
|
2e7b00323d3284c4500ca607f3e66488fd237793
| 4,024
|
agda
|
Agda
|
core/lib/types/Coproduct.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Coproduct.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Coproduct.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Empty
open import lib.types.Lift
open import lib.types.Sigma
open import lib.types.Pi
module lib.types.Coproduct where
module _ {i j} {A : Type i} {B : Type j} where
Coprod= : Coprod A B → Coprod A B → Type (lmax i j)
Coprod= (inl a₁) (inl a₂) = Lift {j = (lmax i j)} $ a₁ == a₂
Coprod= (inl a₁) (inr b₂) = Lift Empty
Coprod= (inr b₁) (inl a₂) = Lift Empty
Coprod= (inr b₁) (inr b₂) = Lift {j = (lmax i j)} $ b₁ == b₂
Coprod=-in : {x y : Coprod A B} → (x == y) → Coprod= x y
Coprod=-in {inl _} idp = lift idp
Coprod=-in {inr _} idp = lift idp
Coprod=-out : {x y : Coprod A B} → Coprod= x y → (x == y)
Coprod=-out {inl _} {inl _} c = ap inl $ lower c
Coprod=-out {inl _} {inr _} c = Empty-rec $ lower c
Coprod=-out {inr _} {inl _} c = Empty-rec $ lower c
Coprod=-out {inr _} {inr _} c = ap inr (lower c)
Coprod=-in-equiv : (x y : Coprod A B) → (x == y) ≃ Coprod= x y
Coprod=-in-equiv x y = equiv Coprod=-in Coprod=-out (f-g x y) (g-f x y)
where f-g : ∀ x' y' → ∀ c → Coprod=-in (Coprod=-out {x'} {y'} c) == c
f-g (inl a₁) (inl .a₁) (lift idp) = idp
f-g (inl a₁) (inr b₂) b = Empty-rec $ lower b
f-g (inr b₁) (inl a₂) b = Empty-rec $ lower b
f-g (inr b₁) (inr .b₁) (lift idp) = idp
g-f : ∀ x' y' → ∀ p → Coprod=-out (Coprod=-in {x'} {y'} p) == p
g-f (inl _) .(inl _) idp = idp
g-f (inr _) .(inr _) idp = idp
inl=inl-equiv : (a₁ a₂ : A) → (inl a₁ == inl a₂) ≃ (a₁ == a₂)
inl=inl-equiv a₁ a₂ = lower-equiv ∘e Coprod=-in-equiv (inl a₁) (inl a₂)
inr=inr-equiv : (b₁ b₂ : B) → (inr b₁ == inr b₂) ≃ (b₁ == b₂)
inr=inr-equiv b₁ b₂ = lower-equiv ∘e Coprod=-in-equiv (inr b₁) (inr b₂)
inl≠inr : (a₁ : A) (b₂ : B) → (inl a₁ ≠ inr b₂)
inl≠inr a₁ b₂ p = lower $ Coprod=-in p
inr≠inl : (b₁ : B) (a₂ : A) → (inr b₁ ≠ inl a₂)
inr≠inl a₁ b₂ p = lower $ Coprod=-in p
⊔-level : ∀ {n} → has-level (S (S n)) A → has-level (S (S n)) B
→ has-level (S (S n)) (Coprod A B)
⊔-level pA _ (inl a₁) (inl a₂) =
equiv-preserves-level (inl=inl-equiv a₁ a₂ ⁻¹) (pA a₁ a₂)
⊔-level _ _ (inl a₁) (inr b₂) = λ p → Empty-rec (inl≠inr a₁ b₂ p)
⊔-level _ _ (inr b₁) (inl a₂) = λ p → Empty-rec (inr≠inl b₁ a₂ p)
⊔-level _ pB (inr b₁) (inr b₂) =
equiv-preserves-level ((inr=inr-equiv b₁ b₂)⁻¹) (pB b₁ b₂)
Coprod-level = ⊔-level
infix 80 _⊙⊔_
_⊙⊔_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊙⊔ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inl (pt X) ]
_⊔⊙_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊔⊙ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inr (pt Y) ]
codiag : ∀ {i} {A : Type i} → A ⊔ A → A
codiag (inl a) = a
codiag (inr a) = a
⊙codiag : ∀ {i} {X : Ptd i} → X ⊙⊔ X ⊙→ X
⊙codiag = (codiag , idp)
-- A binary sigma is a coproduct
ΣBool-equiv-⊔ : ∀ {i} (Pick : Bool → Type i)
→ Σ Bool Pick ≃ Pick true ⊔ Pick false
ΣBool-equiv-⊔ Pick = equiv into out into-out out-into
where
into : Σ _ Pick → Pick true ⊔ Pick false
into (true , a) = inl a
into (false , b) = inr b
out : (Pick true ⊔ Pick false) → Σ _ Pick
out (inl a) = (true , a)
out (inr b) = (false , b)
abstract
into-out : ∀ c → into (out c) == c
into-out (inl a) = idp
into-out (inr b) = idp
out-into : ∀ s → out (into s) == s
out-into (true , a) = idp
out-into (false , b) = idp
module _ {i j k} {A : Type i} {B : Type j} (P : A ⊔ B → Type k) where
Π₁-⊔-equiv-× : Π (A ⊔ B) P ≃ Π A (P ∘ inl) × Π B (P ∘ inr)
Π₁-⊔-equiv-× = equiv to from to-from from-to
where
to : Π (A ⊔ B) P → Π A (P ∘ inl) × Π B (P ∘ inr)
to f = (λ a → f (inl a)) , (λ b → f (inr b))
from : Π A (P ∘ inl) × Π B (P ∘ inr) → Π (A ⊔ B) P
from (f , g) (inl a) = f a
from (f , g) (inr b) = g b
abstract
to-from : ∀ fg → to (from fg) == fg
to-from _ = idp
from-to : ∀ fg → from (to fg) == fg
from-to fg = λ= λ where (inl _) → idp
(inr _) → idp
| 33.815126
| 73
| 0.519135
|
4b5dbe09c3e3553e281201ca40edbc12cc8e59f7
| 1,698
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/PreludeList.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
examples/outdated-and-incorrect/Alonzo/PreludeList.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/Alonzo/PreludeList.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module PreludeList where
open import AlonzoPrelude as Prelude
open import PreludeNat
infixr 50 _::_ _++_
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
[_] : {A : Set} -> A -> List A
[ x ] = x :: []
length : {A : Set} -> List A -> Nat
length [] = 0
length (_ :: xs) = 1 + length xs
map : {A B : Set} -> (A -> B) -> List A -> List B
map f [] = []
map f (x :: xs) = f x :: map f xs
_++_ : {A : Set} -> List A -> List A -> List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
zipWith : {A B C : Set} -> (A -> B -> C) -> List A -> List B -> List C
zipWith f [] [] = []
zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys
zipWith f [] (_ :: _) = []
zipWith f (_ :: _) [] = []
foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B
foldr f z [] = z
foldr f z (x :: xs) = f x (foldr f z xs)
foldl : {A B : Set} -> (B -> A -> B) -> B -> List A -> B
foldl f z [] = z
foldl f z (x :: xs) = foldl f (f z x) xs
replicate : {A : Set} -> Nat -> A -> List A
replicate zero x = []
replicate (suc n) x = x :: replicate n x
iterate : {A : Set} -> Nat -> (A -> A) -> A -> List A
iterate zero f x = []
iterate (suc n) f x = x :: iterate n f (f x)
splitAt : {A : Set} -> Nat -> List A -> List A × List A
splitAt zero xs = < [] , xs >
splitAt (suc n) [] = < [] , [] >
splitAt (suc n) (x :: xs) = add x $ splitAt n xs
where
add : _ -> List _ × List _ -> List _ × List _
add x < ys , zs > = < x :: ys , zs >
reverse : {A : Set} -> List A -> List A
reverse xs = foldl (flip _::_) [] xs
| 25.727273
| 70
| 0.452297
|
583c03b301904cf94447f4be2841895b0fb974cc
| 271
|
agda
|
Agda
|
test/Fail/SafeFlagPragmas.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/SafeFlagPragmas.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/SafeFlagPragmas.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --allow-unsolved-metas
--no-positivity-check
--no-termination-check
--type-in-type
--sized-types
--injective-type-constructors
--experimental-irrelevance #-}
module SafeFlagPragmas where
| 30.111111
| 42
| 0.568266
|
388ba72f60f4ef9fb0a00202415e8c0833769ada
| 2,583
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/BoundedVec.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/BoundedVec.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/BoundedVec.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bounded vectors
------------------------------------------------------------------------
-- Vectors of a specified maximum length.
{-# OPTIONS --without-K --safe #-}
module Data.BoundedVec where
open import Data.Nat
open import Data.List.Base as List using (List)
open import Data.Vec as Vec using (Vec)
import Data.BoundedVec.Inefficient as Ineff
open import Relation.Binary.PropositionalEquality
open import Data.Nat.Solver
open +-*-Solver
------------------------------------------------------------------------
-- The type
abstract
data BoundedVec {a} (A : Set a) : ℕ → Set a where
bVec : ∀ {m n} (xs : Vec A n) → BoundedVec A (n + m)
[] : ∀ {a n} {A : Set a} → BoundedVec A n
[] = bVec Vec.[]
infixr 5 _∷_
_∷_ : ∀ {a n} {A : Set a} →
A → BoundedVec A n → BoundedVec A (suc n)
x ∷ bVec xs = bVec (Vec._∷_ x xs)
------------------------------------------------------------------------
-- Pattern matching
infixr 5 _∷v_
data View {a} (A : Set a) : ℕ → Set a where
[]v : ∀ {n} → View A n
_∷v_ : ∀ {n} (x : A) (xs : BoundedVec A n) → View A (suc n)
abstract
view : ∀ {a n} {A : Set a} → BoundedVec A n → View A n
view (bVec Vec.[]) = []v
view (bVec (Vec._∷_ x xs)) = x ∷v bVec xs
------------------------------------------------------------------------
-- Increasing the bound
abstract
↑ : ∀ {a n} {A : Set a} → BoundedVec A n → BoundedVec A (suc n)
↑ {A = A} (bVec {m = m} {n = n} xs) =
subst (BoundedVec A) lemma
(bVec {m = suc m} xs)
where
lemma : n + (1 + m) ≡ 1 + (n + m)
lemma = solve 2 (λ m n → n :+ (con 1 :+ m) := con 1 :+ (n :+ m))
refl m n
------------------------------------------------------------------------
-- Conversions
module _ {a} {A : Set a} where
abstract
fromList : (xs : List A) → BoundedVec A (List.length xs)
fromList xs =
subst (BoundedVec A) lemma
(bVec {m = zero} (Vec.fromList xs))
where
lemma : List.length xs + 0 ≡ List.length xs
lemma = solve 1 (λ m → m :+ con 0 := m) refl _
toList : ∀ {n} → BoundedVec A n → List A
toList (bVec xs) = Vec.toList xs
toInefficient : ∀ {n} → BoundedVec A n → Ineff.BoundedVec A n
toInefficient xs with view xs
... | []v = Ineff.[]
... | y ∷v ys = y Ineff.∷ toInefficient ys
fromInefficient : ∀ {n} → Ineff.BoundedVec A n → BoundedVec A n
fromInefficient Ineff.[] = []
fromInefficient (x Ineff.∷ xs) = x ∷ fromInefficient xs
| 27.774194
| 72
| 0.473868
|
1a926f3d4dfe5857f1a8684fa23fc2303ffe5441
| 1,310
|
agda
|
Agda
|
src/Categories/Object/Zero.agda
|
FintanH/agda-categories
|
3ef03f73bce18f1efba2890df9ddf3d76ed2de32
|
[
"MIT"
] | null | null | null |
src/Categories/Object/Zero.agda
|
FintanH/agda-categories
|
3ef03f73bce18f1efba2890df9ddf3d76ed2de32
|
[
"MIT"
] | null | null | null |
src/Categories/Object/Zero.agda
|
FintanH/agda-categories
|
3ef03f73bce18f1efba2890df9ddf3d76ed2de32
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- a zero object is both terminal and initial.
module Categories.Object.Zero {o ℓ e} (C : Category o ℓ e) where
open import Level using (_⊔_)
open import Categories.Object.Terminal C
open import Categories.Object.Initial C
open import Categories.Morphism C
open Category C
open HomReasoning
record Zero : Set (o ⊔ ℓ ⊔ e) where
field
zero : Obj
! : ∀ {A} → zero ⇒ A
¡ : ∀ {A} → A ⇒ zero
zero⇒ : ∀ {A B : Obj} → A ⇒ B
zero⇒ {A} = ! ∘ ¡
field
!-unique : ∀ {A} (f : zero ⇒ A) → ! ≈ f
¡-unique : ∀ {A} (f : A ⇒ zero) → ¡ ≈ f
¡-unique₂ : ∀ {A} (f g : A ⇒ zero) → f ≈ g
¡-unique₂ f g = ⟺ (¡-unique f) ○ ¡-unique g
!-unique₂ : ∀ {A} (f g : zero ⇒ A) → f ≈ g
!-unique₂ f g = ⟺ (!-unique f) ○ !-unique g
initial : Initial
initial = record
{ ⊥ = zero
; ⊥-is-initial = record
{ ! = !
; !-unique = !-unique
}
}
terminal : Terminal
terminal = record
{ ⊤ = zero
; ⊤-is-terminal = record
{ ! = ¡
; !-unique = ¡-unique
}
}
module initial = Initial initial
module terminal = Terminal terminal
!-Mono : ∀ {A} → Mono (! {A})
!-Mono = from-⊤-is-Mono {t = terminal} !
¡-Epi : ∀ {A} → Epi (¡ {A})
¡-Epi = to-⊥-is-Epi {i = initial} ¡
| 20.46875
| 64
| 0.524427
|
4b46deeed527412324205b2ed3afc2a4d489b881
| 1,030
|
agda
|
Agda
|
out/STLC/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/STLC/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/STLC/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order equational theory was created from the following second-order syntax description:
syntax STLC | Λ
type
N : 0-ary
_↣_ : 2-ary | r30
term
app : α ↣ β α -> β | _$_ l20
lam : α.β -> α ↣ β | ƛ_ r10
theory
(ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]
(ƛη) f : α ↣ β |> lam (x. app(f, x)) = f
-}
module STLC.Equality where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Families.Build
open import SOAS.ContextMaps.Inductive
open import STLC.Signature
open import STLC.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution Λ:Syn
open import SOAS.Metatheory.SecondOrder.Equality Λ:Syn
private
variable
α β γ τ : ΛT
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ Λ) α Γ → (𝔐 ▷ Λ) α Γ → Set where
ƛβ : ⁅ α ⊩ β ⁆ ⁅ α ⁆̣ ▹ ∅ ⊢ (ƛ 𝔞⟨ x₀ ⟩) $ 𝔟 ≋ₐ 𝔞⟨ 𝔟 ⟩
ƛη : ⁅ α ↣ β ⁆̣ ▹ ∅ ⊢ ƛ (𝔞 $ x₀) ≋ₐ 𝔞
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
| 21.458333
| 99
| 0.615534
|
132c87b9e0a19e951487c657d4c0348f3b076d59
| 489
|
agda
|
Agda
|
List.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
List.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
List.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
open import Prelude
open import Nat
module List where
-- lets us omit a bunch of parens
infixr 99 _::_
infixr 9 _++_
-- standard definition of polymorphic lists
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
{-# BUILTIN LIST List #-}
-- shorthand notation for small lists
[_] : {A : Set} → A → List A
[ x ] = x :: []
-- list append
_++_ : {A : Set} → List A → List A → List A
[] ++ l2 = l2
x :: l1 ++ l2 = x :: (l1 ++ l2)
| 20.375
| 45
| 0.541922
|
9afb00d936d70c2231c411e20cf3dbe4da378f5a
| 3,490
|
agda
|
Agda
|
src/Categories/Category/Construction/Properties/CoKleisli.agda
|
tetrapharmakon/agda-categories
|
cfa6aefd3069d4db995191b458c886edcfba8294
|
[
"MIT"
] | 5
|
2019-05-21T17:07:19.000Z
|
2019-05-22T03:54:24.000Z
|
src/Categories/Category/Construction/Properties/CoKleisli.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Construction/Properties/CoKleisli.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
-- verbatim dual of Categories.Category.Construction.Properties.Kleisli
module Categories.Category.Construction.Properties.CoKleisli where
open import Level
import Relation.Binary.PropositionalEquality as ≡
open import Categories.Adjoint
open import Categories.Adjoint.Properties
open import Categories.Category
open import Categories.Functor using (Functor; _∘F_)
open import Categories.Functor.Equivalence
open import Categories.Comonad
import Categories.Morphism.Reasoning as MR
open import Categories.Adjoint.Construction.CoKleisli
open import Categories.Category.Construction.CoKleisli
private
variable
o ℓ e : Level
𝒞 𝒟 : Category o ℓ e
module _ {F : Functor 𝒞 𝒟} {G : Functor 𝒟 𝒞} (F⊣G : Adjoint F G) where
private
T : Comonad 𝒟
T = adjoint⇒comonad F⊣G
𝒟ₜ : Category _ _ _
𝒟ₜ = CoKleisli T
module 𝒞 = Category 𝒞
module 𝒟 = Category 𝒟
module 𝒟ₜ = Category 𝒟ₜ
module T = Comonad T
module F = Functor F
module G = Functor G
open Adjoint F⊣G
-- Maclane's Comparison Functor
ComparisonF : Functor 𝒟ₜ 𝒞
ComparisonF = record
{ F₀ = λ X → G.F₀ X
; F₁ = λ {A} {B} f → 𝒞 [ (G.F₁ f) ∘ unit.η (G.F₀ A) ]
; identity = λ {A} → zag
; homomorphism = λ {X} {Y} {Z} {f} {g} → begin
G.F₁ (g 𝒟.∘ F.F₁ (G.F₁ f) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ pushˡ G.homomorphism ⟩
G.F₁ g 𝒞.∘ G.F₁ ((F.F₁ (G.F₁ f)) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ (refl⟩∘⟨ pushˡ G.homomorphism) ⟩
G.F₁ g 𝒞.∘ G.F₁ (F.F₁ (G.F₁ f)) 𝒞.∘ G.F₁ (F.F₁ (unit.η (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ (refl⟩∘⟨ (refl⟩∘⟨ sym (unit.commute (unit.η (G.F₀ X))))) ⟩
G.F₁ g 𝒞.∘ G.F₁ (F.F₁ (G.F₁ f)) 𝒞.∘ unit.η (G.F₀ (F.F₀ (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ (refl⟩∘⟨ pullˡ (sym (unit.commute (G.F₁ f)))) ⟩
G.F₁ g 𝒞.∘ (unit.η (G.F₀ Y) 𝒞.∘ G.F₁ f) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ MR.assoc²'' 𝒞 ⟩
(G.F₁ g 𝒞.∘ unit.η (G.F₀ Y)) 𝒞.∘ G.F₁ f 𝒞.∘ unit.η (G.F₀ X) ∎
; F-resp-≈ = λ eq → 𝒞.∘-resp-≈ (G.F-resp-≈ eq) (Category.Equiv.refl 𝒞)
}
where
open 𝒞.HomReasoning
open 𝒞.Equiv
open MR 𝒞
private
L = ComparisonF
module L = Functor L
module Gₜ = Functor (Forgetful T)
module Fₜ = Functor (Cofree T)
F∘L≡Forgetful : (F ∘F L) ≡F Forgetful T
F∘L≡Forgetful = record
{ eq₀ = λ X → ≡.refl
; eq₁ = eq-1
}
where
open 𝒟.HomReasoning
open MR 𝒟
eq-1 : {X Y : 𝒟.Obj} (f : F.F₀ (G.F₀ X) 𝒟.⇒ Y) → 𝒟.id 𝒟.∘ F.F₁ (G.F₁ f 𝒞.∘ unit.η (G.F₀ X)) 𝒟.≈ (F.F₁ (G.F₁ f) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒟.∘ 𝒟.id
eq-1 {X} {Y} f = begin
𝒟.id 𝒟.∘ F.F₁ (G.F₁ f 𝒞.∘ unit.η (G.F₀ X)) ≈⟨ id-comm-sym ⟩
F.F₁ (G.F₁ f 𝒞.∘ unit.η (G.F₀ X)) 𝒟.∘ 𝒟.id ≈⟨ (F.homomorphism ⟩∘⟨refl) ⟩
(F.F₁ (G.F₁ f) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒟.∘ 𝒟.id ∎
L∘Cofree≡G : (L ∘F Cofree T) ≡F G
L∘Cofree≡G = record
{ eq₀ = λ X → ≡.refl
; eq₁ = eq-1
}
where
open 𝒞.HomReasoning
open MR 𝒞
eq-1 : {X Y : 𝒟.Obj} (f : X 𝒟.⇒ Y) → 𝒞.id 𝒞.∘ G.F₁ (f 𝒟.∘ counit.η X) 𝒞.∘ unit.η (G.F₀ X) 𝒞.≈ G.F₁ f 𝒞.∘ 𝒞.id
eq-1 {X} {Y} f = begin
𝒞.id 𝒞.∘ G.F₁ (f 𝒟.∘ counit.η X) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ id-comm-sym ⟩
(G.F₁ (f 𝒟.∘ counit.η X) 𝒞.∘ unit.η (G.F₀ X)) 𝒞.∘ 𝒞.id ≈⟨ (pushˡ G.homomorphism ⟩∘⟨refl) ⟩
(G.F₁ f 𝒞.∘ G.F₁ (counit.η X) 𝒞.∘ unit.η (G.F₀ X)) 𝒞.∘ 𝒞.id ≈⟨ (elimʳ zag ⟩∘⟨refl) ⟩
G.F₁ f 𝒞.∘ 𝒞.id ∎
| 36.354167
| 153
| 0.546705
|
570496de6e63c7f153e81120aff3ac18c0c22638
| 478
|
agda
|
Agda
|
agda-stdlib/src/Data/Vec/Any.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Vec/Any.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Vec/Any.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Vec.Relation.Unary.Any directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Any where
open import Data.Vec.Relation.Unary.Any public
{-# WARNING_ON_IMPORT
"Data.Vec.Any was deprecated in v1.0.
Use Data.Vec.Relation.Unary.Any instead."
#-}
| 26.555556
| 72
| 0.504184
|
13e50aa6a5762a288f8c86bcbe04a687b6ccd728
| 13,850
|
agda
|
Agda
|
Cubical/Algebra/CommRingSolver/Reflection.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/CommRingSolver/Reflection.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRingSolver/Reflection.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
{-
This is inspired by/copied from:
https://github.com/agda/agda-stdlib/blob/master/src/Tactic/MonoidSolver.agda
https://github.com/agda/agda-stdlib/blob/master/src/Tactic/RingSolver.agda
Boilerplate code for calling the ring solver is constructed automatically
with agda's reflection features.
-}
module Cubical.Algebra.CommRingSolver.Reflection where
open import Cubical.Foundations.Prelude hiding (Type)
open import Cubical.Functions.Logic
open import Agda.Builtin.Reflection hiding (Type)
open import Agda.Builtin.String
open import Cubical.Reflection.Base
open import Cubical.Data.Maybe
open import Cubical.Data.Sigma
open import Cubical.Data.List
open import Cubical.Data.Nat.Literals
open import Cubical.Data.Int.Base hiding (abs)
open import Cubical.Data.Int using (fromNegℤ; fromNatℤ)
open import Cubical.Data.Nat using (ℕ) renaming (_+_ to _+ℕ_)
open import Cubical.Data.FinData using () renaming (zero to fzero; suc to fsuc)
open import Cubical.Data.Bool
open import Cubical.Data.Bool.SwitchStatement
open import Cubical.Data.Vec using (Vec) renaming ([] to emptyVec; _∷_ to _∷vec_) public
open import Cubical.Algebra.CommRingSolver.AlgebraExpression
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRingSolver.RawAlgebra
open import Cubical.Algebra.CommRingSolver.IntAsRawRing
open import Cubical.Algebra.CommRingSolver.Solver renaming (solve to ringSolve)
private
variable
ℓ : Level
_==_ = primQNameEquality
{-# INLINE _==_ #-}
record RingNames : Type where
field
is0 : Name → Bool
is1 : Name → Bool
is· : Name → Bool
is+ : Name → Bool
is- : Name → Bool
getName : Term → Maybe Name
getName (con c args) = just c
getName (def f args) = just f
getName _ = nothing
buildMatcher : Name → Maybe Name → Name → Bool
buildMatcher n nothing x = n == x
buildMatcher n (just m) x = n == x or m == x
findRingNames : Term → TC RingNames
findRingNames cring =
let cringStr = varg (def (quote snd) (varg cring ∷ [])) ∷ []
in do
0altName ← normalise (def (quote CommRingStr.0r) cringStr)
1altName ← normalise (def (quote CommRingStr.1r) cringStr)
·altName ← normalise (def (quote CommRingStr._·_) cringStr)
+altName ← normalise (def (quote CommRingStr._+_) cringStr)
-altName ← normalise (def (quote (CommRingStr.-_)) cringStr)
returnTC record {
is0 = buildMatcher (quote CommRingStr.0r) (getName 0altName) ;
is1 = buildMatcher (quote CommRingStr.1r) (getName 1altName) ;
is· = buildMatcher (quote CommRingStr._·_) (getName ·altName) ;
is+ = buildMatcher (quote CommRingStr._+_) (getName +altName) ;
is- = buildMatcher (quote (CommRingStr.-_)) (getName -altName)
}
record VarInfo : Type ℓ-zero where
field
varName : String
varType : Arg Term
index : ℕ
{-
`getLastTwoArgsOf` maps a term 'def n (z₁ ∷ … ∷ zₙ ∷ x ∷ y ∷ [])' to the pair '(x,y)'
non-visible arguments are ignored.
-}
getLastTwoArgsOf : Name → Term → Maybe (Term × Term)
getLastTwoArgsOf n' (def n xs) =
if n == n'
then go xs
else nothing
where
go : List (Arg Term) → Maybe (Term × Term)
go (varg x ∷ varg y ∷ []) = just (x , y)
go (x ∷ xs) = go xs
go _ = nothing
getLastTwoArgsOf n' _ = nothing
{-
`getArgs` maps a term 'x ≡ y' to the pair '(x,y)'
-}
getArgs : Term → Maybe (Term × Term)
getArgs = getLastTwoArgsOf (quote PathP)
firstVisibleArg : List (Arg Term) → Maybe Term
firstVisibleArg [] = nothing
firstVisibleArg (varg x ∷ l) = just x
firstVisibleArg (x ∷ l) = firstVisibleArg l
{-
If the solver needs to be applied during equational reasoning,
the right hand side of the equation to solve cannot be given to
the solver directly. The folllowing function extracts this term y
from a more complex expression as in:
x ≡⟨ solve ... ⟩ (y ≡⟨ ... ⟩ z ∎)
-}
getRhs : Term → Maybe Term
getRhs (def n xs) =
if n == (quote _∎)
then firstVisibleArg xs
else (if n == (quote _≡⟨_⟩_)
then firstVisibleArg xs
else nothing)
getRhs _ = nothing
private
solverCallAsTerm : Term → Arg Term → Term → Term → Term
solverCallAsTerm R varList lhs rhs =
def
(quote ringSolve)
(varg R ∷ varg lhs ∷ varg rhs
∷ varList
∷ varg (def (quote refl) []) ∷ [])
solverCallWithLambdas : ℕ → List VarInfo → Term → Term → Term → Term
solverCallWithLambdas n varInfos R lhs rhs =
encloseWithIteratedLambda
(map VarInfo.varName varInfos)
(solverCallAsTerm R (variableList (rev varInfos)) lhs rhs)
where
encloseWithIteratedLambda : List String → Term → Term
encloseWithIteratedLambda (varName ∷ xs) t = lam visible (abs varName (encloseWithIteratedLambda xs t))
encloseWithIteratedLambda [] t = t
variableList : List VarInfo → Arg Term
variableList [] = varg (con (quote emptyVec) [])
variableList (varInfo ∷ varInfos)
= varg (con (quote _∷vec_) (varg (var (VarInfo.index varInfo) []) ∷ (variableList varInfos) ∷ []))
solverCallByVarIndices : ℕ → List ℕ → Term → Term → Term → Term
solverCallByVarIndices n varIndices R lhs rhs =
solverCallAsTerm R (variableList (rev varIndices)) lhs rhs
where
variableList : List ℕ → Arg Term
variableList [] = varg (con (quote emptyVec) [])
variableList (varIndex ∷ varIndices)
= varg (con (quote _∷vec_) (varg (var (varIndex) []) ∷ (variableList varIndices) ∷ []))
module pr (R : CommRing ℓ) {n : ℕ} where
open CommRingStr (snd R)
0' : Expr ℤAsRawRing (fst R) n
0' = K 0
1' : Expr ℤAsRawRing (fst R) n
1' = K 1
module _ (cring : Term) (names : RingNames) where
open pr
open RingNames names
`0` : List (Arg Term) → Term
`0` [] = def (quote 0') (varg cring ∷ [])
`0` (varg fstcring ∷ xs) = `0` xs
`0` (harg _ ∷ xs) = `0` xs
`0` _ = unknown
`1` : List (Arg Term) → Term
`1` [] = def (quote 1') (varg cring ∷ [])
`1` (varg fstcring ∷ xs) = `1` xs
`1` (harg _ ∷ xs) = `1` xs
`1` _ = unknown
mutual
private
op2 : Name → Term → Term → Term
op2 op x y = con op (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])
op1 : Name → Term → Term
op1 op x = con op (varg (buildExpression x) ∷ [])
`_·_` : List (Arg Term) → Term
`_·_` (harg _ ∷ xs) = `_·_` xs
`_·_` (varg x ∷ varg y ∷ []) = op2 (quote _·'_) x y
`_·_` (varg _ ∷ varg x ∷ varg y ∷ []) = op2 (quote _·'_) x y
`_·_` _ = unknown
`_+_` : List (Arg Term) → Term
`_+_` (harg _ ∷ xs) = `_+_` xs
`_+_` (varg x ∷ varg y ∷ []) = op2 (quote _+'_) x y
`_+_` (varg _ ∷ varg x ∷ varg y ∷ []) = op2 (quote _+'_) x y
`_+_` _ = unknown
`-_` : List (Arg Term) → Term
`-_` (harg _ ∷ xs) = `-_` xs
`-_` (varg x ∷ []) = op1 (quote -'_) x
`-_` (varg _ ∷ varg x ∷ []) = op1 (quote -'_) x
`-_` _ = unknown
K' : List (Arg Term) → Term
K' xs = con (quote K) xs
finiteNumberAsTerm : ℕ → Term
finiteNumberAsTerm ℕ.zero = con (quote fzero) []
finiteNumberAsTerm (ℕ.suc n) = con (quote fsuc) (varg (finiteNumberAsTerm n) ∷ [])
buildExpression : Term → Term
buildExpression (var index _) = con (quote ∣) (varg (finiteNumberAsTerm index) ∷ [])
buildExpression t@(def n xs) =
switch (λ f → f n) cases
case is0 ⇒ `0` xs break
case is1 ⇒ `1` xs break
case is· ⇒ `_·_` xs break
case is+ ⇒ `_+_` xs break
case is- ⇒ `-_` xs break
default⇒ (K' xs)
buildExpression t@(con n xs) =
switch (λ f → f n) cases
case is0 ⇒ `0` xs break
case is1 ⇒ `1` xs break
case is· ⇒ `_·_` xs break
case is+ ⇒ `_+_` xs break
case is- ⇒ `-_` xs break
default⇒ (K' xs)
buildExpression t = unknown
toAlgebraExpression : Maybe (Term × Term) → Maybe (Term × Term)
toAlgebraExpression nothing = nothing
toAlgebraExpression (just (lhs , rhs)) = just (buildExpression lhs , buildExpression rhs)
private
holeMalformedError : {A : Type ℓ} → Term → TC A
holeMalformedError hole′ = typeError
(strErr "Something went wrong when getting the variable names in "
∷ termErr hole′ ∷ [])
astExtractionError : {A : Type ℓ} → Term → TC A
astExtractionError equation = typeError
(strErr "Error while trying to build ASTs for the equation " ∷
termErr equation ∷ [])
variableExtractionError : {A : Type ℓ} → Term → TC A
variableExtractionError varsToSolve = typeError
(strErr "Error reading variables to solve " ∷
termErr varsToSolve ∷
[])
mutual
{- this covers just some common cases and should be refined -}
adjustDeBruijnIndex : (n : ℕ) → Term → Term
adjustDeBruijnIndex n (var k args) = var (k +ℕ n) args
adjustDeBruijnIndex n (def m l) = def m (map (adjustDeBruijnArg n) l)
adjustDeBruijnIndex n _ = unknown
adjustDeBruijnArg : (n : ℕ) → Arg Term → Arg Term
adjustDeBruijnArg n (arg i (var k args)) = arg i (var (k +ℕ n) args)
adjustDeBruijnArg n (arg i x) = arg i x
extractVarIndices : Maybe (List Term) → Maybe (List ℕ)
extractVarIndices (just ((var index _) ∷ l)) with extractVarIndices (just l)
... | just indices = just (index ∷ indices)
... | nothing = nothing
extractVarIndices (just []) = just []
extractVarIndices _ = nothing
listToVec : {A : Type ℓ} → (l : List A) → Vec A (length l)
listToVec [] = emptyVec
listToVec (x ∷ l) = x ∷vec listToVec l
getVarsAndEquation : Term → List VarInfo × Term
getVarsAndEquation t =
let (rawVars , equationTerm) = extractVars t
vars = addIndices (length rawVars) (listToVec rawVars)
in (vars , equationTerm)
where
extractVars : Term → List (String × Arg Term) × Term
extractVars (pi argType (abs varName t)) with extractVars t
... | xs , equation
= (varName , argType) ∷ xs , equation
extractVars equation = [] , equation
addIndices : (n : ℕ) → Vec (String × Arg Term) n → List VarInfo
addIndices ℕ.zero emptyVec = []
addIndices (ℕ.suc countVar) ((varName , argType) ∷vec list) =
record { varName = varName ; varType = argType ; index = countVar }
∷ (addIndices countVar list)
toListOfTerms : Term → Maybe (List Term)
toListOfTerms (con c []) = if (c == (quote [])) then just [] else nothing
toListOfTerms (con c (varg t ∷ varg s ∷ args)) with toListOfTerms s
... | just terms = if (c == (quote _∷_)) then just (t ∷ terms) else nothing
... | nothing = nothing
toListOfTerms (con c (harg t ∷ args)) = toListOfTerms (con c args)
toListOfTerms _ = nothing
checkIsRing : Term → TC Term
checkIsRing ring = checkType ring (def (quote CommRing) (varg unknown ∷ []))
solve-macro : Term → Term → TC Unit
solve-macro uncheckedCommRing hole =
do
commRing ← checkIsRing uncheckedCommRing
hole′ ← inferType hole >>= normalise
names ← findRingNames commRing
(varInfos , equation) ← returnTC (getVarsAndEquation hole′)
{-
The call to the ring solver will be inside a lamba-expression.
That means, that we have to adjust the deBruijn-indices of the variables in 'cring'
-}
adjustedCommRing ← returnTC (adjustDeBruijnIndex (length varInfos) commRing)
just (lhs , rhs) ← returnTC (toAlgebraExpression adjustedCommRing names (getArgs equation))
where nothing → astExtractionError equation
let solution = solverCallWithLambdas (length varInfos) varInfos adjustedCommRing lhs rhs
unify hole solution
solveInPlace-macro : Term → Term → Term → TC Unit
solveInPlace-macro cring varsToSolve hole =
do
equation ← inferType hole >>= normalise
names ← findRingNames cring
just varIndices ← returnTC (extractVarIndices (toListOfTerms varsToSolve))
where nothing → variableExtractionError varsToSolve
just (lhs , rhs) ← returnTC (toAlgebraExpression cring names (getArgs equation))
where nothing → astExtractionError equation
let solution = solverCallByVarIndices (length varIndices) varIndices cring lhs rhs
unify hole solution
solveEqReasoning-macro : Term → Term → Term → Term → Term → TC Unit
solveEqReasoning-macro lhs cring varsToSolve reasoningToTheRight hole =
do
names ← findRingNames cring
just varIndices ← returnTC (extractVarIndices (toListOfTerms varsToSolve))
where nothing → variableExtractionError varsToSolve
just rhs ← returnTC (getRhs reasoningToTheRight)
where
nothing
→ typeError(
strErr "Failed to extract right hand side of equation to solve from " ∷
termErr reasoningToTheRight ∷ [])
just (lhsAST , rhsAST) ← returnTC (toAlgebraExpression cring names (just (lhs , rhs)))
where
nothing
→ typeError(
strErr "Error while trying to build ASTs from " ∷
termErr lhs ∷ strErr " and " ∷ termErr rhs ∷ [])
let solverCall = solverCallByVarIndices (length varIndices) varIndices cring lhsAST rhsAST
unify hole (def (quote _≡⟨_⟩_) (varg lhs ∷ varg solverCall ∷ varg reasoningToTheRight ∷ []))
macro
solve : Term → Term → TC _
solve = solve-macro
solveInPlace : Term → Term → Term → TC _
solveInPlace = solveInPlace-macro
infixr 2 _≡⟨solveIn_withVars_⟩_
_≡⟨solveIn_withVars_⟩_ : Term → Term → Term → Term → Term → TC Unit
_≡⟨solveIn_withVars_⟩_ = solveEqReasoning-macro
fromℤ : (R : CommRing ℓ) → ℤ → fst R
fromℤ = scalar
| 35.788114
| 109
| 0.630542
|
4a45d662e1f3721fd7aa5eb3e553bee69f7084ea
| 416
|
agda
|
Agda
|
test/Fail/Issue2985-1.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2985-1.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2985-1.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --sized-types #-}
open import Agda.Builtin.Size
mutual
data Unit (i : Size) : Set where
c : Unit′ i → Unit i
record Unit′ (i : Size) : Set where
coinductive
field
force : {j : Size< i} → Unit j
open Unit′ public
tail : Unit ∞ → Unit ∞
tail (c x) = force x
u : (∀ {i} → Unit′ i → Unit i) →
∀ {i} → Unit i
u cons = tail (cons λ { .force → u cons })
bad : Unit ∞
bad = u c
| 16
| 42
| 0.545673
|
1df293a9034f351e3b1264e0b97cddd4f43f9820
| 2,877
|
agda
|
Agda
|
canonical-value-forms.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 16
|
2018-03-12T14:32:03.000Z
|
2021-12-19T02:50:23.000Z
|
canonical-value-forms.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 54
|
2017-06-29T20:53:34.000Z
|
2018-11-29T16:32:40.000Z
|
canonical-value-forms.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 1
|
2019-09-13T18:20:02.000Z
|
2019-09-13T18:20:02.000Z
|
open import Nat
open import Prelude
open import contexts
open import core
module canonical-value-forms where
canonical-value-forms-b : ∀{Δ d} →
Δ , ∅ ⊢ d :: b →
d val →
d == c
canonical-value-forms-b TAConst VConst = refl
canonical-value-forms-b (TAVar x₁) ()
canonical-value-forms-b (TAAp wt wt₁) ()
canonical-value-forms-b (TAEHole x x₁) ()
canonical-value-forms-b (TANEHole x wt x₁) ()
canonical-value-forms-b (TACast wt x) ()
canonical-value-forms-b (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-arr : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d val →
Σ[ x ∈ Nat ] Σ[ d' ∈ ihexp ]
((d == (·λ x [ τ1 ] d')) ×
(Δ , ■ (x , τ1) ⊢ d' :: τ2))
canonical-value-forms-arr (TAVar x₁) ()
canonical-value-forms-arr (TALam _ wt) VLam = _ , _ , refl , wt
canonical-value-forms-arr (TAAp wt wt₁) ()
canonical-value-forms-arr (TAEHole x x₁) ()
canonical-value-forms-arr (TANEHole x wt x₁) ()
canonical-value-forms-arr (TACast wt x) ()
canonical-value-forms-arr (TAFailedCast x x₁ x₂ x₃) ()
-- this argues (somewhat informally, because you still have to inspect
-- the types of the theorems above and manually verify this property)
-- that we didn't miss any cases above; this intentionally will make this
-- file fail to typecheck if we added more types, hopefully forcing us to
-- remember to add canonical forms lemmas as appropriate
canonical-value-forms-coverage1 : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d val →
τ ≠ b →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →
⊥
canonical-value-forms-coverage1 TAConst VConst = λ z _ → z refl
canonical-value-forms-coverage1 (TAVar x₁) ()
canonical-value-forms-coverage1 (TALam _ wt) VLam = λ _ z → z _ _ refl
canonical-value-forms-coverage1 (TAAp wt wt₁) ()
canonical-value-forms-coverage1 (TAEHole x x₁) ()
canonical-value-forms-coverage1 (TANEHole x wt x₁) ()
canonical-value-forms-coverage1 (TACast wt x) ()
canonical-value-forms-coverage1 (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-coverage2 : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇-⦈ →
d val →
⊥
canonical-value-forms-coverage2 (TAVar x₁) ()
canonical-value-forms-coverage2 (TAAp wt wt₁) ()
canonical-value-forms-coverage2 (TAEHole x x₁) ()
canonical-value-forms-coverage2 (TANEHole x wt x₁) ()
canonical-value-forms-coverage2 (TACast wt x) ()
canonical-value-forms-coverage2 (TAFailedCast wt x x₁ x₂) ()
| 45.666667
| 80
| 0.550574
|
41c5d63c53d74313252afac2bf7073ea0ddc89ee
| 2,441
|
agda
|
Agda
|
BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module BasicIPC.Metatheory.Hilbert-TarskiConcreteGluedImplicit where
open import BasicIPC.Syntax.Hilbert public
open import BasicIPC.Semantics.TarskiConcreteGluedImplicit public
open ImplicitSyntax (_⊢_) public
-- Completeness with respect to a particular model.
module _ {{_ : Model}} where
reify : ∀ {A w} → w ⊩ A → unwrap w ⊢ A
reify {α P} s = syn s
reify {A ▻ B} s = syn s
reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))
reify {⊤} s = unit
reify⋆ : ∀ {Ξ w} → w ⊩⋆ Ξ → unwrap w ⊢⋆ Ξ
reify⋆ {∅} ∙ = ∙
reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t
-- Additional useful equipment.
module _ {{_ : Model}} where
⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A
⟪K⟫ {A} a = app ck (reify a) ⅋ K a
⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ = app cs (syn s₁) ⅋ λ s₂ →
app (app cs (syn s₁)) (syn s₂) ⅋ ⟪S⟫ s₁ s₂
_⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} a = app cpair (reify a) ⅋ _,_ a
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (app t u) γ = eval t γ ⟪$⟫ eval u γ
eval ci γ = ci ⅋ I
eval ck γ = ck ⅋ ⟪K⟫
eval cs γ = cs ⅋ ⟪S⟫′
eval cpair γ = cpair ⅋ _⟪,⟫′_
eval cfst γ = cfst ⅋ π₁
eval csnd γ = csnd ⅋ π₂
eval unit γ = ∙
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ _⊩ᵅ_ = λ w P → unwrap w ⊢ α P
}
-- Soundness with respect to the canonical model.
reflectᶜ : ∀ {A w} → unwrap w ⊢ A → w ⊩ A
reflectᶜ {α P} t = t ⅋ t
reflectᶜ {A ▻ B} t = t ⅋ λ a → reflectᶜ (app t (reify a))
reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)
reflectᶜ {⊤} t = ∙
reflectᶜ⋆ : ∀ {Ξ w} → unwrap w ⊢⋆ Ξ → w ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {w} → w ⊩⋆ unwrap w
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆
trans⊩⋆ : ∀ {w w′ w″} → w ⊩⋆ unwrap w′ → w′ ⊩⋆ unwrap w″ → w ⊩⋆ unwrap w″
trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reify⋆ ts) (reify⋆ us))
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = reify (s refl⊩⋆)
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
| 24.656566
| 73
| 0.541581
|
20158d36df05ce3015237e0c6931bd5fd723f7f1
| 1,103
|
agda
|
Agda
|
tests/covered/Local.agda
|
andrejtokarcik/agda-semantics
|
dc333ed142584cf52cc885644eed34b356967d8b
|
[
"MIT"
] | 3
|
2015-08-10T15:33:56.000Z
|
2018-12-06T17:24:25.000Z
|
tests/covered/Local.agda
|
andrejtokarcik/agda-semantics
|
dc333ed142584cf52cc885644eed34b356967d8b
|
[
"MIT"
] | null | null | null |
tests/covered/Local.agda
|
andrejtokarcik/agda-semantics
|
dc333ed142584cf52cc885644eed34b356967d8b
|
[
"MIT"
] | null | null | null |
-- from http://wiki.portal.chalmers.se/agda/pmwiki.php?n=ReferenceManual.LocalDefinition
module Local where
data Nat : Set where
zero : Nat
succ : Nat -> Nat
infixl 5 _+_
_+_ : Nat -> Nat -> Nat
zero + n = n
(succ m) + n = succ (m + n)
infixl 6 _*_
_*_ : Nat -> Nat -> Nat
zero * _ = zero
(succ m) * n = n + m * n
f : Nat
f = let h : Nat -> Nat
h m = succ (succ m)
in h zero + h (succ zero)
t1 : Nat
t1 = f
h : Nat -> Nat
h n = let add2 : Nat
add2 = succ (succ n)
twice : Nat -> Nat
twice m = m * m
in twice add2
g : Nat -> Nat
g n = fib n + fact n
where fib : Nat -> Nat
fib zero = succ zero
fib (succ zero) = succ zero
fib (succ (succ n)) = fib (succ n) + fib n
fact : Nat -> Nat
fact zero = succ zero
fact (succ n) = succ n * fact n
k : Nat -> Nat
k n = let aux : Nat -> Nat
aux m = pred (g m) + h m
in aux (pred n)
where pred : Nat -> Nat
pred zero = zero
pred (succ m) = m
| 20.425926
| 88
| 0.474161
|
38f9d4f96f9dd63458ff7aece3278612724ada64
| 36
|
agda
|
Agda
|
test/interaction/Error-in-imported-module/M.agda
|
dagit/agda
|
4383a3d20328a6c43689161496cee8eb479aca08
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/interaction/Error-in-imported-module/M.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/interaction/Error-in-imported-module/M.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module M where
Foo : Set
Foo = Set
| 7.2
| 14
| 0.666667
|
2e8d4394528fe2f8b444bcada87190c56c2c8b16
| 184
|
agda
|
Agda
|
test/Succeed/RewriteAndUniversePolymorphism.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/RewriteAndUniversePolymorphism.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/RewriteAndUniversePolymorphism.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module RewriteAndUniversePolymorphism where
open import Common.Equality
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
test : (a b : ℕ) → a ≡ b → b ≡ a
test a b eq rewrite eq = refl
| 15.333333
| 43
| 0.652174
|
4bd077b8dca93aaa43909d00297fd1864852ca5e
| 14,259
|
agda
|
Agda
|
Cubical/ZCohomology/Groups/Torus.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/ZCohomology/Groups/Torus.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Groups/Torus.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Torus where
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Relation.Nullary
open import Cubical.Data.Unit
open import Cubical.Data.Nat
open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +Comm to +ℤ-comm ; +Assoc to +ℤ-assoc)
open import Cubical.Data.Sigma
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.DirProd
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Bool
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.HITs.SetTruncation as ST
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.HITs.Truncation as T
open import Cubical.HITs.Nullification
open import Cubical.HITs.Pushout
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Loopspace
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Connected
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.Groups.Prelims
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.Groups.WedgeOfSpheres
renaming (to₂ to to₂-∨ ; from₂ to from₂-∨ ; from₁ to from₁-∨ ; to₁ to to₁-∨) hiding (to₀ ; from₀)
open IsGroupHom
open Iso
-- The following section contains stengthened induction principles for cohomology groups of T². They are particularly useful for showing that
-- that some Isos are morphisms. They make things type-check faster, but should probably not be used for computations.
-- We first need some functions
elimFunT² : (n : ℕ) (p q : typ (Ω (coHomK-ptd (suc n))))
→ Square q q p p
→ S¹ × S¹ → coHomK (suc n)
elimFunT² n p q P (base , base) = ∣ ptSn (suc n) ∣
elimFunT² n p q P (base , loop i) = q i
elimFunT² n p q P (loop i , base) = p i
elimFunT² n p q P (loop i , loop j) = P i j
elimFunT²' : (n : ℕ) → Square (refl {ℓ-zero} {coHomK (suc n)} {∣ ptSn (suc n) ∣}) refl refl refl
→ S¹ × S¹ → coHomK (suc n)
elimFunT²' n P (x , base) = ∣ ptSn (suc n) ∣
elimFunT²' n P (base , loop j) = ∣ ptSn (suc n) ∣
elimFunT²' n P (loop i , loop j) = P i j
elimFunT²'≡elimFunT² : (n : ℕ) → (P : _) → elimFunT²' n P ≡ elimFunT² n refl refl P
elimFunT²'≡elimFunT² n P i (base , base) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (base , loop k) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (loop j , base) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (loop j , loop k) = P j k
{-
The first induction principle says that when proving a proposition for some x : Hⁿ(T²), n ≥ 1, it suffices to show that it holds for
(elimFunT² p q P) for any paths p q : ΩKₙ, and square P : Square q q p p. This is useful because elimFunT² p q P (base , base) recudes to 0
-}
coHomPointedElimT² : ∀ {ℓ} (n : ℕ) {B : coHom (suc n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (suc n) (S¹ × S¹)) → isProp (B x))
→ ((p q : _) (P : _) → B ∣ elimFunT² n p q P ∣₂)
→ (x : coHom (suc n) (S¹ × S¹)) → B x
coHomPointedElimT² n {B = B} isprop indp =
coHomPointedElim _ (base , base) isprop
λ f fId → subst B (cong ∣_∣₂ (funExt (λ { (base , base) → sym fId
; (base , loop i) j → helper f fId i1 i (~ j)
; (loop i , base) j → helper f fId i i1 (~ j)
; (loop i , loop j) k → helper f fId i j (~ k)})))
(indp (λ i → helper f fId i i1 i1)
(λ i → helper f fId i1 i i1)
λ i j → helper f fId i j i1)
where
helper : (f : S¹ × S¹ → coHomK (suc n)) → f (base , base) ≡ ∣ ptSn (suc n) ∣
→ I → I → I → coHomK (suc n)
helper f fId i j k =
hfill (λ k → λ {(i = i0) → doubleCompPath-filler (sym fId) (cong f (λ i → (base , loop i))) fId k j
; (i = i1) → doubleCompPath-filler (sym fId) (cong f (λ i → (base , loop i))) fId k j
; (j = i0) → doubleCompPath-filler (sym fId) (cong f (λ i → (loop i , base))) fId k i
; (j = i1) → doubleCompPath-filler (sym fId) (cong f (λ i → (loop i , base))) fId k i})
(inS (f ((loop i) , (loop j))))
k
private
lem : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((P : _) → B ∣ elimFunT² (suc n) refl refl P ∣₂)
→ (p : _) → (refl ≡ p)
→ (q : _) → (refl ≡ q)
→ (P : _)
→ B ∣ elimFunT² (suc n) p q P ∣₂
lem n {B = B} elimP p =
J (λ p _ → (q : _) → (refl ≡ q)
→ (P : _)
→ B ∣ elimFunT² (suc n) p q P ∣₂)
λ q →
J (λ q _ → (P : _) → B ∣ elimFunT² (suc n) refl q P ∣₂)
elimP
{- When working with Hⁿ(T²) , n ≥ 2, we are, in the case described above, allowed to assume that any f : Hⁿ(T²) is
elimFunT² n refl refl P -}
coHomPointedElimT²' : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (2 + n) (S¹ × S¹)) → isProp (B x))
→ ((P : _) → B ∣ elimFunT² (suc n) refl refl P ∣₂)
→ (x : coHom (2 + n) (S¹ × S¹)) → B x
coHomPointedElimT²' n {B = B} prop ind =
coHomPointedElimT² (suc n) prop
λ p q P → T.rec (isProp→isOfHLevelSuc n (prop _))
(λ p-refl → T.rec (isProp→isOfHLevelSuc n (prop _))
(λ q-refl → lem n {B = B} ind p (sym p-refl) q (sym q-refl) P)
(isConnectedPath _ (isConnectedPathKn (suc n) _ _) q refl .fst))
(isConnectedPath _ (isConnectedPathKn (suc n) _ _) p refl .fst)
{- A slight variation of the above which gives definitional equalities for all points (x , base) -}
private
coHomPointedElimT²'' : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (2 + n) (S¹ × S¹)) → isProp (B x))
→ ((P : _) → B ∣ elimFunT²' (suc n) P ∣₂)
→ (x : coHom (2 + n) (S¹ × S¹)) → B x
coHomPointedElimT²'' n {B = B} prop ind =
coHomPointedElimT²' n prop λ P → subst (λ x → B ∣ x ∣₂)
(elimFunT²'≡elimFunT² (suc n) P) (ind P)
--------- H⁰(T²) ------------
H⁰-T²≅ℤ : GroupIso (coHomGr 0 (S₊ 1 × S₊ 1)) ℤGroup
H⁰-T²≅ℤ =
H⁰-connected (base , base)
λ (a , b) → PT.rec isPropPropTrunc
(λ id1 → PT.rec isPropPropTrunc
(λ id2 → ∣ ΣPathP (id1 , id2) ∣₁)
(Sn-connected 0 b) )
(Sn-connected 0 a)
--------- H¹(T²) -------------------------------
H¹-T²≅ℤ×ℤ : GroupIso (coHomGr 1 ((S₊ 1) × (S₊ 1))) (DirProd ℤGroup ℤGroup)
H¹-T²≅ℤ×ℤ = theIso □ GroupIsoDirProd (Hⁿ-Sⁿ≅ℤ 0) (H⁰-Sⁿ≅ℤ 0)
where
typIso : Iso _ _
typIso = setTruncIso (curryIso ⋄ codomainIso S1→K₁≡S1×ℤ ⋄ toProdIso)
⋄ setTruncOfProdIso
theIso : GroupIso _ _
fst theIso = typIso
snd theIso =
makeIsGroupHom
(coHomPointedElimT² _ (λ _ → isPropΠ λ _ → isSet× isSetSetTrunc isSetSetTrunc _ _)
λ pf qf Pf →
coHomPointedElimT² _ (λ _ → isSet× isSetSetTrunc isSetSetTrunc _ _)
λ pg qg Pg i → ∣ funExt (helperFst pf qf pg qg Pg Pf) i ∣₂
, ∣ funExt (helperSnd pf qf pg qg Pg Pf) i ∣₂)
where
module _ (pf qf pg qg : 0ₖ 1 ≡ 0ₖ 1) (Pg : Square qg qg pg pg) (Pf : Square qf qf pf pf) where
helperFst : (x : S¹)
→ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .fst
≡ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y)) .fst
+ₖ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pg qg Pg (x , y)) .fst
helperFst base = refl
helperFst (loop i) j = loopLem j i
where
loopLem : cong (λ x → fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .fst) loop
≡ cong (λ x → fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y)) .fst
+ₖ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pg qg Pg (x , y)) .fst) loop
loopLem = (λ i j → S¹map-id (pf j +ₖ pg j) i)
∙ (λ i j → S¹map-id (pf j) (~ i) +ₖ S¹map-id (pg j) (~ i))
helperSnd : (x : S¹)
→ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .snd
≡ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y)) .snd +ℤ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pg qg Pg (x , y)) .snd
helperSnd =
toPropElim (λ _ → isSetℤ _ _)
((λ i → winding (basechange2⁻ base λ j → S¹map (∙≡+₁ qf qg (~ i) j)))
∙∙ cong (winding ∘ basechange2⁻ base) (congFunct S¹map qf qg)
∙∙ (cong winding (basechange2⁻-morph base (cong S¹map qf) (cong S¹map qg))
∙ winding-hom (basechange2⁻ base (cong S¹map qf)) (basechange2⁻ base (cong S¹map qg))))
----------------------- H²(T²) ------------------------------
H²-T²≅ℤ : GroupIso (coHomGr 2 (S₊ 1 × S₊ 1)) ℤGroup
H²-T²≅ℤ = compGroupIso helper2 (Hⁿ-Sⁿ≅ℤ 0)
where
helper : Iso (∥ ((a : S¹) → coHomK 2) ∥₂ × ∥ ((a : S¹) → coHomK 1) ∥₂) (coHom 1 S¹)
inv helper s = 0ₕ _ , s
fun helper = snd
leftInv helper _ =
ΣPathP (isOfHLevelSuc 0 (isOfHLevelRetractFromIso 0 (fst (Hⁿ-S¹≅0 0)) (isContrUnit)) _ _
, refl)
rightInv helper _ = refl
theIso : Iso (coHom 2 (S¹ × S¹)) (coHom 1 S¹)
theIso = setTruncIso (curryIso ⋄ codomainIso S1→K2≡K2×K1 ⋄ toProdIso)
⋄ setTruncOfProdIso
⋄ helper
helper2 : GroupIso (coHomGr 2 (S¹ × S¹)) (coHomGr 1 S¹)
helper2 .fst = theIso
helper2 .snd = makeIsGroupHom (
coHomPointedElimT²'' 0 (λ _ → isPropΠ λ _ → isSetSetTrunc _ _)
λ P → coHomPointedElimT²'' 0 (λ _ → isSetSetTrunc _ _)
λ Q → ((λ i → ∣ (λ a → ΩKn+1→Kn 1 (sym (rCancel≡refl 0 i)
∙∙ cong (λ x → (elimFunT²' 1 P (a , x) +ₖ elimFunT²' 1 Q (a , x)) -ₖ ∣ north ∣) loop
∙∙ rCancel≡refl 0 i)) ∣₂))
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 P (a , x) +ₖ elimFunT²' 1 Q (a , x)) i) loop) (~ i))) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn 1 (∙≡+₂ 0 (cong (λ x → elimFunT²' 1 P (a , x)) loop) (cong (λ x → elimFunT²' 1 Q (a , x)) loop) (~ i))) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn-hom 1 (cong (λ x → elimFunT²' 1 P (a , x)) loop) (cong (λ x → elimFunT²' 1 Q (a , x)) loop) i) ∣₂)
∙∙ (λ i → ∣ ((λ a → ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 P (a , x)) (~ i)) loop) i)
+ₖ ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 Q (a , x)) (~ i)) loop) i))) ∣₂)
∙ (λ i → ∣ ((λ a → ΩKn+1→Kn 1 (sym (rCancel≡refl 0 (~ i))
∙∙ cong (λ x → elimFunT²' 1 P (a , x) +ₖ ∣ north ∣) loop
∙∙ rCancel≡refl 0 (~ i))
+ₖ ΩKn+1→Kn 1 (sym (rCancel≡refl 0 (~ i))
∙∙ cong (λ x → elimFunT²' 1 Q (a , x) +ₖ ∣ north ∣) loop
∙∙ rCancel≡refl 0 (~ i)))) ∣₂))
private
to₂ : coHom 2 (S₊ 1 × S₊ 1) → ℤ
to₂ = fun (fst H²-T²≅ℤ)
from₂ : ℤ → coHom 2 (S₊ 1 × S₊ 1)
from₂ = inv (fst H²-T²≅ℤ)
to₁ : coHom 1 (S₊ 1 × S₊ 1) → ℤ × ℤ
to₁ = fun (fst H¹-T²≅ℤ×ℤ)
from₁ : ℤ × ℤ → coHom 1 (S₊ 1 × S₊ 1)
from₁ = inv (fst H¹-T²≅ℤ×ℤ)
to₀ : coHom 0 (S₊ 1 × S₊ 1) → ℤ
to₀ = fun (fst H⁰-T²≅ℤ)
from₀ : ℤ → coHom 0 (S₊ 1 × S₊ 1)
from₀ = inv (fst H⁰-T²≅ℤ)
{-
-- Compute fast:
test : to₁ (from₁ (0 , 1) +ₕ from₁ (1 , 0)) ≡ (1 , 1)
test = refl
test2 : to₁ (from₁ (5 , 1) +ₕ from₁ (-2 , 3)) ≡ (3 , 4)
test2 = refl
-- Compute pretty fast
test3 : to₂ (from₂ 1) ≡ 1
test3 = refl
test4 : to₂ (from₂ 2) ≡ 2
test4 = refl
test5 : to₂ (from₂ 3) ≡ 3
test5 = refl
-- Compute, but slower
test6 : to₂ (from₂ 0 +ₕ from₂ 0) ≡ 0
test6 = refl
test6 : to₂ (from₂ 0 +ₕ from₂ 1) ≡ 1
test6 = refl
-- Does not compute
test7 : to₂ (from₂ 1 +ₕ from₂ 0) ≡ 1
test7 = refl
-}
-- Proof (by computation) that T² ≠ S² ∨ S¹ ∨ S¹
private
hasTrivial⌣₁ : ∀ {ℓ} (A : Type ℓ) → Type ℓ
hasTrivial⌣₁ A = (x y : coHom 1 A) → x ⌣ y ≡ 0ₕ 2
hasTrivial⌣₁S²∨S¹∨S¹ : hasTrivial⌣₁ S²⋁S¹⋁S¹
hasTrivial⌣₁S²∨S¹∨S¹ x y =
x ⌣ y ≡⟨ cong₂ _⌣_ (sym (leftInv (fst (H¹-S²⋁S¹⋁S¹)) x)) (sym (leftInv (fst (H¹-S²⋁S¹⋁S¹)) y)) ⟩
from₁-∨ (to₁-∨ x) ⌣ from₁-∨ (to₁-∨ y) ≡⟨ sym (leftInv (fst (H²-S²⋁S¹⋁S¹)) (from₁-∨ (to₁-∨ x) ⌣ from₁-∨ (to₁-∨ y))) ⟩
from₂-∨ (to₂-∨ (from₁-∨ (to₁-∨ x) ⌣ from₁-∨ (to₁-∨ y))) ≡⟨ refl ⟩ -- holds by computation (even with open terms in the context)!
from₂-∨ 0 ≡⟨ hom1g (snd ℤGroup) from₂-∨ (snd (coHomGr 2 S²⋁S¹⋁S¹))
((invGroupEquiv (GroupIso→GroupEquiv H²-S²⋁S¹⋁S¹)) .snd .pres·) ⟩
0ₕ 2 ∎
1≠0 : ¬ (Path ℤ 1 0)
1≠0 p = posNotnegsuc _ _ (cong predℤ p)
¬hasTrivial⌣₁T² : ¬ (hasTrivial⌣₁ (S¹ × S¹))
¬hasTrivial⌣₁T² p = 1≠0 1=0
where
1=0 : pos 1 ≡ pos 0
1=0 =
1 ≡⟨ refl ⟩ -- holds by computation!
to₂ (from₁ (0 , 1) ⌣ from₁ (1 , 0)) ≡⟨ cong to₂ (p (from₁ (0 , 1)) (from₁ (1 , 0))) ⟩
0 ∎
T²≠S²⋁S¹⋁S¹ : ¬ S¹ × S¹ ≡ S²⋁S¹⋁S¹
T²≠S²⋁S¹⋁S¹ p = ¬hasTrivial⌣₁T² (subst hasTrivial⌣₁ (sym p) hasTrivial⌣₁S²∨S¹∨S¹)
| 44.981073
| 151
| 0.52949
|
38bb9631bebae8118bc06b55eb24854453dea8b4
| 231
|
agda
|
Agda
|
test/fail/ATPBadLocalHint1.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
test/fail/ATPBadLocalHint1.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | null | null | null |
test/fail/ATPBadLocalHint1.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- An ATP local hint cannot be equal to the conjecture in which it is
-- used.
-- This error is detected by Syntax.Translation.ConcreteToAbstract.
module ATPBadLocalHint1 where
postulate
D : Set
p : D
{-# ATP prove p p #-}
| 17.769231
| 69
| 0.714286
|
13eb113a07bff8e1dc765a22c90db749c543f640
| 980
|
agda
|
Agda
|
UniDB/Subst/Sum.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Subst/Sum.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Subst/Sum.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
module UniDB.Subst.Sum where
open import UniDB.Subst.Core
open import UniDB.Morph.Sum
--------------------------------------------------------------------------------
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}} {{apRelTX : ApRel T X}}
(Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
(Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}}
where
ap-inl : {γ₁ γ₂ : Dom} (ξ : Ξ γ₁ γ₂) (x : X γ₁) →
ap {T} {X} {Sum Ξ Ζ} (inl ξ) x ≡ ap {T} ξ x
ap-inl ξ = ap-rel≅ {T} (≃-to-≅` lem)
where
lem : (δ : Dom) → [ T ] inl {Ξ} {Ζ} ξ ↑ δ ≃ ξ ↑ δ
lk≃ (lem δ) i rewrite inl-↑ Ξ Ζ ξ δ = refl
ap-inr : {γ₁ γ₂ : Dom} (ζ : Ζ γ₁ γ₂) (x : X γ₁) →
ap {T} {X} {Sum Ξ Ζ} (inr ζ) x ≡ ap {T} ζ x
ap-inr ζ = ap-rel≅ {T} (≃-to-≅` lem)
where
lem : (δ : Dom) → [ T ] inr {Ξ} {Ζ} ζ ↑ δ ≃ ζ ↑ δ
lk≃ (lem δ) i rewrite inr-↑ Ξ Ζ ζ δ = refl
--------------------------------------------------------------------------------
| 32.666667
| 80
| 0.384694
|
067630df9447bfd41a9358cb807979fd2c942d68
| 2,991
|
agda
|
Agda
|
src/Algebra/Linear/Morphism/Bundles.agda
|
felko/linear-algebra
|
d87c5a1eb5dd0569238272e67bce1899616b789a
|
[
"MIT"
] | 15
|
2019-11-02T14:11:00.000Z
|
2020-12-30T06:18:08.000Z
|
src/Algebra/Linear/Morphism/Bundles.agda
|
felko/linear-algebra
|
d87c5a1eb5dd0569238272e67bce1899616b789a
|
[
"MIT"
] | null | null | null |
src/Algebra/Linear/Morphism/Bundles.agda
|
felko/linear-algebra
|
d87c5a1eb5dd0569238272e67bce1899616b789a
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Structures.Bundles.Field
module Algebra.Linear.Morphism.Bundles
{k ℓᵏ} (K : Field k ℓᵏ)
where
open import Algebra.FunctionProperties as FP
open import Relation.Binary using (Rel; Setoid)
open import Level
import Algebra.Linear.Structures.Bundles as VS
open import Algebra.Linear.Morphism.VectorSpace K
open import Function.Equality as FunEq using (_⟶_; _⟨$⟩_; setoid)
module _
{a₁ ℓ₁} (From : VS.VectorSpace K a₁ ℓ₁)
{a₂ ℓ₂} (To : VS.VectorSpace K a₂ ℓ₂)
where
private
module F = VS.VectorSpace From
module T = VS.VectorSpace To
K' : Set k
K' = Field.Carrier K
open F using ()
renaming
( Carrier to A
; _≈_ to _≈₁_
; refl to ≈₁-refl
; sym to ≈₁-sym
; setoid to A-setoid
; _+_ to +₁
; _∙_ to ∙₁
)
open T using ()
renaming
( Carrier to B
; _≈_ to _≈₂_
; refl to ≈₂-refl
; sym to ≈₂-sym
; trans to ≈₂-trans
; setoid to B-setoid
; _+_ to +₂
; _∙_ to ∙₂
)
hom-setoid : ∀ {Carrier} -> (Carrier -> (A-setoid ⟶ B-setoid))
-> Setoid (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) (a₁ ⊔ ℓ₁ ⊔ ℓ₂)
hom-setoid {Carrier} app = record
{ Carrier = Carrier
; _≈_ = λ f g → ∀ {x y} (r : x ≈₁ y) -> (app f ⟨$⟩ x) ≈₂ (app g ⟨$⟩ y)
; isEquivalence = record
{ refl = λ {f} -> FunEq.cong (app f)
; sym = λ r rₓ → ≈₂-sym (r (≈₁-sym rₓ))
; trans = λ r₁ r₂ rₓ → ≈₂-trans (r₁ ≈₁-refl) (r₂ rₓ)
}
}
open LinearDefinitions A B _≈₂_
record LinearMap : Set (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) where
field
⟦_⟧ : Morphism
isLinearMap : IsLinearMap From To ⟦_⟧
infixr 25 _⟪$⟫_
_⟪$⟫_ : A -> B
_⟪$⟫_ = ⟦_⟧
open IsLinearMap isLinearMap public
linearMap-setoid : Setoid (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) (a₁ ⊔ ℓ₁ ⊔ ℓ₂)
linearMap-setoid = hom-setoid {LinearMap} λ f → record
{ _⟨$⟩_ = λ x → f LinearMap.⟪$⟫ x
; cong = LinearMap.⟦⟧-cong f
}
record LinearIsomorphism : Set (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) where
field
⟦_⟧ : Morphism
isLinearIsomorphism : IsLinearIsomorphism From To ⟦_⟧
open IsLinearIsomorphism isLinearIsomorphism public
linearMap : LinearMap
linearMap = record { ⟦_⟧ = ⟦_⟧ ; isLinearMap = isLinearMap }
open LinearMap linearMap public
using (_⟪$⟫_)
linearIsomorphism-setoid : Setoid (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) (a₁ ⊔ ℓ₁ ⊔ ℓ₂)
linearIsomorphism-setoid = hom-setoid {LinearIsomorphism} λ f → record
{ _⟨$⟩_ = λ x -> f LinearIsomorphism.⟪$⟫ x
; cong = LinearIsomorphism.⟦⟧-cong f
}
module _ {a ℓ} (V : VS.VectorSpace K a ℓ) where
LinearEndomorphism : Set (suc (k ⊔ a ⊔ ℓ))
LinearEndomorphism = LinearMap V V
LinearAutomorphism : Set (suc (k ⊔ a ⊔ ℓ))
LinearAutomorphism = LinearIsomorphism V V
| 27.190909
| 86
| 0.55433
|
4b16dab43afbf84cb0dc5426479fd316e2444618
| 10,028
|
agda
|
Agda
|
Cubical/Foundations/Id.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Id.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Id.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Id, refl and J (with definitional computation rule)
- Basic theory about Id, proved using J
- Lemmas for going back and forth between Path and Id
- Function extensionality for Id
- fiber, isContr, equiv all defined using Id
- The univalence axiom expressed using only Id ([EquivContr])
- Propositional truncation and its elimination principle
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Id where
open import Cubical.Foundations.Prelude public
hiding ( _≡_ ; _≡⟨_⟩_ ; _∎ ; isPropIsContr)
renaming ( refl to reflPath
; transport to transportPath
; J to JPath
; JRefl to JPathRefl
; sym to symPath
; _∙_ to compPath
; cong to congPath
; funExt to funExtPath
; isContr to isContrPath
; isProp to isPropPath
; isSet to isSetPath
; fst to pr₁ -- as in the HoTT book
; snd to pr₂ )
open import Cubical.Foundations.Equiv
renaming ( fiber to fiberPath
; isEquiv to isEquivPath
; _≃_ to EquivPath
; equivFun to equivFunPath )
hiding ( isPropIsEquiv
; equivCtr
; equivIsEquiv )
open import Cubical.Foundations.Univalence
renaming ( EquivContr to EquivContrPath )
open import Cubical.HITs.PropositionalTruncation public
renaming ( squash to squashPath
; rec to recPropTruncPath
; elim to elimPropTruncPath )
open import Cubical.Core.Id public
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- Version of the constructor for Id where the y is also
-- explicit. This is sometimes useful when it is needed for
-- typechecking (see JId below).
conId : ∀ {x : A} φ (y : A [ φ ↦ (λ _ → x) ])
(w : (Path _ x (outS y)) [ φ ↦ (λ { (φ = i1) → λ _ → x}) ]) →
x ≡ outS y
conId φ _ w = ⟨ φ , outS w ⟩
-- Reflexivity
refl : ∀ {x : A} → x ≡ x
refl {x = x} = ⟨ i1 , (λ _ → x) ⟩
-- Definition of J for Id
module _ {x : A} (P : ∀ (y : A) → Id x y → Type ℓ') (d : P x refl) where
J : ∀ {y : A} (w : x ≡ y) → P y w
J {y = y} = elimId P (λ φ y w → comp (λ i → P _ (conId (φ ∨ ~ i) (inS (outS w i))
(inS (λ j → outS w (i ∧ j)))))
(λ i → λ { (φ = i1) → d}) d) {y = y}
-- Check that J of refl is the identity function
Jdefeq : Path _ (J refl) d
Jdefeq _ = d
-- Basic theory about Id, proved using J
transport : ∀ (B : A → Type ℓ') {x y : A}
→ x ≡ y → B x → B y
transport B {x} p b = J (λ y p → B y) b p
_⁻¹ : {x y : A} → x ≡ y → y ≡ x
_⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p
ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y
ap f {x} = J (λ z _ → f x ≡ f z) refl
_∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z
_∙_ {x = x} p = J (λ y _ → x ≡ y) p
infix 4 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ p ⟩ q = p ∙ q
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- Convert between Path and Id
pathToId : ∀ {x y : A} → Path _ x y → Id x y
pathToId {x = x} = JPath (λ y _ → Id x y) refl
pathToIdRefl : ∀ {x : A} → Path _ (pathToId (λ _ → x)) refl
pathToIdRefl {x = x} = JPathRefl (λ y _ → Id x y) refl
idToPath : ∀ {x y : A} → Id x y → Path _ x y
idToPath {x = x} = J (λ y _ → Path _ x y) (λ _ → x)
idToPathRefl : ∀ {x : A} → Path _ (idToPath {x = x} refl) reflPath
idToPathRefl {x = x} _ _ = x
pathToIdToPath : ∀ {x y : A} → (p : Path _ x y) → Path _ (idToPath (pathToId p)) p
pathToIdToPath {x = x} = JPath (λ y p → Path _ (idToPath (pathToId p)) p)
(λ i → idToPath (pathToIdRefl i))
idToPathToId : ∀ {x y : A} → (p : Id x y) → Path _ (pathToId (idToPath p)) p
idToPathToId {x = x} = J (λ b p → Path _ (pathToId (idToPath p)) p) pathToIdRefl
-- We get function extensionality by going back and forth between Path and Id
funExt : ∀ {B : A → Type ℓ'} {f g : (x : A) → B x} →
((x : A) → f x ≡ g x) → f ≡ g
funExt p = pathToId (λ i x → idToPath (p x) i)
-- Equivalences expressed using Id
fiber : ∀ {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ')
fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
record isEquiv {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where
field
equiv-proof : (y : B) → isContr (fiber f y)
open isEquiv public
infix 4 _≃_
_≃_ : ∀ (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ')
A ≃ B = Σ[ f ∈ (A → B) ] (isEquiv f)
equivFun : ∀ {B : Type ℓ'} → A ≃ B → A → B
equivFun e = pr₁ e
equivIsEquiv : ∀ {B : Type ℓ'} (e : A ≃ B) → isEquiv (equivFun e)
equivIsEquiv e = pr₂ e
equivCtr : ∀ {B : Type ℓ'} (e : A ≃ B) (y : B) → fiber (equivFun e) y
equivCtr e y = e .pr₂ .equiv-proof y .pr₁
-- Functions for going between the various definitions. This could
-- also be achieved by making lines in the universe and transporting
-- back and forth along them.
fiberPathToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B} →
fiberPath f y → fiber f y
fiberPathToFiber (x , p) = (x , pathToId p)
fiberToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} →
fiber f y → fiberPath f y
fiberToFiberPath (x , p) = (x , idToPath p)
fiberToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B}
(p : fiber f y) → Path _ (fiberPathToFiber (fiberToFiberPath p)) p
fiberToFiber (x , p) = λ i → x , idToPathToId p i
fiberPathToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B}
(p : fiberPath f y) → Path _ (fiberToFiberPath (fiberPathToFiber p)) p
fiberPathToFiberPath (x , p) = λ i → x , pathToIdToPath p i
isContrPathToIsContr : isContrPath A → isContr A
isContrPathToIsContr (ctr , p) = (ctr , λ y → pathToId (p y))
isContrToIsContrPath : isContr A → isContrPath A
isContrToIsContrPath (ctr , p) = (ctr , λ y → idToPath (p y))
isPropPathToIsProp : isPropPath A → isProp A
isPropPathToIsProp H x y = pathToId (H x y)
isPropToIsPropPath : isProp A → isPropPath A
isPropToIsPropPath H x y i = idToPath (H x y) i
-- Specialized helper lemmas for going back and forth between
-- isContrPath and isContr:
helper1 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A)
(h : ∀ y → Path _ (f (g y)) y) → isContrPath A → isContr B
helper1 f g h (x , p) =
(f x , λ y → pathToId (λ i → hcomp (λ j → λ { (i = i0) → f x
; (i = i1) → h y j })
(f (p (g y) i))))
helper2 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A)
(h : ∀ y → Path _ (g (f y)) y) → isContr B → isContrPath A
helper2 {A = A} f g h (x , p) = (g x , λ y → idToPath (rem y))
where
rem : ∀ (y : A) → g x ≡ y
rem y =
g x ≡⟨ ap g (p (f y)) ⟩
g (f y) ≡⟨ pathToId (h y) ⟩
y ∎
-- This proof is essentially the one for proving that isContr with
-- Path is a proposition, but as we are working with Id we have to
-- insert a lof of conversion functions. It is still nice that is
-- works like this though.
isPropIsContr : ∀ (p1 p2 : isContr A) → Path (isContr A) p1 p2
isPropIsContr (a0 , p0) (a1 , p1) j =
( idToPath (p0 a1) j ,
hcomp (λ i → λ { (j = i0) → λ x → idToPathToId (p0 x) i
; (j = i1) → λ x → idToPathToId (p1 x) i })
(λ x → pathToId (λ i → hcomp (λ k → λ { (i = i0) → idToPath (p0 a1) j
; (i = i1) → idToPath (p0 x) (j ∨ k)
; (j = i0) → idToPath (p0 x) (i ∧ k)
; (j = i1) → idToPath (p1 x) i })
(idToPath (p0 (idToPath (p1 x) i)) j))))
-- We now prove that isEquiv is a proposition
isPropIsEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → {f : A → B} → (h1 h2 : isEquiv f) → Path _ h1 h2
equiv-proof (isPropIsEquiv {f = f} h1 h2 i) y =
isPropIsContr {A = fiber f y} (h1 .equiv-proof y) (h2 .equiv-proof y) i
-- Go from a Path equivalence to an Id equivalence
equivPathToEquiv : ∀ {A : Type ℓ} {B : Type ℓ'} → EquivPath A B → A ≃ B
equivPathToEquiv (f , p) =
(f , λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (p .equiv-proof y) })
-- Go from an Id equivalence to a Path equivalence
equivToEquivPath : ∀ {A : Type ℓ} {B : Type ℓ'} → A ≃ B → EquivPath A B
equivToEquivPath (f , p) =
(f , λ { .equiv-proof y → helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y) })
equivToEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → (p : A ≃ B) → Path _ (equivPathToEquiv (equivToEquivPath p)) p
equivToEquiv (f , p) i =
(f , isPropIsEquiv (λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber
(helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y)) }) p i)
-- We can finally prove univalence with Id everywhere from the one for Path
EquivContr : ∀ (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] (T ≃ A))
EquivContr A = helper1 f1 f2 f12 (EquivContrPath A)
where
f1 : ∀ {ℓ} {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (EquivPath T A) → Σ[ T ∈ Type ℓ ] (T ≃ A)
f1 (x , p) = x , equivPathToEquiv p
f2 : ∀ {ℓ} {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (T ≃ A) → Σ[ T ∈ Type ℓ ] (EquivPath T A)
f2 (x , p) = x , equivToEquivPath p
f12 : ∀ {ℓ} {A : Type ℓ} → (y : Σ[ T ∈ Type ℓ ] (T ≃ A)) → Path _ (f1 (f2 y)) y
f12 (x , p) = λ i → x , equivToEquiv p i
-- Propositional truncation
∥∥-isProp : ∀ (x y : ∥ A ∥) → x ≡ y
∥∥-isProp x y = pathToId (squashPath x y)
∥∥-recursion : ∀ {A : Type ℓ} {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P
∥∥-recursion Pprop f x = recPropTruncPath (isPropToIsPropPath Pprop) f x
∥∥-induction : ∀ {A : Type ℓ} {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) →
((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
∥∥-induction Pprop f x = elimPropTruncPath (λ a → isPropToIsPropPath (Pprop a)) f x
| 35.185965
| 136
| 0.541484
|
9a0dada27ea5640c36db780e162ec00318e84adc
| 944
|
agda
|
Agda
|
src/Categories/Functor/Cocontinuous.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Cocontinuous.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Cocontinuous.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Cocontinuous where
open import Level
open import Data.Product using (Σ)
open import Categories.Category
open import Categories.Functor
import Categories.Category.Construction.Cocones as Coc
import Categories.Diagram.Colimit as Col
import Categories.Morphism as Mor
private
variable
o ℓ e : Level
C D E J : Category o ℓ e
-- G preserves the colimit of F.
ColimitPreserving : (G : Functor C D) {F : Functor J C} (L : Col.Colimit F) → Set _
ColimitPreserving {C = C} {D = D} G {F} L = Σ (Col.Colimit (G ∘F F)) λ L′ → G.F₀ (Col.Colimit.coapex L) ≅ Col.Colimit.coapex L′
where module F = Functor F
module G = Functor G
open Mor D
-- cocontinuous functors preserves all colimits.
Cocontinuous : ∀ (o ℓ e : Level) (G : Functor C D) → Set _
Cocontinuous {C = C} o ℓ e G = ∀ {J : Category o ℓ e} {F : Functor J C} (L : Col.Colimit F) → ColimitPreserving G L
| 32.551724
| 127
| 0.685381
|
04df4be4123e9c59cba694108c3632fae1325abf
| 581
|
agda
|
Agda
|
TypeTheory/HoTT/Base.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | 3
|
2020-04-07T17:49:42.000Z
|
2020-04-21T00:03:43.000Z
|
TypeTheory/HoTT/Base.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
TypeTheory/HoTT/Base.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
-- Homotopy type theory
-- https://github.com/agda/cubical
{-# OPTIONS --without-K --safe #-}
module TypeTheory.HoTT.Base where
-- agda-stdlib
open import Level renaming (zero to lzero; suc to lsuc)
open import Data.Product
open import Relation.Binary.PropositionalEquality
private
variable
a b : Level
fiber : {A : Set a} {B : Set b} (f : A → B) (y : B) → Set (a ⊔ b)
fiber f y = ∃ λ x → f x ≡ y
isContr : Set a → Set a
isContr A = Σ A λ x → ∀ y → x ≡ y
isProp : Set a → Set a
isProp A = (x y : A) → x ≡ y
isSet : Set a → Set a
isSet A = (x y : A) → isProp (x ≡ y)
| 20.034483
| 65
| 0.611015
|
adf52c2e2aaacb9da67c6689b3fd0c3185bceaaf
| 11,994
|
agda
|
Agda
|
Categories/Power.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Power.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Power.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
open import Level hiding (suc; zero)
open import Categories.Category
module Categories.Power {o ℓ e : Level} (C : Category o ℓ e) where
open import Function using () renaming (id to idf)
open import Data.Nat using (ℕ; _+_; zero; suc; _≤?_)
open import Data.Product using (_,_)
open import Data.Fin using (Fin; inject+; raise; zero; suc; #_)
open import Data.Sum using (_⊎_; inj₁; inj₂; map) renaming ([_,_] to ⟦_,_⟧; [_,_]′ to ⟦_,_⟧′)
open import Function using (flip) renaming (_∘_ to _∙_)
open import Relation.Nullary.Decidable using (True)
open import Data.Vec.N-ary using (N-ary)
open import Categories.Bifunctor using (Bifunctor)
open import Categories.Functor using (Functor; module Functor)
module C = Category C
Exp : (I : Set) → Category o ℓ e
Exp I = record
{ Obj = I → C.Obj
; _⇒_ = λ x y → (i : I) → C [ x i , y i ]
; _≡_ = λ f g → (i : I) → C [ f i ≡ g i ]
; _∘_ = λ f g i → C [ f i ∘ g i ]
; id = λ {x} i → C.id
; assoc = λ {A} {B} {C'} {D} {f} {g} {h} i → C.assoc
; identityˡ = λ {A} {B} {f} i → C.identityˡ
; identityʳ = λ {A} {B} {f} i → C.identityʳ
; equiv = record
{ refl = λ {x} i → C.Equiv.refl
; sym = λ f i → C.Equiv.sym (f i)
; trans = λ f g i → C.Equiv.trans (f i) (g i)
}
; ∘-resp-≡ = λ f≡g h≡i x → C.∘-resp-≡ (f≡g x) (h≡i x)
}
Power : (n : ℕ) → Category o ℓ e
Power n = Exp (Fin n)
Powerfunctor′ : (D : Category o ℓ e) (I : Set) → Set (e ⊔ ℓ ⊔ o)
Powerfunctor′ D I = Functor (Exp I) D
Powerfunctor : (D : Category o ℓ e) (n : ℕ) → Set (e ⊔ ℓ ⊔ o)
Powerfunctor D n = Powerfunctor′ D (Fin n)
Powerendo′ : (I : Set) → Set (e ⊔ ℓ ⊔ o)
Powerendo′ I = Powerfunctor′ C I
Powerendo : (n : ℕ) → Set (e ⊔ ℓ ⊔ o)
Powerendo n = Powerfunctor C n
Hyperendo : (n m : ℕ) → Set (e ⊔ ℓ ⊔ o)
Hyperendo n m = Functor (Power n) (Power m)
Hyperendo′ : (I J : Set) → Set (e ⊔ ℓ ⊔ o)
Hyperendo′ I J = Functor (Exp I) (Exp J)
_par_ : ∀ {I I′ J J′} (F : Hyperendo′ I I′) (G : Hyperendo′ J J′) → Hyperendo′ (I ⊎ J) (I′ ⊎ J′)
F par G = record
{ F₀ = λ xs → ⟦ F.F₀ (xs ∙ inj₁) , G.F₀ (xs ∙ inj₂) ⟧′
; F₁ = λ {A B} fs → ⟦ F.F₁ (fs ∙ inj₁) , G.F₁ (fs ∙ inj₂) ⟧
; identity = λ {A} → ⟦ F.identity , G.identity ⟧
; homomorphism = λ {A B C fs gs} → ⟦ F.homomorphism , G.homomorphism ⟧
; F-resp-≡ = λ {A B fs gs} fs≡gs → ⟦ F.F-resp-≡ (fs≡gs ∙ inj₁) , G.F-resp-≡ (fs≡gs ∙ inj₂) ⟧
}
where
private module F = Functor F
private module G = Functor G
flattenP : ∀ {D : Category o ℓ e} {n m} (F : Powerfunctor′ D (Fin n ⊎ Fin m)) → Powerfunctor′ D (Fin (n + m))
flattenP {n = n} {m = m} F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ {As Bs} fs → F.F₁ (fs ∙ pack)
; identity = λ {As} → F.identity
; homomorphism = λ {As Bs Cs fs gs} → F.homomorphism
; F-resp-≡ = λ {As Bs fs gs} fs≡gs → F.F-resp-≡ (fs≡gs ∙ pack)
}
where
private module F = Functor F
pack = ⟦ inject+ m , raise n ⟧′
flattenHʳ : ∀ {I} {n m} (F : Hyperendo′ I (Fin n ⊎ Fin m)) → Hyperendo′ I (Fin (n + m))
flattenHʳ {n = n} {m} F = record
{ F₀ = λ As → F.F₀ As ∙ chops n
; F₁ = λ {As Bs} fs → F.F₁ fs ∙ chops n
; identity = F.identity ∙ chops n
; homomorphism = F.homomorphism ∙ chops n
; F-resp-≡ = λ fs≡gs → F.F-resp-≡ fs≡gs ∙ chops n
}
where
private module F = Functor F
chops : (n : ℕ) → ∀ {m} (k : Fin (n + m)) → Fin n ⊎ Fin m
chops 0 k = inj₂ k
chops (suc n) zero = inj₁ zero
chops (suc n) (suc k) = map suc idf (chops n k)
flattenH : ∀ {n m n′ m′} (F : Hyperendo′ (Fin n ⊎ Fin m) (Fin n′ ⊎ Fin m′)) → Hyperendo (n + m) (n′ + m′)
flattenH = flattenHʳ ∙ flattenP
_∥_ : ∀ {n n′ m m′} (F : Hyperendo n n′) (G : Hyperendo m m′) → Hyperendo (n + m) (n′ + m′)
F ∥ G = flattenH (F par G)
reduce′ : ∀ (H : Bifunctor C C C) {I J} (F : Powerendo′ I) (G : Powerendo′ J) → Powerendo′ (I ⊎ J)
reduce′ H {I} {J} F G = record
{ F₀ = my-F₀
; F₁ = my-F₁
; identity = λ {As} → my-identity {As}
; homomorphism = λ {As Bs Cs fs gs} → my-homomorphism {fs = fs} {gs}
; F-resp-≡ = λ fs → H.F-resp-≡ (F.F-resp-≡ (fs ∙ inj₁) , G.F-resp-≡ (fs ∙ inj₂))
}
where
private module L = Category (Exp (I ⊎ J))
private module F = Functor F
private module G = Functor G
private module H = Functor H
open L using () renaming (_≡_ to _≡≡_; _∘_ to _∘∘_)
open C using (_≡_; _∘_)
my-F₀ = λ As → H.F₀ ((F.F₀ (As ∙ inj₁)) , (G.F₀ (As ∙ inj₂)))
my-F₁ : ∀ {As Bs} → L._⇒_ As Bs → C [ my-F₀ As , my-F₀ Bs ]
my-F₁ {As} {Bs} fs = H.F₁ (F.F₁ (fs ∙ inj₁) , G.F₁ (fs ∙ inj₂))
.my-identity : ∀ {As} → my-F₁ (L.id {As}) ≡ C.id
my-identity {As} = begin
H.F₁ (F.F₁ (λ i → C.id {As (inj₁ i)}) , G.F₁ (λ i → C.id {As (inj₂ i)}))
↓⟨ H.F-resp-≡ (F.identity , G.identity) ⟩
H.F₁ (C.id , C.id)
↓⟨ H.identity ⟩
C.id
∎
where
open C.HomReasoning
.my-homomorphism : ∀ {As Bs Cs} {fs : L._⇒_ As Bs} {gs : L._⇒_ Bs Cs} → my-F₁ (gs ∘∘ fs) ≡ (my-F₁ gs ∘ my-F₁ fs)
my-homomorphism {fs = fs} {gs} =
begin
my-F₁ (gs ∘∘ fs)
↓⟨ H.F-resp-≡ (F.homomorphism , G.homomorphism) ⟩
H.F₁ ((F.F₁ (gs ∙ inj₁) ∘ F.F₁ (fs ∙ inj₁)) , (G.F₁ (gs ∙ inj₂) ∘ G.F₁ (fs ∙ inj₂)))
↓⟨ H.homomorphism ⟩
my-F₁ gs ∘ my-F₁ fs
∎
where
open C.HomReasoning
reduce : ∀ (H : Bifunctor C C C) {n m} (F : Powerendo n) (G : Powerendo m) → Powerendo (n + m)
reduce H F G = flattenP (reduce′ H F G)
flattenP-assocʳ : ∀ {n₁ n₂ n₃} (F : Powerendo′ (Fin n₁ ⊎ (Fin n₂ ⊎ Fin n₃))) → Powerendo ((n₁ + n₂) + n₃)
flattenP-assocʳ {n₁} {n₂} {n₃} F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ {As Bs} fs → F.F₁ (fs ∙ pack)
; identity = λ {As} → F.identity
; homomorphism = λ {As Bs Cs fs gs} → F.homomorphism
; F-resp-≡ = λ {As Bs fs gs} fs≡gs → F.F-resp-≡ (fs≡gs ∙ pack)
}
where
module F = Functor F
pack = ⟦ inject+ n₃ ∙ inject+ n₂ , ⟦ inject+ n₃ ∙ raise n₁ , raise (n₁ + n₂) ⟧′ ⟧′
reduce2ʳ : ∀ (G : Bifunctor C C C) {n₁ n₂ n₃} (F₁ : Powerendo n₁) (F₂ : Powerendo n₂) (F₃ : Powerendo n₃) → Powerendo ((n₁ + n₂) + n₃)
reduce2ʳ G F₁ F₂ F₃ = flattenP-assocʳ (reduce′ G F₁ (reduce′ G F₂ F₃))
overlaps : ∀ {D E} (H : Bifunctor D D E) {I} (F G : Powerfunctor′ D I) → Powerfunctor′ E I
overlaps {D} {E} H {I} F G = record
{ F₀ = my-F₀
; F₁ = my-F₁
; identity = λ {As} → my-identity {As}
; homomorphism = λ {As Bs Cs fs gs} → my-homomorphism {fs = fs} {gs}
; F-resp-≡ = λ fs → H.F-resp-≡ (F.F-resp-≡ fs , G.F-resp-≡ fs)
}
where
private module L = Category (Exp I)
private module F = Functor F
private module G = Functor G
private module H = Functor H
private module D = Category D
private module E = Category E
open L using () renaming (_≡_ to _≡≡_; _∘_ to _∘∘_)
open E using (_≡_; _∘_)
open D using () renaming (_∘_ to _∘D_)
my-F₀ = λ As → H.F₀ (F.F₀ As , G.F₀ As)
my-F₁ : ∀ {As Bs} → (Exp I) [ As , Bs ] → E [ my-F₀ As , my-F₀ Bs ]
my-F₁ {As} {Bs} fs = H.F₁ (F.F₁ fs , G.F₁ fs)
.my-identity : ∀ {As} → my-F₁ (L.id {As}) ≡ E.id
my-identity {As} = begin
H.F₁ (F.F₁ (λ i → C.id {As i}) , G.F₁ (λ i → C.id {As i}))
↓⟨ H.F-resp-≡ (F.identity , G.identity) ⟩
H.F₁ (D.id , D.id)
↓⟨ H.identity ⟩
E.id
∎
where
open E.HomReasoning
.my-homomorphism : ∀ {As Bs Cs} {fs : (Exp I) [ As , Bs ]} {gs : (Exp I) [ Bs , Cs ]} → my-F₁ (gs ∘∘ fs) ≡ (my-F₁ gs ∘ my-F₁ fs)
my-homomorphism {fs = fs} {gs} =
begin
my-F₁ (gs ∘∘ fs)
↓⟨ H.F-resp-≡ (F.homomorphism , G.homomorphism) ⟩
H.F₁ ((F.F₁ gs ∘D F.F₁ fs) , (G.F₁ gs ∘D G.F₁ fs))
↓⟨ H.homomorphism ⟩
my-F₁ gs ∘ my-F₁ fs
∎
where
open E.HomReasoning
overlap2ʳ : ∀ (G : Bifunctor C C C) {n} (F₁ F₂ F₃ : Powerendo n) → Powerendo n
overlap2ʳ G F₁ F₂ F₃ = (overlaps {C} G F₁ (overlaps {C} G F₂ F₃))
select′ : ∀ {I} (i : I) → Powerendo′ I
select′ {I} i = record
{ F₀ = λ xs → xs i
; F₁ = λ fs → fs i
; identity = C.Equiv.refl
; homomorphism = C.Equiv.refl
; F-resp-≡ = λ eqs → eqs i
}
select : ∀ m {n} {m<n : True (suc m ≤? n)} → Powerendo n
select m {n} {m<n} = select′ (#_ m {n} {m<n})
triv : (n : ℕ) → Hyperendo n n
triv n = record
{ F₀ = λ x → x
; F₁ = λ x → x
; identity = λ _ → C.Equiv.refl
; homomorphism = λ _ → C.Equiv.refl
; F-resp-≡ = λ x → x
}
pad : ∀ (l r : ℕ) {n m} (F : Hyperendo n m) → Hyperendo ((l + n) + r) ((l + m) + r)
pad l r F = (triv l ∥ F) ∥ triv r
padˡ : ∀ (l : ℕ) {n m} (F : Hyperendo n m) → Hyperendo (l + n) (l + m)
padˡ l F = triv l ∥ F
padʳ : ∀ (r : ℕ) {n m} (F : Hyperendo n m) → Hyperendo (n + r) (m + r)
padʳ r F = F ∥ triv r
unary : (F : Functor C C) → Powerendo 1
unary F = record
{ F₀ = λ As → F.F₀ (As zero)
; F₁ = λ fs → F.F₁ (fs zero)
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≡ = λ fs≡gs → F.F-resp-≡ (fs≡gs zero)
}
where
module F = Functor F
unaryH : (F : Functor C C) → Hyperendo 1 1
unaryH F = record
{ F₀ = λ As → F.F₀ ∙ As
; F₁ = λ fs → F.F₁ ∙ fs
; identity = λ _ → F.identity
; homomorphism = λ _ → F.homomorphism
; F-resp-≡ = λ fs≡gs → F.F-resp-≡ ∙ fs≡gs
}
where
module F = Functor F
nullary : (X : C.Obj) → Powerendo 0
nullary X = record
{ F₀ = λ _ → X
; F₁ = λ _ → C.id
; identity = C.Equiv.refl
; homomorphism = C.Equiv.sym C.identityˡ
; F-resp-≡ = λ _ → C.Equiv.refl
}
nullaryH : (X : C.Obj) → Hyperendo 0 1
nullaryH X = record
{ F₀ = λ _ _ → X
; F₁ = λ _ _ → C.id
; identity = λ _ → C.Equiv.refl
; homomorphism = λ _ → C.Equiv.sym C.identityˡ
; F-resp-≡ = λ _ _ → C.Equiv.refl
}
binary : (F : Bifunctor C C C) → Powerendo 2
binary F = record
{ F₀ = λ As → F.F₀ (As zero , As (suc zero))
; F₁ = λ fs → F.F₁ (fs zero , fs (suc zero))
; identity = F.identity
; homomorphism = F.homomorphism
; F-resp-≡ = λ fs≡gs → F.F-resp-≡ (fs≡gs zero , fs≡gs (suc zero))
}
where
module F = Functor F
binaryH : (F : Bifunctor C C C) → Hyperendo 2 1
binaryH F = record
{ F₀ = λ As _ → F.F₀ (As zero , As (suc zero))
; F₁ = λ fs _ → F.F₁ (fs zero , fs (suc zero))
; identity = λ _ → F.identity
; homomorphism = λ _ → F.homomorphism
; F-resp-≡ = λ fs≡gs _ → F.F-resp-≡ (fs≡gs zero , fs≡gs (suc zero))
}
where
module F = Functor F
hyp : ∀ {n} (F : Powerendo n) → Hyperendo n 1
hyp F = record
{ F₀ = λ As _ → F.F₀ As
; F₁ = λ fs _ → F.F₁ fs
; identity = λ _ → F.identity
; homomorphism = λ _ → F.homomorphism
; F-resp-≡ = λ fs≡gs _ → F.F-resp-≡ fs≡gs
}
where
module F = Functor F
private
curryⁿ : ∀ n {a b} {A : Set a} {B : Set b} → ((Fin n → A) → B) → N-ary n A B
curryⁿ zero f = f (λ ())
curryⁿ (suc n) {A = A} f = λ x → curryⁿ n (f ∙ addon x)
where
addon : A → (Fin n → A) → Fin (suc n) → A
addon x _ zero = x
addon _ g (suc i) = g i
plex′ : ∀ {J I} → (J → Powerendo′ I) → Hyperendo′ I J
plex′ Fs = record
{ F₀ = flip (Functor.F₀ ∙ Fs)
; F₁ = flip (λ j → Functor.F₁ (Fs j))
; identity = λ j → Functor.identity (Fs j)
; homomorphism = λ j → Functor.homomorphism (Fs j)
; F-resp-≡ = flip (λ j → Functor.F-resp-≡ (Fs j))
}
plex : ∀ {n} {I} → N-ary n (Powerendo′ I) (Hyperendo′ I (Fin n))
plex {n} = curryⁿ n plex′
widenˡ : ∀ (l : ℕ) {n} (F : Powerendo n) → Powerendo (l + n)
widenˡ l F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ {As Bs} fs → F.F₁ (fs ∙ pack)
; identity = λ {As} → F.identity
; homomorphism = λ {As Bs Cs fs gs} → F.homomorphism
; F-resp-≡ = λ {As Bs fs gs} fs≡gs → F.F-resp-≡ (fs≡gs ∙ pack)
}
where
private module F = Functor F
pack = raise l
widenʳ : ∀ (r : ℕ) {n} (F : Powerendo n) → Powerendo (n + r)
widenʳ r F = record
{ F₀ = λ As → F.F₀ (As ∙ pack)
; F₁ = λ {As Bs} fs → F.F₁ (fs ∙ pack)
; identity = λ {As} → F.identity
; homomorphism = λ {As Bs Cs fs gs} → F.homomorphism
; F-resp-≡ = λ {As Bs fs gs} fs≡gs → F.F-resp-≡ (fs≡gs ∙ pack)
}
where
private module F = Functor F
pack = inject+ r
| 33.691011
| 134
| 0.533267
|
2fba5e738c4a532cca9b977afd423a8239152e1e
| 1,877
|
agda
|
Agda
|
vendor/stdlib/src/Data/List/All/Properties.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Data/List/All/Properties.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Data/List/All/Properties.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Properties relating All to various list functions
------------------------------------------------------------------------
module Data.List.All.Properties where
open import Data.Bool
open import Data.Bool.Properties
open import Data.Function
open import Data.List as List
import Data.List.Any as Any
open Any.Membership-≡
open import Data.List.All as All using (All; []; _∷_)
open import Data.Product
open import Relation.Unary using (Pred) renaming (_⊆_ to _⋐_)
-- Functions can be shifted between the predicate and the list.
All-map : ∀ {A B} {P : Pred B} {f : A → B} {xs} →
All (P ∘₀ f) xs → All P (List.map f xs)
All-map [] = []
All-map (p ∷ ps) = p ∷ All-map ps
map-All : ∀ {A B} {P : Pred B} {f : A → B} {xs} →
All P (List.map f xs) → All (P ∘₀ f) xs
map-All {xs = []} [] = []
map-All {xs = _ ∷ _} (p ∷ ps) = p ∷ map-All ps
-- A variant of All.map.
gmap : ∀ {A B} {P : A → Set} {Q : B → Set} {f : A → B} →
P ⋐ Q ∘₀ f → All P ⋐ All Q ∘₀ List.map f
gmap g = All-map ∘ All.map g
-- All and all are related via T.
All-all : ∀ {A} (p : A → Bool) {xs} →
All (T ∘₀ p) xs → T (all p xs)
All-all p [] = _
All-all p (px ∷ pxs) = proj₂ T-∧ (px , All-all p pxs)
all-All : ∀ {A} (p : A → Bool) xs →
T (all p xs) → All (T ∘₀ p) xs
all-All p [] _ = []
all-All p (x ∷ xs) px∷xs with proj₁ (T-∧ {p x}) px∷xs
all-All p (x ∷ xs) px∷xs | (px , pxs) = px ∷ all-All p xs pxs
-- All is anti-monotone.
anti-mono : ∀ {A} {P : Pred A} {xs ys} → xs ⊆ ys → All P ys → All P xs
anti-mono xs⊆ys pys = All.tabulate (All.lookup pys ∘ xs⊆ys)
-- all is anti-monotone.
all-anti-mono : ∀ {A} (p : A → Bool) {xs ys} →
xs ⊆ ys → T (all p ys) → T (all p xs)
all-anti-mono p xs⊆ys = All-all p ∘ anti-mono xs⊆ys ∘ all-All p _
| 32.362069
| 72
| 0.508791
|
590b071b2f17e58c1d3c1c5da8d8f9c77d669b5e
| 2,697
|
agda
|
Agda
|
src/Implicits/WellTyped.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Implicits/WellTyped.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Implicits/WellTyped.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
open import Prelude hiding (id; erase)
module Implicits.WellTyped where
open import Data.Fin.Substitution
open import Data.Vec hiding ([_])
open import Data.List as List hiding ([_]; map)
open import Implicits.Syntax.Type
open import Implicits.Syntax.Term
open import Implicits.Syntax.Context
open import Implicits.Substitutions
module TypingRules (_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set) where
infixl 4 _⊢_∈_
-----------------------------------------------------------------------------
-- typings
data _⊢_∈_ {ν n} (K : Ktx ν n) : Term ν n → Type ν → Set where
var : (x : Fin n) → K ⊢ var x ∈ (lookup x (proj₁ K))
λ' : ∀ {t b} a → a ∷Γ K ⊢ t ∈ b → K ⊢ λ' a t ∈ simpl (a →' b)
Λ : ∀ {t} {a : Type (suc ν)} → ktx-weaken K ⊢ t ∈ a → K ⊢ Λ t ∈ ∀' a
_[_] : ∀ {t} {a : Type (suc ν)} →
K ⊢ t ∈ ∀' a → (b : Type ν) → K ⊢ t [ b ] ∈ a tp[/tp b ]
_·_ : ∀ {f t a b} → K ⊢ f ∈ simpl (a →' b) → K ⊢ t ∈ a → K ⊢ f · t ∈ b
-- implicit abstract/application
ρ : ∀ {t b a} → [] ⊢unamb a → a ∷K K ⊢ t ∈ b → K ⊢ ρ a t ∈ (a ⇒ b)
_⟨_⟩ : ∀ {a b f} → K ⊢ f ∈ a ⇒ b → (proj₂ K) ⊢ᵣ a → K ⊢ f ⟨⟩ ∈ b
_with'_ : ∀ {r e a b} → K ⊢ r ∈ a ⇒ b → K ⊢ e ∈ a → K ⊢ r with' e ∈ b
_⊢_∉_ : ∀ {ν n} → (K : Ktx ν n) → Term ν n → Type ν → Set
_⊢_∉_ K t τ = ¬ K ⊢ t ∈ τ
-----------------------------------------------------------------------------
-- syntactic sugar
let'_in'_ : ∀ {ν n} {e₁ : Term ν n} {e₂ : Term ν (suc n)} {a b} {K} →
K ⊢ e₁ ∈ a → a ∷Γ K ⊢ e₂ ∈ b → K ⊢ (let' e₁ ∶ a in' e₂) ∈ b
let' e₁ in' e₂ = (λ' _ e₂) · e₁
implicit'_∶_in'_ : ∀ {ν n} {e₁ : Term ν n} {e₂ : Term ν (suc n)} {a b} {K} →
K ⊢ e₁ ∈ a → [] ⊢unamb a → a ∷K K ⊢ e₂ ∈ b → K ⊢ (implicit e₁ ∶ a in' e₂) ∈ b
implicit' e₁ ∶ a in' e₂ = (ρ a e₂) with' e₁
wt-¿ : ∀ {ν n} {r : Type ν} {K : Ktx ν n} → [] ⊢unamb r → (proj₂ K) ⊢ᵣ r → K ⊢ (¿ r) ∈ r
wt-¿ r x = (ρ r (var zero)) ⟨ x ⟩
-----------------------------------------------------------------------------
-- utilities
erase : ∀ {ν n} {K : Ktx ν n} {t a} → K ⊢ t ∈ a → Term ν n
erase {t = t} _ = t
-- Collections of typing derivations for well-typed terms.
data _⊢ⁿ_∈_ {m n} (Γ : Ktx n m) : ∀ {k} → Vec (Term n m) k → Vec (Type n) k → Set where
[] : Γ ⊢ⁿ [] ∈ []
_∷_ : ∀ {t a k} {ts : Vec (Term n m) k} {as : Vec (Type n) k} →
Γ ⊢ t ∈ a → Γ ⊢ⁿ ts ∈ as → Γ ⊢ⁿ t ∷ ts ∈ (a ∷ as)
-- Lookup a well-typed term in a collection thereof.
lookup-⊢ : ∀ {m n k} {Γ : Ktx n m} {ts : Vec (Term n m) k} {as : Vec (Type n) k} →
(x : Fin k) → Γ ⊢ⁿ ts ∈ as → Γ ⊢ lookup x ts ∈ lookup x as
lookup-⊢ zero (⊢t ∷ ⊢ts) = ⊢t
lookup-⊢ (suc x) (⊢t ∷ ⊢ts) = lookup-⊢ x ⊢ts
| 40.253731
| 91
| 0.429366
|
222894395697c7ab72266a3161085b70d6c135c0
| 912
|
agda
|
Agda
|
misc/RecursiveDescent/Inductive/Token.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
misc/RecursiveDescent/Inductive/Token.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
misc/RecursiveDescent/Inductive/Token.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some parsers which require a decidable token equality
------------------------------------------------------------------------
open import Relation.Binary
module RecursiveDescent.Inductive.Token (D : DecSetoid) where
open DecSetoid D using (_≟_) renaming (carrier to tok)
open import RecursiveDescent.Inductive
open import RecursiveDescent.Inductive.SimpleLib
open import Data.Maybe
open import Relation.Nullary
open import Data.Vec
open import Data.Vec1
-- Parsing a given token (or, really, a given equivalence class of
-- tokens).
sym : forall {nt} -> tok -> Parser tok nt _ tok
sym c = sat p
where
p : tok -> Maybe tok
p x with c ≟ x
... | yes _ = just x
... | no _ = nothing
-- Parsing a sequence of tokens.
string : forall {nt n} -> Vec tok n -> Parser tok nt _ (Vec tok n)
string cs = sequence (map₀₁ sym cs)
| 26.823529
| 72
| 0.600877
|
4120fe3ca782570d97aab9ac072947b841139e5c
| 3,925
|
agda
|
Agda
|
doc/icfp20/code/Midi.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 28
|
2017-04-21T09:08:52.000Z
|
2022-03-04T18:04:07.000Z
|
doc/icfp20/code/Midi.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 1
|
2020-11-13T01:26:20.000Z
|
2020-11-17T00:58:55.000Z
|
doc/icfp20/code/Midi.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 3
|
2019-01-12T17:02:36.000Z
|
2020-11-10T04:04:40.000Z
|
{-# OPTIONS --without-K #-}
module Midi where
open import Agda.Builtin.String using (String)
open import Data.Fin using (toℕ)
open import Data.Nat using (ℕ)
open import Data.List
open import Data.Product using (_,_)
open import Note
open import Pitch
open import MidiEvent
open import Music
{-# FOREIGN GHC
import Codec.Midi
import Data.Text (Text, unpack)
import Data.List (sort)
type HsTicksPerBeat = Integer
type HsTicks = Integer
type HsKey = Integer
type HsVelocity = Integer
type HsPreset = Integer
type HsChannel = Integer
type HsTempo = Integer
type HsAbsTime = Integer
type HsTrackName = Text
-- convert beats per minute to microseconds per beat
bpmToTempo :: Int -> Tempo
bpmToTempo bpm = round $ 1000000 * 60 / fromIntegral bpm
data HsMidiMessage = HsNoteOn HsVelocity HsTicks HsKey | HsNoteOff HsVelocity HsTicks HsKey
deriving Eq
getTicks :: HsMidiMessage -> HsTicks
getTicks (HsNoteOn _ t _) = t
getTicks (HsNoteOff _ t _) = t
instance Ord HsMidiMessage where
a <= b = getTicks a <= getTicks b
data HsMidiTrack = HsMidiTrack HsTrackName HsPreset HsChannel HsTempo [HsMidiMessage]
fi = fromInteger
makeTrack :: Channel -> HsAbsTime -> [HsMidiMessage] -> (Track Ticks , HsAbsTime)
makeTrack c t [] = ([(0, TrackEnd)], t)
makeTrack c t (HsNoteOn v t' k : ms) = let (rest, t'') = makeTrack c t' ms
in ((fi (t' - t), NoteOn c (fi k) (fi v)) : rest, t'')
makeTrack c t (HsNoteOff v t' k : ms) = let (rest, t'') = makeTrack c t' ms
in ((fi (t' - t), NoteOff c (fi k) (fi v)) : rest, t'')
toTrack :: HsMidiTrack -> Track Ticks
toTrack (HsMidiTrack name preset channel tempo messages) =
(0, TrackName (unpack name)) :
(0, ProgramChange (fi channel) (fi preset)) :
(0, TempoChange (bpmToTempo (fi tempo))) :
fst (makeTrack (fi channel) 0 (sort messages))
toMidi :: HsTicksPerBeat -> [HsMidiTrack] -> Midi
toMidi ticks tracks = let mtracks = map toTrack tracks
in Midi MultiTrack (TicksPerBeat (fi ticks)) mtracks
exportTracks :: Text -> HsTicksPerBeat -> [HsMidiTrack] -> IO ()
exportTracks filePath ticksPerBeat tracks = do
let path = unpack filePath
putStrLn $ "Writing file " ++ path
-- putStrLn $ show $ toMidi ticksPerBeat tracks
exportFile path (toMidi ticksPerBeat tracks)
#-}
data Unit : Set where
unit : Unit
{-# COMPILE GHC Unit = data () (()) #-}
postulate
IO : Set → Set
{-# BUILTIN IO IO #-}
{-# COMPILE GHC IO = type IO #-}
FilePath = String
data Pair (A : Set) (B : Set) : Set where
pair : A → B → Pair A B
{-# COMPILE GHC Pair = data (,) ((,)) #-}
HInstrument HPitch HVelocity : Set
HInstrument = ℕ
HPitch = ℕ
HVelocity = ℕ
HChannel = ℕ
HTempo = ℕ
data MidiMessage : Set where
noteOn : HVelocity → Tick → HPitch → MidiMessage
noteOff : HVelocity → Tick → HPitch → MidiMessage
{-# COMPILE GHC MidiMessage = data HsMidiMessage (HsNoteOn | HsNoteOff) #-}
event→messages : MidiEvent → List MidiMessage
event→messages (midiEvent p start stop v) =
let v' = toℕ v
p' = unpitch p
in noteOn v' start p' ∷ noteOff v' stop p' ∷ []
data HMidiTrack : Set where
htrack : String → HInstrument → HChannel → HTempo → List MidiMessage → HMidiTrack
{-# COMPILE GHC HMidiTrack = data HsMidiTrack (HsMidiTrack) #-}
track→htrack : MidiTrack → HMidiTrack
track→htrack (track n i c t m) = htrack n (toℕ i) (toℕ c) t (concatMap event→messages m)
postulate
exportTracks : FilePath → -- path to the file to save the MIDI data to
ℕ → -- number of ticks per beat (by default a beat is a quarter note)
List HMidiTrack → -- tracks, one per instrument
IO Unit
{-# COMPILE GHC exportTracks = exportTracks #-}
| 30.426357
| 100
| 0.635414
|
229635ced01e9962eed274e0f6685ff47c754d92
| 7,614
|
agda
|
Agda
|
src/Bisimilarity/6-2-5.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Bisimilarity/6-2-5.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Bisimilarity/6-2-5.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some results related to an LTS from Section 6.2.5 of "Enhancements
-- of the bisimulation proof method" by Pous and Sangiorgi,
-- implemented using the coinductive definition of bisimilarity
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.6-2-5 {Name : Type} where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Function-universe equality-with-J hiding (id; _∘_)
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
open import Indexed-container using (⟦_⟧)
open import Labelled-transition-system.6-2-5 Name
open import Relation
open import Bisimilarity 6-2-5
open import Bisimilarity.Up-to 6-2-5
-- Some simple lemmas. The first two are stated by Pous and Sangiorgi,
-- and the third one is a generalisation of a result stated by Pous
-- and Sangiorgi.
op·∅ : ∀ {a} → op (a · ∅) ∼ ∅
op·∅ {a} = ⟨ lr , (λ ()) ⟩
where
lr : ∀ {P′ μ} →
op (a · ∅) [ μ ]⟶ P′ →
∃ λ Q′ → ∅ [ μ ]⟶ Q′ × P′ ∼′ Q′
lr (op action ())
op··∅ : ∀ {a} → op (a · a · ∅) ∼ a · ∅
op··∅ {a} = ⟨ lr , rl ⟩
where
lr : ∀ {P′ μ b} →
op (a · b · ∅) [ μ ]⟶ P′ →
∃ λ Q′ → b · ∅ [ μ ]⟶ Q′ × P′ ∼′ Q′
lr (op action action) = _ , action , reflexive
rl : ∀ {Q′ μ} →
a · ∅ [ μ ]⟶ Q′ →
∃ λ P′ → op (a · a · ∅) [ μ ]⟶ P′ × P′ ∼′ Q′
rl action = _ , op action action , reflexive
a≁b·c : ∀ {a b c} → ¬ (a · ∅ ∼ b · c · ∅)
a≁b·c a∼b·c with right-to-left a∼b·c action
... | .∅ , action , ∅∼a with right-to-left (force ∅∼a) action
... | _ , () , _
-- Pous and Sangiorgi note that every context preserves bisimilarity.
-- One can prove that a ·_ preserves bisimilarity in a size-preserving
-- way.
·-cong : ∀ {i a P Q} → [ i ] P ∼ Q → [ i ] a · P ∼ a · Q
·-cong {i} {a} P∼Q =
⟨ lr P∼Q
, Σ-map id (Σ-map id symmetric) ∘ lr (symmetric P∼Q)
⟩
where
lr : ∀ {P P′ Q μ} →
[ i ] P ∼ Q → a · P [ μ ]⟶ P′ →
∃ λ Q′ → a · Q [ μ ]⟶ Q′ × [ i ] P′ ∼′ Q′
lr P∼Q action = _ , action , convert P∼Q
-- The operator op also preserves bisimilarity, but this lemma is not
-- claimed to be size-preserving.
op-cong : ∀ {i} {j : Size< i} {P Q} →
[ i ] P ∼ Q → [ j ] op P ∼ op Q
op-cong {i} {j} P∼Q =
⟨ lr P∼Q
, Σ-map id (Σ-map id symmetric) ∘ lr (symmetric P∼Q)
⟩
where
lr : ∀ {P P′ Q μ} →
[ i ] P ∼ Q → op P [ μ ]⟶ P′ →
∃ λ Q′ → op Q [ μ ]⟶ Q′ × [ j ] P′ ∼′ Q′
lr P∼Q (op P⟶P′ P′⟶P″) =
let Q′ , Q⟶Q′ , P′∼Q′ = left-to-right P∼Q P⟶P′
Q″ , Q′⟶Q″ , P″∼Q″ = left-to-right (force P′∼Q′) P′⟶P″
in Q″ , op Q⟶Q′ Q′⟶Q″ , P″∼Q″
-- Let us assume that the Name type is inhabited. In that case op-cong
-- /cannot/ preserve the size of its argument.
--
-- The proof is based on an argument presented by Pous and Sangiorgi.
op-cong-cannot-preserve-size :
Name →
¬ (∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q)
op-cong-cannot-preserve-size a op-cong = a≁b·c a∼a·a
where
op-cong′ : ∀ {i P Q} → [ i ] P ∼′ Q → [ i ] op P ∼′ op Q
force (op-cong′ P∼′Q) = op-cong (force P∼′Q)
a∼a·a : ∀ {i} → [ i ] a · ∅ ∼ a · a · ∅
a∼a·a {i} = ⟨ lr , rl ⟩
where
a∼′a·a : ∀ {i} → [ i ] a · ∅ ∼′ a · a · ∅
force a∼′a·a = a∼a·a
lemma =
∅ ∼⟨ symmetric op·∅ ⟩
op (a · ∅) ∼⟨ op-cong′ (a∼′a·a {i = i}) ⟩
op (a · a · ∅) ∼⟨ op··∅ ⟩■
a · ∅
lr : ∀ {P′ μ} →
a · ∅ [ μ ]⟶ P′ →
∃ λ Q′ → a · a · ∅ [ μ ]⟶ Q′ × [ i ] P′ ∼′ Q′
lr action = a · ∅ , action , lemma
rl : ∀ {Q′ μ} →
a · a · ∅ [ μ ]⟶ Q′ →
∃ λ P′ → a · ∅ [ μ ]⟶ P′ × [ i ] P′ ∼′ Q′
rl action = ∅ , action , lemma
-- Up to context (for monadic contexts).
Up-to-context : Trans₂ (# 0) Proc
Up-to-context R (P , Q) =
∃ λ (C : Context 1) →
∃ λ P′ →
∃ λ Q′ →
P ≡ C [ (λ _ → P′) ]
×
Q ≡ C [ (λ _ → Q′) ]
×
R (P′ , Q′)
-- Up to context is monotone.
up-to-context-monotone : Monotone Up-to-context
up-to-context-monotone R⊆S =
Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id R⊆S
-- Up to bisimilarity and context.
Up-to-bisimilarity-and-context : Trans₂ (# 0) Proc
Up-to-bisimilarity-and-context =
Up-to-bisimilarity ∘ Up-to-context
-- Up to bisimilarity and context is monotone.
up-to-bisimilarity-and-context-monotone :
Monotone Up-to-bisimilarity-and-context
up-to-bisimilarity-and-context-monotone =
up-to-bisimilarity-monotone ∘ up-to-context-monotone
-- Up to bisimilarity and context is not sound (assuming that Name is
-- inhabited).
--
-- This result is due to Pous and Sangiorgi.
¬-up-to-bisimilarity-and-context :
Name →
¬ Up-to-technique Up-to-bisimilarity-and-context
¬-up-to-bisimilarity-and-context a =
Up-to-technique Up-to-bisimilarity-and-context ↝⟨ _$ R⊆ ⟩
R ⊆ Bisimilarity ∞ ↝⟨ R⊈∼ ⟩□
⊥ □
where
data R : Rel₂ (# 0) Proc where
base : R (a · ∅ , a · a · ∅)
lemma : Up-to-bisimilarity-and-context R (∅ , a · ∅)
lemma =
op (a · ∅) ,
symmetric op·∅ ,
op (a · a · ∅) ,
(op (hole fzero) , a · ∅ , a · a · ∅ , refl , refl , base) ,
op··∅
R⊆ : R ⊆ ⟦ StepC ⟧ (Up-to-bisimilarity-and-context R)
R⊆ base =
⟨ (λ { action → a · ∅ , action , lemma })
, (λ { action → ∅ , action , lemma })
⟩
R⊈∼ : ¬ R ⊆ Bisimilarity ∞
R⊈∼ =
R ⊆ Bisimilarity ∞ ↝⟨ (λ R⊆∼ → R⊆∼ base) ⟩
a · ∅ ∼ a · a · ∅ ↝⟨ a≁b·c ⟩□
⊥ □
-- The last result above can be used to give another proof showing
-- that op-cong cannot preserve the size of its argument (assuming
-- that Name is inhabited).
op-cong-cannot-preserve-size′ :
Name →
¬ (∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q)
op-cong-cannot-preserve-size′ a =
(∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q) ↝⟨ (λ op-cong C P∼Q → []-cong op-cong C (λ _ → P∼Q)) ⟩
(∀ {i P Q} (C : Context 1) → [ i ] P ∼ Q →
[ i ] C [ (λ _ → P) ] ∼ C [ (λ _ → Q) ]) ↝⟨ (λ []-cong → λ where
{x = P , Q} (_ , P∼C[R₁] , _ ,
(C , R₁ , R₂ , refl , refl , R₁∼R₂) , C[R₂]∼Q) →
P ∼⟨ P∼C[R₁] ⟩
C [ (λ _ → R₁) ] ∼⟨ []-cong C R₁∼R₂ ⟩
C [ (λ _ → R₂) ] ∼⟨ C[R₂]∼Q ⟩■
Q) ⟩
(∀ {i} → Up-to-bisimilarity-and-context (Bisimilarity i) ⊆
Bisimilarity i) ↝⟨ _⇔_.from (monotone→⇔ up-to-bisimilarity-and-context-monotone) ⟩
Size-preserving Up-to-bisimilarity-and-context ↝⟨ size-preserving→up-to ⟩
Up-to-technique Up-to-bisimilarity-and-context ↝⟨ ¬-up-to-bisimilarity-and-context a ⟩□
⊥ □
where
[]-cong :
(∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q) →
∀ {i n Ps Qs}
(C : Context n) → (∀ x → [ i ] Ps x ∼ Qs x) →
[ i ] C [ Ps ] ∼ C [ Qs ]
[]-cong op-cong (hole x) Ps∼Qs = Ps∼Qs x
[]-cong op-cong (op C) Ps∼Qs = op-cong ([]-cong op-cong C Ps∼Qs)
[]-cong op-cong (a · C) Ps∼Qs = ·-cong ([]-cong op-cong C Ps∼Qs)
[]-cong op-cong ∅ Ps∼Qs = reflexive
| 32.961039
| 129
| 0.463357
|
13afc28ca4e2899bdde637a0d7521e11c9baced7
| 406
|
agda
|
Agda
|
src/Categories/Category/Cocomplete.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Cocomplete.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Cocomplete.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Cocomplete where
open import Level
open import Categories.Category using (Category)
open import Categories.Functor using (Functor)
open import Categories.Diagram.Colimit using (Colimit)
Cocomplete : (o ℓ e : Level) {o′ ℓ′ e′ : Level} (C : Category o′ ℓ′ e′) → Set _
Cocomplete o ℓ e C = ∀ {J : Category o ℓ e} (F : Functor J C) → Colimit F
| 31.230769
| 79
| 0.70197
|
9a6b5619b57344013d4ef5b4e533a41b009cfbe8
| 7,533
|
agda
|
Agda
|
src/LEMC.agda
|
shinji-kono/zf-in-agda
|
031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0
|
[
"MIT"
] | 5
|
2019-10-02T13:46:23.000Z
|
2021-01-10T13:27:48.000Z
|
src/LEMC.agda
|
shinji-kono/zf-in-agda
|
031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0
|
[
"MIT"
] | null | null | null |
src/LEMC.agda
|
shinji-kono/zf-in-agda
|
031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0
|
[
"MIT"
] | null | null | null |
open import Level
open import Ordinals
open import logic
open import Relation.Nullary
module LEMC {n : Level } (O : Ordinals {n} ) (p∨¬p : ( p : Set n) → p ∨ ( ¬ p )) where
open import zf
open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ )
open import Relation.Binary.PropositionalEquality
open import Data.Nat.Properties
open import Data.Empty
open import Relation.Binary
open import Relation.Binary.Core
open import nat
import OD
open inOrdinal O
open OD O
open OD.OD
open OD._==_
open ODAxiom odAxiom
import OrdUtil
import ODUtil
open Ordinals.Ordinals O
open Ordinals.IsOrdinals isOrdinal
open Ordinals.IsNext isNext
open OrdUtil O
open ODUtil O
open import zfc
open HOD
open _⊆_
decp : ( p : Set n ) → Dec p -- assuming axiom of choice
decp p with p∨¬p p
decp p | case1 x = yes x
decp p | case2 x = no x
∋-p : (A x : HOD ) → Dec ( A ∋ x )
∋-p A x with p∨¬p ( A ∋ x) -- LEM
∋-p A x | case1 t = yes t
∋-p A x | case2 t = no (λ x → t x)
double-neg-eilm : {A : Set n} → ¬ ¬ A → A -- we don't have this in intutionistic logic
double-neg-eilm {A} notnot with decp A -- assuming axiom of choice
... | yes p = p
... | no ¬p = ⊥-elim ( notnot ¬p )
power→⊆ : ( A t : HOD) → Power A ∋ t → t ⊆ A
power→⊆ A t PA∋t = record { incl = λ {x} t∋x → double-neg-eilm (λ not → t1 t∋x (λ x → not x) ) } where
t1 : {x : HOD } → t ∋ x → ¬ ¬ (A ∋ x)
t1 = power→ A t PA∋t
--- With assuption of HOD is ordered, p ∨ ( ¬ p ) <=> axiom of choice
---
record choiced ( X : Ordinal ) : Set n where
field
a-choice : Ordinal
is-in : odef (* X) a-choice
open choiced
-- ∋→d : ( a : HOD ) { x : HOD } → * (& a) ∋ x → X ∋ * (a-choice (choice-func X not))
-- ∋→d a lt = subst₂ (λ j k → odef j k) *iso (sym &iso) lt
oo∋ : { a : HOD} { x : Ordinal } → odef (* (& a)) x → a ∋ * x
oo∋ lt = subst₂ (λ j k → odef j k) *iso (sym &iso) lt
∋oo : { a : HOD} { x : Ordinal } → a ∋ * x → odef (* (& a)) x
∋oo lt = subst₂ (λ j k → odef j k ) (sym *iso) &iso lt
OD→ZFC : ZFC
OD→ZFC = record {
ZFSet = HOD
; _∋_ = _∋_
; _≈_ = _=h=_
; ∅ = od∅
; Select = Select
; isZFC = isZFC
} where
-- infixr 200 _∈_
-- infixr 230 _∩_ _∪_
isZFC : IsZFC (HOD ) _∋_ _=h=_ od∅ Select
isZFC = record {
choice-func = λ A {X} not A∋X → * (a-choice (choice-func X not) );
choice = λ A {X} A∋X not → oo∋ (is-in (choice-func X not))
} where
--
-- the axiom choice from LEM and OD ordering
--
choice-func : (X : HOD ) → ¬ ( X =h= od∅ ) → choiced (& X)
choice-func X not = have_to_find where
ψ : ( ox : Ordinal ) → Set n
ψ ox = (( x : Ordinal ) → x o< ox → ( ¬ odef X x )) ∨ choiced (& X)
lemma-ord : ( ox : Ordinal ) → ψ ox
lemma-ord ox = TransFinite0 {ψ} induction ox where
∀-imply-or : {A : Ordinal → Set n } {B : Set n }
→ ((x : Ordinal ) → A x ∨ B) → ((x : Ordinal ) → A x) ∨ B
∀-imply-or {A} {B} ∀AB with p∨¬p ((x : Ordinal ) → A x) -- LEM
∀-imply-or {A} {B} ∀AB | case1 t = case1 t
∀-imply-or {A} {B} ∀AB | case2 x = case2 (lemma (λ not → x not )) where
lemma : ¬ ((x : Ordinal ) → A x) → B
lemma not with p∨¬p B
lemma not | case1 b = b
lemma not | case2 ¬b = ⊥-elim (not (λ x → dont-orb (∀AB x) ¬b ))
induction : (x : Ordinal) → ((y : Ordinal) → y o< x → ψ y) → ψ x
induction x prev with ∋-p X ( * x)
... | yes p = case2 ( record { a-choice = x ; is-in = ∋oo p } )
... | no ¬p = lemma where
lemma1 : (y : Ordinal) → (y o< x → odef X y → ⊥) ∨ choiced (& X)
lemma1 y with ∋-p X (* y)
lemma1 y | yes y<X = case2 ( record { a-choice = y ; is-in = ∋oo y<X } )
lemma1 y | no ¬y<X = case1 ( λ lt y<X → ¬y<X (d→∋ X y<X) )
lemma : ((y : Ordinal) → y o< x → odef X y → ⊥) ∨ choiced (& X)
lemma = ∀-imply-or lemma1
odef→o< : {X : HOD } → {x : Ordinal } → odef X x → x o< & X
odef→o< {X} {x} lt = o<-subst {_} {_} {x} {& X} ( c<→o< ( subst₂ (λ j k → odef j k ) (sym *iso) (sym &iso) lt )) &iso &iso
have_to_find : choiced (& X)
have_to_find = dont-or (lemma-ord (& X )) ¬¬X∋x where
¬¬X∋x : ¬ ((x : Ordinal) → x o< (& X) → odef X x → ⊥)
¬¬X∋x nn = not record {
eq→ = λ {x} lt → ⊥-elim (nn x (odef→o< lt) lt)
; eq← = λ {x} lt → ⊥-elim ( ¬x<0 lt )
}
--
-- axiom regurality from ε-induction (using axiom of choice above)
--
-- from https://math.stackexchange.com/questions/2973777/is-it-possible-to-prove-regularity-with-transfinite-induction-only
--
-- FIXME : don't use HOD make this level n, so we can remove ε-induction1
record Minimal (x : HOD) : Set (suc n) where
field
min : HOD
x∋min : x ∋ min
min-empty : (y : HOD ) → ¬ ( min ∋ y) ∧ (x ∋ y)
open Minimal
open _∧_
induction : {x : HOD} → ({y : HOD} → x ∋ y → (u : HOD ) → (u∋x : u ∋ y) → Minimal u )
→ (u : HOD ) → (u∋x : u ∋ x) → Minimal u
induction {x} prev u u∋x with p∨¬p ((y : Ordinal ) → ¬ (odef x y) ∧ (odef u y))
... | case1 P =
record { min = x
; x∋min = u∋x
; min-empty = λ y → P (& y)
}
... | case2 NP = min2 where
p : HOD
p = record { od = record { def = λ y1 → odef x y1 ∧ odef u y1 } ; odmax = omin (odmax x) (odmax u) ; <odmax = lemma } where
lemma : {y : Ordinal} → OD.def (od x) y ∧ OD.def (od u) y → y o< omin (odmax x) (odmax u)
lemma {y} lt = min1 (<odmax x (proj1 lt)) (<odmax u (proj2 lt))
np : ¬ (p =h= od∅)
np p∅ = NP (λ y p∋y → ∅< {p} {_} (d→∋ p p∋y) p∅ )
y1choice : choiced (& p)
y1choice = choice-func p np
y1 : HOD
y1 = * (a-choice y1choice)
y1prop : (x ∋ y1) ∧ (u ∋ y1)
y1prop = oo∋ (is-in y1choice)
min2 : Minimal u
min2 = prev (proj1 y1prop) u (proj2 y1prop)
Min2 : (x : HOD) → (u : HOD ) → (u∋x : u ∋ x) → Minimal u
Min2 x u u∋x = (ε-induction {λ y → (u : HOD ) → (u∋x : u ∋ y) → Minimal u } induction x u u∋x )
cx : {x : HOD} → ¬ (x =h= od∅ ) → choiced (& x )
cx {x} nx = choice-func x nx
minimal : (x : HOD ) → ¬ (x =h= od∅ ) → HOD
minimal x ne = min (Min2 (* (a-choice (cx {x} ne) )) x ( oo∋ (is-in (cx ne))) )
x∋minimal : (x : HOD ) → ( ne : ¬ (x =h= od∅ ) ) → odef x ( & ( minimal x ne ) )
x∋minimal x ne = x∋min (Min2 (* (a-choice (cx {x} ne) )) x ( oo∋ (is-in (cx ne))) )
minimal-1 : (x : HOD ) → ( ne : ¬ (x =h= od∅ ) ) → (y : HOD ) → ¬ ( odef (minimal x ne) (& y)) ∧ (odef x (& y) )
minimal-1 x ne y = min-empty (Min2 (* (a-choice (cx ne) )) x ( oo∋ (is-in (cx ne)))) y
| 42.083799
| 143
| 0.443648
|
2ebbccc32e64debc1c9e60087cdec51fcf3d12fc
| 779
|
agda
|
Agda
|
agda/Algebra/Construct/Free/Semilattice/FromList.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
agda/Algebra/Construct/Free/Semilattice/FromList.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Algebra/Construct/Free/Semilattice/FromList.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.FromList where
open import Prelude
open import Algebra.Construct.Free.Semilattice.Definition
open import Algebra.Construct.Free.Semilattice.Eliminators
open import Algebra.Construct.Free.Semilattice.Relation.Unary
open import Data.List
import Data.List.Membership as ℰ
open import Data.Fin using (Fin; fs; f0)
open import HITs.PropositionalTruncation.Sugar
open import HITs.PropositionalTruncation.Properties
fromList : List A → 𝒦 A
fromList = foldr _∷_ []
∈List⇒∈𝒦 : ∀ xs {x : A} → ∥ x ℰ.∈ xs ∥ → x ∈ fromList xs
∈List⇒∈𝒦 [] ∣x∈xs∣ = ⊥-elim (refute-trunc (λ ()) ∣x∈xs∣)
∈List⇒∈𝒦 (x ∷ xs) ∣x∈xs∣ = do
(fs n , x∈xs) ← ∣x∈xs∣
where (f0 , x∈xs) → ∣ inl x∈xs ∣
∣ inr (∈List⇒∈𝒦 xs ∣ n , x∈xs ∣) ∣
| 32.458333
| 61
| 0.690629
|
38258479c8eeaa4f974c80d2e97ba56803c99fa6
| 356
|
agda
|
Agda
|
test/Fail/Issue2403.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2403.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2403.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-01-13, issue #2403
open import Common.Nat
postulate
P : Nat → Set
f : ∀{n} → P n → P (pred n)
test : ∀ n → P n → Set
test zero p = Nat
test (suc n) p = test _ (f p)
-- WAS:
-- The meta-variable is solved to (pred (suc n))
-- Termination checking fails.
-- NOW: If the termination checker normalizes the argument and it passes.
| 19.777778
| 73
| 0.632022
|
1e1461a14a8579a2f9329dd287d6519c4a4f9d52
| 1,472
|
agda
|
Agda
|
GSeTT/Typed-Syntax.agda
|
ThiBen/catt-formalization
|
ed45935b38d6a86fa662f561866140122ee3dcef
|
[
"MIT"
] | 2
|
2020-05-01T08:26:53.000Z
|
2020-05-20T00:41:09.000Z
|
GSeTT/Typed-Syntax.agda
|
ThiBen/catt-formalization
|
ed45935b38d6a86fa662f561866140122ee3dcef
|
[
"MIT"
] | null | null | null |
GSeTT/Typed-Syntax.agda
|
ThiBen/catt-formalization
|
ed45935b38d6a86fa662f561866140122ee3dcef
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import Agda.Primitive
open import Prelude
open import GSeTT.Syntax
open import GSeTT.Rules
open import GSeTT.CwF-structure
open import GSeTT.Uniqueness-Derivations
{- Typed syntax for type theory for globular sets -}
module GSeTT.Typed-Syntax where
Ctx : Set₁
Ctx = Σ Pre-Ctx (λ Γ → Γ ⊢C)
Ty : Ctx → Set₁
Ty (Γ , _) = Σ Pre-Ty (λ A → Γ ⊢T A)
Tm : ∀ (Γ : Ctx) → Ty Γ → Set₁
Tm (Γ , _) (A , _) = Σ Pre-Tm (λ t → Γ ⊢t t # A)
Sub : ∀ (Δ : Ctx) (Γ : Ctx) → Set₁
Sub (Δ , _) (Γ , _) = Σ Pre-Sub (λ γ → Δ ⊢S γ > Γ)
eqC : ∀ (Γ Δ : Ctx) → fst Γ == fst Δ → Γ == Δ
eqC (Γ , Γ⊢) (.Γ , Γ⊢') idp = Σ= idp (has-all-paths-⊢C _ _)
eqT : ∀ {Γ} (A B : Ty Γ) → fst A == fst B → A == B
eqT (A , Γ⊢A) (.A , Γ⊢'A) idp = Σ= idp (has-all-paths-⊢T _ _)
eqt : ∀ {Γ A} (t u : Tm Γ A) → fst t == fst u → t == u
eqt (t , Γ⊢t:A) (.t , Γ⊢':A) idp = Σ= idp (has-all-paths-⊢t _ _)
eqS : ∀ {Γ Δ} (γ δ : Sub Γ Δ) → fst γ == fst δ → γ == δ
eqS (γ , Γ⊢γ:Δ) (.γ , Γ⊢'γ:Δ) idp = Σ= idp (has-all-paths-⊢S _ _)
trS : ∀ {Γ Δ Θ : Ctx} → (p : Δ == Θ) → {γ : Sub Γ Δ} → {δ : Sub Γ Θ} → fst γ == fst δ → transport p γ == δ
trS {Γ} {Δ} {Θ} idp {γ} {δ} x = eqS {Γ} {Θ} γ δ x
eqdec-Ty : ∀ Γ → eqdec (Ty Γ)
eqdec-Ty Γ (A , Γ⊢A) (B , Γ⊢B) with eqdec-PreTy A B
... | inl idp = inl (eqT {Γ} (A , Γ⊢A) (B , Γ⊢B) idp)
... | inr A≠B = inr λ p → A≠B (fst-is-inj p)
is-set-Ty : ∀ Γ → is-set (Ty Γ)
is-set-Ty Γ = eqdec-is-set (eqdec-Ty Γ)
| 32
| 108
| 0.497283
|
0e9b90e1cff47752e8d5e3241056316a6623cde0
| 13,698
|
agda
|
Agda
|
archive/agda-2/Oscar/Data/Permutation.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-2/Oscar/Data/Permutation.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-2/Oscar/Data/Permutation.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Oscar.Data.Permutation where
--open import Data.Permutation public
import Data.Permutation as P
open import Data.Permutation renaming (delete to deleteP; _∘_ to _∘P_; enum to allInj)
open import Oscar.Data.Vec renaming (delete to deleteV; map to mapV)
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Fin renaming (inject to injectF)
open ≡-Reasoning
open import Data.Permutation.Properties
open import Oscar.Data.Vec.Properties
open import Function
open import Data.Sum
open import Agda.Builtin.Nat
<>-inv : ∀ {n} (ps : Permutation n) i → i ≡ < ps > (< ps ⁻¹ > i)
<>-inv ps i =
trans
(sym (id-is-id i))
(subst (< P.id > _ ≡_)
(inj-correct (ps ⁻¹) ps i)
(cong (flip <_> _)
(sym (inv-left ps))))
_⋟_÷_ : ∀ {a m n} {A : Set a} → Vec A n → Vec A m → Inj m n → Set a
x ⋟ px ÷ p = ∀ i → lookup i px ≡ lookup (< p > i) x
lookup-ext : ∀ {a n} {A : Set a} {pv₁ pv₂ : Vec A n} → (∀ i → lookup i pv₁ ≡ lookup i pv₂) → pv₁ ≡ pv₂
lookup-ext {pv₁ = []} {[]} x = refl
lookup-ext {pv₁ = x₁ ∷ pv₁} {x₂ ∷ pv₂} x with lookup-ext {pv₁ = pv₁} {pv₂} (x ∘ suc) | x zero
… | refl | refl = refl
injected-inj : ∀ {a n m} {A : Set a} {v : Vec A m} {pv₁ pv₂ : Vec A n} {p : Inj n m} → v ⋟ pv₁ ÷ p → v ⋟ pv₂ ÷ p → pv₁ ≡ pv₂
injected-inj {pv₁ = pv₁} {pv₂} v⋟pv₁÷p v⋟pv₂÷p = lookup-ext foo where
foo : (i : Fin _) → lookup i pv₁ ≡ lookup i pv₂
foo i = trans (v⋟pv₁÷p i) (sym (v⋟pv₂÷p i))
permuted-inj : ∀ {a n} {A : Set a} {v : Vec A n} {pv₁ pv₂ : Vec A n} {p : Permutation n} → v ⋟ pv₁ ÷ p → v ⋟ pv₂ ÷ p → pv₁ ≡ pv₂
permuted-inj {pv₁ = pv₁} {pv₂} v⋟pv₁÷p v⋟pv₂÷p = lookup-ext foo where
foo : (i : Fin _) → lookup i pv₁ ≡ lookup i pv₂
foo i = trans (v⋟pv₁÷p i) (sym (v⋟pv₂÷p i))
permutedLookup : ∀ {a n} {A : Set a} → Permutation n → Vec A n → Fin n → A
permutedLookup p v = flip lookup v ∘ < p >
inject : ∀ {a n m} {A : Set a} → (p : Inj n m) → (v : Vec A m) → Vec A n
inject p v = tabulate (flip lookup v ∘ < p >)
permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) → Vec A n
permute p v = tabulate (flip lookup v ∘ < p >)
inject-correct : ∀ {a n m} {A : Set a} → (p : Inj n m) → (v : Vec A m) →
v ⋟ inject p v ÷ p
inject-correct p v = lookup∘tabulate (flip lookup v ∘ < p >)
permute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
v ⋟ permute p v ÷ p
permute-correct p v = lookup∘tabulate (flip lookup v ∘ < p >)
Permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
∃ (v ⋟_÷ p)
Permute p v = permute p v , permute-correct p v
_⋟_÷? : ∀ {a m n} {A : Set a} → Vec A n → Vec A m → Set a
_⋟_÷? x px = ∃ (x ⋟ px ÷_)
∈-allInj : ∀ {n m} (i : Inj n m) → i ∈ allInj n m
∈-allInj {zero} [] = here
∈-allInj {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-allInj is)
tabulate₂ : ∀ {n m a} {A : Set a} → (Inj n m → A) → Vec A (size n m)
tabulate₂ f = mapV f (allInj _ _)
∈-tabulate₂ : ∀ {n m a} {A : Set a} (f : Inj n m → A) i → f i ∈ tabulate₂ f
∈-tabulate₂ f i = ∈-map f (∈-allInj i)
ENUM₂ : ∀ {a n} {A : Set a} → (v : Vec A n) → Vec (∃ (v ⋟_÷?)) (size n n)
ENUM₂ v = tabulate₂ (λ p → permute p v , p , permute-correct p v)
enumᵢ : ∀ {a n m} {A : Set a} → Vec A m → Vec (Vec A n) (size n m)
enumᵢ v = tabulate₂ (flip inject v)
enum₂ : ∀ {a n} {A : Set a} → Vec A n → Vec (Vec A n) (size n n)
enum₂ v = tabulate₂ (flip permute v)
enumᵢ-sound : ∀ {a} {A : Set a} {n m} (x : Vec A m) (px : Vec A n) → px ∈ enumᵢ x → x ⋟ px ÷?
enumᵢ-sound x _ px∈enum₂x with map-∈ px∈enum₂x
enumᵢ-sound x _ _ | p , refl = p , inject-correct p x
enum₂-sound : ∀ {a} {A : Set a} {n} (x px : Vec A n) → px ∈ enum₂ x → x ⋟ px ÷?
enum₂-sound x _ px∈enum₂x with map-∈ px∈enum₂x
enum₂-sound x _ _ | p , refl = p , permute-correct p x
remove-÷-zero : ∀ {n a} {A : Set a} {x : A} {xs : Vec A n} {px : A}
{pxs : Vec A n} {ps : Inj n n} →
(x ∷ xs) ⋟ px ∷ pxs ÷ (zero ∷ ps) →
xs ⋟ pxs ÷ ps
remove-÷-zero f i = f (suc i)
enumᵢ-complete : ∀ {a} {A : Set a} {n m} (x : Vec A m) (px : Vec A n) → x ⋟ px ÷? → px ∈ enumᵢ x
enumᵢ-complete x px (p , x⋟px÷p) = proof where
p∈allInj : p ∈ allInj _ _
p∈allInj = ∈-allInj p
permutepx∈enum₂x : inject p x ∈ enumᵢ x
permutepx∈enum₂x = ∈-map (flip inject x) p∈allInj
x⋟permutepx÷p : x ⋟ inject p x ÷ p
x⋟permutepx÷p = inject-correct p x
proof : px ∈ enumᵢ x
proof = subst (_∈ _) (injected-inj {p = p} x⋟permutepx÷p x⋟px÷p) permutepx∈enum₂x
enum₂-complete : ∀ {a} {A : Set a} {n} (x px : Vec A n) → x ⋟ px ÷? → px ∈ enum₂ x
enum₂-complete x px (p , x⋟px÷p) = proof where
p∈allInj : p ∈ allInj _ _
p∈allInj = ∈-allInj p
permutepx∈enum₂x : permute p x ∈ enum₂ x
permutepx∈enum₂x = ∈-map (flip permute x) p∈allInj
x⋟permutepx÷p : x ⋟ permute p x ÷ p
x⋟permutepx÷p = permute-correct p x
proof : px ∈ enum₂ x
proof = subst (_∈ _) (permuted-inj {p = p} x⋟permutepx÷p x⋟px÷p) permutepx∈enum₂x
Enum₂ : ∀ {a n} {A : Set a} → (x : Vec A n) → Σ[ pxs ∈ Vec (Vec A n) (size n n) ] (∀ px → (px ∈ pxs → x ⋟ px ÷?) × (x ⋟ px ÷? → px ∈ pxs))
Enum₂ x = enum₂ x , (λ px → enum₂-sound x px , enum₂-complete x px)
_∃⊎∀_ : ∀ {a} {A : Set a} {l r} (L : A → Set l) (R : A → Set r) {p} (P : A → Set p) → Set _
(L ∃⊎∀ R) P = (∃ λ x → P x × L x) ⊎ (∀ x → P x → R x)
open import Agda.Primitive
stepDecide∃⊎∀ : ∀ {a} {A : Set a} {l r} {L : A → Set l} {R : A → Set r} → (∀ y → L y ⊎ R y) → ∀ {p} (P : A → Set p) →
∀ {d} (done : Vec A d) {nd} (not-done : Vec A nd) →
(∀ y → y ∈ done ⊎ y ∈ not-done → P y) →
(∀ y → P y → y ∈ done ⊎ y ∈ not-done) →
(∀ y → y ∈ done → R y) →
(L ∃⊎∀ R) P
stepDecide∃⊎∀ dec P done {zero} not-done dnd-sound dnd-complete done-R = inj₂ (λ y Py → done-R y (dnd-done y Py)) where
dnd-done : ∀ y → P y → y ∈ done
dnd-done y Py with dnd-complete y Py
dnd-done y Py | inj₁ y∈done = y∈done
dnd-done y Py | inj₂ ()
stepDecide∃⊎∀ dec P done {suc nd} (step ∷ not-dones) dnd-sound dnd-complete done-R with dec step
… | inj₁ l = inj₁ (step , (dnd-sound step (inj₂ here)) , l)
… | inj₂ r = stepDecide∃⊎∀ dec P (step ∷ done) not-dones stepdnd-sound stepdnd-complete (stepdone-R r) where
stepdnd-sound : ∀ y → y ∈ step ∷ done ⊎ y ∈ not-dones → P y
stepdnd-sound _ (inj₁ here) = dnd-sound step (inj₂ here)
stepdnd-sound y (inj₁ (there y∈done)) = dnd-sound y (inj₁ y∈done)
stepdnd-sound y (inj₂ y∈not-dones) = dnd-sound y (inj₂ (there y∈not-dones))
stepdnd-complete : ∀ y → P y → y ∈ step ∷ done ⊎ y ∈ not-dones
stepdnd-complete y Py with dnd-complete y Py
stepdnd-complete y Py | inj₁ y∈done = inj₁ (there y∈done)
stepdnd-complete y Py | inj₂ here = inj₁ here
stepdnd-complete y Py | inj₂ (there y∈not-dones) = inj₂ y∈not-dones
stepdone-R : _ → ∀ y → y ∈ step ∷ done → _
stepdone-R Rstep _ here = Rstep
stepdone-R Rstep y (there y∈done) = done-R y y∈done
decide∃⊎∀ : ∀ {a} {A : Set a} {l r} {L : A → Set l} {R : A → Set r} → (∀ y → L y ⊎ R y) → ∀ {p} (P : A → Set p) →
∀ {nd} (not-done : Vec A nd) →
(∀ y → y ∈ not-done → P y) →
(∀ y → P y → y ∈ not-done) →
(L ∃⊎∀ R) P
decide∃⊎∀ dec P not-done nd-sound nd-complete = stepDecide∃⊎∀ dec P [] not-done []nd-sound []nd-complete (λ {_ ()}) where
[]nd-sound : ∀ y → y ∈ [] ⊎ y ∈ not-done → P y
[]nd-sound y (inj₁ ())
[]nd-sound y (inj₂ y∈not-done) = nd-sound y y∈not-done
[]nd-complete : ∀ y → P y → y ∈ [] ⊎ y ∈ not-done
[]nd-complete y Py = inj₂ (nd-complete y Py)
decidePermutations : ∀ {a n} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ x → (∀ y → L y ⊎ R y) →
(L ∃⊎∀ R) (x ⋟_÷?)
decidePermutations x f = decide∃⊎∀ f _ (enum₂ x) (enum₂-sound x) (enum₂-complete x)
decideInjections : ∀ {a n m} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ (x : Vec A m) → (∀ y → L y ⊎ R y) →
(L ∃⊎∀ R) (x ⋟_÷?)
decideInjections x f = decide∃⊎∀ f _ (enumᵢ x) (enumᵢ-sound x) (enumᵢ-complete x)
-- -- sym-⋟∣ : ∀ {a n} {A : Set a} → (y x : Vec A n) → (p : Permutation n) →
-- -- y ⋟ x ∣ p → x ⋟ y ∣ (p ⁻¹)
-- -- sym-⋟∣ y x ps y⋟x∣p i =
-- -- trans (cong (flip lookup x) {x = i} {y = < ps > (< ps ⁻¹ > i)} (<>-inv ps i)) (sym (y⋟x∣p (< ps ⁻¹ > i)))
-- -- open import Oscar.Data.Vec.Properties
-- -- Permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
-- -- ∃ λ w → w ⋟ v ∥ p
-- -- Permute [] v = v , λ ()
-- -- Permute p@(p' ∷ ps) v@(v' ∷ vs) =
-- -- let ws , [vs≡ws]ps = Permute ps (deleteV p' v)
-- -- w = lookup p' v ∷ ws
-- -- [v≡w]p : w ⋟ v ∥ p
-- -- [v≡w]p = {!!}
-- -- {-
-- -- [v≡w]p = λ
-- -- { zero → here
-- -- ; (suc f) → there (subst (ws [ f ]=_)
-- -- (lookup-delete-thin p' (< ps > f) v)
-- -- ([vs≡ws]ps f)) }
-- -- -}
-- -- in
-- -- w , [v≡w]p
-- -- -- permute : ∀ {a n} {A : Set a} → Permutation n → Vec A n → Vec A n
-- -- -- permute p v = proj₁ (Permute p v)
-- -- -- permute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) → v ⋟ permute p v ∥ p
-- -- -- permute-correct p v = proj₂ (Permute p v)
-- -- -- open import Function
-- -- -- --∈-map-proj₁ : mapV proj₁ (mapV (λ p → F p , G p) xs) ≡ mapV F xs
-- -- -- open import Data.Nat
-- -- -- ∈-enum : ∀ {n m} (i : Inj n m) → i ∈ enum n m
-- -- -- ∈-enum {zero} [] = here
-- -- -- ∈-enum {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-enum is)
-- -- -- open import Data.Permutation.Properties
-- -- -- [thin]=→delete[]= : ∀ {a n} {A : Set a} {i j} {v : Vec A (suc n)} {x} → v [ thin i j ]= x → deleteV i v [ j ]= x
-- -- -- [thin]=→delete[]= {i = zero} {v = x ∷ v} (there x₂) = x₂
-- -- -- [thin]=→delete[]= {n = zero} {i = suc ()} x₁
-- -- -- [thin]=→delete[]= {n = suc n} {i = suc i} {zero} {x ∷ v} here = here
-- -- -- [thin]=→delete[]= {n = suc n} {i = suc i} {suc j} {x ∷ v} (there v[thinij]=?) = there ([thin]=→delete[]= {i = i} v[thinij]=?)
-- -- -- delete≡Permutation : ∀ {a n} {A : Set a} {v₀ : A} {v₊ : Vec A n} {w : Vec A (suc n)} {p : Permutation (suc n)} →
-- -- -- (v₀ ∷ v₊) ⋟ w ∥ p →
-- -- -- v₊ ⋟ deleteV (annihilator p) w ∥ delete (annihilator p) p
-- -- -- delete≡Permutation {v₀ = v₀} {v₊} {w} {p} [v₀∷v₊≡w]p f = [thin]=→delete[]= {i = annihilator p} {j = f} qux where
-- -- -- foo : thin (< p > (annihilator p)) (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)
-- -- -- foo = inj-thin p (annihilator p) f
-- -- -- foo2 : suc (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)
-- -- -- foo2 = subst (λ y → thin y (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)) (ann-correct p) foo
-- -- -- bar : w [ thin (annihilator p) f ]= lookup (< p > (thin (annihilator p) f)) (v₀ ∷ v₊)
-- -- -- bar = [v₀∷v₊≡w]p (thin (annihilator p) f)
-- -- -- qux : w [ thin (annihilator p) f ]= lookup (< delete (annihilator p) p > f) v₊
-- -- -- qux = subst (λ y → w [ thin (annihilator p) f ]= lookup y (v₀ ∷ v₊)) (sym foo2) bar
-- -- -- permute-complete-step : ∀ {a n} {A : Set a} {v₀ : A} {w : Vec A (suc n)} {v₊ : Vec A n} (x : Fin (suc n)) →
-- -- -- w [ x ]= v₀ →
-- -- -- deleteV x w ∈ mapV (flip permute v₊) (enum n n) →
-- -- -- w ∈ mapV (flip permute (v₀ ∷ v₊)) (enum (suc n) (suc n))
-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} zero here here = here
-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} zero x₁ (there ())
-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} (suc ()) x₁ x₂
-- -- -- permute-complete-step {n = suc n} {w = w ∷ ws} x w∷ws[x]=v₀ x₂ = {!!}
-- -- -- permute-lemma : ∀ {a n} {A : Set a} (v w : Vec A n) (p : Permutation n) →
-- -- -- v ⋟ w ∥ p →
-- -- -- w ≡ permute (p ⁻¹) v
-- -- -- permute-lemma v w p x = {!permute-correct p w!}
-- -- -- {-
-- -- -- permute-complete' : ∀ {a n} {A : Set a} (v w : Vec A n) (p : Permutation n) →
-- -- -- v ⋟ w ∥ p →
-- -- -- ∀ {m} {ps : Vec (Permutation n) m} → p ∈ ps →
-- -- -- w ≡ permute p v
-- -- -- w ∈ mapV (flip
-- -- -- -}
-- -- -- permute-complete : ∀ {a n} {A : Set a} (v w : Vec A n) →
-- -- -- v ∃≡Permutation w →
-- -- -- w ∈ mapV (flip permute v) (enum n n)
-- -- -- permute-complete [] [] (p , [v≡w]p) = here
-- -- -- permute-complete {n = suc n} v@(v₀ ∷ v₊) w (p , [v≡w]p) = permute-complete-step (annihilator p) w[ap]=v₀ pc' where
-- -- -- w[ap]=v₀ : w [ annihilator p ]= v₀
-- -- -- w[ap]=v₀ = {![v≡w]p (annihilator p)!}
-- -- -- pc' : deleteV (annihilator p) w ∈ mapV (flip permute v₊) (enum n n)
-- -- -- pc' = permute-complete v₊ (deleteV (annihilator p) w) (delete (annihilator p) p , delete≡Permutation {p = p} [v≡w]p)
-- -- -- EnumPermutations : ∀ {a n} {A : Set a} → (v : Vec A n) →
-- -- -- Σ (Vec (∃ (v ∃≡Permutation_)) (size n n)) λ ws
-- -- -- → ∀ w → (v ∃≡Permutation w → w ∈ mapV proj₁ ws)
-- -- -- EnumPermutations {n = n} v = mapV (λ p → permute p v , p , permute-correct p v) (enum n n) , (λ w v∃≡Pw → subst (w ∈_) (map-∘ proj₁ (λ p → permute p v , p , permute-correct p v) (enum n n)) (permute-complete v w v∃≡Pw))
-- -- -- enumPermutations : ∀ {a n} {A : Set a} → Vec A n → Vec (Vec A n) (size n n)
-- -- -- enumPermutations {n = n} xs = mapV (λ p → permute p xs) (enum n n)
-- -- -- tryPermutations : ∀ {a n} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ x → (f : ∀ y → L y ⊎ R y) → Vec (∃ λ y → x ∃≡Permutation y × L y ⊎ R y) (size n n)
-- -- -- tryPermutations x f = mapV (λ x₁ → x₁ , {!!}) (enumPermutations x)
| 46.433898
| 228
| 0.501533
|
389c76603898928d22b4a3c0a501a8a294369d00
| 7,193
|
agda
|
Agda
|
homotopy/CoverClassification.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/CoverClassification.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/CoverClassification.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.RibbonCover
module homotopy.CoverClassification {i} (A∙ : Ptd i)
(A-conn : is-connected ⟨0⟩ (fst A∙)) where
open Cover
private
A : Type i
A = fst A∙
a₁ : A
a₁ = snd A∙
π1A = fundamental-group A∙
-- A covering space constructed from a G-set.
gset-to-cover : ∀ {j} → Gset π1A j → Cover A (lmax i j)
gset-to-cover gs = Ribbon-cover A∙ gs
-- Covering spaces to G-sets.
cover-to-gset-struct : ∀ {j} (cov : Cover A j)
→ GsetStructure π1A (Fiber cov a₁) (Fiber-is-set cov a₁)
cover-to-gset-struct cov = record
{ act = cover-trace cov
; unit-r = cover-trace-idp₀ cov
; assoc = cover-paste cov
}
cover-to-gset : ∀ {j} → Cover A j → Gset π1A j
cover-to-gset cov = record
{ El = Fiber cov a₁
; El-level = Fiber-level cov a₁
; gset-struct = cover-to-gset-struct cov
}
-- This is derivable from connectedness condition.
module _ where
abstract
[base-path] : ∀ {a₂ : A} → Trunc ⟨-1⟩ (a₁ == a₂)
[base-path] {a₂} =
–> (Trunc=-equiv [ a₁ ] [ a₂ ]) (contr-has-all-paths A-conn [ a₁ ] [ a₂ ])
-- Part 1: Show that the synthesized cover (ribbon) is fiberwisely
-- equivalent to the original fiber.
private
module _ {j} (cov : Cover A j) where
-- Suppose that we get the path, we can compute the ribbon easily.
fiber+path-to-ribbon : ∀ {a₂} (a↑ : Fiber cov a₂) (p : a₁ == a₂)
→ Ribbon A∙ (cover-to-gset cov) a₂
fiber+path-to-ribbon {a₂} a↑ p =
trace (cover-trace cov a↑ [ ! p ]) [ p ]
abstract
-- Our construction is "constant" with respect to paths.
fiber+path-to-ribbon-is-path-irrelevant :
∀ {a₂} (a↑ : Fiber cov a₂) (p₁ p₂ : a₁ == a₂)
→ fiber+path-to-ribbon a↑ p₁ == fiber+path-to-ribbon a↑ p₂
fiber+path-to-ribbon-is-path-irrelevant a↑ p idp =
trace (cover-trace cov a↑ [ ! p ]) [ p ]
=⟨ paste a↑ [ ! p ] [ p ] ⟩
trace a↑ [ ! p ∙ p ]
=⟨ ap (trace a↑) $ !₀-inv-l [ p ] ⟩
trace a↑ idp₀
∎
open import homotopy.ConstantToSetFactorization
fiber+path₋₁-to-ribbon : ∀ {a₂} (a↑ : Cover.Fiber cov a₂)
→ Trunc ⟨-1⟩ (a₁ == a₂) → Ribbon A∙ (cover-to-gset cov) a₂
fiber+path₋₁-to-ribbon a↑ = cst-extend
Ribbon-is-set
(fiber+path-to-ribbon a↑)
(fiber+path-to-ribbon-is-path-irrelevant a↑)
-- So the conversion from fiber to ribbon is done.
fiber-to-ribbon : ∀ {j} (cov : Cover A j)
→ {a₂ : A} (a↑ : Cover.Fiber cov a₂)
→ Ribbon A∙ (cover-to-gset cov) a₂
fiber-to-ribbon cov a↑ = fiber+path₋₁-to-ribbon cov a↑ [base-path]
-- The other direction is easy.
ribbon-to-fiber : ∀ {j} (cov : Cover A j) {a₂}
→ Ribbon A∙ (cover-to-gset cov) a₂ → Cover.Fiber cov a₂
ribbon-to-fiber cov {a₂} r =
Ribbon-rec (Fiber-is-set cov a₂) (cover-trace cov) (cover-paste cov) r
private
-- Some routine computations.
abstract
ribbon-to-fiber-to-ribbon : ∀ {j} (cov : Cover A j) {a₂}
→ (r : Ribbon A∙ (cover-to-gset cov) a₂)
→ fiber-to-ribbon cov (ribbon-to-fiber cov r) == r
ribbon-to-fiber-to-ribbon cov {a₂} = Ribbon-elim
{P = λ r → fiber-to-ribbon cov (ribbon-to-fiber cov r) == r}
(λ {_} → =-preserves-set Ribbon-is-set)
(λ a↑ p → Trunc-elim
-- All ugly things will go away when bp = proj bp′
(λ bp → Ribbon-is-set
(fiber+path₋₁-to-ribbon cov (cover-trace cov a↑ p) bp)
(trace a↑ p))
(lemma a↑ p)
[base-path])
(λ _ _ _ → prop-has-all-paths-↓ (Ribbon-is-set _ _))
where
abstract
lemma : ∀ {a₂} (a↑ : Cover.Fiber cov a₁) (p : a₁ =₀ a₂) (bp : a₁ == a₂)
→ trace {A∙ = A∙} {gs = cover-to-gset cov}
(cover-trace cov (cover-trace cov a↑ p) [ ! bp ]) [ bp ]
== trace {A∙ = A∙} {gs = cover-to-gset cov} a↑ p
lemma a↑ p idp =
trace (cover-trace cov a↑ p) idp₀
=⟨ paste a↑ p idp₀ ⟩
trace a↑ (p ∙₀ idp₀)
=⟨ ap (trace a↑) $ ∙₀-unit-r p ⟩
trace a↑ p
∎
fiber-to-ribbon-to-fiber : ∀ {j} (cov : Cover A j) {a₂}
→ (a↑ : Cover.Fiber cov a₂)
→ ribbon-to-fiber cov (fiber-to-ribbon cov {a₂} a↑) == a↑
fiber-to-ribbon-to-fiber cov {a₂} a↑ = Trunc-elim
-- All ugly things will go away when bp = proj bp′
(λ bp → Cover.Fiber-is-set cov a₂
(ribbon-to-fiber cov
(fiber+path₋₁-to-ribbon cov a↑ bp))
a↑)
(lemma a↑)
[base-path]
where
abstract
lemma : ∀ {a₂} (a↑ : Cover.Fiber cov a₂) (bp : a₁ == a₂)
→ cover-trace cov (cover-trace cov a↑ [ ! bp ]) [ bp ]
== a↑
lemma a↑ idp = idp
cover-to-gset-to-cover : ∀ {j} (cov : Cover A (lmax i j))
→ gset-to-cover (cover-to-gset cov) == cov
cover-to-gset-to-cover cov = cover= λ _ →
ribbon-to-fiber cov , is-eq
(ribbon-to-fiber cov)
(fiber-to-ribbon cov)
(fiber-to-ribbon-to-fiber cov)
(ribbon-to-fiber-to-ribbon cov)
-- The second direction : gset -> covering -> gset
-- Part 2.1: The fiber over the point a is the carrier.
ribbon-a₁-to-El : ∀ {j} {gs : Gset π1A j}
→ Ribbon A∙ gs a₁ → Gset.El gs
ribbon-a₁-to-El {j} {gs} = let open Gset gs in
Ribbon-rec El-level act assoc
ribbon-a₁-to-El-equiv : ∀ {j} {gs : Gset π1A j}
→ Ribbon A∙ gs a₁ ≃ Gset.El gs
ribbon-a₁-to-El-equiv {j} {gs} = let open Gset gs in
ribbon-a₁-to-El , is-eq _
(λ r → trace r idp₀)
(λ a↑ → unit-r a↑)
(Ribbon-elim
{P = λ r → trace (ribbon-a₁-to-El r) idp₀ == r}
(=-preserves-set Ribbon-is-set)
(λ y p →
trace (act y p) idp₀
=⟨ paste y p idp₀ ⟩
trace y (p ∙₀ idp₀)
=⟨ ap (trace y) $ ∙₀-unit-r p ⟩
trace y p
∎)
(λ _ _ _ → prop-has-all-paths-↓ (Ribbon-is-set _ _)))
gset-to-cover-to-gset : ∀ {j} (gs : Gset π1A (lmax i j))
→ cover-to-gset (gset-to-cover gs) == gs
gset-to-cover-to-gset gs =
gset=
ribbon-a₁-to-El-equiv
(λ {x₁}{x₂} x= → Trunc-elim (λ _ → =-preserves-set $ Gset.El-is-set gs) λ g →
ribbon-a₁-to-El (transport (Ribbon A∙ gs) g x₁)
=⟨ ap (λ x → ribbon-a₁-to-El (transport (Ribbon A∙ gs) g x))
$ ! $ <–-inv-l ribbon-a₁-to-El-equiv x₁ ⟩
ribbon-a₁-to-El (transport (Ribbon A∙ gs) g (trace (ribbon-a₁-to-El x₁) idp₀))
=⟨ ap (λ x → ribbon-a₁-to-El (transport (Ribbon A∙ gs) g (trace x idp₀))) x= ⟩
ribbon-a₁-to-El (transport (Ribbon A∙ gs) g (trace x₂ idp₀))
=⟨ ap ribbon-a₁-to-El $ trans-trace g x₂ idp₀ ⟩
Gset.act gs x₂ [ g ]
∎)
-- Finally...
gset-to-cover-equiv : ∀ {j}
→ Gset π1A (lmax i j) ≃ Cover A (lmax i j)
gset-to-cover-equiv {j} =
gset-to-cover , is-eq
_
(λ c → cover-to-gset c)
(λ c → cover-to-gset-to-cover {lmax i j} c)
(gset-to-cover-to-gset {lmax i j})
| 36.145729
| 88
| 0.528847
|
2eb8cd6c2dcfb13a3500cbc7b85322003cfa1dc2
| 408
|
agda
|
Agda
|
testData/parse/agda/records.agda
|
ice1000/intellij-minitt
|
7e601041978a0497db7d4cf3bcf4971f532235cd
|
[
"Apache-2.0"
] | 30
|
2019-05-11T16:26:38.000Z
|
2022-01-29T13:18:34.000Z
|
testData/parse/agda/records.agda
|
ice1000/intellij-minitt
|
7e601041978a0497db7d4cf3bcf4971f532235cd
|
[
"Apache-2.0"
] | 16
|
2019-03-30T04:29:32.000Z
|
2021-03-15T17:04:36.000Z
|
testData/parse/agda/records.agda
|
owo-lang/intellij-owo
|
7e601041978a0497db7d4cf3bcf4971f532235cd
|
[
"Apache-2.0"
] | 3
|
2019-10-07T01:38:12.000Z
|
2021-03-12T21:33:35.000Z
|
--
-- Created by Dependently-Typed Lambda Calculus on 2019-05-15
-- records
-- Author: ice10
--
{-# OPTIONS --without-K --safe #-}
record List (A : Set) : Set where
coinductive
field
head : A
tail : List A
open List
-- | Bisimulation as equality
record _==_ (x : List A) (y : List A) : Set where
coinductive
field
refl-head : head x ≡ head y
refl-tail : tail x == tail y
open _==_
| 17.73913
| 61
| 0.622549
|
061b75c72676979b98dd5d943097984987a1546f
| 2,913
|
agda
|
Agda
|
src/sets/int/definition.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 20
|
2015-06-12T12:20:17.000Z
|
2022-02-01T11:25:54.000Z
|
src/sets/int/definition.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
src/sets/int/definition.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T12:17:00.000Z
|
2019-05-04T19:31:00.000Z
|
{-# OPTIONS --without-K #-}
module sets.int.definition where
open import sum
open import equality
open import function
open import sets.nat.core
open import hott.level
private
data Z : Set where
mk-int : ℕ → ℕ → Z
ℤ : Set
ℤ = Z
_[-]_ : ℕ → ℕ → ℤ
_[-]_ = mk-int
postulate
eq-ℤ : (n m d : ℕ) → n [-] m ≡ (d + n) [-] (d + m)
hℤ : h 2 ℤ
IsAlg-ℤ : ∀ {i} → Set i → Set _
IsAlg-ℤ X = Σ (ℕ → ℕ → X) λ f
→ (∀ n m d → f n m ≡ f (d + n) (d + m))
aℤ : IsAlg-ℤ ℤ
aℤ = _[-]_ , eq-ℤ
map-Alg-ℤ : ∀ {i j}{X : Set i}{Y : Set j}
→ (X → Y) → IsAlg-ℤ X → IsAlg-ℤ Y
map-Alg-ℤ {X = X}{Y} h (f , u) = (g , v)
where
g : ℕ → ℕ → Y
g n m = h (f n m)
v : ∀ n m d → g n m ≡ g (d + n) (d + m)
v n m d = ap h (u n m d)
map-Alg-ℤ-id : ∀ {i}{X : Set i}(aX : IsAlg-ℤ X)
→ map-Alg-ℤ (λ x → x) aX ≡ aX
map-Alg-ℤ-id aX = unapΣ (refl ,
funext λ n → funext λ m → funext λ d → ap-id _)
map-Alg-ℤ-hom : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k}
→ (f : Y → Z)(g : X → Y)(aX : IsAlg-ℤ X)
→ map-Alg-ℤ (f ∘' g) aX
≡ map-Alg-ℤ f (map-Alg-ℤ g aX)
map-Alg-ℤ-hom f g aX = unapΣ (refl , funext λ n → funext λ m → funext λ d
→ sym (ap-hom g f _))
Hom-ℤ : ∀ {i j}{X : Set i}{Y : Set j}
→ IsAlg-ℤ X → IsAlg-ℤ Y → Set _
Hom-ℤ {X = X}{Y} aX aY = Σ (X → Y) λ h → map-Alg-ℤ h aX ≡ aY
id-ℤ : ∀ {i}{X : Set i}(aX : IsAlg-ℤ X) → Hom-ℤ aX aX
id-ℤ aX = (λ x → x) , map-Alg-ℤ-id aX
_⋆ℤ_ : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k}
→ {aX : IsAlg-ℤ X}{aY : IsAlg-ℤ Y}{aZ : IsAlg-ℤ Z}
→ Hom-ℤ aY aZ → Hom-ℤ aX aY → Hom-ℤ aX aZ
_⋆ℤ_ {aX = aX} (f , u) (g , v) = f ∘' g , map-Alg-ℤ-hom f g aX · ap (map-Alg-ℤ f) v · u
module _ {i}{X : Set i}(hX : h 2 X)(aX : IsAlg-ℤ X) where
elim-ℤ : ℤ → X
elim-ℤ (mk-int n n') = proj₁ aX n n'
postulate elim-β-ℤ : ∀ n m d → ap elim-ℤ (eq-ℤ n m d) ≡ proj₂ aX n m d
elim-Alg-β-ℤ : map-Alg-ℤ elim-ℤ aℤ ≡ aX
elim-Alg-β-ℤ = unapΣ (refl , funext λ n → funext λ m → funext λ d → elim-β-ℤ n m d)
elim-Alg-ℤ : Hom-ℤ aℤ aX
elim-Alg-ℤ = elim-ℤ , elim-Alg-β-ℤ
postulate univ-ℤ : (h : Hom-ℤ aℤ aX) → elim-Alg-ℤ ≡ h
Hom-ℤ-contr : contr (Hom-ℤ aℤ aX)
Hom-ℤ-contr = elim-Alg-ℤ , univ-ℤ
elim-prop-ℤ : ∀ {i}{X : ℤ → Set i} → (∀ n → h 1 (X n))
→ (f : ∀ n m → X (n [-] m))
→ ∀ n → X n
elim-prop-ℤ {X = X} hX f n = subst X (i-β₀ n) (proj₂ (s₀ n))
where
Y : Set _
Y = Σ ℤ X
hY : h 2 Y
hY = Σ-level hℤ λ n → h↑ (hX n)
aY : IsAlg-ℤ Y
aY = (λ n m → (n [-] m , f n m))
, (λ n m d → unapΣ (eq-ℤ n m d , h1⇒prop (hX ((d + n) [-] (d + m))) _ _))
pY : Hom-ℤ aY aℤ
pY = proj₁ , unapΣ (refl , h1⇒prop
(Π-level λ n → Π-level λ m → Π-level λ p → hℤ _ _) _ _)
s : Hom-ℤ aℤ aY
s = elim-Alg-ℤ hY aY
s₀ : ℤ → Y
s₀ = proj₁ s
i-β₀ : ∀ n → proj₁ (s₀ n) ≡ n
i-β₀ n = ap (λ f → proj₁ f n)
(contr⇒prop (Hom-ℤ-contr hℤ aℤ) (pY ⋆ℤ s) (id-ℤ aℤ))
| 26.008929
| 87
| 0.472365
|
9ae7d127a7998a3d1ff23c8b7f882c18c9e81fa1
| 3,111
|
agda
|
Agda
|
Cubical/Structures/Monoid.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Monoid.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Monoid.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.Monoid where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_)
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Structures.Pointed
open import Cubical.Structures.InftyMagma
private
variable
ℓ : Level
-- Now we're getting serious: Monoids
raw-monoid-structure : Type ℓ → Type ℓ
raw-monoid-structure X = X × (X → X → X)
raw-monoid-iso : StrIso raw-monoid-structure ℓ
raw-monoid-iso (M , e , _·_) (N , d , _∗_) f =
(equivFun f e ≡ d)
× ((x y : M) → equivFun f (x · y) ≡ (equivFun f x) ∗ (equivFun f y))
-- If we ignore the axioms we get something like a "raw" monoid, which
-- essentially is the join of a pointed type and an ∞-magma
raw-monoid-is-SNS : SNS {ℓ} raw-monoid-structure raw-monoid-iso
raw-monoid-is-SNS = join-SNS pointed-structure pointed-iso pointed-is-SNS
∞-magma-structure ∞-magma-iso ∞-magma-is-SNS
-- Now define monoids
monoid-axioms : (X : Type ℓ) → raw-monoid-structure X → Type ℓ
monoid-axioms X (e , _·_ ) = isSet X
× ((x y z : X) → (x · (y · z)) ≡ ((x · y) · z))
× ((x : X) → (x · e) ≡ x)
× ((x : X) → (e · x) ≡ x)
monoid-structure : Type ℓ → Type ℓ
monoid-structure = add-to-structure (raw-monoid-structure) monoid-axioms
Monoids : Type (ℓ-suc ℓ)
Monoids {ℓ} = TypeWithStr ℓ monoid-structure
monoid-iso : StrIso monoid-structure ℓ
monoid-iso = add-to-iso raw-monoid-structure raw-monoid-iso monoid-axioms
-- We have to show that the monoid axioms are indeed propositions
monoid-axioms-are-Props : (X : Type ℓ) (s : raw-monoid-structure X) → isProp (monoid-axioms X s)
monoid-axioms-are-Props X (e , _·_) s = β s
where
α = s .fst
-- TODO: it would be nice to have versions of this lemmas for higher arities
β = isPropΣ isPropIsSet
λ _ → isPropΣ (isPropPi (λ x → isPropPi (λ y → isPropPi (λ z → α (x · (y · z)) ((x · y) · z)))))
λ _ → isPropΣ (isPropPi (λ x → α (x · e) x))
λ _ → isPropPi (λ x → α (e · x) x)
monoid-is-SNS : SNS {ℓ} monoid-structure monoid-iso
monoid-is-SNS = add-axioms-SNS raw-monoid-structure raw-monoid-iso
monoid-axioms monoid-axioms-are-Props raw-monoid-is-SNS
MonoidPath : (M N : Monoids {ℓ}) → (M ≃[ monoid-iso ] N) ≃ (M ≡ N)
MonoidPath M N = SIP monoid-structure monoid-iso monoid-is-SNS M N
-- Added for groups
-- If there exists a inverse of an element it is unique
inv-lemma : (X : Type ℓ) (e : X) (_·_ : X → X → X)
→ monoid-axioms X (e , _·_)
→ (x y z : X)
→ y · x ≡ e
→ x · z ≡ e
→ y ≡ z
inv-lemma X e _·_ (is-set-X , assoc , runit , lunit) x y z left-inverse right-inverse =
y ≡⟨ sym (runit y) ⟩
y · e ≡⟨ cong (y ·_) (sym right-inverse) ⟩
y · (x · z) ≡⟨ assoc y x z ⟩
(y · x) · z ≡⟨ cong (_· z) left-inverse ⟩
e · z ≡⟨ lunit z ⟩
z ∎
| 37.481928
| 101
| 0.601414
|
58d75389ba2bca89c57ea3ec04fe04305e7f2dd3
| 1,069
|
agda
|
Agda
|
homotopy/PathSetIsInital.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/PathSetIsInital.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
homotopy/PathSetIsInital.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
module homotopy.PathSetIsInital {i} (A : Type i)
-- (A-conn : is-connected ⟨0⟩ A)
where
open Cover
module _
(a₁ : A)
-- And an arbitrary covering.
{k} (cov : Cover A k)
-- (cov-conn : is-connected ⟨0⟩ (Cover.TotalSpace cov))
(a↑₁ : Fiber cov a₁)
where
private
univ-cover = path-set-cover ⊙[ A , a₁ ]
-- Weak initiality by transport.
quotient-cover : CoverHom univ-cover cov
quotient-cover _ p = cover-trace cov a↑₁ p
-- Strong initiality by path induction.
module Uniqueness
(cover-hom : CoverHom univ-cover cov)
(pres-a↑₁ : cover-hom a₁ idp₀ == a↑₁)
where
private
lemma₁ : ∀ a p → cover-hom a [ p ] == quotient-cover a [ p ]
lemma₁ ._ idp = pres-a↑₁
lemma₂ : ∀ a p → cover-hom a p == quotient-cover a p
lemma₂ a = Trunc-elim
(λ p → =-preserves-level ⟨0⟩ (Cover.Fiber-level cov a))
(lemma₁ a)
theorem : cover-hom == quotient-cover
theorem = λ= λ a → λ= $ lemma₂ a
| 24.860465
| 68
| 0.570627
|
29e771d39f88ed66a011206d635ca9eac3a88909
| 897
|
agda
|
Agda
|
Type/Identity.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Type/Identity.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Type/Identity.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Type.Identity where
import Lvl
open import Type
private variable ℓ : Lvl.Level
private variable T : Type{ℓ}
-- Identity type.
-- Also called: Propositional equality.
-- Two terms are identical/equal when their data representation are the same.
data Id {T : Type{ℓ}} : T → T → Type{ℓ} where
instance intro : ∀{x : T} → Id x x
-- Interpretation:
-- The only way to construct something of type Id is to use identical objects for both arguments.
-- When matching on the constructor, the type checker "unifies" the two terms making them the same.
-- This is how the builtin pattern matching by intro works, and therefore many propositions for identity becomes "trivial" syntactically.
{-# BUILTIN EQUALITY Id #-}
{-# BUILTIN REWRITE Id #-}
elim : (P : ∀{x y : T} → (Id x y) → Type{ℓ}) → (∀{x} → P(intro{x = x})) → (∀{x y} → (eq : (Id x y)) → P(eq))
elim _ p intro = p
| 37.375
| 141
| 0.670011
|
cb9287e951298f7a1571cb90cad92433c2fd7f47
| 15,572
|
agda
|
Agda
|
src/Lambda/Compiler-correctness/Steps-match.agda
|
nad/definitional-interpreters
|
dec8cd2d2851340840de25acb0feb78f7b5ffe96
|
[
"MIT"
] | null | null | null |
src/Lambda/Compiler-correctness/Steps-match.agda
|
nad/definitional-interpreters
|
dec8cd2d2851340840de25acb0feb78f7b5ffe96
|
[
"MIT"
] | null | null | null |
src/Lambda/Compiler-correctness/Steps-match.agda
|
nad/definitional-interpreters
|
dec8cd2d2851340840de25acb0feb78f7b5ffe96
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The "time complexity" of the compiled program matches the one
-- obtained from the instrumented interpreter
------------------------------------------------------------------------
open import Prelude hiding (_+_; _*_)
import Lambda.Syntax
module Lambda.Compiler-correctness.Steps-match
{Name : Type}
(open Lambda.Syntax Name)
(def : Name → Tm 1)
where
import Equality.Propositional as E
open import Logical-equivalence using (_⇔_)
import Tactic.By.Propositional as By
open import Prelude.Size
open import Conat E.equality-with-J as Conat
using (Conat; zero; suc; force; ⌜_⌝; _+_; _*_; max;
[_]_≤_; step-≤; step-∼≤; _∎≤)
open import Function-universe E.equality-with-J hiding (_∘_)
open import List E.equality-with-J using (_++_)
open import Monad E.equality-with-J using (return; _>>=_; _⟨$⟩_)
open import Vec.Data E.equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Delay-monad.Quantitative-weak-bisimilarity
open import Lambda.Compiler def
open import Lambda.Delay-crash
open import Lambda.Interpreter.Steps def
open import Lambda.Virtual-machine.Instructions Name hiding (crash)
open import Lambda.Virtual-machine comp-name
private
module C = Closure Code
module T = Closure Tm
------------------------------------------------------------------------
-- Some lemmas
-- A rearrangement lemma for ⟦_⟧.
⟦⟧-· :
∀ {n} (t₁ t₂ : Tm n) {ρ} {k : T.Value → Delay-crash C.Value ∞} →
⟦ t₁ · t₂ ⟧ ρ >>= k ∼
⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k
⟦⟧-· t₁ t₂ {ρ} {k} =
⟦ t₁ · t₂ ⟧ ρ >>= k ∼⟨⟩
(do v₁ ← ⟦ t₁ ⟧ ρ
v₂ ← ⟦ t₂ ⟧ ρ
v₁ ∙ v₂) >>= k ∼⟨ symmetric (associativity (⟦ t₁ ⟧ _) _ _) ⟩
(do v₁ ← ⟦ t₁ ⟧ ρ
(do v₂ ← ⟦ t₂ ⟧ ρ
v₁ ∙ v₂) >>= k) ∼⟨ (⟦ t₁ ⟧ _ ∎) >>=-cong (λ _ → symmetric (associativity (⟦ t₂ ⟧ _) _ _)) ⟩
(do v₁ ← ⟦ t₁ ⟧ ρ
v₂ ← ⟦ t₂ ⟧ ρ
v₁ ∙ v₂ >>= k) ∎
-- Lemmas related to conatural numbers.
private
lemma₁ : ∀ {δ} → [ ∞ ] δ ≤ ⌜ 1 ⌝ + δ
lemma₁ = Conat.≤suc
lemma₂ : ∀ {δ} → [ ∞ ] δ ≤ max ⌜ 1 ⌝ δ
lemma₂ = Conat.ʳ≤max ⌜ 1 ⌝ _
lemma₃ : ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ δ ≤ max ⌜ 1 ⌝ δ + ⌜ 1 ⌝
lemma₃ = Conat.m≤m+n
lemma₄ : ∀ {δ} → [ ∞ ] δ ≤ max ⌜ 1 ⌝ δ + ⌜ 1 ⌝
lemma₄ {δ} =
δ ≤⟨ lemma₂ ⟩
max ⌜ 1 ⌝ δ ≤⟨ lemma₃ {δ = δ} ⟩
max ⌜ 1 ⌝ δ + ⌜ 1 ⌝ ∎≤
lemma₅ : ∀ {δ} → [ ∞ ] ⌜ 1 ⌝ + δ ≤ δ + ⌜ 1 ⌝
lemma₅ {δ} =
⌜ 1 ⌝ + δ ∼⟨ Conat.+-comm ⌜ 1 ⌝ ⟩≤
δ + ⌜ 1 ⌝ ∎≤
lemma₆ : ∀ {δ} → [ ∞ ] ⌜ 1 ⌝ + δ ≤ max ⌜ 1 ⌝ δ + ⌜ 1 ⌝
lemma₆ {δ} =
⌜ 1 ⌝ + δ ≤⟨ lemma₅ ⟩
δ + ⌜ 1 ⌝ ≤⟨ lemma₂ Conat.+-mono (⌜ 1 ⌝ ∎≤) ⟩
max ⌜ 1 ⌝ δ + ⌜ 1 ⌝ ∎≤
lemma₇ : ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ (⌜ 1 ⌝ + δ) ≤ ⌜ 1 ⌝ + δ
lemma₇ {δ} = suc λ { .force →
δ ∎≤ }
lemma₈ : ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ) ≤ max ⌜ 1 ⌝ δ
lemma₈ {δ} = suc λ { .force →
Conat.pred δ ∎≤ }
lemma₉ :
∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ (max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ)) ≤ max ⌜ 1 ⌝ δ
lemma₉ {δ} =
max ⌜ 1 ⌝ (max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ)) ≤⟨ lemma₈ ⟩
max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ) ≤⟨ lemma₈ ⟩
max ⌜ 1 ⌝ δ ∎≤
lemma₁₀ : ∀ {δ} → [ ∞ ] ⌜ 1 ⌝ + ⌜ 0 ⌝ ≤ max ⌜ 1 ⌝ δ
lemma₁₀ = suc λ { .force → zero }
lemma₁₁ : Conat.[ ∞ ] max ⌜ 1 ⌝ ⌜ 1 ⌝ ∼ ⌜ 1 ⌝
lemma₁₁ = suc λ { .force → zero }
lemma₁₂ : Conat.[ ∞ ] ⌜ 1 ⌝ + ⌜ 1 ⌝ ∼ ⌜ 2 ⌝
lemma₁₂ = Conat.symmetric-∼ (Conat.⌜⌝-+ 1)
------------------------------------------------------------------------
-- Well-formed continuations and stacks
-- A continuation is OK with respect to a certain state and conatural
-- number if the following property is satisfied.
Cont-OK :
Size → State → (T.Value → Delay-crash C.Value ∞) → Conat ∞ → Type
Cont-OK i ⟨ c , s , ρ ⟩ k δ =
∀ v → [ i ∣ ⌜ 1 ⌝ ∣ δ ] exec ⟨ c , val (comp-val v) ∷ s , ρ ⟩ ≳ k v
-- If the In-tail-context parameter indicates that we are in a tail
-- context, then the stack must have a certain shape, and it must be
-- related to the continuation and the conatural number in a certain
-- way.
data Stack-OK
(i : Size) (k : T.Value → Delay-crash C.Value ∞) (δ : Conat ∞) :
In-tail-context → Stack → Type where
unrestricted : ∀ {s} → Stack-OK i k δ false s
restricted : ∀ {s n} {c : Code n} {ρ : C.Env n} →
Cont-OK i ⟨ c , s , ρ ⟩ k δ →
Stack-OK i k δ true (ret c ρ ∷ s)
-- A lemma that can be used to show that certain stacks are OK.
ret-ok :
∀ {p i s n c} {ρ : C.Env n} {k δ} →
Cont-OK i ⟨ c , s , ρ ⟩ k δ →
Stack-OK i k (⌜ 1 ⌝ + δ) p (ret c ρ ∷ s)
ret-ok {true} c-ok = restricted (weakenˡ lemma₁ ∘ c-ok)
ret-ok {false} _ = unrestricted
------------------------------------------------------------------------
-- The semantics of the compiled program matches that of the source
-- code
mutual
-- Some lemmas making up the main part of the compiler correctness
-- result.
⟦⟧-correct :
∀ {i n} (t : Tm n) (ρ : T.Env n) {c s}
{k : T.Value → Delay-crash C.Value ∞} {tc δ} →
Stack-OK i k δ tc s →
Cont-OK i ⟨ c , s , comp-env ρ ⟩ k δ →
[ i ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ δ ]
exec ⟨ comp tc t c , s , comp-env ρ ⟩ ≳ ⟦ t ⟧ ρ >>= k
⟦⟧-correct (var x) ρ {c} {s} {k} _ c-ok =
exec ⟨ var x ∷ c , s , comp-env ρ ⟩ ≳⟨ later (λ { .force →
exec ⟨ c , val By.⟨ index (comp-env ρ) x ⟩ ∷ s , comp-env ρ ⟩ ≡⟨ By.⟨by⟩ (comp-index ρ x) ⟩ˢ
exec ⟨ c , val (comp-val (index ρ x)) ∷ s , comp-env ρ ⟩ ≳⟨ weakenˡ lemma₄ (c-ok (index ρ x)) ⟩ˢ
k (index ρ x) ∎ }) ⟩ˢ
⟦ var x ⟧ ρ >>= k ∎
⟦⟧-correct (lam t) ρ {c} {s} {k} _ c-ok =
exec ⟨ clo (comp-body t) ∷ c , s , comp-env ρ ⟩ ≳⟨ later (λ { .force →
exec ⟨ c , val (comp-val (T.lam t ρ)) ∷ s , comp-env ρ ⟩ ≳⟨ weakenˡ lemma₄ (c-ok (T.lam t ρ)) ⟩ˢ
k (T.lam t ρ) ∎ }) ⟩ˢ
⟦ lam t ⟧ ρ >>= k ∎
⟦⟧-correct (t₁ · t₂) ρ {c} {s} {k} _ c-ok =
exec ⟨ comp false t₁ (comp false t₂ (app ∷ c))
, s
, comp-env ρ
⟩ ≳⟨ weakenˡ lemma₉ (⟦⟧-correct t₁ _ unrestricted λ v₁ →
exec ⟨ comp false t₂ (app ∷ c)
, val (comp-val v₁) ∷ s
, comp-env ρ
⟩ ≳⟨ (⟦⟧-correct t₂ _ unrestricted λ v₂ →
exec ⟨ app ∷ c
, val (comp-val v₂) ∷ val (comp-val v₁) ∷ s
, comp-env ρ
⟩ ≳⟨ ∙-correct v₁ v₂ c-ok ⟩ˢ
v₁ ∙ v₂ >>= k ∎) ⟩ˢ
(⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ∎) ⟩ˢ
(⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ∼⟨ symmetric (⟦⟧-· t₁ t₂) ⟩
⟦ t₁ · t₂ ⟧ ρ >>= k ∎
⟦⟧-correct (call f t) ρ {c} {s} {k} unrestricted c-ok =
exec ⟨ comp false (call f t) c , s , comp-env ρ ⟩ ∼⟨⟩ˢ
exec ⟨ comp false t (cal f ∷ c) , s , comp-env ρ ⟩ ≳⟨ (⟦⟧-correct t _ unrestricted λ v →
exec ⟨ cal f ∷ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳⟨ (later λ { .force → weakenˡ lemma₅ (
exec ⟨ comp-name f
, ret c (comp-env ρ) ∷ s
, comp-val v ∷ []
⟩ ≳⟨ body-lemma (def f) [] c-ok ⟩ˢ
(⟦ def f ⟧ (v ∷ []) >>= k) ∎) }) ⟩ˢ
(T.lam (def f) [] ∙ v >>= k) ∎) ⟩ˢ
(⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v >>= k) ∼⟨ associativity (⟦ t ⟧ ρ) _ _ ⟩
(⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v) >>= k ∼⟨⟩
⟦ call f t ⟧ ρ >>= k ∎
⟦⟧-correct (call f t) ρ {c} {ret c′ ρ′ ∷ s} {k} (restricted c-ok) _ =
exec ⟨ comp true (call f t) c , ret c′ ρ′ ∷ s , comp-env ρ ⟩ ∼⟨⟩ˢ
exec ⟨ comp false t (tcl f ∷ c) , ret c′ ρ′ ∷ s , comp-env ρ ⟩ ≳⟨ (⟦⟧-correct t _ unrestricted λ v →
exec ⟨ tcl f ∷ c
, val (comp-val v) ∷ ret c′ ρ′ ∷ s
, comp-env ρ
⟩ ≳⟨ (later λ { .force → weakenˡ lemma₅ (
exec ⟨ comp-name f
, ret c′ ρ′ ∷ s
, comp-val v ∷ []
⟩ ≳⟨ body-lemma (def f) [] c-ok ⟩ˢ
⟦ def f ⟧ (v ∷ []) >>= k ∎) }) ⟩ˢ
T.lam (def f) [] ∙ v >>= k ∎) ⟩ˢ
(⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v >>= k) ∼⟨ associativity (⟦ t ⟧ ρ) _ _ ⟩
(⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v) >>= k ∼⟨⟩
⟦ call f t ⟧ ρ >>= k ∎
⟦⟧-correct (con b) ρ {c} {s} {k} _ c-ok =
exec ⟨ con b ∷ c , s , comp-env ρ ⟩ ≳⟨ later (λ { .force →
exec ⟨ c , val (comp-val (T.con b)) ∷ s , comp-env ρ ⟩ ≳⟨ weakenˡ lemma₄ (c-ok (T.con b)) ⟩ˢ
k (T.con b) ∎ }) ⟩ˢ
⟦ con b ⟧ ρ >>= k ∎
⟦⟧-correct (if t₁ t₂ t₃) ρ {c} {s} {k} {tc} s-ok c-ok =
exec ⟨ comp false t₁ (bra (comp tc t₂ []) (comp tc t₃ []) ∷ c)
, s
, comp-env ρ
⟩ ≳⟨ weakenˡ lemma₈
(⟦⟧-correct t₁ _ unrestricted λ v₁ → ⟦if⟧-correct v₁ t₂ t₃ s-ok c-ok) ⟩ˢ
(⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦if⟧ v₁ t₂ t₃ ρ >>= k) ∼⟨ associativity (⟦ t₁ ⟧ ρ) _ _ ⟩
(⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦if⟧ v₁ t₂ t₃ ρ) >>= k ∼⟨⟩
⟦ if t₁ t₂ t₃ ⟧ ρ >>= k ∎
body-lemma :
∀ {i n n′} (t : Tm (suc n)) ρ {ρ′ : C.Env n′} {c s v}
{k : T.Value → Delay-crash C.Value ∞} {δ} →
Cont-OK i ⟨ c , s , ρ′ ⟩ k δ →
[ i ∣ ⌜ 1 ⌝ ∣ ⌜ 1 ⌝ + δ ]
exec ⟨ comp-body t , ret c ρ′ ∷ s , comp-val v ∷ comp-env ρ ⟩ ≳
⟦ t ⟧ (v ∷ ρ) >>= k
body-lemma t ρ {ρ′} {c} {s} {v} {k} c-ok =
exec ⟨ comp-body t , ret c ρ′ ∷ s , comp-val v ∷ comp-env ρ ⟩ ∼⟨⟩ˢ
exec ⟨ comp-body t , ret c ρ′ ∷ s , comp-env (v ∷ ρ) ⟩ ≳⟨ weakenˡ lemma₇ (⟦⟧-correct t (_ ∷ _) (ret-ok c-ok) λ v′ →
exec ⟨ ret ∷ []
, val (comp-val v′) ∷ ret c ρ′ ∷ s
, comp-env (v ∷ ρ)
⟩ ≳⟨⟩ˢ
exec ⟨ c , val (comp-val v′) ∷ s , ρ′ ⟩ ≳⟨ c-ok v′ ⟩ˢ
k v′ ∎) ⟩ˢ
⟦ t ⟧ (v ∷ ρ) >>= k ∎
∙-correct :
∀ {i n} v₁ v₂ {ρ : C.Env n} {c s}
{k : T.Value → Delay-crash C.Value ∞} {δ} →
Cont-OK i ⟨ c , s , ρ ⟩ k δ →
[ i ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ δ ]
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , ρ ⟩ ≳
v₁ ∙ v₂ >>= k
∙-correct (T.lam t₁ ρ₁) v₂ {ρ} {c} {s} {k} c-ok =
exec ⟨ app ∷ c
, val (comp-val v₂) ∷ val (comp-val (T.lam t₁ ρ₁)) ∷ s
, ρ
⟩ ≳⟨ later (λ { .force → weakenˡ lemma₆ (
exec ⟨ comp-body t₁ , ret c ρ ∷ s , comp-val v₂ ∷ comp-env ρ₁ ⟩ ≳⟨ body-lemma t₁ _ c-ok ⟩ˢ
⟦ t₁ ⟧ (v₂ ∷ ρ₁) >>= k ∎) }) ⟩ˢ
T.lam t₁ ρ₁ ∙ v₂ >>= k ∎
∙-correct (T.con b) v₂ {ρ} {c} {s} {k} _ = weakenˡ lemma₁₀ (
exec ⟨ app ∷ c
, val (comp-val v₂) ∷ val (comp-val (T.con b)) ∷ s
, ρ
⟩ ≳⟨⟩ˢ
crash ∼⟨⟩ˢ
T.con b ∙ v₂ >>= k ∎ˢ)
⟦if⟧-correct :
∀ {i n} v₁ (t₂ t₃ : Tm n) {ρ : T.Env n} {c s}
{k : T.Value → Delay-crash C.Value ∞} {tc δ} →
Stack-OK i k δ tc s →
Cont-OK i ⟨ c , s , comp-env ρ ⟩ k δ →
[ i ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ δ ]
exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c
, val (comp-val v₁) ∷ s
, comp-env ρ
⟩ ≳
⟦if⟧ v₁ t₂ t₃ ρ >>= k
⟦if⟧-correct (T.lam t₁ ρ₁) t₂ t₃ {ρ} {c} {s} {k} {tc} _ _ =
weakenˡ lemma₁₀ (
exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c
, val (comp-val (T.lam t₁ ρ₁)) ∷ s
, comp-env ρ
⟩ ≳⟨⟩ˢ
crash ∼⟨⟩ˢ
⟦if⟧ (T.lam t₁ ρ₁) t₂ t₃ ρ >>= k ∎ˢ)
⟦if⟧-correct (T.con true) t₂ t₃ {ρ} {c} {s} {k} {tc} s-ok c-ok =
exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c
, val (comp-val (T.con true)) ∷ s
, comp-env ρ
⟩ ≳⟨ later (λ { .force → weakenˡ lemma₃ (
exec ⟨ comp tc t₂ [] ++ c , s , comp-env ρ ⟩ ≡⟨ By.by (comp-++ _ t₂) ⟩ˢ
exec ⟨ comp tc t₂ c , s , comp-env ρ ⟩ ≳⟨ ⟦⟧-correct t₂ _ s-ok c-ok ⟩ˢ
⟦ t₂ ⟧ ρ >>= k ∎) }) ⟩ˢ
⟦if⟧ (T.con true) t₂ t₃ ρ >>= k ∎
⟦if⟧-correct (T.con false) t₂ t₃ {ρ} {c} {s} {k} {tc} s-ok c-ok =
exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c
, val (comp-val (T.con false)) ∷ s
, comp-env ρ
⟩ ≳⟨ later (λ { .force → weakenˡ lemma₃ (
exec ⟨ comp tc t₃ [] ++ c , s , comp-env ρ ⟩ ≡⟨ By.by (comp-++ _ t₃) ⟩ˢ
exec ⟨ comp tc t₃ c , s , comp-env ρ ⟩ ≳⟨ ⟦⟧-correct t₃ _ s-ok c-ok ⟩ˢ
⟦ t₃ ⟧ ρ >>= k ∎) }) ⟩ˢ
⟦if⟧ (T.con false) t₂ t₃ ρ >>= k ∎
-- The "time complexity" of the compiled program is linear in the time
-- complexity obtained from the instrumented interpreter, and vice
-- versa.
steps-match :
(t : Tm 0) →
[ ∞ ] steps (⟦ t ⟧ []) ≤ steps (exec ⟨ comp₀ t , [] , [] ⟩)
×
[ ∞ ] steps (exec ⟨ comp₀ t , [] , [] ⟩) ≤
⌜ 1 ⌝ + ⌜ 2 ⌝ * steps (⟦ t ⟧ [])
steps-match t = $⟨ ⟦⟧-correct t [] unrestricted (λ v → laterˡ (return (comp-val v) ∎ˢ)) ⟩
[ ∞ ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ ⌜ 1 ⌝ ]
exec ⟨ comp₀ t , [] , [] ⟩ ≳ comp-val ⟨$⟩ ⟦ t ⟧ [] ↝⟨ proj₂ ∘ _⇔_.to ≳⇔≈×steps≤steps² ⟩
[ ∞ ] steps (comp-val ⟨$⟩ ⟦ t ⟧ []) ≤
steps (exec ⟨ comp₀ t , [] , [] ⟩) ×
[ ∞ ] steps (exec ⟨ comp₀ t , [] , [] ⟩) ≤
max ⌜ 1 ⌝ ⌜ 1 ⌝ +
(⌜ 1 ⌝ + ⌜ 1 ⌝) * steps (comp-val ⟨$⟩ ⟦ t ⟧ []) ↝⟨ _⇔_.to (steps-⟨$⟩ Conat.≤-cong-∼ (_ Conat.∎∼)
×-cong
(_ Conat.∎∼)
Conat.≤-cong-∼
lemma₁₁ Conat.+-cong lemma₁₂ Conat.*-cong steps-⟨$⟩) ⟩□
[ ∞ ] steps (⟦ t ⟧ []) ≤ steps (exec ⟨ comp₀ t , [] , [] ⟩) ×
[ ∞ ] steps (exec ⟨ comp₀ t , [] , [] ⟩) ≤
⌜ 1 ⌝ + ⌜ 2 ⌝ * steps (⟦ t ⟧ []) □
| 38.449383
| 145
| 0.37028
|
0460206dc304ddd7e787a0df36f97239574337d8
| 11,230
|
agda
|
Agda
|
src/Categories/Bicategory/Extras.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
src/Categories/Bicategory/Extras.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
src/Categories/Bicategory/Extras.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Bicategory using (Bicategory)
module Categories.Bicategory.Extras {o ℓ e t} (Bicat : Bicategory o ℓ e t) where
open import Data.Product using (_,_)
import Categories.Category.Construction.Core as Core
open import Categories.Category.Construction.Functors using (Functors; module curry)
open import Categories.Functor using (Functor)
open import Categories.Functor.Bifunctor using (flip-bifunctor)
open import Categories.Functor.Bifunctor.Properties
open import Categories.NaturalTransformation
using (NaturalTransformation; ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties using (push-eq)
open Bicategory Bicat public
private
variable
A B C D : Obj
f g h i : A ⇒₁ B
α β γ δ : f ⇒₂ g
infixr 10 _▷ᵢ_
infixl 10 _◁ᵢ_
infixr 6 _⟩⊚⟨_ refl⟩⊚⟨_
infixl 7 _⟩⊚⟨refl
module ⊚ {A B C} = Functor (⊚ {A} {B} {C})
module ⊚-assoc {A B C D} = NaturalIsomorphism (⊚-assoc {A} {B} {C} {D})
module unitˡ {A B} = NaturalIsomorphism (unitˡ {A} {B})
module unitʳ {A B} = NaturalIsomorphism (unitʳ {A} {B})
module id {A} = Functor (id {A})
private
module MR′ {A} {B} where
open Core.Shorthands (hom A B) public
open MR (hom A B) public hiding (push-eq)
open MR′
unitorˡ : {A B : Obj} {f : A ⇒₁ B} → id₁ ∘₁ f ≅ f
unitorˡ {_} {_} {f} = record
{ from = unitˡ.⇒.η (_ , f)
; to = unitˡ.⇐.η (_ , f)
; iso = unitˡ.iso (_ , f)
}
module unitorˡ {A B f} = _≅_ (unitorˡ {A} {B} {f})
unitorʳ : {A B : Obj} {f : A ⇒₁ B} → f ∘₁ id₁ ≅ f
unitorʳ {_} {_} {f} = record
{ from = unitʳ.⇒.η (f , _)
; to = unitʳ.⇐.η (f , _)
; iso = unitʳ.iso (f , _)
}
module unitorʳ {A B f} = _≅_ (unitorʳ {A} {B} {f})
associator : {A B C D : Obj} {f : D ⇒₁ B} {g : C ⇒₁ D} {h : A ⇒₁ C} →
(f ∘₁ g) ∘₁ h ≅ f ∘₁ g ∘₁ h
associator {_} {_} {_} {_} {f} {g} {h} = record
{ from = ⊚-assoc.⇒.η ((f , g) , h)
; to = ⊚-assoc.⇐.η ((f , g) , h)
; iso = ⊚-assoc.iso ((f , g) , h)
}
module associator {A B C D} {f : C ⇒₁ B} {g : D ⇒₁ C} {h} = _≅_ (associator {A = A} {B = B} {f = f} {g = g} {h = h})
module Shorthands where
λ⇒ = unitorˡ.from
λ⇐ = unitorˡ.to
ρ⇒ = unitorʳ.from
ρ⇐ = unitorʳ.to
α⇒ = associator.from
α⇐ = associator.to
open Shorthands
-- Two curried versions of ⊚.
-⊚[-] : Functor (hom A B) (Functors (hom B C) (hom A C))
-⊚[-] = curry.F₀ (flip-bifunctor ⊚)
[-]⊚- : Functor (hom B C) (Functors (hom A B) (hom A C))
[-]⊚- = curry.F₀ ⊚
-⊚_ : A ⇒₁ B → Functor (hom B C) (hom A C)
-⊚_ = Functor.F₀ -⊚[-]
_⊚- : B ⇒₁ C → Functor (hom A B) (hom A C)
_⊚- = Functor.F₀ [-]⊚-
-▷_ : ∀ {C} → f ⇒₂ g → NaturalTransformation (-⊚_ {C = C} f) (-⊚ g)
-▷_ = Functor.F₁ -⊚[-]
_◁- : ∀ {A} → f ⇒₂ g → NaturalTransformation (_⊚- {A = A} f) (g ⊚-)
_◁- = Functor.F₁ [-]⊚-
identity₂ˡ : id₂ ∘ᵥ α ≈ α
identity₂ˡ = hom.identityˡ
identity₂ʳ : α ∘ᵥ id₂ ≈ α
identity₂ʳ = hom.identityʳ
assoc₂ : (α ∘ᵥ β) ∘ᵥ γ ≈ α ∘ᵥ β ∘ᵥ γ
assoc₂ = hom.assoc
id₂◁ : id₂ {f = g} ◁ f ≈ id₂
id₂◁ = ⊚.identity
▷id₂ : f ▷ id₂ {f = g} ≈ id₂
▷id₂ = ⊚.identity
open hom.HomReasoning
open hom.Equiv
_⊚ᵢ_ : f ≅ h → g ≅ i → f ⊚₀ g ≅ h ⊚₀ i
α ⊚ᵢ β = record
{ from = from α ⊚₁ from β
; to = to α ⊚₁ to β
; iso = record
{ isoˡ = [ ⊚ ]-merge (isoˡ α) (isoˡ β) ○ ⊚.identity
; isoʳ = [ ⊚ ]-merge (isoʳ α) (isoʳ β) ○ ⊚.identity }
}
_◁ᵢ_ : {g h : B ⇒₁ C} (α : g ≅ h) (f : A ⇒₁ B) → g ∘₁ f ≅ h ∘₁ f
α ◁ᵢ _ = α ⊚ᵢ idᵢ
_▷ᵢ_ : {f g : A ⇒₁ B} (h : B ⇒₁ C) (α : f ≅ g) → h ∘₁ f ≅ h ∘₁ g
_ ▷ᵢ α = idᵢ ⊚ᵢ α
⊚-resp-≈ : α ≈ β → γ ≈ δ → α ⊚₁ γ ≈ β ⊚₁ δ
⊚-resp-≈ p q = ⊚.F-resp-≈ (p , q)
⊚-resp-≈ˡ : α ≈ β → α ⊚₁ γ ≈ β ⊚₁ γ
⊚-resp-≈ˡ p = ⊚.F-resp-≈ (p , hom.Equiv.refl)
⊚-resp-≈ʳ : γ ≈ δ → α ⊚₁ γ ≈ α ⊚₁ δ
⊚-resp-≈ʳ q = ⊚.F-resp-≈ (hom.Equiv.refl , q)
_⟩⊚⟨_ : α ≈ β → γ ≈ δ → α ⊚₁ γ ≈ β ⊚₁ δ
_⟩⊚⟨_ = ⊚-resp-≈
refl⟩⊚⟨_ : γ ≈ δ → α ⊚₁ γ ≈ α ⊚₁ δ
refl⟩⊚⟨_ = ⊚-resp-≈ʳ
_⟩⊚⟨refl : α ≈ β → α ⊚₁ γ ≈ β ⊚₁ γ
_⟩⊚⟨refl = ⊚-resp-≈ˡ
∘ᵥ-distr-◁ : (α ◁ f) ∘ᵥ (β ◁ f) ≈ (α ∘ᵥ β) ◁ f
∘ᵥ-distr-◁ {f = f} = ⟺ (Functor.homomorphism (-⊚ f))
∘ᵥ-distr-▷ : (f ▷ α) ∘ᵥ (f ▷ β) ≈ f ▷ (α ∘ᵥ β)
∘ᵥ-distr-▷ {f = f} = ⟺ (Functor.homomorphism (f ⊚-))
λ⇒-∘ᵥ-▷ : λ⇒ ∘ᵥ (id₁ ▷ α) ≈ α ∘ᵥ λ⇒
λ⇒-∘ᵥ-▷ {α = α} = begin
λ⇒ ∘ᵥ (id₁ ▷ α) ≈˘⟨ refl⟩∘⟨ id.identity ⟩⊚⟨refl ⟩
λ⇒ ∘ᵥ id.F₁ _ ⊚₁ α ≈⟨ unitˡ.⇒.commute (_ , α) ⟩
α ∘ᵥ λ⇒ ∎
▷-∘ᵥ-λ⇐ : (id₁ ▷ α) ∘ᵥ λ⇐ ≈ λ⇐ ∘ᵥ α
▷-∘ᵥ-λ⇐ = conjugate-to (unitorˡ ⁻¹) (unitorˡ ⁻¹) λ⇒-∘ᵥ-▷
ρ⇒-∘ᵥ-◁ : ρ⇒ ∘ᵥ (α ◁ id₁) ≈ α ∘ᵥ ρ⇒
ρ⇒-∘ᵥ-◁ {α = α} = begin
ρ⇒ ∘ᵥ (α ◁ id₁) ≈˘⟨ refl⟩∘⟨ refl⟩⊚⟨ id.identity ⟩
ρ⇒ ∘ᵥ (α ⊚₁ id.F₁ _) ≈⟨ unitʳ.⇒.commute (α , _) ⟩
α ∘ᵥ ρ⇒ ∎
◁-∘ᵥ-ρ⇐ : (α ◁ id₁) ∘ᵥ ρ⇐ ≈ ρ⇐ ∘ᵥ α
◁-∘ᵥ-ρ⇐ = conjugate-to (unitorʳ ⁻¹) (unitorʳ ⁻¹) ρ⇒-∘ᵥ-◁
α⇐-◁-∘₁ : α⇐ ∘ᵥ (γ ◁ (g ∘₁ f)) ≈ ((γ ◁ g) ◁ f) ∘ᵥ α⇐
α⇐-◁-∘₁ {γ = γ} {g = g} {f = f} = begin
α⇐ ∘ᵥ (γ ◁ (g ∘₁ f)) ≈˘⟨ refl⟩∘⟨ refl⟩⊚⟨ ⊚.identity ⟩
α⇐ ∘ᵥ (γ ⊚₁ id₂ ⊚₁ id₂) ≈⟨ ⊚-assoc.⇐.commute ((γ , id₂) , id₂) ⟩
((γ ◁ g) ◁ f) ∘ᵥ α⇐ ∎
α⇒-◁-∘₁ : α⇒ ∘ᵥ γ ◁ g ◁ f ≈ γ ◁ (g ∘₁ f) ∘ᵥ α⇒
α⇒-◁-∘₁ = ⟺ (conjugate-to associator associator α⇐-◁-∘₁)
α⇐-▷-◁ : α⇐ ∘ᵥ (f ▷ (γ ◁ g)) ≈ ((f ▷ γ) ◁ g) ∘ᵥ α⇐
α⇐-▷-◁ {f = f} {γ = γ} {g = g} = ⊚-assoc.⇐.commute ((id₂ , γ) , id₂)
α⇒-▷-∘₁ : α⇒ ∘ᵥ (f ∘₁ g) ▷ γ ≈ f ▷ g ▷ γ ∘ᵥ α⇒
α⇒-▷-∘₁{f = f} {g = g} {γ = γ} = begin
α⇒ ∘ᵥ (f ⊚₀ g) ▷ γ ≈˘⟨ refl⟩∘⟨ ⊚.identity ⟩⊚⟨refl ⟩
α⇒ ∘ᵥ (f ▷ id₂) ⊚₁ γ ≈⟨ ⊚-assoc.⇒.commute ((id₂ , id₂) , γ) ⟩
f ▷ g ▷ γ ∘ᵥ α⇒ ∎
α⇐-▷-∘₁ : α⇐ ∘ᵥ (g ▷ (f ▷ γ)) ≈ ((g ∘₁ f) ▷ γ) ∘ᵥ α⇐
α⇐-▷-∘₁ = conjugate-from associator associator (⟺ α⇒-▷-∘₁)
◁-▷-exchg : ∀ {α : f ⇒₂ g} {β : h ⇒₂ i} → (i ▷ α) ∘ᵥ (β ◁ f) ≈ (β ◁ g) ∘ᵥ (h ▷ α)
◁-▷-exchg = [ ⊚ ]-commute
triangle-iso : {f : A ⇒₁ B} {g : B ⇒₁ C} →
(g ▷ᵢ unitorˡ ∘ᵢ associator) ≈ᵢ (unitorʳ ◁ᵢ f)
triangle-iso = ⌞ triangle ⌟
triangle-inv : {f : A ⇒₁ B} {g : B ⇒₁ C} → α⇐ ∘ᵥ g ▷ λ⇐ ≈ ρ⇐ ◁ f
triangle-inv = to-≈ triangle-iso
pentagon-iso : ∀ {E} {f : A ⇒₁ B} {g : B ⇒₁ C} {h : C ⇒₁ D} {i : D ⇒₁ E} →
(i ▷ᵢ associator ∘ᵢ associator ∘ᵢ associator ◁ᵢ f) ≈ᵢ
(associator {f = i} {h} {g ∘₁ f} ∘ᵢ associator)
pentagon-iso = ⌞ pentagon ⌟
pentagon-inv : ∀ {E} {f : A ⇒₁ B} {g : B ⇒₁ C} {h : C ⇒₁ D} {i : D ⇒₁ E} →
(α⇐ ◁ f ∘ᵥ α⇐) ∘ᵥ i ▷ α⇐ ≈ α⇐ ∘ᵥ α⇐ {f = i} {h} {g ∘₁ f}
pentagon-inv = to-≈ pentagon-iso
module UnitorCoherence where
-- Extra coherence laws for the unitors.
--
-- These are similar to the extra coherence laws for monoidal
-- categories that Kelly proved admissible in 1964. The proofs are
-- largely the same. See Categories.Category.Monoidal.Properties
-- for the monoidal versions and
--
-- https://ncatlab.org/nlab/show/monoidal+category
--
-- for an explanation of the proof and references to Kelly's paper.
open ComHom
-- As described on nLab, we start by proving that the 'perimeters'
-- of two large diagrams commute...
id▷λ-perimeter : [ ((id₁ ⊚₀ id₁) ⊚₀ f) ⊚₀ g ⇒ id₁ ⊚₀ (f ⊚₀ g) ]⟨
α⇒ ◁ g ⇒⟨ (id₁ ⊚₀ (id₁ ⊚₀ f)) ⊚₀ g ⟩
α⇒ ⇒⟨ id₁ ⊚₀ ((id₁ ⊚₀ f) ⊚₀ g) ⟩
id₁ ▷ α⇒ ⇒⟨ id₁ ⊚₀ (id₁ ⊚₀ (f ⊚₀ g)) ⟩
id₁ ▷ λ⇒
≈ ρ⇒ ◁ f ◁ g ⇒⟨ (id₁ ⊚₀ f) ⊚₀ g ⟩
α⇒
⟩
id▷λ-perimeter {f = f} {g = g} = begin
id₁ ▷ λ⇒ ∘ᵥ id₁ ▷ α⇒ ∘ᵥ α⇒ ∘ᵥ α⇒ ◁ g ≈⟨ refl⟩∘⟨ pentagon ⟩
id₁ ▷ λ⇒ ∘ᵥ α⇒ ∘ᵥ α⇒ ≈⟨ pullˡ triangle ⟩
ρ⇒ ◁ (f ⊚₀ g) ∘ᵥ α⇒ ≈˘⟨ refl⟩⊚⟨ ⊚.identity ⟩∘⟨refl ⟩
ρ⇒ ⊚₁ (id₂ ◁ g) ∘ᵥ α⇒ ≈˘⟨ ⊚-assoc.⇒.commute _ ⟩
α⇒ ∘ᵥ ρ⇒ ◁ f ◁ g ∎
ρ◁id-perimeter : [ ((f ⊚₀ g) ⊚₀ id₁) ⊚₀ id₁ ⇒ f ⊚₀ (g ⊚₀ id₁) ]⟨
α⇒ ◁ id₁ ⇒⟨ (f ⊚₀ (g ⊚₀ id₁)) ⊚₀ id₁ ⟩
α⇒ ⇒⟨ f ⊚₀ ((g ⊚₀ id₁) ⊚₀ id₁) ⟩
f ▷ α⇒ ⇒⟨ f ⊚₀ (g ⊚₀ (id₁ ⊚₀ id₁)) ⟩
f ▷ g ▷ λ⇒
≈ ρ⇒ ◁ id₁ ⇒⟨ (f ⊚₀ g) ⊚₀ id₁ ⟩
α⇒
⟩
ρ◁id-perimeter {f = f} {g = g} = begin
f ▷ g ▷ λ⇒ ∘ᵥ f ▷ α⇒ ∘ᵥ α⇒ ∘ᵥ α⇒ ◁ id₁ ≈⟨ refl⟩∘⟨ pentagon ⟩
f ▷ g ▷ λ⇒ ∘ᵥ α⇒ ∘ᵥ α⇒ ≈˘⟨ pushˡ (⊚-assoc.⇒.commute _) ⟩
(α⇒ ∘ᵥ (f ▷ id₂) ⊚₁ λ⇒) ∘ᵥ α⇒ ≈⟨ pullʳ (⊚.identity ⟩⊚⟨refl ⟩∘⟨refl) ⟩
α⇒ ∘ᵥ (f ⊚₀ g) ▷ λ⇒ ∘ᵥ α⇒ ≈⟨ refl⟩∘⟨ triangle ⟩
α⇒ ∘ᵥ ρ⇒ ◁ id₁ ∎
-- ... which allow us to prove that the following triangles commute...
id▷λ-coherence : [ id₁ ⊚₀ ((id₁ ⊚₀ f) ⊚₀ g) ⇒ id₁ ⊚₀ (f ⊚₀ g) ]⟨
id₁ ▷ (λ⇒ ◁ g)
≈ id₁ ▷ α⇒ ⇒⟨ id₁ ⊚₀ (id₁ ⊚₀ (f ⊚₀ g)) ⟩
id₁ ▷ λ⇒
⟩
id▷λ-coherence {f = f} {g = g} = begin
id₁ ▷ (λ⇒ ◁ g)
≈⟨ switch-fromtoʳ associator (⟺ (⊚-assoc.⇒.commute _)) ⟩
(α⇒ ∘ᵥ (id₁ ▷ λ⇒) ◁ g) ∘ᵥ α⇐
≈⟨ (refl⟩∘⟨ switch-fromtoʳ associator triangle ⟩⊚⟨refl) ⟩∘⟨refl ⟩
(α⇒ ∘ᵥ ((ρ⇒ ◁ f ∘ᵥ α⇐) ◁ g)) ∘ᵥ α⇐
≈⟨ pushˡ (pushʳ (Functor.homomorphism (-⊚ g))) ⟩
(α⇒ ∘ᵥ ρ⇒ ◁ f ◁ g) ∘ᵥ (α⇐ ◁ g ∘ᵥ α⇐)
≈˘⟨ switch-fromtoʳ (associator ∘ᵢ (associator ⊚ᵢ idᵢ))
(hom.assoc ○ id▷λ-perimeter) ⟩
id₁ ▷ λ⇒ ∘ᵥ id₁ ▷ α⇒
∎
ρ◁id-coherence : [ ((f ⊚₀ g) ⊚₀ id₁) ⊚₀ id₁ ⇒ (f ⊚₀ g) ⊚₀ id₁ ]⟨
ρ⇒ ◁ id₁
≈ α⇒ ◁ id₁ ⇒⟨ (f ⊚₀ (g ⊚₀ id₁)) ⊚₀ id₁ ⟩
(f ▷ ρ⇒) ◁ id₁
⟩
ρ◁id-coherence {f = f} {g = g} = begin
ρ⇒ ◁ id₁
≈⟨ switch-fromtoˡ associator (⟺ ρ◁id-perimeter) ⟩
α⇐ ∘ᵥ f ▷ g ▷ λ⇒ ∘ᵥ f ▷ α⇒ ∘ᵥ α⇒ ∘ᵥ α⇒ ◁ id₁
≈˘⟨ pullʳ (pushˡ (Functor.homomorphism (f ⊚-))) ⟩
(α⇐ ∘ᵥ f ▷ (g ▷ λ⇒ ∘ᵥ α⇒)) ∘ᵥ α⇒ ∘ᵥ α⇒ ◁ id₁
≈⟨ pullˡ (pushˡ (refl⟩∘⟨ refl⟩⊚⟨ triangle)) ⟩
(α⇐ ∘ᵥ f ▷ (ρ⇒ ◁ id₁) ∘ᵥ α⇒) ∘ᵥ α⇒ ◁ id₁
≈˘⟨ switch-fromtoˡ associator (⊚-assoc.⇒.commute _) ⟩∘⟨refl ⟩
(f ▷ ρ⇒) ◁ id₁ ∘ᵥ α⇒ ◁ id₁
∎
-- ... which are the results modulo (id₁ ⊚-) and (-⊚ id₁).
unitorˡ-coherence : [ (id₁ ⊚₀ f) ⊚₀ g ⇒ f ⊚₀ g ]⟨
λ⇒ ◁ g
≈ α⇒ ⇒⟨ id₁ ⊚₀ (f ⊚₀ g) ⟩
λ⇒
⟩
unitorˡ-coherence {f = f} {g = g} = push-eq unitˡ (begin
id.F₁ _ ⊚₁ (λ⇒ ◁ g) ≈⟨ id.identity ⟩⊚⟨refl ⟩
id₁ ▷ (λ⇒ ◁ g) ≈⟨ id▷λ-coherence ⟩
id₁ ▷ λ⇒ ∘ᵥ id₁ ▷ α⇒ ≈˘⟨ Functor.homomorphism (id₁ ⊚-) ⟩
id₁ ▷ (λ⇒ ∘ᵥ α⇒) ≈˘⟨ id.identity ⟩⊚⟨refl ⟩
id.F₁ _ ⊚₁ (λ⇒ ∘ᵥ α⇒) ∎)
unitorʳ-coherence : [ (f ⊚₀ g) ⊚₀ id₁ ⇒ f ⊚₀ g ]⟨
ρ⇒
≈ α⇒ ⇒⟨ f ⊚₀ (g ⊚₀ id₁) ⟩
f ▷ ρ⇒
⟩
unitorʳ-coherence {f = f} {g = g} = push-eq unitʳ (begin
ρ⇒ ⊚₁ id.F₁ _ ≈⟨ refl⟩⊚⟨ id.identity ⟩
ρ⇒ ◁ id₁ ≈⟨ ρ◁id-coherence ⟩
(f ▷ ρ⇒) ◁ id₁ ∘ᵥ α⇒ ◁ id₁ ≈˘⟨ Functor.homomorphism (-⊚ id₁) ⟩
(f ▷ ρ⇒ ∘ᵥ α⇒) ◁ id₁ ≈˘⟨ refl⟩⊚⟨ id.identity ⟩
(f ▷ ρ⇒ ∘ᵥ α⇒) ⊚₁ id.F₁ _ ∎)
open UnitorCoherence public using (unitorˡ-coherence; unitorʳ-coherence)
| 33.825301
| 116
| 0.453517
|
4b26763d2729eeb98a181fc17774a7740fa7dc8e
| 9,064
|
agda
|
Agda
|
Cubical/Data/Nat/Order.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Order.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Order.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-# OPTIONS --no-exact-split --safe #-}
module Cubical.Data.Nat.Order where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sigma
open import Cubical.Data.Sum as ⊎
open import Cubical.Data.Nat.Base
open import Cubical.Data.Nat.Properties
open import Cubical.Induction.WellFounded
open import Cubical.Relation.Nullary
infix 4 _≤_ _<_
_≤_ : ℕ → ℕ → Type₀
m ≤ n = Σ[ k ∈ ℕ ] k + m ≡ n
_<_ : ℕ → ℕ → Type₀
m < n = suc m ≤ n
data Trichotomy (m n : ℕ) : Type₀ where
lt : m < n → Trichotomy m n
eq : m ≡ n → Trichotomy m n
gt : n < m → Trichotomy m n
private
variable
k l m n : ℕ
private
witness-prop : ∀ j → isProp (j + m ≡ n)
witness-prop {m} {n} j = isSetℕ (j + m) n
m≤n-isProp : isProp (m ≤ n)
m≤n-isProp {m} {n} (k , p) (l , q)
= Σ≡Prop witness-prop lemma
where
lemma : k ≡ l
lemma = inj-+m (p ∙ (sym q))
zero-≤ : 0 ≤ n
zero-≤ {n} = n , +-zero n
suc-≤-suc : m ≤ n → suc m ≤ suc n
suc-≤-suc (k , p) = k , (+-suc k _) ∙ (cong suc p)
≤-+k : m ≤ n → m + k ≤ n + k
≤-+k {m} {k = k} (i , p)
= i , +-assoc i m k ∙ cong (_+ k) p
≤-k+ : m ≤ n → k + m ≤ k + n
≤-k+ {m} {n} {k}
= subst (_≤ k + n) (+-comm m k)
∘ subst (m + k ≤_) (+-comm n k)
∘ ≤-+k
pred-≤-pred : suc m ≤ suc n → m ≤ n
pred-≤-pred (k , p) = k , injSuc ((sym (+-suc k _)) ∙ p)
≤-refl : m ≤ m
≤-refl = 0 , refl
≤-suc : m ≤ n → m ≤ suc n
≤-suc (k , p) = suc k , cong suc p
≤-predℕ : predℕ n ≤ n
≤-predℕ {zero} = ≤-refl
≤-predℕ {suc n} = ≤-suc ≤-refl
≤-trans : k ≤ m → m ≤ n → k ≤ n
≤-trans {k} {m} {n} (i , p) (j , q) = i + j , l2 ∙ (l1 ∙ q)
where
l1 : j + i + k ≡ j + m
l1 = (sym (+-assoc j i k)) ∙ (cong (j +_) p)
l2 : i + j + k ≡ j + i + k
l2 = cong (_+ k) (+-comm i j)
≤-antisym : m ≤ n → n ≤ m → m ≡ n
≤-antisym {m} (i , p) (j , q) = (cong (_+ m) l3) ∙ p
where
l1 : j + i + m ≡ m
l1 = (sym (+-assoc j i m)) ∙ ((cong (j +_) p) ∙ q)
l2 : j + i ≡ 0
l2 = m+n≡n→m≡0 l1
l3 : 0 ≡ i
l3 = sym (snd (m+n≡0→m≡0×n≡0 l2))
≤-k+-cancel : k + m ≤ k + n → m ≤ n
≤-k+-cancel {k} {m} (l , p) = l , inj-m+ (sub k m ∙ p)
where
sub : ∀ k m → k + (l + m) ≡ l + (k + m)
sub k m = +-assoc k l m ∙ cong (_+ m) (+-comm k l) ∙ sym (+-assoc l k m)
≤-+k-cancel : m + k ≤ n + k → m ≤ n
≤-+k-cancel {m} {k} {n} (l , p) = l , cancelled
where
cancelled : l + m ≡ n
cancelled = inj-+m (sym (+-assoc l m k) ∙ p)
≤-·k : m ≤ n → m · k ≤ n · k
≤-·k {m} {n} {k} (d , r) = d · k , reason where
reason : d · k + m · k ≡ n · k
reason = d · k + m · k ≡⟨ ·-distribʳ d m k ⟩
(d + m) · k ≡⟨ cong (_· k) r ⟩
n · k ∎
<-k+-cancel : k + m < k + n → m < n
<-k+-cancel {k} {m} {n} = ≤-k+-cancel ∘ subst (_≤ k + n) (sym (+-suc k m))
¬-<-zero : ¬ m < 0
¬-<-zero (k , p) = snotz ((sym (+-suc k _)) ∙ p)
¬m<m : ¬ m < m
¬m<m {m} = ¬-<-zero ∘ ≤-+k-cancel {k = m}
≤0→≡0 : n ≤ 0 → n ≡ 0
≤0→≡0 {zero} ineq = refl
≤0→≡0 {suc n} ineq = ⊥.rec (¬-<-zero ineq)
predℕ-≤-predℕ : m ≤ n → (predℕ m) ≤ (predℕ n)
predℕ-≤-predℕ {zero} {zero} ineq = ≤-refl
predℕ-≤-predℕ {zero} {suc n} ineq = zero-≤
predℕ-≤-predℕ {suc m} {zero} ineq = ⊥.rec (¬-<-zero ineq)
predℕ-≤-predℕ {suc m} {suc n} ineq = pred-≤-pred ineq
¬m+n<m : ¬ m + n < m
¬m+n<m {m} {n} = ¬-<-zero ∘ <-k+-cancel ∘ subst (m + n <_) (sym (+-zero m))
<-weaken : m < n → m ≤ n
<-weaken (k , p) = suc k , sym (+-suc k _) ∙ p
≤<-trans : l ≤ m → m < n → l < n
≤<-trans p = ≤-trans (suc-≤-suc p)
<≤-trans : l < m → m ≤ n → l < n
<≤-trans = ≤-trans
<-trans : l < m → m < n → l < n
<-trans p = ≤<-trans (<-weaken p)
<-asym : m < n → ¬ n ≤ m
<-asym m<n = ¬m<m ∘ <≤-trans m<n
<-+k : m < n → m + k < n + k
<-+k p = ≤-+k p
<-k+ : m < n → k + m < k + n
<-k+ {m} {n} {k} p = subst (λ km → km ≤ k + n) (+-suc k m) (≤-k+ p)
<-·sk : m < n → m · suc k < n · suc k
<-·sk {m} {n} {k} (d , r) = (d · suc k + k) , reason where
reason : (d · suc k + k) + suc (m · suc k) ≡ n · suc k
reason = (d · suc k + k) + suc (m · suc k) ≡⟨ sym (+-assoc (d · suc k) k _) ⟩
d · suc k + (k + suc (m · suc k)) ≡[ i ]⟨ d · suc k + +-suc k (m · suc k) i ⟩
d · suc k + suc m · suc k ≡⟨ ·-distribʳ d (suc m) (suc k) ⟩
(d + suc m) · suc k ≡⟨ cong (_· suc k) r ⟩
n · suc k ∎
≤-∸-+-cancel : m ≤ n → (n ∸ m) + m ≡ n
≤-∸-+-cancel {zero} {n} _ = +-zero _
≤-∸-+-cancel {suc m} {zero} m≤n = ⊥.rec (¬-<-zero m≤n)
≤-∸-+-cancel {suc m} {suc n} m+1≤n+1 = +-suc _ _ ∙ cong suc (≤-∸-+-cancel (pred-≤-pred m+1≤n+1))
left-≤-max : m ≤ max m n
left-≤-max {zero} {n} = zero-≤
left-≤-max {suc m} {zero} = ≤-refl
left-≤-max {suc m} {suc n} = suc-≤-suc left-≤-max
right-≤-max : n ≤ max m n
right-≤-max {zero} {m} = zero-≤
right-≤-max {suc n} {zero} = ≤-refl
right-≤-max {suc n} {suc m} = suc-≤-suc right-≤-max
min-≤-left : min m n ≤ m
min-≤-left {zero} {n} = ≤-refl
min-≤-left {suc m} {zero} = zero-≤
min-≤-left {suc m} {suc n} = suc-≤-suc min-≤-left
min-≤-right : min m n ≤ n
min-≤-right {zero} {n} = zero-≤
min-≤-right {suc m} {zero} = ≤-refl
min-≤-right {suc m} {suc n} = suc-≤-suc min-≤-right
Trichotomy-suc : Trichotomy m n → Trichotomy (suc m) (suc n)
Trichotomy-suc (lt m<n) = lt (suc-≤-suc m<n)
Trichotomy-suc (eq m=n) = eq (cong suc m=n)
Trichotomy-suc (gt n<m) = gt (suc-≤-suc n<m)
_≟_ : ∀ m n → Trichotomy m n
zero ≟ zero = eq refl
zero ≟ suc n = lt (n , +-comm n 1)
suc m ≟ zero = gt (m , +-comm m 1)
suc m ≟ suc n = Trichotomy-suc (m ≟ n)
<-split : m < suc n → (m < n) ⊎ (m ≡ n)
<-split {n = zero} = inr ∘ snd ∘ m+n≡0→m≡0×n≡0 ∘ snd ∘ pred-≤-pred
<-split {zero} {suc n} = λ _ → inl (suc-≤-suc zero-≤)
<-split {suc m} {suc n} = ⊎.map suc-≤-suc (cong suc) ∘ <-split ∘ pred-≤-pred
private
acc-suc : Acc _<_ n → Acc _<_ (suc n)
acc-suc a
= acc λ y y<sn
→ case <-split y<sn of λ
{ (inl y<n) → access a y y<n
; (inr y≡n) → subst _ (sym y≡n) a
}
<-wellfounded : WellFounded _<_
<-wellfounded zero = acc λ _ → ⊥.rec ∘ ¬-<-zero
<-wellfounded (suc n) = acc-suc (<-wellfounded n)
<→≢ : n < m → ¬ n ≡ m
<→≢ {n} {m} p q = ¬m<m (subst (_< m) q p)
module _
(b₀ : ℕ)
(P : ℕ → Type₀)
(base : ∀ n → n < suc b₀ → P n)
(step : ∀ n → P n → P (suc b₀ + n))
where
open WFI (<-wellfounded)
private
dichotomy : ∀ b n → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)
dichotomy b n
= case n ≟ b return (λ _ → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)) of λ
{ (lt o) → inl o
; (eq p) → inr (0 , p ∙ sym (+-zero b))
; (gt (m , p)) → inr (suc m , sym p ∙ +-suc m b ∙ +-comm (suc m) b)
}
dichotomy<≡ : ∀ b n → (n<b : n < b) → dichotomy b n ≡ inl n<b
dichotomy<≡ b n n<b
= case dichotomy b n return (λ d → d ≡ inl n<b) of λ
{ (inl x) → cong inl (m≤n-isProp x n<b)
; (inr (m , p)) → ⊥.rec (<-asym n<b (m , sym (p ∙ +-comm b m)))
}
dichotomy+≡ : ∀ b m n → (p : n ≡ b + m) → dichotomy b n ≡ inr (m , p)
dichotomy+≡ b m n p
= case dichotomy b n return (λ d → d ≡ inr (m , p)) of λ
{ (inl n<b) → ⊥.rec (<-asym n<b (m , +-comm m b ∙ sym p))
; (inr (m' , q))
→ cong inr (Σ≡Prop (λ x → isSetℕ n (b + x)) (inj-m+ {m = b} (sym q ∙ p)))
}
b = suc b₀
lemma₁ : ∀{x y z} → x ≡ suc z + y → y < x
lemma₁ {y = y} {z} p = z , +-suc z y ∙ sym p
subStep : (n : ℕ) → (∀ m → m < n → P m) → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m) → P n
subStep n _ (inl l) = base n l
subStep n rec (inr (m , p))
= transport (cong P (sym p)) (step m (rec m (lemma₁ p)))
wfStep : (n : ℕ) → (∀ m → m < n → P m) → P n
wfStep n rec = subStep n rec (dichotomy b n)
wfStepLemma₀ : ∀ n (n<b : n < b) rec → wfStep n rec ≡ base n n<b
wfStepLemma₀ n n<b rec = cong (subStep n rec) (dichotomy<≡ b n n<b)
wfStepLemma₁ : ∀ n rec → wfStep (b + n) rec ≡ step n (rec n (lemma₁ refl))
wfStepLemma₁ n rec
= cong (subStep (b + n) rec) (dichotomy+≡ b n (b + n) refl)
∙ transportRefl _
+induction : ∀ n → P n
+induction = induction wfStep
+inductionBase : ∀ n → (l : n < b) → +induction n ≡ base n l
+inductionBase n l = induction-compute wfStep n ∙ wfStepLemma₀ n l _
+inductionStep : ∀ n → +induction (b + n) ≡ step n (+induction n)
+inductionStep n = induction-compute wfStep (b + n) ∙ wfStepLemma₁ n _
module <-Reasoning where
-- TODO: would it be better to mirror the way it is done in the agda-stdlib?
infixr 2 _<⟨_⟩_ _≤<⟨_⟩_ _≤⟨_⟩_ _<≤⟨_⟩_ _≡<⟨_⟩_ _≡≤⟨_⟩_ _<≡⟨_⟩_ _≤≡⟨_⟩_
_<⟨_⟩_ : ∀ k → k < n → n < m → k < m
_ <⟨ p ⟩ q = <-trans p q
_≤<⟨_⟩_ : ∀ k → k ≤ n → n < m → k < m
_ ≤<⟨ p ⟩ q = ≤<-trans p q
_≤⟨_⟩_ : ∀ k → k ≤ n → n ≤ m → k ≤ m
_ ≤⟨ p ⟩ q = ≤-trans p q
_<≤⟨_⟩_ : ∀ k → k < n → n ≤ m → k < m
_ <≤⟨ p ⟩ q = <≤-trans p q
_≡≤⟨_⟩_ : ∀ k → k ≡ l → l ≤ m → k ≤ m
_ ≡≤⟨ p ⟩ q = subst (λ k → k ≤ _) (sym p) q
_≡<⟨_⟩_ : ∀ k → k ≡ l → l < m → k < m
_ ≡<⟨ p ⟩ q = _ ≡≤⟨ cong suc p ⟩ q
_≤≡⟨_⟩_ : ∀ k → k ≤ l → l ≡ m → k ≤ m
_ ≤≡⟨ p ⟩ q = subst (λ l → _ ≤ l) q p
_<≡⟨_⟩_ : ∀ k → k < l → l ≡ m → k < m
_ <≡⟨ p ⟩ q = _ ≤≡⟨ p ⟩ q
| 29.144695
| 96
| 0.466461
|
2f9346dc0670469463dc35774b4f8de398c8f83f
| 359
|
agda
|
Agda
|
test/Succeed/CoinductiveAfterEvaluation.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/CoinductiveAfterEvaluation.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/CoinductiveAfterEvaluation.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --guardedness #-}
module CoinductiveAfterEvaluation where
open import Common.Coinduction
data Functor : Set where
Id : Functor
_·_ : Functor → Set → Set
Id · A = A
data ν (F : Functor) : Set where
inn : ∞ (F · ν F) → ν F
-- Evaluation is required to see that Id · ν Id is a coinductive type.
foo : ∀ F → F · ν F
foo Id = inn (♯ foo Id)
| 17.95
| 70
| 0.640669
|
1d114b489c89a630f1e96ceb7f6a8161d6fbd5d0
| 2,504
|
agda
|
Agda
|
nat-to-string.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
nat-to-string.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
nat-to-string.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module nat-to-string where
open import bool
open import char
open import eq
open import list
open import maybe
open import nat
open import nat-division
open import nat-thms
open import product
open import string
open import termination
module slow-ℕ-to-digits where
{- this version of ℕ-to-digits is statically shown terminating -- but the termination
reasoning makes it pretty slow in practice! -}
ℕ-to-digitsh : (base : ℕ) → 1 < base ≡ tt → (x : ℕ) → ↓𝔹 _>_ x → 𝕃 ℕ
ℕ-to-digitsh _ _ 0 _ = []
ℕ-to-digitsh base bp (suc x) (pf↓ fx) with (suc x) ÷ base ! (<=ℕff2 base bp)
... | q , r , p , _ = r :: (ℕ-to-digitsh base bp q (fx (÷<{base}{q}{r}{x} bp p)))
ℕ-to-digits : ℕ → 𝕃 ℕ
ℕ-to-digits x = reverse (ℕ-to-digitsh 10 refl x (↓-> x))
{-# TERMINATING #-}
ℕ-to-digitsh : (base : ℕ) → 1 < base ≡ tt → (x : ℕ) → 𝕃 ℕ
ℕ-to-digitsh _ _ 0 = []
ℕ-to-digitsh base bp (suc x) with (suc x) ÷ base ! (<=ℕff2 base bp)
... | q , r , p = r :: (ℕ-to-digitsh base bp q)
ℕ-to-digits : ℕ → 𝕃 ℕ
ℕ-to-digits x = reverse (ℕ-to-digitsh 10 refl x)
digit-to-string : ℕ → string
digit-to-string 0 = "0"
digit-to-string 1 = "1"
digit-to-string 2 = "2"
digit-to-string 3 = "3"
digit-to-string 4 = "4"
digit-to-string 5 = "5"
digit-to-string 6 = "6"
digit-to-string 7 = "7"
digit-to-string 8 = "8"
digit-to-string 9 = "9"
digit-to-string _ = "unexpected-digit"
digits-to-string : 𝕃 ℕ → string
digits-to-string [] = ""
digits-to-string (d :: ds) = (digit-to-string d) ^ (digits-to-string ds)
ℕ-to-string : ℕ → string
ℕ-to-string 0 = "0"
ℕ-to-string (suc x) = digits-to-string (ℕ-to-digits (suc x))
string-to-digit : char → maybe ℕ
string-to-digit '0' = just 0
string-to-digit '1' = just 1
string-to-digit '2' = just 2
string-to-digit '3' = just 3
string-to-digit '4' = just 4
string-to-digit '5' = just 5
string-to-digit '6' = just 6
string-to-digit '7' = just 7
string-to-digit '8' = just 8
string-to-digit '9' = just 9
string-to-digit _ = nothing
-- the digits are in order from least to most significant
digits-to-ℕh : ℕ → ℕ → 𝕃 ℕ → ℕ
digits-to-ℕh multiplier sum [] = sum
digits-to-ℕh multiplier sum (x :: xs) = digits-to-ℕh (10 * multiplier) (x * multiplier + sum) xs
digits-to-ℕ : 𝕃 ℕ → ℕ
digits-to-ℕ digits = digits-to-ℕh 1 0 digits
string-to-ℕ : string → maybe ℕ
string-to-ℕ s with 𝕃maybe-map string-to-digit (reverse (string-to-𝕃char s))
... | nothing = nothing
... | just ds = just (digits-to-ℕ ds)
string-to-ℕ0 : string → ℕ
string-to-ℕ0 s with string-to-ℕ s
... | nothing = 0
... | just x = x
| 29.116279
| 96
| 0.638978
|
57f87839b992fb1d3fb66d156002849281a4a51e
| 619
|
agda
|
Agda
|
Cubical/HITs/DunceCap/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/DunceCap/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/DunceCap/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.HITs.DunceCap.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.HITs.S1 using (S¹; base)
import Cubical.HITs.S1 as S¹
open import Cubical.HITs.MappingCones
-- definition of the dunce cap as a HIT
data Dunce : Type₀ where
base : Dunce
loop : base ≡ base
surf : PathP (λ i → loop i ≡ loop i) loop refl
-- definition of the dunce cap as a mapping cone
dunceMap : S¹ → S¹
dunceMap base = base
dunceMap (S¹.loop i) = (S¹.loop ⁻¹ ∙∙ S¹.loop ∙∙ S¹.loop) i
DunceCone : Type₀
DunceCone = Cone dunceMap
| 22.107143
| 59
| 0.71567
|
04468b9c261cb5747e68831bdee00ed4ad1dc9fc
| 718
|
agda
|
Agda
|
Chapter1/#2.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
Chapter1/#2.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
Chapter1/#2.agda
|
CodaFi/HoTT-Exercises
|
3411b253b0a49a5f9c3301df175ae8ecdc563b12
|
[
"MIT"
] | null | null | null |
module #2 where
open import Data.Product
open import Data.Sum
open import Relation.Binary.PropositionalEquality
{-
Exercise 1.2. Derive the recursion principle for products recA×B using only the projections, and
verify that the definitional equalities are valid. Do the same for Σ-types.
-}
module Products { a b c }{A : Set a}{B : Set b}{C : Set c}(g : A → B → C) where
recₓ : A × B → C
recₓ x = g (proj₁ x) (proj₂ x)
rec-β : (x : A)(y : B) → recₓ (x , y) ≡ g x y
rec-β x y = refl
module Sums { a b c }{A : Set a}{B : A → Set b}{C : Set c}(g : (x : A) → B x → C) where
rec-Σ : Σ A B → C
rec-Σ x = g (proj₁ x) (proj₂ x)
rec-Σ-β : (x : A)(y : B x) → rec-Σ (x , y) ≡ g x y
rec-Σ-β x y = refl
| 26.592593
| 96
| 0.590529
|
4b8f1b069d6877c006762621c00a3445df642b09
| 11,344
|
agda
|
Agda
|
Lambda/Closure/Equivalences.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | 1
|
2021-02-13T14:48:45.000Z
|
2021-02-13T14:48:45.000Z
|
Lambda/Closure/Equivalences.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
Lambda/Closure/Equivalences.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A very brief treatment of different kinds of term equivalences,
-- including contextual equivalence and applicative bisimilarity
------------------------------------------------------------------------
module Lambda.Closure.Equivalences where
open import Category.Monad.Partiality as Partiality
using (_⊥; later⁻¹; laterˡ⁻¹; laterʳ⁻¹)
open import Codata.Musical.Notation
open import Data.Fin using (Fin; zero)
open import Data.Maybe hiding (_>>=_)
open import Data.Maybe.Relation.Binary.Pointwise as Maybe
using (just; nothing)
open import Data.Nat
open import Data.Product as Prod
open import Data.Unit
open import Data.Vec using ([]; _∷_)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence
using (_⇔_; equivalence; module Equivalence)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open Partiality._⊥
private
open module EP {A : Set} = Partiality.Equality (_≡_ {A = A})
open module RP {A : Set} =
Partiality.Reasoning (P.isEquivalence {A = A})
open module RC {A : Set} =
Partiality.Reasoning {_∼_ = λ (_ _ : A) → ⊤} _
using () renaming (_≈⟨_⟩_ to _≈○⟨_⟩_; _∎ to _∎○)
open import Lambda.Closure.Functional
open PF using (return; _>>=_; fail)
open import Lambda.Syntax
open Closure Tm
------------------------------------------------------------------------
-- Two equivalent notions of equivalence of partial values
-- _≈○_ is a notion of weak bisimilarity which identifies all values.
open module EC {A : Set} = Partiality.Equality (λ (_ _ : A) → ⊤)
using () renaming (_≈_ to _≈○_)
-- _≈○_ is equivalent to "terminates iff terminates".
≈○⇔⇓≈⇓ : {A : Set} {x y : A ⊥} → x ≈○ y ⇔ (x ⇓ ⇔ y ⇓)
≈○⇔⇓≈⇓ {A} = equivalence
(λ x≈y → equivalence (h₁ x≈y) (h₁ (RC.sym x≈y)))
(h₂ _ _)
where
h₁ : {x y : A ⊥} → x ≈○ y → x ⇓ → y ⇓
h₁ (EC.now _) (v , now P.refl) = -, now P.refl
h₁ (EC.later x≈y) (v , laterˡ x⇓v) = Prod.map id laterˡ $ h₁ (♭ x≈y) (v , x⇓v)
h₁ (EC.laterʳ x≈y) (v , x⇓v) = Prod.map id laterˡ $ h₁ x≈y (v , x⇓v)
h₁ (EC.laterˡ x≈y) (v , laterˡ x⇓v) = h₁ x≈y (v , x⇓v)
h₂ : (x y : A ⊥) → x ⇓ ⇔ y ⇓ → x ≈○ y
h₂ (now v) y x⇓⇔y⇓ =
now v ≈○⟨ EC.now _ ⟩
now _ ≈○⟨ Partiality.map _ (sym $ proj₂ $ Equivalence.to x⇓⇔y⇓ ⟨$⟩ (-, now P.refl)) ⟩
y ∎○
h₂ x (now v) x⇓⇔y⇓ =
x ≈○⟨ Partiality.map _ ( proj₂ $ Equivalence.from x⇓⇔y⇓ ⟨$⟩ (-, now P.refl)) ⟩
now _ ≈○⟨ EC.now _ ⟩
now v ∎○
h₂ (later x) (later y) x⇓⇔y⇓ = EC.later (♯
h₂ (♭ x) (♭ y)
(equivalence (lemma (_⟨$⟩_ (Equivalence.to x⇓⇔y⇓)))
(lemma (_⟨$⟩_ (Equivalence.from x⇓⇔y⇓)))))
where
lemma : {A : Set} {x y : ∞ (A ⊥)} →
(later x ⇓ → later y ⇓) → (♭ x ⇓ → ♭ y ⇓)
lemma hyp (v , x⇓) = Prod.map id laterˡ⁻¹ $ hyp (v , laterˡ x⇓)
------------------------------------------------------------------------
-- Two equivalent definitions of contextual equivalence
-- Context m n consists of contexts with zero or more holes. The holes
-- expect terms of type Tm m, and if we fill those holes we get a term
-- of type Tm n.
infixl 9 _·_
data Context (m : ℕ) : ℕ → Set where
• : Context m m
con : ∀ {n} (i : ℕ) → Context m n
var : ∀ {n} (x : Fin n) → Context m n
ƛ : ∀ {n} (C : Context m (suc n)) → Context m n
_·_ : ∀ {n} (C₁ C₂ : Context m n) → Context m n
-- Fills all the holes.
infix 10 _[_]
_[_] : ∀ {m n} → Context m n → Tm m → Tm n
• [ t ] = t
con i [ t ] = con i
var x [ t ] = var x
ƛ C [ t ] = ƛ (C [ t ])
(C₁ · C₂) [ t ] = C₁ [ t ] · C₂ [ t ]
-- Contextual equivalence.
--
-- Termination is the only observation. This is perhaps a bit strange:
-- there is no way to observe the difference between con i and con j
-- for i ≢ j.
infix 4 _≈C_
_≈C_ : ∀ {n} → Tm n → Tm n → Set
t₁ ≈C t₂ = ∀ C → ⟦ C [ t₁ ] ⟧ [] ≈○ ⟦ C [ t₂ ] ⟧ []
-- Alternative definition of contextual equivalence.
infix 4 _≈C′_
_≈C′_ : ∀ {n} → Tm n → Tm n → Set
t₁ ≈C′ t₂ = ∀ C → ⟦ C [ t₁ ] ⟧ [] ⇓ ⇔ ⟦ C [ t₂ ] ⟧ [] ⇓
-- These definitions are equivalent.
≈C⇔≈C′ : ∀ {n} {t₁ t₂ : Tm n} → t₁ ≈C t₂ ⇔ t₁ ≈C′ t₂
≈C⇔≈C′ = equivalence
(λ t₁≈t₂ C → Equivalence.to ≈○⇔⇓≈⇓ ⟨$⟩ t₁≈t₂ C)
(λ t₁≈t₂ C → Equivalence.from ≈○⇔⇓≈⇓ ⟨$⟩ t₁≈t₂ C)
------------------------------------------------------------------------
-- A very strict term equivalence
-- A term equivalence defined directly on top of the semantics.
infix 4 _≈!_
_≈!_ : ∀ {n} → Tm n → Tm n → Set
t₁ ≈! t₂ = ∀ ρ → ⟦ t₁ ⟧ ρ ≈ ⟦ t₂ ⟧ ρ
-- This equivalence is not compatible.
--
-- Note that the proof does not use constants (con).
¬-compatible : ¬ ((t₁ t₂ : Tm 1) → t₁ ≈! t₂ → ƛ t₁ ≈! ƛ t₂)
¬-compatible ƛ-cong with
ƛ-cong (ƛ (vr 1) · ƛ (ƛ (vr 0))) (ƛ (vr 1) · ƛ (vr 0))
(λ _ → later (♯ now P.refl))
[]
... | now ()
------------------------------------------------------------------------
-- Incorrect definition of applicative bisimilarity
-- The difference between this definition and the one below is that in
-- this definition ƛ is inductive rather than coinductive.
module Incorrect where
infix 4 _≈mv_ _≈v_
-- _≈mv_, _≈c_ and _≈v_ are defined mutually (coinductively).
data _≈v_ : Value → Value → Set
-- Equivalence of possibly exceptional values.
_≈mv_ : Maybe Value → Maybe Value → Set
_≈mv_ = Maybe.Pointwise _≈v_
-- Equivalence of computations.
open module EA = Partiality.Equality _≈mv_
using () renaming (_≈_ to _≈c_)
-- Equivalence of values.
data _≈v_ where
con : ∀ {i} → con i ≈v con i
ƛ : ∀ {n₁} {t₁ : Tm (1 + n₁)} {ρ₁} {n₂} {t₂ : Tm (1 + n₂)} {ρ₂}
(t₁≈t₂ : ∀ v → ⟦ t₁ ⟧ (v ∷ ρ₁) ≈c ⟦ t₂ ⟧ (v ∷ ρ₂)) →
ƛ t₁ ρ₁ ≈v ƛ t₂ ρ₂
-- Applicative bisimilarity.
infix 4 _≈t_
_≈t_ : ∀ {n} → Tm n → Tm n → Set
t₁ ≈t t₂ = ∀ ρ → ⟦ t₁ ⟧ ρ ≈c ⟦ t₂ ⟧ ρ
-- This notion of applicative bisimilarity is not reflexive.
--
-- Note that the definition above is a bit strange in Agda: it is
-- subject to the quantifier inversion described by Thorsten
-- Altenkirch and myself in "Termination Checking in the Presence of
-- Nested Inductive and Coinductive Types". However, for this proof
-- it does not matter if _≈c_ is seen as having the form
-- μX.νY.μZ. F X Y Z or νX.μY. F X Y; the ν part is never used.
mutual
distinct-c : ¬ now (just (ƛ (var zero) [])) ≈c
now (just (ƛ (var zero) []))
distinct-c (now eq) = distinct-mv eq
distinct-mv : ¬ just (ƛ (var zero) []) ≈mv
just (ƛ (var zero) [])
distinct-mv (just eq) = distinct-v eq
distinct-v : ¬ ƛ (var zero) [] ≈v ƛ (var zero) []
distinct-v (ƛ eq) = distinct-c (eq (ƛ (var zero) []))
distinct-t : ¬ ƛ (var zero) ≈t (Tm 0 ∋ ƛ (var zero))
distinct-t eq = distinct-c (eq [])
------------------------------------------------------------------------
-- Applicative bisimilarity
infix 4 _≈mv_ _≈v_
-- _≈mv_, _≈c_ and _≈v_ are defined mutually (coinductively).
data _≈v_ : Value → Value → Set
-- Equivalence of possibly exceptional values.
_≈mv_ : Maybe Value → Maybe Value → Set
_≈mv_ = Maybe.Pointwise _≈v_
-- Equivalence of computations.
open module EA = Partiality.Equality _≈mv_
using () renaming (_≈_ to _≈c_)
-- Equivalence of values.
data _≈v_ where
con : ∀ {i} → con i ≈v con i
ƛ : ∀ {n₁} {t₁ : Tm (1 + n₁)} {ρ₁} {n₂} {t₂ : Tm (1 + n₂)} {ρ₂}
(t₁≈t₂ : ∀ v → ∞ (⟦ t₁ ⟧ (v ∷ ρ₁) ≈c ⟦ t₂ ⟧ (v ∷ ρ₂))) →
ƛ t₁ ρ₁ ≈v ƛ t₂ ρ₂
-- Applicative bisimilarity.
infix 4 _≈t_
_≈t_ : ∀ {n} → Tm n → Tm n → Set
t₁ ≈t t₂ = ∀ ρ → ⟦ t₁ ⟧ ρ ≈c ⟦ t₂ ⟧ ρ
-- Applicative bisimilarity is reflexive.
mutual
infix 3 _∎mv _∎c _∎v
_∎mv : (v : Maybe Value) → v ≈mv v
just v ∎mv = just (v ∎v)
nothing ∎mv = nothing
_∎c : (x : Maybe Value ⊥) → x ≈c x
now mv ∎c = EA.now (mv ∎mv)
later x ∎c = EA.later (♯ (♭ x ∎c))
_∎v : (v : Value) → v ≈v v
con i ∎v = con
ƛ t ρ ∎v = ƛ (λ v → ♯ (⟦ t ⟧ (v ∷ ρ) ∎c))
infix 3 _∎t
_∎t : ∀ {n} (t : Tm n) → t ≈t t
t ∎t = λ ρ → ⟦ t ⟧ ρ ∎c
-- Applicative bisimilarity is symmetric.
mutual
sym-mv : ∀ {v₁ v₂} → v₁ ≈mv v₂ → v₂ ≈mv v₁
sym-mv (just v₁≈v₂) = just (sym-v v₁≈v₂)
sym-mv nothing = nothing
sym-c : ∀ {x₁ x₂} → x₁ ≈c x₂ → x₂ ≈c x₁
sym-c (EA.now v₁≈v₂) = EA.now (sym-mv v₁≈v₂)
sym-c (EA.later x₁≈x₂) = EA.later (♯ sym-c (♭ x₁≈x₂))
sym-c (EA.laterˡ x₁≈x₂) = EA.laterʳ (sym-c x₁≈x₂)
sym-c (EA.laterʳ x₁≈x₂) = EA.laterˡ (sym-c x₁≈x₂)
sym-v : ∀ {v₁ v₂} → v₁ ≈v v₂ → v₂ ≈v v₁
sym-v con = con
sym-v (ƛ t₁≈t₂) = ƛ (λ v → ♯ sym-c (♭ (t₁≈t₂ v)))
sym-t : ∀ {n} {t₁ t₂ : Tm n} → t₁ ≈t t₂ → t₂ ≈t t₁
sym-t t₁≈t₂ = λ ρ → sym-c (t₁≈t₂ ρ)
-- Applicative bisimilarity is transitive.
mutual
trans-mv : ∀ {v₁ v₂ v₃} → v₁ ≈mv v₂ → v₂ ≈mv v₃ → v₁ ≈mv v₃
trans-mv (just v₁≈v₂) (just v₂≈v₃) = just (trans-v v₁≈v₂ v₂≈v₃)
trans-mv nothing nothing = nothing
private
now-trans-c : ∀ {x₁ x₂ v₃} → x₁ ≈c x₂ → x₂ ≈c now v₃ → x₁ ≈c now v₃
now-trans-c (EA.now v₁≈v₂) (EA.now v₂≈v₃) = EA.now (trans-mv v₁≈v₂ v₂≈v₃)
now-trans-c (EA.laterˡ x₁≈x₂) x₂≈v₃ = EA.laterˡ (now-trans-c x₁≈x₂ x₂≈v₃)
now-trans-c x₁≈lx₂ (EA.laterˡ x₂≈v₃) = now-trans-c (laterʳ⁻¹ x₁≈lx₂) x₂≈v₃
later-trans-c : ∀ {x₁ x₂ x₃} →
x₁ ≈c x₂ → x₂ ≈c later x₃ → x₁ ≈c later x₃
later-trans-c (EA.later x₁≈x₂) lx₂≈lx₃ = EA.later (♯ trans-c (♭ x₁≈x₂) (later⁻¹ lx₂≈lx₃))
later-trans-c (EA.laterˡ x₁≈x₂) x₂≈lx₃ = EA.later (♯ trans-c x₁≈x₂ (laterʳ⁻¹ x₂≈lx₃))
later-trans-c (EA.laterʳ x₁≈x₂) lx₂≈lx₃ = later-trans-c x₁≈x₂ (laterˡ⁻¹ lx₂≈lx₃)
later-trans-c x₁≈x₂ (EA.laterʳ x₂≈x₃) = EA.laterʳ ( trans-c x₁≈x₂ x₂≈x₃ )
trans-c : ∀ {x₁ x₂ x₃} → x₁ ≈c x₂ → x₂ ≈c x₃ → x₁ ≈c x₃
trans-c {x₃ = now v₃} x₁≈x₂ x₂≈v₃ = now-trans-c x₁≈x₂ x₂≈v₃
trans-c {x₃ = later z₃} x₁≈x₂ x₂≈lx₃ = later-trans-c x₁≈x₂ x₂≈lx₃
trans-v : ∀ {v₁ v₂ v₃} → v₁ ≈v v₂ → v₂ ≈v v₃ → v₁ ≈v v₃
trans-v con con = con
trans-v (ƛ t₁≈t₂) (ƛ t₂≈t₃) =
ƛ (λ v → ♯ trans-c (♭ (t₁≈t₂ v)) (♭ (t₂≈t₃ v)))
trans-t : ∀ {n} {t₁ t₂ t₃ : Tm n} → t₁ ≈t t₂ → t₂ ≈t t₃ → t₁ ≈t t₃
trans-t t₁≈t₂ t₂≈t₃ = λ ρ → trans-c (t₁≈t₂ ρ) (t₂≈t₃ ρ)
-- Bind preserves applicative bisimilarity.
infixl 1 _>>=-cong-c_
_>>=-cong-c_ : ∀ {x₁ x₂ f₁ f₂} →
x₁ ≈c x₂ → (∀ {v₁ v₂} → v₁ ≈v v₂ → f₁ v₁ ≈c f₂ v₂) →
(x₁ >>= f₁) ≈c (x₂ >>= f₂)
_>>=-cong-c_ {f₁ = f₁} {f₂} x₁≈x₂ f₁≈f₂ =
Partiality._>>=-cong_ x₁≈x₂ helper
where
helper : ∀ {mv₁ mv₂} → mv₁ ≈mv mv₂ →
maybe f₁ fail mv₁ ≈c maybe f₂ fail mv₂
helper nothing = EA.now nothing
helper (just v₁≈v₂) = f₁≈f₂ v₁≈v₂
-- _≈!_ is stronger than applicative bisimilarity.
≈!⇒≈t : ∀ {n} {t₁ t₂ : Tm n} → t₁ ≈! t₂ → t₁ ≈t t₂
≈!⇒≈t t₁≈t₂ = λ ρ →
Partiality.map (λ {v₁} v₁≡v₂ → P.subst (_≈mv_ v₁) v₁≡v₂ (v₁ ∎mv))
(t₁≈t₂ ρ)
¬≈t⇒≈! : ¬ ((t₁ t₂ : Tm 0) → t₁ ≈t t₂ → t₁ ≈! t₂)
¬≈t⇒≈! hyp with hyp t₁ t₂ bisimilar []
where
t₁ : Tm 0
t₁ = ƛ (ƛ (vr 0)) · con 0
t₂ : Tm 0
t₂ = ƛ (vr 0)
bisimilar : t₁ ≈t t₂
bisimilar [] =
EA.laterˡ (EA.now (just (ƛ (λ v → ♯ (return v ∎c)))))
... | laterˡ (now ())
| 30.994536
| 103
| 0.530765
|
9a9cfcce6d1643c14a1ecbda2af2aaf7f07b222e
| 401
|
agda
|
Agda
|
src/Util/Relation/Binary/Closure/SymmetricTransitive.agda
|
JLimperg/msc-thesis-code
|
104cddc6b65386c7e121c13db417aebfd4b7a863
|
[
"MIT"
] | 5
|
2021-04-13T21:31:17.000Z
|
2021-06-26T06:37:31.000Z
|
src/Util/Relation/Binary/Closure/SymmetricTransitive.agda
|
JLimperg/msc-thesis-code
|
104cddc6b65386c7e121c13db417aebfd4b7a863
|
[
"MIT"
] | null | null | null |
src/Util/Relation/Binary/Closure/SymmetricTransitive.agda
|
JLimperg/msc-thesis-code
|
104cddc6b65386c7e121c13db417aebfd4b7a863
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Util.Relation.Binary.Closure.SymmetricTransitive where
open import Relation.Binary using (Rel)
open import Util.Prelude
data SymTrans {α ρ} {A : Set α} (R : Rel A ρ) : Rel A (α ⊔ℓ ρ) where
`base : ∀ {x y} → R x y → SymTrans R x y
`sym : ∀ {x y} → SymTrans R y x → SymTrans R x y
`trans : ∀ {x y z} → SymTrans R x y → SymTrans R y z → SymTrans R x z
| 30.846154
| 71
| 0.628429
|
2ee082575d0451d4eaa9f58291c8d4b8ab25692a
| 506
|
agda
|
Agda
|
test/Fail/Issue958b.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue958b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue958b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
open import Imports.Issue958
-- Extra parameterised module to make sure checkpoints line up with
-- the checkpoints in the imported module.
module Dummy (X : Set) where
module M (_ fun : IsFunctor) where
open IsFunctor
-- Here we're in the "same" checkpoint as when the display form was
-- created. It's not the same though, so the display form should be
-- generalized and lifted to the appropriate context.
test : map fun
test = fun
-- EXPECTED: IsFunctor !=< map fun
| 24.095238
| 69
| 0.72332
|
3df3f3e888f3d7fb6976e997a66fc3272d0303f1
| 1,258
|
agda
|
Agda
|
src/Implicits/Resolution/Scala/Terminates.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Implicits/Resolution/Scala/Terminates.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Implicits/Resolution/Scala/Terminates.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
open import Prelude
module Implicits.Resolution.Scala.Terminates where
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Resolution.Infinite.Algorithm
open import Implicits.Resolution.Scala.Type
open import Category.Monad.Partiality
open import Category.Monad.Partiality as P
open Workaround
open import Category.Monad.Partiality.All using (All; module Alternative)
open Alternative renaming (sound to AllP-sound) hiding (complete)
private
open import Relation.Binary.PropositionalEquality as PEq using (_≡_)
open module PartialEq = P.Equality {A = Bool} _≡_
open module PartialReasoning = P.Reasoning (PEq.isEquivalence {A = Bool})
match-terminates : ∀ {ν} (Δ : ICtx ν) → (τ : SimpleType ν) → (r : Type ν) → (match Δ τ r) ⇓
match-terminates Δ τ r = ?
match1st-terminates : ∀ {ν} (Δ : ICtx ν) → (ρs : ICtx ν) → (τ : SimpleType ν) → (match1st Δ ρs τ) ⇓
match1st-terminates Δ List.[] τ = false , (now refl)
match1st-terminates Δ (x List.∷ ρs) τ = {!!}
terminates : ∀ {ν} (Δ : ICtx ν) (a : Type ν) → ScalaICtx Δ → ScalaType a → (resolve Δ a) ⇓
terminates Δ (simpl x) p q = match1st-terminates Δ Δ x
terminates Δ (∀' a) p (∀' q) = terminates (ictx-weaken Δ) a (weaken-scalaictx p) q
terminates Δ (a ⇒ b) p ()
| 39.3125
| 99
| 0.715421
|
132c9dfb5242f064ac0c1e19f9cc45b351805aff
| 1,521
|
agda
|
Agda
|
src/Implicits/Syntax/Type/Unification.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Implicits/Syntax/Type/Unification.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Implicits/Syntax/Type/Unification.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
open import Prelude
module Implicits.Syntax.Type.Unification where
open import Data.Maybe as Maybe
open import Data.Unit
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification.McBride as McBride using (
substitute; asub; AList; _//_) public
open import Data.Vec.Properties
open import Data.Nat as N using ()
open import Data.Nat.Properties.Simple
open import Category.Monad
open import Data.Fin.Substitution
open import Implicits.Substitutions
open import Implicits.Syntax.MetaType public
open import Implicits.Substitutions.Lemmas
open McBride using (substitute; asub; AList; ASub; _//_; asub-weaken) public
private
module M = MetaTypeMetaSubst
module T = MetaTypeTypeSubst
-- Just a bit stricter than mcbride.mgu
-- We require here as well that all meta variables are instantiated
-- (this is equivalent to the ⊢unamb constraint in Oliveira)
mgu : ∀ {m ν} (a : MetaType m ν) → (b : SimpleType ν) → Maybe (Sub (flip MetaType ν) m zero)
mgu a b with McBride.mgu a (simpl b)
mgu a b | just (zero , u) = just (asub u)
mgu a b | just (suc m , _) = nothing
mgu a b | nothing = nothing
Unifier : ∀ {m ν} → (MetaType m ν) → SimpleType ν → (Sub (flip MetaType ν) m zero) → Set
Unifier {m} a b u = from-meta (a M./ u) ≡ (simpl b)
Unifiable : ∀ {m ν} → (MetaType m ν) → SimpleType ν → Set
Unifiable a τ = ∃ (Unifier a τ)
◁-Unifiable : ∀ {m ν} → MetaType m ν → SimpleType ν → Set
◁-Unifiable x τ = Unifiable (x M.◁m) τ
meta-weaken = M.weaken
smeta-weaken = M.smeta-weaken
open-meta = M.open-meta
| 33.065217
| 92
| 0.722551
|
1a2eb7f674ec4561c12315c884c154bf40eaf02f
| 2,749
|
agda
|
Agda
|
src/Data/QuadTree/Implementation/PropDepthRelation.agda
|
JonathanBrouwer/research-project
|
4959a3c9cd8563a1726e0e968e6a179008cd4d9f
|
[
"Unlicense"
] | 1
|
2021-05-25T09:10:20.000Z
|
2021-05-25T09:10:20.000Z
|
src/Data/QuadTree/Implementation/PropDepthRelation.agda
|
JonathanBrouwer/research-project
|
4959a3c9cd8563a1726e0e968e6a179008cd4d9f
|
[
"Unlicense"
] | null | null | null |
src/Data/QuadTree/Implementation/PropDepthRelation.agda
|
JonathanBrouwer/research-project
|
4959a3c9cd8563a1726e0e968e6a179008cd4d9f
|
[
"Unlicense"
] | null | null | null |
module Data.QuadTree.Implementation.PropDepthRelation where
open import Haskell.Prelude
open import Data.Logic
---- Properties of depth
lteTransitiveWeird : (x y d : Nat) -> IsTrue (x < y) -> (y <= d) ≡ ((x <= d) && (y <= d))
lteTransitiveWeird zero zero zero xlty = refl
lteTransitiveWeird zero zero (suc d) xlty = refl
lteTransitiveWeird zero (suc y) zero xlty = refl
lteTransitiveWeird zero (suc y) (suc d) xlty = refl
lteTransitiveWeird (suc x) (suc y) zero xlty = refl
lteTransitiveWeird (suc x) (suc y) (suc d) xlty = lteTransitiveWeird x y d xlty
lteTransitiveWeirdInv : (x y d : Nat) -> IsFalse (x < y) -> (x <= d) ≡ ((x <= d) && (y <= d))
lteTransitiveWeirdInv zero zero zero xnlty = refl
lteTransitiveWeirdInv zero zero (suc d) xnlty = refl
lteTransitiveWeirdInv (suc x) zero zero xnlty = refl
lteTransitiveWeirdInv (suc x) zero (suc d) xnlty =
begin
(suc x <= suc d)
=⟨ sym $ boolAndTrue (suc x <= suc d) ⟩
(suc x <= suc d) && true
=⟨⟩
((suc x <= suc d) && (zero <= suc d))
end
lteTransitiveWeirdInv (suc x) (suc y) zero xnlty = refl
lteTransitiveWeirdInv (suc x) (suc y) (suc d) xnlty = lteTransitiveWeirdInv x y d xnlty
ifComparisonMap : (x y d : Nat) -> ((x <= d) && (y <= d)) ≡ (if x < y then (y <= d) else (x <= d))
ifComparisonMap x y d = ifc x < y
then (λ {{xlty}} ->
begin
(x <= d) && (y <= d)
=⟨ sym $ lteTransitiveWeird x y d xlty ⟩
y <= d
=⟨ sym $ ifTrue (x < y) xlty ⟩
(if x < y then (y <= d) else (x <= d))
end
)
else (λ {{xnlty}} ->
begin
(x <= d) && (y <= d)
=⟨ sym $ lteTransitiveWeirdInv x y d xnlty ⟩
x <= d
=⟨ sym $ ifFalse (x < y) xnlty ⟩
(if x < y then (y <= d) else (x <= d))
end
)
propMaxLte : (x y d : Nat) -> ((x <= d) && (y <= d)) ≡ (max x y <= d)
propMaxLte x y d =
begin
(x <= d) && (y <= d)
=⟨ ifComparisonMap x y d ⟩
(if x < y then (y <= d) else (x <= d))
=⟨ propFnIf (λ v -> v <= d) ⟩
(if x < y then y else x) <= d
=⟨⟩
max x y <= d
end
propAndMap : (a b c d : Bool) -> a ≡ c -> b ≡ d -> (a && b) ≡ (c && d)
propAndMap false false false false ac bd = refl
propAndMap false true false true ac bd = refl
propAndMap true false true false ac bd = refl
propAndMap true true true true ac bd = refl
propMaxLte4 : (w x y z d : Nat) -> (((w <= d) && (x <= d)) && ((y <= d) && (z <= d))) ≡ (max (max w x) (max y z) <= d)
propMaxLte4 w x y z d =
begin
((w <= d) && (x <= d)) && ((y <= d) && (z <= d))
=⟨ propAndMap ((w <= d) && (x <= d)) ((y <= d) && (z <= d)) (max w x <= d) (max y z <= d) (propMaxLte w x d) (propMaxLte y z d) ⟩
(max w x <= d) && (max y z <= d)
=⟨ propMaxLte (if w < x then x else w) (if y < z then z else y) d ⟩
(max (max w x) (max y z) <= d)
end
| 34.797468
| 131
| 0.545289
|
0409ecda60bdf59158f42ba37078cbd3c11a2a98
| 3,531
|
agda
|
Agda
|
Cats/Category/Cat.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Category/Cat.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Category/Cat.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 1
|
2019-03-18T15:35:07.000Z
|
2019-03-18T15:35:07.000Z
|
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Cat where
open import Cats.Functor public using (Functor ; _∘_ ; id)
open import Data.Product using (_,_)
open import Data.Unit using (⊤ ; tt)
open import Level
open import Relation.Binary using
(IsEquivalence ; _Preserves_⟶_ ; _Preserves₂_⟶_⟶_)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open import Cats.Category.Base
open import Cats.Category.Zero
open import Cats.Category.One
open import Cats.Trans.Iso as NatIso using (NatIso ; iso ; forth-natural)
import Cats.Category.Constructions.Iso as Iso
open Functor
open Iso.Build._≅_
private
module ≅ {lo la l≈} (C : Category lo la l≈) = Iso.Build.≅ C
_⇒_ : ∀ {lo la l≈ lo′ la′ l≈′}
→ Category lo la l≈ → Category lo′ la′ l≈′ → Set _
C ⇒ D = Functor C D
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
where
infixr 4 _≈_
_≈_ : (F G : C ⇒ D) → Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′)
F ≈ G = NatIso F G
equiv : IsEquivalence _≈_
equiv = record
{ refl = NatIso.id
; sym = NatIso.sym
; trans = λ eq₁ eq₂ → eq₂ NatIso.∘ eq₁
}
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
where
∘-resp : ∀ {lo″ la″ l≈″} {E : Category lo″ la″ l≈″}
→ {F G : D ⇒ E} {H I : C ⇒ D}
→ F ≈ G
→ H ≈ I
→ F ∘ H ≈ G ∘ I
∘-resp {E = E} {F} {G} {H} {I}
record { iso = F≅G ; forth-natural = fnat-GH }
record { iso = H≅I ; forth-natural = fnat-HI }
= record
{ iso = ≅.trans E F≅G (fobj-resp G H≅I)
; forth-natural = λ {_} {_} {f} →
begin
(fmap G (forth H≅I) E.∘ forth F≅G) E.∘ fmap F (fmap H f)
≈⟨ E.assoc ⟩
fmap G (forth H≅I) E.∘ forth F≅G E.∘ fmap F (fmap H f)
≈⟨ E.∘-resp-r fnat-GH ⟩
fmap G (forth H≅I) E.∘ fmap G (fmap H f) E.∘ forth F≅G
≈⟨ E.unassoc ⟩
(fmap G (forth H≅I) E.∘ fmap G (fmap H f)) E.∘ forth F≅G
≈⟨ E.∘-resp-l (fmap-∘ G) ⟩
fmap G (forth H≅I D.∘ fmap H f) E.∘ forth F≅G
≈⟨ E.∘-resp-l (fmap-resp G fnat-HI) ⟩
fmap G (fmap I f D.∘ forth H≅I) E.∘ forth F≅G
≈⟨ E.∘-resp-l (E.≈.sym (fmap-∘ G)) ⟩
(fmap G (fmap I f) E.∘ fmap G (forth H≅I)) E.∘ forth F≅G
≈⟨ E.assoc ⟩
fmap G (fmap I f) E.∘ fmap G (forth H≅I) E.∘ forth F≅G
∎
}
where
module D = Category D
module E = Category E
open E.≈-Reasoning
id-r : {F : C ⇒ D} → F ∘ id ≈ F
id-r {F} = record
{ iso = ≅.refl D
; forth-natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
where
module D = Category D
id-l : {F : C ⇒ D} → id ∘ F ≈ F
id-l {F} = record
{ iso = ≅.refl D
; forth-natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
where
module D = Category D
assoc : ∀ {lo″ la″ l≈″ lo‴ la‴ l≈‴}
→ {E : Category lo″ la″ l≈″} {X : Category lo‴ la‴ l≈‴}
→ (F : E ⇒ X) (G : D ⇒ E) (H : C ⇒ D)
→ (F ∘ G) ∘ H ≈ F ∘ (G ∘ H)
assoc {E = E} {X} _ _ _ = record
{ iso = ≅.refl X
; forth-natural = X.≈.trans X.id-l (X.≈.sym X.id-r)
}
where
module X = Category X
Cat : ∀ lo la l≈
→ Category (suc (lo ⊔ la ⊔ l≈)) (lo ⊔ la ⊔ l≈) (lo ⊔ la ⊔ l≈)
Cat lo la l≈ = record
{ Obj = Category lo la l≈
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = equiv
; ∘-resp = ∘-resp
; id-r = id-r
; id-l = id-l
; assoc = λ {_} {_} {_} {_} {F} {G} {H} → assoc F G H
}
| 26.155556
| 73
| 0.492778
|
1aa8e00c317c6c38870969d358cf747bba66dd94
| 1,809
|
agda
|
Agda
|
examples/Termination/Nat.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/Termination/Nat.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/Termination/Nat.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Nat where
data Rel (A : Set) : Set1 where
rel : (A -> A -> Set) -> Rel A
_is_than_ : {A : Set} -> A -> Rel A -> A -> Set
x is rel f than y = f x y
data Acc {A : Set} (less : Rel A) (x : A) : Set where
acc : ((y : A) -> x is less than y -> Acc less y) -> Acc less x
data WO {A : Set} (less : Rel A) : Set where
wo : ((x : A) -> Acc less x) -> WO less
data False : Set where
data True : Set where
tt : True
data Nat : Set where
Z : Nat
S : Nat -> Nat
data ∏ {A : Set} (f : A -> Set) : Set where
∏I : ((z : A) -> f z) -> ∏ f
ltNat : Nat -> Nat -> Set
ltNat Z Z = False
ltNat Z (S n) = True
ltNat (S m) (S n) = ltNat m n
ltNat (S m) Z = False
ltNatRel : Rel Nat
ltNatRel = rel ltNat
postulate woltNat : WO ltNatRel
idN : Nat -> Nat
idN x = x
id : {A : Set} -> A -> A
id x = x
down1 : Nat -> Nat
down1 Z = Z
down1 (S n) = down1 n
-- measure down1 = (woNat, id)
-- For a function f : (x:A) -> B(x)
-- f(p) = ... f(x1) ... f(x2)
-- measure_set : Set
-- measure_rel : Rel measure_set
-- measure_ord : WO measure_rel
-- measure_fun : A -> measure_set
-- For j-th call of f in i-th clause of f:
-- measure_i_j_hint : xj is measure_rel than p
data Measure : Set1 where
μ : {M : Set} -> {rel : Rel M} -> (ord : WO rel) -> Measure
{-
down1_measure_set : Set
down1_measure_set = Nat
down1_measure_rel : Rel down1_measure_set
down1_measure_rel = ltNatRel
down1_measure_ord : WO measure_rel
down1_measure_ord = woltNat
-}
down1-measure : Measure
down1-measure = μ woltNat
down1-2-1-hint : (n : Nat) -> n is ltNatRel than (S n)
down1-2-1-hint Z = tt
down1-2-1-hint (S n) = down1-2-1-hint n
{-
down2 : Nat -> Nat
down2 Z = Z
down2 (S n) = down2 (idN n)
down3 : Nat -> Nat
down3 Z = Z
down3 (S n) = down3 (id n)
plus : Nat -> Nat -> Nat
plus Z n = n
plus (S m) n = S(plus m n)
-}
| 19.663043
| 65
| 0.590381
|
31faa976d2240ccdf63a98d55978859ed534faaa
| 1,317
|
agda
|
Agda
|
src/Fragment/Algebra/Properties.agda
|
yallop/agda-fragment
|
f2a6b1cf4bc95214bd075a155012f84c593b9496
|
[
"MIT"
] | 18
|
2021-06-15T15:45:39.000Z
|
2022-01-17T17:26:09.000Z
|
src/Fragment/Algebra/Properties.agda
|
yallop/agda-fragment
|
f2a6b1cf4bc95214bd075a155012f84c593b9496
|
[
"MIT"
] | 1
|
2021-06-16T09:44:31.000Z
|
2021-06-16T10:24:15.000Z
|
src/Fragment/Algebra/Properties.agda
|
yallop/agda-fragment
|
f2a6b1cf4bc95214bd075a155012f84c593b9496
|
[
"MIT"
] | 3
|
2021-06-15T15:34:50.000Z
|
2021-06-16T08:04:31.000Z
|
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Properties where
open import Fragment.Algebra.Algebra
open import Fragment.Algebra.Free
open import Level using (Level)
open import Data.Nat using (ℕ)
open import Data.Vec using (Vec; []; _∷_)
private
variable
a ℓ : Level
mutual
map-extend : ∀ {Σ O a n} → {A : Set a}
→ Vec (Term Σ A) n
→ Vec (Term (Σ ⦅ O ⦆) A) n
map-extend [] = []
map-extend (x ∷ xs) = extend x ∷ map-extend xs
extend : ∀ {Σ O} → {A : Set a}
→ Term Σ A → Term (Σ ⦅ O ⦆) A
extend (atom x) = atom x
extend (term f xs) = term (oldₒ f) (map-extend xs)
forgetₒ : ∀ {Σ O} → Algebra (Σ ⦅ O ⦆) {a} {ℓ} → Algebra Σ {a} {ℓ}
forgetₒ {Σ = Σ} A = record { ∥_∥/≈ = ∥ A ∥/≈
; ∥_∥/≈-isAlgebra = forget-isAlgebra
}
where forget-⟦_⟧ : Interpretation Σ ∥ A ∥/≈
forget-⟦ f ⟧ x = A ⟦ oldₒ f ⟧ x
forget-⟦⟧-cong : Congruence Σ ∥ A ∥/≈ forget-⟦_⟧
forget-⟦⟧-cong f x = (A ⟦ oldₒ f ⟧-cong) x
forget-isAlgebra : IsAlgebra Σ ∥ A ∥/≈
forget-isAlgebra = record { ⟦_⟧ = forget-⟦_⟧
; ⟦⟧-cong = forget-⟦⟧-cong
}
| 29.266667
| 65
| 0.495824
|
4ba58730399dfbc6e509548129f1ec3b881e92b9
| 505
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Char.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
src/data/lib/prim/Agda/Builtin/Char.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
src/data/lib/prim/Agda/Builtin/Char.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2021-04-01T18:30:09.000Z
|
2021-04-01T18:30:09.000Z
|
{-# OPTIONS --without-K --safe --no-universe-polymorphism --no-sized-types --no-guardedness #-}
module Agda.Builtin.Char where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
postulate Char : Set
{-# BUILTIN CHAR Char #-}
primitive
primIsLower primIsDigit primIsAlpha primIsSpace primIsAscii
primIsLatin1 primIsPrint primIsHexDigit : Char → Bool
primToUpper primToLower : Char → Char
primCharToNat : Char → Nat
primNatToChar : Nat → Char
primCharEquality : Char → Char → Bool
| 28.055556
| 95
| 0.750495
|
13d719c2fd63f6dd877570b0befc04b9663b5ce7
| 1,166
|
agda
|
Agda
|
Numeral/Natural/Relation/Properties.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Relation/Properties.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Relation/Properties.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Relation.Properties where
import Lvl
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Induction
open import Numeral.Natural.Relation
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function.Domain
open import Structure.Operator.Properties
open import Structure.Relator.Ordering
open import Structure.Relator.Properties
open import Type
[ℕ]-zero-or-nonzero : ∀{n : ℕ} → (n ≡ 𝟎)∨(n ≢ 𝟎)
[ℕ]-zero-or-nonzero {𝟎} = [∨]-introₗ [≡]-intro
[ℕ]-zero-or-nonzero {𝐒(_)} = [∨]-introᵣ \()
[≡][ℕ]-excluded-middle : ∀{a b : ℕ} → (a ≡ b)∨(a ≢ b)
[≡][ℕ]-excluded-middle {𝟎} {𝟎} = [∨]-introₗ [≡]-intro
[≡][ℕ]-excluded-middle {𝟎} {𝐒(_)} = [∨]-introᵣ \()
[≡][ℕ]-excluded-middle {𝐒(_)}{𝟎} = [∨]-introᵣ \()
[≡][ℕ]-excluded-middle {𝐒(a)}{𝐒(b)} = [∨]-elim ([∨]-introₗ ∘ [≡]-with(𝐒)) ([∨]-introᵣ ∘ (contrapositiveᵣ(injective(𝐒)))) ([≡][ℕ]-excluded-middle {a}{b})
| 37.612903
| 152
| 0.686106
|
2ef01610b7a43051e9815a6c4353005c28f9df86
| 720
|
agda
|
Agda
|
test/Succeed/Issue2727.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2727.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2727.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
open import Agda.Builtin.Equality using (_≡_; refl)
-- First example --
module M (A : Set) where
record R : Set where
data D : Set where
open R (record {})
postulate
x : A
F : D → Set₁
F _ rewrite refl {x = x} = Set
-- Second example --
record ⊤ : Set where
no-eta-equality
constructor tt
data Box (A : Set) : Set where
[_] : A → Box A
Unit : Set
Unit = Box ⊤
F : Unit → Set → Set
F [ _ ] x = x
G : {P : Unit → Set} → ((x : ⊤) → P [ x ]) → ((x : Unit) → P x)
G f [ x ] = f x
record R : Set₁ where
no-eta-equality
field
f : (x : Unit) → Box (F x ⊤)
data ⊥ : Set where
r : R
r = record { f = G [_] }
open R r
H : ⊥ → Set₁
H _ rewrite refl {x = tt} = Set
| 13.584906
| 63
| 0.533333
|
04657132a85f6b9b0267073316911f70c4e674fb
| 104
|
agda
|
Agda
|
src/Extensions/Fin.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Extensions/Fin.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Extensions/Fin.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
module Extensions.Fin where
open import Prelude
open import Data.Fin hiding (_<_)
open import Data.Nat
| 17.333333
| 33
| 0.798077
|
d06648168e36676e7375c834c1b4f73173d52c0d
| 151
|
agda
|
Agda
|
test/Succeed/Imports/Issue5583.agda
|
MxmUrw/agda
|
6ede01fa854c5472e54f7d1799ca2c08ed316129
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Imports/Issue5583.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Imports/Issue5583.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Unit
module Imports.Issue5583 (_ : ⊤) where
it : ∀ {A : Set} → ⦃ A ⦄ → A
it ⦃ x ⦄ = x
data X : Set where
instance x : X
| 13.727273
| 38
| 0.582781
|
0489857f026e004f6d805e48b6709842b76abb32
| 26,178
|
agda
|
Agda
|
delta-lemmas.agda
|
nickcollins/dependent-dicts-agda
|
db857f3e7dc9a4793f68504e6365d93ed75d7f88
|
[
"MIT"
] | null | null | null |
delta-lemmas.agda
|
nickcollins/dependent-dicts-agda
|
db857f3e7dc9a4793f68504e6365d93ed75d7f88
|
[
"MIT"
] | null | null | null |
delta-lemmas.agda
|
nickcollins/dependent-dicts-agda
|
db857f3e7dc9a4793f68504e6365d93ed75d7f88
|
[
"MIT"
] | null | null | null |
open import Prelude
open import Nat
open import List
open import Bij
module delta-lemmas (K : Set) {{bij : bij K Nat}} where
-- abbreviations for conversion between K and Nat
key : Nat → K
key = convert-inv {{bij}}
nat : K → Nat
nat = bij.convert bij
-- another bij-related convenience functions
inj-cp : ∀{k1 k2} → k1 ≠ k2 → nat k1 ≠ nat k2
inj-cp ne eq = abort (ne (bij.inj bij eq))
-- helper function
delta : ∀{n m} → n < m → Nat
delta n<m = difference (n<m→1+n≤m n<m)
-- raw underlying list-of-pairs type
dl : (V : Set) → Set
dl V = List (Nat ∧ V)
---- helper definitions ----
_lkup_ : {V : Set} → dl V → Nat → Maybe V
[] lkup x = None
((hn , hv) :: t) lkup n with <dec n hn
... | Inl n<hn = None
... | Inr (Inl refl) = Some hv
... | Inr (Inr hn<n) = t lkup (delta hn<n)
_,,'_ : ∀{V} → dl V → (Nat ∧ V) → dl V
[] ,,' (n , v) = (n , v) :: []
((hn , hv) :: t) ,,' (n , v) with <dec n hn
... | Inl n<hn = (n , v) :: ((delta n<hn , hv) :: t)
... | Inr (Inl refl) = (n , v) :: t
... | Inr (Inr hn<n) = (hn , hv) :: (t ,,' (delta hn<n , v))
data _∈'_ : {V : Set} (p : Nat ∧ V) → (d : dl V) → Set where
InH : {V : Set} {d : dl V} {n : Nat} {v : V} →
(n , v) ∈' ((n , v) :: d)
InT : {V : Set} {d : dl V} {n s : Nat} {v v' : V} →
(n , v) ∈' d →
(n + 1+ s , v) ∈' ((s , v') :: d)
dom' : {V : Set} → dl V → Nat → Set
dom' {V} d n = Σ[ v ∈ V ] ((n , v) ∈' d)
_#'_ : {V : Set} (n : Nat) → (d : dl V) → Set
n #' d = dom' d n → ⊥
---- lemmas ----
undelta : (x s : Nat) → (x<s+1+x : x < s + 1+ x) → s == delta x<s+1+x
undelta x s x<s+1+x
rewrite n+1+m==1+n+m {s} {x} | ! (m-n==1+m-1+n n≤m+n (n<m→1+n≤m x<s+1+x)) | +comm {s} {x}
= ! (n+m-n==m n≤n+m)
n#'[] : {V : Set} {n : Nat} → _#'_ {V} n []
n#'[] (_ , ())
too-small : {V : Set} {d : dl V} {xl xb : Nat} {v : V} →
xl < xb →
dom' ((xb , v) :: d) xl →
⊥
too-small (_ , ne) (_ , InH) = ne refl
too-small (x+1+xb≤xb , x+1+xb==xb) (_ , InT _) =
x+1+xb==xb (≤antisym x+1+xb≤xb (≤trans (≤1+ ≤refl) n≤m+n))
all-not-none : {V : Set} {d : dl V} {x : Nat} {v : V} →
None ≠ (((x , v) :: d) lkup x)
all-not-none {x = x} rewrite <dec-refl x = λ ()
all-bindings-==-rec-eq : {V : Set} {d1 d2 : dl V} {x : Nat} {v : V} →
((x' : Nat) → ((x , v) :: d1) lkup x' == ((x , v) :: d2) lkup x') →
((x' : Nat) → d1 lkup x' == d2 lkup x')
all-bindings-==-rec-eq {x = x} h x'
with h (x' + 1+ x)
... | eq
with <dec (x' + 1+ x) x
... | Inl x'+1+x<x
= abort (<antisym x'+1+x<x (n<m→n<s+m n<1+n))
... | Inr (Inl x'+1+x==x)
= abort ((flip n≠n+1+m) (n+1+m==1+n+m · (+comm {1+ x} · x'+1+x==x)))
... | Inr (Inr x<x'+1+x)
rewrite ! (undelta x x' x<x'+1+x) = eq
all-bindings-==-rec : {V : Set} {d1 d2 : dl V} {x1 x2 : Nat} {v1 v2 : V} →
((x : Nat) → ((x1 , v1) :: d1) lkup x == ((x2 , v2) :: d2) lkup x) →
((x : Nat) → d1 lkup x == d2 lkup x)
all-bindings-==-rec {x1 = x1} {x2} h x
with h x1 | h x2
... | eq1 | eq2
rewrite <dec-refl x1 | <dec-refl x2
with <dec x1 x2 | <dec x2 x1
... | Inl _ | _
= abort (somenotnone eq1)
... | Inr _ | Inl _
= abort (somenotnone (! eq2))
... | Inr (Inl refl) | Inr (Inl refl)
rewrite someinj eq1 | someinj eq2
= all-bindings-==-rec-eq h x
... | Inr (Inl refl) | Inr (Inr x2<x2)
= abort (<antirefl x2<x2)
... | Inr (Inr x2<x2) | Inr (Inl refl)
= abort (<antirefl x2<x2)
... | Inr (Inr x2<x1) | Inr (Inr x1<x2)
= abort (<antisym x1<x2 x2<x1)
sad-lemma : {V : Set} {d : dl V} {x n : Nat} {v v' : V} →
(x + 1+ n , v') ∈' ((n , v) :: d) →
Σ[ x' ∈ Nat ] Σ[ d' ∈ dl V ] (
d' == ((n , v) :: d) ∧
x' == x + 1+ n ∧
(x' , v') ∈' d')
sad-lemma h = _ , _ , refl , refl , h
lemma-math' : ∀{x x1 n} → x ≠ x1 + (n + 1+ x)
lemma-math' {x} {x1} {n}
rewrite ! (+assc {x1} {n} {1+ x})
| n+1+m==1+n+m {x1 + n} {x}
| +comm {1+ x1 + n} {x}
= n≠n+1+m
lookup-cons-2' : {V : Set} {d : dl V} {n : Nat} {v : V} → d lkup n == Some v → (n , v) ∈' d
lookup-cons-2' {d = []} ()
lookup-cons-2' {d = ((hn , hv) :: t)} {n} h
with <dec n hn
lookup-cons-2' {d = ((hn , hv) :: t)} {n} () | Inl _
lookup-cons-2' {d = ((hn , hv) :: t)} {.hn} refl | Inr (Inl refl) = InH
lookup-cons-2' {d = ((hn , hv) :: t)} {n} {v} h | Inr (Inr hn<n)
= tr
(λ y → (y , v) ∈' ((hn , hv) :: t))
(m-n+n==m (n<m→1+n≤m hn<n))
(InT (lookup-cons-2' {d = t} h))
lookup-cons-1' : {V : Set} {d : dl V} {n : Nat} {v : V} →
(n , v) ∈' d →
d lkup n == Some v
lookup-cons-1' {n = x} InH rewrite <dec-refl x = refl
lookup-cons-1' (InT {d = d} {n = x} {s} {v} x∈d)
with <dec (x + 1+ s) s
... | Inl x+1+s<s = abort (<antisym x+1+s<s (n<m→n<s+m n<1+n))
... | Inr (Inl x+1+s==s) = abort ((flip n≠n+1+m) (n+1+m==1+n+m · (+comm {1+ s} · x+1+s==s)))
... | Inr (Inr s<x+1+s)
with lookup-cons-1' x∈d
... | h rewrite ! (undelta s x s<x+1+s) = h
n,v∈'d,,n,v : {V : Set} {d : dl V} {n : Nat} {v : V} → (n , v) ∈' (d ,,' (n , v))
n,v∈'d,,n,v {d = []} {n} {v} = InH
n,v∈'d,,n,v {d = ((hn , hv) :: t)} {n} {v}
with <dec n hn
... | Inl _ = InH
... | Inr (Inl refl) = InH
... | Inr (Inr hn<n) =
tr
(λ y → (y , v) ∈' ((hn , hv) :: (t ,,' (delta hn<n , v))))
(m-n+n==m (n<m→1+n≤m hn<n))
(InT (n,v∈'d,,n,v {d = t} {delta hn<n}))
n∈d+→'n∈d : {V : Set} {d : dl V} {n n' : Nat} {v v' : V} →
n ≠ n' →
(n , v) ∈' (d ,,' (n' , v')) →
(n , v) ∈' d
n∈d+→'n∈d {d = []} n≠n' InH = abort (n≠n' refl)
n∈d+→'n∈d {d = []} n≠n' (InT ())
n∈d+→'n∈d {d = (hn , hv) :: t} {n' = n'} n≠n' n∈d+
with <dec n' hn
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = n'} n≠n' InH | Inl n'<hn = abort (n≠n' refl)
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = n'} n≠n' (InT InH) | Inl n'<hn
rewrite m-n+n==m (n<m→1+n≤m n'<hn) = InH
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = n'} n≠n' (InT (InT {n = n} n∈d+)) | Inl n'<hn
rewrite +assc {n} {1+ (delta n'<hn)} {1+ n'} | m-n+n==m (n<m→1+n≤m n'<hn)
= InT n∈d+
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = .hn} n≠n' InH | Inr (Inl refl) = abort (n≠n' refl)
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = .hn} n≠n' (InT n∈d+) | Inr (Inl refl) = InT n∈d+
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = n'} n≠n' InH | Inr (Inr hn<n') = InH
n∈d+→'n∈d {_} {(hn , hv) :: t} {n' = n'} n≠n' (InT n∈d+) | Inr (Inr hn<n')
= InT (n∈d+→'n∈d (λ where refl → n≠n' (m-n+n==m (n<m→1+n≤m hn<n'))) n∈d+)
n∈d→'n∈d+ : {V : Set} {d : dl V} {n n' : Nat} {v v' : V} →
n ≠ n' →
(n , v) ∈' d →
(n , v) ∈' (d ,,' (n' , v'))
n∈d→'n∈d+ {n = n} {n'} {v} {v'} n≠n' (InH {d = d'})
with <dec n' n
... | Inl n'<n
= tr
(λ y → (y , v) ∈' ((n' , v') :: ((delta n'<n , v) :: d')))
(m-n+n==m (n<m→1+n≤m n'<n))
(InT InH)
... | Inr (Inl refl) = abort (n≠n' refl)
... | Inr (Inr n<n') = InH
n∈d→'n∈d+ {n = .(_ + 1+ _)} {n'} {v} {v'} n≠n' (InT {d = d} {n} {s} {v' = v''} n∈d)
with <dec n' s
... | Inl n'<s
= tr
(λ y → (y , v) ∈' ((n' , v') :: ((delta n'<s , v'') :: d)))
((+assc {b = 1+ (delta n'<s)}) · (ap1 (n +_) (1+ap (m-n+n==m (n<m→1+n≤m n'<s)))))
(InT (InT n∈d))
... | Inr (Inl refl) = InT n∈d
... | Inr (Inr s<n') =
InT (n∈d→'n∈d+ (λ where refl → n≠n' (m-n+n==m (n<m→1+n≤m s<n'))) n∈d)
mem-dec' : {V : Set} (d : dl V) (n : Nat) → dom' d n ∨ n #' d
mem-dec' [] n = Inr (λ ())
mem-dec' ((hn , hv) :: t) n
with <dec n hn
... | Inl n<hn = Inr (too-small n<hn)
... | Inr (Inl refl) = Inl (hv , InH)
... | Inr (Inr hn<n)
with mem-dec' t (delta hn<n)
mem-dec' ((hn , hv) :: t) n | Inr (Inr hn<n) | Inl (v , rec) =
Inl (v , tr
(λ y → (y , v) ∈' ((hn , hv) :: t))
(m-n+n==m (n<m→1+n≤m hn<n))
(InT rec))
mem-dec' {V} ((hn , hv) :: t) n | Inr (Inr hn<n) | Inr dne =
Inr n∉d
where
n∉d : Σ[ v ∈ V ] ((n , v) ∈' ((hn , hv) :: t)) → ⊥
n∉d (_ , n∈d) with n∈d
... | InH = (π2 hn<n) refl
... | InT {n = s} n-hn-1∈t
rewrite ! (undelta hn s hn<n) = dne (_ , n-hn-1∈t)
extensional' : {V : Set} {d1 d2 : dl V} →
((n : Nat) → d1 lkup n == d2 lkup n) →
d1 == d2
extensional' {d1 = []} {[]} all-bindings-== = refl
extensional' {d1 = []} {(hn2 , hv2) :: t2} all-bindings-==
= abort (all-not-none {d = t2} {x = hn2} (all-bindings-== hn2))
extensional' {d1 = (hn1 , hv1) :: t1} {[]} all-bindings-==
= abort (all-not-none {d = t1} {x = hn1} (! (all-bindings-== hn1)))
extensional' {d1 = (hn1 , hv1) :: t1} {(hn2 , hv2) :: t2} all-bindings-==
rewrite extensional' {d1 = t1} {t2} (all-bindings-==-rec all-bindings-==)
with all-bindings-== hn1 | all-bindings-== hn2
... | hv1== | hv2== rewrite <dec-refl hn1 | <dec-refl hn2
with <dec hn1 hn2 | <dec hn2 hn1
... | Inl hn1<hn2 | _
= abort (somenotnone hv1==)
... | Inr (Inl refl) | Inl hn2<hn1
= abort (somenotnone (! hv2==))
... | Inr (Inr hn2<hn1) | Inl hn2<'hn1
= abort (somenotnone (! hv2==))
... | Inr (Inl refl) | Inr _
rewrite someinj hv1== = refl
... | Inr (Inr hn2<hn1) | Inr (Inl refl)
rewrite someinj hv2== = refl
... | Inr (Inr hn2<hn1) | Inr (Inr hn1<hn2)
= abort (<antisym hn1<hn2 hn2<hn1)
==-dec' : {V : Set}
(d1 d2 : dl V) →
((v1 v2 : V) → v1 == v2 ∨ v1 ≠ v2) →
d1 == d2 ∨ d1 ≠ d2
==-dec' [] [] _ = Inl refl
==-dec' [] (_ :: _) _ = Inr (λ ())
==-dec' (_ :: _) [] _ = Inr (λ ())
==-dec' ((hn1 , hv1) :: t1) ((hn2 , hv2) :: t2) V==dec
with natEQ hn1 hn2 | V==dec hv1 hv2 | ==-dec' t1 t2 V==dec
... | Inl refl | Inl refl | Inl refl = Inl refl
... | Inl refl | Inl refl | Inr ne = Inr λ where refl → ne refl
... | Inl refl | Inr ne | _ = Inr λ where refl → ne refl
... | Inr ne | _ | _ = Inr λ where refl → ne refl
delete' : {V : Set} {d : dl V} {n : Nat} {v : V} →
(n , v) ∈' d →
Σ[ d⁻ ∈ dl V ] (
d == d⁻ ,,' (n , v) ∧
n #' d⁻)
delete' {d = (n' , v') :: d} {n} n∈d
with <dec n n'
... | Inl n<n' = abort (too-small n<n' (_ , n∈d))
delete' {_} {(n' , v') :: []} {.n'} InH | Inr (Inl _) = [] , refl , λ ()
delete' {_} {(n' , v') :: ((n'' , v'') :: d)} {.n'} InH | Inr (Inl _)
= ((n'' + 1+ n' , v'') :: d) , lem , λ {(_ , n'∈d+) → abort (too-small (n<m→n<s+m n<1+n) (_ , n'∈d+))}
where
lem : ((n' , v') :: ((n'' , v'') :: d)) == ((n'' + 1+ n' , v'') :: d) ,,' (n' , v')
lem
with <dec n' (n'' + 1+ n')
lem | Inl n'<n''+1+n' rewrite ! (undelta n' n'' n'<n''+1+n') = refl
lem | Inr (Inl false) = abort (lemma-math' {x1 = Z} false)
lem | Inr (Inr false) = abort (<antisym false (n<m→n<s+m n<1+n))
delete' {d = (n' , v') :: d} InH | Inr (Inr n'<n') = abort (<antirefl n'<n')
delete' {d = (n' , v') :: d} (InT n∈d) | Inr _
with delete' {d = d} n∈d
delete' {d = (n' , v') :: d} {.(_ + 1+ n')} {v} (InT {n = x} n∈d) | Inr _ | d⁻ , refl , x#d⁻
= _ , lem' , lem
where
lem : (x + 1+ n') #' ((n' , v') :: d⁻)
lem (_ , x+1+n'∈d?)
with sad-lemma x+1+n'∈d?
... | _ , _ , refl , n'==x+1+n' , InH = abort (lemma-math' {x1 = Z} n'==x+1+n')
... | _ , _ , refl , n'==x+1+n' , InT x+1+n'∈d'
rewrite +inj {b = 1+ n'} n'==x+1+n'
= x#d⁻ (_ , x+1+n'∈d')
lem' : ((n' , v') :: (d⁻ ,,' (x , v))) == (((n' , v') :: d⁻) ,,' (x + 1+ n' , v))
lem'
with <dec (x + 1+ n') n'
lem' | Inl x+1+n'<n' = abort (<antisym x+1+n'<n' (n<m→n<s+m n<1+n))
lem' | Inr (Inl false) = abort (lemma-math' {x1 = Z} (! false))
lem' | Inr (Inr n'<x+1+n') rewrite ! (undelta n' x n'<x+1+n') = refl
extend-size' : {V : Set} {d : dl V} {n : Nat} {v : V} →
n #' d →
∥ d ,,' (n , v) ∥ == 1+ ∥ d ∥
extend-size' {d = []} n#d = refl
extend-size' {d = (n' , v') :: d} {n} n#d
with <dec n n'
... | Inl n<n' = refl
... | Inr (Inl refl) = abort (n#d (_ , InH))
... | Inr (Inr n'<n)
= 1+ap (extend-size' λ {(v , diff∈d) →
n#d (v , tr
(λ y → (y , v) ∈' ((n' , v') :: d))
(m-n+n==m (n<m→1+n≤m n'<n))
(InT diff∈d))})
---- contrapositives of some previous lemmas ----
lookup-dec' : {V : Set} (d : dl V) (n : Nat) →
Σ[ v ∈ V ] (d lkup n == Some v) ∨ d lkup n == None
lookup-dec' d n
with d lkup n
... | Some v = Inl (v , refl)
... | None = Inr refl
lookup-cp-2' : {V : Set} {d : dl V} {n : Nat} →
n #' d →
d lkup n == None
lookup-cp-2' {d = d} {n} n#d
with lookup-dec' d n
... | Inl (_ , n∈d) = abort (n#d (_ , lookup-cons-2' n∈d))
... | Inr n#'d = n#'d
n#d→'n#d+ : {V : Set} {d : dl V} {n n' : Nat} {v' : V} →
n ≠ n' →
n #' d →
n #' (d ,,' (n' , v'))
n#d→'n#d+ {d = d} {n} {n'} {v'} n≠n' n#d
with mem-dec' (d ,,' (n' , v')) n
... | Inl (_ , n∈d+) = abort (n#d (_ , n∈d+→'n∈d n≠n' n∈d+))
... | Inr n#d+ = n#d+
---- union, and dlt <=> list conversion definitions
merge' : {V : Set} → (V → V → V) → Maybe V → V → V
merge' merge ma1 v2
with ma1
... | None = v2
... | Some v1 = merge v1 v2
union' : {V : Set} → (V → V → V) → dl V → dl V → Nat → dl V
union' merge d1 [] _ = d1
union' merge d1 ((hn , hv) :: d2) offset
with d1 ,,' (hn + offset , merge' merge (d1 lkup hn + offset) hv)
... | d1+ = union' merge d1+ d2 (1+ hn + offset)
dlt⇒list' : {V : Set} (d : dl V) → dl V
dlt⇒list' [] = []
dlt⇒list' ((x , v) :: d) = (x , v) :: map (λ {(x' , v') → x' + 1+ x , v'}) (dlt⇒list' d)
list⇒dlt' : {V : Set} (d : dl V) → dl V
list⇒dlt' = foldr _,,'_ []
---- union, dlt <=> list, etc lemmas ----
lemma-union'-0 : {V : Set} {m : V → V → V} {d1 d2 : dl V} {x n : Nat} {v : V} →
(x , v) ∈' d1 →
(x , v) ∈' (union' m d1 d2 (n + 1+ x))
lemma-union'-0 {d2 = []} x∈d1 = x∈d1
lemma-union'-0 {d2 = (x1 , v1) :: d2} {x} {n} x∈d1
rewrite ! (+assc {1+ x1} {n} {1+ x})
= lemma-union'-0 {d2 = d2} {n = 1+ x1 + n} (n∈d→'n∈d+ (lemma-math' {x1 = x1} {n}) x∈d1)
lemma-union'-1 : {V : Set} {m : V → V → V} {d1 d2 : dl V} {x n : Nat} {v : V} →
(x , v) ∈' d1 →
(n≤x : n ≤ x) →
(difference n≤x) #' d2 →
(x , v) ∈' (union' m d1 d2 n)
lemma-union'-1 {d2 = []} {x} x∈d1 n≤x x-n#d2 = x∈d1
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2
with <dec x (x1 + n)
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inl x<x1+n
with d1 lkup x1 + n
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inl x<x1+n | Some v'
with expr-eq (λ _ → d1 ,,' (x1 + n , m v' v1))
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inl x<x1+n | Some v' | d1+ , refl
= tr
(λ y → (x , v) ∈' (union' m d1+ d2 y))
(n+1+m==1+n+m {difference (π1 x<x1+n)} · 1+ap (m-n+n==m (π1 x<x1+n)))
(lemma-union'-0 {d2 = d2} (n∈d→'n∈d+ (π2 x<x1+n) x∈d1))
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inl x<x1+n | None
with expr-eq (λ _ → d1 ,,' (x1 + n , v1))
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inl x<x1+n | None | d1+ , refl
= tr
(λ y → (x , v) ∈' (union' m d1+ d2 y))
(n+1+m==1+n+m {difference (π1 x<x1+n)} · 1+ap (m-n+n==m (π1 x<x1+n)))
(lemma-union'-0 {d2 = d2} (n∈d→'n∈d+ (π2 x<x1+n) x∈d1))
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inr (Inl refl)
rewrite +comm {x1} {n} | n+m-n==m n≤x
= abort (x-n#d2 (_ , InH))
lemma-union'-1 {m = m} {d1} {(x1 , v1) :: d2} {x} {n} {v} x∈d1 n≤x x-n#d2 | Inr (Inr x1+n<x)
rewrite (! (a+b==c→a==c-b (+assc {delta x1+n<x} · m-n+n==m (n<m→1+n≤m x1+n<x)) n≤x))
= lemma-union'-1
(n∈d→'n∈d+ (flip (π2 x1+n<x)) x∈d1)
(n<m→1+n≤m x1+n<x)
λ {(_ , x-x1-n∈d2) → x-n#d2 (_ , InT x-x1-n∈d2)}
lemma-union'-2 : {V : Set} {m : V → V → V} {d1 d2 : dl V} {x n : Nat} {v : V} →
(x + n) #' d1 →
(x , v) ∈' d2 →
(x + n , v) ∈' (union' m d1 d2 n)
lemma-union'-2 {d1 = d1} x+n#d1 (InH {d = d2})
rewrite lookup-cp-2' x+n#d1
= lemma-union'-0 {d2 = d2} {n = Z} (n,v∈'d,,n,v {d = d1})
lemma-union'-2 {d1 = d1} {n = n} x+n#d1 (InT {d = d2} {n = x} {s} x∈d2)
rewrite +assc {x} {1+ s} {n}
with d1 lkup s + n
... | Some v'
= lemma-union'-2
(λ {(_ , x∈d1+) →
x+n#d1 (_ , n∈d+→'n∈d (flip (lemma-math' {x1 = Z})) x∈d1+)})
x∈d2
... | None
= lemma-union'-2
(λ {(_ , x∈d1+) →
x+n#d1 (_ , n∈d+→'n∈d (flip (lemma-math' {x1 = Z})) x∈d1+)})
x∈d2
lemma-union'-3 : {V : Set} {m : V → V → V} {d1 d2 : dl V} {x n : Nat} {v1 v2 : V} →
(x + n , v1) ∈' d1 →
(x , v2) ∈' d2 →
(x + n , m v1 v2) ∈' (union' m d1 d2 n)
lemma-union'-3 {d1 = d1} x+n∈d1 (InH {d = d2})
rewrite lookup-cons-1' x+n∈d1
= lemma-union'-0 {d2 = d2} {n = Z} (n,v∈'d,,n,v {d = d1})
lemma-union'-3 {d1 = d1} {n = n} x+n∈d1 (InT {d = d2} {n = x} {s} x∈d2)
rewrite +assc {x} {1+ s} {n}
with d1 lkup s + n
... | Some v'
= lemma-union'-3 (n∈d→'n∈d+ (flip (lemma-math' {x1 = Z})) x+n∈d1) x∈d2
... | None
= lemma-union'-3 (n∈d→'n∈d+ (flip (lemma-math' {x1 = Z})) x+n∈d1) x∈d2
lemma-union'-4 : {V : Set} {m : V → V → V} {d1 d2 : dl V} {x n : Nat} →
dom' (union' m d1 d2 n) x →
dom' d1 x ∨ (Σ[ s ∈ Nat ] (x == n + s ∧ dom' d2 s))
lemma-union'-4 {d2 = []} x∈un = Inl x∈un
lemma-union'-4 {d1 = d1} {(x1 , _) :: d2} {x} {n} x∈un
with lemma-union'-4 {d2 = d2} x∈un
... | Inr (s , refl , _ , s∈d2)
rewrite +comm {x1} {n}
| ! (n+1+m==1+n+m {n + x1} {s})
| +assc {n} {x1} {1+ s}
| +comm {x1} {1+ s}
| ! (n+1+m==1+n+m {s} {x1})
= Inr (_ , refl , _ , InT s∈d2)
... | Inl (_ , x∈d1+)
with natEQ x (n + x1)
... | Inl refl = Inr (_ , refl , _ , InH)
... | Inr x≠n+x1
rewrite +comm {x1} {n}
= Inl (_ , n∈d+→'n∈d x≠n+x1 x∈d1+)
dlt⇒list-size' : {V : Set} {d : dl V} → ∥ dlt⇒list' d ∥ == ∥ d ∥
dlt⇒list-size' {d = []} = refl
dlt⇒list-size' {d = _ :: d} = 1+ap (map-len · dlt⇒list-size')
dlt⇒list-In-1' : {V : Set} {d : dl V} {n : Nat} {v : V} →
(n , v) ∈' d →
(n , v) In dlt⇒list' d
dlt⇒list-In-1' InH = LInH
dlt⇒list-In-1' (InT ∈h) = LInT <| map-In <| dlt⇒list-In-1' ∈h
too-small-list : {V : Set} {d : dl V} {m m' : Nat} {v : V} →
m ≤ m' →
(m , v) In (map (λ { (n'' , v'') → n'' + 1+ m' , v'' }) (dlt⇒list' d)) →
⊥
too-small-list {d = (n2 , v2) :: d} n≤n' LInH
= abort (lemma-math' {x1 = Z} (≤antisym (≤trans n≤m+n (n≤m+n {m = n2})) n≤n'))
too-small-list {d = (n2 , v2) :: d} {m} {m'} {v} m≤m' (LInT in')
= too-small-list (≤trans m≤m' (≤trans n≤m+n (n≤m+n {m = n2}))) rec-in
where
rec-in =
tr
(λ y → (m , v) In y)
(map^2
{f = (λ { (n'' , v'') → n'' + 1+ m' , v'' })}
{(λ { (n'' , v'') → n'' + 1+ n2 , v'' })}
{dlt⇒list' d}
·
map-ext (λ where (n'' , v'') → ap1 (λ y' → y' , v'') <| +assc {n''} {b = 1+ n2} {c = 1+ m'}))
in'
dlt⇒list-In-2' : {V : Set} {d : dl V} {n : Nat} {v : V} →
(n , v) In dlt⇒list' d →
(n , v) ∈' d
dlt⇒list-In-2' {d = _ :: d} LInH = InH
dlt⇒list-In-2' {d = (n' , v') :: d} {n} (LInT in')
with <dec n n'
... | Inl n<n' = abort (too-small-list (π1 n<n') in')
... | Inr (Inl refl) = abort (too-small-list ≤refl in')
... | Inr (Inr n'<n)
with n<m→s+1+n=m n'<n
... | _ , refl = InT (dlt⇒list-In-2' (lem2 in'))
where
lem1 : ∀{V l} {m1 m2 : Nat} {vv1 vv2 : V} →
m1 ≠ m2 →
(in'' : (m1 , vv1) In ((m2 , vv2) :: l)) →
Σ[ in2 ∈ ((m1 , vv1) In l) ] (in'' == LInT in2)
lem1 ne LInH = abort (ne refl)
lem1 ne (LInT in'') = in'' , refl
lem2 : ∀{V s l} {vv : V} →
(s + 1+ n' , vv) In map (λ { (n'' , v'') → n'' + 1+ n' , v'' }) l →
(s , vv) In l
lem2 {s = s} {(n2 , v2) :: l} in''
with natEQ s n2
lem2 {s = s} {(s , v2) :: l} LInH | Inl refl = LInH
lem2 {s = s} {(s , v2) :: l} (LInT in'') | Inl refl = LInT (lem2 in'')
... | Inr ne
with lem1 (+inj-cp ne) in''
... | in2 , refl = LInT (lem2 in2)
list⇒dlt-In' : {V : Set} {l : dl V} {n : Nat} {v : V} →
(n , v) ∈' list⇒dlt' l →
(n , v) In l
list⇒dlt-In' {l = (n' , v') :: l} {n} ∈h
rewrite foldl-++ {l1 = reverse l} {(n' , v') :: []} {_,,'_} {[]}
with natEQ n n'
... | Inr ne = LInT (list⇒dlt-In' (n∈d+→'n∈d ne ∈h))
... | Inl refl
rewrite someinj <| (! <| lookup-cons-1' ∈h) · (lookup-cons-1' {n = n} {v'} <| n,v∈'d,,n,v {d = foldl _,,'_ [] (reverse l)})
= LInH
list⇒dlt-order' : {V : Set} {l1 l2 : dl V} {n : Nat} {v1 v2 : V} →
(n , v1) ∈' (list⇒dlt' ((n , v1) :: l1 ++ ((n , v2) :: l2)))
list⇒dlt-order' {l1 = l1} {l2} {n} {v1} {v2}
rewrite foldl-++ {l1 = reverse (l1 ++ ((n , v2) :: l2))} {(n , v1) :: []} {_,,'_} {[]}
= n,v∈'d,,n,v {d = foldl _,,'_ [] <| reverse (l1 ++ ((n , v2) :: l2))}
bij-pair-1 : {V : Set} (nv : Nat ∧ V) → (nat <| key <| π1 nv , π2 nv) == nv
bij-pair-1 (n , v) rewrite convert-bij2 {t = n} = refl
bij-pair-2 : {V : Set} (kv : K ∧ V) → (key <| nat <| π1 kv , π2 kv) == kv
bij-pair-2 (k , v) rewrite convert-bij1 {f = k} = refl
dltmap-func' : {V1 V2 : Set} {d : dl V1} {f : V1 → V2} {n : Nat} {v : V1} →
(map (λ { (hn , hv) → hn , f hv }) (d ,,' (n , v)))
==
(map (λ { (hn , hv) → hn , f hv }) d ,,' (n , f v))
dltmap-func' {d = []} = refl
dltmap-func' {d = (nh , vh) :: d} {f = f} {n}
with <dec n nh
... | Inl n<nh = refl
... | Inr (Inl refl) = refl
... | Inr (Inr nh<n) = ap1 ((nh , f vh) ::_) (dltmap-func' {d = d})
-- these proofs could use refactoring -
-- contraction should probably make use of ==-dec'
-- and exchange is way too long and repetitive
contraction' : {V : Set} {d : dl V} {n : Nat} {v v' : V} → (d ,,' (n , v')) ,,' (n , v) == d ,,' (n , v)
contraction' {d = []} {n} rewrite <dec-refl n = refl
contraction' {d = (hn , hv) :: t} {n} {v} {v'}
with <dec n hn
... | Inl _ rewrite <dec-refl n = refl
... | Inr (Inl refl) rewrite <dec-refl hn = refl
... | Inr (Inr hn<n)
with <dec n hn
... | Inl n<hn = abort (<antisym n<hn hn<n)
... | Inr (Inl refl) = abort (<antirefl hn<n)
... | Inr (Inr hn<'n)
with contraction' {d = t} {delta hn<'n} {v} {v'}
... | eq
rewrite diff-proof-irrelevance (n<m→1+n≤m hn<n) (n<m→1+n≤m hn<'n) | eq
= refl
exchange' : {V : Set} {d : dl V} {n1 n2 : Nat} {v1 v2 : V} →
n1 ≠ n2 →
(d ,,' (n1 , v1)) ,,' (n2 , v2) == (d ,,' (n2 , v2)) ,,' (n1 , v1)
exchange' {V} {d} {n1} {n2} {v1} {v2} n1≠n2 = extensional' fun
where
fun : (n : Nat) →
((d ,,' (n1 , v1)) ,,' (n2 , v2)) lkup n ==
((d ,,' (n2 , v2)) ,,' (n1 , v1)) lkup n
fun n
with natEQ n n1 | natEQ n n2 | mem-dec' d n
fun n | Inl refl | Inl refl | _
= abort (n1≠n2 refl)
fun n1 | Inl refl | Inr n≠n2 | Inl (_ , n1∈d)
with n,v∈'d,,n,v {d = d} {n1} {v1}
... | n∈d+1
with n∈d→'n∈d+ {v' = v2} n≠n2 n∈d+1 | n,v∈'d,,n,v {d = d ,,' (n2 , v2)} {n1} {v1}
... | n∈d++1 | n∈d++2
rewrite lookup-cons-1' n∈d++1 | lookup-cons-1' n∈d++2 = refl
fun n1 | Inl refl | Inr n≠n2 | Inr n1#d
with n,v∈'d,,n,v {d = d} {n1} {v1}
... | n∈d+1
with n∈d→'n∈d+ {v' = v2} n≠n2 n∈d+1 | n,v∈'d,,n,v {d = d ,,' (n2 , v2)} {n1} {v1}
... | n∈d++1 | n∈d++2
rewrite lookup-cons-1' n∈d++1 | lookup-cons-1' n∈d++2 = refl
fun n2 | Inr n≠n1 | Inl refl | Inl (_ , n2∈d)
with n,v∈'d,,n,v {d = d} {n2} {v2}
... | n∈d+2
with n∈d→'n∈d+ {v' = v1} n≠n1 n∈d+2 | n,v∈'d,,n,v {d = d ,,' (n1 , v1)} {n2} {v2}
... | n∈d++1 | n∈d++2
rewrite lookup-cons-1' n∈d++1 | lookup-cons-1' n∈d++2 = refl
fun n2 | Inr n≠n1 | Inl refl | Inr n2#d
with n,v∈'d,,n,v {d = d} {n2} {v2}
... | n∈d+2
with n∈d→'n∈d+ {v' = v1} n≠n1 n∈d+2 | n,v∈'d,,n,v {d = d ,,' (n1 , v1)} {n2} {v2}
... | n∈d++1 | n∈d++2
rewrite lookup-cons-1' n∈d++1 | lookup-cons-1' n∈d++2 = refl
fun n | Inr n≠n1 | Inr n≠n2 | Inl (_ , n∈d)
with n∈d→'n∈d+ {v' = v1} n≠n1 n∈d | n∈d→'n∈d+ {v' = v2} n≠n2 n∈d
... | n∈d+1 | n∈d+2
with n∈d→'n∈d+ {v' = v2} n≠n2 n∈d+1 | n∈d→'n∈d+ {v' = v1} n≠n1 n∈d+2
... | n∈d++1 | n∈d++2
rewrite lookup-cons-1' n∈d++1 | lookup-cons-1' n∈d++2 = refl
fun n | Inr n≠n1 | Inr n≠n2 | Inr n#d
with n#d→'n#d+ {v' = v1} n≠n1 n#d | n#d→'n#d+ {v' = v2} n≠n2 n#d
... | n#d+1 | n#d+2
with n#d→'n#d+ {v' = v2} n≠n2 n#d+1 | n#d→'n#d+ {v' = v1} n≠n1 n#d+2
... | n#d++1 | n#d++2
rewrite lookup-cp-2' n#d++1 | lookup-cp-2' n#d++2 = refl
| 41.420886
| 127
| 0.392238
|
59237ceac539e1305e37ed6382bd30764d333bd5
| 4,044
|
agda
|
Agda
|
test/Succeed/test-recons.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | 1
|
2020-04-26T09:35:17.000Z
|
2020-04-26T09:35:17.000Z
|
test/Succeed/test-recons.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/test-recons.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | 1
|
2020-05-16T20:10:05.000Z
|
2020-05-16T20:10:05.000Z
|
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
open import Agda.Builtin.List
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
infix 0 case_of_
case_of_ : ∀ {a b}{A : Set a}{B : Set b} → A → (A → B) → B
case x of f = f x
map : ∀ {a b}{A : Set a}{B : Set b} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
reverse : ∀ {a}{A : Set a} → List A → List A
reverse {A = A} xs = reverseAcc xs []
where
reverseAcc : List A → List A → List A
reverseAcc [] a = a
reverseAcc (x ∷ xs) a = reverseAcc xs (x ∷ a)
data Maybe (X : Set) : Set where
nothing : Maybe X
just : X → Maybe X
data Fin : Nat → Set where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n → Fin (suc n)
record RVec {a} (X : Set a) (n : Nat) : Set a where
constructor vec
field sel : Fin n → X
test-rvec : Nat → RVec Nat 5
test-rvec x = vec λ _ → x
get-len : Definition → TC Term
get-len (function (clause _ _ (con (quote vec)
(_ ∷ _ ∷ (arg _ a) ∷ _)) ∷ [])) = quoteTC a
get-len _ = quoteTC "ERROR"
macro
def-reg : Name → Term → TC ⊤
def-reg n hole = do
d ← getDefinition n
l ← get-len d
unify hole l
def-recons : Name → Term → TC ⊤
def-recons n hole = do
d ← withReconstructed (getDefinition n)
l ← get-len d
unify hole l
-- normaliseR perserves reconstructed expressions.
def-normR : Name → Term → TC ⊤
def-normR n hole = do
(function (clause tel ps t ∷ [])) ←
withReconstructed (getDefinition n)
where _ → quoteTC "ERROR" >>= unify hole
let ctx = map snd tel
t ← inContext (reverse ctx)
(withReconstructed (normalise t))
let d = function (clause tel ps t ∷ [])
get-len d >>= unify hole
-- normaliseR perserves reconstructed expressions.
def-redR : Name → Term → TC ⊤
def-redR n hole = do
(function (clause tel ps t ∷ [])) ←
withReconstructed (getDefinition n)
where _ → quoteTC "ERROR" >>= unify hole
let ctx = map snd tel
t ← inContext (reverse ctx) (withReconstructed (reduce t))
let d = function (clause tel ps t ∷ [])
get-len d >>= unify hole
test₁ : unknown ≡ def-reg test-rvec
test₁ = refl
test₂ : (lit (nat 5)) ≡ def-recons test-rvec
test₂ = refl
test₃ : (lit (nat 5)) ≡ def-normR test-rvec
test₃ = refl
test₄ : (lit (nat 5)) ≡ def-redR test-rvec
test₄ = refl
pictx : Term → List (Arg Type)
pictx (pi a (abs s x)) = a ∷ pictx x
pictx _ = []
macro
get-ctx : Name → Term → TC ⊤
get-ctx n hole = do
t ← getType n
let c = pictx t
c ← withReconstructed
(inContext (reverse c) getContext)
quoteTC c >>= unify hole
bar : (A : Set) (eq : [] {A = A} ≡ []) (x : Nat) → ⊤
bar _ _ _ = tt
-- if getContext were to work incorrectly, this function wouldn't typecheck
test₅ : List (Arg Type)
test₅ = get-ctx bar
data NotAVec (X : Set) (y : Nat) : Set where
mk : NotAVec X y
f : ∀ {n} → NotAVec Nat n → NotAVec Nat (suc n)
f mk = mk
macro
chk-type : Term → TC ⊤
chk-type hole = do
T ← quoteTC (NotAVec Nat 5)
t ← quoteTC (mk {X = Nat} {y = 5})
(con _ (_ ∷ arg _ t ∷ [])) ← withReconstructed (checkType t T)
where _ → quoteTC "ERROR" >>= unify hole
quoteTC t >>= unify hole
-- checkType would leave unknown's without the call to withReconstructed
test₆ : chk-type ≡ lit (nat 5)
test₆ = refl
q : [] {A = Nat} ≡ [] {A = Nat}
q = refl
macro
inf-type : Term → TC ⊤
inf-type hole = do
(function (clause _ _ b ∷ [])) ← withReconstructed (getDefinition (quote q))
where _ → quoteTC "ERROR" >>= unify hole
(def _ (l ∷ L ∷ e₁ ∷ e₂ ∷ [])) ← withReconstructed (inferType b)
where _ → quoteTC "ERROR" >>= unify hole
(arg _ (con _ (_ ∷ (arg _ N) ∷ []))) ← returnTC e₁
where _ → quoteTC "ERROR" >>= unify hole
quoteTC N >>= unify hole
-- inferType would not reconstruct the arguments within the type
-- without the call to withReconstructed
test₇ : inf-type ≡ def (quote Nat) []
test₇ = refl
| 26.25974
| 80
| 0.59817
|
0bb3d057fd21df0d9ad27f3891dfc407171a10ed
| 2,348
|
agda
|
Agda
|
CombinatoryLogic/Semantics.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | 1
|
2022-02-28T23:44:42.000Z
|
2022-02-28T23:44:42.000Z
|
CombinatoryLogic/Semantics.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | null | null | null |
CombinatoryLogic/Semantics.agda
|
splintah/combinatory-logic
|
df8bf877e60b3059532c54a247a36a3d83cd55b0
|
[
"MIT"
] | null | null | null |
module CombinatoryLogic.Semantics where
open import Relation.Binary using (Rel)
open import CombinatoryLogic.Syntax
-- Kapitel 1, Abschnitt C, §5 (Axiome)
data Axiom : Combinator → Set where
Q : Axiom (Π ∙ (W ∙ (C ∙ Q)))
B : Axiom (C ∙ (B ∙ B ∙ (B ∙ B ∙ B)) ∙ B == B ∙ (B ∙ B) ∙ B)
C : Axiom (C ∙ (B ∙ B ∙ (B ∙ B ∙ B)) ∙ W ∙ C == B ∙ (B ∙ C) ∙ (B ∙ B ∙ B))
W : Axiom (C ∙ (B ∙ B ∙ B) ∙ W == B ∙ (B ∙ W) ∙ (B ∙ B ∙ B))
-- NOTE (Curry): this axiom can be proved from the others.
I₁ : Axiom (C ∙ (B ∙ B ∙ B) ∙ K == B ∙ (B ∙ K) ∙ I)
BC : Axiom (B ∙ B ∙ C == B ∙ (B ∙ (B ∙ C) ∙ C) ∙ (B ∙ B))
BW : Axiom (B ∙ B ∙ W == B ∙ (B ∙ (B ∙ (B ∙ (B ∙ W) ∙ W) ∙ (B ∙ C)) ∙ B ∙ (B ∙ B)) ∙ B)
BK : Axiom (B ∙ B ∙ K == B ∙ K ∙ K)
CC₁ : Axiom (B ∙ C ∙ C ∙ B ∙ (B ∙ I))
CC₂ : Axiom (B ∙ (B ∙ (B ∙ C) ∙ C) ∙ (B ∙ C) == B ∙ (B ∙ C ∙ (B ∙ C)) ∙ C)
CW : Axiom (B ∙ C ∙ W == B ∙ (B ∙ (B ∙ W) ∙ C) ∙ (B ∙ C))
CK : Axiom (B ∙ C ∙ K == B ∙ K)
WC : Axiom (B ∙ W ∙ C == W)
WW : Axiom (B ∙ W ∙ W == B ∙ W ∙ (B ∙ W))
WK : Axiom (B ∙ W ∙ K == B ∙ I)
I₂ : Axiom (B ∙ I == I)
-- Kapitel 1, Abschnitt C, §4 (Symbolische Festsetzungen), Festsetzung 1
infix 4 ⊢_
data ⊢_ : Combinator → Set where
ax : ∀ {X} → Axiom X → ⊢ X
-- Kapitel 1, Abschnitt C, §6 (Regeln)
Q₁ : ∀ {X Y} → ⊢ X → ⊢ X == Y → ⊢ Y
Q₂ : ∀ {X Y Z} → ⊢ X == Y → ⊢ Z ∙ X == Z ∙ Y
Π : ∀ {X Y} → ⊢ Π ∙ X → ⊢ X ∙ Y
B : ∀ {X Y Z} → ⊢ B ∙ X ∙ Y ∙ Z == X ∙ (Y ∙ Z)
C : ∀ {X Y Z} → ⊢ C ∙ X ∙ Y ∙ Z == X ∙ Z ∙ Y
W : ∀ {X Y} → ⊢ W ∙ X ∙ Y == X ∙ Y ∙ Y
K : ∀ {X Y} → ⊢ K ∙ X ∙ Y == X
P : ∀ {X Y} → ⊢ X → ⊢ P ∙ X ∙ Y → ⊢ Y
∧ : ∀ {X Y} → ⊢ X → ⊢ Y → ⊢ ∧ ∙ X ∙ Y
-- We introduce convenience notation for the equality defined in Kapitel 1,
-- Abschnitt C, §4 (Symbolische Festsetzungen), Festsetzung 3 (Gleichheit).
_≈_ : Rel Combinator _
X ≈ Y = ⊢ X == Y
infix 0 _[_]
-- An operator that helps write proofs in the style of Curry. Where Curry writes
-- ⟨statement⟩ (⟨rule⟩)
-- we write
-- ⟨statement⟩ [ ⟨rule⟩ ]
--
-- Later, we can also use the Agda standard library's reasoning combinators
-- (e.g. _≈⟨_⟩_) for proving equalities, but not before it is shown that the
-- equality _≈_ is an equivalence relation, which Curry does in propositions 1,
-- 2 and 3 of Kapitel 1, Abschnitt D (Die Eigenschaften der Gleichheit).
_[_] : ∀ {a} (A : Set a) (x : A) → A
_ [ x ] = x
| 38.491803
| 89
| 0.477428
|
2e932e928d414fc25378f4c75103cc8b80f9907d
| 1,450
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Ideal.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Ideal.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Ideal.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
{-
This is mostly for convenience, when working with ideals
(which are defined for general rings) in a commutative ring.
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Ideal where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Algebra.CommRing.Base
open import Cubical.Algebra.Ring.Ideal renaming (IdealsIn to IdealsInRing)
open import Cubical.Algebra.RingSolver.ReflectionSolving
private
variable
ℓ : Level
IdealsIn : (R : CommRing ℓ) → Type _
IdealsIn R = IdealsInRing (CommRing→Ring R)
module _ (Ring@(R , str) : CommRing ℓ) where
open CommRingStr str
makeIdeal : (I : R → hProp ℓ)
→ (+-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I)
→ (0r-closed : 0r ∈ I)
→ (·-closedLeft : {x : R} → (r : R) → x ∈ I → r · x ∈ I)
→ IdealsIn (R , str)
makeIdeal I +-closed 0r-closed ·-closedLeft = I ,
(record
{ +-closed = +-closed
; -closed = λ x∈I → subst (_∈ I) (useSolver _)
(·-closedLeft (- 1r) x∈I)
; 0r-closed = 0r-closed
; ·-closedLeft = ·-closedLeft
; ·-closedRight = λ r x∈I →
subst (_∈ I)
(·-comm r _)
(·-closedLeft r x∈I)
})
where useSolver : (x : R) → - 1r · x ≡ - x
useSolver = solve Ring
| 32.954545
| 74
| 0.557241
|
adae7e5c886316a10e8a533ba4159d193bd686a7
| 11,070
|
agda
|
Agda
|
LibraBFT/Impl/Properties/Common.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Impl/Properties/Common.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Impl/Properties/Common.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.PKCS
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
import LibraBFT.Concrete.Properties.Common as Common
import LibraBFT.Concrete.Properties.VotesOnce as VO
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Util
open import LibraBFT.Impl.Consensus.Network as Network
open import LibraBFT.Impl.Consensus.Network.Properties as NetworkProps
open import LibraBFT.Impl.Consensus.RoundManager
import LibraBFT.Impl.Handle as Handle
open import LibraBFT.Impl.IO.OBM.InputOutputHandlers
open import LibraBFT.Impl.IO.OBM.Properties.InputOutputHandlers
open import LibraBFT.Impl.Handle.Properties
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.Lemmas
open import LibraBFT.Prelude
open import Optics.All
open Invariants
open RoundManagerTransProps
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open ParamsWithInitAndHandlers Handle.InitHandler.InitAndHandlers
open PeerCanSignForPK
open import LibraBFT.ImplShared.Util.HashCollisions Handle.InitHandler.InitAndHandlers
open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms
Handle.InitHandler.InitAndHandlers
PeerCanSignForPK PeerCanSignForPK-stable
open import LibraBFT.Impl.Handle.InitProperties
open initHandlerSpec
-- This module contains definitions and lemmas used by proofs of the
-- implementation obligations for VotesOnce and PreferredRoundRule.
module LibraBFT.Impl.Properties.Common where
postulate -- TODO-3: prove (note: advanced; waiting on: `handle`)
-- This will require updates to the existing proofs for the peer handlers. We
-- will need to show that honest peers sign things only for their only PK, and
-- that they either resend messages signed before or if sending a new one,
-- that signature hasn't been sent before
impl-sps-avp : StepPeerState-AllValidParts
open Structural impl-sps-avp
-- We can prove this easily for the Agda model because (unlike the Haskell
-- prototype) it does not yet do epoch changes, so only the initial EC is
-- relevant. Later, this will require us to use the fact that epoch changes
-- require proof of committing an epoch-changing transaction.
availEpochsConsistent :
∀{pid pid' v v' pk}{st : SystemState}
→ (pkvpf : PeerCanSignForPK st v pid pk)
→ (pkvpf' : PeerCanSignForPK st v' pid' pk)
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ pcs4𝓔 pkvpf ≡ pcs4𝓔 pkvpf'
availEpochsConsistent (mkPCS4PK _ (inBootstrapInfo refl) _) (mkPCS4PK _ (inBootstrapInfo refl) _) refl = refl
postulate -- TODO-1: Prove (waiting on: complete definition of `initRM`)
uninitQcs∈Bootstrap
: ∀ {pid qc vs}{st : SystemState}
→ ReachableSystemState st
→ initialised st pid ≡ uninitd
→ qc QCProps.∈RoundManager (peerStates st pid)
→ vs ∈ qcVotes qc
→ ∈BootstrapInfo-impl fakeBootstrapInfo (proj₂ vs)
module ∈BootstrapInfoProps where
sameSig∉ : ∀ {pk} {v v' : Vote}
→ (sig : WithVerSig pk v) (sig' : WithVerSig pk v')
→ ¬ ∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig)
→ ver-signature sig' ≡ ver-signature sig
→ ¬ ∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig')
sameSig∉ _ _ ¬bootstrap ≡sig rewrite ≡sig = ¬bootstrap
-- Lemmas for `PeerCanSignForPK`
module PeerCanSignForPKProps where
msb4 -- NOTE: This proof requires updating when we model epoch changes.
: ∀ {pid v pk}{pre post : SystemState}
→ ReachableSystemState pre
→ Step pre post
→ PeerCanSignForPK post v pid pk
→ Meta-Honest-PK pk → (sig : WithVerSig pk v)
→ MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
→ PeerCanSignForPK pre v pid pk
msb4 preach step (mkPCS4PK 𝓔@._ (inBootstrapInfo refl) (mkPCS4PKin𝓔 𝓔id≡ mbr nid≡ pk≡)) hpk sig mws∈pool =
mkPCS4PK 𝓔 (inBootstrapInfo refl) (mkPCS4PKin𝓔 𝓔id≡ mbr nid≡ pk≡)
msb4-eid≡
: ∀ {pre post : SystemState} {v v' pid pk}
→ ReachableSystemState pre
→ Step pre post
→ Meta-Honest-PK pk
→ PeerCanSignForPK post v pid pk
→ v ≡L v' at vEpoch
→ (sig' : WithVerSig pk v')
→ MsgWithSig∈ pk (ver-signature sig') (msgPool pre)
→ PeerCanSignForPK pre v pid pk
msb4-eid≡ rss step hpk pcsfpk ≡eid sig' mws' =
peerCanSignEp≡ (msb4 rss step (peerCanSignEp≡ pcsfpk ≡eid) hpk sig' mws') (sym ≡eid)
pidInjective
: ∀ {pid pid' pk v v'}{st : SystemState}
→ PeerCanSignForPK st v pid pk
→ PeerCanSignForPK st v' pid' pk
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ pid ≡ pid'
pidInjective{pid}{pid'}{pk} pcsfpk₁ pcsfpk₂ ≡epoch = begin
pid ≡⟨ sym (nid≡ (pcs4in𝓔 pcsfpk₁)) ⟩
pcsfpk₁∙pid ≡⟨ PK-inj-same-ECs{pcs4𝓔 pcsfpk₁}{pcs4𝓔 pcsfpk₂}
(availEpochsConsistent pcsfpk₁ pcsfpk₂ ≡epoch) pcsfpk∙pk≡ ⟩
pcsfpk₂∙pid ≡⟨ nid≡ (pcs4in𝓔 pcsfpk₂) ⟩
pid' ∎
where
open ≡-Reasoning
open PeerCanSignForPKinEpoch
open PeerCanSignForPK
pcsfpk₁∙pid = EpochConfig.toNodeId (pcs4𝓔 pcsfpk₁) (mbr (pcs4in𝓔 pcsfpk₁))
pcsfpk₂∙pid = EpochConfig.toNodeId (pcs4𝓔 pcsfpk₂) (mbr (pcs4in𝓔 pcsfpk₂))
pcsfpk₁∙pk = EpochConfig.getPubKey (pcs4𝓔 pcsfpk₁) (mbr (pcs4in𝓔 pcsfpk₁))
pcsfpk₂∙pk = EpochConfig.getPubKey (pcs4𝓔 pcsfpk₂) (mbr (pcs4in𝓔 pcsfpk₂))
pcsfpk∙pk≡ : pcsfpk₁∙pk ≡ pcsfpk₂∙pk
pcsfpk∙pk≡ = begin
pcsfpk₁∙pk ≡⟨ pk≡ (pcs4in𝓔 pcsfpk₁) ⟩
pk ≡⟨ sym (pk≡ (pcs4in𝓔 pcsfpk₂)) ⟩
pcsfpk₂∙pk ∎
module ReachableSystemStateProps where
mws∈pool⇒initd
: ∀ {pid pk v}{st : SystemState}
→ ReachableSystemState st
→ PeerCanSignForPK st v pid pk
→ Meta-Honest-PK pk
→ (sig : WithVerSig pk v)
→ ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig))
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
→ initialised st pid ≡ initd
mws∈pool⇒initd{pk = pk}{v} (step-s{pre = pre} rss step@(step-peer sp@(step-cheat cmc))) pcsfpk hpk sig ¬bootstrap mws∈pool =
peersRemainInitialized step (mws∈pool⇒initd rss (PeerCanSignForPKProps.msb4 rss step pcsfpk hpk sig mws∈poolPre) hpk sig ¬bootstrap mws∈poolPre)
where
¬bootstrap' = ∈BootstrapInfoProps.sameSig∉ sig (msgSigned mws∈pool) ¬bootstrap (msgSameSig mws∈pool)
mws∈poolPre : MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
mws∈poolPre = ¬cheatForgeNew sp refl unit hpk mws∈pool ¬bootstrap'
mws∈pool⇒initd{pid₁}{pk = pk} (step-s{pre = pre} rss step@(step-peer sp@(step-honest{pid₂} sps@(step-init {rm} rm×acts uni)))) pcsfpk hpk sig ¬bootstrap mws∈pool
with pid₁ ≟ pid₂
...| yes refl = StepPeer-post-lemma2 {pre = pre} sps
...| no neq
with newMsg⊎msgSentB4 rss sps hpk (msgSigned mws∈pool) ¬bootstrap' (msg⊆ mws∈pool) (msg∈pool mws∈pool)
where
¬bootstrap' = ∈BootstrapInfoProps.sameSig∉ sig (msgSigned mws∈pool) ¬bootstrap (msgSameSig mws∈pool)
...| Right mws∈poolPre = peersRemainInitialized step (mws∈pool⇒initd rss (PeerCanSignForPKProps.msb4 rss step pcsfpk hpk sig mws∈poolPre') hpk sig ¬bootstrap mws∈poolPre')
where
mws∈poolPre' : MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
mws∈poolPre' rewrite msgSameSig mws∈pool = mws∈poolPre
...| Left (send∈acts , _ , _)
with initHandlerSpec.contract pid₂ fakeBootstrapInfo rm×acts
...| init-contract
with msg⊆ mws∈pool
...| vote∈vm
= ⊥-elim
(P≢V (sym (proj₁ (proj₂ (initHandlerSpec.ContractOk.isInitPM init-contract send∈acts)))))
...| vote∈qc vs∈qc _ qc∈pm
with initHandlerSpec.ContractOk.isInitPM init-contract send∈acts
...| (_ , refl , noSigs) = ⊥-elim (noSigs vs∈qc qc∈pm)
mws∈pool⇒initd{pid₁}{pk}{v} (step-s{pre = pre} rss step@(step-peer{pid₂} sp@(step-honest sps@(step-msg _ ini)))) pcsfpk hpk sig ¬bootstrap mws∈pool
with newMsg⊎msgSentB4 rss sps hpk (msgSigned mws∈pool) ¬bootstrap' (msg⊆ mws∈pool) (msg∈pool mws∈pool)
where
¬bootstrap' = ∈BootstrapInfoProps.sameSig∉ sig (msgSigned mws∈pool) ¬bootstrap (msgSameSig mws∈pool)
...| Left (m∈outs , pcsfpk' , ¬msb4)
with pid≡
where
vd₁≡vd₂ : v ≡L msgPart mws∈pool at vVoteData
vd₁≡vd₂ = either (⊥-elim ∘ PerReachableState.meta-no-collision rss) id (sameSig⇒sameVoteData (msgSigned mws∈pool) sig (msgSameSig mws∈pool))
pid≡ : pid₁ ≡ pid₂
pid≡ = PeerCanSignForPKProps.pidInjective pcsfpk pcsfpk' (cong (_^∙ vdProposed ∙ biEpoch) vd₁≡vd₂)
...| refl rewrite StepPeer-post-lemma2{pid₂}{pre = pre} sps = refl
mws∈pool⇒initd{pid₁}{pk} (step-s{pre = pre} rss step@(step-peer{pid₂} sp@(step-honest sps@(step-msg _ ini)))) pcsfpk hpk sig ¬bootstrap mws∈pool | Right mws∈poolPre =
peersRemainInitialized step (mws∈pool⇒initd rss (PeerCanSignForPKProps.msb4 rss step pcsfpk hpk sig mws∈poolPre') hpk sig ¬bootstrap mws∈poolPre')
where
mws∈poolPre' : MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
mws∈poolPre' rewrite msgSameSig mws∈pool = mws∈poolPre
mws∈pool⇒epoch≡
: ∀ {pid v s' outs pk}{st : SystemState}
→ ReachableSystemState st
→ (sps : StepPeerState pid (msgPool st) (initialised st) (peerStates st pid) (s' , outs))
→ PeerCanSignForPK st v pid pk
→ Meta-Honest-PK pk → (sig : WithVerSig pk v)
→ ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig))
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
→ s' ^∙ rmEpoch ≡ v ^∙ vEpoch
→ peerStates st pid ^∙ rmEpoch ≡ v ^∙ vEpoch
mws∈pool⇒epoch≡ rss (step-init _ uni) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ =
absurd (uninitd ≡ initd) case (trans (sym uni) ini) of λ ()
where
ini = mws∈pool⇒initd rss pcsfpk hpk sig ¬bootstrap mws∈pool
mws∈pool⇒epoch≡{pid}{v}{st = st} rss (step-msg{_ , P pm} m∈pool ini) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ = begin
hpPre ^∙ rmEpoch ≡⟨ noEpochChange ⟩
hpPos ^∙ rmEpoch ≡⟨ epoch≡ ⟩
v ^∙ vEpoch ∎
where
hpPool = msgPool st
hpPre = peerStates st pid
hpPos = LBFT-post (handleProposal 0 pm) hpPre
open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hpPool hpPre)
open ≡-Reasoning
mws∈pool⇒epoch≡{pid}{v}{st = st} rss (step-msg{sndr , V vm} _ _) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ = begin
hvPre ^∙ rmEpoch ≡⟨ noEpochChange ⟩
hvPos ^∙ rmEpoch ≡⟨ epoch≡ ⟩
v ^∙ vEpoch ∎
where
hvPre = peerStates st pid
hvPos = LBFT-post (handleVote 0 vm) hvPre
open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool st) hvPre)
open ≡-Reasoning
mws∈pool⇒epoch≡{pid}{v}{st = st} rss (step-msg{sndr , C cm} _ _) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ = epoch≡
| 45.743802
| 173
| 0.692412
|
5919db32bb14b20debc930bdc38969d4855ae2c2
| 449
|
agda
|
Agda
|
test/Common/MAlonzo.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Common/MAlonzo.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Common/MAlonzo.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module Common.MAlonzo where
open import Common.Prelude hiding (putStrLn)
open import Common.Coinduction
{-# FOREIGN GHC import qualified Data.Text.IO #-}
postulate
putStrLn : ∞ String → IO Unit
{-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn . MAlonzo.RTE.flat #-}
main = putStrLn (♯ "This is a dummy main routine.")
mainPrint : String → _
mainPrint s = putStrLn (♯ s)
mainPrintNat : Nat → _
mainPrintNat n = putStrLn (♯ (natToString n))
| 21.380952
| 71
| 0.714922
|
3826d52dde5dcbc4ac503df8db76163a6cd2d75e
| 537
|
agda
|
Agda
|
neg-datatype-nonterm.agda
|
logicshan/IAL
|
2ad96390a9be5c238e73709a21533c7354cedd0c
|
[
"MIT"
] | null | null | null |
neg-datatype-nonterm.agda
|
logicshan/IAL
|
2ad96390a9be5c238e73709a21533c7354cedd0c
|
[
"MIT"
] | null | null | null |
neg-datatype-nonterm.agda
|
logicshan/IAL
|
2ad96390a9be5c238e73709a21533c7354cedd0c
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --no-positivity-check #-}
{- This file gives a standard example showing that if arguments to
constructors can use the datatype in a negative position (to the
left of one or an odd number of arrows), then termination and
logical consistency is lost. -}
module neg-datatype-nonterm where
open import empty
data Bad : Set where
bad : (Bad → ⊥) → Bad
badFunc : Bad → ⊥
badFunc (bad f) = f (bad f)
-- if you try to normalize the following, it will diverge
inconsistency : ⊥
inconsistency = badFunc (bad badFunc)
| 25.571429
| 67
| 0.713222
|
2221a676e1cc9ad5ef5ed666abd019ed449c2269
| 1,536
|
agda
|
Agda
|
agda-stdlib/src/Data/Nat/Show.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Nat/Show.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Nat/Show.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Showing natural numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Show where
open import Data.Char as Char using (Char)
open import Data.Digit using (showDigit; toDigits; toNatDigits)
open import Function using (_∘_; _$_)
open import Data.List.Base using (List; []; _∷_; map; reverse)
open import Data.Nat
open import Data.Product using (proj₁)
open import Data.String as String using (String)
open import Relation.Nullary.Decidable using (True)
------------------------------------------------------------------------
-- Conversion from unary representation to the representation by the
-- given base.
toDigitChar : (n : ℕ) → Char
toDigitChar n = Char.fromℕ (n + (Char.toℕ '0'))
toDecimalChars : ℕ → List Char
toDecimalChars = map toDigitChar ∘ toNatDigits 10
------------------------------------------------------------------------
-- Show
-- Time complexity is O(log₁₀(n))
show : ℕ → String
show = String.fromList ∘ toDecimalChars
-- Warning: when compiled the time complexity of `showInBase b n` is
-- O(n) instead of the expected O(log(n)).
showInBase : (base : ℕ)
{base≥2 : True (2 ≤? base)}
{base≤16 : True (base ≤? 16)} →
ℕ → String
showInBase base {base≥2} {base≤16} n =
String.fromList $
map (showDigit {base≤16 = base≤16}) $
reverse $
proj₁ $ toDigits base {base≥2 = base≥2} n
| 30.72
| 72
| 0.550781
|
2f73306e758a367cc0fd64b78d992fbe0d310024
| 4,994
|
agda
|
Agda
|
Cubical/Data/FinSet/Quotients.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Data/FinSet/Quotients.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Data/FinSet/Quotients.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- The quotient of finite sets by decidable equivalence relation is still finite, by using equivalence class.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet.Quotients where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_)
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Univalence
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.HITs.SetQuotients as SetQuot
open import Cubical.HITs.SetQuotients.EqClass
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Sigma
open import Cubical.Data.SumFin
open import Cubical.Data.FinSet.Base
open import Cubical.Data.FinSet.Properties
open import Cubical.Data.FinSet.DecidablePredicate
open import Cubical.Data.FinSet.Constructors
open import Cubical.Data.FinSet.Cardinality
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidablePropositions
open import Cubical.Relation.Binary
private
variable
ℓ ℓ' ℓ'' : Level
LiftDecProp : {ℓ ℓ' : Level}{P : Type ℓ} → (p : isDecProp P) → P ≃ Bool→Type* {ℓ'} (p .fst)
LiftDecProp p = p .snd ⋆ BoolProp≃BoolProp*
open Iso
module _
(X : Type ℓ) where
ℙEff : Type ℓ
ℙEff = X → Bool
isSetℙEff : isSet ℙEff
isSetℙEff = isSetΠ (λ _ → isSetBool)
ℙEff→ℙDec : ℙEff → ℙDec {ℓ' = ℓ'} X
ℙEff→ℙDec f .fst x = Bool→Type* (f x) , isPropBool→Type*
ℙEff→ℙDec f .snd x = DecBool→Type*
Iso-ℙEff-ℙDec : Iso ℙEff (ℙDec {ℓ' = ℓ'} X)
Iso-ℙEff-ℙDec .fun = ℙEff→ℙDec
Iso-ℙEff-ℙDec .inv (P , dec) x = Dec→Bool (dec x)
Iso-ℙEff-ℙDec {ℓ' = ℓ'} .leftInv f i x = Bool≡BoolDec* {ℓ = ℓ'} {a = f x} (~ i)
Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .fst = ua (Dec≃DecBool* (P x .snd) (dec x)) (~ i)
Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .snd =
isProp→PathP {B = λ i → isProp (Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .fst)}
(λ i → isPropIsProp)
(Iso-ℙEff-ℙDec .fun (Iso-ℙEff-ℙDec .inv (P , dec)) .fst x .snd) (P x .snd) i
Iso-ℙEff-ℙDec .rightInv (P , dec) i .snd x =
isProp→PathP {B = λ i → Dec (Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .fst)}
(λ i → isPropDec (Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .snd))
(Iso-ℙEff-ℙDec .fun (Iso-ℙEff-ℙDec .inv (P , dec)) .snd x) (dec x) i
ℙEff≃ℙDec : ℙEff ≃ (ℙDec {ℓ' = ℓ'} X)
ℙEff≃ℙDec = isoToEquiv Iso-ℙEff-ℙDec
module _
(X : Type ℓ)(p : isFinOrd X) where
private
e = p .snd
isFinOrdℙEff : isFinOrd (ℙEff X)
isFinOrdℙEff = _ , preCompEquiv (invEquiv e) ⋆ SumFinℙ≃ _
module _
(X : FinSet ℓ) where
isFinSetℙEff : isFinSet (ℙEff (X .fst))
isFinSetℙEff = 2 ^ (card X) ,
Prop.elim (λ _ → isPropPropTrunc {A = _ ≃ Fin _})
(λ p → ∣ isFinOrdℙEff (X .fst) (_ , p) .snd ∣₁)
(X .snd .snd)
module _
(X : FinSet ℓ)
(R : X .fst → X .fst → Type ℓ')
(dec : (x x' : X .fst) → isDecProp (R x x')) where
isEqClassEff : ℙEff (X .fst) → Type ℓ
isEqClassEff f = ∥ Σ[ x ∈ X .fst ] ((a : X .fst) → f a ≡ dec a x .fst) ∥₁
isDecPropIsEqClassEff : {f : ℙEff (X .fst)} → isDecProp (isEqClassEff f)
isDecPropIsEqClassEff = isDecProp∃ X (λ _ → _ , isDecProp∀ X (λ _ → _ , _ , Bool≡≃ _ _))
isEqClassEff→isEqClass' : (f : ℙEff (X .fst))(x : X .fst)
→ ((a : X .fst) → f a ≡ dec a x .fst)
→ (a : X .fst) → Bool→Type* {ℓ = ℓ'} (f a) ≃ ∥ R a x ∥₁
isEqClassEff→isEqClass' f x h a =
pathToEquiv (cong Bool→Type* (h a))
⋆ invEquiv (LiftDecProp (dec a x))
⋆ invEquiv (propTruncIdempotent≃ (isDecProp→isProp (dec a x)))
isEqClass→isEqClassEff' : (f : ℙEff (X .fst))(x : X .fst)
→ ((a : X .fst) → Bool→Type* {ℓ = ℓ'} (f a) ≃ ∥ R a x ∥₁)
→ (a : X .fst) → f a ≡ dec a x .fst
isEqClass→isEqClassEff' f x h a =
Bool→TypeInj* _ _
(h a ⋆ propTruncIdempotent≃ (isDecProp→isProp (dec a x)) ⋆ LiftDecProp (dec a x))
isEqClassEff→isEqClass : (f : ℙEff (X .fst)) → isEqClassEff f ≃ isEqClass {ℓ' = ℓ'} _ R (ℙEff→ℙDec _ f .fst)
isEqClassEff→isEqClass f =
propBiimpl→Equiv isPropPropTrunc isPropPropTrunc
(Prop.map (λ (x , p) → x , isEqClassEff→isEqClass' f x p))
(Prop.map (λ (x , p) → x , isEqClass→isEqClassEff' f x p))
_∥Eff_ : Type ℓ
_∥Eff_ = Σ[ f ∈ ℙEff (X .fst) ] isEqClassEff f
∥Eff≃∥Dec : _∥Eff_ ≃ _∥Dec_ (X .fst) R (λ x x' → isDecProp→Dec (dec x x'))
∥Eff≃∥Dec = Σ-cong-equiv (ℙEff≃ℙDec (X .fst)) isEqClassEff→isEqClass
isFinSet∥Eff : isFinSet _∥Eff_
isFinSet∥Eff = isFinSetSub (_ , isFinSetℙEff X) (λ _ → _ , isDecPropIsEqClassEff)
open BinaryRelation
module _
(X : FinSet ℓ)
(R : X .fst → X .fst → Type ℓ')
(h : isEquivRel R)
(dec : (x x' : X .fst) → isDecProp (R x x')) where
isFinSetQuot : isFinSet (X .fst / R)
isFinSetQuot =
EquivPresIsFinSet
( ∥Eff≃∥Dec X _ dec
⋆ ∥Dec≃∥ _ _ (λ x x' → isDecProp→Dec (dec x x'))
⋆ invEquiv (equivQuot {ℓ' = ℓ'} _ _ h))
(isFinSet∥Eff X _ dec)
| 33.293333
| 111
| 0.633761
|
38b58e4573b6d367ca153ecb867e8ba0d59dbc9c
| 6,809
|
agda
|
Agda
|
Cubical/HITs/Nullification/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Nullification/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Nullification/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Nullification.Properties where
open import Cubical.Foundations.Everything
open isPathSplitEquiv
open import Cubical.Modalities.Everything
open Modality
open import Cubical.HITs.Localization renaming (rec to Localize-rec)
open import Cubical.Data.Unit
open import Cubical.HITs.Nullification.Base
rec : ∀ {ℓ ℓ' ℓ''} {S : Type ℓ} {A : Type ℓ'} {B : Type ℓ''}
→ (nB : isNull S B) → (A → B) → Null S A → B
rec nB g ∣ x ∣ = g x
rec nB g (hub f) = fst (sec nB) (λ s → rec nB g (f s))
rec nB g (spoke f s i) = snd (sec nB) (λ s → rec nB g (f s)) i s
rec nB g (≡hub {x} {y} p i) = fst (secCong nB (rec nB g x) (rec nB g y)) (λ i s → rec nB g (p s i)) i
rec nB g (≡spoke {x} {y} p s i j) = snd (secCong nB (rec nB g x) (rec nB g y)) (λ i s → rec nB g (p s i)) i j s
toPathP⁻ : ∀ {ℓ} (A : I → Type ℓ) {x : A i0} {y : A i1} → x ≡ transport⁻ (λ i → A i) y → PathP A x y
toPathP⁻ A p i = toPathP {A = λ i → A (~ i)} (sym p) (~ i)
toPathP⁻-sq : ∀ {ℓ} {A : Type ℓ} (x : A) → Square (toPathP⁻ (λ _ → A) (λ _ → transport refl x)) refl
(transportRefl x) refl
toPathP⁻-sq x j i = hcomp (λ l → λ { (i = i0) → transportRefl x j
; (i = i1) → x ; (j = i1) → x })
(transportRefl x (i ∨ j))
module _ {ℓ ℓ' ℓ''} {S : Type ℓ} {A : Type ℓ'} {B : Null S A → Type ℓ''} where
private
secCongDep' : ∀ (nB : (x : Null S A) → isNull S (B x)) {x y : Null S A} (p : x ≡ y)
→ (∀ (bx : B x) (by : B y) → hasSection (cong₂ (λ x (b : B x) (_ : S) → b) p))
secCongDep' nB p = secCongDep (λ _ → const) p (λ a → secCong (nB a))
elim : (nB : (x : Null S A) → isNull S (B x)) → ((a : A) → B ∣ a ∣) → (x : Null S A) → B x
elim nB g ∣ x ∣ = g x
elim nB g (hub f)
= fst (sec (nB (hub f)))
(λ s → transport (λ i → B (spoke f s (~ i))) (elim nB g (f s)))
elim nB g (spoke f s i)
= toPathP⁻ (λ i → B (spoke f s i))
(funExt⁻ ( snd (sec (nB (hub f)))
(λ s → transport (λ i → B (spoke f s (~ i))) (elim nB g (f s))) ) s) i
elim nB g (≡hub {x} {y} p i)
= hcomp (λ k → λ { (i = i0) → transportRefl (elim nB g x) k
; (i = i1) → transportRefl (elim nB g y) k })
(fst (secCongDep' nB (≡hub p) (transport refl (elim nB g x)) (transport refl (elim nB g y)))
(λ i s → transport (λ j → B (≡spoke p s (~ j) i)) (elim nB g (p s i))) i)
elim nB g (≡spoke {x} {y} p s j i)
= hcomp (λ k → λ { (i = i0) → toPathP⁻-sq (elim nB g x) k j
; (i = i1) → toPathP⁻-sq (elim nB g y) k j
; (j = i1) → elim nB g (p s i) })
(q₂ j i)
where q₁ : Path (PathP (λ i → B (≡hub p i)) (transport refl (elim nB g x)) (transport refl (elim nB g y)))
(fst (secCongDep' nB (≡hub p) (transport refl (elim nB g x)) (transport refl (elim nB g y)))
(λ i s → transport (λ j → B (≡spoke p s (~ j) i)) (elim nB g (p s i))))
(λ i → transport (λ j → B (≡spoke p s (~ j) i)) (elim nB g (p s i)))
q₁ j i = snd (secCongDep' nB (≡hub p) (transport refl (elim nB g x)) (transport refl (elim nB g y)))
(λ i s → transport (λ j → B (≡spoke p s (~ j) i)) (elim nB g (p s i))) j i s
q₂ : PathP (λ j → PathP (λ i → B (≡spoke p s j i)) (toPathP⁻ (λ _ → B x) (λ _ → transport refl (elim nB g x)) j)
(toPathP⁻ (λ _ → B y) (λ _ → transport refl (elim nB g y)) j))
(fst (secCongDep' nB (≡hub p) (transport refl (elim nB g x)) (transport refl (elim nB g y)))
(λ i s → transport (λ j → B (≡spoke p s (~ j) i)) (elim nB g (p s i))))
(λ i → elim nB g (p s i))
q₂ j i = toPathP⁻ (λ j → B (≡spoke p s j i)) (λ j → q₁ j i) j
-- nullification is a modality
NullModality : ∀ {ℓ} (S : Type ℓ) → Modality ℓ
isModal (NullModality S) = isNull S
isModalIsProp (NullModality S) = isPropIsPathSplitEquiv _
◯ (NullModality S) = Null S
◯-isModal (NullModality S) = isNull-Null
η (NullModality S) = ∣_∣
◯-elim (NullModality S) = elim
◯-elim-β (NullModality S) = λ _ _ _ → refl
◯-=-isModal (NullModality S) x y = fromIsEquiv _ e
where e : isEquiv (λ (p : x ≡ y) → const {B = S} p)
e = transport (λ i → isEquiv {B = funExtPath {A = S} {f = const x} {g = const y} (~ i)}
(λ p → ua-gluePath funExtEquiv {x = const p} {y = cong const p} refl (~ i)))
(isEquivCong (_ , toIsEquiv _ isNull-Null))
idemNull : ∀ {ℓ} (S A : Type ℓ) → isNull S A → A ≃ Null S A
idemNull S A nA = ∣_∣ , isModalToIsEquiv (NullModality S) nA
-- nullification is localization at a map (S → 1)
module Null-iso-Localize {ℓ ℓ'} (S : Type ℓ) (A : Type ℓ') where
to : Null S A → Localize {A = Unit} (λ _ → const {B = S} tt) A
to ∣ x ∣ = ∣ x ∣
to (hub f) = ext tt (to ∘ f) tt
to (spoke f s i) = isExt tt (to ∘ f) s i
to (≡hub {x} {y} p i) = ≡ext tt (const (to x)) (const (to y)) (cong to ∘ p) tt i
to (≡spoke {x} {y} p s i j) = ≡isExt tt (const (to x)) (const (to y)) (cong to ∘ p) s i j
from : Localize {A = Unit} (λ _ → const {B = S} tt) A → Null S A
from ∣ x ∣ = ∣ x ∣
from (ext tt f tt) = hub (from ∘ f)
from (isExt tt f s i) = spoke (from ∘ f) s i
from (≡ext tt g h p tt i) = ≡hub {x = from (g tt)} {from (h tt)} (cong from ∘ p) i
from (≡isExt tt g h p s i j) = ≡spoke {x = from (g tt)} {from (h tt)} (cong from ∘ p) s i j
to-from : ∀ (x : Localize {A = Unit} (λ _ → const {B = S} tt) A) → to (from x) ≡ x
to-from ∣ x ∣ k = ∣ x ∣
to-from (ext tt f tt) k = ext tt (λ s → to-from (f s) k) tt
to-from (isExt tt f s i) k = isExt tt (λ s → to-from (f s) k) s i
to-from (≡ext tt g h p tt i) k = ≡ext tt (λ _ → to-from (g tt) k) (λ _ → to-from (h tt) k) (λ s j → to-from (p s j) k) tt i
to-from (≡isExt tt g h p s i j) k = ≡isExt tt (λ _ → to-from (g tt) k) (λ _ → to-from (h tt) k) (λ s j → to-from (p s j) k) s i j
from-to : ∀ (x : Null S A) → from (to x) ≡ x
from-to ∣ x ∣ k = ∣ x ∣
from-to (hub f) k = hub (λ s → from-to (f s) k)
from-to (spoke f s i) k = spoke (λ s → from-to (f s) k) s i
from-to (≡hub {x} {y} p i) k = ≡hub {x = from-to x k} {from-to y k} (λ s j → from-to (p s j) k) i
from-to (≡spoke {x} {y} p s i j) k = ≡spoke {x = from-to x k} {from-to y k} (λ s j → from-to (p s j) k) s i j
isom : Iso (Null S A) (Localize {A = Unit} (λ _ → const {B = S} tt) A)
isom = iso to from to-from from-to
Null≃Localize : ∀ {ℓ ℓ'} (S : Type ℓ) (A : Type ℓ') → Null S A ≃ Localize (λ _ → const tt) A
Null≃Localize S A = isoToEquiv (Null-iso-Localize.isom S A)
| 52.376923
| 131
| 0.493465
|
29a1fb9b8ebfef25a537f091efa812a24ab33728
| 522
|
agda
|
Agda
|
agda/Heapsort/Impl1/Correctness/Order.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/Heapsort/Impl1/Correctness/Order.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/Heapsort/Impl1/Correctness/Order.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module Heapsort.Impl1.Correctness.Order {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import Data.List
open import Function using (_∘_)
open import Heapsort.Impl1 _≤_ tot≤ trans≤
open import List.Sorted _≤_
open import OList _≤_
open import OList.Properties _≤_
theorem-heapsort-sorted : (xs : List A) → Sorted (forget (heapsort xs))
theorem-heapsort-sorted = lemma-olist-sorted ∘ heapsort
| 30.705882
| 71
| 0.657088
|
0628951b060a470d9ed7e2b1b955a648ae501dc2
| 5,311
|
agda
|
Agda
|
prototyping/Luau/StrictMode.agda
|
Libertus-Lab/luau
|
f1b46f4b967f11fabe666da1de0e71b225368260
|
[
"MIT"
] | 1
|
2021-11-06T08:03:00.000Z
|
2021-11-06T08:03:00.000Z
|
prototyping/Luau/StrictMode.agda
|
sthagen/Roblox-luau
|
39fbd2146a379fb0878369b48764cd7e8772c0fb
|
[
"MIT"
] | null | null | null |
prototyping/Luau/StrictMode.agda
|
sthagen/Roblox-luau
|
39fbd2146a379fb0878369b48764cd7e8772c0fb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Luau.StrictMode where
open import Agda.Builtin.Equality using (_≡_)
open import FFI.Data.Maybe using (just; nothing)
open import Luau.Syntax using (Expr; Stat; Block; BinaryOperator; yes; nil; addr; var; binexp; var_∈_; _⟨_⟩∈_; function_is_end; _$_; block_is_end; local_←_; _∙_; done; return; name; +; -; *; /; <; >; <=; >=; ··)
open import Luau.Type using (Type; nil; number; string; boolean; _⇒_; _∪_; _∩_)
open import Luau.ResolveOverloads using (src; resolve)
open import Luau.Subtyping using (_≮:_)
open import Luau.Heap using (Heap; function_is_end) renaming (_[_] to _[_]ᴴ)
open import Luau.VarCtxt using (VarCtxt; ∅; _⋒_; _↦_; _⊕_↦_; _⊝_) renaming (_[_] to _[_]ⱽ)
open import Luau.TypeCheck using (_⊢ᴮ_∈_; _⊢ᴱ_∈_; ⊢ᴴ_; ⊢ᴼ_; _⊢ᴴᴱ_▷_∈_; _⊢ᴴᴮ_▷_∈_; var; addr; app; binexp; block; return; local; function; srcBinOp)
open import Properties.Contradiction using (¬)
open import Properties.TypeCheck using (typeCheckᴮ)
open import Properties.Product using (_,_)
data Warningᴱ (H : Heap yes) {Γ} : ∀ {M T} → (Γ ⊢ᴱ M ∈ T) → Set
data Warningᴮ (H : Heap yes) {Γ} : ∀ {B T} → (Γ ⊢ᴮ B ∈ T) → Set
data Warningᴱ H {Γ} where
UnallocatedAddress : ∀ {a T} →
(H [ a ]ᴴ ≡ nothing) →
---------------------
Warningᴱ H (addr {a} T)
UnboundVariable : ∀ {x T p} →
(Γ [ x ]ⱽ ≡ nothing) →
------------------------
Warningᴱ H (var {x} {T} p)
FunctionCallMismatch : ∀ {M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
(U ≮: src T) →
-----------------
Warningᴱ H (app D₁ D₂)
app₁ : ∀ {M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
Warningᴱ H D₁ →
-----------------
Warningᴱ H (app D₁ D₂)
app₂ : ∀ {M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
Warningᴱ H D₂ →
-----------------
Warningᴱ H (app D₁ D₂)
BinOpMismatch₁ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
(T ≮: srcBinOp op) →
------------------------------
Warningᴱ H (binexp {op} D₁ D₂)
BinOpMismatch₂ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
(U ≮: srcBinOp op) →
------------------------------
Warningᴱ H (binexp {op} D₁ D₂)
bin₁ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
Warningᴱ H D₁ →
------------------------------
Warningᴱ H (binexp {op} D₁ D₂)
bin₂ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} →
Warningᴱ H D₂ →
------------------------------
Warningᴱ H (binexp {op} D₁ D₂)
FunctionDefnMismatch : ∀ {f x B T U V} {D : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} →
(V ≮: U) →
-------------------------
Warningᴱ H (function {f} {U = U} D)
function₁ : ∀ {f x B T U V} {D : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} →
Warningᴮ H D →
-------------------------
Warningᴱ H (function {f} {U = U} D)
BlockMismatch : ∀ {b B T U} {D : Γ ⊢ᴮ B ∈ U} →
(U ≮: T) →
------------------------------
Warningᴱ H (block {b} {T = T} D)
block₁ : ∀ {b B T U} {D : Γ ⊢ᴮ B ∈ U} →
Warningᴮ H D →
------------------------------
Warningᴱ H (block {b} {T = T} D)
data Warningᴮ H {Γ} where
return : ∀ {M B T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴮ B ∈ U} →
Warningᴱ H D₁ →
------------------
Warningᴮ H (return D₁ D₂)
LocalVarMismatch : ∀ {x M B T U V} {D₁ : Γ ⊢ᴱ M ∈ U} {D₂ : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} →
(U ≮: T) →
--------------------
Warningᴮ H (local D₁ D₂)
local₁ : ∀ {x M B T U V} {D₁ : Γ ⊢ᴱ M ∈ U} {D₂ : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} →
Warningᴱ H D₁ →
--------------------
Warningᴮ H (local D₁ D₂)
local₂ : ∀ {x M B T U V} {D₁ : Γ ⊢ᴱ M ∈ U} {D₂ : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} →
Warningᴮ H D₂ →
--------------------
Warningᴮ H (local D₁ D₂)
FunctionDefnMismatch : ∀ {f x B C T U V W} {D₁ : (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V} {D₂ : (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W} →
(V ≮: U) →
-------------------------------------
Warningᴮ H (function D₁ D₂)
function₁ : ∀ {f x B C T U V W} {D₁ : (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V} {D₂ : (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W} →
Warningᴮ H D₁ →
--------------------
Warningᴮ H (function D₁ D₂)
function₂ : ∀ {f x B C T U V W} {D₁ : (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V} {D₂ : (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W} →
Warningᴮ H D₂ →
--------------------
Warningᴮ H (function D₁ D₂)
data Warningᴼ (H : Heap yes) : ∀ {V} → (⊢ᴼ V) → Set where
FunctionDefnMismatch : ∀ {f x B T U V} {D : (x ↦ T) ⊢ᴮ B ∈ V} →
(V ≮: U) →
---------------------------------
Warningᴼ H (function {f} {U = U} D)
function₁ : ∀ {f x B T U V} {D : (x ↦ T) ⊢ᴮ B ∈ V} →
Warningᴮ H D →
---------------------------------
Warningᴼ H (function {f} {U = U} D)
data Warningᴴ H (D : ⊢ᴴ H) : Set where
addr : ∀ a {O} →
(p : H [ a ]ᴴ ≡ O) →
Warningᴼ H (D a p) →
---------------
Warningᴴ H D
data Warningᴴᴱ H {Γ M T} : (Γ ⊢ᴴᴱ H ▷ M ∈ T) → Set where
heap : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴱ M ∈ T} →
Warningᴴ H D₁ →
-----------------
Warningᴴᴱ H (D₁ , D₂)
expr : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴱ M ∈ T} →
Warningᴱ H D₂ →
---------------------
Warningᴴᴱ H (D₁ , D₂)
data Warningᴴᴮ H {Γ B T} : (Γ ⊢ᴴᴮ H ▷ B ∈ T) → Set where
heap : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴮ B ∈ T} →
Warningᴴ H D₁ →
-----------------
Warningᴴᴮ H (D₁ , D₂)
block : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴮ B ∈ T} →
Warningᴮ H D₂ →
---------------------
Warningᴴᴮ H (D₁ , D₂)
| 27.235897
| 211
| 0.434005
|
3881c4b1dff1a4c00f754f3e7dbe982873c9f8ff
| 1,026
|
agda
|
Agda
|
src/Categories/Category/Topos.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Topos.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Topos.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Topos {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Categories.Category.CartesianClosed C
open import Categories.Category.Complete.Finitely C
open import Categories.Diagram.Equalizer C
open import Categories.Diagram.SubobjectClassifier C
import Categories.Category.Complete.Finitely.Properties as Fₚ
open Category C
record Topos : Set (levelOfTerm C) where
field
cartesianClosed : CartesianClosed
subobjectClassifier : SubobjectClassifier
equalizer : ∀ {A B} (f g : A ⇒ B) → Equalizer f g
open CartesianClosed cartesianClosed public
module subobjectClassifier = SubobjectClassifier subobjectClassifier
finitelyComplete : FinitelyComplete
finitelyComplete = record
{ cartesian = cartesian
; equalizer = equalizer
}
open FinitelyComplete finitelyComplete using (module equalizer; pullback) public
open Fₚ finitelyComplete using (finiteLimit) public
| 27.72973
| 82
| 0.768031
|
38fac901e1e7139cd21e422f40307f69d8c0598e
| 202
|
agda
|
Agda
|
test/Succeed/Issue447.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue447.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue447.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Abstract definitions can't be projection-like
module Issue447 where
postulate
I : Set
R : I → Set
module M (i : I) (r : R i) where
abstract
P : Set₂
P = Set₁
p : P
p = Set
| 11.882353
| 48
| 0.579208
|
580842b49bc05c977777d6d51b91eb9b49b4ab69
| 1,921
|
agda
|
Agda
|
contraction.agda
|
hazelgrove/hazel-palette-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 16
|
2018-03-12T14:32:03.000Z
|
2021-12-19T02:50:23.000Z
|
contraction.agda
|
hazelgrove/hazel-palette-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 54
|
2017-06-29T20:53:34.000Z
|
2018-11-29T16:32:40.000Z
|
contraction.agda
|
hazelgrove/hazelnut-livelits-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 1
|
2019-09-13T18:20:02.000Z
|
2019-09-13T18:20:02.000Z
|
open import Prelude
open import Nat
open import core
open import contexts
open import lemmas-disjointness
module contraction where
-- in the same style as the proofs of exchange, this argument along with
-- trasnport allows you to prove contraction for all the hypothetical
-- judgements uniformly. we never explicitly use contraction anywhere, so
-- we omit any of the specific instances for concision; they are entirely
-- mechanical, as are the specific instances of exchange. one is shown
-- below as an example.
contract : {A : Set} {x : Nat} {τ : A} (Γ : A ctx) →
((Γ ,, (x , τ)) ,, (x , τ)) == (Γ ,, (x , τ))
contract {A} {x} {τ} Γ = funext guts
where
guts : (y : Nat) → (Γ ,, (x , τ) ,, (x , τ)) y == (Γ ,, (x , τ)) y
guts y with natEQ x y
guts .x | Inl refl with Γ x
guts .x | Inl refl | Some x₁ = refl
guts .x | Inl refl | None with natEQ x x
guts .x | Inl refl | None | Inl refl = refl
guts .x | Inl refl | None | Inr x₁ = abort (x₁ refl)
guts y | Inr x₁ with Γ y
guts y | Inr x₂ | Some x₁ = refl
guts y | Inr x₁ | None with natEQ x y
guts .x | Inr x₂ | None | Inl refl = refl
guts y | Inr x₂ | None | Inr x₁ with natEQ x y
guts .x | Inr x₃ | None | Inr x₂ | Inl refl = abort (x₃ refl)
guts y | Inr x₃ | None | Inr x₂ | Inr x₁ = refl
contract-synth : ∀{ Γ x τ e τ'}
→ (Γ ,, (x , τ) ,, (x , τ)) ⊢ e => τ'
→ (Γ ,, (x , τ)) ⊢ e => τ'
contract-synth {Γ = Γ} {e = e} {τ' = τ'} =
tr (λ qq → qq ⊢ e => τ') (contract Γ)
-- as an aside, this also establishes the other direction which is rarely
-- mentioned, since equality is symmetric
elab-synth : ∀{ Γ x τ e τ'}
→ (Γ ,, (x , τ)) ⊢ e => τ'
→ (Γ ,, (x , τ) ,, (x , τ)) ⊢ e => τ'
elab-synth {Γ = Γ} {e = e} {τ' = τ'} =
tr (λ qq → qq ⊢ e => τ') (! (contract Γ))
| 41.76087
| 75
| 0.536179
|
578f6a17aa4d88c5d7dd96297033c94a40db8937
| 697
|
agda
|
Agda
|
test/Fail/TerminationCheckUnquote.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/TerminationCheckUnquote.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/TerminationCheckUnquote.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Check that unquoted functions are termination checked.
module _ where
open import Common.Prelude hiding (_>>=_)
open import Common.Reflection
open import Common.Equality
`⊥ : Type
`⊥ = def (quote ⊥) []
⊥-elim : ∀ {a} {A : Set a} → ⊥ → A
⊥-elim ()
{-
Generate
cheat : ⊥
cheat = cheat
-}
makeLoop : TC Term
makeLoop =
freshName "cheat" >>= λ cheat →
declareDef (vArg cheat) `⊥ >>= λ _ →
defineFun cheat (clause [] [] (def cheat []) ∷ []) >>= λ _ →
returnTC (def cheat [])
macro
magic : Tactic
magic hole =
makeLoop >>= λ loop →
unify hole (def (quote ⊥-elim) (vArg loop ∷ []))
postulate
ComplexityClass : Set
P NP : ComplexityClass
thm : P ≡ NP → ⊥
thm = magic
| 18.342105
| 62
| 0.609756
|
9af365e3f0f4a622791bcde32a027a264fd7c824
| 138
|
agda
|
Agda
|
test/interaction/Issue4333/N0.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue4333/N0.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue4333/N0.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting --confluence-check #-}
module Issue4333.N0 where
open import Issue4333.M
{-# REWRITE p₀ #-}
b₀' : B a₀'
b₀' = b
| 15.333333
| 46
| 0.652174
|
381d5a96e0ba3252debc369301ae12fbe0e32b3b
| 8,570
|
agda
|
Agda
|
Cubical/Algebra/Semilattice/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:28:39.000Z
|
2022-03-05T00:28:39.000Z
|
Cubical/Algebra/Semilattice/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semilattice/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-
following Johnstone's book "Stone Spaces" we define semilattices
to be commutative monoids such that every element is idempotent.
In particular, we take every semilattice to have a neutral element
that is either the maximal or minimal element depending on whether
we have a join or meet semilattice.
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Semilattice.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.CommMonoid
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Reflection.RecordEquiv
open Iso
private
variable
ℓ ℓ' : Level
record IsSemilattice {A : Type ℓ} (ε : A) (_·_ : A → A → A) : Type ℓ where
constructor issemilattice
field
isCommMonoid : IsCommMonoid ε _·_
idem : (x : A) → x · x ≡ x
open IsCommMonoid isCommMonoid public
unquoteDecl IsSemilatticeIsoΣ = declareRecordIsoΣ IsSemilatticeIsoΣ (quote IsSemilattice)
record SemilatticeStr (A : Type ℓ) : Type ℓ where
constructor semilatticestr
field
ε : A
_·_ : A → A → A
isSemilattice : IsSemilattice ε _·_
infixl 7 _·_
open IsSemilattice isSemilattice public
Semilattice : ∀ ℓ → Type (ℓ-suc ℓ)
Semilattice ℓ = TypeWithStr ℓ SemilatticeStr
semilattice : (A : Type ℓ) (ε : A) (_·_ : A → A → A) (h : IsSemilattice ε _·_) → Semilattice ℓ
semilattice A ε _·_ h = A , semilatticestr ε _·_ h
-- Easier to use constructors
makeIsSemilattice : {L : Type ℓ} {ε : L} {_·_ : L → L → L}
(is-setL : isSet L)
(assoc : (x y z : L) → x · (y · z) ≡ (x · y) · z)
(rid : (x : L) → x · ε ≡ x)
(lid : (x : L) → ε · x ≡ x)
(comm : (x y : L) → x · y ≡ y · x)
(idem : (x : L) → x · x ≡ x)
→ IsSemilattice ε _·_
IsSemilattice.isCommMonoid (makeIsSemilattice is-setL assoc rid lid comm idem) =
makeIsCommMonoid is-setL assoc rid lid comm
IsSemilattice.idem (makeIsSemilattice is-setL assoc rid lid comm idem) = idem
makeSemilattice : {L : Type ℓ} (ε : L) (_·_ : L → L → L)
(is-setL : isSet L)
(assoc : (x y z : L) → x · (y · z) ≡ (x · y) · z)
(rid : (x : L) → x · ε ≡ x)
(lid : (x : L) → ε · x ≡ x)
(comm : (x y : L) → x · y ≡ y · x)
(idem : (x : L) → x · x ≡ x)
→ Semilattice ℓ
makeSemilattice ε _·_ is-setL assoc rid lid comm idem =
semilattice _ ε _·_ (makeIsSemilattice is-setL assoc rid lid comm idem)
SemilatticeStr→MonoidStr : {A : Type ℓ} → SemilatticeStr A → MonoidStr A
SemilatticeStr→MonoidStr (semilatticestr _ _ H) =
monoidstr _ _ (H .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid)
Semilattice→Monoid : Semilattice ℓ → Monoid ℓ
Semilattice→Monoid (_ , semilatticestr _ _ H) =
_ , monoidstr _ _ (H .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid)
Semilattice→CommMonoid : Semilattice ℓ → CommMonoid ℓ
Semilattice→CommMonoid (_ , semilatticestr _ _ H) =
_ , commmonoidstr _ _ (H .IsSemilattice.isCommMonoid)
SemilatticeHom : (L : Semilattice ℓ) (M : Semilattice ℓ') → Type (ℓ-max ℓ ℓ')
SemilatticeHom L M = MonoidHom (Semilattice→Monoid L) (Semilattice→Monoid M)
IsSemilatticeEquiv : {A : Type ℓ} {B : Type ℓ'}
(M : SemilatticeStr A) (e : A ≃ B) (N : SemilatticeStr B) → Type (ℓ-max ℓ ℓ')
IsSemilatticeEquiv M e N =
IsMonoidHom (SemilatticeStr→MonoidStr M) (e .fst) (SemilatticeStr→MonoidStr N)
SemilatticeEquiv : (M : Semilattice ℓ) (N : Semilattice ℓ') → Type (ℓ-max ℓ ℓ')
SemilatticeEquiv M N = Σ[ e ∈ (M .fst ≃ N .fst) ] IsSemilatticeEquiv (M .snd) e (N .snd)
isPropIsSemilattice : {L : Type ℓ} (ε : L) (_·_ : L → L → L)
→ isProp (IsSemilattice ε _·_)
isPropIsSemilattice ε _·_ (issemilattice LL LC) (issemilattice SL SC) =
λ i → issemilattice (isPropIsCommMonoid _ _ LL SL i) (isPropIdem LC SC i)
where
isSetL : isSet _
isSetL = LL .IsCommMonoid.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropIdem : isProp ((x : _) → x · x ≡ x)
isPropIdem = isPropΠ λ _ → isSetL _ _
𝒮ᴰ-Semilattice : DUARel (𝒮-Univ ℓ) SemilatticeStr ℓ
𝒮ᴰ-Semilattice =
𝒮ᴰ-Record (𝒮-Univ _) IsSemilatticeEquiv
(fields:
data[ ε ∣ autoDUARel _ _ ∣ presε ]
data[ _·_ ∣ autoDUARel _ _ ∣ isHom ]
prop[ isSemilattice ∣ (λ _ _ → isPropIsSemilattice _ _) ])
where
open SemilatticeStr
open IsMonoidHom
SemilatticePath : (L K : Semilattice ℓ) → SemilatticeEquiv L K ≃ (L ≡ K)
SemilatticePath = ∫ 𝒮ᴰ-Semilattice .UARel.ua
-- TODO: decide if that's the right approach
module JoinSemilattice (L' : Semilattice ℓ) where
private L = fst L'
open SemilatticeStr (snd L') renaming (_·_ to _∨l_ ; ε to 1l)
open CommMonoidTheory (Semilattice→CommMonoid L')
_≤_ : L → L → Type ℓ
x ≤ y = x ∨l y ≡ y
infix 4 _≤_
IndPoset : Poset ℓ ℓ
fst IndPoset = L
PosetStr._≤_ (snd IndPoset) = _≤_
IsPoset.is-set (PosetStr.isPoset (snd IndPoset)) = is-set
IsPoset.is-prop-valued (PosetStr.isPoset (snd IndPoset)) = λ _ _ → is-set _ _
IsPoset.is-refl (PosetStr.isPoset (snd IndPoset)) = idem
IsPoset.is-trans (PosetStr.isPoset (snd IndPoset)) = path
where
path : (a b c : L) → a ∨l b ≡ b → b ∨l c ≡ c → a ∨l c ≡ c
path a b c a∨b≡b b∨c≡c = a ∨l c ≡⟨ cong (a ∨l_) (sym b∨c≡c) ⟩
a ∨l (b ∨l c) ≡⟨ assoc _ _ _ ⟩
(a ∨l b) ∨l c ≡⟨ cong (_∨l c) a∨b≡b ⟩
b ∨l c ≡⟨ b∨c≡c ⟩
c ∎
IsPoset.is-antisym (PosetStr.isPoset (snd IndPoset)) =
λ _ _ a∨b≡b b∨a≡a → sym b∨a≡a ∙∙ comm _ _ ∙∙ a∨b≡b
∨lIsMax : ∀ x y z → x ≤ z → y ≤ z → x ∨l y ≤ z
∨lIsMax x y z x≤z y≤z = cong ((x ∨l y) ∨l_) (sym (idem z)) ∙ commAssocSwap x y z z
∙ cong₂ (_∨l_) x≤z y≤z
∙ idem z
∨≤LCancel : ∀ x y → y ≤ x ∨l y
∨≤LCancel x y = commAssocl y x y ∙ cong (x ∨l_) (idem y)
∨≤RCancel : ∀ x y → x ≤ x ∨l y
∨≤RCancel x y = assoc _ _ _ ∙ cong (_∨l y) (idem x)
≤-∨Pres : ∀ x y u w → x ≤ y → u ≤ w → x ∨l u ≤ y ∨l w
≤-∨Pres x y u w x≤y u≤w = commAssocSwap x u y w ∙ cong₂ (_∨l_) x≤y u≤w
≤-∨LPres : ∀ x y z → x ≤ y → z ∨l x ≤ z ∨l y
≤-∨LPres x y z x≤y = ≤-∨Pres _ _ _ _ (idem z) x≤y
module MeetSemilattice (L' : Semilattice ℓ) where
private L = fst L'
open SemilatticeStr (snd L') renaming (_·_ to _∧l_ ; ε to 0l)
open CommMonoidTheory (Semilattice→CommMonoid L')
_≤_ : L → L → Type ℓ
x ≤ y = x ∧l y ≡ x
infix 4 _≤_
IndPoset : Poset ℓ ℓ
fst IndPoset = L
PosetStr._≤_ (snd IndPoset) = _≤_
IsPoset.is-set (PosetStr.isPoset (snd IndPoset)) = is-set
IsPoset.is-prop-valued (PosetStr.isPoset (snd IndPoset)) = λ _ _ → is-set _ _
IsPoset.is-refl (PosetStr.isPoset (snd IndPoset)) = idem
IsPoset.is-trans (PosetStr.isPoset (snd IndPoset)) = path
where
path : (a b c : L) → a ∧l b ≡ a → b ∧l c ≡ b → a ∧l c ≡ a
path a b c a∧b≡a b∧c≡b = a ∧l c ≡⟨ cong (_∧l c) (sym a∧b≡a) ⟩
(a ∧l b) ∧l c ≡⟨ sym (assoc _ _ _) ⟩
a ∧l (b ∧l c) ≡⟨ cong (a ∧l_) b∧c≡b ⟩
a ∧l b ≡⟨ a∧b≡a ⟩
a ∎
IsPoset.is-antisym (PosetStr.isPoset (snd IndPoset)) =
λ _ _ a∧b≡a b∧a≡b → sym a∧b≡a ∙∙ comm _ _ ∙∙ b∧a≡b
≤-∧LPres : ∀ x y z → x ≤ y → z ∧l x ≤ z ∧l y
≤-∧LPres x y z x≤y = commAssocSwap z x z y ∙∙ cong (_∧l (x ∧l y)) (idem z) ∙∙ cong (z ∧l_) x≤y
∧≤LCancel : ∀ x y → x ∧l y ≤ y
∧≤LCancel x y = sym (assoc _ _ _) ∙ cong (x ∧l_) (idem y)
∧≤RCancel : ∀ x y → x ∧l y ≤ x
∧≤RCancel x y = commAssocr x y x ∙ cong (_∧l y) (idem x)
∧lIsMin : ∀ x y z → z ≤ x → z ≤ y → z ≤ x ∧l y
∧lIsMin x y z z≤x z≤y = cong (_∧l (x ∧l y)) (sym (idem z)) ∙ commAssocSwap z z x y
∙ cong₂ (_∧l_) z≤x z≤y
∙ idem z
| 36.623932
| 97
| 0.588215
|
04a290679b8e66622f2634fc07662eec86cf8b68
| 16,617
|
agda
|
Agda
|
agda-stdlib-0.9/src/Relation/Binary/Sigma/Pointwise.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | 1
|
2016-10-20T15:52:05.000Z
|
2016-10-20T15:52:05.000Z
|
agda-stdlib-0.9/src/Relation/Binary/Sigma/Pointwise.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Relation/Binary/Sigma/Pointwise.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise lifting of binary relations to sigma types
------------------------------------------------------------------------
module Relation.Binary.Sigma.Pointwise where
open import Data.Product as Prod
open import Level
open import Function
open import Function.Equality as F using (_⟶_; _⟨$⟩_)
open import Function.Equivalence as Eq
using (Equivalence; _⇔_; module Equivalence)
open import Function.Injection as Inj
using (Injection; _↣_; module Injection; Injective)
open import Function.Inverse as Inv
using (Inverse; _↔_; module Inverse)
open import Function.LeftInverse as LeftInv
using (LeftInverse; _↞_; module LeftInverse;
_LeftInverseOf_; _RightInverseOf_)
open import Function.Related as Related
using (_∼[_]_; lam; app-←; app-↢)
open import Function.Surjection as Surj
using (Surjection; _↠_; module Surjection)
import Relation.Binary as B
open import Relation.Binary.Indexed as I using (_at_)
import Relation.Binary.HeterogeneousEquality as H
import Relation.Binary.PropositionalEquality as P
------------------------------------------------------------------------
-- Pointwise lifting
infixr 4 _,_
data REL {a₁ a₂ b₁ b₂ ℓ₁ ℓ₂}
{A₁ : Set a₁} (B₁ : A₁ → Set b₁)
{A₂ : Set a₂} (B₂ : A₂ → Set b₂)
(_R₁_ : B.REL A₁ A₂ ℓ₁) (_R₂_ : I.REL B₁ B₂ ℓ₂) :
B.REL (Σ A₁ B₁) (Σ A₂ B₂) (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂ ⊔ ℓ₁ ⊔ ℓ₂) where
_,_ : {x₁ : A₁} {y₁ : B₁ x₁} {x₂ : A₂} {y₂ : B₂ x₂}
(x₁Rx₂ : x₁ R₁ x₂) (y₁Ry₂ : y₁ R₂ y₂) →
REL B₁ B₂ _R₁_ _R₂_ (x₁ , y₁) (x₂ , y₂)
Rel : ∀ {a b ℓ₁ ℓ₂} {A : Set a} (B : A → Set b)
(_R₁_ : B.Rel A ℓ₁) (_R₂_ : I.Rel B ℓ₂) → B.Rel (Σ A B) _
Rel B = REL B B
------------------------------------------------------------------------
-- Rel preserves many properties
module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b}
{R₁ : B.Rel A ℓ₁} {R₂ : I.Rel B ℓ₂} where
refl : B.Reflexive R₁ → I.Reflexive B R₂ →
B.Reflexive (Rel B R₁ R₂)
refl refl₁ refl₂ {x = (x , y)} = (refl₁ , refl₂)
symmetric : B.Symmetric R₁ → I.Symmetric B R₂ →
B.Symmetric (Rel B R₁ R₂)
symmetric sym₁ sym₂ (x₁Rx₂ , y₁Ry₂) = (sym₁ x₁Rx₂ , sym₂ y₁Ry₂)
transitive : B.Transitive R₁ → I.Transitive B R₂ →
B.Transitive (Rel B R₁ R₂)
transitive trans₁ trans₂ (x₁Rx₂ , y₁Ry₂) (x₂Rx₃ , y₂Ry₃) =
(trans₁ x₁Rx₂ x₂Rx₃ , trans₂ y₁Ry₂ y₂Ry₃)
isEquivalence : B.IsEquivalence R₁ → I.IsEquivalence B R₂ →
B.IsEquivalence (Rel B R₁ R₂)
isEquivalence eq₁ eq₂ = record
{ refl = refl (B.IsEquivalence.refl eq₁)
(I.IsEquivalence.refl eq₂)
; sym = symmetric (B.IsEquivalence.sym eq₁)
(I.IsEquivalence.sym eq₂)
; trans = transitive (B.IsEquivalence.trans eq₁)
(I.IsEquivalence.trans eq₂)
}
setoid : ∀ {b₁ b₂ i₁ i₂} →
(A : B.Setoid b₁ b₂) → I.Setoid (B.Setoid.Carrier A) i₁ i₂ →
B.Setoid _ _
setoid s₁ s₂ = record
{ isEquivalence = isEquivalence (B.Setoid.isEquivalence s₁)
(I.Setoid.isEquivalence s₂)
}
------------------------------------------------------------------------
-- The propositional equality setoid over sigma types can be
-- decomposed using Rel
Rel↔≡ : ∀ {a b} {A : Set a} {B : A → Set b} →
Inverse (setoid (P.setoid A) (H.indexedSetoid B))
(P.setoid (Σ A B))
Rel↔≡ {a} {b} {A} {B} = record
{ to = record { _⟨$⟩_ = id; cong = to-cong }
; from = record { _⟨$⟩_ = id; cong = from-cong }
; inverse-of = record
{ left-inverse-of = uncurry (λ _ _ → (P.refl , H.refl))
; right-inverse-of = λ _ → P.refl
}
}
where
open I using (_=[_]⇒_)
to-cong : Rel B P._≡_ (λ x y → H._≅_ x y) =[ id {a = a ⊔ b} ]⇒ P._≡_
to-cong (P.refl , H.refl) = P.refl
from-cong : P._≡_ =[ id {a = a ⊔ b} ]⇒ Rel B P._≡_ (λ x y → H._≅_ x y)
from-cong {i = (x , y)} P.refl = (P.refl , H.refl)
------------------------------------------------------------------------
-- Some properties related to "relatedness"
⟶ : ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′)
(f : A₁ → A₂) → (∀ {x} → (B₁ at x) ⟶ (B₂ at f x)) →
setoid (P.setoid A₁) B₁ ⟶ setoid (P.setoid A₂) B₂
⟶ {A₁ = A₁} {A₂} {B₁} B₂ f g = record
{ _⟨$⟩_ = fg
; cong = fg-cong
}
where
open B.Setoid (setoid (P.setoid A₁) B₁)
using () renaming (_≈_ to _≈₁_)
open B.Setoid (setoid (P.setoid A₂) B₂)
using () renaming (_≈_ to _≈₂_)
open B using (_=[_]⇒_)
fg = Prod.map f (_⟨$⟩_ g)
fg-cong : _≈₁_ =[ fg ]⇒ _≈₂_
fg-cong (P.refl , ∼) = (P.refl , F.cong g ∼)
equivalence :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : I.Setoid A₁ b₁ b₁′} {B₂ : I.Setoid A₂ b₂ b₂′}
(A₁⇔A₂ : A₁ ⇔ A₂) →
(∀ {x} → _⟶_ (B₁ at x) (B₂ at (Equivalence.to A₁⇔A₂ ⟨$⟩ x))) →
(∀ {y} → _⟶_ (B₂ at y) (B₁ at (Equivalence.from A₁⇔A₂ ⟨$⟩ y))) →
Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
equivalence {B₁ = B₁} {B₂} A₁⇔A₂ B-to B-from = record
{ to = ⟶ B₂ (_⟨$⟩_ (to A₁⇔A₂)) B-to
; from = ⟶ B₁ (_⟨$⟩_ (from A₁⇔A₂)) B-from
} where open Equivalence
private
subst-cong : ∀ {i a p} {I : Set i} {A : I → Set a}
(P : ∀ {i} → A i → A i → Set p) {i i′} {x y : A i}
(i≡i′ : P._≡_ i i′) →
P x y → P (P.subst A i≡i′ x) (P.subst A i≡i′ y)
subst-cong P P.refl p = p
equivalence-↞ :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
(B₁ : I.Setoid A₁ b₁ b₁′) {B₂ : I.Setoid A₂ b₂ b₂′}
(A₁↞A₂ : A₁ ↞ A₂) →
(∀ {x} → Equivalence (B₁ at (LeftInverse.from A₁↞A₂ ⟨$⟩ x))
(B₂ at x)) →
Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
equivalence-↞ B₁ {B₂} A₁↞A₂ B₁⇔B₂ =
equivalence (LeftInverse.equivalence A₁↞A₂) B-to B-from
where
B-to : ∀ {x} → _⟶_ (B₁ at x) (B₂ at (LeftInverse.to A₁↞A₂ ⟨$⟩ x))
B-to = record
{ _⟨$⟩_ = λ x → Equivalence.to B₁⇔B₂ ⟨$⟩
P.subst (I.Setoid.Carrier B₁)
(P.sym $ LeftInverse.left-inverse-of A₁↞A₂ _)
x
; cong = F.cong (Equivalence.to B₁⇔B₂) ∘
subst-cong (λ {x} → I.Setoid._≈_ B₁ {x} {x})
(P.sym (LeftInverse.left-inverse-of A₁↞A₂ _))
}
B-from : ∀ {y} → _⟶_ (B₂ at y) (B₁ at (LeftInverse.from A₁↞A₂ ⟨$⟩ y))
B-from = Equivalence.from B₁⇔B₂
equivalence-↠ :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′)
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ {x} → Equivalence (B₁ at x) (B₂ at (Surjection.to A₁↠A₂ ⟨$⟩ x))) →
Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
equivalence-↠ {B₁ = B₁} B₂ A₁↠A₂ B₁⇔B₂ =
equivalence (Surjection.equivalence A₁↠A₂) B-to B-from
where
B-to : ∀ {x} → B₁ at x ⟶ B₂ at (Surjection.to A₁↠A₂ ⟨$⟩ x)
B-to = Equivalence.to B₁⇔B₂
B-from : ∀ {y} → B₂ at y ⟶ B₁ at (Surjection.from A₁↠A₂ ⟨$⟩ y)
B-from = record
{ _⟨$⟩_ = λ x → Equivalence.from B₁⇔B₂ ⟨$⟩
P.subst (I.Setoid.Carrier B₂)
(P.sym $ Surjection.right-inverse-of A₁↠A₂ _)
x
; cong = F.cong (Equivalence.from B₁⇔B₂) ∘
subst-cong (λ {x} → I.Setoid._≈_ B₂ {x} {x})
(P.sym (Surjection.right-inverse-of A₁↠A₂ _))
}
⇔ : ∀ {a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁⇔A₂ : A₁ ⇔ A₂) →
(∀ {x} → B₁ x → B₂ (Equivalence.to A₁⇔A₂ ⟨$⟩ x)) →
(∀ {y} → B₂ y → B₁ (Equivalence.from A₁⇔A₂ ⟨$⟩ y)) →
Σ A₁ B₁ ⇔ Σ A₂ B₂
⇔ {B₁ = B₁} {B₂} A₁⇔A₂ B-to B-from =
Inverse.equivalence (Rel↔≡ {B = B₂}) ⟨∘⟩
equivalence A₁⇔A₂
(Inverse.to (H.≡↔≅ B₂) ⊚ P.→-to-⟶ B-to ⊚ Inverse.from (H.≡↔≅ B₁))
(Inverse.to (H.≡↔≅ B₁) ⊚ P.→-to-⟶ B-from ⊚ Inverse.from (H.≡↔≅ B₂))
⟨∘⟩
Eq.sym (Inverse.equivalence (Rel↔≡ {B = B₁}))
where
open Eq using () renaming (_∘_ to _⟨∘⟩_)
open F using () renaming (_∘_ to _⊚_)
⇔-↠ : ∀ {a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ {x} → _⇔_ (B₁ x) (B₂ (Surjection.to A₁↠A₂ ⟨$⟩ x))) →
_⇔_ (Σ A₁ B₁) (Σ A₂ B₂)
⇔-↠ {B₁ = B₁} {B₂} A₁↠A₂ B₁⇔B₂ =
Inverse.equivalence (Rel↔≡ {B = B₂}) ⟨∘⟩
equivalence-↠ (H.indexedSetoid B₂) A₁↠A₂
(λ {x} → Inverse.equivalence (H.≡↔≅ B₂) ⟨∘⟩
B₁⇔B₂ {x} ⟨∘⟩
Inverse.equivalence (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
Eq.sym (Inverse.equivalence (Rel↔≡ {B = B₁}))
where open Eq using () renaming (_∘_ to _⟨∘⟩_)
injection :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′) →
(A₁↣A₂ : A₁ ↣ A₂) →
(∀ {x} → Injection (B₁ at x) (B₂ at (Injection.to A₁↣A₂ ⟨$⟩ x))) →
Injection (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
injection {B₁ = B₁} B₂ A₁↣A₂ B₁↣B₂ = record
{ to = to
; injective = inj
}
where
to = ⟶ B₂ (_⟨$⟩_ (Injection.to A₁↣A₂)) (Injection.to B₁↣B₂)
inj : Injective to
inj (x , y) =
Injection.injective A₁↣A₂ x ,
lemma (Injection.injective A₁↣A₂ x) y
where
lemma :
∀ {x x′}
{y : I.Setoid.Carrier B₁ x} {y′ : I.Setoid.Carrier B₁ x′} →
P._≡_ x x′ →
(eq : I.Setoid._≈_ B₂ (Injection.to B₁↣B₂ ⟨$⟩ y)
(Injection.to B₁↣B₂ ⟨$⟩ y′)) →
I.Setoid._≈_ B₁ y y′
lemma P.refl = Injection.injective B₁↣B₂
↣ : ∀ {a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁↣A₂ : A₁ ↣ A₂) →
(∀ {x} → B₁ x ↣ B₂ (Injection.to A₁↣A₂ ⟨$⟩ x)) →
Σ A₁ B₁ ↣ Σ A₂ B₂
↣ {B₁ = B₁} {B₂} A₁↣A₂ B₁↣B₂ =
Inverse.injection (Rel↔≡ {B = B₂}) ⟨∘⟩
injection (H.indexedSetoid B₂) A₁↣A₂
(λ {x} → Inverse.injection (H.≡↔≅ B₂) ⟨∘⟩
B₁↣B₂ {x} ⟨∘⟩
Inverse.injection (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
Inverse.injection (Inv.sym (Rel↔≡ {B = B₁}))
where open Inj using () renaming (_∘_ to _⟨∘⟩_)
left-inverse :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
(B₁ : I.Setoid A₁ b₁ b₁′) {B₂ : I.Setoid A₂ b₂ b₂′} →
(A₁↞A₂ : A₁ ↞ A₂) →
(∀ {x} → LeftInverse (B₁ at (LeftInverse.from A₁↞A₂ ⟨$⟩ x))
(B₂ at x)) →
LeftInverse (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
left-inverse B₁ {B₂} A₁↞A₂ B₁↞B₂ = record
{ to = Equivalence.to eq
; from = Equivalence.from eq
; left-inverse-of = left
}
where
eq = equivalence-↞ B₁ A₁↞A₂ (LeftInverse.equivalence B₁↞B₂)
left : Equivalence.from eq LeftInverseOf Equivalence.to eq
left (x , y) =
LeftInverse.left-inverse-of A₁↞A₂ x ,
I.Setoid.trans B₁
(LeftInverse.left-inverse-of B₁↞B₂ _)
(lemma (P.sym (LeftInverse.left-inverse-of A₁↞A₂ x)))
where
lemma :
∀ {x x′ y} (eq : P._≡_ x x′) →
I.Setoid._≈_ B₁ (P.subst (I.Setoid.Carrier B₁) eq y) y
lemma P.refl = I.Setoid.refl B₁
↞ : ∀ {a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁↞A₂ : A₁ ↞ A₂) →
(∀ {x} → B₁ (LeftInverse.from A₁↞A₂ ⟨$⟩ x) ↞ B₂ x) →
Σ A₁ B₁ ↞ Σ A₂ B₂
↞ {B₁ = B₁} {B₂} A₁↞A₂ B₁↞B₂ =
Inverse.left-inverse (Rel↔≡ {B = B₂}) ⟨∘⟩
left-inverse (H.indexedSetoid B₁) A₁↞A₂
(λ {x} → Inverse.left-inverse (H.≡↔≅ B₂) ⟨∘⟩
B₁↞B₂ {x} ⟨∘⟩
Inverse.left-inverse (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
Inverse.left-inverse (Inv.sym (Rel↔≡ {B = B₁}))
where open LeftInv using () renaming (_∘_ to _⟨∘⟩_)
surjection :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′) →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ {x} → Surjection (B₁ at x) (B₂ at (Surjection.to A₁↠A₂ ⟨$⟩ x))) →
Surjection (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
surjection {B₁} B₂ A₁↠A₂ B₁↠B₂ = record
{ to = Equivalence.to eq
; surjective = record
{ from = Equivalence.from eq
; right-inverse-of = right
}
}
where
eq = equivalence-↠ B₂ A₁↠A₂ (Surjection.equivalence B₁↠B₂)
right : Equivalence.from eq RightInverseOf Equivalence.to eq
right (x , y) =
Surjection.right-inverse-of A₁↠A₂ x ,
I.Setoid.trans B₂
(Surjection.right-inverse-of B₁↠B₂ _)
(lemma (P.sym $ Surjection.right-inverse-of A₁↠A₂ x))
where
lemma : ∀ {x x′ y} (eq : P._≡_ x x′) →
I.Setoid._≈_ B₂ (P.subst (I.Setoid.Carrier B₂) eq y) y
lemma P.refl = I.Setoid.refl B₂
↠ : ∀ {a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ {x} → B₁ x ↠ B₂ (Surjection.to A₁↠A₂ ⟨$⟩ x)) →
Σ A₁ B₁ ↠ Σ A₂ B₂
↠ {B₁ = B₁} {B₂} A₁↠A₂ B₁↠B₂ =
Inverse.surjection (Rel↔≡ {B = B₂}) ⟨∘⟩
surjection (H.indexedSetoid B₂) A₁↠A₂
(λ {x} → Inverse.surjection (H.≡↔≅ B₂) ⟨∘⟩
B₁↠B₂ {x} ⟨∘⟩
Inverse.surjection (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
Inverse.surjection (Inv.sym (Rel↔≡ {B = B₁}))
where open Surj using () renaming (_∘_ to _⟨∘⟩_)
inverse :
∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′) →
(A₁↔A₂ : A₁ ↔ A₂) →
(∀ {x} → Inverse (B₁ at x) (B₂ at (Inverse.to A₁↔A₂ ⟨$⟩ x))) →
Inverse (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
inverse {B₁ = B₁} B₂ A₁↔A₂ B₁↔B₂ = record
{ to = Surjection.to surj
; from = Surjection.from surj
; inverse-of = record
{ left-inverse-of = left
; right-inverse-of = Surjection.right-inverse-of surj
}
}
where
surj = surjection B₂ (Inverse.surjection A₁↔A₂)
(Inverse.surjection B₁↔B₂)
left : Surjection.from surj LeftInverseOf Surjection.to surj
left (x , y) =
Inverse.left-inverse-of A₁↔A₂ x ,
I.Setoid.trans B₁
(lemma (P.sym (Inverse.left-inverse-of A₁↔A₂ x))
(P.sym (Inverse.right-inverse-of A₁↔A₂
(Inverse.to A₁↔A₂ ⟨$⟩ x))))
(Inverse.left-inverse-of B₁↔B₂ y)
where
lemma :
∀ {x x′ y} → P._≡_ x x′ →
(eq : P._≡_ (Inverse.to A₁↔A₂ ⟨$⟩ x) (Inverse.to A₁↔A₂ ⟨$⟩ x′)) →
I.Setoid._≈_ B₁
(Inverse.from B₁↔B₂ ⟨$⟩ P.subst (I.Setoid.Carrier B₂) eq y)
(Inverse.from B₁↔B₂ ⟨$⟩ y)
lemma P.refl P.refl = I.Setoid.refl B₁
↔ : ∀ {a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁↔A₂ : A₁ ↔ A₂) →
(∀ {x} → B₁ x ↔ B₂ (Inverse.to A₁↔A₂ ⟨$⟩ x)) →
Σ A₁ B₁ ↔ Σ A₂ B₂
↔ {B₁ = B₁} {B₂} A₁↔A₂ B₁↔B₂ =
Rel↔≡ {B = B₂} ⟨∘⟩
inverse (H.indexedSetoid B₂) A₁↔A₂
(λ {x} → H.≡↔≅ B₂ ⟨∘⟩ B₁↔B₂ {x} ⟨∘⟩ Inv.sym (H.≡↔≅ B₁)) ⟨∘⟩
Inv.sym (Rel↔≡ {B = B₁})
where open Inv using () renaming (_∘_ to _⟨∘⟩_)
private
swap-coercions :
∀ {k a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂} {B₁ : A₁ → Set b₁} (B₂ : A₂ → Set b₂)
(A₁↔A₂ : _↔_ A₁ A₂) →
(∀ {x} → B₁ x ∼[ k ] B₂ (Inverse.to A₁↔A₂ ⟨$⟩ x)) →
∀ {x} → B₁ (Inverse.from A₁↔A₂ ⟨$⟩ x) ∼[ k ] B₂ x
swap-coercions {k} {B₁ = B₁} B₂ A₁↔A₂ eq {x} =
B₁ (Inverse.from A₁↔A₂ ⟨$⟩ x) ∼⟨ eq ⟩
B₂ (Inverse.to A₁↔A₂ ⟨$⟩ (Inverse.from A₁↔A₂ ⟨$⟩ x)) ↔⟨ B.Setoid.reflexive (Related.setoid Related.bijection _)
(P.cong B₂ $ Inverse.right-inverse-of A₁↔A₂ x) ⟩
B₂ x ∎
where open Related.EquationalReasoning
cong : ∀ {k a₁ a₂ b₁ b₂}
{A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(A₁↔A₂ : _↔_ A₁ A₂) →
(∀ {x} → B₁ x ∼[ k ] B₂ (Inverse.to A₁↔A₂ ⟨$⟩ x)) →
Σ A₁ B₁ ∼[ k ] Σ A₂ B₂
cong {Related.implication} = λ A₁↔A₂ → Prod.map (_⟨$⟩_ (Inverse.to A₁↔A₂))
cong {Related.reverse-implication} {B₂ = B₂} = λ A₁↔A₂ B₁←B₂ → lam (Prod.map (_⟨$⟩_ (Inverse.from A₁↔A₂))
(app-← (swap-coercions B₂ A₁↔A₂ B₁←B₂)))
cong {Related.equivalence} = ⇔-↠ ∘ Inverse.surjection
cong {Related.injection} = ↣ ∘ Inverse.injection
cong {Related.reverse-injection} {B₂ = B₂} = λ A₁↔A₂ B₁↢B₂ → lam (↣ (Inverse.injection (Inv.sym A₁↔A₂))
(app-↢ (swap-coercions B₂ A₁↔A₂ B₁↢B₂)))
cong {Related.left-inverse} = λ A₁↔A₂ → ↞ (Inverse.left-inverse A₁↔A₂) ∘ swap-coercions _ A₁↔A₂
cong {Related.surjection} = ↠ ∘ Inverse.surjection
cong {Related.bijection} = ↔
| 37.174497
| 117
| 0.512608
|
3d1d30277a8c99d6247376e8bb93479f0621c3b2
| 9,589
|
agda
|
Agda
|
src/LFRef/Properties/Soundness.agda
|
ajrouvoet/implicits.agda
|
ef2e347a4470e55083c83b743efbc2902ef1ad22
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/LFRef/Properties/Soundness.agda
|
ElessarWebb/implicits.agda
|
ef2e347a4470e55083c83b743efbc2902ef1ad22
|
[
"MIT"
] | null | null | null |
src/LFRef/Properties/Soundness.agda
|
ElessarWebb/implicits.agda
|
ef2e347a4470e55083c83b743efbc2902ef1ad22
|
[
"MIT"
] | null | null | null |
module LFRef.Properties.Soundness where
open import Data.Nat
open import Data.Sum
open import Data.Product as Pr
open import Data.List as List hiding (monad)
open import Data.Fin using (fromℕ≤; Fin)
open import Data.Vec hiding (_∷ʳ_; _>>=_)
open import Data.Star hiding (_>>=_)
open import Function
open import Extensions.List as L
open import Relation.Binary.PropositionalEquality as P
open import Relation.Binary.Core using (REL; Reflexive)
open import Relation.Binary.List.Pointwise as PRel hiding (refl)
open import LFRef.Syntax
open import LFRef.Welltyped
open import LFRef.Eval
open import LFRef.Properties.Decidable
progress : ∀ {𝕊 Σ A} {e : Exp 0} {μ} →
𝕊 , Σ ⊢ μ →
𝕊 , Σ , [] ⊢ₑ e ∶ A →
--------------------------------------
(ExpVal e) ⊎ (∃₂ λ e' μ' → (𝕊 ⊢ e , μ ≻ e' , μ'))
progress p (tm (con k ts _)) = inj₁ (tm con)
progress p (tm unit) = inj₁ (tm unit)
progress p (tm (var ()))
progress p (tm (loc x)) = inj₁ (tm loc)
progress p (fn ·★[ q ] ts) = inj₂ (, (, funapp-β fn (tele-fit-length ts)))
progress p (ref e) with progress p e
progress p (ref {_} {tm _} (tm _)) | inj₁ (tm v) = inj₂ (, (, ref-val v))
progress p (ref {_} {_ ·★ _} e) | inj₁ ()
progress p (ref {_} {ref x} e) | inj₁ ()
progress p (ref {_} { ! x } e) | inj₁ ()
progress p (ref {_} {x ≔ x₁} e) | inj₁ ()
progress p (ref e) | inj₂ (e' , μ' , step) = inj₂ (, (, ref-clos step))
progress p (!_ {x = x} e) with progress p e
progress p (!_ {_} {tm .(loc _)} (tm (loc x))) | inj₁ (tm _) =
inj₂ (, (, !-val (P.subst (_<_ _) (pointwise-length p) ([]=-length x))))
progress p (!_ {_} {tm (var ())} e) | _
progress p (!_ {_} {_ ·★ _} e) | inj₁ ()
progress p (!_ {_} {ref x} e) | inj₁ ()
progress p (!_ {_} { ! x } e) | inj₁ ()
progress p (!_ {_} {x ≔ x₁} e) | inj₁ ()
progress p (! e) | inj₂ (e' , μ' , step) = inj₂ (, (, !-clos step))
progress p (l ≔ e) with progress p l | progress p e
progress p (tm () ≔ e) | inj₁ (tm unit) | (inj₁ (tm x₁))
progress p (tm () ≔ e) | inj₁ (tm con) | (inj₁ (tm x₁))
progress p (tm (loc x) ≔ e) | inj₁ (tm loc) | (inj₁ (tm v)) =
inj₂ (, (, ≔-val (P.subst (_<_ _) (pointwise-length p) ([]=-length x)) v))
progress p (l ≔ e) | inj₂ (_ , _ , step) | _ = inj₂ (, (, ≔-clos₁ step))
progress p (l ≔ e) | inj₁ v | (inj₂ (_ , _ , step)) = inj₂ (, (, ≔-clos₂ v step))
progress-seq : ∀ {𝕊 Σ A} {e : SeqExp 0} {μ} →
𝕊 , Σ ⊢ μ →
𝕊 , Σ , [] ⊢ₛ e ∶ A →
--------------------------------------
SeqExpVal e ⊎ ∃₂ λ e' μ' → (𝕊 ⊢ e , μ ≻ₛ e' , μ')
progress-seq p (ret e) with progress p e
... | inj₁ (tm v) = inj₁ (ret-tm v)
... | inj₂ (e' , μ' , step) = inj₂ (, , ret-clos step)
progress-seq p (lett x e) with progress p x
progress-seq p (lett x e) | inj₁ (tm v) = inj₂ (, (, lett-β))
progress-seq p (lett x e) | inj₂ (x' , μ' , step) = inj₂ (, (, lett-clos step))
postulate
lem₂ : ∀ {n 𝕊 Σ e a b t} {Γ : Ctx n} →
𝕊 , Σ , (a :+: Γ) ⊢ₑ e ∶ weaken₁-tp b →
𝕊 , Σ , Γ ⊢ t ∶ a →
𝕊 , Σ , Γ ⊢ₑ (e exp/ (sub t)) ∶ b
lem₃ : ∀ {n 𝕊 Σ e a b t} {Γ : Ctx n} →
𝕊 , Σ , (a :+: Γ) ⊢ₛ e ∶ weaken₁-tp b →
𝕊 , Σ , Γ ⊢ t ∶ a →
𝕊 , Σ , Γ ⊢ₛ (e seq/ (sub t)) ∶ b
lem₁ : ∀ {n 𝕊 Σ φ ts} {Γ : Ctx n} →
𝕊 ⊢ φ fnOk →
(p : 𝕊 , Σ , Γ ⊢ ts ∶ⁿ weaken+-tele n (Fun.args φ)) →
(q : length ts ≡ (Fun.m φ)) →
𝕊 , Σ , Γ ⊢ₑ (!call (Fun.body φ) ts q) ∶ ((Fun.returntype φ) fun[ ts / q ])
-- loading from a welltyped store results in a welltyped term
!load-ok : ∀ {Σ Σ' A μ i 𝕊} →
-- store-welltypedness type (strengthened for induction)
Rel (λ A x → 𝕊 , Σ , [] ⊢ (proj₁ x) ∶ A) Σ' μ →
Σ' L.[ i ]= A → (l : i < length μ) →
𝕊 , Σ , [] ⊢ (!load μ l) ∶ A
!load-ok [] ()
!load-ok (x∼y ∷ p) here (s≤s z≤n) = x∼y
!load-ok (x∼y ∷ p) (there q) (s≤s l) = !load-ok p q l
mutual
⊒-preserves-tm : ∀ {n Γ Σ Σ' A 𝕊} {t : Term n} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ t ∶ A → 𝕊 , Σ' , Γ ⊢ t ∶ A
⊒-preserves-tm ext unit = unit
⊒-preserves-tm ext (var x) = var x
⊒-preserves-tm ext (con x p q) = con x (⊒-preserves-tele ext p) q
⊒-preserves-tm ext (loc x) = loc (xs⊒ys[i] x ext)
⊒-preserves-tele : ∀ {n m Γ Σ Σ' 𝕊} {ts : List (Term n)} {T : Tele n m} → Σ' ⊒ Σ →
𝕊 , Σ , Γ ⊢ ts ∶ⁿ T →
𝕊 , Σ' , Γ ⊢ ts ∶ⁿ T
⊒-preserves-tele ext ε = ε
⊒-preserves-tele ext (x ⟶ p) = ⊒-preserves-tm ext x ⟶ (⊒-preserves-tele ext p)
-- welltypedness is preseved under store extensions
⊒-preserves : ∀ {n Γ Σ Σ' A 𝕊} {e : Exp n} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ₑ e ∶ A → 𝕊 , Σ' , Γ ⊢ₑ e ∶ A
⊒-preserves ext (tm x) = tm (⊒-preserves-tm ext x)
⊒-preserves ext (x ·★[ refl ] p) with ⊒-preserves-tele ext p
... | p' = x ·★[ refl ] p'
⊒-preserves ext (ref p) = ref (⊒-preserves ext p)
⊒-preserves ext (! p) = ! (⊒-preserves ext p)
⊒-preserves ext (p ≔ q) = ⊒-preserves ext p ≔ ⊒-preserves ext q
⊒-preserves-seq : ∀ {n Γ Σ Σ' A 𝕊} {e : SeqExp n} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ₛ e ∶ A → 𝕊 , Σ' , Γ ⊢ₛ e ∶ A
⊒-preserves-seq ext (ret e) = ret (⊒-preserves ext e)
⊒-preserves-seq ext (lett e c) = lett (⊒-preserves ext e) (⊒-preserves-seq ext c)
-- helper for lifting preserving reductions into their closure
clos-cong : ∀ {Σ μ 𝕊 A B} {e : Exp 0} (c : Exp 0 → Exp 0) →
(f : ∀ {Σ'} (ext : Σ' ⊒ Σ) → 𝕊 , Σ' , [] ⊢ₑ e ∶ A → 𝕊 , Σ' , [] ⊢ₑ c e ∶ B) →
(∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₑ e ∶ A × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ) →
∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₑ c e ∶ B × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ
clos-cong _ f (Σ , wte , ext , μ-wt) = Σ , f ext wte , ext , μ-wt
≻-preserves : ∀ {𝕊 Σ A} {e : Exp 0} {e' μ' μ} →
𝕊 , [] ⊢ok →
𝕊 , Σ , [] ⊢ₑ e ∶ A →
𝕊 , Σ ⊢ μ →
𝕊 ⊢ e , μ ≻ e' , μ' →
----------------------------------------------------
∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₑ e' ∶ A × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ'
-- variables
≻-preserves ok (tm x) q ()
-- function application
≻-preserves {Σ = Σ} ok (fn ·★[ refl ] ts) q (funapp-β x refl) with
[]=-functional _ _ fn x | all-lookup fn (_,_⊢ok.funs-ok ok)
... | refl | fn-ok = Σ , (lem₁ fn-ok ts refl) , ⊑-refl , q
-- new references
≻-preserves {Σ = Σ} ok (ref {A = A} (tm x)) q (ref-val v) = let ext = (∷ʳ-⊒ A Σ) in
Σ ∷ʳ A ,
(tm (loc (P.subst (λ i → _ L.[ i ]= _) (pointwise-length q) (∷ʳ[length] Σ A)))) ,
ext ,
pointwise-∷ʳ (PRel.map (⊒-preserves-tm ext) q) (⊒-preserves-tm ext x)
≻-preserves ok (ref p) q (ref-clos step) =
clos-cong
ref (const ref)
(≻-preserves ok p q step)
-- dereferencing
≻-preserves {Σ = Σ₁} ok (! tm (loc x)) q (!-val p)
= Σ₁ , tm (!load-ok q x p) , ⊑-refl , q
≻-preserves ok (! p) q (!-clos step) =
clos-cong
!_ (const !_)
(≻-preserves ok p q step)
-- assignment
≻-preserves {Σ = Σ₁} ok (_≔_ (tm (loc x)) (tm y)) q (≔-val p v) =
Σ₁ , tm unit , ⊑-refl , pointwise-[]≔ q x p y
≻-preserves ok (p ≔ p₁) q (≔-clos₁ step) =
clos-cong
(λ p' → p' ≔ _) (λ ext p' → p' ≔ ⊒-preserves ext p₁)
(≻-preserves ok p q step)
≻-preserves ok (p ≔ p₁) q (≔-clos₂ v step) =
clos-cong
(λ p' → _ ≔ p') (λ ext p' → ⊒-preserves ext p ≔ p')
(≻-preserves ok p₁ q step)
-- let binding
≻ₛ-preserves : ∀ {𝕊 Σ A} {e : SeqExp 0} {e' μ' μ} →
𝕊 , [] ⊢ok →
𝕊 , Σ , [] ⊢ₛ e ∶ A →
𝕊 , Σ ⊢ μ →
𝕊 ⊢ e , μ ≻ₛ e' , μ' →
-------------------------------------------------------
∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₛ e' ∶ A × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ'
≻ₛ-preserves {Σ = Σ} ok (lett (tm x) p) q lett-β = Σ , lem₃ p x , ⊑-refl , q
≻ₛ-preserves ok (lett p p₁) q (lett-clos step) with ≻-preserves ok p q step
... | Σ₂ , wte' , Σ₂⊒Σ₁ , q' = Σ₂ , lett wte' ((⊒-preserves-seq Σ₂⊒Σ₁ p₁)) , Σ₂⊒Σ₁ , q'
≻ₛ-preserves ok (ret e) q (ret-clos step) with ≻-preserves ok e q step
... | Σ₂ , wte' , Σ₂⊒Σ₁ , q' = Σ₂ , ret wte' , Σ₂⊒Σ₁ , q'
module SafeEval where
open import Category.Monad.Partiality
open import Category.Monad
open import Coinduction
open import Level as Lev
open RawMonad {f = Lev.zero} monad
-- typesafe evaluation in the partiality/delay-monad;
-- or "soundness" modulo non-trivial divergence
eval : ∀ {𝕊 Σ a μ} {e : SeqExp 0} →
𝕊 , [] ⊢ok → -- given an ok signature context,
𝕊 , Σ , [] ⊢ₛ e ∶ a → -- a welltyped closed expression,
𝕊 , Σ ⊢ μ → -- and a welltyped store
---------------------------------------------------------------------------------------
-- eval will either diverge or provide evidence of a term v, store μ' and storetype Σ'
(∃ λ v → ∃ λ μ' → ∃ λ Σ' →
-- such that v is a value,
(SeqExpVal v) ×
-- ...there is a sequence of small steps from e to v
(𝕊 ⊢ e , μ ≻⋆ v , μ') ×
-- ...v has the same type as e
(𝕊 , Σ' , [] ⊢ₛ v ∶ a) ×
-- ...μ' is typed by Σ'
(𝕊 , Σ' ⊢ μ') ×
-- ...and finally, Σ' is an extension of Σ
(Σ' ⊒ Σ)) ⊥
eval 𝕊-ok wte μ-ok with progress-seq μ-ok wte
eval 𝕊-ok wte μ-ok | inj₁ v = now (_ , _ , _ , v , ε , wte , μ-ok , ⊑-refl)
eval 𝕊-ok wte μ-ok | inj₂ (e' , μ' , step) with ≻ₛ-preserves 𝕊-ok wte μ-ok step
... | (Σ' , wte' , ext₁ , μ'-ok) with later (♯ (eval 𝕊-ok wte' μ'-ok))
... | (now (v' , μ'' , Σ'' , val , steps , wte'' , μ''-ok , ext₂)) =
now (v' , (μ'' , (Σ'' , val , ((steps ▻ step) , (wte'' , μ''-ok , ⊑-trans ext₁ ext₂)))))
... | (later x) = later (♯ (♭ x >>=
λ{ (v' , μ'' , Σ'' , val , steps , wte'' , μ''-ok , ext₂) →
now (v' , μ'' , Σ'' , val , steps ▻ step , wte'' , μ''-ok , ⊑-trans ext₁ ext₂)
}))
| 40.631356
| 101
| 0.477735
|
d04f404e542244a215f564e981e3571ed953af1b
| 3,318
|
agda
|
Agda
|
src/Ints/Add/Assoc.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | 1
|
2020-04-15T15:28:03.000Z
|
2020-04-15T15:28:03.000Z
|
src/Ints/Add/Assoc.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | null | null | null |
src/Ints/Add/Assoc.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | null | null | null |
module Ints.Add.Assoc where
open import Ints
open import Nats renaming (suc to nsuc; _+_ to _:+:_)
open import Nats.Add.Assoc
open import Nats.Add.Comm
open import Ints.Add.Comm
open import Equality
open import Function
------------------------------------------------------------------------
-- internal stuffs
private
0+a=a : ∀ a → + 0 + a ≡ a
0+a=a (+ n ) = refl
0+a=a (-[1+ n ]) = refl
a+0=a : ∀ a → a + + 0 ≡ a
a+0=a a rewrite int-add-comm a (+ 0) | 0+a=a a = refl
z+/b+c/=/z+b/+c : ∀ b c → + 0 + (b + c) ≡ (+ 0 + b) + c
z+/b+c/=/z+b/+c (+ a ) (+ b ) = refl
z+/b+c/=/z+b/+c (-[1+ a ]) (-[1+ b ]) = refl
z+/b+c/=/z+b/+c (+ a ) (-[1+ b ])
rewrite 0+a=a (a ⊖ nsuc b) = refl
z+/b+c/=/z+b/+c (-[1+ a ]) (+ b )
rewrite 0+a=a (b ⊖ nsuc a) = refl
a+b=a--b : ∀ a b → a + b ≡ a - (- b)
a+b=a--b a (+ zero ) = refl
a+b=a--b a (+ nsuc n)
rewrite a+b=a--b a (+ n) = refl
a+b=a--b a (-[1+ n ]) = refl
a-b+c=a+c-b : ∀ a b c → a ⊖ b + + c ≡ a :+: c ⊖ b
a-b+c=a+c-b zero zero _ = refl
a-b+c=a+c-b zero (nsuc _) _ = refl
a-b+c=a+c-b (nsuc _) zero _ = refl
a-b+c=a+c-b (nsuc a) (nsuc b) c = a-b+c=a+c-b a b c
a+/b-c/=a+b-c : ∀ a b c → + a + (b ⊖ c) ≡ a :+: b ⊖ c
a+/b-c/=a+b-c a b c
rewrite int-add-comm (+ a) $ b ⊖ c
| a-b+c=a+c-b b c a
| nat-add-comm a b
= refl
b-c-a=b-/c+a/ : ∀ a b c → b ⊖ c + -[1+ a ] ≡ b ⊖ (nsuc c :+: a)
b-c-a=b-/c+a/ _ zero zero = refl
b-c-a=b-/c+a/ _ zero (nsuc _) = refl
b-c-a=b-/c+a/ _ (nsuc _) zero = refl
b-c-a=b-/c+a/ a (nsuc b) (nsuc c) = b-c-a=b-/c+a/ a b c
-a+/b-c/=b-/a+c/ : ∀ a b c → -[1+ a ] + (b ⊖ c) ≡ b ⊖ (nsuc a :+: c)
-a+/b-c/=b-/a+c/ a b c
rewrite int-add-comm -[1+ a ] $ b ⊖ c
| b-c-a=b-/c+a/ a b c
| nat-add-comm a c
= refl
a+/b+c/=/a+b/+c : ∀ a b c → a + (b + c) ≡ a + b + c
a+/b+c/=/a+b/+c (+ zero) b c rewrite 0+a=a (b + c) | 0+a=a b = refl
a+/b+c/=/a+b/+c a (+ zero) c rewrite 0+a=a c | a+0=a a = refl
a+/b+c/=/a+b/+c a b (+ zero) rewrite a+0=a b | a+0=a (a + b) = refl
a+/b+c/=/a+b/+c (+ a) (+ b) (+ c)
rewrite nat-add-assoc a b c = refl
a+/b+c/=/a+b/+c -[1+ a ] -[1+ b ] (+ nsuc c)
rewrite -a+/b-c/=b-/a+c/ a c b = refl
a+/b+c/=/a+b/+c -[1+ a ] (+ nsuc b) -[1+ c ]
rewrite -a+/b-c/=b-/a+c/ a b c
| b-c-a=b-/c+a/ c b a
= refl
a+/b+c/=/a+b/+c (+ nsuc a) -[1+ b ] -[1+ c ]
rewrite b-c-a=b-/c+a/ c a b = refl
a+/b+c/=/a+b/+c (+ nsuc a) -[1+ b ] (+ nsuc c)
rewrite a-b+c=a+c-b a b $ nsuc c
| a+/b-c/=a+b-c (nsuc a) c b
| sym $ nat-add-assoc a 1 c
| nat-add-comm a 1
= refl
a+/b+c/=/a+b/+c -[1+ a ] (+ nsuc b) (+ nsuc c)
rewrite a-b+c=a+c-b b a (nsuc c) = refl
a+/b+c/=/a+b/+c -[1+ a ] -[1+ b ] -[1+ c ]
rewrite nat-add-comm a $ nsuc $ b :+: c
| nat-add-comm (b :+: c) a
| nat-add-assoc a b c
= refl
a+/b+c/=/a+b/+c (+ nsuc a) (+ nsuc b) -[1+ c ]
rewrite a+/b-c/=a+b-c (nsuc a) b c
| sym $ nat-add-assoc a 1 b
| nat-add-comm a 1
= refl
------------------------------------------------------------------------
-- public aliases
int-add-assoc : ∀ a b c → a + (b + c) ≡ a + b + c
int-add-assoc = a+/b+c/=/a+b/+c
| 31.903846
| 72
| 0.402954
|
1e6f9021050f6c43f707e07aa9114e849856d993
| 383
|
agda
|
Agda
|
examples/compiler/Not-named-according-to-the-Haskell-lexical-syntax.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/compiler/Not-named-according-to-the-Haskell-lexical-syntax.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/compiler/Not-named-according-to-the-Haskell-lexical-syntax.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Not-named-according-to-the-Haskell-lexical-syntax where
postulate
IO : Set -> Set
{-# BUILTIN IO IO #-}
{-# COMPILED_TYPE IO IO #-}
postulate
return : {A : Set} -> A -> IO A
{-# COMPILED return (\_ -> return :: a -> IO a) #-}
{-# COMPILED_EPIC return (u1 : Unit, a : Any) -> Any = ioreturn(a) #-}
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
| 20.157895
| 70
| 0.5953
|
4d72638be9b30d7965c760a3f667b9d4ac0a2277
| 8,132
|
agda
|
Agda
|
Cubical/HITs/SetTruncation/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetTruncation/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetTruncation/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Properties of set truncations
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetTruncation.Properties where
open import Cubical.HITs.SetTruncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
renaming (rec to pRec ; elim to pElim) hiding (elim2 ; elim3 ; rec2 ; map)
private
variable
ℓ ℓ' : Level
A B C D : Type ℓ
rec : isSet B → (A → B) → ∥ A ∥₂ → B
rec Bset f ∣ x ∣₂ = f x
rec Bset f (squash₂ x y p q i j) =
Bset _ _ (cong (rec Bset f) p) (cong (rec Bset f) q) i j
rec2 : isSet C → (A → B → C) → ∥ A ∥₂ → ∥ B ∥₂ → C
rec2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y
rec2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) =
Cset _ _ (cong (rec2 Cset f ∣ x ∣₂) p) (cong (rec2 Cset f ∣ x ∣₂) q) i j
rec2 Cset f (squash₂ x y p q i j) z =
Cset _ _ (cong (λ a → rec2 Cset f a z) p) (cong (λ a → rec2 Cset f a z) q) i j
-- Old version:
-- rec2 Cset f = rec (isSetΠ λ _ → Cset) λ x → rec Cset (f x)
-- lemma 6.9.1 in HoTT book
elim : {B : ∥ A ∥₂ → Type ℓ}
(Bset : (x : ∥ A ∥₂) → isSet (B x))
(f : (a : A) → B (∣ a ∣₂))
(x : ∥ A ∥₂) → B x
elim Bset f ∣ a ∣₂ = f a
elim Bset f (squash₂ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset _ _
(cong (elim Bset f) p) (cong (elim Bset f) q) (squash₂ x y p q) i j
elim2 : {C : ∥ A ∥₂ → ∥ B ∥₂ → Type ℓ}
(Cset : ((x : ∥ A ∥₂) (y : ∥ B ∥₂) → isSet (C x y)))
(f : (a : A) (b : B) → C ∣ a ∣₂ ∣ b ∣₂)
(x : ∥ A ∥₂) (y : ∥ B ∥₂) → C x y
elim2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y
elim2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) =
isOfHLevel→isOfHLevelDep 2 (λ a → Cset ∣ x ∣₂ a) _ _
(cong (elim2 Cset f ∣ x ∣₂) p) (cong (elim2 Cset f ∣ x ∣₂) q) (squash₂ y z p q) i j
elim2 Cset f (squash₂ x y p q i j) z =
isOfHLevel→isOfHLevelDep 2 (λ a → Cset a z) _ _
(cong (λ a → elim2 Cset f a z) p) (cong (λ a → elim2 Cset f a z) q) (squash₂ x y p q) i j
-- Old version:
-- elim2 Cset f = elim (λ _ → isSetΠ (λ _ → Cset _ _))
-- (λ a → elim (λ _ → Cset _ _) (f a))
-- TODO: generalize
elim3 : {B : (x y z : ∥ A ∥₂) → Type ℓ}
(Bset : ((x y z : ∥ A ∥₂) → isSet (B x y z)))
(g : (a b c : A) → B ∣ a ∣₂ ∣ b ∣₂ ∣ c ∣₂)
(x y z : ∥ A ∥₂) → B x y z
elim3 Bset g = elim2 (λ _ _ → isSetΠ (λ _ → Bset _ _ _))
(λ a b → elim (λ _ → Bset _ _ _) (g a b))
map : (A → B) → ∥ A ∥₂ → ∥ B ∥₂
map f = rec squash₂ λ x → ∣ f x ∣₂
setTruncUniversal : isSet B → (∥ A ∥₂ → B) ≃ (A → B)
setTruncUniversal {B = B} Bset =
isoToEquiv (iso (λ h x → h ∣ x ∣₂) (rec Bset) (λ _ → refl) rinv)
where
rinv : (f : ∥ A ∥₂ → B) → rec Bset (λ x → f ∣ x ∣₂) ≡ f
rinv f i x =
elim (λ x → isProp→isSet (Bset (rec Bset (λ x → f ∣ x ∣₂) x) (f x)))
(λ _ → refl) x i
setTruncIsSet : isSet ∥ A ∥₂
setTruncIsSet a b p q = squash₂ a b p q
setTruncIdempotentIso : isSet A → Iso ∥ A ∥₂ A
Iso.fun (setTruncIdempotentIso hA) = rec hA (idfun _)
Iso.inv (setTruncIdempotentIso hA) x = ∣ x ∣₂
Iso.rightInv (setTruncIdempotentIso hA) _ = refl
Iso.leftInv (setTruncIdempotentIso hA) = elim (λ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ → refl)
setTruncIdempotent≃ : isSet A → ∥ A ∥₂ ≃ A
setTruncIdempotent≃ {A = A} hA = isoToEquiv (setTruncIdempotentIso hA)
setTruncIdempotent : isSet A → ∥ A ∥₂ ≡ A
setTruncIdempotent hA = ua (setTruncIdempotent≃ hA)
isContr→isContrSetTrunc : isContr A → isContr (∥ A ∥₂)
isContr→isContrSetTrunc contr = ∣ fst contr ∣₂
, elim (λ _ → isOfHLevelPath 2 (setTruncIsSet) _ _)
λ a → cong ∣_∣₂ (snd contr a)
setTruncIso : Iso A B → Iso ∥ A ∥₂ ∥ B ∥₂
Iso.fun (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.fun is x ∣₂)
Iso.inv (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.inv is x ∣₂)
Iso.rightInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.rightInv is a)
Iso.leftInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.leftInv is a)
setSigmaIso : {B : A → Type ℓ} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
setSigmaIso {A = A} {B = B} = iso fun funinv sect retr
where
{- writing it out explicitly to avoid yellow highlighting -}
fun : ∥ Σ A B ∥₂ → ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
fun = rec setTruncIsSet λ {(a , p) → ∣ a , ∣ p ∣₂ ∣₂}
funinv : ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ → ∥ Σ A B ∥₂
funinv = rec setTruncIsSet (λ {(a , p) → rec setTruncIsSet (λ p → ∣ a , p ∣₂) p})
sect : section fun funinv
sect = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { (a , p) → elim {B = λ p → fun (funinv ∣ a , p ∣₂) ≡ ∣ a , p ∣₂}
(λ p → isOfHLevelPath 2 setTruncIsSet _ _) (λ _ → refl) p }
retr : retract fun funinv
retr = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { _ → refl }
sigmaElim : {B : ∥ A ∥₂ → Type ℓ} {C : Σ ∥ A ∥₂ B → Type ℓ'}
(Bset : (x : Σ ∥ A ∥₂ B) → isSet (C x))
(g : (a : A) (b : B ∣ a ∣₂) → C (∣ a ∣₂ , b))
(x : Σ ∥ A ∥₂ B) → C x
sigmaElim {B = B} {C = C} set g (x , y) =
elim {B = λ x → (y : B x) → C (x , y)} (λ _ → isSetΠ λ _ → set _) g x y
sigmaProdElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} {D : Σ (∥ A ∥₂ × ∥ B ∥₂) C → Type ℓ'}
(Bset : (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → isSet (D x))
(g : (a : A) (b : B) (c : C (∣ a ∣₂ , ∣ b ∣₂)) → D ((∣ a ∣₂ , ∣ b ∣₂) , c))
(x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → D x
sigmaProdElim {B = B} {C = C} {D = D} set g ((x , y) , c) =
elim {B = λ x → (y : ∥ B ∥₂) (c : C (x , y)) → D ((x , y) , c)}
(λ _ → isSetΠ λ _ → isSetΠ λ _ → set _)
(λ x → elim (λ _ → isSetΠ λ _ → set _) (g x))
x y c
prodElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) → isSet (C x))
→ ((a : A) (b : B) → C (∣ a ∣₂ , ∣ b ∣₂))
→ (x : ∥ A ∥₂ × ∥ B ∥₂) → C x
prodElim setC f (a , b) = elim2 (λ x y → setC (x , y)) f a b
prodRec : {C : Type ℓ} → isSet C → (A → B → C) → ∥ A ∥₂ × ∥ B ∥₂ → C
prodRec setC f (a , b) = rec2 setC f a b
prodElim2 : {E : (∥ A ∥₂ × ∥ B ∥₂) → (∥ C ∥₂ × ∥ D ∥₂) → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → isSet (E x y))
→ ((a : A) (b : B) (c : C) (d : D) → E (∣ a ∣₂ , ∣ b ∣₂) (∣ c ∣₂ , ∣ d ∣₂))
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → (E x y))
prodElim2 isset f = prodElim (λ _ → isSetΠ λ _ → isset _ _)
λ a b → prodElim (λ _ → isset _ _)
λ c d → f a b c d
setTruncOfProdIso : Iso ∥ A × B ∥₂ (∥ A ∥₂ × ∥ B ∥₂)
Iso.fun setTruncOfProdIso = rec (isSet× setTruncIsSet setTruncIsSet) λ { (a , b) → ∣ a ∣₂ , ∣ b ∣₂ }
Iso.inv setTruncOfProdIso = prodRec setTruncIsSet λ a b → ∣ a , b ∣₂
Iso.rightInv setTruncOfProdIso =
prodElim (λ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl
Iso.leftInv setTruncOfProdIso =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(a , b) → refl}
IsoSetTruncateSndΣ : {A : Type ℓ} {B : A → Type ℓ'} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
Iso.fun IsoSetTruncateSndΣ = map λ a → (fst a) , ∣ snd a ∣₂
Iso.inv IsoSetTruncateSndΣ = rec setTruncIsSet (uncurry λ x → map λ b → x , b)
Iso.rightInv IsoSetTruncateSndΣ =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(uncurry λ a → elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ _ → refl)
Iso.leftInv IsoSetTruncateSndΣ =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ _ → refl
PathIdTrunc₀Iso : {a b : A} → Iso (∣ a ∣₂ ≡ ∣ b ∣₂) ∥ a ≡ b ∥
Iso.fun (PathIdTrunc₀Iso {b = b}) p =
transport (λ i → rec {B = TypeOfHLevel _ 1} (isOfHLevelTypeOfHLevel 1)
(λ a → ∥ a ≡ b ∥ , squash) (p (~ i)) .fst)
∣ refl ∣
Iso.inv PathIdTrunc₀Iso = pRec (squash₂ _ _) (cong ∣_∣₂)
Iso.rightInv PathIdTrunc₀Iso _ = squash _ _
Iso.leftInv PathIdTrunc₀Iso _ = squash₂ _ _ _ _
| 41.070707
| 101
| 0.526685
|
0489ce1a17fc9fccdcaea5560f1fc707293baee9
| 652
|
agda
|
Agda
|
test/Test/Compile/Golden/increasing/increasing-output.agda
|
vehicle-lang/vehicle
|
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
|
[
"BSD-3-Clause"
] | 9
|
2022-02-10T12:56:42.000Z
|
2022-02-17T18:51:05.000Z
|
test/Test/Compile/Golden/increasing/increasing-output.agda
|
vehicle-lang/vehicle
|
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
|
[
"BSD-3-Clause"
] | 19
|
2022-03-07T14:09:13.000Z
|
2022-03-31T20:49:39.000Z
|
test/Test/Compile/Golden/increasing/increasing-output.agda
|
vehicle-lang/vehicle
|
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
|
[
"BSD-3-Clause"
] | null | null | null |
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
{-# OPTIONS --allow-exec #-}
open import Vehicle
open import Vehicle.Data.Tensor
open import Data.Rational as ℚ using (ℚ)
open import Data.Fin as Fin using (Fin; #_)
open import Data.List
module increasing-temp-output where
postulate f : Tensor ℚ (1 ∷ []) → Tensor ℚ (1 ∷ [])
abstract
increasing : ∀ (x : ℚ) → x ℚ.≤ f (x ∷ []) (# 0)
increasing = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
| 27.166667
| 71
| 0.670245
|
2227b59f72f7b8cda7a5d826fcee2a3d30bd3d68
| 232
|
agda
|
Agda
|
examples/Termination/Common/Coinduction.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/Termination/Common/Coinduction.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/Termination/Common/Coinduction.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Common.Coinduction where
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
| 19.333333
| 34
| 0.443966
|
c727eb2b2cd9f7d6821989ca97ce06f484f8dd6e
| 668
|
agda
|
Agda
|
test/Fail/Issue4560NoPatternMatchingWithoutEta.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2021-06-14T11:08:59.000Z
|
2021-06-14T11:08:59.000Z
|
test/Fail/Issue4560NoPatternMatchingWithoutEta.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2020-05-29T19:45:38.000Z
|
2020-05-29T19:45:38.000Z
|
test/Fail/Issue4560NoPatternMatchingWithoutEta.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2021-06-14T11:07:38.000Z
|
2021-06-14T11:07:38.000Z
|
-- Andreas, 2020-04-19, issue #4560, raised by Andrea
-- Having both matching on constructor and copattern matching
-- for non-eta records leads to loss of subject reduction.
open import Agda.Builtin.Equality
postulate
A : Set
a : A
record R : Set where
constructor con
no-eta-equality
field
X Y : A
foo : R → A
foo (con x y) = x
-- Expected error here:
-- Pattern matching on no-eta record types is by default not allowed
-- when checking that the pattern con x y has type R
bar : R
bar .R.X = a
bar .R.Y = a
test : foo bar ≡ a
test = refl
-- Problem was:
-- foo bar != a of type A
-- when checking that the expression refl has type foo bar ≡ a
| 19.647059
| 68
| 0.685629
|
59f856e1bc7d3033edb89817d3fd6ac3a2e863b0
| 3,989
|
agda
|
Agda
|
part1/relations/Relations.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | 1
|
2020-07-07T09:42:22.000Z
|
2020-07-07T09:42:22.000Z
|
part1/relations/Relations.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
part1/relations/Relations.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
module Relations where
-- Imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm)
-- Defining relations
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ}
--------
→ zero ≤ n
s≤s : ∀ {m n : ℕ}
→ m ≤ n
-------------
→ suc m ≤ suc n
_ : 2 ≤ 4
_ = s≤s (s≤s z≤n)
-- Implicit arguments
_ : 2 ≤ 4
_ = s≤s {1} {3} (s≤s {0} {2} (z≤n {2}))
_ : 2 ≤ 4
_ = s≤s {m = 1} {n = 3} (s≤s {m = 0} {n = 2} (z≤n {n = 2}))
_ : 2 ≤ 4
_ = s≤s {n = 3} (s≤s {n = 2} z≤n)
-- Precedence
infix 4 _≤_
-- Inversion
inv-s≤s : ∀ {m n : ℕ}
→ suc m ≤ suc n
-------------
→ m ≤ n
inv-s≤s (s≤s m≤n) = m≤n
inv-z≤n : ∀ {m : ℕ}
→ m ≤ zero
--------
→ m ≡ zero
inv-z≤n z≤n = refl
-- Reflexivity (反射律)
≤-refl : ∀ {n : ℕ}
-----
→ n ≤ n
≤-refl {zero} = z≤n
≤-refl {suc n} = s≤s ≤-refl
-- Transitivity (推移律)
≤-trans : ∀ {m n p : ℕ}
→ m ≤ n
→ n ≤ p
-----
→ m ≤ p
≤-trans z≤n _ = z≤n
≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p)
≤-trans′ : ∀ (m n p : ℕ)
→ m ≤ n
→ n ≤ p
-----
→ m ≤ p
≤-trans′ zero _ _ z≤n _ = z≤n
≤-trans′ (suc m) (suc n) (suc p) (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans′ m n p m≤n n≤p)
-- Anti-symmetry (非対称律)
≤-antisym : ∀ {m n : ℕ}
→ m ≤ n
→ n ≤ m
-----
→ m ≡ n
≤-antisym z≤n z≤n = refl
≤-antisym (s≤s m≤n) (s≤s n≤m) = cong suc (≤-antisym m≤n n≤m)
-- Total (全順序)
data Total (m n : ℕ) : Set where
forward :
m ≤ n
---------
→ Total m n
flipped :
n ≤ m
---------
→ Total m n
data Total′ : ℕ → ℕ → Set where
forward′ : ∀ {m n : ℕ}
→ m ≤ n
----------
→ Total′ m n
flipped′ : ∀ {m n : ℕ}
→ n ≤ m
----------
→ Total′ m n
≤-total : ∀ (m n : ℕ) → Total m n
≤-total zero n = forward z≤n
≤-total (suc m) zero = flipped z≤n
≤-total (suc m) (suc n) with ≤-total m n
... | forward m≤n = forward (s≤s m≤n)
... | flipped n≤m = flipped (s≤s n≤m)
≤-total′ : ∀ (m n : ℕ) → Total m n
≤-total′ zero n = forward z≤n
≤-total′ (suc m) zero = flipped z≤n
≤-total′ (suc m) (suc n) = helper (≤-total′ m n)
where
helper : Total m n → Total (suc m) (suc n)
helper (forward m≤n) = forward (s≤s m≤n)
helper (flipped n≤m) = flipped (s≤s n≤m)
≤-total″ : ∀ (m n : ℕ) → Total m n
≤-total″ m zero = flipped z≤n
≤-total″ zero (suc n) = forward z≤n
≤-total″ (suc m) (suc n) with ≤-total″ m n
... | forward m≤n = forward (s≤s m≤n)
... | flipped n≤m = flipped (s≤s n≤m)
-- Monotonicity (単調性)
+-monoʳ-≤ : ∀ (n p q : ℕ)
→ p ≤ q
-------------
→ n + p ≤ n + q
+-monoʳ-≤ zero p q p≤q = p≤q
+-monoʳ-≤ (suc n) p q p≤q = s≤s (+-monoʳ-≤ n p q p≤q)
+-monoˡ-≤ : ∀ (m n p : ℕ)
→ m ≤ n
-------------
→ m + p ≤ n + p
+-monoˡ-≤ m n p m≤n rewrite +-comm m p | +-comm n p = +-monoʳ-≤ p m n m≤n
+-mono-≤ : ∀ (m n p q : ℕ)
→ m ≤ n
→ p ≤ q
-------------
→ m + p ≤ n + q
+-mono-≤ m n p q m≤n p≤q = ≤-trans (+-monoˡ-≤ m n p m≤n) (+-monoʳ-≤ n p q p≤q)
-- Strict inequality
infix 4 _<_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ}
------------
→ zero < suc n
s<s : ∀ {m n : ℕ}
→ m < n
-------------
→ suc m < suc n
-- Even and odd
data even : ℕ → Set
data odd : ℕ → Set
data even where
zero :
---------
even zero
suc : ∀ {n : ℕ}
→ odd n
------------
→ even (suc n)
data odd where
suc : ∀ {n : ℕ}
→ even n
-----------
→ odd (suc n)
e+e≡e : ∀ {m n : ℕ}
→ even m
→ even n
------------
→ even (m + n)
o+e≡o : ∀ {m n : ℕ}
→ odd m
→ even n
-----------
→ odd (m + n)
e+e≡e zero en = en
e+e≡e (suc om) en = suc (o+e≡o om en)
o+e≡o (suc em) en = suc (e+e≡e em en)
| 18.467593
| 83
| 0.401604
|
133546f0b464fc86c5aa69069e83402e1d71fbce
| 1,159
|
agda
|
Agda
|
Cats/Category/Product/Binary/Facts.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Product/Binary/Facts.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Product/Binary/Facts.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
module Cats.Category.Product.Binary.Facts where
open import Cats.Category
open import Cats.Category.Product.Binary using (_×_)
open import Cats.Functor
open import Cats.Util.Logic.Constructive using (_∧_ ; _,_ ; ∧-eliml ; ∧-elimr)
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈}
{D : Category lo′ la′ l≈′}
where
private
module C = Category C
module D = Category D
module × = Category (C × D)
open Category._≅_
iso-intro : ∀ {A A′ B B′} → A C.≅ A′ → B D.≅ B′ → (A , B) ×.≅ (A′ , B′)
iso-intro f g = record
{ forth = forth f , forth g
; back = back f , back g
; back-forth = back-forth f , back-forth g
; forth-back = forth-back f , forth-back g
}
iso-elim : ∀ {A A′ B B′} → (A , B) ×.≅ (A′ , B′) → A C.≅ A′ ∧ B D.≅ B′
iso-elim f
= record
{ forth = ∧-eliml (forth f)
; back = ∧-eliml (back f)
; back-forth = ∧-eliml (back-forth f)
; forth-back = ∧-eliml (forth-back f)
}
, record
{ forth = ∧-elimr (forth f)
; back = ∧-elimr (back f)
; back-forth = ∧-elimr (back-forth f)
; forth-back = ∧-elimr (forth-back f)
}
| 25.755556
| 78
| 0.537532
|
38f604ab7d0ba1cc0e838725fef293b5ae10dbfc
| 1,059
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/RingExpression.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/RingSolver/RingExpression.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/RingSolver/RingExpression.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.RingExpression where
open import Cubical.Foundations.Prelude
open import Cubical.Data.FinData
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Nat.Order using (zero-≤)
open import Cubical.Data.Vec.Base
open import Cubical.Algebra.RingSolver.AlmostRing
open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
private
variable
ℓ : Level
infixl 6 _⊕_
infixl 7 _⊗_
-- Expression in a ring on A with n variables
data Expr {ℓ} (A : Type ℓ) (n : ℕ) : Type ℓ where
K : A → Expr A n
∣ : Fin n → Expr A n
_⊕_ : Expr A n → Expr A n → Expr A n
_⊗_ : Expr A n → Expr A n → Expr A n
-- _⊛_ : Expr A n → ℕ → Expr A n -- exponentiation
⊝_ : Expr A n → Expr A n
module Eval (R : RawRing ℓ) where
open import Cubical.Data.Vec
open RawRing R
⟦_⟧ : ∀ {n} → Expr ⟨ R ⟩ᵣ n → Vec ⟨ R ⟩ᵣ n → ⟨ R ⟩ᵣ
⟦ K r ⟧ v = r
⟦ ∣ k ⟧ v = lookup k v
⟦ x ⊕ y ⟧ v = ⟦ x ⟧ v + ⟦ y ⟧ v
⟦ x ⊗ y ⟧ v = ⟦ x ⟧ v · ⟦ y ⟧ v
-- ⟦ x ⊛ l ⟧ v = ⟦ x ⟧ v ^ l
⟦ ⊝ x ⟧ v = - ⟦ x ⟧ v
| 26.475
| 69
| 0.596789
|
9a17abcfd5bf3cea918f82344a52fb04ff9b0266
| 1,626
|
agda
|
Agda
|
notes/FOT/FOL/ImplicitArgumentSubst.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOL/ImplicitArgumentSubst.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOL/ImplicitArgumentSubst.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Testing subst using an implicit arguments for the propositional function.
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOL.ImplicitArgumentSubst where
infix 7 _≡_
postulate
D : Set
_·_ : D → D → D
zero succ pred : D
succ₁ : D → D
succ₁ n = succ · n
pred₁ : D → D
pred₁ n = pred · n
-- The identity type on the universe of discourse.
data _≡_ (x : D) : D → Set where
refl : x ≡ x
-- The propositional function is not an implicit argument.
subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y
subst A refl Ax = Ax
-- The propositional formula is an implicit argument.
subst' : {A : D → Set} → ∀ {x y} → x ≡ y → A x → A y
subst' refl Ax = Ax
sym : ∀ {x y} → x ≡ y → y ≡ x
sym refl = refl
-- Conversion rules.
postulate
pred-0 : pred₁ zero ≡ zero
pred-S : ∀ n → pred₁ (succ₁ n) ≡ n
-- The FOTC natural numbers type.
data N : D → Set where
nzero : N zero
nsucc : ∀ {n} → N n → N (succ₁ n)
-- Works using subst.
pred-N : ∀ {n} → N n → N (pred₁ n)
pred-N nzero = subst N (sym pred-0) nzero
pred-N (nsucc {n} Nn) = subst N (sym (pred-S n)) Nn
-- Fails using subst'.
pred-N' : ∀ {n} → N n → N (pred₁ n)
pred-N' nzero = subst' (sym pred-0) nzero
pred-N' (nsucc {n} Nn) = subst' (sym (pred-S n)) Nn
| 27.1
| 78
| 0.501845
|
50b9bc1e3f5ffabd84a8a13fa6488df405957022
| 3,170
|
agda
|
Agda
|
theorems/homotopy/SuspAdjointLoop.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/homotopy/SuspAdjointLoop.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/homotopy/SuspAdjointLoop.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.PtdAdjoint
module homotopy.SuspAdjointLoop where
module Σ⊣Ω {i} where
SuspFunctor : PtdFunctor i i
SuspFunctor = record {
obj = ⊙Susp;
arr = ⊙susp-fmap;
id = ⊙susp-fmap-idf;
comp = ⊙susp-fmap-∘}
LoopFunctor : PtdFunctor i i
LoopFunctor = record {
obj = ⊙Ω;
arr = ⊙ap;
id = λ _ → ⊙ap-idf;
comp = ⊙ap-∘}
module _ (X : Ptd i) where
η : fst X → Ω (⊙Susp X)
η x = merid x ∙ ! (merid (snd X))
module E = SuspensionRec (snd X) (snd X) (idf _)
ε : fst (⊙Susp (⊙Ω X)) → fst X
ε = E.f
⊙η : fst (X ⊙→ ⊙Ω (⊙Susp X))
⊙η = (η , !-inv-r (merid (snd X)))
⊙ε : fst (⊙Susp (⊙Ω X) ⊙→ X)
⊙ε = (ε , idp)
η-natural : {X Y : Ptd i} (f : fst (X ⊙→ Y))
→ ⊙η Y ⊙∘ f == ⊙ap (⊙susp-fmap f) ⊙∘ ⊙η X
η-natural {X = X} (f , idp) = ⊙λ=
(λ x → ! $
ap-∙ (susp-fmap f) (merid x) (! (merid (snd X)))
∙ SuspFmap.merid-β f x
∙2 (ap-! (susp-fmap f) (merid (snd X))
∙ ap ! (SuspFmap.merid-β f (snd X))))
(pt-lemma (susp-fmap f) (merid (snd X)) (SuspFmap.merid-β f (snd X)))
where
pt-lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y : A} (p : x == y) {q : f x == f y} (α : ap f p == q)
→ !-inv-r q == (! $ ap-∙ f p (! p) ∙ α ∙2 (ap-! f p ∙ ap ! α))
∙ ap (ap f) (!-inv-r p) ∙ idp
pt-lemma f idp idp = idp
ε-natural : {X Y : Ptd i} (f : fst (X ⊙→ Y))
→ ⊙ε Y ⊙∘ ⊙susp-fmap (⊙ap f) == f ⊙∘ ⊙ε X
ε-natural (f , idp) = ⊙λ=
(SuspensionElim.f idp idp
(λ p → ↓-='-from-square $ vert-degen-square $
ap-∘ (ε _) (susp-fmap (ap f)) (merid p)
∙ ap (ap (ε _)) (SuspFmap.merid-β (ap f) p)
∙ E.merid-β _ (ap f p)
∙ ap (ap f) (! (E.merid-β _ p))
∙ ∘-ap f (ε _) (merid p)))
idp
εΣ-Ση : (X : Ptd i) → ⊙ε (⊙Susp X) ⊙∘ ⊙susp-fmap (⊙η X) == ⊙idf _
εΣ-Ση X = ⊙λ=
(SuspensionElim.f
idp
(merid (snd X))
(λ x → ↓-='-from-square $
(ap-∘ (ε (⊙Susp X)) (susp-fmap (η X)) (merid x)
∙ ap (ap (ε (⊙Susp X))) (SuspFmap.merid-β (η X) x)
∙ E.merid-β _ (merid x ∙ ! (merid (snd X))))
∙v⊡ square-lemma (merid x) (merid (snd X))
⊡v∙ ! (ap-idf (merid x))))
idp
where
square-lemma : ∀ {i} {A : Type i} {x y z : A}
(p : x == y) (q : z == y)
→ Square idp (p ∙ ! q) p q
square-lemma idp idp = ids
Ωε-ηΩ : (X : Ptd i) → ⊙ap (⊙ε X) ⊙∘ ⊙η (⊙Ω X) == ⊙idf _
Ωε-ηΩ X = ⊙λ=
(λ p → ap-∙ (ε X) (merid p) (! (merid idp))
∙ (E.merid-β X p ∙2 (ap-! (ε X) (merid idp) ∙ ap ! (E.merid-β X idp)))
∙ ∙-unit-r _)
(pt-lemma (ε X) (merid idp) (E.merid-β X idp))
where
pt-lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y : A} (p : x == y) {q : f x == f y} (α : ap f p == q)
→ ap (ap f) (!-inv-r p) ∙ idp
== (ap-∙ f p (! p) ∙ (α ∙2 (ap-! f p ∙ ap ! α)) ∙ !-inv-r q) ∙ idp
pt-lemma f idp idp = idp
adj : CounitUnitAdjoint SuspFunctor LoopFunctor
adj = record {
η = ⊙η;
ε = ⊙ε;
η-natural = η-natural;
ε-natural = ε-natural;
εF-Fη = εΣ-Ση;
Gε-ηG = Ωε-ηΩ}
| 28.818182
| 79
| 0.447319
|
5736d95f43f65573fe9d462d79613e7022c07a96
| 3,104
|
agda
|
Agda
|
agda-stdlib/README/Data/Interleaving.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/README/Data/Interleaving.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/README/Data/Interleaving.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Examples showing how the notion of Interleaving can be used
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module README.Data.Interleaving where
open import Level
open import Data.List.Base hiding (filter)
open import Data.List.Relation.Unary.All
open import Function
open import Relation.Nullary
open import Relation.Unary
-- In its most general form, `Interleaving` is parametrised by two relations
-- `L` (for Left) and `R` (for Right). Given three lists, `xs`, `ys` and `zs`,
-- a proof of `Interleaving xs ys zs` is essentially a diagram explaining how
-- `zs` can be pulled apart into `xs` and `ys` in a way compatible with `L`
-- and `R`. For instance:
-- xs zs ys
--
-- x₁ -- L x₁ z₁ -- z₁
-- x₂ -- L x₂ z₂ -- z₂
-- z₃ -- R z₃ z₁ -- y₁
-- x₃ -- L x₃ z₄ -- z₄
-- z₅ -- R z₅ y₂ -- y₂
open import Data.List.Relation.Ternary.Interleaving.Propositional
-- The special case we will focus on here is the propositional case: both
-- `L` and ̀R` are propositional equality. Rethinking our previous example,
-- this gives us the proof that [z₁, ⋯, z₅] can be partitioned into
-- [z₁, z₂, z₄] on the one hand and [z₃, z₅] in the other.
-- One possible use case for such a relation is the definition of a very
-- precise filter function. Provided a decidable predicate `P`, it will
-- prove not only that the retained values satisfy `P` but that the ones
-- that didn't make the cut satisfy the negation of P.
-- We can make this formal by defining the following record type:
infix 3 _≡_⊎_
record Filter {a p} {A : Set a} (P : Pred A p) (xs : List A) : Set (a ⊔ p) where
constructor _≡_⊎_
field
-- The result of running filter is two lists:
-- * the elements we have kept
-- * and the ones we have thrown away
-- We leave these implicit: they can be inferred from the rest
{kept} : List A
{thrown} : List A
-- There is a way for us to recover the original
-- input by interleaving the two lists
cover : Interleaving kept thrown xs
-- Finally, the partition was made according to the predicate
allP : All P kept
all¬P : All (∁ P) thrown
-- Once we have this type written down, we can write the function.
-- We use an anonymous module to clean up the function's type.
module _ {a p} {A : Set a} {P : Pred A p} (P? : Decidable P) where
filter : ∀ xs → Filter P xs
-- If the list is empty, we are done.
filter [] = [] ≡ [] ⊎ []
filter (x ∷ xs) =
-- otherwise we start by running filter on the tail
let xs' ≡ ps ⊎ ¬ps = filter xs in
-- And depending on whether `P` holds of the head,
-- we cons it to the `kept` or `thrown` list.
case P? x of λ where -- [1]
(yes p) → consˡ xs' ≡ p ∷ ps ⊎ ¬ps
(no ¬p) → consʳ xs' ≡ ps ⊎ ¬p ∷ ¬ps
-- [1] See the following module for explanations of `case_of_` and
-- pattern-matching lambdas
import README.Case
| 36.517647
| 80
| 0.61308
|
1283623cd7d638ee7eebcb463b8e2e1386f3877c
| 1,644
|
agda
|
Agda
|
Numeral/Natural/Relation/Order/Classical.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Relation/Order/Classical.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Relation/Order/Classical.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Relation.Order.Classical where
import Lvl
open import Logic.Propositional
open import Numeral.Natural
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Decidable
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Relator.Properties
open import Relator.Ordering.Proofs
open import Type.Properties.Decidable.Proofs
open import Type
instance
[≰][>]-sub : (_≰_) ⊆₂ (_>_)
[≰][>]-sub = From-[≤][<].ByReflTriSub.[≰][>]-sub (_≤_)(_<_) ⦃ [<][≤]-sub = intro(sub₂(_<_)(_≤_)) ⦄ ⦃ [<]-classical = decider-classical _ ⦄
instance
[≯][≤]-sub : (_≯_) ⊆₂ (_≤_)
[≯][≤]-sub = From-[≤][<].ByReflTriSub.[≯][≤]-sub (_≤_)(_<_) ⦃ [<][≤]-sub = intro(sub₂(_<_)(_≤_)) ⦄ ⦃ [≤]-classical = decider-classical _ ⦄
instance
[≱][<]-sub : (_≱_) ⊆₂ (_<_)
[≱][<]-sub = From-[≤][<].ByReflTriSub.[≱][<]-sub (_≤_)(_<_) ⦃ [<][≤]-sub = intro(sub₂(_<_)(_≤_)) ⦄ ⦃ [<]-classical = decider-classical _ ⦄
instance
[≮][≥]-sub : (_≮_) ⊆₂ (_≥_)
[≮][≥]-sub = From-[≤][<].ByReflTriSub.[≮][≥]-sub (_≤_)(_<_) ⦃ [<][≤]-sub = intro(sub₂(_<_)(_≤_)) ⦄ ⦃ [≤]-classical = decider-classical _ ⦄
[≤]-or-[>] : ∀{a b : ℕ} → (a ≤ b) ∨ (a > b)
[≤]-or-[>] = From-[≤][<].ByReflTriSub.[≤]-or-[>] (_≤_)(_<_) ⦃ [<][≤]-sub = intro(sub₂(_<_)(_≤_)) ⦄ ⦃ [≤]-classical = decider-classical _ ⦄ ⦃ [<]-classical = decider-classical _ ⦄
[≥]-or-[<] : ∀{a b : ℕ} → (a ≥ b) ∨ (a < b)
[≥]-or-[<] = From-[≤][<].ByReflTriSub.[≥]-or-[<] (_≤_)(_<_) ⦃ [<][≤]-sub = intro(sub₂(_<_)(_≤_)) ⦄ ⦃ [≤]-classical = decider-classical _ ⦄ ⦃ [<]-classical = decider-classical _ ⦄
| 44.432432
| 178
| 0.574209
|
57f603839e09c625c46cc1c92eeeacb30ccb20a0
| 1,034
|
agda
|
Agda
|
agda/Everything.agda
|
HuStmpHrrr/popl20-artifact
|
48214a55ebb484fd06307df4320813d4a002535b
|
[
"MIT"
] | 1
|
2021-09-23T08:40:28.000Z
|
2021-09-23T08:40:28.000Z
|
agda/Everything.agda
|
HuStmpHrrr/popl20-artifact
|
48214a55ebb484fd06307df4320813d4a002535b
|
[
"MIT"
] | null | null | null |
agda/Everything.agda
|
HuStmpHrrr/popl20-artifact
|
48214a55ebb484fd06307df4320813d4a002535b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
-- The Everything module of undecidability analysis
-- In Agda, we use first order de Bruijn indices to represent variables, that is, the
-- natural numbers.
module Everything where
-- Subtyping problems of all following calculi are undecidable. In this technical
-- work, our reduction proofs stop at F<: deterministic (F<:ᵈ), the undecidability of
-- which is justified by Pierce92.
-- F<: F<:⁻ F<:ᵈ
import FsubMinus
-- D<:
--
-- The examination of D<: is composed of the following files:
import DsubDef -- defines the syntax of D<:.
import Dsub -- defines the simplified subtyping judgment per Lemma 2 in the paper.
import DsubFull -- defines the original definition of D<:.
import DsubEquivSimpler -- defines D<: normal form and shows that D<: subtyping is undecidable.
import DsubNoTrans -- shows that D<: subtyping without transitivity remains undecidable.
import DsubTermUndec -- shows that D<: term typing is also undecidable.
-- other things
-- properties of F<:⁻
import FsubMinus2
| 35.655172
| 95
| 0.745648
|
4b4866f466dbe631047d8f2987bf59ed1fdfbc72
| 612
|
agda
|
Agda
|
test/Succeed/Issue4383.agda
|
zliu41/agda
|
73405f70bced057d24dd4bf122d53f9548544aba
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4383.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4383.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
{-# OPTIONS --local-confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
module _ (A : Set) where
postulate
D : Set
f : D → D → D
r : (x y z : D) → f x (f y z) ≡ f x z
{-# REWRITE r #-}
-- WAS:
-- Confluence check failed: f x (f y (f y₁ z)) reduces to both
-- f x (f y₁ z) and f x (f y z) which are not equal because
-- y != y₁ of type D
-- when checking confluence of the rewrite rule r with itself
module _ (x y y₁ z : D) where
-- SUCCEEDS:
_ : f x (f y₁ z) ≡ f x (f y z)
_ = refl
| 25.5
| 64
| 0.565359
|
4d07834fa67100e0a6d70e855cb2d695678e6f4b
| 5,327
|
agda
|
Agda
|
Cubical/Data/Bool/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Data/Bool/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Data/Bool/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Bool.Properties where
open import Cubical.Core.Everything
open import Cubical.Functions.Involution
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Data.Bool.Base
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
notnot : ∀ x → not (not x) ≡ x
notnot true = refl
notnot false = refl
notIsEquiv : isEquiv not
notIsEquiv = involIsEquiv {f = not} notnot
notEquiv : Bool ≃ Bool
notEquiv = involEquiv {f = not} notnot
notEq : Bool ≡ Bool
notEq = involPath {f = not} notnot
private
variable
ℓ : Level
-- This computes to false as expected
nfalse : Bool
nfalse = transp (λ i → notEq i) i0 true
-- Sanity check
nfalsepath : nfalse ≡ false
nfalsepath = refl
K-Bool
: (P : {b : Bool} → b ≡ b → Type ℓ)
→ (∀{b} → P {b} refl)
→ ∀{b} → (q : b ≡ b) → P q
K-Bool P Pr {false} = J (λ{ false q → P q ; true _ → Lift ⊥ }) Pr
K-Bool P Pr {true} = J (λ{ true q → P q ; false _ → Lift ⊥ }) Pr
isSetBool : isSet Bool
isSetBool a b = J (λ _ p → ∀ q → p ≡ q) (K-Bool (refl ≡_) refl)
true≢false : ¬ true ≡ false
true≢false p = subst (λ b → if b then Bool else ⊥) p true
false≢true : ¬ false ≡ true
false≢true p = subst (λ b → if b then ⊥ else Bool) p true
not≢const : ∀ x → ¬ not x ≡ x
not≢const false = true≢false
not≢const true = false≢true
zeroˡ : ∀ x → true or x ≡ true
zeroˡ false = refl
zeroˡ true = refl
zeroʳ : ∀ x → x or true ≡ true
zeroʳ false = refl
zeroʳ true = refl
or-identityˡ : ∀ x → false or x ≡ x
or-identityˡ false = refl
or-identityˡ true = refl
or-identityʳ : ∀ x → x or false ≡ x
or-identityʳ false = refl
or-identityʳ true = refl
or-comm : ∀ x y → x or y ≡ y or x
or-comm false y =
false or y ≡⟨ or-identityˡ y ⟩
y ≡⟨ sym (or-identityʳ y) ⟩
y or false ∎
or-comm true y =
true or y ≡⟨ zeroˡ y ⟩
true ≡⟨ sym (zeroʳ y) ⟩
y or true ∎
or-assoc : ∀ x y z → x or (y or z) ≡ (x or y) or z
or-assoc false y z =
false or (y or z) ≡⟨ or-identityˡ _ ⟩
y or z ≡[ i ]⟨ or-identityˡ y (~ i) or z ⟩
((false or y) or z) ∎
or-assoc true y z =
true or (y or z) ≡⟨ zeroˡ _ ⟩
true ≡⟨ sym (zeroˡ _) ⟩
true or z ≡[ i ]⟨ zeroˡ y (~ i) or z ⟩
(true or y) or z ∎
or-idem : ∀ x → x or x ≡ x
or-idem false = refl
or-idem true = refl
⊕-identityʳ : ∀ x → x ⊕ false ≡ x
⊕-identityʳ false = refl
⊕-identityʳ true = refl
⊕-comm : ∀ x y → x ⊕ y ≡ y ⊕ x
⊕-comm false false = refl
⊕-comm false true = refl
⊕-comm true false = refl
⊕-comm true true = refl
⊕-assoc : ∀ x y z → x ⊕ (y ⊕ z) ≡ (x ⊕ y) ⊕ z
⊕-assoc false y z = refl
⊕-assoc true false z = refl
⊕-assoc true true z = notnot z
not-⊕ˡ : ∀ x y → not (x ⊕ y) ≡ not x ⊕ y
not-⊕ˡ false y = refl
not-⊕ˡ true y = notnot y
⊕-invol : ∀ x y → x ⊕ (x ⊕ y) ≡ y
⊕-invol false x = refl
⊕-invol true x = notnot x
isEquiv-⊕ : ∀ x → isEquiv (x ⊕_)
isEquiv-⊕ x = involIsEquiv (⊕-invol x)
⊕-Path : ∀ x → Bool ≡ Bool
⊕-Path x = involPath {f = x ⊕_} (⊕-invol x)
⊕-Path-refl : ⊕-Path false ≡ refl
⊕-Path-refl = isInjectiveTransport refl
¬transportNot : ∀(P : Bool ≡ Bool) b → ¬ (transport P (not b) ≡ transport P b)
¬transportNot P b eq = not≢const b sub
where
sub : not b ≡ b
sub = subst {A = Bool → Bool} (λ f → f (not b) ≡ f b)
(λ i c → transport⁻Transport P c i) (cong (transport⁻ P) eq)
module BoolReflection where
data Table (A : Type₀) (P : Bool ≡ A) : Type₀ where
inspect : (b c : A)
→ transport P false ≡ b
→ transport P true ≡ c
→ Table A P
table : ∀ P → Table Bool P
table = J Table (inspect false true refl refl)
reflLemma : (P : Bool ≡ Bool)
→ transport P false ≡ false
→ transport P true ≡ true
→ transport P ≡ transport (⊕-Path false)
reflLemma P ff tt i false = ff i
reflLemma P ff tt i true = tt i
notLemma : (P : Bool ≡ Bool)
→ transport P false ≡ true
→ transport P true ≡ false
→ transport P ≡ transport (⊕-Path true)
notLemma P ft tf i false = ft i
notLemma P ft tf i true = tf i
categorize : ∀ P → transport P ≡ transport (⊕-Path (transport P false))
categorize P with table P
categorize P | inspect false true p q
= subst (λ b → transport P ≡ transport (⊕-Path b)) (sym p) (reflLemma P p q)
categorize P | inspect true false p q
= subst (λ b → transport P ≡ transport (⊕-Path b)) (sym p) (notLemma P p q)
categorize P | inspect false false p q
= rec (¬transportNot P false (q ∙ sym p))
categorize P | inspect true true p q
= rec (¬transportNot P false (q ∙ sym p))
⊕-complete : ∀ P → P ≡ ⊕-Path (transport P false)
⊕-complete P = isInjectiveTransport (categorize P)
⊕-comp : ∀ p q → ⊕-Path p ∙ ⊕-Path q ≡ ⊕-Path (q ⊕ p)
⊕-comp p q = isInjectiveTransport (λ i x → ⊕-assoc q p x i)
open Iso
reflectIso : Iso Bool (Bool ≡ Bool)
reflectIso .fun = ⊕-Path
reflectIso .inv P = transport P false
reflectIso .leftInv = ⊕-identityʳ
reflectIso .rightInv P = sym (⊕-complete P)
reflectEquiv : Bool ≃ (Bool ≡ Bool)
reflectEquiv = isoToEquiv reflectIso
| 27.178571
| 80
| 0.606908
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.