Search is not available for this dataset
text
string | meta
dict |
---|---|
-- 2016-01-05, Jesper: In some cases, the new unifier is still too restrictive
-- when --cubical-compatible is enabled because it doesn't do generalization of datatype
-- indices. This should be fixed in the future.
-- 2016-06-23, Jesper: Now fixed.
{-# OPTIONS --cubical-compatible #-}
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
data Bar : Set₁ where
bar : Bar
baz : (A : Set) → Bar
data Foo : Bar → Set₁ where
foo : Foo bar
test : foo ≡ foo → Set₁
test refl = Set
| {
"alphanum_fraction": 0.6494023904,
"avg_line_length": 22.8181818182,
"ext": "agda",
"hexsha": "74d8ad5f6d947a1390f720abe20a0deec0dca7b1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/NewUnifierTooRestrictive.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/NewUnifierTooRestrictive.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/NewUnifierTooRestrictive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 165,
"size": 502
} |
module _ where
module M (A : Set) where
record R : Set where
postulate
B : Set
postulate
A : Set
r : M.R A
module M' = M A
open import Agda.Builtin.Reflection
open import Agda.Builtin.List
postulate
any : {A : Set} → A
macro
m : Term → TC _
m goal =
bindTC (inferType goal) λ goal-type →
bindTC (normalise goal-type) λ goal-type →
bindTC (inferType goal-type) λ _ →
unify goal (def (quote any) [])
g : M'.R.B r
g = m
| {
"alphanum_fraction": 0.6155507559,
"avg_line_length": 14.935483871,
"ext": "agda",
"hexsha": "14ae9832e472c7f80fdb98267f06dfe34470227e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3083.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3083.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3083.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 157,
"size": 463
} |
{-# OPTIONS --no-positivity-check #-}
module Clowns where
import Equality
import Isomorphism
import Derivative
import ChainRule
open import Sets
open import Functor
open import Zipper
open import Dissect
open Functor.Recursive
open Functor.Semantics
-- Natural numbers
NatF : U
NatF = K [1] + Id
Nat : Set
Nat = μ NatF
zero : Nat
zero = inn (inl <>)
suc : Nat -> Nat
suc n = inn (inr n)
plus : Nat -> Nat -> Nat
plus n m = fold NatF φ n where
φ : ⟦ NatF ⟧ Nat -> Nat
φ (inl <>) = m
φ (inr z) = suc z
-- Lists
ListF : (A : Set) -> U
ListF A = K [1] + K A × Id
List' : (A : Set) -> Set
List' A = μ (ListF A)
nil : {A : Set} -> List' A
nil = inn (inl <>)
cons : {A : Set} -> A -> List' A -> List' A
cons x xs = inn (inr < x , xs >)
sum : List' Nat -> Nat
sum = fold (ListF Nat) φ where
φ : ⟦ ListF Nat ⟧ Nat -> Nat
φ (inl <>) = zero
φ (inr < n , m >) = plus n m
TreeF : U
TreeF = K [1] + Id × Id
Tree : Set
Tree = μ TreeF
leaf : Tree
leaf = inn (inl <>)
node : Tree -> Tree -> Tree
node l r = inn (inr < l , r >)
| {
"alphanum_fraction": 0.5773294909,
"avg_line_length": 15.5373134328,
"ext": "agda",
"hexsha": "395e53f50b32727b1c14f996cd245d0aa596b17c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/clowns/Clowns.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/clowns/Clowns.agda",
"max_line_length": 43,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/clowns/Clowns.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 392,
"size": 1041
} |
module Numeric.Nat.GCD.Properties where
open import Prelude
open import Numeric.Nat.Properties
open import Numeric.Nat.Divide
open import Numeric.Nat.Divide.Properties
open import Numeric.Nat.GCD
open import Numeric.Nat.GCD.Extended
open import Tactic.Nat
open import Tactic.Cong
gcd-is-gcd : ∀ d a b → gcd! a b ≡ d → IsGCD d a b
gcd-is-gcd d a b refl with gcd a b
... | gcd-res _ isgcd = isgcd
gcd-divides-l : ∀ a b → gcd! a b Divides a
gcd-divides-l a b with gcd a b
... | gcd-res _ i = IsGCD.d|a i
gcd-divides-r : ∀ a b → gcd! a b Divides b
gcd-divides-r a b with gcd a b
... | gcd-res _ i = IsGCD.d|b i
is-gcd-unique : ∀ {a b} d₁ d₂ (g₁ : IsGCD d₁ a b) (g₂ : IsGCD d₂ a b) → d₁ ≡ d₂
is-gcd-unique d d′ (is-gcd d|a d|b gd) (is-gcd d′|a d′|b gd′) =
divides-antisym (gd′ d d|a d|b)
(gd d′ d′|a d′|b)
gcd-unique : ∀ a b d → IsGCD d a b → gcd! a b ≡ d
gcd-unique a b d pd with gcd a b
... | gcd-res d′ pd′ = is-gcd-unique d′ d pd′ pd
is-gcd-commute : ∀ {d a b} → IsGCD d a b → IsGCD d b a
is-gcd-commute (is-gcd d|a d|b g) = is-gcd d|b d|a (flip ∘ g)
gcd-commute : ∀ a b → gcd! a b ≡ gcd! b a
gcd-commute a b with gcd b a
gcd-commute a b | gcd-res d p = gcd-unique a b d (is-gcd-commute p)
gcd-factor-l : ∀ {a b} → a Divides b → gcd! a b ≡ a
gcd-factor-l {a} (factor! b) =
gcd-unique a (b * a) a
(is-gcd divides-refl (divides-mul-r b divides-refl) λ _ k|a _ → k|a)
gcd-factor-r : ∀ {a b} → b Divides a → gcd! a b ≡ b
gcd-factor-r {a} {b} b|a = gcd-commute a b ⟨≡⟩ gcd-factor-l b|a
gcd-idem : ∀ a → gcd! a a ≡ a
gcd-idem a = gcd-factor-l divides-refl
gcd-zero-l : ∀ n → gcd! 0 n ≡ n
gcd-zero-l n = gcd-unique 0 n n (is-gcd (factor! 0) divides-refl λ _ _ k|n → k|n)
gcd-zero-r : ∀ n → gcd! n 0 ≡ n
gcd-zero-r n = gcd-commute n 0 ⟨≡⟩ gcd-zero-l n
zero-is-gcd-l : ∀ {a b} → IsGCD 0 a b → a ≡ 0
zero-is-gcd-l (is-gcd 0|a _ _) = divides-zero 0|a
zero-is-gcd-r : ∀ {a b} → IsGCD 0 a b → b ≡ 0
zero-is-gcd-r (is-gcd _ 0|b _) = divides-zero 0|b
zero-gcd-l : ∀ a b → gcd! a b ≡ 0 → a ≡ 0
zero-gcd-l a b eq with gcd a b
zero-gcd-l a b refl | gcd-res .0 p = zero-is-gcd-l p
zero-gcd-r : ∀ a b → gcd! a b ≡ 0 → b ≡ 0
zero-gcd-r a b eq with gcd a b
zero-gcd-r a b refl | gcd-res .0 p = zero-is-gcd-r p
nonzero-is-gcd-l : ∀ {a b d} {{_ : NonZero a}} → IsGCD d a b → NonZero d
nonzero-is-gcd-l {0} {{}} _
nonzero-is-gcd-l {a@(suc _)} {d = suc _} _ = _
nonzero-is-gcd-l {a@(suc _)} {d = 0} (is-gcd (factor q eq) _ _) = refute eq
nonzero-is-gcd-r : ∀ {a b d} {{_ : NonZero b}} → IsGCD d a b → NonZero d
nonzero-is-gcd-r isgcd = nonzero-is-gcd-l (is-gcd-commute isgcd)
nonzero-gcd-l : ∀ a b {{_ : NonZero a}} → NonZero (gcd! a b)
nonzero-gcd-l a b = nonzero-is-gcd-l (GCD.isGCD (gcd a b))
nonzero-gcd-r : ∀ a b {{_ : NonZero b}} → NonZero (gcd! a b)
nonzero-gcd-r a b = nonzero-is-gcd-r (GCD.isGCD (gcd a b))
private
_|>_ = divides-trans
gcd-assoc : ∀ a b c → gcd! a (gcd! b c) ≡ gcd! (gcd! a b) c
gcd-assoc a b c with gcd a b | gcd b c
... | gcd-res ab (is-gcd ab|a ab|b gab)
| gcd-res bc (is-gcd bc|b bc|c gbc) with gcd ab c
... | gcd-res ab-c (is-gcd abc|ab abc|c gabc) =
gcd-unique a bc ab-c
(is-gcd (abc|ab |> ab|a)
(gbc ab-c (abc|ab |> ab|b) abc|c)
λ k k|a k|bc → gabc k (gab k k|a (k|bc |> bc|b))
(k|bc |> bc|c))
-- Coprimality properties
coprime-sym : ∀ a b → Coprime a b → Coprime b a
coprime-sym a b p = gcd-commute b a ⟨≡⟩ p
coprimeByDivide : ∀ a b → (∀ k → k Divides a → k Divides b → k Divides 1) → Coprime a b
coprimeByDivide a b g = gcd-unique a b 1 (is-gcd one-divides one-divides g)
divide-coprime : ∀ d a b → Coprime a b → d Divides a → d Divides b → d Divides 1
divide-coprime d a b p d|a d|b with gcd a b
divide-coprime d a b refl d|a d|b | gcd-res _ (is-gcd _ _ g) =
g d d|a d|b
mul-coprime-l : ∀ a b c → Coprime a (b * c) → Coprime a b
mul-coprime-l a b c a⊥bc =
coprimeByDivide a b λ k k|a k|b →
divide-coprime k a (b * c) a⊥bc k|a (divides-mul-l c k|b)
mul-coprime-r : ∀ a b c → Coprime a (b * c) → Coprime a c
mul-coprime-r a b c a⊥bc = mul-coprime-l a c b (transport (Coprime a) auto a⊥bc)
is-gcd-factors-coprime : ∀ {a b d} (p : IsGCD d a b) {{_ : NonZero d}} →
Coprime (is-gcd-factor₁ p) (is-gcd-factor₂ p)
is-gcd-factors-coprime {a} {b} {0} _ {{}}
is-gcd-factors-coprime {a} {b} {d@(suc _)} p@(is-gcd (factor qa refl) (factor qb refl) g) with gcd qa qb
... | gcd-res j (is-gcd j|qa j|qb gj) = lem₃ j lem₂
where
lem : IsGCD (j * d) a b
lem = is-gcd (divides-mul-cong-r d j|qa) (divides-mul-cong-r d j|qb) λ k k|a k|b →
divides-mul-r j (g k k|a k|b)
lem₂ : d ≡ j * d
lem₂ = is-gcd-unique d (j * d) p lem
lem₃ : ∀ j → d ≡ j * d → j ≡ 1
lem₃ 0 ()
lem₃ 1 _ = refl
lem₃ (suc (suc n)) eq = refute eq
private
mul-gcd-distr-l' : ∀ a b c ⦃ a>0 : NonZero a ⦄ ⦃ b>0 : NonZero b ⦄ → gcd! (a * b) (a * c) ≡ a * gcd! b c
mul-gcd-distr-l' a b c with gcd b c | gcd (a * b) (a * c)
... | gcd-res d gcd-bc@(is-gcd (factor! b′) (factor! c′) _)
| gcd-res δ gcd-abac@(is-gcd (factor u uδ=ab) (factor v vδ=ac) g) =
let instance _ = nonzero-is-gcd-l gcd-bc
_ : NonZero (d * a)
_ = mul-nonzero d a
in case g (d * a) (factor b′ auto) (factor c′ auto) of λ where
(factor w wda=δ) →
let dab′=dauw =
d * a * b′ ≡⟨ by uδ=ab ⟩
u * δ ≡⟨ u *_ $≡ wda=δ ⟩ʳ
u * (w * (d * a)) ≡⟨ auto ⟩
d * a * (u * w) ∎
dac′=davw =
d * a * c′ ≡⟨ by vδ=ac ⟩
v * δ ≡⟨ v *_ $≡ wda=δ ⟩ʳ
v * (w * (d * a)) ≡⟨ auto ⟩
d * a * (v * w) ∎
uw=b′ : u * w ≡ b′
uw=b′ = sym (mul-inj₂ (d * a) b′ (u * w) dab′=dauw)
vw=c′ : v * w ≡ c′
vw=c′ = sym (mul-inj₂ (d * a) c′ (v * w) dac′=davw)
w=1 : w ≡ 1
w=1 = divides-one (divide-coprime w b′ c′ (is-gcd-factors-coprime gcd-bc)
(factor u uw=b′)
(factor v vw=c′))
in case w=1 of λ where refl → by wda=δ
mul-gcd-distr-l : ∀ a b c → gcd! (a * b) (a * c) ≡ a * gcd! b c
mul-gcd-distr-l zero b c = refl
mul-gcd-distr-l a zero c = (λ z → gcd! z (a * c)) $≡ mul-zero-r a
mul-gcd-distr-l a@(suc _) b@(suc _) c = mul-gcd-distr-l' a b c
mul-gcd-distr-r : ∀ a b c → gcd! (a * c) (b * c) ≡ gcd! a b * c
mul-gcd-distr-r a b c =
gcd! (a * c) (b * c)
≡⟨ gcd! $≡ mul-commute a c *≡ mul-commute b c ⟩
gcd! (c * a) (c * b)
≡⟨ mul-gcd-distr-l c a b ⟩
c * gcd! a b
≡⟨ auto ⟩
gcd! a b * c ∎
-- Divide two numbers by their gcd and return the result, the gcd, and some useful properties.
-- Continuation-passing for efficiency reasons.
gcdReduce' : ∀ {a} {A : Set a} (a b : Nat) ⦃ _ : NonZero b ⦄ →
((a′ b′ d : Nat) → (⦃ _ : NonZero a ⦄ → NonZero a′) →
⦃ nzb : NonZero b′ ⦄ → ⦃ nzd : NonZero d ⦄ →
a′ * d ≡ a → b′ * d ≡ b →
Coprime a′ b′ → A) → A
gcdReduce' a b ret with gcd a b
gcdReduce' a b ret | gcd-res d isgcd@(is-gcd d|a@(factor a′ eqa) d|b@(factor b′ eqb) g)=
let instance _ = nonzero-is-gcd-r isgcd in
ret a′ b′ d (nonzero-factor d|a) ⦃ nonzero-factor d|b ⦄
eqa eqb
(is-gcd-factors-coprime isgcd)
-- Both arguments are non-zero.
gcdReduce : ∀ {a} {A : Set a} (a b : Nat) ⦃ _ : NonZero a ⦄ ⦃ _ : NonZero b ⦄ →
((a′ b′ d : Nat) ⦃ a′>0 : NonZero a′ ⦄ ⦃ b′>0 : NonZero b′ ⦄ ⦃ nzd : NonZero d ⦄ →
a′ * d ≡ a → b′ * d ≡ b → Coprime a′ b′ → A) → A
gcdReduce a b k = gcdReduce' a b λ a′ b′ d a′>0 eq₁ eq₂ a′⊥b′ →
let instance _ = a′>0 in k a′ b′ d eq₁ eq₂ a′⊥b′
-- Only the right argument is guaranteed to be non-zero.
gcdReduce-r : ∀ {a} {A : Set a} (a b : Nat) ⦃ _ : NonZero b ⦄ →
((a′ b′ d : Nat) ⦃ nzb : NonZero b′ ⦄ ⦃ nzd : NonZero d ⦄ →
a′ * d ≡ a → b′ * d ≡ b → Coprime a′ b′ → A) → A
gcdReduce-r a b k = gcdReduce' a b λ a′ b′ d _ eq₁ eq₂ a′⊥b′ →
k a′ b′ d eq₁ eq₂ a′⊥b′
--- Properties ---
coprime-divide-mul-l : ∀ a b c → Coprime a b → a Divides (b * c) → a Divides c
coprime-divide-mul-l a b c p a|bc with extendedGCD a b
coprime-divide-mul-l a b c p a|bc | gcd-res d i e with gcd-unique _ _ _ i ʳ⟨≡⟩ p
coprime-divide-mul-l a b c p (factor q qa=bc) | gcd-res d i (bézoutL x y ax=1+by) | refl =
factor (x * c - y * q) $
(x * c - y * q) * a
≡⟨ auto ⟩
a * x * c - y * (q * a)
≡⟨ by-cong ax=1+by ⟩
suc (b * y) * c - y * (q * a)
≡⟨ by-cong qa=bc ⟩
suc (b * y) * c - y * (b * c)
≡⟨ auto ⟩
c ∎
coprime-divide-mul-l a b c p (factor q qa=bc) | gcd-res d i (bézoutR x y by=1+ax) | refl =
factor (y * q - x * c) $
(y * q - x * c) * a
≡⟨ auto ⟩
y * (q * a) - a * x * c
≡⟨ by-cong qa=bc ⟩
y * (b * c) - a * x * c
≡⟨ auto ⟩
(b * y) * c - a * x * c
≡⟨ by-cong by=1+ax ⟩
suc (a * x) * c - a * x * c
≡⟨ auto ⟩
c ∎
coprime-divide-mul-r : ∀ a b c → Coprime a c → a Divides (b * c) → a Divides b
coprime-divide-mul-r a b c p a|bc =
coprime-divide-mul-l a c b p (transport (a Divides_) auto a|bc)
is-gcd-by-coprime-factors : ∀ d a b (d|a : d Divides a) (d|b : d Divides b) ⦃ nzd : NonZero d ⦄ →
Coprime (get-factor d|a) (get-factor d|b) →
IsGCD d a b
is-gcd-by-coprime-factors d a b d|a@(factor! q) d|b@(factor! r) q⊥r =
is-gcd d|a d|b λ k k|a k|b →
let lem : ∀ j → j Divides q → j Divides r → j ≡ 1
lem j j|q j|r = divides-one (divide-coprime j q r q⊥r j|q j|r)
in
case gcd k d of λ where
(gcd-res g isgcd@(is-gcd (factor k′ k′g=k@refl) (factor d′ d′g=d@refl) sup)) →
let instance g>0 = nonzero-is-gcd-r isgcd
k′⊥d′ : Coprime k′ d′
k′⊥d′ = is-gcd-factors-coprime isgcd
k′|qd′ : k′ Divides (q * d′)
k′|qd′ = cancel-mul-divides-r k′ (q * d′) g
(transport ((k′ * g) Divides_) {x = q * (d′ * g)} {q * d′ * g} auto k|a)
k′|rd′ : k′ Divides (r * d′)
k′|rd′ = cancel-mul-divides-r k′ (r * d′) g
(transport ((k′ * g) Divides_) {x = r * (d′ * g)} {r * d′ * g} auto k|b)
k′|q : k′ Divides q
k′|q = coprime-divide-mul-r k′ q d′ k′⊥d′ k′|qd′
k′|r : k′ Divides r
k′|r = coprime-divide-mul-r k′ r d′ k′⊥d′ k′|rd′
k′=1 = lem k′ k′|q k′|r
k=g : k ≡ g
k=g = case k′=1 of λ where refl → auto
in factor d′ (d′ *_ $≡ k=g ⟨≡⟩ d′g=d)
| {
"alphanum_fraction": 0.5026891691,
"avg_line_length": 39.3576642336,
"ext": "agda",
"hexsha": "546e05440b1350f625df2c71511a89829666644c",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Numeric/Nat/GCD/Properties.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Numeric/Nat/GCD/Properties.agda",
"max_line_length": 106,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Numeric/Nat/GCD/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 4584,
"size": 10784
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.QuotientAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset using (_∈_)
open import Cubical.HITs.SetQuotients hiding (_/_)
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.QuotientRing renaming (_/_ to _/Ring_) hiding ([_]/)
open import Cubical.Algebra.CommRing.Ideal hiding (IdealsIn)
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.Ideal
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Ideal using (isIdeal)
private
variable
ℓ : Level
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) where
open CommRingStr {{...}} hiding (_-_; -_; dist; ·Lid; ·Rdist+) renaming (_·_ to _·R_; _+_ to _+R_)
open CommAlgebraStr {{...}}
open RingTheory (CommRing→Ring (CommAlgebra→CommRing A)) using (-DistR·)
instance
_ : CommRingStr _
_ = snd R
_ : CommAlgebraStr _ _
_ = snd A
_/_ : (I : IdealsIn A) → CommAlgebra R ℓ
_/_ I = commAlgebraFromCommRing
((CommAlgebra→CommRing A) /Ring I)
(λ r → elim (λ _ → squash/) (λ x → [ r ⋆ x ]) (eq r))
(λ r s → elimProp (λ _ → squash/ _ _)
λ x i → [ ((r ·R s) ⋆ x ≡⟨ ⋆-assoc r s x ⟩
r ⋆ (s ⋆ x) ∎) i ])
(λ r s → elimProp (λ _ → squash/ _ _)
λ x i → [ ((r +R s) ⋆ x ≡⟨ ⋆-ldist r s x ⟩
r ⋆ x + s ⋆ x ∎) i ])
(λ r → elimProp2 (λ _ _ → squash/ _ _)
λ x y i → [ (r ⋆ (x + y) ≡⟨ ⋆-rdist r x y ⟩
r ⋆ x + r ⋆ y ∎) i ])
(elimProp (λ _ → squash/ _ _)
(λ x i → [ (1r ⋆ x ≡⟨ ⋆-lid x ⟩ x ∎) i ]))
λ r → elimProp2 (λ _ _ → squash/ _ _)
λ x y i → [ ((r ⋆ x) · y ≡⟨ ⋆-lassoc r x y ⟩
r ⋆ (x · y) ∎) i ]
where
open CommIdeal using (isCommIdeal)
eq : (r : fst R) (x y : fst A) → x - y ∈ (fst I) → [ r ⋆ x ] ≡ [ r ⋆ y ]
eq r x y x-y∈I = eq/ _ _
(subst (λ u → u ∈ fst I)
((r ⋆ 1a) · (x - y) ≡⟨ ·Rdist+ (r ⋆ 1a) x (- y) ⟩
(r ⋆ 1a) · x + (r ⋆ 1a) · (- y) ≡[ i ]⟨ (r ⋆ 1a) · x + -DistR· (r ⋆ 1a) y i ⟩
(r ⋆ 1a) · x - (r ⋆ 1a) · y ≡[ i ]⟨ ⋆-lassoc r 1a x i
- ⋆-lassoc r 1a y i ⟩
r ⋆ (1a · x) - r ⋆ (1a · y) ≡[ i ]⟨ r ⋆ (·Lid x i) - r ⋆ (·Lid y i) ⟩
r ⋆ x - r ⋆ y ∎ )
(isCommIdeal.·Closed (snd I) _ x-y∈I))
[_]/ : {R : CommRing ℓ} {A : CommAlgebra R ℓ} {I : IdealsIn A}
→ (a : fst A) → fst (A / I)
[ a ]/ = [ a ]
| {
"alphanum_fraction": 0.4423142759,
"avg_line_length": 43.5970149254,
"ext": "agda",
"hexsha": "26d16354eda4d14be45dede6c86606a43d3ebc81",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1080,
"size": 2921
} |
-- Example by Ian Orton
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
_∧_ : Bool → Bool → Bool
true ∧ y = y
false ∧ y = false
data ⊥ : Set where
⊥-elim : ∀ {a} {A : Set a} → ⊥ → A
⊥-elim ()
¬_ : ∀ {a} → Set a → Set a
¬ A = A → ⊥
contradiction : ∀ {a b} {A : Set a} {B : Set b} → A → ¬ A → B
contradiction a f = ⊥-elim (f a)
_≢_ : ∀ {a} {A : Set a} (x y : A) → Set a
x ≢ y = ¬ (x ≡ y)
postulate
obvious : (b b' : Bool) (p : b ≢ b') → (b ∧ b') ≡ false
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE obvious #-}
oops : (b : Bool) → b ∧ b ≡ false
oops b = refl
true≢false : true ≡ false → ⊥
true≢false ()
bot : ⊥
bot = true≢false (oops true)
| {
"alphanum_fraction": 0.5231213873,
"avg_line_length": 17.3,
"ext": "agda",
"hexsha": "76f39c82aa80616c004a043438dd834719f1e64c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Fail/Issue2059.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/Fail/Issue2059.agda",
"max_line_length": 61,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Fail/Issue2059.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 289,
"size": 692
} |
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.Pushout
open import Homotopy.VanKampen.Guide
{-
This module provides the function code⇒path
for the homotopy equivalence for
van Kampen theorem.
-}
module Homotopy.VanKampen.CodeToPath {i} (d : pushout-diag i)
(l : legend i (pushout-diag.C d)) where
open pushout-diag d
open legend l
open import Homotopy.Truncation
open import Homotopy.PathTruncation
open import Homotopy.VanKampen.Code d l
private
pgl : ∀ n → _≡₀_ {A = P} (left (f $ loc n)) (right (g $ loc n))
pgl n = proj (glue $ loc n)
p!gl : ∀ n → _≡₀_ {A = P} (right (g $ loc n)) (left (f $ loc n))
p!gl n = proj (! (glue $ loc n))
ap₀l : ∀ {a₁ a₂} → a₁ ≡₀ a₂ → _≡₀_ {A = P} (left a₁) (left a₂)
ap₀l p = ap₀ left p
ap₀r : ∀ {b₁ b₂} → b₁ ≡₀ b₂ → _≡₀_ {A = P} (right b₁) (right b₂)
ap₀r p = ap₀ right p
module _ {a₁ : A} where
private
ap⇒path-split : (∀ {a₂} → a-code-a a₁ a₂ → _≡₀_ {A = P} (left a₁) (left a₂))
× (∀ {b₂} → a-code-b a₁ b₂ → _≡₀_ {A = P} (left a₁) (right b₂))
ap⇒path-split = a-code-rec-nondep a₁
(λ a₂ → left a₁ ≡₀ left a₂)
⦃ λ a₂ → π₀-is-set _ ⦄
(λ b₂ → left a₁ ≡₀ right b₂)
⦃ λ b₂ → π₀-is-set _ ⦄
(λ p → ap₀l p)
(λ n pco p → (pco ∘₀ p!gl n) ∘₀ ap₀l p)
(λ n pco p → (pco ∘₀ pgl n) ∘₀ ap₀r p)
(λ n {co} pco →
(((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n) ∘₀ refl₀
≡⟨ refl₀-right-unit _ ⟩
((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n
≡⟨ ap (λ x → x ∘₀ p!gl n)
$ refl₀-right-unit $ pco ∘₀ pgl n ⟩
(pco ∘₀ pgl n) ∘₀ p!gl n
≡⟨ concat₀-assoc pco (pgl n) (p!gl n) ⟩
pco ∘₀ (pgl n ∘₀ p!gl n)
≡⟨ ap (λ x → pco ∘₀ proj x)
$ opposite-right-inverse $ glue $ loc n ⟩
pco ∘₀ refl₀
≡⟨ refl₀-right-unit pco ⟩∎
pco
∎)
(λ n {co} pco →
(((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n) ∘₀ refl₀
≡⟨ refl₀-right-unit _ ⟩
((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n
≡⟨ ap (λ x → x ∘₀ pgl n)
$ refl₀-right-unit $ pco ∘₀ p!gl n ⟩
(pco ∘₀ p!gl n) ∘₀ pgl n
≡⟨ concat₀-assoc pco (p!gl n) (pgl n) ⟩
pco ∘₀ (p!gl n ∘₀ pgl n)
≡⟨ ap (λ x → pco ∘₀ proj x)
$ opposite-left-inverse $ glue $ loc n ⟩
pco ∘₀ refl₀
≡⟨ refl₀-right-unit pco ⟩∎
pco
∎)
(λ n₁ {co} pco n₂ r →
(((pco ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) ∘₀ p!gl n₂) ∘₀ refl₀
≡⟨ refl₀-right-unit _ ⟩
((pco ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) ∘₀ p!gl n₂
≡⟨ concat₀-assoc (pco ∘₀ pgl n₁) (ap₀r (ap₀ g r)) (p!gl n₂) ⟩
(pco ∘₀ pgl n₁) ∘₀ (ap₀r (ap₀ g r) ∘₀ p!gl n₂)
≡⟨ ap (λ x → (pco ∘₀ pgl n₁) ∘₀ (x ∘₀ p!gl n₂)) $ ! $ ap₀-compose right g r ⟩
(pco ∘₀ pgl n₁) ∘₀ (ap₀ (right ◯ g) r ∘₀ p!gl n₂)
≡⟨ ap (λ x → (pco ∘₀ pgl n₁) ∘₀ x)
$ homotopy₀-naturality (right ◯ g) (left ◯ f) (proj ◯ (! ◯ glue)) r ⟩
(pco ∘₀ pgl n₁) ∘₀ (p!gl n₁ ∘₀ ap₀ (left ◯ f) r)
≡⟨ ! $ concat₀-assoc (pco ∘₀ pgl n₁) (p!gl n₁) (ap₀ (left ◯ f) r) ⟩
((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ ap₀ (left ◯ f) r
≡⟨ ap (λ x → ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ x) $ ap₀-compose left f r ⟩
((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)
≡⟨ ap (λ x → (x ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r))
$ ! $ refl₀-right-unit $ pco ∘₀ pgl n₁ ⟩∎
(((pco ∘₀ pgl n₁) ∘₀ refl₀) ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)
∎)
aa⇒path : ∀ {a₂} → a-code-a a₁ a₂ → _≡₀_ {A = P} (left a₁) (left a₂)
aa⇒path = π₁ ap⇒path-split
ab⇒path : ∀ {b₂} → a-code-b a₁ b₂ → _≡₀_ {A = P} (left a₁) (right b₂)
ab⇒path = π₂ ap⇒path-split
ap⇒path : ∀ {p₂ : P} → a-code a₁ p₂ → left a₁ ≡₀ p₂
ap⇒path {p₂} = pushout-rec
(λ p → a-code a₁ p → left a₁ ≡₀ p)
(λ a → aa⇒path {a})
(λ b → ab⇒path {b})
(loc-fiber-rec l
(λ c → transport (λ p → a-code a₁ p → left a₁ ≡₀ p) (glue c) aa⇒path
≡ ab⇒path)
⦃ λ c → →-is-set (π₀-is-set (left a₁ ≡ right (g c))) _ _ ⦄
(λ n → funext λ co →
transport (λ p → a-code a₁ p → left a₁ ≡₀ p) (glue $ loc n) aa⇒path co
≡⟨ trans-→ (a-code a₁) (λ x → left a₁ ≡₀ x) (glue $ loc n) aa⇒path co ⟩
transport (λ p → left a₁ ≡₀ p) (glue $ loc n) (aa⇒path $ transport (a-code a₁) (! (glue $ loc n)) co)
≡⟨ ap (transport (λ p → left a₁ ≡₀ p) (glue $ loc n) ◯ aa⇒path) $ trans-a-code-!glue-loc n co ⟩
transport (λ p → left a₁ ≡₀ p) (glue $ loc n) (aa⇒path $ ab⇒aa n co)
≡⟨ trans-cst≡₀id (glue $ loc n) (aa⇒path $ ab⇒aa n co) ⟩
(aa⇒path $ ab⇒aa n co) ∘₀ pgl n
≡⟨ refl ⟩
((ab⇒path co ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n
≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ ab⇒path co ∘₀ p!gl n ⟩
(ab⇒path co ∘₀ p!gl n) ∘₀ pgl n
≡⟨ concat₀-assoc (ab⇒path co) (p!gl n) (pgl n) ⟩
ab⇒path co ∘₀ (p!gl n ∘₀ pgl n)
≡⟨ ap (λ x → ab⇒path co ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩
ab⇒path co ∘₀ refl₀
≡⟨ refl₀-right-unit $ ab⇒path co ⟩∎
ab⇒path co
∎))
p₂
-- FIXME
-- There is tension between reducing duplicate code and
-- maintaining definitional equality. I could not make
-- the neccessary type conversion definitional, so
-- I just copied and pasted the previous module.
module _ {b₁ : B} where
private
bp⇒path-split : (∀ {b₂} → b-code-b b₁ b₂ → _≡₀_ {A = P} (right b₁) (right b₂))
× (∀ {a₂} → b-code-a b₁ a₂ → _≡₀_ {A = P} (right b₁) (left a₂))
bp⇒path-split = b-code-rec-nondep b₁
(λ b₂ → right b₁ ≡₀ right b₂)
⦃ λ b₂ → π₀-is-set _ ⦄
(λ a₂ → right b₁ ≡₀ left a₂)
⦃ λ a₂ → π₀-is-set _ ⦄
(λ p → ap₀r p)
(λ n pco p → (pco ∘₀ pgl n) ∘₀ ap₀r p)
(λ n pco p → (pco ∘₀ p!gl n) ∘₀ ap₀l p)
(λ n {co} pco →
(((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n) ∘₀ refl₀
≡⟨ refl₀-right-unit _ ⟩
((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n
≡⟨ ap (λ x → x ∘₀ pgl n)
$ refl₀-right-unit $ pco ∘₀ p!gl n ⟩
(pco ∘₀ p!gl n) ∘₀ pgl n
≡⟨ concat₀-assoc pco (p!gl n) (pgl n) ⟩
pco ∘₀ (p!gl n ∘₀ pgl n)
≡⟨ ap (λ x → pco ∘₀ proj x)
$ opposite-left-inverse $ glue $ loc n ⟩
pco ∘₀ refl₀
≡⟨ refl₀-right-unit pco ⟩∎
pco
∎)
(λ n {co} pco →
(((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n) ∘₀ refl₀
≡⟨ refl₀-right-unit _ ⟩
((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n
≡⟨ ap (λ x → x ∘₀ p!gl n)
$ refl₀-right-unit $ pco ∘₀ pgl n ⟩
(pco ∘₀ pgl n) ∘₀ p!gl n
≡⟨ concat₀-assoc pco (pgl n) (p!gl n) ⟩
pco ∘₀ (pgl n ∘₀ p!gl n)
≡⟨ ap (λ x → pco ∘₀ proj x)
$ opposite-right-inverse $ glue $ loc n ⟩
pco ∘₀ refl₀
≡⟨ refl₀-right-unit pco ⟩∎
pco
∎)
(λ n₁ {co} pco n₂ r →
(((pco ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) ∘₀ pgl n₂) ∘₀ refl₀
≡⟨ refl₀-right-unit _ ⟩
((pco ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) ∘₀ pgl n₂
≡⟨ concat₀-assoc (pco ∘₀ p!gl n₁) (ap₀l (ap₀ f r)) (pgl n₂) ⟩
(pco ∘₀ p!gl n₁) ∘₀ (ap₀l (ap₀ f r) ∘₀ pgl n₂)
≡⟨ ap (λ x → (pco ∘₀ p!gl n₁) ∘₀ (x ∘₀ pgl n₂)) $ ! $ ap₀-compose left f r ⟩
(pco ∘₀ p!gl n₁) ∘₀ (ap₀ (left ◯ f) r ∘₀ pgl n₂)
≡⟨ ap (λ x → (pco ∘₀ p!gl n₁) ∘₀ x)
$ homotopy₀-naturality (left ◯ f) (right ◯ g) (proj ◯ glue) r ⟩
(pco ∘₀ p!gl n₁) ∘₀ (pgl n₁ ∘₀ ap₀ (right ◯ g) r)
≡⟨ ! $ concat₀-assoc (pco ∘₀ p!gl n₁) (pgl n₁) (ap₀ (right ◯ g) r) ⟩
((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ ap₀ (right ◯ g) r
≡⟨ ap (λ x → ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ x) $ ap₀-compose right g r ⟩
((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)
≡⟨ ap (λ x → (x ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r))
$ ! $ refl₀-right-unit $ pco ∘₀ p!gl n₁ ⟩∎
(((pco ∘₀ p!gl n₁) ∘₀ refl₀) ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)
∎)
bb⇒path : ∀ {b₂} → b-code-b b₁ b₂ → _≡₀_ {A = P} (right b₁) (right b₂)
bb⇒path = π₁ bp⇒path-split
ba⇒path : ∀ {a₂} → b-code-a b₁ a₂ → _≡₀_ {A = P} (right b₁) (left a₂)
ba⇒path = π₂ bp⇒path-split
bp⇒path : ∀ {p₂ : P} → b-code b₁ p₂ → right b₁ ≡₀ p₂
bp⇒path {p₂} = pushout-rec
(λ p → b-code b₁ p → right b₁ ≡₀ p)
(λ a → ba⇒path {a})
(λ b → bb⇒path {b})
(λ c → loc-fiber-rec l
(λ c → transport (λ p → b-code b₁ p → right b₁ ≡₀ p) (glue c) ba⇒path
≡ bb⇒path)
⦃ λ c → →-is-set (π₀-is-set (right b₁ ≡ right (g c))) _ _ ⦄
(λ n → funext λ co →
transport (λ p → b-code b₁ p → right b₁ ≡₀ p) (glue $ loc n) ba⇒path co
≡⟨ trans-→ (b-code b₁) (λ x → right b₁ ≡₀ x) (glue $ loc n) ba⇒path co ⟩
transport (λ p → right b₁ ≡₀ p) (glue $ loc n) (ba⇒path $ transport (b-code b₁) (! (glue $ loc n)) co)
≡⟨ ap (transport (λ p → right b₁ ≡₀ p) (glue $ loc n) ◯ ba⇒path) $ trans-b-code-!glue-loc n co ⟩
transport (λ p → right b₁ ≡₀ p) (glue $ loc n) (ba⇒path $ bb⇒ba n co)
≡⟨ trans-cst≡₀id (glue $ loc n) (ba⇒path $ bb⇒ba n co) ⟩
(ba⇒path $ bb⇒ba n co) ∘₀ pgl n
≡⟨ refl ⟩
((bb⇒path co ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n
≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ bb⇒path co ∘₀ p!gl n ⟩
(bb⇒path co ∘₀ p!gl n) ∘₀ pgl n
≡⟨ concat₀-assoc (bb⇒path co) (p!gl n) (pgl n) ⟩
bb⇒path co ∘₀ (p!gl n ∘₀ pgl n)
≡⟨ ap (λ x → bb⇒path co ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩
bb⇒path co ∘₀ refl₀
≡⟨ refl₀-right-unit $ bb⇒path co ⟩∎
bb⇒path co
∎)
c)
p₂
module _ where
private
Lbaaa : ∀ n {a₂} → b-code-a (g $ loc n) a₂ → Set i
Lbaaa n co = aa⇒path {f $ loc n} (ba⇒aa n co) ≡ pgl n ∘₀ ba⇒path co
Lbbab : ∀ n {b₂} → b-code-b (g $ loc n) b₂ → Set i
Lbbab n co = ab⇒path {f $ loc n} (bb⇒ab n co) ≡ pgl n ∘₀ bb⇒path co
private
bp⇒ap⇒path-split : ∀ n
→ (∀ {a₂} co → Lbbab n {a₂} co)
× (∀ {b₂} co → Lbaaa n {b₂} co)
abstract
bp⇒ap⇒path-split n = b-code-rec (g $ loc n)
(λ co → ab⇒path {f $ loc n} (bb⇒ab n co) ≡ pgl n ∘₀ bb⇒path co)
⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄
(λ co → aa⇒path {f $ loc n} (ba⇒aa n co) ≡ pgl n ∘₀ ba⇒path co)
⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄
(λ p →
ab⇒path (bb⇒ab n (⟧b p))
≡⟨ refl ⟩
(refl₀ ∘₀ pgl n) ∘₀ ap₀r p
≡⟨ ap (λ x → x ∘₀ ap₀r p) $ refl₀-left-unit $ pgl n ⟩
pgl n ∘₀ ap₀r p
≡⟨ refl ⟩∎
pgl n ∘₀ bb⇒path (⟧b p)
∎)
(λ n₁ {co} eq p₁ →
(aa⇒path (ba⇒aa n co) ∘₀ pgl n₁) ∘₀ ap₀r p₁
≡⟨ ap (λ x → (x ∘₀ pgl n₁) ∘₀ ap₀r p₁) eq ⟩
((pgl n ∘₀ ba⇒path co) ∘₀ pgl n₁) ∘₀ ap₀r p₁
≡⟨ ap (λ x → x ∘₀ ap₀r p₁)
$ concat₀-assoc (pgl n) (ba⇒path co) (pgl n₁) ⟩
(pgl n ∘₀ (ba⇒path co ∘₀ pgl n₁)) ∘₀ ap₀r p₁
≡⟨ concat₀-assoc (pgl n) (ba⇒path co ∘₀ pgl n₁) (ap₀r p₁) ⟩∎
pgl n ∘₀ ((ba⇒path co ∘₀ pgl n₁) ∘₀ ap₀r p₁)
∎)
(λ n₁ {co} eq p₁ →
(ab⇒path (bb⇒ab n co) ∘₀ p!gl n₁) ∘₀ ap₀l p₁
≡⟨ ap (λ x → (x ∘₀ p!gl n₁) ∘₀ ap₀l p₁) eq ⟩
((pgl n ∘₀ bb⇒path co) ∘₀ p!gl n₁) ∘₀ ap₀l p₁
≡⟨ ap (λ x → x ∘₀ ap₀l p₁)
$ concat₀-assoc (pgl n) (bb⇒path co) (p!gl n₁) ⟩
(pgl n ∘₀ (bb⇒path co ∘₀ p!gl n₁)) ∘₀ ap₀l p₁
≡⟨ concat₀-assoc (pgl n) (bb⇒path co ∘₀ p!gl n₁) (ap₀l p₁) ⟩∎
pgl n ∘₀ ((bb⇒path co ∘₀ p!gl n₁) ∘₀ ap₀l p₁)
∎)
(λ _ co → prop-has-all-paths (π₀-is-set _ _ _) _ co)
(λ _ co → prop-has-all-paths (π₀-is-set _ _ _) _ co)
(λ _ _ _ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _)
ba⇒aa⇒path : ∀ n {a₂} co → Lbaaa n {a₂} co
ba⇒aa⇒path n = π₂ $ bp⇒ap⇒path-split n
bb⇒ab⇒path : ∀ n {b₂} co → Lbbab n {b₂} co
bb⇒ab⇒path n = π₁ $ bp⇒ap⇒path-split n
private
bp⇒ap⇒path : ∀ n {p₂} (co : b-code (g $ loc n) p₂)
→ ap⇒path {f $ loc n} {p₂} (bp⇒ap n {p₂} co)
≡ pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co
abstract
bp⇒ap⇒path n {p₂} = pushout-rec
(λ x → ∀ (co : b-code (g $ loc n) x)
→ ap⇒path {f $ loc n} {x} (bp⇒ap n {x} co)
≡ pgl n ∘₀ bp⇒path {g $ loc n} {x} co)
(λ a₂ → ba⇒aa⇒path n {a₂})
(λ b₂ → bb⇒ab⇒path n {b₂})
(λ _ → funext λ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _)
p₂
code⇒path : ∀ {p₁ p₂} → code p₁ p₂ → p₁ ≡₀ p₂
code⇒path {p₁} {p₂} = pushout-rec
(λ p₁ → code p₁ p₂ → p₁ ≡₀ p₂)
(λ a → ap⇒path {a} {p₂})
(λ b → bp⇒path {b} {p₂})
(loc-fiber-rec l
(λ c → transport (λ x → code x p₂ → x ≡₀ p₂) (glue c) (ap⇒path {f c} {p₂})
≡ bp⇒path {g c} {p₂})
⦃ λ c → →-is-set (π₀-is-set (right (g c) ≡ p₂)) _ _ ⦄
(λ n → funext λ (co : code (right $ g $ loc n) p₂) →
transport (λ x → code x p₂ → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}) co
≡⟨ trans-→ (λ x → code x p₂) (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}) co ⟩
transport (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}
$ transport (λ x → code x p₂) (! (glue $ loc n)) co)
≡⟨ ap (transport (λ x → x ≡₀ p₂) (glue $ loc n) ◯ ap⇒path {f $ loc n} {p₂})
$ trans-!glue-code-loc n {p₂} co ⟩
transport (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂} $ bp⇒ap n {p₂} co)
≡⟨ ap (transport (λ x → x ≡₀ p₂) (glue $ loc n)) $ bp⇒ap⇒path n {p₂} co ⟩
transport (λ x → x ≡₀ p₂) (glue $ loc n) (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co)
≡⟨ trans-id≡₀cst (glue $ loc n) (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co) ⟩
p!gl n ∘₀ (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co)
≡⟨ ! $ concat₀-assoc (p!gl n) (pgl n) (bp⇒path {g $ loc n} {p₂} co) ⟩
(p!gl n ∘₀ pgl n) ∘₀ bp⇒path {g $ loc n} {p₂} co
≡⟨ ap (λ x → proj x ∘₀ bp⇒path {g $ loc n} {p₂} co) $ opposite-left-inverse (glue $ loc n) ⟩
refl₀ ∘₀ bp⇒path {g $ loc n} {p₂} co
≡⟨ refl₀-left-unit (bp⇒path {g $ loc n} {p₂} co) ⟩∎
bp⇒path {g $ loc n} {p₂} co
∎))
p₁
| {
"alphanum_fraction": 0.4451162166,
"avg_line_length": 44.4358208955,
"ext": "agda",
"hexsha": "7edb9c4f2cfdc9bfbf4dde5d7937d2a11ea504be",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Homotopy/VanKampen/CodeToPath.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Homotopy/VanKampen/CodeToPath.agda",
"max_line_length": 114,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Homotopy/VanKampen/CodeToPath.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 7007,
"size": 14886
} |
module Example.Test where
open import Data.Maybe using (Is-just)
open import Prelude.Init
open import Prelude.DecEq
open import Prelude.Decidable
_ : (¬ ¬ ((true , true) ≡ (true , true)))
× (8 ≡ 18 ∸ 10)
_ = auto
| {
"alphanum_fraction": 0.6788990826,
"avg_line_length": 18.1666666667,
"ext": "agda",
"hexsha": "297ec924917c7b4592ce37d2904220649feb7942",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b987bcf8dbe1e1699405f26010273d562805258a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omelkonian/setup-agda",
"max_forks_repo_path": "Example/Test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b987bcf8dbe1e1699405f26010273d562805258a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omelkonian/setup-agda",
"max_issues_repo_path": "Example/Test.agda",
"max_line_length": 41,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "b987bcf8dbe1e1699405f26010273d562805258a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omelkonian/setup-agda",
"max_stars_repo_path": "Example/Test.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T19:15:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-11-14T12:25:39.000Z",
"num_tokens": 66,
"size": 218
} |
-- Export only the experiments that are expected to compile (without
-- any holes)
{-# OPTIONS --cubical --no-import-sorts #-}
module Cubical.Experiments.Everything where
open import Cubical.Experiments.Brunerie public
open import Cubical.Experiments.EscardoSIP public
open import Cubical.Experiments.Generic public
open import Cubical.Experiments.NatMinusTwo
open import Cubical.Experiments.Problem
open import Cubical.Experiments.FunExtFromUA public
open import Cubical.Experiments.HoTT-UF
open import Cubical.Experiments.Rng
| {
"alphanum_fraction": 0.8336483932,
"avg_line_length": 37.7857142857,
"ext": "agda",
"hexsha": "dc6b4fe94c74a0cca7002482eb15b84a02124e95",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Experiments/Everything.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Experiments/Everything.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Experiments/Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 126,
"size": 529
} |
module Web.URI.Port where
open import Web.URI.Port.Primitive public using ( Port? ; :80 ; ε )
| {
"alphanum_fraction": 0.7157894737,
"avg_line_length": 23.75,
"ext": "agda",
"hexsha": "91e445dcf3ee7d8874fbbb774cbd1896702a9147",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-uri",
"max_forks_repo_path": "src/Web/URI/Port.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-uri",
"max_issues_repo_path": "src/Web/URI/Port.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-uri",
"max_stars_repo_path": "src/Web/URI/Port.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-23T04:56:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-23T04:56:25.000Z",
"num_tokens": 24,
"size": 95
} |
{-# OPTIONS --experimental-irrelevance #-}
-- {-# OPTIONS -v tc:10 #-}
module ExplicitLambdaExperimentalIrrelevance where
postulate
A : Set
T : ..(x : A) -> Set -- shape irrelevant type
test : .(a : A) -> T a -> Set
test a = λ (x : T a) -> A
-- this should type check and not complain about irrelevance of a
module M .(a : A) where
-- should also work with module parameter
test1 : T a -> Set
test1 = λ (x : T a) -> A
| {
"alphanum_fraction": 0.6189376443,
"avg_line_length": 24.0555555556,
"ext": "agda",
"hexsha": "26901ac57be218ab8994072470d8a2e48f7ed75d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/ExplicitLambdaExperimentalIrrelevance.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/ExplicitLambdaExperimentalIrrelevance.agda",
"max_line_length": 65,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/ExplicitLambdaExperimentalIrrelevance.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 136,
"size": 433
} |
module Numeral.Integer where
open import Data.Tuple
open import Logic
import Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Relator.Equals
open import Type
open import Type.Quotient
-- Equivalence relation of difference equality.
-- Essentially (if one would already work in the integers):
-- (a₁ , a₂) diff-≡_ (b₁ , b₂)
-- ⇔ a₁ + b₂ ≡ a₂ + b₁
-- ⇔ a₁ − a₂ ≡ b₁ − b₂
_diff-≡_ : (ℕ ⨯ ℕ) → (ℕ ⨯ ℕ) → Stmt{Lvl.𝟎}
(a₁ , a₂) diff-≡ (b₁ , b₂) = (a₁ + b₂ ≡ a₂ + b₁)
ℤ : Type{Lvl.𝟎}
ℤ = (ℕ ⨯ ℕ) / (_diff-≡_)
| {
"alphanum_fraction": 0.6397058824,
"avg_line_length": 24.7272727273,
"ext": "agda",
"hexsha": "15f5b8482328f24cd6e534e179080d3f394b51c2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Mathematical/Numeral/Integer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Mathematical/Numeral/Integer.agda",
"max_line_length": 59,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Mathematical/Numeral/Integer.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 224,
"size": 544
} |
module hello-world where
open import IO
open import Data.String
open import Data.Nat
open import Data.Vec
main = run (putStrLn "Hello World!")
data Bool : Set where
true : Bool
false : Bool
if_then_else_ : {A : Set} → Bool → A → A → A
if true then x else y = x
if false then x else y = y
new : {A : Set} -> A -> A
new x = x
_plus_ : {A : Set} -> A -> A -> A
x plus y = x
vec : Vec Bool 1
vec = true ∷ []
| {
"alphanum_fraction": 0.6124401914,
"avg_line_length": 14.9285714286,
"ext": "agda",
"hexsha": "94c575b10ed1d5c93143f694c0e950da9f2bb2c5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "neosimsim/merkdas",
"max_forks_repo_path": "hello-agda/hello-world.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "neosimsim/merkdas",
"max_issues_repo_path": "hello-agda/hello-world.agda",
"max_line_length": 45,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "neosimsim/merkdas",
"max_stars_repo_path": "hello-agda/hello-world.agda",
"max_stars_repo_stars_event_max_datetime": "2020-05-26T08:08:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-26T08:08:13.000Z",
"num_tokens": 141,
"size": 418
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Rings.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Rings.Ideals.Principal.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} (R : Ring S _+_ _*_) where
open import Rings.Ideals.Definition R
open import Rings.Divisible.Definition R
open Setoid S
record PrincipalIdeal {c : _} {pred : A → Set c} (ideal : Ideal pred) : Set (a ⊔ b ⊔ c) where
field
generator : A
genIsInIdeal : pred generator
genGenerates : {x : A} → pred x → generator ∣ x
| {
"alphanum_fraction": 0.6650165017,
"avg_line_length": 31.8947368421,
"ext": "agda",
"hexsha": "1fe2042b2d0b2cf49ca638072ebbee573ee98ae7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Ideals/Principal/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Ideals/Principal/Definition.agda",
"max_line_length": 134,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Ideals/Principal/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 199,
"size": 606
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Structures.Bundles.Field
module Algebra.Linear.Morphism.Properties
{k ℓᵏ} (K : Field k ℓᵏ)
where
open import Level
open import Algebra.FunctionProperties as FP
import Algebra.Linear.Morphism.Definitions as LinearMorphismDefinitions
import Algebra.Morphism as Morphism
open import Relation.Binary using (Rel; Setoid)
open import Relation.Binary.Morphism.Structures
open import Algebra.Morphism
open import Algebra.Linear.Structures.VectorSpace K
open import Algebra.Linear.Structures.Bundles
module _
{a₁ ℓ₁} (From : VectorSpace K a₁ ℓ₁)
{a₂ ℓ₂} (To : VectorSpace K a₂ ℓ₂)
where
open import Algebra.Linear.Morphism.VectorSpace K
private
module F = VectorSpace From
module T = VectorSpace To
open VectorSpaceField
open F
using ()
renaming
( Carrier to A
; _≈_ to _≈₁_
; refl to ≈₁-refl
; sym to ≈₁-sym
; trans to ≈₁-trans
; setoid to setoid₁
; _+_ to _+₁_
; +-cong to +₁-cong
; +-identityˡ to +₁-identityˡ
; _∙_ to _∙₁_
; ∙-identity to ∙₁-identity
; ∙-absorbˡ to ∙₁-absorbˡ
; ∙-absorbʳ to ∙₁-absorbʳ
; 0# to 0₁
)
open T
using ()
renaming
( Carrier to B
; _≈_ to _≈₂_
; refl to ≈₂-refl
; sym to ≈₂-sym
; trans to ≈₂-trans
; setoid to setoid₂
; _+_ to _+₂_
; +-cong to +₂-cong
; +-identityˡ to +₂-identityˡ
; _∙_ to _∙₂_
; ∙-identity to ∙₂-identity
; ∙-absorbˡ to ∙₂-absorbˡ
; ∙-absorbʳ to ∙₂-absorbʳ
; 0# to 0₂
)
open import Function
open import Function.Equality
open LinearDefinitions (VectorSpace.Carrier From) (VectorSpace.Carrier To) _≈₂_
linear : ∀ (f : setoid₁ ⟶ setoid₂)
-> (∀ (a b : K') (u v : A) -> (f ⟨$⟩ (a ∙₁ u +₁ b ∙₁ v)) ≈₂ a ∙₂ (f ⟨$⟩ u) +₂ b ∙₂ (f ⟨$⟩ v))
-> IsLinearMap From To (f ⟨$⟩_)
linear f lin = record
{ isAbelianGroupMorphism = record
{ gp-homo = record
{ mn-homo = record
{ sm-homo = record
{ ⟦⟧-cong = cong f
; ∙-homo = λ x y →
begin
f ⟨$⟩ x +₁ y
≈⟨ cong f (+₁-cong (≈₁-sym (∙₁-identity x)) (≈₁-sym (∙₁-identity y))) ⟩
f ⟨$⟩ (1ᵏ ∙₁ x +₁ 1ᵏ ∙₁ y)
≈⟨ lin 1ᵏ 1ᵏ x y ⟩
1ᵏ ∙₂ (f ⟨$⟩ x) +₂ 1ᵏ ∙₂ (f ⟨$⟩ y)
≈⟨ +₂-cong (∙₂-identity (f ⟨$⟩ x)) (∙₂-identity (f ⟨$⟩ y)) ⟩
(f ⟨$⟩ x) +₂ (f ⟨$⟩ y)
∎
}
; ε-homo =
begin
f ⟨$⟩ 0₁
≈⟨ cong f (≈₁-trans (≈₁-sym (+₁-identityˡ 0₁)) (+₁-cong (≈₁-sym (∙₁-absorbˡ 0₁)) (≈₁-sym (∙₁-absorbˡ 0₁)))) ⟩
f ⟨$⟩ 0ᵏ ∙₁ 0₁ +₁ 0ᵏ ∙₁ 0₁
≈⟨ lin 0ᵏ 0ᵏ 0₁ 0₁ ⟩
0ᵏ ∙₂ (f ⟨$⟩ 0₁) +₂ 0ᵏ ∙₂ (f ⟨$⟩ 0₁)
≈⟨ ≈₂-trans (+₂-cong (∙₂-absorbˡ (f ⟨$⟩ 0₁)) (∙₂-absorbˡ (f ⟨$⟩ 0₁))) (+₂-identityˡ 0₂) ⟩
0₂
∎
}
}
}
; ∙-homo = λ c u →
begin
f ⟨$⟩ c ∙₁ u
≈⟨ cong f (≈₁-trans (≈₁-sym (+₁-identityˡ (c ∙₁ u))) (+₁-cong (≈₁-sym (∙₁-absorbˡ 0₁)) ≈₁-refl)) ⟩
f ⟨$⟩ 0ᵏ ∙₁ 0₁ +₁ c ∙₁ u
≈⟨ lin 0ᵏ c 0₁ u ⟩
0ᵏ ∙₂ (f ⟨$⟩ 0₁) +₂ c ∙₂ (f ⟨$⟩ u)
≈⟨ ≈₂-trans (+₂-cong (∙₂-absorbˡ (f ⟨$⟩ 0₁)) ≈₂-refl) (+₂-identityˡ (c ∙₂ (f ⟨$⟩ u))) ⟩
c ∙₂ (f ⟨$⟩ u)
∎
}
where open import Relation.Binary.EqReasoning setoid₂
| {
"alphanum_fraction": 0.4787204451,
"avg_line_length": 29.9583333333,
"ext": "agda",
"hexsha": "5b02abb01686366bb1fe19666fdbcf2a88f5432c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Morphism/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Morphism/Properties.agda",
"max_line_length": 121,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Morphism/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 1472,
"size": 3595
} |
module Issue408 where
open import Common.Prelude
open import Common.Equality
-- 1. Agda should prefer to split on an argument that covers
data Fin : Nat → Set where
zero : {n : Nat} → Fin (suc n)
suc : {n : Nat} → Fin n → Fin (suc n)
wk : {n : Nat} → Fin n → Fin (suc n)
wk zero = zero
wk (suc n) = suc (wk n)
predFin : (n : Nat) → Fin n → Fin n
predFin (suc n) zero = zero
predFin (suc n) (suc i) = wk i
-- predFin should be covering
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
_∷_ : {n : Nat} (x : A) (xs : Vec A n) → Vec A (suc n)
_!!_ : {A : Set}{n : Nat} → Vec A n → Fin n → A
(x ∷ xs) !! zero = x
(x ∷ xs) !! (suc i) = xs !! i
-- should be covering, no need for absurd clause
test!!1 : ∀ {A}{n} (x : A) (xs : Vec A n) → (x ∷ xs) !! zero ≡ x
test!!1 x xs = refl
test!!2 : ∀ {A}{n} (x : A) (xs : Vec A n) i → (x ∷ xs) !! (suc i) ≡ xs !! i
test!!2 x xs i = refl
-- 2. Agda should prefer to split on an argument that has only
-- constructor patterns. For max below, split on 2nd, then on 1st.
max : Nat → Nat → Nat
max (suc n) (suc m) = suc (max n m)
max 0 (suc m) = suc m
max n 0 = n
testmax1 : {n m : Nat} → max (suc n) (suc m) ≡ suc (max n m)
testmax1 = refl
testmax2 : {m : Nat} → max 0 (suc m) ≡ suc m
testmax2 = refl
{- DOES NOT WORK YET
testmax3 : {n : Nat} → max n 0 ≡ n
testmax3 = refl
-- equation should hold definitionally
-}
| {
"alphanum_fraction": 0.5598290598,
"avg_line_length": 25.0714285714,
"ext": "agda",
"hexsha": "64b2ebbfbf64a6ed99a08b8567e79aad15f42030",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue408.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue408.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue408.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 561,
"size": 1404
} |
module Extensions.Bool where
open import Data.Unit
open import Data.Bool
open import Relation.Nullary public using (yes; no; ¬_; Dec)
data All {p} (P : Set p) : Bool → Set p where
true : P → All P true
false : All P false
data Any {p} (P : Set p) : Bool → Set p where
true : P → Any P true
all-map : ∀ {p} {P Q : Set p} {b} → All P b → (f : P → Q) → All Q b
all-map (true x) f = true (f x)
all-map false f = false
Is-true : Bool → Set
Is-true t = Any ⊤ t
is-yes : ∀ {a} {A : Set a} → Dec A → Bool
is-yes (yes p) = true
is-yes (no ¬p) = false
| {
"alphanum_fraction": 0.5917266187,
"avg_line_length": 23.1666666667,
"ext": "agda",
"hexsha": "c61b2d14567d7a7cb3f20404e8bca8a3c1ae1bef",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Extensions/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Extensions/Bool.agda",
"max_line_length": 67,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Extensions/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 207,
"size": 556
} |
{-# OPTIONS --erased-cubical #-}
-- Modules that use --cubical can be imported when --erased-cubical is
-- used.
open import Erased-cubical-Import.Cubical
-- However, definitions from such modules can only be used in erased
-- contexts.
_ : {A : Set} → A → ∥ A ∥
_ = ∣_∣
| {
"alphanum_fraction": 0.6690909091,
"avg_line_length": 21.1538461538,
"ext": "agda",
"hexsha": "01e44f0f7202e3ce0d63e00259303dee611682dd",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Erased-cubical-Import.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Erased-cubical-Import.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Erased-cubical-Import.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 86,
"size": 275
} |
module CTL.Modalities.EN where
open import FStream.Core
open import Library
-- Eventually (in) Next : p ⊧ φ ⇔ ∃ p[1] ⊧ φ
EN' : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} → FStream' C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)
EN' s = EPred head (inF (tail s))
EN : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} → FStream C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)
EN s = EPred EN' (inF s)
mutual
EN'ₛ : ∀ {i} {ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream' C (Set ℓ₂) → FStream' {i} C (Set (ℓ₁ ⊔ ℓ₂))
head (EN'ₛ props) = EN' props
tail (EN'ₛ props) = ENₛ (tail props)
ENₛ : ∀ {i} {ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → FStream {i} C (Set (ℓ₁ ⊔ ℓ₂))
inF (ENₛ props) = fmap EN'ₛ (inF props)
| {
"alphanum_fraction": 0.5635528331,
"avg_line_length": 29.6818181818,
"ext": "agda",
"hexsha": "e898ebe35cdd02d6dc8491a4d4372c7781b23d2e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "zimbatm/condatis",
"max_forks_repo_path": "CTL/Modalities/EN.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "zimbatm/condatis",
"max_issues_repo_path": "CTL/Modalities/EN.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Aerate/condatis",
"max_stars_repo_path": "CTL/Modalities/EN.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z",
"num_tokens": 318,
"size": 653
} |
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Dec where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Relation.Nullary using (Dec)
open import Relation.Binary using (REL)
DecRel : {a b ℓ : Level} {A : Set a} {B : Set b}
→ REL A B ℓ → Set (a ⊔ b ⊔ ℓ)
DecRel R = ∀ x y → Dec (R x y)
| {
"alphanum_fraction": 0.6297468354,
"avg_line_length": 22.5714285714,
"ext": "agda",
"hexsha": "05d74f515655fe07fee54a2db2c56e2ebe305f79",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Dec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Dec.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Dec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 105,
"size": 316
} |
{-# OPTIONS --cubical --prop #-}
module Issue2487-2 where
import Issue2487.Infective
| {
"alphanum_fraction": 0.7325581395,
"avg_line_length": 17.2,
"ext": "agda",
"hexsha": "62e16f69b8736ac2d196360131f9a09cb07b7234",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue2487-2.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2487-2.agda",
"max_line_length": 32,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2487-2.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 25,
"size": 86
} |
module #2 where
open import Relation.Binary.PropositionalEquality
open import #1
{-
Exercise 2.2. Show that the three equalities of proofs constructed in the previous exercise form a
commutative triangle. In other words, if the three definitions of concatenation are denoted by
(p ∘ q), (p ∘ q), and (p ∘ q), then the concatenated equality
(p ∘ q) = (p ∘ q) = (p ∘ q)
is equal to the equality (p ∘ q) = (p ∘ q).
-}
composite-commutative-triangle : ∀ {i} {A : Set i}{x y z : A} → (p : x ≡ y) (q : y ≡ z) →
composite (composite=composite' p q) (composite'=composite'' p q) ≡ composite=composite'' p q
composite-commutative-triangle refl refl = refl
| {
"alphanum_fraction": 0.6701649175,
"avg_line_length": 35.1052631579,
"ext": "agda",
"hexsha": "b81a6e006cbc00faaa85a4a6ec3bdf2b9d9a1146",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter2/#2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter2/#2.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter2/#2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 208,
"size": 667
} |
{-# OPTIONS --without-K #-}
open import HoTT
{- Useful lemmas for computing the effect of transporting a function
- across an equivalence in the domain or codomain.
- TODO: find a better place for this. -}
module cohomology.FunctionOver where
{- transporting a function along an equivalence or path in the domain -}
module _ {i} {j} {B : Type i} {C : Type j} (g : B → C) where
domain-over-path : {A : Type i} (p : A == B)
→ g ∘ coe p == g [ (λ D → (D → C)) ↓ p ]
domain-over-path idp = idp
domain-over-equiv : {A : Type i} (e : A ≃ B)
→ g ∘ –> e == g [ (λ D → (D → C)) ↓ ua e ]
domain-over-equiv e = ↓-app→cst-in $ λ q → ap g (↓-idf-ua-out e q)
module _ {i} {j} {A : Type i} {C : Type j} (f : A → C) where
domain!-over-path : {B : Type i} (p : A == B)
→ f == f ∘ coe! p [ (λ D → (D → C)) ↓ p ]
domain!-over-path idp = idp
domain!-over-equiv : {B : Type i} (e : A ≃ B)
→ f == f ∘ <– e [ (λ D → (D → C)) ↓ ua e ]
domain!-over-equiv e = ↓-app→cst-in $
λ q → ap f (! (<–-inv-l e _) ∙ ap (<– e) (↓-idf-ua-out e q))
{- transporting a ptd function along a equivalence or path in the domain -}
module _ {i} {j} {Y : Ptd i} {Z : Ptd j} (g : fst (Y ⊙→ Z)) where
domain-over-⊙path : {X : Ptd i} (p : fst X == fst Y)
(q : coe p (snd X) == snd Y)
→ g ⊙∘ (coe p , q) == g [ (λ W → fst (W ⊙→ Z)) ↓ pair= p (↓-idf-in p q) ]
domain-over-⊙path idp idp = idp
domain-over-⊙equiv : {X : Ptd i} (e : X ⊙≃ Y)
→ g ⊙∘ ⊙–> e == g [ (λ W → fst (W ⊙→ Z)) ↓ ⊙ua e ]
domain-over-⊙equiv {X = X} e =
ap (λ w → g ⊙∘ w) (! $ ⊙λ= (coe-β (⊙≃-to-≃ e)) idp)
◃ domain-over-⊙path (ua (⊙≃-to-≃ e))
(coe-β (⊙≃-to-≃ e) (snd X) ∙ snd (⊙–> e))
module _ {i} {j} {X : Ptd i} {Z : Ptd j} (f : fst (X ⊙→ Z)) where
domain!-over-⊙path : {Y : Ptd i} (p : fst X == fst Y)
(q : coe p (snd X) == snd Y)
→ f == f ⊙∘ (coe! p , ap (coe! p) (! q) ∙ coe!-inv-l p (snd X))
[ (λ W → fst (W ⊙→ Z)) ↓ pair= p (↓-idf-in p q) ]
domain!-over-⊙path idp idp = idp
domain!-over-⊙equiv : {Y : Ptd i} (e : X ⊙≃ Y)
→ f == f ⊙∘ (⊙<– e) [ (λ W → fst (W ⊙→ Z)) ↓ ⊙ua e ]
domain!-over-⊙equiv {Y = Y} e =
(! (ap (λ w → f ⊙∘ w) (⊙<–-inv-l e)) ∙ ! (⊙∘-assoc f _ (⊙–> e)))
◃ domain-over-⊙equiv (f ⊙∘ (⊙<– e)) e
{- transporting a function along an equivalence or path in the codomain -}
module _ {i} {j} {A : Type i} {B : Type j} (f : A → B) where
codomain-over-path : {C : Type j} (p : B == C)
→ f == coe p ∘ f [ (λ D → (A → D)) ↓ p ]
codomain-over-path idp = idp
codomain-over-equiv : {C : Type j} (e : B ≃ C)
→ f == –> e ∘ f [ (λ D → (A → D)) ↓ ua e ]
codomain-over-equiv e = ↓-cst→app-in $ λ _ → ↓-idf-ua-in e idp
module _ {i} {j} {A : Type i} {C : Type j} (g : A → C) where
codomain!-over-path : {B : Type j} (p : B == C)
→ coe! p ∘ g == g [ (λ D → (A → D)) ↓ p ]
codomain!-over-path idp = idp
codomain!-over-equiv : {B : Type j} (e : B ≃ C)
→ <– e ∘ g == g [ (λ D → (A → D)) ↓ ua e ]
codomain!-over-equiv e = ↓-cst→app-in $ λ _ → ↓-idf-ua-in e (<–-inv-r e _)
{- transporting a ptd function along a equivalence or path in the codomain -}
module _ {i} {j} {X : Ptd i} {Y : Ptd j} (f : fst (X ⊙→ Y)) where
codomain-over-⊙path : {Z : Ptd j} (p : fst Y == fst Z)
(q : coe p (snd Y) == snd Z)
→ f == (coe p , q) ⊙∘ f [ (λ W → fst (X ⊙→ W)) ↓ pair= p (↓-idf-in p q) ]
codomain-over-⊙path idp idp = pair= idp (! (∙-unit-r _ ∙ ap-idf (snd f)))
codomain-over-⊙equiv : {Z : Ptd j} (e : Y ⊙≃ Z)
→ f == (⊙–> e) ⊙∘ f [ (λ W → fst (X ⊙→ W)) ↓ ⊙ua e ]
codomain-over-⊙equiv {Z = Z} e =
codomain-over-⊙path (ua (⊙≃-to-≃ e))
(coe-β (⊙≃-to-≃ e) (snd Y) ∙ snd (⊙–> e))
▹ ap (λ w → w ⊙∘ f) (⊙λ= (coe-β (⊙≃-to-≃ e)) idp)
module _ {i} {j} {X : Ptd i} {Z : Ptd j} (g : fst (X ⊙→ Z)) where
codomain!-over-⊙path : {Y : Ptd j} (p : fst Y == fst Z)
(q : coe p (snd Y) == snd Z)
→ (coe! p , ap (coe! p) (! q) ∙ coe!-inv-l p (snd Y)) ⊙∘ g == g
[ (λ W → fst (X ⊙→ W)) ↓ pair= p (↓-idf-in p q) ]
codomain!-over-⊙path idp idp = pair= idp (∙-unit-r _ ∙ ap-idf (snd g))
codomain!-over-⊙equiv : {Y : Ptd j} (e : Y ⊙≃ Z)
→ (⊙<– e) ⊙∘ g == g [ (λ W → fst (X ⊙→ W)) ↓ ⊙ua e ]
codomain!-over-⊙equiv {Y = Y} e =
codomain-over-⊙equiv (⊙<– e ⊙∘ g) e
▹ ! (⊙∘-assoc (⊙–> e) _ g) ∙ ap (λ w → w ⊙∘ g) (⊙<–-inv-r e) ∙ ⊙∘-unit-l g
module _ {i j} where
function-over-paths : {A₁ B₁ : Type i} {A₂ B₂ : Type j}
{f : A₁ → A₂} {g : B₁ → B₂} (p₁ : A₁ == B₁) (p₂ : A₂ == B₂)
→ coe p₂ ∘ f == g ∘ coe p₁
→ f == g [ (λ {(A , B) → A → B}) ↓ pair×= p₁ p₂ ]
function-over-paths idp idp α = α
function-over-equivs : {A₁ B₁ : Type i} {A₂ B₂ : Type j}
{f : A₁ → A₂} {g : B₁ → B₂} (e₁ : A₁ ≃ B₁) (e₂ : A₂ ≃ B₂)
→ –> e₂ ∘ f == g ∘ –> e₁
→ f == g [ (λ {(A , B) → A → B}) ↓ pair×= (ua e₁) (ua e₂) ]
function-over-equivs {f = f} {g = g} e₁ e₂ α =
function-over-paths (ua e₁) (ua e₂) $
transport (λ {(h , k) → h ∘ f == g ∘ k})
(pair×= (! (λ= (coe-β e₂))) (! (λ= (coe-β e₁)))) α
{- transporting a group homomorphism along an isomorphism -}
domain-over-iso : ∀ {i j} {G H : Group i} {K : Group j}
{φ : G →ᴳ H} {ie : is-equiv (GroupHom.f φ)} {ψ : G →ᴳ K} {χ : H →ᴳ K}
→ GroupHom.f ψ == GroupHom.f χ
[ (λ A → A → Group.El K) ↓ ua (GroupHom.f φ , ie) ]
→ ψ == χ [ (λ J → J →ᴳ K) ↓ group-ua (φ , ie) ]
domain-over-iso {K = K} {φ = φ} {ie} {ψ} {χ} p =
hom=-↓ _ _ $ ↓-ap-out _ Group.El _ $
transport
(λ q → GroupHom.f ψ == GroupHom.f χ [ (λ A → A → Group.El K) ↓ q ])
(! (group-ua-el (φ , ie)))
p
codomain-over-iso : ∀ {i j} {G : Group i} {H K : Group j}
{φ : H →ᴳ K} {ie : is-equiv (GroupHom.f φ)} {ψ : G →ᴳ H} {χ : G →ᴳ K}
→ GroupHom.f ψ == GroupHom.f χ
[ (λ A → Group.El G → A) ↓ ua (GroupHom.f φ , ie) ]
→ ψ == χ [ (λ J → G →ᴳ J) ↓ group-ua (φ , ie) ]
codomain-over-iso {G = G} {φ = φ} {ie} {ψ} {χ} p =
hom=-↓ _ _ $ ↓-ap-out _ Group.El _ $
transport
(λ q → GroupHom.f ψ == GroupHom.f χ [ (λ A → Group.El G → A) ↓ q ])
(! (group-ua-el (φ , ie)))
p
hom-over-isos : ∀ {i j} {G₁ H₁ : Group i} {G₂ H₂ : Group j}
{φ₁ : G₁ →ᴳ H₁} {ie₁ : is-equiv (GroupHom.f φ₁)}
{φ₂ : G₂ →ᴳ H₂} {ie₂ : is-equiv (GroupHom.f φ₂)}
{ψ : G₁ →ᴳ G₂} {χ : H₁ →ᴳ H₂}
→ GroupHom.f ψ == GroupHom.f χ
[ (λ {(A , B) → A → B}) ↓ pair×= (ua (GroupHom.f φ₁ , ie₁))
(ua (GroupHom.f φ₂ , ie₂)) ]
→ ψ == χ [ uncurry _→ᴳ_ ↓ pair×= (group-ua (φ₁ , ie₁)) (group-ua (φ₂ , ie₂)) ]
hom-over-isos {φ₁ = φ₁} {ie₁} {φ₂} {ie₂} {ψ} {χ} p = hom=-↓ _ _ $
↓-ap-out (λ {(A , B) → A → B}) (λ {(G , H) → (Group.El G , Group.El H)}) _ $
transport
(λ q → GroupHom.f ψ == GroupHom.f χ [ (λ {(A , B) → A → B}) ↓ q ])
(ap2 (λ p q → pair×= p q) (! (group-ua-el (φ₁ , ie₁)))
(! (group-ua-el (φ₂ , ie₂)))
∙ ! (lemma Group.El Group.El
(group-ua (φ₁ , ie₁)) (group-ua (φ₂ , ie₂))))
p
where
lemma : ∀ {i j k l} {A : Type i} {B : Type j} {C : Type k} {D : Type l}
(f : A → C) (g : B → D) {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap (λ {(a , b) → (f a , g b)}) (pair×= p q)
== pair×= (ap f p) (ap g q)
lemma f g idp idp = idp
| {
"alphanum_fraction": 0.4569966814,
"avg_line_length": 40.6292134831,
"ext": "agda",
"hexsha": "9e2b503890a0c64413c1047d9bdf6551d2b3aa46",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "cohomology/FunctionOver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "cohomology/FunctionOver.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "cohomology/FunctionOver.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 3373,
"size": 7232
} |
module Numeral.PositiveInteger.Oper.Proofs where
open import Functional
open import Function.Equals
open import Function.Iteration
open import Function.Iteration.Proofs
open import Logic.Propositional
open import Logic.Predicate
import Numeral.Natural as ℕ
import Numeral.Natural.Oper as ℕ
open import Numeral.PositiveInteger
open import Numeral.PositiveInteger.Oper
open import Relator.Equals
open import Relator.Equals.Proofs
import Function.Names as Names
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Multi
open import Structure.Operator
open import Structure.Operator.Monoid
import Structure.Operator.Names as Names
open import Structure.Operator.Proofs.Util
open import Structure.Operator.Proofs
open import Structure.Operator.Properties
open import Syntax.Transitivity
open import Type
-- TODO: Move stuff related to ℕ₊-to-ℕ
instance
ℕ-ℕ₊-preserves-𝐒 : Preserving₁(ℕ₊-to-ℕ)(𝐒)(ℕ.𝐒)
Preserving.proof ℕ-ℕ₊-preserves-𝐒 = p where
p : Names.Preserving₁(ℕ₊-to-ℕ)(𝐒)(ℕ.𝐒)
p {𝟏} = [≡]-intro
p {𝐒 x} = congruence₁(ℕ.𝐒) p
instance
ℕ-ℕ₊-preserves-[+] : Preserving₂(ℕ₊-to-ℕ)(_+_)(ℕ._+_)
Preserving.proof ℕ-ℕ₊-preserves-[+] = p where
p : Names.Preserving₂(ℕ₊-to-ℕ)(_+_)(ℕ._+_)
p {x} {𝟏} = [≡]-intro
p {x} {𝐒 y} = congruence₁(ℕ.𝐒) p
instance
ℕ-ℕ₊-preserves-[⋅] : Preserving₂(ℕ₊-to-ℕ)(_⋅_)(ℕ._⋅_)
Preserving.proof ℕ-ℕ₊-preserves-[⋅] {x}{y} = p{x}{y} where
p : Names.Preserving₂(ℕ₊-to-ℕ)(_⋅_)(ℕ._⋅_)
p {x} {𝟏} = [≡]-intro
p {x} {𝐒 y} =
ℕ₊-to-ℕ (x + (x ⋅ y)) 🝖[ _≡_ ]-[ preserving₂(ℕ₊-to-ℕ)(_+_)(ℕ._+_) ]
(ℕ₊-to-ℕ x) ℕ.+ (ℕ₊-to-ℕ (x ⋅ y)) 🝖[ _≡_ ]-[ congruence₁((ℕ₊-to-ℕ x) ℕ.+_) (p{x}{y}) ]
(ℕ₊-to-ℕ x) ℕ.+ ((ℕ₊-to-ℕ x) ℕ.⋅ (ℕ₊-to-ℕ y)) 🝖[ _≡_ ]-end
instance
𝐒-from-ℕ-preserves-𝐒 : Preserving₁(𝐒-from-ℕ)(ℕ.𝐒)(𝐒)
Preserving.proof 𝐒-from-ℕ-preserves-𝐒 = [≡]-intro
instance
𝐒-from-ℕ-preserves-[+] : Preserving₂(𝐒-from-ℕ)(ℕ.𝐒 ∘₂ ℕ._+_)(_+_)
Preserving.proof 𝐒-from-ℕ-preserves-[+] = p where
p : Names.Preserving₂(𝐒-from-ℕ)(ℕ.𝐒 ∘₂ ℕ._+_)(_+_)
p {x}{ℕ.𝟎} = [≡]-intro
p {x}{ℕ.𝐒 y} = congruence₁(𝐒) (p {x}{y})
{-instance
𝐒-from-ℕ-preserves-[⋅] : Preserving₂(𝐒-from-ℕ)(ℕ.𝐒 ∘₂ ℕ._⋅_ )(_⋅_)
Preserving.proof 𝐒-from-ℕ-preserves-[⋅] = p where
p : Names.Preserving₂(𝐒-from-ℕ)(ℕ.𝐒 ∘₂ ℕ._⋅_ )(_⋅_)
p {x}{ℕ.𝟎} = {!!}
p {x}{ℕ.𝐒 y} = {!!}
-}
{- 𝐒-from-ℕ (ℕ.𝐒(x ℕ.+ (x ℕ.⋅ ℕ.𝐒(y)))) 🝖[ _≡_ ]-[ preserving₂(𝐒-from-ℕ)(ℕ.𝐒 ∘₂ ℕ._+_)(_+_) ]
(𝐒-from-ℕ x) + (𝐒-from-ℕ (x ℕ.⋅ ℕ.𝐒(y))) 🝖[ _≡_ ]-[]
(𝐒-from-ℕ x) + (𝐒-from-ℕ (x ℕ.+ (x ℕ.⋅ y))) 🝖[ _≡_ ]-[ congruence₁((𝐒-from-ℕ x) +_) (p{x}{y}) ]
(𝐒-from-ℕ x) + ((𝐒-from-ℕ x) ⋅ (𝐒-from-ℕ y)) 🝖[ _≡_ ]-end
-}
{-
instance
ℕ₊-to-ℕ-injective : Injective(ℕ₊-to-ℕ)
Injective.proof ℕ₊-to-ℕ-injective {𝟏} {𝟏} p = [≡]-intro
Injective.proof ℕ₊-to-ℕ-injective {𝟏} {𝐒 y} p = {!congruence₁(\x → ℕ-to-ℕ₊ x ⦃ ? ⦄) p!}
Injective.proof ℕ₊-to-ℕ-injective {𝐒 x} {𝟏} p = {!preserving₁(ℕ₊-to-ℕ)(𝐒)(ℕ.𝐒) 🝖 p!}
Injective.proof ℕ₊-to-ℕ-injective {𝐒 x} {𝐒 y} p = {!!}
-}
{-
module _ where
[+]-repeatᵣ-𝐒 : ∀{x y z : ℕ} → (x + y ≡ repeatᵣ y (const 𝐒) z x)
[+]-repeatᵣ-𝐒 {x} {𝟎} = [≡]-intro
[+]-repeatᵣ-𝐒 {x} {𝐒 y} {z} = congruence₁(𝐒) ([+]-repeatᵣ-𝐒 {x} {y} {z})
[+]-repeatₗ-𝐒 : ∀{x y z : ℕ} → (x + y ≡ repeatₗ y (const ∘ 𝐒) x z)
[+]-repeatₗ-𝐒 {x} {𝟎} = [≡]-intro
[+]-repeatₗ-𝐒 {x} {𝐒 y} {z} = congruence₁(𝐒) ([+]-repeatₗ-𝐒 {x} {y} {z})
[⋅]-repeatᵣ-[+] : ∀{x y} → (x ⋅ y ≡ repeatᵣ y (_+_) x 0)
[⋅]-repeatᵣ-[+] {x} {𝟎} = [≡]-intro
[⋅]-repeatᵣ-[+] {x} {𝐒 y} = congruence₁(x +_) ([⋅]-repeatᵣ-[+] {x} {y})
[^]-repeatᵣ-[⋅] : ∀{x y} → (x ^ y ≡ repeatᵣ y (_⋅_) x 1)
[^]-repeatᵣ-[⋅] {x} {𝟎} = [≡]-intro
[^]-repeatᵣ-[⋅] {x} {𝐒 y} = congruence₁(x ⋅_) ([^]-repeatᵣ-[⋅] {x} {y})
-}
instance
[𝐒]-injective : Injective(𝐒)
Injective.proof [𝐒]-injective [≡]-intro = [≡]-intro
[1+]-𝐒 : ∀{x : ℕ₊} → (𝟏 + x ≡ 𝐒(x))
[1+]-𝐒 {𝟏} = [≡]-intro
[1+]-𝐒 {𝐒 x} = congruence₁(𝐒) ([1+]-𝐒 {x})
{-# REWRITE [1+]-𝐒 #-}
[+]-step : ∀{x y : ℕ₊} → (𝐒(x) + y) ≡ (x + 𝐒(y))
[+]-step {x} {𝟏} = [≡]-intro
[+]-step {x} {𝐒 y} = congruence₁(𝐒) ([+]-step {x} {y})
{-# REWRITE [+]-step #-}
[+]-commutativity-raw : Names.Commutativity(_+_)
[+]-commutativity-raw {𝟏} {𝟏} = [≡]-intro
[+]-commutativity-raw {𝟏} {𝐒 y} = congruence₁(𝐒) ([+]-commutativity-raw {𝟏} {y})
[+]-commutativity-raw {𝐒 x} {𝟏} = congruence₁(𝐒) ([+]-commutativity-raw {x} {𝟏})
[+]-commutativity-raw {𝐒 x} {𝐒 y} = congruence₁(𝐒) (congruence₁(𝐒) ([+]-commutativity-raw {x} {y}))
instance
[+]-commutativity : Commutativity(_+_)
[+]-commutativity = intro [+]-commutativity-raw
[+]-associativity-raw : Names.Associativity(_+_)
[+]-associativity-raw {x} {y} {𝟏} = [≡]-intro
[+]-associativity-raw {x} {y} {𝐒 z} = congruence₁(𝐒) ([+]-associativity-raw {x} {y} {z})
instance
[+]-associativity : Associativity(_+_)
[+]-associativity = intro [+]-associativity-raw
[⋅]-identityₗ-raw : Names.Identityₗ(_⋅_)(𝟏)
[⋅]-identityₗ-raw {𝟏} = [≡]-intro
[⋅]-identityₗ-raw {𝐒 x} = congruence₁(𝐒) ([⋅]-identityₗ-raw {x}) -- commutativity(_+_) 🝖 congruence₁(𝐒) ([⋅]-identityₗ-raw {x})
{-# REWRITE [⋅]-identityₗ-raw #-}
[⋅]-identityᵣ-raw : Names.Identityᵣ(_⋅_)(𝟏)
[⋅]-identityᵣ-raw = [≡]-intro
instance
[⋅]-identityₗ : Identityₗ(_⋅_)(𝟏)
[⋅]-identityₗ = intro [⋅]-identityₗ-raw
instance
[⋅]-identityᵣ : Identityᵣ(_⋅_)(𝟏)
[⋅]-identityᵣ = intro [⋅]-identityᵣ-raw
instance
[⋅]-identity : Identity(_⋅_)(𝟏)
[⋅]-identity = intro
[⋅]-commutativity-raw : Names.Commutativity(_⋅_) -- TODO: Extract the proof of (x + (𝐒 x + 𝐒 y) ≡ y + (𝐒 x + 𝐒 y)). Note that the properties here can probably also be proven using Function.Repeat.Proofs
[⋅]-commutativity-raw {x} {𝟏} = [≡]-intro
[⋅]-commutativity-raw {𝟏} {𝐒 y} = [≡]-intro
[⋅]-commutativity-raw {𝐒 x} {𝐒 y} =
𝐒 x ⋅ 𝐒 y 🝖[ _≡_ ]-[]
𝐒 x + (𝐒 x ⋅ y) 🝖-[ congruence₁(𝐒) (congruence₂ᵣ(_+_)(x) ([⋅]-commutativity-raw {𝐒 x} {y})) ]
𝐒 x + (y ⋅ 𝐒 x) 🝖[ _≡_ ]-[]
𝐒 x + (y ⋅ 𝐒 x) 🝖[ _≡_ ]-[]
𝐒 x + (y + (y ⋅ x)) 🝖-[ congruence₁(𝐒) (associativity(_+_)) ]-sym
(𝐒 x + y) + (y ⋅ x) 🝖[ _≡_ ]-[]
𝐒(x + y) + (y ⋅ x) 🝖-[ congruence₁(𝐒) (congruence₂(_+_) ([+]-commutativity-raw {x}{y}) ([⋅]-commutativity-raw {y}{x})) ]
𝐒(y + x) + (x ⋅ y) 🝖[ _≡_ ]-[]
(𝐒 y + x) + (x ⋅ y) 🝖-[ congruence₁(𝐒) (associativity(_+_)) ]
𝐒 y + (x + (x ⋅ y)) 🝖[ _≡_ ]-[]
𝐒 y + (x ⋅ 𝐒 y) 🝖-[ congruence₁(𝐒) (congruence₂ᵣ(_+_)(y) ([⋅]-commutativity-raw {𝐒 y} {x})) ]-sym
𝐒 y + (𝐒 y ⋅ x) 🝖[ _≡_ ]-[]
𝐒 y ⋅ 𝐒 x 🝖-end
instance
[⋅]-commutativity : Commutativity(_⋅_)
[⋅]-commutativity = intro(\{x}{y} → [⋅]-commutativity-raw {x}{y})
[⋅][+]-distributivityᵣ-raw : Names.Distributivityᵣ(_⋅_)(_+_)
[⋅][+]-distributivityᵣ-raw {x} {y} {𝟏} = [≡]-intro
[⋅][+]-distributivityᵣ-raw {x} {y} {𝐒 z} =
(x + y) + ((x + y) ⋅ z) 🝖[ _≡_ ]-[ congruence₁((x + y) +_) ([⋅][+]-distributivityᵣ-raw {x} {y} {z}) ]
(x + y) + ((x ⋅ z) + (y ⋅ z)) 🝖[ _≡_ ]-[ One.associate-commute4 {a = x}{y}{x ⋅ z}{y ⋅ z} ([+]-commutativity-raw{x = y}) ]
(x + (x ⋅ z)) + (y + (y ⋅ z)) 🝖[ _≡_ ]-[]
(x ⋅ 𝐒(z)) + (y ⋅ 𝐒(z)) 🝖[ _≡_ ]-end
instance
[⋅][+]-distributivityᵣ : Distributivityᵣ(_⋅_)(_+_)
[⋅][+]-distributivityᵣ = intro(\{x}{y}{z} → [⋅][+]-distributivityᵣ-raw {x}{y}{z})
instance
[⋅][+]-distributivityₗ : Distributivityₗ(_⋅_)(_+_)
[⋅][+]-distributivityₗ = [↔]-to-[←] OneTypeTwoOp.distributivity-equivalence-by-commutativity [⋅][+]-distributivityᵣ
[⋅]-associativity-raw : Names.Associativity(_⋅_)
[⋅]-associativity-raw {x} {y} {𝟏} = [≡]-intro
[⋅]-associativity-raw {x} {y} {𝐒 z} =
(x ⋅ y) + (x ⋅ y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x ⋅ y) ([⋅]-associativity-raw {x}{y}{z}) ]
(x ⋅ y) + (x ⋅ (y ⋅ z)) 🝖[ _≡_ ]-[ distributivityₗ(_⋅_)(_+_) {x = x}{y = y}{z = y ⋅ z} ]-sym
x ⋅ (y + (y ⋅ z)) 🝖-end
instance
[⋅]-associativity : Associativity(_⋅_)
[⋅]-associativity = intro(\{x}{y}{z} → [⋅]-associativity-raw {x}{y}{z})
instance
ℕ₊-multiplicative-monoid : Monoid(_⋅_)
Monoid.binary-operator ℕ₊-multiplicative-monoid = [≡]-binary-operator
Monoid.identity-existence ℕ₊-multiplicative-monoid = [∃]-intro(𝟏)
[⋅]-with-[𝐒]ₗ : ∀{x y} → (𝐒(x) ⋅ y ≡ (x ⋅ y) + y)
[⋅]-with-[𝐒]ₗ {x}{y} =
𝐒(x) ⋅ y 🝖[ _≡_ ]-[ congruence₁(_⋅ y) [1+]-𝐒 ]-sym
(x + 𝟏) ⋅ y 🝖[ _≡_ ]-[ [⋅][+]-distributivityᵣ-raw{x}{𝟏}{y} ]
(x ⋅ y) + (𝟏 ⋅ y) 🝖[ _≡_ ]-[ congruence₁((x ⋅ y) +_) ([⋅]-identityₗ-raw {y}) ]
(x ⋅ y) + y 🝖[ _≡_ ]-end
[⋅]-with-[𝐒]ᵣ : ∀{x y} → (x ⋅ 𝐒(y) ≡ x + (x ⋅ y))
[⋅]-with-[𝐒]ᵣ = [≡]-intro
| {
"alphanum_fraction": 0.5412323373,
"avg_line_length": 38.8918918919,
"ext": "agda",
"hexsha": "4e8ff48b5964bd7f6e5d19a9228ffb6091a1b928",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/PositiveInteger/Oper/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/PositiveInteger/Oper/Proofs.agda",
"max_line_length": 202,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/PositiveInteger/Oper/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 4695,
"size": 8634
} |
-- Andreas, 2017-01-26, issue #2436
-- Outlaw coinductive records with eta-equality
record U : Set where
coinductive
eta-equality
field f : U
-- Infinite eta-expansion would make Agda loop
test : U
test = _
| {
"alphanum_fraction": 0.712962963,
"avg_line_length": 16.6153846154,
"ext": "agda",
"hexsha": "ac729440bfefc8d96e5df889ec67d542c96772d6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2436.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2436.agda",
"max_line_length": 47,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2436.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 68,
"size": 216
} |
module Isos.Isomorphism where
open import Logics.And public
| {
"alphanum_fraction": 0.8360655738,
"avg_line_length": 15.25,
"ext": "agda",
"hexsha": "34652779581fa0b66b80f0c72ca7bd511fe08233",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Isos/Isomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Isos/Isomorphism.agda",
"max_line_length": 29,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Isos/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 15,
"size": 61
} |
{-
- Prelude: Play with some basic theorems...
-}
{-# OPTIONS --rewriting #-}
module Prelude where
open import Agda.Builtin.Equality public
open import Agda.Builtin.Nat renaming (Nat to ℕ) public
{-# BUILTIN REWRITE _≡_ #-}
-- Identity function
id : ∀ {ℓ} {A : Set ℓ} → A → A
id x = x
_ : id 42 ≡ 42
_ = refl
-- Composition
_∘_ :
∀ {ℓ m n}
{A : Set ℓ}
{B : Set m}
{C : B → Set n}
(g : (b : B) → C b)
(f : A → B)
→ ---------
(a : A) → C (f a)
(g ∘ f) x = g (f x)
_ : (id ∘ id) 42 ≡ id (id 42)
_ = refl
-- Transitivity
trans :
∀ {ℓ}
{A : Set ℓ}
{x y z : A}
(q : y ≡ z)
(p : x ≡ y)
→ ---------
x ≡ z
trans n refl = n
-- Symmetry
symm :
∀ {ℓ}
{A : Set ℓ}
{x y : A}
(p : x ≡ y)
→ ---------
y ≡ x
symm refl = refl
-- Congruence
cong :
∀ {ℓ ℓ′}
{A : Set ℓ}
{B : Set ℓ′}
(f : A → B)
{x y : A}
(p : x ≡ y)
→ ---------
f x ≡ f y
cong _ refl = refl
cong₂ :
∀ {ℓ ℓ′}
{A A′ : Set ℓ}
{B : Set ℓ′}
(f : A → A′ → B)
{x y : A}
{x′ y′ : A′}
(p : x ≡ y)
(q : x′ ≡ y′)
→ -----------
f x x′ ≡ f y y′
cong₂ _ refl refl = refl
-- Substitution
subst :
∀ {ℓ ℓ′}
{A : Set ℓ}
(B : A → Set ℓ′)
{x y : A}
(p : x ≡ y)
→ ---------
B x → B y
subst _ refl = λ a → a
-- Type coercion
coe :
∀ {ℓ}
{A B : Set ℓ}
→ -----------
A ≡ B → A → B
coe r a = subst id r a
| {
"alphanum_fraction": 0.4162323157,
"avg_line_length": 13.43,
"ext": "agda",
"hexsha": "02ea11d125b8595a58ac3790026f54d44cb3f95d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "anqurvanillapy/fpl",
"max_forks_repo_path": "agda/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "anqurvanillapy/fpl",
"max_issues_repo_path": "agda/Prelude.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "anqurvanillapy/fpl",
"max_stars_repo_path": "agda/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z",
"num_tokens": 625,
"size": 1343
} |
-- Andreas, 2018-10-17, re issue #2757
--
-- Matching on runtime-irrelevant arguments is fine
-- as long as it produces only one branch.
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
-- Matching on empty types can be erased.
data ⊥ : Set where
⊥-elim : ∀{A : Set} → @0 ⊥ → A
⊥-elim ()
-- Accessibility.
data Acc {A : Set} (R : A → A → Set) (x : A) : Set where
acc : (∀{y} (y<x : R y x) → Acc R y) → Acc R x
-- Accessibility proofs can be erased.
wfrec : {A : Set} (R : A → A → Set) {P : A → Set}
→ (∀{x} → (∀{y} (@0 y<x : R y x) → P y) → P x)
→ ∀{x} (@0 ax : Acc R x) → P x
wfrec R f (acc h) = f λ y<x → wfrec R f (h y<x)
-- Non-branching matches can be erased.
diag : ∀(@0 x) (y : Bool) (@0 eq : x ≡ y) → Bool
diag false false refl = false
diag true y refl = y
diag' : ∀ x (@0 y : Bool) (@0 eq : x ≡ y) → Bool
diag' false false refl = false
diag' true y refl = y
-- Also for literals.
nonBranchLit : ∀ (@0 x) (eq : x ≡ 0) → Set
nonBranchLit 0 refl = Nat
-- The attribute syntax collides lexically with the as-pattern syntax.
userConfusingClashOfAttributesAndAsPatterns : ∀ (@0 x) (eq : x ≡ 0) → Set
userConfusingClashOfAttributesAndAsPatterns (x @0) refl = Nat
| {
"alphanum_fraction": 0.6064516129,
"avg_line_length": 25.8333333333,
"ext": "agda",
"hexsha": "84414b5435d03dd88f523e0fbe9a4845f261b001",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/EraseSingleConstructorMatches.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/EraseSingleConstructorMatches.agda",
"max_line_length": 73,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/EraseSingleConstructorMatches.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 450,
"size": 1240
} |
open import Relation.Nullary using (¬_)
module AKS.Fin where
open import AKS.Nat using (ℕ; _+_; _<_)
record Fin (n : ℕ) : Set where
constructor Fin✓
field
i : ℕ
i<n : i < n
¬Fin0 : ¬ (Fin 0)
¬Fin0 ()
from< : ∀ {i n} → i < n → Fin n
from< {i} i<n = Fin✓ i i<n
| {
"alphanum_fraction": 0.5615942029,
"avg_line_length": 15.3333333333,
"ext": "agda",
"hexsha": "979788c6350543509d7c82ffd054cc46c0bfc895",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Fin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Fin.agda",
"max_line_length": 39,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Fin.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 112,
"size": 276
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Record types with manifest fields and "with", based on Randy
-- Pollack's "Dependently Typed Records in Type Theory"
------------------------------------------------------------------------
-- For an example of how this module can be used, see README.Record.
{-# OPTIONS --without-K --safe #-}
open import Data.Bool.Base using (if_then_else_)
open import Data.Empty
open import Data.List.Base
open import Data.Product hiding (proj₁; proj₂)
open import Data.Unit
open import Function
open import Level
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Decidable
-- The module is parametrised by the type of labels, which should come
-- with decidable equality.
module Record {ℓ : Level} (Label : Set ℓ) (_≟_ : Decidable (_≡_ {A = Label})) where
------------------------------------------------------------------------
-- A Σ-type with a manifest field
-- A variant of Σ where the value of the second field is "manifest"
-- (given by the first).
infix 4 _,
record Manifest-Σ {a b} (A : Set a) {B : A → Set b}
(f : (x : A) → B x) : Set a where
constructor _,
field proj₁ : A
proj₂ : B proj₁
proj₂ = f proj₁
------------------------------------------------------------------------
-- Signatures and records
mutual
infixl 5 _,_∶_ _,_≔_
data Signature s : Set (suc s ⊔ ℓ) where
∅ : Signature s
_,_∶_ : (Sig : Signature s)
(ℓ : Label)
(A : Record Sig → Set s) →
Signature s
_,_≔_ : (Sig : Signature s)
(ℓ : Label)
{A : Record Sig → Set s}
(a : (r : Record Sig) → A r) →
Signature s
-- Record is a record type to ensure that the signature can be
-- inferred from a value of type Record Sig.
record Record {s} (Sig : Signature s) : Set s where
eta-equality
inductive
constructor rec
field fun : Record-fun Sig
Record-fun : ∀ {s} → Signature s → Set s
Record-fun ∅ = Lift _ ⊤
Record-fun (Sig , ℓ ∶ A) = Σ (Record Sig) A
Record-fun (Sig , ℓ ≔ a) = Manifest-Σ (Record Sig) a
------------------------------------------------------------------------
-- Labels
-- A signature's labels, starting with the last one.
labels : ∀ {s} → Signature s → List Label
labels ∅ = []
labels (Sig , ℓ ∶ A) = ℓ ∷ labels Sig
labels (Sig , ℓ ≔ a) = ℓ ∷ labels Sig
-- Inhabited if the label is part of the signature.
infix 4 _∈_
_∈_ : ∀ {s} → Label → Signature s → Set
ℓ ∈ Sig =
foldr (λ ℓ′ → if ⌊ ℓ ≟ ℓ′ ⌋ then (λ _ → ⊤) else id) ⊥ (labels Sig)
------------------------------------------------------------------------
-- Projections
-- Signature restriction and projection. (Restriction means removal of
-- a given field and all subsequent fields.)
Restrict : ∀ {s} (Sig : Signature s) (ℓ : Label) → ℓ ∈ Sig →
Signature s
Restrict ∅ ℓ ()
Restrict (Sig , ℓ′ ∶ A) ℓ ℓ∈ with ℓ ≟ ℓ′
... | yes _ = Sig
... | no _ = Restrict Sig ℓ ℓ∈
Restrict (Sig , ℓ′ ≔ a) ℓ ℓ∈ with ℓ ≟ ℓ′
... | yes _ = Sig
... | no _ = Restrict Sig ℓ ℓ∈
Restricted : ∀ {s} (Sig : Signature s) (ℓ : Label) → ℓ ∈ Sig → Set s
Restricted Sig ℓ ℓ∈ = Record (Restrict Sig ℓ ℓ∈)
Proj : ∀ {s} (Sig : Signature s) (ℓ : Label) {ℓ∈ : ℓ ∈ Sig} →
Restricted Sig ℓ ℓ∈ → Set s
Proj ∅ ℓ {}
Proj (Sig , ℓ′ ∶ A) ℓ {ℓ∈} with ℓ ≟ ℓ′
... | yes _ = A
... | no _ = Proj Sig ℓ {ℓ∈}
Proj (_,_≔_ Sig ℓ′ {A = A} a) ℓ {ℓ∈} with ℓ ≟ ℓ′
... | yes _ = A
... | no _ = Proj Sig ℓ {ℓ∈}
-- Record restriction and projection.
infixl 5 _∣_
_∣_ : ∀ {s} {Sig : Signature s} → Record Sig →
(ℓ : Label) {ℓ∈ : ℓ ∈ Sig} → Restricted Sig ℓ ℓ∈
_∣_ {Sig = ∅} r ℓ {}
_∣_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′
... | yes _ = Σ.proj₁ r
... | no _ = _∣_ (Σ.proj₁ r) ℓ {ℓ∈}
_∣_ {Sig = Sig , ℓ′ ≔ a} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′
... | yes _ = Manifest-Σ.proj₁ r
... | no _ = _∣_ (Manifest-Σ.proj₁ r) ℓ {ℓ∈}
infixl 5 _·_
_·_ : ∀ {s} {Sig : Signature s} (r : Record Sig)
(ℓ : Label) {ℓ∈ : ℓ ∈ Sig} →
Proj Sig ℓ {ℓ∈} (r ∣ ℓ)
_·_ {Sig = ∅} r ℓ {}
_·_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′
... | yes _ = Σ.proj₂ r
... | no _ = _·_ (Σ.proj₁ r) ℓ {ℓ∈}
_·_ {Sig = Sig , ℓ′ ≔ a} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′
... | yes _ = Manifest-Σ.proj₂ r
... | no _ = _·_ (Manifest-Σ.proj₁ r) ℓ {ℓ∈}
------------------------------------------------------------------------
-- With
-- Sig With ℓ ≔ a is the signature Sig, but with the ℓ field set to a.
mutual
infixl 5 _With_≔_
_With_≔_ : ∀ {s} (Sig : Signature s) (ℓ : Label) {ℓ∈ : ℓ ∈ Sig} →
((r : Restricted Sig ℓ ℓ∈) → Proj Sig ℓ r) → Signature s
_With_≔_ ∅ ℓ {} a
_With_≔_ (Sig , ℓ′ ∶ A) ℓ {ℓ∈} a with ℓ ≟ ℓ′
... | yes _ = Sig , ℓ′ ≔ a
... | no _ = _With_≔_ Sig ℓ {ℓ∈} a , ℓ′ ∶ A ∘ drop-With
_With_≔_ (Sig , ℓ′ ≔ a′) ℓ {ℓ∈} a with ℓ ≟ ℓ′
... | yes _ = Sig , ℓ′ ≔ a
... | no _ = _With_≔_ Sig ℓ {ℓ∈} a , ℓ′ ≔ a′ ∘ drop-With
drop-With : ∀ {s} {Sig : Signature s} {ℓ : Label} {ℓ∈ : ℓ ∈ Sig}
{a : (r : Restricted Sig ℓ ℓ∈) → Proj Sig ℓ r} →
Record (_With_≔_ Sig ℓ {ℓ∈} a) → Record Sig
drop-With {Sig = ∅} {ℓ∈ = ()} r
drop-With {Sig = Sig , ℓ′ ∶ A} {ℓ} (rec r) with ℓ ≟ ℓ′
... | yes _ = rec (Manifest-Σ.proj₁ r , Manifest-Σ.proj₂ r)
... | no _ = rec (drop-With (Σ.proj₁ r) , Σ.proj₂ r)
drop-With {Sig = Sig , ℓ′ ≔ a} {ℓ} (rec r) with ℓ ≟ ℓ′
... | yes _ = rec (Manifest-Σ.proj₁ r ,)
... | no _ = rec (drop-With (Manifest-Σ.proj₁ r) ,)
| {
"alphanum_fraction": 0.4922915207,
"avg_line_length": 31.5359116022,
"ext": "agda",
"hexsha": "9252554798a3dcfda3e6b4022af842b7ab18bbaf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Record.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Record.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Record.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2116,
"size": 5708
} |
-- making sure that the fun clauses are kept in declaration order
-- in an interleaved mutual block
open import Agda.Builtin.Nat
interleaved mutual
plus : Nat → Nat → Nat
minus : Nat → Nat → Nat
-- 0 being neutral
plus 0 n = n
minus n 0 = n
-- other 0 case
plus n 0 = n
minus 0 n = 0
-- suc suc
plus (suc m) (suc n) = suc (suc (plus m n))
minus (suc m) (suc n) = minus m n
-- All of these test cases should be true by computation
-- It will not be the case if the definitions have been interleaved
-- the wrong way around (because the resulting definition would be
-- strict in a different argument)
open import Agda.Builtin.Equality
_ : ∀ {n} → plus 0 n ≡ n
_ = refl
_ : ∀ {n} → minus n 0 ≡ n
_ = refl
-- The following should not check with refl; for the same reasons
-- _ : ∀ {n} → plus n 0 ≡ n
-- _ = refl
-- _ : ∀ {n} → minus 0 n ≡ 0
-- _ = refl
-- but they are of course provable by case analysis:
_ : ∀ n → plus n 0 ≡ n
_ = λ where
zero → refl
(suc _) → refl
_ : ∀ n → minus 0 n ≡ 0
_ = λ where
zero → refl
(suc _) → refl
| {
"alphanum_fraction": 0.6122823098,
"avg_line_length": 19.8363636364,
"ext": "agda",
"hexsha": "4f9e6aafb5b21f8420ed40d1018a77587f31f976",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2858-Order.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2858-Order.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2858-Order.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 371,
"size": 1091
} |
-- Reported by nils.anders.danielsson, Feb 17, 2015
-- See also Issue 292 , Issue 1406 , and Issue 1427.
-- The code below is accepted by Agda 2.4.2.2, but not by the current
-- maintenance or master branches.
data Box (A : Set) : Set where
[_] : A → Box A
data _≡_ (A : Set) : Set → Set₁ where
refl : A ≡ A
data _≅_ {A : Set₁} (x : A) : {B : Set₁} → B → Set₂ where
refl : x ≅ x
-- C could be a typed DSEL.
data C : Set → Set₁ where
c₁ c₂ : (A : Set) → C (Box A)
-- If A is considered forced, the code no longer type-checks.
-- D could be some kind of semantics for C.
data D : {A : Set} → C A → Set₂ where
d₁ : (A : Set) → D (c₁ A)
d₂ : (A : Set) → D (c₂ A)
module Doesn't-work where
-- Let's try to write an eliminator for the part of the semantics
-- that concerns c₁ programs. The basic approach doesn't work:
D-elim-c₁ : (P : {A : Set} → D (c₁ A) → Set₂) →
((A : Set) → P (d₁ A)) →
{A : Set} (x : D (c₁ A)) → P x
D-elim-c₁ P p (d₁ A) = p A
-- The following trick also fails (but for some reason the absurd
-- case is accepted):
-- Jesper 2015-12-18 update: this is no longer accepted by the new unifier.
--D-elim-c₁-helper :
-- (P : {A B : Set} {c : C A} →
-- D c → A ≡ Box B → c ≅ c₁ B → Set₂) →
-- ((A : Set) → P (d₁ A) refl refl) →
-- {A B : Set} {c : C A}
-- (x : D c) (eq₂ : c ≅ c₁ B) (eq₁ : A ≡ Box B) → P x eq₁ eq₂
--D-elim-c₁-helper P p (d₂ A) () _
--D-elim-c₁-helper P p (d₁ A) refl refl = p A
module Works where
-- I can define the eliminators by first defining and proving no
-- confusion (following McBride, Goguen and McKinna). However, this
-- requires a fair amount of work, and easy dependent pattern
-- matching is arguably one of the defining features of Agda.
--
-- A quote from "A Few Constructions on Constructors": "The Epigram
-- language and system [25, 23] takes these constructions for
-- granted. We see no reason why the users of other systems should
-- work harder than we do."
data ⊥ : Set₁ where
No-confusion : ∀ {A B} → C A → C B → Set₁
No-confusion (c₁ A) (c₁ B) = A ≡ B
No-confusion (c₂ A) (c₂ B) = A ≡ B
No-confusion _ _ = ⊥
no-confusion :
∀ {A B} (x : C A) (y : C B) → A ≡ B → x ≅ y → No-confusion x y
no-confusion (c₁ A) .(c₁ A) refl refl = refl
no-confusion (c₂ A) .(c₂ A) refl refl = refl
D-elim-c₁-helper :
(P : {A B : Set} {c : C A} →
D c → A ≡ Box B → c ≅ c₁ B → Set₂) →
((A : Set) → P (d₁ A) refl refl) →
{A B : Set} {c : C A}
(x : D c) (eq₂ : c ≅ c₁ B) (eq₁ : A ≡ Box B) → P x eq₁ eq₂
D-elim-c₁-helper P p (d₁ A) eq₂ eq₁ with no-confusion _ _ eq₁ eq₂
D-elim-c₁-helper P p (d₁ B) refl refl | refl = p B
D-elim-c₁-helper P p (d₂ A) eq₂ eq₁ with no-confusion _ _ eq₁ eq₂
D-elim-c₁-helper P p (d₂ A) eq₂ eq₁ | ()
cast : {A B : Set} {x : C A} {y : C B} →
A ≡ B → x ≅ y → D x → D y
cast refl refl x = x
D-elim-c₁ :
(P : {A : Set} → D (c₁ A) → Set₂) →
((A : Set) → P (d₁ A)) →
{A : Set} (x : D (c₁ A)) → P x
D-elim-c₁ P p x =
D-elim-c₁-helper (λ x eq₁ eq₂ → P (cast eq₁ eq₂ x)) p x refl refl
-- should type-check
| {
"alphanum_fraction": 0.557160804,
"avg_line_length": 32.1616161616,
"ext": "agda",
"hexsha": "591ce2add6f3a556dea4a21a18db0f993815df61",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1435.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1435.agda",
"max_line_length": 77,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1435.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 1251,
"size": 3184
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Pointed.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed.Base
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma
Π∙ : ∀ {ℓ ℓ'} (A : Type ℓ) (B∙ : A → Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
Π∙ A B∙ = (∀ a → typ (B∙ a)) , (λ a → pt (B∙ a))
Σ∙ : ∀ {ℓ ℓ'} (A∙ : Pointed ℓ) (B∙ : typ A∙ → Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
Σ∙ A∙ B∙ = (Σ[ a ∈ typ A∙ ] typ (B∙ a)) , (pt A∙ , pt (B∙ (pt A∙)))
_×∙_ : ∀ {ℓ ℓ'} (A∙ : Pointed ℓ) (B∙ : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
A∙ ×∙ B∙ = ((typ A∙) × (typ B∙)) , (pt A∙ , pt B∙)
{- composition of pointed maps -}
_∘∙_ : ∀ {ℓA ℓB ℓC} {A : Pointed ℓA} {B : Pointed ℓB} {C : Pointed ℓC}
(g : B →∙ C) (f : A →∙ B) → (A →∙ C)
(g , g∙) ∘∙ (f , f∙) = (λ x → g (f x)) , ((cong g f∙) ∙ g∙)
{- pointed identity -}
id∙ : ∀ {ℓA} (A : Pointed ℓA) → (A →∙ A)
id∙ A = ((λ x → x) , refl)
{- constant pointed map -}
const∙ : ∀ {ℓA ℓB} (A : Pointed ℓA) (B : Pointed ℓB) → (A →∙ B)
const∙ _ (_ , b) = (λ _ → b) , refl
{- left identity law for pointed maps -}
∘∙-idˡ : ∀ {ℓA ℓB} {A : Pointed ℓA} {B : Pointed ℓB} (f : A →∙ B) → f ∘∙ id∙ A ≡ f
∘∙-idˡ (_ , f∙) = ΣPathP ( refl , (lUnit f∙) ⁻¹ )
{- right identity law for pointed maps -}
∘∙-idʳ : ∀ {ℓA ℓB} {A : Pointed ℓA} {B : Pointed ℓB} (f : A →∙ B) → id∙ B ∘∙ f ≡ f
∘∙-idʳ (_ , f∙) = ΣPathP ( refl , (rUnit f∙) ⁻¹ )
{- associativity for composition of pointed maps -}
∘∙-assoc : ∀ {ℓA ℓB ℓC ℓD} {A : Pointed ℓA} {B : Pointed ℓB} {C : Pointed ℓC} {D : Pointed ℓD}
(h : C →∙ D) (g : B →∙ C) (f : A →∙ B)
→ (h ∘∙ g) ∘∙ f ≡ h ∘∙ (g ∘∙ f)
∘∙-assoc (h , h∙) (g , g∙) (f , f∙) = ΣPathP (refl , q)
where
q : (cong (h ∘ g) f∙) ∙ (cong h g∙ ∙ h∙) ≡ cong h (cong g f∙ ∙ g∙) ∙ h∙
q = ( (cong (h ∘ g) f∙) ∙ (cong h g∙ ∙ h∙)
≡⟨ refl ⟩
(cong h (cong g f∙)) ∙ (cong h g∙ ∙ h∙)
≡⟨ assoc (cong h (cong g f∙)) (cong h g∙) h∙ ⟩
(cong h (cong g f∙) ∙ cong h g∙) ∙ h∙
≡⟨ cong (λ p → p ∙ h∙) ((cong-∙ h (cong g f∙) g∙) ⁻¹) ⟩
(cong h (cong g f∙ ∙ g∙) ∙ h∙) ∎ )
| {
"alphanum_fraction": 0.4801279123,
"avg_line_length": 39.8,
"ext": "agda",
"hexsha": "303cf6f32457f7752b17c04b58f0fa85935bef89",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Foundations/Pointed/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Foundations/Pointed/Properties.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Foundations/Pointed/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1179,
"size": 2189
} |
------------------------------------------------------------------------
-- A variant of set quotients with erased higher constructors
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- Partly following the HoTT book, but adapted for erasure.
--
-- Unlike the HoTT book, but following the cubical library (in which
-- set quotients were implemented by Zesen Qian and Anders Mörtberg),
-- the quotienting relations are not (always) required to be
-- propositional.
-- The module is parametrised by a notion of equality. The higher
-- constructors of the HIT defining quotients use path equality, but
-- the supplied notion of equality is used for many other things.
import Equality.Path as P
module Quotient.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Decidable-UIP equality-with-J using (Constant)
open import Equality.Path.Isomorphisms eq
import Equality.Path.Isomorphisms.Univalence eq as U
open import Equivalence equality-with-J as Eq using (_≃_)
import Equivalence.Erased equality-with-J as EEq
open import Equivalence-relation equality-with-J
open import Erased.Cubical eq as Er using (Erased; Erasedᴾ; [_])
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as PT using (∥_∥; ∣_∣)
open import H-level.Truncation.Propositional.Erased eq as PTᴱ
using (∥_∥ᴱ; ∣_∣; Surjectiveᴱ)
open import Quotient eq as Q using (_/_)
open import Sum equality-with-J
open import Surjection equality-with-J using (_↠_)
open import Univalence-axiom equality-with-J
private
variable
a a₁ a₂ p r r₁ r₂ : Level
A A₁ A₂ B : Type a
P : A → Type p
R : A → A → Type r
f k x y : A
------------------------------------------------------------------------
-- A re-export
-- This module re-exports Quotient.Erased.Basics.
open import Quotient.Erased.Basics eq public
------------------------------------------------------------------------
-- Preservation lemmas
-- Two preservation lemmas for functions.
infix 5 _/ᴱ-map-∥∥_ _/ᴱ-map_
_/ᴱ-map-∥∥_ :
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁→A₂ : A₁ → A₂) →
@0 (∀ x y → ∥ R₁ x y ∥ → ∥ R₂ (A₁→A₂ x) (A₁→A₂ y) ∥) →
A₁ /ᴱ R₁ → A₂ /ᴱ R₂
_/ᴱ-map-∥∥_ {R₁ = R₁} {R₂ = R₂} A₁→A₂ R₁→R₂ = rec λ where
.[]ʳ → [_] ∘ A₁→A₂
.is-setʳ → /ᴱ-is-set
.[]-respects-relationʳ {x = x} {y = y} →
R₁ x y ↝⟨ ∣_∣ ⟩
∥ R₁ x y ∥ ↝⟨ R₁→R₂ _ _ ⟩
∥ R₂ (A₁→A₂ x) (A₁→A₂ y) ∥ ↝⟨ PT.rec /ᴱ-is-set []-respects-relation ⟩□
[ A₁→A₂ x ] ≡ [ A₁→A₂ y ] □
_/ᴱ-map_ :
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁→A₂ : A₁ → A₂) →
@0 (∀ x y → R₁ x y → R₂ (A₁→A₂ x) (A₁→A₂ y)) →
A₁ /ᴱ R₁ → A₂ /ᴱ R₂
A₁→A₂ /ᴱ-map R₁→R₂ = A₁→A₂ /ᴱ-map-∥∥ λ x y → PT.∥∥-map (R₁→R₂ x y)
-- Two preservation lemmas for logical equivalences.
/ᴱ-cong-∥∥-⇔ :
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁⇔A₂ : A₁ ⇔ A₂) →
@0 (∀ x y → ∥ R₁ x y ∥ → ∥ R₂ (_⇔_.to A₁⇔A₂ x) (_⇔_.to A₁⇔A₂ y) ∥) →
@0 (∀ x y → ∥ R₂ x y ∥ → ∥ R₁ (_⇔_.from A₁⇔A₂ x) (_⇔_.from A₁⇔A₂ y) ∥) →
A₁ /ᴱ R₁ ⇔ A₂ /ᴱ R₂
/ᴱ-cong-∥∥-⇔ A₁⇔A₂ R₁→R₂ R₂→R₁ = record
{ to = _⇔_.to A₁⇔A₂ /ᴱ-map-∥∥ R₁→R₂
; from = _⇔_.from A₁⇔A₂ /ᴱ-map-∥∥ R₂→R₁
}
/ᴱ-cong-⇔ :
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁⇔A₂ : A₁ ⇔ A₂) →
@0 (∀ x y → R₁ x y → R₂ (_⇔_.to A₁⇔A₂ x) (_⇔_.to A₁⇔A₂ y)) →
@0 (∀ x y → R₂ x y → R₁ (_⇔_.from A₁⇔A₂ x) (_⇔_.from A₁⇔A₂ y)) →
A₁ /ᴱ R₁ ⇔ A₂ /ᴱ R₂
/ᴱ-cong-⇔ A₁⇔A₂ R₁→R₂ R₂→R₁ =
/ᴱ-cong-∥∥-⇔ A₁⇔A₂ (λ x y → PT.∥∥-map (R₁→R₂ x y))
(λ x y → PT.∥∥-map (R₂→R₁ x y))
-- Two preservation lemmas for split surjections.
infix 5 _/ᴱ-cong-∥∥-↠_ _/ᴱ-cong-↠_
_/ᴱ-cong-∥∥-↠_ :
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
@0 (∀ x y → ∥ R₁ x y ∥ ⇔ ∥ R₂ (_↠_.to A₁↠A₂ x) (_↠_.to A₁↠A₂ y) ∥) →
A₁ /ᴱ R₁ ↠ A₂ /ᴱ R₂
_/ᴱ-cong-∥∥-↠_ {R₁ = R₁} {R₂ = R₂} A₁↠A₂ R₁⇔R₂ = record
{ logical-equivalence = /ᴱ-cong-∥∥-⇔
(_↠_.logical-equivalence A₁↠A₂)
(λ x y → _⇔_.to (R₁⇔R₂ x y))
(λ x y → ∥ R₂ x y ∥ ↝⟨ ≡⇒↝ _ (sym $ cong₂ (λ x y → ∥ R₂ x y ∥) (right-inverse-of x) (right-inverse-of y)) ⟩
∥ R₂ (to (from x)) (to (from y)) ∥ ↝⟨ _⇔_.from (R₁⇔R₂ _ _) ⟩□
∥ R₁ (from x) (from y) ∥ □)
; right-inverse-of = elim-prop λ where
.[]ʳ x →
[ to (from x) ] ≡⟨ cong [_] $ right-inverse-of x ⟩∎
[ x ] ∎
.is-propositionʳ _ → /ᴱ-is-set
}
where
open _↠_ A₁↠A₂
_/ᴱ-cong-↠_ :
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
@0 (∀ x y → R₁ x y ⇔ R₂ (_↠_.to A₁↠A₂ x) (_↠_.to A₁↠A₂ y)) →
A₁ /ᴱ R₁ ↠ A₂ /ᴱ R₂
A₁↠A₂ /ᴱ-cong-↠ R₁⇔R₂ =
A₁↠A₂ /ᴱ-cong-∥∥-↠ λ x y → PT.∥∥-cong-⇔ (R₁⇔R₂ x y)
-- Two preservation lemmas for isomorphisms.
infix 5 _/ᴱ-cong-∥∥_ _/ᴱ-cong_
_/ᴱ-cong-∥∥_ :
{A₁ : Type a₁} {A₂ : Type a₂}
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁↔A₂ : A₁ ↔[ k ] A₂) →
@0 (∀ x y →
∥ R₁ x y ∥ ⇔
∥ R₂ (to-implication A₁↔A₂ x) (to-implication A₁↔A₂ y) ∥) →
A₁ /ᴱ R₁ ↔[ k ] A₂ /ᴱ R₂
_/ᴱ-cong-∥∥_ {k = k} {R₁ = R₁} {R₂ = R₂} A₁↔A₂′ R₁⇔R₂ =
from-bijection (record
{ surjection = from-isomorphism A₁↔A₂ /ᴱ-cong-∥∥-↠ λ x y →
∥ R₁ x y ∥ ↝⟨ R₁⇔R₂ x y ⟩
∥ R₂ (to-implication A₁↔A₂′ x) (to-implication A₁↔A₂′ y) ∥ ↝⟨ ≡⇒↝ _ $ cong₂ (λ f g → ∥ R₂ (f x) (g y) ∥)
(to-implication∘from-isomorphism k bijection)
(to-implication∘from-isomorphism k bijection) ⟩□
∥ R₂ (to x) (to y) ∥ □
; left-inverse-of = elim-prop λ where
.[]ʳ x →
[ from (to x) ] ≡⟨ cong [_] $ left-inverse-of x ⟩∎
[ x ] ∎
.is-propositionʳ _ → /ᴱ-is-set
})
where
A₁↔A₂ = from-isomorphism A₁↔A₂′
open _↔_ A₁↔A₂
_/ᴱ-cong_ :
{A₁ : Type a₁} {A₂ : Type a₂}
{@0 R₁ : A₁ → A₁ → Type r₁}
{@0 R₂ : A₂ → A₂ → Type r₂} →
(A₁↔A₂ : A₁ ↔[ k ] A₂) →
@0 (∀ x y →
R₁ x y ⇔ R₂ (to-implication A₁↔A₂ x) (to-implication A₁↔A₂ y)) →
A₁ /ᴱ R₁ ↔[ k ] A₂ /ᴱ R₂
_/ᴱ-cong_ A₁↔A₂ R₁⇔R₂ =
A₁↔A₂ /ᴱ-cong-∥∥ λ x y → PT.∥∥-cong-⇔ (R₁⇔R₂ x y)
------------------------------------------------------------------------
-- Some properties
-- [_] is surjective with erased proofs.
Surjectiveᴱ-[] : Surjectiveᴱ ([_] {R = R})
Surjectiveᴱ-[] = elim-prop λ where
.[]ʳ x → ∣ x , [ refl _ ] ∣
.is-propositionʳ _ → PTᴱ.truncation-is-proposition
-- Quotienting by the propositional truncation of a relation is
-- equivalent to quotienting by the relation itself.
/ᴱ-∥∥≃/ᴱ : A /ᴱ (λ x y → ∥ R x y ∥) ≃ A /ᴱ R
/ᴱ-∥∥≃/ᴱ {R = R} = F.id /ᴱ-cong-∥∥ λ x y →
∥ ∥ R x y ∥ ∥ ↔⟨ PT.flatten ⟩□
∥ R x y ∥ □
-- If R is an equivalence relation, then A /ᴱ R is weakly effective
-- (where this is expressed using ∥_∥ᴱ).
--
-- This proof is based on that of Proposition 2 in "Quotienting the
-- Delay Monad by Weak Bisimilarity" by Chapman, Uustalu and Veltri.
weakly-effective :
{R : A → A → Type r} →
@0 Is-equivalence-relation R →
∥ R x x ∥ᴱ →
_≡_ {A = A /ᴱ R} [ x ] [ y ] → ∥ R x y ∥ᴱ
weakly-effective
{A = A} {r = r} {x = x} {y = y} {R = R} eq ∥Rxx∥ᴱ [x]≡[y] =
$⟨ ∥Rxx∥ᴱ ⟩
R′ x [ x ] .proj₁ ↝⟨ ≡⇒→ (cong (λ y → R′ x y .proj₁) [x]≡[y]) ⟩
R′ x [ y ] .proj₁ ↔⟨⟩
∥ R x y ∥ᴱ □
where
R′ : A → A /ᴱ R → ∃ λ (P : Type r) → Erased (Is-proposition P)
R′ x = rec λ where
.[]ʳ y → ∥ R x y ∥ᴱ , [ PTᴱ.truncation-is-proposition ]
.is-setʳ → $⟨ (λ {_ _} → Is-set-∃-Is-proposition ext U.prop-ext) ⟩
Is-set (Proposition r) ↝⟨ H-level-cong _ 2
(∃-cong λ _ → inverse $ Er.Erased↔ .Er.erased)
⦂ (_ → _) ⟩□
Is-set (∃ λ (P : Type r) → Erased (Is-proposition P)) □
.[]-respects-relationʳ {x = y} {y = z} →
R y z ↝⟨ (λ r → record
{ to = flip (eq .Is-equivalence-relation.transitive) r
; from = flip (eq .Is-equivalence-relation.transitive)
(eq .Is-equivalence-relation.symmetric r)
}) ⟩
R x y ⇔ R x z ↝⟨ EEq._≃ᴱ_.logical-equivalence ∘ PTᴱ.∥∥ᴱ-cong-⇔ ⟩
∥ R x y ∥ᴱ ⇔ ∥ R x z ∥ᴱ ↔⟨ ⇔↔≡″ ext U.prop-ext ⟩
(∥ R x y ∥ᴱ , _) ≡ (∥ R x z ∥ᴱ , _) ↝⟨ cong (Σ-map id Er.[_]→) ⟩□
(∥ R x y ∥ᴱ , [ _ ]) ≡ (∥ R x z ∥ᴱ , [ _ ]) □
-- If R is an equivalence relation, and R is propositional (for x
-- and y), then A /ᴱ R is effective (for x and y).
effective :
@0 Is-equivalence-relation R →
@0 Is-proposition (R x y) →
R x x →
_≡_ {A = A /ᴱ R} [ x ] [ y ] → R x y
effective {R = R} {x = x} {y = y} eq prop Rxx =
[ x ] ≡ [ y ] ↝⟨ weakly-effective eq ∣ Rxx ∣ ⟩
∥ R x y ∥ᴱ ↔⟨ PTᴱ.∥∥ᴱ↔ prop ⟩□
R x y □
-- If R is an equivalence relation, and R is propositional (for x
-- and y), then R x y is equivalent to equality of x and y under [_]
-- (in erased contexts).
@0 related≃[equal] :
Is-equivalence-relation R →
Is-proposition (R x y) →
R x y ≃ _≡_ {A = A /ᴱ R} [ x ] [ y ]
related≃[equal] eq prop =
Eq.⇔→≃
prop
/ᴱ-is-set
[]-respects-relation
(effective eq prop (eq .Is-equivalence-relation.reflexive))
-- If R is an equivalence relation, then ∥ R x y ∥ is equivalent to
-- equality of x and y under [_] (in erased contexts).
@0 ∥related∥≃[equal] :
Is-equivalence-relation R →
∥ R x y ∥ ≃ _≡_ {A = A /ᴱ R} [ x ] [ y ]
∥related∥≃[equal] {R = R} {x = x} {y = y} eq =
∥ R x y ∥ ↝⟨ inverse PT.∥∥ᴱ≃∥∥ ⟩
∥ R x y ∥ᴱ ↝⟨ Eq.⇔→≃
PTᴱ.truncation-is-proposition
/ᴱ-is-set
(PTᴱ.rec λ @0 where
.PTᴱ.truncation-is-propositionʳ → /ᴱ-is-set
.PTᴱ.∣∣ʳ →
[]-respects-relation)
(weakly-effective eq ∣ eq .Is-equivalence-relation.reflexive ∣) ⟩□
[ x ] ≡ [ y ] □
-- Quotienting with equality (for a set) amounts to the same thing as
-- not quotienting at all.
/ᴱ≡↔ : @0 Is-set A → A /ᴱ _≡_ ↔ A
/ᴱ≡↔ A-set = record
{ surjection = record
{ logical-equivalence = record
{ from = [_]
; to = rec λ where
.[]ʳ → id
.[]-respects-relationʳ → id
.is-setʳ → A-set
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = elim-prop λ where
.[]ʳ _ → refl _
.is-propositionʳ _ → /ᴱ-is-set
}
-- Quotienting with a trivial relation amounts to the same thing as
-- using the propositional truncation (with erased proofs).
/ᴱtrivial↔∥∥ᴱ : @0 (∀ x y → R x y) → A /ᴱ R ↔ ∥ A ∥ᴱ
/ᴱtrivial↔∥∥ᴱ {A = A} {R = R} trivial = record
{ surjection = record
{ logical-equivalence = record
{ to = rec-prop λ where
.[]ʳ → ∣_∣
.is-propositionʳ → PTᴱ.truncation-is-proposition
; from = PTᴱ.rec λ where
.PTᴱ.∣∣ʳ → [_]
.PTᴱ.truncation-is-propositionʳ → elim-prop λ @0 where
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
/ᴱ-is-set
.[]ʳ x → elim-prop λ @0 where
.is-propositionʳ _ → /ᴱ-is-set
.[]ʳ y → []-respects-relation (trivial x y)
}
; right-inverse-of = PTᴱ.elim λ where
.PTᴱ.∣∣ʳ _ → refl _
.PTᴱ.truncation-is-propositionʳ _ →
⇒≡ 1 PTᴱ.truncation-is-proposition
}
; left-inverse-of = elim-prop λ where
.[]ʳ _ → refl _
.is-propositionʳ _ → /ᴱ-is-set
}
------------------------------------------------------------------------
-- A property related to ∥_∥ᴱ, proved using _/ᴱ_
-- Having a constant function (with an erased proof of constancy) into
-- a set is equivalent to having a function from a propositionally
-- truncated type (with erased proofs) into the set.
--
-- The statement of this result is adapted from that of
-- Proposition 2.2 in "The General Universal Property of the
-- Propositional Truncation" by Kraus.
Σ→Erased-Constant≃∥∥ᴱ→ :
@0 Is-set B →
(∃ λ (f : A → B) → Erased (Constant f)) ≃ (∥ A ∥ᴱ → B)
Σ→Erased-Constant≃∥∥ᴱ→ {B = B} {A = A} B-set =
(∃ λ (f : A → B) → Erased (Constant f)) ↔⟨ lemma ⟩
(A /ᴱ (λ _ _ → ⊤) → B) ↝⟨ →-cong₁ ext (/ᴱtrivial↔∥∥ᴱ _) ⟩□
(∥ A ∥ᴱ → B) □
where
lemma : _ ↔ _
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = λ (f , [ c ]) → rec λ where
.[]ʳ → f
.[]-respects-relationʳ _ → c _ _
.is-setʳ → B-set
; from = λ f → (f ∘ [_])
, [ (λ _ _ → cong f ([]-respects-relation _)) ]
}
; right-inverse-of = λ f → ⟨ext⟩ $ elim λ where
.[]ʳ _ → refl _
.[]-respects-relationʳ _ → B-set _ _
.is-setʳ _ → mono₁ 2 B-set
}
; left-inverse-of = λ _ → Σ-≡,≡→≡
(refl _)
(Er.H-level-Erased 1
(Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
B-set)
_ _)
}
-- The two directions of the proposition above compute in the
-- "right" way.
_ :
(@0 B-set : Is-set B) →
_≃_.to (Σ→Erased-Constant≃∥∥ᴱ→ B-set) f ∣ x ∣ ≡ proj₁ f x
_ = λ _ → refl _
_ :
(@0 B-set : Is-set B) →
proj₁ (_≃_.from (Σ→Erased-Constant≃∥∥ᴱ→ B-set) f) x ≡ f ∣ x ∣
_ = λ _ → refl _
------------------------------------------------------------------------
-- Various type formers commute with quotients
-- _⊎_ commutes with quotients.
⊎/ᴱ :
{@0 R₁ : A₁ → A₁ → Type r} {@0 R₂ : A₂ → A₂ → Type r} →
(A₁ ⊎ A₂) /ᴱ (R₁ ⊎ᴾ R₂) ≃ (A₁ /ᴱ R₁ ⊎ A₂ /ᴱ R₂)
⊎/ᴱ = Eq.↔→≃
(rec λ where
.[]ʳ → ⊎-map [_] [_]
.is-setʳ → ⊎-closure 0 /ᴱ-is-set /ᴱ-is-set
.[]-respects-relationʳ {x = inj₁ _} {y = inj₁ _} →
cong inj₁ ∘ []-respects-relation
.[]-respects-relationʳ {x = inj₂ _} {y = inj₂ _} →
cong inj₂ ∘ []-respects-relation)
Prelude.[ rec (λ where
.[]ʳ x → [ inj₁ x ]
.[]-respects-relationʳ → []-respects-relation
.is-setʳ → /ᴱ-is-set)
, rec (λ where
.[]ʳ x → [ inj₂ x ]
.[]-respects-relationʳ → []-respects-relation
.is-setʳ → /ᴱ-is-set)
]
Prelude.[ elim-prop (λ where
.[]ʳ _ → refl _
.is-propositionʳ _ → ⊎-closure 0 /ᴱ-is-set /ᴱ-is-set)
, elim-prop (λ where
.[]ʳ _ → refl _
.is-propositionʳ _ → ⊎-closure 0 /ᴱ-is-set /ᴱ-is-set)
]
(elim-prop λ where
.[]ʳ → Prelude.[ (λ _ → refl _) , (λ _ → refl _) ]
.is-propositionʳ _ → /ᴱ-is-set)
-- Maybe commutes with quotients.
--
-- Chapman, Uustalu and Veltri mention a similar result in
-- "Quotienting the Delay Monad by Weak Bisimilarity".
Maybe/ᴱ :
{@0 R : A → A → Type r} →
Maybe A /ᴱ Maybeᴾ R ≃ Maybe (A /ᴱ R)
Maybe/ᴱ {A = A} {R = R} =
Maybe A /ᴱ Maybeᴾ R ↝⟨ ⊎/ᴱ ⟩
⊤ /ᴱ Trivial ⊎ A /ᴱ R ↔⟨ /ᴱtrivial↔∥∥ᴱ _ ⊎-cong F.id ⟩
∥ ⊤ ∥ᴱ ⊎ A /ᴱ R ↔⟨ PTᴱ.∥∥ᴱ↔ (mono₁ 0 ⊤-contractible) ⊎-cong F.id ⟩□
Maybe (A /ᴱ R) □
-- A simplification lemma for Maybe/-comm.
Maybe/ᴱ-[] :
{@0 R : A → A → Type r} →
_≃_.to (Maybe/ᴱ {R = R}) ∘ [_] ≡ ⊎-map id ([_] {R = R})
Maybe/ᴱ-[] = ⟨ext⟩ λ x →
_≃_.to Maybe/ᴱ [ x ] ≡⟨⟩
⊎-map _ id (⊎-map _ id (⊎-map [_] [_] x)) ≡⟨ sym $ ⊎-map-∘ (⊎-map [_] [_] x) ⟩
⊎-map _ id (⊎-map [_] [_] x) ≡⟨ sym $ ⊎-map-∘ x ⟩∎
⊎-map id [_] x ∎
-- Cartesian products commute with quotients, assuming that the two
-- binary relations involved in the statement are reflexive.
×/ᴱ :
{@0 R₁ : A₁ → A₁ → Type r₁} {@0 R₂ : A₂ → A₂ → Type r₂} →
@0 (∀ {x} → R₁ x x) →
@0 (∀ {x} → R₂ x x) →
(A₁ × A₂) /ᴱ (R₁ ×ᴾ R₂) ≃ (A₁ /ᴱ R₁ × A₂ /ᴱ R₂)
×/ᴱ {R₁ = R₁} {R₂ = R₂} R₁-refl R₂-refl = Eq.↔→≃
(rec λ where
.is-setʳ → ×-closure 2 /ᴱ-is-set /ᴱ-is-set
.[]ʳ → Σ-map [_] [_]
.[]-respects-relationʳ {x = x₁ , x₂} {y = y₁ , y₂} →
R₁ x₁ y₁ × R₂ x₂ y₂ ↝⟨ Σ-map []-respects-relation
[]-respects-relation ⟩
[ x₁ ] ≡ [ y₁ ] × [ x₂ ] ≡ [ y₂ ] ↝⟨ uncurry (cong₂ _,_) ⟩□
([ x₁ ] , [ x₂ ]) ≡ ([ y₁ ] , [ y₂ ]) □)
(uncurry $ rec λ where
.is-setʳ →
Π-closure ext 2 λ _ →
/ᴱ-is-set
.[]ʳ x → (x ,_) /ᴱ-map λ y₁ y₂ →
R₂ y₁ y₂ ↝⟨ R₁-refl ,_ ⟩□
R₁ x x × R₂ y₁ y₂ □
.[]-respects-relationʳ {x = x₁} {y = x₂} R₁x₁x₂ →
⟨ext⟩ $ elim-prop λ @0 where
.is-propositionʳ _ →
/ᴱ-is-set
.[]ʳ y →
[ (x₁ , y) ] ≡⟨ []-respects-relation (R₁x₁x₂ , R₂-refl) ⟩∎
[ (x₂ , y) ] ∎)
(uncurry $ elim-prop λ where
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
×-closure 2 /ᴱ-is-set /ᴱ-is-set
.[]ʳ _ → elim-prop λ where
.is-propositionʳ _ →
×-closure 2 /ᴱ-is-set /ᴱ-is-set
.[]ʳ _ →
refl _)
(elim-prop λ where
.is-propositionʳ _ → /ᴱ-is-set
.[]ʳ _ → refl _)
-- The sigma type former commutes (kind of) with quotients, assuming
-- that the second projections come from propositional types.
Σ/ᴱ :
@0 (∀ {x} → Is-proposition (P x)) →
Σ (A /ᴱ R) P ≃ Σ A (P ∘ [_]) /ᴱ (R on proj₁)
Σ/ᴱ {A = A} {R = R} {P = P} prop = Eq.↔→≃
(uncurry $ elim λ where
.is-setʳ _ →
Π-closure ext 2 λ _ →
/ᴱ-is-set
.[]ʳ → curry [_]
.[]-respects-relationʳ {x = x} {y = y} r → ⟨ext⟩ λ P[y] →
subst (λ x → P x → Σ A (P ∘ [_]) /ᴱ (R on proj₁))
([]-respects-relation r)
(curry [_] x) P[y] ≡⟨ subst-→-domain P {f = curry [_] x} ([]-respects-relation r) ⟩
[ (x , subst P (sym $ []-respects-relation r) P[y]) ] ≡⟨ []-respects-relation r ⟩∎
[ (y , P[y]) ] ∎)
(rec λ where
.is-setʳ → Σ-closure 2 /ᴱ-is-set (λ _ → mono₁ 1 prop)
.[]ʳ → Σ-map [_] id
.[]-respects-relationʳ {x = (x₁ , x₂)} {y = (y₁ , y₂)} →
R x₁ y₁ ↝⟨ []-respects-relation ⟩
[ x₁ ] ≡ [ y₁ ] ↔⟨ ignore-propositional-component prop ⟩
([ x₁ ] , x₂) ≡ ([ y₁ ] , y₂) □)
(elim-prop λ where
.[]ʳ _ → refl _
.is-propositionʳ _ → /ᴱ-is-set)
(uncurry $ elim-prop λ where
.[]ʳ _ _ → refl _
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Σ-closure 2 /ᴱ-is-set (λ _ → mono₁ 1 prop))
-- Erased commutes with quotients if certain conditions hold.
Erased/ᴱ :
{@0 A : Type a} {@0 R : A → A → Type r} →
@0 Is-set A →
@0 (∀ {x y} → R x y → x ≡ y) →
Erased A /ᴱ Erasedᴾ R ≃ Erased (A /ᴱ R)
Erased/ᴱ {A = A} {R = R} set R→≡ = Eq.↔→≃
(rec λ where
.is-setʳ → Er.H-level-Erased 2 /ᴱ-is-set
.[]ʳ → Er.map [_]
.[]-respects-relationʳ [ Rxy ] →
Er.[]-cong [ []-respects-relation Rxy ])
(λ ([ x ]) → [ [ from′ x ] ])
(λ ([ x ]) →
Er.[]-cong
[ flip (elim-prop {P = λ x → [ from′ x ] ≡ x}) x (λ @0 where
.is-propositionʳ _ → /ᴱ-is-set
.[]ʳ _ → refl _)
])
(elim-prop λ where
.is-propositionʳ _ → /ᴱ-is-set
.[]ʳ _ → refl _)
where
@0 from′ : A /ᴱ R → A
from′ = rec λ @0 where
.is-setʳ → set
.[]ʳ → id
.[]-respects-relationʳ → R→≡
| {
"alphanum_fraction": 0.4621113834,
"avg_line_length": 35.6963979417,
"ext": "agda",
"hexsha": "2a3469bcc6b391cfea84cd52b90ad703aa806d5f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Quotient/Erased.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Quotient/Erased.agda",
"max_line_length": 138,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Quotient/Erased.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 8628,
"size": 20811
} |
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
-- WORKS
macro
idT : Term → Term → TC ⊤
idT = unify
-- FAILS
macro
test = unify
| {
"alphanum_fraction": 0.6838709677,
"avg_line_length": 11.9230769231,
"ext": "agda",
"hexsha": "9e8df450de318c30e3de2cf5f5bf9eca358fee7a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1943.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1943.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1943.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 52,
"size": 155
} |
-- Andreas, 2013-11-23
-- postulates are now alsow allowed in old-style mutual blocks
open import Common.Prelude
mutual
even : Nat → Bool
even zero = true
even (suc n) = odd n
postulate
odd : Nat → Bool
-- Error WAS: Postulates are not allowed in mutual blocks
| {
"alphanum_fraction": 0.6892857143,
"avg_line_length": 18.6666666667,
"ext": "agda",
"hexsha": "ebec9a40c096bd53ef84580c5e39514a518fa1c1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue977.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue977.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue977.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 83,
"size": 280
} |
module Preduploid.Functor where
open import Preduploid
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
open import Level
private
variable p q r s : Polarity
record Functor {o₁ ℓ₁ o₂ ℓ₂} (𝒞 : Preduploid o₁ ℓ₁) (𝒟 : Preduploid o₂ ℓ₂)
: Set (levelOfTerm 𝒞 ⊔ levelOfTerm 𝒟) where
private
module 𝒞 = Preduploid.Preduploid 𝒞
module 𝒟 = Preduploid.Preduploid 𝒟
open 𝒟
field
F₀ : 𝒞.Ob p -> Ob p
F₁ : forall {A : 𝒞.Ob p} {B : 𝒞.Ob q} -> A 𝒞.⇒ B -> F₀ A ⇒ F₀ B
identity : forall {A : 𝒞.Ob p} -> F₁ 𝒞.id ≡ id {A = F₀ A}
homomorphism : forall {A : 𝒞.Ob p} {B : 𝒞.Ob q} {C : 𝒞.Ob r} {f : A 𝒞.⇒ B} {g : B 𝒞.⇒ C}
-> F₁ (g 𝒞.⊙ f) ≡ F₁ g ⊙ F₁ f
| {
"alphanum_fraction": 0.6034236805,
"avg_line_length": 25.962962963,
"ext": "agda",
"hexsha": "45410144e052ce3dc05705226d0921cd698fdb31",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16def03e15bb8d71680bea60ae758ab37f4b2df9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/duploids",
"max_forks_repo_path": "Preduploid/Functor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "16def03e15bb8d71680bea60ae758ab37f4b2df9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "elpinal/duploids",
"max_issues_repo_path": "Preduploid/Functor.agda",
"max_line_length": 92,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "16def03e15bb8d71680bea60ae758ab37f4b2df9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/duploids",
"max_stars_repo_path": "Preduploid/Functor.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-13T22:35:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-09T01:39:36.000Z",
"num_tokens": 334,
"size": 701
} |
open import Prelude
open import Algebra
open import Algebra.Monus
module Codata.Segments
{ℓ}
(mon : CTMAPOM ℓ)
where
open CTMAPOM mon
private variable i j : 𝑆
-- This is a type which contains some finite and some infinite lists.
-- The idea is that each entry contains a parameter (w) which says
-- how much coinductive "fuel" it uses.
-- The Colist′ A i type represents a colist which is defined down to depth
-- i; the Colist A type represents a "true" colist, i.e. a colist defined for
-- any given depth.
infixr 5 _◃_
data Colist′ {a} (A : Type a) (i : 𝑆) : Type (a ℓ⊔ ℓ) where
_◃_ : ∀ w → -- Segment size
( (w<i : w < i) → -- If there is enough fuel left (i is the fuel)
-- (also the _<_ type is a proposition)
A × Colist′ A (i ∸ w) -- Produce an element followed by the rest of
-- the list, with w taken out of the fuel.
) →
Colist′ A i
Colist : Type a → Type (a ℓ⊔ ℓ)
Colist A = ∀ {i} → Colist′ A i
-- The main interesting things tyhis type can do are the following:
-- * Infinite lists.
-- * The "fuel" parameter can be an arbitrary monoid, not just ℕ
-- * Finite lists can also be specified, and the way we say something is
-- finite is by taking no fuel.
-- * Everything seems to correspond correctly to the monus axioms.
--------------------------------------------------------------------------------
-- Finite colists
--------------------------------------------------------------------------------
-- By adding a finite prefix you don't have to use any of the fuel.
_∹_ : A → Colist A → Colist A
x ∹ xs = ε ◃ λ _ → x , xs
--------------------------------------------------------------------------------
-- Empty colists
--------------------------------------------------------------------------------
-- To terminate computation you use all the fuel, making an empty list.
-- (I'm not sure how principled this is: semantically I don't know if I like
-- that the size of a segment can depend on the supplied size parameter).
empty : Colist A
empty {i = i} = i ◃ λ i<i → ⊥-elim (irrefl i<i)
--------------------------------------------------------------------------------
-- Finite derived colists
--------------------------------------------------------------------------------
-- singleton
pure : A → Colist A
pure x = x ∹ empty
replicate : ℕ → A → Colist A
replicate zero x = empty
replicate (suc n) x = x ∹ replicate n x
--------------------------------------------------------------------------------
-- Infinite colists
--------------------------------------------------------------------------------
-- This unfold function produces an infinite list; it needs every size segment
-- be non empty so that each step uses some fuel. This is what provides the
-- termination argument.
module _
(B : 𝑆 → Type b) -- The seed type
(ϕ : ∀ {i} → -- At depth i
B i → -- With this seed
∃ w × -- Produce a segment of size w
(w ≢ ε) × -- w can't be ε, so that we use some of the fuel to prove
-- termination
((w<i : w < i) → A × B (i ∸ w)) -- And produce the cons constructor.
)
-- ^ The step function
where
unfold′ : Acc _<_ i → B i → Colist′ A i
unfold′ a = uncurry _◃_
∘ map₂
(λ { (w≢ε , xs′) w<i →
map₂ (case a of
λ { (acc wf) →
unfold′ (wf _ (∸‿<-< _ _ w<i w≢ε)) })
(xs′ w<i) })
∘ ϕ
unfold : (fdc : WellFounded _<_)
(B : 𝑆 → Type b)
(ϕ : ∀ {i} → B i → ∃ w × (w ≢ ε) × ((w<i : w < i) → A × B (i ∸ w))) →
(∀ {i} → B i) → Colist A
unfold fdc B ϕ xs {i} = unfold′ B ϕ (fdc i) xs
-- Here's a simple example using the unfold function: this produces infinitely
-- repeated values, with segment size s.
repeat : (fdc : WellFounded _<_) (s : 𝑆) (s≢ε : s ≢ ε) (x : A) → Colist A
repeat fdc s s≢ε x = unfold fdc (const ⊤) (λ _ → s , s≢ε , const (x , tt)) tt
--------------------------------------------------------------------------------
-- Manipulating colists
--------------------------------------------------------------------------------
-- One important thing to note about the Colist type: it is inductive!
-- Although it does technically represent "coinduction", the constructors and
-- type itself are inductive as far as Agda can see. For that reason functions
-- like map pass the termination checker with no extra ceremony.
map : (A → B) → Colist′ A i → Colist′ B i
map f (w ◃ xs) = w ◃ λ w<i → case xs w<i of λ { (y , ys) → f y , map f ys }
-- You can extract a finite prefix of the colist.
open import Data.List using (List; _∷_; [])
take′ : ∀ i → Colist′ A i → List A
take′ i (w ◃ xs) with w <? i
... | no _ = []
... | yes w<i with xs w<i
... | y , ys = y ∷ take′ _ ys
take : 𝑆 → Colist A → List A
take x xs = take′ x xs
| {
"alphanum_fraction": 0.4837087691,
"avg_line_length": 37.3834586466,
"ext": "agda",
"hexsha": "376420dd166388c340d950976b5563351711c068",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Codata/Segments.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Codata/Segments.agda",
"max_line_length": 80,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Codata/Segments.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 1317,
"size": 4972
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.DistributiveLattice
{dl₁ dl₂} (DL : DistributiveLattice dl₁ dl₂)
where
open DistributiveLattice DL
import Algebra.Properties.Lattice
private
open module L = Algebra.Properties.Lattice lattice public
hiding (replace-equality)
open import Algebra.Structures
open import Algebra.FunctionProperties _≈_
open import Relation.Binary
open import Relation.Binary.Reasoning.Setoid setoid
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; module Equivalence)
open import Data.Product using (_,_)
∨-∧-distribˡ : _∨_ DistributesOverˡ _∧_
∨-∧-distribˡ x y z = begin
x ∨ y ∧ z ≈⟨ ∨-comm _ _ ⟩
y ∧ z ∨ x ≈⟨ ∨-∧-distribʳ _ _ _ ⟩
(y ∨ x) ∧ (z ∨ x) ≈⟨ ∨-comm _ _ ⟨ ∧-cong ⟩ ∨-comm _ _ ⟩
(x ∨ y) ∧ (x ∨ z) ∎
∨-∧-distrib : _∨_ DistributesOver _∧_
∨-∧-distrib = ∨-∧-distribˡ , ∨-∧-distribʳ
∧-∨-distribˡ : _∧_ DistributesOverˡ _∨_
∧-∨-distribˡ x y z = begin
x ∧ (y ∨ z) ≈⟨ ∧-congʳ $ sym (∧-absorbs-∨ _ _) ⟩
(x ∧ (x ∨ y)) ∧ (y ∨ z) ≈⟨ ∧-congʳ $ ∧-congˡ $ ∨-comm _ _ ⟩
(x ∧ (y ∨ x)) ∧ (y ∨ z) ≈⟨ ∧-assoc _ _ _ ⟩
x ∧ ((y ∨ x) ∧ (y ∨ z)) ≈⟨ ∧-congˡ $ sym (∨-∧-distribˡ _ _ _) ⟩
x ∧ (y ∨ x ∧ z) ≈⟨ ∧-congʳ $ sym (∨-absorbs-∧ _ _) ⟩
(x ∨ x ∧ z) ∧ (y ∨ x ∧ z) ≈⟨ sym $ ∨-∧-distribʳ _ _ _ ⟩
x ∧ y ∨ x ∧ z ∎
∧-∨-distribʳ : _∧_ DistributesOverʳ _∨_
∧-∨-distribʳ x y z = begin
(y ∨ z) ∧ x ≈⟨ ∧-comm _ _ ⟩
x ∧ (y ∨ z) ≈⟨ ∧-∨-distribˡ _ _ _ ⟩
x ∧ y ∨ x ∧ z ≈⟨ ∧-comm _ _ ⟨ ∨-cong ⟩ ∧-comm _ _ ⟩
y ∧ x ∨ z ∧ x ∎
∧-∨-distrib : _∧_ DistributesOver _∨_
∧-∨-distrib = ∧-∨-distribˡ , ∧-∨-distribʳ
-- The dual construction is also a distributive lattice.
∧-∨-isDistributiveLattice : IsDistributiveLattice _≈_ _∧_ _∨_
∧-∨-isDistributiveLattice = record
{ isLattice = ∧-∨-isLattice
; ∨-∧-distribʳ = ∧-∨-distribʳ
}
∧-∨-distributiveLattice : DistributiveLattice _ _
∧-∨-distributiveLattice = record
{ _∧_ = _∨_
; _∨_ = _∧_
; isDistributiveLattice = ∧-∨-isDistributiveLattice
}
-- One can replace the underlying equality with an equivalent one.
replace-equality :
{_≈′_ : Rel Carrier dl₂} →
(∀ {x y} → x ≈ y ⇔ (x ≈′ y)) → DistributiveLattice _ _
replace-equality {_≈′_} ≈⇔≈′ = record
{ _≈_ = _≈′_
; _∧_ = _∧_
; _∨_ = _∨_
; isDistributiveLattice = record
{ isLattice = Lattice.isLattice (L.replace-equality ≈⇔≈′)
; ∨-∧-distribʳ = λ x y z → to ⟨$⟩ ∨-∧-distribʳ x y z
}
} where open module E {x y} = Equivalence (≈⇔≈′ {x} {y})
| {
"alphanum_fraction": 0.5306262904,
"avg_line_length": 33.0227272727,
"ext": "agda",
"hexsha": "e393d36e48ec105ffb384ff1d2b9d9f25aa35579",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/DistributiveLattice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/DistributiveLattice.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/DistributiveLattice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1238,
"size": 2906
} |
-- Andreas, 2020-03-27, issue #3684
-- Warn about invalid fields instead of hard error.
module TooManyFields where
postulate X : Set
record D : Set where
field x : X
d : X -> D
d x = record {x = x; y = x}
| {
"alphanum_fraction": 0.654028436,
"avg_line_length": 16.2307692308,
"ext": "agda",
"hexsha": "8a7eef3a63bd36d4d7fcd6765501176046f080ed",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/TooManyFields.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/TooManyFields.agda",
"max_line_length": 51,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/TooManyFields.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 69,
"size": 211
} |
module Logic{ℓ} where
-- open import Logic
-- open import Logic.Classical
-- Everything is computably decidable
-- instance postulate classical : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P)
Stmt : _
Stmt = Set(ℓ) -- Prop(ℓ)
open import Agda.Primitive public
renaming (Setω to Stmtω)
| {
"alphanum_fraction": 0.7050359712,
"avg_line_length": 19.8571428571,
"ext": "agda",
"hexsha": "c18b2cb53de3dd8dd0e3bcae557a488126f66b9a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Mathematical/Logic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Mathematical/Logic.agda",
"max_line_length": 66,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Mathematical/Logic.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 83,
"size": 278
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to Fin, and operations making use of these
-- properties (or other properties not available in Data.Fin)
------------------------------------------------------------------------
module Data.Fin.Properties where
open import Algebra
open import Data.Fin
open import Data.Nat as N
using (ℕ; zero; suc; s≤s; z≤n; _∸_)
renaming (_≤_ to _ℕ≤_; _<_ to _ℕ<_; _+_ to _ℕ+_)
import Data.Nat.Properties as N
open import Data.Product
open import Function
open import Function.Equality as FunS using (_⟨$⟩_)
open import Function.Injection using (_↣_)
open import Algebra.FunctionProperties
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; cong; subst)
open import Category.Functor
open import Category.Applicative
------------------------------------------------------------------------
-- Properties
private
drop-suc : ∀ {o} {m n : Fin o} → Fin.suc m ≡ suc n → m ≡ n
drop-suc refl = refl
preorder : ℕ → Preorder _ _ _
preorder n = P.preorder (Fin n)
setoid : ℕ → Setoid _ _
setoid n = P.setoid (Fin n)
strictTotalOrder : ℕ → StrictTotalOrder _ _ _
strictTotalOrder n = record
{ Carrier = Fin n
; _≈_ = _≡_
; _<_ = _<_
; isStrictTotalOrder = record
{ isEquivalence = P.isEquivalence
; trans = N.<-trans
; compare = cmp
; <-resp-≈ = P.resp₂ _<_
}
}
where
cmp : ∀ {n} → Trichotomous _≡_ (_<_ {n})
cmp zero zero = tri≈ (λ()) refl (λ())
cmp zero (suc j) = tri< (s≤s z≤n) (λ()) (λ())
cmp (suc i) zero = tri> (λ()) (λ()) (s≤s z≤n)
cmp (suc i) (suc j) with cmp i j
... | tri< lt ¬eq ¬gt = tri< (s≤s lt) (¬eq ∘ drop-suc) (¬gt ∘ N.≤-pred)
... | tri> ¬lt ¬eq gt = tri> (¬lt ∘ N.≤-pred) (¬eq ∘ drop-suc) (s≤s gt)
... | tri≈ ¬lt eq ¬gt = tri≈ (¬lt ∘ N.≤-pred) (cong suc eq) (¬gt ∘ N.≤-pred)
decSetoid : ℕ → DecSetoid _ _
decSetoid n = StrictTotalOrder.decSetoid (strictTotalOrder n)
infix 4 _≟_
_≟_ : {n : ℕ} → Decidable {A = Fin n} _≡_
_≟_ {n} = DecSetoid._≟_ (decSetoid n)
to-from : ∀ n → toℕ (fromℕ n) ≡ n
to-from zero = refl
to-from (suc n) = cong suc (to-from n)
toℕ-injective : ∀ {n} {i j : Fin n} → toℕ i ≡ toℕ j → i ≡ j
toℕ-injective {zero} {} {} _
toℕ-injective {suc n} {zero} {zero} eq = refl
toℕ-injective {suc n} {zero} {suc j} ()
toℕ-injective {suc n} {suc i} {zero} ()
toℕ-injective {suc n} {suc i} {suc j} eq =
cong suc (toℕ-injective (cong N.pred eq))
bounded : ∀ {n} (i : Fin n) → toℕ i ℕ< n
bounded zero = s≤s z≤n
bounded (suc i) = s≤s (bounded i)
prop-toℕ-≤ : ∀ {n} (x : Fin n) → toℕ x ℕ≤ N.pred n
prop-toℕ-≤ zero = z≤n
prop-toℕ-≤ (suc {n = zero} ())
prop-toℕ-≤ (suc {n = suc n} i) = s≤s (prop-toℕ-≤ i)
nℕ-ℕi≤n : ∀ n i → n ℕ-ℕ i ℕ≤ n
nℕ-ℕi≤n n zero = begin n ∎
where open N.≤-Reasoning
nℕ-ℕi≤n zero (suc ())
nℕ-ℕi≤n (suc n) (suc i) = begin
n ℕ-ℕ i ≤⟨ nℕ-ℕi≤n n i ⟩
n ≤⟨ N.n≤1+n n ⟩
suc n ∎
where open N.≤-Reasoning
inject-lemma : ∀ {n} {i : Fin n} (j : Fin′ i) →
toℕ (inject j) ≡ toℕ j
inject-lemma {i = zero} ()
inject-lemma {i = suc i} zero = refl
inject-lemma {i = suc i} (suc j) = cong suc (inject-lemma j)
inject+-lemma : ∀ {m} n (i : Fin m) → toℕ i ≡ toℕ (inject+ n i)
inject+-lemma n zero = refl
inject+-lemma n (suc i) = cong suc (inject+-lemma n i)
inject₁-lemma : ∀ {m} (i : Fin m) → toℕ (inject₁ i) ≡ toℕ i
inject₁-lemma zero = refl
inject₁-lemma (suc i) = cong suc (inject₁-lemma i)
inject≤-lemma : ∀ {m n} (i : Fin m) (le : m ℕ≤ n) →
toℕ (inject≤ i le) ≡ toℕ i
inject≤-lemma zero (N.s≤s le) = refl
inject≤-lemma (suc i) (N.s≤s le) = cong suc (inject≤-lemma i le)
≺⇒<′ : _≺_ ⇒ N._<′_
≺⇒<′ (n ≻toℕ i) = N.≤⇒≤′ (bounded i)
<′⇒≺ : N._<′_ ⇒ _≺_
<′⇒≺ {n} N.≤′-refl = subst (λ i → i ≺ suc n) (to-from n)
(suc n ≻toℕ fromℕ n)
<′⇒≺ (N.≤′-step m≤′n) with <′⇒≺ m≤′n
<′⇒≺ (N.≤′-step m≤′n) | n ≻toℕ i =
subst (λ i → i ≺ suc n) (inject₁-lemma i) (suc n ≻toℕ (inject₁ i))
toℕ-raise : ∀ {m} n (i : Fin m) → toℕ (raise n i) ≡ n ℕ+ toℕ i
toℕ-raise zero i = refl
toℕ-raise (suc n) i = cong suc (toℕ-raise n i)
fromℕ≤-toℕ : ∀ {m} (i : Fin m) (i<m : toℕ i ℕ< m) → fromℕ≤ i<m ≡ i
fromℕ≤-toℕ zero (s≤s z≤n) = refl
fromℕ≤-toℕ (suc i) (s≤s (s≤s m≤n)) = cong suc (fromℕ≤-toℕ i (s≤s m≤n))
toℕ-fromℕ≤ : ∀ {m n} (m<n : m ℕ< n) → toℕ (fromℕ≤ m<n) ≡ m
toℕ-fromℕ≤ (s≤s z≤n) = refl
toℕ-fromℕ≤ (s≤s (s≤s m<n)) = cong suc (toℕ-fromℕ≤ (s≤s m<n))
------------------------------------------------------------------------
-- Operations
infixl 6 _+′_
_+′_ : ∀ {m n} (i : Fin m) (j : Fin n) → Fin (N.pred m ℕ+ n)
i +′ j = inject≤ (i + j) (N._+-mono_ (prop-toℕ-≤ i) ≤-refl)
where open DecTotalOrder N.decTotalOrder renaming (refl to ≤-refl)
-- reverse {n} "i" = "n ∸ 1 ∸ i".
reverse : ∀ {n} → Fin n → Fin n
reverse {zero} ()
reverse {suc n} i = inject≤ (n ℕ- i) (N.n∸m≤n (toℕ i) (suc n))
reverse-prop : ∀ {n} → (i : Fin n) → toℕ (reverse i) ≡ n ∸ suc (toℕ i)
reverse-prop {zero} ()
reverse-prop {suc n} i = begin
toℕ (inject≤ (n ℕ- i) _) ≡⟨ inject≤-lemma _ _ ⟩
toℕ (n ℕ- i) ≡⟨ toℕ‿ℕ- n i ⟩
n ∸ toℕ i ∎
where
open P.≡-Reasoning
toℕ‿ℕ- : ∀ n i → toℕ (n ℕ- i) ≡ n ∸ toℕ i
toℕ‿ℕ- n zero = to-from n
toℕ‿ℕ- zero (suc ())
toℕ‿ℕ- (suc n) (suc i) = toℕ‿ℕ- n i
reverse-involutive : ∀ {n} → Involutive _≡_ reverse
reverse-involutive {n} i = toℕ-injective (begin
toℕ (reverse (reverse i)) ≡⟨ reverse-prop _ ⟩
n ∸ suc (toℕ (reverse i)) ≡⟨ eq ⟩
toℕ i ∎)
where
open P.≡-Reasoning
open CommutativeSemiring N.commutativeSemiring using (+-comm)
lem₁ : ∀ m n → (m ℕ+ n) ∸ (m ℕ+ n ∸ m) ≡ m
lem₁ m n = begin
m ℕ+ n ∸ (m ℕ+ n ∸ m) ≡⟨ cong (λ ξ → m ℕ+ n ∸ (ξ ∸ m)) (+-comm m n) ⟩
m ℕ+ n ∸ (n ℕ+ m ∸ m) ≡⟨ cong (λ ξ → m ℕ+ n ∸ ξ) (N.m+n∸n≡m n m) ⟩
m ℕ+ n ∸ n ≡⟨ N.m+n∸n≡m m n ⟩
m ∎
lem₂ : ∀ n → (i : Fin n) → n ∸ suc (n ∸ suc (toℕ i)) ≡ toℕ i
lem₂ zero ()
lem₂ (suc n) i = begin
n ∸ (n ∸ toℕ i) ≡⟨ cong (λ ξ → ξ ∸ (ξ ∸ toℕ i)) i+j≡k ⟩
(toℕ i ℕ+ j) ∸ (toℕ i ℕ+ j ∸ toℕ i) ≡⟨ lem₁ (toℕ i) j ⟩
toℕ i ∎
where
decompose-n : ∃ λ j → n ≡ toℕ i ℕ+ j
decompose-n = n ∸ toℕ i , P.sym (N.m+n∸m≡n (prop-toℕ-≤ i))
j = proj₁ decompose-n
i+j≡k = proj₂ decompose-n
eq : n ∸ suc (toℕ (reverse i)) ≡ toℕ i
eq = begin
n ∸ suc (toℕ (reverse i)) ≡⟨ cong (λ ξ → n ∸ suc ξ) (reverse-prop i) ⟩
n ∸ suc (n ∸ suc (toℕ i)) ≡⟨ lem₂ n i ⟩
toℕ i ∎
-- If there is an injection from a type to a finite set, then the type
-- has decidable equality.
eq? : ∀ {a n} {A : Set a} → A ↣ Fin n → Decidable {A = A} _≡_
eq? inj = Dec.via-injection inj _≟_
-- Quantification over finite sets commutes with applicative functors.
sequence : ∀ {F n} {P : Fin n → Set} → RawApplicative F →
(∀ i → F (P i)) → F (∀ i → P i)
sequence {F} RA = helper _ _
where
open RawApplicative RA
helper : ∀ n (P : Fin n → Set) → (∀ i → F (P i)) → F (∀ i → P i)
helper zero P ∀iPi = pure (λ())
helper (suc n) P ∀iPi =
combine <$> ∀iPi zero ⊛ helper n (λ n → P (suc n)) (∀iPi ∘ suc)
where
combine : P zero → (∀ i → P (suc i)) → ∀ i → P i
combine z s zero = z
combine z s (suc i) = s i
private
-- Included just to show that sequence above has an inverse (under
-- an equivalence relation with two equivalence classes, one with
-- all inhabited sets and the other with all uninhabited sets).
sequence⁻¹ : ∀ {F}{A} {P : A → Set} → RawFunctor F →
F (∀ i → P i) → ∀ i → F (P i)
sequence⁻¹ RF F∀iPi i = (λ f → f i) <$> F∀iPi
where open RawFunctor RF
| {
"alphanum_fraction": 0.5143214509,
"avg_line_length": 33.1742738589,
"ext": "agda",
"hexsha": "c2a8b1164602c5ffcc75699529309750dfc28a27",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Fin/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Fin/Properties.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Fin/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 3473,
"size": 7995
} |
module container.m.level where
open import level
open import sum
open import equality.core
open import equality.calculus
open import function.core
open import function.isomorphism
open import function.extensionality
open import sets.unit
open import sets.nat.core
open import hott.level
open import hott.univalence
open import container.core
open import container.equality
open import container.fixpoint
open import container.m.core
open import container.m.extensionality
private
module Properties {li la lb}
{c : Container li la lb}
(hA : ∀ i → contr (Container.A c i)) where
open Definition c
open Extensionality c
open Fixpoint (fix M fixpoint)
using (head; tail)
module S where
module local where
open Equality c (fix M fixpoint)
using (equality)
open Definition equality public
open Fixpoint (fix local.M local.fixpoint) public
using (head; tail)
open local public
center : ∀ {i} → M i
center {i} = inf (proj₁ (hA i)) λ _ → ♯ center
contraction : ∀ {i} (x : M i) → center ≡ x
contraction {i} x = mext (lem' x)
where
coalg : ∀ {i}{x y : M i}
→ center ≡ x
→ Σ (head x ≡ head y) λ p
→ ((b : B (head x)) → center ≡ tail x b)
coalg {i}{y = y} refl
= proj₂ (hA i) (head y)
, λ b → refl
lem' : ∀ {i}(x : M i) → center ≡M x
lem' _ = S.unfold (λ _ → coalg) _ refl
m-contr : ∀ i → contr (M i)
m-contr i = center , contraction
-- Lemma 14 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
m-level : ∀ {n li la lb} {c : Container li la lb}
→ let open Definition c
in ((i : I) → h n (A i))
→ (i : I) → h n (M i)
m-level {n = 0} hA i = Properties.m-contr hA i
m-level {n = suc n} {c = c} hA i = λ xs ys
→ retract-level mext mext-inv mext-retraction (ih xs ys)
where
open Definition c
open Extensionality c
open Fixpoint (fix M fixpoint)
using (head; tail)
ih : (xs ys : M i) → h n (xs ≡M ys)
ih xs ys = m-level (λ { (i , xs , ys) → hA i (head xs) (head ys) })
(i , xs , ys)
| {
"alphanum_fraction": 0.5808057945,
"avg_line_length": 29.0657894737,
"ext": "agda",
"hexsha": "7b0d54b8a9395901bc970fbac678d2313b424f6f",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/m/level.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "container/m/level.agda",
"max_line_length": 74,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/m/level.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 666,
"size": 2209
} |
import Lvl
open import Data.Boolean
open import Type
module Data.List.Sorting.InsertionSort {ℓ} {T : Type{ℓ}} (_≤?_ : T → T → Bool) where
open import Data.List
import Data.List.Functions as List
open import Data.List.Sorting.Functions(_≤?_)
insertion-sort : List(T) → List(T)
insertion-sort = List.foldᵣ insert ∅
module Proofs where
open import Data.Boolean.Stmt
open import Data.List.Relation.Permutation
open import Data.List.Sorting(_≤?_)
open import Data.List.Sorting.Proofs(_≤?_)
open import Functional using (_∘₂_)
open import Logic.Propositional
open import Relator.Equals
open import Structure.Relator.Properties
open import Syntax.Transitivity
module _ (asym : ∀{x y} → (x ≤? y ≡ not(y ≤? x))) where -- TODO: Use Structure.Relator.Properties.Asymmetry by the relation (IsTrue ∘₂ (_≤?_))
instance
insertion-sort-sorted-proof : ∀{l} → Sorted(insertion-sort l)
insertion-sort-sorted-proof {∅} = empty
insertion-sort-sorted-proof {x ⊰ l} = insert-sorted-proof asym (insertion-sort-sorted-proof {l})
insert-permutation-proof : ∀{x}{l} → ((insert x l) permutes (x ⊰ l))
insert-permutation-proof {x} {∅} = prepend _permutes_.empty
insert-permutation-proof {x} {a ⊰ l} with (x ≤? a)
... | 𝑇 = reflexivity(_permutes_)
... | 𝐹 =
a ⊰ insert x l 🝖-[ _permutes_.prepend (insert-permutation-proof {x} {l}) ]
a ⊰ x ⊰ l 🝖-[ _permutes_.swap ]
x ⊰ a ⊰ l 🝖-end
instance
insertion-sort-permutation-proof : ∀{l} → ((insertion-sort l) permutes l)
insertion-sort-permutation-proof {∅} = _permutes_.empty
insertion-sort-permutation-proof {x ⊰ l} =
insertion-sort (x ⊰ l) 🝖-[ insert-permutation-proof ]
x ⊰ (insertion-sort l) 🝖-[ prepend (insertion-sort-permutation-proof {l}) ]
x ⊰ l 🝖-end
instance
insertion-sort-sorting-algorithm : SortingAlgorithm(insertion-sort)
SortingAlgorithm.sorts insertion-sort-sorting-algorithm {l} = insertion-sort-sorted-proof {l}
SortingAlgorithm.permutes insertion-sort-sorting-algorithm = insertion-sort-permutation-proof
| {
"alphanum_fraction": 0.6646455224,
"avg_line_length": 41.2307692308,
"ext": "agda",
"hexsha": "e7c4edcd6268061e73874add54ac9719b10414b4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/List/Sorting/InsertionSort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/List/Sorting/InsertionSort.agda",
"max_line_length": 144,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/List/Sorting/InsertionSort.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 625,
"size": 2144
} |
module Verifier where
open import ModusPonens using (modusPonens)
check : ∀ {P Q : Set} → (P → Q) → P → Q
check = modusPonens
| {
"alphanum_fraction": 0.671875,
"avg_line_length": 18.2857142857,
"ext": "agda",
"hexsha": "d81c1bbb0f2a24d2e62cb866d755ee47102de064",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "danr/agder",
"max_forks_repo_path": "problems/ModusPonens/Verifier.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "danr/agder",
"max_issues_repo_path": "problems/ModusPonens/Verifier.agda",
"max_line_length": 43,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "danr/agder",
"max_stars_repo_path": "problems/ModusPonens/Verifier.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-17T12:07:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-17T12:07:03.000Z",
"num_tokens": 48,
"size": 128
} |
{-# OPTIONS --cubical #-}
module Multidimensional.Data.DirNum.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty
open import Cubical.Data.Prod
open import Cubical.Data.Bool
open import Cubical.Data.Nat
open import Cubical.Relation.Nullary
open import Multidimensional.Data.Dir
open import Multidimensional.Data.DirNum.Base
open import Multidimensional.Data.Extra.Nat
double-lemma : ∀ {r} → (d : DirNum r) →
doubleℕ (DirNum→ℕ d) ≡ DirNum→ℕ (doubleDirNum+ r d)
double-lemma {r} d = refl
¬↓,d≡↑,d′ : ∀ {n} → ∀ (d d′ : DirNum n) → ¬ (↓ , d) ≡ (↑ , d′)
¬↓,d≡↑,d′ {n} d d′ ↓,d≡↑,d′ = ¬↓≡↑ (cong proj₁ ↓,d≡↑,d′)
¬↑,d≡↓,d′ : ∀ {n} → ∀ (d d′ : DirNum n) → ¬ (↑ , d) ≡ (↓ , d′)
¬↑,d≡↓,d′ {n} d d′ ↑,d≡↓,d′ = ¬↑≡↓ (cong proj₁ ↑,d≡↓,d′)
-- dropping least significant bit preserves equality
-- TODO: this was copied over from Direction.agda ; redefine using DropLeast
dropLeast≡ : ∀ {n} → ∀ (ds ds′ : DirNum n) (d : Dir)
→ ((d , ds) ≡ (d , ds′)) → ds ≡ ds′
dropLeast≡ {n} ds ds′ d d,ds≡d,ds′ = cong proj₂ d,ds≡d,ds′
zero-n→0 : ∀ {r} → DirNum→ℕ (zero-n r) ≡ zero
zero-n→0 {zero} = refl
zero-n→0 {suc r} =
doubleℕ (DirNum→ℕ (zero-n r))
≡⟨ cong doubleℕ (zero-n→0 {r}) ⟩
doubleℕ zero
≡⟨ refl ⟩
zero
∎
zero-n? : ∀ {n} → (x : DirNum n) → Dec (x ≡ zero-n n)
zero-n? {zero} tt = yes refl
zero-n? {suc n} (↓ , ds) with zero-n? ds
... | no ds≠zero-n = no (λ y →
ds≠zero-n (dropLeast≡ ds (zero-n n) ↓ y))
... | yes ds≡zero-n = yes (cong (λ y → (↓ , y)) ds≡zero-n)
zero-n? {suc n} (↑ , ds) = no ((¬↑,d≡↓,d′ ds (zero-n n)))
zero-n≡0 : {r : ℕ} → DirNum→ℕ (zero-n r) ≡ zero
zero-n≡0{zero} = refl
zero-n≡0 {suc r} =
doubleℕ (DirNum→ℕ {r} (zero-n r))
≡⟨ cong doubleℕ (zero-n≡0 {r}) ⟩
0
∎
-- x is doubleable as a DirNum precisely when x's most significant bit is 0
-- this should return a Dec
doubleable-n? : {n : ℕ} → (x : DirNum n) → Bool
doubleable-n? {zero} tt = false
doubleable-n? {suc n} (x , x₁) with zero-n? x₁
... | yes _ = true
... | no _ = doubleable-n? x₁
max→ℕ : (r : ℕ) → DirNum→ℕ (max-n r) ≡ predℕ (doublesℕ r 1)
max→ℕ zero = refl
max→ℕ (suc r) =
suc (doubleℕ (DirNum→ℕ (max-n r)))
≡⟨ cong (λ z → suc (doubleℕ z)) (max→ℕ r) ⟩
suc (doubleℕ (predℕ (doublesℕ r 1)))
≡⟨ cong suc (doublePred (doublesℕ r 1)) ⟩
suc (predℕ (predℕ (doubleℕ (doublesℕ r 1))))
≡⟨ cong (λ z → suc (predℕ (predℕ z))) (doubleDoubles r 1) ⟩
suc (predℕ (predℕ (doublesℕ (suc r) 1)))
≡⟨ refl ⟩
suc (predℕ (predℕ (doublesℕ r 2)))
≡⟨ sucPred (predℕ (doublesℕ r 2)) H ⟩
predℕ (doublesℕ r 2)
∎
where
G : (r : ℕ) → doubleℕ (doublesℕ r 1) ≡ doublesℕ r 2
G zero = refl
G (suc r) = doubleℕ (doublesℕ r 2) ≡⟨ doubleDoubles r 2 ⟩
doublesℕ (suc r) 2 ≡⟨ refl ⟩ doublesℕ r (doubleℕ 2) ∎
H : ¬ predℕ (doublesℕ r 2) ≡ zero
H = λ h → (predDoublePos (doublesℕ r 1) (doublesPos r 1 snotz)
((
predℕ (doubleℕ (doublesℕ r 1)) ≡⟨ cong predℕ (G r) ⟩
predℕ (doublesℕ r 2) ≡⟨ h ⟩
0 ∎
)))
max? : ∀ {n} → (x : DirNum n) → Dec (x ≡ max-n n)
max? {zero} tt = yes refl
max? {suc n} (↓ , ds) = no ((¬↓,d≡↑,d′ ds (max-n n)))
max? {suc n} (↑ , ds) with max? ds
... | yes ds≡max-n = yes (
(↑ , ds)
≡⟨ cong (λ x → (↑ , x)) ds≡max-n ⟩
(↑ , max-n n)
∎
)
... | no ¬ds≡max-n = no (λ d,ds≡d,max-n →
¬ds≡max-n ((dropLeast≡ ds (max-n n) ↑ d,ds≡d,max-n)))
maxn+1≡↑maxn : ∀ n → max-n (suc n) ≡ (↑ , (max-n n))
maxn+1≡↑maxn n = refl
maxr≡pred2ʳ : (r : ℕ) (d : DirNum r) →
d ≡ max-n r → DirNum→ℕ d ≡ predℕ (doublesℕ r (suc zero))
maxr≡pred2ʳ zero d d≡max = refl
maxr≡pred2ʳ (suc r) (↓ , ds) d≡max = ⊥-elim ((¬↓,d≡↑,d′ ds (max-n r)) d≡max)
maxr≡pred2ʳ (suc r) (↑ , ds) d≡max =
suc (doubleℕ (DirNum→ℕ ds))
≡⟨ cong (λ x → suc (doubleℕ x)) (maxr≡pred2ʳ r ds ds≡max) ⟩
suc (doubleℕ (predℕ (doublesℕ r (suc zero)))) -- 2*(2^r - 1) + 1 = 2^r+1 - 1
≡⟨ cong suc (doublePred (doublesℕ r (suc zero))) ⟩
suc (predℕ (predℕ (doubleℕ (doublesℕ r (suc zero)))))
≡⟨ sucPred (predℕ (doubleℕ (doublesℕ r (suc zero)))) (
(predDoublePos (doublesℕ r (suc zero)) ((doublesPos r 1 snotz)))) ⟩
predℕ (doubleℕ (doublesℕ r (suc zero)))
≡⟨ cong predℕ (doubleDoubles r (suc zero)) ⟩
predℕ (doublesℕ (suc r) 1)
≡⟨ refl ⟩
predℕ (doublesℕ r 2) -- 2^r*2 - 1 = 2^(r+1) - 1
∎
where
ds≡max : ds ≡ max-n r
ds≡max = dropLeast≡ ds (max-n r) ↑ d≡max
-- TODO: rename?
nextsuc-lemma : (r : ℕ) (x : DirNum r) →
¬ ((sucDoubleDirNum+ r x) ≡ max-n (suc r)) → ¬ (x ≡ max-n r)
nextsuc-lemma zero tt ¬H = ⊥-elim (¬H refl)
nextsuc-lemma (suc r) (↓ , x) ¬H = ¬↓,d≡↑,d′ x (max-n r)
nextsuc-lemma (suc r) (↑ , x) ¬H =
λ h → ¬H (H (dropLeast≡ x (max-n r) ↑ h)) --⊥-elim (¬H H)
where
H : (x ≡ max-n r) →
sucDoubleDirNum+ (suc r) (↑ , x) ≡ (↑ , (↑ , max-n r))
H x≡maxnr =
sucDoubleDirNum+ (suc r) (↑ , x)
≡⟨ cong (λ y → sucDoubleDirNum+ (suc r) (↑ , y)) x≡maxnr ⟩
sucDoubleDirNum+ (suc r) (↑ , max-n r)
≡⟨ refl ⟩
(↑ , (↑ , max-n r))
∎
next≡suc : (r : ℕ) (x : DirNum r) →
¬ (x ≡ max-n r) → DirNum→ℕ (next x) ≡ suc (DirNum→ℕ x)
next≡suc zero tt ¬x≡maxnr = ⊥-elim (¬x≡maxnr refl)
next≡suc (suc r) (↓ , x) ¬x≡maxnr = refl
next≡suc (suc r) (↑ , x) ¬x≡maxnr =
doubleℕ (DirNum→ℕ (next x))
≡⟨ cong doubleℕ (next≡suc r x (nextsuc-lemma r x ¬x≡maxnr)) ⟩
doubleℕ (suc (DirNum→ℕ x))
≡⟨ refl ⟩
suc (suc (doubleℕ (DirNum→ℕ x)))
∎
| {
"alphanum_fraction": 0.5239114918,
"avg_line_length": 33.7590361446,
"ext": "agda",
"hexsha": "f2f27f6c0bee85499927465599bd3e497deb7d09",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_forks_repo_path": "Multidimensional/Data/DirNum/Properties.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_issues_repo_issues_event_max_datetime": "2019-07-02T16:24:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-19T20:40:07.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_issues_repo_path": "Multidimensional/Data/DirNum/Properties.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_stars_repo_path": "Multidimensional/Data/DirNum/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2628,
"size": 5604
} |
{-# OPTIONS --verbose=10 #-}
module leafs where
open import Data.Nat
open import Data.Vec
open import Agda.Builtin.Sigma
open import Data.Product
open import Data.Fin using (fromℕ)
open import trees
open import optics
open import lemmas
leafsTree : {A : Set} -> Tree A -> ∃[ n ] (Vec A n × (Vec A n -> Tree A))
leafsTree empty = 0 , ([] , λ _ -> empty)
leafsTree (node empty root empty) =
(1 , (root ∷ [] , λ v -> node empty (head v) empty))
leafsTree {A} (node left root right) with leafsTree left | leafsTree right
... | (n1 , (g1 , p1)) | (n2 , (g2 , p2)) =
(n1 + n2 , (g1 ++ g2 , λ v -> node (p1 (take n1 v)) root (p2 (drop n1 v))))
leafs : {A : Set} -> Traversal (Tree A) (Tree A) A A
leafs = record{ extract = leafsTree }
module tests where
tree1 : Tree ℕ
tree1 = node (node empty 1 empty) 3 empty
open Traversal
leafs1 : Vec ℕ 1
leafs1 = get leafs tree1
updatedleafs1 : Tree ℕ
updatedleafs1 = put leafs (node tree1 5 tree1) (2 ∷ 5 ∷ [])
| {
"alphanum_fraction": 0.574906367,
"avg_line_length": 28.1052631579,
"ext": "agda",
"hexsha": "538d05c7122459b6d66298859dcd3ab4d46da28d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "hablapps/safeoptics",
"max_forks_repo_path": "src/main/agda/leafs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "hablapps/safeoptics",
"max_issues_repo_path": "src/main/agda/leafs.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "hablapps/safeoptics",
"max_stars_repo_path": "src/main/agda/leafs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 367,
"size": 1068
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Yoneda where
-- Yoneda Lemma. In total, provides:
-- * the Yoneda Embedding (called embed here) from any Category C into Presheaves C
-- Worth noticing that there is no 'locally small' condition here; however, if one looks at
-- the levels involved, there is indeed a raise from that of C to that of Presheaves C.
-- * The traditional Yoneda lemma (yoneda-inverse) which says that for any object a of C, and
-- any Presheaf F over C (where our presheaves are over Setoids), then
-- Hom[ Presheaves C] (Functor.F₀ embed a , F) ≅ Functor.F₀ F a
-- as Setoids. In addition, Yoneda (yoneda) also says that this isomorphism is natural in a and F.
open import Level
open import Function.Base using (_$_)
open import Function.Bundles using (Inverse)
open import Function.Equality using (Π; _⟨$⟩_; cong)
open import Relation.Binary.Bundles using (module Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
open import Data.Product using (_,_; Σ)
open import Categories.Category using (Category; _[_,_])
open import Categories.Category.Product using (πʳ; πˡ; _※_)
open import Categories.Category.Construction.Presheaves using (Presheaves)
open import Categories.Category.Construction.Functors using (eval)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.Functor.Hom using (module Hom; Hom[_][-,_]; Hom[_][-,-])
open import Categories.Functor.Bifunctor using (Bifunctor)
open import Categories.Functor.Presheaf using (Presheaf)
open import Categories.Functor.Construction.LiftSetoids using (LiftSetoids)
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
import Categories.NaturalTransformation.Hom as NT-Hom
private
variable
o ℓ e : Level
module Yoneda (C : Category o ℓ e) where
open Category C hiding (op) -- uses lots
open HomReasoning using (_○_; ⟺)
open MR C using (id-comm)
open NaturalTransformation using (η; commute)
open NT-Hom C using (Hom[A,C]⇒Hom[B,C])
private
module CE = Category.Equiv C using (refl)
module C = Category C using (op)
-- The Yoneda embedding functor
embed : Functor C (Presheaves C)
embed = record
{ F₀ = Hom[ C ][-,_]
; F₁ = Hom[A,C]⇒Hom[B,C] -- A⇒B induces a NatTrans on the Homs.
; identity = identityˡ ○_
; homomorphism = λ h₁≈h₂ → ∘-resp-≈ʳ h₁≈h₂ ○ assoc
; F-resp-≈ = λ f≈g h≈i → ∘-resp-≈ f≈g h≈i
}
-- Using the adjunction between product and product, we get a kind of contravariant Bifunctor
yoneda-inverse : (a : Obj) (F : Presheaf C (Setoids ℓ e)) →
Inverse (Category.hom-setoid (Presheaves C) {Functor.F₀ embed a} {F}) (Functor.F₀ F a)
yoneda-inverse a F = record
{ f = λ nat → η nat a ⟨$⟩ id
; f⁻¹ = λ x → ntHelper record
{ η = λ X → record
{ _⟨$⟩_ = λ X⇒a → F.₁ X⇒a ⟨$⟩ x
; cong = λ i≈j → F.F-resp-≈ i≈j SE.refl
}
; commute = λ {X} {Y} Y⇒X {f} {g} f≈g →
let module SR = SetoidR (F.₀ Y) in
SR.begin
F.₁ (id ∘ f ∘ Y⇒X) ⟨$⟩ x SR.≈⟨ F.F-resp-≈ (identityˡ ○ ∘-resp-≈ˡ f≈g) (SE.refl {x}) ⟩
F.₁ (g ∘ Y⇒X) ⟨$⟩ x SR.≈⟨ F.homomorphism SE.refl ⟩
F.₁ Y⇒X ⟨$⟩ (F.₁ g ⟨$⟩ x)
SR.∎
}
; cong₁ = λ i≈j → i≈j CE.refl
; cong₂ = λ i≈j y≈z → F.F-resp-≈ y≈z i≈j
; inverse = (λ Fa → F.identity SE.refl) , λ nat {x} {z} z≈y →
let module S = Setoid (F.₀ x) in
S.trans (S.sym (commute nat z CE.refl))
(cong (η nat x) (identityˡ ○ identityˡ ○ z≈y))
}
where
module F = Functor F using (₀; ₁; F-resp-≈; homomorphism; identity)
module SE = Setoid (F.₀ a) using (refl)
private
-- in this bifunctor, a presheaf from Presheaves C goes from C to Setoids ℓ e,
-- but the over Setoids has higher level than the hom setoids.
Nat[Hom[C][-,c],F] : Bifunctor (Presheaves C) (Category.op C) (Setoids _ _)
Nat[Hom[C][-,c],F] = Hom[ Presheaves C ][-,-] ∘F (Functor.op embed ∘F πʳ ※ πˡ)
-- in this bifunctor, it needs to go from Presheaves which maps C to Setoids ℓ e,
-- so the universe level needs to be lifted.
FC : Bifunctor (Presheaves C) (Category.op C) (Setoids _ _)
FC = LiftSetoids (o ⊔ ℓ ⊔ e) (o ⊔ ℓ) ∘F eval {C = Category.op C} {D = Setoids ℓ e}
module yoneda-inverse {a} {F} = Inverse (yoneda-inverse a F)
-- the two bifunctors above are naturally isomorphic.
-- it is easy to show yoneda-inverse first then to yoneda.
yoneda : NaturalIsomorphism Nat[Hom[C][-,c],F] FC
yoneda = record
{ F⇒G = ntHelper record
{ η = λ where
(F , A) → record
{ _⟨$⟩_ = λ α → lift (yoneda-inverse.f α)
; cong = λ i≈j → lift (i≈j CE.refl)
}
; commute = λ where
{_} {G , B} (α , f) {β} {γ} β≈γ → lift $ cong (η α B) (helper f β γ β≈γ)
}
; F⇐G = ntHelper record
{ η = λ (F , A) → record
{ _⟨$⟩_ = λ x → yoneda-inverse.f⁻¹ (lower x)
; cong = λ i≈j y≈z → Functor.F-resp-≈ F y≈z (lower i≈j)
}
; commute = λ (α , f) eq eq′ → helper′ α f (lower eq) eq′
}
; iso = λ (F , A) → record
{ isoˡ = λ {α β} i≈j {X} y≈z →
Setoid.trans (Functor.F₀ F X) ( yoneda-inverse.inverseʳ α {x = X} y≈z) (i≈j CE.refl)
; isoʳ = λ eq → lift (Setoid.trans (Functor.F₀ F A) ( yoneda-inverse.inverseˡ {F = F} _) (lower eq))
}
}
where helper : {F : Functor C.op (Setoids ℓ e)}
{A B : Obj} (f : B ⇒ A)
(β γ : NaturalTransformation Hom[ C ][-, A ] F) →
Setoid._≈_ (Functor.F₀ Nat[Hom[C][-,c],F] (F , A)) β γ →
Setoid._≈_ (Functor.F₀ F B) (η β B ⟨$⟩ f ∘ id) (Functor.F₁ F f ⟨$⟩ (η γ A ⟨$⟩ id))
helper {F} {A} {B} f β γ β≈γ = S.begin
η β B ⟨$⟩ f ∘ id S.≈⟨ cong (η β B) (id-comm ○ (⟺ identityˡ)) ⟩
η β B ⟨$⟩ id ∘ id ∘ f S.≈⟨ commute β f CE.refl ⟩
F.₁ f ⟨$⟩ (η β A ⟨$⟩ id) S.≈⟨ cong (F.₁ f) (β≈γ CE.refl) ⟩
F.₁ f ⟨$⟩ (η γ A ⟨$⟩ id) S.∎
where
module F = Functor F using (₀;₁)
module S = SetoidR (F.₀ B)
helper′ : ∀ {F G : Functor (Category.op C) (Setoids ℓ e)}
{A B Z : Obj}
{h i : Z ⇒ B}
{X Y : Setoid.Carrier (Functor.F₀ F A)}
(α : NaturalTransformation F G)
(f : B ⇒ A) →
Setoid._≈_ (Functor.F₀ F A) X Y →
h ≈ i →
Setoid._≈_ (Functor.F₀ G Z) (Functor.F₁ G h ⟨$⟩ (η α B ⟨$⟩ (Functor.F₁ F f ⟨$⟩ X)))
(η α Z ⟨$⟩ (Functor.F₁ F (f ∘ i) ⟨$⟩ Y))
helper′ {F} {G} {A} {B} {Z} {h} {i} {X} {Y} α f eq eq′ = S.begin
G.₁ h ⟨$⟩ (η α B ⟨$⟩ (F.₁ f ⟨$⟩ X)) S.≈˘⟨ commute α h (S′.sym (cong (F.₁ f) eq)) ⟩
η α Z ⟨$⟩ (F.₁ h ⟨$⟩ (F.₁ f ⟨$⟩ Y)) S.≈⟨ cong (η α Z) (F.F-resp-≈ eq′ S′.refl) ⟩
η α Z ⟨$⟩ (F.₁ i ⟨$⟩ (F.₁ f ⟨$⟩ Y)) S.≈˘⟨ cong (η α Z) (F.homomorphism (Setoid.refl (F.₀ A))) ⟩
η α Z ⟨$⟩ (F.₁ (f ∘ i) ⟨$⟩ Y) S.∎
where
module F = Functor F using (₀; ₁; homomorphism; F-resp-≈)
module G = Functor G using (₀; ₁)
module S = SetoidR (G.₀ Z)
module S′ = Setoid (F.₀ B) using (refl; sym)
module yoneda = NaturalIsomorphism yoneda
| {
"alphanum_fraction": 0.5555412205,
"avg_line_length": 46.9757575758,
"ext": "agda",
"hexsha": "52975067253129e7853ba5c0b677fabfef4cf0e2",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Yoneda.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Yoneda.agda",
"max_line_length": 108,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Yoneda.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 2806,
"size": 7751
} |
module Pi.Everything where
open import Pi.Syntax -- Syntax of Pi
open import Pi.Opsem -- Abstract machine semantics of Pi
open import Pi.AuxLemmas -- Some auxiliary lemmas about opsem for forward/backward deterministic proof
open import Pi.NoRepeat -- Forward/backward deterministic lemmas and Non-repeating lemma
open import Pi.Eval -- Evaluator for Pi
open import Pi.Interp -- Big-step intepreter of Pi
open import Pi.Invariants -- Some invariants about abstract machine semantics
open import Pi.Properties -- Properties of Pi
open import Pi.Examples -- Examples
open import Pi.Category -- Pi Category
| {
"alphanum_fraction": 0.7682539683,
"avg_line_length": 52.5,
"ext": "agda",
"hexsha": "8b3f4f03c40f75e9d2edfa6a4ee7b550495b5152",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "Pi/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "Pi/Everything.agda",
"max_line_length": 103,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "Pi/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 142,
"size": 630
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.DiffInt where
open import Cubical.HITs.Ints.DiffInt.Base public
open import Cubical.HITs.Ints.DiffInt.Properties public
| {
"alphanum_fraction": 0.7817258883,
"avg_line_length": 32.8333333333,
"ext": "agda",
"hexsha": "48a38b3f014dd120face768b9d73c40dda02e977",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/Ints/DiffInt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/Ints/DiffInt.agda",
"max_line_length": 55,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/Ints/DiffInt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 54,
"size": 197
} |
{-
This second-order signature was created from the following second-order syntax description:
syntax Sum | S
type
_⊕_ : 2-ary | l30
term
inl : α -> α ⊕ β
inr : β -> α ⊕ β
case : α ⊕ β α.γ β.γ -> γ
theory
(lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a]
(rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b]
(cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s]
-}
module Sum.Signature where
open import SOAS.Context
-- Type declaration
data ST : Set where
_⊕_ : ST → ST → ST
infixl 30 _⊕_
open import SOAS.Syntax.Signature ST public
open import SOAS.Syntax.Build ST public
-- Operator symbols
data Sₒ : Set where
inlₒ inrₒ : {α β : ST} → Sₒ
caseₒ : {α β γ : ST} → Sₒ
-- Term signature
S:Sig : Signature Sₒ
S:Sig = sig λ
{ (inlₒ {α}{β}) → (⊢₀ α) ⟼₁ α ⊕ β
; (inrₒ {α}{β}) → (⊢₀ β) ⟼₁ α ⊕ β
; (caseₒ {α}{β}{γ}) → (⊢₀ α ⊕ β) , (α ⊢₁ γ) , (β ⊢₁ γ) ⟼₃ γ
}
open Signature S:Sig public
| {
"alphanum_fraction": 0.5273631841,
"avg_line_length": 21.3829787234,
"ext": "agda",
"hexsha": "d07a0ac8c6c56a18cacd0af990dfbd2e6b05fb86",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Sum/Signature.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Sum/Signature.agda",
"max_line_length": 91,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Sum/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 464,
"size": 1005
} |
-- New feature by Jesper Cockx in commit be89d4a8b264dd2719cb8c601a2c7f45a95ba220 :
-- disabling the universe check for a data or record type.
-- Andreas, 2018-10-27, re issue #3327: restructured test cases.
module _ where
-- Pragma is naturally attached to definition.
module DataDef where
data U : Set
T : U → Set
{-# NO_UNIVERSE_CHECK #-}
data U where
pi : (A : Set)(b : A → U) → U
T (pi A b) = (x : A) → T (b x)
-- Pragma can also be attached to signature.
module DataSig where
{-# NO_UNIVERSE_CHECK #-}
data U : Set
T : U → Set
data U where
pi : (A : Set)(b : A → U) → U
T (pi A b) = (x : A) → T (b x)
-- Works also for explicit mutual blocks.
module Mutual where
{-# NO_UNIVERSE_CHECK #-}
data U : Set where
pi : (A : Set)(b : A → U) → U
T : U → Set
T (pi A b) = (x : A) → T (b x)
-- Records:
module Records where
{-# NO_UNIVERSE_CHECK #-}
record R : Set where
field out : Set
{-# NO_UNIVERSE_CHECK #-}
record S : Set
record S where
field out : Set
| {
"alphanum_fraction": 0.6034816248,
"avg_line_length": 17.8275862069,
"ext": "agda",
"hexsha": "05d4234a5d2df8567bdee74dd7b4b3225df6d09d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phadej/agda",
"max_forks_repo_path": "test/Succeed/NoUniverseCheckPragma.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "phadej/agda",
"max_issues_repo_path": "test/Succeed/NoUniverseCheckPragma.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phadej/agda",
"max_stars_repo_path": "test/Succeed/NoUniverseCheckPragma.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 355,
"size": 1034
} |
open import Nat
open import Prelude
open import core
open import contexts
open import typed-elaboration
open import lemmas-gcomplete
open import lemmas-complete
open import progress-checks
open import finality
module cast-inert where
-- if a term is compelete and well typed, then the casts inside are all
-- identity casts and there are no failed casts
cast-inert : ∀{Δ Γ d τ} →
d dcomplete →
Δ , Γ ⊢ d :: τ →
cast-id d
cast-inert dc TAConst = CIConst
cast-inert dc (TAVar x₁) = CIVar
cast-inert (DCLam dc x₁) (TALam x₂ wt) = CILam (cast-inert dc wt)
cast-inert (DCAp dc dc₁) (TAAp wt wt₁) = CIAp (cast-inert dc wt) (cast-inert dc₁ wt₁)
cast-inert () (TAEHole x x₁)
cast-inert () (TANEHole x wt x₁)
cast-inert (DCCast dc x x₁) (TACast wt x₂)
with complete-consistency x₂ x x₁
... | refl = CICast (cast-inert dc wt)
cast-inert () (TAFailedCast wt x x₁ x₂)
-- in a well typed complete internal expression, every cast is the
-- identity cast.
complete-casts : ∀{Γ Δ d τ1 τ2} →
Γ , Δ ⊢ d ⟨ τ1 ⇒ τ2 ⟩ :: τ2 →
d ⟨ τ1 ⇒ τ2 ⟩ dcomplete →
τ1 == τ2
complete-casts wt comp with cast-inert comp wt
complete-casts wt comp | CICast qq = refl
-- relates expressions to the same thing with all identity casts
-- removed. note that this is a syntactic rewrite and it goes under
-- binders.
data no-id-casts : ihexp → ihexp → Set where
NICConst : no-id-casts c c
NICVar : ∀{x} → no-id-casts (X x) (X x)
NICLam : ∀{x τ d d'} → no-id-casts d d' → no-id-casts (·λ x [ τ ] d) (·λ x [ τ ] d')
NICHole : ∀{u} → no-id-casts (⦇-⦈⟨ u ⟩) (⦇-⦈⟨ u ⟩)
NICNEHole : ∀{d d' u} → no-id-casts d d' → no-id-casts (⦇⌜ d ⌟⦈⟨ u ⟩) (⦇⌜ d' ⌟⦈⟨ u ⟩)
NICAp : ∀{d1 d2 d1' d2'} → no-id-casts d1 d1' → no-id-casts d2 d2' → no-id-casts (d1 ∘ d2) (d1' ∘ d2')
NICCast : ∀{d d' τ} → no-id-casts d d' → no-id-casts (d ⟨ τ ⇒ τ ⟩) d'
NICFailed : ∀{d d' τ1 τ2} → no-id-casts d d' → no-id-casts (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) (d' ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩)
-- removing identity casts doesn't change the type
no-id-casts-type : ∀{Γ Δ d τ d' } → Δ , Γ ⊢ d :: τ →
no-id-casts d d' →
Δ , Γ ⊢ d' :: τ
no-id-casts-type TAConst NICConst = TAConst
no-id-casts-type (TAVar x₁) NICVar = TAVar x₁
no-id-casts-type (TALam x₁ wt) (NICLam nic) = TALam x₁ (no-id-casts-type wt nic)
no-id-casts-type (TAAp wt wt₁) (NICAp nic nic₁) = TAAp (no-id-casts-type wt nic) (no-id-casts-type wt₁ nic₁)
no-id-casts-type (TAEHole x x₁) NICHole = TAEHole x x₁
no-id-casts-type (TANEHole x wt x₁) (NICNEHole nic) = TANEHole x (no-id-casts-type wt nic) x₁
no-id-casts-type (TACast wt x) (NICCast nic) = no-id-casts-type wt nic
no-id-casts-type (TAFailedCast wt x x₁ x₂) (NICFailed nic) = TAFailedCast (no-id-casts-type wt nic) x x₁ x₂
| {
"alphanum_fraction": 0.5889570552,
"avg_line_length": 46.5714285714,
"ext": "agda",
"hexsha": "c0737c8569d10e9318636154cdd7c2e5a583e1b5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "cast-inert.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "cast-inert.agda",
"max_line_length": 110,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "cast-inert.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 1137,
"size": 2934
} |
-- Andreas, 2018-11-03, issue #3364
--
-- Better error when trying to import with new qualified module name.
open import Agda.Builtin.Nat as Builtin.Nat
-- WAS: Error:
-- Not in scope:
-- as at ...
-- when scope checking as
-- NOW: Warning
-- `as' must be followed by an unqualified name
-- when scope checking the declaration
-- open import Agda.Builtin.Nat as Builtin.Nat
| {
"alphanum_fraction": 0.7034120735,
"avg_line_length": 23.8125,
"ext": "agda",
"hexsha": "6842c730a9decf50a5911574cde96e5b9e586a5c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phadej/agda",
"max_forks_repo_path": "test/Succeed/Issue3364.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "phadej/agda",
"max_issues_repo_path": "test/Succeed/Issue3364.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phadej/agda",
"max_stars_repo_path": "test/Succeed/Issue3364.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 106,
"size": 381
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Relation.Binary.Raw
module Cubical.Relation.Binary.Reasoning.PartialOrder
{c ℓ} {A : Type c} (P : PartialOrder A ℓ) where
open PartialOrder P
import Cubical.Relation.Binary.Raw.Construct.NonStrictToStrict _≤_ as Strict
------------------------------------------------------------------------
-- Re-export contents of base module
open import Cubical.Relation.Binary.Reasoning.Base.Double
isPreorder
(Strict.<-transitive isPartialOrder)
Strict.<⇒≤
(Strict.<-≤-trans transitive antisym)
(Strict.≤-<-trans transitive antisym)
public
| {
"alphanum_fraction": 0.6732824427,
"avg_line_length": 29.7727272727,
"ext": "agda",
"hexsha": "32ed96c8a648cd46fe2d8901e41ceb4a466dfa34",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Reasoning/PartialOrder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Reasoning/PartialOrder.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Reasoning/PartialOrder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 172,
"size": 655
} |
-- exercises
-- * basic logic properties (implication, and, or, bot, not, forall, exists)
-- * data types
-- * records
-- * non-dep, non-rec, non-indexed case splits
-- * including elimination constants as hints
-- * hidden arguments
open import Auto.Prelude
h0 : (A : Set) → A → A
h0 = {!!}
--h0 = λ A z → z
h1 : (A B : Set) → A → (A → B) → B
h1 = {!!}
--h1 = λ A B z z₁ → z₁ z
h2 : ∀ A B → A ∧ B → B ∧ A
h2 = {!!}
--h2 = λ A B z → ∧-i (_∧_.snd z) (_∧_.fst z)
h3 : ∀ A B C → (A ∧ B) ∧ C → A ∧ (B ∧ C)
h3 = {!!}
--h3 = λ A B C z →
-- ∧-i (_∧_.fst (_∧_.fst z)) (∧-i (_∧_.snd (_∧_.fst z)) (_∧_.snd z))
h4 : (A B C : Set) → A ∨ B → (A → C) → (B → C) → C
h4 A B C x h₁ h₂ = {!-c!}
h5 : ∀ A B → A ∨ B → B ∨ A
h5 A B x = {!-c!}
--h5 A B (∨-i₁ x) = ∨-i₂ x
--h5 A B (∨-i₂ x) = ∨-i₁ x
h6 : ∀ A B C → (A ∨ B) ∨ C → A ∨ (B ∨ C)
h6 A B C x = {!-c!}
--h6 A B C (∨-i₁ (∨-i₁ x)) = ∨-i₁ x
--h6 A B C (∨-i₁ (∨-i₂ x)) = ∨-i₂ (∨-i₁ x)
--h6 A B C (∨-i₂ x) = ∨-i₂ (∨-i₂ x)
h7 : (A : Set) → ⊥ → A
h7 A x = {!-c!}
h8 : ∀ A → A → ¬ (¬ A)
h8 = {!!}
--h8 = λ A z z₁ → z₁ z
h9 : ∀ A → ¬ (¬ (¬ A)) → ¬ A
h9 = {!!}
--h9 = λ A z z₁ → z (λ z₂ → z₂ z₁)
h10 : (∀ A → ¬ (¬ A) → A) →
(∀ A → A ∨ ¬ A)
h10 = {!!}
--h10 = λ z A →
-- z (A ∨ ((x : A) → ⊥)) (λ z₁ → z₁ (∨-i₂ (λ x → z₁ (∨-i₁ x))))
h11 : (∀ A → A ∨ ¬ A) →
(∀ A → ¬ (¬ A) → A)
h11 = {!∨-e ⊥-e!}
--h11 = λ z A z₁ →
-- ∨-e A ((x : A) → ⊥) A (z A) (λ z₂ → z₂) (λ z₂ → ⊥-e A (z₁ z₂))
h12 : {X : Set} {P Q : X → Set} → ((x : X) → P x ∧ Q x) → ((x : X) → P x) ∧ ((x : X) → Q x)
h12 = {!!}
--h12 = λ {X} {P} {Q} z → ∧-i (λ x → _∧_.fst (z x)) (λ x → _∧_.snd (z x))
h13 : {X : Set} {P Q : X → Set} → ((x : X) → P x) ∧ ((x : X) → Q x) → ((x : X) → P x ∧ Q x)
h13 = {!!}
--h13 = λ {X} {P} {Q} z x → ∧-i (_∧_.fst z x) (_∧_.snd z x)
n0 : {X : Set} {P Q : X → Set} → Σ X (λ x → P x ∨ Q x) → Σ X P ∨ Σ X Q
--n0 = {!∨-e!} -- no solution found, not even for the two subproofs
n0 = λ h → ∨-e _ _ _ (Σ.prf h) (λ x → ∨-i₁ (Σ-i (Σ.wit h) x)) (λ x → ∨-i₂ (Σ-i (Σ.wit h) x))
n1 : {X : Set} {P Q : X → Set} → Σ X P ∨ Σ X Q → Σ X (λ x → P x ∨ Q x)
--n1 = {!∨-e!} -- no solution found, not even for the two subproofs
n1 = λ h → ∨-e _ _ _ h (λ x → Σ-i (Σ.wit x) (∨-i₁ (Σ.prf x))) (λ x → Σ-i (Σ.wit x) (∨-i₂ (Σ.prf x)))
h14 : {X : Set} → (x : X) → Σ X (λ x → ⊤)
h14 = {!!}
--h14 = λ {X} x → Σ-i x (record {})
h15 : {X : Set} → Σ (X → X) (λ x → ⊤)
h15 = {!!}
--h15 = λ {X} → Σ-i (λ x → x) (record {})
h16 : {X : Set} {P : X → Set} → Σ (X → X) (λ f → (x : X) → P (f x) → P x)
h16 = {!!}
--h16 = λ {X} {P} → Σ-i (λ x → x) (λ x x₁ → x₁)
module Drink where
postulate RAA : (A : Set) → (¬ A → ⊥) → A
drink : (A : Set) → (a : A)
→ (Drink : A → Set) → Σ A (λ x → (Drink x) → Π A Drink)
drink A a Drink = {!RAA!} -- h17
{-
drink A a Drink = RAA (Σ A (λ z → (x : Drink z) → Π A Drink))
(λ z →
z
(Σ-i a
(λ x →
fun
(λ a₁ →
RAA (Drink a₁)
(λ z₁ →
z (Σ-i a₁ (λ x₁ → fun (λ a₂ → RAA (Drink a₂) (λ _ → z₁ x₁))))))))) -- h17
-}
| {
"alphanum_fraction": 0.3599876505,
"avg_line_length": 26.9916666667,
"ext": "agda",
"hexsha": "f81ac51a24e1c85115a97cafbf8dcb0a8f9808e1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Auto-BasicLogic.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Auto-BasicLogic.agda",
"max_line_length": 108,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Auto-BasicLogic.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 1607,
"size": 3239
} |
module TLP02 where
open import Data.Bool
open import Data.Nat
open import Data.String
open import Relation.Binary.PropositionalEquality
as PropEq using (_≡_; refl)
-- ----- Star型の定義 -----
data Star : Set where
NIL : Star
TRU : Star
N : ℕ → Star
S : String → Star
C : Star → Star → Star
-- ----- 組込関数の定義 -----
postulate
CONS : Star → Star → Star
CAR : Star → Star
CDR : Star → Star
ATOM : Star → Star
IF : Star → Star → Star → Star
EQUAL : Star → Star → Star
SIZE : Star → Star
LT : Star → Star → Star
-- ----- Starから≡に -----
postulate
~ : Star → Star
equal-eq : {x y : Star} → (EQUAL x y) ≡ TRU → x ≡ y
ifAP : {q x y : Star} → (IF q (EQUAL x y) TRU) ≡ TRU → (q ≡ TRU → x ≡ y)
ifEP : {q x y : Star} → (IF q TRU (EQUAL x y)) ≡ TRU → ((~ q) ≡ TRU → x ≡ y)
-- ----- 公理 -----
equal-same : (x : Star) → (EQUAL (EQUAL x x) TRU) ≡ TRU
equal-swap : (x y : Star) → (EQUAL (EQUAL x y) (EQUAL y x)) ≡ TRU
equal-if : (x y : Star) → (IF (EQUAL x y) (EQUAL x y) TRU) ≡ TRU
atom/cons : (x y : Star) → (EQUAL (ATOM (CONS x y)) NIL) ≡ TRU
car/cons : (x y : Star) → (EQUAL (CAR (CONS x y)) x) ≡ TRU
cdr/cons : (x y : Star) → (EQUAL (CDR (CONS x y)) y) ≡ TRU
cons/car+cdr : (x : Star)
→ (IF (ATOM x) TRU (EQUAL (CONS (CAR x) (CDR x)) x)) ≡ TRU
if-true : (x y : Star) → (EQUAL (IF TRU x y) x) ≡ TRU
if-false : (x y : Star) → (EQUAL (IF NIL x y) y) ≡ TRU
if-same : (x y : Star) → (EQUAL (IF x y y) y) ≡ TRU
if-nest-A : (x y z : Star) → (IF x (EQUAL (IF x y z) y) TRU) ≡ TRU
if-nest-E : (x y z : Star) → (IF x TRU (EQUAL (IF x y z) z)) ≡ TRU
size/car : (x : Star)
→ (IF (ATOM x) TRU (EQUAL (LT (SIZE (CAR x)) (SIZE x)) TRU)) ≡ TRU
size/cdr : (x : Star)
→ (IF (ATOM x) TRU (EQUAL (LT (SIZE (CDR x)) (SIZE x)) TRU)) ≡ TRU
-- ----- 練習 -----
hoge2 : (ATOM (CONS TRU TRU)) ≡ NIL
hoge2 = equal-eq (atom/cons TRU TRU)
hoge2' : (ATOM (CONS TRU TRU)) ≡ NIL
hoge2'
rewrite (equal-eq (atom/cons TRU TRU))
= refl
-- -----
{--
-- ----- 停止性で引っかかる -----
memb?' : Star → Star
memb?' xs =
(IF (ATOM xs)
NIL
(IF (EQUAL (CAR xs) (S "?"))
TRU
(memb?' (CDR xs))))
--}
-- ----- memb?の停止性 -----
postulate
premise : (xs : Star) → (~ (ATOM xs)) ≡ TRU
measure-memb? : (xs : Star)
→ (IF (ATOM xs)
TRU
(IF (EQUAL (CAR xs) (S "?"))
TRU
(LT (SIZE (CDR xs)) (SIZE xs))))
≡ TRU
measure-memb? xs
rewrite (ifEP (size/cdr xs) (premise xs))
| (equal-eq (if-same (EQUAL (CAR xs) (S "?")) TRU))
| (equal-eq (if-same (ATOM xs) TRU)) = refl
-- ----- memb?の定義 -----
postulate
memb? : Star → Star
def-memb? : (xs : Star) →
memb? xs ≡
(IF (ATOM xs)
NIL
(IF (EQUAL (CAR xs) (S "?"))
TRU
(memb? (CDR xs))))
-- ----- rembの定義 -----
postulate
remb : Star → Star
def-remb : (xs : Star) →
remb xs ≡
(IF (ATOM xs)
(S "'()")
(IF (EQUAL (CAR xs) (S "?"))
(remb (CDR xs))
(CONS (CAR xs)
(remb (CDR xs)))))
-- ----- 帰納的な証明 -----
postulate
premise2 : (xs : Star) → (ATOM xs) ≡ TRU
premise3 : (xs : Star) → ~ (ATOM xs) ≡ TRU
atomt : (ATOM (S "'()")) ≡ TRU
memb?/remb : (xs : Star)
→ (IF (ATOM xs)
(EQUAL (memb? (remb xs)) NIL)
(IF (EQUAL (memb? (remb (CDR xs))) NIL)
(EQUAL (memb? (remb xs)) NIL)
TRU))
≡ IF (ATOM xs) TRU (IF (EQUAL (memb? (remb (CDR xs))) NIL) TRU TRU)
memb?/remb xs
rewrite (def-remb xs)
| (ifAP (if-nest-A (ATOM xs) (S "'()") ((IF (EQUAL (CAR xs) (S "?"))
(remb (CDR xs))
(CONS (CAR xs)
(remb (CDR xs)))))) (premise2 xs))
| (def-memb? ((S "'()")))
| (atomt)
| (equal-eq (if-true NIL ((IF (EQUAL (CAR (S "'()")) (S "?"))
TRU
(memb? (CDR (S "'()")))))))
| (equal-eq (equal-same NIL))
| (def-remb xs)
-- ----- ここで証明ステップが一気に進んだ
| (ifEP (if-nest-E (ATOM xs) (S "'()") (IF (EQUAL (CAR xs) (S "?"))
(remb (CDR xs))
(CONS (CAR xs)
(remb (CDR xs))))) (premise3 xs)) = refl
memb?/remb2 : (xs : Star)
→ IF (ATOM xs) TRU (IF (EQUAL (memb? (remb (CDR xs))) NIL) TRU TRU)
≡ TRU
memb?/remb2 xs
rewrite (equal-eq (if-same (EQUAL (memb? (remb (CDR xs))) NIL) TRU))
| (equal-eq (if-same (ATOM xs) TRU)) = refl
| {
"alphanum_fraction": 0.4545256745,
"avg_line_length": 31.2653061224,
"ext": "agda",
"hexsha": "02b6c05ae28968a5c9f64b5d03cbd7cebc322e13",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "righ1113/Agda",
"max_forks_repo_path": "TLP02.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "righ1113/Agda",
"max_issues_repo_path": "TLP02.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "righ1113/Agda",
"max_stars_repo_path": "TLP02.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1788,
"size": 4596
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definitions of algebraic structures defined over some other
-- structure, like modules and vector spaces
--
-- Terminology of bundles:
-- * There are both *semimodules* and *modules*.
-- - For M an R-semimodule, R is a semiring, and M forms a commutative
-- monoid.
-- - For M an R-module, R is a ring, and M forms an Abelian group.
-- * There are all four of *left modules*, *right modules*, *bimodules*,
-- and *modules*.
-- - Left modules have a left-scaling operation.
-- - Right modules have a right-scaling operation.
-- - Bimodules have two sorts of scalars. Left-scaling handles one and
-- right-scaling handles the other. Left-scaling and right-scaling
-- are furthermore compatible.
-- - Modules are bimodules with a single sort of scalars and scalar
-- multiplication must also be commutative. Left-scaling and
-- right-scaling coincide.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.Module.Bundles where
open import Algebra.Bundles
open import Algebra.Core
open import Algebra.Module.Structures
open import Algebra.Module.Definitions
open import Function.Base
open import Level
open import Relation.Binary
import Relation.Binary.Reasoning.Setoid as SetR
private
variable
r ℓr s ℓs : Level
------------------------------------------------------------------------
-- Left modules
------------------------------------------------------------------------
record LeftSemimodule (semiring : Semiring r ℓr) m ℓm
: Set (r ⊔ ℓr ⊔ suc (m ⊔ ℓm)) where
open Semiring semiring
infixr 7 _*ₗ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ₗ_ : Opₗ Carrier Carrierᴹ
0ᴹ : Carrierᴹ
isLeftSemimodule : IsLeftSemimodule semiring _≈ᴹ_ _+ᴹ_ 0ᴹ _*ₗ_
open IsLeftSemimodule isLeftSemimodule public
+ᴹ-commutativeMonoid : CommutativeMonoid m ℓm
+ᴹ-commutativeMonoid = record
{ isCommutativeMonoid = +ᴹ-isCommutativeMonoid
}
open CommutativeMonoid +ᴹ-commutativeMonoid public
using () renaming
( monoid to +ᴹ-monoid
; semigroup to +ᴹ-semigroup
; magma to +ᴹ-magma
; rawMagma to +ᴹ-rawMagma
; rawMonoid to +ᴹ-rawMonoid
)
record LeftModule (ring : Ring r ℓr) m ℓm : Set (r ⊔ ℓr ⊔ suc (m ⊔ ℓm)) where
open Ring ring
infixr 8 -ᴹ_
infixr 7 _*ₗ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ₗ_ : Opₗ Carrier Carrierᴹ
0ᴹ : Carrierᴹ
-ᴹ_ : Op₁ Carrierᴹ
isLeftModule : IsLeftModule ring _≈ᴹ_ _+ᴹ_ 0ᴹ -ᴹ_ _*ₗ_
open IsLeftModule isLeftModule public
leftSemimodule : LeftSemimodule semiring m ℓm
leftSemimodule = record { isLeftSemimodule = isLeftSemimodule }
open LeftSemimodule leftSemimodule public
using ( +ᴹ-commutativeMonoid; +ᴹ-monoid; +ᴹ-semigroup; +ᴹ-magma
; +ᴹ-rawMagma; +ᴹ-rawMonoid)
+ᴹ-abelianGroup : AbelianGroup m ℓm
+ᴹ-abelianGroup = record { isAbelianGroup = +ᴹ-isAbelianGroup }
open AbelianGroup +ᴹ-abelianGroup public
using () renaming (group to +ᴹ-group)
------------------------------------------------------------------------
-- Right modules
------------------------------------------------------------------------
record RightSemimodule (semiring : Semiring r ℓr) m ℓm
: Set (r ⊔ ℓr ⊔ suc (m ⊔ ℓm)) where
open Semiring semiring
infixl 7 _*ᵣ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ᵣ_ : Opᵣ Carrier Carrierᴹ
0ᴹ : Carrierᴹ
isRightSemimodule : IsRightSemimodule semiring _≈ᴹ_ _+ᴹ_ 0ᴹ _*ᵣ_
open IsRightSemimodule isRightSemimodule public
+ᴹ-commutativeMonoid : CommutativeMonoid m ℓm
+ᴹ-commutativeMonoid = record
{ isCommutativeMonoid = +ᴹ-isCommutativeMonoid
}
open CommutativeMonoid +ᴹ-commutativeMonoid public
using () renaming
( monoid to +ᴹ-monoid
; semigroup to +ᴹ-semigroup
; magma to +ᴹ-magma
; rawMagma to +ᴹ-rawMagma
; rawMonoid to +ᴹ-rawMonoid
)
record RightModule (ring : Ring r ℓr) m ℓm : Set (r ⊔ ℓr ⊔ suc (m ⊔ ℓm)) where
open Ring ring
infixr 8 -ᴹ_
infixl 7 _*ᵣ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ᵣ_ : Opᵣ Carrier Carrierᴹ
0ᴹ : Carrierᴹ
-ᴹ_ : Op₁ Carrierᴹ
isRightModule : IsRightModule ring _≈ᴹ_ _+ᴹ_ 0ᴹ -ᴹ_ _*ᵣ_
open IsRightModule isRightModule public
rightSemimodule : RightSemimodule semiring m ℓm
rightSemimodule = record { isRightSemimodule = isRightSemimodule }
open RightSemimodule rightSemimodule public
using ( +ᴹ-commutativeMonoid; +ᴹ-monoid; +ᴹ-semigroup; +ᴹ-magma
; +ᴹ-rawMagma; +ᴹ-rawMonoid)
+ᴹ-abelianGroup : AbelianGroup m ℓm
+ᴹ-abelianGroup = record { isAbelianGroup = +ᴹ-isAbelianGroup }
open AbelianGroup +ᴹ-abelianGroup public
using () renaming (group to +ᴹ-group)
------------------------------------------------------------------------
-- Bimodules
------------------------------------------------------------------------
record Bisemimodule (R-semiring : Semiring r ℓr) (S-semiring : Semiring s ℓs)
m ℓm : Set (r ⊔ s ⊔ ℓr ⊔ ℓs ⊔ suc (m ⊔ ℓm)) where
private
module R = Semiring R-semiring
module S = Semiring S-semiring
infixr 7 _*ₗ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ₗ_ : Opₗ R.Carrier Carrierᴹ
_*ᵣ_ : Opᵣ S.Carrier Carrierᴹ
0ᴹ : Carrierᴹ
isBisemimodule : IsBisemimodule R-semiring S-semiring _≈ᴹ_ _+ᴹ_ 0ᴹ _*ₗ_ _*ᵣ_
open IsBisemimodule isBisemimodule public
leftSemimodule : LeftSemimodule R-semiring m ℓm
leftSemimodule = record { isLeftSemimodule = isLeftSemimodule }
rightSemimodule : RightSemimodule S-semiring m ℓm
rightSemimodule = record { isRightSemimodule = isRightSemimodule }
open LeftSemimodule leftSemimodule public
using ( +ᴹ-commutativeMonoid; +ᴹ-monoid; +ᴹ-semigroup; +ᴹ-magma; +ᴹ-rawMagma
; +ᴹ-rawMonoid)
record Bimodule (R-ring : Ring r ℓr) (S-ring : Ring s ℓs) m ℓm
: Set (r ⊔ s ⊔ ℓr ⊔ ℓs ⊔ suc (m ⊔ ℓm)) where
private
module R = Ring R-ring
module S = Ring S-ring
infixr 7 _*ₗ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ₗ_ : Opₗ R.Carrier Carrierᴹ
_*ᵣ_ : Opᵣ S.Carrier Carrierᴹ
0ᴹ : Carrierᴹ
-ᴹ_ : Op₁ Carrierᴹ
isBimodule : IsBimodule R-ring S-ring _≈ᴹ_ _+ᴹ_ 0ᴹ -ᴹ_ _*ₗ_ _*ᵣ_
open IsBimodule isBimodule public
leftModule : LeftModule R-ring m ℓm
leftModule = record { isLeftModule = isLeftModule }
rightModule : RightModule S-ring m ℓm
rightModule = record { isRightModule = isRightModule }
open LeftModule leftModule public
using ( +ᴹ-abelianGroup; +ᴹ-commutativeMonoid; +ᴹ-group; +ᴹ-monoid
; +ᴹ-semigroup; +ᴹ-magma; +ᴹ-rawMagma; +ᴹ-rawMonoid)
bisemimodule : Bisemimodule R.semiring S.semiring m ℓm
bisemimodule = record { isBisemimodule = isBisemimodule }
open Bisemimodule bisemimodule public
using (leftSemimodule; rightSemimodule)
------------------------------------------------------------------------
-- Modules over commutative structures
------------------------------------------------------------------------
record Semimodule (commutativeSemiring : CommutativeSemiring r ℓr) m ℓm
: Set (r ⊔ ℓr ⊔ suc (m ⊔ ℓm)) where
open CommutativeSemiring commutativeSemiring
infixr 7 _*ₗ_
infixl 7 _*ᵣ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ₗ_ : Opₗ Carrier Carrierᴹ
_*ᵣ_ : Opᵣ Carrier Carrierᴹ
0ᴹ : Carrierᴹ
isSemimodule : IsSemimodule commutativeSemiring _≈ᴹ_ _+ᴹ_ 0ᴹ _*ₗ_ _*ᵣ_
open IsSemimodule isSemimodule public
private
module L = LeftDefs Carrier _≈ᴹ_
module R = RightDefs Carrier _≈ᴹ_
bisemimodule : Bisemimodule semiring semiring m ℓm
bisemimodule = record { isBisemimodule = isBisemimodule }
open Bisemimodule bisemimodule public
using ( leftSemimodule; rightSemimodule
; +ᴹ-commutativeMonoid; +ᴹ-monoid; +ᴹ-semigroup; +ᴹ-magma
; +ᴹ-rawMagma; +ᴹ-rawMonoid)
open SetR ≈ᴹ-setoid
*ₗ-comm : L.Commutative _*ₗ_
*ₗ-comm x y m = begin
x *ₗ y *ₗ m ≈⟨ ≈ᴹ-sym (*ₗ-assoc x y m) ⟩
(x * y) *ₗ m ≈⟨ *ₗ-cong (*-comm _ _) ≈ᴹ-refl ⟩
(y * x) *ₗ m ≈⟨ *ₗ-assoc y x m ⟩
y *ₗ x *ₗ m ∎
*ᵣ-comm : R.Commutative _*ᵣ_
*ᵣ-comm m x y = begin
m *ᵣ x *ᵣ y ≈⟨ *ᵣ-assoc m x y ⟩
m *ᵣ (x * y) ≈⟨ *ᵣ-cong ≈ᴹ-refl (*-comm _ _) ⟩
m *ᵣ (y * x) ≈⟨ ≈ᴹ-sym (*ᵣ-assoc m y x) ⟩
m *ᵣ y *ᵣ x ∎
record Module (commutativeRing : CommutativeRing r ℓr) m ℓm
: Set (r ⊔ ℓr ⊔ suc (m ⊔ ℓm)) where
open CommutativeRing commutativeRing
infixr 8 -ᴹ_
infixr 7 _*ₗ_
infixl 6 _+ᴹ_
infix 4 _≈ᴹ_
field
Carrierᴹ : Set m
_≈ᴹ_ : Rel Carrierᴹ ℓm
_+ᴹ_ : Op₂ Carrierᴹ
_*ₗ_ : Opₗ Carrier Carrierᴹ
_*ᵣ_ : Opᵣ Carrier Carrierᴹ
0ᴹ : Carrierᴹ
-ᴹ_ : Op₁ Carrierᴹ
isModule : IsModule commutativeRing _≈ᴹ_ _+ᴹ_ 0ᴹ -ᴹ_ _*ₗ_ _*ᵣ_
open IsModule isModule public
bimodule : Bimodule ring ring m ℓm
bimodule = record { isBimodule = isBimodule }
open Bimodule bimodule public
using ( leftModule; rightModule; leftSemimodule; rightSemimodule
; +ᴹ-abelianGroup; +ᴹ-group; +ᴹ-commutativeMonoid; +ᴹ-monoid
; +ᴹ-semigroup; +ᴹ-magma ; +ᴹ-rawMonoid; +ᴹ-rawMagma)
semimodule : Semimodule commutativeSemiring m ℓm
semimodule = record { isSemimodule = isSemimodule }
open Semimodule semimodule public using (*ₗ-comm; *ᵣ-comm)
| {
"alphanum_fraction": 0.620951417,
"avg_line_length": 29.4925373134,
"ext": "agda",
"hexsha": "252ae1b072c1f2d0686a9eb5f610e9c3014138f2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Module/Bundles.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Module/Bundles.agda",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 3911,
"size": 9880
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- The universal binary relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Construct.Always where
open import Relation.Binary
open import Relation.Binary.Construct.Constant using (Const)
open import Data.Unit using (⊤; tt)
open import Level using (Lift; lift)
------------------------------------------------------------------------
-- Definition
Always : ∀ {a ℓ} {A : Set a} → Rel A ℓ
Always = Const (Lift _ ⊤)
------------------------------------------------------------------------
-- Properties
module _ {a} (A : Set a) ℓ where
refl : Reflexive {ℓ = ℓ} {A} Always
refl = lift tt
sym : Symmetric {ℓ = ℓ} {A} Always
sym _ = lift tt
trans : Transitive {ℓ = ℓ} {A} Always
trans _ _ = lift tt
isEquivalence : IsEquivalence {ℓ = ℓ} {A} Always
isEquivalence = record {}
setoid : Setoid a ℓ
setoid = record
{ isEquivalence = isEquivalence
}
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.17
Always-setoid = setoid
{-# WARNING_ON_USAGE Always-setoid
"Warning: Always-setoid was deprecated in v0.14.
Please use setoid instead."
#-}
| {
"alphanum_fraction": 0.4801346801,
"avg_line_length": 26.0526315789,
"ext": "agda",
"hexsha": "dbfcad5ce678e1392ddef21332816ddcdd45c391",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Always.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Always.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Always.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 328,
"size": 1485
} |
module Oscar.Category.Action where
open import Oscar.Category.Setoid
open import Oscar.Function
open import Oscar.Level
record Action {𝔬} (⋆ : Set 𝔬) 𝔄𝔬 𝔄𝔮
: Set (𝔬 ⊔ lsuc (𝔄𝔬 ⊔ 𝔄𝔮))
where
field
𝔄 : ⋆ → Setoid 𝔄𝔬 𝔄𝔮
⦃ isSetoid ⦄ : ∀ {x} → IsSetoid (Setoid.⋆ (𝔄 x)) 𝔄𝔮
↥ : ⋆ → Set 𝔄𝔬
↥ = Setoid.⋆ ∘ 𝔄
| {
"alphanum_fraction": 0.5945121951,
"avg_line_length": 18.2222222222,
"ext": "agda",
"hexsha": "bcdf4a46b8f694eb4e648b99575720f15f1660b8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Category/Action.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Category/Action.agda",
"max_line_length": 55,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Category/Action.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 171,
"size": 328
} |
{-# OPTIONS --without-K --safe #-}
module Cham.Inference where
| {
"alphanum_fraction": 0.6615384615,
"avg_line_length": 13,
"ext": "agda",
"hexsha": "df0edac7fe15b682d10f2c81ba01952a57ba4c0a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "riz0id/chemical-abstract-machine",
"max_forks_repo_path": "agda/Cham/Inference.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "riz0id/chemical-abstract-machine",
"max_issues_repo_path": "agda/Cham/Inference.agda",
"max_line_length": 34,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "riz0id/chemical-abstract-machine",
"max_stars_repo_path": "agda/Cham/Inference.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 14,
"size": 65
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Bicategory.Instance.Cats where
-- The category of categories (Cats) is a Bicategory
open import Level
open import Data.Product using (Σ; _×_; _,_; proj₁; proj₂)
open import Categories.Bicategory using (Bicategory)
open import Categories.Category using (Category)
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.Category.Instance.One using (One)
open import Categories.Category.Product using (Product; πˡ; πʳ; _※_)
open import Categories.Category.Construction.Functors
open import Categories.Functor.Construction.Constant
import Categories.Morphism.Reasoning as MR
Cats : (o ℓ e : Level) → Bicategory (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) (o ⊔ e) (suc (o ⊔ ℓ ⊔ e))
Cats o ℓ e = record
{ enriched = record
{ Obj = Category o ℓ e
; hom = Functors
; id = λ {A} → const {D = Functors A A} {C = One} idF
; ⊚ = product
; ⊚-assoc = λ {A B C D} →
let module D = Category D in
let module C = Category C in record
{ F⇒G = ntHelper record
{ η = λ { ((F₁ , F₂) , F₃) → F⇒G (associator F₃ F₂ F₁) }
-- the proof is as below, so write it raw combinator-style
; commute = λ { {(G₁ , G₂) , G₃} {(H₁ , H₂) , H₃} ((η₁ , η₂) , η₃) {x} →
let open Category D in let open HomReasoning in
identityˡ ○ ⟺ assoc ○ ∘-resp-≈ˡ (⟺ (homomorphism H₁)) ○ ⟺ identityʳ}
}
; F⇐G = ntHelper record
{ η = λ { ((F₁ , F₂) , F₃) → F⇐G (associator F₃ F₂ F₁)}
; commute = λ { {(G₁ , G₂) , G₃} {(H₁ , H₂) , H₃} ((η₁ , η₂) , η₃) {x} →
let open Category D in let open HomReasoning in begin
id ∘ F₁ H₁ (F₁ H₂ (η η₃ x) C.∘ η η₂ (F₀ G₃ x)) ∘ η η₁ (F₀ G₂ (F₀ G₃ x))
≈⟨ identityˡ ⟩
F₁ H₁ (F₁ H₂ (η η₃ x) C.∘ η η₂ (F₀ G₃ x)) ∘ η η₁ (F₀ G₂ (F₀ G₃ x))
≈⟨ homomorphism H₁ ⟩∘⟨refl ⟩
(F₁ H₁ (F₁ H₂ (η η₃ x)) ∘ F₁ H₁ (η η₂ (F₀ G₃ x))) ∘ η η₁ (F₀ G₂ (F₀ G₃ x))
≈⟨ assoc ⟩
F₁ H₁ (F₁ H₂ (η η₃ x)) ∘ F₁ H₁ (η η₂ (F₀ G₃ x)) ∘ η η₁ (F₀ G₂ (F₀ G₃ x))
≈˘⟨ identityʳ ⟩
(F₁ H₁ (F₁ H₂ (η η₃ x)) ∘ F₁ H₁ (η η₂ (F₀ G₃ x)) ∘ η η₁ (F₀ G₂ (F₀ G₃ x))) ∘ id ∎ }
}
; iso = λ X → record { isoˡ = D.identityʳ ; isoʳ = D.identityˡ }
}
; unitˡ = λ {A} {B} → let module B = Category B in let open B.HomReasoning in record
{ F⇒G = ntHelper record { η = λ _ → F⇒G unitorˡ ; commute = λ _ → B.identityˡ }
; F⇐G = ntHelper record
{ η = λ _ → F⇐G unitorˡ
; commute = λ f → B.identityˡ ○ ⟺ B.identityʳ ○ ⟺ B.identityʳ
}
; iso = λ _ → record { isoˡ = B.identityˡ ; isoʳ = B.identityʳ }
}
; unitʳ = λ {A} {B} → let open Category B in let open HomReasoning in record
{ F⇒G = ntHelper record
{ η = λ _ → F⇒G unitorʳ
; commute = λ { {_} {Y , _} (f , _) {x} → begin
id ∘ F₁ Y (Category.id A) ∘ η f x ≈⟨ identityˡ ○ ∘-resp-≈ˡ (identity Y) ○ MR.id-comm-sym B ⟩
η f x ∘ id ∎ }
}
; F⇐G = ntHelper record
{ η = λ _ → F⇐G unitorʳ
; commute = λ { {_} {Y , _} (f , _) {x} → begin
id ∘ η f x ≈˘⟨ identity Y ⟩∘⟨refl ⟩
F₁ Y (Category.id A) ∘ η f x ≈˘⟨ identityʳ ⟩
(F₁ Y (Category.id A) ∘ η f x) ∘ id ∎ }
}
; iso = λ _ → record { isoˡ = identityˡ ; isoʳ = identityʳ }
}
}
; triangle = λ {_ _ C} → Category.identityʳ C
; pentagon = λ {A B C D E} {f g h i} {X} →
let open Category E in
let open HomReasoning in begin
(F₁ i (Category.id D) ∘ id) ∘ id ∘ F₁ i (F₁ h (F₁ g (Category.id B))) ∘ id
≈⟨ identityʳ ⟩∘⟨ (identityˡ ○ identityʳ) ⟩
F₁ i (Category.id D) ∘ F₁ i (F₁ h (F₁ g (Category.id B)))
≈⟨ identity i ⟩∘⟨ F-resp-≈ i (F-resp-≈ h (identity g)) ⟩
id ∘ F₁ i (F₁ h (Category.id C))
≈⟨ refl⟩∘⟨ F-resp-≈ i (identity h) ⟩
id ∘ F₁ i (Category.id D)
≈⟨ refl⟩∘⟨ identity i ⟩
id ∘ id
∎
}
where
open NaturalTransformation
open NaturalIsomorphism
open Functor
| {
"alphanum_fraction": 0.5204704818,
"avg_line_length": 45.5773195876,
"ext": "agda",
"hexsha": "2405edec8a4d79628cc716788dfbd9a3a7ce49ed",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Bicategory/Instance/Cats.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Bicategory/Instance/Cats.agda",
"max_line_length": 105,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Bicategory/Instance/Cats.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 1764,
"size": 4421
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Application of substitutions to lists, along with various lemmas
------------------------------------------------------------------------
-- This module illustrates how Data.Fin.Substitution.Lemmas.AppLemmas
-- can be used.
{-# OPTIONS --without-K --safe #-}
open import Data.Fin.Substitution.Lemmas
open import Data.Nat using (ℕ)
module Data.Fin.Substitution.List {ℓ} {T : ℕ → Set ℓ} (lemmas₄ : Lemmas₄ T) where
open import Data.List.Base
open import Data.List.Properties
open import Data.Fin.Substitution
import Function as Fun
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
private
open module L = Lemmas₄ lemmas₄ using (_/_; id; _⊙_)
infixl 8 _//_
_//_ : ∀ {m n} → List (T m) → Sub T m n → List (T n)
ts // ρ = map (λ σ → σ / ρ) ts
appLemmas : AppLemmas (λ n → List (T n)) T
appLemmas = record
{ application = record { _/_ = _//_ }
; lemmas₄ = lemmas₄
; id-vanishes = λ ts → begin
ts // id ≡⟨ map-cong L.id-vanishes ts ⟩
map Fun.id ts ≡⟨ map-id ts ⟩
ts ∎
; /-⊙ = λ {_ _ _ ρ₁ ρ₂} ts → begin
ts // ρ₁ ⊙ ρ₂ ≡⟨ map-cong L./-⊙ ts ⟩
map (λ σ → σ / ρ₁ / ρ₂) ts ≡⟨ map-compose ts ⟩
ts // ρ₁ // ρ₂ ∎
}
open AppLemmas appLemmas public
hiding (_/_) renaming (_/✶_ to _//✶_)
| {
"alphanum_fraction": 0.546230441,
"avg_line_length": 29.2916666667,
"ext": "agda",
"hexsha": "d26a29c46b535dc6947cc536dff62e47c553d707",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution/List.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 462,
"size": 1406
} |
module MutualBlockInLet where
postulate
A : Set
a : A
test = let abstract
x = a
y = x
in y
| {
"alphanum_fraction": 0.4885496183,
"avg_line_length": 11.9090909091,
"ext": "agda",
"hexsha": "7c218491fb310c69b3325e021e3ef734e8de2e07",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/fail/AbstractBlockInLet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/fail/AbstractBlockInLet.agda",
"max_line_length": 29,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/AbstractBlockInLet.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 39,
"size": 131
} |
open import Relation.Binary.Core
module PLRTree.Push.Heap {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import Data.Sum
open import Induction.WellFounded
open import Order.Total _≤_ tot≤
open import PLRTree {A}
open import PLRTree.Drop _≤_ tot≤
open import PLRTree.Heap _≤_
open import PLRTree.Heap.Properties _≤_ trans≤
open import PLRTree.Order {A}
open import PLRTree.Order.Properties {A}
lemma-push-≤* : {x y : A}{l r : PLRTree}(t : Tag) → x ≤ y → x ≤* l → x ≤* r → (acc : Acc _≺_ (node t y l r)) → x ≤* (push (node t y l r) acc)
lemma-push-≤* {x} t x≤y (lf≤* .x) x≤*r (acc rs) = nd≤* x≤y (lf≤* x) (lf≤* x)
lemma-push-≤* {x} {y} t x≤y (nd≤* {t'} .{x} {x'} x≤x' x≤*l' x≤*r') (lf≤* .x) (acc rs)
with tot≤ y x'
... | inj₁ y≤x' = nd≤* x≤y (nd≤* x≤x' (lf≤* x) (lf≤* x)) (lf≤* x)
... | inj₂ x'≤y = nd≤* x≤x' (nd≤* x≤y (lf≤* x) (lf≤* x)) (lf≤* x)
lemma-push-≤* {x} {y} t x≤y (nd≤* {t'} .{x} {x'} {l'} {r'} x≤x' x≤*l' x≤*r') (nd≤* {t''} .{x} {x''} {l''} {r''} x≤x'' x≤*l'' x≤*r'') (acc rs)
with tot≤ y x' | tot≤ y x'' | tot≤ x' x''
... | inj₁ y≤x' | inj₁ y≤x'' | _ = nd≤* x≤y (nd≤* x≤x' x≤*l' x≤*r') (nd≤* x≤x'' x≤*l'' x≤*r'')
... | inj₁ y≤x' | inj₂ x''≤y | _ rewrite lemma-≡-height t'' y x'' l'' r'' =
let acc-t''yl''r'' = rs (node t'' y l'' r'') (lemma-≺-right t y (node t' x' l' r') (node t'' x'' l'' r''))
in nd≤* x≤x'' (nd≤* x≤x' x≤*l' x≤*r') (lemma-push-≤* t'' x≤y x≤*l'' x≤*r'' acc-t''yl''r'')
... | inj₂ x'≤y | inj₁ y≤x'' | _ rewrite lemma-≡-height t' y x' l' r' =
let acc-t'yl'r' = rs (node t' y l' r') (lemma-≺-left t y (node t' x' l' r') (node t'' x'' l'' r''))
in nd≤* x≤x' (lemma-push-≤* t' x≤y x≤*l' x≤*r' acc-t'yl'r') (nd≤* x≤x'' x≤*l'' x≤*r'')
... | inj₂ x'≤y | inj₂ x''≤y | inj₁ x'≤x'' rewrite lemma-≡-height t' y x' l' r' =
let acc-t'yl'r' = rs (node t' y l' r') (lemma-≺-left t y (node t' x' l' r') (node t'' x'' l'' r''))
in nd≤* x≤x' (lemma-push-≤* t' x≤y x≤*l' x≤*r' acc-t'yl'r') (nd≤* x≤x'' x≤*l'' x≤*r'')
... | inj₂ x'≤y | inj₂ x''≤y | inj₂ x''≤x' rewrite lemma-≡-height t'' y x'' l'' r'' =
let acc-t''yl''r'' = rs (node t'' y l'' r'') (lemma-≺-right t y (node t' x' l' r') (node t'' x'' l'' r''))
in nd≤* x≤x'' (nd≤* x≤x' x≤*l' x≤*r') (lemma-push-≤* t'' x≤y x≤*l'' x≤*r'' acc-t''yl''r'')
lemma-push-heap : {l r : PLRTree}(t : Tag)(x : A) → Heap l → Heap r → (acc : Acc _≺_ (node t x l r)) → Heap (push (node t x l r) acc)
lemma-push-heap t x leaf _ _ = node (lf≤* x) (lf≤* x) leaf leaf
lemma-push-heap t x (node {t'} {x'} x'≤*l' x'≤*r' hl' hr') leaf (acc rs)
with tot≤ x x'
... | inj₁ x≤x' = node (nd≤* x≤x' (lf≤* x) (lf≤* x)) (lf≤* x) (node (lf≤* x') (lf≤* x') leaf leaf) leaf
... | inj₂ x'≤x = node (nd≤* x'≤x (lf≤* x') (lf≤* x')) (lf≤* x') (node (lf≤* x) (lf≤* x) leaf leaf) leaf
lemma-push-heap t x (node {t'} {x'} {l'} {r'} x'≤*l' x'≤*r' hl' hr') (node {t''} {x''} {l''} {r''} x''≤*l'' x''≤*r'' hl'' hr'') (acc rs)
with tot≤ x x' | tot≤ x x'' | tot≤ x' x''
... | inj₁ x≤x' | inj₁ x≤x'' | _ =
let x≤*t'x'l'r' = nd≤* x≤x' (lemma-≤-≤* x≤x' x'≤*l') (lemma-≤-≤* x≤x' x'≤*r') ;
x≤*t''x''l''r'' = nd≤* x≤x'' (lemma-≤-≤* x≤x'' x''≤*l'') (lemma-≤-≤* x≤x'' x''≤*r'')
in node x≤*t'x'l'r' x≤*t''x''l''r'' (node x'≤*l' x'≤*r' hl' hr') (node x''≤*l'' x''≤*r'' hl'' hr'')
... | inj₁ x≤x' | inj₂ x''≤x | _ rewrite lemma-≡-height t'' x x'' l'' r'' =
let acc-t''xl''r'' = rs (node t'' x l'' r'') (lemma-≺-right t x (node t' x' l' r') (node t'' x'' l'' r'')) ;
x''≤*t'x'l'r' = lemma-≤-≤* x''≤x (nd≤* x≤x' (lemma-≤-≤* x≤x' x'≤*l') (lemma-≤-≤* x≤x' x'≤*r')) ;
x''≤*push-t''xl''r'' = lemma-push-≤* t'' x''≤x x''≤*l'' x''≤*r'' acc-t''xl''r''
in node x''≤*t'x'l'r' x''≤*push-t''xl''r'' (node x'≤*l' x'≤*r' hl' hr') (lemma-push-heap t'' x hl'' hr'' acc-t''xl''r'')
... | inj₂ x'≤x | inj₁ x≤x'' | _ rewrite lemma-≡-height t' x x' l' r' =
let acc-t'xl'r' = rs (node t' x l' r') (lemma-≺-left t x (node t' x' l' r') (node t'' x'' l'' r'')) ;
x'≤*t''x''l''r'' = lemma-≤-≤* x'≤x (nd≤* x≤x'' (lemma-≤-≤* x≤x'' x''≤*l'') (lemma-≤-≤* x≤x'' x''≤*r'')) ;
x'≤*push-t'xl'r' = lemma-push-≤* t' x'≤x x'≤*l' x'≤*r' acc-t'xl'r'
in node x'≤*push-t'xl'r' x'≤*t''x''l''r'' (lemma-push-heap t' x hl' hr' acc-t'xl'r') (node x''≤*l'' x''≤*r'' hl'' hr'')
... | inj₂ x'≤x | inj₂ x''≤x | inj₁ x'≤x'' rewrite lemma-≡-height t' x x' l' r' =
let acc-t'xl'r' = rs (node t' x l' r') (lemma-≺-left t x (node t' x' l' r') (node t'' x'' l'' r'')) ;
x'≤*t''x''l''r'' = lemma-≤-≤* x'≤x'' (nd≤* refl≤ x''≤*l'' x''≤*r'') ;
x'≤*push-t'xl'r' = lemma-push-≤* t' x'≤x x'≤*l' x'≤*r' acc-t'xl'r'
in node x'≤*push-t'xl'r' x'≤*t''x''l''r'' (lemma-push-heap t' x hl' hr' acc-t'xl'r') (node x''≤*l'' x''≤*r'' hl'' hr'')
... | inj₂ x'≤x | inj₂ x''≤x | inj₂ x''≤x' rewrite lemma-≡-height t'' x x'' l'' r'' =
let acc-t''xl''r'' = rs (node t'' x l'' r'') (lemma-≺-right t x (node t' x' l' r') (node t'' x'' l'' r'')) ;
x''≤*t'x'l'r' = lemma-≤-≤* x''≤x' (nd≤* refl≤ x'≤*l' x'≤*r') ;
x''≤*push-t''xl''r'' = lemma-push-≤* t'' x''≤x x''≤*l'' x''≤*r'' acc-t''xl''r''
in node x''≤*t'x'l'r' x''≤*push-t''xl''r'' (node x'≤*l' x'≤*r' hl' hr') (lemma-push-heap t'' x hl'' hr'' acc-t''xl''r'')
| {
"alphanum_fraction": 0.4244070252,
"avg_line_length": 76.7083333333,
"ext": "agda",
"hexsha": "ff3e31fed2390467fee29dac7e2bfc8f50f604cf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/PLRTree/Push/Heap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/PLRTree/Push/Heap.agda",
"max_line_length": 142,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/PLRTree/Push/Heap.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 2932,
"size": 5523
} |
{-# OPTIONS --termination-depth=1 #-}
--{-# OPTIONS -v term:40 #-}
module TerminationWithInsufficientDepth where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
module Depth2 where
-- The fix to issue 59 makes this go through.
-- f : Nat -> Nat
-- f zero = zero
-- f (suc zero) = zero
-- f (suc (suc n)) with zero
-- ... | m = f (suc n)
-- Using a helper function, we still need termination-depth
g : Nat → Nat → Nat
f : Nat → Nat
f zero = zero
f (suc zero) = zero
f (suc (suc n)) = g n zero
g n m = f (suc n)
{- this type checks with --termination-depth >= 2
calls:
f -> f_with (-2)
f_with -> f (+1)
-}
module Depth3 where
f : Nat → Nat
g : Nat → Nat
f zero = zero
f (suc zero) = zero
f (suc (suc zero)) = zero
f (suc (suc (suc n))) = g n
g n = f (suc (suc n))
| {
"alphanum_fraction": 0.5575539568,
"avg_line_length": 17.375,
"ext": "agda",
"hexsha": "b891a0214d9275dcadc535f8f72c56924d43a78b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/TerminationWithInsufficientDepth.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/TerminationWithInsufficientDepth.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/TerminationWithInsufficientDepth.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 299,
"size": 834
} |
{-# OPTIONS --without-K #-}
module Data.ByteString.Primitive.Strict where
open import Data.Word8.Primitive using (Word8)
open import Agda.Builtin.Nat using (Nat)
open import Agda.Builtin.List using (List)
open import Agda.Builtin.String using (String)
open import Agda.Builtin.Bool using (Bool)
open import Agda.Builtin.IO using (IO)
open import Data.Tuple.Base using (Pair)
{-# FOREIGN GHC import qualified Data.Word #-}
{-# FOREIGN GHC import qualified Data.Text #-}
{-# FOREIGN GHC import qualified Data.ByteString #-}
open import Foreign.Haskell using (Unit)
open import Data.ByteString.Primitive.Int
postulate
ByteStringStrict : Set
readBinaryFileStrict : String → IO ByteStringStrict
writeBinaryFileStrict : String → ByteStringStrict → IO Unit
List←Strict : ByteStringStrict → List Word8
List→Strict : List Word8 → ByteStringStrict
emptyStrict : ByteStringStrict
nullStrict : ByteStringStrict → Bool
lengthStrict : ByteStringStrict → Int
headStrict : ByteStringStrict → Word8
tailStrict : ByteStringStrict → ByteStringStrict
indexStrict : ByteStringStrict → Int → Word8
splitAtStrict : Int → ByteStringStrict → Pair ByteStringStrict ByteStringStrict
{-# COMPILE GHC ByteStringStrict = type
Data.ByteString.ByteString
#-}
{-# COMPILE GHC readBinaryFileStrict =
( Data.ByteString.readFile
. Data.Text.unpack
)
#-}
{-# COMPILE GHC writeBinaryFileStrict =
( Data.ByteString.writeFile
. Data.Text.unpack
)
#-}
{-# COMPILE GHC List←Strict =
( Data.ByteString.unpack ) #-}
{-# COMPILE GHC List→Strict =
( Data.ByteString.pack ) #-}
{-# COMPILE GHC emptyStrict = (Data.ByteString.empty) #-}
{-# COMPILE GHC nullStrict = (Data.ByteString.null) #-}
{-# COMPILE GHC lengthStrict = (Data.ByteString.length) #-}
{-# COMPILE GHC headStrict = (Data.ByteString.head) #-}
{-# COMPILE GHC tailStrict = (Data.ByteString.tail) #-}
{-# COMPILE GHC indexStrict = (Data.ByteString.index) #-}
{-# COMPILE GHC splitAtStrict = (Data.ByteString.splitAt) #-}
| {
"alphanum_fraction": 0.7274529237,
"avg_line_length": 34.2033898305,
"ext": "agda",
"hexsha": "098a7ec8c492ead92ce9a1409402d8b514f9ab25",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/bytes-agda",
"max_forks_repo_path": "src/Data/ByteString/Primitive/Strict.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "semenov-vladyslav/bytes-agda",
"max_issues_repo_path": "src/Data/ByteString/Primitive/Strict.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/bytes-agda",
"max_stars_repo_path": "src/Data/ByteString/Primitive/Strict.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 462,
"size": 2018
} |
module Logics.Not where
open import Function
open import Relation.Nullary
------------------------------------------------------------------------
-- internal stuffs
private
a=¬∘¬a : ∀ {a} {A : Set a} → A → ¬ (¬ A)
a=¬∘¬a a z = z a
/p→q/→¬/p→¬q/ : ∀ {p q} {P : Set p} {Q : Set q} → (P → Q) → (¬ Q → ¬ P)
/p→q/→¬/p→¬q/ p→q ¬q p = ¬q $ p→q p
------------------------------------------------------------------------
-- public aliases
not-not : ∀ {ℓ} {A : Set ℓ} → A → ¬ (¬ A)
not-not = a=¬∘¬a
contrapositive : ∀ {p q} {P : Set p} {Q : Set q} → (P → Q) → (¬ Q → ¬ P)
contrapositive = /p→q/→¬/p→¬q/
| {
"alphanum_fraction": 0.3524590164,
"avg_line_length": 24.4,
"ext": "agda",
"hexsha": "4683a4734a32ba1164c951266e7c8df161b02a83",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Logics/Not.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Logics/Not.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Logics/Not.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 233,
"size": 610
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
open import Algebra
module Algebra.Properties.Group {g₁ g₂} (G : Group g₁ g₂) where
open Group G
import Algebra.FunctionProperties as P; open P _≈_
import Relation.Binary.EqReasoning as EqR; open EqR setoid
open import Function
open import Data.Product
⁻¹-involutive : ∀ x → x ⁻¹ ⁻¹ ≈ x
⁻¹-involutive x = begin
x ⁻¹ ⁻¹ ≈⟨ sym $ proj₂ identity _ ⟩
x ⁻¹ ⁻¹ ∙ ε ≈⟨ refl ⟨ ∙-cong ⟩ sym (proj₁ inverse _) ⟩
x ⁻¹ ⁻¹ ∙ (x ⁻¹ ∙ x) ≈⟨ sym $ assoc _ _ _ ⟩
x ⁻¹ ⁻¹ ∙ x ⁻¹ ∙ x ≈⟨ proj₁ inverse _ ⟨ ∙-cong ⟩ refl ⟩
ε ∙ x ≈⟨ proj₁ identity _ ⟩
x ∎
private
left-helper : ∀ x y → x ≈ (x ∙ y) ∙ y ⁻¹
left-helper x y = begin
x ≈⟨ sym (proj₂ identity x) ⟩
x ∙ ε ≈⟨ refl ⟨ ∙-cong ⟩ sym (proj₂ inverse y) ⟩
x ∙ (y ∙ y ⁻¹) ≈⟨ sym (assoc x y (y ⁻¹)) ⟩
(x ∙ y) ∙ y ⁻¹ ∎
right-helper : ∀ x y → y ≈ x ⁻¹ ∙ (x ∙ y)
right-helper x y = begin
y ≈⟨ sym (proj₁ identity y) ⟩
ε ∙ y ≈⟨ sym (proj₁ inverse x) ⟨ ∙-cong ⟩ refl ⟩
(x ⁻¹ ∙ x) ∙ y ≈⟨ assoc (x ⁻¹) x y ⟩
x ⁻¹ ∙ (x ∙ y) ∎
left-identity-unique : ∀ x y → x ∙ y ≈ y → x ≈ ε
left-identity-unique x y eq = begin
x ≈⟨ left-helper x y ⟩
(x ∙ y) ∙ y ⁻¹ ≈⟨ eq ⟨ ∙-cong ⟩ refl ⟩
y ∙ y ⁻¹ ≈⟨ proj₂ inverse y ⟩
ε ∎
right-identity-unique : ∀ x y → x ∙ y ≈ x → y ≈ ε
right-identity-unique x y eq = begin
y ≈⟨ right-helper x y ⟩
x ⁻¹ ∙ (x ∙ y) ≈⟨ refl ⟨ ∙-cong ⟩ eq ⟩
x ⁻¹ ∙ x ≈⟨ proj₁ inverse x ⟩
ε ∎
identity-unique : ∀ {x} → Identity x _∙_ → x ≈ ε
identity-unique {x} id = left-identity-unique x x (proj₂ id x)
left-inverse-unique : ∀ x y → x ∙ y ≈ ε → x ≈ y ⁻¹
left-inverse-unique x y eq = begin
x ≈⟨ left-helper x y ⟩
(x ∙ y) ∙ y ⁻¹ ≈⟨ eq ⟨ ∙-cong ⟩ refl ⟩
ε ∙ y ⁻¹ ≈⟨ proj₁ identity (y ⁻¹) ⟩
y ⁻¹ ∎
right-inverse-unique : ∀ x y → x ∙ y ≈ ε → y ≈ x ⁻¹
right-inverse-unique x y eq = begin
y ≈⟨ sym (⁻¹-involutive y) ⟩
y ⁻¹ ⁻¹ ≈⟨ ⁻¹-cong (sym (left-inverse-unique x y eq)) ⟩
x ⁻¹ ∎
| {
"alphanum_fraction": 0.4603036876,
"avg_line_length": 32.4647887324,
"ext": "agda",
"hexsha": "93e2a9f6668e28f7316638b34f4890d1c2494967",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Algebra/Properties/Group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Algebra/Properties/Group.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Algebra/Properties/Group.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 974,
"size": 2305
} |
record R (A B : Set) : Set where
constructor c₁
field
x : A
mutual
T : Set
T = R D T
data D : Set where
c₂ : T → D
f : T → Set
f (c₁ (c₂ x)) = f x
| {
"alphanum_fraction": 0.4970414201,
"avg_line_length": 10.5625,
"ext": "agda",
"hexsha": "274b0913942ebac5f6f0f1583486cdd559a46828",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2997.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2997.agda",
"max_line_length": 32,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2997.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 74,
"size": 169
} |
open import Auto.Core using (Rule; RuleName; _≟-RuleName_; name2rule; IsHintDB)
open import Level using (zero)
open import Function using (id; _∘_)
open import Category.Functor using (module RawFunctor)
open import Data.Bool as Bool using (if_then_else_)
open import Data.List as List using (List; _++_; []; [_])
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Nat as Nat using (ℕ; pred)
open import Data.Product as Prod using (∃; _,_; proj₂)
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂)
open import Data.Unit as Unit using (⊤)
open import Reflection using (Name)
open import Relation.Nullary.Decidable using (⌊_⌋)
module Auto.Counting where
--------------------------------------------------------------------------------
-- Define a 'counting' hint database which, upon selection of a rule will --
-- decrement an associated 'count' value, and upon reaching 0 will delete --
-- the hint from the hint database. --
-- --
-- The count values can either be natural numbers, in which case they --
-- will be decremented as expected, or the value ⊤, in which case they --
-- will not be decremented, effectively inserting infinite copies of the --
-- rule into the hint database. --
--------------------------------------------------------------------------------
module CountingHintDB where
open RawFunctor (Maybe.functor {zero}) using (_<$>_)
Count : Set
Count = ℕ ⊎ ⊤
record Hint (k : ℕ) : Set where
constructor mkHint
field
rule : Rule k
count : Count
ruleName : RuleName
ruleName = Rule.name rule
HintDB : Set
HintDB = List (∃ Hint)
decrCount : ∀ {k} → Hint k → Maybe (Hint k)
decrCount {k} (mkHint r c) = mkHint r <$> decrCount′ c
where
decrCount′ : Count → Maybe Count
decrCount′ (inj₁ 0) = nothing
decrCount′ (inj₁ 1) = nothing
decrCount′ (inj₁ x) = just (inj₁ (pred x))
decrCount′ (inj₂ _) = just (inj₂ _)
getTr : ∀ {k} → Hint k → (HintDB → HintDB)
getTr h₁ = List.concatMap (List.fromMaybe ∘ mdecr₁)
where
mdecr₁ : ∃ Hint → Maybe (∃ Hint)
mdecr₁ (_ , h₂) =
if ⌊ Hint.ruleName h₁ ≟-RuleName Hint.ruleName h₂ ⌋
then (_,_ _) <$> decrCount h₂
else just (_ , h₂)
countingHintDB : IsHintDB
countingHintDB = record
{ HintDB = HintDB
; Hint = Hint
; getHints = id
; getRule = Hint.rule
; getTr = getTr
; ε = []
; _∙_ = _++_
; return = λ r → [ _ , mkHint r (inj₂ _) ]
}
open CountingHintDB using (mkHint; countingHintDB)
open import Auto.Extensible countingHintDB public
--------------------------------------------------------------------------------
-- Define some new syntax in order to insert rules with limited usage. --
--------------------------------------------------------------------------------
infixl 5 _<<[_]_
_<<[_]_ : HintDB → ℕ → Name → HintDB
db <<[ 0 ] _ = db
db <<[ x ] n with (name2rule n)
db <<[ x ] n | inj₁ msg = db
db <<[ x ] n | inj₂ (k , r) = db ∙ [ k , mkHint r (inj₁ x) ]
| {
"alphanum_fraction": 0.5104381064,
"avg_line_length": 35.0618556701,
"ext": "agda",
"hexsha": "5777aca1d40fcc4b83fabb9272db3cf395fca365",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2019-07-07T07:37:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-10T10:47:30.000Z",
"max_forks_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/AutoInAgda",
"max_forks_repo_path": "src/Auto/Counting.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_issues_repo_issues_event_max_datetime": "2017-11-06T16:49:27.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-11-03T09:46:19.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wenkokke/AutoInAgda",
"max_issues_repo_path": "src/Auto/Counting.agda",
"max_line_length": 96,
"max_stars_count": 22,
"max_stars_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/AutoInAgda",
"max_stars_repo_path": "src/Auto/Counting.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-20T15:04:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-07-18T18:14:09.000Z",
"num_tokens": 894,
"size": 3401
} |
module Cats.Category.Setoids.Facts.Initial where
open import Data.Empty using (⊥)
open import Level
open import Cats.Category
open import Cats.Category.Setoids using (Setoids ; ≈-intro)
module Build {l} {l≈} where
open Category (Setoids l l≈)
Zero : Obj
Zero = record
{ Carrier = Lift l ⊥
; _≈_ = λ()
; isEquivalence = record
{ refl = λ{}
; sym = λ{}
; trans = λ{}
}
}
isInitial : IsInitial Zero
isInitial X = ∃!-intro
(record { arr = λ() ; resp = λ{} })
_
λ _ → ≈-intro λ {}
open Build
instance
hasInitial : ∀ l l≈ → HasInitial (Setoids l l≈)
hasInitial l l≈ = record
{ Zero = Zero
; isInitial = isInitial
}
| {
"alphanum_fraction": 0.5529891304,
"avg_line_length": 17.1162790698,
"ext": "agda",
"hexsha": "b15b0a1ed9f64c2f39074cd555e405d5717ef409",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Setoids/Facts/Initial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Setoids/Facts/Initial.agda",
"max_line_length": 59,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Setoids/Facts/Initial.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 222,
"size": 736
} |
module Generic.Lib.Data.Nat where
open import Data.Nat.Base hiding (_⊔_; _^_) public
open import Generic.Lib.Decidable
instance
ℕEq : Eq ℕ
ℕEq = viaBase Nat._≟_ where
import Data.Nat as Nat
foldℕ : ∀ {α} {A : Set α} -> (A -> A) -> A -> ℕ -> A
foldℕ f x 0 = x
foldℕ f x (suc n) = f (foldℕ f x n)
| {
"alphanum_fraction": 0.6102236422,
"avg_line_length": 20.8666666667,
"ext": "agda",
"hexsha": "ccb97f26d9d336da3ab4e6f754f2d68813c79d02",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Data/Nat.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Data/Nat.agda",
"max_line_length": 52,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Data/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 121,
"size": 313
} |
{-# OPTIONS --without-K #-}
module container.equality where
open import level
open import sum
open import equality.core
open import function.isomorphism
open import function.extensionality
open import container.core
open import container.fixpoint
module Equality {li la lb lx}
(c : Container li la lb)
(fp : Fixpoint c lx) where
open Container c
open Fixpoint fp
substX : {i : I}{a a' : A i}(p : a ≡ a')(b : B a)
→ X (r (subst B p b)) → X (r b)
substX refl _ x = x
substX-β : ∀ {i} {a a' : A i}
(f : (b : B a) → X (r b))
(f' : (b : B a') → X (r b))
(p : a ≡ a')
→ (subst (λ a → (b : B a) → X (r b)) p f ≡ f')
≅ ((b : B a) → f b ≡ substX p b (f' (subst B p b)))
substX-β f f' refl = sym≅ strong-funext-iso
-- structural equality for container fixpoints
I-≡ : Set (li ⊔ lx)
I-≡ = Σ I λ i → X i × X i
A-≡ : I-≡ → Set la
A-≡ (_ , u , v) = head u ≡ head v
B-≡ : {j : I-≡} → A-≡ j → Set lb
B-≡ {_ , u , _} _ = B (head u)
r-≡ : {j : I-≡}{p : A-≡ j} → B-≡ p → I-≡
r-≡ {i , u , v}{p} b = r b , tail u b , substX p b (tail v (subst B p b))
equality : Container _ _ _
equality = record
{ I = I-≡
; A = A-≡
; B = B-≡
; r = (λ {j p} → r-≡ {j} {p}) }
| {
"alphanum_fraction": 0.4765204003,
"avg_line_length": 25.98,
"ext": "agda",
"hexsha": "b8680b9ad05e9f5ad409771e2073a428d9b28317",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/container/equality.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/container/equality.agda",
"max_line_length": 75,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/equality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 521,
"size": 1299
} |
module Issue2487.A where
| {
"alphanum_fraction": 0.84,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "c9f638bbca04a14392454c4764039b533da85487",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2487/A.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2487/A.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2487/A.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 7,
"size": 25
} |
module Class.Show where
open import Data.String using (String)
record Show {a} (A : Set a) : Set a where
field
show : A -> String
open Show {{...}} public
| {
"alphanum_fraction": 0.6463414634,
"avg_line_length": 16.4,
"ext": "agda",
"hexsha": "effc1fb27c35eb61fb333eeb5a8d284272bfd93b",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Class/Show.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Class/Show.agda",
"max_line_length": 41,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Class/Show.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 46,
"size": 164
} |
postulate
Nat : Set
succ : Nat → Nat
Le : Nat → Nat → Set
Fin : Nat → Set
low : ∀ {m n} → Le m n → Fin n → Fin m
instance
Le-refl : ∀ {n} → Le n n
Le-succ : ∀ {m n} ⦃ _ : Le m n ⦄ → Le m (succ n)
Chk1 : ∀ {n} → Fin n → Set
Chk2 : ∀ {n} → Fin n → Fin n → Set
Chk3 : ∀ {m n} ⦃ _ : Le m n ⦄ → Fin m → Fin n → Set
variable
le : Le _ _
X G : Fin _
postulate
works : Chk1 G
→ Chk2 (low le G) X
→ Chk3 X G
-- WAS: Instance argument got solved with `Le-refl`, which is not
-- type-correct.
-- SHOULD: result in a failed instance search
fails : Chk2 (low le G) X
→ Chk3 X G
| {
"alphanum_fraction": 0.5118483412,
"avg_line_length": 21.8275862069,
"ext": "agda",
"hexsha": "b1a622b8765eb62f10962cfd88418070eeea242d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue3464.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue3464.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue3464.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 259,
"size": 633
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.FinData.Properties where
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Data.FinData.Base as Fin
import Cubical.Data.Nat as ℕ
open import Cubical.Data.Empty as Empty
open import Cubical.Relation.Nullary
private
variable
ℓ : Level
A : Type ℓ
znots : ∀{k} {m : Fin k} → ¬ (zero ≡ (suc m))
znots {k} {m} x = subst (Fin.rec (Fin k) ⊥) x m
snotz : ∀{k} {m : Fin k} → ¬ ((suc m) ≡ zero)
snotz {k} {m} x = subst (Fin.rec ⊥ (Fin k)) x m
isPropFin0 : isProp (Fin 0)
isPropFin0 = Empty.rec ∘ ¬Fin0
isContrFin1 : isContr (Fin 1)
isContrFin1 .fst = zero
isContrFin1 .snd zero = refl
injSucFin : ∀ {n} { p q : Fin n} → suc p ≡ suc q → p ≡ q
injSucFin {ℕ.suc ℕ.zero} {zero} {zero} pf = refl
injSucFin {ℕ.suc (ℕ.suc n)} pf = cong predFin pf
discreteFin : ∀{k} → Discrete (Fin k)
discreteFin zero zero = yes refl
discreteFin zero (suc y) = no znots
discreteFin (suc x) zero = no snotz
discreteFin (suc x) (suc y) with discreteFin x y
... | yes p = yes (cong suc p)
... | no ¬p = no (λ q → ¬p (injSucFin q))
isSetFin : ∀{k} → isSet (Fin k)
isSetFin = Discrete→isSet discreteFin
| {
"alphanum_fraction": 0.6608623549,
"avg_line_length": 25.6595744681,
"ext": "agda",
"hexsha": "3cef723fff8264c8f20bf52a0a5760e230fa6da5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/FinData/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/FinData/Properties.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/FinData/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 461,
"size": 1206
} |
module Sandbox.IndRecIndexed where
-- Ornamental Algebras, Algebraic Ornaments, CONOR McBRIDE
-- https://personal.cis.strath.ac.uk/conor.mcbride/pub/OAAO/Ornament.pdf
-- A Finite Axiomtization of Inductive-Recursion definitions, Peter Dybjer, Anton Setzer
-- http://www.cse.chalmers.se/~peterd/papers/Finite_IR.pdf
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)
open import Data.Bool
open import Data.Unit
open import Data.Empty
open import Function
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
data Desc (I : Set) : Set₁ where
arg : (A : Set) → (A → Desc I) → Desc I
rec : I → Desc I → Desc I
ret : I → Desc I
⟦_⟧ : ∀ {I} → Desc I → (I → Set) → (I → Set)
⟦ arg A D ⟧ R i = Σ A (λ a → ⟦ D a ⟧ R i)
⟦ rec j D ⟧ R i = R j × ⟦ D ⟧ R i
⟦ ret j ⟧ R i = j ≡ i
data Data {I} (D : Desc I) : I → Set where
⟨_⟩ : ∀ {i} → ⟦ D ⟧ (Data D) i → Data D i
-- an arrow that respects indices
_⇒_ : ∀ {I} → (I → Set) → (I → Set) → Set
_⇒_ {I} X Y = (i : I) → X i → Y i
map : ∀ {I} {A B : I → Set} → (D : Desc I) → (A ⇒ B) → ⟦ D ⟧ A ⇒ ⟦ D ⟧ B
map (arg T U) f i (t , u) = t , map (U t) f i u
map (rec j D) f i (a , u) = f j a , map D f i u
map (ret j) f i i≡j = i≡j
Alg : ∀ {I} (D : Desc I) → (A : I → Set) → Set
Alg D A = ⟦ D ⟧ A ⇒ A
-- fold D alg i ⟨ x ⟩ = alg i (map D (fold D alg) i x)
-- mapFold F G alg i x = map F (fold G alg) i x
mapFold : ∀ {I} {A : I → Set} (F G : Desc I) → Alg G A → ⟦ F ⟧ (Data G) ⇒ ⟦ F ⟧ A
mapFold (arg Tags decoder) G alg i (tag , subnode) = tag , (mapFold (decoder tag) G alg i subnode)
mapFold (rec j F) G alg i (⟨ x ⟩ , xs) = alg j (mapFold G G alg j x) , mapFold F G alg i xs
mapFold (ret j) G alg i x = x
fold : ∀ {I} {A : I → Set} (D : Desc I) → Alg D A → Data D ⇒ A
fold D alg i ⟨ x ⟩ = alg i (mapFold D D alg i x)
-- ℕ
ℕDesc : Desc ⊤
ℕDesc = arg Bool (λ { true → rec tt (ret tt) ; false → ret tt })
ℕ : Set
ℕ = Data ℕDesc tt
zero : ℕ
zero = ⟨ (false , refl) ⟩
suc : ℕ → ℕ
suc n = ⟨ (true , (n , refl)) ⟩
-- indℕ : (P : ℕ → Set)
-- → P zero
-- → ((n : ℕ) → P n → P (suc n))
-- → (x : ℕ)
-- → P x
-- indℕ P base step ⟨ true , n , refl ⟩ = step n (indℕ P base step n)
-- indℕ P base step ⟨ false , refl ⟩ = base
--
-- _+_ : ℕ → ℕ → ℕ
-- x + y = indℕ (λ _ → ℕ) y (λ n prf → suc prf) x
+alg : ℕ → Alg ℕDesc (λ _ → ℕ)
+alg y .tt (true , sum , refl) = suc sum
+alg y .tt (false , refl) = y
_+_ : ℕ → ℕ → ℕ
x + y = fold ℕDesc (+alg y) tt x
one : ℕ
one = suc zero
two : ℕ
two = suc one
+-suc-left : (m n : ℕ) → suc m + n ≡ suc (m + n)
+-suc-left ⟨ true , m , refl ⟩ n = refl
+-suc-left ⟨ false , refl ⟩ n = refl
-- Nat
NatDesc : Desc ℕ
NatDesc = arg Bool (
λ { true → arg ℕ (λ { n → rec n (ret (suc n)) })
; false → ret zero
})
Nat : ℕ → Set
Nat n = Data NatDesc n
zeroNat : Nat zero
zeroNat = ⟨ (false , refl) ⟩
sucNat : ∀ {n} → Nat n → Nat (suc n)
sucNat {n} x = ⟨ (true , (n , (x , refl))) ⟩
-- Maybe
MaybeDesc : Set → Desc ⊤
MaybeDesc A = arg Bool (λ { true → arg A (λ _ → ret tt) ; false → ret tt })
Maybe : Set → Set
Maybe A = Data (MaybeDesc A) tt
nothing : ∀ {A} → Maybe A
nothing = ⟨ (false , refl) ⟩
just : ∀ {A} → A → Maybe A
just n = ⟨ (true , (n , refl)) ⟩
-- List
ListDesc : Set → Desc ⊤
ListDesc A = arg Bool (
λ { true → arg A (λ _ → rec tt (ret tt))
; false → ret tt
})
List : Set → Set
List A = Data (ListDesc A) tt
nil : ∀ {A} → List A
nil = ⟨ (false , refl) ⟩
cons : ∀ {A} → A → List A → List A
cons x xs = ⟨ (true , (x , (xs , refl))) ⟩
indList : ∀ {A} (P : List A → Set)
→ P nil
→ ((x : A) → (xs : List A) → P xs → P (cons x xs))
→ (xs : List A)
→ P xs
indList P base step ⟨ true , x , xs , refl ⟩ = step x xs (indList P base step xs)
indList P base step ⟨ false , refl ⟩ = base
-- Vec
VecDesc : Set → Desc ℕ
VecDesc A = arg Bool (
λ { true → arg A (λ _ → arg ℕ (λ n → rec n (ret (suc n))))
; false → ret zero
})
Vec : Set → ℕ → Set
Vec A n = Data (VecDesc A) n
nilV : ∀ {A} → Vec A zero
nilV = ⟨ false , refl ⟩
consV : ∀ {A n} → A → Vec A n → Vec A (suc n)
consV {A} {n} x xs = ⟨ true , x , n , xs , refl ⟩
++alg : ∀ {A n} → Vec A n → Alg (VecDesc A) (λ m → Vec A (m + n))
++alg {A} {n} ys .(suc o) (true , z , o , zs , refl) = ⟨ true , z , o + n , zs , sym (+-suc-left o n) ⟩
++alg ys .zero (false , refl) = ys
_++_ : ∀ {A m n} → Vec A m → Vec A n → Vec A (m + n)
_++_ {A} {m} {n} xs ys = fold (VecDesc A) (++alg ys) m xs
-- inverse image of e : J → I
data Inv {J I : Set} (e : J → I) : I → Set where
inv : (j : J) → Inv e (e j)
data Orn {J I : Set} (e : J → I) : Desc I → Set₁ where
arg : (A : Set) → {D : A → Desc I} → ((a : A) → Orn e (D a)) → Orn e (Desc.arg A D)
rec : ∀ {h D} → Inv e h → Orn e D → Orn e (rec h D)
ret : ∀ {o} → Inv e o → Orn e (ret o)
new : ∀ {D} → (A : Set) → ((a : A) → Orn e D) → Orn e D
ListOrn : Set → Orn (λ x → tt) ℕDesc
ListOrn A = arg Bool (λ { true → Orn.new A (λ a → rec (inv tt) (ret (inv tt)))
; false → Orn.ret (inv tt)})
orn : ∀ {I J} {D : Desc I} {e : J → I} → Orn e D → Desc J
orn (arg A O) = arg A (λ x → orn (O x))
orn (rec (inv j) O) = rec j (orn O)
orn (ret (inv j)) = ret j
orn (new A O) = arg A (λ x → orn (O x))
ListDesc' : Set → Desc ⊤
ListDesc' A = orn (ListOrn A)
erase : ∀ {I J} {R : I → Set} {e : J → I} {D : Desc I} → (O : Orn e D) → ⟦ orn O ⟧ (R ∘ e) ⇒ (⟦ D ⟧ R ∘ e)
erase (arg A O) i (a , os) = a , (erase (O a) i os)
erase (rec (inv i) O) j (r , os) = r , erase O j os
erase (ret (inv j)) .j refl = refl
erase (new A O) j (a , os) = erase (O a) j os
ornament-algebra : ∀ {I J} {e : J → I} {D : Desc I} → (O : Orn e D) → Alg (orn O) (λ j → Data D (e j))
ornament-algebra O j x = ⟨ erase O j x ⟩
forget : ∀ {I J} {e : J → I} {D : Desc I} {O : Orn e D} {j : J} → Data (orn O) j → Data D (e j)
forget {I} {J} {e} {D} {O} {j} = fold (orn O) (ornament-algebra O) j
algo : ∀ {I A} → (D : Desc I) → Alg D A → Orn {Σ I {! A !}} proj₁ D
algo (arg A x) alg = arg A (λ a → algo (x a) (λ j ds → alg j (a , ds)))
algo {I} {A} (rec i D) alg = new (A i) (λ a → rec (inv (i , a)) (algo D (λ j ds → alg i (a , {! ds !}))))
algo (ret i) alg = ret (inv (i , alg i refl))
| {
"alphanum_fraction": 0.4991173166,
"avg_line_length": 30.1014492754,
"ext": "agda",
"hexsha": "5de4937d40ada717098af54928f79531f4fc782d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Sandbox/IndRecIndexed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Sandbox/IndRecIndexed.agda",
"max_line_length": 106,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Sandbox/IndRecIndexed.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 2602,
"size": 6231
} |
{-# OPTIONS --without-K #-}
open import Type using (Type₀; Type₁)
open import Type.Identities
open import Data.Zero using (𝟘)
open import Data.One using (𝟙; 0₁)
open import Data.Two.Base using (𝟚; 0₂; 1₂)
open import Data.Product.NP using (Σ; _×_)
open import Data.Sum.NP using (_⊎_)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Fin using (Fin)
open import Data.Vec using (Vec)
open import HoTT using (ua; UA; module Equivalences)
open import Relation.Binary.PropositionalEquality.NP using (_≡_; !_; _∙_; idp)
open Equivalences using (_≃_; ≃-!; ≃-refl; _≃-∙_)
module Explore.Universe.Type {X : Type₀} where
infixr 2 _×ᵁ_
data U : Type₁
El : U → Type₀
data U where
𝟘ᵁ 𝟙ᵁ 𝟚ᵁ : U
_×ᵁ_ _⊎ᵁ_ : U → U → U
Σᵁ : (u : U) (f : El u → U) → U
Xᵁ : U
≃ᵁ : (u : U) (A : Type₀) (e : El u ≃ A) → U
El 𝟘ᵁ = 𝟘
El 𝟙ᵁ = 𝟙
El 𝟚ᵁ = 𝟚
El (u₀ ×ᵁ u₁) = El u₀ × El u₁
El (u₀ ⊎ᵁ u₁) = El u₀ ⊎ El u₁
El (Σᵁ u f) = Σ (El u) λ x → El (f x)
El Xᵁ = X
El (≃ᵁ u A e) = A
infix 8 _^ᵁ_
_^ᵁ_ : U → ℕ → U
u ^ᵁ zero = 𝟙ᵁ
u ^ᵁ suc n = u ×ᵁ u ^ᵁ n
^ᵁ≃Vec : ∀ u n → El (u ^ᵁ n) ≃ Vec (El u) n
^ᵁ≃Vec u zero = ≃-! Vec0≃𝟙
^ᵁ≃Vec u (suc n) = ×≃-second (El u) (^ᵁ≃Vec u n) ≃-∙ ≃-! Vec∘suc≃×
^ᵁ≡Vec : ∀ {{_ : UA}} u n → El (u ^ᵁ n) ≡ Vec (El u) n
^ᵁ≡Vec u n = ua (^ᵁ≃Vec u n)
Finᵁ : ℕ → U
Finᵁ zero = 𝟘ᵁ
Finᵁ (suc n) = 𝟙ᵁ ⊎ᵁ Finᵁ n
Finᵁ' : ℕ → U
Finᵁ' zero = 𝟘ᵁ
Finᵁ' (suc zero) = 𝟙ᵁ
Finᵁ' (suc (suc n)) = 𝟙ᵁ ⊎ᵁ Finᵁ' (suc n)
Finᵁ≃Fin : ∀ n → El (Finᵁ n) ≃ Fin n
Finᵁ≃Fin zero = ≃-! Fin0≃𝟘
Finᵁ≃Fin (suc n) = ⊎≃ ≃-refl (Finᵁ≃Fin n) ≃-∙ ≃-! Fin∘suc≃𝟙⊎Fin
Finᵁ'≃Fin : ∀ n → El (Finᵁ' n) ≃ Fin n
Finᵁ'≃Fin zero = ≃-! Fin0≃𝟘
Finᵁ'≃Fin (suc zero) = ≃-! Fin1≃𝟙
Finᵁ'≃Fin (suc (suc n)) = ⊎≃ ≃-refl (Finᵁ'≃Fin (suc n)) ≃-∙ ≃-! Fin∘suc≃𝟙⊎Fin
| {
"alphanum_fraction": 0.5574419921,
"avg_line_length": 25.9852941176,
"ext": "agda",
"hexsha": "f562f6f40c7c70a35693f1670a312eaa7a1b0586",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Universe/Type.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Universe/Type.agda",
"max_line_length": 78,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Universe/Type.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 1067,
"size": 1767
} |
module Oscar.Property.Preservativity where
open import Oscar.Level
open import Oscar.Relation
record Preservativity
{a} {A : Set a} {b} {B : A → Set b} {c} {C : (x : A) → B x → Set c}
(_▻₁_ : (x : A) → (y : B x) → C x y)
{d} {D : Set d} {e} {E : D → Set e} {f} {F : (x : D) → E x → Set f}
(_▻₂_ : (x : D) → (y : E x) → F x y)
{ℓ}
(_≤_ : ∀ {x y} → F x y → F x y → Set ℓ)
(◽ : A → D)
(◻ : ∀ {x} → B x → E (◽ x))
(□ : ∀ {x y} → C x y → F (◽ x) (◻ y))
: Set (a ⊔ b ⊔ c ⊔ d ⊔ e ⊔ f ⊔ ℓ) where
field
preservativity : ∀ (x : A) (y : B x) → □ (x ▻₁ y) ≤ (◽ x ▻₂ ◻ y)
open Preservativity ⦃ … ⦄ public
-- -- record Preservativity
-- -- {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁} {_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁}
-- -- (_◅₁_ : ∀ {m n} → m ►₁ n → ∀ {l} → m ⟨ l ►₁_ ⟩→ n)
-- -- {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂} (_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂)
-- -- (_◅₂_ : ∀ {m n} → m ►₂ n → ∀ {l} → m ⟨ l ►₂_ ⟩→ n)
-- -- {ℓ}
-- -- (_≤_ : ∀ {m n} → m ►₂ n → m ►₂ n → Set ℓ)
-- -- {μ : 𝔄₁ → 𝔄₂}
-- -- (◽ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n)
-- -- : Set (𝔞₁ ⊔ 𝔰₁ ⊔ 𝔞₂ ⊔ 𝔰₂ ⊔ ℓ) where
-- -- field
-- -- preservativity : ∀ {l m} (f : l ►₁ m) {n} (g : m ►₁ n) → ◽ (g ◅₁ f) ≤ (◽ g ◅₂ ◽ f)
-- -- open Preservativity ⦃ … ⦄ public
-- -- -- record Preservativity
-- -- -- {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁}
-- -- -- (_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁) {𝔱₁}
-- -- -- {▸₁ : 𝔄₁ → Set 𝔱₁}
-- -- -- (_◃₁_ : ∀ {m n} → m ►₁ n → m ⟨ ▸₁ ⟩→ n)
-- -- -- {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂}
-- -- -- (_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂) {𝔱₂}
-- -- -- {▸₂ : 𝔄₂ → Set 𝔱₂}
-- -- -- (_◃₂_ : ∀ {m n} → m ►₂ n → m ⟨ ▸₂ ⟩→ n)
-- -- -- {ℓ}
-- -- -- (_≤_ : ∀ {n} → ▸₂ n → ▸₂ n → Set ℓ)
-- -- -- {μ : 𝔄₁ → 𝔄₂}
-- -- -- (◽ : ∀ {n} → ▸₁ n → ▸₂ (μ n))
-- -- -- (□ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n)
-- -- -- : Set (𝔞₁ ⊔ 𝔰₁ ⊔ 𝔱₁ ⊔ 𝔞₂ ⊔ 𝔰₂ ⊔ 𝔱₂ ⊔ ℓ) where
-- -- -- field
-- -- -- preservativity : ∀ {m n} (f : ▸₁ m) (g : m ►₁ n) → ◽ (g ◃₁ f) ≤ (□ g ◃₂ ◽ f)
-- -- -- open Preservativity ⦃ … ⦄ public
-- -- -- open import Oscar.Class.Associativity
-- -- -- open import Oscar.Class.Symmetry
-- -- -- open import Oscar.Function
-- -- -- instance
-- -- -- Preservativity⋆ : ∀
-- -- -- {𝔞} {𝔄 : Set 𝔞} {𝔰} {_►_ : 𝔄 → 𝔄 → Set 𝔰}
-- -- -- {_◅_ : ∀ {m n} → m ► n → ∀ {l} → m ⟨ l ►_ ⟩→ n}
-- -- -- {𝔱} {▸ : 𝔄 → Set 𝔱}
-- -- -- {_◃_ : ∀ {m n} → m ► n → m ⟨ ▸ ⟩→ n}
-- -- -- {ℓ}
-- -- -- {_≤_ : ∀ {n} → ▸ n → ▸ n → Set ℓ}
-- -- -- ⦃ _ : Associativity _◅_ _◃_ _≤_ ⦄
-- -- -- → ∀ {n} {x : ▸ n}
-- -- -- → Preservativity _►_ (λ ⋆ → _◅_ ⋆) _►_ _◃_ (flip _≤_) (_◃ x) id
-- -- -- Preservativity.preservativity (Preservativity⋆ {_◅_ = _◅_} {_◃_ = _◃_} {_≤_ = _≤_} ⦃ ′associativity ⦄ {x = x}) f = associativity {_◅_ = _◅_} {_◃_ = _◃_} {_≤_ = _≤_} ⦃ {-′associativity-}_ ⦄ x f
-- -- -- preservation : ∀
-- -- -- {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁} {_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁} {𝔱₁} {▸₁ : 𝔄₁ → Set 𝔱₁}
-- -- -- (_◃₁_ : ∀ {m n} → m ►₁ n → m ⟨ ▸₁ ⟩→ n)
-- -- -- {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂} {_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂} {𝔱₂} {▸₂ : 𝔄₂ → Set 𝔱₂}
-- -- -- (_◃₂_ : ∀ {m n} → m ►₂ n → m ⟨ ▸₂ ⟩→ n)
-- -- -- {ℓ}
-- -- -- (_≤_ : ∀ {n} → ▸₂ n → ▸₂ n → Set ℓ)
-- -- -- {μ : 𝔄₁ → 𝔄₂}
-- -- -- {◽ : ∀ {n} → ▸₁ n → ▸₂ (μ n)}
-- -- -- {□ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n}
-- -- -- ⦃ _ : Preservativity _►₁_ _◃₁_ _►₂_ _◃₂_ _≤_ ◽ □ ⦄
-- -- -- {m n} (f : ▸₁ m) (g : m ►₁ n) → ◽ (g ◃₁ f) ≤ (□ g ◃₂ ◽ f)
-- -- -- preservation _◃₁_ _◃₂_ _≤_ f g = preservativity {_◃₁_ = _◃₁_} {_◃₂_ = _◃₂_} {_≤_ = _≤_} f g
| {
"alphanum_fraction": 0.3566714491,
"avg_line_length": 39.1573033708,
"ext": "agda",
"hexsha": "cb9c1d567807cc2e3375051883aeec957dc7e49f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Property/Preservativity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Property/Preservativity.agda",
"max_line_length": 203,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Property/Preservativity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1967,
"size": 3485
} |
module Relation.Equality.Extensionality where
open import Relation.Equality
open import Data.Inductive.Higher.Interval
open import Relation.Path.Operation
funext : ∀ {a b}{A : Set a}{B : A → Set b}{f g : (x : A) → B x} → (∀ x → f x ≡ g x) → f ≡ g
funext {A = A}{B = B} {f = f}{g = g} p = ap {f = h} path-seg
where
h : I → (x : A) → B x
h i x = interval-rec (f x) (g x) (p x) i
| {
"alphanum_fraction": 0.5784061697,
"avg_line_length": 32.4166666667,
"ext": "agda",
"hexsha": "a6baa8c0e230ff3b35d6cced617afb09aba61620",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Relation/Equality/Extensionality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Relation/Equality/Extensionality.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Relation/Equality/Extensionality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 150,
"size": 389
} |
module Issue205 where
data ⊥ : Set where
data D : Set₁ where
d : (Set → Set) → D
_*_ : D → Set → Set
d F * A = F A
foo : (F : D) → F * ⊥
foo (d _) = ⊥
| {
"alphanum_fraction": 0.4968152866,
"avg_line_length": 12.0769230769,
"ext": "agda",
"hexsha": "8716d1d0bb590c6ac95b086fe1b82fcfba49f1aa",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue205.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue205.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue205.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 68,
"size": 157
} |
postulate
A : Set
P : ..(_ : A) → Set
f : {x : A} → P x
g : ..(x : A) → P x
g x = f
| {
"alphanum_fraction": 0.347826087,
"avg_line_length": 10.2222222222,
"ext": "agda",
"hexsha": "b0dc7c87e463ab9e97bd9f870ec045a5b85b8acc",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue875.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue875.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue875.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 49,
"size": 92
} |
{-# OPTIONS --without-K --safe #-}
open import Level
open import Categories.Category
module Categories.Category.Construction.Path {o ℓ e : Level} (C : Category o ℓ e) where
open import Function using (flip)
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.Construct.Closure.Transitive
open Category C
-- Defining the Path Category
∘-tc : {A B : Obj} → A [ _⇒_ ]⁺ B → A ⇒ B
∘-tc [ f ] = f
∘-tc (_ ∼⁺⟨ f⁺ ⟩ f⁺′) = ∘-tc f⁺′ ∘ ∘-tc f⁺
infix 4 _≈⁺_
_≈⁺_ : {A B : Obj} → (i j : A [ _⇒_ ]⁺ B) → Set e
f⁺ ≈⁺ g⁺ = ∘-tc f⁺ ≈ ∘-tc g⁺
Path : Category o (o ⊔ ℓ) e
Path = record
{ Obj = Obj
; _⇒_ = λ A B → A [ _⇒_ ]⁺ B
; _≈_ = _≈⁺_
; id = [ id ]
; _∘_ = flip (_ ∼⁺⟨_⟩_)
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≈ = ∘-resp-≈
}
where open HomReasoning
| {
"alphanum_fraction": 0.5333998006,
"avg_line_length": 23.3255813953,
"ext": "agda",
"hexsha": "150080d6e6aa3985454ebd9b0ac6808d9a73ad62",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/Path.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/Path.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/Path.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 424,
"size": 1003
} |
{-# OPTIONS --cubical #-}
module PathWithBoundary where
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Nat
pred : Nat → Nat
pred (suc n) = n
pred 0 = 0
-- if the with abstraction correcly propagates the boundary the second
-- clause will not typecheck.
false : ∀ n {m} → (pred n + m) ≡ m
false n {m} i with pred n
... | zero = m
... | suc q = m
| {
"alphanum_fraction": 0.6585365854,
"avg_line_length": 17.5714285714,
"ext": "agda",
"hexsha": "277565a314495d3c2444126209921d193346568d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/PathWithBoundary.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/PathWithBoundary.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/PathWithBoundary.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 119,
"size": 369
} |
module Typing where
open import Data.Fin hiding (_≤_)
open import Data.List hiding (drop)
open import Data.List.All
open import Data.Maybe
open import Data.Nat
open import Data.Nat.Properties
open import Data.Product
open import Relation.Binary.PropositionalEquality
-- linearity indicator
data LU : Set where
LL UU : LU
data Dir : Set where
SND RCV : Dir
-- coinductive view on session types
-- following "Interactive Programming in Agda"
-- http://www.cse.chalmers.se/~abela/ooAgda.pdf
mutual
data Type : Set where
TUnit TInt : Type
TPair : Type → Type → Type
TChan : STypeF SType → Type
TFun : LU → Type → Type → Type
data STypeF (S : Set) : Set where
transmit : (d : Dir) (t : Type) (s : S) → STypeF S
choice : (d : Dir) (s1 : S) (s2 : S) → STypeF S
choiceN : (d : Dir) (m : ℕ) (alt : Fin m → S) → STypeF S
end : (d : Dir) → STypeF S
record SType : Set where
coinductive
constructor delay
field force : STypeF SType
open SType
pattern send t s = transmit SND t s
pattern recv t s = transmit RCV t s
pattern sintern s1 s2 = choice SND s1 s2
pattern sextern s1 s2 = choice RCV s1 s2
pattern sintN m a = choiceN SND m a
pattern sextN m a = choiceN RCV m a
pattern send! = end SND
pattern send? = end RCV
-- session type equivalence
data EquivF (R : SType → SType → Set) : STypeF SType → STypeF SType → Set where
eq-send : ∀ {s1 s1'} → (t : Type) → R s1 s1' → EquivF R (send t s1) (send t s1')
eq-recv : ∀ {s1 s1'} → (t : Type) → R s1 s1' → EquivF R (recv t s1) (recv t s1')
eq-sintern : ∀ {s1 s1' s2 s2'} → R s1 s1' → R s2 s2' → EquivF R (sintern s1 s2) (sintern s1' s2')
eq-sextern : ∀ {s1 s1' s2 s2'} → R s1 s1' → R s2 s2' → EquivF R (sextern s1 s2) (sextern s1' s2')
eq-sintN : ∀ {m alt alt'} → ((i : Fin m) → R (alt i) (alt' i)) → EquivF R (sintN m alt) (sintN m alt')
eq-sextN : ∀ {m alt alt'} → ((i : Fin m) → R (alt i) (alt' i)) → EquivF R (sextN m alt) (sextN m alt')
eq-send! : EquivF R send! send!
eq-send? : EquivF R send? send?
record Equiv (s1 : SType) (s2 : SType) : Set where
coinductive
field force : EquivF Equiv (force s1) (force s2)
open Equiv
_≈_ = Equiv
_≈'_ = EquivF Equiv
-- equivalence is reflexive
equivF-refl : ∀ s → s ≈' s
equiv-refl : ∀ s → s ≈ s
force (equiv-refl s) = equivF-refl (force s)
equivF-refl (send t s) = eq-send t (equiv-refl s)
equivF-refl (recv t s) = eq-recv t (equiv-refl s)
equivF-refl (sintern s1 s2) = eq-sintern (equiv-refl s1) (equiv-refl s2)
equivF-refl (sextern s1 s2) = eq-sextern (equiv-refl s1) (equiv-refl s2)
equivF-refl (sintN m alt) = eq-sintN λ i → equiv-refl (alt i)
equivF-refl (sextN m alt) = eq-sextN λ i → equiv-refl (alt i)
equivF-refl send! = eq-send!
equivF-refl send? = eq-send?
-- equivalence is symmetric
eqF-sym : ∀ {s1 s2} → s1 ≈' s2 → s2 ≈' s1
eq-sym : ∀ {s1 s2} → s1 ≈ s2 → s2 ≈ s1
eqF-sym (eq-send t x) = eq-send t (eq-sym x)
eqF-sym (eq-recv t x) = eq-recv t (eq-sym x)
eqF-sym (eq-sintern x x₁) = eq-sintern (eq-sym x) (eq-sym x₁)
eqF-sym (eq-sextern x x₁) = eq-sextern (eq-sym x) (eq-sym x₁)
eqF-sym (eq-sintN x) = eq-sintN λ i → eq-sym (x i)
eqF-sym (eq-sextN x) = eq-sextN λ i → eq-sym (x i)
eqF-sym eq-send! = eq-send!
eqF-sym eq-send? = eq-send?
force (eq-sym s1~s2) = eqF-sym (force s1~s2)
-- equivalence is transitive
equivF-trans : ∀ {s1 s2 s3} → EquivF Equiv s1 s2 → EquivF Equiv s2 s3 → EquivF Equiv s1 s3
equiv-trans : ∀ {s1 s2 s3} → Equiv s1 s2 → Equiv s2 s3 → Equiv s1 s3
force (equiv-trans s1~s2 s2~s3) = equivF-trans (force s1~s2) (force s2~s3)
equivF-trans (eq-send t x) (eq-send .t x₁) = eq-send t (equiv-trans x x₁)
equivF-trans (eq-recv t x) (eq-recv .t x₁) = eq-recv t (equiv-trans x x₁)
equivF-trans (eq-sintern x x₁) (eq-sintern x₂ x₃) = eq-sintern (equiv-trans x x₂) (equiv-trans x₁ x₃)
equivF-trans (eq-sextern x x₁) (eq-sextern x₂ x₃) = eq-sextern (equiv-trans x x₂) (equiv-trans x₁ x₃)
equivF-trans (eq-sintN x) (eq-sintN x₁) = eq-sintN λ i → equiv-trans (x i) (x₁ i)
equivF-trans (eq-sextN x) (eq-sextN x₁) = eq-sextN λ i → equiv-trans (x i) (x₁ i)
equivF-trans eq-send! eq-send! = eq-send!
equivF-trans eq-send? eq-send? = eq-send?
-- dual
dual-dir : Dir → Dir
dual-dir SND = RCV
dual-dir RCV = SND
dual : SType → SType
dualF : STypeF SType → STypeF SType
force (dual s) = dualF (force s)
dualF (transmit d t s) = transmit (dual-dir d) t (dual s)
dualF (choice d s1 s2) = choice (dual-dir d) (dual s1) (dual s2)
dualF (choiceN d m alt) = choiceN (dual-dir d) m λ i → dual (alt i)
dualF (end d) = end (dual-dir d)
-- properties
dual-involution : (s : SType) → s ≈ dual (dual s)
dual-involutionF : (s : STypeF SType) → s ≈' dualF (dualF s)
force (dual-involution s) = dual-involutionF (force s)
dual-involutionF (send t s) = eq-send t (dual-involution s)
dual-involutionF (recv t s) = eq-recv t (dual-involution s)
dual-involutionF (sintern s1 s2) = eq-sintern (dual-involution s1) (dual-involution s2)
dual-involutionF (sextern s1 s2) = eq-sextern (dual-involution s1) (dual-involution s2)
dual-involutionF (sintN m alt) = eq-sintN λ i → dual-involution (alt i)
dual-involutionF (sextN m alt) = eq-sextN λ i → dual-involution (alt i)
dual-involutionF send! = eq-send!
dual-involutionF send? = eq-send?
mutual
-- subtyping
data SubT : Type → Type → Set where
sub-unit : SubT TUnit TUnit
sub-int : SubT TInt TInt
sub-pair : ∀ {t₁ t₂ t₁' t₂'} → SubT t₁ t₁' → SubT t₂ t₂' → SubT (TPair t₁ t₂) (TPair t₁' t₂')
sub-fun : ∀ {t₁ t₂ t₁' t₂' lu} → SubT t₁' t₁ → SubT t₂ t₂' → SubT (TFun lu t₁ t₂) (TFun lu t₁' t₂')
sub-chan : ∀ {s s'} → SubF Sub s s' → SubT (TChan s) (TChan s')
-- session type subtyping
data SubF (R : SType → SType → Set) : STypeF SType → STypeF SType → Set where
sub-send : ∀ {s1 s1'} → (t t' : Type) → (t'<=t : SubT t' t) → (s1<=s1' : R s1 s1') → SubF R (send t s1) (send t' s1')
sub-recv : ∀ {s1 s1'} → (t t' : Type) → (t<=t' : SubT t t') → (s1<=s1' : R s1 s1') → SubF R (recv t s1) (recv t' s1')
sub-sintern : ∀ {s1 s1' s2 s2'} → (s1<=s1' : R s1 s1') → (s2<=s2' : R s2 s2') → SubF R (sintern s1 s2) (sintern s1' s2')
sub-sextern : ∀ {s1 s1' s2 s2'} → (s1<=s1' : R s1 s1') → (s2<=s2' : R s2 s2') → SubF R (sextern s1 s2) (sextern s1' s2')
sub-sintN : ∀ {m m' alt alt'} → (m'≤m : m' ≤ m) → ((i : Fin m') → R (alt (inject≤ i m'≤m)) (alt' i)) → SubF R (sintN m alt) (sintN m' alt')
sub-sextN : ∀ {m m' alt alt'} → (m≤m' : m ≤ m') → ((i : Fin m) → R (alt i) (alt' (inject≤ i m≤m'))) → SubF R (sextN m alt) (sextN m' alt')
sub-send! : SubF R send! send!
sub-send? : SubF R send? send?
record Sub (s1 : SType) (s2 : SType) : Set where
coinductive
field force : SubF Sub (force s1) (force s2)
open Sub
_≲_ = Sub
_≲'_ = SubF Sub
inject-refl : ∀ {m} → (i : Fin m) → inject≤ i ≤-refl ≡ i
inject-refl zero = refl
inject-refl (suc i) = cong suc (inject-refl i)
inject-trans : ∀ {m m' m''} → (m'≤m : m' ≤ m) → (m''≤m' : m'' ≤ m') → (i : Fin m'')
→ (inject≤ (inject≤ i m''≤m') m'≤m) ≡ (inject≤ i (≤-trans m''≤m' m'≤m))
inject-trans z≤n z≤n ()
inject-trans (s≤s m'≤m) z≤n ()
inject-trans (s≤s m'≤m) (s≤s m''≤m') zero = refl
inject-trans (s≤s m'≤m) (s≤s m''≤m') (suc i) = cong suc (inject-trans m'≤m m''≤m' i)
-- subtyping is reflexive
subt-refl : ∀ t → SubT t t
subF-refl : ∀ s → s ≲' s
sub-refl : ∀ s → s ≲ s
force (sub-refl s) = subF-refl (force s)
subF-refl (send t s) = sub-send t t (subt-refl t) (sub-refl s)
subF-refl (recv t s) = sub-recv t t (subt-refl t) (sub-refl s)
subF-refl (sintern s1 s2) = sub-sintern (sub-refl s1) (sub-refl s2)
subF-refl (sextern s1 s2) = sub-sextern (sub-refl s1) (sub-refl s2)
subF-refl (sintN m alt) = sub-sintN ≤-refl auxInt
where
auxInt : (i : Fin m) → Sub (alt (inject≤ i ≤-refl)) (alt i)
auxInt i rewrite inject-refl i = sub-refl (alt i)
subF-refl (sextN m alt) = sub-sextN ≤-refl auxExt
where
auxExt : (i : Fin m) → Sub (alt i) (alt (inject≤ i ≤-refl))
auxExt i rewrite inject-refl i = sub-refl (alt i)
subF-refl send! = sub-send!
subF-refl send? = sub-send?
subt-refl TUnit = sub-unit
subt-refl TInt = sub-int
subt-refl (TPair t t₁) = sub-pair (subt-refl t) (subt-refl t₁)
subt-refl (TChan s) = sub-chan (subF-refl s)
subt-refl (TFun x t t₁) = sub-fun (subt-refl t) (subt-refl t₁)
-- subtyping is transitive
subt-trans : ∀ {t1 t2 t3} → SubT t1 t2 → SubT t2 t3 → SubT t1 t3
sub-trans : ∀ {s1 s2 s3} → s1 ≲ s2 → s2 ≲ s3 → s1 ≲ s3
subF-trans : ∀ {s1 s2 s3} → s1 ≲' s2 → s2 ≲' s3 → s1 ≲' s3
subt-trans sub-unit sub-unit = sub-unit
subt-trans sub-int sub-int = sub-int
subt-trans (sub-pair t1<:t2 t1<:t3) (sub-pair t2<:t3 t2<:t4) = sub-pair (subt-trans t1<:t2 t2<:t3) (subt-trans t1<:t3 t2<:t4)
subt-trans (sub-fun t1<:t2 t1<:t3) (sub-fun t2<:t3 t2<:t4) = sub-fun (subt-trans t2<:t3 t1<:t2) (subt-trans t1<:t3 t2<:t4)
subt-trans (sub-chan s1<:s2) (sub-chan s2<:s3) = sub-chan (subF-trans s1<:s2 s2<:s3)
force (sub-trans s1<:s2 s2<:s3) = subF-trans (force s1<:s2) (force s2<:s3)
subF-trans (sub-send t t' x x₁) (sub-send .t' t'' x₂ x₃) = sub-send t t'' (subt-trans x₂ x) (sub-trans x₁ x₃)
subF-trans (sub-recv t t' x x₁) (sub-recv .t' t'' x₂ x₃) = sub-recv t t'' (subt-trans x x₂) (sub-trans x₁ x₃)
subF-trans (sub-sintern x x₁) (sub-sintern x₂ x₃) = sub-sintern (sub-trans x x₂) (sub-trans x₁ x₃)
subF-trans (sub-sextern x x₁) (sub-sextern x₂ x₃) = sub-sextern (sub-trans x x₂) (sub-trans x₁ x₃)
subF-trans {sintN m alt}{sintN m' alt'}{sintN m'' alt''} (sub-sintN m'≤m palt) (sub-sintN m''≤m' palt') =
sub-sintN (≤-trans m''≤m' m'≤m) λ i → sub-trans (auxInt i) (palt' i)
where
auxInt : (i : Fin m'') → Sub (alt (inject≤ i (≤-trans m''≤m' m'≤m))) (alt' (inject≤ i m''≤m'))
auxInt i with palt (inject≤ i m''≤m')
... | r rewrite (inject-trans m'≤m m''≤m' i) = r
subF-trans {sextN m alt}{sextN m' alt'}{sextN m'' alt''} (sub-sextN m≤m' palt) (sub-sextN m'≤m'' palt') =
sub-sextN (≤-trans m≤m' m'≤m'') λ i → sub-trans (palt i) (auxExt i)
where
auxExt : (i : Fin m) → Sub (alt' (inject≤ i m≤m')) (alt'' (inject≤ i (≤-trans m≤m' m'≤m'')))
auxExt i with palt' (inject≤ i m≤m')
... | r rewrite (inject-trans m'≤m'' m≤m' i) = r
subF-trans sub-send! sub-send! = sub-send!
subF-trans sub-send? sub-send? = sub-send?
-- duality and subtyping
dual-sub : ∀ {s1 s2} → s1 ≲ s2 → dual s2 ≲ dual s1
dual-subF : ∀ {s1 s2} → s1 ≲' s2 → dualF s2 ≲' dualF s1
force (dual-sub s1<=s2) = dual-subF (force s1<=s2)
dual-subF (sub-send t t' t'<=t s1<=s1') = sub-recv t' t t'<=t (dual-sub s1<=s1')
dual-subF (sub-recv t t' t<=t' s1<=s1') = sub-send t' t t<=t' (dual-sub s1<=s1')
dual-subF (sub-sintern s1<=s1' s2<=s2') = sub-sextern (dual-sub s1<=s1') (dual-sub s2<=s2')
dual-subF (sub-sextern s1<=s1' s2<=s2') = sub-sintern (dual-sub s1<=s1') (dual-sub s2<=s2')
dual-subF (sub-sintN m'≤m x) = sub-sextN m'≤m λ i → dual-sub (x i)
dual-subF (sub-sextN m≤m' x) = sub-sintN m≤m' λ i → dual-sub (x i)
dual-subF sub-send! = sub-send?
dual-subF sub-send? = sub-send!
-- equivalence and subtyping
eq-implies-sub : ∀ {s1 s2} → s1 ≈ s2 → s1 ≲ s2
eqF-implies-subF : ∀ {s1 s2} → s1 ≈' s2 → s1 ≲' s2
force (eq-implies-sub s1~s2) = eqF-implies-subF (force s1~s2)
eqF-implies-subF (eq-send t x) = sub-send t t (subt-refl t) (eq-implies-sub x)
eqF-implies-subF (eq-recv t x) = sub-recv t t (subt-refl t) (eq-implies-sub x)
eqF-implies-subF (eq-sintern x x₁) = sub-sintern (eq-implies-sub x) (eq-implies-sub x₁)
eqF-implies-subF (eq-sextern x x₁) = sub-sextern (eq-implies-sub x) (eq-implies-sub x₁)
eqF-implies-subF {sintN m alt} {sintN .m alt'} (eq-sintN x) = sub-sintN ≤-refl auxInt
where
auxInt : (i : Fin m) → Sub (alt (inject≤ i ≤-refl)) (alt' i)
auxInt i rewrite inject-refl i = eq-implies-sub (x i)
eqF-implies-subF {sextN m alt} {sextN .m alt'} (eq-sextN x) = sub-sextN ≤-refl auxExt
where
auxExt : (i : Fin m) → Sub (alt i) (alt' (inject≤ i ≤-refl))
auxExt i rewrite inject-refl i = eq-implies-sub (x i)
eqF-implies-subF eq-send! = sub-send!
eqF-implies-subF eq-send? = sub-send?
-- unrestricted
data Unr : Type → Set where
UUnit : Unr TUnit
UInt : Unr TInt
UPair : ∀ {t₁ t₂} → Unr t₁ → Unr t₂ → Unr (TPair t₁ t₂)
UFun : ∀ {t₁ t₂} → Unr (TFun UU t₁ t₂)
classify-type : (t : Type) → Maybe (Unr t)
classify-type TUnit = just UUnit
classify-type TInt = just UInt
classify-type (TPair t₁ t₂) with classify-type t₁ | classify-type t₂
classify-type (TPair t₁ t₂) | just x | just x₁ = just (UPair x x₁)
classify-type (TPair t₁ t₂) | just x | nothing = nothing
classify-type (TPair t₁ t₂) | nothing | just x = nothing
classify-type (TPair t₁ t₂) | nothing | nothing = nothing
classify-type (TChan x) = nothing
classify-type (TFun LL t₁ t₂) = nothing
classify-type (TFun UU t₁ t₂) = just UFun
TCtx = List Type
-- context splitting, respecting linearity
data Split : TCtx → TCtx → TCtx → Set where
[] : Split [] [] []
dupl : ∀ {t Φ Φ₁ Φ₂} → Unr t → Split Φ Φ₁ Φ₂ → Split (t ∷ Φ) (t ∷ Φ₁) (t ∷ Φ₂)
drop : ∀ {t Φ Φ₁ Φ₂} → Unr t → Split Φ Φ₁ Φ₂ → Split (t ∷ Φ) Φ₁ Φ₂
left : ∀ {t Φ Φ₁ Φ₂} → Split Φ Φ₁ Φ₂ → Split (t ∷ Φ) (t ∷ Φ₁) Φ₂
rght : ∀ {t Φ Φ₁ Φ₂} → Split Φ Φ₁ Φ₂ → Split (t ∷ Φ) Φ₁ (t ∷ Φ₂)
-- split is symmetric
split-sym : ∀ {φ φ₁ φ₂} → Split φ φ₁ φ₂ → Split φ φ₂ φ₁
split-sym [] = []
split-sym (dupl x sp) = dupl x (split-sym sp)
split-sym (drop un-t sp) = drop un-t (split-sym sp)
split-sym (left sp) = rght (split-sym sp)
split-sym (rght sp) = left (split-sym sp)
split-unr : ∀ {φ φ₁ φ₂} → (sp : Split φ φ₁ φ₂) → All Unr φ₁ → All Unr φ₂ → All Unr φ
split-unr [] [] [] = []
split-unr (dupl x sp) (px ∷ unr1) (px₁ ∷ unr2) = px ∷ split-unr sp unr1 unr2
split-unr (drop x sp) unr1 unr2 = x ∷ split-unr sp unr1 unr2
split-unr (left sp) (px ∷ unr1) unr2 = px ∷ split-unr sp unr1 unr2
split-unr (rght sp) unr1 (px ∷ unr2) = px ∷ split-unr sp unr1 unr2
split-all-left : (φ : TCtx) → Split φ φ []
split-all-left [] = []
split-all-left (x ∷ φ) = left (split-all-left φ)
split-all-right : (φ : TCtx) → Split φ [] φ
split-all-right [] = []
split-all-right (x ∷ φ) = rght (split-all-right φ)
-- split the unrestricted part from a typing context
split-refl-left : (φ : TCtx) → ∃ λ φ' → All Unr φ' × Split φ φ φ'
split-refl-left [] = [] , [] , []
split-refl-left (t ∷ φ) with split-refl-left φ | classify-type t
split-refl-left (t ∷ φ) | φ' , unr-φ' , sp' | nothing = φ' , unr-φ' , left sp'
split-refl-left (t ∷ φ) | φ' , unr-φ' , sp' | just y = t ∷ φ' , y ∷ unr-φ' , dupl y sp'
split-all-unr : ∀ {φ} → All Unr φ → Split φ φ φ
split-all-unr [] = []
split-all-unr (px ∷ un-φ) = dupl px (split-all-unr un-φ)
split-from-disjoint : (φ₁ φ₂ : TCtx) → ∃ λ φ → Split φ φ₁ φ₂
split-from-disjoint [] φ₂ = φ₂ , split-all-right φ₂
split-from-disjoint (t ∷ φ₁) φ₂ with split-from-disjoint φ₁ φ₂
... | φ' , sp = t ∷ φ' , left sp
split-unr-right : ∀ {φ φ₁ φ₂ φ₃ φ₄}
→ Split φ φ₁ φ₂ → Split φ₁ φ₃ φ₄ → All Unr φ₂ → Split φ φ₃ φ₄
split-unr-right [] [] unr1 = []
split-unr-right (dupl x sp012) (dupl x₁ sp134) (px ∷ unr1) = dupl x₁ (split-unr-right sp012 sp134 unr1)
split-unr-right (dupl x sp012) (drop x₁ sp134) (px ∷ unr1) = drop px (split-unr-right sp012 sp134 unr1)
split-unr-right (dupl x sp012) (left sp134) (px ∷ unr1) = left (split-unr-right sp012 sp134 unr1)
split-unr-right (dupl x sp012) (rght sp134) (px ∷ unr1) = rght (split-unr-right sp012 sp134 unr1)
split-unr-right (drop x sp012) [] unr1 = drop x (split-unr-right sp012 [] unr1)
split-unr-right (drop x sp012) (dupl x₁ sp134) unr1 = drop x (split-unr-right sp012 (dupl x₁ sp134) unr1)
split-unr-right (drop x sp012) (drop x₁ sp134) unr1 = drop x (split-unr-right sp012 (drop x₁ sp134) unr1)
split-unr-right (drop x sp012) (left sp134) unr1 = drop x (split-unr-right sp012 (left sp134) unr1)
split-unr-right (drop x sp012) (rght sp134) unr1 = drop x (split-unr-right sp012 (rght sp134) unr1)
split-unr-right (left sp012) (dupl x sp134) unr1 = dupl x (split-unr-right sp012 sp134 unr1)
split-unr-right (left sp012) (drop x sp134) unr1 = drop x (split-unr-right sp012 sp134 unr1)
split-unr-right (left sp012) (left sp134) unr1 = left (split-unr-right sp012 sp134 unr1)
split-unr-right (left sp012) (rght sp134) unr1 = rght (split-unr-right sp012 sp134 unr1)
split-unr-right (rght sp012) [] (px ∷ unr1) = drop px (split-unr-right sp012 [] unr1)
split-unr-right (rght sp012) (dupl x sp134) (px ∷ unr1) = drop px (split-unr-right sp012 (dupl x sp134) unr1)
split-unr-right (rght sp012) (drop x sp134) (px ∷ unr1) = drop px (split-unr-right sp012 (drop x sp134) unr1)
split-unr-right (rght sp012) (left sp134) (px ∷ unr1) = drop px (split-unr-right sp012 (left sp134) unr1)
split-unr-right (rght sp012) (rght sp134) (px ∷ unr1) = drop px (split-unr-right sp012 (rght sp134) unr1)
split-unr-left : ∀ {φ φ₁ φ₂ φ₃ φ₄}
→ Split φ φ₁ φ₂ → Split φ₂ φ₃ φ₄ → All Unr φ₁ → Split φ φ₃ φ₄
split-unr-left [] [] [] = []
split-unr-left (dupl x sp012) (dupl x₁ sp234) (px ∷ unr1) = dupl px (split-unr-left sp012 sp234 unr1)
split-unr-left (dupl x sp012) (drop x₁ sp234) (px ∷ unr1) = drop px (split-unr-left sp012 sp234 unr1)
split-unr-left (dupl x sp012) (left sp234) (px ∷ unr1) = left (split-unr-left sp012 sp234 unr1)
split-unr-left (dupl x sp012) (rght sp234) (px ∷ unr1) = rght (split-unr-left sp012 sp234 unr1)
split-unr-left (drop x₁ sp012) [] unr1 = drop x₁ (split-unr-left sp012 [] unr1)
split-unr-left (drop x₁ sp012) (dupl x₂ sp234) unr1 = drop x₁ (split-unr-left sp012 (dupl x₂ sp234) unr1)
split-unr-left (drop x₁ sp012) (drop x₂ sp234) unr1 = drop x₁ (split-unr-left sp012 (drop x₂ sp234) unr1)
split-unr-left (drop x₁ sp012) (left sp234) unr1 = drop x₁ (split-unr-left sp012 (left sp234) unr1)
split-unr-left (drop x₁ sp012) (rght sp234) unr1 = drop x₁ (split-unr-left sp012 (rght sp234) unr1)
split-unr-left (left sp012) [] (px ∷ unr1) = drop px (split-unr-left sp012 [] unr1)
split-unr-left (left sp012) (dupl x sp234) (px ∷ unr1) = drop px (split-unr-left sp012 (dupl x sp234) unr1)
split-unr-left (left sp012) (drop x sp234) (px ∷ unr1) = drop px (split-unr-left sp012 (drop x sp234) unr1)
split-unr-left (left sp012) (left sp234) (px ∷ unr1) = drop px (split-unr-left sp012 (left sp234) unr1)
split-unr-left (left sp012) (rght sp234) (px ∷ unr1) = drop px (split-unr-left sp012 (rght sp234) unr1)
split-unr-left (rght sp012) (dupl x₁ sp234) unr1 = dupl x₁ (split-unr-left sp012 sp234 unr1)
split-unr-left (rght sp012) (drop x₁ sp234) unr1 = drop x₁ (split-unr-left sp012 sp234 unr1)
split-unr-left (rght sp012) (left sp234) unr1 = left (split-unr-left sp012 sp234 unr1)
split-unr-left (rght sp012) (rght sp234) unr1 = rght (split-unr-left sp012 sp234 unr1)
-- reorganize splits
split-rotate : ∀ {φ φ₁ φ₂ φ₁₁ φ₁₂}
→ Split φ φ₁ φ₂ → Split φ₁ φ₁₁ φ₁₂ → ∃ λ φ' → Split φ φ₁₁ φ' × Split φ' φ₁₂ φ₂
split-rotate [] [] = [] , [] , []
split-rotate (drop x sp12) [] with split-rotate sp12 []
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , rght sp-φ' , drop x φ'-sp
split-rotate (dupl x sp12) (dupl x₁ sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , dupl x₁ sp-φ' , dupl x₁ φ'-sp
split-rotate (dupl x sp12) (drop x₁ sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , rght sp-φ' , rght φ'-sp
split-rotate (dupl x sp12) (left sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , dupl x sp-φ' , rght φ'-sp
split-rotate (dupl x sp12) (rght sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , rght sp-φ' , dupl x φ'-sp
split-rotate (drop px sp12) sp1112 with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , rght sp-φ' , drop px φ'-sp
split-rotate (left sp12) (dupl x₁ sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , dupl x₁ sp-φ' , left φ'-sp
split-rotate (left sp12) (left sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = φ' , left sp-φ' , φ'-sp
split-rotate (left sp12) (rght sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , rght sp-φ' , left φ'-sp
split-rotate (left sp12) (drop px sp1112) with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = φ' , drop px sp-φ' , φ'-sp
split-rotate (rght sp12) sp1112 with split-rotate sp12 sp1112
... | φ' , sp-φ' , φ'-sp = _ ∷ φ' , rght sp-φ' , rght φ'-sp
-- extract from type context where all other entries are unrestricted
data _∈_ (x : Type) : List Type → Set where
here : ∀ { xs } → All Unr xs → x ∈ (x ∷ xs)
there : ∀ { x₀ xs } → Unr x₀ → x ∈ xs → x ∈ (x₀ ∷ xs)
-- unrestricted weakening
unr-weaken-var : ∀ {Φ Φ₁ Φ₂ t} → Split Φ Φ₁ Φ₂ → All Unr Φ₂ → t ∈ Φ₁ → t ∈ Φ
unr-weaken-var [] un-Φ₂ ()
unr-weaken-var (dupl x₁ sp) (_ ∷ un-Φ₂) (here x) = here (split-unr sp x un-Φ₂)
unr-weaken-var (dupl x₁ sp) un-Φ₂ (there x x₂) = unr-weaken-var (rght sp) un-Φ₂ x₂
unr-weaken-var (drop un-t sp) un-Φ₂ x = there un-t (unr-weaken-var sp un-Φ₂ x)
unr-weaken-var {t = _} (left sp) un-Φ₂ (here x) = here (split-unr sp x un-Φ₂)
unr-weaken-var {t = t} (left sp) un-Φ₂ (there x x₁) = there x (unr-weaken-var sp un-Φ₂ x₁)
unr-weaken-var {t = t} (rght sp) (unr-t ∷ un-Φ₂) (here x) = there unr-t (unr-weaken-var sp un-Φ₂ (here x))
unr-weaken-var {t = t} (rght sp) (unr-t ∷ un-Φ₂) (there x x₁) = there unr-t (unr-weaken-var sp un-Φ₂ (there x x₁))
-- left and right branching
data Selector : Set where
Left Right : Selector
selection : ∀ {A : Set} → Selector → A → A → A
selection Left x y = x
selection Right x y = y
| {
"alphanum_fraction": 0.6271927762,
"avg_line_length": 46.4257641921,
"ext": "agda",
"hexsha": "495a2cf88262e9ebbc1ba12161fa01a5e9219400",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "peterthiemann/definitional-session",
"max_forks_repo_path": "src/Typing.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "peterthiemann/definitional-session",
"max_issues_repo_path": "src/Typing.agda",
"max_line_length": 143,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "peterthiemann/definitional-session",
"max_stars_repo_path": "src/Typing.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z",
"num_tokens": 9031,
"size": 21263
} |
open import Level using () renaming (zero to ℓ₀)
open import Relation.Binary using (DecSetoid)
module CheckInsert (A : DecSetoid ℓ₀ ℓ₀) where
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
open import Data.Fin.Properties using (_≟_)
open import Data.Maybe using (Maybe ; nothing ; just) renaming (setoid to MaybeSetoid ; Eq to MaybeEq)
open import Data.Vec using (Vec) renaming (_∷_ to _∷V_)
open import Data.Vec.Equality using () renaming (module Equality to VecEq)
open import Relation.Nullary using (Dec ; yes ; no ; ¬_)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary using (Setoid ; module DecSetoid)
open import Relation.Binary.Core using (refl ; _≡_ ; _≢_)
import Relation.Binary.EqReasoning as EqR
open import Relation.Binary.PropositionalEquality using (cong ; sym ; inspect ; [_] ; trans)
open import FinMap
private
open module A = DecSetoid A using (Carrier ; _≈_) renaming (_≟_ to deq)
checkInsert : {n : ℕ} → Fin n → Carrier → FinMapMaybe n Carrier → Maybe (FinMapMaybe n Carrier)
checkInsert i b m with lookupM i m
... | nothing = just (insert i b m)
... | just c with deq b c
... | yes b≈c = just m
... | no b≉c = nothing
data InsertionResult {n : ℕ} (i : Fin n) (x : Carrier) (h : FinMapMaybe n Carrier) : Maybe (FinMapMaybe n Carrier) → Set where
same : (x' : Carrier) → x ≈ x' → lookupM i h ≡ just x' → InsertionResult i x h (just h)
new : lookupM i h ≡ nothing → InsertionResult i x h (just (insert i x h))
wrong : (x' : Carrier) → ¬ (x ≈ x') → lookupM i h ≡ just x' → InsertionResult i x h nothing
insertionresult : {n : ℕ} → (i : Fin n) → (x : Carrier) → (h : FinMapMaybe n Carrier) → InsertionResult i x h (checkInsert i x h)
insertionresult i x h with lookupM i h | inspect (lookupM i) h
insertionresult i x h | just x' | _ with deq x x'
insertionresult i x h | just x' | [ il ] | yes x≈x' = same x' x≈x' il
insertionresult i x h | just x' | [ il ] | no x≉x' = wrong x' x≉x' il
insertionresult i x h | nothing | [ il ] = new il
lemma-checkInsert-same : {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → lookupM i m ≡ just x → checkInsert i x m ≡ just m
lemma-checkInsert-same i x m p with lookupM i m
lemma-checkInsert-same i x m refl | .(just x) with deq x x
lemma-checkInsert-same i x m refl | .(just x) | yes x≈x = refl
lemma-checkInsert-same i x m refl | .(just x) | no x≉x = contradiction A.refl x≉x
lemma-checkInsert-new : {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → lookupM i m ≡ nothing → checkInsert i x m ≡ just (insert i x m)
lemma-checkInsert-new i x m p with lookupM i m
lemma-checkInsert-new i x m refl | .nothing = refl
lemma-checkInsert-wrong : {n : ℕ} → (i : Fin n) → (x : Carrier) → (m : FinMapMaybe n Carrier) → (x' : Carrier) → ¬ (x ≈ x') → lookupM i m ≡ just x' → checkInsert i x m ≡ nothing
lemma-checkInsert-wrong i x m x' d p with lookupM i m
lemma-checkInsert-wrong i x m x' d refl | .(just x') with deq x x'
lemma-checkInsert-wrong i x m x' d refl | .(just x') | yes q = contradiction q d
lemma-checkInsert-wrong i x m x' d refl | .(just x') | no ¬q = refl
lemma-checkInsert-restrict : {n m : ℕ} → (f : Fin n → Carrier) → (i : Fin n) → (is : Vec (Fin n) m) → checkInsert i (f i) (restrict f is) ≡ just (restrict f (i ∷V is))
lemma-checkInsert-restrict f i is with checkInsert i (f i) (restrict f is) | insertionresult i (f i) (restrict f is)
lemma-checkInsert-restrict f i is | ._ | same x fi≈x p = cong just (lemma-insert-same _ i (trans p (cong just (sym (lemma-lookupM-restrict i f is p)))))
lemma-checkInsert-restrict f i is | ._ | new _ = refl
lemma-checkInsert-restrict f i is | ._ | wrong x fi≉x p = contradiction (Setoid.reflexive A.setoid (lemma-lookupM-restrict i f is p)) fi≉x
lemma-lookupM-checkInsert : {n : ℕ} → (i j : Fin n) → (h : FinMapMaybe n Carrier) → {x : Carrier} → lookupM i h ≡ just x → (y : Carrier) → {h' : FinMapMaybe n Carrier} → checkInsert j y h ≡ just h' → lookupM i h' ≡ just x
lemma-lookupM-checkInsert i j h pl y ph' with checkInsert j y h | insertionresult j y h
lemma-lookupM-checkInsert i j h pl y refl | ._ | same _ _ _ = pl
lemma-lookupM-checkInsert i j h pl y ph' | ._ | new _ with i ≟ j
lemma-lookupM-checkInsert i .i h pl y ph' | ._ | new pl' | yes refl = contradiction (trans (sym pl) pl') (λ ())
lemma-lookupM-checkInsert i j h {x} pl y refl | ._ | new _ | no i≢j = begin
lookupM i (insert j y h)
≡⟨ lemma-lookupM-insert-other i j y h i≢j ⟩
lookupM i h
≡⟨ pl ⟩
just x ∎
where open Relation.Binary.PropositionalEquality.≡-Reasoning
lemma-lookupM-checkInsert i j h pl y () | ._ | wrong _ _ _
lemma-lookupM-checkInsert-other : {n : ℕ} → (i j : Fin n) → i ≢ j → (x : Carrier) → (h : FinMapMaybe n Carrier) → {h' : FinMapMaybe n Carrier} → checkInsert j x h ≡ just h' → lookupM i h' ≡ lookupM i h
lemma-lookupM-checkInsert-other i j i≢j x h ph' with lookupM j h
lemma-lookupM-checkInsert-other i j i≢j x h ph' | just y with deq x y
lemma-lookupM-checkInsert-other i j i≢j x h refl | just y | yes x≈y = refl
lemma-lookupM-checkInsert-other i j i≢j x h () | just y | no x≉y
lemma-lookupM-checkInsert-other i j i≢j x h refl | nothing = lemma-lookupM-insert-other i j x h i≢j
| {
"alphanum_fraction": 0.6590263307,
"avg_line_length": 61.3837209302,
"ext": "agda",
"hexsha": "e0e35ec67dc447330fbf1d17928260a3f4e37ad9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jvoigtlaender/bidiragda",
"max_forks_repo_path": "CheckInsert.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jvoigtlaender/bidiragda",
"max_issues_repo_path": "CheckInsert.agda",
"max_line_length": 221,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jvoigtlaender/bidiragda",
"max_stars_repo_path": "CheckInsert.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1776,
"size": 5279
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of First
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.First.Properties where
open import Data.Empty
open import Data.Fin using (suc)
open import Data.List.Base as List using (List; []; _∷_)
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
open import Data.List.Relation.Unary.Any as Any using (here; there)
open import Data.List.Relation.Unary.First
import Data.Sum as Sum
open import Function
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; _≗_)
open import Relation.Unary
open import Relation.Nullary.Negation
------------------------------------------------------------------------
-- map
module _ {a b p q} {A : Set a} {B : Set b} {P : Pred B p} {Q : Pred B q} where
map⁺ : {f : A → B} → First (P ∘′ f) (Q ∘′ f) ⊆ First P Q ∘′ List.map f
map⁺ [ qfx ] = [ qfx ]
map⁺ (pfxs ∷ pqfxs) = pfxs ∷ map⁺ pqfxs
map⁻ : {f : A → B} → First P Q ∘′ List.map f ⊆ First (P ∘′ f) (Q ∘′ f)
map⁻ {f} {[]} ()
map⁻ {f} {x ∷ xs} [ qfx ] = [ qfx ]
map⁻ {f} {x ∷ xs} (pfx ∷ pqfxs) = pfx ∷ map⁻ pqfxs
------------------------------------------------------------------------
-- (++)
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
++⁺ : ∀ {xs ys} → All P xs → First P Q ys → First P Q (xs List.++ ys)
++⁺ [] pqys = pqys
++⁺ (px ∷ pxs) pqys = px ∷ ++⁺ pxs pqys
⁺++ : ∀ {xs} → First P Q xs → ∀ ys → First P Q (xs List.++ ys)
⁺++ [ qx ] ys = [ qx ]
⁺++ (px ∷ pqxs) ys = px ∷ ⁺++ pqxs ys
------------------------------------------------------------------------
-- Relationship to All
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
All⇒¬First : P ⊆ ∁ Q → All P ⊆ ∁ (First P Q)
All⇒¬First p⇒¬q [] ()
All⇒¬First p⇒¬q (px ∷ pxs) [ qx ] = ⊥-elim (p⇒¬q px qx)
All⇒¬First p⇒¬q (_ ∷ pxs) (_ ∷ hf) = All⇒¬First p⇒¬q pxs hf
First⇒¬All : Q ⊆ ∁ P → First P Q ⊆ ∁ (All P)
First⇒¬All q⇒¬p [ qx ] (px ∷ pxs) = q⇒¬p qx px
First⇒¬All q⇒¬p (_ ∷ pqxs) (_ ∷ pxs) = First⇒¬All q⇒¬p pqxs pxs
------------------------------------------------------------------------
-- Irrelevance
unique-index : ∀ {xs} → P ⊆ ∁ Q → (f₁ f₂ : First P Q xs) → index f₁ ≡ index f₂
unique-index p⇒¬q [ _ ] [ _ ] = refl
unique-index p⇒¬q [ qx ] (px ∷ _) = ⊥-elim (p⇒¬q px qx)
unique-index p⇒¬q (px ∷ _) [ qx ] = ⊥-elim (p⇒¬q px qx)
unique-index p⇒¬q (_ ∷ f₁) (_ ∷ f₂) = P.cong suc (unique-index p⇒¬q f₁ f₂)
irrelevant : P ⊆ ∁ Q → Irrelevant P → Irrelevant Q → Irrelevant (First P Q)
irrelevant p⇒¬q p-irr q-irr [ qx₁ ] [ qx₂ ] = P.cong [_] (q-irr qx₁ qx₂)
irrelevant p⇒¬q p-irr q-irr [ qx₁ ] (px₂ ∷ f₂) = ⊥-elim (p⇒¬q px₂ qx₁)
irrelevant p⇒¬q p-irr q-irr (px₁ ∷ f₁) [ qx₂ ] = ⊥-elim (p⇒¬q px₁ qx₂)
irrelevant p⇒¬q p-irr q-irr (px₁ ∷ f₁) (px₂ ∷ f₂) =
P.cong₂ _∷_ (p-irr px₁ px₂) (irrelevant p⇒¬q p-irr q-irr f₁ f₂)
------------------------------------------------------------------------
-- Decidability
module _ {a p} {A : Set a} {P : Pred A p} where
first? : Decidable P → Decidable (First P (∁ P))
first? P? xs = Sum.toDec
$ Sum.map₂ (All⇒¬First contradiction)
$ first (Sum.fromDec ∘ P?) xs
------------------------------------------------------------------------
-- Conversion to Any
module _ {a p} {A : Set a} {P : Pred A p} where
fromAny∘toAny≗id : ∀ {xs} → fromAny {Q = P} {x = xs} ∘′ toAny ≗ id
fromAny∘toAny≗id [ qx ] = refl
fromAny∘toAny≗id (px ∷ pqxs) = P.cong (_ ∷_) (fromAny∘toAny≗id pqxs)
toAny∘fromAny≗id : ∀ {xs} → toAny {Q = P} ∘′ fromAny {x = xs} ≗ id
toAny∘fromAny≗id (here px) = refl
toAny∘fromAny≗id (there v) = P.cong there (toAny∘fromAny≗id v)
------------------------------------------------------------------------
-- Equivalence between the inductive definition and the view
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
toView : ∀ {as} → First P Q as → FirstView P Q as
toView [ qx ] = [] ++ qx ∷ _
toView (px ∷ pqxs) with toView pqxs
... | pxs ++ qy ∷ ys = (px ∷ pxs) ++ qy ∷ ys
fromView : ∀ {as} → FirstView P Q as → First P Q as
fromView (pxs ++ qy ∷ ys) = ++⁺ pxs [ qy ]
| {
"alphanum_fraction": 0.4659949622,
"avg_line_length": 37.9739130435,
"ext": "agda",
"hexsha": "e77bcd3265ea62a5cd2057e63b107ff9cc5a38ba",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/First/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/First/Properties.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/First/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1670,
"size": 4367
} |
{-# OPTIONS --safe --warning=error #-}
open import Sets.EquivalenceRelations
open import Functions.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_; Setω)
open import Setoids.Setoids
open import Groups.Definition
open import LogicalFormulae
open import Orders.WellFounded.Definition
open import Numbers.Naturals.Semiring
open import Groups.Lemmas
module Groups.FreeProduct.Setoid {i : _} {I : Set i} (decidableIndex : (x y : I) → ((x ≡ y) || ((x ≡ y) → False))) {a b : _} {A : I → Set a} {S : (i : I) → Setoid {a} {b} (A i)} {_+_ : (i : I) → (A i) → (A i) → A i} (decidableGroups : (i : I) → (x y : A i) → ((Setoid._∼_ (S i) x y)) || ((Setoid._∼_ (S i) x y) → False)) (G : (i : I) → Group (S i) (_+_ i)) where
open import Groups.FreeProduct.Definition decidableIndex decidableGroups G
=RP' : {m n : _} (s1 : ReducedSequenceBeginningWith m) (s2 : ReducedSequenceBeginningWith n) → Set b
=RP' (ofEmpty i g nonZero) (ofEmpty j h nonZero₁) with decidableIndex i j
=RP' (ofEmpty i g nonZero) (ofEmpty .i h nonZero₁) | inl refl = Setoid._∼_ (S i) g h
=RP' (ofEmpty i g nonZero) (ofEmpty j h nonZero₁) | inr x = False'
=RP' (ofEmpty i g nonZero) (prependLetter i₁ g₁ nonZero₁ s2 x) = False'
=RP' (prependLetter i g nonZero s1 x) (ofEmpty i₁ g₁ nonZero₁) = False'
=RP' (prependLetter i g nonZero s1 x) (prependLetter j h nonZero₁ s2 x₁) with decidableIndex i j
=RP' (prependLetter i g nonZero s1 x) (prependLetter .i h nonZero₁ s2 x₁) | inl refl = Setoid._∼_ (S i) g h && =RP' s1 s2
=RP' (prependLetter i g nonZero s1 x) (prependLetter j h nonZero₁ s2 x₁) | inr x₂ = False'
_=RP_ : Rel ReducedSequence
empty =RP empty = True'
empty =RP nonempty i x = False'
nonempty i x =RP empty = False'
nonempty i x =RP nonempty j y = =RP' x y
=RP'reflex : {i : _} (x : ReducedSequenceBeginningWith i) → =RP' x x
=RP'reflex (ofEmpty i g nonZero) with decidableIndex i i
=RP'reflex (ofEmpty i g nonZero) | inl refl = Equivalence.reflexive (Setoid.eq (S i))
=RP'reflex (ofEmpty i g nonZero) | inr x = exFalso (x refl)
=RP'reflex (prependLetter i g nonZero x x₁) with decidableIndex i i
=RP'reflex (prependLetter i g nonZero x x₁) | inl refl = Equivalence.reflexive (Setoid.eq (S i)) ,, =RP'reflex x
=RP'reflex (prependLetter i g nonZero x x₁) | inr bad = exFalso (bad refl)
private
reflex : Reflexive _=RP_
reflex {empty} = record {}
reflex {nonempty i (ofEmpty .i g nonZero)} with decidableIndex i i
reflex {nonempty i (ofEmpty .i g nonZero)} | inl refl = Equivalence.reflexive (Setoid.eq (S i))
... | inr bad = exFalso (bad refl)
reflex {nonempty i (prependLetter .i g nonZero x x₁)} with decidableIndex i i
reflex {nonempty i (prependLetter .i g nonZero x x₁)} | inl refl = Equivalence.reflexive (Setoid.eq (S i)) ,, =RP'reflex x
reflex {nonempty i (prependLetter .i g nonZero x x₁)} | inr bad = exFalso (bad refl)
=RP'symm : {i j : _} (x : ReducedSequenceBeginningWith i) (y : ReducedSequenceBeginningWith j) → =RP' x y → =RP' y x
=RP'symm (ofEmpty i g nonZero) (ofEmpty j h nonZero2) with decidableIndex i j
=RP'symm (ofEmpty i g nonZero) (ofEmpty j h nonZero2) | inl pr with decidableIndex j i
=RP'symm (ofEmpty .j g nonZero) (ofEmpty j h nonZero2) | inl refl | inl refl = Equivalence.symmetric (Setoid.eq (S j)) {g} {h}
=RP'symm (ofEmpty i g nonZero) (ofEmpty j h nonZero2) | inl pr | inr x = exFalso (x (equalityCommutative pr))
=RP'symm (ofEmpty i g nonZero) (ofEmpty j h nonZero2) | inr x with decidableIndex j i
=RP'symm (ofEmpty i g nonZero) (ofEmpty j h nonZero2) | inr x | inl pr = exFalso (x (equalityCommutative pr))
=RP'symm (ofEmpty i g nonZero) (ofEmpty j h nonZero2) | inr x | inr _ = id
=RP'symm (ofEmpty i g nonZero) (prependLetter i₁ g₁ nonZero₁ y x) = id
=RP'symm (prependLetter i g nonZero x x₁) (ofEmpty i₁ g₁ nonZero₁) = id
=RP'symm (prependLetter i g nonZero x x₁) (prependLetter j h nonZero2 y pr2) pr with decidableIndex i j
=RP'symm (prependLetter .j g nonZero x x₁) (prependLetter j h nonZero2 y pr2) pr | inl refl with decidableIndex j j
=RP'symm (prependLetter .j g nonZero x x₁) (prependLetter j h nonZero2 y pr2) (fst ,, snd) | inl refl | inl refl = Equivalence.symmetric (Setoid.eq (S j)) fst ,, =RP'symm x y snd
=RP'symm (prependLetter .j g nonZero x x₁) (prependLetter j h nonZero2 y pr2) pr | inl refl | inr bad = exFalso (bad refl)
=RP'symm (prependLetter i g nonZero x x₁) (prependLetter j h nonZero2 y pr2) () | inr i!=j
private
symm : Symmetric _=RP_
symm {empty} {empty} x = record {}
symm {nonempty i m} {nonempty i₁ n} x = =RP'symm m n x
=RP'trans : {i j k : _} (x : ReducedSequenceBeginningWith i) (y : ReducedSequenceBeginningWith j) (z : ReducedSequenceBeginningWith k) → =RP' x y → =RP' y z → =RP' x z
=RP'trans (ofEmpty i g nonZero) (ofEmpty j g₁ nonZero₁) (ofEmpty k g₂ nonZero₂) x=y y=z with decidableIndex i j
=RP'trans (ofEmpty .j g nonZero) (ofEmpty j g₁ nonZero₁) (ofEmpty k g₂ nonZero₂) x=y y=z | inl refl with decidableIndex j k
=RP'trans (ofEmpty .j g nonZero) (ofEmpty j g₁ nonZero₁) (ofEmpty .j g₂ nonZero₂) x=y y=z | inl refl | inl refl = Equivalence.transitive (Setoid.eq (S j)) x=y y=z
=RP'trans (prependLetter i g nonZero x x₁) (prependLetter j g₁ nonZero₁ y x₂) (prependLetter k g₂ nonZero₂ z x₃) x=y y=z with decidableIndex i j
=RP'trans (prependLetter .j g nonZero x x₁) (prependLetter j g₁ nonZero₁ y x₂) (prependLetter k g₂ nonZero₂ z x₃) x=y y=z | inl refl with decidableIndex j k
=RP'trans (prependLetter .j g nonZero x x₁) (prependLetter j g₁ nonZero₁ y x₂) (prependLetter .j g₂ nonZero₂ z x₃) (fst1 ,, snd1) (fst2 ,, snd2) | inl refl | inl refl = Equivalence.transitive (Setoid.eq (S j)) fst1 fst2 ,, =RP'trans x y z snd1 snd2
private
trans : (x y z : ReducedSequence) → x =RP y → y =RP z → x =RP z
trans empty empty empty x=y y=z = record {}
trans (nonempty i x) (nonempty i₁ y) (nonempty i₂ z) x=y y=z = =RP'trans x y z x=y y=z
notEqualIfStartDifferent : {j1 j2 : I} (neq : (j1 ≡ j2) → False) → (x1 : ReducedSequenceBeginningWith j1) (x2 : ReducedSequenceBeginningWith j2) → =RP' x1 x2 → False
notEqualIfStartDifferent neq (ofEmpty i g nonZero) (ofEmpty j g₁ nonZero₁) eq with decidableIndex i j
notEqualIfStartDifferent neq (ofEmpty i g nonZero) (ofEmpty j g₁ nonZero₁) eq | inl i=j = neq i=j
notEqualIfStartDifferent neq (prependLetter i g nonZero x1 x) (prependLetter j g₁ nonZero₁ x2 x₁) eq with decidableIndex i j
notEqualIfStartDifferent neq (prependLetter i g nonZero x1 x) (prependLetter j g₁ nonZero₁ x2 x₁) eq | inl eq' = neq eq'
freeProductSetoid : Setoid ReducedSequence
Setoid._∼_ freeProductSetoid = _=RP_
Equivalence.reflexive (Setoid.eq freeProductSetoid) {x} = reflex {x}
Equivalence.symmetric (Setoid.eq freeProductSetoid) {a} {b} = symm {a} {b}
Equivalence.transitive (Setoid.eq freeProductSetoid) {x} {y} {z} = trans x y z
| {
"alphanum_fraction": 0.700739645,
"avg_line_length": 69.6907216495,
"ext": "agda",
"hexsha": "a05ce34f3c47eff397f67f7a8be5cc24ac5ff094",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/FreeProduct/Setoid.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/FreeProduct/Setoid.agda",
"max_line_length": 362,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/FreeProduct/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 2454,
"size": 6760
} |
open import Function using (_∘_)
open import Data.List using (List; _++_) renaming (_∷_ to _,_; _∷ʳ_ to _,′_; [] to ∅)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (∃; _,_)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Nullary.Decidable using (True; toWitness)
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong)
module LambekGrishinCalculus (U : Set) (R : U) (⟦_⟧ᵁ : U → Set) where
infixr 30 _⊗_ _⊕_
infixr 20 _⇒_ _⇛_
infixl 20 _⇐_ _⇚_
infix 5 _⊢_ [_]⊢_ _⊢[_]
data Polarity : Set where
+ : Polarity
- : Polarity
_≟ᴾ_ : (p q : Polarity) → Dec (p ≡ q)
+ ≟ᴾ + = yes refl
+ ≟ᴾ - = no (λ ())
- ≟ᴾ + = no (λ ())
- ≟ᴾ - = yes refl
data Type : Set where
el : (A : U) → (p : Polarity) → Type
_⊗_ : Type → Type → Type
_⇒_ : Type → Type → Type
_⇐_ : Type → Type → Type
_⊕_ : Type → Type → Type
_⇚_ : Type → Type → Type
_⇛_ : Type → Type → Type
data Pos : Type → Set where
el : ∀ A → Pos (el A +)
_⊗_ : ∀ A B → Pos (A ⊗ B)
_⇚_ : ∀ B A → Pos (B ⇚ A)
_⇛_ : ∀ A B → Pos (A ⇛ B)
Pos? : ∀ A → Dec (Pos A)
Pos? (el A +) = yes (el A)
Pos? (el A -) = no (λ ())
Pos? (A ⊗ B) = yes (A ⊗ B)
Pos? (A ⇒ B) = no (λ ())
Pos? (A ⇐ B) = no (λ ())
Pos? (A ⊕ B) = no (λ ())
Pos? (A ⇚ B) = yes (A ⇚ B)
Pos? (A ⇛ B) = yes (A ⇛ B)
data Neg : Type → Set where
el : ∀ A → Neg (el A -)
_⊕_ : ∀ A B → Neg (A ⊕ B)
_⇒_ : ∀ A B → Neg (A ⇒ B)
_⇐_ : ∀ B A → Neg (B ⇐ A)
Neg? : ∀ A → Dec (Neg A)
Neg? (el A +) = no (λ ())
Neg? (el A -) = yes (el A)
Neg? (A ⊗ B) = no (λ ())
Neg? (A ⇒ B) = yes (A ⇒ B)
Neg? (A ⇐ B) = yes (A ⇐ B)
Neg? (A ⊕ B) = yes (A ⊕ B)
Neg? (A ⇚ B) = no (λ ())
Neg? (A ⇛ B) = no (λ ())
Pol? : ∀ A → Pos A ⊎ Neg A
Pol? (el A +) = inj₁ (el A)
Pol? (el A -) = inj₂ (el A)
Pol? (A ⊗ B) = inj₁ (A ⊗ B)
Pol? (A ⇚ B) = inj₁ (A ⇚ B)
Pol? (A ⇛ B) = inj₁ (A ⇛ B)
Pol? (A ⊕ B) = inj₂ (A ⊕ B)
Pol? (A ⇒ B) = inj₂ (A ⇒ B)
Pol? (A ⇐ B) = inj₂ (A ⇐ B)
mutual
data Struct+ : Set where
·_· : Type → Struct+
_⊗_ : Struct+ → Struct+ → Struct+
_⇚_ : Struct+ → Struct- → Struct+
_⇛_ : Struct- → Struct+ → Struct+
data Struct- : Set where
·_· : Type → Struct-
_⊕_ : Struct- → Struct- → Struct-
_⇒_ : Struct+ → Struct- → Struct-
_⇐_ : Struct- → Struct+ → Struct-
mutual
data _⊢[_] : Struct+ → Type → Set where
var : ∀ {A} → · A · ⊢[ A ]
μ : ∀ {X A} {p : True (Neg? A)} → X ⊢ · A · → X ⊢[ A ]
⊗R : ∀ {X Y A B} → X ⊢[ A ] → Y ⊢[ B ] → X ⊗ Y ⊢[ A ⊗ B ]
⇚R : ∀ {X Y A B} → X ⊢[ A ] → [ B ]⊢ Y → X ⇚ Y ⊢[ A ⇚ B ]
⇛R : ∀ {X Y A B} → [ A ]⊢ X → Y ⊢[ B ] → X ⇛ Y ⊢[ A ⇛ B ]
data [_]⊢_ : Type → Struct- → Set where
covar : ∀ {A} → [ A ]⊢ · A ·
μ̃ : ∀ {X A} {p : True (Pos? A)} → · A · ⊢ X → [ A ]⊢ X
⊕L : ∀ {X Y A B} → [ A ]⊢ Y → [ B ]⊢ X → [ A ⊕ B ]⊢ X ⊕ Y
⇒L : ∀ {X Y A B} → X ⊢[ A ] → [ B ]⊢ Y → [ A ⇒ B ]⊢ X ⇒ Y
⇐L : ∀ {X Y A B} → [ A ]⊢ Y → X ⊢[ B ] → [ A ⇐ B ]⊢ Y ⇐ X
data _⊢_ : Struct+ → Struct- → Set where
μ* : ∀ {X A} {p : True (Pos? A)} → X ⊢[ A ] → X ⊢ · A ·
μ̃* : ∀ {X A} {p : True (Neg? A)}→ [ A ]⊢ X → · A · ⊢ X
⊗L : ∀ {X A B} → · A · ⊗ · B · ⊢ X → · A ⊗ B · ⊢ X
⇚L : ∀ {X A B} → · A · ⇚ · B · ⊢ X → · A ⇚ B · ⊢ X
⇛L : ∀ {X A B} → · A · ⇛ · B · ⊢ X → · A ⇛ B · ⊢ X
⊕R : ∀ {X A B} → X ⊢ · A · ⊕ · B · → X ⊢ · A ⊕ B ·
⇒R : ∀ {X A B} → X ⊢ · A · ⇒ · B · → X ⊢ · A ⇒ B ·
⇐R : ∀ {X A B} → X ⊢ · A · ⇐ · B · → X ⊢ · A ⇐ B ·
res₁ : ∀ {X Y Z} → Y ⊢ X ⇒ Z → X ⊗ Y ⊢ Z
res₂ : ∀ {X Y Z} → X ⊗ Y ⊢ Z → Y ⊢ X ⇒ Z
res₃ : ∀ {X Y Z} → X ⊢ Z ⇐ Y → X ⊗ Y ⊢ Z
res₄ : ∀ {X Y Z} → X ⊗ Y ⊢ Z → X ⊢ Z ⇐ Y
dres₁ : ∀ {X Y Z} → Z ⇚ X ⊢ Y → Z ⊢ Y ⊕ X
dres₂ : ∀ {X Y Z} → Z ⊢ Y ⊕ X → Z ⇚ X ⊢ Y
dres₃ : ∀ {X Y Z} → Y ⇛ Z ⊢ X → Z ⊢ Y ⊕ X
dres₄ : ∀ {X Y Z} → Z ⊢ Y ⊕ X → Y ⇛ Z ⊢ X
dist₁ : ∀ {X Y Z W} → X ⊗ Y ⊢ Z ⊕ W → X ⇚ W ⊢ Z ⇐ Y
dist₂ : ∀ {X Y Z W} → X ⊗ Y ⊢ Z ⊕ W → Y ⇚ W ⊢ X ⇒ Z
dist₃ : ∀ {X Y Z W} → X ⊗ Y ⊢ Z ⊕ W → Z ⇛ X ⊢ W ⇐ Y
dist₄ : ∀ {X Y Z W} → X ⊗ Y ⊢ Z ⊕ W → Z ⇛ Y ⊢ X ⇒ W
raise : ∀ {A B} → · A · ⊢ · (B ⇐ A) ⇒ B ·
raise = ⇒R (res₂ (res₃ (μ̃* (⇐L covar var))))
lower : ∀ {A B} → · B ⇚ (A ⇛ B) · ⊢ · A ·
lower = ⇚L (dres₂ (dres₃ (μ* (⇛R covar var))))
import IntuitionisticLogic U ⟦_⟧ᵁ as IL
open IL.Explicit hiding ([_]; _⊢_; reify)
import LinearLogic U R ⟦_⟧ᵁ as LP
open LP renaming (Type to TypeLP; _⊢_ to _⊢LP_; [_] to reifyLP)
mutual
⟦_⟧+ : Type → TypeLP
⟦ el A + ⟧+ = el A
⟦ el A - ⟧+ = ¬ (¬ el A)
⟦ A ⊗ B ⟧+ = ⟦ A ⟧+ ⊗ ⟦ B ⟧+
⟦ A ⇚ B ⟧+ = ⟦ A ⟧+ ⊗ ⟦ B ⟧-
⟦ A ⇛ B ⟧+ = ⟦ A ⟧- ⊗ ⟦ B ⟧+
⟦ A ⊕ B ⟧+ = ¬ ( ⟦ A ⟧- ⊗ ⟦ B ⟧-)
⟦ A ⇒ B ⟧+ = ¬ ( ⟦ A ⟧+ ⊗ ⟦ B ⟧-)
⟦ A ⇐ B ⟧+ = ¬ ( ⟦ A ⟧- ⊗ ⟦ B ⟧+)
⟦_⟧- : Type → TypeLP
⟦ el A + ⟧- = ¬ el A
⟦ el A - ⟧- = ¬ el A
⟦ A ⊗ B ⟧- = ¬ ( ⟦ A ⟧+ ⊗ ⟦ B ⟧+)
⟦ A ⇚ B ⟧- = ¬ ( ⟦ A ⟧+ ⊗ ⟦ B ⟧-)
⟦ A ⇛ B ⟧- = ¬ ( ⟦ A ⟧- ⊗ ⟦ B ⟧+)
⟦ A ⊕ B ⟧- = ⟦ A ⟧- ⊗ ⟦ B ⟧-
⟦ A ⇒ B ⟧- = ⟦ A ⟧+ ⊗ ⟦ B ⟧-
⟦ A ⇐ B ⟧- = ⟦ A ⟧- ⊗ ⟦ B ⟧+
mutual
str+ : Struct+ → List TypeLP
str+ (· A ·) = ⟦ A ⟧+ , ∅
str+ (A ⊗ B) = str+ A ++ str+ B
str+ (A ⇚ B) = str+ A ++ str- B
str+ (A ⇛ B) = str- A ++ str+ B
str- : Struct- → List TypeLP
str- (· A ·) = ⟦ A ⟧- , ∅
str- (A ⊕ B) = str- A ++ str- B
str- (A ⇒ B) = str+ A ++ str- B
str- (A ⇐ B) = str- A ++ str+ B
open Reify {{...}} using (⟦_⟧)
instance
Struct+Reify : Reify Struct+ (List TypeLP)
Struct+Reify = record { ⟦_⟧ = str+ }
instance
Struct-Reify : Reify Struct- (List TypeLP)
Struct-Reify = record { ⟦_⟧ = str- }
instance
TypeReify : Reify Type Set
TypeReify = record { ⟦_⟧ = λ A → ⟦ ⟦ ⟦ A ⟧+ ⟧ ⟧ }
instance
StructReify : Reify Struct+ (List Set)
StructReify = record { ⟦_⟧ = λ X → ⟦ ⟦ ⟦ X ⟧ ⟧ ⟧ }
Neg-≡ : ∀ {A} → Neg A → ⟦ A ⟧+ ≡ ⟦ A ⟧- ⊸ ⊥
Neg-≡ {.(el A -)} (el A) = refl
Neg-≡ {.(A ⊕ B)} (A ⊕ B) = refl
Neg-≡ {.(A ⇒ B)} (A ⇒ B) = refl
Neg-≡ {.(A ⇐ B)} (A ⇐ B) = refl
Pos-≡ : ∀ {A} → Pos A → ⟦ A ⟧- ≡ ⟦ A ⟧+ ⊸ ⊥
Pos-≡ {.(el A +)} (el A) = refl
Pos-≡ {.(A ⊗ B)} (A ⊗ B) = refl
Pos-≡ {.(A ⇚ B)} (A ⇚ B) = refl
Pos-≡ {.(A ⇛ B)} (A ⇛ B) = refl
mutual
reifyʳ : ∀ {X A} → X ⊢[ A ] → ⟦ X ⟧ ⊢LP ⟦ A ⟧+
reifyʳ var = var
reifyʳ (μ {X} {A} {q} t) rewrite Neg-≡ (toWitness q) = abs (to-back (reify t))
reifyʳ (⊗R {X} {Y} {A} {B} s t) = pair (reifyʳ s) (reifyʳ t)
reifyʳ (⇚R {X} {Y} {A} {B} s t) = pair (reifyʳ s) (reifyˡ t)
reifyʳ (⇛R {X} {Y} {A} {B} s t) = pair (reifyˡ s) (reifyʳ t)
reifyˡ : ∀ {A Y} → [ A ]⊢ Y → ⟦ Y ⟧ ⊢LP ⟦ A ⟧-
reifyˡ covar = var
reifyˡ (μ̃ {X} {A} {p} t) rewrite Pos-≡ (toWitness p) = abs (reify t)
reifyˡ (⊕L {X} {Y} {A} {B} s t) = YX↝XY ⟦ X ⟧ ⟦ Y ⟧ (pair (reifyˡ s) (reifyˡ t))
reifyˡ (⇒L {X} {Y} {A} {B} s t) = pair (reifyʳ s) (reifyˡ t)
reifyˡ (⇐L {X} {Y} {A} {B} s t) = pair (reifyˡ s) (reifyʳ t)
reify : ∀ {X Y} → X ⊢ Y → ⟦ X ⟧ ++ ⟦ Y ⟧ ⊢LP ⊥
reify (μ* {X} {A} {p} t) rewrite Pos-≡ (toWitness p) = to-front (app var (reifyʳ t))
reify (μ̃* {X} {A} {q} t) rewrite Neg-≡ (toWitness q) = app var (reifyˡ t)
reify (⊗L {X} {A} {B} t) = pair-left (reify t)
reify (⇚L {X} {A} {B} t) = pair-left (reify t)
reify (⇛L {X} {A} {B} t) = pair-left (reify t)
reify (⊕R {X} {A} {B} t) = pair-left′ {⟦ X ⟧} {⟦ A ⟧- } {⟦ B ⟧- } (reify t)
reify (⇒R {X} {A} {B} t) = pair-left′ {⟦ X ⟧} {⟦ A ⟧+ } {⟦ B ⟧- } (reify t)
reify (⇐R {X} {A} {B} t) = pair-left′ {⟦ X ⟧} {⟦ A ⟧- } {⟦ B ⟧+ } (reify t)
reify (res₁ {X} {Y} {Z} t) rewrite sym (++-assoc ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧) = Y[XZ]↝X[YZ] ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧ (reify t)
reify (res₂ {X} {Y} {Z} t) rewrite ++-assoc ⟦ Y ⟧ ⟦ X ⟧ ⟦ Z ⟧ = [YX]Z↝[XY]Z ⟦ Y ⟧ ⟦ X ⟧ ⟦ Z ⟧ (reify t)
reify (res₃ {X} {Y} {Z} t) rewrite sym (++-assoc ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧) = X[ZY]↝X[YZ] ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧ (reify t)
reify (res₄ {X} {Y} {Z} t) rewrite ++-assoc ⟦ X ⟧ ⟦ Z ⟧ ⟦ Y ⟧ = [XZ]Y↝[XY]Z ⟦ X ⟧ ⟦ Z ⟧ ⟦ Y ⟧ (reify t)
reify (dres₁ {X} {Y} {Z} t) rewrite ++-assoc ⟦ Z ⟧ ⟦ Y ⟧ ⟦ X ⟧ = [XZ]Y↝[XY]Z ⟦ Z ⟧ ⟦ Y ⟧ ⟦ X ⟧ (reify t)
reify (dres₂ {X} {Y} {Z} t) rewrite sym (++-assoc ⟦ Z ⟧ ⟦ X ⟧ ⟦ Y ⟧) = X[ZY]↝X[YZ] ⟦ Z ⟧ ⟦ X ⟧ ⟦ Y ⟧ (reify t)
reify (dres₃ {X} {Y} {Z} t) rewrite ++-assoc ⟦ Z ⟧ ⟦ Y ⟧ ⟦ X ⟧ = [YX]Z↝[XY]Z ⟦ Z ⟧ ⟦ Y ⟧ ⟦ X ⟧ (reify t)
reify (dres₄ {X} {Y} {Z} t) rewrite sym (++-assoc ⟦ Y ⟧ ⟦ Z ⟧ ⟦ X ⟧) = Y[XZ]↝X[YZ] ⟦ Y ⟧ ⟦ Z ⟧ ⟦ X ⟧ (reify t)
reify (dist₁ {X} {Y} {Z} {W} t) = XYZW↝XWZY ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧ ⟦ W ⟧ (reify t)
reify (dist₂ {X} {Y} {Z} {W} t) = XYZW↝YWXZ ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧ ⟦ W ⟧ (reify t)
reify (dist₃ {X} {Y} {Z} {W} t) = XYZW↝ZXWY ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧ ⟦ W ⟧ (reify t)
reify (dist₄ {X} {Y} {Z} {W} t) = XYZW↝ZYXW ⟦ X ⟧ ⟦ Y ⟧ ⟦ Z ⟧ ⟦ W ⟧ (reify t)
[_] : ∀ {X A} → X ⊢[ A ] → (Ctxt ⟦ X ⟧ → ⟦ A ⟧)
[_] = reifyLP ∘ reifyʳ
| {
"alphanum_fraction": 0.4016617346,
"avg_line_length": 36.1563786008,
"ext": "agda",
"hexsha": "85743b3bea15a150d5f30de0f2af1e1e02c866ca",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/msla2014",
"max_forks_repo_path": "src/LambekGrishinCalculus.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wenkokke/msla2014",
"max_issues_repo_path": "src/LambekGrishinCalculus.agda",
"max_line_length": 112,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/msla2014",
"max_stars_repo_path": "src/LambekGrishinCalculus.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-29T09:07:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-17T23:04:39.000Z",
"num_tokens": 4910,
"size": 8786
} |
{-# OPTIONS --without-K #-}
module Ch1 where
-- open import lib.Base
open import Base
-- warmup
module Eq-1-11-2 {i j} {A : Type i} {B : Type j} where
-- import lib.types.Coproduct
-- open import lib.types.Empty
-- open import lib.types.Sigma
-- If not A and not B, then not (A or B)
deMorgan1 : (A → ⊥) × (B → ⊥) → (Coprod A B → ⊥)
-- deMorgan1 (notA , notB) ab = {!!} -- {!!} becomes =>
-- deMorgan1 (notA , notB) (inl x) = {!!} -- by cases, C-c C-c on param ab
-- deMorgan1 (notA , notB) (inr x) = {!!}
deMorgan1 (notA , notB) (inl a) = notA a -- the 'a part' of (A + B) → ⊥
deMorgan1 (notA , notB) (inr b) = notB b
module Ex1-1 where
{-
Exercise 1.1. Given functions f : A -> B and g : B -> C, define their composite g o f : A -> C.
Show that we have h o (g o f ) == (h o g) o f
-}
_o_ : ∀ {i} {A B C : Type i} → (B → C) → (A → B) → A → C
(g o f) x = g (f x)
o-assoc : ∀ {i} {A B C D : Type i} →
(h : C → D) → (g : B → C) → (f : A → B) →
h o (g o f) == (h o g) o f
o-assoc _ _ _ = idp -- "it's de proof"
module Ex1-2 where
-- open import lib.types.Sigma
-- 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.
recAxB : ∀ {i} {A B C : Type i} →
(A → B → C) → A × B → C
recAxB f ab = f (fst ab) (snd ab)
recAxB= : ∀ {i} {A B C : Type i}
{f : A → B → C}
{a : A} {b : B} →
recAxB f (a , b) == f a b
recAxB= = idp
recA+B : ∀ {i j} {A : Type i} {B : Type j} {C : Type (lmax i j)} →
(A → C) → (B → C) → (Coprod A B → C)
recA+B f g (inl x) = f x
recA+B f g (inr x) = g x
recA+B= : {A B C : Type0}
{f : A → C} {g : B → C}
{a : A} {b : B} →
(recA+B f g (inl a) == f a) × (recA+B f g (inr b) == g b)
recA+B= = idp , idp
recΣ : ∀ {i j} {A : Type i} {B : A → Type j} {C : Type (lmax i j)} →
((a : A) → B a → C) →
Σ A B → C
recΣ f ab = f (fst ab) (snd ab)
recΣ= : ∀ {i j} {A : Type i} {B : A → Type j} {C : Type (lmax i j)}
{f : (a : A) → B a → C}
{a : A} {ba : B a} →
recΣ f (a , ba) == f a ba
recΣ= = idp
module Ex1-3 {i j} {A : Type i} {B : Type j} where
-- open import lib.types.Sigma
{- Derive the induction principle for products indA×B, using only the projections
and the propositional uniqueness principle uppt. Verify that the definitional
equalities are valid. Gen- eralize uppt to Σ-types, and do the same for Σ-types.
-}
-- book definition of uppt
uppt-× : (ab : (A × B)) → (fst ab , snd ab) == ab
uppt-× = λ _ → idp
-- definition of induction principle the projections and the transported uniqueness principle
-- (this was a confusing question to work out in Agda, since the transport is redundant / inferred by the typechecker)
ind-× : (C : (A × B) → Type (lmax i j)) →
((a : A ) → (b : B) → C (a , b)) → Π (A × B) C
ind-× C g ab = transport C (uppt-× ab) (g (fst ab) (snd ab))
-- (propositional) verification of defining equations
ind-×= : (C : (A × B) → Type (lmax i j)) →
(g : ((a : A ) → (b : B) → C (a , b))) →
∀ {a b} → ind-× C g (a , b) == g a b
ind-×= C g {a} {b} = -- idp
ind-× C g (a , b) =⟨ idp ⟩
transport C (uppt-× (a , b)) (g a b) =⟨ idp ⟩
transport C idp (g a b) =⟨ idp ⟩
g a b ∎
-- book definition of induction principle using pattern matching
pattern-match-ind-× : (C : (A × B) → Type (lmax i j)) →
Π A (λ x → Π B (λ y → C (x , y))) → Π (A × B) C
pattern-match-ind-× _ g (a , b) = g a b
-- alternative definition of uniqueness principle (from induction principle)
ind-uppt-× : (x : (A × B)) → (fst x , snd x) == x
ind-uppt-× = ind-× (λ z → z == z) (λ x x₁ → idp)
-- validate definition for uppt
uppt-×= : {x : (A × B)} → (uppt-× x) == (ind-uppt-× x)
uppt-×= = idp
-- uppt for Σ types
upptΣ : {B : (a : A) → Type j} → (ab : Σ A B) → ab == (fst ab , snd ab)
upptΣ _ = idp
module Ex1-4 where
-- open import lib.types.Sigma
{-
Assuming as given only the iterator for natural numbers
iter : ∏ C → (C → C) → N → C
C:U
with the defining equations
iter(C, c0, cs, succ(n)) :≡ cs(iter(C, c0, cs, n)),
derive a function having the type of the recursor recN. Show that the defining
equations of the recursor hold propositionally for this function, using the
induction principle for N.
-}
iter : {C : Type0} →
C → (C → C) → ℕ → C
iter c0 cs 0 = c0
iter c0 cs (S n) = cs (iter c0 cs n)
-- used in the definition of recNiter below to keep a count of the applications of a function
sucApply : {C : Type0} → (ℕ → C → C) → ℕ × C → ℕ × C
sucApply {C} cs = cs' where
cs' : ℕ × C → ℕ × C
cs' (n , c) = S n , cs n c
{- Induction principle (dependent eliminator) for ℕ from the book:
indN : ∏(C:N→U)C(0) → ∏(n:N)C(n) → C(succ(n)) → ∏(n:N)C(n)
indN(C, c0, cs, 0) :≡ c0,
indN(C, c0, cs, succ(n)) :≡ cs(n, indN(C, c0, cs, n)).
-}
indN : ∀ {i} {C : ℕ → Type i} →
C 0 → ((n : ℕ) → C n → C (S n)) → (n : ℕ) → C n
indN c0 cs 0 = c0
indN c0 cs (S n) = cs n (indN c0 cs n)
-- digression / warmup - inductive proof that evens-are-even
-- nth even
even : ℕ → ℕ
even n = iter 0 (λ n → S (S n)) n
S= : {m n : ℕ} → m == n → (S m == S n)
S= idp = idp
_*2 : ℕ → ℕ
O *2 = O
(S n) *2 = S (S (n *2))
evens-are-even : (n : ℕ) → Σ ℕ (λ m → even n == m *2)
evens-are-even = indN (0 , idp) inductiveCase where
inductiveCase : (n : ℕ) → Σ ℕ (λ m → even n == m *2) → Σ ℕ (λ m → even (S n) == m *2)
inductiveCase n (m , p) = S m , p'' where
p' = S= p
p'' = S= p'
{- derive a function having the type of the recursor recN
recN : ∏(C:U)C→(N→C→C)→N→C
recN(C, c0, cs, 0) :≡ c0,
recN(C, c0, cs, Sc(n)) :≡ cs(n, recN(C, c0, cs, n)).
-}
recNiter : {C : Type0} →
C → (ℕ → C → C) → ℕ → C
recNiter c0 cs n = snd (iter (0 , c0) cs' n) where
cs' = sucApply cs
{- Show that the defining
equations of the recursor hold propositionally for this function, using the
induction principle for N
-}
recNiter= : {C : Type0} {c0 : C} {cs : ℕ → C → C } →
(n : ℕ) →
(recNiter c0 cs (S n)) == (cs n (recNiter c0 cs n))
recNiter= {C} {c0} {cs} n = cs= n'= -- or, as spelled out below (using equational reasoning from HoTT-Agda)
-- recNiter c0 cs (S n) =⟨ idp ⟩
-- snd (iter' (S n)) =⟨ idp ⟩
-- snd (cs' (iter' n)) =⟨ idp ⟩
-- snd (cs' (n' , snd (iter' n))) =⟨ idp ⟩
-- cs n' (snd (iter' n)) =⟨ cs= n'= ⟩
-- cs n (snd (iter' n)) =⟨ idp ⟩
-- cs n (recNiter c0 cs n) ∎
where
cs' = sucApply cs
iter' : ℕ → ℕ × C
iter' = iter (0 , c0) cs'
n' = fst (iter' n)
-- proof that the first (counter) projection of the iter version of recN at n is just n
fstIter'= : (n : ℕ) → (fst (iter (0 , c0) cs' n) == n)
fstIter'= = indN idp inductiveCase where
inductiveCase : (n : ℕ) →
fst (iter' n) == n →
fst (iter' (S n)) == S n
inductiveCase m p = S= p -- or, as spelled out below
-- fst (iter (0 , c0) cs' (S m)) =⟨ idp ⟩
-- fst (cs' (iter (0 , c0) cs' m)) =⟨ idp ⟩
-- fst (cs' (iter (0 , c0) cs' m)) =⟨ idp ⟩
-- -- fst (cs' (fst (iter (0 , c0) cs' m) , _)) =⟨ idp ⟩ -- Agda loses track of some hidden
-- -- fst (S (fst (iter (0 , c0) cs' m)) , _) =⟨ idp ⟩ -- type data here, thus double-protective comments
-- S (fst (iter (0 , c0) cs' m)) =⟨ S= p ⟩
-- S m ∎
n'= : n' == n
n'= = fstIter'= n
cs= : ∀ {n m} {c : C} → n == m → cs n c == cs m c
cs= idp = idp
-- recursor for Bool (used in next two exercises)
module RecBool where
recBool : ∀ {i} {A : Type i} → A → A → Bool → A
recBool x y true = x
recBool x y false = y
module Ex1-5 where
open RecBool
{-
Exercise 1.5. Show that if we define A + B :≡ ∑(x:2) rec2(U, A, B, x), then we can give a definition
of indA+B for which the definitional equalities stated in §1.7 hold.
-}
_+_ : ∀ {i} → Type i → Type i → Type _
A + B = Σ Bool (λ isA → recBool A B isA)
inl-+ : ∀ {i} {A B : Type i} → A → A + B
inl-+ a = true , a
inr-+ : ∀ {i} {A B : Type i} → B → A + B
inr-+ b = false , b
ind-+ : ∀ {i j} {A B : Type i} (C : A + B → Type j) →
((a : A) → C (inl-+ a)) → ((b : B) → C (inr-+ b)) →
(x : A + B) → C x
ind-+ C g1 g2 (true , a) = g1 a
ind-+ C g1 g2 (false , b) = g2 b
module Ex1-6 {i} {A B : Type i} where
open RecBool
open import FunExt
{-
Exercise 1.6. Show that if we define A × B :≡ ∏(x:2) rec2(U, A, B, x), then we can give a defini- tion of indA×B for which the definitional equalities stated in §1.5 hold propositionally (i.e. using equality types). (This requires the function extensionality axiom, which is introduced in §2.9.)
-}
_x_ : ∀ {i} → (A : Type i) → (B : Type i) → Type _
A x B = Π Bool (λ ab → recBool A B ab)
_,,_ : A → B → A x B
_,,_ a b true = a
_,,_ a b false = b
fst-x : A x B → A
fst-x ab = ab true
snd-x : A x B → B
snd-x ab = ab false
uppt-x : (ab : (A x B)) → (fst-x ab ,, snd-x ab) == ab
uppt-x ab = is-equiv.g fe h where -- (fst-x ab ,, snd-x ab) x == ab x
fe = fun-ext ((fst-x ab ,, snd-x ab)) ab
h : (c : Bool) → (fst-x ab ,, snd-x ab) c == ab c
h true = idp
h false = idp
ind-x : ∀ {j} (C : A x B → Type j) →
((a : A) → (b : B) → C (a ,, b)) →
(ab : A x B) → C ab
ind-x C g ab = transport C (uppt-x ab) (g a b) where
a = fst-x ab
b = snd-x ab
module Ex1-7 where
{-
Exercise 1.7. Give an alternative derivation of ind′=A from ind=A which avoids the use of universes. (This is easiest
using concepts from later chapters.)
-}
{-
Section 1.12.2 "we can show that ind=A entails Lemmas2.3.1 and 3.11.8, and that these two principles imply ind′=A
directly"
-}
{-
Lemma 2.3.1 (Transport). Suppose that P is a type family over A and that p : x =A y. Then there is a function
p∗ : P(x) → P(y).
-}
{-
Lemma 3.11.8. For any A and any a : A, the type ∑(x:A)(a = x) is contractible.
-}
lemma-3-11-8 : ∀ {i} {A : Type i} (a : A) → is-contr (Σ A λ x → a == x)
lemma-3-11-8 {_} {A} a = ((a , idp)) , λ { (x , p) → along {x} p } where
along : {x : A}(p : a == x) → (a , idp) == (x , p)
along idp = idp -- should really prove using ind== then ind='2 will indeed be based path induction from free
-- path induction
ind='2 : ∀ {i j} {A : Type i} {a : A} →
(D : (x : A) (p : a == x) → Type j) →
D a idp →
{x : A} (p : a == x) →
D x p
ind='2 {i} {j} {A} {a} D d {x} p = transport (λ { (x , p) → D x p}) (snd (lemma-3-11-8 a) (x , p)) d
module Ex1-14 where
{- Exercise 1.14. Why do the induction principles for identity types not allow us to construct a
function f : ∏(x:A) ∏(p:x=x)(p = reflx) with the defining equation f (x, reflx ) :≡ reflreflx ? -}
module Ex1-15 {i j} {A : Type i} {C : A → Type j} where
{- Exercise 1.15. Show that indiscernability of identicals follows from path induction. -}
f : ∀ {x y : A} (p : x == y) → C x → C y
f idp = ind== (λ x y _ → C x → C y) (λ x → λ cx → cx) idp
| {
"alphanum_fraction": 0.5067359338,
"avg_line_length": 33.7002967359,
"ext": "agda",
"hexsha": "8d53a5f50cb658e52e4063983aeb5e1c1347abe0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "aerskine/hott-ex",
"max_forks_repo_path": "Ch1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "aerskine/hott-ex",
"max_issues_repo_path": "Ch1.agda",
"max_line_length": 297,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "aerskine/hott-ex",
"max_stars_repo_path": "Ch1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4624,
"size": 11357
} |
module Types.IND where
open import Data.Nat
open import Data.Fin hiding (_+_)
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality hiding (Extensionality)
open import Types.Direction
open import Auxiliary.Extensionality
open import Auxiliary.RewriteLemmas
private
variable
m n : ℕ
----------------------------------------------------------------------
-- session type inductively with explicit rec
data Polarity : Set where
POS NEG : Polarity
mutual
data Type n : Set where
TUnit TInt : Type n
TPair : (T₁ : Type n) (T₂ : Type n) → Type n
TChan : (S : SType n) → Type n
data SType n : Set where
gdd : (G : GType n) → SType n
rec : (G : GType (suc n) ) → SType n
var : (p : Polarity) → (x : Fin n) → SType n
data GType n : Set where
transmit : (d : Dir) (T : Type n) (S : SType n) → GType n
choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n
end : GType n
TType = Type
-- weakening
weakenS : (n : ℕ) → SType m → SType (m + n)
weakenG : (n : ℕ) → GType m → GType (m + n)
weakenT : (n : ℕ) → TType m → TType (m + n)
weakenS n (gdd gst) = gdd (weakenG n gst)
weakenS n (rec gst) = rec (weakenG n gst)
weakenS n (var p x) = var p (inject+ n x)
weakenG n (transmit d t s) = transmit d (weakenT n t) (weakenS n s)
weakenG n (choice d m alt) = choice d m (weakenS n ∘ alt)
weakenG n end = end
weakenT n TUnit = TUnit
weakenT n TInt = TInt
weakenT n (TPair ty ty₁) = TPair (weakenT n ty) (weakenT n ty₁)
weakenT n (TChan x) = TChan (weakenS n x)
weaken1 : SType m → SType (suc m)
weaken1{m} stm with weakenS 1 stm
... | r rewrite n+1=suc-n {m} = r
module CheckWeaken where
s0 : SType 0
s0 = rec (transmit SND TUnit (var POS zero))
s1 : SType 1
s1 = rec (transmit SND TUnit (var POS zero))
s2 : SType 2
s2 = rec (transmit SND TUnit (var POS zero))
check-weakenS1 : weakenS 1 s0 ≡ s1
check-weakenS1 = cong rec (cong (transmit SND TUnit) refl)
check-weakenS2 : weakenS 2 s0 ≡ s2
check-weakenS2 = cong rec (cong (transmit SND TUnit) refl)
weaken1'N : Fin (suc n) → Fin n → Fin (suc n)
weaken1'N zero x = suc x
weaken1'N (suc i) zero = zero
weaken1'N (suc i) (suc x) = suc (weaken1'N i x)
weaken1'S : Fin (suc n) → SType n → SType (suc n)
weaken1'G : Fin (suc n) → GType n → GType (suc n)
weaken1'T : Fin (suc n) → TType n → TType (suc n)
weaken1'S i (gdd gst) = gdd (weaken1'G i gst)
weaken1'S i (rec gst) = rec (weaken1'G (suc i) gst)
weaken1'S i (var p x) = var p (weaken1'N i x)
weaken1'G i (transmit d t s) = transmit d (weaken1'T i t) (weaken1'S i s)
weaken1'G i (choice d m alt) = choice d m (weaken1'S i ∘ alt)
weaken1'G i end = end
weaken1'T i TUnit = TUnit
weaken1'T i TInt = TInt
weaken1'T i (TPair t₁ t₂) = TPair (weaken1'T i t₁) (weaken1'T i t₂)
weaken1'T i (TChan x) = TChan (weaken1'S i x)
weaken1S : SType n → SType (suc n)
weaken1G : GType n → GType (suc n)
weaken1T : Type n → Type (suc n)
weaken1S = weaken1'S zero
weaken1G = weaken1'G zero
weaken1T = weaken1'T zero
module CheckWeaken1' where
sxy : ∀ n → Fin (suc n) → SType n
sxy n x = rec (transmit SND TUnit (var POS x))
s00 : SType 0
s00 = sxy 0 zero
s10 : SType 1
s10 = sxy 1 zero
s11 : SType 1
s11 = sxy 1 (suc zero)
s22 : SType 2
s22 = sxy 2 (suc (suc zero))
check-weaken-s01 : weaken1'S zero s00 ≡ s10
check-weaken-s01 = refl
check-weaken-s1-s2 : weaken1'S zero s11 ≡ s22
check-weaken-s1-s2 = refl
check-weaken-s21 : weaken1'S (suc zero) (sxy 2 (suc zero)) ≡ sxy 3 (suc zero)
check-weaken-s21 = refl
--------------------------------------------------------------------
dual-pol : Polarity → Polarity
dual-pol POS = NEG
dual-pol NEG = POS
dual-pol-inv : ∀ p → dual-pol (dual-pol p) ≡ p
dual-pol-inv POS = refl
dual-pol-inv NEG = refl
swap-polS : (i : Fin (suc n)) → SType (suc n) → SType (suc n)
swap-polG : (i : Fin (suc n)) → GType (suc n) → GType (suc n)
swap-polT : (i : Fin (suc n)) → Type (suc n) → Type (suc n)
swap-polG i (transmit d t st) = transmit d (swap-polT i t) (swap-polS i st)
swap-polG i (choice d m alt) = choice d m (swap-polS i ∘ alt)
swap-polG i end = end
swap-polS i (gdd gst) = gdd (swap-polG i gst)
swap-polS i (rec st) = rec (swap-polG (suc i) st)
swap-polS zero (var p zero) = var (dual-pol p) zero
swap-polS (suc i) (var p zero) = var p zero
swap-polS zero (var p (suc x)) = var p (suc x)
swap-polS {suc n} (suc i) (var p (suc x)) = weaken1S (swap-polS i (var p x))
swap-polT i TUnit = TUnit
swap-polT i TInt = TInt
swap-polT i (TPair t₁ t₂) = TPair (swap-polT i t₁) (swap-polT i t₂)
swap-polT i (TChan x) = TChan (swap-polS i x)
--------------------------------------------------------------------
weak-weakN : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (x : Fin n)
→ weaken1'N (suc i) (weaken1'N j x) ≡ weaken1'N (inject₁ j) (weaken1'N i x)
weak-weakG : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (g : GType n)
→ weaken1'G (suc i) (weaken1'G j g) ≡ weaken1'G (inject₁ j) (weaken1'G i g)
weak-weakS : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s : SType n)
→ weaken1'S (suc i) (weaken1'S j s) ≡ weaken1'S (inject₁ j) (weaken1'S i s)
weak-weakT : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (t : Type n)
→ weaken1'T (suc i) (weaken1'T j t) ≡ weaken1'T (inject₁ j) (weaken1'T i t)
weak-weakN zero zero le x = refl
weak-weakN (suc i) zero le x = refl
weak-weakN (suc i) (suc j) (s≤s le) zero = refl
weak-weakN{suc n} (suc i) (suc j) (s≤s le) (suc x) = cong suc (weak-weakN i j le x)
weak-weakG i j le (transmit d t s) = cong₂ (transmit d) (weak-weakT i j le t) (weak-weakS i j le s)
weak-weakG i j le (choice d m alt) = cong (choice d m) (ext (weak-weakS i j le ∘ alt))
weak-weakG i j le end = refl
weak-weakS i j le (gdd gst) = cong gdd (weak-weakG i j le gst)
weak-weakS i j le (rec gst) = cong rec (weak-weakG (suc i) (suc j) (s≤s le) gst)
weak-weakS i j le (var p x) = cong (var p) (weak-weakN i j le x)
weak-weakT i j le TUnit = refl
weak-weakT i j le TInt = refl
weak-weakT i j le (TPair t t₁) = cong₂ TPair (weak-weakT i j le t) (weak-weakT i j le t₁)
weak-weakT i j le (TChan s) = cong TChan (weak-weakS i j le s)
weaken1-weakenN : (m : ℕ) (j : Fin (suc n)) (x : Fin n)
→ inject+ m (weaken1'N j x) ≡ weaken1'N (inject+ m j) (inject+ m x)
weaken1-weakenN m zero zero = refl
weaken1-weakenN m zero (suc x) = refl
weaken1-weakenN m (suc j) zero = refl
weaken1-weakenN m (suc j) (suc x) = cong suc (weaken1-weakenN m j x)
weaken1-weakenS : (m : ℕ) (j : Fin (suc n)) (s : SType n)
→ weakenS m (weaken1'S j s) ≡ weaken1'S (inject+ m j) (weakenS m s)
weaken1-weakenG : (m : ℕ) (j : Fin (suc n)) (g : GType n)
→ weakenG m (weaken1'G j g) ≡ weaken1'G (inject+ m j) (weakenG m g)
weaken1-weakenT : (m : ℕ) (j : Fin (suc n)) (t : Type n)
→ weakenT m (weaken1'T j t) ≡ weaken1'T (inject+ m j) (weakenT m t)
weaken1-weakenS m j (gdd gst) = cong gdd (weaken1-weakenG m j gst)
weaken1-weakenS m j (rec gst) = cong rec (weaken1-weakenG m (suc j) gst)
weaken1-weakenS m zero (var p zero) = refl
weaken1-weakenS m zero (var p (suc x)) = refl
weaken1-weakenS {suc n} m (suc j) (var p zero) = refl
weaken1-weakenS {suc n} m (suc j) (var p (suc x)) = cong (var p) (cong suc (weaken1-weakenN m j x))
weaken1-weakenG m j (transmit d t s) = cong₂ (transmit d) (weaken1-weakenT m j t) (weaken1-weakenS m j s)
weaken1-weakenG m j (choice d m₁ alt) = cong (choice d m₁) (ext (weaken1-weakenS m j ∘ alt))
weaken1-weakenG m j end = refl
weaken1-weakenT m j TUnit = refl
weaken1-weakenT m j TInt = refl
weaken1-weakenT m j (TPair t t₁) = cong₂ TPair (weaken1-weakenT m j t) (weaken1-weakenT m j t₁)
weaken1-weakenT m j (TChan x) = cong TChan (weaken1-weakenS m j x)
--------------------------------------------------------------------
-- weakening of later index
{-# TERMINATING #-}
swap-weaken1'G : (i : Fin (suc (suc n))) (j : Fin′ i) (gst : GType (suc n)) →
swap-polG (inject j) (weaken1'G i gst) ≡ weaken1'G i (swap-polG (inject! j) gst)
swap-weaken1'S : (i : Fin (suc (suc n))) (j : Fin′ i) (sst : SType (suc n)) →
swap-polS (inject j) (weaken1'S i sst) ≡ weaken1'S i (swap-polS (inject! j) sst)
swap-weaken1'T : (i : Fin (suc (suc n))) (j : Fin′ i) (t : Type (suc n)) →
swap-polT (inject j) (weaken1'T i t) ≡ weaken1'T i (swap-polT (inject! j) t)
swap-weaken1'G i j (transmit d t s) = cong₂ (transmit d) (swap-weaken1'T i j t) (swap-weaken1'S i j s)
swap-weaken1'G i j (choice d m alt) = cong (choice d m) (ext (swap-weaken1'S i j ∘ alt))
swap-weaken1'G i j end = refl
swap-weaken1'S i j (gdd gst) = cong gdd (swap-weaken1'G i j gst)
swap-weaken1'S i j (rec gst) = cong rec (swap-weaken1'G (suc i) (suc j) gst)
swap-weaken1'S zero () (var p x)
swap-weaken1'S (suc i) zero (var p zero) = refl
swap-weaken1'S (suc i) zero (var p (suc x)) = refl
swap-weaken1'S (suc i) (suc j) (var p zero) = refl
swap-weaken1'S{suc n} (suc i) (suc j) (var p (suc x)) rewrite (weak-weakS i zero z≤n (swap-polS (inject! j) (var p x))) =
let sws = swap-weaken1'S{n} i j (var p x) in cong (weaken1'S zero) sws
swap-weaken1'T i j TUnit = refl
swap-weaken1'T i j TInt = refl
swap-weaken1'T i j (TPair t₁ t₂) = cong₂ TPair (swap-weaken1'T i j t₁) (swap-weaken1'T i j t₂)
swap-weaken1'T i j (TChan s) = cong TChan (swap-weaken1'S i j s)
--------------------------------------------------------------------
-- weakening of earlier index
{-# TERMINATING #-}
swap-weaken1'S< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (s : SType (suc n)) →
swap-polS (suc i) (weaken1'S (inject₁ j) s) ≡ weaken1'S (inject₁ j) (swap-polS i s)
swap-weaken1'G< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (g : GType (suc n)) →
swap-polG (suc i) (weaken1'G (inject₁ j) g) ≡ weaken1'G (inject₁ j) (swap-polG i g)
swap-weaken1'T< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (t : Type (suc n)) →
swap-polT (suc i) (weaken1'T (inject₁ j) t) ≡ weaken1'T (inject₁ j) (swap-polT i t)
swap-weaken1'S< i j le (gdd gst) = cong gdd (swap-weaken1'G< i j le gst)
swap-weaken1'S< i j le (rec gst) = cong rec (swap-weaken1'G< (suc i) (suc j) (s≤s le) gst)
swap-weaken1'S< zero zero le (var p x) = refl
swap-weaken1'S< (suc i) zero le (var p x) = refl
swap-weaken1'S<{suc n} (suc i) (suc j) le (var p zero) = refl
swap-weaken1'S<{suc n} (suc i) (suc j) (s≤s le) (var p (suc x)) rewrite (weak-weakS (inject₁ j) zero z≤n (swap-polS i (var p x))) =
let sws = swap-weaken1'S<{n} i j le (var p x) in cong (weaken1'S zero) sws
swap-weaken1'G< i j le (transmit d t s) = cong₂ (transmit d) (swap-weaken1'T< i j le t) (swap-weaken1'S< i j le s)
swap-weaken1'G< i j le (choice d m alt) = cong (choice d m) (ext ((swap-weaken1'S< i j le) ∘ alt))
swap-weaken1'G< i j le end = refl
swap-weaken1'T< i j le TUnit = refl
swap-weaken1'T< i j le TInt = refl
swap-weaken1'T< i j le (TPair t t₁) = cong₂ (TPair) (swap-weaken1'T< i j le t) (swap-weaken1'T< i j le t₁)
swap-weaken1'T< i j le (TChan s) = cong (TChan) (swap-weaken1'S< i j le s)
swap-weakenS : (i : Fin (suc n)) → (s : SType (suc n)) →
swap-polS (suc i) (weaken1S s) ≡ weaken1S (swap-polS i s)
swap-weakenG : (i : Fin (suc n)) → (g : GType (suc n)) →
swap-polG (suc i) (weaken1G g) ≡ weaken1G (swap-polG i g)
swap-weakenT : (i : Fin (suc n)) → (t : Type (suc n)) →
swap-polT (suc i) (weaken1T t) ≡ weaken1T (swap-polT i t)
swap-weakenS i s = swap-weaken1'S< i zero z≤n s
swap-weakenG i g = swap-weaken1'G< i zero z≤n g
swap-weakenT i t = swap-weaken1'T< i zero z≤n t
--------------------------------------------------------------------
-- swapping of general weakening
{-# TERMINATING #-}
swap-weakenG' : (m : ℕ) (j : Fin (suc n)) (gst : GType (suc n))
→ swap-polG (inject+ m j) (weakenG m gst) ≡ weakenG m (swap-polG j gst)
swap-weakenS' : (m : ℕ) (j : Fin (suc n)) (s : SType (suc n))
→ swap-polS (inject+ m j) (weakenS m s) ≡ weakenS m (swap-polS j s)
swap-weakenT' : (m : ℕ) (j : Fin (suc n)) (t : Type (suc n))
→ swap-polT (inject+ m j) (weakenT m t) ≡ weakenT m (swap-polT j t)
swap-weakenG' m j (transmit d t s) = cong₂ (transmit d) (swap-weakenT' m j t) (swap-weakenS' m j s)
swap-weakenG' m j (choice d m₁ alt) = cong (choice d m₁) (ext (swap-weakenS' m j ∘ alt))
swap-weakenG' m j end = refl
swap-weakenS' m j (gdd gst) = cong gdd (swap-weakenG' m j gst)
swap-weakenS' m j (rec gst) = cong rec (swap-weakenG' m (suc j) gst)
swap-weakenS' m zero (var p zero) = refl
swap-weakenS' m (suc j) (var p zero) = refl
swap-weakenS' m zero (var p (suc zero)) = refl
swap-weakenS' m zero (var p (suc (suc x))) = refl
swap-weakenS' {suc n} m (suc j) (var p (suc x)) rewrite (weaken1-weakenS m zero (swap-polS j (var p x))) =
let rst = swap-weakenS'{n} m j (var p x) in cong weaken1S rst
swap-weakenT' m j TUnit = refl
swap-weakenT' m j TInt = refl
swap-weakenT' m j (TPair t t₁) = cong₂ TPair (swap-weakenT' m j t) (swap-weakenT' m j t₁)
swap-weakenT' m j (TChan x) = cong TChan (swap-weakenS' m j x)
--------------------------------------------------------------------
{-# TERMINATING #-}
swap-pol-invS : (i : Fin (suc n)) → (st : SType (suc n)) →
swap-polS i (swap-polS i st) ≡ st
swap-pol-invG : (i : Fin (suc n)) → (st : GType (suc n)) →
swap-polG i (swap-polG i st) ≡ st
swap-pol-invT : (i : Fin (suc n)) → (ty : Type (suc n)) →
swap-polT i (swap-polT i ty) ≡ ty
swap-pol-invS i (gdd gst) = cong gdd (swap-pol-invG i gst)
swap-pol-invS i (rec gst) = cong rec (swap-pol-invG (suc i) gst)
swap-pol-invS zero (var p zero) rewrite dual-pol-inv p = refl
swap-pol-invS (suc i) (var p zero) = refl
swap-pol-invS zero (var p (suc x)) rewrite dual-pol-inv p = refl
swap-pol-invS {suc n} (suc i) (var p (suc x))
rewrite swap-weakenS i (swap-polS i (var p x)) | swap-pol-invS i (var p x) = refl
-- extensionality needed
swap-pol-invG i (transmit d t s) = cong₂ (transmit d) (swap-pol-invT i t) (swap-pol-invS i s)
swap-pol-invG i (choice d m alt) = cong (choice d m) (ext R)
where R : ∀ x → swap-polS i (swap-polS i (alt x)) ≡ alt x
R x rewrite swap-pol-invS i (alt x) = refl
swap-pol-invG i end = refl
swap-pol-invT i TUnit = refl
swap-pol-invT i TInt = refl
swap-pol-invT i (TPair ty ty₁) = cong₂ TPair (swap-pol-invT i ty) (swap-pol-invT i ty₁)
swap-pol-invT i (TChan x) = cong TChan (swap-pol-invS i x)
--------------------------------------------------------------------
-- LM duality
dualS : SType n → SType n
dualG : GType n → GType n
dualG (transmit d t st) = transmit (dual-dir d) t (dualS st)
dualG (choice d m alt) = choice (dual-dir d) m (dualS ∘ alt)
dualG end = end
dualS (gdd gst) = gdd (dualG gst)
dualS (rec gst) = rec (swap-polG zero (dualG gst))
dualS (var p x) = var (dual-pol p) x
--------------------------------------------------------------------
dual-weakenS : (i : Fin (suc n)) (s : SType n) → dualS (weaken1'S i s) ≡ weaken1'S i (dualS s)
dual-weakenG : (i : Fin (suc n)) (g : GType n) → dualG (weaken1'G i g) ≡ weaken1'G i (dualG g)
dual-weakenS i (gdd gst) = cong gdd (dual-weakenG i gst)
dual-weakenS i (rec gst) rewrite (sym (swap-weaken1'G (suc i) zero (dualG gst))) = cong rec (cong (swap-polG zero) (dual-weakenG (suc i) gst))
dual-weakenS i (var p x) = refl
dual-weakenG i (transmit d t s) = cong₂ (transmit (dual-dir d)) refl (dual-weakenS i s)
dual-weakenG i (choice d m alt) = cong (choice (dual-dir d) m) (ext (dual-weakenS i ∘ alt))
dual-weakenG i end = refl
dual-weakenS' : (m : ℕ) (s : SType n) → dualS (weakenS m s) ≡ weakenS m (dualS s)
dual-weakenG' : (m : ℕ) (g : GType n) → dualG (weakenG m g) ≡ weakenG m (dualG g)
dual-weakenS' n (gdd gst) = cong gdd (dual-weakenG' n gst)
dual-weakenS' n (rec gst) rewrite (sym (swap-weakenG' n zero (dualG gst))) = cong rec (cong (swap-polG zero) (dual-weakenG' n gst))
dual-weakenS' n (var p x) = refl
dual-weakenG' n (transmit d t s) = cong₂ (transmit (dual-dir d)) refl (dual-weakenS' n s)
dual-weakenG' n (choice d m alt) = cong (choice (dual-dir d) m) (ext (dual-weakenS' n ∘ alt))
dual-weakenG' n end = refl
--------------------------------------------------------------------
aux : (i : Fin n) (x : Fin n) (p' : Polarity) →
var p' (suc (suc x)) ≡ weaken1S (var p' (suc x))
aux i x p = refl
var-suc : (i : Fin n) (x : Fin n) (p : Polarity) →
∃ λ p' → swap-polS (suc i) (var p (suc x)) ≡ var p' (suc x)
var-suc zero zero p = dual-pol p , refl
var-suc (suc i) zero p = p , refl
var-suc zero (suc x) p = p , refl
var-suc (suc i) (suc x) p
with var-suc i x p
... | p' , snd
rewrite sym (aux i x p') = p' , cong weaken1S snd
--------------------------------------------------------------------
{-# TERMINATING #-}
swap-swapG : (gst : GType (suc n)) → (i : Fin (suc n)) (j : Fin′ i) →
swap-polG i (swap-polG (inject j) gst) ≡ swap-polG (inject j) (swap-polG i gst)
swap-swapT : (t : Type (suc n)) → (i : Fin (suc n)) (j : Fin′ i) →
swap-polT i (swap-polT (inject j) t) ≡ swap-polT (inject j) (swap-polT i t)
swap-swapS : (st : SType (suc n)) → (i : Fin (suc n)) (j : Fin′ i) →
swap-polS i (swap-polS (inject j) st) ≡ swap-polS (inject j) (swap-polS i st)
swap-swapG (transmit d t s) i j = cong₂ (transmit d) (swap-swapT t i j) (swap-swapS s i j)
swap-swapG (choice d m alt) i j = cong (choice d m) (ext (λ x → swap-swapS (alt x) i j))
swap-swapG end i j = refl
swap-swapT TUnit i j = refl
swap-swapT TInt i j = refl
swap-swapT (TPair t t₁) i j = cong₂ TPair (swap-swapT t i j) (swap-swapT t₁ i j)
swap-swapT (TChan x) i j = cong TChan (swap-swapS x i j)
swap-swapS (gdd gst) i j = cong gdd (swap-swapG gst i j)
swap-swapS (rec gst) i j = cong rec (swap-swapG gst (suc i) (suc j))
swap-swapS (var p zero) zero ()
swap-swapS (var p zero) (suc i) zero = refl
swap-swapS (var p zero) (suc i) (suc j) = refl
swap-swapS (var p (suc x)) zero ()
swap-swapS (var p (suc x)) (suc i) zero
with var-suc i x p
... | p' , snd rewrite snd = refl
swap-swapS {suc n} (var p (suc x)) (suc i) (suc j)
rewrite swap-weakenS i (swap-polS (inject j) (var p x))
with swap-swapS (var p x) i j
... | pxij rewrite swap-weakenS (inject j) (swap-polS i (var p x))
= cong weaken1S pxij
{-# TERMINATING #-}
swap-pol-dualG : (i : Fin (suc n)) (gst : GType (suc n)) →
swap-polG i (dualG gst) ≡ dualG (swap-polG i gst)
swap-pol-dualS : (i : Fin (suc n)) (st : SType (suc n)) →
swap-polS i (dualS st) ≡ dualS (swap-polS i st)
swap-pol-dualG i (transmit d t s) = cong (transmit _ (swap-polT i t)) (swap-pol-dualS i s)
swap-pol-dualG i (choice d m alt) = cong (choice _ _) (ext (swap-pol-dualS i ∘ alt))
swap-pol-dualG i end = refl
swap-pol-dualS i (gdd gst) = cong gdd (swap-pol-dualG i gst)
swap-pol-dualS i (rec gst) rewrite sym (swap-pol-dualG (suc i) gst) =
cong rec (swap-swapG (dualG gst) (suc i) zero)
swap-pol-dualS zero (var p zero) = refl
swap-pol-dualS (suc i) (var p zero) = refl
swap-pol-dualS zero (var p (suc x)) = refl
swap-pol-dualS {suc n} (suc i) (var p (suc x))
rewrite (dual-weakenS zero (swap-polS i (var p x))) = cong weaken1S (swap-pol-dualS i (var p x))
--------------------------------------------------------------------
dual-invS : (st : SType n) → st ≡ dualS (dualS st)
dual-invG : (gst : GType n) → gst ≡ dualG (dualG gst)
dual-invS (gdd gst) = cong gdd (dual-invG gst)
dual-invS (rec gst) rewrite sym (swap-pol-dualG zero (dualG gst)) | swap-pol-invG zero (dualG (dualG gst)) = cong rec (dual-invG gst)
dual-invS (var p x) rewrite dual-pol-inv p = refl
dual-invG (transmit d t s) rewrite dual-dir-inv d = cong₂ (transmit d) refl (dual-invS s)
dual-invG (choice d m alt) rewrite dual-dir-inv d = cong (choice d m) (ext R)
where R : (x : Fin m) → alt x ≡ dualS (dualS (alt x))
R x rewrite sym (dual-invS (alt x)) = refl
dual-invG end = refl
dual-if : Polarity → SType n → SType n
dual-if POS s = s
dual-if NEG s = dualS s
dual-if-dual : (p : Polarity) (ist : SType 0) → dual-if p ist ≡ dual-if (dual-pol p) (dualS ist)
dual-if-dual POS ist = (dual-invS ist)
dual-if-dual NEG ist = refl
--------------------------------------------------------------------
-- substitution
st-substS : SType (suc n) → Fin (suc n) → SType 0 → SType n
st-substG : GType (suc n) → Fin (suc n) → SType 0 → GType n
st-substT : Type (suc n) → Fin (suc n) → SType 0 → Type n
st-substS (gdd gst) i st0 = gdd (st-substG gst i st0)
st-substS (rec gst) i st0 = rec (st-substG gst (suc i) st0)
st-substS {n} (var p zero) zero st0 = weakenS n (dual-if p st0)
st-substS {suc n} (var p zero) (suc i) st0 = var p zero
st-substS {suc n} (var p (suc x)) zero st0 = var p x
st-substS {suc n} (var p (suc x)) (suc i) st0 = weaken1S (st-substS (var p x) i st0)
st-substG (transmit d t s) i st0 = transmit d (st-substT t i st0) (st-substS s i st0)
st-substG (choice d m alt) i st0 = choice d m (λ j → st-substS (alt j) i st0)
st-substG end i st0 = end
st-substT TUnit i st0 = TUnit
st-substT TInt i st0 = TInt
st-substT (TPair ty ty₁) i st0 = TPair (st-substT ty i st0) (st-substT ty₁ i st0)
st-substT (TChan st) i st0 = TChan (st-substS st i st0)
--------------------------------------------------------------------
trivial-subst-var : (p : Polarity) (x : Fin n) (ist₁ ist₂ : SType 0)
→ st-substS (var p (suc x)) zero ist₁ ≡ st-substS (var p (suc x)) zero ist₂
trivial-subst-var p zero ist1 ist2 = refl
trivial-subst-var p (suc x) ist1 ist2 = refl
trivial-subst-var' : (p : Polarity) (i : Fin n) (ist₁ ist₂ : SType 0)
→ st-substS (var p zero) (suc i) ist₁ ≡ st-substS (var p zero) (suc i) ist₂
trivial-subst-var' p zero ist1 ist2 = refl
trivial-subst-var' p (suc x) ist1 ist2 = refl
--------------------------------------------------------------------
-- equivalence
variable
t t₁ t₂ t₁' t₂' : Type n
s s₁ s₂ : SType n
g g₁ g₂ : GType n
unfold : SType 0 → GType 0
unfold (gdd gst) = gst
unfold (rec gst) = st-substG gst zero (rec gst)
-- type equivalence
data EquivT (R : SType n → SType n → Set) : Type n → Type n → Set where
eq-unit : EquivT R TUnit TUnit
eq-int : EquivT R TInt TInt
eq-pair : EquivT R t₁ t₁' → EquivT R t₂ t₂' → EquivT R (TPair t₁ t₂) (TPair t₁' t₂')
eq-chan : R s₁ s₂ → EquivT R (TChan s₁) (TChan s₂)
-- session type equivalence
data EquivG (R : SType n → SType n → Set) : GType n → GType n → Set where
eq-transmit : (d : Dir) → EquivT R t₁ t₂ → R s₁ s₂ → EquivG R (transmit d t₁ s₁) (transmit d t₂ s₂)
eq-choice : ∀ {alt alt'} → (d : Dir) → ((i : Fin m) → R (alt i) (alt' i)) → EquivG R (choice d m alt) (choice d m alt')
eq-end : EquivG R end end
record Equiv (s₁ s₂ : SType 0) : Set where
coinductive
field force : EquivG Equiv (unfold s₁) (unfold s₂)
open Equiv
_≈_ = Equiv
_≈'_ = EquivG Equiv
_≈ᵗ_ = EquivT Equiv
-- reflexive
≈-refl : s ≈ s
≈'-refl : g ≈' g
≈ᵗ-refl : t ≈ᵗ t
force (≈-refl {s}) = ≈'-refl
≈'-refl {transmit d t s} = eq-transmit d ≈ᵗ-refl ≈-refl
≈'-refl {choice d m alt} = eq-choice d (λ i → ≈-refl)
≈'-refl {end} = eq-end
≈ᵗ-refl {TUnit} = eq-unit
≈ᵗ-refl {TInt} = eq-int
≈ᵗ-refl {TPair t t₁} = eq-pair ≈ᵗ-refl ≈ᵗ-refl
≈ᵗ-refl {TChan x} = eq-chan ≈-refl
-- symmetric
≈-symm : s₁ ≈ s₂ → s₂ ≈ s₁
≈'-symm : g₁ ≈' g₂ → g₂ ≈' g₁
≈ᵗ-symm : t₁ ≈ᵗ t₂ → t₂ ≈ᵗ t₁
force (≈-symm s₁≈s₂) = ≈'-symm (force s₁≈s₂)
≈'-symm (eq-transmit d x x₁) = eq-transmit d (≈ᵗ-symm x) (≈-symm x₁)
≈'-symm (eq-choice d x) = eq-choice d (≈-symm ∘ x)
≈'-symm eq-end = eq-end
≈ᵗ-symm eq-unit = eq-unit
≈ᵗ-symm eq-int = eq-int
≈ᵗ-symm (eq-pair t₁≈ᵗt₂ t₁≈ᵗt₃) = eq-pair (≈ᵗ-symm t₁≈ᵗt₂) (≈ᵗ-symm t₁≈ᵗt₃)
≈ᵗ-symm (eq-chan x) = eq-chan (≈-symm x)
| {
"alphanum_fraction": 0.5956372279,
"avg_line_length": 40.5559380379,
"ext": "agda",
"hexsha": "4d60a5b5789108b822ca5566e0982c9ae49e5ed4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-07T16:12:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-07T16:12:50.000Z",
"max_forks_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "peterthiemann/dual-session",
"max_forks_repo_path": "src/Types/IND.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "peterthiemann/dual-session",
"max_issues_repo_path": "src/Types/IND.agda",
"max_line_length": 142,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "peterthiemann/dual-session",
"max_stars_repo_path": "src/Types/IND.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T05:43:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-13T05:43:25.000Z",
"num_tokens": 9588,
"size": 23563
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to Pointwise
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Functional.Relation.Binary.Pointwise.Properties where
open import Data.Fin.Base
open import Data.Fin.Properties
hiding (isDecEquivalence; setoid; decSetoid)
open import Data.Nat.Base
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Data.Product.Relation.Binary.Pointwise.NonDependent
using () renaming (Pointwise to ×-Pointwise)
open import Data.Sum.Base using (_⊎_; inj₁; inj₂; [_,_])
open import Data.Vec.Functional as VF hiding (map)
open import Data.Vec.Functional.Relation.Binary.Pointwise
open import Function
open import Level using (Level)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
private
variable
a a′ a″ b b′ b″ r s t ℓ : Level
A : Set a
B : Set b
A′ : Set a′
B′ : Set b′
A″ : Set a″
B″ : Set b″
------------------------------------------------------------------------
-- Relational properties
module _ {R : Rel A ℓ} where
refl : Reflexive R → ∀ {n} → Reflexive (Pointwise R {n})
refl r i = r
sym : Symmetric R → ∀ {n} → Symmetric (Pointwise R {n})
sym s xsys i = s (xsys i)
trans : Transitive R → ∀ {n} → Transitive (Pointwise R {n})
trans t xsys yszs i = t (xsys i) (yszs i)
decidable : Decidable R → ∀ {n} → Decidable (Pointwise R {n})
decidable r? xs ys = all? λ i → r? (xs i) (ys i)
------------------------------------------------------------------------
-- Structures
isEquivalence : IsEquivalence R → ∀ n → IsEquivalence (Pointwise R {n})
isEquivalence isEq n = record
{ refl = refl Eq.refl
; sym = sym Eq.sym
; trans = trans Eq.trans
} where module Eq = IsEquivalence isEq
isDecEquivalence : IsDecEquivalence R →
∀ n → IsDecEquivalence (Pointwise R {n})
isDecEquivalence isDecEq n = record
{ isEquivalence = isEquivalence Eq.isEquivalence n
; _≟_ = decidable Eq._≟_
} where module Eq = IsDecEquivalence isDecEq
------------------------------------------------------------------------
-- Bundles
setoid : Setoid a ℓ → ℕ → Setoid a ℓ
setoid S n = record
{ isEquivalence = isEquivalence S.isEquivalence n
} where module S = Setoid S
decSetoid : DecSetoid a ℓ → ℕ → DecSetoid a ℓ
decSetoid S n = record
{ isDecEquivalence = isDecEquivalence S.isDecEquivalence n
} where module S = DecSetoid S
------------------------------------------------------------------------
-- map
module _ {R : REL A B r} {S : REL A′ B′ s} {f : A → A′} {g : B → B′} where
map⁺ : (∀ {x y} → R x y → S (f x) (g y)) →
∀ {n} {xs : Vector A n} {ys : Vector B n} →
Pointwise R xs ys → Pointwise S (VF.map f xs) (VF.map g ys)
map⁺ f rs i = f (rs i)
------------------------------------------------------------------------
-- head
module _ (R : REL A B r) {n} {xs : Vector A (suc n)} {ys} where
head⁺ : Pointwise R xs ys → R (head xs) (head ys)
head⁺ rs = rs zero
------------------------------------------------------------------------
-- tail
module _ (R : REL A B r) {n} {xs : Vector A (suc n)} {ys} where
tail⁺ : Pointwise R xs ys → Pointwise R (tail xs) (tail ys)
tail⁺ rs = rs ∘ suc
------------------------------------------------------------------------
-- _++_
module _ (R : REL A B r) where
++⁺ : ∀ {m n xs ys xs′ ys′} →
Pointwise R {n = m} xs ys → Pointwise R {n = n} xs′ ys′ →
Pointwise R (xs ++ xs′) (ys ++ ys′)
++⁺ {m} rs rs′ i with splitAt m i
... | inj₁ i′ = rs i′
... | inj₂ j′ = rs′ j′
++⁻ˡ : ∀ {m n} (xs : Vector A m) (ys : Vector B m) {xs′ ys′} →
Pointwise R (xs ++ xs′) (ys ++ ys′) → Pointwise R xs ys
++⁻ˡ {m} {n} _ _ rs i with rs (inject+ n i)
... | r rewrite splitAt-inject+ m n i = r
++⁻ʳ : ∀ {m n} (xs : Vector A m) (ys : Vector B m) {xs′ ys′} →
Pointwise R (xs ++ xs′) (ys ++ ys′) → Pointwise R xs′ ys′
++⁻ʳ {m} {n} _ _ rs i with rs (raise m i)
... | r rewrite splitAt-raise m n i = r
++⁻ : ∀ {m n} xs ys {xs′ ys′} →
Pointwise R (xs ++ xs′) (ys ++ ys′) →
Pointwise R {n = m} xs ys × Pointwise R {n = n} xs′ ys′
++⁻ _ _ rs = ++⁻ˡ _ _ rs , ++⁻ʳ _ _ rs
------------------------------------------------------------------------
-- replicate
module _ {R : REL A B r} {x y n} where
replicate⁺ : R x y → Pointwise R {n = n} (replicate x) (replicate y)
replicate⁺ = const
------------------------------------------------------------------------
-- _⊛_
module _ {R : REL A B r} {S : REL A′ B′ s} {n} where
⊛⁺ : ∀ {fs : Vector (A → A′) n} {gs : Vector (B → B′) n} →
Pointwise (λ f g → ∀ {x y} → R x y → S (f x) (g y)) fs gs →
∀ {xs ys} → Pointwise R xs ys → Pointwise S (fs ⊛ xs) (gs ⊛ ys)
⊛⁺ rss rs i = (rss i) (rs i)
------------------------------------------------------------------------
-- zipWith
module _ {R : REL A B r} {S : REL A′ B′ s} {T : REL A″ B″ t} where
zipWith⁺ : ∀ {n xs ys xs′ ys′ f f′} →
(∀ {x y x′ y′} → R x y → S x′ y′ → T (f x x′) (f′ y y′)) →
Pointwise R xs ys → Pointwise S xs′ ys′ →
Pointwise T (zipWith f xs xs′) (zipWith f′ {n = n} ys ys′)
zipWith⁺ t rs ss i = t (rs i) (ss i)
------------------------------------------------------------------------
-- zip
module _ {R : REL A B r} {S : REL A′ B′ s} {n xs ys xs′ ys′} where
zip⁺ : Pointwise R xs ys → Pointwise S xs′ ys′ →
Pointwise (λ xx yy → R (proj₁ xx) (proj₁ yy) × S (proj₂ xx) (proj₂ yy))
(zip xs xs′) (zip {n = n} ys ys′)
zip⁺ rs ss i = rs i , ss i
zip⁻ : Pointwise (λ xx yy → R (proj₁ xx) (proj₁ yy) × S (proj₂ xx) (proj₂ yy))
(zip xs xs′) (zip {n = n} ys ys′) →
Pointwise R xs ys × Pointwise S xs′ ys′
zip⁻ rss = proj₁ ∘ rss , proj₂ ∘ rss
------------------------------------------------------------------------
-- foldr
module _ {R : REL A B r} {S : REL A′ B′ s}
{f : A → A′ → A′} {g : B → B′ → B′}
where
foldr-cong : (∀ {w x y z} → R w x → S y z → S (f w y) (g x z)) →
∀ {d : A′} {e : B′} → S d e →
∀ {n} {xs : Vector A n} {ys : Vector B n} →
Pointwise R xs ys → S (foldr f d xs) (foldr g e ys)
foldr-cong fg-cong d~e {zero} rss = d~e
foldr-cong fg-cong d~e {suc n} rss =
fg-cong (rss zero) (foldr-cong fg-cong d~e (rss ∘ suc))
| {
"alphanum_fraction": 0.4640562863,
"avg_line_length": 33.7010309278,
"ext": "agda",
"hexsha": "f961e2f11883f773ed60d77aa430b0dd41005af0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Vec/Functional/Relation/Binary/Pointwise/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Vec/Functional/Relation/Binary/Pointwise/Properties.agda",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Vec/Functional/Relation/Binary/Pointwise/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 2145,
"size": 6538
} |
-- Syntax: Types, terms and contexts.
module Syntax where
open import Library
infixr 6 _⇒_
infixr 4 _,_
-- Types and contexts.
data Ty : Set where
★ : Ty
_⇒_ : (a b : Ty) → Ty
data Cxt : Set where
ε : Cxt
_,_ : (Γ : Cxt) (a : Ty) → Cxt
-- Variables and terms.
data Var : (Γ : Cxt) (a : Ty) → Set where
zero : ∀ {Γ a} → Var (Γ , a) a
suc : ∀ {Γ a b} (x : Var Γ a) → Var (Γ , b) a
data Tm (Γ : Cxt) : (a : Ty) → Set where
var : ∀ {a} (x : Var Γ a) → Tm Γ a
abs : ∀ {a b} (t : Tm (Γ , a) b) → Tm Γ (a ⇒ b)
app : ∀ {a b} (t : Tm Γ (a ⇒ b)) (u : Tm Γ a) → Tm Γ b
-- Generalized neutral terms.
data GNe (Arg : Cxt → Ty → Set) (Γ : Cxt) : Ty → Set where
var : ∀{a} (x : Var Γ a) → GNe Arg Γ a
app : ∀{a b} (n : GNe Arg Γ (a ⇒ b)) (o : Arg Γ a) → GNe Arg Γ b
-- βη-normal forms.
mutual
Ne = GNe Nf
data Nf (Γ : Cxt) : Ty → Set where
abs : ∀{a b} (o : Nf (Γ , a) b) → Nf Γ (a ⇒ b)
ne : (n : Ne Γ ★) → Nf Γ ★
mutual
embNe : ∀{Γ a} → Ne Γ a → Tm Γ a
embNe (var x) = var x
embNe (app t u) = app (embNe t) (embNf u)
embNf : ∀{Γ a} → Nf Γ a → Tm Γ a
embNf (ne t) = embNe t
embNf (abs t) = abs (embNf t)
| {
"alphanum_fraction": 0.4544728435,
"avg_line_length": 22.7636363636,
"ext": "agda",
"hexsha": "089827c2d45d05002a3ba97492956dae91a8500e",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda/Syntax.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda/Syntax.agda",
"max_line_length": 67,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 560,
"size": 1252
} |
open import Data.Nat using ( ℕ ) renaming ( zero to zero' ; suc to suc' )
open import Data.Nat.GeneralisedArithmetic using ( fold )
open import Data.String using ( String )
module Data.Natural.Primitive where
infixl 6 _+_
postulate
Natural : Set
zero : Natural
suc : Natural → Natural
_+_ : Natural → Natural → Natural
show : Natural → String
foldl : {A : Set} → (A → A) → A → Natural → A
foldl' : {A : Set} → (A → A) → A → Natural → A
foldr : {A : Set} → (A → A) → A → Natural → A
{-# FOREIGN GHC import qualified Data.Natural.AgdaFFI #-}
{-# COMPILE GHC Natural = type Data.Natural.AgdaFFI.Natural #-}
{-# COMPILE GHC zero = 0 #-}
{-# COMPILE GHC suc = succ #-}
{-# COMPILE GHC _+_ = (+) #-}
{-# COMPILE GHC show = show #-}
{-# COMPILE GHC foldl = (\ _ -> Data.Natural.AgdaFFI.nfoldl) #-}
{-# COMPILE GHC foldl' = (\ _ -> Data.Natural.AgdaFFI.nfoldl') #-}
{-# COMPILE GHC foldr = (\ _ -> Data.Natural.AgdaFFI.nfoldr) #-}
private
postulate
# : ∀ {i} {A : Set i} → A → Natural
{-# COMPILE GHC # = (\ _ _ -> Data.Natural.AgdaFFI.convert MAlonzo.Data.Nat.mazNatToInteger) #-}
fromℕ : ℕ → Natural
fromℕ = #
| {
"alphanum_fraction": 0.6164021164,
"avg_line_length": 31.5,
"ext": "agda",
"hexsha": "2e42267ccc5d3f4ad4c73f7c1c36323121e9b8fb",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "121d6c66cba34b4c15b437366b80c65dd2b02a8d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-system-io",
"max_forks_repo_path": "src/Data/Natural/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "121d6c66cba34b4c15b437366b80c65dd2b02a8d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-system-io",
"max_issues_repo_path": "src/Data/Natural/Primitive.agda",
"max_line_length": 96,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "121d6c66cba34b4c15b437366b80c65dd2b02a8d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-system-io",
"max_stars_repo_path": "src/Data/Natural/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 363,
"size": 1134
} |
-- Mutual Recursion.
module MutRec where
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
data Odd : Set
data Even : Set where
e0 : Even
eS : Odd → Even
data Odd where
oS : Even → Odd
addEO : Even → Odd → Odd
addOO : Odd → Odd → Even
addOO (oS m) n = eS (addEO m n)
addEO e0 n = n
addEO (eS m) n = oS (addOO m n)
_ : addEO (eS (oS e0)) (oS e0) ≡ oS (eS (oS e0))
_ = refl
| {
"alphanum_fraction": 0.6271604938,
"avg_line_length": 15.5769230769,
"ext": "agda",
"hexsha": "fc1d6aecbce27180cff1f5b40ab6b13d204fb71f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "anqurvanillapy/fpl",
"max_forks_repo_path": "agda/MutRec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "anqurvanillapy/fpl",
"max_issues_repo_path": "agda/MutRec.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "anqurvanillapy/fpl",
"max_stars_repo_path": "agda/MutRec.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z",
"num_tokens": 154,
"size": 405
} |
module Esterel.Lang.Binding where
open import utility
open import Data.List
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.Bool
using (Bool ; true ; false ; if_then_else_)
open import Esterel.Lang
open import Esterel.Environment as Env
using (Env ; VarList ; Dom ; Θ ; _←_)
open import Esterel.Context
using (Context1 ; EvaluationContext1 ; _≐_⟦_⟧e ; _⟦_⟧e ; _≐_⟦_⟧c ; _⟦_⟧c)
open import Esterel.Context.Properties
using (plug)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ) renaming (_≟ₛₜ_ to _≟ₛₜₛ_ ; unwrap to Sunwrap)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ) renaming (_≟ₛₜ_ to _≟ₛₜₛₕ_ ; unwrap to sunwrap)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ) renaming (unwrap to vunwrap)
open import Data.Product
using (_×_ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; ∃ ; Σ)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; _≟_ ; zero ; suc)
open import Relation.Nullary
using (Dec ; yes ; no ; ¬_)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Binary
using (Decidable)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; setoid)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Data.Bool
using (not)
open import Data.List.Any as ListAny
using (Any ; any ; here ; there)
open import Data.List.Any.Properties using (∷↔)
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open ListSet Data.Nat._≟_
open _≐_⟦_⟧e
open _≐_⟦_⟧c
open Context1
open EvaluationContext1
base : VarList
base = [] ,′ [] ,′ []
+S : Signal -> VarList -> VarList
+S S' (S , s , v) = ((Sunwrap S') ∷ S , s , v)
+s : SharedVar -> VarList -> VarList
+s s' (S , s , v) = (S , sunwrap s' ∷ s , v)
+x : SeqVar -> VarList -> VarList
+x x' (S , s , v) = (S , s , vunwrap x' ∷ v)
Xs : VarList -> List ℕ
Xs (_ , _ , v) = v
Ss : VarList -> List ℕ
Ss (S , _ , _) = S
FVₑ : Expr -> VarList
FVₑ (plus []) = base
FVₑ (plus (num x ∷ x₁)) = FVₑ (plus x₁)
FVₑ (plus (seq-ref x ∷ x₁)) = +x x (FVₑ (plus x₁))
FVₑ (plus (shr-ref s ∷ x₁)) = +s s (FVₑ (plus x₁))
dist++ˡ : ∀{VL1 VL2 VL3} → (distinct VL1 (VL2 U̬ VL3)) → (distinct VL1 VL2)
dist++ˡ (a , b , c) = (dist'++ˡ a) ,(dist'++ˡ b) ,(dist'++ˡ c)
dist++ʳ : ∀{VL1 VL2 VL3} → (distinct VL1 (VL2 U̬ VL3)) → (distinct VL1 VL3)
dist++ʳ{VL1}{VL2 = (v1 , v2 , v3)}{VL3 = (V1 , V2 , V3)} (a , b , c)
= (dist'++ʳ{V2 = v1}{V3 = V1} a) , (dist'++ʳ{V2 = v2}{V3 = V2} b) , (dist'++ʳ{V2 = v3}{V3 = V3} c)
dist++b : ∀{VL1 VL2 VL3 VL4} → (distinct (VL1 U̬ VL2) (VL3 U̬ VL4)) → (distinct VL1 VL3)
dist++b (a , b , c) = (dist'++b a) , (dist'++b b) , (dist'++b c)
dist:: : ∀{VL1 VL2 S} → (distinct VL1 (+S S VL2)) → (distinct VL1 VL2)
dist::{VL1}{(Ss , s , v)}{S} (a , b , c) = dist':: a , b , c
{- This definition of CorrectBinding accumulates the bound
and free variables to make it easier to work with.
The definition of `CB` (below) matches the one in the paper. -}
data CorrectBinding : Term → (BV : VarList) → (FV : VarList) → Set where
CBnothing : CorrectBinding nothin base base
CBpause : CorrectBinding pause base base
CBsig : ∀{p S BV FV} → CorrectBinding p BV FV
→ CorrectBinding (signl S p) (+S S BV) (FV |̌ (+S S base))
CBpresent : ∀{S p q BVp FVp BVq FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ CorrectBinding (present S ∣⇒ p ∣⇒ q) (BVp U̬ BVq) (+S S (FVp U̬ FVq))
CBemit : ∀{S} → CorrectBinding (emit S) base (+S S base)
CBpar : ∀{p q BVp FVp BVq FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ (BVp≠BVq : distinct BVp BVq)
→ (FVp≠BVq : distinct FVp BVq)
→ (BVp≠FVq : distinct BVp FVq)
→ (Xp≠Xq : distinct' (Xs FVp) (Xs FVq))
→ CorrectBinding (p ∥ q) (BVp U̬ BVq) (FVp U̬ FVq)
CBloop : ∀{p BV FV}
→ CorrectBinding p BV FV
→ (BV≠FV : distinct BV FV)
→ CorrectBinding (loop p) BV FV
CBloopˢ : ∀{p q BVp FVp BVq FVq}
→ CorrectBinding p BVp FVp
→ CorrectBinding q BVq FVq
→ (BVp≠FVq : distinct BVp FVq)
→ (BVq≠FVq : distinct BVq FVq)
→ CorrectBinding (loopˢ p q) (BVp U̬ BVq) (FVp U̬ FVq)
CBseq : ∀{p q BVp BVq FVp FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ (BVp≠FVq : distinct BVp FVq)
→ CorrectBinding (p >> q) (BVp U̬ BVq) (FVp U̬ FVq)
CBsusp : ∀{S p BV FV}
→ (cbp : CorrectBinding p BV FV)
→ ([S]≠BVp : distinct' [ (Sunwrap S) ] (Ss BV))
→ CorrectBinding (suspend p S) BV (+S S FV)
CBexit : ∀{n} → CorrectBinding (exit n) base base
CBtrap : ∀{p BV FV} → CorrectBinding p BV FV → CorrectBinding (trap p) BV FV
CBshared : ∀{s e p BV FV} → CorrectBinding p BV FV
→ CorrectBinding (shared s ≔ e in: p)
(+s s BV) ((FVₑ e) U̬ (FV |̌ (+s s base)))
CBsset : ∀{s e} → CorrectBinding (s ⇐ e) base (+s s (FVₑ e))
CBvar : ∀{x e p BV FV} → CorrectBinding p BV FV
→ CorrectBinding (var x ≔ e in: p)
(+x x BV) ((FVₑ e) U̬ (FV |̌ (+x x base)))
CBvset : ∀{x e} → CorrectBinding (x ≔ e) base (+x x (FVₑ e))
CBif : ∀{x p q BVp BVq FVp FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ CorrectBinding (if x ∣⇒ p ∣⇒ q) (BVp U̬ BVq) (+x x (FVp U̬ FVq))
CBρ : ∀{θ A p BV FV} → CorrectBinding p BV FV
→ CorrectBinding (ρ⟨ θ , A ⟩· p) (((Dom θ) U̬ BV)) (FV |̌ (Dom θ))
binding-is-function : ∀{p BV₁ FV₁ BV₂ FV₂} →
CorrectBinding p BV₁ FV₁ →
CorrectBinding p BV₂ FV₂ →
BV₁ ≡ BV₂ × FV₁ ≡ FV₂
binding-is-function CBnothing CBnothing = refl , refl
binding-is-function CBpause CBpause = refl , refl
binding-is-function (CBsig cb₁) (CBsig cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function (CBpresent cbp₁ cbq₁) (CBpresent cbp₂ cbq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function CBemit CBemit = refl , refl
binding-is-function (CBpar cbp₁ cbq₁ BVp≠BVq₁ FVp≠BVq₁ BVp≠FVq₁ Xp≠Xq₁)
(CBpar cbp₂ cbq₂ BVp≠BVq₂ FVp≠BVq₂ BVp≠FVq₂ Xp≠Xq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBloop cb₁ BV≠FV₁)
(CBloop cb₂ BV≠FVV₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function (CBloopˢ cbp₁ cbq₁ BVp≠FVq₁ BVq≠FVq₁)
(CBloopˢ cbp₂ cbq₂ BVp≠FVq₂ BVq≠FVq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBseq cbp₁ cbq₁ BV≠FV₁) (CBseq cbp₂ cbq₂ BV≠FV₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBsusp cb₁ S∉BV₁) (CBsusp cb₂ S∉BV₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function CBexit CBexit = refl , refl
binding-is-function (CBtrap cb₁) (CBtrap cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function (CBshared cb₁) (CBshared cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function CBsset CBsset = refl , refl
binding-is-function (CBvar cb₁) (CBvar cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function CBvset CBvset = refl , refl
binding-is-function (CBif cbp₁ cbq₁) (CBif cbp₂ cbq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBρ cb₁) (CBρ cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-dec : ∀ p → Dec (∃ \ BV -> ∃ \ FV -> CorrectBinding p BV FV)
binding-dec nothin = yes (base , base , CBnothing)
binding-dec pause = yes (base , base , CBpause)
binding-dec (signl S p) with binding-dec p
binding-dec (signl S p) | yes (BV , FV , CBp) =
yes (+S S BV , (FV |̌ (+S S base)) , CBsig CBp)
binding-dec (signl S p) | no ¬p = no (\ { (BV , FV , CBsig proj₃) → ¬p (_ , _ , proj₃) })
binding-dec (present S ∣⇒ p ∣⇒ q) with binding-dec p
binding-dec (present S ∣⇒ p ∣⇒ q) | yes p₂ with binding-dec q
binding-dec (present S ∣⇒ p ∣⇒ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) =
yes (BVp U̬ BVq , +S S (FVp U̬ FVq) , CBpresent CBp CBq)
binding-dec (present S ∣⇒ p ∣⇒ p₁) | yes p₂ | (no ¬p) =
no (\ { (BV , FV , CBpresent BD BD₁) → ¬p (_ , _ , BD₁) } )
binding-dec (present S ∣⇒ p ∣⇒ p₁) | no ¬p =
no (\ { (BV , FV , CBpresent BD BD₁) → ¬p (_ , _ , BD) } )
binding-dec (emit S) = yes (base , (Sunwrap S ∷ [] , [] , []) , CBemit)
binding-dec (p ∥ q) with binding-dec p
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) with binding-dec q
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) with distinct-dec BVp BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | yes BVp≠BVq = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠BVq' BVp≠BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠BVq with distinct-dec FVp BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (yes FVp≠BVq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec FVp≠BVq' FVp≠BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) with distinct-dec BVp FVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (yes BVp≠FVq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠FVq' BVp≠FVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (no ¬BVp≠FVq) with distinct'-dec (Xs FVp) (Xs FVq)
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (no ¬BVp≠FVq) | (yes Xp≠Xq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = Xp≠Xq' (proj₁ Xp≠Xq) (proj₁ (proj₂ Xp≠Xq)) (proj₂ (proj₂ Xp≠Xq))
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (no ¬BVp≠FVq) | (no ¬Xp≠Xq) =
yes (BVp U̬ BVq , FVp U̬ FVq , CBpar CBp CBq (distinct-dec-is-distinct ¬BVp≠BVq)
(distinct-dec-is-distinct ¬FVp≠BVq)
(distinct-dec-is-distinct ¬BVp≠FVq)
(λ z z∈xs z∈ys → ¬Xp≠Xq (z , z∈xs , z∈ys)))
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | no ¬p =
no (\ { (BV , FV , CBpar X X₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) → ¬p (_ , _ , X₁ ) } )
binding-dec (p ∥ q) | no ¬p =
no (\ { (BV , FV , CBpar X X₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) → ¬p (_ , _ , X) } )
binding-dec (loop p) with binding-dec p
binding-dec (loop p) | yes (BV , FV , CB) with distinct-dec BV FV
binding-dec (loop p) | yes (BV , FV , CB) | yes dec = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (loop p) BV FV)
¬CB (BV₂ , FV₂ , CBloop CB₂ BV≠FV') with binding-is-function CB CB₂
... | (refl , refl) = distinct-not-distinct-dec BV≠FV' dec
binding-dec (loop p) | yes (BV , FV , CB) | no dec = yes (BV , (FV , (CBloop CB (distinct-dec-is-distinct dec))))
binding-dec (loop p) | no ¬p =
no (\ { (BV , FV , CBloop CB BV≠FV) -> ¬p (_ , _ , CB) } )
binding-dec (loopˢ p q) with binding-dec p
binding-dec (loopˢ p q) | yes (BVp , FVq , CBp ) with binding-dec q
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) with distinct-dec BVp FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | yes BVp≠FVq = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (loopˢ p q) BV FV)
¬CB (BV₂ , FV₂ , CBloopˢ CBp₂ CBq₂ BVp≠FVq₂ BVq≠FVq₂) with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠FVq₂ BVp≠FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠FVq with distinct-dec BVq FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠FVq | yes ¬BVq≠FVq = no ¬CB where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (loopˢ p q) BV FV)
¬CB (BV₂ , FV₂ , CBloopˢ CBp₂ CBq₂ BVp≠FVq₂ BVq≠FVq₂) with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVq≠FVq₂ ¬BVq≠FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no BVp≠FVq | no BVq≠FVq =
yes (BVp U̬ BVq , FVp U̬ FVq , CBloopˢ CBp CBq (distinct-dec-is-distinct BVp≠FVq) (distinct-dec-is-distinct BVq≠FVq))
binding-dec (loopˢ p q) | yes (BVp , FVq , CBp) | (no ¬CBq) =
no (\ { (BV , FV , CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) -> ¬CBq (_ , _ , CBq) } )
binding-dec (loopˢ p q) | no ¬CBp =
no (\ { (BV , FV , CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) -> ¬CBp (_ , _ , CBp) })
binding-dec (p >> q) with binding-dec p
binding-dec (p >> q) | yes (BVp , FVq , CBp ) with binding-dec q
binding-dec (p >> q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) with distinct-dec BVp FVq
binding-dec (p >> q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (yes BVp≠FVq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p >> q) BV FV)
¬CB (BV₂ , FV₂ , CBseq CBp₂ CBq₂ BVp≠FVq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠FVq' BVp≠FVq
binding-dec (p >> q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠FVq =
yes (BVp U̬ BVq , FVp U̬ FVq , CBseq CBp CBq (distinct-dec-is-distinct ¬BVp≠FVq))
binding-dec (p >> q) | yes (BVp , FVq , CBp) | (no ¬CBq) =
no (\ { (BV , FV , CBseq CBp CBq BVp≠FVq) -> ¬CBq (_ , _ , CBq) } )
binding-dec (p >> q) | no ¬CBp =
no (\ { (BV , FV , CBseq CBp CBq BVp≠FVq) -> ¬CBp (_ , _ , CBp) })
binding-dec (suspend p S) with binding-dec p
binding-dec (suspend p S) | yes (BV , FV , CB) with distinct'-dec [ (Sunwrap S) ] (Ss BV)
binding-dec (suspend p S) | yes (BV₁ , FV₁ , CB₁) | yes ([S]≠BVp₁ , [S]≠BVp₂ , [S]≠BVp₃) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (suspend p S) BV FV)
¬CB (BV₂ , FV₂ , CBsusp CB₃ [S]≠BVp') with (binding-is-function CB₁ CB₃)
... | refl , refl = [S]≠BVp' [S]≠BVp₁ [S]≠BVp₂ [S]≠BVp₃
binding-dec (suspend p S) | yes (BV , FV , CB) | (no ¬[S]≠BVp) =
yes (BV , +S S FV , CBsusp CB (λ z z∈xs z∈ys → ¬[S]≠BVp (z , z∈xs , z∈ys)))
binding-dec (suspend p S) | no ¬p =
no (\ { (BV , FV , CBsusp CB [S]≠BVp) -> ¬p (_ , _ , CB)})
binding-dec (trap p) with binding-dec p
binding-dec (trap p) | yes (BV , FV , CB) = yes (BV , FV , CBtrap CB)
binding-dec (trap p) | no ¬p =
no (\ { (BV , FV , CBtrap CB ) -> ¬p (BV , FV , CB) })
binding-dec (exit x) = yes (base , base , CBexit)
binding-dec (shared s ≔ e in: p) with binding-dec p
binding-dec (shared s ≔ e in: p) | yes (BV , FV , CB) =
yes (+s s BV , (FVₑ e) U̬ (FV |̌ (+s s base)) , CBshared CB)
binding-dec (shared s ≔ e in: p) | no ¬p =
no (\ { (BV , FV , CBshared CB) -> ¬p (_ , _ , CB) })
binding-dec (s ⇐ e) = yes (base , +s s (FVₑ e) , CBsset)
binding-dec (var x ≔ e in: p) with binding-dec p
binding-dec (var x ≔ e in: p) | yes (BV , FV , CB) =
yes (+x x BV , (FVₑ e) U̬ (FV |̌ (+x x base)) , CBvar CB)
binding-dec (var x ≔ e in: p) | no ¬p =
no (\ { (BV , FV , CBvar CB) -> ¬p (_ , _ , CB) } )
binding-dec (x ≔ e) = yes (base , (+x x (FVₑ e)) , CBvset)
binding-dec (if x ∣⇒ p ∣⇒ q) with binding-dec p
binding-dec (if x ∣⇒ p ∣⇒ q) | yes p₁ with binding-dec q
binding-dec (if x ∣⇒ p₁ ∣⇒ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) =
yes (BVp U̬ BVq , +x x (FVp U̬ FVq) , CBif CBp CBq)
binding-dec (if x ∣⇒ p ∣⇒ q) | yes p₁ | (no ¬p) =
no (\ { (BV , FV , CBif CBp CBq) -> ¬p (_ , _ , CBq) })
binding-dec (if x ∣⇒ p ∣⇒ q) | no ¬p =
no (\ { (BV , FV , CBif CBp CBq) -> ¬p (_ , _ , CBp) })
binding-dec (ρ⟨ θ , A ⟩· p) with binding-dec p
binding-dec (ρ⟨ θ , A ⟩· p) | yes (BV , FV , BP) =
yes (((Dom θ) U̬ BV) , FV |̌ (Dom θ) , CBρ BP)
binding-dec (ρ⟨ θ , A ⟩· p) | no ¬p = no (\ { (BV , FV , CBρ p ) -> ¬p (_ , _ , p) } )
binding-extract : ∀{p BV FV p' E} →
CorrectBinding p BV FV →
p ≐ E ⟦ p' ⟧e →
Σ (VarList × VarList) λ { (BV' , FV') → (BV' ⊆ BV × FV' ⊆ FV) × CorrectBinding p' BV' FV' }
binding-extract cb dehole =
_ , (⊆-refl , ⊆-refl) , cb
binding-extract (CBpar cbp cbq _ _ _ _) (depar₁ p≐E⟦p'⟧)
with binding-extract cbp p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ˡ BV'⊆BV , ∪ˡ FV'⊆FV) , cb*
binding-extract {_} (CBpar {BVp = BVp} {FVp = FVp} cbp cbq _ _ _ _) (depar₂ q≐E⟦q'⟧)
with binding-extract cbq q≐E⟦q'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ʳ BVp BV'⊆BV , ∪ʳ FVp FV'⊆FV) , cb*
binding-extract (CBseq cbp cbq _) (deseq p≐E⟦p'⟧)
with binding-extract cbp p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ˡ BV'⊆BV , ∪ˡ FV'⊆FV) , cb*
binding-extract (CBloopˢ cbp cbq _ _) (deloopˢ p≐E⟦p'⟧)
with binding-extract cbp p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ˡ BV'⊆BV , ∪ˡ FV'⊆FV) , cb*
binding-extract (CBsusp {S = S} cb _) (desuspend p≐E⟦p'⟧)
with binding-extract cb p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (BV'⊆BV , ∪ʳ (+S S base) FV'⊆FV) , cb*
binding-extract (CBtrap cb) (detrap p≐E⟦p'⟧)
with binding-extract cb p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (BV'⊆BV , FV'⊆FV) , cb*
binding-subst : ∀{p BVp FVp q BVq FVq r BVr FVr E} →
CorrectBinding p BVp FVp →
p ≐ E ⟦ q ⟧e →
CorrectBinding q BVq FVq →
BVr ⊆ BVq →
FVr ⊆ FVq →
CorrectBinding r BVr FVr →
Σ (VarList × VarList) λ { (BV' , FV') → (BV' ⊆ BVp × FV' ⊆ FVp) × CorrectBinding (E ⟦ r ⟧e) BV' FV' }
binding-subst (CBpar {BVq = BVq'} {FVq = FVq'} cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq')
(depar₁ p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (∪-respect-⊆-left BVp''⊆BVp' , ∪-respect-⊆-left FVp''⊆FVp') ,
CBpar cbp'' cbq'
(⊆-respect-distinct-left BVp''⊆BVp' BVp'≠BVq')
(⊆-respect-distinct-left FVp''⊆FVp' FVp'≠BVq')
(⊆-respect-distinct-left BVp''⊆BVp' BVp'≠FVq')
(⊆¹-respect-distinct'-left (proj₂ (proj₂ FVp''⊆FVp')) Xp'≠Xq')
binding-subst (CBpar {BVp = BVp'} {FVp = FVp'} cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq')
(depar₂ q'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbq' q'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVq'' , FVq'') , (BVq''⊆BVq' , FVq''⊆FVq') , cbq'' =
_ , (∪-respect-⊆-right BVp' BVq''⊆BVq' , ∪-respect-⊆-right FVp' FVq''⊆FVq') ,
CBpar cbp' cbq''
(⊆-respect-distinct-right BVq''⊆BVq' BVp'≠BVq')
(⊆-respect-distinct-right BVq''⊆BVq' FVp'≠BVq')
(⊆-respect-distinct-right FVq''⊆FVq' BVp'≠FVq')
(⊆¹-respect-distinct'-right (proj₂ (proj₂ FVq''⊆FVq')) Xp'≠Xq')
binding-subst (CBseq {BVq = BVq'} {FVq = FVq'} cbp' cbq' BV≠FV)
(deseq p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (∪-respect-⊆-left BVp''⊆BVp' , ∪-respect-⊆-left FVp''⊆FVp') ,
CBseq cbp'' cbq' (⊆-respect-distinct-left BVp''⊆BVp' BV≠FV)
binding-subst (CBloopˢ {BVq = BVq'} {FVq = FVq'} cbp' cbq' BVp≠FVq BVq≠FVq)
(deloopˢ p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (∪-respect-⊆-left BVp''⊆BVp' , ∪-respect-⊆-left FVp''⊆FVp') ,
CBloopˢ cbp'' cbq' (⊆-respect-distinct-left BVp''⊆BVp' BVp≠FVq) BVq≠FVq
binding-subst (CBsusp {S} {FV = FVp'} cbp' S∉BVp') (desuspend p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVP'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (BVp''⊆BVp' , (∪¹-respect-⊆¹-right [ Signal.unwrap S ] ,′ id ,′ id # FVp''⊆FVp')) ,
CBsusp cbp'' (⊆¹-respect-distinct'-right (proj₁ BVp''⊆BVp') S∉BVp')
binding-subst (CBtrap cbp') (detrap p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , ⟨BVp''⊆BVp'⟩×⟨FVp''⊆FVp'⟩ , cbp'' =
_ , ⟨BVp''⊆BVp'⟩×⟨FVp''⊆FVp'⟩ , CBtrap cbp''
binding-subst cbp dehole cbq BVr⊆BVq FVr⊆FVq cbr
with binding-is-function cbp cbq
... | (refl , refl) = _ , (BVr⊆BVq , FVr⊆FVq) , cbr
binding-extractc' : ∀{p BV FV p' C} →
CorrectBinding p BV FV →
p ≐ C ⟦ p' ⟧c →
Σ (VarList × VarList) λ { (BV' , FV') → CorrectBinding p' BV' FV' }
binding-extractc' cbp dchole =
_ , cbp
binding-extractc' (CBsig cbp) (dcsignl p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBpresent cbp cbp₁) (dcpresent₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBpresent cbp cbp₁) (dcpresent₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBpar cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) (dcpar₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBpar cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) (dcpar₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBloop cbp BV≠FV) (dcloop p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) (dcloopˢ₁ p≐C⟦p'⟧) =
binding-extractc' CBp p≐C⟦p'⟧
binding-extractc' (CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) (dcloopˢ₂ q≐C⟦q'⟧) =
binding-extractc' CBq q≐C⟦q'⟧
binding-extractc' (CBseq cbp cbp₁ BVp≠FVq) (dcseq₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBseq cbp cbp₁ BVp≠FVq) (dcseq₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBsusp cbp [S]≠BVp) (dcsuspend p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBtrap cbp) (dctrap p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBshared cbp) (dcshared p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBvar cbp) (dcvar p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBif cbp cbp₁) (dcif₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBif cbp cbp₁) (dcif₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBρ cbp) (dcenv p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-substc' : ∀{p BVp FVp q BVq FVq r BVr FVr C} →
CorrectBinding p BVp FVp →
p ≐ C ⟦ q ⟧c →
CorrectBinding q BVq FVq →
BVr ⊆ BVq →
FVr ⊆ FVq →
CorrectBinding r BVr FVr →
Σ (VarList × VarList) λ { (BV' , FV') → (BV' ⊆ BVp × FV' ⊆ FVp) × CorrectBinding (C ⟦ r ⟧c) BV' FV' }
binding-substc' CBp dchole CBq BVr⊆BVq FVr⊆FVq CBr
with binding-is-function CBp CBq
... | refl , refl = _ , (BVr⊆BVq , FVr⊆FVq) , CBr
binding-substc' (CBpar cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq)
(dcpar₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , ∪-respect-⊆-left fvsub) ,
CBpar cb1 cbp₁ (⊆-respect-distinct-left bvsub BVp≠BVq)
(⊆-respect-distinct-left fvsub FVp≠BVq)
(⊆-respect-distinct-left bvsub BVp≠FVq)
(⊆¹-respect-distinct'-left (thd fvsub) Xp≠Xq)
binding-substc' (CBpar{BVp = BVp}{FVp = FVp} cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq)
(dcpar₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub , ∪-respect-⊆-right FVp fvsub) ,
CBpar cbp cb1 (⊆-respect-distinct-right bvsub BVp≠BVq)
(⊆-respect-distinct-right bvsub FVp≠BVq)
(⊆-respect-distinct-right fvsub BVp≠FVq)
(⊆¹-respect-distinct'-right (thd fvsub) Xp≠Xq)
binding-substc' (CBseq cbp cbp₁ BVp≠FVq)
(dcseq₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , ∪-respect-⊆-left fvsub) ,
CBseq cb1 cbp₁ (⊆-respect-distinct-left bvsub BVp≠FVq)
binding-substc' (CBseq{BVp = BVp}{FVp = FVp} cbp cbp₁ BVp≠FVq)
(dcseq₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub , ∪-respect-⊆-right FVp fvsub) ,
CBseq cbp cb1 (⊆-respect-distinct-right fvsub BVp≠FVq)
binding-substc' (CBsusp{S = S} cbp [S]≠BVp)
(dcsuspend dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (bvsub , ((∷-respect-⊆¹ (Signal.unwrap S)) , id , id # fvsub)) ,
CBsusp cb1 (⊆¹-respect-distinct'-right (fst bvsub) [S]≠BVp)
binding-substc' (CBtrap CBp) (dctrap dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' CBp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (bvsub , fvsub) , CBtrap cb1
binding-substc' (CBsig{S = S ₛ} cbp) (dcsignl dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (((∷-respect-⊆¹ S) , id , id # bvsub) ,
⊆-respect-|̌ (+S (S ₛ) base) fvsub),
CBsig cb1
binding-substc' (CBpresent{S = S ₛ} cbp cbp₁)
(dcpresent₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub ,
((∷-respect-⊆¹ S) , id , id # (∪-respect-⊆-left fvsub))) ,
CBpresent cb1 cbp₁
binding-substc' (CBpresent{S = S ₛ}{BVp = BVp}{FVp = FVp} cbp cbp₁)
(dcpresent₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub ,
((∷-respect-⊆¹ S) , id , id # (∪-respect-⊆-right FVp fvsub))) ,
CBpresent cbp cb1
binding-substc' (CBloop cbp BV≠FV)
(dcloop dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right base bvsub , fvsub) ,
CBloop cb1 (⊆-respect-distinct-left bvsub
(⊆-respect-distinct-right fvsub BV≠FV))
binding-substc' (CBloopˢ cbp cbp₁ BVp≠FVq BVq≠FVq)
(dcloopˢ₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , ∪-respect-⊆-left fvsub) ,
CBloopˢ cb1 cbp₁ (⊆-respect-distinct-left bvsub BVp≠FVq) BVq≠FVq
binding-substc' (CBloopˢ{BVp = BVp}{FVp = FVp} cbp cbp₁ BVp≠FVq BVq≠FVq)
(dcloopˢ₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub , ∪-respect-⊆-right FVp fvsub) ,
CBloopˢ cbp cb1 (⊆-respect-distinct-right fvsub BVp≠FVq)
(⊆-respect-distinct-left bvsub
(⊆-respect-distinct-right fvsub BVq≠FVq))
binding-substc' (CBshared{s = s}{e = e} cbp)
(dcshared dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (((id , (∷-respect-⊆¹ (SharedVar.unwrap s)) , id # bvsub)) ,
∪-respect-⊆-right (FVₑ e) (⊆-respect-|̌ (+s s base) fvsub)) ,
CBshared cb1
binding-substc' (CBvar{x = x}{e = e} cbp) (dcvar dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (((id , id , (∷-respect-⊆¹ (SeqVar.unwrap x)) # bvsub)) ,
∪-respect-⊆-right (FVₑ e) (⊆-respect-|̌ (+x x base) fvsub)) ,
CBvar cb1
binding-substc' (CBif{x = x ᵥ} cbp cbp₁) (dcif₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , (id , id , (∷-respect-⊆¹ x) # (∪-respect-⊆-left fvsub))) ,
CBif cb1 cbp₁
binding-substc' (CBif{x = x ᵥ}{BVp = BVp}{FVp = FVp} cbp cbp₁)
(dcif₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub ,
(id , id , (∷-respect-⊆¹ x) # (∪-respect-⊆-right FVp fvsub))) ,
CBif cbp cb1
binding-substc' (CBρ{θ = θ} cbp) (dcenv dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right (Dom θ) bvsub , ⊆-respect-|̌ (Dom θ) fvsub) ,
CBρ cb1
-- In the decomposition E ⟦ p ⟧e, the bound variables in p and the free
-- variables in E must be disjoint.
distinct-term-context-help : ∀ {BV FV BVp FVp BVnothin FVnothin} p E →
CorrectBinding (E ⟦ p ⟧e) BV FV →
CorrectBinding p BVp FVp →
(BVp ⊆ BV) →
CorrectBinding (E ⟦ nothin ⟧e) BVnothin FVnothin →
distinct BVp FVnothin
distinct-term-context-help p [] cb cbp BVp⊆BV CBnothing =
(λ _ _ ()) ,′ (λ _ _ ()) ,′ (λ _ _ ())
distinct-term-context-help p (epar₁ q ∷ E)
(CBpar cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq') cbp BVp⊆BV
(CBpar cbnothinp cbnothinq BVp≠BVq₁ FVp≠BVq₁ BVp≠FVq₁ Xp≠Xq₁)
with binding-extract cbp' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbq' cbnothinq
... | refl , refl | refl , refl =
distinct-union-right
(distinct-term-context-help p E cbp' cbp BV'⊆BVE⟦p⟧ cbnothinp)
(⊆-respect-distinct-left BV'⊆BVE⟦p⟧ BVp'≠FVq')
distinct-term-context-help p (epar₂ p₁ ∷ E)
(CBpar cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq') cbp BVp⊆BV
(CBpar {FVq = FVnothinq} cbnothinp cbnothinq BVp≠BVq₁ FVp≠BVq₁ BVp≠FVq₁ Xp≠Xq₁)
with binding-extract cbq' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbp' cbnothinp
... | refl , refl | refl , refl =
⊆-respect-distinct-right
(∪-comm-⊆-right FVnothinq ⊆-refl)
(distinct-union-right
(distinct-term-context-help p E cbq' cbp BV'⊆BVE⟦p⟧ cbnothinq)
(⊆-respect-distinct-left BV'⊆BVE⟦p⟧ (distinct-sym FVp'≠BVq')))
distinct-term-context-help p (eseq q ∷ E)
(CBseq {BVp = BVE⟦p⟧p} {FVp = FVE⟦p⟧p} cbp' cbq' BVp'≠FVq') cbp BVp⊆BV
(CBseq {BVp = BVnothinp} {BVq = BVnothinq} {FVp = FVnothinp} {FVq = FVnothinq}
cbnothinp cbnothinq BVp≠FVq)
with binding-extract cbp' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbq' cbnothinq
... | refl , refl | refl , refl =
distinct-union-right
(distinct-term-context-help p E cbp' cbp BV'⊆BVE⟦p⟧ cbnothinp)
(⊆-respect-distinct-left
BV'⊆BVE⟦p⟧
(distinct-sym (dist++ˡ (distinct-sym (distinct-union-left BVp'≠FVq' BVp≠FVq)))))
distinct-term-context-help p (eloopˢ q ∷ E)
(CBloopˢ {BVp = BVE⟦p⟧p} {FVp = FVE⟦p⟧p} cbp' cbq' BVp'≠FVq' BVq'≠FVq') cbp BVp⊆BV
(CBloopˢ {BVp = BVnothinp} {FVp = FVnothinp} {BVq = BVnothinq} {FVq = FVnothinq}
cbnothinp cbnothinq BVp≠FVq BVq≠FVq)
with binding-extract cbp' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbq' cbnothinq
... | refl , refl | refl , refl =
distinct-union-right
(distinct-term-context-help p E cbp' cbp BV'⊆BVE⟦p⟧ cbnothinp)
(⊆-respect-distinct-left
BV'⊆BVE⟦p⟧
(distinct-sym (dist++ˡ (distinct-sym (distinct-union-left BVp'≠FVq' BVp≠FVq)))))
distinct-term-context-help {BVp = BVp} p (esuspend S ∷ E)
(CBsusp cb [S]≠BVp) cbp BVp⊆BV
(CBsusp {FV = FV} cbnothin [S]≠BVp₁) = BVp≠S∷FV ,′ id ,′ id # dist
where dist = distinct-term-context-help p E cb cbp BVp⊆BV cbnothin
BVp≠S∷FV : (typeof (proj₁ dist)) → ∀ S' → S' ∈ (proj₁ BVp) → S' ∈ (Signal.unwrap S ∷ proj₁ FV) → ⊥
BVp≠S∷FV BVp≠FV S' S'∈BVp (here refl) = [S]≠BVp S' (here refl) (proj₁ BVp⊆BV S' S'∈BVp)
BVp≠S∷FV BVp≠FV S' S'∈BVp (there S'∈FV) = BVp≠FV S' S'∈BVp S'∈FV
distinct-term-context-help p (etrap ∷ E)
(CBtrap cb) cbp BVp⊆BV
(CBtrap cbnothin) =
distinct-term-context-help p E cb cbp BVp⊆BV cbnothin
BVars : ∀ (p : Term) -> VarList
BVars nothin = base
BVars pause = base
BVars (signl S p) = +S S (BVars p)
BVars (present S ∣⇒ p ∣⇒ q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (emit S) = base
BVars (p ∥ q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (loop p) = BV where
BV = BVars p
BVars (loopˢ p q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (p >> q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (suspend p S) = BVars p
BVars (trap p) = BVars p
BVars (exit x) = base
BVars (shared s ≔ e in: p) = +s s (BVars p)
BVars (s ⇐ e) = base
BVars (var x ≔ e in: p) = +x x (BVars p)
BVars (x ≔ e) = base
BVars (if x ∣⇒ p ∣⇒ q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (ρ⟨ θ , A ⟩· p) = (Dom θ) U̬ BV where
BV = BVars p
FVars : ∀ (p : Term) -> VarList
FVars nothin = base
FVars pause = base
FVars (signl S p) = FV |̌ (+S S base) where
FV = FVars p
FVars (present S ∣⇒ p ∣⇒ q) = +S S (FVp U̬ FVq) where
FVp = FVars p
FVq = FVars q
FVars (emit S) = +S S base
FVars (p ∥ q) = FVp U̬ FVq where
FVp = FVars p
FVq = FVars q
FVars (loop p) = FVars p
FVars (loopˢ p q) = FVp U̬ FVq where
FVp = FVars p
FVq = FVars q
FVars (p >> q) = FVp U̬ FVq where
FVp = FVars p
FVq = FVars q
FVars (suspend p S) = +S S (FVars p)
FVars (trap p) = FVars p
FVars (exit x) = base
FVars (shared s ≔ e in: p) = (FVₑ e) U̬ (FV |̌ (+s s base)) where
FV = FVars p
FVars (s ⇐ e) = +s s (FVₑ e) where
FVars (var x ≔ e in: p) = (FVₑ e) U̬ (FV |̌ (+x x base)) where
FV = FVars p
FVars (x ≔ e) = +x x (FVₑ e)
FVars (if x ∣⇒ p ∣⇒ q) = +x x (FVp U̬ FVq) where
FVp = FVars p
FVq = FVars q
FVars (ρ⟨ θ , A ⟩· p) = FV |̌ (Dom θ) where
FV = FVars p
CB : Term -> Set
CB p = CorrectBinding p (BVars p) (FVars p)
BVFVcorrect : ∀ p BV FV -> CorrectBinding p BV FV -> BVars p ≡ BV × FVars p ≡ FV
BVFVcorrect .nothin .([] , [] , []) .([] , [] , []) CBnothing = refl , refl
BVFVcorrect .pause .([] , [] , []) .([] , [] , []) CBpause = refl , refl
BVFVcorrect .(signl _ _) .(+S S BV) .(FV |̌ (+S S base))
(CBsig{p}{S}{BV}{FV} CB) with BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(present _ ∣⇒ _ ∣⇒ _) .(BVp U̬ BVq) .(+S S (FVp U̬ FVq))
(CBpresent{S}{p}{q}{BVp}{FVp}{BVq}{FVq} CBp CBq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(emit _) _ _ CBemit = refl , refl
BVFVcorrect .(_ ∥ _) .(BVp U̬ BVq) .(FVp U̬ FVq)
(CBpar{p}{q}{BVp}{FVp}{BVq}{FVq} CBp CBq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(loop _) .BV .FV
(CBloop{p}{BV}{FV} CB BV≠FV) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(loopˢ _ _) .(BVp U̬ BVq) .(FVp U̬ FVq)
(CBloopˢ{p}{q}{BVp}{FVp}{BVq}{FVq} CBp CBq BVp≠FVq BVq≠FVq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(_ >> _) .(BVp U̬ BVq) .(FVp U̬ FVq)
(CBseq{p}{q}{BVp}{BVq}{FVp}{FVq} CBp CBq BVp≠FVq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(suspend _ _) .BV .(+S S FV)
(CBsusp{S}{p}{BV}{FV} CB [S]≠BVp) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(trap _) .BV .FV (CBtrap{p}{BV}{FV} CB) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(exit _) .([] , [] , []) .([] , [] , []) CBexit = refl , refl
BVFVcorrect .(shared _ ≔ _ in: _) .(+s s BV) .((FVₑ e) U̬ (FV |̌ (+s s base)))
(CBshared{s}{e}{p}{BV}{FV} CB) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(_ ⇐ _) .([] , [] , []) .(+s s (FVₑ e)) (CBsset{s}{e}) = refl , refl
BVFVcorrect .(var _ ≔ _ in: _) .(+x x BV) .((FVₑ e) U̬ (FV |̌ (+x x base)))
(CBvar{x}{e}{p}{BV}{FV} CB) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(_ ≔ _) .([] , [] , []) .(+x x (FVₑ e)) (CBvset{x}{e}) = refl , refl
BVFVcorrect .(if _ ∣⇒ _ ∣⇒ _) .(BVp U̬ BVq) .(+x x (FVp U̬ FVq))
(CBif{x}{p}{q}{BVp}{BVq}{FVp}{FVq} CBp CBq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(ρ⟨ _ , _ ⟩· _) .(((Dom θ) U̬ BV)) .(FV |̌ (Dom θ))
(CBρ{θ}{A}{p}{BV}{FV} CB) with BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
| {
"alphanum_fraction": 0.5750433549,
"avg_line_length": 47.043263288,
"ext": "agda",
"hexsha": "23d1fa57d3b4ef354ab711e7c61f3553d59addb0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/Esterel/Lang/Binding.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/Esterel/Lang/Binding.agda",
"max_line_length": 154,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/Esterel/Lang/Binding.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 18280,
"size": 38058
} |
{-# OPTIONS --prop --rewriting #-}
module Examples.Id where
open import Calf.CostMonoid
open import Calf.CostMonoids using (ℕ-CostMonoid)
costMonoid = ℕ-CostMonoid
open CostMonoid costMonoid
open import Calf costMonoid
open import Calf.Types.Nat
open import Calf.Types.Bounded costMonoid
open import Calf.Types.BigO costMonoid
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning)
module Easy where
id : cmp (Π nat λ _ → F nat)
id n = ret n
id/correct : ∀ n → ◯ (id n ≡ ret n)
id/correct n u = refl
id/cost : cmp (Π nat λ _ → cost)
id/cost n = 0
id≤id/cost : ∀ n → IsBounded nat (id n) (id/cost n)
id≤id/cost n = bound/ret
id/asymptotic : given nat measured-via (λ n → n) , id ∈𝓞(λ n → 0)
id/asymptotic = 0 ≤n⇒f[n]≤ 0 g[n]via λ n _ → id≤id/cost n
module Hard where
id : cmp (Π nat λ _ → F nat)
id zero = ret 0
id (suc n) =
step (F nat) 1 (
bind (F nat) (id n) λ n' →
ret (suc n')
)
id/correct : ∀ n → ◯ (id n ≡ ret n)
id/correct zero u = refl
id/correct (suc n) u =
begin
id (suc n)
≡⟨⟩
step (F nat) 1 (
bind (F nat) (id n) λ n' →
ret (suc n')
)
≡⟨ step/ext (F nat) _ 1 u ⟩
(bind (F nat) (id n) λ n' →
ret (suc n'))
≡⟨ Eq.cong (λ e → bind (F nat) e _) (id/correct n u) ⟩
ret (suc n)
∎
where open ≡-Reasoning
id/cost : cmp (Π nat λ _ → cost)
id/cost zero = 0
id/cost (suc n) =
1 + (
bind cost (id n) λ n' → id/cost n +
0
)
id/cost/closed : cmp (Π nat λ _ → cost)
id/cost/closed n = n
id/cost≤id/cost/closed : ∀ n → ◯ (id/cost n ≤ id/cost/closed n)
id/cost≤id/cost/closed zero u = ≤-refl
id/cost≤id/cost/closed (suc n) u =
begin
id/cost (suc n)
≡⟨⟩
1 + (
bind cost (id n) λ n' → id/cost n +
0
)
≡⟨ Eq.cong (λ e → 1 + bind cost e λ n' → id/cost n + 0) (id/correct n u) ⟩
1 + (id/cost n + 0)
≡⟨ Eq.cong suc (+-identityʳ _) ⟩
1 + id/cost n
≤⟨ +-monoʳ-≤ 1 (id/cost≤id/cost/closed n u) ⟩
1 + id/cost/closed n
≡⟨⟩
suc n
≡⟨⟩
id/cost/closed (suc n)
∎
where open ≤-Reasoning
id≤id/cost : ∀ n → IsBounded nat (id n) (id/cost n)
id≤id/cost zero = bound/ret
id≤id/cost (suc n) =
bound/step 1 _ (
bound/bind (id/cost n) _ (id≤id/cost n) λ n →
bound/ret
)
id≤id/cost/closed : ∀ n → IsBounded nat (id n) (id/cost/closed n)
id≤id/cost/closed n = bound/relax (id/cost≤id/cost/closed n) (id≤id/cost n)
id/asymptotic : given nat measured-via (λ n → n) , id ∈𝓞(λ n → n)
id/asymptotic = 0 ≤n⇒f[n]≤g[n]via λ n _ → id≤id/cost/closed n
easy≡hard : ◯ (Easy.id ≡ Hard.id)
easy≡hard u =
funext λ n →
begin
Easy.id n
≡⟨ Easy.id/correct n u ⟩
ret n
≡˘⟨ Hard.id/correct n u ⟩
Hard.id n
∎
where open ≡-Reasoning
| {
"alphanum_fraction": 0.5450791466,
"avg_line_length": 24.2166666667,
"ext": "agda",
"hexsha": "a529b55958df03fdeee0fbf184de2274c7b68853",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Examples/Id.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Examples/Id.agda",
"max_line_length": 93,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Id.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 1223,
"size": 2906
} |
-- Andreas, 2016-07-28 issue 2120, reported by guillaume
-- {-# OPTIONS -v tc.term.exlam:50 #-}
open import Common.Product
data Nat : Set where
zero : Nat
data Eq {A : Set}(a : A) : A → Set where
refl : Eq a a
postulate _<∣_ : ∀ {X Y : Set} → (X → Y) → X → Y
test : Nat
test = ( λ { (zero , refl) → zero } ) <∣ (zero , zero)
-- WAS: Internal error in Reduce
-- EXPECTED: Proper error, like
--
-- Type mismatch
-- when checking that the pattern refl has type _15 zero
| {
"alphanum_fraction": 0.611691023,
"avg_line_length": 19.9583333333,
"ext": "agda",
"hexsha": "ed4ec6c12de3b2afa088c29627a28f3d87dba20d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2120.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2120.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2120.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 160,
"size": 479
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.