Search is not available for this dataset
text
string | meta
dict |
---|---|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural number division
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.DivMod where
open import Agda.Builtin.Nat using (div-helper; mod-helper)
open import Data.Fin.Base using (Fin; toℕ; fromℕ<)
open import Data.Fin.Properties using (toℕ-fromℕ<)
open import Data.Nat.Base as Nat
open import Data.Nat.DivMod.Core
open import Data.Nat.Divisibility.Core
open import Data.Nat.Properties
open import Data.Nat.Tactic.RingSolver
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable using (False)
open ≤-Reasoning
------------------------------------------------------------------------
-- Definitions
-- The division and modulus operations are only defined when the divisor
-- is non-zero. The proof of this is defined as an irrelevant
-- implict argument of type `False (divisor ≟ 0)`. This allows this
-- proof to be automatically inferred when the divisor is of the form
-- `suc n`, and hence minimises the number of these proofs that
-- need be passed around. You can therefore write `m / suc n` without
-- issue.
infixl 7 _/_ _%_
-- Natural division
_/_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
m / (suc n) = div-helper 0 n m n
-- Natural remainder/modulus
_%_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
m % (suc n) = mod-helper 0 n m n
------------------------------------------------------------------------
-- Relationship between _%_ and _div_
m≡m%n+[m/n]*n : ∀ m n → m ≡ m % suc n + (m / suc n) * suc n
m≡m%n+[m/n]*n m n = div-mod-lemma 0 0 m n
m%n≡m∸m/n*n : ∀ m n → m % suc n ≡ m ∸ (m / suc n) * suc n
m%n≡m∸m/n*n m n-1 = begin-equality
m % n ≡˘⟨ m+n∸n≡m (m % n) m/n*n ⟩
m % n + m/n*n ∸ m/n*n ≡˘⟨ cong (_∸ m/n*n) (m≡m%n+[m/n]*n m n-1) ⟩
m ∸ m/n*n ∎
where n = suc n-1; m/n*n = (m / n) * n
------------------------------------------------------------------------
-- Properties of _%_
n%1≡0 : ∀ n → n % 1 ≡ 0
n%1≡0 = a[modₕ]1≡0
n%n≡0 : ∀ n → suc n % suc n ≡ 0
n%n≡0 n = n[modₕ]n≡0 0 n
m%n%n≡m%n : ∀ m n → m % suc n % suc n ≡ m % suc n
m%n%n≡m%n m n = modₕ-idem 0 m n
[m+n]%n≡m%n : ∀ m n → (m + suc n) % suc n ≡ m % suc n
[m+n]%n≡m%n m n = a+n[modₕ]n≡a[modₕ]n 0 m n
[m+kn]%n≡m%n : ∀ m k n → (m + k * (suc n)) % suc n ≡ m % suc n
[m+kn]%n≡m%n m zero n-1 = cong (_% suc n-1) (+-identityʳ m)
[m+kn]%n≡m%n m (suc k) n-1 = begin-equality
(m + (n + k * n)) % n ≡⟨ cong (_% n) (sym (+-assoc m n (k * n))) ⟩
(m + n + k * n) % n ≡⟨ [m+kn]%n≡m%n (m + n) k n-1 ⟩
(m + n) % n ≡⟨ [m+n]%n≡m%n m n-1 ⟩
m % n ∎
where n = suc n-1
m*n%n≡0 : ∀ m n → (m * suc n) % suc n ≡ 0
m*n%n≡0 = [m+kn]%n≡m%n 0
m%n<n : ∀ m n → m % suc n < suc n
m%n<n m n = s≤s (a[modₕ]n<n 0 m n)
m%n≤m : ∀ m n → m % suc n ≤ m
m%n≤m m n = a[modₕ]n≤a 0 m n
m≤n⇒m%n≡m : ∀ {m n} → m ≤ n → m % suc n ≡ m
m≤n⇒m%n≡m {m} {n} m≤n with ≤⇒≤″ m≤n
... | less-than-or-equal {k} refl = a≤n⇒a[modₕ]n≡a 0 (m + k) m k
%-pred-≡0 : ∀ {m n} {≢0} → (suc m % n) {≢0} ≡ 0 → (m % n) {≢0} ≡ n ∸ 1
%-pred-≡0 {m} {suc n-1} eq = a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 0 n-1 m eq
m<[1+n%d]⇒m≤[n%d] : ∀ {m} n d {≢0} → m < (suc n % d) {≢0} → m ≤ (n % d) {≢0}
m<[1+n%d]⇒m≤[n%d] {m} n (suc d-1) = k<1+a[modₕ]n⇒k≤a[modₕ]n 0 m n d-1
[1+m%d]≤1+n⇒[m%d]≤n : ∀ m n d {≢0} → 0 < (suc m % d) {≢0} → (suc m % d) {≢0} ≤ suc n → (m % d) {≢0} ≤ n
[1+m%d]≤1+n⇒[m%d]≤n m n (suc d-1) leq = 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k 0 n m d-1 leq
%-distribˡ-+ : ∀ m n d {≢0} → ((m + n) % d) {≢0} ≡ (((m % d) {≢0} + (n % d) {≢0}) % d) {≢0}
%-distribˡ-+ m n d@(suc d-1) = begin-equality
(m + n) % d ≡⟨ cong (λ v → (v + n) % d) (m≡m%n+[m/n]*n m d-1) ⟩
(m % d + m / d * d + n) % d ≡⟨ cong (_% d) (+-assoc (m % d) _ n) ⟩
(m % d + (m / d * d + n)) % d ≡⟨ cong (λ v → (m % d + v) % d) (+-comm _ n) ⟩
(m % d + (n + m / d * d)) % d ≡⟨ cong (_% d) (sym (+-assoc (m % d) n _)) ⟩
(m % d + n + m / d * d) % d ≡⟨ [m+kn]%n≡m%n (m % d + n) (m / d) d-1 ⟩
(m % d + n) % d ≡⟨ cong (λ v → (m % d + v) % d) (m≡m%n+[m/n]*n n d-1) ⟩
(m % d + (n % d + (n / d) * d)) % d ≡⟨ sym (cong (_% d) (+-assoc (m % d) (n % d) _)) ⟩
(m % d + n % d + (n / d) * d) % d ≡⟨ [m+kn]%n≡m%n (m % d + n % d) (n / d) d-1 ⟩
(m % d + n % d) % d ∎
%-distribˡ-* : ∀ m n d {≢0} → ((m * n) % d) {≢0} ≡ (((m % d) {≢0} * (n % d) {≢0}) % d) {≢0}
%-distribˡ-* m n d@(suc d-1) = begin-equality
(m * n) % d ≡⟨ cong (λ h → (h * n) % d) (m≡m%n+[m/n]*n m d-1) ⟩
((m′ + k * d) * n) % d ≡⟨ cong (λ h → ((m′ + k * d) * h) % d) (m≡m%n+[m/n]*n n d-1) ⟩
((m′ + k * d) * (n′ + j * d)) % d ≡⟨ cong (_% d) (lemma m′ n′ k j d) ⟩
(m′ * n′ + (m′ * j + (n′ + j * d) * k) * d) % d ≡⟨ [m+kn]%n≡m%n (m′ * n′) (m′ * j + (n′ + j * d) * k) d-1 ⟩
(m′ * n′) % d ≡⟨⟩
((m % d) * (n % d)) % d ∎
where
m′ = m % d
n′ = n % d
k = m / d
j = n / d
lemma : ∀ m′ n′ k j d → (m′ + k * d) * (n′ + j * d) ≡ m′ * n′ + (m′ * j + (n′ + j * d) * k) * d
lemma = solve-∀
%-remove-+ˡ : ∀ {m} n {d} {≢0} → d ∣ m → ((m + n) % d) {≢0} ≡ (n % d) {≢0}
%-remove-+ˡ {m} n {d@(suc d-1)} (divides p refl) = begin-equality
(p * d + n) % d ≡⟨ cong (_% d) (+-comm (p * d) n) ⟩
(n + p * d) % d ≡⟨ [m+kn]%n≡m%n n p d-1 ⟩
n % d ∎
%-remove-+ʳ : ∀ m {n d} {≢0} → d ∣ n → ((m + n) % d) {≢0} ≡ (m % d) {≢0}
%-remove-+ʳ m {n} {suc _} eq rewrite +-comm m n = %-remove-+ˡ {n} m eq
------------------------------------------------------------------------
-- Properties of _/_
/-congˡ : ∀ {m n o : ℕ} {o≢0} → m ≡ n → (m / o) {o≢0} ≡ (n / o) {o≢0}
/-congˡ refl = refl
/-congʳ : ∀ {m n o : ℕ} {n≢0 o≢0} → n ≡ o →
(m / n) {n≢0} ≡ (m / o) {o≢0}
/-congʳ {_} {suc _} {suc _} refl = refl
0/n≡0 : ∀ n {≢0} → (0 / n) {≢0} ≡ 0
0/n≡0 (suc n-1) = refl
n/1≡n : ∀ n → n / 1 ≡ n
n/1≡n n = a[divₕ]1≡a 0 n
n/n≡1 : ∀ n {≢0} → (n / n) {≢0} ≡ 1
n/n≡1 (suc n-1) = n[divₕ]n≡1 n-1 n-1
m*n/n≡m : ∀ m n {≢0} → (m * n / n) {≢0} ≡ m
m*n/n≡m m (suc n-1) = a*n[divₕ]n≡a 0 m n-1
m/n*n≡m : ∀ {m n} {≢0} → n ∣ m → (m / n) {≢0} * n ≡ m
m/n*n≡m {_} {n@(suc n-1)} (divides q refl) = cong (_* n) (m*n/n≡m q n)
m*[n/m]≡n : ∀ {m n} {≢0} → m ∣ n → m * (n / m) {≢0} ≡ n
m*[n/m]≡n {m} m∣n = trans (*-comm m (_ / m)) (m/n*n≡m m∣n)
m/n*n≤m : ∀ m n {≢0} → (m / n) {≢0} * n ≤ m
m/n*n≤m m n@(suc n-1) = begin
(m / n) * n ≤⟨ m≤m+n ((m / n) * n) (m % n) ⟩
(m / n) * n + m % n ≡⟨ +-comm _ (m % n) ⟩
m % n + (m / n) * n ≡⟨ sym (m≡m%n+[m/n]*n m n-1) ⟩
m ∎
m/n<m : ∀ m n {≢0} → m ≥ 1 → n ≥ 2 → (m / n) {≢0} < m
m/n<m m n@(suc n-1) m≥1 n≥2 = *-cancelʳ-< {n} (m / n) m (begin-strict
(m / n) * n ≤⟨ m/n*n≤m m n ⟩
m <⟨ m<m*n m≥1 n≥2 ⟩
m * n ∎)
/-mono-≤ : ∀ {m n o p} {o≢0 p≢0} → m ≤ n → o ≥ p → (m / o) {o≢0} ≤ (n / p) {p≢0}
/-mono-≤ m≤n (s≤s o≥p) = divₕ-mono-≤ 0 m≤n o≥p
/-monoˡ-≤ : ∀ {m n o} {o≢0} → m ≤ n → (m / o) {o≢0} ≤ (n / o) {o≢0}
/-monoˡ-≤ {o≢0 = o≢0} m≤n = /-mono-≤ {o≢0 = o≢0} {o≢0} m≤n ≤-refl
/-monoʳ-≤ : ∀ m {n o} {n≢0 o≢0} → n ≥ o → (m / n) {n≢0} ≤ (m / o) {o≢0}
/-monoʳ-≤ _ {n≢0 = n≢0} {o≢0} n≥o = /-mono-≤ {o≢0 = n≢0} {o≢0} ≤-refl n≥o
m≥n⇒m/n>0 : ∀ {m n n≢0} → m ≥ n → (m / n) {n≢0} > 0
m≥n⇒m/n>0 {m@(suc m-1)} {n@(suc n-1)} m≥n = begin
1 ≡⟨ sym (n/n≡1 m) ⟩
m / m ≤⟨ /-monoʳ-≤ m m≥n ⟩
m / n ∎
+-distrib-/ : ∀ m n {d} {≢0} → (m % d) {≢0} + (n % d) {≢0} < d →
((m + n) / d) {≢0} ≡ (m / d) {≢0} + (n / d) {≢0}
+-distrib-/ m n {suc d-1} leq = +-distrib-divₕ 0 0 m n d-1 leq
+-distrib-/-∣ˡ : ∀ {m} n {d} {≢0} → d ∣ m →
((m + n) / d) {≢0} ≡ (m / d) {≢0} + (n / d) {≢0}
+-distrib-/-∣ˡ {m} n {d@(suc d-1)} (divides p refl) = +-distrib-/ m n (begin-strict
p * d % d + n % d ≡⟨ cong (_+ n % d) (m*n%n≡0 p d-1) ⟩
n % d <⟨ m%n<n n d-1 ⟩
d ∎)
+-distrib-/-∣ʳ : ∀ {m} n {d} {≢0} → d ∣ n →
((m + n) / d) {≢0} ≡ (m / d) {≢0} + (n / d) {≢0}
+-distrib-/-∣ʳ {m} n {d@(suc d-1)} (divides p refl) = +-distrib-/ m n (begin-strict
m % d + p * d % d ≡⟨ cong (m % d +_) (m*n%n≡0 p d-1) ⟩
m % d + 0 ≡⟨ +-identityʳ _ ⟩
m % d <⟨ m%n<n m d-1 ⟩
d ∎)
*-/-assoc : ∀ m {n d} {≢0} → d ∣ n → (m * n / d) {≢0} ≡ m * ((n / d) {≢0})
*-/-assoc zero {_} {d@(suc _)} d∣n = 0/n≡0 (suc d)
*-/-assoc (suc m) {n} {d@(suc _)} d∣n = begin-equality
(n + m * n) / d ≡⟨ +-distrib-/-∣ˡ _ d∣n ⟩
n / d + (m * n) / d ≡⟨ cong (n / d +_) (*-/-assoc m d∣n) ⟩
n / d + m * (n / d) ∎
------------------------------------------------------------------------
-- A specification of integer division.
record DivMod (dividend divisor : ℕ) : Set where
constructor result
field
quotient : ℕ
remainder : Fin divisor
property : dividend ≡ toℕ remainder + quotient * divisor
infixl 7 _div_ _mod_ _divMod_
_div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
_div_ = _/_
_mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor
m mod (suc n) = fromℕ< (m%n<n m n)
_divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
m divMod n@(suc n-1) = result (m / n) (m mod n) (begin-equality
m ≡⟨ m≡m%n+[m/n]*n m n-1 ⟩
m % n + [m/n]*n ≡⟨ cong (_+ [m/n]*n) (sym (toℕ-fromℕ< (m%n<n m n-1))) ⟩
toℕ (fromℕ< (m%n<n m n-1)) + [m/n]*n ∎)
where [m/n]*n = m / n * n
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
a≡a%n+[a/n]*n = m≡m%n+[m/n]*n
{-# WARNING_ON_USAGE a≡a%n+[a/n]*n
"Warning: a≡a%n+[a/n]*n was deprecated in v1.1.
Please use m≡m%n+[m/n]*n instead."
#-}
a%1≡0 = n%1≡0
{-# WARNING_ON_USAGE a%1≡0
"Warning: a%1≡0 was deprecated in v1.1.
Please use n%1≡0 instead."
#-}
a%n%n≡a%n = m%n%n≡m%n
{-# WARNING_ON_USAGE a%n%n≡a%n
"Warning: a%n%n≡a%n was deprecated in v1.1.
Please use m%n%n≡m%n instead."
#-}
[a+n]%n≡a%n = [m+n]%n≡m%n
{-# WARNING_ON_USAGE [a+n]%n≡a%n
"Warning: [a+n]%n≡a%n was deprecated in v1.1.
Please use [m+n]%n≡m%n instead."
#-}
[a+kn]%n≡a%n = [m+kn]%n≡m%n
{-# WARNING_ON_USAGE [a+kn]%n≡a%n
"Warning: [a+kn]%n≡a%n was deprecated in v1.1.
Please use [m+kn]%n≡m%n instead."
#-}
kn%n≡0 = m*n%n≡0
{-# WARNING_ON_USAGE kn%n≡0
"Warning: kn%n≡0 was deprecated in v1.1.
Please use m*n%n≡0 instead."
#-}
a%n<n = m%n<n
{-# WARNING_ON_USAGE a%n<n
"Warning: a%n<n was deprecated in v1.1.
Please use m%n<n instead."
#-}
|
{
"alphanum_fraction": 0.4112813885,
"avg_line_length": 36.7186440678,
"ext": "agda",
"hexsha": "48329677b5a16ed20a43764b799026722a78f259",
"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/Nat/DivMod.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/Nat/DivMod.agda",
"max_line_length": 120,
"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/Nat/DivMod.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": 5419,
"size": 10832
}
|
{-# OPTIONS --cubical #-}
module Miscellaneous.CubicalInteger where
import Lvl
open import Numeral.Natural as ℕ using (ℕ)
open import Numeral.Sign as Sign using (−|+ ; −|0|+ ; ➖ ; ➕)
open import Type.Cubical
open import Type.Cubical.Path.Equality
open import Type
apply : ∀{ℓ}{T : Type{ℓ}}{x y : T} → Interval → (x ≡ y) → T
apply i xy = xy i
infix 10010 −ₙ_ +ₙ_
infix 10020 _+_ _−_
-- The type of integers ℤ = {…,−2,−1,0,1,2,…}.
-- Represented by using the exclusive union of ℕ and ℕ, but the zeroes are equal.
data ℤ : Type{Lvl.𝟎} where
signed : (−|+) → ℕ → ℤ
𝟎-sign : (signed ➖ ℕ.𝟎 ≡ signed ➕ ℕ.𝟎)
-- Intuitive constructor patterns
-- −ₙ_ : ℕ → ℤ
-- +ₙ_ : ℕ → ℤ
pattern −ₙ_ n = signed ➖ n
pattern +ₙ_ n = signed ➕ n
pattern 𝟎 = +ₙ(ℕ.𝟎) -- Zero (0).
pattern 𝟏 = +ₙ(ℕ.𝟏) -- One (1).
pattern −𝟏 = −ₙ(ℕ.𝟏) -- Negative one (−1).
open import Structure.Relator.Properties
open import Type.Cubical.Path
open import Type.Cubical.Path.Proofs
-- module _ where
-- open import Type.Isomorphism
-- postulate univalence : ∀{ℓ}{A B : Type{ℓ}} → (A ≅ B) ≅ (A ≡ B)
elim : ∀{ℓ} → (P : ℤ → Type{ℓ}) → (neg : (n : ℕ) → P(−ₙ n)) → (pos : (n : ℕ) → P(+ₙ n)) → PathP(pointOn(map P 𝟎-sign)) (neg ℕ.𝟎) (pos ℕ.𝟎) → ((n : ℤ) → P(n))
elim(P) neg _ eq (−ₙ n) = neg n
elim(P) _ pos eq (+ₙ n) = pos n
elim(P) _ _ eq (𝟎-sign i) = eq i
-- Sign.
-- The sign part of an integer where zero is interpreted as positive.
-- Notes on the proof of the path:
-- The 𝟎-sign case guarantees that the function respects the congruence property (in this case (−0 = +0) → (sign(−0) = sign(+0))).
-- It is proven by providing the value on a path varying on the variable `i`. In this case, it is constant (both −0 and +0 maps to ➕).
sign : ℤ → (−|+)
sign (signed _ ℕ.𝟎) = ➕
sign (signed s (ℕ.𝐒(_))) = s
sign (𝟎-sign i) = ➕
-- Zeroable sign.
sign₀ : ℤ → (−|0|+)
sign₀ (signed s ℕ.𝟎) = Sign.𝟎
sign₀ (signed s (ℕ.𝐒(_))) = Sign.zeroable s
sign₀ (𝟎-sign i) = Sign.𝟎
-- Absolute value.
-- The natural part of an integer.
absₙ : ℤ → ℕ
absₙ(−ₙ n) = n
absₙ(+ₙ n) = n
absₙ(𝟎-sign _) = ℕ.𝟎
open import Data.Either
open import Functional using (_$_)
open import Logic.Propositional
import Numeral.Sign.Oper as Sign
import Numeral.Natural.Oper as ℕ
open import Relator.Equals using () renaming (_≡_ to Id ; [≡]-intro to Id-intro)
open import Relator.Equals.Proofs.Equivalence using () renaming ([≡]-equiv to Id-equiv ; [≡]-symmetry to Id-symmetry ; [≡]-to-function to Id-to-function ; [≡]-function to Id-function)
open import Syntax.Transitivity
Sign-decidable-eq : ∀(s₁ s₂ : (−|+)) → (Id s₁ s₂ ∨ ¬(Id s₁ s₂))
Sign-decidable-eq ➕ ➕ = [∨]-introₗ Id-intro
Sign-decidable-eq ➕ ➖ = [∨]-introᵣ \()
Sign-decidable-eq ➖ ➕ = [∨]-introᵣ \()
Sign-decidable-eq ➖ ➖ = [∨]-introₗ Id-intro
step : (−|+) → ℤ → ℤ
step s₁ (signed s₂ n) with Sign-decidable-eq s₁ s₂
step _ (signed s n) | Left _ = signed s (ℕ.𝐒(n))
step s₁ (signed s₂ ℕ.𝟎) | Right _ = signed s₁ (ℕ.𝐒(ℕ.𝟎))
step s₁ (signed s₂ (ℕ.𝐒(n))) | Right _ = signed s₂ n
step ➕ (𝟎-sign i) = 𝟏
step ➖ (𝟎-sign i) = −𝟏
-- Predecessor.
-- Alternative implementation:
-- 𝐏(−ₙ n) = −ₙ(ℕ.𝐒(n))
-- 𝐏(+ₙ ℕ.𝟎) = −ₙ(ℕ.𝐒(ℕ.𝟎))
-- 𝐏(+ₙ(ℕ.𝐒 n)) = +ₙ n
-- 𝐏(𝟎-sign i) = reflexivity(_≡_) {−𝟏} i
𝐏 : ℤ → ℤ
𝐏 = step ➖
-- Successor.
-- Alternative implementation:
-- 𝐒(−ₙ(ℕ.𝐒 n)) = −ₙ n
-- 𝐒(−ₙ ℕ.𝟎) = +ₙ(ℕ.𝐒(ℕ.𝟎))
-- 𝐒(+ₙ n) = +ₙ(ℕ.𝐒(n))
-- 𝐒(𝟎-sign i) = reflexivity(_≡_) {𝟏} i
𝐒 : ℤ → ℤ
𝐒 = step ➕
-- Negation.
−_ : ℤ → ℤ
−(signed s n) = signed (Sign.− s) n
−(𝟎-sign i) = symmetry(_≡_) 𝟎-sign i
-- Absolute value.
abs : ℤ → ℤ
abs(signed _ n) = signed ➕ n
abs(𝟎-sign i) = 𝟎
-- Addition.
_+_ : ℤ → ℤ → ℤ
x + (signed _ ℕ.𝟎) = x
x + (signed s (ℕ.𝐒(y))) = step s (x + (signed s y))
x + 𝟎-sign i = x
-- Subtraction.
_−_ : ℤ → ℤ → ℤ
x − y = x + (− y)
import Numeral.Natural.Oper.Proofs as ℕ
_⋅_ : ℤ → ℤ → ℤ
x ⋅ y = signed ((sign x) Sign.⨯ (sign y)) ((absₙ x) ℕ.⋅ (absₙ y))
𝟎-signs : ∀{s₁ s₂} → (signed s₁ ℕ.𝟎 ≡ signed s₂ ℕ.𝟎)
𝟎-signs {➕} {➕} = reflexivity(_≡_)
𝟎-signs {➕} {➖} = symmetry(_≡_) 𝟎-sign
𝟎-signs {➖} {➕} = 𝟎-sign
𝟎-signs {➖} {➖} = reflexivity(_≡_)
-- Notes on the proof of the path:
-- 𝐏(𝟎-sign i) = −𝟏
-- 𝐒(𝐏(𝟎-sign i)) = 𝐒(−𝟏) = −𝟎
-- and
-- • i=0: const(−ₙ 0) j = −ₙ 0
-- • i=1: 𝟎-sign j
-- • j=0: −ₙ 0
-- • j=1: 𝟎-sign i
-- which means:
-- • i=0 ∧ j=0: −0 , −0
-- • i=0 ∧ j=1: −0 , −0
-- • i=1 ∧ j=0: −0 , −0
-- • i=1 ∧ j=1: +0 , +0
-- The value varies between −0 and +0. Therefore, a path between them should be used: 𝟎-sign.
-- It is −𝟎 when i or j is 0 and +𝟎 when i and j is 0. Therefore, min.
𝐒-𝐏-inverses : ∀{n} → (𝐒(𝐏(n)) ≡ n)
𝐒-𝐏-inverses {+ₙ(ℕ.𝟎)} = 𝟎-sign
𝐒-𝐏-inverses {+ₙ(ℕ.𝐒(x))} = reflexivity(_≡_)
𝐒-𝐏-inverses {−ₙ x} = reflexivity(_≡_)
𝐒-𝐏-inverses {𝟎-sign i} j = 𝟎-sign (Interval.min i j)
𝐏-𝐒-inverses : ∀{n} → (𝐏(𝐒(n)) ≡ n)
𝐏-𝐒-inverses {−ₙ(ℕ.𝟎)} = symmetry(_≡_) 𝟎-sign
𝐏-𝐒-inverses {−ₙ(ℕ.𝐒(x))} = reflexivity(_≡_)
𝐏-𝐒-inverses {+ₙ x} = reflexivity(_≡_)
𝐏-𝐒-inverses {𝟎-sign i} j = 𝟎-sign (Interval.max i (Interval.flip j))
step-inverses : ∀{s₁ s₂}{n} → ¬(Id s₁ s₂) → (step s₁ (step s₂ n) ≡ n)
step-inverses {➕} {➕} eq with () ← eq Id-intro
step-inverses {➕} {➖} eq = 𝐒-𝐏-inverses
step-inverses {➖} {➕} eq = 𝐏-𝐒-inverses
step-inverses {➖} {➖} eq with () ← eq Id-intro
open import Structure.Function.Domain
{- TODO: Is something similar to this possible? Maybe (rel = ∀{x} → Unique(P(x))) instead?
induction : ∀{ℓ} → (P : ℤ → Type{ℓ}) → (∀{x y} → (x ≡ y) → P(x) → P(y)) → ((n : ℕ) → P(−ₙ n)) → P(𝟎) → ((n : ℕ) → P(+ₙ n)) → ((n : ℤ) → P(n))
induction(P) rel neg zero pos n = elim(P) neg pos ? n
-}
open import Functional using (_∘_)
import Numeral.Sign.Proofs as Sign
open import Structure.Function
import Structure.Operator.Names as Names
open import Structure.Operator.Properties
open import Structure.Operator
𝐒-to-step : ∀{s}{n} → (signed s (ℕ.𝐒(n)) ≡ step s (signed s n))
𝐒-to-step {➕} {n} = reflexivity(_≡_)
𝐒-to-step {➖} {n} = reflexivity(_≡_)
step-swap : ∀{s₁ s₂}{x} → (step s₁ (step s₂ x) ≡ step s₂ (step s₁ x))
step-swap {➕} {➕} {x} = reflexivity(_≡_)
step-swap {➕} {➖} {x} = 𝐒-𝐏-inverses {x} 🝖 symmetry(_≡_) 𝐏-𝐒-inverses
step-swap {➖} {➕} {x} = 𝐏-𝐒-inverses {x} 🝖 symmetry(_≡_) 𝐒-𝐏-inverses
step-swap {➖} {➖} {x} = reflexivity(_≡_)
[+]ᵣ-of-step : ∀{s}{x y} → (x + step s(y) ≡ step s(x + y))
[+]ᵣ-of-step {s₁}{x} {signed s₂ n} with Sign-decidable-eq s₁ s₂
[+]ᵣ-of-step {s} {x} {signed s n} | Left Id-intro = reflexivity(_≡_)
[+]ᵣ-of-step {➕} {x} {signed ➕ n} | Right p with () ← p Id-intro
[+]ᵣ-of-step {➕} {x} {signed ➖ ℕ.𝟎} | Right _ = reflexivity(_≡_)
[+]ᵣ-of-step {➖} {x} {signed ➕ ℕ.𝟎} | Right _ = reflexivity(_≡_)
[+]ᵣ-of-step {➕} {x} {signed ➖ (ℕ.𝐒 n)} | Right _ = symmetry(_≡_) 𝐒-𝐏-inverses
[+]ᵣ-of-step {➖} {x} {signed ➕ (ℕ.𝐒 n)} | Right _ = symmetry(_≡_) 𝐏-𝐒-inverses
[+]ᵣ-of-step {➖} {x} {signed ➖ n} | Right p with () ← p Id-intro
[+]ᵣ-of-step {➕} {x} {𝟎-sign i} = reflexivity(_≡_)
[+]ᵣ-of-step {➖} {x} {𝟎-sign i} = reflexivity(_≡_)
[+]ₗ-of-step : ∀{s}{x y} → (step s(x) + y ≡ step s(x + y))
[+]ₗ-of-step {s₁} {x} {signed s₂ ℕ.𝟎} = reflexivity(_≡_)
[+]ₗ-of-step {s₁} {x} {signed s₂ (ℕ.𝐒 n)} =
step s₁ x + signed s₂ (ℕ.𝐒 n) 🝖[ _≡_ ]-[]
step s₂ (step s₁ x + signed s₂ n) 🝖[ _≡_ ]-[ congruence₂ᵣ(step)(s₂) ([+]ₗ-of-step {s₁} {x} {signed s₂ n}) ]
step s₂ (step s₁ (x + signed s₂ n)) 🝖[ _≡_ ]-[ step-swap{s₂}{s₁}{x + signed s₂ n} ]
step s₁ (step s₂ (x + signed s₂ n)) 🝖[ _≡_ ]-[ congruence₂ᵣ(step)(s₁) ([+]ᵣ-of-step {s₂} {x} {signed s₂ n}) ]-sym
step s₁ (x + step s₂ (signed s₂ n)) 🝖[ _≡_ ]-[ congruence₂ᵣ(step)(s₁) (congruence₂ᵣ(_+_)(x) (𝐒-to-step {s₂}{n})) ]-sym
step s₁ (x + signed s₂ (ℕ.𝐒 n)) 🝖-end
[+]ₗ-of-step {➕} {signed ➕ ℕ.𝟎} {𝟎-sign i} j = 𝟏
[+]ₗ-of-step {➕} {signed ➖ ℕ.𝟎} {𝟎-sign i} j = 𝟏
[+]ₗ-of-step {➖} {signed ➕ ℕ.𝟎} {𝟎-sign i} j = −𝟏
[+]ₗ-of-step {➖} {signed ➖ ℕ.𝟎} {𝟎-sign i} j = −𝟏
[+]ₗ-of-step {➕} {signed ➕ (ℕ.𝐒 n)} {𝟎-sign i} j = +ₙ (ℕ.𝐒(ℕ.𝐒 n))
[+]ₗ-of-step {➕} {signed ➖ (ℕ.𝐒 n)} {𝟎-sign i} j = −ₙ n
[+]ₗ-of-step {➖} {signed ➕ (ℕ.𝐒 n)} {𝟎-sign i} j = +ₙ n
[+]ₗ-of-step {➖} {signed ➖ (ℕ.𝐒 n)} {𝟎-sign i} j = −ₙ (ℕ.𝐒(ℕ.𝐒 n))
[+]ₗ-of-step {➕} {𝟎-sign i₁} {𝟎-sign i} j = 𝟏
[+]ₗ-of-step {➖} {𝟎-sign i₁} {𝟎-sign i} j = −𝟏
instance
[−]-involution : Involution(−_)
Involution.proof [−]-involution {signed s n} rewrite involution(Sign.−_) {s} = reflexivity(_≡_)
Involution.proof [−]-involution {𝟎-sign i} = reflexivity(_≡_)
instance
[+]-commutativity : Commutativity(_+_)
Commutativity.proof [+]-commutativity {x}{y} = p{x}{y} where
p : Names.Commutativity(_+_)
ps : ∀{x}{s}{n} → (x + signed s (ℕ.𝐒 n) ≡ signed s (ℕ.𝐒 n) + x)
ps {x}{s}{n} =
(x + signed s (ℕ.𝐒 n)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(_) (𝐒-to-step{s}{n}) ]
(x + step s(signed s n)) 🝖[ _≡_ ]-[ [+]ᵣ-of-step {s}{x}{signed s n} ]
step s(x + signed s n) 🝖[ _≡_ ]-[ congruence₂ᵣ(step)(s) (p {x} {signed s n}) ]
step s(signed s n + x) 🝖[ _≡_ ]-[ [+]ₗ-of-step {s}{signed s n}{x} ]-sym
(step s(signed s n) + x) 🝖[ _≡_ ]-[ congruence₂ₗ(_+_)(x) (𝐒-to-step{s}{n}) ]-sym
(signed s (ℕ.𝐒 n) + x) 🝖-end
{-# INLINE ps #-}
p {signed s₁ ℕ.𝟎} {signed s₂ ℕ.𝟎} = congruence₂(_+_) (𝟎-signs {s₁}{s₂}) (𝟎-signs {s₂}{s₁})
p {signed s₁ ℕ.𝟎} {signed s₂ (ℕ.𝐒 n₂)} = ps {signed s₁ ℕ.𝟎}{s₂}{n₂}
p {signed s₁ (ℕ.𝐒 n₁)} {signed s₂ ℕ.𝟎} = symmetry(_≡_) (ps {signed s₂ ℕ.𝟎}{s₁}{n₁})
p {signed s₁ (ℕ.𝐒 n₁)} {signed s₂ (ℕ.𝐒 n₂)} = ps {signed s₁ (ℕ.𝐒 n₁)}{s₂}{n₂}
p {signed ➕ ℕ.𝟎} {𝟎-sign i} j = 𝟎-sign (Interval.max i (Interval.flip j))
p {signed ➖ ℕ.𝟎} {𝟎-sign i} j = 𝟎-sign (Interval.min i j)
p {signed ➕ (ℕ.𝐒 n)} {𝟎-sign i} j = {!!}
p {signed ➖ (ℕ.𝐒 n)} {𝟎-sign i} j = {!!}
p {𝟎-sign i} {signed ➕ ℕ.𝟎} j = 𝟎-sign (Interval.max i j)
p {𝟎-sign i} {signed ➖ ℕ.𝟎} j = 𝟎-sign (Interval.min i (Interval.flip j))
p {𝟎-sign i} {signed ➕ (ℕ.𝐒 n)} j = {!!}
p {𝟎-sign i} {signed ➖ (ℕ.𝐒 n)} j = {!!}
p {𝟎-sign i} {𝟎-sign j} k = {!!}
instance
[+]-identityᵣ : Identityᵣ(_+_)(𝟎)
Identityᵣ.proof [+]-identityᵣ {signed _ _} = reflexivity(_≡_)
Identityᵣ.proof [+]-identityᵣ {𝟎-sign i} = reflexivity(_≡_)
instance
[+]-identityₗ : Identityₗ(_+_)(𝟎)
Identityₗ.proof [+]-identityₗ {x} = commutativity(_+_) {𝟎}{x} 🝖 identityᵣ(_+_)(𝟎)
instance
[+]-identity : Identity(_+_)(𝟎)
[+]-identity = intro
open import Logic.IntroInstances
instance
[+][−]-inverseFunctionᵣ : InverseFunctionᵣ(_+_)(−_)
[+][−]-inverseFunctionᵣ = intro(\{x} → p{x}) where
p : Names.InverseFunctionᵣ(_+_)(𝟎)(−_)
p {signed ➕ ℕ.𝟎} = reflexivity(_≡_)
p {signed ➖ ℕ.𝟎} = 𝟎-sign
p {signed s (ℕ.𝐒 n)} =
signed s (ℕ.𝐒 n) + (− signed s (ℕ.𝐒 n)) 🝖[ _≡_ ]-[]
signed s (ℕ.𝐒 n) + signed (Sign.− s) (ℕ.𝐒 n) 🝖[ _≡_ ]-[ congruence₂(_+_) (𝐒-to-step {s} {n}) (𝐒-to-step {Sign.− s} {n}) ]
step s (signed s n) + step (Sign.− s) (signed (Sign.− s) n) 🝖[ _≡_ ]-[ [+]ₗ-of-step {s}{signed s n}{step (Sign.− s) (signed (Sign.− s) n)} ]
step s (signed s n + step (Sign.− s) (signed (Sign.− s) n)) 🝖[ _≡_ ]-[ congruence₂ᵣ(step)(s) ([+]ᵣ-of-step {Sign.− s}{signed s n}{signed (Sign.− s) n}) ]
step s (step (Sign.− s) (signed s n + signed (Sign.− s) n)) 🝖[ _≡_ ]-[ step-inverses (Sign.[−]-no-fixpoints ∘ symmetry(Id)) ]
signed s n + signed (Sign.− s) n 🝖[ _≡_ ]-[]
signed s n + (− signed s n) 🝖[ _≡_ ]-[ p{signed s n} ]
𝟎 🝖-end
p {𝟎-sign i} j = 𝟎-sign (Interval.max i j)
instance
[+][−]-inverseFunctionₗ : InverseFunctionₗ(_+_)(−_)
InverseFunctionₗ.proof [+][−]-inverseFunctionₗ {x} = commutativity(_+_) {− x}{x} 🝖 inverseFunctionᵣ(_+_)(−_) {x}
instance
[+][−]-inverseFunction : InverseFunction(_+_)(−_)
[+][−]-inverseFunction = intro
instance
[+]-associativity : Associativity(_+_)
[+]-associativity = intro(\{x}{y}{z} → p{x}{y}{z}) where
p : Names.Associativity(_+_)
p {x} {y} {signed s ℕ.𝟎} = reflexivity(_≡_)
p {x} {y} {signed s (ℕ.𝐒 z)} =
(x + y) + signed s (ℕ.𝐒 z) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x + y) (𝐒-to-step {s}{z}) ]
(x + y) + step s (signed s z) 🝖[ _≡_ ]-[ [+]ᵣ-of-step {s}{x + y}{signed s z} ]
step s ((x + y) + signed s z) 🝖[ _≡_ ]-[ congruence₂ᵣ(step)(s) (p{x}{y}{signed s z}) ]
step s (x + (y + signed s z)) 🝖[ _≡_ ]-[ [+]ᵣ-of-step {s}{x}{y + signed s z} ]-sym
x + step s (y + signed s z) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x) ([+]ᵣ-of-step {s}{y}{signed s z}) ]-sym
x + (y + step s (signed s z)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x) (congruence₂ᵣ(_+_)(y) (𝐒-to-step {s})) ]-sym
x + (y + signed s (ℕ.𝐒 z)) 🝖-end
p {x} {y} {𝟎-sign i} = reflexivity(_≡_)
Stepᵣ-injective : ∀{s}{x y} → (step s x ≡ step s y) → (x ≡ y)
Stepᵣ-injective {s} {x} {y} p = symmetry(_≡_) (step-inverses Sign.[−]-no-fixpoints) 🝖 congruence₂ᵣ(step)(Sign.− s) p 🝖 step-inverses Sign.[−]-no-fixpoints
open import Numeral.Natural.Equiv.Path
instance
absₙ-signed-inverses : ∀{s} → Inverseᵣ(absₙ)(signed s)
Inverseᵣ.proof (absₙ-signed-inverses {➕}) = reflexivity(Path)
Inverseᵣ.proof (absₙ-signed-inverses {➖}) = reflexivity(Path)
Signedᵣ-injective : ∀{s}{x y} → (signed s x ≡ signed s y) → (Id x y)
Signedᵣ-injective {s} p = ℕ-Path-to-Id (symmetry(Path) (inverseᵣ(absₙ)(signed s)) 🝖 congruence₁(absₙ) p 🝖 inverseᵣ(absₙ)(signed s))
ℤ-different-identities : ¬(𝟎 ≡ 𝟏)
ℤ-different-identities p with () ← Signedᵣ-injective p
open import Structure.Relator
instance
postulate [⋅]-commutativity : Commutativity(_⋅_)
{-Commutativity.proof [⋅]-commutativity {signed s₁ x} {signed s₂ y} = congruence₂(signed) (sub₂(Id)(Path) (commutativity ⦃ Id-equiv ⦄ (Sign._⨯_) {s₁}{s₂})) (sub₂(Id)(Path) (commutativity ⦃ Id-equiv ⦄ (ℕ._⋅_) {x}{y}))
Commutativity.proof [⋅]-commutativity {signed ➕ x} {𝟎-sign i} j = {!!}
-- {!substitute₁(\expr → ((signed ➕ x) ⋅ expr) ≡ (expr ⋅ (signed ➕ x))) ? ?!}
Commutativity.proof [⋅]-commutativity {signed ➖ x} {𝟎-sign i} = {!sub₂(Id)(Path) ?!}
Commutativity.proof [⋅]-commutativity {𝟎-sign i} {signed s y} = {!𝟎-sign i!}
Commutativity.proof [⋅]-commutativity {𝟎-sign i} {𝟎-sign i₁} = {!!}-}
{-Commutativity.proof [⋅]-commutativity {signed s₁ x} {signed s₂ y}
rewrite commutativity ⦃ Id-equiv ⦄ (ℕ._⋅_) {x}{y}
rewrite commutativity ⦃ Id-equiv ⦄ (Sign._⨯_) {s₁}{s₂}
= reflexivity(Path)
Commutativity.proof [⋅]-commutativity {signed ➕ x} {𝟎-sign i} = {!substitute₁(\expr → ((signed ➕ x) ⋅ expr) ≡ (expr ⋅ (signed ➕ x))) ? ?!}
Commutativity.proof [⋅]-commutativity {signed ➖ x} {𝟎-sign i} = {!sub₂(Id)(Path) ?!}
Commutativity.proof [⋅]-commutativity {𝟎-sign i} {signed s y} = {!𝟎-sign i!}
Commutativity.proof [⋅]-commutativity {𝟎-sign i} {𝟎-sign i₁} = {!!}-}
-- (signed ➕ x) ⋅ -0 ≡ -0 ⋅ (signed ➕ x)
-- (signed ➕ x) ⋅ +0 ≡ +0 ⋅ (signed ➕ x)
instance
postulate [⋅]-associativity : Associativity(_⋅_)
open import Numeral.Sign.Proofs
open import Structure.Operator
instance
[⋅]-identityᵣ : Identityᵣ(_⋅_)(𝟏)
Identityᵣ.proof [⋅]-identityᵣ {signed s x} rewrite identityᵣ(Sign._⨯_)(➕) {s} = {!!}
-- rewrite identityᵣ(Sign._⨯_)(➕) {s} = {!!} -- reflexivity(Path) -- congruence₂ₗ(signed)(x) {!!}
Identityᵣ.proof [⋅]-identityᵣ {𝟎-sign i} = {!!} -- reflexivity(Path)
instance
[⋅]-identityₗ : Identityₗ(_⋅_)(𝟏)
Identityₗ.proof [⋅]-identityₗ {signed s x} = {!!}
-- rewrite identityₗ(Sign._⨯_)(➕) {s} = {!!} -- reflexivity(Path)
Identityₗ.proof [⋅]-identityₗ {𝟎-sign i} = {!!} -- reflexivity(Path)
instance
[⋅]-identity : Identity(_⋅_)(𝟏)
[⋅]-identity = intro
instance
postulate [⋅][+]-distributivityₗ : Distributivityₗ(_⋅_)(_+_)
instance
postulate [⋅][+]-distributivityᵣ : Distributivityᵣ(_⋅_)(_+_)
open import Logic.Predicate
open import Structure.Operator.Field
open import Structure.Operator.Group
open import Structure.Operator.Monoid
open import Structure.Operator.Ring
instance
[+]-monoid : Monoid(_+_)
Monoid.identity-existence [+]-monoid = [∃]-intro 𝟎
instance
[+]-group : Group(_+_)
Group.monoid [+]-group = [+]-monoid
Group.inverse-existence [+]-group = [∃]-intro (−_) ⦃ [+][−]-inverseFunction ⦄
instance
[+]-commutativeGroup : CommutativeGroup(_+_)
[+]-commutativeGroup = intro
instance
[⋅]-monoid : Monoid(_⋅_)
Monoid.identity-existence [⋅]-monoid = [∃]-intro 𝟏
instance
[⋅]-rng : Rng(_+_)(_⋅_)
[⋅]-rng = intro
instance
[⋅]-unity : Unity(_+_)(_⋅_)
Unity.[⋅]-identity-existence [⋅]-unity = [∃]-intro 𝟏
instance
[⋅]-ring : Ring(_+_)(_⋅_)
[⋅]-ring = intro
instance
[⋅]-ringNonZero : Unity.DistinctIdentities [⋅]-unity
Ring.NonZero.proof [⋅]-ringNonZero = ℤ-different-identities ∘ symmetry(_≡_)
open import Data
open import Data.Boolean
import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Data.Boolean.Stmt
open import Functional
import Numeral.Natural.Oper.Comparisons as ℕ
import Numeral.Natural.Oper.Comparisons.Proofs as ℕ
test : (−|+) → (−|+) → (ℕ → ℕ → Bool)
test ➕ ➕ = (ℕ._≤?_)
test ➕ ➖ = ((_&&_) on₂ ((!) ∘ ℕ.positive?))
test ➖ ➕ = (const ∘ const) 𝑇
test ➖ ➖ = (ℕ._≥?_)
_≤_ : ℤ → ℤ → Type{Lvl.𝟎}
signed s₁ x ≤ signed s₂ y = IsTrue(test s₁ s₂ x y)
signed ➕ ℕ.𝟎 ≤ 𝟎-sign _ = ⊤
signed ➕ (ℕ.𝐒 x) ≤ 𝟎-sign _ = ⊥
signed ➖ _ ≤ 𝟎-sign _ = ⊤
𝟎-sign _ ≤ signed ➕ _ = ⊤
𝟎-sign _ ≤ signed ➖ ℕ.𝟎 = ⊤
𝟎-sign _ ≤ signed ➖ (ℕ.𝐒 y) = ⊥
𝟎-sign _ ≤ 𝟎-sign _ = ⊤
{-data _≤_ : ℤ → ℤ → Type{Lvl.𝟎} where
neg : ∀{x y} → (x ℕ.≥ y) → ((signed ➖ x) ≤ (signed ➖ y))
mix : ∀{x y} → ((signed ➖ x) ≤ (signed ➕ y))
pos : ∀{x y} → (x ℕ.≤ y) → ((signed ➕ x) ≤ (signed ➕ y))
-}
instance
[≤]-reflexivity : Reflexivity(_≤_)
Reflexivity.proof [≤]-reflexivity {signed ➕ ℕ.𝟎} = <>
Reflexivity.proof [≤]-reflexivity {signed ➕ (ℕ.𝐒 x)} = ℕ.[≤?]-reflexivity {x}
Reflexivity.proof [≤]-reflexivity {signed ➖ ℕ.𝟎} = <>
Reflexivity.proof [≤]-reflexivity {signed ➖ (ℕ.𝐒 x)} = ℕ.[≤?]-reflexivity {x}
Reflexivity.proof [≤]-reflexivity {𝟎-sign i} = <>
{-
instance
[≤]-antisymmetry : Antisymmetry(_≤_)(_≡_)
Antisymmetry.proof [≤]-antisymmetry {signed x x₁} {signed x₂ x₃} lt gt = ?
Antisymmetry.proof [≤]-antisymmetry {signed x x₁} {𝟎-sign i} lt gt = ?
Antisymmetry.proof [≤]-antisymmetry {𝟎-sign i} {signed x x₁} lt gt = ?
Antisymmetry.proof [≤]-antisymmetry {𝟎-sign i} {𝟎-sign i₁} lt gt = ?
-}
|
{
"alphanum_fraction": 0.5622273682,
"avg_line_length": 39.592750533,
"ext": "agda",
"hexsha": "7138816562912913fdea04034d1c4a6d6fd27e06",
"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": "Miscellaneous/CubicalInteger.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": "Miscellaneous/CubicalInteger.agda",
"max_line_length": 218,
"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": "Miscellaneous/CubicalInteger.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": 8644,
"size": 18569
}
|
-- simply-typed label-dependent λ-calculus w/ DeBruijn indices
-- {-# OPTIONS --show-implicit #-}
module LDLC where
open import Agda.Primitive
open import Agda.Builtin.Bool
open import Data.Bool.Properties hiding (≤-trans ; <-trans ; ≤-refl ; <-irrefl)
open import Data.Empty
open import Data.Nat renaming (_+_ to _+ᴺ_ ; _≤_ to _≤ᴺ_ ; _≥_ to _≥ᴺ_ ; _<_ to _<ᴺ_ ; _>_ to _>ᴺ_ ; _≟_ to _≟ᴺ_)
open import Data.Nat.Properties renaming (_<?_ to _<ᴺ?_)
open import Data.Integer renaming (_+_ to _+ᶻ_ ; _≤_ to _≤ᶻ_ ; _≥_ to _≥ᶻ_ ; _<_ to _<ᶻ_ ; _>_ to _>ᶻ_)
open import Data.Integer.Properties using (⊖-≥ ; 0≤n⇒+∣n∣≡n ; +-monoˡ-≤)
open import Data.List hiding (length ; _++_)
open import Data.List.Relation.Unary.All
open import Relation.Unary using (Decidable)
open import Data.Vec.Relation.Unary.Any
open import Data.Vec.Base hiding (length ; _++_ ; foldr)
open import Relation.Binary.PropositionalEquality renaming (trans to ≡-trans)
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Nullary.Negation
open import Data.Fin
open import Data.Fin.Subset renaming (∣_∣ to ∣_∣ˢ)
open import Data.Fin.Subset.Properties using (anySubset?)
open import Data.Fin.Properties using (any?)
open import Data.Product
open import Data.Sum
open import Function
open import Extensionality
open import Auxiliary
module defs where
data Exp {n : ℕ} : Set where
Var : ℕ → Exp {n}
Abs : Exp {n} → Exp {n}
App : Exp {n} → Exp {n} → Exp {n}
LabI : Fin n → Exp {n}
LabE : {s : Subset n} → (f : ∀ l → l ∈ s → Exp {n}) → Exp {n} → Exp {n}
Prod : Exp {n} → Exp {n} → Exp {n}
Let : Exp {n} → Exp {n} → Exp {n}
data Val {n : ℕ} : Exp {n} → Set where
VVar : {n : ℕ} → Val (Var n)
VLab : {x : Fin n} → Val (LabI x)
VFun : {e : Exp} → Val (Abs e)
VProd : {e e' : Exp} → Val e → Val e' → Val (Prod e e')
data Ty {n : ℕ} : Set where
Label : Subset n → Ty
Pi : Ty {n} → Ty {n} → Ty
Sigma : Ty {n} → Ty {n} → Ty
Case : {s : Subset n} → (f : ∀ l → l ∈ s → Ty {n}) → Exp{n} → Ty
-- shifting and substitution
-- shifting, required to avoid variable-capturing in substitution
-- see Pierce 2002, pg. 78/79
↑ᴺ_,_[_] : ℤ → ℕ → ℕ → ℕ
↑ᴺ d , c [ x ]
with (x <ᴺ? c)
... | yes p = x
... | no ¬p = ∣ ℤ.pos x +ᶻ d ∣
↑_,_[_] : ∀ {n} → ℤ → ℕ → Exp {n} → Exp
↑ d , c [ Var x ] = Var (↑ᴺ d , c [ x ])
↑ d , c [ Abs t ] = Abs (↑ d , (ℕ.suc c) [ t ])
↑ d , c [ App t t₁ ] = App (↑ d , c [ t ]) (↑ d , c [ t₁ ])
↑ d , c [ LabI x ] = LabI x
↑ d , c [ LabE f e ] = LabE (λ l x → ↑ d , c [ (f l x) ]) (↑ d , c [ e ])
↑ d , c [ Prod e e' ] = Prod (↑ d , c [ e ]) (↑ d , (ℕ.suc c) [ e' ])
↑ d , c [ Let e e' ] = Let (↑ d , c [ e ]) (↑ d , (ℕ.suc (ℕ.suc c)) [ e' ])
-- shorthands
↑¹[_] : ∀ {n} → Exp {n} → Exp
↑¹[ e ] = ↑ (ℤ.pos 1) , 0 [ e ]
↑⁻¹[_] : ∀ {n} → Exp {n} → Exp
↑⁻¹[ e ] = ↑ (ℤ.negsuc 0) , 0 [ e ]
-- substitution
-- see Pierce 2002, pg. 80
[_↦_]_ : ∀ {n} → ℕ → Exp {n} → Exp → Exp
[ k ↦ s ] Var x
with (_≟ᴺ_ x k)
... | yes p = s
... | no ¬p = Var x
[ k ↦ s ] Abs t = Abs ([ ℕ.suc k ↦ ↑¹[ s ] ] t)
[ k ↦ s ] App t t₁ = App ([ k ↦ s ] t) ([ k ↦ s ] t₁)
[ k ↦ s ] LabI ins = LabI ins
[ k ↦ s ] LabE f e = LabE (λ l x → [ k ↦ s ] (f l x)) ([ k ↦ s ] e)
[ k ↦ s ] Prod e e' = Prod ([ k ↦ s ] e) ([ ℕ.suc k ↦ ↑¹[ s ] ] e')
[ k ↦ s ] Let e e' = Let ([ k ↦ s ] e) ([ (ℕ.suc (ℕ.suc k)) ↦ ↑ (ℤ.pos 2) , 0 [ s ] ] e')
-- type substitution
[_↦_]ᵀ_ : ∀ {n} → ℕ → Exp {n} → Ty {n} → Ty {n}
[ k ↦ s ]ᵀ Label x = Label x
[ k ↦ s ]ᵀ Pi t t₁ = Pi ([ k ↦ s ]ᵀ t) ([ k ↦ s ]ᵀ t₁)
[ k ↦ s ]ᵀ Sigma t t₁ = Sigma ([ k ↦ s ]ᵀ t) ([ k ↦ s ]ᵀ t₁)
[ k ↦ s ]ᵀ Case f e = Case (λ l x → [ k ↦ s ]ᵀ (f l x)) ([ k ↦ s ] e)
-- variable in expression
data _∈`_ {N : ℕ} : ℕ → Exp {N} → Set where
in-Var : {n : ℕ} → n ∈` Var n
in-Abs : {n : ℕ} {e : Exp} → (ℕ.suc n) ∈` e → n ∈` Abs e
in-App : {n : ℕ} {e e' : Exp} → n ∈` e ⊎ n ∈` e' → n ∈` App e e'
in-LabE : {n : ℕ} {s : Subset N} {f : (∀ l → l ∈ s → Exp {N})} {e : Exp {N}} → (∃₂ λ l i → n ∈` (f l i)) ⊎ n ∈` e → n ∈` LabE {N} {s} f e
in-Prod : {n : ℕ} {e e' : Exp} → n ∈` e ⊎ (ℕ.suc n) ∈` e' → n ∈` Prod e e'
in-Let : {n : ℕ} {e e' : Exp} → n ∈` e ⊎ (ℕ.suc (ℕ.suc n)) ∈` e' → n ∈` Let e e'
-- variable in type
data _∈`ᵀ_ {N : ℕ} : ℕ → Ty {N} → Set where
in-Pi : {n : ℕ} {A B : Ty {N}} → n ∈`ᵀ A ⊎ n ∈`ᵀ B → n ∈`ᵀ Pi A B
in-Sigma : {n : ℕ} {A B : Ty {N}} → n ∈`ᵀ A ⊎ n ∈`ᵀ B → n ∈`ᵀ Sigma A B
in-Case : {n : ℕ} {s : Subset N} {f : ∀ l → l ∈ s → Ty {N}} {e : Exp {N}} → (∃₂ λ l i → n ∈`ᵀ (f l i)) ⊎ n ∈` e → n ∈`ᵀ Case f e
-- Type environment, formation and typing of expressions
data TEnv {n : ℕ} : Set
data _∶_∈_ {n : ℕ} : ℕ → Ty {n} → TEnv {n} → Set
data _⊢_ {n : ℕ} : TEnv {n} → Ty {n} → Set
data _⊢_∶_ {n : ℕ} : TEnv {n} → Exp {n} → Ty {n} → Set
data _⊢_≡ᵀ_ {n : ℕ} : TEnv {n} → Ty {n} → Ty {n} → Set
data _⊢_≡ᵀ'_ {n : ℕ} : TEnv {n} → Ty {n} → Ty {n} → Set
data TEnv {n} where
[] : TEnv
⟨_,_⟩ : (T : Ty) (Γ : TEnv {n}) {ok : Γ ⊢ T} → TEnv
length : {n : ℕ} → TEnv {n} → ℕ
length [] = 0
length ⟨ T , Γ ⟩ = ℕ.suc (length Γ)
-- env-tail ⟨ A , B , C , [] ⟩ 0 = ⟨ B , C , [] ⟩
env-tail : {n : ℕ} → TEnv {n} → ℕ → TEnv {n}
env-tail [] n = []
env-tail ⟨ T , Γ ⟩ zero = Γ
env-tail ⟨ T , Γ ⟩ (ℕ.suc n) = env-tail Γ n
data _∶_∈_ {n} where
here : {T : Ty} {Γ : TEnv} {ok : Γ ⊢ T} → 0 ∶ T ∈ ⟨ T , Γ ⟩ {ok}
there : {n : ℕ} {T₁ T₂ : Ty} {Γ : TEnv} {ok : Γ ⊢ T₂} → n ∶ T₁ ∈ Γ → (ℕ.suc n) ∶ T₁ ∈ ⟨ T₂ , Γ ⟩ {ok}
-- Type formation
data _⊢_ {n} where
TLabF : {Γ : TEnv {n}} {s : Subset n} → Γ ⊢ Label s
TPiF : {Γ : TEnv {n}} {A B : Ty} → (ok : Γ ⊢ A) → ⟨ A , Γ ⟩ {ok} ⊢ B → Γ ⊢ Pi A B
TSigmaF : {Γ : TEnv {n}} {A B : Ty} → (ok : Γ ⊢ A) → ⟨ A , Γ ⟩ {ok} ⊢ B → Γ ⊢ Sigma A B
TCaseF : {Γ : TEnv {n}} {s : Subset n} {e : Exp {n}} {f : ∀ l → l ∈ s → Ty} → (f' : ∀ l i → Γ ⊢ (f l i))
→ (v : Val e)
→ Γ ⊢ e ∶ Label s
→ Γ ⊢ Case {n} {s} f e
-- Typing expressions
data _⊢_∶_ {n} where
TConv : {Γ : TEnv} {T T' : Ty {n}} {e : Exp} → Γ ⊢ e ∶ T → Γ ⊢ T ≡ᵀ T' → Γ ⊢ e ∶ T'
TVarE : {m : ℕ} {Γ : TEnv} {T T' : Ty} → m ∶ T ∈ Γ → env-tail Γ m ⊢ T' ≡ᵀ T → Γ ⊢ (Var m) ∶ T'
-- adjustment: env-tail Γ m ⊢ T' ≡ᵀ T
--
-- Terms of the form ⟨ A , Γ ⟩ ⊢ Var 0 ∶ B can occur through type conversion (if ≡ᵀ⇒⊢, i.e. Γ ⊢ A ≡ᵀ B ⇒ Γ ⊢ A × Γ ⊢ B, should hold), e.g.:
--
--- ∅ ⊢ Label ≡ᵀ (Case (λ ⇒ Label) l)
--- ⟨ Label , ∅ ⟩ ⊢ (Case (λ ⇒ Label) 0) ≡ᵀ (Case (λ ⇒ Label) 0)
---- ∅ ⊢ Pi Label (Case (λ ⇒ Label) 0) ≡ᵀ Pi (Case (λ ⇒ Label) l) (Case (λ ⇒ Label) 0)
--
--- (Γ ⊢ A ≡ᵀ B ⇒ Γ ⊢ A × Γ ⊢ B)
--- ∅ ⊢ Pi Label (Case (λ ⇒ Label) 0) ≡ᵀ Pi (Case (λ ⇒ Label) l) (Case (λ ⇒ Label) 0)
---- ∅ ⊢ Pi (Case (λ ⇒ Label) l) (Case (λ ⇒ Label) 0)
----- ⟨ (Case (λ ⇒ Label) l) , ∅ ⟩ ⊢ (Case (λ ⇒ Label) 0)
------ ⟨ (Case (λ ⇒ Label) l) , ∅ ⟩ ⊢ 0 : Label
TPiI : {Γ : TEnv} {A B : Ty} {e : Exp} {ok : Γ ⊢ A} {ok' : ⟨ A , Γ ⟩ {ok} ⊢ B} → ⟨ A , Γ ⟩ {ok} ⊢ e ∶ B → Γ ⊢ (Abs e) ∶ (Pi A B)
TPiE : {Γ : TEnv} {A B : Ty} {e e' : Exp} → Γ ⊢ e ∶ (Pi A B) → Γ ⊢ e' ∶ A → Γ ⊢ ([ 0 ↦ e' ]ᵀ B) → Γ ⊢ App e e' ∶ ([ 0 ↦ e' ]ᵀ B)
TSigmaI : {Γ : TEnv} {A B : Ty} {e e' : Exp} {ok : Γ ⊢ A} {ok' : ⟨ A , Γ ⟩ {ok} ⊢ B} → Γ ⊢ e ∶ A → ⟨ A , Γ ⟩ {ok} ⊢ e' ∶ B → Γ ⊢ Prod e e' ∶ (Sigma A B)
-- adjustment (also in TPiI): {ok' : ⟨ A , Γ ⟩ ⊢ B}
--
-- since I couldn't prove that it holds without the rule (Γ ⊢ e ∶ T does not imply Γ ⊢ T, see TSigmaE: Let e e' ∶ C because of e')
TSigmaE : {Γ : TEnv {n}} {A B C : Ty} {e e' : Exp} {ok : Γ ⊢ A} {ok' : ⟨ A , Γ ⟩ {ok} ⊢ B} → Γ ⊢ e ∶ (Sigma A B)
→ ⟨ B , ⟨ A , Γ ⟩ {ok} ⟩ {ok'} ⊢ e' ∶ C
→ ¬ (0 ∈`ᵀ C) × ¬ (1 ∈`ᵀ C)
→ Γ ⊢ Let e e' ∶ C
TLabI : {Γ : TEnv} {x : Fin n} {s : Subset n} → (ins : x ∈ s) → Γ ⊢ LabI x ∶ Label {n} s
TLabEl : {Γ : TEnv {n}} {T : Ty} {s : Subset n} {x : Fin n} {ins : x ∈ s} {f : ∀ l → l ∈ s → Exp} {scopecheck : ∀ l i m → m ∈` (f l i) → m <ᴺ length Γ}
→ Γ ⊢ f x ins ∶ T
→ Γ ⊢ LabI {n} x ∶ Label {n} s
→ Γ ⊢ LabE {n} {s} f (LabI {n} x) ∶ T
TLabEx : {Γ : TEnv} {T : Ty {n}} {m : ℕ} {s : Subset n} {f : ∀ l → l ∈ s → Exp} {g : ∀ l → l ∈ s → Ty {n}}
→ (u : ∀ l i → (Γ ⊢ [ m ↦ (LabI l) ] (f l i) ∶ (g l i)))
→ Γ ⊢ Var m ∶ Label {n} s
→ Γ ⊢ LabE {n} {s} f (Var m) ∶ Case g (Var m)
-- Type conversion
data _⊢_≡ᵀ_ {n} where
CRefl : {Γ : TEnv {n}} {T : Ty} {ok : Γ ⊢ T} → Γ ⊢ T ≡ᵀ T
CSym : {Γ : TEnv {n}} {T T' : Ty} → Γ ⊢ T ≡ᵀ T' → Γ ⊢ T' ≡ᵀ T
CTrans : {Γ : TEnv {n}} {T T' T'' : Ty} → Γ ⊢ T ≡ᵀ T' → Γ ⊢ T' ≡ᵀ T'' → Γ ⊢ T ≡ᵀ T''
CLabEta : {Γ : TEnv {n}} {s : Subset n} {x : Fin n} {T : Ty} {ins : x ∈ s} → Γ ⊢ LabI x ∶ Label s → Γ ⊢ T → Γ ⊢ T ≡ᵀ (Case {s = s} (λ l i → T) (LabI x))
CLabBeta : {Γ : TEnv {n}} {s : Subset n} {x : Fin n} {f : (∀ l → l ∈ s → Ty)} → Γ ⊢ Case f (LabI x) → (ins : x ∈ s) → Γ ⊢ Case f (LabI x) ≡ᵀ (f x ins)
CPi : {Γ : TEnv {n}} {A B A' B' : Ty} {ok : Γ ⊢ A} → Γ ⊢ A ≡ᵀ B → ⟨ A , Γ ⟩ {ok} ⊢ A' ≡ᵀ B' → Γ ⊢ Pi A A' ≡ᵀ Pi B B'
CSigma : {Γ : TEnv {n}} {A B A' B' : Ty} {ok : Γ ⊢ A} → Γ ⊢ A ≡ᵀ B → ⟨ A , Γ ⟩ {ok} ⊢ A' ≡ᵀ B' → Γ ⊢ Sigma A A' ≡ᵀ Sigma B B'
CLab : {Γ : TEnv {n}} {s : Subset n} {f f' : (∀ l → l ∈ s → Ty)} {e : Exp {n}} → (Γ ⊢ Case f e) → (∀ l i → Γ ⊢ (f l i) ≡ᵀ (f' l i)) → Γ ⊢ Case f e ≡ᵀ Case f' e
-- adjustment: (Val e) -> (Γ ⊢ Case f e) else illegal terms possible and property ≡ᵀ⇒⊢ wouldn't hold (i.e. Γ ⊢ A ≡ᵀ B ⇒ Γ ⊢ A × Γ ⊢ B)
-- Type conversion without explicit transitivity and symmetry
data _⊢_≡ᵀ'_ {n} where
CRefl' : {Γ : TEnv {n}} {T : Ty} {ok : Γ ⊢ T} → Γ ⊢ T ≡ᵀ' T
CLabEta' : {Γ : TEnv {n}} {s : Subset n} {x : Fin n} {T : Ty} {ins : x ∈ s} {f : (∀ l → l ∈ s → Ty)}
→ Γ ⊢ LabI x ∶ Label s → (∀ l → (ins' : l ∈ s) → Γ ⊢ f l ins')
→ (Γ ⊢ f x ins ≡ᵀ' T)
→ Γ ⊢ T ≡ᵀ' (Case {s = s} f (LabI x))
CLabBeta' : {Γ : TEnv {n}} {s : Subset n} {x : Fin n} {f : (∀ l → l ∈ s → Ty)} {T : Ty {n}}
→ Γ ⊢ Case f (LabI x) → (ins : x ∈ s) → (Γ ⊢ f x ins ≡ᵀ' T) → Γ ⊢ Case f (LabI x) ≡ᵀ' T
CPi' : {Γ : TEnv {n}} {A B A' B' : Ty} {ok : Γ ⊢ A} → Γ ⊢ A ≡ᵀ' B → (⟨ A , Γ ⟩ {ok} ⊢ A' ≡ᵀ' B')→ Γ ⊢ Pi A A' ≡ᵀ' Pi B B'
CSigma' : {Γ : TEnv {n}} {A B A' B' : Ty} {ok : Γ ⊢ A} → Γ ⊢ A ≡ᵀ' B → ⟨ A , Γ ⟩ {ok} ⊢ A' ≡ᵀ' B' → Γ ⊢ Sigma A A' ≡ᵀ' Sigma B B'
CLab' : {Γ : TEnv {n}} {s : Subset n} {f f' : (∀ l → l ∈ s → Ty)} {e : Exp {n}} {ok : ∀ l' → (i : l' ∈ s) → Γ ⊢ f l' i} {ok' : ∀ l' → (i : l' ∈ s) → Γ ⊢ f' l' i}
→ (Γ ⊢ Case f e) → (∀ l i → Γ ⊢ (f l i) ≡ᵀ' (f' l i)) → Γ ⊢ Case f e ≡ᵀ' Case f' e
-- Type environment equivalency for ≡ᵀ
data _≡ᵀ_ {n} : TEnv {n} → TEnv {n} → Set where
tzero : [] ≡ᵀ []
tsuc : {Γ Δ : TEnv {n}} {T T' : Ty} {ok : Γ ⊢ T} {ok' : Δ ⊢ T'} → Γ ≡ᵀ Δ → Δ ⊢ T ≡ᵀ T' → ⟨ T , Γ ⟩ {ok} ≡ᵀ ⟨ T' , Δ ⟩ {ok'}
≡ᵀ-tail : {n : ℕ} {Γ Δ : TEnv {n}} → (m : ℕ) → Γ ≡ᵀ Δ → env-tail Γ m ≡ᵀ env-tail Δ m
≡ᵀ-tail {n} {.[]} {.[]} m tzero = tzero
≡ᵀ-tail {n} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} zero (tsuc eq x) = eq
≡ᵀ-tail {n} {(⟨ T , Γ ⟩)} {(⟨ T' , Δ ⟩)} (ℕ.suc m) (tsuc eq x) = ≡ᵀ-tail m eq
≡ᵀ-length : {n : ℕ} {Γ Δ : TEnv {n}} → Γ ≡ᵀ Δ → length Γ ≡ length Δ
≡ᵀ-length {n} {.[]} {.[]} tzero = refl
≡ᵀ-length {n} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} (tsuc eq x) = cong ℕ.suc (≡ᵀ-length eq)
env-tail-in : {n m : ℕ} {T : Ty {n}} {Γ : TEnv} → (ℕ.suc m) ∶ T ∈ Γ → 0 ∶ T ∈ env-tail Γ m
env-tail-in {n} {.0} {T} {.(⟨ _ , ⟨ T , _ ⟩ ⟩)} (there here) = here
env-tail-in {n} {(ℕ.suc m)} {T} {(⟨ T' , ⟨ T'' , Γ ⟩ ⟩)} (there (there ins)) = env-tail-in (there ins)
-- DEFINITIONS
≡ᵀ-extr : {n m : ℕ} {Γ Δ : TEnv} {A : Ty {n}} → (m ∶ A ∈ Γ) → Γ ≡ᵀ Δ → ∃[ B ] (m ∶ B ∈ Δ × (env-tail Δ m) ⊢ A ≡ᵀ B)
⊢-envsub : {n : ℕ} {A : Ty {n}} {Γ Δ : TEnv {n}} → Γ ⊢ A → Γ ≡ᵀ Δ → Δ ⊢ A
⊢∶-envsub : {n : ℕ} {A : Ty {n}} {Γ Δ : TEnv {n}} {e : Exp} → Γ ⊢ e ∶ A → Γ ≡ᵀ Δ → Δ ⊢ e ∶ A
⊢≡ᵀ-envsub : {n : ℕ} {A B : Ty {n}} {Γ Δ : TEnv {n}} → Γ ⊢ A ≡ᵀ B → Γ ≡ᵀ Δ → Δ ⊢ A ≡ᵀ B
-- IMPLEMENTATIONS
≡ᵀ-extr {n} {.0} {(⟨ A , Γ ⟩)} {(⟨ B , Δ ⟩)} {.A} here (tsuc eq x) = B , (here , x)
≡ᵀ-extr {n} {.(ℕ.suc _)} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} {A} (there j) (tsuc eq x)
with ≡ᵀ-extr j eq
... | fst , snd , snd₁ = fst , ((there snd) , snd₁)
⊢-envsub {n} {.(Label _)} {Γ} {Δ} TLabF eq = TLabF
⊢-envsub {n} {.(Pi _ _)} {Γ} {Δ} (TPiF j j₁) eq = TPiF (⊢-envsub j eq) (⊢-envsub j₁ (tsuc eq (CRefl{ok = ⊢-envsub j eq})))
⊢-envsub {n} {.(Sigma _ _)} {Γ} {Δ} (TSigmaF j j₁) eq = TSigmaF (⊢-envsub j eq) (⊢-envsub j₁ (tsuc eq (CRefl{ok = ⊢-envsub j eq})))
⊢-envsub {n} {.(Case _ _)} {Γ} {Δ} (TCaseF f' v x) eq = TCaseF (λ l i → ⊢-envsub (f' l i) eq) v (⊢∶-envsub x eq)
⊢∶-envsub {n} {A} {Γ} {Δ} {e} (TConv j x) eq = TConv (⊢∶-envsub j eq) (⊢≡ᵀ-envsub x eq)
⊢∶-envsub {n} {A} {Γ} {Δ} {Var m} (TVarE j eq') eq = TVarE (proj₁ (proj₂ (≡ᵀ-extr j eq))) (CTrans (⊢≡ᵀ-envsub eq' (≡ᵀ-tail m eq)) (proj₂ (proj₂ (≡ᵀ-extr j eq))))
⊢∶-envsub {n} {.(Pi _ _)} {Γ} {Δ} {.(Abs _)} (TPiI{ok = ok}{ok' = ok'} j) eq = TPiI{ok = ⊢-envsub ok eq}{ok' = ⊢-envsub ok' (tsuc eq (CRefl{ok = ⊢-envsub ok eq}))} (⊢∶-envsub j (tsuc eq (CRefl{ok = ⊢-envsub ok eq})))
⊢∶-envsub {n} {.([ 0 ↦ _ ]ᵀ _)} {Γ} {Δ} {.(App _ _)} (TPiE j j₁ x) eq = TPiE (⊢∶-envsub j eq) (⊢∶-envsub j₁ eq) (⊢-envsub x eq)
⊢∶-envsub {n} {.(Sigma _ _)} {Γ} {Δ} {.(Prod _ _)} (TSigmaI {ok = ok}{ok' = ok'} j j₁) eq = TSigmaI {ok = ⊢-envsub ok eq}{ok' = ⊢-envsub ok' (tsuc eq (CRefl{ok = ⊢-envsub ok eq}))} (⊢∶-envsub j eq) (⊢∶-envsub j₁ (tsuc eq (CRefl{ok = ⊢-envsub ok eq})))
⊢∶-envsub {n} {A} {Γ} {Δ} {.(Let _ _)} (TSigmaE {ok = ok} {ok' = ok'} j j₁ nin) eq
= TSigmaE{ok = ⊢-envsub ok eq}{ok' = ⊢-envsub ok' (tsuc eq (CRefl{ok = ⊢-envsub ok eq}))} (⊢∶-envsub j eq) (⊢∶-envsub j₁ (tsuc (tsuc eq (CRefl{ok = ⊢-envsub ok eq})) (CRefl{ok = ⊢-envsub ok' (tsuc eq (CRefl{ok = ⊢-envsub ok eq}))}))) nin
⊢∶-envsub {n} {.(Label _)} {Γ} {Δ} {.(LabI _)} (TLabI ins) eq = TLabI ins
⊢∶-envsub {n} {A} {Γ} {Δ} {.(LabE _ (LabI _))} (TLabEl{scopecheck = scopecheck} j j₁) eq rewrite (≡ᵀ-length eq) = TLabEl{scopecheck = scopecheck} (⊢∶-envsub j eq) (⊢∶-envsub j₁ eq)
⊢∶-envsub {n} {A} {Γ} {Δ} {.(LabE _ (Var _))} (TLabEx{T = T} f' j) eq = TLabEx{T = T} (λ l i → ⊢∶-envsub (f' l i) eq) (⊢∶-envsub j eq)
⊢≡ᵀ-envsub {n} {A} {.A} {Γ} {Δ} (CRefl{ok = ok}) eq = CRefl{ok = ⊢-envsub ok eq}
⊢≡ᵀ-envsub {n} {A} {B} {Γ} {Δ} (CSym j) eq = CSym (⊢≡ᵀ-envsub j eq)
⊢≡ᵀ-envsub {n} {A} {B} {Γ} {Δ} (CTrans j j₁) eq = CTrans (⊢≡ᵀ-envsub j eq) (⊢≡ᵀ-envsub j₁ eq)
⊢≡ᵀ-envsub {n} {A} {.(Case (λ l i → A) (LabI _))} {Γ} {Δ} (CLabEta{ins = ins} x x₁) eq = CLabEta{ins = ins} (⊢∶-envsub x eq) (⊢-envsub x₁ eq)
⊢≡ᵀ-envsub {n} {(Case f (LabI l))} {.(f l ins)} {Γ} {Δ} (CLabBeta x ins) eq = CLabBeta ((⊢-envsub x eq)) ins
⊢≡ᵀ-envsub {n} {.(Pi _ _)} {.(Pi _ _)} {Γ} {Δ} (CPi{ok = ok} j j₁) eq = CPi{ok = ⊢-envsub ok eq} (⊢≡ᵀ-envsub j eq) (⊢≡ᵀ-envsub j₁ (tsuc eq (CRefl{ok = ⊢-envsub ok eq})))
⊢≡ᵀ-envsub {n} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} {Δ} (CSigma{ok = ok} j j₁) eq = CSigma{ok = ⊢-envsub ok eq} (⊢≡ᵀ-envsub j eq) (⊢≡ᵀ-envsub j₁ (tsuc eq (CRefl{ok = ⊢-envsub ok eq})))
⊢≡ᵀ-envsub {n} {.(Case _ _)} {.(Case _ _)} {Γ} {Δ} (CLab v x) eq = CLab (⊢-envsub v eq) (λ l i → ⊢≡ᵀ-envsub (x l i) eq)
-- uniqueness of judgements
val-uniqueness : {n : ℕ} {e : Exp {n}} → (v v' : Val e) → v ≡ v'
val-uniqueness {n} {.(Var n₁)} (VVar {n = n₁}) (VVar {n = .n₁}) = refl
val-uniqueness {n} {.(LabI x)} (VLab {x = x}) (VLab {x = .x}) = refl
val-uniqueness {n} {.(Abs e)} (VFun {e = e}) (VFun {e = .e}) = refl
val-uniqueness {n} {.(Prod e e')} (VProd {e = e} {e' = e'} v v') (VProd {e = .e} {e' = .e'} v₁ v₁') = cong₂ VProd (val-uniqueness v v₁) (val-uniqueness v' v₁')
ins-uniqueness : {n : ℕ} {s : Subset n} {l : Fin n} → (i i' : l ∈ s) → i ≡ i'
ins-uniqueness {.(ℕ.suc _)} {.(true ∷ _)} {.zero} here here = refl
ins-uniqueness {.(ℕ.suc _)} {.(_ ∷ _)} {.(Fin.suc _)} (there i) (there i') = cong there (ins-uniqueness i i')
-- Type environment equivalency for ≡ᵀ'
data _≡ᵀ'_ {n} : TEnv {n} → TEnv {n} → Set where
tzero : [] ≡ᵀ' []
tsuc : {Γ Δ : TEnv {n}} {T T' : Ty} {ok : Γ ⊢ T} {ok' : Δ ⊢ T'} → Γ ≡ᵀ' Δ → Δ ⊢ T ≡ᵀ' T' → ⟨ T , Γ ⟩ {ok} ≡ᵀ' ⟨ T' , Δ ⟩ {ok'}
≡ᵀ'-refl : {n : ℕ} {Γ : TEnv {n}} → Γ ≡ᵀ' Γ
≡ᵀ'-refl {n} {[]} = tzero
≡ᵀ'-refl {n} {⟨ T , Γ ⟩ {ok = ok}} = tsuc ≡ᵀ'-refl (CRefl'{ok = ok})
≡ᵀ'-tail : {n : ℕ} {Γ Δ : TEnv {n}} → (m : ℕ) → Γ ≡ᵀ' Δ → env-tail Γ m ≡ᵀ' env-tail Δ m
≡ᵀ'-tail {n} {.[]} {.[]} m tzero = tzero
≡ᵀ'-tail {n} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} zero (tsuc eq x) = eq
≡ᵀ'-tail {n} {(⟨ T , Γ ⟩)} {(⟨ T' , Δ ⟩)} (ℕ.suc m) (tsuc eq x) = ≡ᵀ'-tail m eq
≡ᵀ'-length : {n : ℕ} {Γ Δ : TEnv {n}} → Γ ≡ᵀ' Δ → length Γ ≡ length Δ
≡ᵀ'-length {n} {.[]} {.[]} tzero = refl
≡ᵀ'-length {n} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} (tsuc eq x) = cong ℕ.suc (≡ᵀ'-length eq)
-- DEFINITIONS
⊢∧≡ᵀ'⇒⊢ : {n : ℕ} {Γ : TEnv {n}} {T T' : Ty} → Γ ⊢ T → Γ ⊢ T ≡ᵀ' T' → Γ ⊢ T'
≡ᵀ'⇒⊢ : {n : ℕ} {Γ : TEnv {n}} {T T' : Ty} → Γ ⊢ T ≡ᵀ' T' → Γ ⊢ T × Γ ⊢ T'
≡ᵀ⊆≡ᵀ' : {n : ℕ} {A B : Ty {n}} {Γ : TEnv {n}} → Γ ⊢ A ≡ᵀ B → Γ ⊢ A ≡ᵀ' B
≡ᵀ'⊆≡ᵀ : {n : ℕ} {A B : Ty {n}} {Γ : TEnv {n}} → Γ ⊢ A ≡ᵀ' B → Γ ⊢ A ≡ᵀ B
≡ᵀ⊆≡ᵀ'-env : {n : ℕ} {Γ Δ : TEnv {n}} → Γ ≡ᵀ Δ → Γ ≡ᵀ' Δ
≡ᵀ'⊆≡ᵀ-env : {n : ℕ} {Γ Δ : TEnv {n}} → Γ ≡ᵀ' Δ → Γ ≡ᵀ Δ
≡ᵀ'-trans : {n : ℕ} {A B C : Ty {n}} {Γ : TEnv {n}} → Γ ⊢ A ≡ᵀ' B → Γ ⊢ B ≡ᵀ' C → Γ ⊢ A ≡ᵀ' C
≡ᵀ'-sym : {n : ℕ} {A B : Ty {n}} {Γ : TEnv {n}} → Γ ⊢ A ≡ᵀ' B → Γ ⊢ B ≡ᵀ' A
≡ᵀ-extr' : {n m : ℕ} {Γ Δ : TEnv} {A : Ty {n}} → (m ∶ A ∈ Γ) → Γ ≡ᵀ' Δ → ∃[ B ] (m ∶ B ∈ Δ × (env-tail Δ m) ⊢ A ≡ᵀ' B)
⊢-envsub' : {n : ℕ} {A : Ty {n}} {Γ Δ : TEnv {n}} → Γ ⊢ A → Γ ≡ᵀ' Δ → Δ ⊢ A
⊢∶-envsub' : {n : ℕ} {A : Ty {n}} {Γ Δ : TEnv {n}} {e : Exp} → Γ ⊢ e ∶ A → Γ ≡ᵀ' Δ → Δ ⊢ e ∶ A
⊢≡ᵀ-envsub' : {n : ℕ} {A B : Ty {n}} {Γ Δ : TEnv {n}} → Γ ⊢ A ≡ᵀ' B → Γ ≡ᵀ' Δ → Δ ⊢ A ≡ᵀ' B
-- IMPLEMENTATIONS
--- TRANSITIVITY
≡ᵀ'-trans {n} {A} {.A} {C} {Γ} CRefl' j' = j'
≡ᵀ'-trans {n} {Case f (LabI z)} {B} {.B} {Γ} (CLabBeta' x ins eq) CRefl' = CLabBeta' x ins eq
≡ᵀ'-trans {n} {Case f (LabI z)} {B} {C} {Γ} (CLabBeta' x ins eq) j = CLabBeta' x ins (≡ᵀ'-trans eq j)
≡ᵀ'-trans {n} {.(Pi _ _)} {.(Pi _ _)} {.(Pi _ _)} {Γ} (CPi' j j₁) CRefl' = CPi' j j₁
≡ᵀ'-trans {n} {.(Pi _ _)} {.(Pi _ _)} {.(Pi _ _)} {Γ} (CPi' {ok = ok} j j₁) (CPi' j' j'') = CPi' {ok = ok} (≡ᵀ'-trans j j') (≡ᵀ'-trans j₁ (⊢≡ᵀ-envsub' j'' (tsuc ≡ᵀ'-refl (≡ᵀ'-sym j))))
≡ᵀ'-trans {n} {.(Pi _ _)} {.(Pi _ _)} {.(Case _ (LabI _))} {Γ} (CPi' j j₁) (CLabEta' x x₁ j') = CLabEta' x x₁ (≡ᵀ'-trans j' (≡ᵀ'-sym (CPi' j j₁)))
≡ᵀ'-trans {n} {.(Sigma _ _)} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} (CSigma' j j₁) CRefl' = CSigma' j j₁
≡ᵀ'-trans {n} {.(Sigma _ _)} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} (CSigma' j j₁) (CSigma' j' j'') = CSigma' (≡ᵀ'-trans j j') (≡ᵀ'-trans j₁ (⊢≡ᵀ-envsub' j'' (tsuc ≡ᵀ'-refl (≡ᵀ'-sym j))))
≡ᵀ'-trans {n} {.(Sigma _ _)} {.(Sigma _ _)} {.(Case _ (LabI _))} {Γ} (CSigma' j j₁) (CLabEta' x x₁ j') = CLabEta' x x₁ (≡ᵀ'-trans j' (≡ᵀ'-sym (CSigma' j j₁)))
≡ᵀ'-trans {n} {.(Case _ _)} {.(Case _ _)} {.(Case _ _)} {Γ} (CLab' {ok = ok}{ok' = ok'} v x) CRefl' = CLab'{ok = ok}{ok' = ok'} v x
≡ᵀ'-trans {n} {.(Case _ (LabI _))} {.(Case _ (LabI _))} {C} {Γ} (CLab' {ok = ok} v x) (CLabBeta'{x = x₂} x₁ ins j') = CLabBeta' (TCaseF ok VLab (TLabI ins)) ins (≡ᵀ'-trans (x x₂ ins) j')
≡ᵀ'-trans {n} {.(Case _ _)} {.(Case _ _)} {.(Case _ _)} {Γ} (CLab'{ok = ok} v x) (CLab'{ok' = ok'} v₁ x₁) = CLab'{ok = ok}{ok' = ok'} v (λ l i → ≡ᵀ'-trans (x l i) (x₁ l i))
≡ᵀ'-trans {n} {(Case f e)} {(Case f' .e)} {(Case f'' (LabI l))} {Γ} (CLab'{ok = ok}{ok' = ok'} (TCaseF u v w) x) (CLabEta'{ins = ins} x₁ x₂ j')
= CLabEta'{ins = ins} x₁ x₂ (≡ᵀ'-trans j' (CLab'{ok = ok'}{ok' = ok} (TCaseF ok' v w) λ l₁ i → ≡ᵀ'-sym (x l₁ i)))
≡ᵀ'-trans {n} {A} {.(Case _ (LabI _))} {.(Case _ (LabI _))} {Γ} (CLabEta' x x₁ x₂) CRefl' = CLabEta' x x₁ x₂
≡ᵀ'-trans {n} {A} {.(Case _ (LabI _))} {C} {Γ} (CLabEta' {ins = ins'} x x₁ x₂) (CLabBeta' x₃ ins j')
rewrite (ins-uniqueness ins ins')
= ≡ᵀ'-trans (≡ᵀ'-sym x₂) j'
≡ᵀ'-trans {n} {A} {(Case f (LabI l))} {(Case f' (LabI .l))} {Γ} (CLabEta'{ins = ins} x x₁ x₂) (CLab'{ok' = ok'} v x₃) = CLabEta'{ins = ins} x ok' (≡ᵀ'-trans (≡ᵀ'-sym (x₃ l ins)) x₂)
≡ᵀ'-trans {n} {A} {(Case f (LabI l))} {(Case f' (LabI l'))} {Γ} (CLabEta'{ins = ins} x x₁ x₂) (CLabEta'{ins = ins'} x₃ x₄ j')
= CLabEta'{ins = ins'} x₃ x₄ (≡ᵀ'-trans j' (≡ᵀ'-trans (CLabBeta' (TCaseF x₁ VLab x) ins (CRefl'{ok = x₁ l ins})) x₂))
--- SYMMETRY
≡ᵀ'-sym {n} {A} {.A} {Γ} (CRefl'{ok = ok}) = CRefl'{ok = ok}
≡ᵀ'-sym {n} {(Case f (LabI x₁))} {B} {Γ} (CLabBeta' (TCaseF f' v x) ins eq) = CLabEta' x f' eq
≡ᵀ'-sym {n} {.(Pi _ _)} {.(Pi _ _)} {Γ} (CPi'{ok = ok} j j₁) = CPi'{ok = ⊢∧≡ᵀ'⇒⊢ ok j} (≡ᵀ'-sym j) (⊢≡ᵀ-envsub' (≡ᵀ'-sym j₁) (tsuc ≡ᵀ'-refl j))
≡ᵀ'-sym {n} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} (CSigma'{ok = ok} j j₁) = CSigma'{ok = ⊢∧≡ᵀ'⇒⊢ ok j} (≡ᵀ'-sym j) (⊢≡ᵀ-envsub' (≡ᵀ'-sym j₁) (tsuc ≡ᵀ'-refl j))
≡ᵀ'-sym {n} {.(Case _ _)} {.(Case _ _)} {Γ} (CLab'{ok = ok}{ok' = ok'} (TCaseF u v w) x) = CLab'{ok = ok'}{ok' = ok} (TCaseF ok' v w) (λ l i → ≡ᵀ'-sym (x l i))
≡ᵀ'-sym {n} {A} {(Case f (LabI x'))} {Γ} (CLabEta'{ins = ins} x x₁ x₂) = CLabBeta' (TCaseF x₁ VLab x) ins x₂ -- CLabBeta' (TCaseF x₁ VLab x) ins refl
--- ⊢∧≡ᵀ'⇒⊢ ≡ᵀ'⇒⊢
⊢∧≡ᵀ'⇒⊢ {n} {Γ} {T} {.T} j CRefl' = j
⊢∧≡ᵀ'⇒⊢ {n} {Γ} {T} {.(Case _ (LabI _))} j (CLabEta' x x₁ eq) = TCaseF x₁ VLab x
⊢∧≡ᵀ'⇒⊢ {n} {Γ} {.(Pi _ _)} {.(Pi _ _)} (TPiF j j₁) (CPi'{ok = ok} eq eq₁) = TPiF (⊢∧≡ᵀ'⇒⊢ ok eq ) (⊢∧≡ᵀ'⇒⊢ (⊢-envsub' j₁ (tsuc ≡ᵀ'-refl eq)) (⊢≡ᵀ-envsub' eq₁ (tsuc ≡ᵀ'-refl eq)))
⊢∧≡ᵀ'⇒⊢ {n} {Γ} {.(Sigma _ _)} {.(Sigma _ _)} (TSigmaF j j₁) (CSigma'{ok = ok} eq eq₁) = TSigmaF (⊢∧≡ᵀ'⇒⊢ ok eq ) (⊢∧≡ᵀ'⇒⊢ (⊢-envsub' j₁ (tsuc ≡ᵀ'-refl eq)) (⊢≡ᵀ-envsub' eq₁ (tsuc ≡ᵀ'-refl eq)))
⊢∧≡ᵀ'⇒⊢ {n} {Γ} {(Case f (LabI l))} {T'} (TCaseF f' v x) (CLabBeta' x₁ ins eq) = ⊢∧≡ᵀ'⇒⊢ (f' l ins) eq
⊢∧≡ᵀ'⇒⊢ {n} {Γ} {.(Case _ _)} {.(Case _ _)} (TCaseF f' v x) (CLab'{ok = ok}{ok' = ok'} z x₁) = TCaseF ok' v x
≡ᵀ'⇒⊢ {n} {Γ} {T} {.T} (CRefl'{ok = ok}) = ok , ok
≡ᵀ'⇒⊢ {n} {Γ} {T} {(Case f (LabI l))} (CLabEta'{ins = ins} x x₁ j) = ⊢∧≡ᵀ'⇒⊢ (x₁ l ins) j , TCaseF x₁ VLab x
≡ᵀ'⇒⊢ {n} {Γ} {Case f (LabI l)} {T'} (CLabBeta' (TCaseF f' v x) ins j) = (TCaseF f' v x) , (⊢∧≡ᵀ'⇒⊢ (f' l ins) j)
≡ᵀ'⇒⊢ {n} {Γ} {.(Pi _ _)} {.(Pi _ _)} (CPi'{ok = ok} j j₁) = TPiF ok (proj₁ (≡ᵀ'⇒⊢ j₁)) , TPiF (⊢∧≡ᵀ'⇒⊢ ok j) (⊢-envsub' (proj₂ (≡ᵀ'⇒⊢ j₁)) (tsuc ≡ᵀ'-refl j))
≡ᵀ'⇒⊢ {n} {Γ} {.(Sigma _ _)} {.(Sigma _ _)} (CSigma'{ok = ok} j j₁) = TSigmaF ok (proj₁ (≡ᵀ'⇒⊢ j₁)) , TSigmaF (⊢∧≡ᵀ'⇒⊢ ok j) (⊢-envsub' (proj₂ (≡ᵀ'⇒⊢ j₁)) (tsuc ≡ᵀ'-refl j))
≡ᵀ'⇒⊢ {n} {Γ} {.(Case _ _)} {.(Case _ _)} (CLab' {ok = ok} {ok' = ok'} (TCaseF f' v x₁) x) = TCaseF ok v x₁ , TCaseF ok' v x₁
--- EQUIVALENCE ≡ᵀ & ≡ᵀ'
≡ᵀ⊆≡ᵀ' {n} {A} {.A} {Γ} (CRefl{ok = ok}) = CRefl'{ok = ok}
≡ᵀ⊆≡ᵀ' {n} {A} {B} {Γ} (CSym j) = ≡ᵀ'-sym (≡ᵀ⊆≡ᵀ' j)
≡ᵀ⊆≡ᵀ' {n} {A} {B} {Γ} (CTrans j j₁) = ≡ᵀ'-trans (≡ᵀ⊆≡ᵀ' j) (≡ᵀ⊆≡ᵀ' j₁)
≡ᵀ⊆≡ᵀ' {n} {A} {.(Case (λ l i → A) (LabI _))} {Γ} (CLabEta{ins = ins} x x₁) = CLabEta' {ins = ins} x (λ l ins₁ → x₁) (CRefl'{ok = x₁})
≡ᵀ⊆≡ᵀ' {n} {Case f (LabI l)} {.(f l ins)} {Γ} (CLabBeta (TCaseF f' v x) ins) = CLabBeta' (TCaseF f' v x) ins (CRefl' {ok = f' l ins})
≡ᵀ⊆≡ᵀ' {n} {.(Pi _ _)} {.(Pi _ _)} {Γ} (CPi j j₁) = CPi' (≡ᵀ⊆≡ᵀ' j) (≡ᵀ⊆≡ᵀ' j₁)
≡ᵀ⊆≡ᵀ' {n} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} (CSigma j j₁) = CSigma' (≡ᵀ⊆≡ᵀ' j) (≡ᵀ⊆≡ᵀ' j₁)
≡ᵀ⊆≡ᵀ' {n} {.(Case _ _)} {.(Case _ _)} {Γ} (CLab v x)
= CLab'{ok = λ l' i → proj₁ (≡ᵀ'⇒⊢ (≡ᵀ⊆≡ᵀ' (x l' i)))}{ok' = λ l' i → proj₂ (≡ᵀ'⇒⊢ (≡ᵀ⊆≡ᵀ' (x l' i)))} v (λ l i → ≡ᵀ⊆≡ᵀ' (x l i))
≡ᵀ'⊆≡ᵀ {n} {A} {.A} {Γ} (CRefl'{ok = ok}) = CRefl{ok = ok}
≡ᵀ'⊆≡ᵀ {n} {A} {(Case f (LabI l))} {Γ} (CLabEta'{ins = ins} x x₁ eq) = CSym (CTrans (CLabBeta (TCaseF x₁ VLab x) ins) (≡ᵀ'⊆≡ᵀ eq))
≡ᵀ'⊆≡ᵀ {n} {(Case f (LabI l))} {B} {Γ} (CLabBeta' x ins eq) = CTrans (CLabBeta x ins) (≡ᵀ'⊆≡ᵀ eq)
≡ᵀ'⊆≡ᵀ {n} {.(Pi _ _)} {.(Pi _ _)} {Γ} (CPi' j j₁) = CPi (≡ᵀ'⊆≡ᵀ j ) (≡ᵀ'⊆≡ᵀ j₁)
≡ᵀ'⊆≡ᵀ {n} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} (CSigma' j j₁) = CSigma (≡ᵀ'⊆≡ᵀ j) (≡ᵀ'⊆≡ᵀ j₁)
≡ᵀ'⊆≡ᵀ {n} {.(Case _ _)} {.(Case _ _)} {Γ} (CLab' v x) = CLab v (λ l i → ≡ᵀ'⊆≡ᵀ (x l i))
≡ᵀ⊆≡ᵀ'-env {n} {.[]} {.[]} tzero = tzero
≡ᵀ⊆≡ᵀ'-env {n} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} (tsuc eq x) = tsuc (≡ᵀ⊆≡ᵀ'-env eq) (≡ᵀ⊆≡ᵀ' x)
≡ᵀ'⊆≡ᵀ-env {n} {.[]} {.[]} tzero = tzero
≡ᵀ'⊆≡ᵀ-env {n} {.(⟨ _ , _ ⟩)} {.(⟨ _ , _ ⟩)} (tsuc eq x) = tsuc (≡ᵀ'⊆≡ᵀ-env eq) (≡ᵀ'⊆≡ᵀ x)
--- ENVIRONMENT EQUIVALENCE
≡ᵀ-extr' {n} {.0} {(⟨ A , Γ ⟩)} {(⟨ T' , Δ ⟩)} {A} here (tsuc{T' = .T'} eq x) = T' , (here , x)
≡ᵀ-extr' {n} {(ℕ.suc m)} {(⟨ T , Γ ⟩)} {⟨ T' , Δ ⟩} {A} (there ins) (tsuc eq x)
with ≡ᵀ-extr' {m = m} {Γ} {Δ} ins eq
... | fst , snd , snd₁ = fst , ((there snd) , snd₁)
⊢-envsub' {n} {.(Label _)} {Γ} {Δ} TLabF eq = TLabF
⊢-envsub' {n} {.(Pi _ _)} {Γ} {Δ} (TPiF j j₁) eq = TPiF (⊢-envsub' j eq) (⊢-envsub' j₁ (tsuc eq (CRefl'{ok = ⊢-envsub' j eq})))
⊢-envsub' {n} {.(Sigma _ _)} {Γ} {Δ} (TSigmaF j j₁) eq = TSigmaF (⊢-envsub' j eq) (⊢-envsub' j₁ (tsuc eq (CRefl'{ok = ⊢-envsub' j eq})))
⊢-envsub' {n} {.(Case _ _)} {Γ} {Δ} (TCaseF f' v x) eq = TCaseF (λ l i → ⊢-envsub' (f' l i) eq) v (⊢∶-envsub' x eq)
⊢∶-envsub' {n} {A} {Γ} {Δ} {e} (TConv j x₁) eq = TConv (⊢∶-envsub' j eq) (⊢≡ᵀ-envsub x₁ (≡ᵀ'⊆≡ᵀ-env eq))
⊢∶-envsub' {n} {A} {Γ} {Δ} {Var m} (TVarE j q) eq = TVarE (proj₁ (proj₂ (≡ᵀ-extr' j eq))) (CTrans (⊢≡ᵀ-envsub q (≡ᵀ-tail m (≡ᵀ'⊆≡ᵀ-env eq))) (≡ᵀ'⊆≡ᵀ (proj₂ (proj₂ (≡ᵀ-extr' j eq)))))
⊢∶-envsub' {n} {.(Pi _ _)} {Γ} {Δ} {Abs e} (TPiI{ok = ok}{ok' = ok'} j) eq = TPiI{ok = ⊢-envsub' ok eq}{ok' = ⊢-envsub' ok' (tsuc eq (CRefl'{ok = ⊢-envsub ok (≡ᵀ'⊆≡ᵀ-env eq) }))} (⊢∶-envsub' j (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq})))
⊢∶-envsub' {n} {.([ 0 ↦ e₁ ]ᵀ _)} {Γ} {Δ} {App e e₁} (TPiE j j₁ x) eq = TPiE (⊢∶-envsub' j eq) (⊢∶-envsub' j₁ eq) (⊢-envsub' x eq)
⊢∶-envsub' {n} {.(Label _)} {Γ} {Δ} {LabI x} (TLabI ins) eq = TLabI ins
⊢∶-envsub' {n} {A} {Γ} {Δ} {LabE f .(LabI _)} (TLabEl{scopecheck = sc} j j₁) eq rewrite (≡ᵀ'-length eq) = TLabEl{scopecheck = sc} (⊢∶-envsub' j eq) (⊢∶-envsub' j₁ eq)
⊢∶-envsub' {n} {A} {Γ} {Δ} {LabE f .(Var _)} (TLabEx{T = T} f' j) eq = TLabEx{T = T} (λ l i → ⊢∶-envsub' (f' l i) eq) (⊢∶-envsub' j eq)
⊢∶-envsub' {n} {.(Sigma _ _)} {Γ} {Δ} {Prod e e₁} (TSigmaI{ok = ok}{ok' = ok'} j j₁) eq = TSigmaI{ok = ⊢-envsub' ok eq}{ok' = ⊢-envsub' ok' (tsuc eq (CRefl'{ok = ⊢-envsub ok (≡ᵀ'⊆≡ᵀ-env eq)}))} (⊢∶-envsub' j eq) (⊢∶-envsub' j₁ (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq})))
⊢∶-envsub' {n} {A} {Γ} {Δ} {Let e e₁} (TSigmaE{ok = ok}{ok' = ok'} j j₁ nin) eq = TSigmaE{ok = ⊢-envsub' ok eq}{ok' = ⊢-envsub' ok' (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq}))} (⊢∶-envsub' j eq) (⊢∶-envsub' j₁ (tsuc (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq})) (CRefl'{ok = ⊢-envsub' ok' (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq}))}))) nin
⊢≡ᵀ-envsub' {n} {A} {.A} {Γ} {Δ} (CRefl'{ok = ok}) eq = CRefl'{ok = ⊢-envsub' ok eq}
⊢≡ᵀ-envsub' {n} {A} {.(Case _ (LabI _))} {Γ} {Δ} (CLabEta' x x₁ j) eq = CLabEta' (⊢∶-envsub' x eq) (λ l ins' → ⊢-envsub' (x₁ l ins') eq) (⊢≡ᵀ-envsub' j eq)
⊢≡ᵀ-envsub' {n} {.(Case _ (LabI _))} {B} {Γ} {Δ} (CLabBeta' x ins j) eq = CLabBeta' (⊢-envsub' x eq) ins (⊢≡ᵀ-envsub' j eq)
⊢≡ᵀ-envsub' {n} {.(Pi _ _)} {.(Pi _ _)} {Γ} {Δ} (CPi'{ok = ok} j j₁) eq = CPi'{ok = ⊢-envsub' ok eq} (⊢≡ᵀ-envsub' j eq) (⊢≡ᵀ-envsub' j₁ (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq})))
⊢≡ᵀ-envsub' {n} {.(Sigma _ _)} {.(Sigma _ _)} {Γ} {Δ} (CSigma'{ok = ok} j j₁) eq = CSigma'{ok = ⊢-envsub' ok eq} (⊢≡ᵀ-envsub' j eq) (⊢≡ᵀ-envsub' j₁ (tsuc eq (CRefl'{ok = ⊢-envsub' ok eq})))
⊢≡ᵀ-envsub' {n} {.(Case _ _)} {.(Case _ _)} {Γ} {Δ} (CLab'{ok = ok}{ok' = ok'} v x) eq = CLab'{ok = λ l' i → ⊢-envsub' (ok l' i) eq}{ok' = λ l' i → ⊢-envsub' (ok' l' i) eq} (⊢-envsub' v eq) (λ l i → ⊢≡ᵀ-envsub' (x l i) eq)
--- COROLLARIES
≢ᵀ'⇒≢ᵀ : {n : ℕ} {A B : Ty {n}} {Γ : TEnv {n}} → ¬ (Γ ⊢ A ≡ᵀ' B) → ¬ (Γ ⊢ A ≡ᵀ B)
≢ᵀ'⇒≢ᵀ {n} {A} {B} {Γ} = contraposition ≡ᵀ⊆≡ᵀ'
-- Normalform of types; no redex possible
data Nf {n : ℕ} : Ty → Set where
NLab : {s : Subset n} → Nf (Label s)
NPi : {A B : Ty {n}} → Nf (Pi A B)
NSigma : {A B : Ty {n}} → Nf (Sigma A B)
-- operational semantics (call-by-value)
module operational where
open defs
-- reduction relation
data _⇒_ {n : ℕ} : Exp {n} → Exp {n} → Set where
ξ-App1 : {e₁ e₁' e₂ : Exp} → e₁ ⇒ e₁' → App e₁ e₂ ⇒ App e₁' e₂
ξ-App2 : {e e' v : Exp} → Val v → e ⇒ e' → App v e ⇒ App v e'
ξ-Prod1 : {e₁ e₁' e₂ : Exp} → e₁ ⇒ e₁' → Prod e₁ e₂ ⇒ Prod e₁' e₂
ξ-Prod2 : {e₂ e₂' v : Exp} → Val v → e₂ ⇒ e₂' → Prod v e₂ ⇒ Prod v e₂'
ξ-Let : {e₁ e₁' e₂ : Exp} → e₁ ⇒ e₁' → Let e₁ e₂ ⇒ Let e₁' e₂
β-App : {e v : Exp} → Val v → (App (Abs e) v) ⇒ (↑⁻¹[ ([ 0 ↦ ↑¹[ v ] ] e) ])
β-Let : {e e' e'' : Exp} → Val e → Val e' → Let (Prod e e') e'' ⇒ ↑ (ℤ.negsuc 1) , 0 [ ([ 0 ↦ ↑ (ℤ.pos 1) , 0 [ e ] ] ([ 0 ↦ ↑ (ℤ.pos 1) , 1 [ e' ] ] e'')) ]
β-LabE : {s : Subset n} {f : ∀ l → l ∈ s → Exp} {x : Fin n} → (ins : x ∈ s) → LabE f (LabI x) ⇒ f x ins
---- properties & lemmas
--- properties of shifting
-- ∣ + x +ᶻ k ∣ +ᴺ m ≡ ∣ + (x +ᴺ m) +ᶻ k ∣
aux-calc-1 : {x m : ℕ} {k : ℤ} → k >ᶻ + 0 → ∣ + x +ᶻ k ∣ +ᴺ m ≡ ∣ + (x +ᴺ m) +ᶻ k ∣
aux-calc-1 {x} {m} {+_ n} ge
rewrite (+-assoc x n m)
| (+-comm n m)
| (sym (+-assoc x m n))
= refl
↑ᴺk,l[x]+m≡↑ᴺk,l+m[x+m] : {k : ℤ} {l x m : ℕ} → k >ᶻ + 0 → ↑ᴺ k , l [ x ] +ᴺ m ≡ ↑ᴺ k , l +ᴺ m [ x +ᴺ m ]
↑ᴺk,l[x]+m≡↑ᴺk,l+m[x+m] {k} {l} {x} {m} ge
with x <ᴺ? l
... | yes p
with x +ᴺ m <ᴺ? l +ᴺ m
... | yes q = refl
... | no ¬q = contradiction (+-monoˡ-< m p) ¬q
↑ᴺk,l[x]+m≡↑ᴺk,l+m[x+m] {k} {l} {x} {m} ge
| no ¬p
with x +ᴺ m <ᴺ? l +ᴺ m
... | yes q = contradiction q (<⇒≱ (+-monoˡ-< m (≰⇒> ¬p)))
... | no ¬q = aux-calc-1 ge
-- corollary for suc
suc[↑ᴺk,l[x]]≡↑ᴺk,sucl[sucx] : {k : ℤ} {l x : ℕ} → k >ᶻ + 0 → ℕ.suc (↑ᴺ k , l [ x ]) ≡ ↑ᴺ k , ℕ.suc l [ ℕ.suc x ]
suc[↑ᴺk,l[x]]≡↑ᴺk,sucl[sucx] {k} {l} {x} ge
with (↑ᴺk,l[x]+m≡↑ᴺk,l+m[x+m] {k} {l} {x} {1} ge)
... | w
rewrite (n+1≡sucn{↑ᴺ k , l [ x ]})
| (n+1≡sucn{x})
| (n+1≡sucn{l})
= w
↑-var-refl : {n : ℕ} {d : ℤ} {c : ℕ} {x : ℕ} {le : ℕ.suc x ≤ᴺ c} → ↑ d , c [ Var {n} x ] ≡ Var x
↑-var-refl {n} {d} {c} {x} {le}
with (x <ᴺ? c)
... | no ¬p = contradiction le ¬p
... | yes p = refl
↑¹-var : {n x : ℕ} → ↑¹[ Var {n} x ] ≡ Var (ℕ.suc x)
↑¹-var {n} {zero} = refl
↑¹-var {n} {ℕ.suc x}
rewrite (sym (n+1≡sucn{x +ᴺ 1}))
| (sym (n+1≡sucn{x}))
= cong ↑¹[_] (↑¹-var{n}{x})
↑⁻¹ₖ[↑¹ₖ[s]]≡s : {n : ℕ} {e : Exp {n} } {k : ℕ} → ↑ -[1+ 0 ] , k [ ↑ + 1 , k [ e ] ] ≡ e
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {Var x} {k}
with (x <ᴺ? k)
-- x < k
-- => ↑⁻¹ₖ(↑¹ₖ(Var n)) = ↑⁻¹ₖ(Var n) = Var n
... | yes p = ↑-var-refl{n}{ -[1+ 0 ]}{k}{x}{p}
-- x ≥ k
-- => ↑⁻¹ₖ(↑¹ₖ(Var n)) = ↑⁻¹ₖ(Var |n + 1|) = Var (||n + 1| - 1|) = Var n
... | no ¬p
with (¬[x≤k]⇒¬[sucx≤k] ¬p)
... | ¬p'
with (x +ᴺ 1) <ᴺ? k
... | yes pp = contradiction pp ¬p'
... | no ¬pp
rewrite (∣nℕ+1⊖1∣≡n{x})
= refl
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {Abs e} {k} = cong Abs ↑⁻¹ₖ[↑¹ₖ[s]]≡s
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {App e e₁} = cong₂ App ↑⁻¹ₖ[↑¹ₖ[s]]≡s ↑⁻¹ₖ[↑¹ₖ[s]]≡s
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {LabI ins} = refl
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {LabE f e} = cong₂ LabE (f-ext (λ x → f-ext (λ ins → ↑⁻¹ₖ[↑¹ₖ[s]]≡s))) ↑⁻¹ₖ[↑¹ₖ[s]]≡s
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {Prod e e'} = cong₂ Prod ↑⁻¹ₖ[↑¹ₖ[s]]≡s ↑⁻¹ₖ[↑¹ₖ[s]]≡s
↑⁻¹ₖ[↑¹ₖ[s]]≡s {n} {Let e e'} = cong₂ Let ↑⁻¹ₖ[↑¹ₖ[s]]≡s ↑⁻¹ₖ[↑¹ₖ[s]]≡s
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] : {n : ℕ} {k l : ℤ} {c : ℕ} {s : Exp {n}} → l ≥ᶻ +0 → ↑ k , c [ ↑ l , c [ s ] ] ≡ ↑ (l +ᶻ k) , c [ s ]
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {Var x} ge
with x <ᴺ? c
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {Var x} ge | no ¬p
with ∣ + x +ᶻ l ∣ <ᴺ? c
... | yes q = contradiction q (<⇒≱ (n≤m⇒n<sucm (≤-trans (≮⇒≥ ¬p) (m≥0⇒∣n+m∣≥n ge))))
... | no ¬q
rewrite (0≤n⇒+∣n∣≡n{+ x +ᶻ l} (m≥0⇒n+m≥0 ge))
| (Data.Integer.Properties.+-assoc (+_ x) l k)
= refl
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {Var x} ge | yes p
with x <ᴺ? c
... | yes p' = refl
... | no ¬p' = contradiction p ¬p'
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {Abs s} le = cong Abs (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s]{n}{k}{l}{ℕ.suc c}{s} le)
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {App s s₁} le = cong₂ App (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s]{n}{k}{l}{c}{s} le) (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s]{n}{k}{l}{c}{s₁} le)
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {LabI ins} le = refl
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {LabE f e} le = cong₂ LabE (f-ext (λ x → f-ext (λ ins → ↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {f x ins} le))) ( ↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {e} le)
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {Prod e e'} le = cong₂ Prod (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] le) (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] le)
↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] {n} {k} {l} {c} {Let e e'} le = cong₂ Let (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] le) (↑ᵏ[↑ˡ[s]]≡↑ᵏ⁺ˡ[s] le)
↑k,q[↑l,c[s]]≡↑l+k,c[s] : {n : ℕ} {k l : ℤ} {q c : ℕ} {s : Exp {n}} → + q ≤ᶻ + c +ᶻ l → c ≤ᴺ q → ↑ k , q [ ↑ l , c [ s ] ] ≡ ↑ (l +ᶻ k) , c [ s ]
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {Var x} ge₁ ge₂
with x <ᴺ? c
... | yes p
with x <ᴺ? q
... | yes p' = refl
... | no ¬p' = contradiction (≤-trans p ge₂) ¬p'
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {Var x} ge₁ ge₂
| no ¬p
with ∣ + x +ᶻ l ∣ <ᴺ? q
... | yes p' = contradiction p' (≤⇒≯ (+a≤b⇒a≤∣b∣{q}{+ x +ᶻ l} (Data.Integer.Properties.≤-trans ge₁ ((Data.Integer.Properties.+-monoˡ-≤ l (+≤+ (≮⇒≥ ¬p)))))))
... | no ¬p'
rewrite (0≤n⇒+∣n∣≡n{+ x +ᶻ l} (Data.Integer.Properties.≤-trans (+≤+ z≤n) ((Data.Integer.Properties.≤-trans ge₁ ((Data.Integer.Properties.+-monoˡ-≤ l (+≤+ (≮⇒≥ ¬p))))))))
| (Data.Integer.Properties.+-assoc (+_ x) l k)
= refl
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {Abs s} ge₁ ge₂ = cong Abs (↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {ℕ.suc q} {ℕ.suc c} {s} (+q≤+c+l⇒+1q≤+1c+l{q}{c}{l} ge₁) (s≤s ge₂))
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {App s s₁} ge₁ ge₂ = cong₂ App (↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {s} ge₁ ge₂) (↑k,q[↑l,c[s]]≡↑l+k,c[s]{n} {k} {l} {q} {c} {s₁} ge₁ ge₂)
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {LabI e} ge₁ ge₂ = refl
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {LabE f e} ge₁ ge₂ = cong₂ LabE (f-ext (λ x → f-ext (λ ins → ↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {f x ins} ge₁ ge₂))) (↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {e} ge₁ ge₂)
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {Prod e e'} ge₁ ge₂ = cong₂ Prod (↑k,q[↑l,c[s]]≡↑l+k,c[s] ge₁ ge₂) (↑k,q[↑l,c[s]]≡↑l+k,c[s] ((+q≤+c+l⇒+1q≤+1c+l{q}{c}{l} ge₁)) (s≤s ge₂))
↑k,q[↑l,c[s]]≡↑l+k,c[s] {n} {k} {l} {q} {c} {Let e e'} ge₁ ge₂ = cong₂ Let (↑k,q[↑l,c[s]]≡↑l+k,c[s] ge₁ ge₂)
(↑k,q[↑l,c[s]]≡↑l+k,c[s] ((+q≤+c+l⇒+1q≤+1c+l{ℕ.suc q}{ℕ.suc c}{l} (+q≤+c+l⇒+1q≤+1c+l{q}{c}{l} ge₁))) (s≤s (s≤s ge₂)))
aux-calc-2 : {x l : ℕ} {k : ℤ} → k >ᶻ + 0 → ∣ + (x +ᴺ l) +ᶻ k ∣ ≡ ∣ + x +ᶻ k ∣ +ᴺ l
aux-calc-2 {x} {l} {+_ n} ge
rewrite (+-assoc x l n)
| (+-comm l n)
| (+-assoc x n l)
= refl
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] : {n : ℕ} {k : ℤ} {q c l : ℕ} {s : Exp {n}} → c ≤ᴺ q → + 0 <ᶻ k → ↑ k , q +ᴺ l [ ↑ + l , c [ s ] ] ≡ ↑ + l , c [ ↑ k , q [ s ] ]
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {Var x} le le'
with x <ᴺ? q
... | yes p
with x <ᴺ? c
... | yes p'
with x <ᴺ? q +ᴺ l
... | yes p'' = refl
... | no ¬p'' = contradiction (≤-stepsʳ l p) ¬p''
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {Var x} le le'
| yes p
| no ¬p'
with x +ᴺ l <ᴺ? q +ᴺ l
... | yes p'' = refl
... | no ¬p'' = contradiction (Data.Nat.Properties.+-monoˡ-≤ l p) ¬p''
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {Var x} le le'
| no ¬p
with x <ᴺ? c
... | yes p' = contradiction p' (<⇒≱ (a≤b<c⇒a<c le (≰⇒> ¬p)))
... | no ¬p'
with x +ᴺ l <ᴺ? q +ᴺ l
| ∣ + x +ᶻ k ∣ <ᴺ? c
... | _ | yes p''' = contradiction p''' (<⇒≱ (a≤b<c⇒a<c (≰⇒≥ ¬p') (s≤s (m>0⇒∣n+m∣>n {x} {k} le'))))
... | yes p'' | _ = contradiction p'' (<⇒≱ (+-monoˡ-< l (≰⇒> ¬p)))
... | no ¬p'' | no ¬p''' = cong Var (aux-calc-2 {x} {l} {k} le')
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {Abs s} le le' = cong Abs (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {ℕ.suc q} {ℕ.suc c} {l} {s} (s≤s le) le')
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {App s s₁} le le' = cong₂ App (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {s} le le') (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {s₁} le le')
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {LabI x} le le' = refl
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {LabE f s} le le' = cong₂ LabE (f-ext (λ x → f-ext (λ ins → ↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {f x ins} le le'))) (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {s} le le')
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {Prod e e'} le le' = cong₂ Prod (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] le le') (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] (s≤s le) le')
↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] {n} {k} {q} {c} {l} {Let e e'} le le' = cong₂ Let (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] le le') (↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]] (s≤s (s≤s le)) le')
-- corollaries
↑k,sucq[↑1,c[s]]≡↑1,c[↑k,q[s]] : {n : ℕ} {k : ℤ} {q c : ℕ} {s : Exp {n}} → c ≤ᴺ q → + 0 <ᶻ k → ↑ k , ℕ.suc q [ ↑ + 1 , c [ s ] ] ≡ ↑ + 1 , c [ ↑ k , q [ s ] ]
↑k,sucq[↑1,c[s]]≡↑1,c[↑k,q[s]] {n} {k} {q} {c} {s} le le'
rewrite (sym (n+1≡sucn{q}))
= ↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]]{n}{k}{q}{c}{1}{s} le le'
↑k,sucsucq[↑2,c[s]]≡↑2,c[↑k,q[s]] : {n : ℕ} {k : ℤ} {q c : ℕ} {s : Exp {n}} → c ≤ᴺ q → + 0 <ᶻ k → ↑ k , ℕ.suc (ℕ.suc q) [ ↑ + 2 , c [ s ] ] ≡ ↑ + 2 , c [ ↑ k , q [ s ] ]
↑k,sucsucq[↑2,c[s]]≡↑2,c[↑k,q[s]] {n} {k} {q} {c} {s} le le'
rewrite (sym (n+2≡sucsucn{q}))
= ↑k,q+l[↑l,c[s]]≡↑l,c[↑k,q[s]]{n}{k}{q}{c}{2}{s} le le'
↑Lab-triv : {n : ℕ} {l : Fin n} (k : ℤ) (q : ℕ) → LabI l ≡ ↑ k , q [ LabI l ]
↑Lab-triv {n} {l} k q = refl
↑ᴺ-triv : {m : ℤ} {n x : ℕ} → x ≥ᴺ n → ↑ᴺ m , n [ x ] ≡ ∣ + x +ᶻ m ∣
↑ᴺ-triv {m} {n} {x} ge
with x <ᴺ? n
... | yes p = contradiction p (≤⇒≯ ge)
... | no ¬p = refl
↑ᴺ⁰-refl : {n : ℕ} {c : ℕ} {x : ℕ} → ↑ᴺ + 0 , c [ x ] ≡ x
↑ᴺ⁰-refl {n} {c} {x}
with x <ᴺ? c
... | yes p = refl
... | no ¬p = +-identityʳ x
↑⁰-refl : {n : ℕ} {c : ℕ} {e : Exp {n}} → ↑ + 0 , c [ e ] ≡ e
↑⁰-refl {n} {c} {Var x} = cong Var (↑ᴺ⁰-refl{n}{c}{x})
↑⁰-refl {n} {c} {Abs e} = cong Abs (↑⁰-refl{n}{ℕ.suc c}{e})
↑⁰-refl {n} {c} {App e e₁} = cong₂ App (↑⁰-refl{n}{c}{e}) (↑⁰-refl{n}{c}{e₁})
↑⁰-refl {n} {c} {LabI x} = refl
↑⁰-refl {n} {c} {LabE x e} = cong₂ LabE (f-ext (λ l → f-ext λ i → ↑⁰-refl{n}{c}{x l i})) (↑⁰-refl{n}{c}{e})
↑⁰-refl {n} {c} {Prod e e'} = cong₂ Prod ↑⁰-refl ↑⁰-refl
↑⁰-refl {n} {c} {Let e e'} = cong₂ Let ↑⁰-refl ↑⁰-refl
--- properties of substitution
subst-trivial : {n : ℕ} {x : ℕ} {s : Exp {n}} → [ x ↦ s ] Var x ≡ s
subst-trivial {n} {x} {s}
with x Data.Nat.≟ x
... | no ¬p = contradiction refl ¬p
... | yes p = refl
var-subst-refl : {N n m : ℕ} {neq : n ≢ m} {e : Exp {N}} → [ n ↦ e ] (Var m) ≡ (Var m)
var-subst-refl {N} {n} {m} {neq} {e}
with _≟ᴺ_ n m
| map′ (≡ᵇ⇒≡ m n) (≡⇒≡ᵇ m n) (Data.Bool.Properties.T? (m ≡ᵇ n))
... | yes p | _ = contradiction p neq
... | no ¬p | yes q = contradiction q (≢-sym ¬p)
... | no ¬p | no ¬q = refl
-- inversive lemma for variable in expression relation
inv-in-var : {N n m : ℕ} → _∈`_ {N} n (Var m) → n ≡ m
inv-in-var {N} {n} {.n} in-Var = refl
inv-in-abs : {N n : ℕ} {e : Exp {N}} → _∈`_ {N} n (Abs e) → (ℕ.suc n) ∈` e
inv-in-abs {N} {n} {e} (in-Abs i) = i
inv-in-app : {N n : ℕ} {e e' : Exp {N}} → _∈`_ {N} n (App e e') → (_∈`_ n e ⊎ _∈`_ n e')
inv-in-app {N} {n} {e} {e'} (in-App d) = d
inv-in-labe : {N n : ℕ} {s : Subset N} {f : (∀ l → l ∈ s → Exp {N})} {e : Exp {N}} → _∈`_ {N} n (LabE {N} {s} f e) → (∃₂ λ l i → n ∈` (f l i)) ⊎ n ∈` e
inv-in-labe {N} {n} {s} {f} {e} (in-LabE d) = d
notin-shift : {N n k q : ℕ} {e : Exp {N}} → n ≥ᴺ q → ¬ n ∈` e → ¬ ((n +ᴺ k) ∈` ↑ + k , q [ e ])
notin-shift {N} {n} {k} {q} {Var x} geq j z
with x <ᴺ? q
... | no ¬p
with x ≟ᴺ n
... | yes p' rewrite p' = contradiction in-Var j
... | no ¬p'
with cong (_∸ k) (inv-in-var z)
... | w
rewrite (m+n∸n≡m n k)
| (m+n∸n≡m x k)
= contradiction (sym w) ¬p'
notin-shift {N} {n} {k} {q} {Var .(n +ᴺ k)} geq j in-Var
| yes p = contradiction geq (<⇒≱ (≤-trans (s≤s (m≤m+n n k)) p)) -- q ≤ n VS ℕ.suc (n + k) ≤ n
notin-shift {N} {n} {k} {q} {Abs e} geq j (in-Abs x) = notin-shift (s≤s geq) (λ x₁ → contradiction (in-Abs x₁) j) x
notin-shift {N} {n} {k} {q} {App e e₁} geq j z
with dm2 (contraposition in-App j) | (inv-in-app z)
... | fst , snd | inj₁ x = notin-shift geq fst x
... | fst , snd | inj₂ y = notin-shift geq snd y
notin-shift {N} {n} {k} {q} {LabI x} geq j ()
notin-shift {N} {n} {k} {q} {LabE f e} geq j z
with dm2 (contraposition in-LabE j) | (inv-in-labe z)
... | fst , snd | inj₂ y = notin-shift geq snd y
... | fst , snd | inj₁ (fst₁ , fst₂ , snd₁) = notin-shift geq (¬∃⟶∀¬ (¬∃⟶∀¬ fst fst₁) fst₂) snd₁
notin-shift {N} {n} {k} {q} {Prod e e'} geq j (in-Prod (inj₁ x)) = notin-shift geq (λ x₁ → contradiction (in-Prod (inj₁ x₁)) j) x
notin-shift {N} {n} {k} {q} {Prod e e'} geq j (in-Prod (inj₂ y)) = notin-shift (s≤s geq) (λ x → contradiction (in-Prod (inj₂ x)) j) y
notin-shift {N} {n} {k} {q} {Let e e'} geq j (in-Let (inj₁ x)) = notin-shift geq (λ x₁ → contradiction (in-Let (inj₁ x₁)) j) x
notin-shift {N} {n} {k} {q} {Let e e'} geq j (in-Let (inj₂ y)) = notin-shift (s≤s (s≤s geq)) (λ x → contradiction (in-Let (inj₂ x)) j) y
-- corollary
notin-shift-one : {N n : ℕ} {e : Exp{N}} → ¬ n ∈` e → ¬ (ℕ.suc n ∈` ↑¹[ e ])
notin-shift-one {N} {n} {e} nin rewrite (sym (n+1≡sucn{n})) = notin-shift{N}{n}{1} z≤n nin
-- if n ∉ fv(e), then substitution of n does not do anything
subst-refl-notin : {N n : ℕ} {e e' : Exp {N}} → ¬ n ∈` e → [ n ↦ e' ] e ≡ e
subst-refl-notin {N} {n} {Var x} {e'} nin
with x ≟ᴺ n
... | yes p rewrite p = contradiction in-Var nin
... | no ¬p = refl
subst-refl-notin {N} {n} {Abs e} {e'} nin = cong Abs (subst-refl-notin (contraposition in-Abs nin))
subst-refl-notin {N} {n} {App e e₁} {e'} nin
with dm2 (contraposition in-App nin)
... | fst , snd = cong₂ App (subst-refl-notin fst) (subst-refl-notin snd)
subst-refl-notin {N} {n} {LabI x} {e'} nin = refl
subst-refl-notin {N} {n} {LabE x e} {e'} nin
with dm2 (contraposition in-LabE nin)
... | fst , snd = cong₂ LabE (f-ext (λ l → f-ext (λ x₁ → subst-refl-notin{e' = e'} (¬∃⟶∀¬ (¬∃⟶∀¬ (fst) l) x₁)))) (subst-refl-notin (snd))
subst-refl-notin {N} {n} {Prod e e'} {e''} nin = cong₂ Prod (subst-refl-notin (λ x → contradiction (in-Prod (inj₁ x)) nin)) (subst-refl-notin (λ x → contradiction (in-Prod (inj₂ x)) nin))
subst-refl-notin {N} {n} {Let e e'} {e''} nin = cong₂ Let (subst-refl-notin (λ x → contradiction (in-Let (inj₁ x)) nin)) (subst-refl-notin (λ x → contradiction (in-Let (inj₂ x)) nin))
notin-subst : {N n : ℕ} {e e' : Exp {N}} → ¬ n ∈` e' → ¬ (n ∈` ([ n ↦ e' ] e))
notin-subst {N} {n} {Var x} {e'} nin
with x ≟ᴺ n
... | yes p = nin
... | no ¬p = λ x₁ → contradiction (inv-in-var x₁) (≢-sym ¬p)
notin-subst {N} {n} {Abs e} {e'} nin
with notin-shift{k = 1} z≤n nin
... | w rewrite (n+1≡sucn{n}) = λ x → notin-subst {n = ℕ.suc n} {e = e} {e' = ↑¹[ e' ]} w (inv-in-abs x)
notin-subst {N} {n} {App e e₁} {e'} nin (in-App z)
with z
... | inj₁ x = notin-subst{e = e} nin x
... | inj₂ y = notin-subst{e = e₁} nin y
notin-subst {N} {n} {LabI x} {e'} nin = λ ()
notin-subst {N} {n} {LabE f e} {e'} nin (in-LabE z)
with z
... | inj₁ (fst , fst₁ , snd) = notin-subst{e = f fst fst₁} nin snd
... | inj₂ y = notin-subst{e = e} nin y
-- notin-shift : {N n k q : ℕ} {e : Exp {N}} → n ≥ᴺ q → ¬ n ∈` e → ¬ ((n +ᴺ k) ∈` ↑ + k , q [ e ])
notin-subst {N} {n} {Prod e e'} {e''} nin (in-Prod (inj₁ x)) = notin-subst{e = e} nin x
notin-subst {N} {n} {Prod e e'} {e''} nin (in-Prod (inj₂ y))
with notin-shift{k = 1} z≤n nin
... | w rewrite (n+1≡sucn{n}) = notin-subst {n = ℕ.suc n}{e = e'}{e' = ↑¹[ e'' ]} w y
notin-subst {N} {n} {Let e e'} {e''} nin (in-Let (inj₁ x)) = notin-subst{e = e} nin x
notin-subst {N} {n} {Let e e'} {e''} nin (in-Let (inj₂ y))
with notin-shift{k = 2} z≤n nin
... | w rewrite (n+2≡sucsucn{n}) = notin-subst {n = ℕ.suc (ℕ.suc n)} {e = e'} {e' = ↑ + 2 , 0 [ e'' ]} w y
subst2-refl-notin : {N n : ℕ} {e e' s : Exp {N}} → ¬ n ∈` e' → [ n ↦ e ] ([ n ↦ e' ] s) ≡ [ n ↦ e' ] s
subst2-refl-notin {N} {n} {e} {e'} {s} nin = subst-refl-notin (notin-subst{e = s} nin)
-- if n ∈ [ m ↦ s ] e, n ∉ s, then n ≢ m
subst-in-neq : {N n m : ℕ} {e s : Exp{N}} → ¬ n ∈` s → n ∈` ([ m ↦ s ] e) → n ≢ m
subst-in-neq {N} {n} {m} {Var x} {s} nin ins
with x ≟ᴺ m
... | yes p = contradiction ins nin
subst-in-neq {N} {.x} {m} {Var x} {s} nin in-Var | no ¬p = ¬p
subst-in-neq {N} {n} {m} {Abs e} {s} nin (in-Abs ins) = sucn≢sucm⇒n≢m (subst-in-neq{e = e} (notin-shift-one nin) ins)
subst-in-neq {N} {n} {m} {App e e₁} {s} nin (in-App (inj₁ x)) = subst-in-neq{e = e} nin x
subst-in-neq {N} {n} {m} {App e e₁} {s} nin (in-App (inj₂ y)) = subst-in-neq{e = e₁} nin y
subst-in-neq {N} {n} {m} {LabE f e} {s} nin (in-LabE (inj₁ (fst , fst₁ , snd))) = subst-in-neq{e = f fst fst₁} nin snd
subst-in-neq {N} {n} {m} {LabE f e} {s} nin (in-LabE (inj₂ y)) = subst-in-neq{e = e} nin y
subst-in-neq {N} {n} {m} {Prod e e'} {s} nin (in-Prod (inj₁ x)) = subst-in-neq{e = e} nin x
subst-in-neq {N} {n} {m} {Prod e e'} {s} nin (in-Prod (inj₂ y)) = sucn≢sucm⇒n≢m (subst-in-neq{e = e'} (notin-shift-one nin) y)
subst-in-neq {N} {n} {m} {Let e e'} {s} nin (in-Let (inj₁ x)) = subst-in-neq{e = e} nin x
subst-in-neq {N} {n} {m} {Let e e'} {s} nin (in-Let (inj₂ y))
with notin-shift{k = 2} z≤n nin
... | w rewrite (n+2≡sucsucn{n}) = sucn≢sucm⇒n≢m (sucn≢sucm⇒n≢m (subst-in-neq{e = e'} w y))
-- if n ≢ m, n ∈` e, then n ∈` [ m ↦ e' ] e
subst-in : {N n m : ℕ} {e e' : Exp {N}} → n ≢ m → n ∈` e → n ∈` ([ m ↦ e' ] e)
subst-in {N} {n} {m} {Var x} {e'} neq (in-Var)
with n ≟ᴺ m
... | yes p = contradiction p neq
... | no ¬p = in-Var
subst-in {N} {n} {m} {Abs e} {e'} neq (in-Abs j) = in-Abs (subst-in (n≢m⇒sucn≢sucm neq) j)
subst-in {N} {n} {m} {App e e₁} {e'} neq (in-App z)
with z
... | inj₁ x = in-App (inj₁ (subst-in neq x))
... | inj₂ y = in-App (inj₂ (subst-in neq y))
subst-in {N} {n} {m} {LabE f e} {e'} neq (in-LabE z)
with z
... | inj₁ (fst , fst₁ , snd) = in-LabE (inj₁ (fst , (fst₁ , (subst-in neq snd))))
... | inj₂ y = in-LabE (inj₂ (subst-in neq y))
subst-in {N} {n} {m} {Prod e e'} {e''} neq (in-Prod (inj₁ x)) = in-Prod (inj₁ (subst-in neq x))
subst-in {N} {n} {m} {Prod e e'} {e''} neq (in-Prod (inj₂ y)) = in-Prod (inj₂ (subst-in (n≢m⇒sucn≢sucm neq) y))
subst-in {N} {n} {m} {Let e e'} {e''} neq (in-Let (inj₁ x)) = in-Let (inj₁ (subst-in neq x))
subst-in {N} {n} {m} {Let e e'} {e''} neq (in-Let (inj₂ y)) = in-Let (inj₂ (subst-in (n≢m⇒sucn≢sucm (n≢m⇒sucn≢sucm neq)) y))
-- if n ≢ m, n ∉ e', n ∈ [ m ↦ e' ] e, then n ∈ e
subst-in-reverse : {N n m : ℕ} {e e' : Exp {N}} → n ≢ m → ¬ (n ∈` e') → n ∈` ([ m ↦ e' ] e) → n ∈` e
subst-in-reverse {N} {n} {m} {Var x} {e'} neq nin ins
with x ≟ᴺ m
... | yes p = contradiction ins nin
... | no ¬p = ins
subst-in-reverse {N} {n} {m} {Abs e} {e'} neq nin (in-Abs ins) = in-Abs (subst-in-reverse (n≢m⇒sucn≢sucm neq) (notin-shift-one{N}{n}{e'} nin) ins)
subst-in-reverse {N} {n} {m} {App e e₁} {e'} neq nin (in-App (inj₁ x)) = in-App (inj₁ (subst-in-reverse neq nin x))
subst-in-reverse {N} {n} {m} {App e e₁} {e'} neq nin (in-App (inj₂ y)) = in-App (inj₂ (subst-in-reverse neq nin y))
subst-in-reverse {N} {n} {m} {LabE f e} {e'} neq nin (in-LabE (inj₁ (fst , fst₁ , snd))) = in-LabE (inj₁ (fst , (fst₁ , subst-in-reverse{e = f fst fst₁} neq nin snd)))
subst-in-reverse {N} {n} {m} {LabE f e} {e'} neq nin (in-LabE (inj₂ y)) = in-LabE (inj₂ (subst-in-reverse neq nin y))
subst-in-reverse {N} {n} {m} {Prod e e'} {e''} neq nin (in-Prod (inj₁ x)) = in-Prod (inj₁ (subst-in-reverse neq nin x))
subst-in-reverse {N} {n} {m} {Prod e e'} {e''} neq nin (in-Prod (inj₂ y)) = in-Prod (inj₂ (subst-in-reverse (n≢m⇒sucn≢sucm neq) (notin-shift-one{e = e''} nin) y))
subst-in-reverse {N} {n} {m} {Let e e'} {e''} neq nin (in-Let (inj₁ x)) = in-Let (inj₁ (subst-in-reverse neq nin x))
subst-in-reverse {N} {n} {m} {Let e e'} {e''} neq nin (in-Let (inj₂ y))
with notin-shift{k = 2} z≤n nin
... | w rewrite (n+2≡sucsucn{n}) = in-Let (inj₂ (subst-in-reverse (n≢m⇒sucn≢sucm (n≢m⇒sucn≢sucm neq)) w y))
var-env-< : {N : ℕ} {Γ : TEnv {N}} {T : Ty} {n : ℕ} (j : n ∶ T ∈ Γ) → n <ᴺ (length Γ)
var-env-< {N} {.(⟨ T , _ ⟩)} {T} {.0} here = s≤s z≤n
var-env-< {N} {.(⟨ _ , _ ⟩)} {T} {.(ℕ.suc _)} (there j) = s≤s (var-env-< j)
-- variables contained in a term are < length of env.
free-vars-env-< : {N : ℕ} {e : Exp {N}} {Γ : TEnv {N}} {T : Ty {N}} → Γ ⊢ e ∶ T → (∀ n → n ∈` e → n <ᴺ length Γ)
free-vars-env-< {N} {Var x₁} {Γ} {T} (TConv j x) .x₁ in-Var = free-vars-env-< j x₁ in-Var
free-vars-env-< {N} {Var x₁} {Γ} {T} (TVarE x eq) .x₁ in-Var = var-env-< x
free-vars-env-< {N} {Abs e} {Γ} {T} (TConv j x₁) n x = free-vars-env-< j n x
free-vars-env-< {N} {Abs e} {Γ} {.(Pi _ _)} (TPiI j) n (in-Abs x) = ≤-pred (free-vars-env-< j (ℕ.suc n) x)
free-vars-env-< {N} {App e e₁} {Γ} {T} (TConv j x₁) n x = free-vars-env-< j n x
free-vars-env-< {N} {App e e₁} {Γ} {.([ 0 ↦ e₁ ]ᵀ _)} (TPiE j j₁ x₁) n (in-App (inj₁ x)) = free-vars-env-< j n x
free-vars-env-< {N} {App e e₁} {Γ} {.([ 0 ↦ e₁ ]ᵀ _)} (TPiE j j₁ x₁) n (in-App (inj₂ y)) = free-vars-env-< j₁ n y
free-vars-env-< {N} {LabE f e} {Γ} {T} (TConv j x₁) n x = free-vars-env-< j n x
free-vars-env-< {N} {LabE f .(LabI _)} {Γ} {T} (TLabEl{scopecheck = s} j j₁) n (in-LabE (inj₁ (fst , fst₁ , snd))) = s fst fst₁ n snd
free-vars-env-< {N} {LabE f (Var m)} {Γ} {T} (TLabEx f' j) n x
with n ≟ᴺ m
... | yes p rewrite p = free-vars-env-< j m in-Var
free-vars-env-< {N} {LabE f (Var m)} {Γ} {T} (TLabEx f' j) n (in-LabE (inj₁ (fst , fst₁ , snd))) | no ¬p = free-vars-env-< (f' fst fst₁) n (subst-in ¬p snd)
free-vars-env-< {N} {LabE f (Var m)} {Γ} {T} (TLabEx f' j) n (in-LabE (inj₂ y)) | no ¬p = contradiction (inv-in-var y) ¬p
free-vars-env-< {N} {Prod e e₁} {Γ} {T} (TConv j x₁) n x = free-vars-env-< j n x
free-vars-env-< {N} {Prod e e₁} {Γ} {.(Sigma _ _)} (TSigmaI j j₁) n (in-Prod (inj₁ x)) = free-vars-env-< j n x
free-vars-env-< {N} {Prod e e₁} {Γ} {.(Sigma _ _)} (TSigmaI j j₁) n (in-Prod (inj₂ y)) = ≤-pred (free-vars-env-< j₁ (ℕ.suc n) y)
free-vars-env-< {N} {Let e e₁} {Γ} {T} (TConv j x₁) n x = free-vars-env-< j n x
free-vars-env-< {N} {Let e e₁} {Γ} {T} (TSigmaE j j₁ nin) n (in-Let (inj₁ x)) = free-vars-env-< j n x
free-vars-env-< {N} {Let e e₁} {Γ} {T} (TSigmaE j j₁ nin) n (in-Let (inj₂ y)) = ≤-pred (≤-pred (free-vars-env-< j₁ (ℕ.suc (ℕ.suc n)) y))
-- closed expressions have no free variables
closed-free-vars : {N : ℕ} {e : Exp {N}} {T : Ty {N}} → [] ⊢ e ∶ T → (∀ n → ¬ (n ∈` e))
closed-free-vars {N} {Var x} {T} j n z = contradiction (free-vars-env-< j n z) (λ ())
closed-free-vars {N} {Abs e} {T} (TConv j x) n = closed-free-vars j n
closed-free-vars {N} {Abs e} {.(Pi _ _)} (TPiI j) n (in-Abs x) = contradiction ((free-vars-env-< j (ℕ.suc n) x)) (≤⇒≯ (s≤s z≤n))
closed-free-vars {N} {LabI x} {T} (TConv j x₁) n = closed-free-vars j n
closed-free-vars {N} {LabI x} {.(Label _)} (TLabI ins) n = λ ()
closed-free-vars {N} {Prod e e₁} {T} (TConv j x) n = closed-free-vars j n
closed-free-vars {N} {Prod e e₁} {.(Sigma _ _)} (TSigmaI j j₁) n (in-Prod (inj₁ x)) = closed-free-vars j n x
closed-free-vars {N} {Prod e e₁} {.(Sigma _ _)} (TSigmaI j j₁) n (in-Prod (inj₂ y)) = contradiction (free-vars-env-< j₁ (ℕ.suc n) y) (≤⇒≯ (s≤s z≤n))
closed-free-vars {N} {Let e e₁} {T} (TConv j x) n = closed-free-vars j n
closed-free-vars {N} {Let e e₁} {T} (TSigmaE j j₁ nin) n (in-Let (inj₁ x)) = closed-free-vars j n x
closed-free-vars {N} {Let e e₁} {T} (TSigmaE j j₁ nin) n (in-Let (inj₂ y)) = contradiction (free-vars-env-< j₁ (ℕ.suc (ℕ.suc n)) y) (≤⇒≯ (s≤s (s≤s z≤n)))
closed-free-vars {N} {e} {T} j n x = contradiction (free-vars-env-< j n x) (≤⇒≯ z≤n) -- App & LabE have the same proof
-- shifting with a threshold above number of free variables has no effect
shift-env-size : {n : ℕ} {k : ℤ} {q : ℕ} {e : Exp {n}} → (∀ n → n ∈` e → n <ᴺ q) → ↑ k , q [ e ] ≡ e
shift-env-size {n} {k} {q} {Var x} lmap
with x <ᴺ? q
... | yes p = refl
... | no ¬p = contradiction (lmap x in-Var) ¬p
shift-env-size {n} {k} {q} {Abs e} lmap = cong Abs (shift-env-size (extr lmap))
where extr : (∀ n → n ∈` Abs e → n <ᴺ q) → (∀ n → n ∈` e → n <ᴺ ℕ.suc q)
extr lmap zero ins = s≤s z≤n
extr lmap (ℕ.suc n) ins = s≤s (lmap n (in-Abs ins))
shift-env-size {n} {k} {q} {App e e'} lmap = cong₂ App (shift-env-size (extr lmap)) (shift-env-size(extr' lmap))
where extr : (∀ n → n ∈` App e e' → n <ᴺ q) → (∀ n → n ∈` e → n <ᴺ q)
extr lmap n ins = lmap n (in-App (inj₁ ins))
extr' : (∀ n → n ∈` App e e' → n <ᴺ q) → (∀ n → n ∈` e' → n <ᴺ q)
extr' lmap n ins = lmap n (in-App (inj₂ ins))
shift-env-size {n} {k} {q} {LabI x} lmap = refl
shift-env-size {n} {k} {q} {LabE{s = s} f e} lmap = cong₂ LabE (f-ext λ l' → (f-ext λ x → shift-env-size (extr lmap l' x))) (shift-env-size (extr' lmap))
where extr : (∀ n → n ∈` LabE f e → n <ᴺ q) → (l : Fin n) → (x : l ∈ s) → (∀ n → n ∈` f l x → n <ᴺ q)
extr lmap l x n ins = lmap n (in-LabE (inj₁ (l , (x , ins))))
extr' : (∀ n → n ∈` LabE f e → n <ᴺ q) → (∀ n → n ∈` e → n <ᴺ q)
extr' lmap n ins = lmap n (in-LabE (inj₂ ins))
shift-env-size {n} {k} {q} {Prod e e'} lmap = cong₂ Prod (shift-env-size (extr lmap)) (shift-env-size (extr' lmap))
where extr : (∀ n → n ∈` Prod e e' → n <ᴺ q) → (∀ n → n ∈` e → n <ᴺ q)
extr lmap n ins = lmap n (in-Prod (inj₁ ins))
extr' : (∀ n → n ∈` Prod e e' → n <ᴺ q) → (∀ n → n ∈` e' → n <ᴺ ℕ.suc q)
extr' lmap zero ins = s≤s z≤n
extr' lmap (ℕ.suc n) ins = s≤s (lmap n (in-Prod (inj₂ ins)))
shift-env-size {n} {k} {q} {Let e e'} lmap = cong₂ Let (shift-env-size (extr lmap)) (shift-env-size (extr' lmap))
where extr : (∀ n → n ∈` Let e e' → n <ᴺ q) → (∀ n → n ∈` e → n <ᴺ q)
extr lmap n ins = lmap n (in-Let (inj₁ ins))
extr' : (∀ n → n ∈` Let e e' → n <ᴺ q) → (∀ n → n ∈` e' → n <ᴺ ℕ.suc (ℕ.suc q))
extr' lmap zero ins = s≤s z≤n
extr' lmap (ℕ.suc zero) ins = s≤s (s≤s z≤n)
extr' lmap (ℕ.suc (ℕ.suc n)) ins = s≤s (s≤s (lmap n (in-Let (inj₂ ins))))
-- shifting has no effect on closed terms (corollary of shift-env-size)
closed-no-shift : {n : ℕ} {k : ℤ} {q : ℕ} {e : Exp {n}} {T : Ty {n}} → [] ⊢ e ∶ T → ↑ k , q [ e ] ≡ e
closed-no-shift {n} {k} {zero} {e} {T} j = shift-env-size (free-vars-env-< j)
closed-no-shift {n} {k} {ℕ.suc q} {e} {T} j = shift-env-size λ n i → <-trans (free-vars-env-< j n i) (s≤s z≤n)
--
subst-change-in : {N n m : ℕ} {e s s' : Exp{N}} → ¬ (n ∈` s) × ¬ (n ∈` s') → n ∈` ([ m ↦ s ] e) → n ∈` ([ m ↦ s' ] e)
subst-change-in {N} {n} {m} {Var x} {s} {s'} (fst , snd) ins
with x ≟ᴺ m
... | yes eq = contradiction ins fst
... | no ¬eq = ins
subst-change-in {N} {n} {m} {Abs e} {s} {s'} (fst , snd) (in-Abs ins) = in-Abs (subst-change-in{N}{ℕ.suc n}{ℕ.suc m}{e} (notin-shift-one{N}{n}{s} fst , notin-shift-one{N}{n}{s'} snd) ins)
subst-change-in {N} {n} {m} {App e e₁} {s} {s'} p (in-App (inj₁ x)) = in-App (inj₁ (subst-change-in{N}{n}{m}{e} p x))
subst-change-in {N} {n} {m} {App e e₁} {s} {s'} p (in-App (inj₂ y)) = in-App (inj₂ (subst-change-in{N}{n}{m}{e₁} p y))
subst-change-in {N} {n} {m} {LabE f e} {s} {s'} p (in-LabE (inj₁ (fst , fst₁ , snd))) = in-LabE (inj₁ (fst , (fst₁ , (subst-change-in{N}{n}{m}{f fst fst₁}{s}{s'} p snd))))
subst-change-in {N} {n} {m} {LabE f e} {s} {s'} p (in-LabE (inj₂ y)) = in-LabE (inj₂ (subst-change-in {N} {n} {m} {e} p y))
subst-change-in {N} {n} {m} {Prod e e'} {s} {s'} p (in-Prod (inj₁ x)) = in-Prod (inj₁ (subst-change-in{m = m}{e} p x))
subst-change-in {N} {n} {m} {Prod e e'} {s} {s'} (fst , snd) (in-Prod (inj₂ y)) = in-Prod (inj₂ (subst-change-in {N} {ℕ.suc n} {ℕ.suc m} {e'}
(notin-shift-one{N}{n}{s} fst , notin-shift-one {N} {n} {s'} snd) y))
subst-change-in {N} {n} {m} {Let e e'} {s} {s'} p (in-Let (inj₁ x)) = in-Let (inj₁ (subst-change-in {N} {n} {m} {e} p x))
subst-change-in {N} {n} {m} {Let e e'} {s} {s'} (fst , snd) (in-Let (inj₂ y))
with notin-shift{k = 2} z≤n fst | notin-shift{k = 2} z≤n snd
... | w | w' rewrite (n+2≡sucsucn{n}) = in-Let (inj₂ (subst-change-in {N} {ℕ.suc (ℕ.suc n)} {ℕ.suc (ℕ.suc m)} {e'} (w , w') y))
-- swapping of substitutions A & B if variables of A are not free in substitution term of B and vice versa
subst-subst-swap : {N n m : ℕ} {e e' s : Exp {N}} → n ≢ m → ¬ n ∈` e' → ¬ m ∈` e → [ n ↦ e ] ([ m ↦ e' ] s) ≡ [ m ↦ e' ] ([ n ↦ e ] s)
subst-subst-swap {N} {n} {m} {e} {e'} {Var x} neq nin nin'
with x ≟ᴺ m | x ≟ᴺ n
... | yes p | yes p' = contradiction (≡-trans (sym p') p) neq
... | yes p | no ¬p'
with x ≟ᴺ m
... | yes p'' = subst-refl-notin nin
... | no ¬p'' = contradiction p ¬p''
subst-subst-swap {N} {n} {m} {e} {e'} {Var x} neq nin nin'
| no ¬p | yes p'
with x ≟ᴺ n
... | yes p'' = sym (subst-refl-notin nin')
... | no ¬p'' = contradiction p' ¬p''
subst-subst-swap {N} {n} {m} {e} {e'} {Var x} neq nin nin'
| no ¬p | no ¬p'
with x ≟ᴺ n | x ≟ᴺ m
... | yes p'' | _ = contradiction p'' ¬p'
... | _ | yes p''' = contradiction p''' ¬p
... | no p'' | no ¬p''' = refl
subst-subst-swap {N} {n} {m} {e} {e'} {Abs s} neq nin nin'
with (notin-shift{n = n}{1}{0} z≤n nin) | (notin-shift{n = m}{1}{0} z≤n nin')
... | w | w' rewrite (n+1≡sucn{n}) | (n+1≡sucn{m}) = cong Abs (subst-subst-swap{s = s} (n≢m⇒sucn≢sucm neq) w w')
subst-subst-swap {N} {n} {m} {e} {e'} {App s s₁} neq nin nin' = cong₂ App (subst-subst-swap{s = s} neq nin nin') (subst-subst-swap{s = s₁} neq nin nin')
subst-subst-swap {N} {n} {m} {e} {e'} {LabI x} neq nin nin' = refl
subst-subst-swap {N} {n} {m} {e} {e'} {LabE f s} neq nin nin' = cong₂ LabE (f-ext (λ l → f-ext (λ x → subst-subst-swap{s = f l x} neq nin nin' ))) (subst-subst-swap{s = s} neq nin nin')
subst-subst-swap {N} {n} {m} {e} {e'} {Prod s s'} neq nin nin'
with (notin-shift-one nin) | (notin-shift-one nin')
... | w | w' = cong₂ Prod (subst-subst-swap{s = s} neq nin nin') (subst-subst-swap{s = s'} (n≢m⇒sucn≢sucm neq) w w')
subst-subst-swap {N} {n} {m} {e} {e'} {Let s s'} neq nin nin'
with notin-shift{k = 2} z≤n nin | notin-shift{k = 2} z≤n nin'
... | w | w' rewrite (n+2≡sucsucn{n}) | (n+2≡sucsucn{m}) = cong₂ Let (subst-subst-swap{s = s} neq nin nin') (subst-subst-swap{s = s'} (n≢m⇒sucn≢sucm (n≢m⇒sucn≢sucm neq)) w w')
-- this should be true for all k, but limiting to positive k makes the proof simpler
aux-calc-3 : {m x : ℕ} {k : ℤ} → k >ᶻ + 0 → ∣ + m +ᶻ k ∣ ≡ ∣ + x +ᶻ k ∣ → m ≡ x
aux-calc-3 {m} {x} {+_ n} gt eqv = +-cancelʳ-≡ m x eqv
aux-calc-4 : {m x : ℕ} {k : ℤ} → k >ᶻ + 0 → m ≤ᴺ x → m <ᴺ ∣ + x +ᶻ k ∣
aux-calc-4 {m} {x} {+_ zero} (+<+ ())
aux-calc-4 {m} {x} {+[1+ n ]} (+<+ (s≤s z≤n)) leq = a≤b<c⇒a<c leq (m<m+n x {ℕ.suc n} (s≤s z≤n))
subst-shift-swap : {n : ℕ} {k : ℤ} {x q : ℕ} {s e : Exp {n}} → k >ᶻ + 0 → ↑ k , q [ [ x ↦ e ] s ] ≡ [ ↑ᴺ k , q [ x ] ↦ ↑ k , q [ e ] ] ↑ k , q [ s ]
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
with m ≟ᴺ x
... | yes p
with m <ᴺ? q | x <ᴺ? q
... | yes p' | yes p''
with m ≟ᴺ x
... | yes p''' = refl
... | no ¬p''' = contradiction p ¬p'''
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| yes p | yes p' | no ¬p'' rewrite (cong ℕ.suc p) = contradiction p' ¬p''
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| yes p | no ¬p' | yes p'' rewrite (cong ℕ.suc p) = contradiction p'' ¬p'
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| yes p | no ¬p' | no ¬p''
with ∣ + m +ᶻ k ∣ ≟ᴺ ∣ + x +ᶻ k ∣
... | yes p''' = refl
... | no ¬p''' rewrite p = contradiction refl ¬p'''
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| no ¬p
with m <ᴺ? q | x <ᴺ? q
... | yes p' | yes p''
with m ≟ᴺ x
... | yes p''' = contradiction p''' ¬p
... | no ¬p''' = refl
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| no ¬p | yes p' | no ¬p''
with m ≟ᴺ ∣ + x +ᶻ k ∣
... | yes p''' = contradiction p''' (<⇒≢ (aux-calc-4 gt (≤-pred (≤-trans p' (≰⇒≥ ¬p'')))))
... | no ¬p''' = refl
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| no ¬p | no ¬p' | yes p''
with ∣ + m +ᶻ k ∣ ≟ᴺ x
... | yes p''' = contradiction p''' (≢-sym (<⇒≢ (aux-calc-4{x}{m}{k} gt (≤-pred (≤-trans p'' (≰⇒≥ ¬p'))))))
... | no ¬p''' = refl
subst-shift-swap {n} {k} {x} {q} {Var m} {e} gt
| no ¬p | no ¬p' | no ¬p''
with ∣ + m +ᶻ k ∣ ≟ᴺ ∣ + x +ᶻ k ∣
... | yes p''' = contradiction p''' (contraposition (aux-calc-3 gt) ¬p)
... | no ¬p''' = refl
subst-shift-swap {n} {k} {x} {q} {Abs s} {e} gt
with (subst-shift-swap{n}{k}{ℕ.suc x}{ℕ.suc q}{s}{↑¹[ e ]} gt)
... | w
rewrite (↑k,sucq[↑1,c[s]]≡↑1,c[↑k,q[s]] {n} {k} {q} {0} {e} z≤n gt)
| (suc[↑ᴺk,l[x]]≡↑ᴺk,sucl[sucx] {k} {q} {x} gt)
= cong Abs w
subst-shift-swap {n} {k} {x} {q} {App s₁ s₂} {e} gt = cong₂ App (subst-shift-swap {n} {k} {x} {q} {s₁} {e} gt) (subst-shift-swap {n} {k} {x} {q} {s₂} {e} gt)
subst-shift-swap {n} {k} {x} {q} {LabI ins} {e} gt = refl
subst-shift-swap {n} {k} {x} {q} {LabE f s} {e} gt = cong₂ LabE (f-ext (λ l → f-ext (λ ins → subst-shift-swap {n} {k} {x} {q} {f l ins} {e} gt))) (subst-shift-swap {n} {k} {x} {q} {s} {e} gt)
subst-shift-swap {n} {k} {x} {q} {Prod s s'} {e} gt
with (subst-shift-swap{n}{k}{ℕ.suc x}{ℕ.suc q}{s'}{↑¹[ e ]} gt)
... | w
rewrite (↑k,sucq[↑1,c[s]]≡↑1,c[↑k,q[s]] {n} {k} {q} {0} {e} z≤n gt)
| (suc[↑ᴺk,l[x]]≡↑ᴺk,sucl[sucx] {k} {q} {x} gt)
= cong₂ Prod (subst-shift-swap {n} {k} {x} {q} {s} {e} gt) w
subst-shift-swap {n} {k} {x} {q} {Let s s'} {e} gt
with (subst-shift-swap{n}{k}{ℕ.suc (ℕ.suc x)}{ℕ.suc (ℕ.suc q)}{s'}{↑ + 2 , 0 [ e ]} gt)
... | w
rewrite (↑k,sucsucq[↑2,c[s]]≡↑2,c[↑k,q[s]] {n} {k} {q} {0} {e} z≤n gt)
| sym (suc[↑ᴺk,l[x]]≡↑ᴺk,sucl[sucx] {k} {(ℕ.suc q)} {(ℕ.suc x)} gt )
| sym (suc[↑ᴺk,l[x]]≡↑ᴺk,sucl[sucx] {k} {q} {x} gt )
= cong₂ Let (subst-shift-swap {n} {k} {x} {q} {s} {e} gt) w
--- typing: canonical forms, inequalities
case-redex-eq : {n : ℕ} {s : Subset n} {f : (l : Fin n) → l ∈ s → Ty} {e : Exp} {T T' : Ty} → (([] ⊢ Case f e ≡ᵀ T) × ([] ⊢ Case f e ≡ᵀ T')) → [] ⊢ T ≡ᵀ T'
case-redex-eq {n} {s} {f} {e} {T} {T'} (fst , snd) = CTrans (CSym fst) snd
type-lab : {n : ℕ} {T : Ty {n}} {x : Fin n} → [] ⊢ LabI x ∶ T → ∃[ s ]( [] ⊢ T ≡ᵀ Label s × x ∈ s )
type-lab {n} {Label x₁} {x} (TLabI ins) = x₁ , (CRefl{ok = TLabF}) , ins
type-lab {n} {e} {x} (TConv j y)
with type-lab j
... | fst , snd , snd' = fst , CTrans (CSym y) snd , snd'
type-prod : {n : ℕ} {T : Ty {n}} {e e' : Exp} → [] ⊢ Prod e e' ∶ T → ∃[ A ](∃[ B ]( [] ⊢ T ≡ᵀ Sigma A B ))
type-prod {n} {T} {x} (TSigmaI{A = A}{B = B}{ok = ok}{ok' = ok'} y y') = A , (B , (CRefl{ok = TSigmaF ok ok'}))
type-prod {n} {T} {x} (TConv j y)
with type-prod j
... | fst , fst₁ , snd = fst , (fst₁ , (CTrans (CSym y) snd))
type-abs : {n : ℕ} {T : Ty {n}} {e : Exp} → [] ⊢ Abs e ∶ T → ∃[ A ](∃[ B ]( [] ⊢ T ≡ᵀ Pi A B))
type-abs {n} {.(Pi _ _)} {e} (TPiI{A = A}{B = B}{ok = ok}{ok' = ok'} j) = A , (B , (CRefl{ok = TPiF ok ok'}))
type-abs {n} {T} {e} (TConv j x)
with type-abs j
... | fst , fst₁ , snd = fst , fst₁ , CTrans (CSym x) snd
canonical-forms-pi : {n : ℕ} {A B : Ty {n}} {e : Exp {n}} → [] ⊢ e ∶ Pi A B → Val e → ∃[ e' ]( e ≡ Abs e' )
canonical-forms-pi {n} {A} {B} {Var x} j VVar = contradiction (in-Var) (closed-free-vars j x)
canonical-forms-pi {n} {A} {B} {Abs e} j v = e , refl
canonical-forms-pi {n} {A} {B} {LabI x} (TConv {T = Label x₂} j x₁) v = contradiction x₁ (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-pi {n} {A} {B} {LabI x} (TConv {T = Pi T T₁} j x₁) v = (proj₁ (canonical-forms-pi j v)) , (≡-trans refl (proj₂ (canonical-forms-pi j v)))
canonical-forms-pi {n} {A} {B} {LabI x} (TConv {T = Sigma T T₁} j x₁) v = contradiction x₁ (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-pi {n} {A} {B} {LabI x} (TConv {T = Case f x₂} j x₁) v = contradiction (case-redex-eq (proj₁ (proj₂ (type-lab j)) , x₁)) (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-pi {n} {A} {B} {Prod e e'} (TConv {T = Label x₁} j x) v = contradiction x (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-pi {n} {A} {B} {Prod e e'} (TConv {T = Pi T' T''} j x) v = (proj₁ (canonical-forms-pi j v)) , (≡-trans refl (proj₂ (canonical-forms-pi j v)))
canonical-forms-pi {n} {A} {B} {Prod e e'} (TConv {T = Sigma T' T''} j x) v = contradiction x (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-pi {n} {A} {B} {Prod e e'} (TConv {T = Case f x₁} j x) v = contradiction (case-redex-eq (proj₂ (proj₂ (type-prod j)) , x)) (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma : {n : ℕ} {A B : Ty {n}} {e : Exp {n}} → [] ⊢ e ∶ Sigma A B → Val e → ∃[ e₁ ]( ∃[ e₂ ] ( e ≡ Prod e₁ e₂ ))
canonical-forms-sigma {n} {A} {B} {Var x} j VVar = contradiction (in-Var) (closed-free-vars j x)
canonical-forms-sigma {n} {A} {B} {Abs e} (TConv {T = Label x₁} j x) v = contradiction x (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma {n} {A} {B} {Abs e} (TConv {T = Pi T T₁} j x) v = contradiction x (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma {n} {A} {B} {Abs e} (TConv {T = Sigma T T₁} j x) v = (proj₁ (canonical-forms-sigma j v)) , (proj₂ (canonical-forms-sigma j v))
canonical-forms-sigma {n} {A} {B} {Abs e} (TConv {T = Case f x₁} j x) v = contradiction (case-redex-eq (proj₂ (proj₂ (type-abs j)) , x)) (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma {n} {A} {B} {LabI x} (TConv {T = Label x₁} j y) v = contradiction y (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma {n} {A} {B} {LabI x} (TConv {T = Pi T T₁} j y) v = contradiction y (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma {n} {A} {B} {LabI x} (TConv {T = Sigma T T₁} j y) v = (proj₁ (canonical-forms-sigma j v)) , (proj₂ (canonical-forms-sigma j v))
canonical-forms-sigma {n} {A} {B} {LabI x} (TConv {T = Case f x₁} j y) v = contradiction (case-redex-eq (proj₁ (proj₂ (type-lab j)) , y)) (≢ᵀ'⇒≢ᵀ (λ ()))
canonical-forms-sigma {n} {A} {B} {Prod e e₁} j v = e , e₁ , refl
---- progress and preservation
-- progress theorem, i.e. a well-typed closed expression is either a value
-- or can be reduced further
data Progress {n : ℕ} (e : Exp {n}) {T : Ty} {j : [] ⊢ e ∶ T} : Set where
step : {e' : Exp{n}} → e ⇒ e' → Progress e
value : Val e → Progress e
progress : {n : ℕ} (e : Exp {n}) {T : Ty} {j : [] ⊢ e ∶ T} → Progress e {T} {j}
progress {n} e {T} {TConv{T = T'}{T' = .T} j x}
with progress e {j = j}
... | step {e' = e'} x₁ = step x₁
... | value x₁ = value x₁
progress {n} .(Abs _) {.(Pi _ _)} {TPiI j} = value VFun
progress {n} .(App e e') {T} {TPiE{e = e} {e' = e'} j j₁ x}
with progress e {j = j}
... | step x₁ = step (ξ-App1 x₁)
... | value x₁
with progress e' {j = j₁}
... | step x₂ = step (ξ-App2 x₁ x₂)
... | value x₂
with canonical-forms-pi j x₁
... | fst , snd rewrite snd = step (β-App x₂)
progress {n} .(Prod _ _) {.(Sigma _ _)} {TSigmaI{e = e}{e' = e'} j j₁}
with progress e {j = j}
... | step x = step (ξ-Prod1 x)
... | value x = {!!}
progress {n} .(Let _ _) {T} {TSigmaE{e = e} {e' = e'} j j₁ nin}
with progress e {j = j}
... | step x = step (ξ-Let x)
... | value x
with canonical-forms-sigma j x
... | fst , snd , snd₁ rewrite snd₁
with x
... | VProd y y₁ = step (β-Let y y₁)
progress {n} .(LabI _) {.(Label _)} {TLabI ins} = value VLab
progress {n} .(LabE _ (LabI _)) {T} {TLabEl{ins = ins} j j₁} = step (β-LabE ins)
progress {n} (LabE f (Var m)) {T} {TLabEx f' j} = contradiction (free-vars-env-< j m in-Var) λ ()
|
{
"alphanum_fraction": 0.4534026196,
"avg_line_length": 64.1461187215,
"ext": "agda",
"hexsha": "7b3b97c7e45018acb56db59c288eb1f306f571e0",
"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": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "kcaliban/ldlc",
"max_forks_repo_path": "src/ldlc/LDLC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"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": "kcaliban/ldlc",
"max_issues_repo_path": "src/ldlc/LDLC.agda",
"max_line_length": 331,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "kcaliban/ldlc",
"max_stars_repo_path": "src/ldlc/LDLC.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 37032,
"size": 70240
}
|
-- This module introduces implicit arguments.
module Id8 where
id8 : {A : Set} -> A -> A
id8 = \{A} x -> x -- this doesn't work since the type checker assumes
-- that the implicit A has been has been omitted in
-- the left-hand side (as in id6).
|
{
"alphanum_fraction": 0.5352564103,
"avg_line_length": 31.2,
"ext": "agda",
"hexsha": "99e2ad53e3bd30587888347944762e3d16195514",
"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": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/Id8.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"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": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/Id8.agda",
"max_line_length": 79,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/Id8.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 73,
"size": 312
}
|
module Mask where
open import Basics
open import Ix
open import All
open import Cutting
open import Splitting
open import Perm
open import Interior
open import Recutter
module MASK {I}(C : I |> I) where
open _|>_
open INTERIOR C
open RECUTTER C
module CHOP {P}(pc : CutKit P)(rec : Recutter) where
glue : (is : List I) -> (d : Subs is) ->
All (Interior P) (subCollect is d) -> All (Interior P) is
glue [] <> <> = <>
glue (i ,- is) (inl <> , ds) (p , ps) = p , glue is ds ps
glue (i ,- is) (inr c , ds) ps with isRiffle (slrs (inners C c) (subCollect is ds)) ps
glue (i ,- is) (inr c , ds) .(riffle (slrs (inners C c) (subCollect is ds)) lp rp)
| mkRiffle lp rp = < c 8>< lp > , glue is ds rp
chop : (i : I)(c c' : Cuts C i) ->
All (Interior P) (inners C c) -> All (Interior P) (inners C c')
chops : (is : List I) -> All (Interior P) is -> (d : Subs is) ->
All (Interior P) (subCollect is d)
chop i c c' ps with rec i c c'
... | d , d' , m with chops (inners C c) ps d
... | qs = glue (inners C c') d' (permute m qs)
chops [] <> <> = <>
chops (i ,- is) (p , ps) (inl <> , ds) = p , chops is ps ds
chops (i ,- is) (tile p , ps) (inr c' , ds) =
cat (inners C c') (subCollect is ds) (all (\ _ -> tile) _ (pc i c' p)) (chops is ps ds)
chops (i ,- is) (< c 8>< ps' > , ps) (inr c' , ds) =
cat (inners C c') (subCollect is ds) (chop i c c' ps') (chops is ps ds)
mask : forall {O Q} -> [ O -:> Interior P -:> Interior Q ]
-> [ Interior O -:> Interior P -:> Interior Q ]
mask {O}{Q} f = ifold f help where
help : [ Cutting C (Interior P -:> Interior Q) -:> Interior P -:> Interior Q ]
help i (c' 8>< fs) (tile p) with pc i c' p
... | ps = < c' 8>< allAp (inners C c') fs (all (\ _ -> tile) _ ps) >
help i (c' 8>< fs) < c 8>< ps > = < c' 8>< allAp (inners C c') fs (chop i c c' ps) >
|
{
"alphanum_fraction": 0.5165562914,
"avg_line_length": 40.0612244898,
"ext": "agda",
"hexsha": "3d2ceb9531aa957a9c29133fc1c2fa26b5c4e398",
"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": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pigworker/InteriorDesign",
"max_forks_repo_path": "Mask.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"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": "pigworker/InteriorDesign",
"max_issues_repo_path": "Mask.agda",
"max_line_length": 93,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pigworker/InteriorDesign",
"max_stars_repo_path": "Mask.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z",
"num_tokens": 710,
"size": 1963
}
|
{-
This file contains:
- Definition of set truncations
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.SetTruncation.Base where
open import Cubical.Core.Primitives
open import Cubical.Foundations.Pointed
-- set truncation as a higher inductive type:
data ∥_∥₂ {ℓ} (A : Type ℓ) : Type ℓ where
∣_∣₂ : A → ∥ A ∥₂
squash₂ : ∀ (x y : ∥ A ∥₂) (p q : x ≡ y) → p ≡ q
-- Pointed version
∥_∥₂∙ : ∀ {ℓ} (A : Pointed ℓ) → Pointed ℓ
fst ∥ A ∥₂∙ = ∥ fst A ∥₂
snd ∥ A ∥₂∙ = ∣ pt A ∣₂
|
{
"alphanum_fraction": 0.6087866109,
"avg_line_length": 19.9166666667,
"ext": "agda",
"hexsha": "033d8650632c431ce06d438397872b50a0036999",
"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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/HITs/SetTruncation/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"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": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/HITs/SetTruncation/Base.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/HITs/SetTruncation/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 203,
"size": 478
}
|
open import Categories
open import Monads
module Monads.EM {a b}{C : Cat {a}{b}}(M : Monad C) where
open import Library
open import Functors
open Cat C
open Monad M
record Alg : Set (a ⊔ b) where
constructor alg
field acar : Obj
astr : ∀ Z → Hom Z acar → Hom (T Z) acar
alaw1 : ∀ {Z}{f : Hom Z acar} → f ≅ comp (astr Z f) η
alaw2 : ∀{Z}{W}{k : Hom Z (T W)}{f : Hom W acar} →
astr Z (comp (astr W f) k) ≅ comp (astr W f) (bind k)
open Alg
AlgEq : {X Y : Alg} → acar X ≅ acar Y → (astr X ≅ astr Y) → X ≅ Y
AlgEq {alg acar astr _ _} {alg ._ ._ _ _} refl refl =
cong₂ (alg acar astr)
(iext λ _ → iext λ _ → ir _ _)
(iext λ _ → iext λ _ → iext λ _ → iext λ _ → ir _ _)
record AlgMorph (A B : Alg) : Set (a ⊔ b) where
constructor algmorph
field amor : Hom (acar A) (acar B)
ahom : ∀{Z}{f : Hom Z (acar A)} →
comp amor (astr A Z f) ≅ astr B Z (comp amor f)
open AlgMorph
AlgMorphEq : {X Y : Alg}{f g : AlgMorph X Y} → amor f ≅ amor g → f ≅ g
AlgMorphEq {f = algmorph amor _}{algmorph .amor _} refl =
cong (algmorph amor)
(iext λ _ → iext λ _ → ir _ _)
AlgMorphEq' : {X X' Y Y' : Alg}
{f : AlgMorph X Y}{g : AlgMorph X' Y'} → X ≅ X' → Y ≅ Y' →
amor f ≅ amor g → f ≅ g
AlgMorphEq' refl refl = AlgMorphEq
IdMorph : {A : Alg} → AlgMorph A A
IdMorph {A} = record {
amor = iden;
ahom = λ {Z} {f} →
proof
comp iden (astr A Z f)
≅⟨ idl ⟩
astr A Z f
≅⟨ cong (astr A Z) (sym idl) ⟩
astr A Z (comp iden f)
∎}
CompMorph : {X Y Z : Alg} → AlgMorph Y Z → AlgMorph X Y → AlgMorph X Z
CompMorph {X}{Y}{Z} f g = record {
amor = comp (amor f) (amor g);
ahom = λ{W}{h} →
proof
comp (comp (amor f) (amor g)) (astr X W h)
≅⟨ ass ⟩
comp (amor f) (comp (amor g) (astr X W h))
≅⟨ cong (comp (amor f)) (ahom g) ⟩
comp (amor f) (astr Y W (comp (amor g) h))
≅⟨ ahom f ⟩
astr Z W (comp (amor f) (comp (amor g) h))
≅⟨ cong (astr Z W) (sym ass) ⟩
astr Z W (comp (comp (amor f) (amor g)) h)
∎}
idlMorph : {X Y : Alg}{f : AlgMorph X Y} → CompMorph IdMorph f ≅ f
idlMorph = AlgMorphEq idl
idrMorph : {X Y : Alg}{f : AlgMorph X Y} → CompMorph f IdMorph ≅ f
idrMorph = AlgMorphEq idr
assMorph : {W X Y Z : Alg}
{f : AlgMorph Y Z}{g : AlgMorph X Y}{h : AlgMorph W X} →
CompMorph (CompMorph f g) h ≅ CompMorph f (CompMorph g h)
assMorph = AlgMorphEq ass
EM : Cat {a ⊔ b}{a ⊔ b}
EM = record{
Obj = Alg;
Hom = AlgMorph;
iden = IdMorph;
comp = CompMorph;
idl = idlMorph;
idr = idrMorph;
ass = λ{_}{_}{_}{_}{f}{g}{h} → assMorph {f = f}{g}{h}}
-- -}
|
{
"alphanum_fraction": 0.5414156627,
"avg_line_length": 28.5591397849,
"ext": "agda",
"hexsha": "14c0828d6c39b543e1583c57fb63e1877f1c0d9e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Monads/EM.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Monads/EM.agda",
"max_line_length": 70,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Monads/EM.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 1129,
"size": 2656
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Sn.Properties where
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Path
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.Susp
open import Cubical.HITs.Truncation
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Connected
private
variable
ℓ : Level
sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n)
sphereConnected n = ∣ ptSn n ∣ , elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a → sym (spoke ∣_∣ (ptSn n)) ∙ spoke ∣_∣ a)
-- Elimination principles for spheres
sphereElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isOfHLevel (suc n) (A x))
→ A (ptSn (suc n))
→ (x : S₊ (suc n)) → A x
sphereElim zero hlev pt = toPropElim hlev pt
sphereElim (suc n) hlev pt north = pt
sphereElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt
sphereElim (suc n) {A = A} hlev pt (merid a i) =
sphereElim n {A = λ a → PathP (λ i → A (merid a i)) pt (subst A (merid (ptSn (suc n))) pt)}
(λ a → isOfHLevelPathP' (suc n) (hlev south) _ _)
(λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∧ j))) (~ i) pt)
a i
sphereElim2 : ∀ {ℓ} (n : ℕ) {A : (S₊ (suc n)) → (S₊ (suc n)) → Type ℓ}
→ ((x y : S₊ (suc n)) → isOfHLevel (suc n) (A x y))
→ A (ptSn (suc n)) (ptSn (suc n))
→ (x y : S₊ (suc n)) → A x y
sphereElim2 n hlev pt = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → hlev _ _)
(sphereElim n (hlev _ ) pt)
private
compPath-lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y)
→ PathP (λ i → (p ∙ sym q) i ≡ y) p q
compPath-lem {y = y} p q i j =
hcomp (λ k → λ { (i = i0) → p j
; (i = i1) → q (~ k ∨ j)
; (j = i1) → y })
(p (j ∨ i))
-- Elimination rule for fibrations (x : Sⁿ) → (y : Sᵐ) → A x y of h-Level (n + m).
-- The following principle is just the special case of the "Wedge Connectivity Lemma"
-- for spheres (See Cubical.Homotopy.WedgeConnectivity or chapter 8.6 in the HoTT book).
-- We prove it directly here for two reasons:
-- (i) it should perform better
-- (ii) we get a slightly stronger statement for spheres -- One of the homotopies will, by design, be refl
wedgeConSn : ∀ {ℓ} (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ Σ[ F ∈ ((x : S₊ (suc n)) (y : S₊ (suc m)) → A x y) ]
((x : S₊ (suc m)) → F (ptSn (suc n)) x ≡ f x) × ((x : S₊ (suc n)) → F x (ptSn (suc m)) ≡ g x)
wedgeConSn zero zero {A = A} hlev f g hom = F , (λ _ → refl) , right
where
helper : SquareP (λ i j → A (loop i) (loop j)) (cong f loop) (cong f loop)
(λ i → hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i)))
λ i → hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i))
helper = transport (sym (PathP≡Path _ _ _))
(isOfHLevelPathP' 1 (hlev base base) _ _ _ _)
F : (x y : S¹) → A x y
F base y = f y
F (loop i) base = hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i))
F (loop i) (loop j) = helper i j
right : (x : S¹) → F x base ≡ g x
right base = sym hom
right (loop i) j = hcomp (λ k → λ { (i = i0) → hom (~ j ∧ k)
; (i = i1) → hom (~ j ∧ k)
; (j = i1) → g (loop i) })
(g (loop i))
wedgeConSn zero (suc m) {A = A} hlev f g hom = F , left , (λ _ → refl)
where
transpLemma : (x : S₊ (suc m)) → transport (λ i₁ → A base (merid x i₁)) (g base) ≡ f south
transpLemma x = cong (transport (λ i₁ → A base (merid x i₁)))
hom
∙ (λ i → transp (λ j → A base (merid x (i ∨ j))) i
(f (merid x i)))
pathOverMerid : (x : S₊ (suc m)) → PathP (λ i₁ → A base (merid x i₁))
(g base)
(transport (λ i₁ → A base (merid (ptSn (suc m)) i₁))
(g base))
pathOverMerid x i = hcomp (λ k → λ { (i = i0) → g base
; (i = i1) → (transpLemma x ∙ sym (transpLemma (ptSn (suc m)))) k})
(transp (λ i₁ → A base (merid x (i₁ ∧ i))) (~ i)
(g base))
pathOverMeridId : pathOverMerid (ptSn (suc m)) ≡ λ i → transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base)
pathOverMeridId =
(λ j i → hcomp (λ k → λ {(i = i0) → g base
; (i = i1) → rCancel (transpLemma (ptSn (suc m))) j k})
(transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base)))
∙ λ j i → hfill (λ k → λ { (i = i0) → g base
; (i = i1) → transport (λ i₁ → A base (merid (ptSn (suc m)) i₁))
(g base)})
(inS (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base))) (~ j)
indStep : Σ[ F ∈ ((x : _) (a : _) → PathP (λ i → A x (merid a i))
(g x)
(subst (λ y → A x y) (merid (ptSn (suc m)))
(g x))) ] _
indStep = wedgeConSn zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _)
pathOverMerid
(λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g a))
(sym pathOverMeridId)
F : (x : S¹) (y : Susp (S₊ (suc m))) → A x y
F x north = g x
F x south = subst (λ y → A x y) (merid (ptSn (suc m))) (g x)
F x (merid a i) = indStep .fst x a i
left : (x : Susp (S₊ (suc m))) → F base x ≡ f x
left north = hom
left south = cong (subst (A base) (merid (ptSn (suc m)))) hom
∙ λ i → transp (λ j → A base (merid (ptSn (suc m)) (i ∨ j))) i
(f (merid (ptSn (suc m)) i))
left (merid a i) j =
hcomp (λ k → λ { (i = i0) → hom j
; (i = i1) → transpLemma (ptSn (suc m)) j
; (j = i0) → indStep .snd .fst a (~ k) i
; (j = i1) → f (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom j
; (i = i1) → compPath-lem (transpLemma a) (transpLemma (ptSn (suc m))) k j
; (j = i1) → f (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom j
; (j = i0) → transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i)
(g base)
; (j = i1) → transp (λ j → A base (merid a (i ∧ (j ∨ k)))) (k ∨ ~ i)
(f (merid a (i ∧ k)))})
(transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i)
(hom j))))
wedgeConSn (suc n) m {A = A} hlev f g hom = F , ((λ _ → refl) , right)
where
transpLemma : (x : S₊ (suc n)) → transport (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) ≡ g south
transpLemma x = cong (transport (λ i₁ → A (merid x i₁) (ptSn (suc m))))
(sym hom)
∙ (λ i → transp (λ j → A (merid x (i ∨ j)) (ptSn (suc m))) i
(g (merid x i)))
pathOverMerid : (x : S₊ (suc n)) → PathP (λ i₁ → A (merid x i₁) (ptSn (suc m)))
(f (ptSn (suc m)))
(transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m)))
(f (ptSn (suc m))))
pathOverMerid x i = hcomp (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → (transpLemma x ∙ sym (transpLemma (ptSn (suc n)))) k })
(transp (λ i₁ → A (merid x (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m))))
pathOverMeridId : pathOverMerid (ptSn (suc n)) ≡ λ i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))
pathOverMeridId =
(λ j i → hcomp (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → rCancel (transpLemma (ptSn (suc n))) j k })
(transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))))
∙ λ j i → hfill (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m)))
(f (ptSn (suc m))) })
(inS (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m))))) (~ j)
indStep : Σ[ F ∈ ((a : _) (y : _) → PathP (λ i → A (merid a i) y)
(f y)
(subst (λ x → A x y) (merid (ptSn (suc n)))
(f y))) ] _
indStep = wedgeConSn n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _)
(λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i)
(f a))
pathOverMerid
pathOverMeridId
F : (x : Susp (S₊ (suc n))) (y : S₊ (suc m)) → A x y
right : (x : Susp (S₊ (suc n))) → F x (ptSn (suc m)) ≡ g x
F north y = f y
F south y = subst (λ x → A x y) (merid (ptSn (suc n))) (f y)
F (merid a i) y = indStep .fst a y i
right north = sym hom
right south = cong (subst (λ x → A x (ptSn (suc m)))
(merid (ptSn (suc n))))
(sym hom)
∙ λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∨ j)) (ptSn (suc m))) i
(g (merid (ptSn (suc n)) i))
right (merid a i) j =
hcomp (λ k → λ { (i = i0) → hom (~ j)
; (i = i1) → transpLemma (ptSn (suc n)) j
; (j = i0) → indStep .snd .snd a (~ k) i
; (j = i1) → g (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom (~ j)
; (i = i1) → compPath-lem (transpLemma a) (transpLemma (ptSn (suc n))) k j
; (j = i1) → g (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom (~ j)
; (j = i0) → transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))
; (j = i1) → transp (λ j → A (merid a (i ∧ (j ∨ k))) (ptSn (suc m))) (k ∨ ~ i)
(g (merid a (i ∧ k))) })
(transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i)
(hom (~ j)))))
-- We get ∥ Sⁿ⁺² ∥ₙ₊₂ ≃ ∥ Ω Sⁿ⁺³ ∥ₙ₊₂ from the Freudenthal suspension theorem.
-- Cavallos proof of the Freudenthal suspenion theorem (see Cubical.Homotopy.Freudenthal)
-- can be modified to completely avoid theory about connectedness if one
-- only considers (n+2)-spheres:
module miniFreudenthal (n : HLevel) where
σ : S₊ (2 + n) → typ (Ω (S₊∙ (3 + n)))
σ a = merid a ∙ merid north ⁻¹
S2+n = S₊ (2 + n)
4n+2 = (2 + n) + (2 + n)
module WC-S (p : north ≡ north) where
P : (a b : S2+n) → Type₀
P a b = σ b ≡ p → hLevelTrunc 4n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p)
hLevelP : (a b : S2+n) → isOfHLevel 4n+2 (P a b)
hLevelP _ _ = isOfHLevelΠ 4n+2 λ _ → isOfHLevelTrunc 4n+2
leftFun : (a : S2+n) → P a north
leftFun a r = ∣ a , (rCancel' (merid a) ∙ rCancel' (merid north) ⁻¹) ∙ r ∣
rightFun : (b : S2+n) → P north b
rightFun b r = ∣ b , r ∣
funsAgree : leftFun north ≡ rightFun north
funsAgree i r = ∣ north , ((cong (_∙ r) (rCancel' (rCancel' (merid north))) ∙ lUnit r ⁻¹) i) ∣
totalFun : (a b : S2+n) → P a b
totalFun = wedgeConSn (suc n) (suc n) hLevelP rightFun leftFun funsAgree .fst
leftId : (λ x → totalFun x north) ≡ leftFun
leftId x i = wedgeConSn (suc n) (suc n) hLevelP rightFun leftFun funsAgree .snd .snd i x
fwd : (p : north ≡ north) (a : S2+n)
→ hLevelTrunc 4n+2 (fiber σ p)
→ hLevelTrunc 4n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p)
fwd p a = rec (isOfHLevelTrunc 4n+2) (uncurry (WC-S.totalFun p a))
fwdnorth : (p : north ≡ north) → fwd p north ≡ idfun _
fwdnorth p = funExt (elim (λ _ → isOfHLevelPath 4n+2 (isOfHLevelTrunc 4n+2) _ _)
λ p → refl)
isEquivFwd : (p : north ≡ north) (a : S2+n) → isEquiv (fwd p a)
isEquivFwd p =
suspToPropElim (ptSn (suc n))
(λ _ → isPropIsEquiv _)
helper
where
helper : isEquiv (fwd p north)
helper = subst isEquiv (sym (fwdnorth p)) (idIsEquiv _)
interpolate : (a : S2+n)
→ PathP (λ i → S2+n → north ≡ merid a i) (λ x → merid x ∙ merid a ⁻¹) merid
interpolate a i x j = compPath-filler (merid x) (merid a ⁻¹) (~ i) j
Code : (y : Susp S2+n) → north ≡ y → Type₀
Code north p = hLevelTrunc 4n+2 (fiber σ p)
Code south q = hLevelTrunc 4n+2 (fiber merid q)
Code (merid a i) p =
Glue
(hLevelTrunc 4n+2 (fiber (interpolate a i) p))
(λ
{ (i = i0) → _ , (fwd p a , isEquivFwd p a)
; (i = i1) → _ , idEquiv _
})
encode' : (y : S₊ (3 + n)) (p : north ≡ y) → Code y p
encode' y = J Code ∣ north , rCancel' (merid north) ∣
encodeMerid : (a : S2+n) → encode' south (merid a) ≡ ∣ a , refl ∣
encodeMerid a =
cong (transport (λ i → gluePath i))
(funExt⁻ (funExt⁻ (WC-S.leftId refl) a) _ ∙ λ i → ∣ a , lem (rCancel' (merid a)) (rCancel' (merid north)) i ∣)
∙ transport (PathP≡Path gluePath _ _)
(λ i → ∣ a , (λ j k → rCancel-filler' (merid a) i j k) ∣)
where
gluePath : I → Type _
gluePath i = hLevelTrunc 4n+2 (fiber (interpolate a i) (λ j → merid a (i ∧ j)))
lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y) → (p ∙ q ⁻¹) ∙ q ≡ p
lem p q = assoc p (q ⁻¹) q ⁻¹ ∙∙ cong (p ∙_) (lCancel q) ∙∙ rUnit p ⁻¹
contractCodeNorth : (p : north ≡ north) (c : Code north p) → encode' north p ≡ c
contractCodeNorth =
transport (λ i → (p : north ≡ merid north (~ i))
(c : Code (merid north (~ i)) p)
→ encode' (merid north (~ i)) p ≡ c)
λ p → elim (λ _ → isOfHLevelPath 4n+2 (isOfHLevelTrunc 4n+2) _ _)
(uncurry λ a → J (λ p r → encode' south p ≡ ∣ a , r ∣)
(encodeMerid a))
isConnectedσ : isConnectedFun 4n+2 σ
fst (isConnectedσ p) = encode' north p
snd (isConnectedσ p) = contractCodeNorth p
isConnectedσ-Sn : (n : ℕ) → isConnectedFun (4 + n) (miniFreudenthal.σ n)
isConnectedσ-Sn n = isConnectedFunSubtr _ n _
(subst (λ x → isConnectedFun x (miniFreudenthal.σ n))
helper
(miniFreudenthal.isConnectedσ n))
where
helper : 2 + (n + (2 + n)) ≡ n + (4 + n)
helper = cong suc (sym (+-suc n _)) ∙ sym (+-suc n _)
stabSpheres-n≥2 : (n : ℕ) → Iso (hLevelTrunc (4 + n) (S₊ (2 + n))) (hLevelTrunc (4 + n) (typ (Ω (S₊∙ (3 + n)))))
stabSpheres-n≥2 n = connectedTruncIso (4 + n) (miniFreudenthal.σ n) (isConnectedσ-Sn n)
|
{
"alphanum_fraction": 0.4350091787,
"avg_line_length": 49.814159292,
"ext": "agda",
"hexsha": "8fc06f1e7657466e9f115ca4d49b318e2864e7f8",
"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": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"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": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5968,
"size": 16887
}
|
{-# OPTIONS --safe --warning=error #-}
open import Sets.EquivalenceRelations
open import Setoids.Setoids
open import Groups.FreeGroup.Definition
open import Groups.Homomorphisms.Definition
open import Groups.Homomorphisms.Lemmas
open import Groups.Definition
open import Decidable.Sets
open import Numbers.Naturals.Order
open import LogicalFormulae
open import Semirings.Definition
open import Groups.Lemmas
module Groups.FreeGroup.UniversalProperty {a : _} {A : Set a} (decA : DecidableSet A) where
open import Groups.FreeGroup.Word decA
open import Groups.FreeGroup.Group decA
universalPropertyFunction : {c d : _} {C : Set c} {S : Setoid {c} {d} C} {_+_ : C → C → C} (G : Group S _+_) → (f : A → C) → ReducedWord → C
universalPropertyFunction G f empty = Group.0G G
universalPropertyFunction {_+_ = _+_} G f (prependLetter (ofLetter l) w x) = (f l) + universalPropertyFunction G f w
universalPropertyFunction {_+_ = _+_} G f (prependLetter (ofInv l) w x) = (Group.inverse G (f l)) + universalPropertyFunction G f w
private
prepLemma : {c d : _} {C : Set c} {S : Setoid {c} {d} C} {_+_ : C → C → C} → (G : Group S _+_) → (f : A → C) → (x : ReducedWord) (l : _) → Setoid._∼_ S (universalPropertyFunction G f (prepend x (ofLetter l))) ((f l) + universalPropertyFunction G f x)
prepLemma {S = S} G f empty l = reflexive
where
open Setoid S
open Equivalence eq
prepLemma {S = S} G f (prependLetter (ofLetter x) w pr) l = reflexive
where
open Setoid S
open Equivalence eq
prepLemma {S = S} G f (prependLetter (ofInv x) w pr) l with decA l x
... | inl refl = transitive (symmetric identLeft) (transitive (+WellDefined (symmetric invRight) reflexive) (symmetric +Associative))
where
open Group G
open Setoid S
open Equivalence eq
... | inr l!=x = reflexive
where
open Setoid S
open Equivalence eq
prepLemma' : {c d : _} {C : Set c} {S : Setoid {c} {d} C} {_+_ : C → C → C} → (G : Group S _+_) → (f : A → C) → (x : ReducedWord) (l : _) → Setoid._∼_ S (universalPropertyFunction G f (prepend x (ofInv l))) (Group.inverse G (f l) + universalPropertyFunction G f x)
prepLemma' {S = S} G f empty l = reflexive
where
open Setoid S
open Equivalence eq
prepLemma' {S = S} G f (prependLetter (ofLetter x) w pr) l with decA l x
... | inl refl = symmetric (transitive +Associative (transitive (+WellDefined invLeft reflexive) identLeft))
where
open Group G
open Setoid S
open Equivalence eq
... | inr l!=x = reflexive
where
open Setoid S
open Equivalence eq
prepLemma' {S = S} G f (prependLetter (ofInv x) w pr) l = reflexive
where
open Setoid S
open Equivalence eq
homLemma : {c d : _} {C : Set c} {S : Setoid {c} {d} C} {_+_ : C → C → C} → (G : Group S _+_) → (f : A → C) → (x y : ReducedWord) → Setoid._∼_ S (universalPropertyFunction G f (x +W y)) (universalPropertyFunction G f x + universalPropertyFunction G f y)
homLemma {S = S} G f empty y = symmetric identLeft
where
open Setoid S
open Equivalence eq
open Group G
homLemma {S = S} G f (prependLetter (ofLetter l) x pr) y = transitive (transitive (prepLemma G f (x +W y) l) (+WellDefined reflexive (homLemma G f x y))) (+Associative {f l})
where
open Setoid S
open Equivalence eq
open Group G
homLemma {S = S} G f (prependLetter (ofInv l) x pr) y = transitive (transitive (prepLemma' G f (x +W y) l) (+WellDefined reflexive (homLemma G f x y))) +Associative
where
open Setoid S
open Equivalence eq
open Group G
universalPropertyHom : {c d : _} {C : Set c} {S : Setoid {c} {d} C} {_+_ : C → C → C} (G : Group S _+_) → (f : A → C) → GroupHom freeGroup G (universalPropertyFunction G f)
GroupHom.groupHom (universalPropertyHom {S = S} G f) {x} {y} = homLemma G f x y
GroupHom.wellDefined (universalPropertyHom {S = S} G f) refl = Equivalence.reflexive (Setoid.eq S)
freeEmbedding : A → ReducedWord
freeEmbedding a = prependLetter (ofLetter a) empty (wordEmpty refl)
freeEmbeddingInjective : {a b : A} → freeEmbedding a ≡ freeEmbedding b → a ≡ b
freeEmbeddingInjective {a} {b} pr = ofLetterInjective (prependLetterInjective' pr)
universalPropertyDiagram : {c d : _} {C : Set c} {S : Setoid {c} {d} C} → {_+_ : C → C → C} → (G : Group S _+_) → (f : A → C) → (x : A) → Setoid._∼_ S (f x) (universalPropertyFunction G f (freeEmbedding x))
universalPropertyDiagram {S = S} G f x = symmetric (Group.identRight G)
where
open Setoid S
open Equivalence eq
universalPropertyUniqueness : {c d : _} {C : Set c} {S : Setoid {c} {d} C} → {_+_ : C → C → C} → (G : Group S _+_) → (f : A → C) → {f' : ReducedWord → C} → (GroupHom freeGroup G f') → ((x : A) → Setoid._∼_ S (f x) (f' (freeEmbedding x))) → (x : ReducedWord) → Setoid._∼_ S (f' x) (universalPropertyFunction G f x)
universalPropertyUniqueness {S = S} G f {f'} f'IsHom commutes empty = imageOfIdentityIsIdentity f'IsHom
universalPropertyUniqueness {S = S} G f {f'} f'IsHom commutes (prependLetter (ofLetter a) w pr) = transitive (transitive (GroupHom.wellDefined f'IsHom (equalityCommutative (prependValid w a pr))) (GroupHom.groupHom f'IsHom)) (+WellDefined (symmetric (commutes a)) (universalPropertyUniqueness G f f'IsHom commutes w))
where
open Setoid S
open Equivalence eq
open Group G
universalPropertyUniqueness {S = S} G f {f'} f'IsHom commutes (prependLetter (ofInv a) w pr) = transitive (transitive (GroupHom.wellDefined f'IsHom (equalityCommutative (prependValid' w a pr))) (transitive (GroupHom.groupHom f'IsHom) (+WellDefined (homRespectsInverse f'IsHom) reflexive))) (+WellDefined (symmetric (inverseWellDefined G (commutes a))) (universalPropertyUniqueness G f f'IsHom commutes w))
where
open Setoid S
open Equivalence eq
open Group G
|
{
"alphanum_fraction": 0.6682692308,
"avg_line_length": 52,
"ext": "agda",
"hexsha": "85dd12f55a4464eb841c4dbf80fec2eed63c1a37",
"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/FreeGroup/UniversalProperty.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/FreeGroup/UniversalProperty.agda",
"max_line_length": 405,
"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/FreeGroup/UniversalProperty.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": 1907,
"size": 5824
}
|
{-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
open import Categories.Object.BinaryProducts
module Categories.Object.BinaryProducts.N-ary {o ℓ e}
(C : Category o ℓ e)
(BP : BinaryProducts C)
where
open Category C
open BinaryProducts BP
open Equiv
import Categories.Object.Product
open Categories.Object.Product C
open import Data.Nat using (ℕ; zero; suc)
open import Data.Vec
open import Data.Product.N-ary hiding ([])
Prod : {n : ℕ} → Vec Obj (suc n) → Obj
Prod { zero} (A ∷ []) = A
Prod {suc n} (A ∷ As) = A × Prod {n} As
πˡ : {n m : ℕ}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ Prod (As ++ Bs) ⇒ Prod As
πˡ { zero} (A ∷ []) Bs = π₁
πˡ {suc n} (A ∷ As) Bs = ⟨ π₁ , πˡ {n} As Bs ∘ π₂ ⟩
πʳ : {n m : ℕ}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ Prod (As ++ Bs) ⇒ Prod Bs
πʳ { zero} (A ∷ []) Bs = π₂
πʳ {suc n} (A ∷ As) Bs = πʳ {n} As Bs ∘ π₂
glue : {n m : ℕ}{X : Obj}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ (f : X ⇒ Prod As)
→ (g : X ⇒ Prod Bs)
→ X ⇒ Prod (As ++ Bs)
glue { zero}{m} (A ∷ []) Bs f g = ⟨ f , g ⟩
glue {suc n}{m} (A ∷ As) Bs f g = ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
open HomReasoning
.commuteˡ : {n m : ℕ}{X : Obj}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ {f : X ⇒ Prod As}
→ {g : X ⇒ Prod Bs}
→ πˡ As Bs ∘ glue As Bs f g ≡ f
commuteˡ { zero} (A ∷ []) Bs {f}{g} = commute₁
commuteˡ {suc n} (A ∷ As) Bs {f}{g} =
begin
⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
↓⟨ ⟨⟩∘ ⟩
⟨ π₁ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
, (πˡ As Bs ∘ π₂) ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
⟩
↓⟨ ⟨⟩-cong₂ commute₁ assoc ⟩
⟨ π₁ ∘ f
, πˡ As Bs ∘ π₂ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
⟩
↓⟨ ⟨⟩-congʳ (refl ⟩∘⟨ commute₂) ⟩
⟨ π₁ ∘ f , πˡ As Bs ∘ glue As Bs (π₂ ∘ f) g ⟩
↓⟨ ⟨⟩-congʳ (commuteˡ As Bs) ⟩
⟨ π₁ ∘ f , π₂ ∘ f ⟩
↓⟨ g-η ⟩
f
∎
.commuteʳ : {n m : ℕ}{X : Obj}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ {f : X ⇒ Prod As}
→ {g : X ⇒ Prod Bs}
→ πʳ As Bs ∘ glue As Bs f g ≡ g
commuteʳ { zero} (A ∷ []) Bs {f}{g} = commute₂
commuteʳ {suc n} (A ∷ As) Bs {f}{g} =
begin
(πʳ As Bs ∘ π₂) ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
↓⟨ assoc ⟩
πʳ As Bs ∘ π₂ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
↓⟨ refl ⟩∘⟨ commute₂ ⟩
πʳ As Bs ∘ glue As Bs (π₂ ∘ f) g
↓⟨ commuteʳ As Bs ⟩
g
∎
.N-universal : {n m : ℕ}{X : Obj}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ {f : X ⇒ Prod As}
→ {g : X ⇒ Prod Bs}
→ {h : X ⇒ Prod (As ++ Bs) }
→ πˡ As Bs ∘ h ≡ f
→ πʳ As Bs ∘ h ≡ g
→ glue As Bs f g ≡ h
N-universal { zero} (A ∷ []) Bs {f}{g}{h} h-commuteˡ h-commuteʳ = universal h-commuteˡ h-commuteʳ
N-universal {suc n} (A ∷ As) Bs {f}{g}{h} h-commuteˡ h-commuteʳ =
begin
⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩
↓⟨ ⟨⟩-congʳ (N-universal As Bs π₂∘h-commuteˡ π₂∘h-commuteʳ) ⟩
⟨ π₁ ∘ f , π₂ ∘ h ⟩
↑⟨ ⟨⟩-congˡ π₁∘h-commuteˡ ⟩
⟨ π₁ ∘ h , π₂ ∘ h ⟩
↓⟨ g-η ⟩
h
∎
where
-- h-commuteˡ : ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ h ≡ f
-- h-commuteʳ : (πʳ As Bs ∘ π₂) ∘ h ≡ g
π₁∘h-commuteˡ : π₁ ∘ h ≡ π₁ ∘ f
π₁∘h-commuteˡ =
begin
π₁ ∘ h
↑⟨ commute₁ ⟩∘⟨ refl ⟩
(π₁ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩) ∘ h
↓⟨ assoc ⟩
π₁ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ h
↓⟨ refl ⟩∘⟨ h-commuteˡ ⟩
π₁ ∘ f
∎
π₂∘h-commuteˡ : πˡ As Bs ∘ π₂ ∘ h ≡ π₂ ∘ f
π₂∘h-commuteˡ =
begin
πˡ As Bs ∘ π₂ ∘ h
↑⟨ assoc ⟩
(πˡ As Bs ∘ π₂) ∘ h
↑⟨ commute₂ ⟩∘⟨ refl ⟩
(π₂ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩) ∘ h
↓⟨ assoc ⟩
π₂ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ h
↓⟨ refl ⟩∘⟨ h-commuteˡ ⟩
π₂ ∘ f
∎
π₂∘h-commuteʳ : πʳ As Bs ∘ π₂ ∘ h ≡ g
π₂∘h-commuteʳ = trans (sym assoc) h-commuteʳ
isProduct : {n m : ℕ}
→ (As : Vec Obj (suc n))
→ (Bs : Vec Obj (suc m))
→ Product (Prod As) (Prod Bs)
isProduct {n}{m} As Bs = record
{ A×B = Prod (As ++ Bs)
; π₁ = πˡ As Bs
; π₂ = πʳ As Bs
; ⟨_,_⟩ = glue As Bs
; commute₁ = commuteˡ As Bs
; commute₂ = commuteʳ As Bs
; universal = N-universal As Bs
}
|
{
"alphanum_fraction": 0.472061657,
"avg_line_length": 25.95,
"ext": "agda",
"hexsha": "ad1536d6068466fd2e07f1ba9fd74a31365ce2d0",
"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": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Object/BinaryProducts/N-ary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"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": "p-pavel/categories",
"max_issues_repo_path": "Categories/Object/BinaryProducts/N-ary.agda",
"max_line_length": 97,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "p-pavel/categories",
"max_stars_repo_path": "Categories/Object/BinaryProducts/N-ary.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-29T21:51:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-12-29T21:51:57.000Z",
"num_tokens": 2063,
"size": 4152
}
|
{-# OPTIONS --cubical --no-import-sorts #-}
module Cubical.Codata.Stream where
open import Cubical.Codata.Stream.Base public
open import Cubical.Codata.Stream.Properties public
|
{
"alphanum_fraction": 0.7877094972,
"avg_line_length": 25.5714285714,
"ext": "agda",
"hexsha": "db94ecfa43b8e88e5a08a2d7878cfde7b16e9b19",
"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/Codata/Stream.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/Codata/Stream.agda",
"max_line_length": 51,
"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/Codata/Stream.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 40,
"size": 179
}
|
module Structure.Operator.Ring.Proofs where
import Data.Tuple as Tuple
open import Functional
open import Logic.IntroInstances
open import Logic.Propositional
import Lvl
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Operator.Properties
open import Structure.Operator.Ring
open import Structure.Operator
open import Structure.Operator.Proofs
open import Structure.Relator.Properties
open import Structure.Setoid
open import Syntax.Implication
open import Syntax.Transitivity
open import Type.Properties.MereProposition
open import Type.Properties.Singleton
open import Type.Properties.Singleton.Proofs
open import Type
private variable ℓ ℓₑ : Lvl.Level
private variable T : Type{ℓ}
private variable _+_ _⋅_ : T → T → T
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ ⦃ rng : Rng{T = T}(_+_)(_⋅_) ⦄ where
open Rng(rng)
instance
[+]-cancellationₗ : Cancellationₗ(_+_)
[+]-cancellationₗ = One.cancellationₗ-by-associativity-inverse
instance
[+]-cancellationᵣ : Cancellationᵣ(_+_)
[+]-cancellationᵣ = One.cancellationᵣ-by-associativity-inverse
instance
[⋅]-absorberₗ : Absorberₗ(_⋅_)(𝟎)
Absorberₗ.proof [⋅]-absorberₗ {x} = One.zero-when-redundant-addition $
𝟎 ⋅ x 🝖-[ congruence₂ₗ(_⋅_)(x) (identityₗ(_+_)(𝟎)) ]-sym
(𝟎 + 𝟎) ⋅ x 🝖-[ distributivityᵣ(_⋅_)(_+_) ]
(𝟎 ⋅ x) + (𝟎 ⋅ x) 🝖-end
instance
[⋅]-absorberᵣ : Absorberᵣ(_⋅_)(𝟎)
Absorberᵣ.proof [⋅]-absorberᵣ {x} = One.zero-when-redundant-addition $
x ⋅ 𝟎 🝖-[ congruence₂ᵣ(_⋅_)(x) (identityₗ(_+_)(𝟎)) ]-sym
x ⋅ (𝟎 + 𝟎) 🝖-[ distributivityₗ(_⋅_)(_+_) ]
(x ⋅ 𝟎) + (x ⋅ 𝟎) 🝖-end
-- TODO: Stuff provable in groups
[−]-binaryOperator : BinaryOperator(_−_)
BinaryOperator.congruence [−]-binaryOperator {x₁}{y₁}{x₂}{y₂} xy1 xy2 =
(x₁ − x₂) 🝖[ _≡_ ]-[]
(x₁ + (− x₂)) 🝖[ _≡_ ]-[ congruence₂(_+_) xy1 (congruence₁(−_) xy2) ]
(y₁ + (− y₂)) 🝖[ _≡_ ]-[]
(y₁ − y₂) 🝖-end
postulate [⋅][−]-distributivityₗ : Distributivityₗ(_⋅_)(_−_)
postulate [⋅][−]-distributivityᵣ : Distributivityᵣ(_⋅_)(_−_)
instance
[−]-involution : Involution(−_)
[−]-involution = intro One.double-inverse
[+]-negation-distribution : ∀{x y} → (−(x + y) ≡ (− x) + (− y))
[+]-negation-distribution = One.inverse-distribution 🝖 commutativity(_+_)
[−]-negation-distribution : ∀{x y} → (−(x − y) ≡ y − x)
[−]-negation-distribution = One.inverse-distribution 🝖 congruence₂ₗ(_−_) ⦃ [−]-binaryOperator ⦄ (_) (involution(−_))
-- TODO: See abs-of-negation for a similiar proof
postulate zero-when-equal-negation : ∀{x} → (− x ≡ x) → (x ≡ 𝟎)
instance
[+]-inversePropₗ : InversePropertyₗ(_+_)(−_)
[+]-inversePropₗ = One.inverse-propertyₗ-by-groupₗ
instance
[+]-inversePropᵣ : InversePropertyᵣ(_+_)(−_)
[+]-inversePropᵣ = One.inverse-propertyᵣ-by-groupᵣ
[+][−]-inverseOperᵣ : InverseOperatorᵣ(_+_)(_−_)
[+][−]-inverseOperᵣ = One.standard-inverse-inverse-operatorᵣ-by-inverse-propᵣ ⦃ inverPropᵣ = [+]-inversePropᵣ ⦄
[−][+]-inverseOperᵣ : InverseOperatorᵣ(_−_)(_+_)
[−][+]-inverseOperᵣ = One.standard-inverse-operatorᵣ-by-involuting-inverse-propᵣ ⦃ inverPropᵣ = [+]-inversePropᵣ ⦄
-- TODO: Defined set subset of natural numbers and integers by using summation ∑. That is: (x ∈ ℕ) = ∃{Obj = ℕ}(n ↦ ∑(0 ‥ n) (const 𝟏))
[−]-of-𝟎 : ((− 𝟎) ≡ 𝟎)
[−]-of-𝟎 =
− 𝟎 🝖-[ symmetry(_≡_) (identityₗ(_+_)(𝟎)) ]
𝟎 + (− 𝟎) 🝖-[ inverseFunctionᵣ(_+_)(−_) ]
𝟎 🝖-end
[−]-is-𝟎 : ∀{x} → ((− x) ≡ 𝟎) ↔ (x ≡ 𝟎)
[−]-is-𝟎 = [↔]-intro (p ↦ congruence₁(−_) p 🝖 [−]-of-𝟎) (p ↦ symmetry(_≡_) (involution(−_)) 🝖 congruence₁(−_) p 🝖 [−]-of-𝟎)
[−]-difference-is-𝟎 : ∀{x y} → ((x − y) ≡ 𝟎) ↔ (x ≡ y)
[−]-difference-is-𝟎 {x}{y} = [↔]-intro l r where
l =
(x ≡ y ) ⇒-[ congruence₂ᵣ(_−_) ⦃ [−]-binaryOperator ⦄ (x) ]
(x − x ≡ x − y) ⇒-[ symmetry(_≡_) ]
(x − y ≡ x − x) ⇒-[ _🝖 inverseFunctionᵣ(_+_)(−_) ]
(x − y ≡ 𝟎 ) ⇒-end
r =
(x − y ≡ 𝟎 ) ⇒-[]
(x + (− y) ≡ 𝟎 ) ⇒-[ congruence₂ₗ(_+_)(y) ]
((x + (− y)) + y ≡ 𝟎 + y) ⇒-[ symmetry(_≡_) (associativity(_+_)) 🝖_ ]
(x + ((− y) + y) ≡ 𝟎 + y) ⇒-[ congruence₂ᵣ(_+_)(x) (symmetry(_≡_) (inverseFunctionₗ(_+_)(−_))) 🝖_ ]
(x + 𝟎 ≡ 𝟎 + y) ⇒-[ (\p → symmetry(_≡_) (identityᵣ(_+_)(𝟎)) 🝖 p 🝖 identityₗ(_+_)(𝟎)) ]
(x ≡ y ) ⇒-end
module _ ⦃ unity : Unity(_+_)(_⋅_) ⦄ where
open import Type.Properties.MereProposition
open import Type.Properties.Singleton
open import Type.Properties.Singleton.Proofs
open Unity(unity)
singleton-when-identities-equal : (𝟎 ≡ 𝟏) ↔ IsUnit(T)
singleton-when-identities-equal = [↔]-intro l r where
l : (𝟎 ≡ 𝟏) ← IsUnit(T)
l p = uniqueness(_) ⦃ inst = unit-is-prop ⦃ proof = p ⦄ ⦄
r : (𝟎 ≡ 𝟏) → IsUnit(T)
IsUnit.unit (r oi) = 𝟎
IsUnit.uniqueness (r oi) {x} =
x 🝖[ _≡_ ]-[ identityᵣ(_⋅_)(𝟏) ]-sym
x ⋅ 𝟏 🝖[ _≡_ ]-[ congruence₂ᵣ(_⋅_)(x) oi ]-sym
x ⋅ 𝟎 🝖[ _≡_ ]-[ absorberᵣ(_⋅_)(𝟎) ]
𝟎 🝖-end
[⋅]ₗ-of-[−1] : ∀{x} → ((− 𝟏) ⋅ x ≡ − x)
[⋅]ₗ-of-[−1] {x} = One.unique-inverseᵣ-by-id $
x + ((− 𝟏) ⋅ x) 🝖-[ congruence₂ₗ(_+_)(_) (identityₗ(_⋅_)(𝟏)) ]-sym
(𝟏 ⋅ x) + ((− 𝟏) ⋅ x) 🝖-[ distributivityᵣ(_⋅_)(_+_) ]-sym
(𝟏 + (− 𝟏)) ⋅ x 🝖-[ congruence₂ₗ(_⋅_)(x) (inverseFunctionᵣ(_+_)(−_)) ]
𝟎 ⋅ x 🝖-[ absorberₗ(_⋅_)(𝟎) ]
𝟎 🝖-end
[⋅]ᵣ-of-[−1] : ∀{x} → (x ⋅ (− 𝟏) ≡ − x)
[⋅]ᵣ-of-[−1] {x} = One.unique-inverseₗ-by-id $
(x ⋅ (− 𝟏)) + x 🝖-[ congruence₂ᵣ(_+_)(_) (identityᵣ(_⋅_)(𝟏)) ]-sym
(x ⋅ (− 𝟏)) + (x ⋅ 𝟏) 🝖-[ distributivityₗ(_⋅_)(_+_) ]-sym
x ⋅ ((− 𝟏) + 𝟏) 🝖-[ congruence₂ᵣ(_⋅_)(x) (inverseFunctionₗ(_+_)(−_)) ]
x ⋅ 𝟎 🝖-[ absorberᵣ(_⋅_)(𝟎) ]
𝟎 🝖-end
[⋅]ₗ-of-[−] : ∀{x y} → ((− x) ⋅ y ≡ −(x ⋅ y))
[⋅]ₗ-of-[−] {x}{y} =
((− x) ⋅ y) 🝖-[ congruence₂ₗ(_⋅_)(y) [⋅]ₗ-of-[−1] ]-sym
(((− 𝟏) ⋅ x) ⋅ y) 🝖-[ associativity(_⋅_) ]
((− 𝟏) ⋅ (x ⋅ y)) 🝖-[ [⋅]ₗ-of-[−1] ]
(−(x ⋅ y)) 🝖-end
[⋅]ᵣ-of-[−] : ∀{x y} → (x ⋅ (− y) ≡ −(x ⋅ y))
[⋅]ᵣ-of-[−] {x}{y} =
(x ⋅ (− y)) 🝖-[ congruence₂ᵣ(_⋅_)(x) [⋅]ᵣ-of-[−1] ]-sym
(x ⋅ (y ⋅ (− 𝟏))) 🝖-[ associativity(_⋅_) ]-sym
((x ⋅ y) ⋅ (− 𝟏)) 🝖-[ [⋅]ᵣ-of-[−1] ]
(−(x ⋅ y)) 🝖-end
[⋅]-of-[−] : ∀{x y} → ((− x) ⋅ (− y) ≡ x ⋅ y)
[⋅]-of-[−] {x}{y} =
((− x) ⋅ (− y)) 🝖[ _≡_ ]-[ [⋅]ᵣ-of-[−] ]
−((− x) ⋅ y) 🝖[ _≡_ ]-[ congruence₁(−_) [⋅]ₗ-of-[−] ]
−(−(x ⋅ y)) 🝖[ _≡_ ]-[ involution(−_) ]
(x ⋅ y) 🝖-end
|
{
"alphanum_fraction": 0.5132769619,
"avg_line_length": 38.9653179191,
"ext": "agda",
"hexsha": "78bf3afad3f073509850a27261b6d4b4a17bf25d",
"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": "Structure/Operator/Ring/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": "Structure/Operator/Ring/Proofs.agda",
"max_line_length": 137,
"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": "Structure/Operator/Ring/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": 3269,
"size": 6741
}
|
module Lambda where
open import Data.Bool using (true; false)
open import Data.Nat renaming (_≟_ to _≟N_)
import Data.Stream as S
open import Data.Vec using ([]; _∷_)
open import Relation.Binary.PropositionalEquality
open import Check
open import Eval
open import Operations.Combinatorial
open import Operations.Stateful
open import Types
open import Utils
ex₀ : S.take 5 ([] ⟦ alternator bitO ⟧) ≡ false ∷ true ∷ false ∷ true ∷ false ∷ []
ex₀ = refl
ex₁ : S.take 5 ([] ⟦ constant bitI ⟧) ≡ true ∷ true ∷ true ∷ true ∷ true ∷ []
ex₁ = refl
|
{
"alphanum_fraction": 0.6927175844,
"avg_line_length": 26.8095238095,
"ext": "agda",
"hexsha": "2cd7b13ca9130b9bb9288c55981955189461ec39",
"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": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bens/hwlc",
"max_forks_repo_path": "Lambda.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"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": "bens/hwlc",
"max_issues_repo_path": "Lambda.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bens/hwlc",
"max_stars_repo_path": "Lambda.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 172,
"size": 563
}
|
-- Andreas, 2012-06-05 let for record patterns
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.term.let.pattern:100 #-}
-- {-# OPTIONS -v tc.lhs.top:100 #-}
module LetPair where
import Common.Level
-- open import Common.Equality
data _×_ (A B : Set) : Set where
_,_ : (fst : A)(snd : B) → A × B
swap : {A B : Set} → A × B → B × A
swap p =
let (a , b) = p -- works only for record patterns
in (b , a)
|
{
"alphanum_fraction": 0.5795724466,
"avg_line_length": 22.1578947368,
"ext": "agda",
"hexsha": "2637d402ae3eb5d14605911e8dd46a9a408e582c",
"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/LetPair.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/LetPair.agda",
"max_line_length": 52,
"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/LetPair.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": 144,
"size": 421
}
|
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Data.Unit where
open import Light.Level using (Level ; Setω)
record Dependencies : Setω where
record Library (dependencies : Dependencies) : Setω where
field
ℓ : Level
Unit : Set ℓ
unit : Unit
open Library ⦃ ... ⦄ public
|
{
"alphanum_fraction": 0.6494565217,
"avg_line_length": 24.5333333333,
"ext": "agda",
"hexsha": "da7d87014d28273bf9f8dd196436061a15d43d49",
"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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Library/Data/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Library/Data/Unit.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Library/Data/Unit.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 87,
"size": 368
}
|
{-# OPTIONS --without-K #-}
module RepresPerm where
open import Enumeration using (Enum)
open import Equiv
using (_≃_; id≃; sym≃; trans≃; mkqinv; module qinv; _⋆_; path⊎)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
open import Data.Nat using (ℕ; suc)
open import Data.Fin using (Fin; zero)
open import Data.Product using (_,_)
open import FinEquiv
open import Data.Unit using (⊤)
open import Data.Sum using (_⊎_)
open import LeftCancellation
-- A Representable Permutation consists of
-- 1. an Enumeration of A
-- 2. an Enumeration of B
-- 3. an isomorphism between A and B
record RPerm (A : Set) (n : ℕ) (B : Set) (m : ℕ) : Set where
constructor rp
field
#A : Enum A n
#B : Enum B m
iso : A ≃ B
open RPerm
-- first theorem about these: same size!
thm1 : ∀ {n m} {A B} → (X : RPerm A n B m) → n ≡ m
thm1 {0} {0 } (rp _ _ _ ) = refl
thm1 {0} {suc m} (rp (fA , isoA) (fB , mkqinv g α β) (f , iso)) with fA (I.g (g zero))
where module I = qinv iso
... | ()
thm1 {suc n} {0} (rp (fA , isoA) B≃Fm (f , iso)) with B≃Fm ⋆ f (IA.g zero)
where module IA = qinv isoA
... | ()
thm1 {suc n} {suc m} {A} {B} (rp A≃Fsn B≃Fsm A≃B) =
cong suc (thm1 {n} {m} {Fin n} {Fin m} (rp id≃ id≃ Fn≃Fm))
where
Fsn≃Fsm : Fin (suc n) ≃ Fin (suc m)
Fsn≃Fsm = trans≃ (trans≃ (sym≃ A≃Fsn) A≃B) B≃Fsm
1+n≃1+m : (Fin 1 ⊎ Fin n) ≃ (Fin 1 ⊎ Fin m)
1+n≃1+m = trans≃ (trans≃ (Plus.fwd-iso {suc 0} {n}) Fsn≃Fsm)
(sym≃ (Plus.fwd-iso {suc 0} {m}))
⊤⊎n≃⊤⊎m : (⊤ ⊎ Fin n) ≃ (⊤ ⊎ Fin m)
⊤⊎n≃⊤⊎m = trans≃ (trans≃ (path⊎ (sym≃ Fin1≃⊤) id≃) 1+n≃1+m)
(path⊎ Fin1≃⊤ id≃)
Fn≃Fm = left-cancel-⊤ ⊤⊎n≃⊤⊎m
|
{
"alphanum_fraction": 0.5358532518,
"avg_line_length": 34.5961538462,
"ext": "agda",
"hexsha": "bef8164a3f77508e35e476463ec7cab2f1f53c4d",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/RepresPerm.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/RepresPerm.agda",
"max_line_length": 87,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/RepresPerm.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 774,
"size": 1799
}
|
open import Data.Product using ( ∃ ; _×_ ; _,_ ; proj₁ ; proj₂ )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.ABox using ( ABox )
open import Web.Semantic.DL.ABox.Interp using ( Interp ; _*_ )
open import Web.Semantic.DL.ABox.Interp.Morphism using
( _≲_ ; ≲-trans ; _**_ ; _≋_ )
open import Web.Semantic.DL.KB using ( KB ; _,_ ; tbox )
open import Web.Semantic.DL.KB.Model using ( _⊨_ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( _,_ )
open import Web.Semantic.Util using ( _⊕_⊕_ ; inode ; enode )
module Web.Semantic.DL.Integrity {Σ : Signature} {X V Y : Set} where
-- A variant of the notion of OWL integrity in:
-- Boris Motik, Ian Horrocks, and Ulrike Sattler. Bridging the gap between OWL and
-- relational databases. In Proc. Conf. World Wide Web (WWW2007), pp 807–816, 2007.
-- They propose defining that an integrity constraint S (given as a T-Box) is valid
-- for a knowlege base K whenever S is valid in every minimal Herbrand model.
-- We strengthen this requirement to say that there is a minimal model of K,
-- which validtes S.
infixr 4 _>>_ _,_
infix 2 _⊕_⊨_
-- J ∈ Initial I K whenever J is the initial extension of I
-- satisfying K, that is there is I≲J s.t. I ⊨ K
-- and for any other such I≲K, there is a unique
-- J≲K which commutes with I≲J and I≲K.
_>>_ : ∀ {I : Interp Σ X} {J K : Interp Σ (X ⊕ V ⊕ Y)} →
(I ≲ inode * J) → (J ≲ K) → (I ≲ inode * K)
I≲J >> J≲K = ≲-trans I≲J (inode ** J≲K)
Unique : ∀ (I : Interp Σ X) → (J K : Interp Σ (X ⊕ V ⊕ Y)) →
(I ≲ inode * J) → (I ≲ inode * K) → Set
Unique I J K I≲J I≲K = ∀ (J≲₁K J≲₂K : J ≲ K) →
(I≲K ≋ I≲J >> J≲₁K) → (I≲K ≋ I≲J >> J≲₂K) → (J≲₁K ≋ J≲₂K)
data Mediated (I : Interp Σ X) (J K : Interp Σ (X ⊕ V ⊕ Y))
(I≲J : I ≲ inode * J) (I≲K : I ≲ inode * K) : Set where
_,_ : (J≲K : J ≲ K) → (I≲K ≋ I≲J >> J≲K) × (Unique I J K I≲J I≲K)
→ Mediated I J K I≲J I≲K
med-≲ : ∀ {I} {J K : Interp Σ (X ⊕ V ⊕ Y)} {I≲J I≲K} →
(Mediated I J K I≲J I≲K) → (J ≲ K)
med-≲ (J≲K , I≲K≋I≲J≲K , J≲K-uniq) = J≲K
med-≋ : ∀ {I} {J K : Interp Σ (X ⊕ V ⊕ Y)} {I≲J I≲K} →
(m : Mediated I J K I≲J I≲K) → (I≲K ≋ I≲J >> med-≲ m)
med-≋ (J≲K , I≲K≋I≲J≲K , J≲K-uniq) = I≲K≋I≲J≲K
med-uniq : ∀ {I} {J K : Interp Σ (X ⊕ V ⊕ Y)} {I≲J I≲K} →
(Mediated I J K I≲J I≲K) → Unique I J K I≲J I≲K
med-uniq (J≲K , I≲K≋I≲J≲K , J≲K-uniq) = J≲K-uniq
Mediator : ∀ (I : Interp Σ X) → (J : Interp Σ (X ⊕ V ⊕ Y)) →
(I ≲ inode * J) → (KB Σ (X ⊕ V ⊕ Y)) → Set₁
Mediator I J I≲J KB =
∀ K (I≲K : I ≲ inode * K) → (K ⊨ KB) → Mediated I J K I≲J I≲K
data Initial I KB (J : Interp Σ (X ⊕ V ⊕ Y)) : Set₁ where
_,_ : ∀ (I≲J : I ≲ inode * J) → (J ⊨ KB) × (Mediator I J I≲J KB) →
(J ∈ Initial I KB)
init-≲ : ∀ {I KB} {J : Interp Σ (X ⊕ V ⊕ Y)} →
(J ∈ Initial I KB) → (I ≲ inode * J)
init-≲ (I≲J , J⊨KB , J-med) = I≲J
init-⊨ : ∀ {I KB} {J : Interp Σ (X ⊕ V ⊕ Y)} →
(J ∈ Initial I KB) → (J ⊨ KB)
init-⊨ (I≲J , J⊨KB , J-med) = J⊨KB
init-med : ∀ {I KB} {J : Interp Σ (X ⊕ V ⊕ Y)} →
(J-init : J ∈ Initial I KB) → Mediator I J (init-≲ J-init) KB
init-med (I≲J , J⊨KB , J-med) = J-med
-- I ⊕ KB₁ ⊨ KB₂ whenever the initial extension of I satisfying
-- KB₁ exists, and has exports satisfying KB₂.
data _⊕_⊨_ I (KB₁ : KB Σ (X ⊕ V ⊕ Y)) KB₂ : Set₁ where
_,_ : ∀ J → ((J ∈ Initial I KB₁) × (enode * J ⊨ KB₂)) → (I ⊕ KB₁ ⊨ KB₂)
extension : ∀ {I KB₁ KB₂} → (I ⊕ KB₁ ⊨ KB₂) → (Interp Σ (X ⊕ V ⊕ Y))
extension (J , J-init , J⊨KB₂) = J
ext-init : ∀ {I} {KB₁ : KB Σ (X ⊕ V ⊕ Y)} {KB₂} →
(I⊕KB₁⊨KB₂ : I ⊕ KB₁ ⊨ KB₂) → (extension I⊕KB₁⊨KB₂ ∈ Initial I KB₁)
ext-init (J , J-init , J⊨KB₂) = J-init
ext-⊨ : ∀ {I} {KB₁ : KB Σ (X ⊕ V ⊕ Y)} {KB₂} →
(I⊕KB₁⊨KB₂ : I ⊕ KB₁ ⊨ KB₂) → (enode * (extension I⊕KB₁⊨KB₂) ⊨ KB₂)
ext-⊨ (J , J-init , J⊨KB₂) = J⊨KB₂
ext✓ : ∀ {I S T} {F : ABox Σ (X ⊕ V ⊕ Y)} {B} →
(I⊕SF⊨TB : I ⊕ S , F ⊨ T , B) →
(enode * (extension I⊕SF⊨TB) ⊨ (S , T) , B)
ext✓ I⊕SF⊨TB =
( ( proj₁ (init-⊨ (ext-init I⊕SF⊨TB))
, proj₁ (ext-⊨ I⊕SF⊨TB) )
, proj₂ (ext-⊨ I⊕SF⊨TB) )
|
{
"alphanum_fraction": 0.5424189958,
"avg_line_length": 38.875,
"ext": "agda",
"hexsha": "1eb4ad627a40f5e15aacbe1dac761ae6ad9e581e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Integrity.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Integrity.agda",
"max_line_length": 85,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Integrity.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 2027,
"size": 4043
}
|
module Sort where
open import Sec4
import Sec2
postulate _≤_ : {A : Set} → A → A → Prop
postulate tot-list : {A : Set} → (a b : A) → (a ≤ b) ∨ (b ≤ a)
postulate trans-list : {A : Set} → (a b c : A) → (a ≤ b) → (b ≤ c) → (a ≤ c)
-- XXX: Definition of a list
data List (A : Set) : Set where
Nil : List A
_∷_ : A → List A → List A
-- XXX: definition of an ordered list
all-ordered-list : {A : Set} → (a : A)
→ (l : List A)
→ Prop
all-ordered-list a Nil = ⊤
all-ordered-list a (x ∷ l) = (a ≤ x) ∧ all-ordered-list a l
ordered-list : {A : Set} → List A → Prop
ordered-list Nil = ⊤
ordered-list (x ∷ l) = all-ordered-list x l ∧ (ordered-list l)
-- XXX: Inserting elements in the list
insert-list : {A : Set} → (a : A) → (l : List A) → List A
insert-list a Nil = a ∷ Nil
insert-list a (x ∷ l) with (tot-list a x)
insert-list a (x ∷ l) | ora h = a ∷ (x ∷ l)
insert-list a (x ∷ l) | orb h = x ∷ (insert-list a l)
lem1 : {A : Set}
→ (a x : A)
→ (l : List A)
→ (p : all-ordered-list x l)
→ (p1 : a ≤ x)
→ (all-ordered-list a l)
lem1 a x Nil p p1 = ⋆
lem1 a x (x₁ ∷ l) (and x₂ x₃) p1 = and (trans-list a x x₁ p1 x₂) (lem1 a x l x₃ p1)
lem2 : {A : Set} → (x a : A) → (l : List A) → (h : x ≤ a)
→ (p1 : all-ordered-list x l) → (p2 : ordered-list l)
→ (v : ordered-list (insert-list a l))
→ all-ordered-list x (insert-list a l)
lem2 x a Nil h p1 p3 v = and h ⋆
lem2 x a (x₁ ∷ l) h p1 p3 v with (tot-list a x₁)
lem2 x₂ a (x₁ ∷ l) h p1 p3 v | ora x = and h p1
lem2 x₂ a (x₁ ∷ l) h (and x₃ x₄) (and x₅ x₆) (and x₇ x₈) | orb x = and x₃ (lem2 x₂ a l h x₄ x₆ x₈)
thm2 : {A : Set}
→ ∀ (a : A)
→ ∀ (l : List A)
→ (p : ordered-list l)
→ (ordered-list (insert-list a l))
thm2 a Nil p = and ⋆ ⋆
thm2 a (x ∷ l) p with (tot-list a x)
thm2 a (x ∷ l) (and x₁ x₂) | ora h = and (and h (lem1 a x l x₁ h)) (and x₁ x₂)
thm2 a (x ∷ l) (and x₁ x₂) | orb h =
let v = (thm2 a l x₂)
in
and (lem2 x a l h x₁ x₂ v) v
-- XXX: append lists
_++_ : {A : Set} → (l : List A) → (m : List A) → List A
Nil ++ m = m
(x ∷ l) ++ m = x ∷ (l ++ m)
-- XXX: Length of a list
length : {A : Set} → (l : List A) → Sec2.ℕ
length Nil = Sec2.Z
length (x ∷ l) = Sec2.S (length l)
-- XXX: reverse of a list
rev : {A : Set} → (List A) → (List A)
rev Nil = Nil
rev (x ∷ l) = (rev l) ++ (x ∷ Nil)
-- XXX: Theorem on length of lists
thm : {A : Set} → (l : List A) → (m : List A) → ((length l) Sec2.+ (length m) Sec2.≡ length (l ++ m))
thm Nil m = Sec2.refl
thm (x ∷ l) m =
let
xx = thm l m
in
Sec2.cong xx
cong : {A : Set} → (x : A) → (l m : List A) → (l Sec2.≡ m)
→ (x ∷ l) Sec2.≡ (x ∷ m)
cong x l .l Sec2.refl = Sec2.refl
cong2 : {A : Set} → (l m q : List A) → (l Sec2.≡ m)
→ (l ++ q) Sec2.≡ (m ++ q)
cong2 l .l q Sec2.refl = Sec2.refl
++-lem : {A : Set} → (l : List A) → ((l ++ Nil) Sec2.≡ l)
++-lem Nil = Sec2.refl
++-lem (x ∷ l) = cong x (l ++ Nil) l (++-lem l)
assoc : {A : Set} → (l m q : List A)
→ l ++ (m ++ q) Sec2.≡ (l ++ m) ++ q
assoc Nil m q = Sec2.refl
assoc (x ∷ l) m q = cong x (l ++ (m ++ q)) ((l ++ m) ++ q) (assoc l m q)
rev-lem : {A : Set} → ∀ (l m : List A)
→ rev (l ++ m) Sec2.≡ (rev m) ++ (rev l)
rev-lem Nil m rewrite
++-lem (rev m) = Sec2.refl
rev-lem (x ∷ l) m rewrite
assoc (rev m) (rev l) (x ∷ Nil)
= let p = rev-lem l m in
cong2 (rev (l ++ m)) (rev m ++ rev l) (x ∷ Nil) p
-- XXX: Involution of reversal of lists
rev-involute : {A : Set} → (l : List A) → l Sec2.≡ (rev (rev l))
rev-involute Nil = Sec2.refl
rev-involute (x ∷ l) rewrite
rev-lem (rev l) (x ∷ Nil)
= cong x l (rev (rev l)) (rev-involute l)
|
{
"alphanum_fraction": 0.4520614784,
"avg_line_length": 33.8760330579,
"ext": "agda",
"hexsha": "57315dad5c52ba579d6781f472830f0de4153e26",
"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": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "amal029/agda-tutorial-dybjer",
"max_forks_repo_path": "Sort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"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": "amal029/agda-tutorial-dybjer",
"max_issues_repo_path": "Sort.agda",
"max_line_length": 103,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "amal029/agda-tutorial-dybjer",
"max_stars_repo_path": "Sort.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:52:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:52:30.000Z",
"num_tokens": 1659,
"size": 4099
}
|
open import Coinduction using ( ♭ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; cong ; cong₂ )
open import System.IO.Transducers using ( _⇒_ ; inp ; out ; done ; out*' ; _⟫_ ; _⟨&⟩_ ; _⟨&⟩[_]_ ; discard ; π₁ ; π₂ ; ⟦_⟧ ; _≃_ )
open import System.IO.Transducers.Session using ( [] ; _∷_ ; _&_ )
open import System.IO.Transducers.Trace using ( _≤_ ; Trace ; [] ; _∷_ )
open import System.IO.Transducers.Properties.Lemmas using ( cong₃ ; revApp ; out*'-semantics )
open import System.IO.Transducers.Properties.BraidedMonoidal using ( _++_ )
open import System.IO.Transducers.Properties.Category using ( _⟦⟫⟧_ ; ⟫-semantics )
module System.IO.Transducers.Properties.LaxProduct where
open Relation.Binary.PropositionalEquality.≡-Reasoning
_⟦⟨&⟩⟧_ : ∀ {S T U} →
(f : Trace S → Trace T) → (g : Trace S → Trace U) →
(Trace S) → (Trace (T & U))
(f ⟦⟨&⟩⟧ g) as = f as ++ g as
_⟦⟨&⟩[_]⟧_ : ∀ {S T U V} →
(Trace S → Trace T) → (U ≤ V) → (Trace S → Trace U) →
(Trace S → Trace (T & V))
(f ⟦⟨&⟩[ cs ]⟧ g) as = f as ++ (revApp cs (g as))
⟨&⟩[]-semantics : ∀ {S T U V} →
(P : S ⇒ T) → (cs : U ≤ V) → (Q : S ⇒ U) →
(⟦ P ⟨&⟩[ cs ] Q ⟧ ≃ ⟦ P ⟧ ⟦⟨&⟩[ cs ]⟧ ⟦ Q ⟧)
⟨&⟩[]-semantics (inp {T = []} F) cs Q as with ⟦ inp F ⟧ as
⟨&⟩[]-semantics (inp {T = []} F) cs Q as | [] = out*'-semantics cs Q as
⟨&⟩[]-semantics (inp {T = W ∷ Ts} F) cs (inp G) [] = refl
⟨&⟩[]-semantics (inp {T = W ∷ Ts} F) cs (inp G) (a ∷ as) = ⟨&⟩[]-semantics (♭ F a) cs (♭ G a) as
⟨&⟩[]-semantics (inp {T = W ∷ Ts} F) cs (out c Q) as = ⟨&⟩[]-semantics (inp F) (c ∷ cs) Q as
⟨&⟩[]-semantics (inp {T = W ∷ Ts} F) cs done [] = refl
⟨&⟩[]-semantics (inp {T = W ∷ Ts} F) cs done (a ∷ as) = ⟨&⟩[]-semantics (♭ F a) (a ∷ cs) done as
⟨&⟩[]-semantics (out b P) cs Q as = cong (_∷_ b) (⟨&⟩[]-semantics P cs Q as)
⟨&⟩[]-semantics (done {[]}) cs Q [] = out*'-semantics cs Q []
⟨&⟩[]-semantics (done {W ∷ Ts}) cs (inp F) [] = refl
⟨&⟩[]-semantics (done {W ∷ Ts}) cs (inp F) (a ∷ as) = cong (_∷_ a) (⟨&⟩[]-semantics done cs (♭ F a) as)
⟨&⟩[]-semantics (done {W ∷ Ts}) cs (out c Q) as = ⟨&⟩[]-semantics done (c ∷ cs) Q as
⟨&⟩[]-semantics (done {W ∷ Ts}) cs done [] = refl
⟨&⟩[]-semantics (done {W ∷ Ts}) cs done (a ∷ as) = cong (_∷_ a) (⟨&⟩[]-semantics done (a ∷ cs) done as)
⟨&⟩-semantics : ∀ {S T U} →
(P : S ⇒ T) → (Q : S ⇒ U) →
(⟦ P ⟨&⟩ Q ⟧ ≃ ⟦ P ⟧ ⟦⟨&⟩⟧ ⟦ Q ⟧)
⟨&⟩-semantics P Q = ⟨&⟩[]-semantics P [] Q
⟫-dist-⟨&⟩ : ∀ {S T U V} →
(P : T ⇒ U) → (Q : T ⇒ V) → (R : S ⇒ T) →
(⟦ R ⟫ (P ⟨&⟩ Q) ⟧ ≃ ⟦ (R ⟫ P) ⟨&⟩ (R ⟫ Q) ⟧)
⟫-dist-⟨&⟩ P Q R as =
begin
⟦ R ⟫ P ⟨&⟩ Q ⟧ as
≡⟨ ⟫-semantics R (P ⟨&⟩ Q) as ⟩
⟦ P ⟨&⟩ Q ⟧ (⟦ R ⟧ as)
≡⟨ ⟨&⟩-semantics P Q (⟦ R ⟧ as) ⟩
⟦ P ⟧ (⟦ R ⟧ as) ++ ⟦ Q ⟧ (⟦ R ⟧ as)
≡⟨ cong₂ _++_ (sym (⟫-semantics R P as)) (sym (⟫-semantics R Q as)) ⟩
⟦ R ⟫ P ⟧ as ++ ⟦ R ⟫ Q ⟧ as
≡⟨ sym (⟨&⟩-semantics (R ⟫ P) (R ⟫ Q) as) ⟩
⟦ (R ⟫ P) ⟨&⟩ (R ⟫ Q) ⟧ as
∎
|
{
"alphanum_fraction": 0.4603481625,
"avg_line_length": 50.0322580645,
"ext": "agda",
"hexsha": "6109b3e4777b63ad684db6c4520afdf7c250c36c",
"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": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/Properties/LaxProduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"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": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/Properties/LaxProduct.agda",
"max_line_length": 131,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/Properties/LaxProduct.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": 1441,
"size": 3102
}
|
module fold-Tree where
open import map-Tree using (Tree; leaf; node)
fold-Tree : ∀ {A B C : Set} → (A → C) → (C → B → C → C) → Tree A B → C
fold-Tree f _ (leaf a) = f a
fold-Tree f g (node treeˡ b treeʳ) = g (fold-Tree f g treeˡ) b (fold-Tree f g treeʳ)
|
{
"alphanum_fraction": 0.5746268657,
"avg_line_length": 33.5,
"ext": "agda",
"hexsha": "aa6bb012a559ced0de1f38500e51275d8f70f493",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/lists/fold-Tree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/lists/fold-Tree.agda",
"max_line_length": 84,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/lists/fold-Tree.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 106,
"size": 268
}
|
module moveArg where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
stuff : ( number : Nat) -> Bool -> Bool
stuff number bool = {! !}
stuff2 : Nat -> Bool -> Bool
stuff2 number bool = bool
nonsense : Bool
nonsense = stuff 0 true
dep : (A : Set) -> (B : A) -> Bool -> Bool
dep a b c = c
unnamedDep : (A : Set) -> A -> Bool -> Bool
unnamedDep a b c = c
sameName : (A : Set) -> {A : Set} -> A -> A
sameName set a = a
nonDep : (A : Set) -> (B : Set) -> B -> B
nonDep set1 set2 b = b
data List (A : Set) : Nat -> Set where
nil : List A 0
cons : {n : Nat} -> A -> List A n -> List A (suc n)
map : {n : Nat} -> {A : Set} -> {B : Set} -> (A -> B) -> List A n -> List B n
map f nil = nil
map f (cons x xs) = cons (f x) (map f xs)
map2 : {A : Set} -> {n : Nat} -> {B : Set} -> (A -> B) -> List A n -> List B n
map2 f nil = nil
map2 f (cons x xs) = cons (f x) (map2 f xs)
|
{
"alphanum_fraction": 0.5345982143,
"avg_line_length": 22.4,
"ext": "agda",
"hexsha": "8c07de5d788e01da8c3f8e1292967236ddadf780",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/input/MoveArg.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/input/MoveArg.agda",
"max_line_length": 78,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/input/MoveArg.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 339,
"size": 896
}
|
{-# OPTIONS --without-K --safe #-}
-- This module defines an intermediate calculus that is set up in the D<: universe
-- which bridges F<:- and D<:. The goal here is purely technical - to simply reduce
-- duplication.
module DsubReduced where
open import Data.List as List
open import Data.List.All as All
open import Data.Nat as ℕ
open import Data.Maybe as Maybe
open import Data.Product
open import Function
open import Data.Maybe.Properties as Maybeₚ
open import Data.Nat.Properties as ℕₚ
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality as ≡
open import DsubDef
open import FsubMinus
open import FsubMinus2
open import Utils
-- D<: Reduced
--
-- This judgment for contexts and types in D<: defines a corresponding calculus after
-- interpreting F<:⁻ into D<:. That is, D<: reduced is the image derivation of
-- interpreting F<:⁻ in D<:.
infix 4 _⊢ᵣ_<:_
data _⊢ᵣ_<:_ : Env → Typ → Typ → Set where
drtop : ∀ {Γ T} → Covar T → Γ ⊢ᵣ T <: ⊤
drrefl : ∀ {Γ T} → Covar T → Γ ⊢ᵣ T <: T
drall : ∀ {Γ S U S′ U′} →
Covar S → Covar U → Covar S′ → Covar U′ →
(S′<:S : Γ ⊢ᵣ S′ <: S) →
(U<:U′ : ⟨A: ⊥ ⋯ S′ ⟩ ∷ Γ ⊢ᵣ U <: U′) →
Γ ⊢ᵣ Π ⟨A: ⊥ ⋯ S ⟩ ∙ U <: Π ⟨A: ⊥ ⋯ S′ ⟩ ∙ U′
drsel : ∀ {Γ n U U′} →
(T∈Γ : env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ U ⟩) →
Covar U →
Γ ⊢ᵣ U <: U′ →
Γ ⊢ᵣ n ∙A <: U′
module FsubMinusToDsubR where
open FsubMinus.FsubMinus renaming (Env to Env′ ; _↑_ to _⇑_) hiding (env-lookup)
infix 5 ⟦_⟧ ⟪_⟫
⟦_⟧ : Ftyp → Typ
⟦ ⊤ ⟧ = ⊤
⟦ var x ⟧ = x ∙A
⟦ Π<: S ∙ U ⟧ = Π ⟨A: ⊥ ⋯ ⟦ S ⟧ ⟩ ∙ ⟦ U ⟧
⟪_⟫ : Env′ → Env
⟪ [] ⟫ = []
⟪ T ∷ Γ ⟫ = ⟨A: ⊥ ⋯ ⟦ T ⟧ ⟩ ∷ ⟪ Γ ⟫
module ⟦⟧-Bijective where
open import Function.Bijection
open import Function.Surjection
open import Function.Equality
CovTyp : Set
CovTyp = ∃ λ T → Covar T
⟦⟧-covar : ∀ T → Covar ⟦ T ⟧
⟦⟧-covar ⊤ = cv⊤
⟦⟧-covar (var x) = cv∙A _
⟦⟧-covar (Π<: S ∙ U) = cvΠ (⟦⟧-covar S) (⟦⟧-covar U)
⟦⟧-func : ≡.setoid Ftyp ⟶ ≡.setoid CovTyp
⟦⟧-func = record
{ _⟨$⟩_ = < ⟦_⟧ , ⟦⟧-covar >
; cong = ≡.cong < ⟦_⟧ , ⟦⟧-covar >
}
⟦⟧-injective : ∀ {S U} → ⟦ S ⟧ ≡ ⟦ U ⟧ → S ≡ U
⟦⟧-injective {⊤} {⊤} eq = refl
⟦⟧-injective {⊤} {var x} ()
⟦⟧-injective {⊤} {Π<: _ ∙ _} ()
⟦⟧-injective {var x} {⊤} ()
⟦⟧-injective {var x} {var .x} refl = refl
⟦⟧-injective {var x} {Π<: _ ∙ _} ()
⟦⟧-injective {Π<: _ ∙ _} {⊤} ()
⟦⟧-injective {Π<: _ ∙ _} {var x} ()
⟦⟧-injective {Π<: S₁ ∙ U₁} {Π<: S₂ ∙ U₂} eq
with ⟦ S₁ ⟧ | ⟦ S₂ ⟧ | ⟦ U₁ ⟧ | ⟦ U₂ ⟧
| ⟦⟧-injective {S₁} {S₂} | ⟦⟧-injective {U₁} {U₂}
⟦⟧-injective {Π<: S₁ ∙ U₁} {Π<: S₂ ∙ U₂} refl
| _ | _ | _ | _ | rec₁ | rec₂ = ≡.cong₂ Π<:_∙_ (rec₁ refl) (rec₂ refl)
⟦⟧-func-injective : ∀ {S U} → (CovTyp ∋ (⟦ S ⟧ , ⟦⟧-covar S)) ≡ (⟦ U ⟧ , ⟦⟧-covar U) → S ≡ U
⟦⟧-func-injective {S} {U} eq
with ⟦ S ⟧ | ⟦⟧-covar S | ⟦ U ⟧ | ⟦⟧-covar U
| ⟦⟧-injective {S} {U}
⟦⟧-func-injective {S} {U} refl
| _ | _ | _ | _ | inj = inj refl
infix 5 ⟦_⟧⁻¹
⟦_⟧⁻¹ : CovTyp → Ftyp
⟦ _ , cv⊤ ⟧⁻¹ = ⊤
⟦ _ , cv∙A x ⟧⁻¹ = var x
⟦ _ , cvΠ S U ⟧⁻¹ = Π<: ⟦ -, S ⟧⁻¹ ∙ ⟦ -, U ⟧⁻¹
⟦⟧-func-inv : ≡.setoid CovTyp ⟶ ≡.setoid Ftyp
⟦⟧-func-inv = record
{ _⟨$⟩_ = ⟦_⟧⁻¹
; cong = ≡.cong ⟦_⟧⁻¹
}
⟦⟧-left-inverse-⟦⟧⁻¹ : ∀ {T} (cT : Covar T) → (⟦ ⟦ -, cT ⟧⁻¹ ⟧ , ⟦⟧-covar ⟦ -, cT ⟧⁻¹) ≡ (CovTyp ∋ (-, cT))
⟦⟧-left-inverse-⟦⟧⁻¹ cv⊤ = refl
⟦⟧-left-inverse-⟦⟧⁻¹ (cv∙A n) = refl
⟦⟧-left-inverse-⟦⟧⁻¹ (cvΠ S U)
with ⟦ ⟦ -, S ⟧⁻¹ ⟧ | ⟦ ⟦ -, U ⟧⁻¹ ⟧
| ⟦⟧-covar ⟦ -, S ⟧⁻¹ | ⟦⟧-covar ⟦ -, U ⟧⁻¹
| ⟦⟧-left-inverse-⟦⟧⁻¹ S | ⟦⟧-left-inverse-⟦⟧⁻¹ U
... | _ | _ | _ | _ | refl | refl = refl
⟦⟧-bijective : Bijective ⟦⟧-func
⟦⟧-bijective = record
{ injective = ⟦⟧-func-injective
; surjective = record
{ from = ⟦⟧-func-inv
; right-inverse-of = λ { (_ , T) → ⟦⟧-left-inverse-⟦⟧⁻¹ T }
}
}
open ⟦⟧-Bijective using (⟦⟧-covar ; ⟦⟧-injective) public
⟪⟫-contraEnv : ∀ Γ → ContraEnv ⟪ Γ ⟫
⟪⟫-contraEnv [] = []
⟪⟫-contraEnv (T ∷ Γ) = ctt (⟦⟧-covar T) ∷ ⟪⟫-contraEnv Γ
⟦⟧-↑-comm : ∀ T n → ⟦ T ⟧ ↑ n ≡ ⟦ T ⇑ n ⟧
⟦⟧-↑-comm ⊤ n = refl
⟦⟧-↑-comm (var x) n with n ≤? x
... | yes n≤x = refl
... | no n>x = refl
⟦⟧-↑-comm (Π<: S ∙ U) n
rewrite ⟦⟧-↑-comm S n | ⟦⟧-↑-comm U (suc n)
= refl
<:∈⇒env-lookup : ∀ {n T Γ} → n <: T ∈ Γ → env-lookup ⟪ Γ ⟫ n ≡ just ⟨A: ⊥ ⋯ ⟦ T ⟧ ⟩
<:∈⇒env-lookup {_} {_} {T ∷ ._} hd
rewrite ⟦⟧-↑-comm T 0 = refl
<:∈⇒env-lookup {suc n} {_} {._ ∷ Γ} (tl {_} {T} T∈Γ)
with lookupOpt ⟪ Γ ⟫ n | <:∈⇒env-lookup T∈Γ
... | nothing | ()
... | just _ | eq
rewrite sym $ ⟦⟧-↑-comm T 0 = cong (just ∘ (_↑ 0)) (just-injective eq)
F<:⇒D<:ᵣ : ∀ {Γ S U} → Γ ⊢F S <: U → ⟪ Γ ⟫ ⊢ᵣ ⟦ S ⟧ <: ⟦ U ⟧
F<:⇒D<:ᵣ ftop = drtop (⟦⟧-covar _)
F<:⇒D<:ᵣ fvrefl = drrefl (cv∙A _)
F<:⇒D<:ᵣ (fbinds T∈Γ T<:U) = drsel (<:∈⇒env-lookup T∈Γ) (⟦⟧-covar _) (F<:⇒D<:ᵣ T<:U)
F<:⇒D<:ᵣ (fall S′<:S U<:U′) = drall (⟦⟧-covar _) (⟦⟧-covar _) (⟦⟧-covar _) (⟦⟧-covar _)
(F<:⇒D<:ᵣ S′<:S) (F<:⇒D<:ᵣ U<:U′)
env-lookup⇒<:∈ : ∀ {n T Γ} → env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ T ⟩ →
∀ {Γ′} → Γ ≡ ⟪ Γ′ ⟫ →
∃ λ T′ → T ≡ ⟦ T′ ⟧ × n <: T′ ∈ Γ′
env-lookup⇒<:∈ T∈Γ eqΓ = aux (lookup⇒↦∈ T∈Γ) refl eqΓ
where aux : ∀ {n T Γ} → n ↦ T ∈ Γ →
∀ {U Γ′} → T ≡ ⟨A: ⊥ ⋯ U ⟩ → Γ ≡ ⟪ Γ′ ⟫ →
∃ λ U′ → U ≡ ⟦ U′ ⟧ × n <: U′ ∈ Γ′
aux hd {_} {[]} eqT ()
aux hd {_} {T ∷ Γ′} refl refl
rewrite ⟦⟧-↑-comm T 0 = T ⇑ zero , refl , hd
aux (tl T∈Γ) {_} {[]} eqT ()
aux (tl {T = ⊤} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = ⊥} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = n ∙A} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = Π S ∙ U} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = ⟨A: ⊤ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = ⟨A: ⊥ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} refl refl
with aux T∈Γ refl refl
... | U′ , refl , U′∈Γ′
rewrite ⟦⟧-↑-comm U′ 0 = U′ ⇑ zero , refl , tl U′∈Γ′
aux (tl {T = ⟨A: _ ∙A ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = ⟨A: Π _ ∙ _ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl
aux (tl {T = ⟨A: ⟨A: _ ⋯ _ ⟩ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl
D<:ᵣ⇒F<: : ∀ {Γ′ S′ U′} → Γ′ ⊢ᵣ S′ <: U′ →
∀ {Γ S U} →
Γ′ ≡ ⟪ Γ ⟫ → S′ ≡ ⟦ S ⟧ → U′ ≡ ⟦ U ⟧ →
Γ ⊢F S <: U
D<:ᵣ⇒F<: (drtop S′) {Γ} {S} {⊤} eqΓ eqS refl = ftop
D<:ᵣ⇒F<: (drtop S′) {Γ} {S} {var x} eqΓ eqS ()
D<:ᵣ⇒F<: (drtop S′) {Γ} {S} {Π<: U ∙ U₁} eqΓ eqS ()
D<:ᵣ⇒F<: (drrefl S′) {Γ} {S} {U} eqΓ eqS eqU
rewrite ⟦⟧-injective (≡.trans (sym eqS) eqU) = <:-refl Γ U
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {⊤} {⊤} eqΓ () eqU
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {⊤} {var x} eqΓ () eqU
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {⊤} {Π<: U ∙ U₁} eqΓ () eqU
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {var _} {⊤} eqΓ () eqU
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {var _} {var _} eqΓ () eqU
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {var _} {Π<: _ ∙ _} eqΓ () eqU
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {Π<: _ ∙ _} {⊤} eqΓ refl ()
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {Π<: _ ∙ _} {var _} eqΓ refl ()
D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {Π<: S ∙ U} {Π<: S′ ∙ U′} eqΓ refl refl
= fall (D<:ᵣ⇒F<: S′<:S eqΓ refl refl)
(D<:ᵣ⇒F<: U<:U′ (cong (⟨A: ⊥ ⋯ ⟦ S′ ⟧ ⟩ ∷_) eqΓ) refl refl)
D<:ᵣ⇒F<: (drsel T∈Γ cT S<:U) {Γ} {⊤} {U} eqΓ () eqU
D<:ᵣ⇒F<: (drsel T∈Γ cT S<:U) {Γ} {var x} {U} eqΓ refl eqU
with env-lookup⇒<:∈ T∈Γ eqΓ
... | U′ , eqU′ , T′∈Γ = fbinds T′∈Γ (D<:ᵣ⇒F<: S<:U eqΓ eqU′ eqU)
D<:ᵣ⇒F<: (drsel T∈Γ cT S<:U) {Γ} {Π<: _ ∙ _} {U} eqΓ () eqU
|
{
"alphanum_fraction": 0.4192123666,
"avg_line_length": 38.8142857143,
"ext": "agda",
"hexsha": "0d35553d0482701a9edefe10d648a7c06d7373df",
"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": "48214a55ebb484fd06307df4320813d4a002535b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "HuStmpHrrr/popl20-artifact",
"max_forks_repo_path": "agda/DsubReduced.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"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": "HuStmpHrrr/popl20-artifact",
"max_issues_repo_path": "agda/DsubReduced.agda",
"max_line_length": 111,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "HuStmpHrrr/popl20-artifact",
"max_stars_repo_path": "agda/DsubReduced.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z",
"num_tokens": 4529,
"size": 8151
}
|
{-# OPTIONS --safe #-}
module Cubical.Data.List.FinData where
open import Cubical.Foundations.Prelude
open import Cubical.Data.List
open import Cubical.Data.FinData
variable
ℓ : Level
A : Type ℓ
-- copy-paste from agda-stdlib
lookup : ∀ (xs : List A) → Fin (length xs) → A
lookup (x ∷ xs) zero = x
lookup (x ∷ xs) (suc i) = lookup xs i
|
{
"alphanum_fraction": 0.6820809249,
"avg_line_length": 21.625,
"ext": "agda",
"hexsha": "38820211215289f92bffeb663c691f961d4b1369",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/List/FinData.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/List/FinData.agda",
"max_line_length": 46,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/List/FinData.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 113,
"size": 346
}
|
-- Minimal implicational modal logic, PHOAS approach, final encoding
module Pf.BoxMp where
open import Lib using (Nat; suc)
-- Types
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
BOX : Ty -> Ty
-- Context and truth judgement with modal depth
Cx : Set1
Cx = Ty -> Nat -> Set
isTrue : Ty -> Nat -> Cx -> Set
isTrue a d tc = tc a d
-- Terms
TmRepr : Set1
TmRepr = Nat -> Cx -> Ty -> Set
module ArrMp where
record Tm (tr : TmRepr) : Set1 where
infixl 1 _$_
field
var : forall {d tc a} -> isTrue a d tc -> tr d tc a
lam' : forall {d tc a b} -> (isTrue a d tc -> tr d tc b) -> tr d tc (a => b)
_$_ : forall {d tc a b} -> tr d tc (a => b) -> tr d tc a -> tr d tc b
lam'' : forall {d tc a b} -> (tr d tc a -> tr d tc b) -> tr d tc (a => b)
lam'' f = lam' \x -> f (var x)
syntax lam'' (\a -> b) = lam a => b
open Tm {{...}} public
module BoxMp where
record Tm (tr : TmRepr) : Set1 where
field
box : forall {d tc a} -> tr (suc d) tc a -> tr d tc (BOX a)
unbox' : forall {d >d tc a b} -> tr d tc (BOX a) -> (isTrue a >d tc -> tr d tc b) -> tr d tc b
isArrMp : ArrMp.Tm tr
open ArrMp.Tm isArrMp public
unbox'' : forall {d >d tc a b} -> tr d tc (BOX a) -> (tr >d tc a -> tr d tc b) -> tr d tc b
unbox'' x' f = unbox' x' \x -> f (var x)
syntax unbox'' x' (\x -> y) = unbox x' as x => y
open Tm {{...}} public
Thm : Ty -> Set1
Thm a = forall {tr d tc} {{_ : Tm tr}} -> tr d tc a
open BoxMp public
-- Example theorems
rNec : forall {a} -> Thm a -> Thm (BOX a)
rNec x =
box x
aK : forall {a b} -> Thm (BOX (a => b) => BOX a => BOX b)
aK =
lam f' =>
lam x' =>
unbox f' as f =>
unbox x' as x =>
box (f $ x)
aT : forall {a} -> Thm (BOX a => a)
aT =
lam x' =>
unbox x' as x => x
a4 : forall {a} -> Thm (BOX a => BOX (BOX a))
a4 =
lam x' =>
unbox x' as x => box (box x)
t1 : forall {a} -> Thm (a => BOX (a => a))
t1 =
lam _ => box (lam y => y)
|
{
"alphanum_fraction": 0.4927395934,
"avg_line_length": 22.4565217391,
"ext": "agda",
"hexsha": "b471dbd66bed8a75646de20157efe49d4f80cdfd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Pf/BoxMp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Pf/BoxMp.agda",
"max_line_length": 100,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Pf/BoxMp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 787,
"size": 2066
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Equivalence closures of binary relations
--
-- This module is DEPRECATED. Please use the
-- Relation.Binary.Construct.Closure.Equivalence module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.EquivalenceClosure where
open import Relation.Binary.Construct.Closure.Equivalence public
|
{
"alphanum_fraction": 0.546201232,
"avg_line_length": 32.4666666667,
"ext": "agda",
"hexsha": "c76a60199d8aaddcd62d8479fdc47a385a946ffa",
"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/EquivalenceClosure.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/EquivalenceClosure.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/EquivalenceClosure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 75,
"size": 487
}
|
module Examples where
open import Prelude
open import T
---- some example programs
-- boy, de bruijn indexes are unreadable
w = weaken-closed
one : TNat
one = suc zero
two = suc one
three = suc two
t-plus : TCExp (nat ⇒ nat ⇒ nat)
t-plus = Λ (Λ (rec (var (S Z)) (var Z) (suc (var Z))))
t-compose : ∀{A B C} → TCExp ((A ⇒ B) ⇒ (C ⇒ A) ⇒ (C ⇒ B))
t-compose = Λ (Λ (Λ (var (S (S Z)) $ ((var (S Z)) $ (var Z)))))
t-id : ∀{A} → TCExp (A ⇒ A)
t-id = Λ (var Z)
t-iterate : ∀{A} → TCExp (nat ⇒ (A ⇒ A) ⇒ (A ⇒ A))
t-iterate = Λ (Λ (rec (var (S Z)) (w t-id)
(w t-compose $ var (S Z) $ var Z)))
t-ack : TCExp (nat ⇒ nat ⇒ nat)
t-ack = Λ (rec (var Z) (Λ (suc (var Z)))
(Λ (w t-iterate $ var Z $ var (S Z) $ (var (S Z) $ w one))))
ack-test : TNat
ack-test = t-ack $ two $ two
plus-test : TNat
plus-test = t-plus $ two $ two
|
{
"alphanum_fraction": 0.5266272189,
"avg_line_length": 28.1666666667,
"ext": "agda",
"hexsha": "c99c378ec9eb7e901b75adfa8ae16d821e6f62ca",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-04T22:37:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-26T11:39:14.000Z",
"max_forks_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msullivan/godels-t",
"max_forks_repo_path": "Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"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": "msullivan/godels-t",
"max_issues_repo_path": "Examples.agda",
"max_line_length": 72,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msullivan/godels-t",
"max_stars_repo_path": "Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T00:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-25T01:52:57.000Z",
"num_tokens": 337,
"size": 845
}
|
open import Prelude
open import Nat
open import List
module contexts where
-- helper function
diff-1 : ∀{n m} → n < m → Nat
diff-1 n<m = difference (n<m→1+n≤m n<m)
---- the core declarations ----
-- TODO move definitions
_ctx : Set → Set
A ctx = List (Nat ∧ A)
-- nil context
∅ : {A : Set} → A ctx
∅ = []
-- singleton context
■_ : {A : Set} → (Nat ∧ A) → A ctx
■_ (x , a) = (x , a) :: []
infixr 100 ■_
-- context extension/insertion - never use _::_
_,,_ : ∀{A} → A ctx → (Nat ∧ A) → A ctx
[] ,, (x , a) = ■ (x , a)
((hx , ha) :: t) ,, (x , a) with <dec x hx
... | Inl x<hx = (x , a) :: ((diff-1 x<hx , ha) :: t)
... | Inr (Inl refl) = (x , a) :: t
... | Inr (Inr hx<x) = (hx , ha) :: (t ,, (diff-1 hx<x , a))
infixl 10 _,,_
-- membership, or presence, in a context
data _∈_ : {A : Set} (p : Nat ∧ A) → (Γ : A ctx) → Set where
InH : {A : Set} {Γ : A ctx} {x : Nat} {a : A} →
(x , a) ∈ ((x , a) :: Γ)
InT : {A : Set} {Γ : A ctx} {x s : Nat} {a a' : A} →
(x , a) ∈ Γ →
((x + 1+ s , a)) ∈ ((s , a') :: Γ)
-- the domain of a context
dom : {A : Set} → A ctx → Nat → Set
dom {A} Γ x = Σ[ a ∈ A ] ((x , a) ∈ Γ)
-- apartness for contexts
_#_ : {A : Set} (n : Nat) → (Γ : A ctx) → Set
x # Γ = dom Γ x → ⊥
_##_ : {A : Set} → A ctx → A ctx → Set
Γ1 ## Γ2 = (x : Nat) → dom Γ1 x → x # Γ2
_≈_ : {A : Set} → A ctx → A ctx → Set
_≈_ {A} Γ1 Γ2 = (x : Nat) (a1 a2 : A) →
(x , a1) ∈ Γ1 ∧ (x , a2) ∈ Γ2 →
a1 == a2
-- TODO theorems and explanation
ctxmap : {A B : Set} → (A → B) → A ctx → B ctx
ctxmap f Γ = map (λ {(hx , ha) → (hx , f ha)}) Γ
-- TODO theorems
-- returns a list of the values stored in the context
ctx⇒values : {A : Set} → A ctx → List A
-- TODO theorems
-- converts a list of key-value pairs into a context, with later pairs in the list
-- overriding bindings definend by previous pairs
list⇒ctx : {A : Set} → List (Nat ∧ A) → A ctx
-- TODO theorems
-- converts a list of key-value pairs into a multi-context, where each value of
-- the result is the sublist of values from the former that were mapped to by the
-- corresponding key
list⇒list-ctx : {A : Set} → List (Nat ∧ A) → (List A) ctx
-- union merge A B is the union of A and B,
-- with (merge a b) being invoked to handle the mappings they have in common
union : {A : Set} → (A → A → A) → A ctx → A ctx → A ctx
-- The primary way to test membership is to use _∈_,
-- but this can be used in cases where using _∈_
-- would be too verbose or awkward.
-- The lookup theorems prove that they are compatible
_⦃⦃_⦄⦄ : {A : Set} → A ctx → Nat → Maybe A
[] ⦃⦃ x ⦄⦄ = None
((hx , ha) :: t) ⦃⦃ x ⦄⦄ with <dec x hx
... | Inl x<hx = None
... | Inr (Inl refl) = Some ha
... | Inr (Inr hx<x) = t ⦃⦃ diff-1 hx<x ⦄⦄
---- lemmas ----
undiff-1 : (x s : Nat) → (x<s+1+x : x < s + 1+ x) → s == diff-1 x<s+1+x
undiff-1 x s x<s+1+x
rewrite n+1+m==1+n+m {s} {x} | ! (m-n==1+m-1+n n≤m+n (n<m→1+n≤m x<s+1+x)) | +comm {s} {x}
= ! (n+m-n==m n≤n+m)
too-small : {A : Set} {Γ : A ctx} {xl xb : Nat} {a : A} →
xl < xb →
dom ((xb , a) :: Γ) xl →
⊥
too-small (_ , ne) (_ , InH) = ne refl
too-small (x+1+xb≤xb , x+1+xb==xb) (_ , InT _) =
x+1+xb==xb (≤antisym x+1+xb≤xb (≤trans (≤1+ ≤refl) n≤m+n))
all-not-none : {A : Set} {Γ : A ctx} {x : Nat} {a : A} →
None ≠ (((x , a) :: Γ) ⦃⦃ x ⦄⦄)
all-not-none {x = x} rewrite <dec-refl x = λ ()
all-bindings-==-rec-eq : {A : Set} {Γ1 Γ2 : A ctx} {x : Nat} {a : A} →
((x' : Nat) → ((x , a) :: Γ1) ⦃⦃ x' ⦄⦄ == ((x , a) :: Γ2) ⦃⦃ x' ⦄⦄) →
((x' : Nat) → Γ1 ⦃⦃ x' ⦄⦄ == Γ2 ⦃⦃ x' ⦄⦄)
all-bindings-==-rec-eq {x = x} h x'
with h (x' + 1+ x)
... | eq
with <dec (x' + 1+ x) x
... | Inl x'+1+x<x
= abort (<antisym x'+1+x<x (n<m→n<s+m n<1+n))
... | Inr (Inl x'+1+x==x)
= abort ((flip n≠n+1+m) (n+1+m==1+n+m · (+comm {1+ x} · x'+1+x==x)))
... | Inr (Inr x<x'+1+x)
rewrite ! (undiff-1 x x' x<x'+1+x) = eq
all-bindings-==-rec : {A : Set} {Γ1 Γ2 : A ctx} {x1 x2 : Nat} {a1 a2 : A} →
((x : Nat) → ((x1 , a1) :: Γ1) ⦃⦃ x ⦄⦄ == ((x2 , a2) :: Γ2) ⦃⦃ x ⦄⦄) →
((x : Nat) → Γ1 ⦃⦃ x ⦄⦄ == Γ2 ⦃⦃ x ⦄⦄)
all-bindings-==-rec {x1 = x1} {x2} h x
with h x1 | h x2
... | eq1 | eq2
rewrite <dec-refl x1 | <dec-refl x2
with <dec x1 x2 | <dec x2 x1
... | Inl _ | _
= abort (somenotnone eq1)
... | Inr _ | Inl _
= abort (somenotnone (! eq2))
... | Inr (Inl refl) | Inr (Inl refl)
rewrite someinj eq1 | someinj eq2
= all-bindings-==-rec-eq h x
... | Inr (Inl refl) | Inr (Inr x2<x2)
= abort (<antirefl x2<x2)
... | Inr (Inr x2<x2) | Inr (Inl refl)
= abort (<antirefl x2<x2)
... | Inr (Inr x2<x1) | Inr (Inr x1<x2)
= abort (<antisym x1<x2 x2<x1)
---- core theorems ----
-- lookup is decidable
lookup-dec : {A : Set} (Γ : A ctx) (x : Nat) →
Σ[ a ∈ A ] (Γ ⦃⦃ x ⦄⦄ == Some a) ∨ Γ ⦃⦃ x ⦄⦄ == None
lookup-dec Γ x
with Γ ⦃⦃ x ⦄⦄
... | Some a = Inl (a , refl)
... | None = Inr refl
-- The next two theorems show that lookup (_⦃⦃_⦄⦄) is consistent with membership (_∈_)
lookup-cons-1 : {A : Set} {Γ : A ctx} {x : Nat} {a : A} →
Γ ⦃⦃ x ⦄⦄ == Some a →
(x , a) ∈ Γ
lookup-cons-1 {Γ = []} ()
lookup-cons-1 {Γ = (hx , ha) :: t} {x} h
with <dec x hx
lookup-cons-1 {_} {(hx , ha) :: t} {x} () | Inl _
lookup-cons-1 {_} {(hx , ha) :: t} {.hx} refl | Inr (Inl refl) = InH
lookup-cons-1 {_} {(hx , ha) :: t} {x} {a = a} h | Inr (Inr hx<x)
= tr
(λ y → (y , a) ∈ ((hx , ha) :: t))
(m-n+n==m (n<m→1+n≤m hx<x))
(InT (lookup-cons-1 {Γ = t} h))
lookup-cons-2 : {A : Set} {Γ : A ctx} {x : Nat} {a : A} →
(x , a) ∈ Γ →
Γ ⦃⦃ x ⦄⦄ == Some a
lookup-cons-2 {x = x} InH rewrite <dec-refl x = refl
lookup-cons-2 (InT {Γ = Γ} {x = x} {s} {a} x∈Γ)
with <dec (x + 1+ s) s
... | Inl x+1+s<s = abort (<antisym x+1+s<s (n<m→n<s+m n<1+n))
... | Inr (Inl x+1+s==s) = abort ((flip n≠n+1+m) (n+1+m==1+n+m · (+comm {1+ s} · x+1+s==s)))
... | Inr (Inr s<x+1+s)
with lookup-cons-2 x∈Γ
... | h rewrite ! (undiff-1 s x s<x+1+s) = h
-- membership (_∈_) respects insertion (_,,_)
x,a∈Γ,,x,a : {A : Set} {Γ : A ctx} {x : Nat} {a : A} →
(x , a) ∈ (Γ ,, (x , a))
x,a∈Γ,,x,a {Γ = []} {x} {a} = InH
x,a∈Γ,,x,a {_} {(hx , ha) :: t} {x} {a}
with <dec x hx
... | Inl _ = InH
... | Inr (Inl refl) = InH
... | Inr (Inr hx<x) =
tr
(λ y → (y , a) ∈ ((hx , ha) :: (t ,, (diff-1 hx<x , a))))
(m-n+n==m (n<m→1+n≤m hx<x))
(InT (x,a∈Γ,,x,a {Γ = t} {diff-1 hx<x} {a}))
-- insertion can't generate spurious membership
x∈Γ+→x∈Γ : {A : Set} {Γ : A ctx} {x x' : Nat} {a a' : A} →
x ≠ x' →
(x , a) ∈ (Γ ,, (x' , a')) →
(x , a) ∈ Γ
x∈Γ+→x∈Γ {Γ = []} x≠x' InH = abort (x≠x' refl)
x∈Γ+→x∈Γ {Γ = []} x≠x' (InT ())
x∈Γ+→x∈Γ {Γ = (hx , ha) :: t} {x' = x'} x≠x' x∈Γ+
with <dec x' hx
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = x'} x≠x' InH | Inl x'<hx = abort (x≠x' refl)
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = x'} x≠x' (InT InH) | Inl x'<hx
rewrite m-n+n==m (n<m→1+n≤m x'<hx) = InH
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = x'} x≠x' (InT (InT {x = x} x∈Γ+)) | Inl x'<hx
rewrite +assc {x} {1+ (diff-1 x'<hx)} {1+ x'} | m-n+n==m (n<m→1+n≤m x'<hx)
= InT x∈Γ+
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = .hx} x≠x' InH | Inr (Inl refl) = abort (x≠x' refl)
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = .hx} x≠x' (InT x∈Γ+) | Inr (Inl refl) = InT x∈Γ+
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = x'} x≠x' InH | Inr (Inr hx<x') = InH
x∈Γ+→x∈Γ {_} {(hx , ha) :: t} {x' = x'} x≠x' (InT x∈Γ+) | Inr (Inr hx<x')
= InT (x∈Γ+→x∈Γ (λ where refl → x≠x' (m-n+n==m (n<m→1+n≤m hx<x'))) x∈Γ+)
-- insertion respects membership
x∈Γ→x∈Γ+ : {A : Set} {Γ : A ctx} {x x' : Nat} {a a' : A} →
x ≠ x' →
(x , a) ∈ Γ →
(x , a) ∈ (Γ ,, (x' , a'))
x∈Γ→x∈Γ+ {x = x} {x'} {a} {a'} x≠x' (InH {Γ = Γ'})
with <dec x' x
... | Inl x'<x
= tr
(λ y → (y , a) ∈ ((x' , a') :: ((diff-1 x'<x , a) :: Γ')))
(m-n+n==m (n<m→1+n≤m x'<x))
(InT InH)
... | Inr (Inl refl) = abort (x≠x' refl)
... | Inr (Inr x<x') = InH
x∈Γ→x∈Γ+ {x = .(_ + 1+ _)} {x'} {a} {a'} x≠x' (InT {Γ = Γ} {x} {s} {a' = a''} x∈Γ)
with <dec x' s
... | Inl x'<s
= tr
(λ y → (y , a) ∈ ((x' , a') :: ((diff-1 x'<s , a'') :: Γ)))
((+assc {b = 1+ (diff-1 x'<s)}) · (ap1 (_+_ x) (1+ap (m-n+n==m (n<m→1+n≤m x'<s)))))
(InT (InT x∈Γ))
... | Inr (Inl refl) = InT x∈Γ
... | Inr (Inr s<x') =
InT (x∈Γ→x∈Γ+ (λ where refl → x≠x' (m-n+n==m (n<m→1+n≤m s<x'))) x∈Γ)
-- Decidability of membership
-- This also packages up an appeal to context membership into a form that
-- lets us retain more information
ctxindirect : {A : Set} (Γ : A ctx) (x : Nat) → dom Γ x ∨ x # Γ
ctxindirect [] x = Inr (λ ())
ctxindirect ((hx , ha) :: t) x
with <dec x hx
... | Inl x<hx = Inr (too-small x<hx)
... | Inr (Inl refl) = Inl (ha , InH)
... | Inr (Inr hx<x)
with ctxindirect t (diff-1 hx<x)
ctxindirect ((hx , ha) :: t) x | Inr (Inr hx<x) | Inl (a , rec) =
Inl (a , tr
(λ y → (y , a) ∈ ((hx , ha) :: t))
(m-n+n==m (n<m→1+n≤m hx<x))
(InT rec))
ctxindirect {A} ((hx , ha) :: t) x | Inr (Inr hx<x) | Inr dne =
Inr x∉Γ
where
x∉Γ : Σ[ a ∈ A ] ((x , a) ∈ ((hx , ha) :: t)) → ⊥
x∉Γ (_ , x∈Γ) with x∈Γ
... | InH = (π2 hx<x) refl
... | InT {x = s} x-hx-1∈t
rewrite ! (undiff-1 hx s hx<x) = dne (_ , x-hx-1∈t)
-- contexts give at most one binding for each variable
ctxunicity : {A : Set} {Γ : A ctx} {x : Nat} {a a' : A} →
(x , a) ∈ Γ →
(x , a') ∈ Γ →
a == a'
ctxunicity ah a'h
with lookup-cons-2 ah | lookup-cons-2 a'h
... | ah' | a'h' = someinj (! ah' · a'h')
-- everything is apart from the nil context
x#∅ : {A : Set} {x : Nat} → _#_ {A} x ∅
x#∅ (_ , ())
-- if an index is in the domain of a singleton context, it's the only
-- index in the context
lem-dom-eq : {A : Set} {a : A} {n m : Nat} →
dom (■ (m , a)) n →
n == m
lem-dom-eq (_ , InH) = refl
lem-dom-eq (_ , InT ())
-- If two contexts are semantically equivalent
-- (i.e. they represent the same mapping from ids to values),
-- then they are physically equal as judged by _==_
ctx-==-eqv : {A : Set} {Γ1 Γ2 : A ctx} →
((x : Nat) → Γ1 ⦃⦃ x ⦄⦄ == Γ2 ⦃⦃ x ⦄⦄) →
Γ1 == Γ2
ctx-==-eqv {Γ1 = []} {[]} all-bindings-== = refl
ctx-==-eqv {Γ1 = []} {(hx2 , ha2) :: t2} all-bindings-==
= abort (all-not-none {Γ = t2} {x = hx2} (all-bindings-== hx2))
ctx-==-eqv {Γ1 = (hx1 , ha1) :: t1} {[]} all-bindings-==
= abort (all-not-none {Γ = t1} {x = hx1} (! (all-bindings-== hx1)))
ctx-==-eqv {Γ1 = (hx1 , ha1) :: t1} {(hx2 , ha2) :: t2} all-bindings-==
rewrite ctx-==-eqv {Γ1 = t1} {t2} (all-bindings-==-rec all-bindings-==)
with all-bindings-== hx1 | all-bindings-== hx2
... | ha1== | ha2== rewrite <dec-refl hx1 | <dec-refl hx2
with <dec hx1 hx2 | <dec hx2 hx1
... | Inl hx1<hx2 | _
= abort (somenotnone ha1==)
... | Inr (Inl refl) | Inl hx2<hx1
= abort (somenotnone (! ha2==))
... | Inr (Inr hx2<hx1) | Inl hx2<'hx1
= abort (somenotnone (! ha2==))
... | Inr (Inl refl) | Inr _
rewrite someinj ha1== = refl
... | Inr (Inr hx2<hx1) | Inr (Inl refl)
rewrite someinj ha2== = refl
... | Inr (Inr hx2<hx1) | Inr (Inr hx1<hx2)
= abort (<antisym hx1<hx2 hx2<hx1)
-- equality of contexts is decidable
ctx-==-dec : {A : Set}
(Γ1 Γ2 : A ctx) →
((a1 a2 : A) → a1 == a2 ∨ a1 ≠ a2) →
Γ1 == Γ2 ∨ Γ1 ≠ Γ2
ctx-==-dec [] [] _ = Inl refl
ctx-==-dec [] (_ :: _) _ = Inr (λ ())
ctx-==-dec (_ :: _) [] _ = Inr (λ ())
ctx-==-dec ((hx1 , ha1) :: t1) ((hx2 , ha2) :: t2) A==dec
with natEQ hx1 hx2 | A==dec ha1 ha2 | ctx-==-dec t1 t2 A==dec
... | Inl refl | Inl refl | Inl refl = Inl refl
... | Inl refl | Inl refl | Inr ne = Inr λ where refl → ne refl
... | Inl refl | Inr ne | _ = Inr λ where refl → ne refl
... | Inr ne | _ | _ = Inr λ where refl → ne refl
-- A useful way to destruct context membership. Never destruct a context via _::_
ctx-split : {A : Set} {Γ : A ctx} {n m : Nat} {an am : A} →
(n , an) ∈ (Γ ,, (m , am)) →
(n ≠ m ∧ (n , an) ∈ Γ) ∨ (n == m ∧ an == am)
ctx-split {Γ = Γ} {n} {m} {an} {am} n∈Γ+
with natEQ n m
... | Inl refl = Inr (refl , ctxunicity n∈Γ+ (x,a∈Γ,,x,a {Γ = Γ}))
... | Inr n≠m = Inl (n≠m , x∈Γ+→x∈Γ n≠m n∈Γ+)
-- I'd say "God dammit agda" but AFAICT Coq is terrible about this as well
lemma-bullshit : {A : Set} (Γ' : A ctx) (a : A) (n m : Nat) →
Σ[ Γ ∈ A ctx ] (Γ == (n + 1+ m , a) :: Γ')
lemma-bullshit Γ' a n m = ((n + 1+ m , a) :: Γ') , refl
-- Allows the elimination of contexts. Never destruct a context via _::_
ctx-elim : {A : Set} {Γ : A ctx} →
Γ == ∅
∨
Σ[ n ∈ Nat ] Σ[ a ∈ A ] Σ[ Γ' ∈ A ctx ]
(Γ == Γ' ,, (n , a) ∧ n # Γ')
ctx-elim {Γ = []} = Inl refl
ctx-elim {Γ = (n , a) :: []} = Inr (_ , _ , _ , refl , x#∅)
ctx-elim {Γ = (n , a) :: ((m , a2) :: Γ'')}
with lemma-bullshit Γ'' a2 m n
... | Γ' , eq
= Inr (n , a , Γ' , eqP , not-dom)
where
eqP : (n , a) :: ((m , a2) :: Γ'') == Γ' ,, (n , a)
eqP rewrite eq with <dec n (m + 1+ n)
... | Inl n<m+1+n
rewrite ! (undiff-1 n m n<m+1+n) = refl
... | Inr (Inl n==m+1+n)
= abort (n≠n+1+m (n==m+1+n · (n+1+m==1+n+m · +comm {1+ m})))
... | Inr (Inr m+1+n<n)
= abort (<antisym m+1+n<n (n<m→n<s+m n<1+n))
not-dom : dom Γ' n → ⊥
not-dom rewrite eq = λ n∈Γ' →
too-small (n<m→n<s+m n<1+n) n∈Γ'
-- When using ctx-elim, this theorem is useful for establishing termination
ctx-decreasing : {A : Set} {Γ : A ctx} {n : Nat} {a : A} →
n # Γ →
∥ Γ ,, (n , a) ∥ == 1+ ∥ Γ ∥
ctx-decreasing {Γ = []} n#Γ = refl
ctx-decreasing {Γ = (n' , a') :: Γ} {n} n#Γ
with <dec n n'
... | Inl n<n' = refl
... | Inr (Inl refl) = abort (n#Γ (_ , InH))
... | Inr (Inr n'<n)
= 1+ap (ctx-decreasing λ {(a , diff∈Γ) →
n#Γ (a , tr
(λ y → (y , a) ∈ ((n' , a') :: Γ))
(m-n+n==m (n<m→1+n≤m n'<n))
(InT diff∈Γ))})
---- contrapositives of some previous theorems ----
lem-neq-apart : {A : Set} {a : A} {n m : Nat} →
n ≠ m →
n # (■ (m , a))
lem-neq-apart n≠m h = n≠m (lem-dom-eq h)
x#Γ→x#Γ+ : {A : Set} {Γ : A ctx} {x x' : Nat} {a' : A} →
x ≠ x' →
x # Γ →
x # (Γ ,, (x' , a'))
x#Γ→x#Γ+ {Γ = Γ} {x} {x'} {a'} x≠x' x#Γ
with ctxindirect (Γ ,, (x' , a')) x
... | Inl (_ , x∈Γ+) = abort (x#Γ (_ , x∈Γ+→x∈Γ x≠x' x∈Γ+))
... | Inr x#Γ+ = x#Γ+
x#Γ+→x#Γ : {A : Set} {Γ : A ctx} {x x' : Nat} {a' : A} →
x # (Γ ,, (x' , a')) →
x # Γ
x#Γ+→x#Γ {Γ = Γ} {x} {x'} {a'} x#Γ+
with ctxindirect Γ x
... | Inr x#Γ = x#Γ
... | Inl (_ , x∈Γ)
with natEQ x x'
... | Inl refl = abort (x#Γ+ (_ , x,a∈Γ,,x,a {Γ = Γ}))
... | Inr x≠x' = abort (x#Γ+ (_ , x∈Γ→x∈Γ+ x≠x' x∈Γ))
lookup-cp-1 : {A : Set} {Γ : A ctx} {x : Nat} →
x # Γ →
Γ ⦃⦃ x ⦄⦄ == None
lookup-cp-1 {Γ = Γ} {x} x#Γ
with lookup-dec Γ x
... | Inl (_ , x∈Γ) = abort (x#Γ (_ , (lookup-cons-1 x∈Γ)))
... | Inr x#'Γ = x#'Γ
lookup-cp-2 : {A : Set} {Γ : A ctx} {x : Nat} →
Γ ⦃⦃ x ⦄⦄ == None →
x # Γ
lookup-cp-2 {Γ = Γ} {x} x#Γ
with ctxindirect Γ x
... | Inl (_ , x∈Γ) = abort (somenotnone ((! (lookup-cons-2 x∈Γ)) · x#Γ))
... | Inr x#'Γ = x#'Γ
---- some definitions ----
merge' : {A : Set} → (A → A → A) → Maybe A → A → A
merge' merge ma1 a2
with ma1
... | None = a2
... | Some a1 = merge a1 a2
union' : {A : Set} → (A → A → A) → A ctx → A ctx → Nat → A ctx
union' merge Γ1 [] _ = Γ1
union' merge Γ1 ((hx , ha) :: Γ2) offset
= union' merge (Γ1 ,, (hx + offset , merge' merge (Γ1 ⦃⦃ hx + offset ⦄⦄) ha)) Γ2 (1+ hx + offset)
union merge Γ1 Γ2 = union' merge Γ1 Γ2 0
---- union theorems ----
lemma-math' : ∀{x x1 n} → x ≠ x1 + (n + 1+ x)
lemma-math' {x} {x1} {n}
rewrite ! (+assc {x1} {n} {1+ x})
| n+1+m==1+n+m {x1 + n} {x}
| +comm {1+ x1 + n} {x}
= n≠n+1+m
lemma-union'-0 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x n : Nat} {a : A} →
(x , a) ∈ Γ1 →
(x , a) ∈ union' m Γ1 Γ2 (n + 1+ x)
lemma-union'-0 {Γ2 = []} x∈Γ1 = x∈Γ1
lemma-union'-0 {Γ2 = (x1 , a1) :: Γ2} {x} {n} x∈Γ1
rewrite ! (+assc {1+ x1} {n} {1+ x})
= lemma-union'-0 {Γ2 = Γ2} {n = 1+ x1 + n} (x∈Γ→x∈Γ+ (lemma-math' {x1 = x1} {n}) x∈Γ1)
lemma-union'-1 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x n : Nat} {a : A} →
(x , a) ∈ Γ1 →
(n≤x : n ≤ x) →
(difference n≤x) # Γ2 →
(x , a) ∈ union' m Γ1 Γ2 n
lemma-union'-1 {Γ2 = []} {x} x∈Γ1 n≤x x-n#Γ2 = x∈Γ1
lemma-union'-1 {m = m} {Γ1} {(x1 , a1) :: Γ2} {x} {n} {a} x∈Γ1 n≤x x-n#Γ2
with <dec x (x1 + n)
lemma-union'-1 {m = m} {Γ1} {(x1 , a1) :: Γ2} {x} {n} {a} x∈Γ1 n≤x x-n#Γ2 | Inl x<x1+n
with Γ1 ⦃⦃ x1 + n ⦄⦄
lemma-union'-1 {m = m} {Γ1} {(x1 , a1) :: Γ2} {x} {n} {a} x∈Γ1 n≤x x-n#Γ2 | Inl x<x1+n | Some a'
= tr
(λ y → (x , a) ∈ union' m (Γ1 ,, (x1 + n , m a' a1)) Γ2 y)
(n+1+m==1+n+m {difference (π1 x<x1+n)} · 1+ap (m-n+n==m (π1 x<x1+n)))
(lemma-union'-0 {Γ2 = Γ2} (x∈Γ→x∈Γ+ (π2 x<x1+n) x∈Γ1))
lemma-union'-1 {m = m} {Γ1} {(x1 , a1) :: Γ2} {x} {n} {a} x∈Γ1 n≤x x-n#Γ2 | Inl x<x1+n | None
= tr
(λ y → (x , a) ∈ union' m (Γ1 ,, (x1 + n , a1)) Γ2 y)
(n+1+m==1+n+m {difference (π1 x<x1+n)} · 1+ap (m-n+n==m (π1 x<x1+n)))
(lemma-union'-0 {Γ2 = Γ2} (x∈Γ→x∈Γ+ (π2 x<x1+n) x∈Γ1))
lemma-union'-1 {m = m} {Γ1} {(x1 , a1) :: Γ2} {x} {n} {a} x∈Γ1 n≤x x-n#Γ2 | Inr (Inl refl)
rewrite +comm {x1} {n} | n+m-n==m n≤x
= abort (x-n#Γ2 (_ , InH))
lemma-union'-1 {m = m} {Γ1} {(x1 , a1) :: Γ2} {x} {n} {a} x∈Γ1 n≤x x-n#Γ2 | Inr (Inr x1+n<x)
rewrite (! (a+b==c→a==c-b (+assc {diff-1 x1+n<x} · m-n+n==m (n<m→1+n≤m x1+n<x)) n≤x))
= lemma-union'-1
(x∈Γ→x∈Γ+ (flip (π2 x1+n<x)) x∈Γ1)
(n<m→1+n≤m x1+n<x)
λ {(_ , x-x1-n∈Γ2) → x-n#Γ2 (_ , InT x-x1-n∈Γ2)}
lemma-union'-2 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x n : Nat} {a : A} →
(x + n) # Γ1 →
(x , a) ∈ Γ2 →
(x + n , a) ∈ union' m Γ1 Γ2 n
lemma-union'-2 {Γ1 = Γ1} x+n#Γ1 (InH {Γ = Γ2})
rewrite lookup-cp-1 x+n#Γ1
= lemma-union'-0 {Γ2 = Γ2} {n = Z} (x,a∈Γ,,x,a {Γ = Γ1})
lemma-union'-2 {Γ1 = Γ1} {n = n} x+n#Γ1 (InT {Γ = Γ2} {x = x} {s} x∈Γ2)
rewrite +assc {x} {1+ s} {n}
with Γ1 ⦃⦃ s + n ⦄⦄
... | Some a'
= lemma-union'-2
(λ {(_ , x∈Γ1+) →
x+n#Γ1 (_ , x∈Γ+→x∈Γ (flip (lemma-math' {x1 = Z})) x∈Γ1+)})
x∈Γ2
... | None
= lemma-union'-2
(λ {(_ , x∈Γ1+) →
x+n#Γ1 (_ , x∈Γ+→x∈Γ (flip (lemma-math' {x1 = Z})) x∈Γ1+)})
x∈Γ2
lemma-union'-3 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x n : Nat} {a1 a2 : A} →
(x + n , a1) ∈ Γ1 →
(x , a2) ∈ Γ2 →
(x + n , m a1 a2) ∈ union' m Γ1 Γ2 n
lemma-union'-3 {Γ1 = Γ1} x+n∈Γ1 (InH {Γ = Γ2})
rewrite lookup-cons-2 x+n∈Γ1
= lemma-union'-0 {Γ2 = Γ2} {n = Z} (x,a∈Γ,,x,a {Γ = Γ1})
lemma-union'-3 {Γ1 = Γ1} {n = n} x+n∈Γ1 (InT {Γ = Γ2} {x = x} {s} x∈Γ2)
rewrite +assc {x} {1+ s} {n}
with Γ1 ⦃⦃ s + n ⦄⦄
... | Some a'
= lemma-union'-3 (x∈Γ→x∈Γ+ (flip (lemma-math' {x1 = Z})) x+n∈Γ1) x∈Γ2
... | None
= lemma-union'-3 (x∈Γ→x∈Γ+ (flip (lemma-math' {x1 = Z})) x+n∈Γ1) x∈Γ2
lemma-union'-4 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x n : Nat} →
dom (union' m Γ1 Γ2 n) x →
dom Γ1 x ∨ (Σ[ s ∈ Nat ] (x == n + s ∧ dom Γ2 s))
lemma-union'-4 {Γ2 = []} x∈un = Inl x∈un
lemma-union'-4 {Γ1 = Γ1} {(x1 , a1) :: Γ2} {x} {n} x∈un
with lemma-union'-4 {Γ2 = Γ2} x∈un
... | Inr (s , refl , _ , s∈Γ2)
rewrite +comm {x1} {n}
| ! (n+1+m==1+n+m {n + x1} {s})
| +assc {n} {x1} {1+ s}
| +comm {x1} {1+ s}
| ! (n+1+m==1+n+m {s} {x1})
= Inr (_ , refl , _ , InT s∈Γ2)
... | Inl (_ , x∈Γ1+)
with natEQ x (n + x1)
... | Inl refl = Inr (_ , refl , _ , InH)
... | Inr x≠n+x1
rewrite +comm {x1} {n}
= Inl (_ , x∈Γ+→x∈Γ x≠n+x1 x∈Γ1+)
x,a∈Γ1→x∉Γ2→x,a∈Γ1∪Γ2 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x : Nat} {a : A} →
(x , a) ∈ Γ1 →
x # Γ2 →
(x , a) ∈ union m Γ1 Γ2
x,a∈Γ1→x∉Γ2→x,a∈Γ1∪Γ2 {Γ2 = Γ2} x∈Γ1 x#Γ2
= lemma-union'-1 x∈Γ1 0≤n (tr (λ y → y # Γ2) (! (n+m-n==m 0≤n)) x#Γ2)
x∉Γ1→x,a∈Γ2→x,a∈Γ1∪Γ2 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x : Nat} {a : A} →
x # Γ1 →
(x , a) ∈ Γ2 →
(x , a) ∈ union m Γ1 Γ2
x∉Γ1→x,a∈Γ2→x,a∈Γ1∪Γ2 {Γ1 = Γ1} {x = x} x#Γ1 x∈Γ2
with lemma-union'-2 {n = Z} (tr (λ y → y # Γ1) (! n+Z==n) x#Γ1) x∈Γ2
... | rslt
rewrite n+Z==n {x}
= rslt
x∈Γ1→x∈Γ2→x∈Γ1∪Γ2 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x : Nat} {a1 a2 : A} →
(x , a1) ∈ Γ1 →
(x , a2) ∈ Γ2 →
(x , m a1 a2) ∈ union m Γ1 Γ2
x∈Γ1→x∈Γ2→x∈Γ1∪Γ2 {Γ1 = Γ1} {Γ2} {x} {a1} x∈Γ1 x∈Γ2
with lemma-union'-3 (tr (λ y → (y , a1) ∈ Γ1) (! n+Z==n) x∈Γ1) x∈Γ2
... | rslt
rewrite n+Z==n {x}
= rslt
x∈Γ1∪Γ2→x∈Γ1∨x∈Γ2 : {A : Set} {m : A → A → A} {Γ1 Γ2 : A ctx} {x : Nat} →
dom (union m Γ1 Γ2) x →
dom Γ1 x ∨ dom Γ2 x
x∈Γ1∪Γ2→x∈Γ1∨x∈Γ2 x∈Γ1∪Γ2
with lemma-union'-4 {n = Z} x∈Γ1∪Γ2
x∈Γ1∪Γ2→x∈Γ1∨x∈Γ2 x∈Γ1∪Γ2 | Inl x'∈Γ1 = Inl x'∈Γ1
x∈Γ1∪Γ2→x∈Γ1∨x∈Γ2 x∈Γ1∪Γ2 | Inr (_ , refl , x'∈Γ2) = Inr x'∈Γ2
---- contraction and exchange ----
-- TODO these proofs could use refactoring -
-- contraction should probably make use of ctx-==-dec and
-- exchange is way too long and repetitive
contraction : {A : Set} {Γ : A ctx} {x : Nat} {a a' : A} →
Γ ,, (x , a') ,, (x , a) == Γ ,, (x , a)
contraction {Γ = []} {x} rewrite <dec-refl x = refl
contraction {Γ = (hx , ha) :: t} {x} {a} {a'}
with <dec x hx
... | Inl _ rewrite <dec-refl x = refl
... | Inr (Inl refl) rewrite <dec-refl hx = refl
... | Inr (Inr hx<x)
with <dec x hx
... | Inl x<hx = abort (<antisym x<hx hx<x)
... | Inr (Inl refl) = abort (<antirefl hx<x)
... | Inr (Inr hx<'x)
rewrite diff-proof-irrelevance (n<m→1+n≤m hx<x) (n<m→1+n≤m hx<'x)
| contraction {Γ = t} {diff-1 hx<'x} {a} {a'}
= refl
exchange : {A : Set} {Γ : A ctx} {x1 x2 : Nat} {a1 a2 : A} →
x1 ≠ x2 →
Γ ,, (x1 , a1) ,, (x2 , a2) == Γ ,, (x2 , a2) ,, (x1 , a1)
exchange {A} {Γ} {x1} {x2} {a1} {a2} x1≠x2
= ctx-==-eqv fun
where
fun : (x : Nat) →
(Γ ,, (x1 , a1) ,, (x2 , a2)) ⦃⦃ x ⦄⦄ ==
(Γ ,, (x2 , a2) ,, (x1 , a1)) ⦃⦃ x ⦄⦄
fun x
with natEQ x x1 | natEQ x x2 | ctxindirect Γ x
fun x | Inl refl | Inl refl | _
= abort (x1≠x2 refl)
fun x1 | Inl refl | Inr x≠x2 | Inl (_ , x1∈Γ)
with x,a∈Γ,,x,a {Γ = Γ} {x1} {a1}
... | x∈Γ+1
with x∈Γ→x∈Γ+ {a' = a2} x≠x2 x∈Γ+1 | x,a∈Γ,,x,a {Γ = Γ ,, (x2 , a2)} {x1} {a1}
... | x∈Γ++1 | x∈Γ++2
rewrite lookup-cons-2 x∈Γ++1 | lookup-cons-2 x∈Γ++2 = refl
fun x1 | Inl refl | Inr x≠x2 | Inr x1#Γ
with x,a∈Γ,,x,a {Γ = Γ} {x1} {a1}
... | x∈Γ+1
with x∈Γ→x∈Γ+ {a' = a2} x≠x2 x∈Γ+1 | x,a∈Γ,,x,a {Γ = Γ ,, (x2 , a2)} {x1} {a1}
... | x∈Γ++1 | x∈Γ++2
rewrite lookup-cons-2 x∈Γ++1 | lookup-cons-2 x∈Γ++2 = refl
fun x2 | Inr x≠x1 | Inl refl | Inl (_ , x2∈Γ)
with x,a∈Γ,,x,a {Γ = Γ} {x2} {a2}
... | x∈Γ+2
with x∈Γ→x∈Γ+ {a' = a1} x≠x1 x∈Γ+2 | x,a∈Γ,,x,a {Γ = Γ ,, (x1 , a1)} {x2} {a2}
... | x∈Γ++1 | x∈Γ++2
rewrite lookup-cons-2 x∈Γ++1 | lookup-cons-2 x∈Γ++2 = refl
fun x2 | Inr x≠x1 | Inl refl | Inr x2#Γ
with x,a∈Γ,,x,a {Γ = Γ} {x2} {a2}
... | x∈Γ+2
with x∈Γ→x∈Γ+ {a' = a1} x≠x1 x∈Γ+2 | x,a∈Γ,,x,a {Γ = Γ ,, (x1 , a1)} {x2} {a2}
... | x∈Γ++1 | x∈Γ++2
rewrite lookup-cons-2 x∈Γ++1 | lookup-cons-2 x∈Γ++2 = refl
fun x | Inr x≠x1 | Inr x≠x2 | Inl (_ , x∈Γ)
with x∈Γ→x∈Γ+ {a' = a1} x≠x1 x∈Γ | x∈Γ→x∈Γ+ {a' = a2} x≠x2 x∈Γ
... | x∈Γ+1 | x∈Γ+2
with x∈Γ→x∈Γ+ {a' = a2} x≠x2 x∈Γ+1 | x∈Γ→x∈Γ+ {a' = a1} x≠x1 x∈Γ+2
... | x∈Γ++1 | x∈Γ++2
rewrite lookup-cons-2 x∈Γ++1 | lookup-cons-2 x∈Γ++2 = refl
fun x | Inr x≠x1 | Inr x≠x2 | Inr x#Γ
with x#Γ→x#Γ+ {a' = a1} x≠x1 x#Γ | x#Γ→x#Γ+ {a' = a2} x≠x2 x#Γ
... | x#Γ+1 | x#Γ+2
with x#Γ→x#Γ+ {a' = a2} x≠x2 x#Γ+1 | x#Γ→x#Γ+ {a' = a1} x≠x1 x#Γ+2
... | x#Γ++1 | x#Γ++2
rewrite lookup-cp-1 x#Γ++1 | lookup-cp-1 x#Γ++2 = refl
---- remaining function definitions ----
list⇒ctx = foldl _,,_ ∅
list⇒list-ctx {A} l
= foldl f ∅ (reverse l)
where
f : (List A) ctx → Nat ∧ A → (List A) ctx
f Γ (n , a)
with ctxindirect Γ n
... | Inl (as , n∈Γ)
= Γ ,, (n , a :: as)
... | Inr n#Γ
= Γ ,, (n , a :: [])
ctx⇒values = map π2
|
{
"alphanum_fraction": 0.4136867832,
"avg_line_length": 39.4,
"ext": "agda",
"hexsha": "f835e7beb35a8276b2c3d427a6f5be202b109789",
"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": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnat-myth-",
"max_forks_repo_path": "contexts.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"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": "hazelgrove/hazelnat-myth-",
"max_issues_repo_path": "contexts.agda",
"max_line_length": 101,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnat-myth-",
"max_stars_repo_path": "contexts.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z",
"num_tokens": 12868,
"size": 26595
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Empty.Base where
open import Cubical.Core.Everything
data ⊥ : Type₀ where
rec : ∀ {ℓ} {A : Type ℓ} → ⊥ → A
rec ()
elim : ∀ {ℓ} {A : ⊥ → Type ℓ} → (x : ⊥) → A x
elim ()
|
{
"alphanum_fraction": 0.5720164609,
"avg_line_length": 18.6923076923,
"ext": "agda",
"hexsha": "43cef061357e8a84fde5deb41f9c263bef3f7bc8",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/Data/Empty/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/Data/Empty/Base.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/Data/Empty/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 91,
"size": 243
}
|
open import Stlc hiding (⟹*-Preorder; _⟹*⟪_⟫_; example₀; example₁)
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; refl)
open import Relation.Binary using (Preorder)
import Relation.Binary.PreorderReasoning as PreorderReasoning
⟹*-Preorder : Preorder _ _ _
⟹*-Preorder = record
{ Carrier = Term
; _≈_ = _≡_
; _∼_ = _⟹*_
; isPreorder = record
{ isEquivalence = P.isEquivalence
; reflexive = λ {refl → ⟨⟩}
; trans = _>>_
}
}
open PreorderReasoning ⟹*-Preorder
using (_IsRelatedTo_; begin_; _∎) renaming (_≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _⟹*⟨_⟩_)
infixr 2 _⟹*⟪_⟫_
_⟹*⟪_⟫_ : ∀ x {y z} → x ⟹ y → y IsRelatedTo z → x IsRelatedTo z
x ⟹*⟪ x⟹y ⟫ yz = x ⟹*⟨ ⟨ x⟹y ⟩ ⟩ yz
example₀ : not · true ⟹* false
example₀ =
begin
not · true
⟹*⟪ β⇒ value-true ⟫
if true then false else true
⟹*⟪ β𝔹₁ ⟫
false
∎
example₁ : I² · I · (not · false) ⟹* true
example₁ =
begin
I² · I · (not · false)
⟹*⟪ γ⇒₁ (β⇒ value-λ) ⟫
(λ[ x ∶ 𝔹 ] I · var x) · (not · false)
⟹*⟪ γ⇒₂ value-λ (β⇒ value-false) ⟫
(λ[ x ∶ 𝔹 ] I · var x) · (if false then false else true)
⟹*⟪ γ⇒₂ value-λ β𝔹₂ ⟫
(λ[ x ∶ 𝔹 ] I · var x) · true
⟹*⟪ β⇒ value-true ⟫
I · true
⟹*⟪ β⇒ value-true ⟫
true
∎
|
{
"alphanum_fraction": 0.5439814815,
"avg_line_length": 25.4117647059,
"ext": "agda",
"hexsha": "beb47e55d7166b67f4def314158c06a700b67447",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "manikdv/plfa.github.io",
"max_forks_repo_path": "extra/extra/Preorder.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "manikdv/plfa.github.io",
"max_issues_repo_path": "extra/extra/Preorder.agda",
"max_line_length": 85,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "manikdv/plfa.github.io",
"max_stars_repo_path": "extra/extra/Preorder.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 597,
"size": 1296
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochIndep
open import Util.Prelude
module LibraBFT.Impl.OBM.Util where
-- To tolerate f failures, cluster must contain at least n ≥ 3f + 1 nodes,
-- where n − f nodes form a quorum, assuming 1 vote per node.
-- Note: our Haskell implementation and our model of it support non-uniform voting power,
-- that is NOT reflected in these functions, but is reflected in functions in ValidatorVerifier.
numNodesNeededForNFailures : U64 -> U64
numNodesNeededForNFailures numFaultsAllowed = 3 * numFaultsAllowed + 1
checkBftAndRun : ∀ {names : Set} {b : Set}
→ U64 → List names → (U64 → List names → b)
→ Either ErrLog b
checkBftAndRun numFailures authors f =
if-dec length authors <? numNodesNeededForNFailures numFailures
then Left fakeErr --(ErrL [ "checkBftAndRun: not enough authors for given number of failures"
-- , show numFailures, show (length authors) ])
else pure (f numFailures authors)
|
{
"alphanum_fraction": 0.7380597015,
"avg_line_length": 44.6666666667,
"ext": "agda",
"hexsha": "043a388613eb1afe6150280f9ffe73ef73487bec",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/OBM/Util.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/OBM/Util.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/OBM/Util.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 360,
"size": 1340
}
|
module Problem1 where
{-
If we list all the natural numbers below 10 that are multiples of 3 or
5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
-}
open import Data.Nat
open import Data.Nat.Divisibility
open import Data.Nat.DivMod
open import Data.Nat.Properties
open import Data.List
open import Data.Sum
open import Function.Nary.NonDependent using (congₙ)
open import Relation.Unary.Properties
open import Relation.Binary.PropositionalEquality
problem′ : ℕ → ℕ
problem′ n = sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo n))
example : ℕ
example = problem′ 10
example-correct : example ≡ 23
example-correct = refl
-- this is actually quick enough but I'm sure we can do better
problem : ℕ
problem = problem′ 1000
module Lemmas where
import Agda.Builtin.Nat
open import Algebra.Definitions
open import Data.Bool using (true; false)
open import Data.Empty
open import Data.List.Properties
open import Data.Nat.LCM
open import Relation.Nullary
open import Relation.Unary
-- first definition of triangle numbers. This is easiest to work with
triangle : ℕ → ℕ
triangle zero = zero
triangle n@(suc x) = n + triangle x
-- second definition of triangle numbers. This looks pretty but sadly ⌊_/2⌋
-- is O(n) so this works out pretty slow in practice
triangle′ : ℕ → ℕ
triangle′ n = ⌊ n * suc n /2⌋
-- Identity to do with adding to half something
+-⌊n/2⌋ : ∀ m n → m + ⌊ n /2⌋ ≡ ⌊ 2 * m + n /2⌋
+-⌊n/2⌋ zero n = refl
+-⌊n/2⌋ (suc m) n = begin
suc (m + ⌊ n /2⌋) ≡⟨ cong suc (+-⌊n/2⌋ m n) ⟩
suc ⌊ 2 * m + n /2⌋ ≡⟨ cong (λ x → suc ⌊ m + x + n /2⌋) (+-identityʳ m) ⟩
⌊ suc (suc m + m) + n /2⌋ ≡˘⟨ cong (λ x → ⌊ suc x + n /2⌋) (+-suc m m) ⟩
⌊ suc (m + suc m + n) /2⌋ ≡˘⟨ cong (λ x → ⌊ suc (m + suc x + n) /2⌋) (+-identityʳ m) ⟩
⌊ 2 * suc m + n /2⌋ ∎
where
open ≡-Reasoning
-- The first two definitions of triangle numbers match!
triangle≗triangle′ : triangle ≗ triangle′
triangle≗triangle′ zero = refl
triangle≗triangle′ (suc x) = begin
triangle (suc x) ≡⟨ cong (suc x +_) (triangle≗triangle′ x) ⟩
suc x + ⌊ x * suc x /2⌋ ≡⟨ +-⌊n/2⌋ (suc x) (x * suc x) ⟩
⌊ 2 * suc x + x * suc x /2⌋ ≡˘⟨ cong ⌊_/2⌋ (*-distribʳ-+ (suc x) 2 x) ⟩
⌊ (2 + x) * suc x /2⌋ ≡⟨ cong ⌊_/2⌋ (*-comm (2 + x) _) ⟩
triangle′ (suc x) ∎
where
open ≡-Reasoning
-- the third and final definition of triangle numbers
-- This uses builtin division under the hood which gets compiled to proper
-- division operators (I think ultimately GMP integer division) so it's fast
triangle″ : ℕ → ℕ
triangle″ n = n * suc n / 2
-- halfing is the same as dividing by 2, as you might expect
//2 : ∀ n → ⌊ n /2⌋ ≡ n / 2
//2 zero = refl
//2 (suc zero) = refl
//2 (suc (suc n)) = begin
suc ⌊ n /2⌋ ≡⟨ cong suc (//2 n) ⟩
suc (n / 2) ≡˘⟨ +-distrib-/ 2 n (m%n<n n 1) ⟩
suc (suc n) / 2 ∎
where
open ≡-Reasoning
-- the second and third definitions of triangle numbers also match!
triangle′≗triangle″ : triangle′ ≗ triangle″
triangle′≗triangle″ n = //2 _
-- and so the first and thirdd definitions match
triangle≗triangle″ : triangle ≗ triangle″
triangle≗triangle″ x = trans (triangle≗triangle′ x) (triangle′≗triangle″ x)
-- if we're almost done dividing, we're not going to change the answer
foo : ∀ {k m n j} → n ≤ j → Agda.Builtin.Nat.div-helper k m n j ≡ k
foo z≤n = refl
foo (s≤s p) = foo p
-- dividing a small number by a big one gets 0
m<n⇒m/n≡0 : ∀ {m n n≢0} → m < n → (m / n) {n≢0} ≡ 0
m<n⇒m/n≡0 (s≤s p) = foo p
-- if i divides both m and n then it divides their difference
∣m∣n⇒∣m∸n : ∀ {i m n} → i ∣ m → i ∣ n → i ∣ m ∸ n
∣m∣n⇒∣m∸n (divides p refl) (divides q refl) = divides (p ∸ q) (sym (*-distribʳ-∸ _ p q))
lemma : {x d : ℕ} → suc d ∣ suc x → suc x / suc d ≡ suc (x / suc d)
lemma {x} {zero} p = begin
suc x / 1 ≡⟨ n/1≡n (suc x) ⟩
suc x ≡˘⟨ cong suc (n/1≡n x) ⟩
suc (x / 1) ∎
where
open ≡-Reasoning
lemma {x} {suc d} (divides (suc q) p) = begin
suc x / suc (suc d) ≡⟨ cong (_/ suc (suc d)) p ⟩
suc q * suc (suc d) / suc (suc d) ≡⟨ m*n/n≡m (suc q) (suc (suc d)) ⟩
suc q ≡˘⟨ cong suc (m*n/n≡m q (suc (suc d))) ⟩
suc (q * suc (suc d) / suc (suc d)) ≡⟨⟩
suc ((suc q ∸ 1) * suc (suc d) / suc (suc d)) ≡⟨ cong (λ x → suc (x / suc (suc d))) (*-distribʳ-∸ (suc (suc d)) (suc q) 1) ⟩
suc ((suc q * suc (suc d) ∸ 1 * suc (suc d)) / suc (suc d)) ≡⟨ cong (λ x → suc ((suc q * suc (suc d) ∸ x) / suc (suc d))) (*-identityˡ (suc (suc d))) ⟩
suc ((suc q * suc (suc d) ∸ suc (suc d)) / suc (suc d)) ≡˘⟨ cong (λ x → suc ((x ∸ suc (suc d)) / suc (suc d))) p ⟩
suc (0 + (x ∸ suc d) / suc (suc d)) ≡˘⟨ cong (λ n → suc (n + (x ∸ suc d) / suc (suc d))) (m<n⇒m/n≡0 (n<1+n (suc d))) ⟩
suc (suc d / suc (suc d) + (x ∸ suc d) / suc (suc d)) ≡˘⟨ cong suc (+-distrib-/-∣ʳ {suc d} (x ∸ suc d) (∣m∣n⇒∣m∸n (divides (suc q) p) ∣-refl)) ⟩
suc ((suc d + (x ∸ suc d)) / suc (suc d)) ≡˘⟨ cong (λ x → suc (x / suc (suc d))) (+-∸-assoc (suc d) (+-cancelˡ-≤ 1 (≤-trans (≤-trans (≤-reflexive (sym (*-identityˡ (suc (suc d))))) (*-monoˡ-≤ (suc (suc d)) (s≤s {n = q} z≤n))) (≤-reflexive (sym p)))))⟩
suc (((suc d + x) ∸ suc d) / suc (suc d)) ≡⟨ cong (λ x → suc (x / suc (suc d))) (m+n∸m≡n (suc d) x) ⟩
suc (x / suc (suc d)) ∎
where
open ≡-Reasoning
bar : ∀ {x d} → ¬ (suc (suc d) ∣ suc x) → x % suc (suc d) ≤ d
bar {x} {d} ¬p with suc x % suc (suc d) | inspect (λ a → a % suc (suc d)) (suc x)
... | zero | [ p ] = ⊥-elim (¬p (m%n≡0⇒n∣m (suc x) (suc d) p))
... | suc n | [ p ] = [1+m%d]≤1+n⇒[m%d]≤n x d (suc (suc d)) (≤-trans (s≤s z≤n) (≤-reflexive (sym p))) (+-cancelˡ-≤ 1 (m%n<n (suc x) (suc d)))
lemma₂ : {x d : ℕ} → ¬ (suc d ∣ suc x) → suc x / suc d ≡ x / suc d
lemma₂ {x} {zero} ¬p = ⊥-elim (¬p (1∣ suc x))
lemma₂ {x} {suc d} ¬p with suc x % suc (suc d) | inspect (λ a → a % suc (suc d)) (suc x)
... | zero | [ p ] = ⊥-elim (¬p (m%n≡0⇒n∣m _ _ p))
... | suc n | [ p ] = +-distrib-/ 1 x (+-monoʳ-≤ 2 (bar ¬p))
prop : ∀ d l → suc d * triangle (l / suc d) ≡ sum (filter (suc d ∣?_) (downFrom (suc l)))
prop d zero = *-zeroʳ d
prop d (suc l) with suc d ∣? suc l
... | true because ofʸ p = begin
suc d * triangle (suc l / suc d) ≡⟨ cong (λ x → suc d * triangle x) (lemma p) ⟩
suc d * triangle (suc (l / suc d)) ≡⟨ *-distribˡ-+ (suc d) (suc (l / suc d)) (triangle (l / suc d)) ⟩
suc d * (suc (l / suc d)) + suc d * triangle (l / suc d) ≡˘⟨ cong (λ x → suc d * x + suc d * triangle (l / suc d)) (lemma p) ⟩
suc d * (suc l / suc d) + suc d * triangle (l / suc d) ≡⟨ cong (_+ suc d * triangle (l / suc d)) (m*[n/m]≡n p) ⟩
suc l + suc d * triangle (l / suc d) ≡⟨ cong (suc l +_) (prop d l) ⟩
sum (suc l ∷ filter (suc d ∣?_) (downFrom (suc l))) ≡˘⟨ cong sum (filter-accept (suc d ∣?_) p) ⟩
sum (filter (suc d ∣?_) (suc l ∷ downFrom (suc l))) ∎
where
open ≡-Reasoning
... | false because ofⁿ ¬p = begin
suc d * triangle (suc l / suc d) ≡⟨ cong (λ n → suc d * triangle n) (lemma₂ ¬p) ⟩
suc d * triangle (l / suc d) ≡⟨ prop d l ⟩
sum (filter (suc d ∣?_) (downFrom (suc l))) ≡˘⟨ cong sum (filter-reject (suc d ∣?_) ¬p) ⟩
sum (filter (suc d ∣?_) (suc l ∷ downFrom (suc l))) ∎
where
open ≡-Reasoning
notLemmaAux : ∀ {A : Set} (∙ : A → A → A) (ε : A) (comm : Commutative _≡_ ∙) (assoc : Associative _≡_ ∙) (n : A) (ns : List A) → foldr ∙ ε (n ∷ ns) ≡ foldr ∙ (∙ n ε) ns
notLemmaAux _∙_ ε comm assoc n [] = refl
notLemmaAux _∙_ ε comm assoc n (m ∷ ns) = begin
n ∙ (m ∙ foldr _∙_ ε ns) ≡˘⟨ assoc n m _ ⟩
(n ∙ m) ∙ foldr _∙_ ε ns ≡⟨ cong (_∙ foldr _∙_ ε ns) (comm n m) ⟩
(m ∙ n) ∙ foldr _∙_ ε ns ≡⟨ assoc m n _ ⟩
m ∙ (n ∙ foldr _∙_ ε ns) ≡⟨ cong (m ∙_) (notLemmaAux _∙_ ε comm assoc n ns) ⟩
m ∙ foldr _∙_ (n ∙ ε) ns ∎
where
open ≡-Reasoning
foldr-downFrom-insert : ∀ {A : Set} (_∙_ : A → A → A) (ε : A) (f : ℕ → A) (n : ℕ) → foldr _∙_ (f zero ∙ ε) (applyDownFrom (λ x → f (suc x)) n) ≡ foldr _∙_ ε (applyDownFrom f (suc n))
foldr-downFrom-insert _∙_ ε f zero = refl
foldr-downFrom-insert _∙_ ε f (suc n) = cong (f (suc n) ∙_) (foldr-downFrom-insert _∙_ ε f n)
notLemmaFilterAuxⁿ : ∀ {A : Set} (∙ : A → A → A) (ε : A) {p} {P : Pred A p} (P? : Decidable P) (f : ℕ → A) (n : ℕ) → ¬ P (f 0) → foldr ∙ ε (filter P? (applyDownFrom (λ x → f (suc x)) n)) ≡ foldr ∙ ε (filter P? (applyDownFrom f (suc n)))
notLemmaFilterAuxⁿ ∙ ε P? f zero ¬p = cong (foldr ∙ ε) (sym (filter-reject P? ¬p))
notLemmaFilterAuxⁿ ∙ ε P? f (suc n) ¬p with does (P? (f (suc n)))
... | false = notLemmaFilterAuxⁿ ∙ ε P? f n ¬p
... | true = cong (∙ (f (suc n))) (notLemmaFilterAuxⁿ ∙ ε P? f n ¬p)
foldr-filter-downFrom-insert : ∀ {A : Set} (_∙_ : A → A → A) (ε : A) {p} {P : Pred A p} (P? : Decidable P) (f : ℕ → A) (n : ℕ) → P (f zero) → foldr _∙_ (f zero ∙ ε) (filter P? (applyDownFrom (λ x → f (suc x)) n)) ≡ foldr _∙_ ε (filter P? (applyDownFrom f (suc n)))
foldr-filter-downFrom-insert _∙_ ε P? f zero p = begin
f zero ∙ ε ≡˘⟨ cong (foldr _∙_ ε) (filter-accept P? p) ⟩
foldr _∙_ ε (filter P? (f zero ∷ [])) ∎
where
open ≡-Reasoning
foldr-filter-downFrom-insert _∙_ ε P? f (suc n) p with does (P? (f (suc n)))
... | true = cong (f (suc n) ∙_) (foldr-filter-downFrom-insert _∙_ ε P? f n p)
... | false = foldr-filter-downFrom-insert _∙_ ε P? f n p
notLemmaFilter : ∀ {A : Set} (∙ : A → A → A) (ε : A) (comm : Commutative _≡_ ∙) (assoc : Associative _≡_ ∙) {p} {P : Pred A p} (P? : Decidable P) (f : ℕ → A) (n : ℕ) → foldr ∙ ε (filter P? (applyUpTo f n)) ≡ foldr ∙ ε (filter P? (applyDownFrom f n))
notLemmaFilter ∙ ε comm assoc P? f zero = refl
notLemmaFilter ∙ ε comm assoc P? f (suc n) with P? (f zero)
... | false because ofⁿ ¬p = begin
foldr ∙ ε (filter P? (applyUpTo (λ x → f (suc x)) n)) ≡⟨ notLemmaFilter ∙ ε comm assoc P? (λ x → f (suc x)) n ⟩
foldr ∙ ε (filter P? (applyDownFrom (λ x → f (suc x)) n)) ≡⟨ notLemmaFilterAuxⁿ ∙ ε P? f n ¬p ⟩
foldr ∙ ε (filter P? (applyDownFrom f (suc n))) ∎
where
open ≡-Reasoning
... | true because ofʸ p = begin
∙ (f zero) (foldr ∙ ε (filter P? (applyUpTo (λ x → f (suc x)) n))) ≡⟨ notLemmaAux ∙ ε comm assoc (f zero) (filter P? (applyUpTo (λ x → f (suc x)) n)) ⟩
foldr ∙ (∙ (f zero) (ε)) (filter P? (applyUpTo (λ x → f (suc x)) n)) ≡⟨ notLemmaFilter ∙ (∙ (f zero) ε) comm assoc P? (λ x → f (suc x)) n ⟩
foldr ∙ (∙ (f zero) (ε)) (filter P? (applyDownFrom (λ x → f (suc x)) n)) ≡⟨ foldr-filter-downFrom-insert ∙ ε P? f n p ⟩
foldr ∙ ε (filter P? (applyDownFrom f (suc n))) ∎
where
open ≡-Reasoning
prop′ : ∀ d l → suc d * triangle″ (l / suc d) ≡ sum (filter (suc d ∣?_) (upTo (suc l)))
prop′ d l = begin
suc d * triangle″ (l / suc d) ≡˘⟨ cong (λ x → suc d * x) (triangle≗triangle″ (l / suc d)) ⟩
suc d * triangle (l / suc d) ≡⟨ prop d l ⟩
sum (filter (suc d ∣?_) (downFrom (suc l))) ≡˘⟨ notLemmaFilter _+_ 0 +-comm +-assoc (suc d ∣?_) (λ x → x) (suc l) ⟩
sum (filter (suc d ∣?_) (upTo (suc l))) ∎
where
open ≡-Reasoning
recombine-divisors : ∀ d d′ xs → sum (filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs) ≡ sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)
recombine-divisors d d′ [] = refl
recombine-divisors d d′ (x ∷ xs) with suc d ∣? x | suc d′ ∣? x
... | .true because ofʸ p | .true because ofʸ q = begin
sum (filter (suc d ∣?_) (x ∷ xs)) + sum (filter (suc d′ ∣?_) (x ∷ xs)) ≡⟨ cong₂ (λ x y → sum x + sum y) (filter-accept (suc d ∣?_) p) (filter-accept (suc d′ ∣?_) q) ⟩
sum (x ∷ filter (suc d ∣?_) xs) + sum (x ∷ filter (suc d′ ∣?_) xs) ≡⟨⟩
(x + sum (filter (suc d ∣?_) xs)) + (x + sum (filter (suc d′ ∣?_) xs)) ≡⟨ +-assoc x (sum (filter (suc d ∣?_) xs)) _ ⟩
x + (sum (filter (suc d ∣?_) xs) + (x + sum (filter (suc d′ ∣?_) xs))) ≡˘⟨ cong (x +_) (+-assoc (sum (filter (suc d ∣?_) xs)) x _) ⟩
x + ((sum (filter (suc d ∣?_) xs) + x) + sum (filter (suc d′ ∣?_) xs)) ≡⟨ cong (λ n → x + (n + sum (filter (suc d′ ∣?_) xs))) (+-comm _ x) ⟩
x + ((x + sum (filter (suc d ∣?_) xs)) + sum (filter (suc d′ ∣?_) xs)) ≡⟨ cong (x +_) (+-assoc x (sum (filter (suc d ∣?_) xs)) _) ⟩
x + (x + (sum (filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs))) ≡˘⟨ +-assoc x x _ ⟩
(x + x) + (sum (filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs)) ≡⟨ cong ((x + x) +_) (recombine-divisors d d′ xs) ⟩
(x + x) + (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)) ≡⟨ +-assoc x x _ ⟩
x + (x + (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs))) ≡˘⟨ cong (x +_) (+-assoc x (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) _) ⟩
x + ((x + sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)) ≡⟨ cong (λ n → x + (n + sum (filter (lcm (suc d) (suc d′) ∣?_) xs))) (+-comm x _) ⟩
x + ((sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + x) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)) ≡⟨ cong (x +_) (+-assoc (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) x _) ⟩
x + (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + (x + sum (filter (lcm (suc d) (suc d′) ∣?_) xs))) ≡˘⟨ +-assoc x (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) _ ⟩
(x + sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) + (x + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)) ≡⟨⟩
sum (x ∷ filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (x ∷ filter (lcm (suc d) (suc d′) ∣?_) xs) ≡˘⟨ cong₂ (λ x y → sum x + sum y) (filter-accept ((suc d ∣?_) ∪? (suc d′ ∣?_)) (inj₁ p)) (filter-accept (lcm (suc d) (suc d′) ∣?_) (lcm-least p q))⟩
sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) (x ∷ xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) (x ∷ xs)) ∎
where
open ≡-Reasoning
... | .true because ofʸ p | .false because ofⁿ ¬q = begin
sum (filter (suc d ∣?_) (x ∷ xs)) + sum (filter (suc d′ ∣?_) (x ∷ xs)) ≡⟨ cong₂ (λ x y → sum x + sum y) (filter-accept (suc d ∣?_) p) (filter-reject (suc d′ ∣?_) ¬q) ⟩
sum (x ∷ filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs) ≡⟨ +-assoc x (sum (filter (suc d ∣?_) xs)) _ ⟩
x + (sum (filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs)) ≡⟨ cong (x +_) (recombine-divisors d d′ xs) ⟩
x + (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)) ≡˘⟨ +-assoc x (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) _ ⟩
(x + sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs) ≡˘⟨ cong₂ (λ x y → sum x + sum y) (filter-accept ((suc d ∣?_) ∪? (suc d′ ∣?_)) (inj₁ p)) (filter-reject (lcm (suc d) (suc d′) ∣?_) (λ r → ¬q (∣-trans (n∣lcm[m,n] (suc d) (suc d′)) r))) ⟩
sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) (x ∷ xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) (x ∷ xs)) ∎
where
open ≡-Reasoning
... | .false because ofⁿ ¬p | .true because ofʸ q = begin
sum (filter (suc d ∣?_) (x ∷ xs)) + sum (filter (suc d′ ∣?_) (x ∷ xs)) ≡⟨ cong₂ (λ x y → sum x + sum y) (filter-reject (suc d ∣?_) ¬p) (filter-accept (suc d′ ∣?_) q) ⟩
sum (filter (suc d ∣?_) xs) + sum (x ∷ filter (suc d′ ∣?_) xs) ≡˘⟨ +-assoc (sum (filter (suc d ∣?_) xs)) x _ ⟩
(sum (filter (suc d ∣?_) xs) + x) + sum (filter (suc d′ ∣?_) xs) ≡⟨ cong (_+ sum (filter (suc d′ ∣?_) xs)) (+-comm _ x) ⟩
(x + sum (filter (suc d ∣?_) xs)) + sum (filter (suc d′ ∣?_) xs) ≡⟨ +-assoc x (sum (filter (suc d ∣?_) xs)) _ ⟩
x + (sum (filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs)) ≡⟨ cong (x +_) (recombine-divisors d d′ xs) ⟩
x + (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs)) ≡˘⟨ +-assoc x (sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) _ ⟩
(x + sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs) ≡˘⟨ cong₂ (λ x y → sum x + sum y) (filter-accept ((suc d ∣?_) ∪? (suc d′ ∣?_)) (inj₂ q)) (filter-reject (lcm (suc d) (suc d′) ∣?_) λ r → ¬p (∣-trans (m∣lcm[m,n] (suc d) (suc d′)) r)) ⟩
sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) (x ∷ xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) (x ∷ xs)) ∎
where
open ≡-Reasoning
... | .false because ofⁿ ¬p | .false because ofⁿ ¬q = begin
sum (filter (suc d ∣?_) (x ∷ xs)) + sum (filter (suc d′ ∣?_) (x ∷ xs)) ≡⟨ cong₂ (λ x y → sum x + sum y) (filter-reject (suc d ∣?_) ¬p) (filter-reject (suc d′ ∣?_) ¬q) ⟩
sum (filter (suc d ∣?_) xs) + sum (filter (suc d′ ∣?_) xs) ≡⟨ recombine-divisors d d′ xs ⟩
sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) xs) + sum (filter (lcm (suc d) (suc d′) ∣?_) xs) ≡˘⟨ cong₂ (λ x y → sum x + sum y) (filter-reject ((suc d ∣?_) ∪? (suc d′ ∣?_)) [ ¬p , ¬q ]) (filter-reject (lcm (suc d) (suc d′) ∣?_) (λ r → ¬p (∣-trans (m∣lcm[m,n] (suc d) (suc d′)) r))) ⟩
sum (filter ((suc d ∣?_) ∪? (suc d′ ∣?_)) (x ∷ xs)) + sum (filter (lcm (suc d) (suc d′) ∣?_) (x ∷ xs)) ∎
where
open ≡-Reasoning
solution′ : ℕ → ℕ
solution′ zero = zero
solution′ (suc n) = 3 * Lemmas.triangle″ (n / 3) + 5 * Lemmas.triangle″ (n / 5) ∸ 15 * Lemmas.triangle″ (n / 15)
solution-correct : problem′ ≗ solution′
solution-correct zero = refl
solution-correct (suc n) = begin
sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo (suc n))) ≡˘⟨ +-identityʳ _ ⟩
sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo (suc n))) + 0 ≡˘⟨ cong (sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo (suc n))) +_) (n∸n≡0 (sum (filter (15 ∣?_) (upTo (suc n))))) ⟩
sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo (suc n))) + (sum (filter (15 ∣?_) (upTo (suc n))) ∸ sum (filter (15 ∣?_) (upTo (suc n)))) ≡˘⟨ +-∸-assoc (sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo (suc n)))) {sum (filter (15 ∣?_) (upTo (suc n)))} ≤-refl ⟩
(sum (filter ((3 ∣?_) ∪? (5 ∣?_)) (upTo (suc n))) + sum (filter (15 ∣?_) (upTo (suc n)))) ∸ sum (filter (15 ∣?_) (upTo (suc n))) ≡˘⟨ cong (_∸ sum (filter (15 ∣?_) (upTo (suc n)))) (Lemmas.recombine-divisors 2 4 (upTo (suc n))) ⟩
(sum (filter (3 ∣?_) (upTo (suc n))) + sum (filter (5 ∣?_) (upTo (suc n)))) ∸ sum (filter (15 ∣?_) (upTo (suc n))) ≡˘⟨ congₙ 3 (λ x y z → x + y ∸ z) (Lemmas.prop′ 2 n) (Lemmas.prop′ 4 n) (Lemmas.prop′ 14 n) ⟩
(3 * Lemmas.triangle″ (n / 3) + 5 * Lemmas.triangle″ (n / 5)) ∸ 15 * Lemmas.triangle″ (n / 15) ∎
where
open ≡-Reasoning
solution : ℕ
solution = solution′ 1000
-- output the solution
open import Data.Nat.Show
open import IO
import IO.Primitive as Prim
main : Prim.IO _
main = run (putStrLn (show solution))
|
{
"alphanum_fraction": 0.5117905781,
"avg_line_length": 61.2694805195,
"ext": "agda",
"hexsha": "6e7cf4b989edb83c340de1fc57b41be7c65d5d90",
"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": "a79ee0ec6de898320a38008bf786714ad551f36e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/project-euler",
"max_forks_repo_path": "Problem1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a79ee0ec6de898320a38008bf786714ad551f36e",
"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": "Taneb/project-euler",
"max_issues_repo_path": "Problem1.agda",
"max_line_length": 287,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "a79ee0ec6de898320a38008bf786714ad551f36e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/project-euler",
"max_stars_repo_path": "Problem1.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-21T17:13:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-02T19:18:26.000Z",
"num_tokens": 8791,
"size": 18871
}
|
-- {-# OPTIONS -v tc.cover.splittree:10 -v tc.cc:30 #-}
module Issue829 where
record ⊤ : Set where
constructor tt
data ⊥ : Set where
postulate
P : ⊥ → Set
data D : (A : Set) → A → Set where
c : ⊥ → (x : ⊤) → D ⊤ x
f : {A : Set} {x : A} → D A x → ⊥
f (c () .tt)
g : (x : ⊥) → P x
g ()
h : (A : Set) (x : A) (d : D A x) → P (f d)
h .⊤ tt (c x .tt) = g x
-- Bug.agda:21,21-24
-- Incomplete pattern matching when applying Bug.f
-- when checking that the expression g x has type P (f (c x tt))
-- Agda 2.3.2 gives the following more reasonable error message:
--
-- Bug.agda:21,21-24
-- x != f (c x tt) of type ⊥
-- when checking that the expression g x has type P (f (c x tt))
-- This regression is caused by the patch "Fixed issue 827 : incomplete
-- case tree caused by record pattern translation".
|
{
"alphanum_fraction": 0.5904059041,
"avg_line_length": 22.5833333333,
"ext": "agda",
"hexsha": "a0e67bbd192bb558320ca44429fd85a6d2353867",
"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/Issue829.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/Issue829.agda",
"max_line_length": 72,
"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/Issue829.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": 295,
"size": 813
}
|
--
-- Created by Dependently-Typed Lambda Calculus on 2019-05-15
-- one-linear-layout
-- Author: ice10
--
{-# OPTIONS --without-K --safe #-}
import Relation.Binary
variable A : Set
private variable B : Set
|
{
"alphanum_fraction": 0.6971153846,
"avg_line_length": 17.3333333333,
"ext": "agda",
"hexsha": "86c9e3d9e7deaebef252109fa57ddf24b816d2b2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-03-12T21:33:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-07T01:38:12.000Z",
"max_forks_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "dubinsky/intellij-dtlc",
"max_forks_repo_path": "testData/parse/agda/one-linear-layout.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_issues_repo_issues_event_max_datetime": "2021-03-15T17:04:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-30T04:29:32.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "dubinsky/intellij-dtlc",
"max_issues_repo_path": "testData/parse/agda/one-linear-layout.agda",
"max_line_length": 61,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "dubinsky/intellij-dtlc",
"max_stars_repo_path": "testData/parse/agda/one-linear-layout.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-29T13:18:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-11T16:26:38.000Z",
"num_tokens": 55,
"size": 208
}
|
module Data.Num.Continuous where
open import Data.Num.Core
open import Data.Num.Maximum
open import Data.Num.Bounded
open import Data.Num.Next
open import Data.Num.Increment
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Fin as Fin
using (Fin; fromℕ≤; inject≤)
renaming (zero to z; suc to s)
open import Data.Fin.Properties using (toℕ-fromℕ≤; bounded)
open import Data.Product
open import Function
open import Relation.Nullary.Decidable
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
------------------------------------------------------------------------
Continuous : ∀ b d o → Set
Continuous b d o = (xs : Numeral b d o) → Incrementable xs
Bounded⇒¬Continuous : ∀ {b d o}
→ Bounded b d o
→ ¬ (Continuous b d o)
Bounded⇒¬Continuous (xs , max) claim = contradiction (claim xs) (Maximum⇒¬Incrementable xs max)
first-endpoint : ∀ b d o → Numeral (suc b) (suc d) o
first-endpoint b d o = greatest-digit d ∙
first-endpoint-¬Incrementable : ∀ {b d o}
→ (proper : 2 ≤ suc (d + o))
→ (gapped : Gapped#0 b d o)
→ ¬ (Incrementable (first-endpoint b d o))
first-endpoint-¬Incrementable {b} {d} {o} proper gapped with nextView (first-endpoint b d o) proper
first-endpoint-¬Incrementable proper gapped | Interval b d o ¬greatest
= contradiction (greatest-digit-is-the-Greatest d) ¬greatest
first-endpoint-¬Incrementable proper gapped | GappedEndpoint b d o greatest _
= GappedEndpoint⇒¬Incrementable (first-endpoint b d o) greatest proper gapped
first-endpoint-¬Incrementable proper gapped | UngappedEndpoint b d o greatest ¬gapped
= contradiction gapped ¬gapped
Gapped#0⇒¬Continuous : ∀ {b d o}
→ (proper : 2 ≤ suc (d + o))
→ (gapped : Gapped#0 b d o)
→ ¬ (Continuous (suc b) (suc d) o)
Gapped#0⇒¬Continuous {b} {d} {o} proper gapped#0 cont
= contradiction
(cont (first-endpoint b d o))
(first-endpoint-¬Incrementable proper gapped#0)
¬Gapped#0⇒Continuous : ∀ {b d o}
→ (proper : 2 ≤ suc (d + o))
→ (¬gapped : ¬ (Gapped#0 b d o))
→ Continuous (suc b) (suc d) o
¬Gapped#0⇒Continuous proper ¬gapped#0 xs with Incrementable? xs
¬Gapped#0⇒Continuous proper ¬gapped#0 xs | yes incr = incr
¬Gapped#0⇒Continuous proper ¬gapped#0 xs | no ¬incr = contradiction
(¬Gapped⇒Incrementable xs proper (¬Gapped#0⇒¬Gapped xs proper ¬gapped#0))
¬incr
Continuous-Proper : ∀ b d o
→ (proper : 2 ≤ suc (d + o))
→ Dec (Continuous (suc b) (suc d) o)
Continuous-Proper b d o proper with Gapped#0? b d o
Continuous-Proper b d o proper | yes gapped#0 = no (Gapped#0⇒¬Continuous proper gapped#0)
Continuous-Proper b d o proper | no ¬gapped#0 = yes (¬Gapped#0⇒Continuous proper ¬gapped#0)
Continuous? : ∀ b d o → Dec (Continuous b d o)
Continuous? b d o with numView b d o
Continuous? _ _ _ | NullBase d o = no (Bounded⇒¬Continuous (Bounded-NullBase d o))
Continuous? _ _ _ | NoDigits b o = yes (λ xs → NoDigits-explode xs)
Continuous? _ _ _ | AllZeros b = no (Bounded⇒¬Continuous (Bounded-AllZeros b))
Continuous? _ _ _ | Proper b d o proper = Continuous-Proper b d o proper
-- Continuous⇒¬Gapped#0 : ∀ {b d o}
-- → (cont : True (Continuous? (suc b) (suc d) o))
-- → (proper : suc d + o ≥ 2)
-- → ¬ (Gapped#0 b d o)
-- Continuous⇒¬Gapped#0 cont proper gapped#0 = contradiction (toWitness cont) (Gapped#0⇒¬Continuous proper gapped#0)
-- -- a partial function that only maps ℕ to Continuous Nums
-- fromℕ : ∀ {b d o}
-- → (True (Continuous? b (suc d) o))
-- → (val : ℕ)
-- → (True (o ≤? val))
-- → Numeral b (suc d) o
-- fromℕ {o = zero} cont zero o≤n = z ∙
-- fromℕ {o = zero} cont (suc n) o≤n = 1+ cont (fromℕ cont n tt)
-- fromℕ {o = suc o} cont zero ()
-- fromℕ {o = suc o} cont (suc n) o≤n with o ≟ n
-- fromℕ {b} {d} {suc o} cont (suc n) o≤n | yes o≡n = z ∙
-- fromℕ {b} {d} {suc o} cont (suc n) o≤n | no o≢n = 1+ cont (fromℕ cont n (fromWitness o<n))
-- where
-- o<n : o < n
-- o<n = ≤∧≢⇒< (≤-pred (toWitness o≤n)) o≢n
1+ : ∀ {b d o}
→ {cont : True (Continuous? b d o)}
→ (xs : Numeral b d o)
→ Numeral b d o
1+ {cont = cont} xs = proj₁ (toWitness cont xs)
1+-toℕ : ∀ {b d o}
→ {cont : True (Continuous? b d o)}
→ (xs : Numeral b d o)
→ ⟦ 1+ {cont = cont} xs ⟧ ≡ suc ⟦ xs ⟧
1+-toℕ {cont = cont} xs = proj₂ (toWitness cont xs)
|
{
"alphanum_fraction": 0.6417974629,
"avg_line_length": 37.8130081301,
"ext": "agda",
"hexsha": "d64533c22c21dcf33194194c26f06068ec7bd0d5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Continuous.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Continuous.agda",
"max_line_length": 116,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Continuous.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": 1628,
"size": 4651
}
|
module FFI.Data.HaskellString where
open import Agda.Builtin.String using (String)
{-# FOREIGN GHC import qualified Data.String #-}
{-# FOREIGN GHC import qualified Data.Text #-}
postulate HaskellString : Set
{-# COMPILE GHC HaskellString = type Data.String.String #-}
postulate pack : HaskellString → String
{-# COMPILE GHC pack = Data.Text.pack #-}
postulate unpack : String → HaskellString
{-# COMPILE GHC unpack = Data.Text.unpack #-}
|
{
"alphanum_fraction": 0.7348314607,
"avg_line_length": 26.1764705882,
"ext": "agda",
"hexsha": "cb4ace3702e716f4ae3a0ff907f09dad7f8b415b",
"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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/FFI/Data/HaskellString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"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": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/FFI/Data/HaskellString.agda",
"max_line_length": 59,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/FFI/Data/HaskellString.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 93,
"size": 445
}
|
------------------------------------------------------------------------
-- Definitions of functions that generate list
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --exact-split #-}
module Math.Combinatorics.ListFunction where
open import Data.List
open import Data.List.NonEmpty as NE using (List⁺)
open import Data.Nat
open import Data.Product as Prod using (_×_; _,_)
open import Function
open import Relation.Binary.PropositionalEquality hiding ([_])
module _ {a} {A : Set a} where
-- applyEach (_+ 10) (upTo 3)
-- >>> (10 ∷ 1 ∷ 2 ∷ []) ∷ (0 ∷ 11 ∷ 2 ∷ []) ∷ (0 ∷ 1 ∷ 12 ∷ []) ∷ []
applyEach : (A → A) → List A → List (List A)
applyEach f [] = []
applyEach f (x ∷ xs) = (f x ∷ xs) ∷ map (x ∷_) (applyEach f xs)
module _ {a} {A : Set a} where
-- Combinations
-- combinations 2 (upTo 3)
-- >>> (0 ∷ 1 ∷ []) ∷ (0 ∷ 2 ∷ []) ∷
-- >>> (0 ∷ 3 ∷ []) ∷ (1 ∷ 2 ∷ []) ∷ (1 ∷ 3 ∷ []) ∷ (2 ∷ 3 ∷ []) ∷ []
combinations : ℕ → List A → List (List A)
combinations 0 xs = [ [] ]
combinations (suc k) [] = []
combinations (suc k) (x ∷ xs) =
map (x ∷_) (combinations k xs) ++ combinations (suc k) xs
-- combinationsWithComplement 2 (upTo 2)
-- >>> (0 ∷ 1 ∷ [] , 2 ∷ []) ∷
-- >>> (0 ∷ 2 ∷ [] , 1 ∷ []) ∷ (1 ∷ 2 ∷ [] , 0 ∷ []) ∷ []
combinationsWithComplement : ℕ → List A → List (List A × List A)
combinationsWithComplement 0 xs = [ [] , xs ]
combinationsWithComplement (suc k) [] = []
combinationsWithComplement (suc k) (x ∷ xs) =
map (Prod.map₁ (x ∷_)) (combinationsWithComplement k xs) ++
map (Prod.map₂ (x ∷_)) (combinationsWithComplement (suc k) xs)
-- split list into two list (include empty list and order is preserved)
-- splits₂ (upTo 3)
-- >>> ([] , 0 ∷ 1 ∷ 2 ∷ []) ∷
-- >>> (0 ∷ [] , 1 ∷ 2 ∷ []) ∷
-- >>> (0 ∷ 1 ∷ [] , 2 ∷ []) ∷ (0 ∷ 1 ∷ 2 ∷ [] , []) ∷ []
splits₂ : List A → List (List A × List A)
splits₂ [] = ([] , []) ∷ []
splits₂ (x ∷ xs) = ([] , x ∷ xs) ∷ map (Prod.map₁ (x ∷_)) (splits₂ xs)
splits : ℕ → List A → List (List (List A))
splits 0 xs = []
splits 1 xs = [ xs ∷ [] ]
splits (suc (suc k)) xs = concatMap f (splits (suc k) xs)
where
f : List (List A) → List (List (List A))
f [] = []
f (ys ∷ yss) = map (λ { (as , bs) → as ∷ bs ∷ yss }) (splits₂ ys)
splits⁺₂Acc : A → List A → List (List⁺ A × List⁺ A)
splits⁺₂Acc x [] = []
splits⁺₂Acc x (y ∷ xs) = (x NE.∷ [] , y NE.∷ xs) ∷
map (Prod.map₁ (x NE.∷⁺_)) (splits⁺₂Acc y xs)
-- split list into two list (exclude empty list and order is preserved)
splits⁺₂ : List⁺ A → List (List⁺ A × List⁺ A)
splits⁺₂ (x NE.∷ xs) = splits⁺₂Acc x xs
splits⁺ : ℕ → List⁺ A → List (List (List⁺ A))
splits⁺ 0 xs = []
splits⁺ 1 xs = [ xs ∷ [] ]
splits⁺ (suc (suc k)) xs = concatMap f (splits⁺ (suc k) xs)
where
f : List (List⁺ A) → List (List (List⁺ A))
f [] = []
f (ys ∷ yss) =
map (λ { (as , bs) → as ∷ bs ∷ yss }) (splits⁺₂ ys)
splits⁺AllAcc : A → List A → List⁺ (List⁺ (List⁺ A))
splits⁺AllAcc x [] = ((x NE.∷ []) NE.∷ []) NE.∷ []
splits⁺AllAcc x (y ∷ xs) =
NE.map (λ zs → (x NE.∷ []) NE.∷⁺ zs) yss NE.⁺++⁺
NE.map (λ { (z NE.∷ zs) → (x NE.∷⁺ z) NE.∷ zs} ) yss
where yss = splits⁺AllAcc y xs
splits⁺All : List⁺ A → List⁺ (List⁺ (List⁺ A))
splits⁺All (x NE.∷ xs) = splits⁺AllAcc x xs
-- Partition of set
-- Generalization of `combinationsWithComplement`
-- partitions 2 (upTo 3)
-- >>> ((0 ∷ []) ∷ (1 ∷ 2 ∷ []) ∷ []) ∷
-- >>> ((0 ∷ 1 ∷ []) ∷ (2 ∷ []) ∷ []) ∷
-- >>> ((1 ∷ []) ∷ (0 ∷ 2 ∷ []) ∷ []) ∷ []
partitions : ℕ → List A → List (List (List A))
partitions 0 [] = [ [] ]
partitions 0 (x ∷ xs) = []
partitions (suc k) [] = []
partitions (suc k) (x ∷ xs) =
map ([ x ] ∷_) (partitions k xs) ++
concatMap (applyEach (x ∷_)) (partitions (suc k) xs)
partitionsAll : List A → List (List (List A))
partitionsAll [] = [ [] ]
partitionsAll (x ∷ xs) =
map ([ x ] ∷_) yss ++ concatMap (applyEach (x ∷_)) yss
where yss = partitionsAll xs
module _ {a} {A : Set a} where
-- insertEverywhere 100 (upTo 2)
-- >>> (100 ∷ 0 ∷ 1 ∷ []) ∷ (0 ∷ 100 ∷ 1 ∷ []) ∷ (0 ∷ 1 ∷ 100 ∷ []) ∷ []
insertEverywhere : A → List A → List (List A)
insertEverywhere x [] = [ [ x ] ]
insertEverywhere x (y ∷ ys) = (x ∷ y ∷ ys) ∷ map (y ∷_) (insertEverywhere x ys)
module _ {a} {A : Set a} where
-- permutations (upTo 2)
-- >>> (0 ∷ 1 ∷ []) ∷ (1 ∷ 0 ∷ []) ∷ []
permutations : List A → List (List A)
permutations [] = [ [] ]
permutations (x ∷ xs) = concatMap (insertEverywhere x) (permutations xs)
|
{
"alphanum_fraction": 0.4768876804,
"avg_line_length": 38.5564516129,
"ext": "agda",
"hexsha": "db1158e8d122b90dbc42429e625d296c35268865",
"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": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-combinatorics",
"max_forks_repo_path": "Math/Combinatorics/ListFunction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"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": "rei1024/agda-combinatorics",
"max_issues_repo_path": "Math/Combinatorics/ListFunction.agda",
"max_line_length": 81,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-combinatorics",
"max_stars_repo_path": "Math/Combinatorics/ListFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-25T07:25:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-25T08:24:15.000Z",
"num_tokens": 1859,
"size": 4781
}
|
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.EilenbergSteenrodZ where
open import Cubical.Homotopy.EilenbergSteenrod
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Wedge
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.Relation.Nullary
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Int
open import Cubical.Data.Empty renaming (rec to ⊥-rec)
open import Cubical.Data.Unit
open import Cubical.Data.Sigma
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws renaming (assoc to assoc∙)
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.SetTruncation
renaming (map to sMap ; rec to sRec ; elim2 to sElim2; elim to sElim ; rec2 to sRec2)
open import Cubical.HITs.PropositionalTruncation
renaming (map to pMap ; rec to pRec ; elim to pElim ; elim2 to pElim2)
open import Cubical.HITs.Truncation
renaming (rec to trRec ; map to trMap ; elim to trEilim ; elim2 to trElim2)
open import Cubical.HITs.Susp
open import Cubical.HITs.Pushout
open import Cubical.HITs.Wedge
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open coHomTheory
open Iso
open IsGroup
open GroupStr
open GroupIso
open GroupHom
private
suspΩFun' : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (f : A → Path _ (0ₖ _) (0ₖ _))
→ Susp A → coHomK (suc n)
suspΩFun' n f north = 0ₖ _
suspΩFun' n f south = 0ₖ _
suspΩFun' n f (merid a i) = f a i
suspΩFun : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (f : A → coHomK n) → Susp A → coHomK (suc n)
suspΩFun n f = suspΩFun' n λ a → Kn→ΩKn+1 n (f a)
≡suspΩFun : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) (f : Susp (typ A) → coHomK (suc n)) (p : f north ≡ 0ₖ _)
→ f ≡ suspΩFun' n λ a → sym p ∙∙ (cong f (merid a)) ∙∙ (cong f (sym (merid (pt A))) ∙ p)
≡suspΩFun n s f p i north = p i
≡suspΩFun n s f p i south = (cong f (sym (merid (pt s))) ∙ p) i
≡suspΩFun n s f p i (merid a j) =
doubleCompPath-filler (sym p) (cong f (merid a)) (cong f (sym (merid (pt s))) ∙ p) i j
-- induction principle for Hⁿ(Susp A)
SuspCohomElim : ∀ {ℓ ℓ'} {A : Pointed ℓ} (n : ℕ) {B : coHom (suc n) (Susp (typ A)) → Type ℓ'}
→ ((x : coHom (suc n) (Susp (typ A))) → isProp (B x))
→ ((f : typ A → Path _ (0ₖ _) (0ₖ _)) → f (pt A) ≡ refl → B ∣ suspΩFun' n f ∣₂)
→ (x : _) → B x
SuspCohomElim {A = A} n {B = B} isprop f =
coHomPointedElim _ north isprop λ g gid
→ subst (B ∘ ∣_∣₂) (sym (≡suspΩFun n A g gid))
(f _ ((λ i → (sym gid ∙∙ (λ j → g (merid (pt A) (~ i ∧ j))) ∙∙ ((λ j → g (merid (pt A) (~ i ∧ ~ j))) ∙ gid)))
∙∙ (λ i → (λ j → gid (i ∨ ~ j)) ∙∙ refl ∙∙ lUnit (λ j → gid (i ∨ j)) (~ i))
∙∙ sym (rUnit refl)))
-- (Reduced) cohomology functor
coHomFunctor : {ℓ : Level} (n : Int) → Pointed ℓ → AbGroup {ℓ}
coHomFunctor (pos n) = coHomRedGroup n
coHomFunctor (negsuc n) _ = trivialAbGroup
-- Alternative definition with reduced groups replaced by unrecued one for n ≥ 1
coHomFunctor' : {ℓ : Level} (n : Int) → Pointed ℓ → AbGroup {ℓ}
coHomFunctor' (pos zero) = coHomFunctor 0
coHomFunctor' (pos (suc n)) A = coHomGroup (suc n) (typ A)
coHomFunctor' (negsuc n) = coHomFunctor (negsuc n)
coHomFunctor≡coHomFunctor' : ∀ {ℓ} → coHomFunctor {ℓ} ≡ coHomFunctor'
coHomFunctor≡coHomFunctor' = funExt λ {(pos zero) → refl
; (pos (suc n)) → funExt λ A → sym (coHomGroup≡coHomRedGroup n A)
; (negsuc n) → refl}
-- Ĥ⁰(Susp A) is contractible
H0-susp : ∀ {ℓ} {A : Pointed ℓ} → isContr (coHomRed 0 (Susp (typ A) , north))
fst H0-susp = 0ₕ∙ _
snd (H0-susp {A = A}) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ {(f , p)
→ cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _)
(funExt λ {north → sym p
; south → sym p ∙ cong f (merid (pt A))
; (merid a i) j → isSet→isSet' (isSetInt)
(sym p)
(sym p ∙ cong f (merid (pt A)))
refl (cong f (merid a)) i j}))}
-- We need that Hⁿ⁺¹(Susp A) ≃ Hⁿ(A)
private
suspFunCharacFun : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ ((Susp (typ A)) → coHomK (suc n))
→ (typ A → (coHomK n))
suspFunCharacFun {A = A} n f x = ΩKn+1→Kn n (sym (rCancelₖ (suc n) (f north))
∙∙ cong (λ x → f x -[ (suc n) ]ₖ f north) ((merid x) ∙ sym (merid (pt A)))
∙∙ rCancelₖ (suc n) (f north))
linvLem : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f : typ A → Path (coHomK (suc n)) (0ₖ _) (0ₖ _))
(fId : f (pt A) ≡ refl)
→ (x : _) → suspΩFun n (suspFunCharacFun {A = A} n (suspΩFun' n f)) x
≡ suspΩFun' n f x
linvLem n f fId north = refl
linvLem n f fId south = refl
linvLem {A = A} n f fId (merid x i) j = helper n x f fId j i
where
helper : (n : ℕ) (a : typ A) (f : typ A → Path (coHomK (suc n)) (0ₖ _) (0ₖ _))
(fId : f (pt A) ≡ refl)
→ Kn→ΩKn+1 n (suspFunCharacFun {A = A} n (suspΩFun' n f) a) ≡ f a
helper zero a f fId =
Iso.rightInv (Iso-Kn-ΩKn+1 0) (sym (rCancelₖ _ (0ₖ 1))
∙∙ cong (λ x → suspΩFun' 0 f x +ₖ 0ₖ 1) (merid a ∙ (sym (merid (pt A))))
∙∙ rCancelₖ _ (0ₖ 1))
∙∙ (λ i → sym (transportRefl (λ _ → 0ₖ 1) i)
∙∙ cong (λ x → rUnitₖ 1 (suspΩFun' 0 f x) i) (merid a ∙ (sym (merid (pt A))))
∙∙ transportRefl (λ _ → 0ₖ 1) i)
∙∙ (λ i → rUnit (congFunct (suspΩFun' 0 f) (merid a) (sym (merid (pt A))) i) (~ i))
∙∙ cong (λ p → f a ∙ sym p) fId
∙∙ sym (rUnit (f a))
helper (suc n) a f fId =
Iso.rightInv (Iso-Kn-ΩKn+1 (suc n))
(sym (rCancelₖ _ (0ₖ (suc (suc n))))
∙∙ cong (λ x → suspΩFun' (suc n) f x +ₖ 0ₖ (suc (suc n))) (merid a ∙ (sym (merid (pt A))))
∙∙ rCancelₖ _ (0ₖ (suc (suc n))))
∙∙ ((λ i → sym (transportRefl (λ _ → 0ₖ (suc (suc n))) i)
∙∙ cong (λ x → rUnitₖ (suc (suc n)) (suspΩFun' (suc n) f x) i) (merid a ∙ (sym (merid (pt A))))
∙∙ transportRefl (λ _ → 0ₖ (suc (suc n))) i))
∙∙ (λ i → rUnit (congFunct (suspΩFun' (suc n) f) (merid a) (sym (merid (pt A))) i) (~ i))
∙∙ cong (λ p → f a ∙ sym p) fId
∙∙ sym (rUnit (f a))
suspFunCharac : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → Iso (coHom (suc (suc n)) (Susp (typ A))) (coHom (suc n) (typ A))
fun (suspFunCharac {A = A} n) =
sMap λ f → suspFunCharacFun {A = A} (suc n) f
inv (suspFunCharac {A = A} n) = sMap (suspΩFun (suc n))
rightInv (suspFunCharac {A = A} n) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ f → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _))
(λ fId → cong ∣_∣₂ (funExt λ x → (cong (ΩKn+1→Kn (suc n))
((λ i → (sym (transportRefl (λ _ → 0ₖ _) i)
∙∙ cong (λ x → suspΩFun (suc n) f x +ₖ 0ₖ _)
(merid x ∙ sym (merid (pt A)))
∙∙ transportRefl (λ _ → 0ₖ _) i))
∙∙ (sym (rUnit (cong (λ x → suspΩFun (suc n) f x +ₖ 0ₖ _)
((merid x) ∙ sym (merid (pt A))))))
∙∙ (λ i → congFunct (λ x → rUnitₖ _ (suspΩFun (suc n) f x) i)
(merid x) (sym (merid (pt A))) i)))
∙∙ ΩKn+1→Kn-hom (suc n) (Kn→ΩKn+1 (suc n) (f x))
(sym (Kn→ΩKn+1 (suc n) (f (pt A))))
∙∙ cong₂ _+ₖ_ (Iso.leftInv (Iso-Kn-ΩKn+1 (suc n)) (f x))
(cong (λ x → ΩKn+1→Kn (suc n) (sym (Kn→ΩKn+1 (suc n) x))) fId)
∙∙ cong (λ y → f x +ₖ ΩKn+1→Kn (suc n) (sym y)) (Kn→ΩKn+10ₖ (suc n))
∙∙ cong (f x +ₖ_) (ΩKn+1→Kn-refl (suc n))
∙ rUnitₖ _ (f x)))
(fst (isConnectedPathKn n (f (pt A)) (0ₖ _))))
leftInv (suspFunCharac {A = A} n) =
SuspCohomElim {A = A} _ (λ _ → setTruncIsSet _ _)
λ f fId → cong ∣_∣₂ (funExt (linvLem (suc n) f fId))
-- We also need that H¹(Susp A) ≃ Ĥ⁰(A)
suspFunCharac0 : ∀ {ℓ} {A : Pointed ℓ} → Iso (∥ ((Susp (typ A)) → coHomK 1) ∥₂) ∥ A →∙ (Int , 0) ∥₂
fun (suspFunCharac0 {A = A}) =
sMap λ f → suspFunCharacFun {A = A} 0 f
, (cong (ΩKn+1→Kn 0) ((λ i → sym (rCancelₖ _ (f north))
∙∙ cong (λ x → f x -ₖ f north) (rCancel (merid (pt A)) i)
∙∙ rCancelₖ _ (f north))
∙∙ (doubleCompPath-elim (sym (rCancelₖ _ (f north))) refl (rCancelₖ _ (f north)))
∙∙ (cong (_∙ (rCancelₖ _ (f north))) (sym (rUnit (sym (rCancelₖ _ (f north))))))
∙ (lCancel (rCancelₖ _ (f north)))))
inv suspFunCharac0 = sMap λ f → suspΩFun 0 (fst f)
rightInv (suspFunCharac0 {A = A}) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ {(f , p)
→ cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _)
(funExt (λ x → (λ j → transp (λ i → helix (wedgeMapS¹ (intLoop (p j) (~ i)) base)) j
((transport (λ i → helix (trRec isGroupoidS¹ (λ x → x)
(rUnitₖ 1 ∣ intLoop (f x) i ∣ j)))
(pos 0))))
∙ windingIntLoop (f x))))}
leftInv (suspFunCharac0 {A = A}) =
SuspCohomElim {A = A} _ (λ _ → setTruncIsSet _ _)
λ f fId → cong ∣_∣₂ (funExt (linvLem 0 f fId))
-- We now prove that the alternative definition of cohomology is a cohomology theory.
private
-- First, we need to that coHomFunctor' is contravariant
theMorph : ∀ {ℓ} (n : Int) {A B : Pointed ℓ} (f : A →∙ B)
→ AbGroupHom (coHomFunctor' n B) (coHomFunctor' n A)
fun (theMorph (pos zero) f) = sMap λ g → (λ x → fst g (fst f x)) , cong (fst g) (snd f) ∙ snd g
isHom (theMorph (pos zero) f) =
sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f g → cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _) refl)
theMorph (pos (suc n)) f = coHomMorph _ (fst f)
fun (theMorph (negsuc n) f) = idfun _
isHom (theMorph (negsuc n) f) _ _ = refl
open coHomTheory
isCohomTheoryZ' : ∀ {ℓ} → coHomTheory {ℓ} coHomFunctor'
Hmap isCohomTheoryZ' = theMorph
-------------------------- Suspension --------------------------
-- existence of suspension isomorphism
fst (Suspension isCohomTheoryZ') (pos zero) {A = A} =
invGroupEquiv
(GrIsoToGrEquiv
(Iso+Hom→GrIso (invIso suspFunCharac0)
(sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f g → cong ∣_∣₂ (funExt λ { north → refl
; south → refl
; (merid a i) j → helper a (fst f) (fst g) j i}))))
where
helper : (a : typ A) (f g : typ A → coHomK 0)
→ Kn→ΩKn+1 0 (f a +[ 0 ]ₖ g a)
≡ cong₂ _+ₖ_ (Kn→ΩKn+1 0 (f a)) (Kn→ΩKn+1 0 (g a))
helper a f g = Kn→ΩKn+1-hom 0 (f a) (g a)
∙ ∙≡+₁ (Kn→ΩKn+1 _ (f a)) (Kn→ΩKn+1 _ (g a))
fst (Suspension isCohomTheoryZ') (pos (suc n)) {A = A} =
invGroupEquiv
(GrIsoToGrEquiv
(Iso+Hom→GrIso (invIso (suspFunCharac {A = A} n))
(sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f g → cong ∣_∣₂ (funExt λ { north → refl
; south → refl
; (merid a i) j → helper a f g j i}))))
where
helper : (a : typ A) (f g : typ A → coHomK (suc n))
→ Kn→ΩKn+1 (suc n) (f a +ₖ g a)
≡ cong₂ _+ₖ_ (Kn→ΩKn+1 (suc n) (f a)) (Kn→ΩKn+1 (suc n) (g a))
helper a f g = Kn→ΩKn+1-hom (suc n) (f a) (g a)
∙ ∙≡+₂ n (Kn→ΩKn+1 _ (f a)) (Kn→ΩKn+1 _ (g a))
fst (Suspension isCohomTheoryZ') (negsuc zero) {A = A} =
GrIsoToGrEquiv (Iso+Hom→GrIso (isContr→Iso (H0-susp {A = _ , pt A}) isContrUnit*)
λ _ _ → refl)
fst (Suspension isCohomTheoryZ') (negsuc (suc n)) = idGroupEquiv _
-- naturality of the suspension isomorphism
snd (Suspension (isCohomTheoryZ' {ℓ})) (f , p) (pos zero) =
funExt (sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ {(f , _) → cong ∣_∣₂ (funExt λ {north → refl
; south → refl
; (merid a i) → refl})})
snd (Suspension (isCohomTheoryZ' {ℓ})) (f , p) (pos (suc n)) =
funExt (sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f → cong ∣_∣₂ (funExt λ {north → refl
; south → refl
; (merid a i) → refl}))
snd (Suspension (isCohomTheoryZ' {ℓ})) (f , p) (negsuc zero) = refl
snd (Suspension (isCohomTheoryZ' {ℓ})) (f , p) (negsuc (suc n)) = refl
-------------------------- Exactness ---------------------------
Exactness isCohomTheoryZ' {A = A} {B = B} f n = isoToPath (exactnessIso n f)
where
exactnessIso : (n : Int) (f : A →∙ B)
→ Iso (Ker (theMorph n f)) (Im (theMorph n (cfcod (fst f) , refl)))
fun (exactnessIso (pos zero) (f , p)) =
uncurry (sElim (λ _ → isSetΠ λ _ → isSetΣ setTruncIsSet λ _ → isProp→isSet propTruncIsProp)
λ {(g , q) inker → ∣ g , q ∣₂
, pRec propTruncIsProp
(λ gId → ∣ ∣ (λ { (inl tt) → 0
; (inr b) → g b
; (push a i) → funExt⁻ (cong fst gId) a (~ i)}) , q ∣₂
, cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _) refl) ∣)
(Iso.fun PathIdTrunc₀Iso inker)})
inv (exactnessIso (pos zero) (f , p)) =
uncurry (sElim (λ _ → isSetΠ λ _ → isSetΣ setTruncIsSet λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ {(g , q) inim'
→ ∣ g , q ∣₂
, pRec (setTruncIsSet _ _)
(uncurry
(sElim (λ _ → isSetΠ (λ _ → isOfHLevelPath 2 setTruncIsSet _ _))
(λ pushmap pushId'
→ pRec (setTruncIsSet _ _)
(λ pushId
→ cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _)
(funExt λ x → sym (funExt⁻ (cong fst pushId) (f x))
∙∙ cong (fst pushmap) (sym (push x) ∙ push (pt A))
∙∙ (cong (fst pushmap ∘ inr) p
∙ snd pushmap))))
(Iso.fun PathIdTrunc₀Iso pushId'))))
inim'})
rightInv (exactnessIso (pos zero) (f , p)) =
uncurry (sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2
(isSetΣ setTruncIsSet
(λ _ → isProp→isSet propTruncIsProp)) _ _)
λ {(p , q) _ → Σ≡Prop (λ _ → propTruncIsProp) refl})
leftInv (exactnessIso (pos zero) (f , p)) =
uncurry (sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2
(isSetΣ setTruncIsSet
(λ _ → isProp→isSet (setTruncIsSet _ _))) _ _)
λ {(p , q) _ → Σ≡Prop (λ _ → setTruncIsSet _ _) refl})
fun (exactnessIso (pos (suc n)) f) ker = (fst ker) , inIm-helper (fst ker) (snd ker)
where
inIm-helper : (x : coHom (suc n) (typ B))
→ isInKer _ _ (theMorph (pos (suc n)) {A = A} {B = B} f) x
→ isInIm _ _ (theMorph (pos (suc n)) {A = B} {B = _ , inr (pt B)} (cfcod (fst f) , refl)) x
inIm-helper =
coHomPointedElim _ (pt B) (λ _ → isPropΠ λ _ → propTruncIsProp)
λ g gId inker → pRec propTruncIsProp
(λ gIdTot → ∣ ∣ (λ { (inl tt) → 0ₖ _
; (inr b) → g b
; (push a i) → funExt⁻ gIdTot a (~ i)}) ∣₂
, cong ∣_∣₂ (funExt λ b → refl) ∣)
(Iso.fun PathIdTrunc₀Iso inker)
inv (exactnessIso (pos (suc n)) f) im = fst im , inKer-helper (fst im) (snd im)
where
inKer-helper : (x : coHom (suc n) (typ B))
→ isInIm _ _ (theMorph (pos (suc n)) {A = B} {B = _ , inr (pt B)} (cfcod (fst f) , refl)) x
→ isInKer _ _ (theMorph (pos (suc n)) {A = A} {B = B} f) x
inKer-helper =
coHomPointedElim _ (pt B) (λ _ → isPropΠ λ _ → setTruncIsSet _ _)
λ g gId → pRec (setTruncIsSet _ _)
(uncurry λ cg p
→ subst (isInKer (coHomGr (suc n) (typ B)) (coHomGr (suc n) (typ A))
(coHomMorph (suc n) (fst f)))
p
(helper cg))
where
helper : (cg : _) → coHomFun (suc n) (fst f) (coHomFun (suc n) (cfcod (fst f)) cg) ≡ 0ₕ _
helper = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ cg → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _))
(λ p → (cong ∣_∣₂ (funExt λ x → cong cg (sym (push x))
∙ p)))
(isConnectedPathKn _ (cg (inl tt)) (0ₖ (suc n)) .fst)
rightInv (exactnessIso (pos (suc n)) f) _ = Σ≡Prop (λ _ → propTruncIsProp) refl
leftInv (exactnessIso (pos (suc n)) f) _ = Σ≡Prop (λ _ → setTruncIsSet _ _) refl
exactnessIso (negsuc n) (f , p) =
isContr→Iso ((tt* , refl)
, λ {(tt* , p) → Σ≡Prop (λ _ → isOfHLevelPath 1 isPropUnit* _ _)
refl})
((tt* , ∣ tt* , refl ∣)
, λ {(tt* , p) → Σ≡Prop (λ _ → propTruncIsProp)
refl})
-------------------------- Dimension ---------------------------
Dimension isCohomTheoryZ' (pos zero) p = ⊥-rec (p refl)
fst (Dimension isCohomTheoryZ' (pos (suc n)) _) = 0ₕ _
snd (Dimension isCohomTheoryZ' (pos (suc n)) _) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ f → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _))
(λ f-true → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _))
(λ f-false → cong ∣_∣₂ (funExt (λ {(lift true) → f-true
; (lift false) → f-false})))
(isConnectedPathKn n (0ₖ _) (f (lift false)) .fst))
(isConnectedPathKn n (0ₖ _) (f (lift true)) .fst))
Dimension isCohomTheoryZ' (negsuc n) _ = isContrUnit*
------------------------ Binary wedges -------------------------
BinaryWedge isCohomTheoryZ' (pos zero) = GrIsoToGrEquiv (H⁰Red-⋁ _ _)
BinaryWedge isCohomTheoryZ' (pos (suc n)) = GrIsoToGrEquiv (Hⁿ-⋁ _ _ n)
BinaryWedge isCohomTheoryZ' (negsuc n) =
GrIsoToGrEquiv
(compGroupIso (IsoContrGroupTrivialGroup isContrUnit*)
(invGroupIso (IsoContrGroupTrivialGroup (isOfHLevel× 0 isContrUnit* isContrUnit*))))
-- Substituting back for our original theory, we are done
isCohomTheoryZ : ∀ {ℓ} → coHomTheory {ℓ} coHomFunctor
isCohomTheoryZ = subst coHomTheory (sym coHomFunctor≡coHomFunctor')
isCohomTheoryZ'
|
{
"alphanum_fraction": 0.4565166706,
"avg_line_length": 56.2860892388,
"ext": "agda",
"hexsha": "5b166638eac2843fb32f5afa9d79110d2f51fece",
"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/ZCohomology/EilenbergSteenrodZ.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/EilenbergSteenrodZ.agda",
"max_line_length": 132,
"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/ZCohomology/EilenbergSteenrodZ.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7306,
"size": 21445
}
|
module Modal where
open import Prelude
open import Star
data Progress (A : Set) : Set where
cont : A -> Progress A
stop : Progress A
record Some {A : Set}(R : Rel A) : Set where
field
a : A
b : A
edge : R a b
some : {A : Set}{R : Rel A}{a b : A} -> R a b -> Some R
some x = record {a = _; b = _; edge = x}
EdgePred : {A : Set} -> Rel A -> Set1
EdgePred R = forall {a b} -> R a b -> Set
data PStep {A : Set}{R : Rel A}(P : EdgePred R) :
Rel (Progress (Some (Star R))) where
step : {a b c : A}{x : R a b}{xs : Star R b c} ->
PStep P (cont (some (x • xs))) (cont (some xs))
done : {a b c : A}{x : R a b}{xs : Star R b c} ->
P x -> PStep P (cont (some (x • xs))) stop
Any : {A : Set}{R : Rel A}(P : EdgePred R) -> EdgePred (Star R)
Any P xs = Star (PStep P) (cont (some xs)) stop
mapAny : {A₁ A₂ : Set}{R₁ : Rel A₁}{R₂ : Rel A₂}
{P₁ : EdgePred R₁}{P₂ : EdgePred R₂}{a b : A₁}{xs : Star R₁ a b}
{i : A₁ -> A₂}{f : R₁ =[ i ]=> R₂} ->
({a b : A₁}{x : R₁ a b} -> P₁ x -> P₂ (f x)) ->
Any P₁ xs -> Any (\{a b} -> P₂{a}{b}) (map i f xs)
mapAny h (step • i) = step • mapAny h i
mapAny h (done p • ε) = done (h p) • ε
mapAny h (done p • (() • _))
data Check {A : Set}{R : Rel A}(P : EdgePred R) :
Rel (Some (Star R)) where
check : {a b c : A}{x : R a b}{xs : Star R b c} ->
P x -> Check P (some (x • xs)) (some xs)
checkedEdge : {A : Set}{R : Rel A}{P : EdgePred R}{xs ys : Some (Star R)} ->
Check P xs ys -> Some R
checkedEdge (check {x = x} _) = some x
uncheck : {X : Set}{R : Rel X}{P : EdgePred R}{xs ys : Some (Star R)}
(chk : Check P xs ys) -> P (Some.edge (checkedEdge chk))
uncheck (check p) = p
All : {A : Set}{R : Rel A}(P : EdgePred R) -> EdgePred (Star R)
All P {a}{b} xs = Star (Check P) (some xs) (some {a = b} ε)
data Lookup {A : Set}{R : Rel A}(P Q : EdgePred R) : Set where
result : {a b : A} -> (x : R a b) -> P x -> Q x -> Lookup P Q
lookup : {A : Set}{R : Rel A}{P Q : EdgePred R}{a b : A}{xs : Star R a b} ->
Any P xs -> All Q xs -> Lookup (\{a b} -> P{a}{b}) Q
lookup (step • i) (check _ • xs) = lookup i xs
lookup (done p • ε) (check q • _ ) = result _ p q
lookup (done p • (() • _)) (check q • _ )
|
{
"alphanum_fraction": 0.4978070175,
"avg_line_length": 34.5454545455,
"ext": "agda",
"hexsha": "67e293ca64efa3d3b4dde991f2dc6c9ebf788c5a",
"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/AIM6/Path/Modal.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/AIM6/Path/Modal.agda",
"max_line_length": 76,
"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/AIM6/Path/Modal.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": 874,
"size": 2280
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Utils.Product where
open import Level
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality
-- "very dependent" versions of map and zipWith
map⁎ : ∀ {a b p q} {A : Set a} {B : A → Set b} {P : A → Set p} {Q : {x : A} → P x → B x → Set q} →
(f : (x : A) → B x) → (∀ {x} → (y : P x) → Q y (f x)) → (v : Σ A P) → Σ (B (proj₁ v)) (Q (proj₂ v))
map⁎ f g (x , y) = (f x , g y)
map⁎′ : ∀ {a b p q} {A : Set a} {B : A → Set b} {P : Set p} {Q : P → Set q} → (f : (x : A) → B x) → ((x : P) → Q x) → (v : A × P) → B (proj₁ v) × Q (proj₂ v)
map⁎′ f g (x , y) = (f x , g y)
zipWith : ∀ {a b c p q r s} {A : Set a} {B : Set b} {C : Set c} {P : A → Set p} {Q : B → Set q} {R : C → Set r} {S : (x : C) → R x → Set s} (_∙_ : A → B → C) → (_∘_ : ∀ {x y} → P x → Q y → R (x ∙ y)) → (_*_ : (x : C) → (y : R x) → S x y) → (x : Σ A P) → (y : Σ B Q) → S (proj₁ x ∙ proj₁ y) (proj₂ x ∘ proj₂ y)
zipWith _∙_ _∘_ _*_ (a , p) (b , q) = (a ∙ b) * (p ∘ q)
syntax zipWith f g h = f -< h >- g
|
{
"alphanum_fraction": 0.4522706209,
"avg_line_length": 56.7894736842,
"ext": "agda",
"hexsha": "86543bbcbd8256cadfa5d13a278893f72aa6ce65",
"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/Utils/Product.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/Utils/Product.agda",
"max_line_length": 309,
"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/Utils/Product.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": 510,
"size": 1079
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.SetoidDiscrete where
open import Categories.Category
open import Level
open import Relation.Binary using (Setoid)
open import Function
open import Data.Unit
{-
This is a better version of Discrete, which is more in line with
the rest of this library, and makes a Category out of a Setoid.
But here we have no choice, and we need to truncate the equivalence.
-}
Discrete : ∀ {o ℓ e} (A : Setoid o ℓ) → Category o ℓ e
Discrete {_} {_} {e} A = record
{ Obj = Carrier
; _⇒_ = _≈_
; _≈_ = λ _ _ → Lift e ⊤
; id = refl
; _∘_ = flip trans
}
where
open Setoid A
|
{
"alphanum_fraction": 0.6507462687,
"avg_line_length": 24.8148148148,
"ext": "agda",
"hexsha": "419ccf875ae6c67840aee4eaa90dd3108d16e723",
"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": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Category/SetoidDiscrete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"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": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Category/SetoidDiscrete.agda",
"max_line_length": 69,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Category/SetoidDiscrete.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": 200,
"size": 670
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Setoids.Setoids
open import Rings.Definition
open import Rings.PrincipalIdealDomains.Definition
open import Rings.IntegralDomains.Definition
open import Rings.Ideals.Maximal.Definition
module Rings.PrincipalIdealDomains.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) (pid : {c : _} → PrincipalIdealDomain intDom {c}) where
open import Rings.Ideals.Definition R
open import Rings.Irreducibles.Definition intDom
open import Rings.Ideals.Principal.Definition R
open import Rings.Divisible.Definition R
open import Rings.Associates.Lemmas intDom
open import Rings.Ideals.Lemmas R
open import Rings.Units.Definition R
open import Rings.Irreducibles.Lemmas intDom
open import Rings.Units.Lemmas R
open import Rings.Ideals.Prime.Definition {R = R}
open import Rings.Ideals.Prime.Lemmas {R = R}
open import Rings.Primes.Definition intDom
open import Rings.Primes.Lemmas intDom
open import Rings.Ideals.Principal.Lemmas R
open import Rings.Ideals.Maximal.Lemmas {R = R}
open Ring R
open Setoid S
open Equivalence eq
irreducibleImpliesMaximalIdeal : {r : A} → Irreducible r → {d : _} → MaximalIdeal (generatedIdeal r) {d}
MaximalIdeal.notContained (irreducibleImpliesMaximalIdeal {r} irred {d}) = 1R
MaximalIdeal.notContainedIsNotContained (irreducibleImpliesMaximalIdeal {r} irred {d}) = Irreducible.nonunit irred
MaximalIdeal.isMaximal (irreducibleImpliesMaximalIdeal {r} irred {d}) {biggerPred} bigger biggerContains (outsideR , (biggerContainsOutside ,, notInR)) {x} = biggerPrincipal' (unitImpliesGeneratedIdealEverything w {x})
where
biggerGen : A
biggerGen = PrincipalIdeal.generator (pid bigger)
biggerPrincipal : {x : A} → biggerPred x → biggerGen ∣ x
biggerPrincipal = PrincipalIdeal.genGenerates (pid bigger)
bp : biggerPred biggerGen
bp = PrincipalIdeal.genIsInIdeal (pid bigger)
biggerPrincipal' : {x : A} → biggerGen ∣ x → biggerPred x
biggerPrincipal' {y} bg|y = memberDividesImpliesMember bigger bp bg|y
u : biggerGen ∣ r
u = biggerPrincipal (biggerContains (1R , transitive *Commutative identIsIdent))
biggerGenNonzero : biggerGen ∼ 0R → False
biggerGenNonzero bg=0 = notInR (Ideal.isSubset (generatedIdeal r) (symmetric t) (Ideal.containsIdentity (generatedIdeal r)))
where
t : outsideR ∼ 0R
t with biggerPrincipal {outsideR} biggerContainsOutside
... | mult , pr = transitive (symmetric pr) (transitive (*WellDefined bg=0 reflexive) (transitive *Commutative timesZero))
v : (r ∣ biggerGen) → False
v r|bg with mutualDivisionImpliesAssociate r|bg u (Irreducible.nonzero irred)
v r|bg | assoc = notInR (associateImpliesGeneratedIdealsEqual' assoc (PrincipalIdeal.genGenerates (pid bigger) biggerContainsOutside))
w : Unit biggerGen
w = dividesIrreducibleImpliesUnit irred u v
primeIdealIsMaximal : {c : _} {pred : A → Set c} → {i : Ideal pred} → (nonzero : Sg A (λ a → ((a ∼ 0R) → False) && pred a)) → PrimeIdeal i → {d : _} → MaximalIdeal i {d}
primeIdealIsMaximal {pred = pred} {i} (m , (m!=0 ,, predM)) prime {d = d} = maximalIdealWellDefined (generatedIdeal (PrincipalIdeal.generator princ)) i (memberDividesImpliesMember i (PrincipalIdeal.genIsInIdeal princ)) (PrincipalIdeal.genGenerates princ) isMaximal
where
princ : PrincipalIdeal i
princ = pid i
isPrime : Prime (PrincipalIdeal.generator princ)
isPrime = primeIdealImpliesPrime (λ gen=0 → PrimeIdeal.notContainedIsNotContained prime (exFalso (m!=0 (generatorZeroImpliesAllZero princ gen=0 predM)))) (primeIdealWellDefined i (generatedIdeal (PrincipalIdeal.generator princ)) (PrincipalIdeal.genGenerates princ) (memberDividesImpliesMember i (PrincipalIdeal.genIsInIdeal princ)) prime)
isIrreducible : Irreducible (PrincipalIdeal.generator princ)
isIrreducible = primeIsIrreducible isPrime
isMaximal : MaximalIdeal (generatedIdeal (PrincipalIdeal.generator princ)) {d}
isMaximal = irreducibleImpliesMaximalIdeal isIrreducible {d}
irreducibleImpliesPrime : {x : A} → Irreducible x → Prime x
irreducibleImpliesPrime {x} irred = primeIdealImpliesPrime (Irreducible.nonzero irred) (idealMaximalImpliesIdealPrime (generatedIdeal x) (irreducibleImpliesMaximalIdeal irred))
|
{
"alphanum_fraction": 0.7608497031,
"avg_line_length": 59.1621621622,
"ext": "agda",
"hexsha": "0b2ec2e82730d119bd61fce9af9dabcba8a39833",
"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/PrincipalIdealDomains/Lemmas.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/PrincipalIdealDomains/Lemmas.agda",
"max_line_length": 342,
"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/PrincipalIdealDomains/Lemmas.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": 1264,
"size": 4378
}
|
module x02-842Induction where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_)
-- PLFA coverage of identity, associativity, commutativity, distributivity.
-- An example of the associative law for addition.
_ : (3 + 4) + 5 ≡ 3 + (4 + 5)
_ =
begin
(3 + 4) + 5
≡⟨⟩
7 + 5
≡⟨⟩
12
≡⟨⟩
3 + 9
≡⟨⟩
3 + (4 + 5)
∎
-- A theorem easy to prove.
+-identityᴸ : ∀ (m : ℕ) → zero + m ≡ m
+-identityᴸ m = {!!}
-- A first nontrivial theorem.
-- An equational proof is shown in PLFA.
-- It uses helpers cong and sym imported from the standard library,
-- and a form of equational reasoning that allows more elaborate justification.
-- Instead we will use 'rewrite'.
+-identityʳ : ∀ (m : ℕ) → m + zero ≡ m
+-identityʳ m = {!!}
-- Associativity of addition.
-- (Done first in PLFA.)
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc m n p = {!!}
-- A useful lemma about addition.
-- Equational proof shown in PLFA.
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc m n = {!!}
-- Commutativity of addition.
-- Equational proof shown in PLFA.
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm m n = {!!}
-- 842 exercise: AddSwap (1 point)
-- Please do this without using induction/recursion.
+-swap : ∀ (m n p : ℕ) → (m + n) + p ≡ n + (m + p)
+-swap m n p = {!!}
-- 842 exercise: AddDistMult (2 points)
-- Show that addition distributes over multiplication.
*-+-rdistrib : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p
*-+-rdistrib m n p = {!!}
-- 842 exercise: MultAssoc (2 points)
-- Show that multiplication is associative.
*-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
*-assoc m n p = {!!}
-- 842 exercise: MultComm (3 points)
-- Show that multiplication is commutative.
-- As with the addition proof above, helper lemmas will be needed.
*-comm : ∀ (m n : ℕ) → m * n ≡ n * m
*-comm m n = {!!}
-- 842 exercise: LeftMonusZero (1 point)
-- PLFA asks "Did your proof require induction?"
-- (which should give you an indication of the expected answer).
0∸n≡0 : ∀ (m : ℕ) → zero ∸ m ≡ zero
0∸n≡0 m = {!!}
-- 842 exercise: MonusAssocish (2 points)
-- Show a form of associativity for monus.
∸-+-assoc : ∀ (m n p : ℕ) → m ∸ n ∸ p ≡ m ∸ (n + p)
∸-+-assoc m n p = {!!}
-- 842 extended exercise: properties of binary representation.
-- This is based on the PLFA Bin-laws exercise.
-- Copied from 842Naturals.
data Bin-ℕ : Set where
bits : Bin-ℕ
_x0 : Bin-ℕ → Bin-ℕ
_x1 : Bin-ℕ → Bin-ℕ
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc n) = suc (suc (dbl n))
-- Copy your versions of 'inc', 'to', 'from', 'bin-+' over from 842Naturals.
-- You may choose to change them here to make proofs easier.
-- But make sure to test them if you do!
inc : Bin-ℕ → Bin-ℕ
inc m = {!!}
tob : ℕ → Bin-ℕ
tob m = {!!}
fromb : Bin-ℕ → ℕ
fromb m = {!!}
_bin-+_ : Bin-ℕ → Bin-ℕ → Bin-ℕ
m bin-+ n = {!!}
-- 842 exercise: DoubleB (1 point)
-- Write the Bin-ℕ version of dbl, here called dblb.
-- As with the other Bin-ℕ operations, don't use tob/fromb.
dblb : Bin-ℕ → Bin-ℕ
dblb m = {!!}
-- Here are some properties of tob/fromb/inc suggested by PLFA Induction.
-- Please complete the proofs.
-- 842 exercise: FromInc (1 point)
from∘inc : ∀ (m : Bin-ℕ) → fromb (inc m) ≡ suc (fromb m)
from∘inc m = {!!}
-- 842 exercise: FromToB (1 point)
from∘tob : ∀ (m : ℕ) → fromb (tob m) ≡ m
from∘tob m = {!!}
-- 842 exercise: ToFromB (2 points)
-- The property ∀ (m : Bin-ℕ) → tob (fromb m) ≡ m cannot be proved.
-- Can you see why?
-- However, this restriction of it can be proved.
to/from-corr : ∀ (m : Bin-ℕ) (n : ℕ) → m ≡ tob n → fromb m ≡ n
to/from-corr m n m≡tn = {!!}
-- Here are a few more properties for you to prove.
-- 842 exercise: DblBInc (1 point)
dblb∘inc : ∀ (m : Bin-ℕ) → dblb (inc m) ≡ inc (inc (dblb m))
dblb∘inc m = {!!}
-- 842 exercise: ToDbl (1 point)
to∘dbl : ∀ (m : ℕ) → tob (dbl m) ≡ dblb (tob m)
to∘dbl m = {!!}
-- 842 exercise: FromDblB (1 point)
from∘dblb : ∀ (m : Bin-ℕ) → fromb (dblb m) ≡ dbl (fromb m)
from∘dblb m = {!!}
-- 842 exercise: BinPlusLInc (2 points)
-- This helper function translates the second case for unary addition
-- suc m + n = suc (m + n)
-- into the binary setting. It's useful in the next proof.
-- Hint: induction on both m and n is needed.
bin-+-linc : ∀ (m n : Bin-ℕ) → (inc m) bin-+ n ≡ inc (m bin-+ n)
bin-+-linc m n = {!!}
-- 842 exercise: PlusUnaryBinary (2 points)
-- This theorem relates unary and binary addition.
to∘+ : ∀ (m n : ℕ) → tob (m + n) ≡ tob m bin-+ tob n
to∘+ m n = {!!}
-- This ends the extended exercise.
-- The following theorems proved in PLFA can be found in the standard library.
-- import Data.Nat.Properties using (+-assoc; +-identityʳ; +-suc; +-comm)
-- Unicode used in this chapter:
{-
∀ U+2200 FOR ALL (\forall, \all)
ʳ U+02B3 MODIFIER LETTER SMALL R (\^r)
′ U+2032 PRIME (\')
″ U+2033 DOUBLE PRIME (\')
‴ U+2034 TRIPLE PRIME (\')
⁗ U+2057 QUADRUPLE PRIME (\')
-}
|
{
"alphanum_fraction": 0.596297755,
"avg_line_length": 24.5314009662,
"ext": "agda",
"hexsha": "a0fd7a74499065d427271b8dc4591c0d9d012b3e",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x02-842Induction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x02-842Induction.agda",
"max_line_length": 79,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x02-842Induction.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 1849,
"size": 5078
}
|
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
data Interval : Set where
left right : Interval
sq : left ≡ right
-- Agda should not loop when typechecking the following definition.
--
-- Termination checking should catch that `id left` is not
-- normalizing, given our definition of reduction.
--
-- Hence conversion checking shouldn't reduce applications of `id`.
id : Interval → Interval
id (sq i) = sq i
id left = id (sq i0)
id right = id (sq i1)
|
{
"alphanum_fraction": 0.7183364839,
"avg_line_length": 25.1904761905,
"ext": "agda",
"hexsha": "53a95e315ae284702228da93939d844dd4eac727",
"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/Issue3572.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/Issue3572.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/Fail/Issue3572.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": 137,
"size": 529
}
|
import cedille-options
open import general-util
module process-cmd
(options : cedille-options.options)
{mF : Set → Set}
{{mFm : monad mF}}
(progress-update : string → mF ⊤)
(write-to-log : string → mF ⊤) where
--open import cedille-find
open import cedille-types
open import classify options {mF} ⦃ mFm ⦄ write-to-log
open import constants
open import conversion
open import ctxt
open import free-vars
open import rename
open import spans options { mF } ⦃ mFm ⦄
open import subst
open import syntax-util
open import type-util
open import toplevel-state options { mF } ⦃ mFm ⦄
open import to-string options
open import datatype-util
open import rewriting
open import elab-util options
import cws-types
import cws
-- generate spans from the given comments-and-whitespace syntax tree
process-cwst-etys : cws-types.entities → spanM ⊤
process-cwst-ety : cws-types.entity → spanM ⊤
process-cwst-etys (cws-types.Entity ety etys) = process-cwst-ety ety >> process-cwst-etys etys
process-cwst-etys cws-types.EndEntity = return triv
process-cwst-ety cws-types.EntityNonws = return triv
process-cwst-ety (cws-types.EntityWs pi pi') = return triv
process-cwst-ety (cws-types.EntityComment pi pi') = [- comment-span pi pi' -] return triv
process-cwst : toplevel-state → filepath → spanM toplevel-state
process-cwst s filename with include-elt.cwst (get-include-elt s filename)
process-cwst s filename | nothing = return s
process-cwst s filename | just (cws-types.File etys) = process-cwst-etys etys >> return s
check-and-add-params : ctxt → posinfo → ex-params → spanM (ctxt × params)
check-and-add-params Γ pi' (p@(ExParam pi1 me pi1' x atk pi2) :: ps') =
Γ ⊢ atk ↝ atk~ /
let Γ' = Γ , pi1' - x :` atk~
qx = pi1' % x in
[- punctuation-span "Parens (parameter)" pi1 pi2 -]
[- Decl-span Γ' decl-param pi1 pi1' x atk~ me pi2 pi' -]
[- var-span me Γ' pi1' x checking atk~ nothing -]
check-and-add-params Γ' pi' ps' >>=c λ Γ'' ps~ →
return2 Γ'' (Param me qx atk~ :: ps~)
check-and-add-params Γ pi' [] = return2 Γ []
optAs-posinfo-var : ctxt → maybe import-as → posinfo × var → spanM (posinfo × var)
optAs-posinfo-var Γ nothing = return
optAs-posinfo-var Γ (just (ImportAs pi x)) orig =
[- Import-module-span Γ orig [] [ not-for-navigation ] nothing -]
return2 pi x
{-# TERMINATING #-}
{- notice that these are elaborating functions: they take an ex-QQQ and return a QQQ (along with other activity) -}
process-cmd : toplevel-state → ex-cmd → spanM (toplevel-state × cmd)
process-cmds : toplevel-state → ex-cmds → spanM (toplevel-state × cmds)
process-ctrs : (uqv lqv mqv : var) → params → posinfo → toplevel-state → ex-ctrs → spanM ((ctxt → ctxt) × ctrs)
process-params : toplevel-state → posinfo → ex-params → spanM (toplevel-state × params)
process-start : toplevel-state → filepath → (progress-name : string) → ex-file → spanM (toplevel-state × file)
process-file : toplevel-state → filepath → (progress-name : string) → mF (toplevel-state × file × string × string × params × qualif)
maybe-add-opaque-span : optopaque → (end : posinfo) → spanM ⊤
maybe-add-opaque-span nothing pi = return triv
maybe-add-opaque-span (just piₒ) pi =
spanM-add $ Opaque-span piₒ pi
process-cmd s (ExCmdDef op (ExDefTerm pi x (just tp) t) pi') =
let Γ = toplevel-state.Γ s in
Γ ⊢ tp ⇐ KdStar ↝ tp' /
Γ ⊢ t ⇐ tp' ↝ t' /
check-erased-margs Γ (term-start-pos t) (term-end-pos t) t' (just tp') >>
let Γ' = ctxt-term-def pi globalScope (isNothing op) x (just t') tp' Γ in
maybe-add-opaque-span op pi' >>
[- DefTerm-span Γ' pi x checking (just tp') t' pi' [] -]
check-redefined pi x s
(CmdDefTerm x t')
([- uncurry (Var-span Γ' pi x checking) (compileFail-in Γ t') -]
return (record s { Γ = Γ' }))
process-cmd s (ExCmdDef op (ExDefTerm pi x nothing t) pi') =
let Γ = toplevel-state.Γ s in
Γ ⊢ t ↝ t~ ⇒ T~ /
check-erased-margs Γ (term-start-pos t) (term-end-pos t) t~ nothing >>
let Γ' = ctxt-term-def pi globalScope (isNothing op) x (just t~) T~ Γ in
maybe-add-opaque-span op pi' >>
[- DefTerm-span Γ' pi x synthesizing (just T~) t~ pi' [] -]
check-redefined pi x s
(CmdDefTerm x t~)
([- uncurry (Var-span Γ' pi x synthesizing) (compileFail-in Γ t~) -]
return (record s { Γ = Γ' }))
process-cmd s (ExCmdDef op (ExDefType pi x k tp) pi') =
let Γ = toplevel-state.Γ s in
Γ ⊢ k ↝ k~ /
Γ ⊢ tp ⇐ k~ ↝ tp~ /
let Γ' = ctxt-type-def pi globalScope (isNothing op) x (just tp~) k~ Γ in
maybe-add-opaque-span op pi' >>
spanM-add (DefType-span Γ' pi x checking (just k~) tp~ pi' []) >>
check-redefined pi x s
(CmdDefType x k~ tp~)
([- TpVar-span Γ' pi x checking [] nothing -]
return (record s { Γ = Γ' }))
process-cmd s (ExCmdKind pi x ps k pi') =
let Γ = toplevel-state.Γ s in
check-and-add-params Γ pi' ps >>=c λ Γₚₛ ps~ →
Γₚₛ ⊢ k ↝ k~ /
let Γ' = ctxt-kind-def pi x ps~ k~ Γ in
[- DefKind-span Γ' pi x k~ pi' -]
check-redefined pi x s (CmdDefKind x ps~ k~)
([- KdVar-span Γ' (pi , x) (posinfo-plus-str pi x) ps~ checking [] nothing -]
return (record s { Γ = Γ' }))
process-cmd s (ExCmdData (DefDatatype pi pi' x ps k cs) pi'') =
let Γ = toplevel-state.Γ s
old-Γ = Γ in
[- DefDatatype-header-span pi -]
check-and-add-params Γ pi'' ps >>=c λ Γₚₛ ps' →
Γₚₛ ⊢ k ↝ k' /
let mn = ctxt.mn Γ
qx = mn # x
mps = ctxt.ps Γ ++ ps'
Γ-decl = λ Γ → ctxt-type-decl pi' x k' $ data-highlight Γ (pi' % x)
cmd-fail = CmdDefType x (params-to-kind ps' k') (TpHole pi')
fail = λ e → [- TpVar-span Γ pi' x checking [] (just e) -] return2 s cmd-fail in
process-ctrs x (pi' % x) qx mps pi' (record s {Γ = Γ-decl Γₚₛ}) cs >>=c λ Γ-cs cs~ →
maybe-else' (cedille-options.options.datatype-encoding options >>=c λ fp f → f)
(fail "Missing directive for datatype encoding. Please add a datatype-encoding directive to your .cedille/options file. See cedille/.cedille/options for the current location") λ de →
let is = kind-to-indices Γₚₛ k'
kᵢ = indices-to-kind is $ KdAbs ignored-var
(Tkt $ indices-to-tpapps is $ params-to-tpapps mps $ TpVar qx) KdStar in
either-else' (init-encoding Γₚₛ de (Data x ps' is cs~)) fail λ ecs →
check-redefined pi' x (record s {Γ = Γ-cs Γ}) (CmdDefData ecs x ps' k' cs~)
let fₓ = fresh-var (add-indices-to-ctxt is Γ) "X"
cs~ = map-fst (mn #_) <$> cs~
Γ' = Γ-cs Γ
kₘᵤ = abs-expand-kind ps' $ KdAbs ignored-var (Tkk k') KdStar
Γ' = ctxt-type-def pi' globalScope opacity-open (data-Is/ x) nothing kₘᵤ Γ'
Tₘᵤ = params-to-alls ps' $ TpApp (params-to-tpapps mps (TpVar (mn # data-Is/ x))) (Ttp (params-to-tpapps mps $ TpVar qx))
Γ' = ctxt-term-def pi' globalScope opacity-open (data-is/ x) nothing Tₘᵤ Γ'
Tₜₒ =
abs-expand-type ps' $
mall fₓ (Tkk $ indices-to-kind is KdStar) $
TpAbs Erased ignored-var (Tkt (TpApp (params-to-tpapps mps $ TpVar $ mn # data-Is/ x) $ Ttp $ TpVar fₓ)) $
indices-to-alls is $
TpAbs NotErased ignored-var (Tkt (indices-to-tpapps is $ TpVar fₓ)) $
indices-to-tpapps is $ params-to-tpapps mps $ TpVar qx
Γ' = ctxt-term-def pi' globalScope opacity-open (data-to/ x) (just id-term) Tₜₒ Γ'
Γ' = ctxt-datatype-def pi' x ps' kᵢ k' cs~ ecs Γ' in
[- DefDatatype-span Γ' pi pi' x ps' (abs-expand-kind ps' k') kₘᵤ k' Tₘᵤ Tₜₒ cs~ k pi'' -]
[- TpVar-span Γ' pi' x checking (kind-data old-Γ k' :: params-data old-Γ ps') nothing -]
return (record s {Γ = Γ'})
-- TODO ignore checking but still gen spans if need-to-check false?
process-cmd s (ExCmdImport (ExImport pi op pi' x oa as pi'')) =
let fnₒ = ctxt.fn (toplevel-state.Γ s)
ie = get-include-elt s fnₒ
oa' = maybe-map (λ {(ImportAs pi x) → x}) oa in
case trie-lookup (include-elt.import-to-dep ie) x of λ where
nothing → [- Import-span pi "missing" pi'' [] (just ("File not found: " ^ x)) -]
return2 (set-include-elt s fnₒ (record ie {err = tt}))
(CmdImport (Import op x x oa' []))
(just fnᵢ) →
spanM-push (process-file s fnᵢ x) >>= uncurry₂ λ s f _ →
process-import (toplevel-state.Γ s) op oa fnₒ fnᵢ
(lookup-mod-params (toplevel-state.Γ s) fnᵢ)
(maybe-else' (lookup-mod-params (toplevel-state.Γ s) fnₒ) [] id) >>=c λ e as~ →
let s-e = scope-file s fnₒ fnᵢ oa' as~
Γ = toplevel-state.Γ s in
[- Import-span pi fnᵢ pi'' [] (snd s-e ||-maybe e) -]
return2 (fst s-e) (CmdImport (Import op fnᵢ x oa' as~))
where
-- When importing a file publicly, you may use any number of arguments as long as the
-- parameters of the current module are not free in them.
-- You may then use any number of single-variable parameters from the current module
-- as arguments as long as they retain the same order as before and have no non-parameter
-- arguments between them
-- (so parameters A, B, C, ..., Z can be used as arguments ·C ·X, but not ·X ·C)
public-import-params-ok : params → args → err-m
public-import-params-ok ps = h nothing where
err = just "You can only use parameters for arguments to public imports if the are in order at the end"
params-order : params → trie ℕ
params-order = h 0 where
h : ℕ → params → trie ℕ
h n [] = empty-trie
h n (Param me x atk :: ps) = trie-insert (h (suc n) ps) x n
pso = params-order ps
ps-free : arg → err-m → err-m
ps-free a e = if ~ are-free-in-h pso (free-vars-arg a) then e else err
h : maybe ℕ → args → err-m
h c (a :: as) =
maybe-else' (arg-var a >>= trie-lookup pso)
(maybe-else' c (ps-free a $ h nothing as) λ _ → err) λ aₙ →
maybe-else' c (h (just aₙ) as) λ cₙ →
if cₙ ≥ aₙ then err else h (just aₙ) as
h n [] = nothing
process-import : ctxt → opt-public → maybe import-as → (cur imp : filepath) → maybe params → params → spanM (err-m × args)
process-import Γ op oa fnₒ fnᵢ nothing _ = return2 (just "Undefined module import (this probably shouldn't happen?)") []
process-import Γ Public (just _) fnₒ fnᵢ (just psᵢ) psₒ = return2 (just "Public imports aren't allowed to be qualified") []
process-import Γ op oa fnₒ fnᵢ (just psᵢ) psₒ =
optAs-posinfo-var Γ oa (pi' , x) >>= λ pi-v →
check-args Γ as psᵢ >>= λ as~ →
[- Import-module-span Γ (pi' , x) psᵢ [ location-data (fnᵢ , "1") ] nothing -]
return2 (ifMaybe op $ public-import-params-ok psₒ as~) as~
process-cmds s (c :: cs) =
process-cmd s c >>=c λ s c →
process-cmds s cs >>=c λ s cs →
return2 s (c :: cs)
process-cmds s [] = return2 s []
process-ctrs uX lX mX ps piₓ s csₒ c? = h s csₒ c? where
h : toplevel-state → ex-ctrs → spanM ((ctxt → ctxt) × ctrs)
h s [] = return2 id []
h s (ExCtr pi x T :: cs) =
let Γ = toplevel-state.Γ s in
Γ ⊢ T ⇐ KdStar ↝ T~ /
let T = hnf-ctr Γ lX T~
𝕃tpkd-to-string = foldr (λ tk s → rope-to-string (tpkd-to-string Γ tk) ^ " ; " ^ s) ""
neg-ret-err : maybe string
neg-ret-err =
let err-msg = λ s s' → just (uX ^ s ^ " type of the constructor: " ^ s') in
case run-posM (positivity.ctr-positive lX Γ T) of
λ where
(ctorOk , l) → nothing
(ctorNegative , l) → err-msg " occurs negatively in the"
("Searching types: " ^ 𝕃tpkd-to-string l)
(ctorNotInReturnType , l) → err-msg " is not the return" "" in
let T = [ Γ - TpVar mX / lX ] T
Tₚₛ = [ Γ - params-to-tpapps ps (TpVar mX) / lX ] T~ in
h s cs >>=c λ Γ-f cs →
let Γ = toplevel-state.Γ s
Γ-f' = ctxt-ctr-def pi x Tₚₛ ps (length csₒ) (length csₒ ∸ suc (length cs)) in
check-redefined pi x s (Ctr x T :: cs)
(let Γ = Γ-f' Γ in
[- Var-span Γ pi x checking
[ summary-data x (ctxt-type-def piₓ globalScope opacity-open uX nothing KdStar Γ)
(abs-expand-type ps T) ] neg-ret-err -]
return (record s {Γ = Γ})) >>=c λ s →
return2 (Γ-f ∘ Γ-f')
process-params s pi ps =
let Γ = toplevel-state.Γ s in
check-and-add-params Γ pi ps >>=c λ Γₚₛ ps →
return2
(record s {Γ = ctxt-add-current-params (record Γₚₛ { ps = ps })})
ps
process-start s filename pn (ExModule is pi1 pi2 mn ps cs pi3) =
spanM-push (progress-update pn) >>
process-cmds s (map ExCmdImport is) >>=c λ s is' →
process-params s (params-end-pos first-position ps) ps >>=c λ s ps →
process-cmds s cs >>=c λ s cs →
process-cwst s filename >>= λ s →
let pi2' = posinfo-plus-str pi2 mn in
[- File-span (toplevel-state.Γ s) first-position (posinfo-plus pi3 1) filename -]
[- Module-span pi2 pi2' -]
[- Module-header-span pi1 pi2' -]
return2 s (Module mn ps (is' ++ cs))
-- where
-- unqual-cmd : ctxt → renamectxt → cmd → cmd
-- unqual-cmd Γ ρ (CmdDefTerm x t) = CmdDefTerm x (subst-renamectxt Γ ρ t)
-- unqual-cmd Γ ρ (CmdDefType x k T) = CmdDefType x (subst-renamectxt Γ ρ k) (subst-renamectxt Γ ρ T)
-- unqual-cmd Γ ρ (CmdDefKind x ps k) = CmdDefKind x (substh-params Γ ρ empty-trie ps) (subst-renamectxt (add-params-to-ctxt ps Γ) ρ k)
-- unqual-cmd Γ ρ (CmdDefData eds x ps k cs) = CmdDefData eds x (substh-params Γ ρ empty-trie ps) (subst-renamectxt (add-params-to-ctxt ps Γ) ρ k) (map-snd (subst-renamectxt (add-params-to-ctxt ps Γ) ρ) <$> cs)
-- unqual-cmd Γ ρ (CmdImport (Import op fnᵢ x oa as)) = CmdImport (Import op fnᵢ x oa (subst-renamectxt Γ ρ -arg_ <$> as))
{- process (type-check if necessary) the given file.
We assume the given top-level state has a syntax tree associated with the file. -}
process-file s filename pn with get-include-elt s filename
process-file s filename pn | ie =
proceed s (include-elt.ast ie) (include-elt.ast~ ie)
(set-need-to-add-symbols-to-context-include-elt ie ff) >>= λ where
(s , ie , ret-mod , f) → return ({-set-include-elt s filename ie-} s , f , ret-mod)
where
proceed : toplevel-state → maybe ex-file → maybe file → include-elt →
mF (toplevel-state × include-elt × (string × string × params × qualif) × file)
proceed s nothing f~ ie' =
progress-update filename >>
-- write-to-log "should not happen" >>
return (s , ie' , ctxt-get-current-mod (toplevel-state.Γ s) ,
maybe-else' f~ (Module ignored-var [] []) id) {- should not happen -}
proceed s (just x) f~ ie' with include-elt.need-to-add-symbols-to-context ie
proceed s (just x) (just f~) ie' | ff =
let Γ = toplevel-state.Γ s
mod = ctxt.fn Γ , ctxt.mn Γ , ctxt.ps Γ , ctxt.qual Γ in
return (s , ie' , mod , f~)
proceed (mk-toplevel-state ip fns is Γ logFilePath) (just x) f~ ie' | _
with include-elt.do-type-check ie | ctxt-get-current-mod Γ
proceed (mk-toplevel-state ip fns is Γ logFilePath) (just x) f~ ie' | _ | do-check | prev-mod =
let Γ = ctxt-initiate-file Γ filename (start-modname x) in
process-start (mk-toplevel-state ip fns (trie-insert is filename ie') Γ logFilePath)
filename pn x empty-spans >>= λ where
((mk-toplevel-state ip fns is Γ logFilePath , f) , ss) →
let ret-mod = ctxt.fn Γ , ctxt.mn Γ , ctxt.ps Γ , ctxt.qual Γ
ie'' = if do-check then set-spans-include-elt ie' ss f else record ie' { ast~ = include-elt.ast~ ie' ||-maybe just f } in
progress-update pn >> return
(mk-toplevel-state ip (if do-check then (filename :: fns) else fns) (trie-insert is filename ie'')
(ctxt-set-current-mod Γ prev-mod) logFilePath ,
ie'' ,
ret-mod ,
f)
-- proceed s (just x) f~ ie' | ff =
-- return (s , ie' , ctxt-get-current-mod (toplevel-state.Γ s) ,
-- maybe-else' f~ (Module ignored-var [] []) id)
|
{
"alphanum_fraction": 0.6231264749,
"avg_line_length": 48.3919753086,
"ext": "agda",
"hexsha": "a2e28d0623b7ad6029b97ca62fde82942b3c3cae",
"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": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ice1k/cedille",
"max_forks_repo_path": "src/process-cmd.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"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": "ice1k/cedille",
"max_issues_repo_path": "src/process-cmd.agda",
"max_line_length": 211,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ice1k/cedille",
"max_stars_repo_path": "src/process-cmd.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5299,
"size": 15679
}
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Naturals | Nat
type
N : 0-ary
term
ze : N
su : N -> N
nrec : N α (α,N).α -> α
theory
(zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z
(suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n]
-}
module Naturals.Signature where
open import SOAS.Context
-- Type declaration
data NatT : Set where
N : NatT
open import SOAS.Syntax.Signature NatT public
open import SOAS.Syntax.Build NatT public
-- Operator symbols
data Natₒ : Set where
zeₒ suₒ : Natₒ
nrecₒ : {α : NatT} → Natₒ
-- Term signature
Nat:Sig : Signature Natₒ
Nat:Sig = sig λ
{ zeₒ → ⟼₀ N
; suₒ → (⊢₀ N) ⟼₁ N
; (nrecₒ {α}) → (⊢₀ N) , (⊢₀ α) , (α , N ⊢₂ α) ⟼₃ α
}
open Signature Nat:Sig public
|
{
"alphanum_fraction": 0.5664018161,
"avg_line_length": 19.152173913,
"ext": "agda",
"hexsha": "53c6bca83b03ef1e847ec765684a85da51c7ef0c",
"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/Naturals/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/Naturals/Signature.agda",
"max_line_length": 100,
"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/Naturals/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": 359,
"size": 881
}
|
{-# OPTIONS --instance-search-depth=10 #-}
data ⊥ : Set where
it : {A : Set} {{_ : A}} → A
it {{x}} = x
postulate Eq : Set → Set
instance
postulate weaken : Eq ⊥ → Eq _
loop : Eq ⊥
loop = it
|
{
"alphanum_fraction": 0.5583756345,
"avg_line_length": 14.0714285714,
"ext": "agda",
"hexsha": "0c5e96464470dafceb06da07fb77d1b1498cf586",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue2269.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue2269.agda",
"max_line_length": 42,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue2269.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": 69,
"size": 197
}
|
{-# OPTIONS --universe-polymorphism #-}
module Issue228 where
postulate
Level : Set
zero : Level
suc : Level → Level
∞ : Level
_⊔_ : Level → Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
infixl 6 _⊔_
data _×_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
_,_ : A → B → A × B
data Large : Set ∞ where
large : Large
data Small : Set₁ where
small : Set → Small
P : Set
P = Large × Small
[_] : Set → P
[ A ] = (large , small A)
potentially-bad : P
potentially-bad = [ P ]
|
{
"alphanum_fraction": 0.57,
"avg_line_length": 16.2162162162,
"ext": "agda",
"hexsha": "7f65470ae43add339bdf3482d13ffa8fb5c7d686",
"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/Issue228.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/Issue228.agda",
"max_line_length": 58,
"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/Issue228.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": 216,
"size": 600
}
|
-- {-# OPTIONS -v tc.polarity:10 -v tc.conv.elim:25 #-}
module Issue755 where
open import Common.Prelude renaming (Nat to ℕ)
open import Common.Equality
abstract
foo : Bool → ℕ → ℕ
foo true x = 0
foo false x = 0
-- should work
works : ∀{b} → foo b 0 ≡ foo b 1 → foo b 0 ≡ foo b 1
works refl = refl
-- should fail
test : ∀{b} → foo b 0 ≡ foo b 1 → foo b 0 ≡ foo b 1
test refl = refl
-- 0 != 1 of type ℕ
-- when checking that the pattern refl has type foo 0 ≡ foo 1
|
{
"alphanum_fraction": 0.6203319502,
"avg_line_length": 21.9090909091,
"ext": "agda",
"hexsha": "d2c5dc45024dd3133db1818de6e5b17ebf85140d",
"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/Issue755.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/Issue755.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/Issue755.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": 177,
"size": 482
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.CohomologyRings.Coproduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_ ; snotz to nsnotz)
open import Cubical.Data.Sigma
open import Cubical.Data.Sum
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.DirProd
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.DirectProd
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
open import Cubical.HITs.SetTruncation as ST
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Coproduct
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.CohomologyRing
private variable
ℓ ℓ' : Level
module Equiv-Coproduct-Properties
{X : Type ℓ}
{Y : Type ℓ'}
where
open Iso
open IsGroupHom
open GroupStr
open PlusBis
open RingStr (snd (H*R X)) using ()
renaming
( 0r to 0H*X
; 1r to 1H*X
; _+_ to _+H*X_
; -_ to -H*X_
; _·_ to _cupX_
; +Assoc to +H*XAssoc
; +IdL to +H*XIdL
; +IdR to +H*XIdR
; +Comm to +H*XComm
; ·Assoc to ·H*XAssoc
; ·IdL to ·H*XIdL
; ·IdR to ·H*XIdR
; is-set to isSetH*X )
open RingStr (snd (H*R Y)) using ()
renaming
( 0r to 0H*Y
; 1r to 1H*Y
; _+_ to _+H*Y_
; -_ to -H*Y_
; _·_ to _cupY_
; +Assoc to +H*YAssoc
; +IdL to +H*YIdL
; +IdR to +H*YIdR
; +Comm to +H*YComm
; ·Assoc to ·H*YAssoc
; ·IdL to ·H*YIdL
; ·IdR to ·H*YIdR
; is-set to isSetH*Y )
-- warning this does not open H*(X×Y) !
-- This just a notation shorter and pratical
open RingStr (snd (DirectProd-Ring (H*R X) (H*R Y))) using ()
renaming
( 0r to 0H*X×Y
; 1r to 1H*X×Y
; _+_ to _+H*X×Y_
; -_ to -H*X×Y_
; _·_ to _cupX×Y_
; +Assoc to +H*X×YAssoc
; +IdL to +H*X×YIdL
; +IdR to +H*X×YIdR
; +Comm to +H*X×YComm
; ·Assoc to ·H*X×YAssoc
; ·IdL to ·H*X×YIdL
; ·IdR to ·H*X×YIdR
; is-set to isSetH*X×Y )
open RingStr (snd (H*R (X ⊎ Y))) using ()
renaming
( 0r to 0H*X⊎Y
; 1r to 1H*X⊎Y
; _+_ to _+H*X⊎Y_
; -_ to -H*X⊎Y_
; _·_ to _cupX⊎Y_
; +Assoc to +H*X⊎YAssoc
; +IdL to +H*X⊎YIdL
; +IdR to +H*X⊎YIdR
; +Comm to +H*X⊎YComm
; ·Assoc to ·H*X⊎YAssoc
; ·IdL to ·H*X⊎YIdL
; ·IdR to ·H*X⊎YIdR
; is-set to isSetH*X⊎Y )
-----------------------------------------------------------------------------
-- Notation needed for type checking
-- indeed several base coexists and two cannot be inferef without implicit argument
-- it is clearer to add a notation
baseX : (n : ℕ) → (x : coHom n X) → H* X
baseX n x = base n x
baseY : (n : ℕ) → (x : coHom n Y) → H* Y
baseY n x = base n x
-----------------------------------------------------------------------------
-- Direct Sens
H*-X⊎Y→H*-X×H*-Y : H* (X ⊎ Y) → (H* X) × (H* Y)
H*-X⊎Y→H*-X×H*-Y =
DS-Rec-Set.f _ _ _ _
isSetH*X×Y
(0H*X , 0H*Y)
(λ n a → (base n (fst (fun (fst Equiv-Coproduct-CoHom) a))) , (base n (snd (fun (fst Equiv-Coproduct-CoHom) a))))
_+H*X×Y_
+H*X×YAssoc
+H*X×YIdR
+H*X×YComm
(λ n → ≡-× ((cong (λ A → baseX n (fst A)) (pres1 (snd Equiv-Coproduct-CoHom))) ∙ base-neutral n)
(((cong (λ B → baseY n (snd B)) (pres1 (snd Equiv-Coproduct-CoHom))) ∙ base-neutral n)))
λ n a b → sym (≡-× (cong (λ A → baseX n (fst A)) (pres· (snd Equiv-Coproduct-CoHom) a b)
∙ cong (base n) (helper1 _ _ _)
∙ sym (base-add n _ _))
(cong (λ B → baseY n (snd B)) (pres· (snd Equiv-Coproduct-CoHom) a b)
∙ cong (base n) (helper2 _ _ _)
∙ sym (base-add n _ _)))
where
helper1 : (n : ℕ) → (x y : coHom n X × coHom n Y)
→ fst ((DirProd (coHomGr n X) (coHomGr n Y) .snd GroupStr.· x) y) ≡ ((fst x) +ₕ (fst y))
helper1 n (fst₁ , snd₁) (fst₂ , snd₂) = refl
helper2 : (n : ℕ) → (x y : coHom n X × coHom n Y)
→ snd ((DirProd (coHomGr n X) (coHomGr n Y) .snd GroupStr.· x) y) ≡ ((snd x) +ₕ (snd y))
helper2 n (fst₁ , snd₁) (fst₂ , snd₂) = refl
-----------------------------------------------------------------------------
-- Converse Sens
-- One need to convert seperatly the X an Y
-- Otherwise the traduction fails in the case base n a , 0
-- because one need then to lift x + 0 ≡ 0
-- which doesn't work because the + being lifted is on H*(Y) and not H*(X)×H*(Y)
H*-X→H*-X⊎Y : H*(X) → H*(X ⊎ Y)
H*-X→H*-X⊎Y = DS-Rec-Set.f _ _ _ _ isSetH*X⊎Y
0H*X⊎Y
(λ n a → base n (inv (fst Equiv-Coproduct-CoHom) (a , (0ₕ n))))
_+H*X⊎Y_
+H*X⊎YAssoc
+H*X⊎YIdR
+H*X⊎YComm
(λ n → cong (base n) (pres1 (snd (invGroupIso Equiv-Coproduct-CoHom))) ∙ base-neutral n)
λ n a a' → base-add _ _ _
∙ cong (base n) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) _ _))
∙ cong (base n) (cong (inv (fst Equiv-Coproduct-CoHom))
(≡-× refl (AbGroupStr.+IdL (snd (coHomGroup n Y)) (0ₕ n))))
H*-Y→H*-X⊎Y : H*(Y) → H*(X ⊎ Y)
H*-Y→H*-X⊎Y = DS-Rec-Set.f _ _ _ _ isSetH*X⊎Y
0H*X⊎Y
(λ m b → base m (inv (fst Equiv-Coproduct-CoHom) (0ₕ m , b)))
_+H*X⊎Y_
+H*X⊎YAssoc
+H*X⊎YIdR
+H*X⊎YComm
(λ m → cong (base m) (pres1 (snd (invGroupIso Equiv-Coproduct-CoHom))) ∙ base-neutral m)
λ m b b' → base-add _ _ _
∙ cong (base m) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) (0ₕ m , b) (0ₕ m , b')))
∙ cong (base m) (cong (inv (fst Equiv-Coproduct-CoHom)) (≡-× (AbGroupStr.+IdL (snd (coHomGroup m X)) (0ₕ m)) refl))
H*-X×H*-Y→H*-X⊎Y : H*(X) × H*(Y) → H*(X ⊎ Y)
H*-X×H*-Y→H*-X⊎Y (x , y) = (H*-X→H*-X⊎Y x) +H*X⊎Y (H*-Y→H*-X⊎Y y)
H*-X×H*-Y→H*-X⊎Y-pres+ : (x y : H*(X) × H*(Y)) → H*-X×H*-Y→H*-X⊎Y (x +H*X×Y y) ≡ ((H*-X×H*-Y→H*-X⊎Y x) +H*X⊎Y (H*-X×H*-Y→H*-X⊎Y y))
H*-X×H*-Y→H*-X⊎Y-pres+ (x , y) (x' , y') = RingTheory.+ShufflePairs (H*R (X ⊎ Y)) _ _ _ _
-----------------------------------------------------------------------------
-- Section Sens
e-sectX : (x : H* X) → H*-X⊎Y→H*-X×H*-Y (H*-X→H*-X⊎Y x) ≡ (x , 0H*Y)
e-sectX = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)
refl
(λ n a → ≡-× (cong (base n) (cong fst (rightInv (fst Equiv-Coproduct-CoHom) (a , 0ₕ n))))
(cong (base n) (cong snd (rightInv (fst Equiv-Coproduct-CoHom) (a , 0ₕ n))))
∙ ≡-× refl (base-neutral n))
λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V ∙ ≡-× refl (+H*YIdR _)
e-sectY : (y : H* Y) → (H*-X⊎Y→H*-X×H*-Y (H*-Y→H*-X⊎Y y)) ≡ (0H*X , y)
e-sectY = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)
refl
(λ m b → ≡-× (cong (base m) (cong fst (rightInv (fst Equiv-Coproduct-CoHom) (0ₕ m , b))))
(cong (base m) (cong snd (rightInv (fst Equiv-Coproduct-CoHom) (0ₕ m , b))))
∙ ≡-× (base-neutral m) refl)
λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V ∙ ≡-× (+H*XIdR _) refl
e-sect : (z : H*(X) × H*(Y)) → H*-X⊎Y→H*-X×H*-Y (H*-X×H*-Y→H*-X⊎Y z) ≡ z
e-sect (x , y) = cong₂ _+H*X×Y_ (e-sectX x) (e-sectY y) ∙ ≡-× (+H*XIdR x) (+H*YIdL y)
-----------------------------------------------------------------------------
-- Retraction Sens
e-retr : (x : H*(X ⊎ Y)) → H*-X×H*-Y→H*-X⊎Y (H*-X⊎Y→H*-X×H*-Y x) ≡ x
e-retr = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X⊎Y _ _)
(+H*X⊎YIdR _)
(λ n a → ((base n (T⁻ ((fst (T a)) , 0ₕ n))) +H*X⊎Y (base n (T⁻ (0ₕ n , snd (T a)))))
≡⟨ base-add n _ _ ⟩
base n ((T⁻ ((fst (T a)) , 0ₕ n)) +ₕ (T⁻ (0ₕ n , snd (T a))))
≡⟨ cong (base n) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) ((fst (T a)) , 0ₕ n) (0ₕ n , snd (T a)))) ⟩
base n (T⁻ ( fst (T a) +ₕ 0ₕ n , 0ₕ n +ₕ snd (T a)))
≡⟨ cong (base n) (cong T⁻ (≡-× (rUnitₕ n (fst (T a))) (lUnitₕ n (snd (T a))))) ⟩
base n (T⁻ ( fst (T a) , snd (T a)))
≡⟨ cong (base n) (cong T⁻ (helper1 _ _ (T a))) ⟩
base n (T⁻ (T a))
≡⟨ cong (base n) (leftInv (fst Equiv-Coproduct-CoHom) a) ⟩
base n a ∎)
λ {U V} ind-U ind-V → (H*-X×H*-Y→H*-X⊎Y-pres+ _ _) ∙ (cong₂ _+H*X⊎Y_ ind-U ind-V)
where
T : {n : ℕ} → coHom n (X ⊎ Y) → coHom n X × coHom n Y
T {n} = fun (fst (Equiv-Coproduct-CoHom))
T⁻ : {n : ℕ} → coHom n X × coHom n Y → coHom n (X ⊎ Y)
T⁻ {n} = inv (fst (Equiv-Coproduct-CoHom))
helper1 : (A : Type ℓ) → (B : Type ℓ') → (x : A × B) → (fst x , snd x) ≡ x
helper1 A B (fst₁ , snd₁) = refl
-----------------------------------------------------------------------------
-- Ring Equiv-Coproduct-CoHomphism
H*-X⊎Y→H*-X×H*-Y-pres1 : H*-X⊎Y→H*-X×H*-Y 1H*X⊎Y ≡ (1H*X , 1H*Y)
H*-X⊎Y→H*-X×H*-Y-pres1 = refl
H*-X⊎Y→H*-X×H*-Y-pres+ : (x y : H* (X ⊎ Y)) →
H*-X⊎Y→H*-X×H*-Y ( x +H*X⊎Y y)
≡ H*-X⊎Y→H*-X×H*-Y x +H*X×Y H*-X⊎Y→H*-X×H*-Y y
H*-X⊎Y→H*-X×H*-Y-pres+ x y = refl
H*-X⊎Y→H*-X×H*-Y-pres· : (x y : H* (X ⊎ Y)) →
H*-X⊎Y→H*-X×H*-Y ( x cupX⊎Y y)
≡ H*-X⊎Y→H*-X×H*-Y x cupX×Y H*-X⊎Y→H*-X×H*-Y y
H*-X⊎Y→H*-X×H*-Y-pres· = DS-Ind-Prop.f _ _ _ _ (λ x p q i y → isSetH*X×Y _ _ (p y) (q y) i)
(λ y → refl)
(λ n a → DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)
refl
(λ m b → (base (n +' m) (fst (T (a ⌣ b)))) , base (n +' m) (snd (T (a ⌣ b)))
≡⟨ ≡-× (cong (base (n +' m)) (helperX a b))
(cong (base (n +' m)) (helperY a b)) ⟩
(base (n +' m) ((fst (T a)) ⌣ (fst (T b)))) , base (n +' m) ((snd (T a)) ⌣ (snd (T b))) ∎ )
λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V)
(λ {U V} ind-U ind-V y → cong₂ _+H*X×Y_ (ind-U y) (ind-V y))
where
T : {n : ℕ} → coHom n (X ⊎ Y) → coHom n X × coHom n Y
T {n} = fun (fst (Equiv-Coproduct-CoHom))
helperX : {n : ℕ} → {m : ℕ} → (a : coHom n (X ⊎ Y)) → (b : coHom m (X ⊎ Y))
→ fst (T (a ⌣ b)) ≡ (fst (T a)) ⌣ (fst (T b))
helperX = ST.elim (λ x → isProp→isSet λ u v i y → squash₂ _ _ (u y) (v y) i )
λ g → ST.elim (λ _ → isProp→isSet (squash₂ _ _))
(λ h → refl)
helperY : {n : ℕ} → {m : ℕ} → (a : coHom n (X ⊎ Y)) → (b : coHom m (X ⊎ Y))
→ snd (T (a ⌣ b)) ≡ (snd (T a)) ⌣ (snd (T b))
helperY = ST.elim (λ x → isProp→isSet λ u v i y → squash₂ _ _ (u y) (v y) i )
λ g → ST.elim (λ _ → isProp→isSet (squash₂ _ _))
(λ h → refl)
-----------------------------------------------------------------------------
-- Computation of the Cohomology Ring
module _
(X : Type ℓ)
(Y : Type ℓ')
where
open Equiv-Coproduct-Properties
open Iso
open RingEquivs
CohomologyRing-Coproduct : RingEquiv (H*R(X ⊎ Y)) (DirectProd-Ring (H*R X) (H*R Y))
fst (CohomologyRing-Coproduct) = isoToEquiv is
where
is : Iso (H* (X ⊎ Y)) (H* X × H* Y)
fun is = H*-X⊎Y→H*-X×H*-Y
inv is = H*-X×H*-Y→H*-X⊎Y
rightInv is = e-sect
leftInv is = e-retr
snd (CohomologyRing-Coproduct) = makeIsRingHom
H*-X⊎Y→H*-X×H*-Y-pres1
H*-X⊎Y→H*-X×H*-Y-pres+
H*-X⊎Y→H*-X×H*-Y-pres·
|
{
"alphanum_fraction": 0.4548301614,
"avg_line_length": 39.785942492,
"ext": "agda",
"hexsha": "12c5b4efb8bd04eabb4ce3ea7409e70a7fe45fa1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/CohomologyRings/Coproduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/CohomologyRings/Coproduct.agda",
"max_line_length": 141,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/CohomologyRings/Coproduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5033,
"size": 12453
}
|
-- {-# OPTIONS -v tc.lhs:40 #-} {-# OPTIONS -v scope.pat:40 #-}
module Issue822 where
module M₁ where
postulate [_] : Set
module M₂ where
data D : Set₁ where
[_] : Set → D
module M₃ where
data D : Set₁ where
[_] : Set → D
open M₁
open M₂
open M₃
Foo : _ → Set
Foo [ A ] = A
-- Strange error message:
-- Bug.agda:16,1-14
-- Left hand side gives too many arguments to a function of type
-- D → Set
-- when checking that the clause Foo [ A ] = A has type D → Set
-- If the two open statements are swapped, then we get a more
-- reasonable error message:
-- Bug.agda:16,1-10
-- Ambiguous name [_]. It could refer to any one of
-- M₂.[_] bound at /home/nad/research/dtp/pretty/Bug.agda:10,5-8
-- M₁.[_] bound at /home/nad/research/dtp/pretty/Bug.agda:5,13-16
-- when scope checking the left-hand side Foo [ A ] in the definition
-- of Foo
-- One could perhaps also argue that the code above should be
-- syntactically correct, because M₁.[_] can't be used in the pattern
-- (except for under a dot).
-- Andreas, 2013-03-21
-- To reproduce an error, one now needs ambiguous constructors.
|
{
"alphanum_fraction": 0.6678635548,
"avg_line_length": 23.2083333333,
"ext": "agda",
"hexsha": "39028c902e87ffa414f9df4dc2b22e084f665b89",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue822.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue822.agda",
"max_line_length": 69,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue822.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": 349,
"size": 1114
}
|
{-# OPTIONS --no-auto-inline #-}
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.List
open import Agda.Builtin.Equality
_>>_ : {A B : Set} → TC A → TC B → TC B
m >> m' = m >>= λ _ → m'
-- Normally auto-inlined
id : {A : Set} → A → A
id x = x
id-inline : {A : Set} → A → A
id-inline x = x
{-# INLINE id-inline #-}
f₁ : Nat → Nat
f₁ n = id n
f₂ : Nat → Nat
f₂ n = id-inline n
macro
rhs : Name → Term → TC ⊤
rhs f hole = do
function (clause _ _ rhs ∷ _) ← getDefinition f
where _ → typeError (strErr "fail" ∷ [])
`rhs ← quoteTC rhs
unify hole `rhs
pattern vArg x = arg (arg-info visible relevant) x
pattern hArg x = arg (arg-info hidden relevant) x
-- Should not be inlined
check₁ : rhs f₁ ≡ def (quote id) (hArg (def (quote Nat) []) ∷ vArg (var 0 []) ∷ [])
check₁ = refl
-- Should be inlined
check₂ : rhs f₂ ≡ var 0 []
check₂ = refl
|
{
"alphanum_fraction": 0.6185031185,
"avg_line_length": 21.8636363636,
"ext": "agda",
"hexsha": "629628e0596e5c299ab6b790debf12c8aae80e23",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue3075.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"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": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3075.agda",
"max_line_length": 83,
"max_stars_count": null,
"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/Issue3075.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 327,
"size": 962
}
|
-- Andreas, 2017-08-23, issue #2714
-- This file should compile from within the interaction mode
-- without warning about missing main function.
{-# OPTIONS --no-main #-}
|
{
"alphanum_fraction": 0.7167630058,
"avg_line_length": 24.7142857143,
"ext": "agda",
"hexsha": "30d15c344e1a5cd0e16ef67f4cd150da843eee7f",
"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/interaction/Issue2714.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/interaction/Issue2714.agda",
"max_line_length": 60,
"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/interaction/Issue2714.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": 41,
"size": 173
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Order morphisms
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Relation.Binary.Morphism.Structures
{a b} {A : Set a} {B : Set b}
where
open import Data.Product using (_,_)
open import Function.Definitions
open import Level
open import Relation.Binary.Morphism.Definitions A B
private
variable
ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level
------------------------------------------------------------------------
-- Raw relations
------------------------------------------------------------------------
record IsRelHomomorphism (_∼₁_ : Rel A ℓ₁) (_∼₂_ : Rel B ℓ₂)
(⟦_⟧ : A → B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
cong : Homomorphic₂ _∼₁_ _∼₂_ ⟦_⟧
record IsRelMonomorphism (_∼₁_ : Rel A ℓ₁) (_∼₂_ : Rel B ℓ₂)
(⟦_⟧ : A → B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isHomomorphism : IsRelHomomorphism _∼₁_ _∼₂_ ⟦_⟧
injective : Injective _∼₁_ _∼₂_ ⟦_⟧
open IsRelHomomorphism isHomomorphism public
record IsRelIsomorphism (_∼₁_ : Rel A ℓ₁) (_∼₂_ : Rel B ℓ₂)
(⟦_⟧ : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isMonomorphism : IsRelMonomorphism _∼₁_ _∼₂_ ⟦_⟧
surjective : Surjective _∼₁_ _∼₂_ ⟦_⟧
open IsRelMonomorphism isMonomorphism
bijective : Bijective _∼₁_ _∼₂_ ⟦_⟧
bijective = injective , surjective
------------------------------------------------------------------------
-- Raw orders
------------------------------------------------------------------------
record IsOrderHomomorphism (_≈₁_ : Rel A ℓ₁) (_≈₂_ : Rel B ℓ₂)
(_∼₁_ : Rel A ℓ₃) (_∼₂_ : Rel B ℓ₄)
(⟦_⟧ : A → B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ ℓ₄)
where
field
cong : Homomorphic₂ _≈₁_ _≈₂_ ⟦_⟧
mono : Homomorphic₂ _∼₁_ _∼₂_ ⟦_⟧
module Eq where
isRelHomomorphism : IsRelHomomorphism _≈₁_ _≈₂_ ⟦_⟧
isRelHomomorphism = record { cong = cong }
isRelHomomorphism : IsRelHomomorphism _∼₁_ _∼₂_ ⟦_⟧
isRelHomomorphism = record { cong = mono }
record IsOrderMonomorphism (_≈₁_ : Rel A ℓ₁) (_≈₂_ : Rel B ℓ₂)
(_∼₁_ : Rel A ℓ₃) (_∼₂_ : Rel B ℓ₄)
(⟦_⟧ : A → B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ ℓ₄)
where
field
isOrderHomomorphism : IsOrderHomomorphism _≈₁_ _≈₂_ _∼₁_ _∼₂_ ⟦_⟧
injective : Injective _≈₁_ _≈₂_ ⟦_⟧
cancel : Injective _∼₁_ _∼₂_ ⟦_⟧
open IsOrderHomomorphism isOrderHomomorphism public
hiding (module Eq)
module Eq where
isRelMonomorphism : IsRelMonomorphism _≈₁_ _≈₂_ ⟦_⟧
isRelMonomorphism = record
{ isHomomorphism = IsOrderHomomorphism.Eq.isRelHomomorphism isOrderHomomorphism
; injective = injective
}
isRelMonomorphism : IsRelMonomorphism _∼₁_ _∼₂_ ⟦_⟧
isRelMonomorphism = record
{ isHomomorphism = isRelHomomorphism
; injective = cancel
}
record IsOrderIsomorphism (_≈₁_ : Rel A ℓ₁) (_≈₂_ : Rel B ℓ₂)
(_∼₁_ : Rel A ℓ₃) (_∼₂_ : Rel B ℓ₄)
(⟦_⟧ : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ ℓ₄)
where
field
isOrderMonomorphism : IsOrderMonomorphism _≈₁_ _≈₂_ _∼₁_ _∼₂_ ⟦_⟧
surjective : Surjective _≈₁_ _≈₂_ ⟦_⟧
open IsOrderMonomorphism isOrderMonomorphism public
hiding (module Eq)
module Eq where
isRelIsomorphism : IsRelIsomorphism _≈₁_ _≈₂_ ⟦_⟧
isRelIsomorphism = record
{ isMonomorphism = IsOrderMonomorphism.Eq.isRelMonomorphism isOrderMonomorphism
; surjective = surjective
}
|
{
"alphanum_fraction": 0.5234934962,
"avg_line_length": 31.9237288136,
"ext": "agda",
"hexsha": "c1ac4d2cd9913efeba00e40c1d21b85e23b521bc",
"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/Relation/Binary/Morphism/Structures.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/Relation/Binary/Morphism/Structures.agda",
"max_line_length": 85,
"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/Relation/Binary/Morphism/Structures.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": 1339,
"size": 3767
}
|
module CoInf where
open import Codata.Musical.Notation
-- Check that ∞ can be used as an "expression".
test : Set → Set
test = ∞
|
{
"alphanum_fraction": 0.7099236641,
"avg_line_length": 16.375,
"ext": "agda",
"hexsha": "d53954c95155dd1df15066e85e4b5378134ebb81",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/LibSucceed/CoInf.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/LibSucceed/CoInf.agda",
"max_line_length": 47,
"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/LibSucceed/CoInf.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": 39,
"size": 131
}
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import Groups.Definition
open import Groups.Groups
open import Groups.Homomorphisms.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Groups.Lemmas
open import Groups.Homomorphisms.Lemmas
module Groups.QuotientGroup.Definition {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (fHom : GroupHom G H f) where
quotientGroupSetoid : (Setoid {a} {d} A)
quotientGroupSetoid = ansSetoid
where
open Setoid T
open Group H
open Equivalence eq
ansSetoid : Setoid A
Setoid._∼_ ansSetoid r s = (f (r ·A (Group.inverse G s))) ∼ 0G
Equivalence.reflexive (Setoid.eq ansSetoid) {b} = transitive (GroupHom.wellDefined fHom (Group.invRight G)) (imageOfIdentityIsIdentity fHom)
Equivalence.symmetric (Setoid.eq ansSetoid) {m} {n} pr = i
where
g : f (Group.inverse G (m ·A Group.inverse G n)) ∼ 0G
g = transitive (homRespectsInverse fHom {m ·A Group.inverse G n}) (transitive (inverseWellDefined H pr) (invIdent H))
h : f (Group.inverse G (Group.inverse G n) ·A Group.inverse G m) ∼ 0G
h = transitive (GroupHom.wellDefined fHom (Equivalence.symmetric (Setoid.eq S) (invContravariant G))) g
i : f (n ·A Group.inverse G m) ∼ 0G
i = transitive (GroupHom.wellDefined fHom (Group.+WellDefined G (Equivalence.symmetric (Setoid.eq S) (invTwice G n)) (Equivalence.reflexive (Setoid.eq S)))) h
Equivalence.transitive (Setoid.eq ansSetoid) {m} {n} {o} prmn prno = transitive (GroupHom.wellDefined fHom (Group.+WellDefined G (Equivalence.reflexive (Setoid.eq S)) (Equivalence.symmetric (Setoid.eq S) (Group.identLeft G)))) k
where
g : f (m ·A Group.inverse G n) ·B f (n ·A Group.inverse G o) ∼ 0G ·B 0G
g = replaceGroupOp H reflexive reflexive prmn prno reflexive
h : f (m ·A Group.inverse G n) ·B f (n ·A Group.inverse G o) ∼ 0G
h = transitive g identLeft
i : f ((m ·A Group.inverse G n) ·A (n ·A Group.inverse G o)) ∼ 0G
i = transitive (GroupHom.groupHom fHom) h
j : f (m ·A (((Group.inverse G n) ·A n) ·A Group.inverse G o)) ∼ 0G
j = transitive (GroupHom.wellDefined fHom (fourWay+Associative G)) i
k : f (m ·A ((Group.0G G) ·A Group.inverse G o)) ∼ 0G
k = transitive (GroupHom.wellDefined fHom (Group.+WellDefined G (Equivalence.reflexive (Setoid.eq S)) (Group.+WellDefined G (Equivalence.symmetric (Setoid.eq S) (Group.invLeft G)) (Equivalence.reflexive (Setoid.eq S))))) j
quotientGroupByHom : Group (quotientGroupSetoid) _·A_
Group.+WellDefined (quotientGroupByHom) {x} {y} {m} {n} x~m y~n = ans
where
open Setoid T
open Equivalence (Setoid.eq T)
p1 : f ((x ·A y) ·A (Group.inverse G (m ·A n))) ∼ f ((x ·A y) ·A ((Group.inverse G n) ·A (Group.inverse G m)))
p2 : f ((x ·A y) ·A ((Group.inverse G n) ·A (Group.inverse G m))) ∼ f (x ·A ((y ·A (Group.inverse G n)) ·A (Group.inverse G m)))
p3 : f (x ·A ((y ·A (Group.inverse G n)) ·A (Group.inverse G m))) ∼ (f x) ·B f ((y ·A (Group.inverse G n)) ·A (Group.inverse G m))
p4 : (f x) ·B f ((y ·A (Group.inverse G n)) ·A (Group.inverse G m)) ∼ (f x) ·B (f (y ·A (Group.inverse G n)) ·B f (Group.inverse G m))
p5 : (f x) ·B (f (y ·A (Group.inverse G n)) ·B f (Group.inverse G m)) ∼ (f x) ·B (Group.0G H ·B f (Group.inverse G m))
p6 : (f x) ·B (Group.0G H ·B f (Group.inverse G m)) ∼ (f x) ·B f (Group.inverse G m)
p7 : (f x) ·B f (Group.inverse G m) ∼ f (x ·A (Group.inverse G m))
p8 : f (x ·A (Group.inverse G m)) ∼ Group.0G H
p1 = GroupHom.wellDefined fHom (Group.+WellDefined G (Equivalence.reflexive (Setoid.eq S)) (invContravariant G))
p2 = GroupHom.wellDefined fHom (Equivalence.symmetric (Setoid.eq S) (fourWay+Associative G))
p3 = GroupHom.groupHom fHom
p4 = Group.+WellDefined H reflexive (GroupHom.groupHom fHom)
p5 = Group.+WellDefined H reflexive (replaceGroupOp H (symmetric y~n) reflexive reflexive reflexive reflexive)
p6 = Group.+WellDefined H reflexive (Group.identLeft H)
p7 = symmetric (GroupHom.groupHom fHom)
p8 = x~m
ans : f ((x ·A y) ·A (Group.inverse G (m ·A n))) ∼ Group.0G H
ans = transitive p1 (transitive p2 (transitive p3 (transitive p4 (transitive p5 (transitive p6 (transitive p7 p8))))))
Group.0G (quotientGroupByHom) = Group.0G G
Group.inverse (quotientGroupByHom) = Group.inverse G
Group.+Associative (quotientGroupByHom) {a} {b} {c} = ans
where
open Setoid T
open Equivalence (Setoid.eq T)
ans : f ((a ·A (b ·A c)) ·A (Group.inverse G ((a ·A b) ·A c))) ∼ Group.0G H
ans = transitive (GroupHom.wellDefined fHom (transferToRight'' G (Group.+Associative G))) (imageOfIdentityIsIdentity fHom)
Group.identRight (quotientGroupByHom) {a} = ans
where
open Group G
open Setoid T
open Equivalence eq
transitiveG = Equivalence.transitive (Setoid.eq S)
ans : f ((a ·A 0G) ·A inverse a) ∼ Group.0G H
ans = transitive (GroupHom.wellDefined fHom (transitiveG (Group.+WellDefined G (Group.identRight G) (Equivalence.reflexive (Setoid.eq S))) (Group.invRight G))) (imageOfIdentityIsIdentity fHom)
Group.identLeft (quotientGroupByHom) {a} = ans
where
open Group G
open Setoid T
open Equivalence eq
transitiveG = Equivalence.transitive (Setoid.eq S)
ans : f ((0G ·A a) ·A (inverse a)) ∼ Group.0G H
ans = transitive (GroupHom.wellDefined fHom (transitiveG (Group.+WellDefined G (Group.identLeft G) (Equivalence.reflexive (Setoid.eq S))) (Group.invRight G))) (imageOfIdentityIsIdentity fHom)
Group.invLeft (quotientGroupByHom) {x} = ans
where
open Group G
open Setoid T
open Equivalence eq
ans : f ((inverse x ·A x) ·A (inverse 0G)) ∼ (Group.0G H)
ans = transitive (GroupHom.wellDefined fHom (Equivalence.transitive (Setoid.eq S) (replaceGroupOp G (Equivalence.symmetric (Setoid.eq S) (Group.invLeft G)) (Equivalence.symmetric (Setoid.eq S) (invIdent G)) (Equivalence.reflexive (Setoid.eq S)) ((Equivalence.reflexive (Setoid.eq S))) ((Equivalence.reflexive (Setoid.eq S)))) (identRight {0G}))) (imageOfIdentityIsIdentity fHom)
Group.invRight (quotientGroupByHom) {x} = ans
where
open Group G
open Setoid T
open Equivalence eq
ans : f ((x ·A inverse x) ·A (inverse 0G)) ∼ (Group.0G H)
ans = transitive (GroupHom.wellDefined fHom (Equivalence.transitive (Setoid.eq S) (replaceGroupOp G (Equivalence.symmetric (Setoid.eq S) (Group.invRight G)) (Equivalence.symmetric (Setoid.eq S) (invIdent G)) (Equivalence.reflexive (Setoid.eq S)) (Equivalence.reflexive (Setoid.eq S)) (Equivalence.reflexive (Setoid.eq S))) (identRight {0G}))) (imageOfIdentityIsIdentity fHom)
|
{
"alphanum_fraction": 0.6673054245,
"avg_line_length": 64.6095238095,
"ext": "agda",
"hexsha": "808f62c662a00fba0555b54ab2989ddc2a11b7aa",
"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/QuotientGroup/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": "Groups/QuotientGroup/Definition.agda",
"max_line_length": 382,
"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/QuotientGroup/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": 2318,
"size": 6784
}
|
module Prolegomenon where
open import Agda.Primitive
open import Relation.Binary
open import Algebra
open import Category.Applicative.Predicate
open import Algebra
open import Algebra.Structures
open import Category.Monad.Indexed
open import Algebra.FunctionProperties.Core
open import Function
PowerRightIdentity : ∀ {a ℓ} {A : Set a} → Rel A ℓ → ∀ {b} {B : Set b} → B → (B → A → A) → Set _
PowerRightIdentity _≈_ e _◃_ = ∀ x → (e ◃ x) ≈ x
PowerAssociative : ∀ {a b ℓ} {A : Set a} {B : Set b} → (A → A → Set ℓ) → (B → A → A) → (B → B → B) → Set _
PowerAssociative _≈_ _◃_ _∙_ = ∀ x a b → ((b ∙ a) ◃ x) ≈ (b ◃ (a ◃ x))
_over_ : ∀ {f} {F : Set f} {g} → (F → F → Set g) → ∀ {i} {I : Set i} {a} {A : Set a} → (A → I → F) → A → A → Set (i ⊔ g)
_*_ over f = λ x y → ∀ i → f x i * f y i
record IsMonoidTransformer {s ℓˢ} {S : Set s} (≈ˢ : Rel S ℓˢ) {m ℓᵐ} {M : Set m} (≈ᵐ : Rel M ℓᵐ) (∙ : Op₂ M) (ε : M) (◃ : M → S → S) : Set (s ⊔ ℓˢ ⊔ m ⊔ ℓᵐ) where
field
◃-identity : PowerRightIdentity ≈ˢ ε ◃
≈ˢ-over-◃-⟶-≈ᵐ : ≈ˢ over ◃ ⇒ ≈ᵐ
≈ᵐ-to-≈ˢ-over-◃ : ≈ᵐ ⇒ ≈ˢ over ◃
◃-extracts-∙ : PowerAssociative ≈ˢ ◃ ∙
record MonoidTransformer ℓˢ ℓ⁼ˢ ℓᵐ ℓ⁼ᵐ
: Set (lsuc (ℓˢ ⊔ ℓ⁼ˢ ⊔ ℓᵐ ⊔ ℓ⁼ᵐ)) where
field
base : Setoid ℓˢ ℓ⁼ˢ
exponent : Monoid ℓᵐ ℓ⁼ᵐ
module B = Setoid base
module E = Monoid exponent
{-
open Setoid base public renaming
(Carrier to Carrierˢ
;_≈_ to _≈ˢ_
;reflexive to reflexiveˢ
;refl to reflˢ
;trans to transˢ
;sym to symˢ
)
open Monoid exponent public renaming
(Carrier to Carrierᵐ
;_≈_ to _≈ᵐ_
;reflexive to reflexiveᵐ
;_∙_ to _∙_
;ε to ε
;refl to reflᵐ
;trans to transᵐ
;sym to symᵐ)
-}
infixl 6 _◃_
field
_◃_ : E.Carrier → B.Carrier → B.Carrier
isMonoidTransformer : IsMonoidTransformer B._≈_ E._≈_ E._∙_ E.ε _◃_
open IsMonoidTransformer isMonoidTransformer public
|
{
"alphanum_fraction": 0.5912951168,
"avg_line_length": 28.9846153846,
"ext": "agda",
"hexsha": "e2247d7e84979beb1938f7b2546ec6325e41d7db",
"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-1/Prolegomenon.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-1/Prolegomenon.agda",
"max_line_length": 162,
"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-1/Prolegomenon.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 872,
"size": 1884
}
|
module Int where
open import Agda.Builtin.FromNat
open import Agda.Builtin.FromNeg
open import Data.Char hiding (fromNat)
open import Data.Integer hiding (_≤_; suc)
open import Data.Integer.Literals
open import Data.List
open import Data.Nat hiding (_≤_)
open import Data.String
open import Data.Unit hiding (_≤_)
open import Function
open import Show
postulate
Int : Set
primShow : Int → List Char
primFromInteger : ℤ → Int
primToInteger : Int → ℤ
primMinBound : Int
primMaxBound : Int
{-# COMPILE GHC Int = type Int #-}
{-# COMPILE GHC primShow = show #-}
{-# COMPILE GHC primFromInteger = fromInteger #-}
{-# COMPILE GHC primToInteger = toInteger #-}
{-# COMPILE GHC primMinBound = minBound #-}
{-# COMPILE GHC primMaxBound = maxBound #-}
instance ShowInt : Show Int
ShowInt = fromHaskell primShow
instance Numberℤ : Number ℤ
Numberℤ = number
-- Its values can be automatically derived as instance arguments, but
-- is otherwise identical to the standard library version
data _ℕ≤_ : ℕ → ℕ → Set where
instance z≤n : ∀ {n} → zero ℕ≤ n
instance s≤s : ∀ {m n} {{m≤n : m ℕ≤ n}} → suc m ℕ≤ suc n
-- Its values can be automatically derived as instance arguments, but
-- is otherwise identical to the standard library version
data _≤_ : ℤ → ℤ → Set where
instance -≤- : {m n : ℕ} → {{n≤m : n ℕ≤ m}} → -[1+ m ] ≤ -[1+ n ]
instance -≤+ : {m n : ℕ} → (-[1+ m ]) ≤ (+ n)
instance +≤+ : {m n : ℕ} → {{m≤n : m ℕ≤ n}} → (+ m) ≤ (+ n)
-- Use a literal for the bound so that Agda can automatically check
-- the constraints for fromNat and fromNeg. Value taken from
-- https://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#t:Int
maxBound : ℤ
maxBound = 536870911
-- Use the actual bound in compiled code
{-# COMPILE GHC maxBound = toInteger (maxBound :: Int) #-}
instance NumberInt : Number Int
NumberInt = record { Constraint = Constraint ; fromNat = fromNatInt }
where
Constraint : ℕ → Set
Constraint n = (+ n) ≤ maxBound
fromNatInt : ∀ n → {{_ : Constraint n}} → Int
fromNatInt n = primFromInteger (+ n)
|
{
"alphanum_fraction": 0.6713253012,
"avg_line_length": 31.4393939394,
"ext": "agda",
"hexsha": "4dd97837612d5da8867e6fb11ceeddf60dc8fd12",
"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": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda-editor",
"max_forks_repo_path": "src/Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945",
"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": "cruhland/agda-editor",
"max_issues_repo_path": "src/Int.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda-editor",
"max_stars_repo_path": "src/Int.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 624,
"size": 2075
}
|
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.NType2
open import Preliminaries
open import Truncation_Level_Criteria
module Anonymous_Existence_CollSplit where
-- CHAPTER 4
-- SECTION 4.1
-- Lemma 4.1.2, part 1
constant-implies-path-constant : ∀ {i j} {X : Type i} {Y : Type j} → (f : X → Y) → (const f)
→ (x₁ x₂ : X) → const (ap f {x = x₁} {y = x₂})
constant-implies-path-constant {X = X} f c x₁ x₂ p₁ p₂ = claim-cor where
claim : {x₃ x₄ : X} → {p : x₃ == x₄} → (ap f p) == ! (c x₃ x₃) ∙ (c x₃ x₄)
claim {x₃} {p = idp} = ! (!-inv-l (c x₃ x₃))
claim-cor : ap f p₁ == ap f p₂
claim-cor =
ap f p₁ =⟨ claim ⟩
! (c x₁ x₁) ∙ (c x₁ x₂) =⟨ ! claim ⟩
ap f p₂ ∎
-- Lemma 4.1.2, part 2
constant-refl : ∀ {i j} {X : Type i} {Y : Type j} → (f : X → Y) → (const f)
→ (x : X) → (p : x == x) → ap f p == idp
constant-refl f c x p = constant-implies-path-constant f c x x p idp
-- todo: this is not in the library?
-- We also need the following very simple lemma:
ap-id-trivial : ∀ {i} {X : Type i} → {x₁ x₂ : X} → (p : x₁ == x₂) → ap (idf X) p == p
ap-id-trivial idp = idp
-- Main Lemma 4.1.1 needs a bit of preparation.
fix : ∀ {i} {X : Type i} → (f : X → X) → Type i
fix {X = X} f = Σ X λ x → x == f x
-- let us give a name to the map X → fix f:
to-fix : ∀ {i} {X : Type i} → (f : X → X) → (const f) → X → fix f
to-fix f c x₀ = f x₀ , c _ _
-- the other direction is just projection:
from-fix : ∀ {i} {X : Type i} → (f : X → X) → fix f → X
from-fix f (x₀ , p₀) = x₀
-- let us structure the proof of the fixed point lemma a bit:
module fixedpoint {i : ULevel} {X : Type i} (f : X → X) (c : const f) where
-- let us show that (x , p) == (x , q) first
module _ (x : X) (p q : x == f x) where
t : x == x
t = p ∙ ! q
r : f x == f x
r = ap f t
r-is-triv : r == idp
r-is-triv = constant-refl f c x t
t' : x == x
t' = ap (idf X) t
t'-is-t : t' == t
t'-is-t = ap-id-trivial t
trans-t-p-is-q : transport (λ y → y == f y) t p == q
trans-t-p-is-q =
transport (λ y → y == f y) t p =⟨ transport-is-comp (idf X) f t p ⟩
! t' ∙ p ∙ r =⟨ ap (λ s → ! s ∙ p ∙ r) t'-is-t ⟩
! t ∙ p ∙ r =⟨ ! (∙-assoc (! t) _ _) ⟩
(! t ∙ p) ∙ r =⟨ ap (λ s → (! t ∙ p) ∙ s) r-is-triv ⟩
(! t ∙ p) ∙ idp =⟨ ∙-unit-r _ ⟩
! t ∙ p =⟨ ap (λ s → s ∙ p) (!-∙ p (! q)) ⟩
(! (! q) ∙ ! p) ∙ p =⟨ ∙-assoc (! (! q)) _ _ ⟩
! (! q) ∙ ! p ∙ p =⟨ ap (λ s → ! (! q) ∙ s) (!-inv-l p) ⟩
! (! q) ∙ idp =⟨ ∙-unit-r _ ⟩
! (! q) =⟨ !-! _ ⟩
q ∎
single-x-claim : (x , p) == (x , q)
single-x-claim = pair= t (from-transp _ _ trans-t-p-is-q)
-- Now, we can prove that (x₁ , p₁) and (x₂ , p₂) are always equal:
fix-paths : has-all-paths (fix f)
fix-paths (x₁ , p₁) (x₂ , p₂) =
(x₁ , p₁) =⟨ pair= (p₁ ∙ c x₁ x₂ ∙ ! p₂) (from-transp _ (p₁ ∙ c x₁ x₂ ∙ ! p₂) idp) ⟩
(x₂ , _) =⟨ single-x-claim x₂ _ _ ⟩
(x₂ , p₂) ∎
-- finally, the proof of the fixed point lemma
fixed-point : ∀ {i} {X : Type i} → (f : X → X) → (const f) → is-prop (fix f)
fixed-point {X = X} f c = all-paths-is-prop (fixedpoint.fix-paths f c)
-- Sattler's argument
fixed-point-alt : ∀ {i} {X : Type i} → (f : X → X) → (const f) → is-prop (fix f)
fixed-point-alt {X = X} f c = inhab-to-contr-is-prop inh→contr where
inh→contr : fix f → is-contr (fix f)
inh→contr (x₀ , p₀) = equiv-preserves-level {A = Σ X λ x → x == f x₀} {B = fix f} claim-Σ (pathto-is-contr _) where
claim : (x : X) → (x == f x₀) ≃ (x == f x)
claim x = (λ p → p ∙ c x₀ x) , post∙-is-equiv _
claim-Σ : (Σ X λ x → x == f x₀) ≃ fix f
claim-Σ = equiv-Σ-snd claim
--from here, we need truncation
module with-weak-trunc where
open wtrunc
-- Corollary 4.1.3
-- let us define the following map:
trunc-to-fix : ∀ {i} {X : Type i} → (fc : coll X) → ∣∣ X ∣∣ → fix (fst fc)
trunc-to-fix (f , c) z = tr-rec (fixed-point f c) (to-fix f c) z
coll→splitSup : ∀ {i} {X : Type i} → coll X → splitSup X
coll→splitSup (f , c) = (from-fix f) ∘ trunc-to-fix (f , c)
-- Theorem 4.1.4
coll↔splitSup : ∀ {i} {X : Type i} → coll X ↔ splitSup X
coll↔splitSup {X = X} = coll→splitSup , splitSup→coll where
splitSup→coll : splitSup X → coll X
splitSup→coll hst = f , c where
f = hst ∘ ∣_∣
c : const f
c x₁ x₂ =
f x₁ =⟨ idp ⟩
hst ∣ x₁ ∣ =⟨ ap hst (prop-has-all-paths tr-is-prop _ _) ⟩
hst ∣ x₂ ∣ =⟨ idp ⟩
f x₂ ∎
-- preparation for Statement 4.1.5 - we need to prove that
-- f : X → X with an inhabitant of ∣∣ const f ∣∣ is enough
-- to show that fix f is propositional.
fixed-point-strong : ∀ {i} {X : Type i} → (f : X → X) → ∣∣ const f ∣∣ → is-prop (fix f)
fixed-point-strong {X = X} f = tr-rec {X = const f} {P = is-prop(fix f)} is-prop-is-prop (fixed-point f)
-- Statement 4.1.5 (we exclude the part which is already included in Theorem 4.1.4)
-- to get an easy proof of the addendum, we structure it in the following way:
module thm46 {i : ULevel} {X : Type i} where
module _ (fhc : Σ (X → X) (λ f → ∣∣ const f ∣∣)) where
f = fst fhc
hc = snd fhc
trunc-const-fix : ∣∣ X ∣∣ → ∣∣ const f ∣∣ → fix f
trunc-const-fix z = tr-rec {X = const f} {P = fix f} (fixed-point-strong f hc) (λ c → trunc-to-fix (f , c) z)
trunc-fix : ∣∣ X ∣∣ → fix f
trunc-fix z = trunc-const-fix z hc
g : X → X
g = fst ∘ trunc-fix ∘ ∣_∣
g-const : const g
g-const x₁ x₂ = ap (fst ∘ trunc-fix) (prop-has-all-paths tr-is-prop _ _)
coll↔hideProof : ∀ {i} {X : Type i} → coll X ↔ Σ (X → X) (λ f → ∣∣ const f ∣∣)
coll↔hideProof {X = X} = one , two where
one : coll X → Σ (X → X) (λ f → ∣∣ const f ∣∣)
one (f , c) = f , ∣ c ∣
two : (Σ (X → X) (λ f → ∣∣ const f ∣∣)) → coll X
two fhc = thm46.g fhc , thm46.g-const fhc
-- Statement 4.1.5 addendum
merely-equal : ∀ {i} {X : Type i} → (fhc : Σ (X → X) (λ f → ∣∣ const f ∣∣)) → ∣∣ ((x : X) → fst fhc x == thm46.g fhc x) ∣∣
merely-equal {X = X} (f , hc) = tr-rec tr-is-prop (∣_∣ ∘ const-equal) hc where
open thm46
const-equal : const f → (x : X) → f x == thm46.g (f , hc) x
const-equal c x =
f x =⟨ idp ⟩
fst (to-fix f c x) =⟨ ap fst (! (trunc-β _ _ x)) ⟩
fst (trunc-to-fix (f , c) ∣ x ∣) =⟨ ap fst (! (trunc-β _ _ c)) ⟩
fst (trunc-const-fix (f , hc) ∣ x ∣ ∣ c ∣) =⟨ ap (λ hc' → fst (trunc-const-fix (f , hc) ∣ x ∣ hc')) (prop-has-all-paths tr-is-prop _ _) ⟩
fst (trunc-const-fix (f , hc) ∣ x ∣ hc) =⟨ idp ⟩
fst (trunc-fix (f , hc) ∣ x ∣) =⟨ idp ⟩
g (f , hc) x ∎
|
{
"alphanum_fraction": 0.4815661618,
"avg_line_length": 39.5367231638,
"ext": "agda",
"hexsha": "d1bd7cbd060bef3bbe5ea5ac637870f2f0e2069c",
"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": "nicolai/thesis/Anonymous_Existence.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": "nicolai/thesis/Anonymous_Existence.agda",
"max_line_length": 144,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/thesis/Anonymous_Existence.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": 2904,
"size": 6998
}
|
{-# OPTIONS --without-K #-}
module PathStructure.Unit where
open import Equivalence
open import Types
split-path : {x y : ⊤} → x ≡ y → ⊤
split-path _ = _
merge-path : {x y : ⊤} → ⊤ → x ≡ y
merge-path _ = refl
split-merge-eq : {x y : ⊤} → (x ≡ y) ≃ ⊤
split-merge-eq
= split-path
, (merge-path , λ _ → refl)
, (merge-path , J {A = ⊤}
(λ _ _ p → refl ≡ p)
(λ _ → refl) _ _)
|
{
"alphanum_fraction": 0.534351145,
"avg_line_length": 19.65,
"ext": "agda",
"hexsha": "6f34b75edd471db971d8394e6a91a7072f466d9b",
"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": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/PathStructure/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"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": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/PathStructure/Unit.agda",
"max_line_length": 40,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/PathStructure/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 152,
"size": 393
}
|
-- Andreas, 2017-11-01, issue #2824
-- Allow built-ins that define a new name to be in parametrized module.
module Issue2824SizeU (A : Set) where -- This is the top-level module header.
{-# BUILTIN SIZEUNIV SizeU #-}
-- Should succeed.
|
{
"alphanum_fraction": 0.7083333333,
"avg_line_length": 26.6666666667,
"ext": "agda",
"hexsha": "e83b7ebf7112d3be16cc38d6fb3080224a42a693",
"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/Issue2824SizeU.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/Issue2824SizeU.agda",
"max_line_length": 78,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2824SizeU.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": 68,
"size": 240
}
|
open import Agda.Builtin.Nat
data Vec (A : Set) : Nat → Set where
variable
A : Set
x : A
n : Nat
xs : Vec A n
postulate
IsNil : Vec A 0 → Set
foo : (xs : Vec A n) → IsNil xs
foo = {!!}
|
{
"alphanum_fraction": 0.5566502463,
"avg_line_length": 11.9411764706,
"ext": "agda",
"hexsha": "c05bda6e019d38cfdb390ca8c6c034ff7baff918",
"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/Issue3276.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/Issue3276.agda",
"max_line_length": 36,
"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/Issue3276.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": 82,
"size": 203
}
|
module prelude.Stream where
open import prelude
open import Data.List as L using (List)
record Stream (a : Set) : Set where
constructor _∷_
coinductive
field
hd : a
tl : Stream a
open Stream
take : ∀ {a} → ℕ → Stream a → List a
take ℕz xs = L.[]
take (ℕs n) xs = hd xs L.∷ take n (tl xs)
|
{
"alphanum_fraction": 0.6144200627,
"avg_line_length": 18.7647058824,
"ext": "agda",
"hexsha": "87658d6a90797166226205fe3146e90a4ab86916",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-30T11:45:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-10T17:19:37.000Z",
"max_forks_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dspivak/poly",
"max_forks_repo_path": "code-examples/agda/prelude/Stream.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_issues_repo_issues_event_max_datetime": "2022-01-12T10:06:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-02T02:29:39.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dspivak/poly",
"max_issues_repo_path": "code-examples/agda/prelude/Stream.agda",
"max_line_length": 41,
"max_stars_count": 53,
"max_stars_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mstone/poly",
"max_stars_repo_path": "code-examples/agda/prelude/Stream.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-18T16:31:04.000Z",
"num_tokens": 104,
"size": 319
}
|
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
{-# OPTIONS --allow-exec #-}
open import Vehicle
open import Vehicle.Data.Tensor
open import Data.Product
open import Data.Integer as ℤ using (ℤ)
open import Data.Rational as ℚ using (ℚ)
open import Data.List
open import Relation.Binary.PropositionalEquality
module reachability-output where
private
VEHICLE_PROJECT_FILE = "TODO_projectFile"
f : Tensor ℚ (2 ∷ []) → ℚ
f = evaluate record
{ projectFile = VEHICLE_PROJECT_FILE
; networkUUID = "TODO_networkUUID"
}
abstract
reachable : ∃ λ (x : Tensor ℚ (2 ∷ [])) → f x ≡ ℤ.+ 0 ℚ./ 1
reachable = checkProperty record
{ projectFile = VEHICLE_PROJECT_FILE
; propertyUUID = "TODO_propertyUUID"
}
|
{
"alphanum_fraction": 0.7071759259,
"avg_line_length": 25.4117647059,
"ext": "agda",
"hexsha": "8f417c1a571454800f13fd759febc047fb030a45",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-11-16T14:30:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-03-15T15:22:31.000Z",
"max_forks_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "wenkokke/vehicle",
"max_forks_repo_path": "examples/network/reachability/reachability-output.agda",
"max_issues_count": 53,
"max_issues_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_issues_repo_issues_event_max_datetime": "2021-12-15T22:42:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-16T07:26:42.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "wenkokke/vehicle",
"max_issues_repo_path": "examples/network/reachability/reachability-output.agda",
"max_line_length": 61,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "wenkokke/vehicle",
"max_stars_repo_path": "examples/network/reachability/reachability-output.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T01:35:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-24T05:55:15.000Z",
"num_tokens": 247,
"size": 864
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import groups.ExactSequence
open import groups.HomSequence
module cw.cohomology.grid.LongExactSequence {i} (CT : CohomologyTheory i)
{X Y Z : Ptd i} (n : ℤ) (f : X ⊙→ Y) (g : Y ⊙→ Z) where
open CohomologyTheory CT
open import cohomology.PtdMapSequence CT
open import cw.cohomology.grid.CofiberSplit (fst f) (fst g)
open import cw.cohomology.grid.PtdMap f g
{-
X --> Y ----> Z
| | |
v v v
1 -> Y/X --> Z/X
| this |
v one v
1 ---> Z/Y
-}
private
⊙D-span : ⊙Span
⊙D-span = ⊙span Y/X Z Y (⊙cfcod' f) g
⊙D : Ptd i
⊙D = ⊙Pushout ⊙D-span
Y/X-to-D : Y/X ⊙→ ⊙D
Y/X-to-D = B/A-to-D , idp
open import cohomology.LongExactSequence CT n Y/X-to-D
⊙E : Ptd i
⊙E = ⊙Cofiber (⊙left ⊙D-span)
Z/Y-to-E : Z/Y ⊙→ ⊙E
Z/Y-to-E = C/B-to-E , idp
Z/X-to-D : Z/X ⊙→ ⊙D
Z/X-to-D = C/A-to-D , idp
grid-co∂ : C n Y/X →ᴳ C (succ n) Z/Y
grid-co∂ = record {f = CEl-fmap (succ n) Z/Y-to-E ∘ GroupHom.f co∂ ; pres-comp = lemma} where
abstract lemma = ∘ᴳ-pres-comp (C-fmap (succ n) Z/Y-to-E) co∂
grid-∂-before-Susp : C/B → Susp B/A
grid-∂-before-Susp = extract-glue ∘ C/B-to-E
⊙grid-∂-before-Susp : Z/Y ⊙→ ⊙Susp Y/X
⊙grid-∂-before-Susp = grid-∂-before-Susp , lemma where
abstract lemma = snd (⊙extract-glue ⊙∘ Z/Y-to-E)
abstract
grid-co∂-β : GroupHom.f grid-co∂ ∼ CEl-fmap (succ n) ⊙grid-∂-before-Susp ∘ <– (CEl-Susp n Y/X)
grid-co∂-β x = ∘-CEl-fmap (succ n) Z/Y-to-E ⊙extract-glue _
abstract
grid-∂-before-Susp-glue-β : ∀ x →
ap (fst ⊙grid-∂-before-Susp) (glue x) == merid (cfcod x)
grid-∂-before-Susp-glue-β x =
ap-∘ extract-glue C/B-to-E (glue x)
∙ ap (ap extract-glue) (C/B-to-E-glue-β x)
∙ ap-∙' extract-glue (glue (cfcod x)) (ap cfcod (glue x))
∙ ap2 _∙'_
(ExtractGlue.glue-β (cfcod x))
(∘-ap extract-glue cfcod (glue x) ∙ ap-cst south (glue x))
C-grid-cofiber-seq : HomSequence (C n Z/X) (C (succ n) Y/X)
C-grid-cofiber-seq =
C n Z/X →⟨ C-fmap n Y/X-to-Z/X ⟩ᴳ
C n Y/X →⟨ grid-co∂ ⟩ᴳ
C (succ n) Z/Y →⟨ C-fmap (succ n) Z/X-to-Z/Y ⟩ᴳ
C (succ n) Z/X →⟨ C-fmap (succ n) Y/X-to-Z/X ⟩ᴳ
C (succ n) Y/X ⊣|ᴳ
private
C-cofiber-seq-to-C-grid-cofiber-seq :
HomSeqMap C-cofiber-seq C-grid-cofiber-seq
(C-fmap n Z/X-to-D) (idhom _)
C-cofiber-seq-to-C-grid-cofiber-seq =
C-fmap n Z/X-to-D ↓⟨ comm-sqrᴳ (λ d → ! (C-fmap-idf n _)
∙ (C-comm-square n B/A-to-C/A-comm-square □$ᴳ d)) ⟩ᴳ
idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ
C-fmap (succ n) Z/Y-to-E ↓⟨ C-comm-square (succ n) C/A-to-C/B-comm-square ⟩ᴳ
C-fmap (succ n) Z/X-to-D ↓⟨ comm-sqrᴳ (λ d → ! (C-fmap-idf (succ n) _)
∙ (C-comm-square (succ n) B/A-to-C/A-comm-square □$ᴳ d)) ⟩ᴳ
idhom _ ↓|ᴳ
C-cofiber-seq-equiv-C-grid-cofiber-seq :
HomSeqEquiv C-cofiber-seq C-grid-cofiber-seq
(C-fmap n Z/X-to-D) (idhom _)
C-cofiber-seq-equiv-C-grid-cofiber-seq =
C-cofiber-seq-to-C-grid-cofiber-seq ,
CEl-isemap n Z/X-to-D C/A-to-D-is-equiv ,
idf-is-equiv _ ,
CEl-isemap (succ n) Z/Y-to-E C/B-to-E-is-equiv ,
CEl-isemap (succ n) Z/X-to-D C/A-to-D-is-equiv ,
idf-is-equiv _
abstract
C-grid-cofiber-seq-is-exact : is-exact-seq C-grid-cofiber-seq
C-grid-cofiber-seq-is-exact = seq-equiv-preserves-exact
C-cofiber-seq-equiv-C-grid-cofiber-seq C-cofiber-seq-is-exact
C-grid-cofiber-exact-seq : ExactSequence (C n Z/X) (C (succ n) Y/X)
C-grid-cofiber-exact-seq = C-grid-cofiber-seq , C-grid-cofiber-seq-is-exact
|
{
"alphanum_fraction": 0.5668635875,
"avg_line_length": 33.25,
"ext": "agda",
"hexsha": "9e5b3e5246942b56b39cbe677b18c818938113bc",
"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": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/grid/LongExactSequence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"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": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/grid/LongExactSequence.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/grid/LongExactSequence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1528,
"size": 3724
}
|
-- Andreas, 2014-11-25, issue reported by Peter Divianski (divipp)
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc:10 #-}
-- {-# OPTIONS -v tc.inj:49 #-}
-- {-# OPTIONS -v tc.polarity:49 #-}
-- {-# OPTIONS -v tc.lhs:40 #-}
-- After loading the following Agda code, the last occurrence of 'one' is yellow.
-- Remarks:
-- Probably not an error, but it is against my expectation.
-- The code was obtained by shrinking a more complex one.
-- I guess that the lifting of the local function 'f' happens not as I expect it.
-- The code is quite fragile, the any of following changes fix the problem:
-- - using record ⊤ instead of data Unit
-- - lifting 'f' to be a global function
-- - replacing 'unit' by '_' in the definition of 'f'
-- - giving the implicit argument {v = unit ∷ []} to g
-- Tested with Agda 2.4.2.1 and with the development version of Agda on GitHub (20 Nov 2014)
open import Common.Prelude using (Nat; zero; suc; Unit; unit)
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) -- n is forced
-- Singleton type
data Sg {A : Set} (x : A) : Set where
sg : Sg x
-- modified length function (counts till 1)
nonNil : ∀ {n} → Vec Unit n → Nat
nonNil [] = zero
nonNil (i ∷ is) = suc (f i) where
f : Unit → Nat
f unit = zero
g : ∀ {n} {v : Vec Unit n} → Sg (nonNil v) → Sg v
g sg = sg
one : Sg (suc zero)
one = sg
test : Sg (unit ∷ [])
test = g one -- `one' is yellow, a meta coming from the forced n
{- Analysis
g :=> Sg (nonNil {_n} _v) -> Sg _v
one :=> Sg (suc zero)
suc zero =?= nonNil {_n} _v
use injectivity
_n := suc _n'
_v := _∷_ {_nv} _i _is
zero =?= f {_nv} {_i} {_is} _i
using injectivity on f creates unsolved, because "forced" meta:
inverting injective function _.f :
({.n : Nat} (i : Unit) (is : Vec Unit .n) → Unit → Nat) for zero
(args = [$ {_32}, $ _33, $ _34, $ _33])
meta patterns [_35, _36, _37]
perm = x0,x1,x2 -> x0,x1,x2
tel = {.n : Nat} (i : Unit) (is : Vec Unit .n)
ps = [[]!{VarP ".n"}, []k(VarP "i"), []k(VarP "is"),
[]r(ConP Common.Prelude.Unit.unit(inductive)[] Nothing [])]
inversion
lhs = [$ {_35}, $ _36, $ _37, $ unit]
rhs = [$ {_32}, $ _33, $ _34, $ _33]
type = ({.n : Nat} (i : Unit) (is : Vec Unit .n) → Unit → Nat)
a = ({.n : Nat} (i : Unit) (is : Vec Unit .n) → Unit → Nat)
v = (_.f)
arg1 = {_35}
arg2 = {_32}
-- Here, the equality check is skipped as n is "forced", so the
-- assignment _35 := _32 does not happen
a = ((i : Unit) (is : Vec Unit _35) → Unit → Nat)
v = (_.f {_35})
arg1 = _36
arg2 = _33
term _36 := _33
term _36 := _33
solving _36 := _33
a = ((is : Vec Unit _35) → Unit → Nat)
v = (_.f {_35} _33)
arg1 = _37
arg2 = _34
term _37 := _34
term _37 := _34
solving _37 := _34
a = (Unit → Nat)
v = (_.f {_35} _33 _34)
arg1 = unit
arg2 = _33
compareTerm unit == _33 : Unit
term _33 := unit
term _33 := unit
solving _33 := unit
compareTerm zero == (_.f {_32} unit _34 unit) : Nat
-}
-- Should work without unsolved metas.
|
{
"alphanum_fraction": 0.5866491286,
"avg_line_length": 29.2403846154,
"ext": "agda",
"hexsha": "03014757dd1476190eb784c3f6d664e750355504",
"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/Issue1366.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/Issue1366.agda",
"max_line_length": 92,
"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/Issue1366.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": 1092,
"size": 3041
}
|
open import Agda.Builtin.Equality
_∋_ : ∀ {a} (A : Set a) → A → A
A ∋ x = x
cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
record IsRG (Node : Set) (Edge : Set) : Set where
field
src : Edge → Node
tgt : Edge → Node
rfl : Node → Edge
eq-src-rfl : ∀{x} → src (rfl x) ≡ x
eq-tgt-rfl : ∀{x} → tgt (rfl x) ≡ x
open IsRG {{...}} public
module norecord where
source : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → Edge → Node
source x = src x
lemma1 : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → (e : Edge) → (Node ∋ source e) ≡ src e
lemma1 e = refl
rfl-src : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → Edge → Edge
rfl-src {Node} e = rfl (Node ∋ src e)
lemma2 : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → (n : Node) → rfl-src {Node} (rfl n) ≡ (Edge ∋ rfl n)
lemma2 {Node}{Edge} n = cong (rfl {Node = Node}) (eq-src-rfl {Edge = Edge})
module yesrecord where
record RG : Set₁ where
constructor mkRG
field
Node : Set
Edge : Set
{{isRG}} : IsRG Node Edge
open RG public
source : ∀{rg} → Edge rg → Node rg
source x = src x
lemma1 : ∀{rg} → (e : Edge rg) → (Node rg ∋ source {mkRG (Node rg) (Edge rg)} e) ≡ src e
--causes problems:
--lemma1 : ∀{rg} → (e : Edge rg) → (Node rg ∋ source {_} e) ≡ src e
lemma1 e = refl
rfl-src : ∀{rg} → Edge rg → Edge rg
rfl-src {rg} e = rfl (Node rg ∋ src e)
lemma2 : ∀{rg} → (n : Node rg) → rfl-src {rg} (rfl n) ≡ (Edge rg ∋ rfl n)
lemma2 {rg} n = cong (rfl {Node = Node rg}) (eq-src-rfl {Edge = Edge rg})
|
{
"alphanum_fraction": 0.5365699874,
"avg_line_length": 27.8245614035,
"ext": "agda",
"hexsha": "a8f548fb81c96609fe9e5f7b8b1be18e559da6a9",
"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/Issue2670.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/Issue2670.agda",
"max_line_length": 107,
"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/Issue2670.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": 626,
"size": 1586
}
|
{- Jesper, 2019-07-05: At first, the fix to #3859 causes the line below to
raise a type error:
Cannot instantiate the metavariable _6 to solution Set
(Agda.Primitive.lsuc (Agda.Primitive.lsuc Agda.Primitive.lzero)
Agda.Primitive.⊔ Agda.Primitive.lsuc a) since it contains the
variable a which is not in scope of the metavariable or irrelevant
in the metavariable but relevant in the solution
when checking that the expression λ (A : Set a) → Set has type
(A : Set a) → Set₁
Now it is no longer the case. This test case is here to make sure the
error doesn't come back.
-}
F = λ {a} (A : Set a) → Set
|
{
"alphanum_fraction": 0.7277147488,
"avg_line_length": 36.2941176471,
"ext": "agda",
"hexsha": "451ce108d200ce89bc36eb54c5c1bfa9919a027c",
"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/Issue3859b.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/Issue3859b.agda",
"max_line_length": 74,
"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/Issue3859b.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": 184,
"size": 617
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.DiffInt.Base where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.SetQuotients
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Sigma
open import Cubical.Data.Nat hiding (+-comm ; +-assoc) renaming (_+_ to _+ℕ_)
open import Cubical.Data.Int
rel : (ℕ × ℕ) → (ℕ × ℕ) → Type₀
rel (a₀ , b₀) (a₁ , b₁) = x ≡ y
where
x = a₀ +ℕ b₁
y = a₁ +ℕ b₀
ℤ = (ℕ × ℕ) / rel
-- Proof of equivalence between Int and DiffInt
private
-- Prove all the identities for ℕ×ℕ first and use that to build to ℤ
Int→ℕ×ℕ : Int → (ℕ × ℕ)
Int→ℕ×ℕ (pos n) = ( n , zero )
Int→ℕ×ℕ (negsuc n) = ( zero , suc n )
ℕ×ℕ→Int : (ℕ × ℕ) → Int
ℕ×ℕ→Int(n , m) = n ℕ- m
relInt→ℕ×ℕ : ∀ m n → rel (Int→ℕ×ℕ (m ℕ- n)) (m , n)
relInt→ℕ×ℕ zero zero = refl
relInt→ℕ×ℕ zero (suc n) = refl
relInt→ℕ×ℕ (suc m) zero = refl
relInt→ℕ×ℕ (suc m) (suc n) =
fst (Int→ℕ×ℕ (m ℕ- n)) +ℕ suc n ≡⟨ +-suc (fst (Int→ℕ×ℕ (m ℕ- n))) n ⟩
suc (fst (Int→ℕ×ℕ (m ℕ- n)) +ℕ n) ≡⟨ cong suc (relInt→ℕ×ℕ m n) ⟩
suc (m +ℕ snd (Int→ℕ×ℕ (m ℕ- n))) ∎
Int→ℕ×ℕ→Int : ∀ n → ℕ×ℕ→Int (Int→ℕ×ℕ n) ≡ n
Int→ℕ×ℕ→Int (pos n) = refl
Int→ℕ×ℕ→Int (negsuc n) = refl
ℕ×ℕ→Int→ℕ×ℕ : ∀ p → rel (Int→ℕ×ℕ (ℕ×ℕ→Int p)) p
ℕ×ℕ→Int→ℕ×ℕ (p₀ , p₁) = relInt→ℕ×ℕ p₀ p₁
-- Now build to ℤ using the above
Int→ℤ : Int → ℤ
Int→ℤ n = [ Int→ℕ×ℕ n ]
ℤ→Int : ℤ → Int
ℤ→Int [ z ] = ℕ×ℕ→Int z
ℤ→Int(eq/ a b r i) = lemℤeq a b r i
where lemℤeq : (a b : (ℕ × ℕ)) → rel a b → ℕ×ℕ→Int(a) ≡ ℕ×ℕ→Int(b)
lemℤeq (a₀ , a₁) (b₀ , b₁) r = a₀ ℕ- a₁ ≡⟨ pos- a₀ a₁ ⟩
pos a₀ - pos a₁ ≡[ i ]⟨ ((pos a₀ - pos a₁) + -Cancel (pos b₁) (~ i)) ⟩
(pos a₀ - pos a₁) + (pos b₁ - pos b₁) ≡⟨ +-assoc (pos a₀ + (- pos a₁)) (pos b₁) (- pos b₁) ⟩
((pos a₀ - pos a₁) + pos b₁) - pos b₁ ≡[ i ]⟨ +-assoc (pos a₀) (- pos a₁) (pos b₁) (~ i) + (- pos b₁) ⟩
(pos a₀ + ((- pos a₁) + pos b₁)) - pos b₁ ≡[ i ]⟨ (pos a₀ + +-comm (- pos a₁) (pos b₁) i) - pos b₁ ⟩
(pos a₀ + (pos b₁ - pos a₁)) - pos b₁ ≡[ i ]⟨ +-assoc (pos a₀) (pos b₁) (- pos a₁) i + (- pos b₁) ⟩
((pos a₀ + pos b₁) - pos a₁) - pos b₁ ≡[ i ]⟨ (pos+ a₀ b₁ (~ i) - pos a₁) - pos b₁ ⟩
(pos (a₀ +ℕ b₁) - pos a₁) - pos b₁ ≡[ i ]⟨ (pos (r i) - pos a₁) - pos b₁ ⟩
(pos (b₀ +ℕ a₁) - pos a₁) - pos b₁ ≡[ i ]⟨ (pos+ b₀ a₁ i - pos a₁) - pos b₁ ⟩
((pos b₀ + pos a₁) - pos a₁) - pos b₁ ≡[ i ]⟨ +-assoc (pos b₀) (pos a₁) (- pos a₁) (~ i) + (- pos b₁) ⟩
(pos b₀ + (pos a₁ - pos a₁)) - pos b₁ ≡[ i ]⟨ (pos b₀ + (-Cancel (pos a₁) i)) - pos b₁ ⟩
pos b₀ - pos b₁ ≡[ i ]⟨ pos- b₀ b₁ (~ i) ⟩
b₀ ℕ- b₁ ∎
ℤ→Int(squash/ x x₀ p q i j) = isSetInt (ℤ→Int x) (ℤ→Int x₀) (cong ℤ→Int p) (cong ℤ→Int q) i j
Int→ℤ→Int : ∀ z → ℤ→Int (Int→ℤ z) ≡ z
Int→ℤ→Int (pos n) = refl
Int→ℤ→Int (negsuc n) = refl
ℤ→Int→ℤ : ∀ z → Int→ℤ (ℤ→Int z) ≡ z
ℤ→Int→ℤ = elimProp (λ z → squash/ (Int→ℤ (ℤ→Int z)) z) ℕ×ℕprf
where ℕ×ℕprf : (a : ℕ × ℕ) → Int→ℤ (ℤ→Int [ a ]) ≡ [ a ]
ℕ×ℕprf (a , b) = eq/ (Int→ℕ×ℕ (ℕ×ℕ→Int (a , b))) (a , b) (ℕ×ℕ→Int→ℕ×ℕ (a , b))
Int≡DiffInt : Int ≡ ℤ
Int≡DiffInt = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)
|
{
"alphanum_fraction": 0.4749487255,
"avg_line_length": 40.1529411765,
"ext": "agda",
"hexsha": "d0baa68274de613113fe0338b93de9849331c8a6",
"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/Base.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/Base.agda",
"max_line_length": 122,
"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/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1685,
"size": 3413
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Level using (0ℓ)
open import Data.String
-- This module defines utility functions to help working on proofs.
module LibraBFT.Base.Util where
-- These should obviously not be used in any legitimate proof. They are just for convenience when
-- we want to avoid importing a module with open holes while working on something else.
-- This variant allows a comment to be attached conveniently
obm-dangerous-magic' : ∀ {ℓ} {A : Set ℓ} → String → A
obm-dangerous-magic' {ℓ} {A} _ = magic
where postulate magic : A
obm-dangerous-magic! : ∀ {ℓ} {A : Set ℓ} → A
obm-dangerous-magic! {ℓ} {A} = obm-dangerous-magic' ""
|
{
"alphanum_fraction": 0.7204058625,
"avg_line_length": 35.48,
"ext": "agda",
"hexsha": "de5fa50e168c13630482ee43f45a6c2211a2b8d5",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z",
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Base/Util.agda",
"max_issues_count": 72,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Base/Util.agda",
"max_line_length": 111,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Base/Util.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z",
"num_tokens": 249,
"size": 887
}
|
------------------------------------------------------------------------------
-- Distributive laws on a binary operation: Task B
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module DistributiveLaws.TaskB-I where
open import DistributiveLaws.Base
open import DistributiveLaws.PropertiesI
open import Common.FOL.Relation.Binary.EqReasoning
------------------------------------------------------------------------------
prop₂ : ∀ u x y z →
(x · y · (z · u)) · ((x · y · (z · u)) · (x · z · (y · u))) ≡
x · z · (y · u)
prop₂ u x y z =
xy·zu · (xy·zu · xz·yu) ≡⟨ j₁ ⟩
xy·zu · (x·zu · y·zu · xz·yu) ≡⟨ j₂ ⟩
xy·zu · (x·zu · xz·yu · (y·zu · xz·yu)) ≡⟨ j₃ ⟩
-- Note: The paper proof has a typo in the third proof step:
-- xy·zu · (xz·xu · xz·yu · (z·zu · xz·yu))
xy·zu · (xz·xu · xz·yu · (y·zu · xz·yu)) ≡⟨ j₄ ⟩
xy·zu · (xz · xu·yu · (y·zu · xz·yu)) ≡⟨ j₅ ⟩
xy·zu · (xz · xyu · (y·zu · xz·yu)) ≡⟨ j₆ ⟩
xy·zu · (xz · xyu · (yz·yu · xz·yu)) ≡⟨ j₇ ⟩
xy·zu · (xz · xyu · (yz·xz · yu)) ≡⟨ j₈ ⟩
xy·zu · (xz · xyu · (yxz · yu)) ≡⟨ j₉ ⟩
xy·zu · (xz · xyu · (yx·yu · z·yu)) ≡⟨ j₁₀ ⟩
xy·zu · (xz · xyu · (y·xu · z·yu)) ≡⟨ j₁₁ ⟩
xyz · xyu · (xz · xyu · (y·xu · z·yu)) ≡⟨ j₁₂ ⟩
xz·yz · xyu · (xz · xyu · (y·xu · z·yu)) ≡⟨ j₁₃ ⟩
xz · xyu · (yz · xyu) · (xz · xyu · (y·xu · z·yu)) ≡⟨ j₁₄ ⟩
xz · xyu · (yz · xyu · (y·xu · z·yu)) ≡⟨ j₁₅ ⟩
xz · xyu · (yz · xu·yu · (y·xu · z·yu)) ≡⟨ j₁₆ ⟩
xz · xyu · (y · xu·yu · (z · xu·yu) · (y·xu · z·yu)) ≡⟨ j₁₇ ⟩
xz · xyu ·
(y · xu·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₁₈ ⟩
xz · xyu ·
(y·xu · y·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₁₉ ⟩
xz · xyu · (y·xu · (y·yu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₂₀ ⟩
xz · xyu · (y·xu · yz·yu · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₂₁ ⟩
xz · xyu · (y·xu · y·zu · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₂₂ ⟩
xz · xyu · (y · xu·zu · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₂₃ ⟩
xz · xyu · (y · xu·zu · (z·xu · z·yu · (y·xu · z·yu))) ≡⟨ j₂₄ ⟩
(xz · xyu) · (y · xu·zu · (z·xu · y·xu · z·yu)) ≡⟨ j₂₅ ⟩
xz · xyu · (y · xu·zu · (zy·xu · z·yu)) ≡⟨ j₂₆ ⟩
xz · xyu · (y · xu·zu · (zy·xu · zy·zu)) ≡⟨ j₂₇ ⟩
xz · xyu · (y · xu·zu · (zy · xu·zu)) ≡⟨ j₂₈ ⟩
xz · xyu · (y·zy · xu·zu) ≡⟨ j₂₉ ⟩
xz · xyu · (y·zy · xzu) ≡⟨ j₃₀ ⟩
xz·xy · xzu · (y·zy · xzu) ≡⟨ j₃₁ ⟩
x·zy · xzu · (y·zy · xzu) ≡⟨ j₃₂ ⟩
x·zy · y·zy · xzu ≡⟨ j₃₃ ⟩
xy·zy · xzu ≡⟨ j₃₄ ⟩
xzy · xzu ≡⟨ j₃₅ ⟩
xz·yu ∎
where
-- Two variables abbreviations
xz = x · z
yu = y · u
yz = y · z
zy = z · y
-- Three variables abbreviations
xyu = x · y · u
xyz = x · y · z
xzu = x · z · u
xzy = x · z · y
yxz = y · x · z
x·yu = x · (y · u)
x·zu = x · (z · u)
x·zy = x · (z · y)
y·xu = y · (x · u)
y·yu = y · (y · u)
y·zu = y · (z · u)
y·zy = y · (z · y)
z·xu = z · (x · u)
z·yu = z · (y · u)
-- Four variables abbreviations
xu·yu = x · u · (y · u)
xu·zu = x · u · (z · u)
xy·yz = x · y · (y · z)
xy·zu = x · y · (z · u)
xy·zy = x · y · (z · y)
xz·xu = x · z · (x · u)
xz·xy = x · z · (x · y)
xz·yu = x · z · (y · u)
xz·yz = x · z · (y · z)
yx·yu = y · x · (y · u)
yz·xz = y · z · (x · z)
yz·yu = y · z · (y · u)
zy·xu = z · y · (x · u)
zy·zu = z · y · (z · u)
-- Steps justifications
j₁ : xy·zu · (xy·zu · xz·yu) ≡
xy·zu · (x·zu · y·zu · xz·yu)
j₁ = ·-rightCong (·-leftCong (rightDistributive x y (z · u)))
j₂ : xy·zu · (x·zu · y·zu · xz·yu) ≡
xy·zu · (x·zu · xz·yu · (y·zu · xz·yu))
j₂ = ·-rightCong (rightDistributive x·zu y·zu xz·yu)
j₃ : xy·zu · (x·zu · xz·yu · (y·zu · xz·yu)) ≡
xy·zu · (xz·xu · xz·yu · (y·zu · xz·yu))
j₃ = ·-rightCong (·-leftCong (·-leftCong (leftDistributive x z u)))
j₄ : xy·zu · (xz·xu · xz·yu · (y·zu · xz·yu)) ≡
xy·zu · (xz · xu·yu · (y·zu · xz·yu))
j₄ = ·-rightCong (·-leftCong (sym (leftDistributive (x · z) (x · u) (y · u))))
j₅ : xy·zu · (xz · xu·yu · (y·zu · xz·yu)) ≡
xy·zu · (xz · xyu · (y·zu · xz·yu))
j₅ = ·-rightCong (·-leftCong (·-rightCong (sym (rightDistributive x y u))))
j₆ : xy·zu · (xz · xyu · (y·zu · xz·yu)) ≡
xy·zu · (xz · xyu · (yz·yu · xz·yu))
j₆ = ·-rightCong (·-rightCong (·-leftCong (leftDistributive y z u)))
j₇ : xy·zu · (xz · xyu · (yz·yu · xz·yu)) ≡
xy·zu · (xz · xyu · (yz·xz · yu))
j₇ = ·-rightCong (·-rightCong (sym (rightDistributive (y · z) (x · z) (y · u))))
j₈ : xy·zu · (xz · xyu · (yz·xz · yu)) ≡
xy·zu · (xz · xyu · (yxz · yu))
j₈ = ·-rightCong (·-rightCong (·-leftCong (sym (rightDistributive y x z))))
j₉ : xy·zu · (xz · xyu · (yxz · yu)) ≡
xy·zu · (xz · xyu · (yx·yu · z·yu))
j₉ = ·-rightCong (·-rightCong (rightDistributive (y · x) z yu))
j₁₀ : xy·zu · (xz · xyu · (yx·yu · z·yu)) ≡
xy·zu · (xz · xyu · (y·xu · z·yu))
j₁₀ = ·-rightCong (·-rightCong (·-leftCong (sym (leftDistributive y x u))))
j₁₁ : xy·zu · (xz · xyu · (y·xu · z·yu)) ≡
xyz · xyu · (xz · xyu · (y·xu · z·yu))
j₁₁ = ·-leftCong (leftDistributive (x · y) z u)
j₁₂ : xyz · xyu · (xz · xyu · (y·xu · z·yu)) ≡
xz·yz · xyu · (xz · xyu · (y·xu · z·yu))
j₁₂ = ·-leftCong (·-leftCong (rightDistributive x y z))
j₁₃ : xz·yz · xyu · (xz · xyu · (y·xu · z·yu)) ≡
xz · xyu · (yz · xyu) · (xz · xyu · (y·xu · z·yu))
j₁₃ = ·-leftCong (rightDistributive (x · z) (y · z) xyu)
j₁₄ : xz · xyu · (yz · xyu) · (xz · xyu · (y·xu · z·yu)) ≡
xz · xyu · (yz · xyu · (y·xu · z·yu))
j₁₄ = sym (leftDistributive (xz · xyu) (yz · xyu) (y·xu · z·yu))
j₁₅ : xz · xyu · (yz · xyu · (y·xu · z·yu)) ≡
xz · xyu · (yz · xu·yu · (y·xu · z·yu))
j₁₅ = ·-rightCong (·-leftCong (·-rightCong (rightDistributive x y u)))
j₁₆ : xz · xyu · (yz · xu·yu · (y·xu · z·yu)) ≡
xz · xyu · (y · xu·yu · (z · xu·yu) · (y·xu · z·yu))
j₁₆ = ·-rightCong (·-leftCong (rightDistributive y z xu·yu))
j₁₇ : xz · xyu · (y · xu·yu · (z · xu·yu) · (y·xu · z·yu)) ≡
xz · xyu ·
(y · xu·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu)))
j₁₇ = subst (λ t → xz · xyu · (y · xu·yu · (z · xu·yu) · (y·xu · z·yu)) ≡
xz · xyu · t)
(rightDistributive (y · xu·yu) (z · xu·yu) (y·xu · z·yu))
refl
j₁₈ : xz · xyu ·
(y · xu·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu ·
(y·xu · y·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu)))
j₁₈ = ·-rightCong (·-leftCong (·-leftCong (leftDistributive y (x · u) (y · u))))
j₁₉ : xz · xyu ·
(y·xu · y·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu · (y·xu · (y·yu · z·yu) · (z · xu·yu · (y·xu · z·yu)))
j₁₉ = subst (λ t → xz · xyu ·
(y·xu · y·yu · (y·xu · z·yu) · (z · xu·yu · (y·xu · z·yu)))
≡
xz · xyu · (t · (z · xu·yu · (y·xu · z·yu))))
(sym (leftDistributive y·xu y·yu z·yu))
refl
j₂₀ : xz · xyu · (y·xu · (y·yu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu · (y·xu · yz·yu · (z · xu·yu · (y·xu · z·yu)))
j₂₀ = ·-rightCong (·-leftCong (·-rightCong (sym (rightDistributive y z (y · u)))))
j₂₁ : xz · xyu · (y·xu · yz·yu · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu · (y·xu · y·zu · (z · xu·yu · (y·xu · z·yu)))
j₂₁ = ·-rightCong (·-leftCong (·-rightCong (sym (leftDistributive y z u))))
j₂₂ : xz · xyu · (y·xu · y·zu · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu · (y · xu·zu · (z · xu·yu · (y·xu · z·yu)))
j₂₂ = ·-rightCong (·-leftCong (sym (leftDistributive y (x · u) (z · u))))
j₂₃ : xz · xyu · (y · xu·zu · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu · (y · xu·zu · (z·xu · z·yu · (y·xu · z·yu)))
j₂₃ = ·-rightCong (·-rightCong (·-leftCong (leftDistributive z (x · u) (y · u))))
j₂₄ : xz · xyu · (y · xu·zu · (z·xu · z·yu · (y·xu · z·yu))) ≡
(xz · xyu) · (y · xu·zu · (z·xu · y·xu · z·yu))
j₂₄ = ·-rightCong (·-rightCong (sym (rightDistributive z·xu y·xu z·yu)))
j₂₅ : (xz · xyu) · (y · xu·zu · (z·xu · y·xu · z·yu)) ≡
xz · xyu · (y · xu·zu · (zy·xu · z·yu))
j₂₅ = ·-rightCong (·-rightCong (·-leftCong (sym (rightDistributive z y (x · u)))))
j₂₆ : xz · xyu · (y · xu·zu · (zy·xu · z·yu)) ≡
xz · xyu · (y · xu·zu · (zy·xu · zy·zu))
j₂₆ = ·-rightCong (·-rightCong (·-rightCong (leftDistributive z y u)))
j₂₇ : xz · xyu · (y · xu·zu · (zy·xu · zy·zu)) ≡
xz · xyu · (y · xu·zu · (zy · xu·zu))
j₂₇ = ·-rightCong (·-rightCong (sym (leftDistributive (z · y) (x · u) (z · u))))
j₂₈ : xz · xyu · (y · xu·zu · (zy · xu·zu)) ≡
xz · xyu · (y·zy · xu·zu)
j₂₈ = ·-rightCong (sym (rightDistributive y zy xu·zu))
j₂₉ : xz · xyu · (y·zy · xu·zu) ≡
xz · xyu · (y·zy · xzu)
j₂₉ = ·-rightCong (·-rightCong (sym (rightDistributive x z u)))
j₃₀ : xz · xyu · (y·zy · xzu) ≡
xz·xy · xzu · (y·zy · xzu)
j₃₀ = ·-leftCong (leftDistributive xz (x · y) u)
j₃₁ : xz·xy · xzu · (y·zy · xzu) ≡
x·zy · xzu · (y·zy · xzu)
j₃₁ = ·-leftCong (·-leftCong (sym (leftDistributive x z y)))
j₃₂ : x·zy · xzu · (y·zy · xzu) ≡
x·zy · y·zy · xzu
j₃₂ = sym (rightDistributive x·zy y·zy xzu)
j₃₃ : x·zy · y·zy · xzu ≡
xy·zy · xzu
j₃₃ = ·-leftCong (sym (rightDistributive x y zy))
j₃₄ : xy·zy · xzu ≡
xzy · xzu
j₃₄ = ·-leftCong (sym (rightDistributive x z y))
j₃₅ : xzy · xzu ≡
xz·yu
j₃₅ = sym (leftDistributive xz y u)
|
{
"alphanum_fraction": 0.3992611537,
"avg_line_length": 39.6879699248,
"ext": "agda",
"hexsha": "5d671adf23315717dcdf5bb4215a27d9d949c107",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/DistributiveLaws/TaskB-I.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/DistributiveLaws/TaskB-I.agda",
"max_line_length": 84,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/DistributiveLaws/TaskB-I.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 4945,
"size": 10557
}
|
-- Andreas, 2019-07-05, during work on issue #3889
-- Test-case for with extracted from the standard library
{-# OPTIONS --cubical-compatible #-}
open import Agda.Primitive
open import Agda.Builtin.Equality
open import Agda.Builtin.List
open import Common.Equality
open import Common.Product
data Any {a}{A : Set a} {p} (P : A → Set p) : List A → Set (a ⊔ p) where
here : ∀ {x xs} (px : P x) → Any P (x ∷ xs)
there : ∀ {x xs} (pxs : Any P xs) → Any P (x ∷ xs)
_∈_ : ∀{a}{A : Set a} → A → List A → Set _
x ∈ xs = Any (x ≡_) xs
map : ∀ {a} {A : Set a} {p q} {P : A → Set p} {Q : A → Set q} → (∀{x} → P x → Q x) → ∀{xs} → Any P xs → Any Q xs
map g (here px) = here (g px)
map g (there pxs) = there (map g pxs)
map₁ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A → B) → A × C → B × C
map₁ f (x , y)= f x , y
map₂ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : A → Set c} →
(∀ {x} → B x → C x) → Σ A B → Σ A C
map₂ f (x , y) = (x , f y)
find : ∀ {a} {p} {A : Set a} {P : A → Set p} {xs} → Any P xs → Σ _ λ x → x ∈ xs × P x
find (here px) = (_ , here refl , px)
find (there pxs) = map₂ (map₁ there) (find pxs)
lose : ∀ {a} {p} {A : Set a} {P : A → Set p} {x xs} → x ∈ xs → P x → Any P xs
lose x∈xs px = map (λ eq → subst _ eq px) x∈xs
map∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs}
(p : Any P xs) → let p′ = find p in
{f : ∀{x} → proj₁ p′ ≡ x → P x} →
f refl ≡ proj₂ (proj₂ p′) →
map f (proj₁ (proj₂ p′)) ≡ p
map∘find (here p) hyp = cong here hyp
map∘find (there p) hyp = cong there (map∘find p hyp)
find∘map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs : List A} (p : Any P xs) (f : ∀{x} → P x → Q x) →
find (map f p) ≡ map₂ (map₂ f) (find p)
find∘map (here p) f = refl
find∘map (there p) f rewrite find∘map p f = refl
lose∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A}
(p : Any P xs) →
(let (y , z) = proj₂ (find p)) →
lose y z ≡ p
lose∘find p = map∘find p refl
postulate
a b ℓ : Level
A : Set a
B : Set b
P : A → Set ℓ
Q : B → Set ℓ -- Level needed
Any-×⁺ : ∀ {xs ys} → Any P xs × Any Q ys →
Any (λ x → Any (λ y → P x × Q y) ys) xs
Any-×⁺ (p , q) = map (λ p → map (λ q → (p , q)) q) p
Any-×⁻ : ∀ {xs ys} → Any (λ x → Any (λ y → P x × Q y) ys) xs →
Any P xs × Any Q ys
Any-×⁻ pq with map₂ (map₂ find) (find pq)
... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q)
module _ where
from∘to : ∀{xs ys} (pq : Any P xs × Any Q ys) → Any-×⁻ (Any-×⁺ pq) ≡ pq
-- from∘to (p , q) = {!!}
from∘to (p , q) rewrite
find∘map p (λ p → map (λ q → (p , q)) q)
| find∘map q (λ q → proj₂ (proj₂ (find p)) , q)
| lose∘find p
| lose∘find q
= refl
|
{
"alphanum_fraction": 0.4757106873,
"avg_line_length": 33.0833333333,
"ext": "agda",
"hexsha": "50351e5e07be3e3c974411ecb99e04981e23ad17",
"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/Issue3889.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/Issue3889.agda",
"max_line_length": 112,
"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/Issue3889.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1222,
"size": 2779
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.CategorySolver where
open import Level
open import Categories.Category
open import Categories.Functor hiding (equiv) renaming (id to idF; _≡_ to _≡F_; _∘_ to _∘F_; ∘-resp-≡ to ∘F-resp-≡F)
open import Categories.NaturalTransformation hiding (equiv) renaming (id to idT; _≡_ to _≡T_)
{- We need a way to force the universe levels of two categories to be
the same, to hack together a reified morphism type. These lift
operations let us do this in reification. -}
liftCategory : ∀ {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) → Category (o ⊔ o′) (ℓ ⊔ ℓ′) (e ⊔ e′)
liftCategory {o} {ℓ} {e} {o′} {ℓ′} {e′} C = record {
Obj = Lift {ℓ = o′} (Category.Obj C);
_⇒_ = λ s d → Lift {ℓ = ℓ′} ((lower s) ⇒ (lower d));
_≡_ = λ m₀ m₁ → Lift {ℓ = e′} (lower m₀ ≡ lower m₁);
id = lift id;
_∘_ = λ m₀ m₁ → lift (lower m₀ ∘ lower m₁);
assoc = λ {A} {B} {C₁} {D} {f} {g} {h} → lift C.assoc;
identityˡ = λ {A} {B} {f} → lift C.identityˡ;
identityʳ = λ {A} {B} {f} → lift C.identityʳ;
equiv = record { refl = λ {x} → lift Equiv.refl
; sym = λ x → lift (Equiv.sym (lower x))
; trans = λ x y → lift (Equiv.trans (lower x) (lower y)) };
∘-resp-≡ = λ x y → lift (∘-resp-≡ (lower x) (lower y)) }
where
module C = Category C
open C
liftFunctor : ∀ {o₀ ℓ₀ e₀ o′₀ ℓ′₀ e′₀ o₁ ℓ₁ e₁ o′₁ ℓ′₁ e′₁} {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁}
→ Functor C D → Functor (liftCategory {o′ = o′₀} {ℓ′₀} {e′₀} C) (liftCategory {o′ = o′₁} {ℓ′₁} {e′₁} D)
liftFunctor {o₀} {ℓ₀} {e₀} {o′₀} {ℓ′₀} {e′₀} {o₁} {ℓ₁} {e₁} {o′₁} {ℓ′₁} {e′₁} {C} {D} F =
record {
F₀ = λ x → lift (F.F₀ (lower x));
F₁ = λ m → lift (F.F₁ (lower m));
identity = lift F.identity;
homomorphism = lift F.homomorphism;
F-resp-≡ = λ H → lift (F.F-resp-≡ (lower H)) }
where
module C = Category C
module D = Category D
module ↑C = Category (liftCategory {o′ = o′₀} {ℓ′₀} {e′₀} C)
module ↑D = Category (liftCategory {o′ = o′₁} {ℓ′₁} {e′₁} D)
module F = Functor F
mutual
data ReifiedMorphismHelper {o ℓ e} {C : Category o ℓ e} : Category.Obj C → Category.Obj C → Set (suc (o ⊔ ℓ ⊔ e)) where
∥_₁∥₀_ : ∀ {D : Category o ℓ e} → (F : Functor D C) → {s d : Category.Obj D} → (m : ReifiedMorphism {C = D} s d) → ReifiedMorphismHelper (Functor.F₀ F s) (Functor.F₀ F d)
data ReifiedMorphism {o ℓ e} {C : Category o ℓ e} : Category.Obj C → Category.Obj C → Set (suc (o ⊔ ℓ ⊔ e)) where
_∥∘∥_ : ∀ {s d d′ : Category.Obj C} → (m2 : ReifiedMorphism {C = C} d d′) → (m1 : ReifiedMorphism {C = C} s d) → ReifiedMorphism s d′
∥id∥ : ∀ {x : Category.Obj C} → ReifiedMorphism x x
∥_₁∥₁ : ∀ {s d : Category.Obj C} (m : ReifiedMorphismHelper {C = C} s d) → ReifiedMorphism s d
∥_∥ : ∀ {s d : Category.Obj C} → (m : Category._⇒_ C s d) → ReifiedMorphism s d
pattern ∥F₁∥m D F s d F₀s F₀d m = ∥_₁∥₁ {F₀s} {F₀d} (∥_₁∥₀_ {D} F {s} {d} m)
pattern ∥_₁∥_ F m = ∥ (∥ F ₁∥₀ m) ₁∥₁
⟱ : ∀ {o ℓ e} → {C : Category o ℓ e} → {s d : Category.Obj C} → ReifiedMorphism {C = C} s d → Category._⇒_ C s d
⟱ {C = C} (∥m₂∥ ∥∘∥ ∥m₁∥) = ⟱ ∥m₂∥ ∘ ⟱ ∥m₁∥
where open Category C
⟱ {C = C} ∥id∥ = Category.id C
⟱ (∥ F ₁∥ ∥m∥) = Functor.F₁ F (⟱ ∥m∥)
⟱ ∥ m ∥ = m
record ReifiedMorphismOf {o ℓ e} {C : Category o ℓ e} {s d : Category.Obj C} (m : Category._⇒_ C s d) : Set (suc o ⊔ suc ℓ ⊔ suc e) where
constructor reify
field
reified : ReifiedMorphism {C = C} s d
.reified≡ : Category._≡_ C (⟱ {C = C} reified) m
ReifiedMorphismSimplify : ∀ {o ℓ e} → {C : Category o ℓ e} → {s d : Category.Obj C}
→ (m : ReifiedMorphism {C = C} s d) → ReifiedMorphismOf {C = C} (⟱ m)
ReifiedMorphismSimplify {C = C} ∥ m ∥ = reify ∥ m ∥ (Category.Equiv.refl C)
ReifiedMorphismSimplify {C = C} ∥id∥ = reify ∥id∥ (Category.Equiv.refl C)
ReifiedMorphismSimplify {C = C} (∥m₀∥ ∥∘∥ ∥m₁∥) = ReifiedMorphismSimplify∥∘∥ {∥m₀∥ = ∥m₀∥} {∥m₁∥} (ReifiedMorphismSimplify ∥m₀∥) (ReifiedMorphismSimplify ∥m₁∥)
where
module C = Category C
open C.HomReasoning
ReifiedMorphismSimplify∥∘∥ : ∀ {s d d′ : C.Obj} → {∥m₀∥ : ReifiedMorphism {C = C} d d′} → {∥m₁∥ : ReifiedMorphism {C = C} s d}
→ ReifiedMorphismOf {C = C} (⟱ ∥m₀∥)
→ ReifiedMorphismOf {C = C} (⟱ ∥m₁∥)
→ ReifiedMorphismOf {C = C} (⟱ (∥m₀∥ ∥∘∥ ∥m₁∥))
ReifiedMorphismSimplify∥∘∥ {∥m₀∥ = ∥m₀∥} {∥m₁∥} (reify ∥id∥ id≡m₀) (reify ∥m₁∥′ m₁′≡m₁) =
reify ∥m₁∥′ (begin
⟱ ∥m₁∥′
↑⟨ C.identityˡ ⟩
C.id C.∘ ⟱ ∥m₁∥′
↓⟨ C.∘-resp-≡ id≡m₀ m₁′≡m₁ ⟩
⟱ (∥m₀∥ ∥∘∥ ∥m₁∥)
∎)
ReifiedMorphismSimplify∥∘∥ {∥m₀∥ = ∥m₀∥} {∥m₁∥} (reify ∥m₀∥′ m₀′≡m₀) (reify ∥id∥ id≡m₁) =
reify ∥m₀∥′ (begin
⟱ ∥m₀∥′
↑⟨ C.identityʳ ⟩
⟱ ∥m₀∥′ C.∘ C.id
↓⟨ C.∘-resp-≡ m₀′≡m₀ id≡m₁ ⟩
⟱ (∥m₀∥ ∥∘∥ ∥m₁∥)
∎)
ReifiedMorphismSimplify∥∘∥ {∥m₀∥ = ∥m₀∥} {∥m₁∥} (reify (∥m₀₀∥ ∥∘∥ ∥m₀₁∥) m₀₀∘m₀₁≡m₀) (reify ∥m₁∥′ m₁′≡m₁) =
reify (∥m₀₀∥ ∥∘∥ (∥m₀₁∥ ∥∘∥ ∥m₁∥′)) (begin
⟱ (∥m₀₀∥ ∥∘∥ (∥m₀₁∥ ∥∘∥ ∥m₁∥′))
↑⟨ C.assoc ⟩
(⟱ ∥m₀₀∥ C.∘ ⟱ ∥m₀₁∥) C.∘ ⟱ ∥m₁∥′
↓⟨ C.∘-resp-≡ m₀₀∘m₀₁≡m₀ m₁′≡m₁ ⟩
⟱ (∥m₀∥ ∥∘∥ ∥m₁∥)
∎)
ReifiedMorphismSimplify∥∘∥ (reify ∥m₀∥′ m₀′≡m₀) (reify ∥m₁∥′ m₁′≡m₁) = reify (∥m₀∥′ ∥∘∥ ∥m₁∥′) (C.∘-resp-≡ m₀′≡m₀ m₁′≡m₁)
ReifiedMorphismSimplify {C = C} (∥F₁∥m D F s d ._ ._ ∥m∥) = ReifiedMorphismSimplifyF₀m {s = s} {d} {∥m∥}
(ReifiedMorphismSimplify ∥m∥)
where
module C = Category C
module D = Category D
module F = Functor F
open C.HomReasoning
ReifiedMorphismSimplifyF₀m : ∀ {s d : D.Obj} → {∥m∥ : ReifiedMorphism {C = D} s d}
→ ReifiedMorphismOf {C = D} (⟱ ∥m∥)
→ ReifiedMorphismOf {C = C} (F.F₁ (⟱ ∥m∥))
ReifiedMorphismSimplifyF₀m {∥m∥ = ∥m∥} (reify ∥id∥ id≡m) =
reify ∥id∥ (begin
C.id
↑⟨ F.identity ⟩
F.F₁ D.id
↓⟨ F.F-resp-≡ id≡m ⟩
F.F₁ (⟱ ∥m∥)
∎)
ReifiedMorphismSimplifyF₀m {∥m∥ = ∥m∥} (reify (∥m₀∥ ∥∘∥ ∥m₁∥) m₀∘m₁≡m) =
reify (∥ F ₁∥ ∥m₀∥ ∥∘∥ ∥ F ₁∥ ∥m₁∥) (begin
F.F₁ (⟱ ∥m₀∥) C.∘ F.F₁ (⟱ ∥m₁∥)
↑⟨ F.homomorphism ⟩
F.F₁ (⟱ ∥m₀∥ D.∘ ⟱ ∥m₁∥)
↓⟨ F.F-resp-≡ m₀∘m₁≡m ⟩
F.F₁ (⟱ ∥m∥)
∎)
ReifiedMorphismSimplifyF₀m {∥m∥ = ∥m∥} (reify ∥m∥′ m′≡m) = reify (∥ F ₁∥ ∥m∥′) (F.F-resp-≡ m′≡m)
.removeIdentities : ∀ {o ℓ e} {C : Category o ℓ e} {s d : Category.Obj C} {m : Category._⇒_ C s d}
→ (∥m∥ : ReifiedMorphismOf {C = C} m)
→ Category._≡_ C (⟱ (ReifiedMorphismOf.reified (ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m∥)))) m
removeIdentities {C = C} {m = m} ∥m∥ = begin
⟱
(ReifiedMorphismOf.reified
(ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m∥)))
↓⟨ ReifiedMorphismOf.reified≡ (ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m∥)) ⟩
⟱ (ReifiedMorphismOf.reified ∥m∥)
↓⟨ ReifiedMorphismOf.reified≡ ∥m∥ ⟩
m
∎
where
module C = Category C
open C.HomReasoning
.removeIdentities≡ : ∀ {o ℓ e} {C : Category o ℓ e} {s d : Category.Obj C} {m₀ m₁ : Category._⇒_ C s d}
→ (∥m₀∥ : ReifiedMorphismOf {C = C} m₀)
→ (∥m₁∥ : ReifiedMorphismOf {C = C} m₁)
→ Category._≡_ C (⟱ (ReifiedMorphismOf.reified (ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m₀∥))))
(⟱ (ReifiedMorphismOf.reified (ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m₁∥))))
→ Category._≡_ C m₀ m₁
removeIdentities≡ {C = C} {m₀ = m₀} {m₁} ∥m₀∥ ∥m₁∥ m₀≡m₁ =
begin
m₀
↑⟨ ReifiedMorphismOf.reified≡ ∥m₀∥ ⟩
⟱ (ReifiedMorphismOf.reified ∥m₀∥)
↑⟨ ReifiedMorphismOf.reified≡
(ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m₀∥)) ⟩
⟱
(ReifiedMorphismOf.reified
(ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m₀∥)))
↓⟨ m₀≡m₁ ⟩
⟱
(ReifiedMorphismOf.reified
(ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m₁∥)))
↓⟨ ReifiedMorphismOf.reified≡
(ReifiedMorphismSimplify (ReifiedMorphismOf.reified ∥m₁∥)) ⟩
⟱ (ReifiedMorphismOf.reified ∥m₁∥)
↓⟨ ReifiedMorphismOf.reified≡ ∥m₁∥ ⟩
m₁
∎
where
module C = Category C
open C.HomReasoning
|
{
"alphanum_fraction": 0.4599756197,
"avg_line_length": 52.3617021277,
"ext": "agda",
"hexsha": "7adbe26bc2970bdcdab8926a9f03a1a16013879d",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/CategorySolver.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/CategorySolver.agda",
"max_line_length": 174,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/CategorySolver.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 3994,
"size": 9844
}
|
------------------------------------------------------------------------------
-- The FOTC co-inductive lists type
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- N.B. This module is re-exported by FOTC.Data.Colist.
module FOTC.Data.Colist.Type where
open import FOTC.Base
open import FOTC.Base.List
------------------------------------------------------------------------------
-- The FOTC co-lists type (co-inductive predicate for total list).
-- Functional for the Colist predicate.
-- ColistF : (D → Set) → D → Set
-- ColistF A xs = xs ≡ [] ∨ ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
-- Colist is the greatest fixed-point of ColistF (by Colist-out and
-- Colist-coind).
postulate
Colist : D → Set
postulate
-- Colist is a post-fixed point of ColistF, i.e.
--
-- Colist ≤ ColistF Colist.
Colist-out : ∀ {xs} → Colist xs →
xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Colist xs')
{-# ATP axiom Colist-out #-}
-- Colist is the greatest post-fixed point of ColistF, i.e.
--
-- ∀ A. A ≤ ColistF A ⇒ A ≤ Colist.
--
-- N.B. This is an axiom schema. Because in the automatic proofs we
-- *must* use an instance, we do not add this postulate as an ATP
-- axiom.
postulate
Colist-coind :
(A : D → Set) →
-- A is post-fixed point of ColistF.
(∀ {xs} → A xs → xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs')) →
-- Colist is greater than A.
∀ {xs} → A xs → Colist xs
|
{
"alphanum_fraction": 0.4941176471,
"avg_line_length": 31.0576923077,
"ext": "agda",
"hexsha": "6e25f5502c53aa6ada6e29a571bb8a4465532376",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/Colist/Type.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Colist/Type.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/Colist/Type.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 462,
"size": 1615
}
|
module Eq where
infix 4 _≡_
{-
data _≡_ {A : Set} : A → A → Set where
Refl : {x : A} → x ≡ x
-}
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
Refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL Refl #-}
|
{
"alphanum_fraction": 0.4977578475,
"avg_line_length": 14.8666666667,
"ext": "agda",
"hexsha": "cec06c6fc3a28c1b1495d13819fbee9fe47ab187",
"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": "76743baacba0f07992bac5234ba8045d18706893",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "mjhopkins/PowerOfPi",
"max_forks_repo_path": "Eq.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76743baacba0f07992bac5234ba8045d18706893",
"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": "mjhopkins/PowerOfPi",
"max_issues_repo_path": "Eq.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76743baacba0f07992bac5234ba8045d18706893",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "mjhopkins/PowerOfPi",
"max_stars_repo_path": "Eq.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-25T13:12:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-25T13:12:15.000Z",
"num_tokens": 102,
"size": 223
}
|
-- {-# OPTIONS -v tc.cc:30 -v tc.cover.splittree:10 #-}
-- 2013-05-03 Andreas, issue raise by Nisse.
module Issue842 where
data D : Set where
c₁ c₂ : D
F : D → Set₁
F c₁ = Set
F = λ _ → Set
-- While not unthinkable, this is not the intended use of varying arity.
-- Since we are already splitting on the first argument, it should be
-- present on the lhs also in the second clause.
-- This will now give the error:
-- Incomplete pattern matching for F. Missing cases:
-- F c₂
|
{
"alphanum_fraction": 0.6865979381,
"avg_line_length": 24.25,
"ext": "agda",
"hexsha": "6cf8a63fb9ff2c9239f4970d4c765a0792441bf4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue842.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue842.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue842.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 142,
"size": 485
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Monoidal
module Experiment.Categories.Solver.Category.Monoidal
{o ℓ e} {𝒞 : Category o ℓ e} (M : Monoidal 𝒞) where
open import Level
open import Relation.Binary using (Rel; REL)
open import Data.List
open import Categories.Morphism 𝒞
open Category 𝒞
open Monoidal M
infixr 10 _:⊗₀_ _:⊗₁_
data Sig : Set o where
∥_∥ : Obj → Sig
:unit : Sig
_:⊗₀_ : Sig → Sig → Sig
private
variable
A B C : Obj
W X Y Z : Sig
data Expr : Rel Sig (o ⊔ ℓ) where
:id : Expr X X
_:∘_ : Expr Y Z → Expr X Y → Expr X Z
_:⊗₁_ : Expr X Y → Expr Z W → Expr (X :⊗₀ Z) (Y :⊗₀ W)
:λ⇒ : Expr (:unit :⊗₀ X) X
:λ⇐ : Expr X (:unit :⊗₀ X)
:ρ⇒ : Expr (X :⊗₀ :unit) X
:ρ⇐ : Expr X (X :⊗₀ :unit)
:α⇒ : Expr ((X :⊗₀ Y) :⊗₀ Z) (X :⊗₀ (Y :⊗₀ Z))
:α⇐ : Expr (X :⊗₀ (Y :⊗₀ Z)) ((X :⊗₀ Y) :⊗₀ Z)
-- ∥_∥ : A ⇒ B → Expr ∥ A ∥ ∥ B ∥
NSig : Set o
NSig = List Obj
{-
data NExpr : REL Sig NSig (o ⊔ ℓ) where
:id : NExpr ∥ A ∥ (A ∷ [])
:λ⇒ : NExpr (:unit :⊗₀ X) (normaliseSig X)
-}
⟦_⟧Sig : Sig → Obj
⟦ ∥ A ∥ ⟧Sig = A
⟦ :unit ⟧Sig = unit
⟦ X :⊗₀ Y ⟧Sig = ⟦ X ⟧Sig ⊗₀ ⟦ Y ⟧Sig
⟦_⟧NSig : NSig → Obj
⟦ [] ⟧NSig = unit
⟦ A ∷ X ⟧NSig = A ⊗₀ ⟦ X ⟧NSig
normaliseSig : Sig → NSig
normaliseSig ∥ A ∥ = A ∷ []
normaliseSig :unit = []
normaliseSig (X :⊗₀ Y) = normaliseSig X ++ normaliseSig Y
private
λ⇒ = unitorˡ.from
λ⇐ = unitorˡ.to
ρ⇒ = unitorʳ.from
ρ⇐ = unitorʳ.to
α⇒ = associator.from
α⇐ = associator.to
⟦_⟧ : Expr X Y → ⟦ X ⟧Sig ⇒ ⟦ Y ⟧Sig
⟦ :id ⟧ = id
⟦ e₁ :∘ e₂ ⟧ = ⟦ e₁ ⟧ ∘ ⟦ e₂ ⟧
⟦ e₁ :⊗₁ e₂ ⟧ = ⟦ e₁ ⟧ ⊗₁ ⟦ e₂ ⟧
⟦ :λ⇒ ⟧ = λ⇒
⟦ :λ⇐ ⟧ = λ⇐
⟦ :ρ⇒ ⟧ = ρ⇒
⟦ :ρ⇐ ⟧ = ρ⇐
⟦ :α⇒ ⟧ = α⇒
⟦ :α⇐ ⟧ = α⇐
⟦_⟧⁻¹ : Expr X Y → ⟦ Y ⟧Sig ⇒ ⟦ X ⟧Sig
⟦ :id ⟧⁻¹ = id
⟦ e₁ :∘ e₂ ⟧⁻¹ = ⟦ e₂ ⟧⁻¹ ∘ ⟦ e₁ ⟧⁻¹
⟦ e₁ :⊗₁ e₂ ⟧⁻¹ = ⟦ e₁ ⟧⁻¹ ⊗₁ ⟦ e₂ ⟧⁻¹
⟦ :λ⇒ ⟧⁻¹ = λ⇐
⟦ :λ⇐ ⟧⁻¹ = λ⇒
⟦ :ρ⇒ ⟧⁻¹ = ρ⇐
⟦ :ρ⇐ ⟧⁻¹ = ρ⇒
⟦ :α⇒ ⟧⁻¹ = α⇐
⟦ :α⇐ ⟧⁻¹ = α⇒
⟦_⟧≅ : Expr X Y → ⟦ X ⟧Sig ≅ ⟦ Y ⟧Sig
⟦ :id ⟧≅ = ≅.refl
⟦ e₁ :∘ e₂ ⟧≅ = ≅.trans ⟦ e₂ ⟧≅ ⟦ e₁ ⟧≅
⟦ e₁ :⊗₁ e₂ ⟧≅ = {! !}
⟦ :λ⇒ ⟧≅ = {! !}
⟦ :λ⇐ ⟧≅ = {! !}
⟦ :ρ⇒ ⟧≅ = {! !}
⟦ :ρ⇐ ⟧≅ = {! !}
⟦ :α⇒ ⟧≅ = {! !}
⟦ :α⇐ ⟧≅ = {! !}
-- theorem : (e₁ e₂ : Expr S T) → ⟦ e₁ ⟧ ≈ ⟦ e₂ ⟧
-- lemma : Expr S T → ⟦ S ⟧Sig ≅ ⟦ T ⟧Sig
-- lemma : ⟦ normaliseSig S ⟧NSig ≅ ⟦ S ⟧Sig
-- resp : ⟦ S ⟧NSig ≅ ⟦ T ⟧NSig
-- lemma : Expr S T → normaliseSig S ≡ normaliseSig T
|
{
"alphanum_fraction": 0.4436119874,
"avg_line_length": 22.6428571429,
"ext": "agda",
"hexsha": "63d1c905ad3fe89a933a9466ec5472c0238e4788",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Categories/Solver/Category/Monoidal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Categories/Solver/Category/Monoidal.agda",
"max_line_length": 57,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Categories/Solver/Category/Monoidal.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 1475,
"size": 2536
}
|
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}
module 23-id-pushout where
import 22-descent
open 22-descent public
-- Section 19.1 Characterizing families of maps over pushouts
module hom-Fam-pushout
{ l1 l2 l3 l4 l5 : Level}
{ S : UU l1}
{ A : UU l2}
{ B : UU l3}
{ f : S → A}
{ g : S → B}
( P : Fam-pushout l4 f g)
( Q : Fam-pushout l5 f g)
where
private
PA = pr1 P
PB = pr1 (pr2 P)
PS = pr2 (pr2 P)
QA = pr1 Q
QB = pr1 (pr2 Q)
QS = pr2 (pr2 Q)
{- Definition 19.1.1 -}
hom-Fam-pushout :
UU (l1 ⊔ l2 ⊔ l3 ⊔ l4 ⊔ l5)
hom-Fam-pushout =
Σ ( (x : A) → (PA x) → (QA x)) (λ hA →
Σ ( (y : B) → (PB y) → (QB y)) (λ hB →
( s : S) →
( (hB (g s)) ∘ (map-equiv (PS s))) ~ ((map-equiv (QS s)) ∘ (hA (f s)))))
{- Remark 19.1.2. We characterize the identity type of hom-Fam-pushout. -}
htpy-hom-Fam-pushout :
( h k : hom-Fam-pushout) → UU (l1 ⊔ l2 ⊔ l3 ⊔ l4 ⊔ l5)
htpy-hom-Fam-pushout h k =
Σ ( (x : A) → (pr1 h x) ~ (pr1 k x)) (λ HA →
Σ ( (y : B) → (pr1 (pr2 h) y) ~ (pr1 (pr2 k) y)) (λ HB →
( s : S) →
( ((HB (g s)) ·r (map-equiv (PS s))) ∙h (pr2 (pr2 k) s)) ~
( (pr2 (pr2 h) s) ∙h ((map-equiv (QS s)) ·l (HA (f s))))))
reflexive-htpy-hom-Fam-pushout :
( h : hom-Fam-pushout) → htpy-hom-Fam-pushout h h
reflexive-htpy-hom-Fam-pushout h =
pair
( λ x → htpy-refl)
( pair
( λ y → htpy-refl)
( λ s → htpy-inv htpy-right-unit))
htpy-hom-Fam-pushout-eq :
( h k : hom-Fam-pushout) → Id h k → htpy-hom-Fam-pushout h k
htpy-hom-Fam-pushout-eq h .h refl =
reflexive-htpy-hom-Fam-pushout h
is-contr-total-htpy-hom-Fam-pushout :
( h : hom-Fam-pushout) →
is-contr (Σ (hom-Fam-pushout) (htpy-hom-Fam-pushout h))
is-contr-total-htpy-hom-Fam-pushout h =
is-contr-total-Eq-structure
( λ kA kB-ke (HA : (x : A) → (pr1 h x) ~ (kA x)) →
Σ ( (y : B) → (pr1 (pr2 h) y) ~ (pr1 kB-ke y)) (λ HB →
( s : S) →
( ((HB (g s)) ·r (map-equiv (PS s))) ∙h (pr2 kB-ke s)) ~
( (pr2 (pr2 h) s) ∙h ((map-equiv (QS s)) ·l (HA (f s))))))
( is-contr-total-Eq-Π
( λ x τ → (pr1 h x) ~ τ)
( λ x → is-contr-total-htpy (pr1 h x))
( pr1 h))
( pair (pr1 h) (λ x → htpy-refl))
( is-contr-total-Eq-structure
( λ kB ke (HB : (y : B) → (pr1 (pr2 h) y) ~ kB y) →
(s : S) →
( ((HB (g s)) ·r (map-equiv (PS s))) ∙h (ke s)) ~
( (pr2 (pr2 h) s) ∙h ((map-equiv (QS s)) ·l htpy-refl)))
( is-contr-total-Eq-Π
( λ y τ → (pr1 (pr2 h) y) ~ τ)
( λ y → is-contr-total-htpy (pr1 (pr2 h) y))
( pr1 (pr2 h)))
( pair (pr1 (pr2 h)) (λ y → htpy-refl))
( is-contr-total-Eq-Π
( λ (s : S) he →
(he ~ (pr2 (pr2 h) s ∙h (map-equiv (QS s) ·l htpy-refl))))
( λ s → is-contr-total-htpy'
((pr2 (pr2 h) s) ∙h ((map-equiv (QS s)) ·l htpy-refl)))
( λ s →
((pr2 (pr2 h) s) ∙h ((map-equiv (QS s)) ·l htpy-refl)))))
is-equiv-htpy-hom-Fam-pushout-eq :
( h k : hom-Fam-pushout) → is-equiv (htpy-hom-Fam-pushout-eq h k)
is-equiv-htpy-hom-Fam-pushout-eq h =
fundamental-theorem-id h
( reflexive-htpy-hom-Fam-pushout h)
( is-contr-total-htpy-hom-Fam-pushout h)
( htpy-hom-Fam-pushout-eq h)
eq-htpy-hom-Fam-pushout :
( h k : hom-Fam-pushout) → htpy-hom-Fam-pushout h k → Id h k
eq-htpy-hom-Fam-pushout h k =
inv-is-equiv (is-equiv-htpy-hom-Fam-pushout-eq h k)
open hom-Fam-pushout public
{- Definition 19.1.3. Given a cocone structure on X and a family of maps indexed
by X, we obtain a morphism of descent data. -}
Naturality-fam-maps :
{ l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : A → UU l3}
( f : (a : A) → B a → C a) {x x' : A} (p : Id x x') → UU _
Naturality-fam-maps {B = B} {C} f {x} {x'} p =
(y : B x) → Id (f x' (tr B p y)) (tr C p (f x y))
naturality-fam-maps :
{ l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : A → UU l3}
( f : (a : A) → B a → C a) {x x' : A} (p : Id x x') →
Naturality-fam-maps f p
naturality-fam-maps f refl y = refl
hom-Fam-pushout-map :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( P : X → UU l5) (Q : X → UU l6) → ((x : X) → P x → Q x) →
hom-Fam-pushout (desc-fam c P) (desc-fam c Q)
hom-Fam-pushout-map {f = f} {g} c P Q h =
pair
( precomp-Π (pr1 c) (λ x → P x → Q x) h)
( pair
( precomp-Π (pr1 (pr2 c)) (λ x → P x → Q x) h)
( λ s → naturality-fam-maps h (pr2 (pr2 c) s)))
{- Theorem 19.1.4. The function hom-Fam-pushout-map is an equivalence. -}
square-path-over-fam-maps :
{ l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : A → UU l3}
{ x x' : A} (p : Id x x') (f : B x → C x) (f' : B x' → C x') →
Id (tr (λ a → B a → C a) p f) f' →
( y : B x) → Id (f' (tr B p y)) (tr C p (f y))
square-path-over-fam-maps refl f f' = htpy-eq ∘ inv
hom-Fam-pushout-dep-cocone :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( P : X → UU l5) (Q : X → UU l6) →
dep-cocone f g c (λ x → P x → Q x) →
hom-Fam-pushout (desc-fam c P) (desc-fam c Q)
hom-Fam-pushout-dep-cocone {f = f} {g} c P Q =
tot (λ hA → tot (λ hB →
postcomp-Π (λ s →
square-path-over-fam-maps (pr2 (pr2 c) s) (hA (f s)) (hB (g s)))))
is-equiv-square-path-over-fam-maps :
{ l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : A → UU l3}
{ x x' : A} (p : Id x x') (f : B x → C x) (f' : B x' → C x') →
is-equiv (square-path-over-fam-maps p f f')
is-equiv-square-path-over-fam-maps refl f f' =
is-equiv-comp' htpy-eq inv (is-equiv-inv f f') (funext f' f)
is-equiv-hom-Fam-pushout-dep-cocone :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( P : X → UU l5) (Q : X → UU l6) →
is-equiv (hom-Fam-pushout-dep-cocone c P Q)
is-equiv-hom-Fam-pushout-dep-cocone {f = f} {g} c P Q =
is-equiv-tot-is-fiberwise-equiv (λ hA →
is-equiv-tot-is-fiberwise-equiv (λ hB →
is-equiv-postcomp-Π _
( λ s → is-equiv-square-path-over-fam-maps
( pr2 (pr2 c) s)
( hA (f s))
( hB (g s)))))
coherence-naturality-fam-maps :
{ l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} (P : B → UU l3) (Q : B → UU l4) →
{ f f' : A → B} (H : f ~ f') (h : (b : B) → P b → Q b) (a : A) →
Id ( square-path-over-fam-maps (H a) (h (f a)) (h (f' a)) (apd h (H a)))
( naturality-fam-maps h (H a))
coherence-naturality-fam-maps {A = A} {B} P Q {f} {f'} H =
ind-htpy f
( λ f' H →
( h : (b : B) → P b → Q b) (a : A) →
Id ( square-path-over-fam-maps (H a) (h (f a)) (h (f' a)) (apd h (H a)))
( naturality-fam-maps h (H a)))
( λ h a → refl)
( H)
triangle-hom-Fam-pushout-dep-cocone :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( P : X → UU l5) (Q : X → UU l6) →
( hom-Fam-pushout-map c P Q) ~
( ( hom-Fam-pushout-dep-cocone c P Q) ∘
( dep-cocone-map f g c (λ x → P x → Q x)))
triangle-hom-Fam-pushout-dep-cocone {f = f} {g} c P Q h =
eq-htpy-hom-Fam-pushout
( desc-fam c P)
( desc-fam c Q)
( hom-Fam-pushout-map c P Q h)
( hom-Fam-pushout-dep-cocone c P Q
( dep-cocone-map f g c (λ x → P x → Q x) h))
( pair
( λ a → htpy-refl)
( pair
( λ b → htpy-refl)
( λ s →
( htpy-eq
( coherence-naturality-fam-maps P Q (pr2 (pr2 c)) h s)) ∙h
( htpy-inv htpy-right-unit))))
is-equiv-hom-Fam-pushout-map :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( up-X : (l : Level) → universal-property-pushout l f g c)
( P : X → UU l5) (Q : X → UU l6) →
is-equiv (hom-Fam-pushout-map c P Q)
is-equiv-hom-Fam-pushout-map {l5 = l5} {l6} {f = f} {g} c up-X P Q =
is-equiv-comp
( hom-Fam-pushout-map c P Q)
( hom-Fam-pushout-dep-cocone c P Q)
( dep-cocone-map f g c (λ x → P x → Q x))
( triangle-hom-Fam-pushout-dep-cocone c P Q)
( dependent-universal-property-universal-property-pushout
f g c up-X (l5 ⊔ l6) (λ x → P x → Q x))
( is-equiv-hom-Fam-pushout-dep-cocone c P Q)
equiv-hom-Fam-pushout-map :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( up-X : (l : Level) → universal-property-pushout l f g c)
( P : X → UU l5) (Q : X → UU l6) →
( (x : X) → P x → Q x) ≃
hom-Fam-pushout (desc-fam c P) (desc-fam c Q)
equiv-hom-Fam-pushout-map c up-X P Q =
pair
( hom-Fam-pushout-map c P Q)
( is-equiv-hom-Fam-pushout-map c up-X P Q)
{- Definition 19.2.1. Universal families over spans -}
ev-pt-hom-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} (P : Fam-pushout l4 f g) (Q : Fam-pushout l5 f g)
{a : A} → (pr1 P a) → (hom-Fam-pushout P Q) → pr1 Q a
ev-pt-hom-Fam-pushout P Q {a} p h = pr1 h a p
is-universal-Fam-pushout :
{ l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} (P : Fam-pushout l4 f g) (a : A) (p : pr1 P a) →
UU (l1 ⊔ l2 ⊔ l3 ⊔ l4 ⊔ lsuc l)
is-universal-Fam-pushout l {f = f} {g} P a p =
( Q : Fam-pushout l f g) → is-equiv (ev-pt-hom-Fam-pushout P Q p)
{- Lemma 19.2.2. The descent data of the identity type is a universal family. -}
triangle-is-universal-id-Fam-pushout' :
{ l l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X)
(a : A) ( Q : (x : X) → UU l) →
( ev-refl (pr1 c a) {B = λ x p → Q x}) ~
( ( ev-pt-hom-Fam-pushout
( desc-fam c (Id (pr1 c a)))
( desc-fam c Q)
( refl)) ∘
( hom-Fam-pushout-map c (Id (pr1 c a)) Q))
triangle-is-universal-id-Fam-pushout' c a Q = htpy-refl
is-universal-id-Fam-pushout' :
{ l l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X)
( up-X : (l' : Level) → universal-property-pushout l' f g c) (a : A) →
( Q : (x : X) → UU l) →
is-equiv
( ev-pt-hom-Fam-pushout
( desc-fam c (Id (pr1 c a)))
( desc-fam c Q)
( refl))
is-universal-id-Fam-pushout' c up-X a Q =
is-equiv-left-factor
( ev-refl (pr1 c a) {B = λ x p → Q x})
( ev-pt-hom-Fam-pushout
( desc-fam c (Id (pr1 c a)))
( desc-fam c Q)
( refl))
( hom-Fam-pushout-map c (Id (pr1 c a)) Q)
( triangle-is-universal-id-Fam-pushout' c a Q)
( is-equiv-ev-refl (pr1 c a))
( is-equiv-hom-Fam-pushout-map c up-X (Id (pr1 c a)) Q)
is-universal-id-Fam-pushout :
{ l1 l2 l3 l4 : Level} (l : Level)
{ S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4}
{ f : S → A} {g : S → B} (c : cocone f g X)
( up-X : (l' : Level) → universal-property-pushout l' f g c) (a : A) →
is-universal-Fam-pushout l (desc-fam c (Id (pr1 c a))) a refl
is-universal-id-Fam-pushout l {S = S} {A} {B} {X} {f} {g} c up-X a Q =
inv-map-equiv
( precomp-Π-equiv
( equiv-desc-fam c up-X)
( λ (Q : Fam-pushout l f g) →
is-equiv (ev-pt-hom-Fam-pushout
( desc-fam c (Id (pr1 c a))) Q refl)))
( is-universal-id-Fam-pushout' c up-X a)
( Q)
{- We construct the identity morphism and composition, and we show that
morphisms equipped with two-sided inverses are equivalences. -}
id-hom-Fam-pushout :
{ l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} →
( P : Fam-pushout l4 f g) → hom-Fam-pushout P P
id-hom-Fam-pushout P =
pair
( λ a → id)
( pair
( λ b → id)
( λ s → htpy-refl))
comp-hom-Fam-pushout :
{ l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} →
( P : Fam-pushout l4 f g) (Q : Fam-pushout l5 f g) (R : Fam-pushout l6 f g) →
hom-Fam-pushout Q R → hom-Fam-pushout P Q → hom-Fam-pushout P R
comp-hom-Fam-pushout {f = f} {g} P Q R k h =
pair
( λ a → (pr1 k a) ∘ (pr1 h a))
( pair
( λ b → (pr1 (pr2 k) b) ∘ (pr1 (pr2 h) b))
( λ s → coherence-square-comp-horizontal
( pr1 h (f s))
( pr1 k (f s))
( map-equiv (pr2 (pr2 P) s))
( map-equiv (pr2 (pr2 Q) s))
( map-equiv (pr2 (pr2 R) s))
( pr1 (pr2 h) (g s))
( pr1 (pr2 k) (g s))
( pr2 (pr2 h) s)
( pr2 (pr2 k) s)))
has-inverse-hom-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} →
( P : Fam-pushout l4 f g) (Q : Fam-pushout l5 f g) (h : hom-Fam-pushout P Q) →
UU (l1 ⊔ l2 ⊔ l3 ⊔ l4 ⊔ l5)
has-inverse-hom-Fam-pushout P Q h =
Σ ( hom-Fam-pushout Q P) (λ k →
( htpy-hom-Fam-pushout Q Q
( comp-hom-Fam-pushout Q P Q h k)
( id-hom-Fam-pushout Q)) ×
( htpy-hom-Fam-pushout P P
( comp-hom-Fam-pushout P Q P k h)
( id-hom-Fam-pushout P)))
is-equiv-hom-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} (P : Fam-pushout l4 f g) (Q : Fam-pushout l5 f g) →
hom-Fam-pushout P Q → UU (l2 ⊔ l3 ⊔ l4 ⊔ l5)
is-equiv-hom-Fam-pushout {A = A} {B} {f} {g} P Q h =
((a : A) → is-equiv (pr1 h a)) × ((b : B) → is-equiv (pr1 (pr2 h) b))
is-equiv-has-inverse-hom-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} →
( P : Fam-pushout l4 f g) (Q : Fam-pushout l5 f g) (h : hom-Fam-pushout P Q) →
has-inverse-hom-Fam-pushout P Q h → is-equiv-hom-Fam-pushout P Q h
is-equiv-has-inverse-hom-Fam-pushout P Q h has-inv-h =
pair
( λ a →
is-equiv-has-inverse
( pr1 (pr1 has-inv-h) a)
( pr1 (pr1 (pr2 has-inv-h)) a)
( pr1 (pr2 (pr2 has-inv-h)) a))
( λ b →
is-equiv-has-inverse
( pr1 (pr2 (pr1 has-inv-h)) b)
( pr1 (pr2 (pr1 (pr2 has-inv-h))) b)
( pr1 (pr2 (pr2 (pr2 has-inv-h))) b))
equiv-is-equiv-hom-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
{ f : S → A} {g : S → B} (P : Fam-pushout l4 f g) (Q : Fam-pushout l5 f g) →
( h : hom-Fam-pushout P Q) →
is-equiv-hom-Fam-pushout P Q h → equiv-Fam-pushout P Q
equiv-is-equiv-hom-Fam-pushout P Q h is-equiv-h =
pair
( λ a → pair (pr1 h a) (pr1 is-equiv-h a))
( pair
( λ b → pair (pr1 (pr2 h) b) (pr2 is-equiv-h b))
( pr2 (pr2 h)))
{- Theorem 19.1.3. Characterization of identity types of pushouts. -}
hom-identity-is-universal-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l5}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( up-X : (l : Level) → universal-property-pushout l f g c) →
( P : Fam-pushout l4 f g) (a : A) (p : pr1 P a) →
is-universal-Fam-pushout l5 P a p →
Σ ( hom-Fam-pushout P (desc-fam c (Id (pr1 c a))))
( λ h → Id (pr1 h a p) refl)
hom-identity-is-universal-Fam-pushout {f = f} {g} c up-X P a p is-univ-P =
{!!}
is-identity-is-universal-Fam-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {X : UU l5}
{ f : S → A} {g : S → B} (c : cocone f g X) →
( up-X : (l : Level) → universal-property-pushout l f g c) →
( P : Fam-pushout l4 f g) (a : A) (p : pr1 P a) →
is-universal-Fam-pushout l5 P a p →
Σ ( equiv-Fam-pushout P (desc-fam c (Id (pr1 c a))))
( λ e → Id (map-equiv (pr1 e a) p) refl)
is-identity-is-universal-Fam-pushout {f = f} {g} c up-X a P p₀ is-eq-P = {!!}
|
{
"alphanum_fraction": 0.5112647209,
"avg_line_length": 37.2,
"ext": "agda",
"hexsha": "8149c4e6a693bf5b8a93db25f58275486530ca61",
"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": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tmoux/HoTT-Intro",
"max_forks_repo_path": "Agda/23-id-pushout.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "tmoux/HoTT-Intro",
"max_issues_repo_path": "Agda/23-id-pushout.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tmoux/HoTT-Intro",
"max_stars_repo_path": "Agda/23-id-pushout.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6875,
"size": 15624
}
|
-- In Agda 2.5.3 the error was:
-- μ₂ is not strictly positive, because it occurs
-- in the third argument to ⟦_⟧
-- in the type of the constructor fix
-- in the definition of μ₂.
open import Data.Nat using (ℕ;zero;suc)
open import Data.Fin using (Fin;zero;suc)
open import Data.Vec
open import Data.Empty
open import Data.Product
open import Data.Sum
open import Data.Unit
Σ# : {n : ℕ} -> (Fin n -> Set) -> Set
Σ# {zero} f = ⊥
Σ# {suc zero} f = f zero
Σ# {suc n} f = f zero ⊎ Σ# {n} λ i -> f (suc i)
module Matrices {Ix : Set} {Σ : (Ix -> Set) -> Set} where
Matrix : Set1
Matrix = (i j : Ix) -> Set
_<+>_ : Matrix -> Matrix -> Matrix
m <+> n = λ i j -> m i j ⊎ n i j
{-# INLINE _<+>_ #-}
_<*>_ : Matrix -> Matrix -> Matrix
m <*> n = λ i j -> Σ λ k -> m i k × n k j
{-# INLINE _<*>_ #-}
data Poly {Coeffs : Set1} : Set1 where
0p 1p : Poly
X : Poly
_+_ _*_ : (D1 D2 : Poly {Coeffs}) -> Poly {Coeffs}
K : Coeffs -> Poly
module Dim {n : ℕ} where
open Matrices {Fin n} {Σ#}
⟦_⟧ : Poly {Vec (Vec Set n) n} -> Matrix -> Matrix
⟦ 0p ⟧ x i j = ⊥
⟦ 1p ⟧ x i j = ⊤
⟦ X ⟧ x i j = x i j
⟦ D1 + D2 ⟧ x i j = (⟦ D1 ⟧ x <+> ⟦ D2 ⟧ x) i j
⟦ D1 * D2 ⟧ x i j = (⟦ D1 ⟧ x <*> ⟦ D2 ⟧ x) i j
⟦ K S ⟧ x i j = lookup (lookup S i) j
⟪_⟫ : Poly {Set} -> Set → Set
⟪ 0p ⟫ x = ⊥
⟪ 1p ⟫ x = ⊤
⟪ X ⟫ x = x
⟪ D1 + D2 ⟫ x = (⟪ D1 ⟫ x ⊎ ⟪ D2 ⟫ x)
⟪ D1 * D2 ⟫ x = (⟪ D1 ⟫ x × ⟪ D2 ⟫ x)
⟪ K S ⟫ x = S
data μ₁ (p : Poly) : Set where
fix : ⟪ p ⟫ (μ₁ p) -> μ₁ p
data μ₂ (p : Poly) (i j : Fin n) : Set where
fix : ⟦ p ⟧ (μ₂ p) i j -> μ₂ p i j
|
{
"alphanum_fraction": 0.5012626263,
"avg_line_length": 24.75,
"ext": "agda",
"hexsha": "930dd97be843057ec8c1bc675259340baf6a98eb",
"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": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jappeace/agda",
"max_forks_repo_path": "test/LibSucceed/Issue421.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"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": "jappeace/agda",
"max_issues_repo_path": "test/LibSucceed/Issue421.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jappeace/agda",
"max_stars_repo_path": "test/LibSucceed/Issue421.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 736,
"size": 1584
}
|
{-# OPTIONS --without-K #-}
module hott.level.core where
open import level
open import sum
open import sets.nat.core
open import equality.core
open import equality.groupoid
h : ∀ {i} → ℕ → Set i → Set i
h 0 X = Σ X λ x → (x' : X) → x ≡ x'
h (suc n) X = (x x' : X) → h n (x ≡ x')
contr : ∀ {i} → Set i → Set i
contr = h 0
prop : ∀ {i} → Set i → Set i
prop X = (x x' : X) → x ≡ x'
h1⇒prop : ∀ {i} {X : Set i} → h 1 X → prop X
h1⇒prop h1 x x' = proj₁ (h1 x x')
prop⇒h1 : ∀ {i} {X : Set i} → prop X → h 1 X
prop⇒h1 {X = X} f x y = p₀ x y , lem x y
where
p₀ : (x y : X) → x ≡ y
p₀ x y = f x y · (f y y)⁻¹
lem : (x y : X)(p : x ≡ y) → p₀ x y ≡ p
lem x .x refl = left-inverse (f x x)
contr⇒prop : ∀ {i} {X : Set i} → contr X → prop X
contr⇒prop (x , p) = λ x' x'' → sym (p x') · p x''
h↑ : ∀ {i n}{X : Set i} → h n X → h (suc n) X
h↑ {n = 0} c = prop⇒h1 (contr⇒prop c)
h↑ {n = suc n} hn = λ x x' → h↑ (hn x x')
-- Prop: the set of propositions
HProp : ∀ i → Set (lsuc i)
HProp i = Σ (Set i) (h 1)
-- HSet : sets
HSet : ∀ i → Set (lsuc i)
HSet i = Σ (Set i) (h 2)
-- Types by h-level (shifted by 2)
Type : ∀ i → ℕ → Set (lsuc i)
Type i n = Σ (Set i) (h (suc (suc n)))
_⁻¹_ : ∀ {i k} {X : Set i} {Y : Set k} → (X → Y) → Y → Set (i ⊔ k)
f ⁻¹ y = Σ _ λ x → f x ≡ y
-- singletons are contractible
singl-contr : ∀ {i} {A : Set i} → (x : A) → contr (singleton x)
singl-contr {A = A} x = (x , refl) , λ { (x' , p) → lem x' p }
where
lem : (x' : A)(p : x ≡ x') → (x , refl) ≡ (x' , p)
lem .x refl = refl
singl-contr' : ∀ {i} {A : Set i} → (x : A) → contr (singleton' x)
singl-contr' {A = A} x = (x , refl) , λ { (x' , p) → lem x' p }
where
lem : (x' : A)(p : x' ≡ x) → (x , refl) ≡ (x' , p)
lem .x refl = refl
|
{
"alphanum_fraction": 0.4771167048,
"avg_line_length": 26.4848484848,
"ext": "agda",
"hexsha": "534f4de794b801411d6c8507a69dfe428fc067ea",
"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": "hott/level/core.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": "hott/level/core.agda",
"max_line_length": 66,
"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": "hott/level/core.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": 823,
"size": 1748
}
|
{-# OPTIONS --allow-unsolved-metas #-}
open import Level
open import Ordinals
module OD {n : Level } (O : Ordinals {n} ) where
open import zf
open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ )
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import Data.Nat.Properties
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary hiding (_⇔_)
open import Relation.Binary.Core hiding (_⇔_)
open import logic
import OrdUtil
open import nat
open Ordinals.Ordinals O
open Ordinals.IsOrdinals isOrdinal
open Ordinals.IsNext isNext
open OrdUtil O
-- Ordinal Definable Set
record OD : Set (suc n ) where
field
def : (x : Ordinal ) → Set n
open OD
open _∧_
open _∨_
open Bool
record _==_ ( a b : OD ) : Set n where
field
eq→ : ∀ { x : Ordinal } → def a x → def b x
eq← : ∀ { x : Ordinal } → def b x → def a x
==-refl : { x : OD } → x == x
==-refl {x} = record { eq→ = λ x → x ; eq← = λ x → x }
open _==_
==-trans : { x y z : OD } → x == y → y == z → x == z
==-trans x=y y=z = record { eq→ = λ {m} t → eq→ y=z (eq→ x=y t) ; eq← = λ {m} t → eq← x=y (eq← y=z t) }
==-sym : { x y : OD } → x == y → y == x
==-sym x=y = record { eq→ = λ {m} t → eq← x=y t ; eq← = λ {m} t → eq→ x=y t }
⇔→== : { x y : OD } → ( {z : Ordinal } → (def x z ⇔ def y z)) → x == y
eq→ ( ⇔→== {x} {y} eq ) {z} m = proj1 eq m
eq← ( ⇔→== {x} {y} eq ) {z} m = proj2 eq m
-- next assumptions are our axiom
--
-- OD is an equation on Ordinals, so it contains Ordinals. If these Ordinals have one-to-one
-- correspondence to the OD then the OD looks like a ZF Set.
--
-- If all ZF Set have supreme upper bound, the solutions of OD have to be bounded, i.e.
-- bbounded ODs are ZF Set. Unbounded ODs are classes.
--
-- In classical Set Theory, HOD is used, as a subset of OD,
-- HOD = { x | TC x ⊆ OD }
-- where TC x is a transitive clusure of x, i.e. Union of all elemnts of all subset of x.
-- This is not possible because we don't have V yet. So we assumes HODs are bounded OD.
--
-- We also assumes HODs are isomorphic to Ordinals, which is ususally proved by Goedel number tricks.
-- There two contraints on the HOD order, one is ∋, the other one is ⊂.
-- ODs have an ovbious maximum, but Ordinals are not, but HOD has no maximum because there is an aribtrary
-- bound on each HOD.
--
-- In classical Set Theory, sup is defined by Uion, since we are working on constructive logic,
-- we need explict assumption on sup.
--
-- ==→o≡ is necessary to prove axiom of extensionality.
-- Ordinals in OD , the maximum
Ords : OD
Ords = record { def = λ x → One }
record HOD : Set (suc n) where
field
od : OD
odmax : Ordinal
<odmax : {y : Ordinal} → def od y → y o< odmax
open HOD
record ODAxiom : Set (suc n) where
field
-- HOD is isomorphic to Ordinal (by means of Goedel number)
& : HOD → Ordinal
* : Ordinal → HOD
c<→o< : {x y : HOD } → def (od y) ( & x ) → & x o< & y
⊆→o≤ : {y z : HOD } → ({x : Ordinal} → def (od y) x → def (od z) x ) → & y o< osuc (& z)
*iso : {x : HOD } → * ( & x ) ≡ x
&iso : {x : Ordinal } → & ( * x ) ≡ x
==→o≡ : {x y : HOD } → (od x == od y) → x ≡ y
sup-o : (A : HOD) → ( ( x : Ordinal ) → def (od A) x → Ordinal ) → Ordinal
sup-o< : (A : HOD) → { ψ : ( x : Ordinal ) → def (od A) x → Ordinal } → ∀ {x : Ordinal } → (lt : def (od A) x ) → ψ x lt o< sup-o A ψ
-- possible order restriction
ho< : {x : HOD} → & x o< next (odmax x)
postulate odAxiom : ODAxiom
open ODAxiom odAxiom
-- odmax minimality
--
-- since we have ==→o≡ , so odmax have to be unique. We should have odmaxmin in HOD.
-- We can calculate the minimum using sup but it is tedius.
-- Only Select has non minimum odmax.
-- We have the same problem on 'def' itself, but we leave it.
odmaxmin : Set (suc n)
odmaxmin = (y : HOD) (z : Ordinal) → ((x : Ordinal)→ def (od y) x → x o< z) → odmax y o< osuc z
-- OD ⇔ Ordinal leads a contradiction, so we need bounded HOD
¬OD-order : ( & : OD → Ordinal ) → ( * : Ordinal → OD ) → ( { x y : OD } → def y ( & x ) → & x o< & y) → ⊥
¬OD-order & * c<→o< = osuc-< <-osuc (c<→o< {Ords} OneObj )
-- Open supreme upper bound leads a contradition, so we use domain restriction on sup
¬open-sup : ( sup-o : (Ordinal → Ordinal ) → Ordinal) → ((ψ : Ordinal → Ordinal ) → (x : Ordinal) → ψ x o< sup-o ψ ) → ⊥
¬open-sup sup-o sup-o< = o<> <-osuc (sup-o< next-ord (sup-o next-ord)) where
next-ord : Ordinal → Ordinal
next-ord x = osuc x
-- Ordinal in OD ( and ZFSet ) Transitive Set
Ord : ( a : Ordinal ) → HOD
Ord a = record { od = record { def = λ y → y o< a } ; odmax = a ; <odmax = lemma } where
lemma : {x : Ordinal} → x o< a → x o< a
lemma {x} lt = lt
od∅ : HOD
od∅ = Ord o∅
odef : HOD → Ordinal → Set n
odef A x = def ( od A ) x
_∋_ : ( a x : HOD ) → Set n
_∋_ a x = odef a ( & x )
-- _c<_ : ( x a : HOD ) → Set n
-- x c< a = a ∋ x
d→∋ : ( a : HOD ) { x : Ordinal} → odef a x → a ∋ (* x)
d→∋ a lt = subst (λ k → odef a k ) (sym &iso) lt
-- odef-subst : {Z : HOD } {X : Ordinal }{z : HOD } {x : Ordinal }→ odef Z X → Z ≡ z → X ≡ x → odef z x
-- odef-subst df refl refl = df
otrans : {a x y : Ordinal } → odef (Ord a) x → odef (Ord x) y → odef (Ord a) y
otrans x<a y<x = ordtrans y<x x<a
-- If we have reverse of c<→o<, everything becomes Ordinal
∈→c<→HOD=Ord : ( o<→c< : {x y : Ordinal } → x o< y → odef (* y) x ) → {x : HOD } → x ≡ Ord (& x)
∈→c<→HOD=Ord o<→c< {x} = ==→o≡ ( record { eq→ = lemma1 ; eq← = lemma2 } ) where
lemma1 : {y : Ordinal} → odef x y → odef (Ord (& x)) y
lemma1 {y} lt = subst ( λ k → k o< & x ) &iso (c<→o< {* y} {x} (d→∋ x lt))
lemma2 : {y : Ordinal} → odef (Ord (& x)) y → odef x y
lemma2 {y} lt = subst (λ k → odef k y ) *iso (o<→c< {y} {& x} lt )
-- avoiding lv != Zero error
orefl : { x : HOD } → { y : Ordinal } → & x ≡ y → & x ≡ y
orefl refl = refl
==-iso : { x y : HOD } → od (* (& x)) == od (* (& y)) → od x == od y
==-iso {x} {y} eq = record {
eq→ = λ {z} d → lemma ( eq→ eq (subst (λ k → odef k z ) (sym *iso) d )) ;
eq← = λ {z} d → lemma ( eq← eq (subst (λ k → odef k z ) (sym *iso) d )) }
where
lemma : {x : HOD } {z : Ordinal } → odef (* (& x)) z → odef x z
lemma {x} {z} d = subst (λ k → odef k z) (*iso) d
=-iso : {x y : HOD } → (od x == od y) ≡ (od (* (& x)) == od y)
=-iso {_} {y} = cong ( λ k → od k == od y ) (sym *iso)
ord→== : { x y : HOD } → & x ≡ & y → od x == od y
ord→== {x} {y} eq = ==-iso (lemma (& x) (& y) (orefl eq)) where
lemma : ( ox oy : Ordinal ) → ox ≡ oy → od (* ox) == od (* oy)
lemma ox ox refl = ==-refl
o≡→== : { x y : Ordinal } → x ≡ y → od (* x) == od (* y)
o≡→== {x} {.x} refl = ==-refl
o∅≡od∅ : * (o∅ ) ≡ od∅
o∅≡od∅ = ==→o≡ lemma where
lemma0 : {x : Ordinal} → odef (* o∅) x → odef od∅ x
lemma0 {x} lt with c<→o< {* x} {* o∅} (subst (λ k → odef (* o∅) k ) (sym &iso) lt)
... | t = subst₂ (λ j k → j o< k ) &iso &iso t
lemma1 : {x : Ordinal} → odef od∅ x → odef (* o∅) x
lemma1 {x} lt = ⊥-elim (¬x<0 lt)
lemma : od (* o∅) == od od∅
lemma = record { eq→ = lemma0 ; eq← = lemma1 }
ord-od∅ : & (od∅ ) ≡ o∅
ord-od∅ = sym ( subst (λ k → k ≡ & (od∅ ) ) &iso (cong ( λ k → & k ) o∅≡od∅ ) )
≡o∅→=od∅ : {x : HOD} → & x ≡ o∅ → od x == od od∅
≡o∅→=od∅ {x} eq = record { eq→ = λ {y} lt → ⊥-elim ( ¬x<0 {y} (subst₂ (λ j k → j o< k ) &iso eq ( c<→o< {* y} {x} (d→∋ x lt))))
; eq← = λ {y} lt → ⊥-elim ( ¬x<0 lt )}
=od∅→≡o∅ : {x : HOD} → od x == od od∅ → & x ≡ o∅
=od∅→≡o∅ {x} eq = trans (cong (λ k → & k ) (==→o≡ {x} {od∅} eq)) ord-od∅
∅0 : record { def = λ x → Lift n ⊥ } == od od∅
eq→ ∅0 {w} (lift ())
eq← ∅0 {w} lt = lift (¬x<0 lt)
∅< : { x y : HOD } → odef x (& y ) → ¬ ( od x == od od∅ )
∅< {x} {y} d eq with eq→ (==-trans eq (==-sym ∅0) ) d
∅< {x} {y} d eq | lift ()
∅6 : { x : HOD } → ¬ ( x ∋ x ) -- no Russel paradox
∅6 {x} x∋x = o<¬≡ refl ( c<→o< {x} {x} x∋x )
odef-iso : {A B : HOD } {x y : Ordinal } → x ≡ y → (odef A y → odef B y) → odef A x → odef B x
odef-iso refl t = t
is-o∅ : ( x : Ordinal ) → Dec ( x ≡ o∅ )
is-o∅ x with trio< x o∅
is-o∅ x | tri< a ¬b ¬c = no ¬b
is-o∅ x | tri≈ ¬a b ¬c = yes b
is-o∅ x | tri> ¬a ¬b c = no ¬b
-- the pair
_,_ : HOD → HOD → HOD
x , y = record { od = record { def = λ t → (t ≡ & x ) ∨ ( t ≡ & y ) } ; odmax = omax (& x) (& y) ; <odmax = lemma } where
lemma : {t : Ordinal} → (t ≡ & x) ∨ (t ≡ & y) → t o< omax (& x) (& y)
lemma {t} (case1 refl) = omax-x _ _
lemma {t} (case2 refl) = omax-y _ _
pair<y : {x y : HOD } → y ∋ x → & (x , x) o< osuc (& y)
pair<y {x} {y} y∋x = ⊆→o≤ lemma where
lemma : {z : Ordinal} → def (od (x , x)) z → def (od y) z
lemma (case1 refl) = y∋x
lemma (case2 refl) = y∋x
-- another possible restriction. We reqest no minimality on odmax, so it may arbitrary larger.
odmax<& : { x y : HOD } → x ∋ y → Set n
odmax<& {x} {y} x∋y = odmax x o< & x
in-codomain : (X : HOD ) → ( ψ : HOD → HOD ) → OD
in-codomain X ψ = record { def = λ x → ¬ ( (y : Ordinal ) → ¬ ( odef X y ∧ ( x ≡ & (ψ (* y ))))) }
_∩_ : ( A B : HOD ) → HOD
A ∩ B = record { od = record { def = λ x → odef A x ∧ odef B x }
; odmax = omin (odmax A) (odmax B) ; <odmax = λ y → min1 (<odmax A (proj1 y)) (<odmax B (proj2 y))}
record _⊆_ ( A B : HOD ) : Set (suc n) where
field
incl : { x : HOD } → A ∋ x → B ∋ x
open _⊆_
infixr 220 _⊆_
-- if we have & (x , x) ≡ osuc (& x), ⊆→o≤ → c<→o<
⊆→o≤→c<→o< : ({x : HOD} → & (x , x) ≡ osuc (& x) )
→ ({y z : HOD } → ({x : Ordinal} → def (od y) x → def (od z) x ) → & y o< osuc (& z) )
→ {x y : HOD } → def (od y) ( & x ) → & x o< & y
⊆→o≤→c<→o< peq ⊆→o≤ {x} {y} y∋x with trio< (& x) (& y)
⊆→o≤→c<→o< peq ⊆→o≤ {x} {y} y∋x | tri< a ¬b ¬c = a
⊆→o≤→c<→o< peq ⊆→o≤ {x} {y} y∋x | tri≈ ¬a b ¬c = ⊥-elim ( o<¬≡ (peq {x}) (pair<y (subst (λ k → k ∋ x) (sym ( ==→o≡ {x} {y} (ord→== b))) y∋x )))
⊆→o≤→c<→o< peq ⊆→o≤ {x} {y} y∋x | tri> ¬a ¬b c =
⊥-elim ( o<> (⊆→o≤ {x , x} {y} y⊆x,x ) lemma1 ) where
lemma : {z : Ordinal} → (z ≡ & x) ∨ (z ≡ & x) → & x ≡ z
lemma (case1 refl) = refl
lemma (case2 refl) = refl
y⊆x,x : {z : Ordinal} → def (od (x , x)) z → def (od y) z
y⊆x,x {z} lt = subst (λ k → def (od y) k ) (lemma lt) y∋x
lemma1 : osuc (& y) o< & (x , x)
lemma1 = subst (λ k → osuc (& y) o< k ) (sym (peq {x})) (osucc c )
ε-induction : { ψ : HOD → Set (suc n)}
→ ( {x : HOD } → ({ y : HOD } → x ∋ y → ψ y ) → ψ x )
→ (x : HOD ) → ψ x
ε-induction {ψ} ind x = subst (λ k → ψ k ) *iso (ε-induction-ord (osuc (& x)) <-osuc ) where
induction : (ox : Ordinal) → ((oy : Ordinal) → oy o< ox → ψ (* oy)) → ψ (* ox)
induction ox prev = ind ( λ {y} lt → subst (λ k → ψ k ) *iso (prev (& y) (o<-subst (c<→o< lt) refl &iso )))
ε-induction-ord : (ox : Ordinal) { oy : Ordinal } → oy o< ox → ψ (* oy)
ε-induction-ord ox {oy} lt = TransFinite {λ oy → ψ (* oy)} induction oy
Select : (X : HOD ) → ((x : HOD ) → Set n ) → HOD
Select X ψ = record { od = record { def = λ x → ( odef X x ∧ ψ ( * x )) } ; odmax = odmax X ; <odmax = λ y → <odmax X (proj1 y) }
Replace : HOD → (HOD → HOD) → HOD
Replace X ψ = record { od = record { def = λ x → (x o< sup-o X (λ y X∋y → & (ψ (* y)))) ∧ def (in-codomain X ψ) x }
; odmax = rmax ; <odmax = rmax<} where
rmax : Ordinal
rmax = sup-o X (λ y X∋y → & (ψ (* y)))
rmax< : {y : Ordinal} → (y o< rmax) ∧ def (in-codomain X ψ) y → y o< rmax
rmax< lt = proj1 lt
--
-- If we have LEM, Replace' is equivalent to Replace
--
in-codomain' : (X : HOD ) → ((x : HOD) → X ∋ x → HOD) → OD
in-codomain' X ψ = record { def = λ x → ¬ ( (y : Ordinal ) → ¬ ( odef X y ∧ ((lt : odef X y) → x ≡ & (ψ (* y ) (d→∋ X lt) )))) }
Replace' : (X : HOD) → ((x : HOD) → X ∋ x → HOD) → HOD
Replace' X ψ = record { od = record { def = λ x → (x o< sup-o X (λ y X∋y → & (ψ (* y) (d→∋ X X∋y) ))) ∧ def (in-codomain' X ψ) x }
; odmax = rmax ; <odmax = rmax< } where
rmax : Ordinal
rmax = sup-o X (λ y X∋y → & (ψ (* y) (d→∋ X X∋y)))
rmax< : {y : Ordinal} → (y o< rmax) ∧ def (in-codomain' X ψ) y → y o< rmax
rmax< lt = proj1 lt
Union : HOD → HOD
Union U = record { od = record { def = λ x → ¬ (∀ (u : Ordinal ) → ¬ ((odef U u) ∧ (odef (* u) x))) }
; odmax = osuc (& U) ; <odmax = umax< } where
umax< : {y : Ordinal} → ¬ ((u : Ordinal) → ¬ def (od U) u ∧ def (od (* u)) y) → y o< osuc (& U)
umax< {y} not = lemma (FExists _ lemma1 not ) where
lemma0 : {x : Ordinal} → def (od (* x)) y → y o< x
lemma0 {x} x<y = subst₂ (λ j k → j o< k ) &iso &iso (c<→o< (d→∋ (* x) x<y ))
lemma2 : {x : Ordinal} → def (od U) x → x o< & U
lemma2 {x} x<U = subst (λ k → k o< & U ) &iso (c<→o< (d→∋ U x<U))
lemma1 : {x : Ordinal} → def (od U) x ∧ def (od (* x)) y → ¬ (& U o< y)
lemma1 {x} lt u<y = o<> u<y (ordtrans (lemma0 (proj2 lt)) (lemma2 (proj1 lt)) )
lemma : ¬ ((& U) o< y ) → y o< osuc (& U)
lemma not with trio< y (& U)
lemma not | tri< a ¬b ¬c = ordtrans a <-osuc
lemma not | tri≈ ¬a refl ¬c = <-osuc
lemma not | tri> ¬a ¬b c = ⊥-elim (not c)
_∈_ : ( A B : HOD ) → Set n
A ∈ B = B ∋ A
OPwr : (A : HOD ) → HOD
OPwr A = Ord ( sup-o (Ord (osuc (& A))) ( λ x A∋x → & ( A ∩ (* x)) ) )
Power : HOD → HOD
Power A = Replace (OPwr (Ord (& A))) ( λ x → A ∩ x )
-- {_} : ZFSet → ZFSet
-- { x } = ( x , x ) -- better to use (x , x) directly
union→ : (X z u : HOD) → (X ∋ u) ∧ (u ∋ z) → Union X ∋ z
union→ X z u xx not = ⊥-elim ( not (& u) ( ⟪ proj1 xx
, subst ( λ k → odef k (& z)) (sym *iso) (proj2 xx) ⟫ ))
union← : (X z : HOD) (X∋z : Union X ∋ z) → ¬ ( (u : HOD ) → ¬ ((X ∋ u) ∧ (u ∋ z )))
union← X z UX∋z = FExists _ lemma UX∋z where
lemma : {y : Ordinal} → odef X y ∧ odef (* y) (& z) → ¬ ((u : HOD) → ¬ (X ∋ u) ∧ (u ∋ z))
lemma {y} xx not = not (* y) ⟪ d→∋ X (proj1 xx) , proj2 xx ⟫
data infinite-d : ( x : Ordinal ) → Set n where
iφ : infinite-d o∅
isuc : {x : Ordinal } → infinite-d x →
infinite-d (& ( Union (* x , (* x , * x ) ) ))
-- ω can be diverged in our case, since we have no restriction on the corresponding ordinal of a pair.
-- We simply assumes infinite-d y has a maximum.
--
-- This means that many of OD may not be HODs because of the & mapping divergence.
-- We should have some axioms to prevent this such as & x o< next (odmax x).
--
-- postulate
-- ωmax : Ordinal
-- <ωmax : {y : Ordinal} → infinite-d y → y o< ωmax
--
-- infinite : HOD
-- infinite = record { od = record { def = λ x → infinite-d x } ; odmax = ωmax ; <odmax = <ωmax }
infinite : HOD
infinite = record { od = record { def = λ x → infinite-d x } ; odmax = next o∅ ; <odmax = lemma } where
u : (y : Ordinal ) → HOD
u y = Union (* y , (* y , * y))
-- next< : {x y z : Ordinal} → x o< next z → y o< next x → y o< next z
lemma8 : {y : Ordinal} → & (* y , * y) o< next (odmax (* y , * y))
lemma8 = ho<
--- (x,y) < next (omax x y) < next (osuc y) = next y
lemmaa : {x y : HOD} → & x o< & y → & (x , y) o< next (& y)
lemmaa {x} {y} x<y = subst (λ k → & (x , y) o< k ) (sym nexto≡) (subst (λ k → & (x , y) o< next k ) (sym (omax< _ _ x<y)) ho< )
lemma81 : {y : Ordinal} → & (* y , * y) o< next (& (* y))
lemma81 {y} = nexto=n (subst (λ k → & (* y , * y) o< k ) (cong (λ k → next k) (omxx _)) lemma8)
lemma9 : {y : Ordinal} → & (* y , (* y , * y)) o< next (& (* y , * y))
lemma9 = lemmaa (c<→o< (case1 refl))
lemma71 : {y : Ordinal} → & (* y , (* y , * y)) o< next (& (* y))
lemma71 = next< lemma81 lemma9
lemma1 : {y : Ordinal} → & (u y) o< next (osuc (& (* y , (* y , * y))))
lemma1 = ho<
--- main recursion
lemma : {y : Ordinal} → infinite-d y → y o< next o∅
lemma {o∅} iφ = x<nx
lemma (isuc {y} x) = next< (lemma x) (next< (subst (λ k → & (* y , (* y , * y)) o< next k) &iso lemma71 ) (nexto=n lemma1))
empty : (x : HOD ) → ¬ (od∅ ∋ x)
empty x = ¬x<0
_=h=_ : (x y : HOD) → Set n
x =h= y = od x == od y
pair→ : ( x y t : HOD ) → (x , y) ∋ t → ( t =h= x ) ∨ ( t =h= y )
pair→ x y t (case1 t≡x ) = case1 (subst₂ (λ j k → j =h= k ) *iso *iso (o≡→== t≡x ))
pair→ x y t (case2 t≡y ) = case2 (subst₂ (λ j k → j =h= k ) *iso *iso (o≡→== t≡y ))
pair← : ( x y t : HOD ) → ( t =h= x ) ∨ ( t =h= y ) → (x , y) ∋ t
pair← x y t (case1 t=h=x) = case1 (cong (λ k → & k ) (==→o≡ t=h=x))
pair← x y t (case2 t=h=y) = case2 (cong (λ k → & k ) (==→o≡ t=h=y))
o<→c< : {x y : Ordinal } → x o< y → (Ord x) ⊆ (Ord y)
o<→c< lt = record { incl = λ z → ordtrans z lt }
⊆→o< : {x y : Ordinal } → (Ord x) ⊆ (Ord y) → x o< osuc y
⊆→o< {x} {y} lt with trio< x y
⊆→o< {x} {y} lt | tri< a ¬b ¬c = ordtrans a <-osuc
⊆→o< {x} {y} lt | tri≈ ¬a b ¬c = subst ( λ k → k o< osuc y) (sym b) <-osuc
⊆→o< {x} {y} lt | tri> ¬a ¬b c with (incl lt) (o<-subst c (sym &iso) refl )
... | ttt = ⊥-elim ( o<¬≡ refl (o<-subst ttt &iso refl ))
ψiso : {ψ : HOD → Set n} {x y : HOD } → ψ x → x ≡ y → ψ y
ψiso {ψ} t refl = t
selection : {ψ : HOD → Set n} {X y : HOD} → ((X ∋ y) ∧ ψ y) ⇔ (Select X ψ ∋ y)
selection {ψ} {X} {y} = ⟪
( λ cond → ⟪ proj1 cond , ψiso {ψ} (proj2 cond) (sym *iso) ⟫ )
, ( λ select → ⟪ proj1 select , ψiso {ψ} (proj2 select) *iso ⟫ )
⟫
selection-in-domain : {ψ : HOD → Set n} {X y : HOD} → Select X ψ ∋ y → X ∋ y
selection-in-domain {ψ} {X} {y} lt = proj1 ((proj2 (selection {ψ} {X} )) lt)
sup-c< : (ψ : HOD → HOD) → {X x : HOD} → X ∋ x → & (ψ x) o< (sup-o X (λ y X∋y → & (ψ (* y))))
sup-c< ψ {X} {x} lt = subst (λ k → & (ψ k) o< _ ) *iso (sup-o< X lt )
replacement← : {ψ : HOD → HOD} (X x : HOD) → X ∋ x → Replace X ψ ∋ ψ x
replacement← {ψ} X x lt = ⟪ sup-c< ψ {X} {x} lt , lemma ⟫ where
lemma : def (in-codomain X ψ) (& (ψ x))
lemma not = ⊥-elim ( not ( & x ) ⟪ lt , cong (λ k → & (ψ k)) (sym *iso)⟫ )
replacement→ : {ψ : HOD → HOD} (X x : HOD) → (lt : Replace X ψ ∋ x) → ¬ ( (y : HOD) → ¬ (x =h= ψ y))
replacement→ {ψ} X x lt = contra-position lemma (lemma2 (proj2 lt)) where
lemma2 : ¬ ((y : Ordinal) → ¬ odef X y ∧ ((& x) ≡ & (ψ (* y))))
→ ¬ ((y : Ordinal) → ¬ odef X y ∧ (* (& x) =h= ψ (* y)))
lemma2 not not2 = not ( λ y d → not2 y ⟪ proj1 d , lemma3 (proj2 d)⟫) where
lemma3 : {y : Ordinal } → (& x ≡ & (ψ (* y))) → (* (& x) =h= ψ (* y))
lemma3 {y} eq = subst (λ k → * (& x) =h= k ) *iso (o≡→== eq )
lemma : ( (y : HOD) → ¬ (x =h= ψ y)) → ( (y : Ordinal) → ¬ odef X y ∧ (* (& x) =h= ψ (* y)) )
lemma not y not2 = not (* y) (subst (λ k → k =h= ψ (* y)) *iso ( proj2 not2 ))
---
--- Power Set
---
--- First consider ordinals in HOD
---
--- A ∩ x = record { def = λ y → odef A y ∧ odef x y } subset of A
--
--
∩-≡ : { a b : HOD } → ({x : HOD } → (a ∋ x → b ∋ x)) → a =h= ( b ∩ a )
∩-≡ {a} {b} inc = record {
eq→ = λ {x} x<a → ⟪ (subst (λ k → odef b k ) &iso (inc (d→∋ a x<a))) , x<a ⟫ ;
eq← = λ {x} x<a∩b → proj2 x<a∩b }
--
-- Transitive Set case
-- we have t ∋ x → Ord a ∋ x means t is a subset of Ord a, that is (Ord a) ∩ t =h= t
-- OPwr (Ord a) is a sup of (Ord a) ∩ t, so OPwr (Ord a) ∋ t
-- OPwr A = Ord ( sup-o ( λ x → & ( A ∩ (* x )) ) )
--
ord-power← : (a : Ordinal ) (t : HOD) → ({x : HOD} → (t ∋ x → (Ord a) ∋ x)) → OPwr (Ord a) ∋ t
ord-power← a t t→A = subst (λ k → odef (OPwr (Ord a)) k ) (lemma1 lemma-eq) lemma where
lemma-eq : ((Ord a) ∩ t) =h= t
eq→ lemma-eq {z} w = proj2 w
eq← lemma-eq {z} w = ⟪ subst (λ k → odef (Ord a) k ) &iso ( t→A (d→∋ t w)) , w ⟫
lemma1 : {a : Ordinal } { t : HOD }
→ (eq : ((Ord a) ∩ t) =h= t) → & ((Ord a) ∩ (* (& t))) ≡ & t
lemma1 {a} {t} eq = subst (λ k → & ((Ord a) ∩ k) ≡ & t ) (sym *iso) (cong (λ k → & k ) (==→o≡ eq ))
lemma2 : (& t) o< (osuc (& (Ord a)))
lemma2 = ⊆→o≤ {t} {Ord a} (λ {x} x<t → subst (λ k → def (od (Ord a)) k) &iso (t→A (d→∋ t x<t)))
lemma : & ((Ord a) ∩ (* (& t)) ) o< sup-o (Ord (osuc (& (Ord a)))) (λ x lt → & ((Ord a) ∩ (* x)))
lemma = sup-o< _ lemma2
--
-- Every set in HOD is a subset of Ordinals, so make OPwr (Ord (& A)) first
-- then replace of all elements of the Power set by A ∩ y
--
-- Power A = Replace (OPwr (Ord (& A))) ( λ y → A ∩ y )
-- we have oly double negation form because of the replacement axiom
--
power→ : ( A t : HOD) → Power A ∋ t → {x : HOD} → t ∋ x → ¬ ¬ (A ∋ x)
power→ A t P∋t {x} t∋x = FExists _ lemma5 lemma4 where
a = & A
lemma2 : ¬ ( (y : HOD) → ¬ (t =h= (A ∩ y)))
lemma2 = replacement→ {λ x → A ∩ x} (OPwr (Ord (& A))) t P∋t
lemma3 : (y : HOD) → t =h= ( A ∩ y ) → ¬ ¬ (A ∋ x)
lemma3 y eq not = not (proj1 (eq→ eq t∋x))
lemma4 : ¬ ((y : Ordinal) → ¬ (t =h= (A ∩ * y)))
lemma4 not = lemma2 ( λ y not1 → not (& y) (subst (λ k → t =h= ( A ∩ k )) (sym *iso) not1 ))
lemma5 : {y : Ordinal} → t =h= (A ∩ * y) → ¬ ¬ (odef A (& x))
lemma5 {y} eq not = (lemma3 (* y) eq) not
power← : (A t : HOD) → ({x : HOD} → (t ∋ x → A ∋ x)) → Power A ∋ t
power← A t t→A = ⟪ lemma1 , lemma2 ⟫ where
a = & A
lemma0 : {x : HOD} → t ∋ x → Ord a ∋ x
lemma0 {x} t∋x = c<→o< (t→A t∋x)
lemma3 : OPwr (Ord a) ∋ t
lemma3 = ord-power← a t lemma0
lemma4 : (A ∩ * (& t)) ≡ t
lemma4 = let open ≡-Reasoning in begin
A ∩ * (& t)
≡⟨ cong (λ k → A ∩ k) *iso ⟩
A ∩ t
≡⟨ sym (==→o≡ ( ∩-≡ {t} {A} t→A )) ⟩
t
∎
sup1 : Ordinal
sup1 = sup-o (Ord (osuc (& (Ord (& A))))) (λ x A∋x → & ((Ord (& A)) ∩ (* x)))
lemma9 : def (od (Ord (Ordinals.osuc O (& (Ord (& A)))))) (& (Ord (& A)))
lemma9 = <-osuc
lemmab : & ((Ord (& A)) ∩ (* (& (Ord (& A) )))) o< sup1
lemmab = sup-o< (Ord (osuc (& (Ord (& A))))) lemma9
lemmad : Ord (osuc (& A)) ∋ t
lemmad = ⊆→o≤ (λ {x} lt → subst (λ k → def (od A) k ) &iso (t→A (d→∋ t lt)))
lemmac : ((Ord (& A)) ∩ (* (& (Ord (& A) )))) =h= Ord (& A)
lemmac = record { eq→ = lemmaf ; eq← = lemmag } where
lemmaf : {x : Ordinal} → def (od ((Ord (& A)) ∩ (* (& (Ord (& A)))))) x → def (od (Ord (& A))) x
lemmaf {x} lt = proj1 lt
lemmag : {x : Ordinal} → def (od (Ord (& A))) x → def (od ((Ord (& A)) ∩ (* (& (Ord (& A)))))) x
lemmag {x} lt = ⟪ lt , subst (λ k → def (od k) x) (sym *iso) lt ⟫
lemmae : & ((Ord (& A)) ∩ (* (& (Ord (& A))))) ≡ & (Ord (& A))
lemmae = cong (λ k → & k ) ( ==→o≡ lemmac)
lemma7 : def (od (OPwr (Ord (& A)))) (& t)
lemma7 with osuc-≡< lemmad
lemma7 | case2 lt = ordtrans (c<→o< lt) (subst (λ k → k o< sup1) lemmae lemmab )
lemma7 | case1 eq with osuc-≡< (⊆→o≤ {* (& t)} {* (& (Ord (& t)))} (λ {x} lt → lemmah lt )) where
lemmah : {x : Ordinal } → def (od (* (& t))) x → def (od (* (& (Ord (& t))))) x
lemmah {x} lt = subst (λ k → def (od k) x ) (sym *iso) (subst (λ k → k o< (& t))
&iso
(c<→o< (subst₂ (λ j k → def (od j) k) *iso (sym &iso) lt )))
lemma7 | case1 eq | case1 eq1 = subst (λ k → k o< sup1) (trans lemmae lemmai) lemmab where
lemmai : & (Ord (& A)) ≡ & t
lemmai = let open ≡-Reasoning in begin
& (Ord (& A))
≡⟨ sym (cong (λ k → & (Ord k)) eq) ⟩
& (Ord (& t))
≡⟨ sym &iso ⟩
& (* (& (Ord (& t))))
≡⟨ sym eq1 ⟩
& (* (& t))
≡⟨ &iso ⟩
& t
∎
lemma7 | case1 eq | case2 lt = ordtrans lemmaj (subst (λ k → k o< sup1) lemmae lemmab ) where
lemmak : & (* (& (Ord (& t)))) ≡ & (Ord (& A))
lemmak = let open ≡-Reasoning in begin
& (* (& (Ord (& t))))
≡⟨ &iso ⟩
& (Ord (& t))
≡⟨ cong (λ k → & (Ord k)) eq ⟩
& (Ord (& A))
∎
lemmaj : & t o< & (Ord (& A))
lemmaj = subst₂ (λ j k → j o< k ) &iso lemmak lt
lemma1 : & t o< sup-o (OPwr (Ord (& A))) (λ x lt → & (A ∩ (* x)))
lemma1 = subst (λ k → & k o< sup-o (OPwr (Ord (& A))) (λ x lt → & (A ∩ (* x))))
lemma4 (sup-o< (OPwr (Ord (& A))) lemma7 )
lemma2 : def (in-codomain (OPwr (Ord (& A))) (_∩_ A)) (& t)
lemma2 not = ⊥-elim ( not (& t) ⟪ lemma3 , lemma6 ⟫ ) where
lemma6 : & t ≡ & (A ∩ * (& t))
lemma6 = cong ( λ k → & k ) (==→o≡ (subst (λ k → t =h= (A ∩ k)) (sym *iso) ( ∩-≡ {t} {A} t→A )))
extensionality0 : {A B : HOD } → ((z : HOD) → (A ∋ z) ⇔ (B ∋ z)) → A =h= B
eq→ (extensionality0 {A} {B} eq ) {x} d = odef-iso {A} {B} (sym &iso) (proj1 (eq (* x))) d
eq← (extensionality0 {A} {B} eq ) {x} d = odef-iso {B} {A} (sym &iso) (proj2 (eq (* x))) d
extensionality : {A B w : HOD } → ((z : HOD ) → (A ∋ z) ⇔ (B ∋ z)) → (w ∋ A) ⇔ (w ∋ B)
proj1 (extensionality {A} {B} {w} eq ) d = subst (λ k → w ∋ k) ( ==→o≡ (extensionality0 {A} {B} eq) ) d
proj2 (extensionality {A} {B} {w} eq ) d = subst (λ k → w ∋ k) (sym ( ==→o≡ (extensionality0 {A} {B} eq) )) d
infinity∅ : infinite ∋ od∅
infinity∅ = subst (λ k → odef infinite k ) lemma iφ where
lemma : o∅ ≡ & od∅
lemma = let open ≡-Reasoning in begin
o∅
≡⟨ sym &iso ⟩
& ( * o∅ )
≡⟨ cong ( λ k → & k ) o∅≡od∅ ⟩
& od∅
∎
infinity : (x : HOD) → infinite ∋ x → infinite ∋ Union (x , (x , x ))
infinity x lt = subst (λ k → odef infinite k ) lemma (isuc {& x} lt) where
lemma : & (Union (* (& x) , (* (& x) , * (& x))))
≡ & (Union (x , (x , x)))
lemma = cong (λ k → & (Union ( k , ( k , k ) ))) *iso
isZF : IsZF (HOD ) _∋_ _=h=_ od∅ _,_ Union Power Select Replace infinite
isZF = record {
isEquivalence = record { refl = ==-refl ; sym = ==-sym; trans = ==-trans }
; pair→ = pair→
; pair← = pair←
; union→ = union→
; union← = union←
; empty = empty
; power→ = power→
; power← = power←
; extensionality = λ {A} {B} {w} → extensionality {A} {B} {w}
; ε-induction = ε-induction
; infinity∅ = infinity∅
; infinity = infinity
; selection = λ {X} {ψ} {y} → selection {X} {ψ} {y}
; replacement← = replacement←
; replacement→ = λ {ψ} → replacement→ {ψ}
}
HOD→ZF : ZF
HOD→ZF = record {
ZFSet = HOD
; _∋_ = _∋_
; _≈_ = _=h=_
; ∅ = od∅
; _,_ = _,_
; Union = Union
; Power = Power
; Select = Select
; Replace = Replace
; infinite = infinite
; isZF = isZF
}
|
{
"alphanum_fraction": 0.4614981077,
"avg_line_length": 43.113085622,
"ext": "agda",
"hexsha": "f1f6f53150ceafa05e2b0491c42642ade89e216b",
"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": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/zf-in-agda",
"max_forks_repo_path": "src/OD.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"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": "shinji-kono/zf-in-agda",
"max_issues_repo_path": "src/OD.agda",
"max_line_length": 143,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/zf-in-agda",
"max_stars_repo_path": "src/OD.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z",
"num_tokens": 11712,
"size": 26687
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
open import homotopy.DisjointlyPointedSet
open import groups.Int
open import cohomology.Theory
open import cohomology.ChainComplex
module cw.cohomology.ReconstructedCochainsIsoCellularCochains {i : ULevel}
(OT : OrdinaryTheory i) where
open OrdinaryTheory OT
open import cw.cohomology.WedgeOfCells OT
open import cw.cohomology.cellular.ChainComplex as CCC
open import cw.cohomology.reconstructed.cochain.Complex OT as RCC
open import cw.cohomology.reconstructed.TipAndAugment OT
private
rcc-iso-ccc-nth : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (m≤n : m ≤ n)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ AbGroup.grp (RCC.cochain-template ⊙skel (inl m≤n))
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (inl m≤n))) (C2-abgroup 0)
rcc-iso-ccc-nth ⊙skel {m = O} (inl idp) ac
= FreeAbGroup-extend-iso (C2-abgroup 0)
∘eᴳ C2×CX₀-diag-β ⊙skel ac
rcc-iso-ccc-nth ⊙skel {m = S m} (inl idp) ac
= FreeAbGroup-extend-iso (C2-abgroup 0)
∘eᴳ CXₙ/Xₙ₋₁-diag-β ⊙skel ac
rcc-iso-ccc-nth ⊙skel {m = O} (inr ltS) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inl idp) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-nth ⊙skel {m = S m} (inr ltS) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inl idp) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-nth ⊙skel {m = O} (inr (ltSR lt)) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inr lt) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-nth ⊙skel {m = S m} (inr (ltSR lt)) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inr lt) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-above : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (m≰n : ¬ (m ≤ n))
→ AbGroup.grp (RCC.cochain-template ⊙skel (inr m≰n))
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (inr m≰n))) (C2-abgroup 0)
rcc-iso-ccc-above ⊙skel _
= pre∘ᴳ-iso (C2-abgroup 0) lower-iso
∘eᴳ trivial-iso-Unit (hom₁-Unit-is-trivial (C2-abgroup 0)) ⁻¹ᴳ
∘eᴳ lower-iso
rcc-iso-ccc-template : ∀ {n} (⊙skel : ⊙Skeleton n) {m : ℕ} (m≤n? : Dec (m ≤ n))
→ ⊙has-cells-with-choice 0 ⊙skel i
→ AbGroup.grp (RCC.cochain-template ⊙skel m≤n?)
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) m≤n?)) (C2-abgroup 0)
rcc-iso-ccc-template ⊙skel {m} (inl m≤n) ac = rcc-iso-ccc-nth ⊙skel m≤n ac
rcc-iso-ccc-template ⊙skel {m} (inr m≰n) _ = rcc-iso-ccc-above ⊙skel m≰n
rcc-iso-ccc : ∀ {n} (⊙skel : ⊙Skeleton n) (m : ℕ)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ AbGroup.grp (RCC.cochain-template ⊙skel (≤-dec m n))
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (≤-dec m n))) (C2-abgroup 0)
rcc-iso-ccc {n} ⊙skel m = rcc-iso-ccc-template ⊙skel (≤-dec m n)
rhead-iso-chead : C2 0 ≃ᴳ hom-group (Lift-group {j = i} ℤ-group) (C2-abgroup 0)
rhead-iso-chead
= pre∘ᴳ-iso (C2-abgroup 0) (lower-iso {j = i})
∘eᴳ ℤ→ᴳ-iso-idf (C2-abgroup 0) ⁻¹ᴳ
|
{
"alphanum_fraction": 0.6352159468,
"avg_line_length": 47.03125,
"ext": "agda",
"hexsha": "f79f6e64ab5d78b28a2f518fa97bdedeea72a59f",
"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": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"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": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1358,
"size": 3010
}
|
module Squash where
data _==_ {A : Set}(a : A) : A -> Set where
refl : a == a
data Wrap (A : Set) : Set where
wrap : A -> Wrap A
data Squash (A : Set) : Set where
squash : .A -> Squash A
postulate
A : Set
a1 a2 : A
irr : squash a1 == squash a2
irr = refl
|
{
"alphanum_fraction": 0.5682656827,
"avg_line_length": 14.2631578947,
"ext": "agda",
"hexsha": "5a11bb95de4039e971b18db1aa0b14154fce2e94",
"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/Squash.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/Squash.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": "test/Succeed/Squash.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": 104,
"size": 271
}
|
module Issue2935 where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
bad : ℕ → ℕ
bad zero = zero
bad suc = zero
|
{
"alphanum_fraction": 0.6052631579,
"avg_line_length": 11.4,
"ext": "agda",
"hexsha": "c54eaa84a9747ab92e0f200ad2e627ea5969fd60",
"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/Issue2935.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/Issue2935.agda",
"max_line_length": 22,
"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/Issue2935.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": 42,
"size": 114
}
|
module Impure.LFRef.Syntax where
open import Prelude
open import Data.Vec hiding ([_]; map)
open import Data.List hiding ([_])
open import Data.List.All hiding (lookup)
data Term : (n : ℕ) → Set
data Type : (n : ℕ) → Set
data Term where
var : ∀ {n} → Fin n → Term n
loc : ∀ {n} → ℕ → Term n
unit : ∀ {n} → Term n
-- constructor application
con : ∀ {n} → (fn : ℕ) → (ts : List (Term n)) → Term n
infixl 30 _·★_
data Exp : ℕ → Set where
-- basic lambda expressions
tm : ∀ {n} → Term n → Exp n
-- function calls
_·★_ : ∀ {n} → (fn : ℕ) → (as : List (Term n)) → Exp n
-- heap manipulation
ref : ∀ {n} → Exp n → Exp n
!_ : ∀ {n} → Exp n → Exp n
_≔_ : ∀ {n} → Exp n → Exp n → Exp n
data SeqExp : ℕ → Set where
lett : ∀ {n} → (x : Exp n) → (e : SeqExp (suc n)) → SeqExp n
ret : ∀ {n} → Exp n → SeqExp n
data Val : Term 0 → Set where
loc : ∀ {i} → Val (loc i)
unit : Val unit
con : ∀ {k ts} → Val (con k ts)
data ExpVal : Exp zero → Set where
tm : ∀ {t} → Val t → ExpVal (tm t)
data SeqExpVal : SeqExp zero → Set where
ret-tm : ∀ {t} → Val t → SeqExpVal (ret (tm t))
-- telescoped contexts/arguments
data Tele : (n m : ℕ) → Set where
ε : ∀ {n} → Tele n 0
_⟶_ : ∀ {m n} → Type n → Tele (suc n) m → Tele n (suc m)
infixl 20 _[_]
data Type where
_[_] : ∀ {n} → ℕ → (ts : List (Term n)) → Type n
Ref : ∀ {n} → (A : Type n) → Type n
Unit : ∀ {n} → Type n
Store : Set
Store = List (∃ Val)
record ConType : Set where
field
m : ℕ
args : Tele 0 m
tp : ℕ
indices : List (Term m)
record Fun : Set where
field
m : ℕ
args : Tele 0 m
returntype : Type m
body : Exp m
record Sig : Set where
field
types : List (∃ (Tele 0))
constructors : List ConType
funs : List Fun
open import Data.Fin.Substitution
module App {T} (l : Lift T Term) where
open Lift l
_tp/_ : ∀ {n n'} → Type n → Sub T n n' → Type n'
_/_ : ∀ {n n'} → Term n → Sub T n n' → Term n'
var x / s = lift $ lookup x s
unit / s = unit
_/_ {n} {n'} (con c ts) s = con c (map/ ts)
where
-- inlined for termination checker..
map/ : List (Term n) → List (Term n')
map/ [] = []
map/ (x ∷ ts₁) = x / s ∷ map/ ts₁
loc x / s = loc x
_tele/_ : ∀ {n m n'} → Tele n m → Sub T n n' → Tele n' m
ε tele/ s = ε
(x ⟶ t) tele/ s = (x tp/ s) ⟶ (t tele/ (s ↑))
_tp/_ {n} {n'} (k [ ts ]) s = k [ map/ ts ]
where
-- inlined for termination checker..
map/ : List (Term n) → List (Term n')
map/ [] = []
map/ (x ∷ ts₁) = x / s ∷ map/ ts₁
(Ref A) tp/ s = Ref (A tp/ s)
Unit tp/ s = Unit
_exp/_ : ∀ {n n'} → Exp n → Sub T n n' → Exp n'
tm x exp/ s = tm (x / s)
_exp/_ {n} {n'} (fn ·★ ts) s = fn ·★ map/ ts
where
-- inlined for termination checker..
map/ : List (Term n) → List (Term n')
map/ [] = []
map/ (x ∷ ts₁) = x / s ∷ map/ ts₁
ref x exp/ s = ref (x exp/ s)
(! x) exp/ s = ! (x exp/ s)
(y ≔ x) exp/ s = (y exp/ s) ≔ (x exp/ s)
_seq/_ : ∀ {n n'} → SeqExp n → Sub T n n' → SeqExp n'
lett x e seq/ s = lett (x exp/ s) (e seq/ (s ↑))
ret e seq/ s = ret (e exp/ s)
open Application (record { _/_ = _/_ }) using (_/✶_)
tmSubst : TermSubst Term
tmSubst = record { var = var; app = App._/_ }
open TermSubst tmSubst hiding (var) public
open App termLift using (_exp/_; _tp/_; _tele/_; _seq/_) public
|
{
"alphanum_fraction": 0.5197387949,
"avg_line_length": 24.7720588235,
"ext": "agda",
"hexsha": "badfa6dbfe17b0ab496d6378719cd42e7e08ea76",
"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/Impure/LFRef/Syntax.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/Impure/LFRef/Syntax.agda",
"max_line_length": 63,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Impure/LFRef/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1313,
"size": 3369
}
|
{-# OPTIONS --type-in-type #-}
Ty% : Set; Ty%
= (Ty : Set)
(ι : Ty)
(arr : Ty → Ty → Ty)
→ Ty
ι% : Ty%; ι% = λ _ ι% _ → ι%
arr% : Ty% → Ty% → Ty%; arr% = λ A B Ty% ι% arr% → arr% (A Ty% ι% arr%) (B Ty% ι% arr%)
Con% : Set;Con%
= (Con% : Set)
(nil : Con%)
(snoc : Con% → Ty% → Con%)
→ Con%
nil% : Con%;nil%
= λ Con% nil% snoc → nil%
snoc% : Con% → Ty% → Con%;snoc%
= λ Γ A Con% nil% snoc% → snoc% (Γ Con% nil% snoc%) A
Var% : Con% → Ty% → Set;Var%
= λ Γ A →
(Var% : Con% → Ty% → Set)
(vz : (Γ : _)(A : _) → Var% (snoc% Γ A) A)
(vs : (Γ : _)(B A : _) → Var% Γ A → Var% (snoc% Γ B) A)
→ Var% Γ A
vz% : ∀{Γ A} → Var% (snoc% Γ A) A;vz%
= λ Var% vz% vs → vz% _ _
vs% : ∀{Γ B A} → Var% Γ A → Var% (snoc% Γ B) A;vs%
= λ x Var% vz% vs% → vs% _ _ _ (x Var% vz% vs%)
Tm% : Con% → Ty% → Set;Tm%
= λ Γ A →
(Tm% : Con% → Ty% → Set)
(var : (Γ : _) (A : _) → Var% Γ A → Tm% Γ A)
(lam : (Γ : _) (A B : _) → Tm% (snoc% Γ A) B → Tm% Γ (arr% A B))
(app : (Γ : _) (A B : _) → Tm% Γ (arr% A B) → Tm% Γ A → Tm% Γ B)
→ Tm% Γ A
var% : ∀{Γ A} → Var% Γ A → Tm% Γ A;var%
= λ x Tm% var% lam app → var% _ _ x
lam% : ∀{Γ A B} → Tm% (snoc% Γ A) B → Tm% Γ (arr% A B);lam%
= λ t Tm% var% lam% app → lam% _ _ _ (t Tm% var% lam% app)
app% : ∀{Γ A B} → Tm% Γ (arr% A B) → Tm% Γ A → Tm% Γ B;app%
= λ t u Tm% var% lam% app% →
app% _ _ _ (t Tm% var% lam% app%) (u Tm% var% lam% app%)
v0% : ∀{Γ A} → Tm% (snoc% Γ A) A;v0%
= var% vz%
v1% : ∀{Γ A B} → Tm% (snoc% (snoc% Γ A) B) A;v1%
= var% (vs% vz%)
v2% : ∀{Γ A B C} → Tm% (snoc% (snoc% (snoc% Γ A) B) C) A;v2%
= var% (vs% (vs% vz%))
v3% : ∀{Γ A B C D} → Tm% (snoc% (snoc% (snoc% (snoc% Γ A) B) C) D) A;v3%
= var% (vs% (vs% (vs% vz%)))
v4% : ∀{Γ A B C D E} → Tm% (snoc% (snoc% (snoc% (snoc% (snoc% Γ A) B) C) D) E) A;v4%
= var% (vs% (vs% (vs% (vs% vz%))))
test% : ∀{Γ A} → Tm% Γ (arr% (arr% A A) (arr% A A));test%
= lam% (lam% (app% v1% (app% v1% (app% v1% (app% v1% (app% v1% (app% v1% v0%)))))))
|
{
"alphanum_fraction": 0.4182908546,
"avg_line_length": 27.7916666667,
"ext": "agda",
"hexsha": "d1a25151390d3a00c19fa6f1864a3cb89837f60b",
"lang": "Agda",
"max_forks_count": 19,
"max_forks_repo_forks_event_max_datetime": "2022-03-03T19:46:54.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-05T21:11:34.000Z",
"max_forks_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "int-index/smalltt",
"max_forks_repo_path": "bench/stlc_small.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_issues_repo_issues_event_max_datetime": "2022-02-28T21:51:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-16T09:14:57.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "int-index/smalltt",
"max_issues_repo_path": "bench/stlc_small.agda",
"max_line_length": 87,
"max_stars_count": 377,
"max_stars_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "int-index/smalltt",
"max_stars_repo_path": "bench/stlc_small.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T21:31:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-26T16:57:16.000Z",
"num_tokens": 1056,
"size": 2001
}
|
open import FRP.JS.String using ( String ; _≟_ ; _<_ )
open import FRP.JS.Bool using ( Bool ; true ; false ; _∧_ )
open import FRP.JS.True using ( True )
open import FRP.JS.Maybe using ( Maybe ; just ; nothing )
module FRP.JS.Keys where
infixr 4 _∷_
data IKeys : Set where
[] : IKeys
_∷_ : (k : String) → (ks : IKeys) → IKeys
{-# COMPILED_JS IKeys function(x,v) {
if ((x.array.length) <= (x.offset)) { return v["[]"](); }
else { return v["_∷_"](x.key(),x.tail()); }
} #-}
{-# COMPILED_JS [] require("agda.keys").iempty #-}
{-# COMPILED_JS _∷_ function(k) { return function(ks) { return ks.cons(k); }; } #-}
head : IKeys → Maybe String
head [] = nothing
head (k ∷ ks) = just k
{-# COMPILED_JS head function(ks) { return require("agda.box").box(ks.key()); } #-}
_<?_ : String → Maybe String → Bool
k <? nothing = true
k <? just l = k < l
sorted : IKeys → Bool
sorted [] = true
sorted (k ∷ ks) = (k <? head ks) ∧ (sorted ks)
record Keys : Set where
constructor keys
field
ikeys : IKeys
{ikeys✓} : True (sorted ikeys)
open Keys public
{-# COMPILED_JS Keys function(x,v) { return v.keys(require("agda.keys").iarray(x),null); } #-}
{-# COMPILED_JS keys function(ks) { return function() { return ks.keys(); }; } #-}
{-# COMPILED_JS ikeys function(ks) { return require("agda.keys").iarray(ks); } #-}
{-# COMPILED_JS ikeys✓ function(ks) { return null; } #-}
_∈i_ : String → IKeys → Bool
l ∈i [] = false
l ∈i (k ∷ ks)
with k ≟ l
... | true = true
... | false
with k < l
... | true = l ∈i ks
... | false = false
_∈_ : String → Keys → Bool
l ∈ keys ks = l ∈i ks
|
{
"alphanum_fraction": 0.5927545284,
"avg_line_length": 26.6833333333,
"ext": "agda",
"hexsha": "2c93e1497465df6753c4aa09e5799f073eee2543",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "src/agda/FRP/JS/Keys.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "src/agda/FRP/JS/Keys.agda",
"max_line_length": 94,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/Keys.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 539,
"size": 1601
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Ring.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Reflection.StrictEquiv
open Iso
private
variable
ℓ ℓ' : Level
record IsRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor isring
field
+IsAbGroup : IsAbGroup 0r _+_ -_
·IsMonoid : IsMonoid 1r _·_
dist : (x y z : R) → (x · (y + z) ≡ (x · y) + (x · z))
× ((x + y) · z ≡ (x · z) + (y · z))
-- This is in the Agda stdlib, but it's redundant
-- zero : (x : R) → (x · 0r ≡ 0r) × (0r · x ≡ 0r)
open IsAbGroup +IsAbGroup public
renaming
( assoc to +Assoc
; identity to +Identity
; lid to +Lid
; rid to +Rid
; inverse to +Inv
; invl to +Linv
; invr to +Rinv
; comm to +Comm
; isSemigroup to +IsSemigroup
; isMonoid to +IsMonoid
; isGroup to +IsGroup )
open IsMonoid ·IsMonoid public
renaming
( assoc to ·Assoc
; identity to ·Identity
; lid to ·Lid
; rid to ·Rid
; isSemigroup to ·IsSemigroup )
hiding
( is-set ) -- We only want to export one proof of this
·Rdist+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)
·Rdist+ x y z = dist x y z .fst
·Ldist+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z)
·Ldist+ x y z = dist x y z .snd
record RingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor ringstr
field
0r : A
1r : A
_+_ : A → A → A
_·_ : A → A → A
-_ : A → A
isRing : IsRing 0r 1r _+_ _·_ -_
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsRing isRing public
Ring : Type (ℓ-suc ℓ)
Ring = TypeWithStr _ RingStr
isSetRing : (R : Ring {ℓ}) → isSet ⟨ R ⟩
isSetRing R = R .snd .RingStr.isRing .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
makeIsRing : {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R}
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(r+-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-lid : (x : R) → 1r · x ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-ldist-+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z))
→ IsRing 0r 1r _+_ _·_ -_
makeIsRing is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ =
isring (makeIsAbGroup is-setR assoc +-rid +-rinv +-comm)
(makeIsMonoid is-setR ·-assoc ·-rid ·-lid)
λ x y z → ·-rdist-+ x y z , ·-ldist-+ x y z
makeRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(+-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-lid : (x : R) → 1r · x ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-ldist-+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z))
→ Ring
makeRing 0r 1r _+_ _·_ -_ is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ =
_ , ringstr 0r 1r _+_ _·_ -_
(makeIsRing is-setR assoc +-rid +-rinv +-comm
·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ )
record RingEquiv (R : Ring {ℓ}) (S : Ring {ℓ'}) (e : ⟨ R ⟩ ≃ ⟨ S ⟩) : Type (ℓ-max ℓ ℓ') where
constructor ringequiv
private
module R = RingStr (snd R)
module S = RingStr (snd S)
field
pres1 : equivFun e R.1r ≡ S.1r
isHom+ : (x y : ⟨ R ⟩) → equivFun e (x R.+ y) ≡ equivFun e x S.+ equivFun e y
isHom· : (x y : ⟨ R ⟩) → equivFun e (x R.· y) ≡ equivFun e x S.· equivFun e y
record RingHom (R S : Ring {ℓ}) : Type ℓ where
constructor ringhom
private
module R = RingStr (snd R)
module S = RingStr (snd S)
field
f : ⟨ R ⟩ → ⟨ S ⟩
pres1 : f R.1r ≡ S.1r
isHom+ : (x y : ⟨ R ⟩) → f (x R.+ y) ≡ f x S.+ f y
isHom· : (x y : ⟨ R ⟩) → f (x R.· y) ≡ f x S.· f y
_$_ : {R S : Ring {ℓ}} → (φ : RingHom R S) → (x : ⟨ R ⟩) → ⟨ S ⟩
φ $ x = RingHom.f φ x
module RingΣTheory {ℓ} where
RawRingStructure = λ (X : Type ℓ) → (X → X → X) × X × (X → X → X)
RawRingEquivStr = AutoEquivStr RawRingStructure
rawRingUnivalentStr : UnivalentStr _ RawRingEquivStr
rawRingUnivalentStr = autoUnivalentStr RawRingStructure
RingAxioms : (R : Type ℓ) (s : RawRingStructure R) → Type ℓ
RingAxioms R (_+_ , 1r , _·_) =
AbGroupΣTheory.AbGroupAxioms R _+_
× IsMonoid 1r _·_
× ((x y z : R) → (x · (y + z) ≡ (x · y) + (x · z)) × ((x + y) · z ≡ (x · z) + (y · z)))
RingStructure : Type ℓ → Type ℓ
RingStructure = AxiomsStructure RawRingStructure RingAxioms
RingΣ : Type (ℓ-suc ℓ)
RingΣ = TypeWithStr ℓ RingStructure
RingEquivStr : StrEquiv RingStructure ℓ
RingEquivStr = AxiomsEquivStr RawRingEquivStr RingAxioms
isPropRingAxioms : (R : Type ℓ) (s : RawRingStructure R) → isProp (RingAxioms R s)
isPropRingAxioms R (_+_ , 1r , _·_) =
isProp× (AbGroupΣTheory.isPropAbGroupAxioms R _+_)
(isPropΣ (isPropIsMonoid 1r _·_)
λ R → isPropΠ3 λ _ _ _ →
isProp× (IsSemigroup.is-set (R .IsMonoid.isSemigroup) _ _)
(IsSemigroup.is-set (R .IsMonoid.isSemigroup) _ _))
Ring→RingΣ : Ring → RingΣ
Ring→RingΣ (R , ringstr 0r 1r _+_ _·_ -_ (isring +-isAbelianGroup ·-isMonoid dist)) =
( R
, (_+_ , 1r , _·_)
, AbGroupΣTheory.AbGroup→AbGroupΣ (_ , abgroupstr _ _ _ +-isAbelianGroup) .snd .snd
, ·-isMonoid , dist
)
RingΣ→Ring : RingΣ → Ring
RingΣ→Ring (_ , (y1 , y2 , y3) , z , w1 , w2) =
_ , ringstr _ y2 y1 y3 _
(isring (AbGroupΣTheory.AbGroupΣ→AbGroup (_ , _ , z ) .snd .AbGroupStr.isAbGroup)
w1 w2)
RingIsoRingΣ : Iso Ring RingΣ
RingIsoRingΣ = iso Ring→RingΣ RingΣ→Ring (λ _ → refl) (λ _ → refl)
ringUnivalentStr : UnivalentStr RingStructure RingEquivStr
ringUnivalentStr = axiomsUnivalentStr _ isPropRingAxioms rawRingUnivalentStr
RingΣPath : (R S : RingΣ) → (R ≃[ RingEquivStr ] S) ≃ (R ≡ S)
RingΣPath = SIP ringUnivalentStr
RingEquivΣ : (R S : Ring) → Type ℓ
RingEquivΣ R S = Ring→RingΣ R ≃[ RingEquivStr ] Ring→RingΣ S
RingIsoΣPath : {R S : Ring} → Iso (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e) (RingEquivΣ R S)
fun RingIsoΣPath (e , ringequiv h1 h2 h3) = e , h2 , h1 , h3
inv RingIsoΣPath (e , h1 , h2 , h3) = e , ringequiv h2 h1 h3
rightInv RingIsoΣPath _ = refl
leftInv RingIsoΣPath _ = refl
RingPath : (R S : Ring) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e) ≃ (R ≡ S)
RingPath R S =
Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e ≃⟨ strictIsoToEquiv RingIsoΣPath ⟩
RingEquivΣ R S ≃⟨ RingΣPath _ _ ⟩
Ring→RingΣ R ≡ Ring→RingΣ S ≃⟨ isoToEquiv (invIso (congIso RingIsoRingΣ)) ⟩
R ≡ S ■
RingPath : (R S : Ring {ℓ}) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] RingEquiv R S e) ≃ (R ≡ S)
RingPath = RingΣTheory.RingPath
isPropIsRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
→ isProp (IsRing 0r 1r _+_ _·_ -_)
isPropIsRing 0r 1r _+_ _·_ -_ (isring RG RM RD) (isring SG SM SD) =
λ i → isring (isPropIsAbGroup _ _ _ RG SG i)
(isPropIsMonoid _ _ RM SM i)
(isPropDistr RD SD i)
where
isSetR : isSet _
isSetR = RM .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropDistr : isProp ((x y z : _) → ((x · (y + z)) ≡ ((x · y) + (x · z)))
× (((x + y) · z) ≡ ((x · z) + (y · z))))
isPropDistr = isPropΠ3 λ _ _ _ → isProp× (isSetR _ _) (isSetR _ _)
-- Rings have an abelian group and a monoid
Ring→AbGroup : Ring {ℓ} → AbGroup {ℓ}
Ring→AbGroup (A , ringstr _ _ _ _ _ R) = A , abgroupstr _ _ _ (IsRing.+IsAbGroup R)
Ring→Monoid : Ring {ℓ} → Monoid {ℓ}
Ring→Monoid (A , ringstr _ _ _ _ _ R) = monoid _ _ _ (IsRing.·IsMonoid R)
|
{
"alphanum_fraction": 0.5290365895,
"avg_line_length": 34.5057915058,
"ext": "agda",
"hexsha": "651a833ccddde738c4b377cbc7a3b22892f46b58",
"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/Algebra/Ring/Base.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/Algebra/Ring/Base.agda",
"max_line_length": 101,
"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/Algebra/Ring/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3607,
"size": 8937
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Cocontinuous where
open import Level
open import Data.Product using (Σ)
open import Categories.Category
open import Categories.Functor
import Categories.Category.Construction.Cocones as Coc
import Categories.Diagram.Cocone.Properties as Cocₚ
import Categories.Diagram.Colimit as Col
import Categories.Morphism as Mor
private
variable
o ℓ e : Level
C D E J : Category o ℓ e
-- G preserves the colimit of F.
CoimitPreserving : (G : Functor C D) {F : Functor J C} (L : Col.Colimit F) → Set _
CoimitPreserving {C = C} {D = D} G {F} L = Σ (Col.Colimit (G ∘F F)) λ L′ → G.F₀ (Col.Colimit.coapex L) ≅ Col.Colimit.coapex L′
where module F = Functor F
module G = Functor G
open Mor D
-- cocontinuous functors preserves all colimits.
Cocontinuous : ∀ (o ℓ e : Level) (G : Functor C D) → Set _
Cocontinuous {C = C} o ℓ e G = ∀ {J : Category o ℓ e} {F : Functor J C} (L : Col.Colimit F) → CoimitPreserving G L
|
{
"alphanum_fraction": 0.693856999,
"avg_line_length": 33.1,
"ext": "agda",
"hexsha": "7c5d653faeae3a998374f1e8e3540fc1f6d2d9fd",
"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/Functor/Cocontinuous.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/Functor/Cocontinuous.agda",
"max_line_length": 126,
"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/Functor/Cocontinuous.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 303,
"size": 993
}
|
module Data.Num.Unary where
open import Data.Unit
open import Data.Empty
open import Data.List
open import Data.Nat renaming (_+_ to _⊹_)
data Digit : Set where
[1] : Digit
Unary : Set
Unary = List Digit
_⊕_ : Digit → Digit → Digit
[1] ⊕ [1] = [1]
_⊚_ : Digit → Digit → Digit
[1] ⊚ [1] = [1]
add : Digit → Unary → Unary
add [1] [] = [1] ∷ []
add [1] ([1] ∷ xs) = [1] ∷ add [1] xs
_+_ : Unary → Unary → Unary
[] + ys = ys
xs + [] = xs
(x ∷ xs) + (y ∷ ys) = x ⊕ y ∷ add (x ⊚ y) (xs + ys)
_≈_ : Unary → Unary → Set
[] ≈ [] = ⊤
[] ≈ (x ∷ ys) = ⊥
(x ∷ xs) ≈ [] = ⊥
(x ∷ xs) ≈ (y ∷ ys) = xs ≈ ys
fromℕ : ℕ → Unary
fromℕ zero = []
fromℕ (suc n) = fromℕ n
-- fromℕ zero = []
-- fromℕ (suc n) = [1] ∷ fromℕ n
toℕ : Unary → ℕ
toℕ [] = zero
toℕ (_ ∷ xs) = suc (toℕ xs)
|
{
"alphanum_fraction": 0.5038363171,
"avg_line_length": 17.3777777778,
"ext": "agda",
"hexsha": "37fbddef0e84d66997b4a3cb081aa7fd19b8dbf6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Sandbox/Unary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Sandbox/Unary.agda",
"max_line_length": 51,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Sandbox/Unary.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": 353,
"size": 782
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Vec.Relation.Binary.Pointwise.Inductive directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Relation.Pointwise.Inductive where
open import Data.Vec.Relation.Binary.Pointwise.Inductive public
{-# WARNING_ON_IMPORT
"Data.Vec.Relation.Pointwise.Inductive was deprecated in v1.0.
Use Data.Vec.Relation.Binary.Pointwise.Inductive instead."
#-}
|
{
"alphanum_fraction": 0.5785837651,
"avg_line_length": 32.1666666667,
"ext": "agda",
"hexsha": "73462b03187cbf1b42f6df6187412e515c05c67a",
"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/Relation/Pointwise/Inductive.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/Relation/Pointwise/Inductive.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Vec/Relation/Pointwise/Inductive.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": 113,
"size": 579
}
|
-- The previous error was:
-- Auto in hole `?0` raises a typing error:
-- (zero ∷ L) != L of type (List ℕ)
-- when checking that the expression x₁ has type (foo L)
open import Agda.Builtin.List
open import Agda.Builtin.Nat
data ⊥ : Set where
foo : List Nat → Set
foo [] = ⊥
foo (zero ∷ L) = foo L
foo (suc N ∷ L) = foo (suc N ∷ L)
bar : (L : List Nat) → (foo L) → List Nat
bar [] x = []
bar (zero ∷ L) x₁ = bar L {!!}
bar (suc x ∷ L) x₁ = {!!}
|
{
"alphanum_fraction": 0.56587473,
"avg_line_length": 22.0476190476,
"ext": "agda",
"hexsha": "30af5c5ed18cfae25a83698979351c8cbc2a80ed",
"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/interaction/Issue1169.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/interaction/Issue1169.agda",
"max_line_length": 58,
"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/interaction/Issue1169.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": 170,
"size": 463
}
|
{-# OPTIONS --rewriting #-}
open import Common.Nat
open import Common.Equality
postulate _↦_ : ∀ {a} {A : Set a} → A → A → Set
{-# BUILTIN REWRITE _↦_ #-}
postulate
P : ∀ {a} {A : Set a} → A → Set
postulate rew₁ : (f : Nat → Nat → Nat) → P (λ (x y z : Nat) → f z x) ↦ P f
{-# REWRITE rew₁ #-}
f : Nat → Nat → Nat → Nat
f x _ z = x + z
test : P f ≡ P (λ x z → z + x)
test = refl
postulate rew₂ : (f : Nat → Nat) → P (λ (x y : Nat) → f y) ↦ P f
{-# REWRITE rew₂ #-}
g : Nat → Nat → Nat
g x y = y
test₂ : P g ≡ P (λ (y : Nat) → y)
test₂ = refl
h : Nat → Nat → Nat → Nat
h x y z = x
test₃ : P h ≡ P (λ (z : Nat) → z)
test₃ = refl
|
{
"alphanum_fraction": 0.5031152648,
"avg_line_length": 16.8947368421,
"ext": "agda",
"hexsha": "fc88c5ef4210576d1478b47d5e8aa301a8f5b2f6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/HORewriting.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/HORewriting.agda",
"max_line_length": 74,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/HORewriting.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": 269,
"size": 642
}
|
module SizedIO.Console where
open import Level using () renaming (zero to lzero)
open import Size
open import NativeIO
open import SizedIO.Base
data ConsoleCommand : Set where
putStrLn : String → ConsoleCommand
getLine : ConsoleCommand
ConsoleResponse : ConsoleCommand → Set
ConsoleResponse (putStrLn s) = Unit
ConsoleResponse getLine = String
consoleI : IOInterface
Command consoleI = ConsoleCommand
Response consoleI = ConsoleResponse
IOConsole : Size → Set → Set
IOConsole i = IO consoleI i
IOConsole+ : Size → Set → Set
IOConsole+ i = IO+ consoleI i
translateIOConsoleLocal : (c : ConsoleCommand) → NativeIO (ConsoleResponse c)
translateIOConsoleLocal (putStrLn s) = nativePutStrLn s
translateIOConsoleLocal getLine = nativeGetLine
translateIOConsole : {A : Set} → IOConsole ∞ A → NativeIO A
translateIOConsole = translateIO translateIOConsoleLocal
main : NativeIO Unit
main = nativePutStrLn "Console"
|
{
"alphanum_fraction": 0.7754010695,
"avg_line_length": 25.2702702703,
"ext": "agda",
"hexsha": "6ab8afa1d3fbb2d91aa22ed47be898aed7710861",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "stephanadls/state-dependent-gui",
"max_forks_repo_path": "src/SizedIO/Console.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "stephanadls/state-dependent-gui",
"max_issues_repo_path": "src/SizedIO/Console.agda",
"max_line_length": 77,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "stephanadls/state-dependent-gui",
"max_stars_repo_path": "src/SizedIO/Console.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z",
"num_tokens": 236,
"size": 935
}
|
{-# OPTIONS --cubical-compatible #-}
module Common.Nat where
open import Agda.Builtin.Nat public
using ( Nat; zero; suc; _+_; _*_ )
renaming ( _-_ to _∸_ )
pred : Nat → Nat
pred zero = zero
pred (suc n) = n
|
{
"alphanum_fraction": 0.6244343891,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "4d04760abadabadf249cb8c67524c9d5fbfc5028",
"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/Common/Nat.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/Common/Nat.agda",
"max_line_length": 39,
"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/Common/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 72,
"size": 221
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of permutation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Permutation.Inductive.Properties where
open import Algebra
open import Algebra.FunctionProperties
open import Algebra.Structures
open import Data.List.Base as List
open import Data.List.Relation.Binary.Permutation.Inductive
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.List.Relation.Unary.All using (All; []; _∷_)
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties
open import Data.List.Relation.Binary.BagAndSetEquality
using (bag; _∼[_]_; empty-unique; drop-cons; commutativeMonoid)
import Data.List.Properties as Lₚ
open import Data.Product using (_,_; _×_; ∃; ∃₂)
open import Function using (_∘_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (inverse)
open import Relation.Unary using (Pred)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as ≡
using (_≡_ ; refl ; cong; cong₂; _≢_; inspect)
open PermutationReasoning
------------------------------------------------------------------------
-- sym
module _ {a} {A : Set a} where
↭-sym-involutive : ∀ {xs ys : List A} (p : xs ↭ ys) → ↭-sym (↭-sym p) ≡ p
↭-sym-involutive refl = refl
↭-sym-involutive (prep x ↭) = cong (prep x) (↭-sym-involutive ↭)
↭-sym-involutive (swap x y ↭) = cong (swap x y) (↭-sym-involutive ↭)
↭-sym-involutive (trans ↭₁ ↭₂) =
cong₂ trans (↭-sym-involutive ↭₁) (↭-sym-involutive ↭₂)
------------------------------------------------------------------------
-- Relationships to other predicates
module _ {a} {A : Set a} where
All-resp-↭ : ∀ {ℓ} {P : Pred A ℓ} → (All P) Respects _↭_
All-resp-↭ refl wit = wit
All-resp-↭ (prep x p) (px ∷ wit) = px ∷ All-resp-↭ p wit
All-resp-↭ (swap x y p) (px ∷ py ∷ wit) = py ∷ px ∷ All-resp-↭ p wit
All-resp-↭ (trans p₁ p₂) wit = All-resp-↭ p₂ (All-resp-↭ p₁ wit)
Any-resp-↭ : ∀ {ℓ} {P : Pred A ℓ} → (Any P) Respects _↭_
Any-resp-↭ refl wit = wit
Any-resp-↭ (prep x p) (here px) = here px
Any-resp-↭ (prep x p) (there wit) = there (Any-resp-↭ p wit)
Any-resp-↭ (swap x y p) (here px) = there (here px)
Any-resp-↭ (swap x y p) (there (here px)) = here px
Any-resp-↭ (swap x y p) (there (there wit)) = there (there (Any-resp-↭ p wit))
Any-resp-↭ (trans p p₁) wit = Any-resp-↭ p₁ (Any-resp-↭ p wit)
∈-resp-↭ : ∀ {x : A} → (x ∈_) Respects _↭_
∈-resp-↭ = Any-resp-↭
------------------------------------------------------------------------
-- map
module _ {a b} {A : Set a} {B : Set b} (f : A → B) where
map⁺ : ∀ {xs ys} → xs ↭ ys → map f xs ↭ map f ys
map⁺ refl = refl
map⁺ (prep x p) = prep _ (map⁺ p)
map⁺ (swap x y p) = swap _ _ (map⁺ p)
map⁺ (trans p₁ p₂) = trans (map⁺ p₁) (map⁺ p₂)
------------------------------------------------------------------------
-- _++_
module _ {a} {A : Set a} where
++⁺ˡ : ∀ xs {ys zs : List A} → ys ↭ zs → xs ++ ys ↭ xs ++ zs
++⁺ˡ [] ys↭zs = ys↭zs
++⁺ˡ (x ∷ xs) ys↭zs = prep x (++⁺ˡ xs ys↭zs)
++⁺ʳ : ∀ {xs ys : List A} zs → xs ↭ ys → xs ++ zs ↭ ys ++ zs
++⁺ʳ zs refl = refl
++⁺ʳ zs (prep x ↭) = prep x (++⁺ʳ zs ↭)
++⁺ʳ zs (swap x y ↭) = swap x y (++⁺ʳ zs ↭)
++⁺ʳ zs (trans ↭₁ ↭₂) = trans (++⁺ʳ zs ↭₁) (++⁺ʳ zs ↭₂)
++⁺ : _++_ Preserves₂ _↭_ ⟶ _↭_ ⟶ _↭_
++⁺ ws↭xs ys↭zs = trans (++⁺ʳ _ ws↭xs) (++⁺ˡ _ ys↭zs)
-- Some useful lemmas
zoom : ∀ h {t xs ys : List A} → xs ↭ ys → h ++ xs ++ t ↭ h ++ ys ++ t
zoom h {t} = ++⁺ˡ h ∘ ++⁺ʳ t
inject : ∀ (v : A) {ws xs ys zs} → ws ↭ ys → xs ↭ zs →
ws ++ [ v ] ++ xs ↭ ys ++ [ v ] ++ zs
inject v ws↭ys xs↭zs = trans (++⁺ˡ _ (prep v xs↭zs)) (++⁺ʳ _ ws↭ys)
shift : ∀ v (xs ys : List A) → xs ++ [ v ] ++ ys ↭ v ∷ xs ++ ys
shift v [] ys = refl
shift v (x ∷ xs) ys = begin
x ∷ (xs ++ [ v ] ++ ys) <⟨ shift v xs ys ⟩
x ∷ v ∷ xs ++ ys <<⟨ refl ⟩
v ∷ x ∷ xs ++ ys ∎
drop-mid-≡ : ∀ {x} ws xs {ys} {zs} →
ws ++ [ x ] ++ ys ≡ xs ++ [ x ] ++ zs →
ws ++ ys ↭ xs ++ zs
drop-mid-≡ [] [] eq with cong tail eq
drop-mid-≡ [] [] eq | refl = refl
drop-mid-≡ [] (x ∷ xs) refl = shift _ xs _
drop-mid-≡ (w ∷ ws) [] refl = ↭-sym (shift _ ws _)
drop-mid-≡ (w ∷ ws) (x ∷ xs) eq with Lₚ.∷-injective eq
... | refl , eq′ = prep w (drop-mid-≡ ws xs eq′)
drop-mid : ∀ {x} ws xs {ys zs} →
ws ++ [ x ] ++ ys ↭ xs ++ [ x ] ++ zs →
ws ++ ys ↭ xs ++ zs
drop-mid {x} ws xs p = drop-mid′ p ws xs refl refl
where
drop-mid′ : ∀ {l′ l″ : List A} → l′ ↭ l″ →
∀ ws xs {ys zs : List A} →
ws ++ [ x ] ++ ys ≡ l′ →
xs ++ [ x ] ++ zs ≡ l″ →
ws ++ ys ↭ xs ++ zs
drop-mid′ refl ws xs refl eq = drop-mid-≡ ws xs (≡.sym eq)
drop-mid′ (prep x p) [] [] refl eq with cong tail eq
drop-mid′ (prep x p) [] [] refl eq | refl = p
drop-mid′ (prep x p) [] (x ∷ xs) refl refl = trans p (shift _ _ _)
drop-mid′ (prep x p) (w ∷ ws) [] refl refl = trans (↭-sym (shift _ _ _)) p
drop-mid′ (prep x p) (w ∷ ws) (x ∷ xs) refl refl = prep _ (drop-mid′ p ws xs refl refl)
drop-mid′ (swap y z p) [] [] refl refl = prep _ p
drop-mid′ (swap y z p) [] (x ∷ []) refl eq with cong {B = List _}
(λ { (x ∷ _ ∷ xs) → x ∷ xs
; _ → []
})
eq
drop-mid′ (swap y z p) [] (x ∷ []) refl eq | refl = prep _ p
drop-mid′ (swap y z p) [] (x ∷ _ ∷ xs) refl refl = prep _ (trans p (shift _ _ _))
drop-mid′ (swap y z p) (w ∷ []) [] refl eq with cong tail eq
drop-mid′ (swap y z p) (w ∷ []) [] refl eq | refl = prep _ p
drop-mid′ (swap y z p) (w ∷ x ∷ ws) [] refl refl = prep _ (trans (↭-sym (shift _ _ _)) p)
drop-mid′ (swap y y p) (y ∷ []) (y ∷ []) refl refl = prep _ p
drop-mid′ (swap y z p) (y ∷ []) (z ∷ y ∷ xs) refl refl = begin
_ ∷ _ <⟨ p ⟩
_ ∷ (xs ++ _ ∷ _) <⟨ shift _ _ _ ⟩
_ ∷ _ ∷ xs ++ _ <<⟨ refl ⟩
_ ∷ _ ∷ xs ++ _ ∎
drop-mid′ (swap y z p) (y ∷ z ∷ ws) (z ∷ []) refl refl = begin
_ ∷ _ ∷ ws ++ _ <<⟨ refl ⟩
_ ∷ (_ ∷ ws ++ _) <⟨ ↭-sym (shift _ _ _) ⟩
_ ∷ (ws ++ _ ∷ _) <⟨ p ⟩
_ ∷ _ ∎
drop-mid′ (swap y z p) (y ∷ z ∷ ws) (z ∷ y ∷ xs) refl refl = swap y z (drop-mid′ p _ _ refl refl)
drop-mid′ (trans p₁ p₂) ws xs refl refl with ∈-∃++ (∈-resp-↭ p₁ (∈-insert ws))
... | (h , t , refl) = trans (drop-mid′ p₁ ws h refl refl) (drop-mid′ p₂ h xs refl refl)
-- Algebraic properties
++-identityˡ : LeftIdentity {A = List A} _↭_ [] _++_
++-identityˡ xs = refl
++-identityʳ : RightIdentity {A = List A} _↭_ [] _++_
++-identityʳ xs = ↭-reflexive (Lₚ.++-identityʳ xs)
++-identity : Identity {A = List A} _↭_ [] _++_
++-identity = ++-identityˡ , ++-identityʳ
++-assoc : Associative {A = List A} _↭_ _++_
++-assoc xs ys zs = ↭-reflexive (Lₚ.++-assoc xs ys zs)
++-comm : Commutative _↭_ _++_
++-comm [] ys = ↭-sym (++-identityʳ ys)
++-comm (x ∷ xs) ys = begin
x ∷ xs ++ ys ↭⟨ prep x (++-comm xs ys) ⟩
x ∷ ys ++ xs ≡⟨ cong (λ v → x ∷ v ++ xs) (≡.sym (Lₚ.++-identityʳ _)) ⟩
(x ∷ ys ++ []) ++ xs ↭⟨ ++⁺ʳ xs (↭-sym (shift x ys [])) ⟩
(ys ++ [ x ]) ++ xs ↭⟨ ++-assoc ys [ x ] xs ⟩
ys ++ ([ x ] ++ xs) ≡⟨⟩
ys ++ (x ∷ xs) ∎
++-isMagma : IsMagma _↭_ _++_
++-isMagma = record
{ isEquivalence = ↭-isEquivalence
; ∙-cong = ++⁺
}
++-magma : Magma _ _
++-magma = record
{ isMagma = ++-isMagma
}
++-isSemigroup : IsSemigroup _↭_ _++_
++-isSemigroup = record
{ isMagma = ++-isMagma
; assoc = ++-assoc
}
++-semigroup : Semigroup a _
++-semigroup = record
{ isSemigroup = ++-isSemigroup
}
++-isMonoid : IsMonoid _↭_ _++_ []
++-isMonoid = record
{ isSemigroup = ++-isSemigroup
; identity = ++-identity
}
++-monoid : Monoid a _
++-monoid = record
{ isMonoid = ++-isMonoid
}
++-isCommutativeMonoid : IsCommutativeMonoid _↭_ _++_ []
++-isCommutativeMonoid = record
{ isSemigroup = ++-isSemigroup
; identityˡ = ++-identityˡ
; comm = ++-comm
}
++-commutativeMonoid : CommutativeMonoid _ _
++-commutativeMonoid = record
{ isCommutativeMonoid = ++-isCommutativeMonoid
}
------------------------------------------------------------------------
-- _∷_
module _ {a} {A : Set a} where
drop-∷ : ∀ {x : A} {xs ys} → x ∷ xs ↭ x ∷ ys → xs ↭ ys
drop-∷ = drop-mid [] []
------------------------------------------------------------------------
-- _∷ʳ_
module _ {a} {A : Set a} where
∷↭∷ʳ : ∀ (x : A) xs → x ∷ xs ↭ xs ∷ʳ x
∷↭∷ʳ x xs = ↭-sym (begin
xs ++ [ x ] ↭⟨ shift x xs [] ⟩
x ∷ xs ++ [] ≡⟨ Lₚ.++-identityʳ _ ⟩
x ∷ xs ∎)
------------------------------------------------------------------------
-- Relationships to other relations
module _ {a} {A : Set a} where
↭⇒∼bag : _↭_ ⇒ _∼[ bag ]_
↭⇒∼bag xs↭ys {v} = inverse (to xs↭ys) (from xs↭ys) (from∘to xs↭ys) (to∘from xs↭ys)
where
to : ∀ {xs ys} → xs ↭ ys → v ∈ xs → v ∈ ys
to xs↭ys = Any-resp-↭ {A = A} xs↭ys
from : ∀ {xs ys} → xs ↭ ys → v ∈ ys → v ∈ xs
from xs↭ys = Any-resp-↭ (↭-sym xs↭ys)
from∘to : ∀ {xs ys} (p : xs ↭ ys) (q : v ∈ xs) → from p (to p q) ≡ q
from∘to refl v∈xs = refl
from∘to (prep _ _) (here refl) = refl
from∘to (prep _ p) (there v∈xs) = cong there (from∘to p v∈xs)
from∘to (swap x y p) (here refl) = refl
from∘to (swap x y p) (there (here refl)) = refl
from∘to (swap x y p) (there (there v∈xs)) = cong (there ∘ there) (from∘to p v∈xs)
from∘to (trans p₁ p₂) v∈xs
rewrite from∘to p₂ (Any-resp-↭ p₁ v∈xs)
| from∘to p₁ v∈xs = refl
to∘from : ∀ {xs ys} (p : xs ↭ ys) (q : v ∈ ys) → to p (from p q) ≡ q
to∘from p with from∘to (↭-sym p)
... | res rewrite ↭-sym-involutive p = res
∼bag⇒↭ : _∼[ bag ]_ ⇒ _↭_
∼bag⇒↭ {[]} eq with empty-unique (Inv.sym eq)
... | refl = refl
∼bag⇒↭ {x ∷ xs} eq with ∈-∃++ (to ⟨$⟩ (here ≡.refl))
where open Inv.Inverse (eq {x})
... | zs₁ , zs₂ , p rewrite p = begin
x ∷ xs <⟨ ∼bag⇒↭ (drop-cons (Inv._∘_ (comm zs₁ (x ∷ zs₂)) eq)) ⟩
x ∷ (zs₂ ++ zs₁) <⟨ ++-comm zs₂ zs₁ ⟩
x ∷ (zs₁ ++ zs₂) ↭˘⟨ shift x zs₁ zs₂ ⟩
zs₁ ++ x ∷ zs₂ ∎
where open CommutativeMonoid (commutativeMonoid bag A)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.0
↭⇒~bag = ↭⇒∼bag
{-# WARNING_ON_USAGE ↭⇒~bag
"Warning: ↭⇒~bag was deprecated in v1.0.
Please use ? instead (now typed with '\\sim' rather than '~')."
#-}
~bag⇒↭ = ∼bag⇒↭
{-# WARNING_ON_USAGE ~bag⇒↭
"Warning: ~bag⇒↭ was deprecated in v1.0.
Please use ? instead (now typed with '\\sim' rather than '~')."
#-}
|
{
"alphanum_fraction": 0.4472184987,
"avg_line_length": 37.7721518987,
"ext": "agda",
"hexsha": "dc4f04380ddfb2a22d25764982637c3b5b600970",
"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/Binary/Permutation/Inductive/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/Binary/Permutation/Inductive/Properties.agda",
"max_line_length": 103,
"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/Binary/Permutation/Inductive/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4514,
"size": 11936
}
|
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Sigma
open import lib.types.Pi
open import lib.types.Paths
open import Graphs.Definition
open import Coequalizers.Definition
open import Util.Misc
module Coequalizers.PullbackStability where
module PullbackStability {i k j : ULevel} (E : Type i) (V : Type k) ⦃ gph : Graph E V ⦄
(X : (V / E) → Type j) where
VX = Σ V (X ∘ c[_])
EX = Σ E (X ∘ c[_] ∘ π₀)
instance
gph-pb : Graph EX VX
gph-pb = record { π₀ = λ {(e , x) → ((π₀ e) , x)} ; π₁ = λ {(e , x) → ((π₁ e) , (transport X (quot e) x))} }
pb-equiv : (VX / EX) ≃ Σ (V / E) X
pb-equiv = equiv f g (λ {(e , x) → f-g' e x}) g-f
where
f-point : VX → Σ (V / E) X
f-point (v , x) = (c[ v ] , x)
f : (VX / EX) → Σ (V / E) X
f = Coeq-rec f-point
λ {(e , x) → pair= (quot e) (transp-↓' X (quot e) x)}
g'-path : (e : E) → (λ x → c[ (π₀ e , x) ]) == (λ x → c[ (π₁ e , x) ]) [ (λ z → X z → VX / EX) ↓ (quot e) ]
g'-path e = ↓-app→cst-in (λ {t} {t'} q → quot (e , t) ∙ ap c[_] (pair= idp (to-transp q)))
g'-point : (v : V) → (X c[ v ]) → (VX / EX)
g'-point v x = c[ v , x ]
g' : (z : V / E) → (X z) → (VX / EX)
g' = Coeq-elim (λ z → (X z) → (VX / EX))
g'-point g'-path
g : Σ (V / E) X → (VX / EX)
g (z , x) = g' z x
g-f : (z : VX / EX) → (g (f z) == z)
g-f = Coeq-elim _ (λ _ → idp) λ {(e , x) → ↓-app=idf-in (lemma e x)}
where
lemma1 : {z z' : V / E} (p : z == z') (x : X z) → ap g (pair= p (transp-↓' X p x)) == ↓-app→cst-out (apd g' p) (transp-↓' X p x)
lemma1 idp x = idp
lemma2 : {z z' : V / E} (p : z == z') (x : X z) → (to-transp ((transp-↓' X p x))) == idp
lemma2 idp x = idp
lemma : (e : E) → (x : X c[ π₀ e ]) → idp ∙' quot (e , x) == ap (g ∘ f) (quot (e , x)) ∙ idp
lemma e x = ! $
ap (g ∘ f) (quot (e , x)) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (g ∘ f) (quot (e , x))
=⟨ ap-∘ g f (quot (e , x)) ⟩
ap g (ap f (quot (e , x)))
=⟨ ap (ap g) (Coeq-rec-β= _ _ _) ⟩
ap g (pair= (quot e) (transp-↓' X (quot e) x))
=⟨ lemma1 (quot e) x ⟩
↓-app→cst-out (apd g' (quot e)) (transp-↓' X (quot e) x)
=⟨ ap (λ w → ↓-app→cst-out w (transp-↓' X (quot e) x) ) (Coeq-β= _ _ _ _) ⟩
↓-app→cst-out (↓-app→cst-in λ q → quot (e , _) ∙ ap c[_] (pair= idp (to-transp q))) (transp-↓' X (quot e) x)
=⟨ ↓-app→cst-β ((λ q → quot (e , _) ∙ ap c[_] (pair= idp (to-transp q)))) ((transp-↓' X (quot e) x)) ⟩
(λ q → quot (e , _) ∙ ap c[_] (pair= idp (to-transp q))) (transp-↓' X (quot e) x)
=⟨ idp ⟩
quot (e , _) ∙ ap c[_] (pair= idp (to-transp ((transp-↓' X (quot e) x))))
=⟨ quot (e , x) ∙ₗ ap (ap c[_]) (pair== idp (lemma2 (quot e) x)) ⟩
quot (e , x) ∙ idp
=⟨ ∙-unit-r _ ⟩
quot (e , x)
=⟨ ! (∙'-unit-l _) ⟩
idp ∙' quot (e , x)
=∎
f-g' : (z : V / E) → (x : X z) → f (g' z x) == (z , x)
f-g' = Coeq-elim (λ z → (x : X z) → f (g' z x) == (z , x) )
(λ v x → idp) λ e → lemma1 (quot e) (λ _ → idp) (λ _ → idp) (λ x → (lemma2 (e , x)))
where
fg : (z : V / E) → (x : X z) → Σ (V / E) X
fg z x = f (g' z x)
lemma1 : {z z' : V / E} (p : z == z') (α : (x : X z) → f (g' z x) == (z , x))
(β : (x' : X z') → f (g' z' x') == (z' , x')) →
((x : X z) → ((α x) ∙ Σ-transp X p x) == (↓-app→cst-out (apd fg p) (transp-↓' _ p x) ∙ (β (transport X p x)))) →
α == β [ (λ z'' → (x : X z'') → f (g' z'' x) == (z'' , x)) ↓ p ]
lemma1 idp α β q = λ= (λ x → ! (∙-unit-r _) ∙ q x)
expandapd : {z z' : V / E} (p : z == z') {x : X z} {x' : X z'} (q : x == x' [ X ↓ p ]) → ↓-app→cst-out (apd fg p) q == ap f (↓-app→cst-out (apd g' p) q)
expandapd idp idp = idp
lemma2 : (ex : EX) →
(idp ∙ Σ-transp X (quot (fst ex)) (snd ex)) == (↓-app→cst-out (apd fg (quot (fst ex))) (transp-↓' _ (quot (fst ex)) (snd ex)) ∙ idp)
lemma2 ex@(e , x) = ! $
↓-app→cst-out (apd fg (quot e)) (transp-↓' _ (quot e) x) ∙ idp
=⟨ ∙-unit-r _ ⟩
↓-app→cst-out (apd fg (quot e)) (transp-↓' _ (quot e) x)
=⟨ expandapd (quot e) ((transp-↓' _ (quot e) x)) ⟩
ap f (↓-app→cst-out (apd g' (quot e)) ((transp-↓' _ (quot e) x)))
=⟨ ap (λ w → ap f (↓-app→cst-out w (((transp-↓' _ (quot e) x))))) (Coeq-β= ((λ z → (X z) → (VX / EX))) (λ v x → c[ v , x ]) g'-path e) ⟩
ap f (↓-app→cst-out (g'-path e) (transp-↓' _ (quot e) x))
=⟨ ap (ap f) (↓-app→cst-β ((λ {t} {t'} q → quot (e , t) ∙ ap c[_] (pair= idp (to-transp q)))) ((transp-↓' _ (quot e) x))) ⟩
ap f (quot ex ∙ ap c[_] (pair= idp (to-transp (transp-↓' X (quot e) x))))
=⟨ ap-∙ f (quot ex) (ap c[_] (pair= idp (to-transp (transp-↓' X (quot e) x)))) ⟩
ap f (quot ex) ∙ ap f (ap c[_] (pair= idp (to-transp (transp-↓' X (quot e) x))))
=⟨ ap f (quot ex) ∙ₗ ∘-ap f c[_] _ ⟩
ap f (quot ex) ∙ ap (f ∘ c[_]) (pair= idp (to-transp (transp-↓' X (quot e) x)))
=⟨ idp ⟩
ap f (quot ex) ∙ ap f-point (pair= idp (to-transp (transp-↓' X (quot e) x)))
=⟨ Coeq-rec-β= _ _ _ ∙ᵣ ap f-point (pair= idp (to-transp (transp-↓' X (quot e) x))) ⟩
pair= (quot e) (transp-↓' X (quot e) x) ∙ ap f-point (pair= idp (to-transp (transp-↓' X (quot e) x)))
=⟨ ap (λ w → pair= (quot e) (transp-↓' X (quot e) x) ∙ ap f-point (pair= idp w)) (lemma2a (quot e) x) ⟩
pair= (quot e) (transp-↓' X (quot e) x) ∙ ap f-point (pair= idp idp)
=⟨ ∙-unit-r _ ⟩
pair= (quot e) (transp-↓' X (quot e) x)
=⟨ idp ⟩
Σ-transp X (quot e) x
=⟨ idp ⟩
idp ∙ Σ-transp X (quot e) x
=∎
where
lemma2a : {z z' : V / E} (p : z == z') (x : X z) → (to-transp (transp-↓' X p x)) == idp
lemma2a idp x = idp
|
{
"alphanum_fraction": 0.3902888752,
"avg_line_length": 48.2074074074,
"ext": "agda",
"hexsha": "3ede676194899a299dbde6b35af9cf0127a987a5",
"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": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Coequalizers/PullbackStability.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"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": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Coequalizers/PullbackStability.agda",
"max_line_length": 165,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Coequalizers/PullbackStability.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2723,
"size": 6508
}
|
module WrongHidingInLambda where
f : (A : Set) -> A -> A
f = \{A} x -> x
|
{
"alphanum_fraction": 0.5394736842,
"avg_line_length": 10.8571428571,
"ext": "agda",
"hexsha": "36e195039e5ddf8356fe48e74448ea374cdd030f",
"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/WrongHidingInLambda.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/WrongHidingInLambda.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/WrongHidingInLambda.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": 31,
"size": 76
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Universe levels
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Level where
-- Levels.
open import Agda.Primitive as Prim public
using (Level; _⊔_; Setω)
renaming (lzero to zero; lsuc to suc)
-- Lifting.
record Lift {a} ℓ (A : Set a) : Set (a ⊔ ℓ) where
constructor lift
field lower : A
open Lift public
-- Synonyms
0ℓ : Level
0ℓ = zero
levelOfType : ∀ {a} → Set a → Level
levelOfType {a} _ = a
levelOfTerm : ∀ {a} {A : Set a} → A → Level
levelOfTerm {a} _ = a
|
{
"alphanum_fraction": 0.490881459,
"avg_line_length": 18.8,
"ext": "agda",
"hexsha": "2aefd377862bfc939dfa4b0433e3c412c879e1ba",
"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/Level.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/Level.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Level.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": 177,
"size": 658
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Construction.Properties.Presheaves.Complete {o ℓ e} (C : Category o ℓ e) where
open import Categories.Category.Complete
open import Categories.Category.Complete.Finitely
open import Categories.Category.Complete.Properties
open import Categories.Category.Cocomplete
open import Categories.Category.Cocomplete.Finitely
open import Categories.Category.Cocomplete.Properties
open import Categories.Category.Construction.Presheaves
open import Categories.Category.Instance.Setoids
open import Categories.Category.Instance.Properties.Setoids
private
module C = Category C
Presheaves-Complete : ∀ o′ ℓ′ e′ ℓ″ e″ → Complete o′ ℓ′ e′ (Presheaves C)
Presheaves-Complete o′ ℓ′ e′ ℓ″ e″ = Functors-Complete C.op (Setoids-Complete o′ ℓ′ e′ ℓ″ e″)
Presheaves-FinitelyComplete : ∀ o′ ℓ′ e′ ℓ″ e″ → FinitelyComplete (Presheaves C)
Presheaves-FinitelyComplete o′ ℓ′ e′ ℓ″ e″ = Complete⇒FinitelyComplete (Presheaves C) (Presheaves-Complete o′ ℓ′ e′ ℓ″ e″)
Presheaves-Cocomplete : ∀ o′ ℓ′ e′ ℓ″ e″ → Cocomplete o′ ℓ′ e′ (Presheaves C)
Presheaves-Cocomplete o′ ℓ′ e′ ℓ″ e″ = Functors-Cocomplete C.op (Setoids-Cocomplete o′ ℓ′ e′ ℓ″ e″)
Presheaves-FinitelyCocomplete : ∀ o′ ℓ′ e′ ℓ″ e″ → FinitelyCocomplete (Presheaves C)
Presheaves-FinitelyCocomplete o′ ℓ′ e′ ℓ″ e″ = Cocomplete⇒FinitelyCocomplete (Presheaves C) (Presheaves-Cocomplete o′ ℓ′ e′ ℓ″ e″)
|
{
"alphanum_fraction": 0.7576601671,
"avg_line_length": 46.3225806452,
"ext": "agda",
"hexsha": "2df22bdf875a30698629402308460338484a78da",
"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/Category/Construction/Properties/Presheaves/Complete.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/Category/Construction/Properties/Presheaves/Complete.agda",
"max_line_length": 130,
"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/Category/Construction/Properties/Presheaves/Complete.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": 443,
"size": 1436
}
|
------------------------------------------------------------------------
-- The parser type
------------------------------------------------------------------------
module TotalParserCombinators.Parser where
open import Algebra
open import Category.Monad
open import Codata.Musical.Notation
open import Data.List
open import Data.Maybe using (Maybe; nothing; just)
open import Data.List.Categorical as ListMonad
using () renaming (module MonadProperties to ListMonadProp)
open import Data.List.Relation.Binary.BagAndSetEquality
open import Data.Product using (proj₂)
open import Function
open import Level
open import Relation.Binary.PropositionalEquality
open RawMonadPlus {f = zero} ListMonad.monadPlus
using ()
renaming ( return to return′
; ∅ to fail′
; _∣_ to _∣′_
; _⊛_ to _⊛′_
; _>>=_ to _>>=′_
)
------------------------------------------------------------------------
-- Helper functions
-- Flattening for potential lists.
flatten : {A : Set} → Maybe (List A) → List A
flatten nothing = []
flatten (just xs) = xs
-- fs ⊛flatten mxs is a variant of fs ⊛′ flatten mxs, with the
-- property that fs ⊛flatten nothing evaluates to [].
_⊛flatten_ : {A B : Set} → List (A → B) → Maybe (List A) → List B
fs ⊛flatten nothing = []
fs ⊛flatten just xs = fs ⊛′ xs
-- Applies the function to the value, returning the empty list if
-- there is no function.
apply : {A B : Set} → Maybe (A → List B) → A → List B
apply nothing x = []
apply (just f) x = f x
-- bind mxs mf is a variant of flatten mxs >>=′ apply mf, with the
-- property that bind mxs nothing evaluates to [].
bind : {A B : Set} → Maybe (List A) → Maybe (A → List B) → List B
bind mxs nothing = []
bind mxs (just f) = flatten mxs >>=′ f
-- Verification of some claims made above.
module Claims where
⊛flatten-⊛-flatten : ∀ {A B : Set} (fs : List (A → B)) mxs →
fs ⊛flatten mxs ≡ (fs ⊛′ flatten mxs)
⊛flatten-⊛-flatten fs nothing = sym $ ListMonadProp.right-zero fs
⊛flatten-⊛-flatten fs (just xs) = refl
⊛flatten-nothing : {A B : Set} (fs : List (A → B)) →
fs ⊛flatten nothing ≡ []
⊛flatten-nothing fs = refl
bind-flatten->>=-apply : ∀ {A B : Set} mxs (mf : Maybe (A → List B)) →
bind mxs mf ≡ (flatten mxs >>=′ apply mf)
bind-flatten->>=-apply mxs (just f) = refl
bind-flatten->>=-apply mxs nothing =
sym $ ListMonadProp.right-zero (flatten mxs)
bind-nothing : {A B : Set} (mxs : Maybe (List A)) →
bind mxs nothing ≡ [] {A = B}
bind-nothing mxs = refl
------------------------------------------------------------------------
-- Parsers
infixl 50 _⊛_ _<$>_ _⊛flatten_
infixl 10 _>>=_
infixl 5 _∣_
-- The list index is the "initial bag"; it contains the results which
-- can be emitted without consuming any input. For
-- p : Parser Tok R xs
-- we have
-- x ∈ xs iff x ∈ p · []
-- (see TotalParserCombinators.InitialBag).
mutual
data Parser (Tok : Set) : (R : Set) → List R → Set₁ where
return : ∀ {R} (x : R) → Parser Tok R (return′ x)
fail : ∀ {R} → Parser Tok R fail′
token : Parser Tok Tok fail′
_∣_ : ∀ {R xs₁ xs₂}
(p₁ : Parser Tok R xs₁ )
(p₂ : Parser Tok R xs₂) →
Parser Tok R (xs₁ ∣′ xs₂)
_<$>_ : ∀ {R₁ R₂ xs}
(f : R₁ → R₂)
(p : Parser Tok R₁ xs) →
Parser Tok R₂ (map f xs)
_⊛_ : ∀ {R₁ R₂ fs xs}
(p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs) )
(p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)) →
Parser Tok R₂ (flatten fs ⊛flatten xs)
_>>=_ : ∀ {R₁ R₂ xs} {f : Maybe (R₁ → List R₂)}
(p₁ : ∞⟨ f ⟩Parser Tok R₁ (flatten xs))
(p₂ : (x : R₁) → ∞⟨ xs ⟩Parser Tok R₂ (apply f x)) →
Parser Tok R₂ (bind xs f)
nonempty : ∀ {R xs} (p : Parser Tok R xs) → Parser Tok R []
cast : ∀ {R xs₁ xs₂} (xs₁≈xs₂ : xs₁ ∼[ bag ] xs₂)
(p : Parser Tok R xs₁) → Parser Tok R xs₂
∞⟨_⟩Parser : {A : Set} → Maybe A → Set → (R : Set) → List R → Set₁
∞⟨ nothing ⟩Parser Tok R₁ xs = ∞ (Parser Tok R₁ xs)
∞⟨ just _ ⟩Parser Tok R₁ xs = Parser Tok R₁ xs
-- Note that, with the definition above, a sequenced parser is
-- /allowed/ to be delayed if the "other" parser is not nullable, but
-- it does not have to be.
-- Note also that it would be safe to make the first argument of _>>=_
-- coinductive if apply f x ≡_[] for all x in xs. I suspect that this
-- criterion would be awkward to work with, though. Instead I only
-- allow the argument to be coinductive if f ≡ nothing.
-- Finally note that some of the combinators above are not included in
-- the paper "Total Parser Combinators".
------------------------------------------------------------------------
-- Examples
private
-- Note that these parsers can be both left and right recursive:
leftRight : ∀ {R Tok} → Parser Tok R _
leftRight {R} = ♯ (const <$> leftRight) ⊛ ♯ leftRight {R}
leftRight′ : ∀ {R Tok} → Parser Tok R _
leftRight′ {R} = ♯ leftRight′ {R} >>= λ _ → ♯ leftRight′
-- More examples, included to ensure that all implicit arguments are
-- inferred automatically.
p : {Tok R : Set} → Parser Tok R _
p = token >>= λ _ → ♯ p
p′ : {Tok : Set} → Parser Tok Tok _
p′ = ♯ p′ >>= λ _ → token
------------------------------------------------------------------------
-- Helper functions
-- Returns the initial bag.
initial-bag : ∀ {Tok R xs} → Parser Tok R xs → List R
initial-bag {xs = xs} _ = xs
-- Forces if necessary.
♭? : ∀ {Tok R₁ R₂} {m : Maybe R₂} {xs} →
∞⟨ m ⟩Parser Tok R₁ xs → Parser Tok R₁ xs
♭? {m = nothing} = ♭
♭? {m = just _} = id
-- Is the argument parser forced? If the result is just something,
-- then it is.
forced? : ∀ {Tok A R xs} {m : Maybe A} →
∞⟨ m ⟩Parser Tok R xs → Maybe A
forced? {m = m} _ = m
forced?′ : {Tok R₁ R₂ A : Set} {m : Maybe A} {f : R₁ → List R₂} →
((x : R₁) → ∞⟨ m ⟩Parser Tok R₂ (f x)) → Maybe A
forced?′ {m = m} _ = m
-- Short synonyms for just and nothing. ◌ stands for "delayed" (think
-- "not here") and ○ for "not delayed".
◌ : {R : Set} → Maybe R
◌ = nothing
○ : {R : Set} {x : R} → Maybe R
○ {x = x} = just x
|
{
"alphanum_fraction": 0.5308565211,
"avg_line_length": 33.1597938144,
"ext": "agda",
"hexsha": "a9a9046fbce8a0f3932daa79fb287b7b9a4ab347",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Parser.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"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/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Parser.agda",
"max_line_length": 76,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Parser.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 2002,
"size": 6433
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.