hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
3dc3c916e5d023ba4479f884bd4be3b523c94c07
985
agda
Agda
test/Fail/Issue1428a.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1428a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1428a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-03-16 -- Andreas, 2020-10-26 removed loop during injectivity check {-# OPTIONS --sized-types #-} open import Agda.Builtin.Size -- Note: the assumption of pred is absurd, -- but still should not make Agda loop. module _ (pred : ∀ i → Size< i) where data ⊥ : Set where data SizeLt (i : Size) : Set where wrap : (j : Size< i) → SizeLt i loop : (d : ∀ i → SizeLt i) → ∀ i → SizeLt i → ⊥ loop d i (wrap j) = loop d j (d j) -- -- Loops during injectivity check: -- loop : ∀ i → SizeLt i → ⊥ -- loop i (wrap j) = loop j (wrap (pred j)) d : ∀ i → SizeLt i d i = wrap (pred i) absurd : ⊥ absurd = loop d ∞ (d ∞) _ = FIXME -- Testcase temporarily mutilated, original error: -- -- -Issue1428a.agda:.. -- -Functions may not return sizes, thus, function type -- -(i : Size) → Size< i is illegal -- -when checking that the expression ∀ i → Size< i is a type -- -- +Issue1428a.agda:... -- +Not in scope: -- + FIXME at Issue1428a.agda:... -- +when scope checking FIXME
22.386364
61
0.620305
5846283d41d3cf63c68d7d0a34476ac0f28ea132
364
agda
Agda
test/fail/StronglyRigidOccurrence.agda
dagit/agda
4383a3d20328a6c43689161496cee8eb479aca08
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/fail/StronglyRigidOccurrence.agda
dagit/agda
4383a3d20328a6c43689161496cee8eb479aca08
[ "MIT" ]
null
null
null
test/fail/StronglyRigidOccurrence.agda
dagit/agda
4383a3d20328a6c43689161496cee8eb479aca08
[ "MIT" ]
null
null
null
{-# OPTIONS --allow-unsolved-metas #-} -- The option is supplied to force a real error to pass the regression test. module StronglyRigidOccurrence where data Nat : Set where zero : Nat suc : Nat -> Nat data _≡_ {A : Set}(a : A) : A -> Set where refl : a ≡ a test : let X : Nat; X = _ in X ≡ suc X test = refl -- this gives an error in the occurs checker
24.266667
76
0.653846
060602877b50b42f5ad0aa2016bfd7612db56b69
3,432
agda
Agda
IPC/Metatheory/Gentzen-KripkeExploding.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
IPC/Metatheory/Gentzen-KripkeExploding.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
IPC/Metatheory/Gentzen-KripkeExploding.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module IPC.Metatheory.Gentzen-KripkeExploding where open import IPC.Syntax.Gentzen public open import IPC.Semantics.KripkeExploding public -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A eval (var i) γ = lookup i γ eval (lam {A} {B} t) γ = return {A ▻ B} λ ξ a → eval t (mono⊩⋆ ξ γ , a) eval (app {A} {B} t u) γ = bind {A ▻ B} {B} (eval t γ) λ ξ f → _⟪$⟫_ {A} {B} f (eval u (mono⊩⋆ ξ γ)) eval (pair {A} {B} t u) γ = return {A ∧ B} (eval t γ , eval u γ) eval (fst {A} {B} t) γ = bind {A ∧ B} {A} (eval t γ) (K π₁) eval (snd {A} {B} t) γ = bind {A ∧ B} {B} (eval t γ) (K π₂) eval unit γ = return {⊤} ∙ eval (boom {C} t) γ = bind {⊥} {C} (eval t γ) (K elim𝟘) eval (inl {A} {B} t) γ = return {A ∨ B} (ι₁ (eval t γ)) eval (inr {A} {B} t) γ = return {A ∨ B} (ι₂ (eval t γ)) eval (case {A} {B} {C} t u v) γ = bind {A ∨ B} {C} (eval t γ) λ ξ s → elim⊎ s (λ a → eval u (mono⊩⋆ ξ γ , λ ξ′ k → a ξ′ k)) (λ b → eval v (mono⊩⋆ ξ γ , λ ξ′ k → b ξ′ k)) -- TODO: Correctness of evaluation with respect to conversion. -- The canonical model. private instance canon : Model canon = record { World = Cx Ty ; _≤_ = _⊆_ ; refl≤ = refl⊆ ; trans≤ = trans⊆ ; _⊪ᵅ_ = λ Γ P → Γ ⊢ α P ; mono⊪ᵅ = mono⊢ ; _‼_ = λ Γ A → Γ ⊢ A } -- Soundness and completeness with respect to the canonical model. mutual reflectᶜ : ∀ {A Γ} → Γ ⊢ A → Γ ⊩ A reflectᶜ {α P} t = return {α P} t reflectᶜ {A ▻ B} t = return {A ▻ B} λ η a → reflectᶜ {B} (app (mono⊢ η t) (reifyᶜ {A} a)) reflectᶜ {A ∧ B} t = return {A ∧ B} (reflectᶜ {A} (fst t) , reflectᶜ {B} (snd t)) reflectᶜ {⊤} t = return {⊤} ∙ reflectᶜ {⊥} t = λ η k → boom (mono⊢ η t) reflectᶜ {A ∨ B} t = λ η k → case (mono⊢ η t) (k weak⊆ (ι₁ (reflectᶜ {A} v₀))) (k weak⊆ (ι₂ (reflectᶜ {B} (v₀)))) reifyᶜ : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ A reifyᶜ {α P} k = k refl≤ λ η s → s reifyᶜ {A ▻ B} k = k refl≤ λ η s → lam (reifyᶜ {B} (s weak⊆ (reflectᶜ {A} (v₀)))) reifyᶜ {A ∧ B} k = k refl≤ λ η s → pair (reifyᶜ {A} (π₁ s)) (reifyᶜ {B} (π₂ s)) reifyᶜ {⊤} k = k refl≤ λ η s → unit reifyᶜ {⊥} k = k refl≤ λ η () reifyᶜ {A ∨ B} k = k refl≤ λ η s → elim⊎ s (λ a → inl (reifyᶜ {A} (λ η′ k → a η′ k))) (λ b → inr (reifyᶜ {B} (λ η′ k → b η′ k))) reflectᶜ⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊩⋆ Ξ reflectᶜ⋆ {∅} ∙ = ∙ reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t reifyᶜ⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ Ξ reifyᶜ⋆ {∅} ∙ = ∙ reifyᶜ⋆ {Ξ , A} (ts , t) = reifyᶜ⋆ ts , reifyᶜ t -- Reflexivity and transitivity. refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ refl⊩⋆ = reflectᶜ⋆ refl⊢⋆ trans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″ trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reifyᶜ⋆ ts) (reifyᶜ⋆ us)) -- Completeness with respect to all models, or quotation. quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A quot s = reifyᶜ (s refl⊩⋆) -- Normalisation by evaluation. norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A norm = quot ∘ eval -- TODO: Correctness of normalisation with respect to conversion.
33.980198
83
0.450175
414c366b3e3e0d7c1a48660c16dff63772b8d569
152
agda
Agda
Cubical/Data/Sum.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Data/Sum.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Data/Sum.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Sum where open import Cubical.Data.Sum.Base public open import Cubical.Data.Sum.Properties public
25.333333
46
0.769737
2fd0a393fb0e200bbd1c1853a94bcd299233a4d4
958
agda
Agda
Graphs/PathGraph.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Graphs/PathGraph.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Graphs/PathGraph.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Functions.Definition open import Setoids.Setoids open import Setoids.Subset open import Graphs.Definition open import Sets.FinSet.Definition open import Sets.FinSet.Lemmas open import Numbers.Naturals.Semiring open import Sets.EquivalenceRelations module Graphs.PathGraph where nNotSucc : {n : ℕ} → (n ≡ succ n) → False nNotSucc {zero} () nNotSucc {succ n} pr = nNotSucc (succInjective pr) PathGraph : (n : ℕ) → Graph _ (reflSetoid (FinSet (succ n))) Graph._<->_ (PathGraph n) x y = (toNat x ≡ succ (toNat y)) || (toNat y ≡ succ (toNat x)) Graph.noSelfRelation (PathGraph n) x (inl bad) = nNotSucc bad Graph.noSelfRelation (PathGraph n) x (inr bad) = nNotSucc bad Graph.symmetric (PathGraph n) (inl x) = inr x Graph.symmetric (PathGraph n) (inr x) = inl x Graph.wellDefined (PathGraph n) refl refl i = i
35.481481
88
0.735908
0e4a267aa8a4e65a160711b62f4cd340782aef9e
478
agda
Agda
Cubical/HITs/S2/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/HITs/S2/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/HITs/S2/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.HITs.S2.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels data S² : Type₀ where base : S² surf : PathP (λ i → base ≡ base) refl refl S²ToSetRec : ∀ {ℓ} {A : S² → Type ℓ} → ((x : S²) → isSet (A x)) → A base → (x : S²) → A x S²ToSetRec set b base = b S²ToSetRec set b (surf i j) = isOfHLevel→isOfHLevelDep 2 set b b {a0 = refl} {a1 = refl} refl refl surf i j
26.555556
79
0.608787
41c66894751d8b73f7078e995d22b4dd4fc529b4
29,719
agda
Agda
KeyValue/LinearStore/Implementation.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
KeyValue/LinearStore/Implementation.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
KeyValue/LinearStore/Implementation.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae open import Orders.Total.Definition open import Orders.Total.Lemmas open import Maybe open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Vectors open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order module KeyValue.LinearStore.Implementation {a b c} (keySet : Set a) (valueSet : Set b) (keyOrder : TotalOrder {_} keySet {c}) where record ReducedMap (min : keySet) : Set (a ⊔ b ⊔ c) record ReducedMap min where inductive field firstEntry : valueSet next : Maybe (Sg keySet (λ nextKey → (ReducedMap nextKey) && (TotalOrder._<_ keyOrder min nextKey))) addReducedMap : {min : keySet} → (k : keySet) → (v : valueSet) → (m : ReducedMap min) → ReducedMap (TotalOrder.min keyOrder min k) addReducedMap {min} k v m with TotalOrder.totality keyOrder min k addReducedMap {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) = record { firstEntry = firstEntry ; next = yes (k , (record { firstEntry = v ; next = no} ,, min<k))} addReducedMap {min} k v record { firstEntry = minVal ; next = yes (nextKey , (m ,, pr)) } | inl (inl min<k) = record { firstEntry = minVal ; next = yes ((TotalOrder.min keyOrder nextKey k) , (addReducedMap {_} k v m ,, minFromBoth keyOrder pr min<k))} addReducedMap {min} k v record { firstEntry = firstEntry ; next = next } | inl (inr k<min) = record { firstEntry = v ; next = yes (min , (record { firstEntry = firstEntry ; next = next } ,, k<min)) } addReducedMap {min} k v record { firstEntry = firstEntry ; next = next } | inr min=k rewrite min=k = record { firstEntry = v ; next = next } lookupReduced : {min : keySet} → (m : ReducedMap min) → (target : keySet) → Maybe valueSet lookupReduced {min} m k with TotalOrder.totality keyOrder min k lookupReduced {min} record { firstEntry = firstEntry ; next = no } k | inl (inl min<k) = no lookupReduced {min} record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, _))) } k | inl (inl min<k) = lookupReduced {newMin} m k lookupReduced {min} m k | inl (inr k<min) = no lookupReduced {min} record { firstEntry = firstEntry ; next = next } k | inr min=k = yes firstEntry countReduced : {min : keySet} → (m : ReducedMap min) → ℕ countReduced record { firstEntry = firstEntry ; next = no } = 1 countReduced record { firstEntry = firstEntry ; next = (yes (key , (m ,, pr))) } = succ (countReduced m) lookupReducedSucceedsAfterAdd : {min : keySet} → (k : keySet) → (v : valueSet) → (m : ReducedMap min) → (lookupReduced (addReducedMap k v m) k ≡ yes v) lookupReducedSucceedsAfterAdd {min} k v m with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) with TotalOrder.totality keyOrder k k lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inl _) | inr p = refl lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min)) lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = no } | inl (inl min<k) | inr min=k rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder min<k) lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) | inl (inl _) = lookupReducedSucceedsAfterAdd k v m lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min)) lookupReducedSucceedsAfterAdd {min} k v record { firstEntry = firstEntry ; next = (yes (newMin , (m ,, pr))) } | inl (inl min<k) | inr min=k rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder min<k) lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) with TotalOrder.totality keyOrder k k lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) lookupReducedSucceedsAfterAdd {min} k v m | inl (inr k<min) | inr p = refl lookupReducedSucceedsAfterAdd {min} k v m | inr min=k with TotalOrder.totality keyOrder k k lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inr p with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inr p | inl (inl min<k) rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder min<k) lookupReducedSucceedsAfterAdd {min} k v m | inr min=k | inr p | inl (inr k<min) rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder k<min) lookupReducedSucceedsAfterAdd {.k} k v record { firstEntry = firstEntry ; next = next } | inr refl | inr p | inr s = refl lookupReducedSucceedsAfterUnrelatedAdd : {min : keySet} → (unrelatedK : keySet) → (unrelatedV : valueSet) → (k : keySet) → (v : valueSet) → ((TotalOrder._<_ keyOrder unrelatedK k) || (TotalOrder._<_ keyOrder k unrelatedK)) → (m : ReducedMap min) → (lookupReduced m k ≡ yes v) → lookupReduced (addReducedMap unrelatedK unrelatedV m) k ≡ yes v lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds with TotalOrder.totality keyOrder min k' lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inl min<k') with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr record { firstEntry = firstEntry ; next = no } () | inl (inl min<k') | inl (inl min<k) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedSucceeds | inl (inl min<k') | inl (inl min<k) = lookupReducedSucceedsAfterUnrelatedAdd {a} k' v' k v pr fst lookupReducedSucceeds lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inl x) m lookupReducedSucceeds | inl (inl min<k') | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min (TotalOrder.<Transitive keyOrder min<k' x))) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr k<k') m () | inl (inl min<k') | inl (inr k<min) lookupReducedSucceedsAfterUnrelatedAdd {.min} k' v' min v (inl x) m lookupReducedSucceeds | inl (inl min<k') | inr refl = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder x min<k')) lookupReducedSucceedsAfterUnrelatedAdd {.min} k' v' min v (inr x) record { firstEntry = v2 ; next = no } p | inl (inl min<k') | inr refl = applyEquality yes (yesInjective p) lookupReducedSucceedsAfterUnrelatedAdd {.min} k' v' min v (inr x) record { firstEntry = .v ; next = (yes (a , b)) } refl | inl (inl min<k') | inr refl = applyEquality yes refl lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) with TotalOrder.totality keyOrder k' k lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) | inl (inl k'<k) with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) | inl (inl k'<k) | inl (inl min<k) = lookupReducedSucceeds lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m () | inl (inr k'<min) | inl (inl k'<k) | inl (inr k<min) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inl (inr k'<min) | inl (inl k'<k) | inr refl = lookupReducedSucceeds lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inl x) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder x k<k')) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr x) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr _) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder x (TotalOrder.<Transitive keyOrder k<k' k'<min))) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr _) m () | inl (inr k'<min) | inl (inr k<k') | inl (inr x) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr _) m lookupReducedSucceeds | inl (inr k'<min) | inl (inr k<k') | inr x rewrite x = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<k' k'<min)) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inl x) m lookupReducedSucceeds | inl (inr k'<min) | inr k'=k rewrite k'=k = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v (inr x) m lookupReducedSucceeds | inl (inr k'<min) | inr k'=k rewrite k'=k = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedSucceedsAfterUnrelatedAdd {min} k' v' k v pr m lookupReducedSucceeds | inr refl with TotalOrder.totality keyOrder min k lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inl _) record { firstEntry = firstEntry ; next = no } () | inr refl | inl (inl min<k) lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inl _) record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedSucceeds | inr refl | inl (inl min<k) = lookupReducedSucceeds lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inr x) m lookupReducedSucceeds | inr refl | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k x)) lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inl x) m () | inr refl | inl (inr k<min) lookupReducedSucceedsAfterUnrelatedAdd {k'} k' v' k v (inr x) m () | inr refl | inl (inr k<min) lookupReducedSucceedsAfterUnrelatedAdd {.min} .min v' min v (inl x) m lookupReducedSucceeds | inr refl | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedSucceedsAfterUnrelatedAdd {.min} .min v' min v (inr x) m lookupReducedSucceeds | inr refl | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd : {min : keySet} → (unrelatedK : keySet) → (unrelatedV : valueSet) → (k : keySet) → ((TotalOrder._<_ keyOrder unrelatedK k) || (TotalOrder._<_ keyOrder k unrelatedK)) → (m : ReducedMap min) → (lookupReduced m k ≡ no) → lookupReduced (addReducedMap unrelatedK unrelatedV m) k ≡ no lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails with TotalOrder.totality keyOrder min k' lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inl min<k') with TotalOrder.totality keyOrder min k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) with TotalOrder.totality keyOrder k' k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inl (inl x) = refl lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inl (inr x) = refl lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inl x) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inr x) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inl min<k') | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedFails | inl (inl min<k') | inl (inl min<k) = lookupReducedFailsAfterUnrelatedAdd k' v' k pr fst lookupReducedFails lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inl min<k') | inl (inr k<min) = refl lookupReducedFailsAfterUnrelatedAdd {.min} k' v' min pr m () | inl (inl min<k') | inr refl lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inr k'<min) with TotalOrder.totality keyOrder min k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) with TotalOrder.totality keyOrder k' k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) with TotalOrder.totality keyOrder min k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl x₁) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = refl lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl x₁) record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = lookupReducedFails lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inr x₁) record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = refl lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inr x₁) record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inl _) = lookupReducedFails lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inl (inr x) = refl lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inl k'<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder min<k) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inl (inr k<k') = refl lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inl x) record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inr x) record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr k'<min) | inl (inl min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) with TotalOrder.totality keyOrder k' k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) with TotalOrder.totality keyOrder min k lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min min<k)) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) | inl (inr k<min') = refl lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inl _) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder k<min) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k (inr x) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inl k'<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k'<k x)) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inl (inr k<k') = refl lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inl x) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd {min} .k v' k (inr x) m lookupReducedFails | inl (inr k'<min) | inl (inr k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder x) lookupReducedFailsAfterUnrelatedAdd {min} k' v' k pr m () | inl (inr k'<min) | inr min=k lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr m lookupReducedFails | inr refl with TotalOrder.totality keyOrder min k lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr record { firstEntry = firstEntry ; next = no } lookupReducedFails | inr refl | inl (inl min<k) = refl lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedFails | inr refl | inl (inl min<k) = lookupReducedFails lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr m lookupReducedFails | inr refl | inl (inr k<min) = refl lookupReducedFailsAfterUnrelatedAdd {min} .min v' k pr m () | inr refl | inr min=k countReducedBehavesWhenAddingNotPresent : {min : keySet} → (k : keySet) → (v : valueSet) → (m : ReducedMap min) → (lookupReduced m k ≡ no) → countReduced (addReducedMap k v m) ≡ succ (countReduced m) countReducedBehavesWhenAddingNotPresent {min} k v m lookupReducedFails with TotalOrder.totality keyOrder k min countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) with TotalOrder.totality keyOrder min k countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min)) countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) | inl (inr _) = refl countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inl k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder k<min) countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr min<k) with TotalOrder.totality keyOrder min k countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = no } lookupReducedFails | inl (inr min<k) | inl (inl _) = refl countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedFails | inl (inr min<k) | inl (inl _) = applyEquality succ (countReducedBehavesWhenAddingNotPresent k v (_&&_.fst b) lookupReducedFails) countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr min<k) | inl (inr k<min) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder min<k k<min)) countReducedBehavesWhenAddingNotPresent {min} k v record { firstEntry = firstEntry ; next = next } lookupReducedFails | inl (inr min<k) | inr refl = exFalso (TotalOrder.irreflexive keyOrder min<k) countReducedBehavesWhenAddingNotPresent {min} k v m lookupReducedFails | inr refl with TotalOrder.totality keyOrder min min countReducedBehavesWhenAddingNotPresent {k} k v m lookupReducedFails | inr refl | inl (inl min<min) = exFalso (TotalOrder.irreflexive keyOrder min<min) countReducedBehavesWhenAddingNotPresent {k} k v m lookupReducedFails | inr refl | inl (inr min<min) = exFalso (TotalOrder.irreflexive keyOrder min<min) countReducedBehavesWhenAddingNotPresent {k} k v record { firstEntry = firstEntry ; next = no } () | inr refl | inr p countReducedBehavesWhenAddingNotPresent {k} k v record { firstEntry = firstEntry ; next = (yes x) } () | inr refl | inr p countReducedBehavesWhenAddingPresent : {min : keySet} → (k : keySet) → (v v' : valueSet) → (m : ReducedMap min) → (lookupReduced m k ≡ yes v') → countReduced (addReducedMap k v m) ≡ countReduced m countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds with TotalOrder.totality keyOrder k min countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inl k<min) with TotalOrder.totality keyOrder min k countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inl k<min) | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min min<k)) countReducedBehavesWhenAddingPresent {min} k v v' m () | inl (inl k<min) | inl (inr _) countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inl k<min) | inr q = exFalso (TotalOrder.irreflexive keyOrder (identityOfIndiscernablesLeft (TotalOrder._<_ keyOrder) k<min (equalityCommutative q))) countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inr min<k) with TotalOrder.totality keyOrder min k countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } () | inl (inr min<k) | inl (inl _) countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } lookupReducedSucceeds | inl (inr min<k) | inl (inl _) = applyEquality succ (countReducedBehavesWhenAddingPresent k v v' fst lookupReducedSucceeds) countReducedBehavesWhenAddingPresent {min} k v v' m () | inl (inr min<k) | inl (inr k<min) countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inl (inr min<k) | inr q = exFalso (TotalOrder.irreflexive keyOrder (identityOfIndiscernablesLeft (λ a b → TotalOrder._<_ keyOrder a b) min<k q)) countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inr q with TotalOrder.totality keyOrder min min countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inr q | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder x) countReducedBehavesWhenAddingPresent {min} k v v' m lookupReducedSucceeds | inr q | inl (inr x) = exFalso (TotalOrder.irreflexive keyOrder x) countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } lookupReducedSucceeds | inr _ | inr p with TotalOrder.totality keyOrder min k countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } () | inr _ | inr p | inl (inl x) countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = no } () | inr _ | inr p | inl (inr x`) countReducedBehavesWhenAddingPresent {.k} k v v' record { firstEntry = firstEntry ; next = no } lookupReducedSucceeds | inr q | inr p | inr refl = refl countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedSucceeds | inr q | inr p with TotalOrder.totality keyOrder k k countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedSucceeds | inr q | inr p | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder x) countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , b)) } lookupReducedSucceeds | inr q | inr p | inl (inr x) = exFalso (TotalOrder.irreflexive keyOrder x) countReducedBehavesWhenAddingPresent {min} k v v' record { firstEntry = firstEntry ; next = (yes (a , (m ,, pr))) } q | inr q1 | inr p | inr x with TotalOrder.totality keyOrder min k countReducedBehavesWhenAddingPresent {.k} k v v' record { firstEntry = firstEntry ; next = (yes (a , (m ,, pr))) } q | inr refl | inr p | inr x | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder min<k) countReducedBehavesWhenAddingPresent {.k} k v v' record { firstEntry = firstEntry ; next = (yes (a , (m ,, pr))) } q | inr q1 | inr p | inr x | inr refl = refl data Map : Set (a ⊔ b ⊔ c) where empty : Map nonempty : {min : keySet} → ReducedMap min → Map addMap : (m : Map) → (k : keySet) → (v : valueSet) → Map addMap empty k v = nonempty {min = k} record { firstEntry = v ; next = no } addMap (nonempty x) k v = nonempty (addReducedMap k v x) lookup : (m : Map) → (target : keySet) → Maybe valueSet lookup empty t = no lookup (nonempty x) t = lookupReduced x t count : (m : Map) → ℕ count empty = 0 count (nonempty x) = countReduced x keysReduced : {min : keySet} → (m : ReducedMap min) → Vec keySet (countReduced m) keysReduced {min = min} record { firstEntry = firstEntry ; next = no } = min ,- [] keysReduced {min = min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } = min ,- (keysReduced fst) keys : (m : Map) → Vec keySet (count m) keys empty = [] keys (nonempty m) = keysReduced m lookupReducedWhenLess : {min : keySet} → (m : ReducedMap min) → (k : keySet) → (TotalOrder._<_ keyOrder k min) → (lookupReduced m k ≡ no) lookupReducedWhenLess {min} m k k<min with TotalOrder.totality keyOrder min k lookupReducedWhenLess {min} m k k<min | inl (inl min<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min min<k)) lookupReducedWhenLess {min} m k k<min | inl (inr _) = refl lookupReducedWhenLess {min} m k k<min | inr min=k rewrite min=k = exFalso (TotalOrder.irreflexive keyOrder k<min) lookupCertainReduced : {min : keySet} → (m : ReducedMap min) → (k : keySet) → (vecContains (keysReduced m) k) → Sg valueSet (λ v → lookupReduced m k ≡ yes v) lookupCertainReduced {min} record { firstEntry = firstEntry ; next = no } k pr = firstEntry , q where t : min ≡ k t = vecSolelyContains k pr q : lookupReduced {min} (record { firstEntry = firstEntry ; next = no }) k ≡ yes firstEntry q with TotalOrder.totality keyOrder k k q | inl (inl k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) q | inl (inr k<k) = exFalso (TotalOrder.irreflexive keyOrder k<k) q | inr p with TotalOrder.totality keyOrder min k q | inr p | inl (inl min<k) rewrite t = exFalso (TotalOrder.irreflexive keyOrder min<k) q | inr p | inl (inr k<min) rewrite t = exFalso (TotalOrder.irreflexive keyOrder k<min) q | inr p | inr x = refl lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k pr with TotalOrder.totality keyOrder min k lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = zero ; index<m = _ ; isHere = isHere } | inl (inl min<k) rewrite isHere = exFalso (TotalOrder.irreflexive keyOrder min<k) lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inl min<k) = lookupCertainReduced fst k record { index = index ; index<m = canRemoveSuccFrom<N index<m ; isHere = isHere } lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = zero ; index<m = _ ; isHere = isHere } | inl (inr k<min) rewrite isHere = exFalso (TotalOrder.irreflexive keyOrder k<min) lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) with TotalOrder.totality keyOrder a k lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) | inl (inl a<k) = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder k<min (TotalOrder.<Transitive keyOrder snd a<k))) lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) | inl (inr k<a) = exFalso h where f : Sg valueSet (λ v → lookupReduced fst k ≡ yes v) f = lookupCertainReduced fst k record { index = index ; index<m = canRemoveSuccFrom<N index<m ; isHere = isHere } g : lookupReduced fst k ≡ no g = lookupReducedWhenLess fst k k<a noIsNotYes : {a : _} → {A : Set a} → {b : A} → (no ≡ yes b) → False noIsNotYes {a} {A} {b} () h : False h with f h | a , b rewrite g = noIsNotYes b lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k record { index = (succ index) ; index<m = index<m ; isHere = isHere } | inl (inr k<min) | inr refl = exFalso (TotalOrder.irreflexive keyOrder (TotalOrder.<Transitive keyOrder snd k<min)) lookupCertainReduced {min} record { firstEntry = firstEntry ; next = (yes (a , (fst ,, snd))) } k pr | inr min=k = firstEntry , refl lookupCertain : (m : Map) → (k : keySet) → (vecContains (keys m) k) → Sg valueSet (λ v → lookup m k ≡ yes v) lookupCertain empty k record { index = index ; index<m = (le x ()) ; isHere = isHere } lookupCertain (nonempty {min} m) k pr = lookupCertainReduced {min} m k pr
122.300412
341
0.720886
c5bac97156d193f3ffbd67716e8ed36a8a6be4a9
10,237
agda
Agda
Data/List/Kleene/Base.agda
oisdk/agda-kleene-lists
a7e99bc288e12e83440c891dbd3e5077d9b1657e
[ "MIT" ]
null
null
null
Data/List/Kleene/Base.agda
oisdk/agda-kleene-lists
a7e99bc288e12e83440c891dbd3e5077d9b1657e
[ "MIT" ]
null
null
null
Data/List/Kleene/Base.agda
oisdk/agda-kleene-lists
a7e99bc288e12e83440c891dbd3e5077d9b1657e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} ------------------------------------------------------------------------ -- Lists, based on the Kleene star and plus. -- -- These lists are exatcly equivalent to normal lists, except the "cons" -- case is split into its own data type. This lets us write all the same -- functions as before, but it has 2 advantages: -- -- * Some functions are easier to express on the non-empty type. For -- instance, head can be clearly expressed without the need for -- maybes. -- * It can make some proofs easier. By using the non-empty type where -- possible, we can avoid an extra pattern match, which can really -- simplify certain proofs. module Data.List.Kleene.Base where open import Data.Product as Product using (_×_; _,_; map₂; map₁; proj₁; proj₂) open import Data.Nat as ℕ using (ℕ; suc; zero) open import Data.Maybe as Maybe using (Maybe; just; nothing) open import Data.Sum as Sum using (_⊎_; inj₁; inj₂) open import Algebra open import Function ------------------------------------------------------------------------ -- Definitions infixr 5 _&_ ∹_ mutual -- Non-Empty Lists record _⁺ {a} (A : Set a) : Set a where inductive constructor _&_ field head : A tail : A ⋆ -- Possibly Empty Lists data _⋆ {a} (A : Set a) : Set a where [] : A ⋆ ∹_ : A ⁺ → A ⋆ open _⁺ public ------------------------------------------------------------------------ -- FoldMap module _ {c ℓ a} (sgrp : Semigroup c ℓ) {A : Set a} where open Semigroup sgrp foldMap⁺ : (A → Carrier) → A ⁺ → Carrier foldMap⁺ f (x & []) = f x foldMap⁺ f (x & ∹ xs) = f x ∙ foldMap⁺ f xs module _ {c ℓ a} (mon : Monoid c ℓ) {A : Set a} where open Monoid mon foldMap⋆ : (A → Carrier) → A ⋆ → Carrier foldMap⋆ f [] = ε foldMap⋆ f (∹ xs) = foldMap⁺ semigroup f xs ------------------------------------------------------------------------ -- Folds module _ {a b} {A : Set a} {B : Set b} (f : A → B → B) (b : B) where foldr⁺ : A ⁺ → B foldr⋆ : A ⋆ → B foldr⁺ (x & xs) = f x (foldr⋆ xs) foldr⋆ [] = b foldr⋆ (∹ xs) = foldr⁺ xs module _ {a b} {A : Set a} {B : Set b} (f : B → A → B) where foldl⁺ : B → A ⁺ → B foldl⋆ : B → A ⋆ → B foldl⁺ b (x & xs) = foldl⋆ (f b x) xs foldl⋆ b [] = b foldl⋆ b (∹ xs) = foldl⁺ b xs ------------------------------------------------------------------------ -- Concatenation module _ {a} {A : Set a} where _⁺++⁺_ : A ⁺ → A ⁺ → A ⁺ _⁺++⋆_ : A ⁺ → A ⋆ → A ⁺ _⋆++⁺_ : A ⋆ → A ⁺ → A ⁺ _⋆++⋆_ : A ⋆ → A ⋆ → A ⋆ head (xs ⁺++⋆ ys) = head xs tail (xs ⁺++⋆ ys) = tail xs ⋆++⋆ ys xs ⋆++⋆ ys = foldr⋆ (λ x zs → ∹ x & zs) ys xs xs ⁺++⁺ ys = foldr⁺ (λ x zs → x & ∹ zs) ys xs [] ⋆++⁺ ys = ys (∹ xs) ⋆++⁺ ys = xs ⁺++⁺ ys ------------------------------------------------------------------------ -- Mapping module _ {a b} {A : Set a} {B : Set b} (f : A → B) where map⁺ : A ⁺ → B ⁺ map⋆ : A ⋆ → B ⋆ head (map⁺ xs) = f (head xs) tail (map⁺ xs) = map⋆ (tail xs) map⋆ [] = [] map⋆ (∹ xs) = ∹ map⁺ xs ------------------------------------------------------------------------ -- Applicative Operations module _ {a} {A : Set a} where pure⁺ : A → A ⁺ pure⋆ : A → A ⋆ head (pure⁺ x) = x tail (pure⁺ x) = [] pure⋆ x = ∹ pure⁺ x module _ {a b} {A : Set a} {B : Set b} where _⋆<*>⋆_ : (A → B) ⋆ → A ⋆ → B ⋆ _⁺<*>⋆_ : (A → B) ⁺ → A ⋆ → B ⋆ _⋆<*>⁺_ : (A → B) ⋆ → A ⁺ → B ⋆ _⁺<*>⁺_ : (A → B) ⁺ → A ⁺ → B ⁺ [] ⋆<*>⋆ xs = [] (∹ fs) ⋆<*>⋆ xs = fs ⁺<*>⋆ xs fs ⁺<*>⋆ xs = map⋆ (head fs) xs ⋆++⋆ (tail fs ⋆<*>⋆ xs) [] ⋆<*>⁺ xs = [] (∹ fs) ⋆<*>⁺ xs = ∹ fs ⁺<*>⁺ xs fs ⁺<*>⁺ xs = map⁺ (head fs) xs ⁺++⋆ (tail fs ⋆<*>⁺ xs) ------------------------------------------------------------------------ -- Monadic Operations module _ {a b} {A : Set a} {B : Set b} where _⁺>>=⁺_ : A ⁺ → (A → B ⁺) → B ⁺ _⁺>>=⋆_ : A ⁺ → (A → B ⋆) → B ⋆ _⋆>>=⁺_ : A ⋆ → (A → B ⁺) → B ⋆ _⋆>>=⋆_ : A ⋆ → (A → B ⋆) → B ⋆ (x & xs) ⁺>>=⁺ k = k x ⁺++⋆ (xs ⋆>>=⁺ k) (x & xs) ⁺>>=⋆ k = k x ⋆++⋆ (xs ⋆>>=⋆ k) [] ⋆>>=⋆ k = [] (∹ xs) ⋆>>=⋆ k = xs ⁺>>=⋆ k [] ⋆>>=⁺ k = [] (∹ xs) ⋆>>=⁺ k = ∹ xs ⁺>>=⁺ k ------------------------------------------------------------------------ -- Scans module Scanr {a b} {A : Set a} {B : Set b} (f : A → B → B) (b : B) where cons : A → B ⁺ → B ⁺ head (cons x xs) = f x (head xs) tail (cons x xs) = ∹ xs scanr⁺ : A ⁺ → B ⁺ scanr⋆ : A ⋆ → B ⁺ scanr⋆ = foldr⋆ cons (b & []) scanr⁺ = foldr⁺ cons (b & []) open Scanr public using (scanr⁺; scanr⋆) module _ {a b} {A : Set a} {B : Set b} (f : B → A → B) where scanl⁺ : B → A ⁺ → B ⁺ scanl⋆ : B → A ⋆ → B ⁺ head (scanl⁺ b xs) = b tail (scanl⁺ b xs) = ∹ scanl⋆ (f b (head xs)) (tail xs) head (scanl⋆ b xs) = b tail (scanl⋆ b []) = [] tail (scanl⋆ b (∹ xs)) = ∹ scanl⋆ (f b (head xs)) (tail xs) scanl₁ : B → A ⁺ → B ⁺ scanl₁ b xs = scanl⋆ (f b (head xs)) (tail xs) ------------------------------------------------------------------------ -- Accumulating maps module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : B → A → (B × C)) where mapAccumL⋆ : B → A ⋆ → (B × C ⋆) mapAccumL⁺ : B → A ⁺ → (B × C ⁺) mapAccumL⋆ b [] = b , [] mapAccumL⋆ b (∹ xs) = map₂ ∹_ (mapAccumL⁺ b xs) mapAccumL⁺ b (x & xs) = let y , ys = f b x z , zs = mapAccumL⋆ y xs in z , (ys & zs) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B → (C × B)) (b : B) where mapAccumR⋆ : A ⋆ → (C ⋆ × B) mapAccumR⁺ : A ⁺ → (C ⁺ × B) mapAccumR⋆ [] = [] , b mapAccumR⋆ (∹ xs) = map₁ ∹_ (mapAccumR⁺ xs) mapAccumR⁺ (x & xs) = let ys , y = mapAccumR⋆ xs zs , z = f x y in (zs & ys) , z ------------------------------------------------------------------------ -- Non-Empty Folds module _ {a} {A : Set a} where last : A ⁺ → A last (x & []) = x last (_ & (∹ xs)) = last xs module _ {a} {A : Set a} (f : A → A → A) where foldr1 : A ⁺ → A foldr1 (x & []) = x foldr1 (x & (∹ xs)) = f x (foldr1 xs) foldl1 : A ⁺ → A foldl1 (x & xs) = foldl⋆ f x xs module _ {a b} {A : Set a} {B : Set b} (f : A → Maybe B → B) where foldrMay⋆ : A ⋆ → Maybe B foldrMay⁺ : A ⁺ → B foldrMay⋆ [] = nothing foldrMay⋆ (∹ xs) = just (foldrMay⁺ xs) foldrMay⁺ xs = f (head xs) (foldrMay⋆ (tail xs)) ------------------------------------------------------------------------ -- Indexing module _ {a} {A : Set a} where _[_]⋆ : A ⋆ → ℕ → Maybe A _[_]⁺ : A ⁺ → ℕ → Maybe A [] [ _ ]⋆ = nothing (∹ xs) [ i ]⋆ = xs [ i ]⁺ xs [ zero ]⁺ = just (head xs) xs [ suc i ]⁺ = tail xs [ i ]⋆ applyUpTo⋆ : (ℕ → A) → ℕ → A ⋆ applyUpTo⁺ : (ℕ → A) → ℕ → A ⁺ applyUpTo⋆ f zero = [] applyUpTo⋆ f (suc n) = ∹ applyUpTo⁺ f n head (applyUpTo⁺ f n) = f zero tail (applyUpTo⁺ f n) = applyUpTo⋆ (f ∘ suc) n upTo⋆ : ℕ → ℕ ⋆ upTo⋆ = applyUpTo⋆ id upTo⁺ : ℕ → ℕ ⁺ upTo⁺ = applyUpTo⁺ id ------------------------------------------------------------------------ -- Manipulation module _ {a} {A : Set a} (x : A) where intersperse⁺ : A ⁺ → A ⁺ intersperse⋆ : A ⋆ → A ⋆ head (intersperse⁺ xs) = head xs tail (intersperse⁺ xs) = prepend (tail xs) where prepend : A ⋆ → A ⋆ prepend [] = [] prepend (∹ xs) = ∹ x & ∹ intersperse⁺ xs intersperse⋆ [] = [] intersperse⋆ (∹ xs) = ∹ intersperse⁺ xs module _ {a} {A : Set a} where _⁺<|>⁺_ : A ⁺ → A ⁺ → A ⁺ _⁺<|>⋆_ : A ⁺ → A ⋆ → A ⁺ _⋆<|>⁺_ : A ⋆ → A ⁺ → A ⁺ _⋆<|>⋆_ : A ⋆ → A ⋆ → A ⋆ head (xs ⁺<|>⁺ ys) = head xs tail (xs ⁺<|>⁺ ys) = ∹ (ys ⁺<|>⋆ tail xs) head (xs ⁺<|>⋆ ys) = head xs tail (xs ⁺<|>⋆ ys) = ys ⋆<|>⋆ tail xs [] ⋆<|>⁺ ys = ys (∹ xs) ⋆<|>⁺ ys = xs ⁺<|>⁺ ys [] ⋆<|>⋆ ys = ys (∹ xs) ⋆<|>⋆ ys = ∹ (xs ⁺<|>⋆ ys) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B → C) where ⁺zipWith⁺ : A ⁺ → B ⁺ → C ⁺ ⋆zipWith⁺ : A ⋆ → B ⁺ → C ⋆ ⁺zipWith⋆ : A ⁺ → B ⋆ → C ⋆ ⋆zipWith⋆ : A ⋆ → B ⋆ → C ⋆ head (⁺zipWith⁺ xs ys) = f (head xs) (head ys) tail (⁺zipWith⁺ xs ys) = ⋆zipWith⋆ (tail xs) (tail ys) ⋆zipWith⁺ [] ys = [] ⋆zipWith⁺ (∹ xs) ys = ∹ ⁺zipWith⁺ xs ys ⁺zipWith⋆ xs [] = [] ⁺zipWith⋆ xs (∹ ys) = ∹ ⁺zipWith⁺ xs ys ⋆zipWith⋆ [] ys = [] ⋆zipWith⋆ (∹ xs) ys = ⁺zipWith⋆ xs ys module Unzip {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B × C) where cons : B × C → B ⋆ × C ⋆ → B ⁺ × C ⁺ head (proj₁ (cons x xs)) = proj₁ x tail (proj₁ (cons x xs)) = proj₁ xs head (proj₂ (cons x xs)) = proj₂ x tail (proj₂ (cons x xs)) = proj₂ xs unzipWith⋆ : A ⋆ → B ⋆ × C ⋆ unzipWith⁺ : A ⁺ → B ⁺ × C ⁺ unzipWith⋆ = foldr⋆ (λ x xs → Product.map ∹_ ∹_ (cons (f x) xs)) ([] , []) unzipWith⁺ xs = cons (f (head xs)) (unzipWith⋆ (tail xs)) open Unzip using (unzipWith⁺; unzipWith⋆) public module Partition {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B ⊎ C) where cons : B ⊎ C → B ⋆ × C ⋆ → B ⋆ × C ⋆ proj₁ (cons (inj₁ x) xs) = ∹ x & proj₁ xs proj₂ (cons (inj₁ x) xs) = proj₂ xs proj₂ (cons (inj₂ x) xs) = ∹ x & proj₂ xs proj₁ (cons (inj₂ x) xs) = proj₁ xs partitionSumsWith⋆ : A ⋆ → B ⋆ × C ⋆ partitionSumsWith⁺ : A ⁺ → B ⋆ × C ⋆ partitionSumsWith⋆ = foldr⋆ (cons ∘ f) ([] , []) partitionSumsWith⁺ = foldr⁺ (cons ∘ f) ([] , []) open Partition using (partitionSumsWith⁺; partitionSumsWith⋆) public module _ {a} {A : Set a} where ⋆transpose⋆ : (A ⋆) ⋆ → (A ⋆) ⋆ ⋆transpose⁺ : (A ⋆) ⁺ → (A ⁺) ⋆ ⁺transpose⋆ : (A ⁺) ⋆ → (A ⋆) ⁺ ⁺transpose⁺ : (A ⁺) ⁺ → (A ⁺) ⁺ ⋆transpose⋆ [] = [] ⋆transpose⋆ (∹ xs) = map⋆ ∹_ (⋆transpose⁺ xs) ⋆transpose⁺ (x & []) = map⋆ pure⁺ x ⋆transpose⁺ (x & (∹ xs)) = ⋆zipWith⋆ (λ y z → y & ∹ z) x (⋆transpose⁺ xs) ⁺transpose⋆ [] = [] & [] ⁺transpose⋆ (∹ xs) = map⁺ ∹_ (⁺transpose⁺ xs) ⁺transpose⁺ (x & []) = map⁺ pure⁺ x ⁺transpose⁺ (x & (∹ xs)) = ⁺zipWith⁺ (λ y z → y & ∹ z) x (⁺transpose⁺ xs) module _ {a} {A : Set a} where tails⋆ : A ⋆ → (A ⁺) ⋆ tails⁺ : A ⁺ → (A ⁺) ⁺ head (tails⁺ xs) = xs tail (tails⁺ xs) = tails⋆ (tail xs) tails⋆ [] = [] tails⋆ (∹ xs) = ∹ tails⁺ xs module _ {a} {A : Set a} where reverse⋆ : A ⋆ → A ⋆ reverse⋆ = foldl⋆ (λ xs x → ∹ x & xs) [] reverse⁺ : A ⁺ → A ⁺ reverse⁺ (x & xs) = foldl⋆ (λ ys y → y & (∹ ys)) (x & []) xs
26.248718
88
0.429032
59dc0c5ee55aee7b51f8b850449631f02a5d5390
20,312
agda
Agda
Cubical/Algebra/GradedRing/DirectSumFun.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/GradedRing/DirectSumFun.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/GradedRing/DirectSumFun.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.GradedRing.DirectSumFun where {- This file give a graded ring construction in the case of the fun direct sum. Because of the current proofs this is done only in the case where - Idx is ℕ and for a monoid on it - For the usual ∸ of the Nat library The proof consists in : - Defining a _prod_ operation on the structure - Proving the underlying equivalence respect it - Transporting the proof of RingStr - Deducing an equivalence proof -} open import Cubical.Foundations.Prelude open import Cubical.Foundations.Transport open import Cubical.Foundations.HLevels open import Cubical.Relation.Nullary open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Nat renaming (_+_ to _+ℕ_ ; _∸_ to _-ℕ_ ) open import Cubical.Data.Nat.Order open import Cubical.Data.Sigma open import Cubical.Data.Sum open import Cubical.Algebra.Monoid open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.AbGroup open import Cubical.Algebra.DirectSum.Equiv-DSHIT-DSFun open import Cubical.Algebra.DirectSum.DirectSumHIT.Base open import Cubical.Algebra.DirectSum.DirectSumHIT.Properties open import Cubical.Algebra.DirectSum.DirectSumFun.Base open import Cubical.Algebra.AbGroup.Instances.NProd open import Cubical.Algebra.AbGroup.Instances.DirectSumFun open import Cubical.Algebra.Ring open import Cubical.Algebra.GradedRing.Base open import Cubical.Algebra.GradedRing.DirectSumHIT open import Cubical.Algebra.CommRing open import Cubical.HITs.PropositionalTruncation as PT private variable ℓ ℓ' : Level open AbGroupStr open AbGroupTheory ----------------------------------------------------------------------------- -- Def, notation, lemma module _ -- monoid (_+n_ : ℕ → ℕ → ℕ) -- need to instantiate on +' (isM : IsMonoid 0 _+n_) (_+≡_ : (n m : ℕ) → n +n m ≡ n +ℕ m) -- needed for the behaviour under -ℕ -- (G : ℕ → Type ℓ) (Gstr : (n : ℕ) → AbGroupStr (G n)) where sameFiber+ : {i n : ℕ} → i ≤ n → i +ℕ (n -ℕ i) ≡ n sameFiber+ {zero} {zero} p = refl sameFiber+ {zero} {suc n} p = refl sameFiber+ {suc i} {zero} p = ⊥.rec (¬-<-zero p) sameFiber+ {suc i} {suc n} p = cong suc (sameFiber+ (pred-≤-pred p)) sameFiber : {i n : ℕ} → (i ≤ n) → i +n (n -ℕ i) ≡ n sameFiber {i} {n} p = (i +≡ (n -ℕ i)) ∙ sameFiber+ p open SubstLemma ℕ G Gstr open IsMonoid isM using () renaming ( ·Assoc to +nAssoc ; ·IdR to +nIdR ; ·IdL to +nIdL ) open AbGroupStr (snd (NProd-AbGroup G Gstr)) using () renaming ( 0g to 0Fun ; _+_ to _+Fun_ ; is-set to isSetFun ) module _ (1⋆ : G 0) (_⋆_ : {k l : ℕ} → G k → G l → G (k +n l)) (0-⋆ : {k l : ℕ} → (b : G l) → (0g (Gstr k)) ⋆ b ≡ 0g (Gstr (k +n l))) (⋆-0 : {k l : ℕ} → (a : G k) → a ⋆ (0g (Gstr l)) ≡ 0g (Gstr (k +n l))) (⋆Assoc : {k l m : ℕ} → (a : G k) → (b : G l) → (c : G m) → _≡_ {A = Σ[ k ∈ ℕ ] G k} ((k +n (l +n m)) , (a ⋆ (b ⋆ c))) (((k +n l) +n m) , ((a ⋆ b) ⋆ c))) (⋆IdR : {k : ℕ} → (a : G k) → _≡_ {A = Σ[ k ∈ ℕ ] G k} ( k +n 0 , a ⋆ 1⋆ ) (k , a)) (⋆IdL : {l : ℕ} → (b : G l) → _≡_ {A = Σ[ k ∈ ℕ ] G k} ( 0 +n l , 1⋆ ⋆ b ) (l , b)) (⋆DistR+ : {k l : ℕ} → (a : G k) → (b c : G l) → a ⋆ ((Gstr l) ._+_ b c) ≡ Gstr (k +n l) ._+_ (a ⋆ b) (a ⋆ c)) (⋆DistL+ : {k l : ℕ} → (a b : G k) → (c : G l) → ((Gstr k) ._+_ a b) ⋆ c ≡ Gstr (k +n l) ._+_ (a ⋆ c) (b ⋆ c)) where ----------------------------------------------------------------------------- -- Definition of 1 -- import for pres open Equiv-Properties G Gstr using ( substG ; fun-trad ; fun-trad-eq ; fun-trad-neq ; ⊕HIT→Fun ; ⊕HIT→⊕Fun ; ⊕HIT→⊕Fun-pres+) 1Fun : (n : ℕ) → G n 1Fun zero = 1⋆ 1Fun (suc n) = 0g (Gstr (suc n)) 1⊕Fun : ⊕Fun G Gstr 1⊕Fun = 1Fun , ∣ 0 , helper ∣₁ where helper : AlmostNullProof G Gstr 1Fun 0 helper zero r = ⊥.rec (¬-<-zero r) helper (suc n) r = refl ⊕HIT→Fun-pres1 : (n : ℕ) → ⊕HIT→Fun (base 0 1⋆) n ≡ 1Fun n ⊕HIT→Fun-pres1 zero with discreteℕ 0 0 ... | yes p = cong (λ X → subst G X 1⋆) (isSetℕ _ _ _ _) ∙ transportRefl _ ... | no ¬p = ⊥.rec (¬p refl) ⊕HIT→Fun-pres1 (suc n) with discreteℕ (suc n) 0 ... | yes p = ⊥.rec (snotz p) ... | no ¬p = refl ⊕HIT→⊕Fun-pres1 : ⊕HIT→⊕Fun (base 0 1⋆) ≡ 1⊕Fun ⊕HIT→⊕Fun-pres1 = ΣPathTransport→PathΣ _ _ ((funExt (λ n → ⊕HIT→Fun-pres1 n)) , (squash₁ _ _)) ----------------------------------------------------------------------------- -- Definition of the ring product sumFun : (i n : ℕ) → (i ≤ n) → (f g : (n : ℕ) → G n) → G n sumFun zero n r f g = subst G (sameFiber r) ((f 0) ⋆ (g (n -ℕ 0))) sumFun (ℕ.suc i) n r f g = Gstr n ._+_ (subst G (sameFiber r) ((f (suc i)) ⋆ (g (n -ℕ suc i)))) (sumFun i n (≤-trans ≤-sucℕ r) f g) _prodFun_ : (f g : (n : ℕ) → G n) → (n : ℕ) → G n _prodFun_ f g n = sumFun n n ≤-refl f g -- Proof that it is an almost null sequence prodAn : (f g : (n : ℕ) → G n) → AlmostNull G Gstr f → AlmostNull G Gstr g → AlmostNull G Gstr (f prodFun g) prodAn f g (k , nf) (l , ng) = (k +ℕ l) , λ n pp → sumF0 n n pp ≤-refl where sumF0 : (i n : ℕ) → (pp : k +ℕ l < n) → (r : i ≤ n) → sumFun i n r f g ≡ 0g (Gstr n) sumF0 zero n pp r = cong (subst G (sameFiber r)) (cong (λ X → f 0 ⋆ X) (ng (n -ℕ zero) (<-k+-trans pp)) ∙ ⋆-0 _) ∙ subst0g _ sumF0 (suc i) n pp r with splitℕ-≤ (suc i) k ... | inl x = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (cong (λ X → f (suc i) ⋆ X) (ng (n -ℕ suc i) -- Goal : l < n - suc i -- Proof : l = k + l - k < n - k < n - suc i (subst (λ X → X < n -ℕ suc i) (∸+ l k) (≤<-trans (≤-∸-≥ (k +ℕ l) (suc i) k x) (<-∸-< (k +ℕ l) n (suc i) pp (≤<-trans x (<-+k-trans pp)))))) ∙ ⋆-0 (f (suc i)))) (sumF0 i n pp (≤-trans ≤-sucℕ r)) ∙ +IdR (Gstr n) _ ∙ subst0g _ ... | inr x = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (cong (λ X → X ⋆ g (n -ℕ (suc i))) (nf (suc i) x) ∙ 0-⋆ _)) (sumF0 i n pp (≤-trans ≤-sucℕ r)) ∙ +IdR (Gstr n) _ ∙ subst0g _ _prodF_ : ⊕Fun G Gstr → ⊕Fun G Gstr → ⊕Fun G Gstr _prodF_(f , Anf) (g , Ang) = (f prodFun g) , helper Anf Ang where helper : AlmostNullP G Gstr f → AlmostNullP G Gstr g → AlmostNullP G Gstr (f prodFun g) helper = PT.rec2 squash₁ (λ x y → ∣ (prodAn f g x y) ∣₁) ----------------------------------------------------------------------------- -- Some Ring properties that are needed -- lemma for 0 case prodFunAnnihilL : (f : (n : ℕ) → G n) → 0Fun prodFun f ≡ 0Fun prodFunAnnihilL f = funExt (λ n → sumF0 n n ≤-refl) where sumF0 : (i n : ℕ) → (r : i ≤ n) → sumFun i n r 0Fun f ≡ 0g (Gstr n) sumF0 zero n r = cong (subst G (sameFiber r)) (0-⋆ _) ∙ subst0g _ sumF0 (suc i) n r = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (0-⋆ _)) (sumF0 i n (≤-trans ≤-sucℕ r)) ∙ +IdR (Gstr n) _ ∙ subst0g _ prodFunAnnihilR : (f : (n : ℕ) → (G n)) → f prodFun 0Fun ≡ 0Fun prodFunAnnihilR f = funExt (λ n → sumF0 n n ≤-refl) where sumF0 : (i n : ℕ) → (r : i ≤ n) → sumFun i n r f 0Fun ≡ 0g (Gstr n) sumF0 zero n r = cong (subst G (sameFiber r)) (⋆-0 _) ∙ subst0g _ sumF0 (suc i) n r = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (⋆-0 _)) (sumF0 i n (≤-trans ≤-sucℕ r)) ∙ +IdR (Gstr n) _ ∙ subst0g _ prodFunDistR : (f g h : (n : ℕ) → G n) → f prodFun (g +Fun h) ≡ (f prodFun g) +Fun (f prodFun h) prodFunDistR f g h = funExt (λ n → sumFAssoc n n ≤-refl) where sumFAssoc : (i n : ℕ) → (r : i ≤ n) → sumFun i n r f (g +Fun h) ≡ (Gstr n) ._+_ (sumFun i n r f g) (sumFun i n r f h) sumFAssoc zero n r = cong (subst G (sameFiber r)) (⋆DistR+ _ _ _) ∙ sym (subst+ _ _ _) sumFAssoc (suc i) n r = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (⋆DistR+ _ _ _) ∙ sym (subst+ _ _ _)) (sumFAssoc i n (≤-trans ≤-sucℕ r)) ∙ comm-4 ((G n) , (Gstr n)) _ _ _ _ prodFunDistL : (f g h : (n : ℕ) → G n) → (f +Fun g) prodFun h ≡ (f prodFun h) +Fun (g prodFun h) prodFunDistL f g h = funExt (λ n → sumFAssoc n n ≤-refl) where sumFAssoc : (i n : ℕ) → (r : i ≤ n) → sumFun i n r (f +Fun g) h ≡ (Gstr n) ._+_ (sumFun i n r f h) (sumFun i n r g h) sumFAssoc zero n r = cong (subst G (sameFiber r)) (⋆DistL+ _ _ _) ∙ sym (subst+ _ _ _) sumFAssoc (suc i) n r = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (⋆DistL+ _ _ _) ∙ sym (subst+ _ _ _)) (sumFAssoc i n (≤-trans ≤-sucℕ r)) ∙ comm-4 ((G n) , (Gstr n)) _ _ _ _ ----------------------------------------------------------------------------- -- Preserving the product -- A substitution lemma subst⋆ : {m n k l : ℕ} → (p : m ≡ n) → (q : k ≡ l) → (r : m +n k ≡ n +n l) → (a : G m) → (b : G k) → subst G p a ⋆ subst G q b ≡ subst G r (a ⋆ b) subst⋆ p q r a b = J (λ n p → subst G p a ⋆ subst G q b ≡ subst G (cong₂ _+n_ p q) (a ⋆ b)) (J (λ l q → subst G refl a ⋆ subst G q b ≡ subst G (cong₂ _+n_ refl q) (a ⋆ b)) (cong₂ _⋆_ (transportRefl _) (transportRefl _) ∙ sym (transportRefl _)) q) p ∙ cong (λ X → subst G X (a ⋆ b)) (isSetℕ _ _ _ _) -- Proving the base case open GradedRing-⊕HIT-index (ℕ , (monoidstr 0 _+n_ isM)) G Gstr open GradedRing-⊕HIT-⋆ 1⋆ _⋆_ 0-⋆ ⋆-0 ⋆Assoc ⋆IdR ⋆IdL ⋆DistR+ ⋆DistL+ sumFun≠ : (k : ℕ) → (a : G k) → (l : ℕ) → (b : G l) → (i n : ℕ) → (r : i ≤ n) → (¬pp : k +n l ≡ n → ⊥) → sumFun i n r (fun-trad k a) (fun-trad l b) ≡ 0g (Gstr n) sumFun≠ k a l b zero n r ¬pp with discreteℕ k 0 | discreteℕ l n ... | yes p | yes q = ⊥.rec (¬pp ((k +≡ l) ∙ cong₂ _+ℕ_ p q) ) ... | yes p | no ¬q = cong (subst G (sameFiber r)) (⋆-0 _) ∙ subst0g _ ... | no ¬p | yes q = cong (subst G (sameFiber r)) (0-⋆ _) ∙ subst0g _ ... | no ¬p | no ¬q = cong (subst G (sameFiber r)) (0-⋆ _) ∙ subst0g _ sumFun≠ k a l b (suc i) n r ¬pp with discreteℕ k (suc i) | discreteℕ l (n -ℕ (suc i)) ... | yes p | yes q = ⊥.rec (¬pp (cong₂ _+n_ p q ∙ sameFiber r)) ... | yes p | no ¬q = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (⋆-0 _)) (sumFun≠ k a l b i n (≤-trans ≤-sucℕ r) ¬pp) ∙ +IdR (Gstr n) _ ∙ subst0g _ ... | no ¬p | yes q = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (0-⋆ _)) (sumFun≠ k a l b i n (≤-trans ≤-sucℕ r) ¬pp) ∙ +IdR (Gstr n) _ ∙ subst0g _ ... | no ¬p | no ¬q = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (0-⋆ _)) (sumFun≠ k a l b i n (≤-trans ≤-sucℕ r) ¬pp) ∙ +IdR (Gstr n) _ ∙ subst0g _ -- If k +n l ≡ n then, we unwrap the sum until we reach k. -- Before it is 0, in k the value, then it is 0 sumFun< : (k : ℕ) → (a : G k) → (l : ℕ) → (b : G l) → (i n : ℕ) → (r : i ≤ n) → (i < k) → sumFun i n r (fun-trad k a) (fun-trad l b) ≡ 0g (Gstr n) sumFun< k a l b zero n r pp with discreteℕ k 0 ... | yes p = ⊥.rec (<→≢ pp (sym p)) ... | no ¬p = cong (subst G (sameFiber r)) (0-⋆ _) ∙ subst0g _ sumFun< k a l b (suc i) n r pp with discreteℕ k (suc i) ... | yes p = ⊥.rec (<→≢ pp (sym p)) ... | no ¬p = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (0-⋆ _)) (sumFun< k a l b i n (≤-trans ≤-sucℕ r) (<-trans ≤-refl pp)) ∙ +IdR (Gstr n) _ ∙ subst0g _ sumFun≤ : (k : ℕ) → (a : G k) → (l : ℕ) → (b : G l ) → (i n : ℕ) → (r : i ≤ n) → (pp : k +n l ≡ n) → (k ≤ i) → sumFun i n r (fun-trad k a) (fun-trad l b) ≡ subst G pp (a ⋆ b) sumFun≤ k a l b zero n r pp rr with discreteℕ k 0 | discreteℕ l n ... | yes p | yes q = cong (subst G (sameFiber r)) (subst⋆ p q (pp ∙ sym (+nIdL _)) a b) ∙ sym (substComposite G _ _ _) ∙ cong (λ X → subst G X (a ⋆ b)) (isSetℕ _ _ _ _) ... | yes p | no ¬q = ⊥.rec (¬q (sym (+nIdL l) ∙ cong (λ X → X +n l) (sym p) ∙ pp)) ... | no ¬p | yes q = ⊥.rec (¬p (≤0→≡0 rr)) ... | no ¬p | no ¬q = ⊥.rec (¬p (≤0→≡0 rr)) sumFun≤ k a l b (suc i) n r pp rr with discreteℕ k (suc i) | discreteℕ l (n -ℕ suc i) ... | yes p | yes q = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (subst⋆ p q (pp ∙ sym (sameFiber r)) a b) ∙ sym (substComposite G _ _ _)) (sumFun< k a l b i n (≤-trans ≤-sucℕ r) (0 , (sym p))) ∙ +IdR (Gstr n) _ ∙ cong (λ X → subst G X (a ⋆ b)) (isSetℕ _ _ _ _) ... | yes p | no ¬q = ⊥.rec (¬q (inj-m+ (sym ((suc i) +≡ l) ∙ cong (λ X → X +n l) (sym p) ∙ pp ∙ sym (sameFiber r) ∙ ((suc i) +≡ (n -ℕ suc i))))) ... | no ¬p | yes q = ⊥.rec (¬p (inj-+m (sym (k +≡ (n -ℕ suc i)) ∙ cong (λ X → k +n X) (sym q) ∙ pp ∙ sym (sameFiber r) ∙ ((suc i) +≡ (n -ℕ suc i))))) ... | no ¬p | no ¬q = cong₂ (Gstr n ._+_) (cong (subst G (sameFiber r)) (0-⋆ _) ∙ subst0g _) (sumFun≤ k a l b i n (≤-trans ≤-sucℕ r) pp (≤-suc-≢ rr ¬p)) ∙ +IdL (Gstr n) _ -- If k +n l ≢ n, then it is both zero -- Otherwise, it coincide in (k,l) sumFBase : (k : ℕ) → (a : G k) → (l : ℕ) → (b : G l) → (n : ℕ) → fun-trad (k +n l) (a ⋆ b) n ≡ sumFun n n ≤-refl (fun-trad k a) (fun-trad l b) sumFBase k a l b n with discreteℕ (k +n l) n ... | yes p = sym (sumFun≤ k a l b n n ≤-refl p (l , (+-comm l k ∙ sym (k +≡ l) ∙ p))) ... | no ¬p = sym (sumFun≠ k a l b n n ≤-refl ¬p) -- Proof that ⊕HIT→⊕Fun preserve the cup product ⊕HIT→Fun-pres-prodFun : (x y : ⊕HIT ℕ G Gstr) → ⊕HIT→Fun (x prod y) ≡ ((⊕HIT→Fun x) prodFun (⊕HIT→Fun y)) ⊕HIT→Fun-pres-prodFun = DS-Ind-Prop.f _ _ _ _ (λ x → isPropΠ (λ _ → isSetFun _ _)) (λ y → sym (prodFunAnnihilL (⊕HIT→Fun y))) (λ k a → DS-Ind-Prop.f _ _ _ _ (λ _ → isSetFun _ _) (sym (prodFunAnnihilR (⊕HIT→Fun (base k a)))) (λ l b → funExt λ n → sumFBase k a l b n) λ {U V} ind-U ind-V → cong₂ _+Fun_ ind-U ind-V ∙ sym (prodFunDistR _ _ _)) λ {U} {V} ind-U ind-V y → cong₂ _+Fun_ (ind-U y) (ind-V y) ∙ sym (prodFunDistL _ _ _) ⊕HIT→⊕Fun-pres-prodF : (x y : ⊕HIT ℕ G Gstr) → ⊕HIT→⊕Fun (x prod y) ≡ ((⊕HIT→⊕Fun x) prodF (⊕HIT→⊕Fun y)) ⊕HIT→⊕Fun-pres-prodF x y = ΣPathTransport→PathΣ _ _ ((⊕HIT→Fun-pres-prodFun x y) , (squash₁ _ _)) ----------------------------------------------------------------------------- -- Graded Ring Structure open AbGroupStr (snd (⊕Fun-AbGr G Gstr)) using () renaming ( 0g to 0⊕Fun ; _+_ to _+⊕Fun_ ; -_ to -⊕Fun_ ; is-set to isSet⊕Fun) open IsGroupHom ⊕FunGradedRing-Ring : Ring ℓ ⊕FunGradedRing-Ring = InducedRing ⊕HITgradedRing-Ring 0⊕Fun 1⊕Fun _+⊕Fun_ _prodF_ -⊕Fun_ (fst (Equiv-DirectSum G Gstr)) (pres1 (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres1 (pres· (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres-prodF (presinv (snd (Equiv-DirectSum G Gstr))) RingEquiv-DirectSumGradedRing : RingEquiv ⊕HITgradedRing-Ring ⊕FunGradedRing-Ring RingEquiv-DirectSumGradedRing = InducedRingEquiv ⊕HITgradedRing-Ring 0⊕Fun 1⊕Fun _+⊕Fun_ _prodF_ -⊕Fun_ (fst (Equiv-DirectSum G Gstr)) (pres1 (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres1 (pres· (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres-prodF (presinv (snd (Equiv-DirectSum G Gstr))) ⊕Fun-GradedRing : GradedRing ℓ-zero ℓ ⊕Fun-GradedRing = makeGradedRing ⊕FunGradedRing-Ring (ℕ , (monoidstr 0 _+n_ isM)) G Gstr 1⋆ _⋆_ 0-⋆ ⋆-0 ⋆Assoc ⋆IdR ⋆IdL ⋆DistR+ ⋆DistL+ (RingEquivs.invRingEquiv RingEquiv-DirectSumGradedRing) ----------------------------------------------------------------------------- -- CommRing extension module _ (⋆Comm : {k l : ℕ} → (a : G k) → (b : G l) → _≡_ {A = Σ[ k ∈ ℕ ] G k} ((k +n l) , (a ⋆ b)) ((l +n k) , (b ⋆ a))) where open ExtensionCommRing ⋆Comm ⊕FunGradedRing-CommRing : CommRing ℓ ⊕FunGradedRing-CommRing = InducedCommRing ⊕HITgradedRing-CommRing 0⊕Fun 1⊕Fun _+⊕Fun_ _prodF_ -⊕Fun_ (fst (Equiv-DirectSum G Gstr)) (pres1 (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres1 (pres· (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres-prodF (presinv (snd (Equiv-DirectSum G Gstr))) CommRingEquiv-DirectSumGradedRing : CommRingEquiv ⊕HITgradedRing-CommRing ⊕FunGradedRing-CommRing CommRingEquiv-DirectSumGradedRing = InducedCommRingEquiv ⊕HITgradedRing-CommRing 0⊕Fun 1⊕Fun _+⊕Fun_ _prodF_ -⊕Fun_ (fst (Equiv-DirectSum G Gstr)) (pres1 (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres1 (pres· (snd (Equiv-DirectSum G Gstr))) ⊕HIT→⊕Fun-pres-prodF (presinv (snd (Equiv-DirectSum G Gstr)))
47.237209
122
0.425758
41419a3cd21500009c60c3e1a383367c46eb43d3
8,158
agda
Agda
Cubical/Algebra/Monoid/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Algebra/Monoid/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Algebra/Monoid/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Monoid.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Record open import Cubical.Algebra.Semigroup open Iso private variable ℓ : Level record IsMonoid {A : Type ℓ} (ε : A) (_·_ : A → A → A) : Type ℓ where constructor ismonoid field isSemigroup : IsSemigroup _·_ identity : (x : A) → (x · ε ≡ x) × (ε · x ≡ x) open IsSemigroup isSemigroup public lid : (x : A) → ε · x ≡ x lid x = identity x .snd rid : (x : A) → x · ε ≡ x rid x = identity x .fst record MonoidStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor monoidstr field ε : A _·_ : A → A → A isMonoid : IsMonoid ε _·_ infixl 7 _·_ open IsMonoid isMonoid public -- semigrp : Semigroup -- semigrp = record { isSemigroup = isSemigroup } -- open Semigroup semigrp public Monoid : Type (ℓ-suc ℓ) Monoid = TypeWithStr _ MonoidStr monoid : (A : Type ℓ) (ε : A) (_·_ : A → A → A) (h : IsMonoid ε _·_) → Monoid monoid A ε _·_ h = A , monoidstr ε _·_ h -- Easier to use constructors makeIsMonoid : {M : Type ℓ} {ε : M} {_·_ : M → M → M} (is-setM : isSet M) (assoc : (x y z : M) → x · (y · z) ≡ (x · y) · z) (rid : (x : M) → x · ε ≡ x) (lid : (x : M) → ε · x ≡ x) → IsMonoid ε _·_ IsMonoid.isSemigroup (makeIsMonoid is-setM assoc rid lid) = issemigroup is-setM assoc IsMonoid.identity (makeIsMonoid is-setM assoc rid lid) = λ x → rid x , lid x makeMonoid : {M : Type ℓ} (ε : M) (_·_ : M → M → M) (is-setM : isSet M) (assoc : (x y z : M) → x · (y · z) ≡ (x · y) · z) (rid : (x : M) → x · ε ≡ x) (lid : (x : M) → ε · x ≡ x) → Monoid makeMonoid ε _·_ is-setM assoc rid lid = monoid _ ε _·_ (makeIsMonoid is-setM assoc rid lid) record MonoidEquiv (M N : Monoid {ℓ}) (e : ⟨ M ⟩ ≃ ⟨ N ⟩) : Type ℓ where constructor monoidiso private module M = MonoidStr (snd M) module N = MonoidStr (snd N) field presε : equivFun e M.ε ≡ N.ε isHom : (x y : ⟨ M ⟩) → equivFun e (x M.· y) ≡ equivFun e x N.· equivFun e y module MonoidΣTheory {ℓ} where RawMonoidStructure : Type ℓ → Type ℓ RawMonoidStructure X = X × (X → X → X) RawMonoidEquivStr = AutoEquivStr RawMonoidStructure rawMonoidUnivalentStr : UnivalentStr _ RawMonoidEquivStr rawMonoidUnivalentStr = autoUnivalentStr RawMonoidStructure MonoidAxioms : (M : Type ℓ) → RawMonoidStructure M → Type ℓ MonoidAxioms M (e , _·_) = IsSemigroup _·_ × ((x : M) → (x · e ≡ x) × (e · x ≡ x)) MonoidStructure : Type ℓ → Type ℓ MonoidStructure = AxiomsStructure RawMonoidStructure MonoidAxioms MonoidΣ : Type (ℓ-suc ℓ) MonoidΣ = TypeWithStr ℓ MonoidStructure isPropMonoidAxioms : (M : Type ℓ) (s : RawMonoidStructure M) → isProp (MonoidAxioms M s) isPropMonoidAxioms M (e , _·_) = isPropΣ (isPropIsSemigroup _·_) λ α → isPropΠ λ _ → isProp× (IsSemigroup.is-set α _ _) (IsSemigroup.is-set α _ _) MonoidEquivStr : StrEquiv MonoidStructure ℓ MonoidEquivStr = AxiomsEquivStr RawMonoidEquivStr MonoidAxioms MonoidAxiomsIsoIsMonoid : {M : Type ℓ} (s : RawMonoidStructure M) → Iso (MonoidAxioms M s) (IsMonoid (s .fst) (s .snd)) fun (MonoidAxiomsIsoIsMonoid s) (x , y) = ismonoid x y inv (MonoidAxiomsIsoIsMonoid s) a = (IsMonoid.isSemigroup a) , IsMonoid.identity a rightInv (MonoidAxiomsIsoIsMonoid s) _ = refl leftInv (MonoidAxiomsIsoIsMonoid s) _ = refl MonoidAxioms≡IsMonoid : {M : Type ℓ} (s : RawMonoidStructure M) → MonoidAxioms M s ≡ IsMonoid (s .fst) (s .snd) MonoidAxioms≡IsMonoid s = isoToPath (MonoidAxiomsIsoIsMonoid s) open MonoidStr Monoid→MonoidΣ : Monoid → MonoidΣ Monoid→MonoidΣ (A , M) = A , (ε M , _·_ M) , MonoidAxiomsIsoIsMonoid (ε M , _·_ M) .inv (isMonoid M) MonoidΣ→Monoid : MonoidΣ → Monoid MonoidΣ→Monoid (M , (ε , _·_) , isMonoidΣ) = monoid M ε _·_ (MonoidAxiomsIsoIsMonoid (ε , _·_) .fun isMonoidΣ) MonoidIsoMonoidΣ : Iso Monoid MonoidΣ MonoidIsoMonoidΣ = iso Monoid→MonoidΣ MonoidΣ→Monoid (λ _ → refl) (λ _ → refl) monoidUnivalentStr : UnivalentStr MonoidStructure MonoidEquivStr monoidUnivalentStr = axiomsUnivalentStr _ isPropMonoidAxioms rawMonoidUnivalentStr MonoidΣPath : (M N : MonoidΣ) → (M ≃[ MonoidEquivStr ] N) ≃ (M ≡ N) MonoidΣPath = SIP monoidUnivalentStr MonoidEquivΣ : (M N : Monoid) → Type ℓ MonoidEquivΣ M N = Monoid→MonoidΣ M ≃[ MonoidEquivStr ] Monoid→MonoidΣ N MonoidIsoΣPath : {M N : Monoid} → Iso (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] (MonoidEquiv M N e)) (MonoidEquivΣ M N) fun MonoidIsoΣPath (e , monoidiso h1 h2) = (e , h1 , h2) inv MonoidIsoΣPath (e , h1 , h2) = (e , monoidiso h1 h2) rightInv MonoidIsoΣPath _ = refl leftInv MonoidIsoΣPath _ = refl MonoidPath : (M N : Monoid {ℓ}) → (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] (MonoidEquiv M N e)) ≃ (M ≡ N) MonoidPath M N = Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] MonoidEquiv M N e ≃⟨ isoToEquiv MonoidIsoΣPath ⟩ MonoidEquivΣ M N ≃⟨ MonoidΣPath _ _ ⟩ Monoid→MonoidΣ M ≡ Monoid→MonoidΣ N ≃⟨ isoToEquiv (invIso (congIso MonoidIsoMonoidΣ)) ⟩ M ≡ N ■ RawMonoidΣ : Type (ℓ-suc ℓ) RawMonoidΣ = TypeWithStr ℓ RawMonoidStructure Monoid→RawMonoidΣ : Monoid → RawMonoidΣ Monoid→RawMonoidΣ (A , M) = A , (ε M) , (_·_ M) InducedMonoid : (M : Monoid) (N : RawMonoidΣ) (e : M .fst ≃ N .fst) → RawMonoidEquivStr (Monoid→RawMonoidΣ M) N e → Monoid InducedMonoid M N e r = MonoidΣ→Monoid (inducedStructure rawMonoidUnivalentStr (Monoid→MonoidΣ M) N (e , r)) InducedMonoidPath : (M : Monoid {ℓ}) (N : RawMonoidΣ) (e : M .fst ≃ N .fst) (E : RawMonoidEquivStr (Monoid→RawMonoidΣ M) N e) → M ≡ InducedMonoid M N e E InducedMonoidPath M N e E = MonoidPath M (InducedMonoid M N e E) .fst (e , monoidiso (E .fst) (E .snd)) -- We now extract the important results from the above module isPropIsMonoid : {M : Type ℓ} (ε : M) (_·_ : M → M → M) → isProp (IsMonoid ε _·_) isPropIsMonoid ε _·_ = subst isProp (MonoidΣTheory.MonoidAxioms≡IsMonoid (ε , _·_)) (MonoidΣTheory.isPropMonoidAxioms _ (ε , _·_)) MonoidPath : (M N : Monoid {ℓ}) → (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] MonoidEquiv M N e) ≃ (M ≡ N) MonoidPath {ℓ = ℓ} = SIP (autoUnivalentRecord (autoRecordSpec (MonoidStr {ℓ}) MonoidEquiv (fields: data[ ε ∣ presε ] data[ _·_ ∣ isHom ] prop[ isMonoid ∣ (λ _ → isPropIsMonoid _ _) ])) _ _) where open MonoidStr open MonoidEquiv InducedMonoid : (M : Monoid {ℓ}) (N : MonoidΣTheory.RawMonoidΣ) (e : M .fst ≃ N .fst) → MonoidΣTheory.RawMonoidEquivStr (MonoidΣTheory.Monoid→RawMonoidΣ M) N e → Monoid InducedMonoid = MonoidΣTheory.InducedMonoid InducedMonoidPath : (M : Monoid {ℓ}) (N : MonoidΣTheory.RawMonoidΣ) (e : M .fst ≃ N .fst) (E : MonoidΣTheory.RawMonoidEquivStr (MonoidΣTheory.Monoid→RawMonoidΣ M) N e) → M ≡ InducedMonoid M N e E InducedMonoidPath = MonoidΣTheory.InducedMonoidPath module MonoidTheory {ℓ} (M : Monoid {ℓ}) where open MonoidStr (snd M) -- Added for its use in groups -- If there exists a inverse of an element it is unique inv-lemma : (x y z : ⟨ M ⟩) → y · x ≡ ε → x · z ≡ ε → y ≡ z inv-lemma x y z left-inverse right-inverse = y ≡⟨ sym (rid y) ⟩ y · ε ≡⟨ cong (λ - → y · -) (sym right-inverse) ⟩ y · (x · z) ≡⟨ assoc y x z ⟩ (y · x) · z ≡⟨ cong (λ - → - · z) left-inverse ⟩ ε · z ≡⟨ lid z ⟩ z ∎
34.567797
103
0.620863
d023c80feddbba23408f4094d9f4d13944c7b5f4
3,619
agda
Agda
Data/List/Relation/Quantification/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Data/List/Relation/Quantification/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Data/List/Relation/Quantification/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Data.List.Relation.Quantification.Proofs where import Lvl open import Data.List open import Data.List.Functions open import Data.List.Equiv.Id open import Data.List.Relation.Permutation open import Data.List.Relation.Quantification open import Functional open import Logic.Propositional open import Logic open import Structure.Relator.Properties open import Type.Dependent open import Type private variable ℓ : Lvl.Level private variable T A B C : Type{ℓ} private variable l l₁ l₂ : List(T) private variable ll : List(List(T)) private variable x : T private variable P Q : T → Stmt{ℓ} private variable Q₂ : A → B → Stmt{ℓ} private variable _▫_ : T → T → Stmt{ℓ} AllElements-map : (f : A → B) → (g : A → C) → (∀{x} → P(f(x)) → Q(g(x))) → (AllElements P(map f(l)) → AllElements Q(map g(l))) AllElements-map {l = ∅} f g pq ∅ = ∅ AllElements-map {l = x ⊰ l} f g pq (p ⊰ ap) = pq p ⊰ AllElements-map f g pq ap AllElements-mapᵣ : (f : A → B) → (∀{x} → P(x) → Q(f(x))) → (AllElements P l → AllElements Q (map f(l))) AllElements-mapᵣ = AllElements-map id AllElements-mapₗ : (f : A → B) → (∀{x} → P(f(x)) → Q(x)) → (AllElements P (map f(l)) → AllElements Q l) AllElements-mapₗ f = AllElements-map f id AllElements-fn : (∀{x} → P(x) → Q(x)) → (AllElements P l → AllElements Q l) AllElements-fn = AllElements-map id id AllElements-[++] : AllElements P l₁ → AllElements P l₂ → AllElements P (l₁ ++ l₂) AllElements-[++] {l₁ = ∅} p q = q AllElements-[++] {l₁ = _ ⊰ _} (x ⊰ p) q = x ⊰ AllElements-[++] p q AllElements-concat : (AllElements (AllElements P) l → AllElements P (concat l)) AllElements-concat ∅ = ∅ AllElements-concat (p ⊰ pl) = AllElements-[++] p (AllElements-concat pl) AllElements-concatMap : (f : A → List(B)) → (∀{x} → P(x) → AllElements Q(f(x))) → (AllElements P(l) → AllElements Q(concatMap f(l))) AllElements-concatMap f pq ∅ = ∅ AllElements-concatMap f pq (x ⊰ p) = AllElements-[++] (pq x) (AllElements-concatMap f pq p) AllElements-order-independent : ∀{P : T → Type{ℓ}}{l₁ l₂} → (l₁ permutes l₂) → (AllElements P(l₁) → AllElements P(l₂)) AllElements-order-independent _permutes_.empty ∅ = ∅ AllElements-order-independent (_permutes_.prepend perm) (x ⊰ p) = x ⊰ AllElements-order-independent perm p AllElements-order-independent _permutes_.swap (x ⊰ y ⊰ p) = y ⊰ x ⊰ p AllElements-order-independent (trans perm₁ perm₂) = AllElements-order-independent perm₂ ∘ AllElements-order-independent perm₁ AllElements-of-transitive-binary-relationₗ : ⦃ trans : Transitivity(_▫_) ⦄ → (l₁ ▫ l₂) → (AllElements (_▫ l₁) ll → AllElements (_▫ l₂) ll) AllElements-of-transitive-binary-relationₗ _ ∅ = ∅ AllElements-of-transitive-binary-relationₗ {_▫_ = _▫_} p (a ⊰ al) = transitivity(_▫_) a p ⊰ AllElements-of-transitive-binary-relationₗ p al AllElements-of-transitive-binary-relationᵣ : ⦃ trans : Transitivity(_▫_) ⦄ → (l₂ ▫ l₁) → (AllElements (l₁ ▫_) ll → AllElements (l₂ ▫_) ll) AllElements-of-transitive-binary-relationᵣ _ ∅ = ∅ AllElements-of-transitive-binary-relationᵣ {_▫_ = _▫_} p (a ⊰ al) = (transitivity(_▫_) p a) ⊰ AllElements-of-transitive-binary-relationᵣ p al AllElements-sigma : Σ(List(T)) (AllElements(P)) ↔ List(Σ T P) AllElements-sigma = [↔]-intro L R where L : Σ(List(T)) (AllElements(P)) ← List(Σ T P) L ∅ = intro ∅ ∅ L ((intro x p) ⊰ sl) = let (intro l pl) = L sl in intro (x ⊰ l) (p ⊰ pl) R : Σ(List(T)) (AllElements(P)) → List(Σ T P) R (intro ∅ ∅) = ∅ R (intro (x ⊰ l) (p ⊰ pl)) = intro x p ⊰ R(intro l pl)
48.253333
143
0.640785
29986c79bed1789767fa9c46c52afb13462e99cf
179
agda
Agda
test/Fail/Issue2386BuiltinReflExtraArg.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2386BuiltinReflExtraArg.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2386BuiltinReflExtraArg.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-01-12, issue #2386 postulate B : Set data _≡_ {A : Set} (x : A) : A → Set where refl : (b : B) → x ≡ x {-# BUILTIN EQUALITY _≡_ #-} -- Wrong type of REFL
14.916667
42
0.547486
2f91bfc1ebee8aaec7d5d1329fc8110225006276
11,098
agda
Agda
models/IDesc.agda
dataronio/epigram2
17b7858f51a35b3becb8433028c3f1ba25fbba9a
[ "MIT" ]
48
2016-01-09T17:36:19.000Z
2022-02-11T01:55:28.000Z
models/IDesc.agda
seanwallawalla-forks/Epigram
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
[ "MIT" ]
null
null
null
models/IDesc.agda
seanwallawalla-forks/Epigram
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
[ "MIT" ]
12
2016-08-14T21:36:35.000Z
2022-02-11T01:57:40.000Z
{-# OPTIONS --universe-polymorphism #-} module IDesc where --******************************************** -- Prelude --******************************************** -- Some preliminary stuffs, to avoid relying on the stdlib --**************** -- Universe polymorphism --**************** data Level : Set where zero : Level suc : Level -> Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO zero #-} {-# BUILTIN LEVELSUC suc #-} max : Level -> Level -> Level max zero m = m max (suc n) zero = suc n max (suc n) (suc m) = suc (max n m) {-# BUILTIN LEVELMAX max #-} data Lifted {l : Level} (A : Set l) : Set (suc l) where lifter : A → Lifted A lift : {i : Level} -> Set i -> Set (suc i) lift x = Lifted x unlift : {l : Level}{A : Set l} -> Lifted A -> A unlift (lifter a) = a --**************** -- Sigma and friends --**************** data Sigma {i j : Level}(A : Set i) (B : A -> Set j) : Set (max i j) where _,_ : (x : A) (y : B x) -> Sigma A B pair : {i j : Level}{A : Set i}{B : A -> Set j} -> (x : A) (y : B x) -> Sigma {i = i}{j = j} A B pair x y = x , y _*_ : {i j : Level}(A : Set i)(B : Set j) -> Set (max i j) A * B = Sigma A \_ -> B fst : {i j : Level}{A : Set i}{B : A -> Set j} -> Sigma A B -> A fst (a , _) = a snd : {i j : Level}{A : Set i}{B : A -> Set j} (p : Sigma A B) -> B (fst p) snd (a , b) = b data Zero {i : Level} : Set i where data Unit {i : Level} : Set i where Void : Unit --**************** -- Sum and friends --**************** data _+_ {i j : Level}(A : Set i)(B : Set j) : Set (max i j) where l : A -> A + B r : B -> A + B --**************** -- Equality --**************** data _==_ {l : Level}{A : Set l}(x : A) : A -> Set l where refl : x == x cong : {l m : Level}{A : Set l}{B : Set m} (f : A -> B){x y : A} -> x == y -> f x == f y cong f refl = refl cong2 : {l m n : Level}{A : Set l}{B : Set m}{C : Set n} (f : A -> B -> C){x y : A}{z t : B} -> x == y -> z == t -> f x z == f y t cong2 f refl refl = refl trans : {l : Level}{A : Set l}{x y z : A} -> x == y -> y == z -> x == z trans refl refl = refl proof-lift-unlift-eq : {l : Level}{A : Set l}(x : Lifted A) -> lifter (unlift x) == x proof-lift-unlift-eq (lifter a) = refl postulate reflFun : {l m : Level}{A : Set l}{B : Set m}(f : A -> B)(g : A -> B)-> ((a : A) -> f a == g a) -> f == g --******************************************** -- Desc code --******************************************** data IDesc {l : Level}(I : Set (suc l)) : Set (suc l) where var : I -> IDesc I const : Set l -> IDesc I prod : IDesc I -> IDesc I -> IDesc I sigma : (S : Set l) -> (S -> IDesc I) -> IDesc I pi : (S : Set l) -> (S -> IDesc I) -> IDesc I --******************************************** -- Desc interpretation --******************************************** desc : {l : Level}{I : Set (suc l)} -> IDesc I -> (I -> Set l) -> Set l 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 = Sigma S (\s -> desc (T s) P) desc (pi S T) P = (s : S) -> desc (T s) P --******************************************** -- Fixpoint construction --******************************************** data IMu {l : Level}{I : Set (suc l)}(R : I -> IDesc {l = l} I)(i : I) : Set l where con : desc (R i) (\j -> IMu R j) -> IMu R i --******************************************** -- Predicate: Box --******************************************** box : {l : Level}{I : Set (suc l)}(D : IDesc I)(X : I -> Set l) -> desc D X -> IDesc (Sigma I X) box (var i) X x = var (i , x) box (const _) X x = const Unit box (prod D D') X (d , d') = prod (box D X d) (box D' X d') box (sigma S T) X (a , b) = box (T a) X b box (pi S T) X f = pi S (\s -> box (T s) X (f s)) --******************************************** -- Elimination principle: induction --******************************************** module Elim {l : Level} {I : Set (suc l)} (R : I -> IDesc I) (P : Sigma I (IMu R) -> Set l) (m : (i : I) (xs : desc (R i) (IMu R)) (hs : desc (box (R i) (IMu R) xs) P) -> P ( i , con xs )) where mutual induction : (i : I)(x : IMu R i) -> P (i , x) induction i (con xs) = m i xs (hyps (R i) xs) hyps : (D : IDesc I) -> (xs : desc D (IMu R)) -> desc (box D (IMu R) xs) P hyps (var i) x = induction i x hyps (const X) x = Void hyps (prod D D') (d , d') = hyps D d , hyps D' d' hyps (pi S R) f = \ s -> hyps (R s) (f s) hyps (sigma S R) ( a , b ) = hyps (R a) b induction : {l : Level} {I : Set (suc l)} (R : I -> IDesc I) (P : Sigma I (IMu R) -> Set l) (m : (i : I) (xs : desc (R i) (IMu R)) (hs : desc (box (R i) (IMu R) xs) P) -> P ( i , con xs)) -> (i : I)(x : IMu R i) -> P ( i , x ) induction = Elim.induction --******************************************** -- DescD --******************************************** data DescDConst {l : Level} : Set l where lvar : DescDConst lconst : DescDConst lprod : DescDConst lpi : DescDConst lsigma : DescDConst descDChoice : {l : Level} -> Set (suc l) -> DescDConst -> IDesc Unit descDChoice I lvar = const I descDChoice _ lconst = const (Set _) descDChoice _ lprod = prod (var Void) (var Void) descDChoice _ lpi = sigma (Set _) (\S -> pi (lift S) (\s -> var Void)) descDChoice _ lsigma = sigma (Set _) (\S -> pi (lift S) (\s -> var Void)) IDescD : {l : Level}(I : Set (suc l)) -> IDesc {l = suc l} Unit IDescD I = sigma DescDConst (descDChoice I) IDescl0 : {l : Level}(I : Set (suc l)) -> Unit -> Set (suc l) IDescl0 {x} I = IMu {l = suc x} (\_ -> IDescD {l = x} I) IDescl : {l : Level}(I : Set (suc l)) -> Set (suc l) IDescl I = IDescl0 I Void varl : {l : Level}{I : Set (suc l)}(i : I) -> IDescl I varl {x} i = con (lvar {l = suc x} , i) constl : {l : Level}{I : Set (suc l)}(X : Set l) -> IDescl I constl {x} X = con (lconst {l = suc x} , X) prodl : {l : Level}{I : Set (suc l)}(D D' : IDescl I) -> IDescl I prodl {x} D D' = con (lprod {l = suc x} , (D , D')) pil : {l : Level}{I : Set (suc l)}(S : Set l)(T : S -> IDescl I) -> IDescl I pil {x} S T = con (lpi {l = suc x} , pair {i = suc x}{j = suc x} S (\s -> T (unlift s))) sigmal : {l : Level}{I : Set (suc l)}(S : Set l)(T : S -> IDescl I) -> IDescl I sigmal {x} S T = con (lsigma {l = suc x} , pair {i = suc x}{j = suc x} S (\s -> T (unlift s))) --******************************************** -- From the embedding to the host --******************************************** cases : {l : Level} {I : Set (suc l)} (xs : desc (IDescD I) (IMu (λ _ -> IDescD I))) (hs : desc (box (IDescD I) (IMu (λ _ -> IDescD I)) xs) (λ _ -> IDesc I)) -> IDesc I cases ( lvar , i ) hs = var i cases ( lconst , X ) hs = const X cases ( lprod , (D , D') ) ( d , d' ) = prod d d' cases ( lpi , ( S , T ) ) hs = pi S (\s -> hs (lifter s) ) cases ( lsigma , ( S , T ) ) hs = sigma S (\s -> hs (lifter s)) phi : {l : Level}{I : Set (suc l)} -> IDescl I -> IDesc I phi {x} {I} d = induction (\_ -> IDescD I) (\_ -> IDesc I) (\_ -> cases) Void d --******************************************** -- From the host to the embedding --******************************************** psi : {l : Level}{I : Set (suc l)} -> IDesc I -> IDescl I psi (var i) = varl i psi (const X) = constl X psi (prod D D') = prodl (psi D) (psi D') psi (pi S T) = pil S (\s -> psi (T s)) psi (sigma S T) = sigmal S (\s -> psi (T s)) --******************************************** -- Isomorphism proof --******************************************** -- From host to host proof-phi-psi : {l : Level}{I : Set (suc l)} -> (D : IDesc I) -> phi (psi D) == D proof-phi-psi (var i) = refl proof-phi-psi (const x) = refl proof-phi-psi (prod D D') with proof-phi-psi D | proof-phi-psi D' ... | p | q = cong2 prod p q proof-phi-psi {x} (pi S T) = cong (pi S) (reflFun (\s -> phi (psi (T s))) T (\s -> proof-phi-psi (T s))) proof-phi-psi (sigma S T) = cong (sigma S) (reflFun (\ s -> phi (psi (T s))) T (\s -> proof-phi-psi (T s))) -- From embedding to embedding proof-psi-phi : {l : Level}(I : Set (suc l)) -> (D : IDescl I) -> psi (phi D) == D proof-psi-phi {x} I D = induction (\ _ -> IDescD I) P proof-psi-phi-cases Void D where P : Sigma Unit (IMu (\ x -> IDescD I)) -> Set (suc x) P ( Void , D ) = psi (phi D) == D proof-psi-phi-cases : (i : Unit) (xs : desc (IDescD I) (IDescl0 I)) (hs : desc (box (IDescD I) (IDescl0 I) xs) P) -> P (i , con xs) proof-psi-phi-cases Void (lvar , i) hs = refl proof-psi-phi-cases Void (lconst , x) hs = refl proof-psi-phi-cases Void (lprod , ( D , D' )) ( p , q ) = cong2 prodl p q proof-psi-phi-cases Void (lpi , ( S , T )) hs = cong (\T -> con (lpi {l = suc x} , ( S , T ) )) (trans (reflFun (\ s -> psi (phi (T (lifter (unlift s))))) (\ s -> psi (phi (T (s)))) (\s -> cong (\ s -> psi (phi (T (s)))) (proof-lift-unlift-eq s))) (reflFun (\s -> psi (phi (T s))) T hs)) proof-psi-phi-cases Void (lsigma , ( S , T )) hs = cong (\T -> con (lsigma {l = suc x} , ( S , T ) )) (trans (reflFun (\ s → psi (phi (T (lifter (unlift s))))) (\ s → psi (phi (T (s)))) (\s -> cong (\ s -> psi (phi (T (s)))) (proof-lift-unlift-eq s))) (reflFun (\s -> psi (phi (T s))) T hs))
36.748344
123
0.376825
c5753eb40854e225914c24ff580db94853e00253
4,476
agda
Agda
agda-stdlib/src/Data/Container/Combinator/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Container/Combinator/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Container/Combinator/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Correctness proofs for container combinators ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Container.Combinator.Properties where open import Axiom.Extensionality.Propositional using (Extensionality) open import Data.Container.Core open import Data.Container.Combinator open import Data.Container.Relation.Unary.Any open import Data.Empty using (⊥-elim) open import Data.Product as Prod using (∃; _,_; proj₁; proj₂; <_,_>; uncurry; curry) open import Data.Sum.Base as S using (inj₁; inj₂; [_,_]′; [_,_]) open import Function as F using (_∘′_) open import Function.Inverse as Inv using (_↔_; inverse; module Inverse) open import Level using (_⊔_; lower) open import Relation.Binary.PropositionalEquality as P using (_≡_; _≗_) -- I have proved some of the correctness statements under the -- assumption of functional extensionality. I could have reformulated -- the statements using suitable setoids, but I could not be bothered. module Identity where correct : ∀ {s p x} {X : Set x} → ⟦ id {s} {p} ⟧ X ↔ F.id X correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl) where to : ⟦ id ⟧ X → F.id X to xs = proj₂ xs _ from : F.id X → ⟦ id ⟧ X from x = (_ , λ _ → x) module Constant (ext : ∀ {ℓ ℓ′} → Extensionality ℓ ℓ′) where correct : ∀ {x p y} (X : Set x) {Y : Set y} → ⟦ const {x} {p ⊔ y} X ⟧ Y ↔ F.const X Y correct {x} {y} X {Y} = inverse proj₁ from from∘to λ _ → P.refl where from : X → ⟦ const X ⟧ Y from = < F.id , F.const (⊥-elim ∘′ lower) > from∘to : (x : ⟦ const X ⟧ Y) → from (proj₁ x) ≡ x from∘to xs = P.cong (proj₁ xs ,_) (ext (λ x → ⊥-elim (lower x))) module Composition {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where correct : ∀ {x} {X : Set x} → ⟦ C₁ ∘ C₂ ⟧ X ↔ (⟦ C₁ ⟧ F.∘ ⟦ C₂ ⟧) X correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl) where to : ⟦ C₁ ∘ C₂ ⟧ X → ⟦ C₁ ⟧ (⟦ C₂ ⟧ X) to ((s , f) , g) = (s , < f , curry (g ∘′ any) >) from : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X) → ⟦ C₁ ∘ C₂ ⟧ X from (s , f) = ((s , proj₁ F.∘ f) , uncurry (proj₂ F.∘ f) ∘′ ◇.proof) module Product (ext : ∀ {ℓ ℓ′} → Extensionality ℓ ℓ′) {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where correct : ∀ {x} {X : Set x} → ⟦ C₁ × C₂ ⟧ X ↔ (⟦ C₁ ⟧ X Prod.× ⟦ C₂ ⟧ X) correct {X = X} = inverse to from from∘to (λ _ → P.refl) where to : ⟦ C₁ × C₂ ⟧ X → ⟦ C₁ ⟧ X Prod.× ⟦ C₂ ⟧ X to ((s₁ , s₂) , f) = ((s₁ , f F.∘ inj₁) , (s₂ , f F.∘ inj₂)) from : ⟦ C₁ ⟧ X Prod.× ⟦ C₂ ⟧ X → ⟦ C₁ × C₂ ⟧ X from ((s₁ , f₁) , (s₂ , f₂)) = ((s₁ , s₂) , [ f₁ , f₂ ]′) from∘to : from F.∘ to ≗ F.id from∘to (s , f) = P.cong (s ,_) (ext [ (λ _ → P.refl) , (λ _ → P.refl) ]) module IndexedProduct {i s p} {I : Set i} (Cᵢ : I → Container s p) where correct : ∀ {x} {X : Set x} → ⟦ Π I Cᵢ ⟧ X ↔ (∀ i → ⟦ Cᵢ i ⟧ X) correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl) where to : ⟦ Π I Cᵢ ⟧ X → ∀ i → ⟦ Cᵢ i ⟧ X to (s , f) = λ i → (s i , λ p → f (i , p)) from : (∀ i → ⟦ Cᵢ i ⟧ X) → ⟦ Π I Cᵢ ⟧ X from f = (proj₁ F.∘ f , uncurry (proj₂ F.∘ f)) module Sum {s₁ s₂ p} (C₁ : Container s₁ p) (C₂ : Container s₂ p) where correct : ∀ {x} {X : Set x} → ⟦ C₁ ⊎ C₂ ⟧ X ↔ (⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X) correct {X = X} = inverse to from from∘to to∘from where to : ⟦ C₁ ⊎ C₂ ⟧ X → ⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X to (inj₁ s₁ , f) = inj₁ (s₁ , f) to (inj₂ s₂ , f) = inj₂ (s₂ , f) from : ⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X → ⟦ C₁ ⊎ C₂ ⟧ X from = [ Prod.map inj₁ F.id , Prod.map inj₂ F.id ]′ from∘to : from F.∘ to ≗ F.id from∘to (inj₁ s₁ , f) = P.refl from∘to (inj₂ s₂ , f) = P.refl to∘from : to F.∘ from ≗ F.id to∘from = [ (λ _ → P.refl) , (λ _ → P.refl) ] module IndexedSum {i s p} {I : Set i} (C : I → Container s p) where correct : ∀ {x} {X : Set x} → ⟦ Σ I C ⟧ X ↔ (∃ λ i → ⟦ C i ⟧ X) correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl) where to : ⟦ Σ I C ⟧ X → ∃ λ i → ⟦ C i ⟧ X to ((i , s) , f) = (i , (s , f)) from : (∃ λ i → ⟦ C i ⟧ X) → ⟦ Σ I C ⟧ X from (i , (s , f)) = ((i , s) , f) module ConstantExponentiation {i s p} {I : Set i} (C : Container s p) where correct : ∀ {x} {X : Set x} → ⟦ const[ I ]⟶ C ⟧ X ↔ (I → ⟦ C ⟧ X) correct = IndexedProduct.correct (F.const C)
36.688525
87
0.510724
4185131bd28719fa68bd6a2f175542705b7aa9b6
1,072
agda
Agda
Cubical/Structures/Group/Morphism.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Structures/Group/Morphism.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Structures/Group/Morphism.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Structures.Group.Morphism where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Structures.Group.Base private variable ℓ ℓ' : Level -- The following definition of GroupHom and GroupEquiv are level-wise heterogeneous. -- This allows for example to deduce that G ≡ F from a chain of isomorphisms -- G ≃ H ≃ F, even if H does not lie in the same level as G and F. isGroupHom : (G : Group {ℓ}) (H : Group {ℓ'}) (f : ⟨ G ⟩ → ⟨ H ⟩) → Type _ isGroupHom G H f = (x y : ⟨ G ⟩) → f (x G.+ y) ≡ (f x H.+ f y) where module G = Group G module H = Group H record GroupHom (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor grouphom field fun : ⟨ G ⟩ → ⟨ H ⟩ isHom : isGroupHom G H fun record GroupEquiv (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor groupequiv field eq : ⟨ G ⟩ ≃ ⟨ H ⟩ isHom : isGroupHom G H (equivFun eq) hom : GroupHom G H hom = grouphom (equivFun eq) isHom
28.210526
84
0.641791
d0918b929c485657077be8602d90e41040604ae7
2,266
agda
Agda
src/sbconst2.agda
shinji-kono/automaton-in-agda
eba0538f088f3d0c0fedb19c47c081954fbc69cb
[ "MIT" ]
null
null
null
src/sbconst2.agda
shinji-kono/automaton-in-agda
eba0538f088f3d0c0fedb19c47c081954fbc69cb
[ "MIT" ]
null
null
null
src/sbconst2.agda
shinji-kono/automaton-in-agda
eba0538f088f3d0c0fedb19c47c081954fbc69cb
[ "MIT" ]
null
null
null
module sbconst2 where open import Level renaming ( suc to succ ; zero to Zero ) open import Data.Nat open import Data.Fin open import Data.List open import automaton open import nfa open import logic open NAutomaton open Automaton open import Relation.Binary.PropositionalEquality hiding ( [_] ) open Bool δconv : { Q : Set } { Σ : Set } → ( ( Q → Bool ) → Bool ) → ( nδ : Q → Σ → Q → Bool ) → (f : Q → Bool) → (i : Σ) → (Q → Bool) δconv {Q} { Σ} exists nδ f i q = exists ( λ r → f r /\ nδ r i q ) subset-construction : { Q : Set } { Σ : Set } → ( ( Q → Bool ) → Bool ) → (NAutomaton Q Σ ) → (Automaton (Q → Bool) Σ ) subset-construction {Q} { Σ} exists NFA = record { δ = λ q x → δconv exists ( Nδ NFA ) q x ; aend = λ f → exists ( λ q → f q /\ Nend NFA q ) } test4 = subset-construction existsS1 am2 test51 = accept test4 start1 ( i0 ∷ i1 ∷ i0 ∷ [] ) test61 = accept test4 start1 ( i1 ∷ i1 ∷ i1 ∷ [] ) subset-construction-lemma→ : { Q : Set } { Σ : Set } → (exists : ( Q → Bool ) → Bool ) → (NFA : NAutomaton Q Σ ) → (astart : Q → Bool ) → (x : List Σ) → Naccept NFA exists astart x ≡ true → accept ( subset-construction exists NFA ) astart x ≡ true subset-construction-lemma→ {Q} {Σ} exists NFA astart x naccept = lemma1 x astart naccept where lemma1 : (x : List Σ) → ( states : Q → Bool ) → Naccept NFA exists states x ≡ true → accept ( subset-construction exists NFA ) states x ≡ true lemma1 [] states naccept = naccept lemma1 (h ∷ t ) states naccept = lemma1 t (δconv exists (Nδ NFA) states h) naccept subset-construction-lemma← : { Q : Set } { Σ : Set } → (exists : ( Q → Bool ) → Bool ) → (NFA : NAutomaton Q Σ ) → (astart : Q → Bool ) → (x : List Σ) → accept ( subset-construction exists NFA ) astart x ≡ true → Naccept NFA exists astart x ≡ true subset-construction-lemma← {Q} {Σ} exists NFA astart x saccept = lemma2 x astart saccept where lemma2 : (x : List Σ) → ( states : Q → Bool ) → accept ( subset-construction exists NFA ) states x ≡ true → Naccept NFA exists states x ≡ true lemma2 [] states saccept = saccept lemma2 (h ∷ t ) states saccept = lemma2 t (δconv exists (Nδ NFA) states h) saccept
40.464286
127
0.599735
225634cdec11e75b259a960e5712d51288b6aafb
483
agda
Agda
Relator/Congruence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Relator/Congruence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Relator/Congruence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
open import Type module Relator.Congruence {ℓ₁}{ℓ₂} {X : Type{ℓ₁}}{Y : Type{ℓ₂}} where import Lvl open import Functional open import Logic open import Logic.Propositional open import Relator.Equals -- The congruence relation with respect to a relation infixl 15 _≅_of_ data _≅_of_ (x₁ : X) (x₂ : X) (f : X → Y) : Stmt{ℓ₂} where [≅]-intro : (f(x₁) ≡ f(x₂)) → (x₁ ≅ x₂ of f) [≅]-elim : ∀{x₁ x₂ : X}{f : X → Y} → (x₁ ≅ x₂ of f) → (f(x₁) ≡ f(x₂)) [≅]-elim ([≅]-intro eq) = eq
26.833333
69
0.612836
df4fdcb8ee07b0f1810800c434eee013729e6736
6,445
agda
Agda
Cubical/Algebra/CommRing/FGIdeal.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/FGIdeal.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/FGIdeal.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{- Define finitely generated ideals of commutative rings and show that they are an ideal. Parts of this should be reusable for explicit constructions of free modules over a finite set. -} {-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.FGIdeal where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Powerset open import Cubical.Foundations.HLevels open import Cubical.Data.Sigma open import Cubical.Data.Vec open import Cubical.Data.Nat using (ℕ) open import Cubical.HITs.PropositionalTruncation hiding (map) open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Ideal open import Cubical.Algebra.Ring.QuotientRing open import Cubical.Algebra.Ring.Properties open import Cubical.Algebra.RingSolver.ReflectionSolving hiding (∣) private variable ℓ : Level module _ (Ring@(R , str) : CommRing ℓ) (r : R) where infixr 5 _holds _holds : hProp ℓ → Type ℓ P holds = fst P open CommRingStr str open RingTheory (CommRing→Ring Ring) linearCombination : {n : ℕ} → Vec R n → Vec R n → R linearCombination [] [] = 0r linearCombination (c ∷ coefficients) (x ∷ l) = c · x + linearCombination coefficients l coefficientSum : {n : ℕ} → Vec R n → Vec R n → Vec R n coefficientSum [] [] = [] coefficientSum (x ∷ c) (y ∷ c′) = x + y ∷ coefficientSum c c′ sumDist+ : (n : ℕ) (c c′ l : Vec R n) → linearCombination (coefficientSum c c′) l ≡ linearCombination c l + linearCombination c′ l sumDist+ ℕ.zero [] [] [] = solve Ring sumDist+ (ℕ.suc n) (x ∷ c) (y ∷ c′) (a ∷ l) = linearCombination (coefficientSum (x ∷ c) (y ∷ c′)) (a ∷ l) ≡⟨ refl ⟩ (x + y) · a + linearCombination (coefficientSum c c′) l ≡⟨ step1 ⟩ (x + y) · a + (linearCombination c l + linearCombination c′ l) ≡⟨ step2 ⟩ (x · a + linearCombination c l) + (y · a + linearCombination c′ l) ≡⟨ refl ⟩ linearCombination (x ∷ c) (a ∷ l) + linearCombination (y ∷ c′) (a ∷ l) ∎ where step1 = cong (λ z → (x + y) · a + z) (sumDist+ n c c′ l) autoSolve : (x y a t1 t2 : R) → (x + y) · a + (t1 + t2) ≡ (x · a + t1) + (y · a + t2) autoSolve = solve Ring step2 = autoSolve x y a _ _ dist- : (n : ℕ) (c l : Vec R n) → linearCombination (map -_ c) l ≡ - linearCombination c l dist- ℕ.zero [] [] = solve Ring dist- (ℕ.suc n) (x ∷ c) (a ∷ l) = - x · a + linearCombination (map -_ c) l ≡[ i ]⟨ - x · a + dist- n c l i ⟩ - x · a - linearCombination c l ≡⟨ step1 x a _ ⟩ - (x · a + linearCombination c l) ∎ where step1 : (x a t1 : R) → - x · a - t1 ≡ - (x · a + t1) step1 = solve Ring dist0 : (n : ℕ) (l : Vec R n) → linearCombination (replicate 0r) l ≡ 0r dist0 ℕ.zero [] = refl dist0 (ℕ.suc n) (a ∷ l) = 0r · a + linearCombination (replicate 0r) l ≡[ i ]⟨ 0r · a + dist0 n l i ⟩ 0r · a + 0r ≡⟨ step1 a ⟩ 0r ∎ where step1 : (a : R) → 0r · a + 0r ≡ 0r step1 = solve Ring isLinearCombination : {n : ℕ} → Vec R n → R → Type ℓ isLinearCombination l x = ∥ Σ[ coefficients ∈ Vec R _ ] x ≡ linearCombination coefficients l ∥ {- If x and y are linear combinations of l, then (x + y) is a linear combination. -} isLinearCombination+ : {n : ℕ} {x y : R} → (l : Vec R n) → isLinearCombination l x → isLinearCombination l y → isLinearCombination l (x + y) isLinearCombination+ l = elim (λ _ → isOfHLevelΠ 1 (λ _ → propTruncIsProp)) (λ {(cx , px) → elim (λ _ → propTruncIsProp) λ {(cy , py) → ∣ coefficientSum cx cy , (_ + _ ≡[ i ]⟨ px i + py i ⟩ linearCombination cx l + linearCombination cy l ≡⟨ sym (sumDist+ _ cx cy l) ⟩ linearCombination (coefficientSum cx cy) l ∎) ∣}}) {- If x is a linear combinations of l, then -x is a linear combination. -} isLinearCombination- : {n : ℕ} {x y : R} (l : Vec R n) → isLinearCombination l x → isLinearCombination l (- x) isLinearCombination- l = elim (λ _ → propTruncIsProp) λ {(cx , px) → ∣ map -_ cx , ( - _ ≡⟨ cong -_ px ⟩ - linearCombination cx l ≡⟨ sym (dist- _ cx l) ⟩ linearCombination (map -_ cx) l ∎) ∣} {- 0r is the trivial linear Combination -} isLinearCombination0 : {n : ℕ} (l : Vec R n) → isLinearCombination l 0r isLinearCombination0 l = ∣ replicate 0r , sym (dist0 _ l) ∣ {- Linear combinations are stable under left multiplication -} isLinearCombinationL· : {n : ℕ} (l : Vec R n) → (r x : R) → isLinearCombination l x → isLinearCombination l (r · x) isLinearCombinationL· l r x = elim (λ _ → propTruncIsProp) λ {(cx , px) → ∣ map (r ·_) cx , (r · _ ≡[ i ]⟨ r · px i ⟩ r · linearCombination cx l ≡⟨ step1 _ cx l r ⟩ linearCombination (map (r ·_) cx) l ∎) ∣} where step2 : (r c a t1 : R) → r · (c · a + t1) ≡ r · (c · a) + r · t1 step2 = solve Ring step3 : (r c a t1 : R) → r · (c · a) + t1 ≡ r · c · a + t1 step3 = solve Ring step1 : (k : ℕ) (cx l : Vec R k) → (r : R) → r · linearCombination cx l ≡ linearCombination (map (r ·_) cx) l step1 ℕ.zero [] [] r = 0RightAnnihilates _ step1 (ℕ.suc k) (c ∷ cx) (a ∷ l) r = r · (c · a + linearCombination cx l) ≡⟨ step2 r c a _ ⟩ r · (c · a) + r · linearCombination cx l ≡[ i ]⟨ r · (c · a) + step1 _ cx l r i ⟩ r · (c · a) + linearCombination (map (_·_ r) cx) l ≡⟨ step3 r c a _ ⟩ r · c · a + linearCombination (map (_·_ r) cx) l ∎ generatedIdeal : {n : ℕ} → Vec R n → IdealsIn Ring generatedIdeal l = makeIdeal Ring (λ x → isLinearCombination l x , propTruncIsProp) (isLinearCombination+ l) (isLinearCombination0 l) λ r → isLinearCombinationL· l r _
42.401316
99
0.518542
291b8479737b90d87b15dca9ace739f00831198b
1,942
agda
Agda
benchmark/Syntacticosmos/Subst.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
benchmark/Syntacticosmos/Subst.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
benchmark/Syntacticosmos/Subst.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Subst (Gnd : Set)(U : Set)(El : U -> Set) where open import Basics open import Pr open import Nom import Kind open Kind Gnd U El import Cxt open Cxt Kind import Loc open Loc Kind import Term open Term Gnd U El import Shift open Shift Gnd U El import Inst open Inst Gnd U El data _-[_]_ : Cxt -> Kind -> Cxt -> Set where ES : {D : Cxt}{C : Kind} -> EC -[ C ] D _[_-_:=_] : {G D : Cxt}{C : Kind} -> (G -[ C ] D) -> (x : Nom){Gx : [| G Hasn't x |]}(S : Kind) -> D [! C !]- S -> (G [ x - S ]){Gx} -[ C ] D fetch : {G D : Cxt}{C S : Kind} -> (G -[ C ] D) -> Nom :- GooN G S -> D [! C !]- S fetch ES [ x / () ] fetch (g [ x - S := s ]) [ y / p ] with nomEq x y fetch (g [ x - S := s ]) [ .x / refl ] | yes refl = s fetch (g [ x - S := s ]) [ y / p ] | no n = fetch g [ y / p ] closed : {G : Cxt}{L : Loc}{T : Kind} -> G [ EL / Head ]- T -> G [ L / Head ]- T closed (` x -! xg) = ` x -! xg closed (# () -! _) mutual wsubst : {C : Kind}{G D : Cxt} -> (G -[ C ] D) -> {L : Loc}{T : Kind}(t : L [ Term C ]- T) -> [| Good G t |] -> D [ L / Term C ]- T wsubst g [ s ] sg = G[ wsubsts g s sg ] wsubst g (fn A f) fg = Gfn A \ a -> wsubst g (f a) (fg a) wsubst g (\\ b) bg = G\\ (wsubst g b bg) wsubst g (# v $ s) pg = (# v -! _) G$ wsubsts g s (snd pg) wsubst g (` x $ s) pg = go (shift closed (fetch g [ x / fst pg ])) (wsubsts g s (snd pg)) wsubsts : {C : Kind}{G D : Cxt} -> (G -[ C ] D) -> {L : Loc}{Z : Gnd}{S : Kind} (s : L [ Args C Z ]- S) -> [| Good G s |] -> D [ L / Args C Z ]- S wsubsts g (a ^ s) sg = a G^ wsubsts g s sg wsubsts g (r & s) pg = wsubst g r (fst pg) G& wsubsts g s (snd pg) wsubsts g nil _ = Gnil subst : {C : Kind}{G D : Cxt} -> (G -[ C ] D) -> {L : Loc}{T : Kind} -> G [ L / Term C ]- T -> D [ L / Term C ]- T subst g (t -! tg) = wsubst g t tg
31.322581
73
0.443357
22585bb964f0f34dbe02e1ad7ebb0d7049e247f8
1,026
agda
Agda
BasicIS4/Metatheory/DyadicGentzen-BasicKripkeBozicDosen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIS4/Metatheory/DyadicGentzen-BasicKripkeBozicDosen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIS4/Metatheory/DyadicGentzen-BasicKripkeBozicDosen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module BasicIS4.Metatheory.DyadicGentzen-BasicKripkeBozicDosen where open import BasicIS4.Syntax.DyadicGentzen public open import BasicIS4.Semantics.BasicKripkeBozicDosen public hiding (_⊨_) -- TODO -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A eval (var i) γ δ = lookup i γ eval (lam t) γ δ = λ ξ a → eval t (mono⊩⋆ ξ γ , a) (λ ζ → let _ , (ζ′ , ξ′) = ≤⨾R→R⨾≤ (_ , (ξ , ζ)) in mono⊩⋆ ξ′ (δ ζ′)) eval (app {A} {B} t u) γ δ = _⟪$⟫_ {A} {B} (eval t γ δ) (eval u γ δ) eval (mvar i) γ δ = lookup i (δ reflR) eval (box t) γ δ = λ ζ → eval t ∙ (λ ζ′ → δ (transR ζ ζ′)) eval (unbox t u) γ δ = eval u γ (λ ζ → δ ζ , (eval t γ δ) ζ) eval (pair t u) γ δ = eval t γ δ , eval u γ δ eval (fst t) γ δ = π₁ (eval t γ δ) eval (snd t) γ δ = π₂ (eval t γ δ) eval unit γ δ = ∙ -- TODO: Correctness of evaluation with respect to conversion.
41.04
80
0.517544
225ea7791fc29a7086a551ad9b4f7f33b88fb356
1,780
agda
Agda
test/fail/MixingCoPatternsAndCoConstructors.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/fail/MixingCoPatternsAndCoConstructors.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
test/fail/MixingCoPatternsAndCoConstructors.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
{-# OPTIONS --copatterns #-} module MixingCoPatternsAndCoConstructors where data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ module MStream where record Stream (A : Set) : Set where coinductive constructor _∷_ field head : A tail : Stream A open Stream weird : (n : ℕ) → Stream ℕ head (weird zero) = zero tail (weird zero) = weird zero head (weird (suc n)) = n tail (weird (suc n)) = tail (weird n) weird' : (n : ℕ) → Stream ℕ head (weird' zero) = zero tail (weird' zero) = weird' zero weird' (suc n) = n ∷ tail (weird' n) -- BAD: weird'' : (n : ℕ) → Stream ℕ weird'' zero = zero ∷ weird'' zero weird'' (suc n) = n ∷ tail (weird'' n) -- productive, but not strongly normalizing, -- should be rejected by termination checker: repeat : {A : Set}(a : A) → Stream A head (repeat a) = a tail (repeat a) = a ∷ tail (repeat a) module Coinduction where import Common.Level open import Common.Coinduction record Stream (A : Set) : Set where constructor _∷_ field head : A tail : ∞ (Stream A) open Stream weird'' : (n : ℕ) → Stream ℕ weird'' zero = zero ∷ ♯ weird'' zero weird'' (suc n) = n ∷ tail (weird'' n) module CoList where mutual data CoList (A : Set) : Set where [] : CoList A _∷_ : (x : A)(xs : CoList∞ A) → CoList A record CoList∞ (A : Set) : Set where coinductive constructor delay field force : CoList A open CoList∞ downFrom : (n : ℕ) → CoList ℕ downFrom zero = [] downFrom (suc n) = n ∷ delay (downFrom n) down : (n : ℕ) → CoList∞ ℕ force (down zero) = [] force (down (suc n)) = n ∷ delay (force (down n)) -- weird detour: delay (force ... to test termination checker
20.941176
65
0.575843
0eec7714b88dadab59a8e2765e52433deac23f25
3,343
agda
Agda
README/DependentlyTyped/Beta-Eta.agda
nad/dependently-typed-syntax
498f8aefc570f7815fd1d6616508eeb92c52abce
[ "MIT" ]
5
2020-04-16T12:14:44.000Z
2020-07-08T22:51:36.000Z
README/DependentlyTyped/Beta-Eta.agda
nad/dependently-typed-syntax
498f8aefc570f7815fd1d6616508eeb92c52abce
[ "MIT" ]
null
null
null
README/DependentlyTyped/Beta-Eta.agda
nad/dependently-typed-syntax
498f8aefc570f7815fd1d6616508eeb92c52abce
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Inductively defined beta-eta-equality ------------------------------------------------------------------------ import Level open import Data.Universe module README.DependentlyTyped.Beta-Eta (Uni₀ : Universe Level.zero Level.zero) where open import Data.Product renaming (curry to c) open import Function hiding (_∋_) import README.DependentlyTyped.Term as Term; open Term Uni₀ import README.DependentlyTyped.Term.Substitution as S; open S Uni₀ import Relation.Binary.PropositionalEquality as P open P.≡-Reasoning -- βη-equality. infixl 9 _·_ infix 4 _≈_ infixr 2 _≈⟨_⟩_ data _≈_ : ∀ {Γ₁ σ₁} → Γ₁ ⊢ σ₁ → ∀ {Γ₂ σ₂} → Γ₂ ⊢ σ₂ → Set where -- β and η. β : ∀ {Γ sp₁ sp₂} {σ : IType Γ (π sp₁ sp₂)} (t₁ : Γ ▻ fst σ ⊢ snd σ) (t₂ : Γ ⊢ fst σ) → ƛ t₁ · t₂ ≈ t₁ /⊢ sub t₂ η : ∀ {Γ sp₁ sp₂ σ} (t : Γ ⊢ (π sp₁ sp₂ , σ)) → ƛ ((t /⊢ wk[ fst σ ]) · var zero) ≈ t -- The relation is an equivalence (reflexivity is proved below). sym : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁} {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} (t₁≈t₂ : t₁ ≈ t₂) → t₂ ≈ t₁ _≈⟨_⟩_ : ∀ {Γ₁ σ₁} (t₁ : Γ₁ ⊢ σ₁) {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} {Γ₃ σ₃} {t₃ : Γ₃ ⊢ σ₃} (t₁≈t₂ : t₁ ≈ t₂) (t₂≈t₃ : t₂ ≈ t₃) → t₁ ≈ t₃ -- The relation is a congruence. var : ∀ {Γ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {Γ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} (x₁≅x₂ : x₁ ≅-∋ x₂) → var x₁ ≈ var x₂ ƛ : ∀ {Γ₁ σ₁ τ₁} {t₁ : Γ₁ ▻ σ₁ ⊢ τ₁} {Γ₂ σ₂ τ₂} {t₂ : Γ₂ ▻ σ₂ ⊢ τ₂} (t₁≈t₂ : t₁ ≈ t₂) → ƛ t₁ ≈ ƛ t₂ _·_ : ∀ {Γ₁ sp₁₁ sp₂₁ σ₁} {t₁₁ : Γ₁ ⊢ π sp₁₁ sp₂₁ , σ₁} {t₂₁ : Γ₁ ⊢ fst σ₁} {Γ₂ sp₁₂ sp₂₂ σ₂} {t₁₂ : Γ₂ ⊢ π sp₁₂ sp₂₂ , σ₂} {t₂₂ : Γ₂ ⊢ fst σ₂} (t₁₁≈t₁₂ : t₁₁ ≈ t₁₂) (t₂₁≈t₂₂ : t₂₁ ≈ t₂₂) → t₁₁ · t₂₁ ≈ t₁₂ · t₂₂ -- Reflexivity. infix 3 _□ _□ : ∀ {Γ σ} (t : Γ ⊢ σ) → t ≈ t var x □ = var P.refl ƛ t □ = ƛ (t □) t₁ · t₂ □ = (t₁ □) · (t₂ □) abstract -- βη-equal terms have the same semantics. ≈-sound : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁} {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} → t₁ ≈ t₂ → ⟦ t₁ ⟧ ≅-Value ⟦ t₂ ⟧ ≈-sound (β t₁ t₂) = begin [ c ⟦ t₁ ⟧ ˢ ⟦ t₂ ⟧ ] ≡⟨ corresponds (app (sub t₂)) t₁ ⟩ [ ⟦ t₁ /⊢ sub t₂ ⟧ ] ∎ ≈-sound (η t) = begin [ c (⟦ t /⊢ wk ⟧ ˢ lookup zero) ] ≡⟨ curry-cong $ ˢ-cong (P.sym $ corresponds (app wk) t) (P.refl {x = [ lookup zero ]}) ⟩ [ c ((⟦ t ⟧ /̂Val ŵk) ˢ lookup zero) ] ≡⟨ P.refl ⟩ [ ⟦ t ⟧ ] ∎ ≈-sound (sym t₁≈t₂) = P.sym $ ≈-sound t₁≈t₂ ≈-sound (t₁ ≈⟨ t₁≈t₂ ⟩ t₂≈t₃) = P.trans (≈-sound t₁≈t₂) (≈-sound t₂≈t₃) ≈-sound (var P.refl) = P.refl ≈-sound (ƛ t₁≈t₂) = curry-cong (≈-sound t₁≈t₂) ≈-sound (t₁₁≈t₁₂ · t₂₁≈t₂₂) = ˢ-cong (≈-sound t₁₁≈t₁₂) (≈-sound t₂₁≈t₂₂) -- βη-equal terms have identical contexts. ≈-⇒-≅-Ctxt : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁} {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} → t₁ ≈ t₂ → Γ₁ ≅-Ctxt Γ₂ ≈-⇒-≅-Ctxt t₁≈t₂ = P.cong [Value].Γ $ ≈-sound t₁≈t₂ -- βη-equal terms have identical types. ≈-⇒-≅-Type : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁} {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} → t₁ ≈ t₂ → σ₁ ≅-Type σ₂ ≈-⇒-≅-Type {t₁ = t₁} {t₂ = t₂} t₁≈t₂ with ⟦ t₂ ⟧ | ≈-sound t₁≈t₂ ... | .(⟦ t₁ ⟧) | P.refl = P.refl
32.456311
98
0.454981
5787ae7ce08ba043b2f52b427e10f11763e3581f
443
agda
Agda
Monoids.agda
jmchapman/Relative-Monads
74707d3538bf494f4bd30263d2f5515a84733865
[ "MIT" ]
21
2015-07-30T01:25:12.000Z
2021-02-13T18:02:18.000Z
Monoids.agda
jmchapman/Relative-Monads
74707d3538bf494f4bd30263d2f5515a84733865
[ "MIT" ]
3
2019-01-13T13:12:33.000Z
2019-05-29T09:50:26.000Z
Monoids.agda
jmchapman/Relative-Monads
74707d3538bf494f4bd30263d2f5515a84733865
[ "MIT" ]
1
2019-11-04T21:33:13.000Z
2019-11-04T21:33:13.000Z
module Monoids where open import Library record Monoid {a} : Set (lsuc a) where field S : Set a ε : S _•_ : S → S → S lid : ∀{m} → ε • m ≅ m rid : ∀{m} → m • ε ≅ m ass : ∀{m n o} → (m • n) • o ≅ m • (n • o) infix 10 _•_ Nat+Mon : Monoid Nat+Mon = record { S = ℕ; ε = zero; _•_ = _+_; lid = refl; rid = ≡-to-≅ $ +-right-identity _; ass = λ{m} → ≡-to-≅ $ +-assoc m _ _}
18.458333
50
0.426637
a1e92e49737b632cf442d73cf74332c358d18fc2
1,540
agda
Agda
Cubical/Reflection/Base.agda
rnarkk/cubical
8dea02ee105b45898dbf1f77271ead38994f4d61
[ "MIT" ]
null
null
null
Cubical/Reflection/Base.agda
rnarkk/cubical
8dea02ee105b45898dbf1f77271ead38994f4d61
[ "MIT" ]
null
null
null
Cubical/Reflection/Base.agda
rnarkk/cubical
8dea02ee105b45898dbf1f77271ead38994f4d61
[ "MIT" ]
null
null
null
{- Some basic utilities for reflection -} {-# OPTIONS --no-exact-split --safe #-} module Cubical.Reflection.Base where open import Cubical.Foundations.Prelude open import Cubical.Data.List.Base open import Cubical.Data.Nat.Base import Agda.Builtin.Reflection as R open import Agda.Builtin.String _>>=_ = R.bindTC _<|>_ = R.catchTC _$_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (A → B) → A → B f $ a = f a _>>_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → R.TC A → R.TC B → R.TC B f >> g = f >>= λ _ → g infixl 4 _>>=_ _>>_ _<|>_ infixr 3 _$_ liftTC : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (A → B) → R.TC A → R.TC B liftTC f ta = ta >>= λ a → R.returnTC (f a) v : ℕ → R.Term v n = R.var n [] pattern varg t = R.arg (R.arg-info R.visible (R.modality R.relevant R.quantity-ω)) t pattern harg {q = q} t = R.arg (R.arg-info R.hidden (R.modality R.relevant q)) t pattern _v∷_ a l = varg a ∷ l pattern _h∷_ a l = harg a ∷ l infixr 5 _v∷_ _h∷_ vlam : String → R.Term → R.Term vlam str t = R.lam R.visible (R.abs str t) hlam : String → R.Term → R.Term hlam str t = R.lam R.hidden (R.abs str t) newMeta = R.checkType R.unknown extend*Context : ∀ {ℓ} {A : Type ℓ} → R.Telescope → R.TC A → R.TC A extend*Context [] tac = tac extend*Context ((s , a) ∷ as) tac = R.extendContext s a (extend*Context as tac) makeAuxiliaryDef : String → R.Type → R.Term → R.TC R.Term makeAuxiliaryDef s ty term = R.freshName s >>= λ name → R.declareDef (varg name) ty >> R.defineFun name [ R.clause [] [] term ] >> R.returnTC (R.def name [])
25.666667
84
0.609091
2f4201767181f5035e305ef783aefe38d8521640
2,598
agda
Agda
src/Data/Finitude.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
src/Data/Finitude.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
src/Data/Finitude.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
module Data.Finitude where open import Data.Fin as Fin open import Data.Nat as ℕ open import Level open import Function as Fun hiding (id; _∘_) open import Function.Equality as F using (_⟨$⟩_) open import Function.Injection as Inj hiding (id; _∘_) open import Function.Bijection as Bij hiding (id; _∘_) open import Function.LeftInverse hiding (id; _∘_) open import Function.Inverse as Inv hiding (id; _∘_) open import Relation.Binary import Relation.Binary.PropositionalEquality as P open import Relation.Binary.PropositionalEquality using (_≡_; _≢_) Finitude : ∀ {a ℓ} (A : Setoid a ℓ) (n : ℕ) → Set _ Finitude A n = Inverse A (P.setoid (Fin n)) module Subset where open import Data.Product as Prod hiding (map) open import Data.Fin.Subset using (Subset; _∈_; outside; inside; ∣_∣) renaming (⊥ to ∅) open import Data.Vec subset-finitude : ∀ {n}(s : Subset n) → Finitude (P.setoid (∃ (_∈ s))) ∣ s ∣ subset-finitude {ℕ.zero} [] = record { to = P.→-to-⟶ (λ ()) ; from = P.→-to-⟶ (λ () ) ; inverse-of = record { left-inverse-of = λ () ; right-inverse-of = λ () } } subset-finitude {ℕ.suc n} (inside ∷ s) = record { to = P.→-to-⟶ λ { (_ , here) → Fin.zero ; (_ , there p) → Fin.suc (to ⟨$⟩ (_ , p)) } ; from = P.→-to-⟶ λ { Fin.zero → _ , here ; (Fin.suc i) → _ , there (proj₂ (from ⟨$⟩ i))} ; inverse-of = record { left-inverse-of = λ { (_ , here) → P.refl ; (_ , there p) → P.cong (Prod.map Fin.suc there) (linv (_ , p))} ; right-inverse-of = λ { Fin.zero → P.refl ; (Fin.suc i) → P.cong Fin.suc (rinv i)} } } where open Inverse (subset-finitude s) open _InverseOf_ inverse-of renaming (left-inverse-of to linv ;right-inverse-of to rinv) subset-finitude {ℕ.suc n} (outside ∷ s) = record { to = P.→-to-⟶ (λ { (_ , there p) → to ⟨$⟩ (_ , p)}) ; from = P.→-to-⟶ (λ i → Prod.map Fin.suc there (from ⟨$⟩ i) ) ; inverse-of = record { left-inverse-of = λ { (_ , there p) → P.cong (Prod.map Fin.suc there) (linv (_ , p)) } ; right-inverse-of = rinv } } where open Inverse (subset-finitude s) open _InverseOf_ inverse-of renaming ( left-inverse-of to linv ; right-inverse-of to rinv)
39.969231
89
0.518091
1c9685761194addcba6e963d9983de929a574621
3,138
agda
Agda
examples/outdated-and-incorrect/NestedDataTypes/DeBruijnExSubst.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
examples/outdated-and-incorrect/NestedDataTypes/DeBruijnExSubst.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/NestedDataTypes/DeBruijnExSubst.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module DeBruijnExSubst where open import Prelude -- using (_∘_) -- composition, identity open import Data.Maybe open import Logic.Identity renaming (subst to subst≡) import Logic.ChainReasoning module Chain = Logic.ChainReasoning.Poly.Homogenous _≡_ (\x -> refl) (\x y z -> trans) open Chain open import DeBruijn -- untyped de Bruijn terms data LamE (A : Set) : Set where varE : A -> LamE A appE : LamE A -> LamE A -> LamE A absE : LamE (Maybe A) -> LamE A flatE : LamE (LamE A) -> LamE A -- functoriality of LamE lamE : {A B : Set} -> (A -> B) -> LamE A -> LamE B lamE f (varE a) = varE (f a) lamE f (appE t1 t2) = appE (lamE f t1) (lamE f t2) lamE f (absE r) = absE (lamE (fmap f) r) lamE f (flatE r) = flatE (lamE (lamE f) r) {- from TCS 05 paper eval' : {A B : Set} -> (A -> B) -> LamE A -> Lam B eval' f (varE a) = var (f a) eval' f (appE t1 t2) = app (eval' f t1) (eval' f t2) eval' f (absE r) = abs (eval' (fmap f) r) eval' f (flatE r) = subst id (eval' (eval' f) r) eval : {A : Set} -> LamE A -> Lam A eval = eval' id -} eval : {A : Set} -> LamE A -> Lam A eval (varE a) = var a eval (appE t1 t2) = app (eval t1) (eval t2) eval (absE r) = abs (eval r) eval (flatE r) = subst eval (eval r) evalNAT : {A B : Set}(f : A -> B) -> (t : LamE A) -> eval (lamE f t) ≡ lam f (eval t) evalNAT f (varE a) = refl evalNAT f (appE t1 t2) = chain> eval (lamE f (appE t1 t2)) === eval (appE (lamE f t1) (lamE f t2)) by refl === app (eval (lamE f t1)) (eval (lamE f t2)) by refl === app (lam f (eval t1)) (eval (lamE f t2)) by cong (\ x -> app x (eval (lamE f t2))) (evalNAT f t1) === app (lam f (eval t1)) (lam f (eval t2)) by cong (\ x -> app (lam f (eval t1)) x) (evalNAT f t2) === lam f (app (eval t1) (eval t2)) by refl === lam f (eval (appE t1 t2)) by refl evalNAT f (absE r) = chain> eval (lamE f (absE r)) === eval (absE (lamE (fmap f) r)) by refl === abs (eval (lamE (fmap f) r)) by refl === abs (lam (fmap f) (eval r)) by cong abs (evalNAT (fmap f) r) === lam f (abs (eval r)) by refl === lam f (eval (absE r)) by refl evalNAT f (flatE r) = chain> eval (lamE f (flatE r)) === eval (flatE (lamE (lamE f) r)) by refl === subst eval (eval (lamE (lamE f) r)) by refl === subst eval (lam (lamE f) (eval r)) by cong (subst eval) (evalNAT (lamE f) r) === subst (eval ∘ lamE f) (eval r) by substLaw1 (lamE f) eval (eval r) === subst (lam f ∘ eval) (eval r) by substExt _ _ (evalNAT f) (eval r) === lam f (subst eval (eval r)) by substLaw2 f eval (eval r) === lam f (eval (flatE r)) by refl evalNATcor : {A : Set}(ee : LamE (LamE A)) -> subst id (eval (lamE eval ee)) ≡ eval (flatE ee) evalNATcor ee = chain> subst id (eval (lamE eval ee)) === subst id (lam eval (eval ee)) by cong (subst id) (evalNAT eval ee) === subst eval (eval ee) by substLaw1 eval id (eval ee) === eval (flatE ee) by refl
34.866667
86
0.537285
df7a8e34d7b55391fd732ebac8089a8f7a95f9aa
716
agda
Agda
test/Succeed/Issue421.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue421.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue421.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Positivity for functions in instantiated parameterised modules. module Issue421 where module Foo (_ : Set₁) where Id : Set → Set Id n = n module FooApp = Foo Set data ⊤ : Set where tt : ⊤ ⟦_⟧₁ : ⊤ → Set → Set ⟦ tt ⟧₁ x = FooApp.Id x -- works: ⟦ tt ⟧ x = Foo.Id Set x data μ₁ x : Set where fix : ⟦ x ⟧₁ (μ₁ x) -> μ₁ x -- Instantiating the module in another parameterised module: module Matrices (J : Set) where Id : (J → Set) → J → Set Id m i = m i data Poly : Set where id : (D : Poly) -> Poly module Dim (I : Set) where module M = Matrices I ⟦_⟧₂ : Poly → (I → Set) → (I → Set) ⟦ id D ⟧₂ x i = M.Id x i data μ₂ (p : Poly) (i : I) : Set where fix : ⟦ p ⟧₂ (μ₂ p) i -> μ₂ p i
18.842105
66
0.574022
3d1941c2dd2b2547d45afd834abfef15076e08c5
6,269
agda
Agda
agda/Avionics/SafetyEnvelopes.agda
RPI-WCL/safety-envelopes-sentinels
896e67a2ad21041a1c9ef5f3ad6318c67d730341
[ "BSD-3-Clause" ]
null
null
null
agda/Avionics/SafetyEnvelopes.agda
RPI-WCL/safety-envelopes-sentinels
896e67a2ad21041a1c9ef5f3ad6318c67d730341
[ "BSD-3-Clause" ]
null
null
null
agda/Avionics/SafetyEnvelopes.agda
RPI-WCL/safety-envelopes-sentinels
896e67a2ad21041a1c9ef5f3ad6318c67d730341
[ "BSD-3-Clause" ]
null
null
null
module Avionics.SafetyEnvelopes where open import Data.Bool using (Bool; true; false; _∧_; _∨_) open import Data.List using (List; []; _∷_; any; map; foldl; length) open import Data.List.Relation.Unary.Any as Any using (Any) open import Data.List.Relation.Unary.All as All using (All) open import Data.Maybe using (Maybe; just; nothing; is-just; _>>=_) open import Data.Nat using (ℕ; zero; suc) open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩) open import Function using (_∘_) open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; cong; subst; sym; trans) open import Relation.Unary using (_∈_) open import Relation.Nullary using (yes; no; ¬_) open import Relation.Nullary.Decidable using (fromWitnessFalse) open import Avionics.Real using (ℝ; _+_; _-_; _*_; _÷_; _^_; _<ᵇ_; _≤ᵇ_; _≤_; _<_; _<?_; _≤?_; _≟_; 1/_; 0ℝ; 1ℝ; 2ℝ; 1/2; _^2; √_; fromℕ) --open import Avionics.Product using (_×_; ⟨_,_⟩; proj₁; proj₂) open import Avionics.Probability using (Dist; NormalDist; ND) sum : List ℝ → ℝ sum = foldl _+_ 0ℝ inside : NormalDist → ℝ → ℝ → Bool inside nd z x = ((μ - z * σ) <ᵇ x) ∧ (x <ᵇ (μ + z * σ)) where open NormalDist nd using (μ; σ) record Model : Set where field -- Angles of attack and airspeed available in the model SM : List (ℝ × ℝ) -- Map from angles of attack and airspeeds to Normal Distributions fM : List ((ℝ × ℝ) × (NormalDist × ℝ)) -- Every pair of angle of attack and airspeed must be represented in the map fM .fMisMap₁ : All (λ ⟨α,v⟩ → Any (λ ⟨α,v⟩,ND → proj₁ ⟨α,v⟩,ND ≡ ⟨α,v⟩) fM ) SM .fMisMap₂ : All (λ ⟨α,v⟩,ND → Any (λ ⟨α,v⟩ → proj₁ ⟨α,v⟩,ND ≡ ⟨α,v⟩) SM ) fM .lenSM>0 : length SM ≢ 0 --.lenfM>0 : length fM ≢ 0 -- this is the result of the bijection above and .lenSM>0 z-predictable' : List NormalDist → ℝ → ℝ → ℝ × Bool z-predictable' nds z x = ⟨ x , any (λ nd → inside nd z x) nds ⟩ z-predictable : Model → ℝ → ℝ → ℝ × Bool z-predictable M z x = z-predictable' (map (proj₁ ∘ proj₂) (Model.fM M)) z x -- sample-z-predictable : List NormalDist → ℝ → ℝ → List ℝ → Maybe (ℝ × ℝ × Bool) sample-z-predictable nds zμ zσ [] = nothing sample-z-predictable nds zμ zσ (_ ∷ []) = nothing sample-z-predictable nds zμ zσ xs@(_ ∷ _ ∷ _) = just ⟨ mean , ⟨ var_est , any inside' nds ⟩ ⟩ where n = fromℕ (length xs) mean = (sum xs ÷ n) var_est = (sum (map (λ{x →(x - mean)^2}) xs) ÷ (n - 1ℝ)) inside' : NormalDist → Bool inside' nd = ((μ - zμ * σ) <ᵇ mean) ∧ (mean <ᵇ (μ + zμ * σ)) ∧ (σ^2 - zσ * std[σ^2] <ᵇ var) ∧ (var <ᵇ σ^2 + zσ * std[σ^2]) where open NormalDist nd using (μ; σ) σ^2 = σ ^2 --Var[σ^2] = 2 * (σ^2)^2 / n std[σ^2] = (√ 2ℝ) * (σ^2 ÷ (√ n)) -- Notice that the estimated variance here is computed assuming `μ` -- it's the mean of the distribution. This is so that Cramer-Rao -- lower bound can be applied to it var = (sum (map (λ{x →(x - μ)^2}) xs) ÷ n) nonneg-cf : ℝ → ℝ × Bool nonneg-cf x = ⟨ x , 0ℝ ≤ᵇ x ⟩ data StallClasses : Set where Stall NoStall Uncertain : StallClasses P[stall]f⟨_|stall⟩_ : ℝ → List (ℝ × ℝ × Dist ℝ) → ℝ P[stall]f⟨ x |stall⟩ pbs = sum (map unpack pbs) where unpack : ℝ × ℝ × Dist ℝ → ℝ unpack ⟨ P[⟨α,v⟩] , ⟨ P[stall|⟨α,v⟩] , dist ⟩ ⟩ = pdf x * P[⟨α,v⟩] * P[stall|⟨α,v⟩] where open Dist dist using (pdf) f⟨_⟩_ : ℝ → List (ℝ × ℝ × Dist ℝ) → ℝ f⟨ x ⟩ pbs = sum (map unpack pbs) where unpack : ℝ × ℝ × Dist ℝ → ℝ unpack ⟨ P[⟨α,v⟩] , ⟨ _ , dist ⟩ ⟩ = pdf x * P[⟨α,v⟩] where open Dist dist using (pdf) -- There should be a proof showing that the resulting value will always be in the interval [0,1] P[_|X=_]_ : StallClasses → ℝ → List (ℝ × ℝ × Dist ℝ) → Maybe ℝ P[ Stall |X= x ] pbs with f⟨ x ⟩ pbs ≟ 0ℝ ... | yes _ = nothing ... | no _ = just (((P[stall]f⟨ x |stall⟩ pbs) ÷ (f⟨ x ⟩ pbs))) P[ NoStall |X= x ] pbs with f⟨ x ⟩ pbs ≟ 0ℝ ... | yes _ = nothing ... | no _ = just (1ℝ - ((P[stall]f⟨ x |stall⟩ pbs) ÷ (f⟨ x ⟩ pbs))) P[ Uncertain |X= _ ] _ = nothing postulate -- TODO: Find out how to prove this! -- It probably requires to prove that P[Stall|X=x] + P[NoStall|X=x] ≡ 1 Stall≡1-NoStall : ∀ {x pbs p} → P[ Stall |X= x ] pbs ≡ just p → P[ NoStall |X= x ] pbs ≡ just (1ℝ - p) NoStall≡1-Stall : ∀ {x pbs p} → P[ NoStall |X= x ] pbs ≡ just p → P[ Stall |X= x ] pbs ≡ just (1ℝ - p) -- Main assumptions -- * 0.5 < τ ≤ 1 -- * 0 ≤ p ≤ 1 -- Of course, these assumptions are never explicit in the code. But note -- that, only the first assumption can be broken by an user bad input. The -- second assumption stems for probability theory, yet not proven but -- should be true ≤p→¬≤1-p : ∀ {τ p} -- This first line are the assumptions. From them, the rest should follow → 1/2 < τ → τ ≤ 1ℝ -- 0.5 < τ ≤ 1 → 0ℝ ≤ p → p ≤ 1ℝ -- 0 ≤ p ≤ 1 → τ ≤ p → ¬ τ ≤ (1ℝ - p) ≤1-p→¬≤p : ∀ {τ p} → 1/2 < τ → τ ≤ 1ℝ -- 0.5 < τ ≤ 1 → 0ℝ ≤ p → p ≤ 1ℝ -- 0 ≤ p ≤ 1 → τ ≤ (1ℝ - p) → ¬ τ ≤ p classify'' : List (ℝ × ℝ × Dist ℝ) → ℝ → ℝ → StallClasses classify'' pbs τ x with P[ Stall |X= x ] pbs ... | nothing = Uncertain ... | just p with τ ≤? p | τ ≤? (1ℝ - p) ... | yes _ | no _ = Stall ... | no _ | yes _ = NoStall ... | _ | _ = Uncertain -- the only missing case is `no _ | no _`, `yes _ | yes _` is not possible M→pbs : Model → List (ℝ × ℝ × Dist ℝ) M→pbs M = map convert (Model.fM M) where n = fromℕ (length (Model.fM M)) convert : (ℝ × ℝ) × (NormalDist × ℝ) → ℝ × ℝ × Dist ℝ convert ⟨ _ , ⟨ nd , P[stall|c] ⟩ ⟩ = ⟨ 1/ n , ⟨ P[stall|c] , dist ⟩ ⟩ where open NormalDist nd using (dist) classify : Model → ℝ → ℝ → StallClasses classify M = classify'' (M→pbs M) no-uncertain : StallClasses → Bool no-uncertain Uncertain = false no-uncertain _ = true τ-confident : Model → ℝ → ℝ → Bool τ-confident M τ = no-uncertain ∘ classify M τ safety-envelope : Model → ℝ → ℝ → ℝ → Bool safety-envelope M z τ x = proj₂ (z-predictable M z x) ∧ τ-confident M τ x
37.993939
117
0.55607
3d042242579ded224959de5edee318512b4d9230
184
agda
Agda
test/Fail/Issue3945.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Fail/Issue3945.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/Issue3945.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
module _ where data Flat (A : Set) : Set where flat : @♭ A → Flat A -- the lambda cohesion annotation must match the domain. into : {A : Set} → A → Flat A into = λ (@♭ a) → flat a
20.444444
56
0.608696
29ca3d221a2f040a15a7d3268f3bc807a430876d
6,574
agda
Agda
Cubical/Experiments/CohomologyGroups.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Experiments/CohomologyGroups.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Experiments/CohomologyGroups.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{-# OPTIONS --safe #-} module Cubical.Experiments.CohomologyGroups where open import Cubical.Experiments.ZCohomologyOld.Base open import Cubical.Experiments.ZCohomologyOld.Properties open import Cubical.Experiments.ZCohomologyOld.MayerVietorisUnreduced open import Cubical.Experiments.ZCohomologyOld.Groups.Unit open import Cubical.Experiments.ZCohomologyOld.KcompPrelims open import Cubical.Experiments.ZCohomologyOld.Groups.Sn open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Structure open import Cubical.Foundations.Isomorphism open import Cubical.HITs.Pushout open import Cubical.HITs.Sn open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2) hiding (map) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁) hiding (map) open import Cubical.Data.Bool open import Cubical.Data.Sigma open import Cubical.Data.Int open import Cubical.Algebra.Group open GroupIso open GroupHom open BijectionIso -- --------------------------H¹(S¹) ----------------------------------- {- In order to apply Mayer-Vietoris, we need the following lemma. Given the following diagram a ↦ (a , 0) ψ ϕ A --> A × A -------> B ---> C If ψ is an isomorphism and ϕ is surjective with ker ϕ ≡ {ψ (a , a) ∣ a ∈ A}, then C ≅ B -} diagonalIso : ∀ {ℓ ℓ' ℓ''} {A : Group {ℓ}} (B : Group {ℓ'}) {C : Group {ℓ''}} (ψ : GroupIso (dirProd A A) B) (ϕ : GroupHom B C) → isSurjective _ _ ϕ → ((x : ⟨ B ⟩) → isInKer B C ϕ x → ∃[ y ∈ ⟨ A ⟩ ] x ≡ (fun (map ψ)) (y , y)) → ((x : ⟨ B ⟩) → (∃[ y ∈ ⟨ A ⟩ ] x ≡ (fun (map ψ)) (y , y)) → isInKer B C ϕ x) → GroupIso A C diagonalIso {A = A} B {C = C} ψ ϕ issurj ker→diag diag→ker = BijectionIsoToGroupIso bijIso where open GroupStr module A = GroupStr (snd A) module B = GroupStr (snd B) module C = GroupStr (snd C) module A×A = GroupStr (snd (dirProd A A)) module ψ = GroupIso ψ module ϕ = GroupHom ϕ ψ⁻ = inv ψ fstProj : GroupHom A (dirProd A A) fun fstProj a = a , GroupStr.0g (snd A) isHom fstProj g0 g1 i = (g0 A.+ g1) , GroupStr.lid (snd A) (GroupStr.0g (snd A)) (~ i) bijIso : BijectionIso A C map' bijIso = compGroupHom fstProj (compGroupHom (map ψ) ϕ) inj bijIso a inker = pRec (isSetCarrier A _ _) (λ {(a' , id) → (cong fst (sym (leftInv ψ (a , GroupStr.0g (snd A))) ∙∙ cong ψ⁻ id ∙∙ leftInv ψ (a' , a'))) ∙ cong snd (sym (leftInv ψ (a' , a')) ∙∙ cong ψ⁻ (sym id) ∙∙ leftInv ψ (a , GroupStr.0g (snd A)))}) (ker→diag _ inker) surj bijIso c = pRec propTruncIsProp (λ { (b , id) → ∣ (fst (ψ⁻ b) A.+ (A.- snd (ψ⁻ b))) , ((sym (GroupStr.rid (snd C) _) ∙∙ cong ((fun ϕ) ((fun (map ψ)) (fst (ψ⁻ b) A.+ (A.- snd (ψ⁻ b)) , GroupStr.0g (snd A))) C.+_) (sym (diag→ker (fun (map ψ) ((snd (ψ⁻ b)) , (snd (ψ⁻ b)))) ∣ (snd (ψ⁻ b)) , refl ∣₁)) ∙∙ sym ((isHom ϕ) _ _)) ∙∙ cong (fun ϕ) (sym ((isHom (map ψ)) _ _) ∙∙ cong (fun (map ψ)) (ΣPathP (sym (GroupStr.assoc (snd A) _ _ _) ∙∙ cong (fst (ψ⁻ b) A.+_) (GroupStr.invl (snd A) _) ∙∙ GroupStr.rid (snd A) _ , (GroupStr.lid (snd A) _))) ∙∙ rightInv ψ b) ∙∙ id) ∣₁ }) (issurj c) H¹-S¹≅ℤ : GroupIso intGroup (coHomGr 1 (S₊ 1)) H¹-S¹≅ℤ = diagonalIso (coHomGr 0 (S₊ 0)) (invGroupIso H⁰-S⁰≅ℤ×ℤ) (K.d 0) (λ x → K.Ker-i⊂Im-d 0 x (ΣPathP (isOfHLevelSuc 0 (isContrHⁿ-Unit 0) _ _ , isOfHLevelSuc 0 (isContrHⁿ-Unit 0) _ _))) ((sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp) (λ x inker → pRec propTruncIsProp (λ {((f , g) , id') → helper x f g id' inker}) ((K.Ker-d⊂Im-Δ 0 ∣ x ∣₂ inker))))) ((sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ F surj → pRec (setTruncIsSet _ _) (λ { (x , id) → K.Im-Δ⊂Ker-d 0 ∣ F ∣₂ ∣ (∣ (λ _ → x) ∣₂ , ∣ (λ _ → 0) ∣₂) , (cong ∣_∣₂ (funExt (surjHelper x))) ∙ sym id ∣₁ }) surj) ) □ invGroupIso (coHomPushout≅coHomSn 0 1) where module K = MV Unit Unit (S₊ 0) (λ _ → tt) (λ _ → tt) surjHelper : (x : Int) (x₁ : S₊ 0) → x -[ 0 ]ₖ 0 ≡ S0→Int (x , x) x₁ surjHelper x true = Iso.leftInv (Iso-Kn-ΩKn+1 0) x surjHelper x false = Iso.leftInv (Iso-Kn-ΩKn+1 0) x helper : (F : S₊ 0 → Int) (f g : ∥ (Unit → Int) ∥₂) (id : GroupHom.fun (K.Δ 0) (f , g) ≡ ∣ F ∣₂) → isInKer (coHomGr 0 (S₊ 0)) (coHomGr 1 (Pushout (λ _ → tt) (λ _ → tt))) (K.d 0) ∣ F ∣₂ → ∃[ x ∈ Int ] ∣ F ∣₂ ≡ inv H⁰-S⁰≅ℤ×ℤ (x , x) helper F = sElim2 (λ _ _ → isOfHLevelΠ 2 λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp) λ f g id inker → pRec propTruncIsProp (λ ((a , b) , id2) → sElim2 {C = λ f g → GroupHom.fun (K.Δ 0) (f , g) ≡ ∣ F ∣₂ → _ } (λ _ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp) (λ f g id → ∣ (helper2 f g .fst) , (sym id ∙ sym (helper2 f g .snd)) ∣₁) a b id2) (MV.Ker-d⊂Im-Δ _ _ (S₊ 0) (λ _ → tt) (λ _ → tt) 0 ∣ F ∣₂ inker) where helper2 : (f g : Unit → Int) → Σ[ x ∈ Int ] (inv H⁰-S⁰≅ℤ×ℤ (x , x)) ≡ GroupHom.fun (K.Δ 0) (∣ f ∣₂ , ∣ g ∣₂) helper2 f g = (f _ -[ 0 ]ₖ g _) , cong ∣_∣₂ (funExt λ {true → refl ; false → refl})
46.624113
142
0.458169
4a9ed4420ae32b8fb1aabdba410c31bc3acafe0b
11,424
agda
Agda
src/Partiality-monad/Inductive/Monad/Adjunction.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
2
2020-05-21T22:59:18.000Z
2020-07-03T08:56:08.000Z
src/Partiality-monad/Inductive/Monad/Adjunction.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
src/Partiality-monad/Inductive/Monad/Adjunction.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The partiality monad's monad instance, defined via an adjunction ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} module Partiality-monad.Inductive.Monad.Adjunction where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (T; ⊥) open import Adjunction equality-with-J open import Bijection equality-with-J using (_↔_) open import Category equality-with-J open import Function-universe equality-with-J hiding (id; _∘_) open import Functor equality-with-J open import H-level equality-with-J open import H-level.Closure equality-with-J open import Partiality-algebra as PA hiding (id; _∘_) open import Partiality-algebra.Category as PAC import Partiality-algebra.Properties as PAP open import Partiality-monad.Inductive as PI using (_⊥; partiality-algebra; initial) open import Partiality-monad.Inductive.Eliminators import Partiality-monad.Inductive.Monad as PM import Partiality-monad.Inductive.Omega-continuous as PO -- A forgetful functor from partiality algebras to sets. Forget : ∀ {a p q} {A : Type a} → PAC.precategory p q A ⇨ precategory-Set p ext functor Forget = (λ P → T P , T-is-set P) , Morphism.function , refl , refl where open Partiality-algebra -- The precategory of pointed ω-cpos. ω-CPPO : ∀ p q → Precategory (lsuc (p ⊔ q)) (p ⊔ q) ω-CPPO p q = PAC.precategory p q ⊥₀ -- Pointed ω-cpos. ω-cppo : ∀ p q → Type (lsuc (p ⊔ q)) ω-cppo p q = Partiality-algebra p q ⊥₀ -- If there is a function from B to the carrier of P, then P -- can be converted to a partiality algebra over B. convert : ∀ {a b p q} {A : Type a} {B : Type b} → (P : Partiality-algebra p q A) → (B → Partiality-algebra.T P) → Partiality-algebra p q B convert P f = record { T = T ; partiality-algebra-with = record { _⊑_ = _⊑_ ; never = never ; now = f ; ⨆ = ⨆ ; antisymmetry = antisymmetry ; T-is-set-unused = T-is-set-unused ; ⊑-refl = ⊑-refl ; ⊑-trans = ⊑-trans ; never⊑ = never⊑ ; upper-bound = upper-bound ; least-upper-bound = least-upper-bound ; ⊑-propositional = ⊑-propositional } } where open Partiality-algebra P -- A lemma that removes convert from certain types. drop-convert : ∀ {a p q p′ q′} {A : Type a} {X : ω-cppo p q} {Y : ω-cppo p′ q′} {f : A → _} {g : A → _} → Morphism (convert X f) (convert Y g) → Morphism X Y drop-convert m = record { function = function ; monotone = monotone ; strict = strict ; now-to-now = λ x → ⊥-elim x ; ω-continuous = ω-continuous } where open Morphism m -- Converts partiality algebras to ω-cppos. drop-now : ∀ {a p q} {A : Type a} → Partiality-algebra p q A → ω-cppo p q drop-now P = convert P ⊥-elim -- The function drop-now does not modify ω-cppos. drop-now-constant : ∀ {p q} {P : ω-cppo p q} → drop-now P ≡ P drop-now-constant = cong (λ now → record { partiality-algebra-with = record { now = now } }) (⟨ext⟩ λ x → ⊥-elim x) -- Converts types to ω-cppos. Partial⊚ : ∀ {ℓ} → Type ℓ → ω-cppo ℓ ℓ Partial⊚ = drop-now ∘ partiality-algebra private -- A lemma. Partial⊙′ : let open Partiality-algebra; open Morphism in ∀ {a b p q} {A : Type a} {B : Type b} (P : Partiality-algebra p q B) → (f : A → T P) → ∃ λ (m : Morphism (Partial⊚ A) (drop-now P)) → (∀ x → function m (PI.now x) ≡ now (convert P f) x) × (∀ m′ → (∀ x → function m′ (PI.now x) ≡ now (convert P f) x) → m ≡ m′) Partial⊙′ {A = A} P f = m′ , PI.⊥-rec-now _ , lemma where P′ : Partiality-algebra _ _ A P′ = convert P f m : Morphism (partiality-algebra A) P′ m = proj₁ (initial P′) m′ : Morphism (Partial⊚ A) (drop-now P) m′ = drop-convert m abstract lemma : ∀ m″ → (∀ x → Morphism.function m″ (PI.now x) ≡ Partiality-algebra.now P′ x) → m′ ≡ m″ lemma m″ hyp = _↔_.to equality-characterisation-Morphism ( function m′ ≡⟨⟩ function m ≡⟨ cong function (proj₂ (initial P′) record { function = function m″ ; monotone = monotone m″ ; strict = strict m″ ; now-to-now = hyp ; ω-continuous = ω-continuous m″ }) ⟩∎ function m″ ∎) where open Morphism -- Lifts functions between types to morphisms between the -- corresponding ω-cppos. Partial⊙ : ∀ {a b} {A : Type a} {B : Type b} → (A → B) → Morphism (Partial⊚ A) (Partial⊚ B) Partial⊙ f = proj₁ (Partial⊙′ (partiality-algebra _) (PI.now ∘ f)) -- Partial⊙ f is the unique morphism (of the given type) mapping -- PI.now x to PI.now (f x) (for all x). Partial⊙-now : ∀ {a b} {A : Type a} {B : Type b} {f : A → B} {x} → Morphism.function (Partial⊙ f) (PI.now x) ≡ PI.now (f x) Partial⊙-now = proj₁ (proj₂ (Partial⊙′ (partiality-algebra _) _)) _ Partial⊙-unique : ∀ {a b} {A : Type a} {B : Type b} {f : A → B} {m} → (∀ x → Morphism.function m (PI.now x) ≡ PI.now (f x)) → Partial⊙ f ≡ m Partial⊙-unique = proj₂ (proj₂ (Partial⊙′ (partiality-algebra _) _)) _ -- A functor that maps a set A to A ⊥. Partial : ∀ {ℓ} → precategory-Set ℓ ext ⇨ ω-CPPO ℓ ℓ _⇨_.functor (Partial {ℓ}) = Partial⊚ ∘ proj₁ , Partial⊙ , L.lemma₁ , L.lemma₂ where open Morphism module L where abstract lemma₁ : {A : Type ℓ} → Partial⊙ (id {A = A}) ≡ PA.id lemma₁ = Partial⊙-unique λ _ → refl lemma₂ : {A B C : Type ℓ} {f : A → B} {g : B → C} → Partial⊙ (g ∘ f) ≡ Partial⊙ g PA.∘ Partial⊙ f lemma₂ {f = f} {g} = Partial⊙-unique λ x → function (Partial⊙ g PA.∘ Partial⊙ f) (PI.now x) ≡⟨ cong (function (Partial⊙ g)) Partial⊙-now ⟩ function (Partial⊙ g) (PI.now (f x)) ≡⟨ Partial⊙-now ⟩∎ PI.now (g (f x)) ∎ -- Partial is a left adjoint of Forget. Partial⊣Forget : ∀ {ℓ} → Partial {ℓ = ℓ} ⊣ Forget Partial⊣Forget {ℓ} = η , ε , (λ {X} → let P = Partial⊚ (proj₁ X) in _↔_.to equality-characterisation-Morphism $ ⟨ext⟩ $ ⊥-rec-⊥ record { pe = fun P (function (Partial⊙ PI.now) PI.never) ≡⟨ cong (fun P) $ strict (Partial⊙ PI.now) ⟩ fun P PI.never ≡⟨ strict (m P) ⟩∎ PI.never ∎ ; po = λ x → fun P (function (Partial⊙ PI.now) (PI.now x)) ≡⟨ cong (fun P) Partial⊙-now ⟩ fun P (PI.now (PI.now x)) ≡⟨ fun-now P ⟩∎ PI.now x ∎ ; pl = λ s hyp → fun P (function (Partial⊙ PI.now) (PI.⨆ s)) ≡⟨ cong (fun P) $ ω-continuous (Partial⊙ PI.now) _ ⟩ fun P (PI.⨆ _) ≡⟨ ω-continuous (m P) _ ⟩ PI.⨆ _ ≡⟨ cong PI.⨆ $ _↔_.to PI.equality-characterisation-increasing hyp ⟩∎ PI.⨆ s ∎ ; pp = λ _ → PI.⊥-is-set }) , (λ {X} → ⟨ext⟩ λ x → fun X (PI.now x) ≡⟨ fun-now X ⟩∎ x ∎) where open Morphism {q₂ = ℓ} open PAP open Partiality-algebra η : id⇨ ⇾ Forget ∙⇨ Partial _⇾_.natural-transformation η = PI.now , (λ {X Y f} → ⟨ext⟩ λ x → function (Partial⊙ f) (PI.now x) ≡⟨ Partial⊙-now ⟩∎ PI.now (f x) ∎) m : (X : ω-cppo ℓ ℓ) → Morphism (Partial⊚ (T X)) X m X = $⟨ id ⟩ (T X → T X) ↝⟨ proj₁ ∘ Partial⊙′ X ⟩ Morphism (Partial⊚ (T X)) (drop-now X) ↝⟨ drop-convert ⟩□ Morphism (Partial⊚ (T X)) X □ fun : (X : ω-cppo ℓ ℓ) → T X ⊥ → T X fun X = function (m X) fun-now : ∀ (X : ω-cppo ℓ ℓ) {x} → fun X (PI.now x) ≡ x fun-now X = proj₁ (proj₂ (Partial⊙′ X _)) _ fun-unique : (X : ω-cppo ℓ ℓ) (m′ : Morphism (Partial⊚ (T X)) X) → (∀ x → function m′ (PI.now x) ≡ x) → fun X ≡ function m′ fun-unique X m′ hyp = cong function $ proj₂ (proj₂ (Partial⊙′ X _)) (drop-convert m′) hyp ε : Partial ∙⇨ Forget ⇾ id⇨ _⇾_.natural-transformation ε = (λ {X} → m X) , (λ {X Y f} → let m′ = (Partial ∙⇨ Forget) ⊙ f in _↔_.to equality-characterisation-Morphism $ ⟨ext⟩ $ ⊥-rec-⊥ record { pe = function f (fun X PI.never) ≡⟨ cong (function f) (strict (m X)) ⟩ function f (never X) ≡⟨ strict f ⟩ never Y ≡⟨ sym $ strict (m Y) ⟩ fun Y PI.never ≡⟨ cong (fun Y) $ sym $ strict m′ ⟩∎ fun Y (function m′ PI.never) ∎ ; po = λ x → function f (fun X (PI.now x)) ≡⟨ cong (function f) (fun-now X) ⟩ function f x ≡⟨ sym $ fun-now Y ⟩ fun Y (PI.now (function f x)) ≡⟨ cong (fun Y) $ sym Partial⊙-now ⟩∎ fun Y (function m′ (PI.now x)) ∎ ; pl = λ s hyp → function f (fun X (PI.⨆ s)) ≡⟨ cong (function f) (ω-continuous (m X) _) ⟩ function f (⨆ X _) ≡⟨ ω-continuous f _ ⟩ ⨆ Y _ ≡⟨ cong (⨆ Y) $ _↔_.to (equality-characterisation-increasing Y) hyp ⟩ ⨆ Y _ ≡⟨ sym $ ω-continuous (m Y) _ ⟩ fun Y (PI.⨆ _) ≡⟨ cong (fun Y) $ sym $ ω-continuous m′ _ ⟩∎ fun Y (function m′ (PI.⨆ s)) ∎ ; pp = λ _ → T-is-set Y }) -- Thus we get that the partiality monad is a monad. Partiality-monad : ∀ {ℓ} → Monad (precategory-Set ℓ ext) Partiality-monad = adjunction→monad (Partial , Forget , Partial⊣Forget) private -- The object part of the monad's functor really does correspond to -- the partiality monad. object-part-of-functor-correct : ∀ {a} {A : Set a} → proj₁ (proj₁ Partiality-monad ⊚ A) ≡ proj₁ A ⊥ object-part-of-functor-correct = refl -- The definition of "map" obtained here matches the explicit -- definition in Partiality-monad.Inductive.Monad. map-correct : ∀ {ℓ} {A B : Set ℓ} {f : proj₁ A → proj₁ B} → _⊙_ (proj₁ Partiality-monad) {X = A} {Y = B} f ≡ PO.[_⊥→_⊥].function (PM.map f) map-correct = refl -- The definition of "return" is the expected one. return-correct : ∀ {a} {A : Set a} → _⇾_.transformation (proj₁ (proj₂ Partiality-monad)) {X = A} ≡ PI.now return-correct = refl -- The definition of "join" obtained here matches the explicit -- definition in Partiality-monad.Inductive.Monad. join-correct : ∀ {a} {A : Set a} → _⇾_.transformation (proj₁ (proj₂ (proj₂ Partiality-monad))) {X = A} ≡ PM.join join-correct = refl
34.203593
131
0.503589
18c956c57665543f4435e57a80e0767b654f30d8
152
agda
Agda
Cubical/HITs/Colimit.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/HITs/Colimit.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/HITs/Colimit.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.HITs.Colimit where open import Cubical.HITs.Colimit.Base public open import Cubical.HITs.Colimit.Examples public
25.333333
48
0.789474
fbf56a8fd992158d4ef34f5fafdc7792990d31e2
124
agda
Agda
archive/agda-2/Oscar/Builtin/Nat.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-2/Oscar/Builtin/Nat.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-2/Oscar/Builtin/Nat.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module Oscar.Builtin.Nat where open import Agda.Builtin.Nat public using () renaming (Nat to ℕ; zero to ∅; suc to ↑_)
17.714286
43
0.701613
cba82cef121f53a28bb3669e8fbb2abc431303ad
8,735
agda
Agda
examples/tactics/ac/AC.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
examples/tactics/ac/AC.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/tactics/ac/AC.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
{-# OPTIONS --no-termination-check #-} module AC where import Nat import Bool import List import Fin import Logic import Vec import EqProof open Nat hiding (_<_) renaming (_==_ to _=Nat=_) open Bool open List hiding (module Eq) open Fin renaming (_==_ to _=Fin=_) open Logic open Vec infix 20 _○_ infix 10 _≡_ ForAll : {A : Set}(n : Nat) -> (Vec n A -> Set) -> Set ForAll zero F = F ε ForAll {A} (suc n) F = (x : A) -> ForAll _ \xs -> F (x ∷ xs) apply : {n : Nat}{A : Set}(F : Vec n A -> Set) -> ForAll n F -> (xs : Vec n A) -> F xs apply {zero} F t (vec vnil) = t apply {suc n} F f (vec (vcons x xs)) = apply _ (f x) xs lambda : {n : Nat}{A : Set}(F : Vec n A -> Set) -> ((xs : Vec n A) -> F xs) -> ForAll n F lambda {zero } F f = f ε lambda {suc n} F f = \x -> lambda _ (\xs -> f (x ∷ xs)) data Expr (n : Nat) : Set where zro : Expr n var : Fin n -> Expr n _○_ : Expr n -> Expr n -> Expr n data Theorem (n : Nat) : Set where _≡_ : Expr n -> Expr n -> Theorem n theorem : (n : Nat) -> ({m : Nat} -> ForAll {Expr m} n \_ -> Theorem m) -> Theorem n theorem n thm = apply _ thm (map var (fzeroToN-1 n)) module Provable where NF : Nat -> Set NF n = List (Fin n) infix 12 _⊕_ _⊕_ : {n : Nat} -> NF n -> NF n -> NF n [] ⊕ ys = ys x :: xs ⊕ [] = x :: xs x :: xs ⊕ y :: ys = if x < y then x :: (xs ⊕ y :: ys) else y :: (x :: xs ⊕ ys) normalise : {n : Nat} -> Expr n -> NF n normalise zro = [] normalise (var n) = n :: [] normalise (a ○ b) = normalise a ⊕ normalise b infix 30 _↓ _↓ : {n : Nat} -> NF n -> Expr n (i :: is) ↓ = var i ○ is ↓ [] ↓ = zro infix 10 _=Expr=_ _=NF=_ _=NF=_ : {n : Nat} -> NF n -> NF n -> Bool _=NF=_ = ListEq._==_ where module ListEq = List.Eq _=Fin=_ substNF : {n : Nat}{xs ys : NF n}(P : NF n -> Set) -> IsTrue (xs =NF= ys) -> P xs -> P ys substNF = List.Subst.subst _=Fin=_ (subst {_}) _=Expr=_ : {n : Nat} -> Expr n -> Expr n -> Bool a =Expr= b = normalise a =NF= normalise b provable : {n : Nat} -> Theorem n -> Bool provable (a ≡ b) = a =Expr= b module Semantics {A : Set} (_==_ : A -> A -> Set) (_*_ : A -> A -> A) (one : A) (refl : {x : A} -> x == x) (sym : {x y : A} -> x == y -> y == x) (trans : {x y z : A} -> x == y -> y == z -> x == z) (idL : {x : A} -> (one * x) == x) (idR : {x : A} -> (x * one) == x) (comm : {x y : A} -> (x * y) == (y * x)) (assoc : {x y z : A} -> (x * (y * z)) == ((x * y) * z)) (congL : {x y z : A} -> y == z -> (x * y) == (x * z)) (congR : {x y z : A} -> x == y -> (x * z) == (y * z)) where open Provable module EqP = EqProof _==_ refl trans open EqP expr[_] : {n : Nat} -> Expr n -> Vec n A -> A expr[ zro ] ρ = one expr[ var i ] ρ = ρ ! i expr[ a ○ b ] ρ = expr[ a ] ρ * expr[ b ] ρ eq[_] : {n : Nat} -> Theorem n -> Vec n A -> Set eq[ a ≡ b ] ρ = expr[ a ] ρ == expr[ b ] ρ data CantProve (A : Set) : Set where no-proof : CantProve A Prf : {n : Nat} -> Theorem n -> Bool -> Set Prf thm true = ForAll _ \ρ -> eq[ thm ] ρ Prf thm false = CantProve (Prf thm true) Proof : {n : Nat} -> Theorem n -> Set Proof thm = Prf thm (provable thm) lem0 : {n : Nat} -> (xs ys : NF n) -> (ρ : Vec n A) -> eq[ xs ↓ ○ ys ↓ ≡ (xs ⊕ ys) ↓ ] ρ lem0 [] ys ρ = idL lem0 (x :: xs) [] ρ = idR lem0 (x :: xs) (y :: ys) ρ = if' x < y then less else more where lhs = (var x ○ xs ↓) ○ (var y ○ ys ↓) lbranch = x :: (xs ⊕ y :: ys) rbranch = y :: (x :: xs ⊕ ys) P = \z -> eq[ lhs ≡ (if z then lbranch else rbranch) ↓ ] ρ less : IsTrue (x < y) -> _ less x<y = BoolEq.subst {true}{x < y} P x<y (spine (lem0 xs (y :: ys) ρ)) where spine : forall {x' xs' y' ys' zs} h -> _ spine {x'}{xs'}{y'}{ys'}{zs} h = eqProof> (x' * xs') * (y' * ys') === x' * (xs' * (y' * ys')) by sym assoc === x' * zs by congL h more : IsFalse (x < y) -> _ more x>=y = BoolEq.subst {false}{x < y} P x>=y (spine (lem0 (x :: xs) ys ρ)) where spine : forall {x' xs' y' ys' zs} h -> _ spine {x'}{xs'}{y'}{ys'}{zs} h = eqProof> (x' * xs') * (y' * ys') === (y' * ys') * (x' * xs') by comm === y' * (ys' * (x' * xs')) by sym assoc === y' * ((x' * xs') * ys') by congL comm === y' * zs by congL h lem1 : {n : Nat} -> (e : Expr n) -> (ρ : Vec n A) -> eq[ e ≡ normalise e ↓ ] ρ lem1 zro ρ = refl lem1 (var i) ρ = sym idR lem1 (a ○ b) ρ = trans step1 (trans step2 step3) where step1 : eq[ a ○ b ≡ normalise a ↓ ○ b ] ρ step1 = congR (lem1 a ρ) step2 : eq[ normalise a ↓ ○ b ≡ normalise a ↓ ○ normalise b ↓ ] ρ step2 = congL (lem1 b ρ) step3 : eq[ normalise a ↓ ○ normalise b ↓ ≡ (normalise a ⊕ normalise b) ↓ ] ρ step3 = lem0 (normalise a) (normalise b) ρ lem2 : {n : Nat} -> (xs ys : NF n) -> (ρ : Vec n A) -> IsTrue (xs =NF= ys) -> eq[ xs ↓ ≡ ys ↓ ] ρ lem2 xs ys ρ eq = substNF {_}{xs}{ys} (\z -> eq[ xs ↓ ≡ z ↓ ] ρ) eq refl prove : {n : Nat} -> (thm : Theorem n) -> Proof thm prove thm = proof (provable thm) thm (\h -> h) where proof : {n : Nat}(valid : Bool)(thm : Theorem n) -> (IsTrue valid -> IsTrue (provable thm)) -> Prf thm valid proof false _ _ = no-proof proof true (a ≡ b) isValid = lambda eq[ a ≡ b ] \ρ -> trans (step-a ρ) (trans (step-ab ρ) (step-b ρ)) where step-a : forall ρ -> eq[ a ≡ normalise a ↓ ] ρ step-a ρ = lem1 a ρ step-b : forall ρ -> eq[ normalise b ↓ ≡ b ] ρ step-b ρ = sym (lem1 b ρ) step-ab : forall ρ -> eq[ normalise a ↓ ≡ normalise b ↓ ] ρ step-ab ρ = lem2 (normalise a) (normalise b) ρ (isValid tt) n0 = zero n1 = suc n0 n2 = suc n1 n3 = suc n2 n4 = suc n3 n5 = suc n4 n6 = suc n5 n7 = suc n6 n8 = suc n7 n9 = suc n8 open Provable thmRefl = theorem n1 \x -> x ≡ x thmCom = theorem n2 \x y -> x ○ y ≡ y ○ x thm1 = theorem n3 \x y z -> x ○ (y ○ z) ≡ (z ○ y) ○ x thm2 = theorem n3 \x y z -> x ○ (y ○ z) ≡ (z ○ x) ○ x thm3 = theorem n5 \a b c d e -> (a ○ (a ○ b)) ○ ((c ○ d) ○ (e ○ e)) ≡ b ○ ((e ○ (c ○ a)) ○ (d ○ (e ○ a))) infix 10 _===_ data _===_ (n m : Nat) : Set where eqn : IsTrue (n =Nat= m) -> n === m postulate refl : {x : Nat} -> x === x sym : {x y : Nat} -> x === y -> y === x trans : {x y z : Nat} -> x === y -> y === z -> x === z idL : {x : Nat} -> (zero + x) === x idR : {x : Nat} -> (x + zero) === x comm : {x y : Nat} -> (x + y) === (y + x) assoc : {x y z : Nat} -> (x + (y + z)) === ((x + y) + z) congL : {x y z : Nat} -> y === z -> x + y === x + z congR : {x y z : Nat} -> x === y -> x + z === y + z module NatPlus = Semantics _===_ _+_ zero refl sym trans idL idR (\{x}{y} -> comm {x}{y}) (\{x}{y}{z} -> assoc {x}{y}{z}) (\{x} -> congL {x}) (\{_}{_}{z} -> congR {z = z}) open NatPlus test : (x y z : Nat) -> x + (y + z) === (z + x) + y test = prove (theorem n3 \x y z -> x ○ (y ○ z) ≡ (z ○ x) ○ y) {- _437 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 -> lem0 (x15 :: x16) x18 x19 | [ (expr[ ((x :: xs) ↓ ○ ys ↓) ]) ρ == (expr[ ((x :: xs ⊕ ys) ↓) ]) ρ = _395 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x>=y (ρ ! x) ((expr[ (xs ↓) ]) ρ) (ρ ! y) ((expr[ (ys ↓) ]) ρ) ((expr[ ((x :: xs ⊕ ys) ↓) ]) ρ) : Set ] _428 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 -> x26 | [ _395 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x>=y x xs y ys zs = x * xs * ys == zs : Set ] _364 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 -> lem0 x16 (x17 :: x18) x19 | [(expr[ (xs ↓ ○ (y :: ys) ↓) ]) ρ == (expr[ ((xs ⊕ y :: ys) ↓) ]) ρ = _337 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x<y (ρ ! x) ((expr[ (xs ↓) ]) ρ) (ρ ! y) ((expr[ (ys ↓) ]) ρ) ((expr[ ((xs ⊕ y :: ys) ↓) ]) ρ) : Set] _355 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 -> x26 | [_337 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x<y x xs y ys zs = xs * (y * ys) == zs : Set] -}
33.339695
167
0.448197
41e0fcb26896c4ad368e2ae7b6dd18462eee8185
1,837
agda
Agda
agda-stdlib-0.9/src/Data/Char.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/Char.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Char.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Characters ------------------------------------------------------------------------ module Data.Char where open import Data.Nat using (ℕ) import Data.Nat.Properties as NatProp open import Data.Bool using (Bool; true; false) open import Relation.Nullary open import Relation.Nullary.Decidable open import Relation.Binary import Relation.Binary.On as On open import Relation.Binary.PropositionalEquality as PropEq using (_≡_) open import Relation.Binary.PropositionalEquality.TrustMe open import Data.String.Core using (String; primShowChar) import Data.Char.Core as Core open Core public using (Char) open Core show : Char → String show = primShowChar toNat : Char → ℕ toNat = primCharToNat -- Informative equality test. _≟_ : Decidable {A = Char} _≡_ s₁ ≟ s₂ with primCharEquality s₁ s₂ ... | true = yes trustMe ... | false = no whatever where postulate whatever : _ -- Boolean equality test. -- -- Why is the definition _==_ = primCharEquality not used? One reason -- is that the present definition can sometimes improve type -- inference, at least with the version of Agda that is current at the -- time of writing: see unit-test below. infix 4 _==_ _==_ : Char → Char → Bool c₁ == c₂ = ⌊ c₁ ≟ c₂ ⌋ private -- The following unit test does not type-check (at the time of -- writing) if _==_ is replaced by primCharEquality. data P : (Char → Bool) → Set where p : (c : Char) → P (_==_ c) unit-test : P (_==_ 'x') unit-test = p _ setoid : Setoid _ _ setoid = PropEq.setoid Char decSetoid : DecSetoid _ _ decSetoid = PropEq.decSetoid _≟_ -- An ordering induced by the toNat function. strictTotalOrder : StrictTotalOrder _ _ _ strictTotalOrder = On.strictTotalOrder NatProp.strictTotalOrder toNat
25.873239
72
0.673381
57d959e14d340c6f13d386a9fa0d342be559e4a6
5,917
agda
Agda
src/jarsec.agda
jaywunder/jarsec-verified
40cca331810f1d3f7dc099614ddca4fa96bd695c
[ "MIT" ]
null
null
null
src/jarsec.agda
jaywunder/jarsec-verified
40cca331810f1d3f7dc099614ddca4fa96bd695c
[ "MIT" ]
null
null
null
src/jarsec.agda
jaywunder/jarsec-verified
40cca331810f1d3f7dc099614ddca4fa96bd695c
[ "MIT" ]
null
null
null
module jarsec where open import Algebra open import Data.Bool open import Data.Char -- open import Data.Empty -- open import Data.Fin open import Data.List open import Data.Maybe hiding (map) open import Data.Nat open import Data.Nat.Base open import Data.Nat.Show -- open import Data.Integer open import Data.Product hiding (map) open import Data.Sum hiding (map) open import Data.String hiding (length) open import Function -- open import Data.Sum -- open import Data.Unit -- open import Data.Vec open import Category.Functor open import Relation.Binary open import Data.Char.Base open import Agda.Builtin.Char open import Relation.Binary.PropositionalEquality using (_≡_ ; refl) record Parser (A : Set) : Set where constructor mk-parser field parse : List Char → (List (A × (List Char))) open Parser public item : Parser Char item = mk-parser λ where [] → [] (c ∷ cs) → (c , cs) ∷ [] bind : ∀ { A B : Set } → Parser A → (A → Parser B) → Parser B bind {A} p f = mk-parser $ λ cs → let rs : List (A × List Char) rs = parse p cs in concatMap (λ x → parse (f (proj₁ x)) (proj₂ x)) rs -- in concatMap (λ where (x , cs′) → parse (f x) cs′) rs _>>=_ : ∀ { A B : Set } → Parser A → (A → Parser B) → Parser B p >>= f = bind p f _>>_ : ∀ { A B : Set } → Parser A → Parser B → Parser B pA >> pB = pA >>= λ _ → pB unit : ∀ { A : Set } → A → Parser A unit a = mk-parser (λ str → ( a , str ) ∷ []) unit* : ∀ { A : Set } → List A → Parser A unit* xs = mk-parser (λ str → foldl (λ sum x → (x , str) ∷ sum) [] xs) fmap : ∀ { A B : Set } → (A → B) → Parser A → Parser B fmap f p = do a ← p unit (f a) _<$>_ : ∀ { A B : Set } → (A → B) → Parser A → Parser B f <$> p = fmap f p _<*>_ : ∀ {A B : Set } → Parser A → Parser B → Parser ( A × B ) aP <*> bP = do a ← aP b ← bP unit (a , b) combine : { A : Set } → Parser A → Parser A → Parser A combine p q = mk-parser (λ cs → (parse p cs) Data.List.++ (parse q cs)) failure : { A : Set } → Parser A failure = mk-parser (λ cs → []) option : { A : Set } → Parser A → Parser A → Parser A option p q = mk-parser $ λ where cs → case (parse p cs) of λ where [] → parse q cs result → result {-# TERMINATING #-} mutual many* : { A : Set } → Parser A → Parser (List A) many* v = option (many+ v) (unit []) many+ : { A : Set } → Parser A → Parser (List A) many+ v = fmap (λ { (a , list) → a ∷ list }) (v <*> (many* v)) satisfy : (Char -> Bool) -> Parser Char satisfy f = do c ← item case (f c) of λ where true → unit c false → failure oneOf : List Char → Parser Char oneOf options = satisfy (flip elem options) where elem : Char → List Char → Bool elem a [] = false elem a (x ∷ xs) = case primCharEquality a x of λ where true → true false → elem a xs module _ { A : Set } where {-# TERMINATING #-} chainl1 : Parser A → Parser (A → A → A) → Parser A chainl1 p op = do a ← p rest a where rest : A → Parser A rest a = option (do f ← op b ← p rest (f a b)) (unit a) chainl : { A : Set } → Parser A → Parser (A → A → A) → A → Parser A chainl p op a = option (chainl1 p op) (unit a) char : Char → Parser Char char c = satisfy (primCharEquality c) digit : Parser Char digit = satisfy isDigit -- TODO: Remove ∣_-_∣ : ℕ → ℕ → ℕ ∣ zero - y ∣ = y ∣ x - zero ∣ = x ∣ suc x - suc y ∣ = ∣ x - y ∣ natural : Parser ℕ natural = natFromList <$> ((map primCharToNat) <$> (many+ digit)) where natFromList : List ℕ → ℕ natFromList [] = zero natFromList (n ∷ ns) = let len = length ns in (∣ n - 48 ∣ + (10 * len)) + (natFromList ns) string : String → Parser String string str = primStringFromList <$> (string-chars (primStringToList str)) where string-chars : List Char → Parser (List Char) string-chars [] = unit [] string-chars (c ∷ cs) = do char c string-chars cs unit (c ∷ cs) spaces : Parser String spaces = fmap primStringFromList (many* (oneOf (primStringToList " \n\r"))) token : { A : Set } → Parser A → Parser A token p = do a ← p spaces unit a reserved : String → Parser String reserved str = token (string str) parens : { A : Set } → Parser A → Parser A parens m = do (reserved "(") n ← m (reserved ")") unit n -------------------------------------------------------------------------------- data Expr : Set where Invalid : Expr -- Var : Char → Expr Lit : ℕ → Expr Add : Expr → Expr → Expr Mul : Expr → Expr → Expr -- Add Sub : Expr → Expr → Expr -- Mul Div : Expr → Expr → Expr eval : Expr → ℕ eval Invalid = 0 eval (Lit n) = n eval (Add a b) = eval a + eval b eval (Mul a b) = eval a * eval b eval′ : Maybe Expr → ℕ eval′ (just x) = eval x eval′ nothing = 0 module _ where {-# TERMINATING #-} expr : Parser Expr {-# TERMINATING #-} term : Parser Expr {-# TERMINATING #-} factor : Parser Expr infixOp : {A : Set} → String → (A → A → A) → Parser (A → A → A) mulop : Parser (Expr → Expr → Expr) addop : Parser (Expr → Expr → Expr) number : Parser Expr expr = chainl1 term addop term = chainl1 factor mulop factor = option number (parens expr) infixOp x f = reserved x >> unit f mulop = infixOp "*" Mul addop = infixOp "+" Add number = do n ← natural unit (Lit n) runParser : { A : Set } → Parser A → String → Maybe A runParser p str = case (parse p (primStringToList str)) of λ where [] → nothing (res ∷ xs) → just (proj₁ res) run : String → Maybe Expr run = runParser expr do-everything : String → ℕ do-everything str = eval′ $ run str partial-parse : { A : Set } → Parser A → String → Maybe (List (A × List Char)) partial-parse p str with parse p (primStringToList str) partial-parse p str | [] = nothing partial-parse p str | xs = just xs run-parser : { A : Set } → Parser A → List Char → Maybe (List (A × List Char)) run-parser p str = case (parse p str) of λ where [] → nothing xs → just xs
24.052846
80
0.584925
41c73842cfb1dff804f38c96f68549adc96cc7f6
302
agda
Agda
test/interaction/Issue2543.agda
k-bx/agda
a2a54ce1b97fe103fbe1b961ffda95fe6313abf0
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/interaction/Issue2543.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
null
null
null
test/interaction/Issue2543.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, 2017-04-11, Issue 2543 -- Printing of second non-trivial with-pattern -- {-# OPTIONS -v interaction.case:100 #-} data D : Set where c : D → D f : D → D f y with c y ... | c z with c y ... | q = {!q!} -- C-c C-c q -- Was: -- f y | c z | (c q) = ? -- Expected: -- f y | c z | c q = ?
15.894737
46
0.503311
22670a71a018246e8bf2cc3dfcffd8de7750dd86
2,168
agda
Agda
Cubical/Experiments/Rng.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Experiments/Rng.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Experiments/Rng.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
-- This file needs to be rewritten so that Rng's are defined as a -- record (as is the case for other algebraic structures like -- rings). As this file isn't used for anything at the moment this -- rewrite has been postponed. {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Experiments.Rng where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Structures.Semigroup hiding (⟨_⟩) open import Cubical.Structures.AbGroup private variable ℓ ℓ' : Level module _ {ℓ} where rawRngDesc : Desc ℓ rawRngDesc = autoDesc (λ (X : Type ℓ) → (X → X → X) × (X → X → X)) open Macro ℓ rawRngDesc public renaming ( structure to RawRngStructure ; equiv to RawRngEquivStr ; univalent to rawRngUnivalentStr ) RngAxioms : (X : Type ℓ) (s : RawRngStructure X) → Type ℓ RngAxioms X (_·_ , _+_) = AbGroupΣTheory.AbGroupAxioms X _·_ × SemigroupΣTheory.SemigroupAxioms X _+_ × ((x y z : X) → x · (y + z) ≡ (x · y) + (x · z)) × ((x y z : X) → (x + y) · z ≡ (x · z) + (y · z)) RngStructure : Type ℓ → Type ℓ RngStructure = AxiomsStructure RawRngStructure RngAxioms Rng : Type (ℓ-suc ℓ) Rng {ℓ} = TypeWithStr ℓ RngStructure RngEquivStr : StrEquiv RngStructure ℓ RngEquivStr = AxiomsEquivStr RawRngEquivStr RngAxioms isPropRngAxioms : (X : Type ℓ) (s : RawRngStructure X) → isProp (RngAxioms X s) isPropRngAxioms X (_·_ , _+_) = isPropΣ (AbGroupΣTheory.isPropAbGroupAxioms X _·_) λ _ → isPropΣ (SemigroupΣTheory.isPropSemigroupAxioms X _+_) λ { (isSetX , _) → isPropΣ (isPropΠ3 (λ _ _ _ → isSetX _ _)) λ _ → isPropΠ3 (λ _ _ _ → isSetX _ _)} rngUnivalentStr : UnivalentStr {ℓ} RngStructure RngEquivStr rngUnivalentStr = axiomsUnivalentStr _ isPropRngAxioms rawRngUnivalentStr RngPath : (M N : Rng {ℓ}) → (M ≃[ RngEquivStr ] N) ≃ (M ≡ N) RngPath = SIP rngUnivalentStr
35.540984
99
0.683118
4186dd6c9b453ffc3754eee42442f86c426f9f4c
123
agda
Agda
test/Fail/Issue2893.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2893.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2893.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where module M where F : Set → Set F A = A open M infix 0 F syntax F A = [ A ] G : Set → Set G A = [ A ]
8.2
18
0.528455
df1a7769bb98dcf5863a45b0502a9643b3973e50
9,473
agda
Agda
homotopy/JoinAssoc3x3.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
homotopy/JoinAssoc3x3.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/JoinAssoc3x3.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import homotopy.3x3.Common open import homotopy.3x3.PushoutPushout open import homotopy.3x3.Transpose module homotopy.JoinAssoc3x3 {i} (A B C : Type i) where open M using (Pushout^2) join-assoc-span^2 : Span^2 {i} join-assoc-span^2 = span^2 A (A × C) (A × C) (A × B) ((A × B) × C) (A × C) B (B × C) C fst (idf _) fst (λ u → fst (fst u) , snd u) fst snd fst snd (λ u → fst (fst u) , snd u) (λ u → snd (fst u) , snd u) (idf _) snd (λ _ → idp) (λ _ → idp) (λ _ → idp) (λ _ → idp) open import homotopy.3x3.Commutes join-assoc-span^2 as PP module _ (A B : Type i) (f : B → A) where lemma3-fun : Pushout (span A B B f (idf _)) → A lemma3-fun = Lemma3Fun.f module _ where module Lemma3Fun = PushoutRec (idf _) f (λ _ → idp) lemma3-eq : (x : Pushout (span A B B f (idf _))) → left (lemma3-fun x) == x lemma3-eq = Pushout-elim (λ _ → idp) glue (λ b → ↓-∘=idf-in left lemma3-fun (idp,=□idp,-in idp ∙□-i/ idp / ! (ap (ap left) (Lemma3Fun.glue-β b)) /)) lemma3 : Pushout (span A B B f (idf _)) ≃ A lemma3 = equiv lemma3-fun left (λ _ → idp) lemma3-eq module _ (A B : Type i) (f : B → A) where lemma3'-fun : Pushout (span B A B (idf _) f) → A lemma3'-fun = Lemma3'Fun.f module _ where module Lemma3'Fun = PushoutRec f (idf _) (λ _ → idp) lemma3'-eq : (x : Pushout (span B A B (idf _) f)) → right (lemma3'-fun x) == x lemma3'-eq = ! ∘ (Pushout-elim glue (λ _ → idp) (λ b → ↓-idf=∘-in right lemma3'-fun (,idp=□,idp-in idp ∙□-i/ ap (ap right) (Lemma3'Fun.glue-β b) / idp /))) lemma3' : Pushout (span B A B (idf _) f) ≃ A lemma3' = equiv lemma3'-fun right (λ _ → idp) lemma3'-eq module _ (X Y Z T : Type i) (f : Z → X) (g : Z → Y) where private P1 : Type i P1 = Pushout (span X Y Z f g) P2 : Type i P2 = Pushout (span (X × T) (Y × T) (Z × T) (λ u → (f (fst u) , snd u)) (λ u → (g (fst u) , snd u))) lemma4 : P2 ≃ (P1 × T) lemma4 = equiv to from to-from from-to module Lemma4 where to : P2 → P1 × T to = To.f module _ where module To = PushoutRec (λ u → (left (fst u) , snd u)) (λ u → (right (fst u) , snd u)) (λ u → pair×= (glue (fst u)) idp) from-curr : T → (P1 → P2) from-curr t = FromCurr.f module _ where module FromCurr = PushoutRec {D = P2} (λ x → left (x , t)) (λ y → right (y , t)) (λ z → glue (z , t)) from : P1 × T → P2 from (x , t) = from-curr t x to-from : (u : P1 × T) → to (from u) == u to-from (x , t) = to-from-curr t x where ap-idf,×cst : ∀ {i j} {A : Type i} {B : Type j} {x y : A} (p : x == y) {b : B} → ap (λ v → v , b) p == pair×= p idp ap-idf,×cst idp = idp to-from-curr : (t : T) (x : P1) → to (from-curr t x) == (x , t) to-from-curr t = Pushout-elim (λ _ → idp) (λ _ → idp) (λ z → ↓-='-in (ap-idf,×cst (glue z) ∙ ! (To.glue-β (z , t)) ∙ ! (ap (ap to) (FromCurr.glue-β t z)) ∙ ∘-ap to (from-curr t) (glue z))) from-to : (u : P2) → from (to u) == u from-to = Pushout-elim (λ _ → idp) (λ _ → idp) (λ c → ↓-∘=idf-in from to (! (ap (ap from) (To.glue-β c) ∙ ap-pair×= from (glue (fst c)) ∙ FromCurr.glue-β (snd c) (fst c)))) where ap-pair×= : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A × B → C) {a a' : A} (p : a == a') {b : B} → ap f (pair×= p idp) == ap (λ a → f (a , b)) p ap-pair×= f {a = a} {a' = .a} idp = idp module _ (X Y T : Type i) where private P1 : Type i P1 = Pushout (span X Y (X × Y) fst snd) P2 : Type i P2 = Pushout (span (T × X) (T × Y) ((T × X) × Y) fst (λ u → (fst (fst u) , snd u))) lemma4' : P2 ≃ (T × P1) lemma4' = equiv to from to-from from-to module Lemma4' where to : P2 → T × P1 to = To.f module _ where module To = PushoutRec {D = T × P1} (λ u → (fst u , left (snd u))) (λ u → (fst u , right (snd u))) (λ c → pair×= idp (glue (snd (fst c) , snd c))) from-curr : T → (P1 → P2) from-curr t = FromCurr.f module _ where module FromCurr = PushoutRec {D = P2} (λ x → left (t , x)) (λ y → right (t , y)) (λ z → glue ((t , fst z) , snd z)) from : T × P1 → P2 from (t , x) = from-curr t x to-from : (u : T × P1) → to (from u) == u to-from (t , x) = to-from-curr t x where to-from-curr : (t : T) (x : P1) → to (from-curr t x) == (t , x) to-from-curr t = Pushout-elim (λ _ → idp) (λ _ → idp) (λ c → ↓-='-in (ap-cst,id (λ _ → _) (glue c) ∙ ! (lemma5 c))) where lemma5 : (c : X × Y) → ap (to ∘ from-curr t) (glue c) == pair×= idp (glue c) lemma5 (x , y) = ap (to ∘ from-curr t) (glue (x , y)) =⟨ ap-∘ to (from-curr t) (glue (x , y)) ⟩ ap to (ap (from-curr t) (glue (x , y))) =⟨ FromCurr.glue-β t (x , y) |in-ctx ap to ⟩ ap to (glue ((t , x) , y)) =⟨ To.glue-β ((t , x) , y) ⟩ pair×= idp (glue (x , y)) ∎ from-to : (x : P2) → from (to x) == x from-to = Pushout-elim (λ _ → idp) (λ _ → idp) (λ c → ↓-∘=idf-in from to (! (lemma42 c))) where ap-pair×= : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A × B → C) {a : A} {b b' : B} (p : b == b') → ap f (pair×= idp p) == ap (λ b → f (a , b)) p ap-pair×= f {b = b} {b' = .b} idp = idp lemma42 : (c : (T × X) × Y) → ap from (ap to (glue c)) == glue c lemma42 ((t , x) , y) = ap from (ap to (glue ((t , x) , y))) =⟨ To.glue-β ((t , x) , y) |in-ctx ap from ⟩ ap from (pair×= idp (glue (x , y))) =⟨ ap-pair×= from (glue (x , y)) ⟩ ap (from-curr t) (glue (x , y)) =⟨ FromCurr.glue-β t (x , y) ⟩ glue ((t , x) , y) ∎ lemma2 : M.v-h-span join-assoc-span^2 == *-span A (B * C) lemma2 = span= (lemma3 A (A × C) fst) (ide _) (lemma4' B C A) (Pushout-elim (λ _ → idp) (λ _ → idp) (λ x → ↓-='-in (lemma2-1 x ∙ ! (lemma2-2 x)))) (Pushout-elim (λ _ → idp) (λ _ → idp) (λ x → ↓-='-in (lemma2-3 x ∙ ! (M.F₃∙.glue-β join-assoc-span^2 _ ∙ ∙-unit-r (glue _))))) where lemma2-1 : (x : (A × B) × C) → _ lemma2-1 ((a , b) , c) = ap (fst ∘ Lemma4'.to B C A) (glue ((a , b) , c)) =⟨ ap-∘ fst (Lemma4'.to B C A) (glue ((a , b) , c)) ⟩ ap fst (ap (Lemma4'.to B C A) (glue ((a , b) , c))) =⟨ Lemma4'.To.glue-β B C A ((a , b) , c) |in-ctx fst×= ⟩ fst×= (pair×= idp (glue (b , c))) =⟨ fst×=-β idp (glue (b , c)) ⟩ idp ∎ lemma2-2 : (x : (A × B) × C) → _ lemma2-2 ((a , b) , c) = ap (lemma3-fun A (A × C) fst ∘ M.f₁∙ join-assoc-span^2) (glue ((a , b) , c)) =⟨ ap-∘ (lemma3-fun A (A × C) fst) (M.f₁∙ join-assoc-span^2) (glue ((a , b) , c)) ⟩ ap (lemma3-fun A (A × C) fst) (ap (M.f₁∙ join-assoc-span^2) (glue ((a , b) , c))) =⟨ M.F₁∙.glue-β join-assoc-span^2 ((a , b) , c) |in-ctx ap (lemma3-fun A (A × C) fst) ⟩ ap (lemma3-fun A (A × C) fst) (glue (a , c) ∙ idp) =⟨ ∙-unit-r (glue (a , c)) |in-ctx ap (lemma3-fun A (A × C) fst) ⟩ ap (lemma3-fun A (A × C) fst) (glue (a , c)) =⟨ Lemma3Fun.glue-β A (A × C) fst (a , c) ⟩ idp ∎ lemma2-3 : (x : (A × B) × C) → _ lemma2-3 ((a , b) , c) = ap (snd ∘ Lemma4'.to B C A) (glue ((a , b) , c)) =⟨ ap-∘ snd (Lemma4'.to B C A) (glue ((a , b) , c)) ⟩ ap snd (ap (Lemma4'.to B C A) (glue ((a , b) , c))) =⟨ Lemma4'.To.glue-β B C A ((a , b) , c) |in-ctx snd×= ⟩ snd×= (pair×= idp (glue (b , c))) =⟨ snd×=-β idp (glue (b , c)) ⟩ glue (b , c) ∎ lemma2' : M.v-h-span (transpose join-assoc-span^2) == *-span (A * B) C lemma2' = span= (ide _) (lemma3' C (A × C) snd) (lemma4 A B (A × B) C fst snd) (Pushout-elim (λ _ → idp) (λ _ → idp) (λ c → ↓-='-in (ap-∘ fst (Lemma4.to A B (A × B) C fst snd) (glue c) ∙ ap (ap fst) (Lemma4.To.glue-β A B (A × B) C fst snd c) ∙ fst×=-β (glue (fst c)) idp ∙ ! (∙-unit-r (glue (fst c))) ∙ ! (M.F₁∙.glue-β (transpose join-assoc-span^2) c)))) (Pushout-elim (λ _ → idp) (λ _ → idp) (λ u → ↓-='-in (lemma2'-1 u ∙ ! (lemma2'-2 u)))) where lemma2'-1 : (u : (A × B) × C) → ap (snd ∘ Lemma4.to A B (A × B) C fst snd) (glue u) == idp lemma2'-1 u = ap (snd ∘ Lemma4.to A B (A × B) C fst snd) (glue u) =⟨ ap-∘ snd (Lemma4.to A B (A × B) C fst snd) (glue u) ⟩ ap snd (ap (Lemma4.to A B (A × B) C fst snd) (glue u)) =⟨ Lemma4.To.glue-β A B (A × B) C fst snd u |in-ctx snd×= ⟩ snd×= (pair×= (glue (fst u)) idp) =⟨ snd×=-β (glue (fst u)) idp ⟩ idp ∎ lemma2'-2 : (u : (A × B) × C) → ap (lemma3'-fun C (A × C) snd ∘ M.f₃∙ (transpose join-assoc-span^2)) (glue u) == idp lemma2'-2 u = ap (lemma3'-fun C (A × C) snd ∘ M.f₃∙ (transpose join-assoc-span^2)) (glue u) =⟨ ap-∘ (lemma3'-fun C (A × C) snd) (M.f₃∙ (transpose join-assoc-span^2)) (glue u) ⟩ ap (lemma3'-fun C (A × C) snd) (ap (M.f₃∙ (transpose join-assoc-span^2)) (glue u)) =⟨ M.F₃∙.glue-β (transpose join-assoc-span^2) u |in-ctx ap (lemma3'-fun C (A × C) snd) ⟩ ap (lemma3'-fun C (A × C) snd) (glue (fst (fst u) , snd u) ∙ idp) =⟨ ∙-unit-r (glue (fst (fst u) , snd u)) |in-ctx ap (lemma3'-fun C (A × C) snd) ⟩ ap (lemma3'-fun C (A × C) snd) (glue (fst (fst u) , snd u)) =⟨ Lemma3'Fun.glue-β C (A × C) snd (fst (fst u) , snd u) ⟩ idp ∎ lemma1 : Pushout^2 join-assoc-span^2 == A * (B * C) lemma1 = ap Pushout lemma2 lemma1' : Pushout^2 (transpose join-assoc-span^2) == (A * B) * C lemma1' = ap Pushout lemma2' *-assoc : A * (B * C) == (A * B) * C *-assoc = ! lemma1 ∙ ua PP.theorem ∙ lemma1'
43.255708
285
0.484746
1897007afa4a5a47d39c68060cca5fc1a12249e6
886
agda
Agda
agda-stdlib/src/Reflection/Argument/Relevance.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Reflection/Argument/Relevance.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Reflection/Argument/Relevance.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Argument relevance used in the reflection machinery ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Reflection.Argument.Relevance where open import Relation.Nullary open import Relation.Binary open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Re-exporting the builtins publically open import Agda.Builtin.Reflection public using (Relevance) open Relevance public ------------------------------------------------------------------------ -- Decidable equality _≟_ : DecidableEquality Relevance relevant ≟ relevant = yes refl irrelevant ≟ irrelevant = yes refl relevant ≟ irrelevant = no λ() irrelevant ≟ relevant = no λ()
30.551724
72
0.515801
58169acfe7220b25ef99199004a73647bc10d75b
4,521
agda
Agda
Source/ALL/Languages/ILL/Syntax.agda
heades/Agda-LLS
c83f5d8201362b26a749138f6dbff2dd509f85b1
[ "BSD-3-Clause" ]
3
2017-04-09T20:53:53.000Z
2019-08-02T23:41:23.000Z
Source/ALL/Languages/ILL/Syntax.agda
heades/Agda-LLS
c83f5d8201362b26a749138f6dbff2dd509f85b1
[ "BSD-3-Clause" ]
2
2017-03-27T14:52:46.000Z
2017-04-05T17:30:16.000Z
Source/ALL/Languages/ILL/Syntax.agda
heades/Agda-LLS
c83f5d8201362b26a749138f6dbff2dd509f85b1
[ "BSD-3-Clause" ]
null
null
null
module Languages.ILL.Syntax where open import level open import bool open import nat open import unit open import empty open import eq open import sum open import product open import Utils.HaskellTypes open import Utils.HaskellFunctions open import Languages.ILL.TypeSyntax True : Set True = ⊤{lzero} False : Set False = ⊥{lzero} Name : Set Name = ℕ name-in : ∀{A : Set} → (A → A → 𝔹) → A → List A → Set name-in eq x ctx with list-member eq x ctx name-in _ x ctx | tt = True name-in _ x ctx | ff = False -- Bound Variable Labels: data VLabel : Set where LLPV : VLabel -- Let-Bound Left Pattern Variable RLPV : VLabel -- Let-Bound Right Pattern Variable LCPV : VLabel -- Copy-Bound Left Pattern Variable RCPV : VLabel -- Copy-Bound Right Pattern Variable BV : VLabel -- λ-Bound Variable PBV : VLabel -- Promote-Bound Variable that is ith in the sequence _vl-eq_ : VLabel → VLabel → 𝔹 LLPV vl-eq LLPV = tt RLPV vl-eq RLPV = tt LCPV vl-eq LCPV = tt RCPV vl-eq RCPV = tt BV vl-eq BV = tt PBV vl-eq PBV = tt _ vl-eq _ = ff data Pattern : Set where PTriv : Pattern PTensor : String → String → Pattern data Term : Set where Triv : Term FVar : String → Term BVar : Name → String → VLabel → Term Let : Term → Type → Pattern → Term → Term Lam : String → Type → Term → Term App : Term → Term → Term Tensor : Term → Term → Term Promote : List (Triple Term String Type) → Term → Term Discard : Term → Term → Term Copy : Term → (Prod String String) → Term → Term Derelict : Term → Term {-# TERMINATING #-} open-t : Name → String → VLabel → Term → Term → Term open-t x xs l u (BVar y ys l') with x =ℕ y | xs str-eq ys | l vl-eq l' ... | tt | tt | tt = u ... | _ | _ | _ = BVar y ys l' open-t x xs BV u (Let t₁ y z t₂) = Let (open-t x xs BV u t₁) y z (open-t x xs BV u t₂) open-t x xs l@LCPV u (Let t₁ y z t₂) = Let (open-t x xs l u t₁) y z (open-t x xs l u t₂) open-t x xs l@RCPV u (Let t₁ y z t₂) = Let (open-t x xs l u t₁) y z (open-t x xs l u t₂) open-t x xs l u (Let t₁ a p t₂) = Let (open-t x xs l u t₁) a p (open-t (suc x) xs l u t₂) open-t x xs BV u (Lam ys a t) = Lam ys a (open-t (suc x) xs BV u t) open-t x xs l u (Lam ys a t) = Lam ys a (open-t x xs l u t) open-t x xs l u (App t₁ t₂) = App (open-t x xs l u t₁) (open-t x xs l u t₂) open-t x xs l u (Tensor t₁ t₂) = Tensor (open-t x xs l u t₁) (open-t x xs l u t₂) open-t x xs l@PBV y (Promote ms n) = Promote oms (open-t (suc x) xs l y n) where oms = map (fstMapT (open-t x xs l y)) ms open-t x xs l y (Promote ms n) = Promote oms (open-t x xs l y n) where oms = map (fstMapT (open-t x xs l y)) ms open-t x xs l@LCPV y (Copy m p n) = Copy (open-t x xs l y m ) p (open-t (suc x) xs l y n) open-t x xs l@RCPV y (Copy m p n) = Copy (open-t x xs l y m ) p (open-t (suc x) xs l y n) open-t x xs l y (Copy m p n) = Copy (open-t x xs l y m ) p (open-t x xs l y n) open-t x xs l y (Discard m n) = Discard (open-t x xs l y m) (open-t x xs l y n) open-t x xs l y (Derelict m) = Derelict (open-t x xs l y m) open-t _ _ _ _ t = t {-# TERMINATING #-} close-t : Name → String → VLabel → String → Term → Term close-t x xs l y (FVar z) with y str-eq z ... | tt = BVar x xs l ... | ff = FVar z close-t x xs l@LLPV y (Let t₁ ty p t₂) = Let (close-t x xs l y t₁) ty p (close-t (suc x) xs l y t₂) close-t x xs l@RLPV y (Let t₁ ty p t₂) = Let (close-t x xs l y t₁) ty p (close-t (suc x) xs l y t₂) close-t x xs l y (Let t₁ ty p t₂) = Let (close-t x xs l y t₁) ty p (close-t x xs l y t₂) close-t x xs l@BV y (Lam ys a t) = Lam ys a (close-t (suc x) xs l y t) close-t x xs l y (Lam ys a t) = Lam ys a (close-t x xs l y t) close-t x xs l y (App t₁ t₂) = App (close-t x xs l y t₁) (close-t x xs l y t₂) close-t x xs l y (Tensor t₁ t₂) = Tensor (close-t x xs l y t₁) (close-t x xs l y t₂) close-t x xs l@PBV y (Promote ms n) = Promote cms (close-t (suc x) xs l y n) where cms = map (fstMapT (close-t x xs l y)) ms close-t x xs l y (Promote ms n) = Promote cms (close-t x xs l y n) where cms = map (fstMapT (close-t x xs l y)) ms close-t x xs l@LCPV y (Copy m p n) = Copy (close-t x xs l y m) p (close-t (suc x) xs l y n) close-t x xs l@RCPV y (Copy m p n) = Copy (close-t x xs l y m) p (close-t (suc x) xs l y n) close-t x xs l y (Copy m p n) = Copy (close-t x xs l y m) p (close-t x xs l y n) close-t x xs l y (Discard m n) = Discard (close-t x xs l y m) (close-t x xs l y n) close-t x xs l y (Derelict m) = Derelict (close-t x xs l y m) close-t _ _ _ _ t = t
39.313043
99
0.610042
50e6e5f5569efd8e21b7d164566bdfbd39c7eb29
904
agda
Agda
test/MonoidTactic.agda
jespercockx/agda-prelude
1984cf0341835b2f7bfe678098bd57cfe16ea11f
[ "MIT" ]
null
null
null
test/MonoidTactic.agda
jespercockx/agda-prelude
1984cf0341835b2f7bfe678098bd57cfe16ea11f
[ "MIT" ]
null
null
null
test/MonoidTactic.agda
jespercockx/agda-prelude
1984cf0341835b2f7bfe678098bd57cfe16ea11f
[ "MIT" ]
null
null
null
module MonoidTactic where open import Prelude open import Container.Traversable open import Structure.Monoid.Laws open import Tactic.Monoid open import Tactic.Reflection MonoidAnd : Monoid Bool mempty {{MonoidAnd}} = true _<>_ {{MonoidAnd}} = _&&_ MonoidLawsAnd : MonoidLaws Bool {{MonoidAnd}} idLeft {{MonoidLawsAnd}} x = refl idRight {{MonoidLawsAnd}} false = refl idRight {{MonoidLawsAnd}} true = refl <>assoc {{MonoidLawsAnd}} true y z = refl <>assoc {{MonoidLawsAnd}} false y z = refl test₁ : (a b : Bool) → (a && (b && a && true)) ≡ ((a && b) && a) test₁ a b = auto-monoid {{Laws = MonoidLawsAnd}} test₂ : ∀ {a} {A : Set a} {{Mon : Monoid A}} {{Laws : MonoidLaws A}} → (x y : A) → x <> (y <> x <> mempty) ≡ (x <> y) <> x test₂ x y = auto-monoid test₃ : ∀ {a} {A : Set a} (xs ys zs : List A) → xs ++ ys ++ zs ≡ (xs ++ []) ++ (ys ++ []) ++ zs test₃ xs ys zs = runT monoidTactic
30.133333
95
0.615044
294a05aab1137ac29f1af9a7813611fba4d9b048
3,180
agda
Agda
src/Categories/Morphism/IsoEquiv.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Morphism/IsoEquiv.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Morphism/IsoEquiv.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Morphism.IsoEquiv {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Function using (flip; _on_) open import Relation.Binary hiding (_⇒_) import Relation.Binary.Construct.On as On open import Categories.Morphism 𝒞 open Category 𝒞 private variable A B C : Obj -- Two lemmas to set things up: if they exist, inverses are unique. to-unique : ∀ {f₁ f₂ : A ⇒ B} {g₁ g₂} → Iso f₁ g₁ → Iso f₂ g₂ → f₁ ≈ f₂ → g₁ ≈ g₂ to-unique {_} {_} {f₁} {f₂} {g₁} {g₂} iso₁ iso₂ hyp = begin g₁ ≈˘⟨ identityˡ ⟩ id ∘ g₁ ≈˘⟨ ∘-resp-≈ˡ Iso₂.isoˡ ⟩ (g₂ ∘ f₂) ∘ g₁ ≈˘⟨ ∘-resp-≈ˡ (∘-resp-≈ʳ hyp) ⟩ (g₂ ∘ f₁) ∘ g₁ ≈⟨ assoc ⟩ g₂ ∘ (f₁ ∘ g₁) ≈⟨ ∘-resp-≈ʳ Iso₁.isoʳ ⟩ g₂ ∘ id ≈⟨ identityʳ ⟩ g₂ ∎ where open HomReasoning module Iso₁ = Iso iso₁ module Iso₂ = Iso iso₂ from-unique : ∀ {f₁ f₂ : A ⇒ B} {g₁ g₂} → Iso f₁ g₁ → Iso f₂ g₂ → g₁ ≈ g₂ → f₁ ≈ f₂ from-unique iso₁ iso₂ hyp = to-unique iso₁⁻¹ iso₂⁻¹ hyp where iso₁⁻¹ = record { isoˡ = Iso.isoʳ iso₁ ; isoʳ = Iso.isoˡ iso₁ } iso₂⁻¹ = record { isoˡ = Iso.isoʳ iso₂ ; isoʳ = Iso.isoˡ iso₂ } -- Equality of isomorphisms is just equality of the underlying morphism(s). -- -- Only one equation needs to be given; the equation in the other -- direction holds automatically (by the above lemmas). -- -- The reason for wrapping the underlying equality in a record at all -- is that this helps unification. Concretely, it allows Agda to -- infer the isos |i| and |j| being related in function applications -- where only the equation |i ≃ j| is passed as an explicit argument. infix 4 _≃_ record _≃_ (i j : A ≅ B) : Set e where constructor ⌞_⌟ open _≅_ field from-≈ : from i ≈ from j to-≈ : to i ≈ to j to-≈ = to-unique (iso i) (iso j) from-≈ open _≃_ module _ {A B : Obj} where open Equiv ≃-refl : Reflexive (_≃_ {A} {B}) ≃-refl = ⌞ refl ⌟ ≃-sym : Symmetric (_≃_ {A} {B}) ≃-sym = λ where ⌞ eq ⌟ → ⌞ sym eq ⌟ ≃-trans : Transitive (_≃_ {A} {B}) ≃-trans = λ where ⌞ eq₁ ⌟ ⌞ eq₂ ⌟ → ⌞ trans eq₁ eq₂ ⌟ ≃-isEquivalence : IsEquivalence (_≃_ {A} {B}) ≃-isEquivalence = record { refl = ≃-refl ; sym = ≃-sym ; trans = ≃-trans } ≃-setoid : ∀ {A B : Obj} → Setoid _ _ ≃-setoid {A} {B} = record { Carrier = A ≅ B ; _≈_ = _≃_ ; isEquivalence = ≃-isEquivalence } ---------------------------------------------------------------------- -- An alternative, more direct notion of equality on isomorphisms that -- involves no wrapping/unwrapping. infix 4 _≃′_ _≃′_ : Rel (A ≅ B) e _≃′_ = _≈_ on _≅_.from ≃′-isEquivalence : IsEquivalence (_≃′_ {A} {B}) ≃′-isEquivalence = On.isEquivalence _≅_.from equiv ≃′-setoid : ∀ {A B : Obj} → Setoid _ _ ≃′-setoid {A} {B} = record { Carrier = A ≅ B ; _≈_ = _≃′_ ; isEquivalence = ≃′-isEquivalence } -- The two notions of equality are equivalent ≃⇒≃′ : ∀ {i j : A ≅ B} → i ≃ j → i ≃′ j ≃⇒≃′ eq = from-≈ eq ≃′⇒≃ : ∀ {i j : A ≅ B} → i ≃′ j → i ≃ j ≃′⇒≃ {_} {_} {i} {j} eq = ⌞ eq ⌟
27.179487
75
0.558176
a1a8c460ef29eadf078922d41f233243223a0a3e
3,044
agda
Agda
Cubical/Experiments/FunExtFromUA.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Experiments/FunExtFromUA.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Experiments/FunExtFromUA.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{- Voevodsky's proof that univalence implies funext -} {-# OPTIONS --cubical --safe #-} module Cubical.Experiments.FunExtFromUA where open import Cubical.Foundations.Everything variable ℓ ℓ' : Level _∼_ : {X : Type ℓ} {A : X → Type ℓ'} → (f g : (x : X) → A x) → Type (ℓ-max ℓ ℓ') f ∼ g = ∀ x → f x ≡ g x funext : ∀ ℓ ℓ' → Type (ℓ-suc(ℓ-max ℓ ℓ')) funext ℓ ℓ' = {X : Type ℓ} {Y : Type ℓ'} {f g : X → Y} → f ∼ g → f ≡ g elimEquivFun' : ∀ {ℓ} (P : (A B : Type ℓ) → (A → B) → Type ℓ) → (r : (B : Type ℓ) → P B B (λ x → x)) → (A B : Type ℓ) → (e : A ≃ B) → P A B (e .fst) elimEquivFun' P r A B = elimEquivFun B (λ A → P A B) (r B) A pre-comp-is-equiv : (X Y : Type ℓ) (f : X → Y) (Z : Type ℓ) → isEquiv f → isEquiv (λ (g : Y → Z) → g ∘ f) pre-comp-is-equiv {ℓ} X Y f Z e = elimEquivFun' P r X Y (f , e) where P : (X Y : Type ℓ) → (X → Y) → Type ℓ P X Y f = isEquiv (λ (g : Y → Z) → g ∘ f) r : (B : Type ℓ) → P B B (λ x → x) r B = idIsEquiv (B → Z) leftCancellable : {X : Type ℓ} {Y : Type ℓ'} → (X → Y) → Type (ℓ-max ℓ ℓ') leftCancellable f = ∀ {x x'} → f x ≡ f x' → x ≡ x' equivLC : {X : Type ℓ} {Y : Type ℓ'} (f : X → Y) → isEquiv f → leftCancellable f equivLC f e {x} {x'} p i = hcomp (λ j → \ {(i = i0) → secEq (f , e) x j ; (i = i1) → secEq (f , e) x' j}) (invEq (f , e) (p i)) univalence-gives-funext : funext ℓ' ℓ univalence-gives-funext {ℓ'} {ℓ} {X} {Y} {f₀} {f₁} = γ where Δ = Σ[ y₀ ∈ Y ] Σ[ y₁ ∈ Y ] y₀ ≡ y₁ δ : Y → Δ δ y = (y , y , refl) π₀ π₁ : Δ → Y π₀ (y₀ , y₁ , p) = y₀ π₁ (y₀ , y₁ , p) = y₁ δ-is-equiv : isEquiv δ δ-is-equiv = isoToIsEquiv (iso δ π₀ ε η) where η : (y : Y) → π₀ (δ y) ≡ y η y = refl ε : (d : Δ) → δ (π₀ d) ≡ d ε (y₀ , y₁ , p) i = y₀ , p i , λ j → p (i ∧ j) φ : (Δ → Y) → (Y → Y) φ π = π ∘ δ e : isEquiv φ e = pre-comp-is-equiv Y Δ δ Y δ-is-equiv p : φ π₀ ≡ φ π₁ p = refl q : π₀ ≡ π₁ q = equivLC φ e p g : (h : f₀ ∼ f₁) (π : Δ → Y) (x : X) → Y g = λ h π x → π (f₀ x , f₁ x , h x) γ : f₀ ∼ f₁ → f₀ ≡ f₁ γ h = cong (g h) q γ' : f₀ ∼ f₁ → f₀ ≡ f₁ γ' h = f₀ ≡⟨ refl ⟩ (λ x → f₀ x) ≡⟨ refl ⟩ (λ x → π₀ (f₀ x , f₁ x , h x)) ≡⟨ cong (g h) q ⟩ (λ x → π₁ (f₀ x , f₁ x , h x)) ≡⟨ refl ⟩ (λ x → f₁ x) ≡⟨ refl ⟩ f₁ ∎ {- Experiment testing univalence via funext -} private data ℕ : Type₀ where zero : ℕ succ : ℕ → ℕ f g : ℕ → ℕ f n = n g zero = zero g (succ n) = succ (g n) h : (n : ℕ) → f n ≡ g n h zero = refl h (succ n) = cong succ (h n) p : f ≡ g p = univalence-gives-funext h five : ℕ five = succ (succ (succ (succ (succ zero)))) a : Σ ℕ (λ n → f n ≡ five) a = five , refl b : Σ ℕ (λ n → g n ≡ five) b = subst (λ - → Σ ℕ (λ n → - n ≡ five)) p a c : fst b ≡ five c = refl {- It works, fast. -}
24.95082
80
0.427398
4db1b677cbd367d54438f223a5c32d8e9dd875b2
533
agda
Agda
Light/Library/Data/Either.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
1
2019-12-20T21:33:05.000Z
2019-12-20T21:33:05.000Z
Light/Library/Data/Either.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
null
null
null
Light/Library/Data/Either.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
null
null
null
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Library.Data.Either where open import Light.Level using (Level ; Setω ; _⊔_) open import Light.Variable.Sets open import Light.Variable.Levels record Dependencies : Setω where record Library (dependencies : Dependencies) : Setω where field ℓf : Level → Level → Level Either : Set aℓ → Set bℓ → Set (ℓf aℓ bℓ) left : 𝕒 → Either 𝕒 𝕓 right : 𝕓 → Either 𝕒 𝕓 open Library ⦃ ... ⦄ public
29.611111
79
0.649156
57df3545a769712919a7d92f9ea0a28a84cef572
881
agda
Agda
notes/FOT/Agsy/AddTotality.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/Agsy/AddTotality.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/Agsy/AddTotality.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
{-# OPTIONS --allow-unsolved-metas #-} {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.Agsy.AddTotality where open import Relation.Binary.PropositionalEquality infixl 9 _+_ ------------------------------------------------------------------------------ postulate D : Set zero : D succ : D → D data N : D → Set where zN : N zero sN : ∀ {n} → N n → N (succ n) postulate _+_ : D → D → D +-0x : ∀ d → zero + d ≡ d +-Sx : ∀ d e → succ d + e ≡ succ (d + e) +-N : ∀ {m n} → N m → N n → N (m + n) +-N {m} {n} Nm Nn = {!-c -m -t 20!} -- No solution found at time out (20s). +-N₁ : ∀ {m n} → N m → N n → N (m + n) +-N₁ zN Nn = {!-m!} -- No solution found +-N₁ (sN Nm) Nn = {!-m!} -- No solution found.
24.472222
78
0.441544
58be036d3f676fb235e6ba70882e9df8ed78c430
6,583
agda
Agda
benchmark/monad/Monad.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2021-07-07T10:49:57.000Z
2021-07-07T10:49:57.000Z
benchmark/monad/Monad.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
benchmark/monad/Monad.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
------------------------------------------------------------------------ -- Parser monad ------------------------------------------------------------------------ open import Relation.Binary open import Relation.Binary.OrderMorphism open import Relation.Binary.PropositionalEquality import Relation.Binary.Properties.StrictTotalOrder as STOProps open import Data.Product open import Level module Monad -- Input string positions. {Position : Set} {_<P_ : Rel Position zero} (posOrdered : IsStrictTotalOrder _≡_ _<P_) -- Input strings. (Input : Position -> Set) -- In order to be able to store results in a memo table (and avoid -- having to lift the table code to Set1) the result types have to -- come from the following universe: {Result : Set} (⟦_⟧ : Result -> Set) -- Memoisation keys. These keys must uniquely identify the -- computation that they are associated with, when paired up with -- the current input string position. {Key : let PosPoset = STOProps.poset (record { Carrier = _ ; _≈_ = _; _<_ = _ ; isStrictTotalOrder = posOrdered }) MonoFun = PosPoset ⇒-Poset PosPoset in MonoFun -> Result -> Set} {_≋_ _<_ : Rel (∃₂ Key) zero} (keyOrdered : IsStrictTotalOrder _≋_ _<_) -- Furthermore the underlying equality needs to be strong enough. (funsEqual : _≋_ =[ proj₁ ]⇒ _≡_) (resultsEqual : _≋_ =[ (\rfk -> proj₁ (proj₂ rfk)) ]⇒ _≡_) where open _⇒-Poset_ open STOProps (record { Carrier = _ ; _≈_ = _; _<_ = _ ; isStrictTotalOrder = posOrdered }) import IndexedMap as Map -- renaming (Map to MemoTable) open import Category.Monad open import Category.Monad.State import Data.List as List; open List using (List) open import Data.Unit hiding (poset; _≤_) open import Function open import Data.Maybe hiding (Eq) open import Data.Product.Relation.Lex.Strict open import Data.Product.Relation.Pointwise.NonDependent import Relation.Binary.On as On ------------------------------------------------------------------------ -- Monotone functions MonoFun : Set MonoFun = poset ⇒-Poset poset ------------------------------------------------------------------------ -- Memo tables -- Indices and keys used by the memo table. Index : Set Index = Position × MonoFun × Result data MemoTableKey : Index -> Set where key : forall {f r} (key : Key f r) pos -> MemoTableKey (pos , f , r) -- Input strings of a certain maximum length. Input≤ : Position -> Set Input≤ pos = ∃ \pos′ -> pos′ ≤ pos × Input pos′ -- Memo table values. Value : Index -> Set Value (pos , f , r) = List (⟦ r ⟧ × Input≤ (fun f pos)) -- Shuffles the elements to simplify defining equality and order -- relations for the keys. shuffle : ∃ MemoTableKey -> Position × ∃₂ Key shuffle ((pos , f , r) , key k .pos) = (pos , f , r , k) -- Equality and order. Eq : Rel (∃ MemoTableKey) _ Eq = Pointwise _≡_ _≋_ on shuffle Lt : Rel (∃ MemoTableKey) _ Lt = ×-Lex _≡_ _<P_ _<_ on shuffle isOrdered : IsStrictTotalOrder Eq Lt isOrdered = On.isStrictTotalOrder shuffle (×-isStrictTotalOrder posOrdered keyOrdered) indicesEqual′ : Eq =[ proj₁ ]⇒ _≡_ indicesEqual′ {((_ , _ , _) , key _ ._)} {((_ , _ , _) , key _ ._)} (eq₁ , eq₂) = cong₂ _,_ eq₁ (cong₂ _,_ (funsEqual eq₂) (resultsEqual eq₂)) open Map isOrdered (\{k₁} {k₂} -> indicesEqual′ {k₁} {k₂}) Value {- ------------------------------------------------------------------------ -- Parser monad -- The parser monad is built upon a list monad, for backtracking, and -- two state monads. One of the state monads stores a memo table, and -- is unaffected by backtracking. The other state monad, which /is/ -- affected by backtracking, stores the remaining input string. -- The memo table state monad. module MemoState = RawMonadState (StateMonadState MemoTable) -- The list monad. module List = RawMonadPlus List.ListMonadPlus -- The inner monad (memo table plus list). module IM where Inner : Set -> Set Inner R = State MemoTable (List R) InnerMonadPlus : RawMonadPlus Inner InnerMonadPlus = record { monadZero = record { monad = record { return = \x -> return (List.return x) ; _>>=_ = \m f -> List.concat <$> (List.mapM monad f =<< m) } ; ∅ = return List.∅ } ; _∣_ = \m₁ m₂ -> List._∣_ <$> m₁ ⊛ m₂ } where open MemoState InnerMonadState : RawMonadState MemoTable Inner InnerMonadState = record { monad = RawMonadPlus.monad InnerMonadPlus ; get = List.return <$> get ; put = \s -> List.return <$> put s } where open MemoState open RawMonadPlus InnerMonadPlus public open RawMonadState InnerMonadState public using (get; put; modify) -- The complete parser monad. module PM where P : MonoFun -> Set -> Set P f A = forall {n} -> Input n -> IM.Inner (A × Input≤ (fun f n)) -- Memoises the computation, assuming that the key is sufficiently -- unique. memoise : forall {f r} -> Key f r -> P f ⟦ r ⟧ -> P f ⟦ r ⟧ memoise k p {pos} xs = let open IM in helper =<< lookup k′ <$> get where i = (pos , _) k′ : MemoTableKey i k′ = key k pos helper : Maybe (Value i) -> State MemoTable (Value i) helper (just ris) = return ris where open MemoState helper nothing = p xs >>= \ris -> modify (insert k′ ris) >> return ris where open MemoState -- Other monadic operations. return : forall {A} -> A -> P idM A return a = \xs -> IM.return (a , _ , refl , xs) _>>=_ : forall {A B f g} -> P f A -> (A -> P g B) -> P (g ∘M f) B _>>=_ {g = g} m₁ m₂ xs = m₁ xs ⟨ IM._>>=_ ⟩ \ays -> let a = proj₁ ays le = proj₁ $ proj₂ $ proj₂ ays ys = proj₂ $ proj₂ $ proj₂ ays in fix le ⟨ IM._<$>_ ⟩ m₂ a ys where lemma : forall {i j k} -> j ≤ k -> i ≤ fun g j -> i ≤ fun g k lemma j≤k i≤gj = trans i≤gj (monotone g j≤k) fix : forall {A i j} -> i ≤ j -> A × Input≤ (fun g i) -> A × Input≤ (fun g j) fix le = map-× id (map-Σ id (map-× (lemma le) id)) ∅ : forall {A} -> P idM A ∅ = const IM.∅ _∣_ : forall {A f} -> P f A -> P f A -> P f A m₁ ∣ m₂ = \xs -> IM._∣_ (m₁ xs) (m₂ xs) put : forall {n} -> Input n -> P (constM n) ⊤ put xs = \_ -> IM.return (_ , _ , refl , xs) modify : forall {A f} -> (forall {n} -> Input n -> A × Input (fun f n)) -> P f A modify g xs = IM.return (proj₁ gxs , _ , refl , proj₂ gxs) where gxs = g xs -}
29
72
0.57451
4a8670bccf7ecf66729d60b081a4f3ae3bd01630
445
agda
Agda
Cubical/Algebra/CommRingSolver/IntAsRawRing.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/CommRingSolver/IntAsRawRing.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRingSolver/IntAsRawRing.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRingSolver.IntAsRawRing where open import Cubical.Data.Nat hiding (_+_; _·_) open import Cubical.Data.Int open import Cubical.Data.Int.Base open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRingSolver.RawRing ℤAsRawRing : RawRing ℓ-zero ℤAsRawRing = rawring ℤ (pos zero) (pos (suc zero)) _+_ _·_ (λ k → - k) +Ridℤ : (k : ℤ) → (pos zero) + k ≡ k +Ridℤ k = sym (pos0+ k)
27.8125
70
0.719101
2263738d62f6598ee28eb16851293a3e88944048
1,413
agda
Agda
Numbers/Naturals/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Numbers/Naturals/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Numbers/Naturals/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --warning=error --safe --without-K #-} open import Boolean.Definition open import LogicalFormulae open import Decidable.Lemmas module Numbers.Naturals.Definition where data ℕ : Set where zero : ℕ succ : ℕ → ℕ infix 100 succ {-# BUILTIN NATURAL ℕ #-} succInjective : {a b : ℕ} → (succ a ≡ succ b) → a ≡ b succInjective {a} {.a} refl = refl naughtE : {a : ℕ} → zero ≡ succ a → False naughtE () aIsNotSuccA : (a : ℕ) → (a ≡ succ a) → False aIsNotSuccA zero pr = naughtE pr aIsNotSuccA (succ a) pr = aIsNotSuccA a (succInjective pr) ℕDecideEquality : (a b : ℕ) → ((a ≡ b) || ((a ≡ b) → False)) ℕDecideEquality zero zero = inl refl ℕDecideEquality zero (succ b) = inr (λ ()) ℕDecideEquality (succ a) zero = inr (λ ()) ℕDecideEquality (succ a) (succ b) with ℕDecideEquality a b ℕDecideEquality (succ a) (succ b) | inl x = inl (applyEquality succ x) ℕDecideEquality (succ a) (succ b) | inr x = inr λ pr → x (succInjective pr) ℕDecideEquality' : (a b : ℕ) → Bool ℕDecideEquality' a b with ℕDecideEquality a b ℕDecideEquality' a b | inl x = BoolTrue ℕDecideEquality' a b | inr x = BoolFalse record _=N'_ (a b : ℕ) : Set where field .eq : a ≡ b squashN : {a b : ℕ} → a =N' b → a ≡ b squashN record { eq = eq } = squash ℕDecideEquality eq collapseN : {a b : ℕ} → a ≡ b → a =N' b collapseN refl = record { eq = refl } =N'Refl : {a b : ℕ} → (p1 p2 : a =N' b) → p1 ≡ p2 =N'Refl p1 p2 = refl
27.173077
75
0.642604
103e0eb49ecfce74bcf33771b142bdb923df86ea
5,350
agda
Agda
OTTTests/TestsInstances.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
OTTTests/TestsInstances.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
OTTTests/TestsInstances.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
{-# OPTIONS --copatterns #-} module TestsInstances where open import Function open import Data.Product open import Relation.Nullary using (Dec; yes; no; ¬_) open import Relation.Binary.PropositionalEquality as P open ≡-Reasoning open import Data.Empty renaming (⊥ to Empty) open import Data.Unit renaming (⊤ to One) hiding (_≟_) open import Data.Bool hiding (_≟_) open import Data.Bool.Properties using (¬-not; T-not-≡) open import Data.Nat hiding (_⊔_) open import Isomorphisms open import Tests -- | Functions are testable if their codomain is FunTestable : {A B : Set} → Testable B → Testable (A → B) FunTestable {A} {B} TB = record { index = A ; parts = λ _ → B ; kind = coind ; obs = λ f → record { app = f } ; partsTestable = λ _ → TB } FunIsoTestable : {A B : Set} → IsoTestable B → IsoTestable (A → B) FunIsoTestable T = record { testable = FunTestable (testable T) ; obsIso = (record { inv = app ; isLeftInv = λ a → refl ; isRightInv = λ b → refl }) } -- | We get extensionality for functions under observational equivalence. ext : {A B : Set} → (T : Testable B) → (f : A → B) → (g : A → B) → ((a : A) → f a ≃⟨ T ⟩ g a) → f ≃⟨ FunTestable T ⟩ g ext {A} {B} TB f g p = record { eqProof = q } where q : (φ : Test (FunTestable TB)) → f ⊨ φ ≡ g ⊨ φ q ⊤ = refl q ⊥ = refl q (nonTriv (i , ψ)) = eqProof (p i) ψ -- | Make unit type testable ⊤-testable : Testable One index ⊤-testable = One parts ⊤-testable = λ _ → One kind ⊤-testable = coind obs ⊤-testable = λ { tt → record { app = λ x → x } } partsTestable ⊤-testable = λ i → ⊤-testable ⊤-IsoTestable : IsoTestable One ⊤-IsoTestable = record { testable = ⊤-testable ; obsIso = record { inv = λ f → app f tt ; isLeftInv = λ a → refl ; isRightInv = λ b → refl } } -- | Obs. equiv. is a congruence on ⊤. ≃-cong-⊤ : {A : Set} → {T : Testable A} → {x y : One} → (f : One → A) → x ≃⟨ ⊤-testable ⟩ y → f x ≃⟨ T ⟩ f y ≃-cong-⊤ f p = record { eqProof = λ φ → refl } Parts-ℕ : Bool → Set Parts-ℕ true = One Parts-ℕ false = ℕ rep-ℕ : ℕ → Σ Bool Parts-ℕ rep-ℕ ℕ.zero = (true , tt) rep-ℕ (ℕ.suc n) = (false , n) unrep-ℕ : Σ Bool Parts-ℕ → ℕ unrep-ℕ (true , tt) = ℕ.zero unrep-ℕ (false , n) = ℕ.suc n -- | Make naturals testable ℕ-testable : Testable ℕ index ℕ-testable = Bool parts ℕ-testable = Parts-ℕ kind ℕ-testable = ind obs ℕ-testable = rep-ℕ partsTestable ℕ-testable = λ { true → ⊤-testable ; false → ℕ-testable } ℕ-IsoTestable : IsoTestable ℕ ℕ-IsoTestable = record { testable = ℕ-testable ; obsIso = record { inv = unrep-ℕ ; isLeftInv = li ; isRightInv = ri } } where li : (n : ℕ) → unrep-ℕ (rep-ℕ n) ≡ n li ℕ.zero = refl li (ℕ.suc a) = refl ri : (x : Σ Bool Parts-ℕ) → rep-ℕ (unrep-ℕ x) ≡ x ri (true , tt) = refl ri (false , n) = refl ¬zero→suc : (n : ℕ) → n ≢ zero → ∃ (λ m → n ≡ suc m) ¬zero→suc n p with n ≟ zero ¬zero→suc zero p | yes n=z = ⊥-elim (p n=z) ¬zero→suc (suc m) p | yes sm=z = ⊥-elim (p sm=z) ¬zero→suc zero p | no ¬n=z = ⊥-elim (p refl) ¬zero→suc (suc n) p | no ¬n=z = n , refl lem-tt≢ff : (a : Bool) → a ≡ true → a ≢ false lem-tt≢ff true _ () lem-tt≢ff false () _ -- | If a number is observationally equivalent to 0, then it is -- actually 0. lem-≃→≡-ℕ-zero : {n : ℕ} → n ≃⟨ ℕ-testable ⟩ zero → n ≡ zero lem-≃→≡-ℕ-zero {n} p = q where -- Test to distinguish zero ψs : SubTests ℕ-testable ind ψs = record { app = λ { true → ⊤ ; false → ⊥ } } φ : Test ℕ-testable φ = nonTriv ψs -- n fulfils test, ... u : n ⊨ φ ≡ true u = eqProof p φ -- ... hence is 0. q : n ≡ zero q with n ≟ zero q | yes n=z = n=z q | no ¬n=z = ⊥-elim (lem (¬zero→suc n ¬n=z)) where -- If n ≡ suc n, then we get a contradiction to u lem : (∃ (λ m → n ≡ suc m)) → Empty lem (m , q) with (n ≟ suc m) ... | yes n=sm = lem-tt≢ff (n ⊨ φ) u contradict where contradict : n ⊨ φ ≡ false contradict = begin n ⊨ φ ≡⟨ refl ⟩ cotuple (λ i y → y ⊨ app ψs i) (rep-ℕ n) ≡⟨ cong (λ u → cotuple (λ i y → y ⊨ app ψs i) (rep-ℕ u)) n=sm ⟩ cotuple (λ i y → y ⊨ app ψs i) (false , n) ≡⟨ refl ⟩ false ∎ ... | no ¬n=sm = ¬n=sm q -- | If a number is observationally equivalent to a successor, then it is -- actually a succesor. lem-≃→≡-ℕ-suc : (n m : ℕ) → n ≃⟨ ℕ-testable ⟩ suc m → ∃ λ n' → (n ≡ suc n') × (n' ≃⟨ ℕ-testable ⟩ m) lem-≃→≡-ℕ-suc = {!!} -- | Observational equivalence for natural numbers implies equivalence. ≃→≡-ℕ : {n m : ℕ} → n ≃⟨ ℕ-testable ⟩ m → n ≡ m ≃→≡-ℕ {n} {zero} p = lem-≃→≡-ℕ-zero p ≃→≡-ℕ {n} {(suc m)} p with lem-≃→≡-ℕ-suc n m p ... | n' , q , p' = begin n ≡⟨ q ⟩ suc n' ≡⟨ cong suc (≃→≡-ℕ {n'} {m} p') ⟩ suc m ∎ -- | Obs. equiv. is a congruence for natural numbers. ≃-cong-ℕ : {A : Set} → {T : Testable A} → {x y : ℕ} → (f : ℕ → A) → x ≃⟨ ℕ-testable ⟩ y → f x ≃⟨ T ⟩ f y ≃-cong-ℕ {A} {T} {x} {y} f p = record { eqProof = q } where q : (φ : Test T) → f x ⊨ φ ≡ f y ⊨ φ q φ = cong (λ u → f u ⊨ φ) (≃→≡-ℕ p)
27.57732
77
0.52
3daa6eaaa841dee44715702df3e32949bee02987
1,694
agda
Agda
vendor/stdlib/src/Induction.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Induction.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Induction.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- An abstraction of various forms of recursion/induction ------------------------------------------------------------------------ -- Note: The types in this module can perhaps be easier to understand -- if they are normalised. Note also that Agda can do the -- normalisation for you. module Induction where open import Relation.Unary -- A RecStruct describes the allowed structure of recursion. The -- examples in Induction.Nat should explain what this is all about. RecStruct : Set → Set₁ RecStruct a = Pred a → Pred a -- A recursor builder constructs an instance of a recursion structure -- for a given input. RecursorBuilder : ∀ {a} → RecStruct a → Set₁ RecursorBuilder {a} Rec = (P : Pred a) → Rec P ⊆′ P → Universal (Rec P) -- A recursor can be used to actually compute/prove something useful. Recursor : ∀ {a} → RecStruct a → Set₁ Recursor {a} Rec = (P : Pred a) → Rec P ⊆′ P → Universal P -- And recursors can be constructed from recursor builders. build : ∀ {a} {Rec : RecStruct a} → RecursorBuilder Rec → Recursor Rec build builder P f x = f x (builder P f x) -- We can repeat the exercise above for subsets of the type we are -- recursing over. SubsetRecursorBuilder : ∀ {a} → Pred a → RecStruct a → Set₁ SubsetRecursorBuilder {a} Q Rec = (P : Pred a) → Rec P ⊆′ P → Q ⊆′ Rec P SubsetRecursor : ∀ {a} → Pred a → RecStruct a → Set₁ SubsetRecursor {a} Q Rec = (P : Pred a) → Rec P ⊆′ P → Q ⊆′ P subsetBuild : ∀ {a} {Q : Pred a} {Rec : RecStruct a} → SubsetRecursorBuilder Q Rec → SubsetRecursor Q Rec subsetBuild builder P f x q = f x (builder P f x q)
33.88
72
0.618064
41fcbfd5978bffebb18c1a1cb050c2ed9c91718b
5,297
agda
Agda
nondet/sort.agda
mihanus/curry-agda
b7cfdda11cdadeba882b6b72d75448acd8b0a294
[ "BSD-3-Clause" ]
null
null
null
nondet/sort.agda
mihanus/curry-agda
b7cfdda11cdadeba882b6b72d75448acd8b0a294
[ "BSD-3-Clause" ]
null
null
null
nondet/sort.agda
mihanus/curry-agda
b7cfdda11cdadeba882b6b72d75448acd8b0a294
[ "BSD-3-Clause" ]
null
null
null
module sort where open import bool open import eq open import nat open import list open import nondet open import nondet-thms -- non-deterministic insert. --This takes a nondeterministic list because I need to be able to call it with the result of perm -- --implementation in curry: -- ndinsert x [] = [] -- ndinsert x (y:ys) = (x : y : xs) ? (y : insert x ys) ndinsert : {A : Set} -> A -> ND (list A) -> ND (list A) ndinsert x (Val [] ) = Val ( x :: []) ndinsert x (Val (y :: ys)) = (Val ( x :: y :: ys )) ?? ((_::_ y) $* (ndinsert x (Val ys))) ndinsert x (l ?? r) = (ndinsert x l) ?? (ndinsert x r) --non-deterministic permutation --this is identical to the curry code (except for the Val constructor) perm : {A : Set} -> (list A) -> ND (list A) perm [] = Val [] perm (x :: xs) = ndinsert x (perm xs) --insert a value into a sorted list. --this is identical to curry or haskell code. -- --note that the structure here is identical to ndinsert insert : {A : Set} -> (A -> A -> 𝔹) -> A -> list A -> list A insert _ x [] = x :: [] insert _<_ x (y :: ys) = if x < y then (x :: y :: ys) else (y :: insert _<_ x ys) --simple insertion sort --again this is identical to curry or haskell --also, note that the structure is identical to perm sort : {A : Set} -> (A -> A -> 𝔹) -> list A -> list A sort _ [] = [] sort p (x :: xs) = insert p x (sort p xs) -- Proof: if xs ∈ nxs then x::xs ∈ ndinsert x nxs insId : {A : Set} -> (x : A) -> (xs : list A) -> (x :: xs) ∈ (ndinsert x (Val xs)) insId x [] = ndrefl insId x (y :: xs) = left (Val (x :: y :: xs)) ((_::_ y) $* (ndinsert x (Val xs))) ndrefl --If introduction rule for non-deterministic values. --if x and y are both possible values in z then --∀ c. if c then x else y will give us either x or y, so it must be a possible value of z. -- ifIntro : {A : Set} -> (x : A) -> (y : A) -> (z : ND A) -> (p : x ∈ z) -> (q : y ∈ z) -> (c : 𝔹) -> (if c then x else y) ∈ z ifIntro x y z p q tt = p ifIntro x y z p q ff = q --------------------------------------------------------------------------- -- -- this should prove that if xs ∈ nxs then, insert x xs ∈ ndinsert x nxs -- parameters: -- c : a comparison operator that is needed for insert -- x : the value we are inserting into the list -- xs : the list -- nxs : a non-deterministic list, we know that xs is a possible value for nxs -- xs ∈ nxs : the proof that xs is somewhere in nxs -- --retruns: insert c x xs ∈ ndinsert x nxs -- a proof that inserting a value in a list is ok with non-deterministic lists insert=ndinsert : {A : Set} -> (c : A -> A -> 𝔹) -> (x : A) -> (xs : list A) -> (nxs : ND (list A)) -> xs ∈ nxs -> (insert c x xs) ∈ (ndinsert x nxs) --the first two cases are simple, either we are inserting into an empty list, in which case it's trivial --or, the list doesn't match the non-deterministic case. This is an imposible case insert=ndinsert _ x [] (Val []) _ = ndrefl insert=ndinsert _ x [] (Val (_ :: _)) () --the next two cases are just structural recursion on the non-deterministic tree. insert=ndinsert c x ys (l ?? r) (left .l .r p) = left (ndinsert x l) (ndinsert x r) (insert=ndinsert c x ys l p) insert=ndinsert c x ys (l ?? r) (right .l .r p) = right (ndinsert x l) (ndinsert x r) (insert=ndinsert c x ys r p) --The final case is the interesting one. --We reached a leaf in the non-deterministic tree, so we have a deterministic value. --by definition this is equal to the deterministic list (y :: ys) --At this point we have two possible cases. --Either x is smaller then every element in (y :: ys), in which case it's inserted at the front, --or x is larger than y, in which case it's inserted somewhere in ys. --Since both of these cases are covered by ndinsert we can invoke the ifIntro lemma, to say that we don't care which case it is. -- --variables: -- step : one step of insert -- l : the left hand side of insert c x xs (the then branch) -- r : the right hand side of insert c x xs (the else branch) -- nr : a non-deterministic r -- (Val l) : a non-deterministic l (but since ndinsert only has a deterministic value on the left it's not very interesting) -- rec : The recursive call. If x isn't inserted into the front, then we need to find it. -- l∈step : a proof that l is a possible value for step -- r∈step : a proof that r is a possible value for step insert=ndinsert _<_ x (y :: ys) (Val (.y :: .ys)) ndrefl = ifIntro l r step l∈step r∈step (x < y) where step = ndinsert x (Val (y :: ys)) l = ( x :: y :: ys) r = y :: insert _<_ x ys nr = (_::_ y) $* (ndinsert x (Val ys)) rec = ∈-$* (_::_ y) (insert _<_ x ys) (ndinsert x (Val ys)) (insert=ndinsert _<_ x ys (Val ys) ndrefl) r∈step = right (Val l) nr rec l∈step = left (Val l) nr ndrefl --------------------------------------------------------------------------- -- main theorem. Sorting a list preserves permutations --all of the work is really done by insert=ndinsert sortPerm : {A : Set} -> (c : A -> A -> 𝔹) -> (xs : list A) -> sort c xs ∈ perm xs sortPerm _<_ [] = ndrefl sortPerm _<_ (x :: xs) = insert=ndinsert _<_ x (sort _<_ xs) (perm xs) (sortPerm _<_ xs)
46.06087
149
0.591278
2f2825cdbb0c9095075f55d0665b0659f458592e
3,110
agda
Agda
cohesion/david_jaz_261/LEM.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
6
2021-10-06T17:39:22.000Z
2022-02-13T05:51:12.000Z
cohesion/david_jaz_261/LEM.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
cohesion/david_jaz_261/LEM.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} module LEM where open import Basics open import Flat open import Bool open import lib.Basics open import lib.types.Bool open import Bool open import lib.NType2 open import Axiom.LEM public flat-set-has-dec-eq : {@♭ i : ULevel} (@♭ A : hSet i) → has-dec-eq (♭ (∈ A)) flat-set-has-dec-eq A = λ {(x ^♭) (y ^♭) → LEM (_==ₚ_ {A = ♭ₙ A} (x ^♭) (y ^♭))} discrete-set-has-dec-eq : {@♭ i : ULevel} (@♭ A : hSet i) → (@♭ _ : (∈ A) is-discrete) → has-dec-eq (∈ A) discrete-set-has-dec-eq A p = transport has-dec-eq (discrete-id p) (flat-set-has-dec-eq A) _=bool=ₚ_ : {@♭ i : ULevel} {@♭ A : hSet i} {@♭ p : (∈ A) is-discrete} (x y : ∈ A) → Bool _=bool=ₚ_ {A = A} {p = p} x y = _=bool=_ {_} {∈ A} {discrete-set-has-dec-eq A p} x y un¬¬-crisp : {@♭ i : ULevel} {@♭ P : PropT i} (nnp : ¬ (¬ (P holds))) → P holds un¬¬-crisp {P = P} nnp with (LEM P) ... | (inl p) = p ... | (inr np) = quodlibet (nnp np) ♭PropT₀≃Bool : ♭ PropT₀ ≃ Bool ♭PropT₀≃Bool = equiv to fro to-fro fro-to where to : ♭ PropT₀ → Bool to (P ^♭) = Dec-Prop-to-Bool P (LEM P) fro : Bool → ♭ PropT₀ fro = Bool-to-♭PropT₀ to-fro : (b : Bool) → to (fro b) == b to-fro true = Dec-Prop-to-Bool-true-id True (LEM True) unit to-fro false = Dec-Prop-to-Bool-false-id False (LEM False) quodlibet fro-to : (P : ♭ PropT₀) → fro (to P) == P fro-to (P ^♭) = case P (LEM P) where case₀♭ : (@♭ P : PropT₀) → ♭ (P holds) → fro (to (P ^♭)) == (P ^♭) case₀♭ P (p ^♭) = fro (to (P ^♭)) =⟨ (ap fro (Dec-Prop-to-Bool-true-id P (LEM P) p)) ⟩ fro true -- Since P holds, it equals true =⟨ ! (♭-ap _^♭ (P holds-by p implies-=-True)) ⟩ P ^♭ =∎ case₁♭ : (@♭ P : PropT₀) → ♭ (¬ (P holds)) → fro (to (P ^♭)) == (P ^♭) case₁♭ P (np ^♭) = fro (to (P ^♭)) =⟨ (ap fro (Dec-Prop-to-Bool-false-id P (LEM P) np)) ⟩ fro false =⟨ ! (♭-ap _^♭ (¬- P holds-by np implies-=-False)) ⟩ P ^♭ =∎ case : (@♭ P : PropT₀) → (@♭ d : Dec (P holds)) → fro (to (P ^♭)) == (P ^♭) case P (inl p ) = case₀♭ P (p ^♭) case P (inr np) = case₁♭ P (np ^♭) {- -- We prove that this equivalence preserves the relevant logical structure. module ♭PropT₀≃Bool-properties where preserves-⇒ : {@♭ P Q : PropT₀} (p : (P ⇒ Q) holds) → (((–> ♭PropT₀≃Bool) (P ^♭)) ≤b ((–> ♭PropT₀≃Bool) (Q ^♭))) holds preserves-⇒ {P} {Q} p = {!!} -- As a corollary, we find that the points of the upper naturals are the conaturals. module Points-Of-Upper-Naturals-Are-Conaturals where open import UpperNaturals open import Conaturals theorem : ℕ∞ ≃ ♭ ℕ↑ theorem = {!!} -}
34.555556
92
0.453698
5962098649a993bceddbda012590710692a8d46f
1,800
agda
Agda
core/lib/types/Bool.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/types/Bool.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/types/Bool.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics module lib.types.Bool where {- data Bool : Type₀ where true : Bool false : Bool {-# BUILTIN BOOL Bool #-} {-# BUILTIN FALSE false #-} {-# BUILTIN TRUE true #-} -} Bool = ⊤ ⊔ ⊤ pattern true = inl unit pattern false = inr unit ⊙Bool : Ptd₀ ⊙Bool = ⊙[ Bool , true ] Bool-elim : ∀ {i} {P : Bool → Type i} → P true → P false → Π Bool P Bool-elim true* false* true = true* Bool-elim true* false* false = false* Bool-rec : ∀ {i} {A : Type i} → A → A → (Bool → A) Bool-rec {A = A} = Bool-elim {P = λ _ → A} negate : Bool → Bool negate true = false negate false = true and : Bool → Bool → Bool and true b = b and false _ = false xor : Bool → Bool → Bool xor true = negate xor false = idf Bool xor-diag : ∀ (b : Bool) → xor b b == false xor-diag true = idp xor-diag false = idp and-false-r : ∀ b → and b false == false and-false-r true = idp and-false-r false = idp and-comm : ∀ b c → and b c == and c b and-comm false false = idp and-comm false true = idp and-comm true false = idp and-comm true true = idp private Bool-true≠false-type : Bool → Type₀ Bool-true≠false-type true = Unit Bool-true≠false-type false = Empty abstract Bool-true≠false : true ≠ false Bool-true≠false p = transport Bool-true≠false-type p unit Bool-false≠true : false ≠ true Bool-false≠true p = transport Bool-true≠false-type (! p) unit Bool-has-dec-eq : has-dec-eq Bool Bool-has-dec-eq true true = inl idp Bool-has-dec-eq true false = inr Bool-true≠false Bool-has-dec-eq false true = inr Bool-false≠true Bool-has-dec-eq false false = inl idp Bool-is-set : is-set Bool Bool-is-set = dec-eq-is-set Bool-has-dec-eq instance Bool-level : {n : ℕ₋₂} → has-level (S (S n)) Bool Bool-level = set-has-level-SS Bool-is-set
21.95122
67
0.645
dfdfbcb5ea949f6dfde245931589544aad318e9e
5,525
agda
Agda
TotalParserCombinators/BreadthFirst.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
TotalParserCombinators/BreadthFirst.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
TotalParserCombinators/BreadthFirst.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A breadth-first backend which uses the derivative operator ------------------------------------------------------------------------ module TotalParserCombinators.BreadthFirst where open import Data.List open import Data.List.Any.Membership.Propositional open import Data.Product open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Inverse using (_↔_; module Inverse) open import Relation.Binary.HeterogeneousEquality as H using () renaming (_≅_ to _≅H_) open import Relation.Binary.PropositionalEquality as P using (_≡_) open import TotalParserCombinators.Congruence using (_≅P_; _∎) import TotalParserCombinators.Congruence.Sound as CS open import TotalParserCombinators.Derivative as D using (D) import TotalParserCombinators.InitialBag as I open import TotalParserCombinators.Parser open import TotalParserCombinators.Semantics open import TotalParserCombinators.Simplification as S using (simplify) ------------------------------------------------------------------------ -- A parametrised backend -- The function f is applied before the derivative. module Parse {Tok} (f : ∀ {R xs} → Parser Tok R xs → ∃ λ xs′ → Parser Tok R xs′) (f-correct : ∀ {R xs} (p : Parser Tok R xs) → proj₂ (f p) ≅P p) where -- The parsing function. parse : ∀ {R xs} → Parser Tok R xs → List Tok → List R parse {xs = xs} p [] = xs parse p (t ∷ s) = parse (D t $ proj₂ $ f p) s -- A variant of f-correct. f-correct′ : ∀ {R xs} (p : Parser Tok R xs) → proj₂ (f p) ≅ p f-correct′ = CS.sound ∘ f-correct -- The backend is sound with respect to the semantics. sound : ∀ {R xs x} {p : Parser Tok R xs} (s : List Tok) → x ∈ parse p s → x ∈ p · s sound [] x∈p = I.sound _ x∈p sound (t ∷ s) x∈p = Inverse.to (f-correct′ _) ⟨$⟩ D.sound _ (sound s x∈p) -- The backend is complete with respect to the semantics. complete : ∀ {R xs x} {p : Parser Tok R xs} (s : List Tok) → x ∈ p · s → x ∈ parse p s complete [] x∈p = I.complete x∈p complete (t ∷ s) x∈p = complete s $ D.complete $ Inverse.from (f-correct′ _) ⟨$⟩ x∈p -- The backend does not introduce any unneeded ambiguity. -- -- The proof complete is a left inverse of sound, so the (finite) type -- x ∈ parse p s contains at most as many proofs as x ∈ p · s. In -- other words, the output of parse p s can only contain n copies of x -- if there are at least n distinct parse trees in x ∈ p · s. complete∘sound : ∀ {R xs x} s (p : Parser Tok R xs) (x∈p : x ∈ parse p s) → complete s (sound s x∈p) ≡ x∈p complete∘sound [] p x∈p = I.complete∘sound p x∈p complete∘sound (t ∷ s) p x∈p rewrite Inverse.left-inverse-of (f-correct′ p) (D.sound (proj₂ (f p)) (sound s x∈p)) | D.complete∘sound (proj₂ (f p)) (sound s x∈p) = complete∘sound s (D t $ proj₂ $ f p) x∈p -- The backend does not remove any ambiguity. -- -- The proof complete is a right inverse of sound, which implies that -- the (finite) type x ∈ parse p s contains at least as many proofs as -- x ∈ p · s. In other words, if the output of parse p s contains n -- copies of x, then there are at most n distinct parse trees in -- x ∈ p · s. sound∘complete : ∀ {R xs x} {p : Parser Tok R xs} (s : List Tok) (x∈p : x ∈ p · s) → sound s (complete s x∈p) ≡ x∈p sound∘complete [] x∈p = I.sound∘complete x∈p sound∘complete (t ∷ s) x∈p rewrite sound∘complete s $ D.complete $ Inverse.from (f-correct′ _) ⟨$⟩ x∈p | D.sound∘complete $ Inverse.from (f-correct′ _) ⟨$⟩ x∈p = Inverse.right-inverse-of (f-correct′ _) x∈p -- The backend is correct. correct : ∀ {R xs x s} {p : Parser Tok R xs} → x ∈ p · s ↔ x ∈ parse p s correct {s = s} {p} = record { to = P.→-to-⟶ $ complete s ; from = P.→-to-⟶ $ sound s ; inverse-of = record { left-inverse-of = sound∘complete s ; right-inverse-of = complete∘sound s p } } ------------------------------------------------------------------------ -- Specific instantiations -- Parsing without simplification. parse : ∀ {Tok R xs} → Parser Tok R xs → List Tok → List R parse = Parse.parse ,_ _∎ parse-correct : ∀ {Tok R xs x s} {p : Parser Tok R xs} → x ∈ p · s ↔ x ∈ parse p s parse-correct = Parse.correct ,_ _∎ -- Parsing with simplification. parse-with-simplification : ∀ {Tok R xs} → Parser Tok R xs → List Tok → List R parse-with-simplification = Parse.parse (λ p → , simplify p) S.correct parse-with-simplification-correct : ∀ {Tok R xs x s} {p : Parser Tok R xs} → x ∈ p · s ↔ x ∈ parse-with-simplification p s parse-with-simplification-correct = Parse.correct _ S.correct ------------------------------------------------------------------------ -- An observation -- The worst-case complexity of parse (without simplification) is /at -- least/ exponential in the size of the input string. There is a -- (finite) parser p whose derivative is p ∣ p (for any token). The -- n-th derivative thus contains (at least) 2^n outermost occurrences -- of _∣_, and these occurrences have to be traversed to compute the -- initial bag of the n-th derivative. parse-inefficient : ∀ {Tok R} → ∃ λ (p : Parser Tok R []) → ∀ t → D t p ≅H p ∣ p parse-inefficient {R = R} = (fail {R = R} >>= (λ _ → fail) , λ t → H.refl)
37.331081
72
0.583529
1df7862cb8a4623b5d50d28e1565ce4e3125b74c
75,146
agda
Agda
src/Lens/Non-dependent/Traditional.agda
nad/dependent-lenses
f2da6f7e95b87ca525e8ea43929c6d6163a74811
[ "MIT" ]
3
2020-04-16T12:10:46.000Z
2020-07-03T08:55:52.000Z
src/Lens/Non-dependent/Traditional.agda
nad/dependent-lenses
f2da6f7e95b87ca525e8ea43929c6d6163a74811
[ "MIT" ]
null
null
null
src/Lens/Non-dependent/Traditional.agda
nad/dependent-lenses
f2da6f7e95b87ca525e8ea43929c6d6163a74811
[ "MIT" ]
1
2020-07-01T14:33:26.000Z
2020-07-01T14:33:26.000Z
------------------------------------------------------------------------ -- Traditional non-dependent lenses ------------------------------------------------------------------------ {-# OPTIONS --cubical #-} import Equality.Path as P module Lens.Non-dependent.Traditional {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection equality-with-J as Bij using (_↔_) open import Circle eq as Circle using (𝕊¹) open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional eq as Trunc using (∥_∥; ∣_∣) open import Preimage equality-with-J using (_⁻¹_) open import Surjection equality-with-J using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq as Non-dependent hiding (no-first-projection-lens; no-singleton-projection-lens) private variable a b c p : Level A A₁ A₂ B B₁ B₂ : Type a u v x₁ x₂ y₁ y₂ : A ------------------------------------------------------------------------ -- Traditional lenses -- Lenses. record Lens (A : Type a) (B : Type b) : Type (a ⊔ b) where field -- Getter and setter. get : A → B set : A → B → A -- Lens laws. get-set : ∀ a b → get (set a b) ≡ b set-get : ∀ a → set a (get a) ≡ a set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ -- A combination of get and set. modify : (B → B) → A → A modify f x = set x (f (get x)) instance -- Traditional lenses have getters and setters. has-getter-and-setter : Has-getter-and-setter (Lens {a = a} {b = b}) has-getter-and-setter = record { get = Lens.get ; set = Lens.set } -- Lens A B is isomorphic to a nested Σ-type. Lens-as-Σ : Lens A B ↔ ∃ λ (get : A → B) → ∃ λ (set : A → B → A) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) Lens-as-Σ = record { surjection = record { logical-equivalence = record { to = λ l → get l , set l , get-set l , set-get l , set-set l ; from = λ { (get , set , get-set , set-get , set-set) → record { get = get ; set = set ; get-set = get-set ; set-get = set-get ; set-set = set-set } } } ; right-inverse-of = refl } ; left-inverse-of = refl } where open Lens private variable l₁ l₂ : Lens A B -- An example: A lens corresponding to the value of a function for a -- certain input. function-at : Decidable-equality A → A → Lens (A → B) B function-at _≟_ a = record { get = λ f → f a ; set = λ f b a′ → if a ≟ a′ then b else f a′ ; get-set = λ f b → lemma₁ (a ≟ a) ; set-get = λ f → ⟨ext⟩ λ a′ → lemma₂ f (a ≟ a′) ; set-set = λ f b₁ b₂ → ⟨ext⟩ λ a′ → lemma₃ (a ≟ a′) } where lemma₁ : ∀ {b₁ b₂} (d : Dec (a ≡ a)) → if d then b₁ else b₂ ≡ b₁ lemma₁ (yes _) = refl _ lemma₁ (no a≢a) = ⊥-elim $ a≢a (refl _) lemma₂ : ∀ f {a′} (d : Dec (a ≡ a′)) → if d then f a else f a′ ≡ f a′ lemma₂ f (yes a≡a′) = cong f a≡a′ lemma₂ _ (no _) = refl _ lemma₃ : ∀ {a′ b₁ b₂ b₃} (d : Dec (a ≡ a′)) → if d then b₂ else (if d then b₁ else b₃) ≡ if d then b₂ else b₃ lemma₃ (yes _) = refl _ lemma₃ (no _) = refl _ ------------------------------------------------------------------------ -- Somewhat coherent lenses -- Traditional lenses that satisfy some extra coherence properties. record Coherent-lens (A : Type a) (B : Type b) : Type (a ⊔ b) where field lens : Lens A B open Lens lens public field get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a) get-set-set : ∀ a b₁ b₂ → cong get (set-set a b₁ b₂) ≡ trans (get-set (set a b₁) b₂) (sym (get-set a b₂)) instance -- Somewhat coherent lenses have getters and setters. coherent-has-getter-and-setter : Has-getter-and-setter (Coherent-lens {a = a} {b = b}) coherent-has-getter-and-setter = record { get = Coherent-lens.get ; set = Coherent-lens.set } -- Coherent-lens A B is equivalent to a nested Σ-type. Coherent-lens-as-Σ : Coherent-lens A B ≃ ∃ λ (l : Lens A B) → let open Lens l in (∀ a → cong get (set-get a) ≡ get-set a (get a)) × (∀ a b₁ b₂ → cong get (set-set a b₁ b₂) ≡ trans (get-set (set a b₁) b₂) (sym (get-set a b₂))) Coherent-lens-as-Σ = Eq.↔→≃ (λ l → lens l , get-set-get l , get-set-set l) (λ (l , get-set-get , get-set-set) → record { lens = l ; get-set-get = get-set-get ; get-set-set = get-set-set }) refl refl where open Coherent-lens ------------------------------------------------------------------------ -- Some lemmas -- If two lenses have equal setters, then they also have equal -- getters. getters-equal-if-setters-equal : let open Lens in (l₁ l₂ : Lens A B) → set l₁ ≡ set l₂ → get l₁ ≡ get l₂ getters-equal-if-setters-equal l₁ l₂ setters-equal = ⟨ext⟩ λ a → get l₁ a ≡⟨ cong (get l₁) $ sym $ set-get l₂ _ ⟩ get l₁ (set l₂ a (get l₂ a)) ≡⟨ cong (λ f → get l₁ (f _ _)) $ sym setters-equal ⟩ get l₁ (set l₁ a (get l₂ a)) ≡⟨ get-set l₁ _ _ ⟩∎ get l₂ a ∎ where open Lens -- If the forward direction of an equivalence is Lens.get l, then the -- setter of l can be expressed using the other direction of the -- equivalence. from≡set : ∀ (l : Lens A B) is-equiv → let open Lens A≃B = Eq.⟨ get l , is-equiv ⟩ in ∀ a b → _≃_.from A≃B b ≡ set l a b from≡set l is-equiv a b = _≃_.to-from Eq.⟨ get , is-equiv ⟩ ( get (set a b) ≡⟨ get-set _ _ ⟩∎ b ∎) where open Lens l ------------------------------------------------------------------------ -- Some lens isomorphisms -- Lens preserves equivalences. Lens-cong : A₁ ≃ A₂ → B₁ ≃ B₂ → Lens A₁ B₁ ≃ Lens A₂ B₂ Lens-cong {A₁ = A₁} {A₂ = A₂} {B₁ = B₁} {B₂ = B₂} A₁≃A₂ B₁≃B₂ = Lens A₁ B₁ ↔⟨ Lens-as-Σ ⟩ (∃ λ (get : A₁ → B₁) → ∃ λ (set : A₁ → B₁ → A₁) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (Σ-cong (→-cong ext A₁≃A₂ B₁≃B₂) λ get → Σ-cong (→-cong ext A₁≃A₂ $ →-cong ext B₁≃B₂ A₁≃A₂) λ set → (Π-cong ext A₁≃A₂ λ a → Π-cong ext B₁≃B₂ λ b → inverse (Eq.≃-≡ B₁≃B₂) F.∘ (≡⇒≃ $ cong (_≡ _) (get (set a b) ≡⟨ sym $ cong₂ (λ a b → get (set a b)) (_≃_.left-inverse-of A₁≃A₂ _) (_≃_.left-inverse-of B₁≃B₂ _) ⟩ get (set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a)) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))) ≡⟨ cong get $ sym $ _≃_.left-inverse-of A₁≃A₂ _ ⟩∎ get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ (set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a)) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))))) ∎))) ×-cong (Π-cong ext A₁≃A₂ λ a → inverse (Eq.≃-≡ A₁≃A₂) F.∘ (≡⇒≃ $ cong (_≡ _) (set a (get a) ≡⟨ cong (set a) $ sym $ _≃_.left-inverse-of B₁≃B₂ _ ⟩ set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a))) ≡⟨ cong (λ a → set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a)))) $ sym $ _≃_.left-inverse-of A₁≃A₂ _ ⟩∎ set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a)) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))))) ∎))) ×-cong (inverse $ Π-cong ext (inverse A₁≃A₂) λ a → inverse $ Π-cong ext B₁≃B₂ λ b₁ → inverse $ Π-cong ext (inverse B₁≃B₂) λ b₂ → (≡⇒≃ $ cong (λ a′ → set a′ (_≃_.from B₁≃B₂ b₂) ≡ set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ b₂)) (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ (set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)))) ≡⟨ _≃_.left-inverse-of A₁≃A₂ _ ⟩ set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)) ≡⟨ cong (set (_≃_.from A₁≃A₂ a)) $ _≃_.left-inverse-of B₁≃B₂ _ ⟩∎ set (_≃_.from A₁≃A₂ a) b₁ ∎)) F.∘ Eq.≃-≡ A₁≃A₂)) ⟩ (∃ λ (get : A₂ → B₂) → ∃ λ (set : A₂ → B₂ → A₂) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↔⟨ inverse Lens-as-Σ ⟩□ Lens A₂ B₂ □ -- If B is a proposition, then Lens A B is isomorphic to -- (A → B) × ((a : A) → a ≡ a). lens-to-proposition↔ : Is-proposition B → Lens A B ↔ (A → B) × ((a : A) → a ≡ a) lens-to-proposition↔ {B = B} {A = A} B-prop = Lens A B ↝⟨ Lens-as-Σ ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-left-× λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → Π-closure ext 0 λ _ → +⇒≡ B-prop) ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (∃-cong λ get → ∃-cong λ set → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ ( (set (set a b₁) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a b) b₂ ≡ _) (B-prop _ _) ⟩ (set (set a (get a)) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a (get a)) b ≡ _) (B-prop _ _) ⟩ (set (set a (get a)) (get (set a (get a))) ≡ set a b₂) ≡⟨ cong (λ b → _ ≡ set a b) (B-prop _ _) ⟩∎ (set (set a (get a)) (get (set a (get a))) ≡ set a (get a)) ∎)) ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → (∀ a → set a (get a) ≡ a) × (∀ a → B → B → set (set a (get a)) (get (set a (get a))) ≡ set a (get a))) ↝⟨ (∃-cong λ get → Σ-cong (A→B→A↔A→A get) λ _ → F.id) ⟩ ((A → B) × ∃ λ (f : A → A) → (∀ a → f a ≡ a) × (∀ a → B → B → f (f a) ≡ f a)) ↝⟨ (∃-cong λ get → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → drop-⊤-left-Π ext (B↔⊤ (get a)) F.∘ drop-⊤-left-Π ext (B↔⊤ (get a))) ⟩ ((A → B) × ∃ λ (f : A → A) → (∀ a → f a ≡ a) × (∀ a → f (f a) ≡ f a)) ↝⟨ (∃-cong λ _ → ∃-cong λ f → ∃-cong λ f≡id → ∀-cong ext λ a → ≡⇒↝ _ (cong₂ _≡_ (trans (f≡id (f a)) (f≡id a)) (f≡id a))) ⟩ ((A → B) × ∃ λ (f : A → A) → (∀ a → f a ≡ a) × (∀ a → a ≡ a)) ↝⟨ (∃-cong λ _ → Σ-assoc F.∘ (∃-cong λ _ → Σ-cong (Eq.extensionality-isomorphism ext) λ _ → F.id)) ⟩ (A → B) × (∃ λ (f : A → A) → f ≡ id) × (∀ a → a ≡ a) ↝⟨ (∃-cong λ _ → drop-⊤-left-× λ _ → _⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ⟩□ (A → B) × (∀ a → a ≡ a) □ where B↔⊤ : B → B ↔ ⊤ B↔⊤ b = _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible B-prop b A→B→A↔A→A : (A → B) → (A → B → A) ↔ (A → A) A→B→A↔A→A get = (A → B → A) ↝⟨ ∀-cong ext (λ a → drop-⊤-left-Π ext $ B↔⊤ (get a)) ⟩□ (A → A) □ -- Lens A ⊤ is isomorphic to (a : A) → a ≡ a. lens-to-⊤↔ : Lens A ⊤ ↔ ((a : A) → a ≡ a) lens-to-⊤↔ {A = A} = Lens A ⊤ ↝⟨ lens-to-proposition↔ (mono₁ 0 ⊤-contractible) ⟩ (A → ⊤) × ((a : A) → a ≡ a) ↝⟨ drop-⊤-left-× (λ _ → →-right-zero) ⟩□ ((a : A) → a ≡ a) □ -- Lens A ⊥ is isomorphic to ¬ A. lens-to-⊥↔ : Lens A (⊥ {ℓ = b}) ↔ ¬ A lens-to-⊥↔ {A = A} = Lens A ⊥ ↝⟨ lens-to-proposition↔ ⊥-propositional ⟩ (A → ⊥) × ((a : A) → a ≡ a) ↝⟨ →-cong ext F.id (Bij.⊥↔uninhabited ⊥-elim) ×-cong F.id ⟩ ¬ A × ((a : A) → a ≡ a) ↝⟨ drop-⊤-right lemma ⟩□ ¬ A □ where lemma : ¬ A → ((a : A) → a ≡ a) ↔ ⊤ lemma ¬a = record { surjection = record { logical-equivalence = record { to = _ ; from = λ _ _ → refl _ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ eq → ⟨ext⟩ λ a → ⊥-elim (¬a a) } -- See also lens-from-⊥≃⊤ and lens-from-⊤≃codomain-contractible below. ------------------------------------------------------------------------ -- Some lens results related to h-levels -- If the domain of a lens is inhabited and has h-level n, -- then the codomain also has h-level n. h-level-respects-lens-from-inhabited : ∀ n → Lens A B → A → H-level n A → H-level n B h-level-respects-lens-from-inhabited {A = A} {B = B} n l a = H-level n A ↝⟨ H-level.respects-surjection surj n ⟩□ H-level n B □ where open Lens l surj : A ↠ B surj = record { logical-equivalence = record { to = get ; from = set a } ; right-inverse-of = λ b → get (set a b) ≡⟨ get-set a b ⟩∎ b ∎ } -- Lenses with contractible domains have contractible codomains. contractible-to-contractible : Lens A B → Contractible A → Contractible B contractible-to-contractible l c = h-level-respects-lens-from-inhabited _ l (proj₁ c) c -- If A and B have h-level n given the assumption that A is inhabited, -- then Lens A B also has h-level n. lens-preserves-h-level : ∀ n → (A → H-level n A) → (A → H-level n B) → H-level n (Lens A B) lens-preserves-h-level n hA hB = H-level.respects-surjection (_↔_.surjection (inverse Lens-as-Σ)) n $ Σ-closure n (Π-closure ext n λ a → hB a) λ _ → Σ-closure n (Π-closure ext n λ a → Π-closure ext n λ _ → hA a) λ _ → ×-closure n (Π-closure ext n λ a → Π-closure ext n λ _ → +⇒≡ $ mono₁ n (hB a)) $ ×-closure n (Π-closure ext n λ a → +⇒≡ $ mono₁ n (hA a)) (Π-closure ext n λ a → Π-closure ext n λ _ → Π-closure ext n λ _ → +⇒≡ $ mono₁ n (hA a)) -- If A has positive h-level n, then Lens A B also has h-level n. lens-preserves-h-level-of-domain : ∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B) lens-preserves-h-level-of-domain n hA = [inhabited⇒+]⇒+ n λ l → lens-preserves-h-level (1 + n) (λ _ → hA) λ a → h-level-respects-lens-from-inhabited _ l a hA -- Lens 𝕊¹ ⊤ is not propositional (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.¬-type-of-refl-propositional.) ¬-lens-to-⊤-propositional : Univalence (# 0) → ¬ Is-proposition (Lens 𝕊¹ ⊤) ¬-lens-to-⊤-propositional _ = Is-proposition (Lens 𝕊¹ ⊤) ↝⟨ H-level.respects-surjection (_↔_.surjection lens-to-⊤↔) 1 ⟩ Is-proposition ((x : 𝕊¹) → x ≡ x) ↝⟨ H-level-cong _ 1 (Π-cong ext (inverse Bij.↑↔) λ _ → Eq.≃-≡ $ Eq.↔⇒≃ Bij.↑↔) ⟩ Is-proposition ((x : ↑ lzero 𝕊¹) → x ≡ x) ↝⟨ proj₂ $ Circle.¬-type-of-refl-propositional ⟩□ ⊥ □ ------------------------------------------------------------------------ -- Some equality characterisation lemmas abstract -- An equality characterisation lemma. equality-characterisation₁ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂) equality-characterisation₁ {l₁ = l₁} {l₂ = l₂} = let l₁′ = _↔_.to Lens-as-Σ l₁ l₂′ = _↔_.to Lens-as-Σ l₂ in l₁ ≡ l₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Lens-as-Σ)) ⟩ l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Σ-assoc)) ⟩ ((get l₁ , set l₁) , proj₂ (proj₂ l₁′)) ≡ ((get l₂ , set l₂) , proj₂ (proj₂ l₂′)) ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩ (∃ λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) → subst (λ { (get , set) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) gs (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) ↝⟨ Σ-cong (inverse ≡×≡↔≡) (λ gs → ≡⇒↝ _ $ cong (λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) → subst (λ { (get , set) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) gs (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) (sym $ _↔_.right-inverse-of ≡×≡↔≡ gs)) ⟩ (∃ λ (gs : get l₁ ≡ get l₂ × set l₁ ≡ set l₂) → subst (λ { (get , set) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) (_↔_.to ≡×≡↔≡ gs) (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) ↝⟨ inverse Σ-assoc ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → subst (λ { (get , set) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) (_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ≡⇒↝ _ $ cong (λ x → x ≡ proj₂ (proj₂ l₂′)) (push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _)) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → ( subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) , subst (λ { (get , set) → (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) (_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ (proj₂ l₁′))) ) ≡ proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse ≡×≡↔≡) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡ get-set l₂ × subst (λ { (get , set) → (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) (_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ (proj₂ l₁′))) ≡ proj₂ (proj₂ (proj₂ l₂′))) ↝⟨ (∃-cong λ g → ∃-cong λ s → ∃-cong λ _ → ≡⇒↝ _ $ cong (λ x → x ≡ proj₂ (proj₂ (proj₂ l₂′))) (push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _)) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡ get-set l₂ × ( subst (λ { (get , set) → ∀ a → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) , subst (λ { (get , set) → ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ) ≡ proj₂ (proj₂ (proj₂ l₂′))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → inverse ≡×≡↔≡) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡ get-set l₂ × subst (λ { (get , set) → ∀ a → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) ≡ set-get l₂ × subst (λ { (get , set) → ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ≡ set-set l₂) ↝⟨ (∃-cong λ g → ∃-cong λ s → lemma₁ (λ { (get , set) a → ∀ b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) ×-cong lemma₁ (λ { (get , set) a → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) ×-cong lemma₁ (λ { (get , set) a → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a → subst (λ { (get , set) → ∀ b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a) ≡ get-set l₂ a) × (∀ a → subst (λ { (get , set) → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a → subst (λ { (get , set) → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a) ≡ set-set l₂ a)) ↝⟨ (∃-cong λ g → ∃-cong λ s → (∀-cong ext λ a → lemma₁ (λ { (get , set) b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s))) ×-cong F.id ×-cong (∀-cong ext λ a → lemma₁ (λ { (get , set) b₁ → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ { (get , set) → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → subst (λ { (get , set) → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ → subst (λ { (get , set) → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁) ≡ set-set l₂ a b₁)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ b₁ → lemma₁ (λ { (get , set) b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ { (get , set) → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → subst (λ { (get , set) → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → (∀-cong ext λ a → ∀-cong ext λ b → lemma₂ (λ { (get , set) → get (set a b) ≡ b }) g s) ×-cong (∀-cong ext λ a → lemma₂ (λ { (get , set) → set a (get a) ≡ a }) g s) ×-cong (∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → lemma₂ (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) g s)) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ get → set l₂ (set l₂ a b₁) b₂ ≡ set l₂ a b₂) g (subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂)) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ x → x ≡ _) $ subst-const g) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) □ where open Lens abstract lemma₁ : ∀ (C : A → B → Type c) (eq : u ≡ v) {f g} → (subst (λ x → ∀ y → C x y) eq f ≡ g) ↔ (∀ y → subst (λ x → C x y) eq (f y) ≡ g y) lemma₁ C eq {f} {g} = subst (λ x → ∀ y → C x y) eq f ≡ g ↔⟨ inverse $ Eq.extensionality-isomorphism ext ⟩ (∀ y → subst (λ x → ∀ y → C x y) eq f y ≡ g y) ↝⟨ (∀-cong ext λ y → ≡⇒↝ _ $ cong (λ x → x ≡ _) (sym $ push-subst-application eq _)) ⟩□ (∀ y → subst (λ x → C x y) eq (f y) ≡ g y) □ lemma₂ : (P : A × B → Type p) (x₁≡x₂ : x₁ ≡ x₂) (y₁≡y₂ : y₁ ≡ y₂) → ∀ {p p′} → (subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ p′) ↔ (subst (λ x → P (x , y₂)) x₁≡x₂ (subst (λ y → P (x₁ , y)) y₁≡y₂ p) ≡ p′) lemma₂ P x₁≡x₂ y₁≡y₂ {p = p} = ≡⇒↝ _ $ cong (_≡ _) $ elim¹ (λ y₁≡y₂ → subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ subst (λ x → P (x , _)) x₁≡x₂ (subst (λ y → P (_ , y)) y₁≡y₂ p)) (subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , refl _)) p ≡⟨⟩ subst P (cong₂ _,_ x₁≡x₂ (refl _)) p ≡⟨⟩ subst P (trans (cong (_, _) x₁≡x₂) (cong (_ ,_) (refl _))) p ≡⟨ cong (λ eq → subst P (trans (cong (_, _) x₁≡x₂) eq) p) $ cong-refl _ ⟩ subst P (trans (cong (_, _) x₁≡x₂) (refl _)) p ≡⟨ cong (λ eq → subst P eq p) $ trans-reflʳ _ ⟩ subst P (cong (_, _) x₁≡x₂) p ≡⟨ sym $ subst-∘ _ _ _ ⟩ subst (λ x → P (x , _)) x₁≡x₂ p ≡⟨ cong (subst (λ x → P (x , _)) x₁≡x₂) $ sym $ subst-refl _ _ ⟩∎ subst (λ x → P (x , _)) x₁≡x₂ (subst (λ y → P (_ , y)) (refl _) p) ∎) _ -- Another equality characterisation lemma. equality-characterisation₂ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂) equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → (∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (_≡ _) $ lemma₁ g s a b) ×-cong (∀-cong ext λ a → ≡⇒↝ _ $ cong (_≡ _) $ lemma₂ g s a) ×-cong F.id) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) □ where open Lens lemma₁ : (g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) → ∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) lemma₁ g s a b = subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g eq) $ subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = (get-set l₁ a b)} ⟩ subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (trans (get-set l₁ a b) (cong (const b) s))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (trans _ eq))) $ cong-const s ⟩ subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (trans (get-set l₁ a b) (refl _))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g (trans _ eq)) $ trans-reflʳ _ ⟩ subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g} {fx≡gx = trans _ (get-set l₁ a b)} ⟩ trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) (cong (const b) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) eq)) $ cong-const g ⟩ trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) (refl _)) ≡⟨ cong (trans _) $ trans-reflʳ _ ⟩ trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) ≡⟨ sym $ trans-assoc _ _ (get-set l₁ a b) ⟩ trans (trans (sym (cong (λ get → get (set l₂ a b)) g)) (sym (cong (λ set → get l₁ (set a b)) s))) (get-set l₁ a b) ≡⟨ cong (λ eq → trans eq (get-set l₁ a b)) $ sym $ sym-trans _ (cong (λ get → get (set l₂ a b)) g) ⟩ trans (sym (trans (cong (λ set → get l₁ (set a b)) s) (cong (λ get → get (set l₂ a b)) g))) (get-set l₁ a b) ≡⟨⟩ trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ∎ lemma₂ : (g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) → ∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) lemma₂ g s a = subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡⟨⟩ subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡⟨ cong (subst (λ get → set l₂ a (get a) ≡ a) g) $ subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-get l₁ a} ⟩ subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (trans (set-get l₁ a) (cong (const a) s))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (trans _ eq))) $ cong-const s ⟩ subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (trans (set-get l₁ a) (refl _))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g (trans _ eq)) $ trans-reflʳ _ ⟩ subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g} {fx≡gx = trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)} ⟩ trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) (cong (const a) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) eq)) $ cong-const g ⟩ trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) (refl _)) ≡⟨ cong (trans _) $ trans-reflʳ _ ⟩ trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) ≡⟨ sym $ trans-assoc _ _ (set-get l₁ a) ⟩ trans (trans (sym (cong (λ get → set l₂ a (get a)) g)) (sym (cong (λ set → set a (get l₁ a)) s))) (set-get l₁ a) ≡⟨ cong (λ eq → trans eq (set-get l₁ a)) $ sym $ sym-trans _ (cong (λ get → set l₂ a (get a)) g) ⟩ trans (sym (trans (cong (λ set → set a (get l₁ a)) s) (cong (λ get → set l₂ a (get a)) g))) (set-get l₁ a) ≡⟨⟩ trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ∎ -- And another one. equality-characterisation₃ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂)) equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $ lemma g s a b₁ b₂) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂))) □ where open Lens lemma : (g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) → ∀ a b₁ b₂ → (subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂) ≡ (trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂)) lemma g s a b₁ b₂ = subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂ ≡⟨ cong (_≡ _) $ subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-set l₁ a b₁ b₂} ⟩ trans (sym (cong (λ set → set (set a b₁) b₂) s)) (trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s)) ≡ set-set l₂ a b₁ b₂ ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩ trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (sym (sym (cong (λ set → set (set a b₁) b₂) s))) (set-set l₂ a b₁ b₂) ≡⟨ cong (λ eq → trans _ (cong (λ set → set a b₂) s) ≡ trans eq (set-set l₂ a b₁ b₂)) $ sym-sym (cong (λ set → set (set a b₁) b₂) s) ⟩ trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂) ∎ -- And yet another one. equality-characterisation₄ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) → (∀ a b → trans (sym (trans (cong (get l₁) (s a b)) (g (set l₂ a b)))) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (trans (s a (get l₁ a)) (cong (set l₂ a) (g a)))) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ∘ s))) (set-set l₂ a b₁ b₂)) equality-characterisation₄ {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ equality-characterisation₃ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂))) ↝⟨ (Σ-cong (inverse $ Eq.extensionality-isomorphism ext) λ g → Σ-cong (inverse $ Eq.extensionality-isomorphism ext F.∘ ∀-cong ext λ _ → Eq.extensionality-isomorphism ext) λ s → (∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (λ eq → trans (sym eq) (get-set l₁ a b) ≡ _) ( cong₂ (λ set get → get (set a b)) s g ≡⟨⟩ trans (cong (λ set → get l₁ (set a b)) s) (cong (λ get → get (set l₂ a b)) g) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $ cong-∘ _ _ s ⟩ trans (cong (get l₁ ∘ (_$ b)) (ext⁻¹ s a)) (ext⁻¹ g (set l₂ a b)) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $ cong-∘ _ _ (ext⁻¹ s a) ⟩∎ trans (cong (get l₁) (ext⁻¹ (ext⁻¹ s a) b)) (ext⁻¹ g (set l₂ a b)) ∎)) ×-cong (∀-cong ext λ a → ≡⇒↝ _ $ cong (λ eq → trans (sym eq) (set-get l₁ a) ≡ _) ( cong₂ (λ set get → set a (get a)) s g ≡⟨⟩ trans (cong (λ set → set a (get l₁ a)) s) (cong (λ get → set l₂ a (get a)) g) ≡⟨ sym $ cong₂ trans (cong-∘ _ _ s) (cong-∘ _ _ g) ⟩ trans (ext⁻¹ (ext⁻¹ s a) (get l₁ a)) (cong (set l₂ a) (ext⁻¹ g a)) ∎)) ×-cong ∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $ cong₂ (λ p q → trans _ p ≡ trans (cong (λ set → set (set a b₁) b₂) q) (set-set l₂ a b₁ b₂)) ( cong (λ set → set a b₂) s ≡⟨ sym $ cong-∘ _ _ s ⟩∎ ext⁻¹ (ext⁻¹ s a) b₂ ∎) ( s ≡⟨ sym $ _≃_.right-inverse-of (Eq.extensionality-isomorphism bad-ext) _ ⟩ ⟨ext⟩ (ext⁻¹ s) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → sym $ _≃_.right-inverse-of (Eq.extensionality-isomorphism bad-ext) _) ⟩∎ ⟨ext⟩ (⟨ext⟩ ∘ ext⁻¹ ∘ ext⁻¹ s) ∎)) ⟩□ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) → (∀ a b → trans (sym (trans (cong (get l₁) (s a b)) (g (set l₂ a b)))) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (trans (s a (get l₁ a)) (cong (set l₂ a) (g a)))) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ∘ s))) (set-set l₂ a b₁ b₂))) □ where open Lens -- A lemma that can be used to prove that two lenses with -- definitionally equal getters and setters are equal. equal-laws→≡ : {get : A → B} {set : A → B → A} {l₁′ l₂′ : (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)} → let l₁ = _↔_.from Lens-as-Σ (get , set , l₁′) l₂ = _↔_.from Lens-as-Σ (get , set , l₂′) open Lens in (∀ a b → get-set l₁ a b ≡ get-set l₂ a b) → (∀ a → set-get l₁ a ≡ set-get l₂ a) → (∀ a b₁ b₂ → set-set l₁ a b₁ b₂ ≡ set-set l₂ a b₁ b₂) → l₁ ≡ l₂ equal-laws→≡ {l₁′ = l₁′} {l₂′ = l₂′} hyp₁ hyp₂ hyp₃ = let l₁″ = _↔_.from Lens-as-Σ (_ , _ , l₁′) l₂″ = _↔_.from Lens-as-Σ (_ , _ , l₂′) in _↔_.from equality-characterisation₂ ( refl _ , refl _ , (λ a b → trans (sym (cong₂ (λ set get → get (set a b)) (refl _) (refl _))) (get-set l₁″ a b) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩ trans (sym (refl _)) (get-set l₁″ a b) ≡⟨ cong (flip trans _) sym-refl ⟩ trans (refl _) (get-set l₁″ a b) ≡⟨ trans-reflˡ _ ⟩ get-set l₁″ a b ≡⟨ hyp₁ _ _ ⟩∎ get-set l₂″ a b ∎) , (λ a → trans (sym (cong₂ (λ set get → set a (get a)) (refl _) (refl _))) (set-get l₁″ a) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩ trans (sym (refl _)) (set-get l₁″ a) ≡⟨ cong (flip trans _) sym-refl ⟩ trans (refl _) (set-get l₁″ a) ≡⟨ trans-reflˡ _ ⟩ set-get l₁″ a ≡⟨ hyp₂ _ ⟩∎ set-get l₂″ a ∎) , (λ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) (refl _) (set-set l₁″ a b₁ b₂) ≡⟨ subst-refl _ _ ⟩ set-set l₁″ a b₁ b₂ ≡⟨ hyp₃ _ _ _ ⟩∎ set-set l₂″ a b₁ b₂ ∎) ) where open Lens -- An equality characterisation lemma for lenses from sets. equality-characterisation-for-sets : let open Lens in {l₁ l₂ : Lens A B} → Is-set A → l₁ ≡ l₂ ↔ set l₁ ≡ set l₂ equality-characterisation-for-sets {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} A-set = l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ a → Π-closure ext 0 λ _ → +⇒≡ (B-set a)) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → +⇒≡ A-set) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → Π-closure ext 0 λ _ → Π-closure ext 0 λ _ → +⇒≡ A-set) ⟩ get l₁ ≡ get l₂ × set l₁ ≡ set l₂ ↝⟨ (drop-⊤-left-× λ setters-equal → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure ext 2 λ a → B-set a) (getters-equal-if-setters-equal l₁ l₂ setters-equal)) ⟩□ set l₁ ≡ set l₂ □ where open Lens B-set : A → Is-set B B-set a = h-level-respects-lens-from-inhabited 2 l₁ a A-set ------------------------------------------------------------------------ -- More isomorphisms/equivalences related to lenses -- Lens ⊤ B is equivalent to Contractible B. lens-from-⊤≃codomain-contractible : Lens ⊤ B ≃ Contractible B lens-from-⊤≃codomain-contractible = Eq.⇔→≃ (lens-preserves-h-level-of-domain 0 (mono₁ 0 ⊤-contractible)) (H-level-propositional ext 0) (λ l → contractible-to-contractible l ⊤-contractible) (λ (b , irrB) → record { get = λ _ → b ; get-set = λ _ → irrB ; set-get = refl ; set-set = λ _ _ _ → refl _ }) -- Lens ⊥ B is equivalent to the unit type. lens-from-⊥≃⊤ : Lens (⊥ {ℓ = a}) B ≃ ⊤ lens-from-⊥≃⊤ = Eq.⇔→≃ (lens-preserves-h-level-of-domain 0 ⊥-propositional) (mono₁ 0 ⊤-contractible) _ (λ _ → record { get = ⊥-elim ; set = ⊥-elim ; get-set = λ a → ⊥-elim a ; set-get = λ a → ⊥-elim a ; set-set = λ a → ⊥-elim a }) -- If A is a set and there is a lens from A to B, then A is equivalent -- to the cartesian product of some type (that can be expressed using -- the setter of l) and B. -- -- This result is based on Theorem 2.3.9 from "Lenses and View Update -- Translation" by Pierce and Schmitt. -- -- See also Lens.Non-dependent.Traditional.Combinators.≄Σ∥set⁻¹∥×. ≃Σ∥set⁻¹∥× : Is-set A → (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B) ≃Σ∥set⁻¹∥× {A = A} {B = B} A-set l = Eq.↔→≃ (λ a → (set a , ∣ a , refl _ ∣) , get a) (λ ((f , _) , b) → f b) (λ ((f , p) , b) → flip (Trunc.rec (×-closure 2 (Σ-closure 2 (Π-closure ext 2 λ _ → A-set) λ _ → mono₁ 1 Trunc.truncation-is-proposition) (B-set (f b)))) p λ (a , q) → let lemma₁ = set (f b) ≡⟨ cong (λ f → set (f b)) $ sym q ⟩ set (set a b) ≡⟨ ⟨ext⟩ $ set-set a b ⟩ set a ≡⟨ q ⟩∎ f ∎ lemma₂ = get (f b) ≡⟨ cong (λ f → get (f b)) $ sym q ⟩ get (set a b) ≡⟨ get-set _ _ ⟩∎ b ∎ in (set (f b) , ∣ f b , refl _ ∣) , get (f b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ (Trunc.truncation-is-proposition _ _)) lemma₂ ⟩∎ (f , p ) , b ∎) (λ a → set a (get a) ≡⟨ set-get a ⟩∎ a ∎) where open Lens l B-set : A → Is-set B B-set a = h-level-respects-lens-from-inhabited 2 l a A-set -- If B is an inhabited set and there is a lens from A to B, then A is -- equivalent to the cartesian product of some type (that can be -- expressed using the getter of l) and B. -- -- This result is based on Corollary 13 from "Algebras and Update -- Strategies" by Johnson, Rosebrugh and Wood. ≃get⁻¹× : Is-set B → (b : B) (l : Lens A B) → A ≃ (Lens.get l ⁻¹ b × B) ≃get⁻¹× {B = B} {A = A} B-set b₀ l = Eq.↔→≃ (λ a → (set a b₀ , get-set a b₀) , get a) (λ ((a , _) , b) → set a b) (λ ((a , h) , b) → let lemma = set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩ set a b₀ ≡⟨ cong (set a) (sym h) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎ in (set (set a b) b₀ , get-set (set a b) b₀) , get (set a b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma (B-set _ _)) (get-set a b) ⟩∎ (a , h ) , b ∎) (λ a → set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎) where open Lens l -- For somewhat coherent lenses the previous result can be proved -- without the assumption that the codomain is a set. ≃get⁻¹×-coherent : (b : B) (l : Coherent-lens A B) → A ≃ (Coherent-lens.get l ⁻¹ b × B) ≃get⁻¹×-coherent {B = B} {A = A} b₀ l = Eq.↔→≃ (λ a → (set a b₀ , get-set a b₀) , get a) (λ ((a , _) , b) → set a b) (λ ((a , h) , b) → let lemma₁ = set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩ set a b₀ ≡⟨ cong (set a) (sym h) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎ lemma₂₁ = cong get (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))) ≡⟨ trans (cong-trans _ _ _) $ cong (trans _) $ trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _ ⟩ trans (cong get (set-set a b b₀)) (trans (cong (get ∘ set a) (sym h)) (cong get (set-get a))) ≡⟨ cong₂ (λ p q → trans p (trans (cong (get ∘ set a) (sym h)) q)) (get-set-set _ _ _) (get-set-get _) ⟩∎ trans (trans (get-set (set a b) b₀) (sym (get-set a b₀))) (trans (cong (get ∘ set a) (sym h)) (get-set a (get a))) ∎ lemma₂₂ = sym (trans (trans (get-set (set a b) b₀) (sym (get-set a b₀))) (trans (cong (get ∘ set a) (sym h)) (get-set a (get a)))) ≡⟨ trans (sym-trans _ _) $ cong₂ trans (sym-trans _ _) (sym-trans _ _) ⟩ trans (trans (sym (get-set a (get a))) (sym (cong (get ∘ set a) (sym h)))) (trans (sym (sym (get-set a b₀))) (sym (get-set (set a b) b₀))) ≡⟨ cong₂ (λ p q → trans (trans (sym (get-set a (get a))) p) (trans q (sym (get-set (set a b) b₀)))) (trans (cong sym $ cong-sym _ _) $ sym-sym _) (sym-sym _) ⟩ trans (trans (sym (get-set a (get a))) (cong (get ∘ set a) h)) (trans (get-set a b₀) (sym (get-set (set a b) b₀))) ≡⟨ trans (sym $ trans-assoc _ _ _) $ cong (flip trans _) $ trans-assoc _ _ _ ⟩∎ trans (trans (sym (get-set a (get a))) (trans (cong (get ∘ set a) h) (get-set a b₀))) (sym (get-set (set a b) b₀)) ∎ lemma₂ = subst (λ a → get a ≡ b₀) (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))) (get-set (set a b) b₀) ≡⟨ subst-∘ _ _ _ ⟩ subst (_≡ b₀) (cong get (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a)))) (get-set (set a b) b₀) ≡⟨ subst-trans-sym ⟩ trans (sym (cong get (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))))) (get-set (set a b) b₀) ≡⟨ cong (flip (trans ∘ sym) _) lemma₂₁ ⟩ trans (sym (trans (trans (get-set (set a b) b₀) (sym (get-set a b₀))) (trans (cong (get ∘ set a) (sym h)) (get-set a (get a))))) (get-set (set a b) b₀) ≡⟨ cong (flip trans _) lemma₂₂ ⟩ trans (trans (trans (sym (get-set a (get a))) (trans (cong (get ∘ set a) h) (get-set a b₀))) (sym (get-set (set a b) b₀))) (get-set (set a b) b₀) ≡⟨ trans-[trans-sym]- _ _ ⟩ trans (sym (get-set a (get a))) (trans (cong (get ∘ set a) h) (get-set a b₀)) ≡⟨ cong (λ f → trans (sym (f (get a))) (trans (cong (get ∘ set a) h) (f b₀))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) (get-set a) ⟩ trans (sym (ext⁻¹ (⟨ext⟩ (get-set a)) (get a))) (trans (cong (get ∘ set a) h) (ext⁻¹ (⟨ext⟩ (get-set a)) b₀)) ≡⟨ elim₁ (λ {f} eq → trans (sym (ext⁻¹ eq (get a))) (trans (cong f h) (ext⁻¹ eq b₀)) ≡ h) ( trans (sym (ext⁻¹ (refl id) (get a))) (trans (cong id h) (ext⁻¹ (refl id) b₀)) ≡⟨ cong₂ (λ p q → trans p (trans (cong id h) q)) (trans (cong sym (ext⁻¹-refl _)) sym-refl) (ext⁻¹-refl _) ⟩ trans (refl _) (trans (cong id h) (refl _)) ≡⟨ trans-reflˡ _ ⟩ trans (cong id h) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong id h ≡⟨ sym $ cong-id _ ⟩∎ h ∎) _ ⟩∎ h ∎ in ((set (set a b) b₀ , get-set (set a b) b₀) , get (set a b)) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ lemma₂) (get-set a b) ⟩∎ ((a , h ) , b ) ∎) (λ a → set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎) where open Coherent-lens l ------------------------------------------------------------------------ -- A conversion function -- If A is a set, then Lens A B is equivalent to Coherent-lens A B. ≃coherent : Is-set A → Lens A B ≃ Coherent-lens A B ≃coherent {A = A} {B = B} A-set = Eq.↔→≃ to Coherent-lens.lens (λ l → let l′ = Coherent-lens.lens l in $⟨ ×-closure 1 (Π-closure ext 1 λ a → mono₁ 2 (B-set l′ a)) (Π-closure ext 1 λ a → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → mono₁ 2 (B-set l′ a)) ⟩ Is-proposition _ ↝⟨ (λ p → cong (l′ ,_) (p _ _)) ⦂ (_ → _) ⟩ (l′ , _) ≡ (l′ , _) ↔⟨ Eq.≃-≡ Coherent-lens-as-Σ ⟩□ to l′ ≡ l □) refl where B-set : Lens A B → A → Is-set B B-set l a = h-level-respects-lens-from-inhabited 2 l a A-set to : Lens A B → Coherent-lens A B to l = record { lens = l ; get-set-get = λ a → B-set l a _ _ ; get-set-set = λ a _ _ → B-set l a _ _ } -- The conversion preserves getters and setters. ≃coherent-preserves-getters-and-setters : {A : Type a} (s : Is-set A) → Preserves-getters-and-setters-⇔ A B (_≃_.logical-equivalence (≃coherent s)) ≃coherent-preserves-getters-and-setters _ = (λ _ → refl _ , refl _) , (λ _ → refl _ , refl _) ------------------------------------------------------------------------ -- Some existence results -- There is, in general, no lens for the first projection from a -- Σ-type. no-first-projection-lens : ¬ Lens (∃ λ (b : Bool) → b ≡ true) Bool no-first-projection-lens = Non-dependent.no-first-projection-lens Lens contractible-to-contractible -- A variant of the previous result: If A is merely inhabited, and one -- can "project" out a boolean from a value of type A, but this -- boolean is necessarily true, then there is no lens corresponding to -- this projection. no-singleton-projection-lens : ∥ A ∥ → (bool : A → Bool) → (∀ x → bool x ≡ true) → ¬ ∃ λ (l : Lens A Bool) → ∀ x → Lens.get l x ≡ bool x no-singleton-projection-lens = Non-dependent.no-singleton-projection-lens _ _ Lens.get-set -- There are two lenses with equal setters that are not equal -- (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.not-refl≢refl.) equal-setters-but-not-equal : Univalence lzero → ∃ λ (A : Type) → ∃ λ (B : Type) → ∃ λ (l₁ : Lens A B) → ∃ λ (l₂ : Lens A B) → Lens.set l₁ ≡ Lens.set l₂ × l₁ ≢ l₂ equal-setters-but-not-equal _ = 𝕊¹ , ⊤ , l₁′ , l₂′ , refl _ , l₁′≢l₂′ where open Lens lemma : Lens 𝕊¹ ⊤ ≃ ((x : 𝕊¹) → x ≡ x) lemma = Lens 𝕊¹ ⊤ ↔⟨ lens-to-proposition↔ (mono₁ 0 ⊤-contractible) ⟩ (𝕊¹ → ⊤) × ((x : 𝕊¹) → x ≡ x) ↔⟨ (drop-⊤-left-× λ _ → →-right-zero) ⟩□ ((x : 𝕊¹) → x ≡ x) □ l₁′ : Lens 𝕊¹ ⊤ l₁′ = _≃_.from lemma Circle.not-refl l₂′ : Lens 𝕊¹ ⊤ l₂′ = _≃_.from lemma refl set-l₁′≡set-l₂′ : set l₁′ ≡ set l₂′ set-l₁′≡set-l₂′ = refl _ l₁′≢l₂′ : l₁′ ≢ l₂′ l₁′≢l₂′ = l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (inverse lemma) {x = Circle.not-refl} {y = refl} ⟩ Circle.not-refl ≡ refl ↝⟨ Circle.not-refl≢refl ⟩□ ⊥ □ -- A lens which is used in some counterexamples below. bad : (a : Level) → Lens (↑ a 𝕊¹) (↑ a 𝕊¹) bad a = record { get = id ; set = const id ; get-set = λ _ → cong lift ∘ Circle.not-refl ∘ lower ; set-get = refl ; set-set = λ _ _ → cong lift ∘ Circle.not-refl ∘ lower } -- The lens bad a has a getter which is an equivalence, but it does -- not satisfy either of the coherence laws that Coherent-lens lenses -- must satisfy (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.not-refl≢refl.) getter-equivalence-but-not-coherent : Univalence lzero → let open Lens (bad a) in Is-equivalence get × ¬ (∀ a → cong get (set-get a) ≡ get-set a (get a)) × ¬ (∀ a₁ a₂ a₃ → cong get (set-set a₁ a₂ a₃) ≡ trans (get-set (set a₁ a₂) a₃) (sym (get-set a₁ a₃))) getter-equivalence-but-not-coherent {a = a} _ = _≃_.is-equivalence F.id , (((x : ↑ a 𝕊¹) → cong get (set-get x) ≡ get-set x (get x)) ↔⟨⟩ ((x : ↑ a 𝕊¹) → cong id (refl _) ≡ cong lift (Circle.not-refl (lower x))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ → Eq.id) ⟩ ((x : 𝕊¹) → cong id (refl _) ≡ cong lift (Circle.not-refl x)) ↝⟨ trans (trans (cong-refl _) (cong-id _)) ∘_ ⟩ ((x : 𝕊¹) → cong lift (refl x) ≡ cong lift (Circle.not-refl x)) ↔⟨ (∀-cong ext λ _ → Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩ ((x : 𝕊¹) → refl x ≡ Circle.not-refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩ refl ≡ Circle.not-refl ↝⟨ Circle.not-refl≢refl ∘ sym ⟩□ ⊥ □) , (((x y z : ↑ a 𝕊¹) → cong get (set-set x y z) ≡ trans (get-set (set x y) z) (sym (get-set x z))) ↔⟨⟩ ((x y z : ↑ a 𝕊¹) → cong id (cong lift (Circle.not-refl (lower z))) ≡ trans (cong lift (Circle.not-refl (lower z))) (sym (cong lift (Circle.not-refl (lower z))))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ → Π-cong ext Bij.↑↔ λ _ → Π-cong ext Bij.↑↔ λ _ → Eq.id) ⟩ ((x y z : 𝕊¹) → cong id (cong lift (Circle.not-refl z)) ≡ trans (cong lift (Circle.not-refl z)) (sym (cong lift (Circle.not-refl z)))) ↝⟨ (λ hyp → hyp Circle.base Circle.base) ⟩ ((x : 𝕊¹) → cong id (cong lift (Circle.not-refl x)) ≡ trans (cong lift (Circle.not-refl x)) (sym (cong lift (Circle.not-refl x)))) ↔⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong₂ _≡_ (sym $ cong-id _) (trans (trans-symʳ _) $ sym $ cong-refl _)) ⟩ ((x : 𝕊¹) → cong lift (Circle.not-refl x) ≡ cong lift (refl x)) ↔⟨ (∀-cong ext λ _ → Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩ ((x : 𝕊¹) → Circle.not-refl x ≡ refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩ Circle.not-refl ≡ refl ↝⟨ Circle.not-refl≢refl ⟩□ ⊥ □) where open Lens (bad a)
45.132733
146
0.350079
0bde5aa2155ff924acd6b3f1e5d59974c6af5189
4,911
agda
Agda
H-1.agda
andmkent/misc-HoTT
b05c58ffdaed99932ca2acc632deca8d14742b04
[ "MIT" ]
1
2016-01-26T18:17:16.000Z
2016-01-26T18:17:16.000Z
H-1.agda
andmkent/misc-HoTT
b05c58ffdaed99932ca2acc632deca8d14742b04
[ "MIT" ]
null
null
null
H-1.agda
andmkent/misc-HoTT
b05c58ffdaed99932ca2acc632deca8d14742b04
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} module H where open import Data.Product using (_×_; _,_) import Relation.Binary.Core as C import Relation.Binary.PropositionalEquality as P open P.≡-Reasoning ------------------------------------------------------------------------------ -- Some abbreviations and lemmas about paths infix 4 _≡_ _≡_ : ∀ {ℓ} {A : Set ℓ} → (x y : A) → Set ℓ _≡_ {ℓ} {A} x y = C._≡_ {ℓ} {A} x y refl : ∀ {ℓ} {A} → (x : A) → x ≡ x refl {ℓ} {A} x = C.refl {ℓ} {A} {x} infixr 8 _•_ _•_ : ∀ {ℓ} {A : Set ℓ} {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) _•_ = P.trans unitTransR : ∀ {ℓ} {A : Set ℓ} {x y : A} → (p : x ≡ y) → (p ≡ p • refl y) unitTransR {x = x} C.refl = refl (refl x) unitTransL : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ refl x • p) unitTransL {x = x} C.refl = refl (refl x) -- ap, transport, apd at level 1 ap : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {B : Set ℓ₂} → (f : A → B) → {x y : A} → (x ≡ y) → (f x ≡ f y) ap = P.cong transport : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} (B : A → Set ℓ₂) → {x y : A} → (x ≡ y) → B x → B y transport = P.subst -- binary version transport₂ : ∀ {ℓ₁ ℓ₂ ℓ₃} {A : Set ℓ₁} {B : Set ℓ₂} (P : A → B → Set ℓ₃) → {x₁ x₂ : A} {y₁ y₂ : B} → (x₁ ≡ x₂) → (y₁ ≡ y₂) → P x₁ y₁ → P x₂ y₂ transport₂ = P.subst₂ apd : ∀ {ℓ₁ ℓ₂} → {A : Set ℓ₁} {B : A → Set ℓ₂} → (f : (x : A) → B x) → {x y : A} → (p : x ≡ y) → transport B p (f x) ≡ f y apd f C.refl = C.refl -- ap, transport, apd at level 2 ap² : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {B : Set ℓ₂} → (f : A → B) → {x y : A} {p q : x ≡ y} → (r : p ≡ q) → (ap f p ≡ ap f q) ap² f C.refl = C.refl transport² : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} (P : A → Set ℓ₂) → {x y : A} {p q : x ≡ y} → (r : p ≡ q) → (u : P x) → (transport P p u ≡ transport P q u) transport² P {p = C.refl} C.refl u = refl u apd² : ∀ {ℓ₁ ℓ₂} → {A : Set ℓ₁} {B : A → Set ℓ₂} → (f : (x : A) → B x) → {x y : A} {p q : x ≡ y} → (r : p ≡ q) → apd f p ≡ (transport² B r (f x)) • (apd f q) apd² f {p = C.refl} C.refl = C.refl ------------------------------------------------------------------------------ -- Some higher-inductive types from Ch. 6 module S¹ where postulate S¹ : Set base : S¹ loop : base ≡ base record rec (B : Set) (b : B) (p : b ≡ b) : Set₁ where field f : S¹ → B α : f base ≡ b β : transport (λ x → x ≡ x) α (ap f loop) ≡ p record ind (P : S¹ → Set) (b : P base) (p : transport P loop b ≡ b) : Set₁ where field f : (x : S¹) → P x α : f base ≡ b β : transport (λ x → transport P loop x ≡ x) α (apd f loop) ≡ p ------------------------------------------------------------------------------ -- Interval module I where postulate I : Set 𝟘 : I 𝟙 : I seg : 𝟘 ≡ 𝟙 record rec (B : Set) (b₀ b₁ : B) (s : b₀ ≡ b₁) : Set₁ where postulate f : I → B α₀ : f 𝟘 ≡ b₀ α₁ : f 𝟙 ≡ b₁ β : transport₂ (λ x y → x ≡ y) α₀ α₁ (ap f seg) ≡ s record ind (P : I → Set) (b₀ : P 𝟘) (b₁ : P 𝟙) (s : transport P seg b₀ ≡ b₁) : Set₁ where postulate f : (x : I) → P x α₀ : f 𝟘 ≡ b₀ α₁ : f 𝟙 ≡ b₁ β : transport₂ (λ x y → transport P seg x ≡ y) α₀ α₁ (apd f seg) ≡ s ------------------------------------------------------------------------------ -- S² module S² where postulate S² : Set base : S² surf : refl base ≡ refl base record rec (B : Set) (b : B) (s : refl b ≡ refl b) : Set₁ where postulate f : S² → B α : f base ≡ b β : transport (λ p → refl p ≡ refl p) α (ap² f surf) ≡ s record ind (P : S² → Set) (b : P base) (s : refl b ≡ transport² P surf b • (refl b)) : Set₁ where postulate f : (x : S²) → P x α : f base ≡ b β : transport (λ p → refl p ≡ transport² P surf p • refl p) α (apd² f surf) ≡ s ------------------------------------------------------------------------------ -- Suspensions module Susp (A : Set) where postulate Σ : Set → Set₁ N : Σ A S : Σ A merid : A → (N ≡ S) ------------------------------------------------------------------------------ -- Torus module T² where postulate T² : Set b : T² p : b ≡ b q : b ≡ b t : p • q ≡ q • p ------------------------------------------------------------------------------ -- Torus (alternative definition) module T²' where open S¹ T² : Set T² = S¹ × S¹ ------------------------------------------------------------------------------ -- Torus (second alternative definition) module T²'' where open S¹ postulate T² : Set b : T² p : b ≡ b q : b ≡ b h : T² f : S¹ → T² fb : f base ≡ b floop : transport (λ x → x ≡ x) fb (ap f loop) ≡ p • q • P.sym p • P.sym q s : (x : S¹) → f x ≡ h ------------------------------------------------------------------------------
25.056122
82
0.396864
58691d885d629df38aa77259a1cefac7645c32fe
861
agda
Agda
Definition/Typed/Consequences/SucCong.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/SucCong.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/SucCong.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Definition.Typed.Consequences.SucCong where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Weakening open import Definition.Typed.Properties open import Definition.Typed.Consequences.Syntactic open import Definition.Typed.Consequences.Substitution open import Tools.Product -- Congruence of the type of the successor case in natrec. sucCong : ∀ {F G Γ} → Γ ∙ ℕ ⊢ F ≡ G → Γ ⊢ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) ≡ Π ℕ ▹ (G ▹▹ G [ suc (var 0) ]↑) sucCong F≡G with wfEq F≡G sucCong F≡G | ⊢Γ ∙ ⊢ℕ = let ⊢F , _ = syntacticEq F≡G in Π-cong ⊢ℕ (refl ⊢ℕ) (Π-cong ⊢F F≡G (wkEq (step id) (⊢Γ ∙ ⊢ℕ ∙ ⊢F) (subst↑TypeEq F≡G (refl (sucⱼ (var (⊢Γ ∙ ⊢ℕ) here))))))
31.888889
78
0.576074
3d0bd547dc1c967a8677d49ad7d35259918f8b01
86
agda
Agda
nats.agda
andorp/plfa.github.io
5468837f55cbea38d5c5a163e1ea5d48edb92bcc
[ "CC-BY-4.0" ]
null
null
null
nats.agda
andorp/plfa.github.io
5468837f55cbea38d5c5a163e1ea5d48edb92bcc
[ "CC-BY-4.0" ]
null
null
null
nats.agda
andorp/plfa.github.io
5468837f55cbea38d5c5a163e1ea5d48edb92bcc
[ "CC-BY-4.0" ]
null
null
null
open import Data.Nat {- This is a test line ∀ , yeah it works ≡ -} ten : ℕ ten = 10
12.285714
45
0.604651
068b7a28e7b20c37d5f22751325147ee6dd59141
2,566
agda
Agda
Cubical/Codata/M/AsLimit/itree.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Codata/M/AsLimit/itree.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
Cubical/Codata/M/AsLimit/itree.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --guardedness --safe #-} module Cubical.Codata.M.AsLimit.itree where open import Cubical.Data.Unit open import Cubical.Data.Prod open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ ) open import Cubical.Data.Sum open import Cubical.Data.Empty open import Cubical.Data.Bool open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Codata.M.AsLimit.Container open import Cubical.Codata.M.AsLimit.M open import Cubical.Codata.M.AsLimit.Coalg -- Delay monad defined as an M-type delay-S : (R : Type₀) -> Container ℓ-zero delay-S R = (Unit ⊎ R) , λ { (inr _) -> ⊥ ; (inl tt) -> Unit } delay : (R : Type₀) -> Type₀ delay R = M (delay-S R) delay-ret : {R : Type₀} -> R -> delay R delay-ret r = in-fun (inr r , λ ()) delay-tau : {R : Type₀} -> delay R -> delay R delay-tau S = in-fun (inl tt , λ x → S) -- Bottom element raised data ⊥₁ : Type₁ where -- TREES tree-S : (E : Type₀ -> Type₁) (R : Type₀) -> Container (ℓ-suc ℓ-zero) tree-S E R = (R ⊎ (Σ[ A ∈ Type₀ ] (E A))) , (λ { (inl _) -> ⊥₁ ; (inr (A , e)) -> Lift A } ) tree : (E : Type₀ -> Type₁) (R : Type₀) -> Type₁ tree E R = M (tree-S E R) tree-ret : ∀ {E} {R} -> R -> tree E R tree-ret {E} {R} r = in-fun (inl r , λ ()) tree-vis : ∀ {E} {R} -> ∀ {A} -> E A -> (A -> tree E R) -> tree E R tree-vis {A = A} e k = in-fun (inr (A , e) , λ { (lift x) -> k x } ) -- ITrees (and buildup examples) -- https://arxiv.org/pdf/1906.00046.pdf -- Interaction Trees: Representing Recursive and Impure Programs in Coq -- Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, Steve Zdancewic itree-S : ∀ (E : Type₀ -> Type₁) (R : Type₀) -> Container (ℓ-suc ℓ-zero) itree-S E R = ((Unit ⊎ R) ⊎ (Σ[ A ∈ Type₀ ] (E A))) , (λ { (inl (inl _)) -> Lift Unit ; (inl (inr _)) -> ⊥₁ ; (inr (A , e)) -> Lift A } ) itree : ∀ (E : Type₀ -> Type₁) (R : Type₀) -> Type₁ itree E R = M (itree-S E R) ret' : ∀ {E} {R} -> R -> P₀ (itree-S E R) (itree E R) ret' {E} {R} r = inl (inr r) , λ () tau' : {E : Type₀ -> Type₁} -> {R : Type₀} -> itree E R -> P₀ (itree-S E R) (itree E R) tau' t = inl (inl tt) , λ x → t vis' : ∀ {E} {R} -> ∀ {A : Type₀} -> E A -> (A -> itree E R) -> P₀ (itree-S E R) (itree E R) vis' {A = A} e k = inr (A , e) , λ { (lift x) -> k x } ret : ∀ {E} {R} -> R -> itree E R ret = in-fun ∘ ret' tau : {E : Type₀ -> Type₁} -> {R : Type₀} -> itree E R -> itree E R tau = in-fun ∘ tau' vis : ∀ {E} {R} -> ∀ {A : Type₀} -> E A -> (A -> itree E R) -> itree E R vis {A = A} e = in-fun ∘ (vis' {A = A} e)
33.763158
137
0.564302
fb8a343eb0371e1ec0191932f90a9a50a5f14be5
4,888
agda
Agda
Cubical/Algebra/AbGroup/Instances/Hom.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Algebra/AbGroup/Instances/Hom.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Algebra/AbGroup/Instances/Hom.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
-- Given two abelian groups A, B -- the set of all group homomorphisms from A to B -- is itself an abelian group. -- In other words, Ab is cartesian closed. -- This is needed to show Ab is an abelian category. {-# OPTIONS --safe #-} module Cubical.Algebra.AbGroup.Instances.Hom where open import Cubical.Algebra.AbGroup.Base open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Properties open import Cubical.Foundations.Prelude private variable ℓ ℓ' : Level module _ (A : AbGroup ℓ) (B : AbGroup ℓ') where -- These names are useful for the proofs private open IsGroupHom open AbGroupStr (A .snd) using () renaming (0g to 0A; _+_ to _⋆_; -_ to inv) open AbGroupStr (B .snd) using (_+_; -_; comm; assoc; identity; inverse) renaming (0g to 0B) open GroupTheory (AbGroup→Group B) using (invDistr) renaming (inv1g to inv0B) -- Some lemmas idrB : (b : B .fst) → b + 0B ≡ b idrB b = identity b .fst invrB : (b : B .fst) → b + (- b) ≡ 0B invrB b = inverse b .fst hom0AB : (f : AbGroupHom A B) → f .fst 0A ≡ 0B hom0AB f = hom1g (AbGroupStr→GroupStr (A .snd)) (f .fst) (AbGroupStr→GroupStr (B .snd)) (f .snd .pres·) homInvAB : (f : AbGroupHom A B) → (a : A .fst) → f .fst (inv a) ≡ (- f .fst a) homInvAB f a = homInv (AbGroupStr→GroupStr (A .snd)) (f .fst) (AbGroupStr→GroupStr (B .snd)) (f .snd .pres·) a -- Zero morphism zero : AbGroupHom A B zero .fst a = 0B zero .snd .pres· a a' = sym (idrB _) zero .snd .pres1 = refl zero .snd .presinv a = sym (inv0B) -- Pointwise addition of morphisms module _ (f* g* : AbGroupHom A B) where private f = f* .fst g = g* .fst HomAdd : AbGroupHom A B HomAdd .fst = λ a → f a + g a HomAdd .snd .pres· a a' = f (a ⋆ a') + g (a ⋆ a') ≡⟨ cong (_+ g(a ⋆ a')) (f* .snd .pres· _ _) ⟩ (f a + f a') + g (a ⋆ a') ≡⟨ cong ((f a + f a') +_) (g* .snd .pres· _ _) ⟩ (f a + f a') + (g a + g a') ≡⟨ sym (assoc _ _ _) ⟩ f a + (f a' + (g a + g a')) ≡⟨ cong (f a +_) (assoc _ _ _) ⟩ f a + ((f a' + g a) + g a') ≡⟨ cong (λ b → (f a + b + g a')) (comm _ _) ⟩ f a + ((g a + f a') + g a') ≡⟨ cong (f a +_) (sym (assoc _ _ _)) ⟩ f a + (g a + (f a' + g a')) ≡⟨ assoc _ _ _ ⟩ (f a + g a) + (f a' + g a') ∎ HomAdd .snd .pres1 = f 0A + g 0A ≡⟨ cong (_+ g 0A) (hom0AB f*) ⟩ 0B + g 0A ≡⟨ cong (0B +_) (hom0AB g*) ⟩ 0B + 0B ≡⟨ idrB _ ⟩ 0B ∎ HomAdd .snd .presinv a = f (inv a) + g (inv a) ≡⟨ cong (_+ g (inv a)) (homInvAB f* _) ⟩ (- f a) + g (inv a) ≡⟨ cong ((- f a) +_) (homInvAB g* _) ⟩ (- f a) + (- g a) ≡⟨ comm _ _ ⟩ (- g a) + (- f a) ≡⟨ sym (invDistr _ _) ⟩ - (f a + g a) ∎ -- Pointwise inverse of morphism module _ (f* : AbGroupHom A B) where private f = f* .fst HomInv : AbGroupHom A B HomInv .fst = λ a → - f a HomInv .snd .pres· a a' = - f (a ⋆ a') ≡⟨ cong -_ (f* .snd .pres· _ _) ⟩ - (f a + f a') ≡⟨ invDistr _ _ ⟩ (- f a') + (- f a) ≡⟨ comm _ _ ⟩ (- f a) + (- f a') ∎ HomInv .snd .pres1 = - (f 0A) ≡⟨ cong -_ (f* .snd .pres1) ⟩ - 0B ≡⟨ inv0B ⟩ 0B ∎ HomInv .snd .presinv a = - f (inv a) ≡⟨ cong -_ (homInvAB f* _) ⟩ - (- f a) ∎ -- Group laws for morphisms private 0ₕ = zero _+ₕ_ = HomAdd -ₕ_ = HomInv -- Morphism addition is associative HomAdd-assoc : (f g h : AbGroupHom A B) → (f +ₕ (g +ₕ h)) ≡ ((f +ₕ g) +ₕ h) HomAdd-assoc f g h = GroupHom≡ (funExt λ a → assoc _ _ _) -- Morphism addition is commutative HomAdd-comm : (f g : AbGroupHom A B) → (f +ₕ g) ≡ (g +ₕ f) HomAdd-comm f g = GroupHom≡ (funExt λ a → comm _ _) -- zero is right identity HomAdd-zero : (f : AbGroupHom A B) → (f +ₕ zero) ≡ f HomAdd-zero f = GroupHom≡ (funExt λ a → idrB _) -- -ₕ is right inverse HomInv-invr : (f : AbGroupHom A B) → (f +ₕ (-ₕ f)) ≡ zero HomInv-invr f = GroupHom≡ (funExt λ a → invrB _) -- Abelian group structure on AbGroupHom A B open AbGroupStr HomAbGroupStr : (A : AbGroup ℓ) → (B : AbGroup ℓ') → AbGroupStr (AbGroupHom A B) HomAbGroupStr A B .0g = zero A B HomAbGroupStr A B ._+_ = HomAdd A B HomAbGroupStr A B .-_ = HomInv A B HomAbGroupStr A B .isAbGroup = makeIsAbGroup isSetGroupHom (HomAdd-assoc A B) (HomAdd-zero A B) (HomInv-invr A B) (HomAdd-comm A B) HomAbGroup : (A : AbGroup ℓ) → (B : AbGroup ℓ') → AbGroup (ℓ-max ℓ ℓ') HomAbGroup A B = AbGroupHom A B , HomAbGroupStr A B
33.479452
90
0.511866
4104d1a20e5608266e4c10ffe20d67d93458333c
6,380
agda
Agda
src/Categories/Morphism/Lifts/Properties.agda
Trebor-Huang/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
5
2019-05-21T17:07:19.000Z
2019-05-22T03:54:24.000Z
src/Categories/Morphism/Lifts/Properties.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
null
null
null
src/Categories/Morphism/Lifts/Properties.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Morphism.Lifts.Properties {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Data.Product using (_,_; proj₁; proj₂) open import Categories.Category.Construction.Arrow 𝒞 open import Categories.Diagram.Pullback 𝒞 open import Categories.Diagram.Pushout 𝒞 open import Categories.Morphism.Lifts 𝒞 open import Categories.Morphism.Reasoning 𝒞 renaming (glue to glue-■) import Categories.Morphism as Mor open Category 𝒞 open Definitions 𝒞 open HomReasoning -- We want to talk about retracts of morphisms, so -- we don't use the definition of 'Retract' applied to '𝒞' open Mor 𝒞 hiding (Retract) open Mor using (Retract) open Morphism⇒ -------------------------------------------------------------------------------- -- Lifting and Retractions module _ {X Y T} {f : X ⇒ Y} {i : X ⇒ T} {p : T ⇒ Y} (factors : f ≈ p ∘ i) where -- If 'f' factors into 'p ∘ i' and 'f' has the left lifting property -- with respect to 'p', then 'f' is a retraction of 'i' in the arrow -- category of 𝒞. retract-liftˡ : Lifts f p → Retract Arrow (mor f) (mor i) retract-liftˡ lifts = record { section = mor⇒ (fill-commˡ ○ ⟺ identityʳ) ; retract = mor⇒ (⟺ factors ○ ⟺ identityʳ) ; is-retract = identity² , fill-commʳ } where open Filler (lifts (identityˡ ○ factors)) -- We have an analogous situation for right lifts. retract-liftʳ : Lifts i f → Retract Arrow (mor f) (mor p) retract-liftʳ lifts = record { section = mor⇒ (identityˡ ○ factors) ; retract = mor⇒ (identityˡ ○ ⟺ fill-commʳ) ; is-retract = fill-commˡ , identity² } where open Filler (lifts (⟺ factors ○ ⟺ identityʳ)) -------------------------------------------------------------------------------- -- Closure Properties of Injective and Projective morphisms. module _ {j} (J : MorphismClass j) where private variable X Y Z : Obj f g h i p : X ⇒ Y -- If 'f' is an isomorphism, then it must be J-Projective. iso-proj : ∀ {X Y} (f : X ⇒ Y) → IsIso f → Proj J f iso-proj f f-iso g g∈J {h} {i} comm = record { filler = h ∘ inv ; fill-commˡ = cancelʳ isoˡ ; fill-commʳ = extendʳ (⟺ comm) ○ elimʳ isoʳ } where open IsIso f-iso -- Dually, If 'f' is an isomorphism, then it must be J-Injective. iso-inj : ∀ {X Y} (f : X ⇒ Y) → IsIso f → Inj J f iso-inj f f-iso g g∈J {h} {i} comm = record { filler = inv ∘ i ; fill-commˡ = extendˡ comm ○ elimˡ isoˡ ; fill-commʳ = cancelˡ isoʳ } where open IsIso f-iso -- J-Projective morphisms are closed under composition. proj-∘ : ∀ {X Y Z} {f : Y ⇒ Z} {g : X ⇒ Y} → Proj J f → Proj J g → Proj J (f ∘ g) proj-∘ {f = f} {g = g} f-proj g-proj h h∈J {k} {i} comm = record { filler = UpperFiller.filler ; fill-commˡ = begin UpperFiller.filler ∘ f ∘ g ≈⟨ pullˡ UpperFiller.fill-commˡ ⟩ LowerFiller.filler ∘ g ≈⟨ LowerFiller.fill-commˡ ⟩ k ∎ ; fill-commʳ = UpperFiller.fill-commʳ } where module LowerFiller = Filler (g-proj h h∈J (assoc ○ comm)) module UpperFiller = Filler (f-proj h h∈J (⟺ LowerFiller.fill-commʳ)) -- J-Injective morphisms are closed under composition. inj-∘ : ∀ {X Y Z} {f : Y ⇒ Z} {g : X ⇒ Y} → Inj J f → Inj J g → Inj J (f ∘ g) inj-∘ {f = f} {g = g} f-inj g-inj h h∈J {k} {i} comm = record { filler = LowerFiller.filler ; fill-commˡ = LowerFiller.fill-commˡ ; fill-commʳ = begin (f ∘ g) ∘ LowerFiller.filler ≈⟨ pullʳ LowerFiller.fill-commʳ ⟩ f ∘ UpperFiller.filler ≈⟨ UpperFiller.fill-commʳ ⟩ i ∎ } where module UpperFiller = Filler (f-inj h h∈J (comm ○ assoc)) module LowerFiller = Filler (g-inj h h∈J UpperFiller.fill-commˡ) -- J-Projective morphisms are stable under pushout. proj-pushout : ∀ {X Y Z} {p : X ⇒ Y} {f : X ⇒ Z} → (P : Pushout p f) → Proj J p → Proj J (Pushout.i₂ P) proj-pushout {p = p} {f = f} po p-proj h h∈J sq = record { filler = universal fill-commˡ ; fill-commˡ = universal∘i₂≈h₂ ; fill-commʳ = unique-diagram (pullʳ universal∘i₁≈h₁ ○ fill-commʳ) (pullʳ universal∘i₂≈h₂ ○ ⟺ sq) } where open Pushout po open Filler (p-proj h h∈J (glue-■ sq commute)) -- J-Injective morphisms are stable under pullback. inj-pullback : ∀ {X Y Z} {i : X ⇒ Z} {f : Y ⇒ Z} → (P : Pullback i f) → Inj J i → Inj J (Pullback.p₂ P) inj-pullback {i = i} {f = f} pb i-inj h h∈J sq = record { filler = universal fill-commʳ ; fill-commˡ = unique-diagram (pullˡ p₁∘universal≈h₁ ○ fill-commˡ) (pullˡ p₂∘universal≈h₂ ○ sq) ; fill-commʳ = p₂∘universal≈h₂ } where open Pullback pb open Filler (i-inj h h∈J (glue-■ (⟺ commute) sq)) -- J-Projective morphisms are stable under retractions. proj-retract : Proj J p → Retract Arrow (mor f) (mor p) → Proj J f proj-retract {p = p} {f = f} p-proj f-retracts h h∈J {g} {k} sq = record { filler = filler ∘ cod⇒ section ; fill-commˡ = begin (filler ∘ cod⇒ section) ∘ f ≈⟨ extendˡ (square section) ⟩ (filler ∘ p) ∘ dom⇒ section ≈⟨ fill-commˡ ⟩∘⟨refl ⟩ (g ∘ dom⇒ retract) ∘ dom⇒ section ≈⟨ cancelʳ (proj₁ is-retract) ⟩ g ∎ ; fill-commʳ = begin h ∘ filler ∘ cod⇒ section ≈⟨ extendʳ fill-commʳ ⟩ k ∘ (cod⇒ retract ∘ cod⇒ section) ≈⟨ elimʳ (proj₂ is-retract) ⟩ k ∎ } where open Retract f-retracts open Filler (p-proj h h∈J (glue-■ sq (square retract))) -- J-Injective morphisms are stable under retractions. inj-retract : Inj J i → Retract Arrow (mor f) (mor i) → Inj J f inj-retract {i = i} {f = f} i-inj f-retracts h h∈J {g} {k} sq = record { filler = dom⇒ retract ∘ filler ; fill-commˡ = begin (dom⇒ retract ∘ filler) ∘ h ≈⟨ extendˡ fill-commˡ ⟩ (dom⇒ retract ∘ dom⇒ section) ∘ g ≈⟨ elimˡ (proj₁ is-retract) ⟩ g ∎ ; fill-commʳ = begin f ∘ dom⇒ retract ∘ filler ≈⟨ extendʳ (⟺ (square retract)) ⟩ cod⇒ retract ∘ i ∘ filler ≈⟨ refl⟩∘⟨ fill-commʳ ⟩ cod⇒ retract ∘ cod⇒ section ∘ k ≈⟨ cancelˡ (proj₂ is-retract) ⟩ k ∎ } where open Retract f-retracts open Filler (i-inj h h∈J (glue-■ (square section) sq))
33.229167
105
0.578683
399cfc98e1fb7d6606c97cce2dda615980eb271a
10,151
agda
Agda
Cubical/Foundations/Id.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/Foundations/Id.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/Foundations/Id.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
{- This file contains: - Id, refl and J (with definitional computation rule) - Basic theory about Id, proved using J - Lemmas for going back and forth between Path and Id - Function extensionality for Id - fiber, isContr, equiv all defined using Id - The univalence axiom expressed using only Id ([EquivContr]) - Propositional truncation and its elimination principle -} {-# OPTIONS --cubical --safe #-} module Cubical.Foundations.Id where open import Cubical.Foundations.Prelude public hiding ( _≡_ ; _≡⟨_⟩_ ; _∎ ; isPropIsContr) renaming ( refl to reflPath ; transport to transportPath ; J to JPath ; JRefl to JPathRefl ; sym to symPath ; _∙_ to compPath ; cong to congPath ; funExt to funExtPath ; isContr to isContrPath ; isProp to isPropPath ; isSet to isSetPath ; fst to pr₁ -- as in the HoTT book ; snd to pr₂ ) open import Cubical.Core.Glue renaming ( isEquiv to isEquivPath ; _≃_ to EquivPath ; equivFun to equivFunPath ) open import Cubical.Foundations.Equiv renaming ( fiber to fiberPath ; equivIsEquiv to equivIsEquivPath ; equivCtr to equivCtrPath ) hiding ( isPropIsEquiv; equivCtrPath ) open import Cubical.Foundations.Univalence renaming ( EquivContr to EquivContrPath ) open import Cubical.HITs.PropositionalTruncation public renaming ( squash to squashPath ; recPropTrunc to recPropTruncPath ; elimPropTrunc to elimPropTruncPath ) open import Cubical.Core.Id public private variable ℓ ℓ' : Level A : Type ℓ -- Version of the constructor for Id where the y is also -- explicit. This is sometimes useful when it is needed for -- typechecking (see JId below). conId : ∀ {x : A} φ (y : A [ φ ↦ (λ _ → x) ]) (w : (Path _ x (outS y)) [ φ ↦ (λ { (φ = i1) → λ _ → x}) ]) → x ≡ outS y conId φ _ w = ⟨ φ , outS w ⟩ -- Reflexivity refl : ∀ {x : A} → x ≡ x refl {x = x} = ⟨ i1 , (λ _ → x) ⟩ -- Definition of J for Id module _ {x : A} (P : ∀ (y : A) → Id x y → Type ℓ') (d : P x refl) where J : ∀ {y : A} (w : x ≡ y) → P y w J {y = y} = elimId P (λ φ y w → comp (λ i → P _ (conId (φ ∨ ~ i) (inS (outS w i)) (inS (λ j → outS w (i ∧ j))))) (λ i → λ { (φ = i1) → d}) d) {y = y} -- Check that J of refl is the identity function Jdefeq : Path _ (J refl) d Jdefeq _ = d -- Basic theory about Id, proved using J transport : ∀ (B : A → Type ℓ') {x y : A} → x ≡ y → B x → B y transport B {x} p b = J (λ y p → B y) b p _⁻¹ : {x y : A} → x ≡ y → y ≡ x _⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y ap f {x} = J (λ z _ → f x ≡ f z) refl _∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z _∙_ {x = x} p = J (λ y _ → x ≡ y) p infix 4 _∙_ infix 3 _∎ infixr 2 _≡⟨_⟩_ _≡⟨_⟩_ : (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z _ ≡⟨ p ⟩ q = p ∙ q _∎ : (x : A) → x ≡ x _ ∎ = refl -- Convert between Path and Id pathToId : ∀ {x y : A} → Path _ x y → Id x y pathToId {x = x} = JPath (λ y _ → Id x y) refl pathToIdRefl : ∀ {x : A} → Path _ (pathToId (λ _ → x)) refl pathToIdRefl {x = x} = JPathRefl (λ y _ → Id x y) refl idToPath : ∀ {x y : A} → Id x y → Path _ x y idToPath {x = x} = J (λ y _ → Path _ x y) (λ _ → x) idToPathRefl : ∀ {x : A} → Path _ (idToPath {x = x} refl) reflPath idToPathRefl {x = x} _ _ = x pathToIdToPath : ∀ {x y : A} → (p : Path _ x y) → Path _ (idToPath (pathToId p)) p pathToIdToPath {x = x} = JPath (λ y p → Path _ (idToPath (pathToId p)) p) (λ i → idToPath (pathToIdRefl i)) idToPathToId : ∀ {x y : A} → (p : Id x y) → Path _ (pathToId (idToPath p)) p idToPathToId {x = x} = J (λ b p → Path _ (pathToId (idToPath p)) p) pathToIdRefl -- We get function extensionality by going back and forth between Path and Id funExt : ∀ {B : A → Type ℓ'} {f g : (x : A) → B x} → ((x : A) → f x ≡ g x) → f ≡ g funExt p = pathToId (λ i x → idToPath (p x) i) -- Equivalences expressed using Id fiber : ∀ {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ') fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y isContr : Type ℓ → Type ℓ isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y) isProp : Type ℓ → Type ℓ isProp A = (x y : A) → x ≡ y isSet : Type ℓ → Type ℓ isSet A = (x y : A) → isProp (x ≡ y) record isEquiv {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where field equiv-proof : (y : B) → isContr (fiber f y) open isEquiv public infix 4 _≃_ _≃_ : ∀ (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ') A ≃ B = Σ[ f ∈ (A → B) ] (isEquiv f) equivFun : ∀ {B : Type ℓ'} → A ≃ B → A → B equivFun e = pr₁ e equivIsEquiv : ∀ {B : Type ℓ'} (e : A ≃ B) → isEquiv (equivFun e) equivIsEquiv e = pr₂ e equivCtr : ∀ {B : Type ℓ'} (e : A ≃ B) (y : B) → fiber (equivFun e) y equivCtr e y = e .pr₂ .equiv-proof y .pr₁ -- Functions for going between the various definitions. This could -- also be achieved by making lines in the universe and transporting -- back and forth along them. fiberPathToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B} → fiberPath f y → fiber f y fiberPathToFiber (x , p) = (x , pathToId p) fiberToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} → fiber f y → fiberPath f y fiberToFiberPath (x , p) = (x , idToPath p) fiberToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B} (p : fiber f y) → Path _ (fiberPathToFiber (fiberToFiberPath p)) p fiberToFiber (x , p) = λ i → x , idToPathToId p i fiberPathToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} (p : fiberPath f y) → Path _ (fiberToFiberPath (fiberPathToFiber p)) p fiberPathToFiberPath (x , p) = λ i → x , pathToIdToPath p i isContrPathToIsContr : isContrPath A → isContr A isContrPathToIsContr (ctr , p) = (ctr , λ y → pathToId (p y)) isContrToIsContrPath : isContr A → isContrPath A isContrToIsContrPath (ctr , p) = (ctr , λ y → idToPath (p y)) isPropPathToIsProp : isPropPath A → isProp A isPropPathToIsProp H x y = pathToId (H x y) isPropToIsPropPath : isProp A → isPropPath A isPropToIsPropPath H x y i = idToPath (H x y) i -- Specialized helper lemmas for going back and forth between -- isContrPath and isContr: helper1 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A) (h : ∀ y → Path _ (f (g y)) y) → isContrPath A → isContr B helper1 f g h (x , p) = (f x , λ y → pathToId (λ i → hcomp (λ j → λ { (i = i0) → f x ; (i = i1) → h y j }) (f (p (g y) i)))) helper2 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A) (h : ∀ y → Path _ (g (f y)) y) → isContr B → isContrPath A helper2 {A = A} f g h (x , p) = (g x , λ y → idToPath (rem y)) where rem : ∀ (y : A) → g x ≡ y rem y = g x ≡⟨ ap g (p (f y)) ⟩ g (f y) ≡⟨ pathToId (h y) ⟩ y ∎ -- This proof is essentially the one for proving that isContr with -- Path is a proposition, but as we are working with Id we have to -- insert a lof of conversion functions. It is still nice that is -- works like this though. isPropIsContr : ∀ (p1 p2 : isContr A) → Path (isContr A) p1 p2 isPropIsContr (a0 , p0) (a1 , p1) j = ( idToPath (p0 a1) j , hcomp (λ i → λ { (j = i0) → λ x → idToPathToId (p0 x) i ; (j = i1) → λ x → idToPathToId (p1 x) i }) (λ x → pathToId (λ i → hcomp (λ k → λ { (i = i0) → idToPath (p0 a1) j ; (i = i1) → idToPath (p0 x) (j ∨ k) ; (j = i0) → idToPath (p0 x) (i ∧ k) ; (j = i1) → idToPath (p1 x) i }) (idToPath (p0 (idToPath (p1 x) i)) j)))) -- We now prove that isEquiv is a proposition isPropIsEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → {f : A → B} → (h1 h2 : isEquiv f) → Path _ h1 h2 equiv-proof (isPropIsEquiv {f = f} h1 h2 i) y = isPropIsContr {A = fiber f y} (h1 .equiv-proof y) (h2 .equiv-proof y) i -- Go from a Path equivalence to an Id equivalence equivPathToEquiv : ∀ {A : Type ℓ} {B : Type ℓ'} → EquivPath A B → A ≃ B equivPathToEquiv (f , p) = (f , λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (p .equiv-proof y) }) -- Go from an Id equivalence to a Path equivalence equivToEquivPath : ∀ {A : Type ℓ} {B : Type ℓ'} → A ≃ B → EquivPath A B equivToEquivPath (f , p) = (f , λ { .equiv-proof y → helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y) }) equivToEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → (p : A ≃ B) → Path _ (equivPathToEquiv (equivToEquivPath p)) p equivToEquiv (f , p) i = (f , isPropIsEquiv (λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y)) }) p i) -- We can finally prove univalence with Id everywhere from the one for Path EquivContr : ∀ (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] (T ≃ A)) EquivContr A = helper1 f1 f2 f12 (EquivContrPath A) where f1 : ∀ {ℓ} {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (EquivPath T A) → Σ[ T ∈ Type ℓ ] (T ≃ A) f1 (x , p) = x , equivPathToEquiv p f2 : ∀ {ℓ} {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (T ≃ A) → Σ[ T ∈ Type ℓ ] (EquivPath T A) f2 (x , p) = x , equivToEquivPath p f12 : ∀ {ℓ} {A : Type ℓ} → (y : Σ[ T ∈ Type ℓ ] (T ≃ A)) → Path _ (f1 (f2 y)) y f12 (x , p) = λ i → x , equivToEquiv p i -- Propositional truncation ∥∥-isProp : ∀ (x y : ∥ A ∥) → x ≡ y ∥∥-isProp x y = pathToId (squashPath x y) ∥∥-recursion : ∀ {A : Type ℓ} {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P ∥∥-recursion Pprop f x = recPropTruncPath (isPropToIsPropPath Pprop) f x ∥∥-induction : ∀ {A : Type ℓ} {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) → ((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a ∥∥-induction Pprop f x = elimPropTruncPath (λ a → isPropToIsPropPath (Pprop a)) f x
35.369338
136
0.544281
1ddb9166f697a3dc48df4ada1cc77761a36365d2
616
agda
Agda
agda/Categories/Exponential.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Categories/Exponential.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Categories/Exponential.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe #-} module Categories.Exponential where open import Prelude hiding (_×_) open import Categories open import Categories.Product module _ {ℓ₁ ℓ₂} (C : Category ℓ₁ ℓ₂) (hasProducts : HasProducts C) where open Category C open HasProducts hasProducts module _ (Y Z : Ob) where record Exponential : Type (ℓ₁ ℓ⊔ ℓ₂) where field obj : Ob eval : C [ obj × Y , Z ] uniq : ∀ (X : Ob) (f : C [ X × Y , Z ]) → ∃![ f~ ] (C [ eval ∘ (f~ |×| Category.Id C) ] ≡ f) HasExponentials : Type (ℓ₁ ℓ⊔ ℓ₂) HasExponentials = ∀ X Y → Exponential X Y
26.782609
73
0.592532
223fbfdcba334d12f3a82c758436fd12c121b6f2
4,067
agda
Agda
Agda/models.agda
hemangandhi/HoTT-Intro
09c710bf9c31ba88be144cc950bd7bc19c22a934
[ "CC-BY-4.0" ]
333
2018-09-26T08:33:30.000Z
2022-03-22T23:50:15.000Z
Agda/models.agda
hemangandhi/HoTT-Intro
09c710bf9c31ba88be144cc950bd7bc19c22a934
[ "CC-BY-4.0" ]
8
2019-06-18T04:16:04.000Z
2020-10-16T15:27:01.000Z
Agda/models.agda
hemangandhi/HoTT-Intro
09c710bf9c31ba88be144cc950bd7bc19c22a934
[ "CC-BY-4.0" ]
30
2018-09-26T09:08:57.000Z
2022-03-16T00:33:50.000Z
{-# OPTIONS --without-K #-} {- Our goal in this file is to observe some structure possessed by the universes of types, reflexive graphs, type families, and so on. Somewhat more precisely, we develop an imperfect structure of internal model of type theory, with enough ingredients to get some type theoretic developments off the ground. We begin with the basic structure of type dependency, with operations for context extension, weakening, substitution, and identity morphisms (the `variable rule'). Once this structure is implemented, we introduce the structure of usual type constructors Σ, Π, Id, the unit type, and ℕ. The reason this is an `imperfect' notion of model structure is that in our internal model structure, we have identifications in the role of judgmental equalities. This leads to the usual coherence problem, which we do not attempt to solve. As we said before, our goal is merely to postulate enough equalities so that we can introduce and work with the type constructors. We then proceed to develop some examples. -} module models where import Lecture15 open Lecture15 public Contexts : ( l : Level) → UU (lsuc l) Contexts l = UU l Families : { l1 : Level} (l2 : Level) (ctx : Contexts l1) → UU (l1 ⊔ (lsuc l2)) Families l2 ctx = ctx → UU l2 Terms : { l1 l2 : Level} (l3 : Level) ( ctx : Contexts l1) (fam : Families l2 ctx) → UU (l1 ⊔ (l2 ⊔ (lsuc l3))) Terms l3 ctx fam = (Γ : ctx) → (fam Γ) → UU l3 Context-Extensions : { l1 l2 : Level} ( ctx : Contexts l1) (fam : Families l2 ctx) → UU (l1 ⊔ l2) Context-Extensions ctx fam = (Γ : ctx) → (fam Γ) → ctx Family-Extensions : { l1 l2 : Level} ( ctx : Contexts l1) (fam : Families l2 ctx) ( ctx-ext : Context-Extensions ctx fam) → UU (l1 ⊔ l2) Family-Extensions ctx fam ctx-ext = ( Γ : ctx) → (A : fam Γ) → (fam (ctx-ext Γ A)) → fam Γ Model-Base : ( l1 l2 l3 : Level) → UU (lsuc l1 ⊔ (lsuc l2 ⊔ lsuc l3)) Model-Base l1 l2 l3 = Σ ( Contexts l1) ( λ ctx → Σ (Families l2 ctx) ( λ fam → Σ (Terms l3 ctx fam) ( λ tm → Σ (Context-Extensions ctx fam) (Family-Extensions ctx fam)))) Hom-Model-Base : { l1 l2 l3 l1' l2' l3' : Level} → Model-Base l1 l2 l3 → Model-Base l1' l2' l3' → UU _ Hom-Model-Base ( pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) ( pair ctx' (pair fam' (pair tm' (pair ctx-ext' fam-ext')))) = Σ ( ctx → ctx') ( λ h-ctx → Σ ((Γ : ctx) → (fam Γ) → (fam' (h-ctx Γ))) ( λ h-fam → Σ ((Γ : ctx) (A : fam Γ) → (tm Γ A) → tm' (h-ctx Γ) (h-fam Γ A)) ( λ h-tm → Σ ( (Γ : ctx) (A : fam Γ) → Id ( h-ctx (ctx-ext Γ A)) ( ctx-ext' (h-ctx Γ) (h-fam Γ A))) ( λ h-ctx-ext → (Γ : ctx) (A : fam Γ) (B : fam (ctx-ext Γ A)) → Id ( h-fam Γ (fam-ext Γ A B)) ( fam-ext' ( h-ctx Γ) ( h-fam Γ A) ( tr fam' (h-ctx-ext Γ A) (h-fam (ctx-ext Γ A) B))))))) Assoc-Ctx-ext : { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3) → UU (l1 ⊔ l2) Assoc-Ctx-ext (pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) = ( Γ : ctx) (A : fam Γ) (B : fam (ctx-ext Γ A)) → Id (ctx-ext (ctx-ext Γ A) B) (ctx-ext Γ (fam-ext Γ A B)) Slice-Model-Base : { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3) ( assoc : Assoc-Ctx-ext M) → ( Γ : pr1 M) → Model-Base l2 l2 l3 Slice-Model-Base ( pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) assoc Γ = pair (fam Γ) ( pair (λ A → fam (ctx-ext Γ A)) ( pair (λ A B → tm (ctx-ext Γ A) B) ( pair (fam-ext Γ) ( λ A B C → fam-ext (ctx-ext Γ A) B (tr fam (inv (assoc Γ A B)) C))))) Empty-context : { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3) → UU l1 Empty-context M = pr1 M Axiom-Empty-Context : { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3) (empty-ctx : Empty-context M) → UU (l1 ⊔ l2) Axiom-Empty-Context ( pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) empty-ctx = is-equiv (ctx-ext empty-ctx)
36.3125
78
0.583231
4168610b950481075e5bceb030f676d7824678a6
11,400
agda
Agda
TypeTheory/Common/Context.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/Common/Context.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/Common/Context.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
module Common.Context where import Level open import Data.Nat as Nat open import Data.List as List import Level open import Relation.Binary.PropositionalEquality as PE hiding ([_]) open import Relation.Binary -- using (Setoid; Rel; IsEquivalence) open ≡-Reasoning open import Function as Fun hiding (_∘′_) open import Data.Sum as Sum hiding ([_,_]) open import Categories.Category using (Category) open import Common.SumProperties ------------------------- ---- Type contexts Ctx : Set → Set Ctx Ty = List Ty -- | De Bruijn variable indexing data Var {Ty : Set} : (Γ : Ctx Ty) (a : Ty) → Set where zero : ∀{Γ a} → Var (a ∷ Γ) a succ : ∀{Γ b} (a : Ty) → (x : Var Γ a) → Var (b ∷ Γ) a data _≅V_ {Ty} : ∀ {Γ Γ' : Ctx Ty} {a a' : Ty} → Var Γ a → Var Γ' a' → Set where zero : ∀ {Γ Γ'} {a a'} → zero {Γ = Γ} {a} ≅V zero {Γ = Γ'} {a'} succ : ∀ {Γ Γ'} {a a'} → ∀ {x : Var Γ a} {x' : Var Γ' a'} {b b' : Ty} → x ≅V x' → succ {b = b} a x ≅V succ {b = b'} a' x' Vrefl : ∀ {Ty} {Γ} {a : Ty} {x : Var Γ a} → x ≅V x Vrefl {x = zero} = zero Vrefl {x = succ _ t} = succ Vrefl Vsym : ∀ {Ty} {Γ Γ'} {a a' : Ty} {x : Var Γ a} {x' : Var Γ' a'} → x ≅V x' → x' ≅V x Vsym zero = zero Vsym {Ty} (succ [x]) = succ (Vsym [x]) Vtrans : ∀ {Ty} {Γ Γ' Γ''} {a a' a'' : Ty} {x : Var Γ a} {x' : Var Γ' a'} {x'' : Var Γ'' a''} → x ≅V x' → x' ≅V x'' → x ≅V x'' Vtrans zero zero = zero Vtrans (succ eq) (succ eq') = succ (Vtrans eq eq') -- Note: makes the equality homogeneous in Γ and a ≅V-setoid : ∀ {Ty} {Γ} {a : Ty} → Setoid _ _ ≅V-setoid {Ty} {Γ} {a} = record { Carrier = Var Γ a ; _≈_ = _≅V_ ; isEquivalence = record { refl = Vrefl ; sym = Vsym ; trans = Vtrans } } arr : ∀ {Ty} → (Γ Δ : Ctx Ty) → Set arr {Ty} Γ Δ = ∀ (a : Ty) → Var Γ a → Var Δ a _►_ = arr -- _▹_ = arr infix 4 _≡C_ record _≡C_ {Ty} {Γ Δ : Ctx Ty} (ρ : arr Γ Δ) (γ : arr Γ Δ) : Set where field ≡C-proof : ∀ {a} {x} → ρ a x ≡ γ a x open _≡C_ _≈_ = _≡C_ Crefl : ∀ {Ty} {Γ Δ : Ctx Ty} → Reflexive (_≡C_ {Γ = Γ} {Δ}) Crefl = record { ≡C-proof = PE.refl } Csym : ∀ {Ty} {Γ Δ : Ctx Ty} → Symmetric (_≡C_ {Γ = Γ} {Δ}) Csym p = record { ≡C-proof = PE.sym (≡C-proof p) } Ctrans : ∀ {Ty} {Γ Δ : Ctx Ty} → Transitive (_≡C_ {Γ = Γ} {Δ}) Ctrans p₁ p₂ = record { ≡C-proof = PE.trans (≡C-proof p₁) (≡C-proof p₂) } ≡C-equiv : ∀ {Ty} {Γ Δ : Ctx Ty} → IsEquivalence (_≡C_ {Γ = Γ} {Δ}) ≡C-equiv = record { refl = Crefl ; sym = Csym ; trans = Ctrans } ≡C-setoid : ∀ {Ty} {Γ Δ : Ctx Ty} → Setoid _ _ ≡C-setoid {_} {Γ} {Δ} = record { Carrier = arr Γ Δ ; _≈_ = _≡C_ ; isEquivalence = ≡C-equiv } _∘′_ : ∀ {Ty} {Γ Δ Ξ : Ctx Ty} (ρ : Δ ► Ξ) (γ : Γ ► Δ) → Γ ► Ξ _∘′_ ρ γ = λ a x → ρ a (γ a x) _●_ = _∘′_ ctx-id : ∀ {Ty} {Γ : Ctx Ty} → arr Γ Γ ctx-id = λ _ x → x comp-resp-≡C : ∀ {Ty} {Γ Δ Ξ : Ctx Ty} {ρ ρ' : arr Δ Ξ} {γ γ' : arr Γ Δ} → ρ ≡C ρ' → γ ≡C γ' → ρ ∘′ γ ≡C ρ' ∘′ γ' comp-resp-≡C {_} {Γ} {Δ} {Ξ} {ρ} {ρ'} {γ} {γ'} ρ≡ρ' γ≡γ' = record { ≡C-proof = p } where p : ∀ {a} {x} → (ρ ∘′ γ) a x ≡ (ρ' ∘′ γ') a x p {a} {x} = begin (ρ ∘′ γ) a x ≡⟨ refl ⟩ ρ a (γ a x) ≡⟨ cong (λ u → ρ a u) (≡C-proof γ≡γ') ⟩ ρ a (γ' a x) ≡⟨ ≡C-proof ρ≡ρ' ⟩ ρ' a (γ' a x) ≡⟨ refl ⟩ (ρ' ∘′ γ') a x ∎ -- | Contexts form a category ctx-cat : Set → Category Level.zero Level.zero Level.zero ctx-cat Ty = record { Obj = Ctx Ty ; _⇒_ = arr ; _≡_ = _≡C_ ; _∘_ = _∘′_ ; id = ctx-id ; assoc = record { ≡C-proof = refl } ; identityˡ = record { ≡C-proof = refl } ; identityʳ = record { ≡C-proof = refl } ; equiv = ≡C-equiv ; ∘-resp-≡ = comp-resp-≡C } ------------------------- ---- Coproduct structure on contexts {- _⊕_ : Ctx → Ctx → Ctx Γ₁ ⊕ Γ₂ = Γ₁ ++ Γ₂ in₁ : {Γ₁ Γ₂ : Ctx} → Γ₁ ▹ (Γ₁ ⊕ Γ₂) in₁ _ zero = zero in₁ a (succ .a x) = succ a (in₁ a x) in₂ : {{Γ₁ Γ₂ : Ctx}} → Γ₂ ▹ (Γ₁ ⊕ Γ₂) in₂ {{[]}} _ x = x in₂ {{b ∷ Γ₁}} a x = succ a (in₂ a x) split : {Γ₁ Γ₂ : Ctx} {a : Ty} → Var (Γ₁ ⊕ Γ₂) a → Var Γ₁ a ⊎ Var Γ₂ a split {[]} {Γ₂} x = inj₂ x split {a ∷ Γ₁'} {Γ₂} zero = inj₁ zero split {b ∷ Γ₁'} {Γ₂} {a} (succ .a y) = (Sum.map (succ a) (ctx-id a)) (split {Γ₁'} y) [_,_] : {Γ₁ Γ₂ Δ : Ctx} (f : Γ₁ ▹ Δ) (g : Γ₂ ▹ Δ) → ((Γ₁ ⊕ Γ₂) ▹ Δ) [_,_] {Γ} {Γ₂} f g a x = ([ f a , g a ]′) (split x) _-⊕-_ : {Γ Γ₂ Γ' Γ₂' : Ctx} (f : Γ ▹ Γ') (g : Γ₂ ▹ Γ₂') → ((Γ ⊕ Γ₂) ▹ (Γ' ⊕ Γ₂')) _-⊕-_ {Γ} {Γ₂} {Γ'} {Γ₂'} f g = [ in₁ ● f , in₂ {{Γ'}} {{Γ₂'}} ● g ] succ-distr-lemma : {Γ : Ctx} {a b : Ty} (Γ₂ : Ctx) (x : Var Γ a) → (in₁ {b ∷ Γ} ● succ {Γ}) a x ≡ (succ {Γ ⊕ Γ₂} ● in₁ {Γ} {Γ₂}) a x succ-distr-lemma Γ₂ x = refl split-lemma₁ : {a : Ty} (Γ₁ Γ₂ : Ctx) (x : Var Γ₁ a) → split {Γ₁} {Γ₂} (in₁ {Γ₁} a x) ≡ inj₁ x split-lemma₁ (tt ∷ Γ₁) Γ₂ zero = refl split-lemma₁ (tt ∷ Γ₁) Γ₂ (succ a x) = begin split {tt ∷ Γ₁} (in₁ {tt ∷ Γ₁} a (succ a x)) ≡⟨ refl ⟩ (Sum.map (succ a) id) (split (in₁ a x)) ≡⟨ cong (Sum.map (succ a) id) (split-lemma₁ Γ₁ Γ₂ x) ⟩ (Sum.map (succ a) id) (inj₁ x) ≡⟨ refl ⟩ inj₁ (succ a x) ∎ split-lemma₂ : {a : Ty} (Γ₁ Γ₂ : Ctx) (x : Var Γ₂ a) → split {Γ₁} {Γ₂} (in₂ a x) ≡ inj₂ x split-lemma₂ [] Γ₂ x = refl split-lemma₂ {a} (tt ∷ Γ₁) Γ₂ x = begin split {tt ∷ Γ₁} {Γ₂} (in₂ {{tt ∷ Γ₁}} a x) ≡⟨ refl ⟩ Sum.map (succ a) id (split (in₂ {{Γ₁}} a x)) ≡⟨ cong (λ u → Sum.map (succ a) id u) (split-lemma₂ Γ₁ Γ₂ x) ⟩ Sum.map (succ a) id (inj₂ x) ≡⟨ refl ⟩ inj₂ x ∎ split-lemma : (Γ₁ Γ₂ : Ctx) (a : Ty) (x : Var (Γ₁ ⊕ Γ₂) a) → [ in₁ {Γ₁} {Γ₂} a , in₂ a ]′ (split x) ≡ x split-lemma [] Γ₂ _ x = refl split-lemma (a ∷ Γ₁) Γ₂ .a zero = refl split-lemma (b ∷ Γ₁) Γ₂ a (succ .a x) = begin [ in₁ {b ∷ Γ₁} a , in₂ {{b ∷ Γ₁}} a ]′ (split (succ a x)) ≡⟨ refl ⟩ [ in₁ {b ∷ Γ₁} a , (succ {Γ₁ ⊕ Γ₂} ● in₂ {{Γ₁}} ) a ]′ (Sum.map (succ {Γ₁} a) id (split x)) ≡⟨ copair-sum-map-merge {f₁ = Var.succ {Γ₁} {b} a} (split x) ⟩ [ (in₁ {b ∷ Γ₁} ● succ {Γ₁}) a , (succ {Γ₁ ⊕ Γ₂} ● in₂) a ]′ (split x) ≡⟨ copair-cong {f = (in₁ {b ∷ Γ₁} ● succ {Γ₁}) a} (succ-distr-lemma Γ₂) (split x) ⟩ [ (succ {Γ₁ ⊕ Γ₂} ● in₁ {Γ₁}) a , (succ {Γ₁ ⊕ Γ₂} ● in₂) a ]′ (split x) ≡⟨ copair-distr {f = in₁ {Γ₁} {Γ₂} a} {h = succ {Γ₁ ⊕ Γ₂} a} (split x)⟩ (Var.succ {Γ₁ ⊕ Γ₂} {b} a ∘ [ in₁ {Γ₁} a , in₂ a ]′) (split x) ≡⟨ cong (succ {Γ₁ ⊕ Γ₂} {b} a) (split-lemma Γ₁ Γ₂ a x) ⟩ succ {Γ₁ ⊕ Γ₂} a x ∎ ⊕-is-coprod-arg : ∀{Γ₁ Γ₂ : Ctx} (a : Ty) (x : Var (Γ₁ ⊕ Γ₂) a) → [ in₁ {Γ₁} {Γ₂} , in₂ ] a x ≡ ctx-id a x ⊕-is-coprod-arg {Γ₁} {Γ₂} = split-lemma Γ₁ Γ₂ ⊕-is-coprod : ∀{Γ₁ Γ₂ : Ctx} → [ in₁ {Γ₁} {Γ₂} , in₂ ] ≡C ctx-id ⊕-is-coprod {Γ₁} = {!!} {- η-≡ {f₁ = [ in₁ {Γ₁} , in₂ ]} {f₂ = ctx-id} (λ (a : Ty) → η-≡ {f₁ = [ in₁ {Γ₁}, in₂ ] a} {f₂ = ctx-id a} (⊕-is-coprod-arg {Γ₁} a) ) -} ●-distr-copair₁ˡ : ∀{Γ₁ Γ₂ Δ : Ctx} (h : (Γ₁ ⊕ Γ₂) ▹ Δ) (a : Ty) (x : Var (Γ₁ ⊕ Γ₂) a) → [ h ● in₁ {Γ₁} {Γ₂} , h ● in₂ {{Γ₁}} {{Γ₂}} ] a x ≡ (h ● [ in₁ {Γ₁} {Γ₂} , in₂ ]) a x ●-distr-copair₁ˡ {Γ₁} {Γ₂} {Δ} h a x = begin [ h ● in₁ {Γ₁} , h ● in₂ ] a x ≡⟨ refl ⟩ ([ (h ● in₁ {Γ₁}) a , (h ● in₂) a ]′) (split x) ≡⟨ copair-distr {f = in₁ {Γ₁} a} {g = in₂ a} {h = h a} (split x) ⟩ (h ● [ in₁ {Γ₁} , in₂ ]) a x ∎ ●-distr-copairˡ : ∀{Γ₁ Γ₂ Δ : Ctx} (h : (Γ₁ ⊕ Γ₂) ▹ Δ) → [ h ● in₁ {Γ₁} {Γ₂} , h ● in₂ {{Γ₁}} {{Γ₂}} ] ≡ h ● [ in₁ {Γ₁} {Γ₂} , in₂ ] ●-distr-copairˡ {Γ₁} h = {!!} -- η-≡ (λ a → η-≡ (●-distr-copair₁ˡ {Γ₁} h a)) ⊕-is-coprod₁ : ∀{Γ₁ Γ₂ Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} {h : (Γ₁ ⊕ Γ₂) ▹ Δ} → h ● in₁ ≡C f → h ● in₂ ≡C g → [ f , g ] ≡C h ⊕-is-coprod₁ {Γ₁} {Γ₂} {Δ} {f} {g} {h} h●in₁≡f h●in₂≡g = record { ≡C-proof = p } where p : ∀ {a} {x} → [ f , g ] a x ≡ h a x p {a} {x} = begin [ f , g ] a x ≡⟨ refl ⟩ ([ f a , g a ]′) (split x) ≡⟨ cong (λ u → [ u , g a ]′ (split x)) {!!} ⟩ ([ (h ● in₁ {Γ₁}) a , g a ]′) (split x) ≡⟨ {!!} ⟩ h a x ∎ {- [ h ● in₁ {Γ₁} , g ] ≡⟨ cong (λ u → [ h ● in₁ {Γ₁} , u ]) (sym h●in₂≡g) ⟩ [ h ● in₁ {Γ₁} , h ● in₂ ] ≡⟨ ●-distr-copairˡ {Γ₁} h ⟩ h ● [ in₁ {Γ₁}, in₂ ] ≡⟨ cong (λ u → h ● u) (⊕-is-coprod {Γ₁}) ⟩ h ● ctx-id ≡⟨ refl ⟩ h -} commute-in₁-arg : ∀ {Γ₁ Γ₂ Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} (a : Ty) (x : Var Γ₁ a) → ([ f , g ] ● in₁) a x ≡ f a x commute-in₁-arg _ zero = refl commute-in₁-arg {b ∷ Γ₁} {Γ₂} {Δ} {f} {g} a (succ .a x) = begin ([ f , g ] ● in₁ {b ∷ Γ₁}) a (succ {Γ₁} a x) ≡⟨ refl ⟩ [ f , g ] a (succ {Γ₁ ⊕ Γ₂} a (in₁ {Γ₁} a x)) ≡⟨ refl ⟩ ([ f a , g a ]′) (split (succ {Γ₁ ⊕ Γ₂} a (in₁ {Γ₁} a x))) ≡⟨ refl ⟩ [ f a , g a ]′ ((Sum.map (succ a) id) (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x))) ≡⟨ refl ⟩ (([ f a , g a ]′ ∘ (Sum.map (succ a) id)) (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x))) ≡⟨ copair-sum-map-merge {f₁ = succ a} (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x)) ⟩ ([ (f ● succ) a , g a ]′ (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x))) ≡⟨ cong ([ (f ● succ) a , g a ]′) (split-lemma₁ Γ₁ Γ₂ x) ⟩ f a (succ a x) ∎ commute-in₁ : (Γ₁ : Ctx) → (Γ₂ : Ctx) → {Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} → ([ f , g ] ● in₁) ≡C f commute-in₁ Γ₁ Γ₂ {Δ} {f} {g} = record { ≡C-proof = λ {a} {x} → commute-in₁-arg {f = f} {g} a x } commute-in₂-arg : ∀ {Γ₁ Γ₂ Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} (a : Ty) (x : Var Γ₂ a) → ([ f , g ] ● in₂) a x ≡ g a x commute-in₂-arg {[]} _ _ = refl commute-in₂-arg {tt ∷ Γ₁} {Γ₂} {Δ} {f} {g} a x = begin ([ f , g ] ● in₂ {{tt ∷ Γ₁}} ) a x ≡⟨ refl ⟩ [ f , g ] a ((succ ● in₂) a x) ≡⟨ refl ⟩ [ f a , g a ]′ (split {tt ∷ Γ₁} (succ a (in₂ a x))) ≡⟨ cong (λ u → [ f a , g a ]′ u) {x = split {tt ∷ Γ₁} (succ a (in₂ a x))} refl ⟩ [ f a , g a ]′ ((Sum.map (succ a) id) (split {Γ₁} (in₂ a x))) ≡⟨ cong (λ u → [ f a , g a ]′ (Sum.map (succ a) id u)) (split-lemma₂ Γ₁ Γ₂ x) ⟩ [ f a , g a ]′ ((Sum.map (succ a) id) (inj₂ x)) ≡⟨ copair-sum-map-merge {f₁ = succ {Γ₁} a} {f₂ = id} {g₁ = f a} {g₂ = g a} (inj₂ x) ⟩ [ (f ● succ) a , (g ● ctx-id) a ]′ (inj₂ x) ≡⟨ copair-elimʳ {f = (f ● succ) a} {g = (g ● ctx-id) a} x ⟩ g a x ∎ commute-in₂ : (Γ₁ : Ctx) → (Γ₂ : Ctx) → {Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} → ([ f , g ] ● in₂) ≡C g commute-in₂ Γ₁ Γ₂ {Δ} {f} {g} = record { ≡C-proof = λ {a} {x} → commute-in₂-arg {f = f} {g} a x } open import Categories.Object.Coproduct ctx-cat ctx-coproduct : ∀{Γ₁ Γ₂ : Ctx} → Coproduct Γ₁ Γ₂ ctx-coproduct {Γ₁} {Γ₂} = record { A+B = Γ₁ ⊕ Γ₂ ; i₁ = in₁ ; i₂ = in₂ ; [_,_] = [_,_] ; commute₁ = commute-in₁ Γ₁ Γ₂ ; commute₂ = commute-in₂ Γ₁ Γ₂ ; universal = ⊕-is-coprod₁ } open import Categories.Object.BinaryCoproducts ctx-cat ctx-bin-coproducts : BinaryCoproducts ctx-bin-coproducts = record { coproduct = ctx-coproduct } open BinaryCoproducts ctx-bin-coproducts -}
31.754875
87
0.437368
cb29732e715d0246f8e59474d528f1e12c231f2d
21,508
agda
Agda
src/to-string.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/to-string.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/to-string.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
import cedille-options module to-string (options : cedille-options.options) where open import lib open import cedille-types open import constants open import syntax-util open import ctxt open import rename open import general-util data expr-side : Set where left : expr-side right : expr-side neither : expr-side not-left : expr-side → 𝔹 not-left left = ff not-left _ = tt not-right : expr-side → 𝔹 not-right right = ff not-right _ = tt no-parens : {ed : exprd} → {ed' : exprd} → ⟦ ed ⟧ → ⟦ ed' ⟧ → expr-side → 𝔹 no-parens {_} {TERM} _ (IotaPair pi t t' og pi') lr = tt no-parens {_} {TYPE} _ (TpEq _ t t' _) lr = tt no-parens {_} {TERM} _ (Beta pi ot ot') lr = tt no-parens {_} {TERM} _ (Phi pi eq t t' pi') right = tt no-parens {_} {TERM} _ (Phi pi eq t t' pi') neither = tt no-parens {_} {TERM} _ (Rho _ _ _ _ _ _) right = tt no-parens {_} {TERM} _ (Chi _ _ _) right = tt no-parens {_} {TERM} _ (Delta _ _ _) right = tt no-parens {_} {TERM} _ (Let _ _ _) lr = tt no-parens {_} {TERM} _ (Lam _ _ _ _ _ _) lr = tt no-parens {_} {TERM} _ (Mu _ _ _ _ _ _ _) lr = tt no-parens {_} {TERM} _ (Mu' _ _ _ _ _ _) lr = tt no-parens {_} {TYPE} _ (TpLambda _ _ _ _ _) lr = tt no-parens {_} {TYPE} _ (Abs _ _ _ _ _ _) lr = tt no-parens {_} {KIND} _ (KndPi _ _ _ _ _) lr = tt no-parens {_} {TYPE} _ (Iota _ _ _ _ _) lr = tt no-parens {_} {LIFTINGTYPE} _ (LiftPi _ _ _ _) lr = tt no-parens{TERM} (App t me t') p lr = is-term-level-app p && not-right lr no-parens{TERM} (AppTp t T) p lr = is-term-level-app p && not-right lr no-parens{TERM} (Beta pi ot ot') p lr = tt no-parens{TERM} (Chi pi mT t) p lr = ff no-parens{TERM} (Delta pi mT t) p lr = ff no-parens{TERM} (Epsilon pi lr' m t) p lr = is-eq-op p no-parens{TERM} (Hole pi) p lr = tt no-parens{TERM} (IotaPair pi t t' og pi') p lr = tt no-parens{TERM} (IotaProj t n pi) p lr = tt no-parens{TERM} (Lam pi l' pi' x oc t) p lr = ff no-parens{TERM} (Let pi dtT t) p lr = ff no-parens{TERM} (Open _ _ _) p lr = tt no-parens{TERM} (Parens pi t pi') p lr = tt no-parens{TERM} (Phi pi eq t t' pi') p lr = ff no-parens{TERM} (Rho pi op on eq og t) p lr = ff no-parens{TERM} (Sigma pi t) p lr = is-eq-op p no-parens{TERM} (Theta pi theta t lts) p lr = ff no-parens{TERM} (Var pi x) p lr = tt no-parens{TERM} (Mu _ _ _ _ _ _ _) p lr = tt no-parens{TERM} (Mu' _ _ _ _ _ _) p lr = tt no-parens{TYPE} (Abs pi b pi' x Tk T) p lr = is-arrow p && not-left lr no-parens{TYPE} (Iota pi pi' x oT T) p lr = ff no-parens{TYPE} (Lft pi pi' x t lT) p lr = ff no-parens{TYPE} (NoSpans T pi) p lr = tt no-parens{TYPE} (TpApp T T') p lr = is-arrow p || (is-type-level-app p && not-right lr) no-parens{TYPE} (TpAppt T t) p lr = is-arrow p || (is-type-level-app p && not-right lr) no-parens{TYPE} (TpArrow T a T') p lr = is-arrow p && not-left lr no-parens{TYPE} (TpEq _ t t' _) p lr = tt no-parens{TYPE} (TpHole pi) p lr = tt no-parens{TYPE} (TpLambda pi pi' x Tk T) p lr = ff no-parens{TYPE} (TpParens pi T pi') p lr = tt no-parens{TYPE} (TpVar pi x) p lr = tt no-parens{TYPE} (TpLet _ _ _) _ _ = ff no-parens{KIND} (KndArrow k k') p lr = is-arrow p && not-left lr no-parens{KIND} (KndParens pi k pi') p lr = tt no-parens{KIND} (KndPi pi pi' x Tk k) p lr = is-arrow p && not-left lr no-parens{KIND} (KndTpArrow T k) p lr = is-arrow p && not-left lr no-parens{KIND} (KndVar pi x as) p lr = tt no-parens{KIND} (Star pi) p lr = tt no-parens{LIFTINGTYPE} (LiftArrow lT lT') p lr = is-arrow p && not-left lr no-parens{LIFTINGTYPE} (LiftParens pi lT pi') p lr = tt no-parens{LIFTINGTYPE} (LiftPi pi x T lT) p lr = is-arrow p && not-left lr no-parens{LIFTINGTYPE} (LiftStar pi) p lr = tt no-parens{LIFTINGTYPE} (LiftTpArrow T lT) p lr = is-arrow p && not-left lr no-parens{TK} _ _ _ = tt no-parens{QUALIF} _ _ _ = tt no-parens{ARG} _ _ _ = tt pattern ced-ops-drop-spine = cedille-options.options.mk-options _ _ _ _ ff _ ff pattern ced-ops-conv-arr = cedille-options.options.mk-options _ _ _ _ _ _ ff pattern ced-ops-conv-abs = cedille-options.options.mk-options _ _ _ _ _ _ tt drop-spine : cedille-options.options → {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧ drop-spine ced-ops-drop-spine = h where drop-mod-args : ctxt → maybeErased → spineApp → spineApp drop-mod-args Γ me (v , as) = let qv = unqual-all (ctxt-get-qualif Γ) v in qv , maybe-else' (maybe-if (~ v =string qv) ≫maybe ctxt-qualif-args-length Γ me qv) as (λ n → reverse (drop n (reverse as))) h : {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧ h {TERM} Γ t = maybe-else' (term-to-spapp t) t (spapp-term ∘ drop-mod-args Γ Erased) h {TYPE} Γ T = maybe-else' (type-to-spapp T) T (spapp-type ∘ drop-mod-args Γ NotErased) h Γ x = x drop-spine ops Γ x = x to-string-rewrite : {ed : exprd} → ctxt → cedille-options.options → ⟦ ed ⟧ → Σi exprd ⟦_⟧ to-string-rewrite{TERM} Γ ops (Parens _ t _) = to-string-rewrite Γ ops t to-string-rewrite{TYPE} Γ ops (TpParens _ T _) = to-string-rewrite Γ ops T to-string-rewrite{KIND} Γ ops (KndParens _ k _) = to-string-rewrite Γ ops k to-string-rewrite{LIFTINGTYPE} Γ ops (LiftParens _ lT _) = to-string-rewrite Γ ops lT to-string-rewrite{TK} Γ ops (Tkt T) = to-string-rewrite Γ ops T to-string-rewrite{TK} Γ ops (Tkk k) = to-string-rewrite Γ ops k to-string-rewrite{TYPE} Γ ced-ops-conv-arr (Abs _ me _ ignored-var (Tkt T) T') = , TpArrow T me T' to-string-rewrite{KIND} Γ ced-ops-conv-arr (KndPi _ _ ignored-var (Tkt T) k) = , KndTpArrow T k to-string-rewrite{KIND} Γ ced-ops-conv-arr (KndPi _ _ ignored-var (Tkk k) k') = , KndArrow k k' to-string-rewrite{LIFTINGTYPE} Γ ced-ops-conv-arr (LiftPi _ ignored-var T lT) = , LiftTpArrow T lT to-string-rewrite{TYPE} Γ ced-ops-conv-abs (TpArrow T me T') = , Abs posinfo-gen me posinfo-gen ignored-var (Tkt T) T' to-string-rewrite{KIND} Γ ced-ops-conv-abs (KndTpArrow T k) = , KndPi posinfo-gen posinfo-gen ignored-var (Tkt T) k to-string-rewrite{KIND} Γ ced-ops-conv-abs (KndArrow k k') = , KndPi posinfo-gen posinfo-gen ignored-var (Tkk k) k' to-string-rewrite{LIFTINGTYPE} Γ ced-ops-conv-abs (LiftTpArrow T lT) = , LiftPi posinfo-gen ignored-var T lT to-string-rewrite{TERM} Γ ops (Sigma pi (Sigma pi' t)) = to-string-rewrite Γ ops t to-string-rewrite Γ ops x = , drop-spine ops Γ x ------------------------------- strM : Set strM = ∀ {ed} → rope → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → rope × ℕ × 𝕃 tag to-stringh : {ed : exprd} → ⟦ ed ⟧ → strM strM-Γ : (ctxt → strM) → strM strM-Γ f s n ts Γ = f Γ s n ts Γ infixr 4 _≫str_ _≫str_ : strM → strM → strM (m ≫str m') s n ts Γ pe lr with m s n ts Γ pe lr (m ≫str m') s n ts Γ pe lr | s' , n' , ts' = m' s' n' ts' Γ pe lr strAdd : string → strM strAdd s s' n ts Γ pe lr = s' ⊹⊹ [[ s ]] , n + string-length s , ts strΓ' : defScope → var → strM → strM strΓ' ds v m s n ts Γ@(mk-ctxt (fn , mn , ps , q) syms i symb-occs d) pe = let gl = ds iff globalScope v' = if gl then (mn # v) else v in m s n ts (mk-ctxt (fn , mn , ps , qualif-insert-params q v' (unqual-local v) (if gl then ps else ParamsNil)) syms (trie-insert i v' (var-decl , ("missing" , "missing"))) symb-occs d) pe strΓ : var → strM → strM strΓ x m s n ts Γ = m s n ts (ctxt-var-decl x Γ) ctxt-get-file-id : ctxt → (filename : string) → ℕ ctxt-get-file-id (mk-ctxt mod (syms , mn-fn , mn-ps , ids , id) is os _) = trie-lookup-else 0 ids make-loc-tag : ctxt → (filename start-to end-to : string) → (start-from end-from : ℕ) → tag make-loc-tag Γ fn s e = make-tag "loc" (("fn" , [[ ℕ-to-string (ctxt-get-file-id Γ fn) ]]) :: ("s" , [[ s ]]) :: ("e" , [[ e ]]) :: []) var-loc-tag : ctxt → location → var → (start-from end-from : ℕ) → 𝕃 tag var-loc-tag Γ ("missing" , "missing") x start end = [] var-loc-tag Γ (fn , pos) x start end = [ make-loc-tag Γ fn pos (posinfo-plus-str pos (unqual-local x)) start end ] var-tags : ctxt → qvar → var → ℕ → ℕ → 𝕃 tag var-tags Γ qv uqv s e with qv =string (qualif-var Γ uqv) ...| tt = var-loc-tag Γ (ctxt-var-location Γ qv) uqv s e ...| ff = make-tag "shadowed" [] s e :: var-loc-tag Γ (ctxt-var-location Γ qv) uqv s e strVar : var → strM strVar v s n ts Γ pe lr = let uqv = unqual-local $ unqual-all (ctxt-get-qualif Γ) v uqv' = if cedille-options.options.show-qualified-vars options then v else uqv n' = n + (string-length uqv') in s ⊹⊹ [[ uqv' ]] , n' , var-tags Γ (qualif-var Γ v) uqv n n' ++ ts -- Only necessary to unqual-local because of module parameters strBvar : var → (class body : strM) → strM strBvar v cm bm = strAdd (unqual-local v) ≫str cm ≫str strΓ v bm strMetaVar : var → span-location → strM strMetaVar x (fn , pi , pi') s n ts Γ pe lr = let n' = n + string-length x in s ⊹⊹ [[ x ]] , n' , make-loc-tag Γ fn pi pi' n n' :: ts strEmpty : strM strEmpty s n ts Γ pe lr = s , n , ts {-# TERMINATING #-} term-to-stringh : term → strM type-to-stringh : type → strM kind-to-stringh : kind → strM liftingType-to-stringh : liftingType → strM tk-to-stringh : tk → strM constructors-to-string : dataConsts → strM params-to-string : params → strM params-to-string' : strM → params → strM file-to-string : start → strM cmds-to-string : cmds → strM → strM cmd-to-string : cmd → strM → strM optTerm-to-string : optTerm → string → string → strM optClass-to-string : optClass → strM optGuide-to-string : optGuide → strM optNums-to-string : optNums → strM optType-to-string : optType → strM maybeCheckType-to-string : optType → strM lterms-to-string : lterms → strM arg-to-string : arg → strM args-to-string : args → strM binder-to-string : maybeErased → string opacity-to-string : opacity → string maybeErased-to-string : maybeErased → string lam-to-string : maybeErased → string leftRight-to-string : leftRight → string vars-to-string : vars → strM nums-to-string : nums → strM theta-to-string : theta → strM arrowtype-to-string : maybeErased → string maybeMinus-to-string : maybeMinus → string optPlus-to-string : optPlus → string optPublic-to-string : optPublic → string optAs-to-string : optAs → strM to-string-ed : {ed : exprd} → ⟦ ed ⟧ → strM to-string-ed{TERM} = term-to-stringh to-string-ed{TYPE} = type-to-stringh to-string-ed{KIND} = kind-to-stringh to-string-ed{LIFTINGTYPE} = liftingType-to-stringh to-string-ed{TK} = tk-to-stringh to-string-ed{ARG} = arg-to-string to-string-ed{QUALIF} q = strEmpty to-stringh' : {ed : exprd} → expr-side → ⟦ ed ⟧ → strM to-stringh' {ed} lr t {ed'} s n ts Γ mp lr' = elim-Σi (to-string-rewrite Γ options t) λ t' → parens-unless (~ isJust (mp ≫=maybe λ pe → maybe-if (~ no-parens t' pe lr))) (to-string-ed t') s n ts Γ (just t') lr where parens-unless : 𝔹 → strM → strM parens-unless p s = if p then s else (strAdd "(" ≫str s ≫str strAdd ")") to-stringl : {ed : exprd} → ⟦ ed ⟧ → strM to-stringr : {ed : exprd} → ⟦ ed ⟧ → strM to-stringl = to-stringh' left to-stringr = to-stringh' right to-stringh = to-stringh' neither constructors-to-string DataNull = strEmpty constructors-to-string (DataCons (DataConst _ x t) ds) = strAdd " | " ≫str strAdd x ≫str strAdd " : " ≫str type-to-stringh t ≫str constructors-to-string ds tk-to-stringh (Tkt T) = to-stringh T tk-to-stringh (Tkk k) = to-stringh k term-to-stringh (App t me t') = to-stringl t ≫str strAdd (" " ^ maybeErased-to-string me) ≫str to-stringr t' term-to-stringh (AppTp t T) = to-stringl t ≫str strAdd " · " ≫str to-stringr T term-to-stringh (Beta pi ot ot') = strAdd "β" ≫str optTerm-to-string ot " < " " >" ≫str optTerm-to-string ot' " { " " }" term-to-stringh (Chi pi mT t) = strAdd "χ" ≫str optType-to-string mT ≫str strAdd " - " ≫str to-stringr t term-to-stringh (Delta pi mT t) = strAdd "δ" ≫str optType-to-string mT ≫str strAdd " - " ≫str to-stringr t term-to-stringh (Epsilon pi lr m t) = strAdd "ε" ≫str strAdd (leftRight-to-string lr) ≫str strAdd (maybeMinus-to-string m) ≫str to-stringh t term-to-stringh (Hole pi) = strAdd "●" term-to-stringh (IotaPair pi t t' og pi') = strAdd "[ " ≫str to-stringh t ≫str strAdd " , " ≫str to-stringh t' ≫str optGuide-to-string og ≫str strAdd " ]" term-to-stringh (IotaProj t n pi) = to-stringh t ≫str strAdd ("." ^ n) term-to-stringh (Lam pi l pi' x oc t) = strAdd (lam-to-string l) ≫str strAdd " " ≫str strBvar x (optClass-to-string oc) (strAdd " . " ≫str to-stringr t) term-to-stringh (Let pi dtT t) with dtT ...| DefTerm pi' x m t' = strAdd "[ " ≫str strBvar x (maybeCheckType-to-string m ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t) ...| DefType pi' x k t' = strAdd "[ " ≫str strBvar x (strAdd " ◂ " ≫str to-stringh k ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t) term-to-stringh (Open pi x t) = strAdd "open " ≫str strVar x ≫str strAdd " - " ≫str to-stringh t term-to-stringh (Parens pi t pi') = to-stringh t term-to-stringh (Phi pi eq t t' pi') = strAdd "φ " ≫str to-stringl eq ≫str strAdd " - " ≫str to-stringh t ≫str strAdd " {" ≫str to-stringr t' ≫str strAdd "}" term-to-stringh (Rho pi op on eq og t) = strAdd "ρ" ≫str strAdd (optPlus-to-string op) ≫str optNums-to-string on ≫str strAdd " " ≫str to-stringl eq ≫str optGuide-to-string og ≫str strAdd " - " ≫str to-stringr t term-to-stringh (Sigma pi t) = strAdd "ς " ≫str to-stringh t term-to-stringh (Theta pi theta t lts) = theta-to-string theta ≫str to-stringh t ≫str lterms-to-string lts term-to-stringh (Var pi x) = strVar x term-to-stringh (Mu pi x t ot pi' cs pi'') = strAdd "μ " ≫str strBvar x (strAdd " . " ≫str to-stringh t) strEmpty ≫str optType-to-string ot ≫str strAdd "TODO" term-to-stringh (Mu' pi t ot pi' cs pi'') = strAdd "μ' " ≫str to-stringh t ≫str strAdd " . " ≫str optType-to-string ot ≫str strAdd "TODO" type-to-stringh (Abs pi b pi' x Tk T) = strAdd (binder-to-string b ^ " ") ≫str strBvar x (strAdd " : " ≫str tk-to-stringh Tk ≫str strAdd " . ") (to-stringh T) type-to-stringh (Iota pi pi' x T T') = strAdd "ι " ≫str strBvar x (strAdd " : " ≫str to-stringh T ≫str strAdd " . ") (to-stringh T') type-to-stringh (Lft pi pi' x t lT) = strAdd "↑ " ≫str strBvar x (strAdd " . ") (to-stringh t) ≫str strAdd " : " ≫str to-stringh lT type-to-stringh (NoSpans T pi) = to-string-ed T type-to-stringh (TpApp T T') = to-stringl T ≫str strAdd " · " ≫str to-stringr T' type-to-stringh (TpAppt T t) = to-stringl T ≫str strAdd " " ≫str to-stringr t type-to-stringh (TpArrow T a T') = to-stringl T ≫str strAdd (arrowtype-to-string a) ≫str to-stringr T' type-to-stringh (TpEq _ t t' _) = strAdd "{ " ≫str to-stringh (erase-term t) ≫str strAdd " ≃ " ≫str to-stringh (erase-term t') ≫str strAdd " }" type-to-stringh (TpHole pi) = strAdd "●" type-to-stringh (TpLambda pi pi' x Tk T) = strAdd "λ " ≫str strBvar x (strAdd " : " ≫str tk-to-stringh Tk ≫str strAdd " . ") (to-stringr T) type-to-stringh (TpParens pi T pi') = to-stringh T type-to-stringh (TpVar pi x) = strVar x type-to-stringh (TpLet pi dtT t) with dtT ...| DefTerm pi' x m t' = strAdd "[ " ≫str strBvar x (maybeCheckType-to-string m ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t) ...| DefType pi' x k t' = strAdd "[ " ≫str strBvar x (strAdd " ◂ " ≫str to-stringh k ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t) kind-to-stringh (KndArrow k k') = to-stringl k ≫str strAdd " ➔ " ≫str to-stringr k' kind-to-stringh (KndParens pi k pi') = to-stringh k kind-to-stringh (KndPi pi pi' x Tk k) = strAdd "Π " ≫str strBvar x (strAdd " : " ≫str tk-to-stringh Tk ≫str strAdd " . ") (to-stringh k) kind-to-stringh (KndTpArrow T k) = to-stringl T ≫str strAdd " ➔ " ≫str to-stringr k kind-to-stringh (KndVar pi x as) = strVar x ≫str args-to-string as kind-to-stringh (Star pi) = strAdd "★" liftingType-to-stringh (LiftArrow lT lT') = to-stringl lT ≫str strAdd " ➔↑ " ≫str to-stringr lT' liftingType-to-stringh (LiftParens pi lT pi') = strAdd "(" ≫str to-string-ed lT ≫str strAdd ")" liftingType-to-stringh (LiftPi pi x T lT) = strAdd "Π↑ " ≫str strBvar x (strAdd " : " ≫str to-stringh T ≫str strAdd " . ") (to-stringh lT) liftingType-to-stringh (LiftStar pi) = strAdd "☆" liftingType-to-stringh (LiftTpArrow T lT) = to-stringl T ≫str strAdd " ➔↑ " ≫str to-stringr lT optTerm-to-string NoTerm c1 c2 = strEmpty optTerm-to-string (SomeTerm t _) c1 c2 = strAdd c1 ≫str to-stringh (erase-term t) ≫str strAdd c2 optClass-to-string NoClass = strEmpty optClass-to-string (SomeClass Tk) = strAdd " : " ≫str tk-to-stringh Tk optGuide-to-string NoGuide = strEmpty optGuide-to-string (Guide pi v T) = strAdd " @ " ≫str strBvar v (strAdd " . ") (to-stringh T) optType-to-string NoType = strEmpty optType-to-string (SomeType T) = strAdd " " ≫str to-stringh T maybeCheckType-to-string NoType = strEmpty maybeCheckType-to-string (SomeType T) = strAdd " ◂ " ≫str to-stringh T lterms-to-string (LtermsCons m t ts) = strAdd (" " ^ maybeErased-to-string m) ≫str to-stringh t ≫str lterms-to-string ts lterms-to-string (LtermsNil _) = strEmpty arg-to-string (TermArg me t) = strAdd (maybeErased-to-string me) ≫str to-stringh t arg-to-string (TypeArg T) = strAdd "· " ≫str to-stringh T args-to-string (ArgsCons t ts) = strAdd " " ≫str arg-to-string t ≫str args-to-string ts args-to-string ArgsNil = strEmpty binder-to-string All = "∀" binder-to-string Pi = "Π" opacity-to-string OpacOpaque = "opaque " opacity-to-string OpacTrans = "" maybeErased-to-string Erased = "-" maybeErased-to-string NotErased = "" lam-to-string Erased = "Λ" lam-to-string NotErased = "λ" leftRight-to-string Left = "l" leftRight-to-string Right = "r" leftRight-to-string Both = "" vars-to-string (VarsStart v) = strVar v vars-to-string (VarsNext v vs) = strVar v ≫str strAdd " " ≫str vars-to-string vs theta-to-string Abstract = strAdd "θ " theta-to-string AbstractEq = strAdd "θ+ " theta-to-string (AbstractVars vs) = strAdd "θ<" ≫str vars-to-string vs ≫str strAdd "> " nums-to-string (NumsStart n) = strAdd n nums-to-string (NumsNext n ns) = strAdd n ≫str strAdd " " ≫str nums-to-string ns optNums-to-string NoNums = strEmpty optNums-to-string (SomeNums ns) = strAdd "<" ≫str nums-to-string ns ≫str strAdd ">" arrowtype-to-string NotErased = " ➔ " arrowtype-to-string Erased = " ➾ " maybeMinus-to-string EpsHnf = "" maybeMinus-to-string EpsHanf = "-" optPlus-to-string RhoPlain = "" optPlus-to-string RhoPlus = "+" optPublic-to-string NotPublic = "" optPublic-to-string IsPublic = "public " optAs-to-string NoOptAs = strEmpty optAs-to-string (SomeOptAs _ x) = strAdd " as " ≫str strAdd x braceL : maybeErased → string braceL Erased = "{" braceL NotErased = "(" braceR : maybeErased → string braceR Erased = "}" braceR NotErased = ")" param-to-string : decl → strM → strM param-to-string (Decl _ pi me v atk _) f = strAdd (braceL me) ≫str strAdd (unqual-local v) ≫str strAdd " : " ≫str tk-to-stringh atk ≫str strAdd (braceR me) ≫str strΓ' localScope v f params-to-string' f ParamsNil = f params-to-string' f (ParamsCons p ParamsNil) = param-to-string p f params-to-string' f (ParamsCons p ps) = param-to-string p (strAdd " " ≫str params-to-string' f ps) params-to-string = params-to-string' strEmpty file-to-string (File _ is _ _ mn ps cs _) = cmds-to-string (imps-to-cmds is) (strAdd "module " ≫str strAdd mn ≫str strAdd " " ≫str params-to-string' (strAdd "." ≫str strAdd "\n" ≫str cmds-to-string cs strEmpty) ps) cmds-to-string CmdsStart f = f cmds-to-string (CmdsNext c cs) f = strAdd "\n" ≫str cmd-to-string c (strAdd "\n" ≫str cmds-to-string cs f) cmd-to-string (DefTermOrType op (DefTerm pi x mcT t) _) f = strM-Γ λ Γ → let ps = ctxt-get-current-params Γ in strAdd (opacity-to-string op) ≫str strAdd x ≫str maybeCheckType-to-string (case mcT of λ where NoType → NoType (SomeType T) → SomeType (abs-expand-type ps T)) ≫str strAdd " = " ≫str to-stringh (lam-expand-term ps t) ≫str strAdd " ." ≫str strΓ' globalScope x f cmd-to-string (DefTermOrType op (DefType pi x k T) _) f = strM-Γ λ Γ → let ps = ctxt-get-current-params Γ in strAdd (opacity-to-string op) ≫str strAdd x ≫str strAdd " ◂ " ≫str to-stringh (abs-expand-kind ps k) ≫str strAdd " = " ≫str to-stringh (lam-expand-type ps T) ≫str strAdd " ." ≫str strΓ' globalScope x f cmd-to-string (DefKind pi x ps k _) f = strM-Γ λ Γ → let ps' = ctxt-get-current-params Γ in strAdd x ≫str params-to-string (append-params ps' ps) ≫str strAdd " = " ≫str to-stringh k ≫str strAdd " ." ≫str strΓ' globalScope x f cmd-to-string (ImportCmd (Import _ op _ fn oa as _)) f = strAdd "import " ≫str strAdd (optPublic-to-string op) ≫str strAdd fn ≫str optAs-to-string oa ≫str args-to-string as ≫str strAdd " ." ≫str f cmd-to-string (DefDatatype (Datatype pi pix x ps k cs pi') pi'') f = strAdd "data " ≫str strAdd x ≫str strAdd " " ≫str params-to-string ps ≫str strAdd " : " ≫str kind-to-stringh k ≫str strAdd " = " ≫str constructors-to-string cs ≫str strΓ' globalScope x f strRun : ctxt → strM → rope strRun Γ m = fst (m {TERM} [[]] 0 [] Γ nothing neither) strRunTag : (name : string) → ctxt → strM → tagged-val strRunTag name Γ m with m {TERM} [[]] 0 [] Γ nothing neither ...| s , n , ts = name , s , ts to-string-tag : {ed : exprd} → string → ctxt → ⟦ ed ⟧ → tagged-val to-string-tag name Γ t = strRunTag name Γ (to-stringh (if cedille-options.options.erase-types options then erase t else t)) to-string : {ed : exprd} → ctxt → ⟦ ed ⟧ → rope to-string Γ t = strRun Γ (to-stringh t) tk-to-string : ctxt → tk → rope tk-to-string Γ atk = strRun Γ (tk-to-stringh atk) params-to-string-tag : string → ctxt → params → tagged-val params-to-string-tag name Γ ps = strRunTag name Γ (params-to-string ps)
44.995816
210
0.652362
2911314cd50ac61892f1607c1c1214779d257db1
681
agda
Agda
Orders/WellFounded/Induction.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Orders/WellFounded/Induction.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Orders/WellFounded/Induction.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Functions.Definition open import Orders.WellFounded.Definition module Orders.WellFounded.Induction {a b : _} {A : Set a} {_<_ : Rel {a} {b} A} (wf : WellFounded _<_) where private foldAcc : {c : _} (P : A → Set c) → (∀ x → (∀ y → y < x → P y) → P x) → ∀ z → Accessible _<_ z → P z foldAcc P inductionProof = go where go : (z : A) → (Accessible _<_ z) → P z go z (access prf) = inductionProof z (λ y yLessZ → go y (prf y yLessZ)) rec : {c : _} (P : A → Set c) → (∀ x → (∀ y → y < x → P y) → P x) → (∀ z → P z) rec P inductionProof z = foldAcc P inductionProof _ (wf z)
27.24
108
0.549192
587f30a00a5869f1b4b4b40860884b6ac1d42a2a
749
agda
Agda
test/epic/tests/Mutual.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/epic/tests/Mutual.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/epic/tests/Mutual.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module tests.Mutual where open import Prelude.IO open import Prelude.String open import Prelude.Unit mutual data G : Set where GA : {g : G}(f : F g) -> G GB : G data F : G -> Set where FA : (g : G) -> F g FB : F GB mutual incG : G -> G incG GB = GA FB incG (GA f) = GA (incF f) incF : {g : G} -> F g -> F (incG g) incF FB = FA (GA FB) incF (FA g) = FA (incG g) mutual PrintF : {g : G} -> F g -> String PrintF FB = "FB" PrintF (FA g) = "(FA " +S+ PrintG g +S+ ")" PrintG : G -> String PrintG GB = "GB" PrintG (GA f) = "(GA " +S+ PrintF f +S+ ")" main : IO Unit main = putStrLn (PrintF (FA (GA (FA GB)))) ,, putStrLn (PrintG (incG (GA (incF FB)))) ,, -- return unit
18.268293
50
0.511348
5816c41ad06765f1a267b366803a612b09c7eb14
1,875
agda
Agda
04-cubical-type-theory/material/ExerciseSession3.agda
bafain/EPIT-2020
34742c0409818f8fe581ffc92992d1b5f29f6b47
[ "MIT" ]
1
2021-04-03T16:28:06.000Z
2021-04-03T16:28:06.000Z
04-cubical-type-theory/material/ExerciseSession3.agda
bafain/EPIT-2020
34742c0409818f8fe581ffc92992d1b5f29f6b47
[ "MIT" ]
null
null
null
04-cubical-type-theory/material/ExerciseSession3.agda
bafain/EPIT-2020
34742c0409818f8fe581ffc92992d1b5f29f6b47
[ "MIT" ]
1
2021-08-02T16:16:34.000Z
2021-08-02T16:16:34.000Z
-- Exercises for session 3 -- -- If unsure which exercises to do start with those marked with * -- {-# OPTIONS --cubical --allow-unsolved-metas #-} module ExerciseSession3 where open import Part1 open import Part2 open import Part3 open import Part4 open import ExerciseSession1 hiding (B) open import Cubical.Foundations.Isomorphism open import Cubical.Data.Nat open import Cubical.Data.Int hiding (neg) -- Exercise* 1: prove associativity of _++_ for FMSet. -- (hint: mimic the proof of unitr-++) -- Exercise 2: define the integers as a HIT with a pos and neg -- constructor each taking a natural number as well as a path -- constructor equating pos 0 and neg 0. -- Exercise 3 (a little longer, but not very hard): prove that the -- above definition of the integers is equal to the ones in -- Cubical.Data.Int. Deduce that they form a set. -- Exercise* 4: we can define the notion of a surjection as: isSurjection : (A → B) → Type _ isSurjection {A = A} {B = B} f = (b : B) → ∃ A (λ a → f a ≡ b) -- The exercise is now to: -- -- a) prove that being a surjection is a proposition -- -- b) prove that the inclusion ∣_∣ : A → ∥ A ∥ is surjective -- (hint: use rec for ∥_∥) -- Exercise* 5: define intLoop : Int → ΩS¹ intLoop = {!!} -- which given +n return loop^n and given -n returns loop^-n. Then -- prove that: windingIntLoop : (n : Int) → winding (intLoop n) ≡ n windingIntLoop = {!!} -- (The other direction is much more difficult and relies on the -- encode-decode method. See Egbert's course on Friday!) -- Exercise 6 (harder): the suspension of a type can be defined as data Susp (A : Type ℓ) : Type ℓ where north : Susp A south : Susp A merid : (a : A) → north ≡ south -- Prove that the circle is equal to the suspension of Bool S¹≡SuspBool : S¹ ≡ Susp Bool S¹≡SuspBool = {!!} -- Hint: define maps back and forth and prove that they cancel.
27.573529
66
0.691733
3d827cad97a62eca72cfda603f242aeab0a6e966
762
agda
Agda
src/fot/DistributiveLaws/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/DistributiveLaws/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/DistributiveLaws/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Distributive laws properties ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module DistributiveLaws.PropertiesI where open import DistributiveLaws.Base ------------------------------------------------------------------------------ -- Congruence properties -- The propositional equality is compatible with the binary operation. ·-leftCong : ∀ {a b c} → a ≡ b → a · c ≡ b · c ·-leftCong refl = refl ·-rightCong : ∀ {a b c} → b ≡ c → a · b ≡ a · c ·-rightCong refl = refl
31.75
78
0.419948
a1b365025798f3d2f43105d93c6f6bc0833d7613
270
agda
Agda
test/succeed/EtaAndMetas.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/EtaAndMetas.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/EtaAndMetas.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module EtaAndMetas where record Functor : Set₁ where field F : Set → Set eta : Functor → Functor eta S = record { F = F } where open Functor S postulate Π : (To : Functor) → Set mkΠ : (B : Functor) → Π (eta B) To : Functor π : Π (eta To) π = mkΠ _
14.210526
33
0.596296
29543c1de1ec9a6511858b89a56a428b935b9949
170
agda
Agda
Cubical/HITs/MappingCones.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/HITs/MappingCones.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/HITs/MappingCones.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.HITs.MappingCones where open import Cubical.HITs.MappingCones.Base public open import Cubical.HITs.MappingCones.Properties public
24.285714
55
0.805882
22897c9716034e4237eb1a053287c4099bb3080c
36,397
agda
Agda
src/interactive-cmds.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
src/interactive-cmds.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
src/interactive-cmds.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
import cedille-options module interactive-cmds (options : cedille-options.options) where open import functions open import cedille-types open import conversion open import constants open import ctxt open import general-util open import spans options {Id} open import subst open import syntax-util open import type-util open import to-string options open import toplevel-state options {IO} open import untyped-spans options {Id} open import parser open import resugar open import rewriting open import rename open import classify options {Id} (λ _ → return triv) import spans options {IO} as io-spans open import datatype-util open import free-vars open import json private elab-typed-err : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧ × 𝔹 elab-typed-err {TERM} Γ t = map-snd spans-have-error $ map-fst fst $ id-out $ check-term Γ t nothing empty-spans elab-typed-err {TYPE} Γ T = map-snd spans-have-error $ map-fst fst $ id-out $ check-type Γ T nothing empty-spans elab-typed-err {KIND} Γ k = map-snd spans-have-error $ id-out $ check-kind Γ k empty-spans elab-typed : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧ elab-typed Γ = fst ∘ elab-typed-err Γ elab-untyped : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧ elab-untyped {TERM} Γ t = fst $ id-out $ untyped-term Γ t empty-spans elab-untyped {TYPE} Γ T = fst $ id-out $ untyped-type Γ T empty-spans elab-untyped {KIND} Γ k = fst $ id-out $ untyped-kind Γ k empty-spans elab-untyped-no-params : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧ elab-untyped-no-params Γ = elab-untyped (record Γ {qual = trie-map (map-snd λ _ → []) (ctxt.qual Γ)}) {- Parsing -} ll-ind : ∀ {X : exprd → Set} → X TERM → X TYPE → X KIND → (ll : exprd) → X ll ll-ind t T k TERM = t ll-ind t T k TYPE = T ll-ind t T k KIND = k ll-ind' : ∀ {X : Σ exprd ⟦_⟧ → Set} → (s : Σ exprd ⟦_⟧) → ((t : term) → X (TERM , t)) → ((T : type) → X (TYPE , T)) → ((k : kind) → X (KIND , k)) → X s ll-ind' (TERM , t) tf Tf kf = tf t ll-ind' (TYPE , T) tf Tf kf = Tf T ll-ind' (KIND , k) tf Tf kf = kf k ll-disambiguate : ctxt → ex-tm → maybe ex-tp ll-disambiguate Γ (ExVar pi x) = ctxt-lookup-type-var Γ x >>= λ _ → just (ExTpVar pi x) ll-disambiguate Γ (ExApp t NotErased t') = ll-disambiguate Γ t >>= λ T → just (ExTpAppt T t') ll-disambiguate Γ (ExAppTp t T') = ll-disambiguate Γ t >>= λ T → just (ExTpApp T T') ll-disambiguate Γ (ExLam pi ff pi' x (just atk) t) = ll-disambiguate (ctxt-tk-decl pi' x (case atk of λ {(ExTkt _) → Tkt (TpHole pi'); (ExTkk _) → Tkk KdStar}) Γ) t >>= λ T → just (ExTpLam pi pi' x atk T) ll-disambiguate Γ (ExParens pi t pi') = ll-disambiguate Γ t ll-disambiguate Γ (ExLet pi _ d t) = ll-disambiguate (Γ' d) t >>= λ T → just (ExTpLet pi d T) where Γ' : ex-def → ctxt Γ' (ExDefTerm pi' x T? t) = ctxt-term-def pi' localScope opacity-open x (just (Hole pi')) (TpHole pi') Γ Γ' (ExDefType pi' x k T) = ctxt-type-def pi' localScope opacity-open x (just (TpHole pi')) KdStar Γ ll-disambiguate Γ t = nothing parse-string : (ll : exprd) → string → maybe ⟦ ll ⟧' parse-string ll s = case ll-ind {λ ll → string → Either string ⟦ ll ⟧'} parseTerm parseType parseKind ll s of λ {(Left e) → nothing; (Right e) → just e} ttk = "term, type, or kind" parse-err-msg : (failed-to-parse : string) → (as-a : string) → string parse-err-msg failed-to-parse "" = "Failed to parse \\\\\"" ^ failed-to-parse ^ "\\\\\"" parse-err-msg failed-to-parse as-a = "Failed to parse \\\\\"" ^ failed-to-parse ^ "\\\\\" as a " ^ as-a infixr 7 _>>nothing_ _-_!_>>parse_ _!_>>error_ _>>nothing_ : ∀{ℓ}{A : Set ℓ} → maybe A → maybe A → maybe A (nothing >>nothing m₂) = m₂ (m₁ >>nothing m₂) = m₁ _-_!_>>parse_ : ∀{A B : Set} → (string → maybe A) → string → (error-msg : string) → (A → string ⊎ B) → string ⊎ B (f - s ! e >>parse f') = maybe-else (inj₁ (parse-err-msg s e)) f' (f s) _!_>>error_ : ∀{E A B : Set} → maybe A → E → (A → E ⊎ B) → E ⊎ B (just a ! e >>error f) = f a (nothing ! e >>error f) = inj₁ e parse-try : ∀ {X : Set} → ctxt → string → maybe (((ll : exprd) → ⟦ ll ⟧' → X) → X) parse-try Γ s = maybe-map (λ t f → maybe-else (f TERM t) (f TYPE) (ll-disambiguate Γ t)) (parse-string TERM s) >>nothing maybe-map (λ T f → f TYPE T) (parse-string TYPE s) >>nothing maybe-map (λ k f → f KIND k) (parse-string KIND s) string-to-𝔹 : string → maybe 𝔹 string-to-𝔹 "tt" = just tt string-to-𝔹 "ff" = just ff string-to-𝔹 _ = nothing parse-ll : string → maybe exprd parse-ll "term" = just TERM parse-ll "type" = just TYPE parse-ll "kind" = just KIND parse-ll _ = nothing {- Local Context -} record lci : Set where constructor mk-lci field ll : string; x : var; t : string; T : string; fn : string; pi : posinfo data 𝕃ₛ {ℓ} (A : Set ℓ) : Set ℓ where [_]ₛ : A → 𝕃ₛ A _::ₛ_ : A → 𝕃ₛ A → 𝕃ₛ A headₛ : ∀ {ℓ} {A : Set ℓ} → 𝕃ₛ A → A headₛ [ a ]ₛ = a headₛ (a ::ₛ as) = a 𝕃ₛ-to-𝕃 : ∀ {ℓ} {A : Set ℓ} → 𝕃ₛ A → 𝕃 A 𝕃ₛ-to-𝕃 [ a ]ₛ = [ a ] 𝕃ₛ-to-𝕃 (a ::ₛ as) = a :: 𝕃ₛ-to-𝕃 as merge-lcis-ctxt-tvs : ctxt → 𝕃 string → ctxt × 𝕃 tagged-val merge-lcis-ctxt-tvs c = foldl merge-lcis-ctxt' (c , []) ∘ (sort-lcis ∘ strings-to-lcis) where strings-to-lcis : 𝕃 string → 𝕃 lci strings-to-lcis ss = strings-to-lcis-h ss [] where strings-to-lcis-h : 𝕃 string → 𝕃 lci → 𝕃 lci strings-to-lcis-h (ll :: x :: t :: T :: fn :: pi :: tl) items = strings-to-lcis-h tl (mk-lci ll x t T fn pi :: items) strings-to-lcis-h _ items = items -- TODO: Local context information does not pass Δ information! -- When users are using BR-explorer to rewrite with the rec function, -- if they call it upon "μ' [SUBTERM] {...}", it won't work unless they say -- "μ'<rec/mu> [SUBTERM] {...}". decl-lci : posinfo → var → ctxt → ctxt decl-lci pi x Γ = record Γ { qual = trie-insert (ctxt.qual Γ) x (pi % x , []) } exprd-type-of : exprd → exprd exprd-type-of TERM = TYPE exprd-type-of _ = KIND merge-lci-ctxt : lci → ctxt × 𝕃 tagged-val → ctxt × 𝕃 tagged-val merge-lci-ctxt (mk-lci ll v t T fn pi) (Γ , tvs) = maybe-else (Γ , tvs) (map-snd (λ tv → tvs ++ [ tv ])) (parse-ll ll >>= λ ll → parse-string (exprd-type-of ll) T >>= h ll (parse-string ll t)) where h : (ll : exprd) → maybe ⟦ ll ⟧' → ⟦ exprd-type-of ll ⟧' → maybe (ctxt × tagged-val) h TERM (just t) T = let t = elab-untyped Γ t T = elab-typed Γ T in return2 (ctxt-term-def pi localScope opacity-open v (just t) T Γ) (binder-data Γ pi v (Tkt T) ff (just t) "0" "0") h TYPE (just T) k = let T = elab-untyped Γ T k = elab-typed Γ k in return2 (ctxt-type-def pi localScope opacity-open v (just T) k Γ) (binder-data Γ pi v (Tkk k) ff (just T) "0" "0") h TERM nothing T = let T = elab-typed Γ T in return2 (ctxt-term-decl pi v T Γ) (binder-data Γ pi v (Tkt T) ff nothing "0" "0") h TYPE nothing k = let k = elab-typed Γ k in return2 (ctxt-type-decl pi v k Γ) (binder-data Γ pi v (Tkk k) ff nothing "0" "0") h _ _ _ = nothing merge-lcis-ctxt' : 𝕃ₛ lci → ctxt × 𝕃 tagged-val → ctxt × 𝕃 tagged-val merge-lcis-ctxt' ls (Γ , tvs) = let ls' = 𝕃ₛ-to-𝕃 ls in foldr merge-lci-ctxt (foldr (λ l → decl-lci (lci.pi l) (lci.x l)) Γ ls' , tvs) ls' sort-eq : ∀ {ℓ} {A : Set ℓ} → (A → A → compare-t) → 𝕃 A → 𝕃 (𝕃ₛ A) sort-eq {_} {A} c = foldr insert [] where insert : A → 𝕃 (𝕃ₛ A) → 𝕃 (𝕃ₛ A) insert n [] = [ [ n ]ₛ ] insert n (a :: as) with c (headₛ a) n ...| compare-eq = n ::ₛ a :: as ...| compare-gt = [ n ]ₛ :: a :: as ...| compare-lt = a :: insert n as sort-lcis : 𝕃 lci → 𝕃 (𝕃ₛ lci) sort-lcis = sort-eq λ l₁ l₂ → compare (posinfo-to-ℕ $ lci.pi l₁) (posinfo-to-ℕ $ lci.pi l₂) {- sort-lcis = list-merge-sort.merge-sort lci λ l l' → posinfo-to-ℕ (lci.pi l) > posinfo-to-ℕ (lci.pi l') where import list-merge-sort -} merge-lcis-ctxt : ctxt → 𝕃 string → ctxt merge-lcis-ctxt Γ ls = fst $ merge-lcis-ctxt-tvs Γ ls get-local-ctxt-tvs : ctxt → (pos : ℕ) → (local-ctxt : 𝕃 string) → ctxt × 𝕃 tagged-val get-local-ctxt-tvs Γ pi = merge-lcis-ctxt-tvs (foldr (flip ctxt-clear-symbol ∘ fst) Γ (flip filter (trie-mappings (ctxt.i Γ)) λ {(x , ci , fn' , pi') → ctxt.fn Γ =string fn' && posinfo-to-ℕ pi' > pi})) get-local-ctxt : ctxt → (pos : ℕ) → (local-ctxt : 𝕃 string) → ctxt get-local-ctxt Γ pi ls = fst (get-local-ctxt-tvs Γ pi ls) {- Helpers -} step-reduce : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧ step-reduce Γ t = let t' = erase t in maybe-else t' id (step-reduceh Γ t') where step-reduceh : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → maybe ⟦ ed ⟧ step-reduceh{TERM} Γ (Var x) = ctxt-lookup-term-var-def Γ x step-reduceh{TYPE} Γ (TpVar x) = ctxt-lookup-type-var-def Γ x step-reduceh{TERM} Γ (App (Lam ff x nothing t) t') = just (subst Γ t' x t) step-reduceh{TYPE} Γ (TpApp (TpLam x (Tkk _) T) (Ttp T')) = just (subst Γ T' x T) step-reduceh{TYPE} Γ (TpApp (TpLam x (Tkt _) T) (Ttm t)) = just (subst Γ t x T) step-reduceh{TERM} Γ (App t t') = step-reduceh Γ t >>= λ t → just (App t t') step-reduceh{TYPE} Γ (TpApp T tT) = step-reduceh Γ T >>= λ T → just (TpApp T tT) step-reduceh{TERM} Γ (Lam ff x nothing t) = step-reduceh (ctxt-var-decl x Γ) t >>= λ t → just (Lam ff x nothing t) step-reduceh{TYPE} Γ (TpLam x atk T) = step-reduceh (ctxt-var-decl x Γ) T >>= λ T → just (TpLam x atk T) step-reduceh{TERM} Γ (LetTm ff x T t' t) = just (subst Γ t' x t) step-reduceh{TERM} Γ t @ (Mu μ s Tₘ f~ ms) with decompose-var-headed s >>=c λ sₕ sₐs → env-lookup Γ sₕ ...| just (ctr-def _ _ _ _ _ , _) = just (hnf Γ unfold-head-no-defs t) ...| _ = step-reduceh Γ s >>= λ s → just (Mu μ s Tₘ f~ ms) step-reduceh Γ t = nothing parse-norm : erased? → string → maybe (∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧) parse-norm me "all" = just λ Γ → hnf Γ (record unfold-all {unfold-erase = me}) parse-norm me "head" = just λ Γ → hnf Γ (record unfold-all {unfold-erase = me}) parse-norm me "once" = just λ Γ → step-reduce Γ ∘ erase parse-norm _ _ = nothing parse-norm-err = "normalization method (all, head, once)" {- Command Executors -} normalize-cmd : ctxt → (str ll pi norm : string) → 𝕃 string → string ⊎ tagged-val normalize-cmd Γ str ll pi norm ls = parse-ll - ll ! "language-level" >>parse λ ll' → string-to-ℕ - pi ! "natural number" >>parse λ sp → parse-norm tt - norm ! parse-norm-err >>parse λ norm → parse-string ll' - str ! ll >>parse λ t → let Γ' = get-local-ctxt Γ sp ls in inj₂ (to-string-tag "" Γ' (norm Γ' (elab-untyped Γ' t))) normalize-prompt : ctxt → (str norm : string) → 𝕃 string → string ⊎ tagged-val normalize-prompt Γ str norm ls = parse-norm tt - norm ! parse-norm-err >>parse λ norm → let Γ' = merge-lcis-ctxt Γ ls in parse-try Γ' - str ! ttk >>parse λ f → f λ ll t → inj₂ (to-string-tag "" Γ' (norm Γ' (elab-untyped Γ' t))) erase-cmd : ctxt → (str ll pi : string) → 𝕃 string → string ⊎ tagged-val erase-cmd Γ str ll pi ls = parse-ll - ll ! "language-level" >>parse λ ll' → string-to-ℕ - pi ! "natural number" >>parse λ sp → parse-string ll' - str ! ll >>parse λ t → let Γ' = get-local-ctxt Γ sp ls in inj₂ (to-string-tag "" Γ' (erase (elab-untyped Γ' t))) erase-prompt : ctxt → (str : string) → 𝕃 string → string ⊎ tagged-val erase-prompt Γ str ls = let Γ' = merge-lcis-ctxt Γ ls in parse-try Γ' - str ! ttk >>parse λ f → f λ ll t → inj₂ (to-string-tag "" Γ' (erase (elab-untyped Γ' t))) -- private -- cmds-to-escaped-string : cmds → strM -- cmds-to-escaped-string (c :: cs) = cmd-to-string c $ strAdd "\\n\\n" >>str cmds-to-escaped-string cs -- cmds-to-escaped-string [] = strEmpty -- data-cmd : ctxt → (encoding name ps is cs : string) → string ⊎ tagged-val -- data-cmd Γ encodingₛ x psₛ isₛ csₛ = -- string-to-𝔹 - encodingₛ ! "boolean" >>parse λ encoding → -- parse-string KIND - psₛ ! "kind" >>parse λ psₖ → -- parse-string KIND - isₛ ! "kind" >>parse λ isₖ → -- parse-string KIND - csₛ ! "kind" >>parse λ csₖ → -- let ps = map (λ {(Index x atk) → Decl posinfo-gen posinfo-gen Erased x atk posinfo-gen}) $ kind-to-indices Γ psₖ -- cs = map (λ {(Index x (Tkt T)) → Ctr posinfo-gen x T; (Index x (Tkk k)) → Ctr posinfo-gen x $ mtpvar "ErrorExpectedTypeNotKind"}) $ kind-to-indices empty-ctxt csₖ -- is = kind-to-indices (add-ctrs-to-ctxt cs $ add-params-to-ctxt ps Γ) isₖ -- picked-encoding = if encoding then mendler-encoding else mendler-simple-encoding -- defs = datatype-encoding.mk-defs picked-encoding Γ $ Data x ps is cs in -- inj₂ $ strRunTag "" Γ $ cmds-to-escaped-string $ fst defs -- pretty-cmd : filepath → filepath → IO string -- pretty-cmd src-fn dest-fn = -- readFiniteFile src-fn >>= λ src → -- case parseStart src of λ where -- (Left (Left p)) → return ("Lexical error at position " ^ p) -- (Left (Right p)) → return ("Parse error at position " ^ p) -- (Right file) → writeFile dest-fn "" >> writeRopeToFile dest-fn (to-string.strRun empty-ctxt (to-string.file-to-string file)) >> return "Finished" -- where import to-string (record options {pretty-print = tt}) as to-string {- Commands -} tv-to-json : string ⊎ tagged-val → json tv-to-json (inj₁ s) = json-object [ "error" , json-string s ] -- [[ "{\"error\":\"" ]] ⊹⊹ [[ s ]] ⊹⊹ [[ "\"}" ]] tv-to-json (inj₂ (_ , v , ts)) = tagged-vals-to-json [ "value" , v , ts ] interactive-cmd-h : ctxt → 𝕃 string → string ⊎ tagged-val interactive-cmd-h Γ ("normalize" :: input :: ll :: sp :: norm :: lc) = normalize-cmd Γ input ll sp norm lc interactive-cmd-h Γ ("erase" :: input :: ll :: sp :: lc) = erase-cmd Γ input ll sp lc interactive-cmd-h Γ ("normalizePrompt" :: input :: norm :: lc) = normalize-prompt Γ input norm lc interactive-cmd-h Γ ("erasePrompt" :: input :: lc) = erase-prompt Γ input lc -- interactive-cmd-h Γ ("data" :: encoding :: x :: ps :: is :: cs :: []) = -- data-cmd Γ encoding x ps is cs interactive-cmd-h Γ cs = inj₁ ("Unknown interactive cmd: " ^ 𝕃-to-string (λ s → s) ", " cs) record br-history : Set where inductive constructor mk-br-history field Γ : ctxt t : term Tₗₗ : exprd T : ⟦ Tₗₗ ⟧ Tᵤ : string f : term → 𝕃 (ctr × term) → term Γₗ : 𝕃 tagged-val undo : 𝕃 br-history redo : 𝕃 br-history data br-history2 : Set where br-node : br-history → 𝕃 (ctr × br-history2) → br-history2 br-get-h : br-history2 → br-history br-get-h (br-node h hs) = h br-lookup : 𝕃 ℕ → br-history2 → maybe br-history br-lookup xs h = maybe-map br-get-h $ foldl (λ x h? → h? >>= λ {(br-node h hs) → maybe-map snd $ head2 (nthTail x hs)}) (just h) xs {-# TERMINATING #-} br-cmd2 : ctxt → string → string → string → 𝕃 string → IO ⊤ br-cmd2 Γ Tₛ tₛ sp ls = (string-to-ℕ - sp ! "natural number" >>parse inj₂) >>parseIO λ sp → elim-pair (get-local-ctxt-tvs Γ sp ls) λ Γ Γₗ → (parse-try Γ - Tₛ ! ttk >>parse inj₂) >>parseIO λ Tf → Tf λ Tₗₗ T → (parse-string TERM - tₛ ! "term" >>parse inj₂) >>parseIO λ t → let T = elab-untyped Γ T Tₑ = erase T t = elab-typed Γ t in -- TODO: Probably should switch back to ex-tm so if this doesn't currently check it won't elaborate to a hole! putJson (tv-to-json $ inj₂ $ ts-tag Γ Tₑ) >> await (br-node (mk-br-history Γ t Tₗₗ T (rope-to-string $ ts2.to-string Γ Tₑ) const Γₗ [] []) []) where import to-string (record options {erase-types = ff}) as ts2 import to-string (record options {erase-types = ff; pretty-print = tt}) as pretty2s ts-tag : ∀ {ed} → ctxt → ⟦ ed ⟧ → tagged-val ts-tag = ts2.to-string-tag "" infixr 6 _>>parseIO_ _>>parseIO_ : ∀ {A : Set} → string ⊎ A → (A → IO ⊤) → IO ⊤ inj₁ e >>parseIO f = putJson $ tv-to-json $ inj₁ e inj₂ a >>parseIO f = f a replace-substring : string → string → ℕ → ℕ → string × string replace-substring sₒ sᵣ fm to with string-to-𝕃char sₒ | string-to-𝕃char sᵣ ...| csₒ | csᵣ = 𝕃char-to-string (take fm csₒ ++ csᵣ ++ drop to csₒ) , 𝕃char-to-string (take (to ∸ fm) $ drop fm csₒ) replace : string → string → ℕ → ℕ → string replace sₒ sᵣ fm to = fst $ replace-substring sₒ sᵣ fm to substring : string → ℕ → ℕ → string substring s fm to = snd $ replace-substring s "" fm to escape-rope : rope → rope escape-rope [[ s ]] = [[ escape-string s ]] escape-rope (r₁ ⊹⊹ r₂) = escape-rope r₁ ⊹⊹ escape-rope r₂ parse-path : string → maybe (𝕃 ℕ) parse-path "" = just [] parse-path s with string-split s ' ' | foldr (λ n ns → ns >>= λ ns → string-to-ℕ n >>= λ n → just (n :: ns)) (just []) ...| "" :: ss | f = f ss ...| path | f = f path write-history : 𝕃 ℕ → br-history → br-history2 → br-history2 write-history [] h (br-node _ hs) = br-node h hs write-history (n :: ns) h (br-node hₒ hs) = br-node hₒ $ writeh n hs where writeh : ℕ → 𝕃 (ctr × br-history2) → 𝕃 (ctr × br-history2) writeh _ [] = [] writeh zero ((c , h') :: hs) = (c , write-history ns h h') :: hs writeh (suc n) (h' :: hs) = h' :: writeh n hs write-children : 𝕃 ℕ → 𝕃 (ctr × br-history) → br-history2 → br-history2 write-children [] hs (br-node h _) = br-node h (map (uncurry λ c h → c , br-node h []) hs) write-children (n :: ns) hs (br-node h hsₒ) = br-node h $ writeh n hsₒ where writeh : ℕ → 𝕃 (ctr × br-history2) → 𝕃 (ctr × br-history2) writeh _ [] = [] writeh zero ((c , h') :: hs') = (c , write-children ns hs h') :: hs' writeh (suc n) (h' :: hs) = h' :: writeh n hs outline : br-history2 → term -- outline (br-node (mk-br-history Γ t TYPE T Tₛ f Γₗ undo redo) []) = -- elim-pair (id-out $ check-term Γ t (just T) empty-spans) λ t~ ss → f t~ [] -- outline (br-node (mk-br-history Γ t Tₗₗ T Tₛ f Γₗ undo redo) []) = f (elab-untyped-no-params Γ t) [] -- outline (br-node (mk-br-history Γ t Tₗₗ T Tₛ f Γₗ undo redo) hs) = -- f (elab-typed Γ t) (map (uncurry λ c h → c , outline h) hs) outline (br-node (mk-br-history Γ t Tₗₗ T Tₛ f Γₗ undo redo) hs) = f t (map-snd outline <$> hs) make-case : ctxt → params → term → case-args × term make-case = h [] where h : params → ctxt → params → term → case-args × term h acc Γ (Param me x atk :: ps) (Lam me' x' oc' t') = h (Param me x' atk :: acc) (ctxt-var-decl x' Γ) (substh-params Γ (renamectxt-single x x') empty-trie ps) t' h acc Γ ps (Hole pi) = params-to-case-args (reverse acc ++ ps) , Hole pi h acc Γ ps t = params-to-case-args (reverse acc ++ ps) , params-to-apps ps t await : br-history2 → IO ⊤ awaith : br-history2 → 𝕃 string → IO ⊤ await his = getLine >>= λ input → let input = undo-escape-string input as = string-split input delimiter in awaith his as awaith his as = let put = putJson ∘ tv-to-json err = (_>> await his) ∘' put ∘' inj₁ in case as of λ where -- TODO: for these commands, do not add TYPES/KINDS of local decls to context, as they are probably just bound by foralls/pis/lambdas, not _really_ in scope! ("br" :: path :: as) → maybe-else' (parse-path path) (err ("Could not parse " ^ path ^ " as a list of space-delimited natural numbers")) λ path → let await-with = await ∘ flip (write-history path) his in maybe-else' (br-lookup path his) (err "Beta-reduction pointer does not exist") λ where this @ (mk-br-history Γ t Tₗₗ T Tᵤ f Γₗ undo redo) → case as of λ where ("undo" :: []) → case undo of λ where [] → err "No undo history" (u :: us) → put (inj₂ $ "" , [[ "Undo" ]] , []) >> await-with (record u {undo = us; redo = this :: redo}) --u (await Γ t Tₗₗ T Tᵤ f undo redo :: redo) ("redo" :: []) → case redo of λ where [] → err "No redo history" (r :: rs) → put (inj₂ $ "" , [[ "Redo" ]] , []) >> await-with (record r {undo = this :: undo; redo = rs}) --r ("get" :: []) → put (inj₂ $ "" , [[ Tᵤ ]] , []) >> await his ("parse" :: []) → (_>> await his) $ maybe-else' (parse-string Tₗₗ Tᵤ) (putJson $ spans-to-json $ global-error "Parse error" nothing) λ T → putJson $ spans-to-json $ snd $ id-out $ ll-ind {λ ll → ctxt → ⟦ ll ⟧' → spanM ⟦ ll ⟧} untyped-term untyped-type untyped-kind Tₗₗ (record Γ { fn = "missing" }) T empty-spans ("context" :: []) → putJson (json-object [ "value" , json-array [ tagged-vals-to-json Γₗ ] ]) >> await his ("check" :: t?) → let await-set = maybe-else (await his) λ t → await-with $ record this {t = t; undo = this :: undo; redo = []} in (λ e → either-else' e (uncurry λ t? e → put (inj₁ e) >> await-set t?) (uncurry λ t? m → put (inj₂ $ "value" , [[ m ]] , []) >> await-set t?)) $ ll-ind' {λ T → (maybe term × string) ⊎ (maybe term × string)} (Tₗₗ , T) (λ _ → inj₁ $ nothing , "Expression must be a type, not a term!") (λ T → (case t? of λ where [] → inj₂ nothing (t :: []) → maybe-else' (parse-string TERM t) (inj₁ $ nothing , parse-err-msg t "term") (inj₂ ∘ just) _ → inj₁ $ nothing , "To many arguments given to beta-reduction command 'check'") >>= λ t? → elim-pair (maybe-else' t? (elim-pair (id-out (check-term (qualified-ctxt Γ) (resugar t) (just T) empty-spans)) λ t~ ss → nothing , spans-have-error ss) λ t → elim-pair (id-out (check-term Γ t (just T) empty-spans)) λ t~ ss → just t~ , spans-have-error ss) λ t~? e? → let fail = inj₁ (just (maybe-else' t~? t id) , "Type error") try-β = elim-pair (id-out (check-term Γ (ExBeta pi-gen nothing nothing) (just T) empty-spans)) λ β~ ss → if spans-have-error ss then inj₁ (nothing , "Type error") else inj₂ (just β~ , "Equal by beta") in if e? then if isJust t? then fail else try-β else inj₂ (t~? , "Type inhabited")) (λ _ → inj₁ $ nothing , "Expression must be a type, not a kind!") ("rewrite" :: fm :: to :: eq :: ρ+? :: lc) → let Γ' = merge-lcis-ctxt Γ lc in either-else' (parse-string TERM - eq ! "term" >>parse λ eqₒ → string-to-𝔹 - ρ+? ! "boolean" >>parse λ ρ+? → string-to-ℕ - fm ! "natural number" >>parse λ fm → string-to-ℕ - to ! "natural number" >>parse λ to → parse-try Γ' - substring Tᵤ fm to ! ttk >>parse λ Tf → Tf λ ll Tₗ → elim-pair (id-out (check-term Γ' eqₒ nothing empty-spans)) $ uncurry λ eq Tₑ ss → is-eq-tp? Tₑ ! "Synthesized a non-equational type from the proof" >>error uncurry λ t₁ t₂ → err⊎-guard (spans-have-error ss) "Proof does not type check" >> let Tₑ = TpEq t₁ t₂ x = fresh-var Γ' "x" Tₗ = elab-untyped-no-params Γ' Tₗ in elim-pair (map-snd snd $ rewrite-exprd Tₗ Γ' ρ+? nothing (just eq) t₁ x 0) λ Tᵣ n → err⊎-guard (iszero n) "No rewrites could be performed" >> parse-string Tₗₗ - replace Tᵤ (rope-to-string $ [[ "(" ]] ⊹⊹ ts2.to-string Γ' Tᵣ ⊹⊹ [[ ")" ]]) fm to ! ll-ind "term" "type" "kind" Tₗₗ >>parse λ Tᵤ → let Tᵤ = elab-untyped-no-params (ctxt-var-decl x Γ) Tᵤ in ll-ind' {λ {(ll , T) → ⟦ ll ⟧ → string ⊎ ⟦ ll ⟧ × (term → term)}} (Tₗₗ , Tᵤ) (λ t T → inj₂ $ rewrite-mk-phi x eq T (subst Γ t₂ x t) , id) (λ Tᵤ _ → inj₂ $ post-rewrite (ctxt-var-decl x Γ) x eq t₂ Tᵤ , Rho eq x Tᵤ) (λ k _ → inj₂ $ subst Γ t₂ x k , id) T) err $ uncurry λ T' fₜ → put (inj₂ $ ts-tag Γ $ erase T') >> await-with (record this {T = T'; Tᵤ = rope-to-string $ ts2.to-string Γ $ erase T'; f = f ∘ fₜ; undo = this :: undo; redo = []}) ("normalize" :: fm :: to :: norm :: lc) → either-else' (let Γ' = merge-lcis-ctxt Γ lc in string-to-ℕ - fm ! "natural number" >>parse λ fm → string-to-ℕ - to ! "natural number" >>parse λ to → let tₛ = substring Tᵤ fm to in parse-try Γ' - tₛ ! ttk >>parse λ t → t λ ll t → parse-norm ff - norm ! parse-norm-err >>parse λ norm → let s = norm Γ' $ elab-untyped-no-params Γ' t rs = rope-to-string $ [[ "(" ]] ⊹⊹ ts2.to-string Γ' s ⊹⊹ [[ ")" ]] Tᵤ' = replace Tᵤ rs fm to in parse-string Tₗₗ - Tᵤ' ! ll-ind "term" "type" "kind" Tₗₗ >>parse λ Tᵤ' → let Tᵤ' = elab-untyped-no-params Γ' Tᵤ' in inj₂ Tᵤ') err λ Tᵤ' → put (inj₂ $ ts-tag Γ Tᵤ') >> await-with (record this {T = Tᵤ' {-Checks?-}; Tᵤ = rope-to-string $ ts2.to-string Γ $ erase Tᵤ'; undo = this :: undo; redo = []}) ("conv" :: ll :: fm :: to :: t' :: ls) → let Γ' = merge-lcis-ctxt Γ ls in either-else' (parse-ll - ll ! "language level" >>parse λ ll → string-to-ℕ - fm ! "natural number" >>parse λ fm → string-to-ℕ - to ! "natural number" >>parse λ to → let t = substring Tᵤ fm to in parse-string ll - t ! ll-ind "term" "type" "kind" ll >>parse λ t → parse-string ll - t' ! ll-ind "term" "type" "kind" ll >>parse λ t' → let t = elab-untyped-no-params Γ' t; t' = elab-untyped-no-params Γ' t' in err⊎-guard (~ ll-ind {λ ll → ctxt → ⟦ ll ⟧ → ⟦ ll ⟧ → 𝔹} conv-term conv-type conv-kind ll Γ' t t') "Inconvertible" >> let rs = [[ "(" ]] ⊹⊹ ts2.to-string Γ' (erase t') ⊹⊹ [[ ")" ]] Tᵤ = replace Tᵤ (rope-to-string rs) fm to in parse-string Tₗₗ - Tᵤ ! ll-ind "term" "type" "kind" Tₗₗ >>parse λ Tᵤ → inj₂ (elab-untyped-no-params Γ Tᵤ)) err λ Tᵤ' → put (inj₂ $ ts-tag Γ $ erase Tᵤ') >> await-with (record this {Tᵤ = rope-to-string $ ts2.to-string Γ $ erase Tᵤ'; undo = this :: undo; redo = []}) ("bind" :: xᵤ :: []) → let Γₚᵢ = ℕ-to-string (length Γₗ) in either-else' (ll-ind' {λ {(ll , _) → string ⊎ ctxt × erased? × tpkd × ⟦ ll ⟧ × (term → term)}} (Tₗₗ , T) (λ t' → let R = string ⊎ ctxt × erased? × tpkd × term × (term → term) in (case_of_ {B = (erased? → var → maybe tpkd → term → R) → R} (t' , hnf Γ unfold-head t') $ uncurry λ where (Lam me x oc body) _ f → f me x oc body _ (Lam me x oc body) f → f me x oc body _ _ _ → inj₁ "Not a term abstraction") λ me x oc body → inj₂ $ ctxt-var-decl-loc Γₚᵢ xᵤ Γ , me , maybe-else' oc (Tkt $ TpHole pi-gen) id , rename-var (ctxt-var-decl-loc Γₚᵢ xᵤ Γ) x xᵤ body , Lam me xᵤ oc) (λ T → Γ ⊢ T =β= λ where (TpAbs me x dom cod) → let Γ' = ctxt-tk-decl Γₚᵢ xᵤ dom Γ in inj₂ $ Γ' , me , dom , rename-var Γ' x (Γₚᵢ % xᵤ) cod , Lam me xᵤ (just dom) _ → inj₁ "Not a type abstraction") (λ k → inj₁ "Expression must be a term or a type")) err λ where (Γ' , me , dom , cod , fₜ) → let tv = binder-data Γ' Γₚᵢ xᵤ dom me nothing "0" "0" in -- putJson (json-object [ "value" , json-array (json-array (json-rope (fst (snd tv)) :: json-rope (to-string Γ' $ erase cod) :: []) :: []) ]) >> putJson (json-object [ "value" , json-array [ json-rope (to-string Γ' $ erase cod) ] ]) >> await-with (record this {Γ = Γ' ; T = cod; Tᵤ = rope-to-string $ ts2.to-string Γ' $ erase cod; f = f ∘ fₜ; Γₗ = Γₗ ++ [ tv ]; undo = this :: undo; redo = []}) ("case" :: scrutinee :: rec :: motive?) → -- TODO: Motive? let Γₚᵢ = ℕ-to-string (length Γₗ) in either-else' (parse-string TERM - scrutinee ! "term" >>parse λ scrutinee → elim-pair (id-out (check-term Γ scrutinee nothing empty-spans)) $ uncurry λ tₛ Tₛ ss → if (spans-have-error ss) then inj₁ "Error synthesizing a type from the input term" else let Tₛ = hnf Γ unfold-no-defs Tₛ in case decompose-ctr-type Γ Tₛ of λ where (TpVar Xₛ , [] , as) → ll-ind' {λ T → string ⊎ (term × term × 𝕃 (ctr × type) × type × ctxt × 𝕃 tagged-val × datatype-info)} (Tₗₗ , T) (λ t → inj₁ "Expression must be a type to case split") (λ T → maybe-else' (data-lookup Γ Xₛ as) (inj₁ "The synthesized type of the input term is not a datatype") λ d → let mk-data-info X _ asₚ asᵢ ps kᵢ k cs csₚₛ _ _ = d is' = kind-to-indices (add-params-to-ctxt ps Γ) kᵢ is = drop-last 1 is' Tₘ = refine-motive Γ is' (asᵢ ++ [ Ttm tₛ ]) T sM' = ctxt-mu-decls Γ tₛ is Tₘ d Γₚᵢ "0" "0" rec σ = λ y → inst-ctrs Γ ps asₚ (map-snd (rename-var {TYPE} Γ X y) <$> cs) sM = if rec =string "" then (σ X , const spanMok , Γ , [] , empty-renamectxt , (λ Γ t T → t) , (λ Γ T k → T)) else (σ (Γₚᵢ % mu-Type/ rec) , sM') mu = sigma-build-evidence Xₛ d in case sM of λ where (σ-cs , _ , Γ' , ts , ρ , tf , Tf) → if spans-have-error (snd $ id-out $ check-type (qualified-ctxt Γ) (resugar Tₘ) (just kᵢ) empty-spans) then inj₁ "Computed an ill-typed motive" else inj₂ ( tₛ , mu , map (λ {(Ctr x T) → let T' = hnf Γ' unfold-head-elab T in Ctr x T , (case decompose-ctr-type Γ' T' of λ {(Tₕ , ps' , as) → params-to-alls ps' $ hnf Γ' unfold-head-no-defs (TpApp (recompose-tpapps (drop (length ps) as) Tₘ) (Ttm (recompose-apps (params-to-args ps') $ recompose-apps asₚ (Var x))))})}) σ-cs , Tₘ , Γ' , ts , d)) (λ k → inj₁ "Expression must be a type to case split") (Tₕ , [] , as) → inj₁ "Synthesized a non-datatype from the input term" (Tₕ , ps , as) → inj₁ "Case splitting is currently restricted to datatypes") err $ λ where (scrutinee , mu , cs , Tₘ , Γ , ts , d) → let json = json-object [ "value" , json-array [ json-object (map (λ {(Ctr x _ , T) → unqual-all (ctxt.qual Γ) x , json-rope (to-string Γ (erase T))}) cs) ] ] in -- ) ] ] in putJson json >> let shallow = iszero (string-length rec) mk-cs = map λ where (Ctr x T , t) → let T' = hnf Γ unfold-head-elab T in case decompose-ctr-type Γ T' of λ where (Tₕ , ps , as) → elim-pair (make-case Γ ps t) λ cas t → Case x cas t [] f'' = λ t cs → (if shallow then Mu rec else Sigma (just mu)) t (just Tₘ) d (mk-cs cs) f' = λ t cs → f (f'' t cs) cs mk-hs = map $ map-snd λ T'' → mk-br-history Γ t TYPE T'' (rope-to-string $ to-string Γ $ erase T'') (λ t cs → t) (Γₗ ++ ts) [] [] in await (write-children path (mk-hs cs) $ write-history path (record this {f = f'; Γ = Γ; t = scrutinee; Γₗ = Γₗ ++ ts;-- TODO: Should we really do this? undo = this :: undo; redo = []}) his) ("print" :: tab :: []) → either-else' (string-to-ℕ - tab ! "natural number" >>parse inj₂) err λ tab → putRopeLn (escape-rope (json-to-rope (tv-to-json (inj₂ $ pretty2s.strRunTag "" Γ $ pretty2s.strNest (suc {-left paren-} tab) (pretty2s.to-stringh $ outline his))))) >> await his ("quit" :: []) → put $ inj₂ $ strRunTag "" Γ $ strAdd "Quitting beta-reduction mode..." _ → err $ foldl (λ a s → s ^ char-to-string delimiter ^ a) "Unknown beta-reduction command: " as _ → err "A beta-reduction buffer is still open" interactive-cmd : 𝕃 string → toplevel-state → IO ⊤ interactive-cmd ("br2" :: T :: t :: sp :: lc) ts = br-cmd2 (toplevel-state.Γ ts) T t sp lc --interactive-cmd ("pretty" :: src :: dest :: []) ts = pretty-cmd src dest >>= putStrLn interactive-cmd ls ts = putRopeLn (json-to-rope (tv-to-json (interactive-cmd-h (toplevel-state.Γ ts) ls))) interactive-not-br-cmd-msg = tv-to-json $ inj₁ "Beta-reduction mode has been terminated"
50.064649
227
0.495068
31eced17eb01e560599933b828a6c1f5c8aa9a24
2,349
agda
Agda
test/Compiler/simple/CompileNumbers.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/CompileNumbers.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/CompileNumbers.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS -v treeless.opt:20 #-} module _ where open import Agda.Builtin.Nat using (_<_) open import Common.Prelude open import Common.Integer -- Should compile to -- λ a b → case a of -- "neg" → 0 - b -- _ → b match-on-lit : String → Integer → Integer match-on-lit "neg" x with x ... | pos (suc n) = negsuc n ... | pos 0 = pos 0 ... | negsuc n = pos (suc n) match-on-lit _ x = x -- This doesn't compile as nicely, since the match on "neg" -- ends up between the match on the int and the nat (not sure why). match-on-lit₂ : String → Integer → Integer match-on-lit₂ "neg" (pos (suc n)) = negsuc n match-on-lit₂ "neg" (negsuc n) = pos (suc n) match-on-lit₂ _ x = x -- Should compile to a flat case nested-match : Integer → String nested-match (pos 0) = "zero" nested-match (pos 1) = "one" nested-match (pos (suc (suc n))) = "lots" nested-match (negsuc 0) = "minus one" nested-match (negsuc 1) = "minus two" nested-match (negsuc (suc (suc n))) = "minus lots" data Diff : Set where less : Nat → Diff equal : Diff greater : Nat → Diff compareNat : Nat → Nat → Diff compareNat a b with a < b ... | true = less (b ∸ suc a) ... | false with b < a ... | true = greater (a ∸ suc b) ... | false = equal {-# INLINE compareNat #-} -- Should compile to 0 - a neg : Nat → Integer neg zero = pos zero neg (suc a) = negsuc a {-# INLINE neg #-} -- Should compile to a - b _-N_ : Nat → Nat → Integer a -N b with compareNat a b ... | less k = negsuc k ... | equal = pos (a ∸ b) ... | greater k = pos (suc k) {-# INLINE _-N_ #-} -- Should compile to a + b _+Z_ : Integer → Integer → Integer pos a +Z pos b = pos (a + b) pos a +Z negsuc b = a -N suc b negsuc a +Z pos b = b -N suc a negsuc a +Z negsuc b = negsuc (suc a + b) {-# INLINE _+Z_ #-} -- Should compile to a * b _*Z_ : Integer → Integer → Integer pos a *Z pos b = pos (a * b) pos a *Z negsuc b = neg (a * suc b) negsuc a *Z pos b = neg (suc a * b) negsuc a *Z negsuc b = pos (suc a * suc b) {-# INLINE _*Z_ #-} printInt : Integer → IO Unit printInt x = putStrLn (intToString x) main : IO Unit main = printInt (match-on-lit "neg" (pos 42)) ,, printInt (match-on-lit₂ "neg" (pos 42)) ,, putStrLn (nested-match (negsuc 5))
27.635294
67
0.572584
d07b83666e9cec5f2a02717fa52cf5184fd318b7
6,608
agda
Agda
Lambda/Substitution.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
1
2021-02-13T14:48:45.000Z
2021-02-13T14:48:45.000Z
Lambda/Substitution.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
Lambda/Substitution.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Substitutions ------------------------------------------------------------------------ module Lambda.Substitution where open import Data.Fin using (Fin; zero; suc) open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Nat open import Data.Product open import Data.Unit open import Data.Vec as Vec open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (Star; ε; _◅_) open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂) open PropEq.≡-Reasoning open import Lambda.Syntax ------------------------------------------------------------------------ -- Substitutions -- Code for applying substitutions. module TmApp {T : ℕ → Set} (l : Lift T Tm) where open Lift l hiding (var) -- Applies a substitution to a term. infix 8 _/_ _/_ : ∀ {m n} → Tm m → Sub T m n → Tm n con i / ρ = con i var x / ρ = lift (lookup ρ x) ƛ t / ρ = ƛ (t / ρ ↑) t₁ · t₂ / ρ = (t₁ / ρ) · (t₂ / ρ) open Application (record { _/_ = _/_ }) using (_/✶_) -- Some lemmas about _/_. con-/✶-↑✶ : ∀ k {m n i} (ρs : Subs T m n) → con i /✶ ρs ↑✶ k ≡ con i con-/✶-↑✶ k ε = refl con-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (con-/✶-↑✶ k ρs) refl ƛ-/✶-↑✶ : ∀ k {m n t} (ρs : Subs T m n) → ƛ t /✶ ρs ↑✶ k ≡ ƛ (t /✶ ρs ↑✶ suc k) ƛ-/✶-↑✶ k ε = refl ƛ-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (ƛ-/✶-↑✶ k ρs) refl ·-/✶-↑✶ : ∀ k {m n t₁ t₂} (ρs : Subs T m n) → t₁ · t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) · (t₂ /✶ ρs ↑✶ k) ·-/✶-↑✶ k ε = refl ·-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (·-/✶-↑✶ k ρs) refl tmSubst : TermSubst Tm tmSubst = record { var = var; app = TmApp._/_ } open TermSubst tmSubst hiding (var) -- Substitution lemmas. tmLemmas : TermLemmas Tm tmLemmas = record { termSubst = tmSubst ; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ } where module Lemma {T₁ T₂} {lift₁ : Lift T₁ Tm} {lift₂ : Lift T₂ Tm} where open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) /✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) → (∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) → ∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k /✶-↑✶ ρs₁ ρs₂ hyp k (con i) = begin con i /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.con-/✶-↑✶ _ k ρs₁ ⟩ con i ≡⟨ sym (TmApp.con-/✶-↑✶ _ k ρs₂) ⟩ con i /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x /✶-↑✶ ρs₁ ρs₂ hyp k (ƛ t) = begin ƛ t /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.ƛ-/✶-↑✶ _ k ρs₁ ⟩ ƛ (t /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong ƛ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) t) ⟩ ƛ (t /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (TmApp.ƛ-/✶-↑✶ _ k ρs₂) ⟩ ƛ t /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (t₁ · t₂) = begin t₁ · t₂ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.·-/✶-↑✶ _ k ρs₁ ⟩ (t₁ /✶₁ ρs₁ ↑✶₁ k) · (t₂ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ ρs₁ ρs₂ hyp k t₁) (/✶-↑✶ ρs₁ ρs₂ hyp k t₂) ⟩ (t₁ /✶₂ ρs₂ ↑✶₂ k) · (t₂ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (TmApp.·-/✶-↑✶ _ k ρs₂) ⟩ t₁ · t₂ /✶₂ ρs₂ ↑✶₂ k ∎ ------------------------------------------------------------------------ -- Types -- Well-typed substitutions. infixr 5 _∷_ infix 4 _⇒_⊢_ data _⇒_⊢_ {n} : ∀ {m} → Ctxt m → Ctxt n → Sub Tm m n → Set where [] : ∀ {Δ} → [] ⇒ Δ ⊢ [] _∷_ : ∀ {m} {Γ : Ctxt m} {Δ σ t ρ} (t∈ : Δ ⊢ t ∈ σ) (⊢ρ : Γ ⇒ Δ ⊢ ρ) → σ ∷ Γ ⇒ Δ ⊢ t ∷ ρ -- Some preservation properties. The lemma duplication below -- (Var.↑-preserves/↑-preserves, Var.id-preserves/id-preserves, etc.) -- can perhaps be avoided. module Var where map-suc-preserves : ∀ {m n Γ Δ σ} (ρ : Sub Fin m n) → Γ ⇒ Δ ⊢ Vec.map var ρ → Γ ⇒ σ ∷ Δ ⊢ Vec.map var (Vec.map suc ρ) map-suc-preserves [] [] = [] map-suc-preserves (x ∷ ρ) (var ∷ ⊢ρ) = var ∷ map-suc-preserves ρ ⊢ρ ↑-preserves : ∀ {m n Γ Δ σ} {ρ : Sub Fin m n} → Γ ⇒ Δ ⊢ Vec.map var ρ → σ ∷ Γ ⇒ σ ∷ Δ ⊢ Vec.map var (VarSubst._↑ ρ) ↑-preserves ⊢ρ = var ∷ map-suc-preserves _ ⊢ρ id-preserves : ∀ {n} {Γ : Ctxt n} → Γ ⇒ Γ ⊢ Vec.map var VarSubst.id id-preserves {Γ = []} = [] id-preserves {Γ = _ ∷ _} = ↑-preserves id-preserves wk-preserves : ∀ {n} {Γ : Ctxt n} {σ} → Γ ⇒ σ ∷ Γ ⊢ Vec.map var VarSubst.wk wk-preserves = map-suc-preserves VarSubst.id id-preserves lookup-preserves : ∀ {m n} {Γ : Ctxt m} {Δ : Ctxt n} x ρ → Γ ⇒ Δ ⊢ Vec.map var ρ → Δ ⊢ var (lookup ρ x) ∈ lookup Γ x lookup-preserves zero (y ∷ ρ) (var ∷ ⊢ρ) = var lookup-preserves (suc x) (y ∷ ρ) (var ∷ ⊢ρ) = lookup-preserves x ρ ⊢ρ /-preserves : ∀ {m n} {Γ : Ctxt m} {Δ : Ctxt n} {σ t ρ} → Γ ⊢ t ∈ σ → Γ ⇒ Δ ⊢ Vec.map var ρ → Δ ⊢ t /Var ρ ∈ σ /-preserves con ⊢ρ = con /-preserves (var {x = x}) ⊢ρ = lookup-preserves x _ ⊢ρ /-preserves (ƛ t∈) ⊢ρ = ƛ (/-preserves t∈ (↑-preserves ⊢ρ)) /-preserves (t₁∈ · t₂∈) ⊢ρ = /-preserves t₁∈ ⊢ρ · /-preserves t₂∈ ⊢ρ weaken-preserves : ∀ {n Γ σ τ} {t : Tm n} → Γ ⊢ t ∈ τ → σ ∷ Γ ⊢ weaken t ∈ τ weaken-preserves t∈ = Var./-preserves t∈ Var.wk-preserves map-weaken-preserves : ∀ {m n Γ Δ σ} {ρ : Sub Tm m n} → Γ ⇒ Δ ⊢ ρ → Γ ⇒ σ ∷ Δ ⊢ Vec.map weaken ρ map-weaken-preserves [] = [] map-weaken-preserves (t∈ ∷ ⊢ρ) = weaken-preserves t∈ ∷ map-weaken-preserves ⊢ρ ↑-preserves : ∀ {m n Γ Δ σ} {ρ : Sub Tm m n} → Γ ⇒ Δ ⊢ ρ → σ ∷ Γ ⇒ σ ∷ Δ ⊢ ρ ↑ ↑-preserves ⊢ρ = var ∷ map-weaken-preserves ⊢ρ id-preserves : ∀ {n} {Γ : Ctxt n} → Γ ⇒ Γ ⊢ id id-preserves {Γ = []} = [] id-preserves {Γ = _ ∷ _} = ↑-preserves id-preserves sub-preserves : ∀ {n} {Γ : Ctxt n} {σ t} → Γ ⊢ t ∈ σ → σ ∷ Γ ⇒ Γ ⊢ sub t sub-preserves t∈ = t∈ ∷ id-preserves lookup-preserves : ∀ {m n} {Γ : Ctxt m} {Δ : Ctxt n} x {ρ} → Γ ⇒ Δ ⊢ ρ → Δ ⊢ lookup ρ x ∈ lookup Γ x lookup-preserves zero (t∈ ∷ ⊢ρ) = t∈ lookup-preserves (suc x) (t∈ ∷ ⊢ρ) = lookup-preserves x ⊢ρ /-preserves : ∀ {m n} {Γ : Ctxt m} {Δ : Ctxt n} {σ t ρ} → Γ ⊢ t ∈ σ → Γ ⇒ Δ ⊢ ρ → Δ ⊢ t / ρ ∈ σ /-preserves con ⊢ρ = con /-preserves (var {x = x}) ⊢ρ = lookup-preserves x ⊢ρ /-preserves (ƛ t∈) ⊢ρ = ƛ (/-preserves t∈ (↑-preserves ⊢ρ)) /-preserves (t₁∈ · t₂∈) ⊢ρ = /-preserves t₁∈ ⊢ρ · /-preserves t₂∈ ⊢ρ ------------------------------------------------------------------------ -- Name-space management open TermLemmas tmLemmas public hiding (var)
34.962963
86
0.470339
0e4f27a30cdc743123c9c17d65b0b68bcca11c72
3,450
agda
Agda
archive/agda-2/Oscar/Data/Fin.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-2/Oscar/Data/Fin.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-2/Oscar/Data/Fin.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module Oscar.Data.Fin where open import Data.Fin public using (Fin; zero; suc) -- open import Oscar.Data.Fin.Core public -- --open import Data.Fin hiding (thin; thick; check) public -- --open import Data.Fin.Properties hiding (thin-injective; thick-thin; thin-check-id) public -- -- module _ where -- -- open import Data.Product -- -- open import Oscar.Data.Vec -- -- open import Data.Nat -- -- open import Function -- -- enumFin⋆ : ∀ n → ∃ λ (F : Vec (Fin n) n) → ∀ f → f ∈ F -- -- enumFin⋆ n = tabulate⋆ id -- -- open import Agda.Builtin.Equality -- -- open import Agda.Builtin.Nat -- -- open import Relation.Binary.PropositionalEquality -- -- open import Relation.Nullary -- -- open import Data.Product -- -- open import Data.Empty -- -- open import Function -- -- previous : ∀ {n} -> Fin (suc (suc n)) -> Fin (suc n) -- -- previous (suc x) = x -- -- previous zero = zero -- -- module Thin where -- -- fact1 : ∀ {n} x y z -> thin {n} x y ≡ thin x z -> y ≡ z -- -- fact1 zero y .y refl = refl -- -- fact1 (suc x) zero zero r = refl -- -- fact1 (suc x) zero (suc z) () -- -- fact1 (suc x) (suc y) zero () -- -- fact1 (suc x) (suc y) (suc z) r = cong suc (fact1 x y z (cong previous r)) -- -- fact2 : ∀ {n} x y -> ¬ thin {n} x y ≡ x -- -- fact2 zero y () -- -- fact2 (suc x) zero () -- -- fact2 (suc x) (suc y) r = fact2 x y (cong previous r) -- -- fact3 : ∀{n} x y -> ¬ x ≡ y -> ∃ λ y' -> thin {n} x y' ≡ y -- -- fact3 zero zero ne = ⊥-elim (ne refl) -- -- fact3 zero (suc y) _ = y , refl -- -- fact3 {zero} (suc ()) _ _ -- -- fact3 {suc n} (suc x) zero ne = zero , refl -- -- fact3 {suc n} (suc x) (suc y) ne with y | fact3 x y (ne ∘ cong suc) -- -- ... | .(thin x y') | y' , refl = suc y' , refl -- -- open import Data.Maybe -- -- open import Category.Functor -- -- open import Category.Monad -- -- import Level -- -- open RawMonad (Data.Maybe.monad {Level.zero}) -- -- open import Data.Sum -- -- _≡Fin_ : ∀ {n} -> (x y : Fin n) -> Dec (x ≡ y) -- -- zero ≡Fin zero = yes refl -- -- zero ≡Fin suc y = no λ () -- -- suc x ≡Fin zero = no λ () -- -- suc {suc _} x ≡Fin suc y with x ≡Fin y -- -- ... | yes r = yes (cong suc r) -- -- ... | no r = no λ e -> r (cong previous e) -- -- suc {zero} () ≡Fin _ -- -- module Thick where -- -- half1 : ∀ {n} (x : Fin (suc n)) -> check x x ≡ nothing -- -- half1 zero = refl -- -- half1 {suc _} (suc x) = cong ((_<$>_ suc)) (half1 x) -- -- half1 {zero} (suc ()) -- -- half2 : ∀ {n} (x : Fin (suc n)) y -> ∀ y' -> thin x y' ≡ y -> check x y ≡ just y' -- -- half2 zero zero y' () -- -- half2 zero (suc y) .y refl = refl -- -- half2 {suc n} (suc x) zero zero refl = refl -- -- half2 {suc _} (suc _) zero (suc _) () -- -- half2 {suc n} (suc x) (suc y) zero () -- -- half2 {suc n} (suc x) (suc .(thin x y')) (suc y') refl with check x (thin x y') | half2 x (thin x y') y' refl -- -- ... | .(just y') | refl = refl -- -- half2 {zero} (suc ()) _ _ _ -- -- fact1 : ∀ {n} (x : Fin (suc n)) y r -- -- -> check x y ≡ r -- -- -> x ≡ y × r ≡ nothing ⊎ ∃ λ y' -> thin x y' ≡ y × r ≡ just y' -- -- fact1 x y .(check x y) refl with x ≡Fin y -- -- fact1 x .x ._ refl | yes refl = inj₁ (refl , half1 x) -- -- ... | no el with Thin.fact3 x y el -- -- ... | y' , thinxy'=y = inj₂ (y' , ( thinxy'=y , half2 x y y' thinxy'=y ))
36.702128
117
0.501159
3dc81348b7bf9daefbe1898adb01448bc7e17943
569
agda
Agda
test/Common/Path.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Common/Path.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Common/Path.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --erased-cubical #-} module Common.Path where open import Agda.Builtin.Cubical.Path public open import Agda.Builtin.Cubical.HCompU open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_; primHComp to hcomp; primTransp to transp; primComp to comp; itIsOne to 1=1) public open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to outS; inc to inS) public open Helpers public
43.769231
104
0.606327
0b204ba88b7085415bd6fe6e277d901d76be033b
122
agda
Agda
test/Fail/IUnivNotFibrant.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/IUnivNotFibrant.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/IUnivNotFibrant.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Primitive open import Agda.Primitive.Cubical record Wrap : Set (lsuc lzero) where field A : IUniv
17.428571
36
0.745902
5831f84d13d42c93dd26d269a1b30eb5f13e8d3b
772
agda
Agda
src/Categories/Category/Monoidal.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Monoidal.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Monoidal.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- Definition of Monoidal Category -- Big design decision that differs from the previous version: -- Do not go through "Functor.Power" to encode variables and work -- at the level of NaturalIsomorphisms, instead work at the object/morphism -- level, via the more direct _⊗₀_ _⊗₁_ _⊗- -⊗_. -- The original design needed quite a few contortions to get things working, -- but these are simply not needed when working directly with the morphisms. -- -- Smaller design decision: export some items with long names -- (unitorˡ, unitorʳ and associator), but internally work with the more classical -- short greek names (λ, ρ and α respectively). module Categories.Category.Monoidal where open import Categories.Category.Monoidal.Core public
40.631579
81
0.761658
229a1714a70bbdbb47fd9298f40b4edf08e394ec
2,435
agda
Agda
examples/simple-lib/Lib/Fin.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/simple-lib/Lib/Fin.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/simple-lib/Lib/Fin.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Lib.Fin where open import Lib.Nat open import Lib.Bool open import Lib.Id data Fin : Nat -> Set where zero : {n : Nat} -> Fin (suc n) suc : {n : Nat} -> Fin n -> Fin (suc n) fromNat : (n : Nat) -> Fin (suc n) fromNat zero = zero fromNat (suc n) = suc (fromNat n) toNat : {n : Nat} -> Fin n -> Nat toNat zero = zero toNat (suc n) = suc (toNat n) weaken : {n : Nat} -> Fin n -> Fin (suc n) weaken zero = zero weaken (suc n) = suc (weaken n) lem-toNat-weaken : forall {n} (i : Fin n) -> toNat i ≡ toNat (weaken i) lem-toNat-weaken zero = refl lem-toNat-weaken (suc i) with toNat i | lem-toNat-weaken i ... | .(toNat (weaken i)) | refl = refl lem-toNat-fromNat : (n : Nat) -> toNat (fromNat n) ≡ n lem-toNat-fromNat zero = refl lem-toNat-fromNat (suc n) with toNat (fromNat n) | lem-toNat-fromNat n ... | .n | refl = refl finEq : {n : Nat} -> Fin n -> Fin n -> Bool finEq zero zero = true finEq zero (suc _) = false finEq (suc _) zero = false finEq (suc i) (suc j) = finEq i j -- A view telling you if a given element is the maximal one. data MaxView {n : Nat} : Fin (suc n) -> Set where theMax : MaxView (fromNat n) notMax : (i : Fin n) -> MaxView (weaken i) maxView : {n : Nat}(i : Fin (suc n)) -> MaxView i maxView {zero} zero = theMax maxView {zero} (suc ()) maxView {suc n} zero = notMax zero maxView {suc n} (suc i) with maxView i maxView {suc n} (suc .(fromNat n)) | theMax = theMax maxView {suc n} (suc .(weaken i)) | notMax i = notMax (suc i) -- The non zero view data NonEmptyView : {n : Nat} -> Fin n -> Set where ne : {n : Nat}{i : Fin (suc n)} -> NonEmptyView i nonEmpty : {n : Nat}(i : Fin n) -> NonEmptyView i nonEmpty zero = ne nonEmpty (suc _) = ne -- The thinning view thin : {n : Nat} -> Fin (suc n) -> Fin n -> Fin (suc n) thin zero j = suc j thin (suc i) zero = zero thin (suc i) (suc j) = suc (thin i j) data EqView : {n : Nat} -> Fin n -> Fin n -> Set where equal : {n : Nat}{i : Fin n} -> EqView i i notequal : {n : Nat}{i : Fin (suc n)}(j : Fin n) -> EqView i (thin i j) compare : {n : Nat}(i j : Fin n) -> EqView i j compare zero zero = equal compare zero (suc j) = notequal j compare (suc i) zero with nonEmpty i ... | ne = notequal zero compare (suc i) (suc j) with compare i j compare (suc i) (suc .i) | equal = equal compare (suc i) (suc .(thin i j)) | notequal j = notequal (suc j)
30.061728
73
0.590144
a16826f44c06bdf7148fe15178743ab2af5034eb
15,789
agda
Agda
Lecture3.agda
glangmead/hott_cmu80818
af64d808630f4f1498a75201b6ca4d74d662516b
[ "Unlicense" ]
4
2018-05-03T20:32:19.000Z
2018-09-04T02:52:25.000Z
Lecture3.agda
glangmead/hott_cmu80818
af64d808630f4f1498a75201b6ca4d74d662516b
[ "Unlicense" ]
3
2018-02-22T21:01:16.000Z
2018-03-25T14:44:31.000Z
Lecture3.agda
glangmead/hott_cmu80818
af64d808630f4f1498a75201b6ca4d74d662516b
[ "Unlicense" ]
2
2018-02-22T19:58:46.000Z
2018-06-25T15:05:21.000Z
{-# OPTIONS --without-K #-} module Lecture3 where import Lecture2 open Lecture2 public data unit : U where star : unit 𝟙 = unit ind-unit : {i : Level} {P : unit → UU i} → P star → ((x : unit) → P x) ind-unit p star = p data empty : U where 𝟘 = empty ind-empty : {i : Level} {P : empty → UU i} → ((x : empty) → P x) ind-empty () ¬ : {i : Level} → UU i → UU i ¬ A = A → empty data bool : U where true false : bool not : bool → bool not true = false not false = true ind-bool : {i : Level} {P : bool → UU i} → P true → P false → (x : bool) → P x ind-bool Pt Pf true = Pt ind-bool Pt Pf false = Pf data coprod {i j : Level} (A : UU i) (B : UU j) : UU (i ⊔ j) where inl : A → coprod A B inr : B → coprod A B data Sigma {i j : Level} (A : UU i) (B : A → UU j) : UU (i ⊔ j) where dpair : (x : A) → (B x → Sigma A B) Σ = Sigma ind-Σ : {i j k : Level} {A : UU i} {B : A → UU j} {C : Σ A B → UU k} → ((x : A) (y : B x) → C (dpair x y)) → ((t : Σ A B) → C t) ind-Σ f (dpair x y) = f x y pr1 : {i j : Level} {A : UU i} {B : A → UU j} → Sigma A B → A pr1 (dpair a b) = a pr2 : {i j : Level} {A : UU i} {B : A → UU j} → (t : Sigma A B) → B (pr1 t) pr2 (dpair a b) = b weaken : {i j : Level} (A : UU i) (B : UU j) → (A → UU j) weaken A B = λ a → B prod : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j) prod A B = Sigma A (λ a → B) _×_ : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j) A × B = prod A B -- WARNING, can't use pair in pattern matching as it's not recognized as a ctor pair : {i j : Level} {A : UU i} {B : UU j} → A → (B → prod A B) pair a b = dpair a b -- Pointed types U-pt : Type U-pt = Sigma U (λ X → X) -- Graphs Gph : Type Gph = Sigma U (λ X → (X → X → U)) -- Reflexive graphs rGph : Type rGph = Sigma U (λ X → Sigma (X → X → U) (λ R → (x : X) → R x x)) -- Finite sets Fin : ℕ → U Fin Nzero = empty Fin (Nsucc n) = coprod (Fin n) unit -- Observational equality on the natural numbers EqN : ℕ → (ℕ → U) EqN Nzero Nzero = 𝟙 EqN Nzero (Nsucc n) = 𝟘 EqN (Nsucc m) Nzero = 𝟘 EqN (Nsucc m) (Nsucc n) = EqN m n -- The integers ℤ : U ℤ = coprod ℕ (coprod unit ℕ) -- ^ ^^^^ ^ -- (-∞, -1] 0 [1, ∞) -- -(n+1) n+1 -- Inclusion of the negative integers in-neg : ℕ → ℤ in-neg n = inl n -- Negative one Zneg-one : ℤ Zneg-one = in-neg Nzero -- Zero Zzero : ℤ Zzero = inr (inl star) -- One Zone : ℤ Zone = inr (inr Nzero) -- Inclusion of the positive integers in-pos : ℕ → ℤ in-pos n = inr (inr n) -- Since Agda is already strong with nested induction, I dont think we need this definition. ind-ℤ : {i : Level} (P : ℤ → UU i) → P Zneg-one → ((n : ℕ) → P (inl n) → P (inl (Nsucc n))) → P Zzero → P Zone → ((n : ℕ) → P (inr (inr (n))) → P (inr (inr (Nsucc n)))) → (k : ℤ) → P k ind-ℤ P p-1 p-S p0 p1 pS (inl Nzero) = p-1 ind-ℤ P p-1 p-S p0 p1 pS (inl (Nsucc x)) = p-S x (ind-ℤ P p-1 p-S p0 p1 pS (inl x)) ind-ℤ P p-1 p-S p0 p1 pS (inr (inl star)) = p0 ind-ℤ P p-1 p-S p0 p1 pS (inr (inr Nzero)) = p1 ind-ℤ P p-1 p-S p0 p1 pS (inr (inr (Nsucc x))) = pS x (ind-ℤ P p-1 p-S p0 p1 pS (inr (inr (x)))) Zsucc : ℤ → ℤ Zsucc (inl Nzero) = Zzero Zsucc (inl (Nsucc x)) = inl x Zsucc (inr (inl star)) = Zone Zsucc (inr (inr x)) = inr (inr (Nsucc x)) -- Exercise 3.1 -- In this exercise we were asked to show that (A + ¬A) implies (¬¬A → A). -- In other words, we get double negation elimination for the types that are decidable dne-dec : {i : Level} (A : UU i) → (coprod A (¬ A)) → (¬ (¬ A) → A) dne-dec A (inl x) = λ f → x dne-dec A (inr x) = λ f → ind-empty (f x) -- Exercise 3.3 -- In this exercise we were asked to show that the observational equality on ℕ is an equivalence relation. reflexive-EqN : (n : ℕ) → EqN n n reflexive-EqN Nzero = star reflexive-EqN (Nsucc n) = reflexive-EqN n symmetric-EqN : (m n : ℕ) → EqN m n → EqN n m symmetric-EqN Nzero Nzero t = t symmetric-EqN Nzero (Nsucc n) t = t symmetric-EqN (Nsucc n) Nzero t = t symmetric-EqN (Nsucc m) (Nsucc n) t = symmetric-EqN m n t transitive-EqN : (l m n : ℕ) → EqN l m → EqN m n → EqN l n transitive-EqN Nzero Nzero Nzero s t = star transitive-EqN (Nsucc n) Nzero Nzero s t = ind-empty s transitive-EqN Nzero (Nsucc n) Nzero s t = ind-empty s transitive-EqN Nzero Nzero (Nsucc n) s t = ind-empty t transitive-EqN (Nsucc l) (Nsucc m) Nzero s t = ind-empty t transitive-EqN (Nsucc l) Nzero (Nsucc n) s t = ind-empty s transitive-EqN Nzero (Nsucc m) (Nsucc n) s t = ind-empty s transitive-EqN (Nsucc l) (Nsucc m) (Nsucc n) s t = transitive-EqN l m n s t -- Exercise 3.4 -- In this exercise we were asked to show that observational equality on the natural numbers is the least reflexive relation, in the sense that it implies all other reflexive relation. As we will see once we introduce the identity type, it follows that observationally equal natural numbers can be identified. -- We first make an auxilary construction, where the relation is quantified over inside the scope of the variables n and m. This is to ensure that the inductive hypothesis is strong enough to make the induction go through. least-reflexive-EqN' : {i : Level} (n m : ℕ) (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) → EqN n m → R n m least-reflexive-EqN' Nzero Nzero R ρ p = ρ Nzero least-reflexive-EqN' Nzero (Nsucc m) R ρ = ind-empty least-reflexive-EqN' (Nsucc n) Nzero R ρ = ind-empty least-reflexive-EqN' (Nsucc n) (Nsucc m) R ρ = least-reflexive-EqN' n m (λ x y → R (Nsucc x) (Nsucc y)) (λ x → ρ (Nsucc x)) -- Now we solve the actual exercise by rearranging the order of the variables. least-reflexive-EqN : {i : Level} {R : ℕ → ℕ → UU i} (ρ : (n : ℕ) → R n n) → (n m : ℕ) → EqN n m → R n m least-reflexive-EqN ρ n m p = least-reflexive-EqN' n m _ ρ p -- Exercise 3.5 -- In this exercise we were asked to show that any function on the natural numbers preserves observational equality. The quick solution uses the fact that observational equality is the least reflexive relation. preserve_EqN : (f : ℕ → ℕ) (n m : ℕ) → (EqN n m) → (EqN (f n) (f m)) preserve_EqN f = least-reflexive-EqN {_} {λ x y → EqN (f x) (f y)} (λ x → reflexive-EqN (f x)) -- Exercise 3.6 -- In this exercise we were asked to construct the relations ≤ and < on the natural numbers, and show basic properties about them. -- Definition of ≤ leqN : ℕ → ℕ → U leqN Nzero Nzero = unit leqN Nzero (Nsucc m) = unit leqN (Nsucc n) Nzero = empty leqN (Nsucc n) (Nsucc m) = leqN n m _≤_ = leqN -- Definition of < leN : ℕ → ℕ → U leN Nzero Nzero = empty leN Nzero (Nsucc m) = unit leN (Nsucc n) Nzero = empty leN (Nsucc n) (Nsucc m) = leN n m _<_ = leN reflexive-leqN : (n : ℕ) → n ≤ n reflexive-leqN Nzero = star reflexive-leqN (Nsucc n) = reflexive-leqN n anti-reflexive-leN : (n : ℕ) → ¬ (n < n) anti-reflexive-leN Nzero = ind-empty anti-reflexive-leN (Nsucc n) = anti-reflexive-leN n transitive-leqN : (n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l) transitive-leqN Nzero Nzero Nzero p q = reflexive-leqN Nzero transitive-leqN Nzero Nzero (Nsucc l) p q = q transitive-leqN Nzero (Nsucc m) Nzero p q = star transitive-leqN Nzero (Nsucc m) (Nsucc l) p q = star transitive-leqN (Nsucc n) Nzero l p q = ind-empty p transitive-leqN (Nsucc n) (Nsucc m) Nzero p q = ind-empty q transitive-leqN (Nsucc n) (Nsucc m) (Nsucc l) p q = transitive-leqN n m l p q transitive-leN : (n m l : ℕ) → (leN n m) → (leN m l) → (leN n l) transitive-leN Nzero Nzero Nzero p q = p transitive-leN Nzero Nzero (Nsucc l) p q = q transitive-leN Nzero (Nsucc m) Nzero p q = ind-empty q transitive-leN Nzero (Nsucc m) (Nsucc l) p q = star transitive-leN (Nsucc n) Nzero l p q = ind-empty p transitive-leN (Nsucc n) (Nsucc m) Nzero p q = ind-empty q transitive-leN (Nsucc n) (Nsucc m) (Nsucc l) p q = transitive-leN n m l p q succ-leN : (n : ℕ) → leN n (Nsucc n) succ-leN Nzero = star succ-leN (Nsucc n) = succ-leN n -- Exercise 3.7 -- With the construction of the divisibility relation we open the door to basic number theory. divides : (d n : ℕ) → U divides d n = Σ ℕ (λ m → EqN (d ** m) n) -- Exercise 3.8 -- In this exercise we were asked to construct observational equality on the booleans. This construction is analogous to, but simpler than, the construction of observational equality on the natural numbers. Eq2 : bool → bool → U Eq2 true true = unit Eq2 true false = empty Eq2 false true = empty Eq2 false false = unit reflexive-Eq2 : (x : bool) → Eq2 x x reflexive-Eq2 true = star reflexive-Eq2 false = star least-reflexive-Eq2 : {i : Level} (R : bool → bool → UU i) (ρ : (x : bool) → R x x) (x y : bool) → Eq2 x y → R x y least-reflexive-Eq2 R ρ true true p = ρ true least-reflexive-Eq2 R ρ true false p = ind-empty p least-reflexive-Eq2 R ρ false true p = ind-empty p least-reflexive-Eq2 R ρ false false p = ρ false -- Exercise 3.9 -- In this exercise we were asked to show that 1 + 1 satisfies the induction principle of the booleans. In other words, type theory cannot distinguish the booleans from the type 1 + 1. We will see later that they are indeed equivalent types. t0 : coprod unit unit t0 = inl star t1 : coprod unit unit t1 = inr star ind-coprod-unit-unit : {i : Level} {P : coprod unit unit → UU i} → P t0 → P t1 → (x : coprod unit unit) → P x ind-coprod-unit-unit p0 p1 (inl star) = p0 ind-coprod-unit-unit p0 p1 (inr star) = p1 -- Exercise 3.10 -- In this exercise we were asked to define the relations ≤ and < on the integers. As a criterion of correctness, we were then also asked to show that the type of all integers l satisfying k ≤ l satisfy the induction principle of the natural numbers. -- It turns out that this is a long exercise that requires to develop intermediate properties of the relation ≤, involving long proofs. None of them is really hard, but they are probably unintelligible because induction on the integers splits into so many cases. leqZ : ℤ → ℤ → U leqZ (inl Nzero) (inl Nzero) = unit leqZ (inl Nzero) (inl (Nsucc x)) = empty leqZ (inl Nzero) (inr l) = unit leqZ (inl (Nsucc x)) (inl Nzero) = unit leqZ (inl (Nsucc x)) (inl (Nsucc y)) = leqZ (inl x) (inl y) leqZ (inl (Nsucc x)) (inr l) = unit leqZ (inr k) (inl x) = empty leqZ (inr (inl star)) (inr l) = unit leqZ (inr (inr x)) (inr (inl star)) = empty leqZ (inr (inr Nzero)) (inr (inr y)) = unit leqZ (inr (inr (Nsucc x))) (inr (inr Nzero)) = empty leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) = leqZ (inr (inr (x))) (inr (inr (y))) reflexive-leqZ : (k : ℤ) → leqZ k k reflexive-leqZ (inl Nzero) = star reflexive-leqZ (inl (Nsucc x)) = reflexive-leqZ (inl x) reflexive-leqZ (inr (inl star)) = star reflexive-leqZ (inr (inr Nzero)) = star reflexive-leqZ (inr (inr (Nsucc x))) = reflexive-leqZ (inr (inr x)) transitive-leqZ : (k l m : ℤ) → leqZ k l → leqZ l m → leqZ k m transitive-leqZ (inl Nzero) (inl Nzero) m p q = q transitive-leqZ (inl Nzero) (inl (Nsucc x)) m p q = ind-empty p transitive-leqZ (inl Nzero) (inr (inl star)) (inl Nzero) star q = reflexive-leqZ (inl Nzero) transitive-leqZ (inl Nzero) (inr (inl star)) (inl (Nsucc x)) star q = ind-empty q transitive-leqZ (inl Nzero) (inr (inl star)) (inr (inl star)) star q = star transitive-leqZ (inl Nzero) (inr (inl star)) (inr (inr x)) star q = star transitive-leqZ (inl Nzero) (inr (inr x)) (inl y) star q = ind-empty q transitive-leqZ (inl Nzero) (inr (inr x)) (inr (inl star)) star q = ind-empty q transitive-leqZ (inl Nzero) (inr (inr x)) (inr (inr y)) star q = star transitive-leqZ (inl (Nsucc x)) (inl Nzero) (inl Nzero) star q = star transitive-leqZ (inl (Nsucc x)) (inl Nzero) (inl (Nsucc y)) star q = ind-empty q transitive-leqZ (inl (Nsucc x)) (inl Nzero) (inr m) star q = star transitive-leqZ (inl (Nsucc x)) (inl (Nsucc y)) (inl Nzero) p q = star transitive-leqZ (inl (Nsucc x)) (inl (Nsucc y)) (inl (Nsucc z)) p q = transitive-leqZ (inl x) (inl y) (inl z) p q transitive-leqZ (inl (Nsucc x)) (inl (Nsucc y)) (inr m) p q = star transitive-leqZ (inl (Nsucc x)) (inr y) (inl z) star q = ind-empty q transitive-leqZ (inl (Nsucc x)) (inr y) (inr z) star q = star transitive-leqZ (inr k) (inl x) m p q = ind-empty p transitive-leqZ (inr (inl star)) (inr l) (inl x) star q = ind-empty q transitive-leqZ (inr (inl star)) (inr l) (inr m) star q = star transitive-leqZ (inr (inr x)) (inr (inl star)) m p q = ind-empty p transitive-leqZ (inr (inr Nzero)) (inr (inr Nzero)) m p q = q transitive-leqZ (inr (inr Nzero)) (inr (inr (Nsucc y))) (inl x) star q = ind-empty q transitive-leqZ (inr (inr Nzero)) (inr (inr (Nsucc y))) (inr (inl star)) star q = ind-empty q transitive-leqZ (inr (inr Nzero)) (inr (inr (Nsucc y))) (inr (inr z)) star q = star transitive-leqZ (inr (inr (Nsucc x))) (inr (inr Nzero)) m p q = ind-empty p transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inl z) p q = ind-empty q transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inr (inl star)) p q = ind-empty q transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inr (inr Nzero)) p q = ind-empty q transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inr (inr (Nsucc z))) p q = transitive-leqZ (inr (inr x)) (inr (inr y)) (inr (inr z)) p q succ-leqZ : (k : ℤ) → leqZ k (Zsucc k) succ-leqZ (inl Nzero) = star succ-leqZ (inl (Nsucc Nzero)) = star succ-leqZ (inl (Nsucc (Nsucc x))) = succ-leqZ (inl (Nsucc x)) succ-leqZ (inr (inl star)) = star succ-leqZ (inr (inr Nzero)) = star succ-leqZ (inr (inr (Nsucc x))) = succ-leqZ (inr (inr x)) leqZ-succ-leqZ : (k l : ℤ) → leqZ k l → leqZ k (Zsucc l) leqZ-succ-leqZ k l p = transitive-leqZ k l (Zsucc l) p (succ-leqZ l) leZ : ℤ → ℤ → U leZ (inl Nzero) (inl x) = empty leZ (inl Nzero) (inr y) = unit leZ (inl (Nsucc x)) (inl Nzero) = unit leZ (inl (Nsucc x)) (inl (Nsucc y)) = leZ (inl x) (inl y) leZ (inl (Nsucc x)) (inr y) = unit leZ (inr x) (inl y) = empty leZ (inr (inl star)) (inr (inl star)) = empty leZ (inr (inl star)) (inr (inr x)) = unit leZ (inr (inr x)) (inr (inl star)) = empty leZ (inr (inr Nzero)) (inr (inr Nzero)) = empty leZ (inr (inr Nzero)) (inr (inr (Nsucc y))) = unit leZ (inr (inr (Nsucc x))) (inr (inr Nzero)) = empty leZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) = leZ (inr (inr x)) (inr (inr y)) fam-shift-leqZ : (k : ℤ) {i : Level} (P : (l : ℤ) → leqZ k l → UU i) → (l : ℤ) → (leqZ (Zsucc k) l) → UU i fam-shift-leqZ k P l p = P l (transitive-leqZ k (Zsucc k) l (succ-leqZ k) p) -- ind-Z-leqZ : (k : ℤ) {i : Level} (P : (l : ℤ) → (leqZ k l) → UU i) → -- P k (reflexive-leqZ k) → -- ((l : ℤ) (p : leqZ k l) → P l p → P (Zsucc l) (leqZ-succ-leqZ k l p)) → -- (l : ℤ) (p : leqZ k l) → P l p -- ind-Z-leqZ (inl Nzero) P pk pS (inl Nzero) star = pk -- ind-Z-leqZ (inl Nzero) P pk pS (inl (Nsucc x)) () -- ind-Z-leqZ (inl Nzero) P pk pS (inr (inl star)) star = pS (inl Nzero) star pk -- ind-Z-leqZ (inl Nzero) P pk pS (inr (inr Nzero)) star = pS (inr (inl star)) star (pS (inl Nzero) star pk) -- ind-Z-leqZ (inl Nzero) P pk pS (inr (inr (Nsucc x))) star = pS (inr (inr x)) star (ind-Z-leqZ (inl Nzero) P pk pS (inr (inr x)) star) -- ind-Z-leqZ (inl (Nsucc Nzero)) {i} P pk pS (inl Nzero) star = pS {!!} {!!} {!!} -- ind-Z-leqZ (inl (Nsucc (Nsucc x))) {i} P pk pS (inl Nzero) star = {!!} -- ind-Z-leqZ (inl (Nsucc x)) P pk pS (inl (Nsucc y)) p = {!!} -- ind-Z-leqZ (inl (Nsucc x)) P pk pS (inr y) p = {!!} -- ind-Z-leqZ (inr k) P pk pS l p = {!!} -- Exercise 3.11 Zpred : ℤ → ℤ Zpred (inl x) = inl (Nsucc x) Zpred (inr (inl star)) = inl Nzero Zpred (inr (inr Nzero)) = inr (inl star) Zpred (inr (inr (Nsucc x))) = inr (inr x) -- Exercise 3.12 Zadd : ℤ → ℤ → ℤ Zadd (inl Nzero) l = Zpred l Zadd (inl (Nsucc x)) l = Zpred (Zadd (inl x) l) Zadd (inr (inl star)) l = l Zadd (inr (inr Nzero)) l = Zsucc l Zadd (inr (inr (Nsucc x))) l = Zsucc (Zadd (inr (inr x)) l) Zneg : ℤ → ℤ Zneg (inl x) = inr (inr x) Zneg (inr (inl star)) = inr (inl star) Zneg (inr (inr x)) = inl x
38.322816
309
0.622712
fb0e3c10c7aa93fa5fa9bdf328f985d855ea526b
3,789
agda
Agda
src/Integer/Univalence.agda
kcsmnt0/numbers
67ea7b96228c592daf79e800ebe4a7c12ed7221e
[ "MIT" ]
9
2019-05-20T01:29:41.000Z
2020-01-16T07:16:26.000Z
src/Integer/Univalence.agda
kcsmnt0/numbers
67ea7b96228c592daf79e800ebe4a7c12ed7221e
[ "MIT" ]
null
null
null
src/Integer/Univalence.agda
kcsmnt0/numbers
67ea7b96228c592daf79e800ebe4a7c12ed7221e
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical #-} module Integer.Univalence where open import Cubical.Foundations.NTypes open import Data.Empty open import Data.Product as Σ open import Data.Product.Relation.Pointwise.NonDependent open import Data.Unit open import Equality open import Function open import Integer.Difference as D open import Integer.Signed as S open import Natural as ℕ open import Quotient as / open import Syntax open import Relation.Nullary zero≢suc : ∀ {m} → ¬ (zero ≡ suc m) zero≢suc p = case ⟪ p ⟫ of λ () ⟦D→S⟧ : D.⟦ℤ⟧ → S.⟦ℤ⟧ ⟦D→S⟧ (a – zero) = +1* a ⟦D→S⟧ (zero – b) = -1* b ⟦D→S⟧ (suc a – suc b) = ⟦D→S⟧ (a – b) D→S : D.ℤ → S.ℤ D→S = ⟦D→S⟧ // line where line : ∀ x y → x D.≈ y → ⟦D→S⟧ x S.≈ ⟦D→S⟧ y line (zero – zero) (zero – zero) p = refl line (zero – zero) (zero – suc d) p = refl , p line (zero – zero) (suc c – zero) p = compPath p (cong suc ⟨ +-identityʳ c ⟩) line (zero – b) (suc c – suc d) p = line (zero – b) (c – d) ⟨ suc-injective ⟪ p ⟫ ⟩ line (suc a – suc b) (zero – d) p = line (a – b) (zero – d) ⟨ suc-injective ⟪ p ⟫ ⟩ line (zero – suc b) (zero – zero) p = sym p , refl line (zero – suc b) (zero – suc d) p = sym p line (zero – suc b) (suc c – zero) p = case ⟪ p ⟫ of λ () line (suc a – zero) (zero – d) p = case ⟪ p ⟫ of λ () line (suc a – zero) (suc c – zero) p = suc a ≡⟨ cong suc (sym ⟨ +-identityʳ a ⟩) ⟩ suc (a + 0) ≡⟨ p ⟩ suc (c + 0) ≡⟨ cong suc ⟨ +-identityʳ c ⟩ ⟩ suc c ∎ line (suc a – b) (suc c – suc d) p = line (suc a – b) (c – d) ⟨ suc-injective ⟪ compPath (cong suc (sym (+-suc a d))) p ⟫ ⟩ line (suc a – suc b) (suc c – d) p = line (a – b) (suc c – d) ⟨ suc-injective ⟪ compPath p (cong suc (+-suc c b)) ⟫ ⟩ ⟦S→D⟧ : S.⟦ℤ⟧ → D.⟦ℤ⟧ ⟦S→D⟧ (+1* a) = a – zero ⟦S→D⟧ (-1* a) = zero – a ⟦D→S→D⟧ : ∀ x → ⟦S→D⟧ (⟦D→S⟧ x) D.≈ x ⟦D→S→D⟧ (zero – zero) = refl ⟦D→S→D⟧ (zero – suc b) = refl ⟦D→S→D⟧ (suc a – zero) = refl ⟦D→S→D⟧ (suc a – suc b) = let m , n = ⟦S→D⟧ (⟦D→S⟧ (a – b)) in m + suc b ≡⟨ +-suc m b ⟩ suc (m + b) ≡⟨ cong suc (⟦D→S→D⟧ (a – b)) ⟩ suc (a + n) ∎ ⟦S→D→S⟧ : ∀ x → ⟦D→S⟧ (⟦S→D⟧ x) S.≈ x ⟦S→D→S⟧ (+1* x) = refl ⟦S→D→S⟧ (-1* zero) = refl , refl ⟦S→D→S⟧ (-1* suc x) = refl cong-⟦S→D⟧ : ∀ x y → x S.≈ y → ⟦S→D⟧ x D.≈ ⟦S→D⟧ y cong-⟦S→D⟧ (+1* x) (+1* y) = cong (_+ zero) cong-⟦S→D⟧ (-1* x) (-1* y) = sym cong-⟦S→D⟧ (+1* x) (-1* y) = Σ.uncurry (cong₂ _+_) cong-⟦S→D⟧ (-1* x) (+1* y) (p , q) = compPath (sym (cong₂ _+_ p q)) ⟨ +-comm x y ⟩ cong-⟦D→S⟧ : ∀ x y → x D.≈ y → ⟦D→S⟧ x S.≈ ⟦D→S⟧ y cong-⟦D→S⟧ (zero – zero) (zero – zero) p = refl cong-⟦D→S⟧ (zero – zero) (zero – suc d) p = refl , p cong-⟦D→S⟧ (zero – zero) (suc c – zero) p = compPath p (cong suc ⟨ +-identityʳ c ⟩) cong-⟦D→S⟧ (zero – b) (suc c – suc d) p = cong-⟦D→S⟧ (zero – b) (c – d) ⟨ suc-injective ⟪ p ⟫ ⟩ cong-⟦D→S⟧ (suc a – suc b) (zero – d) p = cong-⟦D→S⟧ (a – b) (zero – d) ⟨ suc-injective ⟪ p ⟫ ⟩ cong-⟦D→S⟧ (zero – suc b) (zero – zero) p = sym p , refl cong-⟦D→S⟧ (zero – suc b) (zero – suc d) p = sym p cong-⟦D→S⟧ (zero – suc b) (suc c – zero) p = case ⟪ p ⟫ of λ () cong-⟦D→S⟧ (suc a – zero) (zero – d) p = case ⟪ p ⟫ of λ () cong-⟦D→S⟧ (suc a – zero) (suc c – zero) p = suc a ≡⟨ cong suc (sym ⟨ +-identityʳ a ⟩) ⟩ suc (a + 0) ≡⟨ p ⟩ suc (c + 0) ≡⟨ cong suc ⟨ +-identityʳ c ⟩ ⟩ suc c ∎ cong-⟦D→S⟧ (suc a – b) (suc c – suc d) p = cong-⟦D→S⟧ (suc a – b) (c – d) ⟨ suc-injective ⟪ compPath (cong suc (sym (+-suc a d))) p ⟫ ⟩ cong-⟦D→S⟧ (suc a – suc b) (suc c – d) p = cong-⟦D→S⟧ (a – b) (suc c – d) ⟨ suc-injective ⟪ compPath p (cong suc (+-suc c b)) ⟫ ⟩ Signed≡Difference : S.ℤ ≡ D.ℤ Signed≡Difference = ua (isoToEquiv ⟦S→D⟧ ⟦D→S⟧ cong-⟦S→D⟧ cong-⟦D→S⟧ ⟦S→D→S⟧ ⟦D→S→D⟧)
33.830357
95
0.494062
57d93ff6b26c0c1dfe0b4246aeb0e218b9b65466
2,895
agda
Agda
test/Succeed/Issue1734.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1734.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1734.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-12-05 issue reported by Conor -- {-# OPTIONS -v tc.cover.splittree:10 -v tc.cc:20 #-} module Issue1734 where infix 4 _≡_ data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x record One : Set where constructor <> data Two : Set where tt ff : Two -- two : ∀{α}{A : Set α} → A → A → Two → A two : (S T : Set) → Two → Set two a b tt = a two a b ff = b record Sg (S : Set)(T : S -> Set) : Set where constructor _,_ field fst : S snd : T fst open Sg public _+_ : Set -> Set -> Set S + T = Sg Two (two S T) data Twoey : Two -> Set where ffey : Twoey ff ttey : Twoey tt postulate Thingy : Set ThingyIf : Two -> Set ThingyIf tt = Thingy ThingyIf ff = One thingy? : (b : Two) -> ThingyIf b -> Twoey b + One -> Thingy + One thingy? .ff <> (tt , ffey) = ff , <> thingy? .tt x (tt , ttey) = tt , x thingy? _ _ _ = ff , <> -- WORKS: thingy? _ _ (ff , _ ) = ff , <> {- Correct split tree split at 2 | `- Issue1734.Sg._,_ -> split at 2 | +- Issue1734.Two.tt -> split at 2 | | | +- Issue1734.Twoey.ffey -> split at 1 | | | | | `- Issue1734.One.<> -> done, 0 bindings | | | `- Issue1734.Twoey.ttey -> done, 1 bindings | `- Issue1734.Two.ff -> done, 3 bindings but clause compiler deviated from it: thingy? b x p = case p of (y , z) -> case y of tt -> case x of <> -> case z of ffey -> ff , <> ttey -> tt , <> _ -> case z of ttey -> tt , x _ -> ff , <> compiled clauses (still containing record splits) case 2 of Issue1734.Sg._,_ -> case 2 of Issue1734.Two.tt -> case 1 of Issue1734.One.<> -> case 1 of Issue1734.Twoey.ffey -> ff , <> Issue1734.Twoey.ttey -> tt , <> _ -> case 2 of Issue1734.Twoey.ttey -> tt , x _ -> ff , <> -} test1 : ∀ x → thingy? tt x (tt , ttey) ≡ tt , x test1 = λ x → refl -- should pass! first-eq-works : ∀ x → thingy? ff x (tt , ffey) ≡ ff , x first-eq-works = λ x → refl -- It's weird. I couldn't make it happen with Twoey b alone: I needed Twoey b + One. -- I also checked that reordering the arguments made it go away. This... thygni? : (b : Two) -> Twoey b + One -> ThingyIf b -> Thingy + One thygni? .ff (tt , ffey) <> = ff , <> thygni? .tt (tt , ttey) x = tt , x thygni? _ _ _ = ff , <> works : ∀ x → thygni? tt (tt , ttey) x ≡ tt , x works = λ x → refl -- Moreover, replacing the gratuitous <> pattern by a variable... hingy? : (b : Two) -> ThingyIf b -> Twoey b + One -> Thingy + One hingy? .ff x (tt , ffey) = ff , <> hingy? .tt x (tt , ttey) = tt , x hingy? _ _ _ = ff , <> -- ...gives... works2 : ∀ x → hingy? tt x (tt , ttey) ≡ tt , x works2 = λ x -> refl -- ...and it has to be a variable: an _ gives the same outcome as <>.
23.346774
84
0.520207
dfd92ce8de03c666fd6e7fe0219df134eb406795
208
agda
Agda
test/Succeed/Issue1550a.agda
zgrannan/agda
5953ce337eb6b77b29ace7180478f49c541aea1c
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/Issue1550a.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue1550a.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, 2015-08-27 use imported rewrite rule {-# OPTIONS --rewriting #-} open import Common.Nat open import Common.Equality open import Issue1550 x+0+0+0 : ∀{x} → ((x + 0) + 0) + 0 ≡ x x+0+0+0 = refl
17.333333
48
0.639423
41f00278ef825c96a4b919b93261746c897a8baf
189
agda
Agda
test/interaction/Issue1325a.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
test/interaction/Issue1325a.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
test/interaction/Issue1325a.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
-- Andreas, 2014-10-23 -- We want to split on hidden variables. data ℕ : Set where zero : ℕ suc : ℕ → ℕ f : {n : ℕ} → Set₁ f = Set where g : {n : ℕ} → Set → Set g _ = {!.n!}
13.5
40
0.507937
57a2666df3bfcb6603e155c3eeabf2489f01d84f
3,269
agda
Agda
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Extrema/NonStrict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Extrema/NonStrict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Extrema/NonStrict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- The lifting of a non-strict order to incorporate new extrema ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This module is designed to be used with -- Relation.Nullary.Construct.Add.Extrema open import Relation.Binary module Relation.Binary.Construct.Add.Extrema.NonStrict {a ℓ} {A : Set a} (_≤_ : Rel A ℓ) where open import Function open import Relation.Nullary.Construct.Add.Extrema import Relation.Nullary.Construct.Add.Infimum as I import Relation.Binary.Construct.Add.Infimum.NonStrict as AddInfimum import Relation.Binary.Construct.Add.Supremum.NonStrict as AddSupremum import Relation.Binary.Construct.Add.Extrema.Equality as Equality ------------------------------------------------------------------------- -- Definition private module Inf = AddInfimum _≤_ module Sup = AddSupremum Inf._≤₋_ open Sup using () renaming (_≤⁺_ to _≤±_) public ------------------------------------------------------------------------- -- Useful pattern synonyms pattern ⊥±≤⊥± = Sup.[ Inf.⊥₋≤ I.⊥₋ ] pattern ⊥±≤[_] l = Sup.[ Inf.⊥₋≤ I.[ l ] ] pattern [_] p = Sup.[ Inf.[ p ] ] pattern ⊥±≤⊤± = ⊥± Sup.≤⊤⁺ pattern [_]≤⊤± k = [ k ] Sup.≤⊤⁺ pattern ⊤±≤⊤± = ⊤± Sup.≤⊤⁺ ⊥±≤_ : ∀ k → ⊥± ≤± k ⊥±≤ ⊥± = ⊥±≤⊥± ⊥±≤ [ k ] = ⊥±≤[ k ] ⊥±≤ ⊤± = ⊥±≤⊤± _≤⊤± : ∀ k → k ≤± ⊤± ⊥± ≤⊤± = ⊥±≤⊤± [ k ] ≤⊤± = [ k ]≤⊤± ⊤± ≤⊤± = ⊤±≤⊤± ------------------------------------------------------------------------- -- Relational properties [≤]-injective : ∀ {k l} → [ k ] ≤± [ l ] → k ≤ l [≤]-injective = Inf.[≤]-injective ∘′ Sup.[≤]-injective module _ {e} {_≈_ : Rel A e} where open Equality _≈_ ≤±-reflexive : (_≈_ ⇒ _≤_) → (_≈±_ ⇒ _≤±_) ≤±-reflexive = Sup.≤⁺-reflexive ∘′ Inf.≤₋-reflexive ≤±-antisym : Antisymmetric _≈_ _≤_ → Antisymmetric _≈±_ _≤±_ ≤±-antisym = Sup.≤⁺-antisym ∘′ Inf.≤₋-antisym ≤±-trans : Transitive _≤_ → Transitive _≤±_ ≤±-trans = Sup.≤⁺-trans ∘′ Inf.≤₋-trans ≤±-minimum : Minimum _≤±_ ⊥± ≤±-minimum = ⊥±≤_ ≤±-maximum : Maximum _≤±_ ⊤± ≤±-maximum = _≤⊤± ≤±-dec : Decidable _≤_ → Decidable _≤±_ ≤±-dec = Sup.≤⁺-dec ∘′ Inf.≤₋-dec ≤±-total : Total _≤_ → Total _≤±_ ≤±-total = Sup.≤⁺-total ∘′ Inf.≤₋-total ≤±-irrelevant : Irrelevant _≤_ → Irrelevant _≤±_ ≤±-irrelevant = Sup.≤⁺-irrelevant ∘′ Inf.≤₋-irrelevant ------------------------------------------------------------------------- -- Structures module _ {e} {_≈_ : Rel A e} where open Equality _≈_ ≤±-isPreorder : IsPreorder _≈_ _≤_ → IsPreorder _≈±_ _≤±_ ≤±-isPreorder = Sup.≤⁺-isPreorder ∘′ Inf.≤₋-isPreorder ≤±-isPartialOrder : IsPartialOrder _≈_ _≤_ → IsPartialOrder _≈±_ _≤±_ ≤±-isPartialOrder = Sup.≤⁺-isPartialOrder ∘′ Inf.≤₋-isPartialOrder ≤±-isDecPartialOrder : IsDecPartialOrder _≈_ _≤_ → IsDecPartialOrder _≈±_ _≤±_ ≤±-isDecPartialOrder = Sup.≤⁺-isDecPartialOrder ∘′ Inf.≤₋-isDecPartialOrder ≤±-isTotalOrder : IsTotalOrder _≈_ _≤_ → IsTotalOrder _≈±_ _≤±_ ≤±-isTotalOrder = Sup.≤⁺-isTotalOrder ∘′ Inf.≤₋-isTotalOrder ≤±-isDecTotalOrder : IsDecTotalOrder _≈_ _≤_ → IsDecTotalOrder _≈±_ _≤±_ ≤±-isDecTotalOrder = Sup.≤⁺-isDecTotalOrder ∘′ Inf.≤₋-isDecTotalOrder
30.268519
80
0.528602
22a03950b555f496baf024f561f533a76ce348de
192
agda
Agda
Cubical/Data/Sigma/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Sigma.Base where open import Cubical.Core.Primitives public -- Σ-types are defined in Core/Primitives as they are needed for Glue types.
27.428571
76
0.755208
fb5f049657bb8a70353b60ef42f9260c5ac811f3
2,357
agda
Agda
Cubical/Data/Unit/Properties.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
Cubical/Data/Unit/Properties.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
Cubical/Data/Unit/Properties.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Unit.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Data.Nat open import Cubical.Data.Unit.Base open import Cubical.Data.Prod.Base open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Reflection.StrictEquiv isContrUnit : isContr Unit isContrUnit = tt , λ {tt → refl} isPropUnit : isProp Unit isPropUnit _ _ i = tt -- definitionally equal to: isContr→isProp isContrUnit isSetUnit : isSet Unit isSetUnit = isProp→isSet isPropUnit isOfHLevelUnit : (n : HLevel) → isOfHLevel n Unit isOfHLevelUnit n = isContr→isOfHLevel n isContrUnit module _ {ℓ} (A : Type ℓ) where UnitToType≃ : (Unit → A) ≃ A unquoteDef UnitToType≃ = defStrictEquiv UnitToType≃ (λ f → f _) const UnitToTypePath : ∀ {ℓ} (A : Type ℓ) → (Unit → A) ≡ A UnitToTypePath A = ua (UnitToType≃ A) isContr→Iso2 : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → isContr A → Iso (A → B) B Iso.fun (isContr→Iso2 iscontr) f = f (fst iscontr) Iso.inv (isContr→Iso2 iscontr) b _ = b Iso.rightInv (isContr→Iso2 iscontr) _ = refl Iso.leftInv (isContr→Iso2 iscontr) f = funExt λ x → cong f (snd iscontr x) diagonal-unit : Unit ≡ Unit × Unit diagonal-unit = isoToPath (iso (λ x → tt , tt) (λ x → tt) (λ {(tt , tt) i → tt , tt}) λ {tt i → tt}) fibId : ∀ {ℓ} (A : Type ℓ) → (fiber (λ (x : A) → tt) tt) ≡ A fibId A = ua e where unquoteDecl e = declStrictEquiv e fst (λ a → a , refl) isContr→≃Unit : ∀ {ℓ} {A : Type ℓ} → isContr A → A ≃ Unit isContr→≃Unit contr = isoToEquiv (iso (λ _ → tt) (λ _ → fst contr) (λ _ → refl) λ _ → snd contr _) isContr→≡Unit : {A : Type₀} → isContr A → A ≡ Unit isContr→≡Unit contr = ua (isContr→≃Unit contr) isContrUnit* : ∀ {ℓ} → isContr (Unit* {ℓ}) isContrUnit* = tt* , λ _ → refl isPropUnit* : ∀ {ℓ} → isProp (Unit* {ℓ}) isPropUnit* _ _ = refl isOfHLevelUnit* : ∀ {ℓ} (n : HLevel) → isOfHLevel n (Unit* {ℓ}) isOfHLevelUnit* zero = tt* , λ _ → refl isOfHLevelUnit* (suc zero) _ _ = refl isOfHLevelUnit* (suc (suc zero)) _ _ _ _ _ _ = tt* isOfHLevelUnit* (suc (suc (suc n))) = isOfHLevelPlus 3 (isOfHLevelUnit* n)
33.197183
100
0.68689
57d4b9f11e607b878e64c887e2cc487c5404ec3b
2,123
agda
Agda
test/asset/agda-stdlib-1.0/Induction.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
test/asset/agda-stdlib-1.0/Induction.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Induction.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- An abstraction of various forms of recursion/induction ------------------------------------------------------------------------ -- The idea underlying Induction.* comes from Epigram 1, see Section 4 -- of "The view from the left" by McBride and McKinna. -- Note: The types in this module can perhaps be easier to understand -- if they are normalised. Note also that Agda can do the -- normalisation for you. {-# OPTIONS --without-K --safe #-} module Induction where open import Level open import Relation.Unary -- A RecStruct describes the allowed structure of recursion. The -- examples in Induction.Nat should explain what this is all about. RecStruct : ∀ {a} → Set a → (ℓ₁ ℓ₂ : Level) → Set _ RecStruct A ℓ₁ ℓ₂ = Pred A ℓ₁ → Pred A ℓ₂ -- A recursor builder constructs an instance of a recursion structure -- for a given input. RecursorBuilder : ∀ {a ℓ₁ ℓ₂} {A : Set a} → RecStruct A ℓ₁ ℓ₂ → Set _ RecursorBuilder Rec = ∀ P → Rec P ⊆′ P → Universal (Rec P) -- A recursor can be used to actually compute/prove something useful. Recursor : ∀ {a ℓ₁ ℓ₂} {A : Set a} → RecStruct A ℓ₁ ℓ₂ → Set _ Recursor Rec = ∀ P → Rec P ⊆′ P → Universal P -- And recursors can be constructed from recursor builders. build : ∀ {a ℓ₁ ℓ₂} {A : Set a} {Rec : RecStruct A ℓ₁ ℓ₂} → RecursorBuilder Rec → Recursor Rec build builder P f x = f x (builder P f x) -- We can repeat the exercise above for subsets of the type we are -- recursing over. SubsetRecursorBuilder : ∀ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} → Pred A ℓ₁ → RecStruct A ℓ₂ ℓ₃ → Set _ SubsetRecursorBuilder Q Rec = ∀ P → Rec P ⊆′ P → Q ⊆′ Rec P SubsetRecursor : ∀ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} → Pred A ℓ₁ → RecStruct A ℓ₂ ℓ₃ → Set _ SubsetRecursor Q Rec = ∀ P → Rec P ⊆′ P → Q ⊆′ P subsetBuild : ∀ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} {Q : Pred A ℓ₁} {Rec : RecStruct A ℓ₂ ℓ₃} → SubsetRecursorBuilder Q Rec → SubsetRecursor Q Rec subsetBuild builder P f x q = f x (builder P f x q)
34.803279
72
0.603391
3d69c94e0298fc783e0c3d2fd004ade73130cb5e
4,773
agda
Agda
src/Categories/Category/CartesianClosed/Canonical.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/CartesianClosed/Canonical.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/CartesianClosed/Canonical.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category.Core using (Category) -- A "canonical" presentation of cartesian closed categories. -- -- This presentation is equivalent to the one in -- Categories.Category.CartesianClosed but it is easier to work with -- in some circumstances. -- -- Here, exponentials are not defined in terms of arbitrary products, -- but in terms of a family of "canonical" products. Since products -- are defined only up to isomorphism the choice of product does not -- matter for the property of being cartesian closed, but working with -- a fixed choice of representatives simplifies the constructions of -- some instances of CCCs (e.g. Cats). module Categories.Category.CartesianClosed.Canonical {o ℓ e} (𝒞 : Category o ℓ e) where open import Level using (levelOfTerm) open import Function using (flip) open import Categories.Category.BinaryProducts 𝒞 open import Categories.Category.Cartesian 𝒞 using (Cartesian) import Categories.Category.CartesianClosed 𝒞 as 𝒞-CC open import Categories.Object.Exponential 𝒞 using (Exponential) open import Categories.Object.Product 𝒞 open import Categories.Object.Terminal 𝒞 using (Terminal) open import Categories.Morphism.Reasoning 𝒞 private open Category 𝒞 open HomReasoning variable A B C : Obj f g h : A ⇒ B -- A (canonical) cartesian closed category is a category with all -- (canonical) products and exponentials -- -- This presentation is equivalent to the one in -- Categories.Category.CartesianClosed.CartesianClosed. record CartesianClosed : Set (levelOfTerm 𝒞) where infixr 7 _×_ infixr 9 _^_ infix 10 ⟨_,_⟩ field -- Canonical products ⊤ : Obj _×_ : Obj → Obj → Obj ! : A ⇒ ⊤ π₁ : A × B ⇒ A π₂ : A × B ⇒ B ⟨_,_⟩ : C ⇒ A → C ⇒ B → C ⇒ A × B !-unique : (f : A ⇒ ⊤) → ! ≈ f π₁-comp : π₁ ∘ ⟨ f , g ⟩ ≈ f π₂-comp : π₂ ∘ ⟨ f , g ⟩ ≈ g ⟨,⟩-unique : ∀ {f g} {h : C ⇒ A × B} → π₁ ∘ h ≈ f → π₂ ∘ h ≈ g → ⟨ f , g ⟩ ≈ h -- The above defines canonical finite products, making 𝒞 cartesian. ⊤-terminal : Terminal ⊤-terminal = record { ⊤-is-terminal = record { !-unique = !-unique } } ×-product : ∀ {A B} → Product A B ×-product {A} {B} = record { project₁ = π₁-comp; project₂ = π₂-comp; unique = ⟨,⟩-unique } isCartesian : Cartesian isCartesian = record { terminal = ⊤-terminal ; products = record { product = ×-product } } open Cartesian isCartesian open BinaryProducts products using (_⁂_) field -- Canonical exponentials (w.r.t. the canonical products) _^_ : Obj → Obj → Obj eval : B ^ A × A ⇒ B curry : C × A ⇒ B → C ⇒ B ^ A eval-comp : eval ∘ (curry f ⁂ id) ≈ f curry-resp-≈ : f ≈ g → curry f ≈ curry g curry-unique : eval ∘ (f ⁂ id) ≈ g → f ≈ curry g -- The above defines canonical exponentials, making 𝒞 cartesian closed. -- -- NOTE: below we use "⊗" to indicate "non-canonical" products. ^-exponential : ∀ {A B} → Exponential A B ^-exponential {A} {B} = record { B^A = B ^ A ; product = ×-product ; eval = eval ; λg = λ C⊗A f → curry (f ∘ repack ×-product C⊗A) ; β = λ {C} C⊗A {g} → begin eval ∘ [ C⊗A ⇒ ×-product ] curry (g ∘ repack ×-product C⊗A) ×id ≈˘⟨ pullʳ [ ×-product ⇒ ×-product ]×∘⟨⟩ ⟩ (eval ∘ (curry (g ∘ repack ×-product C⊗A) ⁂ id)) ∘ repack C⊗A ×-product ≈⟨ eval-comp ⟩∘⟨refl ⟩ (g ∘ repack ×-product C⊗A) ∘ repack C⊗A ×-product ≈⟨ cancelʳ (repack∘repack≈id ×-product C⊗A) ⟩ g ∎ ; λ-unique = λ {C} C⊗A {g} {f} hyp → curry-unique (begin eval ∘ (f ⁂ id) ≈˘⟨ pullʳ [ C⊗A ⇒ ×-product ]×∘⟨⟩ ⟩ (eval ∘ [ C⊗A ⇒ ×-product ] f ×id) ∘ repack ×-product C⊗A ≈⟨ hyp ⟩∘⟨refl ⟩ g ∘ repack ×-product C⊗A ∎) } module Equivalence where open 𝒞-CC using () renaming (CartesianClosed to CartesianClosed′) -- The two presentations of CCCs are equivalent fromCanonical : CartesianClosed → CartesianClosed′ fromCanonical cc = record { cartesian = CartesianClosed.isCartesian cc ; exp = CartesianClosed.^-exponential cc } toCanonical : CartesianClosed′ → CartesianClosed toCanonical cc = record { ⊤ = ⊤ ; _×_ = _×_ ; ! = ! ; π₁ = π₁ ; π₂ = π₂ ; ⟨_,_⟩ = ⟨_,_⟩ ; !-unique = !-unique ; π₁-comp = project₁ ; π₂-comp = project₂ ; ⟨,⟩-unique = unique ; _^_ = _^_ ; eval = eval′ ; curry = λg ; eval-comp = β′ ; curry-resp-≈ = λ-cong ; curry-unique = λ-unique′ } where open CartesianClosed′ cc open BinaryProducts (Cartesian.products cartesian) open Terminal (Cartesian.terminal cartesian)
29.282209
87
0.60067
417d7f075654a0c2f793b1c9ad530df411345ae3
8,349
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Setoid/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
----------------------------------------------------------------------- -- The Agda standard library -- -- Properties of the setoid sublist relation ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Setoid; _⇒_; _Preserves_⟶_) module Data.List.Relation.Binary.Sublist.Setoid.Properties {c ℓ} (S : Setoid c ℓ) where open import Data.List.Base hiding (_∷ʳ_) import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality import Data.List.Relation.Binary.Sublist.Setoid as SetoidSublist import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties as HeteroProperties import Data.List.Membership.Setoid as SetoidMembership open import Data.List.Relation.Unary.Any using (Any) open import Data.Nat using (_≤_; _≥_; z≤n; s≤s) import Data.Nat.Properties as ℕₚ import Data.Maybe.Relation.Unary.All as Maybe open import Function open import Function.Bijection using (_⤖_) open import Function.Equivalence using (_⇔_) open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Relation.Unary using (Pred; Decidable; Irrelevant) open import Relation.Nullary using (¬_) open import Relation.Nullary.Negation using (¬?) open Setoid S using (_≈_) renaming (Carrier to A) open SetoidEquality S using (_≋_; ≋-refl) open SetoidSublist S hiding (map) open SetoidMembership S using (_∈_) ------------------------------------------------------------------------ -- Injectivity of constructors ------------------------------------------------------------------------ module _ {xs ys : List A} where ∷-injectiveˡ : ∀ {x y} {px qx : x ≈ y} {pxs qxs : xs ⊆ ys} → ((x ∷ xs) ⊆ (y ∷ ys) ∋ px ∷ pxs) ≡ (qx ∷ qxs) → px ≡ qx ∷-injectiveˡ refl = refl ∷-injectiveʳ : ∀ {x y} {px qx : x ≈ y} {pxs qxs : xs ⊆ ys} → ((x ∷ xs) ⊆ (y ∷ ys) ∋ px ∷ pxs) ≡ (qx ∷ qxs) → pxs ≡ qxs ∷-injectiveʳ refl = refl ∷ʳ-injective : ∀ {y} {pxs qxs : xs ⊆ ys} → y ∷ʳ pxs ≡ y ∷ʳ qxs → pxs ≡ qxs ∷ʳ-injective refl = refl ------------------------------------------------------------------------ -- Various functions' outputs are sublists ------------------------------------------------------------------------ tail-⊆ : ∀ xs → Maybe.All (_⊆ xs) (tail xs) tail-⊆ xs = HeteroProperties.tail-Sublist ⊆-refl take-⊆ : ∀ n xs → take n xs ⊆ xs take-⊆ n xs = HeteroProperties.take-Sublist n ⊆-refl drop-⊆ : ∀ n xs → drop n xs ⊆ xs drop-⊆ n xs = HeteroProperties.drop-Sublist n ⊆-refl module _ {p} {P : Pred A p} (P? : Decidable P) where takeWhile-⊆ : ∀ xs → takeWhile P? xs ⊆ xs takeWhile-⊆ xs = HeteroProperties.takeWhile-Sublist P? ⊆-refl dropWhile-⊆ : ∀ xs → dropWhile P? xs ⊆ xs dropWhile-⊆ xs = HeteroProperties.dropWhile-Sublist P? ⊆-refl filter-⊆ : ∀ xs → filter P? xs ⊆ xs filter-⊆ xs = HeteroProperties.filter-Sublist P? ⊆-refl module _ {p} {P : Pred A p} (P? : Decidable P) where takeWhile⊆filter : ∀ xs → takeWhile P? xs ⊆ filter P? xs takeWhile⊆filter xs = HeteroProperties.takeWhile-filter P? {xs} ≋-refl filter⊆dropWhile : ∀ xs → filter P? xs ⊆ dropWhile (¬? ∘ P?) xs filter⊆dropWhile xs = HeteroProperties.filter-dropWhile P? {xs} ≋-refl ------------------------------------------------------------------------ -- Various list functions are increasing wrt _⊆_ ------------------------------------------------------------------------ -- We write f⁺ for the proof that `xs ⊆ ys → f xs ⊆ f ys` -- and f⁻ for the one that `f xs ⊆ f ys → xs ⊆ ys`. module _ {as bs : List A} where ∷ˡ⁻ : ∀ {a} → a ∷ as ⊆ bs → as ⊆ bs ∷ˡ⁻ = HeteroProperties.∷ˡ⁻ ∷ʳ⁻ : ∀ {a b} → ¬ (a ≈ b) → a ∷ as ⊆ b ∷ bs → a ∷ as ⊆ bs ∷ʳ⁻ = HeteroProperties.∷ʳ⁻ ∷⁻ : ∀ {a b} → a ∷ as ⊆ b ∷ bs → as ⊆ bs ∷⁻ = HeteroProperties.∷⁻ ------------------------------------------------------------------------ -- map module _ {b ℓ} (R : Setoid b ℓ) where open Setoid R using () renaming (Carrier to B; _≈_ to _≈′_) open SetoidSublist R using () renaming (_⊆_ to _⊆′_) map⁺ : ∀ {as bs} {f : A → B} → f Preserves _≈_ ⟶ _≈′_ → as ⊆ bs → map f as ⊆′ map f bs map⁺ {f = f} f-resp as⊆bs = HeteroProperties.map⁺ f f (SetoidSublist.map S f-resp as⊆bs) ------------------------------------------------------------------------ -- _++_ module _ {as bs : List A} where ++⁺ˡ : ∀ cs → as ⊆ bs → as ⊆ cs ++ bs ++⁺ˡ = HeteroProperties.++ˡ ++⁺ʳ : ∀ cs → as ⊆ bs → as ⊆ bs ++ cs ++⁺ʳ = HeteroProperties.++ʳ ++⁺ : ∀ {cs ds} → as ⊆ bs → cs ⊆ ds → as ++ cs ⊆ bs ++ ds ++⁺ = HeteroProperties.++⁺ ++⁻ : ∀ {cs ds} → length as ≡ length bs → as ++ cs ⊆ bs ++ ds → cs ⊆ ds ++⁻ = HeteroProperties.++⁻ ------------------------------------------------------------------------ -- take module _ where take⁺ : ∀ {m n} {xs} → m ≤ n → take m xs ⊆ take n xs take⁺ m≤n = HeteroProperties.take⁺ m≤n ≋-refl ------------------------------------------------------------------------ -- drop module _ {m n} {xs ys : List A} where drop⁺ : m ≥ n → xs ⊆ ys → drop m xs ⊆ drop n ys drop⁺ = HeteroProperties.drop⁺ module _ {m n} {xs : List A} where drop⁺-≥ : m ≥ n → drop m xs ⊆ drop n xs drop⁺-≥ m≥n = drop⁺ m≥n ⊆-refl module _ {xs ys : List A} where drop⁺-⊆ : ∀ n → xs ⊆ ys → drop n xs ⊆ drop n ys drop⁺-⊆ n xs⊆ys = drop⁺ {n} ℕₚ.≤-refl xs⊆ys ------------------------------------------------------------------------ -- takeWhile / dropWhile module _ {p q} {P : Pred A p} {Q : Pred A q} (P? : Decidable P) (Q? : Decidable Q) where takeWhile⁺ : ∀ {xs} → (∀ {a b} → a ≈ b → P a → Q b) → takeWhile P? xs ⊆ takeWhile Q? xs takeWhile⁺ {xs} P⇒Q = HeteroProperties.⊆-takeWhile-Sublist P? Q? {xs} P⇒Q ≋-refl dropWhile⁺ : ∀ {xs} → (∀ {a b} → a ≈ b → Q b → P a) → dropWhile P? xs ⊆ dropWhile Q? xs dropWhile⁺ {xs} P⇒Q = HeteroProperties.⊇-dropWhile-Sublist P? Q? {xs} P⇒Q ≋-refl ------------------------------------------------------------------------ -- filter module _ {p q} {P : Pred A p} {Q : Pred A q} (P? : Decidable P) (Q? : Decidable Q) where filter⁺ : ∀ {as bs} → (∀ {a b} → a ≈ b → P a → Q b) → as ⊆ bs → filter P? as ⊆ filter Q? bs filter⁺ = HeteroProperties.⊆-filter-Sublist P? Q? ------------------------------------------------------------------------ -- reverse module _ {as bs : List A} where reverseAcc⁺ : ∀ {cs ds} → as ⊆ bs → cs ⊆ ds → reverseAcc cs as ⊆ reverseAcc ds bs reverseAcc⁺ = HeteroProperties.reverseAcc⁺ reverse⁺ : as ⊆ bs → reverse as ⊆ reverse bs reverse⁺ = HeteroProperties.reverse⁺ reverse⁻ : reverse as ⊆ reverse bs → as ⊆ bs reverse⁻ = HeteroProperties.reverse⁻ ------------------------------------------------------------------------ -- Inversion lemmas ------------------------------------------------------------------------ module _ {a b} {A : Set a} {B : Set b} {a as b bs} where ∷⁻¹ : a ≈ b → as ⊆ bs ⇔ a ∷ as ⊆ b ∷ bs ∷⁻¹ = HeteroProperties.∷⁻¹ ∷ʳ⁻¹ : ¬ (a ≈ b) → a ∷ as ⊆ bs ⇔ a ∷ as ⊆ b ∷ bs ∷ʳ⁻¹ = HeteroProperties.∷ʳ⁻¹ ------------------------------------------------------------------------ -- Other ------------------------------------------------------------------------ module _ where length-mono-≤ : ∀ {as bs} → as ⊆ bs → length as ≤ length bs length-mono-≤ = HeteroProperties.length-mono-≤ ------------------------------------------------------------------------ -- Conversion to and from list equality to-≋ : ∀ {as bs} → length as ≡ length bs → as ⊆ bs → as ≋ bs to-≋ = HeteroProperties.toPointwise ------------------------------------------------------------------------ -- Irrelevant special case module _ {a b} {A : Set a} {B : Set b} where []⊆-irrelevant : Irrelevant ([] ⊆_) []⊆-irrelevant = HeteroProperties.Sublist-[]-irrelevant ------------------------------------------------------------------------ -- (to/from)∈ is a bijection module _ {x xs} where to∈-injective : ∀ {p q : [ x ] ⊆ xs} → to∈ p ≡ to∈ q → p ≡ q to∈-injective = HeteroProperties.toAny-injective from∈-injective : ∀ {p q : x ∈ xs} → from∈ p ≡ from∈ q → p ≡ q from∈-injective = HeteroProperties.fromAny-injective to∈∘from∈≗id : ∀ (p : x ∈ xs) → to∈ (from∈ p) ≡ p to∈∘from∈≗id = HeteroProperties.toAny∘fromAny≗id [x]⊆xs⤖x∈xs : ([ x ] ⊆ xs) ⤖ (x ∈ xs) [x]⊆xs⤖x∈xs = HeteroProperties.Sublist-[x]-bijection
33.396
82
0.48401
1cc15e4eacce802ad878fea14b5f2fe657c31311
6,037
agda
Agda
old/Homotopy/PullbackInvariantEquiv.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Homotopy/PullbackInvariantEquiv.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Homotopy/PullbackInvariantEquiv.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import Base open import Homotopy.PullbackDef {- In this file we prove that if two diagrams are equivalent (there are equivalences between the types and the squares are commutative), then the natural map between the pullbacks is also an equivalence -} module Homotopy.PullbackInvariantEquiv {i} (d d' : pullback-diag i) where private pullback-to-pullback : ∀ {i} {A A' : Set i} (p : A ≡ A') {B B' : Set i} (q : B ≡ B') {C C' : Set i} (r : C ≡ C') {f : A → C} {f' : A' → C'} (s : (a : A) → f' ((transport _ p) a) ≡ transport _ r (f a)) {g : B → C} {g' : B' → C'} (t : (b : B) → transport _ r (g b) ≡ g' ((transport _ q) b)) → pullback (diag A , B , C , f , g) → pullback (diag A' , B' , C' , f' , g') pullback-to-pullback p q r s t (a , b , e) = (transport _ p a , transport _ q b , (s a ∘ (ap (transport _ r) e ∘ t b))) transport-pullback : ∀ {i} {A A' : Set i} (p : A ≡ A') {B B' : Set i} (q : B ≡ B') {C C' : Set i} (r : C ≡ C') {f : A → C} {f' : A' → C'} (s : f' ◯ (transport _ p) ≡ transport _ r ◯ f) {g : B → C} {g' : B' → C'} (t : transport _ r ◯ g ≡ g' ◯ (transport _ q)) → transport pullback (pullback-diag-raw-eq p q r {f' = f'} s {g' = g'} t) ≡ pullback-to-pullback p q r (happly s) (happly t) transport-pullback refl refl refl refl refl = funext (λ r → ap (λ u → _ , _ , u) (! (ap-id _) ∘ ! (refl-right-unit _))) transport-pullback-funext : ∀ {i} {A A' : Set i} (p : A ≡ A') {B B' : Set i} (q : B ≡ B') {C C' : Set i} (r : C ≡ C') {f : A → C} {f' : A' → C'} (s : (a : A) → f' ((transport _ p) a) ≡ transport _ r (f a)) {g : B → C} {g' : B' → C'} (t : (b : B) → transport _ r (g b) ≡ g' ((transport _ q) b)) → transport pullback (pullback-diag-raw-eq p q r {f' = f'} (funext s) {g' = g'} (funext t)) ≡ pullback-to-pullback p q r s t transport-pullback-funext p q r s t = transport-pullback p q r (funext s) (funext t) ∘ (ap (λ u → pullback-to-pullback p q r u (happly (funext t))) (happly-funext s) ∘ ap (λ u → pullback-to-pullback p q r s u) (happly-funext t)) path-to-eq-ap : ∀ {i j} {A : Set i} (P : A → Set j) {x y : A} (p : x ≡ y) → π₁ (path-to-eq (ap P p)) ≡ transport P p path-to-eq-ap P refl = refl open pullback-diag d open pullback-diag d' renaming (A to A'; B to B'; C to C'; f to f'; g to g') module PullbackInvariantEquiv (eqA : A ≃ A') (eqB : B ≃ B') (eqC : C ≃ C') (p : (a : A) → f' (eqA ☆ a) ≡ eqC ☆ (f a)) (q : (b : B) → eqC ☆ (g b) ≡ g' (eqB ☆ b)) where private d≡d' : d ≡ d' d≡d' = pullback-diag-eq eqA eqB eqC p q pullback-equiv-pullback : pullback d ≃ pullback d' pullback-equiv-pullback = path-to-eq (ap pullback d≡d') h : (a : A) → f' ((transport (λ v → v) (eq-to-path eqA) a)) ≡ transport (λ v → v) (eq-to-path eqC) (f a) h a = ap f' (trans-id-eq-to-path eqA a) ∘ (p a ∘ (! (trans-id-eq-to-path eqC (f a)))) h' : (b : B) → transport (λ v → v) (eq-to-path eqC) (g b) ≡ g' ((transport (λ v → v) (eq-to-path eqB) b)) h' b = trans-id-eq-to-path eqC (g b) ∘ (q b ∘ ap g' (! (trans-id-eq-to-path eqB b))) pullback-to-equiv-pullback : pullback d → pullback d' pullback-to-equiv-pullback (a , b , e) = ((eqA ☆ a) , (eqB ☆ b) , (p a ∘ (ap (π₁ eqC) e ∘ q b))) private pb-to-pb-equal-pb-to-equiv-pb : (x : pullback d) → pullback-to-pullback (eq-to-path eqA) (eq-to-path eqB) (eq-to-path eqC) h h' x ≡ pullback-to-equiv-pullback x pb-to-pb-equal-pb-to-equiv-pb (a , b , h) = pullback-eq d' (trans-id-eq-to-path eqA a) (trans-id-eq-to-path eqB b) (concat-assoc (ap f' (trans-id (eq-to-path eqA) a ∘ _) ∘ _) _ _ ∘ (concat-assoc (ap f' (trans-id (eq-to-path eqA) a ∘ _)) _ _ ∘ whisker-left (ap f' (trans-id (eq-to-path eqA) a ∘ _)) (concat-assoc (p a) _ _ ∘ whisker-left (p a) (whisker-left (! (trans-id (eq-to-path eqC) (f a) ∘ _)) (concat-assoc (ap (transport (λ v → v) (eq-to-path eqC)) h) _ _ ∘ whisker-left (ap (transport (λ v → v) (eq-to-path eqC)) h) (concat-assoc (trans-id (eq-to-path eqC) (g b) ∘ _) _ _ ∘ whisker-left (trans-id (eq-to-path eqC) (g b) ∘ _) (concat-assoc (q b) _ _ ∘ (whisker-left (q b) (concat-ap g' (! (trans-id (eq-to-path eqB) b ∘ _)) _ ∘ ap (ap g') (opposite-left-inverse (trans-id (eq-to-path eqB) b ∘ _))) ∘ refl-right-unit (q b))))) ∘ move!-right-on-left (trans-id (eq-to-path eqC) (f a) ∘ _) _ _ (! (concat-assoc (ap (transport (λ v → v) (eq-to-path eqC)) h) (trans-id (eq-to-path eqC) (g b) ∘ _) _) ∘ ((whisker-right (q b) (homotopy-naturality (transport (λ v → v) (eq-to-path eqC)) (π₁ eqC) (λ t → trans-id (eq-to-path eqC) t ∘ ap (λ u → π₁ u t) (eq-to-path-right-inverse eqC)) h)) ∘ concat-assoc (trans-id (eq-to-path eqC) (f a) ∘ _) (ap (π₁ eqC) h) (q b))))))) pb-equiv-pb-equal-pb-to-equiv-pb : π₁ pullback-equiv-pullback ≡ pullback-to-equiv-pullback pb-equiv-pb-equal-pb-to-equiv-pb = path-to-eq-ap pullback d≡d' ∘ (transport-pullback-funext (eq-to-path eqA) (eq-to-path eqB) (eq-to-path eqC) h h' ∘ funext pb-to-pb-equal-pb-to-equiv-pb) abstract pullback-invariant-is-equiv : is-equiv pullback-to-equiv-pullback pullback-invariant-is-equiv = transport is-equiv pb-equiv-pb-equal-pb-to-equiv-pb (π₂ pullback-equiv-pullback) pullback-invariant-equiv : pullback d ≃ pullback d' pullback-invariant-equiv = (pullback-to-equiv-pullback , pullback-invariant-is-equiv) open PullbackInvariantEquiv public
44.389706
80
0.511347
a1565b8be26fddded38020b93f43474be2252de7
299
agda
Agda
test/Fail/Issue2247.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2247.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2247.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where open import Agda.Builtin.Equality module MM1 (A : Set) where postulate a0 : A module M1 (a : A) where postulate x : A module M = M1 a0 module MM2 (A : Set) where open module MM1A = MM1 A check : M1.x ≡ (λ a → a) check = refl -- used to be internal error
14.95
44
0.618729
39b05d1d1f831a775db4a8a76f7e82e37f440f8f
138
agda
Agda
Everything.agda
myuon/agda-cate
59004994acdbc65fb4f8abf0baa1777a8dbe758e
[ "MIT" ]
2
2018-07-28T04:59:31.000Z
2019-11-02T07:30:47.000Z
Everything.agda
myuon/agda-cate
59004994acdbc65fb4f8abf0baa1777a8dbe758e
[ "MIT" ]
null
null
null
Everything.agda
myuon/agda-cate
59004994acdbc65fb4f8abf0baa1777a8dbe758e
[ "MIT" ]
null
null
null
module Everything where import Basic import Category import Functor import Nat import Yoneda import Adjoint import Monad import TAlgebra
12.545455
23
0.855072
22ff8b65e7ab6ded3292749b3da385eec416a077
2,541
agda
Agda
SOAS/Coalgebraic/Monoid.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
SOAS/Coalgebraic/Monoid.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
SOAS/Coalgebraic/Monoid.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
-- Families with compatible monoid and coal module SOAS.Coalgebraic.Monoid {T : Set} where open import SOAS.Common open import SOAS.Context {T} open import SOAS.Variable open import SOAS.Families.Core {T} import SOAS.Families.Delta {T} as δ; open δ.Sorted open import SOAS.Abstract.Hom {T} import SOAS.Abstract.Box {T} as □ ; open □.Sorted open import SOAS.Abstract.Monoid {T} import SOAS.Abstract.Coalgebra {T} as →□ ; open →□.Sorted open import SOAS.Coalgebraic.Map open import SOAS.Coalgebraic.Strength open import SOAS.Coalgebraic.Lift private variable Γ Δ : Ctx α β : T -- Coalgebraic monoid: family with compatible coalgebra and monoid structure record CoalgMon (𝒳 : Familyₛ) : Set where field ᴮ : Coalgₚ 𝒳 ᵐ : Mon 𝒳 open Coalgₚ ᴮ public renaming (η to ηᴮ) open Mon ᵐ public hiding (ᵇ ; ᴮ ; r ; r∘η ; μᶜ) renaming (η to ηᵐ) field η-compat : {v : ℐ α Γ} → ηᴮ v ≡ ηᵐ v μ-compat : {ρ : Γ ↝ Δ}{t : 𝒳 α Γ} → r t ρ ≡ μ t (ηᵐ ∘ ρ) open Coalgₚ ᴮ using (r∘η) public -- Multiplication of coalgebraic monoids is a pointed coalgebraic map μᶜ : Coalgebraic ᴮ ᴮ ᴮ μ μᶜ = record { r∘f = λ{ {σ = σ}{ϱ}{t} → begin r (μ t σ) ϱ ≡⟨ μ-compat ⟩ μ (μ t σ) (ηᵐ ∘ ϱ) ≡⟨ assoc ⟩ μ t (λ v → μ (σ v) (ηᵐ ∘ ϱ)) ≡˘⟨ cong (μ t) (dext (λ _ → μ-compat)) ⟩ μ t (λ v → r (σ v) ϱ) ∎ } ; f∘r = λ{ {ρ = ρ}{ς}{t} → begin μ (r t ρ) ς ≡⟨ cong (λ - → μ - ς) μ-compat ⟩ μ (μ t (ηᵐ ∘ ρ)) ς ≡⟨ assoc ⟩ μ t (λ v → μ (ηᵐ (ρ v)) ς) ≡⟨ cong (μ t) (dext (λ _ → lunit)) ⟩ μ t (ς ∘ ρ) ∎ } ; f∘η = trans (μ≈₂ η-compat) runit } where open ≡-Reasoning str-eq : (𝒴 : Familyₛ){F : Functor 𝔽amiliesₛ 𝔽amiliesₛ}(F:Str : Strength F) (open Functor F)(open Strength F:Str) (h : F₀ 〖 𝒳 , 𝒴 〗 α Γ)(σ : Γ ~[ 𝒳 ]↝ Δ) → str ᴮ 𝒴 h σ ≡ str (Mon.ᴮ ᵐ) 𝒴 h σ str-eq 𝒴 {F} F:Str h σ = begin str ᴮ 𝒴 h σ ≡⟨ str-nat₁ {f = id} (record { ᵇ⇒ = record { ⟨r⟩ = sym μ-compat } ; ⟨η⟩ = sym η-compat }) h σ ⟩ str (Mon.ᴮ ᵐ) 𝒴 (F₁ id h) σ ≡⟨ congr identity (λ - → str (Mon.ᴮ ᵐ) 𝒴 - σ) ⟩ str (Mon.ᴮ ᵐ) 𝒴 h σ ∎ where open Functor F open Strength F:Str open ≡-Reasoning lift-eq : {Ξ : Ctx}(t : 𝒳 β (Ξ ∔ Γ))(σ : Γ ~[ 𝒳 ]↝ Δ) → μ t (lift ᴮ Ξ σ) ≡ μ t (lift (Mon.ᴮ ᵐ) Ξ σ) lift-eq {Ξ = Ξ} t σ = str-eq 𝒳 (δ:Strength Ξ) (μ t) σ
33.88
83
0.514758
0633216785983a7f3a56ffc2c52b6270e30bff1e
5,601
agda
Agda
old/Homotopy/ConnectedSuspension.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Homotopy/ConnectedSuspension.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Homotopy/ConnectedSuspension.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import Base open import Homotopy.Truncation open import Homotopy.Connected open import Spaces.Suspension open import Homotopy.PushoutDef import Homotopy.PushoutUP as PushoutUP -- In this file I prove that if [A] is n-connected and its (n+1)-truncation is -- inhabited, then [suspension A] is (n+1)-connected. -- -- The hypothesis that [τ (S n) A] is inhabited is not necessary, it can be -- removed but it’s simpler to assume it module Homotopy.ConnectedSuspension {i} (A : Set i) {n : ℕ₋₂} (p : is-connected n A) (x₀ : τ (S n) A) where -- The (n+1)-truncation of the suspension is a pushout of the following diagram τ-susp-diag : pushout-diag i τ-susp-diag = diag τ (S n) unit , τ (S n) unit , τ (S n) A , τ-extend-nondep (λ _ → proj tt) , τ-extend-nondep (λ _ → proj tt) module τ-susp-H = PushoutUP τ-susp-diag (is-truncated (S n)) import Homotopy.TruncationRightExact (S n) (suspension-diag A) as Exact abstract trunc-cocone : τ-susp-H.cocone (τ (S n) (suspension A)) trunc-cocone = Exact.cocone-τpushout trunc-is-pushout : τ-susp-H.is-pushout (τ (S n) (suspension A)) trunc-cocone trunc-is-pushout = Exact.τpushout-is-pushout -- The previous diagram is equivalent to the following susp-diag : pushout-diag i susp-diag = suspension-diag (τ (S n) A) module susp-H = PushoutUP susp-diag (is-truncated (S n)) -- To be moved τ-unit-to-unit : τ (S n) (unit {i}) → unit {i} τ-unit-to-unit _ = tt abstract τ-unit-to-unit-is-equiv : is-equiv τ-unit-to-unit τ-unit-to-unit-is-equiv = iso-is-eq _ (λ _ → proj tt) (λ _ → refl) (τ-extend ⦃ λ _ → ≡-is-truncated (S n) (τ-is-truncated (S n) _) ⦄ (λ _ → refl)) τ-unit-equiv-unit : τ (S n) unit ≃ unit τ-unit-equiv-unit = (τ-unit-to-unit , τ-unit-to-unit-is-equiv) -- / To be moved abstract τ-susp-equal-susp : τ-susp-diag ≡ susp-diag τ-susp-equal-susp = pushout-diag-eq τ-unit-equiv-unit τ-unit-equiv-unit (id-equiv _) (λ _ → refl) (λ _ → refl) -- But we prove by hand that the point is also a pushout of this diagram unit-cocone : susp-H.cocone unit unit-cocone = (id _ susp-H., id _ , cst refl) private factor-pushout : (E : Set i) → (susp-H.cocone E → (unit {i} → E)) factor-pushout E c = susp-H.A→top c x : {E : Set i} → (susp-H.cocone E → E) x c = susp-H.A→top c tt y : {E : Set i} → (susp-H.cocone E → E) y c = susp-H.B→top c tt x≡y : {E : Set i} (c : susp-H.cocone E) → x c ≡ y c x≡y c = susp-H.h c x₀ ττA-is-contr : is-contr (τ n (τ (S n) A)) ττA-is-contr = equiv-types-truncated _ (τ-equiv-ττ n A) p susp-H-unit-is-pushout : susp-H.is-pushout unit unit-cocone susp-H-unit-is-pushout E ⦃ P-E ⦄ = iso-is-eq _ (factor-pushout E) (λ c → susp-H.cocone-eq-raw _ refl (funext (λ _ → x≡y c)) (app-is-inj x₀ ττA-is-contr (P-E _ _) (trans-Π2 _ (λ v _ → susp-H.A→top c tt ≡ v tt) (funext (λ r → susp-H.h c x₀)) _ _ ∘ (trans-cst≡app _ (λ u → u tt) (funext (λ r → susp-H.h c x₀)) _ ∘ happly (happly-funext (λ _ → susp-H.h c x₀)) tt)))) (λ _ → refl) -- Type of (S n)-truncated pushout-diagrams (this should probably be defined -- more generally in Homotopy.PushoutDef or something) truncated-diag : Set _ truncated-diag = Σ (pushout-diag i) (λ d → (is-truncated (S n) (pushout-diag.A d)) × ((is-truncated (S n) (pushout-diag.B d)) × (is-truncated (S n) (pushout-diag.C d)))) τ-susp-trunc-diag : truncated-diag τ-susp-trunc-diag = (τ-susp-diag , (τ-is-truncated (S n) _ , (τ-is-truncated (S n) _ , τ-is-truncated (S n) _))) susp-trunc-diag : truncated-diag susp-trunc-diag = (susp-diag , (unit-is-truncated-S#instance , (unit-is-truncated-S#instance , τ-is-truncated (S n) _))) -- The two diagrams are equal as truncated diagrams abstract τ-susp-trunc-equal-susp-trunc : τ-susp-trunc-diag ≡ susp-trunc-diag τ-susp-trunc-equal-susp-trunc = Σ-eq τ-susp-equal-susp (Σ-eq (π₁ (is-truncated-is-prop (S n) _ _)) (Σ-eq (π₁ (is-truncated-is-prop (S n) _ _)) (π₁ (is-truncated-is-prop (S n) _ _)))) new-cocone : (d : truncated-diag) → (Set i → Set i) new-cocone (d , (_ , (_ , _))) = PushoutUP.cocone d (is-truncated (S n)) new-is-pushout : (d : truncated-diag) → ((D : Set i) ⦃ PD : is-truncated (S n) D ⦄ (Dcocone : new-cocone d D) → Set _) new-is-pushout (d , (_ , (_ , _))) = PushoutUP.is-pushout d (is-truncated (S n)) unit-new-cocone : (d : truncated-diag) → new-cocone d unit unit-new-cocone d = ((λ _ → tt) PushoutUP., (λ _ → tt) , (λ _ → refl)) unit-is-pushout : (d : truncated-diag) → Set _ unit-is-pushout d = new-is-pushout d unit (unit-new-cocone d) abstract unit-τ-is-pushout : τ-susp-H.is-pushout unit (unit-new-cocone τ-susp-trunc-diag) unit-τ-is-pushout = transport unit-is-pushout (! τ-susp-trunc-equal-susp-trunc) susp-H-unit-is-pushout private unit-equiv-τSnΣA : unit {i} ≃ τ (S n) (suspension A) unit-equiv-τSnΣA = τ-susp-H.pushout-equiv-pushout unit (unit-new-cocone τ-susp-trunc-diag) unit-τ-is-pushout (τ (S n) (suspension A)) trunc-cocone trunc-is-pushout abstract suspension-is-connected-S : is-connected (S n) (suspension A) suspension-is-connected-S = equiv-types-truncated _ unit-equiv-τSnΣA unit-is-contr
35.226415
79
0.599536
3147c50fd4be91554a16131ff8420f1a5c5db157
4,787
agda
Agda
Mixfix/Acyclic/Example.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
Mixfix/Acyclic/Example.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
Mixfix/Acyclic/Example.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- An example ------------------------------------------------------------------------ module Mixfix.Acyclic.Example where open import Coinduction open import Data.Vec using ([]; _∷_; [_]) open import Data.List as List using (List; []; _∷_) renaming ([_] to L[_]) open import Data.List.Any using (here; there) open import Data.List.Any.Membership.Propositional using (_∈_) import Data.Colist as Colist open import Data.Product using (∃₂; ,_) open import Data.Unit using (⊤) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Nat using (zero; suc) open import Data.Fin using (#_) import Data.String as String open String using (String; _++_) open import Relation.Binary import Relation.Binary.List.Pointwise as ListEq open DecSetoid (ListEq.decSetoid String.decSetoid) using (_≟_) open import Function using (_∘_; _$_) open import Data.Bool using (Bool; if_then_else_) import Data.Bool.Show as Bool open import Relation.Nullary.Decidable using (⌊_⌋) import Relation.Binary.PropositionalEquality as P open import IO open import Mixfix.Fixity hiding (_≟_) open import Mixfix.Operator open import Mixfix.Expr open import Mixfix.Acyclic.PrecedenceGraph import Mixfix.Acyclic.Grammar as Grammar import Mixfix.Acyclic.Show as Show import StructurallyRecursiveDescentParsing.Simplified as Simplified open Simplified using (Parser) import StructurallyRecursiveDescentParsing.DepthFirst as DepthFirst import TotalParserCombinators.BreadthFirst as BreadthFirst ------------------------------------------------------------------------ -- Operators atom : Operator closed 0 atom = record { nameParts = "•" ∷ [] } plus : Operator (infx left) 0 plus = record { nameParts = "+" ∷ [] } ifThen : Operator prefx 1 ifThen = record { nameParts = "i" ∷ "t" ∷ [] } ifThenElse : Operator prefx 2 ifThenElse = record { nameParts = "i" ∷ "t" ∷ "e" ∷ [] } comma : Operator (infx left) 0 comma = record { nameParts = "," ∷ [] } wellTyped : Operator postfx 1 wellTyped = record { nameParts = "⊢" ∷ "∶" ∷ [] } ------------------------------------------------------------------------ -- Precedence graph prec : List (∃₂ Operator) → List Precedence → Precedence prec ops = precedence (λ fix → List.gfilter (hasFixity fix) ops) mutual a = prec ((, , atom) ∷ []) [] pl = prec ((, , plus) ∷ []) (a ∷ []) ii = prec ((, , ifThen) ∷ (, , ifThenElse) ∷ []) (pl ∷ a ∷ []) c = prec ((, , comma) ∷ []) (ii ∷ pl ∷ a ∷ []) wt = prec ((, , wellTyped) ∷ []) (c ∷ a ∷ []) g : PrecedenceGraph g = wt ∷ c ∷ ii ∷ pl ∷ a ∷ [] ------------------------------------------------------------------------ -- Expressions open PrecedenceCorrect acyclic g • : ExprIn a non • = ⟪ here P.refl ∙ [] ⟫ _+_ : Outer pl left → Expr (a ∷ []) → ExprIn pl left e₁ + e₂ = e₁ ⟨ here P.refl ∙ [] ⟩ˡ e₂ i_t_ : Expr g → Outer ii right → ExprIn ii right i e₁ t e₂ = ⟪ here P.refl ∙ e₁ ∷ [] ⟩ e₂ i_t_e_ : Expr g → Expr g → Outer ii right → ExprIn ii right i e₁ t e₂ e e₃ = ⟪ there (here P.refl) ∙ e₁ ∷ e₂ ∷ [] ⟩ e₃ _,_ : Outer c left → Expr (ii ∷ pl ∷ a ∷ []) → ExprIn c left e₁ , e₂ = e₁ ⟨ here P.refl ∙ [] ⟩ˡ e₂ _⊢_∶ : Outer wt left → Expr g → Expr g e₁ ⊢ e₂ ∶ = here P.refl ∙ (e₁ ⟨ here P.refl ∙ [ e₂ ] ⟫) ------------------------------------------------------------------------ -- Some tests open Show g fromNameParts : List NamePart → String fromNameParts = List.foldr _++_ "" toNameParts : String → List NamePart toNameParts = List.map (String.fromList ∘ L[_]) ∘ String.toList data Backend : Set where depthFirst : Backend breadthFirst : Backend parse : ∀ {Tok e R} → Backend → Parser Tok e R → List Tok → List R parse depthFirst p = DepthFirst.parseComplete p parse breadthFirst p = BreadthFirst.parse (Simplified.⟦_⟧ p) parseExpr : Backend → String → List String parseExpr backend = List.map (fromNameParts ∘ show) ∘ parse backend (Grammar.expression g) ∘ toNameParts -- The breadth-first backend is considerably slower than the -- depth-first one on these examples. backend = depthFirst runTest : String → List String → IO ⊤ runTest s₁ s₂ = ♯ putStrLn ("Testing: " ++ s₁) >> ♯ (♯ mapM′ putStrLn (Colist.fromList p₁) >> ♯ putStrLn (if ⌊ p₁ ≟ s₂ ⌋ then "Passed" else "Failed") ) where p₁ = parseExpr backend s₁ main = run (♯ runTest "•+•⊢•∶" [] >> ♯ (♯ runTest "•,•⊢∶" [] >> ♯ (♯ runTest "•⊢•∶" L[ "•⊢•∶" ] >> ♯ (♯ runTest "•,i•t•+•⊢•∶" L[ "•,i•t•+•⊢•∶" ] >> ♯ runTest "i•ti•t•e•" ("i•ti•t•e•" ∷ "i•ti•t•e•" ∷ []) ))))
33.243056
72
0.555881
3d7d7708d47bf42b495c726ce42399b8501829bb
7,152
agda
Agda
agda-stdlib/src/Algebra/Consequences/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Algebra/Consequences/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Algebra/Consequences/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Relations between properties of functions, such as associativity and -- commutativity, when the underlying relation is a setoid ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel; Setoid; Substitutive; Symmetric; Total) module Algebra.Consequences.Setoid {a ℓ} (S : Setoid a ℓ) where open Setoid S renaming (Carrier to A) open import Algebra.Core open import Algebra.Definitions _≈_ open import Data.Sum.Base using (inj₁; inj₂) open import Data.Product using (_,_) import Relation.Binary.Consequences as Bin open import Relation.Binary.Reasoning.Setoid S open import Relation.Unary using (Pred) ------------------------------------------------------------------------ -- Re-exports -- Export base lemmas that don't require the setoidd open import Algebra.Consequences.Base public ------------------------------------------------------------------------ -- Magma-like structures module _ {_•_ : Op₂ A} (comm : Commutative _•_) where comm+cancelˡ⇒cancelʳ : LeftCancellative _•_ → RightCancellative _•_ comm+cancelˡ⇒cancelʳ cancelˡ {x} y z eq = cancelˡ x (begin x • y ≈⟨ comm x y ⟩ y • x ≈⟨ eq ⟩ z • x ≈⟨ comm z x ⟩ x • z ∎) comm+cancelʳ⇒cancelˡ : RightCancellative _•_ → LeftCancellative _•_ comm+cancelʳ⇒cancelˡ cancelʳ x {y} {z} eq = cancelʳ y z (begin y • x ≈⟨ comm y x ⟩ x • y ≈⟨ eq ⟩ x • z ≈⟨ comm x z ⟩ z • x ∎) ------------------------------------------------------------------------ -- Monoid-like structures module _ {_•_ : Op₂ A} (comm : Commutative _•_) {e : A} where comm+idˡ⇒idʳ : LeftIdentity e _•_ → RightIdentity e _•_ comm+idˡ⇒idʳ idˡ x = begin x • e ≈⟨ comm x e ⟩ e • x ≈⟨ idˡ x ⟩ x ∎ comm+idʳ⇒idˡ : RightIdentity e _•_ → LeftIdentity e _•_ comm+idʳ⇒idˡ idʳ x = begin e • x ≈⟨ comm e x ⟩ x • e ≈⟨ idʳ x ⟩ x ∎ comm+zeˡ⇒zeʳ : LeftZero e _•_ → RightZero e _•_ comm+zeˡ⇒zeʳ zeˡ x = begin x • e ≈⟨ comm x e ⟩ e • x ≈⟨ zeˡ x ⟩ e ∎ comm+zeʳ⇒zeˡ : RightZero e _•_ → LeftZero e _•_ comm+zeʳ⇒zeˡ zeʳ x = begin e • x ≈⟨ comm e x ⟩ x • e ≈⟨ zeʳ x ⟩ e ∎ ------------------------------------------------------------------------ -- Group-like structures module _ {_•_ : Op₂ A} {_⁻¹ : Op₁ A} {e} (comm : Commutative _•_) where comm+invˡ⇒invʳ : LeftInverse e _⁻¹ _•_ → RightInverse e _⁻¹ _•_ comm+invˡ⇒invʳ invˡ x = begin x • (x ⁻¹) ≈⟨ comm x (x ⁻¹) ⟩ (x ⁻¹) • x ≈⟨ invˡ x ⟩ e ∎ comm+invʳ⇒invˡ : RightInverse e _⁻¹ _•_ → LeftInverse e _⁻¹ _•_ comm+invʳ⇒invˡ invʳ x = begin (x ⁻¹) • x ≈⟨ comm (x ⁻¹) x ⟩ x • (x ⁻¹) ≈⟨ invʳ x ⟩ e ∎ module _ {_•_ : Op₂ A} {_⁻¹ : Op₁ A} {e} (cong : Congruent₂ _•_) where assoc+id+invʳ⇒invˡ-unique : Associative _•_ → Identity e _•_ → RightInverse e _⁻¹ _•_ → ∀ x y → (x • y) ≈ e → x ≈ (y ⁻¹) assoc+id+invʳ⇒invˡ-unique assoc (idˡ , idʳ) invʳ x y eq = begin x ≈⟨ sym (idʳ x) ⟩ x • e ≈⟨ cong refl (sym (invʳ y)) ⟩ x • (y • (y ⁻¹)) ≈⟨ sym (assoc x y (y ⁻¹)) ⟩ (x • y) • (y ⁻¹) ≈⟨ cong eq refl ⟩ e • (y ⁻¹) ≈⟨ idˡ (y ⁻¹) ⟩ y ⁻¹ ∎ assoc+id+invˡ⇒invʳ-unique : Associative _•_ → Identity e _•_ → LeftInverse e _⁻¹ _•_ → ∀ x y → (x • y) ≈ e → y ≈ (x ⁻¹) assoc+id+invˡ⇒invʳ-unique assoc (idˡ , idʳ) invˡ x y eq = begin y ≈⟨ sym (idˡ y) ⟩ e • y ≈⟨ cong (sym (invˡ x)) refl ⟩ ((x ⁻¹) • x) • y ≈⟨ assoc (x ⁻¹) x y ⟩ (x ⁻¹) • (x • y) ≈⟨ cong refl eq ⟩ (x ⁻¹) • e ≈⟨ idʳ (x ⁻¹) ⟩ x ⁻¹ ∎ ---------------------------------------------------------------------- -- Bisemigroup-like structures module _ {_•_ _◦_ : Op₂ A} (◦-cong : Congruent₂ _◦_) (•-comm : Commutative _•_) where comm+distrˡ⇒distrʳ : _•_ DistributesOverˡ _◦_ → _•_ DistributesOverʳ _◦_ comm+distrˡ⇒distrʳ distrˡ x y z = begin (y ◦ z) • x ≈⟨ •-comm (y ◦ z) x ⟩ x • (y ◦ z) ≈⟨ distrˡ x y z ⟩ (x • y) ◦ (x • z) ≈⟨ ◦-cong (•-comm x y) (•-comm x z) ⟩ (y • x) ◦ (z • x) ∎ comm+distrʳ⇒distrˡ : _•_ DistributesOverʳ _◦_ → _•_ DistributesOverˡ _◦_ comm+distrʳ⇒distrˡ distrˡ x y z = begin x • (y ◦ z) ≈⟨ •-comm x (y ◦ z) ⟩ (y ◦ z) • x ≈⟨ distrˡ x y z ⟩ (y • x) ◦ (z • x) ≈⟨ ◦-cong (•-comm y x) (•-comm z x) ⟩ (x • y) ◦ (x • z) ∎ comm⇒sym[distribˡ] : ∀ x → Symmetric (λ y z → (x ◦ (y • z)) ≈ ((x ◦ y) • (x ◦ z))) comm⇒sym[distribˡ] x {y} {z} prf = begin x ◦ (z • y) ≈⟨ ◦-cong refl (•-comm z y) ⟩ x ◦ (y • z) ≈⟨ prf ⟩ (x ◦ y) • (x ◦ z) ≈⟨ •-comm (x ◦ y) (x ◦ z) ⟩ (x ◦ z) • (x ◦ y) ∎ ---------------------------------------------------------------------- -- Ring-like structures module _ {_+_ _*_ : Op₂ A} {_⁻¹ : Op₁ A} {0# : A} (+-cong : Congruent₂ _+_) (*-cong : Congruent₂ _*_) where assoc+distribʳ+idʳ+invʳ⇒zeˡ : Associative _+_ → _*_ DistributesOverʳ _+_ → RightIdentity 0# _+_ → RightInverse 0# _⁻¹ _+_ → LeftZero 0# _*_ assoc+distribʳ+idʳ+invʳ⇒zeˡ +-assoc distribʳ idʳ invʳ x = begin 0# * x ≈⟨ sym (idʳ _) ⟩ (0# * x) + 0# ≈⟨ +-cong refl (sym (invʳ _)) ⟩ (0# * x) + ((0# * x) + ((0# * x)⁻¹)) ≈⟨ sym (+-assoc _ _ _) ⟩ ((0# * x) + (0# * x)) + ((0# * x)⁻¹) ≈⟨ +-cong (sym (distribʳ _ _ _)) refl ⟩ ((0# + 0#) * x) + ((0# * x)⁻¹) ≈⟨ +-cong (*-cong (idʳ _) refl) refl ⟩ (0# * x) + ((0# * x)⁻¹) ≈⟨ invʳ _ ⟩ 0# ∎ assoc+distribˡ+idʳ+invʳ⇒zeʳ : Associative _+_ → _*_ DistributesOverˡ _+_ → RightIdentity 0# _+_ → RightInverse 0# _⁻¹ _+_ → RightZero 0# _*_ assoc+distribˡ+idʳ+invʳ⇒zeʳ +-assoc distribˡ idʳ invʳ x = begin x * 0# ≈⟨ sym (idʳ _) ⟩ (x * 0#) + 0# ≈⟨ +-cong refl (sym (invʳ _)) ⟩ (x * 0#) + ((x * 0#) + ((x * 0#)⁻¹)) ≈⟨ sym (+-assoc _ _ _) ⟩ ((x * 0#) + (x * 0#)) + ((x * 0#)⁻¹) ≈⟨ +-cong (sym (distribˡ _ _ _)) refl ⟩ (x * (0# + 0#)) + ((x * 0#)⁻¹) ≈⟨ +-cong (*-cong refl (idʳ _)) refl ⟩ ((x * 0#) + ((x * 0#)⁻¹)) ≈⟨ invʳ _ ⟩ 0# ∎ ------------------------------------------------------------------------ -- Without Loss of Generality module _ {p} {f : Op₂ A} {P : Pred A p} (≈-subst : Substitutive _≈_ p) (comm : Commutative f) where subst+comm⇒sym : Symmetric (λ a b → P (f a b)) subst+comm⇒sym = ≈-subst P (comm _ _) wlog : ∀ {r} {_R_ : Rel _ r} → Total _R_ → (∀ a b → a R b → P (f a b)) → ∀ a b → P (f a b) wlog r-total = Bin.wlog r-total subst+comm⇒sym
36.121212
84
0.435682