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
5e61e05a5b929dc0c4483ab96736888cffe2ff46
91
agda
Agda
archive/agda-1/OscarEverything.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-1/OscarEverything.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-1/OscarEverything.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module OscarEverything where open import OscarPrelude open import HasSubstantiveDischarge
18.2
35
0.89011
34477e0eed619aa31f2fbd9f02112374db88778f
3,790
agda
Agda
src/Categories/Adjoint/Instance/StrictCore.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
src/Categories/Adjoint/Instance/StrictCore.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
null
null
null
src/Categories/Adjoint/Instance/StrictCore.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Adjoint.Instance.StrictCore where -- The adjunction between the forgetful functor from (strict) Cats to -- (strict) Groupoids and the (strict) Core functor. open import Data.Product open import Level using (_⊔_) import Function open import Relation.Binary using (IsEquivalence) open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Categories.Adjoint open import Categories.Category using (Category) open import Categories.Category.Groupoid using (Groupoid) import Categories.Category.Construction.Core as C open import Categories.Category.Instance.StrictCats open import Categories.Category.Instance.StrictGroupoids open import Categories.Functor renaming (id to idF) open import Categories.Functor.Equivalence open import Categories.Functor.Instance.StrictCore import Categories.Morphism as Morphism import Categories.Morphism.Reasoning as MR open import Categories.Morphism.IsoEquiv using (⌞_⌟; _≃_) -- The forgetful functor from StrictGroupoids to StrictCats Forgetful : ∀ {o ℓ e} → Functor (Groupoids o ℓ e) (Cats o ℓ e) Forgetful {o} {ℓ} {e} = record { F₀ = Groupoid.category ; F₁ = Function.id ; identity = λ {G} → Groupoids.Equiv.refl {G} {G} {idF} ; homomorphism = λ {G H K F H} → Groupoids.Equiv.refl {G} {K} {H ∘F F} ; F-resp-≈ = Function.id } where module Groupoids = Category (Groupoids o ℓ e) -- Core is right-adjoint to the forgetful functor from Groupoids to -- Cats CoreAdj : ∀ {o ℓ e} → Forgetful {o} {ℓ ⊔ e} {e} ⊣ Core CoreAdj = record { unit = record { η = unit ; commute = λ {G H} F → unit-commute {G} {H} F ; sym-commute = λ {G H} F → unit-sym-commute {G} {H} F } ; counit = record { η = counit ; commute = counit-commute ; sym-commute = counit-sym-commute } ; zig = λ {G} → zig {G} ; zag = zag } where open Groupoid using (category) module Core = Functor Core unit : ∀ G → Functor (category G) (C.Core (category G)) unit G = record { F₀ = Function.id ; F₁ = λ f → record { from = f ; to = f ⁻¹ ; iso = iso } ; identity = ⌞ Equiv.refl ⌟ ; homomorphism = ⌞ Equiv.refl ⌟ ; F-resp-≈ = ⌞_⌟ } where open Groupoid G unit-commute : ∀ {G H} (F : Functor (category G) (category H)) → unit H ∘F F ≡F Core.F₁ F ∘F unit G unit-commute {_} {H} F = record { eq₀ = λ _ → refl ; eq₁ = λ _ → ⌞ MR.id-comm-sym (category H) ⌟ } unit-sym-commute : ∀ {G H} (F : Functor (category G) (category H)) → Core.F₁ F ∘F unit G ≡F unit H ∘F F unit-sym-commute {_} {H} F = record { eq₀ = λ _ → refl ; eq₁ = λ _ → ⌞ MR.id-comm-sym (category H) ⌟ } counit : ∀ C → Functor (C.Core C) C counit C = record { F₀ = Function.id ; F₁ = _≅_.from ; identity = Equiv.refl ; homomorphism = Equiv.refl ; F-resp-≈ = _≃_.from-≈ } where open Category C open Morphism C counit-commute : ∀ {C D} (F : Functor C D) → counit D ∘F Core.F₁ F ≡F F ∘F counit C counit-commute {C} {D} F = record { eq₀ = λ _ → refl ; eq₁ = λ _ → MR.id-comm-sym D } counit-sym-commute : ∀ {C D} (F : Functor C D) → F ∘F counit C ≡F counit D ∘F Core.F₁ F counit-sym-commute {C} {D} F = record { eq₀ = λ _ → refl ; eq₁ = λ _ → MR.id-comm-sym D } zig : ∀ {G} → counit (category G) ∘F unit G ≡F idF zig {G} = record { eq₀ = λ _ → refl ; eq₁ = λ _ → MR.id-comm-sym (category G) } zag : ∀ {B} → Core.F₁ (counit B) ∘F unit (Core.F₀ B) ≡F idF zag {B} = record { eq₀ = λ _ → refl ; eq₁ = λ _ → ⌞ MR.id-comm-sym B ⌟ }
33.839286
136
0.588918
52f6af09ae18e0d2d68efef8a69e803a10ac86ce
298
agda
Agda
test/Fail/Issue2880.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2880.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2880.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --safe #-} module Issue2880 where app : {A : Set} → (A → A) → (A → A) app f x = f x {-# COMPILE GHC app = \ A f x -> f (app A f x) #-} mutual id : {A : Set} → A → A id x = x {-# COMPILE GHC id = id' #-} id' : {A : Set} → A → A id' x = x {-# COMPILE GHC id' = id #-}
14.190476
50
0.436242
8bab2a9e7e325e146c3f1f0706d36278344f3f3a
618
agda
Agda
test/Fail/SizeUnsolvedConstraintsInTypeSignature.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/SizeUnsolvedConstraintsInTypeSignature.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/SizeUnsolvedConstraintsInTypeSignature.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --sized-types #-} -- {-# OPTIONS -v tc.size.solve:20 -v tc.decl.ax:10 #-} module SizeUnsolvedConstraintsInTypeSignature where open import Common.Size data Nat : (i : Size) -> Set where Z : {i : Size} -> Nat (↑ i) S : {i : Size} -> Nat i → Nat (↑ i) one1 : (i : Size) → Nat (↑ (↑ i)) one1 i = S Z one2 : (i : Size) → Nat (↑ (↑ (↑ i))) one2 i = S Z postulate _≡_ : {A : Set} → A → A → Set works : (i : Size) → one2 i ≡ one1 i bug : (i : Size) → one1 i ≡ one2 i -- bug caused an interal error due to absense of range info -- should not print a proper error message (or better, work!)
24.72
63
0.567961
3495608ef4249ef729ef19826d5dfed5bb543435
19,672
agda
Agda
HoTT-UF.agda
howsiyu/hott-notes
3aa0425c12e2edeb284ab8588a2b25ea46ae4394
[ "BSD-2-Clause" ]
null
null
null
HoTT-UF.agda
howsiyu/hott-notes
3aa0425c12e2edeb284ab8588a2b25ea46ae4394
[ "BSD-2-Clause" ]
null
null
null
HoTT-UF.agda
howsiyu/hott-notes
3aa0425c12e2edeb284ab8588a2b25ea46ae4394
[ "BSD-2-Clause" ]
null
null
null
-- self-contained notes following https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html and relevant parts of HoTT book open import Agda.Primitive public using (Level ; _⊔_) renaming (Set to Type ; lzero to 𝓾₀ ; lsuc to _⁺) variable 𝓁 𝓂 𝓃 : Level Π : {X : Type 𝓁} (A : X → Type 𝓂) → Type (𝓁 ⊔ 𝓂) Π A = (x : _) → A x id : {X : Type 𝓁} → X → X id x = x _∘_ : {X : Type 𝓁} {Y : Type 𝓂} {Z : Y → Type 𝓃} → ((y : Y) → Z y) → (f : X → Y) → (x : X) → Z (f x) g ∘ f = λ x → g (f x) {-# INLINE _∘_ #-} infixr 50 _∘_ data ⊥ : Type where ⊥-induction : (A : ⊥ → Type 𝓁) → Π A ⊥-induction A () data ⊤ : Type where ⋆ : ⊤ ⊤-induction : (A : ⊤ → Type 𝓁) → A ⋆ → Π A ⊤-induction A a ⋆ = a data _+_ (X : Type 𝓁) (Y : Type 𝓂) : Type (𝓁 ⊔ 𝓂) where inl : X → X + Y inr : Y → X + Y +-induction : {X : Type 𝓁} {Y : Type 𝓂} (A : X + Y → Type 𝓃) → ((x : X) → A (inl x)) → ((y : Y) → A (inr y)) → Π A +-induction A f g (inl x) = f x +-induction A f g (inr y) = g y 𝟚 : Type 𝟚 = ⊤ + ⊤ pattern ₀ = inl ⋆ pattern ₁ = inr ⋆ record Σ {X : Type 𝓁} (Y : X → Type 𝓂) : Type (𝓁 ⊔ 𝓂) where constructor _,_ field fst : X snd : Y fst open Σ Σ-induction : {X : Type 𝓁} {Y : X → Type 𝓂} (A : Σ Y → Type 𝓃) → ((x : X) (y : Y x) → A (x , y)) → Π A Σ-induction A f (x , y) = f x y _×_ : Type 𝓁 → Type 𝓂 → Type (𝓁 ⊔ 𝓂) X × Y = Σ (λ (_ : X) → Y) data Id (X : Type 𝓁) (x : X) : X → Type 𝓁 where refl : Id X x x Id-induction : {X : Type 𝓁} {x : X} (A : (y : X) → Id X x y → Type 𝓂) → A x refl → (y : X) (p : Id X x y) → A y p Id-induction A σ _ refl = σ data Id2 (X : Type 𝓁) : X → X → Type 𝓁 where refl2 : (x : X) → Id2 X x x Id2-induction : {X : Type 𝓁} (A : (x y : X) → Id2 X x y → Type 𝓂) → ((x : X) → A x x (refl2 x)) → (x y : X) (p : Id2 X x y) → A x y p Id2-induction A σ x x (refl2 x) = σ x Id→Id2 : {X : Type 𝓁} → (x y : X) → Id X x y → Id2 X x y Id→Id2 x x refl = refl2 x Id2→Id : {X : Type 𝓁} → (x y : X) → Id2 X x y → Id X x y Id2→Id x x (refl2 x) = refl _≡_ : {X : Type 𝓁} (x y : X) → Type 𝓁 x ≡ y = Id _ x y infix 1 _≡_ sym : {X : Type 𝓁} {x y : X} → x ≡ y → y ≡ x sym refl = refl _∙_ : {X : Type 𝓁} {x y z : X} → x ≡ y → y ≡ z → x ≡ z refl ∙ refl = refl _∙∙_∙∙_ : {X : Type 𝓁} {x y z t : X} → x ≡ y → y ≡ z → z ≡ t → x ≡ t refl ∙∙ refl ∙∙ refl = refl _≡⟨_⟩_ : {X : Type 𝓁 } (x : X) {y z : X} → x ≡ y → y ≡ z → x ≡ z x ≡⟨ p ⟩ q = p ∙ q infixr 0 _≡⟨_⟩_ _∎ : {X : Type 𝓁} (x : X) → x ≡ x x ∎ = refl infix 1 _∎ transport : {X Y : Type 𝓁} → X ≡ Y → X → Y transport refl x = x subst : {X : Type 𝓁} (A : X → Type 𝓂) {x y : X} → x ≡ y → A x → A y subst A refl ax = ax module _ {X : Type 𝓁} {x : X} where refl-left : {y : X} (p : x ≡ y) → refl ∙ p ≡ p refl-left refl = refl refl-right : {y : X} (p : x ≡ y) → p ∙ refl ≡ p refl-right refl = refl ∙-assoc : {y z t : X} (p : x ≡ y) (q : y ≡ z) (r : z ≡ t) → (p ∙ q) ∙ r ≡ p ∙ (q ∙ r) ∙-assoc refl refl refl = refl sym-left : {y : X} (p : x ≡ y) → sym p ∙ p ≡ refl sym-left refl = refl sym-right : {y : X} (p : x ≡ y) → p ∙ sym p ≡ refl sym-right refl = refl sym-involutive : {y : X} (p : x ≡ y) → sym (sym p) ≡ p sym-involutive refl = refl ∙-cancel-left : {X : Type 𝓁} {x y z : X} {p : x ≡ y} {q r : y ≡ z} → p ∙ q ≡ p ∙ r → q ≡ r ∙-cancel-left {p = refl} {q = q} {r = r} s = sym (refl-left q) ∙∙ s ∙∙ refl-left r ∙-cancel-right : {X : Type 𝓁} {x y z : X} {p q : x ≡ y} {r : y ≡ z} → p ∙ r ≡ q ∙ r → p ≡ q ∙-cancel-right {p = p} {q = q} {r = refl} s = sym (refl-right p) ∙∙ s ∙∙ refl-right q module _ {X : Type 𝓁} {Y : Type 𝓂} (f : X → Y) where cong : {x y : X} → x ≡ y → f x ≡ f y cong refl = refl cong-refl : (x : X) → cong (refl {x = x}) ≡ refl cong-refl x = refl cong-sym : {x y : X} → (p : x ≡ y) → cong (sym p) ≡ sym (cong p) cong-sym refl = refl cong-∙ : {x y z : X} (p : x ≡ y) (q : y ≡ z) → cong (p ∙ q) ≡ cong p ∙ cong q cong-∙ refl refl = refl cong-id : {X : Type 𝓁} {x y : X} (p : x ≡ y) → cong id p ≡ p cong-id refl = refl cong-∘ : {X : Type 𝓁} {Y : Type 𝓂} {Z : Type 𝓃} (f : X → Y) (g : Y → Z) {x y : X} (p : x ≡ y) → cong (g ∘ f) p ≡ cong g (cong f p) cong-∘ f g refl = refl congd : {X : Type 𝓁} {Y : X → Type 𝓂} (f : Π Y) {x y : X} (p : x ≡ y) → subst Y p (f x) ≡ f y congd f refl = refl cong₂ : {X : Type 𝓁} {Y : Type 𝓂} {Z : Type 𝓃} (f : X → Y → Z) {x x' : X} → x ≡ x' → {y y' : Y} → y ≡ y' → f x y ≡ f x' y' cong₂ f refl refl = refl ¬_ : Type 𝓁 → Type 𝓁 ¬ A = A → ⊥ contrapositive : {X : Type 𝓁} {Y : Type 𝓂} → (X → Y) → ¬ Y → ¬ X contrapositive f p x = p (f x) decidable : Type 𝓁 → Type 𝓁 decidable A = A + (¬ A) onAllPaths : (Type 𝓁 → Type 𝓁) → Type 𝓁 → Type 𝓁 onAllPaths A X = (x y : X) → A (x ≡ y) discrete : Type 𝓁 → Type 𝓁 discrete = onAllPaths decidable ₁≢₀ : ¬ (₁ ≡ ₀) ₁≢₀ p = subst (λ { ₀ → ⊥ ; ₁ → ⊤ }) p ⋆ 𝟚-is-discrete : discrete 𝟚 𝟚-is-discrete ₀ ₀ = inl refl 𝟚-is-discrete ₀ ₁ = inr (contrapositive sym ₁≢₀) 𝟚-is-discrete ₁ ₀ = inr ₁≢₀ 𝟚-is-discrete ₁ ₁ = inl refl isCenter : (X : Type 𝓁) → X → Type 𝓁 isCenter X x = (y : X) → x ≡ y isContr : (X : Type 𝓁) → Type 𝓁 isContr X = Σ (isCenter X) ⊤-is-contr : isContr ⊤ ⊤-is-contr = ⋆ , λ { ⋆ → refl } surrounding : {X : Type 𝓁} (x : X) → Type 𝓁 surrounding x = Σ λ y → x ≡ y surrounding-is-contr : {X : Type 𝓁} (x : X) → isContr (surrounding x) surrounding-is-contr x = (x , refl) , λ { (.x , refl) → refl } isProp : (X : Type 𝓁) → Type 𝓁 isProp X = Π (isCenter X) ⊥-is-prop : isProp ⊥ ⊥-is-prop () ⊤-is-prop : isProp ⊤ ⊤-is-prop ⋆ ⋆ = refl isContr→isProp : {X : Type 𝓁} → isContr X → isProp X isContr→isProp (c , φ) x y = sym (φ x) ∙ φ y no-unicorns : (X : Type 𝓁) → isProp X → ¬ (isContr X) → ¬ ¬ X → ⊥ no-unicorns X φ ns ne = ne empty where empty : ¬ X empty x = ns (x , φ x) isSet : (X : Type 𝓁) → Type 𝓁 isSet = onAllPaths isProp ⊥-is-set : isSet ⊥ ⊥-is-set () ⊤-is-set : isSet ⊤ ⊤-is-set ⋆ ⋆ refl refl = refl ⊤-is-set' : isSet ⊤ ⊤-is-set' = ⊤-induction (λ x → (z : ⊤) → isProp (x ≡ z)) (Id-induction (λ y → isCenter (⋆ ≡ y)) (Id-induction refl-eq refl ⋆)) where refl-eq : (x : ⊤) → ⋆ ≡ x → Type refl-eq = ⊤-induction (λ x → ⋆ ≡ x → Type) (Id (⋆ ≡ ⋆) refl) wconstant : {X : Type 𝓁} {Y : Type 𝓂} → (X → Y) → Type (𝓁 ⊔ 𝓂) wconstant {X = X} f = (x y : X) → f x ≡ f y endo : Type 𝓁 → Type 𝓁 endo X = X → X wconstant-endo : Type 𝓁 → Type 𝓁 wconstant-endo X = Σ λ (f : endo X) → wconstant f Hedberg : {X : Type 𝓁} (x : X) → ((y : X) → wconstant-endo (x ≡ y)) → (y : X) → isProp (x ≡ y) Hedberg {X = X} x c y p q = p ≡⟨ sym (a y p) ⟩ sym (f x refl) ∙ f y p ≡⟨ cong (λ r → sym (f x refl) ∙ r) (c y .snd p q) ⟩ sym (f x refl) ∙ f y q ≡⟨ a y q ⟩ q ∎ where f : (z : X) → endo (x ≡ z) f z = c z .fst a : (z : X) (r : x ≡ z) → sym (f x refl) ∙ f z r ≡ r a x refl = sym-left (f x refl) isProp→wconstant-endos : {X : Type 𝓁} → isProp X → onAllPaths wconstant-endo X isProp→wconstant-endos φ x y = (λ _ → φ x y) , (λ _ _ → refl) isSet→wconstant-endos : {X : Type 𝓁} → isSet X → onAllPaths wconstant-endo X isSet→wconstant-endos φ x y = id , φ x y wconstant-endos→isSet : {X : Type 𝓁} → onAllPaths wconstant-endo X → isSet X wconstant-endos→isSet c x = Hedberg x (c x) isProp→isSet : {X : Type 𝓁} → isProp X → isSet X isProp→isSet = wconstant-endos→isSet ∘ isProp→wconstant-endos pointed→wconstant-endo : {X : Type 𝓁} → X → wconstant-endo X pointed→wconstant-endo x = (λ _ → x) , (λ _ _ → refl) empty→wconstant-endo : {X : Type 𝓁} → ¬ X → wconstant-endo X empty→wconstant-endo e = id , λ x → ⊥-induction _ (e x) decidable→wconstant-endo : {X : Type 𝓁} → decidable X → wconstant-endo X decidable→wconstant-endo (inl x) = pointed→wconstant-endo x decidable→wconstant-endo (inr e) = empty→wconstant-endo e discrete→wconstant-endos : {X : Type 𝓁} → discrete X → onAllPaths wconstant-endo X discrete→wconstant-endos φ x y = decidable→wconstant-endo (φ x y) discrete→isSet : {X : Type 𝓁} → discrete X → isSet X discrete→isSet = wconstant-endos→isSet ∘ discrete→wconstant-endos isContrΣ : {X : Type 𝓁} {Y : X → Type 𝓂} → isContr X → ((x : X) → isContr (Y x)) → isContr (Σ Y) isContrΣ {X = X} {Y = Y} (x₀ , c) cy = (x₀ , cy x₀ .fst) , λ { (x , y) → f (c x) (cy x .snd y) } where f : {x : X} {y : Y x} → x₀ ≡ x → cy x .fst ≡ y → (x₀ , cy x₀ .fst) ≡ (x , y) f refl refl = refl isPropΣ : {X : Type 𝓁} {Y : X → Type 𝓂} → isProp X → ((x : X) → isProp (Y x)) → isProp (Σ Y) isPropΣ {X = X} {Y = Y} φ ψ (x₀ , y₀) (x₁ , y₁) = f (φ x₀ x₁) (ψ x₁ (subst Y (φ x₀ x₁) y₀) y₁) where f : {x : X} {y : Y x} → (p : x₀ ≡ x) → subst Y p y₀ ≡ y → (x₀ , y₀) ≡ (x , y) f refl refl = refl _∼_ : {X : Type 𝓁} {Y : X → Type 𝓂} (f g : Π Y) → Type (𝓁 ⊔ 𝓂) f ∼ g = (x : _) → f x ≡ g x infix 2 _∼_ deformation-induces-natural-iso : {X : Type 𝓁} {f : X → X} (H : f ∼ id) {x y : X} (p : x ≡ y) → H x ∙ p ≡ cong f p ∙ H y deformation-induces-natural-iso H {x = x} refl = refl-right (H x) ∙ sym (refl-left (H x)) deformation-induces-iso : {X : Type 𝓁} (f : X → X) (H : f ∼ id) (x : X) → H (f x) ≡ cong f (H x) deformation-induces-iso f H x = ∙-cancel-right (deformation-induces-natural-iso H (H x)) retraction : {X : Type 𝓁} {Y : Type 𝓂} → (X → Y) → Type (𝓁 ⊔ 𝓂) retraction f = Σ λ g → g ∘ f ∼ id section : {X : Type 𝓁} {Y : Type 𝓂} → (X → Y) → Type (𝓁 ⊔ 𝓂) section f = Σ λ h → f ∘ h ∼ id _◁_ : Type 𝓁 → Type 𝓂 → Type (𝓁 ⊔ 𝓂) X ◁ Y = Σ λ (r : Y → X) → section r isContrRetract : {X : Type 𝓁} {Y : Type 𝓂} → Y ◁ X → isContr X → isContr Y isContrRetract {Y = Y} (r , (s , η)) (c , φ) = r c , d where d : isCenter Y (r c) d y = r c ≡⟨ cong r (φ (s y)) ⟩ r (s y) ≡⟨ η y ⟩ y ∎ isPropRetract : {X : Type 𝓁} {Y : Type 𝓂} → Y ◁ X → isProp X → isProp Y isPropRetract {Y = Y} (r , (s , η)) φ y₀ y₁ = y₀ ≡⟨ sym (η y₀) ⟩ r (s y₀) ≡⟨ cong r (φ (s y₀) (s y₁)) ⟩ r (s y₁) ≡⟨ η y₁ ⟩ y₁ ∎ Σ-retract : {X : Type 𝓁} (A : X → Type 𝓂) (B : X → Type 𝓃) → ((x : X) → A x ◁ B x) → Σ A ◁ Σ B Σ-retract A B ρ = r , (s , η) where r : Σ B → Σ A r (x , b) = x , (ρ x .fst b) s : Σ A → Σ B s (x , a) = x , ρ x .snd .fst a η : r ∘ s ∼ id η (x , a) = cong (_,_ x) (ρ x .snd .snd a) subst-is-retraction : {X : Type 𝓁} (A : X → Type 𝓂) {x y : X} (p : x ≡ y) → subst A p ∘ subst A (sym p) ∼ id subst-is-retraction A refl ay = refl subst-is-section : {X : Type 𝓁} (A : X → Type 𝓂) {x y : X} (p : x ≡ y) → subst A (sym p) ∘ subst A p ∼ id subst-is-section A refl ax = refl module _ {X : Type 𝓁} {A : X → Type 𝓃} where to-Σ≡ : {σ τ : Σ A} → Σ (λ (p : σ .fst ≡ τ .fst) → subst A p (σ .snd) ≡ τ .snd) → σ ≡ τ to-Σ≡ (refl , refl) = refl from-Σ≡ : {σ τ : Σ A} → σ ≡ τ → Σ (λ (p : σ .fst ≡ τ .fst) → subst A p (σ .snd) ≡ τ .snd) from-Σ≡ refl = (refl , refl) to-Σ≡-is-retraction : {σ τ : Σ A} → to-Σ≡ {σ} {τ} ∘ from-Σ≡ {σ} {τ} ∼ id to-Σ≡-is-retraction refl = refl to-Σ≡-is-section : {σ τ : Σ A} → from-Σ≡ {σ} {τ} ∘ to-Σ≡ {σ} {τ} ∼ id to-Σ≡-is-section (refl , refl) = refl isSetΣ : isSet X → ((x : X) → isSet (A x)) → isSet (Σ A) isSetΣ φ ψ (x₀ , y₀) (x₁ , y₁) = isPropRetract (to-Σ≡ , (from-Σ≡ , to-Σ≡-is-retraction)) (isPropΣ (φ x₀ x₁) (λ x → ψ x₁ (subst A x y₀) y₁)) Σ-reindexing-retract : {X : Type 𝓁} {Y : Type 𝓂} (A : X → Type 𝓃) (r : Y → X) → section r → Σ A ◁ Σ (A ∘ r) Σ-reindexing-retract A r (s , η) = r' , (s' , η') where r' : Σ (A ∘ r) → Σ A r' (y , a) = r y , a s' : Σ A → Σ (A ∘ r) s' (x , a) = s x , subst A (sym (η x)) a η' : r' ∘ s' ∼ id η' (x , a) = to-Σ≡ (η x , subst-is-retraction A (η x) a) module Equiv {X : Type 𝓁} {Y : Type 𝓂} (f : X → Y) where fiber : Y → Type (𝓁 ⊔ 𝓂) fiber y = Σ λ x → f x ≡ y isEquiv : Type (𝓁 ⊔ 𝓂) isEquiv = (y : Y) → isContr (fiber y) inverse : isEquiv → Y → X inverse eq y = eq y .fst .fst inverse-is-section : (eq : isEquiv) → f ∘ inverse eq ∼ id inverse-is-section eq y = eq y .fst .snd inverse-is-retraction : (eq : isEquiv) → inverse eq ∘ f ∼ id inverse-is-retraction eq x = cong fst p where p : Id (fiber (f x)) (eq (f x) .fst) (x , refl) p = eq (f x) .snd (x , refl) isInvertible : Type (𝓁 ⊔ 𝓂) isInvertible = retraction f × section f isEquiv→isInvertible : isEquiv → isInvertible isEquiv→isInvertible eq = (inverse eq , inverse-is-retraction eq) , (inverse eq , inverse-is-section eq) toFiberEq : {y : Y} {σ : fiber y} (τ : fiber y) → Σ (λ (γ : σ .fst ≡ τ .fst) → (cong f γ ∙ τ .snd ≡ σ .snd)) → σ ≡ τ toFiberEq τ (refl , refl) = cong (λ p → (τ .fst , p)) (refl-left (τ .snd)) record isHAEquiv : Type (𝓁 ⊔ 𝓂) where field g : Y → X η : g ∘ f ∼ id ε : f ∘ g ∼ id ha : (x : X) → cong f (η x) ≡ ε (f x) open isHAEquiv isHAEquiv→isInvertible : isHAEquiv → isInvertible isHAEquiv→isInvertible eq = (eq .g , eq .η) , (eq .g , eq .ε) isInvertible→isHAEquiv : isInvertible → isHAEquiv isInvertible→isHAEquiv ((g₀ , η₀) , (h₀ , ε₀)) = record { g = g₀ ; η = η₀ ; ε = ε₂ ; ha = λ x → sym (ha₀ x) } where ε₁ : f ∘ g₀ ∼ id ε₁ y = sym (cong (f ∘ g₀) (ε₀ y)) ∙ (cong f (η₀ (h₀ y)) ∙ ε₀ y) ε₂ : f ∘ g₀ ∼ id ε₂ y = sym (ε₁ (f (g₀ y))) ∙ (cong f (η₀ (g₀ y)) ∙ ε₁ y) ha₀ : (x : X) → ε₂ (f x) ≡ cong f (η₀ x) ha₀ x = sym (ε₁ (f (g₀ (f x)))) ∙ (cong f (η₀ (g₀ (f x))) ∙ ε₁ (f x)) ≡⟨ cong (λ p → sym (ε₁ (f (g₀ (f x)))) ∙ p) ( cong f (η₀ (g₀ (f x))) ∙ ε₁ (f x) ≡⟨ cong (λ p → cong f p ∙ ε₁ (f x)) (deformation-induces-iso (g₀ ∘ f) η₀ x) ⟩ cong f (cong (g₀ ∘ f) (η₀ x)) ∙ ε₁ (f x) ≡⟨ cong (λ p → p ∙ ε₁ (f x)) ( cong f (cong (g₀ ∘ f) (η₀ x)) ≡⟨ sym (cong-∘ (g₀ ∘ f) f (η₀ x)) ⟩ cong (f ∘ g₀ ∘ f) (η₀ x) ≡⟨ cong-∘ f (f ∘ g₀) (η₀ x) ⟩ cong (f ∘ g₀) (cong f (η₀ x)) ∎ ) ⟩ cong (f ∘ g₀) (cong f (η₀ x)) ∙ ε₁ (f x) ≡⟨ sym (deformation-induces-natural-iso ε₁ (cong f (η₀ x))) ⟩ ε₁ (f (g₀ (f x))) ∙ cong f (η₀ x) ∎ ) ⟩ sym (ε₁ (f (g₀ (f x)))) ∙ (ε₁ (f (g₀ (f x))) ∙ cong f (η₀ x)) ≡⟨ sym (∙-assoc _ _ _) ⟩ (sym (ε₁ (f (g₀ (f x)))) ∙ ε₁ (f (g₀ (f x)))) ∙ cong f (η₀ x) ≡⟨ cong (λ p → p ∙ cong f (η₀ x)) (sym-left _) ⟩ refl ∙ cong f (η₀ x) ≡⟨ refl-left _ ⟩ cong f (η₀ x) ∎ isHAEquiv→isEquiv : isHAEquiv → isEquiv isHAEquiv→isEquiv eq y = (eq .g y , eq .ε y) , λ τ → toFiberEq τ (γ τ , lem τ) where γ : (τ : fiber y) → eq .g y ≡ τ .fst γ (x , p) = cong (eq .g) (sym p) ∙ eq .η x natural : {h : Y → Y} (e : h ∼ id) {z z' : Y} (q : z ≡ z') → (sym (cong h q) ∙ e z) ∙ q ≡ e z' natural e {z = z} refl = refl-right (refl ∙ e z) ∙ refl-left (e z) lem : (τ : fiber y) → cong f (γ τ) ∙ τ .snd ≡ eq .ε y lem (x , p) = cong f (cong (eq .g) (sym p) ∙ eq .η x) ∙ p ≡⟨ cong (λ q → q ∙ p) ( cong f (cong (eq .g) (sym p) ∙ eq .η x) ≡⟨ cong-∙ f (cong (eq .g) (sym p)) (eq .η x) ⟩ cong f (cong (eq .g) (sym p)) ∙ cong f (eq .η x) ≡⟨ cong₂ _∙_ (sym (cong-∘ (eq .g) f (sym p)) ∙ cong-sym (f ∘ eq .g) p) (eq .ha x) ⟩ sym (cong (f ∘ eq .g) p) ∙ eq .ε (f x) ∎ ) ⟩ (sym (cong (f ∘ eq .g) p) ∙ eq .ε (f x)) ∙ p ≡⟨ natural (eq .ε) p ⟩ eq .ε y ∎ open Equiv open isHAEquiv _≃_ : Type 𝓁 → Type 𝓂 → Type (𝓁 ⊔ 𝓂) X ≃ Y = Σ λ (f : (X → Y)) → isHAEquiv f idIsHAEquiv : (X : Type 𝓁) → isHAEquiv (id {X = X}) idIsHAEquiv X = record { g = id ; η = λ x → refl ; ε = λ x → refl ; ha = λ x → refl } id-≃ : (X : Type 𝓁) → X ≃ X id-≃ X = (id , idIsHAEquiv X) ∘-≃ : {X : Type 𝓁} {Y : Type 𝓂} {Z : Type 𝓃} → X ≃ Y → Y ≃ Z → X ≃ Z ∘-≃ {X = X} {Y = Y} {Z = Z} (f , eqf) (h , eqh) = (h ∘ f) , record { g = g₀ ; η = η₀ ; ε = ε₀ ; ha = ha₀ } where g₀ : Z → X g₀ = eqf .g ∘ eqh .g η₀ : g₀ ∘ (h ∘ f) ∼ id η₀ x = cong (eqf .g) (eqh .η (f x)) ∙ eqf .η x ε₀ : (h ∘ f) ∘ g₀ ∼ id ε₀ z = cong h (eqf .ε (eqh .g z)) ∙ eqh .ε z ha₀ : (x : X) → cong (h ∘ f) (η₀ x) ≡ ε₀ (h (f x)) ha₀ x = cong (h ∘ f) (cong (eqf .g) (eqh .η (f x)) ∙ eqf .η x) ≡⟨ cong-∙ (h ∘ f) _ _ ⟩ cong (h ∘ f) (cong (eqf .g) (eqh .η (f x))) ∙ cong (h ∘ f) (eqf .η x) ≡⟨ cong₂ _∙_ (sym (cong-∘ (eqf .g) (h ∘ f) (eqh .η (f x)))) (cong-∘ f h (eqf .η x)) ⟩ cong (h ∘ f ∘ eqf .g) (eqh .η (f x)) ∙ cong h (cong f (eqf .η x)) ≡⟨ cong₂ _∙_ (cong-∘ (f ∘ eqf .g) h (eqh .η (f x))) (cong (cong h) (eqf .ha x)) ⟩ cong h (cong (f ∘ eqf .g) (eqh .η (f x))) ∙ cong h (eqf .ε (f x)) ≡⟨ sym (cong-∙ h _ _) ⟩ cong h (cong (f ∘ eqf .g) (eqh .η (f x)) ∙ eqf .ε (f x)) ≡⟨ cong (cong h) (sym (deformation-induces-natural-iso (eqf .ε) (eqh .η (f x)))) ⟩ cong h (eqf .ε (eqh .g (h (f x))) ∙ eqh .η (f x)) ≡⟨ cong-∙ h _ _ ⟩ cong h (eqf .ε (eqh .g (h (f x)))) ∙ cong h (eqh .η (f x)) ≡⟨ cong (λ p → _ ∙ p) (eqh .ha (f x)) ⟩ cong h (eqf .ε (eqh .g (h (f x)))) ∙ eqh .ε (h (f x)) ∎ sym-≃ : {X : Type 𝓁} {Y : Type 𝓂} → X ≃ Y → Y ≃ X sym-≃ {X = X} {Y = Y} (f , eq) = eq .g , record { g = f ; η = eq .ε ; ε = eq .η ; ha = ha₀ } where p : (y : Y) → cong (eq .g ∘ f ∘ eq .g) (eq .ε y) ∙ eq .η (eq .g y) ≡ cong (eq .g ∘ f ∘ eq .g) (eq .ε y) ∙ cong (eq .g) (eq .ε y) p y = cong (eq .g ∘ f ∘ eq .g) (eq .ε y) ∙ eq .η (eq .g y) ≡⟨ cong (λ p → p ∙ _) (cong-∘ (eq .g) (eq .g ∘ f) (eq .ε y)) ⟩ cong (eq .g ∘ f) (cong (eq .g) (eq .ε y)) ∙ eq .η (eq .g y) ≡⟨ sym (deformation-induces-natural-iso (eq .η) (cong (eq .g) (eq .ε y))) ⟩ eq .η (eq .g (f (eq .g y))) ∙ cong (eq .g) (eq .ε y) ≡⟨ cong (λ p → p ∙ _) (deformation-induces-iso (eq .g ∘ f) (eq .η) (eq .g y)) ⟩ cong (eq .g ∘ f) (eq .η (eq .g y)) ∙ cong (eq .g) (eq .ε y) ≡⟨ cong (λ p → p ∙ cong (eq .g) (eq .ε y)) (cong-∘ f (eq .g) (eq .η (eq .g y))) ⟩ cong (eq .g) (cong f (eq .η (eq .g y))) ∙ cong (eq .g) (eq .ε y) ≡⟨ cong (λ p → cong (eq .g) p ∙ cong (eq .g) (eq .ε y)) (eq .ha (eq .g y)) ⟩ cong (eq .g) (eq .ε (f (eq .g y))) ∙ cong (eq .g) (eq .ε y) ≡⟨ sym (cong-∙ (eq .g) (eq .ε (f (eq .g y))) (eq .ε y)) ⟩ cong (eq .g) (eq .ε (f (eq .g y)) ∙ eq .ε y) ≡⟨ cong (cong (eq .g)) (deformation-induces-natural-iso (eq .ε) (eq .ε y)) ⟩ cong (eq .g) (cong (f ∘ eq .g) (eq .ε y) ∙ eq .ε y) ≡⟨ cong-∙ (eq .g) (cong (f ∘ eq .g) (eq .ε y)) (eq .ε y) ⟩ cong (eq .g) (cong (f ∘ eq .g) (eq .ε y)) ∙ cong (eq .g) (eq .ε y) ≡⟨ cong (λ p → p ∙ cong (eq .g) (eq .ε y)) (sym (cong-∘ (f ∘ eq .g) (eq .g) (eq .ε y))) ⟩ cong (eq .g ∘ f ∘ eq .g) (eq .ε y) ∙ cong (eq .g) (eq .ε y) ∎ ha₀ : (y : Y) → cong (eq .g) (eq .ε y) ≡ eq .η (eq .g y) ha₀ y = ∙-cancel-left (sym (p y)) cong-const : {X : Type 𝓁} {Y : Type 𝓂} (y : Y) {x x' : X} {p : x ≡ x'} → cong (λ _ → y) p ≡ refl cong-const y {p = refl} = refl contr-fiber : {X : Type 𝓁} (A : X → Type 𝓂) → ((x : X) → isContr (A x)) → isHAEquiv (λ (a : Σ A) → a .fst) contr-fiber {X = X} A c = record { g = g₀ ; η = η₀ ; ε = ε₀ ; ha = ha₀ } where g₀ : X → Σ A g₀ x = x , c x .fst η₀ : g₀ ∘ fst ∼ id η₀ (x , a) = cong (_,_ x) (c x .snd a) ε₀ : fst ∘ g₀ ∼ id ε₀ x = refl ha₀ : (a : Σ A) → cong fst (η₀ a) ≡ ε₀ (fst a) ha₀ (x , a) = cong fst (cong (_,_ x) (c x .snd a)) ≡⟨ sym (cong-∘ (_,_ x) fst (c x .snd a)) ⟩ cong (λ _ → x) (c x .snd a) ≡⟨ cong-const x ⟩ refl ≡⟨ refl ⟩ ε₀ x ∎ Id→Eq : (X Y : Type 𝓁) → X ≡ Y → X ≃ Y Id→Eq X X refl = id-≃ X isUnivalent : (𝓁 : Level) → Type (𝓁 ⁺) isUnivalent 𝓁 = (X Y : Type 𝓁) → isHAEquiv (Id→Eq X Y)
29.361194
144
0.4695
04cd1a57309e0fb14cdb3499fe7b89c47c31e4ca
1,050
agda
Agda
my-bool-test.agda
logicshan/IAL
2ad96390a9be5c238e73709a21533c7354cedd0c
[ "MIT" ]
null
null
null
my-bool-test.agda
logicshan/IAL
2ad96390a9be5c238e73709a21533c7354cedd0c
[ "MIT" ]
null
null
null
my-bool-test.agda
logicshan/IAL
2ad96390a9be5c238e73709a21533c7354cedd0c
[ "MIT" ]
null
null
null
module my-bool-test where open import bool open import eq open import level ~~tt : ~ ~ tt ≡ tt ~~tt = refl ~~ff : ~ ~ ff ≡ ff ~~ff = refl {- ~~-elim : ∀ (b : 𝔹) → ~ ~ b ≡ b ~~-elim tt = refl ~~-elim ff = refl -} ~~-elim2 : ∀ (b : 𝔹) → ~ ~ b ≡ b ~~-elim2 tt = ~~tt ~~-elim2 ff = ~~ff ~~tt' : ~ ~ tt ≡ tt ~~tt' = refl{lzero}{𝔹}{tt} ~~ff' : ~ ~ ff ≡ ff ~~ff' = refl{lzero}{𝔹}{ff} ~~-elim : ∀ (b : 𝔹) → ~ ~ b ≡ b ~~-elim tt = refl ~~-elim ff = refl ||≡ff₁ : ∀ {b1 b2} → b1 || b2 ≡ ff → b1 ≡ ff ||≡ff₁ {ff} _ = refl{lzero}{𝔹}{ff} ||≡ff₁ {tt} () ||≡ff₂ : ∀ {b1 b2} → b1 || b2 ≡ ff → ff ≡ b1 ||≡ff₂ {ff} _ = refl{lzero}{𝔹}{ff} ||≡ff₂ {tt} p = sym p ||-cong₁ : ∀ {b1 b1' b2} → b1 ≡ b1' → b1 || b2 ≡ b1' || b2 ||-cong₁{b1}{.b1}{b2} refl = refl ||-cong₂ : ∀ {b1 b2 b2'} → b2 ≡ b2' → b1 || b2 ≡ b1 || b2' ||-cong₂ p rewrite p = refl ite-same : ∀{ℓ}{A : Set ℓ} → ∀(b : 𝔹) (x : A) → (if b then x else x) ≡ x ite-same tt x = refl ite-same ff x = refl 𝔹-contra : ff ≡ tt → ∀ {P : Set} → P 𝔹-contra () p : ff && ff ≡ ~ tt p = refl
18.75
58
0.448571
52408008c2186143464cf2a3934f0395ab8c8c12
93
agda
Agda
test/Fail/Issue394-4.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue394-4.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue394-4.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
postulate A : Set F : (A : Set₁) → (A → A → Set) → Set syntax F A (λ x y → B) = A x B y
15.5
38
0.462366
5e36b9caea6185a9a6f3b0a5afcbf3b9ebefc2a0
134
agda
Agda
test/Fail/ModuleArityMismatchEmptyTel.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/ModuleArityMismatchEmptyTel.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/ModuleArityMismatchEmptyTel.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-12-01, test case to trigger error ModuleArityMismatch EmptyTel module _ where module M where module M′ = M Set
19.142857
79
0.738806
34891b35099daf0f42b9fb5248b3e7e80db2498b
2,525
agda
Agda
src/Categories/Diagram/Cone/Properties.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Diagram/Cone/Properties.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Diagram/Cone/Properties.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Diagram.Cone.Properties where open import Level open import Categories.Category open import Categories.Functor open import Categories.Functor.Properties open import Categories.NaturalTransformation import Categories.Diagram.Cone as Con import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D J J′ : Category o ℓ e module _ {F : Functor J C} (G : Functor C D) where private module C = Category C module D = Category D module F = Functor F module G = Functor G module CF = Con F GF = G ∘F F module CGF = Con GF F-map-Coneˡ : CF.Cone → CGF.Cone F-map-Coneˡ K = record { apex = record { ψ = λ X → G.F₁ (ψ X) ; commute = λ f → [ G ]-resp-∘ (commute f) } } where open CF.Cone K F-map-Cone⇒ˡ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CGF.Cone⇒ (F-map-Coneˡ K) (F-map-Coneˡ K′) F-map-Cone⇒ˡ f = record { arr = G.F₁ arr ; commute = [ G ]-resp-∘ commute } where open CF.Cone⇒ f module _ {F : Functor J C} (G : Functor J′ J) where private module C = Category C module J′ = Category J′ module F = Functor F module G = Functor G module CF = Con F FG = F ∘F G module CFG = Con FG F-map-Coneʳ : CF.Cone → CFG.Cone F-map-Coneʳ K = record { apex = record { ψ = λ j → ψ (G.F₀ j) ; commute = λ f → commute (G.F₁ f) } } where open CF.Cone K F-map-Cone⇒ʳ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CFG.Cone⇒ (F-map-Coneʳ K) (F-map-Coneʳ K′) F-map-Cone⇒ʳ f = record { arr = arr ; commute = commute } where open CF.Cone⇒ f module _ {F G : Functor J C} (α : NaturalTransformation F G) where private module C = Category C module J = Category J module F = Functor F module G = Functor G module α = NaturalTransformation α module CF = Con F module CG = Con G open C open HomReasoning open MR C nat-map-Cone : CF.Cone → CG.Cone nat-map-Cone K = record { apex = record { ψ = λ j → α.η j C.∘ ψ j ; commute = λ {X Y} f → begin G.F₁ f ∘ α.η X ∘ ψ X ≈˘⟨ pushˡ (α.commute f) ⟩ (α.η Y ∘ F.F₁ f) ∘ ψ X ≈⟨ pullʳ (commute f) ⟩ α.η Y ∘ ψ Y ∎ } } where open CF.Cone K nat-map-Cone⇒ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CG.Cone⇒ (nat-map-Cone K) (nat-map-Cone K′) nat-map-Cone⇒ {K} {K′} f = record { arr = arr ; commute = pullʳ commute } where open CF.Cone⇒ f
24.754902
92
0.561584
3423a27d79867093a05d7bae221c0d1564b86d2f
12,497
agda
Agda
agda-stdlib/src/Data/List/Membership/Propositional/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Membership/Propositional/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Membership/Propositional/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to propositional list membership ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Membership.Propositional.Properties where open import Algebra using (Op₂; Selective) open import Category.Monad using (RawMonad) open import Data.Bool.Base using (Bool; false; true; T) open import Data.Fin.Base using (Fin) open import Data.List.Base as List open import Data.List.Relation.Unary.Any as Any using (Any; here; there) open import Data.List.Relation.Unary.Any.Properties open import Data.List.Membership.Propositional import Data.List.Membership.Setoid.Properties as Membershipₛ open import Data.List.Relation.Binary.Equality.Propositional using (_≋_; ≡⇒≋; ≋⇒≡) open import Data.List.Categorical using (monad) open import Data.Nat.Base using (ℕ; zero; suc; pred; s≤s; _≤_; _<_) open import Data.Nat.Properties open import Data.Product hiding (map) open import Data.Product.Function.NonDependent.Propositional using (_×-cong_) import Data.Product.Function.Dependent.Propositional as Σ open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂) open import Function.Base open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (module Equivalence) open import Function.Injection using (Injection; Injective; _↣_) open import Function.Inverse as Inv using (_↔_; module Inverse) import Function.Related as Related open import Function.Related.TypeIsomorphisms open import Level using (Level) open import Relation.Binary as B hiding (Decidable) open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; refl; sym; trans; cong; subst; →-to-⟶; _≗_) import Relation.Binary.Properties.DecTotalOrder as DTOProperties open import Relation.Unary using (_⟨×⟩_; Decidable) open import Relation.Nullary.Reflects using (invert) open import Relation.Nullary using (¬_; Dec; does; yes; no; _because_) open import Relation.Nullary.Negation private open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ}) variable ℓ : Level A B : Set ℓ ------------------------------------------------------------------------ -- Publicly re-export properties from Core open import Data.List.Membership.Propositional.Properties.Core public ------------------------------------------------------------------------ -- Equality ∈-resp-≋ : ∀ {x : A} → (x ∈_) Respects _≋_ ∈-resp-≋ = Membershipₛ.∈-resp-≋ (P.setoid _) ∉-resp-≋ : ∀ {x : A} → (x ∉_) Respects _≋_ ∉-resp-≋ = Membershipₛ.∉-resp-≋ (P.setoid _) ------------------------------------------------------------------------ -- mapWith∈ mapWith∈-cong : ∀ (xs : List A) → (f g : ∀ {x} → x ∈ xs → B) → (∀ {x} → (x∈xs : x ∈ xs) → f x∈xs ≡ g x∈xs) → mapWith∈ xs f ≡ mapWith∈ xs g mapWith∈-cong [] f g cong = refl mapWith∈-cong (x ∷ xs) f g cong = P.cong₂ _∷_ (cong (here refl)) (mapWith∈-cong xs (f ∘ there) (g ∘ there) (cong ∘ there)) mapWith∈≗map : ∀ (f : A → B) xs → mapWith∈ xs (λ {x} _ → f x) ≡ map f xs mapWith∈≗map f xs = ≋⇒≡ (Membershipₛ.mapWith∈≗map (P.setoid _) (P.setoid _) f xs) ------------------------------------------------------------------------ -- map module _ (f : A → B) where ∈-map⁺ : ∀ {x xs} → x ∈ xs → f x ∈ map f xs ∈-map⁺ = Membershipₛ.∈-map⁺ (P.setoid A) (P.setoid B) (P.cong f) ∈-map⁻ : ∀ {y xs} → y ∈ map f xs → ∃ λ x → x ∈ xs × y ≡ f x ∈-map⁻ = Membershipₛ.∈-map⁻ (P.setoid A) (P.setoid B) map-∈↔ : ∀ {y xs} → (∃ λ x → x ∈ xs × y ≡ f x) ↔ y ∈ map f xs map-∈↔ {y} {xs} = (∃ λ x → x ∈ xs × y ≡ f x) ↔⟨ Any↔ ⟩ Any (λ x → y ≡ f x) xs ↔⟨ map↔ ⟩ y ∈ List.map f xs ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- _++_ module _ {v : A} where ∈-++⁺ˡ : ∀ {xs ys} → v ∈ xs → v ∈ xs ++ ys ∈-++⁺ˡ = Membershipₛ.∈-++⁺ˡ (P.setoid A) ∈-++⁺ʳ : ∀ xs {ys} → v ∈ ys → v ∈ xs ++ ys ∈-++⁺ʳ = Membershipₛ.∈-++⁺ʳ (P.setoid A) ∈-++⁻ : ∀ xs {ys} → v ∈ xs ++ ys → (v ∈ xs) ⊎ (v ∈ ys) ∈-++⁻ = Membershipₛ.∈-++⁻ (P.setoid A) ∈-insert : ∀ xs {ys} → v ∈ xs ++ [ v ] ++ ys ∈-insert xs = Membershipₛ.∈-insert (P.setoid A) xs refl ∈-∃++ : ∀ {xs} → v ∈ xs → ∃₂ λ ys zs → xs ≡ ys ++ [ v ] ++ zs ∈-∃++ v∈xs with Membershipₛ.∈-∃++ (P.setoid A) v∈xs ... | ys , zs , _ , refl , eq = ys , zs , ≋⇒≡ eq ------------------------------------------------------------------------ -- concat module _ {v : A} where ∈-concat⁺ : ∀ {xss} → Any (v ∈_) xss → v ∈ concat xss ∈-concat⁺ = Membershipₛ.∈-concat⁺ (P.setoid A) ∈-concat⁻ : ∀ xss → v ∈ concat xss → Any (v ∈_) xss ∈-concat⁻ = Membershipₛ.∈-concat⁻ (P.setoid A) ∈-concat⁺′ : ∀ {vs xss} → v ∈ vs → vs ∈ xss → v ∈ concat xss ∈-concat⁺′ v∈vs vs∈xss = Membershipₛ.∈-concat⁺′ (P.setoid A) v∈vs (Any.map ≡⇒≋ vs∈xss) ∈-concat⁻′ : ∀ xss → v ∈ concat xss → ∃ λ xs → v ∈ xs × xs ∈ xss ∈-concat⁻′ xss v∈c with Membershipₛ.∈-concat⁻′ (P.setoid A) xss v∈c ... | xs , v∈xs , xs∈xss = xs , v∈xs , Any.map ≋⇒≡ xs∈xss concat-∈↔ : ∀ {xss : List (List A)} → (∃ λ xs → v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss concat-∈↔ {xss} = (∃ λ xs → v ∈ xs × xs ∈ xss) ↔⟨ Σ.cong Inv.id $ ×-comm _ _ ⟩ (∃ λ xs → xs ∈ xss × v ∈ xs) ↔⟨ Any↔ ⟩ Any (Any (v ≡_)) xss ↔⟨ concat↔ ⟩ v ∈ concat xss ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- applyUpTo module _ (f : ℕ → A) where ∈-applyUpTo⁺ : ∀ {i n} → i < n → f i ∈ applyUpTo f n ∈-applyUpTo⁺ = Membershipₛ.∈-applyUpTo⁺ (P.setoid _) f ∈-applyUpTo⁻ : ∀ {v n} → v ∈ applyUpTo f n → ∃ λ i → i < n × v ≡ f i ∈-applyUpTo⁻ = Membershipₛ.∈-applyUpTo⁻ (P.setoid _) f ------------------------------------------------------------------------ -- tabulate module _ {n} {f : Fin n → A} where ∈-tabulate⁺ : ∀ i → f i ∈ tabulate f ∈-tabulate⁺ = Membershipₛ.∈-tabulate⁺ (P.setoid _) ∈-tabulate⁻ : ∀ {v} → v ∈ tabulate f → ∃ λ i → v ≡ f i ∈-tabulate⁻ = Membershipₛ.∈-tabulate⁻ (P.setoid _) ------------------------------------------------------------------------ -- filter module _ {p} {P : A → Set p} (P? : Decidable P) where ∈-filter⁺ : ∀ {x xs} → x ∈ xs → P x → x ∈ filter P? xs ∈-filter⁺ = Membershipₛ.∈-filter⁺ (P.setoid A) P? (P.subst P) ∈-filter⁻ : ∀ {v xs} → v ∈ filter P? xs → v ∈ xs × P v ∈-filter⁻ = Membershipₛ.∈-filter⁻ (P.setoid A) P? (P.subst P) ------------------------------------------------------------------------ -- derun and deduplicate module _ {r} {R : Rel A r} (R? : B.Decidable R) where ∈-derun⁻ : ∀ xs {z} → z ∈ derun R? xs → z ∈ xs ∈-derun⁻ xs z∈derun[R,xs] = Membershipₛ.∈-derun⁻ (P.setoid A) R? xs z∈derun[R,xs] ∈-deduplicate⁻ : ∀ xs {z} → z ∈ deduplicate R? xs → z ∈ xs ∈-deduplicate⁻ xs z∈dedup[R,xs] = Membershipₛ.∈-deduplicate⁻ (P.setoid A) R? xs z∈dedup[R,xs] module _ (_≈?_ : B.Decidable {A = A} _≡_) where ∈-derun⁺ : ∀ {xs z} → z ∈ xs → z ∈ derun _≈?_ xs ∈-derun⁺ z∈xs = Membershipₛ.∈-derun⁺ (P.setoid A) _≈?_ (flip trans) z∈xs ∈-deduplicate⁺ : ∀ {xs z} → z ∈ xs → z ∈ deduplicate _≈?_ xs ∈-deduplicate⁺ z∈xs = Membershipₛ.∈-deduplicate⁺ (P.setoid A) _≈?_ (λ c≡b a≡b → trans a≡b (sym c≡b)) z∈xs ------------------------------------------------------------------------ -- _>>=_ >>=-∈↔ : ∀ {xs} {f : A → List B} {y} → (∃ λ x → x ∈ xs × y ∈ f x) ↔ y ∈ (xs >>= f) >>=-∈↔ {xs = xs} {f} {y} = (∃ λ x → x ∈ xs × y ∈ f x) ↔⟨ Any↔ ⟩ Any (Any (y ≡_) ∘ f) xs ↔⟨ >>=↔ ⟩ y ∈ (xs >>= f) ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- _⊛_ ⊛-∈↔ : ∀ (fs : List (A → B)) {xs y} → (∃₂ λ f x → f ∈ fs × x ∈ xs × y ≡ f x) ↔ y ∈ (fs ⊛ xs) ⊛-∈↔ fs {xs} {y} = (∃₂ λ f x → f ∈ fs × x ∈ xs × y ≡ f x) ↔⟨ Σ.cong Inv.id (∃∃↔∃∃ _) ⟩ (∃ λ f → f ∈ fs × ∃ λ x → x ∈ xs × y ≡ f x) ↔⟨ Σ.cong Inv.id ((_ ∎) ⟨ _×-cong_ ⟩ Any↔) ⟩ (∃ λ f → f ∈ fs × Any (_≡_ y ∘ f) xs) ↔⟨ Any↔ ⟩ Any (λ f → Any (_≡_ y ∘ f) xs) fs ↔⟨ ⊛↔ ⟩ y ∈ (fs ⊛ xs) ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- _⊗_ ⊗-∈↔ : ∀ {xs ys} {x : A} {y : B} → (x ∈ xs × y ∈ ys) ↔ (x , y) ∈ (xs ⊗ ys) ⊗-∈↔ {xs = xs} {ys} {x} {y} = (x ∈ xs × y ∈ ys) ↔⟨ ⊗↔′ ⟩ Any (x ≡_ ⟨×⟩ y ≡_) (xs ⊗ ys) ↔⟨ Any-cong ×-≡×≡↔≡,≡ (_ ∎) ⟩ (x , y) ∈ (xs ⊗ ys) ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- length ∈-length : ∀ {x : A} {xs} → x ∈ xs → 1 ≤ length xs ∈-length = Membershipₛ.∈-length (P.setoid _) ------------------------------------------------------------------------ -- lookup ∈-lookup : ∀ {xs : List A} i → lookup xs i ∈ xs ∈-lookup {xs = xs} i = Membershipₛ.∈-lookup (P.setoid _) xs i ------------------------------------------------------------------------ -- foldr module _ {_•_ : Op₂ A} where foldr-selective : Selective _≡_ _•_ → ∀ e xs → (foldr _•_ e xs ≡ e) ⊎ (foldr _•_ e xs ∈ xs) foldr-selective = Membershipₛ.foldr-selective (P.setoid A) ------------------------------------------------------------------------ -- allFin ∈-allFin : ∀ {n} (k : Fin n) → k ∈ allFin n ∈-allFin = ∈-tabulate⁺ ------------------------------------------------------------------------ -- inits []∈inits : ∀ {a} {A : Set a} (as : List A) → [] ∈ inits as []∈inits [] = here refl []∈inits (a ∷ as) = here refl ------------------------------------------------------------------------ -- Other properties -- Only a finite number of distinct elements can be members of a -- given list. finite : (f : ℕ ↣ A) → ∀ xs → ¬ (∀ i → Injection.to f ⟨$⟩ i ∈ xs) finite inj [] fᵢ∈[] = ¬Any[] (fᵢ∈[] 0) finite inj (x ∷ xs) fᵢ∈x∷xs = excluded-middle helper where open Injection inj renaming (injective to f-inj) f : ℕ → _ f = to ⟨$⟩_ not-x : ∀ {i} → f i ≢ x → f i ∈ xs not-x {i} fᵢ≢x with fᵢ∈x∷xs i ... | here fᵢ≡x = contradiction fᵢ≡x fᵢ≢x ... | there fᵢ∈xs = fᵢ∈xs helper : ¬ Dec (∃ λ i → f i ≡ x) helper (no fᵢ≢x) = finite inj xs (λ i → not-x (fᵢ≢x ∘ _,_ i)) helper (yes (i , fᵢ≡x)) = finite f′-inj xs f′ⱼ∈xs where f′ : ℕ → _ f′ j with does (i ≤? j) ... | true = f (suc j) ... | false = f j ∈-if-not-i : ∀ {j} → i ≢ j → f j ∈ xs ∈-if-not-i i≢j = not-x (i≢j ∘ f-inj ∘ trans fᵢ≡x ∘ sym) lemma : ∀ {k j} → i ≤ j → ¬ (i ≤ k) → suc j ≢ k lemma i≤j i≰1+j refl = i≰1+j (≤-step i≤j) f′ⱼ∈xs : ∀ j → f′ j ∈ xs f′ⱼ∈xs j with i ≤? j ... | yes i≤j = ∈-if-not-i (<⇒≢ (s≤s i≤j)) ... | no i≰j = ∈-if-not-i (<⇒≢ (≰⇒> i≰j) ∘ sym) f′-injective′ : Injective {B = P.setoid _} (→-to-⟶ f′) f′-injective′ {j} {k} eq with i ≤? j | i ≤? k ... | yes _ | yes _ = P.cong pred (f-inj eq) ... | yes i≤j | no i≰k = contradiction (f-inj eq) (lemma i≤j i≰k) ... | no i≰j | yes i≤k = contradiction (f-inj eq) (lemma i≤k i≰j ∘ sym) ... | no _ | no _ = f-inj eq f′-inj = record { to = →-to-⟶ f′ ; injective = f′-injective′ } ------------------------------------------------------------------------ -- Different members there-injective-≢∈ : ∀ {xs} {x y z : A} {x∈xs : x ∈ xs} {y∈xs : y ∈ xs} → there {x = z} x∈xs ≢∈ there y∈xs → x∈xs ≢∈ y∈xs there-injective-≢∈ neq refl eq = neq refl (P.cong there eq) ------------------------------------------------------------------------ -- DEPRECATED ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.15 boolFilter-∈ : ∀ (p : A → Bool) (xs : List A) {x} → x ∈ xs → p x ≡ true → x ∈ boolFilter p xs boolFilter-∈ p (x ∷ xs) (here refl) px≡true rewrite px≡true = here refl boolFilter-∈ p (y ∷ xs) (there pxs) px≡true with p y ... | true = there (boolFilter-∈ p xs pxs px≡true) ... | false = boolFilter-∈ p xs pxs px≡true {-# WARNING_ON_USAGE boolFilter-∈ "Warning: boolFilter was deprecated in v0.15. Please use filter instead." #-} -- Version 0.16 filter-∈ = ∈-filter⁺ {-# WARNING_ON_USAGE filter-∈ "Warning: filter-∈ was deprecated in v0.16. Please use ∈-filter⁺ instead." #-}
35.005602
107
0.465152
8b5a6c0424db0007bc7435f1310ebcd7b638632d
7,071
agda
Agda
agda-stdlib-0.9/src/Data/Nat/GCD/Lemmas.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/Nat/GCD/Lemmas.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Nat/GCD/Lemmas.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Boring lemmas used in Data.Nat.GCD and Data.Nat.Coprimality ------------------------------------------------------------------------ module Data.Nat.GCD.Lemmas where open import Data.Nat import Data.Nat.Properties as NatProp open NatProp.SemiringSolver open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Function lem₀ = solve 2 (λ n k → n :+ (con 1 :+ k) := con 1 :+ n :+ k) refl lem₁ : ∀ i j → 2 + i ≤′ 2 + j + i lem₁ i j = NatProp.≤⇒≤′ $ s≤s $ s≤s $ NatProp.n≤m+n j i lem₂ : ∀ d x {k n} → d + x * k ≡ x * n → d + x * (n + k) ≡ 2 * x * n lem₂ d x {k} {n} eq = begin d + x * (n + k) ≡⟨ solve 4 (λ d x n k → d :+ x :* (n :+ k) := d :+ x :* k :+ x :* n) refl d x n k ⟩ d + x * k + x * n ≡⟨ cong₂ _+_ eq refl ⟩ x * n + x * n ≡⟨ solve 3 (λ x n k → x :* n :+ x :* n := con 2 :* x :* n) refl x n k ⟩ 2 * x * n ∎ lem₃ : ∀ d x {i k n} → d + (1 + x + i) * k ≡ x * n → d + (1 + x + i) * (n + k) ≡ (1 + 2 * x + i) * n lem₃ d x {i} {k} {n} eq = begin d + y * (n + k) ≡⟨ solve 4 (λ d y n k → d :+ y :* (n :+ k) := (d :+ y :* k) :+ y :* n) refl d y n k ⟩ (d + y * k) + y * n ≡⟨ cong₂ _+_ eq refl ⟩ x * n + y * n ≡⟨ solve 3 (λ x n i → x :* n :+ (con 1 :+ x :+ i) :* n := (con 1 :+ con 2 :* x :+ i) :* n) refl x n i ⟩ (1 + 2 * x + i) * n ∎ where y = 1 + x + i lem₄ : ∀ d y {k i} n → d + y * k ≡ (1 + y + i) * n → d + y * (n + k) ≡ (1 + 2 * y + i) * n lem₄ d y {k} {i} n eq = begin d + y * (n + k) ≡⟨ solve 4 (λ d y n k → d :+ y :* (n :+ k) := d :+ y :* k :+ y :* n) refl d y n k ⟩ d + y * k + y * n ≡⟨ cong₂ _+_ eq refl ⟩ (1 + y + i) * n + y * n ≡⟨ solve 3 (λ y i n → (con 1 :+ y :+ i) :* n :+ y :* n := (con 1 :+ con 2 :* y :+ i) :* n) refl y i n ⟩ (1 + 2 * y + i) * n ∎ private distrib-comm = solve 3 (λ x k n → x :* k :+ x :* n := x :* (n :+ k)) refl lem₅ : ∀ d x {n k} → d + x * n ≡ x * k → d + 2 * x * n ≡ x * (n + k) lem₅ d x {n} {k} eq = begin d + 2 * x * n ≡⟨ solve 3 (λ d x n → d :+ con 2 :* x :* n := d :+ x :* n :+ x :* n) refl d x n ⟩ d + x * n + x * n ≡⟨ cong₂ _+_ eq refl ⟩ x * k + x * n ≡⟨ distrib-comm x k n ⟩ x * (n + k) ∎ lem₆ : ∀ d x {n i k} → d + x * n ≡ (1 + x + i) * k → d + (1 + 2 * x + i) * n ≡ (1 + x + i) * (n + k) lem₆ d x {n} {i} {k} eq = begin d + (1 + 2 * x + i) * n ≡⟨ solve 4 (λ d x i n → d :+ (con 1 :+ con 2 :* x :+ i) :* n := d :+ x :* n :+ (con 1 :+ x :+ i) :* n) refl d x i n ⟩ d + x * n + y * n ≡⟨ cong₂ _+_ eq refl ⟩ y * k + y * n ≡⟨ distrib-comm y k n ⟩ y * (n + k) ∎ where y = 1 + x + i lem₇ : ∀ d y {i} n {k} → d + (1 + y + i) * n ≡ y * k → d + (1 + 2 * y + i) * n ≡ y * (n + k) lem₇ d y {i} n {k} eq = begin d + (1 + 2 * y + i) * n ≡⟨ solve 4 (λ d y i n → d :+ (con 1 :+ con 2 :* y :+ i) :* n := d :+ (con 1 :+ y :+ i) :* n :+ y :* n) refl d y i n ⟩ d + (1 + y + i) * n + y * n ≡⟨ cong₂ _+_ eq refl ⟩ y * k + y * n ≡⟨ distrib-comm y k n ⟩ y * (n + k) ∎ lem₈ : ∀ {i j k q} x y → 1 + y * j ≡ x * i → j * k ≡ q * i → k ≡ (x * k ∸ y * q) * i lem₈ {i} {j} {k} {q} x y eq eq′ = sym (NatProp.im≡jm+n⇒[i∸j]m≡n (x * k) (y * q) i k lemma) where lemma = begin x * k * i ≡⟨ solve 3 (λ x k i → x :* k :* i := x :* i :* k) refl x k i ⟩ x * i * k ≡⟨ cong (λ n → n * k) (sym eq) ⟩ (1 + y * j) * k ≡⟨ solve 3 (λ y j k → (con 1 :+ y :* j) :* k := y :* (j :* k) :+ k) refl y j k ⟩ y * (j * k) + k ≡⟨ cong (λ n → y * n + k) eq′ ⟩ y * (q * i) + k ≡⟨ solve 4 (λ y q i k → y :* (q :* i) :+ k := y :* q :* i :+ k) refl y q i k ⟩ y * q * i + k ∎ lem₉ : ∀ {i j k q} x y → 1 + x * i ≡ y * j → j * k ≡ q * i → k ≡ (y * q ∸ x * k) * i lem₉ {i} {j} {k} {q} x y eq eq′ = sym (NatProp.im≡jm+n⇒[i∸j]m≡n (y * q) (x * k) i k lemma) where lem = solve 3 (λ a b c → a :* b :* c := b :* c :* a) refl lemma = begin y * q * i ≡⟨ lem y q i ⟩ q * i * y ≡⟨ cong (λ n → n * y) (sym eq′) ⟩ j * k * y ≡⟨ sym (lem y j k) ⟩ y * j * k ≡⟨ cong (λ n → n * k) (sym eq) ⟩ (1 + x * i) * k ≡⟨ solve 3 (λ x i k → (con 1 :+ x :* i) :* k := x :* k :* i :+ k) refl x i k ⟩ x * k * i + k ∎ lem₁₀ : ∀ {a′} b c {d} e f → let a = suc a′ in a + b * (c * d * a) ≡ e * (f * d * a) → d ≡ 1 lem₁₀ {a′} b c {d} e f eq = NatProp.i*j≡1⇒j≡1 (e * f ∸ b * c) d (NatProp.im≡jm+n⇒[i∸j]m≡n (e * f) (b * c) d 1 (NatProp.cancel-*-right (e * f * d) (b * c * d + 1) (begin e * f * d * a ≡⟨ solve 4 (λ e f d a → e :* f :* d :* a := e :* (f :* d :* a)) refl e f d a ⟩ e * (f * d * a) ≡⟨ sym eq ⟩ a + b * (c * d * a) ≡⟨ solve 4 (λ a b c d → a :+ b :* (c :* d :* a) := (b :* c :* d :+ con 1) :* a) refl a b c d ⟩ (b * c * d + 1) * a ∎))) where a = suc a′ lem₁₁ : ∀ {i j m n k d} x y → 1 + y * j ≡ x * i → i * k ≡ m * d → j * k ≡ n * d → k ≡ (x * m ∸ y * n) * d lem₁₁ {i} {j} {m} {n} {k} {d} x y eq eq₁ eq₂ = sym (NatProp.im≡jm+n⇒[i∸j]m≡n (x * m) (y * n) d k lemma) where assoc = solve 3 (λ x y z → x :* y :* z := x :* (y :* z)) refl lemma = begin x * m * d ≡⟨ assoc x m d ⟩ x * (m * d) ≡⟨ cong (_*_ x) (sym eq₁) ⟩ x * (i * k) ≡⟨ sym (assoc x i k) ⟩ x * i * k ≡⟨ cong₂ _*_ (sym eq) refl ⟩ (1 + y * j) * k ≡⟨ solve 3 (λ y j k → (con 1 :+ y :* j) :* k := y :* (j :* k) :+ k) refl y j k ⟩ y * (j * k) + k ≡⟨ cong (λ p → y * p + k) eq₂ ⟩ y * (n * d) + k ≡⟨ cong₂ _+_ (sym $ assoc y n d) refl ⟩ y * n * d + k ∎
41.350877
93
0.283835
4b700381a330ccfdcbd9adf8236ee573e533d3a2
909
agda
Agda
test/Succeed/Issue2553.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2553.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2553.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2020-04-19, abusing this test case to trigger some -- warnings for #4560 module _ where id : (A B : Set₁) → (A → B) → A → B id _ _ f = f postulate P : (A : Set₁) → A → Set₁ cong : (A B : Set₁) (f : A → B) (x : A) → P A x → P B (f x) A : Set record R₀ (B : Set) : Set₁ where constructor mkR₀ no-eta-equality field proj₁ : Set proj₂ : B record R₁ (_ : Set) : Set₁ where pattern -- no effect with eta-equality, should be ignored, #4560 constructor mkR₁ eta-equality field p : R₀ A X : Set X = R₀.proj₁ p record R₂ (r : R₁ A) : Set₁ where pattern -- should be ignored, #4560 -- constructor mkR₂ -- constructor not needed eta-equality field g : R₀ (R₁.X r) should-succeed : (r₁ : R₁ A) (r₂ : R₂ r₁) → P (R₂ r₁) r₂ → P (R₀ (R₁.X r₁)) (R₂.g r₂) should-succeed r₁ r₂ = id (P _ _) (P (R₀ (R₁.X r₁)) (R₂.g r₂)) (cong _ _ R₂.g _)
20.2
66
0.569857
ad1d893482ddcf1faa1bf95d07bbf8c1898c3fef
433
agda
Agda
UniDB/Subst/Shifts.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
UniDB/Subst/Shifts.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
UniDB/Subst/Shifts.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
module UniDB.Subst.Shifts where open import UniDB.Subst.Core open import UniDB.Morph.Shifts module _ {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} where instance iLkCompApShifts : LkCompAp T Shifts lk-⊙-ap {{iLkCompApShifts}} ξ₁ ξ₂ i = begin vr (lk (ξ₁ ⊙ ξ₂) i) ≡⟨ cong vr (shiftIx-⊙ ξ₁ ξ₂ i) ⟩ vr (lk ξ₂ (lk ξ₁ i)) ≡⟨ sym (ap-vr {T} ξ₂ (lk ξ₁ i)) ⟩ ap {T} ξ₂ (vr (lk ξ₁ i)) ∎
28.866667
76
0.575058
4a000c29bdf0ed56b5a24e2b2d47cbd0d348fd20
11,089
agda
Agda
src/Data/Zipper.agda
jwiegley/trade-journal
a8aa37e779f7c541a02cdb3f323b3a3393339bdf
[ "BSD-3-Clause" ]
6
2021-08-19T19:35:51.000Z
2022-02-07T16:50:33.000Z
src/Data/Zipper.agda
jwiegley/trade-journal
a8aa37e779f7c541a02cdb3f323b3a3393339bdf
[ "BSD-3-Clause" ]
2
2021-07-30T23:29:35.000Z
2021-09-30T11:25:26.000Z
src/Data/Zipper.agda
jwiegley/trade-journal
a8aa37e779f7c541a02cdb3f323b3a3393339bdf
[ "BSD-3-Clause" ]
2
2021-07-30T23:28:25.000Z
2021-08-02T11:08:45.000Z
module src.Data.Zipper where open import Agda.Builtin.Equality open import Data.Nat open import Data.Nat.Properties open import Induction.WellFounded open import Haskell.Prelude open import Relation.Binary.PropositionalEquality -- language extensions {-# FOREIGN AGDA2HS {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ViewPatterns #-} #-} -- imports {-# FOREIGN AGDA2HS import Control.Arrow (first) import Control.Comonad import Control.Lens hiding ((<.>)) import Control.Monad import Data.Foldable import Data.Functor.Apply import Data.Functor.Extend import Data.Function import Data.List (unfoldr) import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Semigroup.Foldable import GHC.Generics #-} record Zipper (a : Set) : Set where constructor MkZipper field prefix : List a focus : a suffix : List a {-# COMPILE AGDA2HS Zipper #-} open Zipper public {-# FOREIGN AGDA2HS deriving instance Show a => Show (Zipper a) deriving instance Eq a => Eq (Zipper a) deriving instance Generic a => Generic (Zipper a) deriving instance Functor Zipper deriving instance Foldable Zipper deriving instance Traversable Zipper makeLenses ''Zipper #-} {-# TERMINATING #-} repeat : a → List a repeat x = x ∷ repeat x instance isFunctorZipper : Functor Zipper isFunctorZipper .fmap k record { prefix = p ; focus = f ; suffix = s } = record { prefix = map k p ; focus = k f ; suffix = map k s } isApplicativeZipper : Applicative Zipper isApplicativeZipper .pure a = record { prefix = repeat a ; focus = a ; suffix = repeat a } isApplicativeZipper ._<*>_ record { prefix = p1 ; focus = f1 ; suffix = s1 } record { prefix = p2 ; focus = f2 ; suffix = s2 } = record { prefix = zipWith id p1 p2 ; focus = f1 f2 ; suffix = zipWith id s1 s2 } {-# COMPILE AGDA2HS isApplicativeZipper #-} isFoldableZipper : Foldable Zipper isFoldableZipper .foldMap k record { prefix = p ; focus = f ; suffix = s } = foldMap k p <> k f <> foldMap k s isTraversableZipper : Traversable Zipper isTraversableZipper .traverse k record { prefix = p ; focus = f ; suffix = s } = ⦇ MkZipper (traverse k p) (k f) (traverse k s) ⦈ isSemigroupZipper : ∀ {a : Set} → ⦃ Semigroup a ⦄ → Semigroup (Zipper a) isSemigroupZipper ._<>_ record { prefix = p1 ; focus = f1 ; suffix = s1 } record { prefix = p2 ; focus = f2 ; suffix = s2 } = record { prefix = zipWith (_<>_) p1 p2 ; focus = f1 <> f2 ; suffix = zipWith (_<>_) s1 s2 } {-# COMPILE AGDA2HS isSemigroupZipper #-} {-# FOREIGN AGDA2HS -- | Many of these instances are from Tony Morris's package, list-zipper instance Apply Zipper where MkZipper l1 x1 r1 <.> MkZipper l2 x2 r2 = MkZipper (zipWith id l1 l2) (x1 x2) (zipWith id r1 r2) instance Foldable1 Zipper where foldMap1 f (MkZipper [] x []) = f x foldMap1 f (MkZipper [] x (rh : rt)) = f x <> foldMap1 f (rh :| rt) foldMap1 f (MkZipper (lh : lt) x []) = foldMap1 f (lh :| lt) <> f x foldMap1 f (MkZipper (lh : lt) x (rh : rt)) = foldMap1 f (lh :| lt) <> f x <> foldMap1 f (rh :| rt) instance Traversable1 Zipper where traverse1 f (MkZipper [] x []) = (\x' -> MkZipper [] x' []) <$> f x traverse1 f (MkZipper (lh : lt) x []) = (\l' x' -> MkZipper (toList l') x' []) <$> traverse1 f (lh :| lt) <.> f x traverse1 f (MkZipper [] x (rh : rt)) = (\x' r' -> MkZipper [] x' (toList r')) <$> f x <.> traverse1 f (rh :| rt) traverse1 f (MkZipper (lh : lt) x (rh : rt)) = (\l' x' r' -> MkZipper (toList l') x' (toList r')) <$> traverse1 f (lh :| lt) <.> f x <.> traverse1 f (rh :| rt) instance Extend Zipper where duplicated z = let dup x = (x, x) unf f = unfoldr (fmap dup . f) z in MkZipper (unf left) z (unf right) instance Comonad Zipper where duplicate = duplicated extract (MkZipper _ x _) = x #-} left : ∀ {a : Set} → Zipper a → Maybe (Zipper a) left record { prefix = [] ; focus = f ; suffix = s } = Nothing left record { prefix = x ∷ p ; focus = f ; suffix = s } = Just record { prefix = p ; focus = x ; suffix = f ∷ s } {-# COMPILE AGDA2HS left #-} right : ∀ {a : Set} → Zipper a → Maybe (Zipper a) right record { prefix = p ; focus = f ; suffix = [] } = Nothing right record { prefix = p ; focus = f ; suffix = x ∷ s } = Just record { prefix = f ∷ p ; focus = x ; suffix = s } {-# COMPILE AGDA2HS right #-} left-right : ∀ {a : Set} (z r : Zipper a) → right z ≡ Just r → left r ≡ Just z left-right record { prefix = p ; focus = f ; suffix = (x ∷ s) } .(record { prefix = f ∷ p ; focus = x ; suffix = s }) refl = refl right-left : ∀ {a : Set} (z r : Zipper a) → left z ≡ Just r → right r ≡ Just z right-left record { prefix = (x ∷ p) ; focus = f ; suffix = s } .(record { prefix = p ; focus = x ; suffix = f ∷ s }) refl = refl fromList : List a → Maybe (Zipper a) fromList [] = Nothing fromList (x ∷ xs) = Just record { prefix = [] ; focus = x ; suffix = xs } {-# COMPILE AGDA2HS fromList #-} unzipper : Zipper a → List a unzipper record { prefix = p ; focus = f ; suffix = s } = reverse p ++ f ∷ s {-# COMPILE AGDA2HS unzipper #-} overlay : Zipper a → List a → Maybe (Zipper a) overlay record { prefix = p ; focus = _ ; suffix = [] } [] = Nothing overlay record { prefix = xs ; focus = _ ; suffix = (z ∷ zs) } [] = Just record { prefix = xs ; focus = z ; suffix = zs } overlay record { prefix = xs ; focus = _ ; suffix = zs } (w ∷ ws) = Just record { prefix = xs ; focus = w ; suffix = ws ++ zs } {-# COMPILE AGDA2HS overlay #-} record MonadPlus (m : Set → Set) : Set₁ where field mzero : m a mplus : m a → m a → m a overlap ⦃ super ⦄ : Monad m open MonadPlus ⦃ ... ⦄ public {-# COMPILE AGDA2HS MonadPlus existing-class #-} instance isListMonadPlus : MonadPlus List isListMonadPlus = record { mzero = [] ; mplus = _++_ } zipper : ⦃ MonadPlus f ⦄ → (a → Bool) → List a → f (Zipper a) zipper f xs = case break f xs of λ where (ys , z ∷ zs) → return record { prefix = reverse ys ; focus = z ; suffix = zs } _ → mzero {-# COMPILE AGDA2HS zipper #-} spanM : ⦃ Monad m ⦄ → ⦃ MonadPlus f ⦄ → (a → m Bool) → List a → m (f a × List a) spanM _ [] = return (mzero , []) spanM {m} {f} {a} {{M}} p (x ∷ xs) = do true <- p x where false → return (mzero , x ∷ xs) (ys , zs) <- spanM {m} {f} {a} {{M}} p xs return (mplus (return x) ys , zs) {-# COMPILE AGDA2HS spanM #-} infixr 1 _>=>_ _>=>_ : ⦃ Monad m ⦄ → (a → m b) → (b → m c) → a → m c f >=> g = λ x → f x >>= g infixr 1 _<=<_ _<=<_ : ⦃ Monad m ⦄ → (b → m c) → (a → m b) → a → m c f <=< g = g >=> f breakM : ⦃ Monad m ⦄ → ⦃ MonadPlus f ⦄ → (a → m Bool) → List a → m (f a × List a) breakM p = spanM $ return ∘ not <=< p {-# COMPILE AGDA2HS breakM #-} zipperM : {a : Set} → {m : Set → Set} → {f : Set → Set} → ⦃ Monad m ⦄ → ⦃ MonadPlus f ⦄ → (a → m Bool) → List a → m (f (Zipper a)) zipperM {a} {_} {f} {{M}} k xs = breakM {{M}} {{isListMonadPlus}} k xs <&> λ where (ys , z ∷ zs) → return record { prefix = reverse ys ; focus = z ; suffix = zs } _ → mzero {-# COMPILE AGDA2HS zipperM #-} Traversal' : Set → Set → Set₁ Traversal' s a = ∀ {f : Set → Set} → ⦃ Applicative f ⦄ → (a → f a) → (s → f s) items : Traversal' (Zipper a) a items k z = ⦇ MkZipper (reverse <$> traverse k (reverse (prefix z))) (k (focus z)) (traverse k (suffix z)) ⦈ {-# COMPILE AGDA2HS items #-} scanPreState : {s : Set} → (a → s → (b × s)) → s → List a → List (b × s) scanPreState f _ [] = [] scanPreState f s (x ∷ xs) = case f x s of λ where (b , s') → (b , s) ∷ scanPreState f s' xs {-# COMPILE AGDA2HS scanPreState #-} forward : {A : Set} → Zipper A → List A forward z = focus z ∷ suffix z measure : {A : Set}(f : A → ℕ) → Zipper A → ℕ measure f z = sum (map (suc ∘ f) (forward z)) just-inj : {A : Set} {x y : A} → Just x ≡ Just y → x ≡ y just-inj refl = refl suffix-forward : {A : Set} {z z' : Zipper A} → right z ≡ Just z' → suffix z ≡ forward z' suffix-forward {z = MkZipper prefix₁ focus₁ (x ∷ suffix₁)} H rewrite sym (just-inj H) = refl measure-right-< : {A : Set} (m : A → ℕ) {z z' : Zipper A} → right z ≡ Just z' → measure m z' Data.Nat.< measure m z measure-right-< m {z} {z'} H rewrite suffix-forward H = s≤s (m≤n+m _ _) record ZipperMono (A : Set)(m : A → ℕ) : Set where constructor zippermono field func : Zipper A → Zipper A mono : ∀ z → measure m z ≡ measure m (func z) open import Induction.WellFounded open import Data.Nat.Induction -- This version of survey shows that it terminates, but only if the function -- passed is monotonic with respect to a measure on its input and output. survey′ : {a : Set} (m : a → ℕ) → ZipperMono a m -> List a -> List a survey′ {a} m (zippermono f mono) = maybe [] (λ z → go z (<-wellFounded _)) ∘ fromList where go : (z : Zipper a) → Acc Data.Nat._<_ (measure m z) → List a go z (acc rs) with f z | inspect f z ...| z' | [ eq ] with right z' | inspect right z' ...| Nothing | _ = unzipper z' ...| Just z'' | [ eq' ] = go z'' (rs (measure m z'') (≤-trans (measure-right-< m eq') (≤-reflexive (trans (cong (measure m) (sym eq)) (sym (mono z)))))) {-# TERMINATING #-} survey : {a : Set} → (Zipper a -> Zipper a) -> List a -> List a survey {a} f = maybe [] go ∘ fromList where go : Zipper a → List a go z = let z' = f z in maybe (unzipper z') go (right z') {-# COMPILE AGDA2HS survey #-} {-# TERMINATING #-} surveyM : {a : Set} → {m : Set → Set} → ⦃ Monad m ⦄ → (Zipper a → m (Zipper a)) → List a → m (List a) surveyM {a} {m} f = maybe (return []) go ∘ fromList where go : Zipper a → m (List a) go z = do z' <- f z maybe (return (unzipper z')) go (right z') {-# COMPILE AGDA2HS surveyM #-} first : (a → b) → (a × c) → (b × c) first f (a , c) = (f a , c) mapUntils : (List a → List a) → (a → Maybe (List a × b)) → List a → Maybe (List a × b) mapUntils rev k [] = Nothing mapUntils rev k (x ∷ xs) = case k x of λ where (Just (xs' , b)) → Just (rev xs' ++ xs , b) Nothing → first (λ xs → x ∷ xs) <$> mapUntils rev k xs {-# COMPILE AGDA2HS mapUntils #-} -- | Given a zipper list, attempt to locate an element first in the prefix, -- then in the suffix, and allow for a transformation of that sub-zipper -- list within the parent list, plus the generation of some datum. mapLeftThenRightUntils : Zipper a → (Bool → a → Maybe (List a × b)) → Maybe (Zipper a × b) mapLeftThenRightUntils {a} {b} z f = case mapUntils reverse (f true) (prefix z) of λ where (Just (p' , b)) → Just (record z { prefix = p' } , b) Nothing → case mapUntils id (f false) (suffix z) of λ where (Just (s' , b)) → Just (record z { suffix = s' } , b) Nothing → Nothing {-# COMPILE AGDA2HS mapLeftThenRightUntils #-}
31.864943
86
0.586437
c77ff6015c789e77c6ad09c27875a33f313d3e64
566
agda
Agda
Cubical/Algebra/CommRing/Kernel.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/CommRing/Kernel.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Kernel.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.Kernel where open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRing.Base open import Cubical.Algebra.CommRing.Ideal using (IdealsIn; Ideal→CommIdeal) open import Cubical.Algebra.Ring.Kernel using () renaming (kernelIdeal to ringKernelIdeal) private variable ℓ : Level -- If R and S were implicit, their ·Comm component could (almost?) never be inferred. kernelIdeal : (R S : CommRing ℓ) (f : CommRingHom R S) → IdealsIn R kernelIdeal _ _ f = Ideal→CommIdeal (ringKernelIdeal f)
31.444444
90
0.765018
0eaaed507aec516519878778ee0e89a99aefeaf7
27,934
agda
Agda
Structure/Setoid/Size/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Structure/Setoid/Size/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Structure/Setoid/Size/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Structure.Setoid.Size.Proofs where open import Data open import Data.Proofs import Data.Either as Either import Data.Either.Proofs as Either import Lvl open import Functional open import Function.Proofs open import Function.Inverseₗ open import Function.Inverse open import Function.Iteration open import Lang.Instance open import Logic open import Logic.Classical open import Logic.Propositional open import Logic.Predicate open import Structure.Setoid open import Structure.Setoid.Size open import Structure.Function.Domain open import Structure.Function.Domain.Proofs open import Structure.Function open import Structure.Relator.Equivalence open import Structure.Relator.Ordering open import Structure.Relator.Properties open import Syntax.Transitivity open import Type.Properties.Empty open import Type.Properties.Inhabited open import Type private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₗ : Lvl.Level private variable A B C : Setoid{ℓₑ}{ℓ} private variable X Y Z : Type{ℓ} module _ where instance [≍]-to-[≼] : (_≍_ {ℓₑ₁}{ℓ₁}{ℓₑ₂}{ℓ₂}) ⊆₂ (_≼_) _⊆₂_.proof [≍]-to-[≼] ([∃]-intro(f) ⦃ [∧]-intro f-function f-bijective ⦄) = ([∃]-intro(f) ⦃ [∧]-intro f-function (bijective-to-injective(f) ⦃ f-bijective ⦄) ⦄) instance [≍]-to-[≽] : (_≍_ {ℓₑ₁}{ℓ₁}{ℓₑ₂}{ℓ₂}) ⊆₂ (_≽_) _⊆₂_.proof [≍]-to-[≽] ([∃]-intro(f) ⦃ [∧]-intro f-function f-bijective ⦄) = ([∃]-intro(f) ⦃ [∧]-intro f-function (bijective-to-surjective(f) ⦃ f-bijective ⦄) ⦄) [≼]-empty-is-minimal : (([∃]-intro(Empty{ℓ})) ≼ A) [≼]-empty-is-minimal = [∃]-intro empty ⦃ [∧]-intro empty-function empty-injective ⦄ [≽]-empty-is-not-minimal : ¬(∀{A : Setoid{ℓ}} → (A ≽ ([∃]-intro(Empty{ℓ})))) [≽]-empty-is-not-minimal proof with () ← [∃]-witness(proof {[∃]-intro Unit}) <> [≼]-to-[≽]-not-all : ¬((_≼_ {ℓ}) ⊆₂ swap(_≽_)) [≼]-to-[≽]-not-all (intro proof) = [≽]-empty-is-not-minimal(proof [≼]-empty-is-minimal) [≼]-to-[≽]-for-inhabited : ⦃ _ : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ ⦃ inh-A : (◊([∃]-witness A)) ⦄ → ((A ≼ B) → (B ≽ A)) [≼]-to-[≽]-for-inhabited {A = [∃]-intro a} {B = [∃]-intro b} ([∃]-intro f ⦃ [∧]-intro f-func f-inj ⦄) = [∃]-intro (invₗ-construction(const [◊]-existence) f) ⦃ [∧]-intro (invₗ-construction-function ⦃ inj = f-inj ⦄) (inverseₗ-surjective ⦃ inverₗ = invₗ-construction-inverseₗ ⦃ inj = f-inj ⦄ ⦄) ⦄ {- TODO: Maybe this proof could be made to a proof about invertibility instead [≼][≍]-almost-antisymmetry : ⦃ _ : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ → (A ≼ B) → (B ≼ A) → (A ≽ B) [≼][≍]-almost-antisymmetry {A = A}{B = B} ([∃]-intro f ⦃ [∧]-intro func-f inj-f ⦄) ([∃]-intro g ⦃ [∧]-intro func-g inj-g ⦄) = [∃]-intro h ⦃ [∧]-intro func-h surj-h ⦄ where h : [∃]-witness A → [∃]-witness B h(a) = Either.map1 [∃]-witness (const(f(a))) (excluded-middle(∃(b ↦ g(b) ≡ a))) func-h : Function(h) Function.congruence func-h {a₁} {a₂} a₁a₂ with excluded-middle(∃(b ↦ g(b) ≡ a₁)) | excluded-middle(∃(b ↦ g(b) ≡ a₂)) | a₁a₂ -- TODO: Not sure why the last a₁a₂ is neccessary for the result to normalize from the cases, if this is a bug in Agda or if it is intended. An alternative is to just use two-layered Either.map1-values ... | [∨]-introₗ ([∃]-intro b₁ ⦃ gba1 ⦄) | [∨]-introₗ ([∃]-intro b₂ ⦃ gba2 ⦄) | _ = injective(g) ⦃ inj-g ⦄ (gba1 🝖 a₁a₂ 🝖 symmetry(_≡_) gba2) ... | [∨]-introₗ ([∃]-intro b₁ ⦃ gba1 ⦄) | [∨]-introᵣ ngba2 | _ = [⊥]-elim(ngba2([∃]-intro b₁ ⦃ gba1 🝖 a₁a₂ ⦄)) ... | [∨]-introᵣ ngba1 | [∨]-introₗ ([∃]-intro b₂ ⦃ gba2 ⦄) | _ = [⊥]-elim(ngba1([∃]-intro b₂ ⦃ gba2 🝖 symmetry(_≡_) a₁a₂ ⦄)) ... | [∨]-introᵣ _ | [∨]-introᵣ _ | _ = congruence₁(f) ⦃ func-f ⦄ a₁a₂ {- TODO: This choice of h probably does not work for proving antisymmetry because nothing states that f and g are inverses, which is neccessary for this kind of proof inj-h : Injective(h) Injective.proof inj-h {a₁} {a₂} ha₁ha₂ with excluded-middle(∃(b ↦ g(b) ≡ a₁)) | excluded-middle(∃(b ↦ g(b) ≡ a₂)) | ha₁ha₂ ... | [∨]-introₗ ([∃]-intro b₁ ⦃ gba1 ⦄) | [∨]-introₗ ([∃]-intro b₂ ⦃ gba2 ⦄) | b₁b₂ = a₁ 🝖-[ gba1 ]-sym g(b₁) 🝖-[ congruence₁(g) ⦃ func-g ⦄ b₁b₂ ] g(b₂) 🝖-[ gba2 ] a₂ 🝖-end ... | [∨]-introₗ ([∃]-intro b₁ ⦃ gba1 ⦄) | [∨]-introᵣ nega₂ | b₁fa₂ = [⊥]-elim(nega₂ ([∃]-intro (f(a₂)) ⦃ p ⦄)) where p = g(f(a₂)) 🝖-[ congruence₁(g) ⦃ func-g ⦄ b₁fa₂ ]-sym g(b₁) 🝖-[ gba1 ] a₁ 🝖-[ {!gba1!} ] a₂ 🝖-end q = f(a₁) 🝖-[ congruence₁(f) ⦃ func-f ⦄ gba1 ]-sym f(g(b₁)) 🝖-[ {!!} ] b₁ 🝖-[ b₁fa₂ ] f(a₂) 🝖-end ... | [∨]-introᵣ nega₁ | [∨]-introₗ ([∃]-intro b₂ ⦃ gba2 ⦄) | fa₁b₂ = {!!} ... | [∨]-introᵣ nega₁ | [∨]-introᵣ nega₂ | fa₁fa₂ = injective(f) ⦃ inj-f ⦄ fa₁fa₂ -} -- TODO: Is it possible to use [≼]-to-[≽]-for-inhabited instead or maybe this should be moved out? surj-h : Surjective(h) Surjective.proof surj-h {b} with Either.map1-values{f = [∃]-witness}{g = const(f(g(b)))}{e = excluded-middle(∃(x ↦ g(x) ≡ g(b)))} ... | [∨]-introₗ ([∃]-intro ([∃]-intro b₂ ⦃ gb₂gb ⦄) ⦃ fgbb₂ ⦄) = [∃]-intro (g(b)) ⦃ fgbb₂ 🝖 injective(g) ⦃ inj-g ⦄ gb₂gb ⦄ ... | [∨]-introᵣ([∃]-intro neggb ⦃ p ⦄) = [⊥]-elim(neggb ([∃]-intro b ⦃ reflexivity(_≡_) ⦄)) -} open import Structure.Operator open import Structure.Setoid.Uniqueness module _ ⦃ equiv-X : Equiv{ℓₑ₁}(X) ⦄ ⦃ equiv-Y : Equiv{ℓₑ₂}(Y) ⦄ (P : X → Type{ℓₗ}) ⦃ classical-P : Classical(∃ P) ⦄ (c : ¬(∃ P) → Y) (f : X → Y) ⦃ func-f : Function(f) ⦄ where -- TODO: Maybe f should also be able to depend on P, so that (f : (x : X) → P(x) → Y)? -- TODO: This is a generalization of both h in [≼][≍]-antisymmetry-raw and invₗ-construction from Function.Inverseₗ existence-decider : Y existence-decider = Either.map1 (f ∘ [∃]-witness) c (excluded-middle(∃ P)) existence-decider-satisfaction-value : Unique(P) → ∀{x} → P(x) → (f(x) ≡ existence-decider) existence-decider-satisfaction-value unique-P {x} px with Classical.excluded-middle classical-P ... | Either.Left ([∃]-intro y ⦃ py ⦄) = congruence₁(f) (unique-P px py) ... | Either.Right nep with () ← nep ([∃]-intro x ⦃ px ⦄) existence-decider-unsatisfaction-value : ⦃ Constant(c) ⦄ → (p : ¬(∃ P)) → (c(p) ≡ existence-decider) existence-decider-unsatisfaction-value nep with Classical.excluded-middle classical-P ... | Either.Left ep with () ← nep ep ... | Either.Right _ = constant(c) module _ ⦃ equiv-X : Equiv{ℓₑ₁}(X) ⦄ ⦃ equiv-Y : Equiv{ℓₑ₂}(Y) ⦄ ⦃ equiv-Z : Equiv{ℓₑ₃}(Z) ⦄ (P : X → Y → Type{ℓₗ}) ⦃ classical-P : ∀{x} → Classical(∃(P(x))) ⦄ (c : (x : X) → ¬(∃(P(x))) → Z) (f : X → Y → Z) ⦃ func-f : BinaryOperator(f) ⦄ where existence-decider-fn : X → Z existence-decider-fn(x) = existence-decider (P(x)) (c(x)) (f(x)) ⦃ BinaryOperator.right func-f ⦄ open import Structure.Relator existence-decider-fn-function : (∀{x} → Unique(P(x))) → (∀{x₁ x₂}{p₁ p₂} → (x₁ ≡ x₂) → (c x₁ p₁ ≡ c x₂ p₂)) → ⦃ ∀{y} → UnaryRelator(swap P y) ⦄ → Function(existence-decider-fn) Function.congruence (existence-decider-fn-function unique constant) {x₁} {x₂} x₁x₂ with excluded-middle(∃(P(x₁))) | excluded-middle(∃(P(x₂))) | x₁x₂ ... | [∨]-introₗ ([∃]-intro y₁ ⦃ p₁ ⦄) | [∨]-introₗ ([∃]-intro y₂ ⦃ p₂ ⦄) | _ = congruence₂(f) x₁x₂ (unique (substitute₁(swap P y₁) x₁x₂ p₁) p₂) ... | [∨]-introₗ ([∃]-intro y₁ ⦃ p₁ ⦄) | [∨]-introᵣ ngba2 | _ with () ← ngba2 ([∃]-intro y₁ ⦃ substitute₁(swap P y₁) x₁x₂ p₁ ⦄) ... | [∨]-introᵣ ngba1 | [∨]-introₗ ([∃]-intro y₂ ⦃ p₂ ⦄) | _ with () ← ngba1 ([∃]-intro y₂ ⦃ substitute₁(swap P y₂) (symmetry(_≡_) x₁x₂) p₂ ⦄) ... | [∨]-introᵣ _ | [∨]-introᵣ _ | _ = constant x₁x₂ existence-decider-fn-surjective : (∀{x} → Unique(P(x))) → ⦃ ∀{x} → Constant(c(x)) ⦄ → (∀{z} → ∃(x ↦ (∀{y} → P(x)(y) → (f x y ≡ z)) ∧ ((nepx : ¬ ∃(P(x))) → (c x nepx ≡ z)))) → Surjective(existence-decider-fn) Surjective.proof (existence-decider-fn-surjective unique-p property) {z} with [∃]-intro x ⦃ px ⦄ ← property{z} with excluded-middle(∃(P(x))) ... | [∨]-introₗ ([∃]-intro y ⦃ pxy ⦄) = [∃]-intro x ⦃ symmetry(_≡_) (existence-decider-satisfaction-value(P(x)) (c(x)) (f(x)) ⦃ BinaryOperator.right func-f ⦄ unique-p pxy) 🝖 [∧]-elimₗ px pxy ⦄ ... | [∨]-introᵣ nepx = [∃]-intro x ⦃ symmetry(_≡_) (existence-decider-unsatisfaction-value(P(x)) (c(x)) (f(x)) ⦃ BinaryOperator.right func-f ⦄ nepx) 🝖 [∧]-elimᵣ px nepx ⦄ existence-decider-fn-surjective2 : (∀{x} → Unique(P(x))) → ⦃ ∀{x} → Constant(c(x)) ⦄ → (∃{Obj = Z → X}(x ↦ (∀{z}{y} → P(x(z))(y) → (f (x(z)) y ≡ z)) ∧ (∀{z} → (nepx : ¬ ∃(P(x(z)))) → (c (x(z)) nepx ≡ z)))) → Surjective(existence-decider-fn) Surjective.proof (existence-decider-fn-surjective2 unique-p property) {z} with [∃]-intro x ⦃ px ⦄ ← property with excluded-middle(∃(P(x(z)))) ... | [∨]-introₗ ([∃]-intro y ⦃ pxy ⦄) = [∃]-intro (x(z)) ⦃ symmetry(_≡_) (existence-decider-satisfaction-value(P(x(z))) (c(x(z))) (f(x(z))) ⦃ BinaryOperator.right func-f ⦄ unique-p pxy) 🝖 [∧]-elimₗ px pxy ⦄ ... | [∨]-introᵣ nepx = [∃]-intro (x(z)) ⦃ symmetry(_≡_) (existence-decider-unsatisfaction-value(P(x(z))) (c(x(z))) (f(x(z))) ⦃ BinaryOperator.right func-f ⦄ nepx) 🝖 [∧]-elimᵣ px nepx ⦄ module _ (inj-f : ∀{x₁ x₂}{y₁ y₂} → P(x₁)(y₁) → P(x₂)(y₂) → (f x₁ y₁ ≡ f x₂ y₂) → (x₁ ≡ x₂)) (inj-c : ∀{x₁ x₂} → (nep₁ : ¬ ∃(P(x₁))) → (nep₂ : ¬ ∃(P(x₂))) → (c x₁ nep₁ ≡ c x₂ nep₂) → (x₁ ≡ x₂)) (inj-mix : ∀{x₁ x₂}{y₁} → P(x₁)(y₁) → (nep₂ : ¬ ∃(P(x₂))) → (f x₁ y₁ ≡ c x₂ nep₂) → (x₁ ≡ x₂)) where existence-decider-fn-injective : Injective(existence-decider-fn) Injective.proof existence-decider-fn-injective {x₁}{x₂} dx₁dx₂ with excluded-middle(∃(P(x₁))) | excluded-middle(∃(P(x₂))) | dx₁dx₂ ... | Either.Left ([∃]-intro y₁ ⦃ p₁ ⦄) | Either.Left ([∃]-intro y₂ ⦃ p₂ ⦄) | fx₁y₁fx₂y₂ = inj-f p₁ p₂ fx₁y₁fx₂y₂ ... | Either.Left ([∃]-intro y₁ ⦃ p₁ ⦄) | Either.Right nep₂ | fxy₁cxp₂ = inj-mix p₁ nep₂ fxy₁cxp₂ ... | Either.Right nep₁ | Either.Left ([∃]-intro y₂ ⦃ p₂ ⦄) | cxp₁fxy₂ = symmetry(_≡_) (inj-mix p₂ nep₁ (symmetry(_≡_) cxp₁fxy₂)) ... | Either.Right nep₁ | Either.Right nep₂ | cxp₁cxp₂ = inj-c nep₁ nep₂ cxp₁cxp₂ -- The property of antisymmetry for injection existence. -- Also called: Cantor-Schröder-Bernstein Theorem, Schröder-Bernstein Theorem, Cantor–Bernstein theorem -- Source: https://artofproblemsolving.com/wiki/index.php/Schroeder-Bernstein_Theorem [≼][≍]-antisymmetry-raw : ⦃ _ : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ → (A ≼ B) → (B ≼ A) → (A ≍ B) -- TODO: Not everything needs to be classical, only forall, exists, and equality [≼][≍]-antisymmetry-raw {A = [∃]-intro A}{B = [∃]-intro B} ⦃ classical ⦄ ([∃]-intro f ⦃ [∧]-intro func-f inj-f ⦄) ([∃]-intro g ⦃ [∧]-intro func-g inj-g ⦄) = [∃]-intro h ⦃ [∧]-intro func-h (injective-surjective-to-bijective(h)) ⦄ where open import Logic.Predicate.Theorems open import Function.Inverseₗ open import Numeral.Natural open import Structure.Relator -- A lone point `b` of `B` is a point not in the image of `f`. Lone : B → Stmt Lone(b) = ∀{a} → (f(a) ≢ b) -- A point `b₁` is a descendent from a point `b₀` in `B` when a number of compositions of `(f ∘ g)` on `b₀` yields `b₁`. Desc : B → B → Stmt Desc(b₁)(b₀) = ∃(n ↦ (b₁ ≡ ((f ∘ g) ^ n)(b₀))) instance lone-desc-rel : ∀{y} → UnaryRelator(x ↦ Lone(y) ∧ Desc(f(x)) y) UnaryRelator.substitution lone-desc-rel xy = [∧]-map id (ep ↦ [∃]-map-proof-dependent ep (symmetry(_≡_) (congruence₁(f) ⦃ func-f ⦄ xy) 🝖_)) f⁻¹ : B → A f⁻¹ = invₗ-construction g f g⁻¹ : A → B g⁻¹ = invₗ-construction f g instance func-f⁻¹ : Function(f⁻¹) func-f⁻¹ = invₗ-construction-function ⦃ inj = inj-f ⦄ ⦃ func-g ⦄ instance func-g⁻¹ : Function(g⁻¹) func-g⁻¹ = invₗ-construction-function ⦃ inj = inj-g ⦄ ⦃ func-f ⦄ instance inverₗ-f⁻¹ : Inverseₗ(f)(f⁻¹) inverₗ-f⁻¹ = invₗ-construction-inverseₗ ⦃ inj = inj-f ⦄ ⦃ func-g ⦄ instance inverₗ-g⁻¹ : Inverseₗ(g)(g⁻¹) inverₗ-g⁻¹ = invₗ-construction-inverseₗ ⦃ inj = inj-g ⦄ ⦃ func-f ⦄ instance func-const-invₗ-construction : BinaryOperator(const ∘ g⁻¹) func-const-invₗ-construction = functions-to-binaryOperator _ ⦃ r = const-function ⦄ -- The to-be-proven bijection. -- `h` is a mapping such that: -- • If `f(a)` is a descendent of a lonely point, then `h(a) = g⁻¹(a)`. -- • If `f(a)` is not a descendent of a lonely point, then `h(a) = f(a)`. -- Note: The construction of this function requires excluded middle. h : A → B h = existence-decider-fn (a ↦ b ↦ Lone(b) ∧ Desc(f(a))(b)) (\a _ → f(a)) (\a _ → g⁻¹(a)) -- The left inverse of `g` is a right inverse on a point `a` when `f(a)` is a descendent of a lonely point. inverᵣ-g⁻¹-specific : ∀{a}{b} → Lone(b) → Desc(f(a))(b) → (g(g⁻¹(a)) ≡ a) inverᵣ-g⁻¹-specific lone-b ([∃]-intro 𝟎 ⦃ desc-b ⦄) with () ← lone-b desc-b inverᵣ-g⁻¹-specific {a}{b} lone-b ([∃]-intro (𝐒(n)) ⦃ desc-b ⦄) = g(g⁻¹(a)) 🝖[ _≡_ ]-[ congruence₁(g) ⦃ func-g ⦄ (congruence₁(g⁻¹) (injective(f) ⦃ inj-f ⦄ desc-b)) ] g(g⁻¹(g(((f ∘ g) ^ n)(b)))) 🝖[ _≡_ ]-[ congruence₁(g) ⦃ func-g ⦄ (inverseₗ(g)(g⁻¹)) ] g(((f ∘ g) ^ n)(b)) 🝖[ _≡_ ]-[ inverseₗ(f)(f⁻¹) ]-sym f⁻¹(f(g(((f ∘ g) ^ n)(b)))) 🝖[ _≡_ ]-[] f⁻¹(((f ∘ g) ^ 𝐒(n))(b)) 🝖[ _≡_ ]-[ congruence₁(f⁻¹) desc-b ]-sym f⁻¹(f(a)) 🝖[ _≡_ ]-[ inverseₗ(f)(f⁻¹) ] a 🝖-end inj-different-fgn : ∀{n₁ n₂}{b₁ b₂} → (((f ∘ g) ^ n₁)(b₁) ≡ ((f ∘ g) ^ n₂)(b₂)) → ∃(n ↦ (b₁ ≡ ((f ∘ g) ^ 𝐒(n))(b₂)) ∨ (((f ∘ g) ^ 𝐒(n))(b₁) ≡ b₂) ∨ (b₁ ≡ b₂)) inj-different-fgn {𝟎} {𝟎} p = [∃]-intro 𝟎 ⦃ [∨]-introᵣ p ⦄ inj-different-fgn {𝟎} {𝐒 n₂} p = [∃]-intro n₂ ⦃ [∨]-introₗ([∨]-introₗ p) ⦄ inj-different-fgn {𝐒 n₁} {𝟎} p = [∃]-intro n₁ ⦃ [∨]-introₗ([∨]-introᵣ p) ⦄ inj-different-fgn {𝐒 n₁} {𝐒 n₂} p = inj-different-fgn {n₁} {n₂} (Injective.proof inj-g(Injective.proof inj-f p)) -- The lonely points are unique for all descendents from the image of `f`. unique-lone-descendant : ∀{a} → Unique(b ↦ Lone(b) ∧ Desc(f(a))(b)) unique-lone-descendant {a} {b₁} {b₂} ([∧]-intro lone-b₁ ([∃]-intro n₁ ⦃ desc-b₁ ⦄)) ([∧]-intro lone-b₂ ([∃]-intro n₂ ⦃ desc-b₂ ⦄)) with inj-different-fgn{n₁}{n₂}{b₁}{b₂} (symmetry(_≡_) desc-b₁ 🝖 desc-b₂) ... | [∃]-intro n ⦃ Either.Left(Either.Left p) ⦄ with () ← lone-b₁ (symmetry(_≡_) p) ... | [∃]-intro n ⦃ Either.Left(Either.Right p) ⦄ with () ← lone-b₂ p ... | [∃]-intro n ⦃ Either.Right b₁b₂ ⦄ = b₁b₂ instance func-h : Function(h) func-h = existence-decider-fn-function (a ↦ b ↦ Lone(b) ∧ Desc(f(a))(b)) (\x _ → f(x)) (const ∘ g⁻¹) unique-lone-descendant (congruence₁(f) ⦃ func-f ⦄) -- What it means to not have a lonely descendent. not-lone-desc : ∀{a} → ¬ ∃(b ↦ Lone(b) ∧ Desc(f(a)) b) → (∀{b} → (∃(x ↦ f(x) ≡ b) ∨ (∀{n} → (f(a) ≢ ((f ∘ g) ^ n)(b))))) not-lone-desc {z} = (\nepx {x} → (Either.map ([∃]-map-proof [¬¬]-elim ∘ [¬∀]-to-[∃¬] ⦃ classical ⦄ ⦃ classical ⦄) [¬∃]-to-[∀¬] ∘ [¬]-preserves-[∧][∨]ᵣ) (nepx{x})) ∘ [¬∃]-to-[∀¬] instance surj-h : Surjective(h) Surjective.proof surj-h {z} with excluded-middle(∃(y ↦ Lone(y) ∧ Desc(f(g(z))) y)) ... | [∨]-introₗ ([∃]-intro y ⦃ pxy ⦄) = [∃]-intro (g(z)) ⦃ symmetry(_≡_) (existence-decider-satisfaction-value(y ↦ Lone(y) ∧ Desc(f(g(z))) y) (\_ → f(g(z))) (\_ → g⁻¹(g(z))) unique-lone-descendant pxy) 🝖 inverseₗ(g)(g⁻¹) ⦄ ... | [∨]-introᵣ nepx = [∨]-elim (\([∃]-intro x ⦃ p ⦄) → [∃]-intro x ⦃ symmetry(_≡_) (existence-decider-unsatisfaction-value(y ↦ Lone(y) ∧ Desc(f(x)) y) (\_ → f(x)) (\_ → g⁻¹(x)) ⦃ const-function ⦄ ⦃ intro(reflexivity(_≡_)) ⦄ \([∃]-intro xx ⦃ [∧]-intro pp₁ ([∃]-intro n ⦃ pp₂ ⦄) ⦄) → nepx ([∃]-intro xx ⦃ [∧]-intro (\{xxx} ppp → pp₁ ppp) ([∃]-intro (𝐒(n)) ⦃ congruence₁(f) ⦃ func-f ⦄ (congruence₁(g) ⦃ func-g ⦄ (symmetry(_≡_) p 🝖 pp₂)) ⦄) ⦄)) 🝖 p ⦄) (\p → [∃]-intro (g(z)) ⦃ symmetry(_≡_) (existence-decider-unsatisfaction-value(y ↦ Lone(y) ∧ Desc(f(g(z))) y) (\_ → f(g(z))) (\_ → g⁻¹(g(z))) ⦃ const-function ⦄ ⦃ intro(reflexivity(_≡_)) ⦄ nepx) 🝖 [⊥]-elim(p{1} (reflexivity(_≡_))) ⦄) (not-lone-desc nepx {z}) {-TODO: How to define surj-h using existence-decider-fn-surjective? Should existence-decider-fn-surjective be more general? surj-h = existence-decider-fn-surjective (a ↦ b ↦ Lone(b) ∧ Desc(f(a))(b)) (\x _ → f(x)) (const ∘ invₗ-construction f g) unique-lone-descendant ⦃ intro (reflexivity(_≡_)) ⦄ (\{z} → [∃]-intro (g(z)) ⦃ [∧]-intro (\{y} ([∧]-intro lone-y desc-y) → inverseₗ(g)(g⁻¹)) -- ((\nepx → [⊥]-elim(nepx{z} ([∧]-intro (\{x} fxz → nepx{f(x)} ([∧]-intro (\{x'} p → {!!}) {!!})) ([∃]-intro 1 ⦃ reflexivity(_≡_) ⦄)))) ∘ [¬∃]-to-[∀¬]) ((\nepx → Either.map1 ((\([∃]-intro x ⦃ p ⦄) → {!!}) ∘ [∃]-map-proof [¬¬]-elim) (\p → [⊥]-elim(p{1} (reflexivity(_≡_)))) (Either.map ([¬∀]-to-[∃¬] ⦃ classical ⦄ ⦃ classical ⦄) [¬∃]-to-[∀¬] ([¬]-preserves-[∧][∨]ᵣ (nepx{z}))) ) ∘ [¬∃]-to-[∀¬]) ⦄) -} instance inj-h : Injective(h) inj-h = existence-decider-fn-injective (a ↦ b ↦ Lone(b) ∧ Desc(f(a))(b)) (\x _ → f(x)) (const ∘ invₗ-construction f g) (\{x₁ x₂}{y₁ y₂} ([∧]-intro lone₁ desc₁) ([∧]-intro lone₂ desc₂) g⁻¹x₁g⁻¹x₂ → x₁ 🝖[ _≡_ ]-[ inverᵣ-g⁻¹-specific lone₁ desc₁ ]-sym (g ∘ g⁻¹)(x₁) 🝖[ _≡_ ]-[ congruence₁(g) ⦃ func-g ⦄ g⁻¹x₁g⁻¹x₂ ] (g ∘ g⁻¹)(x₂) 🝖[ _≡_ ]-[ inverᵣ-g⁻¹-specific lone₂ desc₂ ] x₂ 🝖-end ) (\_ _ → Injective.proof inj-f) (\{ {_} {_} {_} ([∧]-intro lone₁ ([∃]-intro 𝟎 ⦃ desc₁ ⦄)) no g⁻¹x₁fx₂ → [⊥]-elim(lone₁ desc₁) ; {x₁}{x₂}{y₁} ([∧]-intro lone₁ ([∃]-intro (𝐒(n₁)) ⦃ desc₁ ⦄)) no g⁻¹x₁fx₂ → [⊥]-elim(no([∃]-intro y₁ ⦃ [∧]-intro lone₁ ([∃]-intro n₁ ⦃ f(x₂) 🝖[ _≡_ ]-[ g⁻¹x₁fx₂ ]-sym g⁻¹(x₁) 🝖[ _≡_ ]-[ congruence₁(g⁻¹) (injective(f) ⦃ inj-f ⦄ desc₁) ] g⁻¹(g(((f ∘ g) ^ n₁)(y₁))) 🝖[ _≡_ ]-[ inverseₗ(g)(g⁻¹) ] ((f ∘ g) ^ n₁)(y₁) 🝖-end ⦄) ⦄)) }) instance [≼][≍]-antisymmetry : ⦃ _ : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ → Antisymmetry(_≼_ {ℓₑ}{ℓ})(_≍_) [≼][≍]-antisymmetry = intro [≼][≍]-antisymmetry-raw instance [≍]-reflexivity : Reflexivity(_≍_ {ℓₑ}{ℓ}) Reflexivity.proof([≍]-reflexivity) = [∃]-intro(id) ⦃ [∧]-intro id-function id-bijective ⦄ instance [≍]-symmetry : Symmetry(_≍_ {ℓₑ}{ℓ}) Symmetry.proof [≍]-symmetry ([∃]-intro(f) ⦃ [∧]-intro f-function f-bijective ⦄) = ([∃]-intro(inv f) ⦃ [∧]-intro inv-function (inv-bijective ⦃ func = f-function ⦄) ⦄) where instance f-invertible : Invertible(f) f-invertible = bijective-to-invertible ⦃ bij = f-bijective ⦄ instance invf-invertible : Invertible(inv f) ∃.witness invf-invertible = f ∃.proof invf-invertible = [∧]-intro f-function (Inverse-symmetry ([∧]-elimᵣ([∃]-proof f-invertible))) instance [≍]-transitivity : Transitivity(_≍_ {ℓₑ}{ℓ}) Transitivity.proof([≍]-transitivity) ([∃]-intro(f) ⦃ [∧]-intro f-function f-bijective ⦄) ([∃]-intro(g) ⦃ [∧]-intro g-function g-bijective ⦄) = [∃]-intro(g ∘ f) ⦃ [∧]-intro ([∘]-function {f = g}{g = f} ⦃ g-function ⦄ ⦃ f-function ⦄) ([∘]-bijective {f = g} ⦃ g-function ⦄ {g = f} ⦃ g-bijective ⦄ ⦃ f-bijective ⦄) ⦄ instance [≍]-equivalence : Equivalence(_≍_ {ℓₑ}{ℓ}) [≍]-equivalence = intro instance [≼]-reflexivity : Reflexivity(_≼_ {ℓₑ}{ℓ}) Reflexivity.proof([≼]-reflexivity) = [∃]-intro(id) ⦃ [∧]-intro id-function id-injective ⦄ instance [≼]-transitivity : Transitivity(_≼_ {ℓₑ}{ℓ}) Transitivity.proof([≼]-transitivity) ([∃]-intro(f) ⦃ [∧]-intro f-function f-injective ⦄) ([∃]-intro(g) ⦃ [∧]-intro g-function g-injective ⦄) = [∃]-intro(g ∘ f) ⦃ [∧]-intro ([∘]-function {f = g}{g = f} ⦃ g-function ⦄ ⦃ f-function ⦄) ([∘]-injective {f = g}{g = f} ⦃ g-injective ⦄ ⦃ f-injective ⦄) ⦄ instance [≽]-reflexivity : Reflexivity(_≽_ {ℓₑ}{ℓ}) Reflexivity.proof([≽]-reflexivity) = [∃]-intro(id) ⦃ [∧]-intro id-function id-surjective ⦄ instance [≽]-transitivity : Transitivity(_≽_ {ℓₑ}{ℓ}) Transitivity.proof([≽]-transitivity) ([∃]-intro(f) ⦃ [∧]-intro f-function f-surjective ⦄) ([∃]-intro(g) ⦃ [∧]-intro g-function g-surjective ⦄) = [∃]-intro(g ∘ f) ⦃ [∧]-intro ([∘]-function {f = g}{g = f} ⦃ g-function ⦄ ⦃ f-function ⦄) ([∘]-surjective {f = g} ⦃ g-function ⦄ {g = f} ⦃ g-surjective ⦄ ⦃ f-surjective ⦄) ⦄ module _ where -- This is variant of the "extensional axiom of choice" and is unprovable in Agda, though it is a possible axiom. -- A proof of `(A ≽ B)` means that a right inverse exist, but if the surjection is non-injective (it could be in general), then the right inverse is not a function (two equal values in the codomain of the surjection may point to two inequal objects in the domain). -- Example: -- For X: Set, Y: Set, f: X → Y, a: X, b: X, c₁: Y, c₂: Y -- Assume: -- X = {a,b} -- Y = {c₁,c₂} -- a ≢ b -- c₁ ≡ c₂ -- f(a) = c₁ -- f(b) = c₂ -- This means that f is surjective (maps to both c₁ and c₂) but not injective ((c₁ ≡ c₂) implies (f(a) ≡ f(b)) implies (a ≡ b) which is false). -- Then an inverse f⁻¹ to f can be constructed from the witnesses in surjectivity: -- f⁻¹: Y → X -- f⁻¹(c₁) = a -- f⁻¹(c₂) = b -- f⁻¹ is obviously injective, but it is also not a function: ((c₁ ≡ c₂) would imply (a ≡ b) if it were a function, but that is false). -- This example shows that not all surjections are injective. -- But looking at the example, there are functions that are injective: -- g₁: Y → X -- g₁(c₁) = a -- g₁(c₂) = a -- -- g₂: Y → X -- g₂(c₁) = b -- g₂(c₂) = b -- They are, because: ((a ≡ a) implies (g₁(c₁) ≡ g₁(c₂)) implies (c₁ ≡ c₂) which is true). -- and : ((b ≡ b) implies (g₂(c₁) ≡ g₂(c₂)) implies (c₁ ≡ c₂) which is true). -- This is a simplified example for finite sets, and a restriction of this proposition for finite sets is actually provable because it is possible to enumerate all functions up to function extensionality. -- The real problem comes when the sets are non-finite because then, there is no general way to enumerate the elements. How would an injection be chosen in this case? -- Note that if the surjection is injective, then it is a bijection, and therefore also an injection. record SurjectionInjectionChoice (A : Setoid{ℓₑ₁}{ℓ₁}) (B : Setoid{ℓₑ₂}{ℓ₂}) : Stmt{ℓₑ₁ Lvl.⊔ ℓ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓ₂} where constructor intro field proof : (A ≽ B) → (B ≼ A) open SurjectionInjectionChoice ⦃ … ⦄ using () renaming (proof to [≽]-to-[≼]) public record SurjectionInvertibleFunctionChoice (A : Setoid{ℓₑ₁}{ℓ₁}) (B : Setoid{ℓₑ₂}{ℓ₂}) : Stmt{ℓₑ₁ Lvl.⊔ ℓ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓ₂} where constructor intro field invertibleᵣ : ∀{f : ∃.witness A → ∃.witness B} → Surjective(f) → Invertibleᵣ(f) function : ∀{f : ∃.witness A → ∃.witness B}{surj : Surjective(f)} → Function(∃.witness(invertibleᵣ surj)) module _ ⦃ classical : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ ⦃ surjChoice-ab : SurjectionInjectionChoice A B ⦄ ⦃ surjChoice-ba : SurjectionInjectionChoice B A ⦄ where [≽][≍]-antisymmetry-raw : (A ≽ B) → (B ≽ A) → (A ≍ B) [≽][≍]-antisymmetry-raw ab ba = [≼][≍]-antisymmetry-raw ([≽]-to-[≼] ba) ([≽]-to-[≼] ab) module _ ⦃ classical : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ ⦃ surjChoice-ab : SurjectionInjectionChoice A B ⦄ where [≼][≽][≍]-antisymmetry-raw : (A ≼ B) → (A ≽ B) → (A ≍ B) [≼][≽][≍]-antisymmetry-raw lesser greater = [≼][≍]-antisymmetry-raw lesser ([≽]-to-[≼] greater) module _ ⦃ classical : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ ⦃ surjChoice : ∀{ℓ₁ ℓ₂ ℓₑ₁ ℓₑ₂}{A : Setoid{ℓₑ₁}{ℓ₁}}{B : Setoid{ℓₑ₂}{ℓ₂}} → SurjectionInjectionChoice A B ⦄ where instance [≽][≍]-antisymmetry : Antisymmetry(_≽_ {ℓₑ}{ℓ})(_≍_) [≽][≍]-antisymmetry = intro [≽][≍]-antisymmetry-raw -- TODO: Totality of (_≼_). Is this difficult to prove? -- [≼]-total : ((A ≼ B) ∨ (B ≼ A)) -- TODO: Move global-equiv : ∀{ℓ}{T : Type{ℓ}} → Equiv{ℓₑ}(T) Equiv._≡_ global-equiv = const(const Unit) Equivalence.reflexivity (Equiv.equivalence global-equiv) = intro <> Equivalence.symmetry (Equiv.equivalence global-equiv) = intro(const <>) Equivalence.transitivity (Equiv.equivalence global-equiv) = intro(const(const <>)) [≼]-to-[≽]-for-inhabited-to-excluded-middle : (∀{ℓ₁ ℓ₂ ℓₑ₁ ℓₑ₂}{A : Setoid{ℓₑ₁}{ℓ₁}}{B : Setoid{ℓₑ₂}{ℓ₂}} → ⦃ ◊([∃]-witness A) ⦄ → (A ≼ B) → (B ≽ A)) → (∀{P : Type{ℓ}} → Classical(P)) Classical.excluded-middle ([≼]-to-[≽]-for-inhabited-to-excluded-middle p {P = P}) = proof where open import Data.Boolean open import Data.Option open import Data.Option.Setoid open import Relator.Equals.Proofs.Equivalence f : Option(◊ P) → Bool f (Option.Some _) = 𝑇 f Option.None = 𝐹 instance equiv-bool : Equiv(Bool) equiv-bool = [≡]-equiv instance equiv-pos-P : Equiv{Lvl.𝟎}(◊ P) equiv-pos-P = global-equiv func-f : Function(f) Function.congruence func-f {None} {None} _ = reflexivity(_≡_ ⦃ [≡]-equiv ⦄) Function.congruence func-f {Some _} {Some _} _ = reflexivity(_≡_ ⦃ [≡]-equiv ⦄) inj-f : Injective(f) Injective.proof inj-f {None} {None} _ = <> Injective.proof inj-f {Some _} {Some _} _ = <> surjection : ([∃]-intro Bool ⦃ [≡]-equiv ⦄) ≽ ([∃]-intro (Option(◊ P))) surjection = p ⦃ intro ⦃ None ⦄ ⦄ ([∃]-intro f ⦃ [∧]-intro func-f inj-f ⦄) g : Bool → Option(◊ P) g = [∃]-witness surjection g-value-elim : ∀{y} → (g(𝑇) ≡ y) → (g(𝐹) ≡ y) → (∀{b} → (g(b) ≡ y)) g-value-elim l r {𝑇} = l g-value-elim l r {𝐹} = r open Equiv(Option-equiv ⦃ equiv-pos-P ⦄) using () renaming (transitivity to Option-trans ; symmetry to Option-sym) proof : (P ∨ ¬ P) proof with g(𝐹) | g(𝑇) | (\p → Surjective.proof ([∧]-elimᵣ([∃]-proof surjection)) {Some(intro ⦃ p ⦄)}) | g-value-elim{Option.None} ... | Some l | Some r | _ | _ = [∨]-introₗ (◊.existence l) ... | Some l | None | _ | _ = [∨]-introₗ (◊.existence l) ... | None | Some r | _ | _ = [∨]-introₗ (◊.existence r) ... | None | None | surj | tttest = [∨]-introᵣ (\p → empty(transitivity _ ⦃ Option-trans ⦄ {Some(intro ⦃ p ⦄)}{g([∃]-witness(surj p))}{None} (symmetry _ ⦃ Option-sym ⦄ {g([∃]-witness(surj p))}{Some(intro ⦃ p ⦄)} ([∃]-proof(surj p))) (tttest <> <>)) ) {- Some(intro ⦃ p ⦄) 🝖[ Equiv._≡_ Option-equiv ]-[ [∃]-proof(surj p) ]-sym g([∃]-witness(surj p)) 🝖[ Equiv._≡_ Option-equiv ]-[ tttest <> <> ] None 🝖[ Equiv._≡_ Option-equiv ]-end -} {-module _ ⦃ surjChoice : ∀{A B : Setoid{ℓ}} → SurjectionInjectionChoice A B ⦄ where surjection-injection-choice-to-excluded-middle : ∀{P : Type{ℓ}} → Classical(P) Classical.excluded-middle (surjection-injection-choice-to-excluded-middle {P = P}) = {!!} -}
58.439331
426
0.547004
34d6dceddd0dea9f02a666554cae62944771323c
3,918
agda
Agda
code/SemiNearRingRecords.agda
DSLsofMath/ValiantAgda
43729ff822a0b05c6cb74016b04bdc93c627b0b1
[ "BSD-3-Clause" ]
3
2016-10-23T00:41:14.000Z
2022-03-15T03:04:31.000Z
code/SemiNearRingRecords.agda
DSLsofMath/ValiantAgda
43729ff822a0b05c6cb74016b04bdc93c627b0b1
[ "BSD-3-Clause" ]
null
null
null
code/SemiNearRingRecords.agda
DSLsofMath/ValiantAgda
43729ff822a0b05c6cb74016b04bdc93c627b0b1
[ "BSD-3-Clause" ]
1
2020-04-29T04:53:48.000Z
2020-04-29T04:53:48.000Z
import Algebra.FunctionProperties using (LeftZero; RightZero; _DistributesOverˡ_;_DistributesOverʳ_; Idempotent) import Function using (_on_) import Level import Relation.Binary.EqReasoning as EqReasoning import Relation.Binary.On using (isEquivalence) import Algebra.Structures using (module IsCommutativeMonoid; IsCommutativeMonoid) open import Relation.Binary using (module IsEquivalence; IsEquivalence; _Preserves₂_⟶_⟶_ ; Setoid) open import Data.Product renaming (_,_ to _,,_) -- just to avoid clash with other commas open import Preliminaries using (Rel; UniqueSolution; LowerBound) module SemiNearRingRecords where record SemiNearRing : Set₁ where -- \structure{1}{|SemiNearRing|} field -- \structure{1.1}{Carriers, operators} s : Set _≃s_ : s → s → Set zers : s _+s_ : s → s → s _*s_ : s → s → s open Algebra.Structures using (IsCommutativeMonoid) open Algebra.FunctionProperties _≃s_ using (LeftZero; RightZero) field -- \structure{1.2}{Commutative monoid |(+,0)|} isCommMon : IsCommutativeMonoid _≃s_ _+s_ zers zeroˡ : LeftZero zers _*s_ -- expands to |∀ x → (zers *s x) ≃s zers| zeroʳ : RightZero zers _*s_ -- expands to |∀ x → (x *s zers) ≃s zers| _<*>_ : ∀ {x y u v} → (x ≃s y) → (u ≃s v) → (x *s u ≃s y *s v) open Algebra.FunctionProperties _≃s_ using (Idempotent; _DistributesOverˡ_; _DistributesOverʳ_) field -- \structure{1.3}{Distributive, idempotent, \ldots} idem : Idempotent _+s_ distl : _*s_ DistributesOverˡ _+s_ distr : _*s_ DistributesOverʳ _+s_ -- expands to |∀ a b c → (a +s b) *s c ≃s (a *s c) +s (b *s c)| infix 4 _≤s_ _≤s_ : s -> s -> Set x ≤s y = x +s y ≃s y infix 4 _≃s_; infixl 6 _+s_; infixl 7 _*s_ -- \structure{1.4}{Exporting commutative monoid operations} open Algebra.Structures.IsCommutativeMonoid isCommMon public hiding (refl) renaming ( isEquivalence to isEquivs ; assoc to assocs ; comm to comms ; ∙-cong to _<+>_ ; identityˡ to identityˡs ) identityʳs = proj₂ identity sSetoid : Setoid Level.zero Level.zero -- \structure{1.5}{Setoid, \ldots} sSetoid = record { Carrier = s; _≈_ = _≃s_; isEquivalence = isEquivs } open IsEquivalence isEquivs public hiding (reflexive) renaming (refl to refls ; sym to syms ; trans to transs) LowerBounds = LowerBound _≤s_ -- \structure{1.6}{Lower bounds} record SemiNearRing2 : Set₁ where -- \structure{2}{|SemiNearRing2|} field snr : SemiNearRing open SemiNearRing snr public -- public = export the "local" names from |SemiNearRing| field -- \structure{2.1}{Plus and times for |u|, \ldots} u : Set _+u_ : u → u → u _*u_ : u → u → u u2s : u → s _≃u_ : u → u → Set _≃u_ = _≃s_ Function.on u2s _u*s_ : u → s → s _u*s_ u s = u2s u *s s _s*u_ : s → u → s _s*u_ s u = s *s u2s u infix 4 _≃u_; infixl 6 _+u_; infixl 7 _*u_ _u*s_ _s*u_ uSetoid : Setoid Level.zero Level.zero uSetoid = record { isEquivalence = Relation.Binary.On.isEquivalence u2s isEquivs } _≤u_ : u → u → Set _≤u_ = _≤s_ Function.on u2s L : u → s → u → s → Set -- \structure{2.2}{Linear equation |L|} L a y b x = y +s (a u*s x +s x s*u b) ≃s x -- \structure{2.3}{Properties of |L|} UniqueL = ∀ {a y b} → UniqueSolution _≃s_ (L a y b) CongL = ∀ {a x b} -> ∀ {y y'} -> y ≃s y' -> L a y b x -> L a y' b x
38.038835
112
0.557427
34a822317240261b1dfed11552c813c3d214b5b4
395
agda
Agda
test/Succeed/EpicVaryingArity.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/Succeed/EpicVaryingArity.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/EpicVaryingArity.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- Andreas, 2014-05-03 Test case by Andrea Vezzosi data Two : Set where a b : Two -- This example of varying arity crashed Epic before. f : Two → {eq : Two} → Two f a {x} = a f b = b postulate IO : Set → Set {-# COMPILED_TYPE IO IO #-} postulate return : ∀ {A} → A → IO A {-# COMPILED_EPIC return (u1 : Unit, a : Any) -> Any = ioreturn(a) #-} main : IO Two main = return a
17.173913
70
0.592405
341883eab1e5ba2cbd2e6f571944881c1d0d52e9
1,851
agda
Agda
prototyping/Luau/TypeNormalization.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
1
2021-12-05T21:53:03.000Z
2021-12-05T21:53:03.000Z
prototyping/Luau/TypeNormalization.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
prototyping/Luau/TypeNormalization.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
module Luau.TypeNormalization where open import Luau.Type using (Type; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_) -- The top non-function type ¬function : Type ¬function = number ∪ (string ∪ (nil ∪ boolean)) -- Unions and intersections of normalized types _∪ᶠ_ : Type → Type → Type _∪ⁿˢ_ : Type → Type → Type _∩ⁿˢ_ : Type → Type → Type _∪ⁿ_ : Type → Type → Type _∩ⁿ_ : Type → Type → Type -- Union of function types (F₁ ∩ F₂) ∪ᶠ G = (F₁ ∪ᶠ G) ∩ (F₂ ∪ᶠ G) F ∪ᶠ (G₁ ∩ G₂) = (F ∪ᶠ G₁) ∩ (F ∪ᶠ G₂) (R ⇒ S) ∪ᶠ (T ⇒ U) = (R ∩ⁿ T) ⇒ (S ∪ⁿ U) F ∪ᶠ G = F ∪ G -- Union of normalized types S ∪ⁿ (T₁ ∪ T₂) = (S ∪ⁿ T₁) ∪ T₂ S ∪ⁿ unknown = unknown S ∪ⁿ never = S unknown ∪ⁿ T = unknown never ∪ⁿ T = T (S₁ ∪ S₂) ∪ⁿ G = (S₁ ∪ⁿ G) ∪ S₂ F ∪ⁿ G = F ∪ᶠ G -- Intersection of normalized types S ∩ⁿ (T₁ ∪ T₂) = (S ∩ⁿ T₁) ∪ⁿˢ (S ∩ⁿˢ T₂) S ∩ⁿ unknown = S S ∩ⁿ never = never (S₁ ∪ S₂) ∩ⁿ G = (S₁ ∩ⁿ G) unknown ∩ⁿ G = G never ∩ⁿ G = never F ∩ⁿ G = F ∩ G -- Intersection of normalized types with a scalar (S₁ ∪ nil) ∩ⁿˢ nil = nil (S₁ ∪ boolean) ∩ⁿˢ boolean = boolean (S₁ ∪ number) ∩ⁿˢ number = number (S₁ ∪ string) ∩ⁿˢ string = string (S₁ ∪ S₂) ∩ⁿˢ T = S₁ ∩ⁿˢ T unknown ∩ⁿˢ T = T F ∩ⁿˢ T = never -- Union of normalized types with an optional scalar S ∪ⁿˢ never = S unknown ∪ⁿˢ T = unknown (S₁ ∪ nil) ∪ⁿˢ nil = S₁ ∪ nil (S₁ ∪ boolean) ∪ⁿˢ boolean = S₁ ∪ boolean (S₁ ∪ number) ∪ⁿˢ number = S₁ ∪ number (S₁ ∪ string) ∪ⁿˢ string = S₁ ∪ string (S₁ ∪ S₂) ∪ⁿˢ T = (S₁ ∪ⁿˢ T) ∪ S₂ F ∪ⁿˢ T = F ∪ T -- Normalize! normalize : Type → Type normalize nil = never ∪ nil normalize (S ⇒ T) = (normalize S ⇒ normalize T) normalize never = never normalize unknown = unknown normalize boolean = never ∪ boolean normalize number = never ∪ number normalize string = never ∪ string normalize (S ∪ T) = normalize S ∪ⁿ normalize T normalize (S ∩ T) = normalize S ∩ⁿ normalize T
26.442857
95
0.616964
344573780d17e208daa3ba0d85c51ba86959b93d
695
agda
Agda
test/fail/Test3.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
test/fail/Test3.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
test/fail/Test3.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import lib.Base module fail.Test3 where module _ where private data #I : Type₀ where #zero : #I #one : #I I : Type₀ I = #I zero : I zero = #zero one : I one = #one postulate seg : zero == one I-elim : ∀ {i} {P : I → Type i} (zero* : P zero) (one* : P one) (seg* : zero* == one* [ P ↓ seg ]) → Π I P I-elim {i} {P} zero* one* seg* = I-elim-aux phantom where I-elim-aux : Phantom seg* → Π I P I-elim-aux phantom #zero = zero* I-elim-aux phantom #one = one* postulate P : I → Type₀ z : P zero o : P one s s' : z == o [ P ↓ seg ] absurd : I-elim z o s == I-elim z o s' absurd = idp
16.547619
65
0.516547
2ec273a3ef0ab62d753e379b496e461b81331e3f
508
agda
Agda
test/Fail/Issue183.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue183.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue183.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue183 where postulate A : Set T : Set T = A → A data L (A : Set) : Set where data E (x : T) : T → Set where e : E x x foo : (f : A → A) → L (E f (λ x → f x)) foo = λ _ → e -- Previously: -- An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/Syntax/Translation/AbstractToConcrete.hs:705 -- Should now give a proper error message. -- E (_8 .f) (_8 .f) !=< L (E .f .f) of type Set -- when checking that the expression e has type L (E .f .f)
21.166667
84
0.620079
13344eb6dc059353d990d4b98628b9b81e013083
1,329
agda
Agda
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/BoundedMeetSemilattice.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/BoundedMeetSemilattice.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/BoundedMeetSemilattice.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by bounded meet semilattices ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary.Lattice module Relation.Binary.Properties.BoundedMeetSemilattice {c ℓ₁ ℓ₂} (M : BoundedMeetSemilattice c ℓ₁ ℓ₂) where open BoundedMeetSemilattice M import Algebra.FunctionProperties as P; open P _≈_ open import Data.Product open import Function using (_∘_; flip) open import Relation.Binary open import Relation.Binary.Properties.Poset poset import Relation.Binary.Properties.BoundedJoinSemilattice as J -- The dual construction is a bounded join semilattice. dualIsBoundedJoinSemilattice : IsBoundedJoinSemilattice _≈_ (flip _≤_) _∧_ ⊤ dualIsBoundedJoinSemilattice = record { isJoinSemilattice = record { isPartialOrder = invIsPartialOrder ; supremum = infimum } ; minimum = maximum } dualBoundedJoinSemilattice : BoundedJoinSemilattice c ℓ₁ ℓ₂ dualBoundedJoinSemilattice = record { ⊥ = ⊤ ; isBoundedJoinSemilattice = dualIsBoundedJoinSemilattice } open J dualBoundedJoinSemilattice hiding (dualIsBoundedMeetSemilattice; dualBoundedMeetSemilattice) public
31.642857
76
0.680211
8b15788575a650095395d8ba9b3b80784ab1f93e
274
agda
Agda
test/succeed/Issue414.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/succeed/Issue414.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/Issue414.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- {-# OPTIONS -v tc.rec:100 -v tc.signature:20 #-} module Issue414 where record P : Set₁ where field q : Set x : P x = record { q = q } -- Andreas 2011-05-19 -- record constructor should have been added to the signature -- before record module is constructed!
21.076923
61
0.660584
30d29ba11968a367097c2a6fcddb97bce03eb05b
1,159
agda
Agda
Cubical/Data/Prod/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Data/Prod/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Data/Prod/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "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 -- 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 the -- default 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 -- We still export the version using Σ _×Σ_ : (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ') A ×Σ B = Σ A (λ _ → B) infixr 5 _×Σ_ 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₂)
24.145833
72
0.584987
1e0c3ed8c7554ad26a24dc708ee2679ef4785c0b
2,846
agda
Agda
test/Succeed/Issue2618.agda
AntoineAllioux/agda
68ec2312961776e415c99d2839e41a92ffe464db
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue2618.agda
AntoineAllioux/agda
68ec2312961776e415c99d2839e41a92ffe464db
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue2618.agda
AntoineAllioux/agda
68ec2312961776e415c99d2839e41a92ffe464db
[ "BSD-3-Clause" ]
null
null
null
open import Agda.Builtin.List open import Agda.Builtin.Reflection renaming (bindTC to _>>=_) open import Agda.Builtin.Bool open import Agda.Builtin.Equality open import Agda.Builtin.Nat open import Agda.Builtin.Sigma data Unit : Set where unit : Unit data Empty : Set where qq : ∀ {a} {A : Set a} → A → Term → TC _ qq t hole = withNormalisation true do `t ← quoteTC t ``t ← quoteTC `t unify hole ``t macro qU = qq {A = Unit → Set → Set} qE = qq {A = Empty → Set → Set} qA = qq {A = Set → Set} case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B case x of f = f x pattern vArg x = arg (arg-info visible relevant) x pattern [_] x = x ∷ [] map : {A B : Set} → (A → B) → List A → List B map f [] = [] map f (x ∷ xs) = f x ∷ map f xs mkArgs : List Nat → List (Arg Term) mkArgs = map λ i → vArg (var i []) unit,X=>_∙_ : Nat → List Nat → Term unit,X=> n ∙ args = pat-lam [ clause [ "X" , vArg (agda-sort (lit 0)) ] (vArg (con (quote unit) []) ∷ vArg (var 0) ∷ []) (var n []) ] (mkArgs args) abs,X=>∙_ : List Nat → Term abs,X=>∙ is = pat-lam [ absurd-clause ( ("()" , vArg (def (quote Empty) [])) ∷ ("X" , vArg (agda-sort (lit 0))) ∷ []) (vArg (absurd 1) ∷ vArg (var 0) ∷ []) ] (mkArgs is) abs=>∙_ : List Nat → Term abs=>∙ is = pat-lam [ absurd-clause [ "()" , vArg (def (quote Empty) []) ] (vArg (absurd 0) ∷ []) ] (mkArgs is) _ : qU (λ { unit X → X }) ≡ unit,X=> 0 ∙ [] _ = refl _ : (B : Set) → qU (λ { unit X → B }) ≡ unit,X=> 1 ∙ [] _ = λ _ → refl _ : qE (λ { () X }) ≡ abs,X=>∙ [] _ = refl _ : (B : Set) → qE (λ { () X }) ≡ abs,X=>∙ [] _ = λ _ → refl _ : (u : Unit) → qA (case u of λ { unit X → X }) ≡ (unit,X=> 0 ∙ [ 0 ]) _ = λ _ → refl _ : (B : Set) (u : Unit) → qA (case u of λ { unit X → B }) ≡ unit,X=> 2 ∙ [ 0 ] _ = λ _ _ → refl _ : (B : Set) (e : Empty) → qA (case e of λ { () X }) ≡ abs,X=>∙ [ 0 ] _ = λ _ _ → refl _ : qE (λ ()) ≡ abs=>∙ [] _ = refl _ : (B : Set) → qE (λ ()) ≡ abs=>∙ [] _ = λ _ → refl _ : (B : Set) (e : Empty) → qA (case e of λ ()) ≡ abs=>∙ [ 0 ] _ = λ _ _ → refl module _ (A : Set) where _ : qU (λ { unit X → X }) ≡ unit,X=> 0 ∙ [] _ = refl _ : (B : Set) → qU (λ { unit X → B }) ≡ unit,X=> 1 ∙ [] _ = λ _ → refl _ : qE (λ { () X }) ≡ abs,X=>∙ [] _ = refl _ : (u : Unit) → qA (case u of λ { unit X → X }) ≡ (unit,X=> 0 ∙ [ 0 ]) _ = λ _ → refl _ : (B : Set) (u : Unit) → qA (case u of λ { unit X → B }) ≡ unit,X=> 2 ∙ [ 0 ] _ = λ _ _ → refl _ : (B : Set) (e : Empty) → qA (case e of λ { () X }) ≡ abs,X=>∙ [ 0 ] _ = λ _ _ → refl _ : qE (λ ()) ≡ abs=>∙ [] _ = refl _ : (B : Set) → qE (λ ()) ≡ abs=>∙ [] _ = λ _ → refl _ : (B : Set) (e : Empty) → qA (case e of λ ()) ≡ abs=>∙ [ 0 ] _ = λ _ _ → refl
25.185841
118
0.452214
cb232f2584a137eda2f82e1ec19cc4a033e6e988
22,640
agda
Agda
benchmark/std-lib/Any.agda
KDr2/agda
98c9382a59f707c2c97d75919e389fc2a783ac75
[ "BSD-2-Clause" ]
null
null
null
benchmark/std-lib/Any.agda
KDr2/agda
98c9382a59f707c2c97d75919e389fc2a783ac75
[ "BSD-2-Clause" ]
null
null
null
benchmark/std-lib/Any.agda
KDr2/agda
98c9382a59f707c2c97d75919e389fc2a783ac75
[ "BSD-2-Clause" ]
null
null
null
------------------------------------------------------------------------ -- Properties related to Any ------------------------------------------------------------------------ -- The other modules under Data.List.Any also contain properties -- related to Any. module Any where open import Algebra import Algebra.Definitions as FP open import Effect.Monad open import Data.Bool open import Data.Bool.Properties open import Data.Empty open import Data.List as List open import Data.List.Relation.Unary.Any as Any using (Any; here; there) import Data.List.Effectful open import Data.Product as Prod hiding (swap) open import Data.Product.Function.NonDependent.Propositional using (_×-cong_) open import Data.Product.Relation.Binary.Pointwise.NonDependent import Data.Product.Function.Dependent.Propositional as Σ open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_]′) open import Data.Sum.Relation.Binary.Pointwise open import Data.Sum.Function.Propositional using (_⊎-cong_) open import Function using (_$_; _$′_; _∘_; id; flip; const) open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence as Eq using (_⇔_; module Equivalence) open import Function.Inverse as Inv using (_↔_; module Inverse) open import Function.Related as Related using (Related; SK-sym) open import Function.Related.TypeIsomorphisms open import Level open import Relation.Binary hiding (_⇔_) import Relation.Binary.HeterogeneousEquality as H open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; inspect) renaming ([_] to P[_]) open import Relation.Unary using (_⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_) open import Data.List.Membership.Propositional open import Data.List.Relation.Binary.BagAndSetEquality open Related.EquationalReasoning private module ×⊎ {k ℓ} = CommutativeSemiring (×-⊎-commutativeSemiring k ℓ) open module ListMonad {ℓ} = RawMonad (Data.List.Effectful.monad {ℓ = ℓ}) ------------------------------------------------------------------------ -- Some lemmas related to map, find and lose -- Any.map is functorial. map-id : ∀ {a p} {A : Set a} {P : A → Set p} (f : P ⋐ P) {xs} → (∀ {x} (p : P x) → f p ≡ p) → (p : Any P xs) → Any.map f p ≡ p map-id f hyp (here p) = P.cong here (hyp p) map-id f hyp (there p) = P.cong there $ map-id f hyp p map-∘ : ∀ {a p q r} {A : Set a} {P : A → Set p} {Q : A → Set q} {R : A → Set r} (f : Q ⋐ R) (g : P ⋐ Q) {xs} (p : Any P xs) → Any.map (f ∘ g) p ≡ Any.map f (Any.map g p) map-∘ f g (here p) = refl map-∘ f g (there p) = P.cong there $ map-∘ f g p -- Lemmas relating map and find. map∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs} (p : Any P xs) → let p′ = find p in {f : _≡_ (proj₁ p′) ⋐ P} → f refl ≡ proj₂ (proj₂ p′) → Any.map f (proj₁ (proj₂ p′)) ≡ p map∘find (here p) hyp = P.cong here hyp map∘find (there p) hyp = P.cong there (map∘find p hyp) find∘map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {xs : List A} (p : Any P xs) (f : P ⋐ Q) → find (Any.map f p) ≡ Prod.map id (Prod.map id f) (find p) find∘map (here p) f = refl find∘map (there p) f rewrite find∘map p f = refl -- find satisfies a simple equality when the predicate is a -- propositional equality. find-∈ : ∀ {a} {A : Set a} {x : A} {xs : List A} (x∈xs : x ∈ xs) → find x∈xs ≡ (x , x∈xs , refl) find-∈ (here refl) = refl find-∈ (there x∈xs) rewrite find-∈ x∈xs = refl private -- find and lose are inverses (more or less). lose∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A} (p : Any P xs) → uncurry′ lose (proj₂ (find p)) ≡ p lose∘find p = map∘find p P.refl find∘lose : ∀ {a p} {A : Set a} (P : A → Set p) {x xs} (x∈xs : x ∈ xs) (pp : P x) → find {P = P} (lose x∈xs pp) ≡ (x , x∈xs , pp) find∘lose P x∈xs p rewrite find∘map x∈xs (flip (P.subst P) p) | find-∈ x∈xs = refl -- Any can be expressed using _∈_. Any↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} → (∃ λ x → x ∈ xs × P x) ↔ Any P xs Any↔ {P = P} {xs} = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ (find {P = P}) ; inverse-of = record { left-inverse-of = λ p → find∘lose P (proj₁ (proj₂ p)) (proj₂ (proj₂ p)) ; right-inverse-of = lose∘find } } where to : (∃ λ x → x ∈ xs × P x) → Any P xs to = uncurry′ lose ∘ proj₂ ------------------------------------------------------------------------ -- Any is a congruence Any-cong : ∀ {k ℓ} {A : Set ℓ} {P₁ P₂ : A → Set ℓ} {xs₁ xs₂ : List A} → (∀ x → Related k (P₁ x) (P₂ x)) → xs₁ ∼[ k ] xs₂ → Related k (Any P₁ xs₁) (Any P₂ xs₂) Any-cong {P₁ = P₁} {P₂} {xs₁} {xs₂} P₁↔P₂ xs₁≈xs₂ = Any P₁ xs₁ ↔⟨ SK-sym $ Any↔ {P = P₁} ⟩ (∃ λ x → x ∈ xs₁ × P₁ x) ∼⟨ Σ.cong Inv.id (xs₁≈xs₂ ×-cong P₁↔P₂ _) ⟩ (∃ λ x → x ∈ xs₂ × P₂ x) ↔⟨ Any↔ {P = P₂} ⟩ Any P₂ xs₂ ∎ ------------------------------------------------------------------------ -- Swapping -- Nested occurrences of Any can sometimes be swapped. See also ×↔. swap : ∀ {ℓ} {A B : Set ℓ} {P : A → B → Set ℓ} {xs ys} → Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys swap {ℓ} {P = P} {xs} {ys} = Any (λ x → Any (P x) ys) xs ↔⟨ SK-sym Any↔ ⟩ (∃ λ x → x ∈ xs × Any (P x) ys) ↔⟨ SK-sym $ Σ.cong Inv.id (Σ.cong Inv.id Any↔) ⟩ (∃ λ x → x ∈ xs × ∃ λ y → y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (∃∃↔∃∃ _) ⟩ (∃₂ λ x y → x ∈ xs × y ∈ ys × P x y) ↔⟨ ∃∃↔∃∃ _ ⟩ (∃₂ λ y x → x ∈ xs × y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (Σ.cong Inv.id (∃∃↔∃∃ _)) ⟩ (∃₂ λ y x → y ∈ ys × x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (∃∃↔∃∃ _) ⟩ (∃ λ y → y ∈ ys × ∃ λ x → x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (Σ.cong Inv.id Any↔) ⟩ (∃ λ y → y ∈ ys × Any (flip P y) xs) ↔⟨ Any↔ ⟩ Any (λ y → Any (flip P y) xs) ys ∎ ------------------------------------------------------------------------ -- Lemmas relating Any to ⊥ ⊥↔Any⊥ : ∀ {a} {A : Set a} {xs : List A} → ⊥ ↔ Any (const ⊥) xs ⊥↔Any⊥ {A = A} = record { to = P.→-to-⟶ (λ ()) ; from = P.→-to-⟶ (λ p → from p) ; inverse-of = record { left-inverse-of = λ () ; right-inverse-of = λ p → from p } } where from : {xs : List A} → Any (const ⊥) xs → ∀ {b} {B : Set b} → B from (here ()) from (there p) = from p ⊥↔Any[] : ∀ {a} {A : Set a} {P : A → Set} → ⊥ ↔ Any P [] ⊥↔Any[] = record { to = P.→-to-⟶ (λ ()) ; from = P.→-to-⟶ (λ ()) ; inverse-of = record { left-inverse-of = λ () ; right-inverse-of = λ () } } ------------------------------------------------------------------------ -- Lemmas relating Any to sums and products -- Sums commute with Any (for a fixed list). ⊎↔ : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {xs} → (Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs ⊎↔ {P = P} {Q} = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ from ; inverse-of = record { left-inverse-of = from∘to ; right-inverse-of = to∘from } } where to : ∀ {xs} → Any P xs ⊎ Any Q xs → Any (λ x → P x ⊎ Q x) xs to = [ Any.map inj₁ , Any.map inj₂ ]′ from : ∀ {xs} → Any (λ x → P x ⊎ Q x) xs → Any P xs ⊎ Any Q xs from (here (inj₁ p)) = inj₁ (here p) from (here (inj₂ q)) = inj₂ (here q) from (there p) = Sum.map there there (from p) from∘to : ∀ {xs} (p : Any P xs ⊎ Any Q xs) → from (to p) ≡ p from∘to (inj₁ (here p)) = P.refl from∘to (inj₁ (there p)) rewrite from∘to (inj₁ p) = P.refl from∘to (inj₂ (here q)) = P.refl from∘to (inj₂ (there q)) rewrite from∘to (inj₂ q) = P.refl to∘from : ∀ {xs} (p : Any (λ x → P x ⊎ Q x) xs) → to (from p) ≡ p to∘from (here (inj₁ p)) = P.refl to∘from (here (inj₂ q)) = P.refl to∘from (there p) with from p | to∘from p to∘from (there .(Any.map inj₁ p)) | inj₁ p | P.refl = P.refl to∘from (there .(Any.map inj₂ q)) | inj₂ q | P.refl = P.refl -- Products "commute" with Any. ×↔ : {A B : Set} {P : A → Set} {Q : B → Set} {xs : List A} {ys : List B} → (Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs ×↔ {P = P} {Q} {xs} {ys} = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ from ; inverse-of = record { left-inverse-of = from∘to ; right-inverse-of = to∘from } } where to : Any P xs × Any Q ys → Any (λ x → Any (λ y → P x × Q y) ys) xs to (p , q) = Any.map (λ p → Any.map (λ q → (p , q)) q) p from : Any (λ x → Any (λ y → P x × Q y) ys) xs → Any P xs × Any Q ys from pq with Prod.map id (Prod.map id find) (find pq) ... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q) from∘to : ∀ pq → from (to pq) ≡ pq from∘to (p , q) rewrite find∘map {Q = λ x → Any (λ y → P x × Q y) ys} p (λ p → Any.map (λ q → (p , q)) q) | find∘map {Q = λ y → P (proj₁ (find p)) × Q y} q (λ q → proj₂ (proj₂ (find p)) , q) | lose∘find p | lose∘find q = refl to∘from : ∀ pq → to (from pq) ≡ pq to∘from pq with find pq | (λ (f : _≡_ (proj₁ (find pq)) ⋐ _) → map∘find pq {f}) ... | (x , x∈xs , pq′) | lem₁ with find pq′ | (λ (f : _≡_ (proj₁ (find pq′)) ⋐ _) → map∘find pq′ {f}) ... | (y , y∈ys , p , q) | lem₂ rewrite P.sym $ map-∘ {R = λ x → Any (λ y → P x × Q y) ys} (λ p → Any.map (λ q → p , q) (lose y∈ys q)) (λ y → P.subst P y p) x∈xs = lem₁ _ helper where helper : Any.map (λ q → p , q) (lose y∈ys q) ≡ pq′ helper rewrite P.sym $ map-∘ {R = λ y → P x × Q y} (λ q → p , q) (λ y → P.subst Q y q) y∈ys = lem₂ _ refl ------------------------------------------------------------------------ -- Invertible introduction (⁺) and elimination (⁻) rules for various -- list functions -- map. private map⁺ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → Any (P ∘ f) xs → Any P (List.map f xs) map⁺ (here p) = here p map⁺ (there p) = there $ map⁺ p map⁻ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → Any P (List.map f xs) → Any (P ∘ f) xs map⁻ {xs = []} () map⁻ {xs = x ∷ xs} (here p) = here p map⁻ {xs = x ∷ xs} (there p) = there $ map⁻ p map⁺∘map⁻ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → (p : Any P (List.map f xs)) → map⁺ (map⁻ p) ≡ p map⁺∘map⁻ {xs = []} () map⁺∘map⁻ {xs = x ∷ xs} (here p) = refl map⁺∘map⁻ {xs = x ∷ xs} (there p) = P.cong there (map⁺∘map⁻ p) map⁻∘map⁺ : ∀ {a b p} {A : Set a} {B : Set b} (P : B → Set p) {f : A → B} {xs} → (p : Any (P ∘ f) xs) → map⁻ {P = P} (map⁺ p) ≡ p map⁻∘map⁺ P (here p) = refl map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p) map↔ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → Any (P ∘ f) xs ↔ Any P (List.map f xs) map↔ {P = P} {f = f} = record { to = P.→-to-⟶ $ map⁺ {P = P} {f = f} ; from = P.→-to-⟶ $ map⁻ {P = P} {f = f} ; inverse-of = record { left-inverse-of = map⁻∘map⁺ P ; right-inverse-of = map⁺∘map⁻ } } -- _++_. private ++⁺ˡ : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} → Any P xs → Any P (xs ++ ys) ++⁺ˡ (here p) = here p ++⁺ˡ (there p) = there (++⁺ˡ p) ++⁺ʳ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} → Any P ys → Any P (xs ++ ys) ++⁺ʳ [] p = p ++⁺ʳ (x ∷ xs) p = there (++⁺ʳ xs p) ++⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} → Any P (xs ++ ys) → Any P xs ⊎ Any P ys ++⁻ [] p = inj₂ p ++⁻ (x ∷ xs) (here p) = inj₁ (here p) ++⁻ (x ∷ xs) (there p) = Sum.map there id (++⁻ xs p) ++⁺∘++⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P (xs ++ ys)) → [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs p) ≡ p ++⁺∘++⁻ [] p = refl ++⁺∘++⁻ (x ∷ xs) (here p) = refl ++⁺∘++⁻ (x ∷ xs) (there p) with ++⁻ xs p | ++⁺∘++⁻ xs p ++⁺∘++⁻ (x ∷ xs) (there p) | inj₁ p′ | ih = P.cong there ih ++⁺∘++⁻ (x ∷ xs) (there p) | inj₂ p′ | ih = P.cong there ih ++⁻∘++⁺ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P xs ⊎ Any P ys) → ++⁻ xs ([ ++⁺ˡ , ++⁺ʳ xs ]′ p) ≡ p ++⁻∘++⁺ [] (inj₁ ()) ++⁻∘++⁺ [] (inj₂ p) = refl ++⁻∘++⁺ (x ∷ xs) (inj₁ (here p)) = refl ++⁻∘++⁺ (x ∷ xs) {ys} (inj₁ (there p)) rewrite ++⁻∘++⁺ xs {ys} (inj₁ p) = refl ++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl ++↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} → (Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys) ++↔ {P = P} {xs = xs} = record { to = P.→-to-⟶ [ ++⁺ˡ {P = P}, ++⁺ʳ {P = P} xs ]′ ; from = P.→-to-⟶ $ ++⁻ {P = P} xs ; inverse-of = record { left-inverse-of = ++⁻∘++⁺ xs ; right-inverse-of = ++⁺∘++⁻ xs } } -- return. private return⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {x} → P x → Any P (return x) return⁺ = here return⁻ : ∀ {a p} {A : Set a} {P : A → Set p} {x} → Any P (return x) → P x return⁻ (here p) = p return⁻ (there ()) return⁺∘return⁻ : ∀ {a p} {A : Set a} {P : A → Set p} {x} (p : Any P (return x)) → return⁺ (return⁻ p) ≡ p return⁺∘return⁻ (here p) = refl return⁺∘return⁻ (there ()) return⁻∘return⁺ : ∀ {a p} {A : Set a} (P : A → Set p) {x} (p : P x) → return⁻ {P = P} (return⁺ p) ≡ p return⁻∘return⁺ P p = refl return↔ : ∀ {a p} {A : Set a} {P : A → Set p} {x} → P x ↔ Any P (return x) return↔ {P = P} = record { to = P.→-to-⟶ $ return⁺ {P = P} ; from = P.→-to-⟶ $ return⁻ {P = P} ; inverse-of = record { left-inverse-of = return⁻∘return⁺ P ; right-inverse-of = return⁺∘return⁻ } } -- _∷_. ∷↔ : ∀ {a p} {A : Set a} (P : A → Set p) {x xs} → (P x ⊎ Any P xs) ↔ Any P (x ∷ xs) ∷↔ P {x} {xs} = (P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩ (Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩ Any P (x ∷ xs) ∎ -- concat. private concat⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} → Any (Any P) xss → Any P (concat xss) concat⁺ (here p) = ++⁺ˡ p concat⁺ (there {x = xs} p) = ++⁺ʳ xs (concat⁺ p) concat⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xss → Any P (concat xss) → Any (Any P) xss concat⁻ [] () concat⁻ ([] ∷ xss) p = there $ concat⁻ xss p concat⁻ ((x ∷ xs) ∷ xss) (here p) = here (here p) concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p ... | here p′ = here (there p′) ... | there p′ = there p′ concat⁻∘++⁺ˡ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} xss (p : Any P xs) → concat⁻ (xs ∷ xss) (++⁺ˡ p) ≡ here p concat⁻∘++⁺ˡ xss (here p) = refl concat⁻∘++⁺ˡ xss (there p) rewrite concat⁻∘++⁺ˡ xss p = refl concat⁻∘++⁺ʳ : ∀ {a p} {A : Set a} {P : A → Set p} xs xss (p : Any P (concat xss)) → concat⁻ (xs ∷ xss) (++⁺ʳ xs p) ≡ there (concat⁻ xss p) concat⁻∘++⁺ʳ [] xss p = refl concat⁻∘++⁺ʳ (x ∷ xs) xss p rewrite concat⁻∘++⁺ʳ xs xss p = refl concat⁺∘concat⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xss (p : Any P (concat xss)) → concat⁺ (concat⁻ xss p) ≡ p concat⁺∘concat⁻ [] () concat⁺∘concat⁻ ([] ∷ xss) p = concat⁺∘concat⁻ xss p concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (here p) = refl concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p | concat⁺∘concat⁻ (xs ∷ xss) p concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ˡ p′)) | here p′ | refl = refl concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ʳ xs (concat⁺ p′))) | there p′ | refl = refl concat⁻∘concat⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} (p : Any (Any P) xss) → concat⁻ xss (concat⁺ p) ≡ p concat⁻∘concat⁺ (here p) = concat⁻∘++⁺ˡ _ p concat⁻∘concat⁺ (there {x = xs} {xs = xss} p) rewrite concat⁻∘++⁺ʳ xs xss (concat⁺ p) = P.cong there $ concat⁻∘concat⁺ p concat↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} → Any (Any P) xss ↔ Any P (concat xss) concat↔ {P = P} {xss = xss} = record { to = P.→-to-⟶ $ concat⁺ {P = P} ; from = P.→-to-⟶ $ concat⁻ {P = P} xss ; inverse-of = record { left-inverse-of = concat⁻∘concat⁺ ; right-inverse-of = concat⁺∘concat⁻ xss } } -- _>>=_. >>=↔ : ∀ {ℓ p} {A B : Set ℓ} {P : B → Set p} {xs} {f : A → List B} → Any (Any P ∘ f) xs ↔ Any P (xs >>= f) >>=↔ {P = P} {xs} {f} = Any (Any P ∘ f) xs ↔⟨ map↔ {P = Any P} {f = f} ⟩ Any (Any P) (List.map f xs) ↔⟨ concat↔ {P = P} ⟩ Any P (xs >>= f) ∎ -- _⊛_. ⊛↔ : ∀ {ℓ} {A B : Set ℓ} {P : B → Set ℓ} {fs : List (A → B)} {xs : List A} → Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs) ⊛↔ {ℓ} {P = P} {fs} {xs} = Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → return↔ {a = ℓ} {p = ℓ}) (_ ∎)) (_ ∎) ⟩ Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ {ℓ = ℓ} {p = ℓ}) (_ ∎) ⟩ Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩ Any P (fs ⊛ xs) ∎ -- An alternative introduction rule for _⊛_. ⊛⁺′ : ∀ {ℓ} {A B : Set ℓ} {P : A → Set ℓ} {Q : B → Set ℓ} {fs : List (A → B)} {xs} → Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs) ⊛⁺′ {ℓ} pq p = Inverse.to (⊛↔ {ℓ = ℓ}) ⟨$⟩ Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq -- _⊗_. ⊗↔ : ∀ {ℓ} {A B : Set ℓ} {P : A × B → Set ℓ} {xs : List A} {ys : List B} → Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys) ⊗↔ {ℓ} {P = P} {xs} {ys} = Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ return↔ {a = ℓ} {p = ℓ} ⟩ Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩ Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩ Any P (xs ⊗ ys) ∎ ⊗↔′ : {A B : Set} {P : A → Set} {Q : B → Set} {xs : List A} {ys : List B} → (Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys) ⊗↔′ {P = P} {Q} {xs} {ys} = (Any P xs × Any Q ys) ↔⟨ ×↔ ⟩ Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩ Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎ -- map-with-∈. map-with-∈↔ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {xs : List A} {f : ∀ {x} → x ∈ xs → B} → (∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (mapWith∈ xs f) map-with-∈↔ {A = A} {B} {P} = record { to = P.→-to-⟶ (map-with-∈⁺ _) ; from = P.→-to-⟶ (map-with-∈⁻ _ _) ; inverse-of = record { left-inverse-of = from∘to _ ; right-inverse-of = to∘from _ _ } } where map-with-∈⁺ : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) → (∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) → Any P (mapWith∈ xs f) map-with-∈⁺ f (_ , here refl , p) = here p map-with-∈⁺ f (_ , there x∈xs , p) = there $ map-with-∈⁺ (f ∘ there) (_ , x∈xs , p) map-with-∈⁻ : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) → Any P (mapWith∈ xs f) → ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs) map-with-∈⁻ [] f () map-with-∈⁻ (y ∷ xs) f (here p) = (y , here refl , p) map-with-∈⁻ (y ∷ xs) f (there p) = Prod.map id (Prod.map there id) $ map-with-∈⁻ xs (f ∘ there) p from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) (p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) → map-with-∈⁻ xs f (map-with-∈⁺ f p) ≡ p from∘to f (_ , here refl , p) = refl from∘to f (_ , there x∈xs , p) rewrite from∘to (f ∘ there) (_ , x∈xs , p) = refl to∘from : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) (p : Any P (mapWith∈ xs f)) → map-with-∈⁺ f (map-with-∈⁻ xs f p) ≡ p to∘from [] f () to∘from (y ∷ xs) f (here p) = refl to∘from (y ∷ xs) f (there p) = P.cong there $ to∘from xs (f ∘ there) p ------------------------------------------------------------------------ -- Any and any are related via T -- These introduction and elimination rules are not inverses, though. private any⁺ : ∀ {a} {A : Set a} (p : A → Bool) {xs} → Any (T ∘ p) xs → T (any p xs) any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px any⁺ p (there {x = x} pxs) with p x ... | true = _ ... | false = any⁺ p pxs any⁻ : ∀ {a} {A : Set a} (p : A → Bool) xs → T (any p xs) → Any (T ∘ p) xs any⁻ p [] () any⁻ p (x ∷ xs) px∷xs with p x | inspect p x any⁻ p (x ∷ xs) px∷xs | true | P[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq) any⁻ p (x ∷ xs) px∷xs | false | _ = there (any⁻ p xs px∷xs) any⇔ : ∀ {a} {A : Set a} {p : A → Bool} {xs} → Any (T ∘ p) xs ⇔ T (any p xs) any⇔ = Eq.equivalence (any⁺ _) (any⁻ _ _) ------------------------------------------------------------------------ -- _++_ is commutative private ++-comm : ∀ {a p} {A : Set a} {P : A → Set p} xs ys → Any P (xs ++ ys) → Any P (ys ++ xs) ++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs ++-comm∘++-comm : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P (xs ++ ys)) → ++-comm ys xs (++-comm xs ys p) ≡ p ++-comm∘++-comm [] {ys} p rewrite ++⁻∘++⁺ ys {ys = []} (inj₁ p) = P.refl ++-comm∘++-comm {P = P} (x ∷ xs) {ys} (here p) rewrite ++⁻∘++⁺ {P = P} ys {ys = x ∷ xs} (inj₂ (here p)) = P.refl ++-comm∘++-comm (x ∷ xs) (there p) with ++⁻ xs p | ++-comm∘++-comm xs p ++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ʳ ys p)))) | inj₁ p | P.refl rewrite ++⁻∘++⁺ ys (inj₂ p) | ++⁻∘++⁺ ys (inj₂ $′ there {x = x} p) = refl ++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ˡ p)))) | inj₂ p | P.refl rewrite ++⁻∘++⁺ ys {ys = xs} (inj₁ p) | ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = P.refl ++↔++ : ∀ {a p} {A : Set a} {P : A → Set p} xs ys → Any P (xs ++ ys) ↔ Any P (ys ++ xs) ++↔++ {P = P} xs ys = record { to = P.→-to-⟶ $ ++-comm {P = P} xs ys ; from = P.→-to-⟶ $ ++-comm {P = P} ys xs ; inverse-of = record { left-inverse-of = ++-comm∘++-comm xs ; right-inverse-of = ++-comm∘++-comm ys } }
36.166134
120
0.429284
4373215c7d7e482dce204a26d5b86ec73f0552bd
1,035
agda
Agda
agda/TreeSort/Impl2/Correctness/Permutation.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/TreeSort/Impl2/Correctness/Permutation.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/TreeSort/Impl2/Correctness/Permutation.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
open import Relation.Binary.Core module TreeSort.Impl2.Correctness.Permutation {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import BBSTree _≤_ open import Bound.Total A open import Bound.Total.Order _≤_ open import Data.List open import Data.Sum open import List.Permutation.Base A open import List.Permutation.Base.Concatenation A open import TreeSort.Impl2 _≤_ tot≤ lemma-insert-/ : {a b : Bound}{x : A}(a≤x : LeB a (val x))(x≤b : LeB (val x) b)(t : BBSTree a b) → (flatten (insert a≤x x≤b t)) / x ⟶ (flatten t) lemma-insert-/ a≤x x≤b (bslf _) = /head lemma-insert-/ {x = x} b≤x x≤t (bsnd {x = y} b≤y y≤t l r) with tot≤ x y ... | inj₁ x≤y = lemma++/r (lemma-insert-/ b≤x (lexy x≤y) l) ... | inj₂ y≤x = lemma++/l {xs = flatten l} (/tail (lemma-insert-/ (lexy y≤x) x≤t r)) theorem-treeSort∼ : (xs : List A) → xs ∼ (flatten (treeSort xs)) theorem-treeSort∼ [] = ∼[] theorem-treeSort∼ (x ∷ xs) = ∼x /head (lemma-insert-/ lebx lext (treeSort xs)) (theorem-treeSort∼ xs)
34.5
146
0.618357
43cef061357e8a84fde5deb41f9c263bef3f7bc8
243
agda
Agda
Cubical/Data/Empty/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/Empty/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Data/Empty/Base.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.Data.Empty.Base where open import Cubical.Core.Everything data ⊥ : Type₀ where rec : ∀ {ℓ} {A : Type ℓ} → ⊥ → A rec () elim : ∀ {ℓ} {A : ⊥ → Type ℓ} → (x : ⊥) → A x elim ()
18.692308
50
0.572016
c79a2641e82bcc87f26ecec553b3a629d36939fe
120
agda
Agda
archive/agda-1/IsFormula.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-1/IsFormula.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-1/IsFormula.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module IsFormula where open import Formula data IsFormula : Formula → Set where ⟨_⟩ : (φ : Formula) → IsFormula φ
13.333333
35
0.7
3433fc4ce614fe2f56581b5675a853675222f27a
672
agda
Agda
test/Fail/Issue2348-hidden-instance.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2348-hidden-instance.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2348-hidden-instance.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-12-20, issue #2348, testing nameFirstIfHidden -- {-# OPTIONS -v tc.proj.like:100 #-} {-# OPTIONS --show-implicit #-} -- NEEDED -- something projection-like record Wrap (A : Set) : Set where field out : A proj-like : {A : Set} {{r : Wrap A}} → A proj-like {{r}} = Wrap.out r -- display term with projection-like thing postulate B : Set b : B P : B → Set p : P b instance w : Wrap B ok = P (proj-like {{w}}) -- instance argument does not have to be named test : P (proj-like) test = p -- triggers error message -- Expected error: -- b != Wrap.out w of type B -- when checking that the expression p has type P (proj-like _ {{w}})
20.363636
72
0.622024
35521f16c406a5dfb3fd1ecef6fac9c43b763f99
154
agda
Agda
src/SystemF/Syntax/Context.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/SystemF/Syntax/Context.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/SystemF/Syntax/Context.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
module SystemF.Syntax.Context where open import Prelude open import SystemF.Syntax.Type open import Data.Vec Ctx : ℕ → ℕ → Set Ctx ν n = Vec (Type ν) n
17.111111
35
0.74026
a0a0133f3c0592f27f9fdcf5f900bc0eaef8d339
3,056
agda
Agda
examples/Termination/Sized/DeBruijnExSubstSized.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
examples/Termination/Sized/DeBruijnExSubstSized.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/Termination/Sized/DeBruijnExSubstSized.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --sized-types #-} -- --no-coverage-check #-} module DeBruijnExSubstSized where open import Data.Function -- using (_∘_) -- composition, identity open import Data.Nat open import Data.Maybe open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Size open import DeBruijn -- untyped de Bruijn terms data LamE (A : Set) : Size -> Set where varE : {ι : _} -> A -> LamE A (↑ ι) appE : {ι : _} -> LamE A ι -> LamE A ι -> LamE A (↑ ι) absE : {ι : _} -> LamE (Maybe A) ι -> LamE A (↑ ι) flatE : {ι : _} -> LamE (LamE A ι) ι -> LamE A (↑ ι) -- functoriality of LamE lamE : {A B : Set} -> (A -> B) -> {ι : _} -> LamE A ι -> LamE B ι lamE f (varE a) = varE (f a) lamE f (appE t1 t2) = appE (lamE f t1) (lamE f t2) lamE f (absE r) = absE (lamE (fmap f) r) lamE f (flatE r) = flatE (lamE (lamE f) r) eval : {ι : _} -> {A : Set} -> LamE A ι -> Lam A eval (varE a) = var a eval (appE t1 t2) = app (eval t1) (eval t2) eval (absE r) = abs (eval r) eval (flatE r) = subst (eval) (eval r) -- Theorem (naturality of eval): eval ∘ lamE f ≡ lam f ∘ eval evalNAT : {A B : Set}(f : A -> B) -> {ι : _} -> (t : LamE A ι) -> eval (lamE f t) ≡ lam f (eval t) evalNAT f (varE a) = ≡-refl evalNAT f (appE t1 t2) = begin eval (lamE f (appE t1 t2)) ≡⟨ ≡-refl ⟩ eval (appE (lamE f t1) (lamE f t2)) ≡⟨ ≡-refl ⟩ app (eval (lamE f t1)) (eval (lamE f t2)) ≡⟨ ≡-cong (\ x -> app x (eval (lamE f t2))) (evalNAT f t1) ⟩ app (lam f (eval t1)) (eval (lamE f t2)) ≡⟨ ≡-cong (\ x -> app (lam f (eval t1)) x) (evalNAT f t2) ⟩ app (lam f (eval t1)) (lam f (eval t2)) ≡⟨ ≡-refl ⟩ lam f (app (eval t1) (eval t2)) ≡⟨ ≡-refl ⟩ lam f (eval (appE t1 t2)) ∎ evalNAT f (absE r) = begin eval (lamE f (absE r)) ≡⟨ ≡-refl ⟩ eval (absE (lamE (fmap f) r)) ≡⟨ ≡-refl ⟩ abs (eval (lamE (fmap f) r)) ≡⟨ ≡-cong abs (evalNAT (fmap f) r) ⟩ abs (lam (fmap f) (eval r)) ≡⟨ ≡-refl ⟩ lam f (abs (eval r)) ≡⟨ ≡-refl ⟩ lam f (eval (absE r)) ∎ -- in the following case, one manual size annotation is needed on the RHS -- it is for the first application of the I.H. evalNAT f (flatE {ι} r) = begin eval (lamE f (flatE r)) ≡⟨ ≡-refl ⟩ eval (flatE (lamE (lamE f) r)) ≡⟨ ≡-refl ⟩ subst eval (eval (lamE (lamE f) r)) ≡⟨ ≡-cong (subst (eval {ι})) (evalNAT (lamE f) r) ⟩ subst eval (lam (lamE f) (eval r)) ≡⟨ substLaw1 (lamE f) eval (eval r) ⟩ subst (eval ∘ lamE f) (eval r) ≡⟨ substExt (evalNAT f) (eval r) ⟩ subst (lam f ∘ eval) (eval r) ≡⟨ substLaw2 f eval (eval r) ⟩ lam f (subst eval (eval r)) ≡⟨ ≡-refl ⟩ lam f (eval (flatE r)) ∎ evalNATcor : {A : Set}{ι : _}(ee : LamE (LamE A ι) ι) -> subst id (eval (lamE eval ee)) ≡ eval (flatE ee) evalNATcor ee = begin subst id (eval (lamE eval ee)) ≡⟨ ≡-cong (subst id) (evalNAT eval ee) ⟩ subst id (lam eval (eval ee)) ≡⟨ substLaw1 eval id (eval ee) ⟩ subst eval (eval ee) ≡⟨ ≡-refl ⟩ eval (flatE ee) ∎
30.868687
73
0.53894
5e0a4e41e59fa5d3c777f979ec98aa3c1a310a4f
340
agda
Agda
examples/examplesPaperJFP/finn.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
examples/examplesPaperJFP/finn.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
examples/examplesPaperJFP/finn.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module examplesPaperJFP.finn where open import Data.Nat data Fin : ℕ → Set where zero : {n : ℕ} → Fin (suc n) suc : {n : ℕ} (i : Fin n) → Fin (suc n) mutual data Even : ℕ → Set where 0p : Even 0 sucp : {n : ℕ} → Odd n → Even (suc n) data Odd : ℕ → Set where sucp : {n : ℕ} → Even n → Odd (suc n)
21.25
49
0.517647
359e81115f974091ad432944d4fb56a106d344a1
851
agda
Agda
Cubical/HITs/S1/Properties.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/S1/Properties.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/HITs/S1/Properties.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.S1.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.HITs.S1.Base open import Cubical.HITs.PropositionalTruncation as PropTrunc isConnectedS¹ : (s : S¹) → ∥ base ≡ s ∥ isConnectedS¹ base = ∣ refl ∣ isConnectedS¹ (loop i) = squash ∣ (λ j → loop (i ∧ j)) ∣ ∣ (λ j → loop (i ∨ ~ j)) ∣ i isGroupoidS¹ : isGroupoid S¹ isGroupoidS¹ s t = PropTrunc.rec isPropIsSet (λ p → subst (λ s → isSet (s ≡ t)) p (PropTrunc.rec isPropIsSet (λ q → subst (λ t → isSet (base ≡ t)) q isSetΩS¹) (isConnectedS¹ t))) (isConnectedS¹ s)
29.344828
62
0.698002
2ed544dcf72466a7c443b923bd2456b9cbc20065
265
agda
Agda
test/Fail/Issue1436-2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1436-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1436-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue1436-2 where module A where infixl 19 _↑_ infixl 1 _↓_ data D : Set where ● : D _↓_ _↑_ : D → D → D module B where infix -1000000 _↓_ data D : Set where _↓_ : D → D → D open A open B rejected = ● ↑ ● ↓ ● ↑ ● ↓ ● ↑ ●
11.521739
32
0.509434
8b747ae7c5eaf57bcb5c23a786b9799e1ee925e9
11,220
agda
Agda
Cubical/Foundations/Id.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Foundations/Id.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Foundations/Id.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- This file contains: - Id, refl and J (with definitional computation rule) - Basic theory about Id, proved using J - Lemmas for going back and forth between Path and Id - Function extensionality for Id - fiber, isContr, equiv all defined using Id - The univalence axiom expressed using only Id ([EquivContr]) - Propositional truncation and its elimination principle -} {-# OPTIONS --safe #-} module Cubical.Foundations.Id where open import Cubical.Foundations.Prelude public hiding ( _≡_ ; _≡⟨_⟩_ ; _∎ ; isPropIsContr) renaming ( refl to reflPath ; transport to transportPath ; J to JPath ; JRefl to JPathRefl ; sym to symPath ; _∙_ to compPath ; cong to congPath ; funExt to funExtPath ; isContr to isContrPath ; isProp to isPropPath ; isSet to isSetPath ; fst to pr₁ -- as in the HoTT book ; snd to pr₂ ) open import Cubical.Foundations.Equiv renaming ( fiber to fiberPath ; isEquiv to isEquivPath ; _≃_ to EquivPath ; equivFun to equivFunPath ; isPropIsEquiv to isPropIsEquivPath ) hiding ( equivCtr ; equivIsEquiv ) open import Cubical.Foundations.Univalence renaming ( EquivContr to EquivContrPath ) open import Cubical.Foundations.Isomorphism open import Cubical.HITs.PropositionalTruncation public renaming ( squash to squashPath ; rec to recPropTruncPath ; elim to elimPropTruncPath ) open import Cubical.Core.Id public private variable ℓ ℓ' : Level A : Type ℓ -- Version of the constructor for Id where the y is also -- explicit. This is sometimes useful when it is needed for -- typechecking (see JId below). conId : ∀ {x : A} φ (y : A [ φ ↦ (λ _ → x) ]) (w : (Path _ x (outS y)) [ φ ↦ (λ { (φ = i1) → λ _ → x}) ]) → x ≡ outS y conId φ _ w = ⟨ φ , outS w ⟩ -- Reflexivity refl : ∀ {x : A} → x ≡ x refl {x = x} = ⟨ i1 , (λ _ → x) ⟩ -- Definition of J for Id module _ {x : A} (P : ∀ (y : A) → Id x y → Type ℓ') (d : P x refl) where J : ∀ {y : A} (w : x ≡ y) → P y w J {y = y} = elimId P (λ φ y w → comp (λ i → P _ (conId (φ ∨ ~ i) (inS (outS w i)) (inS (λ j → outS w (i ∧ j))))) (λ i → λ { (φ = i1) → d}) d) {y = y} -- Check that J of refl is the identity function Jdefeq : Path _ (J refl) d Jdefeq _ = d -- Basic theory about Id, proved using J transport : ∀ (B : A → Type ℓ') {x y : A} → x ≡ y → B x → B y transport B {x} p b = J (λ y p → B y) b p _⁻¹ : {x y : A} → x ≡ y → y ≡ x _⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y ap f {x} = J (λ z _ → f x ≡ f z) refl _∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z _∙_ {x = x} p = J (λ y _ → x ≡ y) p infix 4 _∙_ infix 3 _∎ infixr 2 _≡⟨_⟩_ _≡⟨_⟩_ : (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z _ ≡⟨ p ⟩ q = p ∙ q _∎ : (x : A) → x ≡ x _ ∎ = refl -- Convert between Path and Id pathToId : ∀ {x y : A} → Path _ x y → Id x y pathToId {x = x} = JPath (λ y _ → Id x y) refl pathToIdRefl : ∀ {x : A} → Path _ (pathToId (λ _ → x)) refl pathToIdRefl {x = x} = JPathRefl (λ y _ → Id x y) refl idToPath : ∀ {x y : A} → Id x y → Path _ x y idToPath {x = x} = J (λ y _ → Path _ x y) (λ _ → x) idToPathRefl : ∀ {x : A} → Path _ (idToPath {x = x} refl) reflPath idToPathRefl {x = x} _ _ = x pathToIdToPath : ∀ {x y : A} → (p : Path _ x y) → Path _ (idToPath (pathToId p)) p pathToIdToPath {x = x} = JPath (λ y p → Path _ (idToPath (pathToId p)) p) (λ i → idToPath (pathToIdRefl i)) idToPathToId : ∀ {x y : A} → (p : Id x y) → Path _ (pathToId (idToPath p)) p idToPathToId {x = x} = J (λ b p → Path _ (pathToId (idToPath p)) p) pathToIdRefl -- We get function extensionality by going back and forth between Path and Id funExt : ∀ {B : A → Type ℓ'} {f g : (x : A) → B x} → ((x : A) → f x ≡ g x) → f ≡ g funExt p = pathToId (λ i x → idToPath (p x) i) -- Equivalences expressed using Id fiber : ∀ {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ') fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y isContr : Type ℓ → Type ℓ isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y) isProp : Type ℓ → Type ℓ isProp A = (x y : A) → x ≡ y isSet : Type ℓ → Type ℓ isSet A = (x y : A) → isProp (x ≡ y) record isEquiv {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where field equiv-proof : (y : B) → isContr (fiber f y) open isEquiv public infix 4 _≃_ _≃_ : ∀ (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ') A ≃ B = Σ[ f ∈ (A → B) ] (isEquiv f) equivFun : ∀ {B : Type ℓ'} → A ≃ B → A → B equivFun e = pr₁ e equivIsEquiv : ∀ {B : Type ℓ'} (e : A ≃ B) → isEquiv (equivFun e) equivIsEquiv e = pr₂ e equivCtr : ∀ {B : Type ℓ'} (e : A ≃ B) (y : B) → fiber (equivFun e) y equivCtr e y = e .pr₂ .equiv-proof y .pr₁ -- Functions for going between the various definitions. This could -- also be achieved by making lines in the universe and transporting -- back and forth along them. fiberPathToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B} → fiberPath f y → fiber f y fiberPathToFiber (x , p) = (x , pathToId p) fiberToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} → fiber f y → fiberPath f y fiberToFiberPath (x , p) = (x , idToPath p) fiberToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B} (p : fiber f y) → Path _ (fiberPathToFiber (fiberToFiberPath p)) p fiberToFiber (x , p) = λ i → x , idToPathToId p i fiberPathToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} (p : fiberPath f y) → Path _ (fiberToFiberPath (fiberPathToFiber p)) p fiberPathToFiberPath (x , p) = λ i → x , pathToIdToPath p i isContrPathToIsContr : isContrPath A → isContr A isContrPathToIsContr (ctr , p) = (ctr , λ y → pathToId (p y)) isContrToIsContrPath : isContr A → isContrPath A isContrToIsContrPath (ctr , p) = (ctr , λ y → idToPath (p y)) isPropPathToIsProp : isPropPath A → isProp A isPropPathToIsProp H x y = pathToId (H x y) isPropToIsPropPath : isProp A → isPropPath A isPropToIsPropPath H x y i = idToPath (H x y) i -- Specialized helper lemmas for going back and forth between -- isContrPath and isContr: helper1 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A) (h : (y : B) → Path B (f (g y)) y) → isContrPath A → isContr B helper1 f g h (x , p) = (f x , λ y → pathToId (λ i → hcomp (λ j → λ { (i = i0) → f x ; (i = i1) → h y j }) (f (p (g y) i)))) helper2 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A) (h : (y : A) → Path A (g (f y)) y) → isContr B → isContrPath A helper2 {A = A} f g h (x , p) = (g x , λ y → idToPath (rem y)) where rem : ∀ (y : A) → g x ≡ y rem y = g x ≡⟨ ap g (p (f y)) ⟩ g (f y) ≡⟨ pathToId (h y) ⟩ y ∎ -- This proof is essentially the one for proving that isContr with -- Path is a proposition, but as we are working with Id we have to -- insert a lof of conversion functions. It is still nice that is -- works like this though. isPropIsContr : ∀ (p1 p2 : isContr A) → Path (isContr A) p1 p2 isPropIsContr (a0 , p0) (a1 , p1) j = ( idToPath (p0 a1) j , hcomp (λ i → λ { (j = i0) → λ x → idToPathToId (p0 x) i ; (j = i1) → λ x → idToPathToId (p1 x) i }) (λ x → pathToId (λ i → hcomp (λ k → λ { (i = i0) → idToPath (p0 a1) j ; (i = i1) → idToPath (p0 x) (j ∨ k) ; (j = i0) → idToPath (p0 x) (i ∧ k) ; (j = i1) → idToPath (p1 x) i }) (idToPath (p0 (idToPath (p1 x) i)) j)))) -- We now prove that isEquiv is a proposition isPropIsEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → {f : A → B} → (h1 h2 : isEquiv f) → Path _ h1 h2 equiv-proof (isPropIsEquiv {f = f} h1 h2 i) y = isPropIsContr {A = fiber f y} (h1 .equiv-proof y) (h2 .equiv-proof y) i -- Go from a Path equivalence to an Id equivalence equivPathToEquiv : ∀ {A : Type ℓ} {B : Type ℓ'} → EquivPath A B → A ≃ B equivPathToEquiv (f , p) = (f , λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (p .equiv-proof y) }) -- Go from an Id equivalence to a Path equivalence equivToEquivPath : ∀ {A : Type ℓ} {B : Type ℓ'} → A ≃ B → EquivPath A B equivToEquivPath (f , p) = (f , λ { .equiv-proof y → helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y) }) equivToEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → (p : A ≃ B) → Path _ (equivPathToEquiv (equivToEquivPath p)) p equivToEquiv (f , p) i = (f , isPropIsEquiv (λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y)) }) p i) -- We can finally prove univalence with Id everywhere from the one for Path EquivContr : ∀ (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] (T ≃ A)) EquivContr {ℓ = ℓ} A = helper1 f1 f2 f12 (EquivContrPath A) where f1 : {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (EquivPath T A) → Σ[ T ∈ Type ℓ ] (T ≃ A) f1 (x , p) = x , equivPathToEquiv p f2 : {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (T ≃ A) → Σ[ T ∈ Type ℓ ] (EquivPath T A) f2 (x , p) = x , equivToEquivPath p f12 : (y : Σ[ T ∈ Type ℓ ] (T ≃ A)) → Path (Σ[ T ∈ Type ℓ ] (T ≃ A)) (f1 (f2 y)) y f12 (x , p) i = x , equivToEquiv {A = x} {B = A} p i -- Propositional truncation ∥∥-isProp : ∀ (x y : ∥ A ∥) → x ≡ y ∥∥-isProp x y = pathToId (squashPath x y) ∥∥-recursion : ∀ {A : Type ℓ} {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P ∥∥-recursion Pprop f x = recPropTruncPath (isPropToIsPropPath Pprop) f x ∥∥-induction : ∀ {A : Type ℓ} {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) → ((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a ∥∥-induction Pprop f x = elimPropTruncPath (λ a → isPropToIsPropPath (Pprop a)) f x -- Univalence path≡Id : ∀ {ℓ} {A B : Type ℓ} → Path _ (Path _ A B) (Id A B) path≡Id = isoToPath (iso pathToId idToPath idToPathToId pathToIdToPath ) equivPathToEquivPath : ∀ {ℓ} {A : Type ℓ} {B : Type ℓ} → (p : EquivPath A B) → Path _ (equivToEquivPath (equivPathToEquiv p)) p equivPathToEquivPath (f , p) i = ( f , isPropIsEquivPath f (equivToEquivPath (equivPathToEquiv (f , p)) .pr₂) p i ) equivPath≡Equiv : ∀ {ℓ} {A B : Type ℓ} → Path _ (EquivPath A B) (A ≃ B) equivPath≡Equiv {ℓ} = isoToPath (iso (equivPathToEquiv {ℓ}) equivToEquivPath equivToEquiv equivPathToEquivPath) univalenceId : ∀ {ℓ} {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B) univalenceId {ℓ} {A = A} {B = B} = equivPathToEquiv rem where rem0 : Path _ (Lift (EquivPath A B)) (Lift (A ≃ B)) rem0 = congPath Lift equivPath≡Equiv rem1 : Path _ (Id A B) (Lift (A ≃ B)) rem1 i = hcomp (λ j → λ { (i = i0) → path≡Id {A = A} {B = B} j ; (i = i1) → rem0 j }) (univalencePath {A = A} {B = B} i) rem : EquivPath (Id A B) (A ≃ B) rem = compEquiv (eqweqmap rem1) (invEquiv LiftEquiv)
35.846645
136
0.547326
2e7ca09e2f274a69fba757f3e4d6128eeabf1a56
309
agda
Agda
Algebra/Construct/Sign.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Algebra/Construct/Sign.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Algebra/Construct/Sign.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} module Algebra.Construct.Sign where open import Prelude data Signed {a} (A : Type a) : Type a where ⁻_ : A → Signed A ±0 : Signed A ⁺_ : A → Signed A unsign : (A → B) → B → (A → B) → Signed A → B unsign f g h (⁻ x) = f x unsign f g h ±0 = g unsign f g h (⁺ x) = h x
19.3125
45
0.559871
58843bfec3e678e9de59daa38f530e971944a223
29,104
agda
Agda
src/type-inf.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
src/type-inf.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
src/type-inf.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
open import cedille-types import spans open import ctxt import cedille-options open import general-util module type-inf (options : cedille-options.options) {mF : Set → Set} ⦃ _ : monad mF ⦄ (check-term : ctxt → ex-tm → (T? : maybe type) → spans.spanM options {mF} (spans.check-ret options {mF} T? term)) (check-type : ctxt → ex-tp → (k? : maybe kind) → spans.spanM options {mF} (spans.check-ret options {mF} k? type)) where open import spans options {mF} open import rename open import syntax-util open import type-util open import meta-vars options {mF} open import resugar open import subst open import conversion open import free-vars open import constants record spine-data : Set where constructor mk-spine-data field spine-mvars : meta-vars spine-type : decortype spine-locale : ℕ spine-elab : meta-vars → term check-term-spine-elim : ctxt → spine-data → term × type check-term-spine-elim Γ (mk-spine-data Xs dt locl f~) = f~ Xs , meta-vars-subst-type' ff Γ Xs (decortype-to-type dt) -- elim-pair (maybe-else' (meta-vars-to-args Xs) ([] , Hole pi-gen) f~) recompose-apps , -- meta-vars-subst-type' ff Γ Xs (decortype-to-type dt) check-term-spine : ctxt → ex-tm → (m : prototype) → 𝔹 → spanM (maybe spine-data) check-term-spine-return : meta-vars → decortype → ℕ → (meta-vars → term) → spanM (maybe spine-data) check-term-spine-return Xs dt locl f~ = return (just (mk-spine-data Xs dt locl f~)) -- a flag indicating how aggresively we should be unfolding during matching. -- "both" is the backtracking flag. We will attempt "both" matches, which means -- first matching without unfolding, then if that fails unfolding the type once -- and continue matching the subexpresions with "both" data match-unfolding-state : Set where match-unfolding-both match-unfolding-approx match-unfolding-hnf : match-unfolding-state -- main matching definitions -- -------------------------------------------------- -- NOTE: these functions don't actually ever emit spans match-types : ctxt → meta-vars → local-vars → match-unfolding-state → (tpₓ tp : type) → spanM $ match-error-t meta-vars match-kinds : ctxt → meta-vars → local-vars → match-unfolding-state → (kₓ k : kind) → spanM $ match-error-t meta-vars match-tpkds : ctxt → meta-vars → local-vars → match-unfolding-state → (tkₓ tk : tpkd) → spanM $ match-error-t meta-vars record match-prototype-data : Set where constructor mk-match-prototype-data field match-proto-mvars : meta-vars match-proto-dectp : decortype match-proto-error : 𝔹 open match-prototype-data match-prototype : ctxt → (Xs : meta-vars) (is-hnf : 𝔹) (tp : type) (pt : prototype) → spanM match-prototype-data -- substitutions used during matching -- -------------------------------------------------- -- These have to be in the spanM monad because substitution can unlock a `stuck` -- decoration, causing another round of prototype matching (which invokes type matching) substh-decortype : ctxt → renamectxt → trie (Σi exprd ⟦_⟧) → decortype → spanM decortype substh-decortype Γ ρ σ (decor-type tp) = return $ decor-type (substh Γ ρ σ tp) substh-decortype Γ ρ σ (decor-arrow e? dom cod) = substh-decortype Γ ρ σ cod >>= λ cod → return $ decor-arrow e? (substh Γ ρ σ dom) cod substh-decortype Γ ρ σ (decor-decor e? x tk sol dt) = let x' = subst-rename-var-if Γ ρ x σ (decortype-to-type dt) Γ' = ctxt-var-decl x' Γ ρ' = renamectxt-insert ρ x x' in substh-decortype Γ' ρ' σ dt >>= λ dt' → return $ decor-decor e? x' (substh Γ ρ σ -tk tk) (substh-meta-var-sort Γ ρ σ sol) dt' substh-decortype Γ ρ σ (decor-stuck tp pt) = match-prototype Γ meta-vars-empty ff (substh Γ ρ σ tp) pt -- NOTE: its an invariant that if you start with no meta-variables, -- prototype matching produces no meta-variables as output >>= λ ret → return (match-proto-dectp ret) substh-decortype Γ ρ σ (decor-error tp pt) = return $ decor-error (substh Γ ρ σ tp) pt subst-decortype : {ed : exprd} → ctxt → ⟦ ed ⟧ → var → decortype → spanM decortype subst-decortype Γ s x dt = substh-decortype Γ empty-renamectxt (trie-single x (, s)) dt meta-vars-subst-decortype' : (unfold : 𝔹) → ctxt → meta-vars → decortype → spanM decortype meta-vars-subst-decortype' uf Γ Xs dt = substh-decortype Γ empty-renamectxt (meta-vars-get-sub Xs) dt >>= λ dt' → return $ if uf then hnf-decortype Γ unfold-head-elab dt' tt else dt' meta-vars-subst-decortype : ctxt → meta-vars → decortype → spanM decortype meta-vars-subst-decortype = meta-vars-subst-decortype' tt -- unfolding a decorated type to reveal a term / type abstraction -- -------------------------------------------------- {-# TERMINATING #-} meta-vars-peel' : ctxt → span-location → meta-vars → decortype → spanM (𝕃 meta-var × decortype) meta-vars-peel' Γ sl Xs (decor-decor e? x _ (meta-var-tp k mtp) dt) = let Y = meta-var-fresh-tp Xs x sl (k , mtp) Xs' = meta-vars-add Xs Y in subst-decortype Γ (meta-var-to-type-unsafe Y) x dt >>= λ dt' → meta-vars-peel' Γ sl Xs' dt' >>= λ ret → let Ys = fst ret ; rdt = snd ret in return $ Y :: Ys , rdt meta-vars-peel' Γ sl Xs dt@(decor-decor e? x _ (meta-var-tm _ _) _) = return $ [] , dt meta-vars-peel' Γ sl Xs dt@(decor-arrow _ _ _) = return $ [] , dt -- NOTE: vv The clause below will later generate a type error vv meta-vars-peel' Γ sl Xs dt@(decor-stuck _ _) = return $ [] , dt -- NOTE: vv The clause below is an internal error, if reached vv meta-vars-peel' Γ sl Xs dt@(decor-type _) = return $ [] , dt meta-vars-peel' Γ sl Xs dt@(decor-error _ _) = return $ [] , dt meta-vars-unfold-tmapp' : ctxt → span-location → meta-vars → decortype → spanM (𝕃 meta-var × is-tmabsd?) meta-vars-unfold-tmapp' Γ sl Xs dt = meta-vars-subst-decortype Γ Xs dt >>= λ dt' → meta-vars-peel' Γ sl Xs dt' >>= λ where (Ys , dt'@(decor-arrow e? dom cod)) → return $ Ys , yes-tmabsd dt' e? ignored-var dom ff cod (Ys , dt'@(decor-decor e? x _ (meta-var-tm dom _) cod)) → return $ Ys , yes-tmabsd dt' e? x dom (is-free-in x (decortype-to-type cod)) cod (Ys , dt@(decor-decor _ _ _ (meta-var-tp _ _) _)) → return $ Ys , not-tmabsd dt -- NOTE: vv this is a type error vv (Ys , dt@(decor-stuck _ _)) → return $ Ys , not-tmabsd dt -- NOTE: vv this is an internal error, if reached vv (Ys , dt@(decor-type _)) → return $ Ys , not-tmabsd dt (Ys , dt@(decor-error _ _)) → return $ Ys , not-tmabsd dt meta-vars-unfold-tpapp' : ctxt → meta-vars → decortype → spanM is-tpabsd? meta-vars-unfold-tpapp' Γ Xs dt = meta-vars-subst-decortype Γ Xs dt >>= λ where (dt″@(decor-decor e? x _ (meta-var-tp k mtp) dt')) → return $ yes-tpabsd dt″ e? x k (flip maybe-map mtp meta-var-sol.sol) dt' (dt″@(decor-decor _ _ _ (meta-var-tm _ _) _)) → return $ not-tpabsd dt″ (dt″@(decor-arrow _ _ _)) → return $ not-tpabsd dt″ (dt″@(decor-stuck _ _)) → return $ not-tpabsd dt″ (dt″@(decor-type _)) → return $ not-tpabsd dt″ (dt″@(decor-error _ _)) → return $ not-tpabsd dt″ -- errors -- -------------------------------------------------- -- general type errors for applications module check-term-app-tm-errors {A : Set} (t₁ t₂ : ex-tm) (htp : type) (Xs : meta-vars) (is-locale : 𝔹) (m : checking-mode) (Γ : ctxt) where inapplicable : erased? → decortype → prototype → spanM (maybe A) inapplicable e? dt pt = spanM-add (App-span is-locale (term-start-pos t₁) (term-end-pos t₂) m (head-type Γ (meta-vars-subst-type Γ Xs htp) -- :: decortype-data Γ dt -- :: prototype-data Γ pt :: meta-vars-data-all Γ Xs) (just $ "The type of the head does not allow the head to be applied to " ^ h e? ^ " argument")) >> return nothing where h : erased? → string h Erased = "an erased term" h NotErased = "a term" bad-erasure : erased? → spanM (maybe A) bad-erasure e? = spanM-add (App-span is-locale (term-start-pos t₁) (term-end-pos t₂) m (head-type Γ (meta-vars-subst-type Γ Xs htp) :: meta-vars-data-all Γ Xs) (just (msg e?))) >> return nothing where msg : erased? → string msg Erased = "The type computed for the head requires an explicit (non-erased) argument," ^ " but the application is marked as erased" msg NotErased = "The type computed for the head requires an implicit (erased) argument," ^ " but the application is marked as not erased" unmatchable : (tpₓ tp : type) (msg : string) → 𝕃 tagged-val → spanM (maybe A) unmatchable tpₓ tp msg tvs = spanM-add (App-span is-locale (term-start-pos t₁) (term-end-pos t₂) m (arg-exp-type Γ tpₓ :: arg-type Γ tp :: tvs ++ meta-vars-data-all Γ Xs) (just msg)) >> return nothing unsolved-meta-vars : type → 𝕃 tagged-val → spanM (maybe A) unsolved-meta-vars tp tvs = spanM-add (App-span tt (term-start-pos t₁) (term-end-pos t₂) m (type-data Γ tp :: meta-vars-data-all Γ Xs ++ tvs) (just "There are unsolved meta-variables in this maximal application")) >> return nothing module check-term-app-tp-errors {A : Set} (t : ex-tm) (tp : ex-tp) (htp : type) (Xs : meta-vars) (m : checking-mode) (Γ : ctxt) where inapplicable : decortype → spanM (maybe A) inapplicable dt = spanM-add (AppTp-span tt (term-start-pos t) (type-end-pos tp) synthesizing (head-type Γ (meta-vars-subst-type Γ Xs htp) -- :: decortype-data Γ dt :: meta-vars-data-all Γ Xs) (just "The type of the head does not allow the head to be applied to a type argument")) >> return nothing ctai-disagree : (ctai-sol : type) → spanM (maybe A) ctai-disagree ctai-sol = spanM-add (AppTp-span tt (term-start-pos t) (type-end-pos tp) m (head-type Γ (meta-vars-subst-type Γ Xs htp) :: contextual-type-argument Γ ctai-sol :: meta-vars-data-all Γ Xs) (just "The given and contextually inferred type argument differ")) >> return nothing -- meta-variable locality -- -------------------------------------------------- -- for debugging -- prepend to the tvs returned by check-spine-locality if you're having trouble private locale-tag : ℕ → tagged-val locale-tag n = "locale n" , [[ ℕ-to-string n ]] , [] private is-locale : (max : 𝔹) → (locl : maybe ℕ) → 𝔹 is-locale max locl = max || maybe-else' locl ff iszero check-spine-locality : ctxt → meta-vars → type → (max : 𝔹) → (locl : ℕ) → spanM (maybe (meta-vars × ℕ × 𝔹)) check-spine-locality Γ Xs tp max locl = let new-locl = if iszero locl then num-arrows-in-type Γ tp else locl new-Xs = if iszero locl then meta-vars-empty else Xs left-locl = is-locale max (just locl) in if left-locl && (~ meta-vars-solved? Xs) then return nothing else return (just (new-Xs , new-locl , left-locl)) -- main definition -------------------------------------------------- data check-term-app-ret : Set where check-term-app-return : (t~ : term) (Xs : meta-vars) (cod : decortype) (arg-mode : checking-mode) → (tvs : 𝕃 tagged-val) → check-term-app-ret check-term-app : ctxt → (Xs : meta-vars) (Ys : 𝕃 meta-var) → (t₁ t₂ : ex-tm) → is-tmabsd → 𝔹 → spanM (maybe check-term-app-ret) check-term-spine Γ t'@(ExApp t₁ e? t₂) pt max = -- 1) type the applicand, extending the prototype let pt' = proto-arrow e? pt in check-term-spine Γ t₁ pt' ff on-fail handleApplicandTypeError -- 2) make sure the applicand type reveals an arrow (term abstraction) >>=m λ ret → let mk-spine-data Xs dt locl fₕ~ = ret in -- the meta-vars need to know the span they were introduced in let sloc = span-loc $ ctxt.fn Γ in -- see if the decorated type of the head `dt` reveals an arrow meta-vars-unfold-tmapp' Γ sloc Xs dt >>=c λ Ys tm-arrow? → return tm-arrow? on-fail (λ _ → genInapplicableError Xs dt pt' locl) -- if so, get the (plain, undecorated) type of the head `htp` >>=s λ arr → let htp = decortype-to-type ∘ is-tmabsd-dt $ arr in -- 3) make sure erasures of the applicand type + syntax of application match checkErasuresMatch e? (is-tmabsd-e? arr) htp Xs locl -- 4) type the application, filling in missing type arguments with meta-variables >>=m λ _ → check-term-app Γ Xs Ys t₁ t₂ arr (islocl locl) -- 5) check no unsolved mvars, if the application is maximal (or a locality) >>=m λ {(check-term-app-return t₂~ Xs' rtp' arg-mode tvs) → let rtp = decortype-to-type rtp' in checkLocality Γ Xs' htp rtp max (pred locl) tvs >>=m uncurry₂ λ Xs'' locl' is-loc → -- 6) generate span genAppSpan Γ Xs Xs' Ys pt rtp is-loc tvs >> check-term-spine-return Xs'' rtp' locl' -- 7) fill in solutions to meta-vars introduced here and return the rest λ sols → let sols = if max then Xs' else sols -- num-sols-here = length Ys -- sols-here = take num-sols-here sols -- sols-rest = drop num-sols-here sols -- as = maybe-else' (meta-vars-to-args (meta-vars-from-list sols-here)) [] id -- tₕ~ = recompose-apps as tₕₓ~ tₕ~ = foldl (λ X t → maybe-else' (meta-vars-lookup sols (meta-var.name X)) t λ {(meta-var-mk X' (meta-var-tp k T?) _) → maybe-else' T? t (AppTp t ∘ meta-var-sol.sol); (meta-var-mk X' (meta-var-tm T t?) _) → maybe-else' t? t (AppEr t ∘ meta-var-sol.sol)}) (fₕ~ sols) Ys app = if e? then AppEr else App in app tₕ~ t₂~ } where mode = prototype-to-checking pt expected-type-if-pt : ctxt → prototype → 𝕃 tagged-val expected-type-if-pt Γ pt = case pt of λ where (proto-maybe mt) → maybe-else [] (λ tp → [ expected-type Γ tp ]) mt (proto-arrow _ _) → [] span-loc : (fn : string) → span-location span-loc fn = fn , term-start-pos t₁ , term-end-pos t₂ islocl : ℕ → 𝔹 islocl locl = is-locale max (just $ pred locl) handleApplicandTypeError : spanM (maybe _) handleApplicandTypeError = spanM-add (App-span max (term-start-pos t₁) (term-end-pos t₂) mode (expected-type-if-pt Γ pt) nothing) >> check-term Γ t₂ nothing >>= (const $ return nothing) genInapplicableError : meta-vars → decortype → prototype → (locl : ℕ) → spanM (maybe _) genInapplicableError Xs dt pt locl = check-term-app-tm-errors.inapplicable t₁ t₂ (decortype-to-type dt) Xs (islocl locl) mode Γ e? dt (proto-arrow e? pt) checkErasuresMatch : (e?₁ e?₂ : erased?) → type → meta-vars → (locl : ℕ) → spanM (maybe ⊤) checkErasuresMatch e?₁ e?₂ htp Xs locl = if e?₁ xor e?₂ then check-term-app-tm-errors.bad-erasure t₁ t₂ htp Xs (islocl locl) mode Γ e?₁ else (return ∘ just $ triv) checkLocality : ctxt → meta-vars → (htp rtp : type) → (max : 𝔹) (locl : ℕ) → 𝕃 tagged-val → spanM ∘ maybe $ _ checkLocality Γ Xs htp rtp max locl tvs = check-spine-locality Γ Xs rtp max locl on-fail check-term-app-tm-errors.unsolved-meta-vars t₁ t₂ htp Xs (islocl locl) mode Γ rtp tvs >>=m (return ∘ just) genAppSpan : ctxt → (Xs Xs' : meta-vars) → (Ys : 𝕃 meta-var) → prototype → type → (is-locl : 𝔹) → 𝕃 tagged-val → spanM ⊤ genAppSpan Γ Xs Xs' Ys pt rtp is-loc tvs = spanM-add $ elim-pair (meta-vars-check-type-mismatch-if (prototype-to-maybe pt) Γ "synthesized" meta-vars-empty rtp) λ tvs' → App-span is-loc (term-start-pos t₁) (term-end-pos t₂) mode (tvs' ++ meta-vars-intro-data Γ (meta-vars-from-list Ys) ++ meta-vars-sol-data Γ Xs Xs' ++ tvs) check-term-spine Γ t'@(ExAppTp t tp) pt max = -- 1) type the applicand check-term-spine Γ t pt max on-fail handleApplicandTypeError >>=m λ ret → let mk-spine-data Xs dt locl fₕ~ = ret ; htp = decortype-to-type dt in -- 2) make sure it reveals a type abstraction meta-vars-unfold-tpapp' Γ Xs dt on-fail (λ _ → genInapplicableError Xs htp dt) -- 3) ensure the type argument has the expected kind, -- but don't compare with the contextually infered type argument (for now) >>=s λ ret → let mk-tpabsd dt e? x k sol rdt = ret in check-type Γ tp (just (meta-vars-subst-kind Γ Xs k)) -- 4) produce the result type of the application >>= λ tp~ → subst-decortype-if Γ tp~ Xs x k sol rdt >>= λ ret → let Xs = fst ret ; rdt = snd ret ; rtp = decortype-to-type rdt in -- 5) generate span data genAppTpSpan Γ Xs pt rtp >> check-term-spine-return Xs rdt locl -- 7) fill in solutions to meta-vars introduced here and return the rest λ sols → AppTp (fₕ~ sols) tp~ --(map-snd (λ tₕ~ → AppE tₕ~ (Ttp tp~)) ∘ fₕ~) where mode = prototype-to-checking pt span-loc : ctxt → span-location span-loc Γ = (ctxt.fn Γ) , term-start-pos t , type-end-pos tp handleApplicandTypeError : spanM ∘ maybe $ spine-data handleApplicandTypeError = [- AppTp-span tt (term-start-pos t) (type-end-pos tp) synthesizing [] nothing -] check-type Γ tp nothing >>= λ _ → return nothing genInapplicableError : meta-vars → type → decortype → spanM ∘ maybe $ spine-data genInapplicableError Xs htp dt = check-term-app-tp-errors.inapplicable t tp htp Xs mode Γ dt subst-decortype-if : ctxt → type → meta-vars → var → kind → maybe type → decortype → spanM (meta-vars × decortype) subst-decortype-if Γ tp Xs x k sol rdt = if ~ is-hole tp then subst-decortype Γ tp x rdt >>= (λ res → return (Xs , res)) else let sol = maybe-map (λ t → mk-meta-var-sol t checking) sol Y = meta-var-fresh-tp Xs x (span-loc Γ) (k , sol) Xs' = meta-vars-add Xs Y in subst-decortype Γ (meta-var-to-type-unsafe Y) x rdt >>= λ rdt' → return (Xs' , rdt') genAppTpSpan : ctxt → meta-vars → prototype → (ret-tp : type) → spanM ⊤ genAppTpSpan Γ Xs pt ret-tp = spanM-add ∘ elim-pair -- check for a type mismatch, if there even is an expected type (meta-vars-check-type-mismatch-if (prototype-to-maybe pt) Γ "synthesizing" Xs ret-tp) $ -- then take the generated 𝕃 tagged-val and add to the span λ tvs → AppTp-span ff (term-start-pos t) (type-end-pos tp) mode $ tvs ++ meta-vars-data-all Γ Xs -- ++ (prototype-data Γ tp :: [ decortype-data Γ dt ]) check-term-spine Γ (ExParens _ t _) pt max = check-term-spine Γ t pt max check-term-spine Γ t pt max = check-term Γ t nothing >>=c λ t~ htp → let locl = num-arrows-in-type Γ htp in match-prototype Γ meta-vars-empty ff htp pt -- NOTE: it is an invariant that the variables solved in the -- solution set of the fst of this are a subset of the variables given -- to match-* -- that is, for (σ , W) = match-prototype ... -- we have dom(σ) = ∅ >>= λ ret → let dt = match-proto-dectp ret in check-term-spine-return meta-vars-empty dt locl λ _ → t~ -- check-term-app -- -------------------------------------------------- -- -- If `dom` has unsolved meta-vars in it, synthesize argument t₂ and try to solve for them. -- Otherwise, check t₂ against a fully known expected type check-term-app Γ Xs Zs t₁ t₂ (mk-tmabsd dt e? x dom occurs cod) is-locl = let Xs' = meta-vars-add* Xs Zs ; tp = decortype-to-type dt in -- 1) either synth or check arg type, depending on available info -- checking "exits early", as well as failure checkArgWithMetas Xs' tp (genAppRetType Γ) on-fail return -- 2) match *synthesized* type with expected (partial) type >>=s uncurry₂ λ rdt t₂~ atp → match-types Γ Xs' empty-trie match-unfolding-both dom atp >>= (handleMatchResult Xs' t₂~ atp tp rdt) where mode = synthesizing genAppRetType : ctxt → term → spanM decortype genAppRetType Γ t₂~ = if occurs then subst-decortype Γ t₂~ x cod else return cod genAppRetTypeHole : ctxt → spanM decortype genAppRetTypeHole Γ = if occurs then subst-decortype Γ (Hole posinfo-gen) x cod else return cod checkArgWithMetas : meta-vars → type → (term → spanM decortype) → spanM (maybe check-term-app-ret ∨ (decortype × term × type)) checkArgWithMetas Xs' tp rdt-f = -- check arg against fully known type if ~ meta-vars-are-free-in-type Xs' dom then (check-term Γ t₂ (just dom) >>= λ t₂~ → rdt-f t₂~ >>= λ rdt → return (inj₁ (just $ check-term-app-return t₂~ Xs' rdt mode []))) -- synthesize type for the argument else (check-term Γ t₂ nothing >>=c λ t tp → rdt-f t >>= λ rdt → return (inj₂ $ rdt , t , tp)) handleMatchResult : meta-vars → (t₂~ : term) → (atp tp : type) → decortype → match-error-t meta-vars → spanM ∘ maybe $ check-term-app-ret handleMatchResult Xs' t₂~ atp tp rdt (match-error (msg , tvs)) = check-term-app-tm-errors.unmatchable t₁ t₂ tp Xs' is-locl mode Γ dom atp msg tvs handleMatchResult Xs' t₂~ atp tp rdt (match-ok Xs) = meta-vars-subst-decortype' ff Γ Xs rdt >>= λ rdt → return ∘ just $ check-term-app-return t₂~ Xs rdt mode [] match-unfolding-next : match-unfolding-state → match-unfolding-state match-unfolding-next match-unfolding-both = match-unfolding-both match-unfolding-next match-unfolding-approx = match-unfolding-approx match-unfolding-next match-unfolding-hnf = match-unfolding-both module m-err = meta-vars-match-errors check-type-for-match : ctxt → type → spanM $ match-error-t kind check-type-for-match Γ tp = (with-clear-error $ check-type (qualified-ctxt Γ) (resugar tp) nothing >>=c λ _ k → return (match-ok $ k)) >>=spand return -- match-types -- -------------------------------------------------- match-types-ok : meta-vars → spanM $ match-error-t meta-vars match-types-ok = return ∘ match-ok match-types-error : match-error-data → spanM $ match-error-t meta-vars match-types-error = return ∘ match-error match-types Γ Xs Ls match-unfolding-both tpₓ tp = match-types Γ Xs Ls match-unfolding-approx tpₓ tp >>= λ where (match-ok Xs) → match-types-ok Xs (match-error msg) → match-types Γ Xs Ls match-unfolding-hnf (hnf Γ unfold-head-elab tpₓ) (hnf Γ unfold-head-elab tp) match-types Γ Xs Ls unf tpₓ@(TpVar x) tp = -- check that x is a meta-var maybe-else' (meta-vars-lookup-with-kind Xs x) -- if not, make sure the two variables are the same -- TODO: above assumes no term meta-variables (return (err⊎-guard (~ conv-type Γ tpₓ tp) m-err.e-match-failure >> match-ok Xs)) -- scope check the solution λ ret → let X = fst ret ; kₓ = snd ret in if are-free-in Ls tp then match-types-error $ m-err.e-meta-scope Γ tpₓ tp else (check-type-for-match Γ tp >>=s λ k → match-kinds Γ Xs empty-trie match-unfolding-both kₓ k on-fail (λ _ → return ∘ match-error $ m-err.e-bad-sol-kind Γ x tp) >>=s λ Xs → return (meta-vars-solve-tp Γ Xs x tp synthesizing) >>=s λ Xs → match-types-ok $ meta-vars-update-kinds Γ Xs Xs) match-types Γ Xs Ls unf (TpApp tpₓ₁ (Ttp tpₓ₂)) (TpApp tp₁ (Ttp tp₂)) = match-types Γ Xs Ls unf tpₓ₁ tp₁ >>=s λ Xs' → match-types Γ Xs' Ls (match-unfolding-next unf) tpₓ₂ tp₂ match-types Γ Xs Ls unf (TpApp tpₓ (Ttm tmₓ)) (TpApp tp (Ttm tm)) = match-types Γ Xs Ls unf tpₓ tp >>=s λ Xs' → return $ if ~ conv-term Γ tmₓ tm then (match-error m-err.e-match-failure) else match-ok Xs' match-types Γ Xs Ls unf tpₓ'@(TpAbs bₓ xₓ tkₓ tpₓ) tp'@(TpAbs b x tk tp) = if bₓ xor b then (match-types-error m-err.e-match-failure) else (match-tpkds Γ Xs Ls (match-unfolding-next unf) tkₓ tk >>=s λ Xs' → match-types (Γ→Γ' Γ) Xs' Ls' (match-unfolding-next unf) tpₓ tp) where Γ→Γ' : ctxt → ctxt Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ) Ls' = stringset-insert Ls x match-types Γ Xs Ls unf (TpIota xₓ mₓ tpₓ) (TpIota x m tp) = match-types Γ Xs Ls (match-unfolding-next unf) mₓ m >>=s λ Xs → match-types (Γ→Γ' Γ) Xs Ls' (match-unfolding-next unf) tpₓ tp where Γ→Γ' : ctxt → ctxt Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ) Ls' = stringset-insert Ls x match-types Γ Xs Ls unf (TpEq t₁ₓ t₂ₓ) (TpEq t₁ t₂) = if ~ conv-term Γ t₁ₓ t₁ then match-types-error $ m-err.e-match-failure else if ~ conv-term Γ t₂ₓ t₂ then match-types-error $ m-err.e-match-failure else match-types-ok Xs match-types Γ Xs Ls unf (TpLam xₓ atkₓ tpₓ) (TpLam x atk tp) = match-tpkds Γ Xs Ls (match-unfolding-next unf) atkₓ atk >>=s λ Xs → match-types (Γ→Γ' Γ) Xs Ls' (match-unfolding-next unf) tpₓ tp where Γ→Γ' : ctxt → ctxt Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ) Ls' = stringset-insert Ls x match-types Γ Xs Ls unf tpₓ tp = match-types-error m-err.e-match-failure -- match-kinds -- -------------------------------------------------- -- match-kinds-norm: match already normalized kinds match-kinds-norm : ctxt → meta-vars → local-vars → match-unfolding-state → (kₓ k : kind) → spanM $ match-error-t meta-vars -- kind pi match-kinds-norm Γ Xs Ls uf (KdAbs xₓ tkₓ kₓ) (KdAbs x tk k) = match-tpkds Γ Xs Ls uf tkₓ tk >>=s λ Xs → match-kinds (Γ→Γ' Γ) Xs Ls' uf kₓ k where Γ→Γ' = ctxt-rename xₓ x ∘ ctxt-var-decl-if x Ls' = stringset-insert Ls x match-kinds-norm Γ Xs Ls uf KdStar KdStar = match-types-ok $ Xs match-kinds-norm Γ Xs Ls uf kₓ k = match-types-error $ m-err.e-matchk-failure -- m-err.e-kind-ineq Γ kₓ k match-kinds Γ Xs Ls uf kₓ k = match-kinds-norm Γ Xs Ls uf (hnf Γ unfold-head-elab kₓ) (hnf Γ unfold-head-elab k) -- match-tk -- -------------------------------------------------- match-tpkds Γ Xs Ls uf (Tkk kₓ) (Tkk k) = match-kinds Γ Xs Ls uf kₓ k match-tpkds Γ Xs Ls uf (Tkt tpₓ) (Tkt tp) = match-types Γ Xs Ls uf tpₓ tp match-tpkds Γ Xs Ls uf tkₓ tk = match-types-error m-err.e-matchk-failure -- m-err.e-tk-ineq Γ tkₓ tk -- match-prototype -- -------------------------------------------------- match-prototype-err : type → prototype → spanM match-prototype-data match-prototype-err tp pt = return $ mk-match-prototype-data meta-vars-empty (decor-error tp pt) tt {- -------------------- Xs ⊢? T ≔ ⁇ ⇒ (∅ , T) -} match-prototype Γ Xs uf tp (proto-maybe nothing) = return $ mk-match-prototype-data Xs (decor-type tp) ff {- Xs ⊢= T ≔ S ⇒ σ -------------------- Xs ⊢? T ≔ S ⇒ (σ , T) -} match-prototype Γ Xs uf tp pt@(proto-maybe (just tp')) = match-types Γ Xs empty-trie match-unfolding-both tp tp' on-fail (λ _ → return $ mk-match-prototype-data Xs (decor-error tp pt) tt) >>=s λ Xs' → return $ mk-match-prototype-data Xs' (decor-type tp) ff {- Xs,X ⊢? T ≔ ⁇ → P ⇒ (σ , W) ----------------------------------------------- Xs ⊢? ∀ X . T ≔ ⁇ → P ⇒ (σ - X , ∀ X = σ(X) . W) -} match-prototype Γ Xs uf (TpAbs bₓ x (Tkk k) tp) pt'@(proto-arrow e? pt) = -- 1) generate a fresh meta-var Y, add it to the meta-vars, and rename -- occurences of x in tp to Y let ret = meta-vars-add-from-tpabs Γ missing-span-location Xs Erased x k tp Y = fst ret ; Xs' = snd ret ; tp' = subst Γ (meta-var-to-type-unsafe Y) x tp -- 2) match the body against the original prototype to generate a decorated type -- and find some solutions in match-prototype Γ Xs' ff tp' pt' >>= λ ret → let mk-match-prototype-data Xs' dt err = ret Y' = maybe-else' (meta-vars-lookup Xs' (meta-var-name Y)) Y λ Y → Y -- 3) replace the meta-vars with the bound type variable in subst-decortype Γ (TpVar x) (meta-var-name Y) dt -- 4) leave behind the solution for Y as a decoration and drop Y from Xs >>= λ dt' → let sort' = meta-var.sort (meta-var-set-src Y' checking) dt″ = decor-decor Erased x (Tkk k) sort' dt' in return $ mk-match-prototype-data (meta-vars-remove Xs' Y) dt″ err {- Xs ⊢? T ≔ P ⇒ (σ , P) ----------------------------- Xs ⊢? S → T ≔ ⁇ → P ⇒ (σ , P) -} match-prototype Γ Xs uf (TpAbs b x (Tkt dom) cod) (proto-arrow e? pt) = match-prototype Γ Xs ff cod pt >>= λ ret → let mk-match-prototype-data Xs dt err = ret dt' = decor-decor b x (Tkt dom) (meta-var-tm dom nothing) dt in return $ if b xor e? then mk-match-prototype-data meta-vars-empty dt' tt else mk-match-prototype-data Xs dt' err {- X ∈ Xs ----------------------------------- Xs ⊢? X ≔ ⁇ → P ⇒ (σ , (X , ⁇ → P)) -} match-prototype Γ Xs tt tp@(TpVar x) pt@(proto-arrow _ _) = return $ mk-match-prototype-data Xs (decor-stuck tp pt) ff -- everything else... -- Types for which we should keep digging match-prototype Γ Xs ff tp@(TpVar x) pt@(proto-arrow _ _) = match-prototype Γ Xs tt (hnf Γ unfold-head-elab tp) pt match-prototype Γ Xs ff tp@(TpApp _ _) pt@(proto-arrow _ _) = match-prototype Γ Xs tt (hnf Γ unfold-head-elab tp) pt -- types for which we should suspend disbelief match-prototype Γ Xs tt tp@(TpApp _ _) pt@(proto-arrow _ _) = return $ mk-match-prototype-data Xs (decor-stuck tp pt) ff -- types which clearly do not match the prototype match-prototype Γ Xs uf tp@(TpEq _ _) pt@(proto-arrow _ _) = match-prototype-err tp pt match-prototype Γ Xs uf tp@(TpHole _) pt@(proto-arrow _ _) = match-prototype-err tp pt match-prototype Γ Xs uf tp@(TpLam _ _ _) pt@(proto-arrow _ _) = match-prototype-err tp pt match-prototype Γ Xs uf tp@(TpIota _ _ _) pt@(proto-arrow _ _) = match-prototype-err tp pt
42.17971
155
0.631357
1e18c913c0eda5b33c9048f2c607167b15769a1f
169
agda
Agda
test/fail/SetOmega.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/fail/SetOmega.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/SetOmega.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module SetOmega where open import Imports.Level postulate IsType : ∀ {a} → Set a → Set Bad : IsType ((a : Level) → Set a)
16.9
39
0.650888
58d8200f1f23dac3a98c6659474d4957efda3142
301
agda
Agda
test/Fail/Issue3817.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue3817.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue3817.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --rewriting --confluence-check #-} open import Agda.Primitive open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite postulate A : Set a b : A f : Level → A g h : Level f-g : f (lsuc g) ≡ a f-h : f (lsuc h) ≡ b g-h : g ≡ h {-# REWRITE f-g f-h g-h #-}
17.705882
46
0.611296
30ca50f677383b2cd41976dcd64b0a989cc232dd
8,193
agda
Agda
src/Partiality-algebra/Fixpoints.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
2
2020-05-21T22:59:18.000Z
2020-07-03T08:56:08.000Z
src/Partiality-algebra/Fixpoints.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
src/Partiality-algebra/Fixpoints.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Fixpoint combinators ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} open import Partiality-algebra as PA hiding (id; _∘_) module Partiality-algebra.Fixpoints where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (T; ⊥) open import Bijection equality-with-J using (_↔_) import Equivalence equality-with-J as Eq open import Function-universe equality-with-J hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Monad equality-with-J open import Univalence-axiom equality-with-J open import Partiality-algebra.Monotone open import Partiality-algebra.Omega-continuous import Partiality-algebra.Properties as PAP open [_⟶_]⊑ -- The development below, up to fix-is-least, is (very similar to) -- Kleene's fixed-point theorem. private module Fix₀ {a p q} {A : Type a} {P : Partiality-algebra p q A} where open Partiality-algebra P open PAP P -- Repeated composition of a monotone function with itself. comp : [ P ⟶ P ]⊑ → ℕ → [ P ⟶ P ]⊑ comp f zero = id⊑ comp f (suc n) = f ∘⊑ comp f n -- Pre-composition with the function is equal to post-composition -- with the function. pre≡post : ∀ f n → comp f n ∘⊑ f ≡ f ∘⊑ comp f n pre≡post f zero = f ∎ pre≡post f (suc n) = (f ∘⊑ comp f n) ∘⊑ f ≡⟨ ∘⊑-assoc f (comp f n) ⟩ f ∘⊑ (comp f n ∘⊑ f) ≡⟨ cong (f ∘⊑_) $ pre≡post f n ⟩∎ f ∘⊑ (f ∘⊑ comp f n) ∎ -- Repeated application of a monotone function to never. app : [ P ⟶ P ]⊑ → ℕ → T app f n = function (comp f n) never -- An increasing sequence consisting of repeated applications of the -- given monotone function to never. fix-sequence : [ P ⟶ P ]⊑ → Increasing-sequence fix-sequence f = app f , fix-sequence-increasing where abstract fix-sequence-increasing : ∀ n → function (comp f n) never ⊑ function (f ∘⊑ comp f n) never fix-sequence-increasing n = function (comp f n) never ⊑⟨ monotone (comp f n) (never⊑ (function f never)) ⟩ function (comp f n) (function f never) ⊑⟨⟩ function (comp f n ∘⊑ f) never ≡⟨ cong (λ g → function g never) $ pre≡post f n ⟩⊑ function (f ∘⊑ comp f n) never ■ -- Taking the tail of this sequence amounts to the same thing as -- applying the function to each element in the sequence. tailˢ-fix-sequence : (f : [ P ⟶ P ]⊑) → tailˢ (fix-sequence f) ≡ [ f $ fix-sequence f ]-inc tailˢ-fix-sequence f = _↔_.to equality-characterisation-increasing λ _ → refl -- The sequence has the same least upper bound as the sequence you get -- if you apply the function to each element of the sequence. ⨆-fix-sequence : (f : [ P ⟶ P ]⊑) → ⨆ (fix-sequence f) ≡ ⨆ [ f $ fix-sequence f ]-inc ⨆-fix-sequence f = ⨆ (fix-sequence f) ≡⟨ sym $ ⨆tail≡⨆ _ ⟩ ⨆ (tailˢ (fix-sequence f)) ≡⟨ cong ⨆ (tailˢ-fix-sequence f) ⟩∎ ⨆ [ f $ fix-sequence f ]-inc ∎ -- A fixpoint combinator. fix : [ P ⟶ P ]⊑ → T fix f = ⨆ (fix-sequence f) -- The fixpoint combinator produces fixpoints for ω-continuous -- arguments. fix-is-fixpoint-combinator : (fω : [ P ⟶ P ]) → let f : [ P ⟶ P ]⊑ f = [_⟶_].monotone-function fω in fix f ≡ function f (fix f) fix-is-fixpoint-combinator fω = fix f ≡⟨⟩ ⨆ (fix-sequence f) ≡⟨ ⨆-fix-sequence f ⟩ ⨆ [ f $ fix-sequence f ]-inc ≡⟨ sym $ [_⟶_].ω-continuous fω _ ⟩ function f (⨆ (fix-sequence f)) ≡⟨⟩ function f (fix f) ∎ where f : [ P ⟶ P ]⊑ f = [_⟶_].monotone-function fω -- The result of the fixpoint combinator is smaller than or equal to -- every post-fixpoint. fix-is-least : (f : [ P ⟶ P ]⊑) → ∀ x → function f x ⊑ x → fix f ⊑ x fix-is-least f x fx⊑x = least-upper-bound _ _ lemma where lemma : ∀ n → function (comp f n) never ⊑ x lemma zero = never⊑ x lemma (suc n) = function (f ∘⊑ comp f n) never ⊑⟨⟩ function f (function (comp f n) never) ⊑⟨ monotone f (lemma n) ⟩ function f x ⊑⟨ fx⊑x ⟩■ x ■ -- A restricted homomorphism property. comp-∘ : ∀ f n → comp (f ∘⊑ f) n ≡ comp f n ∘⊑ comp f n comp-∘ f zero = id⊑ ∎ comp-∘ f (suc n) = (f ∘⊑ f) ∘⊑ comp (f ∘⊑ f) n ≡⟨ cong ((f ∘⊑ f) ∘⊑_) (comp-∘ f n) ⟩ (f ∘⊑ f) ∘⊑ (comp f n ∘⊑ comp f n) ≡⟨ lemma f f (comp f n) _ ⟩ f ∘⊑ ((f ∘⊑ comp f n) ∘⊑ comp f n) ≡⟨ cong ((_∘⊑ comp f n) ∘ (f ∘⊑_)) $ sym $ pre≡post f n ⟩ f ∘⊑ ((comp f n ∘⊑ f) ∘⊑ comp f n) ≡⟨ sym $ lemma f (comp f n) f _ ⟩∎ (f ∘⊑ comp f n) ∘⊑ (f ∘⊑ comp f n) ∎ where lemma : (f g h k : [ P ⟶ P ]⊑) → (f ∘⊑ g) ∘⊑ (h ∘⊑ k) ≡ f ∘⊑ ((g ∘⊑ h) ∘⊑ k) lemma f g h k = (f ∘⊑ g) ∘⊑ (h ∘⊑ k) ≡⟨ ∘⊑-assoc f g ⟩ f ∘⊑ (g ∘⊑ (h ∘⊑ k)) ≡⟨ cong (f ∘⊑_) $ ∘⊑-assoc g h ⟩∎ f ∘⊑ ((g ∘⊑ h) ∘⊑ k) ∎ -- The function comp f is homomorphic with respect to _+_/_∘⊑_. comp-+∘ : ∀ f m {n} → comp f (m + n) ≡ comp f m ∘⊑ comp f n comp-+∘ f zero {n} = comp f n ∎ comp-+∘ f (suc m) {n} = f ∘⊑ comp f (m + n) ≡⟨ cong (f ∘⊑_) $ comp-+∘ f m ⟩ f ∘⊑ (comp f m ∘⊑ comp f n) ≡⟨ ∘⊑-assoc f (comp f m) ⟩∎ (f ∘⊑ comp f m) ∘⊑ comp f n ∎ -- Taking steps that are "twice as large" does not affect the end -- result. fix-∘ : (f : [ P ⟶ P ]⊑) → fix (f ∘⊑ f) ≡ fix f fix-∘ f = antisymmetry (least-upper-bound _ _ λ n → function (comp (f ∘⊑ f) n) never ≡⟨ cong (λ f → function f never) $ comp-∘ f n ⟩⊑ function (comp f n ∘⊑ comp f n) never ≡⟨ cong (λ f → function f never) $ sym $ comp-+∘ f n ⟩⊑ function (comp f (n + n)) never ⊑⟨ upper-bound (fix-sequence f) (n + n) ⟩■ ⨆ (fix-sequence f) ■) (⨆-mono λ n → function (comp f n) never ⊑⟨ monotone (comp f n) (never⊑ _) ⟩ function (comp f n) (function (comp f n) never) ⊑⟨⟩ function (comp f n ∘⊑ comp f n) never ≡⟨ cong (λ f → function f never) $ sym $ comp-∘ f n ⟩⊑ function (comp (f ∘⊑ f) n) never ■) open Fix₀ -- N-ary Scott induction. module N-ary (open Partiality-algebra) {a p q r} n (As : Fin n → Type a) (Ps : ∀ i → Partiality-algebra p q (As i)) (P : (∀ i → T (Ps i)) → Type r) (P⊥ : P (λ i → never (Ps i))) (P⨆ : (ss : ∀ i → Increasing-sequence (Ps i)) → (∀ n → P (λ i → _[_] (Ps i) (ss i) n)) → P (λ i → ⨆ (Ps i) (ss i))) (fs : ∀ i → [ Ps i ⟶ Ps i ]⊑) where -- Generalised. fix-induction′ : (∀ n → P (λ i → app (fs i) n) → P (λ i → app (fs i) (suc n))) → P (fix ∘ fs) fix-induction′ step = $⟨ lemma ⟩ (∀ n → P (λ i → app (fs i) n)) ↝⟨ P⨆ _ ⟩ P (λ i → ⨆ (Ps i) (fix-sequence (fs i))) ↝⟨ id ⟩□ P (fix ∘ fs) □ where lemma : ∀ n → P (λ i → function (comp (fs i) n) (never (Ps i))) lemma zero = P⊥ lemma (suc n) = $⟨ lemma n ⟩ P (λ i → app (fs i) n) ↝⟨ step n ⟩□ P (λ i → function (fs i) (app (fs i) n)) □ -- Basic. fix-induction : (∀ xs → P xs → P (λ i → function (fs i) (xs i))) → P (fix ∘ fs) fix-induction step = fix-induction′ (λ n → step (λ i → app (fs i) n)) open N-ary public module Fix {a p q} {A : Type a} {P : Partiality-algebra p q A} where open Partiality-algebra P -- Unary Scott induction. fix-induction₁ : ∀ {r} (Q : T → Type r) → Q never → (∀ s → (∀ n → Q (s [ n ])) → Q (⨆ s)) → (f : [ P ⟶ P ]⊑) → (∀ x → Q x → Q (function f x)) → Q (fix f) fix-induction₁ Q Q⊥ Q⨆ f step = fix-induction 1 [ const A , ⊥-elim ] [ const P , (λ i → ⊥-elim i) ] (Q ∘ (_$ fzero)) Q⊥ (Q⨆ ∘ (_$ fzero)) [ const f , (λ x → ⊥-elim x) ] (step ∘ (_$ fzero)) open Fix₀ {P = P} public open Fix public
33.17004
110
0.501892
0389cc51aa9145cc847ebcea63429d67e29733c8
6,790
agda
Agda
src/MultiSorted/Interpretation.agda
cilinder/formaltt
0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb
[ "MIT" ]
21
2021-02-16T14:07:06.000Z
2021-11-19T15:50:08.000Z
src/MultiSorted/Interpretation.agda
andrejbauer/formaltt
2aaf850bb1a262681c5a232cdefae312f921b9d4
[ "MIT" ]
1
2021-04-30T14:18:25.000Z
2021-05-14T16:15:17.000Z
src/MultiSorted/Interpretation.agda
andrejbauer/formaltt
2aaf850bb1a262681c5a232cdefae312f921b9d4
[ "MIT" ]
6
2021-02-16T13:43:07.000Z
2021-05-24T02:51:43.000Z
open import Agda.Primitive using (_⊔_) import Categories.Category as Category import Categories.Category.Cartesian as Cartesian open import MultiSorted.AlgebraicTheory import MultiSorted.Product as Product module MultiSorted.Interpretation {o ℓ e} {𝓈 ℴ} (Σ : Signature {𝓈} {ℴ}) {𝒞 : Category.Category o ℓ e} (cartesian-𝒞 : Cartesian.Cartesian 𝒞) where open Signature Σ open Category.Category 𝒞 -- An interpretation of Σ in 𝒞 record Interpretation : Set (o ⊔ ℓ ⊔ e ⊔ 𝓈 ⊔ ℴ) where field interp-sort : sort → Obj interp-ctx : Product.Producted 𝒞 {Σ = Σ} interp-sort interp-oper : ∀ (f : oper) → Product.Producted.prod interp-ctx (oper-arity f) ⇒ interp-sort (oper-sort f) open Product.Producted interp-ctx -- the interpretation of a term interp-term : ∀ {Γ : Context} {A} → Term Γ A → prod Γ ⇒ interp-sort A interp-term (tm-var x) = π x interp-term (tm-oper f ts) = interp-oper f ∘ tuple (oper-arity f) (λ i → interp-term (ts i)) -- the interpretation of a substitution interp-subst : ∀ {Γ Δ} → Γ ⇒s Δ → prod Γ ⇒ prod Δ interp-subst {Γ} {Δ} σ = tuple Δ λ i → interp-term (σ i) -- the equality of interpretations ⊨_ : (ε : Equation Σ) → Set e open Equation ⊨ ε = interp-term (eq-lhs ε) ≈ interp-term (eq-rhs ε) -- interpretation commutes with substitution open HomReasoning interp-[]s : ∀ {Γ Δ} {A} {t : Term Δ A} {σ : Γ ⇒s Δ} → interp-term (t [ σ ]s) ≈ interp-term t ∘ interp-subst σ interp-[]s {Γ} {Δ} {A} {tm-var x} {σ} = ⟺ (project {Γ = Δ}) interp-[]s {Γ} {Δ} {A} {tm-oper f ts} {σ} = (∘-resp-≈ʳ (tuple-cong {fs = λ i → interp-term (ts i [ σ ]s)} {gs = λ z → interp-term (ts z) ∘ interp-subst σ} (λ i → interp-[]s {t = ts i} {σ = σ}) ○ (∘-distribʳ-tuple {Γ = oper-arity f} {fs = λ z → interp-term (ts z)} {g = interp-subst σ}))) ○ (Equiv.refl ○ sym-assoc) -- -- Every signature has the trivial interpretation open Product 𝒞 Trivial : Interpretation Trivial = let open Cartesian.Cartesian cartesian-𝒞 in record { interp-sort = (λ _ → ⊤) ; interp-ctx = StandardProducted (λ _ → ⊤) cartesian-𝒞 ; interp-oper = λ f → ! } record _⇒I_ (I J : Interpretation) : Set (o ⊔ ℓ ⊔ e ⊔ 𝓈 ⊔ ℴ) where open Interpretation open Producted field hom-morphism : ∀ {A} → interp-sort I A ⇒ interp-sort J A hom-commute : ∀ (f : oper) → hom-morphism ∘ interp-oper I f ≈ interp-oper J f ∘ tuple (interp-ctx J) (oper-arity f) (λ i → hom-morphism ∘ π (interp-ctx I) i) infix 4 _⇒I_ -- The identity homomorphism id-I : ∀ {A : Interpretation} → A ⇒I A id-I {A} = let open Interpretation A in let open HomReasoning in let open Producted interp-sort in record { hom-morphism = id ; hom-commute = λ f → begin (id ∘ interp-oper f) ≈⟨ identityˡ ⟩ interp-oper f ≈˘⟨ identityʳ ⟩ (interp-oper f ∘ id) ≈˘⟨ refl⟩∘⟨ unique interp-ctx (λ i → identityʳ ○ ⟺ identityˡ) ⟩ (interp-oper f ∘ Product.Producted.tuple interp-ctx (oper-arity f) (λ i → id ∘ Product.Producted.π interp-ctx i)) ∎ } -- Compositon of homomorphisms _∘I_ : ∀ {A B C : Interpretation} → B ⇒I C → A ⇒I B → A ⇒I C _∘I_ {A} {B} {C} ϕ ψ = let open _⇒I_ in record { hom-morphism = hom-morphism ϕ ∘ hom-morphism ψ ; hom-commute = let open Interpretation in let open Producted in let open HomReasoning in λ f → begin (((hom-morphism ϕ) ∘ hom-morphism ψ) ∘ interp-oper A f) ≈⟨ assoc ⟩ (hom-morphism ϕ ∘ hom-morphism ψ ∘ interp-oper A f) ≈⟨ (refl⟩∘⟨ hom-commute ψ f) ⟩ (hom-morphism ϕ ∘ interp-oper B f ∘ tuple (interp-ctx B) (oper-arity f) (λ i → hom-morphism ψ ∘ π (interp-ctx A) i)) ≈˘⟨ assoc ⟩ ((hom-morphism ϕ ∘ interp-oper B f) ∘ tuple (interp-ctx B) (oper-arity f) (λ i → hom-morphism ψ ∘ π (interp-ctx A) i)) ≈⟨ (hom-commute ϕ f ⟩∘⟨refl) ⟩ ((interp-oper C f ∘ tuple (interp-ctx C) (oper-arity f) (λ i → hom-morphism ϕ ∘ π (interp-ctx B) i)) ∘ tuple (interp-ctx B) (oper-arity f) (λ i → hom-morphism ψ ∘ π (interp-ctx A) i)) ≈⟨ assoc ⟩ (interp-oper C f ∘ tuple (interp-ctx C) (oper-arity f) (λ i → hom-morphism ϕ ∘ π (interp-ctx B) i) ∘ tuple (interp-ctx B) (oper-arity f) (λ i → hom-morphism ψ ∘ π (interp-ctx A) i)) ≈⟨ (refl⟩∘⟨ ⟺ (∘-distribʳ-tuple (interp-sort C) (interp-ctx C))) ⟩ (interp-oper C f ∘ tuple (interp-ctx C) (oper-arity f) (λ x → (hom-morphism ϕ ∘ π (interp-ctx B) x) ∘ tuple (interp-ctx B) (oper-arity f) (λ i → hom-morphism ψ ∘ π (interp-ctx A) i))) ≈⟨ (refl⟩∘⟨ tuple-cong (interp-sort C) (interp-ctx C) λ i → assoc) ⟩ (interp-oper C f ∘ tuple (interp-ctx C) (oper-arity f) (λ z → hom-morphism ϕ ∘ π (interp-ctx B) z ∘ tuple (interp-ctx B) (oper-arity f) (λ i → hom-morphism ψ ∘ π (interp-ctx A) i))) ≈⟨ (refl⟩∘⟨ tuple-cong (interp-sort C) (interp-ctx C) λ i → refl⟩∘⟨ project (interp-ctx B)) ⟩ (interp-oper C f ∘ tuple (interp-ctx C) (oper-arity f) (λ z → hom-morphism ϕ ∘ hom-morphism ψ ∘ π (interp-ctx A) z)) ≈⟨ (refl⟩∘⟨ tuple-cong (interp-sort C) (interp-ctx C) λ i → sym-assoc) ⟩ (interp-oper C f ∘ tuple (interp-ctx C) (oper-arity f) (λ z → (hom-morphism ϕ ∘ hom-morphism ψ) ∘ π (interp-ctx A) z)) ∎}
44.379085
164
0.463328
52fb0b640dd57c3a2470a6c7df05fbe39b66db5b
2,021
agda
Agda
agda-stdlib/src/Reflection/Abstraction.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Reflection/Abstraction.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Reflection/Abstraction.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Abstractions used in the reflection machinery ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Reflection.Abstraction where open import Data.List.Base as List using (List) open import Data.Product using (_×_; _,_; uncurry; <_,_>) import Data.String as String open import Relation.Nullary import Relation.Nullary.Decidable as Dec open import Relation.Nullary.Product using (_×-dec_) open import Relation.Binary open import Relation.Binary.PropositionalEquality private variable A B : Set ------------------------------------------------------------------------ -- Re-exporting the builtins publically open import Agda.Builtin.Reflection public using (Abs) open Abs public -- Pattern synonyms ------------------------------------------------------------------------ -- Operations map : (A → B) → Abs A → Abs B map f (abs s x) = abs s (f x) ------------------------------------------------------------------------ -- Decidable equality abs-injective₁ : ∀ {i i′} {a a′ : A} → abs i a ≡ abs i′ a′ → i ≡ i′ abs-injective₁ refl = refl abs-injective₂ : ∀ {i i′} {a a′ : A} → abs i a ≡ abs i′ a′ → a ≡ a′ abs-injective₂ refl = refl abs-injective : ∀ {i i′} {a a′ : A} → abs i a ≡ abs i′ a′ → i ≡ i′ × a ≡ a′ abs-injective = < abs-injective₁ , abs-injective₂ > -- We often need decidability of equality for Abs A when implementing it -- for A. Unfortunately ≡-dec makes the termination checker unhappy. -- Instead, we can match on both Abs A and use unAbs-dec for an obviously -- decreasing recursive call. unAbs : Abs A → A unAbs (abs s a) = a unAbs-dec : {x y : Abs A} → Dec (unAbs x ≡ unAbs y) → Dec (x ≡ y) unAbs-dec {x = abs i a} {abs i′ a′} a≟a′ = Dec.map′ (uncurry (cong₂ abs)) abs-injective ((i String.≟ i′) ×-dec a≟a′) ≡-dec : Decidable {A = A} _≡_ → Decidable {A = Abs A} _≡_ ≡-dec _≟_ x y = unAbs-dec (unAbs x ≟ unAbs y)
31.578125
75
0.546759
38c5dfa21d8b2a495d67021aacf51e38fc9b1f73
263
agda
Agda
test/Succeed/Issue602-2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue602-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue602-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Record projections should be positive in their argument module Issue602-2 where record A : Set₁ where constructor mkA field f : Set unA : A → Set unA (mkA x) = x data B (a : A) : Set where mkB : unA a → B a data D : Set where d : B (mkA D) → D
15.470588
58
0.631179
43ca14ec597e30df0002bb96e55a214a4600ce3f
2,519
agda
Agda
agda-stdlib/src/Relation/Binary/Reasoning/Base/Partial.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Reasoning/Base/Partial.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Reasoning/Base/Partial.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- The basic code for equational reasoning with a partial relation ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Reasoning.Base.Partial {a ℓ} {A : Set a} (_∼_ : Rel A ℓ) (trans : Transitive _∼_) where open import Level using (_⊔_) open import Relation.Binary.PropositionalEquality.Core as P using (_≡_) infix 4 _IsRelatedTo_ infix 3 _∎⟨_⟩ infixr 2 step-∼ step-≡ step-≡˘ infixr 2 _≡⟨⟩_ infix 1 begin_ ------------------------------------------------------------------------ -- Definition of "related to" -- This seemingly unnecessary type is used to make it possible to -- infer arguments even if the underlying equality evaluates. data _IsRelatedTo_ (x y : A) : Set ℓ where relTo : (x∼y : x ∼ y) → x IsRelatedTo y ------------------------------------------------------------------------ -- Reasoning combinators -- Note that the arguments to the `step`s are not provided in their -- "natural" order and syntax declarations are later used to re-order -- them. This is because the `step` ordering allows the type-checker to -- better infer the middle argument `y` from the `_IsRelatedTo_` -- argument (see issue 622). -- -- This has two practical benefits. First it speeds up type-checking by -- approximately a factor of 5. Secondly it allows the combinators to be -- used with macros that use reflection, e.g. `Tactic.RingSolver`, where -- they need to be able to extract `y` using reflection. -- Beginning of a proof begin_ : ∀ {x y} → x IsRelatedTo y → x ∼ y begin relTo x∼y = x∼y -- Standard step with the relation step-∼ : ∀ x {y z} → y IsRelatedTo z → x ∼ y → x IsRelatedTo z step-∼ _ (relTo y∼z) x∼y = relTo (trans x∼y y∼z) -- Step with a non-trivial propositional equality step-≡ : ∀ x {y z} → y IsRelatedTo z → x ≡ y → x IsRelatedTo z step-≡ _ x∼z P.refl = x∼z -- Step with a flipped non-trivial propositional equality step-≡˘ : ∀ x {y z} → y IsRelatedTo z → y ≡ x → x IsRelatedTo z step-≡˘ _ x∼z P.refl = x∼z -- Step with a trivial propositional equality _≡⟨⟩_ : ∀ x {y} → x IsRelatedTo y → x IsRelatedTo y _ ≡⟨⟩ x∼y = x∼y -- Termination step _∎⟨_⟩ : ∀ x → x ∼ x → x IsRelatedTo x _ ∎⟨ x∼x ⟩ = relTo x∼x -- Syntax declarations syntax step-∼ x y∼z x∼y = x ∼⟨ x∼y ⟩ y∼z syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z syntax step-≡˘ x y≡z y≡x = x ≡˘⟨ y≡x ⟩ y≡z
30.349398
72
0.593092
8b15074431c491fede85aa9de504fb68ebc5bfab
748
agda
Agda
Cubical/Categories/Functor/BinProduct.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:00.000Z
2022-03-05T00:29:00.000Z
Cubical/Categories/Functor/BinProduct.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Categories/Functor/BinProduct.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
-- Product of two functors {-# OPTIONS --safe #-} module Cubical.Categories.Functor.BinProduct where open import Cubical.Categories.Category.Base open import Cubical.Categories.Constructions.BinProduct open import Cubical.Categories.Functor.Base open import Cubical.Data.Sigma.Properties open import Cubical.Foundations.Prelude private variable ℓA ℓA' ℓB ℓB' ℓC ℓC' ℓD ℓD' : Level A : Category ℓA ℓA' B : Category ℓB ℓB' C : Category ℓC ℓC' D : Category ℓD ℓD' open Functor _×F_ : Functor A C → Functor B D → Functor (A × B) (C × D) (G ×F H) .F-ob (a , b) = (G ⟅ a ⟆ , H ⟅ b ⟆) (G ×F H) .F-hom (g , h) = (G ⟪ g ⟫ , H ⟪ h ⟫) (G ×F H) .F-id = ≡-× (G .F-id) (H .F-id) (G ×F H) .F-seq _ _ = ≡-× (G .F-seq _ _) (H .F-seq _ _)
27.703704
58
0.624332
35c337cd42c463e91dfd7978f68e5f032bbe5251
708
agda
Agda
Dave/Algebra/Naturals/Excercises.agda
DavidStahl97/formal-proofs
05213fb6ab1f51f770f9858b61526ba950e06232
[ "MIT" ]
null
null
null
Dave/Algebra/Naturals/Excercises.agda
DavidStahl97/formal-proofs
05213fb6ab1f51f770f9858b61526ba950e06232
[ "MIT" ]
null
null
null
Dave/Algebra/Naturals/Excercises.agda
DavidStahl97/formal-proofs
05213fb6ab1f51f770f9858b61526ba950e06232
[ "MIT" ]
null
null
null
module Dave.Algebra.Naturals.Excercises where open import Dave.Algebra.Naturals.Addition +-rearrange : ∀ (m n p q : ℕ) → (m + n) + (p + q) ≡ m + (n + p) + q +-rearrange m n p q = begin (m + n) + (p + q) ≡⟨ IsSemigroup.assoc ℕ-+-IsSemigroup m n (p + q) ⟩ m + (n + (p + q)) ≡⟨ cong (λ a → m + a) (sym (IsSemigroup.assoc ℕ-+-IsSemigroup n p q)) ⟩ m + ((n + p) + q) ≡⟨ sym (IsSemigroup.assoc ℕ-+-IsSemigroup m (n + p) q) ⟩ (m + (n + p)) + q ∎ +-swap : ∀ (m n p : ℕ) → m + (n + p) ≡ n + (m + p) +-swap m n p = begin m + (n + p) ≡⟨ +-comm m (n + p) ⟩ (n + p) + m ≡⟨ IsSemigroup.assoc ℕ-+-IsSemigroup n p m ⟩ n + (p + m) ≡⟨ cong (λ a → n + a) (+-comm p m) ⟩ n + (m + p) ∎
44.25
93
0.468927
35027676887662ece77f97925ddd22452d8f2bef
2,161
agda
Agda
src/Examples/Sorting/Sequential.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
29
2021-07-14T03:18:28.000Z
2022-03-22T20:35:11.000Z
src/Examples/Sorting/Sequential.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
null
null
null
src/Examples/Sorting/Sequential.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
2
2021-10-06T10:28:24.000Z
2022-01-29T08:12:01.000Z
{-# OPTIONS --prop --rewriting #-} module Examples.Sorting.Sequential where open import Examples.Sorting.Sequential.Comparable open import Calf costMonoid open import Calf.Types.Nat open import Calf.Types.List open import Relation.Binary.PropositionalEquality as Eq using (_≡_) open import Data.Product using (_,_) test/forward = 1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ 6 ∷ 7 ∷ 8 ∷ 9 ∷ 10 ∷ 11 ∷ 12 ∷ 13 ∷ 14 ∷ 15 ∷ 16 ∷ [] test/backward = 16 ∷ 15 ∷ 14 ∷ 13 ∷ 12 ∷ 11 ∷ 10 ∷ 9 ∷ 8 ∷ 7 ∷ 6 ∷ 5 ∷ 4 ∷ 3 ∷ 2 ∷ 1 ∷ [] test/shuffled = 4 ∷ 8 ∷ 12 ∷ 16 ∷ 13 ∷ 3 ∷ 5 ∷ 14 ∷ 9 ∷ 6 ∷ 7 ∷ 10 ∷ 11 ∷ 1 ∷ 2 ∷ 15 ∷ [] module Ex/InsertionSort where import Examples.Sorting.Sequential.InsertionSort NatComparable as Sort list' = list nat ex/insert : cmp (F list') ex/insert = Sort.insert 3 (1 ∷ 2 ∷ 4 ∷ []) ex/sort : cmp (F list') ex/sort = Sort.sort (1 ∷ 5 ∷ 3 ∷ 1 ∷ 2 ∷ []) ex/sort/forward : cmp (F list') ex/sort/forward = Sort.sort test/forward -- cost: 15 ex/sort/backward : cmp (F list') ex/sort/backward = Sort.sort test/backward -- cost: 120 ex/sort/shuffled : cmp (F list') ex/sort/shuffled = Sort.sort test/shuffled -- cost: 76 module Ex/MergeSort where import Examples.Sorting.Sequential.MergeSort NatComparable as Sort list' = list nat ex/split : cmp (F Sort.pair) ex/split = Sort.split (6 ∷ 2 ∷ 8 ∷ 3 ∷ 1 ∷ 8 ∷ 5 ∷ []) ex/merge : cmp (F list') ex/merge = Sort.merge (2 ∷ 3 ∷ 6 ∷ 8 ∷ [] , 1 ∷ 5 ∷ 8 ∷ []) ex/sort : cmp (F list') ex/sort = Sort.sort (1 ∷ 5 ∷ 3 ∷ 1 ∷ 2 ∷ []) ex/sort/forward : cmp (F list') ex/sort/forward = Sort.sort test/forward -- cost: 32 ex/sort/backward : cmp (F list') ex/sort/backward = Sort.sort test/backward -- cost: 32 ex/sort/shuffled : cmp (F list') ex/sort/shuffled = Sort.sort test/shuffled -- cost: 47 module SortEquivalence (M : Comparable) where open Comparable M open import Examples.Sorting.Sequential.Core M import Examples.Sorting.Sequential.InsertionSort M as ISort import Examples.Sorting.Sequential.MergeSort M as MSort isort≡msort : ◯ (ISort.sort ≡ MSort.sort) isort≡msort = IsSort⇒≡ ISort.sort ISort.sort/correct MSort.sort MSort.sort/correct
30.871429
89
0.641832
4368c2d93a82ffb71f189744f0a36e8af85a370d
2,168
agda
Agda
src/CF/Transform/UnCo.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
6
2020-10-07T14:07:17.000Z
2021-02-28T21:49:08.000Z
src/CF/Transform/UnCo.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
null
null
null
src/CF/Transform/UnCo.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
1
2021-12-28T17:37:15.000Z
2021-12-28T17:37:15.000Z
{-# OPTIONS --no-qualified-instances #-} module CF.Transform.UnCo where open import Data.Product open import Data.List open import Data.List.Relation.Unary.All open import Data.List.Membership.Propositional open import Relation.Unary hiding (_∈_) open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax open import Relation.Ternary.Monad hiding (unit) open import Relation.Ternary.Monad.Weakening open import Relation.Ternary.Data.Bigstar hiding ([_]) open import CF.Types open import CF.Syntax.Hoisted as Hoisted open import CF.Contexts.Lexical open import CF.Transform.Hoist open import CF.Syntax.DeBruijn as Tgt open Hoisted open import Relation.Ternary.Data.Allstar Ty {-# TERMINATING #-} mutual uncoₑ : ∀[ Hoisted.Exp a ⇑ ⇒ Tgt.Exp a ] uncoₑ (unit ⇈ wk) = unit uncoₑ (num x ⇈ wk) = num x uncoₑ (bool x ⇈ wk) = bool x uncoₑ (Exp.var' vars ⇈ wk) = Tgt.var' (member wk) uncoₑ (bop f e₁✴e₂ ⇈ wk) with e₁ , e₂ ← unstar (e₁✴e₂ ⇈ wk) = bop f (uncoₑ e₁) (uncoₑ e₂) uncoₑ (ifthenelse c✴e₁✴e₂ ⇈ wk) = let c , e₁✴e₂ = unstar (c✴e₁✴e₂ ⇈ wk) e₁ , e₂ = unstar e₁✴e₂ in ifthenelse (uncoₑ c) (uncoₑ e₁) (uncoₑ e₂) uncos : ∀[ (Allstar Hoisted.Exp as) ⇑ ⇒ Exps as ] uncos (nil ⇈ wk) = [] uncos (cons e✴es ⇈ wk) with e , es ← unstar (e✴es ⇈ wk) = uncoₑ e ∷ uncos es {-# TERMINATING #-} mutual uncoₛ : ∀[ Hoisted.Stmt r ⇑ ⇒ Tgt.Stmt r ] uncoₛ (run x ⇈ wk) = run (uncoₑ (x ⇈ wk)) uncoₛ (asgn v✴e ⇈ wk) with unstar (v✴e ⇈ wk) ... | vars ⇈ wk' , e⇑ = asgn (member wk') (uncoₑ e⇑) uncoₛ (ifthenelse c✴s₁✴s₂ ⇈ wk) = let c , s₁✴s₂ = unstar (c✴s₁✴s₂ ⇈ wk) s₁ , s₂ = unstar s₁✴s₂ in ifthenelse (uncoₑ c) (uncoₛ s₁) (uncoₛ s₂) uncoₛ (while c✴s ⇈ wk) with c , s ← unstar (c✴s ⇈ wk) = while (uncoₑ c) (uncoₛ s) uncoₛ (block x ⇈ wk) = block (unco' (x ⇈ wk)) unco' : ∀[ Hoisted.Block r ⇑ ⇒ Tgt.Block r ] unco' (nil ⇈ wk) = nil unco' (cons s✴b ⇈ wk) with s , b ← unstar (s✴b ⇈ wk) = uncoₛ s ⍮⍮ unco' b unco : ∀[ Hoisted.Block r ⇒ Tgt.Block r ] unco bl = unco' (return bl)
34.412698
91
0.647601
30b18ad32d8425e29a64eefc59683d05ccd84a0e
2,363
agda
Agda
lib/Univalence.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
lib/Univalence.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/Univalence.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Base open import lib.PathGroupoid open import lib.PathFunctor open import lib.Equivalences open import lib.PathOver module lib.Univalence where {- The map [coe-equiv] is the map which is supposed to be an equivalence according to the univalence axiom. We do not define it directly by path induction because it may be helpful to know definitionally what are the components. -} coe-equiv : ∀ {i} {A B : Type i} → A == B → A ≃ B coe-equiv p = (coe p , record { g = coe! p ; f-g = coe!-inv-r p ; g-f = coe!-inv-l p ; adj = coe-inv-adj p }) {- We postulate the univalence axiom as three separate axioms because it’s more natural this way. But it doesn’t change anything in practice. -} postulate -- Univalence axiom ua : ∀ {i} {A B : Type i} → (A ≃ B) → A == B coe-equiv-β : ∀ {i} {A B : Type i} (e : A ≃ B) → coe-equiv (ua e) == e ua-η : ∀ {i} {A B : Type i} (p : A == B) → ua (coe-equiv p) == p ua-equiv : ∀ {i} {A B : Type i} → (A ≃ B) ≃ (A == B) ua-equiv = equiv ua coe-equiv ua-η coe-equiv-β {- Reductions for coercions along a path constructed with the univalence axiom -} coe-β : ∀ {i} {A B : Type i} (e : A ≃ B) (a : A) → coe (ua e) a == –> e a coe-β e a = ap (λ e → –> e a) (coe-equiv-β e) coe!-β : ∀ {i} {A B : Type i} (e : A ≃ B) (b : B) → coe! (ua e) b == <– e b coe!-β e a = ap (λ e → <– e a) (coe-equiv-β e) {- Paths over a path in a universe in the identity fibration reduces -} ↓-idf-ua-out : ∀ {i} {A B : Type i} (e : A ≃ B) {u : A} {v : B} → u == v [ (λ x → x) ↓ (ua e) ] → –> e u == v ↓-idf-ua-out e p = ! (coe-β e _) ∙ ↓-idf-out (ua e) p ↓-idf-ua-in : ∀ {i} {A B : Type i} (e : A ≃ B) {u : A} {v : B} → –> e u == v → u == v [ (λ x → x) ↓ (ua e) ] ↓-idf-ua-in e p = ↓-idf-in (ua e) (coe-β e _ ∙ p) {- Induction along equivalences If [P] is a predicate over all equivalences in a universe [Type i] and [d] is a proof of [P] over all [ide A], then we get a section of [P] -} equiv-induction : ∀ {i j} (P : {A B : Type i} (f : A ≃ B) → Type j) (d : (A : Type i) → P (ide A)) {A B : Type i} (f : A ≃ B) → P f equiv-induction {i} {j} P d f = transport P (coe-equiv-β f) (aux P d (ua f)) where aux : ∀ {j} (P : {A : Type i} {B : Type i} (f : A ≃ B) → Type j) (d : (A : Type i) → P (ide A)) {A B : Type i} (p : A == B) → P (coe-equiv p) aux P d idp = d _
34.246377
109
0.550571
3d5a868e76ab16a47cea9d9463021c089a04dcfd
302
agda
Agda
test/Fail/SizedTypesRigidVarClash.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/SizedTypesRigidVarClash.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/SizedTypesRigidVarClash.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --sized-types #-} module SizedTypesRigidVarClash where open import Common.Size renaming (↑_ to _^) data Nat : {size : Size} -> Set where zero : {size : Size} -> Nat {size ^} suc : {size : Size} -> Nat {size} -> Nat {size ^} inc : {i j : Size} -> Nat {i} -> Nat {j ^} inc x = suc x
23.230769
52
0.57947
35e2ef4c74a0a13d563525fe1ee3b927cb1a0934
12,928
agda
Agda
AAOSL/Abstract/EvoCR.agda
LaudateCorpus1/aaosl-agda
318881fb24af06bbaafa33edeea0745eca1873f0
[ "UPL-1.0" ]
9
2020-12-22T00:01:00.000Z
2022-03-31T10:16:38.000Z
AAOSL/Abstract/EvoCR.agda
LaudateCorpus1/aaosl-agda
318881fb24af06bbaafa33edeea0745eca1873f0
[ "UPL-1.0" ]
5
2021-01-04T03:45:34.000Z
2021-02-12T04:16:40.000Z
AAOSL/Abstract/EvoCR.agda
LaudateCorpus1/aaosl-agda
318881fb24af06bbaafa33edeea0745eca1873f0
[ "UPL-1.0" ]
3
2020-12-22T00:01:03.000Z
2022-02-18T04:33:50.000Z
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0. Copyright (c) 2021 Victor C Miraldo and 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 Data.Unit.NonEta open import Data.Empty open import Data.Sum open import Data.Product open import Data.Product.Properties open import Data.Fin hiding (_<_; _≤_) open import Data.Fin.Properties using () renaming (_≟_ to _≟Fin_) open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_) open import Data.Nat.Properties open import Data.List renaming (map to List-map) open import Data.List.Properties using (∷-injective; length-map) open import Data.List.Relation.Unary.Any renaming (map to Any-map) open import Data.List.Relation.Unary.All renaming (lookup to All-lookup; map to All-map) open import Data.List.Relation.Unary.All.Properties hiding (All-map) open import Data.List.Relation.Unary.Any.Properties renaming (map⁺ to Any-map⁺) open import Data.List.Relation.Binary.Pointwise using (decidable-≡) open import Data.Bool hiding (_<_; _≤_) open import Data.Maybe renaming (map to Maybe-map) open import Function open import Relation.Binary.PropositionalEquality open import Relation.Binary.Definitions open import Relation.Nullary open import AAOSL.Lemmas open import AAOSL.Abstract.Hash open import AAOSL.Abstract.DepRel module AAOSL.Abstract.EvoCR -- A Hash function maps a bytestring into a hash. (hash : ByteString → Hash) -- And is collision resistant (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) -- Indexes can be encoded in an injective way (encodeI : ℕ → ByteString) (encodeI-inj : (m n : ℕ) → encodeI m ≡ encodeI n → m ≡ n) (dep : DepRel) where open WithCryptoHash hash hash-cr open import AAOSL.Abstract.Advancement hash hash-cr encodeI encodeI-inj dep open DepRel dep -- Returns the last element on path a that is smaller than k last-bef : ∀{j i k}(a : AdvPath j i)(i<k : i < k)(k≤j : k ≤′ j) → ℕ last-bef {j} a i<k ≤′-refl = j -- TODO-1 : The same or similar proof is repeated numerous times below; refactor for clarity last-bef AdvDone i<k (≤′-step k≤j) = ⊥-elim (1+n≰n (≤-unstep (≤-trans i<k (≤′⇒≤ k≤j)))) last-bef {k = k} (AdvThere d h a) i<k (≤′-step k≤j) with hop-tgt h ≤?ℕ k ...| yes th≤k = hop-tgt h ...| no th>k = last-bef a i<k (≤⇒≤′ (≰⇒≥ th>k)) last-bef-correct : ∀{j i k}(a : AdvPath j i)(i<k : i < k)(k≤j : k ≤′ j) → last-bef a i<k k≤j ∈AP a last-bef-correct {j} a i<k ≤′-refl = ∈AP-src last-bef-correct AdvDone i<k (≤′-step k≤j) = ⊥-elim (1+n≰n (≤-unstep (≤-trans i<k (≤′⇒≤ k≤j)))) last-bef-correct {k = k} (AdvThere d h a) i<k (≤′-step k≤j) with hop-tgt h ≤?ℕ k ...| yes th≤k = step (<⇒≢ (hop-< h)) ∈AP-src ...| no th>k with last-bef-correct a i<k (≤⇒≤′ (≰⇒≥ th>k)) ...| ind = step (<⇒≢ (≤-trans (s≤s (∈AP-≤ ind)) (hop-< h))) ind lemma5-hop : ∀{j i}(a : AdvPath j i) → ∀{k} → j < k → (h : HopFrom k) → hop-tgt h ≤ j → i ≤ hop-tgt h → hop-tgt h ∈AP a lemma5-hop {j} a j<k h th≤j i≤th with hop-tgt h ≟ℕ j ...| yes th≡j rewrite th≡j = ∈AP-src ...| no th≢j with a ...| AdvDone rewrite ≤-antisym th≤j i≤th = hereTgtDone ...| (AdvThere x h' a') with hop-tgt h' ≟ℕ hop-tgt h ...| yes th'≡th rewrite sym th'≡th = step (<⇒≢ (hop-< h')) ∈AP-src ...| no th'≢th with hop-tgt h' ≤?ℕ hop-tgt h ...| yes th'≤th = ⊥-elim (1+n≰n (≤-trans j<k (hops-nested-or-nonoverlapping (≤∧≢⇒< th'≤th th'≢th) (≤∧≢⇒< th≤j th≢j)))) ...| no th'>th = step th≢j (lemma5-hop a' (≤-trans (hop-< h') (≤-unstep j<k)) h (≰⇒≥ th'>th) i≤th) lemma5 : ∀{j i k}(a : AdvPath j i)(i<k : i < k)(k≤j : k ≤′ j) → ∀{i₀}(b : AdvPath k i₀) → i₀ ≤ i → last-bef a i<k k≤j ∈AP b lemma5 a i<k ≤′-refl b i₀≤i = ∈AP-src lemma5 AdvDone i<k (≤′-step k≤j) b i₀≤i = ⊥-elim (1+n≰n (≤-unstep (≤-trans i<k (≤′⇒≤ k≤j)))) lemma5 {k = k} (AdvThere d h a) i<k (≤′-step k≤j) b i₀≤i with hop-tgt h ≤?ℕ k ...| yes th≤k = lemma5-hop b (s≤s (≤′⇒≤ k≤j)) h th≤k (≤-trans i₀≤i (lemma1 a)) ...| no th>k = lemma5 a i<k (≤⇒≤′ (≰⇒≥ th>k)) b i₀≤i -- returns the first element on path a that is greather than k first-aft : ∀{j i k}(a : AdvPath j i)(i≤k : i ≤′ k)(k<j : k < j) → ℕ first-aft {i = i} a ≤′-refl k<j = i first-aft AdvDone (≤′-step i≤k) k<j = ⊥-elim (1+n≰n (≤-unstep (≤-trans k<j (≤′⇒≤ i≤k)))) first-aft {j} {i} {k} (AdvThere d h a) (≤′-step i≤k) k<j with hop-tgt h ≟ℕ k ...| yes _ = k ...| no th≢k with hop-tgt h ≤?ℕ k ...| yes th≤k = j ...| no th≥k = first-aft a (≤′-step i≤k) (≰⇒> th≥k) first-aft-correct : ∀{j i k}(a : AdvPath j i)(i≤k : i ≤′ k)(k<j : k < j) → first-aft a i≤k k<j ∈AP a first-aft-correct a ≤′-refl k<j = ∈AP-tgt first-aft-correct AdvDone (≤′-step i≤k) k<j = ⊥-elim (1+n≰n (≤-unstep (≤-trans k<j (≤′⇒≤ i≤k)))) first-aft-correct {j} {i} {k} (AdvThere d h a) (≤′-step i≤k) k<j with hop-tgt h ≟ℕ k ...| yes th≡k rewrite sym th≡k = step (<⇒≢ k<j) ∈AP-src ...| no th≢k with hop-tgt h ≤?ℕ k ...| yes th≤k = ∈AP-src ...| no th≥k with first-aft-correct a (≤′-step i≤k) (≰⇒> th≥k) ...| ind = step (<⇒≢ (≤-trans (s≤s (∈AP-≤ ind)) (hop-< h))) ind lemma5'-hop : ∀{j j₁ k}(h : HopFrom j) → hop-tgt h < k → k < j → (b : AdvPath j₁ k) → j ≤ j₁ → j ∈AP b lemma5'-hop {j} {j₁} h th<k k≤j b j≤j₁ with j ≟ℕ j₁ ...| yes refl = ∈AP-src ...| no j≢j₁ with b ...| AdvDone = ⊥-elim (1+n≰n (≤-trans k≤j j≤j₁)) ...| (AdvThere x hb b') with hop-tgt hb ≟ℕ j ...| yes refl = step (<⇒≢ (hop-< hb)) ∈AP-src ...| no tb≢j with hop-tgt hb ≤?ℕ j ...| no tb≰j = step j≢j₁ (lemma5'-hop h th<k k≤j b' (≰⇒≥ tb≰j)) ...| yes tb≤j with hops-nested-or-nonoverlapping (≤-trans th<k (lemma1 b')) (≤∧≢⇒< tb≤j tb≢j) ...| j₁≤j rewrite ≤-antisym j≤j₁ j₁≤j = ∈AP-src lemma5' : ∀{j i k}(a : AdvPath j i)(i≤k : i ≤′ k)(k<j : k < j) → ∀{j₁}(b : AdvPath j₁ k) → j ≤ j₁ → first-aft a i≤k k<j ∈AP b lemma5' a ≤′-refl k<j b j≤j₁ = ∈AP-tgt lemma5' AdvDone (≤′-step i≤k) k<j b j≤j₁ = ⊥-elim (1+n≰n (≤-unstep (≤-trans k<j (≤′⇒≤ i≤k)))) lemma5' {j} {i} {k} (AdvThere d h a) (≤′-step i≤k) k<j b j≤j₁ with hop-tgt h ≟ℕ k ...| yes _ = ∈AP-tgt ...| no th≢k with hop-tgt h ≤?ℕ k ...| yes th≤k = lemma5'-hop h (≤∧≢⇒< th≤k th≢k) k<j b j≤j₁ ...| no th≥k = lemma5' a (≤′-step i≤k) (≰⇒> th≥k) b (≤-unstep (≤-trans (hop-< h) j≤j₁)) ∈AP-⊕-intro-l : ∀{j k i m} → {a₂ : AdvPath j k}{a₁ : AdvPath k i} → m ∈AP a₂ → m ∈AP (a₂ ⊕ a₁) ∈AP-⊕-intro-l hereTgtThere = hereTgtThere ∈AP-⊕-intro-l (step prog m∈a) = step prog (∈AP-⊕-intro-l m∈a) ∈AP-⊕-intro-l {a₁ = AdvDone} hereTgtDone = hereTgtDone ∈AP-⊕-intro-l {a₁ = AdvThere d h a} hereTgtDone = hereTgtThere ∈AP-⊕-intro-r : ∀{j k i m} → {a₂ : AdvPath j k}{a₁ : AdvPath k i} → m ∈AP a₁ → m ∈AP (a₂ ⊕ a₁) ∈AP-⊕-intro-r {a₂ = AdvDone} hyp = hyp ∈AP-⊕-intro-r {k = k} {a₂ = AdvThere d h a} hyp = step (<⇒≢ (≤-trans (s≤s (∈AP-≤ hyp)) (≤-trans (s≤s (lemma1 a)) (hop-< h)))) (∈AP-⊕-intro-r {a₂ = a} hyp) ∈AP-⊕-≤-r : ∀{j k i m}{a₂ : AdvPath j k}{a₁ : AdvPath k i} → m ∈AP (a₂ ⊕ a₁) → m ≤ k → m ∈AP a₁ ∈AP-⊕-≤-r {a₂ = AdvDone} m∈a12 m≤k = m∈a12 ∈AP-⊕-≤-r {a₂ = AdvThere d h a₂} hereTgtThere m≤k = ⊥-elim (1+n≰n (≤-trans (≤-trans (s≤s (lemma1 a₂)) (hop-< h)) m≤k)) ∈AP-⊕-≤-r {a₂ = AdvThere d h a₂} (step x m∈a12) m≤k = ∈AP-⊕-≤-r m∈a12 m≤k findM : ∀ {j i₂ s₁ s₂ tgt} → (a₁₁ : AdvPath j s₁) → (a₂₁ : AdvPath j s₂) → (a₂₂ : AdvPath s₂ i₂) → (m₂ : MembershipProof s₂ tgt) → i₂ ≤ s₁ → tgt ≤ s₁ → s₁ ≤ s₂ → ∃[ M ] (M ∈AP a₂₂ × M ∈AP mbr-proof m₂ × M ∈AP a₁₁) findM {s₁ = s₁} {s₂} a₁₁ a₂₁ a₂₂ m₂ i₂≤s₁ t≤s₁ s₁≤s₂ with <-cmp s₁ s₂ ...| tri> _ _ s₂<s₁ = ⊥-elim (<⇒≢ s₂<s₁ (sym (≤-antisym s₁≤s₂ (≤-unstep s₂<s₁)))) ...| tri≈ _ refl _ = s₁ , ∈AP-src , ∈AP-src , ∈AP-tgt ...| tri< s₁<s₂ _ _ = last-bef a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) , lemma5 a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) a₂₂ i₂≤s₁ , lemma5 a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) (mbr-proof m₂) t≤s₁ , last-bef-correct a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) findR : ∀{j i₁ s₁ s₂ tgt} → (a₁₁ : AdvPath j s₁) → (a₁₂ : AdvPath s₁ i₁) → (a₂₁ : AdvPath j s₂) → (m₁ : MembershipProof s₁ tgt)(m₂ : MembershipProof s₂ tgt) → i₁ ≤ tgt → tgt ≤ s₁ → s₁ ≤ s₂ -- wlog → ∃[ R ] (R ∈AP mbr-proof m₁ × R ∈AP mbr-proof m₂ × R ∈AP a₁₂) findR {s₁ = s₁} {tgt = tgt} a₁₁ a₁₂ a₂₁ m₁ m₂ i₁≤t t≤s₁ s₁≤s₂ with <-cmp tgt s₁ ...| tri> _ _ s₁<t = ⊥-elim (<⇒≢ s₁<t (sym (≤-antisym t≤s₁ (≤-unstep s₁<t)))) ...| tri≈ _ refl _ = s₁ , ∈AP-src , ∈AP-tgt , ∈AP-src ...| tri< t<s₁ _ _ = first-aft a₁₂ (≤⇒≤′ i₁≤t) t<s₁ , lemma5' a₁₂ (≤⇒≤′ i₁≤t) t<s₁ (mbr-proof m₁) ≤-refl , lemma5' a₁₂ (≤⇒≤′ i₁≤t) t<s₁ (mbr-proof m₂) s₁≤s₂ , first-aft-correct a₁₂ (≤⇒≤′ i₁≤t) t<s₁ -- check Figure 4 (page 12) in: https://arxiv.org/pdf/cs/0302010.pdf -- -- a₁ is dashed black line -- a₂ is dashed gray line -- m₁ is thick black line -- m₂ is thick gray line -- s₁ is j -- s₂ is k -- j is n -- tgt is i evo-cr : ∀{j i₁ i₂}{t₁ t₂ : View} → (a₁ : AdvPath j i₁) → (a₂ : AdvPath j i₂) → rebuild a₁ t₁ j ≡ rebuild a₂ t₂ j → ∀{s₁ s₂ tgt}{u₁ u₂ : View} → (m₁ : MembershipProof s₁ tgt)(m₂ : MembershipProof s₂ tgt) → s₁ ∈AP a₁ → s₂ ∈AP a₂ → s₁ ≤ s₂ -- wlog → i₁ ≤ tgt → i₂ ≤ tgt → rebuildMP m₁ u₁ s₁ ≡ rebuild a₁ t₁ s₁ → rebuildMP m₂ u₂ s₂ ≡ rebuild a₂ t₂ s₂ → HashBroke ⊎ (mbr-datum m₁ ≡ mbr-datum m₂) evo-cr {t₁ = t₁} {t₂} a₁ a₂ hyp {s₁} {s₂} {tgt} {u₁} {u₂} m₁ m₂ s₁∈a₁ s₂∈a₂ s₁≤s₂ i₁≤t i₂≤t c₁ c₂ with ∈AP-cut a₁ s₁∈a₁ | ∈AP-cut a₂ s₂∈a₂ ...| ((a₁₁ , a₁₂) , refl) | ((a₂₁ , a₂₂) , refl) with lemma1 (mbr-proof m₁) ...| t≤s₁ -- The first part of the proof is find some points common to three -- of the provided proofs. This is given in Figure 4 of Maniatis and Baker, -- and they are called M and R too, to help make it at least a little clear. -- First we find a point that belongs in a₂, m₁ and a₁. with findM a₁₁ a₂₁ a₂₂ m₂ (≤-trans i₂≤t t≤s₁) t≤s₁ s₁≤s₂ ...| M , M∈a₂₂ , M∈m₂ , M∈a₁₁ -- Next, we find a point that belongs in m₁, m₂ and a₁. with findR a₁₁ a₁₂ a₂₁ m₁ m₂ i₁≤t t≤s₁ s₁≤s₂ ...| R , R∈m₁ , R∈m₂ , R∈a₁₂ -- Now, since a₁ and a₂ rebuild to the same hash and M belongs -- to both these proofs, the hash for M is the same. with AgreeOnCommon a₁ a₂ hyp (∈AP-⊕-intro-l M∈a₁₁) (∈AP-⊕-intro-r M∈a₂₂) ...| inj₁ hb = inj₁ hb ...| inj₂ M-a1a2 -- Similarly, for a₂₂ and m₂ with AgreeOnCommon a₂₂ (mbr-proof m₂) (trans (sym (rebuild-⊕ a₂₁ a₂₂ ∈AP-src)) (sym c₂)) M∈a₂₂ M∈m₂ ...| inj₁ hb = inj₁ hb ...| inj₂ M-a22m2 -- Which brings us to: rebuild a1 M == rebuild m2 M with trans (trans M-a1a2 (rebuild-⊕ a₂₁ a₂₂ M∈a₂₂)) M-a22m2 ...| M-a1m2 -- If a1 and m2 agree on one point, they agree on all points. In particular, they -- agree on R! with ∈AP-cut (mbr-proof m₂) M∈m₂ ...| ((m₂₁ , m₂₂) , refl) with trans M-a1m2 (rebuild-⊕ m₂₁ m₂₂ ∈AP-src) ...| M-a1m22 with AgreeOnCommon-∈ a₁ m₂₂ (∈AP-⊕-intro-l M∈a₁₁) M-a1m22 (∈AP-⊕-intro-r R∈a₁₂) (∈AP-⊕-≤-r R∈m₂ (≤-trans (∈AP-≤ R∈a₁₂) (∈AP-≥ M∈a₁₁))) ...| inj₁ hb = inj₁ hb ...| inj₂ R-a1m22 with AgreeOnCommon a₁₂ (mbr-proof m₁) (trans (sym (rebuild-⊕ a₁₁ a₁₂ ∈AP-src)) (sym c₁)) R∈a₁₂ R∈m₁ ...| inj₁ hb = inj₁ hb ...| inj₂ R-a12m1 -- Which finally lets us argue that m1 and m2 also agree on R. Similarly, if they agree -- on one point they agree on all points. with ∈AP-cut (mbr-proof m₁) R∈m₁ ...| ((m₁₁ , m₁₂) , refl) with trans (trans (trans (sym R-a1m22) (rebuild-⊕ a₁₁ a₁₂ R∈a₁₂)) R-a12m1) (rebuild-⊕ m₁₁ m₁₂ ∈AP-src) ...| R-m22m12 with AgreeOnCommon-∈ m₂₂ m₁₂ (∈AP-⊕-≤-r R∈m₂ (≤-trans (∈AP-≤ R∈a₁₂) (∈AP-≥ M∈a₁₁))) R-m22m12 ∈AP-tgt ∈AP-tgt ...| inj₁ hb = inj₁ hb ...| inj₂ tgt-m22m12 with trans (trans (rebuild-⊕ m₁₁ m₁₂ ∈AP-tgt) (sym tgt-m22m12)) (sym (rebuild-⊕ m₂₁ m₂₂ ∈AP-tgt)) ...| tgt-m1m2 with rebuild-tgt-lemma (mbr-proof m₁) {u₁ ∪₁ (tgt , auth tgt (mbr-datum m₁) u₁) } | rebuild-tgt-lemma (mbr-proof m₂) {u₂ ∪₁ (tgt , auth tgt (mbr-datum m₂) u₂) } ...| l1 | l2 with trans (sym l1) (trans tgt-m1m2 l2) ...| auths≡ rewrite ≟ℕ-refl tgt = auth-inj-1 {tgt} {mbr-datum m₁} {mbr-datum m₂} (mbr-not-init m₁) auths≡
42.526316
120
0.540996
5e08f17255e7c09dfd22a05adc344f78c12712ac
741
agda
Agda
test/Test/Compile/Golden/reachability/reachability-output.agda
vehicle-lang/vehicle
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
[ "BSD-3-Clause" ]
9
2022-02-10T12:56:42.000Z
2022-02-17T18:51:05.000Z
test/Test/Compile/Golden/reachability/reachability-output.agda
vehicle-lang/vehicle
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
[ "BSD-3-Clause" ]
19
2022-03-07T14:09:13.000Z
2022-03-31T20:49:39.000Z
test/Test/Compile/Golden/reachability/reachability-output.agda
vehicle-lang/vehicle
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
[ "BSD-3-Clause" ]
null
null
null
-- WARNING: This file was generated automatically by Vehicle -- and should not be modified manually! -- Metadata -- - Agda version: 2.6.2 -- - AISEC version: 0.1.0.1 -- - Time generated: ??? {-# OPTIONS --allow-exec #-} open import Vehicle open import Vehicle.Data.Tensor open import Data.Product open import Data.Integer as ℤ using (ℤ) open import Data.Rational as ℚ using (ℚ) open import Data.List open import Relation.Binary.PropositionalEquality module reachability-temp-output where postulate f : Tensor ℚ (2 ∷ []) → Tensor ℚ (1 ∷ []) abstract reachable : ∃ λ (x : Tensor ℚ (2 ∷ [])) → f x ≡ ℤ.+ 0 ℚ./ 1 ∷ [] reachable = checkSpecification record { proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp" }
28.5
71
0.689609
354d18f10f2f45c5e02d90efde17b9395ee02018
11,240
agda
Agda
src/Partiality-algebra.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
2
2020-05-21T22:59:18.000Z
2020-07-03T08:56:08.000Z
src/Partiality-algebra.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
src/Partiality-algebra.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Partiality algebras ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} module Partiality-algebra where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (id; T) renaming (_∘_ to _⊚_) open import Bijection equality-with-J as Bijection using (_↔_) open import Equivalence equality-with-J as Eq using (_≃_) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import Univalence-axiom equality-with-J ------------------------------------------------------------------------ -- Partiality algebras -- Partiality algebras for certain universe levels and types, with a -- certain underlying type (T). record Partiality-algebra-with {a p} (T : Type p) q (A : Type a) : Type (a ⊔ p ⊔ lsuc q) where -- A binary relation on the type. infix 4 _⊑_ _⊒_ field _⊑_ : T → T → Type q _⊒_ : T → T → Type q _⊒_ x y = y ⊑ x -- Increasing sequences. Increasing-sequence : Type (p ⊔ q) Increasing-sequence = ∃ λ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n) -- Projection functions for Increasing-sequence. infix 30 _[_] _[_] : Increasing-sequence → ℕ → T _[_] s n = proj₁ s n increasing : (s : Increasing-sequence) → ∀ n → (s [ n ]) ⊑ (s [ suc n ]) increasing = proj₂ -- Upper bounds. Is-upper-bound : Increasing-sequence → T → Type q Is-upper-bound s x = ∀ n → (s [ n ]) ⊑ x field -- T "constructors". never : T now : A → T ⨆ : Increasing-sequence → T antisymmetry : ∀ {x y} → x ⊑ y → y ⊑ x → x ≡ y -- We have chosen to explicitly make the type set-truncated. -- However, this "constructor" is not used anywhere in the -- development (except when partiality algebras are modified, see -- for instance equality-characterisation-Partiality-algebra-with₁ -- or Partiality-algebra.Pi.Π-with). T-is-set-unused : Is-set T -- _⊑_ "constructors". ⊑-refl : ∀ x → x ⊑ x ⊑-trans : ∀ {x y z} → x ⊑ y → y ⊑ z → x ⊑ z never⊑ : ∀ x → never ⊑ x upper-bound : ∀ s → Is-upper-bound s (⨆ s) least-upper-bound : ∀ s ub → Is-upper-bound s ub → ⨆ s ⊑ ub ⊑-propositional : ∀ {x y} → Is-proposition (x ⊑ y) ---------------------------------------------------------------------- -- Some simple consequences private -- A lemma. T-is-set-and-equality-characterisation : Is-set T × _ T-is-set-and-equality-characterisation = Eq.propositional-identity≃≡ (λ x y → x ⊑ y × y ⊑ x) (λ _ _ → ×-closure 1 ⊑-propositional ⊑-propositional) (λ x → ⊑-refl x , ⊑-refl x) (λ x y → uncurry {B = λ _ → y ⊑ x} antisymmetry) -- T is a set. (This lemma is analogous to Theorem 11.3.9 in -- "Homotopy Type Theory: Univalent Foundations of Mathematics" -- (first edition).) T-is-set : Is-set T T-is-set = proj₁ T-is-set-and-equality-characterisation -- Equality characterisation lemma for T. equality-characterisation-T : ∀ {x y} → (x ⊑ y × y ⊑ x) ≃ (x ≡ y) equality-characterisation-T = proj₂ T-is-set-and-equality-characterisation ext -- Equality characterisation lemma for increasing sequences. equality-characterisation-increasing : ∀ {s₁ s₂} → (∀ n → s₁ [ n ] ≡ s₂ [ n ]) ↔ s₁ ≡ s₂ equality-characterisation-increasing {s₁} {s₂} = (∀ n → s₁ [ n ] ≡ s₂ [ n ]) ↔⟨ Eq.extensionality-isomorphism bad-ext ⟩ proj₁ s₁ ≡ proj₁ s₂ ↝⟨ ignore-propositional-component (Π-closure ext 1 λ _ → ⊑-propositional) ⟩□ s₁ ≡ s₂ □ -- Partiality algebras for certain universe levels and types. record Partiality-algebra {a} p q (A : Type a) : Type (a ⊔ lsuc (p ⊔ q)) where constructor ⟨_⟩ field -- A type. {T} : Type p -- A partiality-algebra with that type as the underlying type. partiality-algebra-with : Partiality-algebra-with T q A open Partiality-algebra-with partiality-algebra-with public ------------------------------------------------------------------------ -- Partiality algebra morphisms -- Morphisms from one partiality algebra to another. record Morphism {a p₁ p₂ q₁ q₂} {A : Type a} (P₁ : Partiality-algebra p₁ q₁ A) (P₂ : Partiality-algebra p₂ q₂ A) : Type (a ⊔ p₁ ⊔ p₂ ⊔ q₁ ⊔ q₂) where private module P₁ = Partiality-algebra P₁ module P₂ = Partiality-algebra P₂ field function : P₁.T → P₂.T monotone : ∀ {x y} → x P₁.⊑ y → function x P₂.⊑ function y sequence-function : P₁.Increasing-sequence → P₂.Increasing-sequence sequence-function = Σ-map (function ⊚_) (monotone ⊚_) field strict : function P₁.never ≡ P₂.never now-to-now : ∀ x → function (P₁.now x) ≡ P₂.now x ω-continuous : ∀ s → function (P₁.⨆ s) ≡ P₂.⨆ (sequence-function s) -- An identity morphism. id : ∀ {a p q} {A : Type a} {P : Partiality-algebra p q A} → Morphism P P id = record { function = Prelude.id ; monotone = Prelude.id ; strict = refl ; now-to-now = λ _ → refl ; ω-continuous = λ _ → refl } -- Composition of morphisms. _∘_ : ∀ {a p₁ p₂ p₃ q₁ q₂ q₃} {A : Type a} {P₁ : Partiality-algebra p₁ q₁ A} {P₂ : Partiality-algebra p₂ q₂ A} {P₃ : Partiality-algebra p₃ q₃ A} → Morphism P₂ P₃ → Morphism P₁ P₂ → Morphism P₁ P₃ _∘_ {P₁ = P₁} {P₂} {P₃} m₁ m₂ = record { function = function m₁ ⊚ function m₂ ; monotone = monotone m₁ ⊚ monotone m₂ ; strict = function m₁ (function m₂ (never P₁)) ≡⟨ cong (function m₁) (strict m₂) ⟩ function m₁ (never P₂) ≡⟨ strict m₁ ⟩∎ never P₃ ∎ ; now-to-now = λ x → function m₁ (function m₂ (now P₁ x)) ≡⟨ cong (function m₁) (now-to-now m₂ x) ⟩ function m₁ (now P₂ x) ≡⟨ now-to-now m₁ x ⟩∎ now P₃ x ∎ ; ω-continuous = λ s → function m₁ (function m₂ (⨆ P₁ s)) ≡⟨ cong (function m₁) (ω-continuous m₂ s) ⟩ function m₁ (⨆ P₂ (sequence-function m₂ s)) ≡⟨ ω-continuous m₁ (sequence-function m₂ s) ⟩∎ ⨆ P₃ (sequence-function m₁ (sequence-function m₂ s)) ∎ } where open Morphism open Partiality-algebra -- Is-morphism-with P Q f holds if f is a morphism from P to Q. Is-morphism-with : ∀ {a p₁ p₂ q₁ q₂} {T₁ : Type p₁} {T₂ : Type p₂} {A : Type a} (P₁ : Partiality-algebra-with T₁ q₁ A) (P₂ : Partiality-algebra-with T₂ q₂ A) → (T₁ → T₂) → Type _ Is-morphism-with P₁ P₂ f = ∃ λ (m : ∀ {x y} → x P₁.⊑ y → f x P₂.⊑ f y) → f P₁.never ≡ P₂.never × (∀ x → f (P₁.now x) ≡ P₂.now x) × (∀ s → f (P₁.⨆ s) ≡ P₂.⨆ (Σ-map (f ⊚_) (m ⊚_) s)) where module P₁ = Partiality-algebra-with P₁ module P₂ = Partiality-algebra-with P₂ -- Is-morphism P Q f holds if f is a morphism from P to Q. Is-morphism : let open Partiality-algebra in ∀ {a p₁ p₂ q₁ q₂} {A : Type a} (P₁ : Partiality-algebra p₁ q₁ A) (P₂ : Partiality-algebra p₂ q₂ A) → (T P₁ → T P₂) → Type _ Is-morphism P₁ P₂ = Is-morphism-with P₁.partiality-algebra-with P₂.partiality-algebra-with where module P₁ = Partiality-algebra P₁ module P₂ = Partiality-algebra P₂ -- An alternative definition of morphisms. Morphism-as-Σ : ∀ {a p₁ p₂ q₁ q₂} {A : Type a} → Partiality-algebra p₁ q₁ A → Partiality-algebra p₂ q₂ A → Type _ Morphism-as-Σ P₁ P₂ = ∃ λ (f : P₁.T → P₂.T) → Is-morphism P₁ P₂ f where module P₁ = Partiality-algebra P₁ module P₂ = Partiality-algebra P₂ -- The two definitions are isomorphic. Morphism↔Morphism-as-Σ : ∀ {a p₁ p₂ q₁ q₂} {A : Type a} {P₁ : Partiality-algebra p₁ q₁ A} {P₂ : Partiality-algebra p₂ q₂ A} → Morphism P₁ P₂ ↔ Morphism-as-Σ P₁ P₂ Morphism↔Morphism-as-Σ = record { surjection = record { logical-equivalence = record { to = λ m → function m , monotone m , strict m , now-to-now m , ω-continuous m ; from = λ { (f , m , s , n , ω) → record { function = f ; monotone = m ; strict = s ; now-to-now = n ; ω-continuous = ω } } } ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ _ → refl } where open Morphism abstract -- Is-morphism-with is pointwise propositional. Is-morphism-with-propositional : let open Partiality-algebra in ∀ {a p₁ p₂ q₁ q₂} {T₁ : Type p₁} {T₂ : Type p₂} {A : Type a} (P₁ : Partiality-algebra-with T₁ q₁ A) (P₂ : Partiality-algebra-with T₂ q₂ A) {f : T₁ → T₂} → Is-proposition (Is-morphism-with P₁ P₂ f) Is-morphism-with-propositional _ P₂ = Σ-closure 1 (implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → P₂.⊑-propositional) λ _ → ×-closure 1 P₂.T-is-set $ ×-closure 1 (Π-closure ext 1 λ _ → P₂.T-is-set) $ Π-closure ext 1 λ _ → P₂.T-is-set where module P₂ = Partiality-algebra-with P₂ -- Is-morphism is pointwise propositional. Is-morphism-propositional : let open Partiality-algebra in ∀ {a p₁ p₂ q₁ q₂} {A : Type a} (P₁ : Partiality-algebra p₁ q₁ A) (P₂ : Partiality-algebra p₂ q₂ A) {f : T P₁ → T P₂} → Is-proposition (Is-morphism P₁ P₂ f) Is-morphism-propositional P₁ P₂ = Is-morphism-with-propositional P₁.partiality-algebra-with P₂.partiality-algebra-with where module P₁ = Partiality-algebra P₁ module P₂ = Partiality-algebra P₂ -- An equality characterisation lemma for morphisms. equality-characterisation-Morphism : ∀ {a p₁ p₂ q₁ q₂} {A : Type a} {P₁ : Partiality-algebra p₁ q₁ A} {P₂ : Partiality-algebra p₂ q₂ A} → {m₁ m₂ : Morphism P₁ P₂} → Morphism.function m₁ ≡ Morphism.function m₂ ↔ m₁ ≡ m₂ equality-characterisation-Morphism {P₁ = P₁} {P₂} {m₁} {m₂} = function m₁ ≡ function m₂ ↝⟨ ignore-propositional-component (Is-morphism-propositional P₁ P₂) ⟩ _↔_.to Morphism↔Morphism-as-Σ m₁ ≡ _↔_.to Morphism↔Morphism-as-Σ m₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Morphism↔Morphism-as-Σ) ⟩□ m₁ ≡ m₂ □ where open Morphism -- The type of morphisms is a set. Morphism-set : ∀ {a p₁ p₂ q₁ q₂} {A : Type a} {P₁ : Partiality-algebra p₁ q₁ A} {P₂ : Partiality-algebra p₂ q₂ A} → Is-set (Morphism P₁ P₂) Morphism-set {P₂ = P₂} = H-level.respects-surjection (_↔_.surjection equality-characterisation-Morphism) 1 (Π-closure ext 2 λ _ → T-is-set P₂) where open Partiality-algebra
31.931818
142
0.554537
211a5f0660175be469a28011730742afe443e892
9,441
agda
Agda
src/STLC1/Kovacs/Substitution.agda
mietek/coquand-kovacs
bd626509948fbf8503ec2e31c1852e1ac6edcc79
[ "X11" ]
null
null
null
src/STLC1/Kovacs/Substitution.agda
mietek/coquand-kovacs
bd626509948fbf8503ec2e31c1852e1ac6edcc79
[ "X11" ]
null
null
null
src/STLC1/Kovacs/Substitution.agda
mietek/coquand-kovacs
bd626509948fbf8503ec2e31c1852e1ac6edcc79
[ "X11" ]
null
null
null
module STLC1.Kovacs.Substitution where open import STLC1.Kovacs.Embedding public open import Category -------------------------------------------------------------------------------- -- Substitutions (Sub ; ∙ ; _,_) infix 3 _⊢⋆_ data _⊢⋆_ : 𝒞 → 𝒞 → Set where ∅ : ∀ {Γ} → Γ ⊢⋆ ∅ _,_ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ) (M : Γ ⊢ A) → Γ ⊢⋆ Ξ , A -- (_ₛ∘ₑ_) -- NOTE: _◐_ = ren⋆ _◐_ : ∀ {Γ Γ′ Ξ} → Γ ⊢⋆ Ξ → Γ′ ⊇ Γ → Γ′ ⊢⋆ Ξ ∅ ◐ η = ∅ (σ , M) ◐ η = σ ◐ η , ren η M -- (_ₑ∘ₛ_) _◑_ : ∀ {Γ Ξ Ξ′} → Ξ′ ⊇ Ξ → Γ ⊢⋆ Ξ′ → Γ ⊢⋆ Ξ done ◑ σ = σ wkₑ η ◑ (σ , M) = η ◑ σ liftₑ η ◑ (σ , M) = η ◑ σ , M -------------------------------------------------------------------------------- -- (dropₛ) wkₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ wkₛ σ = σ ◐ wkₑ idₑ -- (keepₛ) liftₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ , A liftₛ σ = wkₛ σ , 0 -- (⌜_⌝ᵒᵖᵉ) ⌊_⌋ : ∀ {Γ Γ′} → Γ′ ⊇ Γ → Γ′ ⊢⋆ Γ ⌊ done ⌋ = ∅ ⌊ wkₑ η ⌋ = wkₛ ⌊ η ⌋ ⌊ liftₑ η ⌋ = liftₛ ⌊ η ⌋ -- (∈ₛ) getₛ : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ∋ A → Γ ⊢ A getₛ (σ , M) zero = M getₛ (σ , M) (suc i) = getₛ σ i -- (Tmₛ) sub : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A sub σ (𝓋 i) = getₛ σ i sub σ (ƛ M) = ƛ (sub (liftₛ σ) M) sub σ (M ∙ N) = sub σ M ∙ sub σ N sub σ (M , N) = sub σ M , sub σ N sub σ (π₁ M) = π₁ (sub σ M) sub σ (π₂ M) = π₂ (sub σ M) sub σ τ = τ -- (idₛ) idₛ : ∀ {Γ} → Γ ⊢⋆ Γ idₛ {∅} = ∅ idₛ {Γ , A} = liftₛ idₛ cut : ∀ {Γ A B} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B cut M N = sub (idₛ , M) N -- (_∘ₛ_) -- NOTE: _●_ = sub⋆ _●_ : ∀ {Γ Ξ Φ} → Ξ ⊢⋆ Φ → Γ ⊢⋆ Ξ → Γ ⊢⋆ Φ ∅ ● σ₁ = ∅ (σ₂ , M) ● σ₁ = σ₂ ● σ₁ , sub σ₁ M -------------------------------------------------------------------------------- -- (assₛₑₑ) comp◐○ : ∀ {Γ Γ′ Γ″ Ξ} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) → (σ ◐ η₂) ◐ η₁ ≡ σ ◐ (η₂ ○ η₁) comp◐○ η₁ η₂ ∅ = refl comp◐○ η₁ η₂ (σ , M) = _,_ & comp◐○ η₁ η₂ σ ⊗ (ren○ η₁ η₂ M ⁻¹) -- (assₑₛₑ) comp◑◐ : ∀ {Γ Γ′ Ξ Ξ′} → (η₁ : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ′) (η₂ : Ξ′ ⊇ Ξ) → (η₂ ◑ σ) ◐ η₁ ≡ η₂ ◑ (σ ◐ η₁) comp◑◐ η₁ ∅ done = refl comp◑◐ η₁ (σ , M) (wkₑ η₂) = comp◑◐ η₁ σ η₂ comp◑◐ η₁ (σ , M) (liftₑ η₂) = (_, ren η₁ M) & comp◑◐ η₁ σ η₂ -------------------------------------------------------------------------------- -- (idlₑₛ) lid◑ : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ) → idₑ ◑ σ ≡ σ lid◑ ∅ = refl lid◑ (σ , M) = (_, M) & lid◑ σ -- (idlₛₑ) lid◐ : ∀ {Γ Γ′} → (η : Γ′ ⊇ Γ) → idₛ ◐ η ≡ ⌊ η ⌋ lid◐ done = refl lid◐ (wkₑ η) = ((idₛ ◐_) ∘ wkₑ) & rid○ η ⁻¹ ⦙ comp◐○ (wkₑ idₑ) η idₛ ⁻¹ ⦙ wkₛ & lid◐ η lid◐ (liftₑ η) = (_, 0) & ( comp◐○ (liftₑ η) (wkₑ idₑ) idₛ ⦙ ((idₛ ◐_) ∘ wkₑ) & ( lid○ η ⦙ rid○ η ⁻¹ ) ⦙ comp◐○ (wkₑ idₑ) η idₛ ⁻¹ ⦙ (_◐ wkₑ idₑ) & lid◐ η ) -- (idrₑₛ) rid◑ : ∀ {Γ Γ′} → (η : Γ′ ⊇ Γ) → η ◑ idₛ ≡ ⌊ η ⌋ rid◑ done = refl rid◑ (wkₑ η) = comp◑◐ (wkₑ idₑ) idₛ η ⁻¹ ⦙ wkₛ & rid◑ η rid◑ (liftₑ η) = (_, 0) & ( comp◑◐ (wkₑ idₑ) idₛ η ⁻¹ ⦙ (_◐ wkₑ idₑ) & rid◑ η ) -------------------------------------------------------------------------------- -- (∈-ₑ∘ₛ) get◑ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (i : Ξ ∋ A) → getₛ (η ◑ σ) i ≡ (getₛ σ ∘ getₑ η) i get◑ σ done i = refl get◑ (σ , M) (wkₑ η) i = get◑ σ η i get◑ (σ , M) (liftₑ η) zero = refl get◑ (σ , M) (liftₑ η) (suc i) = get◑ σ η i -- (Tm-ₑ∘ₛ) mutual sub◑ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ ⊢ A) → sub (η ◑ σ) M ≡ (sub σ ∘ ren η) M sub◑ σ η (𝓋 i) = get◑ σ η i sub◑ σ η (ƛ M) = ƛ & sublift◑ σ η M sub◑ σ η (M ∙ N) = _∙_ & sub◑ σ η M ⊗ sub◑ σ η N sub◑ σ η (M , N) = _,_ & sub◑ σ η M ⊗ sub◑ σ η N sub◑ σ η (π₁ M) = π₁ & sub◑ σ η M sub◑ σ η (π₂ M) = π₂ & sub◑ σ η M sub◑ σ η τ = refl sublift◑ : ∀ {Γ Ξ Ξ′ A B} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ , B ⊢ A) → sub (liftₛ {B} (η ◑ σ)) M ≡ (sub (liftₛ σ) ∘ ren (liftₑ η)) M sublift◑ σ η M = (λ σ′ → sub (σ′ , 0) M) & comp◑◐ (wkₑ idₑ) σ η ⦙ sub◑ (liftₛ σ) (liftₑ η) M -------------------------------------------------------------------------------- -- (∈-ₛ∘ₑ) get◐ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (i : Ξ ∋ A) → getₛ (σ ◐ η) i ≡ (ren η ∘ getₛ σ) i get◐ η (σ , M) zero = refl get◐ η (σ , M) (suc i) = get◐ η σ i -- (Tm-ₛ∘ₑ) mutual sub◐ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ ⊢ A) → sub (σ ◐ η) M ≡ (ren η ∘ sub σ) M sub◐ η σ (𝓋 i) = get◐ η σ i sub◐ η σ (ƛ M) = ƛ & sublift◐ η σ M sub◐ η σ (M ∙ N) = _∙_ & sub◐ η σ M ⊗ sub◐ η σ N sub◐ η σ (M , N) = _,_ & sub◐ η σ M ⊗ sub◐ η σ N sub◐ η σ (π₁ M) = π₁ & sub◐ η σ M sub◐ η σ (π₂ M) = π₂ & sub◐ η σ M sub◐ η σ τ = refl sublift◐ : ∀ {Γ Γ′ Ξ A B} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ , B ⊢ A) → sub (liftₛ {B} (σ ◐ η)) M ≡ (ren (liftₑ η) ∘ sub (liftₛ σ)) M sublift◐ η σ M = (λ σ′ → sub (σ′ , 0) M) & ( comp◐○ (wkₑ idₑ) η σ ⦙ (σ ◐_) & (wkₑ & ( rid○ η ⦙ lid○ η ⁻¹ )) ⦙ comp◐○ (liftₑ η) (wkₑ idₑ) σ ⁻¹ ) ⦙ sub◐ (liftₑ η) (liftₛ σ) M -------------------------------------------------------------------------------- -- (assₛₑₛ) comp●◑ : ∀ {Γ Ξ Ξ′ Φ} → (σ₁ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (σ₂ : Ξ ⊢⋆ Φ) → (σ₂ ◐ η) ● σ₁ ≡ σ₂ ● (η ◑ σ₁) comp●◑ σ₁ η ∅ = refl comp●◑ σ₁ η (σ₂ , M) = _,_ & comp●◑ σ₁ η σ₂ ⊗ (sub◑ σ₁ η M ⁻¹) -- (assₛₛₑ) comp●◐ : ∀ {Γ Γ′ Ξ Φ} → (η : Γ′ ⊇ Γ) (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) → (σ₂ ● σ₁) ◐ η ≡ σ₂ ● (σ₁ ◐ η) comp●◐ η σ₁ ∅ = refl comp●◐ η σ₁ (σ₂ , M) = _,_ & comp●◐ η σ₁ σ₂ ⊗ (sub◐ η σ₁ M ⁻¹) -------------------------------------------------------------------------------- -- (∈-∘ₛ) get● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (i : Φ ∋ A) → getₛ (σ₂ ● σ₁) i ≡ (sub σ₁ ∘ getₛ σ₂) i get● σ₁ (σ₂ , M) zero = refl get● σ₁ (σ₂ , M) (suc i) = get● σ₁ σ₂ i -- (Tm-∘ₛ) mutual sub● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A) → sub (σ₂ ● σ₁) M ≡ (sub σ₁ ∘ sub σ₂) M sub● σ₁ σ₂ (𝓋 i) = get● σ₁ σ₂ i sub● σ₁ σ₂ (ƛ M) = ƛ & sublift● σ₁ σ₂ M sub● σ₁ σ₂ (M ∙ N) = _∙_ & sub● σ₁ σ₂ M ⊗ sub● σ₁ σ₂ N sub● σ₁ σ₂ (M , N) = _,_ & sub● σ₁ σ₂ M ⊗ sub● σ₁ σ₂ N sub● σ₁ σ₂ (π₁ M) = π₁ & sub● σ₁ σ₂ M sub● σ₁ σ₂ (π₂ M) = π₂ & sub● σ₁ σ₂ M sub● σ₁ σ₂ τ = refl sublift● : ∀ {Γ Ξ Φ A B} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ , B ⊢ A) → sub (liftₛ {B} (σ₂ ● σ₁)) M ≡ (sub (liftₛ σ₁) ∘ sub (liftₛ σ₂)) M sublift● σ₁ σ₂ M = (λ σ′ → sub (σ′ , 0) M) & ( comp●◐ (wkₑ idₑ) σ₁ σ₂ ⦙ (σ₂ ●_) & (lid◑ (wkₛ σ₁) ⁻¹) ⦙ comp●◑ (liftₛ σ₁) (wkₑ idₑ) σ₂ ⁻¹ ) ⦙ sub● (liftₛ σ₁) (liftₛ σ₂) M -------------------------------------------------------------------------------- -- (∈-idₛ) idgetₛ : ∀ {Γ A} → (i : Γ ∋ A) → getₛ idₛ i ≡ 𝓋 i idgetₛ zero = refl idgetₛ (suc i) = get◐ (wkₑ idₑ) idₛ i ⦙ wk & idgetₛ i ⦙ 𝓋 ∘ suc & idgetₑ i -- (Tm-idₛ) idsub : ∀ {Γ A} → (M : Γ ⊢ A) → sub idₛ M ≡ M idsub (𝓋 i) = idgetₛ i idsub (ƛ M) = ƛ & idsub M idsub (M ∙ N) = _∙_ & idsub M ⊗ idsub N idsub (M , N) = _,_ & idsub M ⊗ idsub N idsub (π₁ M) = π₁ & idsub M idsub (π₂ M) = π₂ & idsub M idsub τ = refl -------------------------------------------------------------------------------- -- (idrₛ) rid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ) → σ ● idₛ ≡ σ rid● ∅ = refl rid● (σ , M) = _,_ & rid● σ ⊗ idsub M -- (idlₛ) lid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ) → idₛ ● σ ≡ σ lid● ∅ = refl lid● (σ , M) = (_, M) & ( comp●◑ (σ , M) (wkₑ idₑ) idₛ ⦙ lid● (idₑ ◑ σ) ⦙ lid◑ σ ) -- (assₛ) assoc● : ∀ {Γ Ξ Φ Ψ} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (σ₃ : Φ ⊢⋆ Ψ) → (σ₃ ● σ₂) ● σ₁ ≡ σ₃ ● (σ₂ ● σ₁) assoc● σ₁ σ₂ ∅ = refl assoc● σ₁ σ₂ (σ₃ , M) = _,_ & assoc● σ₁ σ₂ σ₃ ⊗ (sub● σ₁ σ₂ M ⁻¹) -------------------------------------------------------------------------------- 𝗦𝗧𝗟𝗖 : Category 𝒞 _⊢⋆_ 𝗦𝗧𝗟𝗖 = record { idₓ = idₛ ; _⋄_ = _●_ ; lid⋄ = lid● ; rid⋄ = rid● ; assoc⋄ = assoc● } subPsh : 𝒯 → Presheaf₀ 𝗦𝗧𝗟𝗖 subPsh A = record { Fₓ = _⊢ A ; F = sub ; idF = fext! idsub ; F⋄ = λ σ₁ σ₂ → fext! (sub● σ₂ σ₁) } --------------------------------------------------------------------------------
28.522659
80
0.297002
2ef79795722f34becb888538ab3ad9a66a38659a
1,991
agda
Agda
Cubical/Algebra/DistLattice/Basis.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/DistLattice/Basis.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/DistLattice/Basis.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- Definition of a basis of a distributive lattice as a generating sub-meet-semilattice -} {-# OPTIONS --safe #-} module Cubical.Algebra.DistLattice.Basis where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Foundations.Powerset open import Cubical.Functions.Embedding open import Cubical.Data.Sigma open import Cubical.Data.Nat using (ℕ ; zero ; suc) open import Cubical.Data.FinData open import Cubical.Data.Bool open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Monoid.BigOp open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.Semilattice open import Cubical.Algebra.Lattice open import Cubical.Algebra.DistLattice open import Cubical.Algebra.DistLattice.BigOps private variable ℓ : Level module _ (L' : DistLattice ℓ) where private L = fst L' open DistLatticeStr (snd L') open Join L' record IsGenSublattice (M : Semilattice ℓ) (e : fst M → L) : Type ℓ where constructor isgensublattice open SemilatticeStr (snd M) renaming (ε to 0s ; _·_ to _∧s_) field isInj : ∀ x y → e x ≡ e y → x ≡ y pres0 : e 0s ≡ 0l resp∧ : ∀ x y → e (x ∧s y) ≡ e x ∧l e y ⋁Gen : ∀ (x : L) → ∃[ n ∈ ℕ ] Σ[ α ∈ FinVec (fst M) n ] (⋁ (e ∘ α) ≡ x) -- TODO: prove equivalence with the more set-theoretical definition record IsBasis (S : ℙ L) : Type ℓ where constructor isbasis field contains0 : 0l ∈ S ∧lClosed : ∀ (x y : L) → x ∈ S → y ∈ S → x ∧l y ∈ S ⋁Basis : ∀ (x : L) → ∃[ n ∈ ℕ ] Σ[ α ∈ FinVec L n ] (∀ i → α i ∈ S) × (⋁ α ≡ x)
30.166667
85
0.723255
3de95ab9863444b03c0bb40b73039e1ec578ba12
29,319
agda
Agda
src/Examples/Queue.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
29
2021-07-14T03:18:28.000Z
2022-03-22T20:35:11.000Z
src/Examples/Queue.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
null
null
null
src/Examples/Queue.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
2
2021-10-06T10:28:24.000Z
2022-01-29T08:12:01.000Z
{-# OPTIONS --prop --rewriting #-} module Examples.Queue where open import Calf.CostMonoid open import Calf.CostMonoids using (ℕ-CostMonoid) costMonoid = ℕ-CostMonoid open CostMonoid costMonoid using (ℂ) open import Calf costMonoid open import Calf.Types.Nat open import Calf.Types.Unit open import Calf.Types.Sum open import Calf.Types.Bounded costMonoid open import Function open import Data.Nat open import Data.Nat.Properties import Data.Integer as Int import Data.Integer.Properties as IntP open import Data.List renaming (sum to lsum) open import Data.Product open import Relation.Binary.PropositionalEquality as P record Queue (A : tp pos) : Set where field Q : tp pos emp : val Q enq : cmp (Π Q λ _ → Π A λ _ → F Q) deq : cmp (Π Q λ _ → F (sum unit (Σ++ Q λ _ → A))) module CostList (A : tp pos) (n : ℕ) where -- Suppose we want to implement the Queue signature above using lists. -- One cost model is to count the number of times a cons node is inspected. -- This is implemented by the following annotated list type: -- destructing a cons node of type list n A consumes n steps. postulate list : tp pos nil : val list cons : val A → val list → val list list/ind : (l : val list) → (X : val list → tp neg) → cmp (X nil) → ((a : val A) → (l : val list) → (r : val (U (X l))) → cmp (X (cons a l))) → cmp (X l) list/ind/nil : ∀ {X} → (e0 : cmp (X nil)) → (e1 : (a : val A) → (l : val list) → (r : val (U (X l))) → cmp (X (cons a l))) → list/ind nil X e0 e1 ≡ e0 {-# REWRITE list/ind/nil #-} list/ind/cons : ∀ {X} → (a : val A) → (l : val list) → (e0 : cmp (X nil)) → (e1 : (a : val A) → (l : val list) → (r : val (U (X l))) → cmp (X (cons a l))) → list/ind (cons a l) X e0 e1 ≡ step (X (cons a l)) n (e1 a l (list/ind l X e0 e1)) {-# REWRITE list/ind/cons #-} list/match : (l : val list) → (X : val list → tp neg) → cmp (X nil) → ((a : val A) → (l : val list) → cmp (X (cons a l))) → cmp (X l) list/match l X e0 e1 = list/ind l X e0 (λ a l _ → e1 a l) bound/list/match : ∀ (l : val list) (X : val list → tp pos) {e0 : val (U (F (X nil)))} {e1 : (a : val A) → (l : val list) → val (U (F (X (cons a l))))} {p0 : val (U cost)} {p1 : (a : val A) → (l : val list) → val (U cost)} → IsBounded (X nil) e0 p0 → ((a : val A) → (l : val list) → IsBounded (X (cons a l)) (e1 a l) (p1 a l)) → IsBounded (X l) (list/match l (F ∘ X) e0 e1) (list/match l (λ _ → cost) p0 (λ a l → n + p1 a l)) bound/list/match l X {e0} {e1} {p0} {p1} ub0 ub1 = list/match l (λ l → meta (IsBounded (X l) (list/match l (F ∘ X) e0 e1) (list/match l (λ _ → cost) p0 (λ a l → n + p1 a l)))) ub0 λ a l → bound/circ n (bound/step n (p1 a l) (ub1 a l)) len : val list → ℕ len l = list/ind l (λ _ → meta ℕ) 0 λ a l r → 1 + r module Ex/CostList where open CostList nat 0 ex : val list ex = cons 0 (cons 1 nil) module Rev (A : tp pos) where open CostList A 1 revAppend : cmp (Π list λ _ → Π list λ _ → F list) revAppend l = list/ind l (λ _ → Π list λ _ → F list) (λ l' → ret l') λ x _ r → λ l' → r (cons x l') revAppend/lemma/cons : ∀ x xs l' → ◯ (∃ λ y → ∃ λ ys → (len ys ≡ len xs + len l') × revAppend (cons x xs) l' ≡ ret (cons y ys)) revAppend/lemma/cons x xs = list/ind xs (λ xs → meta (∀ x l' → ◯ (∃ λ y → ∃ λ ys → (len ys ≡ len xs + len l') × revAppend (cons x xs) l' ≡ ret (cons y ys)))) (λ x l' u → (x , l' , refl , step/ext (F list) (ret (cons x l')) 1 u)) (λ x' xs' ih x l' u → let (y , ys , h , ≡) = ih x' (cons x l') u in let open ≡-Reasoning in y , ys , ( begin len ys ≡⟨ h ⟩ len xs' + len (cons x l') ≡⟨⟩ len xs' + step (meta ℕ) 1 (suc (len l')) ≡⟨ cong (len xs' +_) (step/ext (meta ℕ) (suc (len l')) 1 u) ⟩ len xs' + suc (len l') ≡⟨ +-suc (len xs') (len l') ⟩ suc (len xs' + len l') ≡⟨⟩ suc (len xs') + len l' ≡˘⟨ cong (_+ len l') (step/ext (meta ℕ) (suc (len xs')) 1 u) ⟩ step (meta ℕ) 1 (suc (len xs')) + len l' ≡⟨⟩ len (cons x' xs') + len l' ∎ ) , ( begin revAppend (cons x (cons x' xs')) l' ≡⟨⟩ step (F list) 1 (revAppend (cons x' xs') (cons x l')) ≡⟨ step/ext (F list) _ 1 u ⟩ revAppend (cons x' xs') (cons x l') ≡⟨ (≡) ⟩ ret (cons y ys) ∎ )) x revAppend/cost : cmp (Π list λ _ → Π list λ _ → cost) revAppend/cost l l' = len l revAppend≤revAppend/cost : ∀ l l' → IsBounded list (revAppend l l') (revAppend/cost l l') revAppend≤revAppend/cost l = list/ind l (λ l → meta (∀ l' → IsBounded list (revAppend l l') (revAppend/cost l l'))) (λ l' → bound/ret) (λ a l r → λ l' → bound/circ 1 (bound/step 1 (len l) (r (cons a l')))) rev : cmp (Π list λ _ → F list) rev l = revAppend l nil rev/lemma/cons : ∀ x xs → ◯ (∃ λ y → ∃ λ ys → len ys ≡ len xs × rev (cons x xs) ≡ ret (cons y ys)) rev/lemma/cons x xs = subst (λ n → ◯ (∃ λ y → ∃ λ ys → len ys ≡ n × rev (cons x xs) ≡ ret (cons y ys))) (+-identityʳ _) (revAppend/lemma/cons x xs nil) rev/cost : cmp (Π list λ _ → cost) rev/cost l = len l rev≤rev/cost : ∀ l → IsBounded list (rev l) (rev/cost l) rev≤rev/cost l = revAppend≤revAppend/cost l nil -- Implement Queue with a pair of lists; (f , b) represents the queue f :: rev b. module FrontBack (A : tp pos) where -- For simplicity, we charge 1 step for each cons node destruction. open CostList A 1 open Rev A Q : tp pos Q = Σ++ list λ _ → list emp : val Q emp = (nil , nil) enq : cmp (Π Q λ _ → Π A λ _ → F Q) enq (f , b) x = ret (f , cons x b) enq/cost : cmp (Π Q λ _ → Π A λ _ → cost) enq/cost (f , b) x = 0 enq≤enq/cost : ∀ q x → IsBounded Q (enq q x) (enq/cost q x) enq≤enq/cost q x = bound/ret deq-tp = sum unit (Σ++ Q λ _ → A) deq/emp : cmp (Π list λ _ → F deq-tp) deq/emp l = list/match l (λ _ → F deq-tp) (ret (inj₁ triv)) λ a l' → ret (inj₂ ((l' , nil) , a)) deq/emp/cost : cmp (Π list λ _ → cost) deq/emp/cost l = list/match l (λ _ → cost) 0 λ a l' → 1 + 0 deq/emp≤deq/emp/cost : ∀ l → IsBounded deq-tp (deq/emp l) (deq/emp/cost l) deq/emp≤deq/emp/cost l = bound/list/match l (λ _ → deq-tp) bound/ret λ a l' → bound/ret deq : cmp (Π Q λ _ → F deq-tp) deq (f , b) = list/match f (λ _ → F deq-tp) (bind (F deq-tp) (rev b) (λ b' → deq/emp b')) λ a l → ret (inj₂ ((l , b) , a)) deq/cost : cmp (Π Q λ _ → cost) deq/cost (f , b) = list/match f (λ _ → cost) (bind cost (rev b) (λ b' → rev/cost b + deq/emp/cost b')) λ a l → 1 + 0 deq/cost/closed : cmp (Π Q λ _ → cost) deq/cost/closed (f , b) = list/match f (λ _ → cost) (list/match b (λ _ → cost) 0 (λ _ b' → 1 + len b)) λ _ _ → 1 deq/cost≤deq/cost/closed : ∀ q → ◯ (deq/cost q ≤ deq/cost/closed q) deq/cost≤deq/cost/closed (f , b) u = list/match f (λ f → meta (deq/cost (f , b) ≤ deq/cost/closed (f , b))) (list/match b (λ b → meta (deq/cost (nil , b) ≤ deq/cost/closed (nil , b))) ≤-refl λ x xs → let open ≤-Reasoning in let (y , ys , _ , ≡) = rev/lemma/cons x xs u in begin deq/cost (nil , cons x xs) ≡⟨⟩ bind cost (rev (cons x xs)) (λ b' → rev/cost (cons x xs) + deq/emp/cost b') ≡⟨⟩ bind cost (rev (cons x xs)) (λ b' → rev/cost (cons x xs) + deq/emp/cost b') ≡⟨ cong (λ e → bind cost e (λ b' → rev/cost (cons x xs) + deq/emp/cost b')) (≡) ⟩ rev/cost (cons x xs) + deq/emp/cost (cons y ys) ≡⟨⟩ step cost 1 (suc (len xs)) + step cost 1 1 ≡⟨ cong₂ _+_ (step/ext cost (suc (len xs)) 1 u) (step/ext cost 1 1 u) ⟩ suc (len xs) + 1 ≡⟨ +-comm (suc (len xs)) 1 ⟩ suc (suc (len xs)) ≡˘⟨ cong suc (step/ext cost _ 1 u) ⟩ suc (step cost 1 (suc (len xs))) ≡⟨⟩ suc (len (cons x xs)) ≡˘⟨ step/ext cost _ 1 u ⟩ step cost 1 (suc (len (cons x xs))) ≡⟨⟩ list/match (cons x xs) (λ _ → cost) 0 (λ _ b' → 1 + len (cons x xs)) ≡⟨⟩ deq/cost/closed (nil , cons x xs) ∎ ) λ _ _ → ≤-refl deq≤deq/cost : ∀ q → IsBounded deq-tp (deq q) (deq/cost q) deq≤deq/cost (f , b) = bound/list/match f (λ _ → deq-tp) (bound/bind (rev/cost b) _ (rev≤rev/cost b) λ b' → deq/emp≤deq/emp/cost b') λ a l → bound/ret deq≤deq/cost/closed : ∀ q → IsBounded deq-tp (deq q) (deq/cost/closed q) deq≤deq/cost/closed q = bound/relax (deq/cost≤deq/cost/closed q) (deq≤deq/cost q) -- Amortized analysis for front-back queue. -- The goal is to bound the cost of a single-thread sequence of queue operations staring with an initial queue q0, -- where an operation is either an enqueue or a dequeue. data op : Set where op/enq : (x : val A) → op op/deq : op -- Potential function ϕ : val Q → ℕ ϕ (f , b) = len f + 2 * len b -- o operate q is the computation induced by operation o on queue q. -- Needed because deq doesn't always return a queue (e.g., deq emp). -- In these cases we just return the empty queue. _operate_ : op → val Q → cmp (F Q) (op/enq x) operate q = enq q x (op/deq) operate q = bind (F Q) (deq q) λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q)) -- o operateϕ q is morally ϕ (o operate q), which doesn't type-check since o operate q is a computation. -- Easier to work with than bind cost (o operate q) ϕ (but they are equivalent, as shown below). _operateϕ_ : op → val Q → ℂ (op/enq x) operateϕ (f , b) = len f + 2 * (1 + len b) (op/deq) operateϕ (f , b) = list/match f (λ _ → cost) (list/match b (λ _ → cost) 0 (λ _ b' → len b')) (λ _ f' → len f' + 2 * len b) operateϕ≡ϕ∘operate : ∀ o q → ◯ (o operateϕ q ≡ bind cost (o operate q) ϕ) operateϕ≡ϕ∘operate (op/enq x) (f , b) u = begin len f + 2 * (1 + len b) ≡˘⟨ cong (λ n → len f + 2 * n) (step/ext cost (1 + len b) 1 u) ⟩ len f + 2 * step cost 1 (1 + len b) ≡⟨⟩ bind cost (enq (f , b) x) ϕ ∎ where open ≡-Reasoning operateϕ≡ϕ∘operate op/deq (f , b) u = list/match f (λ f → meta ((op/deq operateϕ (f , b)) ≡ bind cost (op/deq operate (f , b)) ϕ)) (list/ind b (λ b → meta ((op/deq operateϕ (nil , b)) ≡ bind cost (op/deq operate (nil , b)) ϕ)) refl λ a l ih → emp/cons a l) λ a l → refl where emp/cons : ∀ a l → op/deq operateϕ (nil , cons a l) ≡ bind cost (op/deq operate (nil , cons a l)) ϕ emp/cons a l with rev/lemma/cons a l u ... | (x' , l' , eqn1 , eqn2) = begin op/deq operateϕ (nil , cons a l) ≡⟨⟩ step cost 1 (len l) ≡⟨ step/ext cost (len l) 1 u ⟩ len l ≡⟨ P.sym eqn1 ⟩ len l' ≡⟨ P.sym (+-identityʳ (len l')) ⟩ len l' + 0 ≡⟨⟩ len l' + 2 * len nil ≡⟨⟩ ϕ (l' , nil) ≡˘⟨ step/ext cost (ϕ (l' , nil)) 1 u ⟩ step cost 1 (ϕ (l' , nil)) ≡⟨⟩ bind cost (step (F Q) 1 (ret (l' , nil))) ϕ ≡⟨⟩ bind cost (bind (F Q) (step (F deq-tp) 1 (ret (inj₂ ((l' , nil) , x')))) λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q))) ϕ ≡⟨⟩ bind cost (bind (F Q) (deq/emp (cons x' l')) λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q))) ϕ ≡˘⟨ cong (λ e → bind cost (bind (F Q) e λ l' → bind (F Q) (deq/emp l') λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q))) ϕ ) eqn2 ⟩ bind cost (bind (F Q) (rev (cons a l)) λ l' → bind (F Q) (deq/emp l') λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q))) ϕ ≡⟨⟩ bind cost (bind (F Q) (deq (nil , cons a l)) λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q))) ϕ ≡⟨⟩ bind cost (op/deq operate (nil , cons a l)) ϕ ∎ where open ≡-Reasoning -- op/cost o q is the cost of o operate q. op/cost : op → val Q → ℕ op/cost (op/enq x) q = 0 op/cost (op/deq) (f , b) = list/match f (λ _ → cost) (list/match b (λ _ → cost) 0 (λ _ b' → 2 + len b')) (λ _ _ → 1) deq/cost≡cost/deq : ∀ q → ◯ (deq/cost/closed q ≡ op/cost op/deq q) deq/cost≡cost/deq (f , b) u = P.cong (λ x → list/match f (λ _ → cost) x (λ _ _ → 1)) ( list/match b (λ b → meta (list/match b (λ _ → cost) 0 (λ _ b' → 1 + len b) ≡ list/match b (λ _ → cost) 0 (λ _ b' → 2 + len b'))) refl (λ a l → let open ≡-Reasoning in begin list/match (cons a l) (λ _ → cost) 0 (λ _ b' → 1 + len (cons a l)) ≡⟨⟩ step cost 1 (1 + len (cons a l)) ≡⟨ step/ext cost (1 + len (cons a l)) 1 u ⟩ 1 + len (cons a l) ≡⟨⟩ 1 + step cost 1 (suc (len l)) ≡⟨ cong (1 +_) (step/ext cost (suc (len l)) 1 u) ⟩ 2 + len l ≡˘⟨ step/ext cost (2 + len l) 1 u ⟩ step cost 1 (2 + len l) ≡⟨⟩ list/match (cons a l) (λ _ → cost) 0 (λ _ b' → 2 + len b') ∎ ) ) -- cost o q upperbounds the cost of o operate q. op≤op/cost : ∀ o q → IsBounded Q (o operate q) (op/cost o q) op≤op/cost (op/enq x) q = enq≤enq/cost q x op≤op/cost op/deq q rewrite P.sym (+-identityʳ (op/cost (op/deq) q)) = bound/bind/const {A = deq-tp} {e = deq q} {f = λ s → (sum/case unit (Σ++ Q λ _ → A) (λ _ → F Q) s (λ _ → ret (nil , nil)) (λ (q , x) → ret q))} (op/cost op/deq q) 0 (bound/relax (λ u → ≤-reflexive (deq/cost≡cost/deq q u)) (deq≤deq/cost/closed q)) λ a → bound/sum/case/const/const unit ((Σ++ Q λ _ → A)) (λ _ → Q) a ((λ _ → ret (nil , nil))) (λ (q , x) → ret q) 0 (λ _ → bound/ret) (λ _ → bound/ret) -- is/acost o k when for any state q, k suffices for the cost of o on q and the difference in the potential. is/acost : op → ℕ → Set is/acost o k = ∀ q → (Int.+ (op/cost o q)) Int.+ ((o operateϕ q) Int.⊖ (ϕ q)) Int.≤ Int.+ k acost/weaken : ∀ {m n o} → m ≤ n → is/acost o m → is/acost o n acost/weaken h1 h2 = λ q → IntP.≤-trans (h2 q) (Int.+≤+ h1) -- A sequence of operations induces a single computation by threading through the initial state q0. _op/seq_ : List op → val Q → cmp (F Q) [] op/seq q0 = ret q0 (o ∷ os) op/seq q = bind (F Q) (o operate q) λ q' → os op/seq q' op/seq/cost : ∀ (l : List op) → val Q → ℂ op/seq/cost [] q0 = 0 op/seq/cost (o ∷ os) q = bind cost (o operate q) λ q' → op/cost o q + op/seq/cost os q' -- Cost of a sequence computation is bounded by the sum of cost of the constituents. op/seq≤op/seq/cost : ∀ l q → IsBounded Q (l op/seq q) (op/seq/cost l q) op/seq≤op/seq/cost [] q0 = bound/ret op/seq≤op/seq/cost (o ∷ os) q = bound/bind {A = Q} {e = o operate q} {f = λ q → os op/seq q} (op/cost o q) (op/seq/cost os) (op≤op/cost o q) λ q → op/seq≤op/seq/cost os q -- Telescoping the potential. op/seq/cost/tele : ∀ (l : List op) → val Q → Int.ℤ op/seq/cost/tele [] q0 = Int.0ℤ op/seq/cost/tele (o ∷ os) q = bind (meta Int.ℤ) (o operate q) λ q' → (Int.+ (op/cost o q)) Int.+ (o operateϕ q Int.⊖ ϕ q) Int.+ (op/seq/cost/tele os q') ϕn : ℕ → List op → val Q → ℕ ϕn zero l q0 = ϕ q0 ϕn (suc n) (o ∷ os) q = bind cost (o operate q) λ q' → ϕn n os q' ϕn (suc n) [] q = 0 -- Potential of the initial state ϕ/0 : List op → val Q → ℕ ϕ/0 l = ϕn 0 l -- Potential of the final state ϕ/-1 : List op → val Q → ℕ ϕ/-1 l = ϕn (length l) l bind/dup : ∀ A 𝕊 𝕋 e f (g : val A → 𝕊 → 𝕋) → bind {A} (meta 𝕋) e (λ a → g a (bind {A} (meta 𝕊) e f)) ≡ bind {A} (meta 𝕋) e (λ a → g a (f a)) bind/dup A 𝕊 𝕋 e f g = begin bind (meta 𝕋) e (λ a → g a (bind (meta 𝕊) e f)) ≡⟨ P.cong (λ h → bind (meta 𝕋) e h) (funext (λ a → bind/meta A 𝕊 𝕋 e f (λ s → g a s))) ⟩ bind (meta 𝕋) e (λ a → bind (meta 𝕋) e (λ a' → g a (f a'))) ≡⟨ bind/idem A 𝕋 e (λ a a' → g a (f a')) ⟩ bind (meta 𝕋) e (λ a → g a (f a)) ≡⟨ refl ⟩ bind (meta 𝕋) e (λ a → g a (f a)) ∎ where open ≡-Reasoning -- Telescoping sum: -- Σᵢⁿ op/cost oᵢ + ϕ qᵢ - ϕ qᵢ­₋₁ = ϕ q_{n-1} - ϕ q_0 + Σᵢ costᵢ cost≡cost/tele : ∀ l q → ◯ (op/seq/cost/tele l q ≡ (ϕ/-1 l q Int.⊖ ϕ/0 l q) Int.+ (Int.+ (op/seq/cost l q))) cost≡cost/tele [] q u = P.sym ( begin (ϕ q Int.⊖ ϕ q) Int.+ (Int.+ 0) ≡⟨ IntP.+-identityʳ (ϕ q Int.⊖ ϕ q) ⟩ ϕ q Int.⊖ ϕ q ≡⟨ IntP.n⊖n≡0 (ϕ q) ⟩ Int.+ 0 ≡⟨ refl ⟩ Int.+ 0 ∎ ) where open ≡-Reasoning cost≡cost/tele (o ∷ os) q u rewrite operateϕ≡ϕ∘operate o q u | bind/meta Q ℕ Int.ℤ (o operate q) (λ q' → op/cost o q + op/seq/cost os q') (λ x → (ϕ/-1 (o ∷ os) q Int.⊖ ϕ/0 (o ∷ os) q) Int.+ (Int.+ x)) | bind/dup Q ℕ Int.ℤ (o operate q) (ϕ/-1 os) (λ q' x → (x Int.⊖ ϕ q) Int.+ (Int.+ (op/cost o q + op/seq/cost os q'))) | bind/dup Q ℕ Int.ℤ (o operate q) ϕ (λ q' x → Int.+ (op/cost o q) Int.+ (x Int.⊖ ϕ q) Int.+ (op/seq/cost/tele os q')) = P.cong (λ f → bind (meta Int.ℤ) (o operate q) f) (funext (λ q' → ( begin (Int.+ (op/cost o q)) Int.+ (ϕ q' Int.⊖ ϕ q) Int.+ (op/seq/cost/tele os q') ≡⟨ P.cong (λ x → (Int.+ (op/cost o q)) Int.+ (ϕ q' Int.⊖ ϕ q) Int.+ x) (cost≡cost/tele os q' u) ⟩ Int.+ op/cost o q Int.+ (ϕ q' Int.⊖ ϕ q) Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → x Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ Int.+ op/seq/cost os q')) (IntP.+-comm (Int.+ op/cost o q) (ϕ q' Int.⊖ ϕ q)) ⟩ ϕ q' Int.⊖ ϕ q Int.+ Int.+ op/cost o q Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ Int.+ op/seq/cost os q') ≡⟨ IntP.+-assoc (ϕ q' Int.⊖ ϕ q) (Int.+ op/cost o q) (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ Int.+ op/seq/cost os q') ⟩ ϕ q' Int.⊖ ϕ q Int.+ (Int.+ op/cost o q Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ Int.+ op/seq/cost os q')) ≡⟨ P.cong (λ x → ϕ q' Int.⊖ ϕ q Int.+ x) (P.sym (IntP.+-assoc (Int.+ op/cost o q) (ϕ/-1 os q' Int.⊖ ϕ/0 os q') (Int.+ op/seq/cost os q'))) ⟩ ϕ q' Int.⊖ ϕ q Int.+ (Int.+ op/cost o q Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q') Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → ϕ q' Int.⊖ ϕ q Int.+ (x Int.+ Int.+ op/seq/cost os q')) (IntP.+-comm (Int.+ op/cost o q) (ϕ/-1 os q' Int.⊖ ϕ/0 os q')) ⟩ ϕ q' Int.⊖ ϕ q Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → ϕ q' Int.⊖ ϕ q Int.+ x) (IntP.+-assoc (ϕ/-1 os q' Int.⊖ ϕ/0 os q') (Int.+ op/cost o q) (Int.+ op/seq/cost os q')) ⟩ ϕ q' Int.⊖ ϕ q Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q' Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) ≡⟨ P.sym (IntP.+-assoc (ϕ q' Int.⊖ ϕ q) (ϕ/-1 os q' Int.⊖ ϕ/0 os q') (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) ⟩ ϕ q' Int.⊖ ϕ q Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q') Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → x Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q') Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) (P.sym (IntP.m-n≡m⊖n (ϕ q') (ϕ q))) ⟩ Int.+ ϕ q' Int.- (Int.+ ϕ q) Int.+ (ϕ/-1 os q' Int.⊖ ϕ/0 os q') Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → Int.+ ϕ q' Int.- (Int.+ ϕ q) Int.+ x Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) (P.sym (IntP.m-n≡m⊖n (ϕ/-1 os q') (ϕ/0 os q'))) ⟩ Int.+ ϕ q' Int.- Int.+ ϕ q Int.+ (Int.+ ϕ/-1 os q' Int.- (Int.+ ϕ/0 os q')) Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → x Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) (IntP.+-comm (Int.+ ϕ q' Int.- Int.+ ϕ q) (Int.+ ϕ/-1 os q' Int.- (Int.+ ϕ/0 os q'))) ⟩ Int.+ ϕ/-1 os q' Int.- Int.+ ϕ/0 os q' Int.+ (Int.+ ϕ q' Int.- Int.+ ϕ q) Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → x Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) (IntP.+-minus-telescope (Int.+ ϕ/-1 os q') (Int.+ ϕ q') (Int.+ ϕ q)) ⟩ Int.+ ϕ/-1 os q' Int.- Int.+ ϕ q Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ P.cong (λ x → x Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q')) (IntP.m-n≡m⊖n (ϕ/-1 os q') (ϕ q )) ⟩ ϕ/-1 os q' Int.⊖ ϕ q Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ≡⟨ refl ⟩ ϕ/-1 os q' Int.⊖ ϕ q Int.+ (Int.+ op/cost o q Int.+ Int.+ op/seq/cost os q') ∎ ) )) where open ≡-Reasoning data Amortized : List op → List ℕ → Set where a/emp : Amortized [] [] a/cons : ∀ o k l l' → is/acost o k → Amortized l l' → Amortized (o ∷ l) (k ∷ l') amortized≥cost/tele : ∀ q0 l l' → Amortized l l' → Int.+ (lsum l') Int.≥ op/seq/cost/tele l q0 amortized≥cost/tele q .[] .[] a/emp = IntP.≤-refl amortized≥cost/tele q .(o ∷ os) .(k ∷ l') (a/cons o k os l' x h) rewrite tbind/meta Q Int.ℤ (o operate q) (λ q' → (Int.+ (op/cost o q)) Int.+ (o operateϕ q Int.⊖ ϕ q) Int.+ (op/seq/cost/tele os q')) (λ z → z Int.≤ Int.+ lsum (k ∷ l')) = dbind (λ q' → meta ((Int.+ (op/cost o q)) Int.+ (o operateϕ q Int.⊖ ϕ q) Int.+ (op/seq/cost/tele os q') Int.≤ Int.+ lsum (k ∷ l'))) (o operate q) λ q' → begin Int.+ op/cost o q Int.+ ((o operateϕ q) Int.⊖ ϕ q) Int.+ op/seq/cost/tele os q' ≤⟨ IntP.+-monoˡ-≤ (op/seq/cost/tele os q') (x q) ⟩ Int.+ k Int.+ op/seq/cost/tele os q' ≤⟨ IntP.+-monoʳ-≤ (Int.+ k) (amortized≥cost/tele q' os l' h) ⟩ Int.+ k Int.+ Int.+ lsum l' ≤⟨ IntP.≤-refl ⟩ Int.+ k Int.+ Int.+ lsum l' ∎ where open IntP.≤-Reasoning -- Sum of a sequence of amortized costs (plus the initial potential) bounds the sum of the sequence of actual costs amortized≥cost : ∀ q l l' → Amortized l l' → ◯ (Int.+ (ϕ q + lsum l') Int.≥ Int.+ (op/seq/cost l q)) amortized≥cost q l l' h u = begin Int.+ (op/seq/cost l q) ≤⟨ IntP.n≤m+n (0 + ϕ/-1 l q) ⟩ Int.0ℤ Int.+ (Int.+ ϕ/-1 l q) Int.+ Int.+ op/seq/cost l q ≡⟨ P.cong (λ x → x Int.+ (Int.+ ϕ/-1 l q) Int.+ Int.+ op/seq/cost l q) (P.sym (IntP.n⊖n≡0 (ϕ q))) ⟩ ϕ q Int.⊖ ϕ q Int.+ Int.+ ϕ/-1 l q Int.+ Int.+ op/seq/cost l q ≡⟨ P.cong (λ x → x Int.+ (Int.+ ϕ/-1 l q) Int.+ Int.+ op/seq/cost l q) (P.sym (IntP.m-n≡m⊖n (ϕ q) (ϕ q))) ⟩ Int.+ ϕ q Int.+ Int.- (Int.+ ϕ q) Int.+ Int.+ ϕ/-1 l q Int.+ Int.+ op/seq/cost l q ≡⟨ P.cong (λ x → x Int.+ Int.+ op/seq/cost l q) (IntP.+-assoc (Int.+ ϕ q) (Int.- (Int.+ ϕ q)) (Int.+ ϕ/-1 l q)) ⟩ Int.+ ϕ q Int.+ (Int.- (Int.+ ϕ q) Int.+ Int.+ ϕ/-1 l q) Int.+ Int.+ op/seq/cost l q ≡⟨ P.cong (λ x → Int.+ ϕ q Int.+ x Int.+ Int.+ op/seq/cost l q) (IntP.+-comm (Int.- (Int.+ ϕ q)) (Int.+ ϕ/-1 l q)) ⟩ Int.+ ϕ q Int.+ (Int.+ ϕ/-1 l q Int.- (Int.+ ϕ q)) Int.+ Int.+ op/seq/cost l q ≡⟨ IntP.+-assoc (Int.+ ϕ q) (Int.+ ϕ/-1 l q Int.- (Int.+ ϕ q)) (Int.+ op/seq/cost l q) ⟩ Int.+ ϕ q Int.+ (Int.+ ϕ/-1 l q Int.- Int.+ ϕ q Int.+ Int.+ op/seq/cost l q) ≡⟨ P.cong (λ x → Int.+ ϕ q Int.+ (x Int.+ Int.+ op/seq/cost l q)) (IntP.m-n≡m⊖n (ϕ/-1 l q) (ϕ q)) ⟩ Int.+ ϕ q Int.+ (ϕ/-1 l q Int.⊖ ϕ q Int.+ Int.+ op/seq/cost l q) ≡⟨ P.cong (λ x → Int.+ ϕ q Int.+ x) (P.sym (cost≡cost/tele l q u)) ⟩ Int.+ ϕ q Int.+ op/seq/cost/tele l q ≤⟨ IntP.+-monoʳ-≤ (Int.+ ϕ q) (amortized≥cost/tele q l l' h) ⟩ Int.+ ϕ q Int.+ Int.+ lsum l' ≤⟨ IntP.≤-refl ⟩ Int.+ ϕ q Int.+ Int.+ lsum l' ∎ where open IntP.≤-Reasoning -- Amortized cost for enq and deq on a front-back queue enq/acost : ∀ x → ◯ (is/acost (op/enq x) 2) enq/acost x u (f , b) = begin (Int.+ (op/cost (op/enq x) (f , b))) Int.+ (((op/enq x) operateϕ (f , b)) Int.⊖ (ϕ (f , b))) ≡⟨⟩ Int.0ℤ Int.+ ((len f + 2 * (1 + len b)) Int.⊖ (ϕ (f , b))) ≡⟨ IntP.+-identityˡ ((len f + 2 * (1 + len b)) Int.⊖ (ϕ (f , b))) ⟩ len f + 2 * (1 + len b) Int.⊖ ϕ (f , b) ≡⟨ P.cong (λ x → (len f + x) Int.⊖ (ϕ (f , b))) (*-distribˡ-+ 2 1 (len b)) ⟩ len f + (2 * 1 + 2 * len b) Int.⊖ ϕ (f , b) ≡⟨ P.cong (λ x → (len f + x) Int.⊖ (ϕ (f , b)) ) (+-comm 2 (2 * len b)) ⟩ len f + (2 * len b + 2) Int.⊖ ϕ (f , b) ≡⟨ P.cong (λ x → x Int.⊖ (ϕ (f , b))) (P.sym (+-assoc (len f) (2 * len b) 2)) ⟩ len f + 2 * len b + 2 Int.⊖ ϕ (f , b) ≡⟨ P.cong (λ x → (len f + 2 * len b + 2) Int.⊖ x) (P.sym (+-identityʳ (ϕ (f , b)))) ⟩ len f + 2 * len b + 2 Int.⊖ (ϕ (f , b) + 0) ≡⟨ IntP.+-cancelˡ-⊖ (len f + 2 * len b) 2 0 ⟩ Int.+ 2 ∎ where open IntP.≤-Reasoning n+n≡2*n : ∀ n → n + n ≡ 2 * n n+n≡2*n n = begin n + n ≡⟨ P.cong (λ x → n + x) (P.sym (+-identityʳ n)) ⟩ 2 * n ∎ where open ≡-Reasoning deq/acost : ◯ (is/acost op/deq 0) deq/acost u (f , b) = list/match f (λ f → meta ((Int.+ (op/cost op/deq (f , b))) Int.+ ((op/deq operateϕ (f , b)) Int.⊖ (ϕ (f , b))) Int.≤ Int.0ℤ)) ( list/match b (λ b → meta ((Int.+ (op/cost op/deq (nil , b))) Int.+ ((op/deq operateϕ (nil , b)) Int.⊖ (ϕ (nil , b))) Int.≤ Int.0ℤ)) IntP.≤-refl λ a b' → begin (Int.+ (op/cost op/deq (nil , cons a b'))) Int.+ ((op/deq operateϕ (nil , cons a b')) Int.⊖ (ϕ (nil , cons a b'))) ≡⟨⟩ Int.+ (step cost 1 (2 + len b')) Int.+ (step cost 1 (len b') Int.⊖ (2 * (step cost 1 (1 + len b')))) ≡⟨ cong₂ Int._+_ (cong Int.+_ (step/ext cost (2 + len b') 1 u)) (cong₂ Int._⊖_ (step/ext cost (len b') 1 u) (cong (2 *_) (step/ext cost (1 + len b') 1 u)) ) ⟩ Int.+ (2 + len b') Int.+ (len b' Int.⊖ (2 * (1 + len b'))) ≡⟨ IntP.distribʳ-⊖-+-pos (2 + len b') (len b') (2 * (1 + len b')) ⟩ 2 + len b' + len b' Int.⊖ 2 * (1 + len b') ≡⟨ P.cong (λ x → x Int.⊖ 2 * (1 + len b')) (+-assoc 2 (len b') (len b')) ⟩ 2 + (len b' + len b') Int.⊖ 2 * (1 + len b') ≡⟨ P.cong (λ x → 2 + (len b' + len b') Int.⊖ x) (*-distribˡ-+ 2 1 (len b')) ⟩ 2 + (len b' + len b') Int.⊖ (2 * 1 + 2 * len b') ≡⟨ P.cong (λ x → 2 + x Int.⊖ (2 + 2 * len b')) (n+n≡2*n (len b')) ⟩ 2 + 2 * len b' Int.⊖ (2 + 2 * len b') ≡⟨ IntP.n⊖n≡0 (2 + 2 * len b') ⟩ Int.0ℤ ∎ ) λ a f' → begin (Int.+ (op/cost op/deq (cons a f' , b))) Int.+ ((op/deq operateϕ (cons a f' , b)) Int.⊖ (ϕ (cons a f' , b))) ≡⟨⟩ Int.+ (step cost 1 1) Int.+ (step cost 1 (len f' + 2 * len b) Int.⊖ (step cost 1 (1 + len f') + 2 * len b)) ≡⟨ cong₂ Int._+_ (cong Int.+_ (step/ext cost 1 1 u)) (cong₂ Int._⊖_ (step/ext cost (len f' + 2 * len b) 1 u) (cong (_+ 2 * len b) (step/ext cost (1 + len f') 1 u)) ) ⟩ Int.+ 1 Int.+ ((len f' + 2 * len b) Int.⊖ (1 + len f' + 2 * len b)) ≡⟨ IntP.distribʳ-⊖-+-pos 1 (len f' + 2 * len b) (1 + len f' + 2 * len b) ⟩ 1 + (len f' + 2 * len b) Int.⊖ (1 + len f' + 2 * len b) ≡⟨ P.cong (λ x → x Int.⊖ (1 + len f' + 2 * len b)) (P.sym (+-assoc 1 (len f') (2 * len b))) ⟩ 1 + len f' + 2 * len b Int.⊖ (1 + len f' + 2 * len b) ≡⟨ IntP.n⊖n≡0 (1 + len f' + 2 * len b) ⟩ Int.0ℤ ∎ where open IntP.≤-Reasoning all2s : ℕ → List ℕ all2s n = tabulate {n = n} (λ _ → 2) sum2s : ∀ n → lsum (all2s n) ≡ 2 * n sum2s zero = refl sum2s (suc n) = begin 2 + lsum (all2s n) ≡⟨ P.cong (λ x → 2 + x) (sum2s n) ⟩ 2 + 2 * n ≡⟨ P.cong (λ x → x + 2 * n) (*-identityʳ 2) ⟩ 2 * 1 + 2 * n ≡⟨ P.sym (*-distribˡ-+ 2 1 n) ⟩ 2 * (1 + n) ∎ where open ≡-Reasoning all2s/is/acost : ∀ l → ◯ (Amortized l (all2s (length l))) all2s/is/acost [] u = a/emp all2s/is/acost ((op/enq x) ∷ os) u = a/cons (op/enq x) 2 os (all2s (length os)) (enq/acost x u) (all2s/is/acost os u) all2s/is/acost (op/deq ∷ os) u = a/cons op/deq 2 os (all2s (length os)) (acost/weaken z≤n (deq/acost u)) (all2s/is/acost os u) op/seq/cost≤ϕ₀+2*|l| : ∀ q l → ◯ (Int.+ (op/seq/cost l q) Int.≤ Int.+ (ϕ q + 2 * length l)) op/seq/cost≤ϕ₀+2*|l| q l u = begin Int.+ (op/seq/cost l q) ≤⟨ amortized≥cost q l (all2s (length l)) (all2s/is/acost l u) u ⟩ Int.+ (ϕ q + lsum (all2s (length l))) ≡⟨ P.cong (λ x → Int.+ (ϕ q + x)) (sum2s (length l)) ⟩ Int.+ (ϕ q + 2 * length l) ≤⟨ IntP.≤-refl ⟩ Int.+ (ϕ q + 2 * length l) ∎ where open IntP.≤-Reasoning -- Starting with an empty queue, a sequence of n operations costs at most 2 * n op/seq≤2*|l| : ∀ l → IsBounded Q (l op/seq emp) (2 * length l) op/seq≤2*|l| l = bound/relax (λ u → IntP.drop‿+≤+ (op/seq/cost≤ϕ₀+2*|l| emp l u)) (op/seq≤op/seq/cost l emp)
44.28852
301
0.485897
5e27c1cf31daf5f4fd836b950e4ea82fe44ac6c3
4,465
agda
Agda
Categories/Support/Nat.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Support/Nat.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Support/Nat.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
module Support.Nat where open import Support data _<_ : (n m : ℕ) → Set where Z<Sn : {n : ℕ} → zero < suc n raise< : {n m : ℕ} (n<m : n < m) → suc n < suc m infix 5 _>_ _>_ : (m n : ℕ) → Set _>_ = flip _<_ infixr 7 _+_ _+_ : (n m : ℕ) → ℕ zero + m = m suc n + m = suc (n + m) infixr 9 _*_ _*_ : (n m : ℕ) → ℕ zero * m = zero (suc n) * m = m + n * m +-is-nondecreasingʳ : ∀ (n m : ℕ) → n < suc (n + m) +-is-nondecreasingʳ zero m = Z<Sn +-is-nondecreasingʳ (suc y) m = raise< (+-is-nondecreasingʳ y m) +-idˡ : ∀ a → 0 + a ≣ a +-idˡ a = ≣-refl +-idʳ : ∀ a → a + 0 ≣ a +-idʳ zero = ≣-refl +-idʳ (suc y) = ≣-cong suc (+-idʳ y) +-assocˡ : ∀ a b c → (a + b) + c ≣ a + (b + c) +-assocˡ zero b c = ≣-refl +-assocˡ (suc a) b c = ≣-cong suc (+-assocˡ a b c) +-assocʳ : ∀ a b c → a + (b + c) ≣ (a + b) + c +-assocʳ zero b c = ≣-refl +-assocʳ (suc a) b c = ≣-cong suc (+-assocʳ a b c) +-sucˡ : ∀ a b → suc a + b ≣ suc (a + b) +-sucˡ a b = ≣-refl +-sucʳ : ∀ a b → a + suc b ≣ suc (a + b) +-sucʳ zero b = ≣-refl +-sucʳ (suc y) b = ≣-cong suc (+-sucʳ y b) +-comm : ∀ a b → a + b ≣ b + a +-comm a zero = +-idʳ a +-comm a (suc y) = ≣-trans (≣-cong suc (+-comm a y)) (+-sucʳ a y) *-killˡ : ∀ a → 0 * a ≣ 0 *-killˡ a = ≣-refl *-killʳ : ∀ a → a * 0 ≣ 0 *-killʳ zero = ≣-refl *-killʳ (suc y) = *-killʳ y *-idˡ : ∀ a → 1 * a ≣ a *-idˡ a = +-idʳ a *-idʳ : ∀ a → a * 1 ≣ a *-idʳ zero = ≣-refl *-idʳ (suc y) = ≣-cong suc (*-idʳ y) *-dist-+ˡ : ∀ a b c → a * (b + c) ≣ a * b + a * c *-dist-+ˡ zero b c = ≣-refl *-dist-+ˡ (suc y) b c = begin (b + c) + y * (b + c) ≈⟨ ≣-cong (_+_ (b + c)) (*-dist-+ˡ y b c) ⟩ (b + c) + y * b + y * c ≈⟨ +-assocʳ (b + c) (y * b) (y * c) ⟩ ((b + c) + y * b) + y * c ≈⟨ ≣-cong (λ x → (x + y * b) + y * c) (+-comm b c) ⟩ ((c + b) + y * b) + y * c ≈⟨ ≣-cong (λ x → x + y * c) (+-assocˡ c b (y * b)) ⟩ (c + b + y * b) + y * c ≈⟨ ≣-cong (λ x → x + y * c) (+-comm c (b + y * b)) ⟩ ((b + y * b) + c) + y * c ≈⟨ +-assocˡ (b + y * b) c (y * c) ⟩ (b + y * b) + c + y * c ∎ where open ≣-reasoning ℕ *-dist-+ʳ : ∀ a b c → (a + b) * c ≣ a * c + b * c *-dist-+ʳ zero b c = ≣-refl *-dist-+ʳ (suc y) b c = ≣-trans (+-assocʳ c (y * c) (b * c)) (≣-cong (_+_ c) (*-dist-+ʳ y b c)) *-assocˡ : ∀ a b c → (a * b) * c ≣ a * (b * c) *-assocˡ zero b c = ≣-refl *-assocˡ (suc y) b c = ≣-trans (≣-cong (_+_ (b * c)) (*-assocˡ y b c)) (*-dist-+ʳ b (y * b) c) *-assocʳ : ∀ a b c → (a * b) * c ≣ a * (b * c) *-assocʳ zero b c = ≣-refl *-assocʳ (suc y) b c = ≣-trans (≣-cong (_+_ (b * c)) (*-assocʳ y b c)) (*-dist-+ʳ b (y * b) c) *-sucˡ : ∀ a b → (suc a) * b ≣ b + a * b *-sucˡ a b = ≣-refl *-sucʳ : ∀ a b → a * (suc b) ≣ a + a * b *-sucʳ zero b = ≣-refl *-sucʳ (suc y) b = ≣-cong suc ( begin b + y * suc b ≈⟨ ≣-cong (_+_ b) (*-sucʳ y b) ⟩ b + y + y * b ≈⟨ +-assocʳ b y (y * b) ⟩ (b + y) + y * b ≈⟨ ≣-cong (λ x → x + y * b) (+-comm b y) ⟩ (y + b) + y * b ≈⟨ +-assocˡ y b (y * b) ⟩ y + b + y * b ∎) where open ≣-reasoning ℕ *-comm : ∀ a b → a * b ≣ b * a *-comm a zero = *-killʳ a *-comm a (suc y) = begin a * suc y ≈⟨ *-sucʳ a y ⟩ a + a * y ≈⟨ ≣-cong (_+_ a) (*-comm a y) ⟩ a + y * a ∎ where open ≣-reasoning ℕ <-irref : ∀ {n} → ¬ (n < n) <-irref (raise< n<m) = <-irref n<m <-trans : ∀ {l m n} → (l < m) → (m < n) → (l < n) <-trans Z<Sn (raise< n<m) = Z<Sn <-trans (raise< n<m) (raise< n<m') = raise< (<-trans n<m n<m') <-trans-assoc : ∀ {a b c d} → {a<b : a < b} {b<c : b < c} {c<d : c < d} → <-trans a<b (<-trans b<c c<d) ≣ <-trans (<-trans a<b b<c) c<d <-trans-assoc {a<b = Z<Sn} {raise< b<c} {raise< c<d} = ≣-refl <-trans-assoc {a<b = raise< a<b} {raise< b<c} {raise< c<d} = ≣-cong raise< <-trans-assoc <-unsucʳ : ∀ {m n} → m < suc n → Either (m ≣ n) (m < n) <-unsucʳ (Z<Sn {zero}) = inl ≣-refl <-unsucʳ (Z<Sn {suc y}) = inr Z<Sn <-unsucʳ (raise< {n} {zero} ()) <-unsucʳ (raise< {n} {suc y} n<m) = (≣-cong suc +++ raise<) (<-unsucʳ n<m) <-unsucˡ : ∀ {m n} → suc m < n → m < n <-unsucˡ (raise< {zero} Z<Pn) = Z<Sn <-unsucˡ (raise< {suc y} Sy<Pn) = raise< (<-unsucˡ Sy<Pn) <-sucˡ : ∀ {m n} → m < n → Either (suc m ≣ n) (suc m < n) <-sucˡ (Z<Sn {zero}) = inl ≣-refl <-sucˡ (Z<Sn {suc y}) = inr (raise< Z<Sn) <-sucˡ (raise< n<m) = (≣-cong suc +++ raise<) (<-sucˡ n<m) <-sucʳ : ∀ {m n} → m < n → m < suc n <-sucʳ Z<Sn = Z<Sn <-sucʳ (raise< Pm<Pn) = raise< (<-sucʳ Pm<Pn)
27.90625
135
0.427324
35dbec72e613f68e6c471d21574964a222cec8a4
1,498
agda
Agda
src/fot/FOTC/Data/Stream/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Stream/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Stream/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- The FOTC streams type ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Stream.Type where open import FOTC.Base open import FOTC.Base.List ------------------------------------------------------------------------------ -- The FOTC streams type (co-inductive predicate for total streams). -- Functional for the Stream predicate. -- StreamF : (D → Set) → D → Set -- StreamF A xs = ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs' -- Stream is the greatest fixed-point of StreamF (by Stream-out and -- Stream-coind). postulate Stream : D → Set postulate -- Stream is a post-fixed point of StreamF, i.e. -- -- Stream ≤ StreamF Stream. Stream-out : ∀ {xs} → Stream xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs' {-# ATP axiom Stream-out #-} -- Stream is the greatest post-fixed point of StreamF, i.e. -- -- ∀ A. A ≤ StreamF A ⇒ A ≤ Stream. -- -- N.B. This is an axiom schema. Because in the automatic proofs we -- *must* use an instance, we do not add this postulate as an ATP -- axiom. postulate Stream-coind : (A : D → Set) → -- A is post-fixed point of StreamF. (∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs') → -- Stream is greater than A. ∀ {xs} → A xs → Stream xs
31.208333
79
0.497997
30c3e330b1f3272496af02f520e18a29f05f1144
2,387
agda
Agda
src/CF/Transform/Compile/Statements.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
6
2020-10-07T14:07:17.000Z
2021-02-28T21:49:08.000Z
src/CF/Transform/Compile/Statements.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
null
null
null
src/CF/Transform/Compile/Statements.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
1
2021-12-28T17:37:15.000Z
2021-12-28T17:37:15.000Z
{-# OPTIONS --safe --no-qualified-instances #-} module CF.Transform.Compile.Statements where open import Function using (_∘_) open import Data.Unit using (⊤; tt) open import Data.Product open import Data.List hiding (null; [_]) open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Unary open import Relation.Unary.PredicateTransformer using (Pt) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax open import Relation.Ternary.Monad open import CF.Syntax.DeBruijn open import CF.Transform.Compile.Expressions open import CF.Types open import CF.Transform.Compile.ToJVM open import JVM.Types open import JVM.Compiler open import JVM.Contexts open import JVM.Model StackTy open import JVM.Syntax.Values open import JVM.Syntax.Instructions mutual {- Compiling statements -} compileₛ : ∀ {ψ : StackTy} {Γ r} → Stmt r Γ → ε[ Compiler ⟦ Γ ⟧ ψ ψ Emp ] compileₛ (asgn x e) = do compileₑ e code (store ⟦ x ⟧) compileₛ (run e) = do compileₑ e code pop compileₛ (block x) = do compiler _ x compileₛ (while e body) = do -- condition lcond⁺ ∙⟨ σ ⟩ lcond⁻ ← freshLabel refl ∙⟨ σ ⟩ lcond⁻ ← attachTo lcond⁺ ⟨ ∙-idʳ ⟩ compileₑ e ⟨ Down _ # σ ⟩& lcond⁻ (↓ lend⁻) ∙⟨ σ ⟩ labels ← (✴-rotateₗ ∘ ✴-assocᵣ) ⟨$⟩ (freshLabel ⟨ Down _ # σ ⟩& lcond⁻) (↓ lcond⁻) ∙⟨ σ ⟩ lend⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (if eq lend⁻) ⟨ _ ✴ _ # σ ⟩& labels) -- body compileₛ body lend⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (goto lcond⁻) ⟨ Up _ # σ ⟩& lend⁺) attach lend⁺ compileₛ (ifthenelse c e₁ e₂) = do -- condition compileₑ c lthen+ ∙⟨ σ ⟩ ↓ lthen- ← freshLabel lthen+ ← ✴-id⁻ˡ ⟨$⟩ (code (if ne lthen-) ⟨ Up _ # ∙-comm σ ⟩& lthen+) -- else compileₛ e₂ ↓ lend- ∙⟨ σ ⟩ labels ← (✴-rotateₗ ∘ ✴-assocᵣ) ⟨$⟩ (freshLabel ⟨ Up _ # ∙-idˡ ⟩& lthen+) -- then lthen+ ∙⟨ σ ⟩ lend+ ← ✴-id⁻ˡ ⟨$⟩ (code (goto lend-) ⟨ _ ✴ _ # σ ⟩& labels) lend+ ← ✴-id⁻ˡ ⟨$⟩ (attach lthen+ ⟨ Up _ # σ ⟩& lend+) compileₛ e₁ -- label the end attach lend+ {- Compiling blocks -} compiler : ∀ (ψ : StackTy) {Γ r} → Block r Γ → ε[ Compiler ⟦ Γ ⟧ ψ ψ Emp ] compiler ψ (nil) = do return refl compiler ψ (s ⍮⍮ b) = do compileₛ s compiler _ b
29.109756
102
0.600335
1e87fdfe1a825fb5d2f855db728a9d8b6eb8d232
444
agda
Agda
src/MLib/Matrix/Core.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
src/MLib/Matrix/Core.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
src/MLib/Matrix/Core.agda
bch29/agda-matrices
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
[ "MIT" ]
null
null
null
module MLib.Matrix.Core where open import MLib.Prelude open import MLib.Algebra.PropertyCode open import MLib.Algebra.PropertyCode.Structures import Relation.Binary.Indexed as I Matrix : ∀ {a} → Set a → ℕ → ℕ → Set a Matrix A m n = Fin m → Fin n → A module _ {a} (A : Set a) where row : ∀ {m n} → Fin m → Matrix A m n → Table A n row i M .lookup j = M i j col : ∀ {m n} → Fin n → Matrix A m n → Table A m col j M .lookup i = M i j
24.666667
50
0.641892
2115bbbafd5bae1a0cd474dff0c6516b1570cada
12,627
agda
Agda
Cubical/Algebra/DistLattice/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Algebra/DistLattice/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Algebra/DistLattice/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.DistLattice.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.Semilattice open import Cubical.Algebra.Lattice.Base open Iso private variable ℓ ℓ' : Level record IsDistLattice {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) : Type ℓ where constructor isdistlattice field isLattice : IsLattice 0l 1l _∨l_ _∧l_ ∨l-dist-∧l : (x y z : L) → (x ∨l (y ∧l z) ≡ (x ∨l y) ∧l (x ∨l z)) × ((y ∧l z) ∨l x ≡ (y ∨l x) ∧l (z ∨l x)) ∧l-dist-∨l : (x y z : L) → (x ∧l (y ∨l z) ≡ (x ∧l y) ∨l (x ∧l z)) × ((y ∨l z) ∧l x ≡ (y ∧l x) ∨l (z ∧l x)) open IsLattice isLattice public ∨lLdist∧l : (x y z : L) → x ∨l (y ∧l z) ≡ (x ∨l y) ∧l (x ∨l z) ∨lLdist∧l x y z = ∨l-dist-∧l x y z .fst ∨lRdist∧l : (x y z : L) → (y ∧l z) ∨l x ≡ (y ∨l x) ∧l (z ∨l x) ∨lRdist∧l x y z = ∨l-dist-∧l x y z .snd ∧lLdist∨l : (x y z : L) → x ∧l (y ∨l z) ≡ (x ∧l y) ∨l (x ∧l z) ∧lLdist∨l x y z = ∧l-dist-∨l x y z .fst ∧lRdist∨l : (x y z : L) → (y ∨l z) ∧l x ≡ (y ∧l x) ∨l (z ∧l x) ∧lRdist∨l x y z = ∧l-dist-∨l x y z .snd record DistLatticeStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor distlatticestr field 0l : A 1l : A _∨l_ : A → A → A _∧l_ : A → A → A isDistLattice : IsDistLattice 0l 1l _∨l_ _∧l_ infix 7 _∨l_ infix 6 _∧l_ open IsDistLattice isDistLattice public DistLattice : ∀ ℓ → Type (ℓ-suc ℓ) DistLattice ℓ = TypeWithStr ℓ DistLatticeStr isSetDistLattice : (L : DistLattice ℓ) → isSet ⟨ L ⟩ isSetDistLattice L = L .snd .DistLatticeStr.is-set -- when proving the axioms for a distributive lattice -- we use the fact that from distributivity and absorption -- of ∧l over ∨l we can derive distributivity and absorption -- of ∨l over ∧l and vice versa. We give provide thus two -- ways of making a distributive lattice... makeIsDistLattice∧lOver∨l : {L : Type ℓ} {0l 1l : L} {_∨l_ _∧l_ : L → L → L} (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) (∧l-ldist-∨l : (x y z : L) → x ∧l (y ∨l z) ≡ (x ∧l y) ∨l (x ∧l z)) → IsDistLattice 0l 1l _∨l_ _∧l_ makeIsDistLattice∧lOver∨l {_∨l_ = _∨l_} {_∧l_ = _∧l_} is-setL ∨l-assoc ∨l-rid ∨l-comm ∧l-assoc ∧l-rid ∧l-comm ∧l-absorb-∨l ∧l-ldist-∨l = isdistlattice (makeIsLattice is-setL ∨l-assoc ∨l-rid (λ x → ∨l-comm _ x ∙ ∨l-rid x) ∨l-comm ∧l-assoc ∧l-rid (λ x → ∧l-comm _ x ∙ ∧l-rid x) ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l) (λ x y z → ∨l-ldist-∧l _ _ _ , ∨l-rdist-∧l _ _ _) (λ x y z → ∧l-ldist-∨l _ _ _ , ∧l-rdist-∨l _ _ _) where ∧l-idem : ∀ x → x ∧l x ≡ x ∧l-idem x = cong (x ∧l_) (sym (∨l-rid _)) ∙ ∧l-absorb-∨l _ _ ∨l-absorb-∧l : ∀ x y → x ∨l (x ∧l y) ≡ x ∨l-absorb-∧l x y = cong (_∨l (x ∧l y)) (sym (∧l-idem _)) ∙∙ sym (∧l-ldist-∨l _ _ _) ∙∙ ∧l-absorb-∨l _ _ ∧l-rdist-∨l : ∀ x y z → (y ∨l z) ∧l x ≡ (y ∧l x) ∨l (z ∧l x) ∧l-rdist-∨l _ _ _ = ∧l-comm _ _ ∙∙ ∧l-ldist-∨l _ _ _ ∙∙ cong₂ (_∨l_) (∧l-comm _ _) (∧l-comm _ _) ∨l-ldist-∧l : ∀ x y z → x ∨l (y ∧l z) ≡ (x ∨l y) ∧l (x ∨l z) ∨l-ldist-∧l x y z = x ∨l (y ∧l z) ≡⟨ cong (_∨l (y ∧l z)) (sym (∨l-absorb-∧l _ _)) ⟩ (x ∨l (x ∧l z)) ∨l (y ∧l z) ≡⟨ sym (∨l-assoc _ _ _) ⟩ x ∨l ((x ∧l z) ∨l (y ∧l z)) ≡⟨ cong (_∨l ((x ∧l z) ∨l (y ∧l z))) (sym (∧l-comm _ _ ∙ ∧l-absorb-∨l _ _)) ⟩ ((x ∨l y) ∧l x) ∨l ((x ∧l z) ∨l (y ∧l z)) ≡⟨ cong (((x ∨l y) ∧l x) ∨l_) (sym (∧l-rdist-∨l _ _ _)) ⟩ ((x ∨l y) ∧l x) ∨l ((x ∨l y) ∧l z) ≡⟨ sym (∧l-ldist-∨l _ _ _) ⟩ (x ∨l y) ∧l (x ∨l z) ∎ ∨l-rdist-∧l : ∀ x y z → (y ∧l z) ∨l x ≡ (y ∨l x) ∧l (z ∨l x) ∨l-rdist-∧l x y z = ∨l-comm _ x ∙∙ ∨l-ldist-∧l _ _ _ ∙∙ cong₂ (_∧l_) (∨l-comm _ _) (∨l-comm _ _) makeDistLattice∧lOver∨l : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) (∧l-ldist-∨l : (x y z : L) → x ∧l (y ∨l z) ≡ (x ∧l y) ∨l (x ∧l z)) → DistLattice ℓ makeDistLattice∧lOver∨l 0l 1l _∨l_ _∧l_ is-setL ∨l-assoc ∨l-rid ∨l-comm ∧l-assoc ∧l-rid ∧l-comm ∧l-absorb-∨l ∧l-ldist-∨l = _ , distlatticestr _ _ _ _ (makeIsDistLattice∧lOver∨l is-setL ∨l-assoc ∨l-rid ∨l-comm ∧l-assoc ∧l-rid ∧l-comm ∧l-absorb-∨l ∧l-ldist-∨l) makeIsDistLattice∨lOver∧l : {L : Type ℓ} {0l 1l : L} {_∨l_ _∧l_ : L → L → L} (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∨l-ldist-∧l : (x y z : L) → x ∨l (y ∧l z) ≡ (x ∨l y) ∧l (x ∨l z)) → IsDistLattice 0l 1l _∨l_ _∧l_ makeIsDistLattice∨lOver∧l {_∨l_ = _∨l_} {_∧l_ = _∧l_} is-setL ∨l-assoc ∨l-rid ∨l-comm ∧l-assoc ∧l-rid ∧l-comm ∨l-absorb-∧l ∨l-ldist-∧l = isdistlattice (makeIsLattice is-setL ∨l-assoc ∨l-rid (λ x → ∨l-comm _ x ∙ ∨l-rid x) ∨l-comm ∧l-assoc ∧l-rid (λ x → ∧l-comm _ x ∙ ∧l-rid x) ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l) (λ x y z → ∨l-ldist-∧l _ _ _ , ∨l-rdist-∧l _ _ _) (λ x y z → ∧l-ldist-∨l _ _ _ , ∧l-rdist-∨l _ _ _) where ∨l-idem : ∀ x → x ∨l x ≡ x ∨l-idem x = cong (x ∨l_) (sym (∧l-rid _)) ∙ ∨l-absorb-∧l _ _ ∧l-absorb-∨l : ∀ x y → x ∧l (x ∨l y) ≡ x ∧l-absorb-∨l x y = cong (_∧l (x ∨l y)) (sym (∨l-idem _)) ∙∙ sym (∨l-ldist-∧l _ _ _) ∙∙ ∨l-absorb-∧l _ _ ∨l-rdist-∧l : ∀ x y z → (y ∧l z) ∨l x ≡ (y ∨l x) ∧l (z ∨l x) ∨l-rdist-∧l _ _ _ = ∨l-comm _ _ ∙∙ ∨l-ldist-∧l _ _ _ ∙∙ cong₂ (_∧l_) (∨l-comm _ _) (∨l-comm _ _) ∧l-ldist-∨l : ∀ x y z → x ∧l (y ∨l z) ≡ (x ∧l y) ∨l (x ∧l z) ∧l-ldist-∨l x y z = x ∧l (y ∨l z) ≡⟨ cong (_∧l (y ∨l z)) (sym (∧l-absorb-∨l _ _)) ⟩ (x ∧l (x ∨l z)) ∧l (y ∨l z) ≡⟨ sym (∧l-assoc _ _ _) ⟩ x ∧l ((x ∨l z) ∧l (y ∨l z)) ≡⟨ cong (_∧l ((x ∨l z) ∧l (y ∨l z))) (sym (∨l-comm _ _ ∙ ∨l-absorb-∧l _ _)) ⟩ ((x ∧l y) ∨l x) ∧l ((x ∨l z) ∧l (y ∨l z)) ≡⟨ cong (((x ∧l y) ∨l x) ∧l_) (sym (∨l-rdist-∧l _ _ _)) ⟩ ((x ∧l y) ∨l x) ∧l ((x ∧l y) ∨l z) ≡⟨ sym (∨l-ldist-∧l _ _ _) ⟩ (x ∧l y) ∨l (x ∧l z) ∎ ∧l-rdist-∨l : ∀ x y z → (y ∨l z) ∧l x ≡ (y ∧l x) ∨l (z ∧l x) ∧l-rdist-∨l x y z = ∧l-comm _ x ∙∙ ∧l-ldist-∨l _ _ _ ∙∙ cong₂ (_∨l_) (∧l-comm _ _) (∧l-comm _ _) makeDistLattice∨lOver∧l : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∨l-ldist-∧l : (x y z : L) → x ∨l (y ∧l z) ≡ (x ∨l y) ∧l (x ∨l z)) → DistLattice ℓ makeDistLattice∨lOver∧l 0l 1l _∨l_ _∧l_ is-setL ∨l-assoc ∨l-rid ∨l-comm ∧l-assoc ∧l-rid ∧l-comm ∨l-absorb-∧l ∨l-ldist-∧l = _ , distlatticestr _ _ _ _ (makeIsDistLattice∨lOver∧l is-setL ∨l-assoc ∨l-rid ∨l-comm ∧l-assoc ∧l-rid ∧l-comm ∨l-absorb-∧l ∨l-ldist-∧l) DistLatticeStr→LatticeStr : {A : Type ℓ} → DistLatticeStr A → LatticeStr A DistLatticeStr→LatticeStr (distlatticestr _ _ _ _ H) = latticestr _ _ _ _ (IsDistLattice.isLattice H) DistLattice→Lattice : DistLattice ℓ → Lattice ℓ DistLattice→Lattice (_ , distlatticestr _ _ _ _ H) = _ , latticestr _ _ _ _ (IsDistLattice.isLattice H) DistLatticeHom : (L : DistLattice ℓ) (M : DistLattice ℓ') → Type (ℓ-max ℓ ℓ') DistLatticeHom L M = LatticeHom (DistLattice→Lattice L) (DistLattice→Lattice M) IsDistLatticeEquiv : {A : Type ℓ} {B : Type ℓ'} (L : DistLatticeStr A) (e : A ≃ B) (M : DistLatticeStr B) → Type (ℓ-max ℓ ℓ') IsDistLatticeEquiv L e M = IsLatticeHom (DistLatticeStr→LatticeStr L) (e .fst) (DistLatticeStr→LatticeStr M) DistLatticeEquiv : (L : DistLattice ℓ) (M : DistLattice ℓ') → Type (ℓ-max ℓ ℓ') DistLatticeEquiv L M = Σ[ e ∈ (L .fst ≃ M .fst) ] IsDistLatticeEquiv (L .snd) e (M .snd) isPropIsDistLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) → isProp (IsDistLattice 0l 1l _∨l_ _∧l_) isPropIsDistLattice 0l 1l _∨l_ _∧l_ (isdistlattice LL LD1 LD2) (isdistlattice ML MD1 MD2) = λ i → isdistlattice (isPropIsLattice _ _ _ _ LL ML i) (isPropDist1 LD1 MD1 i) (isPropDist2 LD2 MD2 i) where isSetL : isSet _ isSetL = LL .IsLattice.joinSemilattice .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set isPropDist1 : isProp ((x y z : _) → (x ∨l (y ∧l z) ≡ (x ∨l y) ∧l (x ∨l z)) × ((y ∧l z) ∨l x ≡ (y ∨l x) ∧l (z ∨l x))) isPropDist1 = isPropΠ3 (λ _ _ _ → isProp× (isSetL _ _) (isSetL _ _)) isPropDist2 : isProp ((x y z : _) → (x ∧l (y ∨l z) ≡ (x ∧l y) ∨l (x ∧l z)) × ((y ∨l z) ∧l x ≡ (y ∧l x) ∨l (z ∧l x))) isPropDist2 = isPropΠ3 (λ _ _ _ → isProp× (isSetL _ _) (isSetL _ _)) 𝒮ᴰ-DistLattice : DUARel (𝒮-Univ ℓ) DistLatticeStr ℓ 𝒮ᴰ-DistLattice = 𝒮ᴰ-Record (𝒮-Univ _) IsDistLatticeEquiv (fields: data[ 0l ∣ null ∣ pres0 ] data[ 1l ∣ null ∣ pres1 ] data[ _∨l_ ∣ bin ∣ pres∨l ] data[ _∧l_ ∣ bin ∣ pres∧l ] prop[ isDistLattice ∣ (λ _ _ → isPropIsDistLattice _ _ _ _) ]) where open DistLatticeStr open IsLatticeHom -- faster with some sharing null = autoDUARel (𝒮-Univ _) (λ A → A) bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A) DistLatticePath : (L M : DistLattice ℓ) → DistLatticeEquiv L M ≃ (L ≡ M) DistLatticePath = ∫ 𝒮ᴰ-DistLattice .UARel.ua
46.083942
100
0.448246
0380b5571c17025d892f61eadea7842f06dcb67c
822
agda
Agda
test/asset/agda-stdlib-1.0/Codata/Stream/Categorical.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
test/asset/agda-stdlib-1.0/Codata/Stream/Categorical.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Codata/Stream/Categorical.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- A categorical view of Stream ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Codata.Stream.Categorical where open import Data.Product using (<_,_>) open import Codata.Stream open import Function open import Category.Functor open import Category.Applicative open import Category.Comonad functor : ∀ {ℓ i} → RawFunctor {ℓ} (λ A → Stream A i) functor = record { _<$>_ = λ f → map f } applicative : ∀ {ℓ i} → RawApplicative {ℓ} (λ A → Stream A i) applicative = record { pure = repeat ; _⊛_ = ap } comonad : ∀ {ℓ} → RawComonad {ℓ} (λ A → Stream A _) comonad = record { extract = head ; extend = unfold ∘′ < tail ,_> }
25.6875
72
0.542579
0427caea7f047b8c8070f41f8645bb294474ac3a
1,646
agda
Agda
agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Def.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Def.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Def.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Def where open import Prelude hiding (⊥; ⊤) open import Algebra.Construct.Free.Semilattice.Eliminators open import Algebra.Construct.Free.Semilattice.Definition open import Cubical.Foundations.HLevels open import Data.Empty.UniversePolymorphic open import HITs.PropositionalTruncation.Sugar open import HITs.PropositionalTruncation.Properties open import HITs.PropositionalTruncation open import Data.Unit.UniversePolymorphic private variable p : Level dup-◇ : (P : A → Type p) → (x : A) (xs : Type p) → ∥ P x ⊎ ∥ P x ⊎ xs ∥ ∥ ⇔ ∥ P x ⊎ xs ∥ dup-◇ P x xs .inv p = ∣ inr p ∣ dup-◇ P x xs .fun ps = ps >>= either (∣_∣ ∘ inl) id dup-◇ P x xs .leftInv p = squash _ p dup-◇ P x xs .rightInv p = squash p _ swap-◇ : {x y xs : Type p} → ∥ x ⊎ ∥ y ⊎ xs ∥ ∥ → ∥ y ⊎ ∥ x ⊎ xs ∥ ∥ swap-◇ p = p >>= either′ (∣_∣ ∘ inr ∘ ∣_∣ ∘ inl) (mapʳ (∣_∣ ∘ inr) ∥$∥_) com-◇ : (P : A → Type p) → (x y : A) (xs : Type p) → ∥ P x ⊎ ∥ P y ⊎ xs ∥ ∥ ⇔ ∥ P y ⊎ ∥ P x ⊎ xs ∥ ∥ com-◇ P y z xs .fun = swap-◇ com-◇ P y z xs .inv = swap-◇ com-◇ P y z xs .leftInv p = squash _ p com-◇ P y z xs .rightInv p = squash _ p ◇′ : (P : A → Type p) → 𝒦 A → hProp p ◇′ P = 𝒦-rec isSetHProp (λ { x (xs , _) → ∥ P x ⊎ xs ∥ , squash }) (⊥ , λ ()) (λ x xs → ΣProp≡ (λ _ → isPropIsProp) (isoToPath (dup-◇ P x (xs .fst)))) (λ x y xs → ΣProp≡ (λ _ → isPropIsProp) (isoToPath (com-◇ P x y (xs .fst)))) {-# INLINE ◇′ #-} ◇ : (P : A → Type p) → 𝒦 A → Type p ◇ P xs = ◇′ P xs .fst isProp-◇ : ∀ {P : A → Type p} {xs} → isProp (◇ P xs) isProp-◇ {P = P} {xs = xs} = ◇′ P xs .snd
34.291667
100
0.572904
19487340df17ceacb6700c8808a3e7ab2be3d724
8,810
agda
Agda
src/Equality/Groupoid.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/Equality/Groupoid.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/Equality/Groupoid.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The equality can be turned into a groupoid which is sometimes -- commutative ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Equality.Groupoid {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where open import Bijection eq using (_↔_) open Derived-definitions-and-properties eq open import Equality.Tactic eq open import Groupoid eq open import Pointed-type eq open import Prelude hiding (id; _∘_) ------------------------------------------------------------------------ -- _≡_ comes with a groupoid structure groupoid : ∀ {a} (A : Type a) → Groupoid a a groupoid A = record { Object = A ; _∼_ = _≡_ ; id = refl _ ; _∘_ = flip trans ; _⁻¹ = sym ; left-identity = trans-reflʳ ; right-identity = trans-reflˡ ; assoc = λ z≡u y≡z x≡y → trans-assoc x≡y y≡z z≡u ; left-inverse = trans-symʳ ; right-inverse = trans-symˡ } ------------------------------------------------------------------------ -- In some cases transitivity is commutative -- This proof is based on an informal proof due to Thierry Coquand, -- based on a result from homotopy theory. module Transitivity-commutative {a} {A : Type a} (e : A) (_∙_ : A → A → A) (left-identity : ∀ x → (e ∙ x) ≡ x) (right-identity : ∀ x → (x ∙ e) ≡ x) where open Groupoid (groupoid A) hiding (left-identity; right-identity) abstract commutative : (p q : e ≡ e) → p ∘ q ≡ q ∘ p commutative p q = p ∘ q ≡⟨ cong (_∘_ p) (lem₁ _) ⟩ p ∘ (ri ∘ li ⁻¹ ∘ q′ ∘ li ∘ ri ⁻¹) ≡⟨ prove (Trans (Trans (Trans (Trans (Trans (Sym (Lift ri)) (Lift li)) (Lift q′)) (Sym (Lift li))) (Lift ri)) (Lift p)) (Trans (Trans (Sym (Lift ri)) (Trans (Trans (Lift li) (Lift q′)) (Sym (Lift li)))) (Trans (Lift ri) (Lift p))) (refl _) ⟩ (p ∘ ri) ∘ (li ⁻¹ ∘ q′ ∘ li) ∘ ri ⁻¹ ≡⟨ cong₂ (λ p q → p ∘ q ∘ ri ⁻¹) (lem₂ _) (lem₃ _) ⟩ (ri ∘ lc p) ∘ rc q′ ∘ ri ⁻¹ ≡⟨ prove (Trans (Trans (Sym (Lift ri)) (Lift (rc q′))) (Trans (Lift (lc p)) (Lift ri))) (Trans (Trans (Sym (Lift ri)) (Trans (Lift (rc q′)) (Lift (lc p)))) (Lift ri)) (refl _) ⟩ ri ∘ (lc p ∘ rc q′) ∘ ri ⁻¹ ≡⟨ cong (λ p → ri ∘ p ∘ ri ⁻¹) (lem₄ _ _) ⟩ ri ∘ (rc q′ ∘ lc p) ∘ ri ⁻¹ ≡⟨ prove (Trans (Trans (Sym (Lift ri)) (Trans (Lift (lc p)) (Lift (rc q′)))) (Lift ri)) (Trans (Trans (Trans (Sym (Lift ri)) (Lift (lc p))) (Lift (rc q′))) (Lift ri)) (refl _) ⟩ ri ∘ rc q′ ∘ (lc p ∘ ri ⁻¹) ≡⟨ cong₂ (λ p q → ri ∘ p ∘ q) (sym (lem₃ _)) (lem₅ _) ⟩ ri ∘ (li ⁻¹ ∘ q′ ∘ li) ∘ (ri ⁻¹ ∘ p) ≡⟨ prove (Trans (Trans (Trans (Lift p) (Sym (Lift ri))) (Trans (Trans (Lift li) (Lift q′)) (Sym (Lift li)))) (Lift ri)) (Trans (Lift p) (Trans (Trans (Trans (Trans (Sym (Lift ri)) (Lift li)) (Lift q′)) (Sym (Lift li))) (Lift ri))) (refl _) ⟩ (ri ∘ li ⁻¹ ∘ q′ ∘ li ∘ ri ⁻¹) ∘ p ≡⟨ cong (λ q → q ∘ p) (sym (lem₁ _)) ⟩∎ q ∘ p ∎ where -- Abbreviations. li : ∀ {x} → (e ∙ x) ≡ x li = left-identity _ ri : ∀ {x} → (x ∙ e) ≡ x ri = right-identity _ q′ : e ≡ e q′ = li ∘ ri ⁻¹ ∘ q ∘ ri ∘ li ⁻¹ lc : ∀ {x y} → x ≡ y → (x ∙ e) ≡ (y ∙ e) lc = cong (λ x → (x ∙ e)) rc : ∀ {x y} → x ≡ y → (e ∙ x) ≡ (e ∙ y) rc = cong (λ y → (e ∙ y)) -- Lemmas. lem₁ : (p : e ≡ e) → p ≡ ri ∘ li ⁻¹ ∘ (li ∘ ri ⁻¹ ∘ p ∘ ri ∘ li ⁻¹) ∘ li ∘ ri ⁻¹ lem₁ p = p ≡⟨ prove (Lift p) (Trans (Trans Refl (Lift p)) Refl) (refl _) ⟩ refl _ ∘ p ∘ refl _ ≡⟨ sym (cong₂ (λ q r → q ∘ p ∘ r) (right-inverse _) (right-inverse _)) ⟩ (ri ∘ ri ⁻¹) ∘ p ∘ (ri ∘ ri ⁻¹) ≡⟨ prove (Trans (Trans (Trans (Sym (Lift ri)) (Lift ri)) (Lift p)) (Trans (Sym (Lift ri)) (Lift ri))) (Trans (Trans (Trans (Trans (Trans (Trans (Sym (Lift ri)) Refl) (Lift ri)) (Lift p)) (Sym (Lift ri))) Refl) (Lift ri)) (refl _) ⟩ ri ∘ refl _ ∘ ri ⁻¹ ∘ p ∘ ri ∘ refl _ ∘ ri ⁻¹ ≡⟨ sym (cong₂ (λ q r → ri ∘ q ∘ ri ⁻¹ ∘ p ∘ ri ∘ r ∘ ri ⁻¹) (left-inverse _) (left-inverse _)) ⟩ ri ∘ (li ⁻¹ ∘ li) ∘ ri ⁻¹ ∘ p ∘ ri ∘ (li ⁻¹ ∘ li) ∘ ri ⁻¹ ≡⟨ prove (Trans (Trans (Trans (Trans (Trans (Trans (Sym (Lift ri)) (Trans (Lift li) (Sym (Lift li)))) (Lift ri)) (Lift p)) (Sym (Lift ri))) (Trans (Lift li) (Sym (Lift li)))) (Lift ri)) (Trans (Trans (Trans (Trans (Sym (Lift ri)) (Lift li)) (Trans (Trans (Trans (Trans (Sym (Lift li)) (Lift ri)) (Lift p)) (Sym (Lift ri))) (Lift li))) (Sym (Lift li))) (Lift ri)) (refl _) ⟩∎ ri ∘ li ⁻¹ ∘ (li ∘ ri ⁻¹ ∘ p ∘ ri ∘ li ⁻¹) ∘ li ∘ ri ⁻¹ ∎ lem₂ : ∀ {x y} (p : x ≡ y) → p ∘ ri ≡ ri ∘ lc p lem₂ = elim (λ p → p ∘ ri ≡ ri ∘ lc p) λ _ → prove (Trans (Lift ri) Refl) (Trans (Cong (λ x → (x ∙ e)) Refl) (Lift ri)) (refl _) lem₃ : ∀ {x y} (p : x ≡ y) → li ⁻¹ ∘ p ∘ li ≡ rc p lem₃ = elim (λ p → li ⁻¹ ∘ p ∘ li ≡ rc p) λ x → li ⁻¹ ∘ refl x ∘ li ≡⟨ prove (Trans (Trans (Lift li) Refl) (Sym (Lift li))) (Trans (Lift li) (Sym (Lift li))) (refl _) ⟩ li ⁻¹ ∘ li ≡⟨ left-inverse _ ⟩ refl (e ∙ x) ≡⟨ prove Refl (Cong (λ y → (e ∙ y)) Refl) (refl _) ⟩∎ rc (refl x) ∎ lem₄ : (p q : e ≡ e) → lc p ∘ rc q ≡ rc q ∘ lc p lem₄ p q = elim (λ {x y} x≡y → lc x≡y ∘ cong (λ z → (x ∙ z)) q ≡ cong (λ z → (y ∙ z)) q ∘ lc x≡y) (λ x → prove (Trans (Cong (λ z → x ∙ z) (Lift q)) (Cong (λ x → x ∙ e) Refl)) (Trans (Cong (λ x → x ∙ e) Refl) (Cong (λ z → x ∙ z) (Lift q))) (refl _)) p lem₅ : ∀ {x y} (p : x ≡ y) → lc p ∘ ri ⁻¹ ≡ ri ⁻¹ ∘ p lem₅ = elim (λ p → lc p ∘ ri ⁻¹ ≡ ri ⁻¹ ∘ p) λ _ → prove (Trans (Sym (Lift ri)) (Cong (λ x → (x ∙ e)) Refl)) (Trans Refl (Sym (Lift ri))) (refl _) -- In particular, transitivity is commutative for proofs in -- proj₁ (Ω[ 2 + n ] X). Ω[2+n]-commutative : ∀ {x} {X : Pointed-type x} n → (p q : proj₁ (Ω[ 2 + n ] X)) → trans p q ≡ trans q p Ω[2+n]-commutative {X = X} n p q = Transitivity-commutative.commutative id _∘_ left-identity right-identity q p where open Groupoid (groupoid (proj₁ (Ω[ n ] X)))
51.22093
135
0.332804
c726d389ffe79c3930b236b6380a14ce84fc10a6
365
agda
Agda
cohesion/david_jaz_261/Axiom/C0.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
6
2021-10-06T17:39:22.000Z
2022-02-13T05:51:12.000Z
cohesion/david_jaz_261/Axiom/C0.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
cohesion/david_jaz_261/Axiom/C0.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} open import Basics open import lib.Basics open import Flat module Axiom.C0 {@♭ i j : ULevel} (@♭ I : Type i) (@♭ R : I → Type j) where postulate C0 : {@♭ k : ULevel} (@♭ A : Type k) (p : (index : I) → (is-equiv (λ (a : A) → λ (r : R index) → a))) → A is-discrete
30.416667
83
0.473973
1992c02cc3c453f8ee1120c8dc7bd6d343316dea
10,888
agda
Agda
Cubical/Data/DescendingList/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/DescendingList/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/DescendingList/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
------------------------------------------------------------------------ -- Descending lists -- -- Anders Mörtberg and Chuangjie Xu, October 2019 -- -- We define descending lists via simultaneous definitions and show -- that they are isomorphic to finite multisets. The conversion from -- finite multisets to descending lists is exactly insertion sort. We -- obtain the concatenation operation on descending lists and its -- properties by transporting those on finite multisets. ------------------------------------------------------------------------ {-# OPTIONS --safe #-} open import Cubical.Foundations.Everything open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Unit open import Cubical.Data.List using (List ; [] ; _∷_) open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq open import Cubical.HITs.FiniteMultiset as FMSet hiding ([_]) module Cubical.Data.DescendingList.Properties (A : Type₀) (_≥_ : A → A → Type₀) where open import Cubical.Data.DescendingList.Base A _≥_ toFMSet : DL → FMSet A toFMSet [] = [] toFMSet (cons x u _) = x ∷ toFMSet u toList : DL → List A toList [] = [] toList (cons x u _) = x ∷ toList u -- "x ≥ ALL the elements of u" data _≥ᴬ_ (x : A) : List A → Type₀ where ≥ᴬ[] : x ≥ᴬ [] ≥ᴬcons : {y : A} {u : List A} → x ≥ y → x ≥ᴬ u → x ≥ᴬ (y ∷ u) data descending : List A → Type₀ where []-descending : descending [] cons-descending : {x : A} {u : List A} → x ≥ᴬ u → descending u → descending (x ∷ u) module DescendingDL (≥trans : {x y z : A} → x ≥ y → y ≥ z → x ≥ z) where ≥≥ᴴtrans : {x y : A} {u : DL} → x ≥ y → y ≥ᴴ u → x ≥ᴴ u ≥≥ᴴtrans _ ≥ᴴ[] = ≥ᴴ[] ≥≥ᴴtrans x≥y (≥ᴴcons y≥z) = ≥ᴴcons (≥trans x≥y y≥z) ≥ᴴ→≥ᴬ : {x : A} {u : DL} → x ≥ᴴ u → x ≥ᴬ toList u ≥ᴴ→≥ᴬ ≥ᴴ[] = ≥ᴬ[] ≥ᴴ→≥ᴬ (≥ᴴcons {r = y≥u} x≥y) = ≥ᴬcons x≥y (≥ᴴ→≥ᴬ (≥≥ᴴtrans x≥y y≥u)) descendingDL : (u : DL) → descending (toList u) descendingDL [] = []-descending descendingDL (cons x u x≥u) = cons-descending (≥ᴴ→≥ᴬ x≥u) (descendingDL u) ------------------------------------------------------------------------ -- Descending lists are a set. head≡ : {x y : A} {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v} → cons x u r ≡ cons y v s → x ≡ y head≡ {x} = cong head where head : DL → A head [] = x head (cons z _ _) = z tail≡ : {x y : A} {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v} → cons x u r ≡ cons y v s → u ≡ v tail≡ = cong tail where tail : DL → DL tail [] = [] tail (cons _ u _) = u caseDL : ∀ {ℓ} → {X : Type ℓ} → (x y : X) → DL → X caseDL x y [] = x caseDL x y (cons _ _ _) = y []≢cons : {x : A} {u : DL} {r : x ≥ᴴ u} → ¬ ([] ≡ cons x u r) []≢cons p = subst (caseDL Unit ⊥) p tt cons≢[] : {x : A} {u : DL} {r : x ≥ᴴ u} → ¬ (cons x u r ≡ []) cons≢[] p = subst (caseDL ⊥ Unit) p tt module isSetDL (≥isPropValued : {x y : A} → isProp (x ≥ y)) (discreteA : Discrete A) where ≥ᴴisPropValued : {x : A} {u : DL} → isProp (x ≥ᴴ u) ≥ᴴisPropValued ≥ᴴ[] ≥ᴴ[] = refl ≥ᴴisPropValued (≥ᴴcons x≥y) (≥ᴴcons x≥y') = cong ≥ᴴcons (≥isPropValued x≥y x≥y') cons≡ : {x y : A} {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v} → x ≡ y → u ≡ v → cons x u r ≡ cons y v s cons≡ {x} p = subst P p d where P : A → Type₀ P y = {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v} → u ≡ v → cons x u r ≡ cons y v s d : P x d {u} q = subst Q q c where Q : (v : DL) → Type₀ Q v = {r : x ≥ᴴ u} {s : x ≥ᴴ v} → cons x u r ≡ cons x v s c : Q u c = cong (cons x u) (≥ᴴisPropValued _ _) discreteDL : Discrete DL discreteDL [] [] = yes refl discreteDL [] (cons y v s) = no []≢cons discreteDL (cons x u r) [] = no cons≢[] discreteDL (cons x u r) (cons y v s) with discreteA x y discreteDL (cons x u r) (cons y v s) | yes x≡y with discreteDL u v discreteDL (cons x u r) (cons y v s) | yes x≡y | yes u≡v = yes (cons≡ x≡y u≡v) discreteDL (cons x u r) (cons y v s) | yes x≡y | no u≢v = no (λ e → u≢v (tail≡ e)) discreteDL (cons x u r) (cons y v s) | no x≢y = no (λ e → x≢y (head≡ e)) isSetDL : isSet DL isSetDL = Discrete→isSet discreteDL ------------------------------------------------------------------------ -- Descending lists are isomorphic to finite multisets. module IsoToFMSet (discreteA : Discrete A) (≥dec : (x y : A) → Dec (x ≥ y)) (≥isPropValued : {x y : A} → isProp (x ≥ y)) (≥trans : {x y z : A} → x ≥ y → y ≥ z → x ≥ z) (≰→≥ : {x y : A} → ¬ (x ≥ y) → y ≥ x) (≤≥→≡ : {x y : A} → x ≥ y → y ≥ x → x ≡ y) where ------------------------------------------------------------------------ -- The insert function -- -- The type DL is defined simultaneously with the relation _≥ᴴ_. -- Hence the insert function has to be defined by simultaneously -- proving a property of _≥ᴴ_. insert : A → DL → DL ≥ᴴinsert : {x y : A} {u : DL} → y ≥ᴴ u → ¬ (x ≥ y) → y ≥ᴴ insert x u insert x [] = [ x ] insert x (cons y u r) with ≥dec x y insert x (cons y u r) | yes x≥y = cons x (cons y u r) (≥ᴴcons x≥y) insert x (cons y u r) | no x≱y = cons y (insert x u) (≥ᴴinsert r x≱y) ≥ᴴinsert ≥ᴴ[] x≱y = ≥ᴴcons (≰→≥ x≱y) ≥ᴴinsert {x} {y} {cons z u z≥u} (≥ᴴcons y≥z) x≱y with ≥dec x z ≥ᴴinsert {x} {y} {cons z u z≥u} (≥ᴴcons y≥z) x≱y | yes x≥z = ≥ᴴcons (≰→≥ x≱y) ≥ᴴinsert {x} {y} {cons z u z≥u} (≥ᴴcons y≥z) x≱y | no x≱z = ≥ᴴcons y≥z open isSetDL ≥isPropValued discreteA insert-swap : (x y : A) (u : DL) → insert x (insert y u) ≡ insert y (insert x u) insert-swap x y [] with ≥dec x y insert-swap x y [] | yes x≥y with ≥dec y x insert-swap x y [] | yes x≥y | yes y≥x = cons≡ (≤≥→≡ x≥y y≥x) (cons≡ (≤≥→≡ y≥x x≥y) refl) insert-swap x y [] | yes x≥y | no y≱x = cons≡ refl (cons≡ refl refl) insert-swap x y [] | no x≱y with ≥dec y x insert-swap x y [] | no x≱y | yes y≥x = cons≡ refl (cons≡ refl refl) insert-swap x y [] | no x≱y | no y≱x = ⊥.rec (x≱y (≰→≥ y≱x)) insert-swap x y (cons z u z≥u) with ≥dec y z insert-swap x y (cons z u z≥u) | yes y≥z with ≥dec x y insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y with ≥dec x z insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z with ≥dec y x insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | yes y≥x = cons≡ (≤≥→≡ x≥y y≥x) (cons≡ (≤≥→≡ y≥x x≥y) refl) insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | no y≱x with ≥dec y z insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | no y≱x | yes y≥z' = cons≡ refl (cons≡ refl refl) insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | no y≱x | no y≱z = ⊥.rec (y≱z y≥z) insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | no x≱z = ⊥.rec (x≱z (≥trans x≥y y≥z)) insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y with ≥dec x z insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | yes x≥z with ≥dec y x insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | yes x≥z | yes y≥x = cons≡ refl (cons≡ refl refl) insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | yes x≥z | no y≱x = ⊥.rec (x≱y (≰→≥ y≱x)) insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | no x≱z with ≥dec y z insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | no x≱z | yes y≥z' = cons≡ refl (cons≡ refl refl) insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | no x≱z | no y≱z = ⊥.rec (y≱z y≥z) insert-swap x y (cons z u z≥u) | no y≱z with ≥dec x z insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z with ≥dec y x insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | yes y≥x = ⊥.rec (y≱z (≥trans y≥x x≥z)) insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | no y≱x with ≥dec y z insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | no y≱x | yes y≥z = ⊥.rec (y≱z y≥z) insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | no y≱x | no y≱z' = cons≡ refl (cons≡ refl refl) insert-swap x y (cons z u z≥u) | no y≱z | no x≱z with ≥dec y z insert-swap x y (cons z u z≥u) | no y≱z | no x≱z | yes y≥z = ⊥.rec (y≱z y≥z) insert-swap x y (cons z u z≥u) | no y≱z | no x≱z | no y≱z' = cons≡ refl (insert-swap x y u) -- Insertion sort toDL : FMSet A → DL toDL = FMSet.Rec.f isSetDL [] insert insert-swap {- toDL [] = [] toDL (x ∷ u) = insert x (toDL u) toDL (comm x y u i) = insert-swap x y (toDL u) i toDL (trunc x y p q i j) = isSetDL (toDL x) (toDL y) (cong toDL p) (cong toDL q) i j -} insert-cons : (x : A) (u : DL) (r : x ≥ᴴ u) → insert x u ≡ cons x u r insert-cons x [] _ = cons≡ refl refl insert-cons x (cons y u _) _ with ≥dec x y insert-cons x (cons y u _) _ | yes x≥y = cons≡ refl refl insert-cons x (cons y u _) (≥ᴴcons x≥y) | no x≱y = ⊥.rec (x≱y x≥y) toDL∘toFMSet≡id : (u : DL) → toDL (toFMSet u) ≡ u toDL∘toFMSet≡id [] = refl toDL∘toFMSet≡id (cons x u r) i = hcomp (λ j → λ { (i = i0) → insert x (toDL∘toFMSet≡id u (~ j)) ; (i = i1) → cons x u r }) (insert-cons x u r i) insert-∷ : (x : A) (u : DL) → toFMSet (insert x u) ≡ x ∷ toFMSet u insert-∷ x [] = refl insert-∷ x (cons y u _) with ≥dec x y insert-∷ x (cons y u _) | yes x≥y = refl insert-∷ x (cons y u _) | no x≱y = cong (λ z → y ∷ z) (insert-∷ x u) ∙ comm y x (toFMSet u) toFMSet∘toDL≡id : (u : FMSet A) → toFMSet (toDL u) ≡ u toFMSet∘toDL≡id = FMSet.ElimProp.f (trunc _ _) refl (λ x {u} p → insert-∷ x (toDL u) ∙ cong (λ z → x ∷ z) p) FMSet≡DL : FMSet A ≡ DL FMSet≡DL = isoToPath (iso toDL toFMSet toDL∘toFMSet≡id toFMSet∘toDL≡id) ------------------------------------------------------------------------ -- Concatenation of sorted lists -- -- Defined by transporting the one on finite multisets infixr 30 _++ᴰᴸ_ _++ᴰᴸ_ : DL → DL → DL _++ᴰᴸ_ = transport (λ i → FMSet≡DL i → FMSet≡DL i → FMSet≡DL i) _++_ []Path : PathP (λ i → FMSet≡DL i) [] [] []Path i = transp (λ j → FMSet≡DL (i ∧ j)) (~ i) [] ++Path : PathP (λ i → FMSet≡DL i → FMSet≡DL i → FMSet≡DL i) _++_ _++ᴰᴸ_ ++Path i = transp (λ j → FMSet≡DL (i ∧ j) → FMSet≡DL (i ∧ j) → FMSet≡DL (i ∧ j)) (~ i) _++_ unitl-++ᴰᴸ : ∀ u → [] ++ᴰᴸ u ≡ u unitl-++ᴰᴸ = transport (λ i → (u : FMSet≡DL i) → ++Path i ([]Path i) u ≡ u) unitl-++ unitr-++ᴰᴸ : ∀ u → u ++ᴰᴸ [] ≡ u unitr-++ᴰᴸ = transport (λ i → (u : FMSet≡DL i) → ++Path i u ([]Path i) ≡ u) unitr-++ assoc-++ᴰᴸ : ∀ u v w → u ++ᴰᴸ (v ++ᴰᴸ w) ≡ (u ++ᴰᴸ v) ++ᴰᴸ w assoc-++ᴰᴸ = transport (λ i → (u v w : FMSet≡DL i) → ++Path i u (++Path i v w) ≡ ++Path i (++Path i u v) w) assoc-++ comm-++ᴰᴸ : ∀ u v → u ++ᴰᴸ v ≡ v ++ᴰᴸ u comm-++ᴰᴸ = transport (λ i → (u v : FMSet≡DL i) → ++Path i u v ≡ ++Path i v u) comm-++ ------------------------------------------------------------------------ -- Converting multisets to (descending) lists FMSet→List : FMSet A → List A FMSet→List u = toList (toDL u)
38.885714
122
0.506613
ad4dadd168e40de48e5a4d60082b7062d78d530b
2,420
agda
Agda
day-4/Day4.agda
Zalastax/adventofcode2017
37956e581dc51bf78008d7dd902bb18d2ee481f6
[ "MIT" ]
null
null
null
day-4/Day4.agda
Zalastax/adventofcode2017
37956e581dc51bf78008d7dd902bb18d2ee481f6
[ "MIT" ]
null
null
null
day-4/Day4.agda
Zalastax/adventofcode2017
37956e581dc51bf78008d7dd902bb18d2ee481f6
[ "MIT" ]
null
null
null
module Day4 where open import Prelude.String as String open import Data.Maybe open import Foreign.Haskell using (Unit) open import Prelude.List as List open import Data.Nat open import Data.Nat.DivMod open import Data.Nat.Properties import Data.Nat.Show as ℕs open import Prelude.Char open import Data.Vec as Vec renaming (_>>=_ to _VV=_ ; toList to VecToList) open import Data.Product open import Relation.Nullary open import Data.Nat.Properties open import Data.Bool.Base open import AocIO open import AocUtil open import AocVec open import Relation.Binary.PropositionalEquality open import EvenOdd count-falsy : List Bool → ℕ count-falsy ls = length (filter not ls) split-line : List Char → List String split-line ls with (words ls) ... | ls-words = List.map packString ls-words has-following-duplicates : List String → Bool has-following-duplicates [] = false has-following-duplicates (x ∷ []) = false has-following-duplicates (x ∷ y ∷ ls) with primStringEquality x y ... | false = has-following-duplicates (y ∷ ls) ... | true = true main : IO Unit main = mainBuilder (readFileMain process-file) where sort-word : String → String sort-word s with unpackString s ... | ls with sort ls ... | ls-sorted = packString ls-sorted is-valid-passphrase : List String → Bool is-valid-passphrase ls with List.map sort-word ls ... | sorted-words with sort sorted-words ... | ls-sorted = has-following-duplicates ls-sorted process-file : String → IO Unit process-file file-content with (lines (unpackString file-content)) ... | file-lines with (List.map split-line file-lines) ... | lines-split-into-words with (List.map is-valid-passphrase lines-split-into-words) ... | lines-are-valid with count-falsy lines-are-valid ... | valid-count = printString (ℕs.show valid-count) main2 : IO Unit main2 = mainBuilder (readFileMain process-file) where is-valid-passphrase : List String → Bool is-valid-passphrase ls with sort ls ... | ls-sorted = has-following-duplicates ls-sorted process-file : String → IO Unit process-file file-content with (lines (unpackString file-content)) ... | file-lines with (List.map split-line file-lines) ... | lines-split-into-words with (List.map is-valid-passphrase lines-split-into-words) ... | lines-are-valid with count-falsy lines-are-valid ... | valid-count = printString (ℕs.show valid-count)
34.571429
91
0.721488
3099c07f5e495c5991d29ba09533952a46c1a85a
503
agda
Agda
test/Succeed/Issue4158.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue4158.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue4158.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --rewriting --confluence-check --double-check #-} data _==_ {A : Set} : (x y : A) → Set where refl : {a : A} → a == a {-# BUILTIN REWRITE _==_ #-} postulate copy : ∀ {X : Set} → X → X A : Set a : A uip : (p : a == a) → p == refl record S : Set where field x : A x-β : x == a open S module T (s : S) where dummy = x-β (copy s) {-# REWRITE dummy #-} y-β-is-refl : x-β (copy s) == refl y-β-is-refl = uip _ -- WAS: Double check complains about solution to meta.
20.12
76
0.526839
4b54fb5bf27a2dd7811bf7ac1998df8a319e1a55
893
agda
Agda
test/Succeed/Issue286.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2021-07-07T10:49:57.000Z
2021-07-07T10:49:57.000Z
test/Succeed/Issue286.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue286.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module Issue286 where open import Common.Level data Bool : Set where true false : Bool {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} data _≡_ {ℓ : Level} {A : Set ℓ} : A → A → Set ℓ where refl : {a : A} → a ≡ a {-# BUILTIN EQUALITY _≡_ #-} primitive primTrustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y {-# BUILTIN STRING String #-} primitive primStringEquality : String → String → Bool data Maybe (A : Set) : Set where just : A → Maybe A nothing : Maybe A _≟_ : (s₁ s₂ : String) → Maybe (s₁ ≡ s₂) s₁ ≟ s₂ with primStringEquality s₁ s₂ ... | true = just primTrustMe ... | false = nothing _≟′_ : (s₁ s₂ : String) → Maybe (s₁ ≡ s₂) s₁ ≟′ s₂ with s₁ ≟ s₂ s ≟′ .s | just refl = just refl _ ≟′ _ | nothing = nothing test : Maybe ("" ≡ "") test = "" ≟′ "" ok : test ≡ just refl ok = refl
19.413043
54
0.577828
1ad2554ac106abd8ba8e2529218802cb54a5744b
334
agda
Agda
test/fail/TerminationInfiniteRecord.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/fail/TerminationInfiniteRecord.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/TerminationInfiniteRecord.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- 2010-10-02, see issue 334 module TerminationInfiniteRecord where record Empty : Set where constructor empty field fromEmpty : Empty elimEmpty : Empty -> Set elimEmpty (empty e) = elimEmpty e -- this no longer termination checks -- and it should not, since it is translated to -- elimEmpty e' = elimEmpty (fromEmpty e')
20.875
47
0.730539
1aeb0f6065b88f56f76a8deba6bd8cef847795ab
671
agda
Agda
agda/HITs/PropositionalTruncation/Sugar.agda
oisdk/masters-thesis
9c5e8b6f546bee952e92db0b73bfc12592bf3152
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/HITs/PropositionalTruncation/Sugar.agda
oisdk/masters-thesis
9c5e8b6f546bee952e92db0b73bfc12592bf3152
[ "MIT" ]
null
null
null
agda/HITs/PropositionalTruncation/Sugar.agda
oisdk/masters-thesis
9c5e8b6f546bee952e92db0b73bfc12592bf3152
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe #-} module HITs.PropositionalTruncation.Sugar where open import Cubical.HITs.PropositionalTruncation open import Level _=<<_ : ∀ {a} {A : Type a} {b} {B : ∥ A ∥ → Type b} → ((x : A) → ∥ B ∣ x ∣ ∥) → (xs : ∥ A ∥) → ∥ B xs ∥ _=<<_ = elim (λ _ → squash) _>>=_ : ∀ {a} {A : Type a} {b} {B : Type b} → (xs : ∥ A ∥) → (A → ∥ B ∥) → ∥ B ∥ _>>=_ {a} {A} {b} {B} xs f = elim (λ _ → squash) f xs _>>_ : ∥ A ∥ → ∥ B ∥ → ∥ B ∥ _ >> ys = ys pure : A → ∥ A ∥ pure = ∣_∣ _<*>_ : ∥ (A → B) ∥ → ∥ A ∥ → ∥ B ∥ fs <*> xs = do f ← fs x ← xs ∣ f x ∣ infixr 1 _∥$∥_ _∥$∥_ : (A → B)→ ∥ A ∥ → ∥ B ∥ f ∥$∥ xs = rec squash (λ x → ∣ f x ∣) xs
21.645161
57
0.418778
3484d09c4bc37b5265d79030da85599cc6da12c2
3,145
agda
Agda
test/succeed/Printf.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/succeed/Printf.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/Printf.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Printf where _∘_ : {A : Set}{B : A -> Set}{C : {x : A} -> B x -> Set} -> (f : {x : A}(y : B x) -> C y)(g : (x : A) -> B x)(x : A) -> C (g x) (f ∘ g) x = f (g x) infixr 10 _::_ data List (A : Set) : Set where nil : List A _::_ : A -> List A -> List A {-# BUILTIN LIST List #-} {-# BUILTIN NIL nil #-} {-# BUILTIN CONS _::_ #-} [_] : {A : Set} -> A -> List A [ x ] = x :: nil module Primitive where postulate Int : Set String : Set Float : Set Char : Set {-# BUILTIN INTEGER Int #-} {-# BUILTIN STRING String #-} {-# BUILTIN FLOAT Float #-} {-# BUILTIN CHAR Char #-} private primitive primStringAppend : String -> String -> String primStringToList : String -> List Char primStringFromList : List Char -> String primShowChar : Char -> String primShowInteger : Int -> String primShowFloat : Float -> String _++_ = primStringAppend showChar = primShowChar showInt = primShowInteger showFloat = primShowFloat stringToList = primStringToList listToString = primStringFromList open Primitive data Unit : Set where unit : Unit infixr 8 _×_ infixr 8 _◅_ data _×_ (A B : Set) : Set where _◅_ : A -> B -> A × B data Format : Set where stringArg : Format intArg : Format floatArg : Format charArg : Format litChar : Char -> Format badFormat : Char -> Format data BadFormat (c : Char) : Set where format : String -> List Format format = format' ∘ stringToList where format' : List Char -> List Format format' ('%' :: 's' :: fmt) = stringArg :: format' fmt format' ('%' :: 'd' :: fmt) = intArg :: format' fmt format' ('%' :: 'f' :: fmt) = floatArg :: format' fmt format' ('%' :: 'c' :: fmt) = charArg :: format' fmt format' ('%' :: '%' :: fmt) = litChar '%' :: format' fmt format' ('%' :: c :: fmt) = badFormat c :: format' fmt format' (c :: fmt) = litChar c :: format' fmt format' nil = nil Printf' : List Format -> Set Printf' (stringArg :: fmt) = String × Printf' fmt Printf' (intArg :: fmt) = Int × Printf' fmt Printf' (floatArg :: fmt) = Float × Printf' fmt Printf' (charArg :: fmt) = Char × Printf' fmt Printf' (badFormat c :: fmt) = BadFormat c Printf' (litChar _ :: fmt) = Printf' fmt Printf' nil = Unit Printf : String -> Set Printf fmt = Printf' (format fmt) printf : (fmt : String) -> Printf fmt -> String printf = printf' ∘ format where printf' : (fmt : List Format) -> Printf' fmt -> String printf' (stringArg :: fmt) (s ◅ args) = s ++ printf' fmt args printf' (intArg :: fmt) (n ◅ args) = showInt n ++ printf' fmt args printf' (floatArg :: fmt) (x ◅ args) = showFloat x ++ printf' fmt args printf' (charArg :: fmt) (c ◅ args) = showChar c ++ printf' fmt args printf' (litChar c :: fmt) args = listToString [ c ] ++ printf' fmt args printf' (badFormat _ :: fmt) () printf' nil unit = ""
29.392523
84
0.535135
d1a98d0061cbcc968300b5ab75e8acdce13d5c20
380
agda
Agda
test/succeed/MultipleIdentifiersOneSignature.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
null
null
null
test/succeed/MultipleIdentifiersOneSignature.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
null
null
null
test/succeed/MultipleIdentifiersOneSignature.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
null
null
null
module MultipleIdentifiersOneSignature where data Bool : Set where false true : Bool data Suit : Set where ♥ ♢ ♠ ♣ : Suit record R : Set₁ where field A B C : Set postulate A Char : Set B C : Set {-# BUILTIN CHAR Char #-} {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} primitive primIsDigit primIsSpace : Char → Bool
15.833333
44
0.634211
5ef7baaffec5f50906da2018424d4f73b07dd978
206
agda
Agda
Cubical/HITs/Truncation/FromNegOne.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/Truncation/FromNegOne.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/HITs/Truncation/FromNegOne.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Truncation.FromNegOne where open import Cubical.HITs.Truncation.FromNegOne.Base public open import Cubical.HITs.Truncation.FromNegOne.Properties public
34.333333
64
0.815534
3024bfbe0c9e72dc3104223f1da4dff9dc294707
227
agda
Agda
test/interaction/Issue1326.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1326.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1326.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-10-23 data Bool : Set where true false : Bool module _ (b : Bool) where f : Set f = {!b!} -- Agda produces garbage when splitting on b. -- Splitting on module parameters should be forbidden outright.
17.461538
63
0.678414
349f0a375a21ff170342b4b17a1636488bb96a72
5,543
agda
Agda
src/Util/HoTT/FunctionalExtensionality.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
5
2021-04-13T21:31:17.000Z
2021-06-26T06:37:31.000Z
src/Util/HoTT/FunctionalExtensionality.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
src/Util/HoTT/FunctionalExtensionality.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
-- This module closely follows a section of Martín Escardó's HoTT lecture notes: -- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#funextfromua {-# OPTIONS --without-K #-} module Util.HoTT.FunctionalExtensionality where open import Axiom.Extensionality.Propositional using (ExtensionalityImplicit ; implicit-extensionality) open import Util.Data.Product using (map₂) open import Util.HoTT.Equiv open import Util.HoTT.Equiv.Induction open import Util.HoTT.HLevel.Core open import Util.HoTT.Homotopy open import Util.HoTT.Section open import Util.HoTT.Singleton open import Util.HoTT.Univalence open import Util.Prelude open import Util.Relation.Binary.PropositionalEquality using (Σ-≡⁻) private variable α β γ : Level A B C : Set α FunextNondep : ∀ α β → Set (lsuc (α ⊔ℓ β)) FunextNondep α β = {A : Set α} {B : Set β} {f g : A → B} → (∀ a → f a ≡ g a) → f ≡ g IsContr-∀-Closure : ∀ α β → Set (lsuc (α ⊔ℓ β)) IsContr-∀-Closure α β = {A : Set α} {B : A → Set β} → (∀ a → IsContr (B a)) → IsContr (∀ a → B a) FunextHapply : ∀ α β → Set (lsuc (α ⊔ℓ β)) FunextHapply α β = {A : Set α} {B : A → Set β} (f g : ∀ a → B a) → IsEquiv (≡→~ {f = f} {g}) Funext : ∀ α β → Set (lsuc (α ⊔ℓ β)) Funext α β = {A : Set α} {B : A → Set β} {f g : ∀ a → B a} → (∀ a → f a ≡ g a) → f ≡ g abstract precomp-IsEquiv : {A B : Set α} (f : A → B) → IsEquiv f → {C : Set α} → IsEquiv (λ (g : B → C) → g ∘ f) precomp-IsEquiv f f-equiv {C} = J-IsEquiv (λ A B f → IsEquiv (λ (g : B → C) → g ∘ f)) (λ A → id-IsEquiv) f f-equiv funext-nondep : FunextNondep α β funext-nondep {α} {β} {A} {B} {f} {g} f~g = cong (λ π x → π (f x , g x , f~g x)) π₀≡π₁ where Δ : Set β Δ = Σ[ b ∈ B ] Σ[ b′ ∈ B ] (b ≡ b′) δ : B → Δ δ b = b , b , refl π₀ π₁ : Δ → B π₀ (b , b′ , p) = b π₁ (b , b′ , p) = b′ δ-IsEquiv : IsEquiv δ δ-IsEquiv = IsIso→IsEquiv record { back = π₀ ; back∘forth = λ _ → refl ; forth∘back = λ { (b , b′ , refl) → refl } } φ : (Δ → B) → (B → B) φ = _∘ δ φ-IsEquiv : IsEquiv φ φ-IsEquiv = precomp-IsEquiv δ δ-IsEquiv φπ₀≡φπ₁ : φ π₀ ≡ φ π₁ φπ₀≡φπ₁ = refl π₀≡π₁ : π₀ ≡ π₁ π₀≡π₁ = IsEquiv→Injective φ-IsEquiv φπ₀≡φπ₁ postcomp-IsIso : {A : Set α} {B : Set β} (f : B → C) → IsIso f → IsIso (λ (g : A → B) → f ∘ g) postcomp-IsIso {A = A} {B} f i = record { back = λ g a → i .IsIso.back (g a) ; back∘forth = λ g → funext-nondep λ a → i .IsIso.back∘forth (g a) ; forth∘back = λ g → funext-nondep λ a → i .IsIso.forth∘back (g a) } postcomp-IsEquiv : {A : Set α} {B : Set β} (f : B → C) → IsEquiv f → IsEquiv (λ (g : A → B) → f ∘ g) postcomp-IsEquiv f f-equiv = IsIso→IsEquiv (postcomp-IsIso f (IsEquiv→IsIso f-equiv)) ∀-IsContr : IsContr-∀-Closure α β ∀-IsContr {A = A} {B} B-contr = ◁-pres-IsContr ΠB◁g-fiber g-fiber-IsContr where f : Σ A B → A f = proj₁ f-IsEquiv : IsEquiv f f-IsEquiv = proj₁-IsEquiv B-contr g : (A → Σ A B) → (A → A) g = f ∘_ g-IsEquiv : IsEquiv g g-IsEquiv = postcomp-IsEquiv f f-IsEquiv g-fiber-IsContr : IsContr (Σ[ h ∈ (A → Σ A B) ] (f ∘ h ≡ id)) g-fiber-IsContr = g-IsEquiv id ΠB◁g-fiber : (∀ a → B a) ◁ (Σ[ h ∈ (A → Σ A B) ] (f ∘ h ≡ id)) ΠB◁g-fiber = record { retraction = λ { (h , p) a → subst B (≡→~ p a) (proj₂ (h a)) } ; hasSection = record { section = λ h → (λ a → a , h a) , refl ; isSection = λ _ → refl } } ≡→~-IsEquiv : FunextHapply α β ≡→~-IsEquiv {A = A} {B} f = goal where i : ∀ a → IsContr (Σ[ b ∈ B a ] (f a ≡ b)) i a = IsContr-Singleton′ ii : IsContr (∀ a → Σ[ b ∈ B a ] (f a ≡ b)) ii = ∀-IsContr i iii : (∃[ g ] (f ~ g)) ◁ (∀ a → Σ[ b ∈ B a ] (f a ≡ b)) iii = ≅→▷ (Π-distr-Σ-≅ _ _ _) iv : IsContr (∃[ g ] (f ~ g)) iv = ◁-pres-IsContr iii ii e : (∃[ g ] (f ≡ g)) → (∃[ g ] (f ~ g)) e = map₂ (λ _ → ≡→~) e-IsEquiv : IsEquiv e e-IsEquiv = IsContr→IsEquiv IsContr-Singleton′ iv e goal : ∀ g → IsEquiv (≡→~ {f = f} {g}) goal = IsEquiv-map₂-f→IsEquiv-f (λ _ → ≡→~) e-IsEquiv funext : Funext α β funext {f = f} {g} eq = ≡→~-IsEquiv f g eq .proj₁ .proj₁ funext∙ : ExtensionalityImplicit α β funext∙ = implicit-extensionality funext module _ {α β} {A : Set α} {B : A → Set β} {f g : ∀ a → B a} where ≡→~∘funext : (eq : ∀ a → f a ≡ g a) → ≡→~ (funext eq) ≡ eq ≡→~∘funext eq = ≡→~-IsEquiv f g eq .proj₁ .proj₂ funext-unique′ : ∀ eq → (y : Σ-syntax (f ≡ g) (λ p → ≡→~ p ≡ eq)) → (funext eq , ≡→~∘funext eq) ≡ y funext-unique′ eq = ≡→~-IsEquiv f g eq .proj₂ funext-unique : ∀ eq (p : f ≡ g) → ≡→~ p ≡ eq → funext eq ≡ p funext-unique eq p q = proj₁ (Σ-≡⁻ (funext-unique′ eq (p , q))) funext∘≡→~ : ∀ (eq : f ≡ g) → funext (≡→~ eq) ≡ eq funext∘≡→~ eq = funext-unique (≡→~ eq) eq refl subst-funext : ∀ {α β γ} {A : Set α} {B : A → Set β} {f g : ∀ a → B a} → (P : ∀ a → B a → Set γ) → (f≡g : ∀ x → f x ≡ g x) → ∀ {a} (Pf : P a (f a)) → subst (λ f → P a (f a)) (funext f≡g) Pf ≡ subst (P a) (f≡g a) Pf subst-funext P f≡g {a} Pf = sym (trans (cong (λ p → subst (P a) (p a) Pf) (sym (≡→~∘funext f≡g))) go) where go : subst (P a) (≡→~ (funext f≡g) a) Pf ≡ subst (λ f → P a (f a)) (funext f≡g) Pf go with funext f≡g ... | refl = refl
26.907767
94
0.505683
357a325a3fb2526ef8e03ee6ca7e2ff23384ce40
3,446
agda
Agda
Basic/AST.agda
AndrasKovacs/SemanticsWithApplications
05200d60b4a4b2c6fa37806ced9247055d24db94
[ "MIT" ]
8
2016-09-12T04:25:39.000Z
2020-02-02T10:01:52.000Z
Basic/AST.agda
AndrasKovacs/SemanticsWithApplications
05200d60b4a4b2c6fa37806ced9247055d24db94
[ "MIT" ]
null
null
null
Basic/AST.agda
AndrasKovacs/SemanticsWithApplications
05200d60b4a4b2c6fa37806ced9247055d24db94
[ "MIT" ]
null
null
null
module Basic.AST where import Data.Bool as Bool using (not) open import Data.Bool hiding (not; if_then_else_) open import Data.Fin using (Fin; suc; zero; #_) open import Data.Nat open import Data.Vec open import Relation.Nullary open import Relation.Nullary.Decidable open import Utils.Decidable {- This module covers the first chapter of the book. We omitted a couple of proofs that are present in the chapter. In particular, determinism and totality of the evaluation of expressions is a trivial consequence of Agda's totality, so there's no need to bother with it here. Also, the notion of "composionality" as mentioned in book corresponds simply to structural recursion in Agda. Also, we skipped the proofs about the evaluation of expression with substitutions (exercise 1.14) and contexts with substitutions (exercise 1.13), since we make no use of these in other proofs. -} -- Our type universe (it's not a large one). data Ty : Set where bool nat : Ty {- Interpretation of types into Agda sets. Note that we use natural numbers instead of integers, since naturals are much simpler to handle in formal contexts (also, there's not enough Agda library support for integers). -} ⟦_⟧ᵗ : Ty → Set ⟦ nat ⟧ᵗ = ℕ ⟦ bool ⟧ᵗ = Bool {- This is a point where we make a departure from the book. The book defines states as: State = String → ℕ This is supposed to be a total funuction, and the book doesn't concern itself with scope errors or shadowing, but we certainly have to do so in Agda. So we opt for de Bruijn indices as variables and a finite vector as State. These are as simple to handle as it can get, and we also get alpha equality of programs for free. On the flip side, we have much less readable programs. -} State : ℕ → Set State = Vec ℕ {- In the book there's a mutual definition of boolean and numeric expressions. We instead have a single universe-indexed type family. It's more convenient, and it's also equivalent to the mutual definition (it's a standard Agda/Haskell trick to encode multiple types data as a single indexed type). -} data Exp (n : ℕ) : Ty → Set where lit : ℕ → Exp n nat add mul sub : Exp n nat → Exp n nat → Exp n nat var : Fin n → Exp n nat tt ff : Exp n bool eq lte lt : Exp n nat → Exp n nat → Exp n bool and : Exp n bool → Exp n bool → Exp n bool not : Exp n bool → Exp n bool {- Statements are parameterized by the size of the State they operate on. Since the vanilla "While" language has no declarations or other features that might change the size of the state, we are fine with this. It also allows us to use finite numbers as de Bruijn indices. -} infixr 5 _:=_ infixr 4 _,_ data St (n : ℕ) : Set where _:=_ : Fin n → Exp n nat → St n skip : St n _,_ : St n → St n → St n if_then_else_ : Exp n bool → St n → St n → St n while_do_ : Exp n bool → St n → St n {- The semantics of expressions follows the book exactly. -} ⟦_⟧ᵉ : ∀ {n t} → Exp n t → State n → ⟦ t ⟧ᵗ ⟦ lit x ⟧ᵉ s = x ⟦ add a b ⟧ᵉ s = ⟦ a ⟧ᵉ s + ⟦ b ⟧ᵉ s ⟦ mul a b ⟧ᵉ s = ⟦ a ⟧ᵉ s * ⟦ b ⟧ᵉ s ⟦ sub a b ⟧ᵉ s = ⟦ a ⟧ᵉ s ∸ ⟦ b ⟧ᵉ s ⟦ var x ⟧ᵉ s = lookup x s ⟦ tt ⟧ᵉ s = true ⟦ ff ⟧ᵉ s = false ⟦ eq a b ⟧ᵉ s = ⌊ ⟦ a ⟧ᵉ s ≡⁇ ⟦ b ⟧ᵉ s ⌋ ⟦ lte a b ⟧ᵉ s = ⌊ ⟦ a ⟧ᵉ s ≤⁇ ⟦ b ⟧ᵉ s ⌋ ⟦ lt a b ⟧ᵉ s = ⌊ ⟦ a ⟧ᵉ s <⁇ ⟦ b ⟧ᵉ s ⌋ ⟦ and a b ⟧ᵉ s = ⟦ a ⟧ᵉ s ∧ ⟦ b ⟧ᵉ s ⟦ not e ⟧ᵉ s = Bool.not (⟦ e ⟧ᵉ s)
30.767857
88
0.663378
5e80ce71828f65fc75bd64f6dc5fd265e41881fd
821
agda
Agda
Base/Change/Equivalence/EqReasoning.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
10
2015-03-04T06:09:20.000Z
2019-07-19T07:06:59.000Z
Base/Change/Equivalence/EqReasoning.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
6
2015-07-01T18:09:31.000Z
2017-05-04T13:53:59.000Z
Base/Change/Equivalence/EqReasoning.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
1
2016-02-18T12:26:44.000Z
2016-02-18T12:26:44.000Z
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Delta-observational equivalence - support for equational reasoning ------------------------------------------------------------------------ module Base.Change.Equivalence.EqReasoning where open import Relation.Binary.PropositionalEquality open import Base.Change.Algebra open import Level open import Data.Unit open import Function open import Base.Change.Equivalence.Base public module _ {a} {A : Set a} {{ca : ChangeAlgebra A}} {x : A} where ------------------------------------------------------------------------ -- Convenient syntax for equational reasoning import Relation.Binary.EqReasoning as EqR module ≙-Reasoning where open EqR (≙-setoid {x = x}) public renaming (_≈⟨_⟩_ to _≙⟨_⟩_)
32.84
74
0.550548
590acce82ef8464b7fe4084df8a36bdf7b7f0df9
7,156
agda
Agda
Cubical/Algebra/Ring/Properties.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
Cubical/Algebra/Ring/Properties.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
Cubical/Algebra/Ring/Properties.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{-# OPTIONS --safe #-} module Cubical.Algebra.Ring.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Ring.Base private variable ℓ : Level {- some basic calculations (used for example in QuotientRing.agda), that should become obsolete or subject to change once we have a ring solver (see https://github.com/agda/cubical/issues/297) -} module RingTheory (R' : Ring ℓ) where open RingStr (snd R') private R = ⟨ R' ⟩ implicitInverse : (x y : R) → x + y ≡ 0r → y ≡ - x implicitInverse x y p = y ≡⟨ sym (+Lid y) ⟩ 0r + y ≡⟨ cong (λ u → u + y) (sym (+Linv x)) ⟩ (- x + x) + y ≡⟨ sym (+Assoc _ _ _) ⟩ (- x) + (x + y) ≡⟨ cong (λ u → (- x) + u) p ⟩ (- x) + 0r ≡⟨ +Rid _ ⟩ - x ∎ equalByDifference : (x y : R) → x - y ≡ 0r → x ≡ y equalByDifference x y p = x ≡⟨ sym (+Rid _) ⟩ x + 0r ≡⟨ cong (λ u → x + u) (sym (+Linv y)) ⟩ x + ((- y) + y) ≡⟨ +Assoc _ _ _ ⟩ (x - y) + y ≡⟨ cong (λ u → u + y) p ⟩ 0r + y ≡⟨ +Lid _ ⟩ y ∎ 0Selfinverse : - 0r ≡ 0r 0Selfinverse = sym (implicitInverse _ _ (+Rid 0r)) 0Idempotent : 0r + 0r ≡ 0r 0Idempotent = +Lid 0r +Idempotency→0 : (x : R) → x ≡ x + x → x ≡ 0r +Idempotency→0 x p = x ≡⟨ sym (+Rid x) ⟩ x + 0r ≡⟨ cong (λ u → x + u) (sym (+Rinv _)) ⟩ x + (x + (- x)) ≡⟨ +Assoc _ _ _ ⟩ (x + x) + (- x) ≡⟨ cong (λ u → u + (- x)) (sym p) ⟩ x + (- x) ≡⟨ +Rinv _ ⟩ 0r ∎ -Idempotent : (x : R) → -(- x) ≡ x -Idempotent x = - (- x) ≡⟨ sym (implicitInverse (- x) x (+Linv _)) ⟩ x ∎ 0RightAnnihilates : (x : R) → x · 0r ≡ 0r 0RightAnnihilates x = let x·0-is-idempotent : x · 0r ≡ x · 0r + x · 0r x·0-is-idempotent = x · 0r ≡⟨ cong (λ u → x · u) (sym 0Idempotent) ⟩ x · (0r + 0r) ≡⟨ ·Rdist+ _ _ _ ⟩ (x · 0r) + (x · 0r) ∎ in (+Idempotency→0 _ x·0-is-idempotent) 0LeftAnnihilates : (x : R) → 0r · x ≡ 0r 0LeftAnnihilates x = let 0·x-is-idempotent : 0r · x ≡ 0r · x + 0r · x 0·x-is-idempotent = 0r · x ≡⟨ cong (λ u → u · x) (sym 0Idempotent) ⟩ (0r + 0r) · x ≡⟨ ·Ldist+ _ _ _ ⟩ (0r · x) + (0r · x) ∎ in +Idempotency→0 _ 0·x-is-idempotent -DistR· : (x y : R) → x · (- y) ≡ - (x · y) -DistR· x y = implicitInverse (x · y) (x · (- y)) (x · y + x · (- y) ≡⟨ sym (·Rdist+ _ _ _) ⟩ x · (y + (- y)) ≡⟨ cong (λ u → x · u) (+Rinv y) ⟩ x · 0r ≡⟨ 0RightAnnihilates x ⟩ 0r ∎) -DistL· : (x y : R) → (- x) · y ≡ - (x · y) -DistL· x y = implicitInverse (x · y) ((- x) · y) (x · y + (- x) · y ≡⟨ sym (·Ldist+ _ _ _) ⟩ (x - x) · y ≡⟨ cong (λ u → u · y) (+Rinv x) ⟩ 0r · y ≡⟨ 0LeftAnnihilates y ⟩ 0r ∎) -Dist : (x y : R) → (- x) + (- y) ≡ - (x + y) -Dist x y = implicitInverse _ _ ((x + y) + ((- x) + (- y)) ≡⟨ sym (+Assoc _ _ _) ⟩ x + (y + ((- x) + (- y))) ≡⟨ cong (λ u → x + (y + u)) (+Comm _ _) ⟩ x + (y + ((- y) + (- x))) ≡⟨ cong (λ u → x + u) (+Assoc _ _ _) ⟩ x + ((y + (- y)) + (- x)) ≡⟨ cong (λ u → x + (u + (- x))) (+Rinv _) ⟩ x + (0r + (- x)) ≡⟨ cong (λ u → x + u) (+Lid _) ⟩ x + (- x) ≡⟨ +Rinv _ ⟩ 0r ∎) translatedDifference : (x a b : R) → a - b ≡ (x + a) - (x + b) translatedDifference x a b = a - b ≡⟨ cong (λ u → a + u) (sym (+Lid _)) ⟩ (a + (0r + (- b))) ≡⟨ cong (λ u → a + (u + (- b))) (sym (+Rinv _)) ⟩ (a + ((x + (- x)) + (- b))) ≡⟨ cong (λ u → a + u) (sym (+Assoc _ _ _)) ⟩ (a + (x + ((- x) + (- b)))) ≡⟨ (+Assoc _ _ _) ⟩ ((a + x) + ((- x) + (- b))) ≡⟨ cong (λ u → u + ((- x) + (- b))) (+Comm _ _) ⟩ ((x + a) + ((- x) + (- b))) ≡⟨ cong (λ u → (x + a) + u) (-Dist _ _) ⟩ ((x + a) - (x + b)) ∎ +Assoc-comm1 : (x y z : R) → x + (y + z) ≡ y + (x + z) +Assoc-comm1 x y z = +Assoc x y z ∙∙ cong (λ x → x + z) (+Comm x y) ∙∙ sym (+Assoc y x z) +Assoc-comm2 : (x y z : R) → x + (y + z) ≡ z + (y + x) +Assoc-comm2 x y z = +Assoc-comm1 x y z ∙∙ cong (λ x → y + x) (+Comm x z) ∙∙ +Assoc-comm1 y z x +ShufflePairs : (a b c d : R) → (a + b) + (c + d) ≡ (a + c) + (b + d) +ShufflePairs a b c d = (a + b) + (c + d) ≡⟨ +Assoc _ _ _ ⟩ ((a + b) + c) + d ≡⟨ cong (λ u → u + d) (sym (+Assoc _ _ _)) ⟩ (a + (b + c)) + d ≡⟨ cong (λ u → (a + u) + d) (+Comm _ _) ⟩ (a + (c + b)) + d ≡⟨ cong (λ u → u + d) (+Assoc _ _ _) ⟩ ((a + c) + b) + d ≡⟨ sym (+Assoc _ _ _) ⟩ (a + c) + (b + d) ∎ ·-assoc2 : (x y z w : R) → (x · y) · (z · w) ≡ x · (y · z) · w ·-assoc2 x y z w = ·Assoc (x · y) z w ∙ cong (_· w) (sym (·Assoc x y z)) module HomTheory {R S : Ring ℓ} (f′ : RingHom R S) where open RingTheory ⦃...⦄ open RingStr ⦃...⦄ open IsRingHom (f′ .snd) private instance _ = R _ = S _ = snd R _ = snd S f = fst f′ ker≡0→inj : ({x : ⟨ R ⟩} → f x ≡ 0r → x ≡ 0r) → ({x y : ⟨ R ⟩} → f x ≡ f y → x ≡ y) ker≡0→inj ker≡0 {x} {y} p = equalByDifference _ _ (ker≡0 path) where path : f (x - y) ≡ 0r path = f (x - y) ≡⟨ pres+ _ _ ⟩ f x + f (- y) ≡⟨ cong (f x +_) (pres- _) ⟩ f x - f y ≡⟨ cong (_- f y) p ⟩ f y - f y ≡⟨ +Rinv _ ⟩ 0r ∎ module _{R S : Ring ℓ} (φ ψ : RingHom R S) where open RingStr ⦃...⦄ open IsRingHom private instance _ = R _ = S _ = snd R _ = snd S RingHom≡f : fst φ ≡ fst ψ → φ ≡ ψ RingHom≡f = Σ≡Prop λ f → isPropIsRingHom _ f _
36.697436
97
0.384572
8be6cf41490b3fdae28a76085b3d77b66dfbeed1
413
agda
Agda
test/interaction/Issue2749.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2749.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2749.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --no-unicode #-} module Issue2749 where -- testing ascii only lambda and arrow id : {A : Set} -> A -> A id = {!!} -- testing ascii only double braces it : {A : Set} {{a : A}} → A → A it = {!!} data B : Set where mkB : B → B → B -- testing ascii only suffixes left : B → B left b1 = {!!} open import Agda.Builtin.Equality -- testing ascii only forall allq : (∀ m n → m ≡ n) ≡ {!!} allq = refl
16.52
38
0.576271
5eadba0644ed51e1fec0116ca92fefc3075a8941
427
agda
Agda
agda/BHeap/Order/Properties.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/BHeap/Order/Properties.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/BHeap/Order/Properties.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
module BHeap.Order.Properties {A : Set}(_≤_ : A → A → Set) where open import BHeap _≤_ open import BHeap.Order _≤_ renaming (Acc to Accₕ ; acc to accₕ) open import Data.Nat open import Induction.Nat open import Induction.WellFounded ii-acc : ∀ {b} {h} → Acc _<′_ (# {b} h) → Accₕ h ii-acc (acc rs) = accₕ (λ h' #h'<′#h → ii-acc (rs (# h') #h'<′#h)) ≺-wf : ∀ {b} h → Accₕ {b} h ≺-wf = λ h → ii-acc (<-well-founded (# h))
28.466667
66
0.594848
433aee33191f0d112a8edca8dce2599daa4b2496
1,248
agda
Agda
test/asset/agda-stdlib-1.0/Data/Container/Indexed/Core.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
test/asset/agda-stdlib-1.0/Data/Container/Indexed/Core.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Container/Indexed/Core.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Indexed containers core ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Container.Indexed.Core where open import Level open import Data.Product open import Relation.Unary infix 5 _◃_/_ record Container {i o} (I : Set i) (O : Set o) (c r : Level) : Set (i ⊔ o ⊔ suc c ⊔ suc r) where constructor _◃_/_ field Command : (o : O) → Set c Response : ∀ {o} → Command o → Set r next : ∀ {o} (c : Command o) → Response c → I -- The semantics ("extension") of an indexed container. ⟦_⟧ : ∀ {i o c r ℓ} {I : Set i} {O : Set o} → Container I O c r → Pred I ℓ → Pred O _ ⟦ C ◃ R / n ⟧ X o = Σ[ c ∈ C o ] ((r : R c) → X (n c r)) ------------------------------------------------------------------------ -- All and any module _ {i o c r ℓ} {I : Set i} {O : Set o} (C : Container I O c r) {X : Pred I ℓ} where -- All. □ : ∀ {ℓ′} → Pred (Σ I X) ℓ′ → Pred (Σ O (⟦ C ⟧ X)) _ □ P (_ , _ , k) = ∀ r → P (_ , k r) -- Any. ◇ : ∀ {ℓ′} → Pred (Σ I X) ℓ′ → Pred (Σ O (⟦ C ⟧ X)) _ ◇ P (_ , _ , k) = ∃ λ r → P (_ , k r)
27.130435
72
0.408654
04ab4f13b23829b8b54dac1d17bd04cff4cf664a
115
agda
Agda
Cubical/Data/HomotopyGroup.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/HomotopyGroup.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/HomotopyGroup.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Data.HomotopyGroup where open import Cubical.Data.HomotopyGroup.Base public
23
50
0.782609
198472e46fc6fcfddb940499ab182ad07aabfaf7
5,012
agda
Agda
Data/List/Relation/Binary/Subset/DecSetoid.agda
banacorn/bidirectional
0c9a6e79c23192b28ddb07315b200a94ee900ca6
[ "MIT" ]
2
2020-08-25T07:34:40.000Z
2020-08-25T14:05:01.000Z
Data/List/Relation/Binary/Subset/DecSetoid.agda
banacorn/bidirectional
0c9a6e79c23192b28ddb07315b200a94ee900ca6
[ "MIT" ]
null
null
null
Data/List/Relation/Binary/Subset/DecSetoid.agda
banacorn/bidirectional
0c9a6e79c23192b28ddb07315b200a94ee900ca6
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The extensional sublist relation over decidable setoid equality. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Data.List.Relation.Binary.Subset.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where -- import Data.List.Relation.Binary.Permutation.Setoid as SetoidPerm -- import Data.List.Relation.Binary.Subset.Setoid as SetoidSubset -- import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties -- as HeterogeneousProperties open import Level using (_⊔_) -- open DecSetoid S -- open SetoidSubset setoid public -- open DecSetoidEquality S open Relation.Binary using (Rel) open import Data.List using (List) ------------------------------------------------------------------------ -- Subset relation module _ where open import Function using (_∘_) open import Data.List open import Data.List.Membership.DecSetoid S using (_∈_; _∈?_) open import Relation.Nullary open import Data.List.Relation.Unary.Any public open import Data.List.Relation.Unary.Any.Properties using (¬Any[]) open DecSetoid S infix 4 _⊆_ _⊈_ _⊆_ : Rel (List Carrier) (c ⊔ ℓ) xs ⊆ ys = ∀ x → x ∈ xs → x ∈ ys _⊈_ : Rel (List Carrier) (c ⊔ ℓ) xs ⊈ ys = ¬ xs ⊆ ys -- lemma ∈-cong : ∀ {xs x y} → x ≈ y → x ∈ xs → y ∈ xs ∈-cong x≈y (here P) = here (trans (sym x≈y) P) ∈-cong x≈y (there P) = there (∈-cong x≈y P) ∉[] : ∀ {x xs} → ¬ x ∷ xs ⊆ [] ∉[] {x} {xs} P = ¬Any[] (∈-cong {[]} {x} {x} refl (P x (here refl))) ⊆-refl : ∀ {xs} → xs ⊆ xs ⊆-refl x P = P ∷-mono : ∀ {xs ys x y} → x ≈ y → xs ⊆ ys → x ∷ xs ⊆ y ∷ ys ∷-mono x≈y P x (here Q) = here (trans Q x≈y) ∷-mono x≈y P x (there Q) = there (P x Q) ⊆-swap : ∀ {xs x y} → x ∷ y ∷ xs ⊆ y ∷ x ∷ xs ⊆-swap x (here P) = there (here P) ⊆-swap x (there (here P)) = here P ⊆-swap x (there (there P)) = there (there P) infix 4 _⊆?_ _⊆?_ : Decidable _⊆_ [] ⊆? ys = yes (λ x ()) x ∷ xs ⊆? [] = no ∉[] x ∷ xs ⊆? y ∷ ys with x ∈? y ∷ ys x ∷ xs ⊆? y ∷ ys | yes P with xs ⊆? y ∷ ys ... | yes Q = yes λ where x (here R) → ∈-cong (sym R) P x (there R) → Q x R ... | no ¬Q = no λ R → ¬Q λ x S → R x (there S) x ∷ xs ⊆? y ∷ ys | no ¬P = no λ Q → ¬P (Q x (here refl)) ------------------------------------------------------------------------ -- Equivalence relation module _ where open DecSetoid S open import Data.Product open import Data.List open import Relation.Binary.Construct.Intersection open import Function.Base using (flip) infix 4 _≋_ _≋_ : Rel (List Carrier) (c ⊔ ℓ) _≋_ = _⊆_ ∩ flip _⊆_ {-# DISPLAY _⊆_ ∩ flip _⊆_ = _≋_ #-} ∷-cong : ∀ {xs ys x y} → x ≈ y → xs ≋ ys → x ∷ xs ≋ y ∷ ys ∷-cong x≈y (xs⊆ys , ys⊆xs) = ∷-mono x≈y xs⊆ys , ∷-mono (sym x≈y) ys⊆xs ≋-swap : ∀ {xs x y} → x ∷ y ∷ xs ≋ y ∷ x ∷ xs ≋-swap = ⊆-swap , ⊆-swap open import Data.List.Relation.Binary.Permutation.Homogeneous open import Relation.Nullary open import Relation.Nullary.Decidable infix 4 _≋?_ _≋?_ : Decidable _≋_ _≋?_ = decidable _⊆?_ (flip _⊆?_) ------------------------------------------------------------------------ -- Relational properties module _ where open import Data.Product ≋-isEquivalence : IsEquivalence _≋_ ≋-isEquivalence = record { refl = (λ x z → z) , (λ x z → z) ; sym = λ where (P , Q) → Q , P ; trans = λ where (P , Q) (S , T) → (λ x U → S x (P x U)) , λ x V → Q x (T x V) } -- shorthands ≋-refl : Reflexive _≋_ ≋-refl = IsEquivalence.refl ≋-isEquivalence ≋-sym : Symmetric _≋_ ≋-sym = IsEquivalence.sym ≋-isEquivalence ≋-trans : Transitive _≋_ ≋-trans = IsEquivalence.trans ≋-isEquivalence ⊆-IsPreorder : IsPreorder _≋_ _⊆_ ⊆-IsPreorder = record { isEquivalence = ≋-isEquivalence ; reflexive = λ where (P , Q) x R → P x R ; trans = λ P Q x R → Q x (P x R) } ⊆-Antisymmetric : Antisymmetric _≋_ _⊆_ ⊆-Antisymmetric P Q = P , Q ⊆-isPartialOrder : IsPartialOrder _≋_ _⊆_ ⊆-isPartialOrder = record { isPreorder = ⊆-IsPreorder ; antisym = ⊆-Antisymmetric } ⊆-isDecPartialOrder : IsDecPartialOrder _≋_ _⊆_ ⊆-isDecPartialOrder = record { isPartialOrder = ⊆-isPartialOrder ; _≟_ = _≋?_ ; _≤?_ = _⊆?_ } ------------------------------------------------------------------------ -- Bundles poset : Poset _ _ _ poset = record { Carrier = List (DecSetoid.Carrier S) ; _≈_ = _≋_ ; _≤_ = _⊆_ ; isPartialOrder = ⊆-isPartialOrder } setoid : Setoid _ _ setoid = record { Carrier = List (DecSetoid.Carrier S) ; _≈_ = _≋_ ; isEquivalence = ≋-isEquivalence } ------------------------------------------------------------------------ -- Reasoning module PosetReasoning where open import Relation.Binary.Reasoning.PartialOrder poset public module EqReasoning where open import Relation.Binary.Reasoning.Setoid setoid public
28.804598
84
0.53352
a05712db58c613be9fe99f448ae3814e85ea1bd7
1,983
agda
Agda
Cubical/Displayed/Subst.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Displayed/Subst.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Displayed/Subst.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- Given a type A with a UARel and a family B over A, a SubstRel on B is a family of functions a ≅ a' → B a ≃ B a' path-equal to transport in that family. Any SubstRel gives rise to a DUARel in which b and b' are related over p when the transport of b along p is equial to b'. -} {-# OPTIONS --safe #-} module Cubical.Displayed.Subst where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Path open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Displayed.Base private variable ℓA ℓ≅A ℓB : Level record SubstRel {A : Type ℓA} {ℓ≅A : Level} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB) : Type (ℓ-max (ℓ-max ℓA ℓB) ℓ≅A) where no-eta-equality constructor substrel open UARel 𝒮-A field act : {a a' : A} → a ≅ a' → B a ≃ B a' uaˢ : {a a' : A} (p : a ≅ a') (b : B a) → subst B (≅→≡ p) b ≡ equivFun (act p) b uaˢ⁻ : {a a' : A} (p : a ≅ a') (b : B a') → subst B (sym (≅→≡ p)) b ≡ invEq (act p) b uaˢ⁻ p b = subst B (sym (≅→≡ p)) b ≡⟨ cong (subst B (sym (≅→≡ p))) (sym (secEq (act p) b)) ⟩ subst B (sym (≅→≡ p)) (equivFun (act p) (invEq (act p) b)) ≡⟨ cong (subst B (sym (≅→≡ p))) (sym (uaˢ p (invEq (act p) b))) ⟩ subst B (sym (≅→≡ p)) (subst B (≅→≡ p) (invEq (act p) b)) ≡⟨ pathToIso (cong B (≅→≡ p)) .Iso.leftInv (invEq (act p) b) ⟩ invEq (act p) b ∎ Subst→DUA : {A : Type ℓA} {ℓ≅A : Level} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} → SubstRel 𝒮-A B → DUARel 𝒮-A B ℓB DUARel._≅ᴰ⟨_⟩_ (Subst→DUA 𝒮ˢ-B) b p b' = equivFun (SubstRel.act 𝒮ˢ-B p) b ≡ b' DUARel.uaᴰ (Subst→DUA {𝒮-A = 𝒮-A} {B = B} 𝒮ˢ-B) b p b' = equivFun (SubstRel.act 𝒮ˢ-B p) b ≡ b' ≃⟨ invEquiv (compPathlEquiv (sym (SubstRel.uaˢ 𝒮ˢ-B p b))) ⟩ subst B (≅→≡ p) b ≡ b' ≃⟨ invEquiv (PathP≃Path (λ i → B (≅→≡ p i)) b b') ⟩ PathP (λ i → B (≅→≡ p i)) b b' ■ where open UARel 𝒮-A
32.508197
109
0.580938
4349c3ba90dbc52d321f6398bb18f79887b7fe6d
1,069
agda
Agda
issues/universal-quantified-functions-option/NonFOLHigherOrderFunctions.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
10
2015-09-03T20:54:16.000Z
2019-12-03T13:44:25.000Z
issues/universal-quantified-functions-option/NonFOLHigherOrderFunctions.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
121
2015-01-25T13:22:12.000Z
2018-04-22T06:01:44.000Z
issues/universal-quantified-functions-option/NonFOLHigherOrderFunctions.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
4
2016-05-10T23:06:19.000Z
2016-08-03T03:54:55.000Z
------------------------------------------------------------------------------ -- Testing the translation of higher-order functions ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --universal-quantified-functions #-} {-# OPTIONS --without-K #-} -- We can use the Agda pragma @--universal-quantified-functions@ to -- translate higher-order functions. The canonical examples are the -- conversion rules for the λ-abstraction and the fixed-point -- operator. module NonFOLHigherOrderFunctions where infixl 6 _∙_ infix 4 _≡_ postulate D : Set _≡_ : D → D → Set lam : (D → D) → D _∙_ : D → D → D fix : (D → D) → D postulate beta : (f : D → D) → (a : D) → (lam f) ∙ a ≡ f a {-# ATP axiom beta #-} postulate fix-f : (f : D → D) → fix f ≡ f (fix f) {-# ATP axiom fix-f #-} -- We need to have at least one conjecture to generate a TPTP file. postulate refl : ∀ d → d ≡ d {-# ATP prove refl #-}
29.694444
78
0.510758
306b424cedff24200be6d8f17234b57976d179eb
1,791
agda
Agda
src/Categories/Category/Construction/EilenbergMoore.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Construction/EilenbergMoore.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Construction/EilenbergMoore.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Monad module Categories.Category.Construction.EilenbergMoore {o ℓ e} {C : Category o ℓ e} (M : Monad C) where open import Level open import Categories.Morphism.Reasoning C private module C = Category C module M = Monad M open C open M.F open HomReasoning record Module : Set (o ⊔ ℓ ⊔ e) where field A : Obj action : F₀ A ⇒ A commute : action ∘ F₁ action ≈ action ∘ M.μ.η A identity : action ∘ M.η.η A ≈ C.id record Module⇒ (X Y : Module) : Set (ℓ ⊔ e) where private module X = Module X module Y = Module Y field arr : X.A ⇒ Y.A commute : arr ∘ X.action ≈ Y.action ∘ F₁ arr EilenbergMoore : Category (o ⊔ ℓ ⊔ e) (ℓ ⊔ e) e EilenbergMoore = record { Obj = Module ; _⇒_ = Module⇒ ; _≈_ = λ f g → Module⇒.arr f ≈ Module⇒.arr g ; id = record { arr = C.id ; commute = id-comm-sym ○ ∘-resp-≈ʳ (⟺ identity) } ; _∘_ = compose ; assoc = assoc ; sym-assoc = sym-assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; identity² = identity² ; equiv = record { refl = refl ; sym = sym ; trans = trans } ; ∘-resp-≈ = ∘-resp-≈ } where open Equiv compose : ∀ {X Y Z} → Module⇒ Y Z → Module⇒ X Y → Module⇒ X Z compose {X} {Y} {Z} f g = record { arr = f.arr ∘ g.arr ; commute = begin (f.arr ∘ g.arr) ∘ Module.action X ≈⟨ pullʳ g.commute ⟩ f.arr ∘ Module.action Y ∘ F₁ g.arr ≈⟨ pullˡ f.commute ⟩ (Module.action Z ∘ F₁ f.arr) ∘ F₁ g.arr ≈˘⟨ pushʳ homomorphism ⟩ Module.action Z ∘ F₁ (f.arr ∘ g.arr) ∎ } where module f = Module⇒ f module g = Module⇒ g
25.956522
103
0.551089
358d7fa4dfdcfd77ebce3490eb35850631dfb373
1,553
agda
Agda
test/Succeed/Issue268.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue268.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue268.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v tc.polarity:15 -v tc.pos:50 #-} {-# OPTIONS --guardedness #-} module Issue268 where module Example₁ where open import Common.Coinduction module Record where record Stream : Set where inductive constructor cons field tail : ∞ Stream module Data where data Stream : Set where cons : ∞ Stream → Stream -- open Data open Record id : Stream → Stream id (cons xs) = cons (♯ id (♭ xs)) -- Andreas, 2012-09-14 -- with polarity Nonvariant, Agda recognizes id as a constant function -- since there is no proper match on the argument (Stream is a unit type) -- (if Data is opened, then there is a match on `cons') postulate P : Stream → Set f : ∀ xs → P (id xs) → Set xs : Stream p : P (id xs) Foo : Set Foo = f xs p -- f _ p -- Andreas: _ is not solved for since id is constant -- The code type checks when Data is opened, but not when Record is -- opened: -- -- Bug.agda:34,11-12 -- (Stream.tail (id xs)) != (.Bug.♯-0 _40) of type (∞ Stream) -- when checking that the expression p has type P (id (cons _40)) module Example₂ where data D : Set where d : D id : D → D id d = d module Record where record E : Set where constructor e field f : D module Data where data E : Set where e : D → E -- open Data open Record id′ : E → E id′ (e xs) = e (id xs) postulate P : E → Set f : (x : E) → P (id′ x) → Set x : E p : P (id′ x) Foo : Set Foo = f _ p
18.710843
77
0.576948
52e1906671f277b53692999778a9726c57c661cb
402
agda
Agda
Categories/Groupoid.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
1
2018-12-29T21:51:57.000Z
2018-12-29T21:51:57.000Z
Categories/Groupoid.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
null
null
null
Categories/Groupoid.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module Categories.Groupoid where open import Level open import Categories.Category import Categories.Morphisms record Groupoid {o ℓ e} (C : Category o ℓ e) : Set (o ⊔ ℓ ⊔ e) where private module C = Category C open C using (_⇒_) open Categories.Morphisms C field _⁻¹ : ∀ {A B} → (A ⇒ B) → (B ⇒ A) iso : ∀ {A B} {f : A ⇒ B} → Iso f (f ⁻¹)
21.157895
68
0.621891
193e987fdb6c7656dcb081e11e5810b343f499c8
952
agda
Agda
src/Generic/Lib/Prelude.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
30
2016-07-19T21:10:54.000Z
2022-02-05T10:19:38.000Z
src/Generic/Lib/Prelude.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
9
2017-04-06T18:58:09.000Z
2022-01-04T15:43:14.000Z
src/Generic/Lib/Prelude.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
4
2017-07-17T07:23:39.000Z
2021-01-27T12:57:09.000Z
module Generic.Lib.Prelude where open import Generic.Lib.Intro public open import Generic.Lib.Equality.Propositional public open import Generic.Lib.Equality.Coerce public open import Generic.Lib.Equality.Heteroindexed public open import Generic.Lib.Equality.Congn public open import Generic.Lib.Decidable public open import Generic.Lib.Category public open import Generic.Lib.Data.Nat public open import Generic.Lib.Data.String public open import Generic.Lib.Data.Maybe public open import Generic.Lib.Data.Sum public open import Generic.Lib.Data.Product public open import Generic.Lib.Data.List public open import Generic.Lib.Data.Pow public open import Generic.Lib.Data.Sets public open import Generic.Lib.Reflection.Core public open import Generic.Lib.Reflection.Fold public
47.6
53
0.689076
19c7225adfb79ae36cec3fdcd363dbf3be614f85
2,786
agda
Agda
LibraBFT/Impl/Consensus/EpochManagerTypes.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/EpochManagerTypes.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/EpochManagerTypes.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.KVMap as Map open import LibraBFT.Base.PKCS open import LibraBFT.Base.Types open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Interface.Output open import LibraBFT.Prelude open import Optics.All module LibraBFT.Impl.Consensus.EpochManagerTypes where ------------------------------------------------------------------------------ -- in Haskell, this lives in LBFT.Consensus.Types -- It lives here because of the dependency on RoundManager. data RoundProcessor : Set where RoundProcessorRecovery : RecoveryManager → RoundProcessor RoundProcessorNormal : RoundManager → RoundProcessor record EpochManager : Set where constructor mkEpochManager field _emAuthor : Author _emConfig : ConsensusConfig _emStateComputer : StateComputer _emStorage : PersistentLivenessStorage _emSafetyRulesManager : SafetyRulesManager _emProcessor : Maybe RoundProcessor open EpochManager public unquoteDecl emAuthor emConfig emStateComputer emStorage emSafetyRulesManager emProcessor = mkLens (quote EpochManager) (emAuthor ∷ emConfig ∷ emStateComputer ∷ emStorage ∷ emSafetyRulesManager ∷ emProcessor ∷ []) -- getter only in Haskell emEpochState : Lens EpochManager (Either ErrLog EpochState) emEpochState = mkLens' g s where g : EpochManager → Either ErrLog EpochState g em = case em ^∙ emProcessor of λ where (just (RoundProcessorNormal p)) → pure (p ^∙ rmEpochState) (just (RoundProcessorRecovery p)) → pure (p ^∙ rcmEpochState) nothing → Left fakeErr s : EpochManager → Either ErrLog EpochState → EpochManager s em _ = em -- getter only in Haskell emEpoch : Lens EpochManager (Either ErrLog Epoch) emEpoch = mkLens' g s where g : EpochManager → Either ErrLog Epoch g em = (_^∙ esEpoch) <$> (em ^∙ emEpochState) s : EpochManager → Either ErrLog Epoch → EpochManager s em _ = em -- getter only in Haskell emObmRoundManager : Lens EpochManager (Either ErrLog RoundManager) emObmRoundManager = mkLens' g s where g : EpochManager → Either ErrLog RoundManager g em = case em ^∙ emProcessor of λ where (just (RoundProcessorNormal rm)) → pure rm (just (RoundProcessorRecovery _)) → Left fakeErr nothing → Left fakeErr s : EpochManager → Either ErrLog RoundManager -> EpochManager s em _ = em
39.8
128
0.693467
135baf1abc80410eaa9fe7bc837f992e105a6d8c
10,166
agda
Agda
lib/types/LoopSpace.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/types/LoopSpace.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/types/LoopSpace.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.NConnected open import lib.types.Nat open import lib.types.TLevel open import lib.types.Empty open import lib.types.Group open import lib.types.Pi open import lib.types.Pointed open import lib.types.Paths open import lib.types.Sigma open import lib.types.Truncation open import lib.cubical.Square module lib.types.LoopSpace where module _ {i} where ⊙Ω : Ptd i → Ptd i ⊙Ω (A , a) = ⊙[ (a == a) , idp ] Ω : Ptd i → Type i Ω = fst ∘ ⊙Ω ⊙Ω^ : (n : ℕ) → Ptd i → Ptd i ⊙Ω^ O X = X ⊙Ω^ (S n) X = ⊙Ω (⊙Ω^ n X) Ω^ : (n : ℕ) → Ptd i → Type i Ω^ n X = fst (⊙Ω^ n X) idp^ : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^ n X idp^ n {X} = snd (⊙Ω^ n X) {- for n ≥ 1, we have a group structure on the loop space -} module _ {i} where !^ : (n : ℕ) (t : n ≠ O) {X : Ptd i} → Ω^ n X → Ω^ n X !^ O t = ⊥-rec (t idp) !^ (S n) _ = ! conc^ : (n : ℕ) (t : n ≠ O) {X : Ptd i} → Ω^ n X → Ω^ n X → Ω^ n X conc^ O t = ⊥-rec (t idp) conc^ (S n) _ = _∙_ {- ap and ap2 for pointed functions -} private pt-lemma : ∀ {i} {A : Type i} {x y : A} (p : x == y) → ! p ∙ (idp ∙' p) == idp pt-lemma idp = idp ⊙ap : ∀ {i j} {X : Ptd i} {Y : Ptd j} → fst (X ⊙→ Y) → fst (⊙Ω X ⊙→ ⊙Ω Y) ⊙ap (f , fpt) = ((λ p → ! fpt ∙ ap f p ∙' fpt) , pt-lemma fpt) ⊙ap2 : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} → fst (X ⊙× Y ⊙→ Z) → fst (⊙Ω X ⊙× ⊙Ω Y ⊙→ ⊙Ω Z) ⊙ap2 (f , fpt) = ((λ {(p , q) → ! fpt ∙ ap2 (curry f) p q ∙' fpt}) , pt-lemma fpt) ⊙ap-∘ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → ⊙ap (g ⊙∘ f) == ⊙ap g ⊙∘ ⊙ap f ⊙ap-∘ (g , idp) (f , idp) = ⊙λ= (λ p → ap-∘ g f p) idp ⊙ap-idf : ∀ {i} {X : Ptd i} → ⊙ap (⊙idf X) == ⊙idf _ ⊙ap-idf = ⊙λ= ap-idf idp ⊙ap2-fst : ∀ {i j} {X : Ptd i} {Y : Ptd j} → ⊙ap2 {X = X} {Y = Y} ⊙fst == ⊙fst ⊙ap2-fst = ⊙λ= (uncurry ap2-fst) idp ⊙ap2-snd : ∀ {i j} {X : Ptd i} {Y : Ptd j} → ⊙ap2 {X = X} {Y = Y} ⊙snd == ⊙snd ⊙ap2-snd = ⊙λ= (uncurry ap2-snd) idp ⊙ap-ap2 : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l} (G : fst (Z ⊙→ W)) (F : fst (X ⊙× Y ⊙→ Z)) → ⊙ap G ⊙∘ ⊙ap2 F == ⊙ap2 (G ⊙∘ F) ⊙ap-ap2 (g , idp) (f , idp) = ⊙λ= (uncurry (ap-ap2 g (curry f))) idp ⊙ap2-ap : ∀ {i j k l m} {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m} (G : fst ((U ⊙× V) ⊙→ Z)) (F₁ : fst (X ⊙→ U)) (F₂ : fst (Y ⊙→ V)) → ⊙ap2 G ⊙∘ pair⊙→ (⊙ap F₁) (⊙ap F₂) == ⊙ap2 (G ⊙∘ pair⊙→ F₁ F₂) ⊙ap2-ap (g , idp) (f₁ , idp) (f₂ , idp) = ⊙λ= (λ {(p , q) → ap2-ap-l (curry g) f₁ p (ap f₂ q) ∙ ap2-ap-r (λ x v → g (f₁ x , v)) f₂ p q}) idp ⊙ap2-diag : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : fst (X ⊙× X ⊙→ Y)) → ⊙ap2 F ⊙∘ ⊙diag == ⊙ap (F ⊙∘ ⊙diag) ⊙ap2-diag (f , idp) = ⊙λ= (ap2-diag (curry f)) idp {- ap and ap2 for higher loop spaces -} ap^ : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} → fst (X ⊙→ Y) → fst (⊙Ω^ n X ⊙→ ⊙Ω^ n Y) ap^ O F = F ap^ (S n) F = ⊙ap (ap^ n F) ap2^ : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} → fst ((X ⊙× Y) ⊙→ Z) → fst ((⊙Ω^ n X ⊙× ⊙Ω^ n Y) ⊙→ ⊙Ω^ n Z) ap2^ O F = F ap2^ (S n) F = ⊙ap2 (ap2^ n F) ap^-idf : ∀ {i} (n : ℕ) {X : Ptd i} → ap^ n (⊙idf X) == ⊙idf _ ap^-idf O = idp ap^-idf (S n) = ap ⊙ap (ap^-idf n) ∙ ⊙ap-idf ap^-ap2^ : ∀ {i j k l} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l} (G : fst (Z ⊙→ W)) (F : fst ((X ⊙× Y) ⊙→ Z)) → ap^ n G ⊙∘ ap2^ n F == ap2^ n (G ⊙∘ F) ap^-ap2^ O G F = idp ap^-ap2^ (S n) G F = ⊙ap-ap2 (ap^ n G) (ap2^ n F) ∙ ap ⊙ap2 (ap^-ap2^ n G F) ap2^-fst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} → ap2^ n {X} {Y} ⊙fst == ⊙fst ap2^-fst O = idp ap2^-fst (S n) = ap ⊙ap2 (ap2^-fst n) ∙ ⊙ap2-fst ap2^-snd : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} → ap2^ n {X} {Y} ⊙snd == ⊙snd ap2^-snd O = idp ap2^-snd (S n) = ap ⊙ap2 (ap2^-snd n) ∙ ⊙ap2-snd ap2^-ap^ : ∀ {i j k l m} (n : ℕ) {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m} (G : fst ((U ⊙× V) ⊙→ Z)) (F₁ : fst (X ⊙→ U)) (F₂ : fst (Y ⊙→ V)) → ap2^ n G ⊙∘ pair⊙→ (ap^ n F₁) (ap^ n F₂) == ap2^ n (G ⊙∘ pair⊙→ F₁ F₂) ap2^-ap^ O G F₁ F₂ = idp ap2^-ap^ (S n) G F₁ F₂ = ⊙ap2-ap (ap2^ n G) (ap^ n F₁) (ap^ n F₂) ∙ ap ⊙ap2 (ap2^-ap^ n G F₁ F₂) ap2^-diag : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} (F : fst (X ⊙× X ⊙→ Y)) → ap2^ n F ⊙∘ ⊙diag == ap^ n (F ⊙∘ ⊙diag) ap2^-diag O F = idp ap2^-diag (S n) F = ⊙ap2-diag (ap2^ n F) ∙ ap ⊙ap (ap2^-diag n F) module _ {i} {X : Ptd i} where {- Prove these as lemmas now - so we don't have to deal with the n = O case later -} conc^-unit-l : (n : ℕ) (t : n ≠ O) (q : Ω^ n X) → (conc^ n t (idp^ n) q) == q conc^-unit-l O t _ = ⊥-rec (t idp) conc^-unit-l (S n) _ _ = idp conc^-unit-r : (n : ℕ) (t : n ≠ O) (q : Ω^ n X) → (conc^ n t q (idp^ n)) == q conc^-unit-r O t = ⊥-rec (t idp) conc^-unit-r (S n) _ = ∙-unit-r conc^-assoc : (n : ℕ) (t : n ≠ O) (p q r : Ω^ n X) → conc^ n t (conc^ n t p q) r == conc^ n t p (conc^ n t q r) conc^-assoc O t = ⊥-rec (t idp) conc^-assoc (S n) _ = ∙-assoc !^-inv-l : (n : ℕ) (t : n ≠ O) (p : Ω^ n X) → conc^ n t (!^ n t p) p == idp^ n !^-inv-l O t = ⊥-rec (t idp) !^-inv-l (S n) _ = !-inv-l !^-inv-r : (n : ℕ) (t : n ≠ O) (p : Ω^ n X) → conc^ n t p (!^ n t p) == idp^ n !^-inv-r O t = ⊥-rec (t idp) !^-inv-r (S n) _ = !-inv-r abstract ap^-conc^ : ∀ {i j} (n : ℕ) (t : n ≠ O) {X : Ptd i} {Y : Ptd j} (F : fst (X ⊙→ Y)) (p q : Ω^ n X) → fst (ap^ n F) (conc^ n t p q) == conc^ n t (fst (ap^ n F) p) (fst (ap^ n F) q) ap^-conc^ O t _ _ _ = ⊥-rec (t idp) ap^-conc^ (S n) _ {X = X} {Y = Y} F p q = ! gpt ∙ ap g (p ∙ q) ∙' gpt =⟨ ap-∙ g p q |in-ctx (λ w → ! gpt ∙ w ∙' gpt) ⟩ ! gpt ∙ (ap g p ∙ ap g q) ∙' gpt =⟨ lemma (ap g p) (ap g q) gpt ⟩ (! gpt ∙ ap g p ∙' gpt) ∙ (! gpt ∙ ap g q ∙' gpt) ∎ where g : Ω^ n X → Ω^ n Y g = fst (ap^ n F) gpt : g (idp^ n) == idp^ n gpt = snd (ap^ n F) lemma : ∀ {i} {A : Type i} {x y : A} → (p q : x == x) (r : x == y) → ! r ∙ (p ∙ q) ∙' r == (! r ∙ p ∙' r) ∙ (! r ∙ q ∙' r) lemma p q idp = idp {- ap^ preserves (pointed) equivalences -} module _ {i j} {X : Ptd i} {Y : Ptd j} where is-equiv-ap^ : (n : ℕ) (F : fst (X ⊙→ Y)) (e : is-equiv (fst F)) → is-equiv (fst (ap^ n F)) is-equiv-ap^ O F e = e is-equiv-ap^ (S n) F e = pre∙-is-equiv (! (snd (ap^ n F))) ∘ise post∙'-is-equiv (snd (ap^ n F)) ∘ise snd (equiv-ap (_ , is-equiv-ap^ n F e) _ _) equiv-ap^ : (n : ℕ) (F : fst (X ⊙→ Y)) (e : is-equiv (fst F)) → Ω^ n X ≃ Ω^ n Y equiv-ap^ n F e = (fst (ap^ n F) , is-equiv-ap^ n F e) Ω^-level-in : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i) → (has-level ((n -2) +2+ m) (fst X) → has-level m (Ω^ n X)) Ω^-level-in m O X pX = pX Ω^-level-in m (S n) X pX = Ω^-level-in (S m) n X (transport (λ k → has-level k (fst X)) (! (+2+-βr (n -2) m)) pX) (idp^ n) (idp^ n) Ω^-conn-in : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i) → (is-connected ((n -2) +2+ m) (fst X)) → is-connected m (Ω^ n X) Ω^-conn-in m O X pX = pX Ω^-conn-in m (S n) X pX = path-conn $ Ω^-conn-in (S m) n X $ transport (λ k → is-connected k (fst X)) (! (+2+-βr (n -2) m)) pX {- Eckmann-Hilton argument -} module _ {i} {X : Ptd i} where conc^2-comm : (α β : Ω^ 2 X) → conc^ 2 (ℕ-S≠O _) α β == conc^ 2 (ℕ-S≠O _) β α conc^2-comm α β = ! (⋆2=conc^ α β) ∙ ⋆2=⋆'2 α β ∙ ⋆'2=conc^ α β where ⋆2=conc^ : (α β : Ω^ 2 X) → α ⋆2 β == conc^ 2 (ℕ-S≠O _) α β ⋆2=conc^ α β = ap (λ π → π ∙ β) (∙-unit-r α) ⋆'2=conc^ : (α β : Ω^ 2 X) → α ⋆'2 β == conc^ 2 (ℕ-S≠O _) β α ⋆'2=conc^ α β = ap (λ π → β ∙ π) (∙-unit-r α) {- Pushing truncation through loop space -} module _ {i} where Trunc-Ω^ : (m : ℕ₋₂) (n : ℕ) (X : Ptd i) → ⊙Trunc m (⊙Ω^ n X) == ⊙Ω^ n (⊙Trunc ((n -2) +2+ m) X) Trunc-Ω^ m O X = idp Trunc-Ω^ m (S n) X = ⊙Trunc m (⊙Ω^ (S n) X) =⟨ ! (pair= (Trunc=-path [ _ ] [ _ ]) (↓-idf-ua-in _ idp)) ⟩ ⊙Ω (⊙Trunc (S m) (⊙Ω^ n X)) =⟨ ap ⊙Ω (Trunc-Ω^ (S m) n X) ⟩ ⊙Ω^ (S n) (⊙Trunc ((n -2) +2+ S m) X) =⟨ +2+-βr (n -2) m |in-ctx (λ k → ⊙Ω^ (S n) (⊙Trunc k X)) ⟩ ⊙Ω^ (S n) (⊙Trunc (S (n -2) +2+ m) X) ∎ Ω-Trunc-equiv : (m : ℕ₋₂) (X : Ptd i) → Ω (⊙Trunc (S m) X) ≃ Trunc m (Ω X) Ω-Trunc-equiv m X = Trunc=-equiv [ snd X ] [ snd X ] {- A loop space is a pregroup, and a group if it has the right level -} module _ {i} (n : ℕ) (t : n ≠ O) (X : Ptd i) where Ω^-group-structure : GroupStructure (Ω^ n X) Ω^-group-structure = record { ident = idp^ n; inv = !^ n t; comp = conc^ n t; unitl = conc^-unit-l n t; unitr = conc^-unit-r n t; assoc = conc^-assoc n t; invr = !^-inv-r n t; invl = !^-inv-l n t } Ω^-Group : has-level ⟨ n ⟩ (fst X) → Group i Ω^-Group pX = group (Ω^ n X) (Ω^-level-in ⟨0⟩ n X $ transport (λ t → has-level t (fst X)) (+2+-comm ⟨0⟩ (n -2)) pX) Ω^-group-structure {- Our definition of Ω^ builds up loops on the outside, - but this is equivalent to building up on the inside -} module _ {i} where ⊙Ω^-inner-path : (n : ℕ) (X : Ptd i) → ⊙Ω^ (S n) X == ⊙Ω^ n (⊙Ω X) ⊙Ω^-inner-path O X = idp ⊙Ω^-inner-path (S n) X = ap ⊙Ω (⊙Ω^-inner-path n X) ⊙Ω^-inner-out : (n : ℕ) (X : Ptd i) → fst (⊙Ω^ (S n) X ⊙→ ⊙Ω^ n (⊙Ω X)) ⊙Ω^-inner-out O _ = (idf _ , idp) ⊙Ω^-inner-out (S n) X = ap^ 1 (⊙Ω^-inner-out n X) Ω^-inner-out : (n : ℕ) (X : Ptd i) → (Ω^ (S n) X → Ω^ n (⊙Ω X)) Ω^-inner-out n X = fst (⊙Ω^-inner-out n X) Ω^-inner-out-conc^ : (n : ℕ) (t : n ≠ O) (X : Ptd i) (p q : Ω^ (S n) X) → Ω^-inner-out n X (conc^ (S n) (ℕ-S≠O _) p q) == conc^ n t (Ω^-inner-out n X p) (Ω^-inner-out n X q) Ω^-inner-out-conc^ O t X _ _ = ⊥-rec (t idp) Ω^-inner-out-conc^ (S n) t X p q = ap^-conc^ 1 (ℕ-S≠O _) (⊙Ω^-inner-out n X) p q Ω^-inner-is-equiv : (n : ℕ) (X : Ptd i) → is-equiv (fst (⊙Ω^-inner-out n X)) Ω^-inner-is-equiv O X = is-eq (idf _) (idf _) (λ _ → idp) (λ _ → idp) Ω^-inner-is-equiv (S n) X = is-equiv-ap^ 1 (⊙Ω^-inner-out n X) (Ω^-inner-is-equiv n X) Ω^-inner-equiv : (n : ℕ) (X : Ptd i) → Ω^ (S n) X ≃ Ω^ n (⊙Ω X) Ω^-inner-equiv n X = _ , Ω^-inner-is-equiv n X
32.375796
79
0.447669
30ea4f4716ab21a01830d96a8c63c788ec448816
1,358
agda
Agda
Definition/LogicalRelation/Substitution/Introductions/Universe.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
Definition/LogicalRelation/Substitution/Introductions/Universe.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
Definition/LogicalRelation/Substitution/Introductions/Universe.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Introductions.Universe {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.LogicalRelation open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Substitution open import Tools.Product import Tools.PropositionalEquality as PE -- Validity of the universe type. Uᵛ : ∀ {Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ ¹ ⟩ U / [Γ] Uᵛ [Γ] ⊢Δ [σ] = Uᵣ′ ⁰ 0<1 ⊢Δ , λ _ x₂ → PE.refl -- Valid terms of type U are valid types. univᵛ : ∀ {A Γ l l′} ([Γ] : ⊩ᵛ Γ) ([U] : Γ ⊩ᵛ⟨ l ⟩ U / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ A ∷ U / [Γ] / [U] → Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ] univᵛ {l′ = l′} [Γ] [U] [A] ⊢Δ [σ] = let [A]₁ = maybeEmb′ {l′} (univEq (proj₁ ([U] ⊢Δ [σ])) (proj₁ ([A] ⊢Δ [σ]))) in [A]₁ , (λ [σ′] [σ≡σ′] → univEqEq (proj₁ ([U] ⊢Δ [σ])) [A]₁ ((proj₂ ([A] ⊢Δ [σ])) [σ′] [σ≡σ′])) -- Valid term equality of type U is valid type equality. univEqᵛ : ∀ {A B Γ l l′} ([Γ] : ⊩ᵛ Γ) ([U] : Γ ⊩ᵛ⟨ l′ ⟩ U / [Γ]) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Γ ⊩ᵛ⟨ l′ ⟩ A ≡ B ∷ U / [Γ] / [U] → Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A] univEqᵛ {A} [Γ] [U] [A] [t≡u] ⊢Δ [σ] = univEqEq (proj₁ ([U] ⊢Δ [σ])) (proj₁ ([A] ⊢Δ [σ])) ([t≡u] ⊢Δ [σ])
34.820513
96
0.512518
34bd75996a7934412bca134196fae070d91874d8
7,349
agda
Agda
test/succeed/Issue854.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/Issue854.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
test/succeed/Issue854.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- 2013-06-15 Andreas, issue reported by Stevan Andjelkovic module Issue854 where infixr 1 _⊎_ infixr 2 _×_ infixr 4 _,_ infix 4 _≡_ data ⊥ : Set where ⊥-elim : {A : Set} → ⊥ → A ⊥-elim () record ⊤ : Set where constructor tt data Bool : Set where true false : Bool data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ data Maybe (A : Set) : Set where nothing : Maybe A just : (x : A) → Maybe A data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data _⊎_ (A : Set) (B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B [_,_] : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ] (inj₁ x) = f x [ f , g ] (inj₂ y) = g y [_,_]₁ : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set₁} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ]₁ (inj₁ x) = f x [ f , g ]₁ (inj₂ y) = g y record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public _×_ : Set → Set → Set A × B = Σ A λ _ → B uncurry₁ : {A : Set} {B : A → Set} {C : Σ A B → Set₁} → ((x : A) → (y : B x) → C (x , y)) → ((p : Σ A B) → C p) uncurry₁ f (x , y) = f x y ------------------------------------------------------------------------ infix 5 _◃_ infixr 1 _⊎C_ infixr 2 _×C_ record Container : Set₁ where constructor _◃_ field Shape : Set Position : Shape → Set open Container public ⟦_⟧ : Container → (Set → Set) ⟦ S ◃ P ⟧ X = Σ S λ s → P s → X idC : Container idC = ⊤ ◃ λ _ → ⊤ constC : Set → Container constC X = X ◃ λ _ → ⊥ 𝟘 = constC ⊥ 𝟙 = constC ⊤ _⊎C_ : Container → Container → Container S ◃ P ⊎C S′ ◃ P′ = (S ⊎ S′) ◃ [ P , P′ ]₁ _×C_ : Container → Container → Container S ◃ P ×C S′ ◃ P′ = (S × S′) ◃ uncurry₁ (λ s s′ → P s ⊎ P′ s′) data μ (C : Container) : Set where ⟨_⟩ : ⟦ C ⟧ (μ C) → μ C _⋆C_ : Container → Set → Container C ⋆C X = constC X ⊎C C _⋆_ : Container → Set → Set C ⋆ X = μ (C ⋆C X) AlgIter : Container → Set → Set AlgIter C X = ⟦ C ⟧ X → X iter : ∀ {C X} → AlgIter C X → μ C → X iter φ ⟨ s , k ⟩ = φ (s , λ p → iter φ (k p)) AlgRec : Container → Set → Set AlgRec C X = ⟦ C ⟧ (μ C × X) → X {-# NO_TERMINATION_CHECK #-} rec : ∀ {C X} → AlgRec C X → μ C → X rec φ ⟨ s , k ⟩ = φ (s , λ p → (k p , rec φ (k p))) return : ∀ {C X} → X → C ⋆ X return x = ⟨ inj₁ x , ⊥-elim ⟩ do : ∀ {C X} → ⟦ C ⟧ (C ⋆ X) → C ⋆ X do (s , k) = ⟨ inj₂ s , k ⟩ _>>=_ : ∀ {C X Y} → C ⋆ X → (X → C ⋆ Y) → C ⋆ Y _>>=_ {C}{X}{Y} m k = iter φ m where φ : AlgIter (C ⋆C X) (C ⋆ Y) φ (inj₁ x , _) = k x φ (inj₂ s , k) = do (s , k) ------------------------------------------------------------------------ _↠_ : Set → Set → Container I ↠ O = I ◃ λ _ → O State : Set → Container State S = ⊤ ↠ S -- get ⊎C S ↠ ⊤ -- put get : ∀ {S} → State S ⋆ S get = do (inj₁ tt , return) put : ∀ {S} → S → State S ⋆ ⊤ put s = do (inj₂ s , return) Homo : Container → Set → Set → Container → Set → Set Homo Σ X I Σ′ Y = AlgRec (Σ ⋆C X) (I → Σ′ ⋆ Y) Pseudohomo : Container → Set → Set → Container → Set → Set Pseudohomo Σ X I Σ′ Y = ⟦ Σ ⋆C X ⟧ ((Σ ⊎C Σ′) ⋆ X × (I → Σ′ ⋆ Y)) → I → Σ′ ⋆ Y state : ∀ {Σ S X} → Pseudohomo (State S) X S Σ (X × S) state (inj₁ x , _) = λ s → return (x , s) -- return state (inj₂ (inj₁ _) , k) = λ s → proj₂ (k s) s -- get state (inj₂ (inj₂ s) , k) = λ _ → proj₂ (k tt) s -- put Abort : Container Abort = ⊤ ↠ ⊥ aborting : ∀ {X} → Abort ⋆ X aborting = do (tt , ⊥-elim) abort : ∀ {Σ X} → Pseudohomo Abort X ⊤ Σ (Maybe X) abort (inj₁ x , _) _ = return (just x) -- return abort (inj₂ _ , _) _ = return nothing -- abort ------------------------------------------------------------------------ record _⇒_ (C C′ : Container) : Set where field shape : Shape C → Shape C′ position : ∀ {s} → Position C′ (shape s) → Position C s open _⇒_ public idMorph : ∀ {C} → C ⇒ C idMorph = record { shape = λ s → s; position = λ p → p } inlMorph : ∀ {C C′ : Container} → C ⇒ (C ⊎C C′) inlMorph = record { shape = inj₁ ; position = λ p → p } swapMorph : ∀ {C C′} → (C ⊎C C′) ⇒ (C′ ⊎C C) swapMorph {C}{C′}= record { shape = sh ; position = λ {s} p → pos {s} p } where sh : Shape C ⊎ Shape C′ → Shape C′ ⊎ Shape C sh (inj₁ s) = inj₂ s sh (inj₂ s′) = inj₁ s′ pos : ∀ {s} → Position (C′ ⊎C C) (sh s) → Position (C ⊎C C′) s pos {inj₁ s} p = p pos {inj₂ s′} p′ = p′ ⟪_⟫ : ∀ {C C′ X} → C ⇒ C′ → ⟦ C ⟧ X → ⟦ C′ ⟧ X ⟪ m ⟫ xs = shape m (proj₁ xs) , λ p′ → proj₂ xs (position m p′) ⟪_⟫Homo : ∀ {C C′ X} → C ⇒ C′ → Homo C X ⊤ C′ X ⟪ m ⟫Homo (inj₁ x , _) _ = return x ⟪ m ⟫Homo (inj₂ s , k) _ = let (s′ , k′) = ⟪ m ⟫ (s , k) in do (s′ , λ p′ → proj₂ (k′ p′) tt) natural : ∀ {C C′ X} → C ⇒ C′ → C ⋆ X → C′ ⋆ X natural f m = rec ⟪ f ⟫Homo m tt inl : ∀ {C C′ X} → C ⋆ X → (C ⊎C C′) ⋆ X inl = natural inlMorph squeeze : ∀ {Σ Σ′ X} → ((Σ ⊎C Σ′) ⊎C Σ′) ⋆ X → (Σ ⊎C Σ′) ⋆ X squeeze = natural m where m = record { shape = [ (λ x → x) , inj₂ ] ; position = λ { {inj₁ x} p → p ; {inj₂ x} p → p} } lift : ∀ {Σ Σ′ X Y I} → Pseudohomo Σ X I Σ′ Y → Pseudohomo (Σ ⊎C Σ′) X I Σ′ Y lift φ (inj₁ x , _) i = φ (inj₁ x , ⊥-elim) i lift φ (inj₂ (inj₁ s) , k) i = φ (inj₂ s , λ p → let (w , ih) = k p in squeeze w , ih) i lift φ (inj₂ (inj₂ s′) , k′) i = do (s′ , λ p′ → proj₂ (k′ p′) i) weaken : ∀ {Σ Σ′ Σ″ Σ‴ X Y I} → Homo Σ′ X I Σ″ Y → Σ ⇒ Σ′ → Σ″ ⇒ Σ‴ → Homo Σ X I Σ‴ Y weaken {Σ}{Σ′}{Σ″}{Σ‴}{X}{Y} φ f g (s , k) i = w‴ where w : Σ ⋆ X w = ⟨ s , (λ p → proj₁ (k p)) ⟩ w′ : Σ′ ⋆ X w′ = natural f w w″ : Σ″ ⋆ Y w″ = rec φ w′ i w‴ : Σ‴ ⋆ Y w‴ = natural g w″ ⌈_⌉Homo : ∀ {Σ Σ′ X Y I} → Pseudohomo Σ X I Σ′ Y → Homo Σ X I Σ′ Y ⌈ φ ⌉Homo (inj₁ x , _) = φ (inj₁ x , ⊥-elim) ⌈ φ ⌉Homo (inj₂ s , k) = φ (inj₂ s , λ p → let (w , ih) = k p in inl w , ih) run : ∀ {Σ Σ′ Σ″ Σ‴ X Y I} → Pseudohomo Σ X I Σ′ Y → Σ″ ⇒ (Σ ⊎C Σ′) → Σ′ ⇒ Σ‴ → Σ″ ⋆ X → I → Σ‴ ⋆ Y run φ p q = rec (weaken ⌈ lift φ ⌉Homo p q) ------------------------------------------------------------------------ prog : (State ℕ ⊎C Abort) ⋆ Bool prog = ⟨ inj₂ (inj₁ (inj₁ tt)) , (λ n → -- get >>= λ n → ⟨ inj₂ (inj₁ (inj₂ (suc n))) , (λ _ → -- put (suc n) ⟨ inj₂ (inj₂ tt) , (λ _ → -- aborting return true) ⟩) ⟩) ⟩ progA : State ℕ ⋆ Maybe Bool progA = run abort swapMorph idMorph prog tt progS : ℕ → Abort ⋆ (Bool × ℕ) progS = run state idMorph idMorph prog progAS : ℕ → 𝟘 ⋆ (Maybe Bool × ℕ) progAS = run state inlMorph idMorph progA progSA : ℕ → 𝟘 ⋆ Maybe (Bool × ℕ) progSA n = run abort inlMorph idMorph (progS n) tt testSA : progSA zero ≡ return nothing testSA = refl testAS : progAS zero ≡ return (nothing , suc zero) testAS = refl -- The last statement seemed to make the type checker loop. -- But it just created huge terms during the conversion check -- and never finished. -- These terms contained many projection redexes -- (projection applied to record value). -- After changing the strategy, such that these redexes are, -- like beta-redexes, removed immediately in internal syntax, -- the code checks instantaneously.
25.254296
76
0.465914
2151e5f16f39959903f9e75fef5651179014eb0c
2,004
agda
Agda
product-thms.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
29
2019-02-06T13:09:31.000Z
2022-03-04T15:05:12.000Z
product-thms.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
8
2018-07-09T22:53:38.000Z
2022-03-22T03:43:34.000Z
product-thms.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
17
2018-12-03T22:38:15.000Z
2021-11-28T20:13:21.000Z
module product-thms where open import eq open import level open import product open import unit open import functions -- this is called the inspect idiom, in the Agda stdlib keep : ∀{ℓ}{A : Set ℓ} → (x : A) → Σ A (λ y → x ≡ y) keep x = ( x , refl ) ,inj : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}{a a' : A}{b b' : B} → a , b ≡ a' , b' → a ≡ a' ∧ b ≡ b' ,inj refl = refl , refl eta-× : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃}{h : A × B → C} → (extensionality {ℓ₁ ⊔ ℓ₂}{ℓ₃}) → (λ c → h (fst c , snd c)) ≡ h eta-× {A = A}{B}{C}{h} ext = ext eta-×-aux where eta-×-aux : ∀{a : Σ A (λ x → B)} → h (fst a , snd a) ≡ h a eta-×-aux {(a , b)} = refl eq-× : ∀{ℓ₁ ℓ₂}{A : Set ℓ₁}{B : Set ℓ₂}{a a' : A}{b b' : B} → a ≡ a' → b ≡ b' → (a , b) ≡ (a' , b') eq-× refl refl = refl -- This module proves typical isomorphisms about ∧. module ∧-Isos where postulate ext-set : ∀{l1 l2 : level} → extensionality {l1} {l2} ∧-unit-l : ∀{ℓ}{A : Set ℓ} → A → A ∧ ⊤ ∧-unit-l x = x , triv ∧-unit-r : ∀{ℓ}{A : Set ℓ} → A → ⊤ ∧ A ∧-unit-r x = twist-× (∧-unit-l x) ∧-unit-l-iso : ∀{ℓ}{A : Set ℓ} → Iso A (A ∧ ⊤) ∧-unit-l-iso {_}{A} = isIso ∧-unit-l fst refl (ext-set aux) where aux : {a : A ∧ ⊤} → (fst a , triv) ≡ a aux {x , triv} = refl ∧-unit-r-iso : ∀{ℓ}{A : Set ℓ} → Iso A (⊤ ∧ A) ∧-unit-r-iso {_}{A} = isIso ∧-unit-r snd refl (ext-set aux) where aux : {a : ⊤ ∧ A} → (triv , snd a) ≡ a aux {triv , x} = refl ∧-assoc₁ : ∀{ℓ}{A B C : Set ℓ} → (A ∧ (B ∧ C)) → ((A ∧ B) ∧ C) ∧-assoc₁ (a , b , c) = ((a , b) , c) ∧-assoc₂ : ∀{ℓ}{A B C : Set ℓ} → ((A ∧ B) ∧ C) → (A ∧ (B ∧ C)) ∧-assoc₂ ((a , b) , c) = (a , b , c) ∧-assoc-iso : ∀{ℓ}{A B C : Set ℓ} → Iso (A ∧ (B ∧ C)) ((A ∧ B) ∧ C) ∧-assoc-iso {_}{A}{B}{C} = isIso ∧-assoc₁ ∧-assoc₂ (ext-set aux₁) (ext-set aux₂) where aux₁ : {a : A ∧ (B ∧ C)} → ∧-assoc₂ (∧-assoc₁ a) ≡ a aux₁ {a , (b , c)} = refl aux₂ : {a : (A ∧ B) ∧ C} → ∧-assoc₁ (∧-assoc₂ a) ≡ a aux₂ {(a , b) , c} = refl
29.910448
82
0.456088
52e0ef4112a16a1e807198c9bcc6fb527c1906dd
3,691
agda
Agda
Cubical/Foundations/Univalence/Universe.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/Univalence/Universe.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/Univalence/Universe.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 --postfix-projections #-} open import Cubical.Core.Everything open import Cubical.Functions.Embedding open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Prelude open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport -- A helper module for deriving univalence for a higher inductive-recursive -- universe. -- -- U is the type of codes -- El is the decoding -- un is a higher constructor that requires paths between codes to exist -- for equivalences of decodings -- comp is intended to be the computational behavior of El on un, although -- it seems that being a path is sufficient. -- -- Given a universe defined as above, it's possible to show that the path -- space of the code type is equivalent to the path space of the actual -- decodings, which are themselves determined by equivalences. -- -- The levels are left independent, but of course it will generally be -- impossible to define this sort of universe unless ℓ' < ℓ, because El will -- be too big to go in a constructor of U. The exception would be if U could -- be defined independently of El, though it might be tricky to get the right -- higher structure in such a case. module Cubical.Foundations.Univalence.Universe {ℓ ℓ'} (U : Type ℓ) (El : U → Type ℓ') (un : ∀ s t → El s ≃ El t → s ≡ t) (comp : ∀{s t} (e : El s ≃ El t) → cong El (un s t e) ≡ ua e) where private variable A : Type ℓ' module UU-Lemmas where reg : transport (λ _ → A) ≡ idfun A reg {A} i z = transp (λ _ → A) i z nu : ∀ x y → x ≡ y → El x ≃ El y nu x y p = transportEquiv (cong El p) cong-un-te : ∀ x y (p : El x ≡ El y) → cong El (un x y (transportEquiv p)) ≡ p cong-un-te x y p = comp (transportEquiv p) ∙ uaTransportη p nu-un : ∀ x y (e : El x ≃ El y) → nu x y (un x y e) ≡ e nu-un x y e = equivEq (nu x y (un x y e)) e λ i z → (cong (λ p → transport p z) (comp e) ∙ uaβ e z) i El-un-equiv : ∀ x i → El (un x x (idEquiv _) i) ≃ El x El-un-equiv x i = λ where .fst → transp (λ j → p j) (i ∨ ~ i) .snd → transp (λ j → isEquiv (transp (λ k → p (j ∧ k)) (~ j ∨ i ∨ ~ i))) (i ∨ ~ i) (idIsEquiv T) where T = El (un x x (idEquiv _) i) p : T ≡ El x p j = (comp (idEquiv _) ∙ uaIdEquiv {A = El x}) j i un-refl : ∀ x → un x x (idEquiv (El x)) ≡ refl un-refl x i j = hcomp (λ k → λ where (i = i0) → un x x (idEquiv (El x)) j (i = i1) → un x x (idEquiv (El x)) (j ∨ k) (j = i0) → un x x (idEquiv (El x)) (~ i ∨ k) (j = i1) → x) (un (un x x (idEquiv (El x)) (~ i)) x (El-un-equiv x (~ i)) j) nu-refl : ∀ x → nu x x refl ≡ idEquiv (El x) nu-refl x = equivEq (nu x x refl) (idEquiv (El x)) reg un-nu : ∀ x y (p : x ≡ y) → un x y (nu x y p) ≡ p un-nu x y p = J (λ z q → un x z (nu x z q) ≡ q) (cong (un x x) (nu-refl x) ∙ un-refl x) p open UU-Lemmas open Iso equivIso : ∀ s t → Iso (s ≡ t) (El s ≃ El t) equivIso s t .fun = nu s t equivIso s t .inv = un s t equivIso s t .rightInv = nu-un s t equivIso s t .leftInv = un-nu s t pathIso : ∀ s t → Iso (s ≡ t) (El s ≡ El t) pathIso s t .fun = cong El pathIso s t .inv = un s t ∘ transportEquiv pathIso s t .rightInv = cong-un-te s t pathIso s t .leftInv = un-nu s t minivalence : ∀{s t} → (s ≡ t) ≃ (El s ≃ El t) minivalence {s} {t} = isoToEquiv (equivIso s t) path-reflection : ∀{s t} → (s ≡ t) ≃ (El s ≡ El t) path-reflection {s} {t} = isoToEquiv (pathIso s t) isEmbeddingEl : isEmbedding El isEmbeddingEl s t = snd path-reflection
33.862385
81
0.606069
43f99b82c1fc17c31d8414dd70d812f76b0f8607
352
agda
Agda
test/asset/agda-stdlib-1.0/Data/Empty.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Empty.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Empty.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Empty type ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Empty where open import Level data ⊥ : Set where ⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever ⊥-elim ()
20.705882
72
0.357955
52f42a50820fd5b658651104504b683bfadec24a
2,584
agda
Agda
src/fot/FOTC/Data/Nat/Divisibility/By0/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Nat/Divisibility/By0/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Nat/Divisibility/By0/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Properties of the divisibility relation ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.Divisibility.By0.PropertiesATP where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.Divisibility.By0 open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.PropertiesATP open import FOTC.Data.Nat.PropertiesATP ------------------------------------------------------------------------------ -- Any positive number divides 0. postulate S∣0 : ∀ n → succ₁ n ∣ zero {-# ATP prove S∣0 #-} -- 0 divides 0. postulate 0∣0 : zero ∣ zero {-# ATP prove 0∣0 #-} -- The divisibility relation is reflexive. postulate ∣-refl : ∀ {n} → N n → n ∣ n {-# ATP prove ∣-refl *-leftIdentity #-} -- If x divides y and z then x divides y ∸ z. postulate x∣y→x∣z→x∣y∸z-helper : ∀ {m n o k k'} → N m → N k → N k' → n ≡ k * m → o ≡ k' * m → n ∸ o ≡ (k ∸ k') * m {-# ATP prove x∣y→x∣z→x∣y∸z-helper *∸-leftDistributive #-} x∣y→x∣z→x∣y∸z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n ∸ o x∣y→x∣z→x∣y∸z Nm Nn No (k , Nk , h₁) (k' , Nk' , h₂) = k ∸ k' , ∸-N Nk Nk' , x∣y→x∣z→x∣y∸z-helper Nm Nk Nk' h₁ h₂ -- If x divides y and z then x divides y + z. postulate x∣y→x∣z→x∣y+z-helper : ∀ {m n o k k'} → N m → N k → N k' → n ≡ k * m → o ≡ k' * m → n + o ≡ (k + k') * m {-# ATP prove x∣y→x∣z→x∣y+z-helper *+-leftDistributive #-} x∣y→x∣z→x∣y+z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n + o x∣y→x∣z→x∣y+z Nm Nn No (k , Nk , h₁) (k' , Nk' , h₂) = k + k' , +-N Nk Nk' , x∣y→x∣z→x∣y+z-helper Nm Nk Nk' h₁ h₂ -- If x divides y and y is positive, then x ≤ y. postulate x∣S→x≤S-helper₁ : ∀ {m n} → succ₁ n ≡ zero * m → ⊥ {-# ATP prove x∣S→x≤S-helper₁ #-} -- Nice proof by the ATPa. postulate x∣S→x≤S-helper₂ : ∀ {m n o} → N m → N n → N o → succ₁ n ≡ succ₁ o * m → m ≤ succ₁ n {-# ATP prove x∣S→x≤S-helper₂ x≤x+y *-N #-} x∣S→x≤S : ∀ {m n} → N m → N n → m ∣ (succ₁ n) → m ≤ succ₁ n x∣S→x≤S Nm Nn (.zero , nzero , Sn≡0*m) = ⊥-elim (x∣S→x≤S-helper₁ Sn≡0*m) x∣S→x≤S Nm Nn (.(succ₁ k) , nsucc {k} Nk , Sn≡Sk*m) = x∣S→x≤S-helper₂ Nm Nn Nk Sn≡Sk*m
36.914286
78
0.45743
5ea6018dae25d195b1e5944b78260c54430c61c2
3,666
agda
Agda
Cubical/HITs/Pushout/Flattening.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/Pushout/Flattening.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/HITs/Pushout/Flattening.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{- The flattening lemma for pushouts (Lemma 8.5.3 in the HoTT book) proved in a cubical style. The proof in the HoTT book (the core lying in Lemma 6.12.2, the flattening lemma for coequalizers) consists mostly of long strings of equalities about transport. This proof follows almost entirely from definitional equalities involving glue/unglue. -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.Pushout.Flattening 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.Data.Sigma open import Cubical.HITs.Pushout.Base module FlatteningLemma {ℓa ℓb ℓc} {A : Type ℓa} {B : Type ℓb} {C : Type ℓc} (f : A → B) (g : A → C) {ℓ} (F : B → Type ℓ) (G : C → Type ℓ) (e : ∀ a → F (f a) ≃ G (g a)) where E : Pushout f g → Type ℓ E (inl x) = F x E (inr x) = G x E (push a i) = ua (e a) i Σf : Σ[ a ∈ A ] F (f a) → Σ[ b ∈ B ] F b Σf (a , x) = (f a , x) Σg : Σ[ a ∈ A ] F (f a) → Σ[ c ∈ C ] G c Σg (a , x) = (g a , (e a) .fst x) module FlattenIso where fwd : Pushout Σf Σg → Σ (Pushout f g) E fwd (inl (b , x)) = (inl b , x) fwd (inr (c , x)) = (inr c , x) fwd (push (a , x) i) = (push a i , ua-gluePt (e a) i x) bwd : Σ (Pushout f g) E → Pushout Σf Σg bwd (inl b , x) = inl (b , x) bwd (inr c , x) = inr (c , x) bwd (push a i , x) = hcomp (λ j → λ { (i = i0) → push (a , x) (~ j) ; (i = i1) → inr (g a , x) }) (inr (g a , ua-unglue (e a) i x)) bwd-fwd : ∀ x → bwd (fwd x) ≡ x bwd-fwd (inl (b , x)) = refl bwd-fwd (inr (c , x)) = refl bwd-fwd (push (a , x) i) j = hcomp (λ k → λ { (i = i0) → push (a , ua-gluePt (e a) i0 x) (~ k) ; (i = i1) → inr (g a , ua-gluePt (e a) i1 x) ; (j = i1) → push (a , x) (i ∨ ~ k) }) (inr (g a , ua-unglue (e a) i (ua-gluePt (e a) i x))) -- Note: the (j = i1) case typechecks because of the definitional equalities: -- ua-gluePt e i0 x ≡ x , ua-gluePt e i1 x ≡ e .fst x, -- ua-unglue-glue : ua-unglue e i (ua-gluePt e i x) ≡ e .fst x -- essentially: ua-glue e (i ∨ ~ k) ∘ ua-unglue e i sq : ∀ {ℓ} {A B : Type ℓ} (e : A ≃ B) → SquareP (λ i k → ua e i → ua e (i ∨ ~ k)) {- i = i0 -} (λ k x → ua-gluePt e (~ k) x) {- i = i1 -} (λ k x → x) {- k = i0 -} (λ i x → ua-unglue e i x) {- k = i1 -} (λ i x → x) sq e i k x = ua-glue e (i ∨ ~ k) (λ { ((i ∨ ~ k) = i0) → x }) (inS (ua-unglue e i x)) -- Note: this typechecks because of the definitional equalities: -- ua-unglue e i0 x ≡ e .fst x, ua-glue e i1 _ (inS y) ≡ y, ua-unglue e i1 x ≡ x, -- ua-glue-unglue : ua-glue e i (λ { (i = i0) → x }) (inS (ua-unglue e i x)) ≡ x fwd-bwd : ∀ x → fwd (bwd x) ≡ x fwd-bwd (inl b , x) = refl fwd-bwd (inr c , x) = refl fwd-bwd (push a i , x) j = -- `fwd` (or any function) takes hcomps to comps on a constant family, so we must use a comp here comp (λ _ → Σ (Pushout f g) E) (λ k → λ { (i = i0) → push a (~ k) , ua-gluePt (e a) (~ k) x ; (i = i1) → inr (g a) , x ; (j = i1) → push a (i ∨ ~ k) , sq (e a) i k x }) (inr (g a) , ua-unglue (e a) i x) isom : Iso (Σ (Pushout f g) E) (Pushout Σf Σg) isom = iso bwd fwd bwd-fwd fwd-bwd flatten : Σ (Pushout f g) E ≃ Pushout Σf Σg flatten = isoToEquiv FlattenIso.isom
39.847826
103
0.499182