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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
df500824729e0f7fae70202e096bfe9f5807fc5c
| 12,612
|
agda
|
Agda
|
Cubical/Relation/ZigZag/Applications/MultiSet.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Relation/ZigZag/Applications/MultiSet.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Relation/ZigZag/Applications/MultiSet.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
-- We apply the theory of quasi equivalence relations (QERs) to finite multisets and association lists.
{-# OPTIONS --safe #-}
module Cubical.Relation.ZigZag.Applications.MultiSet where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.RelationalStructure
open import Cubical.Foundations.Structure
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Univalence
open import Cubical.Data.Unit
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat
open import Cubical.Data.List hiding ([_])
open import Cubical.Data.Sigma
open import Cubical.HITs.SetQuotients
open import Cubical.HITs.FiniteMultiset as FMS hiding ([_] ; _++_)
open import Cubical.HITs.FiniteMultiset.CountExtensionality
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Relation.Nullary
open import Cubical.Relation.ZigZag.Base
open import Cubical.Structures.MultiSet
open import Cubical.Structures.Relational.Auto
open import Cubical.Structures.Relational.Macro
-- we define simple association lists without any higher constructors
data AList {ℓ} (A : Type ℓ) : Type ℓ where
⟨⟩ : AList A
⟨_,_⟩∷_ : A → ℕ → AList A → AList A
infixr 5 ⟨_,_⟩∷_
private
variable
ℓ : Level
-- We have a CountStructure on List and AList and use these to get a QER between the two
module Lists&ALists {A : Type ℓ} (discA : Discrete A) where
multisetShape : Type ℓ → Type ℓ
multisetShape X = X × (A → X → X) × (X → X → X) × (A → X → Const[ ℕ , isSetℕ ])
module S = RelMacro ℓ (autoRelDesc multisetShape)
addIfEq : (a x : A) → ℕ → ℕ → ℕ
addIfEq a x m n with discA a x
... | yes _ = m + n
... | no _ = n
module _ {a x : A} {n : ℕ} where
addIfEq≡ : {m : ℕ} → a ≡ x → addIfEq a x m n ≡ m + n
addIfEq≡ a≡x with discA a x
... | yes _ = refl
... | no a≢x = ⊥.rec (a≢x a≡x)
addIfEq≢ : {m : ℕ} → ¬ (a ≡ x) → addIfEq a x m n ≡ n
addIfEq≢ a≢x with discA a x
... | yes a≡x = ⊥.rec (a≢x a≡x)
... | no _ = refl
addIfEq0 : addIfEq a x 0 n ≡ n
addIfEq0 with discA a x
... | yes _ = refl
... | no _ = refl
addIfEq+ : {m : ℕ} (n' : ℕ) → addIfEq a x m (n + n') ≡ addIfEq a x m n + n'
addIfEq+ n' with discA a x
... | yes _ = +-assoc _ n n'
... | no _ = refl
module L where
emp : List A
emp = []
insert : A → List A → List A
insert x xs = x ∷ xs
union : List A → List A → List A
union xs ys = xs ++ ys
count : A → List A → ℕ
count a [] = zero
count a (x ∷ xs) = addIfEq a x 1 (count a xs)
structure : S.structure (List A)
structure = emp , insert , union , count
countUnion : ∀ a xs ys → count a (union xs ys) ≡ count a xs + count a ys
countUnion a [] ys = refl
countUnion a (x ∷ xs) ys =
cong (addIfEq a x 1) (countUnion a xs ys)
∙ addIfEq+ (count a ys)
module AL where
emp : AList A
emp = ⟨⟩
insert* : ℕ → A → AList A → AList A
insert* m a ⟨⟩ = ⟨ a , m ⟩∷ ⟨⟩
insert* m a (⟨ y , n ⟩∷ ys) with (discA a y)
... | yes _ = ⟨ y , m + n ⟩∷ ys
... | no _ = ⟨ y , n ⟩∷ insert* m a ys
insert : A → AList A → AList A
insert = insert* 1
union : AList A → AList A → AList A
union ⟨⟩ ys = ys
union (⟨ x , n ⟩∷ xs) ys = insert* n x (union xs ys)
count : A → AList A → ℕ
count a ⟨⟩ = zero
count a (⟨ y , n ⟩∷ ys) = addIfEq a y n (count a ys)
structure : S.structure (AList A)
structure = emp , insert , union , count
countInsert* : ∀ m a x ys → count a (insert* m x ys) ≡ addIfEq a x m (count a ys)
countInsert* m a x ⟨⟩ = refl
countInsert* m a x (⟨ y , n ⟩∷ ys) with discA a x | discA a y | discA x y
... | yes a≡x | yes a≡y | yes x≡y = addIfEq≡ a≡y ∙ sym (+-assoc m n _)
... | yes a≡x | yes a≡y | no x≢y = ⊥.rec (x≢y (sym a≡x ∙ a≡y))
... | yes a≡x | no a≢y | yes x≡y = ⊥.rec (a≢y (a≡x ∙ x≡y))
... | yes a≡x | no a≢y | no x≢y = addIfEq≢ a≢y ∙ countInsert* m a x ys ∙ addIfEq≡ a≡x
... | no a≢x | yes a≡y | yes x≡y = ⊥.rec (a≢x (a≡y ∙ sym x≡y))
... | no a≢x | yes a≡y | no x≢y = addIfEq≡ a≡y ∙ cong (n +_) (countInsert* m a x ys ∙ addIfEq≢ a≢x)
... | no a≢x | no a≢y | yes x≡y = addIfEq≢ a≢y
... | no a≢x | no a≢y | no x≢y = addIfEq≢ a≢y ∙ countInsert* m a x ys ∙ addIfEq≢ a≢x
countInsert = countInsert* 1
countUnion : ∀ a xs ys → count a (union xs ys) ≡ count a xs + count a ys
countUnion a ⟨⟩ ys = refl
countUnion a (⟨ x , n ⟩∷ xs) ys =
countInsert* n a x (union xs ys)
∙ cong (addIfEq a x n) (countUnion a xs ys)
∙ addIfEq+ (count a ys)
-- now for the QER between List and Alist
R : List A → AList A → Type ℓ
R xs ys = ∀ a → L.count a xs ≡ AL.count a ys
φ : List A → AList A
φ [] = ⟨⟩
φ (x ∷ xs) = AL.insert x (φ xs)
ψ : AList A → List A
ψ ⟨⟩ = []
ψ (⟨ x , zero ⟩∷ xs) = ψ xs
ψ (⟨ x , suc n ⟩∷ xs) = x ∷ ψ (⟨ x , n ⟩∷ xs)
η : ∀ xs → R xs (φ xs)
η [] a = refl
η (x ∷ xs) a = cong (addIfEq a x 1) (η xs a) ∙ sym (AL.countInsert a x (φ xs))
-- for the other direction we need a little helper function
ε : ∀ y → R (ψ y) y
ε' : (x : A) (n : ℕ) (xs : AList A) (a : A)
→ L.count a (ψ (⟨ x , n ⟩∷ xs)) ≡ AL.count a (⟨ x , n ⟩∷ xs)
ε ⟨⟩ a = refl
ε (⟨ x , n ⟩∷ xs) a = ε' x n xs a
ε' x zero xs a = ε xs a ∙ sym addIfEq0
ε' x (suc n) xs a with discA a x
... | yes a≡x = cong suc (ε' x n xs a ∙ addIfEq≡ a≡x)
... | no a≢x = ε' x n xs a ∙ addIfEq≢ a≢x
-- Induced quotients and equivalence
open isQuasiEquivRel
-- R is a QER
QuasiR : QuasiEquivRel _ _ ℓ
QuasiR .fst .fst = R
QuasiR .fst .snd _ _ = isPropΠ λ _ → isSetℕ _ _
QuasiR .snd .zigzag r r' r'' a = (r a) ∙∙ sym (r' a) ∙∙ (r'' a)
QuasiR .snd .fwd a = ∣ φ a , η a ∣
QuasiR .snd .bwd b = ∣ ψ b , ε b ∣
isStructuredInsert : (x : A) {xs : List A} {ys : AList A}
→ R xs ys → R (L.insert x xs) (AL.insert x ys)
isStructuredInsert x {xs} {ys} r a =
cong (addIfEq a x 1) (r a) ∙ sym (AL.countInsert a x ys)
isStructuredUnion :
{xs : List A} {ys : AList A} (r : R xs ys)
{xs' : List A} {ys' : AList A} (r' : R xs' ys')
→ R (L.union xs xs') (AL.union ys ys')
isStructuredUnion {xs} {ys} r {xs'} {ys'} r' a =
L.countUnion a xs xs' ∙ cong₂ _+_ (r a) (r' a) ∙ sym (AL.countUnion a ys ys')
-- R is structured
isStructuredR : S.relation R L.structure AL.structure
isStructuredR .fst a = refl
isStructuredR .snd .fst = isStructuredInsert
isStructuredR .snd .snd .fst {xs} {ys} = isStructuredUnion {xs} {ys}
isStructuredR .snd .snd .snd a r = r a
module E = QER→Equiv QuasiR
open E renaming (Rᴸ to Rᴸ; Rᴿ to Rᴬᴸ)
List/Rᴸ = (List A) / Rᴸ
AList/Rᴬᴸ = (AList A) / Rᴬᴸ
List/Rᴸ≃AList/Rᴬᴸ : List/Rᴸ ≃ AList/Rᴬᴸ
List/Rᴸ≃AList/Rᴬᴸ = E.Thm
main : QERDescends _ S.relation (List A , L.structure) (AList A , AL.structure) QuasiR
main = structuredQER→structuredEquiv S.suitable _ _ QuasiR isStructuredR
open QERDescends
LQstructure : S.structure List/Rᴸ
LQstructure = main .quoᴸ .fst
ALQstructure : S.structure AList/Rᴬᴸ
ALQstructure = main .quoᴿ .fst
-- We get a path between structure over the equivalence from the fact that the QER is structured
List/Rᴸ≡AList/Rᴬᴸ :
Path (TypeWithStr ℓ S.structure) (List/Rᴸ , LQstructure) (AList/Rᴬᴸ , ALQstructure)
List/Rᴸ≡AList/Rᴬᴸ =
sip S.univalent _ _
(E.Thm , S.matches (List/Rᴸ , LQstructure) (AList/Rᴬᴸ , ALQstructure) E.Thm .fst (main .rel))
-- Deriving associativity of union for association list multisets
LQunion = LQstructure .snd .snd .fst
ALQunion = ALQstructure .snd .snd .fst
hasAssociativeUnion : TypeWithStr ℓ S.structure → Type ℓ
hasAssociativeUnion (_ , _ , _ , _⊔_ , _) =
∀ xs ys zs → (xs ⊔ ys) ⊔ zs ≡ xs ⊔ (ys ⊔ zs)
LQassoc : hasAssociativeUnion (List/Rᴸ , LQstructure)
LQassoc = elimProp3 (λ _ _ _ → squash/ _ _) (λ xs ys zs i → [ ++-assoc xs ys zs i ])
ALQassoc : hasAssociativeUnion (AList/Rᴬᴸ , ALQstructure)
ALQassoc = subst hasAssociativeUnion List/Rᴸ≡AList/Rᴬᴸ LQassoc
-- We now show that List/Rᴸ≃FMSet
_∷/_ : A → List/Rᴸ → List/Rᴸ
_∷/_ = LQstructure .snd .fst
multisetShape' : Type ℓ → Type ℓ
multisetShape' X = X × (A → X → X) × (A → X → Const[ ℕ , isSetℕ ])
FMSstructure : S.structure (FMSet A)
FMSstructure = [] , _∷_ , FMS._++_ , FMScount discA
infixr 5 _∷/_
FMSet→List/Rᴸ : FMSet A → List/Rᴸ
FMSet→List/Rᴸ = FMS.Rec.f squash/ [ [] ] _∷/_ β
where
δ : ∀ c a b xs → L.count c (a ∷ b ∷ xs) ≡ L.count c (b ∷ a ∷ xs)
δ c a b xs with discA c a | discA c b
δ c a b xs | yes _ | yes _ = refl
δ c a b xs | yes _ | no _ = refl
δ c a b xs | no _ | yes _ = refl
δ c a b xs | no _ | no _ = refl
γ : ∀ a b xs → Rᴸ (a ∷ b ∷ xs) (b ∷ a ∷ xs)
γ a b xs =
∣ φ (a ∷ b ∷ xs) , η (a ∷ b ∷ xs) , (λ c → δ c b a xs ∙ η (a ∷ b ∷ xs) c) ∣
β : ∀ a b [xs] → a ∷/ b ∷/ [xs] ≡ b ∷/ a ∷/ [xs]
β a b = elimProp (λ _ → squash/ _ _) (λ xs → eq/ _ _ (γ a b xs))
-- The inverse is induced by the standard projection of lists into finite multisets,
-- which is a morphism of CountStructures
-- Moreover, we need 'count-extensionality' for finite multisets
List→FMSet : List A → FMSet A
List→FMSet [] = []
List→FMSet (x ∷ xs) = x ∷ List→FMSet xs
List→FMSet-count : ∀ a xs → L.count a xs ≡ FMScount discA a (List→FMSet xs)
List→FMSet-count a [] = refl
List→FMSet-count a (x ∷ xs) with discA a x
... | yes _ = cong suc (List→FMSet-count a xs)
... | no _ = List→FMSet-count a xs
List/Rᴸ→FMSet : List/Rᴸ → FMSet A
List/Rᴸ→FMSet [ xs ] = List→FMSet xs
List/Rᴸ→FMSet (eq/ xs ys r i) = path i
where
countsAgree : ∀ a → L.count a xs ≡ L.count a ys
countsAgree a = cong (LQstructure .snd .snd .snd a) (eq/ xs ys r)
θ : ∀ a → FMScount discA a (List→FMSet xs) ≡ FMScount discA a (List→FMSet ys)
θ a = sym (List→FMSet-count a xs) ∙∙ countsAgree a ∙∙ List→FMSet-count a ys
path : List→FMSet xs ≡ List→FMSet ys
path = FMScountExt.Thm discA _ _ θ
List/Rᴸ→FMSet (squash/ xs/ xs/' p q i j) =
trunc (List/Rᴸ→FMSet xs/) (List/Rᴸ→FMSet xs/') (cong List/Rᴸ→FMSet p) (cong List/Rᴸ→FMSet q) i j
List/Rᴸ→FMSet-insert : (x : A) (ys : List/Rᴸ) → List/Rᴸ→FMSet (x ∷/ ys) ≡ x ∷ List/Rᴸ→FMSet ys
List/Rᴸ→FMSet-insert x = elimProp (λ _ → FMS.trunc _ _) λ xs → refl
List→FMSet-union : (xs ys : List A)
→ List→FMSet (xs ++ ys) ≡ FMS._++_ (List→FMSet xs) (List→FMSet ys)
List→FMSet-union [] ys = refl
List→FMSet-union (x ∷ xs) ys = cong (x ∷_) (List→FMSet-union xs ys)
List/Rᴸ≃FMSet : List/Rᴸ ≃ FMSet A
List/Rᴸ≃FMSet = isoToEquiv (iso List/Rᴸ→FMSet FMSet→List/Rᴸ τ σ)
where
σ' : (xs : List A) → FMSet→List/Rᴸ (List/Rᴸ→FMSet [ xs ]) ≡ [ xs ]
σ' [] = refl
σ' (x ∷ xs) = cong (x ∷/_) (σ' xs)
σ : section FMSet→List/Rᴸ List/Rᴸ→FMSet
σ = elimProp (λ _ → squash/ _ _) σ'
τ' : ∀ x {xs} → List/Rᴸ→FMSet (FMSet→List/Rᴸ xs) ≡ xs → List/Rᴸ→FMSet (FMSet→List/Rᴸ (x ∷ xs)) ≡ x ∷ xs
τ' x {xs} p = List/Rᴸ→FMSet-insert x (FMSet→List/Rᴸ xs) ∙ cong (x ∷_) p
τ : retract FMSet→List/Rᴸ List/Rᴸ→FMSet
τ = FMS.ElimProp.f (FMS.trunc _ _) refl τ'
List/Rᴸ≃FMSet-EquivStr : S.equiv (List/Rᴸ , LQstructure) (FMSet A , FMSstructure) List/Rᴸ≃FMSet
List/Rᴸ≃FMSet-EquivStr .fst = refl
List/Rᴸ≃FMSet-EquivStr .snd .fst a xs = List/Rᴸ→FMSet-insert a xs
List/Rᴸ≃FMSet-EquivStr .snd .snd .fst = elimProp2 (λ _ _ → trunc _ _) List→FMSet-union
List/Rᴸ≃FMSet-EquivStr .snd .snd .snd a =
elimProp (λ _ → isSetℕ _ _) (List→FMSet-count a)
{-
Putting everything together we get:
≃
List/Rᴸ ------------> AList/Rᴬᴸ
|
|≃
|
∨
≃
FMSet A ------------> AssocList A
We thus get that AList/Rᴬᴸ≃AssocList.
Constructing such an equivalence directly requires count extensionality for association lists,
which should be even harder to prove than for finite multisets.
This strategy should work for all implementations of multisets with HITs.
We just have to show that:
∙ The HIT is equivalent to FMSet (like AssocList)
∙ There is a QER between lists and the basic data type of the HIT
with the higher constructors removed (like AList)
Then we get that this HIT is equivalent to the corresponding set quotient that identifies elements
that give the same count on each a : A.
TODO: Show that all the equivalences are indeed isomorphisms of multisets not only of CountStructures!
-}
| 35.130919
| 107
| 0.595544
|
4af0d01466e4690c5ba23edd5e399a3acca3ad93
| 2,219
|
agda
|
Agda
|
Cubical/HITs/MappingCones/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/MappingCones/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/MappingCones/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.MappingCones.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Unit
open import Cubical.Data.Sum
open import Cubical.HITs.Pushout
open import Cubical.HITs.MappingCones.Base
private
variable
ℓ ℓ' ℓ'' : Level
PushoutUnit-iso-Cone : ∀ {X : Type ℓ} {Y : Type ℓ'} (f : X → Y) → Iso (Pushout (const tt) f) (Cone f)
Iso.fun (PushoutUnit-iso-Cone f) (inl tt) = hub
Iso.fun (PushoutUnit-iso-Cone f) (inr x) = inj x
Iso.fun (PushoutUnit-iso-Cone f) (push x i) = spoke x i
Iso.inv (PushoutUnit-iso-Cone f) (inj x) = inr x
Iso.inv (PushoutUnit-iso-Cone f) hub = inl tt
Iso.inv (PushoutUnit-iso-Cone f) (spoke x i) = push x i
Iso.rightInv (PushoutUnit-iso-Cone f) (inj x) = refl
Iso.rightInv (PushoutUnit-iso-Cone f) hub = refl
Iso.rightInv (PushoutUnit-iso-Cone f) (spoke x i) = refl
Iso.leftInv (PushoutUnit-iso-Cone f) (inl tt) = refl
Iso.leftInv (PushoutUnit-iso-Cone f) (inr x) = refl
Iso.leftInv (PushoutUnit-iso-Cone f) (push x i) = refl
PushoutUnit≡Cone : ∀ {X : Type ℓ} {Y : Type ℓ'} (f : X → Y) → Pushout (const tt) f ≡ Cone f
PushoutUnit≡Cone f = isoToPath (PushoutUnit-iso-Cone f)
ConesUnit-iso-Cone : ∀ {X : Type ℓ} {Y : Type ℓ'} (f : X → Y) → Iso (Cones Unit (λ { tt → f })) (Cone f)
Iso.fun (ConesUnit-iso-Cone f) (inj x) = inj x
Iso.fun (ConesUnit-iso-Cone f) (hub tt) = hub
Iso.fun (ConesUnit-iso-Cone f) (spoke tt x i) = spoke x i
Iso.inv (ConesUnit-iso-Cone f) (inj x) = inj x
Iso.inv (ConesUnit-iso-Cone f) hub = hub tt
Iso.inv (ConesUnit-iso-Cone f) (spoke x i) = spoke tt x i
Iso.rightInv (ConesUnit-iso-Cone f) (inj x) = refl
Iso.rightInv (ConesUnit-iso-Cone f) hub = refl
Iso.rightInv (ConesUnit-iso-Cone f) (spoke x i) = refl
Iso.leftInv (ConesUnit-iso-Cone f) (inj x) = refl
Iso.leftInv (ConesUnit-iso-Cone f) (hub x) = refl
Iso.leftInv (ConesUnit-iso-Cone f) (spoke a x i) = refl
ConesUnit≡Cone : ∀ {X : Type ℓ} {Y : Type ℓ'} (f : X → Y) → (Cones Unit (λ { tt → f })) ≡ (Cone f)
ConesUnit≡Cone f = isoToPath (ConesUnit-iso-Cone f)
| 42.673077
| 104
| 0.66201
|
2092b58c42b91594f67ac8e3a9f7e71470503791
| 455
|
agda
|
Agda
|
test/interaction/Issue800.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue800.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue800.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2013-02-18 problem with 'with'-display, see also issue 295
-- {-# OPTIONS -v tc.with:50 #-}
module Issue800 where
data ⊤ : Set where
tt : ⊤
data I⊤ : ⊤ → Set where
itt : ∀ r → I⊤ r
bug : ∀ l → ∀ k → I⊤ l → ⊤
bug .l k (itt l) with itt k
... | foo = {! foo!}
{-
Current rewriting:
bug .l l (itt k) | itt .k = ?
Desired rewriting:
bug .l k (itt l) | itt .k = ?
Jesper, 2019-11-21, new rewriting:
... | itt .k = ?
-}
| 18.2
| 70
| 0.523077
|
cbc9ee1ecbd03c8506efee2aae3688d958616273
| 2,521
|
agda
|
Agda
|
LibraBFT/Impl/Consensus/Liveness/ProposalGenerator.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Impl/Consensus/Liveness/ProposalGenerator.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Impl/Consensus/Liveness/ProposalGenerator.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Encode as Encode
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block
import LibraBFT.Impl.Consensus.ConsensusTypes.BlockData as BlockData
import LibraBFT.Impl.Types.BlockInfo as BlockInfo
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Util
open import LibraBFT.Prelude
open import Optics.All
module LibraBFT.Impl.Consensus.Liveness.ProposalGenerator where
ensureHighestQuorumCertM : Round → LBFT (Either ErrLog QuorumCert)
generateNilBlockM : Round → LBFT (Either ErrLog Block)
generateNilBlockM round =
ensureHighestQuorumCertM round ∙?∙ (ok ∘ Block.newNil round)
generateProposalM : Instant → Round → LBFT (Either ErrLog BlockData)
generateProposalM _now round = do
lrg ← use (lProposalGenerator ∙ pgLastRoundGenerated)
ifD lrg <?ℕ round
then (do
lProposalGenerator ∙ pgLastRoundGenerated ∙= round
ensureHighestQuorumCertM round ∙?∙ λ hqc -> do
payload ← ifD BlockInfo.hasReconfiguration (hqc ^∙ qcCertifiedBlock)
-- IMPL-DIFF : create a fake TX
then pure (Encode.encode 0) -- (Payload [])
else pure (Encode.encode 0) -- use pgTxnManager <*> use (rmEpochState ∙ esEpoch) <*> pure round
use (lRoundManager ∙ pgAuthor) >>= λ where
nothing → bail fakeErr -- ErrL (here ["lRoundManager.pgAuthor", "Nothing"])
(just author) →
ok (BlockData.newProposal payload author round {-pure blockTimestamp <*>-} hqc))
else bail fakeErr
-- where
-- here t = "ProposalGenerator" ∷ "generateProposal" ∷ t
ensureHighestQuorumCertM round = do
hqc ← use (lBlockStore ∙ bsHighestQuorumCert)
ifD‖ (hqc ^∙ qcCertifiedBlock ∙ biRound) ≥?ℕ round ≔
bail fakeErr {- ErrL (here [ "given round is lower than hqc round"
, show (hqc^.qcCertifiedBlock.biRound) ]) -}
‖ hqc ^∙ qcEndsEpoch ≔
bail fakeErr {-ErrEpochEndedNoProposals (here ["further proposals not allowed"])-}
‖ otherwise≔
ok hqc
-- where
-- here t = "ProposalGenerator":"ensureHighestQuorumCertM":lsR round:t
| 44.22807
| 117
| 0.685839
|
c5644280fc3efdfb808b740e50126e163a61a726
| 1,022
|
agda
|
Agda
|
Common/ContextPair.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
Common/ContextPair.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
Common/ContextPair.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module Common.ContextPair where
open import Common.Context public
-- Context pairs.
infix 4 _⁏_
record Cx² (U V : Set) : Set where
constructor _⁏_
field
int : Cx U
mod : Cx V
open Cx² public
∅² : ∀ {U V} → Cx² U V
∅² = ∅ ⁏ ∅
-- Context inclusion.
module _ {U V : Set} where
infix 3 _⊆²_
_⊆²_ : Cx² U V → Cx² U V → Set
Γ ⁏ Δ ⊆² Γ′ ⁏ Δ′ = Γ ⊆ Γ′ × Δ ⊆ Δ′
refl⊆² : ∀ {Π} → Π ⊆² Π
refl⊆² = refl⊆ , refl⊆
trans⊆² : ∀ {Π Π′ Π″} → Π ⊆² Π′ → Π′ ⊆² Π″ → Π ⊆² Π″
trans⊆² (η , θ) (η′ , θ′) = trans⊆ η η′ , trans⊆ θ θ′
weak⊆²₁ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊆² Γ , A ⁏ Δ
weak⊆²₁ = weak⊆ , refl⊆
weak⊆²₂ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊆² Γ ⁏ Δ , A
weak⊆²₂ = refl⊆ , weak⊆
bot⊆² : ∀ {Π} → ∅² ⊆² Π
bot⊆² = bot⊆ , bot⊆
-- Context concatenation.
module _ {U V : Set} where
_⧺²_ : Cx² U V → Cx² U V → Cx² U V
(Γ ⁏ Δ) ⧺² (Γ′ ⁏ Δ′) = Γ ⧺ Γ′ ⁏ Δ ⧺ Δ′
weak⊆²⧺₁ : ∀ {Π} Π′ → Π ⊆² Π ⧺² Π′
weak⊆²⧺₁ (Γ′ ⁏ Δ′) = weak⊆⧺₁ Γ′ , weak⊆⧺₁ Δ′
weak⊆²⧺₂ : ∀ {Π Π′} → Π′ ⊆² Π ⧺² Π′
weak⊆²⧺₂ = weak⊆⧺₂ , weak⊆⧺₂
| 18.581818
| 55
| 0.473581
|
1076cdbc1ee33d0a77e7aabb5c9721d2df620273
| 791
|
agda
|
Agda
|
archive/agda-2/Oscar/Class/Equivalence.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-2/Oscar/Class/Equivalence.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-2/Oscar/Class/Equivalence.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Oscar.Class.Equivalence where
open import Oscar.Class.Reflexivity
open import Oscar.Class.Symmetry
open import Oscar.Class.Transitivity
open import Oscar.Function
open import Oscar.Level
record Equivalence {a} {A : Set a} {ℓ} (_≋_ : A → A → Set ℓ) : Set (a ⊔ ℓ) where
field
⦃ ′reflexivity ⦄ : Reflexivity _≋_
⦃ ′symmetry ⦄ : Symmetry _≋_
⦃ ′transitivity ⦄ : Transitivity _≋_
open Equivalence ⦃ … ⦄ public hiding (′reflexivity; ′symmetry; ′transitivity)
instance
Equivalence⋆ : ∀
{a} {A : Set a} {ℓ} {_≋_ : A → A → Set ℓ}
⦃ _ : Reflexivity _≋_ ⦄
⦃ _ : Symmetry _≋_ ⦄
⦃ _ : Transitivity _≋_ ⦄
→ Equivalence _≋_
Equivalence.′reflexivity Equivalence⋆ = it
Equivalence.′symmetry Equivalence⋆ = it
Equivalence.′transitivity Equivalence⋆ = it
| 27.275862
| 80
| 0.668774
|
183342e4e44018aea301f8552001d389ba2ee53e
| 662
|
agda
|
Agda
|
test/Fail/ImplicitRecordFields.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/ImplicitRecordFields.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/ImplicitRecordFields.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- This file tests that implicit record fields are not printed out (by
-- default).
-- Andreas, 2016-07-20 Repaired this long disfunctional test case.
module ImplicitRecordFields where
record R : Set₁ where
field
{A} : Set
f : A → A
{B C} D {E} : Set
g : B → C → E
postulate
A : Set
r : R
data _≡_ {A : Set₁} (x : A) : A → Set where
refl : x ≡ x
foo : r ≡ record
{ A = A
; f = λ x → x
; B = A
; C = A
; D = A
; g = λ x _ → x
}
foo = refl
-- EXPECTED ERROR:
-- .R.A r != A of type Set
-- when checking that the expression refl has type
-- r ≡ record { f = λ x → x ; D = A ; g = λ x _ → x }
| 18.388889
| 70
| 0.521148
|
3925e485ffa3e9fbecbca0328ff56c819f75532d
| 417
|
agda
|
Agda
|
test/Succeed/Issue376Loop.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue376Loop.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue376Loop.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2014-01-01 Andreas, test case constructed by Christian Sattler
{-# OPTIONS --allow-unsolved-metas #-}
-- unguarded recursive record
record R : Set where
eta-equality
inductive
constructor cons
field
r : R
postulate F : (R → Set) → Set
q : (∀ P → F P) → (∀ P → F P)
q h P = h (λ {(cons x) → {!!}})
-- ISSUE WAS: Bug in implementation of eta-expansion of projected var,
-- leading to loop in Agda.
| 19.857143
| 70
| 0.63789
|
0e0aec86c63521d6419d820930d962a56bfb94ca
| 733
|
agda
|
Agda
|
Graph.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Graph.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Graph.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Type
module Graph {ℓ₁ ℓ₂} (V : Type{ℓ₁}) where
-- A graph is represented by a binary relation which states whether there is an edge from one vertex to another.
-- In other words, a graph is here defined by only its adjacency relation.
-- This is by default (without any assumptions) a directed multigraph which is possibly infinite.
--
-- An object of type Graph is the adjacency relation.
-- For (_⟶_ : Graph), (a b : V), an object of type (a ⟶ b) is an edge from vertices a to b, and its existence means that there is an edge from a to b.
Graph : Type
Graph = (V → V → Type{ℓ₂})
module _ (_⟶_ : Graph) where
-- Two vertices are adjacent when there is an edge from the first one to the second one.
Adjacent = _⟶_
| 43.117647
| 150
| 0.713506
|
fb8fa29be8724704d44f828758163bdb91a475e3
| 362
|
agda
|
Agda
|
test/interaction/Issue2537.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue2537.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue2537.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-04-10, issue #2537 reported by xekoukou
-- Preserve named args when splitting in a where clause.
-- {-# OPTIONS -v reify:100 #-}
data Bool : Set where
true false : Bool
fun : {a b c d e f g : Bool} → Bool → Bool
fun {g = g} x with x
... | r = {!g!} -- C-c C-c g
-- Expected result:
-- fun {g = true} x | r = ?
-- fun {g = false} x | r = ?
| 22.625
| 56
| 0.569061
|
23da4995c2722f0f2a5c0c20748d5189313caa10
| 5,614
|
agda
|
Agda
|
Cubical/Data/Maybe/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Data/Maybe/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Data/Maybe/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Data.Maybe.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Functions.Embedding
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Unit
open import Cubical.Data.Nat
open import Cubical.Relation.Nullary
open import Cubical.Data.Sum
open import Cubical.Data.Maybe.Base
map-Maybe-id : ∀ {ℓ} {A : Type ℓ} → ∀ m → map-Maybe (idfun A) m ≡ m
map-Maybe-id nothing = refl
map-Maybe-id (just _) = refl
-- Path space of Maybe type
module MaybePath {ℓ} {A : Type ℓ} where
Cover : Maybe A → Maybe A → Type ℓ
Cover nothing nothing = Lift Unit
Cover nothing (just _) = Lift ⊥
Cover (just _) nothing = Lift ⊥
Cover (just a) (just a') = a ≡ a'
reflCode : (c : Maybe A) → Cover c c
reflCode nothing = lift tt
reflCode (just b) = refl
encode : ∀ c c' → c ≡ c' → Cover c c'
encode c _ = J (λ c' _ → Cover c c') (reflCode c)
encodeRefl : ∀ c → encode c c refl ≡ reflCode c
encodeRefl c = JRefl (λ c' _ → Cover c c') (reflCode c)
decode : ∀ c c' → Cover c c' → c ≡ c'
decode nothing nothing _ = refl
decode (just _) (just _) p = cong just p
decodeRefl : ∀ c → decode c c (reflCode c) ≡ refl
decodeRefl nothing = refl
decodeRefl (just _) = refl
decodeEncode : ∀ c c' → (p : c ≡ c') → decode c c' (encode c c' p) ≡ p
decodeEncode c _ =
J (λ c' p → decode c c' (encode c c' p) ≡ p)
(cong (decode c c) (encodeRefl c) ∙ decodeRefl c)
encodeDecode : ∀ c c' → (d : Cover c c') → encode c c' (decode c c' d) ≡ d
encodeDecode nothing nothing _ = refl
encodeDecode (just a) (just a') =
J (λ a' p → encode (just a) (just a') (cong just p) ≡ p) (encodeRefl (just a))
Cover≃Path : ∀ c c' → Cover c c' ≃ (c ≡ c')
Cover≃Path c c' = isoToEquiv
(iso (decode c c') (encode c c') (decodeEncode c c') (encodeDecode c c'))
Cover≡Path : ∀ c c' → Cover c c' ≡ (c ≡ c')
Cover≡Path c c' = isoToPath
(iso (decode c c') (encode c c') (decodeEncode c c') (encodeDecode c c'))
isOfHLevelCover : (n : HLevel)
→ isOfHLevel (suc (suc n)) A
→ ∀ c c' → isOfHLevel (suc n) (Cover c c')
isOfHLevelCover n p nothing nothing = isOfHLevelLift (suc n) (isOfHLevelUnit (suc n))
isOfHLevelCover n p nothing (just a') = isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p (just a) nothing = isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p (just a) (just a') = p a a'
isOfHLevelMaybe : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isOfHLevel (suc (suc n)) A
→ isOfHLevel (suc (suc n)) (Maybe A)
isOfHLevelMaybe n lA c c' =
isOfHLevelRetract (suc n)
(MaybePath.encode c c')
(MaybePath.decode c c')
(MaybePath.decodeEncode c c')
(MaybePath.isOfHLevelCover n lA c c')
private
variable
ℓ : Level
A : Type ℓ
fromJust-def : A → Maybe A → A
fromJust-def a nothing = a
fromJust-def _ (just a) = a
just-inj : (x y : A) → just x ≡ just y → x ≡ y
just-inj x _ eq = cong (fromJust-def x) eq
isEmbedding-just : isEmbedding (just {A = A})
isEmbedding-just w z = MaybePath.Cover≃Path (just w) (just z) .snd
¬nothing≡just : ∀ {x : A} → ¬ (nothing ≡ just x)
¬nothing≡just {A = A} {x = x} p = lower (subst (caseMaybe (Maybe A) (Lift ⊥)) p (just x))
¬just≡nothing : ∀ {x : A} → ¬ (just x ≡ nothing)
¬just≡nothing {A = A} {x = x} p = lower (subst (caseMaybe (Lift ⊥) (Maybe A)) p (just x))
isProp-x≡nothing : (x : Maybe A) → isProp (x ≡ nothing)
isProp-x≡nothing nothing x w =
subst isProp (MaybePath.Cover≡Path nothing nothing) (isOfHLevelLift 1 isPropUnit) x w
isProp-x≡nothing (just _) p _ = ⊥.rec (¬just≡nothing p)
isProp-nothing≡x : (x : Maybe A) → isProp (nothing ≡ x)
isProp-nothing≡x nothing x w =
subst isProp (MaybePath.Cover≡Path nothing nothing) (isOfHLevelLift 1 isPropUnit) x w
isProp-nothing≡x (just _) p _ = ⊥.rec (¬nothing≡just p)
isContr-nothing≡nothing : isContr (nothing {A = A} ≡ nothing)
isContr-nothing≡nothing = inhProp→isContr refl (isProp-x≡nothing _)
discreteMaybe : Discrete A → Discrete (Maybe A)
discreteMaybe eqA nothing nothing = yes refl
discreteMaybe eqA nothing (just a') = no ¬nothing≡just
discreteMaybe eqA (just a) nothing = no ¬just≡nothing
discreteMaybe eqA (just a) (just a') with eqA a a'
... | yes p = yes (cong just p)
... | no ¬p = no (λ p → ¬p (just-inj _ _ p))
module SumUnit where
Maybe→SumUnit : Maybe A → Unit ⊎ A
Maybe→SumUnit nothing = inl tt
Maybe→SumUnit (just a) = inr a
SumUnit→Maybe : Unit ⊎ A → Maybe A
SumUnit→Maybe (inl _) = nothing
SumUnit→Maybe (inr a) = just a
Maybe→SumUnit→Maybe : (x : Maybe A) → SumUnit→Maybe (Maybe→SumUnit x) ≡ x
Maybe→SumUnit→Maybe nothing = refl
Maybe→SumUnit→Maybe (just _) = refl
SumUnit→Maybe→SumUnit : (x : Unit ⊎ A) → Maybe→SumUnit (SumUnit→Maybe x) ≡ x
SumUnit→Maybe→SumUnit (inl _) = refl
SumUnit→Maybe→SumUnit (inr _) = refl
Maybe≡SumUnit : Maybe A ≡ Unit ⊎ A
Maybe≡SumUnit = isoToPath (iso SumUnit.Maybe→SumUnit SumUnit.SumUnit→Maybe SumUnit.SumUnit→Maybe→SumUnit SumUnit.Maybe→SumUnit→Maybe)
congMaybeEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ A ≃ B → Maybe A ≃ Maybe B
congMaybeEquiv e = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun = map-Maybe (equivFun e)
isom .inv = map-Maybe (invEq e)
isom .rightInv nothing = refl
isom .rightInv (just b) = cong just (secEq e b)
isom .leftInv nothing = refl
isom .leftInv (just a) = cong just (retEq e a)
| 35.308176
| 133
| 0.654792
|
18669f7511e4e7a85d6021c69a312010bdae1f1a
| 30,021
|
agda
|
Agda
|
complexity/Complexity.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 2
|
2016-04-26T20:22:22.000Z
|
2019-08-08T12:27:18.000Z
|
complexity/Complexity.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 1
|
2020-03-23T08:39:04.000Z
|
2020-05-12T00:32:45.000Z
|
complexity/Complexity.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | null | null | null |
{- COMPLEXITY LANGUAGE -}
open import Preliminaries
open import Preorder-Max
module Complexity where
data CTp : Set where
unit : CTp
nat : CTp
_->c_ : CTp → CTp → CTp
_×c_ : CTp → CTp → CTp
list : CTp → CTp
bool : CTp
C : CTp
-- represent a context as a list of types
Ctx = List CTp
-- de Bruijn indices (for free variables)
data _∈_ : CTp → Ctx → Set where
i0 : ∀ {Γ τ}
→ τ ∈ (τ :: Γ)
iS : ∀ {Γ τ τ1}
→ τ ∈ Γ
→ τ ∈ (τ1 :: Γ)
data _|-_ : Ctx → CTp → Set where
unit : ∀ {Γ}
→ Γ |- unit
0C : ∀ {Γ}
→ Γ |- C
1C : ∀ {Γ}
→ Γ |- C
plusC : ∀ {Γ}
→ Γ |- C
→ Γ |- C
→ Γ |- C
var : ∀ {Γ τ}
→ τ ∈ Γ
→ Γ |- τ
z : ∀ {Γ}
→ Γ |- nat
suc : ∀ {Γ}
→ (e : Γ |- nat)
→ Γ |- nat
rec : ∀ {Γ τ}
→ Γ |- nat
→ Γ |- τ
→ (nat :: (τ :: Γ)) |- τ
→ Γ |- τ
lam : ∀ {Γ τ ρ}
→ (ρ :: Γ) |- τ
→ Γ |- (ρ ->c τ)
app : ∀ {Γ τ1 τ2}
→ Γ |- (τ2 ->c τ1)
→ Γ |- τ2
→ Γ |- τ1
prod : ∀ {Γ τ1 τ2}
→ Γ |- τ1
→ Γ |- τ2
→ Γ |- (τ1 ×c τ2)
l-proj : ∀ {Γ τ1 τ2}
→ Γ |- (τ1 ×c τ2)
→ Γ |- τ1
r-proj : ∀ {Γ τ1 τ2}
→ Γ |- (τ1 ×c τ2)
→ Γ |- τ2
nil : ∀ {Γ τ} → Γ |- list τ
_::c_ : ∀ {Γ τ} → Γ |- τ → Γ |- list τ → Γ |- list τ
listrec : ∀ {Γ τ τ'} → Γ |- list τ → Γ |- τ' → (τ :: (list τ :: (τ' :: Γ))) |- τ' → Γ |- τ'
true : ∀ {Γ} → Γ |- bool
false : ∀ {Γ} → Γ |- bool
_+C_ : ∀ {Γ τ} → Γ |- C → Γ |- (C ×c τ)→ Γ |- (C ×c τ)
c +C e = prod (plusC c (l-proj e)) (r-proj e)
------weakening and substitution lemmas
-- renaming = variable for variable substitution
--functional view:
--avoids induction,
--some associativity/unit properties for free
-- read: you can rename Γ' as Γ
rctx : Ctx → Ctx → Set
rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ
rename-var : ∀ {Γ Γ' τ} → rctx Γ Γ' → τ ∈ Γ' → τ ∈ Γ
rename-var ρ a = ρ a
idr : ∀ {Γ} → rctx Γ Γ
idr x = x
-- weakening with renaming
p∙ : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) Γ'
p∙ ρ = λ x → iS (ρ x)
p : ∀ {Γ τ} → rctx (τ :: Γ) Γ
p = p∙ idr
_∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C
ρ1 ∙rr ρ2 = ρ1 o ρ2
-- free stuff
rename-var-ident : ∀ {Γ τ} → (x : τ ∈ Γ) → rename-var idr x == x
rename-var-ident _ = Refl
rename-var-∙ : ∀ {A B C τ} → (r1 : rctx A B) (r2 : rctx B C) (x : τ ∈ C)
→ rename-var r1 (rename-var r2 x) == rename-var (r1 ∙rr r2) x
rename-var-∙ _ _ _ = Refl
∙rr-assoc : ∀ {A B C D} → (r1 : rctx A B) (r2 : rctx B C) (r3 : rctx C D) → _==_ {_} {rctx A D} (r1 ∙rr (r2 ∙rr r3)) ((r1 ∙rr r2) ∙rr r3)
∙rr-assoc r1 r2 r3 = Refl
r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
r-extend ρ i0 = i0
r-extend ρ (iS x) = iS (ρ x)
ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ
ren unit ρ = unit
ren 0C ρ = 0C
ren 1C ρ = 1C
ren (plusC e e₁) ρ = plusC (ren e ρ) (ren e₁ ρ)
ren (var x) ρ = var (ρ x)
ren z ρ = z
ren (suc e) ρ = suc (ren e ρ)
ren (rec e e₁ e₂) ρ = rec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend ρ)))
ren (lam e) ρ = lam (ren e (r-extend ρ))
ren (app e e₁) ρ = app (ren e ρ) (ren e₁ ρ)
ren (prod e1 e2) ρ = prod (ren e1 ρ) (ren e2 ρ)
ren (l-proj e) ρ = l-proj (ren e ρ)
ren (r-proj e) ρ = r-proj (ren e ρ)
ren nil ρ = nil
ren (x ::c xs) ρ = ren x ρ ::c ren xs ρ
ren true ρ = true
ren false ρ = false
ren (listrec e e₁ e₂) ρ = listrec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend (r-extend ρ))))
extend-ren-comp-lemma : ∀ {Γ Γ' Γ'' τ τ'} → (x : τ ∈ τ' :: Γ'') (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'')
→ Id {_} {_} ((r-extend ρ1 ∙rr r-extend ρ2) x) (r-extend (ρ1 ∙rr ρ2) x)
extend-ren-comp-lemma i0 ρ1 ρ2 = Refl
extend-ren-comp-lemma (iS x) ρ1 ρ2 = Refl
extend-ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'')
→ Id {_} {rctx (τ :: Γ) (τ :: Γ'')} (r-extend ρ1 ∙rr r-extend ρ2) (r-extend (ρ1 ∙rr ρ2))
extend-ren-comp ρ1 ρ2 = λ=i (λ τ → λ= (λ x → extend-ren-comp-lemma x ρ1 ρ2))
ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (ren (ren e ρ2) ρ1) == (ren e (ρ1 ∙rr ρ2))
ren-comp ρ1 ρ2 unit = Refl
ren-comp ρ1 ρ2 0C = Refl
ren-comp ρ1 ρ2 1C = Refl
ren-comp ρ1 ρ2 (plusC e e₁) = ap2 plusC (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (var x) = ap var (rename-var-∙ ρ1 ρ2 x)
ren-comp ρ1 ρ2 z = Refl
ren-comp ρ1 ρ2 (suc e) = ap suc (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (rec e e₁ e₂) = ap3 rec (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
(ap (ren e₂) (ap r-extend (extend-ren-comp ρ1 ρ2) ∘
extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)) e₂)
ren-comp ρ1 ρ2 (lam e) = ap lam ((ap (ren e) (extend-ren-comp ρ1 ρ2)) ∘ ren-comp (r-extend ρ1) (r-extend ρ2) e)
ren-comp ρ1 ρ2 (app e e₁) = ap2 app (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (prod e e₁) = ap2 prod (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (l-proj e) = ap l-proj (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (r-proj e) = ap r-proj (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 nil = Refl
ren-comp ρ1 ρ2 (e ::c e₁) = ap2 _::c_ (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (listrec e e₁ e₂) = ap3 listrec (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
(ap (ren e₂) (ap r-extend (ap r-extend (extend-ren-comp ρ1 ρ2)) ∘
(ap r-extend (extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
extend-ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)))) ∘
ren-comp (r-extend (r-extend (r-extend ρ1)))
(r-extend (r-extend (r-extend ρ2))) e₂)
ren-comp ρ1 ρ2 true = Refl
ren-comp ρ1 ρ2 false = Refl
-- weakening a context
wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2
wkn e = ren e iS
sctx : Ctx → Ctx → Set
sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ
--lem2 (addvar)
s-extend : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ')
s-extend Θ i0 = var i0
s-extend Θ (iS x) = wkn (Θ x)
ids : ∀ {Γ} → sctx Γ Γ
ids x = var x
-- weakening with substitution
q∙ : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) Γ'
q∙ Θ = λ x → wkn (Θ x)
lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ')
lem3' Θ e i0 = e
lem3' Θ e (iS i) = Θ i
--lem3
q : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ)
q e = lem3' ids e
-- subst-var
svar : ∀ {Γ1 Γ2 τ} → sctx Γ1 Γ2 → τ ∈ Γ2 → Γ1 |- τ
svar Θ i = q (Θ i) i0
lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ'))
lem4' Θ a b = lem3' (lem3' Θ b) a
lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ))
lem4 e1 e2 = lem4' ids e1 e2
lem5' : ∀ {Γ Γ' τ1 τ2 τ3} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ')))
lem5' Θ a b c = lem3' (lem3' (lem3' Θ c) b) a
lem5 : ∀ {Γ τ1 τ2 τ3} → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ)))
lem5 e1 e2 e3 = lem5' ids e1 e2 e3
subst : ∀ {Γ Γ' τ} → Γ' |- τ → sctx Γ Γ' → Γ |- τ
subst unit Θ = unit
subst 0C Θ = 0C
subst 1C Θ = 1C
subst (plusC e e₁) Θ = plusC (subst e Θ) (subst e₁ Θ)
subst (var x) Θ = Θ x
subst z Θ = z
subst (suc e) Θ = suc (subst e Θ)
subst (rec e e₁ e₂) Θ = rec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend Θ)))
subst (lam e) Θ = lam (subst e (s-extend Θ))
subst (app e e₁) Θ = app (subst e Θ) (subst e₁ Θ)
subst (prod e1 e2) Θ = prod (subst e1 Θ) (subst e2 Θ)
subst (l-proj e) Θ = l-proj (subst e Θ)
subst (r-proj e) Θ = r-proj (subst e Θ)
subst nil Θ = nil
subst (x ::c xs) Θ = subst x Θ ::c subst xs Θ
subst true Θ = true
subst false Θ = false
subst (listrec e e₁ e₂) Θ = listrec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend (s-extend Θ))))
subst1 : ∀ {Γ τ τ1} → Γ |- τ1 → (τ1 :: Γ) |- τ → Γ |- τ
subst1 e e' = subst e' (q e)
_rs_ : ∀ {A B C} → rctx A B → sctx B C → sctx A C
_rs_ ρ Θ x = ren (subst (var x) Θ) ρ
_ss_ : ∀ {A B C} → sctx A B → sctx B C → sctx A C
_ss_ Θ1 Θ2 x = subst (subst (var x) Θ2) Θ1
_sr_ : ∀ {A B C} → sctx A B → rctx B C → sctx A C
_sr_ Θ ρ x = subst (ren (var x) ρ) Θ
--free stuff
svar-rs : ∀ {A B C τ} (ρ : rctx A B) (Θ : sctx B C) (x : τ ∈ C)
→ svar (ρ rs Θ) x == ren (svar Θ x) ρ
svar-rs = λ ρ Θ x → Refl
svar-ss : ∀ {A B C τ} (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ C)
→ svar (Θ1 ss Θ2) x == subst (svar Θ2 x) Θ1
svar-ss = λ Θ1 Θ2 x → Refl
svar-sr : ∀ {A B C τ} (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ C)
→ svar Θ (rename-var ρ x) == svar (Θ sr ρ) x
svar-sr = λ Θ ρ x → Refl
svar-id : ∀ {Γ τ} → (x : τ ∈ Γ) → var x == svar ids x
svar-id = λ x → Refl
rsr-assoc : ∀ {A B C D} → (ρ1 : rctx A B) (Θ : sctx B C) (ρ2 : rctx C D)
→ Id {_} {sctx A D} ((ρ1 rs Θ) sr ρ2) (ρ1 rs (Θ sr ρ2))
rsr-assoc = λ ρ1 Θ ρ2 → Refl
extend-id-once-lemma : ∀ {Γ τ τ'} → (x : τ ∈ τ' :: Γ) → _==_ {_} {τ' :: Γ |- τ}
(ids {τ' :: Γ} {τ} x) (s-extend {Γ} {Γ} {τ'} (ids {Γ}) {τ} x)
extend-id-once-lemma i0 = Refl
extend-id-once-lemma (iS x) = Refl
extend-id-once : ∀ {Γ τ} → Id {_} {sctx (τ :: Γ) (τ :: Γ)} (ids {τ :: Γ}) (s-extend ids)
extend-id-once = λ=i (λ τ → λ= (λ x → extend-id-once-lemma x))
extend-id-twice : ∀ {Γ τ1 τ2} → Id {_} {sctx (τ1 :: τ2 :: Γ) (τ1 :: τ2 :: Γ)} (ids {τ1 :: τ2 :: Γ}) (s-extend (s-extend ids))
extend-id-twice = ap s-extend extend-id-once ∘ extend-id-once
subst-id : ∀ {Γ τ} (e : Γ |- τ) → e == subst e ids
subst-id unit = Refl
subst-id 0C = Refl
subst-id 1C = Refl
subst-id (plusC e e₁) = ap2 plusC (subst-id e) (subst-id e₁)
subst-id (var x) = svar-id x
subst-id z = Refl
subst-id (suc e) = ap suc (subst-id e)
subst-id (rec e e₁ e₂) = ap3 rec (subst-id e) (subst-id e₁) (ap (subst e₂) extend-id-twice ∘ subst-id e₂)
subst-id (lam e) = ap lam (ap (subst e) extend-id-once ∘ subst-id e)
subst-id (app e e₁) = ap2 app (subst-id e) (subst-id e₁)
subst-id (prod e e₁) = ap2 prod (subst-id e) (subst-id e₁)
subst-id (l-proj e) = ap l-proj (subst-id e)
subst-id (r-proj e) = ap r-proj (subst-id e)
subst-id nil = Refl
subst-id (e ::c e₁) = ap2 _::c_ (subst-id e) (subst-id e₁)
subst-id true = Refl
subst-id false = Refl
subst-id (listrec e e₁ e₂) = ap3 listrec (subst-id e) (subst-id e₁) (ap (subst e₂) (ap s-extend (ap s-extend extend-id-once) ∘ extend-id-twice) ∘ subst-id e₂)
extend-rs-once-lemma : ∀ {A B C τ τ'} → (x : τ ∈ τ' :: B) (ρ : rctx C A) (Θ : sctx A B) → _==_ {_} {τ' :: C |- τ}
(_rs_ {τ' :: C} {τ' :: A} {τ' :: B} (r-extend {C} {A} {τ'} ρ)
(s-extend {A} {B} {τ'} Θ) {τ} x)
(s-extend {C} {B} {τ'} (_rs_ {C} {A} {B} ρ Θ) {τ} x)
extend-rs-once-lemma i0 ρ Θ = Refl
extend-rs-once-lemma (iS x) ρ Θ = ! (ren-comp iS ρ (Θ x)) ∘ ren-comp (r-extend ρ) iS (Θ x)
extend-rs-once : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: C) (τ :: B)} (r-extend ρ rs s-extend Θ) (s-extend (ρ rs Θ))
extend-rs-once ρ Θ = λ=i (λ τ → λ= (λ x → extend-rs-once-lemma x ρ Θ))
extend-rs-twice : ∀ {A B C τ τ'} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: τ' :: C) (τ :: τ' :: B)} ((r-extend (r-extend ρ)) rs (s-extend (s-extend Θ))) ((s-extend (s-extend (ρ rs Θ))))
extend-rs-twice ρ Θ = ap s-extend (extend-rs-once ρ Θ) ∘ extend-rs-once (r-extend ρ) (s-extend Θ)
subst-rs : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ)
→ ren (subst e Θ) ρ == subst e (ρ rs Θ)
subst-rs ρ Θ unit = Refl
subst-rs ρ Θ 0C = Refl
subst-rs ρ Θ 1C = Refl
subst-rs ρ Θ (plusC e e₁) = ap2 plusC (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (var x) = svar-rs ρ Θ x
subst-rs ρ Θ z = Refl
subst-rs ρ Θ (suc e) = ap suc (subst-rs ρ Θ e)
subst-rs ρ Θ (rec e e₁ e₂) = ap3 rec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
(ap (subst e₂) (extend-rs-twice ρ Θ) ∘
subst-rs (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂)
subst-rs ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ subst-rs (r-extend ρ) (s-extend Θ) e)
subst-rs ρ Θ (app e e₁) = ap2 app (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (prod e e₁) = ap2 prod (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (l-proj e) = ap l-proj (subst-rs ρ Θ e)
subst-rs ρ Θ (r-proj e) = ap r-proj (subst-rs ρ Θ e)
subst-rs ρ Θ nil = Refl
subst-rs ρ Θ (e ::c e₁) = ap2 _::c_ (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ true = Refl
subst-rs ρ Θ false = Refl
subst-rs ρ Θ (listrec e e₁ e₂) = ap3 listrec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘
extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘
subst-rs (r-extend (r-extend (r-extend ρ))) (s-extend (s-extend (s-extend Θ))) e₂)
rs-comp : ∀ {Γ Γ' Γ'' τ} → (ρ : rctx Γ Γ') → (Θ : sctx Γ' Γ'') → (e : Γ'' |- τ)
→ (ren (subst e Θ) ρ) == subst e (ρ rs Θ)
rs-comp ρ Θ unit = Refl
rs-comp ρ Θ 0C = Refl
rs-comp ρ Θ 1C = Refl
rs-comp ρ Θ (plusC e e₁) = ap2 plusC (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (var x) = svar-rs ρ Θ x
rs-comp ρ Θ z = Refl
rs-comp ρ Θ (suc e) = ap suc (rs-comp ρ Θ e)
rs-comp ρ Θ (rec e e₁ e₂) = ap3 rec (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
(ap (subst e₂) (extend-rs-twice ρ Θ) ∘ rs-comp (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂)
rs-comp ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ rs-comp (r-extend ρ) (s-extend Θ) e)
rs-comp ρ Θ (app e e₁) = ap2 app (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (prod e e₁) = ap2 prod (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (l-proj e) = ap l-proj (rs-comp ρ Θ e)
rs-comp ρ Θ (r-proj e) = ap r-proj (rs-comp ρ Θ e)
rs-comp ρ Θ nil = Refl
rs-comp ρ Θ (e ::c e₁) = ap2 _::c_ (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (listrec e e₁ e₂) = ap3 listrec (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘
extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘
rs-comp (r-extend (r-extend (r-extend ρ)))
(s-extend (s-extend (s-extend Θ))) e₂)
rs-comp ρ Θ true = Refl
rs-comp ρ Θ false = Refl
extend-sr-once-lemma : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_sr_ Θ ρ) x) (_sr_ (s-extend Θ) (r-extend ρ) x)
extend-sr-once-lemma Θ ρ i0 = Refl
extend-sr-once-lemma Θ ρ (iS x) = Refl
extend-sr-once : ∀ {A B C τ} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ :: A) (τ :: C)} (s-extend Θ sr r-extend ρ) (s-extend (Θ sr ρ))
extend-sr-once Θ ρ = λ=i (λ τ → λ= (λ x → ! (extend-sr-once-lemma Θ ρ x)))
extend-sr-twice : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ' :: τ :: A) (τ' :: τ :: C)}
(s-extend (s-extend Θ) sr r-extend (r-extend ρ)) (s-extend (s-extend (Θ sr ρ)))
extend-sr-twice Θ ρ = ap s-extend (extend-sr-once Θ ρ) ∘ extend-sr-once (s-extend Θ) (r-extend ρ)
sr-comp : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (subst (ren e ρ) Θ) == subst e (Θ sr ρ)
sr-comp Θ ρ unit = Refl
sr-comp Θ ρ 0C = Refl
sr-comp Θ ρ 1C = Refl
sr-comp Θ ρ (plusC e e₁) = ap2 plusC (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (var x) = svar-sr Θ ρ x
sr-comp Θ ρ z = Refl
sr-comp Θ ρ (suc e) = ap suc (sr-comp Θ ρ e)
sr-comp Θ ρ (rec e e₁ e₂) = ap3 rec (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
(ap (subst e₂) (ap s-extend (extend-sr-once Θ ρ) ∘
extend-sr-once (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend Θ)) (r-extend (r-extend ρ)) e₂)
sr-comp Θ ρ (lam e) = ap lam (ap (subst e) (extend-sr-once Θ ρ) ∘ sr-comp (s-extend Θ) (r-extend ρ) e)
sr-comp Θ ρ (app e e₁) = ap2 app (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (prod e e₁) = ap2 prod (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (l-proj e) = ap l-proj (sr-comp Θ ρ e)
sr-comp Θ ρ (r-proj e) = ap r-proj (sr-comp Θ ρ e)
sr-comp Θ ρ nil = Refl
sr-comp Θ ρ (e ::c e₁) = ap2 _::c_ (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (listrec e e₁ e₂) = ap3 listrec (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-sr-once Θ ρ)) ∘
extend-sr-twice (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend (s-extend Θ)))
(r-extend (r-extend (r-extend ρ))) e₂)
sr-comp Θ ρ true = Refl
sr-comp Θ ρ false = Refl
extend-ss-once-lemma : ∀ {A B C τ τ'} → (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_ss_ Θ1 Θ2) x) (_ss_ (s-extend Θ1) (s-extend Θ2) x)
extend-ss-once-lemma Θ1 Θ2 i0 = Refl
extend-ss-once-lemma Θ1 Θ2 (iS x) = ! (sr-comp (s-extend Θ1) iS (Θ2 x)) ∘ rs-comp iS Θ1 (Θ2 x)
extend-ss-once : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C)
→ _==_ {_} {sctx (τ :: A) (τ :: C)} (s-extend (Θ1 ss Θ2))
((s-extend Θ1) ss
(s-extend Θ2))
extend-ss-once Θ1 Θ2 = λ=i (λ τ → λ= (λ x → extend-ss-once-lemma Θ1 Θ2 x))
subst-ss : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ)
→ subst e (Θ1 ss Θ2) == subst (subst e Θ2) Θ1
subst-ss Θ1 Θ2 unit = Refl
subst-ss Θ1 Θ2 0C = Refl
subst-ss Θ1 Θ2 1C = Refl
subst-ss Θ1 Θ2 (plusC e e₁) = ap2 plusC (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (var x) = svar-ss Θ1 Θ2 x
subst-ss Θ1 Θ2 z = Refl
subst-ss Θ1 Θ2 (suc e) = ap suc (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (rec e e₁ e₂) = ap3 rec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
(subst-ss (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) e₂ ∘
ap (subst e₂) (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2)))
subst-ss Θ1 Θ2 (lam e) = ap lam (subst-ss (s-extend Θ1) (s-extend Θ2) e ∘ ap (subst e) (extend-ss-once Θ1 Θ2))
subst-ss Θ1 Θ2 (app e e₁) = ap2 app (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (prod e e₁) = ap2 prod (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (l-proj e) = ap l-proj (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (r-proj e) = ap r-proj (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 nil = Refl
subst-ss Θ1 Θ2 (e ::c e₁) = ap2 _::c_ (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 true = Refl
subst-ss Θ1 Θ2 false = Refl
subst-ss Θ1 Θ2 (listrec e e₁ e₂) = ap3 listrec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
(subst-ss (s-extend (s-extend (s-extend Θ1))) (s-extend (s-extend (s-extend Θ2))) e₂ ∘
ap (subst e₂) (extend-ss-once (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) ∘
ap s-extend (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2))))
throw : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ'
throw Θ x = Θ (iS x)
fuse1 : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ Γ') → (q v ss q∙ Θ) x == Θ x
fuse1 v Θ x = subst (ren (Θ x) iS) (q v) =⟨ sr-comp (q v) iS (Θ x) ⟩
subst (Θ x) (q v sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
subst-compose-lemma-lemma : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ τ' :: Γ')
→ _==_ {_} {Γ |- τ} (_ss_ (q v) (s-extend Θ) x) (lem3' Θ v x)
subst-compose-lemma-lemma v Θ i0 = Refl
subst-compose-lemma-lemma v Θ (iS x) = fuse1 v Θ x
subst-compose-lemma : ∀ {Γ Γ' τ} (v : Γ |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ :: Γ')} ((q v) ss (s-extend Θ)) (lem3' Θ v)
subst-compose-lemma v Θ = λ=i (λ τ → λ= (λ x → subst-compose-lemma-lemma v Θ x))
subst-compose : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) )
→ subst (subst e (s-extend Θ)) (q v) == subst e (lem3' Θ v)
subst-compose Θ v e = ap (subst e) (subst-compose-lemma v Θ) ∘ (! (subst-ss (q v) (s-extend Θ) e))
fuse2 : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: Γ')
→ (lem4 v1 v2 ss throw (s-extend (s-extend Θ))) x == (lem3' Θ v2) x
fuse2 v1 v2 Θ x = subst (ren (s-extend Θ x) iS) (lem4 v1 v2) =⟨ sr-comp (lem4 v1 v2) iS (s-extend Θ x) ⟩
subst (s-extend Θ x) (lem4 v1 v2 sr iS) =⟨ Refl ⟩
subst (s-extend Θ x) (lem3' ids v2) =⟨ subst-compose-lemma-lemma v2 Θ x ⟩
(lem3' Θ v2 x ∎)
subst-compose2-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((lem4 v1 v2 ss s-extend (s-extend Θ)) x) (lem4' Θ v1 v2 x)
subst-compose2-lemma-lemma v1 v2 e1 Θ i0 = Refl
subst-compose2-lemma-lemma v1 v2 e1 Θ (iS x) = fuse2 v1 v2 Θ x
subst-compose2-lemma : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (lem4 v1 v2 ss s-extend (s-extend Θ)) (lem4' Θ v1 v2)
subst-compose2-lemma v1 v2 e1 Θ = λ=i (λ τ → λ= (λ x → subst-compose2-lemma-lemma v1 v2 e1 Θ x))
fuse3 : ∀ {Γ Γ' τ1 τ2 τ'} (Θ : sctx Γ Γ') (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) (x : τ' ∈ τ2 :: Γ')
→ subst (lem3' ids v2 x) Θ == lem3' Θ (subst v2 Θ) x
fuse3 Θ v1 v2 i0 = Refl
fuse3 Θ v1 v2 (iS x) = Refl
subst-compose3-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((Θ ss lem4 v1 v2) x) (lem4' Θ (subst v1 Θ) (subst v2 Θ) x)
subst-compose3-lemma-lemma Θ e1 v1 v2 i0 = Refl
subst-compose3-lemma-lemma Θ e1 v1 v2 (iS x) = fuse3 Θ v1 v2 x
subst-compose3-lemma : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (Θ ss lem4 v1 v2) (lem4' Θ (subst v1 Θ) (subst v2 Θ))
subst-compose3-lemma Θ e1 v1 v2 = λ=i (λ τ → λ= (λ x → subst-compose3-lemma-lemma Θ e1 v1 v2 x))
subst-compose2 : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2)
→ subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) == subst e1 (lem4' Θ v1 v2)
subst-compose2 Θ e1 v1 v2 = ap (subst e1) (subst-compose2-lemma v1 v2 e1 Θ) ∘
! (subst-ss (lem4 v1 v2) (s-extend (s-extend Θ)) e1)
subst-compose3 : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ subst (subst e1 (lem4 v1 v2)) Θ == subst e1 (lem4' Θ (subst v1 Θ) (subst v2 Θ))
subst-compose3 Θ e1 v1 v2 = ap (subst e1) (subst-compose3-lemma Θ e1 v1 v2) ∘ ! (subst-ss Θ (lem4 v1 v2) e1)
subst-compose4 : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- τ) (e2 : (nat :: (τ :: Γ')) |- τ)
→ subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) == subst e2 (lem4' Θ v' r)
subst-compose4 Θ v' r e2 = subst-compose2 Θ e2 v' r
fuse4-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (Θ : sctx Γ Γ') (x : τ ∈ Γ')
→ (lem3' (lem3' ids v3) v2 ss q∙ (q∙ Θ)) x == Θ x
fuse4-lemma v1 v2 v3 Θ x = subst (ren (wkn (Θ x)) iS) (lem3' (q v3) v2) =⟨ sr-comp (lem3' (q v3) v2) iS (wkn (Θ x)) ⟩
subst (wkn (Θ x)) (lem3' (q v3) v2 sr iS) =⟨ Refl ⟩
subst (ren (Θ x) iS) (lem3' (q v3) v2 sr iS) =⟨ sr-comp (lem3' (q v3) v2 sr iS) iS (Θ x) ⟩
subst (Θ x) ((lem3' (q v3) v2 sr iS) sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
fuse4 : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: τ3 :: Γ')
→ subst (s-extend (s-extend Θ) x) (lem3' (lem3' ids v3) v2) == lem3' (lem3' Θ v3) v2 x
fuse4 v1 v2 v3 Θ i0 = Refl
fuse4 v1 v2 v3 Θ (iS i0) = Refl
fuse4 v1 v2 v3 Θ (iS (iS x)) = subst (wkn (wkn (Θ x))) (lem3' (lem3' ids v3) v2) =⟨ subst-ss (lem3' (lem3' ids v3) v2) (q∙ (q∙ Θ)) (var x) ⟩
subst (var x) (lem3' (lem3' ids v3) v2 ss q∙ (q∙ Θ)) =⟨ fuse4-lemma v1 v2 v3 Θ x ⟩
subst (var x) Θ =⟨ Refl ⟩
(Θ x ∎)
subst-compose5-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (e1 : τ1 :: τ2 :: τ3 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: τ3 :: Γ')
→ _==_ {_} {_} ((lem5 v1 v2 v3 ss s-extend (s-extend (s-extend Θ))) x) (lem5' Θ v1 v2 v3 x)
subst-compose5-lemma-lemma v1 v2 v3 e Θ i0 = Refl
subst-compose5-lemma-lemma v1 v2 v3 e Θ (iS x) = (lem5 v1 v2 v3 ss s-extend (s-extend (s-extend Θ))) (iS x) =⟨ sr-comp (lem5 v1 v2 v3) iS (s-extend (s-extend Θ) x) ⟩
subst (s-extend (s-extend Θ) x) (lem3' (lem3' ids v3) v2) =⟨ fuse4 v1 v2 v3 Θ x ⟩
(lem3' (lem3' Θ v3) v2 x ∎)
subst-compose5-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (e : τ1 :: τ2 :: τ3 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: τ3 :: Γ')} (lem5 v1 v2 v3 ss (s-extend (s-extend (s-extend Θ)))) (lem5' Θ v1 v2 v3)
subst-compose5-lemma v1 v2 v3 e Θ = λ=i (λ τ → λ= (λ x → subst-compose5-lemma-lemma v1 v2 v3 e Θ x))
subst-compose5 : ∀ {Γ Γ' τ τ1 τ2 τ3} (Θ : sctx Γ Γ') (e : (τ1 :: (τ2 :: (τ3 :: Γ'))) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3)
→ subst (subst e (s-extend (s-extend (s-extend (Θ))))) (lem5 v1 v2 v3) == subst e (lem5' Θ v1 v2 v3)
subst-compose5 Θ e v1 v2 v3 = ap (subst e) (subst-compose5-lemma v1 v2 v3 e Θ) ∘
! (subst-ss (lem5 v1 v2 v3) (s-extend (s-extend (s-extend Θ))) e)
-------
-- define 'stepping' as a datatype (fig. 1 of proof)
data _≤s_ : ∀ {Γ T} → Γ |- T → Γ |- T → Set where
refl-s : ∀ {Γ T}
→ {e : Γ |- T}
→ e ≤s e
trans-s : ∀ {Γ T}
→ {e e' e'' : Γ |- T}
→ e ≤s e' → e' ≤s e''
→ e ≤s e''
plus-s : ∀ {Γ}
→ {e1 e2 n1 n2 : Γ |- C}
→ e1 ≤s n1 → e2 ≤s n2
→ (plusC e1 e2) ≤s (plusC n1 n2)
cong-refl : ∀ {Γ τ} {e e' : Γ |- τ} → e == e' → e ≤s e'
+-unit-l : ∀ {Γ} {e : Γ |- C} → (plusC 0C e) ≤s e
+-unit-l' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC 0C e)
+-unit-r : ∀ {Γ} {e : Γ |- C} → (plusC e 0C) ≤s e
+-unit-r' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC e 0C)
+-1-r : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC e 1C)
+-assoc : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC e1 (plusC e2 e3)) ≤s (plusC (plusC e1 e2) e3)
+-assoc' : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC e1 (plusC e2 e3)) ≤s (plusC (plusC e1 e2) e3)
refl-+ : ∀ {Γ} {e0 e1 : Γ |- C} → (plusC e0 e1) ≤s (plusC e1 e0)
cong-+ : ∀ {Γ} {e0 e1 e0' e1' : Γ |- C} → e0 ≤s e0' → e1 ≤s e1' → (plusC e0 e1) ≤s (plusC e0' e1')
cong-lproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (l-proj e) ≤s (l-proj e')
cong-rproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (r-proj e) ≤s (r-proj e')
cong-app : ∀ {Γ τ τ'} {e e' : Γ |- (τ ->c τ')} {e1 : Γ |- τ} → e ≤s e' → (app e e1) ≤s (app e' e1)
cong-rec : ∀ {Γ τ} {e e' : Γ |- nat} {e0 : Γ |- τ} {e1 : (nat :: (τ :: Γ)) |- τ}
→ e ≤s e'
→ rec e e0 e1 ≤s rec e' e0 e1
cong-listrec : ∀ {Γ τ τ'} {e e' : Γ |- list τ} {e0 : Γ |- τ'} {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ e ≤s e'
→ listrec e e0 e1 ≤s listrec e' e0 e1
lam-s : ∀ {Γ T T'}
→ {e : (T :: Γ) |- T'}
→ {e2 : Γ |- T}
→ subst e (q e2) ≤s app (lam e) e2
l-proj-s : ∀ {Γ T1 T2}
→ {e1 : Γ |- T1} {e2 : Γ |- T2}
→ e1 ≤s (l-proj (prod e1 e2))
r-proj-s : ∀ {Γ T1 T2}
→ {e1 : Γ |- T1} → {e2 : Γ |- T2}
→ e2 ≤s (r-proj (prod e1 e2))
rec-steps-z : ∀ {Γ T}
→ {e0 : Γ |- T}
→ {e1 : (nat :: (T :: Γ)) |- T}
→ e0 ≤s (rec z e0 e1)
rec-steps-s : ∀ {Γ T}
→ {e : Γ |- nat}
→ {e0 : Γ |- T}
→ {e1 : (nat :: (T :: Γ)) |- T}
→ subst e1 (lem4 e (rec e e0 e1)) ≤s (rec (suc e) e0 e1)
listrec-steps-nil : ∀ {Γ τ τ'}
→ {e0 : Γ |- τ'}
→ {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ e0 ≤s (listrec nil e0 e1)
listrec-steps-cons : ∀ {Γ τ τ'}
→ {h : Γ |- τ} {t : Γ |- list τ}
→ {e0 : Γ |- τ'}
→ {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ subst e1 (lem5 h t (listrec t e0 e1)) ≤s (listrec (h ::c t) e0 e1)
_trans_ : ∀ {Γ T}
→ {e e' e'' : Γ |- T}
→ e ≤s e' → e' ≤s e''
→ e ≤s e''
_trans_ = trans-s
infixr 10 _trans_
| 48.342995
| 179
| 0.461111
|
2368e995ee5c5449d9308baeccda21314a82a308
| 316
|
agda
|
Agda
|
test/Succeed/Issue2686.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2686.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2686.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-08-13, issue #2686
-- Overloaded constructor where only one alternative is not abstract.
-- Not ambiguous, since abstract constructors are not in scope!
-- {-# OPTIONS -v tc.check.term:40 #-}
abstract
data A : Set where
c : A
data D : Set where
c : D
test = c
match : D → D
match c = c
| 17.555556
| 69
| 0.661392
|
df48ebfb6513c4a6460af1fa21e9e1c7eacff68b
| 3,724
|
agda
|
Agda
|
Example-03.agda
|
ashinkarov/agda-extractor
|
c8954c8acd8089ced82af9e05084fbbc7fedb36c
|
[
"0BSD"
] | 1
|
2021-01-11T14:52:59.000Z
|
2021-01-11T14:52:59.000Z
|
Example-03.agda
|
ashinkarov/agda-extractor
|
c8954c8acd8089ced82af9e05084fbbc7fedb36c
|
[
"0BSD"
] | null | null | null |
Example-03.agda
|
ashinkarov/agda-extractor
|
c8954c8acd8089ced82af9e05084fbbc7fedb36c
|
[
"0BSD"
] | null | null | null |
open import ExtractSac as ES using ()
open import Extract (ES.kompile-fun)
open import Data.Nat as N using (ℕ; zero; suc; _≤_; _≥_; _<_; s≤s; z≤n)
import Data.Nat.DivMod as N
open import Data.Nat.Properties as N
open import Data.List as L using (List; []; _∷_)
open import Data.Vec as V using (Vec; []; _∷_)
import Data.Vec.Properties as V
open import Data.Fin using (Fin; zero; suc; #_)
open import Data.Product as Prod using (Σ; _,_; curry; uncurry) renaming (_×_ to _⊗_)
open import Relation.Binary.PropositionalEquality
open import Reflection
open import Structures
open import Function
open import Array.Base
open import Array.Properties
open import APL2
open import Agda.Builtin.Float
v→a : ∀ {a}{X : Set a}{n} → Vec X n → Ar X 1 (n ∷ [])
v→a s = imap (λ iv → V.lookup s $ ix-lookup iv zero )
a→v : ∀ {a}{X : Set a}{s} → Ar X 1 (s ∷ []) → Vec X s
a→v (imap x) = V.tabulate λ i → x (i ∷ [])
-- blog←{⍺×⍵×1-⍵}
blog : ∀ {n s} → Ar Float n s → Ar Float n s → Ar Float n s
blog α ω = α ×ᵣ ω ×ᵣ 1.0 -ᵣ ω
test-blog = a→v $ blog (v→a $ 3.0 ∷ 4.0 ∷ []) (v→a $ 5.0 ∷ 6.0 ∷ [])
kblog = kompile blog [] []
test₃₆ : kblog ≡ ok _
test₃₆ = refl
-- backbias←{+/,⍵}
backbias : ∀ {n s} → Ar Float n s → Scal Float
backbias ω = --(▾_ ∘₂ _+ᵣ_) / , ω
_+ᵣ′_ / , ω
where
--_+ᵣ′_ : Float → Float → Float
--a +ᵣ′ b = ▾ (a +ᵣ b)
_+ᵣ′_ = primFloatPlus
kbackbias = kompile backbias (quote prod ∷ []) (quote prod ∷ quote off→idx ∷ quote reduce-custom.reduce-1d ∷ [])
--test₃₇ : kbackbias ≡ ok _
--test₃₇ = refl
-- logistic←{÷1+*-⍵}
logistic : ∀ {n s} → Ar Float n s → Ar Float n s
logistic ω = ÷ᵣ 1.0 +ᵣ *ᵣ -ᵣ ω
klogistic = kompile logistic [] []
test₃₈ : klogistic ≡ ok _
test₃₈ = refl
-- meansqerr←{÷∘2+/,(⍺-⍵)*2}
meansqerr : ∀ {n s} → Ar Float n s → Ar Float n s → Scal Float
meansqerr α ω = _÷ᵣ 2.0 $ _+ᵣ′_ / , (α +ᵣ ω) ×ᵣ (α -ᵣ ω)
where
_+ᵣ′_ = primFloatPlus
kmeansqerr = kompile meansqerr (quote prod ∷ []) (quote prod ∷ quote off→idx ∷ quote reduce-custom.reduce-1d ∷ [])
test₃₉ : klogistic ≡ ok _
test₃₉ = refl
-- backavgpool←{2⌿2/⍵÷4}⍤2
backavgpool : ∀ {s} → Ar Float 2 s → Ar Float 2 $ ▾ (2 × s)
backavgpool {s = _ ∷ _ ∷ []} ω = 2 /ᵣ′ 2 ⌿ᵣ ω ×ᵣ 4.0
where
infixr 20 _/ᵣ′_
_/ᵣ′_ = _/ᵣ_ {s = _ ∷ []}
kbackavgpool = kompile backavgpool [] []
test₄₀ : kbackavgpool ≡ ok _
test₄₀ = refl
-- Something that could go in Stdlib.
≡⇒≤ : ∀ {a b} → a ≡ b → a N.≤ b
≡⇒≤ refl = ≤-refl
-- This should be perfectly generaliseable --- instead of 2
-- we can use any m>0
a<b⇒k<2⇒a*2+k<b*2 : ∀ {a b k} → a N.< b → k N.< 2 → a N.* 2 N.+ k N.< b N.* 2
a<b⇒k<2⇒a*2+k<b*2 {a} {b} {zero} a<b k<2
rewrite (+-identityʳ (a N.* 2))
| (*-comm a 2)
| (*-comm b 2) = *-monoʳ-< 1 a<b
a<b⇒k<2⇒a*2+k<b*2 {a} {b} {suc zero} a<b k<2 = ≤-trans (N.s≤s (≡⇒≤ (+-comm _ 1)))
(*-monoˡ-≤ 2 a<b)
a<b⇒k<2⇒a*2+k<b*2 {a} {b} {suc (suc k)} a<b (N.s≤s (N.s≤s ()))
A<B⇒K<2⇒A*2+K<B*2 : ∀ {n s}{a b k : Ar ℕ n s} → a <a b → k <a (cst 2) → ((a × 2) + k) <a (b × 2)
A<B⇒K<2⇒A*2+K<B*2 {a = imap a} {imap b} {imap k} a<b k<2 = λ iv → a<b⇒k<2⇒a*2+k<b*2 (a<b iv) (k<2 iv)
avgpool : ∀ {s}
→ Ar Float 2 $ ▾ (s × 2)
→ Ar Float 2 s
avgpool {s} (imap p) = imap body
where
body : _ → _
body iv = ▾ (_÷ᵣ 4.0 $ _+ᵣ′_ / , f ̈ ι [2,2])
where
[2,2] = cst {s = 2 ∷ []} 2
f : _ → _
f (i , pf) = let ix , ix<s = ix→a iv in
p $ a→ix ((ix × 2) + i) (s × 2) $ A<B⇒K<2⇒A*2+K<B*2 ix<s pf
_+ᵣ′_ = primFloatPlus
kavgpool = kompile avgpool [] []
open import ReflHelper
fin-id : ∀ {n} → Fin n → Fin n
fin-id x = x
| 27.382353
| 114
| 0.523899
|
cb00f04e827e78a43534a84b9f16a48412cbf8fa
| 734
|
agda
|
Agda
|
agda/PLRTree/Complete/Correctness/Base.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/PLRTree/Complete/Correctness/Base.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/PLRTree/Complete/Correctness/Base.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
module PLRTree.Complete.Correctness.Base {A : Set} where
open import BTree.Complete.Base {A}
open import BTree.Complete.Alternative.Correctness {A} renaming (lemma-complete'-complete to lemma-complete''-complete)
open import Function using (_∘_)
open import PLRTree {A}
open import PLRTree.Complete {A} renaming (Complete to Complete' ; _⋗_ to _⋗'_ ; _⋘_ to _⋘'_ ; _⋙_ to _⋙'_)
open import PLRTree.Complete.Correctness.Alternative {A} renaming (lemma-complete'-complete to lemma-complete'-complete'')
open import PLRTree.Equality.Correctness {A}
lemma-complete'-complete : {t : PLRTree} → Complete' t → Complete (forget t)
lemma-complete'-complete = lemma-complete''-complete ∘ lemma-complete'-complete''
| 52.428571
| 122
| 0.731608
|
106bbf45d16dfafa4673b19f5eb8aefff1ec2dbd
| 3,491
|
agda
|
Agda
|
Numeral/Natural/Oper/Proofs/Multiplication.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Oper/Proofs/Multiplication.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Oper/Proofs/Multiplication.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Oper.Proofs.Multiplication where
open import Logic.Propositional
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Oper.Proofs.Order
open import Numeral.Natural.Relation
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Classical
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Operator
import Structure.Operator.Names as Names
open import Structure.Operator.Properties
open import Structure.Relator.Properties
open import Syntax.Transitivity
instance
[⋅][−₀]-distributivityᵣ : Distributivityᵣ(_⋅_)(_−₀_)
Distributivityᵣ.proof([⋅][−₀]-distributivityᵣ) {x}{y}{z} = p{x}{y}{z} where
p : ∀{x y z : ℕ} → ((x −₀ y) ⋅ z) ≡ (x ⋅ z) −₀ (y ⋅ z)
p {x} {y} {𝟎} = [≡]-intro
p {x} {y} {𝐒 z} with [≥]-or-[<] {x}{y}
... | [∨]-introₗ gt =
(x −₀ y) ⋅ 𝐒(z) 🝖[ _≡_ ]-[]
(x −₀ y) + ((x −₀ y) ⋅ z) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x −₀ y) (p {x}{y}{z}) ]
(x −₀ y) + ((x ⋅ z) −₀ (y ⋅ z)) 🝖[ _≡_ ]-[ [+][−₀]-almost-associativity {x −₀ y} ([≤]-with-[⋅]ᵣ {c = z} gt) ]-sym
((x −₀ y) + (x ⋅ z)) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ₗ(_−₀_)(y ⋅ z) (commutativity(_+_) {x −₀ y}{x ⋅ z}) ]
((x ⋅ z) + (x −₀ y)) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ₗ(_−₀_)(y ⋅ z) ([+][−₀]-almost-associativity {x ⋅ z} gt) ]-sym
(((x ⋅ z) + x) −₀ y) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ₗ(_−₀_)(y ⋅ z) (congruence₂ₗ(_−₀_)(y) (commutativity(_+_) {x ⋅ z}{x})) ]
((x + (x ⋅ z)) −₀ y) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ [−₀][−₀]-to-[−₀][+] {x + (x ⋅ z)}{y}{y ⋅ z} ]
(x + (x ⋅ z)) −₀ (y + (y ⋅ z)) 🝖[ _≡_ ]-[]
(x ⋅ 𝐒(z)) −₀ (y ⋅ 𝐒(z)) 🝖-end
... | [∨]-introᵣ lt =
(x −₀ y) ⋅ 𝐒(z) 🝖[ _≡_ ]-[ congruence₂ₗ(_⋅_)(𝐒(z)) ([↔]-to-[→] [−₀]-when-0 (sub₂(_<_)(_≤_) lt)) ]
𝟎 ⋅ 𝐒(z) 🝖[ _≡_ ]-[ absorberₗ(_⋅_)(𝟎) {𝐒(z)} ]
𝟎 🝖[ _≡_ ]-[ [↔]-to-[→] [−₀]-when-0 ([≤]-with-[+] ⦃ sub₂(_<_)(_≤_) lt ⦄ ⦃ [≤]-with-[⋅]ᵣ {c = z} (sub₂(_<_)(_≤_) lt) ⦄) ]-sym
(x + (x ⋅ z)) −₀ (y + (y ⋅ z)) 🝖-end
-- TODO: This is a specialized distributivity-equivalence-by-commutativity
instance
[⋅][−₀]-distributivityₗ : Distributivityₗ(_⋅_)(_−₀_)
Distributivityₗ.proof([⋅][−₀]-distributivityₗ) {x}{y}{z} = p{x}{y}{z} where
p : ∀{x y z : ℕ} → (x ⋅ (y −₀ z)) ≡ (x ⋅ y) −₀ (x ⋅ z)
p{x}{y}{z} =
x ⋅ (y −₀ z) 🝖[ _≡_ ]-[ commutativity(_⋅_) {x}{y −₀ z} ]
(y −₀ z) ⋅ x 🝖[ _≡_ ]-[ distributivityᵣ(_⋅_)(_−₀_) {y}{z}{x} ]
(y ⋅ x) −₀ (z ⋅ x) 🝖[ _≡_ ]-[ congruence₂(_−₀_) (commutativity(_⋅_) {y}{x}) (commutativity(_⋅_) {z}{x}) ]
(x ⋅ y) −₀ (x ⋅ z) 🝖-end
[⋅]-cancellationₗ : ∀{x} → ⦃ pos : Positive(x) ⦄ → (Names.CancellationOnₗ(_⋅_)(x))
[⋅]-cancellationₗ {𝐒 a}{b}{c} p with [<]-trichotomy {b}{c}
... | [∨]-introₗ ([∨]-introₗ lt) with () ← [<]-to-[≢] ([<]-with-[⋅]ₗ {a = a} lt) p
... | [∨]-introₗ ([∨]-introᵣ eq) = eq
... | [∨]-introᵣ gt with () ← [>]-to-[≢] ([<]-with-[⋅]ₗ {a = a} gt) p
[⋅]-cancellationᵣ : ∀{x} → ⦃ pos : Positive(x) ⦄ → (Names.CancellationOnᵣ(_⋅_)(x))
[⋅]-cancellationᵣ {𝐒 c}{a}{b} p with [<]-trichotomy {a}{b}
... | [∨]-introₗ ([∨]-introₗ lt) with () ← [<]-to-[≢] ([<]-with-[⋅]ᵣ {c = c} lt) p
... | [∨]-introₗ ([∨]-introᵣ eq) = eq
... | [∨]-introᵣ gt with () ← [>]-to-[≢] ([<]-with-[⋅]ᵣ {c = c} gt) p
| 54.546875
| 159
| 0.49069
|
dc9c96efe7a8b5d3a16232c6a5a6c8b0594dbf83
| 7,109
|
agda
|
Agda
|
src/Categories/Diagram/Pullback.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Pullback.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Pullback.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Diagram.Pullback {o ℓ e} (C : Category o ℓ e) where
open Category C
open HomReasoning
open import Level
open import Data.Product using (_,_; ∃)
open import Function using (flip; _$_) renaming (_∘_ to _●_)
open import Categories.Morphism C
open import Categories.Object.Product C
open import Categories.Diagram.Equalizer C
open import Categories.Morphism.Reasoning C as Square
renaming (glue to glue-square) hiding (id-unique)
private
variable
A B X Y Z : Obj
f g h h₁ h₂ i i₁ i₂ j : A ⇒ B
-- Pullback of two arrows with a common codomain
record Pullback (f : X ⇒ Z) (g : Y ⇒ Z) : Set (o ⊔ ℓ ⊔ e) where
field
{P} : Obj
p₁ : P ⇒ X
p₂ : P ⇒ Y
field
commute : f ∘ p₁ ≈ g ∘ p₂
universal : ∀ {h₁ : A ⇒ X} {h₂ : A ⇒ Y} → f ∘ h₁ ≈ g ∘ h₂ → A ⇒ P
unique : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} →
p₁ ∘ i ≈ h₁ → p₂ ∘ i ≈ h₂ →
i ≈ universal eq
p₁∘universal≈h₁ : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} →
p₁ ∘ universal eq ≈ h₁
p₂∘universal≈h₂ : ∀ {eq : f ∘ h₁ ≈ g ∘ h₂} →
p₂ ∘ universal eq ≈ h₂
unique′ : (eq eq′ : f ∘ h₁ ≈ g ∘ h₂) → universal eq ≈ universal eq′
unique′ eq eq′ = unique p₁∘universal≈h₁ p₂∘universal≈h₂
id-unique : id ≈ universal commute
id-unique = unique identityʳ identityʳ
unique-diagram : p₁ ∘ h ≈ p₁ ∘ i →
p₂ ∘ h ≈ p₂ ∘ i →
h ≈ i
unique-diagram {h = h} {i = i} eq₁ eq₂ = begin
h ≈⟨ unique eq₁ eq₂ ⟩
universal eq ≈˘⟨ unique refl refl ⟩
i ∎
where eq = extendʳ commute
swap : Pullback f g → Pullback g f
swap p = record
{ p₁ = p₂
; p₂ = p₁
; commute = ⟺ commute
; universal = universal ● ⟺
; unique = flip unique
; p₁∘universal≈h₁ = p₂∘universal≈h₂
; p₂∘universal≈h₂ = p₁∘universal≈h₁
}
where open Pullback p
glue : (p : Pullback f g) → Pullback h (Pullback.p₁ p) → Pullback (f ∘ h) g
glue {h = h} p q = record
{ p₁ = q.p₁
; p₂ = p.p₂ ∘ q.p₂
; commute = glue-square p.commute q.commute
; universal = λ eq → q.universal (⟺ (p.p₁∘universal≈h₁ {eq = sym-assoc ○ eq}))
; unique = λ {_ h₁ h₂ i} eq eq′ →
q.unique eq (p.unique (begin
p.p₁ ∘ q.p₂ ∘ i ≈˘⟨ extendʳ q.commute ⟩
h ∘ q.p₁ ∘ i ≈⟨ refl⟩∘⟨ eq ⟩
h ∘ h₁ ∎)
(sym-assoc ○ eq′))
; p₁∘universal≈h₁ = q.p₁∘universal≈h₁
; p₂∘universal≈h₂ = assoc ○ ∘-resp-≈ʳ q.p₂∘universal≈h₂ ○ p.p₂∘universal≈h₂
}
where module p = Pullback p
module q = Pullback q
unglue : (p : Pullback f g) → Pullback (f ∘ h) g → Pullback h (Pullback.p₁ p)
unglue {f = f} {g = g} {h = h} p q = record
{ p₁ = q.p₁
; p₂ = p₂′
; commute = ⟺ p.p₁∘universal≈h₁
; universal = λ {_ h₁ h₂} eq → q.universal $ begin
(f ∘ h) ∘ h₁ ≈⟨ pullʳ eq ⟩
f ∘ p.p₁ ∘ h₂ ≈⟨ extendʳ p.commute ⟩
g ∘ p.p₂ ∘ h₂ ∎
; unique = λ {_ h₁ h₂ i} eq eq′ → q.unique eq $ begin
q.p₂ ∘ i ≈⟨ pushˡ (⟺ p.p₂∘universal≈h₂) ⟩
p.p₂ ∘ p₂′ ∘ i ≈⟨ refl⟩∘⟨ eq′ ⟩
p.p₂ ∘ h₂ ∎
; p₁∘universal≈h₁ = q.p₁∘universal≈h₁
; p₂∘universal≈h₂ = λ {_ _ _ eq} →
p.unique-diagram ((pullˡ p.p₁∘universal≈h₁) ○ pullʳ q.p₁∘universal≈h₁ ○ eq)
(pullˡ p.p₂∘universal≈h₂ ○ q.p₂∘universal≈h₂)
}
where module p = Pullback p
module q = Pullback q
p₂′ = p.universal (sym-assoc ○ q.commute) -- used twice above
Product×Equalizer⇒Pullback :
(p : Product A B) → Equalizer (f ∘ Product.π₁ p) (g ∘ Product.π₂ p) →
Pullback f g
Product×Equalizer⇒Pullback {f = f} {g = g} p e = record
{ p₁ = π₁ ∘ arr
; p₂ = π₂ ∘ arr
; commute = sym-assoc ○ equality ○ assoc
; universal = λ {_ h₁ h₂} eq → equalize $ begin
(f ∘ π₁) ∘ ⟨ h₁ , h₂ ⟩ ≈⟨ pullʳ project₁ ⟩
f ∘ h₁ ≈⟨ eq ⟩
g ∘ h₂ ≈˘⟨ pullʳ project₂ ⟩
(g ∘ π₂) ∘ ⟨ h₁ , h₂ ⟩ ∎
; unique = λ eq eq′ → e.unique (p.unique (sym-assoc ○ eq) (sym-assoc ○ eq′))
; p₁∘universal≈h₁ = pullʳ (⟺ e.universal) ○ project₁
; p₂∘universal≈h₂ = pullʳ (⟺ e.universal) ○ project₂
}
where module p = Product p
module e = Equalizer e
open p
open e
Product×Pullback⇒Equalizer : (p : Product A B) → Pullback f g →
Equalizer (f ∘ Product.π₁ p) (g ∘ Product.π₂ p)
Product×Pullback⇒Equalizer {f = f} {g = g} p pu = record
{ arr = ⟨ p₁ , p₂ ⟩
; equality = begin
(f ∘ π₁) ∘ ⟨ p₁ , p₂ ⟩ ≈⟨ pullʳ project₁ ⟩
f ∘ p₁ ≈⟨ commute ⟩
g ∘ p₂ ≈˘⟨ pullʳ project₂ ⟩
(g ∘ π₂) ∘ ⟨ p₁ , p₂ ⟩ ∎
; equalize = λ eq → pu.universal (sym-assoc ○ eq ○ assoc)
; universal = λ {_ h} → begin
h ≈˘⟨ p.unique (⟺ p₁∘universal≈h₁) (⟺ p₂∘universal≈h₂) ⟩
⟨ p₁ ∘ _ , p₂ ∘ _ ⟩ ≈⟨ p.unique (pullˡ project₁) (pullˡ project₂) ⟩
⟨ p₁ , p₂ ⟩ ∘ _ ∎
; unique = λ eq → pu.unique (pushˡ (⟺ project₁) ○ ⟺ (∘-resp-≈ʳ eq))
(pushˡ (⟺ project₂) ○ ⟺ (∘-resp-≈ʳ eq))
}
where module p = Product p
module pu = Pullback pu
open p
open pu
module _ (p : Pullback f g) where
open Pullback p
Pullback-resp-≈ : h ≈ f → i ≈ g → Pullback h i
Pullback-resp-≈ eq eq′ = record
{ p₁ = p₁
; p₂ = p₂
; commute = ∘-resp-≈ˡ eq ○ commute ○ ⟺ (∘-resp-≈ˡ eq′)
; universal = λ eq″ → universal (∘-resp-≈ˡ (⟺ eq) ○ eq″ ○ ∘-resp-≈ˡ eq′)
; unique = unique
; p₁∘universal≈h₁ = p₁∘universal≈h₁
; p₂∘universal≈h₂ = p₂∘universal≈h₂
}
Pullback-resp-Mono : Mono g → Mono p₁
Pullback-resp-Mono mg h i eq = unique-diagram eq (mg _ _ eq′)
where eq′ : g ∘ p₂ ∘ h ≈ g ∘ p₂ ∘ i
eq′ = begin
g ∘ p₂ ∘ h ≈⟨ extendʳ (sym commute) ⟩
f ∘ p₁ ∘ h ≈⟨ refl⟩∘⟨ eq ⟩
f ∘ p₁ ∘ i ≈⟨ extendʳ commute ⟩
g ∘ p₂ ∘ i ∎
Pullback-resp-Iso : Iso g h → ∃ λ i → Iso p₁ i
Pullback-resp-Iso {h = h} iso = universal eq
, record
{ isoˡ = unique-diagram eq₁ eq₂
; isoʳ = p₁∘universal≈h₁
}
where open Iso iso
eq = begin
f ∘ id ≈⟨ introˡ refl ⟩
id ∘ f ∘ id ≈⟨ pushˡ (⟺ isoʳ) ⟩
g ∘ h ∘ f ∘ id ∎
eq₁ = begin
p₁ ∘ universal eq ∘ p₁ ≈⟨ cancelˡ p₁∘universal≈h₁ ⟩
p₁ ≈˘⟨ identityʳ ⟩
p₁ ∘ id ∎
eq₂ = begin
p₂ ∘ universal eq ∘ p₁ ≈⟨ extendʳ p₂∘universal≈h₂ ⟩
h ∘ (f ∘ id) ∘ p₁ ≈⟨ refl ⟩∘⟨ identityʳ ⟩∘⟨ refl ⟩
h ∘ f ∘ p₁ ≈⟨ refl ⟩∘⟨ commute ⟩
h ∘ g ∘ p₂ ≈⟨ cancelˡ isoˡ ⟩
p₂ ≈˘⟨ identityʳ ⟩
p₂ ∘ id ∎
| 36.086294
| 87
| 0.478548
|
392ccdff6016bc66ec0028558d639ef55de62c9d
| 1,223
|
agda
|
Agda
|
agda/hott/types/coproduct.agda
|
piyush-kurur/hott
|
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
|
[
"BSD-3-Clause"
] | null | null | null |
agda/hott/types/coproduct.agda
|
piyush-kurur/hott
|
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
|
[
"BSD-3-Clause"
] | null | null | null |
agda/hott/types/coproduct.agda
|
piyush-kurur/hott
|
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module hott.types.coproduct where
open import hott.core.universe
data _∐_ {ℓ₀ ℓ₁ : Level}
(A : Type ℓ₀)
(B : Type ℓ₁) : Type (ℓ₀ ⊔ ℓ₁) where
inl : (a : A) → A ∐ B -- left introduction
inr : (b : B) → A ∐ B -- right introduction
-- A more suggestive way of building elements of nested co-product
-- types. For example if we have a : A, b : B and c : C then the
-- expressions, a ∣∙, ∙∣ b ∣∙ and ∙∣ ∙∣ c are elements inl a, inr (inl
-- b) and inr (inr c) of A ∐ B ∐ C respectively.
_∣∙ : {ℓ₀ ℓ₁ : Level}{A : Type ℓ₀}{B : Type ℓ₁}
→ A → A ∐ B
_∣∙ = inl
∙∣_ : {ℓ₀ ℓ₁ : Level}{A : Type ℓ₀}{B : Type ℓ₁}
→ B → A ∐ B
∙∣_ = inr
infixr 0 ∙∣_
infixr 0 _∣∙
-- A more suggestive way of building a case by case analysis.
-- For example, one can just write f1 ∣ f2 ∣ f3
_∣_ : {a b c : Level}
{A : Type a}
{B : Type b}
{C : Type c}
→ (A → C)
→ (B → C)
→ (A ∐ B → C)
(f ∣ g) (inl a) = f a
(f ∣ g) (inr b) = g b
infixr 0 _∐_
infixr 0 _∣_
-- Case by case analysis.
either : {ℓ₀ ℓ₁ ℓ₃ : Level}
{A : Type ℓ₀}{B : Type ℓ₁}{C : Type ℓ₃}
→ (A → C) → (B → C) → (A ∐ B → C)
either f g (inl a) = f a
either f g (inr b) = g b
| 23.075472
| 70
| 0.51758
|
18039b6fcd49e856c4f7bc31dd2a9e8fb2dfe67e
| 319
|
agda
|
Agda
|
test/LibSucceed/InstanceArguments/08-higherOrder.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/LibSucceed/InstanceArguments/08-higherOrder.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/LibSucceed/InstanceArguments/08-higherOrder.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module InstanceArguments.08-higherOrder where
explicitize : ∀ {A : Set} {B : A → Set} → ({{x : A}} → B x) → (x : A) → B x
explicitize f x = f {{x}}
implicitize : ∀ {A : Set} {B : A → Set} → ((x : A) → B x) → {{x : A}} → B x
implicitize f {{x}} = f x
data T : Set where
tt : T
test = explicitize (λ {{t : T}} → t)
| 24.538462
| 75
| 0.507837
|
0ef0fe6c942d9307706017cf7f178fb23a5e9581
| 2,373
|
agda
|
Agda
|
agda/List/Permutation/Base/Bag.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/List/Permutation/Base/Bag.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/List/Permutation/Base/Bag.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
module List.Permutation.Base.Bag (A : Set) where
open import Data.List
open import Data.List.Any as Any
open import Data.List.Any.BagAndSetEquality
open import Data.List.Any.Properties
open import Data.Sum renaming (_⊎_ to _∨_)
open import Function
open import Function.Inverse hiding (sym ; _∘_ ; id)
open import Function.Related as Related hiding (_∼[_]_)
open import List.Permutation.Base A
import Relation.Binary.EqReasoning as EqR
open import Relation.Binary.PropositionalEquality as P hiding (sym)
open Any.Membership-≡
open EqR ([ bag ]-Equality A)
open Related.EquationalReasoning renaming (_∎ to _□)
infix 4 _≈-bag_
_≈-bag_ : ∀ {a} {A : Set a} → List A → List A → Set a
xs ≈-bag ys = xs ∼[ bag ] ys
sym-≈-bag : {xs ys : List A} → xs ≈-bag ys → ys ≈-bag xs
sym-≈-bag {xs} {ys} xs≈ys {z} = record
{ to = Inverse.from xs≈ys
; from = Inverse.to xs≈ys
; inverse-of = record
{ left-inverse-of = Inverse.right-inverse-of xs≈ys
; right-inverse-of = Inverse.left-inverse-of xs≈ys
}
}
refl-≈-bag : {xs : List A} → xs ≈-bag xs
refl-≈-bag {xs} = begin xs ∎
∨↔ : ∀{a b}{A : Set a}{B : Set b} → (A ∨ B) ↔ (B ∨ A)
∨↔ = record
{ to = P.→-to-⟶ ∨→
; from = P.→-to-⟶ ∨→
; inverse-of = record
{ left-inverse-of = v→∘v→
; right-inverse-of = v→∘v→
}
}
where
∨→ : ∀{a b}{A : Set a}{B : Set b} → (A ∨ B) → (B ∨ A)
∨→ (inj₁ x) = inj₂ x
∨→ (inj₂ x) = inj₁ x
v→∘v→ : ∀{a b}{A : Set a}{B : Set b}(a∨b : A ∨ B) → ∨→ (∨→ a∨b) ≡ a∨b
v→∘v→ (inj₁ _) = refl
v→∘v→ (inj₂ _) = refl
xy≈-bag-yx : {x y : A} → x ∷ y ∷ [] ≈-bag y ∷ x ∷ []
xy≈-bag-yx {x} {y} {z} =
z ∈ x ∷ y ∷ [] ↔⟨ sym $ ++↔ {xs = x ∷ []} {ys = y ∷ []} ⟩
(z ∈ x ∷ [] ∨ z ∈ y ∷ []) ↔⟨ ∨↔ ⟩
(z ∈ y ∷ [] ∨ z ∈ x ∷ []) ↔⟨ ++↔ ⟩
z ∈ y ∷ x ∷ [] □
lemma-/-≈-bag : {y : A}{xs ys : List A} → xs / y ⟶ ys → xs ≈-bag (y ∷ ys)
lemma-/-≈-bag /head = refl-≈-bag
lemma-/-≈-bag (/tail {x} {y} {xs} {ys} xs/y⟶ys) = begin
x ∷ xs ≈⟨ ∷-cong refl (lemma-/-≈-bag xs/y⟶ys) ⟩
x ∷ y ∷ ys ≈⟨ ++-cong xy≈-bag-yx refl-≈-bag ⟩
y ∷ x ∷ ys ∎
lemma-∼-≈-bag : {xs ys : List A} → xs ∼ ys → xs ≈-bag ys
lemma-∼-≈-bag ∼[] = refl-≈-bag
lemma-∼-≈-bag (∼x {x} {xs} {ys} {xs'} {ys'} xs/x⟶xs' ys/x⟶ys' xs'∼ys') = begin
xs ≈⟨ lemma-/-≈-bag xs/x⟶xs' ⟩
x ∷ xs' ≈⟨ ∷-cong refl (lemma-∼-≈-bag xs'∼ys') ⟩
x ∷ ys' ≈⟨ sym-≈-bag (lemma-/-≈-bag ys/x⟶ys') ⟩
ys ∎
| 30.818182
| 78
| 0.51791
|
fb1f0a56381527397ac671970ed167d14590e804
| 30,984
|
agda
|
Agda
|
Definitional.agda
|
kztk-m/sparcl-agda
|
e2fb3a669e733a9020a51b24244d89abd8fcf725
|
[
"BSD-3-Clause"
] | null | null | null |
Definitional.agda
|
kztk-m/sparcl-agda
|
e2fb3a669e733a9020a51b24244d89abd8fcf725
|
[
"BSD-3-Clause"
] | null | null | null |
Definitional.agda
|
kztk-m/sparcl-agda
|
e2fb3a669e733a9020a51b24244d89abd8fcf725
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
-- Approx. 15-20 min are required to typecheck this file (for Agda 2.6.1) on
-- my MacBook 13-inch 2017 with 3.5 GHz Core i7 CPU and 16 GB memory.
--
-- Since most of the time was spent for termination analysis, please
-- uncomment {-# TERMINATING #-} before evalR and eval to remove the
-- termination checks.
module Definitional where
open import Syntax
open import Data.Nat
open import Data.Fin using (Fin ; suc; zero)
open import Data.List using (length ; [] ; _∷_ )
open import Data.List.Properties using (length-++)
open import Data.Vec using ([] ; _∷_)
open import Data.Vec.Relation.Unary.All using (All ; [] ; _∷_)
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Level renaming (zero to lzero ; suc to lsuc)
open ≡-Reasoning
open import Function using () renaming (case_of_ to CASE_OF_)
open import Value
open import Size
open import Codata.Thunk
module Interpreter where
open import Codata.Delay renaming (length to dlength ; map to dmap )
open import PInj
open _⊢_⇔_
-- A variant of the Delay monad in which the bind operator is
-- frozen. While we cannot restrict levels in general, using Set is
-- enough for enough for our purpose.
data DELAY : (A : Set) -> (i : Size) -> Set₁ where
Now : ∀ {A i} -> A -> DELAY A i
Later : ∀ {A i} -> Thunk (DELAY A) i -> DELAY A i
Bind : ∀ {A B i}
-> (m : DELAY A i) -> (f : A -> DELAY B i) -> DELAY B i
Never : ∀ {A i} -> DELAY A i
Never = Later λ where .force -> Never
Dmap : ∀ {A B i} -> (A -> B) -> DELAY A i -> DELAY B i
Dmap f d = Bind d (λ x -> Now (f x))
-- The function runD thaws the frozen operations.
runD : ∀ {A : Set} {i : Size} -> DELAY A i -> Delay A i
runD (Now x) = now x
runD (Later x) = later λ where .force -> runD (force x)
runD (Bind d f) = bind (runD d) (λ x -> runD (f x))
-- The frozen version of _⊢_⇔_
record _⊢F_⇔_ (i : Size) (A B : Set) : Set₁ where
field
Forward : A -> DELAY B i
Backward : B -> DELAY A i
open _⊢F_⇔_
forwardF : ∀ {A B i} -> i ⊢F A ⇔ B -> A -> Delay B i
forwardF h a = runD (Forward h a)
backwardF : ∀ {A B i} -> i ⊢F A ⇔ B -> B -> Delay A i
backwardF h b = runD (Backward h b)
-- Similarly to runD, runD⇔ thawas the frozen operations in
-- _⊢F_⇔_.
runD⇔ : ∀ {A B i} -> i ⊢F A ⇔ B -> i ⊢ A ⇔ B
forward (runD⇔ f) = forwardF f
backward (runD⇔ f) = backwardF f
-- Environments handled by the forward and backward evaluations,
-- which correponds to μ in the paper.
data RValEnv : (Θ : TyEnv) (Ξ : MultEnv (length Θ)) -> Set where
[] : RValEnv [] []
skip : ∀ {Θ Ξ A} -> RValEnv Θ Ξ -> RValEnv (A ∷ Θ) (zero ∷ Ξ)
_∷_ : ∀ {Θ Ξ A} -> Value [] ∅ A -> RValEnv Θ Ξ -> RValEnv (A ∷ Θ) (one ∷ Ξ)
emptyRValEnv : ∀ {Θ} -> RValEnv Θ ∅
emptyRValEnv {[]} = []
emptyRValEnv {_ ∷ _} = skip emptyRValEnv
splitRValEnv : ∀ {Θ Ξ₁ Ξ₂} -> RValEnv Θ (Ξ₁ +ₘ Ξ₂) -> RValEnv Θ Ξ₁ × RValEnv Θ Ξ₂
splitRValEnv {[]} {[]} {[]} [] = [] , []
splitRValEnv {_ ∷ Θ} {zero ∷ Ξ₁} {zero ∷ Ξ₂} (skip ρ)
with splitRValEnv ρ
... | ρ₁ , ρ₂ = skip ρ₁ , skip ρ₂
splitRValEnv {_ ∷ Θ} {zero ∷ Ξ₁} {one ∷ Ξ₂} (x ∷ ρ)
with splitRValEnv ρ
... | ρ₁ , ρ₂ = skip ρ₁ , x ∷ ρ₂
splitRValEnv {_ ∷ Θ} {one ∷ Ξ₁} {zero ∷ Ξ₂} (x ∷ ρ)
with splitRValEnv ρ
... | ρ₁ , ρ₂ = x ∷ ρ₁ , skip ρ₂
-- An inverse of splitRValEnv.
mergeRValEnv : ∀ {Θ Ξ₁ Ξ₂} -> all-no-omega (Ξ₁ +ₘ Ξ₂) -> RValEnv Θ Ξ₁ -> RValEnv Θ Ξ₂ -> RValEnv Θ (Ξ₁ +ₘ Ξ₂)
mergeRValEnv {.[]} {.[]} {.[]} _ [] [] = []
mergeRValEnv {.(_ ∷ _)} {.(zero ∷ _)} {.(zero ∷ _)} (_ ∷ ano) (skip ρ₁) (skip ρ₂) = skip (mergeRValEnv ano ρ₁ ρ₂)
mergeRValEnv {.(_ ∷ _)} {.(zero ∷ _)} {.(one ∷ _)} (_ ∷ ano) (skip ρ₁) (x ∷ ρ₂) = x ∷ (mergeRValEnv ano ρ₁ ρ₂)
mergeRValEnv {.(_ ∷ _)} {.(one ∷ _)} {.(zero ∷ _)} (_ ∷ ano) (x ∷ ρ₁) (skip ρ₂) = x ∷ mergeRValEnv ano ρ₁ ρ₂
mergeRValEnv {.(_ ∷ _)} {.(one ∷ _)} {.(one ∷ _)} (() ∷ ano) (x ∷ ρ₁) (x₁ ∷ ρ₂)
-- Construction of the empty value environment.
from-all-zero : ∀ {Θ Ξ} -> all-zero Ξ -> RValEnv Θ Ξ
from-all-zero {[]} {[]} [] = []
from-all-zero {_ ∷ Θ} {.(zero ∷ _)} (refl ∷ az) = skip (from-all-zero az)
-- Value environments conforms to an empty invertible environment must be empty.
all-zero-canon : ∀ {Θ Ξ} -> (az : all-zero Ξ) -> (θ : RValEnv Θ Ξ) -> θ ≡ (from-all-zero az)
all-zero-canon {[]} {[]} [] [] = refl
all-zero-canon {_ ∷ Θ} {_ ∷ Ξ} (refl ∷ az) (skip θ) = cong skip (all-zero-canon az θ)
-- Looking-up function for RValEnv
lkup : ∀ {Θ A} {x : Θ ∋ A} {Ξ} -> varOk● Θ x Ξ -> RValEnv Θ Ξ -> Value [] ∅ A
lkup (there ok) (skip ρ) = lkup ok ρ
lkup (here ad) (x ∷ ρ) = x -- ad asserts ρ consists only of skip and []
-- An inverse of lkup; the linearity matters here.
unlkup : ∀ {Θ A} {x : Θ ∋ A} {Ξ} -> varOk● Θ x Ξ -> Value [] ∅ A -> RValEnv Θ Ξ
unlkup (there ok) v = skip (unlkup ok v)
unlkup (here ad) v = v ∷ from-all-zero ad
-- Some utility functions.
var●₀ : ∀ {A Θ} -> Residual (A ∷ Θ) (one ∷ ∅) (A ●)
var●₀ = var● vz (here all-zero-∅)
BindR : ∀ {i Θ Ξ A} {r : Set} -> DELAY (Value Θ Ξ (A ●)) i -> (Residual Θ Ξ (A ●) -> DELAY r i) -> DELAY r i
BindR x f = Bind x λ { (red r) -> f r }
-- For the do trick for the pattern matching
-- See https://github.com/agda/agda/issues/2298
_>>=_ : ∀ {a b : Level} {A : Set a} {B : A -> Set b} -> ∀ (x : A) -> (∀ x -> B x) -> B x
x >>= f = f x
-- Function application.
apply :
∀ {Θ Ξ₁ Ξ₂ A m B} i ->
all-no-omega (Ξ₁ +ₘ m ×ₘ Ξ₂) ->
Value Θ Ξ₁ (A # m ~> B) -> Value Θ Ξ₂ A -> DELAY (Value Θ (Ξ₁ +ₘ m ×ₘ Ξ₂) B) i
-- Forward, backward and unidirectional evalautions are given as
-- mutually recursive functions. Notice that, the existence of these
-- functions essentially proves the type safety (i.e., the
-- preservation and progree prperty). Thus, in a sense, they are
-- generalizations of Lemma 3.1 and Lemma 3.2 in the paper.
-- Forward and backward evaluation.
-- {-# TERMINATING #-}
evalR :
∀ {Θ Ξ A} i ->
all-no-omega Ξ -> Residual Θ Ξ (A ●) -> i ⊢F (RValEnv Θ Ξ) ⇔ Value [] ∅ A
-- Unidirectional evaluation. Also, an important thing is that this function keeps
-- the invariant all-no-omega (Ξₑ +ₘ Ξ) for recursive calls, which essentially supports
-- the claim in Section 3.4: "This assumption is actually an invariant in our system ...".
-- {-# TERMINATING #-}
eval :
∀ {Θ Ξₑ Γ Δ Ξ A} i ->
all-no-omega (Ξₑ +ₘ Ξ) -> ValEnv Γ Δ Θ Ξₑ -> Term Γ Δ Θ Ξ A -> DELAY (Value Θ (Ξₑ +ₘ Ξ) A) i
apply {Θ} {Ξ₁} {Ξ₂} i ano (clo {Ξ' = Ξ'} {Ξₜ = Ξₜ} m refl θ t) v with all-no-omega-dist _ _ ano
... | ano-'t , ano-m2 = Later λ { .force {j} ->
let T = eval j (subst all-no-omega lemma ano) (tup _ _ refl (value-to-multM ano-m2 v) θ) t
in subst (λ x -> DELAY (Value Θ x _) j) (sym lemma) T
}
where
lemma : Ξ' +ₘ Ξₜ +ₘ m ×ₘ Ξ₂ ≡ m ×ₘ Ξ₂ +ₘ Ξ' +ₘ Ξₜ
lemma = trans (+ₘ-comm _ _)
(sym (+ₘ-assoc (m ×ₘ Ξ₂) Ξ' _))
-- evalR is defined so that evalR ∞ ano r actually defines a
-- bijection. See Invertiblity.agda for its proof.
Forward (evalR i ano unit●) _ = Now (unit refl)
Backward (evalR i ano unit●) _ = Now emptyRValEnv
Forward (evalR i ano (letunit● r₁ r₂)) ρ = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
ρ₁ , ρ₂ <- splitRValEnv ρ
Bind (Forward (evalR i ano₁ r₁) ρ₁) λ { (unit eq) -> Forward (evalR i ano₂ r₂) ρ₂ }
Backward (evalR i ano (letunit● r₁ r₂)) v = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
Bind (Backward (evalR i ano₂ r₂) v) λ ρ₂ ->
Bind (Backward (evalR i ano₁ r₁) (unit refl)) λ ρ₁ ->
Now (mergeRValEnv ano ρ₁ ρ₂)
Forward (evalR i ano (pair● r₁ r₂)) ρ = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
ρ₁ , ρ₂ <- splitRValEnv ρ
Bind (Forward (evalR i ano₁ r₁) ρ₁) λ v₁ ->
Bind (Forward (evalR i ano₂ r₂) ρ₂) λ v₂ ->
Now (pair refl v₁ v₂)
Backward (evalR i ano (pair● {A = A} {B} r₁ r₂)) (pair {Ξ₁ = []} {[]} spΞ v₁ v₂) = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
Bind (Backward (evalR i ano₁ r₁) v₁) λ ρ₁ ->
Bind (Backward (evalR i ano₂ r₂) v₂) λ ρ₂ ->
Now (mergeRValEnv ano ρ₁ ρ₂)
Forward (evalR i ano (letpair● r₁ r₂)) ρ = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
ρ₁ , ρ₂ <- splitRValEnv ρ
Bind (Forward (evalR i ano₁ r₁) ρ₁) λ {
(pair {Ξ₁ = []} {[]} spΞ v₁ v₂ ) ->
Forward (evalR i (one ∷ one ∷ ano₂) r₂) (v₁ ∷ v₂ ∷ ρ₂)
}
Backward (evalR i ano (letpair● r₁ r₂)) v = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
Bind (Backward (evalR i (one ∷ one ∷ ano₂) r₂) v) λ { (v₁ ∷ v₂ ∷ ρ₂) ->
Bind (Backward (evalR i ano₁ r₁) (pair refl v₁ v₂)) λ ρ₁ ->
Now (mergeRValEnv ano ρ₁ ρ₂)
}
Forward (evalR i ano (inl● r)) ρ = Bind (Forward (evalR i ano r) ρ) λ x -> Now (inl x)
Backward (evalR i ano (inl● r)) v =
CASE v OF λ {
(inl v₁) -> Backward (evalR i ano r) v₁ ;
(inr v₂) -> Never
}
Forward (evalR i ano (inr● r)) ρ = Bind (Forward (evalR i ano r) ρ) λ x -> Now (inr x)
Backward (evalR i ano (inr● r)) v =
CASE v OF λ {
(inl v₁) -> Never ;
(inr v₂) -> Backward (evalR i ano r) v₂
}
Forward (evalR i ano (case● {Γ₁ = Γ₁} {Γ₂} r refl θ₁ t₁ θ₂ t₂ f)) ρ = do
ano₀ , ano- <- all-no-omega-dist _ _ ano
ρ₀ , ρ- <- splitRValEnv ρ
Bind (Forward (evalR i ano₀ r) ρ₀) λ {
(inl v₁) ->
Bind (eval i (one ∷ ano-) (weakenΘ-valEnv Γ₁ (compat-ext-here ext-id) θ₁) t₁) λ { (red r₁) ->
Later λ { .force {j} ->
Bind (Forward (evalR j (one ∷ ano-) r₁) (v₁ ∷ ρ-)) λ v ->
Bind (apply j [] f v) λ {
(inl _) -> Now v ;
(inr _) -> Never
}
}
}
;
(inr v₂) ->
Bind (eval i (one ∷ ano-) (weakenΘ-valEnv Γ₂ (compat-ext-here ext-id) θ₂) t₂) λ { (red r₂) ->
Later λ { .force {j} ->
Bind (Forward (evalR j (one ∷ ano-) r₂) (v₂ ∷ ρ-)) λ v ->
Bind (apply j [] f v) λ {
(inl _) -> Never ;
(inr _) -> Now v
}
}
}
}
Backward (evalR i ano (case● {Γ₁ = Γ₁} {Γ₂} r refl θ₁ t₁ θ₂ t₂ f)) v = do
ano₀ , ano- <- all-no-omega-dist _ _ ano
Bind (apply i [] f v) λ {
(inl _) ->
Bind (eval i (one ∷ ano-) (weakenΘ-valEnv Γ₁ (compat-ext-here ext-id) θ₁) t₁) λ { (red r₁) ->
Later λ { .force {j} ->
Bind (Backward (evalR j (one ∷ ano-) r₁) v) λ { (v₁ ∷ ρ-) ->
Bind (Backward (evalR j ano₀ r) (inl v₁)) λ ρ₀ ->
Now (mergeRValEnv ano ρ₀ ρ-)
}
}
}
;
(inr _) ->
Bind (eval i (one ∷ ano-) (weakenΘ-valEnv Γ₂ (compat-ext-here ext-id) θ₂) t₂) λ { (red r₂) ->
Later λ where .force {j} ->
Bind (Backward (evalR j (one ∷ ano-) r₂) v) λ { (v₂ ∷ ρ-) ->
Bind (Backward (evalR j ano₀ r) (inr v₂)) λ ρ₀ ->
Now (mergeRValEnv ano ρ₀ ρ-)
}
}
}
Forward (evalR i ano (var● x ok)) ρ = Now (lkup ok ρ)
Backward (evalR i ano (var● x ok)) v = Now (unlkup ok v)
Forward (evalR i ano (pin r f)) ρ = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
ρ₁ , ρ₂ <- splitRValEnv ρ
Bind (Forward (evalR i ano₁ r) ρ₁) λ v₁ ->
CASE f OF λ { (clo .omega refl θ t) →
Later λ { .force {j} ->
Bind (eval j ano₂ (tup ∅ _ (∅-lid _) (mult-omega (weakenΘ-value extendΘ v₁) refl) θ) t) λ {
(red r₂) ->
-- maybe another delaying would be needed here
Bind (Forward (evalR j ano₂ r₂) ρ₂) λ v₂ ->
Now (pair refl v₁ v₂)
}
}
}
Backward (evalR i ano (pin r (clo .omega refl θ t))) (pair {Ξ₁ = []} {[]} refl v₁ v₂) = do
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
Later λ { .force {j} ->
BindR (eval j ano₂ (tup ∅ _ (∅-lid _) (mult-omega (weakenΘ-value extendΘ v₁) refl) θ) t) λ r₂ ->
Bind (Backward (evalR j ano₂ r₂) v₂) λ ρ₂ ->
Bind (Backward (evalR j ano₁ r) v₁) λ ρ₁ ->
Now (mergeRValEnv ano ρ₁ ρ₂)
}
-- The unidirectional evaluation, of which definition would be
-- routine except for rather tedious manipulation of value
-- environments.
eval {Θ} _ ano θ (var x ok) = Now (subst (λ x -> Value Θ x _) (sym (∅-rid _)) (lookupVar θ ok))
eval _ ano θ (abs m t) = Now (clo m refl θ t)
eval {Θ} {Γ = Γ} i ano θ (app {Δ₁ = Δ₁} {Δ₂} {Ξ₁ = Ξ₁} {Ξ₂} {m = m} t₁ t₂)
with separateEnv {Γ} Δ₁ (m ×ₘ Δ₂) θ
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ with eval i (proj₁ lemma) θ₁ t₁ | proj₂ lemma | un×ₘ-valEnv Γ θ₂
where
lemma' : Ξₑ₁ +ₘ Ξₑ₂ +ₘ (Ξ₁ +ₘ m ×ₘ Ξ₂) ≡ (Ξₑ₁ +ₘ Ξ₁) +ₘ (Ξₑ₂ +ₘ m ×ₘ Ξ₂)
lemma' = +ₘ-transpose Ξₑ₁ Ξₑ₂ Ξ₁ (m ×ₘ Ξ₂)
lemma : all-no-omega (Ξₑ₁ +ₘ Ξ₁) × all-no-omega (Ξₑ₂ +ₘ m ×ₘ Ξ₂)
lemma = all-no-omega-dist (Ξₑ₁ +ₘ Ξ₁) _ (subst all-no-omega lemma' ano)
... | T₁ | ano-e2m2 | Ξₑ₂' , θ₂' , refl with (subst all-no-omega (sym (×ₘ-dist m Ξₑ₂' _)) ano-e2m2)
... | ano-m[e2'2] with eval i (all-no-omega-dist-×ₘ m (Ξₑ₂' +ₘ Ξ₂) ano-m[e2'2]) θ₂' t₂
... | T₂ =
Bind T₁ (λ { (clo {Ξ' = Ξ'} {Ξₜ = Ξₜ} m spΞ θf t) → Bind T₂ λ v₂ ->
Later λ { .force ->
let lemma : m ×ₘ (Ξₑ₂' +ₘ Ξ₂) +ₘ Ξ' +ₘ Ξₜ ≡ Ξₑ₁ +ₘ m ×ₘ Ξₑ₂' +ₘ (Ξ₁ +ₘ m ×ₘ Ξ₂)
lemma =
begin
m ×ₘ (Ξₑ₂' +ₘ Ξ₂) +ₘ Ξ' +ₘ Ξₜ
≡⟨ +ₘ-assoc (m ×ₘ (Ξₑ₂' +ₘ Ξ₂)) Ξ' _ ⟩
m ×ₘ (Ξₑ₂' +ₘ Ξ₂) +ₘ (Ξ' +ₘ Ξₜ)
≡⟨ cong (_ +ₘ_) spΞ ⟩
m ×ₘ (Ξₑ₂' +ₘ Ξ₂) +ₘ (Ξₑ₁ +ₘ Ξ₁)
≡⟨ cong (_+ₘ _) (×ₘ-dist m Ξₑ₂' Ξ₂) ⟩
m ×ₘ Ξₑ₂' +ₘ m ×ₘ Ξ₂ +ₘ (Ξₑ₁ +ₘ Ξ₁)
≡⟨ +ₘ-transpose (m ×ₘ Ξₑ₂') (m ×ₘ Ξ₂) Ξₑ₁ _ ⟩
m ×ₘ Ξₑ₂' +ₘ Ξₑ₁ +ₘ (m ×ₘ Ξ₂ +ₘ Ξ₁)
≡⟨ cong₂ (_+ₘ_) (+ₘ-comm _ _) (+ₘ-comm _ _) ⟩
Ξₑ₁ +ₘ m ×ₘ Ξₑ₂' +ₘ (Ξ₁ +ₘ m ×ₘ Ξ₂)
∎
lemma-ano : all-no-omega (m ×ₘ (Ξₑ₂' +ₘ Ξ₂) +ₘ Ξ' +ₘ Ξₜ)
lemma-ano = subst all-no-omega (sym lemma) ano
in (Bind (eval _ lemma-ano (tup (m ×ₘ (Ξₑ₂' +ₘ Ξ₂)) Ξ' refl (value-to-multM ano-m[e2'2] v₂) θf) t) λ v -> Now (subst (λ Ξ -> Value Θ Ξ _) lemma v)
)}
})
eval {Γ = Γ} _ ano θ (unit ad) with discardable-has-no-resources {Γ} θ ad
... | refl = Now (substV (sym (∅-lid _)) (unit refl))
eval {Θ} {Ξₑ} {Γ} i ano θ (letunit {Δ₀ = Δ₀} {Δ} {Ξ₀ = Ξ₀} {Ξ} m t₀ t)
with separateEnv {Γ} (m ×ₘ Δ₀) Δ θ
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂
with un×ₘ-valEnv Γ θ₁
... | Ξₑ₁' , θ₁' , refl
with subst all-no-omega (+ₘ-transpose (m ×ₘ Ξₑ₁') Ξₑ₂ (m ×ₘ Ξ₀) _) ano
... | ano'
with all-no-omega-dist (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀) _ ano'
... | ano-me1'm0 , ano-e2
with eval i (all-no-omega-dist-×ₘ m (Ξₑ₁' +ₘ Ξ₀) (subst all-no-omega (sym (×ₘ-dist m Ξₑ₁' Ξ₀)) ano-me1'm0)) θ₁' t₀
... | T₀ = Bind T₀ λ { (unit emp-e1'0) →
let lemma : Ξₑ₂ +ₘ Ξ ≡ (m ×ₘ Ξₑ₁' +ₘ Ξₑ₂) +ₘ ((m ×ₘ Ξ₀) +ₘ Ξ)
lemma =
begin
Ξₑ₂ +ₘ Ξ
≡⟨ sym (∅-lid _) ⟩
∅ +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ cong (_+ₘ (Ξₑ₂ +ₘ Ξ)) (sym (×ₘ∅ m)) ⟩
m ×ₘ ∅ +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ cong (λ h -> m ×ₘ h +ₘ (Ξₑ₂ +ₘ Ξ)) (emp-e1'0) ⟩
m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ cong (_+ₘ _) (×ₘ-dist m Ξₑ₁' Ξ₀) ⟩
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ +ₘ-transpose (m ×ₘ Ξₑ₁') (m ×ₘ Ξ₀) Ξₑ₂ Ξ ⟩
(m ×ₘ Ξₑ₁' +ₘ Ξₑ₂) +ₘ ((m ×ₘ Ξ₀) +ₘ Ξ)
∎
in Dmap (substV lemma) (eval i ano-e2 θ₂ t)
}
eval {Θ} {Ξₑ} {Γ} i ano θ (pair {Δ₁ = Δ₁} {Δ₂} {Ξ₁ = Ξ₁} {Ξ₂} t₁ t₂)
with separateEnv {Γ} Δ₁ Δ₂ θ
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂
with subst all-no-omega (+ₘ-transpose Ξₑ₁ Ξₑ₂ Ξ₁ _) ano
... | ano'
with all-no-omega-dist (Ξₑ₁ +ₘ Ξ₁) _ ano'
... | ano-e11 , ano-e22
with eval i ano-e11 θ₁ t₁ | eval i ano-e22 θ₂ t₂
... | T₁ | T₂ = Bind T₁ λ v₁ ->
Bind T₂ λ v₂ -> Now (pair (+ₘ-transpose Ξₑ₁ Ξ₁ Ξₑ₂ _) v₁ v₂)
eval {Θ} {Ξₑ} {Γ} i ano θ (letpair {Δ₀ = Δ₀} {Δ} {Ξ₀ = Ξ₀} {Ξ} m t₀ t)
with separateEnv {Γ} (m ×ₘ Δ₀) Δ θ
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂
with un×ₘ-valEnv Γ θ₁
... | Ξₑ₁' , θ₁' , refl
with subst all-no-omega (+ₘ-transpose (m ×ₘ Ξₑ₁') Ξₑ₂ (m ×ₘ Ξ₀) Ξ) ano
... | ano'
with all-no-omega-dist (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀) _ ano'
... | ano-me1'm0 , ano-e2-
with subst all-no-omega (sym (×ₘ-dist m Ξₑ₁' _)) ano-me1'm0
... | ano-m[e1'0]
with all-no-omega-dist-×ₘ m _ ano-m[e1'0]
... | ano-e1'0
with eval i ano-e1'0 θ₁' t₀
... | T₀ = Bind T₀ λ { (pair {Ξ₁ = Ξ₁} {Ξ₂} spΞ v₁ v₂) →
let ano-m[12] : all-no-omega (m ×ₘ (Ξ₁ +ₘ Ξ₂))
ano-m[12] = subst all-no-omega (cong (m ×ₘ_) (sym spΞ)) ano-m[e1'0]
ano-m1m2 : all-no-omega (m ×ₘ Ξ₁ +ₘ m ×ₘ Ξ₂)
ano-m1m2 = subst all-no-omega (×ₘ-dist m Ξ₁ Ξ₂) ano-m[12]
an : all-no-omega (m ×ₘ Ξ₁) × all-no-omega (m ×ₘ Ξ₂)
an = all-no-omega-dist (m ×ₘ Ξ₁) _ ano-m1m2
eq : m ×ₘ Ξ₁ +ₘ (m ×ₘ Ξ₂ +ₘ Ξₑ₂) ≡ m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ Ξₑ₂
eq = begin
m ×ₘ Ξ₁ +ₘ (m ×ₘ Ξ₂ +ₘ Ξₑ₂)
≡⟨ sym (+ₘ-assoc (m ×ₘ Ξ₁) (m ×ₘ Ξ₂) _) ⟩
m ×ₘ Ξ₁ +ₘ m ×ₘ Ξ₂ +ₘ Ξₑ₂
≡⟨ cong (_+ₘ Ξₑ₂) (sym (×ₘ-dist m Ξ₁ Ξ₂)) ⟩
m ×ₘ (Ξ₁ +ₘ Ξ₂) +ₘ Ξₑ₂
≡⟨ cong (_+ₘ Ξₑ₂) (cong (m ×ₘ_) spΞ) ⟩
m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ Ξₑ₂
≡⟨ cong (_+ₘ Ξₑ₂) (×ₘ-dist m _ _) ⟩
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ Ξₑ₂
∎
θ' : ValEnv (_ ∷ _ ∷ Γ) (M→M₀ m ∷ M→M₀ m ∷ Δ) Θ (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ Ξₑ₂)
θ' = tup (m ×ₘ Ξ₁) _ eq (value-to-multM (proj₁ an) v₁)
(tup (m ×ₘ Ξ₂) Ξₑ₂ refl (value-to-multM (proj₂ an) v₂) θ₂)
eq' : m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ Ξₑ₂ +ₘ Ξ ≡ (m ×ₘ Ξₑ₁' +ₘ Ξₑ₂) +ₘ (m ×ₘ Ξ₀ +ₘ Ξ)
eq' = begin
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ Ξₑ₂ +ₘ Ξ
≡⟨ +ₘ-assoc (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀) Ξₑ₂ _ ⟩
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ +ₘ-transpose (m ×ₘ Ξₑ₁') (m ×ₘ Ξ₀) Ξₑ₂ _ ⟩
(m ×ₘ Ξₑ₁' +ₘ Ξₑ₂) +ₘ (m ×ₘ Ξ₀ +ₘ Ξ)
∎
-- solve 4 (λ a b c d ->
-- ((a ⊞ b) ⊞ c) ⊞ d ⊜
-- (a ⊞ c) ⊞ (b ⊞ d)) refl (m ×ₘ Ξₑ₁') (m ×ₘ Ξ₀) Ξₑ₂ Ξ
in Dmap (substV eq') (eval i (subst all-no-omega (sym eq') ano) θ' t)
}
eval {Θ} {Ξₑ} {Γ} i ano θ (many m t) = do
(Ξₑ' , θ' , refl) <- un×ₘ-valEnv Γ θ
ano-m[e'-] <- subst all-no-omega (sym (×ₘ-dist m Ξₑ' _)) ano
ano-e'- <- all-no-omega-dist-×ₘ m _ ano-m[e'-]
Bind (eval i ano-e'- θ' t) λ v ->
Now (many m (×ₘ-dist m Ξₑ' _) v)
eval {Θ} {Ξₑ} {Γ} i ano θ (unmany {Δ₀ = Δ₀} {Δ} {Ξ₀ = Ξ₀} {Ξ} {m₀ = m₀} {A} m t₀ t) = do
tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ <- separateEnv {Γ} (m ×ₘ Δ₀) Δ θ
Ξₑ₁' , θ₁' , refl <- un×ₘ-valEnv Γ θ₁
ano' <- subst all-no-omega (+ₘ-transpose (m ×ₘ Ξₑ₁') Ξₑ₂ (m ×ₘ Ξ₀) Ξ) ano
ano-me1'm0 , ano-e2 <- all-no-omega-dist (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀) _ ano'
ano-m[e1'0] <- subst all-no-omega (sym (×ₘ-dist m Ξₑ₁' _)) ano-me1'm0
ano-e1'0 <- all-no-omega-dist-×ₘ m _ ano-m[e1'0]
Bind (eval i ano-e1'0 θ₁' t₀ ) λ where
(many {Ξ₀ = Ξ''} .m₀ sp v₀) -> do
let ano-mm₀[e1'0] : all-no-omega (m ×ₘ m₀ ×ₘ Ξ'')
ano-mm₀[e1'0] = subst all-no-omega (cong (m ×ₘ_) (sym sp)) ano-m[e1'0]
ano-mul[e1'0] : all-no-omega (mul m m₀ ×ₘ Ξ'')
ano-mul[e1'0] = subst all-no-omega (sym (mul-×ₘ m m₀ Ξ'')) ano-mm₀[e1'0]
eq : m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ) ≡ mul m m₀ ×ₘ Ξ'' +ₘ Ξₑ₂ +ₘ Ξ
eq =
begin
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ cong (_+ₘ _) (sym (×ₘ-dist m Ξₑ₁' _)) ⟩
m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ cong (λ e -> m ×ₘ e +ₘ _) (sym sp) ⟩
m ×ₘ m₀ ×ₘ Ξ'' +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ cong (_+ₘ _) (sym (mul-×ₘ m m₀ Ξ'')) ⟩
mul m m₀ ×ₘ Ξ'' +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ sym (+ₘ-assoc _ _ _) ⟩
mul m m₀ ×ₘ Ξ'' +ₘ Ξₑ₂ +ₘ Ξ
∎
ano'' : all-no-omega (mul m m₀ ×ₘ Ξ'' +ₘ Ξₑ₂ +ₘ Ξ)
ano'' = subst all-no-omega eq ano'
θ' : ValEnv (A ∷ Γ) (M→M₀ (mul m m₀) ∷ Δ) Θ (mul m m₀ ×ₘ Ξ'' +ₘ Ξₑ₂)
θ' = tup _ Ξₑ₂ refl (value-to-multM ano-mul[e1'0] v₀) θ₂
Bind (eval i ano'' θ' t) λ v -> Now (substV (trans (sym eq) (sym (+ₘ-transpose (m ×ₘ Ξₑ₁') Ξₑ₂ (m ×ₘ Ξ₀) Ξ))) v)
eval i ano θ (inl t) = Dmap inl (eval i ano θ t)
eval i ano θ (inr t) = Dmap inr (eval i ano θ t)
eval {Θ} {Ξₑ = Ξₑ} {Γ} i ano θ (case {Δ₀ = Δ₀} {Δ} {Ξ₀ = Ξ₀} {Ξ} m t₀ t₁ t₂)
with separateEnv {Γ} (m ×ₘ Δ₀) Δ θ
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂
with un×ₘ-valEnv Γ θ₁
... | Ξₑ₁' , θ₁' , refl
with subst all-no-omega (+ₘ-transpose (m ×ₘ Ξₑ₁') Ξₑ₂ (m ×ₘ Ξ₀) Ξ) ano
... | ano'
with all-no-omega-dist (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀) _ ano'
... | ano-me1'm0 , ano-e2-
with subst all-no-omega (sym (×ₘ-dist m Ξₑ₁' _)) ano-me1'm0
... | ano-m[e1'0]
with all-no-omega-dist-×ₘ m _ ano-m[e1'0]
... | ano-e1'0
with eval i ano-e1'0 θ₁' t₀
... | T₀ = Bind T₀ λ {
(inl v) →
let θ' : ValEnv (_ ∷ Γ) (M→M₀ m ∷ Δ) Θ (m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ Ξₑ₂)
θ' = tup (m ×ₘ (Ξₑ₁' +ₘ Ξ₀)) Ξₑ₂ refl (value-to-multM ano-m[e1'0] v) θ₂
in Dmap (substV lemma) (eval i (subst all-no-omega (sym lemma) ano) θ' t₁) ;
(inr v) →
let θ' : ValEnv (_ ∷ Γ) (M→M₀ m ∷ Δ) Θ (m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ Ξₑ₂)
θ' = tup (m ×ₘ (Ξₑ₁' +ₘ Ξ₀)) Ξₑ₂ refl (value-to-multM ano-m[e1'0] v) θ₂
in Dmap (substV lemma) (eval i (subst all-no-omega (sym lemma) ano) θ' t₂)
}
where
lemma : m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ Ξₑ₂ +ₘ Ξ ≡
(m ×ₘ Ξₑ₁' +ₘ Ξₑ₂) +ₘ (m ×ₘ Ξ₀ +ₘ Ξ)
lemma =
begin
m ×ₘ (Ξₑ₁' +ₘ Ξ₀) +ₘ Ξₑ₂ +ₘ Ξ
≡⟨ cong (λ x -> x +ₘ Ξₑ₂ +ₘ Ξ) (×ₘ-dist m Ξₑ₁' _) ⟩
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ Ξₑ₂ +ₘ Ξ
≡⟨ +ₘ-assoc (m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀) Ξₑ₂ _ ⟩
m ×ₘ Ξₑ₁' +ₘ m ×ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ)
≡⟨ +ₘ-transpose _ _ _ _ ⟩
(m ×ₘ Ξₑ₁' +ₘ Ξₑ₂) +ₘ (m ×ₘ Ξ₀ +ₘ Ξ)
∎
eval i ano θ (roll t) = Dmap roll (eval i ano θ t)
eval i ano θ (unroll t) =
Bind (eval i ano θ t) λ { (roll v) → Later λ where .force -> Now v }
eval {Γ = Γ} i ano θ (unit● ad) with discardable-has-no-resources {Γ} θ ad
... | refl = Now (red (substR (sym (∅-lid _)) unit●))
eval {Θ} {Ξₑ} {Γ} i ano θ (letunit● {Δ₀ = Δ₀} {Δ} {Ξ₀ = Ξ₀} {Ξ} t₀ t) = do
tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ <- separateEnv {Γ} Δ₀ Δ θ
let lemma : Ξₑ₁ +ₘ Ξₑ₂ +ₘ (Ξ₀ +ₘ Ξ) ≡ Ξₑ₁ +ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ)
lemma = +ₘ-transpose _ _ _ _
let ano' = subst all-no-omega lemma ano
ano-e10 , ano-e2- <- all-no-omega-dist (Ξₑ₁ +ₘ Ξ₀) _ ano'
BindR (eval i ano-e10 θ₁ t₀) λ E₀ ->
BindR (eval i ano-e2- θ₂ t) λ E ->
Now (red (substR (sym lemma) (letunit● E₀ E)))
eval {Θ} {Ξₑ} {Γ} i ano θ (pair● {Δ₁ = Δ₁} {Δ₂} {Ξ₁ = Ξ₁} {Ξ₂} t₁ t₂) = do
tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ <- separateEnv {Γ} Δ₁ Δ₂ θ
let lemma : Ξₑ₁ +ₘ Ξₑ₂ +ₘ (Ξ₁ +ₘ Ξ₂) ≡ Ξₑ₁ +ₘ Ξ₁ +ₘ (Ξₑ₂ +ₘ Ξ₂)
lemma = +ₘ-transpose _ _ _ _
let ano' = subst all-no-omega lemma ano
ano-e11 , ano-e22 <- all-no-omega-dist (Ξₑ₁ +ₘ Ξ₁) _ ano'
BindR (eval i ano-e11 θ₁ t₁) λ E₁ ->
BindR (eval i ano-e22 θ₂ t₂) λ E₂ ->
Now (red (substR (sym lemma) (pair● E₁ E₂)))
eval {Θ} {Ξₑ} {Γ} i ano θ (letpair● {Δ₀ = Δ₀} {Δ} {Ξ₀ = Ξ₀} {Ξ} t₀ t)
with separateEnv {Γ} Δ₀ Δ θ
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂
with subst all-no-omega (+ₘ-transpose Ξₑ₁ Ξₑ₂ Ξ₀ _) ano
... | ano'
with all-no-omega-dist (Ξₑ₁ +ₘ Ξ₀) _ ano'
... | ano-e10 , ano-e2-
with eval i ano-e10 θ₁ t₀ | eval i (one ∷ one ∷ ano-e2-) (weakenΘ-valEnv Γ (compat-ext-here (compat-ext-here ext-id)) θ₂) t
... | T₁ | T =
Bind T₁ λ { (red E₁) ->
Bind T λ { (red E ) ->
Now (red (substR (+ₘ-transpose Ξₑ₁ Ξ₀ _ _) (letpair● E₁ E)))
}}
eval i ano θ (inl● t) =
BindR (eval i ano θ t) λ E -> Now (red (inl● E))
eval i ano θ (inr● t) =
BindR (eval i ano θ t) λ E -> Now (red (inr● E))
eval {Θ} {Ξₑ} {Γ} i ano θ (case● {Δ₀ = Δ₀} {Δ} {Δ'} {Ξ₀ = Ξ₀} {Ξ} {Ξ'} t t₁ t₂ t₃)
with separateEnv {Γ} (Δ₀ +ₘ Δ) _ θ
... | tup Ξₑ₁₂ Ξₑ₃ refl θ' θ₃
with discardable-has-no-resources {Γ} θ₃ (omega×ₘ-discardable Δ')
... | refl
with un×ₘ-valEnv Γ θ₃
... | Ξₑ₃' , θ₃' , eq
with omega×ₘ∅-inv Ξₑ₃' eq
... | refl
with separateEnv {Γ} Δ₀ Δ θ'
... | tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂
with subst all-no-omega lemma ano | lemma
where
open import Algebra.Solver.CommutativeMonoid (+ₘ-commutativeMonoid (length Θ))
renaming (_⊕_ to _⊞_)
lemma : Ξₑ₁ +ₘ Ξₑ₂ +ₘ ∅ +ₘ (Ξ₀ +ₘ Ξ +ₘ omega ×ₘ Ξ')
≡ (Ξₑ₁ +ₘ Ξ₀) +ₘ (Ξₑ₂ +ₘ Ξ) +ₘ omega ×ₘ Ξ'
lemma = solve 5 (\a b c d e -> ((a ⊞ b) ⊞ id) ⊞ ((c ⊞ d) ⊞ e)
⊜ ((a ⊞ c) ⊞ (b ⊞ d)) ⊞ e) refl Ξₑ₁ Ξₑ₂ Ξ₀ Ξ (omega ×ₘ Ξ')
... | ano' | lemma
with all-no-omega-dist ((Ξₑ₁ +ₘ Ξ₀) +ₘ (Ξₑ₂ +ₘ Ξ)) _ ano'
... | ano'' , ano₃
with all-no-omega-dist (Ξₑ₁ +ₘ Ξ₀) _ ano''
... | ano-e10 , ano-e2-
with all-no-omega-omega×ₘ Ξ' ano₃
... | refl
with eval i ano-e10 θ₁ t | eval i (subst all-no-omega (sym (∅-lid _)) all-no-omega-∅) θ₃' t₃
... | T | T₃ =
Bind T λ { (red r) ->
Bind T₃ λ { f ->
Now (red (substR (trans lemma' (sym lemma))
let f' = weakenΘ-value smashΘ (subst (λ x -> Value Θ x _) (∅-lid ∅) f)
in (case● r refl θ₂ t₁ θ₂ t₂ f')))
}
}
where
lemma' : Ξₑ₁ +ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ)
≡ Ξₑ₁ +ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ) +ₘ omega ×ₘ ∅
lemma' =
sym (trans (cong (λ x -> Ξₑ₁ +ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ) +ₘ x)
(×ₘ∅ omega))
(∅-rid (Ξₑ₁ +ₘ Ξ₀ +ₘ (Ξₑ₂ +ₘ Ξ) )))
eval {Θ} {Ξₑ} {Γ} i ano θ (var● x ad ok)
with discardable-has-no-resources {Γ} θ ad
... | refl = Now (red (substR (sym (∅-lid _)) (var● x ok)))
eval {Θ} {Ξₑ} {Γ} i ano θ (pin {Δ₁ = Δ₁} {Δ₂} {Ξ₁ = Ξ₁} {Ξ₂} t₁ t₂) = do
tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ <- separateEnv {Γ} Δ₁ Δ₂ θ
let ano' = subst all-no-omega (+ₘ-transpose Ξₑ₁ Ξₑ₂ Ξ₁ _) ano
ano-e11 , ano-e22 <- all-no-omega-dist (Ξₑ₁ +ₘ Ξ₁) _ ano'
BindR (eval i ano-e11 θ₁ t₁) λ r ->
Bind (eval i ano-e22 θ₂ t₂) λ v ->
Now (red (substR (+ₘ-transpose _ _ _ _) (pin r v)))
eval {Γ = Γ} i ano θ (unlift e) = do
Ξ' , θ' , refl <- un×ₘ-valEnv Γ θ
ano₁ , ano₂ <- all-no-omega-dist _ _ ano
refl <- all-no-omega-omega×ₘ _ ano₁
refl <- all-no-omega-omega×ₘ _ ano₂
Bind (eval i (subst all-no-omega (sym (∅-lid ∅)) all-no-omega-∅ ) θ' e) λ v ->
BindR (apply i (one ∷ subst all-no-omega (sym lemma₁) all-no-omega-∅) (weakenΘ-value (compat-ext-here ext-id) v) (red var●₀)) λ r ->
Now (substV (sym lemma₂) (inj refl (weakenΘ-residual (compat-skip smashΘ) (substR (cong (one ∷_) lemma₁) r) )))
where
open import Data.Vec.Properties using (map-id)
lemma₁ : ∀ {n} -> ∅ +ₘ ∅ +ₘ Data.Vec.map (λ y -> y) ∅ ≡ ∅ {n}
lemma₁ {n} rewrite map-id (∅ {n}) | ∅-rid {n} ∅ = ∅-lid ∅
lemma₂ : ∀ {n} -> omega ×ₘ ∅ +ₘ omega ×ₘ ∅ ≡ ∅ {n}
lemma₂ {n} rewrite ×ₘ∅ {n} omega | ∅-lid {n} ∅ = refl
eval {Γ = Γ} i ano θ (fapp e₁ e₂) = do
anoₑ , ano' <- all-no-omega-dist _ _ ano
ano₁ , ano'' <- all-no-omega-dist _ _ ano'
refl <- all-no-omega-omega×ₘ _ ano''
tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ <- separateEnv {Γ} _ _ θ
Ξₑ₂' , θ₂' , refl <- un×ₘ-valEnv Γ θ₂
ano₁' , _ <- all-no-omega-dist _ _ (subst all-no-omega lemma' ano)
Bind (eval i ano₁' θ₁ e₁) λ {
(inj spΞ r) → do
refl , refl <- ∅+ₘ∅-inv _ _ (sym spΞ)
refl <- all-no-omega-omega×ₘ _ (subst all-no-omega (∅-lid _) anoₑ)
Bind (eval i (subst all-no-omega (sym (∅-lid ∅)) all-no-omega-∅) θ₂' e₂) λ v -> Later λ { .force {j} ->
Bind (Forward (evalR j (one ∷ all-no-omega-∅) r) (weakenΘ-value smashΘ (substV (∅-lid ∅) v) ∷ [])) λ v' ->
Now (substV (sym lemma) (weakenΘ-value extendΘ v'))
}
}
where
lemma' : ∀ {n} {Ξₑ₁ Ξ₁ X Y : MultEnv n} -> Ξₑ₁ +ₘ X +ₘ (Ξ₁ +ₘ Y) ≡ Ξₑ₁ +ₘ Ξ₁ +ₘ (X +ₘ Y)
lemma' {n} {A} {B} {C} {D} = +ₘ-transpose A C B D
lemma : ∀ {n} -> ∅ +ₘ omega ×ₘ ∅ +ₘ (∅ +ₘ omega ×ₘ ∅) ≡ ∅ {n}
lemma {n} rewrite ×ₘ∅ {n} omega | ∅-lid {n} ∅ = ∅-lid ∅
eval {Γ = Γ} i ano θ (bapp e₁ e₂) = do
anoₑ , ano' <- all-no-omega-dist _ _ ano
ano₁ , ano'' <- all-no-omega-dist _ _ ano'
refl <- all-no-omega-omega×ₘ _ ano''
tup Ξₑ₁ Ξₑ₂ refl θ₁ θ₂ <- separateEnv {Γ} _ _ θ
Ξₑ₂' , θ₂' , refl <- un×ₘ-valEnv Γ θ₂
ano₁' , _ <- all-no-omega-dist _ _ (subst all-no-omega lemma' ano)
Bind (eval i ano₁' θ₁ e₁) λ {
(inj spΞ r) → do
refl , refl <- ∅+ₘ∅-inv _ _ (sym spΞ)
refl <- all-no-omega-omega×ₘ _ (subst all-no-omega (∅-lid _) anoₑ)
Bind (eval i (subst all-no-omega (sym (∅-lid ∅)) all-no-omega-∅) θ₂' e₂) λ v -> Later λ { .force {j} ->
Bind (Backward (evalR j (one ∷ all-no-omega-∅) r) (weakenΘ-value smashΘ (substV (∅-lid ∅) v))) λ { (v' ∷ []) ->
Now (substV (sym lemma) (weakenΘ-value extendΘ v'))
}
}
}
where
lemma' : ∀ {n} {Ξₑ₁ Ξ₁ X Y : MultEnv n} -> Ξₑ₁ +ₘ X +ₘ (Ξ₁ +ₘ Y) ≡ Ξₑ₁ +ₘ Ξ₁ +ₘ (X +ₘ Y)
lemma' {n} {A} {B} {C} {D} = +ₘ-transpose A C B D
lemma : ∀ {n} -> ∅ +ₘ omega ×ₘ ∅ +ₘ (∅ +ₘ omega ×ₘ ∅) ≡ ∅ {n}
lemma {n} rewrite ×ₘ∅ {n} omega | ∅-lid {n} ∅ = ∅-lid ∅
open Interpreter public
| 42.677686
| 157
| 0.481991
|
cbac082a07b0ea51feba646378d293b3ccd40d59
| 2,295
|
agda
|
Agda
|
vendor/stdlib/src/Data/Fin/Subset/Props.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Data/Fin/Subset/Props.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Data/Fin/Subset/Props.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Some properties about subsets
------------------------------------------------------------------------
module Data.Fin.Subset.Props where
open import Data.Nat
open import Data.Vec hiding (_∈_)
open import Data.Empty
open import Data.Function
open import Data.Fin
open import Data.Fin.Subset
open import Data.Product
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Constructor mangling
drop-there : ∀ {s n x} {p : Subset n} → suc x ∈ s ∷ p → x ∈ p
drop-there (there x∈p) = x∈p
drop-∷-⊆ : ∀ {n s₁ s₂} {p₁ p₂ : Subset n} → s₁ ∷ p₁ ⊆ s₂ ∷ p₂ → p₁ ⊆ p₂
drop-∷-⊆ p₁s₁⊆p₂s₂ x∈p₁ = drop-there $ p₁s₁⊆p₂s₂ (there x∈p₁)
drop-∷-Empty : ∀ {n s} {p : Subset n} → Empty (s ∷ p) → Empty p
drop-∷-Empty ¬¬∅ (x , x∈p) = ¬¬∅ (suc x , there x∈p)
------------------------------------------------------------------------
-- More interesting properties
allInside : ∀ {n} (x : Fin n) → x ∈ all inside
allInside zero = here
allInside (suc x) = there (allInside x)
allOutside : ∀ {n} (x : Fin n) → x ∉ all outside
allOutside zero ()
allOutside (suc x) (there x∈) = allOutside x x∈
⊆⊇⟶≡ : ∀ {n} {p₁ p₂ : Subset n} →
p₁ ⊆ p₂ → p₂ ⊆ p₁ → p₁ ≡ p₂
⊆⊇⟶≡ = helper _ _
where
helper : ∀ {n} (p₁ p₂ : Subset n) →
p₁ ⊆ p₂ → p₂ ⊆ p₁ → p₁ ≡ p₂
helper [] [] _ _ = refl
helper (s₁ ∷ p₁) (s₂ ∷ p₂) ₁⊆₂ ₂⊆₁ with ⊆⊇⟶≡ (drop-∷-⊆ ₁⊆₂)
(drop-∷-⊆ ₂⊆₁)
helper (outside ∷ p) (outside ∷ .p) ₁⊆₂ ₂⊆₁ | refl = refl
helper (inside ∷ p) (inside ∷ .p) ₁⊆₂ ₂⊆₁ | refl = refl
helper (outside ∷ p) (inside ∷ .p) ₁⊆₂ ₂⊆₁ | refl with ₂⊆₁ here
... | ()
helper (inside ∷ p) (outside ∷ .p) ₁⊆₂ ₂⊆₁ | refl with ₁⊆₂ here
... | ()
∅⟶allOutside : ∀ {n} {p : Subset n} →
Empty p → p ≡ all outside
∅⟶allOutside {p = []} ¬¬∅ = refl
∅⟶allOutside {p = s ∷ ps} ¬¬∅ with ∅⟶allOutside (drop-∷-Empty ¬¬∅)
∅⟶allOutside {p = outside ∷ .(all outside)} ¬¬∅ | refl = refl
∅⟶allOutside {p = inside ∷ .(all outside)} ¬¬∅ | refl =
⊥-elim (¬¬∅ (zero , here))
| 37.016129
| 72
| 0.44793
|
fb7e84152b2edac030360c7a2f2abdca512ed45b
| 708
|
agda
|
Agda
|
src/Ints.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | 1
|
2020-04-15T15:28:03.000Z
|
2020-04-15T15:28:03.000Z
|
src/Ints.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | null | null | null |
src/Ints.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | null | null | null |
module Ints where
open import Nats public
using (ℕ; zero; _∸_)
renaming (suc to nsuc; _+_ to _:+:_; _*_ to _:*:_)
open import Agda.Builtin.Int public
renaming (Int to ℤ; negsuc to -[1+_]; pos to +_)
infix 8 -_
-- infixl 7 _*_ _⊓_
infixl 6 _+_ _-_ _⊖_
∣_∣ : ℤ → ℕ
∣ + n ∣ = n
∣ -[1+ n ] ∣ = nsuc n
-_ : ℤ → ℤ
- (+ nsuc n) = -[1+ n ]
- (+ zero) = + zero
- -[1+ n ] = + nsuc n
_⊖_ : ℕ → ℕ → ℤ
m ⊖ zero = + m
zero ⊖ nsuc n = -[1+ n ]
nsuc m ⊖ nsuc n = m ⊖ n
_+_ : ℤ → ℤ → ℤ
-[1+ m ] + -[1+ n ] = -[1+ nsuc (m :+: n) ]
-[1+ m ] + + n = n ⊖ nsuc m
+ m + -[1+ n ] = m ⊖ nsuc n
+ m + + n = + (m :+: n)
_-_ : ℤ → ℤ → ℤ
i - j = i + - j
suc : ℤ → ℤ
suc i = + 1 + i
| 18.153846
| 52
| 0.418079
|
1052f7cceed60f3f4a0ae7baab8301b05d632a3d
| 586
|
agda
|
Agda
|
test/Succeed/Issue1944-UnappliedOverloadedProjection.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1944-UnappliedOverloadedProjection.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1944-UnappliedOverloadedProjection.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, Bentfest 2016-04-28 Marsstrand
-- Issue 1944: also resolve overloaded projections in checking position
module _ (A : Set) (a : A) where
record R (B : Set) : Set where
field f : B
open R
record S (B : Set) : Set where
field f : B
open S
test : R A → A
test = f
test1 : ∀{A} → R A → A
test1 = f
test2 : ∀ A → R A → A
test2 A = f {A}
postulate
F : Set → Set
mapF : ∀{A B} (f : A → B) → F A → F B
fr : F (R A)
test3 : F (R A) → F A
test3 = mapF f
test4 : F (R _) → F A
test4 = mapF f
test5 : ∀{A} → F (F (R A)) → F _
test5 = mapF (mapF f)
test6 = mapF f fr
| 15.421053
| 71
| 0.559727
|
1c0974f1d7a7fa7fd5eeb236a9de6a99743f92d5
| 7,916
|
agda
|
Agda
|
src/SyntaxMap.agda
|
andrejbauer/dependent-type-theory-syntax
|
9b634d284a0ec5108c68489575194cd573f38908
|
[
"MIT"
] | 7
|
2021-05-25T11:14:42.000Z
|
2021-10-14T01:48:00.000Z
|
src/SyntaxMap.agda
|
andrejbauer/dependent-type-theory-syntax
|
9b634d284a0ec5108c68489575194cd573f38908
|
[
"MIT"
] | null | null | null |
src/SyntaxMap.agda
|
andrejbauer/dependent-type-theory-syntax
|
9b634d284a0ec5108c68489575194cd573f38908
|
[
"MIT"
] | null | null | null |
open import Level
import Categories.Category
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; subst; cong)
open import Syntax
open import Renaming
open import Substitution
open import Instantiation
module SyntaxMap where
open Signature
open Expression
open Equality
infix 5 _→ᵐ_
-- syntax map
_→ᵐ_ : Signature → Signature → Set
𝕊 →ᵐ 𝕋 = ∀ {cl} (S : symb 𝕊 cl) → Expr 𝕋 (obj cl) (symb-arg 𝕊 S) 𝟘
-- equality of syntax maps
infix 4 _≈ᵐ_
_≈ᵐ_ : ∀ {𝕊 𝕋} (f g : 𝕊 →ᵐ 𝕋) → Set
_≈ᵐ_ {𝕊 = 𝕊} {𝕋 = 𝕋} f g =
∀ {cl} (S : symb 𝕊 cl) → f S ≈ g S
-- equality is an equivalence relation
≈ᵐ-refl : ∀ {𝕊 𝕋} {f : 𝕊 →ᵐ 𝕋} → f ≈ᵐ f
≈ᵐ-refl {𝕋 = 𝕋} S = ≈-refl
≈ᵐ-sym : ∀ {𝕊 𝕋} {f g : 𝕊 →ᵐ 𝕋} → f ≈ᵐ g → g ≈ᵐ f
≈ᵐ-sym {𝕋 = 𝕋} ξ S = ≈-sym (ξ S)
≈ᵐ-trans : ∀ {𝕊 𝕋} {f g h : 𝕊 →ᵐ 𝕋} → f ≈ᵐ g → g ≈ᵐ h → f ≈ᵐ h
≈ᵐ-trans {𝕋 = 𝕋} ζ ξ S = ≈-trans (ζ S) (ξ S)
-- The identity raw syntax map
𝟙ᵐ : ∀ {𝕊} → (𝕊 →ᵐ 𝕊)
𝟙ᵐ {𝕊} S = expr-symb S (expr-meta-generic 𝕊)
-- Action of a raw syntax map
infixr 10 [_]ᵐ_
[_]ᵐ_ : ∀ {𝕊 𝕋} → (𝕊 →ᵐ 𝕋) → ∀ {cl 𝕄 γ} → Expr 𝕊 𝕄 cl γ → Expr 𝕋 𝕄 cl γ
[ f ]ᵐ (expr-var x) = expr-var x
[_]ᵐ_ {𝕋 = 𝕋} f {𝕄 = 𝕄} (expr-symb S es) =
[ (λ M → [ f ]ᵐ es M) ]ⁱ ([ 𝟘-initial ]ʳ f S)
[ f ]ᵐ (expr-meta M ts) = expr-meta M (λ i → [ f ]ᵐ (ts i))
[ f ]ᵐ expr-eqty = expr-eqty
[ f ]ᵐ expr-eqtm = expr-eqtm
-- Action preserves equality
[]ᵐ-resp-≈ : ∀ {𝕊 𝕋} {cl 𝕄 γ} (f : 𝕊 →ᵐ 𝕋) {t u : Expr 𝕊 𝕄 cl γ} →
t ≈ u → [ f ]ᵐ t ≈ [ f ]ᵐ u
[]ᵐ-resp-≈ f (≈-≡ ξ) = ≈-≡ (cong ([ f ]ᵐ_) ξ)
[]ᵐ-resp-≈ {𝕋 = 𝕋} f (≈-symb {S = S} ξ) =
[]ⁱ-resp-≈ⁱ ([ 𝟘-initial ]ʳ f S) λ M → []ᵐ-resp-≈ f (ξ M)
[]ᵐ-resp-≈ f (≈-meta ξ) = ≈-meta (λ i → []ᵐ-resp-≈ f (ξ i))
[]ᵐ-resp-≈ᵐ : ∀ {𝕊 𝕋} {cl 𝕄 γ} {f g : 𝕊 →ᵐ 𝕋} (t : Expr 𝕊 𝕄 cl γ) →
f ≈ᵐ g → [ f ]ᵐ t ≈ [ g ]ᵐ t
[]ᵐ-resp-≈ᵐ (expr-var x) ξ = ≈-refl
[]ᵐ-resp-≈ᵐ {f = f} {g = g} (expr-symb S es) ξ =
[]ⁱ-resp-≈ⁱ-≈ {I = λ M → [ f ]ᵐ es M} {J = λ M → [ g ]ᵐ es M}
(λ M → []ᵐ-resp-≈ᵐ (es M) ξ)
([]ʳ-resp-≈ 𝟘-initial (ξ S))
[]ᵐ-resp-≈ᵐ (expr-meta M ts) ξ = ≈-meta (λ i → []ᵐ-resp-≈ᵐ (ts i) ξ)
[]ᵐ-resp-≈ᵐ expr-eqty ξ = ≈-eqty
[]ᵐ-resp-≈ᵐ expr-eqtm ξ = ≈-eqtm
[]ᵐ-resp-≈ᵐ-≈ : ∀ {𝕊 𝕋} {cl 𝕄 γ} {f g : 𝕊 →ᵐ 𝕋} {t u : Expr 𝕊 𝕄 cl γ} →
f ≈ᵐ g → t ≈ u → [ f ]ᵐ t ≈ [ g ]ᵐ u
[]ᵐ-resp-≈ᵐ-≈ {g = g} {t = t} ζ ξ = ≈-trans ([]ᵐ-resp-≈ᵐ t ζ) ([]ᵐ-resp-≈ g ξ)
-- Composition of raw syntax maps
infixl 7 _∘ᵐ_
_∘ᵐ_ : ∀ {𝕊 𝕋 𝕌} → (𝕋 →ᵐ 𝕌) → (𝕊 →ᵐ 𝕋) → (𝕊 →ᵐ 𝕌)
(g ∘ᵐ f) S = [ g ]ᵐ (f S)
-- Action preserves identity
module _ {𝕊} where
open Equality
open Renaming
open Substitution
[𝟙ᵐ] : ∀ {cl 𝕄 γ} (t : Expr 𝕊 cl 𝕄 γ) → [ 𝟙ᵐ ]ᵐ t ≈ t
[𝟙ᵐ] (expr-var x) = ≈-refl
[𝟙ᵐ] (expr-symb S es) =
≈-symb (λ {cⁱ γⁱ} i → [𝟙ᵐ]-arg cⁱ γⁱ i)
where [𝟙ᵐ]-arg : ∀ cⁱ γⁱ (i : [ cⁱ , γⁱ ]∈ symb-arg 𝕊 S) → _
[𝟙ᵐ]-arg (obj x) γⁱ i =
≈-trans
([]ˢ-resp-≈ _ ([]ʳ-resp-≈ _ ([𝟙ᵐ] (es i))))
(≈-trans (≈-sym ([ˢ∘ʳ] (es i))) ([]ˢ-id (λ { (var-left _) → ≈-refl ; (var-right _) → ≈-refl })))
[𝟙ᵐ]-arg EqTy γⁱ i = ≈-eqty
[𝟙ᵐ]-arg EqTm γⁱ i = ≈-eqtm
[𝟙ᵐ] (expr-meta M ts) = ≈-meta λ i → [𝟙ᵐ] (ts i)
[𝟙ᵐ] expr-eqty = ≈-eqty
[𝟙ᵐ] expr-eqtm = ≈-eqtm
-- interaction of maps with instantiation and substitution
module _ {𝕊 𝕋} where
open Substitution
infixl 7 _ᵐ∘ˢ_
_ᵐ∘ˢ_ : ∀ {𝕊 𝕋} {𝕄 γ δ} (f : 𝕊 →ᵐ 𝕋) (σ : 𝕊 % 𝕄 ∥ γ →ˢ δ) → (𝕋 % 𝕄 ∥ γ →ˢ δ)
(f ᵐ∘ˢ σ) x = [ f ]ᵐ σ x
[]ᵐ-[]ʳ : ∀ {f : 𝕊 →ᵐ 𝕋} {cl 𝕄 γ δ} {ρ : γ →ʳ δ} (t : Expr 𝕊 cl 𝕄 γ) →
([ f ]ᵐ ([ ρ ]ʳ t)) ≈ ([ ρ ]ʳ [ f ]ᵐ t)
[]ᵐ-[]ʳ (expr-var x) = ≈-refl
[]ᵐ-[]ʳ {f = f} {ρ = ρ} (expr-symb S es) =
≈-trans
([]ⁱ-resp-≈ⁱ ([ 𝟘-initial ]ʳ f S) λ M → []ᵐ-[]ʳ (es M))
(≈-trans
([]ⁱ-resp-≈ⁱ-≈
{t = [ 𝟘-initial ]ʳ f S}
{u = [ ρ ]ʳ ([ 𝟘-initial ]ʳ f S)}
(λ M → ≈-refl)
(≈-trans ([]ʳ-resp-≡ʳ (f S) (λ {()})) ([∘ʳ] (f S))))
(≈-sym ([ʳ∘ⁱ] ([ 𝟘-initial ]ʳ f S))))
[]ᵐ-[]ʳ (expr-meta M ts) = ≈-meta (λ i → []ᵐ-[]ʳ (ts i))
[]ᵐ-[]ʳ expr-eqty = ≈-eqty
[]ᵐ-[]ʳ expr-eqtm = ≈-eqtm
[]ᵐ-[]ˢ : ∀ {cl 𝕄 γ δ} {f : 𝕊 →ᵐ 𝕋} {σ : 𝕊 % 𝕄 ∥ γ →ˢ δ} (t : Expr 𝕊 cl 𝕄 γ) →
[ f ]ᵐ ([ σ ]ˢ t) ≈ [ f ᵐ∘ˢ σ ]ˢ [ f ]ᵐ t
[]ᵐ-[]ˢ (expr-var x) = ≈-refl
[]ᵐ-[]ˢ {f = f} {σ = σ} (expr-symb S es) =
≈-trans
([]ⁱ-resp-≈ⁱ ([ 𝟘-initial ]ʳ f S) (λ M → []ᵐ-[]ˢ (es M)))
(≈-trans
([]ⁱ-resp-≈ⁱ
([ 𝟘-initial ]ʳ f S)
(λ M → []ˢ-resp-≈ˢ
(λ { (var-left x) → []ᵐ-[]ʳ (σ x)
; (var-right _) → ≈-refl})
([ f ]ᵐ es M)))
(≈-sym ([]ˢ-[]ⁱ {ρ = 𝟘-initial} (f S) λ {()})))
[]ᵐ-[]ˢ (expr-meta M ts) = ≈-meta (λ i → []ᵐ-[]ˢ (ts i))
[]ᵐ-[]ˢ expr-eqty = ≈-eqty
[]ᵐ-[]ˢ expr-eqtm = ≈-eqtm
infixl 7 _ᵐ∘ⁱ_
_ᵐ∘ⁱ_ : ∀ {𝕂 𝕄 γ} (f : 𝕊 →ᵐ 𝕋) (I : 𝕊 % 𝕂 →ⁱ 𝕄 ∥ γ) → 𝕋 % 𝕂 →ⁱ 𝕄 ∥ γ
(f ᵐ∘ⁱ I) M = [ f ]ᵐ I M
⇑ⁱ-resp-ᵐ∘ⁱ : ∀ {𝕂 𝕄 γ δ} {f : 𝕊 →ᵐ 𝕋} {I : 𝕊 % 𝕂 →ⁱ 𝕄 ∥ γ} →
⇑ⁱ {δ = δ} (f ᵐ∘ⁱ I) ≈ⁱ f ᵐ∘ⁱ ⇑ⁱ I
⇑ⁱ-resp-ᵐ∘ⁱ {I = I} M = ≈-sym ([]ᵐ-[]ʳ (I M))
[]ᵐ-[]ⁱ : ∀ {cl 𝕂 𝕄 γ} {f : 𝕊 →ᵐ 𝕋} {I : 𝕊 % 𝕂 →ⁱ 𝕄 ∥ γ} (t : Expr 𝕊 cl 𝕂 γ) →
[ f ]ᵐ ([ I ]ⁱ t) ≈ [ f ᵐ∘ⁱ I ]ⁱ [ f ]ᵐ t
[]ᵐ-[]ⁱ (expr-var x) = ≈-refl
[]ᵐ-[]ⁱ {f = f} {I = I} (expr-symb S es) =
≈-trans
([]ⁱ-resp-≈ⁱ
([ 𝟘-initial ]ʳ f S)
λ M → ≈-trans
([]ᵐ-[]ⁱ (es M))
([]ⁱ-resp-≈ⁱ ([ f ]ᵐ es M) (≈ⁱ-sym (⇑ⁱ-resp-ᵐ∘ⁱ {I = I}))))
([∘ⁱ] ([ 𝟘-initial ]ʳ f S))
[]ᵐ-[]ⁱ {f = f} {I = I} (expr-meta M ts) =
≈-trans
([]ᵐ-[]ˢ (I M))
([]ˢ-resp-≈ˢ (λ { (var-left _) → ≈-refl ; (var-right x) → []ᵐ-[]ⁱ (ts x)}) ([ f ]ᵐ I M))
[]ᵐ-[]ⁱ expr-eqty = ≈-eqty
[]ᵐ-[]ⁱ expr-eqtm = ≈-eqtm
-- idenity is right-neutral
[]ᵐ-meta-generic : ∀ {𝕊 𝕋} {𝕄 γ} {f : 𝕊 →ᵐ 𝕋} {clᴹ γᴹ} {M : [ clᴹ , γᴹ ]∈ 𝕄} →
[ f ]ᵐ (expr-meta-generic 𝕊 {γ = γ} M) ≈ expr-meta-generic 𝕋 M
[]ᵐ-meta-generic {clᴹ = obj _} = ≈-refl
[]ᵐ-meta-generic {clᴹ = EqTy} = ≈-eqty
[]ᵐ-meta-generic {clᴹ = EqTm} = ≈-eqtm
𝟙ᵐ-right : ∀ {𝕊 𝕋} {f : 𝕊 →ᵐ 𝕋} → f ∘ᵐ 𝟙ᵐ ≈ᵐ f
𝟙ᵐ-right {f = f} S =
≈-trans
([]ⁱ-resp-≈ⁱ ([ 𝟘-initial ]ʳ (f S)) λ M → []ᵐ-meta-generic {M = M})
(≈-trans ([𝟙ⁱ] ([ 𝟘-initial ]ʳ f S)) ([]ʳ-id (λ { ()})))
-- Action preserves composition
module _ {𝕊 𝕋 𝕌} where
[∘ᵐ] : ∀ {f : 𝕊 →ᵐ 𝕋} {g : 𝕋 →ᵐ 𝕌} {cl 𝕄 γ} (t : Expr 𝕊 cl 𝕄 γ) → [ g ∘ᵐ f ]ᵐ t ≈ [ g ]ᵐ [ f ]ᵐ t
[∘ᵐ] (expr-var x) = ≈-refl
[∘ᵐ] {f = f} {g = g} (expr-symb S es) =
≈-trans
([]ⁱ-resp-≈ⁱ-≈ (λ M → [∘ᵐ] (es M)) (≈-sym ([]ᵐ-[]ʳ (f S))))
(≈-sym ([]ᵐ-[]ⁱ ([ 𝟘-initial ]ʳ f S)))
[∘ᵐ] (expr-meta M ts) = ≈-meta (λ i → [∘ᵐ] (ts i))
[∘ᵐ] expr-eqty = ≈-eqty
[∘ᵐ] expr-eqtm = ≈-eqtm
-- Associativity of composition
assocᵐ : ∀ {𝕊 𝕋 𝕌 𝕍} {f : 𝕊 →ᵐ 𝕋} {g : 𝕋 →ᵐ 𝕌} {h : 𝕌 →ᵐ 𝕍} →
(h ∘ᵐ g) ∘ᵐ f ≈ᵐ h ∘ᵐ (g ∘ᵐ f)
assocᵐ {f = f} S = [∘ᵐ] (f S)
-- The category of signatures and syntax maps
module _ where
open Categories.Category
SyntaxMaps : Category (suc zero) zero zero
SyntaxMaps =
record
{ Obj = Signature
; _⇒_ = _→ᵐ_
; _≈_ = _≈ᵐ_
; id = 𝟙ᵐ
; _∘_ = _∘ᵐ_
; assoc = λ {_} {_} {_} {_} {f} {_} {_} {_} S → [∘ᵐ] (f S)
; sym-assoc = λ {_} {_} {_} {𝕍} {f} {_} {_} {_} S → ≈-sym ([∘ᵐ] (f S))
; identityˡ = λ S → [𝟙ᵐ] _
; identityʳ = λ {_} {_} {f} {_} → 𝟙ᵐ-right {f = f}
; identity² = λ _ → [𝟙ᵐ] _
; equiv = record { refl = λ _ → ≈-refl ; sym = ≈ᵐ-sym ; trans = ≈ᵐ-trans }
; ∘-resp-≈ = λ ζ ξ S → []ᵐ-resp-≈ᵐ-≈ ζ (ξ S)
}
| 33.685106
| 114
| 0.41334
|
d0b74f91299c53bfac300cabd6fc521a21172e82
| 112
|
agda
|
Agda
|
papers/unraveling-recursion/code/src/Type.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 1,299
|
2018-10-02T13:41:39.000Z
|
2022-03-28T01:10:02.000Z
|
papers/unraveling-recursion/code/src/Type.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 2,493
|
2018-09-28T19:28:17.000Z
|
2022-03-31T15:31:31.000Z
|
papers/unraveling-recursion/code/src/Type.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 399
|
2018-10-05T09:36:10.000Z
|
2022-03-31T11:18:25.000Z
|
module Type where
open import Type.Core public
open import Type.NbE public
open import Type.Lemmas public
| 18.666667
| 30
| 0.785714
|
0e8c5cd932f5bfaa7d51e7e2351899e93bffb61c
| 1,228
|
agda
|
Agda
|
Cubical/Data/Prod/Base.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Data/Prod/Base.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
Cubical/Data/Prod/Base.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Prod.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
-- Here we define an inductive version of the product type, see below
-- for its uses.
-- See `Cubical.Data.Sigma` for `_×_` defined as a special case of
-- sigma types, which is the generally preferred one.
-- If × is defined using Σ then transp/hcomp will be compute
-- "negatively", that is, they won't reduce unless we project out the
-- first of second component. This is not always what we want so this
-- implementation is done using a datatype which computes positively.
private
variable
ℓ ℓ' : Level
data _×_ (A : Type ℓ) (B : Type ℓ') : Type (ℓ-max ℓ ℓ') where
_,_ : A → B → A × B
infixr 5 _×_
proj₁ : {A : Type ℓ} {B : Type ℓ'} → A × B → A
proj₁ (x , _) = x
proj₂ : {A : Type ℓ} {B : Type ℓ'} → A × B → B
proj₂ (_ , x) = x
private
variable
A : Type ℓ
B C : A → Type ℓ
intro : (∀ a → B a) → (∀ a → C a) → ∀ a → B a × C a
intro f g a = f a , g a
map : {B : Type ℓ} {D : B → Type ℓ'}
→ (∀ a → C a) → (∀ b → D b) → (x : A × B) → C (proj₁ x) × D (proj₂ x)
map f g = intro (f ∘ proj₁) (g ∘ proj₂)
| 25.583333
| 72
| 0.612378
|
0eb14ac353548178662986188b4124fbfa3bd01e
| 484
|
agda
|
Agda
|
OutsideIn/TopLevel.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | 2
|
2015-09-14T05:22:15.000Z
|
2020-11-19T14:30:07.000Z
|
OutsideIn/TopLevel.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | null | null | null |
OutsideIn/TopLevel.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | null | null | null |
open import OutsideIn.Prelude
open import OutsideIn.X
module OutsideIn.TopLevel(x : X) where
import OutsideIn.Expressions as E
open E(x)
open X(x)
data Program (ev : Set)(tv : Set) : Set where
end : Program ev tv
bind₁_,_ : ∀ {s} → Expression ev tv s → Program (Ⓢ ev) tv → Program ev tv
bind₂_·_∷_⇒_,_ : ∀ {s} → (n : ℕ) → Expression ev (tv ⨁ n) s
→ QConstraint (tv ⨁ n) → Type (tv ⨁ n)
→ Program (Ⓢ ev) tv → Program ev tv
| 34.571429
| 77
| 0.572314
|
4a7b5dfce4c7b1560fd21ec55ad7b002c11bde29
| 3,284
|
agda
|
Agda
|
src/Const.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Const.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Const.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some properties related to the const function
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Const
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Logical-equivalence using (_⇔_)
open import Prelude
import Bijection eq as Bijection
open Derived-definitions-and-properties eq
open import Embedding eq
open import Equivalence eq as Eq using (_≃_)
open import Fin eq
open import Function-universe eq
open import H-level eq
open import H-level.Closure eq
open import Injection eq using (Injective)
import Nat eq as Nat
open import Univalence-axiom eq
-- If A is inhabited, then the function const : B → (A → B) is
-- injective.
const-is-injective :
∀ {a b} →
{A : Type a} {B : Type b} →
A → Injective {B = A → B} const
const-is-injective x {y} {z} =
const y ≡ const z ↝⟨ cong (_$ x) ⟩□
y ≡ z □
-- Thus, if B is a set, then const is also an embedding (assuming
-- extensionality).
const-is-embedding :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} →
Is-set B →
A → Is-embedding {B = A → B} const
const-is-embedding {a} {b} ext B-set x =
_≃_.to (Injective≃Is-embedding
ext B-set
(Π-closure (lower-extensionality b a ext) 2 λ _ →
B-set)
const)
(const-is-injective x)
-- However, if B is not a set, then one can construct a counterexample
-- (assuming extensionality and univalence).
--
-- This example is due to Thierry Coquand. (His proof was not
-- identical to the one below.)
const-is-not-embedding :
∀ {a b} →
Extensionality (a ⊔ b) (lsuc b) →
Univalence b →
Univalence (# 0) →
¬ ({A : Type a} {B : Type (lsuc b)} →
A → Is-embedding {B = A → B} const)
const-is-not-embedding {a} {b} ext univ univ₀ hyp =
from-⊎ (2 Nat.≟ 4) 2≡4
where
ext-b : Extensionality b b
ext-b = lower-extensionality a (lsuc b) ext
ext-ab₊ : Extensionality a (lsuc b)
ext-ab₊ = lower-extensionality b lzero ext
ext₁ : Extensionality (# 0) (# 1)
ext₁ = lower-extensionality _ (lsuc b) ext
ext₀ : Extensionality (# 0) (# 0)
ext₀ = lower-extensionality _ _ ext
emb : Is-embedding {B = ↑ a (Fin 2) → Type b} const
emb = hyp (lift true)
2≡4 : 2 ≡ 4
2≡4 = _⇔_.to isomorphic-same-size (
Fin 2 ↝⟨ inverse $ [Fin≡Fin]↔Fin! ext₀ univ₀ 2 ⟩
Fin 2 ≡ Fin 2 ↔⟨ inverse $ ≡-preserves-≃ ext-b univ univ₀ (Eq.↔⇒≃ Bijection.↑↔) (Eq.↔⇒≃ Bijection.↑↔) ⟩
↑ b (Fin 2) ≡ ↑ b (Fin 2) ↔⟨ Eq.⟨ _ , emb (↑ b (Fin 2)) (↑ b (Fin 2)) ⟩ ⟩
const (↑ b (Fin 2)) ≡ const (↑ b (Fin 2)) ↔⟨ inverse $ Eq.extensionality-isomorphism ext-ab₊ ⟩
(↑ a (Fin 2) → ↑ b (Fin 2) ≡ ↑ b (Fin 2)) ↔⟨ →-cong ext-ab₊ (Eq.↔⇒≃ Bijection.↑↔)
(≡-preserves-≃ ext-b univ univ₀ (Eq.↔⇒≃ Bijection.↑↔) (Eq.↔⇒≃ Bijection.↑↔)) ⟩
(Fin 2 → Fin 2 ≡ Fin 2) ↝⟨ ∀-cong ext₁ (λ _ → [Fin≡Fin]↔Fin! ext₀ univ₀ 2) ⟩
(Fin 2 → Fin 2) ↝⟨ [Fin→Fin]↔Fin^ ext₀ 2 2 ⟩□
Fin 4 □)
| 33.85567
| 136
| 0.53715
|
5001f7fd3970ecd535630486444afe464e9bdad7
| 628
|
agda
|
Agda
|
notes/papers/implicit/examples/Loop.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
notes/papers/implicit/examples/Loop.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
notes/papers/implicit/examples/Loop.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Loop where
{-
data _=>_ (A, B : Set) : Set where
lam : (A -> B) -> A => B
app : {A, B : Set} -> (A => B) -> A -> B
app (lam f) = f
delta = lam (\x -> app x x)
loop = app delta delta
-}
lam : (A, B : Set) -> (A -> B) -> A -> B
lam A B f = f
app : (A, B : Set) -> (A -> B) -> A -> B
app A B f = f
postulate Nat : Set
zero : Nat
wrap : (F : Nat -> Set) -> F zero -> F zero
wrap F x = x
delta : (Nat -> Nat) -> Nat
delta = \x -> x (wrap _ x)
loop : Nat
loop = delta (wrap _ delta)
-- delta : _ -> _
-- delta = \x -> app _ _ x x -- lam _ _ (\x -> app _ _ x x)
--
-- loop = app _ _ delta (wrap _ delta)
| 16.526316
| 59
| 0.461783
|
4aed98737d2fd903b59c1c48c0f76673612034b3
| 19,149
|
agda
|
Agda
|
LibraBFT/Yasm/System.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Yasm/System.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Yasm/System.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Base as LYB
-- This module defines a model of a distributed system, parameterized by
-- SystemParameters, which establishes various application-dependent types,
-- handlers, etc. The model supports a set of peers executing handlers in
-- response to messages received; these handlers can update the peer's
-- local state and/or send additional messages. The model also enables
-- "cheat" steps, which can send arbitrary messages, except that they are
-- constrained to prevent a cheat step from introducing a new signature for
-- an "honest" public key. The module also contains some structures for
-- proving properties of executions of the modeled system.
module LibraBFT.Yasm.System
(ℓ-EC : Level)
(EpochConfig : Set ℓ-EC)
(epochId : EpochConfig → EpochId)
(authorsN : EpochConfig → ℕ)
(parms : LYB.SystemParameters ℓ-EC EpochConfig epochId authorsN)
where
data InitStatus : Set where
uninitd : InitStatus
initd : InitStatus
open import LibraBFT.Yasm.Base ℓ-EC EpochConfig epochId authorsN
open SystemParameters parms
open import LibraBFT.Yasm.AvailableEpochs PeerId ℓ-EC EpochConfig epochId authorsN
using (AvailableEpochs) renaming (lookup'' to EC-lookup)
import LibraBFT.Yasm.AvailableEpochs PeerId ℓ-EC EpochConfig epochId authorsN as AE
open import Util.FunctionOverride PeerId _≟PeerId_
open import LibraBFT.Base.PKCS
SenderMsgPair : Set
SenderMsgPair = PeerId × Msg
SentMessages : Set
SentMessages = List SenderMsgPair
-- The model supports sending messages that contain some fields that are
-- /not/ covered by the message's signature. Therefore, given a message
-- with a verifiable signature, it is possible for a propositionally
-- different message that verifies against the same signature to have been
-- sent before, which is captured by the following definition.
record MsgWithSig∈ (pk : PK)(sig : Signature)(pool : SentMessages) : Set where
constructor mkMsgWithSig∈
field
msgWhole : Msg
msgPart : Part
msg⊆ : msgPart ⊂Msg msgWhole
msgSender : PeerId
msg∈pool : (msgSender , msgWhole) ∈ pool
msgSigned : WithVerSig pk msgPart
msgSameSig : ver-signature msgSigned ≡ sig
open MsgWithSig∈ public
postulate -- TODO-1: prove it
MsgWithSig∈? : ∀ {pk} {sig} {pool} → Dec (MsgWithSig∈ pk sig pool)
MsgWithSig∈-++ʳ : ∀{pk sig pool ms} → MsgWithSig∈ pk sig pool → MsgWithSig∈ pk sig (ms ++ pool)
MsgWithSig∈-++ʳ {ms = pre} msig = record
{ msgWhole = msgWhole msig
; msgPart = msgPart msig
; msg⊆ = msg⊆ msig
; msg∈pool = Any-++ʳ pre (msg∈pool msig)
; msgSigned = msgSigned msig
; msgSameSig = msgSameSig msig
}
MsgWithSig∈-++ˡ : ∀{pk sig pool ms} → MsgWithSig∈ pk sig ms → MsgWithSig∈ pk sig (ms ++ pool)
MsgWithSig∈-++ˡ {ms = pre} msig = record
{ msgWhole = msgWhole msig
; msgPart = msgPart msig
; msg⊆ = msg⊆ msig
; msg∈pool = Any-++ˡ (msg∈pool msig)
; msgSigned = msgSigned msig
; msgSameSig = msgSameSig msig
}
MsgWithSig∈-transp : ∀{pk sig pool pool'}
→ (mws : MsgWithSig∈ pk sig pool)
→ (msgSender mws , msgWhole mws) ∈ pool'
→ MsgWithSig∈ pk sig pool'
MsgWithSig∈-transp msig ∈pool' = record
{ msgWhole = msgWhole msig
; msgPart = msgPart msig
; msg⊆ = msg⊆ msig
; msg∈pool = ∈pool'
; msgSigned = msgSigned msig
; msgSameSig = msgSameSig msig
}
-- * Forbidding the Forging of Signatures
--
-- Whenever our reasoning must involve digital signatures, it is standard
-- to talk about EUF-CMA resistant signature schemes. Informally, this captures
-- signatures schemes that cannot be compromised by certain adversaries.
-- Formally, it means that for any probabilistic-polynomial-time adversary 𝓐,
-- and some security parameter k:
--
-- Pr[ EUF-CMA(k) ] ≤ ε(k) for ε a negigible function.
--
-- EUF-CMA is defined as:
--
-- EUF-CMA(k): | O(m):
-- L ← ∅ | σ ← Sign(sk , m)
-- (pk, sk) ← Gen(k) | L ← L ∪ { m }
-- (m , σ) ← 𝓐ᴼ(pk) | return σ
-- return (Verify(pk, m, σ) ∧ m ∉ L) |
--
-- This says that 𝓐 cannot create a message that has /not yet been signed/ and
-- forge a signature for it. The list 'L' keeps track of the messages that 𝓐
-- asked to be signed by the oracle.
--
-- Because the probability of the adversary to win the EUF-CMA(k) game
-- approaches 0 as k increases; it is reasonable to assume that winning
-- the game is /impossible/ for realistic security parameters.
--
-- EUF-CMA security is incorporated into our model by constraining messages
-- sent by a cheat step to ensure that for every verifiably signed part of
-- such a message, if there is a signature on the part, then it is either for
-- a dishonest public key (in which cases it's secret key may have been leaked),
-- or a message has been sent with the same signature before (in which case the
-- signature is simply being "replayed" from a previous message).
--
-- Dishonest (or "cheat") messages are those that are not the result of
-- a /handle/ or /init/ call, but rather are the result of a /cheat/ step.
--
-- A part of a cheat message can contain a verifiable signature only if it
-- is for a dishonest public key, or a message with the same signature has
-- been sent before (a cheater can "reuse" an honest signature sent
-- before; it just can't produce a new one). Note that this constraint
-- precludes a peer sending a message that contains a new verifiable
-- signature for an honest PK, even if the PK is the peer's own PK for
-- some epoch (implying that the peer possesses the associated secret
-- key). In other words, a peer that is honest for a given epoch (by
-- virtue of being a member of that epoch and being assigned an honest PK
-- for the epoch), cannot send a message for that epoch using a cheat
-- step.
CheatPartConstraint : SentMessages → Part → Set
CheatPartConstraint pool m = ∀{pk} → (ver : WithVerSig pk m)
→ Meta-Dishonest-PK pk
⊎ MsgWithSig∈ pk (ver-signature ver) pool
-- The only constraints on messages sent by cheat steps are that:
-- * the sender is not an honest member in the epoch of any part of the message
-- * the signature on any part of the message satisfies CheatCanSign, meaning
-- that it is not a new signature for an honest public key
CheatMsgConstraint : SentMessages → Msg → Set
CheatMsgConstraint pool m = ∀{part} → part ⊂Msg m → CheatPartConstraint pool part
-- * The System State
--
-- A system consists in a partial map from PeerId to PeerState, a pool
-- of sent messages and a number of available epochs.
record SystemState (e : ℕ) : Set ℓ-EC where
field
peerStates : PeerId → PeerState
initialised : PeerId → InitStatus
msgPool : SentMessages -- All messages ever sent
availEpochs : AvailableEpochs e
open SystemState public
initialState : SystemState 0
initialState = record
{ peerStates = const initPS
; initialised = const uninitd
; msgPool = []
; availEpochs = []
}
-- Convenience function for appending an epoch to the system state
pushEpoch : ∀{e} → EpochConfigFor e → SystemState e → SystemState (suc e)
pushEpoch 𝓔 st = record
{ peerStates = peerStates st
; initialised = initialised st
; msgPool = msgPool st
; availEpochs = AE.append 𝓔 (availEpochs st)
}
-- * Small Step Semantics
--
-- The small step semantics are divided into three datatypes:
--
-- i) StepPeerState executes a step through init or handle
-- ii) StepPeer executes a step through StepPeerState or cheat
-- iii) Step transitions the system state by a StepPeer or by
-- bringing a new epoch into existence
-- The pre and post states of Honest peers are related iff
data StepPeerState {e}(pid : PeerId)(𝓔s : AvailableEpochs e)(pool : SentMessages)
(peerInits : PeerId → InitStatus) (ps : PeerState) :
(PeerId → InitStatus) → (PeerState × List Msg) → Set where
-- The peer receives an "initialization package"; for now, this consists
-- of the actual EpochConfig for the epoch being initialized. Later, we
-- may move to a more general scheme, enabled by assuming a function
-- 'render : InitPackage -> EpochConfig'.
step-init : ∀ (ix : Fin e)
→ StepPeerState pid 𝓔s pool peerInits ps ⟦ peerInits , pid ← initd ⟧ (init pid (AE.lookup' 𝓔s ix) ps)
-- The peer processes a message in the pool
step-msg : ∀{m}
→ m ∈ pool
→ peerInits pid ≡ initd
→ StepPeerState pid 𝓔s pool peerInits ps peerInits (handle pid (proj₂ m) ps)
-- The pre-state of the suplied PeerId is related to the post-state and list of output messages iff:
data StepPeer {e}(pre : SystemState e) : PeerId → PeerState → List Msg → Set where
-- it can be obtained by a handle or init call.
step-honest : ∀{pid st outs init'}
→ StepPeerState pid (availEpochs pre) (msgPool pre) (initialised pre) (peerStates pre pid) init' (st , outs)
→ StepPeer pre pid st outs
-- or the peer decides to cheat. CheatMsgConstraint ensures it cannot
-- forge signatures by honest peers. Cheat steps do not modify peer
-- state: these are maintained exclusively by the implementation
-- handlers.
step-cheat : ∀{pid}
→ (fm : SentMessages → PeerState → Msg)
→ let m = fm (msgPool pre) (peerStates pre pid)
in CheatMsgConstraint (msgPool pre) m
→ StepPeer pre pid (peerStates pre pid) (m ∷ [])
isCheat : ∀ {e pre pid ms outs} → StepPeer {e} pre pid ms outs → Set
isCheat (step-honest _) = ⊥
isCheat (step-cheat _ _) = Unit
-- Computes the post-sysstate for a given step-peer.
StepPeer-post : ∀{e pid st' outs}{pre : SystemState e}
→ StepPeer pre pid st' outs → SystemState e
StepPeer-post {e} {pid} {st'} {outs} {pre} _ = record pre
{ peerStates = ⟦ peerStates pre , pid ← st' ⟧
; msgPool = List-map (pid ,_) outs ++ msgPool pre
}
StepPeer-post-lemma : ∀{e pid st' outs}{pre : SystemState e}
→ (pstep : StepPeer pre pid st' outs)
→ st' ≡ peerStates (StepPeer-post pstep) pid
StepPeer-post-lemma pstep = sym override-target-≡
cheatStepDNMPeerStates : ∀{e pid st' outs}{pre : SystemState e}
→ (theStep : StepPeer pre pid st' outs)
→ isCheat theStep
→ peerStates (StepPeer-post theStep) ≡ peerStates pre
cheatStepDNMPeerStates {pid = pid} {pre = pre} (step-cheat _ _) _
= overrideSameVal-correct-ext {f = peerStates pre} {pid}
cheatStepDNMPeerStates₁ : ∀{e pid pid' st' outs}{pre : SystemState e}
→ (theStep : StepPeer pre pid st' outs)
→ isCheat theStep
→ peerStates (StepPeer-post theStep) pid' ≡ peerStates pre pid'
cheatStepDNMPeerStates₁ {_} {pid} {pid'} (step-cheat fm x₁) x
= overrideSameVal-correct pid pid'
data Step : ∀{e e'} → SystemState e → SystemState e' → Set ℓ-EC where
step-epoch : ∀{e}{pre : SystemState e}
→ (𝓔 : EpochConfigFor e)
-- TODO-3: Eventually, we'll condition this step to only be
-- valid when peers on the previous epoch have agreed that 𝓔
-- is the new one. → ∃EnoughValidCommitMsgsFor pre 𝓔
→ Step pre (pushEpoch 𝓔 pre)
step-peer : ∀{e pid st' outs}{pre : SystemState e}
→ (pstep : StepPeer pre pid st' outs)
→ Step pre (StepPeer-post pstep)
msgs-stable : ∀ {e e'} {pre : SystemState e} {post : SystemState e'} {m}
→ (theStep : Step pre post)
→ m ∈ msgPool pre
→ m ∈ msgPool post
msgs-stable (step-epoch _) m∈ = m∈
msgs-stable (step-peer {pid = pid} {outs = outs} _) m∈ = Any-++ʳ (List-map (pid ,_) outs) m∈
peersRemainInitialized : ∀ {pid} {e e'} {pre : SystemState e} {post : SystemState e'}
→ (theStep : Step pre post)
→ initialised pre pid ≡ initd
→ initialised post pid ≡ initd
peersRemainInitialized (step-epoch _) isInitd = isInitd
peersRemainInitialized {pid} (step-peer step) isInitd
with step
... | step-cheat _ _ = isInitd
... | step-honest {pidS} {st} {outs} stp
with pid ≟PeerId pidS
...| yes refl = isInitd
...| no imp = isInitd
-- not used yet, but some proofs could probably be cleaned up using this,
-- e.g., prevVoteRnd≤-pred-step in Impl.VotesOnce
sendMessages-target : ∀ {m : SenderMsgPair} {sm : SentMessages} {ml : List SenderMsgPair}
→ ¬ (m ∈ sm)
→ m ∈ (ml ++ sm)
→ m ∈ ml
sendMessages-target {ml = ml} ¬m∈sm m∈++
with Any-++⁻ ml m∈++
...| inj₁ m∈ml = m∈ml
...| inj₂ m∈sm = ⊥-elim (¬m∈sm m∈sm)
step-epoch-does-not-send : ∀ {e} (pre : SystemState e) (𝓔 : EpochConfigFor e)
→ msgPool (pushEpoch 𝓔 pre) ≡ msgPool pre
step-epoch-does-not-send _ _ = refl
-- * Reflexive-Transitive Closure
data Step* : ∀{e e'} → SystemState e → SystemState e' → Set ℓ-EC where
step-0 : ∀{e}{pre : SystemState e}
→ Step* pre pre
step-s : ∀{e e' e''}{fst : SystemState e}{pre : SystemState e'}{post : SystemState e''}
→ Step* fst pre
→ Step pre post
→ Step* fst post
ReachableSystemState : ∀{e} → SystemState e → Set ℓ-EC
ReachableSystemState = Step* initialState
eventProcessorPostSt : ∀ {pid s' s outs init'} {e} {st : SystemState e}
→ (r : ReachableSystemState st)
→ (stP : StepPeerState pid (availEpochs st) (msgPool st) (initialised st)
(peerStates st pid) init' (s' , outs))
→ peerStates (StepPeer-post {pre = st} (step-honest stP)) pid ≡ s
→ s ≡ s'
eventProcessorPostSt _ _ ps≡s = trans (sym ps≡s) override-target-≡
Step*-mono : ∀{e e'}{st : SystemState e}{st' : SystemState e'}
→ Step* st st' → e ≤ e'
Step*-mono step-0 = ≤-refl
Step*-mono (step-s tr (step-peer _)) = Step*-mono tr
Step*-mono (step-s tr (step-epoch _)) = ≤-step (Step*-mono tr)
MsgWithSig∈-Step* : ∀{e e' sig pk}{st : SystemState e}{st' : SystemState e'}
→ Step* st st'
→ MsgWithSig∈ pk sig (msgPool st)
→ MsgWithSig∈ pk sig (msgPool st')
MsgWithSig∈-Step* step-0 msig = msig
MsgWithSig∈-Step* (step-s tr (step-epoch _)) msig
= MsgWithSig∈-Step* tr msig
MsgWithSig∈-Step* (step-s tr (step-peer ps)) msig
= MsgWithSig∈-++ʳ (MsgWithSig∈-Step* tr msig)
MsgWithSig∈-Step*-part : ∀{e e' sig pk}{st : SystemState e}{st' : SystemState e'}
→ (tr : Step* st st')
→ (msig : MsgWithSig∈ pk sig (msgPool st))
→ msgPart msig ≡ msgPart (MsgWithSig∈-Step* tr msig)
MsgWithSig∈-Step*-part step-0 msig = refl
MsgWithSig∈-Step*-part (step-s tr (step-epoch _)) msig
= MsgWithSig∈-Step*-part tr msig
MsgWithSig∈-Step*-part (step-s tr (step-peer ps)) msig
= MsgWithSig∈-Step*-part tr msig
MsgWithSig∈-Step*-sender : ∀{e e' sig pk}{st : SystemState e}{st' : SystemState e'}
→ (tr : Step* st st')
→ (msig : MsgWithSig∈ pk sig (msgPool st))
→ msgSender msig ≡ msgSender (MsgWithSig∈-Step* tr msig)
MsgWithSig∈-Step*-sender step-0 msig = refl
MsgWithSig∈-Step*-sender (step-s tr (step-epoch _)) msig
= MsgWithSig∈-Step*-sender tr msig
MsgWithSig∈-Step*-sender (step-s tr (step-peer ps)) msig
= MsgWithSig∈-Step*-sender tr msig
------------------------------------------
-- Type synonym to express a relation over system states;
SystemStateRel : (∀{e e'} → SystemState e → SystemState e' → Set ℓ-EC) → Set (ℓ+1 ℓ-EC)
SystemStateRel P = ∀{e e'}{st : SystemState e}{st' : SystemState e'} → P st st' → Set ℓ-EC
-- Just like Data.List.Any maps a predicate over elements to a predicate over lists,
-- Any-step maps a relation over steps to a relation over steps in a trace.
data Any-Step (P : SystemStateRel Step) : SystemStateRel Step* where
step-here : ∀{e e' e''}{fst : SystemState e}{pre : SystemState e'}{post : SystemState e''}
→ (cont : Step* fst pre)
→ {this : Step pre post}(prf : P this)
→ Any-Step P (step-s cont this)
step-there : ∀{e e' e''}{fst : SystemState e}{pre : SystemState e'}{post : SystemState e''}
→ {cont : Step* fst pre}
→ {this : Step pre post}
→ (prf : Any-Step P cont)
→ Any-Step P (step-s cont this)
Any-Step-⇒ : ∀ {P Q : SystemStateRel Step}
→ (∀ {e e'}{pre : SystemState e}{post : SystemState e'} → (x : Step pre post) → P {e} {e'} x → Q {e} {e'} x)
→ ∀ {e e' fst lst} {tr : Step* {e} {e'} fst lst}
→ Any-Step P tr
→ Any-Step Q tr
Any-Step-⇒ p⇒q (step-here cont {this} prf) = step-here cont (p⇒q this prf)
Any-Step-⇒ p⇒q (step-there anyStep) = step-there (Any-Step-⇒ p⇒q anyStep)
Any-Step-elim
: ∀{e₀ e₁}{st₀ : SystemState e₀}{st₁ : SystemState e₁}{P : SystemStateRel Step}{Q : Set ℓ-EC}
→ {r : Step* st₀ st₁}
→ (P⇒Q : ∀{d d'}{s : SystemState d}{s' : SystemState d'}{st : Step s s'}
→ P st → Step* s' st₁ → Q)
→ Any-Step P r → Q
Any-Step-elim P⇒Q (step-here cont prf)
= P⇒Q prf step-0
Any-Step-elim P⇒Q (step-there {this = this} f)
= Any-Step-elim (λ p s → P⇒Q p (step-s s this)) f
------------------------------------------
module _ (P : ∀{e} → SystemState e → Set) where
Step*-Step-fold : (∀{e}{st : SystemState e}
→ ReachableSystemState st
→ (𝓔 : EpochConfigFor e)
→ P st
→ P (pushEpoch 𝓔 st))
→ (∀{e pid st' outs}{st : SystemState e}
→ ReachableSystemState st
→ (pstep : StepPeer st pid st' outs)
→ P st
→ P (StepPeer-post pstep))
→ P initialState
→ ∀{e}{st : SystemState e}
→ (tr : ReachableSystemState st) → P st
Step*-Step-fold fe fs p₀ step-0 = p₀
Step*-Step-fold fe fs p₀ (step-s tr (step-epoch 𝓔)) = fe tr 𝓔 (Step*-Step-fold fe fs p₀ tr)
Step*-Step-fold fe fs p₀ (step-s tr (step-peer p)) = fs tr p (Step*-Step-fold fe fs p₀ tr)
| 44.636364
| 123
| 0.610998
|
fb84c22338e401385d3103d963258c82d7975884
| 5,594
|
agda
|
Agda
|
src/fot/FOTC/Program/GCD/Partial/DivisibleATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/GCD/Partial/DivisibleATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/GCD/Partial/DivisibleATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- The gcd is divisible by any common divisor
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.GCD.Partial.DivisibleATP where
open import FOTC.Base
open import FOTC.Base.PropertiesATP
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Divisibility.NotBy0
open import FOTC.Data.Nat.Divisibility.NotBy0.PropertiesATP
open import FOTC.Data.Nat.Induction.NonAcc.LexicographicATP
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesATP
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.PropertiesATP
open import FOTC.Program.GCD.Partial.Definitions
open import FOTC.Program.GCD.Partial.GCD
------------------------------------------------------------------------------
-- The gcd 0 (succ n) is Divisible.
postulate
gcd-0S-Divisible : ∀ {n} → N n → Divisible zero (succ₁ n) (gcd zero (succ₁ n))
{-# ATP prove gcd-0S-Divisible #-}
postulate
gcd-S0-Divisible : ∀ {n} → N n → Divisible (succ₁ n) zero (gcd (succ₁ n) zero)
{-# ATP prove gcd-S0-Divisible #-}
------------------------------------------------------------------------------
-- The gcd (succ₁ m) (succ₁ n) when succ₁ m > succ₁ n is Divisible.
-- For the proof using the ATP we added the helper hypothesis
-- c | succ₁ m → c | succ₁ c → c | succ₁ m ∸ succ₁ n.
postulate
gcd-S>S-Divisible-ah :
∀ {m n} → N m → N n →
(Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))) →
succ₁ m > succ₁ n →
∀ c → N c → CD (succ₁ m) (succ₁ n) c →
(c ∣ succ₁ m ∸ succ₁ n) →
c ∣ gcd (succ₁ m) (succ₁ n)
{-# ATP prove gcd-S>S-Divisible-ah #-}
gcd-S>S-Divisible :
∀ {m n} → N m → N n →
(Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))) →
succ₁ m > succ₁ n →
Divisible (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n))
gcd-S>S-Divisible {m} {n} Nm Nn acc Sm>Sn c Nc (c∣Sm , c∣Sn) =
gcd-S>S-Divisible-ah Nm Nn acc Sm>Sn c Nc (c∣Sm , c∣Sn)
(x∣y→x∣z→x∣y∸z Nc (nsucc Nm) (nsucc Nn) c∣Sm c∣Sn)
------------------------------------------------------------------------------
-- The gcd (succ₁ m) (succ₁ n) when succ₁ m ≯ succ₁ n is Divisible.
-- For the proof using the ATP we added the helper hypothesis
-- c | succ₁ n → c | succ₁ m → c | succ₁ n ∸ succ₁ m.
postulate
gcd-S≯S-Divisible-ah :
∀ {m n} → N m → N n →
(Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))) →
succ₁ m ≯ succ₁ n →
∀ c → N c → CD (succ₁ m) (succ₁ n) c →
(c ∣ succ₁ n ∸ succ₁ m) →
c ∣ gcd (succ₁ m) (succ₁ n)
{-# ATP prove gcd-S≯S-Divisible-ah #-}
gcd-S≯S-Divisible :
∀ {m n} → N m → N n →
(Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))) →
succ₁ m ≯ succ₁ n →
Divisible (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n))
gcd-S≯S-Divisible {m} {n} Nm Nn acc Sm≯Sn c Nc (c∣Sm , c∣Sn) =
gcd-S≯S-Divisible-ah Nm Nn acc Sm≯Sn c Nc (c∣Sm , c∣Sn)
(x∣y→x∣z→x∣y∸z Nc (nsucc Nn) (nsucc Nm) c∣Sn c∣Sm)
------------------------------------------------------------------------------
-- The gcd m n when m > n is Divisible.
gcd-x>y-Divisible :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → x≢0≢y o p →
Divisible o p (gcd o p)) →
m > n →
x≢0≢y m n →
Divisible m n (gcd m n)
gcd-x>y-Divisible nzero Nn _ 0>n _ _ _ = ⊥-elim (0>x→⊥ Nn 0>n)
gcd-x>y-Divisible (nsucc Nm) nzero _ _ _ c Nc = gcd-S0-Divisible Nm c Nc
gcd-x>y-Divisible (nsucc {m} Nm) (nsucc {n} Nn) ah Sm>Sn _ c Nc =
gcd-S>S-Divisible Nm Nn ih Sm>Sn c Nc
where
-- Inductive hypothesis.
ih : Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))
ih = ah {succ₁ m ∸ succ₁ n}
{succ₁ n}
(∸-N (nsucc Nm) (nsucc Nn))
(nsucc Nn)
([Sx∸Sy,Sy]<[Sx,Sy] Nm Nn)
(λ p → ⊥-elim (S≢0 (∧-proj₂ p)))
------------------------------------------------------------------------------
-- The gcd m n when m ≯ n is Divisible.
gcd-x≯y-Divisible :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → x≢0≢y o p →
Divisible o p (gcd o p)) →
m ≯ n →
x≢0≢y m n →
Divisible m n (gcd m n)
gcd-x≯y-Divisible nzero nzero _ _ h _ _ = ⊥-elim (h (refl , refl))
gcd-x≯y-Divisible nzero (nsucc Nn) _ _ _ c Nc = gcd-0S-Divisible Nn c Nc
gcd-x≯y-Divisible (nsucc _) nzero _ Sm≯0 _ _ _ = ⊥-elim (S≯0→⊥ Sm≯0)
gcd-x≯y-Divisible (nsucc {m} Nm) (nsucc {n} Nn) ah Sm≯Sn _ c Nc =
gcd-S≯S-Divisible Nm Nn ih Sm≯Sn c Nc
where
-- Inductive hypothesis.
ih : Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))
ih = ah {succ₁ m}
{succ₁ n ∸ succ₁ m}
(nsucc Nm)
(∸-N (nsucc Nn) (nsucc Nm))
([Sx,Sy∸Sx]<[Sx,Sy] Nm Nn)
(λ p → ⊥-elim (S≢0 (∧-proj₁ p)))
------------------------------------------------------------------------------
-- The gcd is Divisible.
gcdDivisible : ∀ {m n} → N m → N n → x≢0≢y m n → Divisible m n (gcd m n)
gcdDivisible = Lexi-wfind A h
where
A : D → D → Set
A i j = x≢0≢y i j → Divisible i j (gcd i j)
h : ∀ {i j} → N i → N j → (∀ {k l} → N k → N l → Lexi k l i j → A k l) →
A i j
h Ni Nj ah = case (gcd-x>y-Divisible Ni Nj ah)
(gcd-x≯y-Divisible Ni Nj ah)
(x>y∨x≯y Ni Nj)
| 39.673759
| 83
| 0.510011
|
df867fde78127db5d16213cab2089c4430147030
| 3,498
|
agda
|
Agda
|
04-cubical-type-theory/material/SolutionsSession2.agda
|
williamdemeo/EPIT-2020
|
19d72759e18e05d2c509f62d23a998573270140c
|
[
"MIT"
] | null | null | null |
04-cubical-type-theory/material/SolutionsSession2.agda
|
williamdemeo/EPIT-2020
|
19d72759e18e05d2c509f62d23a998573270140c
|
[
"MIT"
] | null | null | null |
04-cubical-type-theory/material/SolutionsSession2.agda
|
williamdemeo/EPIT-2020
|
19d72759e18e05d2c509f62d23a998573270140c
|
[
"MIT"
] | 1
|
2021-08-02T16:16:34.000Z
|
2021-08-02T16:16:34.000Z
|
-- Solutions to ExerciseSession2
{-# OPTIONS --cubical #-}
module SolutionsSession2 where
open import Part1
open import Part2
open import ExerciseSession1
-- Exercise 1
JEq : {x : A} (P : (z : A) → x ≡ z → Type ℓ'')
(d : P x refl) → J P d refl ≡ d
JEq P p d = transportRefl p d
-- Exercise 2
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b = sym (p a) ∙ p b
-- Exercise 3
isProp→isProp' : isProp A → isProp' A
isProp→isProp' p x y = p x y , isProp→isSet p _ _ (p x y)
-- Exercise 4
isContr→isContr≡ : isContr A → (x y : A) → isContr (x ≡ y)
isContr→isContr≡ h = isProp→isProp' (isContr→isProp h)
-- Exercise 5
fromPathP : {A : I → Type ℓ} {x : A i0} {y : A i1}
→ PathP A x y
→ transport (λ i → A i) x ≡ y
fromPathP {A = A} p i = transp (λ j → A (i ∨ j)) i (p i)
-- The converse is harder to prove so we give it:
toPathP : {A : I → Type ℓ} {x : A i0} {y : A i1}
→ transport (λ i → A i) x ≡ y
→ PathP A x y
toPathP {A = A} {x = x} p i =
hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
-- Exercise 6
Σ≡Prop : {B : A → Type ℓ'} {u v : Σ A B} (h : (x : A) → isProp (B x))
→ (p : fst u ≡ fst v) → u ≡ v
Σ≡Prop {B = B} {u = u} {v = v} h p =
ΣPathP (p , toPathP (h _ (transport (λ i → B (p i)) (snd u)) (snd v)))
-- Exercice 7 (thanks Loïc for the slick proof!)
isPropIsContr : isProp (isContr A)
isPropIsContr (c0 , h0) (c1 , h1) j =
h0 c1 j , λ y i → hcomp (λ k → λ { (i = i0) → h0 (h0 c1 j) k;
(i = i1) → h0 y k;
(j = i0) → h0 (h0 y i) k;
(j = i1) → h0 (h1 y i) k}) c0
-- Exercises about Part 3:
-- Exercise 8 (a bit longer, but very good):
open import Cubical.Data.Nat
open import Cubical.Data.Int hiding (addEq ; subEq)
-- Compose sucPathInt with itself n times. Transporting along this
-- will be addition, transporting with it backwards will be subtraction.
-- a) Define a path "addEq n" by composing sucPathInt with itself n
-- times.
addEq : ℕ → Int ≡ Int
addEq zero = refl
addEq (suc n) = (addEq n) ∙ sucPathInt
-- b) Define another path "subEq n" by composing "sym sucPathInt" with
-- itself n times.
subEq : ℕ → Int ≡ Int
subEq zero = refl
subEq (suc n) = (subEq n) ∙ sym sucPathInt
-- c) Define addition on integers by pattern-matching and transporting
-- along addEq/subEq appropriately.
_+Int_ : Int → Int → Int
m +Int pos n = transport (addEq n) m
m +Int negsuc n = transport (subEq (suc n)) m
-- d) Do some concrete computations using _+Int_ (this would not work
-- in HoTT as the transport would be stuck!)
-- Exercise 9: prove that hSet is not an hSet
open import Cubical.Data.Bool renaming (notEq to notPath)
open import Cubical.Data.Empty
-- Just define hSets of level 0 for simplicity
hSet : Type₁
hSet = Σ[ A ∈ Type₀ ] isSet A
-- Bool is an hSet
BoolSet : hSet
BoolSet = Bool , isSetBool
notPath≢refl : (notPath ≡ refl) → ⊥
notPath≢refl e = true≢false (transport (λ i → transport (e i) true ≡ false) refl)
¬isSet-hSet : isSet hSet → ⊥
¬isSet-hSet h = notPath≢refl (cong (cong fst) (h BoolSet BoolSet p refl))
where
p : BoolSet ≡ BoolSet
p = Σ≡Prop (λ A → isPropIsSet {A = A}) notPath
-- Exercise 10: squivalence between FinData and Fin
-- Thanks to Elies for the PR with the code. On the development
-- version of the library there is now:
--
-- open import Cubical.Data.Fin using (FinData≡Fin)
| 27.761905
| 81
| 0.598914
|
1c2e7a2ff9cba91efdaf88898ea32932c8d41a2b
| 15,406
|
agda
|
Agda
|
Cubical/Algebra/CommRing/FGIdeal.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/FGIdeal.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/FGIdeal.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-
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.Function
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.Sum hiding (map ; elim ; rec)
open import Cubical.Data.FinData hiding (elim ; rec)
open import Cubical.Data.Nat renaming ( zero to ℕzero ; suc to ℕsuc
; _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_
; +-assoc to +ℕ-assoc ; +-comm to +ℕ-comm
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
hiding (elim ; _choose_)
open import Cubical.Data.Nat.Order
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.CommRing.BinomialThm
open import Cubical.Algebra.Ring.QuotientRing
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.Matrix
private
variable
ℓ : Level
module _ (Ring@(R , str) : CommRing ℓ) where
infixr 5 _holds
_holds : hProp ℓ → Type ℓ
P holds = fst P
open CommRingStr str
open RingTheory (CommRing→Ring Ring)
open Sum (CommRing→Ring Ring)
linearCombination : {n : ℕ} → FinVec R n → FinVec R n → R
linearCombination α V = ∑ (λ i → α i · V i)
sumDist+ : ∀ {n : ℕ} (α β V : FinVec R n)
→ linearCombination (λ i → α i + β i) V ≡ linearCombination α V + linearCombination β V
sumDist+ α β V = ∑Ext (λ i → ·Ldist+ (α i) (β i) (V i)) ∙ ∑Split (λ i → α i · V i) (λ i → β i · V i)
dist- : ∀ {n : ℕ} (α V : FinVec R n)
→ linearCombination (λ i → - α i) V ≡ - linearCombination α V
dist- α V = ∑Ext (λ i → -DistL· (α i) (V i)) ∙ ∑Dist- (λ i → α i · V i)
dist0 : ∀ {n : ℕ} (V : FinVec R n)
→ linearCombination (replicateFinVec n 0r) V ≡ 0r
dist0 {n = n} V = ∑Ext (λ i → 0LeftAnnihilates (V i)) ∙ ∑0r n
isLinearCombination : {n : ℕ} → FinVec R n → R → Type ℓ
isLinearCombination V x = ∃[ α ∈ FinVec R _ ] x ≡ linearCombination α V
{- If x and y are linear combinations of l, then (x + y) is
a linear combination. -}
isLinearCombination+ : {n : ℕ} {x y : R} (V : FinVec R n)
→ isLinearCombination V x
→ isLinearCombination V y
→ isLinearCombination V (x + y)
isLinearCombination+ V = map2 λ α β → (λ i → α .fst i + β .fst i)
, cong₂ (_+_) (α .snd) (β .snd) ∙ sym (sumDist+ _ _ V)
{- If x is a linear combinations of l, then -x is
a linear combination. -}
isLinearCombination- : {n : ℕ} {x : R} (V : FinVec R n)
→ isLinearCombination V x → isLinearCombination V (- x)
isLinearCombination- V = map λ α → (λ i → - α .fst i) , cong (-_) (α .snd) ∙ sym (dist- _ V)
{- 0r is the trivial linear Combination -}
isLinearCombination0 : {n : ℕ} (V : FinVec R n)
→ isLinearCombination V 0r
isLinearCombination0 V = ∣ _ , sym (dist0 V) ∣
{- Linear combinations are stable under left multiplication -}
isLinearCombinationL· : {n : ℕ} (V : FinVec R n) (r : R) {x : R}
→ isLinearCombination V x → isLinearCombination V (r · x)
isLinearCombinationL· V r = map λ α → (λ i → r · α .fst i) , cong (r ·_) (α .snd)
∙∙ ∑Mulrdist r (λ i → α .fst i · V i)
∙∙ ∑Ext λ i → ·Assoc r (α .fst i) (V i)
generatedIdeal : {n : ℕ} → FinVec R n → IdealsIn Ring
fst (generatedIdeal V) = λ x → isLinearCombination V x , isPropPropTrunc
CommIdeal.isCommIdeal.+Closed (snd (generatedIdeal V)) = isLinearCombination+ V
CommIdeal.isCommIdeal.contains0 (snd (generatedIdeal V)) = isLinearCombination0 V
CommIdeal.isCommIdeal.·Closed (snd (generatedIdeal V)) = λ r → isLinearCombinationL· V r
open CommIdeal.isCommIdeal
genIdeal : {n : ℕ} (R : CommRing ℓ) → FinVec (fst R) n → CommIdeal.CommIdeal R
fst (genIdeal R V) x = isLinearCombination R V x , isPropPropTrunc
+Closed (snd (genIdeal R V)) = isLinearCombination+ R V
contains0 (snd (genIdeal R V)) = isLinearCombination0 R V
·Closed (snd (genIdeal R V)) r = isLinearCombinationL· R V r
syntax genIdeal R V = ⟨ V ⟩[ R ]
FGIdealIn : (R : CommRing ℓ) → Type (ℓ-suc ℓ)
FGIdealIn R = Σ[ I ∈ CommIdeal.CommIdeal R ]
∃[ nV ∈ Σ[ n ∈ ℕ ] FinVec (fst R) n ] I ≡ ⟨ nV .snd ⟩[ R ]
-- The lattice laws
module _ (R' : CommRing ℓ) where
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
open CommIdeal R'
open Sum (CommRing→Ring R')
open KroneckerDelta (CommRing→Ring R')
private
R = fst R'
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
inclOfFGIdeal : {n : ℕ} (V : FinVec R n) (I : CommIdeal)
→ (∀ i → V i ∈ I) → ⟨ V ⟩ ⊆ I
inclOfFGIdeal V I ∀i→Vi∈I x = elim (λ _ → I .fst x .snd) inclOfFGIdealΣ
where
inclOfFGIdealΣ : Σ[ α ∈ FinVec R _ ] x ≡ linearCombination R' α V → x ∈ I
inclOfFGIdealΣ (α , x≡α·V) = subst-∈ I (sym x≡α·V) (∑Closed I (λ i → α i · V i)
λ i → ·Closed (I .snd) _ (∀i→Vi∈I i))
indInIdeal : ∀ {n : ℕ} (U : FinVec R n) (i : Fin n) → U i ∈ ⟨ U ⟩
indInIdeal U i = ∣ (δ i) , sym (∑Mul1r _ U i) ∣
sucIncl : ∀ {n : ℕ} (U : FinVec R (ℕsuc n)) → ⟨ U ∘ suc ⟩ ⊆ ⟨ U ⟩
sucIncl U x = map λ (α , x≡∑αUsuc) → (λ { zero → 0r ; (suc i) → α i }) , x≡∑αUsuc ∙ path _ _
where
path : ∀ s u₀ → s ≡ 0r · u₀ + s
path = solve R'
emptyFGIdeal : ∀ (V : FinVec R 0) → ⟨ V ⟩ ≡ 0Ideal
emptyFGIdeal V = CommIdeal≡Char (λ _ → rec (is-set _ _) snd)
(λ _ x≡0 → ∣ (λ ()) , x≡0 ∣)
0FGIdealLIncl : {n : ℕ} → ⟨ replicateFinVec n 0r ⟩ ⊆ 0Ideal
0FGIdealLIncl x = elim (λ _ → is-set _ _)
λ (α , x≡∑α0) → subst-∈ 0Ideal (sym x≡∑α0) (∑Closed 0Ideal (λ i → α i · 0r)
λ i → subst-∈ 0Ideal (sym (0RightAnnihilates _)) refl)
0FGIdealRIncl : {n : ℕ} → 0Ideal ⊆ ⟨ replicateFinVec n 0r ⟩
0FGIdealRIncl x x≡0 = subst-∈ ⟨ replicateFinVec _ 0r ⟩ (sym x≡0)
(⟨ replicateFinVec _ 0r ⟩ .snd .contains0)
0FGIdeal : {n : ℕ} → ⟨ replicateFinVec n 0r ⟩ ≡ 0Ideal
0FGIdeal = CommIdeal≡Char 0FGIdealLIncl 0FGIdealRIncl
FGIdealAddLemmaLIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ++Fin V ⟩ ⊆ (⟨ U ⟩ +i ⟨ V ⟩)
FGIdealAddLemmaLIncl {n = ℕzero} U V x x∈⟨V⟩ =
∣ (0r , x) , ⟨ U ⟩ .snd .contains0 , x∈⟨V⟩ , sym (+Lid x) ∣
FGIdealAddLemmaLIncl {n = ℕsuc n} U V x = rec isPropPropTrunc helperΣ
where
helperΣ : Σ[ α ∈ FinVec R _ ] (x ≡ ∑ λ i → α i · (U ++Fin V) i) → x ∈ (⟨ U ⟩ +i ⟨ V ⟩)
helperΣ (α , p) = subst-∈ (⟨ U ⟩ +i ⟨ V ⟩) (sym p)
((⟨ U ⟩ +i ⟨ V ⟩) .snd .+Closed zeroIncl sumIncl)
where
zeroIncl : (α zero · U zero) ∈ (⟨ U ⟩ +i ⟨ V ⟩)
zeroIncl = +iLincl ⟨ U ⟩ ⟨ V ⟩ (α zero · U zero)
(⟨ U ⟩ .snd .·Closed (α zero) (indInIdeal U zero))
sumIncl : (∑ λ i → (α ∘ suc) i · ((U ∘ suc) ++Fin V) i) ∈ (⟨ U ⟩ +i ⟨ V ⟩)
sumIncl = let sum = ∑ λ i → (α ∘ suc) i · ((U ∘ suc) ++Fin V) i in
+iRespLincl ⟨ U ∘ suc ⟩ ⟨ U ⟩ ⟨ V ⟩ (sucIncl U) sum
(FGIdealAddLemmaLIncl (U ∘ suc) V _ ∣ (α ∘ suc) , refl ∣)
FGIdealAddLemmaRIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ (⟨ U ⟩ +i ⟨ V ⟩) ⊆ ⟨ U ++Fin V ⟩
FGIdealAddLemmaRIncl U V x = rec isPropPropTrunc (uncurry3 helper)
where
helperΣ : ((y , z) : R × R)
→ Σ[ α ∈ FinVec R _ ] (y ≡ ∑ λ i → α i · U i)
→ Σ[ β ∈ FinVec R _ ] (z ≡ ∑ λ i → β i · V i)
→ x ≡ y + z
→ x ∈ ⟨ U ++Fin V ⟩
helperΣ (y , z) (α , y≡∑αU) (β , z≡∑βV) x≡y+z = ∣ (α ++Fin β) , path ∣
where
path : x ≡ ∑ λ i → (α ++Fin β) i · (U ++Fin V) i
path = x ≡⟨ x≡y+z ⟩
y + z ≡⟨ cong₂ (_+_) y≡∑αU z≡∑βV ⟩
(∑ λ i → α i · U i) + (∑ λ i → β i · V i) ≡⟨ sym (∑Split++ (λ i → α i · U i) _) ⟩
(∑ ((λ i → α i · U i) ++Fin (λ i → β i · V i))) ≡⟨ ∑Ext (mul++dist α U β V) ⟩
(∑ λ i → (α ++Fin β) i · (U ++Fin V) i) ∎
helper : ((y , z) : R × R)
→ ∃[ α ∈ FinVec R _ ] (y ≡ ∑ λ i → α i · U i)
→ ∃[ β ∈ FinVec R _ ] (z ≡ ∑ λ i → β i · V i)
→ x ≡ y + z
→ x ∈ ⟨ U ++Fin V ⟩
helper _ = rec2 (isPropΠ (λ _ → isPropPropTrunc)) (helperΣ _)
FGIdealAddLemma : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ++Fin V ⟩ ≡ ⟨ U ⟩ +i ⟨ V ⟩
FGIdealAddLemma U V = CommIdeal≡Char (FGIdealAddLemmaLIncl U V) (FGIdealAddLemmaRIncl U V)
IdealAddAssoc : {n m k : ℕ} (U : FinVec R n) (V : FinVec R m) (W : FinVec R k)
→ ⟨ U ++Fin (V ++Fin W) ⟩ ≡ ⟨ (U ++Fin V) ++Fin W ⟩
IdealAddAssoc {n = n} {m = m} {k = k} U V W =
let genIdealExpl : (n : ℕ) → FinVec R n → CommIdeal
genIdealExpl _ V = ⟨ V ⟩
in cong₂ genIdealExpl (+ℕ-assoc n m k) (++FinAssoc U V W)
++FinComm : ∀ {n m : ℕ} (V : FinVec R n) (W : FinVec R m)
→ ⟨ V ++Fin W ⟩ ≡ ⟨ W ++Fin V ⟩
++FinComm V W = FGIdealAddLemma V W ∙∙ +iComm ⟨ V ⟩ ⟨ W ⟩ ∙∙ sym (FGIdealAddLemma W V)
open ProdFin R'
prodIn··Ideal : {n m : ℕ} (U : FinVec R n) (V : FinVec R m) (x y : R)
→ (x ∈ ⟨ U ⟩) → (y ∈ ⟨ V ⟩) → (x · y) ∈ ⟨ U ··Fin V ⟩
prodIn··Ideal {n = n} {m = m} U V x y = map2 Σhelper
where
Σhelper : Σ[ α ∈ FinVec R n ] x ≡ linearCombination R' α U
→ Σ[ β ∈ FinVec R m ] y ≡ linearCombination R' β V
→ Σ[ γ ∈ FinVec R (n ·ℕ m) ] (x · y) ≡ linearCombination R' γ (U ··Fin V)
Σhelper (α , x≡∑αU) (β , y≡∑βV) = α ··Fin β , path
where
path : x · y ≡ ∑ λ i → (α ··Fin β) i · (U ··Fin V) i
path = x · y ≡⟨ cong₂ (_·_) x≡∑αU y≡∑βV ⟩
(∑ λ i → α i · U i) · (∑ λ i → β i · V i) ≡⟨ ∑Dist··Fin (λ i → α i · U i) _ ⟩
(∑ λ j → ((λ i → α i · U i) ··Fin (λ i → β i · V i)) j) ≡⟨ ∑Ext (·Dist··Fin α U β V) ⟩
(∑ λ i → (α ··Fin β) i · (U ··Fin V) i) ∎
FGIdealMultLemmaLIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ··Fin V ⟩ ⊆ (⟨ U ⟩ ·i ⟨ V ⟩)
FGIdealMultLemmaLIncl U V x = elim (λ _ → isPropPropTrunc)
λ (α , x≡∑αUV) → subst-∈ (⟨ U ⟩ ·i ⟨ V ⟩) (sym x≡∑αUV) --replace x by ∑αᵢⱼUᵢVⱼ
(∑Closed (⟨ U ⟩ ·i ⟨ V ⟩) (λ i → α i · (U ··Fin V) i) --show that each αᵢ(U··V)ᵢ is in product
λ i → (⟨ U ⟩ ·i ⟨ V ⟩) .snd .·Closed (α i) --drop the α's
(flattenElim {P = _∈ (⟨ U ⟩ ·i ⟨ V ⟩)} (toMatrix U V) --show theat UᵢVⱼ is in product
(λ j k → prodInProd ⟨ U ⟩ ⟨ V ⟩ (U j) (V k) (indInIdeal U j) (indInIdeal V k)) i))
FGIdealMultLemmaRIncl : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ (⟨ U ⟩ ·i ⟨ V ⟩) ⊆ ⟨ U ··Fin V ⟩
FGIdealMultLemmaRIncl U V x = elim (λ _ → isPropPropTrunc)
λ (_ , (α , β) , ∀α∈⟨U⟩ , ∀β∈⟨V⟩ , x≡∑αβ) → subst-∈ ⟨ U ··Fin V ⟩ (sym x≡∑αβ)
(∑Closed ⟨ U ··Fin V ⟩ _ (λ i → prodIn··Ideal U V (α i) (β i) (∀α∈⟨U⟩ i) (∀β∈⟨V⟩ i)))
FGIdealMultLemma : {n m : ℕ} (U : FinVec R n) (V : FinVec R m)
→ ⟨ U ··Fin V ⟩ ≡ ⟨ U ⟩ ·i ⟨ V ⟩
FGIdealMultLemma U V = CommIdeal≡Char (FGIdealMultLemmaLIncl U V) (FGIdealMultLemmaRIncl U V)
-- A useful lemma for constructing the structure sheaf
module GeneratingPowers (R' : CommRing ℓ) (n : ℕ) where
open CommRingStr (snd R')
open CommRingTheory R'
open RingTheory (CommRing→Ring R')
open Sum (CommRing→Ring R')
open Exponentiation R'
open BinomialThm R'
open CommIdeal R'
private
R = fst R'
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
_ⁿ : {m : ℕ} → FinVec R m → FinVec R m
U ⁿ = λ i → U i ^ n
lemma : (m : ℕ) (α U : FinVec R (ℕsuc m))
→ (linearCombination R' α U) ^ ((ℕsuc m) ·ℕ n) ∈ ⟨ U ⁿ ⟩
lemma ℕzero α U = ∣ α ⁿ , path ∣
where
path : (α zero · U zero + 0r) ^ (n +ℕ 0) ≡ α zero ^ n · U zero ^ n + 0r
path = (α zero · U zero + 0r) ^ (n +ℕ 0) ≡⟨ cong (_^ (n +ℕ 0)) (+Rid _) ⟩
(α zero · U zero) ^ (n +ℕ 0) ≡⟨ cong ((α zero · U zero) ^_) (+-zero n) ⟩
(α zero · U zero) ^ n ≡⟨ ^-ldist-· _ _ n ⟩
α zero ^ n · U zero ^ n ≡⟨ sym (+Rid _) ⟩
α zero ^ n · U zero ^ n + 0r ∎
lemma (ℕsuc m) α U = subst-∈ ⟨ U ⁿ ⟩ (sym (BinomialThm (n +ℕ (ℕsuc m) ·ℕ n) x y)) ∑Binomial∈⟨Uⁿ⟩
where
x = α zero · U zero
y = linearCombination R' (α ∘ suc) (U ∘ suc)
binomialSummand∈⟨Uⁿ⟩ : ∀ (i : Fin _) → BinomialVec (n +ℕ (ℕsuc m) ·ℕ n) x y i ∈ ⟨ U ⁿ ⟩
binomialSummand∈⟨Uⁿ⟩ i with ≤-+-split n ((ℕsuc m) ·ℕ n) (toℕ i) (pred-≤-pred (toℕ<n i))
... | inl n≤i = subst-∈ ⟨ U ⁿ ⟩ (·CommAssocr _ _ (x ^ (toℕ i)))
(⟨ U ⁿ ⟩ .snd .·Closed _ (xHelper (toℕ i) n≤i))
where
xHelper : ∀ k → n ≤ k → x ^ k ∈ ⟨ U ⁿ ⟩
xHelper k n≤k = subst-∈ ⟨ U ⁿ ⟩ path (⟨ U ⁿ ⟩ .snd .·Closed _ (indInIdeal R' (U ⁿ) zero))
where
path : α zero ^ k · U zero ^ (k ∸ n) · U zero ^ n ≡ x ^ k
path = α zero ^ k · U zero ^ (k ∸ n) · U zero ^ n
≡⟨ sym (·Assoc _ _ _) ⟩
α zero ^ k · (U zero ^ (k ∸ n) · U zero ^ n)
≡⟨ cong ((α zero ^ k) ·_) (·-of-^-is-^-of-+ (U zero) (k ∸ n) n) ⟩
α zero ^ k · U zero ^ ((k ∸ n) +ℕ n)
≡⟨ cong (λ l → (α zero ^ k) · (U zero ^ l)) (≤-∸-+-cancel n≤k) ⟩
α zero ^ k · U zero ^ k
≡⟨ sym (^-ldist-· (α zero) (U zero) k) ⟩
x ^ k ∎
... | inr [m+1]n≤n+[m+1]n-i = ⟨ U ⁿ ⟩ .snd .·Closed _ (yHelper (toℕ i) [m+1]n≤n+[m+1]n-i)
where
powSucIncl : ⟨ (U ∘ suc) ⁿ ⟩ ⊆ ⟨ U ⁿ ⟩
powSucIncl = inclOfFGIdeal R' ((U ∘ suc) ⁿ) ⟨ U ⁿ ⟩ (λ i → indInIdeal R' (U ⁿ) (suc i))
inductiveStep : y ^ ((ℕsuc m) ·ℕ n) ∈ ⟨ U ⁿ ⟩
inductiveStep = powSucIncl _ (lemma m (α ∘ suc) (U ∘ suc))
yHelper : ∀ k
→ (ℕsuc m) ·ℕ n ≤ n +ℕ (ℕsuc m) ·ℕ n ∸ k
→ y ^ (n +ℕ (ℕsuc m) ·ℕ n ∸ k) ∈ ⟨ U ⁿ ⟩
yHelper k [m+1]n≤n+[m+1]n-k = subst-∈ ⟨ U ⁿ ⟩ path (⟨ U ⁿ ⟩ .snd .·Closed _ inductiveStep)
where
n+[m+1]n-k = n +ℕ (ℕsuc m) ·ℕ n ∸ k
[m+1]n = (ℕsuc m) ·ℕ n
path : y ^ (n+[m+1]n-k ∸ [m+1]n) · y ^ [m+1]n ≡ y ^ n+[m+1]n-k
path =
y ^ (n+[m+1]n-k ∸ [m+1]n) · y ^ [m+1]n ≡⟨ ·-of-^-is-^-of-+ y (n+[m+1]n-k ∸ [m+1]n) [m+1]n ⟩
y ^ ((n+[m+1]n-k ∸ [m+1]n) +ℕ [m+1]n) ≡⟨ cong (y ^_) (≤-∸-+-cancel [m+1]n≤n+[m+1]n-k) ⟩
y ^ n+[m+1]n-k ∎
∑Binomial∈⟨Uⁿ⟩ : ∑ (BinomialVec (n +ℕ (ℕsuc m) ·ℕ n) x y) ∈ ⟨ U ⁿ ⟩
∑Binomial∈⟨Uⁿ⟩ = ∑Closed ⟨ U ⁿ ⟩ _ binomialSummand∈⟨Uⁿ⟩
thm : ∀ (m : ℕ) (U : FinVec R m) → 1r ∈ ⟨ U ⟩ → 1r ∈ ⟨ U ⁿ ⟩
thm ℕzero U 1∈⟨U⟩ = 1∈⟨U⟩
thm (ℕsuc m) U = elim (λ _ → isPropPropTrunc) Σhelper
where
Σhelper : Σ[ α ∈ FinVec R (ℕsuc m) ] 1r ≡ linearCombination R' α U
→ 1r ∈ ⟨ U ⁿ ⟩
Σhelper (α , p) = subst-∈ ⟨ U ⁿ ⟩ path (lemma m α U)
where
path : linearCombination R' α U ^ ((ℕsuc m) ·ℕ n) ≡ 1r
path = linearCombination R' α U ^ ((ℕsuc m) ·ℕ n) ≡⟨ cong (_^ ((ℕsuc m) ·ℕ n)) (sym p) ⟩
1r ^ ((ℕsuc m) ·ℕ n) ≡⟨ 1ⁿ≡1 ((ℕsuc m) ·ℕ n) ⟩
1r ∎
| 44.655072
| 102
| 0.503245
|
1c84edb3a211005e4955daa25f33bf49ba622384
| 8,302
|
agda
|
Agda
|
test/Fail/Issue1560.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
test/Fail/Issue1560.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue1560.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2015-06-11, issue #1560 reported by Peter Thiemann
-- Ulf, 2015-09-23:
-- This test was still taking 12s, which is annoyingly much.
-- I commented out a few of the constructors to bring it down
-- to 2s. With agda-2.4.2 it checks in 18s, which should be long
-- enough to notice.
open import Common.Coinduction
-- Andreas, 2017-04-26: removing fake mutual speeds up from 1.8s to 1.3s
-- However, the purpose of this test is to be slow on old versions of Agda
-- which shows if the fake mutual is present.
-- module _ where
mutual
-- an stype
data SType' : Set where
Skip : SType'
Semi : ∞ SType' → ∞ SType' → SType'
Case : ∞ SType' → ∞ SType' → SType'
c : (SType' → SType') → SType'
-- equivalence
data _∼_ : SType' → SType' → Set where
∼-Skip : Skip ∼ Skip
∼-Case : ∀ {s₁ s₁' s₂ s₂'} → ∞ (♭ s₁ ∼ ♭ s₁') → ∞ (♭ s₂ ∼ ♭ s₂') → Case s₁ s₂ ∼ Case s₁' s₂'
∼-Semi : ∀ {s₁ s₁' s₂ s₂'} → ∞ (♭ s₁ ∼ ♭ s₁') → ∞ (♭ s₂ ∼ ♭ s₂') → Semi s₁ s₂ ∼ Semi s₁' s₂'
∼-Semi-Skip-Left-Left : ∀ {s₁ s₂ s₃} → ∞ (♭ s₁ ∼ Skip) → ∞ (♭ s₂ ∼ s₃) → Semi s₁ s₂ ∼ s₃
-- ∼-Semi-Skip-Right-Left : ∀ {s₁ s₂ s₃} → ∞ (♭ s₂ ∼ Skip) → ∞ (♭ s₁ ∼ s₃) → Semi s₁ s₂ ∼ s₃
-- ∼-Semi-Skip-Left-Right : ∀ {s₁ s₂ s₃} → ∞ (♭ s₁ ∼ Skip) → ∞ (♭ s₂ ∼ s₃) → s₃ ∼ Semi s₁ s₂
-- ∼-Semi-Skip-Right-Right : ∀ {s₁ s₂ s₃} → ∞ (♭ s₂ ∼ Skip) → ∞ (♭ s₁ ∼ s₃) → s₃ ∼ Semi s₁ s₂
∼-Semi-Case-Left : ∀ {s₁ s₂ s₃ sl1 sl2 sr}
→ ∞ (♭ sl1 ∼ Semi s₁ s₃) → ∞ (♭ sl2 ∼ Semi s₂ s₃) → ∞ (♭ sr ∼ Case s₁ s₂) → Case sl1 sl2 ∼ Semi sr s₃
∼-Semi-Case-Right : ∀ {s₁ s₂ s₃ sl1 sl2 sr}
→ ∞ (♭ sl1 ∼ Semi s₁ s₃) → ∞ (♭ sl2 ∼ Semi s₂ s₃) → ∞ (♭ sr ∼ Case s₁ s₂) → Semi sr s₃ ∼ Case sl1 sl2
-- reflexivity
∼-refl : (s : SType') → s ∼ s
∼-refl Skip = ∼-Skip
∼-refl (Semi x x₁) = ∼-Semi (♯ ∼-refl (♭ x)) (♯ ∼-refl (♭ x₁))
∼-refl (Case s₁ s₂) = ∼-Case (♯ ∼-refl (♭ s₁)) (♯ ∼-refl (♭ s₂))
∼-refl (c f) = {!!}
-- symmetry
∼-sym : ∀ {s₁ s₂} → s₁ ∼ s₂ → s₂ ∼ s₁
∼-sym ∼-Skip = ∼-Skip
∼-sym (∼-Case s₁' s₂') = ∼-Case (♯ ∼-sym (♭ s₁')) (♯ ∼-sym (♭ s₂'))
∼-sym (∼-Semi s₁' s₂') = ∼-Semi (♯ ∼-sym (♭ s₁')) (♯ ∼-sym (♭ s₂'))
∼-sym (∼-Semi-Skip-Left-Left s₁∼s₂ s₁∼s₃) = {!∼-Semi-Skip-Left-Right s₁∼s₂ s₁∼s₃!}
-- ∼-sym (∼-Semi-Skip-Right-Left s₁∼s₂ s₁∼s₃) = ∼-Semi-Skip-Right-Right s₁∼s₂ s₁∼s₃
-- ∼-sym (∼-Semi-Skip-Left-Right s₁∼s₂ s₁∼s₃) = ∼-Semi-Skip-Left-Left s₁∼s₂ s₁∼s₃
-- ∼-sym (∼-Semi-Skip-Right-Right s₁∼s₂ s₁∼s₃) = ∼-Semi-Skip-Right-Left s₁∼s₂ s₁∼s₃
∼-sym (∼-Semi-Case-Left sl1 sl2 sr) = ∼-Semi-Case-Right sl1 sl2 sr
∼-sym (∼-Semi-Case-Right sl1 sl2 sr) = ∼-Semi-Case-Left sl1 sl2 sr
-- transitivity
∼-trans : ∀ {s₁ s₂ s₃} → s₁ ∼ s₂ → s₂ ∼ s₃ → s₁ ∼ s₃
∼-trans ∼-Skip ∼-Skip = ∼-Skip
-- ∼-trans ∼-Skip (∼-Semi-Skip-Left-Right x x₁) = ∼-Semi-Skip-Left-Right x x₁
-- ∼-trans ∼-Skip (∼-Semi-Skip-Right-Right x x₁) = ∼-Semi-Skip-Right-Right x x₁
∼-trans (∼-Case x x₁) (∼-Case x₂ x₃) = ∼-Case (♯ ∼-trans (♭ x) (♭ x₂)) (♯ ∼-trans (♭ x₁) (♭ x₃))
-- ∼-trans (∼-Case x x₁) (∼-Semi-Skip-Left-Right x₂ x₃) = ∼-Semi-Skip-Left-Right x₂ (♯ ∼-trans (♭ x₃) (∼-Case (♯ ∼-sym (♭ x)) (♯ ∼-sym (♭ x₁))))
-- ∼-trans (∼-Case x x₁) (∼-Semi-Skip-Right-Right x₂ x₃) = ∼-Semi-Skip-Right-Right x₂ (♯ ∼-trans (♭ x₃) (∼-Case (♯ ∼-sym (♭ x)) (♯ ∼-sym (♭ x₁))))
∼-trans (∼-Case x x₁) (∼-Semi-Case-Left x₂ x₃ x₄) = ∼-Semi-Case-Left (♯ ∼-trans (♭ x) (♭ x₂)) (♯ ∼-trans (♭ x₁) (♭ x₃)) x₄
∼-trans (∼-Semi x x₁) (∼-Semi x₂ x₃) = ∼-Semi (♯ ∼-trans (♭ x) (♭ x₂)) (♯ ∼-trans (♭ x₁) (♭ x₃))
∼-trans (∼-Semi x x₁) (∼-Semi-Skip-Left-Left x₂ x₃) = ∼-Semi-Skip-Left-Left (♯ ∼-trans (♭ x) (♭ x₂)) (♯ ∼-trans (♭ x₁) (♭ x₃))
-- ∼-trans (∼-Semi x x₁) (∼-Semi-Skip-Right-Left x₂ x₃) = ∼-Semi-Skip-Right-Left (♯ ∼-trans (♭ x₁) (♭ x₂)) (♯ ∼-trans (♭ x) (♭ x₃))
-- ∼-trans (∼-Semi x x₁) (∼-Semi-Skip-Left-Right x₂ x₃) = ∼-Semi-Skip-Left-Right x₂ (♯ ∼-trans (♭ x₃) (∼-Semi (♯ ∼-sym (♭ x)) (♯ ∼-sym (♭ x₁))))
-- ∼-trans (∼-Semi x x₁) (∼-Semi-Skip-Right-Right x₂ x₃) = ∼-Semi-Skip-Right-Right x₂ (♯ ∼-trans (♭ x₃) (∼-Semi (♯ ∼-sym (♭ x)) (♯ ∼-sym (♭ x₁))))
∼-trans (∼-Semi x x₁) (∼-Semi-Case-Right x₂ x₃ x₄) = ∼-Semi-Case-Right (♯ ∼-trans (♭ x₂) (∼-Semi (♯ ∼-refl _) (♯ ∼-sym (♭ x₁)))) (♯ ∼-trans (♭ x₃) (∼-Semi (♯ ∼-refl _) (♯ ∼-sym (♭ x₁)))) (♯ ∼-trans (♭ x) (♭ x₄))
∼-trans (∼-Semi-Skip-Left-Left x x₁) ∼-Skip = ∼-Semi-Skip-Left-Left x x₁
∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Case x₂ x₃) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Case x₂ x₃))
∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi x₂ x₃) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi x₂ x₃))
∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi-Skip-Left-Left x₂ x₃) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi-Skip-Left-Left x₂ x₃))
-- ∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi-Skip-Right-Left x₂ x₃) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi-Skip-Right-Left x₂ x₃))
-- ∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi-Skip-Left-Right x₂ x₃) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi-Skip-Left-Right x₂ x₃))
-- ∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi-Skip-Right-Right x₂ x₃) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi-Skip-Right-Right x₂ x₃))
∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi-Case-Left x₂ x₃ x₄) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi-Case-Left x₂ x₃ x₄))
∼-trans (∼-Semi-Skip-Left-Left x x₁) (∼-Semi-Case-Right x₂ x₃ x₄) = ∼-Semi-Skip-Left-Left x (♯ ∼-trans (♭ x₁) (∼-Semi-Case-Right x₂ x₃ x₄))
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) ∼-Skip = ∼-Semi-Skip-Right-Left x x₁
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Case x₂ x₃) = ∼-Semi-Skip-Right-Left x (♯ ∼-trans (♭ x₁) (∼-Case x₂ x₃))
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi x₂ x₃) = ∼-Semi-Skip-Right-Left x (♯ ∼-trans (♭ x₁) (∼-Semi x₂ x₃))
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi-Skip-Left-Left x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi-Skip-Right-Left x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi-Skip-Left-Right x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi-Skip-Right-Right x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi-Case-Left x₂ x₃ x₄) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Left x x₁) (∼-Semi-Case-Right x₂ x₃ x₄) = {!!}
--∼-trans (∼-Semi-Skip-Left-Right x x₁) (∼-Semi x₂ x₃) = ∼-Semi-Skip-Left-Right (♯ ∼-trans (∼-sym (♭ x₂)) (♭ x)) (♯ ∼-trans (∼-sym (♭ x₃)) (♭ x₁))
-- ∼-trans (∼-Semi-Skip-Left-Right x x₁) (∼-Semi-Skip-Left-Left x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Left-Right x x₁) (∼-Semi-Skip-Right-Left x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Left-Right x x₁) (∼-Semi-Skip-Left-Right x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Left-Right x x₁) (∼-Semi-Skip-Right-Right x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Left-Right x x₁) (∼-Semi-Case-Right x₂ x₃ x₄) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Right x x₁) (∼-Semi x₂ x₃) = ∼-Semi-Skip-Right-Right (♯ ∼-trans (∼-sym (♭ x₃)) (♭ x)) (♯ ∼-trans (∼-sym (♭ x₂)) (♭ x₁))
-- ∼-trans (∼-Semi-Skip-Right-Right x x₁) (∼-Semi-Skip-Left-Left x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Right x x₁) (∼-Semi-Skip-Right-Left x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Right x x₁) (∼-Semi-Skip-Left-Right x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Right x x₁) (∼-Semi-Skip-Right-Right x₂ x₃) = {!!}
-- ∼-trans (∼-Semi-Skip-Right-Right x x₁) (∼-Semi-Case-Right x₂ x₃ x₄) = {!!}
∼-trans (∼-Semi-Case-Left x x₁ x₂) (∼-Semi x₃ x₄) = ∼-Semi-Case-Left {!!} (♯ ∼-trans (♭ x₁) (∼-Semi (♯ ∼-refl _) x₄)) (♯ ∼-trans (∼-sym (♭ x₃)) (♭ x₂))
∼-trans (∼-Semi-Case-Left x x₁ x₂) (∼-Semi-Skip-Left-Left x₃ x₄) = {!!}
-- ∼-trans (∼-Semi-Case-Left x x₁ x₂) (∼-Semi-Skip-Right-Left x₃ x₄) = {!!}
-- ∼-trans (∼-Semi-Case-Left x x₁ x₂) (∼-Semi-Skip-Left-Right x₃ x₄) = {!!}
-- ∼-trans (∼-Semi-Case-Left x x₁ x₂) (∼-Semi-Skip-Right-Right x₃ x₄) = {!!}
∼-trans (∼-Semi-Case-Left x x₁ x₂) (∼-Semi-Case-Right x₃ x₄ x₅) = {!!}
∼-trans (∼-Semi-Case-Right x x₁ x₂) (∼-Case x₃ x₄) = ∼-Semi-Case-Right (♯ ∼-trans (∼-sym (♭ x₃)) (♭ x)) (♯ ∼-trans (∼-sym (♭ x₄)) (♭ x₁)) x₂
-- ∼-trans (∼-Semi-Case-Right x x₁ x₂) (∼-Semi-Skip-Left-Right x₃ x₄) = {!!}
-- ∼-trans (∼-Semi-Case-Right x x₁ x₂) (∼-Semi-Skip-Right-Right x₃ x₄) = {!!}
∼-trans (∼-Semi-Case-Right x x₁ x₂) (∼-Semi-Case-Left x₃ x₄ x₅) = {!!}
| 70.957265
| 213
| 0.538545
|
dc5fe645668fab5976352aab372cdf553e27d977
| 1,282
|
agda
|
Agda
|
LibraBFT/Yasm/Yasm.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Yasm/Yasm.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Yasm/Yasm.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Base as LYB
import LibraBFT.Yasm.System as LYS
-- This module provides a single import for all Yasm modules
module LibraBFT.Yasm.Yasm
(ℓ-PeerState : Level)
(ℓ-VSFP : Level)
(parms : LYB.SystemParameters ℓ-PeerState)
(ValidSenderForPK : LYS.ValidSenderForPK-type ℓ-PeerState ℓ-VSFP parms)
(ValidSenderForPK-stable : LYS.ValidSenderForPK-stable-type ℓ-PeerState ℓ-VSFP parms ValidSenderForPK)
where
open LYB.SystemParameters parms
open import LibraBFT.Yasm.Base public
open import LibraBFT.Yasm.System ℓ-PeerState ℓ-VSFP parms public
open import LibraBFT.Yasm.Properties ℓ-PeerState ℓ-VSFP parms ValidSenderForPK ValidSenderForPK-stable public
open import Util.FunctionOverride PeerId _≟PeerId_ public
| 49.307692
| 111
| 0.670047
|
18608b8e57adf4b5a29c02ab9f26ebdea686e5b1
| 2,852
|
agda
|
Agda
|
src/Magma/Bundles.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | 2
|
2021-08-15T06:16:13.000Z
|
2021-08-17T09:14:03.000Z
|
src/Magma/Bundles.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | 2
|
2021-10-04T05:30:30.000Z
|
2021-10-09T08:24:56.000Z
|
src/Magma/Bundles.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Magma.Bundles where
open import Algebra.Bundles
open import Algebra.Core
open import Magma.Structures
open import Relation.Binary
open import Level
record IdempotentMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isIdempotentMagma : IsIdempotentMagma _≈_ _∙_
open IsIdempotentMagma isIdempotentMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
record AlternateMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isAlternateMagma : IsAlternateMagma _≈_ _∙_
open IsAlternateMagma isAlternateMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
record FlexibleMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isFlexibleMagma : IsFlexibleMagma _≈_ _∙_
open IsFlexibleMagma isFlexibleMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
record MedialMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isMedialMagma : IsMedialMagma _≈_ _∙_
open IsMedialMagma isMedialMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
record SemimedialMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isSemimedialMagma : IsSemimedialMagma _≈_ _∙_
open IsSemimedialMagma isSemimedialMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
record LeftUnitalMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
isLeftUnitalMagma : IsLeftUnitalMagma _≈_ _∙_ ε
open IsLeftUnitalMagma isLeftUnitalMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
record RightUnitalMagma c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
isRightUnitalMagma : IsRightUnitalMagma _≈_ _∙_ ε
open IsRightUnitalMagma isRightUnitalMagma public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (rawMagma)
| 21.443609
| 54
| 0.652525
|
dfc774397ad32f666efc78bb596a2fe7320fbd8f
| 1,583
|
agda
|
Agda
|
agda-stdlib-0.9/src/Function/Injection.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/Function/Injection.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Function/Injection.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Injections
------------------------------------------------------------------------
module Function.Injection where
open import Function as Fun using () renaming (_∘_ to _⟨∘⟩_)
open import Level
open import Relation.Binary
open import Function.Equality as F
using (_⟶_; _⟨$⟩_) renaming (_∘_ to _⟪∘⟫_)
import Relation.Binary.PropositionalEquality as P
-- Injective functions.
Injective : ∀ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} →
A ⟶ B → Set _
Injective {A = A} {B} f = ∀ {x y} → f ⟨$⟩ x ≈₂ f ⟨$⟩ y → x ≈₁ y
where
open Setoid A renaming (_≈_ to _≈₁_)
open Setoid B renaming (_≈_ to _≈₂_)
-- The set of all injections between two setoids.
record Injection {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂) (To : Setoid t₁ t₂) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
field
to : From ⟶ To
injective : Injective to
-- The set of all injections from one set to another.
infix 3 _↣_
_↣_ : ∀ {f t} → Set f → Set t → Set _
From ↣ To = Injection (P.setoid From) (P.setoid To)
-- Identity and composition.
infixr 9 _∘_
id : ∀ {s₁ s₂} {S : Setoid s₁ s₂} → Injection S S
id = record { to = F.id; injective = Fun.id }
_∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂}
{F : Setoid f₁ f₂} {M : Setoid m₁ m₂} {T : Setoid t₁ t₂} →
Injection M T → Injection F M → Injection F T
f ∘ g = record
{ to = to f ⟪∘⟫ to g
; injective = (λ {_} → injective g) ⟨∘⟩ injective f
} where open Injection
| 28.781818
| 72
| 0.534428
|
1057a1d82f92305b828b67318535e11bf656b564
| 50
|
agda
|
Agda
|
test/interaction/Imports/Issue5357-D.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Imports/Issue5357-D.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Imports/Issue5357-D.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Imports.Issue5357-D where
A : Set₁
A = Set
| 12.5
| 32
| 0.74
|
202ba845295e52dce13a39588e81f56a3cdfcb15
| 436
|
agda
|
Agda
|
Cubical/HITs/SetQuotients/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetQuotients/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/SetQuotients/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-
This file contains:
- Definition of set quotients
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetQuotients.Base where
open import Cubical.Core.Primitives
-- Set quotients as a higher inductive type:
data _/_ {ℓ ℓ'} (A : Type ℓ) (R : A → A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
[_] : (a : A) → A / R
eq/ : (a b : A) → (r : R a b) → [ a ] ≡ [ b ]
squash/ : (x y : A / R) → (p q : x ≡ y) → p ≡ q
| 24.222222
| 76
| 0.557339
|
fb44fa0b638b6549c4403a61b8f1d5778d0cc2d6
| 5,532
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/NonStrictToStrict.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/NonStrictToStrict.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/NonStrictToStrict.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Conversion of _≤_ to _<_
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Construct.NonStrictToStrict
{a ℓ₁ ℓ₂} {A : Set a} (_≈_ : Rel A ℓ₁) (_≤_ : Rel A ℓ₂) where
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Data.Sum using (inj₁; inj₂)
open import Function using (_∘_; flip)
open import Relation.Nullary using (¬_; yes; no)
------------------------------------------------------------------------
-- _≤_ can be turned into _<_ as follows:
_<_ : Rel A _
x < y = (x ≤ y) × ¬ (x ≈ y)
------------------------------------------------------------------------
-- The converted relations have certain properties
-- (if the original relations have certain other properties)
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ = proj₁
<-irrefl : Irreflexive _≈_ _<_
<-irrefl x≈y (_ , x≉y) = x≉y x≈y
<-trans : IsPartialOrder _≈_ _≤_ → Transitive _<_
<-trans po (x≤y , x≉y) (y≤z , y≉z) =
(trans x≤y y≤z , x≉y ∘ antisym x≤y ∘ trans y≤z ∘ reflexive ∘ Eq.sym)
where open IsPartialOrder po
<-≤-trans : Symmetric _≈_ → Transitive _≤_ → Antisymmetric _≈_ _≤_ →
_≤_ Respectsʳ _≈_ → Trans _<_ _≤_ _<_
<-≤-trans sym trans antisym respʳ (x≤y , x≉y) y≤z =
trans x≤y y≤z , (λ x≈z → x≉y (antisym x≤y (respʳ (sym x≈z) y≤z)))
≤-<-trans : Transitive _≤_ → Antisymmetric _≈_ _≤_ →
_≤_ Respectsˡ _≈_ → Trans _≤_ _<_ _<_
≤-<-trans trans antisym respʳ x≤y (y≤z , y≉z) =
trans x≤y y≤z , (λ x≈z → y≉z (antisym y≤z (respʳ x≈z x≤y)))
<-asym : Antisymmetric _≈_ _≤_ → Asymmetric _<_
<-asym antisym (x≤y , x≉y) (y≤x , _) = x≉y (antisym x≤y y≤x)
<-respˡ-≈ : Transitive _≈_ → _≤_ Respectsˡ _≈_ → _<_ Respectsˡ _≈_
<-respˡ-≈ trans respˡ y≈z (y≤x , y≉x) =
(respˡ y≈z y≤x) , (λ z≈x → y≉x (trans y≈z z≈x))
<-respʳ-≈ : Symmetric _≈_ → Transitive _≈_ →
_≤_ Respectsʳ _≈_ → _<_ Respectsʳ _≈_
<-respʳ-≈ sym trans respʳ {x} {y} {z} y≈z (x≤y , x≉y) =
(respʳ y≈z x≤y) , λ x≈z → x≉y (trans x≈z (sym y≈z))
<-resp-≈ : IsEquivalence _≈_ → _≤_ Respects₂ _≈_ → _<_ Respects₂ _≈_
<-resp-≈ eq (respʳ , respˡ) =
<-respʳ-≈ sym trans respʳ , <-respˡ-≈ trans respˡ
where open IsEquivalence eq
<-trichotomous : Symmetric _≈_ → Decidable _≈_ →
Antisymmetric _≈_ _≤_ → Total _≤_ →
Trichotomous _≈_ _<_
<-trichotomous ≈-sym _≟_ antisym total x y with x ≟ y
... | yes x≈y = tri≈ (<-irrefl x≈y) x≈y (<-irrefl (≈-sym x≈y))
... | no x≉y with total x y
... | inj₁ x≤y = tri< (x≤y , x≉y) x≉y
(x≉y ∘ antisym x≤y ∘ proj₁)
... | inj₂ x≥y = tri> (x≉y ∘ flip antisym x≥y ∘ proj₁) x≉y
(x≥y , x≉y ∘ ≈-sym)
<-decidable : Decidable _≈_ → Decidable _≤_ → Decidable _<_
<-decidable _≟_ _≤?_ x y with x ≟ y | x ≤? y
... | yes x≈y | _ = no (flip proj₂ x≈y)
... | no x≉y | yes x≤y = yes (x≤y , x≉y)
... | no x≉y | no x≰y = no (x≰y ∘ proj₁)
<-isStrictPartialOrder : IsPartialOrder _≈_ _≤_ →
IsStrictPartialOrder _≈_ _<_
<-isStrictPartialOrder po = record
{ isEquivalence = isEquivalence
; irrefl = <-irrefl
; trans = <-trans po
; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
} where open IsPartialOrder po
<-isStrictTotalOrder₁ : Decidable _≈_ → IsTotalOrder _≈_ _≤_ →
IsStrictTotalOrder _≈_ _<_
<-isStrictTotalOrder₁ ≟ tot = record
{ isEquivalence = isEquivalence
; trans = <-trans isPartialOrder
; compare = <-trichotomous Eq.sym ≟ antisym total
} where open IsTotalOrder tot
<-isStrictTotalOrder₂ : IsDecTotalOrder _≈_ _≤_ →
IsStrictTotalOrder _≈_ _<_
<-isStrictTotalOrder₂ dtot = <-isStrictTotalOrder₁ _≟_ isTotalOrder
where open IsDecTotalOrder dtot
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.16
irrefl = <-irrefl
{-# WARNING_ON_USAGE irrefl
"Warning: irrefl was deprecated in v0.16.
Please use <-irrefl instead."
#-}
trans = <-trans
{-# WARNING_ON_USAGE trans
"Warning: trans was deprecated in v0.16.
Please use <-trans instead."
#-}
antisym⟶asym = <-asym
{-# WARNING_ON_USAGE antisym⟶asym
"Warning: antisym⟶asym was deprecated in v0.16.
Please use <-asym instead."
#-}
decidable = <-decidable
{-# WARNING_ON_USAGE decidable
"Warning: decidable was deprecated in v0.16.
Please use <-decidable instead."
#-}
trichotomous = <-trichotomous
{-# WARNING_ON_USAGE trichotomous
"Warning: trichotomous was deprecated in v0.16.
Please use <-trichotomous instead."
#-}
isPartialOrder⟶isStrictPartialOrder = <-isStrictPartialOrder
{-# WARNING_ON_USAGE isPartialOrder⟶isStrictPartialOrder
"Warning: isPartialOrder⟶isStrictPartialOrder was deprecated in v0.16.
Please use <-isStrictPartialOrder instead."
#-}
isTotalOrder⟶isStrictTotalOrder = <-isStrictTotalOrder₁
{-# WARNING_ON_USAGE isTotalOrder⟶isStrictTotalOrder
"Warning: isTotalOrder⟶isStrictTotalOrder was deprecated in v0.16.
Please use <-isStrictTotalOrder₁ instead."
#-}
isDecTotalOrder⟶isStrictTotalOrder = <-isStrictTotalOrder₂
{-# WARNING_ON_USAGE isDecTotalOrder⟶isStrictTotalOrder
"Warning: isDecTotalOrder⟶isStrictTotalOrder was deprecated in v0.16.
Please use <-isStrictTotalOrder₂ instead."
#-}
| 35.922078
| 72
| 0.58966
|
23d1fa57d3b4ef354ab711e7c61f3553d59addb0
| 38,058
|
agda
|
Agda
|
agda/Esterel/Lang/Binding.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/Esterel/Lang/Binding.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/Esterel/Lang/Binding.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module Esterel.Lang.Binding where
open import utility
open import Data.List
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.Bool
using (Bool ; true ; false ; if_then_else_)
open import Esterel.Lang
open import Esterel.Environment as Env
using (Env ; VarList ; Dom ; Θ ; _←_)
open import Esterel.Context
using (Context1 ; EvaluationContext1 ; _≐_⟦_⟧e ; _⟦_⟧e ; _≐_⟦_⟧c ; _⟦_⟧c)
open import Esterel.Context.Properties
using (plug)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ) renaming (_≟ₛₜ_ to _≟ₛₜₛ_ ; unwrap to Sunwrap)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ) renaming (_≟ₛₜ_ to _≟ₛₜₛₕ_ ; unwrap to sunwrap)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ) renaming (unwrap to vunwrap)
open import Data.Product
using (_×_ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; ∃ ; Σ)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; _≟_ ; zero ; suc)
open import Relation.Nullary
using (Dec ; yes ; no ; ¬_)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Binary
using (Decidable)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; setoid)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Data.Bool
using (not)
open import Data.List.Any as ListAny
using (Any ; any ; here ; there)
open import Data.List.Any.Properties using (∷↔)
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open ListSet Data.Nat._≟_
open _≐_⟦_⟧e
open _≐_⟦_⟧c
open Context1
open EvaluationContext1
base : VarList
base = [] ,′ [] ,′ []
+S : Signal -> VarList -> VarList
+S S' (S , s , v) = ((Sunwrap S') ∷ S , s , v)
+s : SharedVar -> VarList -> VarList
+s s' (S , s , v) = (S , sunwrap s' ∷ s , v)
+x : SeqVar -> VarList -> VarList
+x x' (S , s , v) = (S , s , vunwrap x' ∷ v)
Xs : VarList -> List ℕ
Xs (_ , _ , v) = v
Ss : VarList -> List ℕ
Ss (S , _ , _) = S
FVₑ : Expr -> VarList
FVₑ (plus []) = base
FVₑ (plus (num x ∷ x₁)) = FVₑ (plus x₁)
FVₑ (plus (seq-ref x ∷ x₁)) = +x x (FVₑ (plus x₁))
FVₑ (plus (shr-ref s ∷ x₁)) = +s s (FVₑ (plus x₁))
dist++ˡ : ∀{VL1 VL2 VL3} → (distinct VL1 (VL2 U̬ VL3)) → (distinct VL1 VL2)
dist++ˡ (a , b , c) = (dist'++ˡ a) ,(dist'++ˡ b) ,(dist'++ˡ c)
dist++ʳ : ∀{VL1 VL2 VL3} → (distinct VL1 (VL2 U̬ VL3)) → (distinct VL1 VL3)
dist++ʳ{VL1}{VL2 = (v1 , v2 , v3)}{VL3 = (V1 , V2 , V3)} (a , b , c)
= (dist'++ʳ{V2 = v1}{V3 = V1} a) , (dist'++ʳ{V2 = v2}{V3 = V2} b) , (dist'++ʳ{V2 = v3}{V3 = V3} c)
dist++b : ∀{VL1 VL2 VL3 VL4} → (distinct (VL1 U̬ VL2) (VL3 U̬ VL4)) → (distinct VL1 VL3)
dist++b (a , b , c) = (dist'++b a) , (dist'++b b) , (dist'++b c)
dist:: : ∀{VL1 VL2 S} → (distinct VL1 (+S S VL2)) → (distinct VL1 VL2)
dist::{VL1}{(Ss , s , v)}{S} (a , b , c) = dist':: a , b , c
{- This definition of CorrectBinding accumulates the bound
and free variables to make it easier to work with.
The definition of `CB` (below) matches the one in the paper. -}
data CorrectBinding : Term → (BV : VarList) → (FV : VarList) → Set where
CBnothing : CorrectBinding nothin base base
CBpause : CorrectBinding pause base base
CBsig : ∀{p S BV FV} → CorrectBinding p BV FV
→ CorrectBinding (signl S p) (+S S BV) (FV |̌ (+S S base))
CBpresent : ∀{S p q BVp FVp BVq FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ CorrectBinding (present S ∣⇒ p ∣⇒ q) (BVp U̬ BVq) (+S S (FVp U̬ FVq))
CBemit : ∀{S} → CorrectBinding (emit S) base (+S S base)
CBpar : ∀{p q BVp FVp BVq FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ (BVp≠BVq : distinct BVp BVq)
→ (FVp≠BVq : distinct FVp BVq)
→ (BVp≠FVq : distinct BVp FVq)
→ (Xp≠Xq : distinct' (Xs FVp) (Xs FVq))
→ CorrectBinding (p ∥ q) (BVp U̬ BVq) (FVp U̬ FVq)
CBloop : ∀{p BV FV}
→ CorrectBinding p BV FV
→ (BV≠FV : distinct BV FV)
→ CorrectBinding (loop p) BV FV
CBloopˢ : ∀{p q BVp FVp BVq FVq}
→ CorrectBinding p BVp FVp
→ CorrectBinding q BVq FVq
→ (BVp≠FVq : distinct BVp FVq)
→ (BVq≠FVq : distinct BVq FVq)
→ CorrectBinding (loopˢ p q) (BVp U̬ BVq) (FVp U̬ FVq)
CBseq : ∀{p q BVp BVq FVp FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ (BVp≠FVq : distinct BVp FVq)
→ CorrectBinding (p >> q) (BVp U̬ BVq) (FVp U̬ FVq)
CBsusp : ∀{S p BV FV}
→ (cbp : CorrectBinding p BV FV)
→ ([S]≠BVp : distinct' [ (Sunwrap S) ] (Ss BV))
→ CorrectBinding (suspend p S) BV (+S S FV)
CBexit : ∀{n} → CorrectBinding (exit n) base base
CBtrap : ∀{p BV FV} → CorrectBinding p BV FV → CorrectBinding (trap p) BV FV
CBshared : ∀{s e p BV FV} → CorrectBinding p BV FV
→ CorrectBinding (shared s ≔ e in: p)
(+s s BV) ((FVₑ e) U̬ (FV |̌ (+s s base)))
CBsset : ∀{s e} → CorrectBinding (s ⇐ e) base (+s s (FVₑ e))
CBvar : ∀{x e p BV FV} → CorrectBinding p BV FV
→ CorrectBinding (var x ≔ e in: p)
(+x x BV) ((FVₑ e) U̬ (FV |̌ (+x x base)))
CBvset : ∀{x e} → CorrectBinding (x ≔ e) base (+x x (FVₑ e))
CBif : ∀{x p q BVp BVq FVp FVq}
→ (cbp : CorrectBinding p BVp FVp)
→ (cbq : CorrectBinding q BVq FVq)
→ CorrectBinding (if x ∣⇒ p ∣⇒ q) (BVp U̬ BVq) (+x x (FVp U̬ FVq))
CBρ : ∀{θ A p BV FV} → CorrectBinding p BV FV
→ CorrectBinding (ρ⟨ θ , A ⟩· p) (((Dom θ) U̬ BV)) (FV |̌ (Dom θ))
binding-is-function : ∀{p BV₁ FV₁ BV₂ FV₂} →
CorrectBinding p BV₁ FV₁ →
CorrectBinding p BV₂ FV₂ →
BV₁ ≡ BV₂ × FV₁ ≡ FV₂
binding-is-function CBnothing CBnothing = refl , refl
binding-is-function CBpause CBpause = refl , refl
binding-is-function (CBsig cb₁) (CBsig cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function (CBpresent cbp₁ cbq₁) (CBpresent cbp₂ cbq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function CBemit CBemit = refl , refl
binding-is-function (CBpar cbp₁ cbq₁ BVp≠BVq₁ FVp≠BVq₁ BVp≠FVq₁ Xp≠Xq₁)
(CBpar cbp₂ cbq₂ BVp≠BVq₂ FVp≠BVq₂ BVp≠FVq₂ Xp≠Xq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBloop cb₁ BV≠FV₁)
(CBloop cb₂ BV≠FVV₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function (CBloopˢ cbp₁ cbq₁ BVp≠FVq₁ BVq≠FVq₁)
(CBloopˢ cbp₂ cbq₂ BVp≠FVq₂ BVq≠FVq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBseq cbp₁ cbq₁ BV≠FV₁) (CBseq cbp₂ cbq₂ BV≠FV₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBsusp cb₁ S∉BV₁) (CBsusp cb₂ S∉BV₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function CBexit CBexit = refl , refl
binding-is-function (CBtrap cb₁) (CBtrap cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function (CBshared cb₁) (CBshared cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function CBsset CBsset = refl , refl
binding-is-function (CBvar cb₁) (CBvar cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-is-function CBvset CBvset = refl , refl
binding-is-function (CBif cbp₁ cbq₁) (CBif cbp₂ cbq₂)
with binding-is-function cbp₁ cbp₂ | binding-is-function cbq₁ cbq₂
... | (refl , refl) | (refl , refl) = refl , refl
binding-is-function (CBρ cb₁) (CBρ cb₂)
with binding-is-function cb₁ cb₂
... | (refl , refl) = refl , refl
binding-dec : ∀ p → Dec (∃ \ BV -> ∃ \ FV -> CorrectBinding p BV FV)
binding-dec nothin = yes (base , base , CBnothing)
binding-dec pause = yes (base , base , CBpause)
binding-dec (signl S p) with binding-dec p
binding-dec (signl S p) | yes (BV , FV , CBp) =
yes (+S S BV , (FV |̌ (+S S base)) , CBsig CBp)
binding-dec (signl S p) | no ¬p = no (\ { (BV , FV , CBsig proj₃) → ¬p (_ , _ , proj₃) })
binding-dec (present S ∣⇒ p ∣⇒ q) with binding-dec p
binding-dec (present S ∣⇒ p ∣⇒ q) | yes p₂ with binding-dec q
binding-dec (present S ∣⇒ p ∣⇒ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) =
yes (BVp U̬ BVq , +S S (FVp U̬ FVq) , CBpresent CBp CBq)
binding-dec (present S ∣⇒ p ∣⇒ p₁) | yes p₂ | (no ¬p) =
no (\ { (BV , FV , CBpresent BD BD₁) → ¬p (_ , _ , BD₁) } )
binding-dec (present S ∣⇒ p ∣⇒ p₁) | no ¬p =
no (\ { (BV , FV , CBpresent BD BD₁) → ¬p (_ , _ , BD) } )
binding-dec (emit S) = yes (base , (Sunwrap S ∷ [] , [] , []) , CBemit)
binding-dec (p ∥ q) with binding-dec p
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) with binding-dec q
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) with distinct-dec BVp BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | yes BVp≠BVq = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠BVq' BVp≠BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠BVq with distinct-dec FVp BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (yes FVp≠BVq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec FVp≠BVq' FVp≠BVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) with distinct-dec BVp FVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (yes BVp≠FVq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠FVq' BVp≠FVq
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (no ¬BVp≠FVq) with distinct'-dec (Xs FVp) (Xs FVq)
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (no ¬BVp≠FVq) | (yes Xp≠Xq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p ∥ q) BV FV)
¬CB (BV₂ , FV₂ , CBpar CBp₂ CBq₂ BVp≠BVq' FVp≠BVq' BVp≠FVq' Xp≠Xq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = Xp≠Xq' (proj₁ Xp≠Xq) (proj₁ (proj₂ Xp≠Xq)) (proj₂ (proj₂ Xp≠Xq))
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (no ¬BVp≠BVq) | (no ¬FVp≠BVq) | (no ¬BVp≠FVq) | (no ¬Xp≠Xq) =
yes (BVp U̬ BVq , FVp U̬ FVq , CBpar CBp CBq (distinct-dec-is-distinct ¬BVp≠BVq)
(distinct-dec-is-distinct ¬FVp≠BVq)
(distinct-dec-is-distinct ¬BVp≠FVq)
(λ z z∈xs z∈ys → ¬Xp≠Xq (z , z∈xs , z∈ys)))
binding-dec (p ∥ q) | yes (BVp , FVp , CBp) | no ¬p =
no (\ { (BV , FV , CBpar X X₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) → ¬p (_ , _ , X₁ ) } )
binding-dec (p ∥ q) | no ¬p =
no (\ { (BV , FV , CBpar X X₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) → ¬p (_ , _ , X) } )
binding-dec (loop p) with binding-dec p
binding-dec (loop p) | yes (BV , FV , CB) with distinct-dec BV FV
binding-dec (loop p) | yes (BV , FV , CB) | yes dec = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (loop p) BV FV)
¬CB (BV₂ , FV₂ , CBloop CB₂ BV≠FV') with binding-is-function CB CB₂
... | (refl , refl) = distinct-not-distinct-dec BV≠FV' dec
binding-dec (loop p) | yes (BV , FV , CB) | no dec = yes (BV , (FV , (CBloop CB (distinct-dec-is-distinct dec))))
binding-dec (loop p) | no ¬p =
no (\ { (BV , FV , CBloop CB BV≠FV) -> ¬p (_ , _ , CB) } )
binding-dec (loopˢ p q) with binding-dec p
binding-dec (loopˢ p q) | yes (BVp , FVq , CBp ) with binding-dec q
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) with distinct-dec BVp FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | yes BVp≠FVq = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (loopˢ p q) BV FV)
¬CB (BV₂ , FV₂ , CBloopˢ CBp₂ CBq₂ BVp≠FVq₂ BVq≠FVq₂) with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠FVq₂ BVp≠FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠FVq with distinct-dec BVq FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠FVq | yes ¬BVq≠FVq = no ¬CB where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (loopˢ p q) BV FV)
¬CB (BV₂ , FV₂ , CBloopˢ CBp₂ CBq₂ BVp≠FVq₂ BVq≠FVq₂) with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVq≠FVq₂ ¬BVq≠FVq
binding-dec (loopˢ p q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no BVp≠FVq | no BVq≠FVq =
yes (BVp U̬ BVq , FVp U̬ FVq , CBloopˢ CBp CBq (distinct-dec-is-distinct BVp≠FVq) (distinct-dec-is-distinct BVq≠FVq))
binding-dec (loopˢ p q) | yes (BVp , FVq , CBp) | (no ¬CBq) =
no (\ { (BV , FV , CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) -> ¬CBq (_ , _ , CBq) } )
binding-dec (loopˢ p q) | no ¬CBp =
no (\ { (BV , FV , CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) -> ¬CBp (_ , _ , CBp) })
binding-dec (p >> q) with binding-dec p
binding-dec (p >> q) | yes (BVp , FVq , CBp ) with binding-dec q
binding-dec (p >> q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) with distinct-dec BVp FVq
binding-dec (p >> q) | yes (BVp , FVp , CBp) | (yes (BVq , FVq , CBq)) | (yes BVp≠FVq) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (p >> q) BV FV)
¬CB (BV₂ , FV₂ , CBseq CBp₂ CBq₂ BVp≠FVq') with (binding-is-function CBp CBp₂ , binding-is-function CBq CBq₂)
... | ((refl , refl) , (refl , refl)) = distinct-not-distinct-dec BVp≠FVq' BVp≠FVq
binding-dec (p >> q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) | no ¬BVp≠FVq =
yes (BVp U̬ BVq , FVp U̬ FVq , CBseq CBp CBq (distinct-dec-is-distinct ¬BVp≠FVq))
binding-dec (p >> q) | yes (BVp , FVq , CBp) | (no ¬CBq) =
no (\ { (BV , FV , CBseq CBp CBq BVp≠FVq) -> ¬CBq (_ , _ , CBq) } )
binding-dec (p >> q) | no ¬CBp =
no (\ { (BV , FV , CBseq CBp CBq BVp≠FVq) -> ¬CBp (_ , _ , CBp) })
binding-dec (suspend p S) with binding-dec p
binding-dec (suspend p S) | yes (BV , FV , CB) with distinct'-dec [ (Sunwrap S) ] (Ss BV)
binding-dec (suspend p S) | yes (BV₁ , FV₁ , CB₁) | yes ([S]≠BVp₁ , [S]≠BVp₂ , [S]≠BVp₃) = no ¬CB
where
¬CB : ¬ (∃ \ BV -> ∃ \ FV -> CorrectBinding (suspend p S) BV FV)
¬CB (BV₂ , FV₂ , CBsusp CB₃ [S]≠BVp') with (binding-is-function CB₁ CB₃)
... | refl , refl = [S]≠BVp' [S]≠BVp₁ [S]≠BVp₂ [S]≠BVp₃
binding-dec (suspend p S) | yes (BV , FV , CB) | (no ¬[S]≠BVp) =
yes (BV , +S S FV , CBsusp CB (λ z z∈xs z∈ys → ¬[S]≠BVp (z , z∈xs , z∈ys)))
binding-dec (suspend p S) | no ¬p =
no (\ { (BV , FV , CBsusp CB [S]≠BVp) -> ¬p (_ , _ , CB)})
binding-dec (trap p) with binding-dec p
binding-dec (trap p) | yes (BV , FV , CB) = yes (BV , FV , CBtrap CB)
binding-dec (trap p) | no ¬p =
no (\ { (BV , FV , CBtrap CB ) -> ¬p (BV , FV , CB) })
binding-dec (exit x) = yes (base , base , CBexit)
binding-dec (shared s ≔ e in: p) with binding-dec p
binding-dec (shared s ≔ e in: p) | yes (BV , FV , CB) =
yes (+s s BV , (FVₑ e) U̬ (FV |̌ (+s s base)) , CBshared CB)
binding-dec (shared s ≔ e in: p) | no ¬p =
no (\ { (BV , FV , CBshared CB) -> ¬p (_ , _ , CB) })
binding-dec (s ⇐ e) = yes (base , +s s (FVₑ e) , CBsset)
binding-dec (var x ≔ e in: p) with binding-dec p
binding-dec (var x ≔ e in: p) | yes (BV , FV , CB) =
yes (+x x BV , (FVₑ e) U̬ (FV |̌ (+x x base)) , CBvar CB)
binding-dec (var x ≔ e in: p) | no ¬p =
no (\ { (BV , FV , CBvar CB) -> ¬p (_ , _ , CB) } )
binding-dec (x ≔ e) = yes (base , (+x x (FVₑ e)) , CBvset)
binding-dec (if x ∣⇒ p ∣⇒ q) with binding-dec p
binding-dec (if x ∣⇒ p ∣⇒ q) | yes p₁ with binding-dec q
binding-dec (if x ∣⇒ p₁ ∣⇒ q) | yes (BVp , FVp , CBp) | yes (BVq , FVq , CBq) =
yes (BVp U̬ BVq , +x x (FVp U̬ FVq) , CBif CBp CBq)
binding-dec (if x ∣⇒ p ∣⇒ q) | yes p₁ | (no ¬p) =
no (\ { (BV , FV , CBif CBp CBq) -> ¬p (_ , _ , CBq) })
binding-dec (if x ∣⇒ p ∣⇒ q) | no ¬p =
no (\ { (BV , FV , CBif CBp CBq) -> ¬p (_ , _ , CBp) })
binding-dec (ρ⟨ θ , A ⟩· p) with binding-dec p
binding-dec (ρ⟨ θ , A ⟩· p) | yes (BV , FV , BP) =
yes (((Dom θ) U̬ BV) , FV |̌ (Dom θ) , CBρ BP)
binding-dec (ρ⟨ θ , A ⟩· p) | no ¬p = no (\ { (BV , FV , CBρ p ) -> ¬p (_ , _ , p) } )
binding-extract : ∀{p BV FV p' E} →
CorrectBinding p BV FV →
p ≐ E ⟦ p' ⟧e →
Σ (VarList × VarList) λ { (BV' , FV') → (BV' ⊆ BV × FV' ⊆ FV) × CorrectBinding p' BV' FV' }
binding-extract cb dehole =
_ , (⊆-refl , ⊆-refl) , cb
binding-extract (CBpar cbp cbq _ _ _ _) (depar₁ p≐E⟦p'⟧)
with binding-extract cbp p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ˡ BV'⊆BV , ∪ˡ FV'⊆FV) , cb*
binding-extract {_} (CBpar {BVp = BVp} {FVp = FVp} cbp cbq _ _ _ _) (depar₂ q≐E⟦q'⟧)
with binding-extract cbq q≐E⟦q'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ʳ BVp BV'⊆BV , ∪ʳ FVp FV'⊆FV) , cb*
binding-extract (CBseq cbp cbq _) (deseq p≐E⟦p'⟧)
with binding-extract cbp p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ˡ BV'⊆BV , ∪ˡ FV'⊆FV) , cb*
binding-extract (CBloopˢ cbp cbq _ _) (deloopˢ p≐E⟦p'⟧)
with binding-extract cbp p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (∪ˡ BV'⊆BV , ∪ˡ FV'⊆FV) , cb*
binding-extract (CBsusp {S = S} cb _) (desuspend p≐E⟦p'⟧)
with binding-extract cb p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (BV'⊆BV , ∪ʳ (+S S base) FV'⊆FV) , cb*
binding-extract (CBtrap cb) (detrap p≐E⟦p'⟧)
with binding-extract cb p≐E⟦p'⟧
... | (BV' , FV') , (BV'⊆BV , FV'⊆FV) , cb* = _ , (BV'⊆BV , FV'⊆FV) , cb*
binding-subst : ∀{p BVp FVp q BVq FVq r BVr FVr E} →
CorrectBinding p BVp FVp →
p ≐ E ⟦ q ⟧e →
CorrectBinding q BVq FVq →
BVr ⊆ BVq →
FVr ⊆ FVq →
CorrectBinding r BVr FVr →
Σ (VarList × VarList) λ { (BV' , FV') → (BV' ⊆ BVp × FV' ⊆ FVp) × CorrectBinding (E ⟦ r ⟧e) BV' FV' }
binding-subst (CBpar {BVq = BVq'} {FVq = FVq'} cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq')
(depar₁ p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (∪-respect-⊆-left BVp''⊆BVp' , ∪-respect-⊆-left FVp''⊆FVp') ,
CBpar cbp'' cbq'
(⊆-respect-distinct-left BVp''⊆BVp' BVp'≠BVq')
(⊆-respect-distinct-left FVp''⊆FVp' FVp'≠BVq')
(⊆-respect-distinct-left BVp''⊆BVp' BVp'≠FVq')
(⊆¹-respect-distinct'-left (proj₂ (proj₂ FVp''⊆FVp')) Xp'≠Xq')
binding-subst (CBpar {BVp = BVp'} {FVp = FVp'} cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq')
(depar₂ q'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbq' q'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVq'' , FVq'') , (BVq''⊆BVq' , FVq''⊆FVq') , cbq'' =
_ , (∪-respect-⊆-right BVp' BVq''⊆BVq' , ∪-respect-⊆-right FVp' FVq''⊆FVq') ,
CBpar cbp' cbq''
(⊆-respect-distinct-right BVq''⊆BVq' BVp'≠BVq')
(⊆-respect-distinct-right BVq''⊆BVq' FVp'≠BVq')
(⊆-respect-distinct-right FVq''⊆FVq' BVp'≠FVq')
(⊆¹-respect-distinct'-right (proj₂ (proj₂ FVq''⊆FVq')) Xp'≠Xq')
binding-subst (CBseq {BVq = BVq'} {FVq = FVq'} cbp' cbq' BV≠FV)
(deseq p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (∪-respect-⊆-left BVp''⊆BVp' , ∪-respect-⊆-left FVp''⊆FVp') ,
CBseq cbp'' cbq' (⊆-respect-distinct-left BVp''⊆BVp' BV≠FV)
binding-subst (CBloopˢ {BVq = BVq'} {FVq = FVq'} cbp' cbq' BVp≠FVq BVq≠FVq)
(deloopˢ p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (∪-respect-⊆-left BVp''⊆BVp' , ∪-respect-⊆-left FVp''⊆FVp') ,
CBloopˢ cbp'' cbq' (⊆-respect-distinct-left BVp''⊆BVp' BVp≠FVq) BVq≠FVq
binding-subst (CBsusp {S} {FV = FVp'} cbp' S∉BVp') (desuspend p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVP'') , (BVp''⊆BVp' , FVp''⊆FVp') , cbp'' =
_ , (BVp''⊆BVp' , (∪¹-respect-⊆¹-right [ Signal.unwrap S ] ,′ id ,′ id # FVp''⊆FVp')) ,
CBsusp cbp'' (⊆¹-respect-distinct'-right (proj₁ BVp''⊆BVp') S∉BVp')
binding-subst (CBtrap cbp') (detrap p'≐E⟦q⟧) cbq BVr⊆BVq FVr⊆FVq cbr
with binding-subst cbp' p'≐E⟦q⟧ cbq BVr⊆BVq FVr⊆FVq cbr
... | (BVp'' , FVp'') , ⟨BVp''⊆BVp'⟩×⟨FVp''⊆FVp'⟩ , cbp'' =
_ , ⟨BVp''⊆BVp'⟩×⟨FVp''⊆FVp'⟩ , CBtrap cbp''
binding-subst cbp dehole cbq BVr⊆BVq FVr⊆FVq cbr
with binding-is-function cbp cbq
... | (refl , refl) = _ , (BVr⊆BVq , FVr⊆FVq) , cbr
binding-extractc' : ∀{p BV FV p' C} →
CorrectBinding p BV FV →
p ≐ C ⟦ p' ⟧c →
Σ (VarList × VarList) λ { (BV' , FV') → CorrectBinding p' BV' FV' }
binding-extractc' cbp dchole =
_ , cbp
binding-extractc' (CBsig cbp) (dcsignl p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBpresent cbp cbp₁) (dcpresent₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBpresent cbp cbp₁) (dcpresent₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBpar cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) (dcpar₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBpar cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) (dcpar₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBloop cbp BV≠FV) (dcloop p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) (dcloopˢ₁ p≐C⟦p'⟧) =
binding-extractc' CBp p≐C⟦p'⟧
binding-extractc' (CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) (dcloopˢ₂ q≐C⟦q'⟧) =
binding-extractc' CBq q≐C⟦q'⟧
binding-extractc' (CBseq cbp cbp₁ BVp≠FVq) (dcseq₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBseq cbp cbp₁ BVp≠FVq) (dcseq₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBsusp cbp [S]≠BVp) (dcsuspend p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBtrap cbp) (dctrap p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBshared cbp) (dcshared p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBvar cbp) (dcvar p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBif cbp cbp₁) (dcif₁ p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-extractc' (CBif cbp cbp₁) (dcif₂ p≐C⟦p'⟧) =
binding-extractc' cbp₁ p≐C⟦p'⟧
binding-extractc' (CBρ cbp) (dcenv p≐C⟦p'⟧) =
binding-extractc' cbp p≐C⟦p'⟧
binding-substc' : ∀{p BVp FVp q BVq FVq r BVr FVr C} →
CorrectBinding p BVp FVp →
p ≐ C ⟦ q ⟧c →
CorrectBinding q BVq FVq →
BVr ⊆ BVq →
FVr ⊆ FVq →
CorrectBinding r BVr FVr →
Σ (VarList × VarList) λ { (BV' , FV') → (BV' ⊆ BVp × FV' ⊆ FVp) × CorrectBinding (C ⟦ r ⟧c) BV' FV' }
binding-substc' CBp dchole CBq BVr⊆BVq FVr⊆FVq CBr
with binding-is-function CBp CBq
... | refl , refl = _ , (BVr⊆BVq , FVr⊆FVq) , CBr
binding-substc' (CBpar cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq)
(dcpar₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , ∪-respect-⊆-left fvsub) ,
CBpar cb1 cbp₁ (⊆-respect-distinct-left bvsub BVp≠BVq)
(⊆-respect-distinct-left fvsub FVp≠BVq)
(⊆-respect-distinct-left bvsub BVp≠FVq)
(⊆¹-respect-distinct'-left (thd fvsub) Xp≠Xq)
binding-substc' (CBpar{BVp = BVp}{FVp = FVp} cbp cbp₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq)
(dcpar₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub , ∪-respect-⊆-right FVp fvsub) ,
CBpar cbp cb1 (⊆-respect-distinct-right bvsub BVp≠BVq)
(⊆-respect-distinct-right bvsub FVp≠BVq)
(⊆-respect-distinct-right fvsub BVp≠FVq)
(⊆¹-respect-distinct'-right (thd fvsub) Xp≠Xq)
binding-substc' (CBseq cbp cbp₁ BVp≠FVq)
(dcseq₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , ∪-respect-⊆-left fvsub) ,
CBseq cb1 cbp₁ (⊆-respect-distinct-left bvsub BVp≠FVq)
binding-substc' (CBseq{BVp = BVp}{FVp = FVp} cbp cbp₁ BVp≠FVq)
(dcseq₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub , ∪-respect-⊆-right FVp fvsub) ,
CBseq cbp cb1 (⊆-respect-distinct-right fvsub BVp≠FVq)
binding-substc' (CBsusp{S = S} cbp [S]≠BVp)
(dcsuspend dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (bvsub , ((∷-respect-⊆¹ (Signal.unwrap S)) , id , id # fvsub)) ,
CBsusp cb1 (⊆¹-respect-distinct'-right (fst bvsub) [S]≠BVp)
binding-substc' (CBtrap CBp) (dctrap dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' CBp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (bvsub , fvsub) , CBtrap cb1
binding-substc' (CBsig{S = S ₛ} cbp) (dcsignl dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (((∷-respect-⊆¹ S) , id , id # bvsub) ,
⊆-respect-|̌ (+S (S ₛ) base) fvsub),
CBsig cb1
binding-substc' (CBpresent{S = S ₛ} cbp cbp₁)
(dcpresent₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub ,
((∷-respect-⊆¹ S) , id , id # (∪-respect-⊆-left fvsub))) ,
CBpresent cb1 cbp₁
binding-substc' (CBpresent{S = S ₛ}{BVp = BVp}{FVp = FVp} cbp cbp₁)
(dcpresent₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub ,
((∷-respect-⊆¹ S) , id , id # (∪-respect-⊆-right FVp fvsub))) ,
CBpresent cbp cb1
binding-substc' (CBloop cbp BV≠FV)
(dcloop dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right base bvsub , fvsub) ,
CBloop cb1 (⊆-respect-distinct-left bvsub
(⊆-respect-distinct-right fvsub BV≠FV))
binding-substc' (CBloopˢ cbp cbp₁ BVp≠FVq BVq≠FVq)
(dcloopˢ₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , ∪-respect-⊆-left fvsub) ,
CBloopˢ cb1 cbp₁ (⊆-respect-distinct-left bvsub BVp≠FVq) BVq≠FVq
binding-substc' (CBloopˢ{BVp = BVp}{FVp = FVp} cbp cbp₁ BVp≠FVq BVq≠FVq)
(dcloopˢ₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub , ∪-respect-⊆-right FVp fvsub) ,
CBloopˢ cbp cb1 (⊆-respect-distinct-right fvsub BVp≠FVq)
(⊆-respect-distinct-left bvsub
(⊆-respect-distinct-right fvsub BVq≠FVq))
binding-substc' (CBshared{s = s}{e = e} cbp)
(dcshared dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (((id , (∷-respect-⊆¹ (SharedVar.unwrap s)) , id # bvsub)) ,
∪-respect-⊆-right (FVₑ e) (⊆-respect-|̌ (+s s base) fvsub)) ,
CBshared cb1
binding-substc' (CBvar{x = x}{e = e} cbp) (dcvar dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (((id , id , (∷-respect-⊆¹ (SeqVar.unwrap x)) # bvsub)) ,
∪-respect-⊆-right (FVₑ e) (⊆-respect-|̌ (+x x base) fvsub)) ,
CBvar cb1
binding-substc' (CBif{x = x ᵥ} cbp cbp₁) (dcif₁ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-left bvsub , (id , id , (∷-respect-⊆¹ x) # (∪-respect-⊆-left fvsub))) ,
CBif cb1 cbp₁
binding-substc' (CBif{x = x ᵥ}{BVp = BVp}{FVp = FVp} cbp cbp₁)
(dcif₂ dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp₁ dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right BVp bvsub ,
(id , id , (∷-respect-⊆¹ x) # (∪-respect-⊆-right FVp fvsub))) ,
CBif cbp cb1
binding-substc' (CBρ{θ = θ} cbp) (dcenv dc) CBq BVr⊆BVq FVr⊆FVq CBr
with binding-substc' cbp dc CBq BVr⊆BVq FVr⊆FVq CBr
... | _ , (bvsub , fvsub) , cb1 =
_ , (∪-respect-⊆-right (Dom θ) bvsub , ⊆-respect-|̌ (Dom θ) fvsub) ,
CBρ cb1
-- In the decomposition E ⟦ p ⟧e, the bound variables in p and the free
-- variables in E must be disjoint.
distinct-term-context-help : ∀ {BV FV BVp FVp BVnothin FVnothin} p E →
CorrectBinding (E ⟦ p ⟧e) BV FV →
CorrectBinding p BVp FVp →
(BVp ⊆ BV) →
CorrectBinding (E ⟦ nothin ⟧e) BVnothin FVnothin →
distinct BVp FVnothin
distinct-term-context-help p [] cb cbp BVp⊆BV CBnothing =
(λ _ _ ()) ,′ (λ _ _ ()) ,′ (λ _ _ ())
distinct-term-context-help p (epar₁ q ∷ E)
(CBpar cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq') cbp BVp⊆BV
(CBpar cbnothinp cbnothinq BVp≠BVq₁ FVp≠BVq₁ BVp≠FVq₁ Xp≠Xq₁)
with binding-extract cbp' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbq' cbnothinq
... | refl , refl | refl , refl =
distinct-union-right
(distinct-term-context-help p E cbp' cbp BV'⊆BVE⟦p⟧ cbnothinp)
(⊆-respect-distinct-left BV'⊆BVE⟦p⟧ BVp'≠FVq')
distinct-term-context-help p (epar₂ p₁ ∷ E)
(CBpar cbp' cbq' BVp'≠BVq' FVp'≠BVq' BVp'≠FVq' Xp'≠Xq') cbp BVp⊆BV
(CBpar {FVq = FVnothinq} cbnothinp cbnothinq BVp≠BVq₁ FVp≠BVq₁ BVp≠FVq₁ Xp≠Xq₁)
with binding-extract cbq' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbp' cbnothinp
... | refl , refl | refl , refl =
⊆-respect-distinct-right
(∪-comm-⊆-right FVnothinq ⊆-refl)
(distinct-union-right
(distinct-term-context-help p E cbq' cbp BV'⊆BVE⟦p⟧ cbnothinq)
(⊆-respect-distinct-left BV'⊆BVE⟦p⟧ (distinct-sym FVp'≠BVq')))
distinct-term-context-help p (eseq q ∷ E)
(CBseq {BVp = BVE⟦p⟧p} {FVp = FVE⟦p⟧p} cbp' cbq' BVp'≠FVq') cbp BVp⊆BV
(CBseq {BVp = BVnothinp} {BVq = BVnothinq} {FVp = FVnothinp} {FVq = FVnothinq}
cbnothinp cbnothinq BVp≠FVq)
with binding-extract cbp' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbq' cbnothinq
... | refl , refl | refl , refl =
distinct-union-right
(distinct-term-context-help p E cbp' cbp BV'⊆BVE⟦p⟧ cbnothinp)
(⊆-respect-distinct-left
BV'⊆BVE⟦p⟧
(distinct-sym (dist++ˡ (distinct-sym (distinct-union-left BVp'≠FVq' BVp≠FVq)))))
distinct-term-context-help p (eloopˢ q ∷ E)
(CBloopˢ {BVp = BVE⟦p⟧p} {FVp = FVE⟦p⟧p} cbp' cbq' BVp'≠FVq' BVq'≠FVq') cbp BVp⊆BV
(CBloopˢ {BVp = BVnothinp} {FVp = FVnothinp} {BVq = BVnothinq} {FVq = FVnothinq}
cbnothinp cbnothinq BVp≠FVq BVq≠FVq)
with binding-extract cbp' (((E ⟦ p ⟧e) ≐ E ⟦ p ⟧e) ∋ plug refl)
... | (BV' , FV') , (BV'⊆BVE⟦p⟧ , FV'⊆FVE⟦p⟧) , cbp*
with binding-is-function cbp cbp* | binding-is-function cbq' cbnothinq
... | refl , refl | refl , refl =
distinct-union-right
(distinct-term-context-help p E cbp' cbp BV'⊆BVE⟦p⟧ cbnothinp)
(⊆-respect-distinct-left
BV'⊆BVE⟦p⟧
(distinct-sym (dist++ˡ (distinct-sym (distinct-union-left BVp'≠FVq' BVp≠FVq)))))
distinct-term-context-help {BVp = BVp} p (esuspend S ∷ E)
(CBsusp cb [S]≠BVp) cbp BVp⊆BV
(CBsusp {FV = FV} cbnothin [S]≠BVp₁) = BVp≠S∷FV ,′ id ,′ id # dist
where dist = distinct-term-context-help p E cb cbp BVp⊆BV cbnothin
BVp≠S∷FV : (typeof (proj₁ dist)) → ∀ S' → S' ∈ (proj₁ BVp) → S' ∈ (Signal.unwrap S ∷ proj₁ FV) → ⊥
BVp≠S∷FV BVp≠FV S' S'∈BVp (here refl) = [S]≠BVp S' (here refl) (proj₁ BVp⊆BV S' S'∈BVp)
BVp≠S∷FV BVp≠FV S' S'∈BVp (there S'∈FV) = BVp≠FV S' S'∈BVp S'∈FV
distinct-term-context-help p (etrap ∷ E)
(CBtrap cb) cbp BVp⊆BV
(CBtrap cbnothin) =
distinct-term-context-help p E cb cbp BVp⊆BV cbnothin
BVars : ∀ (p : Term) -> VarList
BVars nothin = base
BVars pause = base
BVars (signl S p) = +S S (BVars p)
BVars (present S ∣⇒ p ∣⇒ q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (emit S) = base
BVars (p ∥ q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (loop p) = BV where
BV = BVars p
BVars (loopˢ p q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (p >> q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (suspend p S) = BVars p
BVars (trap p) = BVars p
BVars (exit x) = base
BVars (shared s ≔ e in: p) = +s s (BVars p)
BVars (s ⇐ e) = base
BVars (var x ≔ e in: p) = +x x (BVars p)
BVars (x ≔ e) = base
BVars (if x ∣⇒ p ∣⇒ q) = BVp U̬ BVq where
BVp = BVars p
BVq = BVars q
BVars (ρ⟨ θ , A ⟩· p) = (Dom θ) U̬ BV where
BV = BVars p
FVars : ∀ (p : Term) -> VarList
FVars nothin = base
FVars pause = base
FVars (signl S p) = FV |̌ (+S S base) where
FV = FVars p
FVars (present S ∣⇒ p ∣⇒ q) = +S S (FVp U̬ FVq) where
FVp = FVars p
FVq = FVars q
FVars (emit S) = +S S base
FVars (p ∥ q) = FVp U̬ FVq where
FVp = FVars p
FVq = FVars q
FVars (loop p) = FVars p
FVars (loopˢ p q) = FVp U̬ FVq where
FVp = FVars p
FVq = FVars q
FVars (p >> q) = FVp U̬ FVq where
FVp = FVars p
FVq = FVars q
FVars (suspend p S) = +S S (FVars p)
FVars (trap p) = FVars p
FVars (exit x) = base
FVars (shared s ≔ e in: p) = (FVₑ e) U̬ (FV |̌ (+s s base)) where
FV = FVars p
FVars (s ⇐ e) = +s s (FVₑ e) where
FVars (var x ≔ e in: p) = (FVₑ e) U̬ (FV |̌ (+x x base)) where
FV = FVars p
FVars (x ≔ e) = +x x (FVₑ e)
FVars (if x ∣⇒ p ∣⇒ q) = +x x (FVp U̬ FVq) where
FVp = FVars p
FVq = FVars q
FVars (ρ⟨ θ , A ⟩· p) = FV |̌ (Dom θ) where
FV = FVars p
CB : Term -> Set
CB p = CorrectBinding p (BVars p) (FVars p)
BVFVcorrect : ∀ p BV FV -> CorrectBinding p BV FV -> BVars p ≡ BV × FVars p ≡ FV
BVFVcorrect .nothin .([] , [] , []) .([] , [] , []) CBnothing = refl , refl
BVFVcorrect .pause .([] , [] , []) .([] , [] , []) CBpause = refl , refl
BVFVcorrect .(signl _ _) .(+S S BV) .(FV |̌ (+S S base))
(CBsig{p}{S}{BV}{FV} CB) with BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(present _ ∣⇒ _ ∣⇒ _) .(BVp U̬ BVq) .(+S S (FVp U̬ FVq))
(CBpresent{S}{p}{q}{BVp}{FVp}{BVq}{FVq} CBp CBq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(emit _) _ _ CBemit = refl , refl
BVFVcorrect .(_ ∥ _) .(BVp U̬ BVq) .(FVp U̬ FVq)
(CBpar{p}{q}{BVp}{FVp}{BVq}{FVq} CBp CBq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(loop _) .BV .FV
(CBloop{p}{BV}{FV} CB BV≠FV) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(loopˢ _ _) .(BVp U̬ BVq) .(FVp U̬ FVq)
(CBloopˢ{p}{q}{BVp}{FVp}{BVq}{FVq} CBp CBq BVp≠FVq BVq≠FVq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(_ >> _) .(BVp U̬ BVq) .(FVp U̬ FVq)
(CBseq{p}{q}{BVp}{BVq}{FVp}{FVq} CBp CBq BVp≠FVq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(suspend _ _) .BV .(+S S FV)
(CBsusp{S}{p}{BV}{FV} CB [S]≠BVp) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(trap _) .BV .FV (CBtrap{p}{BV}{FV} CB) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(exit _) .([] , [] , []) .([] , [] , []) CBexit = refl , refl
BVFVcorrect .(shared _ ≔ _ in: _) .(+s s BV) .((FVₑ e) U̬ (FV |̌ (+s s base)))
(CBshared{s}{e}{p}{BV}{FV} CB) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(_ ⇐ _) .([] , [] , []) .(+s s (FVₑ e)) (CBsset{s}{e}) = refl , refl
BVFVcorrect .(var _ ≔ _ in: _) .(+x x BV) .((FVₑ e) U̬ (FV |̌ (+x x base)))
(CBvar{x}{e}{p}{BV}{FV} CB) with
BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
BVFVcorrect .(_ ≔ _) .([] , [] , []) .(+x x (FVₑ e)) (CBvset{x}{e}) = refl , refl
BVFVcorrect .(if _ ∣⇒ _ ∣⇒ _) .(BVp U̬ BVq) .(+x x (FVp U̬ FVq))
(CBif{x}{p}{q}{BVp}{BVq}{FVp}{FVq} CBp CBq) with
BVFVcorrect p BVp FVp CBp | BVFVcorrect q BVq FVq CBq
... | refl , refl | refl , refl = refl , refl
BVFVcorrect .(ρ⟨ _ , _ ⟩· _) .(((Dom θ) U̬ BV)) .(FV |̌ (Dom θ))
(CBρ{θ}{A}{p}{BV}{FV} CB) with BVFVcorrect p BV FV CB
... | refl , refl = refl , refl
| 47.043263
| 154
| 0.575043
|
dfe66f556d425d1efaebc85a51135359670aff0c
| 4,965
|
agda
|
Agda
|
braun-tree.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
braun-tree.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
braun-tree.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
open import bool
module braun-tree{ℓ} (A : Set ℓ) (_<A_ : A → A → 𝔹) where
open import bool-thms
open import eq
open import list
open import nat
open import nat-thms
open import product
open import sum
-- the index n is the size of the tree (number of elements of type A)
data braun-tree : (n : ℕ) → Set ℓ where
bt-empty : braun-tree 0
bt-node : ∀ {n m : ℕ} →
A → braun-tree n → braun-tree m →
n ≡ m ∨ n ≡ suc m →
braun-tree (suc (n + m))
{- we will keep smaller (_<A_) elements closer to the root of the Braun tree as we insert -}
bt-insert : ∀ {n : ℕ} → A → braun-tree n → braun-tree (suc n)
bt-insert a bt-empty = bt-node a bt-empty bt-empty (inj₁ refl)
bt-insert a (bt-node{n}{m} a' l r p)
rewrite +comm n m with p | if a <A a' then (a , a') else (a' , a)
bt-insert a (bt-node{n}{m} a' l r _) | inj₁ p | (a1 , a2)
rewrite p = (bt-node a1 (bt-insert a2 r) l (inj₂ refl))
bt-insert a (bt-node{n}{m} a' l r _) | inj₂ p | (a1 , a2) =
(bt-node a1 (bt-insert a2 r) l (inj₁ (sym p)))
bt-replace-min : ∀{n : ℕ} → A → braun-tree (suc n) → braun-tree (suc n)
bt-replace-min a (bt-node _ bt-empty bt-empty u) = (bt-node a bt-empty bt-empty u)
bt-replace-min a (bt-node _ bt-empty (bt-node _ _ _ _) (inj₁ ()))
bt-replace-min a (bt-node _ bt-empty (bt-node _ _ _ _) (inj₂ ()))
bt-replace-min a (bt-node _ (bt-node _ _ _ _) bt-empty (inj₁ ()))
bt-replace-min a (bt-node a' (bt-node x l r u) bt-empty (inj₂ y)) with a <A x
bt-replace-min a (bt-node a' (bt-node x l r u) bt-empty (inj₂ y)) | tt = (bt-node a (bt-node x l r u) bt-empty (inj₂ y))
bt-replace-min a (bt-node a' (bt-node x l r u) bt-empty (inj₂ y)) | ff =
(bt-node x (bt-replace-min a (bt-node x l r u)) bt-empty (inj₂ y))
bt-replace-min a (bt-node a' (bt-node x l r u) (bt-node x' l' r' u') v) with a <A x && a <A x'
bt-replace-min a (bt-node a' (bt-node x l r u) (bt-node x' l' r' u') v) | tt =
(bt-node a (bt-node x l r u) (bt-node x' l' r' u') v)
bt-replace-min a (bt-node a' (bt-node x l r u) (bt-node x' l' r' u') v) | ff with x <A x'
bt-replace-min a (bt-node a' (bt-node x l r u) (bt-node x' l' r' u') v) | ff | tt =
(bt-node x (bt-replace-min a (bt-node x l r u)) (bt-node x' l' r' u') v)
bt-replace-min a (bt-node a' (bt-node x l r u) (bt-node x' l' r' u') v) | ff | ff =
(bt-node x' (bt-node x l r u) (bt-replace-min a (bt-node x' l' r' u')) v)
{- thanks to Matías Giovannini for the excellent post
http://alaska-kamtchatka.blogspot.com/2010/02/braun-trees.html
explaining how to do delete -}
bt-delete-min : ∀ {p : ℕ} → braun-tree (suc p) → braun-tree p
bt-delete-min (bt-node a bt-empty bt-empty u) = bt-empty
bt-delete-min (bt-node a bt-empty (bt-node _ _ _ _) (inj₁ ()))
bt-delete-min (bt-node a bt-empty (bt-node _ _ _ _) (inj₂ ()))
bt-delete-min (bt-node a (bt-node{n'}{m'} a' l' r' u') bt-empty u) rewrite +0 (n' + m') = bt-node a' l' r' u'
bt-delete-min (bt-node a
(bt-node{n}{m} x l1 r1 u1)
(bt-node{n'}{m'} x' l2 r2 u2) u)
rewrite +suc(n + m)(n' + m') | +suc n (m + (n' + m'))
| +comm(n + m)(n' + m') =
if (x <A x') then
(bt-node x (bt-node x' l2 r2 u2)
(bt-delete-min (bt-node x l1 r1 u1)) (lem{n}{m}{n'}{m'} u))
else
(bt-node x' (bt-replace-min x (bt-node x' l2 r2 u2))
(bt-delete-min (bt-node x l1 r1 u1)) (lem{n}{m}{n'}{m'} u))
where lem : {n m n' m' : ℕ} → suc (n + m) ≡ suc (n' + m') ∨ suc (n + m) ≡ suc (suc (n' + m')) →
suc (n' + m') ≡ n + m ∨ suc (n' + m') ≡ suc (n + m)
lem{n}{m}{n'}{m'} (inj₁ x) = inj₂ (sym x)
lem (inj₂ y) = inj₁ (sym (suc-inj y))
bt-remove-min : ∀ {p : ℕ} → braun-tree (suc p) → A × braun-tree p
bt-remove-min (bt-node a l r u) = a , bt-delete-min (bt-node a l r u)
----------------------------------------------------------------------
-- this version stores data at the leaves instead of at the nodes
----------------------------------------------------------------------
data braun-tree' : (n : ℕ) → Set ℓ where
bt'-leaf : A → braun-tree' 1
bt'-node : ∀ {n m : ℕ} →
braun-tree' n → braun-tree' m →
n =ℕ m ≡ tt ⊎ n =ℕ m + 1 ≡ tt →
braun-tree' (n + m)
bt'-insert : ∀ {n : ℕ} → A → braun-tree' n → braun-tree' (suc n)
bt'-insert a (bt'-leaf a') = bt'-node (bt'-leaf a) (bt'-leaf a') (inj₁ refl)
bt'-insert a (bt'-node{n}{m} l r p) rewrite +comm n m with p
bt'-insert a (bt'-node{n}{m} l r p) | inj₁ p' rewrite =ℕ-to-≡{n} p' = (bt'-node (bt'-insert a r) l (inj₂ lem))
where lem : suc m =ℕ m + 1 ≡ tt
lem rewrite +comm m 1 = =ℕ-refl m
bt'-insert a (bt'-node{n}{m} l r p) | inj₂ p' = (bt'-node (bt'-insert a r) l (inj₁ (lem n m p')))
where lem : ∀ n m → n =ℕ m + 1 ≡ tt → suc m =ℕ n ≡ tt
lem n m p' rewrite =ℕ-to-≡{n} p' | +comm m 1 = =ℕ-refl m
𝕃-to-braun-tree' : A → (l : 𝕃 A) → braun-tree' (suc (length l))
𝕃-to-braun-tree' a [] = bt'-leaf a
𝕃-to-braun-tree' a (a' :: as) = bt'-insert a (𝕃-to-braun-tree' a' as)
| 48.676471
| 120
| 0.536354
|
cb43bef5b1b2ed07e5c6f3a7649d243ad431013b
| 7,522
|
agda
|
Agda
|
Categories/Yoneda.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Yoneda.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Yoneda.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Yoneda where
-- Yoneda Lemma. In total, provides:
-- * the Yoneda Embedding (called embed here) from any Category C into Presheaves C
-- Worth noticing that there is no 'locally small' condition here; however, if one looks at
-- the levels involved, there is indeed a raise from that of C to that of Presheaves C.
-- * The traditional Yoneda lemma (yoneda-inverse) which says that for any object a of C, and
-- any Presheaf F over C (where our presheaves are over Setoids), then
-- Hom[ Presheaves C] (Functor.F₀ embed a , F) ≅ Functor.F₀ F a
-- as Setoids. In addition, Yoneda (yoneda) also says that this isomorphism is natural in a and F.
open import Level
open import Function using (_$_; Inverse) -- else there's a conflict with the import below
open import Function.Equality using (Π; _⟨$⟩_; cong)
open import Relation.Binary using (module Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
open import Data.Product using (_,_; Σ)
open import Categories.Category using (Category; _[_,_])
open import Categories.Category.Product
open import Categories.Category.Construction.Presheaves
open import Categories.Category.Construction.Functors
open import Categories.Category.Instance.Setoids
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Hom using (module Hom; Hom[_][-,_]; Hom[_][-,-])
open import Categories.Functor.Bifunctor
open import Categories.Functor.Presheaf
open import Categories.Functor.Construction.LiftSetoids
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
import Categories.NaturalTransformation.Hom as NT-Hom
private
variable
o ℓ e : Level
module Yoneda (C : Category o ℓ e) where
open Category C
open HomReasoning
open MR C
open Functor
open NaturalTransformation
open NT-Hom C
private
module CE = Category.Equiv C
module C = Category C
-- The Yoneda embedding functor
embed : Functor C (Presheaves C)
embed = record
{ F₀ = Hom[ C ][-,_]
; F₁ = Hom[A,C]⇒Hom[B,C] -- A⇒B induces a NatTrans on the Homs.
; identity = identityˡ ○_
; homomorphism = λ h₁≈h₂ → ∘-resp-≈ʳ h₁≈h₂ ○ assoc
; F-resp-≈ = λ f≈g h≈i → ∘-resp-≈ f≈g h≈i
}
-- Using the adjunction between product and product, we get a kind of contravariant Bifunctor
yoneda-inverse : (a : Obj) (F : Presheaf C (Setoids ℓ e)) →
Inverse (Category.hom-setoid (Presheaves C) {Functor.F₀ embed a} {F}) (Functor.F₀ F a)
yoneda-inverse a F = record
{ f = λ nat → η nat a ⟨$⟩ id
; f⁻¹ = λ x → ntHelper record
{ η = λ X → record
{ _⟨$⟩_ = λ X⇒a → F₁ F X⇒a ⟨$⟩ x
; cong = λ i≈j → F-resp-≈ F i≈j SE.refl
}
; commute = λ {X} {Y} Y⇒X {f} {g} f≈g →
let module SFY = Setoid (F₀ F Y) in
let module SR = SetoidR (F₀ F Y) in
SR.begin
F₁ F (id ∘ f ∘ Y⇒X) ⟨$⟩ x SR.≈⟨ F-resp-≈ F (identityˡ ○ ∘-resp-≈ˡ f≈g) (SE.refl {x}) ⟩
F₁ F (g ∘ Y⇒X) ⟨$⟩ x SR.≈⟨ homomorphism F SE.refl ⟩
F₁ F Y⇒X ⟨$⟩ (F₁ F g ⟨$⟩ x)
SR.∎
}
; cong₁ = λ i≈j → i≈j CE.refl
; cong₂ = λ i≈j y≈z → F-resp-≈ F y≈z i≈j
; inverse = (λ Fa → identity F SE.refl) , λ nat {x} {z} z≈y →
let module S = Setoid (F₀ F x) in
S.trans (S.sym (commute nat z CE.refl))
(cong (η nat x) (identityˡ ○ identityˡ ○ z≈y))
}
where module SE = Setoid (F₀ F a)
private
-- in this bifunctor, a presheaf from Presheaves C goes from C to Setoids ℓ e,
-- but the over Setoids has higher level than the hom setoids.
Nat[Hom[C][-,c],F] : Bifunctor (Presheaves C) (Category.op C) (Setoids _ _)
Nat[Hom[C][-,c],F] = Hom[ Presheaves C ][-,-] ∘F (Functor.op embed ∘F πʳ ※ πˡ)
-- in this bifunctor, it needs to go from Presheaves which maps C to Setoids ℓ e,
-- so the universe level needs to be lifted.
FC : Bifunctor (Presheaves C) (Category.op C) (Setoids _ _)
FC = LiftSetoids (o ⊔ ℓ ⊔ e) (o ⊔ ℓ) ∘F eval {C = Category.op C} {D = Setoids ℓ e}
module yoneda-inverse {a} {F} = Inverse (yoneda-inverse a F)
-- the two bifunctors above are naturally isomorphic.
-- it is easy to show yoneda-inverse first then to yoneda.
yoneda : NaturalIsomorphism Nat[Hom[C][-,c],F] FC
yoneda = record
{ F⇒G = ntHelper record
{ η = λ where
(F , A) → record
{ _⟨$⟩_ = λ α → lift (yoneda-inverse.f α)
; cong = λ i≈j → lift (i≈j CE.refl)
}
; commute = λ where
{_} {G , B} (α , f) {β} {γ} β≈γ → lift $ cong (η α B) (helper f β γ β≈γ)
}
; F⇐G = ntHelper record
{ η = λ where
(F , A) → record
{ _⟨$⟩_ = λ where
(lift x) → yoneda-inverse.f⁻¹ x
; cong = λ where
(lift i≈j) y≈z → F-resp-≈ F y≈z i≈j
}
; commute = λ where
(α , f) (lift eq) eq′ → helper′ α f eq eq′
}
; iso = λ where
(F , A) → record
{ isoˡ = λ {α β} i≈j {X} y≈z →
let module S = Setoid (F₀ F X)
in S.trans ( yoneda-inverse.inverseʳ α {x = X} y≈z) (i≈j CE.refl)
; isoʳ = λ where
(lift eq) →
let module S = Setoid (F₀ F A)
in lift (S.trans ( yoneda-inverse.inverseˡ {F = F} _) eq)
}
}
where helper : ∀ {F : Functor (Category.op C) (Setoids ℓ e)}
{A B : Obj} (f : B ⇒ A)
(β γ : NaturalTransformation Hom[ C ][-, A ] F) →
Setoid._≈_ (F₀ Nat[Hom[C][-,c],F] (F , A)) β γ →
Setoid._≈_ (F₀ F B) (η β B ⟨$⟩ f ∘ id) (F₁ F f ⟨$⟩ (η γ A ⟨$⟩ id))
helper {F} {A} {B} f β γ β≈γ = S.begin
η β B ⟨$⟩ f ∘ id S.≈⟨ cong (η β B) (id-comm ○ (⟺ identityˡ)) ⟩
η β B ⟨$⟩ id ∘ id ∘ f S.≈⟨ commute β f CE.refl ⟩
F₁ F f ⟨$⟩ (η β A ⟨$⟩ id) S.≈⟨ cong (F₁ F f) (β≈γ CE.refl) ⟩
F₁ F f ⟨$⟩ (η γ A ⟨$⟩ id) S.∎
where module S where
open Setoid (F₀ F B) public
open SetoidR (F₀ F B) public
helper′ : ∀ {F G : Functor (Category.op C) (Setoids ℓ e)}
{A B Z : Obj}
{h i : Z ⇒ B}
{X Y : Setoid.Carrier (F₀ F A)}
(α : NaturalTransformation F G)
(f : B ⇒ A) →
Setoid._≈_ (F₀ F A) X Y →
h ≈ i →
Setoid._≈_ (F₀ G Z) (F₁ G h ⟨$⟩ (η α B ⟨$⟩ (F₁ F f ⟨$⟩ X)))
(η α Z ⟨$⟩ (F₁ F (f ∘ i) ⟨$⟩ Y))
helper′ {F} {G} {A} {B} {Z} {h} {i} {X} {Y} α f eq eq′ = S.begin
F₁ G h ⟨$⟩ (η α B ⟨$⟩ (F₁ F f ⟨$⟩ X)) S.≈˘⟨ commute α h (S′.sym (cong (F₁ F f) eq)) ⟩
η α Z ⟨$⟩ (F₁ F h ⟨$⟩ (F₁ F f ⟨$⟩ Y)) S.≈⟨ cong (η α Z) (F-resp-≈ F eq′ S′.refl) ⟩
η α Z ⟨$⟩ (F₁ F i ⟨$⟩ (F₁ F f ⟨$⟩ Y)) S.≈˘⟨ cong (η α Z) (homomorphism F (Setoid.refl (F₀ F A))) ⟩
η α Z ⟨$⟩ (F₁ F (f ∘ i) ⟨$⟩ Y) S.∎
where module S where
open Setoid (F₀ G Z) public
open SetoidR (F₀ G Z) public
module S′ = Setoid (F₀ F B)
module yoneda = NaturalIsomorphism yoneda
| 43.732558
| 110
| 0.541345
|
1ca4300ec7654b51b3cfd2bfc2c904178e5facc8
| 2,146
|
agda
|
Agda
|
src/FLA/Algebra/Properties/Field.agda
|
iblech/functional-linear-algebra
|
0ba4d1d145575f1d23806a7c0e57bc8800554c16
|
[
"BSD-3-Clause"
] | 21
|
2020-09-22T20:49:34.000Z
|
2022-01-07T05:28:00.000Z
|
src/FLA/Algebra/Properties/Field.agda
|
iblech/functional-linear-algebra
|
0ba4d1d145575f1d23806a7c0e57bc8800554c16
|
[
"BSD-3-Clause"
] | 6
|
2020-09-01T01:42:12.000Z
|
2022-01-07T05:27:53.000Z
|
src/FLA/Algebra/Properties/Field.agda
|
iblech/functional-linear-algebra
|
0ba4d1d145575f1d23806a7c0e57bc8800554c16
|
[
"BSD-3-Clause"
] | 3
|
2021-04-12T20:34:17.000Z
|
2021-09-07T19:55:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Level using (Level)
open import FLA.Algebra.Structures
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
module FLA.Algebra.Properties.Field {ℓ : Level } {A : Set ℓ} ⦃ F : Field A ⦄ where
open Field F
0ᶠ+0ᶠ≡0ᶠ : 0ᶠ + 0ᶠ ≡ 0ᶠ
0ᶠ+0ᶠ≡0ᶠ = +0ᶠ 0ᶠ
0ᶠ+ : (a : A) → 0ᶠ + a ≡ a
0ᶠ+ a rewrite +-comm 0ᶠ a = +0ᶠ a
a*0ᶠ≡0ᶠ : (a : A) → a * 0ᶠ ≡ 0ᶠ
a*0ᶠ≡0ᶠ a = begin
a * 0ᶠ ≡˘⟨ 0ᶠ+ (a * 0ᶠ) ⟩
0ᶠ + a * 0ᶠ ≡⟨ cong (_+ a * 0ᶠ) (sym (+-inv a)) ⟩
- a + a + a * 0ᶠ ≡⟨ cong (λ x → - a + x + a * 0ᶠ) (sym (*1ᶠ a)) ⟩
- a + a * 1ᶠ + a * 0ᶠ ≡˘⟨ +-assoc (- a) (a * 1ᶠ) (a * 0ᶠ) ⟩
- a + (a * 1ᶠ + a * 0ᶠ) ≡⟨ cong (- a +_) (sym (*-distr-+ a 1ᶠ 0ᶠ)) ⟩
- a + (a * (1ᶠ + 0ᶠ)) ≡⟨ cong (λ x → - a + (a * x)) (+0ᶠ 1ᶠ) ⟩
- a + (a * 1ᶠ) ≡⟨ cong (- a +_) (*1ᶠ a) ⟩
- a + a ≡⟨ +-inv a ⟩
0ᶠ ∎
0ᶠ*a≡0ᶠ : (a : A) → 0ᶠ * a ≡ 0ᶠ
0ᶠ*a≡0ᶠ a = trans (*-comm 0ᶠ a) (a*0ᶠ≡0ᶠ a)
-a≡-1ᶠ*a : (a : A) → - a ≡ - 1ᶠ * a
-a≡-1ᶠ*a a = begin
- a ≡˘⟨ +0ᶠ (- a) ⟩
- a + 0ᶠ ≡⟨ cong (- a +_) (sym (a*0ᶠ≡0ᶠ a)) ⟩
- a + (a * 0ᶠ) ≡⟨ cong (λ x → - a + (a * x)) (sym (+-inv 1ᶠ)) ⟩
- a + (a * (- 1ᶠ + 1ᶠ)) ≡⟨ cong (- a +_) (*-distr-+ a (- 1ᶠ) 1ᶠ) ⟩
- a + (a * - 1ᶠ + a * 1ᶠ) ≡⟨ cong (- a +_) (+-comm (a * - 1ᶠ) (a * 1ᶠ)) ⟩
- a + (a * 1ᶠ + a * - 1ᶠ ) ≡⟨ +-assoc (- a) (a * 1ᶠ) (a * - 1ᶠ) ⟩
- a + a * 1ᶠ + a * - 1ᶠ ≡⟨ cong (λ x → - a + x + a * - 1ᶠ) (*1ᶠ a) ⟩
- a + a + a * - 1ᶠ ≡⟨ cong (_+ a * - 1ᶠ) (+-inv a) ⟩
0ᶠ + a * - 1ᶠ ≡⟨ 0ᶠ+ (a * - 1ᶠ) ⟩
a * - 1ᶠ ≡⟨ *-comm a (- 1ᶠ) ⟩
- 1ᶠ * a ∎
-a*b≡-[a*b] : (a b : A) → - a * b ≡ - (a * b)
-a*b≡-[a*b] a b = begin
- a * b ≡⟨ cong (_* b) (-a≡-1ᶠ*a a) ⟩
(- 1ᶠ * a) * b ≡˘⟨ *-assoc (- 1ᶠ) a b ⟩
- 1ᶠ * (a * b) ≡˘⟨ -a≡-1ᶠ*a ((a * b)) ⟩
- (a * b) ∎
a*-b≡-[a*b] : (a b : A) → a * - b ≡ - (a * b)
a*-b≡-[a*b] a b = begin
a * - b ≡⟨ *-comm a (- b) ⟩
- b * a ≡⟨ -a*b≡-[a*b] b a ⟩
- (b * a) ≡⟨ cong -_ (*-comm b a) ⟩
- (a * b) ∎
| 35.180328
| 82
| 0.345294
|
d0da2b5459e2a7ad28aec724e69b113e1ad50379
| 8,505
|
agda
|
Agda
|
Cubical/Foundations/Prelude.agda
|
oisdk/cubical
|
a01973ef7264f9454a40697313a2073c51a6b77a
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Prelude.agda
|
oisdk/cubical
|
a01973ef7264f9454a40697313a2073c51a6b77a
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Prelude.agda
|
oisdk/cubical
|
a01973ef7264f9454a40697313a2073c51a6b77a
|
[
"MIT"
] | null | null | null |
{-
This file proves a variety of basic results about paths:
- refl, sym, cong and composition of paths. This is used to set up
equational reasoning.
- Transport, subst and functional extensionality
- J and its computation rule (up to a path)
- Σ-types and contractibility of singletons
- Converting PathP to and from a homogeneous path with transp
- Direct definitions of lower h-levels
- Export natural numbers
- Export universe lifting
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Prelude where
open import Cubical.Core.Primitives public
infixr 30 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
-- Basic theory about paths. These proofs should typically be
-- inlined. This module also makes equational reasoning work with
-- (non-dependent) paths.
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y z : A
refl : x ≡ x
refl {x = x} = λ _ → x
sym : x ≡ y → y ≡ x
sym p i = p (~ i)
symP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} →
(p : PathP A x y) → PathP (λ i → A (~ i)) y x
symP p j = p (~ j)
cong : ∀ (f : (a : A) → B a) (p : x ≡ y) →
PathP (λ i → B (p i)) (f x) (f y)
cong f p i = f (p i)
cong₂ : ∀ {C : (a : A) → (b : B a) → Type ℓ} →
(f : (a : A) → (b : B a) → C a b) →
(p : x ≡ y) →
{u : B x} {v : B y} (q : PathP (λ i → B (p i)) u v) →
PathP (λ i → C (p i) (q i)) (f x u) (f y v)
cong₂ f p q i = f (p i) (q i)
-- The filler of homogeneous path composition:
-- compPath-filler p q = PathP (λ i → x ≡ q i) p (p ∙ q)
compPath-filler : ∀ {x y z : A} → x ≡ y → y ≡ z → I → I → A
compPath-filler {x = x} p q j i =
hfill (λ j → λ { (i = i0) → x
; (i = i1) → q j }) (inS (p i)) j
_∙_ : x ≡ y → y ≡ z → x ≡ z
(p ∙ q) j = compPath-filler p q i1 j
-- The filler of heterogeneous path composition:
-- compPathP-filler p q = PathP (λ i → PathP (λ j → (compPath-filler (λ i → A i) B i j)) x (q i)) p (compPathP p q)
compPathP-filler : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → {B_i1 : Type ℓ} {B : A i1 ≡ B_i1} → {z : B i1} →
(p : PathP A x y) → (q : PathP (λ i → B i) y z) → ∀ (i j : I) → compPath-filler (λ i → A i) B j i
compPathP-filler {A = A} {x = x} {B = B} p q i =
fill (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j }) (inS (p i))
compPathP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} → {z : B i1} →
(p : PathP A x y) → (q : PathP (λ i → B i) y z) → PathP (λ j → ((λ i → A i) ∙ B) j) x z
compPathP p q j = compPathP-filler p q j i1
_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
≡⟨⟩-syntax : (x : A) → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 2 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- another definition of composition, useful for some proofs
compPath'-filler : ∀ {x y z : A} → x ≡ y → y ≡ z → I → I → A
compPath'-filler {z = z} p q j i =
hfill (λ j → λ { (i = i0) → p (~ j)
; (i = i1) → z }) (inS (q i)) j
_□_ : x ≡ y → y ≡ z → x ≡ z
(p □ q) j = compPath'-filler p q i1 j
□≡∙ : (p : x ≡ y) (q : y ≡ z) → p □ q ≡ p ∙ q
□≡∙ {x = x} {y = y} {z = z} p q i j = hcomp (λ k → \ { (i = i0) → compPath'-filler p q k j
; (i = i1) → compPath-filler p q k j
; (j = i0) → p ( ~ i ∧ ~ k)
; (j = i1) → q (k ∨ ~ i) }) (helper i j)
where
helper : PathP (λ i → p (~ i) ≡ q (~ i)) q p
helper i j = hcomp (λ k → \ { (i = i0) → q (k ∧ j)
; (i = i1) → p (~ k ∨ j)
; (j = i0) → p (~ i ∨ ~ k)
; (j = i1) → q (~ i ∧ k) })
y
-- Transport, subst and functional extensionality
-- transport is a special case of transp
transport : {A B : Type ℓ} → A ≡ B → A → B
transport p a = transp (λ i → p i) i0 a
-- Transporting in a constant family is the identity function (up to a
-- path). If we would have regularity this would be definitional.
transportRefl : (x : A) → transport refl x ≡ x
transportRefl {A = A} x i = transp (λ _ → A) i x
-- We want B to be explicit in subst
subst : (B : A → Type ℓ') (p : x ≡ y) → B x → B y
subst B p pa = transport (λ i → B (p i)) pa
substRefl : (px : B x) → subst B refl px ≡ px
substRefl px = transportRefl px
funExt : {f g : (x : A) → B x} → ((x : A) → f x ≡ g x) → f ≡ g
funExt p i x = p x i
-- J for paths and its computation rule
module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
J : (p : x ≡ y) → P y p
J p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
JRefl : J refl ≡ d
JRefl = transportRefl d
-- Contractibility of singletons
singl : (a : A) → Type _
singl {A = A} a = Σ[ x ∈ A ] (a ≡ x)
contrSingl : (p : x ≡ y) → Path (singl x) (x , refl) (y , p)
contrSingl p i = (p i , λ j → p (i ∧ j))
-- Converting to and from a PathP
module _ {A : I → Type ℓ} {x : A i0} {y : A i1} where
toPathP : transp A i0 x ≡ y → PathP A x y
toPathP p i = hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
fromPathP : PathP A x y → transp A i0 x ≡ y
fromPathP p i = transp (λ j → A (i ∨ j)) i (p i)
-- Direct definitions of lower h-levels
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)
Square :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Type _
Square a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋
isSet' : Type ℓ → Type ℓ
isSet' A =
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Square a₀₋ a₁₋ a₋₀ a₋₁
isGroupoid : Type ℓ → Type ℓ
isGroupoid A = ∀ a b → isSet (Path A a b)
Cube :
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Type _
Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
PathP (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋
isGroupoid' : Set ℓ → Set ℓ
isGroupoid' A =
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁
is2Groupoid : Type ℓ → Type ℓ
is2Groupoid A = ∀ a b → isGroupoid (Path A a b)
-- Essential consequences of isProp and isContr
isProp→PathP : ∀ {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ PathP (λ i → B i) b0 b1
isProp→PathP hB b0 b1 = toPathP (hB _ _ _)
isPropIsContr : isProp (isContr A)
isPropIsContr z0 z1 j =
( z0 .snd (z1 .fst) j
, λ x i → hcomp (λ k → λ { (i = i0) → z0 .snd (z1 .fst) j
; (i = i1) → z0 .snd x (j ∨ k)
; (j = i0) → z0 .snd x (i ∧ k)
; (j = i1) → z1 .snd x i })
(z0 .snd (z1 .snd x i) j))
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b i =
hcomp (λ j → λ { (i = i0) → p a j
; (i = i1) → p b j }) x
isProp→isSet : isProp A → isSet A
isProp→isSet h a b p q j i =
hcomp (λ k → λ { (i = i0) → h a a k
; (i = i1) → h a b k
; (j = i0) → h a (p i) k
; (j = i1) → h a (q i) k }) a
-- Universe lifting
record Lift {i j} (A : Type i) : Type (ℓ-max i j) where
constructor lift
field
lower : A
open Lift public
| 30.703971
| 115
| 0.483363
|
cb4ace3702e716f4ae3a0ff907f09dad7f8b415b
| 445
|
agda
|
Agda
|
prototyping/FFI/Data/HaskellString.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-12-05T21:53:03.000Z
|
2021-12-05T21:53:03.000Z
|
prototyping/FFI/Data/HaskellString.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/FFI/Data/HaskellString.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
module FFI.Data.HaskellString where
open import Agda.Builtin.String using (String)
{-# FOREIGN GHC import qualified Data.String #-}
{-# FOREIGN GHC import qualified Data.Text #-}
postulate HaskellString : Set
{-# COMPILE GHC HaskellString = type Data.String.String #-}
postulate pack : HaskellString → String
{-# COMPILE GHC pack = Data.Text.pack #-}
postulate unpack : String → HaskellString
{-# COMPILE GHC unpack = Data.Text.unpack #-}
| 26.176471
| 59
| 0.734831
|
d0d38d0f4a6938430aeacc047283871f70e2a763
| 739
|
agda
|
Agda
|
test/Fail/Issue964.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue964.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue964.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-08-04, issue #964
-- Allow open metas and interaction points in imported files
-- {-# OPTIONS -v import:100 #-}
-- {-# OPTIONS -v meta.postulate:20 #-}
-- {-# OPTIONS -v tc.conv.level:50 #-}
open import Common.Level
open import Common.Equality
postulate something : Set₁
open import Common.Issue964.UnsolvedMetas something
test = M.N.meta3
shouldFail : _≡_ {A = Level} meta (lsuc (lsuc lzero))
shouldFail = refl
-- WAS: WEIRD ERROR:
-- Set (Set .Issue964.UnsolvedMetas.1) != Set₂
-- when checking that the expression refl has type
-- meta ≡ lsuc (lsuc lzero)
-- NOW:
-- Set (.Issue964.UnsolvedMetas.unsolved#meta.1 something) != Set₂
-- when checking that the expression refl has type
-- meta ≡ lsuc (lsuc lzero)
| 25.482759
| 66
| 0.700947
|
cbf319525e2f26e06bb9cf5ef4e579110ce06579
| 1,267
|
agda
|
Agda
|
test/Succeed/Issue1648.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1648.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1648.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-09-18 Andreas, issue reported by Gillaume Brunerie
{- Problem WAS
The following code doesn’t typecheck but it should. I have no idea what’s going on.
Replacing the definition of PathOver-rewr by a question mark and
asking for full normalisation of the goal (C-u C-u C-c C-t), I obtain
HetEq idp u v == (u == v), so it seems that the term PathOver (λ _ →
B) p u v) is rewritten as HetEq idp u v using ap-cst (as expected),
but then for some reason HetEq idp u v isn’t reduced to u == v. -}
{-# OPTIONS --rewriting --confluence-check #-}
-- {-# OPTIONS --show-implicit #-}
data _==_ {i} {A : Set i} (a : A) : A → Set where
idp : a == a
{-# BUILTIN REWRITE _==_ #-}
ap : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A}
→ x == y → f x == f y
ap f idp = idp
ap-cst : ∀ {a} {b} {A : Set a} {B : Set b} (b : B) {x y : A} (p : x == y)
→ ap (λ _ → b) p == idp
ap-cst b idp = idp
{-# REWRITE ap-cst #-}
HetEq : {A B : Set} (e : A == B) (a : A) (b : B) → Set
HetEq idp a b = (a == b)
PathOver : {A : Set} (B : A → Set)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set
PathOver B p u v = HetEq (ap B p) u v
PathOver-rewr : {A B : Set} {x y : A} (p : x == y) (u v : B)
→ (PathOver (λ _ → B) p u v) == (u == v)
PathOver-rewr p u v = idp
| 31.675
| 83
| 0.552486
|
234a6affb8e5961024afba6d03f3eee8693eabf4
| 35,702
|
agda
|
Agda
|
src/DualLMRefined.agda
|
kcaliban/dual-session
|
cd41919582013e75463308c32750e2712cf2de86
|
[
"BSD-2-Clause"
] | null | null | null |
src/DualLMRefined.agda
|
kcaliban/dual-session
|
cd41919582013e75463308c32750e2712cf2de86
|
[
"BSD-2-Clause"
] | null | null | null |
src/DualLMRefined.agda
|
kcaliban/dual-session
|
cd41919582013e75463308c32750e2712cf2de86
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module DualLMRefined where
open import Data.Bool
open import Data.Nat hiding (compare)
open import Data.Nat.Properties
open import Data.Fin hiding (_+_)
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality hiding (Extensionality)
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
open import Extensionality
open import Direction
-- variables
variable
n m : ℕ
----------------------------------------------------------------------
-- auxiliaries for automatic rewriting
n+1=suc-n : n + 1 ≡ suc n
n+1=suc-n {zero} = refl
n+1=suc-n {suc n} = cong suc (n+1=suc-n {n})
{-# REWRITE n+1=suc-n #-}
n+0=n : n + 0 ≡ n
n+0=n {zero} = refl
n+0=n {suc n} = cong suc (n+0=n {n})
{-# REWRITE n+0=n #-}
inject+0-x=x : {x : Fin m} → inject+ 0 x ≡ x
inject+0-x=x {x = zero} = refl
inject+0-x=x {x = suc x} = cong suc inject+0-x=x
{-# REWRITE inject+0-x=x #-}
n+sucm : n + suc m ≡ suc (n + m)
n+sucm {0} = refl
n+sucm {suc n} = cong suc (n+sucm{n})
{-# REWRITE n+sucm #-}
n=fromℕtoℕn : (toℕ (fromℕ n)) ≡ n
n=fromℕtoℕn {zero} = refl
n=fromℕtoℕn {suc n} = cong suc (n=fromℕtoℕn {n})
{-# REWRITE n=fromℕtoℕn #-}
sucn∸suctoℕx≡n∸toℕx : {n : ℕ} {x : Fin n} → suc (n ∸ suc (toℕ x)) ≡ n ∸ (toℕ x)
sucn∸suctoℕx≡n∸toℕx {suc n} {zero} = refl
sucn∸suctoℕx≡n∸toℕx {suc n} {suc x} = sucn∸suctoℕx≡n∸toℕx{n}{x}
sym-sucn∸suctoℕx≡n∸toℕx : {n : ℕ} {x : Fin n} → n ∸ (toℕ x) ≡ suc (n ∸ suc (toℕ x))
sym-sucn∸suctoℕx≡n∸toℕx {n} {x} = sym (sucn∸suctoℕx≡n∸toℕx{n}{x})
{-# REWRITE sym-sucn∸suctoℕx≡n∸toℕx #-}
n∸n≡0F : n ∸ n ≡ 0
n∸n≡0F {0} = refl
n∸n≡0F {suc n} = n∸n≡0F{n}
{-# REWRITE n∸n≡0F #-}
{-# REWRITE m+n∸n≡m #-}
----------------------------------------------------------------------
-- some more required properties on natural numbers and fin
toℕx≤n : {n : ℕ} {x : Fin n} → Data.Nat._≤_ (toℕ x) n
toℕx≤n {suc n} {zero} = z≤n
toℕx≤n {suc n} {suc x} = s≤s toℕx≤n
toℕx≤n' : {n : ℕ} {x : Fin (suc n)} → Data.Nat._≤_ (toℕ x) n
toℕx≤n' {0} {zero} = z≤n
toℕx≤n' {suc n} {zero} = z≤n
toℕx≤n' {suc n} {suc x} = s≤s (toℕx≤n'{n}{x})
n∸x+x≡n : {n x : ℕ} → Data.Nat._≤_ x n → n ∸ x + x ≡ n
n∸x+x≡n {0} {zero} le = refl
n∸x+x≡n {0} {suc x} ()
n∸x+x≡n {suc n} {zero} le = refl
n∸x+x≡n {suc n} {suc x} (s≤s le) = cong suc (n∸x+x≡n le)
toℕx<n : {n : ℕ} {x : Fin n} → Data.Nat._<_ (toℕ x) n
toℕx<n {suc n} {zero} = s≤s z≤n
toℕx<n {suc n} {suc x} = s≤s toℕx<n
n∸x≡suc[n∸sucx] : {n x : ℕ} → Data.Nat._<_ x n → n ∸ x ≡ suc (n ∸ (suc x))
n∸x≡suc[n∸sucx] {suc n} {0} le = refl
n∸x≡suc[n∸sucx] {suc n} {suc x} (s≤s le) = n∸x≡suc[n∸sucx] le
suc[n+x]≡n+sucx : {n x : ℕ} → suc (n + x) ≡ (n + suc x)
suc[n+x]≡n+sucx {0} {x} = refl
suc[n+x]≡n+sucx {suc n} {x} = refl
suc[n∸sucx+x]≡n : {n x : ℕ} → Data.Nat._<_ x n → suc (n ∸ (suc x) + x) ≡ n
suc[n∸sucx+x]≡n {suc n} {0} le = refl
suc[n∸sucx+x]≡n {suc n} {suc x} (s≤s le) = cong suc (suc[n∸sucx+x]≡n {n} {x} le)
suc[n∸suc[toℕi]+toℕi]≡n : {n : ℕ} {i : Fin n} → suc (n ∸ (suc (toℕ i)) + toℕ i) ≡ n
suc[n∸suc[toℕi]+toℕi]≡n {n} {i} = suc[n∸sucx+x]≡n{n}{toℕ i} toℕx<n
{-# REWRITE suc[n∸suc[toℕi]+toℕi]≡n #-}
m∸toℕ+toℕ≡m : {n : ℕ} {i : Fin (suc n)} → n ∸ (toℕ i) + (toℕ i) ≡ n
m∸toℕ+toℕ≡m {n} {i} = m∸n+n≡m{n}{toℕ i} toℕx≤n'
{-# REWRITE m∸toℕ+toℕ≡m #-}
<suc : {n x : ℕ} → Data.Nat._<_ x n → Data.Nat._<_ x (suc n)
<suc {suc n} {0} le = s≤s z≤n
<suc {suc n} {suc x} (s≤s le) = s≤s (<suc {n} {x} le)
≤suc : {n x : ℕ} → Data.Nat._≤_ x n → Data.Nat._≤_ x (suc n)
≤suc {n} {0} le = z≤n
≤suc {suc n} {suc x} (s≤s le) = s≤s (≤suc {n} {x} le)
----------------------------------------------------------------------
module IND where
mutual
data Type (n : ℕ) : Set where
TUnit TInt : Type n
TPair : Type n → Type n → Type n
TChan : SType n → Type n
data SType (n : ℕ) : Set where
gdd : (gst : GType n) → SType n
rec : (gst : GType (suc n)) → SType n
var : (x : Fin n) → SType n
data GType (n : ℕ) : Set where
transmit : (d : Dir) (t : Type n) (s : SType n) → GType n
choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n
end : GType n
data MClType (n : ℕ) : Set where
MClTUnit MClTInt : MClType n
MClTPair : MClType n → MClType n → MClType n
MClTChan : SType 0 → MClType n
data MClSType (n : ℕ) : Set where
tgdd : (tgst : MClGType n) → MClSType n
trec : (tgst : MClGType (suc n)) → MClSType n
tvar : (x : Fin n) → MClSType n
data MClGType (n : ℕ) : Set where
ttransmit : (d : Dir) (t : MClType n) (s : MClSType n) → MClGType n
tchoice : (d : Dir) (m : ℕ) (alt : Fin m → MClSType n) → MClGType n
end : MClGType n
----------------------------------------------------------------------
weaken1'N : Fin (suc n) → Fin n → Fin (suc n)
weaken1'N zero x = suc x
weaken1'N (suc i) zero = zero
weaken1'N (suc i) (suc x) = suc (weaken1'N i x)
weaken1'S : Fin (suc n) → SType n → SType (suc n)
weaken1'G : Fin (suc n) → GType n → GType (suc n)
weaken1'T : Fin (suc n) → Type n → Type (suc n)
weaken1'S i (gdd gst) = gdd (weaken1'G i gst)
weaken1'S i (rec gst) = rec (weaken1'G (suc i) gst)
weaken1'S i (var x) = var (weaken1'N i x)
weaken1'G i (transmit d t s) = transmit d (weaken1'T i t) (weaken1'S i s)
weaken1'G i (choice d m alt) = choice d m (weaken1'S i ∘ alt)
weaken1'G i end = end
weaken1'T i TUnit = TUnit
weaken1'T i TInt = TInt
weaken1'T i (TPair t₁ t₂) = TPair (weaken1'T i t₁) (weaken1'T i t₂)
weaken1'T i (TChan x) = TChan (weaken1'S i x)
weaken1S : SType n → SType (suc n)
weaken1G : GType n → GType (suc n)
weaken1T : Type n → Type (suc n)
weaken1S = weaken1'S zero
weaken1G = weaken1'G zero
weaken1T = weaken1'T zero
weakenS : (n : ℕ) → SType m → SType (m + n)
weakenG : (n : ℕ) → GType m → GType (m + n)
weakenT : (n : ℕ) → Type m → Type (m + n)
weakenS n (gdd gst) = gdd (weakenG n gst)
weakenS n (rec gst) = rec (weakenG n gst)
weakenS n (var x) = var (inject+ n x)
weakenG n (transmit d t s) = transmit d (weakenT n t) (weakenS n s)
weakenG n (choice d m alt) = choice d m (λ i → weakenS n (alt i))
weakenG n end = end
weakenT n TUnit = TUnit
weakenT n TInt = TInt
weakenT n (TPair ty ty₁) = TPair (weakenT n ty) (weakenT n ty₁)
weakenT n (TChan x) = TChan (weakenS n x)
----------------------------------------------------------------------
-- Single substitution with SType 0
st-substS : SType (suc n) → Fin (suc n) → SType 0 → SType n
st-substG : GType (suc n) → Fin (suc n) → SType 0 → GType n
st-substT : Type (suc n) → Fin (suc n) → SType 0 → Type n
st-substS (gdd gst) i st0 = gdd (st-substG gst i st0)
st-substS (rec gst) i st0 = rec (st-substG gst (suc i) st0)
st-substS {n} (var zero) zero st0 = weakenS n st0
st-substS {suc n} (var zero) (suc i) st0 = var zero
st-substS {suc n} (var (suc x)) zero st0 = var x
st-substS {suc n} (var (suc x)) (suc i) st0 = weaken1S (st-substS (var x) i st0)
st-substG (transmit d t s) i st0 = transmit d (st-substT t i st0) (st-substS s i st0)
st-substG (choice d m alt) i st0 = choice d m (λ j → st-substS (alt j) i st0)
st-substG end i st0 = end
st-substT TUnit i st0 = TUnit
st-substT TInt i st0 = TInt
st-substT (TPair ty ty₁) i st0 = TPair (st-substT ty i st0) (st-substT ty₁ i st0)
st-substT (TChan st) i st0 = TChan (st-substS st i st0)
-- Single substitution with SType n
st-substS' : Fin (suc n) → SType n → SType (suc n) → SType n
st-substG' : Fin (suc n) → SType n → GType (suc n) → GType n
st-substT' : Fin (suc n) → SType n → Type (suc n) → Type n
st-substS' i st (gdd gst) = gdd (st-substG' i st gst)
st-substS' i st (rec gst) = rec (st-substG' (suc i) (weaken1S st) gst)
st-substS' i st (var x)
with compare x i
st-substS' i st (var .(inject least)) | less .i least = var (inject! least)
st-substS' .x st (var x) | equal .x = st
st-substS' .(inject least) st (var (suc x)) | greater .(suc x) least = var x
st-substG' i st (transmit d t s) = transmit d (st-substT' i st t) (st-substS' i st s)
st-substG' i st (choice d m alt) = choice d m (λ j → st-substS' i st (alt j))
st-substG' i st end = end
st-substT' i st TUnit = TUnit
st-substT' i st TInt = TInt
st-substT' i st (TPair ty ty₁) = TPair (st-substT' i st ty) (st-substT' i st ty₁)
st-substT' i st (TChan s) = TChan (st-substS' i st s)
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
open IND
data Stack : ℕ → Set where
ε : Stack 0
⟪_,_⟫ : Stack n → IND.GType (suc n) → Stack (suc n)
data StackS : ℕ → Set where
ε : StackS 0
⟪_,_⟫ : StackS n → IND.SType n → StackS (suc n)
data StackS0 : ℕ → Set where
ε : StackS0 0
⟪_,_⟫ : StackS0 n → IND.SType 0 → StackS0 (suc n)
data StackMCl : ℕ → Set where
ε : StackMCl 0
⟪_,_⟫ : StackMCl n → IND.MClGType (suc n) → StackMCl (suc n)
-- Stack of length m starting at arbitrary type size n
data Stack' : ℕ → ℕ → Set where
ε : Stack' n 0
⟪_,_⟫ : Stack' n m → IND.GType (suc (n + m)) → Stack' n (suc m)
data Stack'S : ℕ → ℕ → Set where
ε : Stack'S n 0
⟪_,_⟫ : Stack'S n m → IND.SType (n + m) → Stack'S n (suc m)
data Stack'Sn : ℕ → ℕ → Set where
ε : Stack'Sn n 0
⟪_,_⟫ : Stack'Sn n m → IND.SType n → Stack'Sn n (suc m)
get : {n : ℕ} → (i : Fin n) → Stack n → Stack (n ∸ (suc (toℕ i))) × IND.GType (n ∸ (toℕ i))
get {suc n} zero ⟪ σ , x ⟫ = σ , x
get {suc n} (suc i) ⟪ σ , x ⟫ = get i σ
getS : {n : ℕ} → (i : Fin n) → StackS n → StackS (n ∸ (suc (toℕ i))) × IND.SType (n ∸ (suc (toℕ i)))
getS {suc n} zero ⟪ σ , x ⟫ = σ , x
getS {suc n} (suc i) ⟪ σ , x ⟫ = getS i σ
getS0 : {n : ℕ} → (i : Fin n) → StackS0 n → StackS0 (n ∸ (suc (toℕ i))) × IND.SType 0
getS0 {suc n} zero ⟪ σ , x ⟫ = σ , x
getS0 {suc n} (suc i) ⟪ σ , x ⟫ = getS0 i σ
getMCl : {n : ℕ} → (i : Fin n) → StackMCl n → StackMCl (n ∸ (suc (toℕ i))) × IND.MClGType (n ∸ (toℕ i))
getMCl {suc n} zero ⟪ σ , x ⟫ = σ , x
getMCl {suc n} (suc i) ⟪ σ , x ⟫ = getMCl i σ
get' : {n m : ℕ} → (i : Fin m) → Stack' n m → Stack' n (m ∸ (suc (toℕ i))) × IND.GType (n + (m ∸ (toℕ i)))
get' {n} {suc m} zero ⟪ σ , x ⟫ = σ , x
get' {n} {suc m} (suc i) ⟪ σ , x ⟫ = get' i σ
get'S : {n m : ℕ} → (i : Fin m) → Stack'S n m → Stack'S n (m ∸ (suc (toℕ i))) × IND.SType (n + (m ∸ (suc (toℕ i))))
get'S {n} {suc m} zero ⟪ σ , x ⟫ = σ , x
get'S {n} {suc m} (suc i) ⟪ σ , x ⟫ = get'S i σ
get'Sn : {n m : ℕ} → (i : Fin m) → Stack'Sn n m → Stack'Sn n (m ∸ (suc (toℕ i))) × IND.SType n
get'Sn {n} {suc m} zero ⟪ σ , x ⟫ = σ , x
get'Sn {n} {suc m} (suc i) ⟪ σ , x ⟫ = get'Sn i σ
----------------------------------------------------------------------
stack-split : (i : Fin (suc n)) → Stack n → Stack (n ∸ toℕ i) × Stack' (n ∸ toℕ i) (toℕ i)
stack-split zero σ = σ , ε
stack-split{n} (suc i) ⟪ σ , x ⟫
with stack-split i σ
... | σ' , σ'' = σ' , ⟪ σ'' , x ⟫
-- couldn't achieve this by rewriting alone
suc[n+[m∸sucx]+x]≡n+m : {n m x : ℕ} → Data.Nat._<_ x m → suc (n + (m ∸ suc x) + x) ≡ n + m
suc[n+[m∸sucx]+x]≡n+m {0} {m} {x} le = suc[n∸sucx+x]≡n{m}{x} le
suc[n+[m∸sucx]+x]≡n+m {suc n} {suc m} {0} le = refl
suc[n+[m∸sucx]+x]≡n+m {suc n} {suc m} {suc x} (s≤s le) = cong suc (cong suc (suc[n+[m∸sucx]+x]≡n+m le))
-- i from the top of the stack
stack'-m-i : {n m : ℕ} → (i : Fin m) → Stack' n m → Stack' (n + (m ∸ (toℕ i))) (toℕ i)
stack'-m-i {n} {m} zero σ = ε
stack'-m-i {n} {suc m} (suc i) ⟪ σ , x ⟫ rewrite (sym (suc[n+[m∸sucx]+x]≡n+m{n}{m}{toℕ i} toℕx<n)) = ⟪ (stack'-m-i i σ) , x ⟫
weaken1-Stack' : (i : Fin (suc n)) → Stack' n m → Stack' (suc n) m
weaken1-Stack' i ε = ε
weaken1-Stack'{n}{m} i ⟪ σ , x ⟫ = ⟪ (weaken1-Stack' i σ) , (weaken1'G (inject+ m i) x) ⟫
weaken1-Stack'Sn : (i : Fin (suc n)) → Stack'Sn n m → Stack'Sn (suc n) m
weaken1-Stack'Sn i ε = ε
weaken1-Stack'Sn{n}{m} i ⟪ σ , x ⟫ = ⟪ (weaken1-Stack'Sn i σ) , (weaken1'S i x) ⟫
-- substitute after index i, required for rec case
stack-sim-substS-i> : (i : Fin n) → StackS0 (n ∸ (toℕ (suc i))) → SType n → SType (toℕ (suc i))
stack-sim-substG-i> : (i : Fin n) → StackS0 (n ∸ (toℕ (suc i))) → GType n → GType (toℕ (suc i))
stack-sim-substT-i> : (i : Fin n) → StackS0 (n ∸ (toℕ (suc i))) → Type n → Type (toℕ (suc i))
stack-sim-substS-i> i σ (gdd gst) = gdd (stack-sim-substG-i> i σ gst)
stack-sim-substS-i> i σ (rec gst) = rec (stack-sim-substG-i> (suc i) σ gst)
stack-sim-substS-i>{suc n} zero σ (var zero) = var zero
stack-sim-substS-i> zero σ (var (suc x))
with getS0 x σ
... | σ' , s = weaken1S s
stack-sim-substS-i> (suc i) σ (var zero) = var zero
stack-sim-substS-i> (suc i) σ (var (suc x)) = weaken1S (stack-sim-substS-i> i σ (var x))
stack-sim-substG-i> i σ (transmit d t s) = transmit d (stack-sim-substT-i> i σ t) (stack-sim-substS-i> i σ s)
stack-sim-substG-i> i σ (choice d m alt) = choice d m (λ x → stack-sim-substS-i> i σ (alt x))
stack-sim-substG-i> i σ end = end
stack-sim-substT-i> i σ TUnit = TUnit
stack-sim-substT-i> i σ TInt = TInt
stack-sim-substT-i> i σ (TPair t t₁) = TPair (stack-sim-substT-i> i σ t) (stack-sim-substT-i> i σ t₁)
stack-sim-substT-i> i σ (TChan x) = TChan (stack-sim-substS-i> i σ x)
-- substitute stack
stack-sim-substS : StackS0 n → SType n → SType 0
stack-sim-substG : StackS0 n → GType n → GType 0
stack-sim-substT : StackS0 n → Type n → Type 0
stack-sim-substS σ (gdd gst) = gdd (stack-sim-substG σ gst)
stack-sim-substS σ (rec gst) = rec (stack-sim-substG-i> zero σ gst) -- Apply stack substitution to variables 1, ..., suc n; keep 0F; can't extend StackS0 since only SType 0F allowed
stack-sim-substS σ (var x)
with getS0 x σ
... | σ' , s = s
stack-sim-substG σ (transmit d t s) = transmit d (stack-sim-substT σ t) (stack-sim-substS σ s)
stack-sim-substG σ (choice d m alt) = choice d m (λ x → stack-sim-substS σ (alt x))
stack-sim-substG σ end = end
stack-sim-substT σ TUnit = TUnit
stack-sim-substT σ TInt = TInt
stack-sim-substT σ (TPair t t₁) = TPair (stack-sim-substT σ t) (stack-sim-substT σ t₁)
stack-sim-substT σ (TChan x) = TChan (stack-sim-substS σ x)
stack-sim-substS'-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → SType m → SType (n + toℕ i)
stack-sim-substG'-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → GType m → GType (n + toℕ i)
stack-sim-substT'-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → Type m → Type (n + toℕ i)
stack-sim-substS'-i≥ i σ (gdd gst) = gdd (stack-sim-substG'-i≥ i σ gst)
stack-sim-substS'-i≥ i σ (rec gst) = rec (stack-sim-substG'-i≥ (suc i) σ gst)
stack-sim-substS'-i≥ zero σ (var x)
with get'Sn x σ
... | σ' , y = y
stack-sim-substS'-i≥ (suc i) σ (var zero) = var zero
stack-sim-substS'-i≥ (suc i) σ (var (suc x)) = weaken1S (stack-sim-substS'-i≥ i σ (var x))
stack-sim-substG'-i≥ i σ (transmit d t s) = transmit d (stack-sim-substT'-i≥ i σ t) (stack-sim-substS'-i≥ i σ s)
stack-sim-substG'-i≥ i σ (choice d m alt) = choice d m (λ x → stack-sim-substS'-i≥ i σ (alt x))
stack-sim-substG'-i≥ i σ end = end
stack-sim-substT'-i≥ i σ TUnit = TUnit
stack-sim-substT'-i≥ i σ TInt = TInt
stack-sim-substT'-i≥ i σ (TPair t t₁) = TPair (stack-sim-substT'-i≥ i σ t) (stack-sim-substT'-i≥ i σ t₁)
stack-sim-substT'-i≥ i σ (TChan x) = TChan (stack-sim-substS'-i≥ i σ x)
-- substitute stack'
stack-sim-substS' : Stack'Sn n m → SType m → SType n
stack-sim-substG' : Stack'Sn n m → GType m → GType n
stack-sim-substT' : Stack'Sn n m → Type m → Type n
stack-sim-substS' σ (gdd gst) = gdd (stack-sim-substG' σ gst)
stack-sim-substS'{n}{m} σ (rec gst) = rec (stack-sim-substG'-i≥ (suc zero) σ gst)
stack-sim-substS' σ (var x)
with get'Sn x σ
... | σ' , s = s
stack-sim-substG' σ (transmit d t s) = transmit d (stack-sim-substT' σ t) (stack-sim-substS' σ s)
stack-sim-substG' σ (choice d m alt) = choice d m (λ x → stack-sim-substS' σ (alt x))
stack-sim-substG' σ end = end
stack-sim-substT' σ TUnit = TUnit
stack-sim-substT' σ TInt = TInt
stack-sim-substT' σ (TPair t t₁) = TPair (stack-sim-substT' σ t) (stack-sim-substT' σ t₁)
stack-sim-substT' σ (TChan x) = TChan (stack-sim-substS' σ x)
{- required for alt. def. of rec case of stack-sim-substS'-top
stack-sim-substS'-top-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → SType (n + m) → SType (n + toℕ i)
stack-sim-substG'-top-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → GType (n + m) → GType (n + toℕ i)
stack-sim-substT'-top-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → Type (n + m) → Type (n + toℕ i)
stack-sim-substS'-top-i≥ i σ (gdd gst) = {!!}
stack-sim-substS'-top-i≥ i σ (rec gst) = rec (stack-sim-substG'-top-i≥ (suc i) σ gst)
stack-sim-substS'-top-i≥ i σ (var x) = {!!}
stack-sim-substS'-top-i≥' : (i : Fin (suc m)) → Stack'Sn (n + toℕ i) (toℕ i) → SType (n + m) → SType (n + m ∸ toℕ i)
stack-sim-substG'-top-i≥' : (i : Fin (suc m)) → Stack'Sn (n + toℕ i) (toℕ i) → GType (n + m) → GType (n + m ∸ toℕ i)
stack-sim-substS'-top-i≥'{m = m}{n = suc n} i σ (rec gst) = rec (stack-sim-substG'-top-i≥' {!!} {!!} gst)
-}
-- substitute top variables from stack'
stack-sim-substS'-top : Stack'Sn n m → SType (n + m) → SType n
stack-sim-substG'-top : Stack'Sn n m → GType (n + m) → GType n
stack-sim-substT'-top : Stack'Sn n m → Type (n + m) → Type n
stack-sim-substS'-top σ (gdd gst) = gdd (stack-sim-substG'-top σ gst)
stack-sim-substS'-top{n}{m} σ (rec gst) = rec (stack-sim-substG'-top{m = m} (weaken1-Stack'Sn zero σ) gst) -- alternative: rec (stack-sim-substG'-top-i≥ 1 σ gst)
stack-sim-substS'-top{n}{m} σ (var x) = {!!} -- <= n => var n, > n => substitute
-- Transform Stack of STypes to Stack of closed STypes by substitution
-- ⟪ ε , SType 0 , SType 1 , SType 2 , ⋯ ⟫
-- ⟪ ε , SType 0 , SType 1 [0 ↦ SType 0], SType 2 [0 ↦ SType 0, 1 ↦ SType 1 [0 ↦ SType 0]], ⋯ ⟫
-- ⟪ ε , SType 0 , SType 0 , SType 0 , ⋯ ⟫
stack-transform : StackS n → StackS0 n
stack-transform ε = ε
stack-transform ⟪ σ , x ⟫
with stack-transform σ
... | σ' = ⟪ σ' , (stack-sim-substS σ' x) ⟫
stack-transform' : Stack'S n m → Stack'Sn n m
stack-transform' ε = ε
stack-transform'{n} ⟪ σ , x ⟫
with stack-transform' σ
... | σ' = ⟪ σ' , stack-sim-substS'-top σ' x ⟫
stack-cat : Stack n → Stack' n m → Stack (n + m)
stack-cat σ ε = σ
stack-cat σ ⟪ σ' , x ⟫ = ⟪ (stack-cat σ σ') , x ⟫
stack-cat' : Stack' 0 n → Stack' n m → Stack' 0 (n + m)
stack-cat' σ ε = σ
stack-cat' σ ⟪ σ' , x ⟫ = ⟪ (stack-cat' σ σ') , x ⟫
stack-sim-substS-refl : (s : SType 0) → stack-sim-substS ε s ≡ s
stack-sim-substG-refl : (g : GType 0) → stack-sim-substG ε g ≡ g
stack-sim-substT-refl : (t : Type 0) → stack-sim-substT ε t ≡ t
stack-sim-substS-refl (gdd gst) = cong gdd (stack-sim-substG-refl gst)
stack-sim-substS-refl (rec gst) = {!!} -- requires stack-sim-substG-i>-refl
stack-sim-substG-refl (transmit d t s) = cong₂ (transmit d) (stack-sim-substT-refl t) (stack-sim-substS-refl s)
stack-sim-substG-refl (choice d m alt) = cong (choice d m) (ext (λ x → stack-sim-substS-refl (alt x)))
stack-sim-substG-refl end = refl
stack-sim-substT-refl TUnit = refl
stack-sim-substT-refl TInt = refl
stack-sim-substT-refl (TPair t t₁) = cong₂ TPair (stack-sim-substT-refl t) (stack-sim-substT-refl t₁)
stack-sim-substT-refl (TChan x) = cong TChan (stack-sim-substS-refl x)
----------------------------------------------------------------------
-- Message closure
mclS : (σ : StackS n) → SType n → MClSType n
mclG : (σ : StackS n) → GType n → MClGType n
mclT : (σ : StackS n) → Type n → MClType n
mclS σ (gdd gst) = tgdd (mclG σ gst)
mclS σ (rec gst) = trec (mclG ⟪ σ , (rec gst) ⟫ gst)
mclS σ (var x) = tvar x
mclG σ (transmit d t s) = ttransmit d (mclT σ t) (mclS σ s)
mclG σ (choice d m alt) = tchoice d m (λ x → mclS σ (alt x))
mclG σ end = end
mclT σ TUnit = MClTUnit
mclT σ TInt = MClTInt
mclT σ (TPair t t₁) = MClTPair (mclT σ t) (mclT σ t₁)
mclT σ (TChan x) = MClTChan (stack-sim-substS (stack-transform σ) x)
----------------------------------------------------------------------
-- Any mcl type is a normal type with weakening
mcl2indS : MClSType n → SType n
mcl2indG : MClGType n → GType n
mcl2indT : MClType n → Type n
mcl2indS (tgdd tgst) = gdd (mcl2indG tgst)
mcl2indS (trec tgst) = rec (mcl2indG tgst)
mcl2indS (tvar x) = var x
mcl2indG (ttransmit d t s) = transmit d (mcl2indT t) (mcl2indS s)
mcl2indG (tchoice d m alt) = choice d m (λ x → mcl2indS (alt x))
mcl2indG end = end
mcl2indT MClTUnit = TUnit
mcl2indT MClTInt = TInt
mcl2indT (MClTPair t t₁) = TPair (mcl2indT t) (mcl2indT t₁)
mcl2indT{n} (MClTChan x) = TChan (weakenS n x)
----------------------------------------------------------------------
stack2StackS : Stack n → StackS n
stack2StackS ε = ε
stack2StackS ⟪ σ , x ⟫ = ⟪ (stack2StackS σ) , (rec x) ⟫
stackMCl2Stack : StackMCl n → Stack n
stackMCl2Stack ε = ε
stackMCl2Stack ⟪ σ , x ⟫ = ⟪ (stackMCl2Stack σ) , (mcl2indG x) ⟫
stackMCl2StackS : StackMCl n → StackS n
stackMCl2StackS ε = ε
stackMCl2StackS ⟪ σ , x ⟫ = ⟪ (stackMCl2StackS σ) , (rec (mcl2indG x)) ⟫
stack2StackMCl : Stack n → StackMCl n
stack2StackMCl ε = ε
stack2StackMCl ⟪ σ , x ⟫ = ⟪ (stack2StackMCl σ) , (mclG ⟪ stack2StackS σ , rec x ⟫ x) ⟫
stack2Stack' : Stack n → Stack' 0 n
stack2Stack' ε = ε
stack2Stack' ⟪ σ , x ⟫ = ⟪ stack2Stack' σ , x ⟫
stack'2Stack : Stack' 0 n → Stack n
stack'2Stack ε = ε
stack'2Stack ⟪ σ , x ⟫ = ⟪ stack'2Stack σ , x ⟫
stack'2Stack'S : Stack' n m → Stack'S n m
stack'2Stack'S ε = ε
stack'2Stack'S ⟪ σ , x ⟫ = ⟪ (stack'2Stack'S σ) , (rec x) ⟫
stack-stack'-refl : (σ : Stack n) → (stack'2Stack (stack2Stack' σ)) ≡ σ
stack-stack'-refl ε = refl
stack-stack'-refl ⟪ σ , x ⟫ rewrite (stack-stack'-refl σ) = refl
{-# REWRITE stack-stack'-refl #-}
----------------------------------------------------------------------
naive-dualS : SType n → SType n
naive-dualG : GType n → GType n
naive-dualT : Type n → Type n
naive-dualS (gdd gst) = gdd (naive-dualG gst)
naive-dualS (rec gst) = rec (naive-dualG gst)
naive-dualS (var x) = var x
naive-dualG (transmit d t s) = transmit (dual-dir d) (naive-dualT t) (naive-dualS s)
naive-dualG (choice d m alt) = choice (dual-dir d) m (λ x → naive-dualS (alt x))
naive-dualG end = end
naive-dualT TUnit = TUnit
naive-dualT TInt = TInt
naive-dualT (TPair t t₁) = TPair (naive-dualT t) (naive-dualT t₁)
naive-dualT (TChan x) = TChan (naive-dualS x)
naive-dualSt : MClSType n → MClSType n
naive-dualGt : MClGType n → MClGType n
naive-dualTt : MClType n → MClType n
naive-dualSt (tgdd tgst) = tgdd (naive-dualGt tgst)
naive-dualSt (trec tgst) = trec (naive-dualGt tgst)
naive-dualSt (tvar x) = tvar x
naive-dualGt (ttransmit d t s) = ttransmit (dual-dir d) (naive-dualTt t) (naive-dualSt s)
naive-dualGt (tchoice d m alt) = tchoice (dual-dir d) m (λ x → naive-dualSt (alt x))
naive-dualGt end = end
naive-dualTt MClTUnit = MClTUnit
naive-dualTt MClTInt = MClTInt
naive-dualTt (MClTPair t t₁) = MClTPair (naive-dualTt t) (naive-dualTt t₁)
naive-dualTt (MClTChan x) = MClTChan (naive-dualS x)
----------------------------------------------------------------------
dualS : (σ : StackS n) → SType n → MClSType n
dualG : (σ : StackS n) → GType n → MClGType n
dualT : (σ : StackS n) → Type n → MClType n
dualS σ (gdd gst) = tgdd (dualG σ gst)
dualS σ (rec gst) = trec (dualG ⟪ σ , (rec gst) ⟫ gst)
dualS σ (var x) = (tvar x)
dualG{n} σ (transmit d t s) = ttransmit (dual-dir d) (dualT σ t) (dualS σ s)
dualG σ (choice d m alt) = tchoice (dual-dir d) m ((dualS σ) ∘ alt)
dualG σ end = end
dualT σ TUnit = MClTUnit
dualT σ TInt = MClTInt
dualT σ (TPair t t₁) = MClTPair (dualT σ t) (dualT σ t₁)
dualT σ (TChan x) = MClTChan (stack-sim-substS (stack-transform σ) x)
module sanity-check where
-- μx.!x.x → μx.?(μx.!x.x).x
S : SType 0
S = rec (transmit SND (TChan (var zero)) (var zero))
DS = rec (transmit RCV (weaken1T (TChan S)) (var zero))
_ : mclS ε DS ≡ dualS ε S
_ = refl
-- μx.!x.!x.x → μx.?(μx.!x.!x.x).?(μx.!x.!x.x).x
S' : SType 0
S' = rec (transmit SND (TChan (var zero)) (gdd ((transmit SND (TChan (var zero)) (var zero)))))
DS' = rec (transmit RCV (weaken1T (TChan S')) (gdd ((transmit RCV (weaken1T (TChan S')) (var zero)))))
_ : mclS ε DS' ≡ dualS ε S'
_ = refl
-- μx.!x.(μy.!y.y) → μx.?(μx.!x.(μy.!y.y)).(μy.?(μy.!y.y).y)
S'' : SType 0
S'' = rec (transmit SND (TChan (var zero)) (rec (transmit SND (TChan (var zero)) (var zero))))
DS'' = rec (transmit RCV (weaken1T (TChan S'')) (weaken1S DS))
_ : mclS ε DS'' ≡ dualS ε S''
_ = refl
----------------------------------------------------------------------
open import DualCoinductive hiding (n ; m)
_≈_ = COI._≈_
_≈'_ = COI._≈'_
_≈ᵗ_ = COI._≈ᵗ_
-- IND to Coinductive using two stacks
-- e.g. i = 0 => σ
-- i = 1 => σ , g -- g = get σ' 0
-- i = 2F => σ , g' , g -- g = get σ' 0; g' = get σ' 1
-- i = n => σ'
ind2coiS' : (i : Fin (suc n)) → Stack (n ∸ toℕ i) → Stack' (n ∸ toℕ i) (toℕ i) → IND.SType n → COI.SType
ind2coiG' : (i : Fin (suc n)) → Stack (n ∸ toℕ i) → Stack' (n ∸ toℕ i) (toℕ i) → IND.GType n → COI.STypeF COI.SType
ind2coiT' : (i : Fin (suc n)) → Stack (n ∸ toℕ i) → Stack' (n ∸ toℕ i) (toℕ i) → IND.Type n → COI.Type
COI.SType.force (ind2coiS' i σ σ' (gdd gst)) = ind2coiG' i σ σ' gst
COI.SType.force (ind2coiS'{n} i σ σ' (rec gst)) = ind2coiG' (suc i) σ ⟪ σ' , gst ⟫ gst
COI.SType.force (ind2coiS' i σ σ' (var x)) = {!!}
-- IND to Coinductive
ind2coiS : Stack n → IND.SType n → COI.SType
ind2coiG : Stack n → IND.GType n → COI.STypeF COI.SType
ind2coiT : Stack n → IND.Type n → COI.Type
ind2coiT σ TUnit = COI.TUnit
ind2coiT σ TInt = COI.TInt
ind2coiT σ (TPair t t₁) = COI.TPair (ind2coiT σ t) (ind2coiT σ t₁)
ind2coiT σ (TChan x) = COI.TChan (ind2coiS σ x)
COI.SType.force (ind2coiS σ (gdd gst)) = ind2coiG σ gst
COI.SType.force (ind2coiS σ (rec gst)) = ind2coiG ⟪ σ , gst ⟫ gst
COI.SType.force (ind2coiS{n} σ (var x))
with get x σ
... | σ' , gxs rewrite (n∸x≡suc[n∸sucx]{n}{toℕ x} toℕx<n) = ind2coiG ⟪ σ' , gxs ⟫ gxs
ind2coiG σ (transmit d t s) = COI.transmit d (ind2coiT σ t) (ind2coiS σ s)
ind2coiG σ (choice d m alt) = COI.choice d m (λ x → ind2coiS σ (alt x))
ind2coiG σ end = COI.end
-- IND to Coinductive using StackS0
ind2coiS'' : StackS0 n → IND.SType n → COI.SType
ind2coiG'' : StackS0 n → IND.GType n → COI.STypeF COI.SType
COI.SType.force (ind2coiS'' σ (gdd gst)) = ind2coiG'' σ gst
COI.SType.force (ind2coiS''{n} σ (rec gst)) = ind2coiG''{suc n} ⟪ σ , stack-sim-substS σ (rec gst) ⟫ gst
ind2coiS'' σ (var x)
with getS0 x σ
... | σ' , gxs = ind2coiS'' ε gxs
-- Equivalence of IND to COI with one stack and IND to COI with two stacks
ind2coiS≈ind2coiS' : (σ : Stack' 0 n) (s : IND.SType n)
→ ind2coiS' (fromℕ n) ε σ s ≈ ind2coiS (stack'2Stack σ) s
ind2coiG≈ind2coiG' : (σ : Stack' 0 n) (g : IND.GType n)
→ ind2coiG' (fromℕ n) ε σ g ≈' ind2coiG (stack'2Stack σ) g
COI.Equiv.force (ind2coiS≈ind2coiS' σ (gdd gst)) = ind2coiG≈ind2coiG' σ gst
COI.Equiv.force (ind2coiS≈ind2coiS'{n} σ (rec gst)) = ind2coiG≈ind2coiG'{suc n} ⟪ σ , gst ⟫ gst
COI.Equiv.force (ind2coiS≈ind2coiS' σ (var x)) = {!!}
-- Message closure to Coinductive
mcl2coiT : StackMCl n → MClType n → COI.Type
mcl2coiS : StackMCl n → MClSType n → COI.SType
mcl2coiG : StackMCl n → MClGType n → COI.STypeF COI.SType
mcl2coiT σ MClTUnit = COI.TUnit
mcl2coiT σ MClTInt = COI.TInt
mcl2coiT σ (MClTPair t t₁) = COI.TPair (mcl2coiT σ t) (mcl2coiT σ t₁)
mcl2coiT σ (MClTChan s) = COI.TChan (ind2coiS ε s)
COI.SType.force (mcl2coiS σ (tgdd g)) = mcl2coiG σ g
COI.SType.force (mcl2coiS σ (trec g)) = mcl2coiG ⟪ σ , g ⟫ g
COI.SType.force (mcl2coiS{n} σ (tvar x))
with getMCl x σ
... | σ' , gxs rewrite (n∸x≡suc[n∸sucx]{n}{toℕ x} toℕx<n) = mcl2coiG ⟪ σ' , gxs ⟫ gxs
mcl2coiG σ (ttransmit d t s) = COI.transmit d (mcl2coiT σ t) (mcl2coiS σ s)
mcl2coiG σ (tchoice d m alt) = COI.choice d m (mcl2coiS σ ∘ alt)
mcl2coiG σ end = COI.end
----------------------------------------------------------------------
-- lemm 1
-- stack-sim-substS (stack-transform ⟪ stack2StackS σ , (rec x) ⟫) s ≡ stack-sim-substS (stack-transform (stack2StackS σ)) (st-substS' 0 (rec x) s)
-- lemm 2
-- ind2coiS ⟪ σ , x ⟫ s ≈ ind2coiS σ (st-substS' 0 (rec x) s)
-- unfolding vs single substitution
ind2coi-substS : (σ : Stack n) (g : GType (suc n)) (s : SType (suc n)) →
ind2coiS ⟪ σ , g ⟫ s ≈ ind2coiS σ (st-substS' zero (rec g) s)
ind2coi-substG : (σ : Stack n) (g : GType (suc n)) (g' : GType (suc n)) →
ind2coiG ⟪ σ , g ⟫ g' ≈' ind2coiG σ (st-substG' zero (rec g) g')
COI.Equiv.force (ind2coi-substS σ g (gdd gst)) = ind2coi-substG σ g gst
COI.Equiv.force (ind2coi-substS σ g (rec gst)) = {!!}
-- the following line for rec-case is a contradiction for gst = transmit d t (var 1)
-- COI.≈'-trans (COI.≈'-trans (ind2coi-substG ⟪ σ , g ⟫ gst gst) (ind2coi-substG σ g (st-substG' 0 (rec gst) gst))) (COI.≈'-trans {!!} (COI.≈'-symm (ind2coi-substG σ (st-substG' 1 (weaken1S (rec g)) gst) (st-substG' 1 (weaken1S (rec g)) gst))))
COI.Equiv.force (ind2coi-substS σ g (var zero)) = COI.≈'-refl
COI.Equiv.force (ind2coi-substS {n} σ g (var (suc x))) = {!!}
ind2coi-substG σ g (transmit d t s) = COI.eq-transmit d {!!} (ind2coi-substS σ g s)
ind2coi-substG σ g (choice d m alt) = COI.eq-choice d λ i → ind2coi-substS σ g (alt i)
ind2coi-substG σ g end = COI.eq-end
-- unfolding vs simultaneous substitution: special, needed case
st-unfold : {n : ℕ} (σ : Stack n) (s : IND.SType n) →
ind2coiS ε (stack-sim-substS (stack-transform (stack2StackS σ)) s) ≈ ind2coiS σ s
st-unfold {0} ε s rewrite (stack-sim-substS-refl s) = COI.≈-refl
st-unfold {suc n} ⟪ σ , x ⟫ s = {!st-unfold σ (st-substS' 0 (rec x) s)!} -- provable if lemm 1 & lemm 2 hold
-- unfolding vs simultaneous substitution: general case
stack-unfoldS : (σ : Stack n) (σ' : Stack' n m) (s : IND.SType (n + m)) →
ind2coiS σ (stack-sim-substS'-top (stack-transform' (stack'2Stack'S σ')) s) ≈ ind2coiS (stack-cat σ σ') s
COI.Equiv.force (stack-unfoldS {n} σ σ' (gdd gst)) = {!!}
COI.Equiv.force (stack-unfoldS σ σ' (rec gst)) = {!!}
COI.Equiv.force (stack-unfoldS {n} σ σ' (var x)) = {!!}
-- unfolding vs simultaneous substition: general case w/ alt. def. for ind2coiS
stack-unfoldS' : (i : Fin (suc n)) (σ : Stack (n ∸ toℕ i)) (σ' : Stack' (n ∸ toℕ i) (toℕ i)) (s : IND.SType n) →
ind2coiS σ (stack-sim-substS'-top (stack-transform' (stack'2Stack'S σ')) s) ≈ ind2coiS' i σ σ' s
COI.Equiv.force (stack-unfoldS' i σ σ' (gdd gst)) = {!!}
COI.Equiv.force (stack-unfoldS' i σ σ' (rec gst)) = {!!} -- req. first lemma from graveyard of lemmas
COI.Equiv.force (stack-unfoldS' i σ σ' (var x)) = {!!}
----------------------------------------------------------------------
-- proof idea for var case:
-- mcl2coiS (stack2StackMCl σ) (tvar x)
-------- getMCl x (stack2StackMCl σ) = σ' , g
-- => mcl2coiG ⟪ σ' , g ⟫ g
-------- getMCl x (stack2StackMCl σ) = (stack2StackMCl (get x σ).1 , mclG ⟪ stack2StackS (get x σ).1 , rec (get x σ).2 ⟫ (get x σ).2
-- => mcl2coiG ⟪ (stack2StackMCl (get x σ).1 , mclG ⟪ stack2StackS (get x σ).1 , rec (get x σ).2 ⟫ (get x σ).2 ⟫ (mclG ⟪ stack2StackS (get x σ).1 , rec (get x σ).2 ⟫ (get x σ).2)
------- which by definition of stack2StackMCl and stack2StackS is equivalent to
-- = mcl2coiG (stack2StackMCl ⟪ (get x σ).1 , (get x σ).2 ⟫) (mclG (stack2StackS ⟪ (get x σ).1 , (get x σ).2 ⟫) g)
------- which, by mcl-equiv-G
-- ≈' ind2coiG ⟪ (get x σ).1 , (get x σ).2 ⟫ (get x σ).2
-- = ind2coiG σ (var x)
getMCl-get : (x : Fin n) (σ : Stack n)
→ getMCl x (stack2StackMCl σ) ≡ (stack2StackMCl (proj₁ (get x σ)) , mclG ⟪ stack2StackS (proj₁ (get x σ)) , rec (proj₂ (get x σ)) ⟫ (proj₂ (get x σ)))
getMCl-get zero ⟪ σ , x ⟫ = refl
getMCl-get (suc x) ⟪ σ , x₁ ⟫ = getMCl-get x σ
----------------------------------------------------------------------
mcl-equiv-S : (σ : Stack n) (s : IND.SType n) →
mcl2coiS (stack2StackMCl σ) (mclS (stack2StackS σ) s) ≈ ind2coiS σ s
mcl-equiv-G : (σ : Stack n) (g : IND.GType n) →
mcl2coiG (stack2StackMCl σ) (mclG (stack2StackS σ) g) ≈' ind2coiG σ g
mcl-equiv-T : (σ : Stack n) (t : IND.Type n) →
mcl2coiT (stack2StackMCl σ) (mclT (stack2StackS σ) t) ≈ᵗ ind2coiT σ t
COI.Equiv.force (mcl-equiv-S σ (gdd gst)) = mcl-equiv-G σ gst
COI.Equiv.force (mcl-equiv-S σ (rec gst)) = mcl-equiv-G ⟪ σ , gst ⟫ gst
COI.Equiv.force (mcl-equiv-S{n} σ (var x))
rewrite (getMCl-get x σ)
with (proj₁ (get x σ)) | (proj₂ (get x σ))
... | σ' | g rewrite (n∸x≡suc[n∸sucx]{n}{toℕ x} toℕx<n) = mcl-equiv-G ⟪ σ' , g ⟫ g
mcl-equiv-G σ (transmit d t s) = COI.eq-transmit d (mcl-equiv-T σ t) (mcl-equiv-S σ s)
mcl-equiv-G σ (choice d m alt) = COI.eq-choice d (λ i → mcl-equiv-S σ (alt i))
mcl-equiv-G σ end = COI.eq-end
mcl-equiv-T σ TUnit = COI.eq-unit
mcl-equiv-T σ TInt = COI.eq-int
mcl-equiv-T σ (TPair t t₁) = COI.eq-pair (mcl-equiv-T σ t) (mcl-equiv-T σ t₁)
mcl-equiv-T {n} σ (TChan x) = COI.eq-chan {!!}
σ : Stack 1
σ = ⟪ ε , end ⟫
g : GType 2
g = transmit SND TInt (var (suc zero))
s : COI.SType
s = ind2coiS σ (rec g)
s' : COI.SType
s' = ind2coiS ε (stack-sim-substS (stack-transform (stack2StackS σ)) (rec g))
s≈s' : s ≈ s'
COI.Equiv.force s≈s' = COI.eq-transmit SND COI.eq-int (record { force = COI.eq-end })
-- naive-mcl-dual : (σ : StackMCl n) (s : IND.SType n) →
-- mcl2coiS σ (naive-dualSt (mclS (stackTail2StackS σ) s)) ≈ mcl2coiS σ (dualS (stackTail2StackS σ) s)
{- graveyard of attempted lemmas
-- idea: "move" a substitution that is done at stack unfolding to a simultaneous subtitution before unfolding
-- problem: cannot formulate this for SType since Stack requires a GType
stack-unfold-lemmaG : {m n : ℕ} (σ : Stack n) (σ' : Stack' n m) (g : GType (suc (n + m))) →
ind2coiG ⟪ σ , stack-sim-substG'-top (weaken1-Stack'Sn 0 (stack-transform' (stack'2Stack'S σ'))) g ⟫ (stack-sim-substG'-top (weaken1-Stack'Sn 0 (stack-transform' (stack'2Stack'S σ'))) g)
≈'
ind2coiG σ (stack-sim-substG'-top (stack-transform' (stack'2Stack'S ⟪ σ' , g ⟫)) g)
stack-unfold-lemmaG {m} {n} σ σ' (transmit d t s) = {!!}
stack-unfold-lemmaG {m} {n} σ σ' (choice d m₁ alt) = {!!}
stack-unfold-lemmaG {m} {n} σ σ' end = {!!}
------------------------------------------------------------
-- won't work for the same reason as below
stack-unfoldS-i : (i : Fin n) (σ : Stack n) (s : IND.SType (suc (n ∸ suc (toℕ i) + toℕ i)))
→ ind2coiS (proj₁ (stack-split i σ)) (stack-sim-substS'-top (stack-transform' (stack'2Stack'S (proj₂ (stack-split i σ)))) s) ≈ ind2coiS σ (rewrfixS{n}{i} s)
stack-unfoldG-i : (i : Fin n) (σ : Stack n) (g : IND.GType (suc (n ∸ suc (toℕ i) + toℕ i)))
→ ind2coiG (proj₁ (stack-split i σ)) (stack-sim-substG'-top (stack-transform' (stack'2Stack'S (proj₂ (stack-split i σ)))) g) ≈' ind2coiG σ (rewrfixG{n}{i} g)
COI.Equiv.force (stack-unfoldS-i i σ (gdd gst)) = {!!}
COI.Equiv.force (stack-unfoldS-i{n} i σ (rec gst)) = {!stack-unfoldG-i (suc i) ? gst!}
COI.Equiv.force (stack-unfoldS-i i σ (var x)) = {!!}
-- won't work. rec case adds something to σ on the left side, but something at the end of (stack-cat σ σ') on the right side.
stack-unfoldS' : (σ : Stack n) (σ' : Stack' n m) (s : IND.SType (n + m)) →
ind2coiS σ (stack-sim-substS'-top (stack-transform' (stack'2Stack'S σ')) s) ≈ ind2coiS (stack-cat σ σ') s
stack-unfoldG' : (σ : Stack n) (σ' : Stack' n m) (g : IND.GType (n + m)) →
ind2coiG σ (stack-sim-substG'-top (stack-transform' (stack'2Stack'S σ')) g) ≈' ind2coiG (stack-cat σ σ') g
COI.Equiv.force (stack-unfoldS' σ σ' (gdd gst)) = {!!}
COI.Equiv.force (stack-unfoldS'{n}{m} σ σ' (rec gst)) = {!!} -- {!stack-unfoldG'{suc n}{m} ⟪ σ , stack-sim-substG'-top-i≥ 1 (stack-transform' (stack'2Stack'S σ')) gst ⟫ (weaken1-Stack' 0 σ') gst!}
COI.Equiv.force (stack-unfoldS' σ σ' (var x)) = {!!}
-}
| 40.024664
| 244
| 0.58148
|
fbdcd20fac85aba0071856a6d5a9e1f5c2df0c69
| 2,015
|
agda
|
Agda
|
Cubical/HITs/DunceCap/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/DunceCap/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/DunceCap/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.DunceCap.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1 using (S¹; base; decodeEncode)
import Cubical.HITs.S1 as S¹
open import Cubical.HITs.MappingCones
open import Cubical.HITs.DunceCap.Base
-- DunceCone is contractible (easy)
Disk : Type₀
Disk = Cone (idfun S¹)
isContr-Disk : isContr Disk
fst isContr-Disk = hub
snd isContr-Disk (inj x) i = spoke x i
snd isContr-Disk hub i = hub
snd isContr-Disk (spoke x j) i = spoke x (i ∧ j)
dunceMap≡id : dunceMap ≡ idfun S¹
dunceMap≡id i base = base
dunceMap≡id i (S¹.loop j) = p i j
where p : S¹.loop ⁻¹ ∙∙ S¹.loop ∙∙ S¹.loop ≡ S¹.loop
p = sym (decodeEncode base (S¹.loop ⁻¹ ∙∙ S¹.loop ∙∙ S¹.loop)) ∙ sym (lUnit S¹.loop)
isContr-DunceCone : isContr DunceCone
isContr-DunceCone = subst isContr (cong Cone (sym dunceMap≡id)) isContr-Disk
-- Dunce is contractible (harder)
contrDunce : (d : Dunce) → d ≡ base
contrDunce base k = loop k
contrDunce (loop i) k = surf k i
contrDunce (surf i j) k
= hcomp (λ l → λ { (i = i0) → surf k j
; (i = i1) → cube l
; (j = i0) → cube l
; (j = i1) → cube l
; (k = i0) → surf i j
; (k = i1) → base })
(surf (k ∨ i) j)
where cube : I → Dunce
cube l = hfill (λ i → λ { (k = i0) → loop i
; (k = i1) → base
; (l = i0) → loop (k ∨ i)
; (l = i1) → surf k i })
(inS (loop k)) i
isContr-Dunce : isContr Dunce
fst isContr-Dunce = base
snd isContr-Dunce = sym ∘ contrDunce
Dunce≡DunceCone : Dunce ≡ DunceCone
Dunce≡DunceCone = ua (Contr→Equiv isContr-Dunce isContr-DunceCone)
| 31
| 92
| 0.602481
|
1cd2503d54812e846cd707042cfba5a9e4a48222
| 652
|
agda
|
Agda
|
lib/types/Cospan.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Cospan.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Cospan.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pi
open import lib.types.Pointed
module lib.types.Cospan where
record Cospan {i j k : ULevel} : Type (lsucc (lmax (lmax i j) k)) where
constructor cospan
field
A : Type i
B : Type j
C : Type k
f : A → C
g : B → C
record ⊙Cospan {i j k : ULevel} : Type (lsucc (lmax (lmax i j) k)) where
constructor ⊙cospan
field
X : Ptd i
Y : Ptd j
Z : Ptd k
f : fst (X ⊙→ Z)
g : fst (Y ⊙→ Z)
⊙cospan-out : ∀ {i j k} → ⊙Cospan {i} {j} {k} → Cospan {i} {j} {k}
⊙cospan-out (⊙cospan X Y Z f g) =
cospan (fst X) (fst Y) (fst Z) (fst f) (fst g)
| 21.733333
| 72
| 0.562883
|
df9a6ac3b98ac945cd8128e939097f8259faee41
| 9,572
|
agda
|
Agda
|
Cubical/Experiments/ZariskiLatticeBasicOpens.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Experiments/ZariskiLatticeBasicOpens.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/ZariskiLatticeBasicOpens.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Experiments.ZariskiLatticeBasicOpens where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.CommRing.Localisation.InvertingElements
open import Cubical.Algebra.CommAlgebra.Base
open import Cubical.Algebra.CommAlgebra.Properties
open import Cubical.Algebra.CommAlgebra.Localisation
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.Algebra.Semilattice
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
open BinaryRelation
open isEquivRel
private
variable
ℓ ℓ' : Level
module Presheaf (A' : CommRing ℓ) where
open CommRingStr (snd A') renaming (_·_ to _·r_ ; ·Comm to ·r-comm ; ·Assoc to ·rAssoc
; ·Lid to ·rLid ; ·Rid to ·rRid)
open Exponentiation A'
open CommRingTheory A'
open InvertingElementsBase A'
open isMultClosedSubset
open CommAlgebraStr ⦃...⦄
private
A = fst A'
A[1/_] : A → CommAlgebra A' ℓ
A[1/ x ] = AlgLoc.S⁻¹RAsCommAlg A' [ x ⁿ|n≥0] (powersFormMultClosedSubset _)
A[1/_]ˣ : (x : A) → ℙ (fst A[1/ x ])
A[1/ x ]ˣ = (CommAlgebra→CommRing A[1/ x ]) ˣ
_≼_ : A → A → Type ℓ
x ≼ y = ∃[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y -- rad(x) ⊆ rad(y)
-- ≼ is a pre-order:
Refl≼ : isRefl _≼_
Refl≼ x = PT.∣ 1 , 1r , ·r-comm _ _ ∣
Trans≼ : isTrans _≼_
Trans≼ x y z = map2 Trans≼Σ
where
Trans≼Σ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] y ^ n ≡ a ·r z
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r z
Trans≼Σ (n , a , p) (m , b , q) = n ·ℕ m , (a ^ m ·r b) , path
where
path : x ^ (n ·ℕ m) ≡ a ^ m ·r b ·r z
path = x ^ (n ·ℕ m) ≡⟨ ^-rdist-·ℕ x n m ⟩
(x ^ n) ^ m ≡⟨ cong (_^ m) p ⟩
(a ·r y) ^ m ≡⟨ ^-ldist-· a y m ⟩
a ^ m ·r y ^ m ≡⟨ cong (a ^ m ·r_) q ⟩
a ^ m ·r (b ·r z) ≡⟨ ·rAssoc _ _ _ ⟩
a ^ m ·r b ·r z ∎
R : A → A → Type ℓ
R x y = x ≼ y × y ≼ x -- rad(x) ≡ rad(y)
RequivRel : isEquivRel R
RequivRel .reflexive x = Refl≼ x , Refl≼ x
RequivRel .symmetric _ _ Rxy = (Rxy .snd) , (Rxy .fst)
RequivRel .transitive _ _ _ Rxy Ryz = Trans≼ _ _ _ (Rxy .fst) (Ryz .fst)
, Trans≼ _ _ _ (Ryz .snd) (Rxy .snd)
RpropValued : isPropValued R
RpropValued x y = isProp× isPropPropTrunc isPropPropTrunc
powerIs≽ : (x a : A) → x ∈ [ a ⁿ|n≥0] → a ≼ x
powerIs≽ x a = map powerIs≽Σ
where
powerIs≽Σ : Σ[ n ∈ ℕ ] (x ≡ a ^ n) → Σ[ n ∈ ℕ ] Σ[ z ∈ A ] (a ^ n ≡ z ·r x)
powerIs≽Σ (n , p) = n , 1r , sym p ∙ sym (·rLid _)
module ≼ToLoc (x y : A) where
private
instance
_ = snd A[1/ x ]
lemma : x ≼ y → y ⋆ 1a ∈ A[1/ x ]ˣ -- y/1 ∈ A[1/x]ˣ
lemma = PT.rec (A[1/ x ]ˣ (y ⋆ 1a) .snd) lemmaΣ
where
path1 : (y z : A) → 1r ·r (y ·r 1r ·r z) ·r 1r ≡ z ·r y
path1 = solve A'
path2 : (xn : A) → xn ≡ 1r ·r 1r ·r (1r ·r 1r ·r xn)
path2 = solve A'
lemmaΣ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y → y ⋆ 1a ∈ A[1/ x ]ˣ
lemmaΣ (n , z , p) = [ z , (x ^ n) , PT.∣ n , refl ∣ ] -- xⁿ≡zy → y⁻¹ ≡ z/xⁿ
, eq/ _ _ ((1r , powersFormMultClosedSubset _ .containsOne)
, (path1 _ _ ∙∙ sym p ∙∙ path2 _))
module ≼PowerToLoc (x y : A) (x≼y : x ≼ y) where
private
[yⁿ|n≥0] = [ y ⁿ|n≥0]
instance
_ = snd A[1/ x ]
lemma : ∀ (s : A) → s ∈ [yⁿ|n≥0] → s ⋆ 1a ∈ A[1/ x ]ˣ
lemma _ s∈[yⁿ|n≥0] = ≼ToLoc.lemma _ _ (Trans≼ _ y _ x≼y (powerIs≽ _ _ s∈[yⁿ|n≥0]))
𝓞ᴰ : A / R → CommAlgebra A' ℓ
𝓞ᴰ = rec→Gpd.fun isGroupoidCommAlgebra (λ a → A[1/ a ]) RCoh LocPathProp
where
RCoh : ∀ a b → R a b → A[1/ a ] ≡ A[1/ b ]
RCoh a b (a≼b , b≼a) = fst (isContrS₁⁻¹R≡S₂⁻¹R (≼PowerToLoc.lemma _ _ b≼a)
(≼PowerToLoc.lemma _ _ a≼b))
where
open AlgLocTwoSubsets A' [ a ⁿ|n≥0] (powersFormMultClosedSubset _)
[ b ⁿ|n≥0] (powersFormMultClosedSubset _)
LocPathProp : ∀ a b → isProp (A[1/ a ] ≡ A[1/ b ])
LocPathProp a b = isPropS₁⁻¹R≡S₂⁻¹R
where
open AlgLocTwoSubsets A' [ a ⁿ|n≥0] (powersFormMultClosedSubset _)
[ b ⁿ|n≥0] (powersFormMultClosedSubset _)
-- The quotient A/R corresponds to the basic opens of the Zariski topology.
-- Multiplication lifts to the quotient and corresponds to intersection
-- of basic opens, i.e. we get a meet-semilattice with:
_∧/_ : A / R → A / R → A / R
_∧/_ = setQuotSymmBinOp (RequivRel .reflexive) (RequivRel .transitive) _·r_
(λ a b → subst (λ x → R (a ·r b) x) (·r-comm a b) (RequivRel .reflexive (a ·r b))) ·r-lcoh
where
·r-lcoh-≼ : (x y z : A) → x ≼ y → (x ·r z) ≼ (y ·r z)
·r-lcoh-≼ x y z = map ·r-lcoh-≼Σ
where
path : (x z a y zn : A) → x ·r z ·r (a ·r y ·r zn) ≡ x ·r zn ·r a ·r (y ·r z)
path = solve A'
·r-lcoh-≼Σ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] (x ·r z) ^ n ≡ a ·r (y ·r z)
·r-lcoh-≼Σ (n , a , p) = suc n , (x ·r z ^ n ·r a) , (cong (x ·r z ·r_) (^-ldist-· _ _ _)
∙∙ cong (λ v → x ·r z ·r (v ·r z ^ n)) p
∙∙ path _ _ _ _ _)
·r-lcoh : (x y z : A) → R x y → R (x ·r z) (y ·r z)
·r-lcoh x y z Rxy = ·r-lcoh-≼ x y z (Rxy .fst) , ·r-lcoh-≼ y x z (Rxy .snd)
BasicOpens : Semilattice ℓ
BasicOpens = makeSemilattice [ 1r ] _∧/_ squash/
(elimProp3 (λ _ _ _ → squash/ _ _) λ _ _ _ → cong [_] (·rAssoc _ _ _))
(elimProp (λ _ → squash/ _ _) λ _ → cong [_] (·rRid _))
(elimProp (λ _ → squash/ _ _) λ _ → cong [_] (·rLid _))
(elimProp2 (λ _ _ → squash/ _ _) λ _ _ → cong [_] (·r-comm _ _))
(elimProp (λ _ → squash/ _ _) λ a → eq/ _ _ -- R a a²
(∣ 1 , a , ·rRid _ ∣ , ∣ 2 , 1r , cong (a ·r_) (·rRid a) ∙ sym (·rLid _) ∣))
-- The induced partial order
open MeetSemilattice BasicOpens renaming (_≤_ to _≼/_ ; IndPoset to BasicOpensAsPoset)
-- coincides with our ≼
≼/CoincidesWith≼ : ∀ (x y : A) → ([ x ] ≼/ [ y ]) ≡ (x ≼ y)
≼/CoincidesWith≼ x y = [ x ] ≼/ [ y ] -- ≡⟨ refl ⟩ [ x ·r y ] ≡ [ x ]
≡⟨ isoToPath (isEquivRel→effectiveIso RpropValued RequivRel _ _) ⟩
R (x ·r y) x
≡⟨ isoToPath Σ-swap-Iso ⟩
R x (x ·r y)
≡⟨ hPropExt (RpropValued _ _) isPropPropTrunc ·To≼ ≼To· ⟩
x ≼ y ∎
where
x≼xy→x≼yΣ : Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r (x ·r y)
→ Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y
x≼xy→x≼yΣ (n , z , p) = n , (z ·r x) , p ∙ ·rAssoc _ _ _
·To≼ : R x (x ·r y) → x ≼ y
·To≼ (x≼xy , _) = PT.map x≼xy→x≼yΣ x≼xy
x≼y→x≼xyΣ : Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y
→ Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r (x ·r y)
x≼y→x≼xyΣ (n , z , p) = suc n , z , cong (x ·r_) p ∙ ·CommAssocl _ _ _
≼To· : x ≼ y → R x ( x ·r y)
≼To· x≼y = PT.map x≼y→x≼xyΣ x≼y , PT.∣ 1 , y , ·rRid _ ∙ ·r-comm _ _ ∣
open IsPoset
open PosetStr
Refl≼/ : isRefl _≼/_
Refl≼/ = BasicOpensAsPoset .snd .isPoset .is-refl
Trans≼/ : isTrans _≼/_
Trans≼/ = BasicOpensAsPoset .snd .isPoset .is-trans
-- The restrictions:
ρᴰᴬ : (a b : A) → a ≼ b → isContr (CommAlgebraHom A[1/ b ] A[1/ a ])
ρᴰᴬ _ b a≼b = A[1/b]HasUniversalProp _ (≼PowerToLoc.lemma _ _ a≼b)
where
open AlgLoc A' [ b ⁿ|n≥0] (powersFormMultClosedSubset _)
renaming (S⁻¹RHasAlgUniversalProp to A[1/b]HasUniversalProp)
ρᴰᴬId : ∀ (a : A) (r : a ≼ a) → ρᴰᴬ a a r .fst ≡ idAlgHom
ρᴰᴬId a r = ρᴰᴬ a a r .snd _
ρᴰᴬComp : ∀ (a b c : A) (l : a ≼ b) (m : b ≼ c)
→ ρᴰᴬ a c (Trans≼ _ _ _ l m) .fst ≡ ρᴰᴬ a b l .fst ∘a ρᴰᴬ b c m .fst
ρᴰᴬComp a _ c l m = ρᴰᴬ a c (Trans≼ _ _ _ l m) .snd _
ρᴰ : (x y : A / R) → x ≼/ y → CommAlgebraHom (𝓞ᴰ y) (𝓞ᴰ x)
ρᴰ = elimContr2 λ _ _ → isContrΠ
λ [a]≼/[b] → ρᴰᴬ _ _ (transport (≼/CoincidesWith≼ _ _) [a]≼/[b])
ρᴰId : ∀ (x : A / R) (r : x ≼/ x) → ρᴰ x x r ≡ idAlgHom
ρᴰId = SQ.elimProp (λ _ → isPropΠ (λ _ → isSetAlgebraHom _ _ _ _))
λ a r → ρᴰᴬId a (transport (≼/CoincidesWith≼ _ _) r)
ρᴰComp : ∀ (x y z : A / R) (l : x ≼/ y) (m : y ≼/ z)
→ ρᴰ x z (Trans≼/ _ _ _ l m) ≡ ρᴰ x y l ∘a ρᴰ y z m
ρᴰComp = SQ.elimProp3 (λ _ _ _ → isPropΠ2 (λ _ _ → isSetAlgebraHom _ _ _ _))
λ a b c _ _ → sym (ρᴰᴬ a c _ .snd _) ∙ ρᴰᴬComp a b c _ _
| 38.288
| 100
| 0.534371
|
dc9357a0442bc451696b329cf5b305d548de8188
| 16,018
|
agda
|
Agda
|
Cubical/Functions/Embedding.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Functions/Embedding.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Functions/Embedding.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Functions.Embedding where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence using (ua; univalence; pathToEquiv)
open import Cubical.Functions.Fibration
open import Cubical.Data.Sigma
open import Cubical.Functions.Fibration
open import Cubical.Functions.FunExtEquiv
open import Cubical.Relation.Nullary using (Discrete; yes; no)
open import Cubical.Structures.Axioms
open import Cubical.Reflection.StrictEquiv
open import Cubical.Data.Nat using (ℕ; zero; suc)
open import Cubical.Data.Sigma
private
variable
ℓ ℓ₁ ℓ₂ : Level
A B : Type ℓ
f h : A → B
w x : A
y z : B
-- Embeddings are generalizations of injections. The usual
-- definition of injection as:
--
-- f x ≡ f y → x ≡ y
--
-- is not well-behaved with higher h-levels, while embeddings
-- are.
isEmbedding : (A → B) → Type _
isEmbedding f = ∀ w x → isEquiv {A = w ≡ x} (cong f)
isPropIsEmbedding : isProp (isEmbedding f)
isPropIsEmbedding {f = f} = isPropΠ2 λ _ _ → isPropIsEquiv (cong f)
-- If A and B are h-sets, then injective functions between
-- them are embeddings.
--
-- Note: It doesn't appear to be possible to omit either of
-- the `isSet` hypotheses.
injEmbedding
: {f : A → B}
→ isSet A → isSet B
→ (∀{w x} → f w ≡ f x → w ≡ x)
→ isEmbedding f
injEmbedding {f = f} iSA iSB inj w x
= isoToIsEquiv (iso (cong f) inj sect retr)
where
sect : section (cong f) inj
sect p = iSB (f w) (f x) _ p
retr : retract (cong f) inj
retr p = iSA w x _ p
-- If `f` is an embedding, we'd expect the fibers of `f` to be
-- propositions, like an injective function.
hasPropFibers : (A → B) → Type _
hasPropFibers f = ∀ y → isProp (fiber f y)
-- This can be relaxed to having all prop fibers over the image, see [hasPropFibersOfImage→isEmbedding]
hasPropFibersOfImage : (A → B) → Type _
hasPropFibersOfImage f = ∀ x → isProp (fiber f (f x))
-- some notation
_↪_ : Type ℓ₁ → Type ℓ₂ → Type (ℓ-max ℓ₁ ℓ₂)
A ↪ B = Σ[ f ∈ (A → B) ] isEmbedding f
hasPropFibersIsProp : isProp (hasPropFibers f)
hasPropFibersIsProp = isPropΠ (λ _ → isPropIsProp)
private
lemma₀ : (p : y ≡ z) → fiber f y ≡ fiber f z
lemma₀ {f = f} p = λ i → fiber f (p i)
lemma₁ : isEmbedding f → ∀ x → isContr (fiber f (f x))
lemma₁ {f = f} iE x = value , path
where
value : fiber f (f x)
value = (x , refl)
path : ∀(fi : fiber f (f x)) → value ≡ fi
path (w , p) i
= case equiv-proof (iE w x) p of λ
{ ((q , sq) , _)
→ hfill (λ j → λ { (i = i0) → (x , refl)
; (i = i1) → (w , sq j)
})
(inS (q (~ i) , λ j → f (q (~ i ∨ j))))
i1
}
isEmbedding→hasPropFibers : isEmbedding f → hasPropFibers f
isEmbedding→hasPropFibers iE y (x , p)
= subst (λ f → isProp f) (lemma₀ p) (isContr→isProp (lemma₁ iE x)) (x , p)
private
fibCong→PathP
: {f : A → B}
→ (p : f w ≡ f x)
→ (fi : fiber (cong f) p)
→ PathP (λ i → fiber f (p i)) (w , refl) (x , refl)
fibCong→PathP p (q , r) i = q i , λ j → r j i
PathP→fibCong
: {f : A → B}
→ (p : f w ≡ f x)
→ (pp : PathP (λ i → fiber f (p i)) (w , refl) (x , refl))
→ fiber (cong f) p
PathP→fibCong p pp = (λ i → fst (pp i)) , (λ j i → snd (pp i) j)
PathP≡fibCong
: {f : A → B}
→ (p : f w ≡ f x)
→ PathP (λ i → fiber f (p i)) (w , refl) (x , refl) ≡ fiber (cong f) p
PathP≡fibCong p
= isoToPath (iso (PathP→fibCong p) (fibCong→PathP p) (λ _ → refl) (λ _ → refl))
hasPropFibers→isEmbedding : hasPropFibers f → isEmbedding f
hasPropFibers→isEmbedding {f = f} iP w x .equiv-proof p
= subst isContr (PathP≡fibCong p) (isProp→isContrPathP (λ i → iP (p i)) fw fx)
where
fw : fiber f (f w)
fw = (w , refl)
fx : fiber f (f x)
fx = (x , refl)
hasPropFibersOfImage→hasPropFibers : hasPropFibersOfImage f → hasPropFibers f
hasPropFibersOfImage→hasPropFibers {f = f} fibImg y a b =
subst (λ y → isProp (fiber f y)) (snd a) (fibImg (fst a)) a b
hasPropFibersOfImage→isEmbedding : hasPropFibersOfImage f → isEmbedding f
hasPropFibersOfImage→isEmbedding = hasPropFibers→isEmbedding ∘ hasPropFibersOfImage→hasPropFibers
isEmbedding≡hasPropFibers : isEmbedding f ≡ hasPropFibers f
isEmbedding≡hasPropFibers
= isoToPath
(iso isEmbedding→hasPropFibers
hasPropFibers→isEmbedding
(λ _ → hasPropFibersIsProp _ _)
(λ _ → isPropIsEmbedding _ _))
isEquiv→hasPropFibers : isEquiv f → hasPropFibers f
isEquiv→hasPropFibers e b = isContr→isProp (equiv-proof e b)
isEquiv→isEmbedding : isEquiv f → isEmbedding f
isEquiv→isEmbedding e = λ _ _ → congEquiv (_ , e) .snd
Equiv→Embedding : A ≃ B → A ↪ B
Equiv→Embedding (f , isEquivF) = (f , isEquiv→isEmbedding isEquivF)
iso→isEmbedding : ∀ {ℓ} {A B : Type ℓ}
→ (isom : Iso A B)
-------------------------------
→ isEmbedding (Iso.fun isom)
iso→isEmbedding {A = A} {B} isom = (isEquiv→isEmbedding (equivIsEquiv (isoToEquiv isom)))
isEmbedding→Injection :
∀ {ℓ} {A B C : Type ℓ}
→ (a : A → B)
→ (e : isEmbedding a)
----------------------
→ ∀ {f g : C → A} →
∀ x → (a (f x) ≡ a (g x)) ≡ (f x ≡ g x)
isEmbedding→Injection a e {f = f} {g} x = sym (ua (cong a , e (f x) (g x)))
-- if `f` has a retract, then `cong f` has, as well. If `B` is a set, then `cong f`
-- further has a section, making `f` an embedding.
module _ {f : A → B} (retf : hasRetract f) where
open Σ retf renaming (fst to g ; snd to ϕ)
congRetract : f w ≡ f x → w ≡ x
congRetract {w = w} {x = x} p = sym (ϕ w) ∙∙ cong g p ∙∙ ϕ x
isRetractCongRetract : retract (cong {x = w} {y = x} f) congRetract
isRetractCongRetract p = transport (PathP≡doubleCompPathˡ _ _ _ _) (λ i j → ϕ (p j) i)
hasRetract→hasRetractCong : hasRetract (cong {x = w} {y = x} f)
hasRetract→hasRetractCong = congRetract , isRetractCongRetract
retractableIntoSet→isEmbedding : isSet B → isEmbedding f
retractableIntoSet→isEmbedding setB w x =
isoToIsEquiv (iso (cong f) congRetract (λ _ → setB _ _ _ _) (hasRetract→hasRetractCong .snd))
Embedding-into-Discrete→Discrete : A ↪ B → Discrete B → Discrete A
Embedding-into-Discrete→Discrete (f , isEmbeddingF) _≟_ x y with f x ≟ f y
... | yes p = yes (invIsEq (isEmbeddingF x y) p)
... | no ¬p = no (¬p ∘ cong f)
Embedding-into-isProp→isProp : A ↪ B → isProp B → isProp A
Embedding-into-isProp→isProp (f , isEmbeddingF) isProp-B x y
= invIsEq (isEmbeddingF x y) (isProp-B (f x) (f y))
Embedding-into-isSet→isSet : A ↪ B → isSet B → isSet A
Embedding-into-isSet→isSet (f , isEmbeddingF) isSet-B x y p q =
p ≡⟨ sym (retIsEq isEquiv-cong-f p) ⟩
cong-f⁻¹ (cong f p) ≡⟨ cong cong-f⁻¹ cong-f-p≡cong-f-q ⟩
cong-f⁻¹ (cong f q) ≡⟨ retIsEq isEquiv-cong-f q ⟩
q ∎
where
cong-f-p≡cong-f-q = isSet-B (f x) (f y) (cong f p) (cong f q)
isEquiv-cong-f = isEmbeddingF x y
cong-f⁻¹ = invIsEq isEquiv-cong-f
Embedding-into-hLevel→hLevel
: ∀ n → A ↪ B → isOfHLevel (suc n) B → isOfHLevel (suc n) A
Embedding-into-hLevel→hLevel zero = Embedding-into-isProp→isProp
Embedding-into-hLevel→hLevel (suc n) (f , isEmbeddingF) Blvl x y
= isOfHLevelRespectEquiv (suc n) (invEquiv equiv) subLvl
where
equiv : (x ≡ y) ≃ (f x ≡ f y)
equiv .fst = cong f
equiv .snd = isEmbeddingF x y
subLvl : isOfHLevel (suc n) (f x ≡ f y)
subLvl = Blvl (f x) (f y)
-- We now show that the powerset is the subtype classifier
-- i.e. ℙ X ≃ Σ[A ∈ Type ℓ] (A ↪ X)
Embedding→Subset : {X : Type ℓ} → Σ[ A ∈ Type ℓ ] (A ↪ X) → ℙ X
Embedding→Subset (_ , f , isEmbeddingF) x = fiber f x , isEmbedding→hasPropFibers isEmbeddingF x
Subset→Embedding : {X : Type ℓ} → ℙ X → Σ[ A ∈ Type ℓ ] (A ↪ X)
Subset→Embedding {X = X} A = D , fst , Ψ
where
D = Σ[ x ∈ X ] x ∈ A
Ψ : isEmbedding fst
Ψ w x = isEmbeddingFstΣProp (∈-isProp A)
Subset→Embedding→Subset : {X : Type ℓ} → section (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Subset→Embedding→Subset _ = funExt λ x → Σ≡Prop (λ _ → isPropIsProp) (ua (FiberIso.fiberEquiv _ x))
Embedding→Subset→Embedding : {X : Type ℓ} → retract (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Embedding→Subset→Embedding {ℓ = ℓ} {X = X} (A , f , ψ) =
cong (equivFun Σ-assoc-≃) (Σ≡Prop (λ _ → isPropIsEmbedding) (retEq (fibrationEquiv X ℓ) (A , f)))
Subset≃Embedding : {X : Type ℓ} → ℙ X ≃ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≃Embedding = isoToEquiv (iso Subset→Embedding Embedding→Subset
Embedding→Subset→Embedding Subset→Embedding→Subset)
Subset≡Embedding : {X : Type ℓ} → ℙ X ≡ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≡Embedding = ua Subset≃Embedding
isEmbedding-∘ : isEmbedding f → isEmbedding h → isEmbedding (f ∘ h)
isEmbedding-∘ {f = f} {h = h} Embf Embh w x
= compEquiv (cong h , Embh w x) (cong f , Embf (h w) (h x)) .snd
isEmbedding→embedsFibersIntoSingl
: isEmbedding f
→ ∀ z → fiber f z ↪ singl z
isEmbedding→embedsFibersIntoSingl {f = f} isE z = e , isEmbE where
e : fiber f z → singl z
e x = f (fst x) , sym (snd x)
isEmbE : isEmbedding e
isEmbE u v = goal where
-- "adjust" ΣeqCf by trivial equivalences that hold judgementally, which should save compositions
Dom′ : ∀ u v → Type _
Dom′ u v = Σ[ p ∈ fst u ≡ fst v ] PathP (λ i → f (p i) ≡ z) (snd u) (snd v)
Cod′ : ∀ u v → Type _
Cod′ u v = Σ[ p ∈ f (fst u) ≡ f (fst v) ] PathP (λ i → p i ≡ z) (snd u) (snd v)
ΣeqCf : Dom′ u v ≃ Cod′ u v
ΣeqCf = Σ-cong-equiv-fst (_ , isE _ _)
dom→ : u ≡ v → Dom′ u v
dom→ p = cong fst p , cong snd p
dom← : Dom′ u v → u ≡ v
dom← p i = p .fst i , p .snd i
cod→ : e u ≡ e v → Cod′ u v
cod→ p = cong fst p , cong (sym ∘ snd) p
cod← : Cod′ u v → e u ≡ e v
cod← p i = p .fst i , sym (p .snd i)
goal : isEquiv (cong e)
goal .equiv-proof x .fst .fst =
dom← (equivCtr ΣeqCf (cod→ x) .fst)
goal .equiv-proof x .fst .snd j =
cod← (equivCtr ΣeqCf (cod→ x) .snd j)
goal .equiv-proof x .snd (g , p) i .fst =
dom← (equivCtrPath ΣeqCf (cod→ x) (dom→ g , cong cod→ p) i .fst)
goal .equiv-proof x .snd (g , p) i .snd j =
cod← (equivCtrPath ΣeqCf (cod→ x) (dom→ g , cong cod→ p) i .snd j)
isEmbedding→hasPropFibers′ : isEmbedding f → hasPropFibers f
isEmbedding→hasPropFibers′ {f = f} iE z =
Embedding-into-isProp→isProp (isEmbedding→embedsFibersIntoSingl iE z) isPropSingl
universeEmbedding :
∀ {ℓ ℓ₁ : Level}
→ (F : Type ℓ → Type ℓ₁)
→ (∀ X → F X ≃ X)
→ isEmbedding F
universeEmbedding F liftingEquiv = hasPropFibersOfImage→isEmbedding propFibersF where
lemma : ∀ A B → (F A ≡ F B) ≃ (B ≡ A)
lemma A B = (F A ≡ F B) ≃⟨ univalence ⟩
(F A ≃ F B) ≃⟨ equivComp (liftingEquiv A) (liftingEquiv B) ⟩
(A ≃ B) ≃⟨ invEquivEquiv ⟩
(B ≃ A) ≃⟨ invEquiv univalence ⟩
(B ≡ A) ■
fiberSingl : ∀ X → fiber F (F X) ≃ singl X
fiberSingl X = Σ-cong-equiv-snd (λ _ → lemma _ _)
propFibersF : hasPropFibersOfImage F
propFibersF X = Embedding-into-isProp→isProp (Equiv→Embedding (fiberSingl X)) isPropSingl
liftEmbedding : (ℓ ℓ₁ : Level)
→ isEmbedding (Lift {i = ℓ} {j = ℓ₁})
liftEmbedding ℓ ℓ₁ = universeEmbedding (Lift {j = ℓ₁}) (λ _ → invEquiv LiftEquiv)
module FibrationIdentityPrinciple {B : Type ℓ} {ℓ₁} where
-- note that fibrationEquiv (for good reason) uses ℓ₁ = ℓ-max ℓ ℓ₁, so we have to work
-- some universe magic to achieve good universe polymorphism
-- First, prove it for the case that's dealt with in fibrationEquiv
Fibration′ = Fibration B (ℓ-max ℓ ℓ₁)
module Lifted (f g : Fibration′) where
f≃g′ : Type (ℓ-max ℓ ℓ₁)
f≃g′ = ∀ b → fiber (f .snd) b ≃ fiber (g .snd) b
Fibration′IP : f≃g′ ≃ (f ≡ g)
Fibration′IP =
f≃g′
≃⟨ equivΠCod (λ _ → invEquiv univalence) ⟩
(∀ b → fiber (f .snd) b ≡ fiber (g .snd) b)
≃⟨ funExtEquiv ⟩
fiber (f .snd) ≡ fiber (g .snd)
≃⟨ invEquiv (congEquiv (fibrationEquiv B ℓ₁)) ⟩
f ≡ g
■
-- Then embed into the above case by lifting the type
L : Type _ → Type _ -- local synonym fixing the levels of Lift
L = Lift {i = ℓ₁} {j = ℓ}
liftFibration : Fibration B ℓ₁ → Fibration′
liftFibration (A , f) = L A , f ∘ lower
hasPropFibersLiftFibration : hasPropFibers liftFibration
hasPropFibersLiftFibration (A , f) =
Embedding-into-isProp→isProp (Equiv→Embedding fiberChar)
(isPropΣ (isEmbedding→hasPropFibers (liftEmbedding _ _) A)
λ _ → isEquiv→hasPropFibers (snd (invEquiv (preCompEquiv LiftEquiv))) _)
where
fiberChar : fiber liftFibration (A , f)
≃ (Σ[ (E , eq) ∈ fiber L A ] fiber (_∘ lower) (transport⁻ (λ i → eq i → B) f))
fiberChar =
fiber liftFibration (A , f)
≃⟨ Σ-cong-equiv-snd (λ _ → invEquiv ΣPath≃PathΣ) ⟩
(Σ[ (E , g) ∈ Fibration B ℓ₁ ] Σ[ eq ∈ (L E ≡ A) ] PathP (λ i → eq i → B) (g ∘ lower) f)
≃⟨ boringSwap ⟩
(Σ[ (E , eq) ∈ fiber L A ] Σ[ g ∈ (E → B) ] PathP (λ i → eq i → B) (g ∘ lower) f)
≃⟨ Σ-cong-equiv-snd (λ _ → Σ-cong-equiv-snd λ _ → pathToEquiv (PathP≡Path⁻ _ _ _)) ⟩
(Σ[ (E , eq) ∈ fiber L A ] fiber (_∘ lower) (transport⁻ (λ i → eq i → B) f))
■ where
unquoteDecl boringSwap =
declStrictEquiv boringSwap
(λ ((E , g) , (eq , p)) → ((E , eq) , (g , p)))
(λ ((E , g) , (eq , p)) → ((E , eq) , (g , p)))
isEmbeddingLiftFibration : isEmbedding liftFibration
isEmbeddingLiftFibration = hasPropFibers→isEmbedding hasPropFibersLiftFibration
-- and finish off
module _ (f g : Fibration B ℓ₁) where
open Lifted (liftFibration f) (liftFibration g)
f≃g : Type (ℓ-max ℓ ℓ₁)
f≃g = ∀ b → fiber (f .snd) b ≃ fiber (g .snd) b
FibrationIP : f≃g ≃ (f ≡ g)
FibrationIP =
f≃g ≃⟨ equivΠCod (λ b → equivComp (Σ-cong-equiv-fst LiftEquiv)
(Σ-cong-equiv-fst LiftEquiv)) ⟩
f≃g′ ≃⟨ Fibration′IP ⟩
(liftFibration f ≡ liftFibration g) ≃⟨ invEquiv (_ , isEmbeddingLiftFibration _ _) ⟩
(f ≡ g) ■
open FibrationIdentityPrinciple renaming (f≃g to _≃Fib_) using (FibrationIP) public
Embedding : (B : Type ℓ₁) → (ℓ : Level) → Type (ℓ-max ℓ₁ (ℓ-suc ℓ))
Embedding B ℓ = Σ[ A ∈ Type ℓ ] A ↪ B
module EmbeddingIdentityPrinciple {B : Type ℓ} {ℓ₁} (f g : Embedding B ℓ₁) where
module _ where
open Σ f renaming (fst to F) public
open Σ g renaming (fst to G) public
open Σ (f .snd) renaming (fst to ffun; snd to isEmbF) public
open Σ (g .snd) renaming (fst to gfun; snd to isEmbG) public
f≃g : Type _
f≃g = (∀ b → fiber ffun b → fiber gfun b) ×
(∀ b → fiber gfun b → fiber ffun b)
toFibr : Embedding B ℓ₁ → Fibration B ℓ₁
toFibr (A , (f , _)) = (A , f)
isEmbeddingToFibr : isEmbedding toFibr
isEmbeddingToFibr w x = fullEquiv .snd where
-- carefully managed such that (cong toFibr) is the equivalence
fullEquiv : (w ≡ x) ≃ (toFibr w ≡ toFibr x)
fullEquiv = compEquiv (congEquiv (invEquiv Σ-assoc-≃)) (invEquiv (Σ≡PropEquiv (λ _ → isPropIsEmbedding)))
EmbeddingIP : f≃g ≃ (f ≡ g)
EmbeddingIP =
f≃g
≃⟨ strictIsoToEquiv (invIso toProdIso) ⟩
(∀ b → (fiber ffun b → fiber gfun b) × (fiber gfun b → fiber ffun b))
≃⟨ equivΠCod (λ _ → isEquivPropBiimpl→Equiv (isEmbedding→hasPropFibers isEmbF _)
(isEmbedding→hasPropFibers isEmbG _)) ⟩
(∀ b → (fiber (f .snd .fst) b) ≃ (fiber (g .snd .fst) b))
≃⟨ FibrationIP (toFibr f) (toFibr g) ⟩
(toFibr f ≡ toFibr g)
≃⟨ invEquiv (_ , isEmbeddingToFibr _ _) ⟩
f ≡ g
■
open EmbeddingIdentityPrinciple renaming (f≃g to _≃Emb_) using (EmbeddingIP) public
| 37.425234
| 109
| 0.614996
|
d07ea617123bd7b81b2d32c51e25699ab862e857
| 836
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Nat.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Nat.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Nat.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat where
------------------------------------------------------------------------
-- Publicly re-export the contents of the base module
open import Data.Nat.Base public
------------------------------------------------------------------------
-- Publicly re-export queries
open import Data.Nat.Properties public
using
( _≟_
; _≤?_ ; _≥?_ ; _<?_ ; _>?_
; _≤′?_; _≥′?_; _<′?_; _>′?_
; _≤″?_; _<″?_; _≥″?_; _>″?_
)
------------------------------------------------------------------------
-- Deprecated
-- Version 0.17
open import Data.Nat.Properties public
using (≤-pred)
| 24.588235
| 72
| 0.348086
|
cb98285a253a67858a4ae45d600913ea1957c80c
| 3,624
|
agda
|
Agda
|
src/Categories/Diagram/Pullback/Properties.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Pullback/Properties.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Pullback/Properties.agda
|
glittershark/agda-categories
|
2128fab9e8d341364cbf784bb17c547bf73891de
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Diagram.Pullback.Properties {o ℓ e} (C : Category o ℓ e) where
open import Function using (_$_)
open import Categories.Category.Cartesian C
open import Categories.Diagram.Pullback C
open import Categories.Diagram.Equalizer C
open import Categories.Object.Product C
open import Categories.Object.Terminal C
open import Categories.Morphism.Reasoning C
private
open Category C
variable
X Y Z : Obj
f g h i : X ⇒ Y
open HomReasoning
-- pullback from a terminal object is the same as a product
module _ (t : Terminal) where
open Terminal t
pullback-⊤⇒product : Pullback (! {X}) (! {Y}) → Product X Y
pullback-⊤⇒product p = record
{ A×B = P
; π₁ = p₁
; π₂ = p₂
; ⟨_,_⟩ = λ f g → universal (!-unique₂ {f = ! ∘ f} {g = ! ∘ g})
; project₁ = p₁∘universal≈h₁
; project₂ = p₂∘universal≈h₂
; unique = λ eq eq′ → ⟺ (unique eq eq′)
}
where open Pullback p
product⇒pullback-⊤ : Product X Y → Pullback (! {X}) (! {Y})
product⇒pullback-⊤ p = record
{ p₁ = π₁
; p₂ = π₂
; commute = !-unique₂
; universal = λ {_ f g} _ → ⟨ f , g ⟩
; unique = λ eq eq′ → ⟺ (unique eq eq′)
; p₁∘universal≈h₁ = project₁
; p₂∘universal≈h₂ = project₂
}
where open Product p
-- pullbacks respect _≈_
module _ (p : Pullback f g) where
open Pullback p
pullback-resp-≈ : f ≈ h → g ≈ i → Pullback h i
pullback-resp-≈ eq eq′ = record
{ p₁ = p₁
; p₂ = p₂
; commute = ∘-resp-≈ˡ (⟺ eq) ○ commute ○ ∘-resp-≈ˡ eq′
; universal = λ eq″ → universal (∘-resp-≈ˡ eq ○ eq″ ○ ∘-resp-≈ˡ (⟺ eq′))
; unique = unique
; p₁∘universal≈h₁ = p₁∘universal≈h₁
; p₂∘universal≈h₂ = p₂∘universal≈h₂
}
module _ (pullbacks : ∀ {X Y Z} (f : X ⇒ Z) (g : Y ⇒ Z) → Pullback f g)
(cartesian : Cartesian) where
open Cartesian cartesian
pullback×cartesian⇒equalizer : Equalizer f g
pullback×cartesian⇒equalizer {f = f} {g = g} = record
{ arr = p.p₁
; equality = equality
; equalize = λ {_ h} eq → p.universal $ begin
⟨ f , g ⟩ ∘ h ≈⟨ ⟨⟩∘ ⟩
⟨ f ∘ h , g ∘ h ⟩ ≈˘⟨ ⟨⟩-cong₂ identityˡ (identityˡ ○ eq) ⟩
⟨ id ∘ f ∘ h , id ∘ f ∘ h ⟩ ≈˘⟨ ⟨⟩∘ ⟩
⟨ id , id ⟩ ∘ f ∘ h ∎
; universal = ⟺ p.p₁∘universal≈h₁
; unique = λ eq → p.unique (⟺ eq)
(⟺ (pullˡ eq′) ○ ⟺ (∘-resp-≈ʳ eq))
}
where p : Pullback ⟨ f , g ⟩ ⟨ id , id ⟩
p = pullbacks _ _
module p = Pullback p
eq : ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈ ⟨ p.p₂ , p.p₂ ⟩
eq = begin
⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈˘⟨ ⟨⟩∘ ⟩
⟨ f , g ⟩ ∘ p.p₁ ≈⟨ p.commute ⟩
⟨ id , id ⟩ ∘ p.p₂ ≈⟨ ⟨⟩∘ ⟩
⟨ id ∘ p.p₂ , id ∘ p.p₂ ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ identityˡ ⟩
⟨ p.p₂ , p.p₂ ⟩ ∎
eq′ : f ∘ p.p₁ ≈ p.p₂
eq′ = begin
f ∘ p.p₁ ≈˘⟨ project₁ ⟩
π₁ ∘ ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈⟨ refl⟩∘⟨ eq ⟩
π₁ ∘ ⟨ p.p₂ , p.p₂ ⟩ ≈⟨ project₁ ⟩
p.p₂ ∎
equality : f ∘ p.p₁ ≈ g ∘ p.p₁
equality = begin
f ∘ p.p₁ ≈⟨ eq′ ⟩
p.p₂ ≈˘⟨ project₂ ⟩
π₂ ∘ ⟨ p.p₂ , p.p₂ ⟩ ≈˘⟨ refl⟩∘⟨ eq ⟩
π₂ ∘ ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈⟨ project₂ ⟩
g ∘ p.p₁ ∎
| 34.188679
| 82
| 0.458057
|
4a5e17dcc95c39c065f9d631dc705d5b3b412cfc
| 171
|
agda
|
Agda
|
Cubical/HITs/Rational.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/Rational.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Rational.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Rational where
open import Cubical.HITs.Rational.Base public
-- open import Cubical.HITs.Rational.Properties public
| 24.428571
| 54
| 0.77193
|
0e2e033592b1c31e03db63387d8afc9bbc9c08d3
| 1,086
|
agda
|
Agda
|
archive/agda-2/Oscar/Definition.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-2/Oscar/Definition.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-2/Oscar/Definition.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Oscar.Definition where
{-
unpack : AList m n → Fin m → Term n -- sub
substitute : (Fin m → Term n) → Term m → Term n -- _◃_
substitutes : ∀ N → (Fin m → Term n) → Terms N m → Terms N n -- _◃s_
stepify : (Term m → Term n) → Step m → Step n -- fmapS
collapse : (List ∘ Step) n → Term n → Term n -- _⊹_
Substitist =
Substitunction = Fin m → Term n
Oscar.Data.Proposequality
Oscar.Data.Proposextensequality
Oscar.Data.Term
Oscar.Data.Terms
Oscar.Data.PropositionalEquality
setoidPropositionalEquality : Set → Setoid
Oscar.Data.IndexedPropositionalEquality
setoidIndexedPropEq : ∀ {A : Set} {B : A → Set} → ((x : A) → B x) → ((x : A) → B x) → Setoid
Oscar.Data.Substitist
Oscar.Setoid.PropositionalEquality
Oscar.Morphism.Substitist
Oscar.Unification
Oscar.Data.Substitunction
Substitunction m n = Fin m → Term n
: Morphism ℕ
:
Oscar.Definition.Substitist
: Morphism ℕ
= alistSetoid
: IsSemigroupoid
: Semigroupoid _++_
: IsCategory
: Category
Oscar.Definition.Substitist.internal
AList
alistSetoid : ℕ → ℕ → Setoid
ε = anil
_++_
-}
| 21.72
| 94
| 0.6814
|
10769a9406a3e37ba406b3a0d6cc0ad658115bb3
| 25,705
|
agda
|
Agda
|
Cubical/ZCohomology/Properties.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Properties.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/Properties.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Properties where
{-
This module contains:
1. direct proofs of connectedness of Kn and ΩKn
2. Induction principles for cohomology groups of pointed types
3. Equivalence between cohomology of A and reduced cohomology of (A + 1)
4. Equivalence between cohomology and reduced cohomology for dimension ≥ 1
5. Encode-decode proof of Kₙ ≃ ΩKₙ₊₁ and proofs that this equivalence
and its inverse are morphisms
6. A proof of coHomGr ≅ coHomGrΩ
7. A locked (non-reducing) version of Kₙ ≃ ΩKₙ₊₁
-}
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.HITs.S1 hiding (encode ; decode)
open import Cubical.HITs.Sn
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws renaming (assoc to assoc∙)
open import Cubical.Foundations.Univalence
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim ; elim2 to sElim2 ; isSetSetTrunc to §)
open import Cubical.Data.Int renaming (_+_ to _ℤ+_) hiding (-_)
open import Cubical.Data.Nat
open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; map2 to trMap2; rec to trRec ; elim3 to trElim3)
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Connected
open import Cubical.Algebra.Group hiding (Unit ; ℤ)
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Data.Sum.Base hiding (map)
open import Cubical.Functions.Morphism
open import Cubical.Data.Sigma
open Iso renaming (inv to inv')
private
variable
ℓ ℓ' : Level
------------------- Connectedness ---------------------
is2ConnectedKn : (n : ℕ) → isConnected 2 (coHomK (suc n))
is2ConnectedKn zero = ∣ ∣ base ∣ ∣
, trElim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _)
(trElim (λ _ → isOfHLevelPath 3 (isOfHLevelSuc 2 (isOfHLevelTrunc 2)) _ _)
(toPropElim (λ _ → isOfHLevelTrunc 2 _ _) refl))
is2ConnectedKn (suc n) = ∣ ∣ north ∣ ∣
, trElim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _)
(trElim (λ _ → isProp→isOfHLevelSuc (3 + n) (isOfHLevelTrunc 2 _ _))
(suspToPropElim (ptSn (suc n)) (λ _ → isOfHLevelTrunc 2 _ _) refl))
isConnectedKn : (n : ℕ) → isConnected (2 + n) (coHomK (suc n))
isConnectedKn n = isOfHLevelRetractFromIso 0 (invIso (truncOfTruncIso (2 + n) 1)) (sphereConnected (suc n))
-- direct proof of connectedness of ΩKₙ₊₁ not relying on the equivalence ∥ a ≡ b ∥ₙ ≃ (∣ a ∣ₙ₊₁ ≡ ∣ b ∣ₙ₊₁)
isConnectedPathKn : (n : ℕ) (x y : (coHomK (suc n))) → isConnected (suc n) (x ≡ y)
isConnectedPathKn n =
trElim (λ _ → isProp→isOfHLevelSuc (2 + n) (isPropΠ λ _ → isPropIsContr))
(sphereElim _ (λ _ → isProp→isOfHLevelSuc n (isPropΠ λ _ → isPropIsContr))
λ y → isContrRetractOfConstFun
{B = (hLevelTrunc (suc n) (ptSn (suc n) ≡ ptSn (suc n)))} ∣ refl ∣
(fun⁻ n y
, trElim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(J (λ y p → fun⁻ n y _ ≡ _) (funExt⁻ (fun⁻Id n) ∣ refl ∣))))
where
fun⁻ : (n : ℕ) → (y : coHomK (suc n)) →
hLevelTrunc (suc n) (ptSn (suc n) ≡ ptSn (suc n))
→ hLevelTrunc (suc n) (∣ ptSn (suc n) ∣ ≡ y)
fun⁻ n =
trElim (λ _ → isOfHLevelΠ (3 + n) λ _ → isOfHLevelSuc (2 + n) (isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n))))
(sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n)) λ _ → ∣ refl ∣)
fun⁻Id : (n : ℕ) → fun⁻ n ∣ ptSn (suc n) ∣ ≡ λ _ → ∣ refl ∣
fun⁻Id zero = refl
fun⁻Id (suc n) = refl
-------------------
-- Induction principles for cohomology groups (n ≥ 1)
-- If we want to show a proposition about some x : Hⁿ(A), it suffices to show it under the
-- assumption that x = ∣ f ∣₂ for some f : A → Kₙ and that f is pointed
coHomPointedElim : {A : Type ℓ} (n : ℕ) (a : A) {B : coHom (suc n) A → Type ℓ'}
→ ((x : coHom (suc n) A) → isProp (B x))
→ ((f : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → B ∣ f ∣₂)
→ (x : coHom (suc n) A) → B x
coHomPointedElim {ℓ' = ℓ'} {A = A} n a isprop indp =
sElim (λ _ → isOfHLevelSuc 1 (isprop _))
λ f → helper n isprop indp f (f a) refl
where
helper : (n : ℕ) {B : coHom (suc n) A → Type ℓ'}
→ ((x : coHom (suc n) A) → isProp (B x))
→ ((f : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → B ∣ f ∣₂)
→ (f : A → coHomK (suc n))
→ (x : coHomK (suc n))
→ f a ≡ x → B ∣ f ∣₂
-- pattern matching a bit extra to avoid isOfHLevelPlus'
helper zero isprop ind f =
trElim (λ _ → isOfHLevelPlus {n = 1} 2 (isPropΠ λ _ → isprop _))
(toPropElim (λ _ → isPropΠ λ _ → isprop _) (ind f))
helper (suc zero) isprop ind f =
trElim (λ _ → isOfHLevelPlus {n = 1} 3 (isPropΠ λ _ → isprop _))
(suspToPropElim base (λ _ → isPropΠ λ _ → isprop _) (ind f))
helper (suc (suc zero)) isprop ind f =
trElim (λ _ → isOfHLevelPlus {n = 1} 4 (isPropΠ λ _ → isprop _))
(suspToPropElim north (λ _ → isPropΠ λ _ → isprop _) (ind f))
helper (suc (suc (suc n))) isprop ind f =
trElim (λ _ → isOfHLevelPlus' {n = 5 + n} 1 (isPropΠ λ _ → isprop _))
(suspToPropElim north (λ _ → isPropΠ λ _ → isprop _) (ind f))
coHomPointedElim2 : {A : Type ℓ} (n : ℕ) (a : A) {B : coHom (suc n) A → coHom (suc n) A → Type ℓ'}
→ ((x y : coHom (suc n) A) → isProp (B x y))
→ ((f g : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → g a ≡ coHom-pt (suc n) → B ∣ f ∣₂ ∣ g ∣₂)
→ (x y : coHom (suc n) A) → B x y
coHomPointedElim2 {ℓ' = ℓ'} {A = A} n a isprop indp = sElim2 (λ _ _ → isOfHLevelSuc 1 (isprop _ _))
λ f g → helper n a isprop indp f g (f a) (g a) refl refl
where
helper : (n : ℕ) (a : A) {B : coHom (suc n) A → coHom (suc n) A → Type ℓ'}
→ ((x y : coHom (suc n) A) → isProp (B x y))
→ ((f g : A → coHomK (suc n)) → f a ≡ coHom-pt (suc n) → g a ≡ coHom-pt (suc n) → B ∣ f ∣₂ ∣ g ∣₂)
→ (f g : A → coHomK (suc n))
→ (x y : coHomK (suc n))
→ f a ≡ x → g a ≡ y
→ B ∣ f ∣₂ ∣ g ∣₂
helper zero a isprop indp f g =
elim2 (λ _ _ → isOfHLevelPlus {n = 1} 2 (isPropΠ2 λ _ _ → isprop _ _))
(toPropElim2 (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g))
helper (suc zero) a isprop indp f g =
elim2 (λ _ _ → isOfHLevelPlus {n = 1} 3 (isPropΠ2 λ _ _ → isprop _ _))
(suspToPropElim2 base (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g))
helper (suc (suc zero)) a isprop indp f g =
elim2 (λ _ _ → isOfHLevelPlus {n = 1} 4 (isPropΠ2 λ _ _ → isprop _ _))
(suspToPropElim2 north (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g))
helper (suc (suc (suc n))) a isprop indp f g =
elim2 (λ _ _ → isOfHLevelPlus' {n = 5 + n} 1 (isPropΠ2 λ _ _ → isprop _ _))
(suspToPropElim2 north (λ _ _ → isPropΠ2 λ _ _ → isprop _ _) (indp f g))
coHomK-elim : ∀ {ℓ} (n : ℕ) {B : coHomK (suc n) → Type ℓ}
→ ((x : _) → isOfHLevel (suc n) (B x))
→ B (0ₖ (suc n))
→ (x : _) → B x
coHomK-elim n {B = B } hlev b =
trElim (λ _ → isOfHLevelPlus {n = (suc n)} 2 (hlev _))
(sphereElim _ (hlev ∘ ∣_∣) b)
{- Equivalence between cohomology of A and reduced cohomology of (A + 1) -}
coHomRed+1Equiv : (n : ℕ) →
(A : Type ℓ) →
(coHom n A) ≡ (coHomRed n ((A ⊎ Unit , inr (tt))))
coHomRed+1Equiv zero A i = ∥ helpLemma {C = (ℤ , pos 0)} i ∥₂
module coHomRed+1 where
helpLemma : {C : Pointed ℓ} → ( (A → (typ C)) ≡ ((((A ⊎ Unit) , inr (tt)) →∙ C)))
helpLemma {C = C} = isoToPath (iso map1
map2
(λ b → linvPf b)
(λ _ → refl))
where
map1 : (A → typ C) → ((((A ⊎ Unit) , inr (tt)) →∙ C))
map1 f = map1' , refl
module helpmap where
map1' : A ⊎ Unit → fst C
map1' (inl x) = f x
map1' (inr x) = pt C
map2 : ((((A ⊎ Unit) , inr (tt)) →∙ C)) → (A → typ C)
map2 (g , pf) x = g (inl x)
linvPf : (b :((((A ⊎ Unit) , inr (tt)) →∙ C))) → map1 (map2 b) ≡ b
linvPf (f , snd) i = (λ x → helper x i) , λ j → snd ((~ i) ∨ j)
where
helper : (x : A ⊎ Unit) → ((helpmap.map1') (map2 (f , snd)) x) ≡ f x
helper (inl x) = refl
helper (inr tt) = sym snd
coHomRed+1Equiv (suc zero) A i = ∥ coHomRed+1.helpLemma A i {C = (coHomK 1 , ∣ base ∣)} i ∥₂
coHomRed+1Equiv (suc (suc n)) A i = ∥ coHomRed+1.helpLemma A i {C = (coHomK (2 + n) , ∣ north ∣)} i ∥₂
Iso-coHom-coHomRed : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → Iso (coHomRed (suc n) A) (coHom (suc n) (typ A))
fun (Iso-coHom-coHomRed {A = A , a} n) = map fst
inv' (Iso-coHom-coHomRed {A = A , a} n) = map λ f → (λ x → f x -ₖ f a) , rCancelₖ _ _
rightInv (Iso-coHom-coHomRed {A = A , a} n) =
sElim (λ _ → isOfHLevelPath 2 § _ _)
λ f → trRec (isProp→isOfHLevelSuc _ (§ _ _))
(λ p → cong ∣_∣₂ (funExt λ x → cong (λ y → f x +ₖ y) (cong -ₖ_ p ∙ -0ₖ) ∙ rUnitₖ _ (f x)))
(Iso.fun (PathIdTruncIso (suc n)) (isContr→isProp (isConnectedKn n) ∣ f a ∣ ∣ 0ₖ _ ∣))
leftInv (Iso-coHom-coHomRed {A = A , a} n) =
sElim (λ _ → isOfHLevelPath 2 § _ _)
λ {(f , p) → cong ∣_∣₂ (ΣPathP (((funExt λ x → (cong (λ y → f x -ₖ y) p
∙∙ cong (λ y → f x +ₖ y) -0ₖ
∙∙ rUnitₖ _ (f x)) ∙ refl))
, helper n (f a) (sym p)))}
where
path : (n : ℕ) (x : coHomK (suc n)) (p : 0ₖ _ ≡ x) → _
path n x p = (cong (λ y → x -ₖ y) (sym p) ∙∙ cong (λ y → x +ₖ y) -0ₖ ∙∙ rUnitₖ _ x) ∙ refl
helper : (n : ℕ) (x : coHomK (suc n)) (p : 0ₖ _ ≡ x)
→ PathP (λ i → path n x p i ≡ 0ₖ _) (rCancelₖ _ x) (sym p)
helper zero x =
J (λ x p → PathP (λ i → path 0 x p i ≡ 0ₖ _)
(rCancelₖ _ x) (sym p))
λ i j → rUnit (rUnit (λ _ → 0ₖ 1) (~ j)) (~ j) i
helper (suc n) x =
J (λ x p → PathP (λ i → path (suc n) x p i ≡ 0ₖ _) (rCancelₖ _ x) (sym p))
λ i j → rCancelₖ (suc (suc n)) (0ₖ (suc (suc n))) (~ i ∧ ~ j)
+∙≡+ : (n : ℕ) {A : Pointed ℓ} (x y : coHomRed (suc n) A)
→ Iso.fun (Iso-coHom-coHomRed n) (x +ₕ∙ y)
≡ Iso.fun (Iso-coHom-coHomRed n) x +ₕ Iso.fun (Iso-coHom-coHomRed n) y
+∙≡+ zero = sElim2 (λ _ _ → isOfHLevelPath 2 § _ _) λ _ _ → refl
+∙≡+ (suc n) = sElim2 (λ _ _ → isOfHLevelPath 2 § _ _) λ _ _ → refl
private
homhelp : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) (x y : coHom (suc n) (typ A))
→ Iso.inv (Iso-coHom-coHomRed {A = A} n) (x +ₕ y)
≡ Iso.inv (Iso-coHom-coHomRed n) x +ₕ∙ Iso.inv (Iso-coHom-coHomRed n) y
homhelp n A = morphLemmas.isMorphInv _+ₕ∙_ _+ₕ_
(Iso.fun (Iso-coHom-coHomRed n)) (+∙≡+ n) _
(Iso.rightInv (Iso-coHom-coHomRed n)) (Iso.leftInv (Iso-coHom-coHomRed n))
coHomGr≅coHomRedGr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ)
→ GroupEquiv (coHomRedGrDir (suc n) A) (coHomGr (suc n) (typ A))
fst (coHomGr≅coHomRedGr n A) = isoToEquiv (Iso-coHom-coHomRed n)
snd (coHomGr≅coHomRedGr n A) = makeIsGroupHom (+∙≡+ n)
coHomRedGroup : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → AbGroup ℓ
coHomRedGroup zero A = coHomRedGroupDir zero A
coHomRedGroup (suc n) A =
InducedAbGroup (coHomGroup (suc n) (typ A))
_+ₕ∙_
(isoToEquiv (invIso (Iso-coHom-coHomRed n)))
(homhelp n A)
abstract
coHomGroup≡coHomRedGroup : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ)
→ coHomGroup (suc n) (typ A) ≡ coHomRedGroup (suc n) A
coHomGroup≡coHomRedGroup n A =
InducedAbGroupPath (coHomGroup (suc n) (typ A))
_+ₕ∙_
(isoToEquiv (invIso (Iso-coHom-coHomRed n)))
(homhelp n A)
------------------- Kₙ ≃ ΩKₙ₊₁ ---------------------
-- This proof uses the encode-decode method rather than Freudenthal
-- We define the map σ : Kₙ → ΩKₙ₊₁ and prove that it is a morphism
private
module _ (n : ℕ) where
σ : {n : ℕ} → coHomK (suc n) → Path (coHomK (2 + n)) ∣ north ∣ ∣ north ∣
σ {n = n} = trRec (isOfHLevelTrunc (4 + n) _ _)
λ a → cong ∣_∣ (merid a ∙ sym (merid (ptSn (suc n))))
σ-hom-helper : ∀ {ℓ} {A : Type ℓ} {a : A} (p : a ≡ a) (r : refl ≡ p)
→ lUnit p ∙ cong (_∙ p) r ≡ rUnit p ∙ cong (p ∙_) r
σ-hom-helper p = J (λ p r → lUnit p ∙ cong (_∙ p) r ≡ rUnit p ∙ cong (p ∙_) r) refl
σ-hom : {n : ℕ} (x y : coHomK (suc n)) → σ (x +ₖ y) ≡ σ x ∙ σ y
σ-hom {n = zero} =
elim2 (λ _ _ → isOfHLevelPath 3 (isOfHLevelTrunc 4 _ _) _ _)
(wedgeconFun _ _
(λ _ _ → isOfHLevelTrunc 4 _ _ _ _)
(λ x → lUnit _
∙ cong (_∙ σ ∣ x ∣) (cong (cong ∣_∣) (sym (rCancel (merid base)))))
(λ y → cong σ (rUnitₖ 1 ∣ y ∣)
∙∙ rUnit _
∙∙ cong (σ ∣ y ∣ ∙_) (cong (cong ∣_∣) (sym (rCancel (merid base)))))
(sym (σ-hom-helper (σ ∣ base ∣) (cong (cong ∣_∣) (sym (rCancel (merid base)))))))
σ-hom {n = suc n} =
elim2 (λ _ _ → isOfHLevelPath (4 + n) (isOfHLevelTrunc (5 + n) _ _) _ _)
(wedgeconFun _ _ (λ _ _ → isOfHLevelPath ((2 + n) + (2 + n)) (wedgeConHLev' n) _ _)
(λ x → lUnit _
∙ cong (_∙ σ ∣ x ∣) (cong (cong ∣_∣) (sym (rCancel (merid north)))))
(λ y → cong σ (rUnitₖ (2 + n) ∣ y ∣)
∙∙ rUnit _
∙∙ cong (σ ∣ y ∣ ∙_) (cong (cong ∣_∣) (sym (rCancel (merid north)))))
(sym (σ-hom-helper (σ ∣ north ∣) (cong (cong ∣_∣) (sym (rCancel (merid north)))))))
-- We will need to following lemma
σ-minusDistr : {n : ℕ} (x y : coHomK (suc n)) → σ (x -ₖ y) ≡ σ x ∙ sym (σ y)
σ-minusDistr {n = n} =
morphLemmas.distrMinus'
_+ₖ_ _∙_
σ σ-hom ∣ (ptSn (suc n)) ∣ refl
-ₖ_ sym
(λ x → sym (lUnit x)) (λ x → sym (rUnit x))
(rUnitₖ (suc n))
(lCancelₖ (suc n)) rCancel
(assocₖ (suc n)) assoc∙
(cong (cong ∣_∣) (rCancel (merid (ptSn (suc n)))))
-- we define the code using addIso
Code : (n : ℕ) → coHomK (2 + n) → Type₀
Code n x = (trRec {B = TypeOfHLevel ℓ-zero (3 + n)} (isOfHLevelTypeOfHLevel (3 + n))
λ a → Code' a , hLevCode' a) x .fst
where
Code' : (S₊ (2 + n)) → Type₀
Code' north = coHomK (suc n)
Code' south = coHomK (suc n)
Code' (merid a i) = isoToPath (addIso (suc n) ∣ a ∣) i
hLevCode' : (x : S₊ (2 + n)) → isOfHLevel (3 + n) (Code' x)
hLevCode' = suspToPropElim (ptSn (suc n)) (λ _ → isPropIsOfHLevel (3 + n)) (isOfHLevelTrunc (3 + n))
symMeridLem : (n : ℕ) → (x : S₊ (suc n)) (y : coHomK (suc n))
→ subst (Code n) (cong ∣_∣ (sym (merid x))) y ≡ y -ₖ ∣ x ∣
symMeridLem n x = trElim (λ _ → isOfHLevelPath (3 + n) (isOfHLevelTrunc (3 + n)) _ _)
(λ y → cong (_-ₖ ∣ x ∣) (transportRefl ∣ y ∣))
decode : {n : ℕ} (x : coHomK (2 + n)) → Code n x → ∣ north ∣ ≡ x
decode {n = n} = trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelPath (4 + n) (isOfHLevelTrunc (4 + n)) _ _)
decode-elim
where
north≡merid : (a : S₊ (suc n))
→ Path (coHomK (2 + n)) ∣ north ∣ ∣ north ∣
≡ (Path (coHomK (2 + n)) ∣ north ∣ ∣ south ∣)
north≡merid a i = Path (coHomK (2 + n)) ∣ north ∣ ∣ merid a i ∣
decode-elim : (a : S₊ (2 + n)) → Code n ∣ a ∣ → Path (coHomK (2 + n)) ∣ north ∣ ∣ a ∣
decode-elim north = σ
decode-elim south = trRec (isOfHLevelTrunc (4 + n) _ _)
λ a → cong ∣_∣ (merid a)
decode-elim (merid a i) =
hcomp (λ k → λ { (i = i0) → σ
; (i = i1) → mainPath a k})
(funTypeTransp (Code n) (λ x → ∣ north ∣ ≡ x) (cong ∣_∣ (merid a)) σ i)
where
mainPath : (a : (S₊ (suc n))) →
transport (north≡merid a) ∘ σ ∘ transport (λ i → Code n ∣ merid a (~ i) ∣)
≡ trRec (isOfHLevelTrunc (4 + n) _ _) λ a → cong ∣_∣ (merid a)
mainPath a = funExt (trElim (λ _ → isOfHLevelPath (3 + n) (isOfHLevelTrunc (4 + n) _ _) _ _)
(λ x → (λ i → transport (north≡merid a) (σ (symMeridLem n a ∣ x ∣ i)))
∙∙ cong (transport (north≡merid a)) (-distrHelp x)
∙∙ (substAbove x)))
where
-distrHelp : (x : S₊ (suc n)) → σ (∣ x ∣ -ₖ ∣ a ∣) ≡ cong ∣_∣ (merid x) ∙ cong ∣_∣ (sym (merid a))
-distrHelp x =
σ-minusDistr ∣ x ∣ ∣ a ∣
∙ (λ i → (cong ∣_∣ (compPath-filler (merid x) (λ j → merid (ptSn (suc n)) (~ j ∨ i)) (~ i)))
∙ (cong ∣_∣ (sym (compPath-filler (merid a) (λ j → merid (ptSn (suc n)) (~ j ∨ i)) (~ i)))))
substAbove : (x : S₊ (suc n)) → transport (north≡merid a) (cong ∣_∣ (merid x) ∙ cong ∣_∣ (sym (merid a)))
≡ cong ∣_∣ (merid x)
substAbove x i = transp (λ j → north≡merid a (i ∨ j)) i
(compPath-filler (cong ∣_∣ (merid x)) (λ j → ∣ merid a (~ j ∨ i) ∣) (~ i))
encode : {n : ℕ} {x : coHomK (2 + n)} → Path (coHomK (2 + n)) ∣ north ∣ x → Code n x
encode {n = n} p = transport (cong (Code n) p) ∣ (ptSn (suc n)) ∣
decode-encode : {n : ℕ} {x : coHomK (2 + n)} (p : Path (coHomK (2 + n)) ∣ north ∣ x)
→ decode _ (encode p) ≡ p
decode-encode {n = n} =
J (λ y p → decode _ (encode p) ≡ p)
(cong (decode ∣ north ∣) (transportRefl ∣ ptSn (suc n) ∣)
∙ cong (cong ∣_∣) (rCancel (merid (ptSn (suc n)))))
-- We define an addition operation on Code which we can use in order to show that encode is a
-- morphism (in a very loose sense)
hLevCode : {n : ℕ} (x : coHomK (2 + n)) → isOfHLevel (3 + n) (Code n x)
hLevCode {n = n} =
trElim (λ _ → isProp→isOfHLevelSuc (3 + n) (isPropIsOfHLevel (3 + n)))
(sphereToPropElim _
(λ _ → (isPropIsOfHLevel (3 + n))) (isOfHLevelTrunc (3 + n)))
Code-add' : {n : ℕ} (x : _) → Code n ∣ north ∣ → Code n ∣ x ∣ → Code n ∣ x ∣
Code-add' {n = n} north = _+ₖ_
Code-add' {n = n} south = _+ₖ_
Code-add' {n = n} (merid a i) = helper n a i
where
help : (n : ℕ) → (x y a : S₊ (suc n))
→ transport (λ i → Code n ∣ north ∣ → Code n ∣ merid a i ∣ → Code n ∣ merid a i ∣)
(_+ₖ_) ∣ x ∣ ∣ y ∣
≡ ∣ x ∣ +ₖ ∣ y ∣
help n x y a =
(λ i → transportRefl ((∣ transportRefl x i ∣ +ₖ (∣ transportRefl y i ∣ -ₖ ∣ a ∣)) +ₖ ∣ a ∣) i)
∙∙ cong (_+ₖ ∣ a ∣) (assocₖ _ ∣ x ∣ ∣ y ∣ (-ₖ ∣ a ∣))
∙∙ sym (assocₖ _ (∣ x ∣ +ₖ ∣ y ∣) (-ₖ ∣ a ∣) ∣ a ∣)
∙∙ cong ((∣ x ∣ +ₖ ∣ y ∣) +ₖ_) (lCancelₖ _ ∣ a ∣)
∙∙ rUnitₖ _ _
helper : (n : ℕ) (a : S₊ (suc n))
→ PathP (λ i → Code n ∣ north ∣ → Code n ∣ merid a i ∣ → Code n ∣ merid a i ∣) _+ₖ_ _+ₖ_
helper n a =
toPathP (funExt
(trElim (λ _ → isOfHLevelPath (3 + n) (isOfHLevelΠ (3 + n) (λ _ → isOfHLevelTrunc (3 + n))) _ _)
λ x → funExt
(trElim (λ _ → isOfHLevelPath (3 + n) (isOfHLevelTrunc (3 + n)) _ _)
λ y → help n x y a)))
Code-add : {n : ℕ} (x : _) → Code n ∣ north ∣ → Code n x → Code n x
Code-add {n = n} =
trElim (λ x → isOfHLevelΠ (4 + n) λ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelSuc (3 + n) (hLevCode {n = n} x))
Code-add'
encode-hom : {n : ℕ} {x : _} (q : 0ₖ _ ≡ 0ₖ _) (p : 0ₖ _ ≡ x)
→ encode (q ∙ p) ≡ Code-add {n = n} x (encode q) (encode p)
encode-hom {n = n} q = J (λ x p → encode (q ∙ p) ≡ Code-add {n = n} x (encode q) (encode p))
(cong encode (sym (rUnit q))
∙∙ sym (rUnitₖ _ (encode q))
∙∙ cong (encode q +ₖ_) (cong ∣_∣ (sym (transportRefl _))))
stabSpheres : (n : ℕ) → Iso (coHomK (suc n)) (typ (Ω (coHomK-ptd (2 + n))))
fun (stabSpheres n) = decode _
inv' (stabSpheres n) = encode
rightInv (stabSpheres n) p = decode-encode p
leftInv (stabSpheres n) =
trElim (λ _ → isOfHLevelPath (3 + n) (isOfHLevelTrunc (3 + n)) _ _)
λ a → cong encode (congFunct ∣_∣ (merid a) (sym (merid (ptSn (suc n)))))
∙∙ (λ i → transport (congFunct (Code n) (cong ∣_∣ (merid a))
(cong ∣_∣ (sym (merid (ptSn (suc n))))) i) ∣ ptSn (suc n) ∣)
∙∙ (substComposite (λ x → x)
(cong (Code n) (cong ∣_∣ (merid a)))
(cong (Code n) (cong ∣_∣ (sym (merid (ptSn (suc n)))))) ∣ ptSn (suc n) ∣
∙∙ cong (transport (λ i → Code n ∣ merid (ptSn (suc n)) (~ i) ∣))
(transportRefl (∣ (ptSn (suc n)) ∣ +ₖ ∣ a ∣) ∙ lUnitₖ (suc n) ∣ a ∣)
∙∙ symMeridLem n (ptSn (suc n)) ∣ a ∣
∙∙ cong (∣ a ∣ +ₖ_) -0ₖ
∙∙ rUnitₖ (suc n) ∣ a ∣)
Iso-Kn-ΩKn+1 : (n : HLevel) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n))))
Iso-Kn-ΩKn+1 zero = invIso (compIso (congIso (truncIdempotentIso _ isGroupoidS¹)) ΩS¹Isoℤ)
Iso-Kn-ΩKn+1 (suc n) = stabSpheres n
Kn≃ΩKn+1 : {n : ℕ} → coHomK n ≃ typ (Ω (coHomK-ptd (suc n)))
Kn≃ΩKn+1 {n = n} = isoToEquiv (Iso-Kn-ΩKn+1 n)
-- Some properties of the Iso
Kn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n)))
Kn→ΩKn+1 n = Iso.fun (Iso-Kn-ΩKn+1 n)
ΩKn+1→Kn : (n : ℕ) → typ (Ω (coHomK-ptd (suc n))) → coHomK n
ΩKn+1→Kn n = Iso.inv (Iso-Kn-ΩKn+1 n)
Kn→ΩKn+10ₖ : (n : ℕ) → Kn→ΩKn+1 n (0ₖ n) ≡ refl
Kn→ΩKn+10ₖ zero = sym (rUnit refl)
Kn→ΩKn+10ₖ (suc n) i j = ∣ (rCancel (merid (ptSn (suc n))) i j) ∣
ΩKn+1→Kn-refl : (n : ℕ) → ΩKn+1→Kn n refl ≡ 0ₖ n
ΩKn+1→Kn-refl zero = refl
ΩKn+1→Kn-refl (suc zero) = refl
ΩKn+1→Kn-refl (suc (suc n)) = refl
Kn→ΩKn+1-hom : (n : ℕ) (x y : coHomK n) → Kn→ΩKn+1 n (x +[ n ]ₖ y) ≡ Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y
Kn→ΩKn+1-hom zero x y = (λ j i → hfill (doubleComp-faces (λ i₁ → ∣ base ∣) (λ _ → ∣ base ∣) i)
(inS (∣ intLoop (x ℤ+ y) i ∣)) (~ j))
∙∙ (λ j i → ∣ intLoop-hom x y (~ j) i ∣)
∙∙ (congFunct ∣_∣ (intLoop x) (intLoop y)
∙ cong₂ _∙_ (λ j i → hfill (doubleComp-faces (λ i₁ → ∣ base ∣) (λ _ → ∣ base ∣) i)
(inS (∣ intLoop x i ∣)) j)
λ j i → hfill (doubleComp-faces (λ i₁ → ∣ base ∣) (λ _ → ∣ base ∣) i)
(inS (∣ intLoop y i ∣)) j)
Kn→ΩKn+1-hom (suc n) = σ-hom
ΩKn+1→Kn-hom : (n : ℕ) (x y : Path (coHomK (suc n)) (0ₖ _) (0ₖ _))
→ ΩKn+1→Kn n (x ∙ y) ≡ ΩKn+1→Kn n x +[ n ]ₖ ΩKn+1→Kn n y
ΩKn+1→Kn-hom zero p q =
cong winding (congFunct (trRec isGroupoidS¹ (λ x → x)) p q)
∙ winding-hom (cong (trRec isGroupoidS¹ (λ x → x)) p) (cong (trRec isGroupoidS¹ (λ x → x)) q)
ΩKn+1→Kn-hom (suc n) = encode-hom
isHomogeneousKn : (n : HLevel) → isHomogeneous (coHomK-ptd n)
isHomogeneousKn n =
subst isHomogeneous
(sym (ΣPathP (ua Kn≃ΩKn+1 , ua-gluePath _ (Kn→ΩKn+10ₖ n))))
(isHomogeneousPath _ _)
-- With the equivalence Kn≃ΩKn+1, we get that the two definitions of cohomology groups agree
open IsGroupHom
coHom≅coHomΩ : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → GroupIso (coHomGr n A) (coHomGrΩ n A)
fun (fst (coHom≅coHomΩ n A)) = map λ f a → Kn→ΩKn+1 n (f a)
inv' (fst (coHom≅coHomΩ n A)) = map λ f a → ΩKn+1→Kn n (f a)
rightInv (fst (coHom≅coHomΩ n A)) =
sElim (λ _ → isOfHLevelPath 2 § _ _)
λ f → cong ∣_∣₂ (funExt λ x → rightInv (Iso-Kn-ΩKn+1 n) (f x))
leftInv (fst (coHom≅coHomΩ n A)) =
sElim (λ _ → isOfHLevelPath 2 § _ _)
λ f → cong ∣_∣₂ (funExt λ x → leftInv (Iso-Kn-ΩKn+1 n) (f x))
snd (coHom≅coHomΩ n A) =
makeIsGroupHom
(sElim2 (λ _ _ → isOfHLevelPath 2 § _ _)
λ f g → cong ∣_∣₂ (funExt λ x → Kn→ΩKn+1-hom n (f x) (g x)))
module lockedKnIso (key : Unit') where
Kn→ΩKn+1' : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n)))
Kn→ΩKn+1' n = lock key (Iso.fun (Iso-Kn-ΩKn+1 n))
ΩKn+1→Kn' : (n : ℕ) → typ (Ω (coHomK-ptd (suc n))) → coHomK n
ΩKn+1→Kn' n = lock key (Iso.inv (Iso-Kn-ΩKn+1 n))
ΩKn+1→Kn→ΩKn+1 : (n : ℕ) → (x : typ (Ω (coHomK-ptd (suc n)))) → Kn→ΩKn+1' n (ΩKn+1→Kn' n x) ≡ x
ΩKn+1→Kn→ΩKn+1 n x = pm key
where
pm : (key : Unit') → lock key (Iso.fun (Iso-Kn-ΩKn+1 n)) (lock key (Iso.inv (Iso-Kn-ΩKn+1 n)) x) ≡ x
pm unlock = Iso.rightInv (Iso-Kn-ΩKn+1 n) x
Kn→ΩKn+1→Kn : (n : ℕ) → (x : coHomK n) → ΩKn+1→Kn' n (Kn→ΩKn+1' n x) ≡ x
Kn→ΩKn+1→Kn n x = pm key
where
pm : (key : Unit') → lock key (Iso.inv (Iso-Kn-ΩKn+1 n)) (lock key (Iso.fun (Iso-Kn-ΩKn+1 n)) x) ≡ x
pm unlock = Iso.leftInv (Iso-Kn-ΩKn+1 n) x
-distrLemma : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : ℕ) (f : GroupHom (coHomGr n A) (coHomGr m B))
(x y : coHom n A)
→ fst f (x -[ n ]ₕ y) ≡ fst f x -[ m ]ₕ fst f y
-distrLemma n m f' x y = sym (-cancelRₕ m (f y) (f (x -[ n ]ₕ y)))
∙∙ cong (λ x → x -[ m ]ₕ f y) (sym (f' .snd .pres· (x -[ n ]ₕ y) y))
∙∙ cong (λ x → x -[ m ]ₕ f y) ( cong f (-+cancelₕ n _ _))
where
f = fst f'
| 49.243295
| 132
| 0.514725
|
502e4f0f48d5e5cf1c204b6d3977fa1c334a830b
| 135
|
agda
|
Agda
|
test/interaction/Imports/ImportedDisplayForms.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Imports/ImportedDisplayForms.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Imports/ImportedDisplayForms.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Imports.ImportedDisplayForms where
open import Agda.Builtin.Nat
postulate
_plus_ : Set
{-# DISPLAY _+_ a b = a plus b #-}
| 13.5
| 41
| 0.718519
|
cb312041da770ba57b394cb6de036f232cbc4b7b
| 3,788
|
agda
|
Agda
|
Operational-semantics-using-the-partiality-monad.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | 1
|
2021-02-13T14:48:45.000Z
|
2021-02-13T14:48:45.000Z
|
Operational-semantics-using-the-partiality-monad.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
Operational-semantics-using-the-partiality-monad.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Code related to the paper
-- "Operational Semantics Using the Partiality Monad"
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
-- Several definitions and proofs in this code are closely related to
-- definitions and proofs in the paper "Coinductive big-step
-- operational semantics" by Leroy and Grall. See my paper for more
-- detailed references to related work, and also for more explanations
-- of how the code works.
module Operational-semantics-using-the-partiality-monad where
------------------------------------------------------------------------
-- Section 2
-- Fin.
import Data.Fin
-- Vec, lookup.
import Data.Vec
-- The partiality monad.
import Category.Monad.Partiality
-- A variant of trivial, as well as proofs showing that the definition
-- of weak bisimilarity in the paper coincides with Capretta's
-- definition and a more standard definition based on weak
-- bisimulations.
import AdmissibleButNotPostulable
------------------------------------------------------------------------
-- Section 3
-- Tm, Env, Value.
import Lambda.Syntax
-- Big-step functional semantics, Ω.
import Lambda.Closure.Functional
-- The module above uses some workarounds in order to convince Agda
-- that the code is productive. The following module contains (more or
-- less) the same code without the workarounds, but is checked with
-- the termination checker turned off.
import Lambda.Closure.Functional.No-workarounds
-- An alternative definition of the functional semantics. This
-- definition uses continuation-passing style instead of bind.
import Lambda.Closure.Functional.Alternative
------------------------------------------------------------------------
-- Section 4
-- Type system.
import Lambda.Syntax
-- Type soundness.
import Lambda.Closure.Functional.Type-soundness
-- The use of Lift in the paper is replaced by the use of two
-- different predicate transformers: Any for Maybe and All for the
-- partiality monad.
import Data.Maybe
import Category.Monad.Partiality.All
-- An alternative definition of the functional semantics, using
-- substitutions instead of environments and closures, plus a proof of
-- type soundness.
import Lambda.Substitution.Functional
------------------------------------------------------------------------
-- Section 5
-- The relational semantics.
import Lambda.Closure.Relational
-- Proofs of equivalence.
import Lambda.Closure.Equivalence
------------------------------------------------------------------------
-- Section 6
-- The virtual machine. Two semantics are given, one relational and
-- one functional, and they are proved to be equivalent.
import Lambda.VirtualMachine
------------------------------------------------------------------------
-- Section 7
-- The compiler.
import Lambda.VirtualMachine
-- Compiler correctness for the functional semantics.
import Lambda.Closure.Functional
import Lambda.Closure.Functional.No-workarounds
-- Compiler correctness for the relational semantics.
import Lambda.Closure.Relational
------------------------------------------------------------------------
-- Section 8
-- The non-deterministic language along with a compiler and a compiler
-- correctness proof, as well as a type soundness proof.
import Lambda.Closure.Functional.Non-deterministic
import Lambda.Closure.Functional.Non-deterministic.No-workarounds
------------------------------------------------------------------------
-- Section 9
-- A very brief treatment of different kinds of term equivalences,
-- including contextual equivalence and applicative bisimilarity.
import Lambda.Closure.Equivalences
-- _⇓.
import Category.Monad.Partiality
| 27.057143
| 72
| 0.631468
|
fb92dc3d7356f043997b28ce0697485d9d6dd972
| 20,614
|
agda
|
Agda
|
LibraBFT/Prelude.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Prelude.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Prelude.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
-- This is a selection of useful functions and definitions
-- from the standard library that we tend to use a lot.
module LibraBFT.Prelude where
open import Level
renaming (suc to ℓ+1; zero to ℓ0; _⊔_ to _ℓ⊔_)
public
1ℓ : Level
1ℓ = ℓ+1 0ℓ
open import Agda.Builtin.Unit
public
open import Function
using (_∘_; _∘′_; id; case_of_; _on_; typeOf; flip; const; _∋_; _$_)
public
identity = id
infixl 1 _&_
_&_ = Function._|>_
open import Data.Unit.NonEta
public
open import Data.Empty
public
-- NOTE: This function is defined to give extra documentation when discharging
-- absurd cases where Agda can tell by pattern matching that `A` is not
-- inhabited. For example:
-- > absurd (just v ≡ nothing) case impossibleProof of λ ()
infix 0 absurd_case_of_
absurd_case_of_ : ∀ {ℓ₁ ℓ₂} (A : Set ℓ₁) {B : Set ℓ₂} → A → (A → ⊥) → B
absurd A case x of f = ⊥-elim (f x)
open import Data.Nat
renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_; _≥?_ to _≥?ℕ_; compare to compareℕ; Ordering to Orderingℕ)
public
max = _⊔_
min = _⊓_
open import Data.Nat.DivMod using (_/_)
div = _/_
open import Data.Nat.Properties
hiding (≡-irrelevant ; _≟_)
public
open import Data.List
renaming (map to List-map ; filter to List-filter ; lookup to List-lookup;
tabulate to List-tabulate; foldl to List-foldl)
hiding (fromMaybe; [_])
public
foldl' = List-foldl
open import Data.List.Properties
renaming (≡-dec to List-≡-dec; length-map to List-length-map; map-compose to List-map-compose; filter-++ to List-filter-++; length-filter to List-length-filter)
using (∷-injective; length-++; map-++-commute; sum-++-commute; map-tabulate; tabulate-lookup; ++-identityʳ; ++-identityˡ)
public
open import Data.List.Relation.Binary.Subset.Propositional
renaming (_⊆_ to _⊆List_)
public
open import Data.List.Relation.Unary.Any
using (Any; here; there)
renaming (lookup to Any-lookup; map to Any-map; satisfied to Any-satisfied
;index to Any-index; any to Any-any)
public
open import Data.List.Relation.Unary.Any.Properties
using (¬Any[])
renaming ( map⁺ to Any-map⁺
; map⁻ to Any-map⁻
; concat⁺ to Any-concat⁺
; concat⁻ to Any-concat⁻
; ++⁻ to Any-++⁻
; ++⁺ʳ to Any-++ʳ
; ++⁺ˡ to Any-++ˡ
; singleton⁻ to Any-singleton⁻
; tabulate⁺ to Any-tabulate⁺
; filter⁻ to Any-filter⁻
)
public
open import Data.List.Relation.Unary.All
using (All; []; _∷_)
renaming (head to All-head; tail to All-tail;
lookup to All-lookup; tabulate to All-tabulate;
reduce to All-reduce; map to All-map)
public
open import Data.List.Relation.Unary.All.Properties
hiding (All-map)
renaming ( tabulate⁻ to All-tabulate⁻
; tabulate⁺ to All-tabulate⁺
; map⁺ to All-map⁺
; map⁻ to All-map⁻
; ++⁺ to All-++
)
public
open import Data.List.Membership.Propositional
using (_∈_; _∉_)
public
open import Data.List.Membership.Propositional.Properties
renaming (∈-filter⁺ to List-∈-filter⁺; ∈-filter⁻ to List-∈-filter⁻)
public
open import Data.Vec
using (Vec; []; _∷_)
renaming (replicate to Vec-replicate; lookup to Vec-lookup
;map to Vec-map; head to Vec-head; tail to Vec-tail
;updateAt to Vec-updateAt; tabulate to Vec-tabulate
;allFin to Vec-allFin; toList to Vec-toList; fromList to Vec-fromList
;_++_ to _Vec-++_)
public
open import Data.Vec.Relation.Unary.All
using ([]; _∷_)
renaming (All to Vec-All; lookup to Vec-All-lookup)
public
open import Data.Vec.Properties
using ()
renaming (updateAt-minimal to Vec-updateAt-minimal
;[]=⇒lookup to Vec-[]=⇒lookup
;lookup⇒[]= to Vec-lookup⇒[]=
;lookup∘tabulate to Vec-lookup∘tabulate
;≡-dec to Vec-≡-dec)
public
open import Data.List.Relation.Binary.Pointwise
using (decidable-≡)
public
open import Data.Bool
renaming (_≟_ to _≟Bool_)
hiding (_≤?_; _<_; _<?_; _≤_; not)
public
open import Data.Maybe
renaming (map to Maybe-map; zip to Maybe-zip ; _>>=_ to _Maybe->>=_)
hiding (align; alignWith; zipWith)
public
-- a non-dependent eliminator
maybeS : ∀ {a b} {A : Set a} {B : Set b} →
(x : Maybe A) → B → ((x : A) → B) → B
maybeS {B = B} x f t = maybe {B = const B} t f x
maybeHsk : ∀ {A B : Set} → B → (A → B) → Maybe A → B
maybeHsk b a→b = λ where
nothing → b
(just a) → a→b a
open import Data.Maybe.Relation.Unary.Any
renaming (Any to Maybe-Any; dec to Maybe-Any-dec)
hiding (map; zip; zipWith; unzip ; unzipWith)
public
maybe-any-⊥ : ∀{a}{A : Set a} → Maybe-Any {A = A} (λ _ → ⊤) nothing → ⊥
maybe-any-⊥ ()
headMay : ∀ {A : Set} → List A → Maybe A
headMay [] = nothing
headMay (x ∷ _) = just x
lastMay : ∀ {A : Set} → List A → Maybe A
lastMay [] = nothing
lastMay (x ∷ []) = just x
lastMay (_ ∷ x ∷ xs) = lastMay (x ∷ xs)
open import Data.Maybe.Properties
using (just-injective)
renaming (≡-dec to Maybe-≡-dec)
public
open import Data.Fin
using (Fin; suc; zero; fromℕ; fromℕ< ; toℕ ; cast)
renaming (_≟_ to _≟Fin_; _≤?_ to _≤?Fin_; _≤_ to _≤Fin_ ; _<_ to _<Fin_;
inject₁ to Fin-inject₁; inject+ to Fin-inject+; inject≤ to Fin-inject≤)
public
fins : (n : ℕ) → List (Fin n)
fins n = Vec-toList (Vec-allFin n)
open import Data.Fin.Properties
using (toℕ-injective; toℕ<n)
renaming (<-cmp to Fin-<-cmp; <⇒≢ to <⇒≢Fin; suc-injective to Fin-suc-injective)
public
open import Relation.Binary.PropositionalEquality
hiding (decSetoid)
public
open import Relation.Binary.HeterogeneousEquality
using (_≅_)
renaming (cong to ≅-cong; cong₂ to ≅-cong₂)
public
open import Relation.Binary
public
data Ordering : Set where
LT EQ GT : Ordering
compare : ℕ → ℕ → Ordering
compare m n
with <-cmp m n
... | tri< a ¬b ¬c = LT
... | tri≈ ¬a b ¬c = EQ
... | tri> ¬a ¬b c = GT
≡-irrelevant : ∀{a}{A : Set a} → Irrelevant {a} {A} _≡_
≡-irrelevant refl refl = refl
to-witness-lemma : ∀{ℓ}{A : Set ℓ}{a : A}{f : Maybe A}(x : Is-just f)
→ to-witness x ≡ a → f ≡ just a
to-witness-lemma (just x) refl = refl
open import Relation.Nullary
hiding (Irrelevant; proof)
public
open import Relation.Nullary.Decidable
hiding (map)
public
open import Data.Sum
renaming ([_,_] to either; map to ⊎-map; map₁ to ⊎-map₁; map₂ to ⊎-map₂)
public
open import Data.Sum.Properties
using (inj₁-injective ; inj₂-injective)
public
⊎-elimˡ : ∀ {ℓ₀ ℓ₁}{A₀ : Set ℓ₀}{A₁ : Set ℓ₁} → ¬ A₀ → A₀ ⊎ A₁ → A₁
⊎-elimˡ ¬a = either (⊥-elim ∘ ¬a) id
⊎-elimʳ : ∀ {ℓ₀ ℓ₁}{A₀ : Set ℓ₀}{A₁ : Set ℓ₁} → ¬ A₁ → A₀ ⊎ A₁ → A₀
⊎-elimʳ ¬a = either id (⊥-elim ∘ ¬a)
open import Data.Product
renaming (map to ×-map; map₂ to ×-map₂; map₁ to ×-map₁; <_,_> to split; swap to ×-swap)
hiding (zip)
public
fst = proj₁
open import Data.Product.Properties
public
module _ {ℓA} {A : Set ℓA} where
NoneOfKind : ∀ {ℓ} {P : A → Set ℓ} → List A → (p : (a : A) → Dec (P a)) → Set ℓA
NoneOfKind xs p = List-filter p xs ≡ []
postulate -- TODO-1: Replace with or prove using library properties? Move to Lemmas?
NoneOfKind⇒ : ∀ {ℓ} {P : A → Set ℓ} {Q : A → Set ℓ} {xs : List A}
→ (p : (a : A) → Dec (P a))
→ {q : (a : A) → Dec (Q a)}
→ (∀ {a} → P a → Q a) -- TODO-1: Use proper notation (Relation.Unary?)
→ NoneOfKind xs q
→ NoneOfKind xs p
infix 4 _<?ℕ_
_<?ℕ_ : Decidable _<_
m <?ℕ n = suc m ≤?ℕ n
infix 0 if-yes_then_else_
infix 0 if-dec_then_else_
if-yes_then_else_ : ∀ {ℓA ℓB} {A : Set ℓA} {B : Set ℓB} → Dec A → (A → B) → (¬ A → B) → B
if-yes (yes prf) then f else _ = f prf
if-yes (no prf) then _ else g = g prf
if-dec_then_else_ : ∀ {ℓA ℓB} {A : Set ℓA} {B : Set ℓB} → Dec A → B → B → B
if-dec x then f else g = if-yes x then const f else const g
open import Relation.Nullary.Negation
using (contradiction; contraposition)
public
open import Relation.Binary
using (Setoid; IsPreorder)
public
open import Relation.Unary
using (_∪_)
public
open import Relation.Unary.Properties
using (_∪?_)
public
-- Injectivity for a function of two potentially different types (A and B) via functions to a
-- common type (C).
Injective' : ∀ {b c d e}{B : Set b}{C : Set c}{D : Set d} → (hB : B → D) → (hC : C → D) → (_≈_ : B → C → Set e) → Set _
Injective' {C = C} hB hC _≈_ = ∀ {b c} → hB b ≡ hC c → b ≈ c
Injective : ∀ {c d e}{C : Set c}{D : Set d} → (h : C → D) → (_≈_ : Rel C e) → Set _
Injective h _≈_ = Injective' h h _≈_
Injective-≡ : ∀ {c d}{C : Set c}{D : Set d} → (h : C → D) → Set _
Injective-≡ h = Injective h _≡_
Injective-int : ∀{a b c d e}{A : Set a}{B : Set b}{C : Set c}{D : Set d}
→ (_≈_ : A → B → Set e)
→ (h : C → D)
→ (f₁ : A → C)
→ (f₂ : B → C)
→ Set (a ℓ⊔ b ℓ⊔ d ℓ⊔ e)
Injective-int _≈_ h f₁ f₂ = ∀ {a₁} {b₁} → h (f₁ a₁) ≡ h (f₂ b₁) → a₁ ≈ b₁
NonInjective : ∀{a b c}{A : Set a}{B : Set b}
→ (_≈_ : Rel A c)
→ (A → B) → Set (a ℓ⊔ b ℓ⊔ c)
NonInjective {A = A} _≈_ f
= Σ (A × A) (λ { (x₁ , x₂) → ¬ (x₁ ≈ x₂) × f x₁ ≡ f x₂ })
NonInjective-≡ : ∀{a b}{A : Set a}{B : Set b}
→ (A → B) → Set (a ℓ⊔ b)
NonInjective-≡ = NonInjective _≡_
NonInjective-≡-preds : ∀{a b}{A : Set a}{B : Set b}{ℓ₁ ℓ₂ : Level}
→ (A → Set ℓ₁)
→ (A → Set ℓ₂)
→ (A → B) → Set (a ℓ⊔ b ℓ⊔ ℓ₁ ℓ⊔ ℓ₂)
NonInjective-≡-preds Pred1 Pred2 f = Σ (NonInjective _≡_ f) λ { ((a₀ , a₁) , _ , _) → Pred1 a₀ × Pred2 a₁ }
NonInjective-≡-pred : ∀{a b}{A : Set a}{B : Set b}{ℓ : Level}
→ (P : A → Set ℓ)
→ (A → B) → Set (a ℓ⊔ b ℓ⊔ ℓ)
NonInjective-≡-pred Pred = NonInjective-≡-preds Pred Pred
NonInjective-∘ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c}
→ {f : A → B}(g : B → C)
→ NonInjective-≡ f
→ NonInjective-≡ (g ∘ f)
NonInjective-∘ g ((x0 , x1) , (x0≢x1 , fx0≡fx1))
= ((x0 , x1) , x0≢x1 , (cong g fx0≡fx1))
--------------------------------------------
-- Handy fmap and bind for specific types --
_<M$>_ : ∀{a b}{A : Set a}{B : Set b}
→ (f : A → B)
→ Maybe A → Maybe B
_<M$>_ = Maybe-map
<M$>-univ : ∀{a b}{A : Set a}{B : Set b}
→ (f : A → B)(x : Maybe A)
→ {y : B} → f <M$> x ≡ just y
→ ∃[ x' ] (x ≡ just x' × f x' ≡ y)
<M$>-univ f (just x) refl = x , (refl , refl)
maybe-lift : {A : Set}
→ {mx : Maybe A}{x : A}
→ (P : A → Set)
→ P x → mx ≡ just x
→ maybe {B = const Set} P ⊥ mx
maybe-lift {mx = just .x} {x} P px refl = px
<M$>-nothing : ∀ {a b}{A : Set a}{B : Set b}(f : A → B)
→ f <M$> nothing ≡ nothing
<M$>-nothing _ = refl
_<⊎$>_ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c}
→ (A → B) → C ⊎ A → C ⊎ B
f <⊎$> (inj₁ hb) = inj₁ hb
f <⊎$> (inj₂ x) = inj₂ (f x)
_⊎⟫=_ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c}
→ C ⊎ A → (A → C ⊎ B) → C ⊎ B
(inj₁ x) ⊎⟫= _ = inj₁ x
(inj₂ a) ⊎⟫= f = f a
-- Syntactic support for more faithful model of Haskell code
Either : ∀ {a b} → Set a → Set b → Set (a ℓ⊔ b)
Either A B = A ⊎ B
pattern Left x = inj₁ x
pattern Right x = inj₂ x
isLeft : ∀ {a b} {A : Set a} {B : Set b} → Either A B → Bool
isLeft (Left _) = true
isLeft (Right _) = false
isRight : ∀ {a b} {A : Set a} {B : Set b} → Either A B → Bool
isRight = Data.Bool.not ∘ isLeft
-- a non-dependent eliminator
eitherS : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
(x : Either A B) → ((x : A) → C) → ((x : B) → C) → C
eitherS eab fa fb = case eab of λ where
(Left a) → fa a
(Right b) → fb b
module _ {ℓ₀ ℓ₁ ℓ₂ : Level} where
EL-type = Set ℓ₁ → Set ℓ₂ → Set ℓ₀
EL-level = ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₀
-- Utility to make passing between `Either` and `EitherD` more convenient
record EitherLike (E : EL-type) : Set (ℓ+1 EL-level) where
field
fromEither : ∀ {A : Set ℓ₁} {B : Set ℓ₂} → Either A B → E A B
toEither : ∀ {A : Set ℓ₁} {B : Set ℓ₂} → E A B → Either A B
open EitherLike ⦃ ... ⦄ public
EL-func : EL-type → Set (ℓ+1 EL-level)
EL-func EL = ⦃ mel : EitherLike EL ⦄ → Set EL-level
instance
EitherLike-Either : ∀ {ℓ₁ ℓ₂} → EitherLike{ℓ₁ ℓ⊔ ℓ₂}{ℓ₁}{ℓ₂} Either
EitherLike.fromEither EitherLike-Either = id
EitherLike.toEither EitherLike-Either = id
-- an approximation of Haskell's backtick notation for making infix operators; in Agda, must have
-- spaces between f and backticks
flip' : _ -- Avoids warning about definition and syntax declaration being in different scopes
flip' = flip
syntax flip' f = ` f `
open import Data.String as String
hiding (_==_ ; _≟_ ; concat)
check : Bool → List String → Either String Unit
check b t = if b then inj₂ unit else inj₁ (String.intersperse "; " t)
-- TODO-1: Maybe this belongs somewhere else? It's in a similar
-- category as Optics, so maybe should similarly be in a module that
-- is separate from the main project?
------------------
-- Guard Syntax --
--
-- Example Usage:
--
-- > f : ℕ → ℕ
-- > f x = grd‖ x ≟ℕ 10 ≔ 12
-- > ‖ otherwise≔ 40 + 2
--
--
-- > g : ℕ ⊎ ℕ → ℕ
-- > g x = case x of λ
-- > { (inj₁ x) → grd‖ x ≤? 10 ≔ 2 * x
-- > ‖ otherwise≔ 42
-- > ; (inj₂ y) → y
-- > }
--
-- To type: ‖ --> \Vert
-- ≔ --> \:=
record ToBool {a}(A : Set a) : Set a where
field
toBool : A → Bool
open ToBool {{ ... }} public
not : ∀ {b} {B : Set b} ⦃ _ : ToBool B ⦄ → B → Bool
not b = Data.Bool.not (toBool b)
instance
ToBool-Bool : ToBool Bool
ToBool-Bool = record { toBool = id }
ToBool-Dec : ∀{a}{A : Set a} → ToBool (Dec A)
ToBool-Dec = record { toBool = ⌊_⌋ }
toWitnessT : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ true → P
toWitnessT {d = yes proof} _ = proof
toWitnessF : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ false → ¬ P
toWitnessF{d = no proof} _ = proof
infix 3 _≔_
data GuardClause {a}{b}(A : Set a) : Set (a ℓ⊔ ℓ+1 b) where
_≔_ : {B : Set b}{{ bb : ToBool B }} → B → A → GuardClause A
infix 3 otherwise≔_
data Guards {a}{b}(A : Set a) : Set (a ℓ⊔ ℓ+1 b) where
otherwise≔_ : A → Guards A
clause : GuardClause{a}{b} A → Guards{a}{b} A → Guards A
infixr 2 _‖_
_‖_ : ∀{a}{b}{A : Set a} → GuardClause{a}{b} A → Guards A → Guards A
_‖_ = clause
infix 1 grd‖_
grd‖_ : ∀{a}{b}{A : Set a} → Guards{a}{b} A → A
grd‖_ (otherwise≔ a) = a
grd‖_ (clause (b ≔ a) g) = if toBool b then a else (grd‖ g)
Any-satisfied-∈ : ∀{a ℓ}{A : Set a}{P : A → Set ℓ}{xs : List A}
→ Any P xs → Σ A (λ x → P x × x ∈ xs)
Any-satisfied-∈ (here px) = _ , (px , here refl)
Any-satisfied-∈ (there p) = let (a , px , prf) = Any-satisfied-∈ p
in (a , px , there prf)
f-sum : ∀{a}{A : Set a} → (A → ℕ) → List A → ℕ
f-sum f = sum ∘ List-map f
record Functor {ℓ₁ ℓ₂ : Level} (F : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where
infixl 4 _<$>_
field
_<$>_ : ∀ {A B : Set ℓ₁} → (A → B) → F A → F B
fmap = _<$>_
open Functor ⦃ ... ⦄ public
record Applicative {ℓ₁ ℓ₂ : Level} (F : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where
infixl 4 _<*>_
field
pure : ∀ {A : Set ℓ₁} → A → F A
_<*>_ : ∀ {A B : Set ℓ₁} → F (A → B) → F A → F B
open Applicative ⦃ ... ⦄ public
instance
ApplicativeFunctor : ∀ {ℓ₁ ℓ₂} {F : Set ℓ₁ → Set ℓ₂} ⦃ _ : Applicative F ⦄ → Functor F
Functor._<$>_ ApplicativeFunctor f xs = pure f <*> xs
record Monad {ℓ₁ ℓ₂ : Level} (M : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where
infixl 1 _>>=_ _>>_
field
return : ∀ {A : Set ℓ₁} → A → M A
_>>=_ : ∀ {A B : Set ℓ₁} → M A → (A → M B) → M B
_>>_ : ∀ {A B : Set ℓ₁} → M A → M B → M B
m₁ >> m₂ = m₁ >>= λ _ → m₂
open Monad ⦃ ... ⦄ public
instance
MonadApplicative : ∀ {ℓ₁ ℓ₂} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → Applicative M
Applicative.pure MonadApplicative = return
Applicative._<*>_ MonadApplicative fs xs = do
f ← fs
x ← xs
return (f x)
instance
Monad-Either : ∀ {ℓ}{C : Set ℓ} → Monad{ℓ}{ℓ} (Either C)
Monad.return (Monad-Either{ℓ}{C}) = inj₂
Monad._>>=_ (Monad-Either{ℓ}{C}) = either (const ∘ inj₁) _&_
Monad-Maybe : ∀ {ℓ} → Monad {ℓ} {ℓ} Maybe
Monad.return (Monad-Maybe{ℓ}) = just
Monad._>>=_ (Monad-Maybe{ℓ}) = _Maybe->>=_
Monad-List : ∀ {ℓ} → Monad {ℓ}{ℓ} List
Monad.return Monad-List x = x ∷ []
Monad._>>=_ Monad-List x f = concat (List-map f x)
maybeSMP : ∀ {ℓ} {A B : Set} {m : Set → Set ℓ} ⦃ _ : Monad m ⦄ → m (Maybe A) → B → (A → m B) → m B
maybeSMP ma b f = do
x ← ma
case x of λ where
nothing → pure b
(just j) → f j
fromMaybeM : ∀ {ℓ} {A : Set} {m : Set → Set ℓ} ⦃ _ : Monad m ⦄ → m A → m (Maybe A) → m A
fromMaybeM ma mma = do
mma >>= λ where
nothing → ma
(just a) → pure a
forM_ : ∀ {ℓ} {A B : Set} {M : Set → Set ℓ} ⦃ _ : Monad M ⦄ → List A → (A → M B) → M Unit
forM_ [] _ = return unit
forM_ (x ∷ xs) f = f x >> forM_ xs f
-- NOTE: because 'forM_' is defined above, it is necessary to
-- call 'forM' with parenthesis (e.g., recursive call in definition)
-- to disambiguate it for the Agda parser.
forM : ∀ {ℓ} {A B : Set} {M : Set → Set ℓ} ⦃ _ : Monad M ⦄ → List A → (A → M B) → M (List B)
forM [] _ = return []
forM (x ∷ xs) f = do
fx ← f x
fxs ← (forM) xs f
return (fx ∷ fxs)
foldrM : ∀ {ℓ₁ ℓ₂} {A B : Set ℓ₁} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → (A → B → M B) → B → List A → M B
foldrM _ b [] = return b
foldrM f b (a ∷ as) = foldrM f b as >>= f a
foldlM : ∀ {ℓ₁ ℓ₂} {A B : Set ℓ₁} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → (B → A → M B) → B → List A → M B
foldlM _ z [] = pure z
foldlM f z (x ∷ xs) = do
z' ← f z x
foldlM f z' xs
foldM = foldlM
foldM_ : {A B : Set} {M : Set → Set} ⦃ _ : Monad M ⦄ → (B → A → M B) → B → List A → M Unit
foldM_ f a xs = foldlM f a xs >> pure unit
open import LibraBFT.Base.Util public
record Eq {a} (A : Set a) : Set a where
infix 4 _≟_ _==_ _/=_
field
_≟_ : (a b : A) → Dec (a ≡ b)
_==_ : A → A → Bool
a == b = toBool $ a ≟ b
_/=_ : A → A → Bool
a /= b = not (a == b)
open Eq ⦃ ... ⦄ public
elem : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → A → List A → Bool
elem x = toBool ∘ Any-any (x ≟_)
instance
Eq-Nat : Eq ℕ
Eq._≟_ Eq-Nat = _≟ℕ_
Eq-Maybe : ∀ {a} {A : Set a} ⦃ _ : Eq A ⦄ → Eq (Maybe A)
Eq._≟_ Eq-Maybe nothing nothing = yes refl
Eq._≟_ Eq-Maybe (just _) nothing = no λ ()
Eq._≟_ Eq-Maybe nothing (just _) = no λ ()
Eq._≟_ Eq-Maybe (just a) (just b)
with a ≟ b
... | no proof = no λ where refl → proof refl
... | yes refl = yes refl
infixl 9 _!?_
_!?_ : {A : Set} → List A → ℕ → Maybe A
[] !? _ = nothing
(x ∷ _ ) !? 0 = just x
(_ ∷ xs) !? (suc n) = xs !? n
-- Like a Haskell list-comprehension for ℕ : [ n | n <- [from .. to] ]
fromToList : ℕ → ℕ → List ℕ
fromToList from to with from ≤′? to
... | no ¬pr = []
... | yes pr = fromToList-le from to pr []
where
fromToList-le : ∀ (from to : ℕ) (klel : from ≤′ to) (acc : List ℕ) → List ℕ
fromToList-le from ._ ≤′-refl acc = from ∷ acc
fromToList-le from (suc to) (≤′-step klel) acc = fromToList-le from to klel (suc to ∷ acc)
_ : fromToList 1 1 ≡ 1 ∷ []
_ = refl
_ : fromToList 1 2 ≡ 1 ∷ 2 ∷ []
_ = refl
_ : fromToList 2 1 ≡ []
_ = refl
| 31.328267
| 164
| 0.529106
|
d054cc161102706e3919dbaaa5c21387048044a2
| 1,119
|
agda
|
Agda
|
theorems/homotopy/TruncationLoopLadder.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/homotopy/TruncationLoopLadder.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/homotopy/TruncationLoopLadder.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 HoTT
module homotopy.TruncationLoopLadder where
⊙Ω-Trunc : ∀ {i} {n : ℕ₋₂} (X : Ptd i)
→ ⊙Ω (⊙Trunc (S n) X) ⊙≃ ⊙Trunc n (⊙Ω X)
⊙Ω-Trunc X = ≃-to-⊙≃ (=ₜ-equiv [ pt X ] [ pt X ]) idp
step : ∀ {i j} n {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y)
→ ⊙CommSquareEquiv
(⊙Ω-fmap (⊙Trunc-fmap {n = S n} f))
(⊙Trunc-fmap {n = n} (⊙Ω-fmap f))
(⊙–> (⊙Ω-Trunc X))
(⊙–> (⊙Ω-Trunc Y))
step n (f , idp) =
⊙comm-sqr (=ₜ-equiv-nat _ _ _ , idp) , snd (⊙Ω-Trunc _) , snd (⊙Ω-Trunc _)
rail : ∀ m {i} (X : Ptd i)
→ ⊙Ω^' m (⊙Trunc ⟨ m ⟩ X) ⊙→ ⊙Trunc 0 (⊙Ω^' m X)
rail O X = ⊙idf _
rail (S m) X = rail m (⊙Ω X) ⊙∘ ⊙Ω^'-fmap m (⊙–> (⊙Ω-Trunc X))
ladder : ∀ {i j} m {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y)
→ ⊙CommSquareEquiv
(⊙Ω^'-fmap m (⊙Trunc-fmap {n = ⟨ m ⟩} f))
(⊙Trunc-fmap {n = 0} (⊙Ω^'-fmap m f))
(rail m X)
(rail m Y)
ladder O f = ⊙comm-sqr (⊙∘-unit-l _) , idf-is-equiv _ , idf-is-equiv _
ladder (S m) f =
⊙CommSquareEquiv-∘v (ladder m (⊙Ω-fmap f)) (⊙Ω^'-csemap m (step ⟨ m ⟩ f))
| 32.911765
| 78
| 0.459339
|
39541ece4dae39bad09ca49ec5be6def7516529e
| 461
|
agda
|
Agda
|
test/interaction/Issue1298.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue1298.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue1298.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.cover:40 #-}
-- Andreas, 2014-10-09
-- Reported by ohmanjoakim
infixr 8 _⇒_
data Ty : Set where
_⇒_ : Ty → Ty → Ty
⟦_⟧ : Ty → Set
⟦ A ⇒ B ⟧ = ⟦ A ⟧ → ⟦ B ⟧
data Term : Ty → Set where
K : (A B : Ty) → Term (A ⇒ B ⇒ A)
test : (A : Ty) (a : Term A) → ⟦ A ⟧
test A a = {!a!}
-- When doing a case split on a in foo, the following is written:
-- test .(x ⇒ x₁ ⇒ x) (K A B) x x₁ = ?
-- Correct is
-- test .(A ⇒ B ⇒ A) (K A B) x x₁ = ?
| 18.44
| 65
| 0.496746
|
500cf338e0a86cd85390fd32274db1d8d435a34b
| 14,808
|
agda
|
Agda
|
agda/Esterel/Lang/CanFunction/MergePotentialRuleCan.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/Esterel/Lang/CanFunction/MergePotentialRuleCan.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/Esterel/Lang/CanFunction/MergePotentialRuleCan.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
{-
The equivalent "goodness" of can w.r.t. the rmerge reduction.
The lemma proved in this file is
can-irr : ∀ {BV} {FV} θ₁ θ₂ q →
CorrectBinding q BV FV →
(distinct' (proj₁ FV) (proj₁ (Dom θ₂))) →
Can q θ₁ ≡ Can q (θ₁ ← θ₂)
That is, the result of the Can function will not change
provided that the program does not refer to any variables
in the new environment.
-}
module Esterel.Lang.CanFunction.MergePotentialRuleCan where
open import utility
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Base
open import Esterel.Context
open import Esterel.Context.Properties
using (plug ; unplug)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open import Data.Bool
using (Bool ; true ; false ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; [] ; _∷_ ; _++_ ; map ; concatMap)
open import Data.List.Properties
using (map-id)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _≟_ ; _+_)
open import Data.Nat.Properties.Simple
using (+-comm)
open import Data.Product
using (Σ ; proj₁ ; proj₂ ; ∃ ; _,_ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function
using (_∘_ ; _∋_ ; id)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; trans ; sym ; cong ; subst)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ListSet Data.Nat._≟_
using (set-subtract ; set-subtract-[] ; set-subtract-split ; set-subtract-merge
; set-subtract-notin
; set-remove-mono-∈ ; set-remove-removed ; set-remove-not-removed)
can-new-irr : ∀ {BV} {FV} θ₁ θ₂ θo q →
CorrectBinding q BV FV →
(∀ S' → S' ∈ (proj₁ FV) → (S' ∉ proj₁ (Dom θ₂)) ⊎ (S' ∈ proj₁ (Dom θo))) →
Can q (θ₁ ← θo) ≡ Can q ((θ₁ ← θ₂) ← θo)
canθ-new-irr : ∀ {BV} {FV} sigs S θ₁ θ₂ θo q →
CorrectBinding q BV FV →
(∀ S' → S' ∈ (proj₁ FV) →
((S' ∉ proj₁ (Dom θ₂)) ⊎ (S' ∈ proj₁ (Dom θo))) ⊎
S' ∈ map (_+_ S) (SigMap.keys sigs)) →
Canθ sigs S q (θ₁ ← θo) ≡ Canθ sigs S q ((θ₁ ← θ₂) ← θo)
can-new-irr θ₁ θ₂ θo nothin CBnothing S-prop = refl
can-new-irr θ₁ θ₂ θo pause CBpause S-prop = refl
can-new-irr θ₁ θ₂ θo (signl S q) (CBsig cbq) S-prop
rewrite canθ-new-irr (Env.sig ([S]-env S)) 0 θ₁ θ₂ θo q cbq
(λ S' S'∈FV →
Data.Sum.map
(S-prop S')
(subst (S' ∈_) (sym (map-id (proj₁ (Dom ([S]-env S))))) ∘
(λ S'∈[S] →
subst (_∈ proj₁ (Dom ([S]-env S)))
(sym (∈:: S'∈[S]))
(Env.sig-∈-single S Signal.unknown)))
(set-subtract-split {ys = Signal.unwrap S ∷ []} S'∈FV))
= refl
can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop
with S-prop (Signal.unwrap S) (here refl)| Env.Sig∈ S (θ₁ ← θo) | Env.Sig∈ S ((θ₁ ← θ₂) ← θo)
... | inj₂ S∈Domθo | no S∉domθ₁←θo | S∈domθ₁←θ₂←θo? =
⊥-elim (S∉domθ₁←θo (Env.sig-←-monoʳ S θo θ₁ S∈Domθo))
... | inj₂ S∈Domθo | yes S∈domθ₁←θo | no S∉domθ₁←θ₂←θo =
⊥-elim (S∉domθ₁←θ₂←θo (Env.sig-←-monoʳ S θo (θ₁ ← θ₂) S∈Domθo))
... | inj₂ S∈Domθo | yes S∈domθ₁←θo | yes S∈domθ₁←θ₂←θo
rewrite SigMap.∈-get-U-irr-m S (Env.sig θ₁) (Env.sig (θ₁ ← θ₂)) (Env.sig θo)
S∈domθ₁←θo S∈domθ₁←θ₂←θo S∈Domθo
with Env.sig-stats {S} ((θ₁ ← θ₂) ← θo) S∈domθ₁←θ₂←θo
... | Signal.present = can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
... | Signal.absent = can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
... | Signal.unknown
rewrite can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
| can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop
| inj₁ S∉Domθ₂ | yes S∈domθ₁←θo | yes S∈domθ₁←θ₂←θo
with Env.sig-←⁻ {θ₁} {θo} S S∈domθ₁←θo
... | inj₂ S∈Domθo
rewrite SigMap.∈-get-U-irr-m S (Env.sig θ₁) (Env.sig (θ₁ ← θ₂)) (Env.sig θo)
S∈domθ₁←θo S∈domθ₁←θ₂←θo S∈Domθo
with Env.sig-stats {S} ((θ₁ ← θ₂) ← θo) S∈domθ₁←θ₂←θo
... | Signal.present = can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
... | Signal.absent = can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
... | Signal.unknown
rewrite can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
| can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop
| inj₁ S∉Domθ₂ | yes S∈domθ₁←θo | yes S∈domθ₁←θ₂←θo
| inj₁ S∈domθ₁ with Env.sig-←-irr-get {θ₁} {θ₂} {S} S∈domθ₁ S∉Domθ₂
... | a , b rewrite SigMap.get-U-both-irr-m S (Env.sig θ₁) (Env.sig (θ₁ ← θ₂)) (Env.sig θo) S∈domθ₁ a S∈domθ₁←θo S∈domθ₁←θ₂←θo b
with Env.sig-stats {S} ((θ₁ ← θ₂) ← θo) S∈domθ₁←θ₂←θo
... | Signal.present = can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
... | Signal.absent = can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
... | Signal.unknown
rewrite can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
| can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent cbp cbq) S-prop
| inj₁ S∉Domθ₂ | yes S∈domθ₁←θo | no S∉domθ₁←θ₂←θo
rewrite SigMap.keys-assoc-comm (Env.sig θ₁) (Env.sig θ₂) (Env.sig θo)
= ⊥-elim (S∉domθ₁←θ₂←θo (SigMap.U-mono {m = Env.sig (θ₁ ← θo)} {k = S} S∈domθ₁←θo))
can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent cbp cbq) S-prop
| inj₁ S∉Domθ₂ | no S∉domθ₁←θo | yes S∈domθ₁←θ₂←θo
with Env.sig-←⁻ {θ₁ ← θo} {θ₂} S
(subst (Signal.unwrap S ∈_)
(SigMap.keys-assoc-comm (Env.sig θ₁) (Env.sig θ₂) (Env.sig θo))
S∈domθ₁←θ₂←θo)
... | (inj₁ S∈Domθ₁←θo) = ⊥-elim (S∉domθ₁←θo S∈Domθ₁←θo)
... | (inj₂ S∈Domθ₂) = ⊥-elim (S∉Domθ₂ S∈Domθ₂)
can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop
| inj₁ S∉Domθ₂ | no S∉domθ₁←θo | no S∉domθ₁←θ₂←θo
rewrite can-new-irr θ₁ θ₂ θo p cbp
(λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp)))
| can-new-irr θ₁ θ₂ θo q cbq
(λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (emit S) CBemit S-prop = refl
can-new-irr θ₁ θ₂ θo (p ∥ q) (CBpar {FVp = FVp} cbp cbq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) S-prop
rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp))
| can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (loop q) (CBloop cbq BV≠FV) S-prop =
can-new-irr θ₁ θ₂ θo q cbq S-prop
can-new-irr θ₁ θ₂ θo (loopˢ p q) (CBloopˢ {BVp = BVp} {FVp = FVp} CBp CBq BVp≠FVq BVq≠FVq) S-prop
rewrite can-new-irr θ₁ θ₂ θo p CBp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp))
| can-new-irr θ₁ θ₂ θo q CBq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (p >> q) (CBseq {BVp = BVp} {FVp = FVp} cbp cbq BVp≠FVq) S-prop
with can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp))
... | can-p-θ₁←θo≡can-p-θ₁←θ₂←θo
with any (Code._≟_ Code.nothin) (Canₖ p (θ₁ ← θo))
| any (Code._≟_ Code.nothin) (Canₖ p ((θ₁ ← θ₂) ← θo))
... | yes nothin∈can-p-θ₁←θo | yes nothin∈can-p-θ₁←θ₂←θo
rewrite can-p-θ₁←θo≡can-p-θ₁←θ₂←θo
| can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq))
= refl
... | yes nothin∈can-p-θ₁←θo | no nothin∉can-p-θ₁←θ₂←θo
= ⊥-elim (nothin∉can-p-θ₁←θ₂←θo
(subst (λ xs → Code.nothin ∈ proj₁ (proj₂ xs))
can-p-θ₁←θo≡can-p-θ₁←θ₂←θo
nothin∈can-p-θ₁←θo))
... | no nothin∉can-p-θ₁←θo | yes nothin∈can-p-θ₁←θ₂←θo
= ⊥-elim (nothin∉can-p-θ₁←θo
(subst (λ xs → Code.nothin ∈ proj₁ (proj₂ xs))
(sym can-p-θ₁←θo≡can-p-θ₁←θ₂←θo)
nothin∈can-p-θ₁←θ₂←θo))
... | no nothin∉can-p-θ₁←θo | no nothin∉can-p-θ₁←θ₂←θo
rewrite can-p-θ₁←θo≡can-p-θ₁←θ₂←θo = refl
can-new-irr θ₁ θ₂ θo (suspend q S) (CBsusp cbq [S]≠BVp) S-prop =
can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FV → S-prop S' (there S'∈FV))
can-new-irr θ₁ θ₂ θo (exit n) CBexit S-prop = refl
can-new-irr θ₁ θ₂ θo (trap q) (CBtrap cbq) S-prop
rewrite can-new-irr θ₁ θ₂ θo q cbq S-prop
= refl
can-new-irr θ₁ θ₂ θo (shared s ≔ e in: q) (CBshared {FV = FV} cbq) S-prop
rewrite set-subtract-[] (proj₁ FV)
| can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FV → S-prop S' (++ʳ (proj₁ (FVₑ e)) S'∈FV))
= refl
can-new-irr θ₁ θ₂ θo (s ⇐ e) CBsset S-prop = refl
can-new-irr θ₁ θ₂ θo (var x ≔ e in: q) (CBvar {FV = FV} cbq) S-prop
rewrite set-subtract-[] (proj₁ FV)
= can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FV → S-prop S' (++ʳ (proj₁ (FVₑ e)) S'∈FV))
can-new-irr θ₁ θ₂ θo (x ≔ e) CBvset S-prop = refl
can-new-irr θ₁ θ₂ θo (if x ∣⇒ p ∣⇒ q) (CBif {FVp = FVp} cbp cbq) S-prop
rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp))
| can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq))
= refl
can-new-irr θ₁ θ₂ θo (ρ⟨ θ , A ⟩· q) (CBρ {FV = FV} cbq) S-prop
rewrite canθ-new-irr (Env.sig θ) 0 θ₁ θ₂ θo q cbq
(λ S' S'∈FV →
Data.Sum.map
(S-prop S')
(subst (S' ∈_) (sym (map-id (proj₁ (Dom θ)))))
(set-subtract-split {ys = proj₁ (Dom θ)} S'∈FV))
= refl
canθ-new-irr-S-prop-accumulate : ∀ {xs ys zs} S status θo →
(∀ S' → S' ∈ xs →
(S' ∉ ys ⊎ S' ∈ proj₁ (Dom θo)) ⊎
S' ∈ (S + 0 ∷ map (_+_ S) (map suc zs))) →
∀ S' → S' ∈ xs →
(S' ∉ ys ⊎ S' ∈ proj₁ (Dom (θo ← [ (S ₛ) ↦ status ]))) ⊎
S' ∈ map (_+_ (suc S)) zs
canθ-new-irr-S-prop-accumulate {zs = zs} S status θo S-prop S' S'∈xs with S-prop S' S'∈xs
... | inj₁ (inj₁ S'∉ys) = inj₁ (inj₁ S'∉ys)
... | inj₁ (inj₂ S'∈Domθo) =
inj₁ (inj₂ (Env.sig-←-monoˡ (S' ₛ) θo [ (S ₛ) ↦ status ] S'∈Domθo))
... | inj₂ (here refl) rewrite +-comm S 0 =
inj₁ (inj₂ (Env.sig-←-monoʳ (S ₛ) [ S ₛ ↦ status ] θo (Env.sig-∈-single (S ₛ) status)))
... | inj₂ (there S'∈map-+-S-suc-zs)
rewrite map-+-compose-suc S zs
= inj₂ S'∈map-+-S-suc-zs
canθ-new-irr {BV} {FV} [] S θ₁ θ₂ θo q cbq S-prop =
can-new-irr θ₁ θ₂ θo q cbq S-prop'
where
S-prop' : ∀ S' → S' ∈ proj₁ FV → S' ∉ proj₁ (Dom θ₂) ⊎ S' ∈ proj₁ (Dom θo)
S-prop' S' S'∈FV with S-prop S' S'∈FV
... | inj₁ S'∉Domθ₂⊎S'∈Domθo = S'∉Domθ₂⊎S'∈Domθo
... | inj₂ ()
canθ-new-irr (nothing ∷ sigs) S θ₁ θ₂ θo q cbq S-prop =
canθ-new-irr sigs (suc S) θ₁ θ₂ θo q cbq
(λ S' S'∈FV →
Data.Sum.map id (subst (S' ∈_) (map-+-compose-suc S (SigMap.keys sigs)))
(S-prop S' S'∈FV))
canθ-new-irr (just Signal.present ∷ sigs) S θ₁ θ₂ θo q cbq S-prop
rewrite sym (Env.←-assoc θ₁ θo ([S]-env-present (S ₛ)))
| sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env-present (S ₛ)))
= canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env-present (S ₛ)) q cbq
(canθ-new-irr-S-prop-accumulate S Signal.present θo S-prop)
canθ-new-irr (just Signal.absent ∷ sigs) S θ₁ θ₂ θo q cbq S-prop
rewrite sym (Env.←-assoc θ₁ θo ([S]-env-absent (S ₛ)))
| sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env-absent (S ₛ)))
= canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env-absent (S ₛ)) q cbq
(canθ-new-irr-S-prop-accumulate S Signal.absent θo S-prop)
canθ-new-irr (just Signal.unknown ∷ sigs) S θ₁ θ₂ θo q cbq S-prop
with any (_≟_ S) (Canθₛ sigs (suc S) q ((θ₁ ← θo) ← [S]-env (S ₛ)))
| any (_≟_ S) (Canθₛ sigs (suc S) q (((θ₁ ← θ₂) ← θo) ← [S]-env (S ₛ)))
... | yes S∈canθ-sigs-q-θ₁←θo←[S] | yes S∈canθ-sigs-q-θ₁←θ₂←θo←[S]
rewrite sym (Env.←-assoc θ₁ θo ([S]-env (S ₛ)))
| sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env (S ₛ)))
= canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env (S ₛ)) q cbq
(canθ-new-irr-S-prop-accumulate S Signal.unknown θo S-prop)
... | no S∉canθ-sigs-q-θ₁←θo←[S] | no S∉canθ-sigs-q-θ₁←θ₂←θo←[S]
rewrite sym (Env.←-assoc θ₁ θo ([S]-env-absent (S ₛ)))
| sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env-absent (S ₛ)))
= canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env-absent (S ₛ)) q cbq
(canθ-new-irr-S-prop-accumulate S Signal.absent θo S-prop)
... | yes S∈canθ-sigs-q-θ₁←θo←[S] | no S∉canθ-sigs-q-θ₁←θ₂←θo←[S]
rewrite sym (Env.←-assoc θ₁ θo ([S]-env (S ₛ)))
| sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env (S ₛ)))
| canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env (S ₛ)) q cbq
(canθ-new-irr-S-prop-accumulate S Signal.unknown θo S-prop)
= ⊥-elim
(S∉canθ-sigs-q-θ₁←θ₂←θo←[S]
S∈canθ-sigs-q-θ₁←θo←[S])
... | no S∉canθ-sigs-q-θ₁←θo←[S] | yes S∈canθ-sigs-q-θ₁←θ₂←θo←[S]
rewrite sym (Env.←-assoc θ₁ θo ([S]-env (S ₛ)))
| sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env (S ₛ)))
| canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env (S ₛ)) q cbq
(canθ-new-irr-S-prop-accumulate S Signal.unknown θo S-prop)
= ⊥-elim
(S∉canθ-sigs-q-θ₁←θo←[S]
S∈canθ-sigs-q-θ₁←θ₂←θo←[S])
can-irr : ∀ {BV} {FV} θ₁ θ₂ q →
CorrectBinding q BV FV →
(distinct' (proj₁ FV) (proj₁ (Dom θ₂))) →
Can q θ₁ ≡ Can q (θ₁ ← θ₂)
can-irr θ₁ θ₂ q cbq FV≠Domθ₂
with can-new-irr θ₁ θ₂ Env.[]env q cbq (λ S' S'∈FV → inj₁ (FV≠Domθ₂ S' S'∈FV))
... | eq rewrite cong (Can q) (Env.←-comm Env.[]env θ₁ distinct-empty-left)
| cong (Can q) (Env.←-comm Env.[]env (θ₁ ← θ₂) distinct-empty-left)
= eq
| 46.566038
| 128
| 0.568679
|
dca2d116ddcc62d64ecaeb6f0a96ea9ea3f8cf25
| 2,766
|
agda
|
Agda
|
examples/outdated-and-incorrect/tait/Prelude.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/tait/Prelude.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/tait/Prelude.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Prelude where
infix 20 _≡_ _≤_ _∈_
infixl 60 _,_ _++_ _+_ _◄_ _◄²_
_∘_ : {A B : Set}{C : B -> Set}(f : (x : B) -> C x)(g : A -> B)(x : A) -> C (g x)
(f ∘ g) x = f (g x)
data _≡_ {A : Set}(x : A) : {B : Set} -> B -> Set where
refl : x ≡ x
cong : {A : Set}{B : A -> Set}(f : (z : A) -> B z){x y : A} ->
x ≡ y -> f x ≡ f y
cong f refl = refl
subst : {A : Set}(P : A -> Set){x y : A} -> x ≡ y -> P y -> P x
subst P refl px = px
sym : {A : Set}{x y : A} -> x ≡ y -> y ≡ x
sym refl = refl
data Nat : Set where
zero : Nat
suc : Nat -> Nat
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN NATPLUS _+_ #-}
data _≤_ : Nat -> Nat -> Set where
leqZ : {m : Nat} -> zero ≤ m
leqS : {n m : Nat} -> n ≤ m -> suc n ≤ suc m
refl-≤ : {n : Nat} -> n ≤ n
refl-≤ {zero } = leqZ
refl-≤ {suc n} = leqS refl-≤
refl-≤' : {n m : Nat} -> n ≡ m -> n ≤ m
refl-≤' refl = refl-≤
trans-≤ : {x y z : Nat} -> x ≤ y -> y ≤ z -> x ≤ z
trans-≤ leqZ yz = leqZ
trans-≤ (leqS xy) (leqS yz) = leqS (trans-≤ xy yz)
lem-≤suc : {x : Nat} -> x ≤ suc x
lem-≤suc {zero } = leqZ
lem-≤suc {suc x} = leqS lem-≤suc
lem-≤+L : (x : Nat){y : Nat} -> y ≤ x + y
lem-≤+L zero = refl-≤
lem-≤+L (suc x) = trans-≤ (lem-≤+L x) lem-≤suc
lem-≤+R : {x y : Nat} -> x ≤ x + y
lem-≤+R {zero } = leqZ
lem-≤+R {suc x} = leqS lem-≤+R
data List (A : Set) : Set where
ε : List A
_,_ : List A -> A -> List A
_++_ : {A : Set} -> List A -> List A -> List A
xs ++ ε = xs
xs ++ (ys , y) = (xs ++ ys) , y
data All {A : Set}(P : A -> Set) : List A -> Set where
∅ : All P ε
_◄_ : forall {xs x} -> All P xs -> P x -> All P (xs , x)
{-
data Some {A : Set}(P : A -> Set) : List A -> Set where
hd : forall {x xs} -> P x -> Some P (xs , x)
tl : forall {x xs} -> Some P xs -> Some P (xs , x)
-}
data _∈_ {A : Set}(x : A) : List A -> Set where
hd : forall {xs} -> x ∈ xs , x
tl : forall {y xs} -> x ∈ xs -> x ∈ xs , y
_!_ : {A : Set}{P : A -> Set}{xs : List A} ->
All P xs -> {x : A} -> x ∈ xs -> P x
∅ ! ()
(xs ◄ x) ! hd = x
(xs ◄ x) ! tl i = xs ! i
tabulate : {A : Set}{P : A -> Set}{xs : List A} ->
({x : A} -> x ∈ xs -> P x) -> All P xs
tabulate {xs = ε} f = ∅
tabulate {xs = xs , x} f = tabulate (f ∘ tl) ◄ f hd
data All² {I : Set}{A : I -> Set}(P : {i : I} -> A i -> Set) :
{is : List I} -> All A is -> Set where
∅² : All² P ∅
_◄²_ : forall {i is}{x : A i}{xs : All A is} ->
All² P xs -> P x -> All² P (xs ◄ x)
data _∈²_ {I : Set}{A : I -> Set}{i : I}(x : A i) :
{is : List I} -> All A is -> Set where
hd² : forall {is}{xs : All A is} -> x ∈² xs ◄ x
tl² : forall {j is}{y : A j}{xs : All A is} ->
x ∈² xs -> x ∈² xs ◄ y
| 26.342857
| 81
| 0.435286
|
0e5c5c77e66b3e256aa745eb27d76e9c4057952e
| 1,180
|
agda
|
Agda
|
agda/proof-nat.agda
|
anqurvanillapy/fpl
|
9576d5b76e6a868992dbe52930712ac67697bed2
|
[
"MIT"
] | 1
|
2019-08-24T22:47:47.000Z
|
2019-08-24T22:47:47.000Z
|
agda/proof-nat.agda
|
anqurvanillapy/fpl
|
9576d5b76e6a868992dbe52930712ac67697bed2
|
[
"MIT"
] | null | null | null |
agda/proof-nat.agda
|
anqurvanillapy/fpl
|
9576d5b76e6a868992dbe52930712ac67697bed2
|
[
"MIT"
] | null | null | null |
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
{- Addition -}
_+_ : ℕ → ℕ → ℕ
zero + n = n
(suc m) + n = suc (m + n)
_ : 3 + 4 ≡ 7
_ =
begin
3 + 4
≡⟨⟩
suc (2 + 4)
≡⟨⟩
suc (suc (1 + 4))
≡⟨⟩
suc (suc (suc (0 + 4)))
≡⟨⟩
suc (suc (suc 4))
≡⟨⟩
7
∎
_ : 1 + 1 ≡ 2
_ = refl
{- Multiplication -}
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
_ : 2 * 2 ≡ 4
_ =
begin
2 * 2
≡⟨⟩
2 + (1 * 2)
≡⟨⟩
2 + (2 + (0 * 2))
≡⟨⟩
2 + 2
≡⟨⟩
4
∎
_ : 1 * 1 ≡ 1
_ = refl
{- Exponentiation -}
_^_ : ℕ → ℕ → ℕ
n ^ 0 = 1
n ^ (suc m) = n * (n ^ m)
_ : 2 ^ 3 ≡ 8
_ =
begin
2 ^ 3
≡⟨⟩
2 * (2 ^ 2)
≡⟨⟩
2 * (2 * (2 ^ 1))
≡⟨⟩
2 * (2 * (2 * (2 ^ 0)))
≡⟨⟩
2 * (2 * (2 * 1))
≡⟨⟩
8
∎
_ : 42 ^ 0 ≡ 1
_ = refl
{- Monus -}
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ (suc n) = zero
(suc m) ∸ (suc n) = m ∸ n
_ : 2 ∸ 1 ≡ 1
_ =
begin
2 ∸ 1
≡⟨⟩
1 ∸ 0
≡⟨⟩
1
∎
_ : 7 ∸ 4 ≡ 3
_ = refl
_ : 4 ∸ 7 ≡ 0
_ = refl
| 11.132075
| 50
| 0.35678
|
1cac0d8654e2781d5d447a370e5ef7a186d7bdc6
| 1,030
|
agda
|
Agda
|
lib/types/Groupoid.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Groupoid.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Groupoid.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NType2
open import lib.types.TLevel
open import lib.types.Sigma
open import lib.types.Pi
module lib.types.Groupoid where
record GroupoidStructure {i j} {El : Type i} (Arr : El → El → Type j)
(_ : ∀ x y → has-level ⟨0⟩ (Arr x y)) : Type (lmax i j) where
field
id : ∀ {x} → Arr x x
inv : ∀ {x y} → Arr x y → Arr y x
comp : ∀ {x y z} → Arr x y → Arr y z → Arr x z
unit-l : ∀ {x y} (a : Arr x y) → comp id a == a
unit-r : ∀ {x y} (a : Arr x y) → comp a id == a
assoc : ∀ {x y z w} (a : Arr x y) (b : Arr y z) (c : Arr z w)
→ comp (comp a b) c == comp a (comp b c)
inv-r : ∀ {x y} (a : Arr x y) → (comp a (inv a)) == id
inv-l : ∀ {x y } (a : Arr x y) → (comp (inv a) a) == id
record Groupoid {i j} : Type (lsucc (lmax i j)) where
constructor groupoid
field
El : Type i
Arr : El → El → Type j
Arr-level : ∀ x y → has-level ⟨0⟩ (Arr x y)
groupoid-struct : GroupoidStructure Arr Arr-level
| 33.225806
| 69
| 0.538835
|
4a0ea43afec71e24f6d20cb96cf547d2cce05282
| 9,169
|
agda
|
Agda
|
src/scratch/FinDecEq1.agda
|
zampino/ggt
|
e2d6b5f9bea15dd67817bf67e273f6b9a14335af
|
[
"MIT"
] | 2
|
2020-04-17T11:10:00.000Z
|
2020-11-28T05:48:39.000Z
|
src/scratch/FinDecEq1.agda
|
zampino/ggt
|
e2d6b5f9bea15dd67817bf67e273f6b9a14335af
|
[
"MIT"
] | null | null | null |
src/scratch/FinDecEq1.agda
|
zampino/ggt
|
e2d6b5f9bea15dd67817bf67e273f6b9a14335af
|
[
"MIT"
] | null | null | null |
module Scratch.FinDecEq1 where
open import Data.Bool.Base hiding (_≤_)
open import Data.Product
open import Data.Sum
open import Level renaming (suc to lsuc; _⊔_ to _⊔ℓ_; zero to lzero)
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Unary using (Decidable)
open import Relation.Binary hiding (Decidable)
open import Function.Base
-- open import Function.Bijection hiding (_∘_)
-- open import Function.Equality hiding (≡-setoid; _∘_)
open import Data.Nat.Base hiding (_≤_)
open import Data.Fin renaming (zero to fzero; suc to fsuc)
open import Data.Fin.Properties hiding (to-from)
-- see http://firsov.ee/finset/finset.pdf
open import Data.List.Base renaming (tabulate to tab;
lookup to nth;
filter to lfilter;
allFin to allF)
open import Data.List.Properties
open import Data.List.Relation.Unary.Any
-- open import Data.List.Membership.Propositional renaming (_∈_ to _∈ℓ_)
-- open import Data.List.Membership.Propositional.Properties
open import Data.List.Relation.Unary.Any as Any -- hiding (tail)
open import Data.List.Relation.Unary.Any.Properties hiding (tabulate⁺)
open import Data.List.Relation.Unary.All as All hiding (tabulate)
open import Data.List.Relation.Unary.AllPairs as AllPairs
open import Data.List.Relation.Unary.AllPairs.Properties renaming (map⁺ to ap-map⁺)
-- :-( can't use Vector because it doesn't have a filter
-- open import Data.Vec.Functional as Coll
-- open import Data.Vec.Functional.Relation.Unary.Any
-- renaming (here to here'; there to there')
open import Relation.Binary.PropositionalEquality as Eq
open Eq.≡-Reasoning
open import Scratch.Data.List.Relation.Helpers
open import Scratch.Subset
-- record StronglyFiniteSetoid (n : ℕ) : Set (lsuc (c ⊔ℓ ℓ)) where
-- field
-- S : Setoid c ℓ
-- χ : Bijection (≡-setoid n) S
--
-- open Setoid S
-- open Bijection χ
-- open Π to renaming (_⟨$⟩_ to to')
-- open Π from renaming (_⟨$⟩_ to from')
--
-- ι : Fin n → Carrier
-- ι x = to' x
--
-- ρ : Carrier → Fin n
-- ρ y = from' y
-- TODO: pullback of ω where ω ≤ _≈_ (see orbital relation)
-- /Users/amantini/dev/agda/agda-stdlib/README/Data/Interleaving.agda
-- if ω is decidable then the pullback is a FinDecEq
open import Data.Vec hiding (length)
renaming (lookup to vlookup)
open import Data.Vec.Properties
-- open import Data.Vec.Relation.Unary.Any
open import Data.Fin.Subset
open import Data.Fin.Subset.Properties
lmap = Data.List.Base.map
syntax lmap (λ x → B) L = ⟦ B ∣ x ∈ℓ L ⟧
fsuc∈ : ∀ {n} → { p : Subset n} → {x : Fin n} → {s : Side} → (x ∈ p) → (fsuc x) ∈ (s Data.Vec.∷ p)
fsuc∈ here = there here
fsuc∈ (there x∈p) = there (fsuc∈ x∈p)
fst₊ : ∀ {n} → (s : Subset n) → Nonempty s → Σ (Fin n) (λ x → ( x ∈ s × (∀ {y} → (y ∈ s) → x ≤ y )))
fst₊ {suc n} (inside ∷ rest) ne = ( fzero , here , λ _ → z≤n )
fst₊ {suc n} (outside ∷ rest) ne with (∃-toSum ne)
... | inj₂ b = let w = drop-there (proj₂ b)
z = (proj₁ b , w)
( a , bb , c ) = (fst₊ rest z)
in (fsuc a , fsuc∈ bb , λ { (there y∈s) → s≤s (c y∈s) } )
fst₋ : ∀ {n} → (s : Subset n) → Nonempty s → Fin n
fst₋ s ne = proj₁ (fst₊ s ne)
fst₋unique : ∀ {n} → ∀ (s t : Subset n) → (ns : Nonempty s) → (nt : Nonempty t) →
s ≡ t → (fst₋ s ns) ≡ (fst₋ t nt)
fst₋unique s t ns nt s≡t = let fs , fs∈s , fs≤ = (fst₊ s ns)
ft , ft∈t , ft≤ = (fst₊ t nt)
ft∈s : ft ∈ s
ft∈s = subst _ (sym s≡t) ft∈t
fs∈t : fs ∈ t
fs∈t = subst _ s≡t fs∈s
in ≤-antisym (fs≤ ft∈s) (ft≤ fs∈t)
open import Data.Unit hiding (_≟_; ⊤)
-- TODO: see src/Data/List/Membership/Setoid.agda
-- see src/Relation/Nullary/Decidable.agda
≡→T : ∀ {b : Bool} → b ≡ true → T b
≡→T refl = tt
record FinDecEq {a} (n : ℕ) : Set (lsuc a) where
field
_ω_ : Rel (Fin n) a
isDecEq : IsDecEquivalence _ω_
std : DecSetoid _ _
std = record { Carrier = (Fin n) ;
_≈_ = _ω_ ;
isDecEquivalence = isDecEq }
open DecSetoid std
renaming (_≟_ to _ω?_ ;
refl to r ;
sym to s ;
trans to t ;
Carrier to F;
setoid to std')
public
import Data.List.Membership.Propositional
module MP = Data.List.Membership.Propositional {A = F}
open MP renaming (_∈_ to _∈ℓ_)
-- open import Data.List.Membership.Propositional renaming (_∈_ to _∈ℓ_)
open import Data.List.Membership.Propositional.Properties
[_]ω : (Fin n) → Subset n
[ o ]ω = tabulate (does ∘ (_ω? o))
-- TODO: use src/Data/List/Membership/Setoid.agda
-- and src/Data/Fin/Subset/Properties.agda
ω⇒∈ : ∀ {x y} → x ω y → x ∈ [ y ]ω
ω⇒∈ {x} {y} xωy = let lkp = begin vlookup [ y ]ω x ≡⟨ lookup∘tabulate _ x ⟩
does (x ω? y) ≡⟨ dec-true (x ω? y) xωy ⟩
true ∎
in lookup⇒[]= x [ y ]ω lkp
-- in particular classes are not empty
o∈[o]ω : ∀ { o : Fin n } → o ∈ [ o ]ω
o∈[o]ω = ω⇒∈ r
-- and actually equal
-- conversely
∈⇒ω : ∀ {x y} → x ∈ [ y ]ω → x ω y
∈⇒ω {x} {y} x∈[y] = let w = begin true ≡˘⟨ []=⇒lookup x∈[y] ⟩
vlookup [ y ]ω x ≡⟨ lookup∘tabulate _ x ⟩
does (x ω? y) ≡˘⟨ isYes≗does _ ⟩
isYes (x ω? y) ∎
r : True (x ω? y)
r = ≡→T (sym w)
in toWitness r
ω⇒⊆ : ∀ {x y} → x ω y → [ x ]ω ⊆ [ y ]ω
ω⇒⊆ {x} {y} xωy {s} s∈[x] = ω⇒∈ (t (∈⇒ω s∈[x]) xωy )
ω⇒≡ : ∀ {x y} → x ω y → [ x ]ω ≡ [ y ]ω
ω⇒≡ {x} {y} xωy = ⊆-antisym (ω⇒⊆ xωy) (ω⇒⊆ (s xωy))
-- canonical choice - TODO
c : F → F
c f = fst₋ {n} [ f ]ω ( f , o∈[o]ω )
--
cx∈[x] : ∀ (x : Fin n) → (c x) ∈ [ x ]ω
cx∈[x] x = proj₁ (proj₂ (fst₊ [ x ]ω ( x , o∈[o]ω )))
xωcx : ∀ (x : F) → x ω (c x)
xωcx x = s (∈⇒ω (cx∈[x] x))
--
c⇒ω : ∀ {x y} → c x ≡ c y → x ω y
c⇒ω {x} {y} cx≡cy = let P = λ q → q ∈ [ y ]ω
w : (c x) ∈ [ y ]ω
w = subst P (sym cx≡cy) (cx∈[x] y)
in t (xωcx x) (∈⇒ω w)
--
ω⇒c : ∀ {x y} → x ω y → c x ≡ c y
ω⇒c {x} {y} xωy = fst₋unique _ _ _ _ (ω⇒≡ xωy)
c-idempt : (x : F) → c (c x) ≡ c x
c-idempt x = ω⇒c {c x} {x} (s (xωcx x))
ω-disj : ∀ {x y} → ¬ (x ω y) → Empty ([ x ]ω ∩ [ y ]ω)
ω-disj {x} {y} ¬xωy f∈∩ = let f , [x]∩[y] = f∈∩
l , r = x∈p∩q⁻ _ _ [x]∩[y]
fωx : f ω x
fωx = ∈⇒ω l
fωy = ∈⇒ω r
in ¬xωy (t (s fωx) fωy)
ω-Disj : ∀ {x y} → ¬ (x ω y) → Disj [ x ]ω [ y ]ω
ω-Disj ¬xωy = Empty-unique (ω-disj ¬xωy)
-- canonical representative
cr : (i : F) → Set
cr i = i ≡ (c i)
-- c' : (i : F) → cr i × i ω (c i)
-- _≟_
cr? : Decidable cr
cr? = λ i → i ≟ (c i)
cr-disj : ∀ {x y} → (cr x) → (cr y) → x ≢ y → ¬ (x ω y)
cr-disj {x} {y} crx cry x≢y xωy = let x≡y = begin x ≡⟨ crx ⟩
c x ≡⟨ ω⇒c xωy ⟩
c y ≡˘⟨ cry ⟩
y ∎
in x≢y x≡y
Tr : List F
Tr = (lfilter cr? (allF n))
-- ∈-filter⁻ : ∀ {v xs} → v ∈ filter P? xs → v ∈ xs × P v
-- C : List (Subset n)
-- C = ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧
-- ap x≢y allF
-- ap ¬ x ω y Tr
-- ap Disj (map [_] Tr)
ap1 : AllPairs _≢_ (allF n)
ap1 = tabulate⁺ id
ap2 : AllPairs (λ x y → ¬ x ω y) Tr
ap2 = filter⁺⁺ cr? cr-disj ap1
ap3 : AllPairs Disj ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧
ap3 = ap-map⁺ (AllPairs.map ω-Disj ap2)
C-cover' : ∀ (x : F) → (∃ λ k → cr k × x ω k)
C-cover' x = (c x) , sym (c-idempt x) , xωcx x
C-cover : ∀ (x : F) → Any (x ∈_) ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧
C-cover x = let (k , crk , xωk) = C-cover' x
k∈ℓallF : k ∈ℓ allF n
k∈ℓallF = ∈-allFin {n} k
k∈ℓTr : k ∈ℓ Tr
k∈ℓTr = ∈-filter⁺ cr? k∈ℓallF crk
a : Any (x ω_) Tr
a = lose k∈ℓTr xωk
b : Any ((x ∈_) ∘ [_]ω) Tr
b = Any.map ω⇒∈ a
-- map⁺ : Any (P ∘ f) xs → Any P (List.map f xs)
in map⁺ b
--
[]ω-cover : ⊤ ≡ ⋃ ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧
[]ω-cover = cover-⊤ ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧ C-cover
-- Cardinality : n ≡ Data.List.Base.sum ⟦ ∣ [ x ]ω ∣ ∣ x ∈ℓ Tr ⟧
-- Cardinality =
-- let c = ∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣ ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧ ap3
-- in begin
-- n ≡˘⟨ ∣⊤∣≡n n ⟩
-- ∣ ⊤ {n} ∣ ≡⟨ cong ∣_∣ []ω-cover ⟩
-- ∣ ⋃ ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧ ∣ ≡⟨ c ⟩
-- -- cong List.sum (map-compose λ t → ∣ [ t ]ω ∣ ) refl
-- Data.List.Base.sum (lmap ∣_∣ ⟦ [ x ]ω ∣ x ∈ℓ Tr ⟧) ≡˘⟨ ? ⟩
-- Data.List.Base.sum ⟦ ∣ [ x ]ω ∣ ∣ x ∈ℓ Tr ⟧ ∎
| 33.221014
| 100
| 0.476279
|
cb0d762e677bfa0cfe498ef56662e6731ed1a133
| 233
|
agda
|
Agda
|
test/Succeed/Issue2155.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue2155.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue2155.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Float
NaN : Float
NaN = primFloatDiv 0.0 0.0
defNaN : NaN ≡ NaN
defNaN = refl
primEqNaN : primFloatEquality NaN NaN ≡ true
primEqNaN = refl
| 16.642857
| 44
| 0.763948
|
d0af3abea33c0dad136dfae6da85ddee873edff9
| 1,051
|
agda
|
Agda
|
test/Succeed/QuoteAbsurdClause.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/QuoteAbsurdClause.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/QuoteAbsurdClause.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Unit
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.List
open import Agda.Builtin.Sigma
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
data ⊥ : Set where
[_] : {A : Set} → A → List A
[ x ] = x ∷ []
vArg : {A : Set} → A → Arg A
vArg x = arg (arg-info visible (modality relevant quantity-ω)) x
macro
getFunDef : Name → Term → TC ⊤
getFunDef f hole = do
function cls ← getDefinition f
where _ → error
niceCls ← quoteTC cls
unify hole niceCls
where postulate error : _
noooo : (A : Set) → ⊥ → A
noooo A ()
-- Quoting the term `noooo Nat x` used to produce an absurd lambda
-- applied to `x`, which should not happen. It should instead simply
-- keep the term `noooo Nat x` as-is.
fooooo : ⊥ → Nat
fooooo x = noooo Nat x
test : getFunDef fooooo ≡
[
clause [ "x" , vArg (def (quote ⊥) []) ] [ vArg (var 0) ]
(def (quote noooo) (vArg (def (quote Nat) []) ∷ vArg (var 0 []) ∷ []))
]
test = refl
| 25.02381
| 88
| 0.617507
|
fb93ae84543a6186d71cd30fbc7433a6b6bbdb32
| 598
|
agda
|
Agda
|
Agda/ProcessAlgebra.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | 2
|
2020-02-03T05:05:52.000Z
|
2020-03-11T10:35:42.000Z
|
Agda/ProcessAlgebra.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | null | null | null |
Agda/ProcessAlgebra.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | 1
|
2019-12-13T04:50:46.000Z
|
2019-12-13T04:50:46.000Z
|
module ProcessAlgebra where
open import Data.Nat
open import Data.Nat.Properties
open import Data.List
data Channel : Set where
ℂ_ : ℕ → Channel
data ℙ : Set₁ where
ν_[_] : List Channel → (Channel → ℙ) → ℙ
B_,_ : Channel → ℙ → ℙ
Send_[_],_ : ∀ {A : Set} → Channel → A → ℙ → ℙ
Recv_,_ : ∀ {A : Set} → Channel → (A → ℙ) → ℙ
_||_ : ℙ → ℙ → ℙ
Dup_ : ℙ → ℙ
Done : ℙ
data Message : Set₁ where
_,_of_ : Channel → (A : Set) → A → Message
data Action : Set₁ where
Out_ : Message → Action
In_ : Message → Action
data Label : Set₁ where
Silent : Label
Act_ : Action → Label
| 19.290323
| 48
| 0.605351
|
4a696337d00519e048501af3c107c0f237dc46cb
| 734
|
agda
|
Agda
|
agda/Everything.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/Everything.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/Everything.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
module Everything where
open import Relation.Binary.Core
postulate A : Set
postulate _≤_ : A → A → Set
postulate tot≤ : Total _≤_
postulate trans≤ : Transitive _≤_
open import BBHeap.Everything _≤_ tot≤ trans≤
open import BHeap.Everything _≤_ tot≤
open import BTree.Complete.Alternative.Correctness {A}
open import BubbleSort.Everything _≤_ tot≤ trans≤
open import Heapsort.Everything _≤_ tot≤ trans≤
open import InsertSort.Everything _≤_ tot≤
open import List.Permutation.Base.Bag A
open import Mergesort.Everything _≤_ tot≤
open import PLRTree.Everything _≤_ tot≤ trans≤
open import Quicksort.Everything _≤_ tot≤ trans≤
open import SelectSort.Everything _≤_ tot≤ trans≤
open import TreeSort.Everything _≤_ tot≤ trans≤
| 22.242424
| 54
| 0.775204
|
cbda517d996a5dbbbc07f074c0f2b393025bab0b
| 382
|
agda
|
Agda
|
Base.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
Base.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
Base.agda
|
DDOtten/M-types
|
5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
module M-types.Base where
open import M-types.Base.Core public
open import M-types.Base.Sum public
open import M-types.Base.Prod public
open import M-types.Base.Eq public
open import M-types.Base.Equi public
open import M-types.Base.Rel public
open import M-types.Base.Contr public
open import M-types.Base.Axiom public
| 29.384615
| 41
| 0.717277
|
396fbc021c94087d58e9df16ebe89fc61ce42245
| 666
|
agda
|
Agda
|
test/Succeed/Issue2386BuiltinEqualitySet.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2386BuiltinEqualitySet.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2386BuiltinEqualitySet.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
-- Relaxing the constraints of BUILTIN EQUALITY
postulate
A : Set
a b : A
P : A → Set
-- Level-polymorphic equality
module P where
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
instance refl : x ≡ x
-- Set-polymorphic equality
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
-- The type of primErase has to match the flavor of EQUALITY
primitive primEraseEquality : ∀ {A : Set} {x y : A} → _≡_ x y → _≡_ x y
testTM : (eq : a ≡ a) → primEraseEquality {x = a} {y = a} eq ≡ refl
testTM _ = refl
-- Testing rewrite
subst : a ≡ b → P a → P b
subst eq p rewrite eq = p
| 20.181818
| 71
| 0.605105
|
20a8c9d333d994ba3823a79d6ee73d5674f75132
| 15,775
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Reflection.agda
|
isovector/agda
|
9a29f3a1f5e24c818bdabbf2c17d0f79887aa8b4
|
[
"BSD-2-Clause"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/Reflection.agda
|
isovector/agda
|
9a29f3a1f5e24c818bdabbf2c17d0f79887aa8b4
|
[
"BSD-2-Clause"
] | null | null | null |
src/data/lib/prim/Agda/Builtin/Reflection.agda
|
isovector/agda
|
9a29f3a1f5e24c818bdabbf2c17d0f79887aa8b4
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.Reflection where
open import Agda.Builtin.Unit
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat
open import Agda.Builtin.Word
open import Agda.Builtin.List
open import Agda.Builtin.String
open import Agda.Builtin.Char
open import Agda.Builtin.Float
open import Agda.Builtin.Int
open import Agda.Builtin.Sigma
open import Agda.Primitive
-- Names --
postulate Name : Set
{-# BUILTIN QNAME Name #-}
primitive
primQNameEquality : Name → Name → Bool
primQNameLess : Name → Name → Bool
primShowQName : Name → String
-- Fixity --
data Associativity : Set where
left-assoc : Associativity
right-assoc : Associativity
non-assoc : Associativity
data Precedence : Set where
related : Float → Precedence
unrelated : Precedence
data Fixity : Set where
fixity : Associativity → Precedence → Fixity
{-# BUILTIN ASSOC Associativity #-}
{-# BUILTIN ASSOCLEFT left-assoc #-}
{-# BUILTIN ASSOCRIGHT right-assoc #-}
{-# BUILTIN ASSOCNON non-assoc #-}
{-# BUILTIN PRECEDENCE Precedence #-}
{-# BUILTIN PRECRELATED related #-}
{-# BUILTIN PRECUNRELATED unrelated #-}
{-# BUILTIN FIXITY Fixity #-}
{-# BUILTIN FIXITYFIXITY fixity #-}
{-# COMPILE GHC Associativity = data MAlonzo.RTE.Assoc (MAlonzo.RTE.LeftAssoc | MAlonzo.RTE.RightAssoc | MAlonzo.RTE.NonAssoc) #-}
{-# COMPILE GHC Precedence = data MAlonzo.RTE.Precedence (MAlonzo.RTE.Related | MAlonzo.RTE.Unrelated) #-}
{-# COMPILE GHC Fixity = data MAlonzo.RTE.Fixity (MAlonzo.RTE.Fixity) #-}
{-# COMPILE JS Associativity = function (x,v) { return v[x](); } #-}
{-# COMPILE JS left-assoc = "left-assoc" #-}
{-# COMPILE JS right-assoc = "right-assoc" #-}
{-# COMPILE JS non-assoc = "non-assoc" #-}
{-# COMPILE JS Precedence =
function (x,v) {
if (x === "unrelated") { return v[x](); } else { return v["related"](x); }} #-}
{-# COMPILE JS related = function(x) { return x; } #-}
{-# COMPILE JS unrelated = "unrelated" #-}
{-# COMPILE JS Fixity = function (x,v) { return v["fixity"](x["assoc"], x["prec"]); } #-}
{-# COMPILE JS fixity = function (x) { return function (y) { return { "assoc": x, "prec": y}; }; } #-}
primitive
primQNameFixity : Name → Fixity
primQNameToWord64s : Name → Σ Word64 (λ _ → Word64)
-- Metavariables --
postulate Meta : Set
{-# BUILTIN AGDAMETA Meta #-}
primitive
primMetaEquality : Meta → Meta → Bool
primMetaLess : Meta → Meta → Bool
primShowMeta : Meta → String
primMetaToNat : Meta → Nat
-- Arguments --
-- Arguments can be (visible), {hidden}, or {{instance}}.
data Visibility : Set where
visible hidden instance′ : Visibility
{-# BUILTIN HIDING Visibility #-}
{-# BUILTIN VISIBLE visible #-}
{-# BUILTIN HIDDEN hidden #-}
{-# BUILTIN INSTANCE instance′ #-}
-- Arguments can be relevant or irrelevant.
data Relevance : Set where
relevant irrelevant : Relevance
{-# BUILTIN RELEVANCE Relevance #-}
{-# BUILTIN RELEVANT relevant #-}
{-# BUILTIN IRRELEVANT irrelevant #-}
-- Arguments also have a quantity.
data Quantity : Set where
quantity-0 quantity-ω : Quantity
{-# BUILTIN QUANTITY Quantity #-}
{-# BUILTIN QUANTITY-0 quantity-0 #-}
{-# BUILTIN QUANTITY-ω quantity-ω #-}
-- Relevance and quantity are combined into a modality.
data Modality : Set where
modality : (r : Relevance) (q : Quantity) → Modality
{-# BUILTIN MODALITY Modality #-}
{-# BUILTIN MODALITY-CONSTRUCTOR modality #-}
data ArgInfo : Set where
arg-info : (v : Visibility) (m : Modality) → ArgInfo
data Arg {a} (A : Set a) : Set a where
arg : (i : ArgInfo) (x : A) → Arg A
{-# BUILTIN ARGINFO ArgInfo #-}
{-# BUILTIN ARGARGINFO arg-info #-}
{-# BUILTIN ARG Arg #-}
{-# BUILTIN ARGARG arg #-}
-- Name abstraction --
data Abs {a} (A : Set a) : Set a where
abs : (s : String) (x : A) → Abs A
{-# BUILTIN ABS Abs #-}
{-# BUILTIN ABSABS abs #-}
-- Literals --
data Literal : Set where
nat : (n : Nat) → Literal
word64 : (n : Word64) → Literal
float : (x : Float) → Literal
char : (c : Char) → Literal
string : (s : String) → Literal
name : (x : Name) → Literal
meta : (x : Meta) → Literal
{-# BUILTIN AGDALITERAL Literal #-}
{-# BUILTIN AGDALITNAT nat #-}
{-# BUILTIN AGDALITWORD64 word64 #-}
{-# BUILTIN AGDALITFLOAT float #-}
{-# BUILTIN AGDALITCHAR char #-}
{-# BUILTIN AGDALITSTRING string #-}
{-# BUILTIN AGDALITQNAME name #-}
{-# BUILTIN AGDALITMETA meta #-}
-- Terms and patterns --
data Term : Set
data Sort : Set
data Pattern : Set
data Clause : Set
Type = Term
Telescope = List (Σ String λ _ → Arg Type)
data Term where
var : (x : Nat) (args : List (Arg Term)) → Term
con : (c : Name) (args : List (Arg Term)) → Term
def : (f : Name) (args : List (Arg Term)) → Term
lam : (v : Visibility) (t : Abs Term) → Term
pat-lam : (cs : List Clause) (args : List (Arg Term)) → Term
pi : (a : Arg Type) (b : Abs Type) → Term
agda-sort : (s : Sort) → Term
lit : (l : Literal) → Term
meta : (x : Meta) → List (Arg Term) → Term
unknown : Term
data Sort where
set : (t : Term) → Sort
lit : (n : Nat) → Sort
prop : (t : Term) → Sort
propLit : (n : Nat) → Sort
inf : (n : Nat) → Sort
unknown : Sort
data Pattern where
con : (c : Name) (ps : List (Arg Pattern)) → Pattern
dot : (t : Term) → Pattern
var : (x : Nat) → Pattern
lit : (l : Literal) → Pattern
proj : (f : Name) → Pattern
absurd : (x : Nat) → Pattern -- absurd patterns counts as variables
data Clause where
clause : (tel : Telescope) (ps : List (Arg Pattern)) (t : Term) → Clause
absurd-clause : (tel : Telescope) (ps : List (Arg Pattern)) → Clause
{-# BUILTIN AGDATERM Term #-}
{-# BUILTIN AGDASORT Sort #-}
{-# BUILTIN AGDAPATTERN Pattern #-}
{-# BUILTIN AGDACLAUSE Clause #-}
{-# BUILTIN AGDATERMVAR var #-}
{-# BUILTIN AGDATERMCON con #-}
{-# BUILTIN AGDATERMDEF def #-}
{-# BUILTIN AGDATERMMETA meta #-}
{-# BUILTIN AGDATERMLAM lam #-}
{-# BUILTIN AGDATERMEXTLAM pat-lam #-}
{-# BUILTIN AGDATERMPI pi #-}
{-# BUILTIN AGDATERMSORT agda-sort #-}
{-# BUILTIN AGDATERMLIT lit #-}
{-# BUILTIN AGDATERMUNSUPPORTED unknown #-}
{-# BUILTIN AGDASORTSET set #-}
{-# BUILTIN AGDASORTLIT lit #-}
{-# BUILTIN AGDASORTPROP prop #-}
{-# BUILTIN AGDASORTPROPLIT propLit #-}
{-# BUILTIN AGDASORTINF inf #-}
{-# BUILTIN AGDASORTUNSUPPORTED unknown #-}
{-# BUILTIN AGDAPATCON con #-}
{-# BUILTIN AGDAPATDOT dot #-}
{-# BUILTIN AGDAPATVAR var #-}
{-# BUILTIN AGDAPATLIT lit #-}
{-# BUILTIN AGDAPATPROJ proj #-}
{-# BUILTIN AGDAPATABSURD absurd #-}
{-# BUILTIN AGDACLAUSECLAUSE clause #-}
{-# BUILTIN AGDACLAUSEABSURD absurd-clause #-}
-- Definitions --
data Definition : Set where
function : (cs : List Clause) → Definition
data-type : (pars : Nat) (cs : List Name) → Definition
record-type : (c : Name) (fs : List (Arg Name)) → Definition
data-cons : (d : Name) → Definition
axiom : Definition
prim-fun : Definition
{-# BUILTIN AGDADEFINITION Definition #-}
{-# BUILTIN AGDADEFINITIONFUNDEF function #-}
{-# BUILTIN AGDADEFINITIONDATADEF data-type #-}
{-# BUILTIN AGDADEFINITIONRECORDDEF record-type #-}
{-# BUILTIN AGDADEFINITIONDATACONSTRUCTOR data-cons #-}
{-# BUILTIN AGDADEFINITIONPOSTULATE axiom #-}
{-# BUILTIN AGDADEFINITIONPRIMITIVE prim-fun #-}
-- Errors --
data ErrorPart : Set where
strErr : String → ErrorPart
termErr : Term → ErrorPart
nameErr : Name → ErrorPart
{-# BUILTIN AGDAERRORPART ErrorPart #-}
{-# BUILTIN AGDAERRORPARTSTRING strErr #-}
{-# BUILTIN AGDAERRORPARTTERM termErr #-}
{-# BUILTIN AGDAERRORPARTNAME nameErr #-}
-- TC monad --
postulate
TC : ∀ {a} → Set a → Set a
returnTC : ∀ {a} {A : Set a} → A → TC A
bindTC : ∀ {a b} {A : Set a} {B : Set b} → TC A → (A → TC B) → TC B
unify : Term → Term → TC ⊤
typeError : ∀ {a} {A : Set a} → List ErrorPart → TC A
inferType : Term → TC Type
checkType : Term → Type → TC Term
normalise : Term → TC Term
reduce : Term → TC Term
catchTC : ∀ {a} {A : Set a} → TC A → TC A → TC A
quoteTC : ∀ {a} {A : Set a} → A → TC Term
unquoteTC : ∀ {a} {A : Set a} → Term → TC A
quoteωTC : ∀ {A : Setω} → A → TC Term
getContext : TC Telescope
extendContext : ∀ {a} {A : Set a} → String → Arg Type → TC A → TC A
inContext : ∀ {a} {A : Set a} → Telescope → TC A → TC A
freshName : String → TC Name
declareDef : Arg Name → Type → TC ⊤
declarePostulate : Arg Name → Type → TC ⊤
defineFun : Name → List Clause → TC ⊤
getType : Name → TC Type
getDefinition : Name → TC Definition
blockOnMeta : ∀ {a} {A : Set a} → Meta → TC A
commitTC : TC ⊤
isMacro : Name → TC Bool
-- If the argument is 'true' makes the following primitives also normalise
-- their results: inferType, checkType, quoteTC, getType, and getContext
withNormalisation : ∀ {a} {A : Set a} → Bool → TC A → TC A
-- Makes the following primitives to reconstruct hidden arguments
-- getDefinition, normalise, reduce, inferType, checkType and getContext
withReconstructed : ∀ {a} {A : Set a} → TC A → TC A
-- Prints the third argument if the corresponding verbosity level is turned
-- on (with the -v flag to Agda).
debugPrint : String → Nat → List ErrorPart → TC ⊤
-- Only allow reduction of specific definitions while executing the TC computation
onlyReduceDefs : ∀ {a} {A : Set a} → List Name → TC A → TC A
-- Don't allow reduction of specific definitions while executing the TC computation
dontReduceDefs : ∀ {a} {A : Set a} → List Name → TC A → TC A
-- Fail if the given computation gives rise to new, unsolved
-- "blocking" constraints.
noConstraints : ∀ {a} {A : Set a} → TC A → TC A
-- Run the given TC action and return the first component. Resets to
-- the old TC state if the second component is 'false', or keep the
-- new TC state if it is 'true'.
runSpeculative : ∀ {a} {A : Set a} → TC (Σ A λ _ → Bool) → TC A
-- Get a list of all possible instance candidates for the given meta
-- variable (it does not have to be an instance meta).
getInstances : Meta → TC (List Term)
{-# BUILTIN AGDATCM TC #-}
{-# BUILTIN AGDATCMRETURN returnTC #-}
{-# BUILTIN AGDATCMBIND bindTC #-}
{-# BUILTIN AGDATCMUNIFY unify #-}
{-# BUILTIN AGDATCMTYPEERROR typeError #-}
{-# BUILTIN AGDATCMINFERTYPE inferType #-}
{-# BUILTIN AGDATCMCHECKTYPE checkType #-}
{-# BUILTIN AGDATCMNORMALISE normalise #-}
{-# BUILTIN AGDATCMREDUCE reduce #-}
{-# BUILTIN AGDATCMCATCHERROR catchTC #-}
{-# BUILTIN AGDATCMQUOTETERM quoteTC #-}
{-# BUILTIN AGDATCMUNQUOTETERM unquoteTC #-}
{-# BUILTIN AGDATCMQUOTEOMEGATERM quoteωTC #-}
{-# BUILTIN AGDATCMGETCONTEXT getContext #-}
{-# BUILTIN AGDATCMEXTENDCONTEXT extendContext #-}
{-# BUILTIN AGDATCMINCONTEXT inContext #-}
{-# BUILTIN AGDATCMFRESHNAME freshName #-}
{-# BUILTIN AGDATCMDECLAREDEF declareDef #-}
{-# BUILTIN AGDATCMDECLAREPOSTULATE declarePostulate #-}
{-# BUILTIN AGDATCMDEFINEFUN defineFun #-}
{-# BUILTIN AGDATCMGETTYPE getType #-}
{-# BUILTIN AGDATCMGETDEFINITION getDefinition #-}
{-# BUILTIN AGDATCMBLOCKONMETA blockOnMeta #-}
{-# BUILTIN AGDATCMCOMMIT commitTC #-}
{-# BUILTIN AGDATCMISMACRO isMacro #-}
{-# BUILTIN AGDATCMWITHNORMALISATION withNormalisation #-}
{-# BUILTIN AGDATCMDEBUGPRINT debugPrint #-}
{-# BUILTIN AGDATCMONLYREDUCEDEFS onlyReduceDefs #-}
{-# BUILTIN AGDATCMDONTREDUCEDEFS dontReduceDefs #-}
{-# BUILTIN AGDATCMWITHRECONSPARAMS withReconstructed #-}
{-# BUILTIN AGDATCMNOCONSTRAINTS noConstraints #-}
{-# BUILTIN AGDATCMRUNSPECULATIVE runSpeculative #-}
{-# BUILTIN AGDATCMGETINSTANCES getInstances #-}
-- All the TC primitives are compiled to functions that return
-- undefined, rather than just undefined, in an attempt to make sure
-- that code will run properly.
{-# COMPILE JS returnTC = _ => _ => _ => undefined #-}
{-# COMPILE JS bindTC = _ => _ => _ => _ =>
_ => _ => undefined #-}
{-# COMPILE JS unify = _ => _ => undefined #-}
{-# COMPILE JS typeError = _ => _ => _ => undefined #-}
{-# COMPILE JS inferType = _ => undefined #-}
{-# COMPILE JS checkType = _ => _ => undefined #-}
{-# COMPILE JS normalise = _ => undefined #-}
{-# COMPILE JS reduce = _ => undefined #-}
{-# COMPILE JS catchTC = _ => _ => _ => _ => undefined #-}
{-# COMPILE JS quoteTC = _ => _ => _ => undefined #-}
{-# COMPILE JS unquoteTC = _ => _ => _ => undefined #-}
{-# COMPILE JS quoteωTC = _ => _ => undefined #-}
{-# COMPILE JS getContext = undefined #-}
{-# COMPILE JS extendContext = _ => _ => _ => _ => _ => undefined #-}
{-# COMPILE JS inContext = _ => _ => _ => _ => undefined #-}
{-# COMPILE JS freshName = _ => undefined #-}
{-# COMPILE JS declareDef = _ => _ => undefined #-}
{-# COMPILE JS declarePostulate = _ => _ => undefined #-}
{-# COMPILE JS defineFun = _ => _ => undefined #-}
{-# COMPILE JS getType = _ => undefined #-}
{-# COMPILE JS getDefinition = _ => undefined #-}
{-# COMPILE JS blockOnMeta = _ => _ => _ => undefined #-}
{-# COMPILE JS commitTC = undefined #-}
{-# COMPILE JS isMacro = _ => undefined #-}
{-# COMPILE JS withNormalisation = _ => _ => _ => _ => undefined #-}
{-# COMPILE JS withReconstructed = _ => _ => _ => undefined #-}
{-# COMPILE JS debugPrint = _ => _ => _ => undefined #-}
{-# COMPILE JS onlyReduceDefs = _ => _ => _ => _ => undefined #-}
{-# COMPILE JS dontReduceDefs = _ => _ => _ => _ => undefined #-}
{-# COMPILE JS noConstraints = _ => _ => _ => undefined #-}
{-# COMPILE JS runSpeculative = _ => _ => _ => undefined #-}
{-# COMPILE JS getInstances = _ => undefined #-}
| 40.038071
| 130
| 0.553344
|
3922e9174791507a64f86c766a954b7adaa1fce3
| 311
|
agda
|
Agda
|
test/Fail/Errors/Issue84.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Fail/Errors/Issue84.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Fail/Errors/Issue84.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
postulate
D : Set
_≡_ : D → D → Set
a b : D
postulate p : a ≡ b
{-# ATP axiom p #-}
postulate foo : a ≡ b
{-# ATP prove foo #-}
| 19.4375
| 42
| 0.4791
|
1cebd6cc93e3c27beb7afe0a18de1e58ec7c96f2
| 1,291
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Transrightidentity.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Transrightidentity.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/Transrightidentity.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Leftunit
open import Oscar.Class.Reflexivity
open import Oscar.Class.Transitivity
module Oscar.Class.Transrightidentity where
module Transrightidentity
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
{ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ)
(ε : Reflexivity.type _∼_)
(transitivity : Transitivity.type _∼_)
= ℭLASS (_∼_ ,, (λ {x y} → _∼̇_ {x} {y}) ,, (λ {x} → ε {x}) ,, (λ {x y z} → transitivity {x} {y} {z}))
(∀ {x y} {f : x ∼ y} → Leftunit.type _∼̇_ ε transitivity f)
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
{ℓ} {_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ}
{ε : Reflexivity.type _∼_}
{transitivity : Transitivity.type _∼_}
where
transrightidentity = Transrightidentity.method _∼_ _∼̇_ ε transitivity
instance
toLeftunitFromTransrightidentity :
⦃ _ : Transrightidentity.class _∼_ _∼̇_ ε transitivity ⦄
→ ∀ {x y} {f : x ∼ y} → Leftunit.class _∼̇_ ε transitivity f
toLeftunitFromTransrightidentity .⋆ = transrightidentity
module Transrightidentity!
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
{ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ)
⦃ _ : Reflexivity.class _∼_ ⦄
⦃ _ : Transitivity.class _∼_ ⦄
= Transrightidentity (_∼_) (_∼̇_) reflexivity transitivity
| 32.275
| 104
| 0.597986
|
dcc396fd7702724c7d5dbb61bc3ecf950d6f3ead
| 10,654
|
agda
|
Agda
|
agda/sn-calculus-confluence/rec.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/sn-calculus-confluence/rec.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/sn-calculus-confluence/rec.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module sn-calculus-confluence.rec where
open import Data.Nat using (_+_)
open import Function using (_∋_ ; _∘_)
open import Data.Nat.Properties.Simple using ( +-comm ; +-assoc )
open import utility
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Environment as Env
open import Esterel.Context
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.List
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.Empty
open import sn-calculus
open import context-properties
open import Esterel.Lang.Binding
open import Data.Maybe using ( just )
open import Data.List.Any
open import Data.List.Any.Properties
open import Data.FiniteMap
import Data.OrderedListMap as OMap
open import Data.Nat as Nat using (ℕ)
open import Esterel.Variable.Signal as Signal
using (Signal)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar)
open import Esterel.Variable.Sequential as SeqVar
open import sn-calculus-confluence.helper
open import sn-calculus-confluence.recrec
ρ-conf-rec : ∀{θ El Er ql qr i oli ori qro qlo FV BV θl θr A Al Ar}
→ CorrectBinding (ρ⟨ θ , A ⟩· i) FV BV
→ (ieql : i ≐ El ⟦ ql ⟧e)
→ (ieqr : i ≐ Er ⟦ qr ⟧e)
→ El a~ Er
→ (rl : (ρ⟨ θ , A ⟩· i) sn⟶₁ (ρ⟨ θl , Al ⟩· oli))
→ (rr : (ρ⟨ θ , A ⟩· i) sn⟶₁ (ρ⟨ θr , Ar ⟩· ori))
→ (olieq : oli ≐ El ⟦ qlo ⟧e)
→ (orieq : ori ≐ Er ⟦ qro ⟧e)
→ (->E-view rl ieql olieq)
→ (->E-view rr ieqr orieq)
→ (
Σ[ θo ∈ Env ]
Σ[ Ao ∈ Ctrl ]
Σ[ si ∈ Term ]
Σ[ Elo ∈ EvaluationContext ]
Σ[ Ero ∈ EvaluationContext ]
Σ[ oorieq ∈ ori ≐ Elo ⟦ ql ⟧e ]
Σ[ oolieq ∈ oli ≐ Ero ⟦ qr ⟧e ]
Σ[ sireq ∈ (si ≐ Elo ⟦ qlo ⟧e ) ]
Σ[ sileq ∈ (si ≐ Ero ⟦ qro ⟧e ) ]
Σ[ redl ∈ ((ρ⟨ θl , Al ⟩· oli) sn⟶₁ (ρ⟨ θo , Ao ⟩· si )) ]
Σ[ redr ∈ ((ρ⟨ θr , Ar ⟩· ori) sn⟶₁ (ρ⟨ θo , Ao ⟩· si )) ]
((->E-view redl oolieq sileq) × (->E-view redr oorieq sireq)))
ρ-conf-rec {p₂} {El = El@.(epar₂ _ ∷ _)} {Er@.(epar₁ _ ∷ _)} {i = .(_ ∥ _)} cb (depar₂ ieqr) (depar₁ ieql) par redl redr olieq orieq viewl viewr with ρ-conf-rec2{El = El}{Er} cb (depar₂ ieqr) (depar₁ ieql) par redl redr olieq orieq viewl viewr refl refl
... | (θo , Ao , whatever , Erl , Ero , thig , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro , _) = θo , Ao , whatever , Erl , Ero , thig , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro
ρ-conf-rec {p₂} {El = (epar₁ q ∷ El)} {(epar₂ p ∷ Er)} {i = .(_ ∥ _)}{oli = (olp ∥ .q)}{ori = (.p ∥ orq)} cb@(CBρ (CBpar cbl cbr a b c d)) (depar₁ ieql) (depar₂ ieqr) par2 redl redr (depar₁ olieq) (depar₂ orieq) viewl viewr
with unwrap-rho redl (depar₁ ieql) (depar₁ olieq) ieql olieq viewl | unwrap-rho redr (depar₂ ieqr) (depar₂ orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with wrap-rho redli ieql olieq viewli (epar₂ q) (depar₂ ieql) (depar₂ olieq) | wrap-rho redri ieqr orieq viewri (epar₁ p) (depar₁ ieqr) (depar₁ orieq)
... | (redl2 , viewl2) | (redr2 , viewr2) with ρ-conf-rec2{El = epar₂ q ∷ El}{epar₁ p ∷ Er}{oli = oli2}{ori = ori2} (CBρ (CBpar cbr cbl (distinct-sym a) (distinct-sym c) (distinct-sym b) (distinct'-sym d))) (depar₂ ieql) (depar₁ ieqr) par redl2 redr2 (depar₂ olieq) (depar₁ orieq) viewl2 viewr2 refl refl
where
oli2 = Term ∋ (q ∥ olp)
ori2 = orq ∥ p
... | (θo , Ao , (sil@.orq ∥ sir@.olp) , (epar₂ _ ∷ Erl) , (epar₁ _ ∷ Ero) , (depar₂ oorieq) , (depar₁ oolieq) , (depar₂ sireq) , (depar₁ sileq) , rlout , rrout , viewlo , viewro , ((.Erl , .Ero , _ , _) , refl , refl))
with unwrap-rho rlout (depar₁ oolieq) (depar₁ sileq) oolieq sileq viewlo | unwrap-rho rrout (depar₂ oorieq) (depar₂ sireq) oorieq sireq viewro
... | (roli , roliview) | (rori , roriview)
with wrap-rho roli oolieq sileq roliview (epar₂ sir) (depar₂ oolieq) (depar₂ sileq) | wrap-rho rori oorieq sireq roriview (epar₁ sil) (depar₁ oorieq) (depar₁ sireq)
... | (rolo , roloview) | (roro , roroview) = θo , Ao , sir ∥ sil , epar₁ orq ∷ Erl ,
epar₂ olp ∷ Ero ,
depar₁ oorieq ,
depar₂ oolieq ,
depar₁ sireq , depar₂ sileq , rolo , roro , roloview , roroview -- _ , _ , _ , _ , _ , rolo , roro , roloview , roroview -- {! !}
ρ-conf-rec {El = epar₁ q ∷ El} {epar₁ .q ∷ Er} {ql} {qr} {.(_ ∥ q)} (CBρ (CBpar cb cb₁ x x₁ x₂ x₃)) (depar₁ ieql) (depar₁ ieqr) (parr a~~) redl redr (depar₁ olieq) (depar₁ orieq) viewl viewr
with unwrap-rho redl (depar₁ ieql) (depar₁ olieq) ieql olieq viewl | unwrap-rho redr (depar₁ ieqr) (depar₁ orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with ρ-conf-rec (CBρ cb) ieql ieqr a~~ redli redri olieq orieq viewli viewri
... | ( θo , Ao , si , Elo , Ero , oorieq , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro )
with wrap-rho rlout oolieq sileq viewlo (epar₁ q) (depar₁ oolieq) (depar₁ sileq) | wrap-rho rrout oorieq sireq viewro (epar₁ q) (depar₁ oorieq) (depar₁ sireq)
... | (rol , rolview) | (ror , rorview) = θo , Ao , si ∥ q , (epar₁ q) ∷ Elo , (epar₁ q) ∷ Ero , depar₁ oorieq ,
depar₁ oolieq , depar₁ sireq , depar₁ sileq , rol , ror , rolview , rorview
ρ-conf-rec {El = (epar₂ p ∷ El)} {(epar₂ .p ∷ Er)} {i = .(_ ∥ _)} (CBρ (CBpar cb₁ cb x x₁ x₂ x₃)) (depar₂ ieql) (depar₂ ieqr) (parl a~~) redl redr (depar₂ olieq) (depar₂ orieq) viewl viewr
with unwrap-rho redl (depar₂ ieql) (depar₂ olieq) ieql olieq viewl | unwrap-rho redr (depar₂ ieqr) (depar₂ orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with ρ-conf-rec (CBρ cb) ieql ieqr a~~ redli redri olieq orieq viewli viewri
... | ( θo , Ao , si , Elo , Ero , oorieq , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro )
with wrap-rho rlout oolieq sileq viewlo (epar₂ p) (depar₂ oolieq) (depar₂ sileq) | wrap-rho rrout oorieq sireq viewro (epar₂ p) (depar₂ oorieq) (depar₂ sireq)
... | (rol , rolview) | (ror , rorview) = θo , Ao , p ∥ si , (epar₂ p) ∷ Elo , (epar₂ p) ∷ Ero , depar₂ oorieq ,
depar₂ oolieq , depar₂ sireq , depar₂ sileq , rol , ror , rolview , rorview
ρ-conf-rec {El = (eseq q ∷ El)} {(eseq .q ∷ Er)} {i = .(_ >> q)} (CBρ (CBseq cb cb₁ x)) (deseq ieql) (deseq ieqr) (seq a~~) redl redr (deseq olieq) (deseq orieq) viewl viewr
with unwrap-rho redl (deseq ieql) (deseq olieq) ieql olieq viewl | unwrap-rho redr (deseq ieqr) (deseq orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with ρ-conf-rec (CBρ cb) ieql ieqr a~~ redli redri olieq orieq viewli viewri
... | ( θo , Ao , si , Elo , Ero , oorieq , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro )
with wrap-rho rlout oolieq sileq viewlo (eseq q) (deseq oolieq) (deseq sileq) | wrap-rho rrout oorieq sireq viewro (eseq q) (deseq oorieq) (deseq sireq)
... | (rol , rolview) | (ror , rorview) = θo , Ao , (si >> q) , (eseq q) ∷ Elo , (eseq q) ∷ Ero , deseq oorieq ,
deseq oolieq , deseq sireq , deseq sileq , rol , ror , rolview , rorview
ρ-conf-rec {El = (eloopˢ q ∷ El)} {(eloopˢ .q ∷ Er)} {i = .(loopˢ _ q)} (CBρ (CBloopˢ cb cb₁ x _)) (deloopˢ ieql) (deloopˢ ieqr) (loopˢ a~~) redl redr (deloopˢ olieq) (deloopˢ orieq) viewl viewr
with unwrap-rho redl (deloopˢ ieql) (deloopˢ olieq) ieql olieq viewl | unwrap-rho redr (deloopˢ ieqr) (deloopˢ orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with ρ-conf-rec (CBρ cb) ieql ieqr a~~ redli redri olieq orieq viewli viewri
... | ( θo , Ao , si , Elo , Ero , oorieq , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro )
with wrap-rho rlout oolieq sileq viewlo (eloopˢ q) (deloopˢ oolieq) (deloopˢ sileq) | wrap-rho rrout oorieq sireq viewro (eloopˢ q) (deloopˢ oorieq) (deloopˢ sireq)
... | (rol , rolview) | (ror , rorview) = θo , Ao , (loopˢ si q) , (eloopˢ q) ∷ Elo , (eloopˢ q) ∷ Ero , deloopˢ oorieq ,
deloopˢ oolieq , deloopˢ sireq , deloopˢ sileq , rol , ror , rolview , rorview
ρ-conf-rec {El = (esuspend S ∷ El)} {(esuspend .S ∷ Er)} {i = .(suspend _ _)} (CBρ (CBsusp cb x)) (desuspend ieql) (desuspend ieqr) (susp a~~) redl redr (desuspend olieq) (desuspend orieq) viewl viewr
with unwrap-rho redl (desuspend ieql) (desuspend olieq) ieql olieq viewl | unwrap-rho redr (desuspend ieqr) (desuspend orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with ρ-conf-rec (CBρ cb) ieql ieqr a~~ redli redri olieq orieq viewli viewri
... | ( θo , Ao , si , Elo , Ero , oorieq , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro )
with wrap-rho rlout oolieq sileq viewlo (esuspend S) (desuspend oolieq) (desuspend sileq) | wrap-rho rrout oorieq sireq viewro (esuspend S) (desuspend oorieq) (desuspend sireq)
... | (rol , rolview) | (ror , rorview) = θo , Ao , (suspend si S) , (esuspend S) ∷ Elo , (esuspend S) ∷ Ero , desuspend oorieq ,
desuspend oolieq , desuspend sireq , desuspend sileq , rol , ror , rolview , rorview
ρ-conf-rec {El = (etrap ∷ El)} {(etrap ∷ Er)} {i = .(trap _)} (CBρ (CBtrap cb)) (detrap ieql) (detrap ieqr) (trp a~~) redl redr (detrap olieq) (detrap orieq) viewl viewr
with unwrap-rho redl (detrap ieql) (detrap olieq) ieql olieq viewl | unwrap-rho redr (detrap ieqr) (detrap orieq) ieqr orieq viewr
... | (redli , viewli) | (redri , viewri) with ρ-conf-rec (CBρ cb) ieql ieqr a~~ redli redri olieq orieq viewli viewri
... | ( θo , Ao , si , Elo , Ero , oorieq , oolieq , sireq , sileq , rlout , rrout , viewlo , viewro )
with wrap-rho rlout oolieq sileq viewlo (etrap) (detrap oolieq) (detrap sileq) | wrap-rho rrout oorieq sireq viewro (etrap) (detrap oorieq) (detrap sireq)
... | (rol , rolview) | (ror , rorview) = θo , Ao , (trap si) , (etrap) ∷ Elo , (etrap) ∷ Ero , detrap oorieq ,
detrap oolieq , detrap sireq , detrap sileq , rol , ror , rolview , rorview
| 81.953846
| 305
| 0.585508
|
dfa461a09e63b5206e6570e6dba7a29c563b7f4d
| 1,431
|
agda
|
Agda
|
Numeral/Natural/Relation/Order/Existence.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Relation/Order/Existence.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Relation/Order/Existence.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Relation.Order.Existence where
import Lvl
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
import Numeral.Natural.Relation.Order as [≤def]
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Relator.Ordering
open import Structure.Function
open import Structure.Function.Domain
open import Syntax.Function
open import Syntax.Transitivity
_≤_ : ℕ → ℕ → Stmt
_≤_ a b = ∃{Obj = ℕ}(n ↦ a + n ≡ b)
_<_ : ℕ → ℕ → Stmt
_<_ a b = (𝐒(a) ≤ b)
open From-[≤][<] (_≤_) (_<_) public
[≤]-with-[𝐒] : ∀{a b : ℕ} → (a ≤ b) → (𝐒(a) ≤ 𝐒(b))
[≤]-with-[𝐒] {a} {b} ([∃]-intro n ⦃ f ⦄) =
[∃]-intro n ⦃
𝐒(a) + n 🝖[ _≡_ ]-[ [+]-stepₗ {a} {n} ]
𝐒(a + n) 🝖[ _≡_ ]-[ congruence₁(𝐒) f ]
𝐒(b) 🝖-end
⦄
[≤]-equivalence : ∀{x y} → (x ≤ y) ↔ (x [≤def].≤ y)
[≤]-equivalence{x}{y} = [↔]-intro (l{x}{y}) (r{x}{y}) where
l : ∀{x y} → (x ≤ y) ← (x [≤def].≤ y)
l{𝟎} {y} ([≤def].min) = [∃]-intro(y) ⦃ [≡]-intro ⦄
l{𝐒(x)}{𝟎} ()
l{𝐒(x)}{𝐒(y)} ([≤def].succ proof) = [≤]-with-[𝐒] {x}{y} (l{x}{y} (proof))
r : ∀{x y} → (x ≤ y) → (x [≤def].≤ y)
r{𝟎} {y} ([∃]-intro(z) ⦃ 𝟎+z≡y ⦄) = [≤def].min
r{𝐒(x)}{𝟎} ([∃]-intro(z) ⦃ ⦄)
r{𝐒(x)}{𝐒(y)} ([∃]-intro(z) ⦃ 𝐒x+z≡𝐒y ⦄) = [≤def].succ (r{x}{y} ([∃]-intro(z) ⦃ injective(𝐒)(𝐒x+z≡𝐒y) ⦄))
| 31.108696
| 107
| 0.533194
|
dfcaccd5598d823b0d791e0d97b48c4215907e6e
| 5,551
|
agda
|
Agda
|
Cubical/Categories/DistLatticeSheaf.agda
|
mzeuner/cubical
|
63c770b381039c0132c17d7913f4566b35984701
|
[
"MIT"
] | null | null | null |
Cubical/Categories/DistLatticeSheaf.agda
|
mzeuner/cubical
|
63c770b381039c0132c17d7913f4566b35984701
|
[
"MIT"
] | null | null | null |
Cubical/Categories/DistLatticeSheaf.agda
|
mzeuner/cubical
|
63c770b381039c0132c17d7913f4566b35984701
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.DistLatticeSheaf where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Powerset
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary.Poset
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Semilattice
open import Cubical.Algebra.Lattice
open import Cubical.Algebra.DistLattice
open import Cubical.Algebra.DistLattice.Basis
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Limits.Pullback
open import Cubical.Categories.Limits.Terminal
open import Cubical.Categories.Instances.Functors
open import Cubical.Categories.Instances.CommRings
open import Cubical.Categories.Instances.Poset
open import Cubical.Categories.Instances.Semilattice
open import Cubical.Categories.Instances.Lattice
open import Cubical.Categories.Instances.DistLattice
private
variable
ℓ ℓ' ℓ'' : Level
module _ (L : DistLattice ℓ) (C : Category ℓ' ℓ'') (T : Terminal C) where
open Category hiding (_⋆_)
open Functor
open DistLatticeStr (snd L)
open MeetSemilattice (Lattice→MeetSemilattice (DistLattice→Lattice L))
open PosetStr (IndPoset .snd)
𝟙 : ob C
𝟙 = terminalOb C T
DLCat : Category ℓ ℓ
DLCat = DistLatticeCategory L
open Category DLCat
-- C-valued presheaves on a distributive lattice
DLPreSheaf : Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'')
DLPreSheaf = Functor (DLCat ^op) C
hom-∨₁ : (x y : L .fst) → DLCat [ x , x ∨l y ]
hom-∨₁ x y = goal
where
-- TODO: isn't the fixity of the operators a bit weird?
goal : x ∧l (x ∨l y) ≡ x
goal = ∧lAbsorb∨l x y
hom-∨₂ : (x y : L .fst) → DLCat [ y , x ∨l y ]
hom-∨₂ x y = goal
where
-- TODO: upstream this kind of simple lemmas? Or are they already somewhere?
goal : y ∧l (x ∨l y) ≡ y
goal = cong (y ∧l_) (∨lComm x y) ∙ ∧lAbsorb∨l y x
hom-∧₁ : (x y : L .fst) → DLCat [ x ∧l y , x ]
hom-∧₁ x y = goal
where
goal : (x ∧l y) ∧l x ≡ x ∧l y
goal = ∧lComm (x ∧l y) x ∙ ∧lAssoc x x y ∙ cong (_∧l y) (∧lIdem x)
hom-∧₂ : (x y : L .fst) → DLCat [ x ∧l y , y ]
hom-∧₂ x y = goal
where
goal : (x ∧l y) ∧l y ≡ x ∧l y
goal = sym (∧lAssoc x y y) ∙ cong (x ∧l_) (∧lIdem y)
{-
x ∧ y ----→ y
| |
| sq |
V V
x ----→ x ∨ y
-}
sq : (x y : L .fst) → hom-∧₂ x y ⋆ hom-∨₂ x y ≡ hom-∧₁ x y ⋆ hom-∨₁ x y
sq x y = is-prop-valued (x ∧l y) (x ∨l y) (hom-∧₂ x y ⋆ hom-∨₂ x y) (hom-∧₁ x y ⋆ hom-∨₁ x y)
{-
F(x ∨ y) ----→ F(y)
| |
| Fsq |
V V
F(x) ------→ F(x ∧ y)
-}
Fsq : (F : DLPreSheaf) (x y : L .fst)
→ F .F-hom (hom-∨₂ x y) ⋆⟨ C ⟩ F .F-hom (hom-∧₂ x y) ≡
F .F-hom (hom-∨₁ x y) ⋆⟨ C ⟩ F .F-hom (hom-∧₁ x y)
Fsq F x y = sym (F-seq F (hom-∨₂ x y) (hom-∧₂ x y))
∙∙ cong (F .F-hom) (sq x y)
∙∙ F-seq F (hom-∨₁ x y) (hom-∧₁ x y)
isDLSheaf : (F : DLPreSheaf) → Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'')
isDLSheaf F = (F-ob F 0l ≡ 𝟙)
× ((x y : L .fst) → isPullback C _ _ _ (Fsq F x y))
-- TODO: might be better to define this as a record
DLSheaf : Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'')
DLSheaf = Σ[ F ∈ DLPreSheaf ] isDLSheaf F
module Lemma1 (L : DistLattice ℓ) (C : Category ℓ' ℓ'') (T : Terminal C) (L' : ℙ (fst L)) (hB : IsBasis L L') where
open Category hiding (_⋆_)
open Functor
open DistLatticeStr (snd L)
open IsBasis hB
isDLBasisSheaf : (F : DLPreSheaf L C T) → Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'')
isDLBasisSheaf F = (F-ob F 0l ≡ 𝟙 L C T)
× ((x y : L .fst) → x ∈ L' → y ∈ L' → isPullback C _ _ _ (Fsq L C T F x y))
DLBasisSheaf : Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'')
DLBasisSheaf = Σ[ F ∈ DLPreSheaf L C T ] isDLBasisSheaf F
-- To prove the statement we probably need that C is:
-- 1. univalent
-- 2. has finite limits (or pullbacks and a terminal object)
-- 3. isGroupoid (C .ob)
-- The last point is not strictly necessary, but we have to have some
-- control over the hLevel as we want to write F(x) in terms of its
-- basis cover which is information hidden under a prop truncation...
-- Alternatively we just prove the statement for C = CommRingsCategory
-- TODO: is unique existence expressed like this what we want?
-- statement : (F' : DLBasisSheaf)
-- → ∃![ F ∈ DLSheaf L C T ] ((x : fst L) → (x ∈ L') → CatIso C (F-ob (fst F) x) (F-ob (fst F') x)) -- TODO: if C is univalent the CatIso could be ≡?
-- statement (F' , h1 , hPb) = ?
-- It might be easier to prove all of these if we use the definition
-- in terms of particular limits instead
-- Scrap zone:
-- -- Sublattices: upstream later
-- record isSublattice (L' : ℙ (fst L)) : Type ℓ where
-- field
-- 1l-closed : 1l ∈ L'
-- 0l-closed : 0l ∈ L'
-- ∧l-closed : {x y : fst L} → x ∈ L' → y ∈ L' → x ∧l y ∈ L'
-- ∨l-closed : {x y : fst L} → x ∈ L' → y ∈ L' → x ∨l y ∈ L'
-- open isSublattice
-- Sublattice : Type (ℓ-suc ℓ)
-- Sublattice = Σ[ L' ∈ ℙ (fst L) ] isSublattice L'
-- restrictDLSheaf : DLSheaf → Sublattice → DLSheaf
-- F-ob (fst (restrictDLSheaf F (L' , HL'))) x = {!F-ob (fst F) x!} -- Hmm, not nice...
-- F-hom (fst (restrictDLSheaf F L')) = {!!}
-- F-id (fst (restrictDLSheaf F L')) = {!!}
-- F-seq (fst (restrictDLSheaf F L')) = {!!}
-- snd (restrictDLSheaf F L') = {!!}
| 32.846154
| 161
| 0.591245
|
fb25a0efc94f509358c6efd39405f2877f938d5c
| 658
|
agda
|
Agda
|
src/fot/FOTC/Program/Iter0/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/Iter0/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/Iter0/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Some properties of the function iter₀
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Iter0.PropertiesATP where
open import FOTC.Program.Iter0.Iter0
open import FOTC.Base
open import FOTC.Base.List
------------------------------------------------------------------------------
postulate iter₀-0 : ∀ f → iter₀ f zero ≡ []
{-# ATP prove iter₀-0 #-}
| 31.333333
| 78
| 0.399696
|
4a52f6dbb766b93c52da45e147f606debea3cbde
| 1,116
|
agda
|
Agda
|
src/Types/Tail1.agda
|
peterthiemann/dual-session
|
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
|
[
"BSD-2-Clause"
] | 1
|
2022-02-13T05:43:25.000Z
|
2022-02-13T05:43:25.000Z
|
src/Types/Tail1.agda
|
peterthiemann/dual-session
|
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
|
[
"BSD-2-Clause"
] | null | null | null |
src/Types/Tail1.agda
|
peterthiemann/dual-session
|
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
|
[
"BSD-2-Clause"
] | 1
|
2019-12-07T16:12:50.000Z
|
2019-12-07T16:12:50.000Z
|
module Types.Tail1 where
open import Data.Fin
open import Data.Nat
open import Function using (_∘_)
open import Types.Direction
import Types.IND1 as IND
private
variable
n : ℕ
-- session types restricted to tail recursion
-- can be recognized by type of TChan constructor
data Type : Set
data SType (n : ℕ) : Set
data GType (n : ℕ) : Set
data Type where
TUnit TInt : Type
TPair : (t₁ t₂ : Type) → Type
TChan : (s : IND.SType 0) → Type
data SType n where
gdd : (g : GType n) → SType n
rec : (g : GType (suc n)) → SType n
var : (x : Fin n) → SType n
data GType n where
transmit : (d : Dir) (t : Type) (s : SType n) → GType n
choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n
end : GType n
-- naive definition of duality for tail recursive session types
-- message types are ignored as they are closed
dualS : SType n → SType n
dualG : GType n → GType n
dualS (gdd g) = gdd (dualG g)
dualS (rec g) = rec (dualG g)
dualS (var x) = var x
dualG (transmit d t s) = transmit (dual-dir d) t (dualS s)
dualG (choice d m alt) = choice (dual-dir d) m (dualS ∘ alt)
dualG end = end
| 22.77551
| 63
| 0.65233
|
df4dda904ef694b748768bafe3b684924ff195df
| 1,278
|
agda
|
Agda
|
skylighting-core/test/cases/abc.agda
|
jgm/highlighting-kate2
|
df6ac5844729a564cf2e7ae956dd820209c6afd2
|
[
"MIT",
"BSD-3-Clause"
] | 139
|
2016-12-14T19:36:22.000Z
|
2022-03-31T05:41:52.000Z
|
skylighting-core/test/cases/abc.agda
|
jgm/highlighting-kate2
|
df6ac5844729a564cf2e7ae956dd820209c6afd2
|
[
"MIT",
"BSD-3-Clause"
] | 133
|
2017-01-19T10:19:36.000Z
|
2022-03-13T21:07:07.000Z
|
skylighting-core/test/cases/abc.agda
|
jgm/highlighting-kate2
|
df6ac5844729a564cf2e7ae956dd820209c6afd2
|
[
"MIT",
"BSD-3-Clause"
] | 66
|
2017-01-21T21:36:16.000Z
|
2022-01-18T10:12:38.000Z
|
module Reals where
-- (a set with properties of) the reals
data ℝ : Set where
r0 : ℝ
r1 : ℝ
_+_ : ℝ → ℝ → ℝ
-- equality
data _==_ : ℝ → ℝ → Set where
AXrefl== : ∀ {r} → r == r
AXsymm== : ∀ {r s} → r == s → s == r
AXtrans== : ∀ {r s t} → r == s → s == t → r == t
AX+0 : ∀ {r} → (r + r0) == r
AXsymm+ : ∀ {r s} → (r + s) == (s + r)
AX+== : ∀ {r s t} → r == s → (r + t) == (s + t)
THM0+ : {r : ℝ} → r == (r0 + r)
THM0+ = AXsymm== (AXtrans== AXsymm+ AX+0)
-- AXsymm+ AX+0 r0 + r == r + r0 and r + r0 == r
-- AXtrans== so r0 + r == r
-- AXsymm== so r == r0 + r
THM0+alt : {r : ℝ} → r == (r0 + r)
THM0+alt {r} = AXsymm== {r0 + r} {r} ((AXtrans== {r0 + r} {r + r0} {r}) (AXsymm+ {r0} {r}) (AX+0 {r}))
-- strict partial ordering
data _<_ : ℝ → ℝ → Set where
AXtrans<<< : ∀ {r s t} → r < s → s < t → r < t
AX<=< : ∀ {r s t} → r < s → s == t → r < t
AX=<< : ∀ {r s t} → r == s → s < t → r < t
AX0<1 : r0 < r1
AX+<< : ∀ {r s t} → r < s → (r + t) < (s + t)
THM<+1 : {r : ℝ} → r < (r + r1)
THM<+1 = AX<=< (AX=<< THM0+ (AX+<< AX0<1)) AXsymm+
-- AX0<1 0 < 1
-- AX<+ % so 0 + r < 1 + r
-- AX=<< lem0+ % so r < 1 + r
-- AX<=< % AXsymm+ so r < r + 1
| 31.170732
| 104
| 0.365415
|
1ca2d748f7611afc3358a7ba240b2928a8e156d3
| 16,764
|
agda
|
Agda
|
Cubical/Data/BinNat/BinNat.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/BinNat/BinNat.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/BinNat/BinNat.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{- Binary natural numbers (Anders Mörtberg, Jan. 2019)
This file defines two representations of binary numbers. We prove that
they are equivalent to unary numbers and univalence is then used to
transport both programs and properties between the representations.
This is an example of how having computational univalence can be
useful for practical programming.
The first definition is [Binℕ] and the numbers are essentially lists
of 0/1 with no trailing zeroes (in little-endian format). The main
definitions and examples are:
- Equivalence between Binℕ and ℕ ([Binℕ≃ℕ]) with an equality obtained
using univalence ([Binℕ≡ℕ]).
- Addition on Binℕ defined by transporting addition on ℕ to Binℕ
([_+Binℕ_]) along Binℕ≡ℕ together with a proof that addition on Binℕ
is associative obtained by transporting the proof for ℕ ([+Binℕ-assoc]).
- Functions testing whether a binary number is odd or even in O(1)
([oddBinℕ], [evenBinℕ]) and the corresponding functions for ℕ
obtained by transport. Proof that odd numbers are not even
transported from Binℕ to ℕ ([oddℕnotEvenℕ]).
- An example of the structure identity principle for natural number
structures ([NatImpl]). We first prove that Binℕ≡ℕ lifts to natural
number structures ([NatImplℕ≡Binℕ]) and we then use this to
transport "+-suc : m + suc n ≡ suc (m + n)" from ℕ to Binℕ ([+Binℕ-suc]).
- An example of program/data refinement using the structure identity
principle where we transport a property that is infeasible to prove
by computation for ℕ ([propDoubleℕ]):
2^20 * 2^10 = 2^5 * (2^15 * 2^10)
from the corresponding result on Binℕ which is proved instantly by
refl ([propDoubleBinℕ]).
These examples are inspired from an old cubicaltt formalization:
https://github.com/mortberg/cubicaltt/blob/master/examples/binnat.ctt
which itself is based on an even older cubical formalization (from 2014):
https://github.com/simhu/cubical/blob/master/examples/binnat.cub
The second representation is more non-standard and inspired by:
https://github.com/RedPRL/redtt/blob/master/library/cool/nats.red
Only some of the experiments have been done for this representation,
but it has the virtue of being a bit simpler to prove equivalent to
ℕ. The same representation can be found in:
http://www.cs.bham.ac.uk/~mhe/agda-new/BinaryNaturals.html
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.BinNat.BinNat where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
data Binℕ : Type₀
data Pos : Type₀
-- Binary natural numbers
data Binℕ where
binℕ0 : Binℕ
binℕpos : Pos → Binℕ
-- Positive binary numbers
data Pos where
x0 : Pos → Pos
x1 : Binℕ → Pos
pattern pos1 = x1 binℕ0
pattern x1-pos n = x1 (binℕpos n)
-- Note on notation:
-- We use "⇒" for functions that are equivalences (and therefore
-- they don't preserve the numerical value where the ranges don't
-- match, as with Binℕ⇒Pos).
--
-- We use "→" for the opposite situation (numerical value is preserved,
-- but the function is not necessarily an equivalence)
Binℕ⇒Pos : Binℕ → Pos
sucPos : Pos → Pos
Binℕ⇒Pos binℕ0 = pos1
Binℕ⇒Pos (binℕpos n) = sucPos n
sucPos (x0 ps) = x1-pos ps
sucPos (x1 ps) = x0 (Binℕ⇒Pos ps)
Binℕ→ℕ : Binℕ → ℕ
Pos⇒ℕ : Pos → ℕ
Pos→ℕ : Pos → ℕ
Binℕ→ℕ binℕ0 = zero
Binℕ→ℕ (binℕpos x) = Pos→ℕ x
Pos→ℕ ps = suc (Pos⇒ℕ ps)
Pos⇒ℕ (x0 ps) = suc (doubleℕ (Pos⇒ℕ ps))
Pos⇒ℕ (x1 ps) = doubleℕ (Binℕ→ℕ ps)
posInd : {P : Pos → Type₀} → P pos1 → ((p : Pos) → P p → P (sucPos p)) → (p : Pos) → P p
posInd {P} h1 hs ps = f ps
where
H : (p : Pos) → P (x0 p) → P (x0 (sucPos p))
H p hx0p = hs (x1-pos p) (hs (x0 p) hx0p)
f : (ps : Pos) → P ps
f pos1 = h1
f (x0 ps) = posInd (hs pos1 h1) H ps
f (x1-pos ps) = hs (x0 ps) (posInd (hs pos1 h1) H ps)
Binℕ⇒Pos⇒ℕ : (p : Binℕ) → Pos⇒ℕ (Binℕ⇒Pos p) ≡ Binℕ→ℕ p
Binℕ⇒Pos⇒ℕ binℕ0 = refl
Binℕ⇒Pos⇒ℕ (binℕpos (x0 p)) = refl
Binℕ⇒Pos⇒ℕ (binℕpos (x1 x)) = λ i → suc (doubleℕ (Binℕ⇒Pos⇒ℕ x i))
Pos⇒ℕsucPos : (p : Pos) → Pos⇒ℕ (sucPos p) ≡ suc (Pos⇒ℕ p)
Pos⇒ℕsucPos p = Binℕ⇒Pos⇒ℕ (binℕpos p)
Pos→ℕsucPos : (p : Pos) → Pos→ℕ (sucPos p) ≡ suc (Pos→ℕ p)
Pos→ℕsucPos p = cong suc (Binℕ⇒Pos⇒ℕ (binℕpos p))
ℕ⇒Pos : ℕ → Pos
ℕ⇒Pos zero = pos1
ℕ⇒Pos (suc n) = sucPos (ℕ⇒Pos n)
ℕ→Pos : ℕ → Pos
ℕ→Pos zero = pos1
ℕ→Pos (suc n) = ℕ⇒Pos n
Pos⇒ℕ⇒Pos : (p : Pos) → ℕ⇒Pos (Pos⇒ℕ p) ≡ p
Pos⇒ℕ⇒Pos p = posInd refl hs p
where
hs : (p : Pos) → ℕ⇒Pos (Pos⇒ℕ p) ≡ p → ℕ⇒Pos (Pos⇒ℕ (sucPos p)) ≡ sucPos p
hs p hp =
ℕ⇒Pos (Pos⇒ℕ (sucPos p)) ≡⟨ cong ℕ⇒Pos (Pos⇒ℕsucPos p) ⟩
sucPos (ℕ⇒Pos (Pos⇒ℕ p)) ≡⟨ cong sucPos hp ⟩
sucPos p ∎
ℕ⇒Pos⇒ℕ : (n : ℕ) → Pos⇒ℕ (ℕ⇒Pos n) ≡ n
ℕ⇒Pos⇒ℕ zero = refl
ℕ⇒Pos⇒ℕ (suc n) =
Pos⇒ℕ (ℕ⇒Pos (suc n)) ≡⟨ Pos⇒ℕsucPos (ℕ⇒Pos n) ⟩
suc (Pos⇒ℕ (ℕ⇒Pos n)) ≡⟨ cong suc (ℕ⇒Pos⇒ℕ n) ⟩
suc n ∎
ℕ→Binℕ : ℕ → Binℕ
ℕ→Binℕ zero = binℕ0
ℕ→Binℕ (suc n) = binℕpos (ℕ⇒Pos n)
ℕ→Binℕ→ℕ : (n : ℕ) → Binℕ→ℕ (ℕ→Binℕ n) ≡ n
ℕ→Binℕ→ℕ zero = refl
ℕ→Binℕ→ℕ (suc n) = cong suc (ℕ⇒Pos⇒ℕ n)
Binℕ→ℕ→Binℕ : (n : Binℕ) → ℕ→Binℕ (Binℕ→ℕ n) ≡ n
Binℕ→ℕ→Binℕ binℕ0 = refl
Binℕ→ℕ→Binℕ (binℕpos p) = cong binℕpos (Pos⇒ℕ⇒Pos p)
Binℕ≃ℕ : Binℕ ≃ ℕ
Binℕ≃ℕ = isoToEquiv (iso Binℕ→ℕ ℕ→Binℕ ℕ→Binℕ→ℕ Binℕ→ℕ→Binℕ)
-- Use univalence (in fact only "ua") to get an equality from the
-- above equivalence
Binℕ≡ℕ : Binℕ ≡ ℕ
Binℕ≡ℕ = ua Binℕ≃ℕ
sucBinℕ : Binℕ → Binℕ
sucBinℕ x = binℕpos (Binℕ⇒Pos x)
Binℕ→ℕsuc : (x : Binℕ) → suc (Binℕ→ℕ x) ≡ Binℕ→ℕ (sucBinℕ x)
Binℕ→ℕsuc binℕ0 = refl
Binℕ→ℕsuc (binℕpos x) = sym (Pos→ℕsucPos x)
-- We can transport addition on ℕ to Binℕ
_+Binℕ_ : Binℕ → Binℕ → Binℕ
_+Binℕ_ = transport (λ i → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i)) _+_
-- Test: 4 + 1 = 5
private
_ : binℕpos (x0 (x0 pos1)) +Binℕ binℕpos pos1 ≡ binℕpos (x1-pos (x0 pos1))
_ = refl
-- It is easy to test if binary numbers are odd
oddBinℕ : Binℕ → Bool
oddBinℕ binℕ0 = false
oddBinℕ (binℕpos (x0 _)) = false
oddBinℕ (binℕpos (x1 _)) = true
evenBinℕ : Binℕ → Bool
evenBinℕ n = oddBinℕ (sucBinℕ n)
-- And prove the following property (without induction)
oddBinℕnotEvenBinℕ : (n : Binℕ) → oddBinℕ n ≡ not (evenBinℕ n)
oddBinℕnotEvenBinℕ binℕ0 = refl
oddBinℕnotEvenBinℕ (binℕpos (x0 x)) = refl
oddBinℕnotEvenBinℕ (binℕpos (x1 x)) = refl
-- It is also easy to define and prove the property for unary numbers,
-- however the definition uses recursion and the proof induction
private
oddn : ℕ → Bool
oddn zero = true
oddn (suc x) = not (oddn x)
evenn : ℕ → Bool
evenn n = not (oddn n)
oddnSuc : (n : ℕ) → oddn n ≡ not (evenn n)
oddnSuc zero = refl
oddnSuc (suc n) = cong not (oddnSuc n)
-- So what we can do instead is to transport the odd test from Binℕ to
-- ℕ along the equality
oddℕ : ℕ → Bool
oddℕ = transport (λ i → Binℕ≡ℕ i → Bool) oddBinℕ
evenℕ : ℕ → Bool
evenℕ = transport (λ i → Binℕ≡ℕ i → Bool) evenBinℕ
-- We can then also transport the property
oddℕnotEvenℕ : (n : ℕ) → oddℕ n ≡ not (evenℕ n)
oddℕnotEvenℕ =
let -- We first build a path from oddBinℕ to oddℕ. When i=1 this is
-- "transp (λ j → Binℕ≡ℕ j → Bool) i0 oddBinℕ" (i.e. oddℕ)
oddp : PathP (λ i → Binℕ≡ℕ i → Bool) oddBinℕ oddℕ
oddp i = transp (λ j → Binℕ≡ℕ (i ∧ j) → Bool) (~ i) oddBinℕ
-- We then build a path from evenBinℕ to evenℕ
evenp : PathP (λ i → Binℕ≡ℕ i → Bool) evenBinℕ evenℕ
evenp i = transp (λ j → Binℕ≡ℕ (i ∧ j) → Bool) (~ i) evenBinℕ
in -- Then transport oddBinℕnotEvenBinℕ in a suitable equality type
-- When i=0 this is "(n : Binℕ) → oddBinℕ n ≡ not (evenBinℕ n)"
-- When i=1 this is "(n : ℕ) → oddℕ n ≡ not (evenℕ n)"
transport (λ i → (n : Binℕ≡ℕ i) → oddp i n ≡ not (evenp i n)) oddBinℕnotEvenBinℕ
-- We can do the same for natural numbers:
-- First construct the path
addp : PathP (λ i → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i)) _+_ _+Binℕ_
addp i = transp (λ j → Binℕ≡ℕ (~ i ∨ ~ j) → Binℕ≡ℕ (~ i ∨ ~ j) → Binℕ≡ℕ (~ i ∨ ~ j)) (~ i) _+_
-- Then transport associativity:
+Binℕ-assoc : ∀ m n o → m +Binℕ (n +Binℕ o) ≡ (m +Binℕ n) +Binℕ o
+Binℕ-assoc =
transport (λ i → (m n o : Binℕ≡ℕ (~ i))
→ addp i m (addp i n o) ≡ addp i (addp i m n) o) +-assoc
-- We can also define what it means to be an implementation of natural
-- numbers and use this to transport properties between different
-- implementation of natural numbers. This can be seen as a special
-- case of the structure identity principle: any property that holds
-- for one structure also holds for an equivalent one.
-- An implementation of natural numbers (i.e. a "natural number
-- structure") has a zero and successor.
record NatImpl (A : Type₀) : Type₀ where
field
z : A
s : A → A
open NatImpl
NatImplℕ : NatImpl ℕ
z NatImplℕ = zero
s NatImplℕ = suc
NatImplBinℕ : NatImpl Binℕ
z NatImplBinℕ = binℕ0
s NatImplBinℕ = sucBinℕ
-- Using the equality between binary and unary numbers we can get an
-- equality between the two implementations of the NatImpl interface
NatImplℕ≡Binℕ : PathP (λ i → NatImpl (Binℕ≡ℕ (~ i))) NatImplℕ NatImplBinℕ
z (NatImplℕ≡Binℕ i) = transp (λ j → Binℕ≡ℕ (~ i ∨ ~ j)) (~ i) zero
s (NatImplℕ≡Binℕ i) =
λ x → glue (λ { (i = i0) → suc x
; (i = i1) → sucBinℕ x })
-- We need to do use and hcomp to do and endpoint
-- correction as "suc (unglue x)" connects "suc x"
-- with "suc (Binℕ→ℕ x)" along i (which makes sense as
-- x varies from ℕ to Binℕ along i), but we need
-- something from "suc x" to "Binℕ→ℕ (sucBinℕ x)" for
-- the glue to be well-formed
(hcomp (λ j → λ { (i = i0) → suc x
; (i = i1) → Binℕ→ℕsuc x j })
(suc (unglue (i ∨ ~ i) x)))
-- We then use this to transport +-suc from unary to binary numbers
+Binℕ-suc : ∀ m n → m +Binℕ sucBinℕ n ≡ sucBinℕ (m +Binℕ n)
+Binℕ-suc =
transport (λ i → (m n : Binℕ≡ℕ (~ i))
→ addp i m (NatImplℕ≡Binℕ i .s n) ≡ NatImplℕ≡Binℕ i .s (addp i m n)) +-suc
-- Doubling experiment: we define a notion of "doubling structure" and
-- transport a proof that is proved directly using refl for binary
-- numbers to unary numbers. This is an example of program/data
-- refinement: we can use univalence to prove properties about
-- inefficient data-structures using efficient ones.
-- Doubling structures
record Double {ℓ} (A : Type ℓ) : Type (ℓ-suc ℓ) where
field
-- doubling function computing 2 * x
double : A → A
-- element to double
elt : A
open Double
-- Compute: 2^n * x
doubles : ∀ {ℓ} {A : Type ℓ} (D : Double A) → ℕ → A → A
doubles D n x = iter n (double D) x
Doubleℕ : Double ℕ
double Doubleℕ = doubleℕ
elt Doubleℕ = n1024
where
-- 1024 = 2^8 * 2^2 = 2^10
n1024 : ℕ
n1024 = doublesℕ 8 4
-- The doubling operation on binary numbers is O(1), while for unary
-- numbers it is O(n). What is of course even more problematic is that
-- we cannot handle very big unary natural numbers, but with binary
-- there is no problem to represent very big numbers
doubleBinℕ : Binℕ → Binℕ
doubleBinℕ binℕ0 = binℕ0
doubleBinℕ (binℕpos x) = binℕpos (x0 x)
DoubleBinℕ : Double Binℕ
double DoubleBinℕ = doubleBinℕ
elt DoubleBinℕ = bin1024
where
-- 1024 = 2^10 = 10000000000₂
bin1024 : Binℕ
bin1024 = binℕpos (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 pos1))))))))))
-- As these function don't commute strictly we have to prove it
-- separately and insert it in the proof of DoubleBinℕ≡Doubleℕ below
-- (just like we had to in NatImplℕ≡NatImplBinℕ
Binℕ→ℕdouble : (x : Binℕ) → doubleℕ (Binℕ→ℕ x) ≡ Binℕ→ℕ (doubleBinℕ x)
Binℕ→ℕdouble binℕ0 = refl
Binℕ→ℕdouble (binℕpos x) = refl
-- We use the equality between Binℕ and ℕ to get an equality of
-- doubling structures
DoubleBinℕ≡Doubleℕ : PathP (λ i → Double (Binℕ≡ℕ i)) DoubleBinℕ Doubleℕ
double (DoubleBinℕ≡Doubleℕ i) =
λ x → glue (λ { (i = i0) → doubleBinℕ x
; (i = i1) → doubleℕ x })
(hcomp (λ j → λ { (i = i0) → Binℕ→ℕdouble x j
; (i = i1) → doubleℕ x })
(doubleℕ (unglue (i ∨ ~ i) x)))
elt (DoubleBinℕ≡Doubleℕ i) = transp (λ j → Binℕ≡ℕ (i ∨ ~ j)) i (Doubleℕ .elt)
-- We can now use transport to prove a property that is too slow to
-- check with unary numbers. We define the property we want to check
-- as a record so that Agda does not try to unfold it eagerly.
record propDouble {ℓ} {A : Type ℓ} (D : Double A) : Type ℓ where
field
-- 2^20 * e = 2^5 * (2^15 * e)
proof : doubles D 20 (elt D) ≡ doubles D 5 (doubles D 15 (elt D))
open propDouble
-- The property we want to prove takes too long to typecheck for ℕ:
-- propDoubleℕ : propDouble Doubleℕ
-- propDoubleℕ = refl
-- With binary numbers it is instant
propDoubleBinℕ : propDouble DoubleBinℕ
proof propDoubleBinℕ = refl
-- By transporting the proof along the equality we then get it for
-- unary numbers
propDoubleℕ : propDouble Doubleℕ
propDoubleℕ = transport (λ i → propDouble (DoubleBinℕ≡Doubleℕ i)) propDoubleBinℕ
--------------------------------------------------------------------------------
--
-- Alternative encoding of binary natural numbers inspired by:
-- https://github.com/RedPRL/redtt/blob/master/library/cool/nats.red
--
-- This representation makes the equivalence with ℕ a bit easier to
-- prove, but the doubling example wouldn't work as nicely as we
-- cannot define it as an O(1) operation
data binnat : Type₀ where
zero : binnat -- 0
consOdd : binnat → binnat -- 2*n + 1
consEven : binnat → binnat -- 2*{n+1}
binnat→ℕ : binnat → ℕ
binnat→ℕ zero = 0
binnat→ℕ (consOdd n) = suc (doubleℕ (binnat→ℕ n))
binnat→ℕ (consEven n) = suc (suc (doubleℕ (binnat→ℕ n)))
suc-binnat : binnat → binnat
suc-binnat zero = consOdd zero
suc-binnat (consOdd n) = consEven n
suc-binnat (consEven n) = consOdd (suc-binnat n)
ℕ→binnat : ℕ → binnat
ℕ→binnat zero = zero
ℕ→binnat (suc n) = suc-binnat (ℕ→binnat n)
binnat→ℕ-suc : (n : binnat) → binnat→ℕ (suc-binnat n) ≡ suc (binnat→ℕ n)
binnat→ℕ-suc zero = refl
binnat→ℕ-suc (consOdd n) = refl
binnat→ℕ-suc (consEven n) = λ i → suc (doubleℕ (binnat→ℕ-suc n i))
ℕ→binnat→ℕ : (n : ℕ) → binnat→ℕ (ℕ→binnat n) ≡ n
ℕ→binnat→ℕ zero = refl
ℕ→binnat→ℕ (suc n) = (binnat→ℕ-suc (ℕ→binnat n)) ∙ (cong suc (ℕ→binnat→ℕ n))
suc-ℕ→binnat-double : (n : ℕ) → suc-binnat (ℕ→binnat (doubleℕ n)) ≡ consOdd (ℕ→binnat n)
suc-ℕ→binnat-double zero = refl
suc-ℕ→binnat-double (suc n) = λ i → suc-binnat (suc-binnat (suc-ℕ→binnat-double n i))
binnat→ℕ→binnat : (n : binnat) → ℕ→binnat (binnat→ℕ n) ≡ n
binnat→ℕ→binnat zero = refl
binnat→ℕ→binnat (consOdd n) =
(suc-ℕ→binnat-double (binnat→ℕ n)) ∙ (cong consOdd (binnat→ℕ→binnat n))
binnat→ℕ→binnat (consEven n) =
(λ i → suc-binnat (suc-ℕ→binnat-double (binnat→ℕ n) i)) ∙ (cong consEven (binnat→ℕ→binnat n))
ℕ≃binnat : ℕ ≃ binnat
ℕ≃binnat = isoToEquiv (iso ℕ→binnat binnat→ℕ binnat→ℕ→binnat ℕ→binnat→ℕ)
ℕ≡binnat : ℕ ≡ binnat
ℕ≡binnat = ua ℕ≃binnat
-- We can transport addition on ℕ to binnat
_+binnat_ : binnat → binnat → binnat
_+binnat_ = transport (λ i → ℕ≡binnat i → ℕ≡binnat i → ℕ≡binnat i) _+_
-- Test: 4 + 1 = 5
_ : consEven (consOdd zero) +binnat consOdd zero ≡ consOdd (consEven zero)
_ = refl
oddbinnat : binnat → Bool
oddbinnat zero = false
oddbinnat (consOdd _) = true
oddbinnat (consEven _) = false
oddℕ' : ℕ → Bool
oddℕ' = transport (λ i → ℕ≡binnat (~ i) → Bool) oddbinnat
-- The NatImpl example for this representation of binary numbers
private
NatImplbinnat : NatImpl binnat
z NatImplbinnat = zero
s NatImplbinnat = suc-binnat
-- Note that the s case is a bit simpler as no end-point correction
-- is necessary (things commute strictly)
NatImplℕ≡NatImplbinnat : PathP (λ i → NatImpl (ℕ≡binnat i)) NatImplℕ NatImplbinnat
z (NatImplℕ≡NatImplbinnat i) = transp (λ j → ℕ≡binnat (i ∨ ~ j)) i zero
s (NatImplℕ≡NatImplbinnat i) =
λ x → glue (λ { (i = i0) → suc x
; (i = i1) → suc-binnat x })
(suc-binnat (unglue (i ∨ ~ i) x))
oddSuc : (n : binnat) → oddbinnat n ≡ not (oddbinnat (suc-binnat n))
oddSuc zero = refl
oddSuc (consOdd _) = refl
oddSuc (consEven _) = refl
oddℕSuc' : (n : ℕ) → oddℕ' n ≡ not (oddℕ' (suc n))
oddℕSuc' =
let eq : (i : I) → ℕ≡binnat (~ i) → Bool
eq i = transp (λ j → ℕ≡binnat (~ i ∨ ~ j) → Bool) (~ i) oddbinnat
in transport
(λ i → (n : ℕ≡binnat (~ i)) → eq i n ≡ not (eq i (NatImplℕ≡NatImplbinnat (~ i) .NatImpl.s n)))
oddSuc
| 34.004057
| 104
| 0.645848
|
209ab067d8c79a74ad96f20fb29c66396b086f43
| 810
|
agda
|
Agda
|
test/Succeed/fol-theorems/DuplicateAgdaDefinitions1.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Succeed/fol-theorems/DuplicateAgdaDefinitions1.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Succeed/fol-theorems/DuplicateAgdaDefinitions1.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
------------------------------------------------------------------------------
-- Testing the erasing of the duplicate definitions required by a conjecture
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module DuplicateAgdaDefinitions1 where
infix 7 _≈_
------------------------------------------------------------------------------
postulate
D : Set
_≈_ : D → D → Set
Eq : D → D → Set
Eq x y = x ≈ y
{-# ATP definition Eq #-}
postulate Eq-trans : ∀ {x y z} → Eq x y → Eq y z → Eq x z
postulate Eq-trans₂ : ∀ {w x y z} → Eq w x → Eq x y → Eq y z → Eq w z
{-# ATP prove Eq-trans₂ Eq-trans #-}
| 28.928571
| 78
| 0.402469
|
103095dfae9f042528124d206e87cccb3ee21f2a
| 1,076
|
agda
|
Agda
|
src/Dijkstra/EitherLike.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Dijkstra/EitherLike.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Dijkstra/EitherLike.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
module Dijkstra.EitherLike where
open import Haskell.Prelude
open import Level
renaming (suc to ℓ+1; zero to ℓ0; _⊔_ to _ℓ⊔_)
public
module _ {ℓ₀ ℓ₁ ℓ₂ : Level} where
EL-type = Set ℓ₁ → Set ℓ₂ → Set ℓ₀
EL-level = ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₀
-- Utility to make passing between `Either` and `EitherD` more convenient
record EitherLike (E : EL-type) : Set (ℓ+1 EL-level) where
field
fromEither : ∀ {A : Set ℓ₁} {B : Set ℓ₂} → Either A B → E A B
toEither : ∀ {A : Set ℓ₁} {B : Set ℓ₂} → E A B → Either A B
open EitherLike ⦃ ... ⦄ public
EL-func : EL-type → Set (ℓ+1 EL-level)
EL-func EL = ⦃ mel : EitherLike EL ⦄ → Set EL-level
instance
EitherLike-Either : ∀ {ℓ₁ ℓ₂} → EitherLike{ℓ₁ ℓ⊔ ℓ₂}{ℓ₁}{ℓ₂} Either
EitherLike.fromEither EitherLike-Either = id
EitherLike.toEither EitherLike-Either = id
| 31.647059
| 111
| 0.671004
|
1016ec3d6ec0ecd030fa6650055c9e276ce319bc
| 4,401
|
agda
|
Agda
|
code-examples/agda/poly0.agda
|
mstone/poly
|
425de958985aacbd3284d3057fe21fd682e315ea
|
[
"MIT"
] | 53
|
2021-02-18T16:31:04.000Z
|
2022-03-22T23:08:27.000Z
|
code-examples/agda/poly0.agda
|
mstone/poly
|
425de958985aacbd3284d3057fe21fd682e315ea
|
[
"MIT"
] | 2
|
2021-09-02T02:29:39.000Z
|
2022-01-12T10:06:32.000Z
|
code-examples/agda/poly0.agda
|
mstone/poly
|
425de958985aacbd3284d3057fe21fd682e315ea
|
[
"MIT"
] | 4
|
2021-07-10T17:19:37.000Z
|
2022-01-30T11:45:57.000Z
|
{-# OPTIONS --type-in-type #-}
module poly0 where
open import prelude
open import functors
open import poly.core public
variable
A B C X Y : ∫
I A⁺ B⁺ C⁺ X⁺ Y⁺ : Set
A⁻ : A⁺ → Set
B⁻ : B⁺ → Set
C⁻ : C⁺ → Set
X⁻ : X⁺ → Set
Y⁻ : Y⁺ → Set
∃⊤ ∃⊥ ⊤∫ ∫∫ : Set → ∫
∃⊤ a = a , λ _ → ⊤
∃⊥ a = a , λ _ → ⊥
⊤∫ a = ⊤ , λ _ → a
∫∫ a = a , λ _ → a
𝒴 𝟘 : ∫
𝒴 = ⊤ , λ _ → ⊤
𝟘 = ⊥ , λ _ → ⊥
module _ {A@(A⁺ , A⁻) B@(B⁺ , B⁻) : ∫} where
infixl 5 _★_
-- infix notatjon for get
_★_ : A⁺ → (l : ∫[ A , B ]) → B⁺
σa ★ l = get l σa
infixr 4 _#_←_
-- Infix notatjon for set
_#_←_ : (a⁺ : A⁺) → (A↝B : ∫[ A , B ]) → B⁻ (a⁺ ★ A↝B) → A⁻ a⁺
a⁺ # l ← b⁻ = π₂ (l a⁺) b⁻
_↕_ : (get : A⁺ → B⁺) → (set : (a⁺ : A⁺) → B⁻ (get a⁺) → A⁻ a⁺) → ∫[ A , B ]
g ↕ s = λ a⁺ → (g a⁺) , (s a⁺)
module _ {A@(A⁺ , A⁻) C@(C⁺ , C⁻) : ∫} (l : ∫[ A , C ]) where
-- vertical and cartesian factorization
Factor : Σ[ B ∈ ∫ ] (∫[ A , B ]) × (∫[ B , C ])
Factor = (A⁺ , C⁻ ∘ get l)
, id ↕ set l
, get l ↕ λ _ → id
module lenses (f : A⁺ → B⁺) where
constant : ∫[ ∃⊥ A⁺ , ∃⊥ B⁺ ]
emitter : ∫[ ∃⊤ A⁺ , ∃⊤ B⁺ ]
sensor : ∫[ ⊤∫ B⁺ , ⊤∫ A⁺ ]
constant a⁺ = f a⁺ , id
emitter a⁺ = f a⁺ , λ _ → tt
sensor _ = tt , f
open lenses public
enclose : ((a⁺ : A⁺) → B⁻ a⁺) → ∫[ (A⁺ , B⁻) , 𝒴 ]
enclose f a⁺ = tt , λ _ → f a⁺
auto : ∫[ ∃⊤ A⁺ , 𝒴 ]
auto = enclose λ _ → tt
{-
lift∫ : (f : Set → Set) → ∫ → ∫
lift∫ f (A⁺ , A⁻) = A⁺ , f ∘ A⁻
liftLens : ∀ {A B} (f : Set → Set) → ∫[ A , B ] → ∫[ lift∫ f A , lift∫ f B ]
liftLens f l a⁺ with l a⁺
... | b⁺ , setb = b⁺ , φ setb
-}
{-
module lift_comonad (f : Set → Set) {A : ∫} ⦃ f_monad : Monad f ⦄ where
extract : lift∫ f A ↝ A
extract a⁺ = a⁺ , η f_monad
-- id ↕ λ _ → η
duplicate : lift∫ f A ↝ lift∫ f (lift∫ f A)
duplicate a⁺ = a⁺ , μ
-}
module poly-ops where
infixl 6 _⊗_
infixl 5 _⊕_
_⊕_ _⊗_ _⊠_ _⊚_ : ∫ → ∫ → ∫
(A⁺ , A⁻) ⊕ (B⁺ , B⁻) = (A⁺ ⊎ B⁺) , (A⁻ ⨄ B⁻) -- coproduct
(A⁺ , A⁻) ⊗ (B⁺ , B⁻) = (A⁺ × B⁺) , (A⁻ ⨃ B⁻) -- product
(A⁺ , A⁻) ⊠ (B⁺ , B⁻) = (A⁺ × B⁺) , (A⁻ ⨉ B⁻) -- juxtapose
(A⁺ , A⁻) ⊚ (B⁺ , B⁻) = (Σ[ a⁺ ∈ A⁺ ](A⁻ a⁺ → B⁺)) -- compose
, λ (_ , bs) → ∃ (B⁻ ∘ bs)
-- N-ary
Σ⊕ : (I → ∫) → ∫
Σ⊕ {I = I} A = Σ I (π₁ ∘ A) , λ (i , a⁺) → π₂ (A i) a⁺
Π⊗ : (I → ∫) → ∫
Π⊗ {I = I} a = ((i : I) → π₁ (a i))
, λ a⁺ → Σ[ i ∈ I ](π₂ (a i) (a⁺ i))
Π⊠ : (I → ∫) → ∫
Π⊠ {I = I} a = ((i : I) → π₁ (a i))
, (λ a⁺ → (i : I) -> π₂ (a i) (a⁺ i))
_ᵒ_ : ∫ → ℕ → ∫
_ ᵒ ℕz = 𝒴
a ᵒ ℕs n = a ⊚ (a ᵒ n)
open poly-ops public
module lens-ops where
_⟦+⟧_ : ∀ {a b x y} → ∫[ a , b ] → ∫[ x , y ] → ∫[ a ⊕ x , b ⊕ y ] -- coproduct
_⟦|⟧_ : ∀ {a b x } → ∫[ a , x ] → ∫[ b , x ] → ∫[ a ⊕ b , x ] -- copair
_⟦⊗⟧_ : ∀ {a b x y} → ∫[ a , b ] → ∫[ x , y ] → ∫[ a ⊗ x , b ⊗ y ] -- product
_⟦×⟧_ : ∀ {x a b } → ∫[ x , a ] → ∫[ x , b ] → ∫[ x , a ⊗ b ] -- pair
_⟦⊠⟧_ : ∀ {a b x y} → ∫[ a , b ] → ∫[ x , y ] → ∫[ a ⊠ x , b ⊠ y ] -- juxtaposition
_⟦⊚⟧_ : ∀ {a b x y} → ∫[ a , b ] → ∫[ x , y ] → ∫[ a ⊚ x , b ⊚ y ] -- composition
(a↝b ⟦+⟧ x↝y) = λ{(Σ₁ a⁺) → let b⁺ , setb = a↝b a⁺ in Σ₁ b⁺ , setb
;(Σ₂ x⁺) → let y⁺ , sety = x↝y x⁺ in Σ₂ y⁺ , sety}
(a↝x ⟦|⟧ b↝x) = λ{(Σ₁ a⁺) → a↝x a⁺
;(Σ₂ b⁺) → b↝x b⁺}
(a↝b ⟦⊗⟧ x↝y) (a⁺ , x⁺) with a↝b a⁺ | x↝y x⁺
... | b⁺ , setb | y⁺ , sety = (b⁺ , y⁺)
, λ{(Σ₁ b⁻) → Σ₁ (setb b⁻)
;(Σ₂ y⁻) → Σ₂ (sety y⁻)}
_⟦×⟧_ x↝a x↝b x⁺ with x↝a x⁺ | x↝b x⁺
... | a⁺ , seta | b⁺ , setb = (a⁺ , b⁺) , λ{(Σ₁ a⁻) → seta a⁻
;(Σ₂ b⁻) → setb b⁻}
_⟦⊠⟧_ a↝b x↝y (a⁺ , x⁺) = ((a⁺ ★ a↝b) , (x⁺ ★ x↝y))
, λ (b⁻ , y⁻) → (a⁺ # a↝b ← b⁻) , (x⁺ # x↝y ← y⁻)
(a↝b ⟦⊚⟧ x↝y) (a⁺ , a⁻→x⁺) with a↝b a⁺
... | b⁺ , setb = (b⁺ , get x↝y ∘ a⁻→x⁺ ∘ setb)
, λ (b⁻ , y⁻) → let a⁻ = setb b⁻
in a⁻ , (a⁻→x⁺ a⁻ # x↝y ← y⁻)
-- N-ary
Π⟦⊠⟧ : {as bs : I → ∫}
→ ((i : I) → (∫[ as i , bs i ]))
→ ∫[ Π⊠ as , Π⊠ bs ]
Π⟦⊠⟧ ls as⁺ = (λ i → as⁺ i ★ ls i)
, (λ dbs i → as⁺ i # ls i ← dbs i)
_⟦ᵒ⟧_ : ∫[ A , B ] → (n : ℕ) → ∫[ A ᵒ n , B ᵒ n ]
_⟦ᵒ⟧_ {a} {b} l = go where
go : (n : ℕ) → ∫[ a ᵒ n , b ᵒ n ]
go ℕz = 𝒾 {x = 𝒴}
go (ℕs n) = l ⟦⊚⟧ (go n)
open lens-ops public
| 30.5625
| 85
| 0.33606
|
20f152bdfa894d785a75ecb2c120ec8a5cfde202
| 794
|
agda
|
Agda
|
src/Data/Lens/Proofs/LensLaws.agda
|
JonathanBrouwer/research-project
|
4959a3c9cd8563a1726e0e968e6a179008cd4d9f
|
[
"Unlicense"
] | 1
|
2021-05-25T09:10:20.000Z
|
2021-05-25T09:10:20.000Z
|
src/Data/Lens/Proofs/LensLaws.agda
|
JonathanBrouwer/research-project
|
4959a3c9cd8563a1726e0e968e6a179008cd4d9f
|
[
"Unlicense"
] | null | null | null |
src/Data/Lens/Proofs/LensLaws.agda
|
JonathanBrouwer/research-project
|
4959a3c9cd8563a1726e0e968e6a179008cd4d9f
|
[
"Unlicense"
] | null | null | null |
module Data.Lens.Proofs.LensLaws where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Lens.Lens
open import Data.Logic
open import Agda.Primitive
-- First, define the lens laws
ViewSet : {a b : Set} -> (l : Lens a b) -> Set
ViewSet {a} {b} l = (v : b) (s : a) -> view l (set l v s) ≡ v
SetView : {a b : Set} -> (l : Lens a b) -> Set
SetView {a} {b} l = (s : a) -> set l (view l s) s ≡ s
SetSet : {a b : Set} -> (l : Lens a b) -> Set
SetSet {a} {b} l = (v1 v2 : b) (s : a) -> set l v2 (set l v1 s) ≡ set l v2 s
-- Define ValidLens as a lens for which the laws hold
data ValidLens (a b : Set) : Set₁ where
CValidLens : (l : Lens a b) -> ViewSet l -> SetView l -> SetSet l -> ValidLens a b
toLens : ValidLens a b -> Lens a b
toLens (CValidLens l _ _ _) = l
| 29.407407
| 84
| 0.602015
|
dfbfeedf8ddb3960fc84919200d92566ec07541a
| 1,474
|
agda
|
Agda
|
SOAS/ContextMaps/Properties.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
SOAS/ContextMaps/Properties.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
SOAS/ContextMaps/Properties.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
import SOAS.Families.Core
-- Various properties of context map operations
module SOAS.ContextMaps.Properties {T : Set}
(open SOAS.Families.Core {T}) (𝒳 : Familyₛ) where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.ContextMaps.CategoryOfRenamings {T}
open import SOAS.ContextMaps.Combinators
open import Categories.Functor.Bifunctor
open import Categories.Object.Initial
open import Categories.Object.Coproduct
open import Categories.Category.Cocartesian
open import Categories.Category.Equivalence using (StrongEquivalence)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (niHelper) renaming (refl to NI-refl)
private
variable
Γ Δ Θ Ξ : Ctx
α : T
-- Copairing and injection
copair∘i₁ : {σ : Γ ~[ 𝒳 ]↝ Θ}{ς : Δ ~[ 𝒳 ]↝ Θ} (v : ℐ α Γ)
→ copair 𝒳 σ ς (∔.i₁ v) ≡ σ v
copair∘i₁ new = refl
copair∘i₁ {σ = σ} (old v) = copair∘i₁ {σ = σ ∘ old} v
copair∘i₂ : {σ : Γ ~[ 𝒳 ]↝ Θ}{ς : Δ ~[ 𝒳 ]↝ Θ} (v : ℐ α Δ)
→ copair 𝒳 σ ς (∔.i₂ {Γ} v) ≡ ς v
copair∘i₂ {Γ = ∅} v = refl
copair∘i₂ {Γ = α ∙ Γ} {σ = σ} v = copair∘i₂ {σ = σ ∘ old} v
-- Push function into copairing
f∘copair : (𝒳 {𝒴} : Familyₛ) (f : Θ ~[ 𝒳 ➔ 𝒴 ]↝ Ξ)(σ : Γ ~[ 𝒳 ]↝ Θ)(ς : Δ ~[ 𝒳 ]↝ Θ)
(v : ℐ α (Γ ∔ Δ))
→ f (copair 𝒳 σ ς v) ≡ copair 𝒴 (f ∘ σ) (f ∘ ς) v
f∘copair {Γ = ∅} 𝒳 f σ ς v = refl
f∘copair {Γ = α ∙ Γ} 𝒳 f σ ς new = refl
f∘copair {Γ = α ∙ Γ} 𝒳 f σ ς (old v) = f∘copair 𝒳 f (σ ∘ old) ς v
| 32.755556
| 84
| 0.625509
|
dc10e2cc4797d9f635b1730e42080cfcc64d46e4
| 1,207
|
agda
|
Agda
|
agda/Data/List/Filter.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/List/Filter.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/List/Filter.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Data.List.Filter where
open import Prelude
open import Data.List
open import Data.List.Membership
open import Data.Sigma.Properties
open import Data.Bool.Properties
open import Data.Fin
module _ {p} {P : A → Type p} where
filter : (P? : ∀ x → Dec (P x)) → List A → List (∃ P)
filter P? = foldr f []
where
f : _ → List (∃ P) → List (∃ P)
f y ys with P? y
... | yes t = (y , t) ∷ ys
... | no _ = ys
filter-preserves : (isPropP : ∀ x → isProp (P x)) (P? : ∀ x → Dec (P x)) (xs : List A) →
(x : A) →
(v : P x) →
(x ∈ xs) →
((x , v) ∈ filter P? xs)
filter-preserves isPropP P? (x ∷ xs) y v (n , y∈xs) with P? x
filter-preserves isPropP P? (x ∷ xs) y v (f0 , y∈xs) | yes t = f0 , ΣProp≡ isPropP y∈xs
filter-preserves isPropP P? (x ∷ xs) y v (fs n , y∈xs) | yes t = let m , q = filter-preserves isPropP P? xs y v (n , y∈xs) in fs m , q
filter-preserves isPropP P? (x ∷ xs) y v (f0 , y∈xs) | no ¬t = ⊥-elim (¬t (subst P (sym y∈xs) v))
filter-preserves isPropP P? (x ∷ xs) y v (fs n , y∈xs) | no ¬t = filter-preserves isPropP P? xs y v (n , y∈xs)
| 38.935484
| 136
| 0.525269
|
fbf7fbecf565bdab48c2e5cc9cd1ac6e323439c0
| 90
|
agda
|
Agda
|
agda/Data/Fin.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
agda/Data/Fin.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/Fin.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Data.Fin where
open import Data.Fin.Base public
| 15
| 32
| 0.7
|
3915693ceb51f001de8ce12b4ac883debedc76a5
| 3,613
|
agda
|
Agda
|
HoTT/Basic_Types.agda
|
andyfreeyy/agda_and_math
|
76b9ef64626b6d3bbb7ace4f1a16aeb447c54328
|
[
"MIT"
] | 2
|
2020-03-23T09:01:42.000Z
|
2020-05-24T10:56:36.000Z
|
HoTT/Basic_Types.agda
|
andyfreeyy/agda_and_math
|
76b9ef64626b6d3bbb7ace4f1a16aeb447c54328
|
[
"MIT"
] | null | null | null |
HoTT/Basic_Types.agda
|
andyfreeyy/agda_and_math
|
76b9ef64626b6d3bbb7ace4f1a16aeb447c54328
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --exact-split --safe #-}
module Basic_Types where
-- Already in the builtin's of agda, there are Π types, which is ∀, and lambda
-- abstraction, which is λ{ } and function types, which is →.
-- ------------------------------------
-- Some operations for function types
-- The curly brackts ∀{} should be viewed as contexts.
-- identity function
id : ∀ {A : Set} → A → A
id = λ{ x → x }
-- function composition
comp : ∀ {A B C : Set} → (B → C) → (A → B) → A → C
comp {A} {B} {C} = λ (f : B → C) (g : A → B) (x : A) → f (g x)
-- The judgemental equality of association of functions is builtin in agda,
-- i.e., all the rules of derivation in the basic language of type theory,
-- e.g., the β-, η- reduction is automatic in agda.
-- swapping the argument
swap : ∀ {A B : Set} {C : A → B → Set} →
(∀ (a : A) (b : B) → C a b) → (∀ (b : B) (a : A) → C a b)
swap {A} {B} {C} = λ { p → λ (b : B) (a : A) → p a b }
-- ------------------------------------
-- the unit type
data 𝟙 : Set where
⋆ : 𝟙
𝟙-ind : ∀ {A : 𝟙 → Set} → ∀ (a : A ⋆) → ∀ (x : 𝟙) → A x
𝟙-ind {A} a = 𝟙-indhelper
where 𝟙-indhelper : ∀ (x : 𝟙) → A x
𝟙-indhelper ⋆ = a
-- ------------------------------------
-- the empty type
data 𝟘 : Set where
𝟘-ind : ∀ {A : 𝟘 → Set} → ∀ (x : 𝟘) → A x
𝟘-ind {A} ()
-- define negation
¬_ : ∀ (A : Set) → Set
¬ A = A → 𝟘
-- ------------------------------------
-- the boolean type
data 𝟚 : Set where
tt ff : 𝟚
𝟚-ind : ∀ {A : 𝟚 → Set} → A ff → A tt → ∀ (x : 𝟚) → A x
𝟚-ind Aff _ ff = Aff
𝟚-ind _ Att tt = Att
-- ------------------------------------
-- natural numbers
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
-- ℕ induction
ℕ-ind : ∀ {A : ℕ → Set} →
∀ (a : A 0) → (∀ (n : ℕ) → A n → A (succ n)) → ∀ (m : ℕ) → A m
ℕ-ind {A} a p = ℕ-indhelper
where ℕ-indhelper : ∀ (m : ℕ) → A m
ℕ-indhelper 0 = a
ℕ-indhelper (succ n) = p n (ℕ-indhelper n)
-- From this exercise, we can actually see that the idea of induction is
-- builtin in agda, since we essentially use the induction builtin in agda
-- to prove ℕ-ind.
-- ℕ recursion, which is a special case for ℕ induction, where the type is not
-- dependent on ℕ
ℕ-rec : ∀ {A : Set} →
∀ (a : A) → (∀ (n : ℕ) → A → A) → ∀ (m : ℕ) → A
ℕ-rec {A} = ℕ-ind {λ { n → A }}
-- for example, we can use ℕ-rec to define addition
add : ℕ → ℕ → ℕ
add = ℕ-rec {ℕ → ℕ} (id {ℕ}) (λ (n : ℕ) (p : ℕ → ℕ) → comp succ p)
-- ------------------------------------
-- the sum type
record Σ (A : Set) (B : A → Set) : Set where
constructor
_,_
field
a : A
b : B a
-- the two projections
π₁ : ∀ {A : Set} {B : A → Set} → Σ A B → A
π₁ (x , y) = x
π₂ : ∀ {A : Set} {B : A → Set} → ∀ (z : Σ A B) → B (π₁ z)
π₂ (x , y) = y
syntax Σ A (λ a → b) = Σ a ∶ A , b
-- Σ induction
Σ-ind : ∀ {A : Set} {B : A → Set} {P : Σ A B → Set} →
(∀ (a : A) (b : B a) → P (a , b)) → ∀ (z : Σ A B) → P z
Σ-ind {A} {B} {P} = λ (f : ∀ (a : A) (b : B a) → P (a , b)) →
λ (z : Σ A B) → f (π₁ z) (π₂ z)
-- cartesion product type
_×_ : Set → Set → Set
A × B = Σ a ∶ A , B
×-ind : ∀ {A : Set} {B : Set} {P : A × B → Set} →
(∀ (a : A) (b : B) → P (a , b)) → ∀ (z : A × B) → P z
×-ind {A} {B} {P} = Σ-ind {A} {λ (a : A) → B} {P}
-- ------------------------------------
-- the coproduct type
data _⊎_ (A : Set) (B : Set) : Set where
inl : A → A ⊎ B
inr : B → A ⊎ B
⊎-ind : ∀ {A : Set} {B : Set} {P : A ⊎ B → Set} →
(∀ (a : A) → P (inl a)) → (∀ (b : B) → P (inr b)) →
∀ (u : A ⊎ B) → P u
⊎-ind f _ (inl x) = f x
⊎-ind _ g (inr y) = g y
| 27.165414
| 78
| 0.443952
|
0e03e0a0b8e1f38f380d61fc2c5d20885d97859e
| 4,722
|
agda
|
Agda
|
Cubical/DStructures/Structures/Higher.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/DStructures/Structures/Higher.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/DStructures/Structures/Higher.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.Higher where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
open import Cubical.Homotopy.Base
open import Cubical.Homotopy.Connected
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Higher
open import Cubical.Algebra.Group.EilenbergMacLane1
open import Cubical.HITs.EilenbergMacLane1
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.DStructures.Meta.Isomorphism
open import Cubical.DStructures.Structures.Universe
open import Cubical.DStructures.Structures.Type
open import Cubical.DStructures.Structures.Group
open import Cubical.DStructures.Structures.Constant
private
variable
ℓ ℓ' : Level
𝒮ᴰ-connected : {ℓ : Level} (k : ℕ) → URGStrᴰ (𝒮-universe {ℓ}) (isConnected k) ℓ-zero
𝒮ᴰ-connected k =
Subtype→Sub-𝒮ᴰ (λ A → isConnected k A , isPropIsContr)
𝒮-universe
𝒮ᴰ-truncated : {ℓ : Level} (n : ℕ) → URGStrᴰ (𝒮-universe {ℓ}) (isOfHLevel n) ℓ-zero
𝒮ᴰ-truncated n =
Subtype→Sub-𝒮ᴰ (λ A → isOfHLevel n A , isPropIsOfHLevel n)
𝒮-universe
𝒮ᴰ-BGroup : (n k : ℕ)
→ URGStrᴰ (𝒮-universe {ℓ})
(λ A → A × (isConnected (k + 1) A) × (isOfHLevel (n + k + 2) A))
ℓ
𝒮ᴰ-BGroup n k =
combine-𝒮ᴰ 𝒮ᴰ-pointed
(combine-𝒮ᴰ (𝒮ᴰ-connected (k + 1))
(𝒮ᴰ-truncated (n + k + 2)))
𝒮-BGroup : (n k : ℕ) → URGStr (Σ[ A ∈ Type ℓ ] A × (isConnected (k + 1) A) × (isOfHLevel (n + k + 2) A)) ℓ
𝒮-BGroup n k = ∫⟨ 𝒮-universe ⟩ 𝒮ᴰ-BGroup n k
𝒮-1BGroup : URGStr 1BGroupΣ ℓ
𝒮-1BGroup = 𝒮-BGroup 0 1
𝒮-Iso-BGroup-Group : {ℓ : Level} → 𝒮-PIso (𝒮-group ℓ) 𝒮-1BGroup
RelIso.fun 𝒮-Iso-BGroup-Group G = EM₁ G , embase , EM₁Connected G , EM₁Groupoid G
RelIso.inv 𝒮-Iso-BGroup-Group = π₁-1BGroupΣ
RelIso.leftInv 𝒮-Iso-BGroup-Group = π₁EM₁≃
RelIso.rightInv 𝒮-Iso-BGroup-Group BG = basetype-≅ , basepoint-≅ , tt , tt
where
-- notation
type = fst BG
* = fst (snd BG)
conn = fst (snd (snd BG))
trunc = snd (snd (snd BG))
BG' = (bgroup (type , *) conn trunc)
π₁BG : Group
π₁BG = π₁-1BGroupΣ BG
EM₁π₁BG : 1BGroupΣ
EM₁π₁BG = EM₁ π₁BG , embase , EM₁Connected π₁BG , EM₁Groupoid π₁BG
-- equivalences
basetype-≅ : EM₁ π₁BG ≃ type
fst basetype-≅ = EM₁-functor-lInv-function π₁BG BG' (GroupEquiv.hom (π₁EM₁≃ π₁BG))
snd basetype-≅ = EM₁-functor-lInv-onIso-isEquiv π₁BG BG' (π₁EM₁≃ π₁BG)
basepoint-≅ : * ≡ *
basepoint-≅ = refl
𝒮ᴰ-BGroupHom : (n k : ℕ) → URGStrᴰ (𝒮-BGroup {ℓ} n k ×𝒮 𝒮-BGroup {ℓ'} n k)
(λ (BG , BH) → BGroupHomΣ BG BH)
(ℓ-max ℓ ℓ')
𝒮ᴰ-BGroupHom n k =
make-𝒮ᴰ
(λ {(BG , BH)} {(BG' , BH')} f (((eᴳ , _) , eᴳ-pt , _), ((eᴴ , _) , eᴴ-pt , _)) f'
→ ((eᴴ , eᴴ-pt) ∘∙ f) ∙∼ (f' ∘∙ (eᴳ , eᴳ-pt)))
(λ {(BG , BH)} f → q {(BG , BH)} f)
contrSingl
where
module _ {(BG , BH) : BGroupΣ n k × BGroupΣ n k} (f : BGroupHomΣ BG BH) where
q : (id∙ (baseΣ BH) ∘∙ f) ∙∼ (f ∘∙ id∙ (baseΣ BG))
q = funExt∙⁻ (id∙ (baseΣ BH) ∘∙ f
≡⟨ ∘∙-idʳ f ⟩
f
≡⟨ sym (∘∙-idˡ f) ⟩
(f ∘∙ id∙ (baseΣ BG)) ∎)
module _ ((BG , BH) : BGroupΣ n k × BGroupΣ n k) (f : BGroupHomΣ BG BH) where
contrSingl : isContr (Σ[ f' ∈ BGroupHomΣ BG BH ] ((id∙ (baseΣ BH) ∘∙ f) ∙∼ (f' ∘∙ id∙ (baseΣ BG))))
contrSingl =
isContrRespectEquiv (Σ-cong-equiv-snd (λ f' → f ≡ f'
≃⟨ invEquiv (funExt∙≃ f f') ⟩
f ∙∼ f'
≃⟨ pathToEquiv (cong (_∙∼ f')
(sym (∘∙-idʳ f))
∙ cong ((id∙ (baseΣ BH) ∘∙ f) ∙∼_)
(sym (∘∙-idˡ f'))) ⟩
(id∙ (baseΣ BH) ∘∙ f) ∙∼ (f' ∘∙ id∙ (baseΣ BG)) ■))
(isContrSingl f)
| 37.776
| 113
| 0.532402
|
10691735209a294f0ff0ea081f6a8f2d2029a562
| 4,003
|
agda
|
Agda
|
internal/lob--2015-06-14--III.agda
|
JasonGross/lob
|
716129208eaf4fe3b5f629f95dde4254805942b3
|
[
"MIT"
] | 19
|
2015-07-17T17:53:30.000Z
|
2021-03-17T14:04:53.000Z
|
internal/lob--2015-06-14--III.agda
|
JasonGross/lob
|
716129208eaf4fe3b5f629f95dde4254805942b3
|
[
"MIT"
] | 1
|
2015-07-17T20:20:43.000Z
|
2015-07-17T20:20:43.000Z
|
internal/lob--2015-06-14--III.agda
|
JasonGross/lob
|
716129208eaf4fe3b5f629f95dde4254805942b3
|
[
"MIT"
] | 1
|
2015-07-17T18:53:37.000Z
|
2015-07-17T18:53:37.000Z
|
module lob--2015-06-14--III where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
record Σ {X : Set} (F : X → Set) : Set where
constructor _,_
field fst : X
snd : F fst
data ⊤ : Set where
unit : ⊤
data Tree (X : Set) : Set where
br : Tree X → Tree X → Tree X
leaf : X → Tree X
indtree : {X : Set} → (P : Tree X → Set)
→ ((s t : Tree X) → P s → P t → P (br s t))
→ ((x : X) → P (leaf x))
→ (t : Tree X) → P t
indtree P b l (br s t) = b s t (indtree P b l s) (indtree P b l t)
indtree P b l (leaf x) = l x
data Preterm : Set where
type : ℕ → Preterm
pi : Preterm → Preterm → Preterm
sig : Preterm → Preterm → Preterm
bot : Preterm
top : Preterm
unit : Preterm
var : ℕ → Preterm
lam : Preterm → Preterm → Preterm
app : Preterm → Preterm → Preterm
tree : Preterm → Preterm
br : Preterm → Preterm → Preterm → Preterm
leaf : Preterm → Preterm → Preterm
ind : Preterm → Preterm → Preterm → Preterm → Preterm → Preterm
‘λ→’ = lam
data _::_ : Preterm → Preterm → Set where
::type : (ℓ : ℕ) → type ℓ :: type (suc ℓ)
-- ...
□ : Preterm → Set
□ T = Σ \(t : Preterm) → t :: T
num : ℕ → Preterm
num 0 = leaf top unit
num (suc n) = br top unit (num n)
data List (X : Set) : Set where
nil : List X
_,_ : X → List X → List X
infixr 1 _,_
list : List Preterm → Preterm
list nil = leaf top unit
list (x , xs) = br top x (list xs)
cons : ℕ → List Preterm → Preterm
cons n xs = br top (num n) (list xs)
‘type’ : Preterm → Preterm
‘type’ n = cons 0 (n , nil)
‘pi’ : Preterm → Preterm → Preterm
‘pi’ x f = cons 1 (x , f , nil)
‘sig’ : Preterm → Preterm → Preterm
‘sig’ x f = cons 2 (x , f , nil)
‘bot’ : Preterm
‘bot’ = cons 3 nil
‘top’ : Preterm
‘top’ = cons 4 nil
‘unit’ : Preterm
‘unit’ = cons 5 nil
‘var’ : Preterm → Preterm
‘var’ n = cons 6 (n , nil)
‘lam’ : Preterm → Preterm → Preterm
‘lam’ t b = cons 7 (t , b , nil)
‘app’ : Preterm → Preterm → Preterm
‘app’ f x = cons 8 (f , x , nil)
‘tree’ : Preterm → Preterm
‘tree’ x = cons 9 (x , nil)
‘br’ : Preterm → Preterm → Preterm → Preterm
‘br’ x l r = cons 10 (x , l , r , nil)
‘leaf’ : Preterm → Preterm → Preterm
‘leaf’ x y = cons 11 (x , y , nil)
‘ind’ : Preterm → Preterm → Preterm → Preterm → Preterm → Preterm
‘ind’ x p b l t = cons 12 (x , p , b , l , t , nil)
‘Preterm’ : Preterm
‘Preterm’ = tree top
‘Preterm’::type₀ : ‘Preterm’ :: type 0
‘Preterm’::type₀ = {!!}
‘□’ : Preterm
‘□’ = {!!}
_‘→’_ : Preterm → Preterm → Preterm
A ‘→’ B = pi A {!!}
quot : Preterm → Preterm
quot (type n) = ‘type’ (num n)
quot (pi x f) = ‘pi’ (quot x) (quot f)
quot (sig x f) = ‘sig’ (quot x) (quot f)
quot bot = ‘bot’
quot top = ‘top’
quot unit = ‘unit’
quot (var n) = ‘var’ (num n)
quot (lam x b) = ‘lam’ (quot x) (quot b)
quot (app f x) = ‘app’ (quot f) (quot x)
quot (tree x) = ‘tree’ (quot x)
quot (br x l r) = ‘br’ (quot x) (quot l) (quot r)
quot (leaf x y) = ‘leaf’ (quot x) (quot y)
quot (ind x p b l t) = ‘ind’ (quot x) (quot p) (quot b) (quot l) (quot t)
‘quot’ : Preterm
‘quot’ = {!!}
‘‘→’’ : Preterm
‘‘→’’ = {!!}
⌜_⌝ = quot
_‘’_ = app
infixl 1 _‘’_
postulate
X : Set
‘X’ : Preterm
‘X’::type₀ : ‘X’ :: type 0
App : {‘A’ ‘B’ : Preterm}
→ □ (‘A’ ‘→’ ‘B’)
→ □ ‘A’
→ □ ‘B’
App □‘A→B’ □‘A’ = {!!}
‘App’ : Preterm
‘App’ = {!!}
Quot : {‘T’ : Preterm}
→ □ ‘T’
→ □ (‘□’ ‘’ ⌜ ‘T’ ⌝)
Quot □T = {!!}
‘Quot’ : Preterm
‘Quot’ = {!!}
‘L₀’ : Preterm
‘L₀’ = (‘λ→’ ‘Preterm’ ((‘app’ ⌜ ‘□’ ⌝ (‘app’ (var 0) (‘quot’ ‘’ (var 0)))) ‘’ ‘‘→’’ ‘’ ⌜ ‘X’ ⌝ ))
L : Preterm
L = (λ (h : Preterm) → (app ‘□’ (app h (⌜ h ⌝))) ‘→’ ‘X’) ‘L₀’
‘L’ = app ‘L₀’ ⌜ ‘L₀’ ⌝
Conv : □ (‘□’ ‘’ ⌜ L ⌝) → □ (‘□’ ‘’ ‘L’)
Conv = {!!}
‘Conv’ : Preterm
‘Conv’ = {!!}
postulate
f : □ ‘X’ → X
‘f’ : Preterm
d‘f’ : ‘f’ :: (app ‘□’ (quot ‘X’) ‘→’ ‘X’)
y : X
y = (λ (ℓ : □ L) → f (App ℓ (Conv (Quot ℓ))))
( ‘λ→’ (‘□’ ‘’ ‘L’) (‘f’ ‘’ (‘App’ ‘’ (var 0) ‘’ (‘Conv’ ‘’ (‘Quot’ ‘’ var 0))))
, {!!})
| 19.816832
| 98
| 0.501374
|
23cd34507e044066419c62b0e5c6ec740f6e9421
| 1,126
|
agda
|
Agda
|
src/Categories/Category/Exact.agda
|
Akshobhya1234/agda-categories
|
c202a616d4f376b11e8320e641c98db2ddc9d233
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Exact.agda
|
Akshobhya1234/agda-categories
|
c202a616d4f376b11e8320e641c98db2ddc9d233
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Exact.agda
|
Akshobhya1234/agda-categories
|
c202a616d4f376b11e8320e641c98db2ddc9d233
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
-- Exact category (https://ncatlab.org/nlab/show/exact+category)
-- is a regular category
-- in which every internal equivalence is a kernel pair
module Categories.Category.Exact where
open import Level
open import Categories.Category.Core
open import Categories.Diagram.Pullback
open import Categories.Category.Cocartesian
open import Categories.Object.Coproduct
open import Categories.Morphism
open import Categories.Category.Complete.Finitely using (FinitelyComplete)
open import Categories.Diagram.Coequalizer
open import Categories.Diagram.KernelPair
open import Categories.Category.Regular
open import Categories.Morphism.Regular
open import Categories.Object.InternalRelation
record Exact {o ℓ e : Level} (𝒞 : Category o ℓ e) : Set (suc (o ⊔ ℓ ⊔ e)) where
open Category 𝒞
open Pullback
open Coequalizer
open Equivalence
field
regular : Regular 𝒞
quotient : ∀ {X : Obj} (E : Equivalence 𝒞 X) → Coequalizer 𝒞 (R.p₁ E) (R.p₂ E)
effective : ∀ {X : Obj} (E : Equivalence 𝒞 X) → IsPullback 𝒞 (R.p₁ E) (R.p₂ E)
(arr (quotient E)) (arr (quotient E))
| 31.277778
| 84
| 0.742451
|
23621f6e4d1a6eed7aa690d0c0084c8e1992797a
| 1,593
|
agda
|
Agda
|
src/deriveUtil.agda
|
shinji-kono/automaton-in-agda
|
eba0538f088f3d0c0fedb19c47c081954fbc69cb
|
[
"MIT"
] | null | null | null |
src/deriveUtil.agda
|
shinji-kono/automaton-in-agda
|
eba0538f088f3d0c0fedb19c47c081954fbc69cb
|
[
"MIT"
] | null | null | null |
src/deriveUtil.agda
|
shinji-kono/automaton-in-agda
|
eba0538f088f3d0c0fedb19c47c081954fbc69cb
|
[
"MIT"
] | null | null | null |
module deriveUtil 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 regex
open import automaton
open import nfa
open import logic
open NAutomaton
open Automaton
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import Relation.Nullary
open Bool
data alpha2 : Set where
a : alpha2
b : alpha2
a-eq? : (x y : alpha2) → Dec (x ≡ y)
a-eq? a a = yes refl
a-eq? b b = yes refl
a-eq? a b = no (λ ())
a-eq? b a = no (λ ())
open Regex
open import finiteSet
fin-a : FiniteSet alpha2
fin-a = record {
finite = finite0
; Q←F = Q←F0
; F←Q = F←Q0
; finiso→ = finiso→0
; finiso← = finiso←0
} where
finite0 : ℕ
finite0 = 2
Q←F0 : Fin finite0 → alpha2
Q←F0 zero = a
Q←F0 (suc zero) = b
F←Q0 : alpha2 → Fin finite0
F←Q0 a = # 0
F←Q0 b = # 1
finiso→0 : (q : alpha2) → Q←F0 ( F←Q0 q ) ≡ q
finiso→0 a = refl
finiso→0 b = refl
finiso←0 : (f : Fin finite0 ) → F←Q0 ( Q←F0 f ) ≡ f
finiso←0 zero = refl
finiso←0 (suc zero) = refl
open import derive alpha2 fin-a a-eq?
test11 = regex→automaton ( < a > & < b > )
test12 = accept test11 record { state = < a > & < b > ; is-derived = unit } ( a ∷ b ∷ [] )
test13 = accept test11 record { state = < a > & < b > ; is-derived = unit } ( a ∷ a ∷ [] )
test14 = regex-match ( ( < a > & < b > ) * ) ( a ∷ b ∷ a ∷ a ∷ [] )
test15 = regex-derive ( ( < a > & < b > ) * ∷ [] )
test16 = regex-derive test15
test17 : regex-derive test16 ≡ test16
test17 = refl
| 22.757143
| 91
| 0.578782
|
d0bd3e744881b231af1ecfcdb32b6e8f3cb932f8
| 203
|
agda
|
Agda
|
test/Succeed/Issue2243.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2243.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2243.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-10-08, issue #2243
-- {-# OPTIONS -v tc.cover.cover:100 #-}
open import Agda.Builtin.Char
f : Char → Char
f 'x' = 'x'
f 'x' = 'y' -- should be marked as unreachable clause
f _ = 's'
| 18.454545
| 54
| 0.605911
|
dcf4e68d4b2f3eb99fba732a19a1cadf54fb742d
| 17,140
|
agda
|
Agda
|
Cubical/HITs/Truncation/Properties.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Truncation/Properties.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Truncation/Properties.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Truncation.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Equiv.PathSplit
open isPathSplitEquiv
open import Cubical.Modalities.Modality
open Modality
open import Cubical.Data.Empty as ⊥ using (⊥)
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.NatMinusOne as ℕ₋₁
open import Cubical.Data.Sigma
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.Nullification as Null hiding (rec; elim)
open import Cubical.HITs.Truncation.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc
renaming (∥_∥ to ∥_∥₁; ∣_∣ to ∣_∣₁; squash to squash₁) using ()
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂)
open import Cubical.HITs.GroupoidTruncation as GpdTrunc using (∥_∥₃; ∣_∣₃; squash₃)
open import Cubical.HITs.2GroupoidTruncation as 2GpdTrunc using (∥_∥₄; ∣_∣₄; squash₄)
private
variable
ℓ ℓ' : Level
A B : Type ℓ
sphereFill : (n : ℕ₋₁) (f : S n → A) → Type _
sphereFill {A = A} n f = Σ[ top ∈ A ] ((x : S n) → top ≡ f x)
isSphereFilled : ℕ₋₁ → Type ℓ → Type ℓ
isSphereFilled n A = (f : S n → A) → sphereFill n f
isSphereFilledTrunc : {n : HLevel} → isSphereFilled (-1+ n) (hLevelTrunc n A)
isSphereFilledTrunc {n = zero} f = hub f , ⊥.elim
isSphereFilledTrunc {n = suc n} f = hub f , spoke f
isSphereFilled→isOfHLevelSuc : {n : HLevel} → isSphereFilled (ℕ→ℕ₋₁ n) A → isOfHLevel (suc n) A
isSphereFilled→isOfHLevelSuc {A = A} {zero} h x y = sym (snd (h f) north) ∙ snd (h f) south
where
f : Susp ⊥ → A
f north = x
f south = y
isSphereFilled→isOfHLevelSuc {A = A} {suc n} h x y = isSphereFilled→isOfHLevelSuc (helper h x y)
where
helper : isSphereFilled (ℕ→ℕ₋₁ (suc n)) A → (x y : A) → isSphereFilled (ℕ→ℕ₋₁ n) (x ≡ y)
helper h x y f = sym p ∙ q , r
where
f' : Susp (S (ℕ→ℕ₋₁ n)) → A
f' north = x
f' south = y
f' (merid u i) = f u i
p = snd (h f') north
q = snd (h f') south
r : (s : S (ℕ→ℕ₋₁ n)) → sym p ∙ q ≡ f s
r s i j = hcomp (λ k → λ { (i = i0) → compPath-filler (sym p) q k j
; (i = i1) → snd (h f') (merid s j) k
; (j = i0) → p (k ∨ ~ i)
; (j = i1) → q k })
(p (~ i ∧ ~ j))
isOfHLevel→isSphereFilled : {n : HLevel} → isOfHLevel n A → isSphereFilled (-1+ n) A
isOfHLevel→isSphereFilled {n = zero} h f = fst h , λ _ → snd h _
isOfHLevel→isSphereFilled {n = suc zero} h f = f north , λ _ → h _ _
isOfHLevel→isSphereFilled {A = A} {suc (suc n)} h = helper λ x y → isOfHLevel→isSphereFilled (h x y)
where
helper : {n : HLevel} → ((x y : A) → isSphereFilled (-1+ n) (x ≡ y)) → isSphereFilled (suc₋₁ (-1+ n)) A
helper {n} h f = l , r
where
l : A
l = f north
f' : S (-1+ n) → f north ≡ f south
f' x i = f (merid x i)
h' : sphereFill (-1+ n) f'
h' = h (f north) (f south) f'
r : (x : S (suc₋₁ (-1+ n))) → l ≡ f x
r north = refl
r south = h' .fst
r (merid x i) j = hcomp (λ k → λ { (i = i0) → f north
; (i = i1) → h' .snd x (~ k) j
; (j = i0) → f north
; (j = i1) → f (merid x i) })
(f (merid x (i ∧ j)))
-- isNull (S n) A ≃ (isSphereFilled n A) × (∀ (x y : A) → isSphereFilled n (x ≡ y))
isOfHLevel→isSnNull : {n : HLevel} → isOfHLevel n A → isNull (S (-1+ n)) A
fst (sec (isOfHLevel→isSnNull h)) f = fst (isOfHLevel→isSphereFilled h f)
snd (sec (isOfHLevel→isSnNull h)) f i s = snd (isOfHLevel→isSphereFilled h f) s i
fst (secCong (isOfHLevel→isSnNull h) x y) p = fst (isOfHLevel→isSphereFilled (isOfHLevelPath _ h x y) (funExt⁻ p))
snd (secCong (isOfHLevel→isSnNull h) x y) p i j s = snd (isOfHLevel→isSphereFilled (isOfHLevelPath _ h x y) (funExt⁻ p)) s i j
isSnNull→isOfHLevel : {n : HLevel} → isNull (S (-1+ n)) A → isOfHLevel n A
isSnNull→isOfHLevel {n = zero} nA = fst (sec nA) ⊥.rec , λ y → fst (secCong nA _ y) (funExt ⊥.elim)
isSnNull→isOfHLevel {n = suc n} nA = isSphereFilled→isOfHLevelSuc (λ f → fst (sec nA) f , λ s i → snd (sec nA) f i s)
isOfHLevelTrunc : (n : HLevel) → isOfHLevel n (hLevelTrunc n A)
isOfHLevelTrunc zero = hub ⊥.rec , λ _ → ≡hub ⊥.rec
isOfHLevelTrunc (suc n) = isSphereFilled→isOfHLevelSuc isSphereFilledTrunc
-- isOfHLevelTrunc n = isSnNull→isOfHLevel isNull-Null
-- hLevelTrunc n is a modality
rec : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel n B →
(A → B) →
hLevelTrunc n A →
B
rec h = Null.rec (isOfHLevel→isSnNull h)
elim : {n : HLevel}
{B : hLevelTrunc n A → Type ℓ'}
(hB : (x : hLevelTrunc n A) → isOfHLevel n (B x))
(g : (a : A) → B (∣ a ∣))
(x : hLevelTrunc n A) →
B x
elim hB = Null.elim (λ x → isOfHLevel→isSnNull (hB x))
elim2 : {n : HLevel}
{B : hLevelTrunc n A → hLevelTrunc n A → Type ℓ'}
(hB : ((x y : hLevelTrunc n A) → isOfHLevel n (B x y)))
(g : (a b : A) → B ∣ a ∣ ∣ b ∣)
(x y : hLevelTrunc n A) →
B x y
elim2 {n = n} hB g =
elim (λ _ → isOfHLevelΠ n (λ _ → hB _ _))
(λ a → elim (λ _ → hB _ _) (λ b → g a b))
elim3 : {n : HLevel}
{B : (x y z : hLevelTrunc n A) → Type ℓ'}
(hB : ((x y z : hLevelTrunc n A) → isOfHLevel n (B x y z)))
(g : (a b c : A) → B (∣ a ∣) ∣ b ∣ ∣ c ∣)
(x y z : hLevelTrunc n A) →
B x y z
elim3 {n = n} hB g =
elim2 (λ _ _ → isOfHLevelΠ n (hB _ _))
(λ a b → elim (λ _ → hB _ _ _) (λ c → g a b c))
HLevelTruncModality : ∀ {ℓ} (n : HLevel) → Modality ℓ
isModal (HLevelTruncModality n) = isOfHLevel n
isModalIsProp (HLevelTruncModality n) = isPropIsOfHLevel n
◯ (HLevelTruncModality n) = hLevelTrunc n
◯-isModal (HLevelTruncModality n) = isOfHLevelTrunc n
η (HLevelTruncModality n) = ∣_∣
◯-elim (HLevelTruncModality n) = elim
◯-elim-β (HLevelTruncModality n) = λ _ _ _ → refl
◯-=-isModal (HLevelTruncModality n) = isOfHLevelPath n (isOfHLevelTrunc n)
truncIdempotentIso : (n : HLevel) → isOfHLevel n A → Iso A (hLevelTrunc n A)
truncIdempotentIso n hA = isModalToIso (HLevelTruncModality n) hA
truncIdempotent≃ : (n : HLevel) → isOfHLevel n A → A ≃ hLevelTrunc n A
truncIdempotent≃ n hA = ∣_∣ , isModalToIsEquiv (HLevelTruncModality n) hA
truncIdempotent : (n : HLevel) → isOfHLevel n A → hLevelTrunc n A ≡ A
truncIdempotent n hA = ua (invEquiv (truncIdempotent≃ n hA))
-- universal property
univTrunc : ∀ {ℓ} (n : HLevel) {B : TypeOfHLevel ℓ n} → Iso (hLevelTrunc n A → B .fst) (A → B .fst)
Iso.fun (univTrunc n {B , lev}) g a = g ∣ a ∣
Iso.inv (univTrunc n {B , lev}) = elim λ _ → lev
Iso.rightInv (univTrunc n {B , lev}) b = refl
Iso.leftInv (univTrunc n {B , lev}) b = funExt (elim (λ x → isOfHLevelPath _ lev _ _)
λ a → refl)
-- functorial action
map : {n : HLevel} {B : Type ℓ'} (g : A → B)
→ hLevelTrunc n A → hLevelTrunc n B
map g = rec (isOfHLevelTrunc _) (λ a → ∣ g a ∣)
mapCompIso : {n : HLevel} {B : Type ℓ'} → (Iso A B) → Iso (hLevelTrunc n A) (hLevelTrunc n B)
Iso.fun (mapCompIso g) = map (Iso.fun g)
Iso.inv (mapCompIso g) = map (Iso.inv g)
Iso.rightInv (mapCompIso g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ b → cong ∣_∣ (Iso.rightInv g b)
Iso.leftInv (mapCompIso g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ a → cong ∣_∣ (Iso.leftInv g a)
mapId : {n : HLevel} → ∀ t → map {n = n} (idfun A) t ≡ t
mapId {n = n} =
elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) (λ _ → refl)
-- equivalences to prop/set/groupoid truncations
propTruncTrunc1Iso : Iso ∥ A ∥₁ (∥ A ∥ 1)
Iso.fun propTruncTrunc1Iso = PropTrunc.elim (λ _ → isOfHLevelTrunc 1) ∣_∣
Iso.inv propTruncTrunc1Iso = elim (λ _ → squash₁) ∣_∣₁
Iso.rightInv propTruncTrunc1Iso = elim (λ _ → isOfHLevelPath 1 (isOfHLevelTrunc 1) _ _) (λ _ → refl)
Iso.leftInv propTruncTrunc1Iso = PropTrunc.elim (λ _ → isOfHLevelPath 1 squash₁ _ _) (λ _ → refl)
propTrunc≃Trunc1 : ∥ A ∥₁ ≃ ∥ A ∥ 1
propTrunc≃Trunc1 = isoToEquiv propTruncTrunc1Iso
propTrunc≡Trunc1 : ∥ A ∥₁ ≡ ∥ A ∥ 1
propTrunc≡Trunc1 = ua propTrunc≃Trunc1
setTruncTrunc2Iso : Iso ∥ A ∥₂ (∥ A ∥ 2)
Iso.fun setTruncTrunc2Iso = SetTrunc.elim (λ _ → isOfHLevelTrunc 2) ∣_∣
Iso.inv setTruncTrunc2Iso = elim (λ _ → squash₂) ∣_∣₂
Iso.rightInv setTruncTrunc2Iso = elim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _) (λ _ → refl)
Iso.leftInv setTruncTrunc2Iso = SetTrunc.elim (λ _ → isOfHLevelPath 2 squash₂ _ _) (λ _ → refl)
setTrunc≃Trunc2 : ∥ A ∥₂ ≃ ∥ A ∥ 2
setTrunc≃Trunc2 = isoToEquiv setTruncTrunc2Iso
propTrunc≡Trunc2 : ∥ A ∥₂ ≡ ∥ A ∥ 2
propTrunc≡Trunc2 = ua setTrunc≃Trunc2
groupoidTrunc≃Trunc3Iso : Iso ∥ A ∥₃ (∥ A ∥ 3)
Iso.fun groupoidTrunc≃Trunc3Iso = GpdTrunc.elim (λ _ → isOfHLevelTrunc 3) ∣_∣
Iso.inv groupoidTrunc≃Trunc3Iso = elim (λ _ → squash₃) ∣_∣₃
Iso.rightInv groupoidTrunc≃Trunc3Iso = elim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) (λ _ → refl)
Iso.leftInv groupoidTrunc≃Trunc3Iso = GpdTrunc.elim (λ _ → isOfHLevelPath 3 squash₃ _ _) (λ _ → refl)
groupoidTrunc≃Trunc3 : ∥ A ∥₃ ≃ ∥ A ∥ 3
groupoidTrunc≃Trunc3 = isoToEquiv groupoidTrunc≃Trunc3Iso
groupoidTrunc≡Trunc3 : ∥ A ∥₃ ≡ ∥ A ∥ 3
groupoidTrunc≡Trunc3 = ua groupoidTrunc≃Trunc3
2GroupoidTrunc≃Trunc4Iso : Iso ∥ A ∥₄ (∥ A ∥ 4)
Iso.fun 2GroupoidTrunc≃Trunc4Iso = 2GpdTrunc.elim (λ _ → isOfHLevelTrunc 4) ∣_∣
Iso.inv 2GroupoidTrunc≃Trunc4Iso = elim (λ _ → squash₄) ∣_∣₄
Iso.rightInv 2GroupoidTrunc≃Trunc4Iso = elim (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _) (λ _ → refl)
Iso.leftInv 2GroupoidTrunc≃Trunc4Iso = 2GpdTrunc.elim (λ _ → isOfHLevelPath 4 squash₄ _ _) (λ _ → refl)
2GroupoidTrunc≃Trunc4 : ∥ A ∥₄ ≃ ∥ A ∥ 4
2GroupoidTrunc≃Trunc4 =
isoToEquiv
(iso
(2GpdTrunc.elim (λ _ → isOfHLevelTrunc 4) ∣_∣)
(elim (λ _ → squash₄) ∣_∣₄)
(elim (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _) (λ _ → refl))
(2GpdTrunc.elim (λ _ → isOfHLevelPath 4 squash₄ _ _) (λ _ → refl)))
2GroupoidTrunc≡Trunc4 : ∥ A ∥₄ ≡ ∥ A ∥ 4
2GroupoidTrunc≡Trunc4 = ua 2GroupoidTrunc≃Trunc4
isContr→isContrTrunc : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A → isContr (hLevelTrunc n A)
isContr→isContrTrunc n contr = ∣ fst contr ∣ , (elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → cong ∣_∣ (snd contr a))
truncOfProdIso : (n : ℕ) → Iso (hLevelTrunc n (A × B)) (hLevelTrunc n A × hLevelTrunc n B)
Iso.fun (truncOfProdIso n) = rec (isOfHLevelΣ n (isOfHLevelTrunc n) (λ _ → isOfHLevelTrunc n)) λ {(a , b) → ∣ a ∣ , ∣ b ∣}
Iso.inv (truncOfProdIso n) (a , b) = rec (isOfHLevelTrunc n)
(λ a → rec (isOfHLevelTrunc n)
(λ b → ∣ a , b ∣)
b)
a
Iso.rightInv (truncOfProdIso n) (a , b) =
elim {B = λ a → Iso.fun (truncOfProdIso n) (Iso.inv (truncOfProdIso n) (a , b)) ≡ (a , b)}
(λ _ → isOfHLevelPath n (isOfHLevelΣ n (isOfHLevelTrunc n) (λ _ → isOfHLevelTrunc n)) _ _)
(λ a → elim {B = λ b → Iso.fun (truncOfProdIso n) (Iso.inv (truncOfProdIso n) (∣ a ∣ , b)) ≡ (∣ a ∣ , b)}
(λ _ → isOfHLevelPath n (isOfHLevelΣ n (isOfHLevelTrunc n) (λ _ → isOfHLevelTrunc n)) _ _)
(λ b → refl) b) a
Iso.leftInv (truncOfProdIso n) = elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → refl
---- ∥ Ω A ∥ ₙ ≡ Ω ∥ A ∥ₙ₊₁ ----
abstract
isOfHLevelTypeOfHLevel2 : ∀ n → isOfHLevel (suc n) (TypeOfHLevel ℓ n)
isOfHLevelTypeOfHLevel2 n = isOfHLevelTypeOfHLevel n
{- Proofs of Theorem 7.3.12. and Corollary 7.3.13. in the HoTT book -}
module ΩTrunc where
{- We define the fibration P to show a more general result -}
P : {X : Type ℓ} {n : HLevel} → ∥ X ∥ (suc n) → ∥ X ∥ (suc n) → Type ℓ
P {n = n} x y = elim2 (λ _ _ → isOfHLevelTypeOfHLevel2 (n))
(λ a b → ∥ a ≡ b ∥ n , isOfHLevelTrunc (n)) x y .fst
{- We will need P to be of hLevel n + 3 -}
hLevelP : {n : HLevel} (a b : ∥ B ∥ (suc n)) → isOfHLevel ((suc n)) (P a b)
hLevelP {n = n} =
elim2 (λ x y → isProp→isOfHLevelSuc (n) (isPropIsOfHLevel (suc n)))
(λ a b → isOfHLevelSuc (n) (isOfHLevelTrunc (n)))
{- decode function from P x y to x ≡ y -}
decode-fun : {n : HLevel} (x y : ∥ B ∥ (suc n)) → P x y → x ≡ y
decode-fun {n = n} =
elim2 (λ u v → isOfHLevelΠ (suc n)
(λ _ → isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)) u v))
decode*
where
decode* : ∀ {n : HLevel} (u v : B)
→ P {n = n} ∣ u ∣ ∣ v ∣ → Path (∥ B ∥ (suc n)) ∣ u ∣ ∣ v ∣
decode* {B = B} {n = zero} u v =
rec ( isOfHLevelTrunc 1 ∣ u ∣ ∣ v ∣
, λ _ → isOfHLevelSuc 1 (isOfHLevelTrunc 1) _ _ _ _) (cong ∣_∣)
decode* {n = suc n} u v =
rec (isOfHLevelTrunc (suc (suc n)) ∣ u ∣ ∣ v ∣) (cong ∣_∣)
{- auxiliary function r used to define encode -}
r : {m : HLevel} (u : ∥ B ∥ (suc m)) → P u u
r = elim (λ x → hLevelP x x) (λ a → ∣ refl ∣)
{- encode function from x ≡ y to P x y -}
encode-fun : {n : HLevel} (x y : ∥ B ∥ (suc n)) → x ≡ y → P x y
encode-fun x y p = transport (λ i → P x (p i)) (r x)
{- We need the following two lemmas on the functions behaviour for refl -}
dec-refl : {n : HLevel} (x : ∥ B ∥ (suc n)) → decode-fun x x (r x) ≡ refl
dec-refl {n = zero} =
elim (λ x → isOfHLevelSuc 1 (isOfHLevelSuc 1 (isOfHLevelTrunc 1) x x) _ _) (λ _ → refl)
dec-refl {n = suc n} =
elim (λ x → isOfHLevelSuc (suc n)
(isOfHLevelSuc (suc n)
(isOfHLevelTrunc (suc (suc n)) x x)
(decode-fun x x (r x)) refl))
(λ _ → refl)
enc-refl : {n : HLevel} (x : ∥ B ∥ (suc n)) → encode-fun x x refl ≡ r x
enc-refl x j = transp (λ _ → P x x) j (r x)
{- decode-fun is a right-inverse -}
P-rinv : {n : HLevel} (u v : ∥ B ∥ (suc n)) (x : Path (∥ B ∥ (suc n)) u v)
→ decode-fun u v (encode-fun u v x) ≡ x
P-rinv u v = J (λ y p → decode-fun u y (encode-fun u y p) ≡ p)
(cong (decode-fun u u) (enc-refl u) ∙ dec-refl u)
{- decode-fun is a left-inverse -}
P-linv : {n : HLevel} (u v : ∥ B ∥ (suc n )) (x : P u v)
→ encode-fun u v (decode-fun u v x) ≡ x
P-linv {n = n} =
elim2 (λ x y → isOfHLevelΠ (suc n)
(λ z → isOfHLevelSuc (suc n) (hLevelP x y) _ _))
helper
where
helper : {n : HLevel} (a b : B) (p : P {n = n} ∣ a ∣ ∣ b ∣)
→ encode-fun _ _ (decode-fun ∣ a ∣ ∣ b ∣ p) ≡ p
helper {n = zero} a b =
elim (λ x → ( sym (isOfHLevelTrunc 0 .snd _) ∙ isOfHLevelTrunc 0 .snd x
, λ y → isOfHLevelSuc 1 (isOfHLevelSuc 0 (isOfHLevelTrunc 0)) _ _ _ _))
(J (λ y p → encode-fun ∣ a ∣ ∣ y ∣ (decode-fun _ _ ∣ p ∣) ≡ ∣ p ∣)
(enc-refl ∣ a ∣))
helper {n = suc n} a b =
elim (λ x → hLevelP {n = suc n} ∣ a ∣ ∣ b ∣ _ _)
(J (λ y p → encode-fun {n = suc n} ∣ a ∣ ∣ y ∣ (decode-fun _ _ ∣ p ∣) ≡ ∣ p ∣)
(enc-refl ∣ a ∣))
{- The final Iso established -}
IsoFinal : (n : HLevel) (x y : ∥ B ∥ (suc n)) → Iso (x ≡ y) (P x y)
Iso.fun (IsoFinal _ x y) = encode-fun x y
Iso.inv (IsoFinal _ x y) = decode-fun x y
Iso.rightInv (IsoFinal _ x y) = P-linv x y
Iso.leftInv (IsoFinal _ x y) = P-rinv x y
PathIdTrunc : {a b : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ b ∣) ≡ (∥ a ≡ b ∥ n)
PathIdTrunc n = isoToPath (ΩTrunc.IsoFinal n _ _)
PathΩ : {a : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ a ∣) ≡ (∥ a ≡ a ∥ n)
PathΩ n = PathIdTrunc n
{- Special case using direct defs of truncations -}
PathIdTrunc₀Iso : {a b : A} → Iso (∣ a ∣₂ ≡ ∣ b ∣₂) ∥ a ≡ b ∥₁
PathIdTrunc₀Iso = compIso (congIso setTruncTrunc2Iso)
(compIso (ΩTrunc.IsoFinal _ ∣ _ ∣ ∣ _ ∣)
(invIso propTruncTrunc1Iso))
-------------------------
truncOfTruncIso : (n m : HLevel) → Iso (hLevelTrunc n A) (hLevelTrunc n (hLevelTrunc (m + n) A))
Iso.fun (truncOfTruncIso n m) = elim (λ _ → isOfHLevelTrunc n) λ a → ∣ ∣ a ∣ ∣
Iso.inv (truncOfTruncIso {A = A} n m) =
elim (λ _ → isOfHLevelTrunc n)
(elim (λ _ → (isOfHLevelPlus m (isOfHLevelTrunc n )))
λ a → ∣ a ∣)
Iso.rightInv (truncOfTruncIso {A = A} n m) =
elim (λ x → isOfHLevelPath n (isOfHLevelTrunc n) _ _ )
(elim (λ x → isOfHLevelPath (m + n) (isOfHLevelPlus m (isOfHLevelTrunc n)) _ _ )
λ a → refl)
Iso.leftInv (truncOfTruncIso n m) = elim (λ x → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → refl
truncOfTruncEq : (n m : ℕ) → (hLevelTrunc n A) ≃ (hLevelTrunc n (hLevelTrunc (m + n) A))
truncOfTruncEq n m = isoToEquiv (truncOfTruncIso n m)
| 43.173804
| 131
| 0.578705
|
39569708c11c34c18312220c15c5ec3c51dceaa6
| 1,531
|
agda
|
Agda
|
theorems/cw/Degree.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/cw/Degree.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/cw/Degree.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import cw.CW
open import homotopy.PinSn
module cw.Degree
{i} {n : ℕ} (skel : Skeleton {i} (S (S n)))
(skel-has-dec-cells : has-dec-cells skel)
(skel-is-aligned : is-aligned skel)
-- the cells at the upper and lower dimensions
(upper : cells-last skel)
(lower : cells-nth (inr ltS) skel)
where
private
lower-skel = cw-take (inr ltS) skel
lower-cells = cells-last lower-skel
lower-cells-has-dec-eq = snd (fst skel-has-dec-cells)
-- squash the lower CW complex except one of its cells [lower]
cw-squash-lower-to-Sphere : ⟦ lower-skel ⟧ → Sphere (S n)
cw-squash-lower-to-Sphere = Attached-rec (λ _ → north) squash-hubs squash-spokes where
-- squash cells except [lower]
squash-hubs : lower-cells → Sphere (S n)
squash-hubs c with lower-cells-has-dec-eq c lower
... | (inl _) = south
... | (inr _) = north
-- squash cells except [lower]
squash-spokes : (c : lower-cells) → Sphere n
→ north == squash-hubs c
squash-spokes c s with lower-cells-has-dec-eq c lower
... | (inl _) = merid s
... | (inr _) = idp
degree-map : Sphere (S n) → Sphere (S n)
degree-map = cw-squash-lower-to-Sphere ∘ attaching-last skel upper
degree-⊙map : fst (⊙Sphere (S n) ⊙→ ⊙Sphere (S n))
degree-⊙map = degree-map , ap cw-squash-lower-to-Sphere (! (snd (snd skel-is-aligned upper)))
degree' : ℤ → ℤ
degree' = transport Group.El (πₙ₊₁Sⁿ⁺¹ n)
∘ GroupHom.f (πS-fmap n degree-⊙map)
∘ transport! Group.El (πₙ₊₁Sⁿ⁺¹ n)
degree : ℤ
degree = degree' 1
| 31.244898
| 93
| 0.650555
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.