Search is not available for this dataset
text
string | meta
dict |
---|---|
{-
The naive, but incorrect, way to define the integers as a HIT.
This file mainly contains a proof that IsoInt ≢ Int, and ends with a
demonstration of how the same proof strategy fails for BiInvInt.
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.IsoInt.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Int
open import Cubical.Data.Nat
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
data IsoInt : Type₀ where
zero : IsoInt
suc : IsoInt -> IsoInt
-- suc is an isomorphism:
pred : IsoInt -> IsoInt
suc-pred : ∀ z -> suc (pred z) ≡ z
pred-suc : ∀ z -> pred (suc z) ≡ z
suc-iso : Iso IsoInt IsoInt
suc-iso = record { fun = suc ; inv = pred ; rightInv = suc-pred ; leftInv = pred-suc }
-- this submodule is adapted from Section 5 of
-- http://www.cs.ru.nl/~herman/PUBS/HIT-programming.pdf
module NonTrivial where
-- these two paths are distinct!
p₁ p₂ : Path IsoInt (suc (pred (suc zero))) (suc zero)
p₁ i = suc-pred (suc zero) i
p₂ i = suc (pred-suc zero i)
-- to prove this we map into S¹, sending p₁ to refl and p₂ to loop
open import Cubical.HITs.S1
toS¹ : IsoInt → S¹
toS¹ zero = base
toS¹ (suc x) = toS¹ x
toS¹ (pred x) = toS¹ x
toS¹ (suc-pred x i) = refl {x = toS¹ x} i
toS¹ (pred-suc x i) = rotLoop (toS¹ x) i
p₁≡refl : cong toS¹ p₁ ≡ refl
p₁≡refl = refl
p₂≡loop : cong toS¹ p₂ ≡ loop
p₂≡loop = refl
-- this is enough to show that p₁ and p₂ cannot be equal
p₁≢p₂ : ¬ (p₁ ≡ p₂)
p₁≢p₂ eq = znots 0≡1
where -- using winding numbers, p₁ ≡ p₂ implies 0 ≡ 1
0≡1 : 0 ≡ 1
0≡1 = injPos (cong (winding ∘ cong toS¹) eq)
¬isSet-IsoInt : ¬ (isSet IsoInt)
¬isSet-IsoInt pf = NonTrivial.p₁≢p₂ (pf _ _ NonTrivial.p₁ NonTrivial.p₂)
¬Int≡IsoInt : ¬ (Int ≡ IsoInt)
¬Int≡IsoInt p = ¬isSet-IsoInt (subst isSet p isSetInt)
private
-- Note: this same proof strategy fails for BiInvInt!
open import Cubical.HITs.Ints.BiInvInt hiding (zero; suc; pred; suc-pred; pred-suc)
import Cubical.HITs.Ints.BiInvInt as BiI
p₁ p₂ : Path BiInvInt (BiI.suc (BiI.pred (BiI.suc BiI.zero))) (BiI.suc BiI.zero)
p₁ i = BiI.suc-pred (BiI.suc BiI.zero) i
p₂ i = BiI.suc (BiI.pred-suc BiI.zero i)
open import Cubical.HITs.S1
toS¹ : BiInvInt → S¹
toS¹ BiI.zero = base
toS¹ (BiI.suc x) = toS¹ x
toS¹ (BiI.predr x) = toS¹ x
toS¹ (BiI.predl x) = toS¹ x
toS¹ (BiI.suc-predr x i) = refl {x = toS¹ x} i
toS¹ (BiI.predl-suc x i) = rotLoop (toS¹ x) i
-- still p₂ maps to loop...
p₂≡loop : cong toS¹ p₂ ≡ loop
p₂≡loop = refl
open import Cubical.Foundations.GroupoidLaws
-- ...but now so does p₁!
p₁≡loop : cong toS¹ p₁ ≡ loop
p₁≡loop = sym (decodeEncode base (cong toS¹ p₁)) ∙ sym (lUnit loop)
-- if we use BiI.predr instead of BiI.pred (≡ BiI.predl) in p₁ and p₂,
-- both paths in S¹ are refl
|
{
"alphanum_fraction": 0.6528651871,
"avg_line_length": 26.7168141593,
"ext": "agda",
"hexsha": "ec3304dd859eec06989c5fe724e7d6df0609ad96",
"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/HITs/Ints/IsoInt/Base.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/HITs/Ints/IsoInt/Base.agda",
"max_line_length": 86,
"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/HITs/Ints/IsoInt/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1157,
"size": 3019
}
|
-- Andreas, 2017-01-12, issue #2386
postulate
F : ∀{a}{A : Set a} → A → A
data Eq (A : Set) : (x y : F A) → Set where
refl : (x : F A) → Eq A x x
{-# BUILTIN EQUALITY Eq #-}
-- Expected error:
-- The type of BUILTIN EQUALITY must be a polymorphic relation
-- when checking the pragma BUILTIN EQUALITY Eq
|
{
"alphanum_fraction": 0.6217948718,
"avg_line_length": 22.2857142857,
"ext": "agda",
"hexsha": "95284277b9088d5ae653e0ffd23e78a0578e93ba",
"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/Issue2386-c.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/Issue2386-c.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2386-c.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": 107,
"size": 312
}
|
-- Andreas, 2015-08-27 Rewrite rules in parametrized modules are fine.
-- Jesper, 2015-10-14 Semantics of rewrite rules in parametrized modules has
-- changed (see issue 1652)
-- Jesper, 2015-11-9 Rewrite rules in parametrized modules are now
-- generalized to the top-context automatically
{-# OPTIONS --rewriting #-}
open import Common.Nat
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
module _ (y z : Nat) where
assoc+ : ∀ x → (x + y) + z ≡ x + (y + z)
assoc+ zero = refl
assoc+ (suc x) rewrite assoc+ x = refl
{-# REWRITE assoc+ #-}
test : ∀{x y} → (x + 0) + y ≡ x + y
test = refl
|
{
"alphanum_fraction": 0.6163328197,
"avg_line_length": 27.0416666667,
"ext": "agda",
"hexsha": "1d91fa367834b689f0ea766eb6090e862f8469b0",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/RewritingRuleInParametrizedModule.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/RewritingRuleInParametrizedModule.agda",
"max_line_length": 76,
"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/Succeed/RewritingRuleInParametrizedModule.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": 201,
"size": 649
}
|
------------------------------------------------------------------------
-- Some examples
------------------------------------------------------------------------
module Contractive.Examples where
open import Codata.Musical.Notation
open import Codata.Musical.Stream
open import Data.Nat
open import Data.Nat.Properties
import Data.Vec as Vec
open Vec using (_∷_; [])
open import Function
open import Contractive
import Contractive.Stream as S
open import StreamProg using (Ord; lt; eq; gt; merge)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open COFE (S.cofe 0)
fibF : ContractiveFun (S.cofe 0)
fibF = record
{ F = F
; isContractive = isCon _ _ _
}
where
F = λ xs → 0 ∷ ♯ (1 ∷ ♯ zipWith _+_ xs (tail xs))
lemma₁ : ∀ _∙_ (xs ys : Stream ℕ) n →
take n (zipWith _∙_ xs ys) ≡
Vec.zipWith _∙_ (take n xs) (take n ys)
lemma₁ _∙_ _ _ zero = refl
lemma₁ _∙_ (x ∷ xs) (y ∷ ys) (suc n) =
cong (_∷_ (x ∙ y)) (lemma₁ _∙_ (♭ xs) (♭ ys) n)
lemma₂ : ∀ (xs ys : Stream ℕ) n →
Eq n xs ys → take n xs ≡ take n ys
lemma₂ _ _ zero _ = refl
lemma₂ (x ∷ xs) ( y ∷ ys) (suc n) hyp
with cong Vec.head hyp | take n (♭ xs) | lemma₂ (♭ xs) (♭ ys) n (cong Vec.tail hyp)
lemma₂ (x ∷ xs) (.x ∷ ys) (suc n) hyp | refl | .(take n (♭ ys)) | refl = refl
isCon : ∀ (xs ys : Stream ℕ) n →
(∀ {m} → m <′ n → Eq m xs ys) →
Eq n (F xs) (F ys)
isCon _ _ zero _ = refl
isCon (x ∷ xs) (y ∷ ys) (suc n) hyp = cong (λ zs → 0 ∷ 1 ∷ zs) (begin
take n (zipWith _+_ (x ∷ xs) (♭ xs)) ≡⟨ lemma₁ _+_ (x ∷ xs) (♭ xs) n ⟩
Vec.zipWith _+_ (take n (x ∷ xs)) (take n (♭ xs)) ≡⟨ cong₂ (Vec.zipWith _+_)
(lemma₂ _ _ n (hyp ≤′-refl))
(cong Vec.tail (hyp ≤′-refl)) ⟩
Vec.zipWith _+_ (take n (y ∷ ys)) (take n (♭ ys)) ≡⟨ sym $ lemma₁ _+_ (y ∷ ys) (♭ ys) n ⟩
take n (zipWith _+_ (y ∷ ys) (♭ ys)) ∎)
fib : Stream ℕ
fib = ContractiveFun.fixpoint fibF
-- Note that I could not be bothered to finish the following
-- definition.
hammingF : ContractiveFun (S.cofe 0)
hammingF = record
{ F = F
; isContractive = isCon _ _ _
}
where
toOrd : ∀ {m n} → Ordering m n → Ord
toOrd (less _ _) = lt
toOrd (equal _) = eq
toOrd (greater _ _) = gt
cmp : ℕ → ℕ → Ord
cmp m n = toOrd (compare m n)
F = λ (xs : _) → 0 ∷ ♯ merge cmp (map (_*_ 2) xs) (map (_*_ 3) xs)
postulate
lemma : ∀ n → cmp (2 * suc n) (3 * suc n) ≡ lt
isCon : ∀ (xs ys : Stream ℕ) n →
(∀ {m} → m <′ n → Eq m xs ys) →
Eq n (F xs) (F ys)
isCon _ _ zero _ = refl
isCon (x ∷ xs) (y ∷ ys) (suc n) hyp with cong Vec.head (hyp (s≤′s z≤′n))
isCon (0 ∷ xs) (.0 ∷ ys) (suc n) hyp | refl =
cong (λ zs → 0 ∷ 0 ∷ zs) (begin
take n (merge cmp (map (_*_ 2) (♭ xs)) (map (_*_ 3) (♭ xs))) ≡⟨ iCantBeBothered ⟩
take n (merge cmp (map (_*_ 2) (♭ ys)) (map (_*_ 3) (♭ ys))) ∎)
where postulate iCantBeBothered : _
isCon (suc x ∷ xs) (.(suc x) ∷ ys) (suc n) hyp | refl
with cmp (2 * suc x) (3 * suc x) | lemma x
isCon (suc x ∷ xs) (.(suc x) ∷ ys) (suc n) hyp | refl | .lt | refl =
cong (λ zs → 0 ∷ 2 * suc x ∷ zs) (begin
take n (merge cmp (map (_*_ 2) (♭ xs))
(map (_*_ 3) (suc x ∷ xs))) ≡⟨ iCantBeBothered ⟩
take n (merge cmp (map (_*_ 2) (♭ ys))
(map (_*_ 3) (suc x ∷ ys))) ∎)
where postulate iCantBeBothered : _
hamming : Stream ℕ
hamming = ContractiveFun.fixpoint hammingF
|
{
"alphanum_fraction": 0.484375,
"avg_line_length": 36.0388349515,
"ext": "agda",
"hexsha": "acd2356ce69d3454342b560191f950099ec8f243",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Contractive/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "Contractive/Examples.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Contractive/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1400,
"size": 3712
}
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Categories.Definition where
record Category {a b : _} : Set (lsuc (a ⊔ b)) where
field
objects : Set a
arrows : objects → objects → Set b
id : (x : objects) → arrows x x
_∘_ : {x y z : objects} → arrows y z → arrows x y → arrows x z
rightId : {x y : objects} → (f : arrows x y) → (id y) ∘ f ≡ f
leftId : {x y : objects} → (f : arrows x y) → f ∘ (id x) ≡ f
compositionAssociative : {x y z w : objects} → (f : arrows z w) → (g : arrows y z) → (h : arrows x y) → (f ∘ (g ∘ h)) ≡ (f ∘ g) ∘ h
|
{
"alphanum_fraction": 0.5720720721,
"avg_line_length": 39.1764705882,
"ext": "agda",
"hexsha": "b9e9080cd161fe04af632107c25c210d7d7b6e90",
"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": "Categories/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": "Categories/Definition.agda",
"max_line_length": 135,
"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": "Categories/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": 245,
"size": 666
}
|
{-# OPTIONS --without-K --safe #-}
-- The Simplex category Δ
module Categories.Category.Instance.Simplex where
open import Level using (0ℓ)
open import Data.Product
open import Data.Fin.Base using (Fin; zero; suc; _≤_; _<_; inject₁; punchIn)
open import Data.Nat.Base using (ℕ; zero; suc; z≤n; s≤s)
open import Function renaming (id to idF; _∘_ to _∙_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong)
open import Categories.Category.Core using (Category)
--------------------------------------------------------------------------------
-- The Simplex Category
--
-- Classically, the category Δ is defined as follows:
-- * Objects are Natural Numbers
-- * Morphisms 'm ⇒ n' are order-preserving maps 'Fin m → Fin n'
--
-- We _can_ define this version of Δ, but it is generally /not/ the version we want.
-- Most of the time we work with Δ, we only care about 2 classes of maps:
-- * Face maps 'δᵢ : n ⇒ (1 + n)' whose image omits 'i'
-- * Boundary maps 'σᵢ : (1 + n) ⇒ n' such that 'σᵢ i = σᵢ (i + 1) = i'
-- It turns out that all of the maps of Δ can be decomposed into compositions
-- of these 2 classes of maps[1], so most texts will define Functors out of Δ
-- based solely how they act on these morphisms.
--
-- Therefore, we want our definition of Δ to put these morphisms front and center,
-- by encoding our homs as follows:
infix 4 _Δ⇒_
infixr 9 _⊚_
data _Δ⇒_ : ℕ → ℕ → Set where
ε : ∀ {n} → n Δ⇒ n
δ : ∀ {n} → (i : Fin (suc n)) → n Δ⇒ (suc n)
σ : ∀ {n} → (j : Fin n) → (suc n) Δ⇒ n
_⊚_ : ∀ {l m n} → m Δ⇒ n → l Δ⇒ m → l Δ⇒ n
-- However, this raises some tricky questions about equality of morphisms. It is tempting
-- to use the Simplical Identities[2] directly as our notion of equality:
-- * δᵢ ∘ δⱼ = δⱼ₊₁ ∘ δᵢ if i ≤ j
-- * σⱼ ∘ σᵢ = σᵢ ∘ σⱼ₊₁ if i ≤ j
-- * σⱼ ∘ δᵢ = δᵢ ∘ σⱼ₋₁ if i < j
-- * σⱼ ∘ δᵢ = id if i = j or i = j + 1
-- * σⱼ ∘ δᵢ = δᵢ₋₁ ∘ σⱼ if j + 1 < i
--
-- However, working with these isn't exactly pleasant and will prove these
-- as theorems later. Instead of quotienting by these identities,
-- we appeal to the denotational semantics of our formal chains of morphisms.
-- In this case we interpret our morphisms as maps between finite ordinals:
face : ∀ {n} → Fin (ℕ.suc n) → Fin n → Fin (ℕ.suc n)
face = punchIn
degen : ∀ {n} → Fin n → Fin (ℕ.suc n) → Fin n
degen Fin.zero Fin.zero = Fin.zero
degen Fin.zero (Fin.suc k) = k
degen (Fin.suc i) Fin.zero = Fin.zero
degen (Fin.suc i) (Fin.suc k) = Fin.suc (degen i k)
⟦_⟧ : ∀ {m n} → m Δ⇒ n → (Fin m → Fin n)
⟦ ε ⟧ x = x
⟦ δ i ⟧ x = face i x
⟦ σ j ⟧ x = degen j x
⟦ f ⊚ g ⟧ x = ⟦ f ⟧ (⟦ g ⟧ x)
-- Now, we can define equality of morphisms by appealing to our semantics!
infix 4 _≗_
-- We wrap this in a record so that we don't compute away what the original morphsims were.
record _≗_ {m n} (f g : m Δ⇒ n) : Set where
constructor Δ-eq
field
Δ-pointwise : ∀ {x} → ⟦ f ⟧ x ≡ ⟦ g ⟧ x
open _≗_ public
-- Now, we get the same benefits of being able to do induction on our input
-- arguments when trying to prove equalities, as well as being able to define functors
-- out of Δ via their action on face/degeneracy maps.
Δ : Category 0ℓ 0ℓ 0ℓ
Δ = record
{ Obj = ℕ
; _⇒_ = _Δ⇒_
; _≈_ = _≗_
; id = ε
; _∘_ = _⊚_
; assoc = Δ-eq refl
; sym-assoc = Δ-eq refl
; identityˡ = Δ-eq refl
; identityʳ = Δ-eq refl
; identity² = Δ-eq refl
; equiv = record
{ refl = Δ-eq refl
; sym = λ eq → Δ-eq (sym (Δ-pointwise eq))
; trans = λ eq₁ eq₂ → Δ-eq (trans (Δ-pointwise eq₁) (Δ-pointwise eq₂))
}
; ∘-resp-≈ = λ {_ _ _ f g h i} eq₁ eq₂ → Δ-eq (trans (cong ⟦ f ⟧ (Δ-pointwise eq₂)) (Δ-pointwise eq₁))
}
-- For completeness, here are the aforementioned simplical identities. These may seem /slightly/
-- different than the ones presented before, but it's just re-indexing to avoid having to use 'pred'.
open Category Δ
-- δᵢ ∘ δⱼ = δⱼ₊₁ ∘ δᵢ if i ≤ j
face-comm : ∀ {n} (i j : Fin (suc n)) → i ≤ j → δ (inject₁ i) ∘ δ j ≈ δ (suc j) ∘ δ i
face-comm zero _ z≤n = Δ-eq refl
face-comm (suc i) (suc j) (s≤s le) = Δ-eq (λ { {zero} → refl ; {suc x} → cong suc (Δ-pointwise (face-comm i j le)) })
-- σⱼ ∘ σᵢ = σᵢ ∘ σⱼ₊₁ if i ≤ j
degen-comm : ∀ {n} (i j : Fin n) → i ≤ j → σ j ∘ σ (inject₁ i) ≈ σ i ∘ σ (suc j)
degen-comm zero zero z≤n = Δ-eq λ { {zero} → refl ; {suc x} → refl }
degen-comm zero (suc _) z≤n = Δ-eq λ { {zero} → refl ; {suc x} → refl }
degen-comm (suc i) (suc j) (s≤s le) = Δ-eq (λ { {zero} → refl ; {suc x} → cong suc (Δ-pointwise (degen-comm i j le)) })
-- σⱼ ∘ δᵢ = δᵢ ∘ σⱼ₋₁ if i < j
degen-face-comm : ∀ {n} (i : Fin (suc n)) (j : Fin n) → i < suc j → σ (suc j) ∘ δ (inject₁ i) ≈ δ i ∘ σ j
degen-face-comm zero _ (s≤s _) = Δ-eq refl
degen-face-comm (suc i) (suc j) (s≤s le) = Δ-eq (λ { {zero} → refl ; {suc x} → cong suc (Δ-pointwise (degen-face-comm i j le)) })
-- σⱼ ∘ δᵢ = id if i = j
degen-face-id : ∀ {n} (i j : Fin n) → i ≡ j → σ j ∘ δ (inject₁ i) ≈ id
degen-face-id zero zero refl = Δ-eq refl
degen-face-id (suc i) (suc i) refl = Δ-eq (λ { {zero} → refl ; {suc x} → cong suc (Δ-pointwise (degen-face-id i i refl)) })
-- σⱼ ∘ δᵢ = id if i = j + 1
degen-face-suc-id : ∀ {n} (i : Fin (suc n)) (j : Fin n) → i ≡ suc j → σ j ∘ δ i ≈ id
degen-face-suc-id (suc zero) zero refl = Δ-eq λ { {zero} → refl ; {suc x} → refl }
degen-face-suc-id (suc (suc i)) (suc i) refl = Δ-eq λ { {zero} → refl ; {suc x} → cong suc (Δ-pointwise (degen-face-suc-id (suc i) i refl)) }
-- σⱼ ∘ δᵢ = δᵢ₋₁ ∘ σⱼ if j + 1 < i
degen-face-suc-comm : ∀ {n} (i : Fin (suc n)) (j : Fin n) → suc j < i → σ (inject₁ j) ∘ δ (suc i) ≈ δ i ∘ σ j
degen-face-suc-comm (suc (suc i)) zero (s≤s (s≤s z≤n)) = Δ-eq (λ { {zero} → refl ; {suc x} → refl })
degen-face-suc-comm (suc (suc i)) (suc j) (s≤s le) = Δ-eq (λ { {zero} → refl ; {suc x} → cong suc (Δ-pointwise (degen-face-suc-comm (suc i) j le)) })
-- Further Work:
-- If we had a means of decomposing any monotone map 'Fin n ⇒ Fin m' into a series of face/boundary
-- maps, we would be able to compute normal forms in Δ by using normalization by evaluation. This is
-- very promising, as it would let us define a reflection tactic to automatically perform
-- proofs about chains of morphisms in Δ.
-- Footnotes:
-- 1. For a proof of this, see Categories for The Working Mathematician VII.5
-- 2. See https://ncatlab.org/nlab/show/simplex+category
|
{
"alphanum_fraction": 0.5951717734,
"avg_line_length": 42.5131578947,
"ext": "agda",
"hexsha": "96448b6553fc47581916104e054e0b067d45e02a",
"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/Instance/Simplex.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/Instance/Simplex.agda",
"max_line_length": 156,
"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/Instance/Simplex.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": 2559,
"size": 6462
}
|
-- Sums and cocartesian categories
module CategoryTheory.BCCCs.Cocartesian where
open import CategoryTheory.Categories
open import Relation.Binary using (IsEquivalence)
module _ {n} (ℂ : Category n) where
open Category ℂ
-- Initial object in a category
record InitialObj : Set (lsuc n) where
field
-- | Data
-- The initial object
⊥ : obj
-- Canonical morphism
¡ : {A : obj} -> (⊥ ~> A)
-- | Laws
-- Need to show that the canonical morphism ! is unique
¡-unique : {A : obj} -> (m : ⊥ ~> A)
-> m ≈ ¡
-- Sum of two objects
-- Based on github.com/copumpkin/categories
record Sum (A B : obj) : Set (lsuc n) where
infix 10 [_⁏_]
field
-- | Data
-- Sum of A and B
A⊕B : obj
-- First injection
ι₁ : A ~> A⊕B
-- Second injection
ι₂ : B ~> A⊕B
-- Canonical mediator
[_⁏_] : ∀{S} -> (A ~> S) -> (B ~> S) -> (A⊕B ~> S)
-- | Laws
-- [_⁏_] expresses that given another candidate sum S
-- and candidate injections to A and B there is a morphism
-- from A⊕B to S. We need to check that this mediator makes
-- the sum diagram commute and is unique.
ι₁-comm : ∀{S} -> {i₁ : A ~> S} {i₂ : B ~> S}
-> [ i₁ ⁏ i₂ ] ∘ ι₁ ≈ i₁
ι₂-comm : ∀{S} -> {i₁ : A ~> S} {i₂ : B ~> S}
-> [ i₁ ⁏ i₂ ] ∘ ι₂ ≈ i₂
⊕-unique : ∀{S} -> {i₁ : A ~> S} {i₂ : B ~> S} {m : A⊕B ~> S}
-> m ∘ ι₁ ≈ i₁ -> m ∘ ι₂ ≈ i₂ -> [ i₁ ⁏ i₂ ] ≈ m
-- η-expansion of function sums (via morphisms)
⊕-η-exp : ∀{S} -> {m : A⊕B ~> S}
-> [ m ∘ ι₁ ⁏ m ∘ ι₂ ] ≈ m
⊕-η-exp = ⊕-unique r≈ r≈
-- Summing of injection functions is the identity
⊕-η-id : [ ι₁ ⁏ ι₂ ] ≈ id
⊕-η-id = ⊕-unique id-left id-left
-- Congruence over function summing
[⁏]-cong : ∀{S} -> {i₁ j₁ : A ~> S} {i₂ j₂ : B ~> S}
-> i₁ ≈ j₁ -> i₂ ≈ j₂
-> [ i₁ ⁏ i₂ ] ≈ [ j₁ ⁏ j₂ ]
[⁏]-cong pr1 pr2 = ⊕-unique (ι₁-comm ≈> pr1 [sym]) (ι₂-comm ≈> pr2 [sym])
-- Type class for cocartesian categories
record Cocartesian {n} (ℂ : Category n) : Set (lsuc n) where
open Category ℂ
field
-- | Data
-- Initial object
init : InitialObj ℂ
-- Binary sums for all pairs of objects
sum : ∀(A B : obj) -> Sum ℂ A B
open InitialObj init public
open module S {A} {B} = Sum (sum A B) public
-- Shorthand for sum object
infixl 22 _⊕_
_⊕_ : (A B : obj) -> obj
A ⊕ B = A⊕B {A} {B}
-- Parallel sum of morphisms
infixl 65 _⊹_
_⊹_ : {A B P Q : obj} -> (A ~> P) -> (B ~> Q)
-> (A ⊕ B ~> P ⊕ Q)
_⊹_ {A} {B} {P} {Q} f g = [ ι₁ ∘ f ⁏ ι₂ ∘ g ]
-- Sum of three morphisms
[_⁏_⁏_] : ∀{S A B C : obj} -> (A ~> S) -> (B ~> S) -> (C ~> S) -> (A ⊕ B ⊕ C ~> S)
[ f ⁏ g ⁏ h ] = [ [ f ⁏ g ] ⁏ h ]
|
{
"alphanum_fraction": 0.4411575563,
"avg_line_length": 32.0618556701,
"ext": "agda",
"hexsha": "65cf6fe05b6a412511e28be8ee532682319eafca",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/CategoryTheory/BCCCs/Cocartesian.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/CategoryTheory/BCCCs/Cocartesian.agda",
"max_line_length": 86,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/CategoryTheory/BCCCs/Cocartesian.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 1122,
"size": 3110
}
|
module BasicIPC.Metatheory.ClosedHilbert-TarskiGluedClosedHilbert where
open import BasicIPC.Syntax.ClosedHilbert public
open import BasicIPC.Semantics.TarskiGluedClosedHilbert public
-- Internalisation of syntax as syntax representation in a particular model.
module _ {{_ : Model}} where
[_] : ∀ {A} → ⊢ A → [⊢] A
[ app t u ] = [app] [ t ] [ u ]
[ ci ] = [ci]
[ ck ] = [ck]
[ cs ] = [cs]
[ cpair ] = [cpair]
[ cfst ] = [cfst]
[ csnd ] = [csnd]
[ unit ] = [unit]
-- Soundness with respect to all models, or evaluation, for closed terms only.
eval₀ : ∀ {A} → ⊢ A → ⊨ A
eval₀ (app t u) = eval₀ t ⟪$⟫ eval₀ u
eval₀ ci = [ci] ⅋ I
eval₀ ck = [ck] ⅋ ⟪K⟫
eval₀ cs = [cs] ⅋ ⟪S⟫′
eval₀ cpair = [cpair] ⅋ _⟪,⟫′_
eval₀ cfst = [cfst] ⅋ π₁
eval₀ csnd = [csnd] ⅋ π₂
eval₀ unit = ∙
-- Correctness of evaluation with respect to conversion.
eval₀✓ : ∀ {{_ : Model}} {A} {t t′ : ⊢ A} → t ⋙ t′ → eval₀ t ≡ eval₀ t′
eval₀✓ refl⋙ = refl
eval₀✓ (trans⋙ p q) = trans (eval₀✓ p) (eval₀✓ q)
eval₀✓ (sym⋙ p) = sym (eval₀✓ p)
eval₀✓ (congapp⋙ p q) = cong² _⟪$⟫_ (eval₀✓ p) (eval₀✓ q)
eval₀✓ (congi⋙ p) = cong I (eval₀✓ p)
eval₀✓ (congk⋙ p q) = cong² K (eval₀✓ p) (eval₀✓ q)
eval₀✓ (congs⋙ p q r) = cong³ ⟪S⟫ (eval₀✓ p) (eval₀✓ q) (eval₀✓ r)
eval₀✓ (congpair⋙ p q) = cong² _,_ (eval₀✓ p) (eval₀✓ q)
eval₀✓ (congfst⋙ p) = cong π₁ (eval₀✓ p)
eval₀✓ (congsnd⋙ p) = cong π₂ (eval₀✓ p)
eval₀✓ beta▻ₖ⋙ = refl
eval₀✓ beta▻ₛ⋙ = refl
eval₀✓ beta∧₁⋙ = refl
eval₀✓ beta∧₂⋙ = refl
eval₀✓ eta∧⋙ = refl
eval₀✓ eta⊤⋙ = refl
-- The canonical model.
private
instance
canon : Model
canon = record
{ ⊩ᵅ_ = λ P → ⊢ α P
; [⊢]_ = ⊢_
; [app] = app
; [ci] = ci
; [ck] = ck
; [cs] = cs
; [cpair] = cpair
; [cfst] = cfst
; [csnd] = csnd
; [unit] = unit
}
-- Completeness with respect to all models, or quotation, for closed terms only.
quot₀ : ∀ {A} → ⊨ A → ⊢ A
quot₀ s = reifyʳ s
-- Normalisation by evaluation, for closed terms only.
norm₀ : ∀ {A} → ⊢ A → ⊢ A
norm₀ = quot₀ ∘ eval₀
-- Correctness of normalisation with respect to conversion.
norm₀✓ : ∀ {{_ : Model}} {A} {t t′ : ⊢ A} → t ⋙ t′ → norm₀ t ≡ norm₀ t′
norm₀✓ p = cong reifyʳ (eval₀✓ p)
|
{
"alphanum_fraction": 0.5316561845,
"avg_line_length": 26.5,
"ext": "agda",
"hexsha": "69b669fa91379353d0aed14783a1254a702fdee1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicIPC/Metatheory/ClosedHilbert-TarskiGluedClosedHilbert.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicIPC/Metatheory/ClosedHilbert-TarskiGluedClosedHilbert.agda",
"max_line_length": 80,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicIPC/Metatheory/ClosedHilbert-TarskiGluedClosedHilbert.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1046,
"size": 2385
}
|
-- Andreas, 2012-04-18 make sure with functions of irrelevant functions
-- are also irrelevant
module IrrelevantWith where
import Common.Level
open import Common.Irrelevance
.unsq : ∀ {a}{A : Set a} → Squash A → A
unsq sq with Set
... | _ = unsquash sq
|
{
"alphanum_fraction": 0.7254901961,
"avg_line_length": 23.1818181818,
"ext": "agda",
"hexsha": "32c8bb685479e3e596b6ff42e089d354c8fb8864",
"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": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/IrrelevantWith.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/IrrelevantWith.agda",
"max_line_length": 71,
"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/Succeed/IrrelevantWith.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": 75,
"size": 255
}
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Rationals.HITQ.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Relation.Nullary
open import Cubical.Data.Int
open import Cubical.Data.Nat as ℕ hiding (_·_)
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Sigma
-- ℚ as a higher inductive type
data ℚ : Type₀ where
con : (u : ℤ) (a : ℤ) → ¬ (a ≡ 0) → ℚ
path : ∀ u a v b {p q} → (u · b) ≡ (v · a) → con u a p ≡ con v b q
trunc : isSet ℚ
[_] : ℤ × ℕ₊₁ → ℚ
[ a , 1+ b ] = con a (pos (suc b)) (ℕ.snotz ∘ cong abs)
module Elim {ℓ} {B : ℚ → Type ℓ}
(con* : ∀ u a (p : ¬ (a ≡ 0)) → B (con u a p))
(path* : ∀ u a v b {p q} (eq : (u · b) ≡ (v · a))
→ PathP (λ i → B (path u a v b {p} {q} eq i)) (con* u a p) (con* v b q))
(trunc* : (q : ℚ) → isSet (B q))
where
f : (q : ℚ) → B q
f (con u a x) = con* u a x
f (path u a v b x i) = path* u a v b x i
f (trunc xs ys p q i j) =
isOfHLevel→isOfHLevelDep 2 trunc* (f xs) (f ys) (cong f p) (cong f q) (trunc xs ys p q) i j
module ElimProp {ℓ} {B : ℚ → Type ℓ} {BProp : {q : ℚ} → isProp (B q)}
(con* : ∀ u a (p : ¬ (a ≡ 0)) → B (con u a p))
where
f : (q : ℚ) → B q
f = Elim.f con*
(λ u a v b {p} {q} eq →
toPathP (BProp (transport (λ i → B (path u a v b eq i)) (con* u a p)) (con* v b q)))
λ q → isProp→isSet BProp
module Rec {ℓ} {B : Type ℓ} {BType : isSet B}
(con* : ∀ u a (p : ¬ (a ≡ 0)) → B)
(path* : ∀ u a v b {p q} (eq : (u · b) ≡ (v · a))
→ con* u a p ≡ con* v b q) where
f : ℚ → B
f = Elim.f con* path* λ _ → BType
module Rec2 {ℓ} {B : Type ℓ} {BType : isSet B}
(con* : ∀ u a (p : ¬ (a ≡ 0)) v b (q : ¬ (b ≡ 0)) → B)
(path*₁ : ∀ u₁ a₁ {p₁}
u₂ a₂ v₂ b₂ {p₂ q₂}
(eq₁ : (u₁ · b₂) ≡ (v₂ · a₁))
→ con* u₁ a₁ p₁ u₂ a₂ p₂ ≡ con* v₂ b₂ q₂ u₂ a₂ p₂)
(path*₂ : ∀ u₁ a₁ {p₁}
u₂ a₂ v₂ b₂ {p₂ q₂}
(eq₂ : (u₂ · b₂) ≡ (v₂ · a₂))
→ con* u₁ a₁ p₁ u₂ a₂ p₂ ≡ con* u₁ a₁ p₁ v₂ b₂ q₂)
where
f : ℚ → ℚ → B
f = Rec.f {BType = λ x y p q i j w → BType (x w) (y w) (λ k → p k w) (λ k → q k w) i j}
(λ u a p → Rec.f {BType = BType} (con* u a p) (path*₂ u a {p}))
λ u a v b eq → funExt (ElimProp.f {BProp = BType _ _}
λ u₂ a₂ p₂ → path*₁ _ _ _ _ _ _ eq)
--- Natural number and negative integer literals for ℚ
open import Cubical.Data.Nat.Literals public
instance
fromNatℚ : HasFromNat ℚ
fromNatℚ = record { Constraint = λ _ → Unit ; fromNat = λ n → [ pos n , 1 ] }
instance
fromNegℚ : HasFromNeg ℚ
fromNegℚ = record { Constraint = λ _ → Unit ; fromNeg = λ n → [ neg n , 1 ] }
|
{
"alphanum_fraction": 0.5299242424,
"avg_line_length": 30.3448275862,
"ext": "agda",
"hexsha": "ad94f9803b80452e85540a2e0c887e4628e975a0",
"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/HITs/Rationals/HITQ/Base.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/HITs/Rationals/HITQ/Base.agda",
"max_line_length": 96,
"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/HITs/Rationals/HITQ/Base.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": 1201,
"size": 2640
}
|
{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.Data.Fin.Recursive where
open import Cubical.Data.Fin.Recursive.Base public
open import Cubical.Data.Fin.Recursive.Properties public
|
{
"alphanum_fraction": 0.7810945274,
"avg_line_length": 28.7142857143,
"ext": "agda",
"hexsha": "40d38939e9e9fb6867b77a7c39687212674e92ba",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Fin/Recursive.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/Data/Fin/Recursive.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Fin/Recursive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 48,
"size": 201
}
|
------------------------------------------------------------------------
-- A small definition of a dependently typed language, using the
-- technique from McBride's "Outrageous but Meaningful Coincidences"
------------------------------------------------------------------------
{-# OPTIONS --type-in-type #-}
-- The code contains an example, a partial definition of categories,
-- which triggers the use of an enormous amount of memory (with the
-- development version of Agda which is current at the time of
-- writing). I'm not entirely sure if the code is correct: 2.5G heap
-- doesn't seem to suffice to typecheck this code. /NAD
module Language where
------------------------------------------------------------------------
-- Prelude
open import Prelude
subst : {A : Set} {x y : A} (P : A -> Set) ->
x == y -> P x -> P y
subst P = J (\ x y _ -> P x -> P y) (\ x p -> p)
Empty : Set
Empty = (A : Set) -> A
record Unit : Set
record Unit where
constructor tt
open Unit
data Either (A : Set) (B : Set) : Set
data Either A B where
left : A -> Either A B
right : B -> Either A B
record Sigma (A : Set) (B : A -> Set) : Set
record Sigma A B where
constructor pair
field
fst : A
snd : B fst
open Sigma
uncurry : {A : Set} {B : A -> Set} {C : Sigma A B -> Set} ->
((x : A) (y : B x) -> C (pair x y)) ->
((p : Sigma A B) -> C p)
uncurry f p = f (fst p) (snd p)
Times : Set -> Set -> Set
Times A B = Sigma A (\ _ -> B)
------------------------------------------------------------------------
-- A universe
data U : Set
El : U -> Set
data U where
set : U
el : Set -> U
sigma : (a : U) -> (El a -> U) -> U
pi : (a : U) -> (El a -> U) -> U
El set = Set
El (el A) = A
El (sigma a b) = Sigma (El a) (\ x -> El (b x))
El (pi a b) = (x : El a) -> El (b x)
-- Abbreviations.
fun : U -> U -> U
fun a b = pi a (\ _ -> b)
times : U -> U -> U
times a b = sigma a (\ _ -> b)
-- Example.
raw-categoryU : U
raw-categoryU =
sigma set (\ obj ->
sigma (fun (el obj) (fun (el obj) set)) (\ hom ->
times
(pi (el obj) (\ x -> el (hom x x)))
(pi (el obj) (\ x -> pi (el obj) (\ y -> pi (el obj) (\ z ->
fun (el (hom x y)) (fun (el (hom y z)) (el (hom x z)))))))))
------------------------------------------------------------------------
-- Contexts
-- Contexts.
data Ctxt : Set
-- Types.
Ty : Ctxt -> Set
-- Environments.
Env : Ctxt -> Set
data Ctxt where
empty : Ctxt
snoc : (G : Ctxt) -> Ty G -> Ctxt
Ty G = Env G -> U
Env empty = Unit
Env (snoc G s) = Sigma (Env G) (\ g -> El (s g))
-- Variables (de Bruijn indices).
Var : (G : Ctxt) -> Ty G -> Set
Var empty t = Empty
Var (snoc G s) t =
Either ((\ g -> s (fst g)) == t)
(Sigma _ (\ u -> Times ((\ g -> u (fst g)) == t) (Var G u)))
zero : {G : _} {s : _} ->
Var (snoc G s) (\ g -> s (fst g))
zero = left refl
suc : {G : _} {s : _} {t : _}
(x : Var G t) ->
Var (snoc G s) (\ g -> t (fst g))
suc x = right (pair _ (pair refl x))
-- A lookup function.
lookup : (G : Ctxt) (s : Ty G) -> Var G s -> (g : Env G) -> El (s g)
lookup empty _ absurd _ = absurd _
lookup (snoc _ _) _ (left eq) g = subst (\ f -> El (f g)) eq (snd g)
lookup (snoc _ _) t (right p) g =
subst (\ f -> El (f g)) (fst (snd p)) (lookup _ _ (snd (snd p)) (fst g))
{-
------------------------------------------------------------------------
-- A language
-- Syntax for types.
data Type (G : Ctxt) (s : Ty G) : Set
-- Terms.
data Term (G : Ctxt) (s : Ty G) : Set
-- The semantics of a term.
eval : {G : _} {s : _} -> Term G s -> (g : Env G) -> El (s g)
data Type G s where
set'' : s == (\ _ -> set) -> Type G s
el'' : (x : Term G (\ _ -> set)) ->
(\ g -> el (eval x g)) == s ->
Type G s
sigma'' : {t : _} {u : _} ->
Type G t ->
Type (snoc G t) u ->
(\ g -> sigma (t g) (\ v -> u (pair g v))) == s ->
Type G s
pi'' : {t : _} {u : _} ->
Type G t ->
Type (snoc G t) u ->
(\ g -> pi (t g) (\ v -> u (pair g v))) == s ->
Type G s
data Term G s where
var : Var G s -> Term G s
lam'' : {t : _} {u : _} ->
Term (snoc G t) (uncurry u) ->
(\ g -> pi (t g) (\ v -> u g v)) == s ->
Term G s
app'' : {t : _} {u : (g : Env G) -> El (t g) -> U} ->
Term G (\ g -> pi (t g) (\ v -> u g v)) ->
(t2 : Term G t) ->
(\ g -> u g (eval t2 g)) == s ->
Term G s
eval (var x) g = lookup _ _ x g
eval (lam'' t eq) g = subst (\ f -> El (f g)) eq
(\ v -> eval t (pair g v))
eval (app'' t1 t2 eq) g = subst (\ f -> El (f g)) eq
(eval t1 g (eval t2 g))
-- Abbreviations.
set' : {G : _} -> Type G (\ _ -> set)
set' = set'' refl
el' : {G : _}
(x : Term G (\ _ -> set)) ->
Type G (\ g -> el (eval x g))
el' x = el'' x refl
sigma' : {G : _} {t : _} {u : _} ->
Type G t ->
Type (snoc G t) u ->
Type G (\ g -> sigma (t g) (\ v -> u (pair g v)))
sigma' s t = sigma'' s t refl
pi' : {G : _} {t : _} {u : _} ->
Type G t ->
Type (snoc G t) u ->
Type G (\ g -> pi (t g) (\ v -> u (pair g v)))
pi' s t = pi'' s t refl
lam : {G : _} {t : _} {u : _} ->
Term (snoc G t) (uncurry u) ->
Term G (\ g -> pi (t g) (\ v -> u g v))
lam t = lam'' t refl
app : {G : _} {t : _} {u : (g : Env G) -> El (t g) -> U} ->
Term G (\ g -> pi (t g) (\ v -> u g v)) ->
(t2 : Term G t) ->
Term G (\ g -> u g (eval t2 g))
app t1 t2 = app'' t1 t2 refl
-- Example.
raw-category : Type empty (\ _ -> raw-categoryU)
raw-category =
-- Objects.
sigma' set'
-- Morphisms.
(sigma' (pi' (el' (var zero)) (pi' (el' (var (suc zero))) set'))
-- Identity.
(sigma' (pi' (el' (var (suc zero)))
(el' (app (app (var (suc zero)) (var zero)) (var zero))))
-- Composition.
(pi' (el' (var (suc (suc zero)))) -- X.
(pi' (el' (var (suc (suc (suc zero))))) -- Y.
(pi' (el' (var (suc (suc (suc (suc zero)))))) -- Z.
(pi' (el' (app (app (var (suc (suc (suc (suc zero)))))
(var (suc (suc zero))))
(var (suc zero)))) -- Hom X Y.
(pi' (el' (app (app (var (suc (suc (suc (suc (suc zero))))))
(var (suc (suc zero))))
(var (suc zero)))) -- Hom Y Z.
(el' (app (app (var (suc (suc (suc (suc (suc (suc zero)))))))
(var (suc (suc (suc (suc zero))))))
(var (suc (suc zero)))))) -- Hom X Z.
))))))
-}
|
{
"alphanum_fraction": 0.4069428238,
"avg_line_length": 27.2063492063,
"ext": "agda",
"hexsha": "6c69fcf33c34e1cc465e3bd8949a85d827ffeb25",
"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": "src/prototyping/term/examples/Language.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": "src/prototyping/term/examples/Language.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "src/prototyping/term/examples/Language.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": 2252,
"size": 6856
}
|
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Lemmas
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Groups.Definition
open import Groups.Lemmas
open import Fields.Fields
open import Sets.EquivalenceRelations
open import Sequences
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Functions.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Semirings.Definition
open import Numbers.Modulo.Definition
open import Orders.Total.Definition
module Fields.CauchyCompletion.BaseExpansion {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) where
open Setoid S
open SetoidTotalOrder (TotallyOrderedRing.total order)
open SetoidPartialOrder pOrder
open Equivalence eq
open PartiallyOrderedRing pRing
open Ring R
open Group additiveGroup
open Field F
open import Fields.Orders.Limits.Definition {F = F} (record { oRing = order })
open import Fields.Orders.Total.Lemmas {F = F} (record { oRing = order })
open import Fields.Orders.Limits.Lemmas {F = F} (record { oRing = order })
open import Fields.Lemmas F
open import Fields.Orders.Lemmas {F = F} record { oRing = order }
open import Rings.Orders.Total.Lemmas order
open import Rings.Orders.Total.AbsoluteValue order
open import Rings.Orders.Partial.Lemmas pRing
open import Fields.CauchyCompletion.Definition order F
open import Fields.CauchyCompletion.Setoid order F
open import Fields.CauchyCompletion.Addition order F
open import Fields.CauchyCompletion.Comparison order F
open import Fields.CauchyCompletion.Approximation order F
open import Rings.InitialRing R
open import Rings.Orders.Partial.Bounded pRing
open import Rings.Orders.Total.Bounded order
open import Rings.Orders.Total.Cauchy order
-- TODO this is not necessarily true :( the bounded sequence could oscillate between 1 and -1
cauchyTimesBoundedIsCauchy : {s : Sequence A} → cauchy s → {t : Sequence A} → Bounded t → cauchy (apply _*_ s t)
cauchyTimesBoundedIsCauchy {s} cau {t} (K , bounded) e 0<e with allInvertible K (boundNonzero (K , bounded))
... | 1/K , prK with cau (1/K * e) (orderRespectsMultiplication (reciprocalPositive K 1/K (boundGreaterThanZero (K , bounded)) (transitive *Commutative prK)) 0<e)
... | N , cauPr = N , ans
where
ans : {m n : ℕ} (N<m : N <N m) (N<n : N <N n) → (abs (index (apply _*_ s t) m + inverse (index (apply _*_ s t) n))) < e
ans N<m N<n with cauPr N<m N<n
... | r = {!!}
boundedTimesCauchyIsCauchy : {s : Sequence A} → cauchy s → {t : Sequence A} → Bounded t → cauchy (apply _*_ t s)
boundedTimesCauchyIsCauchy {s} cau {t} bou = cauchyWellDefined (ans s t) (cauchyTimesBoundedIsCauchy cau bou)
where
ans : (s t : Sequence A) (m : ℕ) → index (apply _*_ s t) m ∼ index (apply _*_ t s) m
ans s t m rewrite indexAndApply t s _*_ {m} | indexAndApply s t _*_ {m} = *Commutative
private
digitExpansionSeq : {n : ℕ} → .(0<n : 0 <N n) → Sequence (ℤn n 0<n) → Sequence A
Sequence.head (digitExpansionSeq {n} 0<n seq) = fromN (ℤn.x (Sequence.head seq))
Sequence.tail (digitExpansionSeq {n} 0<n seq) = digitExpansionSeq 0<n (Sequence.tail seq)
powerSeq : (i : A) → (start : A) → Sequence A
Sequence.head (powerSeq i start) = start
Sequence.tail (powerSeq i start) = powerSeq i (start * i)
powerSeqInduction : (i : A) (start : A) → (m : ℕ) → (index (powerSeq i start) (succ m)) ∼ i * (index (powerSeq i start) m)
powerSeqInduction i start zero = *Commutative
powerSeqInduction i start (succ m) = powerSeqInduction i (start * i) m
ofBaseExpansionSeq : {n : ℕ} → .(0<n : 0 <N n) → Sequence (ℤn n 0<n) → Sequence A
ofBaseExpansionSeq {succ n} 0<n seq = apply _*_ (digitExpansionSeq 0<n seq) (powerSeq pow pow)
where
pow : A
pow = underlying (allInvertible (fromN (succ n)) (charNotN n))
powerSeqPositive : {i : A} → (0R < i) → {s : A} → (0R < s) → (m : ℕ) → 0R < index (powerSeq i s) m
powerSeqPositive {i} 0<i {s} 0<s zero = 0<s
powerSeqPositive {i} 0<i {s} 0<s (succ m) = <WellDefined reflexive (symmetric (powerSeqInduction i s m)) (orderRespectsMultiplication 0<i (powerSeqPositive 0<i 0<s m))
powerSeqConvergesTo0 : (i : A) → (0R < i) → (i < 1R) → {s : A} → (0R < s) → (powerSeq i s) ~> 0G
powerSeqConvergesTo0 i 0<i i<1 {s} 0<s e 0<e = {!!}
powerSeqConverges : (i : A) → (0R < i) → (i < 1R) → {s : A} → (0R < s) → cauchy (powerSeq i s)
powerSeqConverges i 0<i i<1 {s} 0<s = convergentSequenceCauchy nontrivial {r = 0R} (powerSeqConvergesTo0 i 0<i i<1 0<s)
0<n : {n : ℕ} → 1 <N n → 0 <N n
0<n 1<n = TotalOrder.<Transitive ℕTotalOrder (le 0 refl) 1<n
digitExpansionBoundedLemma : {n : ℕ} → .(0<n : 0 <N n) → (seq : Sequence (ℤn n 0<n)) → (m : ℕ) → index (digitExpansionSeq _ seq) m < fromN n
digitExpansionBoundedLemma {n} 0<n seq zero with Sequence.head seq
... | record { x = x ; xLess = xLess } = fromNPreservesOrder (0<1 nontrivial) {x} {n} ((squash<N xLess))
digitExpansionBoundedLemma 0<n seq (succ m) = digitExpansionBoundedLemma 0<n (Sequence.tail seq) m
digitExpansionBoundedLemma2 : {n : ℕ} → .(0<n : 0 <N n) → (seq : Sequence (ℤn n 0<n)) → (m : ℕ) → inverse (fromN n) < index (digitExpansionSeq 0<n seq) m
digitExpansionBoundedLemma2 {n} 0<n seq zero = <WellDefined identLeft (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invRight) identRight)) (orderRespectsAddition {_} {fromN (ℤn.x (Sequence.head seq)) + fromN n} (<WellDefined reflexive (fromNPreserves+ (ℤn.x (Sequence.head seq)) n) (fromNPreservesOrder (0<1 nontrivial) {0} {ℤn.x (Sequence.head seq) +N n} (canAddToOneSideOfInequality' _ (squash<N 0<n)))) (inverse (fromN n)))
digitExpansionBoundedLemma2 0<n seq (succ m) = digitExpansionBoundedLemma2 0<n (Sequence.tail seq) m
digitExpansionBounded : {n : ℕ} → .(0<n : 0 <N n) → (seq : Sequence (ℤn n 0<n)) → Bounded (digitExpansionSeq 0<n seq)
digitExpansionBounded {n} 0<n seq = fromN n , λ m → ((digitExpansionBoundedLemma2 0<n seq m) ,, digitExpansionBoundedLemma 0<n seq m)
private
1/nPositive : (n : ℕ) → 0R < underlying (allInvertible (fromN (succ n)) (charNotN n))
1/nPositive n with allInvertible (fromN (succ n)) (charNotN n)
... | a , b = reciprocalPositive (fromN (succ n)) a (fromNPreservesOrder (0<1 nontrivial) (succIsPositive n)) (transitive *Commutative b)
1/n<1 : (n : ℕ) → (0 <N n) → underlying (allInvertible (fromN (succ n)) (charNotN n)) < 1R
1/n<1 n 1<n with allInvertible (fromN (succ n)) (charNotN n)
... | a , b = reciprocal<1 (fromN (succ n)) a (<WellDefined identRight reflexive (fromNPreservesOrder (0<1 nontrivial) {1} {succ n} (succPreservesInequality 1<n))) (transitive *Commutative b)
-- Construct the real that is the given base-n expansion between 0 and 1.
ofBaseExpansion : {n : ℕ} → .(1<n : 1 <N n) → (fromN n ∼ 0R → False) → Sequence (ℤn n (0<n 1<n)) → CauchyCompletion
ofBaseExpansion {succ n} 1<n charNotN seq = record { elts = ofBaseExpansionSeq (0<n 1<n) seq ; converges = boundedTimesCauchyIsCauchy (powerSeqConverges _ (1/nPositive n) (1/n<1 n (canRemoveSuccFrom<N (squash<N 1<n))) (1/nPositive n)) (digitExpansionBounded (0<n 1<n) seq)}
toBaseExpansion : {n : ℕ} → .(1<n : 1 <N n) → (fromN n ∼ 0R → False) → (a : CauchyCompletion) → 0R r<C a → a <Cr 1R → Sequence (ℤn n (0<n 1<n))
Sequence.head (toBaseExpansion {n} 1<n charNotN c 0<c c<1) = {!!}
-- TOOD: approximate c to within 1/n^2, extract the first decimal of the result.
Sequence.tail (toBaseExpansion {n} 1<n charNotN c 0<c c<1) = toBaseExpansion 1<n charNotN {!!} {!!} {!!}
baseExpansionProof : {n : ℕ} → .{1<n : 1 <N n} → {charNotN : fromN n ∼ 0R → False} → (as : CauchyCompletion) → (0<a : 0R r<C as) → (a<1 : as <Cr 1R) → Setoid._∼_ cauchyCompletionSetoid (ofBaseExpansion 1<n charNotN (toBaseExpansion 1<n charNotN as 0<a a<1)) as
baseExpansionProof = {!!}
|
{
"alphanum_fraction": 0.6934814453,
"avg_line_length": 61.5939849624,
"ext": "agda",
"hexsha": "58715c0ac2cde6a19681fc4b45e7443fd1b2e86a",
"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": "Fields/CauchyCompletion/BaseExpansion.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": "Fields/CauchyCompletion/BaseExpansion.agda",
"max_line_length": 455,
"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": "Fields/CauchyCompletion/BaseExpansion.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": 2861,
"size": 8192
}
|
module Builtin.Reflection where
open import Prelude hiding (abs)
open import Prelude.Equality.Unsafe
open import Builtin.Float
open import Container.Traversable
open import Control.Monad.Zero
open import Agda.Builtin.Reflection as Builtin
open Builtin public
hiding ( primQNameEquality
; primQNameLess
; primShowQName
; primMetaEquality
; primMetaLess
; primShowMeta )
--- Names ---
instance
ShowName : Show Name
showsPrec {{ShowName}} _ x = showString (primShowQName x)
instance
EqName : Eq Name
_==_ {{EqName}} x y with primQNameEquality x y
... | true = yes unsafeEqual
... | false = no unsafeNotEqual
data LessName (x y : Name) : Set where
less-name : primQNameLess x y ≡ true → LessName x y
private
cmpName : ∀ x y → Comparison LessName x y
cmpName x y with inspect (primQNameLess x y)
... | true with≡ eq = less (less-name eq)
... | false with≡ _ with inspect (primQNameLess y x)
... | true with≡ eq = greater (less-name eq)
... | false with≡ _ = equal unsafeEqual
instance
OrdName : Ord Name
OrdName = defaultOrd cmpName
OrdLawsName : Ord/Laws Name
Ord/Laws.super OrdLawsName = it
less-antirefl {{OrdLawsName}} (less-name eq) = unsafeNotEqual eq
less-trans {{OrdLawsName}} (less-name _) (less-name _) = less-name unsafeEqual
--- Meta variables ---
instance
ShowMeta : Show Meta
showsPrec {{ShowMeta}} _ x = showString (primShowMeta x)
instance
EqMeta : Eq Meta
_==_ {{EqMeta}} x y with primMetaEquality x y
... | true = yes unsafeEqual
... | false = no unsafeNotEqual
data LessMeta (x y : Meta) : Set where
less-meta : primMetaLess x y ≡ true → LessMeta x y
private
cmpMeta : ∀ x y → Comparison LessMeta x y
cmpMeta x y with inspect (primMetaLess x y)
... | true with≡ eq = less (less-meta eq)
... | false with≡ _ with inspect (primMetaLess y x)
... | true with≡ eq = greater (less-meta eq)
... | false with≡ _ = equal unsafeEqual
instance
OrdMeta : Ord Meta
OrdMeta = defaultOrd cmpMeta
OrdLawsMeta : Ord/Laws Meta
Ord/Laws.super OrdLawsMeta = it
less-antirefl {{OrdLawsMeta}} (less-meta eq) = unsafeNotEqual eq
less-trans {{OrdLawsMeta}} (less-meta _) (less-meta _) = less-meta unsafeEqual
--- Literals ---
instance
ShowLiteral : Show Literal
showsPrec {{ShowLiteral}} _ (nat n) = shows n
showsPrec {{ShowLiteral}} _ (word64 n) = shows n
showsPrec {{ShowLiteral}} _ (float x) = shows x
showsPrec {{ShowLiteral}} _ (char c) = shows c
showsPrec {{ShowLiteral}} _ (string s) = shows s
showsPrec {{ShowLiteral}} _ (name x) = shows x
showsPrec {{ShowLiteral}} _ (meta x) = shows x
--- Terms ---
pattern vArg x = arg (arg-info visible relevant) x
pattern hArg x = arg (arg-info hidden relevant) x
pattern iArg x = arg (arg-info instance′ relevant) x
unArg : ∀ {A} → Arg A → A
unArg (arg _ x) = x
getArgInfo : ∀ {A} → Arg A → ArgInfo
getArgInfo (arg i _) = i
getVisibility : ∀ {A} → Arg A → Visibility
getVisibility (arg (arg-info v _) _) = v
getRelevance : ∀ {A} → Arg A → Relevance
getRelevance (arg (arg-info _ r) _) = r
isVisible : ∀ {A} → Arg A → Bool
isVisible (arg (arg-info visible _) _) = true
isVisible _ = false
instance
FunctorArg : Functor Arg
fmap {{FunctorArg}} f (arg i x) = arg i (f x)
TraversableArg : Traversable Arg
traverse {{TraversableArg}} f (arg i x) = ⦇ (arg i) (f x) ⦈
unAbs : ∀ {A} → Abs A → A
unAbs (abs _ x) = x
instance
FunctorAbs : Functor Abs
fmap {{FunctorAbs}} f (abs s x) = abs s (f x)
TraversableAbs : Traversable Abs
traverse {{TraversableAbs}} f (abs s x) = ⦇ (abs s) (f x) ⦈
absurd-lam : Term
absurd-lam = pat-lam (absurd-clause (vArg absurd ∷ []) ∷ []) []
--- TC monad ---
mapTC : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → TC A → TC B
mapTC f m = bindTC m λ x → returnTC (f x)
instance
FunctorTC : ∀ {a} → Functor {a} TC
fmap {{FunctorTC}} = mapTC
ApplicativeTC : ∀ {a} → Applicative {a} TC
pure {{ApplicativeTC}} = returnTC
_<*>_ {{ApplicativeTC}} = monadAp bindTC
MonadTC : ∀ {a} → Monad {a} TC
_>>=_ {{MonadTC}} = bindTC
FunctorTC′ : ∀ {a b} → Functor′ {a} {b} TC
fmap′ {{FunctorTC′}} = mapTC
ApplicativeTC′ : ∀ {a b} → Applicative′ {a} {b} TC
_<*>′_ {{ApplicativeTC′}} = monadAp′ bindTC
MonadTC′ : ∀ {a b} → Monad′ {a} {b} TC
_>>=′_ {{MonadTC′}} = bindTC
FunctorZeroTC : ∀ {a} → FunctorZero {a} TC
empty {{FunctorZeroTC}} = typeError []
AlternativeTC : ∀ {a} → Alternative {a} TC
_<|>_ {{AlternativeTC}} = catchTC
Tactic = Term → TC ⊤
give : Term → Tactic
give v = λ hole → unify hole v
define : Arg Name → Type → List Clause → TC ⊤
define f a cs = declareDef f a >> defineFun (unArg f) cs
newMeta : Type → TC Term
newMeta = checkType unknown
newMeta! : TC Term
newMeta! = newMeta unknown
typeErrorS : ∀ {a} {A : Set a} → String → TC A
typeErrorS s = typeError (strErr s ∷ [])
blockOnMeta! : ∀ {a} {A : Set a} → Meta → TC A
blockOnMeta! x = commitTC >>=′ λ _ → blockOnMeta x
inferNormalisedType : Term → TC Type
inferNormalisedType t = withNormalisation true (inferType t)
--- Convenient wrappers ---
-- Zero for non-datatypes
getParameters : Name → TC Nat
getParameters d =
caseM getDefinition d of λ
{ (data-type n _) → pure n
; _ → pure 0 }
getConstructors : Name → TC (List Name)
getConstructors d =
caseM getDefinition d of λ
{ (data-type _ cs) → pure cs
; (record-type c _) → pure (c ∷ [])
; _ → typeError (strErr "Cannot get constructors of non-data or record type" ∷ nameErr d ∷ [])
}
getClauses : Name → TC (List Clause)
getClauses d =
caseM getDefinition d of λ
{ (function cs) → pure cs
; _ → typeError (strErr "Cannot get constructors of non-function type" ∷ nameErr d ∷ [])
}
-- Get the constructor of a record type (or single-constructor data type)
recordConstructor : Name → TC Name
recordConstructor r =
caseM getConstructors r of λ
{ (c ∷ []) → pure c
; _ → typeError $ strErr "Cannot get constructor of non-record type" ∷ nameErr r ∷ [] }
-- Injectivity of constructors
arg-inj₁ : ∀ {A i i′} {x x′ : A} → arg i x ≡ arg i′ x′ → i ≡ i′
arg-inj₁ refl = refl
arg-inj₂ : ∀ {A i i′} {x x′ : A} → arg i x ≡ arg i′ x′ → x ≡ x′
arg-inj₂ refl = refl
arg-info-inj₁ : ∀ {v v′ r r′} → arg-info v r ≡ arg-info v′ r′ → v ≡ v′
arg-info-inj₁ refl = refl
arg-info-inj₂ : ∀ {v v′ r r′} → arg-info v r ≡ arg-info v′ r′ → r ≡ r′
arg-info-inj₂ refl = refl
abs-inj₁ : ∀ {A s s′} {x x′ : A} → abs s x ≡ abs s′ x′ → s ≡ s′
abs-inj₁ refl = refl
abs-inj₂ : ∀ {A s s′} {x x′ : A} → abs s x ≡ abs s′ x′ → x ≡ x′
abs-inj₂ refl = refl
--- Terms ---
var-inj₁ : ∀ {x x′ args args′} → Term.var x args ≡ var x′ args′ → x ≡ x′
var-inj₁ refl = refl
var-inj₂ : ∀ {x x′ args args′} → Term.var x args ≡ var x′ args′ → args ≡ args′
var-inj₂ refl = refl
con-inj₁ : ∀ {c c′ args args′} → Term.con c args ≡ con c′ args′ → c ≡ c′
con-inj₁ refl = refl
con-inj₂ : ∀ {c c′ args args′} → Term.con c args ≡ con c′ args′ → args ≡ args′
con-inj₂ refl = refl
def-inj₁ : ∀ {f f′ args args′} → def f args ≡ def f′ args′ → f ≡ f′
def-inj₁ refl = refl
def-inj₂ : ∀ {f f′ args args′} → def f args ≡ def f′ args′ → args ≡ args′
def-inj₂ refl = refl
meta-inj₁ : ∀ {f f′ args args′} → Term.meta f args ≡ meta f′ args′ → f ≡ f′
meta-inj₁ refl = refl
meta-inj₂ : ∀ {f f′ args args′} → Term.meta f args ≡ meta f′ args′ → args ≡ args′
meta-inj₂ refl = refl
lam-inj₁ : ∀ {v v′ t t′} → lam v t ≡ lam v′ t′ → v ≡ v′
lam-inj₁ refl = refl
lam-inj₂ : ∀ {v v′ t t′} → lam v t ≡ lam v′ t′ → t ≡ t′
lam-inj₂ refl = refl
pat-lam-inj₁ : ∀ {v v′ t t′} → pat-lam v t ≡ pat-lam v′ t′ → v ≡ v′
pat-lam-inj₁ refl = refl
pat-lam-inj₂ : ∀ {v v′ t t′} → pat-lam v t ≡ pat-lam v′ t′ → t ≡ t′
pat-lam-inj₂ refl = refl
pi-inj₁ : ∀ {t₁ t₁′ t₂ t₂′} → pi t₁ t₂ ≡ pi t₁′ t₂′ → t₁ ≡ t₁′
pi-inj₁ refl = refl
pi-inj₂ : ∀ {t₁ t₁′ t₂ t₂′} → pi t₁ t₂ ≡ pi t₁′ t₂′ → t₂ ≡ t₂′
pi-inj₂ refl = refl
sort-inj : ∀ {x y} → agda-sort x ≡ agda-sort y → x ≡ y
sort-inj refl = refl
lit-inj : ∀ {x y} → Term.lit x ≡ lit y → x ≡ y
lit-inj refl = refl
--- Sorts ---
set-inj : ∀ {x y} → set x ≡ set y → x ≡ y
set-inj refl = refl
slit-inj : ∀ {x y} → Sort.lit x ≡ lit y → x ≡ y
slit-inj refl = refl
--- Patterns ---
pcon-inj₁ : ∀ {x y z w} → Pattern.con x y ≡ con z w → x ≡ z
pcon-inj₁ refl = refl
pcon-inj₂ : ∀ {x y z w} → Pattern.con x y ≡ con z w → y ≡ w
pcon-inj₂ refl = refl
pvar-inj : ∀ {x y} → Pattern.var x ≡ var y → x ≡ y
pvar-inj refl = refl
plit-inj : ∀ {x y} → Pattern.lit x ≡ lit y → x ≡ y
plit-inj refl = refl
proj-inj : ∀ {x y} → Pattern.proj x ≡ proj y → x ≡ y
proj-inj refl = refl
--- Clauses ---
clause-inj₁ : ∀ {x y z w} → clause x y ≡ clause z w → x ≡ z
clause-inj₁ refl = refl
clause-inj₂ : ∀ {x y z w} → clause x y ≡ clause z w → y ≡ w
clause-inj₂ refl = refl
absurd-clause-inj : ∀ {x y} → absurd-clause x ≡ absurd-clause y → x ≡ y
absurd-clause-inj refl = refl
--- Literals ---
nat-inj : ∀ {x y} → nat x ≡ nat y → x ≡ y
nat-inj refl = refl
word64-inj : ∀ {x y} → word64 x ≡ word64 y → x ≡ y
word64-inj refl = refl
float-inj : ∀ {x y} → float x ≡ float y → x ≡ y
float-inj refl = refl
char-inj : ∀ {x y} → char x ≡ char y → x ≡ y
char-inj refl = refl
string-inj : ∀ {x y} → string x ≡ string y → x ≡ y
string-inj refl = refl
name-inj : ∀ {x y} → name x ≡ name y → x ≡ y
name-inj refl = refl
meta-inj : ∀ {x y} → Literal.meta x ≡ meta y → x ≡ y
meta-inj refl = refl
|
{
"alphanum_fraction": 0.6117847267,
"avg_line_length": 26.8628571429,
"ext": "agda",
"hexsha": "d483be0e226f8ff5c93ab3131ca6fb43a17ab366",
"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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Builtin/Reflection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"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": "lclem/agda-prelude",
"max_issues_repo_path": "src/Builtin/Reflection.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Builtin/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3486,
"size": 9402
}
|
-- Strict A is a datatype isomorphic to A, with constructor ! : A → Strict A
-- Semantically it has no impact, but its constructor is strict, so it can be
-- used to force evaluation of a term to whnf by pattern-matching.
open import Data.Strict.Primitive using ()
module Data.Strict where
open Data.Strict.Primitive public using ( Strict ; ! )
|
{
"alphanum_fraction": 0.7421203438,
"avg_line_length": 31.7272727273,
"ext": "agda",
"hexsha": "9612e898c001779bef684f0b8c2d8dca2ba6f20b",
"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/Data/Strict.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/Data/Strict.agda",
"max_line_length": 77,
"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/Data/Strict.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": 80,
"size": 349
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Container.Relation.Unary.Any directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Data.Container.Any where
open import Data.Container.Relation.Unary.Any public
open import Data.Container.Relation.Unary.Any.Properties public
|
{
"alphanum_fraction": 0.5267665953,
"avg_line_length": 33.3571428571,
"ext": "agda",
"hexsha": "14aafe9c87918d4bd703ea224cc775c198add5cc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Any.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/Container/Any.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Any.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": 73,
"size": 467
}
|
{-# OPTIONS --without-K #-}
module Invertibility where
open import Size
open import Codata.Delay renaming (length to dlength ; map to dmap )
open import Codata.Thunk using (Thunk ; force)
open import Relation.Binary.PropositionalEquality
open import Data.Vec.Relation.Unary.All using (All ; [] ; _∷_)
open import Data.Product
open import Syntax
open import Value
open import Definitional
open import Data.List using (List ; [] ; _∷_ ; length)
open import Data.Vec using ([] ; _∷_)
open import Level renaming (zero to lzero ; suc to lsuc)
open import Function using () renaming (case_of_ to CASE_OF_)
open import Relation.Nullary
open import Data.Empty
open import PInj
open _⊢F_⇔_
-- m ⟶ v states that computation of m terminates in v, which is
-- suitable for structural induction more than ⇓.
data _⟶_ : {A : Set} (m : DELAY A ∞) (v : A) -> Set₁ where
now⟶ : ∀ {A : Set} (v : A) -> Now v ⟶ v
later⟶ : ∀ {A : Set} {x : Thunk (DELAY A) ∞} -> ∀ (v : A)
-> (ev : force x ⟶ v)
-> Later x ⟶ v
bind⟶ :
∀ {A B : Set} {m : DELAY A ∞} {f : A -> DELAY B ∞} (u : A) (v : B)
-> m ⟶ u
-> f u ⟶ v
-> Bind m f ⟶ v
-- We will check that m ⟶ v conincides with the termination of thawed
-- computation (d : runD m ⇓) that results in v (that is, extract d ≡
-- v).
module _ where
open import Data.Nat
open import Data.Nat.Properties
private
-- It is unclear that we can prove the statement ⇓-⟶ by the
-- indunction on m⇓, as it is not immediately clear that m⇓ does
-- not involve infinite number of binds. So, we base ourselves on
-- the number of 'later' and prove that the descruction of "bind"
-- cannot increase the number ('lemma', below).
-- steps
len : ∀ {A : Set} {m : Delay A ∞} -> m ⇓ -> ℕ
len (now _) = ℕ.zero
len (later x) = ℕ.suc (len x)
-- Destruction cannot increase "steps"
lemma :
∀ {A B : Set} -> (m : Delay A ∞) (f : A -> Delay B ∞)
-> (mf⇓ : bind m f ⇓) -> Σ (m ⇓) λ m⇓ → Σ (f (extract m⇓) ⇓) λ fu⇓ -> (extract mf⇓ ≡ extract fu⇓ × len m⇓ ≤ len mf⇓ × len fu⇓ ≤ len mf⇓)
lemma (now x) f bd = (now x) , bd , refl , z≤n , ≤-refl
lemma (later x) f (later bd) with lemma (force x) f bd
... | m⇓ , f⇓ , eq , rel₁ , rel₂ = later m⇓ , f⇓ , eq , s≤s rel₁ , ≤-step rel₂
-- A generalized statement for induction.
aux : ∀ {A : Set} n -> (m : DELAY A ∞) -> (m⇓ : runD m ⇓) -> len m⇓ ≤ n -> m ⟶ extract m⇓
aux n (Now x) (now .x) ctr = now⟶ x
aux zero (Later x) (later m⇓) ()
aux (suc n) (Later x) (later m⇓) (s≤s ctr) = later⟶ _ (aux n (force x) m⇓ ctr)
aux n (Bind m f) mf⇓ ctr with lemma (runD m) _ mf⇓
... | m⇓ , fu⇓ , eq , rel₁ , rel₂ with aux n m m⇓ (≤-trans rel₁ ctr)
... | m⟶u with aux n (f (extract m⇓)) fu⇓ (≤-trans rel₂ ctr)
... | fu⟶v rewrite eq = bind⟶ {m = m} {f} (extract m⇓) (extract fu⇓) m⟶u fu⟶v
⇓-⟶ : ∀ {A : Set} (m : DELAY A ∞) -> (m⇓ : runD m ⇓) -> m ⟶ extract m⇓
⇓-⟶ m m⇓ = aux (len m⇓) m m⇓ (≤-refl)
-- In contrast, the opposite direction is straightforward, thanks to
-- the frozen bind.
⟶-⇓ : ∀ {A : Set} (m : DELAY A ∞) (v : A)
-> m ⟶ v -> Σ[ m⇓ ∈ runD m ⇓ ] (extract m⇓ ≡ v)
⟶-⇓ .(Now v) v (now⟶ .v) = now v , refl
⟶-⇓ .(Later _) v (later⟶ .v m⟶v) with ⟶-⇓ _ v m⟶v
... | m⇓ , refl = later m⇓ , refl
⟶-⇓ .(Bind m f) v (bind⟶ {m = m} {f} u .v m⟶u fu⟶v)
with ⟶-⇓ _ u m⟶u | ⟶-⇓ _ v fu⟶v
... | m⇓ , refl | fu⇓ , refl = bind-⇓ m⇓ fu⇓ , lemma m⇓ fu⇓
where
lemma :
∀ {ℓ} {A B : Set ℓ} {m : Delay A ∞} {f : A → Delay B ∞}
-> (m⇓ : m ⇓) -> (fu⇓ : f (extract m⇓) ⇓)
-> extract (bind-⇓ m⇓ {f = f} fu⇓) ≡ extract fu⇓
lemma (now a) fu⇓ = refl
lemma {f = f} (later m⇓) fu⇓ rewrite lemma {f = f} m⇓ fu⇓ = refl
-- Never does not terminate.
¬Never⟶ : ∀ {A : Set} {v : A} -> ¬ (Never ⟶ v)
¬Never⟶ (later⟶ _ x) = ¬Never⟶ x
-- A useful variant of now⟶
now⟶≡ : ∀ {A : Set} {v v' : A} -> v' ≡ v -> Now v' ⟶ v
now⟶≡ refl = now⟶ _
-- Several properties on value environments (for forward and backward
-- evaluations) and manipulations on them.
RValEnv-∅-canon : ∀ {Θ} (ρ : RValEnv Θ ∅) -> ρ ≡ emptyRValEnv
RValEnv-∅-canon {[]} [] = refl
RValEnv-∅-canon {x ∷ Θ} (skip ρ) = cong skip (RValEnv-∅-canon {Θ} ρ)
lkup-unlkup : ∀ {Θ A} {x : Θ ∋ A} {Ξ} -> (ok : varOk● Θ x Ξ) (ρ : RValEnv Θ Ξ) -> unlkup ok (lkup ok ρ) ≡ ρ
lkup-unlkup (there ok) (skip ρ) = cong skip (lkup-unlkup ok ρ)
lkup-unlkup (here ad) (x ∷ ρ) with all-zero-canon ad ρ
... | refl = refl
unlkup-lkup : ∀ {Θ A} {x : Θ ∋ A} {Ξ} -> (ok : varOk● Θ x Ξ) (v : Value [] ∅ A) -> lkup ok (unlkup ok v) ≡ v
unlkup-lkup (there ok) v = unlkup-lkup ok v
unlkup-lkup (here ad) v = refl
split-merge :
∀ {Θ Ξ₁ Ξ₂}
-> (ano : all-no-omega (Ξ₁ +ₘ Ξ₂))
-> ∀ (ρ : RValEnv Θ (Ξ₁ +ₘ Ξ₂))
-> mergeRValEnv ano (proj₁ (splitRValEnv ρ)) (proj₂ (splitRValEnv ρ)) ≡ ρ
split-merge {[]} {[]} {[]} ano [] = refl
split-merge {x ∷ Θ} {Multiplicity₀.zero ∷ Ξ₁} {Multiplicity₀.zero ∷ Ξ₂} (px ∷ ano) (skip ρ)
rewrite split-merge {Θ} {Ξ₁} {Ξ₂} ano ρ = refl
split-merge {x ∷ Θ} {Multiplicity₀.zero ∷ Ξ₁} {one ∷ Ξ₂} (px ∷ ano) (v ∷ ρ)
rewrite split-merge {Θ} {Ξ₁} {Ξ₂} ano ρ = refl
split-merge {x ∷ Θ} {one ∷ Ξ₁} {Multiplicity₀.zero ∷ Ξ₂} (px ∷ ano) (v ∷ ρ)
rewrite split-merge {Θ} {Ξ₁} {Ξ₂} ano ρ = refl
merge-split :
∀ {Θ Ξ₁ Ξ₂}
-> (ano : all-no-omega (Ξ₁ +ₘ Ξ₂))
-> (ρ₁ : RValEnv Θ Ξ₁)
-> (ρ₂ : RValEnv Θ Ξ₂)
-> splitRValEnv (mergeRValEnv ano ρ₁ ρ₂) ≡ (ρ₁ , ρ₂)
merge-split {[]} {[]} {[]} ano [] [] = refl
merge-split {x ∷ Θ} {zero ∷ Ξ₁} {zero ∷ Ξ₂} (px ∷ ano) (skip ρ₁) (skip ρ₂) rewrite merge-split ano ρ₁ ρ₂ = refl
merge-split {x ∷ Θ} {zero ∷ Ξ₁} {one ∷ Ξ₂} (px ∷ ano) (skip ρ₁) (v ∷ ρ₂) rewrite merge-split ano ρ₁ ρ₂ = refl
merge-split {x ∷ Θ} {one ∷ Ξ₁} {zero ∷ Ξ₂} (_ ∷ ano) (v ∷ ρ₁) (skip ρ₂) rewrite merge-split ano ρ₁ ρ₂ = refl
merge-split {x ∷ Θ} {one ∷ Ξ₁} {one ∷ Ξ₂} (() ∷ ano) ρ₁ ρ₂
-- Round-trip properties (corresponding to Lemma 3.3 in the paper)
forward-backward :
∀ {Θ Ξ A}
-> (ano : all-no-omega Ξ)
-> (E : Residual Θ Ξ (A ●))
-> let h = evalR ∞ ano E
in ∀ ρ v -> Forward h ρ ⟶ v -> Backward h v ⟶ ρ
forward-backward ano unit● ρ v fwd with RValEnv-∅-canon ρ
... | refl = now⟶ emptyRValEnv
forward-backward ano (letunit● E E₁) ρ v fwd with all-no-omega-dist _ _ ano
forward-backward ano (letunit● E E₁) ρ v (bind⟶ (unit refl) .v fwd fwd₁) | ano₁ , ano₂ =
let bwd = forward-backward ano₁ E _ _ fwd
bwd₁ = forward-backward ano₂ E₁ _ _ fwd₁
in bind⟶ _ _ bwd₁ (bind⟶ _ _ bwd (now⟶≡ (split-merge ano ρ)))
forward-backward ano (pair● E₁ E₂) ρ (pair {Ξ₁ = []} {[]} spΞ v₁ v₂) fwd with all-no-omega-dist _ _ ano
forward-backward ano (pair● E₁ E₂) ρ (pair {_} {[]} {[]} spΞ v₁ v₂) (bind⟶ _ _ fwd₁ (bind⟶ _ _ fwd₂ (now⟶ _))) | ano₁ , ano₂ =
let bwd₁ = forward-backward ano₁ E₁ _ _ fwd₁
bwd₂ = forward-backward ano₂ E₂ _ _ fwd₂
in bind⟶ _ _ bwd₁ (bind⟶ _ _ bwd₂ (now⟶≡ (split-merge ano ρ)))
forward-backward ano (letpair● E E₁) ρ v fwd
with all-no-omega-dist _ _ ano
forward-backward ano (letpair● E E₁) ρ v (bind⟶ (pair {Ξ₁ = []} {[]} refl v₁ v₂) .v fwd fwd₁) | ano₁ , ano₂ =
let bwd = forward-backward ano₁ E _ _ fwd
bwd₁ = forward-backward (one ∷ one ∷ ano₂) E₁ _ _ fwd₁
in bind⟶ _ _ bwd₁ (bind⟶ _ _ bwd (now⟶≡ (split-merge ano ρ)))
forward-backward ano (inl● E) ρ _ (bind⟶ u _ fwd (now⟶ _)) = forward-backward ano E _ _ fwd
forward-backward ano (inr● E) ρ _ (bind⟶ u _ fwd (now⟶ _)) = forward-backward ano E _ _ fwd
forward-backward ano (case● E refl θ₁ t₁ θ₂ t₂ v₁) ρ v fwd
with all-no-omega-dist _ _ ano
forward-backward ano (case● E refl θ₁ t₁ θ₂ t₂ v₁) ρ v (bind⟶ (inl u) .v fwd (bind⟶ (red r₁) .v ev₁ (later⟶ .v (bind⟶ _ .v fwd₁ (bind⟶ (inl (unit refl)) .v ap (now⟶ _)))))) | ano₀ , ano- =
bind⟶ _ _ ap (
bind⟶ _ _ ev₁ (later⟶ _ (
bind⟶ _ _ (forward-backward (one ∷ ano-) r₁ _ _ fwd₁) (bind⟶ _ _ (forward-backward ano₀ E _ _ fwd) (now⟶≡ (split-merge ano ρ))))))
forward-backward ano (case● E refl θ₁ t₁ θ₂ t₂ v₁) ρ v (bind⟶ (inl u) .v fwd (bind⟶ (red r₁) .v ev₁ (later⟶ .v (bind⟶ u₁ .v fwd₁ (bind⟶ (inr (unit refl)) .v ap nev))))) | ano₀ , ano- = ⊥-elim (¬Never⟶ nev)
forward-backward ano (case● E refl θ₁ t₁ θ₂ t₂ v₁) ρ v (bind⟶ (inr u) .v fwd (bind⟶ (red r₁) .v ev₁ (later⟶ .v (bind⟶ u₁ .v fwd₁ (bind⟶ (inl (unit refl)) .v ap nev))))) | ano₀ , ano- = ⊥-elim (¬Never⟶ nev)
forward-backward ano (case● E refl θ₁ t₁ θ₂ t₂ v₁) ρ v (bind⟶ (inr u) .v fwd (bind⟶ (red r₁) .v ev₁ (later⟶ .v (bind⟶ _ .v fwd₁ (bind⟶ (inr (unit refl)) .v ap (now⟶ _)))))) | ano₀ , ano- =
bind⟶ _ _ ap (
bind⟶ _ _ ev₁ (later⟶ _ (
bind⟶ _ _ (forward-backward (one ∷ ano-) r₁ _ _ fwd₁) (bind⟶ _ _ (forward-backward ano₀ E _ _ fwd) (now⟶≡ (split-merge ano ρ))))))
forward-backward ano (var● x ok) ρ .(lkup ok ρ) (now⟶ _) rewrite lkup-unlkup ok ρ = now⟶ ρ
forward-backward ano (pin E (clo .omega refl θ t)) ρ (pair {Ξ₁ = []} {[]} refl v₁ v₂) fwd
with all-no-omega-dist _ _ ano
forward-backward ano (pin E (clo .omega refl θ t)) ρ (pair {_} {[]} {[]} refl v₁ v₂)
(bind⟶ _ _ fwd (later⟶ _ (bind⟶ (red r) _ ev (bind⟶ _ _ fwd₂ (now⟶ _))))) | ano₁ , ano₂ =
later⟶ ρ (bind⟶ _ _ ev
(bind⟶ _ ρ (forward-backward ano₂ r _ _ fwd₂)
(bind⟶ _ _ (forward-backward ano₁ E _ _ fwd) (now⟶≡ (split-merge ano ρ)))))
backward-forward :
∀ {Θ Ξ A}
-> (ano : all-no-omega Ξ)
-> (E : Residual Θ Ξ (A ●))
-> let h = evalR ∞ ano E
in ∀ ρ v -> Backward h v ⟶ ρ -> Forward h ρ ⟶ v
backward-forward ano unit● ρ (unit refl) bwd = now⟶ (unit refl)
backward-forward ano (letunit● E E₁) ρ v (bind⟶ ρ₂ _ bwd₂ (bind⟶ ρ₁ _ bwd₁ (now⟶ _))) with all-no-omega-dist _ _ ano
... | ano₁ , ano₂ rewrite merge-split ano ρ₁ ρ₂ =
bind⟶ _ _ (backward-forward ano₁ E _ _ bwd₁) (backward-forward ano₂ E₁ _ _ bwd₂)
backward-forward ano (pair● E₁ E₂) ρ (pair {Ξ₁ = []} {[]} refl v₁ v₂) (bind⟶ ρ₁ _ bwd₁ (bind⟶ ρ₂ _ bwd₂ (now⟶ _)))
with all-no-omega-dist _ _ ano
... | ano₁ , ano₂ rewrite merge-split ano ρ₁ ρ₂ =
bind⟶ _ _ (backward-forward ano₁ E₁ _ _ bwd₁) (bind⟶ _ _ (backward-forward ano₂ E₂ _ _ bwd₂) (now⟶ (pair refl v₁ v₂)))
backward-forward ano (letpair● E E₁) ρ v (bind⟶ (v₁ ∷ v₂ ∷ ρ₂) _ bwd₂ (bind⟶ ρ₁ _ bwd₁ (now⟶ _)))
with all-no-omega-dist _ _ ano
... | ano₁ , ano₂ rewrite merge-split ano ρ₁ ρ₂ =
bind⟶ _ _ (backward-forward ano₁ E _ _ bwd₁) (backward-forward (one ∷ one ∷ ano₂) E₁ _ _ bwd₂)
backward-forward ano (inl● E) ρ (inl v) bwd = bind⟶ _ _ (backward-forward ano E ρ v bwd) (now⟶ (inl v))
backward-forward ano (inl● E) ρ (inr v) bwd = ⊥-elim (¬Never⟶ bwd)
backward-forward ano (inr● E) ρ (inl v) bwd = ⊥-elim (¬Never⟶ bwd)
backward-forward ano (inr● E) ρ (inr v) bwd = bind⟶ _ _ (backward-forward ano E ρ v bwd) (now⟶ (inr v))
backward-forward
ano (case● E refl θ₁ t₁ θ₂ t₂ ϕ) ρ v
(bind⟶ u _ ap bwd)
with all-no-omega-dist _ _ ano
backward-forward
ano (case● E refl θ₁ t₁ θ₂ t₂ ϕ) ρ v
(bind⟶ (inl u) .ρ ap (bind⟶ (red r) _ ev (later⟶ _ (bind⟶ (v₁ ∷ ρ-) _ bwd- (bind⟶ ρ₀ _ bwd₀ (now⟶ _)))))) | ano₀ , ano- rewrite merge-split ano ρ₀ ρ- =
bind⟶ _ _ (backward-forward ano₀ E _ _ bwd₀)
(bind⟶ _ _ ev (later⟶ _
(bind⟶ _ _ (backward-forward (one ∷ ano-) r _ _ bwd-)
(bind⟶ _ _ ap (now⟶ v)))))
backward-forward
ano (case● E refl θ₁ t₁ θ₂ t₂ ϕ) ρ v
(bind⟶ (inr u) .ρ ap (bind⟶ (red r) _ ev (later⟶ _ (bind⟶ (v₁ ∷ ρ-) _ bwd- (bind⟶ ρ₀ _ bwd₀ (now⟶ _)))))) | ano₀ , ano- rewrite merge-split ano ρ₀ ρ- =
bind⟶ _ _ (backward-forward ano₀ E _ _ bwd₀)
(bind⟶ _ _ ev (later⟶ _
(bind⟶ _ _ (backward-forward (one ∷ ano-) r _ _ bwd-)
(bind⟶ _ _ ap (now⟶ v)))))
backward-forward ano (var● x ok) .(unlkup ok v) v (now⟶ _) rewrite unlkup-lkup ok v = now⟶ v
backward-forward ano (pin E (clo .omega refl θ t)) ρ (pair {_} {[]} {[]} refl v₁ v₂)
(later⟶ _ (bind⟶ (red r) _ ev (bind⟶ ρ₂ _ bwd₂ (bind⟶ ρ₁ _ bwd₁ (now⟶ _)))))
with all-no-omega-dist _ _ ano
... | ano₁ , ano₂ rewrite merge-split ano ρ₁ ρ₂ =
bind⟶ _ _ (backward-forward ano₁ E _ _ bwd₁)
(later⟶ _ (bind⟶ _ _ ev (bind⟶ _ _ (backward-forward ano₂ r _ _ bwd₂) (now⟶ (pair refl v₁ v₂)))))
|
{
"alphanum_fraction": 0.5770653514,
"avg_line_length": 46.2547528517,
"ext": "agda",
"hexsha": "9cc4bba730b5319fc40267a68f1e4da9e17a2c18",
"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": "e2fb3a669e733a9020a51b24244d89abd8fcf725",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "kztk-m/sparcl-agda",
"max_forks_repo_path": "Invertibility.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725",
"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": "kztk-m/sparcl-agda",
"max_issues_repo_path": "Invertibility.agda",
"max_line_length": 205,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "kztk-m/sparcl-agda",
"max_stars_repo_path": "Invertibility.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5346,
"size": 12165
}
|
module Issue628 where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN SUC suc #-}
{-# BUILTIN ZERO zero #-}
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
data ⊥ : Set where
0≢1+n : ∀ {n} -> 0 ≡ suc n → ⊥
0≢1+n ()
divSucAux : (k m n j : ℕ) -> ℕ
divSucAux k m zero j = k
divSucAux k m (suc n) zero = divSucAux (suc k) m n m
divSucAux k m (suc n) (suc j) = divSucAux k m n j
{-# BUILTIN NATDIVSUCAUX divSucAux #-}
oh-noes : ⊥
oh-noes = 0≢1+n {divSucAux 0 0 0 1} refl
|
{
"alphanum_fraction": 0.5694980695,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "a4c00731ba194e6485718d16b645b32b6ae2214c",
"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/Issue628.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/Issue628.agda",
"max_line_length": 52,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "np/agda-git-experiment",
"max_stars_repo_path": "test/fail/Issue628.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": 224,
"size": 518
}
|
open import IO using ( _>>_ ; putStr ; run )
module System.IO.Examples.HelloRaw where
main = run (putStr "Hello, World\n")
|
{
"alphanum_fraction": 0.696,
"avg_line_length": 20.8333333333,
"ext": "agda",
"hexsha": "f192c8fc792a80fe8410e4a25e6d1f70fdfdb4d7",
"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/Examples/HelloRaw.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/Examples/HelloRaw.agda",
"max_line_length": 44,
"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/Examples/HelloRaw.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": 36,
"size": 125
}
|
module Examples.DivergingContext where
open import Prelude
data TC : Set where
tc-int : TC
tc-bool : TC
_tc≟_ : (a b : TC) → Dec (a ≡ b)
tc-int tc≟ tc-int = yes refl
tc-int tc≟ tc-bool = no (λ ())
tc-bool tc≟ tc-int = no (λ ())
tc-bool tc≟ tc-bool = yes refl
open import Implicits.Oliveira.Types TC _tc≟_
open import Implicits.Oliveira.Terms TC _tc≟_
open import Implicits.Oliveira.Contexts TC _tc≟_
open import Implicits.Oliveira.WellTyped TC _tc≟_
open import Implicits.Oliveira.Substitutions TC _tc≟_
open import Implicits.Oliveira.Types.Unification TC _tc≟_
open import Implicits.Improved.Infinite.Resolution TC _tc≟_
open import Data.Maybe
open import Data.List
open import Coinduction
open import Data.List.Any.Membership using (map-mono)
open import Data.List.Any
open Membership-≡
Int : ∀ {ν} → Type ν
Int = simpl (tc tc-int)
module Ex₁ where
r : Type zero
r = (∀' (((simpl (x →' x)) ⇒ (simpl (x →' (simpl (x →' x))))) ⇒ x))
where
x = (simpl (tvar zero))
Δ : ICtx zero
Δ = r ∷ []
-- Exploiting coinductive definition here to show that there is an infinite derivation
-- of any type under the context Δ with the special characteristic that the context grows to
-- infinity as well!
--
-- This may not be immediately obvious, but it can be seen by exploring the first argument of 'p'
-- in the recursive calls, denoting the growing context.
-- Also note that the element added to the context won't ever match the goal.
-- This is not proven here, but an argument for it is made in the form of ¬r↓goal
p : ∀ Δ' a → Δ ⊆ Δ' → Δ' ⊢ᵣ simpl a
p Δ' a f = r-simp (f (here refl))
(i-tabs
(simpl a)
(i-iabs (♯ r-iabs (p (new-r ∷ Δ') new-goal (λ x → there (f x)))) (i-simp a)))
where
new-r = simpl (simpl a →' simpl a)
new-goal = (simpl a →' simpl (simpl a →' simpl a))
¬r↓goal : ¬ (new-r ∷ Δ') ⊢ new-r ↓ new-goal
¬r↓goal ()
|
{
"alphanum_fraction": 0.6590198123,
"avg_line_length": 31.4426229508,
"ext": "agda",
"hexsha": "e984678764c646bfa4550525d9d88909b22a1eeb",
"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/Examples/DivergingContext.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/Examples/DivergingContext.agda",
"max_line_length": 99,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Examples/DivergingContext.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 627,
"size": 1918
}
|
-- Andreas, 2016-06-08
-- Better error message when case splitting is invoked in location
-- where there is nothing to split
record R : Set where
field f : {!!}
-- C-c C-c RET here gives:
-- Cannot split here, as we are not in a function definition
|
{
"alphanum_fraction": 0.7035573123,
"avg_line_length": 25.3,
"ext": "agda",
"hexsha": "ad35e82af92e5585dafca5872f6d233a5f085410",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue289r.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue289r.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue289r.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": 66,
"size": 253
}
|
module Numeral.Natural.Proofs where
import Lvl
open import Numeral.Natural
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function
open import Structure.Function.Domain
private variable n : ℕ
[𝐒]-not-0 : (𝐒(n) ≢ 𝟎)
[𝐒]-not-0 ()
𝐒-not-self : (𝐒(n) ≢ n)
𝐒-not-self ()
instance
[𝐒]-injectivity : Injective(𝐒)
Injective.proof([𝐒]-injectivity) = congruence₁(𝐏)
instance
[𝐏][𝐒]-inverseᵣ : Inverseᵣ(𝐏)(𝐒)
[𝐏][𝐒]-inverseᵣ = intro [≡]-intro
|
{
"alphanum_fraction": 0.7090163934,
"avg_line_length": 19.52,
"ext": "agda",
"hexsha": "bc4f7d70eaa04db5f8314805671384ef69cf0386",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Proofs.agda",
"max_line_length": 51,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/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": 200,
"size": 488
}
|
open import Data.Graph
module Data.Graph.Path.Finite {ℓᵥ ℓₑ} (g : FiniteGraph ℓᵥ ℓₑ) where
open import Category.Monad
open import Data.Bool as Bool
open import Data.Graph.Path.Cut g hiding (_∈_)
open import Data.List as List hiding (_∷ʳ_)
open import Data.List.Any as Any
open import Data.List.Any.Properties
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties hiding (finite)
open import Data.List.Categorical as ListCat
open import Data.Nat using (ℕ; zero; suc; _≤_; z≤n; s≤s)
open import Data.Nat.Properties
open import Data.Product as Σ
open import Data.Unit using (⊤; tt)
open import Data.Sum as ⊎
open import Data.Vec as Vec using (Vec; []; _∷_)
import Level as ℓ
open import Finite
open import Function
open import Function.Equality using (Π)
open import Function.Equivalence using (Equivalence)
open import Function.Inverse using (Inverse)
open import Function.LeftInverse using (LeftInverse; leftInverse)
open import Relation.Binary
open import Relation.Binary.Construct.Closure.ReflexiveTransitive hiding (_>>=_)
open import Relation.Binary.PropositionalEquality as ≡
open import Relation.Binary.HeterogeneousEquality as ≅
open import Relation.Nullary hiding (module Dec)
open import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Negation
open Π using (_⟨$⟩_)
open Equivalence using (to; from)
open FiniteGraph g
open Inverse using (to; from)
open IsFinite
open RawMonad {ℓᵥ ℓ.⊔ ℓₑ} ListCat.monad
isubst : ∀ {ℓ₁ ℓ₂ ℓ₃} {I : Set ℓ₁}
(A : I → Set ℓ₂) (B : ∀ {k} → A k → Set ℓ₃)
{i j : I} {x : A i} {y : A j} →
i ≡ j → x ≅ y →
B x → B y
isubst A B refl refl = id
True-unique : ∀ {ℓ} {A : Set ℓ} (A? : Dec A) (x y : True A?) → x ≡ y
True-unique A? x y with A?
True-unique A? tt tt | yes a = refl
True-unique A? () y | no ¬a
True-unique-≅ : ∀
{ℓ₁ ℓ₂} {A : Set ℓ₁} {B : Set ℓ₂}
(A? : Dec A) (B? : Dec B)
(x : True A?) (y : True B?) →
x ≅ y
True-unique-≅ A? B? x y with A? | B?
True-unique-≅ A? B? tt tt | yes a | yes b = refl
True-unique-≅ A? B? x () | _ | no ¬b
True-unique-≅ A? B? () y | no ¬a | _
∃-≅ : ∀
{ℓ₁ ℓ₂} {A : Set ℓ₁} {P : A → Set ℓ₂}
{x y : A} {p : P x} {q : P y} →
x ≡ y → p ≅ q → (∃ P ∋ (x , p)) ≡ (y , q)
∃-≅ refl refl = refl
nexts : ∀ {a b n} → Path a b n → List (∃ λ b → Path a b (suc n))
nexts {a} {b} p = List.map (λ where (_ , e) → -, p ∷ʳ e) (elements (edgeFinite b))
∈-nexts : ∀ {a c n} →
(pf : IsFinite (∃ λ b → Path a b n)) →
(p : Path a c (suc n)) →
(c , p) ∈ (elements pf >>= (nexts ∘ proj₂))
∈-nexts pf p =
case unsnoc p of λ where
(_ , p′ , e′ , refl) →
to >>=-∈↔ ⟨$⟩
(-,
membership pf (-, p′) ,
∈-map⁺ (membership (edgeFinite _) (-, e′)))
Path-finite : ∀ n a → IsFinite (∃ λ b → Path a b n)
Path-finite zero a = finite List.[ -, [] ] λ where (_ , []) → here refl
Path-finite (suc n) a =
let pf = Path-finite n a in
finite (elements pf >>= (nexts ∘ proj₂)) (∈-nexts pf ∘ proj₂)
≤-top? : ∀ {x y} → x ≤ suc y → x ≤ y ⊎ x ≡ suc y
≤-top? z≤n = inj₁ z≤n
≤-top? {y = zero} (s≤s z≤n) = inj₂ refl
≤-top? {y = suc y} (s≤s p) =
case ≤-top? p of λ where
(inj₁ le) → inj₁ (s≤s le)
(inj₂ refl) → inj₂ refl
Path≤-finite : ∀ n a → IsFinite (∃ λ b → Path≤ a b n)
Path≤-finite zero a = finite List.[ -, -, z≤n , [] ] λ where (_ , _ , z≤n , []) → here refl
Path≤-finite (suc n) a =
let
finite xs elem = Path≤-finite n a
finite xs′ elem′ = Path-finite (suc n) a
in
finite
(List.map (Σ.map₂ (Σ.map₂ (Σ.map₁ ≤-step))) xs List.++
List.map (Σ.map₂ (_,_ (suc n) ∘ _,_ ≤-refl)) xs′)
λ where
(b , m , le , p) → case ≤-top? le of λ where
(inj₁ le′) →
to ++↔ ⟨$⟩
inj₁
(to map-∈↔ ⟨$⟩
(-, (elem (b , m , le′ , p)) ,
≡.cong (λ q → b , m , q , p) (≤-irrelevance le (≤-step le′))))
(inj₂ refl) →
to (++↔ {xs = List.map _ xs}) ⟨$⟩
inj₂
(to map-∈↔ ⟨$⟩
(-, elem′ (-, p) ,
≡.cong (λ q → b , m , q , p) (≤-irrelevance le (s≤s ≤-refl))))
AcyclicPath-finite : ∀ a → IsFinite (∃₂ λ b n → ∃ λ (p : Path a b n) → True (acyclic? p))
AcyclicPath-finite a =
via-left-inverse (IsFinite.filter (Path≤-finite (size vertexFinite) a) _) $
leftInverse
(λ where (b , n , p , acp) → (b , n , acyclic-length-≤ p (toWitness acp) , p) , acp)
(λ where ((b , n , le , p) , acp) → b , n , p , acp)
λ where _ → refl
AcyclicStar : Vertex → Vertex → Set _
AcyclicStar a b = ∃ λ (p : Star Edge a b) → True (acyclic? (fromStar p))
AcyclicStar-finite : ∀ a → IsFinite (∃ (AcyclicStar a))
AcyclicStar-finite a =
via-left-inverse (AcyclicPath-finite a) $
leftInverse
(λ where
(b , p , acp) →
b , starLength p , fromStar p , acp)
(λ where
(b , n , p , acp) →
b , toStar p ,
isubst (Path a b) (True ∘ acyclic?)
(starLength-toStar p) (fromStar-toStar p)
acp)
(λ where
(b , p , acp) →
≡.cong (b ,_) $
∃-≅
(≡.sym (toStar-fromStar p))
(True-unique-≅ _ _ _ _))
|
{
"alphanum_fraction": 0.5524744849,
"avg_line_length": 33.7207792208,
"ext": "agda",
"hexsha": "6f2f9866d0aa6beb9d7c83f31fc715ecbc648e3b",
"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": "0196cf8a136a4933cd6358e4c9692aaf919ca603",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kcsmnt0/graph",
"max_forks_repo_path": "src/Data/Graph/Path/Finite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603",
"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": "kcsmnt0/graph",
"max_issues_repo_path": "src/Data/Graph/Path/Finite.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kcsmnt0/graph",
"max_stars_repo_path": "src/Data/Graph/Path/Finite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1973,
"size": 5193
}
|
-- Andreas, AIM XXXV, 2022-05-09, issue #5728
-- Give a proper error rather than crashing.
test : Set
test with Set
...
-- This used to be an internal error.
-- Expected error now:
-- The right-hand side can only be omitted if there is an absurd
-- pattern, () or {}, in the left-hand side.
|
{
"alphanum_fraction": 0.6860068259,
"avg_line_length": 24.4166666667,
"ext": "agda",
"hexsha": "856a6a4ec40d3dd5fd5e24c9fe9ab49125909258",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/Issue5728.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/Issue5728.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue5728.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 79,
"size": 293
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import groups.Cokernel
open import groups.Exactness
open import groups.HomSequence
open import groups.ExactSequence
open import cw.CW
module cw.cohomology.TipGrid {i} (OT : OrdinaryTheory i)
(⊙skel : ⊙Skeleton {i} 1) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where
open OrdinaryTheory OT
open import cw.cohomology.Descending OT
open import cw.cohomology.WedgeOfCells OT ⊙skel
open import cw.cohomology.TipAndAugment OT (⊙cw-init ⊙skel)
open import cw.cohomology.TipCoboundary OT ⊙skel
import cohomology.LongExactSequence
{-
X₀ --> X₁
| |
v v
1 -> X₁/X₀
-}
private
module LES n = cohomology.LongExactSequence cohomology-theory n (⊙cw-incl-last ⊙skel)
Ker-cw-co∂-head' : C 0 ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker cw-co∂-head'
Ker-cw-co∂-head' = Exact2.G-trivial-implies-H-iso-ker
(exact-seq-index 2 $ LES.C-cofiber-exact-seq -1)
(exact-seq-index 0 $ LES.C-cofiber-exact-seq 0)
(CXₙ/Xₙ₋₁-<-is-trivial ltS ac)
{- NOT USED
Ker-cw-co∂-head : G ×ᴳ C 0 ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker cw-co∂-head
Ker-cw-co∂-head = lemma ∘eᴳ ×ᴳ-emap (idiso G) Ker-cw-co∂-head' where
lemma : G ×ᴳ Ker.grp cw-co∂-head' ≃ᴳ Ker.grp cw-co∂-head
lemma = group-hom (λ{(g , (h , is-ker)) → ((g , h) , is-ker)})
(λ _ _ → Subtype=-out (Ker.subEl-prop cw-co∂-head) idp) ,
is-eq _ (λ{((g , h) , is-ker) → (g , (h , is-ker))}) (λ _ → idp) (λ _ → idp)
-}
private
-- separate lemmas to speed up the type checking
abstract
lemma-exact₀ : is-exact (C-fmap 1 (⊙cfcod' (⊙cw-incl-last ⊙skel)))
(C-fmap 1 (⊙cw-incl-last ⊙skel))
lemma-exact₀ = exact-seq-index 2 $ LES.C-cofiber-exact-seq 0
lemma-trivial : is-trivialᴳ (C 1 (⊙cw-head ⊙skel))
lemma-trivial = CX₀-≠-is-trivial (pos-≠ (ℕ-S≠O 0))
(⊙init-has-cells-with-choice ⊙skel ac)
Coker-cw-co∂-head : CokerCo∂Head.grp ≃ᴳ C 1 ⊙⟦ ⊙skel ⟧
Coker-cw-co∂-head = Exact2.L-trivial-implies-coker-iso-K
co∂-head-incl-exact lemma-exact₀ CX₁/X₀-is-abelian lemma-trivial
|
{
"alphanum_fraction": 0.6596910812,
"avg_line_length": 32.3709677419,
"ext": "agda",
"hexsha": "9b8ee3a11543381c8989a7c2fd7623305a49b70d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/TipGrid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/TipGrid.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/TipGrid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 850,
"size": 2007
}
|
{-# OPTIONS --safe #-}
module Cubical.Homotopy.Loopspace where
open import Cubical.Core.Everything
open import Cubical.Data.Nat
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws
open import Cubical.HITs.SetTruncation
open import Cubical.HITs.Truncation hiding (elim2) renaming (rec to trRec)
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv.HalfAdjoint
open Iso
{- loop space of a pointed type -}
Ω : {ℓ : Level} → Pointed ℓ → Pointed ℓ
Ω (_ , a) = ((a ≡ a) , refl)
{- n-fold loop space of a pointed type -}
Ω^_ : ∀ {ℓ} → ℕ → Pointed ℓ → Pointed ℓ
(Ω^ 0) p = p
(Ω^ (suc n)) p = Ω ((Ω^ n) p)
{- homotopy Group -}
π : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Type ℓ
π n A = ∥ typ ((Ω^ n) A) ∥ 2
{- loop space map -}
Ω→ : ∀ {ℓA ℓB} {A : Pointed ℓA} {B : Pointed ℓB} (f : A →∙ B) → (Ω A →∙ Ω B)
Ω→ (f , f∙) = (λ p → (sym f∙ ∙ cong f p) ∙ f∙) , cong (λ q → q ∙ f∙) (sym (rUnit (sym f∙))) ∙ lCancel f∙
{- Commutativity of loop spaces -}
isComm∙ : ∀ {ℓ} (A : Pointed ℓ) → Type ℓ
isComm∙ A = (p q : typ (Ω A)) → p ∙ q ≡ q ∙ p
Eckmann-Hilton : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → isComm∙ ((Ω^ (suc n)) A)
Eckmann-Hilton n α β =
transport (λ i → cong (λ x → rUnit x (~ i)) α ∙ cong (λ x → lUnit x (~ i)) β
≡ cong (λ x → lUnit x (~ i)) β ∙ cong (λ x → rUnit x (~ i)) α)
λ i → (λ j → α (j ∧ ~ i) ∙ β (j ∧ i)) ∙ λ j → α (~ i ∨ j) ∙ β (i ∨ j)
isCommA→isCommTrunc : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → isComm∙ A
→ isOfHLevel (suc n) (typ A)
→ isComm∙ (∥ typ A ∥ (suc n) , ∣ pt A ∣)
isCommA→isCommTrunc {A = (A , a)} n comm hlev p q =
((λ i j → (leftInv (truncIdempotentIso (suc n) hlev) ((p ∙ q) j) (~ i)))
∙∙ (λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣) (cong (trRec hlev (λ x → x)) (p ∙ q)))
∙∙ (λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣) (congFunct {A = ∥ A ∥ (suc n)} {B = A} (trRec hlev (λ x → x)) p q i)))
∙ ((λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣) (comm (cong (trRec hlev (λ x → x)) p) (cong (trRec hlev (λ x → x)) q) i))
∙∙ (λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣) (congFunct {A = ∥ A ∥ (suc n)} {B = A} (trRec hlev (λ x → x)) q p (~ i)))
∙∙ (λ i j → (leftInv (truncIdempotentIso (suc n) hlev) ((q ∙ p) j) i)))
ptdIso→comm : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Type ℓ'} (e : Iso (typ A) B) → isComm∙ A → isComm∙ (B , fun e (pt A))
ptdIso→comm {A = (A , a)} {B = B} e comm p q =
sym (rightInv (congIso e) (p ∙ q))
∙∙ (cong (fun (congIso e)) ((invCongFunct e p q)
∙∙ (comm (inv (congIso e) p) (inv (congIso e) q))
∙∙ (sym (invCongFunct e q p))))
∙∙ rightInv (congIso e) (q ∙ p)
{- Homotopy group version -}
π-comp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → ∥ typ ((Ω^ (suc n)) A) ∥₂
→ ∥ typ ((Ω^ (suc n)) A) ∥₂ → ∥ typ ((Ω^ (suc n)) A) ∥₂
π-comp n = elim2 (λ _ _ → isSetSetTrunc) λ p q → ∣ p ∙ q ∣₂
Eckmann-Hilton-π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p q : ∥ typ ((Ω^ (2 + n)) A) ∥₂)
→ π-comp (1 + n) p q ≡ π-comp (1 + n) q p
Eckmann-Hilton-π n = elim2 (λ x y → isOfHLevelPath 2 isSetSetTrunc _ _)
λ p q → cong ∣_∣₂ (Eckmann-Hilton n p q)
|
{
"alphanum_fraction": 0.5077202543,
"avg_line_length": 44.6351351351,
"ext": "agda",
"hexsha": "29cfb40cad5b5df951155924e8f4dd1db2c7317b",
"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": "f2d74ae8e2e176963029a35bd886364480948214",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kl-i/cubical-0.3",
"max_forks_repo_path": "Cubical/Homotopy/Loopspace.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2d74ae8e2e176963029a35bd886364480948214",
"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": "kl-i/cubical-0.3",
"max_issues_repo_path": "Cubical/Homotopy/Loopspace.agda",
"max_line_length": 130,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f2d74ae8e2e176963029a35bd886364480948214",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kl-i/cubical-0.3",
"max_stars_repo_path": "Cubical/Homotopy/Loopspace.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1510,
"size": 3303
}
|
------------------------------------------------------------------------
-- Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
-- Author: Sandro Stucki
-- Copyright (c) 2017-2021 EPFL
-- The code in this repository contains an Agda mechanization of the
-- type system Fω extended with interval kinds ("F omega int"). An
-- interval kind `A..B' represents a type interval bounded by a pair
-- of types `A', `B'. It is inhabited by all proper types `C : A..B'
-- that are both supertypes of `A' and subtypes of `B'. Interval
-- kinds are flexible enough to express various features found in
-- other type systems, such as
--
-- * F-<:-style bounded polymorphism,
-- * bounded type operators,
-- * singleton kinds and first-class type definitions.
--
-- The mechanization includes a small-step operational call-by-value
-- semantics, declarative and canonical presentations of typing and
-- kinding, along with (syntactic) proofs of various meta-theoretic
-- properties, such as
--
-- * weak normalization of types (and kinds) via hereditary substitution,
-- * subject reduction for types (w.r.t. full β-reduction),
-- * type safety (progress & preservation) w.r.t. to the CBV semantics,
-- * undecidability of subtyping.
--
-- For more details on Fω with interval kinds, see my PhD thesis
-- "Higher-Order Subtyping with Type Intervals", which is available at
--
-- http://dx.doi.org/10.5075/epfl-thesis-8014
--
-- The code makes heavy use of the Agda standard library, which is
-- freely available at
--
-- https://github.com/agda/agda-stdlib/
--
-- The code has been tested using Agda 2.6.1.3 and version 1.6 of
-- the Agda standard library.
module README where
------------------------------------------------------------------------
-- Modules related to Fω with interval kinds.
-- Syntax of (untyped) terms along with support for substitutions,
-- (untyped) hereditary substitutions and normalization.
open import FOmegaInt.Syntax
open import FOmegaInt.Syntax.SingleVariableSubstitution
open import FOmegaInt.Syntax.HereditarySubstitution
open import FOmegaInt.Syntax.Normalization
-- Weak equality of (untyped) terms up to kind annotations in
-- abstractions.
open import FOmegaInt.Syntax.WeakEquality
-- Variants of β-reduction/equivalence and properties thereof.
open import FOmegaInt.Reduction.Cbv
open import FOmegaInt.Reduction.Full
-- Typing, kinding, subtyping, etc. along with corresponding
-- substitution lemmas.
open import FOmegaInt.Typing
-- An alternate presentation of kinding and subtyping that is better
-- suited for proving functionality and validity lemmas, along with a
-- proof that the two presentations are equivalent.
open import FOmegaInt.Kinding.Declarative
open import FOmegaInt.Kinding.Declarative.Validity
open import FOmegaInt.Kinding.Declarative.Equivalence
-- Soundness of normalization w.r.t. to declarative kinding.
open import FOmegaInt.Kinding.Declarative.Normalization
-- Simple kinding of types, (hereditary) substitution lemmas.
open import FOmegaInt.Kinding.Simple
-- Lemmas about η-expansion of simply kinded and normalization and
-- simultaneous simplification of declaratively kinded types.
open import FOmegaInt.Kinding.Simple.EtaExpansion
open import FOmegaInt.Kinding.Simple.Normalization
-- Canonical kinding of types along with (hereditary) substitution,
-- validity and inversion lemmas for canonical kinding and subtyping.
open import FOmegaInt.Kinding.Canonical
open import FOmegaInt.Kinding.Canonical.HereditarySubstitution
open import FOmegaInt.Kinding.Canonical.Validity
open import FOmegaInt.Kinding.Canonical.Inversion
-- Lifting of weak (untyped) kind and type equality to canonical kind
-- and type equality.
open import FOmegaInt.Kinding.Canonical.WeakEquality
-- Equivalence of canonical and declarative kinding.
open import FOmegaInt.Kinding.Canonical.Equivalence
-- Generation of typing and inversion of declarative subtyping in the
-- empty context.
open import FOmegaInt.Typing.Inversion
-- Type safety (preservation/subject reduction and progress).
open import FOmegaInt.Typing.Preservation
open import FOmegaInt.Typing.Progress
-- Encodings and properties of higher-order extremal types, interval
-- kinds and bounded quantifiers.
open import FOmegaInt.Typing.Encodings
-- A reduced variant of the canonical system to be used in the
-- undecidability proof.
open import FOmegaInt.Kinding.Canonical.Reduced
-- Setup for the undecidability proof: syntax and lemmas for the SK
-- combinator calculus, and support for encoding/decoding SK terms and
-- equality proofs into types and subtyping derivations.
open import FOmegaInt.Undecidable.SK
open import FOmegaInt.Undecidable.Encoding
open import FOmegaInt.Undecidable.Decoding
-- Undecidability of subtyping
open import FOmegaInt.Undecidable
------------------------------------------------------------------------
-- Modules containing generic functionality
-- Extra lemmas that are derivable in the substitution framework of
-- the Agda standard library, as well as support for binary (term)
-- relations lifted to substitutions, typed substitutions, and typed
-- relations lifted to substitutions.
open import Data.Context
open import Data.Context.WellFormed
open import Data.Context.Properties
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Fin.Substitution.Relation
open import Data.Fin.Substitution.Typed
open import Data.Fin.Substitution.TypedRelation
-- Support for generic reduction relations.
open import Relation.Binary.Reduction
-- Relational reasoning for transitive relations.
open import Relation.Binary.TransReasoning
|
{
"alphanum_fraction": 0.7510103672,
"avg_line_length": 38.1946308725,
"ext": "agda",
"hexsha": "ba81b5a5ab767fac05379d37dfa70cea4503c09f",
"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": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"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": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/README.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/README.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1288,
"size": 5691
}
|
-- Check if sharing is properly used for evaluation.
-- E.g. (\x -> putStrLn x; putStrLn x) (computeString)
-- should only evaluate computeString once.
-- Doing the evaluation twice should still yield the correct result,
-- but will incur a performance penalty.
-- MAlonzo: seems to use proper sharing for this example with ghc -O,
-- but not with ghc -O0. The sharing for -O0 is not introduced by MAlonzo,
-- but by the cleverness of GHC.
module Sharing where
open import Common.Prelude
open import Common.IO
{-# IMPORT Debug.Trace #-}
postulate
primTrace : {b : Set} → String → b → b
{-# COMPILED primTrace (\_ -> Debug.Trace.trace) #-}
{-# COMPILED_UHC primTrace (\_ -> UHC.Agda.Builtins.primTrace) #-}
main : IO Unit
main = (λ x → putStrLn x ,, putStrLn x ) (primTrace "Eval" "hoi")
|
{
"alphanum_fraction": 0.7022613065,
"avg_line_length": 30.6153846154,
"ext": "agda",
"hexsha": "45b9b6ba58bc535364077e7032c451a13921d75b",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Compiler/simple/Sharing.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Compiler/simple/Sharing.agda",
"max_line_length": 74,
"max_stars_count": null,
"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/Compiler/simple/Sharing.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 212,
"size": 796
}
|
open import Algebra
open import Data.Product
open import Data.Bool
open import Data.List
open import Data.List.Properties
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Empty
open import Relation.Nullary
open import Relation.Nullary.Decidable
module LM {A : Set} = Monoid (Data.List.Properties.++-monoid A)
infixr 4 _⇒_
data Type : Set where
o : Type
_⇒_ : Type → Type → Type
Env = List Type
Type≡? : (A B : Type) → Dec (A ≡ B)
Type≡? o o = yes refl
Type≡? o (B ⇒ B₁) = no (λ ())
Type≡? (A ⇒ A₁) o = no (λ ())
Type≡? (A ⇒ B) (A' ⇒ B') with Type≡? A A'
Type≡? (A ⇒ B) (.A ⇒ B') | yes refl with Type≡? B B'
Type≡? (A ⇒ B) (.A ⇒ .B) | yes refl | yes refl = yes refl
Type≡? (A ⇒ B) (.A ⇒ B') | yes refl | no ¬p = no (λ {refl → ¬p refl})
Type≡? (A ⇒ B) (A' ⇒ B') | no ¬p = no (λ {refl → ¬p refl})
Env≡? : (Γ Δ : Env) → Dec (Γ ≡ Δ)
Env≡? [] [] = yes refl
Env≡? [] (x ∷ Δ) = no (λ ())
Env≡? (x ∷ Γ) [] = no (λ ())
Env≡? (A ∷ Γ) (A' ∷ Δ) with Type≡? A A'
Env≡? (A ∷ Γ) (A' ∷ Δ) | yes p with Env≡? Γ Δ
Env≡? (A ∷ Γ) (.A ∷ .Γ) | yes refl | yes refl = yes refl
Env≡? (A ∷ Γ) (A' ∷ Δ) | yes p | no ¬q = no (λ {refl → ¬q refl})
Env≡? (A ∷ Γ) (A' ∷ Δ) | no ¬p = no (λ {refl → ¬p refl})
data Var : Env → Type → Set where
Z : ∀ {Γ : Env} {A : Type} → Var (A ∷ Γ) A
S : ∀ {Γ : Env} {A B : Type} → Var Γ B → Var (A ∷ Γ) B
data Exp : Env → Type → Set where
var : ∀ {Γ : Env} {A : Type} → Var Γ A → Exp Γ A
abs : ∀ {Γ : Env} {A B : Type} → Exp (A ∷ Γ) B → Exp Γ (A ⇒ B)
app : ∀ {Γ : Env} {A B : Type} → Exp Γ (A ⇒ B) → Exp Γ A → Exp Γ B
data PH (X : Type → Set) : Type → Set where
var : ∀ {A : Type} → X A → PH X A
abs : ∀ {A B : Type} → (X A → PH X B) → PH X (A ⇒ B)
app : ∀ {A B : Type} → PH X (A ⇒ B) → PH X A → PH X B
-- logical prediacte on PH
PHᴾ : ∀ {X}(Xᴾ : ∀ {A} → X A → Set) → ∀ {A} → PH X A → Set
PHᴾ Xᴾ (var a) = Xᴾ a
PHᴾ Xᴾ (abs t) = ∀ a → Xᴾ a → PHᴾ Xᴾ (t a)
PHᴾ Xᴾ (app t u) = PHᴾ Xᴾ t × PHᴾ Xᴾ u
postulate
free-thm :
∀ {A}(t : ∀ {X} → PH X A) → ∀ X (Xᴾ : ∀ {A} → X A → Set) → PHᴾ {X} Xᴾ t
PH' : Type → Set
PH' = PH (λ _ → Env)
VarOK? : ∀ Γ A Δ → Dec (∃ λ Ξ → (Ξ ++ A ∷ Δ) ≡ Γ)
VarOK? [] A Δ = no (λ {([] , ()) ; (_ ∷ _ , ())})
VarOK? (A' ∷ Γ) A Δ with Env≡? (A' ∷ Γ) (A ∷ Δ)
VarOK? (A' ∷ Γ) .A' .Γ | yes refl = yes ([] , refl)
VarOK? (A' ∷ Γ) A Δ | no ¬p with VarOK? Γ A Δ
VarOK? (A' ∷ Γ) A Δ | no ¬p | yes (Σ , refl) =
yes (A' ∷ Σ , refl)
VarOK? (A' ∷ Γ) A Δ | no ¬p | no ¬q
= no λ { ([] , refl) → ¬p refl ; (x ∷ Σ , s) → ¬q (Σ , proj₂ (∷-injective s))}
OK : ∀ {A} → Env → PH' A → Set
OK {A} Γ t = ∀ Δ → PHᴾ (λ {B} Σ → True (VarOK? (Δ ++ Γ) B Σ)) t
toVar : ∀ {Γ Σ A} → (∃ λ Ξ → (Ξ ++ A ∷ Σ) ≡ Γ) → Var Γ A
toVar ([] , refl) = Z
toVar (x ∷ Ξ , refl) = S (toVar (Ξ , refl))
toExp' : ∀ {Γ A} (t : PH' A) → OK {A} Γ t → Exp Γ A
toExp' (var x) p = var (toVar (toWitness (p [])))
toExp' {Γ} (abs {A} {B} t) p =
abs (toExp' (t Γ)
λ Δ → subst (λ z → PHᴾ (λ {B₁} Σ₁ → True (VarOK? z B₁ Σ₁)) (t Γ))
(LM.assoc Δ (A ∷ []) Γ)
(p (Δ ++ A ∷ []) Γ (fromWitness (Δ , sym (LM.assoc Δ (A ∷ []) Γ)))))
toExp' (app t u) p =
app (toExp' t (proj₁ ∘ p)) (toExp' u (proj₂ ∘ p))
toExp : ∀ {A} → (∀ {X} → PH X A) → Exp [] A
toExp {A} t = toExp' t λ Δ → free-thm t _ _
-- examples
------------------------------------------------------------
t0 : ∀ {X} → PH X ((o ⇒ o) ⇒ o ⇒ o)
t0 = abs var
t1 : ∀ {X} → PH X ((o ⇒ o) ⇒ o ⇒ o)
t1 = abs λ f → abs λ x → app (var f) (app (var f) (var x))
test1 : toExp t0 ≡ abs (var Z)
test1 = refl
test2 : toExp t1 ≡ abs (abs (app (var (S Z)) (app (var (S Z)) (var Z))))
test2 = refl
|
{
"alphanum_fraction": 0.462489695,
"avg_line_length": 32.203539823,
"ext": "agda",
"hexsha": "51ed1a3a776576bc435edd84e4fd2e5fd45ca097",
"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/PHOAStoEXP.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/PHOAStoEXP.agda",
"max_line_length": 87,
"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/PHOAStoEXP.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": 1714,
"size": 3639
}
|
{-# OPTIONS --safe #-}
module JVM.Syntax.Values where
open import Data.Bool
open import Data.Integer.Base
open import Relation.Unary
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax
open import JVM.Types
data Const : Ty → Set where
null : ∀ {c} → Const (ref c)
num : ℤ → Const int
bool : Bool → Const boolean
|
{
"alphanum_fraction": 0.7348484848,
"avg_line_length": 23.2941176471,
"ext": "agda",
"hexsha": "b40444732186ae18111157bef9bf93d990f621b4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Syntax/Values.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"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": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Syntax/Values.agda",
"max_line_length": 46,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Syntax/Values.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 101,
"size": 396
}
|
{-# OPTIONS --type-in-type #-}
-- Yeah, that's type-in-type. I'm a sissy, I want to use the stdlib, I
-- don't want to reimplement ℕ, ⊤, etc. in Set1.
module ILabel where
open import Data.String
open import Data.Empty
open import Data.Unit
open import Data.Product
open import Data.Maybe
open import Data.Nat
open import Relation.Binary.PropositionalEquality
--****************************************************************
-- A universe of labels
--****************************************************************
infixr 5 _∷_
data AllowedBy : Set -> Set where
ε : forall {T} ->
AllowedBy T
_∷_ : {S : Set}{T : S -> Set} ->
(s : S)(ts : AllowedBy (T s)) -> AllowedBy ((x : S) -> T x)
UId = String
-- The universe (that's a tiny one):
data Label : Set where
label : (u : UId)(T : Set)(ts : AllowedBy T) -> Label
--****************************************************************
-- IDesc & co.
--****************************************************************
data IDesc (I : Set1) : Set1 where
var : I -> IDesc I
const : Set -> IDesc I
prod : IDesc I -> IDesc I -> IDesc I
sigma : (S : Set) -> (S -> IDesc I) -> IDesc I
pi : (S : Set) -> (S -> IDesc I) -> IDesc I
desc : {I : Set1} -> IDesc I -> (I -> Set) -> Set
desc (var i) P = P i
desc (const X) P = X
desc (prod D D') P = desc D P × desc D' P
desc (sigma S T) P = Σ S (\s -> desc (T s) P)
desc (pi S T) P = (s : S) -> desc (T s) P
-- We (may) stuck a label on the fix-point:
data IMu {I : Set1}(L : Maybe (I -> Label))(R : I -> IDesc I)(i : I) : Set where
con : desc (R i) (\j -> IMu L R j) -> IMu L R i
--****************************************************************
-- Example: Nat
--****************************************************************
data NatConst : Set where
Ze : NatConst
Su : NatConst
natCases : NatConst -> IDesc ⊤
natCases Ze = const ⊤
natCases Suc = var _
NatD : ⊤ → IDesc ⊤
NatD _ = sigma NatConst natCases
Nat : Set
Nat = IMu (just (\ _ -> label "Nat" Set ε)) NatD _
--****************************************************************
-- Example: Vector
--****************************************************************
data VecConst : ℕ -> Set where
Vnil : VecConst 0
Vcons : {n : ℕ} -> VecConst (1 + n)
vecDChoice : Set -> (n : ℕ) -> VecConst n -> IDesc ℕ
vecDChoice X 0 Vnil = const ⊤
vecDChoice X (suc n) Vcons = prod (const X) (var n)
vecD : Set -> ℕ -> IDesc ℕ
vecD X n = sigma (VecConst n) (vecDChoice X n)
vec : Set -> ℕ -> Set
vec X n = IMu (just (\n -> label "Vec" (ℕ -> Set) (n ∷ ε))) (vecD X) n
--****************
-- Example: Fin
--****************
data FinConst : ℕ -> Set where
Fz : {n : ℕ} -> FinConst (1 + n)
Fs : {n : ℕ} -> FinConst (1 + n)
finDChoice : (n : ℕ) -> FinConst n -> IDesc ℕ
finDChoice 0 ()
finDChoice (suc n) Fz = const ⊤
finDChoice (suc n) Fs = var n
finD : ℕ -> IDesc ℕ
finD n = sigma (FinConst n) (finDChoice n)
fin : ℕ -> Set
fin n = IMu (just (\ n -> label "Fin" (ℕ -> Set) (n ∷ ε))) finD n
--****************
-- Example: Identity type
--****************
-- data Id (A : Set) (a : A) : A -> Set := (refl : Id A a a)
data IdConst : Set where
Refl : IdConst
idD : (A : Set)(a : A)(b : A) -> IDesc A
idD A a b = sigma IdConst (\ _ -> const (a ≡ b))
id : (A : Set)(a : A)(b : A) -> Set
id A a b = IMu (just (\ b -> label "Id" ((A : Set)(a : A)(b : A) -> Set) (A ∷ a ∷ b ∷ ε))) (idD A a) b
|
{
"alphanum_fraction": 0.4599180807,
"avg_line_length": 25.3185185185,
"ext": "agda",
"hexsha": "80fd2bd2cc0a5df5cb85c0f43f1ecad5afc04816",
"lang": "Agda",
"max_forks_count": 12,
"max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z",
"max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mietek/epigram",
"max_forks_repo_path": "models/ILabel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mietek/epigram",
"max_issues_repo_path": "models/ILabel.agda",
"max_line_length": 102,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mietek/epigram",
"max_stars_repo_path": "models/ILabel.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z",
"num_tokens": 1104,
"size": 3418
}
|
------------------------------------------------------------------------
-- Propositional equality
------------------------------------------------------------------------
module Relation.Binary.PropositionalEquality1 where
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
------------------------------------------------------------------------
-- Propositional equality
infix 4 _≡₁_ _≢₁_
data _≡₁_ {a : Set₁} (x : a) : a → Set where
refl : x ≡₁ x
-- Nonequality.
_≢₁_ : {a : Set₁} → a → a → Set
x ≢₁ y = ¬ x ≡₁ y
------------------------------------------------------------------------
-- Some properties
reflexive : ∀ {a} (x : a) → x ≡₁ x
reflexive _ = refl
sym : ∀ {a} {x y : a} → x ≡₁ y → y ≡₁ x
sym refl = refl
trans : ∀ {a} {x y z : a} → x ≡₁ y → y ≡₁ z → x ≡₁ z
trans refl refl = refl
subst : {a b : Set} → a ≡₁ b → a → b
subst refl x = x
cong : ∀ {a b} (f : a → b) → ∀ {x y} → x ≡₁ y → f x ≡₁ f y
cong _ refl = refl
cong₂ : ∀ {a b c} (f : a → b → c) →
∀ {x₁ x₂ y₁ y₂} → x₁ ≡₁ x₂ → y₁ ≡₁ y₂ → f x₁ y₁ ≡₁ f x₂ y₂
cong₂ _ refl refl = refl
cong₀₁ : ∀ {a b} (f : a → b) → ∀ {x y} → x ≡ y → f x ≡₁ f y
cong₀₁ _ refl = refl
cong₁₀ : ∀ {a b} (f : a → b) → ∀ {x y} → x ≡₁ y → f x ≡ f y
cong₁₀ _ refl = refl
|
{
"alphanum_fraction": 0.4247517189,
"avg_line_length": 25.6666666667,
"ext": "agda",
"hexsha": "40c26156d87399247601364a36013408334a08f4",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Relation/Binary/PropositionalEquality1.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Relation/Binary/PropositionalEquality1.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/PropositionalEquality1.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 468,
"size": 1309
}
|
open import Data.Empty
open import Data.List hiding ([_]) renaming (_∷_ to _∷ₗ_)
open import Data.Maybe
open import Data.Product
open import Data.Sum
open import Data.Unit
open import AEff
open import EffectAnnotations
open import Preservation
open import Progress
open import Renamings
open import Substitutions renaming (⟨_,_⟩ to ⟨_,,_⟩)
open import Types
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary
open import Relation.Nullary.Negation
module Finality where
-- SMALL-STEP OPERATIONAL SEMANTICS FOR WELL-TYPED COMPUTATIONS
-- WITH INLINED EVALUATION CONTEXT RULES
mutual
infix 10 _↝↝_
data _↝↝_ {Γ : Ctx} : {C : CType} → Γ ⊢C⦂ C → Γ ⊢C⦂ C → Set where
-- COMPUTATIONAL RULES
apply : {X : VType}
{C : CType} →
(M : Γ ∷ X ⊢C⦂ C) →
(V : Γ ⊢V⦂ X) →
----------------------
(ƛ M) · V
↝↝
M [ sub-id [ V ]s ]c
let-return : {X Y : VType}
{o : O}
{i : I} →
(V : Γ ⊢V⦂ X) →
(N : Γ ∷ X ⊢C⦂ Y ! (o , i)) →
-----------------------------
let= (return V) `in N
↝↝
N [ sub-id [ V ]s ]c
let-↑ : {X Y : VType}
{o : O}
{i : I}
{op : Σₛ} →
(p : op ∈ₒ o) →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(M : Γ ⊢C⦂ X ! (o , i)) →
(N : Γ ∷ X ⊢C⦂ Y ! (o , i)) →
--------------------------------
let= (↑ op p V M) `in N
↝↝
↑ op p V (let= M `in N)
let-promise : {X Y Z : VType}
{o o' : O}
{i i' : I}
{op : Σₛ} →
(p : (o' , i') ⊑ lkpᵢ op i) →
(M₁ : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →
(M₂ : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →
(N : Γ ∷ Y ⊢C⦂ Z ! (o , i)) →
---------------------------------------------------------------------------------------------------------
let= (promise op ∣ p ↦ M₁ `in M₂) `in N
↝↝
(promise op ∣ p ↦ M₁ `in (let= M₂ `in (C-rename (ren-cong ren-wk) N)))
let-await : {X Y Z : VType}
{o : O}
{i : I} →
(V : Γ ⊢V⦂ ⟨ X ⟩) →
(M : Γ ∷ X ⊢C⦂ Y ! (o , i)) →
(N : Γ ∷ Y ⊢C⦂ Z ! (o , i)) →
-------------------------------------------------------
let= (await V until M) `in N
↝↝
await V until (let= M `in C-rename (ren-cong ren-wk) N)
let-spawn : {X Y : VType}
{C : CType}
{o : O}
{i : I} →
(M : Γ ■ ⊢C⦂ C) →
(N : Γ ⊢C⦂ X ! (o , i)) →
(K : Γ ∷ X ⊢C⦂ Y ! (o , i)) →
---------------------------------------
let= (spawn M N) `in K
↝↝
spawn M (let= N `in K)
promise-↑ : {X Y : VType}
{o o' : O}
{i i' : I}
{op op' : Σₛ} →
(p : (o' , i') ⊑ lkpᵢ op i) →
(q : op' ∈ₒ o) →
(V : Γ ∷ ⟨ X ⟩ ⊢V⦂ proj₁ (payload op')) →
(M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →
--------------------------------------------------------------------------------------------------------
(promise op ∣ p ↦ M `in (↑ op' q V N))
↝↝
↑ op' q (strengthen-val {Δ = X ∷ₗ []} (proj₂ (payload op')) V) (promise op ∣ p ↦ M `in N)
promise-spawn : {X Y : VType}
{C : CType}
{o o' : O}
{i i' : I}
{op : Σₛ} →
(p : (o' , i') ⊑ lkpᵢ op i) →
(M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ■ ⊢C⦂ C) →
(K : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →
---------------------------------------------------------------------------------------------------------
(promise op ∣ p ↦ M `in (spawn N K))
↝↝
spawn (strengthen-■-c {Γ' = []} {Δ = X ∷ₗ []} N) (promise op ∣ p ↦ M `in K)
↓-return : {X : VType}
{o : O}
{i : I}
{op : Σₛ} →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(W : Γ ⊢V⦂ X) →
----------------------------------------------------------------
↓ {o = o} {i = i} op V (return W)
↝↝
return {o = proj₁ (op ↓ₑ (o , i))} {i = proj₂ (op ↓ₑ (o , i))} W
↓-↑ : {X : VType}
{o : O}
{i : I}
{op : Σₛ}
{op' : Σₛ} →
(p : op' ∈ₒ o) →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(W : Γ ⊢V⦂ proj₁ (payload op')) →
(M : Γ ⊢C⦂ X ! (o , i)) →
---------------------------------
↓ op V (↑ op' p W M)
↝↝
↑ op' (↓ₑ-⊑ₒ op' p) W (↓ op V M)
↓-promise-op : {X Y : VType}
{o o' : O}
{i i' : I}
{op : Σₛ} →
(p : (o' , i') ⊑ lkpᵢ op i) →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →
--------------------------------------------------------------------------------------------------------------------------------------------------------
↓ op V (promise op ∣ p ↦ M `in N )
↝↝
(let= (coerce (⊑ₒ-trans (proj₁ (⊑-proj p (proj₂ (proj₂ (⊑-just p))))) (↓ₑ-⊑ₒ-o' {o = o} (proj₂ (proj₂ (⊑-just p)))))
(⊑ᵢ-trans (proj₂ (⊑-proj p (proj₂ (proj₂ (⊑-just p))))) (↓ₑ-⊑ₒ-i' {o = o} (proj₂ (proj₂ (⊑-just p)))))
(M [ (sub-id [ V ]s)
[ ƛ (promise op ∣ subst (λ oi → (o' , i') ⊑ oi) (sym ite-≡) ⊑-refl ↦ C-rename (ren-cong (ren-cong ren-wk)) M `in return (` Hd)) ]s ]c))
`in (↓ op (V-rename ren-wk V) N))
↓-promise-op' : {X Y : VType}
{o o' : O}
{i i' : I}
{op op' : Σₛ} →
(p : ¬ op ≡ op') →
(q : (o' , i') ⊑ lkpᵢ op' i) →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(M : Γ ∷ proj₁ (payload op') ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op' ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →
-----------------------------------------------------------------------------------------------------------
↓ op V (promise op' ∣ q ↦ M `in N )
↝↝
promise op' ∣ (lkpᵢ-↓ₑ-neq-⊑ {o = o} {i = i} p q) ↦ M `in ↓ op (V-rename ren-wk V) N
↓-await : {X Y : VType}
{o : O}
{i : I}
{op : Σₛ} →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(W : Γ ⊢V⦂ ⟨ X ⟩) →
(M : Γ ∷ X ⊢C⦂ Y ! (o , i)) →
------------------------------------------
↓ op V (await W until M)
↝↝
await W until (↓ op (V-rename ren-wk V) M)
↓-spawn : {X : VType}
{C : CType}
{o : O}
{i : I}
{op : Σₛ} →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(M : Γ ■ ⊢C⦂ C) →
(N : Γ ⊢C⦂ X ! (o , i)) →
--------------------------------
↓ op V (spawn M N)
↝↝
spawn M (↓ op V N)
await-promise : {X : VType}
{C : CType} →
(V : Γ ⊢V⦂ X) →
(M : Γ ∷ X ⊢C⦂ C) →
--------------------
await ⟨ V ⟩ until M
↝↝
M [ sub-id [ V ]s ]c
box-unbox : {X : VType}
{C : CType} →
(V : Γ ■ ⊢V⦂ X) →
(M : Γ ∷ X ⊢C⦂ C) →
----------------------------------------
unbox (□ V) `in M
↝↝
M [ ⟨ sub-id ,, ■-str-v {Γ' = []} V ⟩ ]c
-- INLINED EVALUATION CONTEXT RULES
context-let : {X Y : VType}
{o : O}
{i : I} →
{M M' : Γ ⊢C⦂ X ! (o , i)} →
{N : Γ ∷ X ⊢C⦂ Y ! (o , i)} →
M ↝↝ M' →
-----------------------------
let= M `in N
↝↝
let= M' `in N
context-↑ : {X : VType}
{o : O}
{i : I}
{op : Σₛ}
{p : op ∈ₒ o}
{V : Γ ⊢V⦂ proj₁ (payload op)}
{M N : Γ ⊢C⦂ X ! (o , i)} →
M ↝↝ N →
---------------------------
↑ op p V M
↝↝
↑ op p V N
context-↓ : {X : VType}
{o : O}
{i : I}
{op : Σₛ}
{V : Γ ⊢V⦂ proj₁ (payload op)}
{M N : Γ ⊢C⦂ X ! (o , i)} →
M ↝↝ N →
------------------------------
↓ op V M
↝↝
↓ op V N
context-promise : {X Y : VType}
{o o' : O}
{i i' : I}
{op : Σₛ} →
{r : (o' , i') ⊑ lkpᵢ op i}
{M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')} →
{N N' : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)} →
N ↝↝ N' →
--------------------------------------------------------------------------------------------------------
promise op ∣ r ↦ M `in N
↝↝
promise op ∣ r ↦ M `in N'
context-spawn : {C D : CType}
{M : Γ ■ ⊢C⦂ C}
{N N' : Γ ⊢C⦂ D} →
N ↝↝ N' →
------------------
spawn M N
↝↝
spawn M N'
context-coerce : {X : VType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'} →
{M N : Γ ⊢C⦂ X ! (o , i)} →
M ↝↝ N →
---------------------------
coerce p q M
↝↝
coerce p q N
-- COERCION RULES
coerce-return : {X : VType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'} →
(V : Γ ⊢V⦂ X) →
--------------------------------
coerce p q (return V) ↝↝ return V
coerce-↑ : {X : VType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'}
{op : Σₛ} →
(r : op ∈ₒ o) →
(V : Γ ⊢V⦂ proj₁ (payload op)) →
(M : Γ ⊢C⦂ X ! (o , i)) →
-------------------------------
coerce p q (↑ op r V M)
↝↝
↑ op (p op r) V (coerce p q M)
coerce-promise : {X Y : VType}
{o o' o'' : O}
{i i' i'' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'}
{op : Σₛ} →
(r : (o'' , i'') ⊑ lkpᵢ op i )
(M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o'' , i'') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o'' , i'')) →
(N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →
-------------------------------------------------------------------------------------------------------------
coerce p q (promise op ∣ r ↦ M `in N)
↝↝
promise_∣_↦_`in_ op (subst (λ oi → (o'' , i'') ⊑ oi) (sym (lkpᵢ-next-eq q (proj₂ (proj₂ (⊑-just r)))))
(⊑-trans r (proj₂ (proj₂ (⊑-just r))) (
(lkpᵢ-next-⊑ₒ q (proj₂ (proj₂ (⊑-just r)))) ,
(lkpᵢ-next-⊑ᵢ q (proj₂ (proj₂ (⊑-just r)))))))
M
(coerce p q N)
coerce-await : {X Y : VType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'} →
(V : Γ ⊢V⦂ ⟨ X ⟩) →
(M : Γ ∷ X ⊢C⦂ Y ! (o , i)) →
-----------------------------
coerce p q (await V until M)
↝↝
await V until (coerce p q M)
coerce-spawn : {X : VType}
{C : CType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'} →
(M : Γ ■ ⊢C⦂ C) →
(N : Γ ⊢C⦂ X ! (o , i)) →
-------------------------
coerce p q (spawn M N)
↝↝
spawn M (coerce p q N)
-- ONE-TO-ONE CORRESPONDENCE BETWEEN THE TWO SETS OF REDUCTION RULES
↝↝-to-↝ : {Γ : Ctx}
{C : CType}
{M N : Γ ⊢C⦂ C} →
M ↝↝ N →
-----------------
M ↝ N
↝↝-to-↝ (apply M V) =
apply M V
↝↝-to-↝ (let-return V N) =
let-return V N
↝↝-to-↝ (let-↑ p V M N) =
let-↑ p V M N
↝↝-to-↝ (let-promise p M₁ M₂ N) =
let-promise p M₁ M₂ N
↝↝-to-↝ (let-await V M N) =
let-await V M N
↝↝-to-↝ (let-spawn M N K) =
let-spawn M N K
↝↝-to-↝ (promise-↑ p q V M N) =
promise-↑ p q V M N
↝↝-to-↝ (promise-spawn p M N K) =
promise-spawn p M N K
↝↝-to-↝ (↓-return V W) =
↓-return V W
↝↝-to-↝ (↓-↑ p V W M) =
↓-↑ p V W M
↝↝-to-↝ (↓-promise-op p V M N) =
↓-promise-op p V M N
↝↝-to-↝ (↓-promise-op' p q V M N) =
↓-promise-op' p q V M N
↝↝-to-↝ (↓-await V W M) =
↓-await V W M
↝↝-to-↝ (↓-spawn V M N) =
↓-spawn V M N
↝↝-to-↝ (await-promise V M) =
await-promise V M
↝↝-to-↝ (box-unbox V M) =
box-unbox V M
↝↝-to-↝ (context-let r) =
context _ (↝↝-to-↝ r)
↝↝-to-↝ (context-↑ r) =
context _ (↝↝-to-↝ r)
↝↝-to-↝ (context-↓ r) =
context _ (↝↝-to-↝ r)
↝↝-to-↝ (context-promise r) =
context _ (↝↝-to-↝ r)
↝↝-to-↝ (context-spawn r) =
context _ (↝↝-to-↝ r)
↝↝-to-↝ (context-coerce r) =
context _ (↝↝-to-↝ r)
↝↝-to-↝ (coerce-return V) =
coerce-return V
↝↝-to-↝ (coerce-↑ p V M) =
coerce-↑ p V M
↝↝-to-↝ (coerce-promise p M N) =
coerce-promise p M N
↝↝-to-↝ (coerce-await V M) =
coerce-await V M
↝↝-to-↝ (coerce-spawn M N) =
coerce-spawn M N
mutual
↝-context-to-↝↝ : {Γ : Ctx}
{Δ : BCtx}
{C : CType} →
(E : Γ ⊢E[ Δ ]⦂ C) →
{M N : (Γ ⋈ Δ) ⊢C⦂ hole-ty-e E} →
M ↝ N →
---------------------------------
E [ M ] ↝↝ E [ N ]
↝-context-to-↝↝ [-] r =
↝-to-↝↝ r
↝-context-to-↝↝ (let= E `in x) r =
context-let (↝-context-to-↝↝ E r)
↝-context-to-↝↝ (↑ op p V E) r =
context-↑ (↝-context-to-↝↝ E r)
↝-context-to-↝↝ (↓ op V E) r =
context-↓ (↝-context-to-↝↝ E r)
↝-context-to-↝↝ (promise op ∣ p ↦ M `in E) r =
context-promise (↝-context-to-↝↝ E r)
↝-context-to-↝↝ (spawn M E) r =
context-spawn (↝-context-to-↝↝ E r)
↝-context-to-↝↝ (coerce p q E) r =
context-coerce (↝-context-to-↝↝ E r)
↝-to-↝↝ : {Γ : Ctx}
{C : CType}
{M N : Γ ⊢C⦂ C} →
M ↝ N →
-----------------
M ↝↝ N
↝-to-↝↝ (apply M V) =
apply M V
↝-to-↝↝ (let-return V N) =
let-return V N
↝-to-↝↝ (let-↑ p V M N) =
let-↑ p V M N
↝-to-↝↝ (let-promise p M₁ M₂ N) =
let-promise p M₁ M₂ N
↝-to-↝↝ (let-await V M N) =
let-await V M N
↝-to-↝↝ (let-spawn M N K) =
let-spawn M N K
↝-to-↝↝ (promise-↑ p q V M N) =
promise-↑ p q V M N
↝-to-↝↝ (promise-spawn p M N K) =
promise-spawn p M N K
↝-to-↝↝ (↓-return V W) =
↓-return V W
↝-to-↝↝ (↓-↑ p V W M) =
↓-↑ p V W M
↝-to-↝↝ (↓-promise-op p V M N) =
↓-promise-op p V M N
↝-to-↝↝ (↓-promise-op' p q V M N) =
↓-promise-op' p q V M N
↝-to-↝↝ (↓-await V W M) =
↓-await V W M
↝-to-↝↝ (↓-spawn V M N) =
↓-spawn V M N
↝-to-↝↝ (await-promise V M) =
await-promise V M
↝-to-↝↝ (box-unbox V M) =
box-unbox V M
↝-to-↝↝ (context E r) =
↝-context-to-↝↝ E r
↝-to-↝↝ (coerce-return V) =
coerce-return V
↝-to-↝↝ (coerce-↑ p V M) =
coerce-↑ p V M
↝-to-↝↝ (coerce-promise p M N) =
coerce-promise p M N
↝-to-↝↝ (coerce-await V M) =
coerce-await V M
↝-to-↝↝ (coerce-spawn M N) =
coerce-spawn M N
-- FINALITY OF RESULT FORMS
run-finality-↝↝ : {Γ : MCtx}
{C : CType}
{M N : ⟨⟨ Γ ⟩⟩ ⊢C⦂ C} →
RunResult⟨ Γ ∣ M ⟩ →
M ↝↝ N →
-----------------------
⊥
run-finality-↝↝ (promise ()) (promise-↑ p q V M N)
run-finality-↝↝ (promise ()) (promise-spawn p M N K)
run-finality-↝↝ (promise R) (context-promise r) =
run-finality-↝↝ R r
comp-finality-↝↝ : {Γ : MCtx}
{C : CType}
{M N : ⟨⟨ Γ ⟩⟩ ⊢C⦂ C} →
CompResult⟨ Γ ∣ M ⟩ →
M ↝↝ N →
-----------------------
⊥
comp-finality-↝↝ (comp R) r =
run-finality-↝↝ R r
comp-finality-↝↝ (signal R) (context-↑ r) =
comp-finality-↝↝ R r
comp-finality-↝↝ (spawn R) (context-spawn r) =
comp-finality-↝↝ R r
comp-finality : {Γ : MCtx}
{C : CType}
{M N : ⟨⟨ Γ ⟩⟩ ⊢C⦂ C} →
CompResult⟨ Γ ∣ M ⟩ →
M ↝ N →
-----------------------
⊥
comp-finality R r =
comp-finality-↝↝ R (↝-to-↝↝ r)
|
{
"alphanum_fraction": 0.2597924837,
"avg_line_length": 35.8416370107,
"ext": "agda",
"hexsha": "5d7135f578eaab6739212d13d2933d4049ede092",
"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": "b41df71f4456666aab4bd14e13d285c31af80ff6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danelahman/modal-aeff-agda",
"max_forks_repo_path": "Finality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6",
"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": "danelahman/modal-aeff-agda",
"max_issues_repo_path": "Finality.agda",
"max_line_length": 174,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danelahman/higher-order-aeff-agda",
"max_stars_repo_path": "Finality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T18:50:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-17T15:00:34.000Z",
"num_tokens": 6767,
"size": 20143
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Substitutions
------------------------------------------------------------------------
-- Uses a variant of Conor McBride's technique from "Type-Preserving
-- Renaming and Substitution".
-- See Data.Fin.Substitution.Example for an example of how this module
-- can be used: a definition of substitution for the untyped
-- λ-calculus.
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Substitution where
open import Data.Nat hiding (_⊔_)
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec
open import Function as Fun using (flip)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
as Star using (Star; ε; _◅_)
open import Level using (Level; _⊔_)
import Level as L
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- General functionality
-- A Sub T m n is a substitution which, when applied to something with
-- at most m variables, yields something with at most n variables.
Sub : ∀ {ℓ} → Pred ℕ ℓ → ℕ → ℕ → Set ℓ
Sub T m n = Vec (T n) m
-- A /reversed/ sequence of matching substitutions.
Subs : ∀ {ℓ} → Pred ℕ ℓ → ℕ → ℕ → Set ℓ
Subs T = flip (Star (flip (Sub T)))
-- Some simple substitutions.
record Simple {ℓ : Level} (T : Pred ℕ ℓ) : Set ℓ where
infix 10 _↑
infixl 10 _↑⋆_ _↑✶_
field
var : ∀ {n} → Fin n → T n -- Takes variables to Ts.
weaken : ∀ {n} → T n → T (suc n) -- Weakens Ts.
-- Lifting.
_↑ : ∀ {m n} → Sub T m n → Sub T (suc m) (suc n)
ρ ↑ = var zero ∷ map weaken ρ
_↑⋆_ : ∀ {m n} → Sub T m n → ∀ k → Sub T (k + m) (k + n)
ρ ↑⋆ zero = ρ
ρ ↑⋆ suc k = (ρ ↑⋆ k) ↑
_↑✶_ : ∀ {m n} → Subs T m n → ∀ k → Subs T (k + m) (k + n)
ρs ↑✶ k = Star.gmap (_+_ k) (λ ρ → ρ ↑⋆ k) ρs
-- The identity substitution.
id : ∀ {n} → Sub T n n
id {zero} = []
id {suc n} = id ↑
-- Weakening.
wk⋆ : ∀ k {n} → Sub T n (k + n)
wk⋆ zero = id
wk⋆ (suc k) = map weaken (wk⋆ k)
wk : ∀ {n} → Sub T n (suc n)
wk = wk⋆ 1
-- A substitution which only replaces the first variable.
sub : ∀ {n} → T n → Sub T (suc n) n
sub t = t ∷ id
-- Application of substitutions.
record Application {ℓ₁ ℓ₂ : Level} (T₁ : Pred ℕ ℓ₁) (T₂ : Pred ℕ ℓ₂) :
Set (ℓ₁ ⊔ ℓ₂) where
infixl 8 _/_ _/✶_
infixl 9 _⊙_
-- Post-application of substitutions to things.
field _/_ : ∀ {m n} → T₁ m → Sub T₂ m n → T₁ n
-- Reverse composition. (Fits well with post-application.)
_⊙_ : ∀ {m n k} → Sub T₁ m n → Sub T₂ n k → Sub T₁ m k
ρ₁ ⊙ ρ₂ = map (λ t → t / ρ₂) ρ₁
-- Application of multiple substitutions.
_/✶_ : ∀ {m n} → T₁ m → Subs T₂ m n → T₁ n
_/✶_ = Star.gfold Fun.id _ (flip _/_) {k = zero}
-- A combination of the two records above.
record Subst {ℓ : Level} (T : Pred ℕ ℓ) : Set ℓ where
field
simple : Simple T
application : Application T T
open Simple simple public
open Application application public
-- Composition of multiple substitutions.
⨀ : ∀ {m n} → Subs T m n → Sub T m n
⨀ ε = id
⨀ (ρ ◅ ε) = ρ -- Convenient optimisation; simplifies some proofs.
⨀ (ρ ◅ ρs) = ⨀ ρs ⊙ ρ
------------------------------------------------------------------------
-- Instantiations and code for facilitating instantiations
-- Liftings from T₁ to T₂.
record Lift {ℓ₁ ℓ₂ : Level} (T₁ : Pred ℕ ℓ₁) (T₂ : Pred ℕ ℓ₂) :
Set (ℓ₁ ⊔ ℓ₂) where
field
simple : Simple T₁
lift : ∀ {n} → T₁ n → T₂ n
open Simple simple public
-- Variable substitutions (renamings).
module VarSubst where
subst : Subst Fin
subst = record
{ simple = record { var = Fun.id; weaken = suc }
; application = record { _/_ = flip lookup }
}
open Subst subst public
-- "Term" substitutions.
record TermSubst (T : Pred ℕ L.zero) : Set₁ where
field
var : ∀ {n} → Fin n → T n
app : ∀ {T′ : Pred ℕ L.zero} → Lift T′ T → ∀ {m n} → T m → Sub T′ m n → T n
module Lifted {T′ : Pred ℕ L.zero} (lift : Lift T′ T) where
application : Application T T′
application = record { _/_ = app lift }
open Lift lift public
open Application application public
varLift : Lift Fin T
varLift = record { simple = VarSubst.simple; lift = var }
infix 8 _/Var_
_/Var_ : ∀ {m n} → T m → Sub Fin m n → T n
_/Var_ = app varLift
simple : Simple T
simple = record
{ var = var
; weaken = λ t → t /Var VarSubst.wk
}
termLift : Lift T T
termLift = record { simple = simple; lift = Fun.id }
subst : Subst T
subst = record
{ simple = simple
; application = Lifted.application termLift
}
open Subst subst public hiding (var; simple)
|
{
"alphanum_fraction": 0.5596019479,
"avg_line_length": 25.5297297297,
"ext": "agda",
"hexsha": "2a9d636b90c6ece7fc61d665156f3bf0a50578cd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1595,
"size": 4723
}
|
module IORef where
data Unit : Set where
unit : Unit
data Pair (A B : Set) : Set where
pair : A -> B -> Pair A B
fst : {A B : Set} -> Pair A B -> A
fst (pair a b) = a
snd : {A B : Set} -> Pair A B -> B
snd (pair a b) = b
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Fin : Nat -> Set where
fz : {n : Nat} -> Fin (suc n)
fs : {n : Nat} -> Fin n -> Fin (suc n)
infixr 40 _::_
infixl 20 _!_
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
_!_ : {A : Set}{n : Nat} -> Vec A n -> Fin n -> A
[] ! ()
x :: _ ! fz = x
_ :: xs ! (fs i) = xs ! i
Loc : Nat -> Set
Loc = Fin
-- A universe. IORefs can store data of type el(u), for some u : U
postulate
U : Set
el : U -> Set
-- Shapes tell you what types live on the heap.
Shape : Nat -> Set
Shape n = Vec U n -- Fin n -> U
-- Shapes can grow as you allocate new memory
_||_ : {n : Nat} -> Shape n -> U -> Shape (suc n)
xs || u = u :: xs
infixl 40 _▻_
infixl 60 _[_:=_] _[_]
-- The heap maps locations to elements of the right type.
data Heap : {n : Nat}(s : Shape n) -> Set where
ε : Heap []
_▻_ : {n : Nat}{s : Shape n}{a : U} -> Heap s -> el a -> Heap (s || a)
-- Heap : {n : Nat} -> Shape n -> Set
-- Heap {n} shape = (k : Fin n) -> el (shape ! k)
_[_:=_] : {n : Nat}{s : Shape n} -> Heap s -> (l : Loc n) -> el (s ! l) -> Heap s
ε [ () := _ ]
(h ▻ _) [ fz := x ] = h ▻ x
(h ▻ y) [ fs i := x ] = h [ i := x ] ▻ y
_[_] : {n : Nat}{s : Shape n} -> Heap s -> (l : Loc n) -> el (s ! l)
ε [ () ]
(h ▻ x) [ fz ] = x
(h ▻ _) [ fs i ] = h [ i ]
-- (h [ fz := x ]) fz = x
-- (h [ fz := x ]) (fs i) = h (fs i)
-- (h [ fs i := x ]) fz = h fz
-- _[_:=_] {._}{_ :: s} h (fs i) x (fs j) = _[_:=_] {s = s} (\z -> h (fs z)) i x j
-- Well-scoped, well-typed IORefs
data IO (A : Set) : {n m : Nat} -> Shape n -> Shape m -> Set where
Return : {n : Nat}{s : Shape n} -> A -> IO A s s
WriteIORef : {n m : Nat}{s : Shape n}{t : Shape m} ->
(loc : Loc n) -> el (s ! loc) -> IO A s t -> IO A s t
ReadIORef : {n m : Nat}{s : Shape n}{t : Shape m} ->
(loc : Loc n) -> (el (s ! loc) -> IO A s t) -> IO A s t
NewIORef : {n m : Nat}{s : Shape n}{t : Shape m}{u : U} ->
el u -> IO A (s || u) t -> IO A s t
-- Running IO programs
run : {A : Set} -> {n m : Nat} -> {s : Shape n} -> {t : Shape m}
-> Heap s -> IO A s t -> Pair A (Heap t)
run heap (Return x) = pair x heap
run heap (WriteIORef l x io) = run (heap [ l := x ]) io
run heap (ReadIORef l k) = run heap (k (heap [ l ]))
run heap (NewIORef x k) = run (heap ▻ x) k
infixr 10 _>>=_ _>>_
_>>=_ : {A B : Set}{n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃} ->
IO A s₁ s₂ -> (A -> IO B s₂ s₃) -> IO B s₁ s₃
Return x >>= f = f x
WriteIORef r x k >>= f = WriteIORef r x (k >>= f)
ReadIORef r k >>= f = ReadIORef r (\x -> k x >>= f)
NewIORef x k >>= f = NewIORef x (k >>= f)
_>>_ : {A B : Set}{n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃} ->
IO A s₁ s₂ -> IO B s₂ s₃ -> IO B s₁ s₃
a >> b = a >>= \_ -> b
-- The operations without CPS
data IORef : {n : Nat}(s : Shape n) -> U -> Set where
ioRef : {n : Nat}{s : Shape n}(r : Loc n) -> IORef s (s ! r)
return : {A : Set}{n : Nat}{s : Shape n} -> A -> IO A s s
return = Return
writeIORef : {n : Nat}{s : Shape n}{a : U} ->
IORef s a -> el a -> IO Unit s s
writeIORef (ioRef r) x = WriteIORef r x (Return unit)
readIORef : {n : Nat}{s : Shape n}{a : U} -> IORef s a -> IO (el a) s s
readIORef (ioRef r) = ReadIORef r Return
newIORef : {n : Nat}{s : Shape n}{a : U} -> el a -> IO (IORef (s || a) a) s (s || a)
newIORef x = NewIORef x (Return (ioRef fz))
-- Some nice properties
infix 10 _==_ _≡_
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
subst : {A : Set}(P : A -> Set){x y : A} -> x == y -> P y -> P x
subst {A} P refl Px = Px
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong {A} f refl = refl
trans : {A : Set}{x y z : A} -> x == y -> y == z -> x == z
trans {A} refl p = p
fsteq : {A B : Set}{x y : A}{z w : B} -> pair x z == pair y w -> x == y
fsteq {A}{B} refl = refl
-- Lemmas
update-lookup : {n : Nat}{s : Shape n}(h : Heap s)(r : Loc n)(x : el (s ! r)) ->
h [ r := x ] [ r ] == x
update-lookup ε () _
update-lookup (h ▻ _) fz x = refl
update-lookup (h ▻ _) (fs i) x = update-lookup h i x
update-update : {n : Nat}{s : Shape n}(h : Heap s)(r : Loc n)(x y : el (s ! r)) ->
h [ r := x ] [ r := y ] == h [ r := y ]
update-update ε () _ _
update-update (h ▻ _) fz x y = refl
update-update (h ▻ z) (fs i) x y = cong (\ ∙ -> ∙ ▻ z) (update-update h i x y)
-- Equality of monadic computations
data _≡_ {A : Set}{n m : Nat}{s : Shape n}{t : Shape m}(io₁ io₂ : IO A s t) : Set where
eqIO : ((h : Heap s) -> run h io₁ == run h io₂) -> io₁ ≡ io₂
uneqIO : {A : Set}{n m : Nat}{s : Shape n}{t : Shape m}{io₁ io₂ : IO A s t} ->
io₁ ≡ io₂ -> (h : Heap s) -> run h io₁ == run h io₂
uneqIO (eqIO e) = e
-- Congruence properties
cong->> : {A B : Set}{n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃}
{io₁₁ io₁₂ : IO A s₁ s₂}{io₂₁ io₂₂ : A -> IO B s₂ s₃} ->
io₁₁ ≡ io₁₂ -> ((x : A) -> io₂₁ x ≡ io₂₂ x) -> io₁₁ >>= io₂₁ ≡ io₁₂ >>= io₂₂
cong->> {A}{B}{s₁ = s₁}{s₂}{s₃}{io₁₁}{io₁₂}{io₂₁}{io₂₂}(eqIO eq₁) eq₂ =
eqIO (prf io₁₁ io₁₂ io₂₁ io₂₂ eq₁ eq₂)
where
prf : {n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃}
(io₁₁ io₁₂ : IO A s₁ s₂)(io₂₁ io₂₂ : A -> IO B s₂ s₃) ->
((h : Heap s₁) -> run h io₁₁ == run h io₁₂) ->
((x : A) -> io₂₁ x ≡ io₂₂ x) ->
(h : Heap s₁) -> run h (io₁₁ >>= io₂₁) == run h (io₁₂ >>= io₂₂)
prf (Return x) (Return y) k₁ k₂ eq₁ eq₂ h =
subst (\ ∙ -> run h (k₁ ∙) == run h (k₂ y)) x=y (uneqIO (eq₂ y) h)
where
x=y : x == y
x=y = fsteq (eq₁ h)
prf (WriteIORef r₁ x₁ k₁) (Return y) k₂ k₃ eq₁ eq₂ h = ?
-- ... boring proofs
-- Monad laws
-- boring...
-- IO laws
new-read : {n : Nat}{s : Shape n}{a : U}(x : el a) ->
newIORef {s = s} x >>= readIORef ≡
newIORef x >> return x
new-read x = eqIO \h -> refl
write-read : {n : Nat}{s : Shape n}{a : U}(r : IORef s a)(x : el a) ->
writeIORef r x >> readIORef r
≡ writeIORef r x >> return x
write-read (ioRef r) x =
eqIO \h -> cong (\ ∙ -> pair ∙ (h [ r := x ]))
(update-lookup h r x)
write-write : {n : Nat}{s : Shape n}{a : U}(r : IORef s a)(x y : el a) ->
writeIORef r x >> writeIORef r y
≡ writeIORef r y
write-write (ioRef r) x y =
eqIO \h -> cong (\ ∙ -> pair unit ∙) (update-update h r x y)
-- Some separation properties would be nice
|
{
"alphanum_fraction": 0.4751341163,
"avg_line_length": 31.9305555556,
"ext": "agda",
"hexsha": "48bb6ca23bf569f2fe07ce77632c83e18f5a1290",
"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": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/IORef.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"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": "larrytheliquid/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/IORef.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/IORef.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2876,
"size": 6897
}
|
{-# OPTIONS --cubical --no-import-sorts --prop #-}
module Utils where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
open import Function.Base
variable
ℓ ℓ' ℓ'' : Level
module Test where
import Algebra.Properties.BooleanAlgebra
open import Algebra.Bundles
module _ (B : BooleanAlgebra ℓ ℓ') where
open BooleanAlgebra B
open import Algebra.Definitions _≈_
∨-complementˡ : LeftInverse ⊤ ¬_ _∨_
∨-complementˡ = {! comm+invʳ⇒invˡ ∨-comm ∨-complementʳ !}
∨-complement : Inverse ⊤ ¬_ _∨_
∨-complement = {! ∨-complementˡ , ∨-complementʳ !}
∧-complementˡ : LeftInverse ⊥ ¬_ _∧_
∧-complementˡ = {! comm+invʳ⇒invˡ ∧-comm ∧-complementʳ !}
∧-complement : Inverse ⊥ ¬_ _∧_
∧-complement = {! ∧-complementˡ , ∧-complementʳ !}
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
-- open import Cubical.Structures.CommRing
-- open import Cubical.Relation.Nullary.Base -- ¬_
-- open import Cubical.Relation.Binary.Base
-- open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
-- open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
-- -- open import Cubical.Structures.Poset
-- open import Cubical.Foundations.Function
-- open import Function.Base using (_∋_)
-- open import Function.Base using (it) -- instance search
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Logic
-- open import Algebra.Definitions
-- open import Cubical.Data.Empty
open import Cubical.HITs.PropositionalTruncation
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Unit.Base
⊥↑ : ∀{ℓ} → hProp ℓ
⊥↑ = Lift ⊥.⊥ , λ ()
⊤↑ : ∀{ℓ} → hProp ℓ
⊤↑ = Lift Unit , isOfHLevelLift 1 (λ _ _ _ → tt)
-- _ = {! ⇔toPath!}
⊔-complementˡ : ∀ x → ¬ x ⊔ x ≡ ⊤↑ -- LeftInverse _≡_ ⊤ ¬_ _⊔_
⊔-complementˡ = {! comm+invʳ⇒invˡ ⊔-comm ⊔-complementʳ !}
-- ⊔-complementʳ : ∀ x → x ⊔ ¬ x ≡ ∥ [ ⊤ ] ∥ₚ
-- ⊔-complementʳ : ∀(x : hProp ℓ) → x ⊔ ¬ x ≡ ((hProp ℓ) ∋ ⊤)
⊔-complementʳ : ∀(x : hProp ℓ) → x ⊔ ¬ x ≡ ⊤↑
⊔-complementʳ x = λ i → {! ⊔-comm x (¬ x) i !}
⊔-complement : (∀ x → ¬ x ⊔ x ≡ ⊤↑) × (∀ x → x ⊔ ¬ x ≡ ⊤↑) -- Inverse _≡_ ⊤ ¬_ _⊔_
⊔-complement = ⊔-complementˡ , {! ⊔-complementʳ !}
-- agda deduces
-- Σ Type (λ A → (x y : A) → x ≡ y)
-- hProp normalizes to
-- λ ℓ → Σ (Type ℓ) (λ A → (x y : A) → x ≡ y)
--
⊓-complementˡ : ∀ x → ¬ x ⊓ x ≡ ⊥ -- LeftInverse _≡_ ⊥ ¬_ _⊓_
⊓-complementˡ = {! isProp!} -- comm+invʳ⇒invˡ ⊓-comm ⊓-complementʳ
⊓-complementʳ : ∀ x → x ⊓ ¬ x ≡ ⊥
⊓-complementʳ = {!!}
⊓-complement : (∀ x → ¬ x ⊓ x ≡ ⊥) × (∀ x → x ⊓ ¬ x ≡ ⊥) -- Inverse _≡_ ⊥ ¬_ _⊓_
⊓-complement = ⊓-complementˡ , ⊓-complementʳ
⊓-⊔-distribʳ : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'')
→ (Q ⊔ R) ⊓ P ≡ (Q ⊓ P) ⊔ (R ⊓ P)
⊓-⊔-distribʳ P Q R = (
(Q ⊔ R) ⊓ P ≡⟨ ⊓-comm _ _ ⟩
P ⊓ (Q ⊔ R) ≡⟨ ⊓-⊔-distribˡ P Q R ⟩
(P ⊓ Q) ⊔ (P ⊓ R) ≡⟨ ( λ i → ⊓-comm P Q i ⊔ ⊓-comm P R i) ⟩
(Q ⊓ P) ⊔ (R ⊓ P) ∎)
_ : isProp ≡ (λ(A : Type ℓ) → (x y : A) → x ≡ y)
_ = refl
-- `sq` stands for "squashed" and |_| is the constructor for ∥_∥
--
-- data ∥_∥ {ℓ} (A : Type ℓ) : Type ℓ where
-- ∣_∣ : A → ∥ A ∥
-- squash : ∀ (x y : ∥ A ∥) → x ≡ y
--
-- (see https://ice1000.org/2018/12-06-CubicalAgda.html#propositional-truncation )
-- we also have
--
-- hProp ℓ = Σ[ A ∈ Type ℓ ] (∀( x y : A) → x ≡ y)
-- isContr {ℓ} = λ( A : Type ℓ ) → Σ[ x ∈ A ] (∀ y → x ≡ y)
-- isProp {ℓ} = λ( A : Type ℓ ) → ∀( x y : A) → x ≡ y
--
-- and in `Cubical.Foundations.Id` we have
--
-- postulate
-- Id : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
-- _≡_ : ∀ {ℓ} {A : Type ℓ} → A → A → Type ℓ
-- _≡_ = Id
--
-- which is imported in `Cubical.Foundations.Everything`, but _≡_ is hidden in favour of the _≡_ from `Agda.Builtin.Cubical.Path`:
--
-- _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
-- _≡_ {A = A} = PathP (λ i → A)
--
-- we have conversion functions between `Id` and `PathP`
-- recall from https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html
--
-- is-center X c = (x : X) → c ≡ x
-- is-singleton X = Σ c ꞉ X , is-center X c
-- is-subsingleton X = (x y : X) → x ≡ y
-- 𝟘-is-subsingleton : is-subsingleton 𝟘
-- singletons-are-subsingletons : (X : 𝓤 ̇ ) → is-singleton X → is-subsingleton X
-- 𝟙-is-subsingleton : is-subsingleton 𝟙
--
-- now,
-- see https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#axiomatic-approach
-- see https://ice1000.org/2018/12-06-CubicalAgda.html#propositional-truncation
-- However I would not only use recPropTrunc explicitly as we can just use pattern-matching to define functions out of HITs.
-- see https://cstheory.stackexchange.com/questions/30542/squash-type-vs-propositional-truncation-type
-- Squash types correspond to judgmental truncation, not propositional truncation.
-- In a type theory without a type for judgmental equality, there's non much of a way to make use of an inhabitant of a squash type;
-- there's no way to write an eliminator into any type except another squash type.
-- Relatedly, having squash types, as presented in the book you linked, makes typechecking undecidable;
-- having propositional truncation types does not result in this drawback.
-- there is https://github.com/agda/cubical/pull/136
-- Elimination of propositional truncation to higher types
import Cubical.Foundations.Id
import Cubical.HITs.PropositionalTruncation.Properties -- look here for examples
∥∥-isProp : {A : Type ℓ} → ∀ (x y : ∥ A ∥) → x ≡ y
∥∥-isProp {ℓ = ℓ} {A = A} x y = (squash x y)
_ = propTruncIsProp
propTruncIsProp' : {A : Type ℓ} → isProp ∥ A ∥
propTruncIsProp' x y = squash x y
{-
t0 : {A : Type ℓ} → (x y : ∥ A ∥) → x ≡ y -- isProp (∥ A ∥)
t0 x ∣ y ∣ = squash x ∣ y ∣
-- Goal: ∥ A ∥
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ t0 x y₀ j
-- i = i1 ⊢ t0 x y₁ j
-- j = i0 ⊢ x
-- j = i1 ⊢ squash y₀ y₁ i
t0 x (squash y₀ y₁ i) j = {! t0 !}
-}
{-
-- Goal: ∣ x ∣ ≡ ∣ y ∣
t0 ∣ x ∣ ∣ y ∣ = squash ∣ x ∣ ∣ y ∣
-- Goal: ∣ x ∣ ≡ squash y₀ y₁ i
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ t0 ∣ x ∣ y₀
-- i = i1 ⊢ t0 ∣ x ∣ y₁
t0 ∣ x ∣ (squash y₀ y₁ i) = squash ∣ x ∣ (squash y₀ y₁ i) -- {! squash ∣ x ∣ (squash y₀ y₁ i)!} -- {! λ j → squash ∣ x ∣ (squash y₁ y₂ j) {! !} !}
t0 (squash x₁ x₂ i) ∣ y ∣ = squash (squash x₁ x₂ i) ∣ y ∣
t0 (squash x₁ x₂ i) (squash y₁ y₂ j) = squash (squash x₁ x₂ i) (squash y₁ y₂ j)
-}
-- Definition 2.4.3. The propositional truncation of a type X
-- is a proposition ∥ X ∥
-- together with a truncation map |_| : X → ∥ X ∥
-- such that for any other proposition Q, given a map g : X → Q, we obtain a map h : ∥ X ∥ → Q.
--
-- Remark 2.4.4. The uniqueness of the obtained map ∥ X ∥ → Q follows from the fact that Q is a proposition, and function extensionality
--
-- The propositional truncation ∥ X ∥ of a type X is a proposition. We may say, quite simply,
-- that we have a constructor sq which is a proof that the type ∥ X ∥ is a squashed to be a propo-
-- sition: it takes two elements of ∥ X ∥ and gives a proof that they are identical, i.e. squashed
-- together.
-- Definition 2.4.7.
-- We refer to types that are propositions as properties.
-- We refer to types that potentially have several witnesses as structure.
{-
module _ {ℓ} (X Y : Type ℓ) (g : X → Y) where
f : ∥ X ∥ → Y
f ∣ x ∣ = g x
f (squash x₀ x₁ i) = {! !}
-}
-- well, that might not work at all
-- ⊓-unliftˡ : {P : hProp ℓ} {Q : hProp ℓ'}
import Cubical.HITs.PropositionalTruncation.Properties
-- _ : (P : hProp P.ℓ) (Q : hProp Q.ℓ) (R : hProp R.ℓ) → (hProp P.ℓ → hProp Q.ℓ → hProp R.ℓ) → h
-- _ = ?
--_ = _≡ₚ_
⊓-identityˡ-↑ : (P : hProp ℓ) → ⊤↑ {ℓ} ⊓ P ≡ P
⊓-identityˡ-↑ _ = ⇔toPath snd λ x → lift tt , x
-- \ is \\
-- ↑ is \u
private
lemma : ∀ x y → x ⊓ y ≡ ⊥ → x ⊔ y ≡ ⊤ → ¬ x ≡ y
lemma x y x⊓y=⊥ x⊔y=⊤ = (
¬ x ≡⟨ sym (⊓-identityʳ _) ⟩
¬ x ⊓ ⊤ ≡⟨ (λ i → ¬ x ⊓ x⊔y=⊤ (~ i) ) ⟩
¬ x ⊓ (x ⊔ y) ≡⟨ ⊓-⊔-distribˡ (¬ x) x y ⟩
(¬ x ⊓ x) ⊔ (¬ x ⊓ y) ≡⟨ (λ i → ⊓-complementˡ x i ⊔ (¬ x ⊓ y)) ⟩
⊥ ⊔ (¬ x ⊓ y) ≡⟨ (λ i → x⊓y=⊥ (~ i) ⊔ (¬ x ⊓ y)) ⟩
(x ⊓ y) ⊔ (¬ x ⊓ y) ≡⟨ sym (⊓-⊔-distribʳ y x (¬ x)) ⟩
(x ⊔ ¬ x) ⊓ y ≡⟨ (λ i → (⊔-complementʳ x) i ⊓ y ) ⟩
⊤↑ ⊓ y ≡⟨ ⊓-identityˡ-↑ _ ⟩
y ∎)
data Prop2Type (P : Prop ℓ) : Type (ℓ-suc ℓ) where
inₚ : (p : P) → Prop2Type P
Prop-to-hProp : Prop ℓ → hProp (ℓ-suc ℓ)
Prop-to-hProp P = Prop2Type P , λ{ (inₚ x) (inₚ y) → refl }
|
{
"alphanum_fraction": 0.5589310187,
"avg_line_length": 35.3064516129,
"ext": "agda",
"hexsha": "909a9360d80057710973251496fc7f5c20cca315",
"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": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "test/Utils.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"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": "mchristianl/synthetic-reals",
"max_issues_repo_path": "test/Utils.agda",
"max_line_length": 148,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "test/Utils.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 3736,
"size": 8756
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some code related to propositional equality that relies on the K
-- rule
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Relation.Binary.PropositionalEquality.WithK where
open import Axiom.UniquenessOfIdentityProofs.WithK
open import Relation.Binary
open import Relation.Binary.PropositionalEquality.Core
------------------------------------------------------------------------
-- Re-exporting safe erasure function
-- ≡-erase ignores its `x ≡ y` argument and reduces to refl whenever
-- x and y are judgmentally equal. This is useful when the computation
-- producing the proof `x ≡ y` is expensive.
open import Agda.Builtin.Equality.Erase
using ()
renaming ( primEraseEquality to ≡-erase )
public
------------------------------------------------------------------------
-- Proof irrelevance
≡-irrelevant : ∀ {a} {A : Set a} → Irrelevant {A = A} _≡_
≡-irrelevant = uip
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.0
≡-irrelevance = ≡-irrelevant
{-# WARNING_ON_USAGE ≡-irrelevance
"Warning: ≡-irrelevance was deprecated in v1.0.
Please use ≡-irrelevant instead."
#-}
|
{
"alphanum_fraction": 0.5189189189,
"avg_line_length": 31.4893617021,
"ext": "agda",
"hexsha": "446b596c1c75e19534386a955e55ce12d677e8d9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/PropositionalEquality/WithK.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/PropositionalEquality/WithK.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/PropositionalEquality/WithK.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": 300,
"size": 1480
}
|
{-# OPTIONS --without-K --exact-split #-}
module 13-circle where
import 12-univalence
open 12-univalence public
{- Section 11.1 The induction principle of the circle -}
free-loops :
{ l1 : Level} (X : UU l1) → UU l1
free-loops X = Σ X (λ x → Id x x)
base-free-loop :
{ l1 : Level} {X : UU l1} → free-loops X → X
base-free-loop = pr1
loop-free-loop :
{ l1 : Level} {X : UU l1} (l : free-loops X) →
Id (base-free-loop l) (base-free-loop l)
loop-free-loop = pr2
-- Now we characterize the identity types of free loops
Eq-free-loops :
{ l1 : Level} {X : UU l1} (l l' : free-loops X) → UU l1
Eq-free-loops (pair x l) l' =
Σ (Id x (pr1 l')) (λ p → Id (l ∙ p) (p ∙ (pr2 l')))
reflexive-Eq-free-loops :
{ l1 : Level} {X : UU l1} (l : free-loops X) → Eq-free-loops l l
reflexive-Eq-free-loops (pair x l) = pair refl right-unit
Eq-free-loops-eq :
{ l1 : Level} {X : UU l1} (l l' : free-loops X) →
Id l l' → Eq-free-loops l l'
Eq-free-loops-eq l .l refl = reflexive-Eq-free-loops l
abstract
is-contr-total-Eq-free-loops :
{ l1 : Level} {X : UU l1} (l : free-loops X) →
is-contr (Σ (free-loops X) (Eq-free-loops l))
is-contr-total-Eq-free-loops (pair x l) =
is-contr-total-Eq-structure
( λ x l' p → Id (l ∙ p) (p ∙ l'))
( is-contr-total-path x)
( pair x refl)
( is-contr-is-equiv'
( Σ (Id x x) (λ l' → Id l l'))
( tot (λ l' α → right-unit ∙ α))
( is-equiv-tot-is-fiberwise-equiv
( λ l' → is-equiv-concat right-unit l'))
( is-contr-total-path l))
abstract
is-equiv-Eq-free-loops-eq :
{ l1 : Level} {X : UU l1} (l l' : free-loops X) →
is-equiv (Eq-free-loops-eq l l')
is-equiv-Eq-free-loops-eq l =
fundamental-theorem-id l
( reflexive-Eq-free-loops l)
( is-contr-total-Eq-free-loops l)
( Eq-free-loops-eq l)
dependent-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → UU l2
dependent-free-loops l P =
Σ ( P (base-free-loop l))
( λ p₀ → Id (tr P (loop-free-loop l) p₀) p₀)
Eq-dependent-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) →
( p p' : dependent-free-loops l P) → UU l2
Eq-dependent-free-loops (pair x l) P (pair y p) p' =
Σ ( Id y (pr1 p'))
( λ q → Id (p ∙ q) ((ap (tr P l) q) ∙ (pr2 p')))
reflexive-Eq-dependent-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) →
( p : dependent-free-loops l P) → Eq-dependent-free-loops l P p p
reflexive-Eq-dependent-free-loops (pair x l) P (pair y p) =
pair refl right-unit
Eq-dependent-free-loops-eq :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) →
( p p' : dependent-free-loops l P) →
Id p p' → Eq-dependent-free-loops l P p p'
Eq-dependent-free-loops-eq l P p .p refl =
reflexive-Eq-dependent-free-loops l P p
abstract
is-contr-total-Eq-dependent-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) →
( p : dependent-free-loops l P) →
is-contr (Σ (dependent-free-loops l P) (Eq-dependent-free-loops l P p))
is-contr-total-Eq-dependent-free-loops (pair x l) P (pair y p) =
is-contr-total-Eq-structure
( λ y' p' q → Id (p ∙ q) ((ap (tr P l) q) ∙ p'))
( is-contr-total-path y)
( pair y refl)
( is-contr-is-equiv'
( Σ (Id (tr P l y) y) (λ p' → Id p p'))
( tot (λ p' α → right-unit ∙ α))
( is-equiv-tot-is-fiberwise-equiv
( λ p' → is-equiv-concat right-unit p'))
( is-contr-total-path p))
abstract
is-equiv-Eq-dependent-free-loops-eq :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2)
( p p' : dependent-free-loops l P) →
is-equiv (Eq-dependent-free-loops-eq l P p p')
is-equiv-Eq-dependent-free-loops-eq l P p =
fundamental-theorem-id p
( reflexive-Eq-dependent-free-loops l P p)
( is-contr-total-Eq-dependent-free-loops l P p)
( Eq-dependent-free-loops-eq l P p)
eq-Eq-dependent-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2)
( p p' : dependent-free-loops l P) →
Eq-dependent-free-loops l P p p' → Id p p'
eq-Eq-dependent-free-loops l P p p' =
inv-is-equiv (is-equiv-Eq-dependent-free-loops-eq l P p p')
ev-free-loop' :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) →
( (x : X) → P x) → dependent-free-loops l P
ev-free-loop' (pair x₀ p) P f = pair (f x₀) (apd f p)
induction-principle-circle :
{ l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) →
UU ((lsuc l2) ⊔ l1)
induction-principle-circle l2 {X} l =
(P : X → UU l2) → sec (ev-free-loop' l P)
{- Section 11.2 The universal property of the circle -}
{- We first state the universal property of the circle -}
ev-free-loop :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) →
( X → Y) → free-loops Y
ev-free-loop l Y f = pair (f (pr1 l)) (ap f (pr2 l))
universal-property-circle :
{ l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) → UU _
universal-property-circle l2 l =
( Y : UU l2) → is-equiv (ev-free-loop l Y)
{- A fairly straightforward proof of the universal property of the circle
factors through the dependent universal property of the circle. -}
dependent-universal-property-circle :
{ l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) →
UU ((lsuc l2) ⊔ l1)
dependent-universal-property-circle l2 {X} l =
( P : X → UU l2) → is-equiv (ev-free-loop' l P)
{- We first prove that the dependent universal property of the circle follows
from the induction principle of the circle. To show this, we have to show
that the section of ev-free-loop' is also a retraction. This construction
is also by the induction principle of the circle, but it requires (a minimal
amount of) preparations. -}
Eq-subst :
{ l1 l2 : Level} {X : UU l1} {P : X → UU l2} (f g : (x : X) → P x) →
X → UU _
Eq-subst f g x = Id (f x) (g x)
tr-Eq-subst :
{ l1 l2 : Level} {X : UU l1} {P : X → UU l2} (f g : (x : X) → P x)
{ x y : X} (p : Id x y) (q : Id (f x) (g x)) (r : Id (f y) (g y))→
( Id ((apd f p) ∙ r) ((ap (tr P p) q) ∙ (apd g p))) →
( Id (tr (Eq-subst f g) p q) r)
tr-Eq-subst f g refl q .((ap id q) ∙ refl) refl =
inv (right-unit ∙ (ap-id q))
dependent-free-loops-htpy :
{l1 l2 : Level} {X : UU l1} {l : free-loops X} {P : X → UU l2}
{f g : (x : X) → P x} →
( Eq-dependent-free-loops l P (ev-free-loop' l P f) (ev-free-loop' l P g)) →
( dependent-free-loops l (λ x → Id (f x) (g x)))
dependent-free-loops-htpy {l = (pair x l)} (pair p q) =
pair p (tr-Eq-subst _ _ l p p q)
isretr-ind-circle :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
( ind-circle : induction-principle-circle l2 l) (P : X → UU l2) →
( (pr1 (ind-circle P)) ∘ (ev-free-loop' l P)) ~ id
isretr-ind-circle l ind-circle P f =
eq-htpy
( pr1
( ind-circle
( λ t → Id (pr1 (ind-circle P) (ev-free-loop' l P f) t) (f t)))
( dependent-free-loops-htpy
( Eq-dependent-free-loops-eq l P _ _
( pr2 (ind-circle P) (ev-free-loop' l P f)))))
abstract
dependent-universal-property-induction-principle-circle :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
induction-principle-circle l2 l → dependent-universal-property-circle l2 l
dependent-universal-property-induction-principle-circle l ind-circle P =
is-equiv-has-inverse
( pr1 (ind-circle P))
( pr2 (ind-circle P))
( isretr-ind-circle l ind-circle P)
{- Now that we have established the dependent universal property, we can
reduce the (non-dependent) universal property to the dependent case. We do
so by constructing a commuting triangle relating ev-free-loop to
ev-free-loop' via a comparison equivalence. -}
tr-triv :
{i j : Level} {A : UU i} {B : UU j} {x y : A} (p : Id x y) (b : B) →
Id (tr (λ (a : A) → B) p b) b
tr-triv refl b = refl
apd-triv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y : A}
(p : Id x y) → Id (apd f p) ((tr-triv p (f x)) ∙ (ap f p))
apd-triv f refl = refl
comparison-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) →
free-loops Y → dependent-free-loops l (λ x → Y)
comparison-free-loops l Y =
tot (λ y l' → (tr-triv (pr2 l) y) ∙ l')
abstract
is-equiv-comparison-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) →
is-equiv (comparison-free-loops l Y)
is-equiv-comparison-free-loops l Y =
is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-concat (tr-triv (pr2 l) y) y)
triangle-comparison-free-loops :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) →
( (comparison-free-loops l Y) ∘ (ev-free-loop l Y)) ~
( ev-free-loop' l (λ x → Y))
triangle-comparison-free-loops (pair x l) Y f =
eq-Eq-dependent-free-loops
( pair x l)
( λ x → Y)
( comparison-free-loops (pair x l) Y (ev-free-loop (pair x l) Y f))
( ev-free-loop' (pair x l) (λ x → Y) f)
( pair refl (right-unit ∙ (inv (apd-triv f l))))
abstract
universal-property-dependent-universal-property-circle :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
( dependent-universal-property-circle l2 l) →
( universal-property-circle l2 l)
universal-property-dependent-universal-property-circle l dup-circle Y =
is-equiv-right-factor
( ev-free-loop' l (λ x → Y))
( comparison-free-loops l Y)
( ev-free-loop l Y)
( htpy-inv (triangle-comparison-free-loops l Y))
( is-equiv-comparison-free-loops l Y)
( dup-circle (λ x → Y))
{- Now we get the universal property of the circle from the induction principle
of the circle by composing the earlier two proofs. -}
abstract
universal-property-induction-principle-circle :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
induction-principle-circle l2 l → universal-property-circle l2 l
universal-property-induction-principle-circle l =
( universal-property-dependent-universal-property-circle l) ∘
( dependent-universal-property-induction-principle-circle l)
unique-mapping-property-circle :
{ l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) →
UU (l1 ⊔ (lsuc l2))
unique-mapping-property-circle l2 {X} l =
( Y : UU l2) (l' : free-loops Y) →
is-contr (Σ (X → Y) (λ f → Eq-free-loops (ev-free-loop l Y f) l'))
abstract
unique-mapping-property-universal-property-circle :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
universal-property-circle l2 l →
unique-mapping-property-circle l2 l
unique-mapping-property-universal-property-circle l up-circle Y l' =
is-contr-is-equiv'
( fib (ev-free-loop l Y) l')
( tot (λ f → Eq-free-loops-eq (ev-free-loop l Y f) l'))
( is-equiv-tot-is-fiberwise-equiv
( λ f → is-equiv-Eq-free-loops-eq (ev-free-loop l Y f) l'))
( is-contr-map-is-equiv (up-circle Y) l')
{- We show that if a type with a free loop satisfies the induction principle
of the circle with respect to any universe level, then it satisfies the
induction principle with respect to the zeroth universe level. -}
naturality-tr-fiberwise-transformation :
{ l1 l2 l3 : Level} {X : UU l1} {P : X → UU l2} {Q : X → UU l3}
( f : (x : X) → P x → Q x) {x y : X} (α : Id x y) (p : P x) →
Id (tr Q α (f x p)) (f y (tr P α p))
naturality-tr-fiberwise-transformation f refl p = refl
functor-dependent-free-loops :
{ l1 l2 l3 : Level} {X : UU l1} (l : free-loops X)
{ P : X → UU l2} {Q : X → UU l3} (f : (x : X) → P x → Q x) →
dependent-free-loops l P → dependent-free-loops l Q
functor-dependent-free-loops l {P} {Q} f =
toto
( λ q₀ → Id (tr Q (loop-free-loop l) q₀) q₀)
( f (base-free-loop l))
( λ p₀ α →
( naturality-tr-fiberwise-transformation f (loop-free-loop l) p₀) ∙
( ap (f (base-free-loop l)) α))
coherence-square-functor-dependent-free-loops :
{ l1 l2 l3 : Level} {X : UU l1} {P : X → UU l2} {Q : X → UU l3}
( f : (x : X) → P x → Q x) {x y : X} (α : Id x y)
( h : (x : X) → P x) →
Id ( ( naturality-tr-fiberwise-transformation f α (h x)) ∙
( ap (f y) (apd h α)))
( apd (postcomp-Π f h) α)
coherence-square-functor-dependent-free-loops f refl h = refl
square-functor-dependent-free-loops :
{ l1 l2 l3 : Level} {X : UU l1} (l : free-loops X)
{ P : X → UU l2} {Q : X → UU l3} (f : (x : X) → P x → Q x) →
( (functor-dependent-free-loops l f) ∘ (ev-free-loop' l P)) ~
( (ev-free-loop' l Q) ∘ (postcomp-Π f))
square-functor-dependent-free-loops (pair x l) {P} {Q} f h =
eq-Eq-dependent-free-loops (pair x l) Q
( functor-dependent-free-loops (pair x l) f
( ev-free-loop' (pair x l) P h))
( ev-free-loop' (pair x l) Q (postcomp-Π f h))
( pair refl
( right-unit ∙ (coherence-square-functor-dependent-free-loops f l h)))
abstract
is-equiv-functor-dependent-free-loops-is-fiberwise-equiv :
{ l1 l2 l3 : Level} {X : UU l1} (l : free-loops X)
{ P : X → UU l2} {Q : X → UU l3} {f : (x : X) → P x → Q x}
( is-equiv-f : (x : X) → is-equiv (f x)) →
is-equiv (functor-dependent-free-loops l f)
is-equiv-functor-dependent-free-loops-is-fiberwise-equiv
(pair x l) {P} {Q} {f} is-equiv-f =
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map
( λ q₀ → Id (tr Q l q₀) q₀)
( _)
( _)
( is-equiv-f x)
( λ p₀ →
is-equiv-comp'
( concat
( naturality-tr-fiberwise-transformation f l p₀)
( f x p₀))
( ap (f x))
( is-emb-is-equiv (f x) (is-equiv-f x) (tr P l p₀) p₀)
( is-equiv-concat
( naturality-tr-fiberwise-transformation f l p₀)
( f x p₀)))
abstract
lower-dependent-universal-property-circle :
{ l1 l2 : Level} (l3 : Level) {X : UU l1} (l : free-loops X) →
dependent-universal-property-circle (l2 ⊔ l3) l →
dependent-universal-property-circle l3 l
lower-dependent-universal-property-circle {l1} {l2} l3 l dup-circle P =
is-equiv-left-is-equiv-right-square
( ev-free-loop' l P)
( ev-free-loop' l (λ x → raise l2 (P x)))
( postcomp-Π (λ x → map-raise l2 (P x)))
( functor-dependent-free-loops l (λ x → map-raise l2 (P x)))
( square-functor-dependent-free-loops l (λ x → map-raise l2 (P x)))
( is-equiv-postcomp-Π _ (λ x → is-equiv-map-raise l2 (P x)))
( is-equiv-functor-dependent-free-loops-is-fiberwise-equiv l
( λ x → is-equiv-map-raise l2 (P x)))
( dup-circle (λ x → raise l2 (P x)))
abstract
lower-lzero-dependent-universal-property-circle :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
dependent-universal-property-circle l2 l →
dependent-universal-property-circle lzero l
lower-lzero-dependent-universal-property-circle =
lower-dependent-universal-property-circle lzero
{- The dependent universal property of the circle (and hence also the induction
principle of the circle, implies that the circle is connected in the sense
that for any family of propositions parametrized by the circle, if the
proposition at the base holds, then it holds for any x : circle. -}
{- Exercises -}
-- Exercise 11.1
abstract
is-connected-circle' :
{ l1 l2 : Level} {X : UU l1} (l : free-loops X) →
( dup-circle : dependent-universal-property-circle l2 l)
( P : X → UU l2) (is-prop-P : (x : X) → is-prop (P x)) →
P (base-free-loop l) → (x : X) → P x
is-connected-circle' l dup-circle P is-prop-P p =
inv-is-equiv
( dup-circle P)
( pair p (center (is-prop-P _ (tr P (pr2 l) p) p)))
|
{
"alphanum_fraction": 0.5962471692,
"avg_line_length": 37.8799019608,
"ext": "agda",
"hexsha": "a50486854e66897b6227a7085a8fe33adacf680f",
"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": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tadejpetric/HoTT-Intro",
"max_forks_repo_path": "Agda/13-circle.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5",
"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": "tadejpetric/HoTT-Intro",
"max_issues_repo_path": "Agda/13-circle.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tadejpetric/HoTT-Intro",
"max_stars_repo_path": "Agda/13-circle.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5500,
"size": 15455
}
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.Fin.Literals where
open import Agda.Builtin.Nat
using (suc)
open import Agda.Builtin.FromNat
renaming (Number to HasFromNat)
open import Cubical.Data.Fin.Base
using (Fin; fromℕ≤)
open import Cubical.Data.Nat.Order.Recursive
using (_≤_)
instance
fromNatFin : {n : _} → HasFromNat (Fin (suc n))
fromNatFin {n} = record
{ Constraint = λ m → m ≤ n
; fromNat = λ m ⦃ m≤n ⦄ → fromℕ≤ m n m≤n
}
|
{
"alphanum_fraction": 0.6666666667,
"avg_line_length": 26.5263157895,
"ext": "agda",
"hexsha": "f32eb5f12156f0750d984d8f8523e02744ef4e80",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Fin/Literals.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/Data/Fin/Literals.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Fin/Literals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 177,
"size": 504
}
|
{- Diamond operator. -}
module TemporalOps.Diamond.Functor where
open import CategoryTheory.Categories
open import CategoryTheory.Instances.Reactive
open import CategoryTheory.Functor
open import TemporalOps.Common
open import TemporalOps.Next
open import TemporalOps.Delay
open import Data.Product
-- Arbitrary delay
◇_ : τ -> τ
(◇ A) n = Σ[ k ∈ ℕ ] (delay A by k at n)
infixr 65 ◇_
-- ◇ instances
F-◇ : Endofunctor ℝeactive
F-◇ = record
{ omap = ◇_
; fmap = fmap-◇
; fmap-id = fmap-◇-id
; fmap-∘ = fmap-◇-∘
; fmap-cong = fmap-◇-cong
}
where
-- Lifting of ◇
fmap-◇ : {A B : τ} -> A ⇴ B -> ◇ A ⇴ ◇ B
fmap-◇ f n (k , v) = k , (Functor.fmap (F-delay k) f at n) v
-- ◇ preserves identities
fmap-◇-id : ∀ {A : τ} {n : ℕ} {a : (◇ A) n}
-> (fmap-◇ (id {A}) at n) a ≡ a
fmap-◇-id {A} {n} {zero , v} = refl
fmap-◇-id {A} {zero} {suc k , v} = refl
fmap-◇-id {A} {suc n} {suc k , v}
rewrite delay-+ {A} 1 k n
| Functor.fmap-id (F-delay (suc k)) {A} {suc n} {v}
= refl
-- ◇ preserves composition
fmap-◇-∘ : ∀ {A B C : τ} {g : B ⇴ C} {f : A ⇴ B} {n : ℕ} {a : (◇ A) n}
-> (fmap-◇ (g ∘ f) at n) a ≡ (fmap-◇ g ∘ fmap-◇ f at n) a
fmap-◇-∘ {n = n} {zero , v} = refl
fmap-◇-∘ {n = zero} {suc k , v} = refl
fmap-◇-∘ {A} {B} {C} {g} {f} {suc n} {suc k , v}
rewrite delay-+ {A} 1 k n
| Functor.fmap-∘ (F-delay (suc k)) {A} {B} {C} {g} {f} {suc n} {v}
= refl
-- ▹ is congruent
fmap-◇-cong : ∀{A B : τ} {f f′ : A ⇴ B}
-> ({n : ℕ} {a : A at n} -> f n a ≡ f′ n a)
-> ({n : ℕ} {a : ◇ A at n} -> (fmap-◇ f at n) a
≡ (fmap-◇ f′ at n) a)
fmap-◇-cong {A} e {n} {zero , a}
rewrite delay-+-left0 {A} 0 n
| e {n} {a} = refl
fmap-◇-cong e {zero} {suc k , a} = refl
fmap-◇-cong {A} {B} {f} {f′} e {suc n} {suc k , a}
rewrite delay-+ {A} 1 k n
| Functor.fmap-cong (F-delay (suc k)) {A} {B} {f} {f′} e {suc n} {a}
= refl
|
{
"alphanum_fraction": 0.4533838145,
"avg_line_length": 33.5396825397,
"ext": "agda",
"hexsha": "9f4244c8ea7cf3ad87cc6e41389a4f173a616d3d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/TemporalOps/Diamond/Functor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/TemporalOps/Diamond/Functor.agda",
"max_line_length": 82,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/TemporalOps/Diamond/Functor.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 921,
"size": 2113
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SmashProduct.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.Pushout.Base
open import Cubical.Data.Unit
open import Cubical.Data.Prod
open import Cubical.HITs.Wedge
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
data Smash {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') : Type (ℓ-max ℓ ℓ') where
basel : Smash A B
baser : Smash A B
proj : (x : typ A) → (y : typ B) → Smash A B
gluel : (a : typ A) → proj a (pt B) ≡ basel
gluer : (b : typ B) → proj (pt A) b ≡ baser
private
variable
ℓ ℓ' : Level
A B C D : Pointed ℓ
Smash-map : (f : A →∙ C) (g : B →∙ D) → Smash A B → Smash C D
Smash-map f g basel = basel
Smash-map f g baser = baser
Smash-map (f , fpt) (g , gpt) (proj x y) = proj (f x) (g y)
Smash-map (f , fpt) (g , gpt) (gluel a i) = ((λ j → proj (f a) (gpt j)) ∙ gluel (f a)) i
Smash-map (f , fpt) (g , gpt) (gluer b i) = ((λ j → proj (fpt j) (g b)) ∙ gluer (g b)) i
-- Commutativity
comm : Smash A B → Smash B A
comm basel = baser
comm baser = basel
comm (proj x y) = proj y x
comm (gluel a i) = gluer a i
comm (gluer b i) = gluel b i
commK : (x : Smash A B) → comm (comm x) ≡ x
commK basel = refl
commK baser = refl
commK (proj x y) = refl
commK (gluel a x) = refl
commK (gluer b x) = refl
-- WIP below
SmashPt : (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
SmashPt A B = (Smash A B , basel)
SmashPtProj : (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
SmashPtProj A B = Smash A B , (proj (snd A) (snd B))
--- Alternative definition
i∧ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} → A ⋁ B → (typ A) × (typ B)
i∧ {A = A , ptA} {B = B , ptB} (inl x) = x , ptB
i∧ {A = A , ptA} {B = B , ptB} (inr x) = ptA , x
i∧ {A = A , ptA} {B = B , ptB} (push tt i) = ptA , ptB
_⋀_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Type (ℓ-max ℓ ℓ')
A ⋀ B = Pushout {A = (A ⋁ B)} (λ _ → tt) i∧
_⋀∙_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Pointed (ℓ-max ℓ ℓ')
A ⋀∙ B = Pushout {A = (A ⋁ B)} (λ _ → tt) i∧ , (inl tt)
_⋀→_ : (f : A →∙ C) (g : B →∙ D) → A ⋀ B → C ⋀ D
(f ⋀→ g) (inl tt) = inl tt
((f , fpt) ⋀→ (g , gpt)) (inr (x , x₁)) = inr (f x , g x₁)
_⋀→_ {B = B} {D = D} (f , fpt) (b , gpt) (push (inl x) i) = (push (inl (f x)) ∙ (λ i → inr (f x , gpt (~ i)))) i
_⋀→_ (f , fpt) (g , gpt) (push (inr x) i) = (push (inr (g x)) ∙ (λ i → inr (fpt (~ i) , g x))) i
_⋀→_ {A = A} {C = C} {B = B} {D = D} (f , fpt) (g , gpt) (push (push tt j) i) =
hcomp (λ k → λ { (i = i0) → inl tt
; (i = i1) → inr (fpt (~ k) , gpt (~ k))
; (j = i0) → compPath-filler (push (inl (fpt (~ k))))
((λ i → inr (fpt (~ k) , gpt (~ i)))) k i
; (j = i1) → compPath-filler (push (inr (gpt (~ k))))
((λ i → inr (fpt (~ i) , gpt (~ k)))) k i})
(push (push tt j) i)
⋀→Smash : A ⋀ B → Smash A B
⋀→Smash (inl x) = basel
⋀→Smash (inr (x , x₁)) = proj x x₁
⋀→Smash (push (inl x) i) = gluel x (~ i)
⋀→Smash {A = A} {B = B} (push (inr x) i) = (sym (gluel (snd A)) ∙∙ gluer (snd B) ∙∙ sym (gluer x)) i
⋀→Smash {A = A} {B = B} (push (push a j) i) =
hcomp (λ k → λ { (i = i0) → gluel (snd A) (k ∨ ~ j)
; (i = i1) → gluer (snd B) (~ k ∧ j)
; (j = i0) → gluel (snd A) (~ i)})
(invSides-filler (gluel (snd A)) (gluer (snd B)) j (~ i))
Smash→⋀ : Smash A B → A ⋀ B
Smash→⋀ basel = inl tt
Smash→⋀ baser = inl tt
Smash→⋀ (proj x y) = inr (x , y)
Smash→⋀ (gluel a i) = push (inl a) (~ i)
Smash→⋀ (gluer b i) = push (inr b) (~ i)
{- associativity maps for smash produts. Proof pretty much direcly translated from https://github.com/ecavallo/redtt/blob/master/library/pointed/smash.red -}
private
pivotl : (b b' : typ B)
→ Path (Smash A B) (proj (snd A) b) (proj (snd A) b')
pivotl b b' i = (gluer b ∙ sym (gluer b')) i
pivotr : (a a' : typ A)
→ Path (Smash A B) (proj a (snd B)) (proj a' (snd B))
pivotr a a' i = (gluel a ∙ sym (gluel a')) i
pivotlrId : {A : Pointed ℓ} {B : Pointed ℓ'} → _
pivotlrId {A = A} {B = B} = rCancel (gluer (snd B)) ∙ sym (rCancel (gluel (snd A)))
rearrange-proj : (c : fst C)
→ (Smash A B) → Smash (SmashPtProj C B) A
rearrange-proj c basel = baser
rearrange-proj c baser = basel
rearrange-proj c (proj x y) = proj (proj c y) x
rearrange-proj {C = C} c (gluel a i) =
hcomp (λ k → λ { (i = i0) → proj (pivotr (snd C) c k) a
; (i = i1) → baser})
(gluer a i)
rearrange-proj c (gluer b i) = gluel (proj c b) i
rearrange-gluel : (s : Smash A B)
→ Path (Smash (SmashPtProj C B) A) basel (rearrange-proj (snd C) s)
rearrange-gluel {A = A} {B = B} {C = C} basel = sym (gluel (proj (snd C) (snd B))) ∙
gluer (snd A)
rearrange-gluel baser = refl
rearrange-gluel {A = A} {B = B} {C = C} (proj a b) i =
hcomp (λ k → λ { (i = i0) → (sym (gluel (proj (snd C) (snd B))) ∙
gluer (snd A)) (~ k)
; (i = i1) → proj (pivotl (snd B) b k) a})
(gluer a (~ i))
rearrange-gluel {A = A} {B = B} {C = C} (gluel a i) j =
hcomp (λ k → λ { (i = i1) → ((λ i₁ → gluel (proj (snd C) (snd B)) (~ i₁)) ∙
gluer (snd A)) (~ k ∨ j)
; (j = i0) → ((λ i₁ → gluel (proj (snd C) (snd B)) (~ i₁)) ∙
gluer (snd A)) (~ k)
; (j = i1) → top-filler i k})
(gluer a (i ∨ ~ j))
where
top-filler : I → I → Smash (SmashPtProj C B) A
top-filler i j =
hcomp (λ k → λ { (i = i0) → side-filler k j
; (i = i1) → gluer a (j ∨ k)
; (j = i0) → gluer a (i ∧ k)})
(gluer a (i ∧ j))
where
side-filler : I → I → Smash (SmashPtProj C B) A
side-filler i j =
hcomp (λ k → λ { (i = i0) → proj (proj (snd C) (snd B)) a
; (i = i1) → proj ((rCancel (gluel (snd C)) ∙ sym (rCancel (gluer (snd B)))) k j) a
; (j = i0) → proj (proj (snd C) (snd B)) a
; (j = i1) → (proj ((gluel (snd C) ∙ sym (gluel (snd C))) i) a)})
(proj ((gluel (snd C) ∙ sym (gluel (snd C))) (j ∧ i)) a)
rearrange-gluel {A = A} {B = B} {C = C} (gluer b i) j =
hcomp (λ k → λ {(i = i1) → ((sym (gluel (proj (snd C) (snd B)))) ∙ gluer (snd A)) (~ k)
; (j = i0) → ((sym (gluel (proj (snd C) (snd B)))) ∙ gluer (snd A)) (~ k)
; (j = i1) → top-filler1 i k})
(gluer (snd A) (i ∨ (~ j)))
where
top-filler1 : I → I → Smash (SmashPtProj C B) A
top-filler1 i j =
hcomp (λ k → λ { (i = i0) → congFunct (λ x → proj x (snd A)) (gluer (snd B)) (sym (gluer b)) (~ k) j
; (i = i1) → (sym (gluel (proj (snd C) (snd B))) ∙ gluer (snd A)) (~ j)
; (j = i0) → gluer (snd A) i
; (j = i1) → gluel (proj (snd C) b) i})
(top-filler2 i j)
where
top-filler2 : I → I → Smash (SmashPtProj C B) A
top-filler2 i j =
hcomp (λ k → λ { (j = i0) → gluer (snd A) (i ∧ k)
; (j = i1) → gluel (gluer b (~ k)) i})
(hcomp (λ k → λ { (j = i0) → gluel (gluer (snd B) i0) (~ k ∧ (~ i))
; (j = i1) → gluel (baser) (~ k ∨ i)
; (i = i0) → gluel (gluer (snd B) j) (~ k)
; (i = i1) → gluel (proj (snd C) (snd B)) j })
(gluel (proj (snd C) (snd B)) (j ∨ (~ i))))
rearrange : Smash (SmashPtProj A B) C → Smash (SmashPtProj C B) A
rearrange basel = basel
rearrange baser = baser
rearrange (proj x y) = rearrange-proj y x
rearrange (gluel a i) = rearrange-gluel a (~ i)
rearrange {A = A} {B = B} {C = C} (gluer b i) = ((λ j → proj (pivotr b (snd C) j) (snd A)) ∙
gluer (snd A)) i
⋀∙→SmashPtProj : (A ⋀∙ B) →∙ SmashPtProj A B
⋀∙→SmashPtProj {A = A} {B = B} = fun , refl
where
fun : (A ⋀ B) → Smash A B
fun (inl x) = proj (snd A) (snd B)
fun (inr (x , x₁)) = proj x x₁
fun (push (inl x) i) = pivotr (snd A) x i
fun (push (inr x) i) = pivotl (snd B) x i
fun (push (push a j) i) = pivotlrId (~ j) i
SmashPtProj→⋀∙ : (SmashPtProj A B) →∙ (A ⋀∙ B)
SmashPtProj→⋀∙ {A = A} {B = B} = Smash→⋀ , sym (push (inr (snd B)))
SmashAssociate : Smash (SmashPtProj A B) C → Smash A (SmashPtProj B C)
SmashAssociate = comm ∘ Smash-map (comm , refl) (idfun∙ _) ∘ rearrange
SmashAssociate⁻ : Smash A (SmashPtProj B C) → Smash (SmashPtProj A B) C
SmashAssociate⁻ = rearrange ∘ comm ∘ Smash-map (idfun∙ _) (comm , refl)
⋀-associate : (A ⋀∙ B) ⋀ C → A ⋀ (B ⋀∙ C)
⋀-associate = (idfun∙ _ ⋀→ SmashPtProj→⋀∙) ∘ Smash→⋀ ∘ SmashAssociate ∘ ⋀→Smash ∘ (⋀∙→SmashPtProj ⋀→ idfun∙ _)
⋀-associate⁻ : A ⋀ (B ⋀∙ C) → (A ⋀∙ B) ⋀ C
⋀-associate⁻ = (SmashPtProj→⋀∙ ⋀→ idfun∙ _) ∘ Smash→⋀ ∘ SmashAssociate⁻ ∘ ⋀→Smash ∘ (idfun∙ _ ⋀→ ⋀∙→SmashPtProj)
|
{
"alphanum_fraction": 0.4732947233,
"avg_line_length": 43.5700934579,
"ext": "agda",
"hexsha": "ac90a41c182f3eea7ce1dd2d049cb5e1de2f757d",
"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/HITs/SmashProduct/Base.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/HITs/SmashProduct/Base.agda",
"max_line_length": 157,
"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/HITs/SmashProduct/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3908,
"size": 9324
}
|
module Issue616 where
open import Common.Coinduction
const : ∀ {a b}{A : Set a}{B : Set b} → A → B → A
const x _ = x
-- The recursive call should be ignored by the termination checker,
-- since ♭ is a projection function and shouldn't store its implicit
-- arguments.
contrived : Set₁
contrived = ♭ {A = const _ contrived} (♯ Set)
|
{
"alphanum_fraction": 0.6895522388,
"avg_line_length": 23.9285714286,
"ext": "agda",
"hexsha": "12c5395b526e652d3ae827e210e8708887ace9a0",
"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/Issue616.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/Issue616.agda",
"max_line_length": 68,
"max_stars_count": 3,
"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/Issue616.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": 97,
"size": 335
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Cocomplete.Finitely
module Categories.Category.Cocomplete.Finitely.Properties {o ℓ e} {C : Category o ℓ e} (finite : FinitelyCocomplete C) where
open import Categories.Category.Duality C
private
module C = Category C
open C
open import Categories.Category.Finite.Fin
open import Categories.Category.Complete.Finitely C.op
open import Categories.Category.Complete.Finitely.Properties (FinitelyCocomplete⇒coFinitelyComplete finite)
open import Categories.Diagram.Colimit
open import Categories.Diagram.Limit
open import Categories.Diagram.Duality C
open import Categories.Functor
finiteColimit : (shape : FinCatShape) (F : Functor (FinCategory shape) C) → Colimit F
finiteColimit shape F = coLimit⇒Colimit (finiteLimit shape.op F.op)
where module shape = FinCatShape shape
module F = Functor F
|
{
"alphanum_fraction": 0.7958287596,
"avg_line_length": 35.0384615385,
"ext": "agda",
"hexsha": "4606c17155f211e6602e4dac1e63ebb3d416d20b",
"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/Cocomplete/Finitely/Properties.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/Cocomplete/Finitely/Properties.agda",
"max_line_length": 124,
"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/Cocomplete/Finitely/Properties.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": 215,
"size": 911
}
|
------------------------------------------------------------------------
-- Some algebraic structures (not packed up with sets, operations,
-- etc.)
------------------------------------------------------------------------
open import Relation.Binary
module Algebra.Structures where
import Algebra.FunctionProperties as FunctionProperties
open FunctionProperties using (Op₁; Op₂)
import Relation.Binary.EqReasoning as EqR
open import Data.Function
open import Data.Product
------------------------------------------------------------------------
-- One binary operation
record IsSemigroup {A} (≈ : Rel A) (∙ : Op₂ A) : Set where
open FunctionProperties ≈
field
isEquivalence : IsEquivalence ≈
assoc : Associative ∙
∙-pres-≈ : ∙ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
open IsEquivalence isEquivalence public
record IsMonoid {A} (≈ : Rel A) (∙ : Op₂ A) (ε : A) : Set where
open FunctionProperties ≈
field
isSemigroup : IsSemigroup ≈ ∙
identity : Identity ε ∙
open IsSemigroup isSemigroup public
record IsCommutativeMonoid
{A} (≈ : Rel A) (∙ : Op₂ A) (ε : A) : Set where
open FunctionProperties ≈
field
isMonoid : IsMonoid ≈ ∙ ε
comm : Commutative ∙
open IsMonoid isMonoid public
record IsGroup
{A} (≈ : Rel A) (_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set where
open FunctionProperties ≈
infixl 7 _-_
field
isMonoid : IsMonoid ≈ _∙_ ε
inverse : Inverse ε _⁻¹ _∙_
⁻¹-pres-≈ : _⁻¹ Preserves ≈ ⟶ ≈
open IsMonoid isMonoid public
_-_ : Op₂ A
x - y = x ∙ (y ⁻¹)
record IsAbelianGroup
{A} (≈ : Rel A) (∙ : Op₂ A) (ε : A) (⁻¹ : Op₁ A) : Set where
open FunctionProperties ≈
field
isGroup : IsGroup ≈ ∙ ε ⁻¹
comm : Commutative ∙
open IsGroup isGroup public
isCommutativeMonoid : IsCommutativeMonoid ≈ ∙ ε
isCommutativeMonoid = record
{ isMonoid = isMonoid
; comm = comm
}
------------------------------------------------------------------------
-- Two binary operations
record IsNearSemiring {A} (≈ : Rel A) (+ * : Op₂ A) (0# : A) : Set where
open FunctionProperties ≈
field
+-isMonoid : IsMonoid ≈ + 0#
*-isSemigroup : IsSemigroup ≈ *
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
open IsMonoid +-isMonoid public
renaming ( assoc to +-assoc
; ∙-pres-≈ to +-pres-≈
; isSemigroup to +-isSemigroup
; identity to +-identity
)
open IsSemigroup *-isSemigroup public
using ()
renaming ( assoc to *-assoc
; ∙-pres-≈ to *-pres-≈
)
record IsSemiringWithoutOne
{A} (≈ : Rel A) (+ * : Op₂ A) (0# : A) : Set where
open FunctionProperties ≈
field
+-isCommutativeMonoid : IsCommutativeMonoid ≈ + 0#
*-isSemigroup : IsSemigroup ≈ *
distrib : * DistributesOver +
zero : Zero 0# *
open IsCommutativeMonoid +-isCommutativeMonoid public
renaming ( assoc to +-assoc
; ∙-pres-≈ to +-pres-≈
; isSemigroup to +-isSemigroup
; identity to +-identity
; isMonoid to +-isMonoid
; comm to +-comm
)
open IsSemigroup *-isSemigroup public
using ()
renaming ( assoc to *-assoc
; ∙-pres-≈ to *-pres-≈
)
isNearSemiring : IsNearSemiring ≈ + * 0#
isNearSemiring = record
{ +-isMonoid = +-isMonoid
; *-isSemigroup = *-isSemigroup
; distribʳ = proj₂ distrib
; zeroˡ = proj₁ zero
}
record IsSemiringWithoutAnnihilatingZero
{A} (≈ : Rel A) (+ * : Op₂ A) (0# 1# : A) : Set where
open FunctionProperties ≈
field
-- Note that these structures do have an additive unit, but this
-- unit does not necessarily annihilate multiplication.
+-isCommutativeMonoid : IsCommutativeMonoid ≈ + 0#
*-isMonoid : IsMonoid ≈ * 1#
distrib : * DistributesOver +
open IsCommutativeMonoid +-isCommutativeMonoid public
renaming ( assoc to +-assoc
; ∙-pres-≈ to +-pres-≈
; isSemigroup to +-isSemigroup
; identity to +-identity
; isMonoid to +-isMonoid
; comm to +-comm
)
open IsMonoid *-isMonoid public
using ()
renaming ( assoc to *-assoc
; ∙-pres-≈ to *-pres-≈
; isSemigroup to *-isSemigroup
; identity to *-identity
)
record IsSemiring {A} (≈ : Rel A) (+ * : Op₂ A) (0# 1# : A) : Set where
open FunctionProperties ≈
field
isSemiringWithoutAnnihilatingZero :
IsSemiringWithoutAnnihilatingZero ≈ + * 0# 1#
zero : Zero 0# *
open IsSemiringWithoutAnnihilatingZero
isSemiringWithoutAnnihilatingZero public
isSemiringWithoutOne : IsSemiringWithoutOne ≈ + * 0#
isSemiringWithoutOne = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isSemigroup = *-isSemigroup
; distrib = distrib
; zero = zero
}
open IsSemiringWithoutOne isSemiringWithoutOne public
using (isNearSemiring)
record IsCommutativeSemiringWithoutOne
{A} (≈ : Rel A) (+ * : Op₂ A) (0# : A) : Set where
open FunctionProperties ≈
field
isSemiringWithoutOne : IsSemiringWithoutOne ≈ + * 0#
*-comm : Commutative *
open IsSemiringWithoutOne isSemiringWithoutOne public
record IsCommutativeSemiring
{A} (≈ : Rel A) (+ * : Op₂ A) (0# 1# : A) : Set where
open FunctionProperties ≈
field
isSemiring : IsSemiring ≈ + * 0# 1#
*-comm : Commutative *
open IsSemiring isSemiring public
*-isCommutativeMonoid : IsCommutativeMonoid ≈ * 1#
*-isCommutativeMonoid = record
{ isMonoid = *-isMonoid
; comm = *-comm
}
isCommutativeSemiringWithoutOne :
IsCommutativeSemiringWithoutOne ≈ + * 0#
isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = isSemiringWithoutOne
; *-comm = *-comm
}
record IsRing {A} (≈ : Rel A)
(_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set where
open FunctionProperties ≈
field
+-isAbelianGroup : IsAbelianGroup ≈ _+_ 0# -_
*-isMonoid : IsMonoid ≈ _*_ 1#
distrib : _*_ DistributesOver _+_
open IsAbelianGroup +-isAbelianGroup public
renaming ( assoc to +-assoc
; ∙-pres-≈ to +-pres-≈
; isSemigroup to +-isSemigroup
; identity to +-identity
; isMonoid to +-isMonoid
; inverse to -‿inverse
; ⁻¹-pres-≈ to -‿pres-≈
; isGroup to +-isGroup
; comm to +-comm
; isCommutativeMonoid to +-isCommutativeMonoid
)
open IsMonoid *-isMonoid public
using ()
renaming ( assoc to *-assoc
; ∙-pres-≈ to *-pres-≈
; isSemigroup to *-isSemigroup
; identity to *-identity
)
zero : Zero 0# _*_
zero = (zeroˡ , zeroʳ)
where
open EqR (record { isEquivalence = isEquivalence })
zeroˡ : LeftZero 0# _*_
zeroˡ x = begin
0# * x ≈⟨ sym $ proj₂ +-identity _ ⟩
(0# * x) + 0# ≈⟨ refl ⟨ +-pres-≈ ⟩ sym (proj₂ -‿inverse _) ⟩
(0# * x) + ((0# * x) + - (0# * x)) ≈⟨ sym $ +-assoc _ _ _ ⟩
((0# * x) + (0# * x)) + - (0# * x) ≈⟨ sym (proj₂ distrib _ _ _) ⟨ +-pres-≈ ⟩ refl ⟩
((0# + 0#) * x) + - (0# * x) ≈⟨ (proj₂ +-identity _ ⟨ *-pres-≈ ⟩ refl)
⟨ +-pres-≈ ⟩
refl ⟩
(0# * x) + - (0# * x) ≈⟨ proj₂ -‿inverse _ ⟩
0# ∎
zeroʳ : RightZero 0# _*_
zeroʳ x = begin
x * 0# ≈⟨ sym $ proj₂ +-identity _ ⟩
(x * 0#) + 0# ≈⟨ refl ⟨ +-pres-≈ ⟩ sym (proj₂ -‿inverse _) ⟩
(x * 0#) + ((x * 0#) + - (x * 0#)) ≈⟨ sym $ +-assoc _ _ _ ⟩
((x * 0#) + (x * 0#)) + - (x * 0#) ≈⟨ sym (proj₁ distrib _ _ _) ⟨ +-pres-≈ ⟩ refl ⟩
(x * (0# + 0#)) + - (x * 0#) ≈⟨ (refl ⟨ *-pres-≈ ⟩ proj₂ +-identity _)
⟨ +-pres-≈ ⟩
refl ⟩
(x * 0#) + - (x * 0#) ≈⟨ proj₂ -‿inverse _ ⟩
0# ∎
isSemiringWithoutAnnihilatingZero
: IsSemiringWithoutAnnihilatingZero ≈ _+_ _*_ 0# 1#
isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-isMonoid
; distrib = distrib
}
isSemiring : IsSemiring ≈ _+_ _*_ 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero =
isSemiringWithoutAnnihilatingZero
; zero = zero
}
open IsSemiring isSemiring public
using (isNearSemiring; isSemiringWithoutOne)
record IsCommutativeRing {A}
(≈ : Rel A) (+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set where
open FunctionProperties ≈
field
isRing : IsRing ≈ + * - 0# 1#
*-comm : Commutative *
open IsRing isRing public
isCommutativeSemiring : IsCommutativeSemiring ≈ + * 0# 1#
isCommutativeSemiring = record
{ isSemiring = isSemiring
; *-comm = *-comm
}
open IsCommutativeSemiring isCommutativeSemiring public
using (isCommutativeSemiringWithoutOne)
record IsLattice {A} (≈ : Rel A) (∨ ∧ : Op₂ A) : Set where
open FunctionProperties ≈
field
isEquivalence : IsEquivalence ≈
∨-comm : Commutative ∨
∨-assoc : Associative ∨
∨-pres-≈ : ∨ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
∧-comm : Commutative ∧
∧-assoc : Associative ∧
∧-pres-≈ : ∧ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
absorptive : Absorptive ∨ ∧
open IsEquivalence isEquivalence public
record IsDistributiveLattice {A} (≈ : Rel A) (∨ ∧ : Op₂ A) : Set where
open FunctionProperties ≈
field
isLattice : IsLattice ≈ ∨ ∧
∨-∧-distribʳ : ∨ DistributesOverʳ ∧
open IsLattice isLattice public
record IsBooleanAlgebra
{A} (≈ : Rel A) (∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set where
open FunctionProperties ≈
field
isDistributiveLattice : IsDistributiveLattice ≈ ∨ ∧
∨-complementʳ : RightInverse ⊤ ¬ ∨
∧-complementʳ : RightInverse ⊥ ¬ ∧
¬-pres-≈ : ¬ Preserves ≈ ⟶ ≈
open IsDistributiveLattice isDistributiveLattice public
|
{
"alphanum_fraction": 0.5089831281,
"avg_line_length": 32.7313432836,
"ext": "agda",
"hexsha": "9e1e9d05f804e890cdce7483f5cd3a6f0f545220",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Algebra/Structures.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Algebra/Structures.agda",
"max_line_length": 92,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Algebra/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 3492,
"size": 10965
}
|
-- Andreas, 2018-05-28, issue #3095, cannot make hidden shadowing variable visible
-- Andreas, 2019-07-15, issue #3919, make hidden variable visible in par. module
open import Agda.Builtin.Equality
module _ (A : Set) where
data Nat : Set where
suc : {n : Nat} → Nat
data IsSuc : Nat → Set where
isSuc : ∀{n} → IsSuc (suc {n})
test₁ : ∀{n} → IsSuc n → Set
test₁ p = aux p
where
aux : ∀{n} → IsSuc n → Set
aux isSuc = {!n!} -- C-c C-c
-- Expected: aux (isSuc {n}) = {!!}
-- Context:
-- p : IsSuc n
-- n : Nat (not in scope)
-- n₁ : Nat (not in scope)
-- WAS: ERROR
-- Ambiguous variable n
-- when checking that the expression ? has type Set
test₂ : ∀{m} → IsSuc m → Set
test₂ p = aux p
where
aux : ∀{n} → IsSuc n → Set
aux isSuc = {!m!} -- C-c C-c
-- Expected: cannot make hidden module parameter m visible
test₃ : ∀ m → IsSuc m → Set
test₃ m p = aux p refl
where
aux : ∀{n} → IsSuc n → m ≡ n → Set
aux isSuc refl = {!n!} -- C-c C-c
-- Expected: aux (isSuc {n}) refl = ?
test₄ : Nat → Nat
test₄ x = bar x
where
bar : Nat → Nat
bar y = {!x!} -- C-c C-c
-- Expected: cannot split on module parameter x
test₅ : Nat → {n : Nat} → Nat → Nat
test₅ = λ x y → {!n!} -- C-c C-c
-- Expected: cannot make hidden lambda-bound variable n visible
issue3919 : {n m : Nat} → n ≡ m
issue3919 = {!m!} -- C-c C-c
-- Expected: issue3919 {m = m} = ?
|
{
"alphanum_fraction": 0.583632448,
"avg_line_length": 24.0172413793,
"ext": "agda",
"hexsha": "dd81a8e40703486f634a706a71cdb466da44ab37",
"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": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "strake/agda",
"max_forks_repo_path": "test/interaction/Issue3095.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_issues_repo_issues_event_max_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "strake/agda",
"max_issues_repo_path": "test/interaction/Issue3095.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "strake/agda",
"max_stars_repo_path": "test/interaction/Issue3095.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 514,
"size": 1393
}
|
module PlfaInduction where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_ ; refl ; cong ; sym)
open Eq.≡-Reasoning using (begin_ ; _≡⟨⟩_ ; _≡⟨_⟩_ ; _∎ )
open import Data.Nat using (ℕ ; zero ; suc ; _+_ ; _*_ ; _^_ )
+-assoc : ∀ (a b c : ℕ) → (a + b) + c ≡ a + (b + c)
+-assoc zero b c =
begin
(zero + b) + c
≡⟨⟩
b + c
≡⟨⟩
zero + (b + c)
∎
+-assoc (suc a) b c =
begin
(suc a + b) + c
≡⟨⟩
suc (a + b) + c
≡⟨⟩
suc ((a + b) + c)
≡⟨ cong suc (+-assoc a b c) ⟩
suc (a + (b + c))
≡⟨⟩
suc a + (b + c)
∎
+-identityʳ : ∀ (a : ℕ) → a + zero ≡ a
+-identityʳ zero =
begin
zero + zero
≡⟨⟩
zero
∎
+-identityʳ (suc a) =
begin
suc a + zero
≡⟨⟩
suc (a + zero)
≡⟨ cong suc (+-identityʳ a) ⟩
suc a
∎
+-suc : ∀ (a b : ℕ) → a + suc b ≡ suc (a + b)
+-suc zero b =
begin
zero + suc b
≡⟨⟩
suc b
≡⟨⟩
suc (zero + b)
∎
+-suc (suc a) b =
begin
suc a + suc b
≡⟨⟩
suc (a + suc b)
≡⟨ cong suc (+-suc a b) ⟩
suc (suc a + b)
∎
+-comm : ∀ (a b : ℕ) → a + b ≡ b + a
+-comm zero b =
begin
zero + b
≡⟨⟩
b
≡⟨ sym (+-identityʳ b) ⟩
b + zero
∎
+-comm (suc a) b =
begin
suc a + b
≡⟨⟩
suc (a + b)
≡⟨ cong suc (+-comm a b) ⟩
suc (b + a)
≡⟨ sym (+-suc b a) ⟩
b + suc a
∎
+-rearrange : ∀ (a b c d : ℕ) → (a + b) + (c + d) ≡ (a + (b + c)) + d
+-rearrange a b c d =
begin
-- Because addition associates to the left
-- a + b + (c + d)
-- is the same as
(a + b) + (c + d)
≡⟨ +-assoc a b (c + d) ⟩
a + (b + (c + d))
-- Lesson: The + and the _ in in (a +_) MUST be next to each other (no spaces allowed)
≡⟨ cong (a +_) (sym (+-assoc b c d)) ⟩
a + ((b + c) + d)
≡⟨ sym (+-assoc a (b + c) d) ⟩
(a + (b + c)) + d
∎
-- Let's do it again, now using the rewrite magic
--+-assoc' : ∀ (a b c : ℕ) → a + b + c ≡ a + (b + c)
--+-assoc' zero b c = refl
--+-assoc' (suc a) b c rewrite +-assoc' a b c = refl
--+-suc' : ∀ (a b : ℕ) → a + suc b ≡ suc (a + b)
--+-suc' zero b = refl
--+-suc' (suc a) b rewrite +-suc' a b = refl
+-swap : ∀ (a b c : ℕ) → a + (b + c) ≡ b + (a + c)
+-swap a b c rewrite sym (+-assoc a b c) | +-comm a b | +-assoc b a c = refl
*-zero : ∀ (a : ℕ) → a * zero ≡ zero
*-zero zero = refl
*-zero (suc a) rewrite *-zero a = refl
*-rsucdist : ∀ (n m : ℕ) → n * suc m ≡ n + n * m
*-rsucdist zero m = refl
*-rsucdist (suc n) m rewrite *-rsucdist n m | +-swap m n (n * m) = refl
*-distrib : ∀ (x b c : ℕ) → (b + c) * x ≡ b * x + c * x
*-distrib zero b c rewrite *-zero (b + c) | *-zero b | *-zero c = refl
*-distrib (suc x) b c rewrite *-rsucdist (b + c) x
| *-distrib x b c
| +-rearrange b c (b * x) (c * x)
| +-comm c (b * x)
| sym (+-rearrange b (b * x) c (c * x) )
| sym (*-rsucdist b x)
| sym (*-rsucdist c x) = refl
*-assoc : ∀ (a b c : ℕ) → (a * b) * c ≡ a * (b * c)
*-assoc zero b c = refl
*-assoc (suc a) b c =
begin
(suc a * b) * c
≡⟨⟩
(b + a * b) * c
≡⟨ *-distrib c b (a * b) ⟩
b * c + (a * b) * c
≡⟨ cong (λ { x → b * c + x }) (*-assoc a b c) ⟩
suc a * (b * c)
∎
*-comm : ∀ (a b : ℕ) → a * b ≡ b * a
*-comm zero b rewrite *-zero b = refl
*-comm (suc a) b rewrite *-comm a b | sym (*-rsucdist b a) = refl
infixl 6 _∸_
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ (suc n) = zero
(suc m) ∸ (suc n) = m ∸ n
∸-zero : ∀ (a : ℕ) → zero ∸ a ≡ zero
∸-zero zero = refl
∸-zero (suc a) = refl
∸-suc : ∀ (a b : ℕ) → a ∸ suc b ≡ a ∸ 1 ∸ b
∸-suc zero b rewrite ∸-zero b = refl
∸-suc (suc a) b = refl
-- ∸-+-assoc : ∀ (a b c : ℕ) → a ∸ b ∸ c ≡ a ∸ (b + c)
-- ∸-+-assoc a zero c = refl
-- ∸-+-assoc a (suc b) c =
-- begin
-- a ∸ suc b ∸ c
-- ≡⟨ cong (λ x → x ∸ c) (∸-suc a b) ⟩
-- a ∸ 1 ∸ b ∸ c -- Remember this is equal to ((a ∸ 1) ∸ b) ∸ c
-- ≡⟨ ∸-+-assoc ⟩
-- ≡⟨ ∸-suc a (b + c) ⟩
-- a ∸ (b + c)
-- ∎
|
{
"alphanum_fraction": 0.4177623419,
"avg_line_length": 23.0342857143,
"ext": "agda",
"hexsha": "48629a8b183f20bd62ffef34842eeaeaa10bb4b2",
"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": "9f81052c4c872f0e19677bf6e9710350d3acf0e5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "GustavoMF31/upgraded-happiness",
"max_forks_repo_path": "PlfaInduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f81052c4c872f0e19677bf6e9710350d3acf0e5",
"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": "GustavoMF31/upgraded-happiness",
"max_issues_repo_path": "PlfaInduction.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f81052c4c872f0e19677bf6e9710350d3acf0e5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "GustavoMF31/upgraded-happiness",
"max_stars_repo_path": "PlfaInduction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1881,
"size": 4031
}
|
------------------------------------------------------------------------------
-- Theorems which require a non-empty domain
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOL.NonEmptyDomain.TheoremsATP where
open import FOL.Base
------------------------------------------------------------------------------
-- We postulate some formulae and propositional functions.
postulate
A : Set
A¹ : D → Set
postulate ∀→∃ : (∀ {x} → A¹ x) → ∃ A¹
{-# ATP prove ∀→∃ #-}
-- Let A be a formula. If x is not free in A then ⊢ (∃x)A ↔ A
-- (Mendelson 1997, proposition 2.18 (b), p. 70).
postulate ∃-erase-add₁ : (∃[ _ ] A) ↔ A
{-# ATP prove ∃-erase-add₁ #-}
-- Quantification over a variable that does not occur can be erased or
-- added.
postulate ∀-erase-add : ((x : D) → A) ↔ A
{-# ATP prove ∀-erase-add #-}
postulate ∃-erase-add₂ : (∃[ x ] (A ∨ A¹ x)) ↔ A ∨ (∃[ x ] A¹ x)
{-# ATP prove ∃-erase-add₂ #-}
------------------------------------------------------------------------------
-- References
--
-- Mendelson, Elliott (1997). Introduction to Mathematical Logic. 4th
-- ed. Chapman & Hall.
|
{
"alphanum_fraction": 0.4493865031,
"avg_line_length": 31.8048780488,
"ext": "agda",
"hexsha": "e2468f40fb8533d33b198d735cfd84159b051f2c",
"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/FOL/NonEmptyDomain/TheoremsATP.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/FOL/NonEmptyDomain/TheoremsATP.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/FOL/NonEmptyDomain/TheoremsATP.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": 324,
"size": 1304
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Digits and digit expansions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Digit where
open import Data.Nat using (ℕ; zero; suc; pred; _+_; _*_; _≤?_; _≤′_)
open import Data.Nat.Properties
open import Data.Nat.Solver
open import Data.Fin as Fin using (Fin; zero; suc; toℕ)
open import Data.Char using (Char)
open import Data.List.Base
open import Data.Product
open import Data.Vec as Vec using (Vec; _∷_; [])
open import Data.Nat.DivMod
open import Induction.Nat using (<′-rec; <′-Rec)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
open import Function
open +-*-Solver
------------------------------------------------------------------------
-- Digits
-- Digit b is the type of digits in base b.
Digit : ℕ → Set
Digit b = Fin b
-- Some specific digit kinds.
Decimal = Digit 10
Bit = Digit 2
-- Some named digits.
0b : Bit
0b = zero
1b : Bit
1b = suc zero
------------------------------------------------------------------------
-- Showing digits
-- The characters used to show the first 16 digits.
digitChars : Vec Char 16
digitChars =
'0' ∷ '1' ∷ '2' ∷ '3' ∷ '4' ∷ '5' ∷ '6' ∷ '7' ∷ '8' ∷ '9' ∷
'a' ∷ 'b' ∷ 'c' ∷ 'd' ∷ 'e' ∷ 'f' ∷ []
-- showDigit shows digits in base ≤ 16.
showDigit : ∀ {base} {base≤16 : True (base ≤? 16)} →
Digit base → Char
showDigit {base≤16 = base≤16} d =
Vec.lookup digitChars (Fin.inject≤ d (toWitness base≤16))
------------------------------------------------------------------------
-- Digit expansions
Expansion : ℕ → Set
Expansion base = List (Fin base)
-- fromDigits takes a digit expansion of a natural number, starting
-- with the _least_ significant digit, and returns the corresponding
-- natural number.
fromDigits : ∀ {base} → Expansion base → ℕ
fromDigits [] = 0
fromDigits {base} (d ∷ ds) = toℕ d + fromDigits ds * base
-- toDigits b n yields the digits of n, in base b, starting with the
-- _least_ significant digit.
--
-- Note that the list of digits is always non-empty.
toDigits : (base : ℕ) {base≥2 : True (2 ≤? base)} (n : ℕ) →
∃ λ (ds : Expansion base) → fromDigits ds ≡ n
toDigits zero {base≥2 = ()} _
toDigits (suc zero) {base≥2 = ()} _
toDigits (suc (suc k)) n = <′-rec Pred helper n
where
base = suc (suc k)
Pred = λ n → ∃ λ ds → fromDigits ds ≡ n
cons : ∀ {m} (r : Fin base) → Pred m → Pred (toℕ r + m * base)
cons r (ds , eq) = (r ∷ ds , P.cong (λ i → toℕ r + i * base) eq)
open ≤-Reasoning
lem : ∀ x k r → 2 + x ≤′ r + (1 + x) * (2 + k)
lem x k r = ≤⇒≤′ $ begin
2 + x
≤⟨ m≤m+n _ _ ⟩
2 + x + (x + (1 + x) * k + r)
≡⟨ solve 3 (λ x r k → con 2 :+ x :+ (x :+ (con 1 :+ x) :* k :+ r)
:=
r :+ (con 1 :+ x) :* (con 2 :+ k))
refl x r k ⟩
r + (1 + x) * (2 + k)
∎
helper : ∀ n → <′-Rec Pred n → Pred n
helper n rec with n divMod base
helper .(toℕ r + 0 * base) rec | result zero r refl = ([ r ] , refl)
helper .(toℕ r + suc x * base) rec | result (suc x) r refl =
cons r (rec (suc x) (lem (pred (suc x)) k (toℕ r)))
|
{
"alphanum_fraction": 0.5161384123,
"avg_line_length": 29.3931623932,
"ext": "agda",
"hexsha": "bd935b910ec1b5a491370b105d4018d7d286f525",
"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/Digit.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/Digit.agda",
"max_line_length": 77,
"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/Digit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1084,
"size": 3439
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A solver for proving that one list is a sublist of the other.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (DecSetoid)
module Data.List.Relation.Binary.Sublist.DecSetoid.Solver {c ℓ} (S : DecSetoid c ℓ) where
open DecSetoid S
open import Data.List.Relation.Binary.Sublist.Heterogeneous.Solver _≈_ refl _≟_
using (Item; module Item; TList; module TList; prove) public
|
{
"alphanum_fraction": 0.5561312608,
"avg_line_length": 34.0588235294,
"ext": "agda",
"hexsha": "7a2d70e754c284763127966874b655bd3cbd169a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/DecSetoid/Solver.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/Sublist/DecSetoid/Solver.agda",
"max_line_length": 89,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/DecSetoid/Solver.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": 123,
"size": 579
}
|
postulate
F : Set₁ → Set₁
record R : Set₁ where
field
f : F Set
{-# COMPILE GHC F = \ _ -> () #-}
{-# FOREIGN GHC data D = C () #-}
{-# COMPILE GHC R = data D (C) #-}
|
{
"alphanum_fraction": 0.4972067039,
"avg_line_length": 13.7692307692,
"ext": "agda",
"hexsha": "e610339745866c23eb10669fdd542136209cc640",
"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/Issue2913.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/Issue2913.agda",
"max_line_length": 34,
"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/Issue2913.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": 61,
"size": 179
}
|
{-# OPTIONS --cubical --safe --guardedness #-}
module Data.PolyP.Types where
open import Function hiding (_⟨_⟩_)
open import Data.Sum
open import Data.Sigma
open import Level
open import Data.Unit
open import Data.Nat
open import Data.Empty
open import WellFounded
open import Literals.Number
open import Data.Fin.Indexed.Literals
open import Data.Fin.Indexed.Properties
open import Data.Fin.Indexed
open import Data.Nat.Literals
open import Data.Maybe
open import Data.PolyP.Universe
open import Data.PolyP.Composition
open import Data.PolyP.Currying
open import Data.PolyP.RecursionSchemes
LIST : ∀ {n} → Functor (suc n)
LIST = μ⟨ ① ⊕ ! (fs f0) ⊗ ! f0 ⟩
-- The free near-semiring
FOREST : Functor 1
FOREST = μ⟨ LIST ⊚ (① ⊕ ! (fs f0) ⊗ ! f0) ⟩
-- Lists of lists
LEVELS : Functor 1
LEVELS = μ⟨ ① ⊕ ! (fs f0) ⊗ ! f0 ⟩ ⊚ μ⟨ ① ⊕ ! (fs f0) ⊗ ! f0 ⟩
-- The free monad
FREE : Functor 1 → Functor 1
FREE f = μ⟨ ! (fs f0) ⊕ f0 ⇑ f ⟩
COFREE : Functor 1 → Functor 1
COFREE f = μ⟨ ! (fs f0) ⊗ f0 ⇑ f ⟩
ROSE : Functor 1
ROSE = μ⟨ ! (fs f0) ⊗ f0 ⇑ LIST ⟩
module _ {A B : Type} where
FOLDR : (A → B → B) → B → ⟦ LIST ⟧ ~ A → B
FOLDR f b = cata (const b ▿ uncurry f)
open import Data.List
open import Data.List.Properties
open import Function.Isomorphism
open import Path
pattern _∷′_ x xs = ⟨ inr (x , xs) ⟩
pattern []′ = ⟨ inl tt ⟩
generic-list : List A ⇔ ⟦ LIST ⟧ ~ A
generic-list .fun = foldr _∷′_ []′
generic-list .inv = FOLDR _∷_ []
generic-list .leftInv = list-elim _ (λ x xs p i → x ∷ p i) λ i → []
generic-list .rightInv = elim _ λ { (inr ( x , xs , p)) i → x ∷′ p i ; (inl _) i → []′ }
open import Data.Vec
STREAM : Type → Type
STREAM A = ν (! (fs f0) ⊗ ! f0) ~ A
nats : ℕ → STREAM ℕ
nats n .unfold = n , nats (suc n)
|
{
"alphanum_fraction": 0.6157662624,
"avg_line_length": 25.5492957746,
"ext": "agda",
"hexsha": "bf003f6a17f70bc919da38fbe4c311154044ae8b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/PolyP/Types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/PolyP/Types.agda",
"max_line_length": 107,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/PolyP/Types.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 689,
"size": 1814
}
|
------------------------------------------------------------------------
-- Extension The Agda standard library
--
-- Properties of indexed binary relations
------------------------------------------------------------------------
module Relation.Binary.Indexed.Extra where
open import Data.Product
open import Data.Sum
open import Function
open import Level
-- import Relation.Binary.PropositionalEquality.Core as PropEq
-- open import Relation.Binary.Consequences as Consequences
open import Relation.Binary.Core as Core using (_≡_)
open import Relation.Binary.Indexed.Core
open import Relation.Binary.Indexed
import Relation.Binary as B
------------------------------------------------------------------------
-- Simple properties and equivalence relations
-- open Core public hiding (_≡_; refl; _≢_)
--
-- open Consequences public using (Total)
------------------------------------------------------------------------
-- Simple properties of indexed binary relations
-- Implication/containment. Could also be written ⊆.
[_][_]_⇒_ : ∀ {i₁ i₂ a b ℓ₁ ℓ₂} {I₁ : Set i₁} {I₂ : Set i₂}
(A : I₁ → Set a) (B : I₂ → Set b)
→ REL A B ℓ₁ → REL A B ℓ₂ → Set _
[ A ][ B ] P ⇒ Q = ∀ {i₁ i₂} {x : A i₁} {y : B i₂} → P x y → Q x y
-- _Preserves_⟶_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b} →
-- ((x : A) → B x) → B.Rel A ℓ₁ → Rel B ℓ₂ → Set (ℓ₂ ⊔ (ℓ₁ ⊔ a))
-- f Preserves P ⟶ Q = P =[ f ]⇒ Q
_Respects_ : ∀ {𝒾 a ℓ₁ ℓ₂} {I : Set 𝒾} {A : I → Set a} {i : I}
→ (A i → Set ℓ₁) → Rel A ℓ₂ → Set (ℓ₂ ⊔ (ℓ₁ ⊔ a))
P Respects _∼_ = ∀ {x y} → x ∼ y → P x → P y
[_]_Respects₂_ : ∀ {𝒾 a ℓ₁ ℓ₂} {I : Set 𝒾} (A : I → Set a)
→ Rel A ℓ₁ → Rel A ℓ₂ → Set (ℓ₂ ⊔ (ℓ₁ ⊔ (a ⊔ 𝒾)))
[ A ] P Respects₂ _∼_ =
(∀ {i} {x : A i} → _Respects_ {A = A} {i = i} (P x) _∼_) ×
(∀ {i} {y : A i} → _Respects_ {A = A} {i = i} (flip P y) _∼_)
------------------------------------------------------------------------
-- Preorders
record IsPreorder {𝒾 a ℓ₁ ℓ₂} {I : Set 𝒾} (A : I → Set a)
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_∼_ : Rel A ℓ₂) -- The relation.
: Set (𝒾 ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isEquivalence : IsEquivalence A _≈_
-- Reflexivity is expressed in terms of an underlying equality:
reflexive : [ A ][ A ] _≈_ ⇒ _∼_
trans : Transitive A _∼_
module Eq = IsEquivalence isEquivalence
refl : Reflexive A _∼_
refl = reflexive Eq.refl
∼-resp-≈ : [ A ] _∼_ Respects₂ _≈_
∼-resp-≈ = (λ x≈y z∼x → trans z∼x (reflexive x≈y))
, (λ x≈y x∼z → trans (reflexive $ Eq.sym x≈y) x∼z)
record Preorder {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _∼_
field
Carrier : I → Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_∼_ : Rel Carrier ℓ₂ -- The relation.
isPreorder : IsPreorder Carrier _≈_ _∼_
open IsPreorder isPreorder public
SetoidIsPreorder : ∀ {𝒾} {I : Set 𝒾} {c ℓ} (S : Setoid I c ℓ) → IsPreorder (Setoid.Carrier S) (Setoid._≈_ S) (Setoid._≈_ S)
SetoidIsPreorder {𝒾} {I} S = record
{ isEquivalence = isEquivalence
; reflexive = id
; trans = IsEquivalence.trans isEquivalence
}
where
open Setoid S
Setoid⇒Preorder : ∀ {𝒾} {I : Set 𝒾} {c ℓ} (S : Setoid I c ℓ) → Preorder I c ℓ ℓ
Setoid⇒Preorder S = record { isPreorder = SetoidIsPreorder S }
-- record
-- { Carrier = {! !}
-- ; _≈_ = {! !}
-- ; _∼_ = {! !}
-- ; isPreorder = {! !}
-- }
-- IsEquivalence.reflexive (Setoid.isEquivalence S)
-- where open IsEquivalence {! !}
--
-- isPreorder : IsPreorder _≡_ _≈_
-- isPreorder = record
-- { isEquivalence = PropEq.isEquivalence
-- ; reflexive = reflexive
-- ; trans = trans
-- }
--
-- preorder : Preorder c c ℓ
-- preorder = record { isPreorder = isPreorder }
|
{
"alphanum_fraction": 0.505700532,
"avg_line_length": 34.9292035398,
"ext": "agda",
"hexsha": "c77649ea2f08c8d56df2b3341a10f5c1b32ec5c8",
"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": "9f6d933b227aecab338ecaef1d86566a54fdac68",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/categories",
"max_forks_repo_path": "src/Relation/Binary/Indexed/Extra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f6d933b227aecab338ecaef1d86566a54fdac68",
"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/categories",
"max_issues_repo_path": "src/Relation/Binary/Indexed/Extra.agda",
"max_line_length": 123,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9f6d933b227aecab338ecaef1d86566a54fdac68",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/categories",
"max_stars_repo_path": "src/Relation/Binary/Indexed/Extra.agda",
"max_stars_repo_stars_event_max_datetime": "2018-01-04T23:19:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-01-04T23:19:30.000Z",
"num_tokens": 1386,
"size": 3947
}
|
open import Relation.Binary.Core
module Bound.Lower.Order.Properties {A : Set}
(_≤_ : A → A → Set)
(trans≤ : Transitive _≤_) where
open import Bound.Lower A
open import Bound.Lower.Order _≤_
transLeB : {a b c : Bound} → LeB a b → LeB b c → LeB a c
transLeB lebx _ = lebx
transLeB (lexy x≤y) (lexy y≤z) = lexy (trans≤ x≤y y≤z)
|
{
"alphanum_fraction": 0.6021798365,
"avg_line_length": 28.2307692308,
"ext": "agda",
"hexsha": "c9e9fde2dc34d823f29f6dbae4acc1f137e98c98",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/Bound/Lower/Order/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/Bound/Lower/Order/Properties.agda",
"max_line_length": 56,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/Bound/Lower/Order/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 136,
"size": 367
}
|
------------------------------------------------------------------------------
-- The program to sort a list is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module prove the correctness of a program which sorts a list
-- by converting it into an ordered tree and then back to a list
-- (Burstall 1969, p. 45).
module FOTC.Program.SortList.CorrectnessProofI where
open import FOTC.Base
open import FOTC.Data.Nat.List.Type
open import FOTC.Program.SortList.PropertiesI
open import FOTC.Program.SortList.Properties.Totality.TreeI
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
-- Main theorem: The sort program generates an ordered list.
sortCorrect : ∀ {is} → ListN is → OrdList (sort is)
sortCorrect {is} Lis =
subst OrdList
refl
(flatten-OrdList (makeTree-Tree Lis) (makeTree-OrdTree Lis))
------------------------------------------------------------------------------
-- References
--
-- Burstall, R. M. (1969). Proving properties of programs by
-- structural induction. The Computer Journal 12.1, pp. 41–48.
|
{
"alphanum_fraction": 0.5326821938,
"avg_line_length": 38.0285714286,
"ext": "agda",
"hexsha": "99fadb52ac4ea722f3ff9fb8c6c708f0212860d3",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/SortList/CorrectnessProofI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/SortList/CorrectnessProofI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/SortList/CorrectnessProofI.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": 269,
"size": 1331
}
|
module plfa.working.Naturals where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
seven : ℕ
seven = suc(suc(suc(suc(suc(suc(suc(zero)))))))
{-# BUILTIN NATURAL ℕ #-}
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
_+_ : ℕ → ℕ → ℕ
zero + n = n
(suc m) + n = suc(m + n)
_ : 2 + 3 ≡ 5
_ =
begin
2 + 3
≡⟨⟩
(suc (suc zero)) + (suc (suc (suc zero)))
≡⟨⟩
suc( (suc zero) + (suc (suc (suc zero))))
≡⟨⟩
(suc(suc (zero + (suc (suc (suc zero))))))
≡⟨⟩
(suc (suc (suc (suc (suc zero)))))
≡⟨⟩
5
∎
_ : 2 + 3 ≡ 5
_ =
begin
2 + 3
≡⟨⟩
suc (1 + 3)
≡⟨⟩
suc (suc (0 + 3))
≡⟨⟩
suc (suc 3)
≡⟨⟩
5
∎
_ : 3 + 4 ≡ 7
_ =
begin
3 + 4
≡⟨⟩
suc (2 + 4)
≡⟨⟩
suc (2 + (suc 3))
≡⟨⟩
suc (suc (2 + 3))
≡⟨⟩
suc (suc 5)
≡⟨⟩
7
∎
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (n * m)
_ : 3 * 4 ≡ 12
_ =
begin
3 * 4
≡⟨⟩
(suc 2) * 4
≡⟨⟩
4 + (4 * 2)
≡⟨⟩
4 + ((suc 3) * 2)
≡⟨⟩
4 + (2 + (2 * 3))
≡⟨⟩
4 + (2 + (suc 1 * 3))
≡⟨⟩
4 + (2 + (3 + (3 * 1)))
≡⟨⟩
4 + (2 + (3 + (suc 2 * 1)))
≡⟨⟩
4 + (2 + (3 + (1 + (1 * 2))))
≡⟨⟩
12
∎
_^_ : ℕ → ℕ → ℕ
n ^ zero = suc zero
n ^ (suc m) = n * (n ^ m)
_ : 3 ^ 4 ≡ 81
_ =
begin
3 ^ 4
≡⟨⟩
3 ^ (1 + 3)
≡⟨⟩
3 * (3 ^ 3)
≡⟨⟩
3 * (3 * (3 ^ 2))
≡⟨⟩
3 * (3 * (3 * (3 ^ 1)))
≡⟨⟩
3 * (3 * (3 * 3))
≡⟨⟩
81
∎
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
_ : 5 ∸ 3 ≡ 2
_ =
begin
5 ∸ 3
≡⟨⟩
(1 + 4) ∸ (1 + 2)
≡⟨⟩
4 ∸ 2
≡⟨⟩
3 ∸ 1
≡⟨⟩
2 ∸ 0
≡⟨⟩
2
∎
_ : 2 ∸ 5 ≡ 0
_ =
begin
2 ∸ 5
≡⟨⟩
1 ∸ 4
≡⟨⟩
0 ∸ 3
≡⟨⟩
0
∎
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (p O) = p I
inc (p I) = (inc p) O
_ : inc (⟨⟩ O O O O) ≡ ⟨⟩ O O O I
_ = refl
_ : inc (⟨⟩ O O O I) ≡ ⟨⟩ O O I O
_ = refl
_ : inc (⟨⟩ O O I O) ≡ ⟨⟩ O O I I
_ = refl
_ : inc (⟨⟩ O O I I) ≡ ⟨⟩ O I O O
_ = refl
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
to : ℕ → Bin
to zero = ⟨⟩ O
to (suc n) = inc (to n)
from : Bin → ℕ
from ⟨⟩ = zero
from (p O) = from p * 2
from (p I) = suc ((from p) * 2)
_ : to 3 ≡ ⟨⟩ I I
_ = refl
_ : from (⟨⟩ I I) ≡ 3
_ = refl
|
{
"alphanum_fraction": 0.284129119,
"avg_line_length": 15.5706806283,
"ext": "agda",
"hexsha": "35077b0bf60002b445a1c6cc16fd55efa3d8140d",
"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": "5365a4ba8ba0dc80cb77ab73aee92c645d0787d9",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "kaychaks/plfa.github.io",
"max_forks_repo_path": "src/plfa/working/Naturals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5365a4ba8ba0dc80cb77ab73aee92c645d0787d9",
"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": "kaychaks/plfa.github.io",
"max_issues_repo_path": "src/plfa/working/Naturals.agda",
"max_line_length": 54,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5365a4ba8ba0dc80cb77ab73aee92c645d0787d9",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "kaychaks/plfa.github.io",
"max_stars_repo_path": "src/plfa/working/Naturals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1444,
"size": 2974
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Graphs where
-- The "Underlying Graph" <-> "Free Category on a Graph" Adjunction.
-- Lots of surprises here, of various level of surprisingness
-- 1. The Free Category rises universe levels of arrows (and equivalences); the Underlying Graph does not
-- (due to the Transitive Closure "Star" construction)
-- 2. As a consequence of (1), the eventual Adjunction will be for all Levels being the same
-- 3. If you want a Functor Categories Graph, then the object/hom levels are straightforward,
-- but if you use "Categories" with NaturalIsomorphism, then the 2-point Groupoid is contractible
-- (thus equivalent to the 1-point Category), and yet those two Graphs shouldn't be considered to
-- be the same! So _≡F_ must be used so that we have no wiggle room when mapping Graphs around.
-- Interestingly, this only shows up when trying to prove that the Underlying Functor respects
-- _≈_, which is not traditionally a requirement of a Functor! This requirement is usually left
-- implicit. If we were to allow Functor to not respect _≈_, things would be fine. But of course
-- we couldn't do any reasonable equational reasoning anymore. Of course, if _≈_ were the global
-- _≡_, this isn't an issue, but that is definitely not wanted here.
-- 4. A lot of weird little lemmas about _≡_ and subst/transport are needed, because we're in a mixed
-- reasoning situation with both ≡ and ≈ present. These could probably be generalized and factored
-- into a separate module (or into the standard library).
open import Level
open import Function using (_$_; flip) renaming (id to idFun; _∘_ to _⊚_)
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
import Relation.Binary.EqReasoning as EqR
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties hiding (trans)
open import Data.Product using (proj₁; proj₂; _,_)
open import Categories.Category
open import Categories.Functor using (Functor)
open import Categories.Functor.Equivalence
open import Categories.Category.Instance.StrictCats
open import Categories.Utils.EqReasoning
open import Categories.NaturalTransformation hiding (id)
open import Categories.NaturalTransformation.NaturalIsomorphism hiding (refl; sym; trans; isEquivalence)
open import Categories.Adjoint
import Categories.Morphism.HeterogeneousIdentity as HId
-- a graph has vertices Obj and edges _⇒_, where edges form a setoid over _≈_.
record Graph o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where
infix 4 _≈_ _⇒_
field
Obj : Set o
_⇒_ : Rel Obj ℓ
_≈_ : ∀ {A B} → Rel (A ⇒ B) e
equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
setoid : {A B : Obj} → Setoid _ _
setoid {A} {B} = record
{ Carrier = A ⇒ B
; _≈_ = _≈_
; isEquivalence = equiv
}
module Equiv {A} {B} = IsEquivalence (equiv {A} {B})
module EdgeReasoning {A B : Obj} = EqR (setoid {A} {B})
private
variable
o o′ ℓ ℓ′ e e′ : Level
-- This doesn't belong here... but will do for now
module PathEquiv {o ℓ e : Level} {Obj : Set o} {_⇒_ : Obj → Obj → Set ℓ} (_≈_ : {A B : Obj} → Rel (A ⇒ B) e)
(equiv : {A B : Obj} → IsEquivalence ( _≈_ {A} {B})) where
private
module E {A} {B} = IsEquivalence (equiv {A} {B})
open E renaming (refl to ≈refl; sym to ≈sym; trans to ≈trans)
infix 4 _≈*_
data _≈*_ : {A B : Obj} (p q : Star _⇒_ A B) → Set (o ⊔ ℓ ⊔ e) where
ε : {A : Obj} → _≈*_ {A} ε ε
_◅_ : {A B C : Obj} {x y : A ⇒ B} {p q : Star _⇒_ B C} (x≈y : x ≈ y) (p≈q : p ≈* q) → x ◅ p ≈* y ◅ q
refl : {A B : Obj} {p : Star _⇒_ A B} → p ≈* p
refl {p = ε} = ε
refl {p = x ◅ p} = ≈refl ◅ refl
sym : {A B : Obj} {p q : Star _⇒_ A B} → p ≈* q → q ≈* p
sym ε = ε
sym (x≈y ◅ eq) = ≈sym x≈y ◅ sym eq
≡⇒≈* : {A B : Obj} {p q : Star _⇒_ A B} → p ≡ q → p ≈* q
≡⇒≈* ≡.refl = refl
≡⇒≈ : {A B : Obj} → {p q : A ⇒ B} → p ≡ q → p ≈ q
≡⇒≈ ≡.refl = ≈refl
trans : {A B : Obj} {p q r : Star _⇒_ A B} → p ≈* q → q ≈* r → p ≈* r
trans ε ε = ε
trans (x≈y ◅ ss) (y≈z ◅ tt) = ≈trans x≈y y≈z ◅ trans ss tt
isEquivalence : {A B : Obj} → IsEquivalence (λ (p q : Star _⇒_ A B) → p ≈* q)
isEquivalence = record { refl = refl ; sym = sym ; trans = trans }
setoid : Obj → Obj → Setoid (o ⊔ ℓ) (o ⊔ ℓ ⊔ e)
setoid A B = record { _≈_ = _≈*_ ; isEquivalence = isEquivalence {A} {B} }
-- convenient to define here
--
-- FIXME: this should go into the standard library at
-- Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
◅◅-identityʳ : {A B : Obj} → (f : Star _⇒_ A B) → f ◅◅ ε ≈* f
◅◅-identityʳ ε = ε
◅◅-identityʳ (x ◅ f) = ≈refl ◅ ◅◅-identityʳ f
module PathEqualityReasoning {A B} where
open EqR (setoid A B) public
module _ (G : Graph o ℓ e) where
open Graph G
private module P = PathEquiv {o} {ℓ} {e} {Obj} {_⇒_} _≈_ equiv
open P
Free : Category o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e)
Free = record
{ Obj = Obj
; _⇒_ = Star _⇒_
; _≈_ = _≈*_
; id = ε
; _∘_ = _▻▻_
; assoc = λ {_ _ _ _} {f g h} → sym $ ≡⇒≈* $ ◅◅-assoc f g h
; sym-assoc = λ {_ _ _ _} {f g h} → ≡⇒≈* $ ◅◅-assoc f g h
; identityˡ = λ {_ _ f} → ◅◅-identityʳ f
; identityʳ = refl
; identity² = refl
; equiv = isEquivalence
; ∘-resp-≈ = resp
}
where resp : ∀ {A B C} {f h : Star _⇒_ B C} {g i : Star _⇒_ A B} →
f ≈* h → g ≈* i → (f ▻▻ g) ≈* (h ▻▻ i)
resp eq ε = eq
resp eq (eq₁ ◅ eq₂) = eq₁ ◅ (resp eq eq₂)
open P public renaming (_≈*_ to [_]_≈*_)
record GraphMorphism (G : Graph o ℓ e) (G′ : Graph o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module G = Graph G
module G′ = Graph G′
field
M₀ : G.Obj → G′.Obj
M₁ : ∀ {A B} → A G.⇒ B → M₀ A G′.⇒ M₀ B
M-resp-≈ : ∀ {A B} {f g : A G.⇒ B} → f G.≈ g → M₁ f G′.≈ M₁ g
idGHom : {G : Graph o ℓ e} → GraphMorphism G G
idGHom = record { M₀ = idFun ; M₁ = idFun ; M-resp-≈ = idFun }
_∘GM_ : {G₁ G₂ G₃ : Graph o ℓ e} (m₁ : GraphMorphism G₂ G₃) (m₂ : GraphMorphism G₁ G₂) → GraphMorphism G₁ G₃
m₁ ∘GM m₂ = record
{ M₀ = M₀ m₁ ⊚ M₀ m₂
; M₁ = M₁ m₁ ⊚ M₁ m₂
; M-resp-≈ = M-resp-≈ m₁ ⊚ M-resp-≈ m₂
}
where open GraphMorphism
module Trsp (G : Graph o ℓ e) where
open Graph G
-- Two shorthands that will be useful for the definition of morphism
-- equality: transport the domain or codomain of an edge along an
-- equality.
infixr 9 _◂_
infixl 9 _▸_
_◂_ : ∀ {A B C} → A ≡ B → B ⇒ C → A ⇒ C
p ◂ f = ≡.subst (_⇒ _) (≡.sym p) f
_▸_ : ∀ {A B C} → A ⇒ B → B ≡ C → A ⇒ C
f ▸ p = ≡.subst (_ ⇒_) p f
-- Some simple properties of transports
◂-▸-comm : ∀ {A B C D} (p : A ≡ B) (f : B ⇒ C) (q : C ≡ D) →
p ◂ (f ▸ q) ≡ (p ◂ f) ▸ q
◂-▸-comm ≡.refl f ≡.refl = ≡.refl
◂-trans : ∀ {A B C D} (p : A ≡ B) (q : B ≡ C) (f : C ⇒ D) →
p ◂ q ◂ f ≡ (≡.trans p q) ◂ f
◂-trans ≡.refl ≡.refl f = ≡.refl
▸-trans : ∀ {A B C D} (f : A ⇒ B) (p : B ≡ C) (q : C ≡ D) →
f ▸ p ▸ q ≡ f ▸ ≡.trans p q
▸-trans f ≡.refl ≡.refl = ≡.refl
◂-resp-≈ : ∀ {A B C} (p : A ≡ B) {f g : B ⇒ C} → f ≈ g → p ◂ f ≈ p ◂ g
◂-resp-≈ ≡.refl f≈g = f≈g
▸-resp-≈ : ∀ {A B C} {f g : A ⇒ B} → f ≈ g → (p : B ≡ C) → f ▸ p ≈ g ▸ p
▸-resp-≈ f≈g ≡.refl = f≈g
module TrspGM {G : Graph o ℓ e} {H : Graph o′ ℓ′ e′}
(m : GraphMorphism G H) where
module G = Graph G
module H = Graph H
open GraphMorphism m
open Trsp G
open Trsp H using () renaming (_◂_ to _◃_; _▸_ to _▹_)
M-resp-▸ : ∀ {A B C} (f : A G.⇒ B) (p : B ≡ C) →
M₁ (f ▸ p) ≡ M₁ f ▹ ≡.cong M₀ p
M-resp-▸ f ≡.refl = ≡.refl
M-resp-◂ : ∀ {A B C} (p : A ≡ B) (f : B G.⇒ C) →
M₁ (p ◂ f) ≡ ≡.cong M₀ p ◃ M₁ f
M-resp-◂ ≡.refl f = ≡.refl
record GraphMorphism≈ {G : Graph o ℓ e} {G′ : Graph o′ ℓ′ e′}
(M M′ : GraphMorphism G G′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module G = Graph G
module G′ = Graph G′
module M = GraphMorphism M
module M′ = GraphMorphism M′
open Trsp G′
-- Pick a presentation of equivalence for graph morphisms that works
-- well with functor equality.
field
M₀≡ : ∀ {X} → M.M₀ X ≡ M′.M₀ X
M₁≡ : ∀ {A B} {f : A G.⇒ B} → M.M₁ f ▸ M₀≡ G′.≈ M₀≡ ◂ M′.M₁ f
Graphs : ∀ o ℓ e → Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e)
Graphs o ℓ e = record
{ Obj = Graph o ℓ e
; _⇒_ = GraphMorphism
; _≈_ = GraphMorphism≈
; id = idGHom
; _∘_ = _∘GM_
; assoc = λ {_ _ _ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G }
; sym-assoc = λ {_ _ _ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G }
; identityˡ = λ {_ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G }
; identityʳ = λ {_ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G }
; identity² = λ {G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G }
; equiv = λ {_ G} → record
{ refl = record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G }
; sym = λ {i j} eq → record
{ M₀≡ = ≡.sym (M₀≡ eq)
; M₁≡ = λ {_ _ f} →
let open EdgeReasoning G
open Trsp G
in begin
M₁ j f ▸ ≡.sym (M₀≡ eq)
≡˘⟨ ≡.cong (_◂ (M₁ j f ▸ _)) (≡.trans-symˡ (M₀≡ eq)) ⟩
≡.trans (≡.sym $ M₀≡ eq) (M₀≡ eq) ◂ (M₁ j f ▸ ≡.sym (M₀≡ eq))
≡˘⟨ ◂-trans (≡.sym $ M₀≡ eq) (M₀≡ eq) _ ⟩
≡.sym (M₀≡ eq) ◂ M₀≡ eq ◂ (M₁ j f ▸ ≡.sym (M₀≡ eq))
≡⟨ ≡.cong (≡.sym (M₀≡ eq) ◂_)
(◂-▸-comm (M₀≡ eq) (M₁ j f) (≡.sym $ M₀≡ eq)) ⟩
≡.sym (M₀≡ eq) ◂ ((M₀≡ eq ◂ M₁ j f) ▸ ≡.sym (M₀≡ eq))
≈˘⟨ ◂-resp-≈ (≡.sym (M₀≡ eq)) (▸-resp-≈ (M₁≡ eq) (≡.sym (M₀≡ eq))) ⟩
≡.sym (M₀≡ eq) ◂ (M₁ i f ▸ M₀≡ eq ▸ ≡.sym (M₀≡ eq))
≡⟨ ≡.cong (≡.sym (M₀≡ eq) ◂_)
(▸-trans (M₁ i f) (M₀≡ eq) (≡.sym (M₀≡ eq))) ⟩
≡.sym (M₀≡ eq) ◂ (M₁ i f ▸ ≡.trans (M₀≡ eq) (≡.sym (M₀≡ eq)))
≡⟨ ≡.cong (λ p → ≡.sym (M₀≡ eq) ◂ (M₁ i f ▸ p)) (≡.trans-symʳ (M₀≡ eq)) ⟩
≡.sym (M₀≡ eq) ◂ M₁ i f
∎
}
; trans = λ {i j k} eq eq′ → record
{ M₀≡ = ≡.trans (M₀≡ eq) (M₀≡ eq′)
; M₁≡ = λ {_ _ f} →
let open EdgeReasoning G
open Trsp G
in begin
M₁ i f ▸ ≡.trans (M₀≡ eq) (M₀≡ eq′)
≡˘⟨ ▸-trans (M₁ i f) (M₀≡ eq) (M₀≡ eq′) ⟩
(M₁ i f ▸ M₀≡ eq) ▸ M₀≡ eq′
≈⟨ ▸-resp-≈ (M₁≡ eq) (M₀≡ eq′) ⟩
(M₀≡ eq ◂ M₁ j f) ▸ M₀≡ eq′
≡˘⟨ ◂-▸-comm (M₀≡ eq) (M₁ j f) (M₀≡ eq′) ⟩
M₀≡ eq ◂ (M₁ j f ▸ M₀≡ eq′)
≈⟨ ◂-resp-≈ (M₀≡ eq) (M₁≡ eq′) ⟩
M₀≡ eq ◂ (M₀≡ eq′ ◂ M₁ k f)
≡⟨ ◂-trans (M₀≡ eq) (M₀≡ eq′) (M₁ k f) ⟩
≡.trans (M₀≡ eq) (M₀≡ eq′) ◂ M₁ k f
∎
}
}
; ∘-resp-≈ = λ {_ G H} {f g h i} eq eq′ → record
{ M₀≡ = ≡.trans (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq)
; M₁≡ = λ {_ _ j} →
let open EdgeReasoning H
open Trsp H
open Trsp G using () renaming (_▸_ to _▹_; _◂_ to _◃_)
open TrspGM
in begin
M₁ (f ∘GM h) j ▸ ≡.trans (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq)
≡˘⟨ ▸-trans (M₁ f (M₁ h j)) (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq) ⟩
M₁ f (M₁ h j) ▸ ≡.cong (M₀ f) (M₀≡ eq′) ▸ M₀≡ eq
≡˘⟨ ≡.cong (_▸ M₀≡ eq) (M-resp-▸ f (M₁ h j) (M₀≡ eq′)) ⟩
M₁ f (M₁ h j ▹ M₀≡ eq′) ▸ M₀≡ eq
≈⟨ M₁≡ eq ⟩
M₀≡ eq ◂ M₁ g (M₁ h j ▹ M₀≡ eq′)
≈⟨ ◂-resp-≈ (M₀≡ eq) (M-resp-≈ g (M₁≡ eq′)) ⟩
M₀≡ eq ◂ M₁ g (M₀≡ eq′ ◃ M₁ i j)
≡⟨ ≡.cong (M₀≡ eq ◂_) (M-resp-◂ g (M₀≡ eq′) (M₁ i j)) ⟩
M₀≡ eq ◂ ≡.cong (M₀ g) (M₀≡ eq′) ◂ M₁ g (M₁ i j)
≡⟨ ◂-trans (M₀≡ eq) (≡.cong (M₀ g) (M₀≡ eq′)) (M₁ g (M₁ i j)) ⟩
≡.trans (M₀≡ eq) (≡.cong (M₀ g) (M₀≡ eq′)) ◂ M₁ g (M₁ i j)
≡˘⟨ ≡.cong (_◂ M₁ g (M₁ i j)) (≡.naturality (λ _ → M₀≡ eq)) ⟩
≡.trans (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq) ◂ M₁ g (M₁ i j)
∎
}
}
where
open Graph
open GraphMorphism
open GraphMorphism≈
open _≡F_
-- Put the rest of the Graph stuff here too:
Underlying₀ : Category o ℓ e → Graph o ℓ e
Underlying₀ C = record { Obj = C.Obj ; _⇒_ = C._⇒_ ; _≈_ = C._≈_ ; equiv = C.equiv }
where module C = Category C
Underlying₁ : {C : Category o ℓ e} {D : Category o′ ℓ′ e′} → Functor C D → GraphMorphism (Underlying₀ C) (Underlying₀ D)
Underlying₁ F = record { M₀ = F.F₀ ; M₁ = F.F₁ ; M-resp-≈ = F.F-resp-≈ }
where module F = Functor F
Underlying : Functor (Cats o ℓ e) (Graphs o ℓ e)
Underlying = record
{ F₀ = Underlying₀
; F₁ = Underlying₁
; identity = λ {A} → record { M₀≡ = ≡.refl ; M₁≡ = Category.Equiv.refl A }
; homomorphism = λ where {Z = Z} → record { M₀≡ = ≡.refl ; M₁≡ = Category.Equiv.refl Z }
; F-resp-≈ = λ {A} {B} {F} {G} F≈G → record
{ M₀≡ = λ {X} → eq₀ F≈G X
; M₁≡ = λ {x} {y} {f} →
let open Category B
open HId B
open Trsp (Underlying₀ B)
open Functor
open Graph.EdgeReasoning (Underlying₀ B)
in begin
F₁ F f ▸ eq₀ F≈G y ≈⟨ hid-subst-cod (F₁ F f) (eq₀ F≈G y) ⟩
hid (eq₀ F≈G y) ∘ F₁ F f ≈⟨ eq₁ F≈G f ⟩
F₁ G f ∘ hid (eq₀ F≈G x) ≈˘⟨ hid-subst-dom (eq₀ F≈G x) (F₁ G f) ⟩
eq₀ F≈G x ◂ F₁ G f ∎
}
}
where
open NaturalTransformation
open NaturalIsomorphism
-- Transports on paths
module TrspStar (G : Graph o ℓ e) where
open Graph G
open Trsp (Underlying₀ (Free G)) public using () renaming
( _◂_ to _◂*_
; _▸_ to _▸*_
)
open Trsp G
-- Lemmas relating transports to path operations.
◂*-▸*-ε : ∀ {A B : Obj} (p : A ≡ B) → ε ▸* p ≡ p ◂* ε
◂*-▸*-ε ≡.refl = ≡.refl
◂*-◅ : ∀ {A B C D : Obj} (p : A ≡ B) (f : B ⇒ C) (fs : Star _⇒_ C D) →
p ◂* (f ◅ fs) ≡ (p ◂ f) ◅ fs
◂*-◅ ≡.refl f fs = ≡.refl
◅-▸* : ∀ {A B C D : Obj} (f : A ⇒ B) (fs : Star _⇒_ B C) (p : C ≡ D) →
(f ◅ fs) ▸* p ≡ f ◅ (fs ▸* p)
◅-▸* f fs ≡.refl = ≡.refl
◅-◂*-▸ : ∀ {A B C D : Obj} (f : A ⇒ B) (p : B ≡ C) (fs : Star _⇒_ C D) →
_≡_ {_} {Star _⇒_ A D} (f ◅ (p ◂* fs)) ((f ▸ p) ◅ fs)
◅-◂*-▸ f ≡.refl fs = ≡.refl
-- define these ahead of time
module _ {G₁ G₂ : Graph o ℓ e} (G⇒ : GraphMorphism G₁ G₂) where
open Graph G₁ renaming (_⇒_ to _⇒₁_; Obj to Obj₁)
open Graph G₂ renaming (_⇒_ to _⇒₂_; Obj to Obj₂; module Equiv to Equiv₂)
open GraphMorphism G⇒
mapGraph : {A B : Obj₁} → Star _⇒₁_ A B → Star _⇒₂_ (M₀ A) (M₀ B)
mapGraph ε = ε
mapGraph (x ◅ y) = M₁ x ◅ mapGraph y
map-hom : {X Y Z : Graph.Obj G₁} (f : Star _⇒₁_ X Y) {g : Star _⇒₁_ Y Z} →
[ G₂ ] mapGraph (f ◅◅ g) ≈* (mapGraph f ◅◅ mapGraph g)
map-hom ε {g} = refl G₂
map-hom (x ◅ f) {g} = Equiv₂.refl ◅ map-hom f
map-resp : {A B : Obj₁} (f : Star _⇒₁_ A B) {g : Star _⇒₁_ A B} →
[ G₁ ] f ≈* g → [ G₂ ] mapGraph f ≈* mapGraph g
map-resp ε ε = ε
map-resp (x ◅ f) (f≈* ◅ eq) = M-resp-≈ f≈* ◅ map-resp f eq
-- don't want a single global GraphMorphism
module _ {G : Graph o ℓ e} where
open Graph G
map-id : {A B : Obj} (f : Star _⇒_ A B) → [ G ] mapGraph (idGHom {G = G}) f ≈* f
map-id ε = ε
map-id (fs ◅ f) = Equiv.refl ◅ map-id f
module _ {X Y Z : Graph o ℓ e} {G₁ : GraphMorphism X Y} {G₂ : GraphMorphism Y Z} where
open Graph X
map-∘ : {A B : Obj} (f : Star _⇒_ A B) → [ Z ] (mapGraph (G₂ ∘GM G₁) f) ≈* mapGraph G₂ (mapGraph G₁ f)
map-∘ ε = ε
map-∘ (fs ◅ f) = Graph.Equiv.refl Z ◅ map-∘ f
module _ {G H : Graph o ℓ e} {f g : GraphMorphism G H}
(f≈g : GraphMorphism≈ f g) where
open Graph G
open GraphMorphism
open GraphMorphism≈ f≈g
open TrspStar H
open Trsp H
map-M₁≡ : {A B : Obj} (hs : Star _⇒_ A B) →
[ H ] mapGraph f hs ▸* M₀≡ ≈* M₀≡ ◂* mapGraph g hs
map-M₁≡ ε = ≡⇒≈* H (◂*-▸*-ε M₀≡)
map-M₁≡ (hs ◅ h) = begin
(M₁ f hs ◅ mapGraph f h) ▸* M₀≡ ≡⟨ ◅-▸* (M₁ f hs) _ M₀≡ ⟩
M₁ f hs ◅ (mapGraph f h ▸* M₀≡) ≈⟨ Graph.Equiv.refl H ◅ map-M₁≡ h ⟩
M₁ f hs ◅ (M₀≡ ◂* mapGraph g h) ≡⟨ ◅-◂*-▸ (M₁ f hs) M₀≡ _ ⟩
(M₁ f hs ▸ M₀≡) ◅ mapGraph g h ≈⟨ M₁≡ ◅ (refl H) ⟩
(M₀≡ ◂ M₁ g hs) ◅ mapGraph g h ≡˘⟨ ◂*-◅ M₀≡ (M₁ g hs) _ ⟩
M₀≡ ◂* (M₁ g hs ◅ mapGraph g h) ∎
where open PathEqualityReasoning H
module _ (C : Category o ℓ e) where
open Category C
open HomReasoning
-- A helper that should probably go into Categories.Morphism.Reasoning...
toSquare : ∀ {A B} {f g : A ⇒ B} → f ≈ g → CommutativeSquare f id id g
toSquare {_} {_} {f} {g} f≈g = begin
id ∘ f ≈⟨ identityˡ ⟩
f ≈⟨ f≈g ⟩
g ≈˘⟨ identityʳ ⟩
g ∘ id ∎
CatF : Functor (Graphs o ℓ e) (Cats o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e))
CatF = record
{ F₀ = Free
; F₁ = λ {G₁} {G₂} G⇒ → record
{ F₀ = M₀ G⇒
; F₁ = mapGraph G⇒
; identity = refl G₂
; homomorphism = λ {_} {_} {_} {f} → map-hom G⇒ f
; F-resp-≈ = λ { {f = f} → map-resp G⇒ f}
}
; identity = λ {G} → record
{ eq₀ = λ _ → ≡.refl
; eq₁ = λ f → toSquare (Free G) (map-id f)
}
; homomorphism = λ {_} {_} {G} → record
{ eq₀ = λ _ → ≡.refl
; eq₁ = λ h → toSquare (Free G) (map-∘ h)
}
; F-resp-≈ = λ {_} {G} {f} {g} f≈g → record
{ eq₀ = λ _ → M₀≡ f≈g
; eq₁ = λ h →
let open Category (Free G)
open HId (Free G)
open TrspStar G
open HomReasoning
in begin
mapGraph f h ◅◅ (hid $ M₀≡ f≈g)
≈˘⟨ hid-subst-cod (mapGraph f h) (M₀≡ f≈g) ⟩
mapGraph f h ▸* M₀≡ f≈g
≈⟨ map-M₁≡ f≈g h ⟩
M₀≡ f≈g ◂* mapGraph g h
≈⟨ hid-subst-dom (M₀≡ f≈g) (mapGraph g h) ⟩
(hid $ M₀≡ f≈g) ◅◅ mapGraph g h
∎
}
}
where
open GraphMorphism
open GraphMorphism≈
-- Because of the Level changes in CatF, sizes must all be same:
CatF-is-Free : (o : Level) → Adjoint (CatF {o} {o} {o}) (Underlying)
CatF-is-Free o = record
{ unit = ntHelper record
{ η = GM
; commute = λ {X} {Y} f → record { M₀≡ = ≡.refl ; M₁≡ = Graph.Equiv.refl Y ◅ ε }
}
; counit = ntHelper record
{ η = λ X → record
{ F₀ = idFun
; F₁ = unwind X
; identity = Category.Equiv.refl X
; homomorphism = λ { {f = f} {g} → unwind-◅◅ X {f = f} {g} }
; F-resp-≈ = unwind-resp-≈ X
}
; commute = λ {_} {Y} F → record
{ eq₀ = λ _ → ≡.refl
; eq₁ = λ f → toSquare Y (comm F f)
}
}
; zig = λ {G} → record
{ eq₀ = λ _ → ≡.refl
; eq₁ = λ f → toSquare (Free G) (zig′ G f)
}
; zag = λ {B} → record { M₀≡ = ≡.refl ; M₁≡ = Category.identityˡ B }
}
where
GM : (X : Graph o o o) → GraphMorphism X (Underlying₀ (Free X))
GM _ = record { M₀ = idFun ; M₁ = return ; M-resp-≈ = λ f≈g → f≈g ◅ ε }
module _ (X : Category o o o) where
open Category X
open HomReasoning
unwind : {A B : Obj} → Star _⇒_ A B → A ⇒ B
unwind = fold _⇒_ (flip _∘_) id
unwind-◅◅ : {A B C : Obj} {f : Star _⇒_ A B} {g : Star _⇒_ B C} →
unwind (f ◅◅ g) ≈ (unwind g) ∘ (unwind f)
unwind-◅◅ {f = ε} {g} = Equiv.sym identityʳ
unwind-◅◅ {f = x ◅ f} {g} = ∘-resp-≈ˡ (unwind-◅◅ {f = f} {g}) ○ assoc
unwind-resp-≈ : {A B : Obj} {f g : Star _⇒_ A B} → [ Underlying₀ X ] f ≈* g → unwind f ≈ unwind g
unwind-resp-≈ ε = Equiv.refl
unwind-resp-≈ (x ◅ eq) = ∘-resp-≈ (unwind-resp-≈ eq) x
zig′ : (X : Graph o o o) → {A B : Graph.Obj X} → (f : Star (Graph._⇒_ X) A B) →
let Y = Free X in [ X ] (unwind Y) (mapGraph (GM X) f) ≈* f
zig′ A ε = ε
zig′ A (fs ◅ f) = Graph.Equiv.refl A ◅ zig′ A f
module _ {X Y : Category o o o} (F : Functor X Y) where
open Category X renaming (Obj to Obj₁; _⇒_ to _⇒₁_)
open Category Y renaming (_≈_ to _≈₂_; module Equiv to EY)
open Category.HomReasoning Y
open Functor F
comm : {A B : Obj₁} (f : Star _⇒₁_ A B) → unwind Y (mapGraph (Underlying₁ F) f) ≈₂ F₁ (unwind X f)
comm ε = EY.sym identity
comm (x ◅ f) = EY.sym (homomorphism ○ Category.∘-resp-≈ˡ Y (EY.sym (comm f)))
|
{
"alphanum_fraction": 0.5119590834,
"avg_line_length": 36.5926605505,
"ext": "agda",
"hexsha": "38bb94518fce804cb7ef45c3a1e14e1ce5c39657",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Category/Construction/Graphs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"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/agda-categories",
"max_issues_repo_path": "Categories/Category/Construction/Graphs.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Category/Construction/Graphs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9230,
"size": 19943
}
|
module bug where
data True : Set where
tt : True
data Sigma (x : True) : Set where
pair : True -> Sigma x
postulate
p : True
T : True -> Sigma p -> Set
T tt (pair _) = True
postulate
S : True -> Sigma p -> Set
z : Sigma p
z = pair p
postulate
build : (q : Sigma p) -> T p q -> True
pz : T p z
|
{
"alphanum_fraction": 0.5727848101,
"avg_line_length": 12.1538461538,
"ext": "agda",
"hexsha": "c55ad304adbfc457452444df15e40951702bd699",
"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/bugs/fixed/DroppingParameters.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/bugs/fixed/DroppingParameters.agda",
"max_line_length": 40,
"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/bugs/fixed/DroppingParameters.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": 109,
"size": 316
}
|
module conversion where
open import constants
open import cedille-types
open import ctxt
open import free-vars
open import rename
open import subst
open import syntax-util
open import general-util
open import type-util
record unfolding : Set where
constructor unfold
field
unfold-all : 𝔹
unfold-defs : 𝔹
unfold-erase : 𝔹
unfold-all : unfolding
unfold-all = unfold tt tt tt
unfold-head : unfolding
unfold-head = unfold ff tt tt
unfold-head-elab : unfolding
unfold-head-elab = unfold ff tt ff
unfold-no-defs : unfolding
unfold-no-defs = unfold tt ff ff
unfold-head-no-defs : unfolding
unfold-head-no-defs = unfold ff ff ff
unfold-dampen : unfolding → unfolding
unfold-dampen (unfold a d e) = unfold a (a && d) e
conv-t : Set → Set
conv-t T = ctxt → T → T → 𝔹
{-# TERMINATING #-}
-- main entry point
-- does not assume erased
conv-term : conv-t term
conv-type : conv-t type
conv-kind : conv-t kind
-- assume erased
conv-terme : conv-t term
conv-argse : conv-t (𝕃 term)
conv-typee : conv-t type
conv-kinde : conv-t kind
-- call hnf, then the conv-X-norm functions
conv-term' : conv-t term
conv-type' : conv-t type
hnf : ∀ {ed : exprd} → ctxt → (u : unfolding) → ⟦ ed ⟧ → ⟦ ed ⟧
-- assume head normalized inputs
conv-term-norm : conv-t term
conv-type-norm : conv-t type
conv-kind-norm : conv-t kind
-- does not assume erased
conv-tpkd : conv-t tpkd
conv-tmtp : conv-t tmtp
conv-tmtp* : conv-t (𝕃 tmtp)
-- assume erased
conv-tpkde : conv-t tpkd
conv-tmtpe : conv-t tmtp
conv-tmtpe* : conv-t (𝕃 tmtp)
conv-ctr-ps : ctxt → var → var → maybe (ℕ × ℕ)
conv-ctr-args : conv-t (var × args)
conv-ctr : conv-t var
conv-term Γ t t' = conv-terme Γ (erase t) (erase t')
conv-terme Γ t t' with decompose-apps t | decompose-apps t'
conv-terme Γ t t' | Var x , args | Var x' , args' =
ctxt-eq-rep Γ x x' && conv-argse Γ (erase-args args) (erase-args args')
|| conv-ctr-args Γ (x , args) (x' , args')
|| conv-term' Γ t t'
conv-terme Γ t t' | _ | _ = conv-term' Γ t t'
conv-argse Γ [] [] = tt
conv-argse Γ (a :: args) (a' :: args') = conv-terme Γ a a' && conv-argse Γ args args'
conv-argse Γ _ _ = ff
conv-type Γ t t' = conv-typee Γ (erase t) (erase t')
conv-typee Γ t t' with decompose-tpapps t | decompose-tpapps t'
conv-typee Γ t t' | TpVar x , args | TpVar x' , args' =
ctxt-eq-rep Γ x x' && conv-tmtp* Γ args args'
|| conv-type' Γ t t'
conv-typee Γ t t' | _ | _ = conv-type' Γ t t'
conv-kind Γ k k' = conv-kinde Γ (erase k) (erase k')
conv-kinde Γ k k' = conv-kind-norm Γ (hnf Γ unfold-head k) (hnf Γ unfold-head k')
conv-term' Γ t t' = conv-term-norm Γ (hnf Γ unfold-head t) (hnf Γ unfold-head t')
conv-type' Γ t t' = conv-type-norm Γ (hnf Γ unfold-head t) (hnf Γ unfold-head t')
hnf {TERM} Γ u (AppE t T) = hnf Γ u t
hnf {TERM} Γ u (Beta _ t) = hnf Γ u t
hnf {TERM} Γ u (Delta b? T t) = id-term
hnf {TERM} Γ u (Hole pi) = Hole pi
hnf {TERM} Γ u (IotaPair t₁ t₂ x Tₓ) = hnf Γ u t₁
hnf {TERM} Γ u (IotaProj t n) = hnf Γ u t
hnf {TERM} Γ u (Lam tt x T t) = hnf Γ u t
hnf {TERM} Γ u (LetTp x k T t) = hnf Γ u t
hnf {TERM} Γ u (Phi tₑ t₁ t₂) = hnf Γ u t₂
hnf {TERM} Γ u (Rho tₑ x Tₓ t) = hnf Γ u t
hnf {TERM} Γ u (VarSigma t) = hnf Γ u t
hnf {TERM} Γ u (App t t') with hnf Γ u t
...| Lam ff x nothing t'' = hnf Γ u ([ Γ - t' / x ] t'')
...| t'' = App t'' (hnf Γ (unfold-dampen u) t')
hnf {TERM} Γ u (Lam ff x _ t) with hnf (ctxt-var-decl x Γ) u t
...| App t' (Var x') = if x' =string x && ~ is-free-in x t' then t' else Lam ff x nothing (App t' (Var x'))
...| t' = Lam ff x nothing t'
hnf {TERM} Γ u (LetTm me x T t t') = hnf Γ u ([ Γ - t / x ] t')
hnf {TERM} Γ u (Var x) with
ifMaybe (unfolding.unfold-defs u) $ ctxt-lookup-term-var-def Γ x
...| nothing = Var x
...| just t = hnf Γ (unfold-dampen u) t
hnf {TERM} Γ u (Mu f tₒ _ t~ cs') =
let t = hnf Γ u tₒ
Γ' = ctxt-var-decl f Γ
cs = erase-cases cs'
t-else = λ t → Mu f t nothing t~ $ flip map cs λ where
(Case x cas t T) → Case x cas
(hnf (add-caseArgs-to-ctxt cas Γ') (unfold-dampen u) t) T
case-matches : var → args → case → maybe (term × case-args × args)
case-matches = λ {cₓ as (Case cₓ' cas t T) →
conv-ctr-ps Γ cₓ' cₓ ≫=maybe uncurry λ ps' ps →
ifMaybej (length as =ℕ length cas + ps) (t , cas , drop ps as)}
matching-case = λ cₓ as → foldr (_||-maybe_ ∘ case-matches cₓ as) nothing cs
sub-mu = let x = fresh-var Γ "x" in , Lam ff x nothing (t-else (Var x))
sub = λ Γ → substs Γ (trie-insert (trie-single f sub-mu) (data-to/ f) (, id-term)) in
maybe-else' (decompose-var-headed t ≫=maybe uncurry matching-case) (t-else t) λ where
(tₓ , cas , as) → hnf Γ u (recompose-apps as (case-args-to-lams cas (sub (add-caseArgs-to-ctxt cas Γ') tₓ)))
hnf {TERM} Γ u (Sigma mt tₒ _ t~ cs') =
let t = hnf Γ u tₒ
cs = erase-cases cs'
t-else = λ t → Sigma nothing t nothing t~ $ flip map cs λ where
(Case x cas t T) → Case x cas
(hnf (add-caseArgs-to-ctxt cas Γ) (unfold-dampen u) t) T
case-matches : var → args → case → maybe (term × case-args × args)
case-matches = λ {cₓ as (Case cₓ' cas t T) →
conv-ctr-ps Γ cₓ' cₓ ≫=maybe uncurry λ ps' ps →
ifMaybej (length as =ℕ length cas + ps) (t , cas , drop ps as)}
matching-case = λ cₓ as → foldr (_||-maybe_ ∘ case-matches cₓ as) nothing cs
sub = λ Γ → id {A = term} in
maybe-else' (decompose-var-headed t ≫=maybe uncurry matching-case) (t-else t) λ where
(tₓ , cas , as) → hnf Γ u (recompose-apps as (case-args-to-lams cas (sub (add-caseArgs-to-ctxt cas Γ) tₓ)))
hnf{TYPE} Γ u (TpAbs me x tk tp) = TpAbs me x (hnf Γ (unfold-dampen u) -tk tk) (hnf (ctxt-var-decl x Γ) (unfold-dampen u) tp)
hnf{TYPE} Γ u (TpIota x tp₁ tp₂) = TpIota x (hnf Γ (unfold-dampen u) tp₁) (hnf (ctxt-var-decl x Γ) (unfold-dampen u) tp₂)
hnf{TYPE} Γ u (TpAppTp tp tp') with hnf Γ u tp
...| TpLam x _ tp'' = hnf Γ u ([ Γ - tp' / x ] tp'')
...| tp'' = TpAppTp tp'' (hnf Γ (unfold-dampen u) tp')
hnf{TYPE} Γ u (TpAppTm tp tm) with hnf Γ u tp
...| TpLam x _ tp'' = hnf Γ u ([ Γ - tm / x ] tp'')
...| tp'' = TpAppTm tp''
(if unfolding.unfold-erase u then hnf Γ (unfold-dampen u) tm else tm)
hnf{TYPE} Γ u (TpEq tm₁ tm₂) = TpEq (hnf Γ (unfold-dampen u) tm₁) (hnf Γ (unfold-dampen u) tm₂)
hnf{TYPE} Γ u (TpHole pi) = TpHole pi
hnf{TYPE} Γ u (TpLam x tk tp) = TpLam x (hnf Γ (unfold-dampen u) -tk tk) (hnf (ctxt-var-decl x Γ) (unfold-dampen u) tp)
hnf{TYPE} Γ u (TpVar x) with
ifMaybe (unfolding.unfold-defs u) $ ctxt-lookup-type-var-def Γ x
...| nothing = TpVar x
...| just t = hnf Γ (unfold-dampen u) t
hnf{KIND} Γ u (KdAbs x tk kd) =
KdAbs x (hnf Γ (unfold-dampen u) -tk tk) (hnf (ctxt-var-decl x Γ) u kd)
hnf{KIND} Γ u (KdHole pi) = KdHole pi
hnf{KIND} Γ u KdStar = KdStar
hanf : ctxt → (erase : 𝔹) → term → term
hanf Γ e t with erase-if e t
...| t' = maybe-else t' id
(decompose-var-headed t' ≫=maybe uncurry λ x as →
ctxt-lookup-term-var-def Γ x ≫=maybe λ t'' →
just (recompose-apps as t''))
-- unfold across the term-type barrier
hnf-term-type : ctxt → (erase : 𝔹) → type → type
hnf-term-type Γ e (TpEq t₁ t₂) = TpEq (hanf Γ e t₁) (hanf Γ e t₂)
hnf-term-type Γ e (TpAppTm tp t) = hnf Γ (record unfold-head {unfold-erase = e}) (TpAppTm tp (hanf Γ e t))
hnf-term-type Γ e tp = hnf Γ unfold-head tp
conv-cases : conv-t cases
conv-cases Γ cs₁ cs₂ = isJust $ foldl (λ c₂ x → x ≫=maybe λ cs₁ → conv-cases' Γ cs₁ c₂) (just cs₁) cs₂ where
conv-cases' : ctxt → cases → case → maybe cases
conv-cases' Γ [] (Case x₂ as₂ t₂ T₂) = nothing
conv-cases' Γ (c₁ @ (Case x₁ as₁ t₁ T₁) :: cs₁) c₂ @ (Case x₂ as₂ t₂ T₂) with conv-ctr Γ x₁ x₂
...| ff = conv-cases' Γ cs₁ c₂ ≫=maybe λ cs₁ → just (c₁ :: cs₁)
...| tt = ifMaybej (length as₂ =ℕ length as₁ && conv-term Γ (expand-case c₁) (expand-case (Case x₂ as₂ t₂ T₂))) cs₁
ctxt-term-udef : posinfo → defScope → opacity → var → term → ctxt → ctxt
conv-term-norm Γ (Var x) (Var x') = ctxt-eq-rep Γ x x' || conv-ctr Γ x x'
-- hnf implements erasure for terms, so we can ignore some subterms for App and Lam cases below
conv-term-norm Γ (App t1 t2) (App t1' t2') = conv-term-norm Γ t1 t1' && conv-term Γ t2 t2'
conv-term-norm Γ (Lam ff x _ t) (Lam ff x' _ t') = conv-term (ctxt-rename x x' (ctxt-var-decl-if x' Γ)) t t'
conv-term-norm Γ (Hole _) _ = tt
conv-term-norm Γ _ (Hole _) = tt
conv-term-norm Γ (Mu x₁ t₁ _ _ cs₁) (Mu x₂ t₂ _ _ cs₂) =
let Γ' = ctxt-rename x₁ x₂ $ ctxt-var-decl x₂ Γ in
conv-term Γ t₁ t₂ && conv-cases Γ' cs₁ cs₂
conv-term-norm Γ (Sigma _ t₁ _ _ cs₁) (Sigma _ t₂ _ _ cs₂) = conv-term Γ t₁ t₂ && conv-cases Γ cs₁ cs₂
{- it can happen that a term is equal to a lambda abstraction in head-normal form,
if that lambda-abstraction would eta-contract following some further beta-reductions.
We implement this here by implicitly eta-expanding the variable and continuing
the comparison.
A simple example is
λ v . t ((λ a . a) v) ≃ t
-}
conv-term-norm Γ (Lam ff x _ t) t' =
let x' = fresh-var Γ x in
conv-term (ctxt-rename x x' Γ) t (App t' (Var x'))
conv-term-norm Γ t' (Lam ff x _ t) =
let x' = fresh-var Γ x in
conv-term (ctxt-rename x x' Γ) (App t' (Var x')) t
conv-term-norm Γ _ _ = ff
conv-type-norm Γ (TpVar x) (TpVar x') = ctxt-eq-rep Γ x x'
conv-type-norm Γ (TpApp t1 t2) (TpApp t1' t2') = conv-type-norm Γ t1 t1' && conv-tmtp Γ t2 t2'
conv-type-norm Γ (TpAbs me x tk tp) (TpAbs me' x' tk' tp') =
(me iff me') && conv-tpkd Γ tk tk' && conv-type (ctxt-rename x x' (ctxt-var-decl-if x' Γ)) tp tp'
conv-type-norm Γ (TpIota x m tp) (TpIota x' m' tp') =
conv-type Γ m m' && conv-type (ctxt-rename x x' (ctxt-var-decl-if x' Γ)) tp tp'
conv-type-norm Γ (TpEq t₁ t₂) (TpEq t₁' t₂') = conv-term Γ t₁ t₁' && conv-term Γ t₂ t₂'
conv-type-norm Γ (TpLam x tk tp) (TpLam x' tk' tp') =
conv-tpkd Γ tk tk' && conv-type (ctxt-rename x x' (ctxt-var-decl-if x' Γ)) tp tp'
conv-type-norm Γ _ _ = ff
{- even though hnf turns Pi-kinds where the variable is not free in the body into arrow kinds,
we still need to check off-cases, because normalizing the body of a kind could cause the
bound variable to be erased (hence allowing it to match an arrow kind). -}
conv-kind-norm Γ (KdAbs x tk k) (KdAbs x' tk' k'') =
conv-tpkd Γ tk tk' && conv-kind (ctxt-rename x x' (ctxt-var-decl-if x' Γ)) k k''
conv-kind-norm Γ KdStar KdStar = tt
conv-kind-norm Γ _ _ = ff
conv-tpkd Γ tk tk' = conv-tpkde Γ (erase -tk tk) (erase -tk tk')
conv-tmtp Γ tT tT' = conv-tmtpe Γ (erase -tT tT) (erase -tT tT')
conv-tpkde Γ (Tkk k) (Tkk k') = conv-kind Γ k k'
conv-tpkde Γ (Tkt t) (Tkt t') = conv-type Γ t t'
conv-tpkde Γ _ _ = ff
conv-tmtpe Γ (Ttm t) (Ttm t') = conv-term Γ t t'
conv-tmtpe Γ (Ttp T) (Ttp T') = conv-type Γ T T'
conv-tmtpe Γ _ _ = ff
conv-tmtp* = =𝕃 ∘ conv-tmtp
conv-tmtpe* = =𝕃 ∘ conv-tmtpe
conv-ctr Γ x₁ x₂ = conv-ctr-args Γ (x₁ , []) (x₂ , [])
conv-ctr-ps Γ x₁ x₂ with env-lookup Γ x₁ | env-lookup Γ x₂
...| just (ctr-def ps₁ T₁ n₁ i₁ a₁ , _) | just (ctr-def ps₂ T₂ n₂ i₂ a₂ , _) =
ifMaybej (n₁ =ℕ n₂ && i₁ =ℕ i₂ && a₁ =ℕ a₂) (length (erase-params ps₁) , length (erase-params ps₂))
...| _ | _ = nothing
conv-ctr-args Γ (x₁ , as₁) (x₂ , as₂) =
maybe-else' (conv-ctr-ps Γ x₁ x₂) ff $ uncurry λ ps₁ ps₂ →
let as₁ = erase-args as₁; as₂ = erase-args as₂ in
ps₁ ∸ length as₁ =ℕ ps₂ ∸ length as₂ &&
conv-argse Γ (drop ps₁ as₁) (drop ps₂ as₂)
{-# TERMINATING #-}
inconv : ctxt → term → term → 𝔹
inconv Γ t₁ t₂ = inconv-lams empty-renamectxt empty-renamectxt
(hnf Γ unfold-all t₁) (hnf Γ unfold-all t₂)
where
fresh : var → renamectxt → renamectxt → var
fresh x ρ₁ ρ₂ = fresh-h (λ x → ctxt-binds-var Γ x || renamectxt-in-field ρ₁ x || renamectxt-in-field ρ₂ x) x
make-subst : renamectxt → renamectxt → 𝕃 var → 𝕃 var → term → term → (renamectxt × renamectxt × term × term)
make-subst ρ₁ ρ₂ [] [] t₁ t₂ = ρ₁ , ρ₂ , t₁ , t₂
make-subst ρ₁ ρ₂ (x₁ :: xs₁) [] t₁ t₂ =
let x = fresh x₁ ρ₁ ρ₂ in
make-subst (renamectxt-insert ρ₁ x₁ x) (renamectxt-insert ρ₂ x x) xs₁ [] t₁ (App t₂ $ Var x)
make-subst ρ₁ ρ₂ [] (x₂ :: xs₂) t₁ t₂ =
let x = fresh x₂ ρ₁ ρ₂ in
make-subst (renamectxt-insert ρ₁ x x) (renamectxt-insert ρ₂ x₂ x) [] xs₂ (App t₁ $ Var x) t₂
make-subst ρ₁ ρ₂ (x₁ :: xs₁) (x₂ :: xs₂) t₁ t₂ =
let x = fresh x₁ ρ₁ ρ₂ in
make-subst (renamectxt-insert ρ₁ x₁ x) (renamectxt-insert ρ₂ x₂ x) xs₁ xs₂ t₁ t₂
inconv-lams : renamectxt → renamectxt → term → term → 𝔹
inconv-apps : renamectxt → renamectxt → var → var → args → args → 𝔹
inconv-ctrs : renamectxt → renamectxt → var → var → args → args → 𝔹
inconv-mu : renamectxt → renamectxt → maybe (var × var) → cases → cases → 𝔹
inconv-args : renamectxt → renamectxt → args → args → 𝔹
inconv-args ρ₁ ρ₂ a₁ a₂ =
let a₁ = erase-args a₁; a₂ = erase-args a₂ in
~ length a₁ =ℕ length a₂
|| list-any (uncurry $ inconv-lams ρ₁ ρ₂) (zip a₁ a₂)
inconv-lams ρ₁ ρ₂ t₁ t₂ =
elim-pair (decompose-lams t₁) λ l₁ b₁ →
elim-pair (decompose-lams t₂) λ l₂ b₂ →
elim-pair (make-subst ρ₁ ρ₂ l₁ l₂ b₁ b₂) λ ρ₁ ρ₂b₁₂ →
elim-pair ρ₂b₁₂ λ ρ₂ b₁₂ →
elim-pair b₁₂ λ b₁ b₂ →
case (decompose-apps b₁ , decompose-apps b₂) of uncurry λ where
(Var x₁ , a₁) (Var x₂ , a₂) →
inconv-apps ρ₁ ρ₂ x₁ x₂ a₁ a₂ || inconv-ctrs ρ₁ ρ₂ x₁ x₂ a₁ a₂
(Mu x₁ t₁ _ _ ms₁ , a₁) (Mu x₂ t₂ _ _ ms₂ , a₂) →
inconv-mu ρ₁ ρ₂ (just $ x₁ , x₂) ms₁ ms₂ ||
inconv-lams ρ₁ ρ₂ t₁ t₂ || inconv-args ρ₁ ρ₂ a₁ a₂
(Sigma _ t₁ _ _ ms₁ , a₁) (Sigma _ t₂ _ _ ms₂ , a₂) →
inconv-mu ρ₁ ρ₂ nothing ms₁ ms₂ ||
inconv-lams ρ₁ ρ₂ t₁ t₂ || inconv-args ρ₁ ρ₂ a₁ a₂
_ _ → ff
inconv-apps ρ₁ ρ₂ x₁ x₂ a₁ a₂ =
maybe-else' (renamectxt-lookup ρ₁ x₁) ff λ x₁ →
maybe-else' (renamectxt-lookup ρ₂ x₂) ff λ x₂ →
~ x₁ =string x₂
|| inconv-args ρ₁ ρ₂ a₁ a₂
inconv-ctrs ρ₁ ρ₂ x₁ x₂ as₁ as₂ with env-lookup Γ x₁ | env-lookup Γ x₂
...| just (ctr-def ps₁ _ n₁ i₁ a₁ , _) | just (ctr-def ps₂ _ n₂ i₂ a₂ , _) =
let ps₁ = erase-params ps₁; ps₂ = erase-params ps₂
as₁ = erase-args as₁; as₂ = erase-args as₂ in
length as₁ ≤ length ps₁ + a₁ && -- Could use of "≤" here conflict with η-equality?
length as₂ ≤ length ps₂ + a₂ &&
(~ n₁ =ℕ n₂ ||
~ i₁ =ℕ i₂ ||
~ a₁ =ℕ a₂ ||
~ length as₁ + length ps₂ =ℕ length as₂ + length ps₁ ||
-- ^ as₁ ∸ ps₁ ≠ as₂ ∸ ps₂, + ps₁ + ps₂ to both sides ^
list-any (uncurry $ inconv-lams ρ₁ ρ₂)
(zip (drop (length ps₁) as₁) (drop (length ps₂) as₂)))
...| _ | _ = ff
inconv-mu ρ₁ ρ₂ xs? ms₁ ms₂ =
~ length ms₁ =ℕ length ms₂ ||
maybe-else ff id
(foldr {B = maybe 𝔹} (λ c b? → b? ≫=maybe λ b → inconv-case c ≫=maybe λ b' → just (b || b')) (just ff) ms₁)
where
matching-case : case → maybe (term × ℕ × ℕ)
matching-case (Case x _ _ _) = foldl (λ where
(Case xₘ cas tₘ _) m? → m? ||-maybe
(conv-ctr-ps Γ xₘ x ≫=maybe uncurry λ psₘ ps →
just (case-args-to-lams cas tₘ , length cas , ps)))
nothing ms₂
inconv-case : case → maybe 𝔹
inconv-case c₁ @ (Case x cas₁ t₁ _) =
matching-case c₁ ≫=maybe λ c₂ →
just (inconv-lams ρ₁ ρ₂ (case-args-to-lams cas₁ t₁) (fst c₂))
ctxt-kind-def : posinfo → var → params → kind → ctxt → ctxt
ctxt-kind-def pi v ps2 k Γ =
record Γ {
qual = qualif-insert-params (ctxt.qual Γ) (ctxt.mn Γ # v) v (ctxt.ps Γ);
syms = trie-insert-append2 (ctxt.syms Γ) (ctxt.fn Γ) (ctxt.mn Γ) v;
i = trie-insert (ctxt.i Γ) (ctxt.mn Γ # v)
(kind-def (ctxt.ps Γ ++ ps2) (hnf Γ unfold-head-elab k) , ctxt.fn Γ , pi)
}
ctxt-datatype-decl : var → var → args → ctxt → ctxt
ctxt-datatype-decl vₒ vᵣ as Γ =
record Γ {
μ' = trie-insert (ctxt.μ' Γ) (mu-Type/ vᵣ) (vₒ , as);
μ̲ = stringset-insert (ctxt.μ̲ Γ) (mu-Type/ vᵣ)
}
ctxt-datatype-undef : var → ctxt → ctxt
ctxt-datatype-undef v Γ =
record Γ {
μ = trie-remove (ctxt.μ Γ) v;
μ' = trie-remove (ctxt.μ' Γ) v;
Is/μ = trie-remove (ctxt.Is/μ Γ) v;
μ~ = trie-remove (ctxt.μ~ Γ) v;
μ̲ = trie-remove (ctxt.μ̲ Γ) v
}
ctxt-datatype-def : posinfo → var → params → kind → kind → ctrs → encoding-defs → ctxt → ctxt
ctxt-datatype-def pi D psᵢ kᵢ k cs eds Γ =
let D' = ctxt.mn Γ # D
ecds = record {
Is/D = data-Is/ D';
is/D = data-is/ D';
to/D = data-to/ D';
TypeF/D = data-TypeF/ D';
fmap/D = data-fmap/ D';
IndF/D = data-IndF/ D'} in
record Γ {
qual = qualif-insert-params (ctxt.qual Γ) D' D (ctxt.ps Γ);
syms = trie-insert-append2 (ctxt.syms Γ) (ctxt.fn Γ) (ctxt.mn Γ) D;
i = trie-insert (ctxt.i Γ) D' (type-def (just (ctxt.ps Γ)) tt nothing (abs-expand-kind psᵢ k) , ctxt.fn Γ , pi);
μ = trie-insert (ctxt.μ Γ) D' (ctxt.ps Γ ++ psᵢ , kᵢ , k , cs , eds , ecds);
Is/μ = trie-insert (ctxt.Is/μ Γ) (data-Is/ D') D';
μ~ = trie-insert (ctxt.μ~ Γ) D' (foldl pull-defs [] (encoding-defs.ecs eds ++ encoding-defs.gcs eds));
μᵤ = just eds;
μ̲ = stringset-insert (ctxt.μ̲ Γ) D'
}
where
pull-defs : cmd → 𝕃 (var × tmtp) → 𝕃 (var × tmtp)
pull-defs (CmdDefTerm x t) μ~ = ((ctxt.mn Γ # x) , Ttm t) :: μ~
pull-defs (CmdDefType x k T) μ~ = ((ctxt.mn Γ # x) , Ttp T) :: μ~
pull-defs _ μ~ = μ~
ctxt-type-def : posinfo → defScope → opacity → var → maybe type → kind → ctxt → ctxt
ctxt-type-def _ _ _ ignored-var _ _ Γ = Γ
ctxt-type-def pi s op v t k Γ =
let v' = if s iff localScope then pi % v else ctxt.mn Γ # v in
record Γ {
qual = qualif-insert-params (ctxt.qual Γ) v' v (if s iff localScope then [] else ctxt.ps Γ);
i = trie-insert (ctxt.i Γ) v' (type-def (def-params s (ctxt.ps Γ)) op (hnf Γ unfold-head-elab <$> t) k , ctxt.fn Γ , pi)
}
ctxt-ctr-def : posinfo → var → type → params → (ctrs-length ctr-index : ℕ) → ctxt → ctxt
ctxt-ctr-def pi c t ps' n i Γ =
let c' = ctxt.mn Γ # c in
record Γ {
qual = qualif-insert-params (ctxt.qual Γ) c' c (ctxt.ps Γ);
syms = trie-insert-append2 (ctxt.syms Γ) (ctxt.fn Γ) (ctxt.mn Γ) c;
i = trie-insert (ctxt.i Γ) c' (ctr-def ps' t n i (unerased-arrows t) , ctxt.fn Γ , pi)
}
ctxt-term-def : posinfo → defScope → opacity → var → maybe term → type → ctxt → ctxt
ctxt-term-def _ _ _ ignored-var _ _ Γ = Γ
ctxt-term-def pi s op v t tp Γ =
let v' = if s iff localScope then pi % v else ctxt.mn Γ # v in
record Γ {
qual = qualif-insert-params (ctxt.qual Γ) v' v (if s iff localScope then [] else ctxt.ps Γ);
syms = if s iff localScope then ctxt.syms Γ else trie-insert-append2 (ctxt.syms Γ) (ctxt.fn Γ) (ctxt.mn Γ) v;
i = trie-insert (ctxt.i Γ) v' (term-def (def-params s (ctxt.ps Γ)) op (hnf Γ unfold-head <$> t) tp , ctxt.fn Γ , pi)
}
ctxt-term-udef _ _ _ ignored-var _ Γ = Γ
ctxt-term-udef pi s op v t Γ =
let v' = if s iff localScope then pi % v else ctxt.mn Γ # v in
record Γ {
qual = qualif-insert-params (ctxt.qual Γ) v' v (if s iff localScope then [] else ctxt.ps Γ);
syms = if s iff localScope then ctxt.syms Γ else trie-insert-append2 (ctxt.syms Γ) (ctxt.fn Γ) (ctxt.mn Γ) v;
i = trie-insert (ctxt.i Γ) v' (term-udef (def-params s (ctxt.ps Γ)) op (hnf Γ unfold-head t) , ctxt.fn Γ , pi)
}
|
{
"alphanum_fraction": 0.6073453675,
"avg_line_length": 42.1557017544,
"ext": "agda",
"hexsha": "7b8fa0dc801751a4162c9b4e961f6ad47b91ec60",
"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/conversion.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/conversion.agda",
"max_line_length": 125,
"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/conversion.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7447,
"size": 19223
}
|
module IrrelevantModuleParameter1 (A : Set) .(a : A) where
postulate
P : A -> Set
p : P a
-- cannot use a here, because it is irrelevant
|
{
"alphanum_fraction": 0.6690140845,
"avg_line_length": 23.6666666667,
"ext": "agda",
"hexsha": "57ce5d72918f4b4e13f6b72b8bf6577741f57d37",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/IrrelevantModuleParameter1.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/IrrelevantModuleParameter1.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/IrrelevantModuleParameter1.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": 45,
"size": 142
}
|
{-# OPTIONS --cubical --no-positivity-check --no-termination-check --allow-unsolved-metas #-}
open import Prelude
open import Algebra
open import Algebra.Monus
open import Relation.Binary
open import Data.Maybe
open import Data.List using (List; _∷_; []; foldr)
module Control.Monad.HeapT.Sized
{ℓ}
(mon : CTMAPOM ℓ)
(gmon : GradedMonad (CTMAPOM.monoid mon) ℓ ℓ)
where
open CTMAPOM mon
open GradedMonad gmon
private
variable
w i j : 𝑆
infixr 5 _∷_
infixr 6 _⋊_
mutual
data Root′ (A : Type ℓ) (i : 𝑆) : Type ℓ where
_⋊_ : ∀ w → (w < i → 𝐹 w (Branch A (i ∸ w))) → Root′ A i
data Node (A : Type ℓ) (i : 𝑆) : Type ℓ where
⌊_⌋ : A → Node A i
⌈_⌉ : Root′ A i → Node A i
data Branch (A : Type ℓ) (i : 𝑆) : Type ℓ where
[] : Branch A i
_∷_ : Node A i → 𝐹 ε (Branch A i) → Branch A i
Heap : Type ℓ → Type ℓ
Heap A = ∀ {i} → 𝐹 ε (Branch A i)
infixr 5 _++_
_++_ : 𝐹 w (Branch A i) → 𝐹 ε (Branch A i) → 𝐹 w (Branch A i)
xs ++ ys =
xs >>=ε λ { [] → ys
; (x ∷ xs) → pure (x ∷ xs ++ ys) }
infixr 1 _>>=ᴺ_ _>>=ᴴ_
mutual
_>>=ᴺ_ : Node A i → (A → Heap B) → 𝐹 ε (Branch B i)
⌊ x ⌋ >>=ᴺ f = f x
⌈ w ⋊ s ⌉ >>=ᴺ f = pure (⌈ w ⋊ (λ w<i → s w<i >>=ᴴ f) ⌉ ∷ pure [])
_>>=ᴴ_ : 𝐹 w (Branch A i) → (A → Heap B) → 𝐹 w (Branch B i)
xs >>=ᴴ f =
xs >>=ε λ { [] → pure []
; (x ∷ xs) → (x >>=ᴺ f) ++ (xs >>=ᴴ f) }
pureᴴ : A → Heap A
pureᴴ x = pure (⌊ x ⌋ ∷ pure [])
liftᴴ : 𝐹 w A → Heap A
liftᴴ xs = pure (⌈ _ ⋊ const (map (λ x → ⌊ x ⌋ ∷ pure []) xs) ⌉ ∷ pure [])
flatten : 𝐹 w (Branch A i) → 𝐹 w (List A × List (Root′ A i))
flatten xs =
xs >>=ε λ { [] → pure ([] , [])
; (⌊ x ⌋ ∷ xs) → map (map₁ (x ∷_)) (flatten xs)
; (⌈ x ⌉ ∷ xs) → map (map₂ (x ∷_)) (flatten xs) }
module PopMin
(decomp : ∀ {A B w₁ w₂ w₃} → 𝐹 (w₁ ∙ w₂) A → 𝐹 (w₁ ∙ w₃) B → 𝐹 w₁ (𝐹 w₂ A × 𝐹 w₃ B))
(choice : {w : 𝑆} → {A B : Type ℓ} → (A → 𝐹 w B) → 𝐹 w (A → B))
where
_∪_ : Root′ A i → Root′ A i → Root′ A i
_∪_ {i = i} (wˣ ⋊ xs) (wʸ ⋊ ys) with wˣ ≤|≥ wʸ
... | inr (k , wˣ≡wʸ∙k) = {!!}
... | inl (k , wʸ≡wˣ∙k) = wˣ ⋊ λ wˣ<i → map (λ { (xs , ys) → ⌈ k ⋊ (λ k<i∸wˣ → subst (𝐹 _ ∘ Branch _) (cong (_ ∸_) wʸ≡wˣ∙k ; sym (∸‿assoc _ wˣ k)) (map (_$ subst (_< i) (sym wʸ≡wˣ∙k) {!!}) ys)) ⌉ ∷ xs }) (decomp (subst (flip 𝐹 _) (sym (∙ε _)) (xs wˣ<i)) (subst (flip 𝐹 _) wʸ≡wˣ∙k (choice ys)))
where
lemma : ∀ x y z → x < z → y < z ∸ x → x ∙ y < z
lemma = {!!}
-- ⋃⁺ : Root A → List (Root A) → Root A
-- ⋃⁺ x₁ [] = x₁
-- ⋃⁺ x₁ (x₂ ∷ []) = x₁ ∪ x₂
-- ⋃⁺ x₁ (x₂ ∷ x₃ ∷ xs) = (x₁ ∪ x₂) ∪ ⋃⁺ x₃ xs
-- ⋃ : List (Root A) → Maybe (Root A)
-- ⋃ [] = nothing
-- ⋃ (x ∷ xs) = just (⋃⁺ x xs)
-- popMin : 𝐹 w (Branch A) → 𝐹 w (List A × Maybe (Root A))
-- popMin = map (map₂ ⋃) ∘ flatten
|
{
"alphanum_fraction": 0.4643864598,
"avg_line_length": 30.170212766,
"ext": "agda",
"hexsha": "5ef6211a17f6acfb60f3209468a30f68478dd41f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Control/Monad/HeapT/Sized.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Control/Monad/HeapT/Sized.agda",
"max_line_length": 296,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Control/Monad/HeapT/Sized.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 1443,
"size": 2836
}
|
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS --guardedness #-}
open import Data.Empty
open import Data.Product
open import Data.Sum
open import Data.List using ([]; _++_; _∷_; _∷ʳ_)
open import Relation.Nullary
open import Relation.Nullary.Negation using (contraposition)
open import Relation.Unary using (_∈_)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym; subst)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_; _◅◅_; return)
open import Common
module FairCompliance {ℙ : Set} (message : Message ℙ)
where
open import Trace message
open import Session message
open import SessionType message
open import Transitions message
open import HasTrace message
fair-compliance-red* : ∀{S S'} -> FairComplianceS S -> Reductions S S' -> FairComplianceS S'
fair-compliance-red* comp reds reds' = comp (reds ◅◅ reds')
fair-compliance->may-succeed : ∀{S} -> FairComplianceS S -> MaySucceed S
fair-compliance->may-succeed fcomp = fcomp ε
fc-after-output :
∀{f g x} ->
FairComplianceS (out f # inp g) ->
x ∈ dom f ->
FairComplianceS (f x .force # g x .force)
fc-after-output comp fx reds = comp (sync (out fx) inp ◅ reds)
fc-after-input :
∀{f g x} ->
FairComplianceS (inp f # out g) ->
x ∈ dom g ->
FairComplianceS (f x .force # g x .force)
fc-after-input comp gx reds = comp (sync inp (out gx) ◅ reds)
fc-input : ∀{R f} -> FairComplianceS (R # inp f) ->
Win R ⊎ ∃[ g ] (R ≡ out g × Witness g × (∀{x} (!x : x ∈ dom g) -> FairComplianceS (g x .force # f x .force)))
fc-input {nil} spec with spec ε
... | _ , ε , win#def () _
... | _ , sync () _ ◅ _ , _
fc-input {inp _} spec with spec ε
... | _ , ε , win#def () _
... | _ , sync () inp ◅ _ , _
fc-input {out g} spec with Empty? g
... | inj₁ U = inj₁ (out U)
... | inj₂ W = inj₂ (g , refl , W , λ !x -> fair-compliance-red* spec (return (sync (out !x) inp)))
fc-output : ∀{R f} -> FairComplianceS (R # out f) ->
Win R ⊎ ∃[ g ] (R ≡ inp g × Witness f × (∀{x} (!x : x ∈ dom f) -> FairComplianceS (g x .force # f x .force)))
fc-output {nil} spec with spec ε
... | _ , ε , win#def () out
... | _ , sync () _ ◅ _ , _
fc-output {inp g} {f} spec with Empty? f
... | inj₂ W = inj₂ (g , refl , W , λ !x -> fair-compliance-red* spec (return (sync inp (out !x))))
... | inj₁ U with spec ε
... | _ , ε , win#def () _
... | _ , sync inp (out !x) ◅ _ , _ = ⊥-elim (U _ !x)
fc-output {out g} spec with Empty? g
... | inj₁ U = inj₁ (out U)
... | inj₂ (_ , !x) with spec ε
... | _ , ε , win#def (out U) out = ⊥-elim (U _ !x)
... | _ , sync () (out _) ◅ _ , _
fc-transitions :
∀{R R' T T' φ} ->
Transitions R (co-trace φ) R' ->
Transitions T φ T' ->
FairComplianceS (R # T) ->
FairComplianceS (R' # T')
fc-transitions rr tr comp = fair-compliance-red* comp (zip-red* rr tr)
fc-trace :
∀{R T φ} ->
FairComplianceS (R # T) ->
(rφ : R HasTrace (co-trace φ))
(tφ : T HasTrace φ) ->
FairComplianceS (after rφ # after tφ)
fc-trace comp (_ , _ , rr) (_ , _ , tr) = fc-transitions rr tr comp
fc-output-trace :
∀{R T x} ->
FairComplianceS (R # T) ->
T HasTrace (O x ∷ []) ->
Win R ⊎ (R HasTrace (I x ∷ []))
fc-output-trace {nil} comp tφ with comp ε
... | _ , ε , win#def () _
... | _ , sync () _ ◅ _ , _
fc-output-trace {inp f} {_} {x} comp (_ , _ , step (out gx) refl) with x ∈? f
... | yes fx = inj₂ (_ , fx , step inp refl)
... | no nfx with comp (return (sync inp (out gx)))
... | _ , ε , win#def w _ = ⊥-elim (nfx (win->defined w))
... | _ , sync r _ ◅ _ , _ = ⊥-elim (contraposition transition->defined nfx r)
fc-output-trace {out f} comp (_ , _ , step (out _) refl) with comp ε
... | _ , ε , win#def w _ = inj₁ w
... | _ , sync () (out _) ◅ _ , _
has-trace-snoc :
∀{T φ α} -> T HasTrace (φ ∷ʳ α) ->
∃ λ (tφ : T HasTrace φ) -> after tφ HasTrace (α ∷ [])
has-trace-snoc {_} {[]} tα@(_ , _ , step inp refl) = (_ , inp , refl) , tα
has-trace-snoc {_} {[]} tα@(_ , _ , step (out _) refl) = (_ , out , refl) , tα
has-trace-snoc {_} {_ ∷ φ} (_ , def , step t tr) =
let (_ , tdef , sr) , tφ/α = has-trace-snoc (_ , def , tr) in
(_ , tdef , step t sr) , tφ/α
client-wins-or-accepts-prefix :
∀{R T φ x}
(comp : FairComplianceS (R # T))
(rφ : R HasTrace (co-trace φ))
(tφ : T HasTrace (φ ∷ʳ O x)) ->
Win (after rφ) ⊎ R HasTrace (co-trace (φ ∷ʳ O x))
client-wins-or-accepts-prefix {_} {_} {φ} comp rφ tφα with has-trace-snoc tφα
... | tφ , tφ/α with fc-trace comp rφ tφ
... | comp/φ with fc-output-trace comp/φ tφ/α
... | inj₁ w = inj₁ w
... | inj₂ rφ/α =
let rφα = join-trace rφ rφ/α in
inj₂ (subst (_ HasTrace_) (sym (co-trace-++ φ _)) rφα)
|
{
"alphanum_fraction": 0.6206595708,
"avg_line_length": 37.4575163399,
"ext": "agda",
"hexsha": "da1cde639f292092f5067585d64e74c941706520",
"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": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/FairCompliance.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"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": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/FairCompliance.agda",
"max_line_length": 121,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/FairCompliance.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 1932,
"size": 5731
}
|
module OscarPrelude where
open import Prelude public
renaming (_==_ to _≟_) -- TODO ask Agda to rename Eq._==_ to Eq._≟_
renaming (force to force!) -- needed by ∞Delay
renaming (forceLemma to force!Lemma)
_≢_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
x ≢ y = ¬ (x ≡ y)
infix 0 _↔_
_↔_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
P ↔ Q = (P → Q) × (Q → P)
infix 0 _←⊗→_
_←⊗→_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
P ←⊗→ Q = (P → ¬ Q) × (Q → ¬ P)
∃ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
∃ = Σ _
∄ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
∄ = ¬_ ∘ ∃
infixl 4 _⊎_
_⊎_ = Either
{-# DISPLAY Either = _⊎_ #-}
--open import Agda.Builtin.Size public
open import Size public
open import Control.Monad.State public
open import Control.Monad.Identity public
open import Container.Traversable public
open import Container.List renaming (_∈_ to _∈Container_) public
sequence : ∀ {a b} {A : Set a} {F : Set a → Set b} ⦃ _ : Applicative F ⦄ → List (F A) → F ⊤′
sequence [] = pure tt
sequence (x ∷ xs) = x *> sequence xs
open import Tactic.Nat public
open import Tactic.Deriving.Eq public
|
{
"alphanum_fraction": 0.5919589393,
"avg_line_length": 25.4130434783,
"ext": "agda",
"hexsha": "3e0ab62bc0962d12981f5f5e40e7ef3d1744eb6d",
"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/OscarPrelude.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/OscarPrelude.agda",
"max_line_length": 92,
"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/OscarPrelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 531,
"size": 1169
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Semi-heterogeneous vector equality over setoids
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.Vec.Relation.Binary.Equality.Setoid
{a ℓ} (S : Setoid a ℓ) where
open import Data.Nat.Base using (ℕ; zero; suc; _+_)
open import Data.Vec
open import Data.Vec.Relation.Binary.Pointwise.Inductive as PW
using (Pointwise)
open import Function
open import Level using (_⊔_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open Setoid S renaming (Carrier to A)
------------------------------------------------------------------------
-- Definition of equality
infix 4 _≋_
_≋_ : ∀ {m n} → REL (Vec A m) (Vec A n) (a ⊔ ℓ)
_≋_ = Pointwise _≈_
open Pointwise public using ([]; _∷_)
open PW public using (length-equal)
------------------------------------------------------------------------
-- Relational properties
≋-refl : ∀ {n} → Reflexive (_≋_ {n})
≋-refl = PW.refl refl
≋-sym : ∀ {n m} → Sym _≋_ (_≋_ {m} {n})
≋-sym = PW.sym sym
≋-trans : ∀ {n m o} → Trans (_≋_ {m}) (_≋_ {n} {o}) (_≋_)
≋-trans = PW.trans trans
≋-isEquivalence : ∀ n → IsEquivalence (_≋_ {n})
≋-isEquivalence = PW.isEquivalence isEquivalence
≋-setoid : ℕ → Setoid a (a ⊔ ℓ)
≋-setoid = PW.setoid S
------------------------------------------------------------------------
-- map
open PW public using ( map⁺)
------------------------------------------------------------------------
-- ++
open PW public using (++⁺ ; ++⁻ ; ++ˡ⁻; ++ʳ⁻)
++-identityˡ : ∀ {n} (xs : Vec A n) → [] ++ xs ≋ xs
++-identityˡ _ = ≋-refl
++-identityʳ : ∀ {n} (xs : Vec A n) → xs ++ [] ≋ xs
++-identityʳ [] = []
++-identityʳ (x ∷ xs) = refl ∷ ++-identityʳ xs
map-++-commute : ∀ {b m n} {B : Set b}
(f : B → A) (xs : Vec B m) {ys : Vec B n} →
map f (xs ++ ys) ≋ map f xs ++ map f ys
map-++-commute f [] = ≋-refl
map-++-commute f (x ∷ xs) = refl ∷ map-++-commute f xs
------------------------------------------------------------------------
-- concat
open PW public using (concat⁺; concat⁻)
------------------------------------------------------------------------
-- replicate
replicate-shiftʳ : ∀ {m} n x (xs : Vec A m) →
replicate {n = n} x ++ (x ∷ xs) ≋
replicate {n = 1 + n} x ++ xs
replicate-shiftʳ zero x xs = ≋-refl
replicate-shiftʳ (suc n) x xs = refl ∷ (replicate-shiftʳ n x xs)
|
{
"alphanum_fraction": 0.4499229584,
"avg_line_length": 28.8444444444,
"ext": "agda",
"hexsha": "5403745b902bf83f1e426b8022140e9fd604c67b",
"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/Vec/Relation/Binary/Equality/Setoid.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/Vec/Relation/Binary/Equality/Setoid.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/Data/Vec/Relation/Binary/Equality/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 770,
"size": 2596
}
|
module IIRD where
open import LF
-- A code for an IIRD (captures both general and restricted IIRDs)
-- I - index set
-- D - return type of the recursive component
-- E - generalised return type of the recursive component (including the index)
-- for restricted IIRD E = D i for an external i
-- and for general IIRD E = (i : I) × D i
-- The intuition is that restricted IIRD are parameterised over the index,
-- whereas general IIRD compute their indices.
data OP (I : Set)(D : I -> Set1)(E : Set1) : Set1 where
-- Nullary constructor, contains the result of the recursive component
ι : E -> OP I D E
-- Non-recursive argument A, following arguments may depend on this argument.
-- To code multi-constructor datatypes, the first argument is the name of the
-- constructor and γ does the appropriate case-split on the name.
σ : (A : Set)(γ : A -> OP I D E) -> OP I D E
-- Recursive argument
-- A - assumptions, for instance lim : (Nat -> Ord) -> Ord, where A = Nat
-- i - the index of the inductive occurrence
-- γ - the rest of the arguments, may depend on the result of calling the
-- recursive function on the inductive argument
δ : (A : Set)(i : A -> I)(γ : ((a : A) -> D (i a)) -> OP I D E) -> OP I D E
-- Helper function. The definition is simple, but the type is not.
_«_×_» : {A B : Set}{C : B -> Set}{D : B -> Set1}
(f : (b : B) -> C b -> D b)
(g : A -> B)(h : (a : A) -> C (g a)) ->
(a : A) -> D (g a)
f « g × h » = \a -> f (g a) (h a)
-- The type of constructor arguments. Parameterised over
-- U - the inductive type
-- T - the recursive function
-- This is the F of the simple polynomial type μF
Ku : {I : Set}{D : I -> Set1}{E : Set1} -> OP I D E ->
(U : I -> Set)(T : (i : I) -> U i -> D i) -> Set
Ku (ι e) U T = One
Ku (σ A γ) U T = A × \a -> Ku (γ a) U T
Ku (δ A i γ) U T = ((a : A) -> U (i a)) × \g -> Ku (γ (T « i × g »)) U T
-- The recursive function. As with Ku this is only the top-level structure.
-- To get the real function there is a recursive knot to be tied.
Kt : {I : Set}{D : I -> Set1}{E : Set1}
(γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) ->
Ku γ U T -> E
Kt (ι e) U T ★ = e
Kt (σ A γ) U T < a | b > = Kt (γ a) U T b
Kt (δ A i γ) U T < g | b > = Kt (γ (T « i × g »)) U T b
-- The assumptions of a particular inductive occurrence in a value.
KIArg : {I : Set}{D : I -> Set1}{E : Set1}
(γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) ->
Ku γ U T -> Set
KIArg (ι e) U T ★ = Zero
KIArg (σ A γ) U T < a | b > = KIArg (γ a) U T b
KIArg (δ A i γ) U T < g | b > = A + KIArg (γ (T « i × g »)) U T b
-- Given the assumptions of an inductive occurence in a value we can compute
-- its index.
KIArg→I : {I : Set}{D : I -> Set1}{E : Set1}
(γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) ->
(a : Ku γ U T) -> KIArg γ U T a -> I
KIArg→I (ι e) U T ★ ()
KIArg→I (σ A γ) U T < a | b > c = KIArg→I (γ a) U T b c
KIArg→I (δ A i γ) U T < g | b > (inl a) = i a
KIArg→I (δ A i γ) U T < g | b > (inr a) = KIArg→I (γ (T « i × g »)) U T b a
-- Given the assumptions of an inductive occurrence in a value we can compute
-- its value.
KIArg→U : {I : Set}{D : I -> Set1}{E : Set1}
(γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) ->
(a : Ku γ U T)(v : KIArg γ U T a) -> U (KIArg→I γ U T a v)
KIArg→U (ι e) U T ★ ()
KIArg→U (σ A γ) U T < a | b > c = KIArg→U (γ a) U T b c
KIArg→U (δ A i γ) U T < g | b > (inl a) = g a
KIArg→U (δ A i γ) U T < g | b > (inr a) = KIArg→U (γ (T « i × g »)) U T b a
-- The type of induction hypotheses. Basically
-- forall assumptions, the predicate holds for an inductive occurrence with
-- those assumptions
KIH : {I : Set}{D : I -> Set1}{E : Set1}
(γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) ->
(F : (i : I) -> U i -> Set1)(a : Ku γ U T) -> Set1
KIH γ U T F a = (v : KIArg γ U T a) -> F (KIArg→I γ U T a v) (KIArg→U γ U T a v)
-- If we can prove a predicate F for any values, we can construct the inductive
-- hypotheses for a given value.
-- Termination note: g will only be applied to values smaller than a
Kmap : {I : Set}{D : I -> Set1}{E : Set1}
(γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) ->
(F : (i : I) -> U i -> Set1)
(g : (i : I)(u : U i) -> F i u)
(a : Ku γ U T) -> KIH γ U T F a
Kmap γ U T F g a = \v -> g (KIArg→I γ U T a v) (KIArg→U γ U T a v)
-- Things needed for general IIRD
OPg : (I : Set)(D : I -> Set1) -> Set1
OPg I D = OP I D (I ×' D)
Gu : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) -> Set
Gu γ U T = Ku γ U T
Gi : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i)
(a : Gu γ U T) -> I
Gi γ U T a = π₀' (Kt γ U T a)
Gt : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i)
(a : Gu γ U T) -> D (Gi γ U T a)
Gt γ U T a = π₁' (Kt γ U T a)
-- Things needed for restricted IIRD
OPr : (I : Set)(D : I -> Set1) -> Set1
OPr I D = (i : I) -> OP I D (D i)
Hu : {I : Set}{D : I -> Set1}
(γ : OPr I D)(U : I -> Set)(T : (i : I) -> U i -> D i)
(i : I) -> Set
Hu γ U T i = Ku (γ i) U T
Ht : {I : Set}{D : I -> Set1}
(γ : OPr I D)(U : I -> Set)(T : (i : I) -> U i -> D i)
(i : I)(a : Hu γ U T i) -> D i
Ht γ U T i a = Kt (γ i) U T a
|
{
"alphanum_fraction": 0.5059974165,
"avg_line_length": 40.4402985075,
"ext": "agda",
"hexsha": "59b2b1141b2fd7eae19feadaa5a058eb0463b101",
"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": "examples/outdated-and-incorrect/iird/IIRD.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": "examples/outdated-and-incorrect/iird/IIRD.agda",
"max_line_length": 90,
"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": "examples/outdated-and-incorrect/iird/IIRD.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": 2129,
"size": 5419
}
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Conversion {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.RedSteps
open import Definition.Typed.Properties
import Definition.Typed.Weakening as Wk
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Conversion of syntactic reduction closures.
convRed:*: : ∀ {t u A B Γ} → Γ ⊢ t :⇒*: u ∷ A → Γ ⊢ A ≡ B → Γ ⊢ t :⇒*: u ∷ B
convRed:*: [ ⊢t , ⊢u , d ] A≡B = [ conv ⊢t A≡B , conv ⊢u A≡B , conv* d A≡B ]
mutual
-- Helper function for conversion of terms converting from left to right.
convTermT₁ : ∀ {l l′ Γ A B t} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
convTermT₁ (ℕᵥ D D′) A≡B t = t
convTermT₁ (Emptyᵥ D D′) A≡B t = t
convTermT₁ (Unitᵥ D D′) A≡B t = t
convTermT₁ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ k d (neNfₜ neK₂ ⊢k k≡k)) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in neₜ k (convRed:*: d K≡K₁)
(neNfₜ neK₂ (conv ⊢k K≡K₁) (~-conv k≡k K≡K₁))
convTermT₁ {Γ = Γ} (Bᵥ BΠ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ f d funcF f≡f [f] [f]₁) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity BΠ ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x) (PE.sym ΠF₁G₁≡ΠF′G′)
(≅-eq A≡B)
in Πₜ f (convRed:*: d ΠFG≡ΠF₁G₁) funcF (≅-conv f≡f ΠFG≡ΠF₁G₁)
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[b]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [b]
[a≡b]₁ = convEqTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a≡b]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convEqTerm₁ ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a]) [G≡G₁]
([f] [ρ] ⊢Δ [a]₁ [b]₁ [a≡b]₁))
(λ {ρ} [ρ] ⊢Δ [a] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convTerm₁ ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a]) [G≡G₁] ([f]₁ [ρ] ⊢Δ [a]₁))
convTermT₁ {l} {l′} {Γ} (Bᵥ BΣ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Σₜ f d pProd f≡f [fst] [snd]) =
let ΣF₁G₁≡ΣF′G′ = whrDet* (red D₁ , Σₙ) (D′ , Σₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity BΣ ΣF₁G₁≡ΣF′G′
ΣFG≡ΣF₁G₁ = PE.subst (λ x → Γ ⊢ Σ F ▹ G ≡ x) (PE.sym ΣF₁G₁≡ΣF′G′)
(≅-eq A≡B)
⊢Γ = wf ⊢F
F≡F₁ = PE.subst (λ x → Γ ⊩⟨ l ⟩ wk id F ≡ wk id x / [F] Wk.id ⊢Γ)
(PE.sym F₁≡F′)
([F≡F′] Wk.id ⊢Γ)
[fst]₁ = convTerm₁ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id (wf ⊢F₁)) F≡F₁ [fst]
G≡G₁ = PE.subst (λ x → Γ ⊩⟨ l ⟩ wk (lift id) G [ fst f ] ≡ wk (lift id) x [ fst f ] / [G] Wk.id ⊢Γ [fst])
(PE.sym G₁≡G′)
([G≡G′] Wk.id ⊢Γ [fst])
[snd]₁ = convTerm₁ ([G] Wk.id ⊢Γ [fst]) ([G]₁ Wk.id (wf ⊢F₁) [fst]₁) G≡G₁ [snd]
in Σₜ f (convRed:*: d ΣFG≡ΣF₁G₁) pProd (≅-conv f≡f ΣFG≡ΣF₁G₁)
[fst]₁ [snd]₁
convTermT₁ (Uᵥ (Uᵣ .⁰ 0<1 ⊢Γ) (Uᵣ .⁰ 0<1 ⊢Γ₁)) A≡B t = t
convTermT₁ (emb⁰¹ x) A≡B t = convTermT₁ x A≡B t
convTermT₁ (emb¹⁰ x) A≡B t = convTermT₁ x A≡B t
-- Helper function for conversion of terms converting from right to left.
convTermT₂ : ∀ {l l′ Γ A B t} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
convTermT₂ (ℕᵥ D D′) A≡B t = t
convTermT₂ (Emptyᵥ D D′) A≡B t = t
convTermT₂ (Unitᵥ D D′) A≡B t = t
convTermT₂ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ k d (neNfₜ neK₂ ⊢k k≡k)) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in neₜ k (convRed:*: d K₁≡K)
(neNfₜ neK₂ (conv ⊢k K₁≡K) (~-conv k≡k K₁≡K))
convTermT₂ {Γ = Γ} (Bᵥ BΠ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ f d funcF f≡f [f] [f]₁) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity BΠ ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x)
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ f (convRed:*: d (sym ΠFG≡ΠF₁G₁)) funcF (≅-conv f≡f (sym ΠFG≡ΠF₁G₁))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[b]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [b]
[a≡b]₁ = convEqTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a≡b]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convEqTerm₂ ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([f] [ρ] ⊢Δ [a]₁ [b]₁ [a≡b]₁))
(λ {ρ} [ρ] ⊢Δ [a] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convTerm₂ ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([f]₁ [ρ] ⊢Δ [a]₁))
convTermT₂ {l} {l′} {Γ = Γ} (Bᵥ BΣ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Σₜ f d pProd f≡f [fst]₁ [snd]₁) =
let ΣF₁G₁≡ΣF′G′ = whrDet* (red D₁ , Σₙ) (D′ , Σₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity BΣ ΣF₁G₁≡ΣF′G′
ΣFG≡ΣF₁G₁ = PE.subst (λ x → Γ ⊢ Σ F ▹ G ≡ x)
(PE.sym ΣF₁G₁≡ΣF′G′) (≅-eq A≡B)
⊢Γ = wf ⊢F
⊢Γ₁ = wf ⊢F₁
F≡F₁ = PE.subst (λ x → Γ ⊩⟨ l ⟩ wk id F ≡ wk id x / [F] Wk.id ⊢Γ)
(PE.sym F₁≡F′)
([F≡F′] Wk.id ⊢Γ)
[fst] = (convTerm₂ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fst]₁)
G≡G₁ = PE.subst (λ x → Γ ⊩⟨ l ⟩ wk (lift id) G [ fst f ] ≡ wk (lift id) x [ fst f ] / [G] Wk.id ⊢Γ [fst])
(PE.sym G₁≡G′)
([G≡G′] Wk.id ⊢Γ [fst])
[snd] = (convTerm₂ ([G] Wk.id ⊢Γ [fst]) ([G]₁ Wk.id ⊢Γ₁ [fst]₁) G≡G₁ [snd]₁)
in Σₜ f (convRed:*: d (sym ΣFG≡ΣF₁G₁)) pProd (≅-conv f≡f (sym ΣFG≡ΣF₁G₁))
[fst] [snd]
convTermT₂ (Uᵥ (Uᵣ .⁰ 0<1 ⊢Γ) (Uᵣ .⁰ 0<1 ⊢Γ₁)) A≡B t = t
convTermT₂ (emb⁰¹ x) A≡B t = convTermT₂ x A≡B t
convTermT₂ (emb¹⁰ x) A≡B t = convTermT₂ x A≡B t
-- Conversion of terms converting from left to right.
convTerm₁ : ∀ {Γ A B t l l′} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
convTerm₁ [A] [B] A≡B t = convTermT₁ (goodCases [A] [B] A≡B) A≡B t
-- Conversion of terms converting from right to left.
convTerm₂ : ∀ {Γ A B t l l′} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
-- NOTE: this would be easier to define by mutual induction with symEq (which needs conversion),
-- rather than by defining everything from scratch for both left-to-right and right-to-left,
-- but with the mutual definition termination checking fails in Agda.
convTerm₂ [A] [B] A≡B t = convTermT₂ (goodCases [A] [B] A≡B) A≡B t
-- Conversion of terms converting from right to left
-- with some propositionally equal types.
convTerm₂′ : ∀ {Γ A B B′ t l l′} → B PE.≡ B′
→ ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B′ / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
convTerm₂′ PE.refl [A] [B] A≡B t = convTerm₂ [A] [B] A≡B t
-- Helper function for conversion of term equality converting from left to right.
convEqTermT₁ : ∀ {l l′ Γ A B t u} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
convEqTermT₁ (ℕᵥ D D′) A≡B t≡u = t≡u
convEqTermT₁ (Emptyᵥ D D′) A≡B t≡u = t≡u
convEqTermT₁ (Unitᵥ D D′) A≡B t≡u = t≡u
convEqTermT₁ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ₌ k m d d′ (neNfₜ₌ neK₂ neM₁ k≡m)) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in neₜ₌ k m (convRed:*: d K≡K₁)
(convRed:*: d′ K≡K₁)
(neNfₜ₌ neK₂ neM₁ (~-conv k≡m K≡K₁))
convEqTermT₁ {Γ = Γ} (Bᵥ BΠ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ₌ f g d d′ funcF funcG t≡u [t] [u] [t≡u]) =
let [A] = Bᵣ′ BΠ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Bᵣ′ BΠ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x)
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ₌ f g (convRed:*: d ΠFG≡ΠF₁G₁) (convRed:*: d′ ΠFG≡ΠF₁G₁)
funcF funcG (≅-conv t≡u ΠFG≡ΠF₁G₁)
(convTerm₁ [A] [B] [A≡B] [t]) (convTerm₁ [A] [B] [A≡B] [u])
(λ {ρ} [ρ] ⊢Δ [a] →
let F₁≡F′ , G₁≡G′ = B-PE-injectivity BΠ (whrDet* (red D₁ , Πₙ) (D′ , Πₙ))
[F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convEqTerm₁ ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a])
[G≡G₁] ([t≡u] [ρ] ⊢Δ [a]₁))
convEqTermT₁ {Γ = Γ} (Bᵥ BΣ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Σₜ₌ p r d d′ pProd rProd p≅r [t] [u] [fstp] [fstr] [fst≡] [snd≡]) =
let [A] = Bᵣ′ BΣ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Bᵣ′ BΣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΣF₁G₁≡ΣF′G′ = whrDet* (red D₁ , Σₙ) (D′ , Σₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity BΣ ΣF₁G₁≡ΣF′G′
ΣFG≡ΣF₁G₁ = PE.subst (λ x → Γ ⊢ Σ F ▹ G ≡ x)
(PE.sym ΣF₁G₁≡ΣF′G′) (≅-eq A≡B)
⊢Γ = wf ⊢F
⊢Γ₁ = wf ⊢F₁
F≡F₁ = PE.subst (λ x → Γ ⊩⟨ _ ⟩ wk id F ≡ wk id x / [F] Wk.id ⊢Γ)
(PE.sym F₁≡F′)
([F≡F′] Wk.id ⊢Γ)
[fstp]₁ = convTerm₁ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fstp]
[fstr]₁ = convTerm₁ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fstr]
[fst≡]₁ = convEqTerm₁ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fst≡]
G≡G₁ = PE.subst (λ x → Γ ⊩⟨ _ ⟩ wk (lift id) G [ fst p ] ≡ wk (lift id) x [ fst p ] / [G] Wk.id ⊢Γ [fstp])
(PE.sym G₁≡G′)
([G≡G′] Wk.id ⊢Γ [fstp])
[snd≡]₁ = convEqTerm₁ ([G] Wk.id ⊢Γ [fstp]) ([G]₁ Wk.id ⊢Γ₁ [fstp]₁) G≡G₁ [snd≡]
in Σₜ₌ p r (convRed:*: d ΣFG≡ΣF₁G₁) (convRed:*: d′ ΣFG≡ΣF₁G₁)
pProd rProd (≅-conv p≅r ΣFG≡ΣF₁G₁)
(convTerm₁ [A] [B] [A≡B] [t]) (convTerm₁ [A] [B] [A≡B] [u])
[fstp]₁ [fstr]₁ [fst≡]₁ [snd≡]₁
convEqTermT₁ (Uᵥ (Uᵣ .⁰ 0<1 ⊢Γ) (Uᵣ .⁰ 0<1 ⊢Γ₁)) A≡B t≡u = t≡u
convEqTermT₁ (emb⁰¹ x) A≡B t≡u = convEqTermT₁ x A≡B t≡u
convEqTermT₁ (emb¹⁰ x) A≡B t≡u = convEqTermT₁ x A≡B t≡u
-- Helper function for conversion of term equality converting from right to left.
convEqTermT₂ : ∀ {l l′ Γ A B t u} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
convEqTermT₂ (ℕᵥ D D′) A≡B t≡u = t≡u
convEqTermT₂ (Emptyᵥ D D′) A≡B t≡u = t≡u
convEqTermT₂ (Unitᵥ D D′) A≡B t≡u = t≡u
convEqTermT₂ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ₌ k m d d′ (neNfₜ₌ neK₂ neM₁ k≡m)) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in neₜ₌ k m (convRed:*: d K₁≡K) (convRed:*: d′ K₁≡K)
(neNfₜ₌ neK₂ neM₁ (~-conv k≡m K₁≡K))
convEqTermT₂ {Γ = Γ} (Bᵥ BΠ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ₌ f g d d′ funcF funcG t≡u [t] [u] [t≡u]) =
let [A] = Bᵣ′ BΠ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Bᵣ′ BΠ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x)
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ₌ f g (convRed:*: d (sym ΠFG≡ΠF₁G₁)) (convRed:*: d′ (sym ΠFG≡ΠF₁G₁))
funcF funcG (≅-conv t≡u (sym ΠFG≡ΠF₁G₁))
(convTerm₂ [A] [B] [A≡B] [t]) (convTerm₂ [A] [B] [A≡B] [u])
(λ {ρ} [ρ] ⊢Δ [a] →
let F₁≡F′ , G₁≡G′ = B-PE-injectivity BΠ (whrDet* (red D₁ , Πₙ) (D′ , Πₙ))
[F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convEqTerm₂ ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([t≡u] [ρ] ⊢Δ [a]₁))
convEqTermT₂ {Γ = Γ} (Bᵥ BΣ (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Σₜ₌ p r d d′ funcF funcG t≡u [t] [u] [fstp]₁ [fstr]₁ [fst≡]₁ [snd≡]₁) =
let [A] = Bᵣ′ BΣ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Bᵣ′ BΣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΣF₁G₁≡ΣF′G′ = whrDet* (red D₁ , Σₙ) (D′ , Σₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity BΣ ΣF₁G₁≡ΣF′G′
ΣFG≡ΣF₁G₁ = PE.subst (λ x → Γ ⊢ Σ F ▹ G ≡ x)
(PE.sym ΣF₁G₁≡ΣF′G′) (≅-eq A≡B)
⊢Γ = wf ⊢F
⊢Γ₁ = wf ⊢F₁
F≡F₁ = PE.subst (λ x → Γ ⊩⟨ _ ⟩ wk id F ≡ wk id x / [F] Wk.id ⊢Γ)
(PE.sym F₁≡F′)
([F≡F′] Wk.id ⊢Γ)
[fstp] = convTerm₂ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fstp]₁
[fstr] = convTerm₂ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fstr]₁
[fst≡] = convEqTerm₂ ([F] Wk.id ⊢Γ) ([F]₁ Wk.id ⊢Γ₁) F≡F₁ [fst≡]₁
G≡G₁ = PE.subst (λ x → Γ ⊩⟨ _ ⟩ wk (lift id) G [ fst p ] ≡ wk (lift id) x [ fst p ] / [G] Wk.id ⊢Γ [fstp])
(PE.sym G₁≡G′)
([G≡G′] Wk.id ⊢Γ [fstp])
[snd≡] = convEqTerm₂ ([G] Wk.id ⊢Γ [fstp]) ([G]₁ Wk.id ⊢Γ₁ [fstp]₁) G≡G₁ [snd≡]₁
in Σₜ₌ p r (convRed:*: d (sym ΣFG≡ΣF₁G₁)) (convRed:*: d′ (sym ΣFG≡ΣF₁G₁))
funcF funcG (≅-conv t≡u (sym ΣFG≡ΣF₁G₁))
(convTerm₂ [A] [B] [A≡B] [t]) (convTerm₂ [A] [B] [A≡B] [u])
[fstp] [fstr] [fst≡] [snd≡]
convEqTermT₂ (Uᵥ (Uᵣ .⁰ 0<1 ⊢Γ) (Uᵣ .⁰ 0<1 ⊢Γ₁)) A≡B t≡u = t≡u
convEqTermT₂ (emb⁰¹ x) A≡B t≡u = convEqTermT₂ x A≡B t≡u
convEqTermT₂ (emb¹⁰ x) A≡B t≡u = convEqTermT₂ x A≡B t≡u
-- Conversion of term equality converting from left to right.
convEqTerm₁ : ∀ {l l′ Γ A B t u} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
convEqTerm₁ [A] [B] A≡B t≡u = convEqTermT₁ (goodCases [A] [B] A≡B) A≡B t≡u
-- Conversion of term equality converting from right to left.
convEqTerm₂ : ∀ {l l′ Γ A B t u} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
convEqTerm₂ [A] [B] A≡B t≡u = convEqTermT₂ (goodCases [A] [B] A≡B) A≡B t≡u
|
{
"alphanum_fraction": 0.3967094197,
"avg_line_length": 54.5100286533,
"ext": "agda",
"hexsha": "0029c838e1119f6bdf918d22f4c8340cd300b13e",
"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": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"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": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_line_length": 114,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9787,
"size": 19024
}
|
module Negative4 where
data Empty : Set where
data NSPos : Set where
c : ((NSPos -> Empty) -> NSPos) -> NSPos
|
{
"alphanum_fraction": 0.6355932203,
"avg_line_length": 11.8,
"ext": "agda",
"hexsha": "0cbf4aa364f4176eb274650e4f59c6c3a242c672",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Negative4.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/Negative4.agda",
"max_line_length": 43,
"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/Negative4.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": 35,
"size": 118
}
|
module Implicits.Syntax.Type.Constructors where
open import Prelude
open import Implicits.Syntax.Type
open import Implicits.Substitutions
open TypeSubst
-- polymorphic identity
tid : ∀ {n} → Type n
tid = ∀' (simpl ((TVar zero) →' (TVar zero)))
-- type of bools encoding
tbool : Type 0
tbool = ∀' (simpl ((TVar zero) →' (simpl ((TVar zero) →' (TVar zero)))))
-- church numerals
tnat : Type 0
tnat = ∀' (simpl ((simpl ((TVar zero) →' (TVar zero))) →' (simpl ((TVar zero) →' (TVar zero)))))
-- existential quantification
∃' : ∀ {n} → (Type (suc n)) → Type n
∃' a = ∀' (∀' (simpl ((a tp/tp (wk ↑)) →' (simpl ((TVar (suc zero)) →' (TVar zero))))))
-- unit type
⊤' : ∀ {n} → Type n
⊤' = tid
-- zero type
⊥' : ∀ {n} → Type n
⊥' = ∀' (TVar zero)
-- n-ary function type
infixr 7 _→ⁿ_
_→ⁿ_ : ∀ {n k} → Vec (Type n) k → Type n → Type n
[] →ⁿ z = z
(a ∷ as) →ⁿ z = as →ⁿ (simpl (a →' z))
-- Record/finite tuple
rec : ∀ {n k} → Vec (Type n) k → Type n
rec [] = ⊤'
rec (a ∷ as) = ∀' (simpl ((map tp-weaken (a ∷ as) →ⁿ TVar zero) →' TVar zero))
-- tuple
_×'_ : ∀ {n} → Type n → Type n → Type n
a ×' b = rec (a ∷ b ∷ [])
|
{
"alphanum_fraction": 0.5510204082,
"avg_line_length": 24.5,
"ext": "agda",
"hexsha": "aa7b2b89d99c518b1018accf58dc588639a50141",
"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/Implicits/Syntax/Type/Constructors.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/Implicits/Syntax/Type/Constructors.agda",
"max_line_length": 96,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Syntax/Type/Constructors.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 465,
"size": 1127
}
|
{-# OPTIONS --without-K --rewriting #-}
module Flat where
open import lib.Basics
open import Basics
open import Bool
open import lib.types.Bool
open import lib.NType2
open import lib.Equivalence2
open import lib.types.Suspension
open import lib.types.IteratedSuspension
open import lib.types.Pushout as Pushout
open import lib.types.Truncation
-- The type of points of A, ♭ A, is inductively generated by the crisp elements of A
data ♭ {@♭ l : ULevel} (@♭ A : Type l) : Type l where
_^♭ : A ::→ ♭ A
-- The deduced mapping principle of ♭ A: it represents crisp functions.
♭-elim : {c : ULevel} {@♭ l : ULevel}{@♭ A : Type l}
→ (C : ♭ A → Type c)
→ ((@♭ u : A) → C (u ^♭))
→ (x : ♭ A) → C x
♭-elim C f (x ^♭) = f x
syntax ♭-elim C (λ u → t) a = let♭ u ^♭:= a in♭ t in-family C
{- Mike's "let" notation (following Felix) -}
-- An implicit version of ♭-elim
let♭ : {@♭ i j : ULevel} {@♭ A : Type i} {B : ♭ A → Type j}
(a : ♭ A) (f : (@♭ u : A) → B (u ^♭))
→ B a
let♭ (u ^♭) f = f u
syntax let♭ a (λ u → t) = let♭ u ^♭:= a in♭ t
♭-rec : {@♭ i : ULevel} {j : ULevel} {@♭ A : Type i} {B : Type j}
→ (A ::→ B) → (♭ A) → B
♭-rec f (a ^♭) = f a
♭-rec-eq : {@♭ i : ULevel} {j : ULevel} {@♭ A : Type i} {B : Type j}
→ (A ::→ B) ≃ (♭ A → B)
♭-rec-eq {A = A} {B = B} =
equiv ♭-rec
(λ f → λ (@♭ a : A) → f (a ^♭)) -- fro
(λ f → λ= (λ { (a ^♭) → refl })) -- to-fro
(λ f → refl) -- fro-to
-- Crisp function types, but from A : ♭ Type
_♭:→_ : {@♭ i : ULevel} {j : ULevel} (A : ♭ (Type i)) (B : Type j) → Type (lmax i j)
(A ^♭) ♭:→ B = A ::→ B
-- The inclusion of the points of A into A
_↓♭ : {@♭ i : ULevel} {@♭ A : Type i} → (♭ A → A)
_↓♭ (x ^♭) = x
-- The (judgemental) computation rule for mapping out of points
♭-β : {@♭ i : ULevel} {@♭ A : Type i} (@♭ a : ♭ A)
→ ((a ↓♭) ^♭) == a
♭-β (a ^♭) = refl
-- Application of crisp functions to crisp equalities
-- Used mostly to apply _^♭.
♭-ap : {@♭ i j : ULevel} {@♭ A : Type i} {B : Type j}
(f : (@♭ a : A) → B) {@♭ x y : A} (@♭ p : x == y)
→ (f x) == (f y)
♭-ap f refl = refl
-- ♭ is a functor
♭→ : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}
→ (@♭ f : A → B) → (♭ A → ♭ B)
♭→ f (x ^♭) = (f x) ^♭
-- The naturality square of the inclusion of points (judgemental!)
♭→-nat : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} (@♭ f : A → B)
→ (a : ♭ A) → (f ∘ _↓♭) a == (_↓♭ ∘ (♭→ f)) a
♭→-nat f (a ^♭) = refl
-- Proof of functoriality
♭→∘ : {@♭ i j k : ULevel} {@♭ A : Type i} {@♭ B : Type j} {@♭ C : Type k}
{@♭ f : A → B} {@♭ g : B → C}
→ ♭→ (g ∘ f) == (♭→ g) ∘ (♭→ f)
♭→∘ {f = f} {g = g} =
λ= (λ a → -- We test on elements, but
let♭ u ^♭:= a in♭ -- might as well assume those elements are crisp
refl -- where it follows by definition.
in-family (λ a → (♭→ (g ∘ f)) a == ((♭→ g) ∘ (♭→ f)) a) )
-- ♭→ preserves crisp equivalences
♭→e : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}
→ (@♭ e : A ≃ B) → (♭ A) ≃ (♭ B)
♭→e e =
equiv (♭→ (–> e))
(♭→ (<– e))
(λ { (a ^♭) → ♭-ap _^♭ (<–-inv-r e a) })
(λ { (a ^♭) → ♭-ap _^♭ (<–-inv-l e a) })
-- A type is discrete if the inclusion of its point is an equivalence.
_is-discrete : {@♭ l : ULevel} → (@♭ A : Type l) → Type l
_is-discrete {l} A = is-equiv {l} {l} {♭ A} {A} _↓♭
-- The equivalence between the points of a discrete type and itself
discrete-eq : {@♭ l : ULevel} {@♭ A : Type l} → A is-discrete → (♭ A) ≃ A
discrete-eq = _↓♭ ,_
_is-discrete-is-a-prop : {@♭ l : ULevel} (@♭ A : Type l) → (A is-discrete) is-a-prop
A is-discrete-is-a-prop = is-equiv-is-prop
is-discrete-prop : {@♭ l : ULevel} → SubtypeProp (♭ (Type l)) l
is-discrete-prop = (λ { (A ^♭) → A is-discrete }) , (λ { (A ^♭) → A is-discrete-is-a-prop })
-- The subtype of discrete types
Discrete : (@♭ l : ULevel) → Type (lsucc l)
Discrete l = Subtype is-discrete-prop
Discrete-_-Type_ : (@♭ n : ℕ₋₂) (@♭ i : ULevel) → Type (lsucc i)
Discrete- n -Type i = Subtype prop
where prop : SubtypeProp (♭ (n -Type i)) i
prop = (λ { (A ^♭) → (fst A) is-discrete }) , (λ { (A ^♭) → (fst A) is-discrete-is-a-prop })
DiscSet : (@♭ i : ULevel) → Type (lsucc i)
DiscSet i = Discrete- ⟨ S (S O) ⟩₋₂ -Type i
DiscSet₀ = DiscSet lzero
∈Disc : {@♭ i : ULevel} (A : DiscSet i) → Type i
∈Disc A = ((♭→ ∈) (fst A)) ↓♭
DiscSet-to-Set : {@♭ i : ULevel} → DiscSet i → hSet i
DiscSet-to-Set A = (fst A) ↓♭
-- DiscSet_is-discrete : {@♭ i : ULevel} → (@♭ A : DiscSet i) → (∈Disc A) is-discrete
-- DiscSet A is-discrete = {!(snd A)!}
-- Just in case, we apply univalence to the discrete-eq
discrete-id : {@♭ l : ULevel} {@♭ A : Type l} → A is-discrete → (♭ A) == A
discrete-id p = ua (discrete-eq p)
-- Obviously, the points of a type are discrete
♭-is-discrete : {@♭ l : ULevel} {@♭ A : Type l} → (♭ A) is-discrete
♭-is-discrete {_} {A} =
_↓♭ is-an-equivalence-because
fro is-inverse-by
to-fro
and
fro-to
where
fro : ♭ A → ♭ (♭ A)
fro (a ^♭) = (a ^♭) ^♭
to-fro : (a : ♭ A) → ((fro a) ↓♭) == a
to-fro (a ^♭) = refl
fro-to : (a : ♭ (♭ A)) → fro (a ↓♭) == a
fro-to ((a ^♭) ^♭) = refl
-- To prove the ♭i is an equivalence, it suffices to give a section of it.
_is-discrete-because_is-section-by_ : {@♭ l : ULevel} (@♭ A : Type l)
(@♭ s : A → ♭ A) (@♭ p : (a : A) → ((s a) ↓♭)== a)
→ A is-discrete
A is-discrete-because s is-section-by p =
_↓♭ is-an-equivalence-because s is-inverse-by p and
(λ { (a ^♭) → ! (♭-β (s a)) ∙ (♭-ap _^♭ (p a))})
-- ♭ commutes with identity types in the following sense
module _ {@♭ i : ULevel} {@♭ A : Type i} where
♭-identity-eq : (@♭ x y : A) → ♭ (x == y) ≃ ((x ^♭) == (y ^♭))
♭-identity-eq _ _ = equiv to fro to-fro fro-to
where
to : {@♭ x y : A} → ♭ (x == y) → ((x ^♭) == (y ^♭))
to (refl ^♭) = refl
fro : {@♭ x y : A} → ((x ^♭) == (y ^♭)) → ♭ (x == y)
fro refl = refl ^♭
to-fro : {@♭ x y : A} → (p : (x ^♭) == (y ^♭)) → (to (fro p) == p)
to-fro refl = refl
fro-to : {@♭ x y : A} → (p : ♭ (x == y)) → fro (to p) == p
fro-to (refl ^♭) = refl
{- From Tslil:
There once was a Bear in a Zoo
Who didn't know quite what to do
It bored him so
To walk to and fro
So he flipped it and walked fro and to
-}
-- ♭ preserves crisp level.
♭-preserves-level : {@♭ i : ULevel} {@♭ A : Type i}
{@♭ n : ℕ₋₂} (@♭ p : has-level n A)
→ has-level n (♭ A)
♭-preserves-level {_}{A}{⟨-2⟩} p =
has-level-in ((a ^♭) ,
(λ {(y ^♭) → (–> (♭-identity-eq a y)) ((contr-path p y )^♭)}))
where -- If A contracts onto a, then ♭ A contracts onto a ^♭
a = contr-center p
♭-preserves-level {_}{A}{S n} p =
has-level-in (λ {(x ^♭) (y ^♭) →
equiv-preserves-level
(♭-identity-eq x y)
{{♭-preserves-level {_}{(x == y)}{n} (has-level-apply p x y)}}})
{-
Because the equality types of ♭ A are themselves ♭ (x == y) for x y : A,
and because we know that x == y has level n if A has level (S n), we can recurse
to show that ♭ (x == y) has level n and therefore ♭ A has level (S n).
-}
-- A version of ♭ that acts on n-types.
♭ₙ : {@♭ i : ULevel} {@♭ n : ℕ₋₂}
→ (@♭ A : n -Type i) → (n -Type i)
♭ₙ A = (♭ (fst A)) , ♭-preserves-level (snd A)
♭-Trunc-map : {@♭ i : ULevel} {@♭ n : ℕ₋₂} (@♭ X : Type i)
→ (Trunc n (♭ X)) → ♭ (Trunc n X)
♭-Trunc-map X =
Trunc-elim {{p = ♭-preserves-level Trunc-level}}
(λ { (a ^♭) → [ a ] ^♭ })
-- Until ♯ works we have to postulate this.
♭-Trunc-eq : {@♭ i : ULevel} {@♭ n : ℕ₋₂} (@♭ X : Type i)
→ (Trunc n (♭ X)) ≃ ♭ (Trunc n X)
♭-Trunc-eq X = (♭-Trunc-map X) , unproven
where
postulate unproven : (♭-Trunc-map X) is-an-equiv
⊤-is-discrete : ⊤ is-discrete
⊤-is-discrete = _↓♭ is-an-equivalence-because
(λ {unit → unit ^♭}) is-inverse-by
(λ {unit → refl})
and
(λ {(unit ^♭) → refl})
-- ♭ commutes with coproducts.
♭-commutes-with-⊔ : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}
→ ♭ (A ⊔ B) ≃ (♭ A) ⊔ (♭ B)
♭-commutes-with-⊔ = to ,
(to is-an-equivalence-because
fro is-inverse-by
(λ { (inl (a ^♭)) → refl ;
(inr (b ^♭)) → refl })
and
(λ { ((inl a) ^♭) → refl ;
((inr b) ^♭) → refl }))
where
to : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}
→ ♭ (A ⊔ B) → (♭ A) ⊔ (♭ B)
to ((inl a) ^♭) = inl (a ^♭)
to ((inr b) ^♭) = inr (b ^♭)
fro : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}
→ (♭ A) ⊔ (♭ B) → ♭ (A ⊔ B)
fro (inl (a ^♭)) = (inl a) ^♭
fro (inr (b ^♭)) = (inr b) ^♭
-- ♭ commutes with Σ types for crisp families.
module _ {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : A → Type j} where
♭-commutes-with-Σ : ♭ (Σ A B) ≃ Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u))
♭-commutes-with-Σ = equiv to fro ((λ { ((a ^♭) , (b ^♭)) → refl })) ((λ { ((a , b) ^♭) → refl }))
where
to : ♭ (Σ A B) → Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u))
to ((a , b) ^♭) = ((a ^♭) , (b ^♭))
fro : Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u)) → ♭ (Σ A B)
fro ((a ^♭) , (b ^♭)) = (a , b) ^♭
ℕ-is-discrete : ℕ is-discrete
ℕ-is-discrete =
ℕ is-discrete-because fro is-section-by to-fro
where
fro : ℕ → ♭ ℕ
fro O = O ^♭
fro (S n) = (♭→ S) (fro n)
to-fro : (n : ℕ) → ((fro n) ↓♭) == n
to-fro O = refl
to-fro (S n) = (fro (S n)) ↓♭
=⟨ ! ((♭→-nat S) (fro n)) ⟩
(S ∘ _↓♭) (fro n)
=⟨ ap S (to-fro n) ⟩
S n
=∎
{-
When proving this equality by induction on n, the case of 0 presents no problem,
but when we work with (S n), we have to deal with the fact that n is not crisp.
However, as a constructor (and therefore defined in the empty context), S is crisp.
Therefore, we can use the naturality sqaure of ♭ to commute it past fro, and then recurse.
-}
-- We copy the proof for ULevel (or would but we can't pattern match on lsucc?)
{-
ULevel-is-discrete : ULevel is-discrete
ULevel-is-discrete =
ULevel is-discrete-because fro is-section-by to-fro
where
fro : ULevel → ♭ ULevel
fro lzero = lzero ^♭
fro (lsucc n) = (♭→ lsucc) (fro n)
to-fro : (n : ULevel) → ♭i (fro n) == n
to-fro lzero = refl
to-fro (lsucc n) = ♭i (fro (lsucc n))
=⟨ ! ((♭→-nat lsucc) (fro n)) ⟩
(lsucc ∘ ♭i) (fro n)
=⟨ ap lsucc (to-fro n) ⟩
lsucc n
=∎ -}
Bool-is-discrete : Bool is-discrete
Bool-is-discrete = Bool is-discrete-because fro is-section-by to-fro
where
fro : Bool → ♭ Bool
fro true = true ^♭
fro false = false ^♭
to-fro : (b : Bool) → ((fro b) ↓♭)== b
to-fro true = refl
to-fro false = refl
Bool-to-♭PropT₀ : Bool → ♭ PropT₀
Bool-to-♭PropT₀ true = True ^♭
Bool-to-♭PropT₀ false = False ^♭
Bool-to-♭PropT₀∘↓♭=♭→Bool-to-PropT₀ : Bool-to-♭PropT₀ ∘ _↓♭ == (♭→ Bool-to-PropT₀)
Bool-to-♭PropT₀∘↓♭=♭→Bool-to-PropT₀ = λ= (λ { (true ^♭) → refl ; (false ^♭) → refl })
{-
_-Sphere-is-discrete : (@♭ n : ℕ) → (Sphere n) is-discrete
n -Sphere-is-discrete = (Sphere n) is-discrete-because
(fro n) is-section-by {!!}
where
♭-north : {@♭ n : ℕ} → ♭ (Sphere n)
♭-north {O} = true ^♭
♭-north {S n} = {!north!}
♭-south : {@♭ n : ℕ} → ♭ (Sphere n)
♭-south = {!!}
fro : (@♭ n : ℕ) → (Sphere n) → ♭ (Sphere n)
fro O = λ { true → true ^♭ ; false → false ^♭ }
fro (S n) = {!Susp-rec {A = Sphere n} {C = ♭ (Sphere (S n))} ♭-north ♭-south!}
-}
|
{
"alphanum_fraction": 0.437833595,
"avg_line_length": 35.6862745098,
"ext": "agda",
"hexsha": "37423864d848ff876c2abf613b6840c3a695a06c",
"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": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "glangmead/formalization",
"max_forks_repo_path": "cohesion/david_jaz_261/Flat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "glangmead/formalization",
"max_issues_repo_path": "cohesion/david_jaz_261/Flat.agda",
"max_line_length": 102,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "glangmead/formalization",
"max_stars_repo_path": "cohesion/david_jaz_261/Flat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z",
"num_tokens": 5103,
"size": 12740
}
|
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_
infixr 1 _,_
_∩_ : {I : Set} → (I → Set) → (I → Set) → I → Set
P ∩ Q = λ i → P i × Q i
record Preorder : Set₁ where
no-eta-equality
field I : Set
infix 4 _∈_
postulate
Ty World Cxt : Set
All : (P : Ty → Set) → Cxt → Set
_∈_ : Ty → World → Set
module Monotone (pre : Preorder) where
open Preorder pre
postulate
Monotone : (I → Set) → Set
instance
postulate
all-monotone : {Γ : Cxt} {C : Ty → I → Set}
⦃ w : ∀ {ty} → Monotone (C ty) ⦄ →
Monotone (λ W → All (λ ty → C ty W) Γ)
module Monad (pre : Preorder) (let open Preorder pre)
(M : (I → Set) → I → Set) where
postulate
_>>=_ : ∀ {P Q W} → M P W → (∀ {W'} → P W' → M Q W') → M Q W
postulate
M : (World → Set) → World → Set
Val : World → Set
preorder : Preorder
preorder .Preorder.I = World
module Inner (Dummy : Set) where -- Succeeds if no Dummy
private
-- Succeeds if type is given
pre : _ -- Preorder
pre = preorder
open Monotone pre
open Monad pre M
postulate
R : World → Set
instance
any-monotone : ∀ {ty} → Monotone (ty ∈_)
local : ∀ Γ {W} → R W × All (_∈ W) Γ → M Val W
^ : ∀ {Q : World → Set} ⦃ m : Monotone Q ⦄ → ∀ {W} → Q W → M (R ∩ Q) W
eval-method : ∀ Γ {W} → All (_∈ W) Γ → M Val W
eval-method Γ args =
^ args >>= local _ -- Succeeds if giving Γ for _
|
{
"alphanum_fraction": 0.5226504395,
"avg_line_length": 20.8309859155,
"ext": "agda",
"hexsha": "68bfaf8a71d7cd8e10be953ff0de8f0669724be1",
"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/Issue3177a.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/Issue3177a.agda",
"max_line_length": 78,
"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/Issue3177a.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": 564,
"size": 1479
}
|
module Prelude.Vec where
open import Prelude.Nat
open import Prelude.Fin
open import Prelude.Unit
open import Prelude.List using (List ; [] ; _::_)
infixr 40 _::_
data Vec (A : Set) : Nat -> Set where
_::_ : forall {n} -> A -> Vec A n -> Vec A (S n)
[] : Vec A Z
infixr 30 _++_
_++_ : {A : Set}{m n : Nat} -> Vec A m -> Vec A n -> Vec A (m + n)
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
snoc : {A : Set}{n : Nat} -> Vec A n -> A -> Vec A (S n)
snoc [] e = e :: []
snoc (x :: xs) e = x :: snoc xs e
length : {A : Set}{n : Nat} -> Vec A n -> Nat
length [] = Z
length (x :: xs) = 1 + length xs
length' : {A : Set}{n : Nat} -> Vec A n -> Nat
length' {n = n} _ = n
zipWith3 : ∀ {A B C D n} -> (A -> B -> C -> D) -> Vec A n -> Vec B n -> Vec C n -> Vec D n
zipWith3 f [] [] [] = []
zipWith3 f (x :: xs) (y :: ys) (z :: zs) = f x y z :: zipWith3 f xs ys zs
zipWith : ∀ {A B C n} -> (A -> B -> C) -> Vec A n -> Vec B n -> {u : Unit} -> Vec C n
zipWith _ [] [] = []
zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys {u = unit}
_!_ : ∀ {A n} -> Vec A n -> Fin n -> A
x :: xs ! fz = x
_ :: xs ! fs n = xs ! n
[] ! ()
_[_]=_ : {A : Set}{n : Nat} -> Vec A n -> Fin n -> A -> Vec A n
(a :: as) [ fz ]= e = e :: as
(a :: as) [ fs n ]= e = a :: (as [ n ]= e)
[] [ () ]= e
map : ∀ {A B n}(f : A -> B)(xs : Vec A n) -> Vec B n
map f [] = []
map f (x :: xs) = f x :: map f xs
forgetL : {A : Set}{n : Nat} -> Vec A n -> List A
forgetL [] = []
forgetL (x :: xs) = x :: forgetL xs
rem : {A : Set}(xs : List A) -> Vec A (Prelude.List.length xs)
rem [] = []
rem (x :: xs) = x :: rem xs
|
{
"alphanum_fraction": 0.4444444444,
"avg_line_length": 27.7627118644,
"ext": "agda",
"hexsha": "d9d2df104a3b101be8afeaf4045bf26562fde4bd",
"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": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "test/epic/Prelude/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"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": "larrytheliquid/agda",
"max_issues_repo_path": "test/epic/Prelude/Vec.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/epic/Prelude/Vec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 652,
"size": 1638
}
|
{-# OPTIONS --without-K #-}
module Fmmh where
open import Data.List using (List)
open import Pitch
-- Reconstruction of "Functional Modelling of Musical Harmony" (ICFP 2011)
-- using similar notation. Original code:
-- https://github.com/chordify/HarmTrace-Base
data Mode : Set where
maj : Mode
min : Mode
data ChordQuality : Set where
maj : ChordQuality
min : ChordQuality
dom7 : ChordQuality
dim : ChordQuality
data Chord : DiatonicDegree → ChordQuality → Set where
chord : (d : DiatonicDegree) → (q : ChordQuality) → Chord d q
data Ton : Mode → Set where
maj : Chord d1 maj → Ton maj
min : Chord d1 min → Ton min
data SDom : Mode → Set where
ii : Chord d2 min → SDom maj
iv-maj : Chord d4 maj → SDom maj
iii-iv : Chord d3 min → Chord d4 maj → SDom maj
iv-min : Chord d4 min → SDom min
data Dom (m : Mode) : Set where
v7 : Chord d5 dom7 → Dom m
v : Chord d5 maj → Dom m
vii : Chord d7 dim → Dom m
sdom : SDom m → Dom m → Dom m
ii-v : Chord d2 dom7 → Chord d5 dom7 → Dom m
data Phrase (m : Mode) : Set where
i-v-i : Ton m → Dom m → Ton m → Phrase m
v-i : Dom m → Ton m → Phrase m
data Piece : Set where
piece : {m : Mode} → List (Phrase m) → Piece
|
{
"alphanum_fraction": 0.6469622332,
"avg_line_length": 24.8571428571,
"ext": "agda",
"hexsha": "7c372232f413bb661f42692cb3944709dda4e3b8",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "doc/icfp20/code/Fmmh.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "doc/icfp20/code/Fmmh.agda",
"max_line_length": 74,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "doc/icfp20/code/Fmmh.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 419,
"size": 1218
}
|
module muRec where
open import Data.Nat
open import Data.Sum
open import Relation.Binary.PropositionalEquality as PE
open import PropsAsTypes
mutual
record D (A : Set) : Set where
coinductive
field
step : Dμ A
data Dμ (A : Set) : Set where
now : A → Dμ A
later : D A → Dμ A
open D public
coiter-D : {A X : Set} → (X → A ⊎ X) → X → D A
coiter-D c x .step with c x
... | inj₁ a = now a
... | inj₂ x' = later (coiter-D c x')
compute-D₁ : {A X : Set} (c : X → A ⊎ X) (x : X) →
∀ a → c x ≡ inj₁ a → coiter-D c x .step ≡ now a
compute-D₁ c x a p with c x
compute-D₁ c x .a refl | inj₁ a = refl
compute-D₁ c x a () | inj₂ y
compute-D₂ : {A X : Set} (c : X → A ⊎ X) (x : X) →
∀ x' → c x ≡ inj₂ x' →
coiter-D c x .step ≡ later (coiter-D c x')
compute-D₂ c x x' p with c x
compute-D₂ c x x' () | inj₁ a
compute-D₂ c x .x' refl | inj₂ x' = refl
compute-D-inv₁ : {A X : Set} (c : X → A ⊎ X) (x : X) →
∀ a → coiter-D c x .step ≡ now a → c x ≡ inj₁ a
compute-D-inv₁ c x a p with c x
compute-D-inv₁ c x .a refl | inj₁ a = refl
compute-D-inv₁ c x a () | inj₂ y
compute-D-inv₂ : {A X : Set} (c : X → A ⊎ X) (x : X) →
∀ x' → c x ≡ inj₂ x' →
coiter-D c x .step ≡ later (coiter-D c x')
compute-D-inv₂ c x x' p with c x
compute-D-inv₂ c x x' () | inj₁ a
compute-D-inv₂ c x .x' refl | inj₂ x' = refl
ifIsZero_then_else_ : {A : Set} → ℕ → A → A → A
ifIsZero zero then x else y = x
ifIsZero (suc _) then x else y = y
isZeroProof : ∀{m n k : ℕ} →
ifIsZero m then inj₁ n else inj₂ k ≡ inj₁ n →
m ≡ 0
isZeroProof {zero} p = refl
isZeroProof {suc m} ()
μ-rec'-coalg : (ℕ → ℕ) → ℕ → ℕ ⊎ ℕ
μ-rec'-coalg f n = ifIsZero f n then inj₁ n else inj₂ (suc n)
μ-rec' : (ℕ → ℕ) → ℕ → D ℕ
μ-rec' f = coiter-D (μ-rec'-coalg f)
μ-rec : (ℕ → ℕ) → D ℕ
μ-rec f = μ-rec' f 0
data _↓_ {A : Set} (d : D A) (a : A) : Prop where
stopped : d .step ≡ now a → d ↓ a
delayed : {d' : D A} → d .step ≡ later d' → d' ↓ a → d ↓ a
μ-rec'-coalg-correct : (f : ℕ → ℕ) (n : ℕ) → μ-rec'-coalg f n ≡ inj₁ n → f n ≡ 0
μ-rec'-coalg-correct f n p = isZeroProof p
μ-rec'-correct : (f : ℕ → ℕ) (m n : ℕ) → (μ-rec' f m ↓ n) → f (m + n) ≡ 0
μ-rec'-correct f m n (stopped p) =
let q = compute-D-inv₁ (μ-rec'-coalg f) m n p
in {!!}
μ-rec'-correct f m n (delayed d' p) = {!!}
μ-rec-correct : (f : ℕ → ℕ) (n : ℕ) → (μ-rec f ↓ n) → f n ≡ 0
μ-rec-correct f n (stopped p) =
let q = compute-D-inv₁ (μ-rec'-coalg f) 0 n p
in μ-rec'-coalg-correct f n {!!}
μ-rec-correct f n (delayed d' p) = {!!}
|
{
"alphanum_fraction": 0.5171762929,
"avg_line_length": 29.7640449438,
"ext": "agda",
"hexsha": "4093780888ffd0706a3b86a35535324cc8206011",
"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": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "TypeTheory/Lecture/muRec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"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": "hbasold/Sandbox",
"max_issues_repo_path": "TypeTheory/Lecture/muRec.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "TypeTheory/Lecture/muRec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1083,
"size": 2649
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.Instances.FreeCommAlgebra where
{-
The free commutative algebra over a commutative ring,
or in other words the ring of polynomials with coefficients in a given ring.
Note that this is a constructive definition, which entails that polynomials
cannot be represented by lists of coefficients, where the last one is non-zero.
For rings with decidable equality, that is still possible.
I learned about this (and other) definition(s) from David Jaz Myers.
You can watch him talk about these things here:
https://www.youtube.com/watch?v=VNp-f_9MnVk
This file contains
* the definition of the free commutative algebra on a type I over a commutative ring R as a HIT
(let us call that R[I])
* a prove that the construction is an commutative R-algebra
* definitions of the induced maps appearing in the universal property of R[I],
that is: * for any map I → A, where A is a commutative R-algebra,
the induced algebra homomorphism R[I] → A
('inducedHom')
* for any hom R[I] → A, the 'restricttion to variables' I → A
('evaluateAt')
* a proof that the two constructions are inverse to each other
('homRetrievable' and 'mapRetrievable')
* a proof, that the corresponding pointwise equivalence of functors is natural
('naturalR', 'naturalL')
-}
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Function hiding (const)
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring using ()
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.Algebra
open import Cubical.HITs.SetTruncation
private
variable
ℓ ℓ' ℓ'' : Level
module Construction (R : CommRing ℓ) where
open CommRingStr (snd R) using (1r; 0r) renaming (_+_ to _+r_; _·_ to _·r_)
data R[_] (I : Type ℓ') : Type (ℓ-max ℓ ℓ') where
var : I → R[ I ]
const : ⟨ R ⟩ → R[ I ]
_+_ : R[ I ] → R[ I ] → R[ I ]
-_ : R[ I ] → R[ I ]
_·_ : R[ I ] → R[ I ] → R[ I ] -- \cdot
+-assoc : (x y z : R[ I ]) → x + (y + z) ≡ (x + y) + z
+-rid : (x : R[ I ]) → x + (const 0r) ≡ x
+-rinv : (x : R[ I ]) → x + (- x) ≡ (const 0r)
+-comm : (x y : R[ I ]) → x + y ≡ y + x
·-assoc : (x y z : R[ I ]) → x · (y · z) ≡ (x · y) · z
·-lid : (x : R[ I ]) → (const 1r) · x ≡ x
·-comm : (x y : R[ I ]) → x · y ≡ y · x
ldist : (x y z : R[ I ]) → (x + y) · z ≡ (x · z) + (y · z)
+HomConst : (s t : ⟨ R ⟩) → const (s +r t) ≡ const s + const t
·HomConst : (s t : ⟨ R ⟩) → const (s ·r t) ≡ (const s) · (const t)
0-trunc : (x y : R[ I ]) (p q : x ≡ y) → p ≡ q
_⋆_ : {I : Type ℓ'} → ⟨ R ⟩ → R[ I ] → R[ I ]
r ⋆ x = const r · x
⋆-assoc : {I : Type ℓ'} → (s t : ⟨ R ⟩) (x : R[ I ]) → (s ·r t) ⋆ x ≡ s ⋆ (t ⋆ x)
⋆-assoc s t x = const (s ·r t) · x ≡⟨ cong (λ u → u · x) (·HomConst _ _) ⟩
(const s · const t) · x ≡⟨ sym (·-assoc _ _ _) ⟩
const s · (const t · x) ≡⟨ refl ⟩
s ⋆ (t ⋆ x) ∎
⋆-ldist-+ : {I : Type ℓ'} → (s t : ⟨ R ⟩) (x : R[ I ]) → (s +r t) ⋆ x ≡ (s ⋆ x) + (t ⋆ x)
⋆-ldist-+ s t x = (s +r t) ⋆ x ≡⟨ cong (λ u → u · x) (+HomConst _ _) ⟩
(const s + const t) · x ≡⟨ ldist _ _ _ ⟩
(s ⋆ x) + (t ⋆ x) ∎
⋆-rdist-+ : {I : Type ℓ'} → (s : ⟨ R ⟩) (x y : R[ I ]) → s ⋆ (x + y) ≡ (s ⋆ x) + (s ⋆ y)
⋆-rdist-+ s x y = const s · (x + y) ≡⟨ ·-comm _ _ ⟩
(x + y) · const s ≡⟨ ldist _ _ _ ⟩
(x · const s) + (y · const s) ≡⟨ cong (λ u → u + (y · const s)) (·-comm _ _) ⟩
(s ⋆ x) + (y · const s) ≡⟨ cong (λ u → (s ⋆ x) + u) (·-comm _ _) ⟩
(s ⋆ x) + (s ⋆ y) ∎
⋆-assoc-· : {I : Type ℓ'} → (s : ⟨ R ⟩) (x y : R[ I ]) → (s ⋆ x) · y ≡ s ⋆ (x · y)
⋆-assoc-· s x y = (s ⋆ x) · y ≡⟨ sym (·-assoc _ _ _) ⟩
s ⋆ (x · y) ∎
0a : {I : Type ℓ'} → R[ I ]
0a = (const 0r)
1a : {I : Type ℓ'} → R[ I ]
1a = (const 1r)
isCommAlgebra : {I : Type ℓ'} → IsCommAlgebra R {A = R[ I ]} 0a 1a _+_ _·_ -_ _⋆_
isCommAlgebra = makeIsCommAlgebra 0-trunc
+-assoc +-rid +-rinv +-comm
·-assoc ·-lid ldist ·-comm
⋆-assoc ⋆-ldist-+ ⋆-rdist-+ ·-lid ⋆-assoc-·
_[_] : (R : CommRing ℓ) (I : Type ℓ') → CommAlgebra R (ℓ-max ℓ ℓ')
(R [ I ]) = R[ I ] , commalgebrastr 0a 1a _+_ _·_ -_ _⋆_ isCommAlgebra
where
open Construction R
module Theory {R : CommRing ℓ} {I : Type ℓ'} where
open CommRingStr (snd R)
using (0r; 1r)
renaming (_·_ to _·r_; _+_ to _+r_; ·Comm to ·r-comm; ·Rid to ·r-rid)
module _ (A : CommAlgebra R ℓ'') (φ : I → ⟨ A ⟩) where
open CommAlgebraStr (A .snd)
open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A)
open Construction using (var; const) renaming (_+_ to _+c_; -_ to -c_; _·_ to _·c_)
imageOf0Works : 0r ⋆ 1a ≡ 0a
imageOf0Works = 0-actsNullifying 1a
imageOf1Works : 1r ⋆ 1a ≡ 1a
imageOf1Works = ⋆-lid 1a
inducedMap : ⟨ R [ I ] ⟩ → ⟨ A ⟩
inducedMap (var x) = φ x
inducedMap (const r) = r ⋆ 1a
inducedMap (P +c Q) = (inducedMap P) + (inducedMap Q)
inducedMap (-c P) = - inducedMap P
inducedMap (Construction.+-assoc P Q S i) = +-assoc (inducedMap P) (inducedMap Q) (inducedMap S) i
inducedMap (Construction.+-rid P i) =
let
eq : (inducedMap P) + (inducedMap (const 0r)) ≡ (inducedMap P)
eq = (inducedMap P) + (inducedMap (const 0r)) ≡⟨ refl ⟩
(inducedMap P) + (0r ⋆ 1a) ≡⟨ cong
(λ u → (inducedMap P) + u)
(imageOf0Works) ⟩
(inducedMap P) + 0a ≡⟨ +-rid _ ⟩
(inducedMap P) ∎
in eq i
inducedMap (Construction.+-rinv P i) =
let eq : (inducedMap P - inducedMap P) ≡ (inducedMap (const 0r))
eq = (inducedMap P - inducedMap P) ≡⟨ +-rinv _ ⟩
0a ≡⟨ sym imageOf0Works ⟩
(inducedMap (const 0r))∎
in eq i
inducedMap (Construction.+-comm P Q i) = +-comm (inducedMap P) (inducedMap Q) i
inducedMap (P ·c Q) = inducedMap P · inducedMap Q
inducedMap (Construction.·-assoc P Q S i) = ·Assoc (inducedMap P) (inducedMap Q) (inducedMap S) i
inducedMap (Construction.·-lid P i) =
let eq = inducedMap (const 1r) · inducedMap P ≡⟨ cong (λ u → u · inducedMap P) imageOf1Works ⟩
1a · inducedMap P ≡⟨ ·Lid (inducedMap P) ⟩
inducedMap P ∎
in eq i
inducedMap (Construction.·-comm P Q i) = ·-comm (inducedMap P) (inducedMap Q) i
inducedMap (Construction.ldist P Q S i) = ·Ldist+ (inducedMap P) (inducedMap Q) (inducedMap S) i
inducedMap (Construction.+HomConst s t i) = ⋆-ldist s t 1a i
inducedMap (Construction.·HomConst s t i) =
let eq = (s ·r t) ⋆ 1a ≡⟨ cong (λ u → u ⋆ 1a) (·r-comm _ _) ⟩
(t ·r s) ⋆ 1a ≡⟨ ⋆-assoc t s 1a ⟩
t ⋆ (s ⋆ 1a) ≡⟨ cong (λ u → t ⋆ u) (sym (·Rid _)) ⟩
t ⋆ ((s ⋆ 1a) · 1a) ≡⟨ ⋆-rassoc t (s ⋆ 1a) 1a ⟩
(s ⋆ 1a) · (t ⋆ 1a) ∎
in eq i
inducedMap (Construction.0-trunc P Q p q i j) =
isSetAlgebra (CommAlgebra→Algebra A) (inducedMap P) (inducedMap Q) (cong _ p) (cong _ q) i j
module _ where
open IsAlgebraHom
inducedHom : AlgebraHom (CommAlgebra→Algebra (R [ I ])) (CommAlgebra→Algebra A)
inducedHom .fst = inducedMap
inducedHom .snd .pres0 = 0-actsNullifying _
inducedHom .snd .pres1 = imageOf1Works
inducedHom .snd .pres+ x y = refl
inducedHom .snd .pres· x y = refl
inducedHom .snd .pres- x = refl
inducedHom .snd .pres⋆ r x =
(r ⋆ 1a) · inducedMap x ≡⟨ ⋆-lassoc r 1a (inducedMap x) ⟩
r ⋆ (1a · inducedMap x) ≡⟨ cong (λ u → r ⋆ u) (·Lid (inducedMap x)) ⟩
r ⋆ inducedMap x ∎
module _ (A : CommAlgebra R ℓ'') where
open CommAlgebraStr (A .snd)
open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A)
open Construction using (var; const) renaming (_+_ to _+c_; -_ to -c_; _·_ to _·c_)
Hom = AlgebraHom (CommAlgebra→Algebra (R [ I ])) (CommAlgebra→Algebra A)
open IsAlgebraHom
evaluateAt : Hom → I → ⟨ A ⟩
evaluateAt φ x = φ .fst (var x)
mapRetrievable : ∀ (φ : I → ⟨ A ⟩)
→ evaluateAt (inducedHom A φ) ≡ φ
mapRetrievable φ = refl
proveEq : ∀ {X : Type ℓ''} (isSetX : isSet X) (f g : ⟨ R [ I ] ⟩ → X)
→ (var-eq : (x : I) → f (var x) ≡ g (var x))
→ (const-eq : (r : ⟨ R ⟩) → f (const r) ≡ g (const r))
→ (+-eq : (x y : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → (eq-y : f y ≡ g y)
→ f (x +c y) ≡ g (x +c y))
→ (·-eq : (x y : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → (eq-y : f y ≡ g y)
→ f (x ·c y) ≡ g (x ·c y))
→ (-eq : (x : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x)
→ f (-c x) ≡ g (-c x))
→ f ≡ g
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (var x) = var-eq x i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (const x) = const-eq x i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (x +c y) =
+-eq x y
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i y)
i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (-c x) =
-eq x ((λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)) i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (x ·c y) =
·-eq x y
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
(λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i y)
i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-assoc x y z j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c (y +c z)) ≡ g (x +c (y +c z))
a₀₋ = +-eq _ _ (rec x) (+-eq _ _ (rec y) (rec z))
a₁₋ : f ((x +c y) +c z) ≡ g ((x +c y) +c z)
a₁₋ = +-eq _ _ (+-eq _ _ (rec x) (rec y)) (rec z)
a₋₀ : f (x +c (y +c z)) ≡ f ((x +c y) +c z)
a₋₀ = cong f (Construction.+-assoc x y z)
a₋₁ : g (x +c (y +c z)) ≡ g ((x +c y) +c z)
a₋₁ = cong g (Construction.+-assoc x y z)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-rid x j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c (const 0r)) ≡ g (x +c (const 0r))
a₀₋ = +-eq _ _ (rec x) (const-eq 0r)
a₁₋ : f x ≡ g x
a₁₋ = rec x
a₋₀ : f (x +c (const 0r)) ≡ f x
a₋₀ = cong f (Construction.+-rid x)
a₋₁ : g (x +c (const 0r)) ≡ g x
a₋₁ = cong g (Construction.+-rid x)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-rinv x j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c (-c x)) ≡ g (x +c (-c x))
a₀₋ = +-eq x (-c x) (rec x) (-eq x (rec x))
a₁₋ : f (const 0r) ≡ g (const 0r)
a₁₋ = const-eq 0r
a₋₀ : f (x +c (-c x)) ≡ f (const 0r)
a₋₀ = cong f (Construction.+-rinv x)
a₋₁ : g (x +c (-c x)) ≡ g (const 0r)
a₋₁ = cong g (Construction.+-rinv x)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-comm x y j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x +c y) ≡ g (x +c y)
a₀₋ = +-eq x y (rec x) (rec y)
a₁₋ : f (y +c x) ≡ g (y +c x)
a₁₋ = +-eq y x (rec y) (rec x)
a₋₀ : f (x +c y) ≡ f (y +c x)
a₋₀ = cong f (Construction.+-comm x y)
a₋₁ : g (x +c y) ≡ g (y +c x)
a₋₁ = cong g (Construction.+-comm x y)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-assoc x y z j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x ·c (y ·c z)) ≡ g (x ·c (y ·c z))
a₀₋ = ·-eq _ _ (rec x) (·-eq _ _ (rec y) (rec z))
a₁₋ : f ((x ·c y) ·c z) ≡ g ((x ·c y) ·c z)
a₁₋ = ·-eq _ _ (·-eq _ _ (rec x) (rec y)) (rec z)
a₋₀ : f (x ·c (y ·c z)) ≡ f ((x ·c y) ·c z)
a₋₀ = cong f (Construction.·-assoc x y z)
a₋₁ : g (x ·c (y ·c z)) ≡ g ((x ·c y) ·c z)
a₋₁ = cong g (Construction.·-assoc x y z)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-lid x j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f ((const 1r) ·c x) ≡ g ((const 1r) ·c x)
a₀₋ = ·-eq _ _ (const-eq 1r) (rec x)
a₁₋ : f x ≡ g x
a₁₋ = rec x
a₋₀ : f ((const 1r) ·c x) ≡ f x
a₋₀ = cong f (Construction.·-lid x)
a₋₁ : g ((const 1r) ·c x) ≡ g x
a₋₁ = cong g (Construction.·-lid x)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-comm x y j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (x ·c y) ≡ g (x ·c y)
a₀₋ = ·-eq _ _ (rec x) (rec y)
a₁₋ : f (y ·c x) ≡ g (y ·c x)
a₁₋ = ·-eq _ _ (rec y) (rec x)
a₋₀ : f (x ·c y) ≡ f (y ·c x)
a₋₀ = cong f (Construction.·-comm x y)
a₋₁ : g (x ·c y) ≡ g (y ·c x)
a₋₁ = cong g (Construction.·-comm x y)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.ldist x y z j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f ((x +c y) ·c z) ≡ g ((x +c y) ·c z)
a₀₋ = ·-eq (x +c y) z
(+-eq _ _ (rec x) (rec y))
(rec z)
a₁₋ : f ((x ·c z) +c (y ·c z)) ≡ g ((x ·c z) +c (y ·c z))
a₁₋ = +-eq _ _ (·-eq _ _ (rec x) (rec z)) (·-eq _ _ (rec y) (rec z))
a₋₀ : f ((x +c y) ·c z) ≡ f ((x ·c z) +c (y ·c z))
a₋₀ = cong f (Construction.ldist x y z)
a₋₁ : g ((x +c y) ·c z) ≡ g ((x ·c z) +c (y ·c z))
a₋₁ = cong g (Construction.ldist x y z)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+HomConst s t j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (const (s +r t)) ≡ g (const (s +r t))
a₀₋ = const-eq (s +r t)
a₁₋ : f (const s +c const t) ≡ g (const s +c const t)
a₁₋ = +-eq _ _ (const-eq s) (const-eq t)
a₋₀ : f (const (s +r t)) ≡ f (const s +c const t)
a₋₀ = cong f (Construction.+HomConst s t)
a₋₁ : g (const (s +r t)) ≡ g (const s +c const t)
a₋₁ = cong g (Construction.+HomConst s t)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·HomConst s t j) =
let
rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)
a₀₋ : f (const (s ·r t)) ≡ g (const (s ·r t))
a₀₋ = const-eq (s ·r t)
a₁₋ : f (const s ·c const t) ≡ g (const s ·c const t)
a₁₋ = ·-eq _ _ (const-eq s) (const-eq t)
a₋₀ : f (const (s ·r t)) ≡ f (const s ·c const t)
a₋₀ = cong f (Construction.·HomConst s t)
a₋₁ : g (const (s ·r t)) ≡ g (const s ·c const t)
a₋₁ = cong g (Construction.·HomConst s t)
in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i
proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.0-trunc x y p q j k) =
let
P : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
P x i = proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x
Q : (x : ⟨ R [ I ] ⟩) → f x ≡ g x
Q x i = proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x
in isOfHLevel→isOfHLevelDep 2
(λ z → isProp→isSet (isSetX (f z) (g z))) _ _
(cong P p)
(cong Q q)
(Construction.0-trunc x y p q) j k i
homRetrievable : ∀ (f : Hom)
→ inducedMap A (evaluateAt f) ≡ fst f
homRetrievable f =
proveEq
(isSetAlgebra (CommAlgebra→Algebra A))
(inducedMap A (evaluateAt f))
(λ x → f $a x)
(λ x → refl)
(λ r → r ⋆ 1a ≡⟨ cong (λ u → r ⋆ u) (sym f.pres1) ⟩
r ⋆ (f $a (const 1r)) ≡⟨ sym (f.pres⋆ r _) ⟩
f $a (const r ·c const 1r) ≡⟨ cong (λ u → f $a u) (sym (Construction.·HomConst r 1r)) ⟩
f $a (const (r ·r 1r)) ≡⟨ cong (λ u → f $a (const u)) (·r-rid r) ⟩
f $a (const r) ∎)
(λ x y eq-x eq-y →
ι (x +c y) ≡⟨ refl ⟩
(ι x + ι y) ≡⟨ cong (λ u → u + ι y) eq-x ⟩
((f $a x) + ι y) ≡⟨
cong (λ u → (f $a x) + u) eq-y ⟩
((f $a x) + (f $a y)) ≡⟨ sym (f.pres+ _ _) ⟩ (f $a (x +c y)) ∎)
(λ x y eq-x eq-y →
ι (x ·c y) ≡⟨ refl ⟩
ι x · ι y ≡⟨ cong (λ u → u · ι y) eq-x ⟩
(f $a x) · (ι y) ≡⟨ cong (λ u → (f $a x) · u) eq-y ⟩
(f $a x) · (f $a y) ≡⟨ sym (f.pres· _ _) ⟩
f $a (x ·c y) ∎)
(λ x eq-x →
ι (-c x) ≡⟨ refl ⟩
- ι x ≡⟨ cong (λ u → - u) eq-x ⟩
- (f $a x) ≡⟨ sym (f.pres- x) ⟩
f $a (-c x) ∎)
where
ι = inducedMap A (evaluateAt f)
module f = IsAlgebraHom (f .snd)
evaluateAt : {R : CommRing ℓ} {I : Type ℓ'} (A : CommAlgebra R ℓ'')
(f : AlgebraHom (CommAlgebra→Algebra (R [ I ])) (CommAlgebra→Algebra A))
→ (I → ⟨ A ⟩)
evaluateAt A f x = f $a (Construction.var x)
inducedHom : {R : CommRing ℓ} {I : Type ℓ'} (A : CommAlgebra R ℓ'')
(φ : I → ⟨ A ⟩)
→ AlgebraHom (CommAlgebra→Algebra (R [ I ])) (CommAlgebra→Algebra A)
inducedHom A φ = Theory.inducedHom A φ
module _ {R : CommRing ℓ} {A B : CommAlgebra R ℓ''} where
A′ = CommAlgebra→Algebra A
B′ = CommAlgebra→Algebra B
R′ = (CommRing→Ring R)
ν : AlgebraHom A′ B′ → (⟨ A ⟩ → ⟨ B ⟩)
ν φ = φ .fst
{-
Hom(R[I],A) → (I → A)
↓ ↓
Hom(R[I],B) → (I → B)
-}
naturalR : {I : Type ℓ'} (ψ : AlgebraHom A′ B′)
(f : AlgebraHom (CommAlgebra→Algebra (R [ I ])) A′)
→ (ν ψ) ∘ evaluateAt A f ≡ evaluateAt B (ψ ∘a f)
naturalR ψ f = refl
{-
Hom(R[I],A) → (I → A)
↓ ↓
Hom(R[J],A) → (J → A)
-}
naturalL : {I J : Type ℓ'} (φ : J → I)
(f : AlgebraHom (CommAlgebra→Algebra (R [ I ])) A′)
→ (evaluateAt A f) ∘ φ
≡ evaluateAt A (f ∘a (inducedHom (R [ I ]) (λ x → Construction.var (φ x))))
naturalL φ f = refl
|
{
"alphanum_fraction": 0.467994167,
"avg_line_length": 43.6118421053,
"ext": "agda",
"hexsha": "2638d4cec4e22ade0941759770e7d25b49bd24d3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lpw25/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommAlgebra/Instances/FreeCommAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lpw25/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommAlgebra/Instances/FreeCommAlgebra.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lpw25/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommAlgebra/Instances/FreeCommAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8260,
"size": 19887
}
|
module Imports.Issue5357-B where
import Imports.Issue5357-D
|
{
"alphanum_fraction": 0.85,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "73911edaa3f6823f38973634630504b8438082a1",
"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/Imports/Issue5357-B.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/Imports/Issue5357-B.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/interaction/Imports/Issue5357-B.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": 17,
"size": 60
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Reflection-based solver for monoid equalities
------------------------------------------------------------------------
--
-- This solver automates the construction of proofs of equivalences
-- between monoid expressions.
-- When called like so:
--
-- proof : ∀ x y z → (x ∙ y) ∙ z ≈ x ∙ (y ∙ z) ∙ ε
-- proof x y z = solve mon
--
-- The following diagram describes what happens under the hood:
--
-- ┌▸x ∙ (y ∙ (z ∙ ε)) ════ x ∙ (y ∙ (z ∙ ε))◂┐
-- │ ║ ║ │
-- │ ║ ║ │
-- [_⇓] ║ ║ [_⇓]
-- ╱ ║ ║ ╲
-- ╱ ║ ║ ╲
-- (x ∙′ y) ∙′ z homo homo x ∙′ (y ∙′ z) ∙′ ε′
-- ▴ ╲ ║ ║ ╱ ▴
-- │ ╲ ║ ║ ╱ │
-- │ [_↓] ║ ║ [_↓] │
-- │ │ ║ ║ │ │
-- │ │ ║ ║ │ │
-- │ └───▸(x ∙ y) ∙ z x ∙ (y ∙ z) ∙ ε◂─┘ │
-- │ │ │ │
-- │ │ │ │
-- └────reflection────┘ └───reflection──────┘
--
-- The actual output—the proof constructed by the solver—is represented
-- by the double-lined path (══).
--
-- We start at the bottom, with our two expressions.
-- Through reflection, we convert these two expressions to their AST
-- representations, in the Expr type.
-- We then can evaluate the AST in two ways: one simply gives us back
-- the two expressions we put in ([_↓]), and the other normalises
-- ([_⇓]).
-- We use the homo function to prove equivalence between these two
-- forms: joining up these two proofs gives us the desired overall
-- proof.
-- Note: What's going on with the Monoid parameter?
--
-- This module is not parameterised over a monoid, which is contrary
-- to what you might expect. Instead, we take the monoid record as an
-- argument to the solve macro, and then pass it around as an
-- argument wherever we need it.
--
-- We need to get the monoid record at the call site, not the import
-- site, to ensure that it's consistent with the rest of the context.
-- For instance, if we wanted to produce `x ∙ y` using the monoid record
-- as imported, we would run into problems:
-- * If we tried to just reflect on the expression itself
-- (quoteTerm (x ∙ y)) we would likely get some de Bruijn indices
-- wrong (in x and y), and ∙ might not even be in scope where the
-- user wants us to solve! If they're solving an expression like
-- x + (y + z), they can pass in the +-0-monoid, but don't have to
-- open it themselves.
-- * If instead we tried to construct a term which accesses the _∙_
-- field on the reflection of the record, we'd run into similar
-- problems again. While the record is a parameter for us, it might
-- not be for the user.
-- Basically, we need the Monoid we're looking at to be exactly the
-- same as the one the user is looking at, and in order to do that we
-- quote it at the call site.
{-# OPTIONS --without-K --safe #-}
module Tactic.MonoidSolver where
open import Algebra
open import Function
open import Data.Bool as Bool using (Bool; _∨_; if_then_else_)
open import Data.Maybe as Maybe using (Maybe; just; nothing; maybe)
open import Data.List as List using (List; _∷_; [])
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Product as Product using (_×_; _,_)
open import Agda.Builtin.Reflection
open import Reflection.Argument
open import Reflection.Term using (getName; _⋯⟅∷⟆_)
open import Reflection.TypeChecking.MonadSyntax
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
----------------------------------------------------------------------
-- The Expr type with homomorphism proofs
----------------------------------------------------------------------
infixl 7 _∙′_
data Expr {a} (A : Set a) : Set a where
_∙′_ : Expr A → Expr A → Expr A
ε′ : Expr A
[_↑] : A → Expr A
module _ {m₁ m₂} (monoid : Monoid m₁ m₂) where
open Monoid monoid
open SetoidReasoning setoid
-- Convert the AST to an expression (i.e. evaluate it) without
-- normalising.
[_↓] : Expr Carrier → Carrier
[ x ∙′ y ↓] = [ x ↓] ∙ [ y ↓]
[ ε′ ↓] = ε
[ [ x ↑] ↓] = x
-- Convert an AST to an expression (i.e. evaluate it) while
-- normalising.
--
-- This first function actually converts an AST to the Cayley
-- representation of the underlying monoid.
-- This obeys the monoid laws up to beta-eta equality, which is the
-- property which gives us the "normalising" behaviour we want.
[_⇓]′ : Expr Carrier → Carrier → Carrier
[ x ∙′ y ⇓]′ z = [ x ⇓]′ ([ y ⇓]′ z)
[ ε′ ⇓]′ y = y
[ [ x ↑] ⇓]′ y = x ∙ y
[_⇓] : Expr Carrier → Carrier
[ x ⇓] = [ x ⇓]′ ε
homo′ : ∀ x y → [ x ⇓] ∙ y ≈ [ x ⇓]′ y
homo′ ε′ y = identityˡ y
homo′ [ x ↑] y = ∙-congʳ (identityʳ x)
homo′ (x ∙′ y) z = begin
[ x ∙′ y ⇓] ∙ z ≡⟨⟩
[ x ⇓]′ [ y ⇓] ∙ z ≈˘⟨ ∙-congʳ (homo′ x [ y ⇓]) ⟩
([ x ⇓] ∙ [ y ⇓]) ∙ z ≈⟨ assoc [ x ⇓] [ y ⇓] z ⟩
[ x ⇓] ∙ ([ y ⇓] ∙ z) ≈⟨ ∙-congˡ (homo′ y z) ⟩
[ x ⇓] ∙ ([ y ⇓]′ z) ≈⟨ homo′ x ([ y ⇓]′ z) ⟩
[ x ⇓]′ ([ y ⇓]′ z) ∎
homo : ∀ x → [ x ⇓] ≈ [ x ↓]
homo ε′ = refl
homo [ x ↑] = identityʳ x
homo (x ∙′ y) = begin
[ x ∙′ y ⇓] ≡⟨⟩
[ x ⇓]′ [ y ⇓] ≈˘⟨ homo′ x [ y ⇓] ⟩
[ x ⇓] ∙ [ y ⇓] ≈⟨ ∙-cong (homo x) (homo y) ⟩
[ x ↓] ∙ [ y ↓] ∎
----------------------------------------------------------------------
-- Helpers for reflection
----------------------------------------------------------------------
_==_ = primQNameEquality
{-# INLINE _==_ #-}
getArgs : Term → Maybe (Term × Term)
getArgs (def _ xs) = go xs
where
go : List (Arg Term) → Maybe (Term × Term)
go (vArg x ∷ vArg y ∷ []) = just (x , y)
go (x ∷ xs) = go xs
go _ = nothing
getArgs _ = nothing
----------------------------------------------------------------------
-- Getting monoid names
----------------------------------------------------------------------
-- We try to be flexible here, by matching two kinds of names.
-- The first is the field accessor for the monoid record itself.
-- However, users will likely want to use the solver with
-- expressions like:
--
-- xs ++ (ys ++ zs) ≡ (xs ++ ys) ++ zs
--
-- So we also evaluate the field accessor to find functions like ++.
record MonoidNames : Set where
field
is-∙ : Name → Bool
is-ε : Name → Bool
buildMatcher : Name → Maybe Name → Name → Bool
buildMatcher n nothing x = n == x
buildMatcher n (just m) x = n == x ∨ m == x
findMonoidNames : Term → TC MonoidNames
findMonoidNames mon = do
∙-altName ← normalise (def (quote Monoid._∙_) (2 ⋯⟅∷⟆ mon ⟨∷⟩ []))
ε-altName ← normalise (def (quote Monoid.ε) (2 ⋯⟅∷⟆ mon ⟨∷⟩ []))
returnTC record
{ is-∙ = buildMatcher (quote Monoid._∙_) (getName ∙-altName)
; is-ε = buildMatcher (quote Monoid.ε) (getName ε-altName)
}
----------------------------------------------------------------------
-- Building Expr
----------------------------------------------------------------------
-- We now define a function that takes an AST representing the LHS
-- or RHS of the equation to solve and converts it into an AST
-- respresenting the corresponding Expr.
″ε″ : Term
″ε″ = quote ε′ ⟨ con ⟩ []
[_↑]′ : Term → Term
[ t ↑]′ = quote [_↑] ⟨ con ⟩ (t ⟨∷⟩ [])
module _ (names : MonoidNames) where
open MonoidNames names
mutual
″∙″ : List (Arg Term) → Term
″∙″ (x ⟨∷⟩ y ⟨∷⟩ []) = quote _∙′_ ⟨ con ⟩ buildExpr x ⟨∷⟩ buildExpr y ⟨∷⟩ []
″∙″ (x ∷ xs) = ″∙″ xs
″∙″ _ = unknown
buildExpr : Term → Term
buildExpr t@(def n xs) =
if is-∙ n
then ″∙″ xs
else if is-ε n
then ″ε″
else
[ t ↑]′
buildExpr t@(con n xs) =
if is-∙ n
then ″∙″ xs
else if is-ε n
then ″ε″
else [ t ↑]′
buildExpr t = quote [_↑] ⟨ con ⟩ (t ⟨∷⟩ [])
----------------------------------------------------------------------
-- Constructing the solution
----------------------------------------------------------------------
-- This function joins up the two homomorphism proofs. It constructs
-- a proof of the following form:
--
-- trans (sym (homo x)) (homo y)
--
-- where x and y are the Expr representations of each side of the
-- goal equation.
constructSoln : Term → MonoidNames → Term → Term → Term
constructSoln mon names lhs rhs =
quote Monoid.trans ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩
(quote Monoid.sym ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩
(quote homo ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩ buildExpr names lhs ⟨∷⟩ []) ⟨∷⟩ [])
⟨∷⟩
(quote homo ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩ buildExpr names rhs ⟨∷⟩ []) ⟨∷⟩
[]
----------------------------------------------------------------------
-- Macro
----------------------------------------------------------------------
solve-macro : Term → Term → TC _
solve-macro mon hole = do
hole′ ← inferType hole >>= normalise
names ← findMonoidNames mon
just (lhs , rhs) ← returnTC (getArgs hole′)
where nothing → typeError (termErr hole′ ∷ [])
let soln = constructSoln mon names lhs rhs
unify hole soln
macro
solve : Term → Term → TC _
solve = solve-macro
|
{
"alphanum_fraction": 0.4810574521,
"avg_line_length": 35.3235294118,
"ext": "agda",
"hexsha": "e9f150e22f6d86a1eb8aead1a1cd0aef6097703b",
"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/Tactic/MonoidSolver.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/Tactic/MonoidSolver.agda",
"max_line_length": 78,
"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/Tactic/MonoidSolver.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": 2925,
"size": 9608
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SmashProduct where
open import Cubical.HITs.SmashProduct.Base public
-- open import Cubical.HITs.SmashProduct.Properties public
|
{
"alphanum_fraction": 0.7810945274,
"avg_line_length": 28.7142857143,
"ext": "agda",
"hexsha": "9a9c934212d8506ec51a8035dd9a4322496d5bb8",
"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/HITs/SmashProduct.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/HITs/SmashProduct.agda",
"max_line_length": 58,
"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/HITs/SmashProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 52,
"size": 201
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor
-- Street fibration, which is the version of fibration that respects the principle of equivalence.
-- https://ncatlab.org/nlab/show/Grothendieck+fibration#StreetFibration
module Categories.Functor.Fibration {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F : Functor C D) where
open import Level
open import Categories.Morphism D using (_≅_)
open import Categories.Morphism.Cartesian using (Cartesian)
private
module C = Category C
module D = Category D
open Functor F
record Fibration : Set (levelOfTerm F) where
field
universal₀ : ∀ {A B} (f : A D.⇒ F₀ B) → C.Obj
universal₁ : ∀ {A B} (f : A D.⇒ F₀ B) → universal₀ f C.⇒ B
iso : ∀ {A B} (f : A D.⇒ F₀ B) → F₀ (universal₀ f) ≅ A
module iso {A B} (f : A D.⇒ F₀ B) = _≅_ (iso f)
field
commute : ∀ {A B} (f : A D.⇒ F₀ B) → f D.∘ iso.from f D.≈ F₁ (universal₁ f)
cartesian : ∀ {A B} (f : A D.⇒ F₀ B) → Cartesian F (universal₁ f)
module cartesian {A B} (f : A D.⇒ F₀ B) = Cartesian (cartesian f)
|
{
"alphanum_fraction": 0.6395663957,
"avg_line_length": 33.5454545455,
"ext": "agda",
"hexsha": "96732aad876672ad58c19f5988a3dd83190bef8f",
"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": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Fibration.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"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": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Fibration.agda",
"max_line_length": 121,
"max_stars_count": 5,
"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/Functor/Fibration.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-22T03:54:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-21T17:07:19.000Z",
"num_tokens": 399,
"size": 1107
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.EilenbergSteenrod where
{-
This module contains the Eilenberg-Steenrod axioms for ordinary
reduced cohomology theories with binary additivity.
The axioms are based on the ones given in Cavallo's MSc thesis
(https://www.cs.cmu.edu/~ecavallo/works/thesis15.pdf) and
Buchholtz/Favonia (2018)
-}
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.HITs.Wedge
open import Cubical.HITs.Pushout
open import Cubical.HITs.Susp
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Sigma
open import Cubical.Data.Int
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open GroupEquiv
open GroupHom
record coHomTheory {ℓ ℓ' : Level} (H : (n : Int) → Pointed ℓ → AbGroup {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ'))
where
Boolℓ : Pointed ℓ
Boolℓ = Lift Bool , lift true
field
Hmap : (n : Int) → {A B : Pointed ℓ} (f : A →∙ B) → AbGroupHom (H n B) (H n A)
Suspension : Σ[ F ∈ ((n : Int) {A : Pointed ℓ} → AbGroupEquiv (H (sucInt n) (Susp (typ A) , north)) (H n A)) ]
({A B : Pointed ℓ} (f : A →∙ B) (n : Int)
→ fun (Hmap (sucInt n) (suspFun (fst f) , refl)) ∘ invEq (eq (F n {A = B}))
≡ invEq (eq (F n {A = A})) ∘ fun (Hmap n f))
Exactness : {A B : Pointed ℓ} (f : A →∙ B) (n : Int)
→ Ker (Hmap n f)
≡ Im (Hmap n {B = _ , inr (pt B)} (cfcod (fst f) , refl))
Dimension : (n : Int) → ¬ n ≡ 0 → isContr (fst (H n Boolℓ))
BinaryWedge : (n : Int) {A B : Pointed ℓ} → AbGroupEquiv (H n (A ⋁ B , (inl (pt A)))) (dirProdAb (H n A) (H n B))
|
{
"alphanum_fraction": 0.6415401302,
"avg_line_length": 36.88,
"ext": "agda",
"hexsha": "ffcef42b61207e2053f4ef319dbe9ad305975846",
"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/Homotopy/EilenbergSteenrod.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/Homotopy/EilenbergSteenrod.agda",
"max_line_length": 117,
"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/Homotopy/EilenbergSteenrod.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 652,
"size": 1844
}
|
data D : Set → Set1 where
c : (A B : Set) → D (A → B)
test : (X : Set) → D X → Set
test .(A → B) (c A B) = A
-- this should crash Epic as long as A is considered forced in constructor c
|
{
"alphanum_fraction": 0.5706806283,
"avg_line_length": 21.2222222222,
"ext": "agda",
"hexsha": "ccf52b1f824b0b273120d2f07d2e9631194b5215",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue1441-5.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue1441-5.agda",
"max_line_length": 76,
"max_stars_count": null,
"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/Issue1441-5.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 70,
"size": 191
}
|
postulate
A : Set
P : A → Set
p : (a : A) → P a
record R : Set where
field
a : A
b : P _
b = p a
test : A
test = R.b
|
{
"alphanum_fraction": 0.4592592593,
"avg_line_length": 9.6428571429,
"ext": "agda",
"hexsha": "afdc14b918bc4db01678f9a2c7f5a6f5108c28a3",
"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/Issue3566.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/Issue3566.agda",
"max_line_length": 20,
"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/Issue3566.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": 61,
"size": 135
}
|
-- Andreas, 2014-09-23
-- Check fixity declarations also in new 'instance' block.
module _ where
postulate
D : Set
instance
infixl 0 D Undeclared
postulate d : D
-- Should fail with error:
-- Names out of scope in fixity declarations: Undeclared
|
{
"alphanum_fraction": 0.7265625,
"avg_line_length": 17.0666666667,
"ext": "agda",
"hexsha": "00c5a37b30e40c7dd8bde1e3abcb7d16affb364f",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue329a.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue329a.agda",
"max_line_length": 58,
"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/Issue329a.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": 75,
"size": 256
}
|
------------------------------------------------------------------------------
-- Example using distributive laws on a binary operation via Agsy
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Tested with the development version of the Agda standard library on
-- 17 May 2012.
module Agsy.DistributiveLaws.TaskB-TopDown where
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
infixl 7 _·_
------------------------------------------------------------------------------
-- Distributive laws axioms
postulate
D : Set -- The universe
_·_ : D → D → D -- The binary operation.
leftDistributive : ∀ x y z → x · (y · z) ≡ (x · y) · (x · z)
rightDistributive : ∀ x y z → (x · y) · z ≡ (x · z) · (y · z)
-- We test Agsy with the longest chains of equalities from
-- DistributiveLaws.TaskB-TopDownATP.
taskB : ∀ u x y z →
(x · y · (z · u)) · ((x · y · ( z · u)) · (x · z · (y · u))) ≡
x · z · (y · u)
taskB u x y z =
-- The numbering of the proof step justifications are associated with
-- the numbers used in DistributiveLaws.TaskB-I.
begin
xy·zu · (xy·zu · xz·yu) ≡⟨ j₁₋₅ ⟩
xy·zu · (xz · xu·yu · (y·zu · xz·yu)) ≡⟨ j₅₋₉ ⟩
xy·zu · (xz · xyu · (yxz · yu)) ≡⟨ j₉₋₁₄ ⟩
xz · xyu · (yz · xyu) · (xz · xyu · (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·zu · (z · xu·yu · (y·xu · z·yu))) ≡⟨ j₂₃₋₂₅ ⟩
(xz · xyu) · (y · xu·zu · (z·xu · y·xu · z·yu)) ≡⟨ j₂₅₋₃₀ ⟩
xz · xyu · (y·zy · xzu) ≡⟨ j₃₀₋₃₅ ⟩
xz·yu
∎
where
-- Two variables abbreviations
xz = x · z
yu = y · u
yz = y · z
-- Three variables abbreviations
xyu = x · y · u
xyz = x · y · z
xzu = x · z · u
yxz = y · x · z
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·zu = x · y · (z · u)
xz·yu = x · z · (y · u)
-- Steps justifications
j₁₋₅ : xy·zu · (xy·zu · xz·yu) ≡
xy·zu · (xz · xu·yu · (y·zu · xz·yu))
j₁₋₅ = {!-t 20 -m !} -- Agsy fails
j₅₋₉ : xy·zu · (xz · xu·yu · (y·zu · xz·yu)) ≡
xy·zu · (xz · xyu · (yxz · yu))
j₅₋₉ = {!-t 20 -m !} -- Agsy fails
j₉₋₁₄ : xy·zu · (xz · xyu · (yxz · yu)) ≡
xz · xyu · (yz · xyu) · (xz · xyu · (y·xu · z·yu))
j₉₋₁₄ = {!-t 20 -m!} -- Agsy fails
j₁₄₋₂₀ : xz · xyu · (yz · xyu) · (xz · xyu · (y·xu · z·yu)) ≡
xz · xyu · (y·xu · (y·yu · z·yu) · (z · xu·yu · (y·xu · z·yu)))
j₁₄₋₂₀ = {!-t 20 -m!} -- Agsy fails
j₂₀₋₂₃ : xz · xyu · (y·xu · (y·yu · z·yu) · (z · xu·yu · (y·xu · z·yu))) ≡
xz · xyu · (y · xu·zu · (z · xu·yu · (y·xu · z·yu)))
j₂₀₋₂₃ = {!-t 20 -m!} -- Agsy fails
j₂₃₋₂₅ : xz · xyu · (y · xu·zu · (z · xu·yu · (y·xu · z·yu))) ≡
(xz · xyu) · (y · xu·zu · (z·xu · y·xu · z·yu))
j₂₃₋₂₅ = {!-t 20 -m!} -- Agsy fails
j₂₅₋₃₀ : (xz · xyu) · (y · xu·zu · (z·xu · y·xu · z·yu)) ≡
xz · xyu · (y·zy · xzu)
j₂₅₋₃₀ = {!-t 20 -m!} -- Agsy fails
j₃₀₋₃₅ : xz · xyu · (y·zy · xzu) ≡
xz·yu
j₃₀₋₃₅ = {!-t 20 -m!} -- Agsy fails
|
{
"alphanum_fraction": 0.4126721763,
"avg_line_length": 31.8421052632,
"ext": "agda",
"hexsha": "8981ecc12a391eec35640dd1a2cfb2b83af96105",
"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/Agsy/DistributiveLaws/TaskB-TopDown.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/Agsy/DistributiveLaws/TaskB-TopDown.agda",
"max_line_length": 79,
"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/Agsy/DistributiveLaws/TaskB-TopDown.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": 1596,
"size": 3630
}
|
{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.Algebra.Algebra where
open import Cubical.Algebra.Algebra.Base public
|
{
"alphanum_fraction": 0.7591240876,
"avg_line_length": 27.4,
"ext": "agda",
"hexsha": "3ae394189ffb5e53469b8d3200524d01c5e00692",
"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/Algebra/Algebra.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/Algebra/Algebra.agda",
"max_line_length": 50,
"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/Algebra/Algebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 34,
"size": 137
}
|
{-# OPTIONS --safe #-}
module Definition.Conversion.FullReduction where
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.Typed.Weakening
open import Definition.Conversion
open import Definition.Conversion.Whnf
open import Definition.Conversion.Stability
open import Definition.Typed.Consequences.Inversion
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.NeTypeEq
open import Definition.Typed.Consequences.Equality
open import Definition.Typed.Consequences.RelevanceUnicity
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties.Escape
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Definition.Typed.Consequences.TypeUnicity
open import Tools.Empty using (⊥; ⊥-elim)
open import Tools.Product
import Tools.PropositionalEquality as PE
mutual
data NfNeutral (Γ : Con Term) : Term → Set where
var : ∀ n → NfNeutral Γ (var n)
∘ₙ : ∀ {k u l} → NfNeutral Γ k → Nf Γ u → NfNeutral Γ (k ∘ u ^ l)
natrecₙ : ∀ {l C c g k} → Nf (Γ ∙ ℕ ^ [ ! , ι ⁰ ]) C → Nf Γ c → Nf Γ g → NfNeutral Γ k → NfNeutral Γ (natrec l C c g k)
Idₙ : ∀ {A t u} → NfNeutral Γ A → Nf Γ t → Nf Γ u → NfNeutral Γ (Id A t u)
Idℕₙ : ∀ {t u} → NfNeutral Γ t → Nf Γ u → NfNeutral Γ (Id ℕ t u)
Idℕ0ₙ : ∀ {u} → NfNeutral Γ u → NfNeutral Γ (Id ℕ zero u)
IdℕSₙ : ∀ {t u} → Nf Γ t → NfNeutral Γ u → NfNeutral Γ (Id ℕ (suc t) u)
IdUₙ : ∀ {t u l} → NfNeutral Γ t → Nf Γ u → NfNeutral Γ (Id (U l) t u)
IdUℕₙ : ∀ {u l} → NfNeutral Γ u → NfNeutral Γ (Id (U l) ℕ u)
IdUΠₙ : ∀ {A rA lA B lB l u} → Nf Γ A → Nf (Γ ∙ A ^ [ rA , ι lA ]) B → NfNeutral Γ u
→ NfNeutral Γ (Id (U l) (Π A ^ rA ° lA ▹ B ° lB ° l) u)
castₙ : ∀ {l A B e t} → NfNeutral Γ A → Nf Γ B → Nf Γ t → NfNeutral Γ (cast l A B e t)
castℕₙ : ∀ {l B e t} → NfNeutral Γ B → Nf Γ t → NfNeutral Γ (cast l ℕ B e t)
castΠₙ : ∀ {l A rA lA P lP B e t} → Nf Γ A → Nf (Γ ∙ A ^ [ rA , ι lA ]) P → NfNeutral Γ B → Nf Γ t
→ NfNeutral Γ (cast l (Π A ^ rA ° lA ▹ P ° lP ° l) B e t)
castℕℕₙ : ∀ {l e t} → NfNeutral Γ t → NfNeutral Γ (cast l ℕ ℕ e t)
castℕΠₙ : ∀ {l A rA B e t} → Nf Γ A → Nf (Γ ∙ A ^ [ rA , ι ⁰ ]) B → Nf Γ t → NfNeutral Γ (cast l ℕ (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° l) e t)
castΠℕₙ : ∀ {l A rA B e t} → Nf Γ A → Nf (Γ ∙ A ^ [ rA , ι ⁰ ]) B → Nf Γ t → NfNeutral Γ (cast l (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° l) ℕ e t)
castΠΠ%!ₙ : ∀ {l A B A' B' e t} → Nf Γ A → Nf (Γ ∙ A ^ [ % , ι ⁰ ]) B → Nf Γ A' → Nf (Γ ∙ A' ^ [ ! , ι ⁰ ]) B' → Nf Γ t
→ NfNeutral Γ (cast l (Π A ^ % ° ⁰ ▹ B ° ⁰ ° l) (Π A' ^ ! ° ⁰ ▹ B' ° ⁰ ° l) e t)
castΠΠ!%ₙ : ∀ {l A B A' B' e t} → Nf Γ A → Nf (Γ ∙ A ^ [ ! , ι ⁰ ]) B → Nf Γ A' → Nf (Γ ∙ A' ^ [ % , ι ⁰ ]) B' → Nf Γ t
→ NfNeutral Γ (cast l (Π A ^ ! ° ⁰ ▹ B ° ⁰ ° l) (Π A' ^ % ° ⁰ ▹ B' ° ⁰ ° l) e t)
Emptyrecₙ : ∀ {l lEmpty A e} → Nf Γ A → NfNeutral Γ (Emptyrec l lEmpty A e)
data Nf (Γ : Con Term) : Term → Set where
Uₙ : ∀ {r l} → Nf Γ (Univ r l)
Πₙ : ∀ {A r lA B lB l} → Nf Γ A → Nf (Γ ∙ A ^ [ r , ι lA ]) B → Nf Γ (Π A ^ r ° lA ▹ B ° lB ° l)
∃ₙ : ∀ {l A B} → Γ ⊢ A ^ [ % , ι l ] → Nf Γ A → Nf (Γ ∙ A ^ [ % , ι l ]) B → Nf Γ (∃ A ▹ B)
ℕₙ : Nf Γ ℕ
Emptyₙ : ∀ {l} → Nf Γ (Empty l)
lamₙ : ∀ {A l rF lF t} → Γ ⊢ A ^ [ rF , ι lF ] → Nf (Γ ∙ A ^ [ rF , ι lF ]) t → Nf Γ (lam A ▹ t ^ l)
zeroₙ : Nf Γ zero
sucₙ : ∀ {t} → Nf Γ t → Nf Γ (suc t)
ne : ∀ {n} → NfNeutral Γ n → Nf Γ n
sprop : ∀ {t A l} → Γ ⊢ t ∷ A ^ [ % , l ] → Nf Γ t
NfNeutralNeutral : ∀ {t Γ} → NfNeutral Γ t → Neutral t
NfNeutralNeutral (var n) = var n
NfNeutralNeutral (∘ₙ X x) = ∘ₙ (NfNeutralNeutral X)
NfNeutralNeutral (natrecₙ x x₁ x₂ X) = natrecₙ (NfNeutralNeutral X)
NfNeutralNeutral (Idₙ X x x₁) = Idₙ (NfNeutralNeutral X)
NfNeutralNeutral (Idℕₙ X x) = Idℕₙ (NfNeutralNeutral X)
NfNeutralNeutral (Idℕ0ₙ X) = Idℕ0ₙ (NfNeutralNeutral X)
NfNeutralNeutral (IdℕSₙ x X) = IdℕSₙ (NfNeutralNeutral X)
NfNeutralNeutral (IdUₙ X x) = IdUₙ (NfNeutralNeutral X)
NfNeutralNeutral (IdUℕₙ X) = IdUℕₙ (NfNeutralNeutral X)
NfNeutralNeutral (IdUΠₙ x x₁ X) = IdUΠₙ (NfNeutralNeutral X)
NfNeutralNeutral (castₙ X x x₁) = castₙ (NfNeutralNeutral X)
NfNeutralNeutral (castℕₙ X x) = castℕₙ (NfNeutralNeutral X)
NfNeutralNeutral (castΠₙ x x₁ X x₂) = castΠₙ (NfNeutralNeutral X)
NfNeutralNeutral (castℕℕₙ X) = castℕℕₙ (NfNeutralNeutral X)
NfNeutralNeutral (castℕΠₙ x x₁ x₂) = castℕΠₙ
NfNeutralNeutral (castΠℕₙ x x₁ x₂) = castΠℕₙ
NfNeutralNeutral (castΠΠ%!ₙ x x₁ x₂ x₃ x₄) = castΠΠ%!ₙ
NfNeutralNeutral (castΠΠ!%ₙ x x₁ x₂ x₃ x₄) = castΠΠ!%ₙ
NfNeutralNeutral (Emptyrecₙ x) = Emptyrecₙ
NfWhnf : ∀ {Γ t A l} → Γ ⊢ t ∷ A ^ [ ! , l ] → Nf Γ t → Whnf t
NfWhnf ⊢t Uₙ = Uₙ
NfWhnf ⊢t (Πₙ X X₁) = Πₙ
NfWhnf ⊢t (∃ₙ _ X X₁) = ∃ₙ
NfWhnf ⊢t ℕₙ = ℕₙ
NfWhnf ⊢t Emptyₙ = Emptyₙ
NfWhnf ⊢t (lamₙ _ X) = lamₙ
NfWhnf ⊢t zeroₙ = zeroₙ
NfWhnf ⊢t (sucₙ X) = sucₙ
NfWhnf ⊢t (ne x) = ne (NfNeutralNeutral x)
NfWhnf ⊢t (sprop ⊢t') = let !≡% , _ = type-uniq ⊢t ⊢t' in ⊥-elim (!≢% !≡%)
NfΠinversion : ∀ {F G rF lF lG lΠ Γ} → Nf Γ (Π F ^ rF ° lF ▹ G ° lG ° lΠ ) → Nf Γ F × Nf (Γ ∙ F ^ [ rF , ι lF ]) G
NfΠinversion (Πₙ X Y) = X , Y
NfΠinversion (sprop ⊢t) =
let _ , _ , _ , _ , _ , _ , e = inversion-Π ⊢t
%≡! , _ = typelevel-injectivity e
in ⊥-elim (!≢% (PE.sym %≡!))
NfΠA′ : ∀ {A F G rF lF lG lΠ Γ l} ([Π] : Γ ⊩⟨ l ⟩Π Π F ^ rF ° lF ▹ G ° lG ° lΠ ^[ ! , lΠ ] )
→ Γ ⊩⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≡ A ^ [ ! , ι lΠ ] / (Π-intr [Π])
→ Nf Γ A
→ ∃₂ λ H E → Nf Γ H × Nf (Γ ∙ H ^ [ rF , ι lF ]) E × A PE.≡ Π H ^ rF ° lF ▹ E ° lG ° lΠ
NfΠA′ (noemb (Πᵣ rF′ lF′ lG′ lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) nfA =
let _ , rF≡rF′ , lF≡lF′ , _ , lG≡lG′ , _ = Π-PE-injectivity (whnfRed* (red D) Πₙ)
X = whnfRed* D′ (NfWhnf (un-univ (redFirst* D′)) nfA)
NfH , NfE = NfΠinversion (PE.subst (Nf _) X nfA)
in F′ , G′ , NfH , PE.subst₂ (λ r l → Nf (_ ∙ _ ^ [ r , ι l ]) _) (PE.sym rF≡rF′) (PE.sym lF≡lF′) NfE ,
PE.subst (λ r → _ PE.≡ Π _ ^ r ° _ ▹ _ ° _ ° _) (PE.sym rF≡rF′)
(PE.subst (λ l → _ PE.≡ Π _ ^ _ ° l ▹ _ ° _ ° _) (PE.sym lF≡lF′)
(PE.subst (λ l → _ PE.≡ Π _ ^ _ ° _ ▹ _ ° l ° _) (PE.sym lG≡lG′) X))
NfΠA′ (emb emb< [Π]) [Π≡A] nfA = NfΠA′ [Π] [Π≡A] nfA
NfΠA′ (emb ∞< [Π]) [Π≡A] nfA = NfΠA′ [Π] [Π≡A] nfA
NfΠA : ∀ {A F G rF lF lG lΠ Γ}
→ Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≡ A ^ [ ! , ι lΠ ]
→ Nf Γ A
→ ∃₂ λ H E → Nf Γ H × Nf (Γ ∙ H ^ [ rF , ι lF ]) E × A PE.≡ Π H ^ rF ° lF ▹ E ° lG ° lΠ
NfΠA {A} Π≡A whnfA =
let X = reducibleEq Π≡A
[Π] = proj₁ X
[A] = proj₁ (proj₂ X)
[Π≡A] = proj₂ (proj₂ X)
in NfΠA′ (Π-elim [Π]) (irrelevanceEq [Π] (Π-intr (Π-elim [Π])) [Π≡A]) whnfA
mutual
convNfNeutral : ∀ {Γ Δ t A r} → ⊢ Γ ≡ Δ → Γ ⊢ t ∷ A ^ r → NfNeutral Γ t → NfNeutral Δ t
convNfNeutral Γ≡Δ ⊢t (var n) = var n
convNfNeutral Γ≡Δ ⊢t (∘ₙ X x) =
let F , rF , lF , G , lG , rG , ⊢k , ⊢u , _ , erl = inversion-app ⊢t
in ∘ₙ (convNfNeutral Γ≡Δ ⊢k X) (convNf Γ≡Δ ⊢u x)
convNfNeutral Γ≡Δ ⊢t (natrecₙ x x₁ x₂ X) =
let _ , ⊢x , ⊢x₁ , ⊢x₂ , ⊢X , _ = inversion-natrec ⊢t
in natrecₙ (convNf (Γ≡Δ ∙ refl (univ (ℕⱼ (wfTerm ⊢t)))) (un-univ ⊢x) x) (convNf Γ≡Δ ⊢x₁ x₁)
(convNf Γ≡Δ ⊢x₂ x₂) (convNfNeutral Γ≡Δ ⊢X X)
convNfNeutral Γ≡Δ ⊢t (Idₙ X x x₁) =
let _ , ⊢X , ⊢x , ⊢x₁ , _ = inversion-Id ⊢t
in Idₙ (convNfNeutral Γ≡Δ ⊢X X) (convNf Γ≡Δ ⊢x x) (convNf Γ≡Δ ⊢x₁ x₁)
convNfNeutral Γ≡Δ ⊢t (Idℕₙ X x) =
let _ , _ , ⊢X , ⊢x , _ = inversion-Id ⊢t
in Idℕₙ (convNfNeutral Γ≡Δ ⊢X X) (convNf Γ≡Δ ⊢x x)
convNfNeutral Γ≡Δ ⊢t (Idℕ0ₙ X) =
let _ , _ , _ , ⊢X , _ = inversion-Id ⊢t
in Idℕ0ₙ (convNfNeutral Γ≡Δ ⊢X X)
convNfNeutral Γ≡Δ ⊢t (IdℕSₙ x X) =
let _ , _ , ⊢x , ⊢X , _ = inversion-Id ⊢t
in IdℕSₙ (convNf Γ≡Δ (proj₁ (inversion-suc ⊢x)) x) (convNfNeutral Γ≡Δ ⊢X X)
convNfNeutral Γ≡Δ ⊢t (IdUₙ X x) =
let _ , _ , ⊢X , ⊢x , _ = inversion-Id ⊢t
in IdUₙ (convNfNeutral Γ≡Δ ⊢X X) (convNf Γ≡Δ ⊢x x)
convNfNeutral Γ≡Δ ⊢t (IdUℕₙ X) =
let _ , _ , _ , ⊢X , _ = inversion-Id ⊢t
in IdUℕₙ (convNfNeutral Γ≡Δ ⊢X X)
convNfNeutral Γ≡Δ ⊢t (IdUΠₙ x x₁ X) =
let _ , _ , ⊢Π , ⊢X , _ = inversion-Id ⊢t
_ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢Π
in IdUΠₙ (convNf Γ≡Δ ⊢F x) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G x₁) (convNfNeutral Γ≡Δ ⊢X X)
convNfNeutral Γ≡Δ ⊢t (castₙ X x x₁) =
let _ , ⊢X , ⊢x , ⊢e , ⊢x₁ , _ = inversion-cast ⊢t
in castₙ (convNfNeutral Γ≡Δ ⊢X X) (convNf Γ≡Δ ⊢x x) (convNf Γ≡Δ ⊢x₁ x₁)
convNfNeutral Γ≡Δ ⊢t (castℕₙ X x) =
let _ , _ , ⊢X , ⊢e , ⊢x , _ = inversion-cast ⊢t
in castℕₙ (convNfNeutral Γ≡Δ ⊢X X) (convNf Γ≡Δ ⊢x x)
convNfNeutral Γ≡Δ ⊢t (castΠₙ x x₁ X x₂) =
let _ , ⊢Π , ⊢X , ⊢e , ⊢x₂ , _ = inversion-cast ⊢t
_ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢Π
in castΠₙ (convNf Γ≡Δ ⊢F x) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G x₁) (convNfNeutral Γ≡Δ ⊢X X) (convNf Γ≡Δ ⊢x₂ x₂)
convNfNeutral Γ≡Δ ⊢t (castℕℕₙ X) =
let _ , _ , _ , _ , ⊢X , _ = inversion-cast ⊢t
in castℕℕₙ (convNfNeutral Γ≡Δ ⊢X X)
convNfNeutral Γ≡Δ ⊢t (castℕΠₙ x x₁ x₂) =
let _ , _ , ⊢Π , ⊢e , ⊢x₂ , _ = inversion-cast ⊢t
_ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢Π
in castℕΠₙ (convNf Γ≡Δ ⊢F x) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G x₁) (convNf Γ≡Δ ⊢x₂ x₂)
convNfNeutral Γ≡Δ ⊢t (castΠℕₙ x x₁ x₂) =
let _ , ⊢Π , _ , ⊢e , ⊢x₂ , _ = inversion-cast ⊢t
_ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢Π
in castΠℕₙ (convNf Γ≡Δ ⊢F x) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G x₁) (convNf Γ≡Δ ⊢x₂ x₂)
convNfNeutral Γ≡Δ ⊢t (castΠΠ%!ₙ x x₁ x₂ x₃ x₄) =
let _ , ⊢Π , ⊢Π' , ⊢e , ⊢x₄ , _ = inversion-cast ⊢t
_ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢Π
_ , _ , _ , ⊢F' , ⊢G' , _ = inversion-Π ⊢Π'
in castΠΠ%!ₙ (convNf Γ≡Δ ⊢F x) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G x₁)
(convNf Γ≡Δ ⊢F' x₂) (convNf (Γ≡Δ ∙ refl (univ ⊢F')) ⊢G' x₃) (convNf Γ≡Δ ⊢x₄ x₄)
convNfNeutral Γ≡Δ ⊢t (castΠΠ!%ₙ x x₁ x₂ x₃ x₄) =
let _ , ⊢Π , ⊢Π' , ⊢e , ⊢x₄ , _ = inversion-cast ⊢t
_ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢Π
_ , _ , _ , ⊢F' , ⊢G' , _ = inversion-Π ⊢Π'
in castΠΠ!%ₙ (convNf Γ≡Δ ⊢F x) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G x₁)
(convNf Γ≡Δ ⊢F' x₂) (convNf (Γ≡Δ ∙ refl (univ ⊢F')) ⊢G' x₃) (convNf Γ≡Δ ⊢x₄ x₄)
convNfNeutral Γ≡Δ ⊢t (Emptyrecₙ x) =
let _ , ⊢x , _ = inversion-Emptyrec ⊢t
in Emptyrecₙ (convNf Γ≡Δ (un-univ ⊢x) x)
convNf : ∀ {Γ Δ t A r} → ⊢ Γ ≡ Δ → Γ ⊢ t ∷ A ^ r → Nf Γ t → Nf Δ t
convNf Γ≡Δ ⊢t Uₙ = Uₙ
convNf Γ≡Δ ⊢t (Πₙ X X₁) =
let _ , _ , _ , ⊢F , ⊢G , _ = inversion-Π ⊢t
in Πₙ (convNf Γ≡Δ ⊢F X) (convNf (Γ≡Δ ∙ refl (univ ⊢F)) ⊢G X₁)
convNf Γ≡Δ ⊢t (∃ₙ ⊢A X X₁) =
let l , ⊢F , ⊢G , _ , erl = inversion-∃ ⊢t
_ , _ , erl = type-uniq (un-univ ⊢A) ⊢F
_ , elA = Uinjectivity erl
in ∃ₙ (stability Γ≡Δ ⊢A) (convNf Γ≡Δ ⊢F X) (convNf (Γ≡Δ ∙ refl (⊢A))
(PE.subst (λ l → _ ∙ _ ^ [ % , ι l ] ⊢ _ ∷ SProp l ^ [ ! , next l ]) (PE.sym elA) ⊢G) X₁)
convNf Γ≡Δ ⊢t ℕₙ = ℕₙ
convNf Γ≡Δ ⊢t Emptyₙ = Emptyₙ
convNf Γ≡Δ ⊢t (lamₙ ⊢F X) =
let rF , lF , G , rG , lG , ⊢F' , ⊢t' , _ , erl = inversion-lam ⊢t
er , el = typelevel-injectivity erl
_ , _ , erl = type-uniq (un-univ ⊢F) (un-univ ⊢F')
erF , elF = Uinjectivity erl
in lamₙ (stability Γ≡Δ ⊢F) (convNf (Γ≡Δ ∙ refl ⊢F)
(PE.subst₂ (λ r l → _ ∙ _ ^ [ r , ι l ] ⊢ _ ∷ G ^ [ rG , ι lG ]) (PE.sym erF) (PE.sym elF) ⊢t') X)
convNf Γ≡Δ ⊢t zeroₙ = zeroₙ
convNf Γ≡Δ ⊢t (sucₙ X) = sucₙ (convNf Γ≡Δ (proj₁ (inversion-suc ⊢t)) X )
convNf Γ≡Δ ⊢t (ne x) = ne (convNfNeutral Γ≡Δ ⊢t x)
convNf Γ≡Δ ⊢t (sprop x) = sprop (stabilityTerm Γ≡Δ x)
mutual
fullRedNe : ∀ {t A l Γ} → Γ ⊢ t ~ t ↑! A ^ l → ∃ λ u → NfNeutral Γ u × Γ ⊢ t ≡ u ∷ A ^ [ ! , l ]
fullRedNe (var-refl x _) = var _ , var _ , refl x
fullRedNe (app-cong {rF = !} {lΠ = lΠ} t u) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
u′ , nfU′ , u≡u′ = fullRedTerm u
in (t′ ∘ u′ ^ lΠ) ,
∘ₙ nfT′ nfU′ ,
app-cong t≡t′ u≡u′
fullRedNe (app-cong {t = a} {rF = %} {lΠ = lΠ} t (%~↑ ⊢a ⊢a')) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
in (t′ ∘ a ^ lΠ) ,
∘ₙ nfT′ (sprop ⊢a) ,
app-cong t≡t′ (proof-irrelevance ⊢a ⊢a')
fullRedNe (natrec-cong {lF = l} C z s n) =
let C′ , nfC′ , C≡C′ = fullRed C
z′ , nfZ′ , z≡z′ = fullRedTerm z
s′ , nfS′ , s≡s′ = fullRedTerm s
n′ , nfN′ , n≡n′ = fullRedNe′ n
in natrec l C′ z′ s′ n′
, natrecₙ nfC′ nfZ′ nfS′ nfN′
, natrec-cong C≡C′ z≡z′ s≡s′ n≡n′
fullRedNe (Emptyrec-cong {k = k} {ll = l} {lEmpty = lEmpty} C (%~↑ ⊢e ⊢e')) =
let C′ , nfC′ , C≡C′ = fullRed C
in Emptyrec l lEmpty C′ k , Emptyrecₙ nfC′
, Emptyrec-cong C≡C′ ⊢e ⊢e'
fullRedNe (Id-cong A t u) =
let A′ , nfA′ , A≡A′ = fullRedNe′ A
t′ , nfT′ , t≡t′ = fullRedTerm t
u′ , nfU′ , u≡u′ = fullRedTerm u
in Id A′ t′ u′ , Idₙ nfA′ nfT′ nfU′ , Id-cong A≡A′ t≡t′ u≡u′
fullRedNe (Id-ℕ t u) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
u′ , nfU′ , u≡u′ = fullRedTerm u
in Id ℕ t′ u′ , Idℕₙ nfT′ nfU′ , Id-cong (refl (ℕⱼ (wfEqTerm u≡u′))) t≡t′ u≡u′
fullRedNe (Id-ℕ0 t) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
in Id ℕ zero t′ , Idℕ0ₙ nfT′ , Id-cong (refl (ℕⱼ (wfEqTerm t≡t′))) (refl (zeroⱼ (wfEqTerm t≡t′))) t≡t′
fullRedNe (Id-ℕS t u) =
let t′ , nfT′ , t≡t′ = fullRedTerm t
u′ , nfU′ , u≡u′ = fullRedNe′ u
in Id ℕ (suc t′) u′ , IdℕSₙ nfT′ nfU′ , Id-cong (refl (ℕⱼ (wfEqTerm u≡u′))) (suc-cong t≡t′) u≡u′
fullRedNe (Id-U t u) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
u′ , nfU′ , u≡u′ = fullRedTerm u
in Id (U _) t′ u′ , IdUₙ nfT′ nfU′ , Id-cong (refl (univ 0<1 (wfEqTerm u≡u′))) t≡t′ u≡u′
fullRedNe (Id-Uℕ t) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
in Id (U _) ℕ t′ , IdUℕₙ nfT′ , Id-cong (refl (univ 0<1 (wfEqTerm t≡t′))) (refl (ℕⱼ (wfEqTerm t≡t′))) t≡t′
fullRedNe (Id-UΠ {rA = rA} A t) =
let t′ , nfT′ , t≡t′ = fullRedNe′ t
A′ , nfA′ , A≡A′ = fullRedTerm A
H , E , NfH , NfE , Π≡HE = NfΠA (univ A≡A′) nfA′
in Id (U _) (Π H ^ rA ° ⁰ ▹ E ° ⁰ ° ⁰) t′ ,
IdUΠₙ NfH NfE nfT′ ,
Id-cong (refl (univ 0<1 (wfEqTerm t≡t′))) (PE.subst (λ A → _ ⊢ _ ≡ A ∷ U ⁰ ^ _) Π≡HE A≡A′) t≡t′
fullRedNe (cast-cong {e = e} {e' = e'} x x₁ x₂ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedNe′ x
B′ , nfB′ , B≡B′ = fullRedTerm x₁
t′ , nft′ , t≡t′ = fullRedTerm x₂
in cast ⁰ A′ B′ e t′ , castₙ nfA′ nfB′ nft′ ,
cast-cong A≡A′ B≡B′ t≡t′ ⊢e (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) A≡A′ B≡B′)))
fullRedNe (cast-ℕ {e = e} {e' = e'} x x₁ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedNe′ x
t′ , nft′ , t≡t′ = fullRedTerm x₁
in cast ⁰ _ A′ e t′ , castℕₙ nfA′ nft′ ,
cast-cong (refl (ℕⱼ (wfTerm ⊢e)) ) A≡A′ t≡t′ ⊢e
(conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) (refl (ℕⱼ (wfTerm ⊢e))) A≡A′)))
fullRedNe (cast-ℕℕ {e = e} {e' = e'} x ⊢e ⊢e') =
let t′ , nft′ , t≡t′ = fullRedNe′ x
in cast ⁰ _ _ e t′ , castℕℕₙ nft′ ,
cast-cong (refl (ℕⱼ (wfTerm ⊢e)) ) (refl (ℕⱼ (wfTerm ⊢e)) ) t≡t′ ⊢e ⊢e
fullRedNe (cast-Π {e = e} {e' = e'} x x₁ x₂ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedTerm x
B′ , nfB′ , B≡B′ = fullRedNe′ x₁
t′ , nft′ , t≡t′ = fullRedTerm x₂
H , E , NfH , NfE , Π≡HE = NfΠA (univ A≡A′) nfA′
nfCast = castΠₙ NfH NfE nfB′ nft′
in cast ⁰ A′ B′ e t′ , PE.subst (λ A → NfNeutral _ (cast ⁰ A _ _ _)) (PE.sym Π≡HE) nfCast ,
cast-cong A≡A′ B≡B′ t≡t′ ⊢e (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) A≡A′ B≡B′)))
fullRedNe (cast-Πℕ {e = e} {e' = e'} x x₁ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedTerm x
t′ , nft′ , t≡t′ = fullRedTerm x₁
H , E , NfH , NfE , Π≡HE = NfΠA (univ A≡A′) nfA′
nfCast = castΠℕₙ NfH NfE nft′
in cast ⁰ A′ ℕ e t′ , PE.subst (λ A → NfNeutral _ (cast ⁰ A _ _ _)) (PE.sym Π≡HE) nfCast ,
cast-cong A≡A′ (refl (ℕⱼ (wfTerm ⊢e))) t≡t′ ⊢e (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) A≡A′ (refl (ℕⱼ (wfTerm ⊢e))))))
fullRedNe (cast-ℕΠ {e = e} {e' = e'} x x₁ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedTerm x
t′ , nft′ , t≡t′ = fullRedTerm x₁
H , E , NfH , NfE , Π≡HE = NfΠA (univ A≡A′) nfA′
nfCast = castℕΠₙ NfH NfE nft′
in cast ⁰ ℕ A′ e t′ , PE.subst (λ A → NfNeutral _ (cast ⁰ _ A _ _)) (PE.sym Π≡HE) nfCast ,
cast-cong (refl (ℕⱼ (wfTerm ⊢e))) A≡A′ t≡t′ ⊢e (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) (refl (ℕⱼ (wfTerm ⊢e))) A≡A′ )))
fullRedNe (cast-ΠΠ%! {e = e} {e' = e'} x x₁ x₂ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedTerm x
B′ , nfB′ , B≡B′ = fullRedTerm x₁
t′ , nft′ , t≡t′ = fullRedTerm x₂
H , E , NfH , NfE , Π≡HE = NfΠA (univ A≡A′) nfA′
H' , E' , NfH' , NfE' , Π≡HE' = NfΠA (univ B≡B′) nfB′
nfCast = castΠΠ%!ₙ NfH NfE NfH' NfE' nft′
in cast ⁰ A′ B′ e t′ , PE.subst₂ (λ A B → NfNeutral _ (cast ⁰ A B _ _)) (PE.sym Π≡HE) (PE.sym Π≡HE') nfCast ,
cast-cong A≡A′ B≡B′ t≡t′ ⊢e (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) A≡A′ B≡B′ )))
fullRedNe (cast-ΠΠ!% {e = e} {e' = e'} x x₁ x₂ ⊢e ⊢e') =
let A′ , nfA′ , A≡A′ = fullRedTerm x
B′ , nfB′ , B≡B′ = fullRedTerm x₁
t′ , nft′ , t≡t′ = fullRedTerm x₂
H , E , NfH , NfE , Π≡HE = NfΠA (univ A≡A′) nfA′
H' , E' , NfH' , NfE' , Π≡HE' = NfΠA (univ B≡B′) nfB′
nfCast = castΠΠ!%ₙ NfH NfE NfH' NfE' nft′
in cast ⁰ A′ B′ e t′ , PE.subst₂ (λ A B → NfNeutral _ (cast ⁰ A B _ _)) (PE.sym Π≡HE) (PE.sym Π≡HE') nfCast ,
cast-cong A≡A′ B≡B′ t≡t′ ⊢e (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e)) ) A≡A′ B≡B′ )))
fullRedNe′ : ∀ {t A rA Γ} → Γ ⊢ t ~ t ↓! A ^ rA → ∃ λ u → NfNeutral Γ u × Γ ⊢ t ≡ u ∷ A ^ [ ! , rA ]
fullRedNe′ ([~] A D whnfB k~l) =
let u , nf , t≡u = fullRedNe k~l
in u , nf , conv t≡u (subset* D)
fullRed : ∀ {A rA Γ} → Γ ⊢ A [conv↑] A ^ rA → ∃ λ B → Nf Γ B × Γ ⊢ A ≡ B ^ rA
fullRed ([↑] A′ B′ D D′ whnfA′ whnfB′ A′<>B′)
rewrite whrDet* (D , whnfA′) (D′ , whnfB′) =
let B″ , nf , B′≡B″ = fullRed′ A′<>B′
in B″ , nf , trans (subset* D′) B′≡B″
fullRed′ : ∀ {A rA Γ} → Γ ⊢ A [conv↓] A ^ rA → ∃ λ B → Nf Γ B × Γ ⊢ A ≡ B ^ rA
fullRed′ (U-refl {r = r} _ ⊢Γ) = Univ r ¹ , Uₙ , refl (Uⱼ ⊢Γ)
fullRed′ (univ x) =
let u , Nfu , u≡u = fullRedTerm′ x
in u , Nfu , univ u≡u
fullRedTerm : ∀ {t A l Γ} → Γ ⊢ t [conv↑] t ∷ A ^ l → ∃ λ u → Nf Γ u × Γ ⊢ t ≡ u ∷ A ^ [ ! , l ]
fullRedTerm ([↑]ₜ B t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u)
rewrite whrDet*Term (d , whnft′) (d′ , whnfu′) =
let u″ , nf , u′≡u″ = fullRedTerm′ t<>u
in u″ , nf , conv (trans (subset*Term d′) u′≡u″) (sym (subset* D))
fullRedTerm′ : ∀ {t A l Γ} → Γ ⊢ t [conv↓] t ∷ A ^ l → ∃ λ u → Nf Γ u × Γ ⊢ t ≡ u ∷ A ^ [ ! , l ]
fullRedTerm′ (U-refl {r = r} _ ⊢Γ) = Univ r ⁰ , Uₙ , refl (univ 0<1 ⊢Γ)
fullRedTerm′ (ne A) =
let B , nf , A≡B = fullRedNe′ A
in B , ne nf , A≡B
fullRedTerm′ (ℕ-refl ⊢Γ) = ℕ , ℕₙ , refl (ℕⱼ ⊢Γ)
fullRedTerm′ (Empty-refl PE.refl ⊢Γ) = Empty _ , Emptyₙ , refl (Emptyⱼ ⊢Γ)
fullRedTerm′ (Π-cong {rF = rF} PE.refl PE.refl PE.refl PE.refl l< l<' ⊢F F G) =
let F′ , nfF′ , F≡F′ = fullRedTerm F
G′ , nfG′ , G≡G′ = fullRedTerm G
in Π F′ ^ rF ° _ ▹ G′ ° _ ° _ , Πₙ nfF′ (convNf (reflConEq (wf ⊢F) ∙ univ F≡F′) (proj₂ (proj₂ (syntacticEqTerm G≡G′))) nfG′)
, Π-cong l< l<' ⊢F F≡F′ G≡G′
fullRedTerm′ (∃-cong PE.refl ⊢F F G) =
let F′ , nfF′ , F≡F′ = fullRedTerm F
G′ , nfG′ , G≡G′ = fullRedTerm G
in ∃ F′ ▹ G′ , ∃ₙ (univ (proj₂ (proj₂ (syntacticEqTerm F≡F′)))) nfF′
(convNf (reflConEq (wf ⊢F) ∙ univ F≡F′) (proj₂ (proj₂ (syntacticEqTerm G≡G′))) nfG′)
, ∃-cong ⊢F F≡F′ G≡G′
fullRedTerm′ (ℕ-ins t) =
let u , nf , t≡u = fullRedNe′ t
in u , ne nf , t≡u
fullRedTerm′ (ne-ins ⊢t _ _ t) =
let u , nfU , t≡u = fullRedNe′ t
_ , ⊢t∷M , _ = syntacticEqTerm t≡u
_ , neT , _ = ne~↓! t
in u , ne nfU , conv t≡u (proj₂ (neTypeEq neT ⊢t∷M ⊢t))
fullRedTerm′ (zero-refl ⊢Γ) = zero , zeroₙ , refl (zeroⱼ ⊢Γ)
fullRedTerm′ (suc-cong t) =
let u , nf , t≡u = fullRedTerm t
in suc u , sucₙ nf , suc-cong t≡u
fullRedTerm′ (η-eq {F = F} {l = l} l< l<' ⊢F ⊢t _ _ _ t∘0) =
let u , nf , t∘0≡u = fullRedTerm t∘0
_ , _ , ⊢u = syntacticEqTerm t∘0≡u
ΓF⊢ = wf ⊢F ∙ ⊢F
wk⊢F = wk (step id) ΓF⊢ ⊢F
ΓFF'⊢ = ΓF⊢ ∙ wk⊢F
wk⊢u = wkTerm (lift (step id)) ΓFF'⊢ ⊢u
λu∘0 = (lam _ ▹ (U.wk (lift (step id)) u) ^ _) ∘ var 0 ^ l
in lam _ ▹ u ^ _ ,
lamₙ ⊢F nf
, η-eq l< l<' ⊢F ⊢t (lamⱼ l< l<' ⊢F ⊢u)
(trans t∘0≡u (PE.subst₂ (λ x y → _ ⊢ x ≡ λu∘0 ∷ y ^ _)
(wkSingleSubstId u) (wkSingleSubstId _)
(sym (β-red l< l<' wk⊢F wk⊢u (var ΓF⊢ here)))))
|
{
"alphanum_fraction": 0.5101382919,
"avg_line_length": 51.2057416268,
"ext": "agda",
"hexsha": "253e2907a3353b2ceaa60efbeac261bdbfd4fc74",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Conversion/FullReduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Conversion/FullReduction.agda",
"max_line_length": 141,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Conversion/FullReduction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 11493,
"size": 21404
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.EpochManager as EpochManager
open import LibraBFT.Impl.Consensus.EpochManagerTypes
import LibraBFT.Impl.Consensus.TestUtils.MockStorage as MockStorage
import LibraBFT.Impl.Types.OnChainConfig.ValidatorSet as ValidatorSet
import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
import LibraBFT.Impl.Types.Waypoint as Waypoint
import LibraBFT.Impl.IO.OBM.GenKeyFile as GenKeyFile
import LibraBFT.Impl.OBM.ConfigHardCoded as ConfigHardCoded
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochIndep
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.PKCS
open import Util.Prelude hiding (_++_)
------------------------------------------------------------------------------
open import Data.String using (String; _++_)
module LibraBFT.Impl.Consensus.ConsensusProvider where
obmInitialData
: GenKeyFile.NfLiwsVsVvPe
→ Either ErrLog
(NodeConfig × OnChainConfigPayload × LedgerInfoWithSignatures × SK × ProposerElection)
obmInitialData ( _numFaults , genesisLIWS , validatorSigner
, validatorVerifier , proposerElection ) = do
let vs = ValidatorSet.obmFromVV validatorVerifier
occp = onChainConfigPayload vs
wp ← Waypoint.newEpochBoundary (genesisLIWS ^∙ liwsLedgerInfo)
let nc = nodeConfig wp
pure (nc , occp , genesisLIWS , validatorSigner ^∙ vsPrivateKey , proposerElection)
where
onChainConfigPayload : ValidatorSet → OnChainConfigPayload
onChainConfigPayload = OnChainConfigPayload∙new ({-Epoch-} 1)
nodeConfig : Waypoint → NodeConfig
nodeConfig genesisWaypoint =
record -- NodeConfig
{ _ncObmMe = validatorSigner ^∙ vsAuthor
; _ncConsensus = record -- ConsensusConfig
{ _ccMaxPrunedBlocksInMem = ConfigHardCoded.maxPrunedBlocksInMem
; _ccRoundInitialTimeoutMS = ConfigHardCoded.roundInitialTimeoutMS
; _ccSafetyRules = record -- SafetyRulesConfig
{ _srcService = SRSLocal
; _srcExportConsensusKey = true
; _srcObmGenesisWaypoint = genesisWaypoint
}
; _ccSyncOnly = false
}
}
abstract
obmInitialData-ed-abs
: GenKeyFile.NfLiwsVsVvPe
→ EitherD ErrLog
(NodeConfig × OnChainConfigPayload × LedgerInfoWithSignatures × SK × ProposerElection)
obmInitialData-ed-abs = fromEither ∘ obmInitialData
------------------------------------------------------------------------------
-- LBFT-OBM-DIFF
-- 'start_consensus' in Rust inits and loops
-- that is split so 'startConsensus' returns init data
-- then loop is called with that data.
module startConsensus-ed
(nodeConfig : NodeConfig)
-- BEGIN OBM
(obmNow : Instant)
(obmPayload : OnChainConfigPayload)
(obmGenesisLIWS : LedgerInfoWithSignatures)
(obmSK : SK)
(obmNeedFetch : ObmNeedFetch)
(obmProposalGenerator : ProposalGenerator)
(obmStateComputer : StateComputer)
where
-- END OBM
step₁ : ValidatorSet → (RecoveryData × PersistentLivenessStorage) → EitherD ErrLog (EpochManager × List Output)
step₂ : PersistentLivenessStorage → ValidatorInfo → EitherD ErrLog (EpochManager × List Output)
step₀ : EitherD ErrLog (EpochManager × List Output)
step₀ = do
let obmValidatorSet = obmPayload ^∙ occpObmValidatorSet
eitherS (MockStorage.startForTesting obmValidatorSet (just obmGenesisLIWS)) LeftD (step₁ obmValidatorSet)
step₁ obmValidatorSet (_obmRecoveryData , persistentLivenessStorage) = do
let stateComputer = obmStateComputer
eitherS (ValidatorSet.obmGetValidatorInfo (nodeConfig ^∙ ncObmMe) obmValidatorSet) LeftD (step₂ persistentLivenessStorage)
step₂ persistentLivenessStorage vi = do
eitherS (EpochManager.new nodeConfig stateComputer persistentLivenessStorage
(vi ^∙ viAccountAddress) obmSK) LeftD $
λ epochMgr →
EpochManager.start-ed
epochMgr obmNow
obmPayload obmNeedFetch obmProposalGenerator
obmGenesisLIWS
abstract
startConsensus-ed-abs = startConsensus-ed.step₀
startConsensus-ed-abs-≡ : startConsensus-ed-abs ≡ startConsensus-ed.step₀
startConsensus-ed-abs-≡ = refl
|
{
"alphanum_fraction": 0.6799103504,
"avg_line_length": 43.8214285714,
"ext": "agda",
"hexsha": "cd5e8aa03295a6a0a5af9b43ecfdfdb0f904abd9",
"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/Consensus/ConsensusProvider.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/Consensus/ConsensusProvider.agda",
"max_line_length": 130,
"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/Consensus/ConsensusProvider.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1257,
"size": 4908
}
|
{-# OPTIONS --type-in-type
--guardedness-preserving-type-constructors #-}
module Issue690b where
open import Common.Coinduction
data Rec (A : ∞ Set) : Set where
fold : (x : ♭ A) → Rec A
infixr 4 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
infix 4 _≡_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
data ⊥ : Set where
{-# NON_TERMINATING #-}
D : Set
D = Rec (♯ Σ Set λ E → Σ (D ≡ E) λ _ → E → ⊥)
lam : (D → ⊥) → D
lam f = fold (D , refl , f)
app : D → D → ⊥
app (fold (.D , refl , f)) d = f d
omega : D
omega = lam (λ x → app x x)
Omega : ⊥
Omega = app omega omega
|
{
"alphanum_fraction": 0.5457271364,
"avg_line_length": 16.2682926829,
"ext": "agda",
"hexsha": "4982d3e5aea9c4a2addc9b0fd281bc66628fab58",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue690b.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue690b.agda",
"max_line_length": 58,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue690b.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": 258,
"size": 667
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Core properties related to propositional list membership.
--
-- This file is needed to break the cyclic dependency with the proof
-- `Any-cong` in `Data.Any.Properties` which relies on `Any↔` in this
-- file.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Membership.Propositional.Properties.Core where
open import Function using (flip; id; _∘_)
open import Function.Inverse using (_↔_; inverse)
open import Data.List.Base using (List)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
open import Data.List.Membership.Propositional
open import Data.Product as Prod
using (_,_; proj₁; proj₂; uncurry′; ∃; _×_)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl)
open import Relation.Unary using (_⊆_)
-- Lemmas relating map and find.
map∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs}
(p : Any P xs) → let p′ = find p in
{f : _≡_ (proj₁ p′) ⊆ P} →
f refl ≡ proj₂ (proj₂ p′) →
Any.map f (proj₁ (proj₂ p′)) ≡ p
map∘find (here p) hyp = P.cong here hyp
map∘find (there p) hyp = P.cong there (map∘find p hyp)
find∘map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs : List A} (p : Any P xs) (f : P ⊆ Q) →
find (Any.map f p) ≡ Prod.map id (Prod.map id f) (find p)
find∘map (here p) f = refl
find∘map (there p) f rewrite find∘map p f = refl
-- find satisfies a simple equality when the predicate is a
-- propositional equality.
find-∈ : ∀ {a} {A : Set a} {x : A} {xs : List A} (x∈xs : x ∈ xs) →
find x∈xs ≡ (x , x∈xs , refl)
find-∈ (here refl) = refl
find-∈ (there x∈xs) rewrite find-∈ x∈xs = refl
-- find and lose are inverses (more or less).
lose∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A}
(p : Any P xs) →
uncurry′ lose (proj₂ (find p)) ≡ p
lose∘find p = map∘find p P.refl
find∘lose : ∀ {a p} {A : Set a} (P : A → Set p) {x xs}
(x∈xs : x ∈ xs) (pp : P x) →
find {P = P} (lose x∈xs pp) ≡ (x , x∈xs , pp)
find∘lose P x∈xs p
rewrite find∘map x∈xs (flip (P.subst P) p)
| find-∈ x∈xs
= refl
-- Any can be expressed using _∈_
∃∈-Any : ∀ {a p} {A : Set a} {P : A → Set p} {xs} →
(∃ λ x → x ∈ xs × P x) → Any P xs
∃∈-Any = uncurry′ lose ∘ proj₂
Any↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} →
(∃ λ x → x ∈ xs × P x) ↔ Any P xs
Any↔ = inverse ∃∈-Any find from∘to lose∘find
where
from∘to : ∀ v → find (∃∈-Any v) ≡ v
from∘to p = find∘lose _ (proj₁ (proj₂ p)) (proj₂ (proj₂ p))
|
{
"alphanum_fraction": 0.5413895048,
"avg_line_length": 35.1428571429,
"ext": "agda",
"hexsha": "3710a14308a178ebc035875ba78680ea62df93c3",
"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/Membership/Propositional/Properties/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/Propositional/Properties/Core.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/Data/List/Membership/Propositional/Properties/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 970,
"size": 2706
}
|
module core where
open import Data.Nat
open import Data.Vec
open import Data.Fin
open import Data.String
open import Data.Rational
open import Data.Sum
open import Data.Unit
open import Binders.Var
{-
module ABTLearning where
data View {univ : Set} (f : univ -> Set) (a : univ) : list univ -> Set where
Syn : f a -> View f a []
Var :
record ABT {u : Set}
data Var (a b : Set) where
Free
-}
module Term where
data Literal : Set where
Nat : ℕ -> Literal
Rat : ℚ -> Literal
Str : String -> Literal
data term (a : Set) : Set where
v : a -> term a
app : ∀ (n : ℕ ) -> term a -> Vec (term a) n -> term a
abs : ∀ (n : ℕ ) -> term (Var (Fin n) (term a))-> term a
primcall : ∀ {n : ℕ } -> String -> Vec (term a) n -> term a
lit : Literal -> term a
force : term a -> term a
delay : term a -> term a
module TypedTerm where
data PrimType : Set where
Nat : PrimType
Rat : PrimType
Str : PrimType
data Sort : Set where -- should this be a record??
lit : ℕ -> Sort
-- var :
-- univ→ :
data Literal : PrimType -> Set where
NatL : ℕ -> Literal Nat
RatL : ℚ -> Literal Rat
StrL : String -> Literal Str
module PHOAS where
data Exp (a : Set) : Set where
Lam : (a -> Exp a) -> Exp a
App : (Exp a) -> Exp a -> Exp a
|
{
"alphanum_fraction": 0.5442225392,
"avg_line_length": 22.253968254,
"ext": "agda",
"hexsha": "b17baaee9e65b5f392bba2be835aa27006d17f8a",
"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": "e0de23b3c78313a7f6856c3d48c3d6a2ce3962dd",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "hopper-lang/hopper-v0",
"max_forks_repo_path": "models/agda/core.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "e0de23b3c78313a7f6856c3d48c3d6a2ce3962dd",
"max_issues_repo_issues_event_max_datetime": "2020-02-19T01:08:47.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-02-19T01:08:47.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "hopper-lang/hopper-v0",
"max_issues_repo_path": "models/agda/core.agda",
"max_line_length": 79,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "e0de23b3c78313a7f6856c3d48c3d6a2ce3962dd",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "hopper-lang/hopper-v0",
"max_stars_repo_path": "models/agda/core.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-18T03:02:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-23T16:03:03.000Z",
"num_tokens": 429,
"size": 1402
}
|
{-# OPTIONS --without-K #-}
open import HoTT hiding (_::_)
module algebra.ReducedWord {i} (A : Type i) (dec : has-dec-eq A) where
open import algebra.Word A
is-reduced : Word → Type i
is-reduced nil = Lift ⊤
is-reduced (x :: nil) = Lift ⊤
is-reduced (x :: y :: w) = is-reduced (y :: w)
is-reduced (x :: y inv:: w) = (x ≠ y) × is-reduced (y inv:: w)
is-reduced (x inv:: nil) = Lift Unit
is-reduced (x inv:: y :: w) = (x ≠ y) × is-reduced (y :: w)
is-reduced (x inv:: y inv:: w) = is-reduced (y inv:: w)
ReducedWord : Type i
ReducedWord = Σ Word is-reduced
-- Everything is a set.
A-is-set : is-set A
A-is-set = dec-eq-is-set dec
Word-has-dec-eq : has-dec-eq (Word)
Word-has-dec-eq nil nil = inl idp
Word-has-dec-eq nil (x :: w) = inr (lower ∘ Word=-out)
Word-has-dec-eq nil (x inv:: w) = inr (lower ∘ Word=-out)
Word-has-dec-eq (x :: v) nil = inr (lower ∘ Word=-out)
Word-has-dec-eq (x :: v) (y :: w) with (dec x y)
Word-has-dec-eq (x :: v) (y :: w) | inl x=y with (Word-has-dec-eq v w)
Word-has-dec-eq (x :: v) (y :: w) | inl x=y | inl v=w = inl (Word=-in (x=y , v=w))
Word-has-dec-eq (x :: v) (y :: w) | inl x=y | inr v≠w = inr (v≠w ∘ Word-snd=)
Word-has-dec-eq (x :: v) (y :: w) | inr x≠y = inr (x≠y ∘ Word-fst=)
Word-has-dec-eq (x :: v) (y inv:: w) = inr (lower ∘ Word=-out)
Word-has-dec-eq (x inv:: v) nil = inr (lower ∘ Word=-out)
Word-has-dec-eq (x inv:: v) (y :: w) = inr (lower ∘ Word=-out)
Word-has-dec-eq (x inv:: v) (y inv:: w) with (dec x y)
Word-has-dec-eq (x inv:: v) (y inv:: w) | inl x=y with (Word-has-dec-eq v w)
Word-has-dec-eq (x inv:: v) (y inv:: w) | inl x=y | inl v=w = inl (Word=-in (x=y , v=w))
Word-has-dec-eq (x inv:: v) (y inv:: w) | inl x=y | inr v≠w = inr (v≠w ∘ Word-snd=')
Word-has-dec-eq (x inv:: v) (y inv:: w) | inr x≠y = inr (x≠y ∘ Word-fst=')
Word-is-set : is-set Word
Word-is-set = dec-eq-is-set Word-has-dec-eq
is-reduced-is-prop : (w : Word) → is-prop (is-reduced w)
is-reduced-is-prop nil = Lift-level Unit-is-prop
is-reduced-is-prop (x :: nil) = Lift-level Unit-is-prop
is-reduced-is-prop (x :: y :: w) = is-reduced-is-prop (y :: w)
is-reduced-is-prop (x :: y inv:: w) =
×-level (Π-is-prop (λ _ → λ ())) (is-reduced-is-prop (y inv:: w))
is-reduced-is-prop (x inv:: nil) = Lift-level Unit-is-prop
is-reduced-is-prop (x inv:: y :: w) =
×-level (Π-is-prop (λ _ → λ ())) (is-reduced-is-prop (y :: w))
is-reduced-is-prop (x inv:: y inv:: w) = is-reduced-is-prop (y inv:: w)
ReducedWord-is-set : is-set ReducedWord
ReducedWord-is-set = subtype-level Word-is-set is-reduced-is-prop
ReducedWord= : ReducedWord → ReducedWord → Type i
ReducedWord= = subtype=
ReducedWord=-in : {x y : ReducedWord} → ReducedWord= x y → x == y
ReducedWord=-in = subtype=-in is-reduced-is-prop
|
{
"alphanum_fraction": 0.5427422058,
"avg_line_length": 44.5223880597,
"ext": "agda",
"hexsha": "f9d0aede8a1b1e3d339b476a3eb8ab8b3f332b7d",
"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": "algebra/ReducedWord.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": "algebra/ReducedWord.agda",
"max_line_length": 90,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "algebra/ReducedWord.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": 1152,
"size": 2983
}
|
{-# OPTIONS --no-termination-check
#-}
------------------------------------------------------------------------
-- Examples
------------------------------------------------------------------------
module RecursiveDescent.Coinductive.Examples where
open import Data.List
open import Data.Nat
open import Data.Bool
open import Data.Product.Record
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
import Data.Char as C
import Data.String as S
open C using (Char)
open S using (String)
open import RecursiveDescent.Coinductive
open import Utilities
open import RecursiveDescent.Coinductive.Lib
open Sym C.decSetoid
-- A function used to simplify the examples a little.
_∈?_ : forall {i r} -> String -> Parser Char i r -> List r
s ∈? p = parse-complete p (S.toList s)
{-
module Ex₀ where
-- This is not well-typed.
p : Parser Char _ String
p ~ return 5 ⊛> p
-}
module Ex₁ where
-- e ∷= 0 + e | 0
e ~ sym '0' ⊛> sym '+' ⊛> e
∣ sym '0'
ex₁ : "0+0" ∈? e ≡ '0' ∷ []
ex₁ = refl
module Ex₂ where
-- e ∷= f + e | f
-- f ∷= 0 | 0 * f | ( e )
mutual
expr ~ factor ⊛> sym '+' ⊛> expr
∣ factor
factor ~ sym '0'
∣ sym '0' ⊛> sym '*' ⊛> factor
∣ sym '(' ⊛> expr <⊛ sym ')'
ex₁ : "(0*)" ∈? expr ≡ []
ex₁ = refl
ex₂ : "0*(0+0)" ∈? expr ≡ '0' ∷ []
ex₂ = refl
{-
module Ex₃ where
-- This is not allowed:
-- e ∷= f + e | f
-- f ∷= 0 | f * 0 | ( e )
mutual
expr = factor ⊛> sym '+' ⊛> expr
∣ factor
factor = sym '0'
∣ factor ⊛> sym '*' ⊛> sym '0'
∣ sym '(' ⊛> expr <⊛ sym ')'
-}
module Ex₄ where
-- The language aⁿbⁿcⁿ, which is not context free.
-- The non-terminal top returns the number of 'a' characters parsed.
-- top ∷= aⁿbⁿcⁿ
-- as n ∷= aˡ⁺¹bⁿ⁺ˡ⁺¹cⁿ⁺ˡ⁺¹
-- bcs x n ∷= xⁿ⁺¹
bcs : Char -> ℕ -> Parser Char _ ℕ
bcs c zero = sym c ⊛> return 0
bcs c (suc n) = sym c ⊛> bcs c n
as : ℕ -> Parser Char _ ℕ
as n ~ suc <$ sym 'a' ⊛
( as (suc n)
∣ _+_ <$> bcs 'b' n ⊛ bcs 'c' n
)
top = return 0 ∣ as zero
ex₁ : "aaabbbccc" ∈? top ≡ 3 ∷ []
ex₁ = refl
ex₂ : "aaabbccc" ∈? top ≡ []
ex₂ = refl
module Ex₅ where
-- A grammar making use of a parameterised parser from the library.
a = sym 'a'
as = length <$> a ⋆
ex₁ : "aaaaa" ∈? as ≡ 5 ∷ []
ex₁ = refl
module Ex₆ where
-- A grammar which uses the chain₁ combinator.
op = _+_ <$ sym '+'
∣ _*_ <$ sym '*'
∣ _∸_ <$ sym '∸'
expr : Assoc -> Parser Char _ ℕ
expr a = chain₁ a number op
ex₁ : "12345" ∈? number ≡ 12345 ∷ []
ex₁ = refl
ex₂ : "1+5*2∸3" ∈? expr left ≡ 9 ∷ []
ex₂ = refl
ex₃ : "1+5*2∸3" ∈? expr right ≡ 1 ∷ []
ex₃ = refl
module Ex₇ where
-- A proper expression example.
addOp = _+_ <$ sym '+'
∣ _∸_ <$ sym '∸'
mulOp = _*_ <$ sym '*'
mutual
expr ~ chain₁ left term addOp
term ~ chain₁ left factor mulOp
factor ~ sym '(' ⊛> expr <⊛ sym ')'
∣ number
ex₁ : "1+5*2∸3" ∈? expr ≡ 8 ∷ []
ex₁ = refl
ex₂ : "1+5*(2∸3)" ∈? expr ≡ 1 ∷ []
ex₂ = refl
|
{
"alphanum_fraction": 0.5017622557,
"avg_line_length": 18.9151515152,
"ext": "agda",
"hexsha": "d2179f6f6512ab064f5f3b4142e1e7dabd76ddce",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/RecursiveDescent/Coinductive/Examples.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/RecursiveDescent/Coinductive/Examples.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/RecursiveDescent/Coinductive/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 1168,
"size": 3121
}
|
-- The debug output should include the text "Termination checking
-- mutual block MutId 0" once, not three times.
{-# OPTIONS -vterm.mutual.id:40 #-}
open import Agda.Builtin.Nat
record R : Set₁ where
field
A : Set
f0 : Nat → Nat
f0 zero = zero
f0 (suc n) = f0 n
f1 : Nat → Nat
f1 zero = zero
f1 (suc n) = f1 n
f2 : Nat → Nat
f2 zero = zero
f2 (suc n) = f2 n
-- Included in order to make the code fail to type-check.
Bad : Set
Bad = Set
|
{
"alphanum_fraction": 0.6150627615,
"avg_line_length": 17.0714285714,
"ext": "agda",
"hexsha": "62714781123051e7ba048148ab5f6cc32f444c6f",
"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/Issue3590-2.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/Issue3590-2.agda",
"max_line_length": 65,
"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/Issue3590-2.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": 171,
"size": 478
}
|
-- Andreas, 2013-11-07
-- Instance candidates are now considered modulo judgemental equality.
module Issue899 where
postulate
A B : Set
f : {{ x : A }} → B
instance a : A
instance
a' : A
a' = a
test : B
test = f
{- The previous code fails with the following message:
Resolve implicit argument _x_257 : A. Candidates: [a : A, a : A]
There are indeed two values in scope of type A (a and a'), but given
that they are definitionally equal, Agda should not complain about it
but just pick any one of them. -}
-- Andreas, 2017-07-28: the other example now also works, thanks to G. Brunerie
record Eq (A : Set) : Set₁ where
field
_==_ : A → A → Set
record Ord (A : Set) : Set₁ where
field
{{eq}} : Eq A
_<_ : A → A → Set
postulate
N : Set
eqN : N → N → Set
ordN : N → N → Set
instance
EqN : Eq N
EqN = record {_==_ = eqN}
OrdN : Ord N
OrdN = record {_<_ = ordN}
ordToEq : {A : Set} → Ord A → Eq A
ordToEq o = Ord.eq o
postulate
f2 : (A : Set) {{e : Eq A}} → Set → Set
test2 = f2 N N
|
{
"alphanum_fraction": 0.6142034549,
"avg_line_length": 18.6071428571,
"ext": "agda",
"hexsha": "0dbc72c2f9fa975a98a02b696ac8b18e4e77ffbd",
"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/Issue899.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/Issue899.agda",
"max_line_length": 79,
"max_stars_count": 1,
"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/Issue899.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 360,
"size": 1042
}
|
variable
X : Set
postulate
foo : ∀ A -> X -- error at `src/full/Agda/TypeChecking/Monad/MetaVars.hs:98`
-- expected: `{X : Set} -> _1 -> X`
Y : Set
bar : ∀ A -> Y -- normal `_1 -> Y` type with unsolved metavar
|
{
"alphanum_fraction": 0.5308641975,
"avg_line_length": 24.3,
"ext": "agda",
"hexsha": "8f4ec3a0b305e6d3d14f310fc62894a38e068652",
"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/Issue3157.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/Issue3157.agda",
"max_line_length": 80,
"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/Issue3157.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": 243
}
|
-- Andreas, 2012-09-15
-- Positive effects of making Agda recognize constant functions.
-- Arguments to constant functions are ignored in definitional equality.
{-# OPTIONS --copatterns #-}
module NonvariantPolarity where
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
constructor trivial
data Bool : Set where
true false : Bool
True : Bool → Set
True true = ⊤
True false = ⊥
module IgnoreArg where
-- A function ignoring its first argument
knot : Bool → Bool → Bool
knot x true = false
knot x false = true
test : (y : Bool) → knot true y ≡ knot false y
test y = refl
module UnusedModulePar where
-- An unused module parameter
module M (x : Bool) where
not : Bool → Bool
not true = false
not false = true
open M true
open M false renaming (not to not′)
test : (y : Bool) → not y ≡ not′ y
test y = refl
module Absurd where
-- Absurd patterns do not count as matches; abort is constant in its 2nd arg.
abort : (A : Set) → ⊥ → A
abort A ()
test : (x y : ⊥) → abort Bool x ≡ abort Bool y
test x y = refl
module ProofIrrelevance where
-- Record and absurd patterns do not count as match.
fun : (b : Bool) → True b → Bool
fun true trivial = true
fun false ()
-- This gives us a kind of proof irrelevance.
test : (b : Bool) → (x y : True b) → fun b x ≡ fun b y
test b x y = refl
module CoinductiveUnit where
record Unit : Set where
coinductive
constructor delay
field force : Unit
open Unit
-- The identity on Unit does not match on its argument, so it is constant.
id : Unit → Unit
force (id x) = id (force x)
idConst : (x y : Unit) → id x ≡ id y
idConst x y = refl
-- That does not imply x ≡ y (needs bisimulation).
|
{
"alphanum_fraction": 0.654109589,
"avg_line_length": 21.3658536585,
"ext": "agda",
"hexsha": "781e0e82139ebf59070138bcf9e6b226166a1ed2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/NonvariantPolarity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/NonvariantPolarity.agda",
"max_line_length": 79,
"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/Succeed/NonvariantPolarity.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": 520,
"size": 1752
}
|
{-# OPTIONS --cubical --safe --guardedness #-}
module Issue3564-2 where
open import Issue3564
|
{
"alphanum_fraction": 0.7113402062,
"avg_line_length": 16.1666666667,
"ext": "agda",
"hexsha": "d29e22a06e747004c19709f453a9bb67cdb83f07",
"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/Issue3564-2.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/Issue3564-2.agda",
"max_line_length": 47,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3564-2.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": 27,
"size": 97
}
|
-- Andreas, 2016-08-08, issue #2131 reported by Andrea
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS --show-irrelevant #-}
-- {-# OPTIONS -v tc:25 #-}
postulate
A : Set
P : (F : .(U : Set) → Set) → Set
const : (X : Set) .(Y : Set) → Set
const X Y = X
works : (G : .(Z : Set) → Set) (p : P G) → P (λ V → const (G _) V) -- V is irrelevant
works G p = p
irr : (G : .(Z : Set) → Set) (p : P G) → P (const (G {!!}))
irr G p = p
-- Agda computes as follows:
-- P G =? P (const (G (?0 G p))) : Set
-- G =? const (G (?0 G p)) : .(U : Set) → Set
-- G U =? const (G (?0 G p)) U : Set
-- G U =? G (?0 G p)
-- ?0 G p := U
-- This assignment fails, since U is not in scope of ?0
-- However, since ?0 is in irrelevant context, this should not be
-- a definite failure, but leave the meta unsolved.
|
{
"alphanum_fraction": 0.5264452645,
"avg_line_length": 27.1,
"ext": "agda",
"hexsha": "7db79af0d3e85b50b2e5758765c3ce706a071ad6",
"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/Issue2131.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/Issue2131.agda",
"max_line_length": 85,
"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/Issue2131.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": 307,
"size": 813
}
|
module Lec5 where
open import Lec1Done
open import Lec2Done
open import Lec3Done
data List (X : Set) : Set where -- BUILTIN insists on level polymorphism
[] : List X
_,-_ : (x : X)(xs : List X) -> List X
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _,-_ #-}
{-# COMPILE GHC List = data [] ([] | (:)) #-}
list : {X Y : Set} -> (X -> Y) -> List X -> List Y
list f [] = []
list f (x ,- xs) = f x ,- list f xs
data Two : Set where ff tt : Two
{-# BUILTIN BOOL Two #-}
{-# BUILTIN FALSE ff #-}
{-# BUILTIN TRUE tt #-}
----------------------------------------------------------------------------
-- chars and strings
----------------------------------------------------------------------------
postulate -- this means that we just suppose the following things exist...
Char : Set
String : Set
{-# BUILTIN CHAR Char #-}
{-# BUILTIN STRING String #-}
primitive -- these are baked in; they even work!
primCharEquality : Char -> Char -> Two
primStringAppend : String -> String -> String
primStringToList : String -> List Char
primStringFromList : List Char -> String
---------------------------------------------------------------------------
-- COLOURS
---------------------------------------------------------------------------
-- We're going to be making displays from coloured text.
data Colour : Set where
black red green yellow blue magenta cyan white : Colour
{-# COMPILE GHC Colour = data HaskellSetup.Colour (HaskellSetup.Black | HaskellSetup.Red | HaskellSetup.Green | HaskellSetup.Yellow | HaskellSetup.Blue | HaskellSetup.Magenta | HaskellSetup.Cyan | HaskellSetup.White) #-}
record _**_ (S T : Set) : Set where
constructor _,_
field
outl : S
outr : T
open _**_
{-# COMPILE GHC _**_ = data (,) ((,)) #-}
infixr 4 _**_ _,_
{- Here's the characterization of keys I give you -}
data Direction : Set where up down left right : Direction
data Modifier : Set where normal shift control : Modifier
data Key : Set where
char : Char -> Key
arrow : Modifier -> Direction -> Key
enter : Key
backspace : Key
delete : Key
escape : Key
tab : Key
data Event : Set where
key : (k : Key) -> Event
resize : (w h : Nat) -> Event
{- This type collects the things you're allowed to do with the text window. -}
data Action : Set where
goRowCol : Nat -> Nat -> Action -- send the cursor somewhere
sendText : List Char -> Action -- send some text
move : Direction -> Nat -> Action -- which way and how much
fgText : Colour -> Action
bgText : Colour -> Action
{- I wire all of that stuff up to its Haskell counterpart. -}
{-# FOREIGN GHC import qualified ANSIEscapes #-}
{-# FOREIGN GHC import qualified HaskellSetup #-}
{-# COMPILE GHC Direction = data ANSIEscapes.Dir (ANSIEscapes.DU | ANSIEscapes.DD | ANSIEscapes.DL | ANSIEscapes.DR) #-}
{-# COMPILE GHC Modifier = data HaskellSetup.Modifier (HaskellSetup.Normal | HaskellSetup.Shift | HaskellSetup.Control) #-}
{-# COMPILE GHC Key = data HaskellSetup.Key (HaskellSetup.Char | HaskellSetup.Arrow | HaskellSetup.Enter | HaskellSetup.Backspace | HaskellSetup.Delete | HaskellSetup.Escape | HaskellSetup.Tab) #-}
{-# COMPILE GHC Event = data HaskellSetup.Event (HaskellSetup.Key | HaskellSetup.Resize) #-}
{-# COMPILE GHC Action = data HaskellSetup.Action (HaskellSetup.GoRowCol | HaskellSetup.SendText | HaskellSetup.Move | HaskellSetup.FgText | HaskellSetup.BgText) #-}
data ColourChar : Set where
_-_/_ : (fg : Colour)(c : Char)(bg : Colour) -> ColourChar
-- ... e.g. green - '*' / black for a green * on black.
Matrix : Set -> Nat * Nat -> Set
Matrix C (w , h) = Vec (Vec C w) h
Painting : Nat * Nat -> Set
Painting = Matrix ColourChar
vecFoldR : {X Y : Set} -> (X -> Y -> Y) -> Y -> {n : Nat} -> Vec X n -> Y
vecFoldR c n [] = n
vecFoldR c n (x ,- xs) = c x (vecFoldR c n xs)
paintAction : {wh : Nat * Nat} -> Matrix ColourChar wh -> List Action
paintAction = vecFoldR (vecFoldR (\ {(f - c / b) k -> \ as ->
fgText f ,- bgText b ,- sendText (c ,- []) ,- k as}) id) []
postulate -- Haskell has a monad for doing IO, which we use at the top level
IO : Set -> Set
return : {A : Set} -> A -> IO A
_>>=_ : {A B : Set} -> IO A -> (A -> IO B) -> IO B
infixl 1 _>>=_
{-# BUILTIN IO IO #-}
{-# COMPILE GHC IO = type IO #-}
{-# COMPILE GHC return = (\ _ -> return) #-}
{-# COMPILE GHC _>>=_ = (\ _ _ -> (>>=)) #-}
---------------------------------------------------------------------------
-- APPLICATIONS --
---------------------------------------------------------------------------
-- Here's a general idea of what it means to be an "application".
-- You need to choose some sort of size-dependent state, then provide these
-- bits and pieces. We need to know how the state is updated according to
-- events, with resizing potentially affecting the state's type. We must
-- be able to paint the state. The state should propose a cursor position.
-- (Keen students may modify this definition to ensure the cursor must be
-- within the bounds of the application.)
record Application (wh : Nat * Nat) : Set where
coinductive
field
handleKey : Key -> Application wh
handleResize : (wh' : Nat * Nat) -> Application wh'
paintMe : Painting wh
cursorMe : Nat * Nat -- x,y coords
open Application public
-- Now your turn. Build the appropriate handler to connect these
-- applications with mainAppLoop. Again, work in two stages, first
-- figuring out how to do the right actions, then managing the
-- state properly. (1 mark)
_+L_ : {X : Set} -> List X -> List X -> List X
[] +L ys = ys
(x ,- xs) +L ys = x ,- (xs +L ys)
infixr 3 _+L_
APP : Set
APP = Sg (Nat * Nat) Application
appPaint : APP -> List Action
appPaint (_ , app) =
goRowCol 0 0 ,- paintAction p
-- must have composition here, to work around compiler bug
-- paintAction (paintMatrix p)
-- segfaults, because p is erased
+L (goRowCol (snd xy) (fst xy) ,- [])
where
p = paintMe app
xy = cursorMe app
appHandler : Event -> APP -> APP ** List Action
appHandler (key k) (wh , app) = app' , appPaint app'
where
app' : APP
app' = _ , handleKey app k
appHandler (resize w h) (wh , app) = app' , appPaint app'
where
app' : APP
app' = _ , handleResize app (w , h)
{- This is the bit of code I wrote in Haskell to animate your code. -}
postulate
mainAppLoop : {S : Set} -> -- program state
-- INITIALIZER
S -> -- initial state
-- EVENT HANDLER
(Event -> S -> -- event and state in
S ** List Action) -> -- new state and screen actions out
-- PUT 'EM TOGETHER AND YOU'VE GOT AN APPLICATION!
IO One
{-# COMPILE GHC mainAppLoop = (\ _ -> HaskellSetup.mainAppLoop) #-}
appMain : (forall wh -> Application wh) -> IO One
appMain app = mainAppLoop ((0 , 0) , app (0 , 0)) appHandler
-- will get resized dynamically to size of terminal, first thing
vPure : {n : Nat}{X : Set} -> X -> Vec X n
vPure {zero} x = []
vPure {suc n} x = x ,- vPure x
rectApp : Char -> forall wh -> Application wh
handleKey (rectApp c wh) (char x) = rectApp x wh
handleKey (rectApp c wh) _ = rectApp c wh
handleResize (rectApp c _) wh = rectApp c wh
paintMe (rectApp c wh) = vPure (vPure (green - c / black))
cursorMe (rectApp c wh) = wh
main : IO One
main = appMain (rectApp '*')
-- agda --compile --ghc-flag "-lncurses" Lec5.agda
|
{
"alphanum_fraction": 0.5869536511,
"avg_line_length": 35.5539906103,
"ext": "agda",
"hexsha": "c2d17a528560997d58645ac4aca852be134130c3",
"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/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec5.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/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec5.agda",
"max_line_length": 220,
"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/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec5.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": 2038,
"size": 7573
}
|
open import Agda.Builtin.Size
postulate
X : Set
P : X → Set
Q : (x : X) → P x → Set
data D (i : Size) : Set where
c : D i
f : (i : Size) → D i → X
f i c = {!!}
g : (x : X) (y : P x) → Q x y → Q x y
g _ _ q = q
h : (i : Size) (n : D i) → P (f i n)
h _ c = {!!}
k : (n : D ∞) → Q (f ∞ n) (h ∞ n)
k _ = g _ (h _ {!!}) _
|
{
"alphanum_fraction": 0.3987915408,
"avg_line_length": 15.0454545455,
"ext": "agda",
"hexsha": "d348721978461bf3b2d96ca240e1b99b590f716f",
"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/interaction/Issue2881.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/interaction/Issue2881.agda",
"max_line_length": 37,
"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/interaction/Issue2881.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": 162,
"size": 331
}
|
{-# OPTIONS --without-K #-}
module ConcretePermutation where
import Level using (zero)
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Fin using (Fin; zero; suc; inject+; raise)
open import Data.Sum
using (_⊎_; inj₁; inj₂; [_,_]′)
renaming (map to map⊎)
open import Data.Product using (_×_; proj₁; proj₂; _,′_)
open import Data.Vec
using (Vec; _∷_; []; tabulate; _>>=_; allFin)
renaming (_++_ to _++V_; map to mapV; concat to concatV)
open import Data.Vec.Properties
using (lookup-allFin; tabulate∘lookup; lookup∘tabulate; lookup-++-inject+;
tabulate-∘)
open import Function using (_∘_; id)
open import Algebra using (CommutativeSemiring)
open import Algebra.Structures using
(IsSemigroup; IsCommutativeMonoid; IsCommutativeSemiring)
open import Relation.Binary using (IsEquivalence)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans;
cong; cong₂; module ≡-Reasoning; proof-irrelevance)
open import Proofs using (
-- FiniteFunctions
finext;
-- VectorLemmas
lookup-++-raise; lookupassoc; tabulate-split; _!!_; unSplit;
concat-map; map-map-map; lookup-map; map-∘;
left!!; right!!
)
open import FinVec -- using ()
open import FinVecProperties -- using ()
------------------------------------------------------------------------------
-- a concrete permutation has 4 components:
-- - the permutation
-- - its inverse
-- - and 2 proofs that it is indeed inverse
record CPerm (values : ℕ) (size : ℕ) : Set where
constructor cp
field
π : FinVec values size
πᵒ : FinVec size values
αp : π ∘̂ πᵒ ≡ 1C
βp : πᵒ ∘̂ π ≡ 1C
πᵒ≡ : ∀ {m n} → (π₁ π₂ : CPerm m n) → (CPerm.π π₁ ≡ CPerm.π π₂) →
(CPerm.πᵒ π₁ ≡ CPerm.πᵒ π₂)
πᵒ≡ {n} (cp π πᵒ αp βp) (cp .π πᵒ₁ αp₁ βp₁) refl =
begin (
πᵒ ≡⟨ sym (∘̂-rid πᵒ) ⟩
πᵒ ∘̂ 1C ≡⟨ cong (_∘̂_ πᵒ) (sym αp₁) ⟩
πᵒ ∘̂ (π ∘̂ πᵒ₁) ≡⟨ ∘̂-assoc πᵒ π πᵒ₁ ⟩
(πᵒ ∘̂ π) ∘̂ πᵒ₁ ≡⟨ cong (λ x → x ∘̂ πᵒ₁) βp ⟩
1C ∘̂ πᵒ₁ ≡⟨ ∘̂-lid πᵒ₁ ⟩
πᵒ₁ ∎)
where open ≡-Reasoning
p≡ : ∀ {m n} → {π₁ π₂ : CPerm m n} → (CPerm.π π₁ ≡ CPerm.π π₂) → π₁ ≡ π₂
p≡ {m} {n} {cp π πᵒ αp βp} {cp .π πᵒ₁ αp₁ βp₁} refl with
πᵒ≡ (cp π πᵒ αp βp) (cp π πᵒ₁ αp₁ βp₁) refl
p≡ {m} {n} {cp π πᵒ αp βp} {cp .π .πᵒ αp₁ βp₁} refl | refl
with proof-irrelevance αp αp₁ | proof-irrelevance βp βp₁
p≡ {m} {n} {cp π πᵒ αp βp} {cp .π .πᵒ .αp .βp} refl | refl | refl | refl = refl
idp : ∀ {n} → CPerm n n
idp {n} = cp 1C 1C (∘̂-rid _) (∘̂-lid _)
symp : ∀ {m n} → CPerm m n → CPerm n m
symp (cp p₁ p₂ α β) = cp p₂ p₁ β α
transp : ∀ {m₁ m₂ m₃} → CPerm m₂ m₁ → CPerm m₃ m₂ → CPerm m₃ m₁
transp {n} (cp π πᵒ αp βp) (cp π₁ πᵒ₁ αp₁ βp₁) = cp (π ∘̂ π₁) (πᵒ₁ ∘̂ πᵒ) pf₁ pf₂
where
open ≡-Reasoning
pf₁ : (π ∘̂ π₁) ∘̂ (πᵒ₁ ∘̂ πᵒ) ≡ 1C
pf₁ =
begin (
(π ∘̂ π₁) ∘̂ (πᵒ₁ ∘̂ πᵒ) ≡⟨ ∘̂-assoc _ _ _ ⟩
((π ∘̂ π₁) ∘̂ πᵒ₁) ∘̂ πᵒ ≡⟨ cong (λ x → x ∘̂ πᵒ) (sym (∘̂-assoc _ _ _)) ⟩
(π ∘̂ (π₁ ∘̂ πᵒ₁)) ∘̂ πᵒ ≡⟨ cong (λ x → (π ∘̂ x) ∘̂ πᵒ) (αp₁) ⟩
(π ∘̂ 1C) ∘̂ πᵒ ≡⟨ cong (λ x → x ∘̂ πᵒ) (∘̂-rid _) ⟩
π ∘̂ πᵒ ≡⟨ αp ⟩
1C ∎)
pf₂ : (πᵒ₁ ∘̂ πᵒ) ∘̂ (π ∘̂ π₁) ≡ 1C
pf₂ =
begin (
(πᵒ₁ ∘̂ πᵒ) ∘̂ (π ∘̂ π₁) ≡⟨ ∘̂-assoc _ _ _ ⟩
((πᵒ₁ ∘̂ πᵒ) ∘̂ π) ∘̂ π₁ ≡⟨ cong (λ x → x ∘̂ π₁) (sym (∘̂-assoc _ _ _)) ⟩
(πᵒ₁ ∘̂ (πᵒ ∘̂ π)) ∘̂ π₁ ≡⟨ cong (λ x → (πᵒ₁ ∘̂ x) ∘̂ π₁) βp ⟩
(πᵒ₁ ∘̂ 1C) ∘̂ π₁ ≡⟨ cong (λ x → x ∘̂ π₁) (∘̂-rid _) ⟩
πᵒ₁ ∘̂ π₁ ≡⟨ βp₁ ⟩
1C ∎)
-- zero permutation
0p : CPerm 0 0
0p = idp {0}
_⊎p_ : ∀ {m₁ m₂ n₁ n₂} → CPerm m₁ m₂ → CPerm n₁ n₂ → CPerm (m₁ + n₁) (m₂ + n₂)
_⊎p_ {m₁} {m₂} {n₁} {n₂} π₀ π₁ =
cp ((π π₀) ⊎c (π π₁)) ((πᵒ π₀) ⊎c (πᵒ π₁)) pf₁ pf₂
where
open CPerm
open ≡-Reasoning
pf₁ : (π π₀ ⊎c π π₁) ∘̂ (πᵒ π₀ ⊎c πᵒ π₁) ≡ 1C
pf₁ =
begin (
(π π₀ ⊎c π π₁) ∘̂ (πᵒ π₀ ⊎c πᵒ π₁)
≡⟨ ⊎c-distrib {p₁ = π π₀} ⟩
(π π₀ ∘̂ πᵒ π₀) ⊎c (π π₁ ∘̂ πᵒ π₁)
≡⟨ cong₂ _⊎c_ (αp π₀) (αp π₁) ⟩
1C {m₂} ⊎c 1C {n₂}
≡⟨ 1C⊎1C≡1C {m₂} ⟩
1C ∎)
pf₂ : (πᵒ π₀ ⊎c πᵒ π₁) ∘̂ (π π₀ ⊎c π π₁) ≡ 1C
pf₂ =
begin (
(πᵒ π₀ ⊎c πᵒ π₁) ∘̂ (π π₀ ⊎c π π₁)
≡⟨ ⊎c-distrib {p₁ = πᵒ π₀} ⟩
(πᵒ π₀ ∘̂ π π₀) ⊎c (πᵒ π₁ ∘̂ π π₁)
≡⟨ cong₂ _⊎c_ (βp π₀) (βp π₁) ⟩
1C {m₁} ⊎c 1C {n₁}
≡⟨ 1C⊎1C≡1C {m₁} ⟩
1C ∎ )
-- For the rest of the permutations, it is convenient to lift things from
-- FinVec in one go; but don't use it yet, it makes other things fall apart
{--
mkPerm : {m n : ℕ} (eq : Fin m ≃ Fin n) → CPerm m n
mkPerm {m} {n} eq = cp p q p∘̂q≡1 q∘̂p≡1
where
f = proj₁ eq
g = proj₁ (sym≃ eq)
p = tabulate g -- note the flip!
q = tabulate f
q∘̂p≡1 = ~⇒≡ {f = g} {g = f} (p∘!p≡id {p = eq})
p∘̂q≡1 = ~⇒≡ {f = f} {g = g} (p∘!p≡id {p = sym≃ eq})
--}
unite+p : {m : ℕ} → CPerm m (0 + m)
unite+p {m} =
cp (unite+ {m}) (uniti+ {m}) (unite+∘̂uniti+~id {m}) (uniti+∘̂unite+~id {m})
uniti+p : {m : ℕ} → CPerm (0 + m) m
uniti+p {m} = symp (unite+p {m})
unite+rp : {m : ℕ} → CPerm m (m + 0)
unite+rp {m} =
cp (unite+r {m}) (uniti+r) (unite+r∘̂uniti+r~id) (uniti+r∘̂unite+r~id)
uniti+rp : {m : ℕ} → CPerm (m + 0) m
uniti+rp {m} = symp (unite+rp {m})
assocl+p : {m n o : ℕ} → CPerm ((m + n) + o) (m + (n + o))
assocl+p {m} =
cp
(assocl+ {m}) (assocr+ {m})
(assocl+∘̂assocr+~id {m}) (assocr+∘̂assocl+~id {m})
assocr+p : {m n o : ℕ} → CPerm (m + (n + o)) ((m + n) + o)
assocr+p {m} = symp (assocl+p {m})
swap+p : {m n : ℕ} → CPerm (n + m) (m + n)
swap+p {m} {n} =
cp (swap+cauchy m n) (swap+cauchy n m) (swap+-inv {m}) (swap+-inv {n})
unite*p : {m : ℕ} → CPerm m (1 * m)
unite*p {m} =
cp (unite* {m}) (uniti* {m}) (unite*∘̂uniti*~id {m}) (uniti*∘̂unite*~id {m})
uniti*p : {m : ℕ} → CPerm (1 * m) m
uniti*p {m} = symp (unite*p {m})
unite*rp : {m : ℕ} → CPerm m (m * 1)
unite*rp {m} =
cp
(unite*r {m}) (uniti*r {m})
(unite*r∘̂uniti*r~id {m}) (uniti*r∘̂unite*r~id {m})
uniti*rp : {m : ℕ} → CPerm (m * 1) m
uniti*rp {m} = symp (unite*rp {m})
swap*p : {m n : ℕ} → CPerm (n * m) (m * n)
swap*p {m} {n} =
cp (swap⋆cauchy m n) (swap⋆cauchy n m) (swap*-inv {m}) (swap*-inv {n})
assocl*p : {m n o : ℕ} → CPerm ((m * n) * o) (m * (n * o))
assocl*p {m} =
cp
(assocl* {m}) (assocr* {m})
(assocl*∘̂assocr*~id {m}) (assocr*∘̂assocl*~id {m})
assocr*p : {m n o : ℕ} → CPerm (m * (n * o)) ((m * n) * o)
assocr*p {m} = symp (assocl*p {m})
_×p_ : ∀ {m₁ m₂ n₁ n₂} → CPerm m₁ m₂ → CPerm n₁ n₂ → CPerm (m₁ * n₁) (m₂ * n₂)
_×p_ {m₁} {m₂} {n₁} {n₂} π₀ π₁ =
cp ((π π₀) ×c (π π₁)) ((πᵒ π₀) ×c (πᵒ π₁)) pf₁ pf₂
where
open CPerm
open ≡-Reasoning
pf₁ : (π π₀ ×c π π₁) ∘̂ (πᵒ π₀ ×c πᵒ π₁) ≡ 1C
pf₁ =
begin (
(π π₀ ×c π π₁) ∘̂ (πᵒ π₀ ×c πᵒ π₁) ≡⟨ ×c-distrib {p₁ = π π₀} ⟩
(π π₀ ∘̂ πᵒ π₀) ×c (π π₁ ∘̂ πᵒ π₁) ≡⟨ cong₂ _×c_ (αp π₀) (αp π₁) ⟩
1C ×c 1C ≡⟨ 1C×1C≡1C ⟩
1C ∎)
pf₂ : (πᵒ π₀ ×c πᵒ π₁) ∘̂ (π π₀ ×c π π₁) ≡ 1C
pf₂ =
begin (
(πᵒ π₀ ×c πᵒ π₁) ∘̂ (π π₀ ×c π π₁) ≡⟨ ×c-distrib {p₁ = πᵒ π₀} ⟩
(πᵒ π₀ ∘̂ π π₀) ×c (πᵒ π₁ ∘̂ π π₁) ≡⟨ cong₂ _×c_ (βp π₀) (βp π₁) ⟩
1C ×c 1C ≡⟨ 1C×1C≡1C ⟩
1C ∎)
distp : {m n o : ℕ} → CPerm (m * o + n * o) ((m + n) * o)
distp {m} {n} {o} =
cp
(dist*+ {m}) (factor*+ {m})
(dist*+∘̂factor*+~id {m}) (factor*+∘̂dist*+~id {m})
factorp : {m n o : ℕ} → CPerm ((m + n) * o) (m * o + n * o)
factorp {m} = symp (distp {m})
distlp : {m n o : ℕ} → CPerm (m * n + m * o) (m * (n + o))
distlp {m} {n} {o} =
cp
(distl*+ {m}) (factorl*+ {m})
(distl*+∘̂factorl*+~id {m}) (factorl*+∘̂distl*+~id {m})
factorlp : {m n o : ℕ} → CPerm (m * (n + o)) (m * n + m * o)
factorlp {m} = symp (distlp {m})
-- right-zero absorbing permutation
0pr : ∀ {n} → CPerm 0 (n * 0)
0pr {n} =
cp
(right-zero*l {n}) (right-zero*r {n})
(right-zero*l∘̂right-zero*r~id {n}) (right-zero*r∘̂right-zero*l~id {n})
-- and its symmetric version
0pl : ∀ {n} → CPerm (n * 0) 0
0pl {n} = symp (0pr {n})
--
ridp : ∀ {m₁ m₂} {p : CPerm m₂ m₁} → transp p idp ≡ p
ridp {p = p} = p≡ (∘̂-rid (CPerm.π p))
lidp : ∀ {m₁ m₂} {p : CPerm m₂ m₁} → transp idp p ≡ p
lidp {p = p} = p≡ (∘̂-lid (CPerm.π p))
assocp : ∀ {m₁ m₂ m₃ n₁} → {p₁ : CPerm m₁ n₁} → {p₂ : CPerm m₂ m₁} →
{p₃ : CPerm m₃ m₂} →
transp p₁ (transp p₂ p₃) ≡ transp (transp p₁ p₂) p₃
assocp {p₁ = p₁} {p₂} {p₃} =
p≡ (∘̂-assoc (CPerm.π p₁) (CPerm.π p₂) (CPerm.π p₃))
linv : ∀ {m₁ m₂} (p : CPerm m₂ m₁) → transp p (symp p) ≡ idp
linv p = p≡ (CPerm.αp p)
rinv : ∀ {m₁ m₂} (p : CPerm m₂ m₁) → transp (symp p) p ≡ idp
rinv p = p≡ (CPerm.βp p)
transp-resp-≡ : ∀ {m₁ m₂ m₃} {f h : CPerm m₂ m₃} {g i : CPerm m₁ m₂} →
f ≡ h → g ≡ i → transp f g ≡ transp h i
transp-resp-≡ refl refl = refl
1p⊎1p≡1p : ∀ {m n} → idp {m} ⊎p idp {n} ≡ idp
1p⊎1p≡1p {m} = p≡ (1C⊎1C≡1C {m})
1p×1p≡1p : ∀ {m n} → idp {m} ×p idp {n} ≡ idp
1p×1p≡1p {m} = p≡ (1C×1C≡1C {m})
⊎p-distrib : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → {p₁ : CPerm m₁ n₁} → {p₂ : CPerm m₂ n₂}
→ {p₃ : CPerm m₃ m₁} → {p₄ : CPerm m₄ m₂} →
transp (p₁ ⊎p p₂) (p₃ ⊎p p₄) ≡ (transp p₁ p₃) ⊎p (transp p₂ p₄)
⊎p-distrib {p₁ = p₁} = p≡ (⊎c-distrib {p₁ = CPerm.π p₁})
×p-distrib : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → {p₁ : CPerm m₁ n₁} → {p₂ : CPerm m₂ n₂}
→ {p₃ : CPerm m₃ m₁} → {p₄ : CPerm m₄ m₂} →
(transp p₁ p₃) ×p (transp p₂ p₄) ≡ transp (p₁ ×p p₂) (p₃ ×p p₄)
×p-distrib {p₁ = p₁} = p≡ (sym (×c-distrib {p₁ = CPerm.π p₁}))
0p⊎x≡x : ∀ {m n} {p : CPerm m n} → idp {0} ⊎p p ≡ p
0p⊎x≡x {p = p} = p≡ 1C₀⊎x≡x
-- this comes from looking at things categorically:
unite+p∘[0⊎x]≡x∘unite+p : ∀ {m n} (p : CPerm m n) →
transp unite+p (0p ⊎p p) ≡ transp p unite+p
unite+p∘[0⊎x]≡x∘unite+p p = p≡ unite+∘[0⊎x]≡x∘unite+
uniti+p∘x≡[0⊎x]∘uniti+p : ∀ {m n} (p : CPerm m n) →
transp uniti+p p ≡ transp (0p ⊎p p) uniti+p
uniti+p∘x≡[0⊎x]∘uniti+p p = p≡ (uniti+∘x≡[0⊎x]∘uniti+ {x = CPerm.π p})
-- and the right version
{-
unite+rp∘[x⊎0]≡x∘unite+rp : ∀ {m n} (p : CPerm m n) →
transp unite+rp (p ⊎p 0p) ≡ transp p unite+rp
unite+rp∘[x⊎0]≡x∘unite+rp p = p≡ ?
uniti+rp∘[x⊎0]≡x∘uniti+rp : ∀ {m n} (p : CPerm m n) →
transp uniti+rp (p ⊎p 0p) ≡ transp p uniti+rp
uniti+rp∘[x⊎0]≡x∘uniti+rp p = p≡ {!!}
-}
-- SCPerm : ℕ → ℕ → Setoid zero zero
-- SCPerm m n = setoid (CPerm m n)
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4885314552,
"avg_line_length": 32.4290123457,
"ext": "agda",
"hexsha": "5c602b9f660e9e1cfd708ad8ecce04e5ef9e10c9",
"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/Obsolete/ConcretePermutation.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/Obsolete/ConcretePermutation.agda",
"max_line_length": 86,
"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/Obsolete/ConcretePermutation.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": 5759,
"size": 10507
}
|
{-
Reflection-based tools for converting between iterated record types, particularly between
record types and iterated Σ-types. Currently requires eta equality.
See end of file for examples.
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Reflection.RecordEquiv where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.List as List
open import Cubical.Data.Nat
open import Cubical.Data.Maybe
open import Cubical.Data.Sigma
import Agda.Builtin.Reflection as R
open import Cubical.Reflection.Base
Projections = List R.Name
-- Describes a correspondence between two iterated record types
Assoc = List (Projections × Projections)
-- Describes a correspondence between a record type and an iterated Σ-types;
-- more convenient than Assoc for this special case
data ΣFormat : Type where
leaf : R.Name → ΣFormat
_,_ : ΣFormat → ΣFormat → ΣFormat
infixr 4 _,_
module Internal where
flipAssoc : Assoc → Assoc
flipAssoc = List.map λ {p .fst → p .snd; p .snd → p .fst}
list→ΣFormat : List R.Name → Maybe ΣFormat
list→ΣFormat [] = nothing
list→ΣFormat (x ∷ []) = just (leaf x)
list→ΣFormat (x ∷ y ∷ xs) = map-Maybe (leaf x ,_) (list→ΣFormat (y ∷ xs))
recordName→ΣFormat : R.Name → R.TC (Maybe ΣFormat)
recordName→ΣFormat name = R.getDefinition name >>= go
where
go : R.Definition → R.TC (Maybe ΣFormat)
go (R.record-type c fs) = R.returnTC (list→ΣFormat (List.map (λ {(R.arg _ n) → n}) fs))
go _ = R.typeError (R.strErr "Not a record type name:" ∷ R.nameErr name ∷ [])
ΣFormat→Assoc : ΣFormat → Assoc
ΣFormat→Assoc = go []
where
go : List R.Name → ΣFormat → Assoc
go prefix (leaf fieldName) = [ prefix , [ fieldName ] ]
go prefix (sig₁ , sig₂) =
go (quote fst ∷ prefix) sig₁ ++ go (quote snd ∷ prefix) sig₂
MaybeΣFormat→Assoc : Maybe ΣFormat → Assoc
MaybeΣFormat→Assoc nothing = [ [] , [] ]
MaybeΣFormat→Assoc (just sig) = ΣFormat→Assoc sig
convertTerm : Assoc → R.Term → R.Term
convertTerm al term = R.pat-lam (List.map makeClause al) []
where
makeClause : Projections × Projections → R.Clause
makeClause (projl , projr) =
R.clause [] (goPat [] projr) (goTm projl)
where
goPat : List (R.Arg R.Pattern) → List R.Name → List (R.Arg R.Pattern)
goPat acc [] = acc
goPat acc (π ∷ projs) = goPat (varg (R.proj π) ∷ acc) projs
goTm : List R.Name → R.Term
goTm [] = term
goTm (π ∷ projs) = R.def π [ varg (goTm projs) ]
convertFun : Assoc → R.Term
convertFun al = vlam "ρ" (convertTerm al (v 0))
convertMacro : Assoc → R.Term → R.TC Unit
convertMacro al hole = R.unify hole (convertFun al)
equivMacro : Assoc → R.Term → R.TC Unit
equivMacro al hole =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ hole₂ →
let
iso : R.Term
iso =
R.pat-lam
( R.clause [] [ varg (R.proj (quote Iso.fun)) ] hole₁
∷ R.clause [] [ varg (R.proj (quote Iso.inv)) ] hole₂
∷ R.clause [] [ varg (R.proj (quote Iso.rightInv)) ] (vlam "_" (R.def (quote refl) []))
∷ R.clause [] [ varg (R.proj (quote Iso.leftInv)) ] (vlam "_" (R.def (quote refl) []))
∷ []
)
[]
in
R.unify hole (R.def (quote isoToEquiv) [ varg iso ]) >>
convertMacro al hole₁ >>
convertMacro (flipAssoc al) hole₂
open Internal
macro
-- ΣFormat → <Σ-Type> ≃ <RecordType>
Σ≃Record : ΣFormat → R.Term → R.TC Unit
Σ≃Record sig = equivMacro (ΣFormat→Assoc sig)
-- ΣFormat → <RecordType> ≃ <Σ-Type>
Record≃Σ : ΣFormat → R.Term → R.TC Unit
Record≃Σ sig = equivMacro (flipAssoc (ΣFormat→Assoc sig))
-- <RecordTypeName> → <Σ-Type> ≃ <RecordType>
FlatΣ≃Record : R.Name → R.Term → R.TC Unit
FlatΣ≃Record name hole =
recordName→ΣFormat name >>= λ sig →
equivMacro (MaybeΣFormat→Assoc sig) hole
-- <RecordTypeName> → <RecordType> ≃ <Σ-Type>
Record≃FlatΣ : R.Name → R.Term → R.TC Unit
Record≃FlatΣ name hole =
recordName→ΣFormat name >>= λ sig →
equivMacro (flipAssoc (MaybeΣFormat→Assoc sig)) hole
-- ΣFormat → <RecordType₁> ≃ <RecordType₂>
Record≃Record : Assoc → R.Term → R.TC Unit
Record≃Record = equivMacro
module Example where
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ'
record Example {A : Type ℓ} (B : A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
cool : A
fun : A
wow : B cool
open Example
{-
Example: Equivalence between a Σ-type and record type using FlatΣ≃Record
-}
Example0 : (Σ[ a ∈ A ] Σ[ a' ∈ A ] B a) ≃ Example B
Example0 = FlatΣ≃Record Example
Example0' : Example B ≃ (Σ[ a ∈ A ] Σ[ a' ∈ A ] B a)
Example0' = Record≃FlatΣ Example
Example0'' : Unit ≃ Unit -- any record with no fields is equivalent to unit
Example0'' = FlatΣ≃Record Unit
{-
Example: Equivalence between an arbitrarily arrange Σ-type and record type using Σ≃Record
-}
Example1 : (Σ[ p ∈ A × A ] B (p .snd)) ≃ Example B
Example1 =
Σ≃Record ((leaf (quote fun) , leaf (quote cool)) , leaf (quote wow))
{-
Example: Equivalence between arbitrary iterated record types (less convenient) using
Record≃Record
-}
record Inner {A : Type ℓ} (B : A → Type ℓ') (a : A) : Type (ℓ-max ℓ ℓ') where
field
fun' : A
wow' : B a
record Outer {A : Type ℓ} (B : A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
cool' : A
inner : B cool'
open Inner
open Outer
Example2 : Example B ≃ Outer (Inner B)
Example2 =
Record≃Record
( ([ quote cool ] , [ quote cool' ])
∷ ([ quote fun ] , (quote fun' ∷ quote inner ∷ []))
∷ ([ quote wow ] , (quote wow' ∷ quote inner ∷ []))
∷ []
)
|
{
"alphanum_fraction": 0.6239257477,
"avg_line_length": 29.5329949239,
"ext": "agda",
"hexsha": "d054d023aa191431255484b87b08432dfbccd32f",
"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/Reflection/RecordEquiv.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/Reflection/RecordEquiv.agda",
"max_line_length": 97,
"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/Reflection/RecordEquiv.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1917,
"size": 5818
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.