Search is not available for this dataset
text
string
meta
dict
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Properties.Setoids.Extensive where open import Level open import Data.Product using (Σ; proj₁; proj₂; _,_; Σ-syntax; _×_; -,_) open import Function.Equality using (Π) open import Relation.Binary using (Setoid; Rel) open import Categories.Category using (Category; _[_,_]) open import Categories.Category.Instance.Setoids open import Categories.Category.Extensive open import Categories.Category.Cocartesian open import Categories.Diagram.Pullback open import Categories.Category.Instance.Properties.Setoids.Limits.Canonical open import Categories.Category.Monoidal.Instance.Setoids open import Data.Sum.Relation.Binary.Pointwise open import Data.Unit.Polymorphic using (⊤; tt) open import Data.Empty using (⊥; ⊥-elim) open import Data.Sum.Base using ([_,_]′; _⊎_) open import Function.Equality as SΠ renaming (id to ⟶-id) open import Data.Product using (∃) open import Relation.Binary.PropositionalEquality using (_≡_; [_]; inspect) open Π module _ ℓ where private S = Setoids ℓ ℓ module S = Category S open Pullback Setoids-Extensive : (ℓ : Level) → Extensive (Setoids ℓ ℓ) Setoids-Extensive ℓ = record { cocartesian = record { initial = initial ; coproducts = coproducts } ; pullback₁ = λ f → pullback ℓ ℓ f i₁ ; pullback₂ = λ f → pullback ℓ ℓ f i₂ ; pullback-of-cp-is-cp = λ {C A B} f → record { [_,_] = λ g h → record { _⟨$⟩_ = copair-$ f g h ; cong = λ {z z′} → copair-cong f g h z z′ } ; inject₁ = λ {X g h z} eq → trans (isEquivalence {ℓ} X) (copair-inject₁ f g h z) (cong g eq) ; inject₂ = λ {X g h z} eq → trans (isEquivalence {ℓ} X) (copair-inject₂ f g h z) (cong h eq) ; unique = λ {X u g h} feq₁ feq₂ {z z′} eq → trans (isEquivalence {ℓ} X) (copair-unique f g h u z (λ {z} → feq₁ {z}) (λ {z} → feq₂ {z})) (cong u eq) } ; pullback₁-is-mono = λ _ _ eq x≈y → drop-inj₁ (eq x≈y) ; pullback₂-is-mono = λ _ _ eq x≈y → drop-inj₂ (eq x≈y) ; disjoint = λ {A B} → record { commute = λ { {()} _} ; universal = λ {C f g} eq → record { _⟨$⟩_ = λ z → conflict A B (f ⟨$⟩ z) (g ⟨$⟩ z) (eq (refl (isEquivalence {ℓ} C))) ; cong = λ z → tt } ; unique = λ _ _ _ → tt ; p₁∘universal≈h₁ = λ {C h₁ h₂ eq x y} x≈y → conflict A B (h₁ ⟨$⟩ x) (h₂ ⟨$⟩ y) (eq x≈y) ; p₂∘universal≈h₂ = λ {C h₁ h₂ eq x y} x≈y → conflict A B (h₁ ⟨$⟩ x) (h₂ ⟨$⟩ y) (eq x≈y) } } where open Cocartesian (Setoids-Cocartesian {ℓ} {ℓ}) open Relation.Binary.IsEquivalence open import Data.Sum using (inj₁; inj₂) open Setoid renaming (_≈_ to [_][_≈_]; Carrier to ∣_∣) using (isEquivalence) -- must be in the standard library. Maybe it is? conflict : ∀ {ℓ ℓ' ℓ''} (X Y : Setoid ℓ ℓ') {Z : Set ℓ''} (x : ∣ X ∣) (y : ∣ Y ∣) → [ ⊎-setoid X Y ][ inj₁ x ≈ inj₂ y ] → Z conflict X Y x y () module Diagram {A B C X : Setoid ℓ ℓ} (f : C ⟶ ⊎-setoid A B) (g : P (pullback ℓ ℓ f i₁) ⟶ X) (h : P (pullback ℓ ℓ f i₂) ⟶ X) where private A⊎B = ⊎-setoid A B A′ = P (pullback ℓ ℓ f i₁) B′ = P (pullback ℓ ℓ f i₂) refl-A = refl (isEquivalence A) refl-B = refl (isEquivalence B) refl-C = refl (isEquivalence C) refl-A⊎B = refl (isEquivalence A⊎B) reflexive-A⊎B = reflexive (isEquivalence A⊎B) sym-A = sym (isEquivalence A) sym-B = sym (isEquivalence B) sym-C = sym (isEquivalence C) sym-X = sym (isEquivalence X) sym-A⊎B = sym (isEquivalence A⊎B) trans-X = trans (isEquivalence X) trans-A⊎B = trans (isEquivalence A⊎B) -- copairing of g : A′ → X and h : B′ → X, resulting in C → X copair-$ : ∣ C ∣ → ∣ X ∣ copair-$ z with (f ⟨$⟩ z) | inspect (f ⟨$⟩_) z ... | inj₁ x | [ eq ] = g ⟨$⟩ record { elem₁ = z ; elem₂ = x ; commute = reflexive-A⊎B eq } ... | inj₂ y | [ eq ] = h ⟨$⟩ record { elem₁ = z ; elem₂ = y ; commute = reflexive-A⊎B eq } -- somewhat roundabout way to expand the definition of copair-$ z if f ⟨$⟩ z ≈ inj₁ x, -- in order to circumwent the pitfalls of the with-abstraction copair-$-i₁ : (x : ∣ A ∣) (z : ∣ C ∣) → (eq : [ A⊎B ][ f ⟨$⟩ z ≈ inj₁ x ]) → ∃ (λ v → [ X ][ copair-$ z ≈ g ⟨$⟩ v ] × [ C ][ FiberProduct.elem₁ v ≈ z ] × [ A ][ FiberProduct.elem₂ v ≈ x ]) copair-$-i₁ x z eq with (f ⟨$⟩ z) | inspect (f ⟨$⟩_) z ... | inj₁ x′ | [ eq′ ] = record { elem₁ = z ; elem₂ = x′ ; commute = reflexive-A⊎B eq′} , cong g (refl-C , refl-A) , refl-C , drop-inj₁ eq -- same for f ⟨$⟩ z ≈ inj₂ y copair-$-i₂ : (y : ∣ B ∣) (z : ∣ C ∣) → (eq : [ A⊎B ][ f ⟨$⟩ z ≈ inj₂ y ]) → ∃ (λ v → [ X ][ copair-$ z ≈ h ⟨$⟩ v ] × [ C ][ FiberProduct.elem₁ v ≈ z ] × [ B ][ FiberProduct.elem₂ v ≈ y ]) copair-$-i₂ y z eq with (f ⟨$⟩ z) | inspect (f ⟨$⟩_) z ... | inj₂ y′ | [ eq′ ] = record { elem₁ = z ; elem₂ = y′ ; commute = reflexive-A⊎B eq′} , cong h (refl-C , refl-B) , refl-C , drop-inj₂ eq case-f⟨$⟩z : (z : ∣ C ∣) → (∃ λ x → [ A⊎B ][ f ⟨$⟩ z ≈ inj₁ x ]) ⊎ (∃ λ y → [ A⊎B ][ f ⟨$⟩ z ≈ inj₂ y ]) case-f⟨$⟩z z with (f ⟨$⟩ z) ... | inj₁ x = inj₁ (x , refl-A⊎B) ... | inj₂ y = inj₂ (y , refl-A⊎B) copair-cong : (z z′ : ∣ C ∣) → (z≈z′ : [ C ][ z ≈ z′ ]) → [ X ][ copair-$ z ≈ copair-$ z′ ] copair-cong z z′ z≈z′ with (f ⟨$⟩ z) | inspect (_⟨$⟩_ f) z | (f ⟨$⟩ z′) | inspect (_⟨$⟩_ f) z′ ... | inj₁ x | [ eq ] | inj₁ x′ | [ eq′ ] = cong g (z≈z′ , drop-inj₁ (trans-A⊎B (sym-A⊎B (reflexive-A⊎B eq)) (trans-A⊎B (cong f z≈z′) (reflexive-A⊎B eq′)))) ... | inj₁ x | [ eq ] | inj₂ y | [ eq′ ] = conflict A B x y (trans-A⊎B (sym-A⊎B (reflexive-A⊎B eq)) (trans-A⊎B (cong f z≈z′) (reflexive-A⊎B eq′))) ... | inj₂ y | [ eq ] | inj₁ x | [ eq′ ] = conflict A B x y (trans-A⊎B (sym-A⊎B (reflexive-A⊎B eq′)) (trans-A⊎B (cong f (sym-C z≈z′)) (reflexive-A⊎B eq))) ... | inj₂ y | [ eq ] | inj₂ y′ | [ eq′ ] = cong h (z≈z′ , drop-inj₂ (trans-A⊎B (sym-A⊎B (reflexive-A⊎B eq)) (trans-A⊎B (cong f z≈z′) (reflexive-A⊎B eq′)))) copair-inject₁ : (z : FiberProduct f i₁) → [ X ][ copair-$ (FiberProduct.elem₁ z) ≈ g ⟨$⟩ z ] copair-inject₁ record { elem₁ = z ; elem₂ = x ; commute = eq } with case-f⟨$⟩z z ... | inj₁ _ with copair-$-i₁ x z eq ... | _ , eq₁ , eq₂ , eq₃ = trans-X eq₁ (cong g (eq₂ , eq₃)) copair-inject₁ record { elem₁ = z ; elem₂ = x ; commute = eq } | inj₂ (y , eq′) = conflict A B x y (trans-A⊎B (sym-A⊎B eq) eq′) copair-inject₂ : (z : FiberProduct f i₂) → [ X ][ copair-$ (FiberProduct.elem₁ z) ≈ h ⟨$⟩ z ] copair-inject₂ record { elem₁ = z ; elem₂ = y ; commute = eq } with case-f⟨$⟩z z ... | inj₂ _ with copair-$-i₂ y z eq ... | _ , eq₁ , eq₂ , eq₃ = trans-X eq₁ (cong h (eq₂ , eq₃)) copair-inject₂ record { elem₁ = z ; elem₂ = y ; commute = eq } | inj₁ (x , eq′) = conflict A B x y (trans-A⊎B (sym-A⊎B eq′) eq) copair-unique : (u : C ⟶ X) (z : ∣ C ∣) → [ A′ ⇨ X ][ u ∘ p₁ (pullback ℓ ℓ f i₁) ≈ g ] → [ B′ ⇨ X ][ u ∘ p₁ (pullback ℓ ℓ f i₂) ≈ h ] → [ X ][ copair-$ z ≈ u ⟨$⟩ z ] copair-unique u z feq₁ feq₂ with case-f⟨$⟩z z ... | inj₁ (x , eq) with copair-$-i₁ x z eq ... | z′ , eq₁ , eq₂ , _ = trans-X eq₁ (trans-X (sym-X (feq₁{z′} (refl-C , refl-A))) (cong u eq₂)) copair-unique u z feq₁ feq₂ | inj₂ (y , eq) with copair-$-i₂ y z eq ... | z′ , eq₁ , eq₂ , _ = trans-X eq₁ (trans-X (sym-X (feq₂{z′} (refl-C , refl-B))) (cong u eq₂)) open Diagram
{ "alphanum_fraction": 0.4873486029, "avg_line_length": 49.3431952663, "ext": "agda", "hexsha": "526aaadd7f8052db42893b783e583cecb8cb3ad4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "e2d7596549e7840b521576f48746ac3c4560f126", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sergey-goncharov/agda-categories", "max_forks_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Extensive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e2d7596549e7840b521576f48746ac3c4560f126", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sergey-goncharov/agda-categories", "max_issues_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Extensive.agda", "max_line_length": 124, "max_stars_count": null, "max_stars_repo_head_hexsha": "e2d7596549e7840b521576f48746ac3c4560f126", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "sergey-goncharov/agda-categories", "max_stars_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Extensive.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3128, "size": 8339 }
{-# OPTIONS --safe --erased-cubical #-} module Erased-cubical where -- Modules that use --cubical can be imported. open import Erased-cubical.Cubical-again -- Code from such modules that was originally defined in modules using -- --without-K or --erased-cubical can be used without restrictions. _ : {A : Set} → A → ∥ A ∥ _ = ∣_∣ _ : D _ = c -- Matching on an erased constructor that was defined in a module that -- uses --cubical is fine, and makes it possible to use erased -- definitions in the right-hand side. f : D′ → D′ f c′ = c′
{ "alphanum_fraction": 0.6880733945, "avg_line_length": 22.7083333333, "ext": "agda", "hexsha": "ebb993282328303e0f6384483c0788f585987028", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Erased-cubical.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Erased-cubical.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Erased-cubical.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 160, "size": 545 }
module Data.Finitude.Properties where open import Data.Fin as Fin using (Fin; #_ ) open import Data.Fin.Properties hiding (decSetoid) open import Relation.Nullary open import Relation.Unary open import Relation.Binary renaming (Decidable to Dec₂) hiding (Irrelevant) open import Relation.Binary.PropositionalEquality as P hiding (decSetoid; isEquivalence) open import Data.Finitude open import Function.Equality as F using (_⟨$⟩_) open import Function.Inverse as Inv using (Inverse) open import Data.Nat as ℕ hiding (_≟_) import Level finitude→≡ : ∀ {n m} → Finitude (P.setoid (Fin n)) m → n ≡ m finitude→≡ fin = ⇒Fin∼Fin fin where open import Data.Fin.PigeonHole dec-≈ : ∀ {a ℓ n}{S : Setoid a ℓ} → Finitude S n → Dec₂ (Setoid._≈_ S) dec-≈ {S = S} fin x y with (Inverse.to fin ⟨$⟩ x) ≟ (Inverse.to fin ⟨$⟩ y) dec-≈ {S = S} fin x y | yes fx≡fy = yes (Inverse.injective fin fx≡fy) dec-≈ {S = S} fin x y | no fx≢fy = no (λ x≈y → fx≢fy (F.cong (Inverse.to fin) x≈y)) decSetoid : ∀ {a ℓ n}{S : Setoid a ℓ} → Finitude S n → DecSetoid a ℓ decSetoid {S = S} fin = record { isDecEquivalence = record { _≟_ = dec-≈ fin ; isEquivalence = isEquivalence } } where open Setoid S same-size↔ : ∀ {n a₁ a₂ ℓ₁ ℓ₂}{A₁ : Setoid a₁ ℓ₁}{A₂ : Setoid a₂ ℓ₂} → Finitude A₁ n → Finitude A₂ n → Inverse A₁ A₂ same-size↔ fin₁ fin₂ = Inv.sym fin₂ Inv.∘ fin₁ size-unique : ∀ {a ℓ} {A : Setoid a ℓ} {n m} → Finitude A n → Finitude A m → n ≡ m size-unique finN finM = finitude→≡ (finM Inv.∘ Inv.sym finN) {- open import Data.Empty open import Data.Unit Irr : ∀ {a ℓ}(S : Setoid a ℓ) → Set (a Level.⊔ ℓ) Irr S = ∀ x y → x ≈ y where open Setoid S ⊥-Irr : Irrelevant ⊥ ⊥-Irr = λ () ⊤-Irr : Irrelevant ⊤ ⊤-Irr = λ _ _ → P.refl Irr-finitude : ∀ {a ℓ n}{S : Set a} → Irrelevant S → Finitude (P.setoid S) n → n ℕ.≤ 1 Irr-finitude {n = ℕ.zero} irr fin = z≤n Irr-finitude {n = ℕ.suc ℕ.zero} irr fin = s≤s z≤n Irr-finitude {n = ℕ.suc (ℕ.suc n)}{S} irr fin = ⊥-elim contra where open Setoid S x₀ = Inverse.from fin ⟨$⟩ # 0 x₁ = Inverse.from fin ⟨$⟩ # 1 contra : ⊥ contra with Inverse.injective (Inv.sym fin) (irr x₀ x₁) ... | () -}
{ "alphanum_fraction": 0.6182144459, "avg_line_length": 32.7794117647, "ext": "agda", "hexsha": "500fdcdef7b5ace5354ce30c3b68a6b93a2c0469", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "abacd166f63582b7395d9cc10b6323c0f69649e5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "tizmd/agda-finitary", "max_forks_repo_path": "src/Data/Finitude/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "abacd166f63582b7395d9cc10b6323c0f69649e5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "tizmd/agda-finitary", "max_issues_repo_path": "src/Data/Finitude/Properties.agda", "max_line_length": 117, "max_stars_count": null, "max_stars_repo_head_hexsha": "abacd166f63582b7395d9cc10b6323c0f69649e5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "tizmd/agda-finitary", "max_stars_repo_path": "src/Data/Finitude/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 876, "size": 2229 }
-- Andreas, 2016-10-03, re issue #2231 -- Testing whether the musical coinduction works fine in abstract blocks {-# OPTIONS --guardedness #-} module AbstractCoinduction where {-# BUILTIN INFINITY ∞_ #-} {-# BUILTIN SHARP ♯_ #-} {-# BUILTIN FLAT ♭ #-} infixr 5 _≺_ abstract ------------------------------------------------------------------------ -- Streams data Stream (A : Set) : Set where _≺_ : (x : A) (xs : ∞ (Stream A)) -> Stream A head : ∀ {A} -> Stream A -> A head (x ≺ xs) = x tail : ∀ {A} -> Stream A -> Stream A tail (x ≺ xs) = ♭ xs ------------------------------------------------------------------------ -- Stream programs infix 8 _∞ infixr 5 _⋎_ infix 4 ↓_ mutual data Stream′ (A : Set) : Set1 where _≺_ : (x : A) (xs : ∞ (StreamProg A)) -> Stream′ A data StreamProg (A : Set) : Set1 where ↓_ : (xs : Stream′ A) -> StreamProg A _∞' : (x : A) -> StreamProg A _⋎'_ : (xs ys : StreamProg A) -> StreamProg A _∞ : ∀ {A : Set} (x : A) -> StreamProg A _∞ = _∞' _⋎_ : ∀ {A : Set} (xs ys : StreamProg A) -> StreamProg A _⋎_ = _⋎'_ head′ : ∀ {A} → Stream′ A → A head′ (x ≺ xs) = x tail′ : ∀ {A} → Stream′ A → StreamProg A tail′ (x ≺ xs) = ♭ xs P⇒′ : ∀ {A} -> StreamProg A -> Stream′ A P⇒′ (↓ xs) = xs P⇒′ (x ∞') = x ≺ ♯ (x ∞) P⇒′ (xs ⋎' ys) with P⇒′ xs P⇒′ (xs ⋎' ys) | xs′ = head′ xs′ ≺ ♯ (ys ⋎ tail′ xs′) mutual ′⇒ : ∀ {A} -> Stream′ A -> Stream A ′⇒ (x ≺ xs) = x ≺ ♯ P⇒ (♭ xs) P⇒ : ∀ {A} -> StreamProg A -> Stream A P⇒ xs = ′⇒ (P⇒′ xs) ------------------------------------------------------------------------ -- Stream equality infix 4 _≡_ _≈_ _≊_ data _≡_ {a : Set} (x : a) : a -> Set where ≡-refl : x ≡ x data _≈_ {A} (xs ys : Stream A) : Set where _≺_ : (x≡ : head xs ≡ head ys) (xs≈ : ∞ (tail xs ≈ tail ys)) -> xs ≈ ys _≊_ : ∀ {A} (xs ys : StreamProg A) -> Set xs ≊ ys = P⇒ xs ≈ P⇒ ys foo : ∀ {A : Set} (x : A) -> x ∞ ⋎ x ∞ ≊ x ∞ foo x = ≡-refl ≺ ♯ foo x -- The first goal has goal type -- head (′⇒ (x ≺ x ∞ ⋎ x ∞)) ≡ head (′⇒ (x ≺ x ∞)). -- The normal form of the left-hand side is x, and the normal form of -- the right-hand side is x (both according to Agda), but ≡-refl is -- not accepted by the type checker: -- x != head (′⇒ (P⇒′ (x ∞))) of type .A -- when checking that the expression ≡-refl has type -- (head (P⇒ (x ∞ ⋎ x ∞)) ≡ head (P⇒ (x ∞)))
{ "alphanum_fraction": 0.4392900363, "avg_line_length": 25.2959183673, "ext": "agda", "hexsha": "ff20da98867b086ce09b436b3b5996190e8f07e7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "caryoscelus/agda", "max_forks_repo_path": "test/Succeed/AbstractCoinduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "caryoscelus/agda", "max_issues_repo_path": "test/Succeed/AbstractCoinduction.agda", "max_line_length": 74, "max_stars_count": null, "max_stars_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "caryoscelus/agda", "max_stars_repo_path": "test/Succeed/AbstractCoinduction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1030, "size": 2479 }
module HasVacuousDischarge where open import OscarPrelude open import HasNegation open import HasSubstantiveDischarge record HasVacuousDischarge (A : Set) : Set₁ where field ⦃ hasNegation ⦄ : HasNegation A ⦃ hasSubstantiveDischarge ⦄ : HasSubstantiveDischarge A A ◁_ : List A → Set ◁ +s = ∃ λ (s : A) → +s ≽ s × +s ≽ ~ s ⋪_ : List A → Set ⋪_ = ¬_ ∘ ◁_ open HasVacuousDischarge ⦃ … ⦄ public {-# DISPLAY HasVacuousDischarge.◁_ _ = ◁_ #-} {-# DISPLAY HasVacuousDischarge.⋪_ _ = ⋪_ #-}
{ "alphanum_fraction": 0.6614173228, "avg_line_length": 21.1666666667, "ext": "agda", "hexsha": "8768b9fe273b357971a416d17fabb522dac40af7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-1/HasVacuousDischarge.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-1/HasVacuousDischarge.agda", "max_line_length": 61, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/HasVacuousDischarge.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 202, "size": 508 }
------------------------------------------------------------------------ -- A simplification of Hinze.Section3 ------------------------------------------------------------------------ module Hinze.Simplified.Section3 where open import Stream.Programs open import Stream.Equality open import Stream.Pointwise open import Hinze.Simplified.Section2-4 open import Hinze.Lemmas open import Codata.Musical.Notation hiding (∞) open import Data.Product open import Data.Bool open import Data.Vec hiding (_⋎_) open import Data.Nat renaming (suc to 1+) import Data.Nat.Properties as Nat import Relation.Binary.PropositionalEquality as P open import Algebra.Structures private module CS = IsCommutativeSemiring Nat.+-*-isCommutativeSemiring ------------------------------------------------------------------------ -- Abbreviations 2^ : ℕ → ℕ 2^ n = 2 ^ n 2*2^ : ℕ → ℕ 2*2^ n = 2 * 2 ^ n ------------------------------------------------------------------------ -- Definitions pot : Prog Bool pot = true ≺ ♯ (pot ⋎ false ∞) msb : Prog ℕ msb = 1 ≺ ♯ (2* · msb ⋎ 2* · msb) ones′ : Prog ℕ ones′ = 1 ≺ ♯ (ones′ ⋎ 1+ · ones′) ones : Prog ℕ ones = 0 ≺♯ ones′ carry : Prog ℕ carry = 0 ≺ ♯ (1+ · carry ⋎ 0 ∞) carry-folded : carry ≊ 0 ∞ ⋎ 1+ · carry carry-folded = carry ∎ turn-length : ℕ → ℕ turn-length 0 = 0 turn-length (1+ n) = ℓ + 1+ ℓ where ℓ = turn-length n turn : (n : ℕ) → Vec ℕ (turn-length n) turn 0 = [] turn (1+ n) = turn n ++ [ n ] ++ turn n tree : ℕ → Prog ℕ tree n = n ≺ ♯ (turn n ≺≺ tree (1+ n)) frac : Prog ℕ frac = 0 ≺ ♯ (frac ⋎ 1+ · nat) frac-folded : frac ≊ nat ⋎ frac frac-folded = frac ∎ god : Prog ℕ god = 1+2* · frac ------------------------------------------------------------------------ -- Laws and properties carry-god-nat : 2^ · carry ⟨ _*_ ⟩ god ≊ tailP nat carry-god-nat = 2^ · carry ⟨ _*_ ⟩ god ≊⟨ ⟨ _*_ ⟩-cong (2^ · carry) (1 ∞ ⋎ 2* · 2^ · carry) lemma god (1+2* · nat ⋎ god) (≅-sym (⋎-map 1+2* nat frac)) ⟩ (1 ∞ ⋎ 2* · 2^ · carry) ⟨ _*_ ⟩ (1+2* · nat ⋎ god) ≊⟨ ≅-sym (abide-law _*_ (1 ∞) (1+2* · nat) (2* · 2^ · carry) god) ⟩ 1 ∞ ⟨ _*_ ⟩ 1+2* · nat ⋎ 2* · 2^ · carry ⟨ _*_ ⟩ god ≊⟨ ⋎-cong (1 ∞ ⟨ _*_ ⟩ 1+2* · nat) (1+2* · nat) (pointwise 1 (λ s → 1 ∞ ⟨ _*_ ⟩ s) (λ s → s) (λ n → proj₁ CS.*-identity n) (1+2* · nat)) (2* · 2^ · carry ⟨ _*_ ⟩ god) (2* · (2^ · carry ⟨ _*_ ⟩ god)) (pointwise 2 (λ s t → 2* · s ⟨ _*_ ⟩ t) (λ s t → 2* · (s ⟨ _*_ ⟩ t)) (CS.*-assoc 2) (2^ · carry) god) ⟩ 1+2* · nat ⋎ 2* · (2^ · carry ⟨ _*_ ⟩ god) ≊⟨ P.refl ≺ coih ⟩ 1+2* · nat ⋎ 2* · tailP nat ≊⟨ ≅-sym (tailP-cong nat (2* · nat ⋎ 1+2* · nat) nat-lemma₂) ⟩ tailP nat ∎ where coih = ♯ ⋎-cong (2* · (2^ · carry ⟨ _*_ ⟩ god)) (2* · tailP nat) (·-cong 2* (2^ · carry ⟨ _*_ ⟩ god) (tailP nat) carry-god-nat) (tailP (1+2* · nat)) (tailP (1+2* · nat)) (tailP (1+2* · nat) ∎) lemma = 2^ · carry ≡⟨ P.refl ⟩ 2^ · (0 ∞ ⋎ 1+ · carry) ≊⟨ ≅-sym (⋎-map 2^ (0 ∞) (1+ · carry)) ⟩ 2^ · 0 ∞ ⋎ 2^ · 1+ · carry ≊⟨ ⋎-cong (2^ · 0 ∞) (1 ∞) (pointwise 0 (2^ · 0 ∞) (1 ∞) P.refl) (2^ · 1+ · carry) (2* · 2^ · carry) (pointwise 1 (λ s → 2^ · 1+ · s) (λ s → 2* · 2^ · s) (λ _ → P.refl) carry) ⟩ (1 ∞ ⋎ 2* · 2^ · carry) ∎
{ "alphanum_fraction": 0.3566818073, "avg_line_length": 33.464, "ext": "agda", "hexsha": "87661fe778e4fb2c9d6c4687e7978ff85a617a10", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/codata", "max_forks_repo_path": "Hinze/Simplified/Section3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/codata", "max_issues_repo_path": "Hinze/Simplified/Section3.agda", "max_line_length": 104, "max_stars_count": 1, "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/codata", "max_stars_repo_path": "Hinze/Simplified/Section3.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "num_tokens": 1411, "size": 4183 }
module Luau.Syntax.FromJSON where open import Luau.Syntax using (Block; Stat ; Expr; nil; _$_; var; var_∈_; function_is_end; _⟨_⟩; local_←_; return; done; _∙_; maybe; VarDec; number; binexp; BinaryOperator; +; -; *; /) open import Luau.Type.FromJSON using (typeFromJSON) open import Agda.Builtin.List using (List; _∷_; []) open import FFI.Data.Aeson using (Value; Array; Object; object; array; string; fromString; lookup) open import FFI.Data.Bool using (true; false) open import FFI.Data.Either using (Either; Left; Right) open import FFI.Data.Maybe using (Maybe; nothing; just) open import FFI.Data.Scientific using (toFloat) open import FFI.Data.String using (String; _++_) open import FFI.Data.Vector using (head; tail; null; empty) args = fromString "args" body = fromString "body" func = fromString "func" lokal = fromString "local" list = fromString "list" name = fromString "name" type = fromString "type" value = fromString "value" values = fromString "values" vars = fromString "vars" op = fromString "op" left = fromString "left" right = fromString "right" data Lookup : Set where _,_ : String → Value → Lookup nil : Lookup lookupIn : List String → Object → Lookup lookupIn [] obj = nil lookupIn (key ∷ keys) obj with lookup (fromString key) obj lookupIn (key ∷ keys) obj | nothing = lookupIn keys obj lookupIn (key ∷ keys) obj | just value = (key , value) binOpFromJSON : Value → Either String BinaryOperator binOpFromString : String → Either String BinaryOperator varDecFromJSON : Value → Either String (VarDec maybe) varDecFromObject : Object → Either String (VarDec maybe) exprFromJSON : Value → Either String (Expr maybe) exprFromObject : Object → Either String (Expr maybe) statFromJSON : Value → Either String (Stat maybe) statFromObject : Object → Either String (Stat maybe) blockFromJSON : Value → Either String (Block maybe) blockFromArray : Array → Either String (Block maybe) binOpFromJSON (string s) = binOpFromString s binOpFromJSON val = Left "Binary operator not a string" binOpFromString "Add" = Right + binOpFromString "Sub" = Right - binOpFromString "Mul" = Right * binOpFromString "Div" = Right / binOpFromString s = Left ("'" ++ s ++ "' is not a valid operator") varDecFromJSON (object arg) = varDecFromObject arg varDecFromJSON val = Left "VarDec not an object" varDecFromObject obj with lookup name obj | lookup type obj varDecFromObject obj | just (string name) | nothing = Right (var name) varDecFromObject obj | just (string name) | just Value.null = Right (var name) varDecFromObject obj | just (string name) | just tyValue with typeFromJSON tyValue varDecFromObject obj | just (string name) | just tyValue | Right ty = Right (var name ∈ ty) varDecFromObject obj | just (string name) | just tyValue | Left err = Left err varDecFromObject obj | just _ | _ = Left "AstLocal name is not a string" varDecFromObject obj | nothing | _ = Left "AstLocal missing name" exprFromJSON (object obj) = exprFromObject obj exprFromJSON val = Left "AstExpr not an object" exprFromObject obj with lookup type obj exprFromObject obj | just (string "AstExprCall") with lookup func obj | lookup args obj exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) with head arr exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 with exprFromJSON value | exprFromJSON value2 exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 | Right fun | Right arg = Right (fun $ arg) exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 | Left err | _ = Left err exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 | _ | Left err = Left err exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | nothing = Left ("AstExprCall empty args") exprFromObject obj | just (string "AstExprCall") | just value | just _ = Left ("AstExprCall args not an array") exprFromObject obj | just (string "AstExprCall") | nothing | _ = Left ("AstExprCall missing func") exprFromObject obj | just (string "AstExprCall") | _ | nothing = Left ("AstExprCall missing args") exprFromObject obj | just (string "AstExprConstantNil") = Right nil exprFromObject obj | just (string "AstExprFunction") with lookup args obj | lookup body obj exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue with head arr | blockFromJSON blockValue exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just argValue | Right B with varDecFromJSON argValue exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just argValue | Right B | Right arg = Right (function "" ⟨ arg ⟩ is B end) exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just argValue | Right B | Left err = Left err exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | nothing | Right B = Left "Unsupported AstExprFunction empty args" exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | _ | Left err = Left err exprFromObject obj | just (string "AstExprFunction") | just _ | just _ = Left "AstExprFunction args not an array" exprFromObject obj | just (string "AstExprFunction") | nothing | _ = Left "AstExprFunction missing args" exprFromObject obj | just (string "AstExprFunction") | _ | nothing = Left "AstExprFunction missing body" exprFromObject obj | just (string "AstExprLocal") with lookup lokal obj exprFromObject obj | just (string "AstExprLocal") | just x with varDecFromJSON x exprFromObject obj | just (string "AstExprLocal") | just x | Right x′ = Right (var (Luau.Syntax.name x′)) exprFromObject obj | just (string "AstExprLocal") | just x | Left err = Left err exprFromObject obj | just (string "AstExprLocal") | nothing = Left "AstExprLocal missing local" exprFromObject obj | just (string "AstExprConstantNumber") with lookup value obj exprFromObject obj | just (string "AstExprConstantNumber") | just (FFI.Data.Aeson.Value.number x) = Right (number (toFloat x)) exprFromObject obj | just (string "AstExprConstantNumber") | just _ = Left "AstExprConstantNumber value is not a number" exprFromObject obj | just (string "AstExprConstantNumber") | nothing = Left "AstExprConstantNumber missing value" exprFromObject obj | just (string "AstExprBinary") with lookup op obj | lookup left obj | lookup right obj exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r with binOpFromJSON o | exprFromJSON l | exprFromJSON r exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | Right o′ | Right l′ | Right r′ = Right (binexp l′ o′ r′) exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | Left err | _ | _ = Left err exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | _ | Left err | _ = Left err exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | _ | _ | Left err = Left err exprFromObject obj | just (string "AstExprBinary") | nothing | _ | _ = Left "Missing 'op' in AstExprBinary" exprFromObject obj | just (string "AstExprBinary") | _ | nothing | _ = Left "Missing 'left' in AstExprBinary" exprFromObject obj | just (string "AstExprBinary") | _ | _ | nothing = Left "Missing 'right' in AstExprBinary" exprFromObject obj | just (string ty) = Left ("TODO: Unsupported AstExpr " ++ ty) exprFromObject obj | just _ = Left "AstExpr type not a string" exprFromObject obj | nothing = Left "AstExpr missing type" {-# NON_TERMINATING #-} statFromJSON (object obj) = statFromObject obj statFromJSON _ = Left "AstStat not an object" statFromObject obj with lookup type obj statFromObject obj | just(string "AstStatLocal") with lookup vars obj | lookup values obj statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) with head(arr1) | head(arr2) statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) with varDecFromJSON(x) | exprFromJSON(value) statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) | Right x′ | Right M = Right (local x′ ← M) statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) | Left err | _ = Left err statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) | _ | Left err = Left err statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | nothing = Left "AstStatLocal empty values" statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | nothing | _ = Left "AstStatLocal empty vars" statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(_) = Left "AstStatLocal values not an array" statFromObject obj | just(string "AstStatLocal") | just(_) | just(_) = Left "AstStatLocal vars not an array" statFromObject obj | just(string "AstStatLocal") | just(_) | nothing = Left "AstStatLocal missing values" statFromObject obj | just(string "AstStatLocal") | nothing | _ = Left "AstStatLocal missing vars" statFromObject obj | just(string "AstStatLocalFunction") with lookup name obj | lookup func obj statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value with varDecFromJSON fnName | exprFromJSON value statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | Right fnVar | Right (function "" ⟨ x ⟩ is B end) = Right (function (Luau.Syntax.name fnVar) ⟨ x ⟩ is B end) statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | Left err | _ = Left err statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | _ | Left err = Left err statFromObject obj | just(string "AstStatLocalFunction") | just _ | just _ | Right _ | Right _ = Left "AstStatLocalFunction func is not an AstExprFunction" statFromObject obj | just(string "AstStatLocalFunction") | nothing | _ = Left "AstStatFunction missing name" statFromObject obj | just(string "AstStatLocalFunction") | _ | nothing = Left "AstStatFunction missing func" statFromObject obj | just(string "AstStatReturn") with lookup list obj statFromObject obj | just(string "AstStatReturn") | just(array arr) with head arr statFromObject obj | just(string "AstStatReturn") | just(array arr) | just value with exprFromJSON value statFromObject obj | just(string "AstStatReturn") | just(array arr) | just value | Right M = Right (return M) statFromObject obj | just(string "AstStatReturn") | just(array arr) | just value | Left err = Left err statFromObject obj | just(string "AstStatReturn") | just(array arr) | nothing = Left "AstStatReturn empty list" statFromObject obj | just(string "AstStatReturn") | just(_) = Left "AstStatReturn list not an array" statFromObject obj | just(string "AstStatReturn") | nothing = Left "AstStatReturn missing list" statFromObject obj | just (string ty) = Left ("TODO: Unsupported AstStat " ++ ty) statFromObject obj | just _ = Left "AstStat type not a string" statFromObject obj | nothing = Left "AstStat missing type" blockFromJSON (array arr) = blockFromArray arr blockFromJSON (object obj) with lookup type obj | lookup body obj blockFromJSON (object obj) | just (string "AstStatBlock") | just value = blockFromJSON value blockFromJSON (object obj) | just (string "AstStatBlock") | nothing = Left "AstStatBlock missing body" blockFromJSON (object obj) | just (string ty) | _ = Left ("Unsupported AstBlock " ++ ty) blockFromJSON (object obj) | just _ | _ = Left "AstStatBlock type not a string" blockFromJSON (object obj) | nothing | _ = Left "AstStatBlock missing type" blockFromJSON _ = Left "AstBlock not an array or AstStatBlock object" blockFromArray arr with head arr blockFromArray arr | nothing = Right done blockFromArray arr | just value with statFromJSON value blockFromArray arr | just value | Left err = Left err blockFromArray arr | just value | Right S with blockFromArray(tail arr) blockFromArray arr | just value | Right S | Left err = Left (err) blockFromArray arr | just value | Right S | Right B = Right (S ∙ B)
{ "alphanum_fraction": 0.7401817592, "avg_line_length": 71.6511627907, "ext": "agda", "hexsha": "a2c9a42fb588ab0e873c3117f1764f4fc234ab18", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Tr4shh/Roblox-Luau", "max_forks_repo_path": "prototyping/Luau/Syntax/FromJSON.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Tr4shh/Roblox-Luau", "max_issues_repo_path": "prototyping/Luau/Syntax/FromJSON.agda", "max_line_length": 193, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Tr4shh/Roblox-Luau", "max_stars_repo_path": "prototyping/Luau/Syntax/FromJSON.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3301, "size": 12324 }
------------------------------------------------------------------------ -- Some properties imply others ------------------------------------------------------------------------ module Relation.Binary.Consequences where open import Relation.Binary.Core hiding (refl) open import Relation.Nullary.Core open import Relation.Binary.PropositionalEquality.Core open import Data.Function open import Data.Sum open import Data.Product open import Data.Empty -- Some of the definitions can be found in the following module: open import Relation.Binary.Consequences.Core public trans∧irr⟶asym : ∀ {a} → {≈ < : Rel a} → Reflexive ≈ → Transitive < → Irreflexive ≈ < → Asymmetric < trans∧irr⟶asym refl trans irrefl = λ x<y y<x → irrefl refl (trans x<y y<x) irr∧antisym⟶asym : ∀ {a} → {≈ < : Rel a} → Irreflexive ≈ < → Antisymmetric ≈ < → Asymmetric < irr∧antisym⟶asym irrefl antisym = λ x<y y<x → irrefl (antisym x<y y<x) x<y asym⟶antisym : ∀ {a} → {≈ < : Rel a} → Asymmetric < → Antisymmetric ≈ < asym⟶antisym asym x<y y<x = ⊥-elim (asym x<y y<x) asym⟶irr : ∀ {a} → {≈ < : Rel a} → < Respects₂ ≈ → Symmetric ≈ → Asymmetric < → Irreflexive ≈ < asym⟶irr {< = _<_} resp sym asym {x} {y} x≈y x<y = asym x<y y<x where y<y : y < y y<y = proj₂ resp x≈y x<y y<x : y < x y<x = proj₁ resp (sym x≈y) y<y total⟶refl : ∀ {a} → {≈ ∼ : Rel a} → ∼ Respects₂ ≈ → Symmetric ≈ → Total ∼ → ≈ ⇒ ∼ total⟶refl {≈ = ≈} {∼ = ∼} resp sym total = refl where refl : ≈ ⇒ ∼ refl {x} {y} x≈y with total x y ... | inj₁ x∼y = x∼y ... | inj₂ y∼x = proj₁ resp x≈y (proj₂ resp (sym x≈y) y∼x) total+dec⟶dec : ∀ {a} → {≈ ≤ : Rel a} → ≈ ⇒ ≤ → Antisymmetric ≈ ≤ → Total ≤ → Decidable ≈ → Decidable ≤ total+dec⟶dec {≈ = ≈} {≤ = ≤} refl antisym total _≟_ = dec where dec : Decidable ≤ dec x y with total x y ... | inj₁ x≤y = yes x≤y ... | inj₂ y≤x with x ≟ y ... | yes x≈y = yes (refl x≈y) ... | no ¬x≈y = no (λ x≤y → ¬x≈y (antisym x≤y y≤x)) tri⟶asym : ∀ {a} → {≈ < : Rel a} → Trichotomous ≈ < → Asymmetric < tri⟶asym tri {x} {y} x<y x>y with tri x y ... | tri< _ _ x≯y = x≯y x>y ... | tri≈ _ _ x≯y = x≯y x>y ... | tri> x≮y _ _ = x≮y x<y tri⟶irr : ∀ {a} → {≈ < : Rel a} → < Respects₂ ≈ → Symmetric ≈ → Trichotomous ≈ < → Irreflexive ≈ < tri⟶irr resp sym tri = asym⟶irr resp sym (tri⟶asym tri) tri⟶dec≈ : ∀ {a} → {≈ < : Rel a} → Trichotomous ≈ < → Decidable ≈ tri⟶dec≈ compare x y with compare x y ... | tri< _ x≉y _ = no x≉y ... | tri≈ _ x≈y _ = yes x≈y ... | tri> _ x≉y _ = no x≉y tri⟶dec< : ∀ {a} → {≈ < : Rel a} → Trichotomous ≈ < → Decidable < tri⟶dec< compare x y with compare x y ... | tri< x<y _ _ = yes x<y ... | tri≈ x≮y _ _ = no x≮y ... | tri> x≮y _ _ = no x≮y subst⟶cong : {≈ : ∀ {a} → Rel a} → (∀ {a} → Reflexive {a} ≈) → (∀ {a} → Substitutive {a} ≈) → Congruential ≈ subst⟶cong {≈ = _≈_} refl subst f {x} x≈y = subst (λ y → f x ≈ f y) x≈y refl cong+trans⟶cong₂ : {≈ : ∀ {a} → Rel a} → Congruential ≈ → (∀ {a} → Transitive {a} ≈) → Congruential₂ ≈ cong+trans⟶cong₂ cong trans f {x = x} {v = v} x≈y u≈v = cong (f x) u≈v ⟨ trans ⟩ cong (flip f v) x≈y map-NonEmpty : ∀ {I} {P Q : Rel I} → P ⇒ Q → NonEmpty P → NonEmpty Q map-NonEmpty f x = nonEmpty (f (NonEmpty.proof x))
{ "alphanum_fraction": 0.5203742831, "avg_line_length": 27.3801652893, "ext": "agda", "hexsha": "dc864e727832d05fa81fcda58808b3c5350429c8", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Relation/Binary/Consequences.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Relation/Binary/Consequences.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/Consequences.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 1449, "size": 3313 }
-- Andreas, 2019-08-07, issue #3966 -- -- Precise error location for unification problem during coverage checking. {-# OPTIONS --cubical-compatible #-} module _ {A : Set} where open import Common.Equality open import Common.List data _⊆_ : (xs ys : List A) → Set where _∷ʳ_ : ∀ {xs ys} → ∀ y → _⊆_ xs ys → _⊆_ xs (y ∷ ys) _∷_ : ∀ {x xs y ys} → x ≡ y → _⊆_ xs ys → _⊆_ (x ∷ xs) (y ∷ ys) ⊆-trans : ∀{xs ys zs} → xs ⊆ ys → ys ⊆ zs → xs ⊆ zs ⊆-trans rs (y ∷ʳ ss) = y ∷ʳ ⊆-trans rs ss ⊆-trans (y ∷ʳ rs) (s ∷ ss) = _ ∷ʳ ⊆-trans rs ss ⊆-trans (r ∷ rs) (s ∷ ss) = trans r s ∷ ⊆-trans rs ss -- Provoke a unification error during coverage checking: test : ∀ {x} {xs ys zs : List A} {τ : (x ∷ xs) ⊆ zs} {σ : ys ⊆ zs} us (ρ : us ⊆ zs) (τ' : (x ∷ xs) ⊆ us) (σ' : ys ⊆ us) (σ'∘ρ≡σ : ⊆-trans σ' ρ ≡ σ) → Set₁ test {τ = z ∷ʳ τ} {σ = z ∷ʳ σ} (y ∷ us) (.z ∷ʳ ρ) (y ∷ʳ τ') (refl ∷ σ') refl = Set test {σ = z ∷ʳ σ} _ (refl ∷ ρ) _ (refl ∷ σ') () test {τ = z ∷ʳ τ} {σ = refl ∷ σ} (y ∷ us) ρ (y ∷ʳ τ') (refl ∷ σ') σ'∘ρ≡σ = Set test {τ = refl ∷ τ} {σ = z ∷ʳ σ} (y ∷ us) ρ (y ∷ʳ τ') (refl ∷ σ') σ'∘ρ≡σ = Set test {τ = refl ∷ τ} {σ = refl ∷ σ} (y ∷ us) ρ (y ∷ʳ τ') (refl ∷ σ') σ'∘ρ≡σ = Set test (x ∷ us) ρ (refl ∷ τ') (x ∷ʳ σ') refl = Set -- ONLY this LHS should be highlighted! test (x ∷ us) ρ (refl ∷ τ') (refl ∷ σ') σ'∘ρ≡σ = Set test (y ∷ us) ρ (y ∷ʳ τ') (refl ∷ σ') σ'∘ρ≡σ = Set -- Expected error location: 34,1-43 -- I'm not sure if there should be a case for the constructor refl, -- because I get stuck when trying to solve the following unification -- problems (inferred index ≟ expected index): -- ⊆-trans (x ∷ʳ σ') ρ ≟ refl ∷ σ -- when checking the definition of test
{ "alphanum_fraction": 0.5272088941, "avg_line_length": 37.9777777778, "ext": "agda", "hexsha": "8fb936a1faf2d277694f55fe5f6d1c770cd231a1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Fail/Issue3966.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Fail/Issue3966.agda", "max_line_length": 89, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/Issue3966.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 822, "size": 1709 }
{-# OPTIONS --without-K #-} module Agda.Builtin.Word where open import Agda.Builtin.Nat postulate Word64 : Set {-# BUILTIN WORD64 Word64 #-} primitive primWord64ToNat : Word64 → Nat primWord64FromNat : Nat → Word64
{ "alphanum_fraction": 0.7155555556, "avg_line_length": 17.3076923077, "ext": "agda", "hexsha": "124fb8ea7cd27be76f47a7d8a59c4866f6e367de", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "asr/eagda", "max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Word.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "asr/eagda", "max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Word.agda", "max_line_length": 34, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "asr/eagda", "max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Word.agda", "max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z", "num_tokens": 65, "size": 225 }
{-# OPTIONS --safe #-} -- --without-K #-} open import Relation.Nullary.Decidable using (toWitness; fromWitness) open import Relation.Nullary using (yes; no) open import Function using (_∘_) import Data.Empty as Empty import Data.Product as Product import Data.Product.Properties as Productₚ import Data.Unit as Unit import Data.Nat.Base as Nat import Data.Vec.Base as Vec import Data.Vec.Properties as Vecₚ import Data.Fin.Base as Fin import Data.Vec.Relation.Unary.All as All open Empty using (⊥-elim) open Unit using (tt) open Nat using (ℕ; zero; suc) open Vec using (Vec; []; _∷_) open All using (All; []; _∷_) open Fin using (Fin ; zero ; suc) open Product using (_×_; _,_; proj₁; proj₂) import PiCalculus.Syntax open PiCalculus.Syntax.Scoped open import PiCalculus.Semantics open import PiCalculus.LinearTypeSystem.Algebras module PiCalculus.LinearTypeSystem.Framing (Ω : Algebras) where open Algebras Ω open import PiCalculus.LinearTypeSystem Ω open import PiCalculus.LinearTypeSystem.ContextLemmas Ω private variable n : ℕ i j : Fin n idx : Idx idxs : Idxs n γ : PreCtx n t : Type x y z : Usage idx Γ Θ Δ Ξ : Ctx idxs P Q : Scoped n ∋-frame : {idxs : Idxs n} {Γ Θ Δ Ξ Ψ : Ctx idxs} {x : Usage idx ²} → Γ ≔ Δ ⊗ Θ → Ξ ≔ Δ ⊗ Ψ → Γ ∋[ i ] x ▹ Θ → Ξ ∋[ i ] x ▹ Ψ ∋-frame (Γ≔ , x≔) (Ξ≔ , x'≔) (zero xyz) rewrite ⊗-uniqueˡ Γ≔ ⊗-idˡ | ⊗-unique Ξ≔ ⊗-idˡ | ∙²-uniqueˡ x≔ xyz = zero x'≔ ∋-frame (Γ≔ , x≔) (Ξ≔ , x'≔) (suc x) rewrite ∙²-uniqueˡ x≔ ∙²-idˡ | ∙²-unique x'≔ ∙²-idˡ = suc (∋-frame Γ≔ Ξ≔ x) ⊢-frame : {γ : PreCtx n} {idxs : Idxs n} {Γ Δ Θ Ξ Ψ : Ctx idxs} → Γ ≔ Δ ⊗ Θ → Ξ ≔ Δ ⊗ Ψ → γ ; Γ ⊢ P ▹ Θ → γ ; Ξ ⊢ P ▹ Ψ ⊢-frame Γ≔ Ξ≔ 𝟘 rewrite ⊗-uniqueˡ Γ≔ ⊗-idˡ | ⊗-unique Ξ≔ ⊗-idˡ = 𝟘 ⊢-frame Γ≔ Ξ≔ (ν t m μ ⊢P) = ν t m μ (⊢-frame {Δ = _ -, (μ , μ)} (Γ≔ , ∙²-idʳ) (Ξ≔ , ∙²-idʳ) ⊢P) ⊢-frame Γ≔ Ξ≔ ((t , ∋i) ⦅⦆ ⊢P) with ∋-⊗ ∋i | ⊢-⊗ ⊢P ⊢-frame Γ≔ Ξ≔ ((t , ∋i) ⦅⦆ ⊢P) | _ , i≔ , _ | (_ -, _) , (P≔ , x≔) = let iP≔ = ⊗-comp i≔ P≔ Γ≔ _ , i'≔ , P'≔ = ⊗-assoc Ξ≔ iP≔ in (t , ∋-frame i≔ i'≔ ∋i) ⦅⦆ ⊢-frame (P≔ , x≔) (P'≔ , x≔) ⊢P ⊢-frame Γ≔ Ξ≔ ((ti , ∋i) ⟨ tj , ∋j ⟩ ⊢P) with ∋-⊗ ∋i | ∋-⊗ ∋j | ⊢-⊗ ⊢P ⊢-frame Γ≔ Ξ≔ ((ti , ∋i) ⟨ tj , ∋j ⟩ ⊢P) | _ , i≔ , _ | _ , j≔ , _ | _ , P≔ = let _ , ij≔ , _ = ⊗-assoc⁻¹ i≔ j≔ [ij]P≔ = ⊗-comp ij≔ P≔ Γ≔ _ , ij'≔ , P'≔ = ⊗-assoc Ξ≔ [ij]P≔ ij≔ = ⊗-comp i≔ j≔ ij≔ _ , i'≔ , j'≔ = ⊗-assoc ij'≔ ij≔ in (ti , ∋-frame i≔ i'≔ ∋i) ⟨ tj , ∋-frame j≔ j'≔ ∋j ⟩ ⊢-frame P≔ P'≔ ⊢P ⊢-frame Γ≔ Ξ≔ (⊢P ∥ ⊢Q) with ⊢-⊗ ⊢P | ⊢-⊗ ⊢Q ⊢-frame Γ≔ Ξ≔ (⊢P ∥ ⊢Q) | _ , P≔ | _ , Q≔ = let PQ≔ = ⊗-comp P≔ Q≔ Γ≔ _ , P'≔ , Q'≔ = ⊗-assoc Ξ≔ PQ≔ in ⊢-frame P≔ P'≔ ⊢P ∥ ⊢-frame Q≔ Q'≔ ⊢Q
{ "alphanum_fraction": 0.5161870504, "avg_line_length": 32.7058823529, "ext": "agda", "hexsha": "838a1eee20adac8a5a82e098134b6f691149342f", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z", "max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/typing-linear-pi", "max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/Framing.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/typing-linear-pi", "max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/Framing.agda", "max_line_length": 77, "max_stars_count": 26, "max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/typing-linear-pi", "max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/Framing.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z", "num_tokens": 1467, "size": 2780 }
{-# OPTIONS --without-K #-} module hott.loop.level where open import sets.nat.core open import hott.loop.core open import hott.level.core Ω-level : ∀ {i n}{X : Set i}(m : ℕ){x : X} → h (m + n) X → h n (Ω m x) Ω-level zero hX = hX Ω-level (suc m) hX = Ω-level m (hX _ _)
{ "alphanum_fraction": 0.6, "avg_line_length": 23.3333333333, "ext": "agda", "hexsha": "16f99f43961ed7f35bfdb92e06d58ee3a7bbb466", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/hott/loop/level.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/hott/loop/level.agda", "max_line_length": 42, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/hott/loop/level.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 102, "size": 280 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Finite sets ------------------------------------------------------------------------ -- Note that elements of Fin n can be seen as natural numbers in the -- set {m | m < n}. The notation "m" in comments below refers to this -- natural number view. module Data.Fin where open import Data.Nat as Nat using (ℕ; zero; suc; z≤n; s≤s) renaming ( _+_ to _N+_; _∸_ to _N∸_ ; _≤_ to _N≤_; _≥_ to _N≥_; _<_ to _N<_; _≤?_ to _N≤?_) open import Function import Level open import Relation.Nullary.Decidable open import Relation.Binary ------------------------------------------------------------------------ -- Types -- Fin n is a type with n elements. data Fin : ℕ → Set where zero : {n : ℕ} → Fin (suc n) suc : {n : ℕ} (i : Fin n) → Fin (suc n) -- A conversion: toℕ "n" = n. toℕ : ∀ {n} → Fin n → ℕ toℕ zero = 0 toℕ (suc i) = suc (toℕ i) -- A Fin-indexed variant of Fin. Fin′ : ∀ {n} → Fin n → Set Fin′ i = Fin (toℕ i) ------------------------------------------------------------------------ -- Conversions -- toℕ is defined above. -- fromℕ n = "n". fromℕ : (n : ℕ) → Fin (suc n) fromℕ zero = zero fromℕ (suc n) = suc (fromℕ n) -- fromℕ≤ {m} _ = "m". fromℕ≤ : ∀ {m n} → m N< n → Fin n fromℕ≤ (Nat.s≤s Nat.z≤n) = zero fromℕ≤ (Nat.s≤s (Nat.s≤s m≤n)) = suc (fromℕ≤ (Nat.s≤s m≤n)) -- # m = "m". #_ : ∀ m {n} {m<n : True (suc m N≤? n)} → Fin n #_ _ {m<n = m<n} = fromℕ≤ (toWitness m<n) -- raise m "n" = "m + n". raise : ∀ {m} n → Fin m → Fin (n N+ m) raise zero i = i raise (suc n) i = suc (raise n i) -- reduce≥ "m + n" _ = "n". reduce≥ : ∀ {m n} (i : Fin (m N+ n)) (i≥m : toℕ i N≥ m) → Fin n reduce≥ {zero} i i≥m = i reduce≥ {suc m} zero () reduce≥ {suc m} (suc i) (s≤s i≥m) = reduce≥ i i≥m -- inject⋆ m "n" = "n". inject : ∀ {n} {i : Fin n} → Fin′ i → Fin n inject {i = zero} () inject {i = suc i} zero = zero inject {i = suc i} (suc j) = suc (inject j) inject! : ∀ {n} {i : Fin (suc n)} → Fin′ i → Fin n inject! {n = zero} {i = suc ()} _ inject! {i = zero} () inject! {n = suc _} {i = suc _} zero = zero inject! {n = suc _} {i = suc _} (suc j) = suc (inject! j) inject+ : ∀ {m} n → Fin m → Fin (m N+ n) inject+ n zero = zero inject+ n (suc i) = suc (inject+ n i) inject₁ : ∀ {m} → Fin m → Fin (suc m) inject₁ zero = zero inject₁ (suc i) = suc (inject₁ i) inject≤ : ∀ {m n} → Fin m → m N≤ n → Fin n inject≤ zero (Nat.s≤s le) = zero inject≤ (suc i) (Nat.s≤s le) = suc (inject≤ i le) ------------------------------------------------------------------------ -- Operations -- Folds. fold : ∀ (T : ℕ → Set) {m} → (∀ {n} → T n → T (suc n)) → (∀ {n} → T (suc n)) → Fin m → T m fold T f x zero = x fold T f x (suc i) = f (fold T f x i) fold′ : ∀ {n t} (T : Fin (suc n) → Set t) → (∀ i → T (inject₁ i) → T (suc i)) → T zero → ∀ i → T i fold′ T f x zero = x fold′ {n = zero} T f x (suc ()) fold′ {n = suc n} T f x (suc i) = f i (fold′ (T ∘ inject₁) (f ∘ inject₁) x i) -- Lifts functions. lift : ∀ {m n} k → (Fin m → Fin n) → Fin (k N+ m) → Fin (k N+ n) lift zero f i = f i lift (suc k) f zero = zero lift (suc k) f (suc i) = suc (lift k f i) -- "m" + "n" = "m + n". infixl 6 _+_ _+_ : ∀ {m n} (i : Fin m) (j : Fin n) → Fin (toℕ i N+ n) zero + j = j suc i + j = suc (i + j) -- "m" - "n" = "m ∸ n". infixl 6 _-_ _-_ : ∀ {m} (i : Fin m) (j : Fin′ (suc i)) → Fin (m N∸ toℕ j) i - zero = i zero - suc () suc i - suc j = i - j -- m ℕ- "n" = "m ∸ n". infixl 6 _ℕ-_ _ℕ-_ : (n : ℕ) (j : Fin (suc n)) → Fin (suc n N∸ toℕ j) n ℕ- zero = fromℕ n zero ℕ- suc () suc n ℕ- suc i = n ℕ- i -- m ℕ-ℕ "n" = m ∸ n. infixl 6 _ℕ-ℕ_ _ℕ-ℕ_ : (n : ℕ) → Fin (suc n) → ℕ n ℕ-ℕ zero = n zero ℕ-ℕ suc () suc n ℕ-ℕ suc i = n ℕ-ℕ i -- pred "n" = "pred n". pred : ∀ {n} → Fin n → Fin n pred zero = zero pred (suc i) = inject₁ i ------------------------------------------------------------------------ -- Order relations infix 4 _≤_ _<_ _≤_ : ∀ {n} → Rel (Fin n) Level.zero _≤_ = _N≤_ on toℕ _<_ : ∀ {n} → Rel (Fin n) Level.zero _<_ = _N<_ on toℕ data _≺_ : ℕ → ℕ → Set where _≻toℕ_ : ∀ n (i : Fin n) → toℕ i ≺ n -- An ordering view. data Ordering {n : ℕ} : Fin n → Fin n → Set where less : ∀ greatest (least : Fin′ greatest) → Ordering (inject least) greatest equal : ∀ i → Ordering i i greater : ∀ greatest (least : Fin′ greatest) → Ordering greatest (inject least) compare : ∀ {n} (i j : Fin n) → Ordering i j compare zero zero = equal zero compare zero (suc j) = less (suc j) zero compare (suc i) zero = greater (suc i) zero compare (suc i) (suc j) with compare i j compare (suc .(inject least)) (suc .greatest) | less greatest least = less (suc greatest) (suc least) compare (suc .greatest) (suc .(inject least)) | greater greatest least = greater (suc greatest) (suc least) compare (suc .i) (suc .i) | equal i = equal (suc i)
{ "alphanum_fraction": 0.4597083653, "avg_line_length": 25.5490196078, "ext": "agda", "hexsha": "1f6be1695510b03ee1ff1dbbfbdd32eda333ef2b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Data/Fin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Data/Fin.agda", "max_line_length": 84, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Data/Fin.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 2035, "size": 5212 }
{-# OPTIONS --rewriting --confluence-check #-} open import Agda.Builtin.Nat using (Nat; zero; suc) open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite variable k l m n : Nat postulate max : Nat → Nat → Nat max-0l : max 0 n ≡ n max-0r : max m 0 ≡ m max-diag : max m m ≡ m max-ss : max (suc m) (suc n) ≡ suc (max m n) max-assoc : max (max k l) m ≡ max k (max l m) {-# REWRITE max-0l #-} {-# REWRITE max-0r #-} {-# REWRITE max-diag #-} {-# REWRITE max-ss #-} --{-# REWRITE max-assoc #-} -- not confluent! postulate _+_ : Nat → Nat → Nat plus-0l : 0 + n ≡ n plus-0r : m + 0 ≡ m plus-suc-l : (suc m) + n ≡ suc (m + n) plus-suc-r : m + (suc n) ≡ suc (m + n) plus-assoc : (k + l) + m ≡ k + (l + m) {-# REWRITE plus-0l #-} {-# REWRITE plus-0r #-} {-# REWRITE plus-suc-l #-} {-# REWRITE plus-suc-r #-} {-# REWRITE plus-assoc #-} postulate _*_ : Nat → Nat → Nat mult-0l : 0 * n ≡ 0 mult-0r : m * 0 ≡ 0 mult-suc-l : (suc m) * n ≡ n + (m * n) mult-suc-r : m * (suc n) ≡ (m * n) + m plus-mult-distr-l : k * (l + m) ≡ (k * l) + (k * m) plus-mult-distr-r : (k + l) * m ≡ (k * m) + (l * m) mult-assoc : (k * l) * m ≡ k * (l * m) {-# REWRITE mult-0l #-} {-# REWRITE mult-0r #-} {-# REWRITE mult-suc-l #-} {-# REWRITE mult-suc-r #-} -- requires rule plus-assoc! --{-# REWRITE plus-mult-distr-l #-} --{-# REWRITE plus-mult-distr-r #-} --{-# REWRITE mult-assoc #-}
{ "alphanum_fraction": 0.532769556, "avg_line_length": 25.8, "ext": "agda", "hexsha": "f2da81c32b999eb10a60abf7269033db0633d45c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/RewritingConfluence.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Succeed/RewritingConfluence.agda", "max_line_length": 55, "max_stars_count": 2, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Succeed/RewritingConfluence.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 572, "size": 1419 }
{-# OPTIONS --allow-unsolved-metas #-} module AgdaFeatureInstanceResolutionViaConstraint where postulate A : Set postulate y : A Appy : (A → Set) → Set Appy H = H y record Foo (T : Set) : Set where field foo : T open Foo ⦃ … ⦄ public postulate S : A → Set record Failing : Set where no-eta-equality postulate instance FooInstance : {R : A → Set} → Foo (Appy R) works1 : Appy S works1 = foo ⦃ FooInstance {R = S} ⦄ fails2 : Appy S fails2 = foo ⦃ FooInstance {R = {!!}} ⦄ {- [21] (_R_11 y) =< (S y) : Set _12 := λ → Foo.foo FooInstance [blocked by problem 21] -} fails3 : Appy S fails3 = foo record Succeeds : Set where no-eta-equality record Bar (B : A → Set) : Set where no-eta-equality postulate instance BarInstance : Bar S instance FooInstance : {R : A → Set} ⦃ _ : Bar R ⦄ → Foo (Appy R) works1 : Appy S works1 = foo ⦃ FooInstance {R = S} ⦄ works2 : Appy S works2 = foo ⦃ FooInstance {R = {!!}} ⦄ works3 : Appy S works3 = foo
{ "alphanum_fraction": 0.606330366, "avg_line_length": 18.3818181818, "ext": "agda", "hexsha": "41b431be371e2e72a44d4eca5b9531841c267a3b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/AgdaFeatureInstanceResolutionViaConstraint.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/AgdaFeatureInstanceResolutionViaConstraint.agda", "max_line_length": 69, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/AgdaFeatureInstanceResolutionViaConstraint.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 378, "size": 1011 }
{-# OPTIONS --cubical --no-import-sorts --guardedness --safe #-} -- Construction of M-types from -- https://arxiv.org/pdf/1504.02949.pdf -- "Non-wellfounded trees in Homotopy Type Theory" -- Benedikt Ahrens, Paolo Capriotti, Régis Spadotti module Cubical.Codata.M.AsLimit.M.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv using (_≃_) open import Cubical.Foundations.Function using (_∘_) open import Cubical.Data.Unit open import Cubical.Data.Prod open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ ) open import Cubical.Data.Sigma hiding (_×_) open import Cubical.Data.Nat.Algebra open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function open import Cubical.Foundations.Path open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws open import Cubical.Data.Sum open import Cubical.Codata.M.AsLimit.helper open import Cubical.Codata.M.AsLimit.Container open import Cubical.Codata.M.AsLimit.Coalg.Base open Iso private limit-collapse : ∀ {ℓ} {S : Container ℓ} (X : ℕ → Type ℓ) (l : (n : ℕ) → X n → X (suc n)) → (x₀ : X 0) → ∀ (n : ℕ) → X n limit-collapse X l x₀ 0 = x₀ limit-collapse {S = S} X l x₀ (suc n) = l n (limit-collapse {S = S} X l x₀ n) lemma11-Iso : ∀ {ℓ} {S : Container ℓ} (X : ℕ → Type ℓ) (l : (n : ℕ) → X n → X (suc n)) → Iso (Σ[ x ∈ ((n : ℕ) → X n)] ((n : ℕ) → x (suc n) ≡ l n (x n))) (X 0) fun (lemma11-Iso X l) (x , y) = x 0 inv (lemma11-Iso {S = S} X l) x₀ = limit-collapse {S = S} X l x₀ , (λ n → refl {x = limit-collapse {S = S} X l x₀ (suc n)}) rightInv (lemma11-Iso X l) _ = refl leftInv (lemma11-Iso {ℓ = ℓ} {S = S} X l) (x , y) i = let temp = χ-prop (x 0) (fst (inv (lemma11-Iso {S = S} X l) (fun (lemma11-Iso {S = S} X l) (x , y))) , refl , (λ n → refl {x = limit-collapse {S = S} X l (x 0) (suc n)})) (x , refl , y) in temp i .fst , proj₂ (temp i .snd) where open AlgebraPropositionality open NatSection X-fiber-over-ℕ : (x₀ : X 0) -> NatFiber NatAlgebraℕ ℓ X-fiber-over-ℕ x₀ = record { Fiber = X ; fib-zero = x₀ ; fib-suc = λ {n : ℕ} xₙ → l n xₙ } X-section : (x₀ : X 0) → (z : Σ[ x ∈ ((n : ℕ) → X n)] (x 0 ≡ x₀) × (∀ n → (x (suc n)) ≡ l n (x n))) -> NatSection (X-fiber-over-ℕ x₀) X-section = λ x₀ z → record { section = fst z ; sec-comm-zero = proj₁ (snd z) ; sec-comm-suc = proj₂ (snd z) } Z-is-Section : (x₀ : X 0) → Iso (Σ[ x ∈ ((n : ℕ) → X n)] (x 0 ≡ x₀) × (∀ n → (x (suc n)) ≡ l n (x n))) (NatSection (X-fiber-over-ℕ x₀)) fun (Z-is-Section x₀) (x , (z , y)) = record { section = x ; sec-comm-zero = z ; sec-comm-suc = y } inv (Z-is-Section x₀) x = NatSection.section x , (sec-comm-zero x , sec-comm-suc x) rightInv (Z-is-Section x₀) _ = refl leftInv (Z-is-Section x₀) (x , (z , y)) = refl -- S≡T χ-prop' : (x₀ : X 0) → isProp (NatSection (X-fiber-over-ℕ x₀)) χ-prop' x₀ a b = SectionProp.S≡T isNatInductiveℕ (X-section x₀ (inv (Z-is-Section x₀) a)) (X-section x₀ (inv (Z-is-Section x₀) b)) χ-prop : (x₀ : X 0) → isProp (Σ[ x ∈ ((n : ℕ) → X n) ] (x 0 ≡ x₀) × (∀ n → (x (suc n)) ≡ l n (x n))) χ-prop x₀ = subst isProp (sym (isoToPath (Z-is-Section x₀))) (χ-prop' x₀) ----------------------------------------------------- -- Shifting the limit of a chain is an equivalence -- ----------------------------------------------------- -- Shift is equivalence (12) and (13) in the proof of Theorem 7 -- https://arxiv.org/pdf/1504.02949.pdf -- "Non-wellfounded trees in Homotopy Type Theory" -- Benedikt Ahrens, Paolo Capriotti, Régis Spadotti -- TODO: This definition is inefficient, it should be updated to use some cubical features! shift-iso : ∀ {ℓ} (S : Container ℓ) -> Iso (P₀ S (M S)) (M S) shift-iso S@(A , B) = P₀ S (M S) Iso⟨ Σ-cong-iso-snd (λ x → iso (λ f → (λ n z → f z .fst n) , λ n i a → f a .snd n i) (λ (u , q) z → (λ n → u n z) , λ n i → q n i z) (λ _ → refl) (λ _ → refl)) ⟩ (Σ[ a ∈ A ] (Σ[ u ∈ ((n : ℕ) → B a → X (sequence S) n) ] ((n : ℕ) → π (sequence S) ∘ (u (suc n)) ≡ u n))) Iso⟨ invIso α-iso-step-5-Iso ⟩ (Σ[ a ∈ (Σ[ a ∈ ((n : ℕ) → A) ] ((n : ℕ) → a (suc n) ≡ a n)) ] Σ[ u ∈ ((n : ℕ) → B (a .fst n) → X (sequence S) n) ] ((n : ℕ) → PathP (λ x → B (a .snd n x) → X (sequence S) n) (π (sequence S) ∘ u (suc n)) (u n))) Iso⟨ α-iso-step-1-4-Iso-lem-12 ⟩ M S ∎Iso where α-iso-step-5-Iso-helper0 : ∀ (a : (ℕ -> A)) → (p : (n : ℕ) → a (suc n) ≡ a n) → (n : ℕ) → a n ≡ a 0 α-iso-step-5-Iso-helper0 a p 0 = refl α-iso-step-5-Iso-helper0 a p (suc n) = p n ∙ α-iso-step-5-Iso-helper0 a p n α-iso-step-5-Iso-helper1-Iso : ∀ (a : ℕ -> A) → (p : (n : ℕ) → a (suc n) ≡ a n) → (u : (n : ℕ) → B (a n) → Wₙ S n) → (n : ℕ) → (PathP (λ x → B (p n x) → Wₙ S n) (πₙ S ∘ u (suc n)) (u n)) ≡ (πₙ S ∘ (subst (\k -> B k → Wₙ S (suc n)) (α-iso-step-5-Iso-helper0 a p (suc n))) (u (suc n)) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n)) α-iso-step-5-Iso-helper1-Iso a p u n = PathP (λ x → B (p n x) → Wₙ S n) (πₙ S ∘ u (suc n)) (u n) ≡⟨ PathP≡Path (λ x → B (p n x) → Wₙ S n) (πₙ S ∘ u (suc n)) (u n) ⟩ subst (λ k → B k → Wₙ S n) (p n) (πₙ S ∘ u (suc n)) ≡ (u n) ≡⟨ (λ i → transp (λ j → B (α-iso-step-5-Iso-helper0 a p n (i ∧ j)) → Wₙ S n) (~ i) (subst (λ k → B k → Wₙ S n) (p n) (πₙ S ∘ u (suc n))) ≡ transp (λ j → B (α-iso-step-5-Iso-helper0 a p n (i ∧ j)) → Wₙ S n) (~ i) (u n)) ⟩ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (subst (λ k → B k → Wₙ S n) (p n) (πₙ S ∘ u (suc n))) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n) ≡⟨ (λ i → sym (substComposite (λ k → B k → Wₙ S n) (p n) (α-iso-step-5-Iso-helper0 a p n) (πₙ S ∘ u (suc n))) i ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n)) ⟩ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p (suc n)) (πₙ S ∘ u (suc n)) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n) ≡⟨ (λ i → substCommSlice (λ k → B k → Wₙ S (suc n)) (λ k → B k → Wₙ S n) (λ a x x₁ → (πₙ S) (x x₁)) (α-iso-step-5-Iso-helper0 a p (suc n)) (u (suc n)) i ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n)) ⟩ πₙ S ∘ subst (λ k → B k → Wₙ S (suc n)) (α-iso-step-5-Iso-helper0 a p (suc n)) (u (suc n)) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n) ∎ α-iso-step-5-Iso : Iso (Σ[ a ∈ (Σ[ a ∈ ((n : ℕ) → A) ] ((n : ℕ) → a (suc n) ≡ a n)) ] Σ[ u ∈ ((n : ℕ) → B (a .fst n) → X (sequence S) n) ] ((n : ℕ) → PathP (λ x → B (a .snd n x) → X (sequence S) n) (π (sequence S) ∘ u (suc n)) (u n))) (Σ[ a ∈ A ] (Σ[ u ∈ ((n : ℕ) → B a → X (sequence S) n) ] ((n : ℕ) → π (sequence S) ∘ (u (suc n)) ≡ u n))) α-iso-step-5-Iso = Σ-cong-iso (lemma11-Iso {S = S} (λ _ → A) (λ _ x → x)) (λ a,p → Σ-cong-iso (pathToIso (cong (λ k → (n : ℕ) → k n) (funExt λ n → cong (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 (a,p .fst) (a,p .snd) n)))) λ u → pathToIso (cong (λ k → (n : ℕ) → k n) (funExt λ n → α-iso-step-5-Iso-helper1-Iso (a,p .fst) (a,p .snd) u n))) α-iso-step-1-4-Iso-lem-12 : Iso (Σ[ a ∈ (Σ[ a ∈ ((n : ℕ) → A)] ((n : ℕ) → a (suc n) ≡ a n)) ] (Σ[ u ∈ ((n : ℕ) → B (a .fst n) → X (sequence S) n) ] ((n : ℕ) → PathP (λ x → B (a .snd n x) → X (sequence S) n) (π (sequence S) ∘ u (suc n)) (u n)))) (limit-of-chain (sequence S)) fun α-iso-step-1-4-Iso-lem-12 (a , b) = (λ { 0 → lift tt ; (suc n) → (a .fst n) , (b .fst n)}) , λ { 0 → refl {x = lift tt} ; (suc m) i → a .snd m i , b .snd m i } inv α-iso-step-1-4-Iso-lem-12 x = ((λ n → (x .fst) (suc n) .fst) , λ n i → (x .snd) (suc n) i .fst) , (λ n → (x .fst) (suc n) .snd) , λ n i → (x .snd) (suc n) i .snd fst (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) 0 = lift tt fst (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) (suc n) = refl i snd (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) 0 = refl snd (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) (suc n) = c (suc n) leftInv α-iso-step-1-4-Iso-lem-12 (a , b) = refl shift : ∀ {ℓ} (S : Container ℓ) -> P₀ S (M S) ≡ M S shift S = isoToPath (shift-iso S) -- lemma 13 & lemma 12 -- Transporting along shift in-fun : ∀ {ℓ} {S : Container ℓ} -> P₀ S (M S) -> M S in-fun {S = S} = fun (shift-iso S) out-fun : ∀ {ℓ} {S : Container ℓ} -> M S -> P₀ S (M S) out-fun {S = S} = inv (shift-iso S) -- Property of functions into M-types lift-to-M : ∀ {ℓ} {A : Type ℓ} {S : Container ℓ} → (x : (n : ℕ) -> A → X (sequence S) n) → ((n : ℕ) → (a : A) → π (sequence S) (x (suc n) a) ≡ x n a) --------------- → (A → M S) lift-to-M x p a = (λ n → x n a) , λ n i → p n a i lift-direct-M : ∀ {ℓ} {S : Container ℓ} → (x : (n : ℕ) → X (sequence S) n) → ((n : ℕ) → π (sequence S) (x (suc n)) ≡ x n) --------------- → M S lift-direct-M x p = x , p
{ "alphanum_fraction": 0.4840618835, "avg_line_length": 49.3897435897, "ext": "agda", "hexsha": "992810c3ecdb50c614d39c859ae66d27adecde6d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Codata/M/AsLimit/M/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Codata/M/AsLimit/M/Base.agda", "max_line_length": 187, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Codata/M/AsLimit/M/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4004, "size": 9631 }
{-# OPTIONS --without-K #-} module lob where open import common open import well-typed-syntax open import well-typed-quoted-syntax open import well-typed-syntax-interpreter-full module inner (‘X’ : Typ ε) (‘f’ : Term {Γ = ε ▻ (‘□’ ‘’ ⌜ ‘X’ ⌝T)} (W ‘X’)) where X : Set _ X = Typε⇓ ‘X’ f'' : (x : Typε⇓ (‘□’ ‘’ ⌜ ‘X’ ⌝T)) → Typε▻⇓ {‘□’ ‘’ ⌜ ‘X’ ⌝T} (W ‘X’) x f'' = Termε▻⇓ ‘f’ {-f : □ ‘X’ → X f □‘X’ = un▻-Typε▻⇓ (Termε▻⇓ ‘f’ helper) where helper : {!.well-typed-syntax-interpreter.Typ⇓ (transfer-Typ (‘□’ ‘’ ⌜ ‘X’ ⌝T)) .well-typed-syntax-interpreter-full.Contextε⇓!} helper = {!!}-} dummy : Typ ε dummy = ‘Context’ cast : (Γv : Σ Context Typ) → Typ (ε ▻ ‘Σ’ ‘Context’ ‘Typ’) cast (Γ , v) = context-pick-if {P = Typ} {Γ} (W dummy) v Hf : (h : Σ Context Typ) → Typ ε Hf h = (cast h ‘’ quote-sigma h ‘→'’ ‘X’) qh : Term {Γ = (ε ▻ ‘Σ’ ‘Context’ ‘Typ’)} (W (‘Typ’ ‘’ ‘ε’)) qh = f' w‘‘’’ x where f' : Term (W (‘Typ’ ‘’ ⌜ ε ▻ ‘Σ’ ‘Context’ ‘Typ’ ⌝c)) f' = w→ ‘cast’ ‘'’ₐ ‘VAR₀’ x : Term (W (‘Term’ ‘’₁ ⌜ ε ⌝c ‘’ ⌜ ‘Σ’ ‘Context’ ‘Typ’ ⌝T)) x = (w→ ‘quote-sigma’ ‘'’ₐ ‘VAR₀’) h2 : Typ (ε ▻ ‘Σ’ ‘Context’ ‘Typ’) h2 = (W1 ‘□’ ‘’ (qh w‘‘→'’’ w ⌜ ‘X’ ⌝T)) h : Σ Context Typ h = ((ε ▻ ‘Σ’ ‘Context’ ‘Typ’) , h2) H0 : Typ ε H0 = Hf h H : Set H = Term {Γ = ε} H0 ‘H0’ : □ (‘Typ’ ‘’ ⌜ ε ⌝c) ‘H0’ = ⌜ H0 ⌝T ‘H’ : Typ ε ‘H’ = ‘□’ ‘’ ‘H0’ H0' : Typ ε H0' = ‘H’ ‘→'’ ‘X’ H' : Set H' = Term {Γ = ε} H0' ‘H0'’ : □ (‘Typ’ ‘’ ⌜ ε ⌝c) ‘H0'’ = ⌜ H0' ⌝T ‘H'’ : Typ ε ‘H'’ = ‘□’ ‘’ ‘H0'’ toH-helper-helper : ∀ {k} → h2 ≡ k → □ (h2 ‘’ quote-sigma h ‘→'’ ‘□’ ‘’ ⌜ h2 ‘’ quote-sigma h ‘→'’ ‘X’ ⌝T) → □ (k ‘’ quote-sigma h ‘→'’ ‘□’ ‘’ ⌜ k ‘’ quote-sigma h ‘→'’ ‘X’ ⌝T) toH-helper-helper p x = transport (λ k → □ (k ‘’ quote-sigma h ‘→'’ ‘□’ ‘’ ⌜ k ‘’ quote-sigma h ‘→'’ ‘X’ ⌝T)) p x toH-helper : □ (cast h ‘’ quote-sigma h ‘→'’ ‘H’) toH-helper = toH-helper-helper {k = context-pick-if {P = Typ} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} (W dummy) h2} (sym (context-pick-if-refl {P = Typ} {W dummy} {h2})) (S₀₀W1'→ ((‘‘→'’’→w‘‘→'’’ ‘∘’ ‘‘fcomp-nd’’ ‘'’ₐ (‘s←←’ ‘‘∘’’ ‘cast-refl’ ‘‘∘’’ ⌜→'⌝ ‘'’ₐ ⌜ ‘λ∙’ ‘VAR₀’ ⌝t)) ‘∘’ ⌜←'⌝)) ‘toH’ : □ (‘H'’ ‘→'’ ‘H’) ‘toH’ = ⌜→'⌝ ‘∘’ ‘‘fcomp-nd’’ ‘'’ₐ (⌜→'⌝ ‘'’ₐ ⌜ toH-helper ⌝t) ‘∘’ ⌜←'⌝ toH : H' → H toH h' = toH-helper ‘∘’ h' fromH-helper-helper : ∀ {k} → h2 ≡ k → □ (‘□’ ‘’ ⌜ h2 ‘’ quote-sigma h ‘→'’ ‘X’ ⌝T ‘→'’ h2 ‘’ quote-sigma h) → □ (‘□’ ‘’ ⌜ k ‘’ quote-sigma h ‘→'’ ‘X’ ⌝T ‘→'’ k ‘’ quote-sigma h) fromH-helper-helper p x = transport (λ k → □ (‘□’ ‘’ ⌜ k ‘’ quote-sigma h ‘→'’ ‘X’ ⌝T ‘→'’ k ‘’ quote-sigma h)) p x fromH-helper : □ (‘H’ ‘→'’ cast h ‘’ quote-sigma h) fromH-helper = fromH-helper-helper {k = context-pick-if {P = Typ} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} (W dummy) h2} (sym (context-pick-if-refl {P = Typ} {W dummy} {h2})) (S₀₀W1'← (⌜→'⌝ ‘∘’ ‘‘fcomp-nd’’ ‘'’ₐ (⌜→'⌝ ‘'’ₐ ⌜ ‘λ∙’ ‘VAR₀’ ⌝t ‘‘∘’’ ‘cast-refl'’ ‘‘∘’’ ‘s→→’) ‘∘’ w‘‘→'’’→‘‘→'’’)) {--} ‘fromH’ : □ (‘H’ ‘→'’ ‘H'’) ‘fromH’ = ⌜→'⌝ ‘∘’ ‘‘fcomp-nd’’ ‘'’ₐ (⌜→'⌝ ‘'’ₐ ⌜ fromH-helper ⌝t) ‘∘’ ⌜←'⌝ fromH : H → H' fromH h' = fromH-helper ‘∘’ h' lob : □ ‘X’ lob = fromH h' ‘'’ₐ ⌜ h' ⌝t where f' : Term {ε ▻ ‘□’ ‘’ ‘H0’} (W (‘□’ ‘’ (⌜ ‘□’ ‘’ ‘H0’ ⌝T ‘‘→'’’ ⌜ ‘X’ ⌝T))) f' = Conv0 {‘H0’} {‘X’} (SW1W (w∀ ‘fromH’ ‘’ₐ ‘VAR₀’)) x : Term {ε ▻ ‘□’ ‘’ ‘H0’} (W (‘□’ ‘’ ⌜ ‘H’ ⌝T)) x = w→ ‘quote-term’ ‘'’ₐ ‘VAR₀’ h' : H h' = toH (‘λ∙’ (w→ (‘λ∙’ ‘f’) ‘'’ₐ (w→→ ‘tApp-nd’ ‘'’ₐ f' ‘'’ₐ x))) lob : {‘X’ : Typ ε} → □ ((‘□’ ‘’ ⌜ ‘X’ ⌝T) ‘→'’ ‘X’) → □ ‘X’ lob {‘X’} ‘f’ = inner.lob ‘X’ (un‘λ∙’ ‘f’)
{ "alphanum_fraction": 0.4050429185, "avg_line_length": 31.593220339, "ext": "agda", "hexsha": "552c0ff710f38c2697644474914362a85bf6b912", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_path": "internal/lob.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_path": "internal/lob.agda", "max_line_length": 122, "max_stars_count": 19, "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_path": "internal/lob.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "num_tokens": 2135, "size": 3728 }
{-# OPTIONS --without-K #-} open import Types module J {a c} {A : Set a} (C : (x y : A) → x ≡ y → Set c) where open import GroupoidStructure open import PathOperations open import PathStructure.Sigma open import Transport γ : {x y : A} (p : x ≡ y) → Id (Σ A λ y → x ≡ y) (x , refl) (y , p) γ p = merge-path (p , tr-post _ p refl · id·p _) justification : {x y : A} (p : x ≡ y) → C x x refl → C x y p justification p = tr (λ z → C _ (π₁ z) (π₂ z)) (γ p)
{ "alphanum_fraction": 0.5773420479, "avg_line_length": 27, "ext": "agda", "hexsha": "86b7823b39ee6f56a2bfac587bc8e1594ea3a72d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "vituscze/HoTT-lectures", "max_forks_repo_path": "src/J.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "vituscze/HoTT-lectures", "max_issues_repo_path": "src/J.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "vituscze/HoTT-lectures", "max_stars_repo_path": "src/J.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 178, "size": 459 }
{-# OPTIONS --without-K #-} module Model.RGraph where open import Cats.Category open import Relation.Binary using (IsEquivalence) open import Util.HoTT.Equiv open import Util.HoTT.FunctionalExtensionality open import Util.HoTT.HLevel open import Util.Prelude hiding (id) renaming (_∘_ to _∘F_) open import Util.Relation.Binary.PropositionalEquality infixr 0 _⇒_ infix 4 _≈_ infixr 9 _∘_ record RGraph : Set₁ where no-eta-equality field ObjHSet : HSet 0ℓ open HLevel ObjHSet public using () renaming ( type to Obj ; level to Obj-IsSet ) field eqHProp : Obj → Obj → HProp 0ℓ private module M₀ x y = HLevel (eqHProp x y) module M₁ {x} {y} = HLevel (eqHProp x y) open M₀ public using () renaming ( type to eq ) open M₁ public using () renaming ( level to eq-IsProp ) field eq-refl : ∀ x → eq x x open RGraph public private variable Γ Δ Ψ : RGraph record _⇒_ (Γ Δ : RGraph) : Set where no-eta-equality field fobj : Γ .Obj → Δ .Obj feq : ∀ {x y} → Γ .eq x y → Δ .eq (fobj x) (fobj y) open _⇒_ public private variable f g h i : Γ ⇒ Δ ⇒Canon : (Γ Δ : RGraph) → Set ⇒Canon Γ Δ = Σ[ fobj ∈ (Γ .Obj → Δ .Obj) ] (∀ {x y} → Γ .eq x y → Δ .eq (fobj x) (fobj y)) ⇒≅⇒Canon : (Γ ⇒ Δ) ≅ (⇒Canon Γ Δ) ⇒≅⇒Canon = record { forth = λ f → f .fobj , f .feq ; isIso = record { back = λ f → record { fobj = proj₁ f ; feq = proj₂ f } ; back∘forth = λ where record { fobj = fobj ; feq = feq } → refl ; forth∘back = λ f → refl } } ⇒Canon-IsSet : ∀ Γ Δ → IsSet (⇒Canon Γ Δ) ⇒Canon-IsSet Γ Δ = Σ-IsSet (→-IsSet (Δ .Obj-IsSet)) (λ _ → ∀∙-IsSet (λ _ → ∀∙-IsSet λ _ → →-IsSet (IsProp→IsSet (Δ .eq-IsProp)))) ⇒-IsSet : IsSet (Γ ⇒ Δ) ⇒-IsSet {Γ} {Δ} = ≅-pres-IsOfHLevel 2 (≅-sym ⇒≅⇒Canon) (⇒Canon-IsSet Γ Δ) record _≈_ (f g : Γ ⇒ Δ) : Set where no-eta-equality constructor ≈⁺ field ≈⁻ : ∀ x → f .fobj x ≡ g .fobj x open _≈_ public ≈→≡Canon : ∀ {Γ Δ} {f g : Γ ⇒ Δ} → f ≈ g → ⇒≅⇒Canon .forth f ≡ ⇒≅⇒Canon .forth g ≈→≡Canon {Δ = Δ} {f} {g} (≈⁺ f≈g) = Σ-≡⁺ ( funext f≈g , funext∙ (funext∙ (funext λ x≈y → Δ .eq-IsProp _ _)) ) ≈→≡ : f ≈ g → f ≡ g ≈→≡ f≈g = ≅-Injective ⇒≅⇒Canon (≈→≡Canon f≈g) ≈-isEquivalence : ∀ Γ Δ → IsEquivalence (_≈_ {Γ} {Δ}) ≈-isEquivalence Γ Δ = record { refl = ≈⁺ (λ x → refl) ; sym = λ f≈g → ≈⁺ (λ x → sym (f≈g .≈⁻ x)) ; trans = λ f≈g g≈h → ≈⁺ (λ x → trans (f≈g .≈⁻ x) (g≈h .≈⁻ x)) } private open module M₀ {Γ} {Δ} = IsEquivalence (≈-isEquivalence Γ Δ) public using () renaming ( refl to ≈-refl ; sym to ≈-sym ; trans to ≈-trans ; reflexive to ≈-reflexive ) id : ∀ {Γ} → Γ ⇒ Γ id = record { fobj = λ x → x ; feq = λ x → x } _∘_ : ∀ {Γ Δ Ψ} → Δ ⇒ Ψ → Γ ⇒ Δ → Γ ⇒ Ψ f ∘ g = record { fobj = f .fobj ∘F g .fobj ; feq = f .feq ∘F g .feq } RGraphs : Category (lsuc 0ℓ) 0ℓ 0ℓ RGraphs = record { Obj = RGraph ; _⇒_ = _⇒_ ; _≈_ = _≈_ ; id = id ; _∘_ = _∘_ ; equiv = ≈-isEquivalence _ _ ; ∘-resp = λ {Γ Δ Ψ f g h i} f≈g h≈i → ≈⁺ (λ x → trans (f≈g .≈⁻ _) (cong (g .fobj) (h≈i .≈⁻ x))) ; id-r = ≈⁺ (λ x → refl) ; id-l = ≈⁺ (λ x → refl) ; assoc = ≈⁺ (λ x → refl) } module RGraphs = Category RGraphs
{ "alphanum_fraction": 0.5403225806, "avg_line_length": 20.15, "ext": "agda", "hexsha": "e90ad119bb8a76eb8828806a8708a2536554e8e1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/msc-thesis-code", "max_forks_repo_path": "src/Model/RGraph.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JLimperg/msc-thesis-code", "max_issues_repo_path": "src/Model/RGraph.agda", "max_line_length": 83, "max_stars_count": 5, "max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/msc-thesis-code", "max_stars_repo_path": "src/Model/RGraph.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z", "num_tokens": 1516, "size": 3224 }
------------------------------------------------------------------------ -- The Agda standard library -- -- A data structure which keeps track of an upper bound on the number -- of elements /not/ in a given list ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Level using (0ℓ) open import Relation.Binary module Data.List.Countdown (D : DecSetoid 0ℓ 0ℓ) where open import Data.Empty open import Data.Fin using (Fin; zero; suc; punchOut) open import Data.Fin.Properties using (suc-injective; punchOut-injective) open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Injection using (Injection; module Injection) open import Data.List hiding (lookup) open import Data.List.Relation.Unary.Any as Any using (here; there) open import Data.Nat.Base using (ℕ; zero; suc) open import Data.Product open import Data.Sum open import Data.Sum.Properties open import Relation.Nullary open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; _≢_; refl; cong) open PropEq.≡-Reasoning private open module D = DecSetoid D hiding (refl) renaming (Carrier to Elem) open import Data.List.Membership.Setoid D.setoid ------------------------------------------------------------------------ -- Helper functions private -- The /first/ occurrence of x in xs. first-occurrence : ∀ {xs} x → x ∈ xs → x ∈ xs first-occurrence x (here x≈y) = here x≈y first-occurrence x (there {x = y} x∈xs) with x ≟ y ... | yes x≈y = here x≈y ... | no _ = there $ first-occurrence x x∈xs -- The index of the first occurrence of x in xs. first-index : ∀ {xs} x → x ∈ xs → Fin (length xs) first-index x x∈xs = Any.index $ first-occurrence x x∈xs -- first-index preserves equality of its first argument. first-index-cong : ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) → x₁ ≈ x₂ → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs first-index-cong {x₁} {x₂} x₁∈xs x₂∈xs x₁≈x₂ = helper x₁∈xs x₂∈xs where helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs helper (here x₁≈x) (here x₂≈x) = refl helper (here x₁≈x) (there {x = x} x₂∈xs) with x₂ ≟ x ... | yes x₂≈x = refl ... | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x)) helper (there {x = x} x₁∈xs) (here x₂≈x) with x₁ ≟ x ... | yes x₁≈x = refl ... | no x₁≉x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x)) helper (there {x = x} x₁∈xs) (there x₂∈xs) with x₁ ≟ x | x₂ ≟ x ... | yes x₁≈x | yes x₂≈x = refl ... | yes x₁≈x | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x)) ... | no x₁≉x | yes x₂≈x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x)) ... | no x₁≉x | no x₂≉x = cong suc $ helper x₁∈xs x₂∈xs -- first-index is injective in its first argument. first-index-injective : ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂ first-index-injective {x₁} {x₂} = helper where helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂ helper (here x₁≈x) (here x₂≈x) _ = trans x₁≈x (sym x₂≈x) helper (here x₁≈x) (there {x = x} x₂∈xs) _ with x₂ ≟ x helper (here x₁≈x) (there {x = x} x₂∈xs) _ | yes x₂≈x = trans x₁≈x (sym x₂≈x) helper (here x₁≈x) (there {x = x} x₂∈xs) () | no x₂≉x helper (there {x = x} x₁∈xs) (here x₂≈x) _ with x₁ ≟ x helper (there {x = x} x₁∈xs) (here x₂≈x) _ | yes x₁≈x = trans x₁≈x (sym x₂≈x) helper (there {x = x} x₁∈xs) (here x₂≈x) () | no x₁≉x helper (there {x = x} x₁∈xs) (there x₂∈xs) _ with x₁ ≟ x | x₂ ≟ x helper (there {x = x} x₁∈xs) (there x₂∈xs) _ | yes x₁≈x | yes x₂≈x = trans x₁≈x (sym x₂≈x) helper (there {x = x} x₁∈xs) (there x₂∈xs) () | yes x₁≈x | no x₂≉x helper (there {x = x} x₁∈xs) (there x₂∈xs) () | no x₁≉x | yes x₂≈x helper (there {x = x} x₁∈xs) (there x₂∈xs) eq | no x₁≉x | no x₂≉x = helper x₁∈xs x₂∈xs (suc-injective eq) ------------------------------------------------------------------------ -- The countdown data structure -- If counted ⊕ n is inhabited then there are at most n values of type -- Elem which are not members of counted (up to _≈_). You can read the -- symbol _⊕_ as partitioning Elem into two parts: counted and -- uncounted. infix 4 _⊕_ record _⊕_ (counted : List Elem) (n : ℕ) : Set where field -- An element can be of two kinds: -- ⑴ It is provably in counted. -- ⑵ It is one of at most n elements which may or may not be in -- counted. The "at most n" part is guaranteed by the field -- "injective". kind : ∀ x → x ∈ counted ⊎ Fin n injective : ∀ {x y i} → kind x ≡ inj₂ i → kind y ≡ inj₂ i → x ≈ y -- A countdown can be initialised by proving that Elem is finite. empty : ∀ {n} → Injection D.setoid (PropEq.setoid (Fin n)) → [] ⊕ n empty inj = record { kind = inj₂ ∘ _⟨$⟩_ to ; injective = λ {x} {y} {i} eq₁ eq₂ → injective (begin to ⟨$⟩ x ≡⟨ inj₂-injective eq₁ ⟩ i ≡⟨ PropEq.sym $ inj₂-injective eq₂ ⟩ to ⟨$⟩ y ∎) } where open Injection inj -- A countdown can also be initialised by proving that Elem is finite. emptyFromList : (counted : List Elem) → (∀ x → x ∈ counted) → [] ⊕ length counted emptyFromList counted complete = empty record { to = record { _⟨$⟩_ = λ x → first-index x (complete x) ; cong = first-index-cong (complete _) (complete _) } ; injective = first-index-injective (complete _) (complete _) } -- Finds out if an element has been counted yet. lookup : ∀ {counted n} → counted ⊕ n → ∀ x → Dec (x ∈ counted) lookup {counted} _ x = Any.any (_≟_ x) counted -- When no element remains to be counted all elements have been -- counted. lookup! : ∀ {counted} → counted ⊕ zero → ∀ x → x ∈ counted lookup! counted⊕0 x with _⊕_.kind counted⊕0 x ... | inj₁ x∈counted = x∈counted ... | inj₂ () private -- A variant of lookup!. lookup‼ : ∀ {m counted} → counted ⊕ m → ∀ x → x ∉ counted → ∃ λ n → m ≡ suc n lookup‼ {suc m} counted⊕n x x∉counted = (m , refl) lookup‼ {zero} counted⊕n x x∉counted = ⊥-elim (x∉counted $ lookup! counted⊕n x) -- Counts a previously uncounted element. insert : ∀ {counted n} → counted ⊕ suc n → ∀ x → x ∉ counted → x ∷ counted ⊕ n insert {counted} {n} counted⊕1+n x x∉counted = record { kind = kind′; injective = inj } where open _⊕_ counted⊕1+n helper : ∀ x y i {j} → kind x ≡ inj₂ i → kind y ≡ inj₂ j → i ≡ j → x ≈ y helper _ _ _ eq₁ eq₂ refl = injective eq₁ eq₂ kind′ : ∀ y → y ∈ x ∷ counted ⊎ Fin n kind′ y with y ≟ x | kind x | kind y | helper x y kind′ y | yes y≈x | _ | _ | _ = inj₁ (here y≈x) kind′ y | _ | inj₁ x∈counted | _ | _ = ⊥-elim (x∉counted x∈counted) kind′ y | _ | _ | inj₁ y∈counted | _ = inj₁ (there y∈counted) kind′ y | no y≉x | inj₂ i | inj₂ j | hlp = inj₂ (punchOut (y≉x ∘ sym ∘ hlp _ refl refl)) inj : ∀ {y z i} → kind′ y ≡ inj₂ i → kind′ z ≡ inj₂ i → y ≈ z inj {y} {z} eq₁ eq₂ with y ≟ x | z ≟ x | kind x | kind y | kind z | helper x y | helper x z | helper y z inj () _ | yes _ | _ | _ | _ | _ | _ | _ | _ inj _ () | _ | yes _ | _ | _ | _ | _ | _ | _ inj _ _ | no _ | no _ | inj₁ x∈counted | _ | _ | _ | _ | _ = ⊥-elim (x∉counted x∈counted) inj () _ | no _ | no _ | inj₂ _ | inj₁ _ | _ | _ | _ | _ inj _ () | no _ | no _ | inj₂ _ | _ | inj₁ _ | _ | _ | _ inj eq₁ eq₂ | no _ | no _ | inj₂ i | inj₂ _ | inj₂ _ | _ | _ | hlp = hlp _ refl refl $ punchOut-injective {i = i} _ _ $ (PropEq.trans (inj₂-injective eq₁) (PropEq.sym (inj₂-injective eq₂))) -- Counts an element if it has not already been counted. lookupOrInsert : ∀ {counted m} → counted ⊕ m → ∀ x → x ∈ counted ⊎ ∃ λ n → m ≡ suc n × x ∷ counted ⊕ n lookupOrInsert counted⊕n x with lookup counted⊕n x ... | yes x∈counted = inj₁ x∈counted ... | no x∉counted with lookup‼ counted⊕n x x∉counted ... | (n , refl) = inj₂ (n , refl , insert counted⊕n x x∉counted)
{ "alphanum_fraction": 0.5439924314, "avg_line_length": 39.6995305164, "ext": "agda", "hexsha": "6568df2b8edea62af2b6584a1ce2989c20b5ca29", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Countdown.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Countdown.agda", "max_line_length": 107, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Countdown.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3202, "size": 8456 }
{-# OPTIONS --without-K --safe #-} -- Restriction Functor module Categories.Functor.Restriction where open import Level using (Level; _⊔_) open import Categories.Category using (Category; _[_,_]; _[_≈_]) open import Categories.Category.Restriction using (Restriction) open import Categories.Functor using (Functor; _∘F_) renaming (id to idF) private variable o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ : Level C : Category o ℓ e D : Category o′ ℓ′ e′ E : Category o″ ℓ″ e″ record RestrictionF {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (RC : Restriction C) (RD : Restriction D) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where private module C = Category C using (Obj) module RC = Restriction RC module RD = Restriction RD field Func : Functor C D open Functor Func using (F₁) field F-resp-↓ : {A B : C.Obj} → (f : C [ A , B ]) → D [ F₁ (f RC.↓) ≈ (F₁ f) RD.↓ ] id : {RC : Restriction C} → RestrictionF RC RC id {C = C} = record { Func = idF ; F-resp-↓ = λ f → Category.Equiv.refl C } _∘R_ : {RC : Restriction C} {RD : Restriction D} {RE : Restriction E} → RestrictionF RD RE → RestrictionF RC RD → RestrictionF RC RE _∘R_ {C = C} {E = E} {RC} {RD} {RE} F G = record { Func = Func F ∘F Func G ; F-resp-↓ = resp } where open RestrictionF open Category E using (_≈_; module HomReasoning) open HomReasoning module F = Functor (Func F) module G = Functor (Func G) module RC = Restriction RC module RD = Restriction RD module RE = Restriction RE resp : ∀ {A B : Category.Obj C} → (f : C [ A , B ]) → F.₁ (G.₁ (f RC.↓)) ≈ F.₁ (G.₁ f) RE.↓ resp f = begin F.₁ (G.₁ (f RC.↓)) ≈⟨ F.F-resp-≈ (F-resp-↓ G f) ⟩ F.₁ ((G.₁ f) RD.↓) ≈⟨ F-resp-↓ F _ ⟩ F.₁ (G.₁ f) RE.↓ ∎
{ "alphanum_fraction": 0.5878995434, "avg_line_length": 33.0566037736, "ext": "agda", "hexsha": "e435932ca7ed54f92a99c098e179ea2780b66571", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Functor/Restriction.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Functor/Restriction.agda", "max_line_length": 132, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Functor/Restriction.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 667, "size": 1752 }
{-# OPTIONS -v treeless.opt:20 #-} module _ where open import Common.Prelude open import Common.Equality data Dec {a} (A : Set a) : Set a where yes : A → Dec A no : (A → ⊥) → Dec A decEq₂ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} {f : A → B → C} → (∀ {x y z w} → f x y ≡ f z w → x ≡ z) → (∀ {x y z w} → f x y ≡ f z w → y ≡ w) → ∀ {x y z w} → Dec (x ≡ y) → Dec (z ≡ w) → Dec (f x z ≡ f y w) decEq₂ f-inj₁ f-inj₂ (no neq) _ = no λ eq → neq (f-inj₁ eq) decEq₂ f-inj₁ f-inj₂ _ (no neq) = no λ eq → neq (f-inj₂ eq) decEq₂ f-inj₁ f-inj₂ (yes refl) (yes refl) = yes refl main : IO Unit main = putStrLn ""
{ "alphanum_fraction": 0.485799701, "avg_line_length": 30.4090909091, "ext": "agda", "hexsha": "fe8373f43a7ca069dbb9a8294c24f0113f809983", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Compiler/simple/EraseRefl.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Compiler/simple/EraseRefl.agda", "max_line_length": 72, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Compiler/simple/EraseRefl.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 290, "size": 669 }
-- Andreas, 2020-06-16, issue #4752 -- Disallow @-patterns in pattern synonyms. -- -- Agda 2.5.2 implemented @-patterns and accidentially -- allowed them in pattern synonyms. -- However they just lead to a panic when used. data Nat : Set where suc : Nat → Nat pattern ss x = suc x@(suc _) -- EXPECTED: -- -- @-patterns are not allowed in pattern synonyms -- when scope checking the declaration -- pattern ss x = suc x@(suc _) test : Nat → Set test (ss x) = test x -- WAS (from 2.5.2): -- -- Panic: unbound variable x -- when checking that the expression x has type Nat
{ "alphanum_fraction": 0.678200692, "avg_line_length": 22.2307692308, "ext": "agda", "hexsha": "291eb77f0946ee9c4be4c39257461d1ad09c4b3b", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue4752.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue4752.agda", "max_line_length": 54, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue4752.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 169, "size": 578 }
{-# 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
{ "alphanum_fraction": 0.5794701987, "avg_line_length": 23.2307692308, "ext": "agda", "hexsha": "3d5a868e76ab16a47cea9d9463021c089a04dcfd", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/SizedTypesRigidVarClash.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/SizedTypesRigidVarClash.agda", "max_line_length": 52, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/SizedTypesRigidVarClash.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 100, "size": 302 }
module StateSizedIO.GUI.WxGraphicsLib where open import SizedIO.Base open import StateSizedIO.GUI.BaseStateDependent open import Size renaming (Size to AgdaSize) open import Data.Bool.Base open import Data.List.Base open import Data.Nat open import Function open import Data.Integer open import NativeIO open import StateSizedIO.GUI.WxBindingsFFI open import StateSizedIO.GUI.VariableList data GuiLev1Command : Set where makeFrame : GuiLev1Command setChildredLayout : Frame → ℕ → ℕ → ℕ → ℕ → GuiLev1Command makeButton : Frame → GuiLev1Command setAttribButton : Button → WxColor → GuiLev1Command addButton : Frame → Button → GuiLev1Command deleteButton : Button → GuiLev1Command drawBitmap : DC → Bitmap → Point → Bool → GuiLev1Command repaint : Frame → GuiLev1Command bitmapGetWidth : Bitmap → GuiLev1Command putStrLn : String → GuiLev1Command GuiLev1Response : GuiLev1Command → Set GuiLev1Response makeFrame = Frame GuiLev1Response (makeButton _) = Button GuiLev1Response (bitmapGetWidth _) = ℤ GuiLev1Response _ = Unit GuiLev1Interface : IOInterface Command GuiLev1Interface = GuiLev1Command Response GuiLev1Interface = GuiLev1Response GuiLev2State : Set₁ GuiLev2State = VarList data GuiLev2Command (s : GuiLev2State) : Set₁ where level1C : GuiLev1Command → GuiLev2Command s createVar : {A : Set} → A → GuiLev2Command s setButtonHandler : Button → List (prod s → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s setTimer : Frame → ℤ → List (prod s → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s setKeyHandler : Button → List (prod s → IO GuiLev1Interface ∞ (prod s)) → List (prod s → IO GuiLev1Interface ∞ (prod s)) → List (prod s → IO GuiLev1Interface ∞ (prod s)) → List (prod s → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s setOnPaint : Frame → List (prod s → DC → Rect → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s GuiLev2Response : (s : GuiLev2State) → GuiLev2Command s → Set GuiLev2Response _ (level1C c) = GuiLev1Response c GuiLev2Response _ (createVar {A} a) = Var A GuiLev2Response _ (setTimer fra x p) = Timer GuiLev2Response _ _ = Unit GuiLev2Next : (s : GuiLev2State) → (c : GuiLev2Command s) → GuiLev2Response s c → GuiLev2State GuiLev2Next s (createVar {A} a) var = addVar A var s GuiLev2Next s _ _ = s GuiLev2Interface : IOInterfaceˢ Stateˢ GuiLev2Interface = GuiLev2State Commandˢ GuiLev2Interface = GuiLev2Command Responseˢ GuiLev2Interface = GuiLev2Response nextˢ GuiLev2Interface = GuiLev2Next translateLev1Local : (c : GuiLev1Command) → NativeIO (GuiLev1Response c) translateLev1Local makeFrame = nativeNewFrame "dummy title" translateLev1Local (setChildredLayout win a b c d) = nativeSetChildredLayout win a b c d translateLev1Local (makeButton fra) = nativeMakeButton fra "dummy button label" translateLev1Local (deleteButton bt) = nativeDeleteButton bt translateLev1Local (addButton fra bt) = nativeAddButton fra bt translateLev1Local (setAttribButton bt col) = nativeSetColorButton bt col translateLev1Local (drawBitmap dc bm p b) = nativeDrawBitmap dc bm p b translateLev1Local (repaint fra) = nativeRepaint fra translateLev1Local (bitmapGetWidth b) = nativeBitmapGetWidth b translateLev1Local (putStrLn s) = nativePutStrLn s translateLev1 : {A : Set} → IO GuiLev1Interface ∞ A → NativeIO A translateLev1 = translateIO translateLev1Local translateLev1List : {A : Set} → List (IO GuiLev1Interface ∞ A) → List (NativeIO A) translateLev1List l = map translateLev1 l translateLev2Local : (s : GuiLev2State) → (c : GuiLev2Command s) → NativeIO (GuiLev2Response s c) translateLev2Local s (level1C c) = translateLev1Local c translateLev2Local s (createVar {A} a) = nativeNewVar {A} a translateLev2Local s (setButtonHandler bt proglist) = nativeSetButtonHandler bt (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglist)) translateLev2Local s (setTimer fra interv proglist) = nativeSetTimer fra interv (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglist)) translateLev2Local s (setKeyHandler bt proglistRight proglistLeft proglistUp proglistDown) = nativeSetKeyHandler bt (λ key -> case (showKey key) of λ { "Right" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistRight)) ; "Left" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistLeft)) ; "Up" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistUp)) ; "Down" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistDown)) ; _ → nativeReturn unit } ) translateLev2Local s (setOnPaint fra proglist) = nativeSetOnPaint fra (λ dc rect → (dispatchList s (map (λ prog aa → translateLev1 (prog aa dc rect)) proglist))) translateLev2 : {s : GuiLev2State} → {A : Set} → IOˢ GuiLev2Interface ∞ (λ _ → A) s → NativeIO A translateLev2 = translateIOˢ {I = GuiLev2Interface} translateLev2Local
{ "alphanum_fraction": 0.6640766173, "avg_line_length": 38.9718309859, "ext": "agda", "hexsha": "e48677e9610303121a8adfa5fb121b5d0ef4b833", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "src/StateSizedIO/GUI/WxGraphicsLib.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "src/StateSizedIO/GUI/WxGraphicsLib.agda", "max_line_length": 98, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "src/StateSizedIO/GUI/WxGraphicsLib.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 1660, "size": 5534 }
{-# OPTIONS --cubical --no-import-sorts #-} module Number.Instances.Int where open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero) open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ) open import Cubical.Relation.Nullary.Base renaming (¬_ to ¬ᵗ_) open import Cubical.Relation.Binary.Base open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_) open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_) open import Cubical.Data.Sigma open import Cubical.Data.Bool as Bool using (Bool; not; true; false) open import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥) -- `⊥` and `elim` open import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_; inl to inlᵖ; inr to inrᵖ) open import Function.Base using (it; _∋_; _$_) open import Cubical.Foundations.Isomorphism open import Cubical.HITs.PropositionalTruncation --.Properties open import Utils using (!_; !!_) open import MoreLogic.Reasoning open import MoreLogic.Definitions open import MoreLogic.Properties open import MorePropAlgebra.Definitions hiding (_≤''_) open import MorePropAlgebra.Structures open import MorePropAlgebra.Bundles open import MorePropAlgebra.Consequences open import Number.Structures2 open import Number.Bundles2 open import Number.Instances.Nat using (lemma10''; lemma12'') open import Number.Prelude.Nat import Agda.Builtin.Int as Builtin import Data.Integer.Base as BuiltinBase import Data.Integer.Properties as BuiltinProps open import Cubical.Data.Int renaming ( Int to ℤ ; isSetInt to isSetℤ ; _-_ to infix 7 _-_ ; _+_ to infix 5 _+_ ) import Cubical.HITs.Ints.QuoInt as QuoInt -- Cubical.Data.Int is isomorphic to Agda.Builtin.Int Int≅Builtin : Iso ℤ Builtin.Int Int≅Builtin .Iso.fun ( pos n) = Builtin.pos n Int≅Builtin .Iso.fun ( negsuc n) = Builtin.negsuc n Int≅Builtin .Iso.inv (Builtin.pos n) = pos n Int≅Builtin .Iso.inv (Builtin.negsuc n) = negsuc n Int≅Builtin .Iso.rightInv (Builtin.pos n) = refl Int≅Builtin .Iso.rightInv (Builtin.negsuc n) = refl Int≅Builtin .Iso.leftInv ( pos n) = refl Int≅Builtin .Iso.leftInv ( negsuc n) = refl Int≡Builtin : ℤ ≡ Builtin.Int Int≡Builtin = isoToPath Int≅Builtin Sign : Type₀ Sign = Bool pattern spos = Bool.false pattern sneg = Bool.true _·ˢ_ : Sign → Sign → Sign _·ˢ_ = Bool._⊕_ sign : ℤ → Sign sign (pos n) = spos sign (negsuc n) = sneg signed : Sign → ℕ → ℤ signed spos x = pos x signed sneg zero = 0 signed sneg (suc x) = neg (suc x) -_ : ℤ → ℤ - pos zero = pos zero - pos (suc n) = negsuc n - negsuc n = pos (suc n) -involutive : ∀ a → - - a ≡ a -involutive (pos zero) = refl -involutive (pos (suc n)) = refl -involutive (negsuc n) = refl infix 8 -_ infix 7 _·_ infix 7 _·'_ infix 7 _·''_ infixl 4 _<_ -- multiplication on integers -- NOTE: this definition leads to a lot cases and a lot of calculations -- the general advice would be to have as few cases as possible -- because then at a call site we also need not many cases -- NOTE: the way that QuoInt._+_ is defined works that it reduces the first argument, e.g. it reduces `a` in `a + b` -- therefore we also need to split (only) on the first argument `a` -- _+_ : ℤ → ℤ → ℤ -- (signed _ zero) + n = n -- (posneg _) + n = n -- (pos (suc m)) + n = sucℤ (pos m + n) -- (neg (suc m)) + n = predℤ (neg m + n) -- we might apply something similar for _·_ -- although that is not done for QuoInt._*_ -- _*_ : ℤ → ℤ → ℤ -- m * n = signed (sign m *S sign n) (abs m ℕ.* abs n) -- but it is done for ℕ._*_ -- _*_ : Nat → Nat → Nat -- zero * m = zero -- suc n * m = m + n * m _·_ : ℤ → ℤ → ℤ pos a · pos b = pos (a ·ⁿ b) pos zero · negsuc b = pos 0 pos (suc a) · negsuc b = negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) -- maybe `(a +ⁿ b) +ⁿ a ·ⁿ b` would be a better choice ? negsuc a · pos zero = pos 0 negsuc a · pos (suc b) = negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) negsuc a · negsuc b = pos (suc a ·ⁿ suc b) -- an equivalent multiplication on integers -- NOTE: this is the way it's defined in the noncubical standard library -- I used it to proof associativity, which seemed incredibly hard for the previous definition _·'_ : ℤ → ℤ → ℤ x ·' y = signed (sign x ·ˢ sign y) (abs x ·ⁿ abs y) mksigned : Sign → ℕ → ℤ mksigned s zero = pos 0 mksigned s (suc n) = signed s (suc n) -- a third multiplication on the integers -- NOTE: with the use of `mksigned` we need not case-split on the sign, if the absolute value is zero _·''_ : ℤ → ℤ → ℤ x ·'' y = mksigned (sign x ·ˢ sign y) (abs x ·ⁿ abs y) abstract ·''-nullifiesʳ : ∀ x → x ·'' 0 ≡ 0 ·''-nullifiesʳ (pos n) i = mksigned spos (·ⁿ-nullifiesʳ n i) ·''-nullifiesʳ (negsuc n) i = mksigned sneg (·ⁿ-nullifiesʳ n i) -- hProp-valued _<_ _<_ : ∀(x y : ℤ) → hProp ℓ-zero pos x < pos y = x <ⁿ y pos x < negsuc y = ⊥ negsuc x < pos y = ⊤ negsuc x < negsuc y = y <ⁿ x min : ℤ → ℤ → ℤ min (pos x) (pos y) = pos (minⁿ x y) min (pos x) (negsuc y) = negsuc y min (negsuc x) (pos y) = negsuc x min (negsuc x) (negsuc y) = negsuc (maxⁿ x y) max : ℤ → ℤ → ℤ max (pos x) (pos y) = pos (maxⁿ x y) max (pos x) (negsuc y) = pos x max (negsuc x) (pos y) = pos y max (negsuc x) (negsuc y) = negsuc (minⁿ x y) -- some calculations that arose in the proofs private abstract lemma1 : ∀ a b → a ·ⁿ b +ⁿ (a +ⁿ b) ≡ b +ⁿ a ·ⁿ suc b lemma1 a b = a ·ⁿ b +ⁿ (a +ⁿ b) ≡⟨ (λ i → +ⁿ-assoc (a ·ⁿ b) a b i) ⟩ (a ·ⁿ b +ⁿ a) +ⁿ b ≡⟨ (λ i → +ⁿ-comm (a ·ⁿ b) a i +ⁿ b) ⟩ (a +ⁿ a ·ⁿ b) +ⁿ b ≡⟨ (λ i → +ⁿ-comm (a +ⁿ a ·ⁿ b) b i) ⟩ b +ⁿ (a +ⁿ a ·ⁿ b) ≡⟨ (λ i → b +ⁿ ·ⁿ-suc a b (~ i)) ⟩ b +ⁿ a ·ⁿ suc b ∎ lemma2 : ∀ a b c → c +ⁿ (b +ⁿ a ·ⁿ suc b) ·ⁿ suc c ≡ (c +ⁿ b ·ⁿ suc c) +ⁿ a ·ⁿ suc (c +ⁿ b ·ⁿ suc c) lemma2 a b c = c +ⁿ (b +ⁿ a ·ⁿ suc b) ·ⁿ suc c ≡⟨ (λ i → c +ⁿ ·ⁿ-distribʳ b (a ·ⁿ suc b) (suc c) (~ i)) ⟩ c +ⁿ (b ·ⁿ suc c +ⁿ (a ·ⁿ suc b) ·ⁿ suc c) ≡⟨ +ⁿ-assoc c _ _ ⟩ (c +ⁿ b ·ⁿ suc c) +ⁿ (a ·ⁿ suc b) ·ⁿ suc c ≡⟨ (λ i → (c +ⁿ b ·ⁿ suc c) +ⁿ ·ⁿ-assoc a (suc b) (suc c) (~ i)) ⟩ (c +ⁿ b ·ⁿ suc c) +ⁿ a ·ⁿ (suc b ·ⁿ suc c) ≡⟨ refl ⟩ (c +ⁿ b ·ⁿ suc c) +ⁿ a ·ⁿ suc (c +ⁿ b ·ⁿ suc c) ∎ lemma3 : ∀ y z → y ·ⁿ z +ⁿ (y +ⁿ z) ≡ y ·ⁿ suc z +ⁿ z lemma3 y z = y ·ⁿ z +ⁿ (y +ⁿ z) ≡⟨ +ⁿ-assoc (y ·ⁿ z) y z ⟩ (y ·ⁿ z +ⁿ y) +ⁿ z ≡⟨ (λ i → +ⁿ-comm (y ·ⁿ z) y i +ⁿ z) ⟩ (y +ⁿ y ·ⁿ z) +ⁿ z ≡⟨ (λ i → ·ⁿ-suc y z (~ i) +ⁿ z) ⟩ y ·ⁿ suc z +ⁿ z ∎ lemma4 = λ(a b : ℕ) → a ·ⁿ suc b +ⁿ (a +ⁿ suc b) ≡⟨ (λ i → ·ⁿ-suc a b i +ⁿ (a +ⁿ suc b)) ⟩ (a +ⁿ a ·ⁿ b) +ⁿ (a +ⁿ suc b) ≡⟨ sym $ +ⁿ-assoc a (a ·ⁿ b) (a +ⁿ suc b) ⟩ a +ⁿ (a ·ⁿ b +ⁿ (a +ⁿ suc b)) ≡⟨ (λ i → a +ⁿ +ⁿ-assoc (a ·ⁿ b) a (suc b) i) ⟩ a +ⁿ ((a ·ⁿ b +ⁿ a) +ⁿ suc b) ≡⟨ (λ i → a +ⁿ +ⁿ-suc (a ·ⁿ b +ⁿ a) b i) ⟩ a +ⁿ suc ((a ·ⁿ b +ⁿ a) +ⁿ b) ≡⟨ (λ i → a +ⁿ suc (+ⁿ-assoc (a ·ⁿ b) a b (~ i))) ⟩ a +ⁿ suc (a ·ⁿ b +ⁿ (a +ⁿ b)) ∎ lemma5 = λ(a b : ℕ) → a +ⁿ (b +ⁿ a ·ⁿ suc b) ≡⟨ +ⁿ-assoc a b (a ·ⁿ suc b) ⟩ (a +ⁿ b) +ⁿ a ·ⁿ suc b ≡⟨ (λ i → +ⁿ-comm a b i +ⁿ a ·ⁿ suc b) ⟩ (b +ⁿ a) +ⁿ a ·ⁿ suc b ≡⟨ sym $ +ⁿ-assoc b a (a ·ⁿ suc b) ⟩ b +ⁿ (a +ⁿ a ·ⁿ suc b) ≡⟨ (λ i → b +ⁿ ·ⁿ-suc a (suc b) (~ i)) ⟩ b +ⁿ a ·ⁿ suc (suc b) ∎ lemma6 : ∀ m n → suc (m +ⁿ n ·ⁿ suc (suc (suc m))) ≡ suc n +ⁿ (m +ⁿ n ·ⁿ suc (suc m)) lemma6 m n = suc (m +ⁿ n ·ⁿ suc (suc (suc m))) ≡⟨ (λ i → suc $ m +ⁿ ·ⁿ-suc n (suc (suc m)) i) ⟩ suc (m +ⁿ (n +ⁿ n ·ⁿ suc (suc m))) ≡⟨ (λ i → suc $ +ⁿ-assoc m n (n ·ⁿ (suc (suc m))) i) ⟩ suc ((m +ⁿ n) +ⁿ n ·ⁿ suc (suc m)) ≡⟨ (λ i → suc $ +ⁿ-comm m n i +ⁿ n ·ⁿ suc (suc m)) ⟩ suc ((n +ⁿ m) +ⁿ n ·ⁿ suc (suc m)) ≡⟨ (λ i → suc $ +ⁿ-assoc n m (n ·ⁿ (suc (suc m))) (~ i)) ⟩ suc (n +ⁿ (m +ⁿ n ·ⁿ suc (suc m))) ≡⟨ refl ⟩ suc n +ⁿ (m +ⁿ n ·ⁿ suc (suc m)) ∎ lemma7 : ∀ a b → b +ⁿ a ·ⁿ suc b ≡ a +ⁿ b ·ⁿ suc a lemma7 a b = b +ⁿ a ·ⁿ suc b ≡⟨ (λ i → b +ⁿ ·ⁿ-suc a b i) ⟩ b +ⁿ (a +ⁿ a ·ⁿ b) ≡⟨ (λ i → +ⁿ-assoc b a (a ·ⁿ b) i) ⟩ (b +ⁿ a) +ⁿ a ·ⁿ b ≡⟨ (λ i → +ⁿ-comm b a i +ⁿ a ·ⁿ b) ⟩ (a +ⁿ b) +ⁿ a ·ⁿ b ≡⟨ (λ i → +ⁿ-assoc a b (a ·ⁿ b) (~ i)) ⟩ a +ⁿ (b +ⁿ a ·ⁿ b) ≡⟨ (λ i → a +ⁿ (b +ⁿ ·ⁿ-comm a b i)) ⟩ a +ⁿ (b +ⁿ b ·ⁿ a) ≡⟨ (λ i → a +ⁿ ·ⁿ-suc b a (~ i)) ⟩ a +ⁿ b ·ⁿ suc a ∎ abstract <-irrefl : (a : ℤ) → [ ¬ (a < a) ] <-irrefl (pos zero ) = <ⁿ-irrefl 0 <-irrefl (pos (suc n)) = <ⁿ-irrefl (suc n) <-irrefl (negsuc n ) = <ⁿ-irrefl n <-trans : (a b c : ℤ) → [ a < b ] → [ b < c ] → [ a < c ] <-trans (pos a) (pos b) (pos c) a<b b<c = <ⁿ-trans a<b b<c <-trans (negsuc a) (pos b) (pos c) a<b b<c = tt <-trans (negsuc a) (negsuc b) (pos c) a<b b<c = tt <-trans (negsuc a) (negsuc b) (negsuc c) a<b b<c = <ⁿ-trans b<c a<b <-asym : (a b : ℤ) → [ a < b ] → [ ¬(b < a) ] <-asym = irrefl+trans⇒asym _<_ <-irrefl <-trans <-cotrans : (a b : ℤ) → [ a < b ] → (x : ℤ) → [ (a < x) ⊔ (x < b) ] <-cotrans (pos a) (pos b) a<b (pos x) = <ⁿ-cotrans _ _ a<b x <-cotrans (pos a) (pos b) a<b (negsuc x) = inrᵖ tt <-cotrans (negsuc a) (pos b) a<b (pos x) = inlᵖ tt <-cotrans (negsuc a) (pos b) a<b (negsuc x) = inrᵖ tt <-cotrans (negsuc a) (negsuc b) a<b (pos x) = inlᵖ tt <-cotrans (negsuc a) (negsuc b) a<b (negsuc x) = pathTo⇒ (⊔-comm (b <ⁿ x) (x <ⁿ a)) (<ⁿ-cotrans _ _ a<b x) -- some properties about `pos`, `negsuc`, `+pos` and `+negsuc` abstract +-identityʳ : ∀ x → x + 0 ≡ x +-identityʳ x = refl +-identityˡ : ∀ x → 0 + x ≡ x +-identityˡ x = +-comm 0 x ∙ +-identityʳ x -- usage count: 3 -1·≡- : ∀ a → negsuc 0 · a ≡ - a -1·≡- (pos zero) = refl -1·≡- (pos (suc n)) = refl -1·≡- (negsuc n) = λ i → pos $ suc $ +ⁿ-comm n 0 i -- usage count: 0 negsuc≡-pos : ∀ a → negsuc a ≡ - pos (suc a) negsuc≡-pos a = refl -- usage count: 2 negsuc-reflects-≡ : ∀ x y → negsuc x ≡ negsuc y → x ≡ y negsuc-reflects-≡ x y p i = predⁿ (abs (p i)) -- usage count: 2 pos-reflects-≡ : ∀ x y → pos x ≡ pos y → x ≡ y pos-reflects-≡ x y p i = abs (p i) -- usage count: 1 - 2 possuc+negsuc≡0 : ∀ n → (pos (suc n) +negsuc n) ≡ pos 0 possuc+negsuc≡0 zero = refl possuc+negsuc≡0 (suc n) = let r = possuc+negsuc≡0 n in sym ind ∙ r where ind = pos (suc n) +negsuc n ≡⟨ refl ⟩ predInt (pos (suc (suc n))) +negsuc n ≡⟨ sym $ predInt+negsuc n (pos (suc (suc n))) ⟩ predInt (pos (suc (suc n)) +negsuc n) ∎ -- usage count: 0 - 1 sucInt[negsuc+pos]≡0 : ∀ n → sucInt (negsuc n +pos n) ≡ pos 0 sucInt[negsuc+pos]≡0 zero = refl sucInt[negsuc+pos]≡0 (suc n) = let r = sucInt[negsuc+pos]≡0 n in sym ind ∙ r where ind = sucInt ( negsuc n +pos n ) ≡⟨ refl ⟩ sucInt (sucInt (negsuc (suc n)) +pos n ) ≡⟨ (λ i → sucInt $ sucInt+pos n (negsuc (suc n)) (~ i)) ⟩ sucInt (sucInt (negsuc (suc n) +pos n)) ∎ +-inverseʳ : ∀ a → a + (- a) ≡ 0 +-inverseʳ (pos zero ) = refl +-inverseʳ (pos (suc n)) = possuc+negsuc≡0 n +-inverseʳ (negsuc n ) = sucInt[negsuc+pos]≡0 n +-inverseˡ : ∀ a → (- a) + a ≡ 0 +-inverseˡ a = +-comm (- a) a ∙ +-inverseʳ a +-inverse : (x : ℤ) → (x + (- x) ≡ pos 0) × ((- x) + x ≡ pos 0) +-inverse x .fst = +-inverseʳ x +-inverse x .snd = +-inverseˡ x -- usage count: 11 - 14 pos+pos≡+ⁿ : ∀ a x → (pos a +pos x) ≡ pos (a +ⁿ x) pos+pos≡+ⁿ a zero = λ i → pos $ +ⁿ-comm 0 a i pos+pos≡+ⁿ a (suc x) = let r = pos+pos≡+ⁿ a x in sucInt (pos a +pos x) ≡⟨ (λ i → sucInt $ r i) ⟩ sucInt (pos (a +ⁿ x)) ≡⟨ refl ⟩ pos (suc (a +ⁿ x)) ≡⟨ (λ i → pos $ +ⁿ-suc a x (~ i)) ⟩ pos (a +ⁿ suc x) ∎ -- usage count: 7 - 8 negsuc+negsuc≡+ⁿ : ∀ a x → (negsuc a +negsuc x) ≡ negsuc (suc (a +ⁿ x)) negsuc+negsuc≡+ⁿ a zero = λ i → negsuc $ suc $ +ⁿ-comm 0 a i negsuc+negsuc≡+ⁿ a (suc x) = let r = negsuc+negsuc≡+ⁿ a x in predInt (negsuc a +negsuc x) ≡⟨ (λ i → predInt (r i)) ⟩ predInt (negsuc (suc (a +ⁿ x))) ≡⟨ refl ⟩ negsuc (suc (suc (a +ⁿ x))) ≡⟨ (λ i → negsuc $ suc $ +ⁿ-suc a x (~ i)) ⟩ negsuc (suc (a +ⁿ suc x)) ∎ -- usage count: 6 - 7 +negsuc-identityˡ : ∀ x → 0 +negsuc x ≡ negsuc x +negsuc-identityˡ zero = refl +negsuc-identityˡ (suc x) = λ i → predInt $ +negsuc-identityˡ x i -- usage count: 0 pos+negsuc≡⊎ : ∀ a b → (Σ[ y ∈ ℕ ] pos a +negsuc b ≡ pos y) ⊎ (Σ[ y ∈ ℕ ] pos a +negsuc b ≡ negsuc y) pos+negsuc≡⊎ zero zero = inr (0 , refl) pos+negsuc≡⊎ (suc a) zero = inl (a , refl) pos+negsuc≡⊎ zero (suc b) = inr (suc b , λ i → predInt $ +negsuc-identityˡ b i) pos+negsuc≡⊎ (suc a) (suc b) with pos+negsuc≡⊎ a b ... | inl (y , p) = inl (y , predInt+negsuc b (pos (suc a)) ∙ p) ... | inr (y , p) = inr (y , predInt+negsuc b (pos (suc a)) ∙ p) -- usage count: 0 negsuc+pos≡⊎ : ∀ a b → (Σ[ y ∈ ℕ ] negsuc a +pos b ≡ pos y) ⊎ (Σ[ y ∈ ℕ ] negsuc a +pos b ≡ negsuc y) negsuc+pos≡⊎ zero zero = inr (0 , refl) negsuc+pos≡⊎ (suc a) zero = inr (suc a , refl) negsuc+pos≡⊎ zero (suc b) = inl (b , sucInt+pos b (negsuc 0) ∙ +-identityˡ (pos b)) negsuc+pos≡⊎ (suc a) (suc b) with negsuc+pos≡⊎ a b ... | inl (y , p) = inl (y , sucInt+pos b (negsuc (suc a)) ∙ p) ... | inr (y , p) = inr (y , sucInt+pos b (negsuc (suc a)) ∙ p) -- usage count: 4 - 6 pos+negsuc≡negsuc+pos : ∀ a b → pos a +negsuc b ≡ negsuc b +pos a pos+negsuc≡negsuc+pos a zero = (λ i → predInt $ pos+pos≡+ⁿ 0 a (~ i)) ∙ predInt+pos a 0 pos+negsuc≡negsuc+pos a (suc b) = (λ i → predInt $ pos+negsuc≡negsuc+pos a b i) ∙ predInt+ (negsuc b) (pos a) -- usage count: 0 - 1 predInt- : ∀ a → predInt (- a) ≡ - (sucInt a) predInt- (pos zero) = refl predInt- (pos (suc n)) = refl predInt- (negsuc zero) = refl predInt- (negsuc (suc n)) = refl -- usage count: 2 - 3 pos+negsuc-swap : ∀ a b → pos (suc a) +negsuc b ≡ -(pos (suc b) + negsuc a) pos+negsuc-swap zero zero = refl pos+negsuc-swap (suc a) zero = λ i → - (predInt+negsuc a 1 ∙ +negsuc-identityˡ a) (~ i) pos+negsuc-swap a (suc b) = predInt (pos (suc a) +negsuc b) ≡⟨ (λ i → predInt $ pos+negsuc-swap a b i) ⟩ predInt (- (pos (suc b) +negsuc a)) ≡⟨ predInt- (pos (suc b) +negsuc a) ⟩ - sucInt (pos (suc b) +negsuc a) ≡⟨ (λ i → - sucInt+negsuc a (pos (suc b)) i) ⟩ - (pos (suc (suc b)) +negsuc a) ∎ -- usage count: 2 negsuc+pos-swap : ∀ a b → negsuc a +pos (suc b) ≡ -(negsuc b + pos (suc a)) negsuc+pos-swap a b = sym (pos+negsuc≡negsuc+pos (suc b) a) ∙ pos+negsuc-swap b a ∙ (λ i → - pos+negsuc≡negsuc+pos (suc a) b i) -- usage count: 1 +negsuc-assoc : ∀ a b c → a +negsuc (b +ⁿ suc c) ≡ (a +negsuc b) +negsuc c +negsuc-assoc a b c = (λ i → a + (negsuc+negsuc≡+ⁿ b c ∙ (λ j → negsuc (+ⁿ-suc b c (~ j)))) (~ i)) ∙ +-assoc a (negsuc b) (negsuc c) -- usage count: 1 sucInt[negsuc+pos]≡pos : ∀ a → sucInt (negsuc 0 +pos a) ≡ pos a sucInt[negsuc+pos]≡pos a = sucInt+pos a (negsuc 0) ∙ pos+pos≡+ⁿ 0 a -- usage count: 1 +pos-inverse : ∀ a → negsuc a +pos a ≡ negsuc 0 +pos-inverse zero = refl +pos-inverse (suc a) = sucInt+pos a (negsuc (suc a)) ∙ +pos-inverse a -- usage count: 1 +pos-assoc : ∀ a b c → (a +pos b) +pos c ≡ a +pos (b +ⁿ c) +pos-assoc a b c = sym (+-assoc a (pos b) (pos c)) ∙ (λ i → a + pos+pos≡+ⁿ b c i) data Trichotomy (m n : ℤ) : Type₀ where lt : [ m < n ] → Trichotomy m n eq : m ≡ n → Trichotomy m n gt : [ n < m ] → Trichotomy m n _≟_ : ∀ m n → Trichotomy m n pos a ≟ pos b with a ≟ⁿ b ... | ltⁿ p = lt p ... | eqⁿ p = eq λ i → pos (p i) ... | gtⁿ p = gt p pos a ≟ negsuc b = gt tt negsuc a ≟ pos b = lt tt negsuc a ≟ negsuc b with a ≟ⁿ b ... | ltⁿ p = gt p ... | eqⁿ p = eq λ i → negsuc (p i) ... | gtⁿ p = lt p data MinTrichtotomy (x y : ℤ) : Type where min-lt : min x y ≡ x → [ x < y ] → MinTrichtotomy x y min-gt : min x y ≡ y → [ y < x ] → MinTrichtotomy x y min-eq : min x y ≡ x → min x y ≡ y → MinTrichtotomy x y data MaxTrichtotomy (x y : ℤ) : Type where max-lt : max x y ≡ y → [ x < y ] → MaxTrichtotomy x y max-gt : max x y ≡ x → [ y < x ] → MaxTrichtotomy x y max-eq : max x y ≡ x → max x y ≡ y → MaxTrichtotomy x y min-trichotomy : ∀ x y → MinTrichtotomy x y min-trichotomy (pos x) (pos y) with (pos x) ≟ (pos y) ... | lt p = min-lt (λ i → pos $ minⁿ-tightˡ x y p i) p ... | eq p = let minxy≡x = (λ i → minⁿ x (pos-reflects-≡ x y p (~ i))) ∙ minⁿ-identity x in min-eq (λ j → pos $ minxy≡x j) ((λ i → pos $ minxy≡x i) ∙ p) ... | gt p = min-gt (λ i → pos $ minⁿ-tightʳ x y p i) p min-trichotomy (pos x) (negsuc y) = min-gt refl tt min-trichotomy (negsuc x) (pos y) = min-lt refl tt min-trichotomy (negsuc x) (negsuc y) with (negsuc x) ≟ (negsuc y) ... | lt p = min-lt (λ i → negsuc $ maxⁿ-tightˡ x y p i) p ... | eq p = let maxxy≡x = (λ i → maxⁿ x (negsuc-reflects-≡ x y p (~ i))) ∙ maxⁿ-identity x in min-eq (λ j → negsuc $ maxxy≡x j) ((λ i → negsuc $ maxxy≡x i) ∙ p) ... | gt p = min-gt (λ i → negsuc $ maxⁿ-tightʳ x y p i) p max-trichotomy : ∀ x y → MaxTrichtotomy x y max-trichotomy (pos x) (pos y) with (pos x) ≟ (pos y) ... | lt p = max-lt ((λ i → pos $ maxⁿ-tightʳ x y p i)) p ... | eq p = let maxxy≡x = (λ i → maxⁿ x (pos-reflects-≡ x y p (~ i))) ∙ maxⁿ-identity x in max-eq (λ j → pos $ maxxy≡x j) ((λ i → pos $ maxxy≡x i) ∙ p) ... | gt p = max-gt (λ i → pos $ maxⁿ-tightˡ x y p i) p max-trichotomy (pos x) (negsuc y) = max-gt refl tt max-trichotomy (negsuc x) (pos y) = max-lt refl tt max-trichotomy (negsuc x) (negsuc y) with (negsuc x) ≟ (negsuc y) ... | lt p = max-lt (λ i → negsuc $ minⁿ-tightʳ x y p i) p ... | eq p = let minxy≡x = (λ i → minⁿ x (negsuc-reflects-≡ x y p (~ i))) ∙ minⁿ-identity x in max-eq (λ j → negsuc $ minxy≡x j) ((λ i → negsuc $ minxy≡x i) ∙ p) ... | gt p = max-gt (λ i → negsuc $ minⁿ-tightˡ x y p i) p abstract -- NOTE: same proof as in `Number.Instances.Nat` is-min : (x y z : ℤ) → [ ¬ᵖ (min x y < z) ⇔ ¬ᵖ (x < z) ⊓ ¬ᵖ (y < z) ] is-min x y z .fst z≤minxy with min-trichotomy x y ... | min-lt p x<y = (λ x<z → z≤minxy $ pathTo⇐ (λ i → p i < z) x<z) , (λ y<z → z≤minxy $ pathTo⇐ (λ i → p i < z) $ <-trans x y z x<y y<z) ... | min-gt p y<x = (λ x<z → z≤minxy $ pathTo⇐ (λ i → p i < z) $ <-trans y x z y<x x<z) , (λ y<z → z≤minxy $ pathTo⇐ (λ i → p i < z) y<z) ... | min-eq p q = (λ x<z → z≤minxy $ pathTo⇐ (λ i → p i < z) x<z) , (λ y<z → z≤minxy $ pathTo⇐ (λ i → q i < z) y<z) is-min x y z .snd (z≤x , z≤y) minxy<z with min-trichotomy x y ... | min-lt p _ = z≤x $ pathTo⇒ (λ i → p i < z) minxy<z ... | min-gt p _ = z≤y $ pathTo⇒ (λ i → p i < z) minxy<z ... | min-eq p q = z≤x $ pathTo⇒ (λ i → p i < z) minxy<z -- NOTE: same proof as in `Number.Instances.Nat` is-max : (x y z : ℤ) → [ ¬ᵖ (z < max x y) ⇔ ¬ᵖ (z < x) ⊓ ¬ᵖ (z < y) ] is-max x y z .fst maxxy≤z with max-trichotomy x y ... | max-gt p y<x = (λ z<x → maxxy≤z $ pathTo⇐ (λ i → z < p i) z<x ) , (λ z<y → maxxy≤z $ pathTo⇐ (λ i → z < p i) $ <-trans z y x z<y y<x ) ... | max-lt p x<y = (λ z<x → maxxy≤z $ pathTo⇐ (λ i → z < p i) $ <-trans z x y z<x x<y ) , (λ z<y → maxxy≤z $ pathTo⇐ (λ i → z < p i) z<y ) ... | max-eq p q = (λ z<x → maxxy≤z $ pathTo⇐ (λ i → z < p i) z<x ) , (λ z<y → maxxy≤z $ pathTo⇐ (λ i → z < q i) z<y ) is-max x y z .snd (z≤x , z≤y) maxxy<z with max-trichotomy x y ... | max-gt p _ = z≤x $ pathTo⇒ (λ i → z < p i) maxxy<z ... | max-lt p _ = z≤y $ pathTo⇒ (λ i → z < p i) maxxy<z ... | max-eq p q = z≤x $ pathTo⇒ (λ i → z < p i) maxxy<z abstract sucInt-reflects-< : ∀ x y → [ sucInt x < sucInt y ] → [ x < y ] sucInt-reflects-< (pos x ) (pos y ) p = sucⁿ-creates-<ⁿ x y .snd p sucInt-reflects-< (pos x ) (negsuc zero ) p = ¬-<ⁿ-zero p sucInt-reflects-< (negsuc x ) (pos y ) p = tt sucInt-reflects-< (negsuc zero ) (negsuc zero ) p = p sucInt-reflects-< (negsuc (suc x)) (negsuc zero ) p = 0<ⁿsuc x sucInt-reflects-< (negsuc (suc x)) (negsuc (suc y)) p = sucⁿ-creates-<ⁿ y x .fst p predInt-reflects-< : ∀ x y → [ predInt x < predInt y ] → [ x < y ] predInt-reflects-< (pos zero ) (pos zero ) p = p predInt-reflects-< (pos zero ) (pos (suc y)) p = 0<ⁿsuc y predInt-reflects-< (pos (suc x)) (pos (suc y)) p = sucⁿ-creates-<ⁿ x y .fst p predInt-reflects-< (pos zero ) (negsuc y ) p = ¬-<ⁿ-zero p predInt-reflects-< (negsuc x ) (pos y ) p = tt predInt-reflects-< (negsuc x ) (negsuc y ) p = sucⁿ-creates-<ⁿ y x .snd p sucInt-preserves-< : ∀ x y → [ x < y ] → [ sucInt x < sucInt y ] sucInt-preserves-< (pos x ) (pos y ) p = sucⁿ-creates-<ⁿ x y .fst p sucInt-preserves-< (negsuc zero ) (pos y ) p = 0<ⁿsuc y sucInt-preserves-< (negsuc (suc x)) (pos y ) p = tt sucInt-preserves-< (negsuc zero ) (negsuc zero ) p = p sucInt-preserves-< (negsuc zero ) (negsuc (suc y)) p = ¬-<ⁿ-zero p sucInt-preserves-< (negsuc (suc x)) (negsuc zero ) p = tt sucInt-preserves-< (negsuc (suc x)) (negsuc (suc y)) p = sucⁿ-creates-<ⁿ y x .snd p predInt-preserves-< : ∀ x y → [ x < y ] → [ predInt x < predInt y ] predInt-preserves-< (pos zero ) (pos zero ) p = p predInt-preserves-< (pos zero ) (pos (suc y)) p = tt predInt-preserves-< (pos (suc x)) (pos zero ) p = ¬-<ⁿ-zero p predInt-preserves-< (pos (suc x)) (pos (suc y)) p = sucⁿ-creates-<ⁿ x y .snd p predInt-preserves-< (negsuc x ) (pos zero ) p = 0<ⁿsuc x predInt-preserves-< (negsuc x ) (pos (suc y)) p = tt predInt-preserves-< (negsuc x ) (negsuc y ) p = sucⁿ-creates-<ⁿ y x .fst p abstract +-preserves-< : ∀ a b x → [ a < b ] → [ (a + x) < (b + x) ] +-preserves-< a b (pos zero) a<b = a<b +-preserves-< a b (pos (suc n)) a<b = let r = +-preserves-< a b (pos n) a<b in sucInt-preserves-< (a +pos n) (b +pos n) r +-preserves-< a b (negsuc zero) a<b = predInt-preserves-< a b a<b +-preserves-< a b (negsuc (suc n)) a<b = let r = +-preserves-< a b (negsuc n) a<b in predInt-preserves-< (a +negsuc n) (b +negsuc n) r +-reflects-< : ∀ a b x → [ (a + x) < (b + x) ] → [ a < b ] +-reflects-< a b x = snd ( (a + x) < (b + x) ⇒ᵖ⟨ +-preserves-< (a + x) (b + x) (- x) ⟩ ((a + x) + (- x)) < ((b + x) + (- x)) ⇒ᵖ⟨ (pathTo⇐ λ i → +-assoc a x (- x) i < +-assoc b x (- x) i) ⟩ (a + (x + (- x))) < (b + (x + (- x))) ⇒ᵖ⟨ (pathTo⇒ λ i → (a + +-inverseʳ x i) < (b + +-inverseʳ x i)) ⟩ (a + 0) < (b + 0) ⇒ᵖ⟨ (λ x → x) ⟩ a < b ◼ᵖ) +-reflects-<ˡ : ∀ a b x → [ (x + a) < (x + b) ] → [ a < b ] +-reflects-<ˡ a b x p = +-reflects-< a b x (transport (λ i → [ +-comm x a i < +-comm x b i ]) p) abstract -- + is <-extentional +-<-ext : (w x y z : ℤ) → [ (w + x) < (y + z) ] → [ (w < y) ⊔ (x < z) ] +-<-ext w x y z r with w ≟ y | x ≟ z ... | lt w<y | q = inlᵖ w<y ... | eq w≡y | q = inrᵖ (+-reflects-<ˡ x z y (transport (λ i → [ (w≡y i + x) < (y + z) ]) r)) ... | gt y<w | q = inrᵖ $ case (<-cotrans (w + x) (y + z) r (y + x)) as ((w + x) < (y + x)) ⊔ ((y + x) < (y + z)) ⇒ x < z of λ { (inl p) → ⊥-elim {A = λ _ → [ x < z ]} (<-asym y w y<w (+-reflects-< w y x p)) ; (inr p) → +-reflects-<ˡ x z y p } -- properties about multiplication abstract -- equality of _·_ and _·'_ ·≡·' : ∀ x y → x · y ≡ x ·' y ·≡·' (pos a) (pos b) = refl ·≡·' (pos zero) (negsuc b) = refl ·≡·' (pos (suc a)) (negsuc b) = negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) ≡⟨ (λ i → negsuc $ lemma1 a b i) ⟩ negsuc (b +ⁿ a ·ⁿ suc b) ≡⟨ refl ⟩ neg (suc (b +ⁿ a ·ⁿ suc b)) ∎ ·≡·' (negsuc a) (pos zero) = λ i → signed sneg $ ·ⁿ-nullifiesʳ a (~ i) ·≡·' (negsuc a) (pos (suc b)) = λ i → negsuc $ lemma1 a b i ·≡·' (negsuc a) (negsuc b) = refl ·'-nullifiesʳ : ∀ x → x ·' 0 ≡ 0 ·'-nullifiesʳ (pos n) i = signed spos (·ⁿ-nullifiesʳ n i) ·'-nullifiesʳ (negsuc n) i = signed sneg (·ⁿ-nullifiesʳ n i) ·'-nullifiesˡ : ∀ x → 0 ·' x ≡ 0 ·'-nullifiesˡ (pos n) i = pos (·ⁿ-nullifiesˡ n i) ·'-nullifiesˡ (negsuc n) = refl abstract -distrˡ : ∀ a b → -(a · b) ≡ (- a) · b -distrˡ (pos zero ) (pos zero ) = refl -distrˡ (pos zero ) (pos (suc b)) = refl -distrˡ (pos (suc a)) (pos zero ) = λ i → - pos (·ⁿ-nullifiesʳ a i) -distrˡ (pos (suc a)) (pos (suc b)) = λ i → negsuc $ lemma1 a b (~ i) -distrˡ (pos zero ) (negsuc b ) = refl -distrˡ (pos (suc a)) (negsuc b ) = λ i → pos $ suc $ lemma1 a b i -distrˡ (negsuc a ) (pos zero ) = λ i → pos (·ⁿ-nullifiesʳ a (~ i)) -distrˡ (negsuc a ) (pos (suc b)) = λ i → pos $ suc $ lemma1 a b i -distrˡ (negsuc a ) (negsuc b ) = λ i → negsuc $ lemma1 a b (~ i) abstract ·-comm : ∀ a b → a · b ≡ b · a ·-comm (pos a ) (pos b ) = λ i → pos $ ·ⁿ-comm a b i ·-comm (pos zero ) (negsuc b ) = refl ·-comm (pos (suc a)) (negsuc b ) = λ i → negsuc $ ·ⁿ-comm a b i +ⁿ +ⁿ-comm a b i ·-comm (negsuc a ) (pos zero ) = refl ·-comm (negsuc a ) (pos (suc b)) = λ i → negsuc $ ·ⁿ-comm a b i +ⁿ +ⁿ-comm a b i ·-comm (negsuc a ) (negsuc b ) i = pos (suc (lemma7 a b i)) -distrʳ : ∀ a b → -(a · b) ≡ a · (- b) -distrʳ a b = (λ i → - ·-comm a b i) ∙ -distrˡ b a ∙ ·-comm (- b) a abstract -- this proof of associativity is ported from `Data.Integer.Properties` which works on -- _·_ : ℤ → ℤ → ℤ -- i · j = sign i S· sign j ◃ ∣ i ∣ ℕ· ∣ j ∣ ·'-assoc : ∀ x y z → (x ·' y) ·' z ≡ x ·' (y ·' z) ·'-assoc (pos 0) y z = (λ i → ·'-nullifiesˡ y i ·' z) ∙ ·'-nullifiesˡ z ∙ sym (·'-nullifiesˡ (y ·' z)) ·'-assoc x (pos 0) z = (λ i → ·'-nullifiesʳ x i ·' z) ∙ ·'-nullifiesˡ z ∙ sym (·'-nullifiesʳ x) ∙ (λ i → x ·' ·'-nullifiesˡ z (~ i)) ·'-assoc x y (pos 0) = ·'-nullifiesʳ (x ·' y) ∙ sym (·'-nullifiesʳ x) ∙ (λ i → x ·' ·'-nullifiesʳ y (~ i)) ·'-assoc (negsuc a ) (negsuc b ) (pos (suc c)) = λ i → (pos (suc (lemma2 a b c i))) ·'-assoc (negsuc a ) (pos (suc b)) (negsuc c ) = λ i → (pos (suc (lemma2 a b c i))) ·'-assoc (pos (suc a)) (pos (suc b)) (pos (suc c)) = λ i → (pos (suc (lemma2 a b c i))) ·'-assoc (pos (suc a)) (negsuc b ) (negsuc c ) = λ i → (pos (suc (lemma2 a b c i))) ·'-assoc (negsuc a ) (negsuc b ) (negsuc c ) = λ i → (negsuc (lemma2 a b c i) ) ·'-assoc (negsuc a ) (pos (suc b)) (pos (suc c)) = λ i → (negsuc (lemma2 a b c i) ) ·'-assoc (pos (suc a)) (negsuc b ) (pos (suc c)) = λ i → (negsuc (lemma2 a b c i) ) ·'-assoc (pos (suc a)) (pos (suc b)) (negsuc c ) = λ i → (negsuc (lemma2 a b c i) ) abstract -- equality of associativity on _·_ and _·'_ ·'-assoc≡ : ∀ x y z → ((x · y) · z ≡ x · (y · z)) ≡ ((x ·' y) ·' z ≡ x ·' (y ·' z)) ·'-assoc≡ x y z i = ·≡·' (·≡·' x y i) z i ≡ ·≡·' x (·≡·' y z i) i -- associativity of _·_ from associativiy of _·'_ ·-assoc : ∀ x y z → (x · y) · z ≡ x · (y · z) ·-assoc x y z = transport (sym (·'-assoc≡ x y z)) (·'-assoc x y z) abstract ·-nullifiesˡ : ∀ x → 0 · x ≡ 0 ·-nullifiesˡ (pos n) = refl ·-nullifiesˡ (negsuc n) = refl ·-nullifiesʳ : ∀ x → x · 0 ≡ 0 ·-nullifiesʳ x = ·-comm x 0 ∙ ·-nullifiesˡ x ·-identityˡ : ∀ x → 1 · x ≡ x ·-identityˡ (pos n) = λ i → pos $ +ⁿ-comm n 0 i ·-identityˡ (negsuc n) = refl ·-identityʳ : ∀ x → x · 1 ≡ x ·-identityʳ x = ·-comm x 1 ∙ ·-identityˡ x abstract ·-preserves-< : (x y z : ℤ) → [ 0 < z ] → [ x < y ] → [ (x · z) < (y · z) ] ·-preserves-< (pos x) (pos y) (pos z ) p q = ·ⁿ-preserves-<ⁿ x y z p q ·-preserves-< (negsuc x) (pos y) (pos zero ) p q = subst (λ p → [ 0 <ⁿ p ]) (sym $ ·ⁿ-nullifiesʳ y) p ·-preserves-< (negsuc x) (pos y) (pos (suc z)) p q = tt ·-preserves-< (negsuc x) (negsuc y) (pos zero ) p q = p ·-preserves-< (negsuc x) (negsuc y) (pos (suc z)) p q = ( y <ⁿ x ⇒ᵖ⟨ ·ⁿ-preserves-<ⁿ y x (suc z) (0<ⁿsuc z) ⟩ (y ·ⁿ suc z ) <ⁿ (x ·ⁿ suc z ) ⇒ᵖ⟨ +ⁿ-createsʳ-<ⁿ (y ·ⁿ suc z) (x ·ⁿ suc z) z .fst ⟩ (y ·ⁿ suc z +ⁿ z ) <ⁿ (x ·ⁿ suc z +ⁿ z ) ⇒ᵖ⟨ pathTo⇐ (λ i → lemma3 y z i <ⁿ lemma3 x z i) ⟩ (y ·ⁿ z +ⁿ (y +ⁿ z)) <ⁿ (x ·ⁿ z +ⁿ (x +ⁿ z)) ◼ᵖ) .snd q ·-reflects-< : (x y z : ℤ) → [ 0 < z ] → [ (x · z) < (y · z) ] → [ x < y ] ·-reflects-< (pos x) (pos y) (pos z ) p q = ·ⁿ-reflects-<ⁿ x y z p q ·-reflects-< (pos x) (negsuc y) (pos zero ) p q = <ⁿ-irrefl 0 p ·-reflects-< (negsuc x) (pos y) (pos zero ) p q = tt ·-reflects-< (negsuc x) (pos y) (pos (suc z)) p q = tt ·-reflects-< (negsuc x) (negsuc y) (pos zero ) p (k , q) = ⊥-elim {A = λ _ → [ y <ⁿ x ]} $ snotzⁿ (sym (+ⁿ-suc k 0) ∙ q) ·-reflects-< (negsuc x) (negsuc y) (pos (suc z)) p q = ( (y ·ⁿ z +ⁿ (y +ⁿ z)) <ⁿ (x ·ⁿ z +ⁿ (x +ⁿ z)) ⇒ᵖ⟨ pathTo⇒ (λ i → +ⁿ-assoc (y ·ⁿ z) y z i <ⁿ +ⁿ-assoc (x ·ⁿ z) x z i) ⟩ ((y ·ⁿ z +ⁿ y) +ⁿ z) <ⁿ ((x ·ⁿ z +ⁿ x) +ⁿ z) ⇒ᵖ⟨ +ⁿ-createsʳ-<ⁿ (y ·ⁿ z +ⁿ y) (x ·ⁿ z +ⁿ x) z .snd ⟩ (y ·ⁿ z +ⁿ y ) <ⁿ (x ·ⁿ z +ⁿ x ) ⇒ᵖ⟨ pathTo⇒ (λ i → γ y i <ⁿ γ x i) ⟩ (y ·ⁿ suc z ) <ⁿ (x ·ⁿ suc z ) ⇒ᵖ⟨ ·ⁿ-reflects-<ⁿ y x (suc z) (0<ⁿsuc z) ⟩ y <ⁿ x ◼ᵖ) .snd q where γ : ∀ x → x ·ⁿ z +ⁿ x ≡ x ·ⁿ suc z γ x = sym $ ·ⁿ-comm x (suc z) ∙ +ⁿ-comm x (z ·ⁿ x) ∙ (λ i → ·ⁿ-comm z x i +ⁿ x) abstract ·-sucInt : ∀ m n → (m · sucInt n) ≡ (m + (m · n)) ·-sucInt (pos a ) (pos b ) = (λ i → pos (·ⁿ-suc a b i)) ∙ sym (pos+pos≡+ⁿ a (a ·ⁿ b)) ·-sucInt (pos zero ) (negsuc b ) = ·-nullifiesˡ _ ·-sucInt (pos (suc a)) (negsuc zero) = pos (a ·ⁿ zero) ≡⟨ (λ i → pos $ ·ⁿ-nullifiesʳ a i) ⟩ pos 0 ≡⟨ sym $ +-inverse (pos (suc a)) .fst ⟩ (pos (suc a) +negsuc a ) ≡⟨ refl ⟩ (pos (suc a) +negsuc ( zero +ⁿ a )) ≡⟨ (λ i → pos (suc a) +negsuc (sym (·ⁿ-nullifiesʳ a) i +ⁿ +ⁿ-comm 0 a i)) ⟩ (pos (suc a) +negsuc (a ·ⁿ zero +ⁿ (a +ⁿ zero))) ∎ ·-sucInt (pos (suc a)) (negsuc (suc b)) = negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) ≡⟨ sym $ +negsuc-identityˡ (a ·ⁿ b +ⁿ (a +ⁿ b)) ⟩ 0 +negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) ≡⟨ (λ i → possuc+negsuc≡0 a (~ i) +negsuc (a ·ⁿ b +ⁿ (a +ⁿ b))) ⟩ (pos (suc a) +negsuc a) +negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) ≡⟨ sym $ +negsuc-assoc (pos (suc a)) a (a ·ⁿ b +ⁿ (a +ⁿ b)) ⟩ pos (suc a) +negsuc (a +ⁿ suc (a ·ⁿ b +ⁿ (a +ⁿ b))) ≡⟨ (λ i → pos (suc a) +negsuc (lemma4 a b (~ i))) ⟩ pos (suc a) +negsuc (a ·ⁿ suc b +ⁿ (a +ⁿ suc b)) ∎ ·-sucInt (negsuc a ) (pos zero ) = λ i → negsuc $ ·ⁿ-nullifiesʳ a i +ⁿ +ⁿ-comm a 0 i ·-sucInt (negsuc a ) (pos (suc b)) = negsuc (a ·ⁿ suc b +ⁿ (a +ⁿ suc b)) ≡⟨ (λ i → negsuc $ lemma4 a b i) ⟩ negsuc (a +ⁿ suc (a ·ⁿ b +ⁿ (a +ⁿ b))) ≡⟨ (λ i → negsuc $ +ⁿ-suc a (a ·ⁿ b +ⁿ (a +ⁿ b)) i) ∙ sym (negsuc+negsuc≡+ⁿ a (a ·ⁿ b +ⁿ (a +ⁿ b))) ⟩ negsuc a +negsuc (a ·ⁿ b +ⁿ (a +ⁿ b)) ∎ ·-sucInt (negsuc a) (negsuc zero) = sym (+-inverse (pos (suc a)) .snd) ∙ (λ i → sucInt (negsuc a +pos (·ⁿ-identityʳ a (~ i)))) ·-sucInt (negsuc a) (negsuc (suc b)) = pos (suc (b +ⁿ a ·ⁿ suc b)) ≡⟨ refl ⟩ sucInt (pos (b +ⁿ a ·ⁿ suc b)) ≡⟨ (λ i → sucInt $ sucInt[negsuc+pos]≡pos (b +ⁿ a ·ⁿ suc b) (~ i)) ⟩ sucInt (sucInt (negsuc 0 +pos (b +ⁿ a ·ⁿ suc b))) ≡⟨ (λ i → sucInt (sucInt (+pos-inverse a (~ i) +pos (b +ⁿ a ·ⁿ suc b)))) ⟩ sucInt (sucInt ((negsuc a +pos a) +pos (b +ⁿ a ·ⁿ suc b))) ≡⟨ (λ i → sucInt $ sucInt $ +pos-assoc (negsuc a) a (b +ⁿ a ·ⁿ suc b) i) ⟩ sucInt (sucInt (negsuc a +pos (a +ⁿ (b +ⁿ a ·ⁿ suc b)))) ≡⟨ (λ i → sucInt (sucInt (negsuc a +pos lemma5 a b i))) ⟩ sucInt (sucInt (negsuc a +pos (b +ⁿ a ·ⁿ suc (suc b)))) ∎ abstract ·-sucIntˡ : ∀ m n → (sucInt m · n) ≡ (n + (m · n)) ·-sucIntˡ m n = ·-comm (sucInt m) n ∙ ·-sucInt n m ∙ λ i → n + ·-comm n m i ·-predInt : ∀ m n → (m · predInt n) ≡ ((- m) + (m · n)) ·-predInt m (pos zero) = ·-comm m (negsuc 0) ∙ -1·≡- m ∙ λ i → (- m) + ·-nullifiesʳ m (~ i) ·-predInt m (pos (suc n)) = m · pos n ≡⟨ +-comm (m · pos n) 0 ⟩ 0 + m · pos n ≡⟨ (λ i → +-inverseˡ m (~ i) + (m · pos n)) ⟩ ((- m) + m) + (m · pos n) ≡⟨ sym $ +-assoc (- m) m (m · pos n) ⟩ (- m) + (m + (m · pos n)) ≡⟨ (λ i → (- m) + ·-sucInt m (pos n) (~ i)) ⟩ (- m) + (m · pos (suc n)) ∎ ·-predInt (pos zero) (negsuc zero) = refl ·-predInt (pos (suc n)) (negsuc zero) = (λ i → negsuc $ ·ⁿ-identityʳ n i +ⁿ +ⁿ-comm n 1 i) ∙ (λ i → negsuc $ +ⁿ-comm n (suc n) i) ∙ sym (negsuc+negsuc≡+ⁿ n n) ∙ (λ i → negsuc n +negsuc (·ⁿ-nullifiesʳ n (~ i) +ⁿ +ⁿ-comm 0 n i)) ·-predInt (pos zero) (negsuc (suc m)) = refl ·-predInt (pos (suc n)) (negsuc (suc m)) = negsuc (n ·ⁿ suc (suc m) +ⁿ (n +ⁿ suc (suc m))) ≡⟨ (λ i → negsuc $ ·ⁿ-suc n (suc m) i +ⁿ +ⁿ-suc n (suc m) i) ⟩ negsuc ((n +ⁿ n ·ⁿ suc m) +ⁿ suc (n +ⁿ suc m)) ≡⟨ (λ i → negsuc $ +ⁿ-assoc n (n ·ⁿ suc m) (suc n +ⁿ suc m) (~ i)) ⟩ negsuc (n +ⁿ (n ·ⁿ suc m +ⁿ suc (n +ⁿ suc m))) ≡⟨ (λ i → negsuc $ n +ⁿ +ⁿ-suc (n ·ⁿ suc m) (n +ⁿ suc m) i) ⟩ negsuc (n +ⁿ suc (n ·ⁿ suc m +ⁿ (n +ⁿ suc m))) ≡⟨ (λ i → negsuc $ +ⁿ-suc n (n ·ⁿ suc m +ⁿ (n +ⁿ suc m)) i) ⟩ negsuc (suc (n +ⁿ (n ·ⁿ suc m +ⁿ (n +ⁿ suc m)))) ≡⟨ sym $ negsuc+negsuc≡+ⁿ n (n ·ⁿ suc m +ⁿ (n +ⁿ suc m)) ⟩ (negsuc n +negsuc (n ·ⁿ suc m +ⁿ (n +ⁿ suc m))) ∎ ·-predInt (negsuc n) (negsuc zero) = cong sucInt ((λ i → pos $ suc $ ·ⁿ-suc n 1 i) ∙ sym (pos+pos≡+ⁿ (suc n) (n ·ⁿ 1))) ·-predInt (negsuc n) (negsuc (suc m)) = pos (suc (suc (suc (m +ⁿ n ·ⁿ suc (suc (suc m)))))) ≡⟨ refl ⟩ sucInt (sucInt (pos (suc (m +ⁿ n ·ⁿ suc (suc (suc m)))))) ≡⟨ (λ i → sucInt $ sucInt $ pos $ lemma6 m n i) ⟩ sucInt (sucInt (pos (suc n +ⁿ (m +ⁿ n ·ⁿ suc (suc m))))) ≡⟨ (λ i → sucInt $ sucInt $ pos+pos≡+ⁿ (suc n) (m +ⁿ n ·ⁿ suc (suc m)) (~ i)) ⟩ sucInt (sucInt (pos (suc n) +pos (m +ⁿ n ·ⁿ suc (suc m)))) ∎ abstract ·-predIntˡ : ∀ m n → (predInt m · n) ≡ ((- n) + (m · n)) ·-predIntˡ m n = ·-comm (predInt m) n ∙ ·-predInt n m ∙ λ i → (- n) + (·-comm n m i) -distrib : ∀ m n → -(m + n) ≡ (- m) + (- n) -distrib (pos zero) (pos zero) = refl -distrib (pos (suc n)) (pos zero) = refl -distrib (pos zero) (pos (suc m)) = - sucInt (pos zero +pos m) ≡⟨ (λ i → - sucInt (pos+pos≡+ⁿ 0 m i)) ⟩ negsuc m ≡⟨ sym $ +negsuc-identityˡ m ⟩ (pos zero +negsuc m) ∎ -distrib (pos (suc n)) (pos (suc m)) = (λ i → - sucInt (pos+pos≡+ⁿ (suc n) m i)) ∙ sym (negsuc+negsuc≡+ⁿ n m) -distrib (pos zero) (negsuc m) = (λ i → - +negsuc-identityˡ m i) ∙ sym (pos+pos≡+ⁿ 0 (suc m)) -distrib (pos (suc n)) (negsuc m) = sym (pos+negsuc-swap m n) ∙ pos+negsuc≡negsuc+pos (suc m) n -distrib (negsuc n) (pos zero) = refl -distrib (negsuc n) (pos (suc m)) = (λ i → - pos+negsuc≡negsuc+pos (suc m) n (~ i)) ∙ sym (pos+negsuc-swap n m) -distrib (negsuc n) (negsuc m) = (λ i → - negsuc+negsuc≡+ⁿ n m i) ∙ (λ i → sucInt $ pos+pos≡+ⁿ (suc n) m (~ i)) abstract ·-distribˡ : ∀ o m n → (o · m) + (o · n) ≡ o · (m + n) ·-distribˡ (pos zero) m n = (λ i → ·-nullifiesˡ m i + ·-nullifiesˡ n i) ∙ (sym $ ·-nullifiesˡ (m + n)) ·-distribˡ (pos (suc o)) m n = let ind = ·-distribˡ (pos o) m n lhs = (pos (suc o) · m) + (pos (suc o) · n) ≡⟨ (λ i → ·-sucIntˡ (pos o) m i + ·-sucIntˡ (pos o) n i) ⟩ (m + (pos o · m)) + (n + (pos o · n)) ≡⟨ sym $ +-assoc m (pos o · m) (n + (pos o · n)) ⟩ m + ((pos o · m) + (n + (pos o · n))) ≡⟨ (λ i → m + +-comm (pos o · m) (n + (pos o · n)) i) ⟩ m + ((n + (pos o · n)) + (pos o · m)) ≡⟨ (λ i → m + +-assoc n (pos o · n) (pos o · m) (~ i)) ⟩ m + (n + ((pos o · n) + (pos o · m))) ≡⟨ (λ i → +-assoc m n (+-comm (pos o · n) (pos o · m) i) i) ⟩ (m + n) + ((pos o · m) + (pos o · n)) ≡⟨ (λ i → (m + n) + ind i) ⟩ (m + n) + (pos o · (m + n)) ∎ rhs = (pos (suc o) · (m + n)) ≡⟨ refl ⟩ (sucInt (pos o) · (m + n)) ≡⟨ ·-sucIntˡ (pos o) (m + n) ⟩ ((m + n) + (pos o · (m + n))) ∎ in lhs ∙ sym rhs ·-distribˡ (negsuc zero) (pos zero) (pos zero) = refl ·-distribˡ (negsuc zero) (pos zero) (pos (suc n)) = +negsuc-identityˡ n ∙ λ i → negsuc 0 · sucInt (pos+pos≡+ⁿ 0 n (~ i)) ·-distribˡ (negsuc zero) (pos (suc m)) (pos zero) = refl ·-distribˡ (negsuc zero) (pos (suc m)) (pos (suc n)) = negsuc+negsuc≡+ⁿ m n ∙ λ i → negsuc 0 · sucInt (pos+pos≡+ⁿ (suc m) n (~ i)) ·-distribˡ (negsuc zero) (pos zero) (negsuc n) = (λ i → sucInt $ pos+pos≡+ⁿ 0 (n +ⁿ 0) i) ∙ (λ i → negsuc 0 · +negsuc-identityˡ n (~ i)) ·-distribˡ (negsuc zero) (pos (suc m)) (negsuc n) = sucInt (negsuc m +pos (n +ⁿ zero)) ≡⟨ (λ i → sucInt $ negsuc m +pos +ⁿ-comm n 0 i) ⟩ sucInt (negsuc m +pos n) ≡⟨ refl ⟩ negsuc m +pos (suc n) ≡⟨ negsuc+pos-swap m n ⟩ - (negsuc n +pos (suc m)) ≡⟨ (λ i → - pos+negsuc≡negsuc+pos (suc m) n (~ i)) ⟩ - (pos (suc m) +negsuc n) ≡⟨ sym $ -1·≡- (pos (suc m) +negsuc n) ⟩ negsuc zero · (pos (suc m) +negsuc n) ∎ ·-distribˡ (negsuc zero) (negsuc m) (pos zero) = refl ·-distribˡ (negsuc zero) (negsuc m) (pos (suc n)) = pos (suc (m +ⁿ zero)) +negsuc n ≡⟨ (λ i → pos (suc (+ⁿ-comm m 0 i)) +negsuc n) ⟩ pos (suc m) +negsuc n ≡⟨ pos+negsuc≡negsuc+pos (suc m) n ⟩ sucInt (negsuc n +pos m) ≡⟨ negsuc+pos-swap n m ⟩ - negsuc m +pos (suc n) ≡⟨ refl ⟩ - sucInt (negsuc m +pos n) ≡⟨ sym $ -1·≡- (sucInt (negsuc m +pos n)) ⟩ negsuc zero · sucInt (negsuc m +pos n) ∎ ·-distribˡ (negsuc zero) (negsuc m) (negsuc n) = sucInt (pos (suc (m +ⁿ zero)) +pos (n +ⁿ zero)) ≡⟨ (λ i → sucInt (pos (suc (+ⁿ-comm m 0 i)) +pos (+ⁿ-comm n 0 i))) ⟩ sucInt (pos (suc m) +pos (n)) ≡⟨ (λ i → sucInt $ pos+pos≡+ⁿ (suc m) n i) ⟩ sucInt (pos (suc m +ⁿ n)) ≡⟨ refl ⟩ pos (suc (suc (m +ⁿ n))) ≡⟨ (λ i → pos $ suc $ suc $ +ⁿ-comm 0 (m +ⁿ n) i) ⟩ negsuc zero · (negsuc (suc (m +ⁿ n))) ≡⟨ (λ i → negsuc zero · negsuc+negsuc≡+ⁿ m n (~ i)) ⟩ negsuc zero · (negsuc m +negsuc n) ∎ ·-distribˡ (negsuc (suc o)) m n = let r = ·-distribˡ (negsuc o) m n lhs = (negsuc (suc o) · m) + (negsuc (suc o) · n) ≡⟨ (λ i → ·-predIntˡ (negsuc o) m i + ·-predIntˡ (negsuc o) n i) ⟩ ((- m) + (negsuc o · m)) + ((- n) + (negsuc o · n)) ≡⟨ sym $ +-assoc (- m) (negsuc o · m) ((- n) + (negsuc o · n)) ⟩ (- m) + ((negsuc o · m) + ((- n) + (negsuc o · n))) ≡⟨ (λ i → (- m) + +-comm (negsuc o · m) ((- n) + (negsuc o · n)) i) ⟩ (- m) + (((- n) + (negsuc o · n)) + (negsuc o · m)) ≡⟨ (λ i → (- m) + +-assoc (- n) (negsuc o · n) (negsuc o · m) (~ i)) ⟩ (- m) + ((- n) + ((negsuc o · n) + (negsuc o · m))) ≡⟨ (λ i → +-assoc (- m) (- n) (+-comm (negsuc o · n) (negsuc o · m) i) i) ⟩ ((- m) + (- n)) + ((negsuc o · m) + (negsuc o · n)) ≡⟨ (λ i → ((- m) + (- n)) + r i) ⟩ ((- m) + (- n)) + (negsuc o · (m + n)) ∎ rhs = negsuc (suc o) · (m + n) ≡⟨ ·-predIntˡ (negsuc o) (m + n) ⟩ (- (m + n)) + negsuc (o) · (m + n) ≡⟨ (λ i → -distrib m n i + negsuc (o) · (m + n)) ⟩ ((- m) + (- n)) + (negsuc (o) · (m + n)) ∎ in lhs ∙ sym rhs abstract ·-distribʳ : ∀ m n o → (m · o) + (n · o) ≡ (m + n) · o ·-distribʳ m n o = transport (sym λ i → ·-comm m o i + ·-comm n o i ≡ ·-comm (m + n) o i) $ ·-distribˡ o m n +-Semigroup : [ isSemigroup _+_ ] +-Semigroup .IsSemigroup.is-set = isSetℤ +-Semigroup .IsSemigroup.is-assoc = +-assoc ·-Semigroup : [ isSemigroup _·_ ] ·-Semigroup .IsSemigroup.is-set = isSetℤ ·-Semigroup .IsSemigroup.is-assoc x y z = sym (·-assoc x y z) +-Monoid : [ isMonoid 0 _+_ ] +-Monoid .IsMonoid.is-Semigroup = +-Semigroup +-Monoid .IsMonoid.is-identity x = +-identityʳ x , +-identityˡ x ·-Monoid : [ isMonoid 1 _·_ ] ·-Monoid .IsMonoid.is-Semigroup = ·-Semigroup ·-Monoid .IsMonoid.is-identity x = ·-identityʳ x , ·-identityˡ x is-Semiring : [ isSemiring 0 1 _+_ _·_ ] is-Semiring .IsSemiring.+-Monoid = +-Monoid is-Semiring .IsSemiring.·-Monoid = ·-Monoid is-Semiring .IsSemiring.+-comm = +-comm is-Semiring .IsSemiring.is-dist x y z = sym (·-distribˡ x y z) , sym (·-distribʳ x y z) is-CommSemiring : [ isCommSemiring 0 1 _+_ _·_ ] is-CommSemiring .IsCommSemiring.is-Semiring = is-Semiring is-CommSemiring .IsCommSemiring.·-comm = ·-comm <-StrictLinearOrder : [ isStrictLinearOrder _<_ ] <-StrictLinearOrder .IsStrictLinearOrder.is-irrefl = <-irrefl <-StrictLinearOrder .IsStrictLinearOrder.is-trans a b c = <-trans a b c <-StrictLinearOrder .IsStrictLinearOrder.is-tricho a b with a ≟ b ... | lt a<b = inl (inl a<b) ... | eq a≡b = inr ∣ a≡b ∣ ... | gt b<a = inl (inr b<a) ≤-Lattice : [ isLattice (λ x y → ¬ᵖ (y < x)) min max ] ≤-Lattice .IsLattice.≤-PartialOrder = linearorder⇒partialorder _ (≤'-isLinearOrder <-StrictLinearOrder) ≤-Lattice .IsLattice.is-min = is-min ≤-Lattice .IsLattice.is-max = is-max is-LinearlyOrderedCommSemiring : [ isLinearlyOrderedCommSemiring 0 1 _+_ _·_ _<_ min max ] is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.is-CommSemiring = is-CommSemiring is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.<-StrictLinearOrder = <-StrictLinearOrder is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.≤-Lattice = ≤-Lattice is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.+-<-ext = +-<-ext is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.·-preserves-< = ·-preserves-< is-LinearlyOrderedCommRing : [ isLinearlyOrderedCommRing 0 1 _+_ _·_ -_ _<_ min max ] is-LinearlyOrderedCommRing .IsLinearlyOrderedCommRing.is-LinearlyOrderedCommSemiring = is-LinearlyOrderedCommSemiring is-LinearlyOrderedCommRing .IsLinearlyOrderedCommRing.+-inverse = +-inverse ℤbundle : LinearlyOrderedCommRing {ℓ-zero} {ℓ-zero} ℤbundle .LinearlyOrderedCommRing.Carrier = ℤ ℤbundle .LinearlyOrderedCommRing.0f = 0 ℤbundle .LinearlyOrderedCommRing.1f = 1 ℤbundle .LinearlyOrderedCommRing._+_ = _+_ ℤbundle .LinearlyOrderedCommRing._·_ = _·_ ℤbundle .LinearlyOrderedCommRing.-_ = -_ ℤbundle .LinearlyOrderedCommRing.min = min ℤbundle .LinearlyOrderedCommRing.max = max ℤbundle .LinearlyOrderedCommRing._<_ = _<_ ℤbundle .LinearlyOrderedCommRing.is-LinearlyOrderedCommRing = is-LinearlyOrderedCommRing -- ·-reflects-≡ˡ : ∀ a b x → (pos (suc x)) ·' a ≡ (pos (suc x)) ·' b → a ≡ b -- ·-reflects-≡ˡ a b x p = {! !} -- private -- ¬0≡suc -- ¬0≡possuc -- ¬0≡negsuc -- ¬pos≡negsuc -- -- ·-reflects-≡ʳ : ∀ a b x → a · (pos (suc x)) ≡ b · (pos (suc x)) → a ≡ b -- ·-reflects-≡ʳ (pos 0 ) (pos 0 ) x q = refl -- ·-reflects-≡ʳ (pos 0 ) (pos (suc b)) x q = {! ⊥ !} -- ·-reflects-≡ʳ (pos (suc a)) (pos 0 ) x q = {! ⊥ !} -- ·-reflects-≡ʳ (pos (suc a)) (pos (suc b)) x q i = sucInt $ ·-reflects-≡ʳ (pos a) (pos b) x {! !} i -- ·-reflects-≡ʳ (pos 0 ) (negsuc b ) x q = {! ⊥ !} -- ·-reflects-≡ʳ (pos (suc a)) (negsuc b ) x q = {! ⊥ !} -- ·-reflects-≡ʳ (negsuc a ) (pos 0 ) x q = {! ⊥ !} -- ·-reflects-≡ʳ (negsuc a ) (pos (suc b)) x q = {! ⊥ !} -- ·-reflects-≡ʳ (negsuc zero) (negsuc zero) x q = refl -- ·-reflects-≡ʳ (negsuc zero) (negsuc (suc b)) x q = {! ⊥ !} -- ·-reflects-≡ʳ (negsuc (suc a)) (negsuc zero) x q = {! ⊥ !} -- ·-reflects-≡ʳ (negsuc (suc a)) (negsuc (suc b)) x q i = predInt $ ·-reflects-≡ʳ (negsuc a) (negsuc b) x {! !} i
{ "alphanum_fraction": 0.5031090885, "avg_line_length": 50.9598163031, "ext": "agda", "hexsha": "9e36858e5b867bff3dc478d87e6eafae50a11b3c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mchristianl/synthetic-reals", "max_forks_repo_path": "agda/Number/Instances/Int.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mchristianl/synthetic-reals", "max_issues_repo_path": "agda/Number/Instances/Int.agda", "max_line_length": 228, "max_stars_count": 3, "max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mchristianl/synthetic-reals", "max_stars_repo_path": "agda/Number/Instances/Int.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z", "num_tokens": 21131, "size": 44386 }
{-# OPTIONS --without-K #-} module higher.circle where open import higher.circle.core public open import higher.circle.properties public
{ "alphanum_fraction": 0.7826086957, "avg_line_length": 23, "ext": "agda", "hexsha": "52424fd906612fc38f54e7623ef6b9b4cce06ad7", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/higher/circle.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/higher/circle.agda", "max_line_length": 43, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/higher/circle.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 25, "size": 138 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommAlgebra.Instances.Unit where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Structure open import Cubical.Data.Unit open import Cubical.Data.Sigma.Properties using (Σ≡Prop) open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommAlgebra.Base open import Cubical.Algebra.CommRing.Instances.Unit open import Cubical.Algebra.Algebra.Base using (IsAlgebraHom) open import Cubical.Algebra.CommRingSolver.Reflection private variable ℓ ℓ' : Level module _ (R : CommRing ℓ) where UnitCommAlgebra : CommAlgebra R ℓ' UnitCommAlgebra = commAlgebraFromCommRing UnitCommRing (λ _ _ → tt*) (λ _ _ _ → refl) (λ _ _ _ → refl) (λ _ _ _ → refl) (λ _ → refl) (λ _ _ _ → refl) module _ (A : CommAlgebra R ℓ) where terminalMap : CommAlgebraHom A (UnitCommAlgebra {ℓ' = ℓ}) terminalMap = (λ _ → tt*) , isHom where open IsAlgebraHom isHom : IsCommAlgebraHom (snd A) _ (snd UnitCommAlgebra) pres0 isHom = isPropUnit* _ _ pres1 isHom = isPropUnit* _ _ pres+ isHom = λ _ _ → isPropUnit* _ _ pres· isHom = λ _ _ → isPropUnit* _ _ pres- isHom = λ _ → isPropUnit* _ _ pres⋆ isHom = λ _ _ → isPropUnit* _ _ terminalityContr : isContr (CommAlgebraHom A UnitCommAlgebra) terminalityContr = terminalMap , path where path : (ϕ : CommAlgebraHom A UnitCommAlgebra) → terminalMap ≡ ϕ path ϕ = Σ≡Prop (isPropIsCommAlgebraHom {M = A} {N = UnitCommAlgebra}) λ i _ → isPropUnit* _ _ i open CommAlgebraStr (snd A) module _ (1≡0 : 1a ≡ 0a) where 1≡0→isContr : isContr ⟨ A ⟩ 1≡0→isContr = 0a , λ a → 0a ≡⟨ step1 a ⟩ a · 0a ≡⟨ cong (λ b → a · b) (sym 1≡0) ⟩ a · 1a ≡⟨ step2 a ⟩ a ∎ where S = CommAlgebra→CommRing A open CommRingStr (snd S) renaming (_·_ to _·s_) step1 : (x : ⟨ A ⟩) → 0r ≡ x ·s 0r step1 = solve S step2 : (x : ⟨ A ⟩) → x ·s 1r ≡ x step2 = solve S equivFrom1≡0 : CommAlgebraEquiv A UnitCommAlgebra equivFrom1≡0 = isContr→Equiv 1≡0→isContr isContrUnit* , snd terminalMap
{ "alphanum_fraction": 0.6050170068, "avg_line_length": 35.6363636364, "ext": "agda", "hexsha": "8e6a396ac4906d1254a1f180bf6c41f8bf156c26", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Algebra/CommAlgebra/Instances/Unit.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Algebra/CommAlgebra/Instances/Unit.agda", "max_line_length": 82, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Algebra/CommAlgebra/Instances/Unit.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 779, "size": 2352 }
-- Qualified mixfix operators module Issue597 where open import Common.Prelude as Prel hiding (if_then_else_) open import Common.Level using (lzero) lz = lzero Common.Level.⊔ lzero module A where data _×_ (A B : Set) : Set where _,_ : A → B → A × B if_then_else_ : ∀ {A : Set} → Bool → A → A → A if true then x else y = x if false then x else y = y pattern _+2 n = suc (suc n) module B where _₁ : ∀ {A B} → A × B → A (x , y)₁ = x _₂ : ∀ {A B} → A × B → B (x , y)₂ = y syntax Exist (λ x → p) = ∃ x ∶ p data Exist {A : Set}(P : A → Set) : Set where _,_ : (x : A) → P x → Exist P pp : Nat → Nat pp 0 = 0 pp 1 = 0 pp (n A.+2) = n infix 5 add_ add_ : Nat A.× Nat → Nat add_ p = p A.B.₁ Prel.+ p A.B.₂ six : Nat six = add 1 A., 5 two : Nat two = A.if true then 2 else 4 data Even : Nat → Set where ez : Even 0 ess : ∀ n → Even n → Even (suc (suc n)) pair : A.B.∃ n ∶ Even n pair = 2 A.B., ess zero ez
{ "alphanum_fraction": 0.544132918, "avg_line_length": 18.1698113208, "ext": "agda", "hexsha": "892035accea5efcb48632a38c5054d0d67995dbb", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/Issue597.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/succeed/Issue597.agda", "max_line_length": 57, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/succeed/Issue597.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 392, "size": 963 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Structures.Group.Base where open import Cubical.Foundations.Prelude open import Cubical.Data.Sigma open import Cubical.Structures.Monoid hiding (⟨_⟩) private variable ℓ : Level record IsGroup {G : Type ℓ} (0g : G) (_+_ : G → G → G) (-_ : G → G) : Type ℓ where constructor isgroup field isMonoid : IsMonoid 0g _+_ inverse : (x : G) → (x + (- x) ≡ 0g) × ((- x) + x ≡ 0g) open IsMonoid isMonoid public infixl 6 _-_ _-_ : G → G → G x - y = x + (- y) invl : (x : G) → (- x) + x ≡ 0g invl x = inverse x .snd invr : (x : G) → x + (- x) ≡ 0g invr x = inverse x .fst record Group : Type (ℓ-suc ℓ) where constructor group field Carrier : Type ℓ 0g : Carrier _+_ : Carrier → Carrier → Carrier -_ : Carrier → Carrier isGroup : IsGroup 0g _+_ -_ infix 8 -_ infixr 7 _+_ open IsGroup isGroup public -- Extractor for the carrier type ⟨_⟩ : Group → Type ℓ ⟨_⟩ = Group.Carrier makeIsGroup : {G : Type ℓ} {0g : G} {_+_ : G → G → G} { -_ : G → G} (is-setG : isSet G) (assoc : (x y z : G) → x + (y + z) ≡ (x + y) + z) (rid : (x : G) → x + 0g ≡ x) (lid : (x : G) → 0g + x ≡ x) (rinv : (x : G) → x + (- x) ≡ 0g) (linv : (x : G) → (- x) + x ≡ 0g) → IsGroup 0g _+_ -_ makeIsGroup is-setG assoc rid lid rinv linv = isgroup (makeIsMonoid is-setG assoc rid lid) λ x → rinv x , linv x makeGroup : {G : Type ℓ} (0g : G) (_+_ : G → G → G) (-_ : G → G) (is-setG : isSet G) (assoc : (x y z : G) → x + (y + z) ≡ (x + y) + z) (rid : (x : G) → x + 0g ≡ x) (lid : (x : G) → 0g + x ≡ x) (rinv : (x : G) → x + (- x) ≡ 0g) (linv : (x : G) → (- x) + x ≡ 0g) → Group makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv = group _ 0g _+_ -_ (makeIsGroup is-setG assoc rid lid rinv linv) makeGroup-right : ∀ {ℓ} {A : Type ℓ} → (id : A) → (comp : A → A → A) → (inv : A → A) → (set : isSet A) → (assoc : ∀ a b c → comp a (comp b c) ≡ comp (comp a b) c) → (rUnit : ∀ a → comp a id ≡ a) → (rCancel : ∀ a → comp a (inv a) ≡ id) → Group makeGroup-right {A = A} id comp inv set assoc rUnit rCancel = makeGroup id comp inv set assoc rUnit lUnit rCancel lCancel where _⨀_ = comp abstract lCancel : ∀ a → comp (inv a) a ≡ id lCancel a = inv a ⨀ a ≡⟨ sym (rUnit (comp (inv a) a)) ⟩ (inv a ⨀ a) ⨀ id ≡⟨ cong (comp (comp (inv a) a)) (sym (rCancel (inv a))) ⟩ (inv a ⨀ a) ⨀ (inv a ⨀ (inv (inv a))) ≡⟨ assoc _ _ _ ⟩ ((inv a ⨀ a) ⨀ (inv a)) ⨀ (inv (inv a)) ≡⟨ cong (λ □ → □ ⨀ _) (sym (assoc _ _ _)) ⟩ (inv a ⨀ (a ⨀ inv a)) ⨀ (inv (inv a)) ≡⟨ cong (λ □ → (inv a ⨀ □) ⨀ (inv (inv a))) (rCancel a) ⟩ (inv a ⨀ id) ⨀ (inv (inv a)) ≡⟨ cong (λ □ → □ ⨀ (inv (inv a))) (rUnit (inv a)) ⟩ inv a ⨀ (inv (inv a)) ≡⟨ rCancel (inv a) ⟩ id ∎ lUnit : ∀ a → comp id a ≡ a lUnit a = id ⨀ a ≡⟨ cong (λ b → comp b a) (sym (rCancel a)) ⟩ (a ⨀ inv a) ⨀ a ≡⟨ sym (assoc _ _ _) ⟩ a ⨀ (inv a ⨀ a) ≡⟨ cong (comp a) (lCancel a) ⟩ a ⨀ id ≡⟨ rUnit a ⟩ a ∎ makeGroup-left : ∀ {ℓ} {A : Type ℓ} → (id : A) → (comp : A → A → A) → (inv : A → A) → (set : isSet A) → (assoc : ∀ a b c → comp a (comp b c) ≡ comp (comp a b) c) → (lUnit : ∀ a → comp id a ≡ a) → (lCancel : ∀ a → comp (inv a) a ≡ id) → Group makeGroup-left {A = A} id comp inv set assoc lUnit lCancel = makeGroup id comp inv set assoc rUnit lUnit rCancel lCancel where abstract rCancel : ∀ a → comp a (inv a) ≡ id rCancel a = comp a (inv a) ≡⟨ sym (lUnit (comp a (inv a))) ⟩ comp id (comp a (inv a)) ≡⟨ cong (λ b → comp b (comp a (inv a))) (sym (lCancel (inv a))) ⟩ comp (comp (inv (inv a)) (inv a)) (comp a (inv a)) ≡⟨ sym (assoc (inv (inv a)) (inv a) (comp a (inv a))) ⟩ comp (inv (inv a)) (comp (inv a) (comp a (inv a))) ≡⟨ cong (comp (inv (inv a))) (assoc (inv a) a (inv a)) ⟩ comp (inv (inv a)) (comp (comp (inv a) a) (inv a)) ≡⟨ cong (λ b → comp (inv (inv a)) (comp b (inv a))) (lCancel a) ⟩ comp (inv (inv a)) (comp id (inv a)) ≡⟨ cong (comp (inv (inv a))) (lUnit (inv a)) ⟩ comp (inv (inv a)) (inv a) ≡⟨ lCancel (inv a) ⟩ id ∎ rUnit : ∀ a → comp a id ≡ a rUnit a = comp a id ≡⟨ cong (comp a) (sym (lCancel a)) ⟩ comp a (comp (inv a) a) ≡⟨ assoc a (inv a) a ⟩ comp (comp a (inv a)) a ≡⟨ cong (λ b → comp b a) (rCancel a) ⟩ comp id a ≡⟨ lUnit a ⟩ a ∎
{ "alphanum_fraction": 0.4484982866, "avg_line_length": 29.8855421687, "ext": "agda", "hexsha": "e996e9b35833411d5e92c42d8669c30d9788140f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "RobertHarper/cubical", "max_forks_repo_path": "Cubical/Structures/Group/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "RobertHarper/cubical", "max_issues_repo_path": "Cubical/Structures/Group/Base.agda", "max_line_length": 75, "max_stars_count": null, "max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "RobertHarper/cubical", "max_stars_repo_path": "Cubical/Structures/Group/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2019, "size": 4961 }
module Data.Maybe where data Maybe (a : Set) : Set where nothing : Maybe a just : a -> Maybe a fmap : {A B : Set} -> (A -> B) -> Maybe A -> Maybe B fmap f nothing = nothing fmap f (just a) = just (f a )
{ "alphanum_fraction": 0.5720930233, "avg_line_length": 17.9166666667, "ext": "agda", "hexsha": "112f1e11017eb55cef4a4fa14893565c8ac31e9d", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "examples/lib/Data/Maybe.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "examples/lib/Data/Maybe.agda", "max_line_length": 52, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "examples/lib/Data/Maybe.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 75, "size": 215 }
module imper-repeat where open import lib open import eq-reasoning data Singleton {a} {A : Set a} (x : A) : Set a where _with≡_ : (y : A) → x ≡ y → Singleton x inspect : ∀ {a} {A : Set a} (x : A) → Singleton x inspect x = x with≡ refl -- Unicode notes. I use: -- \Mix, \Mie, \MiF etc for meta-variables 𝑥, 𝑒, 𝐹 etc. -- \mapsto for variable frame bindings and update. -- \| for the frame update operation. -- \|- turnstile ⊢ is used for the semantics relations. -- (\|-n for its negation ⊬) -- \d= for code literal values e.g. ⇓ 42 and ⇓true -- The down arrow is also used for the eval relation. -- \u= for code variable lookups like ⇑ "x" and ⇑ "y" -- superscripts of items with \^e as ᵉ, \c^c as ᶜ -- ↩ for sequencing. This is \lefthookarrow. -- ∷= which is \:: followed by = -- -- variable identifiers -- Id : Set Id = string _=Id_ : Id → Id → 𝔹 _=Id_ = _=string_ -- -- values (just natural numbers here) -- Val : Set Val = ℕ -- -- value and variable expressions -- data Expn : Set where ⇓_ : Val → Expn ⇑_ : Id → Expn _+ᵉ_ : Expn → Expn → Expn _-ᵉ_ : Expn → Expn → Expn _*ᵉ⇓_ : Expn → Val → Expn -- -- conditions on values and variables -- data Cond : Set where ⇓true : Cond ⇓false : Cond _∧ᶜ_ : Cond → Cond → Cond _∨ᶜ_ : Cond → Cond → Cond ¬ᶜ_ : Cond → Cond [_<ᶜ_] : Expn → Expn → Cond [_=ᶜ_] : Expn → Expn → Cond -- -- stack frames containing variable bindings -- Frm : Set Frm = 𝕃 (Id × Val) [_↦_] : Id → Val → Frm [ 𝑥 ↦ 𝑣 ] = [(𝑥 , 𝑣)] [-↦0] : Frm [-↦0] = [] -- -- program statements that transform a frame -- data Stmt : Set where skip : Stmt _∷=_ : Id → Expn → Stmt _↩_ : Stmt → Stmt → Stmt if_then_else_end : Cond → Stmt → Stmt → Stmt by_repeat_end : Id → Stmt → Stmt returns_ : Expn → Stmt infix 10 ⇑_ ⇓_ infix 9 _*ᵉ⇓_ infixl 8 _+ᵉ_ _-ᵉ_ infix 7 ¬ᶜ_ infixl 6 _∨ᶜ_ infixl 5 _∧ᶜ_ infix 4 _∷=_ infix 3 returns_ infixl 2 _↩_ -- -- functional SEMANTICS of frames -- _∥_ : Frm → Id → Val [] ∥ 𝑥 = 0 ((𝑦 , 𝑤) :: 𝐹) ∥ 𝑥 = if (𝑥 =Id 𝑦) then 𝑤 else (𝐹 ∥ 𝑥) _∣_↦_ : Frm → Id → Val → Frm [] ∣ 𝑥 ↦ 𝑣 = [ 𝑥 ↦ 𝑣 ] ((𝑦 , 𝑤) :: 𝐹) ∣ 𝑥 ↦ 𝑣 = if (𝑥 =Id 𝑦) then (𝑦 , 𝑣) :: 𝐹 else (𝑦 , 𝑤) :: (𝐹 ∣ 𝑥 ↦ 𝑣) -- -- functional SEMANTICS of expressions -- ⟦_⟧ᵉ_ : Expn → Frm → Val ⟦ ⇓ 𝑣 ⟧ᵉ _ = 𝑣 ⟦ ⇑ 𝑥 ⟧ᵉ 𝐹 = 𝐹 ∥ 𝑥 ⟦ 𝑒₁ +ᵉ 𝑒₂ ⟧ᵉ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) + (⟦ 𝑒₂ ⟧ᵉ 𝐹) ⟦ 𝑒₁ -ᵉ 𝑒₂ ⟧ᵉ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) ∸ (⟦ 𝑒₂ ⟧ᵉ 𝐹) ⟦ 𝑒₁ *ᵉ⇓ 𝑣₂ ⟧ᵉ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) * 𝑣₂ -- -- functional SEMANTICS of conditions -- ⟦_⟧ᶜ_ : Cond → Frm → 𝔹 ⟦ ⇓true ⟧ᶜ _ = tt ⟦ ⇓false ⟧ᶜ _ = ff ⟦ 𝒸₁ ∧ᶜ 𝒸₂ ⟧ᶜ 𝐹 = (⟦ 𝒸₁ ⟧ᶜ 𝐹) && (⟦ 𝒸₂ ⟧ᶜ 𝐹) ⟦ 𝒸₁ ∨ᶜ 𝒸₂ ⟧ᶜ 𝐹 = (⟦ 𝒸₁ ⟧ᶜ 𝐹) || (⟦ 𝒸₂ ⟧ᶜ 𝐹) ⟦ ¬ᶜ 𝒸 ⟧ᶜ 𝐹 = ~ (⟦ 𝒸 ⟧ᶜ 𝐹) ⟦ [ 𝑒₁ <ᶜ 𝑒₂ ] ⟧ᶜ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) < (⟦ 𝑒₂ ⟧ᵉ 𝐹) ⟦ [ 𝑒₁ =ᶜ 𝑒₂ ] ⟧ᶜ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) =ℕ (⟦ 𝑒₂ ⟧ᵉ 𝐹) -- -- functional SEMANTICS of program execution -- ⟦_∣_∷=_…0⟧ˢ_ : Stmt → Id → ℕ → Frm → Frm ⟦_⟧ˢ_ : Stmt → Frm → Frm ⟦ 𝑠 ∣ 𝑥 ∷= 0 …0⟧ˢ 𝐹 = 𝐹 ⟦ 𝑠 ∣ 𝑥 ∷= (suc 𝑛) …0⟧ˢ 𝐹 = ⟦ 𝑠 ∣ 𝑥 ∷= 𝑛 …0⟧ˢ ((⟦ 𝑠 ⟧ˢ 𝐹) ∣ 𝑥 ↦ 𝑛) ⟦ skip ⟧ˢ 𝐹 = 𝐹 ⟦ 𝑥 ∷= 𝑒 ⟧ˢ 𝐹 = (𝐹 ∣ 𝑥 ↦ (⟦ 𝑒 ⟧ᵉ 𝐹)) ⟦ 𝑠₁ ↩ 𝑠₂ ⟧ˢ 𝐹 = (⟦ 𝑠₂ ⟧ˢ (⟦ 𝑠₁ ⟧ˢ 𝐹)) ⟦ if 𝒸 then 𝑠₁ else 𝑠₂ end ⟧ˢ 𝐹 = if (⟦ 𝒸 ⟧ᶜ 𝐹) then (⟦ 𝑠₁ ⟧ˢ 𝐹) else (⟦ 𝑠₂ ⟧ˢ 𝐹) ⟦ by 𝑥 repeat 𝑠 end ⟧ˢ 𝐹 = ⟦ 𝑠 ∣ 𝑥 ∷= (⟦ ⇑ 𝑥 ⟧ᵉ 𝐹) …0⟧ˢ 𝐹 ⟦ returns 𝑒 ⟧ˢ 𝐹 = 𝐹 ∣ "retval" ↦ (⟦ 𝑒 ⟧ᵉ 𝐹) -- -- SEMANTICS of stack bindings as a relation -- infixl 7 _⊢ᶠ_↦_ infixl 5 _∣_↦_ infixl 4 _⊢ᵉ_⇓_ infixl 3 _⊢ᶜ_ _⊬ᶜ_ -- _↦_ data _⊢ᶠ_↦_ : Frm → Id → Val → Set where var-undef : ∀ {𝑥 : Id} ---------------- → [] ⊢ᶠ 𝑥 ↦ 0 var-match : ∀ {𝑥 𝑦 : Id} {𝐹 : Frm} {𝑤 : Val} → (𝑥 =string 𝑦) ≡ tt --------------------------- → ((𝑦 , 𝑤) :: 𝐹) ⊢ᶠ 𝑥 ↦ 𝑤 var-mismatch : ∀ {𝑥 𝑦 : Id} {𝐹 : Frm} {𝑣 𝑤 : Val} → (𝑥 =string 𝑦) ≡ ff → 𝐹 ⊢ᶠ 𝑥 ↦ 𝑣 ------------------------- → ((𝑦 , 𝑤) :: 𝐹) ⊢ᶠ 𝑥 ↦ 𝑣 if-tt-then : ∀{A : Set} {b : 𝔹} {a1 a2 : A} → b ≡ tt → if b then a1 else a2 ≡ a1 if-tt-then{A}{b}{a1}{a2} b≡tt = begin if b then a1 else a2 ≡⟨ cong3 if_then_else_ b≡tt refl refl ⟩ if tt then a1 else a2 ≡⟨ refl ⟩ a1 ∎ postulate if-ff-then : ∀{A : Set}{b : 𝔹}{a1 a2 : A} → b ≡ ff → if b then a1 else a2 ≡ a2 var-thm-fwd : ∀{x : Id}{F : Frm}{v : Val} → F ⊢ᶠ x ↦ v → F ∥ x ≡ v var-thm-fwd{x}{[]}{0} var-undef = begin [] ∥ x ≡⟨ refl ⟩ 0 ∎ var-thm-fwd (var-match{x}{y}{F}{w} x≡y) = begin ((y , w) :: F) ∥ x ≡⟨ refl ⟩ if (x =Id y) then w else (F ∥ x) ≡⟨ if-tt-then x≡y ⟩ w ∎ var-thm-fwd (var-mismatch{x}{y}{F}{v}{w} x≢y x↦v) = let F∥x≡v : F ∥ x ≡ v F∥x≡v = var-thm-fwd x↦v in begin ((y , w) :: F) ∥ x ≡⟨ refl ⟩ if (x =Id y) then w else (F ∥ x) ≡⟨ if-ff-then x≢y ⟩ F ∥ x ≡⟨ F∥x≡v ⟩ v ∎ var-thm-rev : ∀{x : Id}{F : Frm}{v : Val} → F ∥ x ≡ v → F ⊢ᶠ x ↦ v var-thm-rev{x}{[]}{v} []∥x≡v = let v≡0 : v ≡ 0 v≡0 = begin v ≡⟨ sym []∥x≡v ⟩ [] ∥ x ≡⟨ refl ⟩ 0 ∎ in cong-pred (λ xxx → [] ⊢ᶠ x ↦ xxx) (sym v≡0) var-undef var-thm-rev{x}{(y , w) :: F}{v} y,w::F∥x≡v with inspect (x =string y) ... | tt with≡ same = let v≡w : v ≡ w v≡w = begin v ≡⟨ sym y,w::F∥x≡v ⟩ ((y , w) :: F) ∥ x ≡⟨ refl ⟩ if x =string y then w else F ∥ x ≡⟨ cong3 if_then_else_ same refl refl ⟩ if tt then w else F ∥ x ≡⟨ refl ⟩ w ∎ in cong-pred (λ xxx → ((y , w) :: F) ⊢ᶠ x ↦ xxx) (sym v≡w) (var-match same) ... | ff with≡ diff = let v≡F∥x : v ≡ F ∥ x v≡F∥x = begin v ≡⟨ sym y,w::F∥x≡v ⟩ ((y , w) :: F) ∥ x ≡⟨ refl ⟩ if x =string y then w else F ∥ x ≡⟨ cong3 if_then_else_ diff refl refl ⟩ if ff then w else F ∥ x ≡⟨ refl ⟩ F ∥ x ∎ in (var-mismatch diff (var-thm-rev (sym v≡F∥x))) -- -- SEMANTICS of expression evaluation as a relation -- data _⊢ᵉ_⇓_ : Frm → Expn → Val → Set where e-val : ∀ {𝑣 : Val} {𝐹 : Frm} ---------------- → 𝐹 ⊢ᵉ (⇓ 𝑣) ⇓ 𝑣 e-var : ∀ {𝑥 : Id} {𝐹 : Frm} {𝑣 : Val} → 𝐹 ⊢ᶠ 𝑥 ↦ 𝑣 --------------- → 𝐹 ⊢ᵉ (⇑ 𝑥) ⇓ 𝑣 e-add : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val} → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ → 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂ --------------------------- → 𝐹 ⊢ᵉ (𝑒₁ +ᵉ 𝑒₂) ⇓ (𝑣₁ + 𝑣₂) e-sub : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val} → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ → 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂ --------------------------- → 𝐹 ⊢ᵉ (𝑒₁ -ᵉ 𝑒₂) ⇓ (𝑣₁ ∸ 𝑣₂) e-scale : ∀ {𝑒₁ : Expn} {𝑣₁ 𝑣₂ : Val} {𝐹 : Frm} → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ --------------------------- → 𝐹 ⊢ᵉ ( 𝑒₁ *ᵉ⇓ 𝑣₂) ⇓ (𝑣₁ * 𝑣₂) e-thm-fwd : ∀{𝑒 : Expn}{𝐹 : Frm}{𝑣 : Val} → (𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣) → ((⟦ 𝑒 ⟧ᵉ 𝐹) ≡ 𝑣) e-thm-fwd (e-val{v}{F}) = begin ⟦ ⇓ v ⟧ᵉ F ≡⟨ refl ⟩ v ∎ e-thm-fwd (e-var{x}{F}{v} x↦v) = begin ⟦ ⇑ x ⟧ᵉ F ≡⟨ var-thm-fwd x↦v ⟩ v ∎ e-thm-fwd (e-add{e1}{e2}{F}{v1}{v2} e1⇓v1 e2⇓v2) = let ⟦e1⟧≡v1 = e-thm-fwd e1⇓v1 ⟦e2⟧≡v2 = e-thm-fwd e2⇓v2 in begin ⟦ e1 +ᵉ e2 ⟧ᵉ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F + ⟦ e2 ⟧ᵉ F ≡⟨ cong2 _+_ ⟦e1⟧≡v1 ⟦e2⟧≡v2 ⟩ v1 + v2 ∎ e-thm-fwd (e-sub{e1}{e2}{F}{v1}{v2} e1⇓v1 e2⇓v2) = let ⟦e1⟧≡v1 = e-thm-fwd e1⇓v1 ⟦e2⟧≡v2 = e-thm-fwd e2⇓v2 in begin ⟦ e1 -ᵉ e2 ⟧ᵉ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F ∸ ⟦ e2 ⟧ᵉ F ≡⟨ cong2 _∸_ ⟦e1⟧≡v1 ⟦e2⟧≡v2 ⟩ v1 ∸ v2 ∎ e-thm-fwd (e-scale{e1}{v1}{v2}{F} e1⇓v1) = let ⟦e1⟧≡v1 = e-thm-fwd e1⇓v1 in begin ⟦ e1 *ᵉ⇓ v2 ⟧ᵉ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F * v2 ≡⟨ cong2 _*_ ⟦e1⟧≡v1 refl ⟩ v1 * v2 ∎ e-thm-rev : ∀{𝑒 : Expn}{𝐹 : Frm}{𝑣 : Val} → ((⟦ 𝑒 ⟧ᵉ 𝐹) ≡ 𝑣) → (𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣) e-thm-rev{e}{F}{v} ⟦e⟧F≡v with e ... | ⇓ w = cong-pred (λ xxx → F ⊢ᵉ (⇓ w) ⇓ xxx) ⟦e⟧F≡v e-val ... | ⇑ x = let v≡F∥x : v ≡ F ∥ x v≡F∥x = begin v ≡⟨ sym ⟦e⟧F≡v ⟩ ⟦ ⇑ x ⟧ᵉ F ≡⟨ refl ⟩ F ∥ x ∎ in e-var (var-thm-rev (sym v≡F∥x)) ... | e1 +ᵉ e2 = {!!} ... | e1 -ᵉ e2 = {!!} ... | e1 *ᵉ⇓ v2 = {!!} -- -- SEMANTICS of conditions as a decidable relation -- data _⊢ᶜ_ : Frm → Cond → Set data _⊬ᶜ_ : Frm → Cond → Set data _⊢ᶜ_ where c-tt : ∀ {𝐹 : Frm} ----------- → 𝐹 ⊢ᶜ ⇓true c-and : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm} → 𝐹 ⊢ᶜ 𝒸₁ → 𝐹 ⊢ᶜ 𝒸₂ ----------------- → 𝐹 ⊢ᶜ (𝒸₁ ∧ᶜ 𝒸₂) c-or₁ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm} → 𝐹 ⊢ᶜ 𝒸₁ --------------- → 𝐹 ⊢ᶜ (𝒸₁ ∨ᶜ 𝒸₂) c-or₂ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm} → 𝐹 ⊢ᶜ 𝒸₂ ---------------- → 𝐹 ⊢ᶜ (𝒸₁ ∨ᶜ 𝒸₂) c-less : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val} → 𝑣₁ < 𝑣₂ ≡ tt → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ → 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂ ------------------- → 𝐹 ⊢ᶜ [ 𝑒₁ <ᶜ 𝑒₂ ] c-eq : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val} → 𝑣₁ =ℕ 𝑣₂ ≡ tt → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ → 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂ ------------------- → 𝐹 ⊢ᶜ [ 𝑒₁ =ᶜ 𝑒₂ ] c-not : ∀ {𝒸 : Cond} {𝐹 : Frm} → 𝐹 ⊬ᶜ 𝒸 ------------- → 𝐹 ⊢ᶜ (¬ᶜ 𝒸) data _⊬ᶜ_ where ~c-ff : ∀ {𝐹 : Frm} -------------- → 𝐹 ⊬ᶜ ⇓false ~c-or : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm} → 𝐹 ⊬ᶜ 𝒸₁ → 𝐹 ⊬ᶜ 𝒸₂ ---------------- → 𝐹 ⊬ᶜ (𝒸₁ ∨ᶜ 𝒸₂) ~c-and₁ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm} → 𝐹 ⊬ᶜ 𝒸₁ ----------------- → 𝐹 ⊬ᶜ (𝒸₁ ∧ᶜ 𝒸₂) ~c-and₂ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm} → 𝐹 ⊬ᶜ 𝒸₂ ----------------- → 𝐹 ⊬ᶜ (𝒸₁ ∧ᶜ 𝒸₂) ~c-eq : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val} → 𝑣₁ =ℕ 𝑣₂ ≡ ff → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ → 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂ ------------------- → 𝐹 ⊬ᶜ [ 𝑒₁ =ᶜ 𝑒₂ ] ~c-less : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val} → 𝑣₁ < 𝑣₂ ≡ ff → 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁ → 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂ ------------------- → 𝐹 ⊬ᶜ [ 𝑒₁ <ᶜ 𝑒₂ ] ~c-not : ∀ {𝒸 : Cond} {𝐹 : Frm} → 𝐹 ⊢ᶜ 𝒸 ------------- → 𝐹 ⊬ᶜ (¬ᶜ 𝒸) test3 : [] ⊢ᶜ (⇓true ∧ᶜ (¬ᶜ ⇓false)) test3 = c-and c-tt (c-not ~c-ff) c-thm-fwd : ∀{𝒸 : Cond}{𝐹 : Frm} → 𝐹 ⊢ᶜ 𝒸 → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ tt) ~c-thm-fwd : ∀{𝒸 : Cond}{𝐹 : Frm} → 𝐹 ⊬ᶜ 𝒸 → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ ff) c-thm-fwd (c-tt{F}) = begin ⟦ ⇓true ⟧ᶜ F ≡⟨ refl ⟩ tt ∎ c-thm-fwd (c-and{c1}{c2}{F} dat1 dat2) = let ⟦c1⟧F≡tt : ⟦ c1 ⟧ᶜ F ≡ tt ⟦c1⟧F≡tt = c-thm-fwd dat1 ⟦c2⟧F≡tt : ⟦ c2 ⟧ᶜ F ≡ tt ⟦c2⟧F≡tt = c-thm-fwd dat2 in begin ⟦ c1 ∧ᶜ c2 ⟧ᶜ F ≡⟨ refl ⟩ (⟦ c1 ⟧ᶜ F) && (⟦ c2 ⟧ᶜ F) ≡⟨ cong2 _&&_ ⟦c1⟧F≡tt ⟦c2⟧F≡tt ⟩ tt && tt ≡⟨ refl ⟩ tt ∎ c-thm-fwd (c-or₁{c1}{c2}{F} dat1) = let ⟦c1⟧F≡tt : ⟦ c1 ⟧ᶜ F ≡ tt ⟦c1⟧F≡tt = c-thm-fwd dat1 in begin ⟦ c1 ∨ᶜ c2 ⟧ᶜ F ≡⟨ refl ⟩ (⟦ c1 ⟧ᶜ F) || (⟦ c2 ⟧ᶜ F) ≡⟨ cong2 _||_ ⟦c1⟧F≡tt refl ⟩ tt || (⟦ c2 ⟧ᶜ F) ≡⟨ refl ⟩ tt ∎ c-thm-fwd (c-or₂{c1}{c2}{F} dat2) = let ⟦c2⟧F≡tt : ⟦ c2 ⟧ᶜ F ≡ tt ⟦c2⟧F≡tt = c-thm-fwd dat2 in begin ⟦ c1 ∨ᶜ c2 ⟧ᶜ F ≡⟨ refl ⟩ (⟦ c1 ⟧ᶜ F) || (⟦ c2 ⟧ᶜ F) ≡⟨ cong2 _||_ refl ⟦c2⟧F≡tt ⟩ (⟦ c1 ⟧ᶜ F) || tt ≡⟨ ||-tt (⟦ c1 ⟧ᶜ F) ⟩ tt ∎ c-thm-fwd (c-less{e1}{e2}{F}{v1}{v2} v1<v2 e1⇓v1 e2⇓v2) = let ⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1 ⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1 ⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2 ⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2 in begin ⟦ [ e1 <ᶜ e2 ] ⟧ᶜ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F < ⟦ e2 ⟧ᵉ F ≡⟨ cong2 _<_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩ v1 < v2 ≡⟨ v1<v2 ⟩ tt ∎ c-thm-fwd (c-eq{e1}{e2}{F}{v1}{v2} v1≡v2 e1⇓v1 e2⇓v2) = let ⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1 ⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1 ⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2 ⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2 in begin ⟦ [ e1 =ᶜ e2 ] ⟧ᶜ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F =ℕ ⟦ e2 ⟧ᵉ F ≡⟨ cong2 _=ℕ_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩ v1 =ℕ v2 ≡⟨ v1≡v2 ⟩ tt ∎ c-thm-fwd (c-not{c}{F} dat) = let ⟦c⟧F≡ff : ⟦ c ⟧ᶜ F ≡ ff ⟦c⟧F≡ff = ~c-thm-fwd dat in begin begin ⟦ ¬ᶜ c ⟧ᶜ F ≡⟨ refl ⟩ ~ ⟦ c ⟧ᶜ F ≡⟨ cong ~_ ⟦c⟧F≡ff ⟩ ~ ff ≡⟨ refl ⟩ tt ∎ ~c-thm-fwd (~c-ff{F}) = begin ⟦ ⇓false ⟧ᶜ F ≡⟨ refl ⟩ ff ∎ ~c-thm-fwd (~c-or{c1}{c2}{F} dat1 dat2) = let ⟦c1⟧F≡ff : ⟦ c1 ⟧ᶜ F ≡ ff ⟦c1⟧F≡ff = ~c-thm-fwd dat1 ⟦c2⟧F≡ff : ⟦ c2 ⟧ᶜ F ≡ ff ⟦c2⟧F≡ff = ~c-thm-fwd dat2 in begin ⟦ c1 ∨ᶜ c2 ⟧ᶜ F ≡⟨ refl ⟩ (⟦ c1 ⟧ᶜ F) || (⟦ c2 ⟧ᶜ F) ≡⟨ cong2 _||_ ⟦c1⟧F≡ff ⟦c2⟧F≡ff ⟩ ff || ff ≡⟨ refl ⟩ ff ∎ ~c-thm-fwd (~c-and₁{c1}{c2}{F} dat1) = let ⟦c1⟧F≡ff : ⟦ c1 ⟧ᶜ F ≡ ff ⟦c1⟧F≡ff = ~c-thm-fwd dat1 in begin ⟦ c1 ∧ᶜ c2 ⟧ᶜ F ≡⟨ refl ⟩ (⟦ c1 ⟧ᶜ F) && (⟦ c2 ⟧ᶜ F) ≡⟨ cong2 _&&_ ⟦c1⟧F≡ff refl ⟩ ff && (⟦ c2 ⟧ᶜ F) ≡⟨ refl ⟩ ff ∎ ~c-thm-fwd (~c-and₂{c1}{c2}{F} dat2) = let ⟦c2⟧F≡ff : ⟦ c2 ⟧ᶜ F ≡ ff ⟦c2⟧F≡ff = ~c-thm-fwd dat2 in begin begin ⟦ c1 ∧ᶜ c2 ⟧ᶜ F ≡⟨ refl ⟩ (⟦ c1 ⟧ᶜ F) && (⟦ c2 ⟧ᶜ F) ≡⟨ cong2 _&&_ refl ⟦c2⟧F≡ff ⟩ (⟦ c1 ⟧ᶜ F) && ff ≡⟨ &&-ff (⟦ c1 ⟧ᶜ F) ⟩ ff ∎ ~c-thm-fwd (~c-less{e1}{e2}{F}{v1}{v2} v1≮v2 e1⇓v1 e2⇓v2) = let ⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1 ⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1 ⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2 ⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2 in begin ⟦ [ e1 <ᶜ e2 ] ⟧ᶜ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F < ⟦ e2 ⟧ᵉ F ≡⟨ cong2 _<_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩ v1 < v2 ≡⟨ v1≮v2 ⟩ ff ∎ ~c-thm-fwd (~c-eq{e1}{e2}{F}{v1}{v2} v1≢v2 e1⇓v1 e2⇓v2) = let ⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1 ⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1 ⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2 ⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2 in begin ⟦ [ e1 =ᶜ e2 ] ⟧ᶜ F ≡⟨ refl ⟩ ⟦ e1 ⟧ᵉ F =ℕ ⟦ e2 ⟧ᵉ F ≡⟨ cong2 _=ℕ_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩ v1 =ℕ v2 ≡⟨ v1≢v2 ⟩ ff ∎ ~c-thm-fwd (~c-not{c}{F} ⊢c) = begin ⟦ ¬ᶜ c ⟧ᶜ F ≡⟨ refl ⟩ ~ ⟦ c ⟧ᶜ F ≡⟨ cong ~_ (c-thm-fwd ⊢c) ⟩ ~ tt ≡⟨ refl ⟩ ff ∎ -- These can probably be shown just by using -- the contrapositives of c-thm-fwd and ~c-thm-fwd postulate c-thm-rev : ∀{𝒸 : Cond}{𝐹 : Frm} → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ tt) → 𝐹 ⊢ᶜ 𝒸 ~c-thm-rev : ∀{𝒸 : Cond}{𝐹 : Frm} → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ ff) → 𝐹 ⊬ᶜ 𝒸 -- -- SEMANTICS of program statements -- as a state transformation relation -- data _=[_]⇒_ : Frm → Stmt → Frm → Set where s-skip : ∀ {𝐹 : Frm} -------------- → 𝐹 =[ skip ]⇒ 𝐹 s-assign : ∀ {𝑥 : Id} {𝑒 : Expn} {𝐹 : Frm} {𝑣 : Val} → 𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣 --------------------------- → 𝐹 =[ 𝑥 ∷= 𝑒 ]⇒ (𝐹 ∣ 𝑥 ↦ 𝑣) s-seq : ∀ {𝑠₁ 𝑠₂ : Stmt} {𝐹₀ 𝐹₁ 𝐹₂ : Frm} → 𝐹₀ =[ 𝑠₁ ]⇒ 𝐹₁ → 𝐹₁ =[ 𝑠₂ ]⇒ 𝐹₂ ------------------- → 𝐹₀ =[ 𝑠₁ ↩ 𝑠₂ ]⇒ 𝐹₂ s-if-then : ∀ {𝒸 : Cond} {𝑠₁ 𝑠₂ : Stmt} {𝐹 𝐹' : Frm} → 𝐹 ⊢ᶜ 𝒸 → 𝐹 =[ 𝑠₁ ]⇒ 𝐹' → 𝐹 =[ 𝑠₂ ]⇒ 𝐹' ------------------------------------ → 𝐹 =[ if 𝒸 then 𝑠₁ else 𝑠₂ end ]⇒ 𝐹' s-if-else : ∀ {𝒸 : Cond} {𝑠₁ 𝑠₂ : Stmt} {𝐹 𝐹' : Frm} → 𝐹 ⊬ᶜ 𝒸 → 𝐹 =[ 𝑠₂ ]⇒ 𝐹' ------------------------------------ → 𝐹 =[ if 𝒸 then 𝑠₁ else 𝑠₂ end ]⇒ 𝐹' s-repeat-0 : ∀ {𝑠 : Stmt} {𝑥 : Id} {𝐹 : Frm} → 𝐹 ⊢ᶠ 𝑥 ↦ 0 ----------------------------- → 𝐹 =[ by 𝑥 repeat 𝑠 end ]⇒ 𝐹 s-repeat-suc : ∀ {𝑛 : ℕ} {𝑠 : Stmt} {𝑥 : Id} {𝐹 𝐹' : Frm} → 𝐹 ⊢ᶠ 𝑥 ↦ suc 𝑛 → 𝐹 =[ 𝑠 ↩ 𝑥 ∷= (⇓ 𝑛) ↩ by 𝑥 repeat 𝑠 end ]⇒ 𝐹' ---------------------------------------------- → 𝐹 =[ by 𝑥 repeat 𝑠 end ]⇒ 𝐹' -- -- A lil cheat: "returns" is just assign; doesn't exit s-return : ∀ {𝑒 : Expn} {𝐹 : Frm} {𝑣 : Val} → 𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣 ------------------------------------- → 𝐹 =[ returns 𝑒 ]⇒ (𝐹 ∣ "retval" ↦ 𝑣) arg1 : Id arg1 = "arg1" arg2 : Id arg2 = "arg2" retval : Id retval = "retval" W : Id W = "w" X : Id X = "x" Y : Id Y = "y" Z : Id Z = "z" pgm0 : Stmt pgm0 = X ∷= ⇓ 3 ↩ Y ∷= ⇓ 1 ↩ Y ∷= ⇑ Y *ᵉ⇓ 2 pgm1 : Stmt pgm1 = X ∷= ⇓ 3 ↩ Y ∷= ⇓ 1 ↩ by X repeat Y ∷= ⇑ Y *ᵉ⇓ 2 end Z∷=X*Y = W ∷= ⇑ X ↩ Z ∷= ⇓ 0 ↩ by W repeat Z ∷= ⇑ Z +ᵉ ⇑ Y end pgm2 = X ∷= ⇓ 3 ↩ Y ∷= ⇓ 1 ↩ by X repeat Z∷=X*Y ↩ Y ∷= ⇑ Z end fact-pgm : Stmt fact-pgm = X ∷= ⇑ arg1 ↩ Y ∷= ⇓ 1 ↩ by X repeat Z∷=X*Y ↩ Y ∷= ⇑ Z end ↩ returns ⇑ Y min-pgm : Stmt min-pgm = if [ ⇑ arg2 <ᶜ ⇑ arg1 ] then X ∷= ⇑ arg1 ↩ arg1 ∷= ⇑ arg2 ↩ arg2 ∷= ⇑ X else skip end result1 = ⟦ pgm1 ⟧ˢ [-↦0] result2 = ⟦ pgm2 ⟧ˢ [-↦0] [➊↦_] : Val → Frm [➊↦ 𝑣 ] = [-↦0] ∣ arg1 ↦ 𝑣 [➊↦_,➋↦_] : Val → Val → Frm [➊↦ 𝑣₁ ,➋↦ 𝑣₂ ] = (([-↦0] ∣ arg1 ↦ 𝑣₁) ∣ arg2 ↦ 𝑣₂ ) frame6 = ((((( [➊↦ 3 ] ∣ X ↦ 0) ∣ Y ↦ 6) ∣ W ↦ 0) ∣ Z ↦ 6) ∣ retval ↦ 6) postulate test6 : [➊↦ 3 ] =[ fact-pgm ]⇒ frame6 exec : Stmt → Frm exec 𝑠 = ⟦ 𝑠 ⟧ˢ [-↦0] exec1 : Stmt → Val → Frm exec1 𝑠 𝑣₁ = ⟦ 𝑠 ⟧ˢ [➊↦ 𝑣₁ ] exec2 : Stmt → Val → Val → Frm exec2 𝑠 𝑣₁ 𝑣₂ = ⟦ 𝑠 ⟧ˢ [➊↦ 𝑣₁ ,➋↦ 𝑣₂ ] test7 = exec2 min-pgm 7 5 test7a : (test7 ∥ arg1) ≡ 5 test7a = refl test7b : (test7 ∥ arg2) ≡ 7 test7b = refl postulate s-thm : ∀ {𝑠 : Stmt } {𝐹 : Frm} → 𝐹 =[ 𝑠 ]⇒ (⟦ 𝑠 ⟧ˢ 𝐹) postulate fact-thm : ∀ {n : ℕ} {𝐹 : Frm} → [➊↦ n ] =[ fact-pgm ]⇒ 𝐹 → 𝐹 ⊢ᶠ retval ↦ (factorial n)
{ "alphanum_fraction": 0.3871188763, "avg_line_length": 21.8379052369, "ext": "agda", "hexsha": "a18feb3bfc3e2f6b7410ed8b97baf02286935875", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JimFixGroupResearch/imper-ial", "max_forks_repo_path": "imper-repeat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JimFixGroupResearch/imper-ial", "max_issues_repo_path": "imper-repeat.agda", "max_line_length": 89, "max_stars_count": null, "max_stars_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JimFixGroupResearch/imper-ial", "max_stars_repo_path": "imper-repeat.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 10628, "size": 17514 }
{- Name: Bowornmet (Ben) Hudson --Progress and Preservation in Godel's T-- Progress: if e:τ, then either e val or ∃e' such that e=>e'. Preservation: if e:τ and e=>e', then e':τ. -} open import Preliminaries module Godel where -- nat and => data Typ : Set where nat : Typ _⇒_ : Typ → Typ → Typ ------------------------------------------ -- represent a context as a list of types Ctx = List Typ -- de Bruijn indices (for free variables) data _∈_ : Typ → Ctx → Set where i0 : ∀ {Γ τ} → τ ∈ (τ :: Γ) iS : ∀ {Γ τ τ1} → τ ∈ Γ → τ ∈ (τ1 :: Γ) ------------------------------------------ -- static semantics data _|-_ : Ctx → Typ → Set where var : ∀ {Γ τ} → (x : τ ∈ Γ) → Γ |- τ z : ∀ {Γ} → Γ |- nat suc : ∀ {Γ} → (e : Γ |- nat) → Γ |- nat rec : ∀ {Γ τ} → (e : Γ |- nat) → (e0 : Γ |- τ) → (e1 : (nat :: (τ :: Γ)) |- τ) → Γ |- τ lam : ∀ {Γ τ ρ} → (x : (ρ :: Γ) |- τ) → Γ |- (ρ ⇒ τ) app : ∀ {Γ τ1 τ2} → (e1 : Γ |- (τ2 ⇒ τ1)) → (e2 : Γ |- τ2) → Γ |- τ1 ------------------------------------------ -- renaming function rctx : Ctx → Ctx → Set rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ -- re: transferring variables in contexts lem1 : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ') lem1 d i0 = i0 lem1 d (iS x) = iS (d x) -- renaming lemma ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ ren (var x) d = var (d x) ren z d = z ren (suc e) d = suc (ren e d) ren (rec e e0 e1) d = rec (ren e d) (ren e0 d) (ren e1 (lem1(lem1 d))) ren (lam e) d = lam (ren e (lem1 d)) ren (app e1 e2) d = app (ren e1 d) (ren e2 d) ------------------------------------------ -- substitution sctx : Ctx → Ctx → Set sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ -- weakening a context wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2 wkn e = ren e iS -- weakening also works with substitution wkn-s : ∀ {Γ τ1 Γ'} → sctx Γ Γ' → sctx (τ1 :: Γ) Γ' wkn-s d = λ f → wkn (d f) wkn-r : ∀ {Γ τ1 Γ'} → rctx Γ Γ' → rctx (τ1 :: Γ) Γ' wkn-r d = λ x → iS (d x) -- lem2 (need a lemma for subst like we did for renaming) lem2 : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ') lem2 d i0 = var i0 lem2 d (iS i) = wkn (d i) -- another substitution lemma lem3 : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ) lem3 e i0 = e lem3 e (iS i) = var i -- one final lemma needed for the last stepping rule. Thank you Professor Licata! lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ)) lem4 e1 e2 i0 = e1 lem4 e1 e2 (iS i0) = e2 lem4 e1 e2 (iS (iS i)) = var i -- the 'real' substitution lemma (if (x : τ') :: Γ |- (e : τ) and Γ |- (e : τ') , then Γ |- e[x -> e'] : τ) subst : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ' |- τ → Γ |- τ subst d (var x) = d x subst d z = z subst d (suc e) = suc (subst d e) subst d (rec e e0 e1) = rec (subst d e) (subst d e0) (subst (lem2 (lem2 d)) e1) subst d (lam e) = lam (subst (lem2 d) e) subst d (app e1 e2) = app (subst d e1) (subst d e2) ------------------------------------------ -- closed values of L{nat,⇒} (when something is a value) -- recall that we use empty contexts when we work with dynamic semantics data val : ∀ {τ} → [] |- τ → Set where z-isval : val z suc-isval : (e : [] |- nat) → (val e) → val (suc e) lam-isval : ∀ {ρ τ} (e : (ρ :: []) |- τ) → val (lam e) ------------------------------------------ -- stepping rules (preservation is folded into this) -- Preservation: if e:τ and e=>e', then e':τ data _>>_ : ∀ {τ} → [] |- τ → [] |- τ → Set where suc-steps : (e e' : [] |- nat) → e >> e' → (suc e) >> (suc e') app-steps : ∀ {τ1 τ2} → (e1 e1' : [] |- (τ2 ⇒ τ1)) → (e2 : [] |- τ2) → e1 >> e1' → (app e1 e2) >> (app e1' e2) app-steps-2 : ∀ {τ1 τ2} → (e1 : [] |- (τ2 ⇒ τ1)) → (e2 e2' : [] |- τ2) → val e1 → e2 >> e2' → (app e1 e2) >> (app e1 e2') app-steps-3 : ∀ {τ1 τ2} → (e1 : (τ1 :: []) |- τ2) → (e2 : [] |- τ1) → (app (lam e1) e2) >> subst (lem3 e2) e1 rec-steps : ∀ {τ} → (e e' : [] |- nat) → (e0 : [] |- τ) → (e1 : (nat :: (τ :: [])) |- τ) → e >> e' → (rec e e0 e1) >> (rec e' e0 e1) rec-steps-z : ∀ {τ} → (e : val z) → (e0 : [] |- τ) → (e1 : (nat :: (τ :: [])) |- τ) → (rec z e0 e1) >> e0 rec-steps-suc : ∀ {τ} → (e : [] |- nat) → (e0 : [] |- τ) → (e1 : (nat :: (τ :: [])) |- τ) → val e → (rec (suc e) e0 e1) >> subst (lem4 e (rec e e0 e1)) e1 ------------------------------------------ -- Proof of progress! -- Progress: if e:τ, then either e val or ∃e' such that e=>e' progress : ∀ {τ} (e : [] |- τ) → Either (val e) (Σ (λ e' → (e >> e'))) progress (var ()) progress z = Inl z-isval progress (suc e) with progress e progress (suc e) | Inl d = Inl (suc-isval e d) progress (suc e) | Inr (e' , d) = Inr (suc e' , suc-steps e e' d) progress (rec e e1 e2) with progress e progress (rec .z e1 e2) | Inl z-isval = Inr (e1 , rec-steps-z z-isval e1 e2) progress (rec .(suc e) e1 e2) | Inl (suc-isval e d) = Inr (subst (lem4 e (rec e e1 e2)) e2 , rec-steps-suc e e1 e2 d) progress (rec e e1 e2) | Inr (e' , d) = Inr (rec e' e1 e2 , rec-steps e e' e1 e2 d) progress (lam e) = Inl (lam-isval e) progress (app e1 e2) with progress e1 progress (app .(lam e) e2) | Inl (lam-isval e) = Inr (subst (lem3 e2) e , app-steps-3 e e2) progress (app e1 e2) | Inr (e1' , d) = Inr (app e1' e2 , app-steps e1 e1' e2 d) ------------------------------------------ -- Denotational semantics -- interpreting a T type in Agda interp : Typ → Set interp nat = Nat interp (A ⇒ B) = interp A → interp B -- interpreting contexts interpC : Ctx → Set interpC [] = Unit interpC (A :: Γ) = interpC Γ × interp A -- helper function to look a variable up in an interpC gamma lookupC : ∀{Γ A} → (x : A ∈ Γ) → interpC Γ → interp A lookupC i0 (recur , return) = return lookupC (iS i) (recur , return) = lookupC i recur -- primitive recursion function corresponding to rec natrec : ∀{C : Set} → C → (Nat → C → C) → Nat → C natrec base step Z = base natrec base step (S n) = step n (natrec base step n) -- interpreting expressions in Godel's T as a function from the interpretation of the context to the interpretation of its corresponding type interpE : ∀{Γ τ} → Γ |- τ → (interpC Γ → interp τ) interpE (var x) d = lookupC x d interpE z d = Z interpE (suc e) d = S (interpE e d) interpE (rec e e0 e1) d = natrec (interpE e0 d) (λ n k → interpE e1 ((d , k) , n)) (interpE e d) interpE (lam e) d = λ x → interpE e (d , x) interpE (app e1 e2) d = interpE e1 d (interpE e2 d) helper : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ' helper d = λ x → d (iS x) helper-r : ∀ {Γ Γ' τ} → rctx Γ (τ :: Γ') → rctx Γ Γ' helper-r d = λ x → d (iS x) -- compositionality of functions interpS : ∀ {Γ Γ'} → sctx Γ Γ' → interpC Γ → interpC Γ' interpS {Γ} {[]} a b = <> interpS {Γ} {A :: Γ'} a b = interpS (helper a) b , interpE (a i0) b interpR : ∀ {Γ Γ'} → rctx Γ Γ' → interpC Γ → interpC Γ' interpR {Γ} {[]} a b = <> interpR {Γ} {A :: Γ'} a b = interpR (helper-r a) b , lookupC (a i0) b --lemmas for lambda case of interpR-lemma interpR-lemma-lemma-lemma : ∀ {Γ Γ' τ} → (x : interp τ) → (Θ : rctx Γ Γ') → (Θ' : interpC Γ) → (interpR Θ Θ') == interpR (wkn-r Θ) (Θ' , x) interpR-lemma-lemma-lemma {Γ} {[]} x Θ Θ' = Refl interpR-lemma-lemma-lemma {Γ} {A :: Γ'} x Θ Θ' = ap (λ h → h , lookupC (Θ i0) Θ') (interpR-lemma-lemma-lemma x (helper-r Θ) Θ') interpR-lemma-lemma : ∀ {Γ Γ' τ} → (x : interp τ) → (Θ : rctx Γ Γ') → (Θ' : interpC Γ) → (interpR Θ Θ' , x) == (interpR (lem1 Θ) (Θ' , x)) interpR-lemma-lemma {Γ} {[]} x Θ Θ' = Refl interpR-lemma-lemma {Γ} {A :: Γ'} x Θ Θ' = ap (λ h → h , x) (interpR-lemma-lemma-lemma x Θ Θ') interpR-lemma-lemma-rec : ∀ {Γ Γ' τ} → (x : interp nat) → (y : interp τ) → (Θ : rctx Γ Γ') → (Θ' : interpC Γ) → ((interpR Θ Θ' , y) , x) == interpR (lem1 (lem1 Θ)) ((Θ' , y) , x) interpR-lemma-lemma-rec x y Θ Θ' = interpR-lemma-lemma x (lem1 Θ) (Θ' , y) ∘ ap (λ h → h , x) (interpR-lemma-lemma y Θ Θ') interpR-lemma : ∀ {Γ Γ' τ} (e : Γ' |- τ) → (Θ : rctx Γ Γ') → (Θ' : interpC Γ) → (interpE e) (interpR Θ Θ') == (interpE (ren e Θ)) Θ' interpR-lemma (var i0) Θ Θ' = Refl interpR-lemma (var (iS x)) Θ Θ' = interpR-lemma (var x) (helper-r Θ) Θ' interpR-lemma z Θ Θ' = Refl interpR-lemma (suc e) Θ Θ' = ap S (interpR-lemma e Θ Θ') interpR-lemma {Γ} {Γ'} {τ} (rec e e1 e2) Θ Θ' = natrec (interpE e1 (interpR Θ Θ')) (λ n k → interpE e2 ((interpR Θ Θ' , k) , n)) (interpE e (interpR Θ Θ')) =⟨ ap (λ h → natrec h (λ n k → interpE e2 ((interpR Θ Θ' , k) , n)) (interpE e (interpR Θ Θ'))) (interpR-lemma e1 Θ Θ') ⟩ natrec (interpE (ren e1 Θ) Θ') (λ n k → interpE e2 ((interpR Θ Θ' , k) , n)) (interpE e (interpR Θ Θ')) =⟨ ap (λ h → natrec (interpE (ren e1 Θ) Θ') (λ n k → interpE e2 ((interpR Θ Θ' , k) , n)) h) (interpR-lemma e Θ Θ') ⟩ natrec (interpE (ren e1 Θ) Θ') (λ n k → interpE e2 ((interpR Θ Θ' , k) , n)) (interpE (ren e Θ) Θ') =⟨ ap (λ h → natrec (interpE (ren e1 Θ) Θ') h (interpE (ren e Θ) Θ')) (λ= (λ x → λ= (λ y → ap (λ h → interpE e2 h) (interpR-lemma-lemma-rec x y Θ Θ')))) ⟩ natrec (interpE (ren e1 Θ) Θ') (λ n k → interpE e2 (interpR (lem1 (lem1 Θ)) ((Θ' , k) , n))) (interpE (ren e Θ) Θ') =⟨ ap (λ h → natrec (interpE (ren e1 Θ) Θ') h (interpE (ren e Θ) Θ')) (λ= (λ x → λ= (λ y → interpR-lemma {nat :: τ :: Γ} {nat :: τ :: Γ'} e2 (lem1 (lem1 Θ)) ((Θ' , y) , x)))) ⟩ natrec (interpE (ren e1 Θ) Θ') (λ n k → interpE (ren e2 (lem1 (lem1 Θ))) ((Θ' , k) , n)) (interpE (ren e Θ) Θ') ∎ interpR-lemma {Γ} {Γ'} {ρ ⇒ τ} (lam e) Θ Θ' = interpE (lam e) (interpR Θ Θ') =⟨ Refl ⟩ (λ x → interpE e (interpR Θ Θ' , x)) =⟨ λ= (λ x → ap (λ h → interpE e h) (interpR-lemma-lemma x Θ Θ')) ⟩ (λ x → interpE e (interpR (lem1 Θ) (Θ' , x))) =⟨ λ= (λ x → interpR-lemma {ρ :: Γ} {ρ :: Γ'} e (lem1 Θ) (Θ' , x)) ⟩ ((λ x → interpE (ren e (lem1 Θ)) (Θ' , x)) ∎) interpR-lemma (app e1 e2) Θ Θ' = interpE (app e1 e2) (interpR Θ Θ') =⟨ Refl ⟩ interpE e1 (interpR Θ Θ') (interpE e2 (interpR Θ Θ')) =⟨ ap (λ x → x (interpE e2 (interpR Θ Θ'))) (interpR-lemma e1 Θ Θ') ⟩ interpE (ren e1 Θ) Θ' (interpE e2 (interpR Θ Θ')) =⟨ ap (λ x → interpE (ren e1 Θ) Θ' x) (interpR-lemma e2 Θ Θ') ⟩ interpE (ren e1 Θ) Θ' (interpE (ren e2 Θ) Θ') ∎ -- no proof is possible without the genius of Dan Licata mutual wkn-lemma : ∀ {Γ τ} (a : interp τ) → (Θ' : interpC Γ) → Θ' == interpR iS (Θ' , a) wkn-lemma a Θ' = interpR-lemma-lemma-lemma a (λ x → x) Θ' ∘ ! (mutual-lemma Θ') mutual-lemma : ∀ {Γ} (Θ' : interpC Γ) → interpR (λ x → x) Θ' == Θ' mutual-lemma {[]} Θ' = Refl mutual-lemma {A :: Γ} (Θ' , a) = ! (ap (λ h → h , a) (wkn-lemma a Θ')) interp-lemma2 : ∀ {Γ τ' Θ' τ} (a : interp τ) → (e : Γ |- τ') → interpE e Θ' == interpE (wkn e) (Θ' , a) interp-lemma2 {Γ} {τ'} {Θ'} a e = interpE e Θ' =⟨ ap (λ x → interpE e x) (wkn-lemma a Θ') ⟩ interpE e (interpR iS (Θ' , a)) =⟨ interpR-lemma e iS (Θ' , a) ⟩ interpE (ren e iS) (Θ' , a) ∎ interp-lemma : ∀ {Γ Γ' Θ' τ} (a : interp τ) → (Θ : sctx Γ Γ') → interpS Θ Θ' == interpS (wkn-s Θ) (Θ' , a) interp-lemma {Γ} {[]} a Θ = Refl interp-lemma {Γ} {A :: Γ'} a Θ = ap2 (λ x y → x , y) (interp-lemma a (helper Θ)) (interp-lemma2 a (Θ i0)) lemma : ∀ {Γ Γ' Θ' τ} (x : interp τ) → (Θ : sctx Γ Γ') → ((interpS Θ Θ') , x) == (interpS (lem2 Θ) (Θ' , x)) lemma x Θ = ap (λ y → y , x) (interp-lemma x Θ) lemma-c-lemma-lemma : ∀ {Γ Γ' τ} → (x : interp τ) → (Θ : sctx Γ Γ') → (Θ' : interpC Γ) → (interpS Θ Θ') == (interpS (wkn-s Θ) (Θ' , x)) lemma-c-lemma-lemma {Γ} {[]} x Θ Θ' = Refl lemma-c-lemma-lemma {Γ} {A :: Γ'} x Θ Θ' = ap2 (λ x₁ y → x₁ , y) (lemma-c-lemma-lemma x (helper Θ) Θ') (interp-lemma2 x (Θ i0)) lemma-c-lemma : ∀ {Γ Γ' τ} → (x : interp τ) → (Θ : sctx Γ Γ') → (Θ' : interpC Γ) → (interpS Θ Θ' , x) == (interpS (lem2 Θ) (Θ' , x)) lemma-c-lemma {Γ} {[]} x Θ Θ' = Refl lemma-c-lemma {Γ} {A :: Γ'} x Θ Θ' = ap (λ h → h , x) (lemma-c-lemma-lemma x Θ Θ') lemma-c-lemma-rec : ∀ {Γ Γ' τ} → (x : interp nat) → (y : interp τ) → (Θ : sctx Γ Γ') → (Θ' : interpC Γ) → ((interpS Θ Θ' , y) , x) == interpS (lem2 (lem2 Θ)) ((Θ' , y) , x) lemma-c-lemma-rec {Γ} {[]} x y Θ Θ' = Refl lemma-c-lemma-rec {Γ} {A :: Γ'} x y Θ Θ' = lemma-c-lemma x (lem2 Θ) (Θ' , y) ∘ ap (λ h → h , x) (lemma-c-lemma y Θ Θ') lemma-c : ∀ {Γ Γ' τ} (e : Γ' |- τ) → (Θ : sctx Γ Γ') → (Θ' : interpC Γ) → (interpE e) (interpS Θ Θ') == (interpE (subst Θ e)) Θ' lemma-c (var i0) b c = Refl lemma-c (var (iS x)) b c = lemma-c (var x) (helper b) c lemma-c z b c = Refl lemma-c (suc e) b c = ap S (lemma-c e b c) lemma-c {Γ} {Γ'} {τ} (rec e e0 e1) b c = natrec (interpE e0 (interpS b c)) (λ n k → interpE e1 ((interpS b c , k) , n)) (interpE e (interpS b c)) =⟨ ap (λ h → natrec h (λ n k → interpE e1 ((interpS b c , k) , n)) (interpE e (interpS b c))) (lemma-c e0 b c) ⟩ natrec (interpE (subst b e0) c) (λ n k → interpE e1 ((interpS b c , k) , n)) (interpE e (interpS b c)) =⟨ ap (λ h → natrec (interpE (subst b e0) c) (λ n k → interpE e1 ((interpS b c , k) , n)) h) (lemma-c e b c) ⟩ natrec (interpE (subst b e0) c) (λ n k → interpE e1 ((interpS b c , k) , n)) (interpE (subst b e) c) =⟨ ap (λ h → natrec (interpE (subst b e0) c) h (interpE (subst b e) c)) (λ= (λ x → λ= (λ y → ap (λ h → interpE e1 h) (lemma-c-lemma-rec x y b c)))) ⟩ natrec (interpE (subst b e0) c) (λ n k → interpE e1 (interpS (lem2 (lem2 b)) ((c , k) , n))) (interpE (subst b e) c) =⟨ ap (λ h → natrec (interpE (subst b e0) c) h (interpE (subst b e) c)) (λ= (λ x → λ= (λ y → lemma-c {nat :: τ :: Γ} {nat :: τ :: Γ'} e1 (lem2 (lem2 b)) ((c , y) , x)))) ⟩ natrec (interpE (subst b e0) c) (λ n k → interpE (subst (lem2 (lem2 b)) e1) ((c , k) , n)) (interpE (subst b e) c) ∎ lemma-c {Γ} {Γ'} {ρ ⇒ τ} (lam e) b c = interpE (lam e) (interpS b c) =⟨ Refl ⟩ (λ x → interpE e (interpS b c , x)) =⟨ λ= (λ x → ap (λ h → interpE e h) (lemma-c-lemma x b c)) ⟩ (λ x → interpE e (interpS (lem2 b) (c , x))) =⟨ λ= (λ x → lemma-c {ρ :: Γ} {ρ :: Γ'} e (lem2 b) (c , x)) ⟩ (λ x → interpE (subst (lem2 b) e) (c , x)) ∎ lemma-c (app e1 e2) b c = interpE (app e1 e2) (interpS b c) =⟨ Refl ⟩ interpE e1 (interpS b c) (interpE e2 (interpS b c)) =⟨ ap (λ f → f (interpE e2 (interpS b c))) (lemma-c e1 b c) ⟩ interpE (subst b e1) c (interpE e2 (interpS b c)) =⟨ ap (λ f → interpE (subst b e1) c f) (lemma-c e2 b c) ⟩ interpE (subst b e1) c (interpE (subst b e2) c) ∎ -- Soundness: if e >> e' then interp e == interp e' sound : ∀ {τ} (e e' : [] |- τ) → e >> e' → (interpE e <>) == (interpE e' <>) sound (var x) d () sound z d () sound (suc e) .(suc e') (suc-steps .e e' p) = ap S (sound e e' p) sound (rec e e0 e1) .(rec e' e0 e1) (rec-steps .e e' .e0 .e1 p) = ap (natrec (interpE e0 <>) (λ n k → interpE e1 ((<> , k) , n))) (sound e e' p) sound (rec .z .d e1) d (rec-steps-z e .d .e1) = Refl sound (rec .(suc e) e0 e1) .(subst (lem4 e (rec e e0 e1)) e1) (rec-steps-suc e .e0 .e1 x) = lemma-c e1 (lem4 e (rec e e0 e1)) <> sound (lam x) d () sound (app e1 e2) .(app e1' e2) (app-steps .e1 e1' .e2 p) = ap (λ d → d (interpE e2 <>)) (sound e1 e1' p) sound (app e1 e2) .(app e1 e2') (app-steps-2 .e1 .e2 e2' x p) = ap (λ d → interpE e1 <> d) (sound e2 e2' p) sound (app .(lam e1) e2) .(subst (lem3 e2) e1) (app-steps-3 e1 .e2) = lemma-c e1 (lem3 e2) <>
{ "alphanum_fraction": 0.3663058824, "avg_line_length": 53.9340101523, "ext": "agda", "hexsha": "9904a90c1f2f61a8c52818232ab70dbba1b373d1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "benhuds/Agda", "max_forks_repo_path": "ug/Godel.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z", "max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "benhuds/Agda", "max_issues_repo_path": "ug/Godel.agda", "max_line_length": 175, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "benhuds/Agda", "max_stars_repo_path": "old/Godel.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z", "num_tokens": 7079, "size": 21250 }
{-# OPTIONS --safe #-} open import Generics.Prelude hiding (lookup) open import Generics.Telescope open import Generics.Desc open import Generics.All open import Generics.HasDesc import Generics.Helpers as Helpers module Generics.Constructions.Recursion {P I ℓ} {A : Indexed P I ℓ} (H : HasDesc A) (open HasDesc H) {p c} (Pr : Pred′ I (λ i → A′ (p , i) → Set c)) where private variable V : ExTele P i : ⟦ I ⟧tel p v : ⟦ V ⟧tel p Pr′ : A′ (p , i) → Set c Pr′ {i} = unpred′ I _ Pr i Below : (x : A′ (p , i)) → Acc x → Setω BelowIndArg : (C : ConDesc P V I) (x : ⟦ C ⟧IndArg A′ (p , v)) → AllIndArgω Acc C x → Setω BelowIndArg (var _) x = Below x BelowIndArg (π ai S C) x a = ∀ s → BelowIndArg C (app< ai > x s) (a s) BelowIndArg (A ⊗ B) (x , y) (ax , ay) = BelowIndArg A x ax ×ω BelowIndArg B y ay BelowCon : (C : ConDesc P V I) (x : ⟦ C ⟧Con A′ (p , v , i)) → AllConω Acc C x → Setω BelowCon (var _) x _ = ⊤ω BelowCon (π ai S C) (s , x) = BelowCon C x BelowCon (A ⊗ B) (f , x) (af , ax) = BelowIndArg A f af ×ω BelowCon B x ax Below x (acc a) with split x ... | (k , x) = BelowCon _ x a module _ (f : ∀ {i} (x : A′ (p , i)) (a : Acc x) → Below x a → Pr′ x) where below : (x : A′ (p , i)) (a : Acc x) → Below x a below x (acc a) with split x ... | (k , x) = belowCon _ x a where belowIndArg : (C : ConDesc P V I) (x : ⟦ C ⟧IndArg A′ (p , v)) (a : AllIndArgω Acc C x) → BelowIndArg C x a belowIndArg (var _) x a = below x a belowIndArg (π ai _ C) x a s = belowIndArg C (app< ai > x s) (a s) belowIndArg (A ⊗ B) (x , y) (ax , ay) = belowIndArg A x ax , belowIndArg B y ay belowCon : (C : ConDesc P V I) (x : ⟦ C ⟧Con A′ (p , v , i)) (a : AllConω Acc C x) → BelowCon C x a belowCon (var _) _ _ = tt belowCon (π _ _ C) (_ , x) a = belowCon C x a belowCon (A ⊗ B) (f , x) (af , ax) = belowIndArg A f af , belowCon B x ax rec : (x : A′ (p , i)) → Pr′ x rec x = f x (wf x) (below x (wf x))
{ "alphanum_fraction": 0.5, "avg_line_length": 27.5, "ext": "agda", "hexsha": "dda8867a10e57d458827418e642c1343e034e9c0", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/generics", "max_forks_repo_path": "src/Generics/Constructions/Recursion.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "flupe/generics", "max_issues_repo_path": "src/Generics/Constructions/Recursion.agda", "max_line_length": 75, "max_stars_count": 11, "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/generics", "max_stars_repo_path": "src/Generics/Constructions/Recursion.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "num_tokens": 836, "size": 2200 }
module Type.WellOrdering where import Lvl open import Functional open import Logic open import Logic.Propositional open import Logic.Predicate open import Type open import Type.Dependent private variable ℓ ℓ₁ ℓ₂ : Lvl.Level -- Types with terms that are well-founded trees. -- Constructs types that are similar to some kind of tree. -- The first parameter is the index for a constructor. -- The second parameter is the arity for each constructor. -- -- A type able to describe all non-dependent inductively defined data types assuming there are some previously defined types. -- When described like this, the parameters should be interpreted as the following: -- • The first parameter `A` indicates the "number" of branches based on another type's "cardinality" and should also contain the data for every branch. -- • The second parameter `B` is used when the type to be defined refers to itself. -- Examples: -- open import Data -- open import Data.Boolean -- -- module _ (L R : Type{Lvl.𝟎}) where -- E : Type{Lvl.𝟎} -- E = W{A = Σ(Bool)(if_then R else L)}(const Empty) -- Either type using W. -- l : L → E -- Left branch introduction. -- l x = sup (intro 𝐹 x) empty -- r : R → E -- Rght branch introduction. -- r x = sup (intro 𝑇 x) empty -- -- N = W{A = Bool}(if_then Unit{Lvl.𝟎} else Empty{Lvl.𝟎}) -- Natural numbers using W. -- z : N -- Zero branch introduction. -- z = sup 𝐹 empty -- z' : _ → N -- Zero branch introduction (defined like this because empty functions are not unique (from no function extensionality) resulting in more than one zero for this definition of the natural numbers). -- z' empty = sup 𝐹 empty -- s : N → N -- Successor branch introduction. -- s n = sup 𝑇 (\{<> → n}) -- e : ∀{P : N → Type{Lvl.𝟎}} → (∀{empty} → P(z empty)) → (∀{n} → P(n) → P(s n)) → (∀{n} → P(n)) -- TODO: Is this a correct eliminator? Note: It does not pass the termination checker -- e pz ps {sup 𝐹 b} = pz -- e pz ps {sup 𝑇 b} = ps (e pz (\{n} → ps{n}) {b <>}) record W {A : Type{ℓ₁}} (B : A → Type{ℓ₂}) : Type{ℓ₁ Lvl.⊔ ℓ₂} where inductive eta-equality constructor sup field a : A b : B(a) → W(B) -- TODO: Is the type of this eliminator correct? -- W-elim : ∀{A : Type{ℓ₁}}{B : A → Type{ℓ₂}}{P : W(B) → Type{ℓ}} → (∀{a : A}{b : B(a) → W(B)} → (∀{ba : B(a)} → P(b(ba))) → P(sup a b)) → (∀{w : W(B)} → P(w)) -- TODO: Note that this is essentially Sets.IterativeSet V : ∀{ℓ₁} → Type{Lvl.𝐒(ℓ₁)} V {ℓ₁} = W {A = Type{ℓ₁}} id
{ "alphanum_fraction": 0.5858511422, "avg_line_length": 46.7931034483, "ext": "agda", "hexsha": "cb80acc682c4d5b3e2c5659c3042b44f5751e989", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Type/WellOrdering.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Type/WellOrdering.agda", "max_line_length": 256, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Type/WellOrdering.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 821, "size": 2714 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category using (Category) -- Defines the following properties of a Category: -- Cartesian -- a Cartesian category is a category with all products -- (for the induced Monoidal structure, see Cartesian.Monoidal) module Categories.Category.Cartesian {o ℓ e} (𝒞 : Category o ℓ e) where open import Level using (levelOfTerm) open import Data.Nat using (ℕ; zero; suc) open Category 𝒞 open HomReasoning open import Categories.Category.BinaryProducts 𝒞 using (BinaryProducts; module BinaryProducts) open import Categories.Object.Terminal 𝒞 using (Terminal) private variable A B C D W X Y Z : Obj f f′ g g′ h i : A ⇒ B -- Cartesian monoidal category record Cartesian : Set (levelOfTerm 𝒞) where field terminal : Terminal products : BinaryProducts open BinaryProducts products using (_×_) power : Obj → ℕ → Obj power A 0 = Terminal.⊤ terminal power A 1 = A power A (suc (suc n)) = A × power A (suc n)
{ "alphanum_fraction": 0.7202020202, "avg_line_length": 26.7567567568, "ext": "agda", "hexsha": "c99a177ea6469c1c1c6f718da730806a03b9f6f9", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Category/Cartesian.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Category/Cartesian.agda", "max_line_length": 94, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Category/Cartesian.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 268, "size": 990 }
-- Andreas, 2014-11-25, variant of Issue 1366 {-# OPTIONS --copatterns #-} open import Common.Prelude using (Nat; zero; suc; Unit; unit) data Vec (A : Set) : Nat → Set where [] : Vec A zero _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) -- Singleton type data Sg {A : Set} (x : A) : Set where sg : Sg x -- Generalizing Unit → Nat record DNat : Set₁ where field D : Set force : D → Nat open DNat nonNil : ∀ {n} → Vec Unit n → Nat nonNil [] = zero nonNil (i ∷ is) = suc (force f i) where f : DNat D f = Unit force f unit = zero g : ∀ {n} {v : Vec Unit n} → Sg (nonNil v) → Sg v g sg = sg one : Sg (suc zero) one = sg test : Sg (unit ∷ []) test = g one
{ "alphanum_fraction": 0.55, "avg_line_length": 17.9487179487, "ext": "agda", "hexsha": "298bad9e4988aa3d4cdf4f8174a8417e3eb7e987", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1366a.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1366a.agda", "max_line_length": 61, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1366a.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 267, "size": 700 }
module Ints where open import Nats public using (ℕ; zero; _∸_) renaming (suc to nsuc; _+_ to _:+:_; _*_ to _:*:_) open import Agda.Builtin.Int public renaming (Int to ℤ; negsuc to -[1+_]; pos to +_) infix 8 -_ -- infixl 7 _*_ _⊓_ infixl 6 _+_ _-_ _⊖_ ∣_∣ : ℤ → ℕ ∣ + n ∣ = n ∣ -[1+ n ] ∣ = nsuc n -_ : ℤ → ℤ - (+ nsuc n) = -[1+ n ] - (+ zero) = + zero - -[1+ n ] = + nsuc n _⊖_ : ℕ → ℕ → ℤ m ⊖ zero = + m zero ⊖ nsuc n = -[1+ n ] nsuc m ⊖ nsuc n = m ⊖ n _+_ : ℤ → ℤ → ℤ -[1+ m ] + -[1+ n ] = -[1+ nsuc (m :+: n) ] -[1+ m ] + + n = n ⊖ nsuc m + m + -[1+ n ] = m ⊖ nsuc n + m + + n = + (m :+: n) _-_ : ℤ → ℤ → ℤ i - j = i + - j suc : ℤ → ℤ suc i = + 1 + i
{ "alphanum_fraction": 0.418079096, "avg_line_length": 18.1538461538, "ext": "agda", "hexsha": "fb7e84152b2edac030360c7a2f2abdca512ed45b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ice1k/Theorems", "max_forks_repo_path": "src/Ints.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ice1k/Theorems", "max_issues_repo_path": "src/Ints.agda", "max_line_length": 52, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ice1k/Theorems", "max_stars_repo_path": "src/Ints.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z", "num_tokens": 370, "size": 708 }
module IlltypedPattern where data Nat : Set where zero : Nat suc : Nat -> Nat f : (A : Set) -> A -> A f A zero = zero
{ "alphanum_fraction": 0.5826771654, "avg_line_length": 11.5454545455, "ext": "agda", "hexsha": "93c7c6fc082bce8385bb07a92c45f0d35c0efb59", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/IlltypedPattern.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/IlltypedPattern.agda", "max_line_length": 28, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/IlltypedPattern.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 44, "size": 127 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Rationals.SigmaQ where open import Cubical.HITs.Rationals.SigmaQ.Base public open import Cubical.HITs.Rationals.SigmaQ.Properties public
{ "alphanum_fraction": 0.7904761905, "avg_line_length": 30, "ext": "agda", "hexsha": "ff0be3b64228a13275767218de8b348ed003de4c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/HITs/Rationals/SigmaQ.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/HITs/Rationals/SigmaQ.agda", "max_line_length": 59, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/HITs/Rationals/SigmaQ.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 60, "size": 210 }
-- -- Created by Dependently-Typed Lambda Calculus on 2019-05-15 -- private-primitive-variable -- Author: ice1000 -- {-# OPTIONS --without-K --safe #-} private variable A : Set a : A primitive primInterval : Set
{ "alphanum_fraction": 0.6787330317, "avg_line_length": 13.8125, "ext": "agda", "hexsha": "cc1e9a0cc9641a1e9de93e4b98d77a2623b44e59", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-03-12T21:33:35.000Z", "max_forks_repo_forks_event_min_datetime": "2019-10-07T01:38:12.000Z", "max_forks_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "dubinsky/intellij-dtlc", "max_forks_repo_path": "testData/parse/agda/private-primitive-variable.agda", "max_issues_count": 16, "max_issues_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be", "max_issues_repo_issues_event_max_datetime": "2021-03-15T17:04:36.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-30T04:29:32.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "dubinsky/intellij-dtlc", "max_issues_repo_path": "testData/parse/agda/private-primitive-variable.agda", "max_line_length": 61, "max_stars_count": 30, "max_stars_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "dubinsky/intellij-dtlc", "max_stars_repo_path": "testData/parse/agda/private-primitive-variable.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-29T13:18:34.000Z", "max_stars_repo_stars_event_min_datetime": "2019-05-11T16:26:38.000Z", "num_tokens": 64, "size": 221 }
-- Andreas, 2014-05-17 open import Common.Prelude open import Common.Equality test : Nat test rewrite refl = zero
{ "alphanum_fraction": 0.7586206897, "avg_line_length": 14.5, "ext": "agda", "hexsha": "1804b500385fe2204f3a067f494b348f28225094", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/Issue1110a.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/succeed/Issue1110a.agda", "max_line_length": 27, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/succeed/Issue1110a.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 33, "size": 116 }
{-# OPTIONS --postfix-projections #-} module StateSized.StackStateDependent where open import Data.Product open import Function open import Data.String.Base as Str open import Data.Nat.Base as N open import Data.Vec as Vec using (Vec; []; _∷_; head; tail) open import Relation.Binary using (Rel) open import Relation.Binary.PropositionalEquality open import Relation.Binary.Product.Pointwise open import NativeIO open import SizedIO.Base open import SizedIO.Console hiding (main) open import StateSizedIO.GUI.BaseStateDependent open import StateSizedIO.Object open import StateSizedIO.IOObject open import Size StackStateˢ = ℕ data StackMethodˢ (A : Set) : StackStateˢ → Set where push : {n : StackStateˢ} → A → StackMethodˢ A n pop : {n : StackStateˢ} → StackMethodˢ A (suc n) StackResultˢ : (A : Set) → (s : StackStateˢ) → StackMethodˢ A s → Set StackResultˢ A .n (push { n } x₁) = Unit StackResultˢ A (suc .n) (pop {n} ) = A nˢ : (A : Set) → (s : StackStateˢ) → (m : StackMethodˢ A s) → (r : StackResultˢ A s m) → StackStateˢ nˢ A .n (push { n } x) r = suc n nˢ A (suc .n) (pop { n }) r = n StackInterfaceˢ : (A : Set) → Interfaceˢ StackInterfaceˢ A .Stateˢ = StackStateˢ StackInterfaceˢ A .Methodˢ = StackMethodˢ A StackInterfaceˢ A .Resultˢ = StackResultˢ A StackInterfaceˢ A .nextˢ = nˢ A stackP : ∀{n : ℕ} → (i : Size) → (v : Vec String n) → IOObjectˢ consoleI (StackInterfaceˢ String) i n method (stackP { n } i es) {j} (push e) = return (_ , stackP j (e ∷ es)) method (stackP {suc n} i (x ∷ xs)){j} pop = return (x , stackP j xs) -- UNSIZED Version, without IO stackP' : ∀{n : ℕ} → (v : Vec String n) → Objectˢ (StackInterfaceˢ String) n stackP' es .objectMethod (push e) = (_ , stackP' (e ∷ es)) stackP' (x ∷ xs) .objectMethod pop = x , stackP' xs stackO : ∀{E : Set} {n : ℕ} (v : Vec E n) → Objectˢ (StackInterfaceˢ E) n objectMethod (stackO es) (push e) = _ , stackO (e ∷ es) objectMethod (stackO (e ∷ es)) pop = e , stackO es stackF : ∀{E : Set} (n : ℕ) (f : ℕ → E) → Objectˢ (StackInterfaceˢ E) n objectMethod (stackF n f) (push x) = _ , stackF (suc n) \{ zero → x ; (suc m) → f m } objectMethod (stackF (suc n) f) pop = (f zero) , stackF n (f ∘ suc) tabulate : ∀{E : Set} (n : ℕ) (f : ℕ → E) → Vec E n tabulate zero f = [] tabulate (suc n) f = f zero ∷ tabulate n λ m → f (suc m) module _ {E : Set} where private I = StackInterfaceˢ E S = Stateˢ I O = Objectˢ I open Bisim I _≡×≅'_ : ∀{s} → (o o' : E × O s) → Set _≡×≅'_ = _≡_ ×-Rel _≅_ Eq×Bisim : ∀ (s : S) → (o o' : E × O s) → Set Eq×Bisim s = _≡_ ×-Rel _≅_ pop-after-push : ∀{n}{v : Vec E n} (e : E) (let stack = stackO v) → (objectMethod stack (push e) ▹ λ { (_ , stack₁) → objectMethod stack₁ pop ▹ λ { (e₁ , stack₂) → ( e₁ , stack₂ ) }}) ≡×≅' (e , stack) pop-after-push e = refl , refl≅ _ push-after-pop : ∀{n}{v : Vec E n} (e : E) (let stack = stackO (e ∷ v)) → (objectMethod stack pop ▹ λ { (e₁ , stack₁) → objectMethod stack₁ (push e₁) ▹ λ { (_ , stack₂) → stack₂ }}) ≅ stack push-after-pop e = refl≅ _ -- The implementations of stacks with either vectors or functions are bisimilar. impl-bisim : ∀{n : ℕ} {f : ℕ → E} (v : Vec E n) (p : tabulate n f ≡ v) → stackF n f ≅ stackO v bisimMethod (impl-bisim v p) (push e) = bisim (impl-bisim (e ∷ v) (cong (_∷_ e) p)) bisimMethod (impl-bisim (x ∷ v) p) pop rewrite cong head p = bisim (impl-bisim v (cong tail p)) program : IOConsole ∞ Unit program = exec getLine λ str₀ → method s₀ (push str₀) >>= λ{ (_ , s₁) → -- empty exec getLine λ str₁ → method s₁ (push str₁) >>= λ{ (_ , s₂) → -- full method s₂ pop >>= λ{ (str₂ , s₃) → exec (putStrLn ("first pop: " Str.++ str₂) ) λ _ → exec getLine λ str₃ → method s₃ (push str₃) >>= λ{ (_ , s₄) → method s₄ pop >>= λ{ (str₄ , s₅) → exec (putStrLn ("second pop: " Str.++ str₄) ) λ _ → method s₅ pop >>= λ{ (str₅ , s₅) → exec (putStrLn ("third pop: " Str.++ str₅) ) λ _ → return unit }}}}}} where s₀ = stackP ∞ [] main : NativeIO Unit main = translateIOConsole program
{ "alphanum_fraction": 0.5866510539, "avg_line_length": 30.7194244604, "ext": "agda", "hexsha": "107369c48245284a2df888f218e9a191640e8ed7", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "examples/StateSized/StackStateDependent.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "examples/StateSized/StackStateDependent.agda", "max_line_length": 101, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "examples/StateSized/StackStateDependent.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 1633, "size": 4270 }
{-# OPTIONS --safe --cubical #-} module Lens.Operators where open import Prelude open import Lens.Definition infixl 4 getter setter getter : Lens A B → A → B getter l xs = get (fst l xs) syntax getter l xs = xs [ l ] setter : Lens A B → A → B → A setter l xs = set (fst l xs) syntax setter l xs x = xs [ l ]≔ x
{ "alphanum_fraction": 0.6446540881, "avg_line_length": 16.7368421053, "ext": "agda", "hexsha": "e5a6881385373a26f28e4d064c67d4d45194d8fe", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Lens/Operators.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Lens/Operators.agda", "max_line_length": 34, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Lens/Operators.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 98, "size": 318 }
module Properties.Product where infixr 5 _×_ _,_ record Σ {A : Set} (B : A → Set) : Set where constructor _,_ field fst : A field snd : B fst open Σ public _×_ : Set → Set → Set A × B = Σ (λ (a : A) → B)
{ "alphanum_fraction": 0.5860465116, "avg_line_length": 14.3333333333, "ext": "agda", "hexsha": "0d41c817c6dd01f37c037d8d912c8399f58bfb70", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "XanderYZZ/luau", "max_forks_repo_path": "prototyping/Properties/Product.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "XanderYZZ/luau", "max_issues_repo_path": "prototyping/Properties/Product.agda", "max_line_length": 44, "max_stars_count": 1, "max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "TheGreatSageEqualToHeaven/luau", "max_stars_repo_path": "prototyping/Properties/Product.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z", "num_tokens": 82, "size": 215 }
{-# OPTIONS --without-K #-} {- Truncated higher inductive types look like higher inductive types except that they are truncated down to some fixed truncation level. This allow to define truncations (obviously) but also free algebras for algebraic theories, Eilenberg-MacLane spaces, etc. The idea is that to get an n-truncated higher inductive type, you just have to add the following two constructors, where [I] is the HIT you are defining. top : (f : Sⁿ n → I) → I rays : (f : Sⁿ n → I) (x : Sⁿ n) → top f ≡ f x In this file, I prove whatever is needed to go from the usual elimination rules generated by the previous constructors to the elimination rules that we expect from truncated higher inductive types. We have to note that the previous definition does not work for [n = 0], because this only adds a point to I instead of turning it into a contractible space. 0-truncated higher inductive types are not really interesting but handling truncations is easier when 0 is not special Hence I’m adding the following path constructor hack-prop : (p : n ≡ 0) (x y : τ) → (x ≡ y) This will force [I] to be a prop (hence contractible because [top] of the empty function is of type [I]) and does not change anything when [n] is not 0. I may use the following syntax for [n]-truncated higher inductive types: (n)data I : Set i where … -} module Homotopy.TruncatedHIT where open import Base open import Spaces.Spheres public open import Spaces.Suspension public _+1 : ℕ₋₂ → ℕ ⟨-2⟩ +1 = 0 (S ⟨-2⟩) +1 = 0 (S n) +1 = S (n +1) -- [hSⁿ n] is what is supposed to be filled to get something n-truncated hSⁿ : ℕ₋₂ → Set hSⁿ ⟨-2⟩ = ⊥ hSⁿ n = Sⁿ (n +1) -- Type of fillings of a sphere filling : ∀ {i} (n : ℕ₋₂) {A : Set i} (f : hSⁿ n → A) → Set i filling {i} n {A} f = Σ A (λ t → ((x : hSⁿ n) → t ≡ f x)) -- Type of dependent fillings of a sphere above a ball filling-dep : ∀ {i j} (n : ℕ₋₂) {A : Set i} (P : A → Set j) (f : hSⁿ n → A) (fill : filling n f) (p : (x : hSⁿ n) → P (f x)) → Set j filling-dep {i} {j} n {A} P f fill p = Σ (P (π₁ fill)) (λ t → ((x : hSⁿ n) → transport P (π₂ fill x) t ≡ p x)) -- [has-n-spheres-filled n A] is inhabited iff every n-sphere in [A] can be -- filled with an (n+1)-ball. -- We will show that this is equivalent to being n-truncated, *for n > 0* -- (for n = 0, having 0-spheres filled only means that A is inhabited) has-spheres-filled : ∀ {i} (n : ℕ₋₂) (A : Set i) → Set i has-spheres-filled n A = (f : hSⁿ n → A) → filling n f -- [has-n-spheres-filled] satisfy the same inductive property -- than [is-truncated] fill-paths : ∀ {i} (n : ℕ₋₂) (A : Set i) (t : has-spheres-filled (S n) A) → (n ≡ ⟨-2⟩ → is-contr A) → ((x y : A) → has-spheres-filled n (x ≡ y)) fill-paths ⟨-2⟩ A t contr x y f = (contr-has-all-paths (contr refl) x y , abort) fill-paths (S n) A t _ x y f = ((! (π₂ u (north _)) ∘ π₂ u (south _)) , (λ z → ! (lemma (paths _ z)) ∘ suspension-β-paths-nondep _ _ _ _ f _)) where -- [f] is a map from [hSⁿ (S n)] to [x ≡ y], we can build from it a map -- from [hSⁿ (S n)] to [A] newf : hSⁿ (S (S n)) → A newf = suspension-rec-nondep _ _ x y f u : filling (S (S n)) newf u = t newf -- I’ve got a filling -- Every path in the sphere is equal (in A) to the canonical path going -- through the center of the filled sphere lemma : {p q : hSⁿ (S (S n))} (l : p ≡ q) → ap newf l ≡ ! (π₂ u p) ∘ π₂ u q lemma {p = a} refl = ! (opposite-left-inverse (π₂ u a)) -- We first prove that if n-spheres are filled, then the type is n-truncated, -- we have to prove it for n = -1, and then use the previous lemma abstract spheres-filled-is-truncated : ∀ {i} (n : ℕ₋₂) (A : Set i) → ((n ≡ ⟨-2⟩ → is-contr A) → has-spheres-filled n A → is-truncated n A) spheres-filled-is-truncated ⟨-2⟩ A contr t = contr refl spheres-filled-is-truncated (S ⟨-2⟩) A _ t = all-paths-is-prop (λ x y → ! (π₂ (t (f x y)) true) ∘ π₂ (t (f x y)) false) where f : (x y : A) → bool {zero} → A f x y true = x f x y false = y spheres-filled-is-truncated (S (S n)) A _ t = λ x y → spheres-filled-is-truncated (S n) (x ≡ y) (λ ()) (fill-paths (S n) A t (λ ()) x y) -- We now prove the converse abstract truncated-has-spheres-filled : ∀ {i} (n : ℕ₋₂) (A : Set i) (t : is-truncated n A) → has-spheres-filled n A truncated-has-spheres-filled ⟨-2⟩ A t f = (π₁ t , abort) truncated-has-spheres-filled (S ⟨-2⟩) A t f = (f true , (λ {true → refl ; false → π₁ (t (f true) (f false))})) truncated-has-spheres-filled (S (S n)) A t f = (f (north _) , (suspension-rec _ _ refl (ap f (paths _ (⋆Sⁿ _))) (λ x → trans-cst≡app (f (north _)) f (paths _ _) _ ∘ (! (π₂ filled-newf x) ∘ π₂ filled-newf (⋆Sⁿ _))))) where newf : hSⁿ (S n) → (f (north _) ≡ f (south _)) newf x = ap f (paths _ x) filled-newf : filling (S n) newf filled-newf = truncated-has-spheres-filled (S n) _ (t _ _) newf -- I prove that if [A] has [S n]-spheres filled, then the type of fillings -- of [n]-spheres is a proposition. The idea is that two fillings of -- an [n]-sphere define an [S n]-sphere, which is then filled. filling-has-all-paths : ∀ {i} (n : ℕ₋₂) (A : Set i) ⦃ fill : has-spheres-filled (S n) A ⦄ (f : hSⁿ n → A) → has-all-paths (filling n f) filling-has-all-paths ⟨-2⟩ A ⦃ fill ⦄ f fill₁ fill₂ = Σ-eq (! (π₂ big-map-filled true) ∘ π₂ big-map-filled false) (funext abort) where big-map : hSⁿ ⟨-1⟩ → A big-map true = π₁ fill₁ big-map false = π₁ fill₂ big-map-filled : filling ⟨-1⟩ big-map big-map-filled = fill big-map filling-has-all-paths (S n) A ⦃ fill ⦄ f fill₁ fill₂ = Σ-eq (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _)) (funext (λ x → trans-Π2 _ (λ t x₁ → t ≡ f x₁) (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _)) (π₂ fill₁) x ∘ (trans-id≡cst (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _)) (π₂ fill₁ x) ∘ move!-right-on-left (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _)) _ _ (move-left-on-right _ (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _)) _ (! (suspension-β-paths-nondep _ _ _ _ g x) ∘ lemma (paths _ x)))))) where g : hSⁿ (S n) → (π₁ fill₁ ≡ π₁ fill₂) g x = π₂ fill₁ x ∘ ! (π₂ fill₂ x) big-map : hSⁿ (S (S n)) → A big-map = suspension-rec-nondep _ _ (π₁ fill₁) (π₁ fill₂) g big-map-filled : filling (S (S n)) big-map big-map-filled = fill big-map lemma : {u v : hSⁿ (S (S n))} (p : u ≡ v) → ap big-map p ≡ (! (π₂ big-map-filled u) ∘ π₂ big-map-filled v) lemma {u = a} refl = ! (opposite-left-inverse (π₂ big-map-filled a)) abstract truncated-has-filling-dep : ∀ {i j} (A : Set i) (P : A → Set j) (n : ℕ₋₂) ⦃ trunc : (x : A) → is-truncated n (P x) ⦄ (contr : n ≡ ⟨-2⟩ → is-contr A) (fill : has-spheres-filled n A) (f : hSⁿ n → A) (p : (x : hSⁿ n) → P (f x)) → filling-dep n P f (fill f) p truncated-has-filling-dep A P ⟨-2⟩ ⦃ trunc ⦄ contr fill f p = (π₁ (trunc (π₁ (fill f))) , abort) truncated-has-filling-dep A P (S n) ⦃ trunc ⦄ contr fill f p = transport (λ t → filling-dep (S n) P f t p) eq fill-dep where -- Combining [f] and [p] we have a sphere in the total space of [P] newf : hSⁿ (S n) → Σ A P newf x = (f x , p x) -- But this total space is (S n)-truncated ΣAP-truncated : is-truncated (S n) (Σ A P) ΣAP-truncated = Σ-is-truncated (S n) (spheres-filled-is-truncated (S n) A contr fill) trunc -- Hence the sphere is filled tot-fill : filling (S n) newf tot-fill = truncated-has-spheres-filled (S n) (Σ A P) ΣAP-truncated newf -- We can split this filling as a filling of [f] in [A] … new-fill : filling (S n) f new-fill = (π₁ (π₁ tot-fill) , (λ x → base-path (π₂ tot-fill x))) -- and a dependent filling above the previous filling of [f], along [p] fill-dep : filling-dep (S n) P f new-fill p fill-dep = (π₂ (π₁ tot-fill) , (λ x → fiber-path (π₂ tot-fill x))) A-has-spheres-filled-S : has-spheres-filled (S (S n)) A A-has-spheres-filled-S = truncated-has-spheres-filled (S (S n)) A (truncated-is-truncated-S (S n) (spheres-filled-is-truncated (S n) A contr fill)) -- But both the new and the old fillings of [f] are equal, hence we will -- have a dependent filling above the old one eq : new-fill ≡ fill f eq = filling-has-all-paths (S n) A f new-fill (fill f)
{ "alphanum_fraction": 0.5799184967, "avg_line_length": 38.9162995595, "ext": "agda", "hexsha": "58077c8bb8215218aae3538fcfd38bb4a9bae40d", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Homotopy/TruncatedHIT.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Homotopy/TruncatedHIT.agda", "max_line_length": 80, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "old/Homotopy/TruncatedHIT.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 3123, "size": 8834 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Construction.Adjoints where open import Level open import Data.Product using (_×_ ; _,_) open import Categories.Category open import Categories.Category.Helper open import Categories.Adjoint open import Categories.Adjoint.Compose open import Categories.Adjoint.Mate open import Categories.Functor renaming (id to idF) open import Categories.NaturalTransformation renaming (id to idN) open import Categories.NaturalTransformation.NaturalIsomorphism open import Categories.NaturalTransformation.Equivalence renaming (_≃_ to _≊_) import Categories.Morphism.Reasoning as MR private variable o o′ ℓ ℓ′ e e′ : Level -- category of adjunctions between two fixed categories module _ (C : Category o ℓ e) (D : Category o′ ℓ′ e′) where private module C = Category C module D = Category D record AdjointObj : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where field L : Functor C D R : Functor D C L⊣R : L ⊣ R module L = Functor L module R = Functor R module L⊣R = Adjoint L⊣R record Adjoint⇒ (X Y : AdjointObj) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where private module X = AdjointObj X module Y = AdjointObj Y field mate : HaveMate X.L⊣R Y.L⊣R open HaveMate mate public private _≈_ : ∀ {A B} → Adjoint⇒ A B → Adjoint⇒ A B → Set (o ⊔ e ⊔ o′ ⊔ e′) f ≈ g = Adjoint⇒.α f ≊ Adjoint⇒.α g × Adjoint⇒.β f ≊ Adjoint⇒.β g id : {X : AdjointObj} → Adjoint⇒ X X id {X} = record { mate = record { α = idN ; β = idN ; mate = record { commute₁ = C.∘-resp-≈ˡ R.identity ; commute₂ = D.∘-resp-≈ʳ L.identity } } } where open AdjointObj X _∘_ : ∀ {X Y Z} → Adjoint⇒ Y Z → Adjoint⇒ X Y → Adjoint⇒ X Z _∘_ {X} {Y} {Z} f g = record { mate = record { α = f.α ∘ᵥ g.α ; β = g.β ∘ᵥ f.β ; mate = record { commute₁ = λ {W} → let open C.HomReasoning open MR C in begin X.R.F₁ (f.α.η W D.∘ g.α.η W) C.∘ X.L⊣R.unit.η W ≈⟨ X.R.homomorphism ⟩∘⟨refl ⟩ (X.R.F₁ (f.α.η W) C.∘ X.R.F₁ (g.α.η W)) C.∘ X.L⊣R.unit.η W ≈⟨ pullʳ g.commute₁ ⟩ X.R.F₁ (f.α.η W) C.∘ g.β.η (Y.L.F₀ W) C.∘ Y.L⊣R.unit.η W ≈⟨ pullˡ (g.β.sym-commute _) ⟩ (g.β.η (Z.L.F₀ W) C.∘ Y.R.F₁ (f.α.η W)) C.∘ Y.L⊣R.unit.η W ≈⟨ pullʳ f.commute₁ ⟩ g.β.η (Z.L.F₀ W) C.∘ f.β.η (Z.L.F₀ W) C.∘ Z.L⊣R.unit.η W ≈⟨ C.sym-assoc ⟩ (g.β.η (Z.L.F₀ W) C.∘ f.β.η (Z.L.F₀ W)) C.∘ Z.L⊣R.unit.η W ∎ ; commute₂ = λ {W} → let open D.HomReasoning open MR D in begin X.L⊣R.counit.η W D.∘ X.L.F₁ (g.β.η W C.∘ f.β.η W) ≈⟨ refl⟩∘⟨ X.L.homomorphism ⟩ X.L⊣R.counit.η W D.∘ X.L.F₁ (g.β.η W) D.∘ X.L.F₁ (f.β.η W) ≈⟨ pullˡ g.commute₂ ⟩ (Y.L⊣R.counit.η W D.∘ g.α.η (Y.R.F₀ W)) D.∘ X.L.F₁ (f.β.η W) ≈⟨ pullʳ (g.α.commute _) ⟩ Y.L⊣R.counit.η W D.∘ Y.L.F₁ (f.β.η W) D.∘ g.α.η (Z.R.F₀ W) ≈⟨ pullˡ f.commute₂ ⟩ (Z.L⊣R.counit.η W D.∘ f.α.η (Z.R.F₀ W)) D.∘ g.α.η (Z.R.F₀ W) ≈⟨ D.assoc ⟩ Z.L⊣R.counit.η W D.∘ f.α.η (Z.R.F₀ W) D.∘ g.α.η (Z.R.F₀ W) ∎ } } } where module X = AdjointObj X module Y = AdjointObj Y module Z = AdjointObj Z module f = Adjoint⇒ f module g = Adjoint⇒ g Adjoints : Category (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (o ⊔ e ⊔ o′ ⊔ e′) Adjoints = categoryHelper record { Obj = AdjointObj ; _⇒_ = Adjoint⇒ ; _≈_ = _≈_ ; id = id ; _∘_ = _∘_ ; assoc = D.assoc , C.sym-assoc ; identityˡ = D.identityˡ , C.identityʳ ; identityʳ = D.identityʳ , C.identityˡ ; equiv = record { refl = D.Equiv.refl , C.Equiv.refl ; sym = λ { (eq₁ , eq₂) → D.Equiv.sym eq₁ , C.Equiv.sym eq₂ } ; trans = λ { (eq₁ , eq₂) (eq₃ , eq₄) → D.Equiv.trans eq₁ eq₃ , C.Equiv.trans eq₂ eq₄ } } ; ∘-resp-≈ = λ { (eq₁ , eq₂) (eq₃ , eq₄) → D.∘-resp-≈ eq₁ eq₃ , C.∘-resp-≈ eq₄ eq₂ } } module _ o ℓ e where private _≈_ : ∀ {A B : Category o ℓ e} → AdjointObj A B → AdjointObj A B → Set (o ⊔ ℓ ⊔ e) f ≈ g = f.L ≃ g.L × f.R ≃ g.R where module f = AdjointObj f module g = AdjointObj g id : {A : Category o ℓ e} → AdjointObj A A id = record { L = idF ; R = idF ; L⊣R = ⊣-id } _∘_ : {A B C : Category o ℓ e} → AdjointObj B C → AdjointObj A B → AdjointObj A C f ∘ g = record { L = f.L ∘F g.L ; R = g.R ∘F f.R ; L⊣R = g.L⊣R ∘⊣ f.L⊣R } where module f = AdjointObj f module g = AdjointObj g Adjunctions : Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) Adjunctions = categoryHelper record { Obj = Category o ℓ e ; _⇒_ = AdjointObj ; _≈_ = _≈_ ; id = id ; _∘_ = _∘_ ; assoc = λ {_ _ _ _ f g h} → associator (AdjointObj.L f) (AdjointObj.L g) (AdjointObj.L h) , sym-associator (AdjointObj.R h) (AdjointObj.R g) (AdjointObj.R f) ; identityˡ = unitorˡ , unitorʳ ; identityʳ = unitorʳ , unitorˡ ; equiv = record { refl = ≃.refl , ≃.refl ; sym = λ { (α , β) → ≃.sym α , ≃.sym β } ; trans = λ { (α₁ , β₁) (α₂ , β₂) → ≃.trans α₁ α₂ , ≃.trans β₁ β₂ } } ; ∘-resp-≈ = λ { (α₁ , β₁) (α₂ , β₂) → α₁ ⓘₕ α₂ , β₂ ⓘₕ β₁ } }
{ "alphanum_fraction": 0.4959132907, "avg_line_length": 34.7407407407, "ext": "agda", "hexsha": "51c9f5637baf0cc3338c4164fbec44058b889ded", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Category/Construction/Adjoints.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Category/Construction/Adjoints.agda", "max_line_length": 104, "max_stars_count": 5, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Category/Construction/Adjoints.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 2421, "size": 5628 }
-- Some basic structures and operation for dealing with non-deterministic values module nondet where open import bool open import nat open import list infixr 8 _??_ ---------------------------------------------------------------------- -- A tree datatype to represent non-deterministic value of some type. -- It is either a value, a failure, or a choice between -- non-deterministic values. ---------------------------------------------------------------------- data ND (A : Set) : Set where Val : A → ND A _??_ : ND A → ND A → ND A ---------------------------------------------------------------------- -- Some operation to define functions working this the ND datatype: -- Map a function on non-deterministic values: mapND : {A B : Set} → (A → B) → ND A → ND B mapND f (Val xs) = Val (f xs) mapND f (t1 ?? t2) = mapND f t1 ?? mapND f t2 -- Extend the first argument to ND: with-nd-arg : {A B : Set} → (A → ND B) → ND A → ND B with-nd-arg f (Val x) = f x with-nd-arg f (t1 ?? t2) = with-nd-arg f t1 ?? with-nd-arg f t2 -- Extend the first argument of a binary function to ND: with-nd-arg2 : {A B C : Set} → (A → B → ND C) → ND A → B → ND C with-nd-arg2 f (Val x) y = f x y with-nd-arg2 f (t1 ?? t2) y = with-nd-arg2 f t1 y ?? with-nd-arg2 f t2 y -- Extend the first argument of a ternary function to ND: with-nd-arg3 : {A B C D : Set} → (A → B → C → ND D) → ND A → B → C → ND D with-nd-arg3 f (Val x) y z = f x y z with-nd-arg3 f (t1 ?? t2) y z = with-nd-arg3 f t1 y z ?? with-nd-arg3 f t2 y z -- Apply a non-deterministic functional value to a non-determistic argument: apply-nd : {A B : Set} → ND (A → B) → ND A → ND B apply-nd (Val f) xs = mapND f xs apply-nd (t1 ?? t2) xs = apply-nd t1 xs ?? apply-nd t2 xs -- Extend a deterministic function to one with non-deterministic result: toND : {A B : Set} → (A → B) → A → ND B toND f x = Val (f x) -- Extend a deterministic function to a non-deterministic one: det-to-nd : {A B : Set} → (A → B) → ND A → ND B det-to-nd f = with-nd-arg (toND f) ---------------------------------------------------------------------- -- Some operations to define properties of non-deterministic values: -- Count the number of values: #vals : {A : Set} → ND A → ℕ #vals (Val _) = 1 #vals (t1 ?? t2) = #vals t1 + #vals t2 -- Extract the list of all values: vals-of : {A : Set} → ND A → 𝕃 A vals-of (Val v) = v :: [] vals-of (t1 ?? t2) = vals-of t1 ++ vals-of t2 -- All values in a Boolean tree are true: always : ND 𝔹 → 𝔹 always (Val b) = b always (t1 ?? t2) = always t1 && always t2 -- There exists some true value in a Boolean tree: eventually : ND 𝔹 → 𝔹 eventually (Val b) = b eventually (t1 ?? t2) = eventually t1 || eventually t2 -- There is not value: failing : {A : Set} → ND A → 𝔹 failing (Val _) = ff failing (t1 ?? t2) = failing t1 && failing t2 -- All non-deterministic values satisfy a given predicate: _satisfy_ : {A : Set} → ND A → (A → 𝔹) → 𝔹 (Val n) satisfy p = p n (t1 ?? t2) satisfy p = t1 satisfy p && t2 satisfy p -- Every value in a tree is equal to the second argument w.r.t. a -- comparison function provided as the first argument: every : {A : Set} → (eq : A → A → 𝔹) → A → ND A → 𝔹 every eq x xs = xs satisfy (eq x) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.5503759398, "avg_line_length": 34.2783505155, "ext": "agda", "hexsha": "7a02301e042051433cbe8193379e1bf18e80e7bf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "phlummox/curry-tools", "max_forks_repo_path": "currypp/.cpm/packages/verify/imports/nondet.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "phlummox/curry-tools", "max_issues_repo_path": "currypp/.cpm/packages/verify/imports/nondet.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "phlummox/curry-tools", "max_stars_repo_path": "currypp/.cpm/packages/verify/imports/nondet.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1073, "size": 3325 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Functions.Definition module Functions.Lemmas where invertibleImpliesBijection : {a b : _} {A : Set a} {B : Set b} {f : A → B} → Invertible f → Bijection f Bijection.inj (invertibleImpliesBijection {a} {b} {A} {B} {f} record { inverse = inverse ; isLeft = isLeft ; isRight = isRight }) {x} {y} fx=fy = ans where bl : inverse (f x) ≡ inverse (f y) bl = applyEquality inverse fx=fy ans : x ≡ y ans rewrite equalityCommutative (isRight x) | equalityCommutative (isRight y) = bl Bijection.surj (invertibleImpliesBijection {a} {b} {A} {B} {f} record { inverse = inverse ; isLeft = isLeft ; isRight = isRight }) y = (inverse y , isLeft y) bijectionImpliesInvertible : {a b : _} {A : Set a} {B : Set b} {f : A → B} → Bijection f → Invertible f Invertible.inverse (bijectionImpliesInvertible record { inj = inj ; surj = surj }) b = underlying (surj b) Invertible.isLeft (bijectionImpliesInvertible {f = f} record { inj = inj ; surj = surj }) b with surj b Invertible.isLeft (bijectionImpliesInvertible {f = f} record { inj = inj ; surj = surj }) b | a , prop = prop Invertible.isRight (bijectionImpliesInvertible {f = f} record { inj = inj ; surj = surj }) a with surj (f a) Invertible.isRight (bijectionImpliesInvertible {f = f} record { inj = property ; surj = surj }) a | a₁ , b = property b injComp : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Injection f → Injection g → Injection (g ∘ f) injComp {f = f} {g} propF propG pr = propF (propG pr) surjComp : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Surjection f → Surjection g → Surjection (g ∘ f) surjComp {f = f} {g} propF propG c with propG c surjComp {f = f} {g} propF propG c | b , pr with propF b surjComp {f = f} {g} propF propG c | b , pr | a , pr2 = a , pr' where pr' : g (f a) ≡ c pr' rewrite pr2 = pr bijectionComp : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Bijection f → Bijection g → Bijection (g ∘ f) Bijection.inj (bijectionComp bijF bijG) = injComp (Bijection.inj bijF) (Bijection.inj bijG) Bijection.surj (bijectionComp bijF bijG) = surjComp (Bijection.surj bijF) (Bijection.surj bijG) compInjRightInj : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Injection (g ∘ f) → Injection f compInjRightInj {f = f} {g} property {x} {y} fx=fy = property (applyEquality g fx=fy) compSurjLeftSurj : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Surjection (g ∘ f) → Surjection g compSurjLeftSurj {f = f} {g} property b with property b compSurjLeftSurj {f = f} {g} property b | a , b1 = f a , b1 injectionPreservedUnderExtensionalEq : {a b : _} {A : Set a} {B : Set b} {f g : A → B} → Injection f → ({x : A} → f x ≡ g x) → Injection g injectionPreservedUnderExtensionalEq {A = A} {B} {f} {g} property prop {x} {y} gx=gy = property (transitivity (prop {x}) (transitivity gx=gy (equalityCommutative (prop {y})))) surjectionPreservedUnderExtensionalEq : {a b : _} {A : Set a} {B : Set b} {f g : A → B} → Surjection f → ({x : A} → f x ≡ g x) → Surjection g surjectionPreservedUnderExtensionalEq {f = f} {g} surj ext b with surj b surjectionPreservedUnderExtensionalEq {f = f} {g} surj ext b | a , pr = a , transitivity (equalityCommutative ext) pr bijectionPreservedUnderExtensionalEq : {a b : _} {A : Set a} {B : Set b} {f g : A → B} → Bijection f → ({x : A} → f x ≡ g x) → Bijection g Bijection.inj (bijectionPreservedUnderExtensionalEq record { inj = inj ; surj = surj } ext) = injectionPreservedUnderExtensionalEq inj ext Bijection.surj (bijectionPreservedUnderExtensionalEq record { inj = inj ; surj = surj } ext) = surjectionPreservedUnderExtensionalEq surj ext inverseIsInvertible : {a b : _} {A : Set a} {B : Set b} {f : A → B} → (inv : Invertible f) → Invertible (Invertible.inverse inv) Invertible.inverse (inverseIsInvertible {f = f} inv) = f Invertible.isLeft (inverseIsInvertible {f = f} inv) b = Invertible.isRight inv b Invertible.isRight (inverseIsInvertible {f = f} inv) a = Invertible.isLeft inv a idIsBijective : {a : _} {A : Set a} → Bijection (id {a} {A}) Bijection.inj idIsBijective pr = pr Bijection.surj idIsBijective b = b , refl functionCompositionExtensionallyAssociative : {a b c d : _} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → (f : A → B) → (g : B → C) → (h : C → D) → (x : A) → (h ∘ (g ∘ f)) x ≡ ((h ∘ g) ∘ f) x functionCompositionExtensionallyAssociative f g h x = refl
{ "alphanum_fraction": 0.6462274407, "avg_line_length": 65.7, "ext": "agda", "hexsha": "1e83559beba85c7dcd839d11e1c84127d2140792", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Functions/Lemmas.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Functions/Lemmas.agda", "max_line_length": 195, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Functions/Lemmas.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 1742, "size": 4599 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Groups.Definition module Groups.DirectSum.Definition {m n o p : _} {A : Set m} {S : Setoid {m} {o} A} {_·A_ : A → A → A} {B : Set n} {T : Setoid {n} {p} B} {_·B_ : B → B → B} (G : Group S _·A_) (H : Group T _·B_) where open import Setoids.Product S T directSumGroup : Group productSetoid (λ x1 y1 → (((_&&_.fst x1) ·A (_&&_.fst y1)) ,, ((_&&_.snd x1) ·B (_&&_.snd y1)))) Group.+WellDefined directSumGroup (s ,, t) (u ,, v) = Group.+WellDefined G s u ,, Group.+WellDefined H t v Group.0G directSumGroup = (Group.0G G ,, Group.0G H) Group.inverse directSumGroup (g1 ,, H1) = (Group.inverse G g1) ,, (Group.inverse H H1) Group.+Associative directSumGroup = Group.+Associative G ,, Group.+Associative H Group.identRight directSumGroup = Group.identRight G ,, Group.identRight H Group.identLeft directSumGroup = Group.identLeft G ,, Group.identLeft H Group.invLeft directSumGroup = Group.invLeft G ,, Group.invLeft H Group.invRight directSumGroup = Group.invRight G ,, Group.invRight H
{ "alphanum_fraction": 0.6893115942, "avg_line_length": 55.2, "ext": "agda", "hexsha": "8cea052927a84da1adbd298d851301d515b24ae2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Groups/DirectSum/Definition.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Groups/DirectSum/Definition.agda", "max_line_length": 200, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Groups/DirectSum/Definition.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 353, "size": 1104 }
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Properties.MaybeEmb {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Typed open import Definition.LogicalRelation -- Any level can be embedded into the highest level. maybeEmb : ∀ {l A Γ} → Γ ⊩⟨ l ⟩ A → Γ ⊩⟨ ¹ ⟩ A maybeEmb {⁰} [A] = emb′ 0<1 [A] maybeEmb {¹} [A] = [A] -- The lowest level can be embedded in any level. maybeEmb′ : ∀ {l A Γ} → Γ ⊩⟨ ⁰ ⟩ A → Γ ⊩⟨ l ⟩ A maybeEmb′ {⁰} [A] = [A] maybeEmb′ {¹} [A] = emb′ 0<1 [A]
{ "alphanum_fraction": 0.6138147567, "avg_line_length": 24.5, "ext": "agda", "hexsha": "0fa791ff244c48aca606fcf74458d956b1f67855", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_path": "Definition/LogicalRelation/Properties/MaybeEmb.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_path": "Definition/LogicalRelation/Properties/MaybeEmb.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_path": "Definition/LogicalRelation/Properties/MaybeEmb.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 216, "size": 637 }
{-# OPTIONS --cubical --no-import-sorts #-} module Cubical.Codata.Conat where open import Cubical.Codata.Conat.Base public open import Cubical.Codata.Conat.Properties public
{ "alphanum_fraction": 0.7840909091, "avg_line_length": 25.1428571429, "ext": "agda", "hexsha": "35d140c2d46ef02080f6ddecc2111f2fd40ade36", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Codata/Conat.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Codata/Conat.agda", "max_line_length": 50, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Codata/Conat.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 43, "size": 176 }
-- Andreas, 2015-07-16 issue reported by G.Allais -- This ought to pass, ideally, but the lack of positivity polymorphism -- does not allow for a precise analysis of the composition operator. -- -- Subsequently, the positivity analysis for tabulate returns no -- positivity info for all arguments, leading to a rejection of -- Command₃. -- {-# OPTIONS -v tc.pos:10 #-} open import Common.Product open import Common.List record ⊤ {a} : Set a where _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} → (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) → ((x : A) → C (g x)) f ∘ g = λ x → f (g x) postulate String : Set USL = List String data _∈_ a : USL → Set where z : ∀ {xs} → a ∈ (a ∷ xs) s : ∀ {b xs} → a ∈ xs → a ∈ (b ∷ xs) [Fields] : (args : USL) → Set₁ [Fields] [] = ⊤ [Fields] (_ ∷ args) = Set × [Fields] args [tabulate] : (args : USL) (ρ : {arg : _} (pr : arg ∈ args) → Set) → [Fields] args [tabulate] [] ρ = _ [tabulate] (arg ∷ args) ρ = ρ z , [tabulate] args (λ x → ρ (s x)) [Record] : (args : USL) (f : [Fields] args) → Set [Record] [] _ = ⊤ [Record] (hd ∷ args) (f , fs) = f × [Record] args fs record Fields (args : USL) : Set₁ where constructor mkFields field fields : [Fields] args open Fields public record Record (args : USL) (f : Fields args) : Set where constructor mkRecord field content : [Record] args (fields f) open Record public module WORKS where tabulate : {args : USL} (ρ : {arg : _} (pr : arg ∈ args) → Set) → Fields args tabulate {args = args} ρ = mkFields ([tabulate] args ρ) -- WORKS -- tabulate {args = args} = mkFields ∘ [tabulate] args -- FAILS mutual data Command₁ : Set where mkCommand : (modifierNames : USL) → Record modifierNames (tabulate (λ {s} _ → Modifier s)) → Command₁ record Command₂ : Set where inductive field modifierNames : USL modifiers : [Record] modifierNames ([tabulate] _ (λ {s} _ → Modifier s)) record Command₃ : Set where inductive field modifierNames : USL modifiers : Record modifierNames (tabulate (λ {s} _ → Modifier s)) data Modifier (name : String) : Set where command₁ : Command₁ → Modifier name command₂ : Command₂ → Modifier name command₃ : Command₃ → Modifier name module FAILS where tabulate : {args : USL} (ρ : {arg : _} (pr : arg ∈ args) → Set) → Fields args -- tabulate {args = args} ρ = mkFields ([tabulate] args ρ) -- WORKS tabulate {args = args} = mkFields ∘ [tabulate] args -- FAILS mutual data Command₁ : Set where mkCommand : (modifierNames : USL) → Record modifierNames (tabulate (λ {s} _ → Modifier s)) → Command₁ record Command₂ : Set where inductive field modifierNames : USL modifiers : [Record] modifierNames ([tabulate] _ (λ {s} _ → Modifier s)) record Command₃ : Set where inductive field modifierNames : USL modifiers : Record modifierNames (tabulate (λ {s} _ → Modifier s)) data Modifier (name : String) : Set where command₁ : Command₁ → Modifier name command₂ : Command₂ → Modifier name command₃ : Command₃ → Modifier name
{ "alphanum_fraction": 0.586102719, "avg_line_length": 28.7826086957, "ext": "agda", "hexsha": "527339568a03fa0663812b7fb47dfd35f000bbea", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1544.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1544.agda", "max_line_length": 84, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1544.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 1048, "size": 3310 }
module ReCaseSplit where data Bool : Set where true : Bool false : Bool maybe : Bool _func : Bool -> Bool maybe func = ? false func = false (true) func = true func2 : Bool -> Bool func2 = λ{false → false ; (true) → true} open import IO.Primitive func3 : IO Bool func3 = return false func4 : IO Bool func4 = do false <- func3 where true -> return true return false module SubModule where func5 : Bool -> Bool func5 maybe = ? func5 false = false func5 true = func6 true where func6 : Bool -> Bool func6 maybe = ? func6 false = false func6 true = true
{ "alphanum_fraction": 0.6313213703, "avg_line_length": 16.1315789474, "ext": "agda", "hexsha": "f6ebca664f4f84f72b12ebe5319c00d08ad6d34f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "omega12345/RefactorAgda", "max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/ReCaseSplit.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "omega12345/RefactorAgda", "max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/ReCaseSplit.agda", "max_line_length": 40, "max_stars_count": 5, "max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "omega12345/RefactorAgda", "max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/ReCaseSplit.agda", "max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z", "num_tokens": 179, "size": 613 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Equational.Theory module Fragment.Equational.Model.Base (Θ : Theory) where open import Fragment.Equational.Model.Satisfaction {Σ Θ} open import Fragment.Algebra.Algebra (Σ Θ) hiding (∥_∥/≈) open import Fragment.Algebra.Free (Σ Θ) open import Level using (Level; _⊔_; suc) open import Function using (_∘_) open import Data.Fin using (Fin) open import Data.Nat using (ℕ) open import Relation.Binary using (Setoid) private variable a ℓ : Level Models : Algebra {a} {ℓ} → Set (a ⊔ ℓ) Models S = ∀ {n} → (eq : eqs Θ n) → S ⊨ (Θ ⟦ eq ⟧ₑ) module _ (S : Setoid a ℓ) where record IsModel : Set (a ⊔ ℓ) where field isAlgebra : IsAlgebra S models : Models (algebra S isAlgebra) open IsAlgebra isAlgebra public record Model : Set (suc a ⊔ suc ℓ) where field ∥_∥/≈ : Setoid a ℓ isModel : IsModel ∥_∥/≈ ∥_∥ₐ : Algebra ∥_∥ₐ = algebra ∥_∥/≈ (IsModel.isAlgebra isModel) ∥_∥ₐ-models : Models ∥_∥ₐ ∥_∥ₐ-models = IsModel.models isModel open Algebra (algebra ∥_∥/≈ (IsModel.isAlgebra isModel)) hiding (∥_∥/≈) public open Model public
{ "alphanum_fraction": 0.6620450607, "avg_line_length": 24.0416666667, "ext": "agda", "hexsha": "07f8022555ab0dc7198a7ba5bc34de2255de072a", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Equational/Model/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Equational/Model/Base.agda", "max_line_length": 58, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Equational/Model/Base.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 428, "size": 1154 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Bisimilarity for Colists ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Codata.Colist.Bisimilarity where open import Level using (_⊔_) open import Size open import Codata.Thunk open import Codata.Colist open import Relation.Binary open import Relation.Binary.PropositionalEquality as Eq using (_≡_) data Bisim {a b r} {A : Set a} {B : Set b} (R : A → B → Set r) (i : Size) : (xs : Colist A ∞) (ys : Colist B ∞) → Set (r ⊔ a ⊔ b) where [] : Bisim R i [] [] _∷_ : ∀ {x y xs ys} → R x y → Thunk^R (Bisim R) i xs ys → Bisim R i (x ∷ xs) (y ∷ ys) module _ {a r} {A : Set a} {R : A → A → Set r} where reflexive : Reflexive R → ∀ {i} → Reflexive (Bisim R i) reflexive refl^R {i} {[]} = [] reflexive refl^R {i} {r ∷ rs} = refl^R ∷ λ where .force → reflexive refl^R module _ {a b} {A : Set a} {B : Set b} {r} {P : A → B → Set r} {Q : B → A → Set r} where symmetric : Sym P Q → ∀ {i} → Sym (Bisim P i) (Bisim Q i) symmetric sym^PQ [] = [] symmetric sym^PQ (p ∷ ps) = sym^PQ p ∷ λ where .force → symmetric sym^PQ (ps .force) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} {r} {P : A → B → Set r} {Q : B → C → Set r} {R : A → C → Set r} where transitive : Trans P Q R → ∀ {i} → Trans (Bisim P i) (Bisim Q i) (Bisim R i) transitive trans^PQR [] [] = [] transitive trans^PQR (p ∷ ps) (q ∷ qs) = trans^PQR p q ∷ λ where .force → transitive trans^PQR (ps .force) (qs .force) -- Pointwise Equality as a Bisimilarity ------------------------------------------------------------------------ module _ {ℓ} {A : Set ℓ} where infix 1 _⊢_≈_ _⊢_≈_ : ∀ i → Colist A ∞ → Colist A ∞ → Set ℓ _⊢_≈_ = Bisim _≡_ refl : ∀ {i} → Reflexive (i ⊢_≈_) refl = reflexive Eq.refl sym : ∀ {i} → Symmetric (i ⊢_≈_) sym = symmetric Eq.sym trans : ∀ {i} → Transitive (i ⊢_≈_) trans = transitive Eq.trans
{ "alphanum_fraction": 0.5053658537, "avg_line_length": 33.064516129, "ext": "agda", "hexsha": "5506f1102f04f4047da401bf24e5b2c215c92136", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist/Bisimilarity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist/Bisimilarity.agda", "max_line_length": 87, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist/Bisimilarity.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 729, "size": 2050 }
{-# OPTIONS --without-K --rewriting #-} module cw.examples.Examples where open import cw.examples.Empty public open import cw.examples.Sphere public open import cw.examples.Unit public
{ "alphanum_fraction": 0.7807486631, "avg_line_length": 23.375, "ext": "agda", "hexsha": "fc0279e069a4fe36a651e019b101079012460cfd", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/cw/examples/Examples.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_path": "theorems/cw/examples/Examples.agda", "max_line_length": 39, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "theorems/cw/examples/Examples.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 38, "size": 187 }
-- Andreas, 2017-01-13, issue #2402 -- Error message: incomplete pattern matching -- {-# OPTIONS -v tc.cover:20 #-} open import Common.Bool module _ (A B C D E F G H I J K L M O P Q R S T U V W X Y Z : Set) where test : Bool → Bool test true = false -- Reports: -- Incomplete pattern matching for test. Missing cases: -- test _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ false -- Expected: -- Incomplete pattern matching for test. Missing cases: -- test false
{ "alphanum_fraction": 0.6491596639, "avg_line_length": 22.6666666667, "ext": "agda", "hexsha": "9694e9f15d6ea74caab19c065107030f14498d6f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue2402-1.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue2402-1.agda", "max_line_length": 72, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue2402-1.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 147, "size": 476 }
{-# OPTIONS --cubical --safe #-} module Relation.Nullary.Discrete.Properties where open import Relation.Nullary.Discrete open import Relation.Nullary.Stable.Properties using (Stable≡→isSet) open import Relation.Nullary.Decidable.Properties using (Dec→Stable; isPropDec) open import HLevels open import Level open import Path Discrete→isSet : Discrete A → isSet A Discrete→isSet d = Stable≡→isSet (λ x y → Dec→Stable (x ≡ y) (d x y)) isPropDiscrete : isProp (Discrete A) isPropDiscrete f g i x y = isPropDec (Discrete→isSet f x y) (f x y) (g x y) i
{ "alphanum_fraction": 0.7450628366, "avg_line_length": 27.85, "ext": "agda", "hexsha": "7d8ef3e75de78e620cba322d9c1a87b412a8f069", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Relation/Nullary/Discrete/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Relation/Nullary/Discrete/Properties.agda", "max_line_length": 79, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Relation/Nullary/Discrete/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 172, "size": 557 }
-- Andreas, 2014-05-20 Triggered by Andrea Vezzosi & NAD {-# OPTIONS --copatterns #-} -- {-# OPTIONS -v tc.conv.coerce:10 #-} open import Common.Size -- Andreas, 2015-03-16: currently forbidden -- Size≤ : Size → SizeUniv -- Size≤ i = Size< ↑ i postulate Dom : Size → Set mapDom : ∀ i (j : Size< (↑ i)) → Dom i → Dom j record ∞Dom i : Set where field force : ∀ (j : Size< i) → Dom j ∞mapDom : ∀ i (j : Size< (↑ i)) → ∞Dom i → ∞Dom j ∞Dom.force (∞mapDom i j x) k = mapDom k k (∞Dom.force x k) -- The second k on the rhs has type -- k : Size< j -- and should have type -- k : Size≤ k = Size< ↑ k -- Since j <= ↑ k does not hold (we have only k < j), -- we cannot do the usual subtyping Size< j <= Size≤ k, -- but we have to use the "singleton type property" -- k : Size< ↑ k
{ "alphanum_fraction": 0.5827067669, "avg_line_length": 26.6, "ext": "agda", "hexsha": "1236419d33305dd973f66dc1ae7acf805f0eb748", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1136.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue1136.agda", "max_line_length": 58, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue1136.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 289, "size": 798 }
{-# OPTIONS --without-K --rewriting #-} open import PathInduction module Pushout {i} {j} {k} where {-<Pushout>-} record Span : Type (lsucc (lmax (lmax i j) k)) where constructor span field A : Type i B : Type j C : Type k f : C → A g : C → B postulate Pushout : Span → Type (lmax (lmax i j) k) module _ {d : Span} where open Span d postulate inl : A → Pushout d inr : B → Pushout d push : (c : C) → inl (f c) == inr (g c) module _ {l} {P : Pushout d → Type l} (inl* : (a : A) → P (inl a)) (inr* : (b : B) → P (inr b)) (push* : (c : C) → inl* (f c) == inr* (g c) [ P ↓ push c ]) where postulate Pushout-elim : (x : Pushout d) → P x inl-β : (a : A) → (Pushout-elim (inl a) ↦ inl* a) inr-β : (b : B) → (Pushout-elim (inr b) ↦ inr* b) {-# REWRITE inl-β #-} {-# REWRITE inr-β #-} push-βd' : (c : C) → (apd Pushout-elim (push c) == push* c) {-</>-} -- Makes the arguments of [push-βd] implicit push-βd : ∀ {l} {P : Pushout d → Type l} {inl* : (a : A) → P (inl a)} {inr* : (b : B) → P (inr b)} {push* : (c : C) → inl* (f c) == inr* (g c) [ P ↓ push c ]} → (c : C) → apd (Pushout-elim inl* inr* push*) (push c) == push* c push-βd = push-βd' _ _ _ -- Non-dependent elimination rule and corresponding reduction rule {-<PushoutRec>-} Pushout-rec : ∀ {l} {D : Type l} (inl* : A → D) (inr* : B → D) (push* : (c : C) → inl* (f c) == inr* (g c)) → Pushout d → D Pushout-rec inl* inr* push* = Pushout-elim inl* inr* (λ c → ↓-cst-in (push* c)) push-β : ∀ {l} {D : Type l} {inl* : A → D} {inr* : B → D} {push* : (c : C) → inl* (f c) == inr* (g c)} → (c : C) → ap (Pushout-rec inl* inr* push*) (push c) == push* c push-β c = apd=cst-in (push-βd c) {-</>-}
{ "alphanum_fraction": 0.4679144385, "avg_line_length": 27.5, "ext": "agda", "hexsha": "77e38d2a91b600340c72122f1dcb9bdeef1f85f0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guillaumebrunerie/JamesConstruction", "max_forks_repo_path": "Pushout.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guillaumebrunerie/JamesConstruction", "max_issues_repo_path": "Pushout.agda", "max_line_length": 81, "max_stars_count": 5, "max_stars_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guillaumebrunerie/JamesConstruction", "max_stars_repo_path": "Pushout.agda", "max_stars_repo_stars_event_max_datetime": "2018-11-16T22:10:16.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-07T04:34:52.000Z", "num_tokens": 800, "size": 1870 }
{-# OPTIONS --without-K --safe #-} module Definition.Conversion.Reduction where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Typed.RedSteps open import Definition.Conversion -- Weak head expansion of algorithmic equality of types. reductionConv↑ : ∀ {A A′ B B′ Γ} → Γ ⊢ A ⇒* A′ → Γ ⊢ B ⇒* B′ → Γ ⊢ A′ [conv↑] B′ → Γ ⊢ A [conv↑] B reductionConv↑ A⇒* B⇒* ([↑] A″ B″ D D′ whnfA″ whnfB″ A″<>B″) = [↑] A″ B″ (A⇒* ⇨* D) (B⇒* ⇨* D′) whnfA″ whnfB″ A″<>B″ -- Weak head expansion of algorithmic equality of terms. reductionConv↑Term : ∀ {t t′ u u′ A B Γ} → Γ ⊢ A ⇒* B → Γ ⊢ t ⇒* t′ ∷ B → Γ ⊢ u ⇒* u′ ∷ B → Γ ⊢ t′ [conv↑] u′ ∷ B → Γ ⊢ t [conv↑] u ∷ A reductionConv↑Term A⇒* t⇒* u⇒* ([↑]ₜ B′ t″ u″ D d d′ whnfB′ whnft″ whnfu″ t″<>u″) = [↑]ₜ B′ t″ u″ (A⇒* ⇨* D) ((conv* t⇒* (subset* D)) ⇨∷* d) ((conv* u⇒* (subset* D)) ⇨∷* d′) whnfB′ whnft″ whnfu″ t″<>u″
{ "alphanum_fraction": 0.4753363229, "avg_line_length": 32.7941176471, "ext": "agda", "hexsha": "51c3d0bf86d322c1e3e28d750c73251810e3b8d2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Vtec234/logrel-mltt", "max_forks_repo_path": "Definition/Conversion/Reduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Vtec234/logrel-mltt", "max_issues_repo_path": "Definition/Conversion/Reduction.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Vtec234/logrel-mltt", "max_stars_repo_path": "Definition/Conversion/Reduction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 448, "size": 1115 }
-- 2011-09-15 posted by Nisse, variant of Issue292e -- {-# OPTIONS --show-implicit -v tc.lhs.unify:15 #-} module Issue292-16b where data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x postulate A : Set f : A → A data C (A : Set)(f : A → A) : A → Set where c : ∀ x → C A f (f x) record Box : Set where constructor box field a : A b : C A f a test : ∀ {x₁ x₂} → box (f x₁) (c x₁) ≡ box (f x₂) (c x₂) → x₁ ≡ x₂ test refl = refl -- We recover from the heteogenerous -- -- c x₁ : C A f (f x₁) =?= c₂ x₂ : C A f (f x₂) -- -- to the homogeneous -- -- x₁ =?= x₂ : A -- -- since the parameters to C are syntactically equal on lhs and rhs
{ "alphanum_fraction": 0.5595776772, "avg_line_length": 20.0909090909, "ext": "agda", "hexsha": "e69316f9802d05cd983aac485fa0b8a3d4aaec2f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue292-16b.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue292-16b.agda", "max_line_length": 67, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue292-16b.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 269, "size": 663 }
{-# OPTIONS --safe --warning=error --without-K --guardedness #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Setoids.Setoids open import Rings.Definition open import Rings.Orders.Partial.Definition open import Rings.Orders.Total.Definition open import Groups.Definition open import Fields.Fields open import Sets.EquivalenceRelations open import Sequences open import Functions.Definition open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Setoids.Orders.Partial.Definition open import Setoids.Orders.Total.Definition module Fields.CauchyCompletion.Definition {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) where open Setoid S open SetoidTotalOrder (TotallyOrderedRing.total order) open SetoidPartialOrder pOrder open Equivalence eq open TotallyOrderedRing order open Ring R open Group additiveGroup open Field F open import Rings.Orders.Total.Lemmas order open import Rings.Orders.Total.AbsoluteValue order open import Rings.Orders.Total.Cauchy order open import Groups.Lemmas additiveGroup cauchyWellDefined : {s1 s2 : Sequence A} → ((m : ℕ) → index s1 m ∼ index s2 m) → cauchy s1 → cauchy s2 cauchyWellDefined {s1} {s2} prop c e 0<e with c e 0<e ... | N , pr = N , λ {m} {n} N<m N<n → <WellDefined (absWellDefined _ _ (+WellDefined (prop m) (inverseWellDefined (prop n)))) reflexive (pr N<m N<n) record CauchyCompletion : Set (m ⊔ o) where field elts : Sequence A converges : (cauchy elts) injection : A → CauchyCompletion CauchyCompletion.elts (injection a) = constSequence a CauchyCompletion.converges (injection a) = (λ ε 0<e → 0 , λ {m} {n} _ _ → <WellDefined (symmetric (identityOfIndiscernablesRight _∼_ (absWellDefined (index (constSequence a) m + inverse (index (constSequence a) n)) 0R (t m n)) absZero)) reflexive 0<e) where t : (m n : ℕ) → index (constSequence a) m + inverse (index (constSequence a) n) ∼ 0R t m n = identityOfIndiscernablesLeft _∼_ (identityOfIndiscernablesLeft _∼_ invRight (equalityCommutative (applyEquality (λ i → a + inverse i) (indexAndConst a n)))) (applyEquality (_+ inverse (index (constSequence a) n)) (equalityCommutative (indexAndConst a m))) -- Some slightly odd things here relating to equality rather than equivalence. Ultimately this is here so we can say Q → R is a genuine injection, not just a setoid one. private lemma : {x y : CauchyCompletion} → x ≡ y → CauchyCompletion.elts x ≡ CauchyCompletion.elts y lemma {x} {.x} refl = refl CInjection' : Injection injection CInjection' pr = headInjective (lemma pr)
{ "alphanum_fraction": 0.742375314, "avg_line_length": 48.0517241379, "ext": "agda", "hexsha": "e0a6a6587b8bc1f61754309f889ee569ceab7a4e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Fields/CauchyCompletion/Definition.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Fields/CauchyCompletion/Definition.agda", "max_line_length": 298, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Fields/CauchyCompletion/Definition.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 849, "size": 2787 }
--2010-09-28 module AbsurdIrrelevance where data Empty : Set where absurd : {A : Set} -> .Empty -> A absurd ()
{ "alphanum_fraction": 0.652173913, "avg_line_length": 12.7777777778, "ext": "agda", "hexsha": "24773826aada8d914225a4b6249d572d7ddb7023", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/AbsurdIrrelevance.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/succeed/AbsurdIrrelevance.agda", "max_line_length": 33, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/AbsurdIrrelevance.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 40, "size": 115 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Int.Base where open import Cubical.Core.Everything open import Cubical.Data.Nat data ℤ : Type₀ where pos : (n : ℕ) → ℤ negsuc : (n : ℕ) → ℤ neg : (n : ℕ) → ℤ neg zero = pos zero neg (suc n) = negsuc n infix 100 -_ -_ : ℕ → ℤ -_ = neg {-# DISPLAY pos n = n #-} {-# DISPLAY negsuc n = - (suc n) #-} sucInt : ℤ → ℤ sucInt (pos n) = pos (suc n) sucInt (negsuc zero) = pos zero sucInt (negsuc (suc n)) = negsuc n predInt : ℤ → ℤ predInt (pos zero) = negsuc zero predInt (pos (suc n)) = pos n predInt (negsuc n) = negsuc (suc n) -- Natural number and negative integer literals for ℤ open import Cubical.Data.Nat.Literals public instance fromNatℤ : FromNat ℤ fromNatℤ = record { Constraint = λ _ → ⊤ ; fromNat = λ n → pos n } instance negativeℤ : Negative ℤ negativeℤ = record { Constraint = λ _ → ⊤ ; fromNeg = λ n → neg n }
{ "alphanum_fraction": 0.6213903743, "avg_line_length": 21.25, "ext": "agda", "hexsha": "435c035a5a9f25557d808476ee64c45a557de8d3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bijan2005/univalent-foundations", "max_forks_repo_path": "Cubical/Data/Int/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bijan2005/univalent-foundations", "max_issues_repo_path": "Cubical/Data/Int/Base.agda", "max_line_length": 69, "max_stars_count": null, "max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bijan2005/univalent-foundations", "max_stars_repo_path": "Cubical/Data/Int/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 346, "size": 935 }
open import Oscar.Prelude module Oscar.Class.[IsExtensionB] where record [IsExtensionB] {a} {A : Ø a} {b} (B : A → Ø b) : Ø₀ where constructor ∁ no-eta-equality
{ "alphanum_fraction": 0.6494252874, "avg_line_length": 14.5, "ext": "agda", "hexsha": "e429c4037dce0fa1bc947bfc80a9f8490524b402", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/[IsExtensionB].agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/[IsExtensionB].agda", "max_line_length": 39, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/[IsExtensionB].agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 63, "size": 174 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import stash.modalities.gbm.GbmUtil module stash.modalities.gbm.PushoutMono where -- -- The goal of this file is to prove the following: -- Suppose we have a pushout -- -- g -- C ------> B -- v | -- | | -- f | | -- v v -- A ------> D -- -- and the map f is a monomorphism. Then the square -- is also a pullback. -- is-mono : ∀ {i j} {A : Type i} {B : Type j} → (A → B) → Type _ is-mono {B = B} f = (b : B) → has-level (S ⟨-2⟩) (hfiber f b) mono-eq : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a₀ a₁ : A} (p : f a₀ == f a₁) → is-mono f → a₀ == a₁ mono-eq f {a₀} {a₁} p ism = ! (fst= (fst (ism (f a₁) (a₁ , idp) (a₀ , p)))) mono-eq-idp : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a : A} → (is-m : is-mono f) → mono-eq f {a₀ = a} idp is-m == idp mono-eq-idp f {a} ism = ap (λ x → ! (fst= x)) (snd (ism (f a) (a , idp) (a , idp)) idp) mono-eq-ap : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a₀ a₁ : A} (p : f a₀ == f a₁) → (is-m : is-mono f) → ap f (mono-eq f p is-m) == p mono-eq-ap f {a₀} {a₁} p ism = ap f (! (fst= α)) =⟨ ! (!-ap f (fst= α)) ⟩ ! (ap f (fst= α)) =⟨ ! (∙-unit-r (! (ap f (fst= α)))) ⟩ ! (ap f (fst= α)) ∙ idp =⟨ ↓-app=cst-out (snd= α) |in-ctx (λ x → ! (ap f (fst= α)) ∙ x) ⟩ ! (ap f (fst= α)) ∙ ap f (fst= α) ∙ p =⟨ ! (∙-assoc (! (ap f (fst= α))) (ap f (fst= α)) p) ⟩ (! (ap f (fst= α)) ∙ ap f (fst= α)) ∙ p =⟨ !-inv-l (ap f (fst= α)) |in-ctx (λ x → x ∙ p) ⟩ p ∎ where α = fst (ism (f a₁) (a₁ , idp) (a₀ , p)) ap-lem : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} (f : Σ A B → C) {a₀ a₁ : A} {p : a₀ == a₁} {b₀ : B a₀} {b₁ : B a₁} (q : b₀ == b₁ [ B ↓ p ]) → ap f (pair= p q) == ↓-cst-out (↓-Π-out (apd (curry f) p) q) ap-lem f {p = idp} idp = idp Lift-Unit-is-contr : ∀ {i} → is-contr (Lift {j = i} ⊤) Lift-Unit-is-contr = equiv-preserves-level (lower-equiv ⁻¹) Unit-is-contr Lift-Unit-is-prop : ∀ {i} → is-prop (Lift {j = i} ⊤) Lift-Unit-is-prop = contr-is-prop Lift-Unit-is-contr module MonoLemma {i} (s : Span {i} {i} {i}) (m : is-mono (Span.f s)) where open Span s private D = Pushout s mleft : A → D mleft = left mright : B → D mright = right mglue : (c : C) → mleft (f c) == mright (g c) mglue c = glue c -- Construct a fibration over the pushout -- whose total space is equivalent to B glue-equiv : (c : C) → hfiber f (f c) ≃ Lift {j = i} ⊤ glue-equiv c = contr-equiv-LiftUnit (inhab-prop-is-contr (c , idp) (m (f c))) -- Now, I claim that the values of this fibration are props. -- How do you prove this? module B' = PushoutRec {d = s} (hfiber f) (cst (Lift ⊤)) (ua ∘ glue-equiv) B' : (d : D) → Type i B' = B'.f B'-β : (c : C) → ap B' (glue c) == ua (glue-equiv c) B'-β c = B'.glue-β c B'-is-prop : (d : D) → is-prop (B' d) B'-is-prop = Pushout-elim (λ a → m a) (λ b → Lift-Unit-is-prop) (λ c → prop-lemma (λ z → is-prop (B' z) , is-prop-is-prop) (mglue c) (m (f c)) Lift-Unit-is-prop) B'-prop : (d : D) → hProp i B'-prop d = B' d , B'-is-prop d B'-pth-in : ∀ {a b} (p : mleft a == mright b) (x : B' (mleft a)) (y : B' (mright b)) → x == y [ B' ↓ p ] B'-pth-in p x y = prop-lemma B'-prop p x y B'-pth-in' : ∀ {a b} (p : mright b == mleft a) (x : B' (mleft a)) (y : B' (mright b)) → y == x [ B' ↓ p ] B'-pth-in' p x y = prop-lemma B'-prop p y x cpth : (c : C) → (c , idp) == (lift unit) [ B' ↓ glue c ] cpth c = fst (pths-ovr-contr B'-prop (glue c) (c , idp) (lift unit)) -- Yeah, these triples of data seem to come up a bunch -- the point is, such data is contractible... data-contr : (c : C) → is-contr (Σ (B' (left (f c))) (λ l → Σ (B' (right (g c))) (λ r → l == r [ B' ↓ glue c ]))) data-contr c = Σ-level (inhab-prop-is-contr (c , idp) (m (f c))) (λ l → Σ-level Lift-Unit-is-contr (λ r → pths-ovr-contr B'-prop (glue c) l r)) data-elim : (c : C) (P : (l : B' (left (f c))) (r : B' (right (g c))) → (l == r [ B' ↓ glue c ]) → Type i) → (t : Σ (B' (left (f c))) (λ l → Σ (B' (right (g c))) (λ r → l == r [ B' ↓ glue c ]))) → P (fst t) (fst (snd t)) (snd (snd t)) → (l : B' (left (f c))) → (r : B' (right (g c))) → (q : l == r [ B' ↓ glue c ]) → P l r q data-elim c P t x l r q = transport (λ { (l₀ , r₀ , q₀) → P l₀ r₀ q₀ }) (contr-has-all-paths (data-contr c) _ _) x module _ where private to : B → Σ D B' to b = mright b , lift unit module From = PushoutElim {d = s} {P = λ d → B' d → B} (λ a e → g (fst e)) (λ b _ → b) (λ c → ↓-Π-in (λ {l} {r} q → ↓-cst-in (ap g (mono-eq f (snd l) m)))) from : Σ D B' → B from = uncurry $ From.f to-from : (db : Σ D B') → to (from db) == db to-from = uncurry $ Pushout-elim lem₀ (λ b _ → idp) (λ c → ↓-Π-in (λ {l} {r} q → ↓-app=idf-in (lem₁ c l r q))) where lem₀ : (a : A) (l : B' (left a)) → to (from (left a , l)) == left a , l lem₀ .(f c) (c , idp) = ! (pair= (mglue c) (cpth c)) P : (c : C) (l : B' (left (f c))) (r : B' (right (g c))) (q : l == r [ B' ↓ glue c ]) → Type i P c l r q = lem₀ (f c) l ∙' pair= (glue c) q == ap (λ v → to (from v)) (pair= (glue c) q) ∙ idp lem₂ : (c : C) → P c (c , idp) (lift unit) (cpth c) lem₂ c = ! (pair= (glue c) (cpth c)) ∙' pair= (glue c) (cpth c) =⟨ !-inv'-l (pair= (glue c) (cpth c)) ⟩ idp =⟨ ! (mono-eq-idp f m) |in-ctx (λ x → ap to (ap g x)) ⟩ ap to (ap g (mono-eq f idp m)) =⟨ ! (↓-cst-β (pair= (glue c) (cpth c)) (ap g (mono-eq f idp m))) |in-ctx (λ x → ap to x) ⟩ ap to (↓-cst-out (↓-cst-in {p = (pair= (glue c) (cpth c))} (ap g (mono-eq f idp m)))) =⟨ ! (↓-Π-β (λ {l} {r} q → ↓-cst-in (ap g (mono-eq f (snd l) m))) (cpth c)) |in-ctx (λ x → ap to (↓-cst-out x)) ⟩ ap to (↓-cst-out (↓-Π-out (↓-Π-in (λ {l} {r} q → ↓-cst-in (ap g (mono-eq f (snd l) m)))) (cpth c))) =⟨ ! (From.glue-β c) |in-ctx (λ x → ap to (↓-cst-out (↓-Π-out x (cpth c)))) ⟩ ap to (↓-cst-out (↓-Π-out (apd (curry from) (glue c)) (cpth c))) =⟨ ! (ap-lem from (cpth c)) |in-ctx (λ x → ap to x) ⟩ ap to (ap from (pair= (glue c) (cpth c))) =⟨ ∘-ap to from (pair= (glue c) (cpth c)) ⟩ ap (to ∘ from) (pair= (glue c) (cpth c)) =⟨ ! (∙-unit-r _) ⟩ ap (to ∘ from) (pair= (glue c) (cpth c)) ∙ idp ∎ lem₁ : (c : C) (l : B' (left (f c))) (r : B' (right (g c))) (q : l == r [ B' ↓ glue c ]) → lem₀ (f c) l ∙' pair= (glue c) q == ap (λ v → to (from v)) (pair= (glue c) q) ∙ idp lem₁ c l r q = data-elim c (P c) ((c , idp) , (lift unit , cpth c)) (lem₂ c) l r q B≃B' : B ≃ Σ D B' B≃B' = equiv to from to-from (λ b → idp) -- From the above equivalence, we can prove that -- mright is also a mono mright-is-mono : is-mono mright mright-is-mono d = equiv-preserves-level (lem ⁻¹ ∘e (hfiber-fst d) ⁻¹) (B'-is-prop d) where lem : hfiber mright d ≃ hfiber fst d lem = hfiber-sq-eqv mright fst (fst B≃B') (idf D) (comm-sqr (λ b → idp)) (snd B≃B') (idf-is-equiv D) d -- Pulling back over A, we should have a space -- equivalent to C as well as the path spaces -- we are interested in. C' : Type i C' = Σ A (B' ∘ mleft) -- Given (b : B) and an element it is equal to in the -- the pushout, we can find an element in the fiber which -- witnesses that equaltiy witness-for : ∀ {a b} (p : mleft a == mright b) → hfiber f a witness-for p = transport! B' p (lift unit) -- Using the fact that mright is a mono, we can -- find a proof of the following witness-for-coh₀ : ∀ {a b} (p : mleft a == mright b) → g (fst (witness-for p)) == b witness-for-coh₀ {a} {b} p = mono-eq mright lem mright-is-mono where c : C c = fst (witness-for p) lem : mright (g c) == mright b lem = ! (mglue c) ∙ ap mleft (snd (witness-for p)) ∙ p witness-for-coh₁ : ∀ {a b} (p : mleft a == mright b) → (! (ap mleft (snd (witness-for p))) ∙ mglue (fst (witness-for p))) == p [ (λ ab → mleft (fst ab) == mright (snd ab)) ↓ (ap (λ x → (a , x)) (witness-for-coh₀ p)) ] witness-for-coh₁ {a} p = ↓-ap-in _ (λ b₀ → (a , b₀)) (↓-cst=app-in calc) where α = ap mleft (snd (witness-for p)) β = mglue (fst (witness-for p)) calc = (! α ∙ β) ∙' ap mright (witness-for-coh₀ p) =⟨ mono-eq-ap mright (! β ∙ α ∙ p) mright-is-mono |in-ctx (λ x → (! α ∙ β) ∙' x) ⟩ (! α ∙ β) ∙' ! β ∙ α ∙ p =⟨ ∙'=∙ (! α ∙ β) (! β ∙ α ∙ p) ⟩ (! α ∙ β) ∙ ! β ∙ α ∙ p =⟨ ∙-assoc (! α) β (! β ∙ α ∙ p) ⟩ ! α ∙ β ∙ ! β ∙ α ∙ p =⟨ ! (∙-assoc β (! β) (α ∙ p)) |in-ctx (λ x → ! α ∙ x) ⟩ ! α ∙ (β ∙ ! β) ∙ α ∙ p =⟨ !-inv-r β |in-ctx (λ x → ! α ∙ x ∙ α ∙ p) ⟩ ! α ∙ α ∙ p =⟨ ! (∙-assoc (! α) α p) ⟩ (! α ∙ α) ∙ p =⟨ !-inv-l α |in-ctx (λ x → x ∙ p) ⟩ p ∎ C'-equiv-pths : C' ≃ Σ (A × B) (λ ab → mleft (fst ab) == mright (snd ab)) C'-equiv-pths = equiv to from to-from from-to where to : C' → Σ (A × B) (λ ab → mleft (fst ab) == mright (snd ab)) to (a , c , p) = (a , g c) , ! (ap mleft p) ∙ mglue c from : Σ (A × B) (λ ab → mleft (fst ab) == mright (snd ab)) → C' from ((a , b) , p) = a , witness-for p to-from : (x : Σ (A × B) (λ ab → mleft (fst ab) == mright (snd ab))) → to (from x) == x to-from ((a , b) , p) = pair= (pair= idp (witness-for-coh₀ p)) (witness-for-coh₁ p) from-to : (c' : C') → from (to c') == c' from-to (a , c , p) = pair= idp (fst (m _ _ (c , p))) C-equiv-C' : C ≃ C' C-equiv-C' = equiv to from to-from from-to where to : C → C' to c = f c , (c , idp) from : C' → C from (a , c , p) = c to-from : (c' : C') → to (from c') == c' to-from (a , c , p) = pair= p (fst (pths-ovr-contr (λ a → hfiber f a , m a) p (c , idp) (c , p))) from-to : (c : C) → from (to c) == c from-to c = idp -- Combining the two equivalences from above -- gives us the result we want. pushout-mono-is-pullback : C ≃ Σ (A × B) (λ ab → mleft (fst ab) == mright (snd ab)) pushout-mono-is-pullback = C'-equiv-pths ∘e C-equiv-C'
{ "alphanum_fraction": 0.4292687256, "avg_line_length": 43.0076335878, "ext": "agda", "hexsha": "efe7025ec123b7e1f381c97d1820f5c7793e7adb", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/stash/modalities/gbm/PushoutMono.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_path": "theorems/stash/modalities/gbm/PushoutMono.agda", "max_line_length": 141, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "theorems/stash/modalities/gbm/PushoutMono.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 4521, "size": 11268 }
module Examples.Syntax where open import Agda.Builtin.Equality using (_≡_; refl) open import FFI.Data.String using (_++_) open import Luau.Syntax using (var; _$_; return; nil; function_is_end; local_←_; done; _∙_; _⟨_⟩) open import Luau.Syntax.ToString using (exprToString; blockToString) ex1 : exprToString(function "" ⟨ var "x" ⟩ is return (var "f" $ var "x") ∙ done end) ≡ "function(x)\n" ++ " return f(x)\n" ++ "end" ex1 = refl ex2 : blockToString(local var "x" ← nil ∙ return (var "x") ∙ done) ≡ "local x = nil\n" ++ "return x" ex2 = refl ex3 : blockToString(function "f" ⟨ var "x" ⟩ is return (var "x") ∙ done end ∙ return (var "f") ∙ done) ≡ "local function f(x)\n" ++ " return x\n" ++ "end\n" ++ "return f" ex3 = refl
{ "alphanum_fraction": 0.628, "avg_line_length": 30, "ext": "agda", "hexsha": "4ffcf4c504c4c87cf88305ef22b2f293817e678b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Tr4shh/Roblox-Luau", "max_forks_repo_path": "prototyping/Examples/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Tr4shh/Roblox-Luau", "max_issues_repo_path": "prototyping/Examples/Syntax.agda", "max_line_length": 104, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Tr4shh/Roblox-Luau", "max_stars_repo_path": "prototyping/Examples/Syntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 263, "size": 750 }
module general-exercises.RunningHaskellCode where -- To compile code: stack exec -- agda general-exercises/RunningHaskellCode.agda -c open import Data.String using (String) open import Agda.Builtin.Unit using (⊤) -- Working directly with Haskell code, kinda dangerous stuff -- -- This didn't actually work because all Agda stuff is wrapped around colists -- and there is even more wrapping around printError to make it work. It is not -- that it is impossible, it is just a matter of copying the code from -- `IO.Primitive`, which I don't want to do right now -- --open import Agda.Builtin.IO using (IO) -- --{-# FOREIGN GHC import qualified System.IO as SIO #-} --{-# FOREIGN GHC import qualified Data.Text #-} -- --postulate printError : String → IO ⊤ -- --{-# COMPILE GHC printError = SIO.hPutStrLn SIO.stderr $ Data.Text.unpack #-} -- --main = printError "Printing to stderr!" -- Using the Standard Library open import IO using (run; putStrLn) main = run (putStrLn "Hello freaking World!") -- Exporting Agda binaries to use in Haskell code --open import Data.Nat using (ℕ; suc; zero) -- --double : ℕ → ℕ --double zero = zero --double (suc n) = suc (suc (double n)) --{-# COMPILE GHC double as doubleNat #-}
{ "alphanum_fraction": 0.7156943303, "avg_line_length": 32.0263157895, "ext": "agda", "hexsha": "16eced5423021fb83b67b3dfc0404cb55b4428fa", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "helq/old_code", "max_forks_repo_path": "proglangs-learning/Agda/general-exercises/RunningHaskellCode.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z", "max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z", "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "helq/old_code", "max_issues_repo_path": "proglangs-learning/Agda/general-exercises/RunningHaskellCode.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "helq/old_code", "max_stars_repo_path": "proglangs-learning/Agda/general-exercises/RunningHaskellCode.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 310, "size": 1217 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Some algebraic structures (not packed up with sets, operations, -- etc.) ------------------------------------------------------------------------ open import Relation.Binary module Algebra.Structures where import Algebra.FunctionProperties as FunctionProperties open import Data.Product open import Function open import Level using (_⊔_) import Relation.Binary.EqReasoning as EqR open FunctionProperties using (Op₁; Op₂) ------------------------------------------------------------------------ -- One binary operation record IsSemigroup {a ℓ} {A : Set a} (≈ : Rel A ℓ) (∙ : Op₂ A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isEquivalence : IsEquivalence ≈ assoc : Associative ∙ ∙-cong : ∙ Preserves₂ ≈ ⟶ ≈ ⟶ ≈ open IsEquivalence isEquivalence public record IsMonoid {a ℓ} {A : Set a} (≈ : Rel A ℓ) (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isSemigroup : IsSemigroup ≈ ∙ identity : Identity ε ∙ open IsSemigroup isSemigroup public record IsCommutativeMonoid {a ℓ} {A : Set a} (≈ : Rel A ℓ) (_∙_ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isSemigroup : IsSemigroup ≈ _∙_ identityˡ : LeftIdentity ε _∙_ comm : Commutative _∙_ open IsSemigroup isSemigroup public identity : Identity ε _∙_ identity = (identityˡ , identityʳ) where open EqR (record { isEquivalence = isEquivalence }) identityʳ : RightIdentity ε _∙_ identityʳ = λ x → begin (x ∙ ε) ≈⟨ comm x ε ⟩ (ε ∙ x) ≈⟨ identityˡ x ⟩ x ∎ isMonoid : IsMonoid ≈ _∙_ ε isMonoid = record { isSemigroup = isSemigroup ; identity = identity } record IsGroup {a ℓ} {A : Set a} (≈ : Rel A ℓ) (_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ infixl 7 _-_ field isMonoid : IsMonoid ≈ _∙_ ε inverse : Inverse ε _⁻¹ _∙_ ⁻¹-cong : _⁻¹ Preserves ≈ ⟶ ≈ open IsMonoid isMonoid public _-_ : FunctionProperties.Op₂ A x - y = x ∙ (y ⁻¹) record IsAbelianGroup {a ℓ} {A : Set a} (≈ : Rel A ℓ) (∙ : Op₂ A) (ε : A) (⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isGroup : IsGroup ≈ ∙ ε ⁻¹ comm : Commutative ∙ open IsGroup isGroup public isCommutativeMonoid : IsCommutativeMonoid ≈ ∙ ε isCommutativeMonoid = record { isSemigroup = isSemigroup ; identityˡ = proj₁ identity ; comm = comm } ------------------------------------------------------------------------ -- Two binary operations record IsNearSemiring {a ℓ} {A : Set a} (≈ : Rel A ℓ) (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field +-isMonoid : IsMonoid ≈ + 0# *-isSemigroup : IsSemigroup ≈ * distribʳ : * DistributesOverʳ + zeroˡ : LeftZero 0# * open IsMonoid +-isMonoid public renaming ( assoc to +-assoc ; ∙-cong to +-cong ; isSemigroup to +-isSemigroup ; identity to +-identity ) open IsSemigroup *-isSemigroup public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ) record IsSemiringWithoutOne {a ℓ} {A : Set a} (≈ : Rel A ℓ) (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field +-isCommutativeMonoid : IsCommutativeMonoid ≈ + 0# *-isSemigroup : IsSemigroup ≈ * distrib : * DistributesOver + zero : Zero 0# * open IsCommutativeMonoid +-isCommutativeMonoid public hiding (identityˡ) renaming ( assoc to +-assoc ; ∙-cong to +-cong ; isSemigroup to +-isSemigroup ; identity to +-identity ; isMonoid to +-isMonoid ; comm to +-comm ) open IsSemigroup *-isSemigroup public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ) isNearSemiring : IsNearSemiring ≈ + * 0# isNearSemiring = record { +-isMonoid = +-isMonoid ; *-isSemigroup = *-isSemigroup ; distribʳ = proj₂ distrib ; zeroˡ = proj₁ zero } record IsSemiringWithoutAnnihilatingZero {a ℓ} {A : Set a} (≈ : Rel A ℓ) (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field -- Note that these structures do have an additive unit, but this -- unit does not necessarily annihilate multiplication. +-isCommutativeMonoid : IsCommutativeMonoid ≈ + 0# *-isMonoid : IsMonoid ≈ * 1# distrib : * DistributesOver + open IsCommutativeMonoid +-isCommutativeMonoid public hiding (identityˡ) renaming ( assoc to +-assoc ; ∙-cong to +-cong ; isSemigroup to +-isSemigroup ; identity to +-identity ; isMonoid to +-isMonoid ; comm to +-comm ) open IsMonoid *-isMonoid public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ; isSemigroup to *-isSemigroup ; identity to *-identity ) record IsSemiring {a ℓ} {A : Set a} (≈ : Rel A ℓ) (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero ≈ + * 0# 1# zero : Zero 0# * open IsSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero public isSemiringWithoutOne : IsSemiringWithoutOne ≈ + * 0# isSemiringWithoutOne = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isSemigroup = *-isSemigroup ; distrib = distrib ; zero = zero } open IsSemiringWithoutOne isSemiringWithoutOne public using (isNearSemiring) record IsCommutativeSemiringWithoutOne {a ℓ} {A : Set a} (≈ : Rel A ℓ) (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isSemiringWithoutOne : IsSemiringWithoutOne ≈ + * 0# *-comm : Commutative * open IsSemiringWithoutOne isSemiringWithoutOne public record IsCommutativeSemiring {a ℓ} {A : Set a} (≈ : Rel A ℓ) (_+_ _*_ : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field +-isCommutativeMonoid : IsCommutativeMonoid ≈ _+_ 0# *-isCommutativeMonoid : IsCommutativeMonoid ≈ _*_ 1# distribʳ : _*_ DistributesOverʳ _+_ zeroˡ : LeftZero 0# _*_ private module +-CM = IsCommutativeMonoid +-isCommutativeMonoid open module *-CM = IsCommutativeMonoid *-isCommutativeMonoid public using () renaming (comm to *-comm) open EqR (record { isEquivalence = +-CM.isEquivalence }) distrib : _*_ DistributesOver _+_ distrib = (distribˡ , distribʳ) where distribˡ : _*_ DistributesOverˡ _+_ distribˡ x y z = begin (x * (y + z)) ≈⟨ *-comm x (y + z) ⟩ ((y + z) * x) ≈⟨ distribʳ x y z ⟩ ((y * x) + (z * x)) ≈⟨ *-comm y x ⟨ +-CM.∙-cong ⟩ *-comm z x ⟩ ((x * y) + (x * z)) ∎ zero : Zero 0# _*_ zero = (zeroˡ , zeroʳ) where zeroʳ : RightZero 0# _*_ zeroʳ x = begin (x * 0#) ≈⟨ *-comm x 0# ⟩ (0# * x) ≈⟨ zeroˡ x ⟩ 0# ∎ isSemiring : IsSemiring ≈ _+_ _*_ 0# 1# isSemiring = record { isSemiringWithoutAnnihilatingZero = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isMonoid = *-CM.isMonoid ; distrib = distrib } ; zero = zero } open IsSemiring isSemiring public hiding (distrib; zero; +-isCommutativeMonoid) isCommutativeSemiringWithoutOne : IsCommutativeSemiringWithoutOne ≈ _+_ _*_ 0# isCommutativeSemiringWithoutOne = record { isSemiringWithoutOne = isSemiringWithoutOne ; *-comm = *-CM.comm } record IsRing {a ℓ} {A : Set a} (≈ : Rel A ℓ) (_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field +-isAbelianGroup : IsAbelianGroup ≈ _+_ 0# -_ *-isMonoid : IsMonoid ≈ _*_ 1# distrib : _*_ DistributesOver _+_ open IsAbelianGroup +-isAbelianGroup public renaming ( assoc to +-assoc ; ∙-cong to +-cong ; isSemigroup to +-isSemigroup ; identity to +-identity ; isMonoid to +-isMonoid ; inverse to -‿inverse ; ⁻¹-cong to -‿cong ; isGroup to +-isGroup ; comm to +-comm ; isCommutativeMonoid to +-isCommutativeMonoid ) open IsMonoid *-isMonoid public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ; isSemigroup to *-isSemigroup ; identity to *-identity ) zero : Zero 0# _*_ zero = (zeroˡ , zeroʳ) where open EqR (record { isEquivalence = isEquivalence }) zeroˡ : LeftZero 0# _*_ zeroˡ x = begin 0# * x ≈⟨ sym $ proj₂ +-identity _ ⟩ (0# * x) + 0# ≈⟨ refl ⟨ +-cong ⟩ sym (proj₂ -‿inverse _) ⟩ (0# * x) + ((0# * x) + - (0# * x)) ≈⟨ sym $ +-assoc _ _ _ ⟩ ((0# * x) + (0# * x)) + - (0# * x) ≈⟨ sym (proj₂ distrib _ _ _) ⟨ +-cong ⟩ refl ⟩ ((0# + 0#) * x) + - (0# * x) ≈⟨ (proj₂ +-identity _ ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ refl ⟩ (0# * x) + - (0# * x) ≈⟨ proj₂ -‿inverse _ ⟩ 0# ∎ zeroʳ : RightZero 0# _*_ zeroʳ x = begin x * 0# ≈⟨ sym $ proj₂ +-identity _ ⟩ (x * 0#) + 0# ≈⟨ refl ⟨ +-cong ⟩ sym (proj₂ -‿inverse _) ⟩ (x * 0#) + ((x * 0#) + - (x * 0#)) ≈⟨ sym $ +-assoc _ _ _ ⟩ ((x * 0#) + (x * 0#)) + - (x * 0#) ≈⟨ sym (proj₁ distrib _ _ _) ⟨ +-cong ⟩ refl ⟩ (x * (0# + 0#)) + - (x * 0#) ≈⟨ (refl ⟨ *-cong ⟩ proj₂ +-identity _) ⟨ +-cong ⟩ refl ⟩ (x * 0#) + - (x * 0#) ≈⟨ proj₂ -‿inverse _ ⟩ 0# ∎ isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero ≈ _+_ _*_ 0# 1# isSemiringWithoutAnnihilatingZero = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isMonoid = *-isMonoid ; distrib = distrib } isSemiring : IsSemiring ≈ _+_ _*_ 0# 1# isSemiring = record { isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero ; zero = zero } open IsSemiring isSemiring public using (isNearSemiring; isSemiringWithoutOne) record IsCommutativeRing {a ℓ} {A : Set a} (≈ : Rel A ℓ) (+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isRing : IsRing ≈ + * - 0# 1# *-comm : Commutative * open IsRing isRing public isCommutativeSemiring : IsCommutativeSemiring ≈ + * 0# 1# isCommutativeSemiring = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isCommutativeMonoid = record { isSemigroup = *-isSemigroup ; identityˡ = proj₁ *-identity ; comm = *-comm } ; distribʳ = proj₂ distrib ; zeroˡ = proj₁ zero } open IsCommutativeSemiring isCommutativeSemiring public using ( *-isCommutativeMonoid ; isCommutativeSemiringWithoutOne ) record IsLattice {a ℓ} {A : Set a} (≈ : Rel A ℓ) (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isEquivalence : IsEquivalence ≈ ∨-comm : Commutative ∨ ∨-assoc : Associative ∨ ∨-cong : ∨ Preserves₂ ≈ ⟶ ≈ ⟶ ≈ ∧-comm : Commutative ∧ ∧-assoc : Associative ∧ ∧-cong : ∧ Preserves₂ ≈ ⟶ ≈ ⟶ ≈ absorptive : Absorptive ∨ ∧ open IsEquivalence isEquivalence public record IsDistributiveLattice {a ℓ} {A : Set a} (≈ : Rel A ℓ) (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isLattice : IsLattice ≈ ∨ ∧ ∨-∧-distribʳ : ∨ DistributesOverʳ ∧ open IsLattice isLattice public record IsBooleanAlgebra {a ℓ} {A : Set a} (≈ : Rel A ℓ) (∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ) where open FunctionProperties ≈ field isDistributiveLattice : IsDistributiveLattice ≈ ∨ ∧ ∨-complementʳ : RightInverse ⊤ ¬ ∨ ∧-complementʳ : RightInverse ⊥ ¬ ∧ ¬-cong : ¬ Preserves ≈ ⟶ ≈ open IsDistributiveLattice isDistributiveLattice public
{ "alphanum_fraction": 0.5035304501, "avg_line_length": 32.9200968523, "ext": "agda", "hexsha": "6c1d8dd4bd9a655d37e6e0754f6238e886d1703f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Algebra/Structures.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Algebra/Structures.agda", "max_line_length": 90, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Algebra/Structures.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 4432, "size": 13596 }
------------------------------------------------------------------------ -- A combination of the delay monad (with the possibility of crashing) -- and a kind of writer monad yielding colists ------------------------------------------------------------------------ module Lambda.Delay-crash-trace where open import Equality.Propositional as E using (_≡_; refl) open import Prelude open import Prelude.Size open import Colist E.equality-with-J as C using (Colist; []; _∷_; force) open import Monad E.equality-with-J using (Raw-monad; return; _>>=_; _⟨$⟩_) open import Delay-monad using (now; later; force) open import Delay-monad.Bisimilarity as D using (now; later; force) open import Lambda.Delay-crash using (Delay-crash) ------------------------------------------------------------------------ -- The monad mutual -- A kind of delay monad with the possibility of crashing that also -- yields a trace (colist) of values. data Delay-crash-trace (A B : Type) (i : Size) : Type where -- A result is returned now. now : B → Delay-crash-trace A B i -- The computation crashes now. crash : Delay-crash-trace A B i -- A result is possibly returned later. This constructor also -- functions as a coinductive cons constructor for the resulting -- trace. later : A → Delay-crash-trace′ A B i → Delay-crash-trace A B i -- An inductive cons constructor for the resulting trace. tell : A → Delay-crash-trace A B i → Delay-crash-trace A B i record Delay-crash-trace′ (A B : Type) (i : Size) : Type where coinductive field force : {j : Size< i} → Delay-crash-trace A B j open Delay-crash-trace′ public ------------------------------------------------------------------------ -- Extracting or deleting the trace -- Returns the trace. trace : ∀ {A B i} → Delay-crash-trace A B i → Colist A i trace (now x) = [] trace crash = [] trace (later x m) = x ∷ λ { .force → trace (m .force) } trace (tell x m) = x ∷ λ { .force → trace m } -- Erases the trace. delay-crash : ∀ {A B i} → Delay-crash-trace A B i → Delay-crash B i delay-crash (now x) = now (just x) delay-crash crash = now nothing delay-crash (later x m) = later λ { .force → delay-crash (m .force) } delay-crash (tell x m) = delay-crash m ------------------------------------------------------------------------ -- Delay-crash-trace is a raw monad -- Bind. bind : ∀ {i A B C} → Delay-crash-trace A B i → (B → Delay-crash-trace A C i) → Delay-crash-trace A C i bind (now x) f = f x bind crash f = crash bind (later x m) f = later x λ { .force → bind (force m) f } bind (tell x m) f = tell x (bind m f) -- Delay-crash-trace is a raw monad. instance raw-monad : ∀ {A i} → Raw-monad (λ B → Delay-crash-trace A B i) Raw-monad.return raw-monad = now Raw-monad._>>=_ raw-monad = bind ------------------------------------------------------------------------ -- Strong bisimilarity for Delay-crash-trace module _ {A B : Type} where mutual -- Strong bisimilarity. infix 4 [_]_∼_ [_]_∼′_ data [_]_∼_ (i : Size) : Delay-crash-trace A B ∞ → Delay-crash-trace A B ∞ → Type where now : ∀ {x} → [ i ] now x ∼ now x crash : [ i ] crash ∼ crash later : ∀ {v x y} → [ i ] force x ∼′ force y → [ i ] later v x ∼ later v y tell : ∀ {v x y} → [ i ] x ∼ y → [ i ] tell v x ∼ tell v y record [_]_∼′_ (i : Size) (x : Delay-crash-trace A B ∞) (y : Delay-crash-trace A B ∞) : Type where coinductive field force : {j : Size< i} → [ j ] x ∼ y open [_]_∼′_ public -- Reflexivity. reflexive : ∀ {i} x → [ i ] x ∼ x reflexive (now _) = now reflexive crash = crash reflexive (later v x) = later λ { .force → reflexive (force x) } reflexive (tell v x) = tell (reflexive x) -- Symmetry. symmetric : ∀ {i x y} → [ i ] x ∼ y → [ i ] y ∼ x symmetric now = now symmetric crash = crash symmetric (later p) = later λ { .force → symmetric (force p) } symmetric (tell p) = tell (symmetric p) -- Transitivity. transitive : ∀ {i x y z} → [ i ] x ∼ y → [ i ] y ∼ z → [ i ] x ∼ z transitive now now = now transitive crash crash = crash transitive (later p) (later q) = later λ { .force → transitive (force p) (force q) } transitive (tell p) (tell q) = tell (transitive p q) -- Equational reasoning combinators. infix -1 _∎ infixr -2 step-∼ step-≡ _∼⟨⟩_ _∎ : ∀ {i} x → [ i ] x ∼ x _∎ = reflexive step-∼ : ∀ {i} x {y z} → [ i ] y ∼ z → [ i ] x ∼ y → [ i ] x ∼ z step-∼ _ y∼z x∼y = transitive x∼y y∼z syntax step-∼ x y∼z x∼y = x ∼⟨ x∼y ⟩ y∼z step-≡ : ∀ {i} x {y z} → [ i ] y ∼ z → x ≡ y → [ i ] x ∼ z step-≡ _ y∼z refl = y∼z syntax step-≡ x y∼z x≡y = x ≡⟨ x≡y ⟩ y∼z _∼⟨⟩_ : ∀ {i} x {y} → [ i ] x ∼ y → [ i ] x ∼ y _ ∼⟨⟩ x∼y = x∼y ---------------------------------------------------------------------- -- Monad laws left-identity : ∀ {A B C : Type} x (f : B → Delay-crash-trace A C ∞) → [ ∞ ] return x >>= f ∼ f x left-identity x f = reflexive (f x) right-identity : ∀ {i} {A B : Type} (x : Delay-crash-trace A B ∞) → [ i ] x >>= return ∼ x right-identity (now x) = now right-identity crash = crash right-identity (later v x) = later λ { .force → right-identity (force x) } right-identity (tell v x) = tell (right-identity x) associativity : ∀ {i} {A B C D : Type} → (x : Delay-crash-trace A B ∞) (f : B → Delay-crash-trace A C ∞) (g : C → Delay-crash-trace A D ∞) → [ i ] x >>= (λ x → f x >>= g) ∼ x >>= f >>= g associativity (now x) f g = reflexive (f x >>= g) associativity crash f g = crash associativity (later v x) f g = later λ { .force → associativity (force x) f g } associativity (tell v x) f g = tell (associativity x f g) ---------------------------------------------------------------------- -- Some preservation lemmas infixl 5 _>>=-cong_ _>>=-cong_ : ∀ {i} {A B C : Type} {x y : Delay-crash-trace A B ∞} {f g : B → Delay-crash-trace A C ∞} → [ i ] x ∼ y → (∀ z → [ i ] f z ∼ g z) → [ i ] x >>= f ∼ y >>= g now >>=-cong q = q _ crash >>=-cong q = crash later p >>=-cong q = later λ { .force → force p >>=-cong q } tell p >>=-cong q = tell (p >>=-cong q) trace-cong : ∀ {i} {A B : Type} {x y : Delay-crash-trace A B ∞} → [ i ] x ∼ y → C.[ i ] trace x ∼ trace y trace-cong now = [] trace-cong crash = [] trace-cong (later p) = refl ∷ λ { .force → trace-cong (force p) } trace-cong (tell p) = refl ∷ λ { .force → trace-cong p } delay-crash-cong : ∀ {i} {A B : Type} {x y : Delay-crash-trace A B ∞} → [ i ] x ∼ y → D.[ i ] delay-crash x ∼ delay-crash y delay-crash-cong now = now delay-crash-cong crash = now delay-crash-cong (later p) = later λ { .force → delay-crash-cong (force p) } delay-crash-cong (tell p) = delay-crash-cong p ------------------------------------------------------------------------ -- More lemmas -- The delay-crash function commutes with _>>=_ (in a certain sense). delay-crash->>= : ∀ {i A B C} (x : Delay-crash-trace A B ∞) {f : B → Delay-crash-trace A C ∞} → D.[ i ] delay-crash (x >>= f) ∼ delay-crash x >>= delay-crash ∘ f delay-crash->>= (now x) = D.reflexive _ delay-crash->>= crash = D.reflexive _ delay-crash->>= (later x m) = later λ { .force → delay-crash->>= (force m) } delay-crash->>= (tell x m) = delay-crash->>= m -- Use of _⟨$⟩_ does not affect the trace. trace-⟨$⟩ : ∀ {i} {A B C : Type} {f : B → C} (x : Delay-crash-trace A B ∞) → C.[ i ] trace (f ⟨$⟩ x) ∼ trace x trace-⟨$⟩ (now x) = [] trace-⟨$⟩ crash = [] trace-⟨$⟩ (later _ x) = refl ∷ λ { .force → trace-⟨$⟩ (force x) } trace-⟨$⟩ (tell _ x) = refl ∷ λ { .force → trace-⟨$⟩ x }
{ "alphanum_fraction": 0.5017391304, "avg_line_length": 30.3773584906, "ext": "agda", "hexsha": "c11f49dd096bb0d211db066ee4ab835580fb3ceb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/definitional-interpreters", "max_forks_repo_path": "src/Lambda/Delay-crash-trace.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/definitional-interpreters", "max_issues_repo_path": "src/Lambda/Delay-crash-trace.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/definitional-interpreters", "max_stars_repo_path": "src/Lambda/Delay-crash-trace.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2697, "size": 8050 }
module Examples.TestCall where open import Prelude open import Libraries.SelectiveReceive open import Libraries.Call open SelRec AddReplyMessage : MessageType AddReplyMessage = ValueType UniqueTag ∷ [ ValueType ℕ ]ˡ AddReply : InboxShape AddReply = [ AddReplyMessage ]ˡ AddMessage : MessageType AddMessage = ValueType UniqueTag ∷ ReferenceType AddReply ∷ ValueType ℕ ∷ [ ValueType ℕ ]ˡ Calculator : InboxShape Calculator = [ AddMessage ]ˡ calculatorActor : ∀ {i} → ∞ActorM (↑ i) Calculator (Lift (lsuc lzero) ⊤) [] (λ _ → []) calculatorActor = loop where loop : ∀ {i} → ∞ActorM i Calculator (Lift (lsuc lzero) ⊤) [] (λ _ → []) loop .force = receive ∞>>= λ { (Msg Z (tag ∷ _ ∷ n ∷ m ∷ [])) → do Z ![t: Z ] ((lift tag) ∷ [ lift (n + m) ]ᵃ ) strengthen [] loop ; (Msg (S ()) _) } TestBox : InboxShape TestBox = AddReply calltestActor : ∀ {i} → ∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → []) calltestActor .force = spawn∞ calculatorActor ∞>> do x ← call [] Z Z 0 ((lift 10) ∷ [ lift 32 ]ᵃ) ⊆-refl Z strengthen [] return-result x where return-result : SelRec TestBox (call-select 0 ⊆-refl Z) → ∀ {i} → ∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → []) return-result record { msg = (Msg Z (tag ∷ n ∷ [])) } = return n return-result record { msg = (Msg (S x) x₁) ; msg-ok = () }
{ "alphanum_fraction": 0.5998573466, "avg_line_length": 29.829787234, "ext": "agda", "hexsha": "51839c35ecf381ca0fabe00df3be2a78d4c67984", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Zalastax/singly-typed-actors", "max_forks_repo_path": "src/Examples/TestCall.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Zalastax/singly-typed-actors", "max_issues_repo_path": "src/Examples/TestCall.agda", "max_line_length": 90, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Zalastax/thesis", "max_stars_repo_path": "src/Examples/TestCall.agda", "max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z", "num_tokens": 463, "size": 1402 }
module Tactic.Nat.Coprime.Problem where open import Prelude open import Prelude.List.Relations.All open import Numeric.Nat.GCD Atom = Nat infixl 7 _⊗_ infix 3 _⋈_ infix 2 _⊨_ data Exp : Set where atom : (x : Atom) → Exp _⊗_ : (a b : Exp) → Exp data Formula : Set where _⋈_ : (a b : Exp) → Formula data Problem : Set where _⊨_ : (Γ : List Formula) (φ : Formula) → Problem Env = Atom → Nat ⟦_⟧e_ : Exp → Env → Nat ⟦ atom x ⟧e ρ = ρ x ⟦ e ⊗ e₁ ⟧e ρ = ⟦ e ⟧e ρ * ⟦ e₁ ⟧e ρ ⟦_⟧f_ : Formula → Env → Set ⟦ a ⋈ b ⟧f ρ = Coprime (⟦ a ⟧e ρ) (⟦ b ⟧e ρ) ⟦_⟧p'_ : Problem → Env → Set ⟦ Γ ⊨ φ ⟧p' ρ = All (⟦_⟧f ρ) Γ → ⟦ φ ⟧f ρ ⟦_⟧p_ : Problem → Env → Set ⟦ Γ ⊨ φ ⟧p ρ = foldr (λ ψ A → ⟦ ψ ⟧f ρ → A) (⟦ φ ⟧f ρ) Γ curryProblem : ∀ Q ρ → ⟦ Q ⟧p' ρ → ⟦ Q ⟧p ρ curryProblem ([] ⊨ φ) ρ H = H [] curryProblem (x ∷ Γ ⊨ φ) ρ H = λ x → curryProblem (Γ ⊨ φ) ρ (H ∘ (x ∷_))
{ "alphanum_fraction": 0.5406643757, "avg_line_length": 21.2926829268, "ext": "agda", "hexsha": "f52fd7b4de1c5a98dc0246b5be0155cb7dc44957", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "t-more/agda-prelude", "max_forks_repo_path": "src/Tactic/Nat/Coprime/Problem.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "t-more/agda-prelude", "max_issues_repo_path": "src/Tactic/Nat/Coprime/Problem.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "t-more/agda-prelude", "max_stars_repo_path": "src/Tactic/Nat/Coprime/Problem.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 455, "size": 873 }
------------------------------------------------------------------------------ -- Testing the erasing of the duplicate definitions required by a conjecture ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module DuplicateAgdaDefinitions2 where -- We add 4 to the fixities of the standard library. infix 8 _<_ _≤_ infix 7 _≡_ ------------------------------------------------------------------------------ postulate D : Set zero true false : D succ : D → D data _≡_ (x : D) : D → Set where refl : x ≡ x data N : D → Set where zN : N zero sN : ∀ {n} → N n → N (succ n) data Bool : D → Set where tB : Bool true fB : Bool false {-# ATP axioms tB fB #-} postulate _<_ : D → D → D <-00 : zero < zero ≡ false <-0S : ∀ n → zero < succ n ≡ true <-S0 : ∀ n → succ n < zero ≡ false <-SS : ∀ m n → succ m < succ n ≡ m < n _≤_ : D → D → D m ≤ n = m < succ n {-# ATP definition _≤_ #-} NLE : D → D → Set NLE m n = m ≤ n ≡ false {-# ATP definition NLE #-} postulate Sx≰0 : ∀ {n} → N n → NLE (succ n) zero ≤-Bool : ∀ {m n} → N m → N n → Bool (m ≤ n) ≤-Bool {n = n} zN Nn = prf where postulate prf : Bool (zero ≤ n) ≤-Bool (sN {m} Nm) zN = prf where postulate prf : Bool (succ m ≤ zero) {-# ATP prove prf Sx≰0 #-} ≤-Bool (sN {m} Nm) (sN {n} Nn) = prf (≤-Bool Nm Nn) where postulate prf : Bool (m ≤ n) → Bool (succ m ≤ succ n)
{ "alphanum_fraction": 0.4430067776, "avg_line_length": 27.05, "ext": "agda", "hexsha": "01cdb4a258db7d7ccb0a1495fba329c333e33e09", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "test/Succeed/fol-theorems/DuplicateAgdaDefinitions2.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "test/Succeed/fol-theorems/DuplicateAgdaDefinitions2.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "test/Succeed/fol-theorems/DuplicateAgdaDefinitions2.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 519, "size": 1623 }
{-# OPTIONS --safe --without-K #-} module Data.List.Membership.Propositional.Disjoint {ℓ} {A : Set ℓ} where import Relation.Binary.PropositionalEquality as P open import Data.List.Membership.Setoid.Disjoint (P.setoid A) public
{ "alphanum_fraction": 0.7709251101, "avg_line_length": 45.4, "ext": "agda", "hexsha": "a303cfed49689b4c11c7e6da1f74177eb604bc46", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "d4cd2a3442a9b58e6139499d16a2b31268f27f80", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "tizmd/agda-distinct-disjoint", "max_forks_repo_path": "src/Data/List/Membership/Propositional/Disjoint.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d4cd2a3442a9b58e6139499d16a2b31268f27f80", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "tizmd/agda-distinct-disjoint", "max_issues_repo_path": "src/Data/List/Membership/Propositional/Disjoint.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "d4cd2a3442a9b58e6139499d16a2b31268f27f80", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "tizmd/agda-distinct-disjoint", "max_stars_repo_path": "src/Data/List/Membership/Propositional/Disjoint.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 59, "size": 227 }
{-# OPTIONS --type-in-type --no-pattern-matching #-} open import Spire.DarkwingDuck.Primitive module Spire.DarkwingDuck.Derived where ---------------------------------------------------------------------- subst : (A : Set) (x : A) (y : A) (P : A → Set) → P x → x ≡ y → P y subst A x y P p = elimEq A x (λ y _ → P y) p y ISet : Set → Set ISet I = I → Set Scope : Tel → Set Scope = elimTel (λ _ → Set) ⊤ (λ A B ih → Σ A ih) ---------------------------------------------------------------------- UncurriedBranches : (E : Enum) (P : Tag E → Set) (X : Set) → Set UncurriedBranches E P X = Branches E P → X CurriedBranchesM : Enum → Set CurriedBranchesM E = (P : Tag E → Set) (X : Set) → Set CurriedBranches : (E : Enum) → CurriedBranchesM E CurriedBranches = elimEnum CurriedBranchesM (λ P X → X) (λ l E ih P X → P here → ih (λ t → P (there t)) X) CurryBranches : Enum → Set CurryBranches E = (P : Tag E → Set) (X : Set) → UncurriedBranches E P X → CurriedBranches E P X curryBranches : (E : Enum) → CurryBranches E curryBranches = elimEnum CurryBranches (λ P X f → f tt) (λ l E ih P X f c → ih (λ t → P (there t)) X (λ cs → f (c , cs))) ---------------------------------------------------------------------- UncurriedScope : (T : Tel) (X : Scope T → Set) → Set UncurriedScope T X = (xs : Scope T) → X xs CurriedScope : (T : Tel) (X : Scope T → Set) → Set CurriedScope = elimTel (λ T → (X : Scope T → Set) → Set) (λ X → X tt) (λ A B ih X → (a : A) → ih a (λ b → X (a , b))) CurryScope : Tel → Set CurryScope T = (X : Scope T → Set) → UncurriedScope T X → CurriedScope T X curryScope : (T : Tel) → CurryScope T curryScope = elimTel CurryScope (λ X f → f tt) (λ A B ih X f a → ih a (λ b → X (a , b)) (λ b → f (a , b))) UncurryScope : Tel → Set UncurryScope T = (X : Scope T → Set) → CurriedScope T X → UncurriedScope T X uncurryScope : (T : Tel) → UncurryScope T uncurryScope = elimTel UncurryScope (λ X x → elimUnit X x) (λ A B ih X f → elimPair A (λ a → Scope (B a)) X (λ a b → ih a (λ b → X (a , b)) (f a) b)) ---------------------------------------------------------------------- UncurriedFunc : (I : Set) (D : Desc I) (X : ISet I) → Set UncurriedFunc I D X = (i : I) → Func I D X i → X i CurriedFuncM : (I : Set) → Desc I → Set CurriedFuncM I _ = (X : ISet I) → Set CurriedFunc : (I : Set) (D : Desc I) (X : ISet I) → Set CurriedFunc I = elimDesc I (CurriedFuncM I) (λ i X → X i) (λ i D ih X → (x : X i) → ih X) (λ A B ih X → (a : A) → ih a X) CurryFunc : (I : Set) → Desc I → Set CurryFunc I D = (X : ISet I) → UncurriedFunc I D X → CurriedFunc I D X curryFunc : (I : Set) (D : Desc I) → CurryFunc I D curryFunc I = elimDesc I (CurryFunc I) (λ i X cn → cn i refl) (λ i D ih X cn x → ih X (λ j xs → cn j (x , xs))) (λ A B ih X cn a → ih a X (λ j xs → cn j (a , xs))) ---------------------------------------------------------------------- UncurriedHyps : (I : Set) (D : Desc I) (X : ISet I) (P : (i : I) → X i → Set) (cn : UncurriedFunc I D X) → Set UncurriedHyps I D X P cn = (i : I) (xs : Func I D X i) (ihs : Hyps I D X P i xs) → P i (cn i xs) CurriedHypsM : (I : Set) (D : Desc I) → Set CurriedHypsM I D = (X : ISet I) (P : (i : I) → X i → Set) (cn : UncurriedFunc I D X) → Set CurriedHyps : (I : Set) (D : Desc I) → CurriedHypsM I D CurriedHyps I = elimDesc I (CurriedHypsM I) (λ i X P cn → P i (cn i refl)) (λ i D ih X P cn → (x : X i) → P i x → ih X P (λ j xs → cn j (x , xs))) (λ A B ih X P cn → (a : A) → ih a X P (λ j xs → cn j (a , xs))) UncurryHyps : (I : Set) (D : Desc I) → Set UncurryHyps I D = (X : ISet I) (P : (i : I) → X i → Set) (cn : UncurriedFunc I D X) → CurriedHyps I D X P cn → UncurriedHyps I D X P cn uncurryHyps : (I : Set) (D : Desc I) → UncurryHyps I D uncurryHyps I = elimDesc I (UncurryHyps I) (λ j X P cn pf i q u → elimEq I j (λ k r → P k (cn k r)) pf i q ) (λ j D ih X P cn pf i → elimPair (X j) (λ _ → Func I D X i) (λ xs → Hyps I (Rec j D) X P i xs → P i (cn i xs)) (λ x xs → elimPair (P j x) (λ _ → Hyps I D X P i xs) (λ _ → P i (cn i (x , xs))) (λ p ps → ih X P (λ j ys → cn j (x , ys)) (pf x p) i xs ps ) ) ) (λ A B ih X P cn pf i → elimPair A (λ a → Func I (B a) X i) (λ xs → Hyps I (Arg A (λ a → B a)) X P i xs → P i (cn i xs)) (λ a xs → ih a X P (λ j ys → cn j (a , ys)) (pf a) i xs ) ) ---------------------------------------------------------------------- BranchesD : Enum → Tel → Set BranchesD E T = Branches E (λ _ → Desc (Scope T)) caseD : (E : Enum) (T : Tel) (cs : BranchesD E T) (t : Tag E) → Desc (Scope T) caseD E T = case E (λ _ → Desc (Scope T)) sumD : (E : Enum) (T : Tel) (cs : BranchesD E T) → Desc (Scope T) sumD E T cs = Arg (Tag E) (λ t → caseD E T cs t) Indices : Tel → Set Indices P = Scope P → Tel indices : (P : Tel) → CurriedScope P (λ _ → Tel) → Indices P indices P I = uncurryScope P (λ p → Tel) I Constrs : (E : Enum) (P : Tel) (I : Indices P) → Set Constrs E P I = (p : Scope P) → BranchesD E (I p) constrs : (E : Enum) (P : Tel) (I : Indices P) → CurriedScope P (λ p → BranchesD E (I p)) → Constrs E P I constrs E P I C = uncurryScope P (λ p → BranchesD E (I p)) C Data : (X : (N : String) (E : Enum) (P : Tel) (I : Indices P) (C : Constrs E P I) → Set) → Set Data X = (N : String) (E : Enum) (P : Tel) (I : Indices P) (C : Constrs E P I) → X N E P I C ---------------------------------------------------------------------- FormUncurried : Data λ N E P I C → UncurriedScope P λ p → UncurriedScope (I p) λ i → Set FormUncurried N E P I C p = μ N (Scope P) (Scope (I p)) (sumD E (I p) (C p)) p Former : (P : Tel) → Indices P → Set Former P I = CurriedScope P λ p → CurriedScope (I p) λ i → Set Form : Data λ N E P I C → Former P I Form N E P I C = curryScope P (λ p → CurriedScope (I p) λ i → Set) λ p → curryScope (I p) (λ i → Set) λ i → FormUncurried N E P I C p i ---------------------------------------------------------------------- injUncurried : Data λ N E P I C → (t : Tag E) → UncurriedScope P λ p → CurriedFunc (Scope (I p)) (caseD E (I p) (C p) t) (FormUncurried N E P I C p) injUncurried N E P I C t p = curryFunc (Scope (I p)) (caseD E (I p) (C p) t) (FormUncurried N E P I C p) (λ i xs → init (t , xs)) Inj : Data λ N E P I C → (t : Tag E) → Set Inj N E P I C t = CurriedScope P λ p → CurriedFunc (Scope (I p)) (caseD E (I p) (C p) t) (FormUncurried N E P I C p) inj : Data λ N E P I C → (t : Tag E) → Inj N E P I C t inj N E P I C t = curryScope P (λ p → CurriedFunc (Scope (I p)) (caseD E (I p) (C p) t) (FormUncurried N E P I C p)) (injUncurried N E P I C t) ---------------------------------------------------------------------- indCurried : (ℓ : String) (P I : Set) (D : Desc I) (p : P) (M : (i : I) → μ ℓ P I D p i → Set) (f : CurriedHyps I D (μ ℓ P I D p) M (λ _ xs → init xs)) (i : I) (x : μ ℓ P I D p i) → M i x indCurried ℓ P I D p M f i x = ind ℓ P I D p M (uncurryHyps I D (μ ℓ P I D p) M (λ _ xs → init xs) f) i x SumCurriedHyps : Data λ N E P I C → UncurriedScope P λ p → (M : CurriedScope (I p) (λ i → FormUncurried N E P I C p i → Set)) → Tag E → Set SumCurriedHyps N E P I C p M t = let unM = uncurryScope (I p) (λ i → FormUncurried N E P I C p i → Set) M in CurriedHyps (Scope (I p)) (caseD E (I p) (C p) t) (FormUncurried N E P I C p) unM (λ i xs → init (t , xs)) elimUncurried : Data λ N E P I C → UncurriedScope P λ p → (M : CurriedScope (I p) (λ i → FormUncurried N E P I C p i → Set)) → let unM = uncurryScope (I p) (λ i → FormUncurried N E P I C p i → Set) M in UncurriedBranches E (SumCurriedHyps N E P I C p M) (CurriedScope (I p) (λ i → (x : FormUncurried N E P I C p i) → unM i x)) elimUncurried N E P I C p M cs = let unM = uncurryScope (I p) (λ i → FormUncurried N E P I C p i → Set) M in curryScope (I p) (λ i → (x : FormUncurried N E P I C p i) → unM i x) (indCurried N (Scope P) (Scope (I p)) (sumD E (I p) (C p)) p unM (case E (SumCurriedHyps N E P I C p M) cs)) Elim : Data λ N E P I C → Set Elim N E P I C = CurriedScope P λ p → (M : CurriedScope (I p) (λ i → FormUncurried N E P I C p i → Set)) → let unM = uncurryScope (I p) (λ i → FormUncurried N E P I C p i → Set) M in CurriedBranches E (SumCurriedHyps N E P I C p M) (CurriedScope (I p) (λ i → (x : FormUncurried N E P I C p i) → unM i x)) elim : Data λ N E P I C → Elim N E P I C elim N E P I C = curryScope P (λ p → (M : CurriedScope (I p) (λ i → FormUncurried N E P I C p i → Set)) → let unM = uncurryScope (I p) (λ i → FormUncurried N E P I C p i → Set) M in CurriedBranches E (SumCurriedHyps N E P I C p M) (CurriedScope (I p) (λ i → (x : FormUncurried N E P I C p i) → unM i x))) (λ p M → let unM = uncurryScope (I p) (λ i → FormUncurried N E P I C p i → Set) M in curryBranches E (SumCurriedHyps N E P I C p M) (CurriedScope (I p) (λ i → (x : FormUncurried N E P I C p i) → unM i x)) (elimUncurried N E P I C p M)) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.5169686985, "avg_line_length": 35.8464566929, "ext": "agda", "hexsha": "6cbf60151b5ee1c74c638a97f277d5d25f9bd9ce", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_path": "data/github.com/spire/spire/3d67f137ee9423b7e6f8593634583998cd692353/formalization/agda/Spire/DarkwingDuck/Derived.agda", "max_issues_count": 91, "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_path": "data/github.com/spire/spire/3d67f137ee9423b7e6f8593634583998cd692353/formalization/agda/Spire/DarkwingDuck/Derived.agda", "max_line_length": 105, "max_stars_count": 43, "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_path": "data/github.com/spire/spire/3d67f137ee9423b7e6f8593634583998cd692353/formalization/agda/Spire/DarkwingDuck/Derived.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z", "num_tokens": 3587, "size": 9105 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.Instances.Int where open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRing open import Cubical.Data.Int as Int renaming ( ℤ to ℤ ; _+_ to _+ℤ_; _·_ to _·ℤ_; -_ to -ℤ_) open CommRingStr using (0r ; 1r ; _+_ ; _·_ ; -_ ; isCommRing) ℤCommRing : CommRing ℓ-zero fst ℤCommRing = ℤ 0r (snd ℤCommRing) = 0 1r (snd ℤCommRing) = 1 _+_ (snd ℤCommRing) = _+ℤ_ _·_ (snd ℤCommRing) = _·ℤ_ - snd ℤCommRing = -ℤ_ isCommRing (snd ℤCommRing) = isCommRingℤ where abstract isCommRingℤ : IsCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_ isCommRingℤ = makeIsCommRing isSetℤ Int.+Assoc (λ _ → refl) -Cancel Int.+Comm Int.·Assoc Int.·Rid ·DistR+ Int.·Comm
{ "alphanum_fraction": 0.64, "avg_line_length": 29.8076923077, "ext": "agda", "hexsha": "c20c263cb10b5e7cee9b0502525e673a1971d726", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/Int.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/Int.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/Int.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 295, "size": 775 }
-- Andreas, 2016-10-14, issue #2257, reported by m0davis -- Bisected by Nisse. {-# OPTIONS --allow-unsolved-metas #-} -- {-# OPTIONS -v tc.ip:20 #-} -- {-# OPTIONS -v tc:20 #-} record R (A : Set) : Set₁ where field a : A F : ∀ {f} → Set foo : Set foo = ∀ {f} → {!!} field bar : Set
{ "alphanum_fraction": 0.5211726384, "avg_line_length": 16.1578947368, "ext": "agda", "hexsha": "54e55df7bac01c1d173ed3e75a6158a298591c72", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2257b.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2257b.agda", "max_line_length": 56, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue2257b.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 114, "size": 307 }
{-# OPTIONS --without-K #-} module sets.finite.level where open import sum open import function.isomorphism.core open import hott.level.core open import hott.level.closure open import hott.level.sets open import sets.finite.core finite-h2 : ∀ {i}{A : Set i} → IsFinite A → h 2 A finite-h2 (n , fA) = iso-level (sym≅ fA) (fin-set n)
{ "alphanum_fraction": 0.7185628743, "avg_line_length": 25.6923076923, "ext": "agda", "hexsha": "4a0dd0759916ab5c4b63cbc9edd250183f6fee43", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/sets/finite/hlevel.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/sets/finite/hlevel.agda", "max_line_length": 52, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/sets/finite/hlevel.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 99, "size": 334 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types import LibraBFT.Impl.Consensus.ConsensusTypes.QuorumCert as QuorumCert import LibraBFT.Impl.Consensus.ConsensusTypes.TimeoutCertificate as TimeoutCertificate open import LibraBFT.Impl.OBM.Logging.Logging import LibraBFT.Impl.Types.BlockInfo as BlockInfo open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.LBFT open import Optics.All open import Util.Hash open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) module LibraBFT.Impl.Consensus.ConsensusTypes.SyncInfo where highestRound : SyncInfo → Round highestRound self = max (self ^∙ siHighestCertifiedRound) (self ^∙ siHighestTimeoutRound) verify : SyncInfo → ValidatorVerifier → Either ErrLog Unit verifyM : SyncInfo → ValidatorVerifier → LBFT (Either ErrLog Unit) verifyM self validator = pure (verify self validator) module verify (self : SyncInfo) (validator : ValidatorVerifier) where step₀ step₁ step₂ step₃ step₄ step₅ step₆ : Either ErrLog Unit here' : List String → List String epoch = self ^∙ siHighestQuorumCert ∙ qcCertifiedBlock ∙ biEpoch step₀ = do lcheck (epoch == self ^∙ siHighestCommitCert ∙ qcCertifiedBlock ∙ biEpoch) (here' ("Multi epoch in SyncInfo - HCC and HQC" ∷ [])) step₁ step₁ = do lcheck (maybeS (self ^∙ siHighestTimeoutCert) true (λ tc -> epoch == tc ^∙ tcEpoch)) (here' ("Multi epoch in SyncInfo - TC and HQC" ∷ [])) step₂ step₂ = do lcheck ( self ^∙ siHighestQuorumCert ∙ qcCertifiedBlock ∙ biRound ≥? self ^∙ siHighestCommitCert ∙ qcCertifiedBlock ∙ biRound) (here' ("HQC has lower round than HCC" ∷ [])) step₃ step₃ = do lcheck (self ^∙ siHighestCommitCert ∙ qcCommitInfo /= BlockInfo.empty) (here' ("HCC has no committed block" ∷ [])) step₄ step₄ = do QuorumCert.verify (self ^∙ siHighestQuorumCert) validator step₅ step₅ = do -- Note: do not use (self ^∙ siHighestCommitCert) because it might be -- same as siHighestQuorumCert -- so no need to check again maybeS (self ^∙ sixxxHighestCommitCert) (pure unit) (` QuorumCert.verify ` validator) step₆ step₆ = do maybeS (self ^∙ siHighestTimeoutCert) (pure unit) (` TimeoutCertificate.verify ` validator) here' t = "SyncInfo" ∷ "verify" ∷ t verify = verify.step₀ hasNewerCertificates : SyncInfo → SyncInfo → Bool hasNewerCertificates self other = ⌊ self ^∙ siHighestCertifiedRound >? other ^∙ siHighestCertifiedRound ⌋ ∨ ⌊ self ^∙ siHighestTimeoutRound >? other ^∙ siHighestTimeoutRound ⌋ ∨ ⌊ self ^∙ siHighestCommitRound >? other ^∙ siHighestCommitRound ⌋
{ "alphanum_fraction": 0.6798690671, "avg_line_length": 38.6708860759, "ext": "agda", "hexsha": "4cde76ac70ac530e9730ab4b028a6250b70398c1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/SyncInfo.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/SyncInfo.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/SyncInfo.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 874, "size": 3055 }
-- Andrease, 2016-12-31, issue #1975 reported by nad. -- {-# OPTIONS -v tc.lhs.split:40 #-} data ⊥ : Set where record ⊤ : Set where data Bool : Set where true false : Bool T : Bool → Set T false = ⊥ T true = ⊤ module M (b : Bool) where data D : Set where c : T b → D open M true -- The following definition is rejected: -- rejected : M.D false → ⊥ -- rejected (c x) = x data D₂ : Set where c : D₂ -- WAS: However, the following definition is accepted: test : M.D false → ⊥ test (c x) = x -- I think both definitions should be rejected. -- NOW: Both are rejected.
{ "alphanum_fraction": 0.6207482993, "avg_line_length": 15.4736842105, "ext": "agda", "hexsha": "9ddb39c8f317b282026422c08673d10db74b3427", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1975.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue1975.agda", "max_line_length": 54, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1975.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 189, "size": 588 }
{- This file contains: - Equivalence with the pushout definition Written by: Loïc Pujet, September 2019 - Associativity of the join Written by: Loïc Pujet, September 2019 -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.Join.Properties where open import Cubical.Core.Glue open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Data.Prod open import Cubical.HITs.Join.Base open import Cubical.HITs.Pushout private variable ℓ ℓ' : Level -- Alternative definition of the join using a pushout joinPushout : (A : Type ℓ) → (B : Type ℓ') → Type (ℓ-max ℓ ℓ') joinPushout A B = Pushout {A = A × B} proj₁ proj₂ -- Proof that it is equal joinPushout-iso-join : (A : Type ℓ) → (B : Type ℓ') → Iso (joinPushout A B) (join A B) joinPushout-iso-join A B = iso joinPushout→join join→joinPushout join→joinPushout→join joinPushout→join→joinPushout where joinPushout→join : joinPushout A B → join A B joinPushout→join (inl x) = inl x joinPushout→join (inr x) = inr x joinPushout→join (push y i) = push (proj₁ y) (proj₂ y) i join→joinPushout : join A B → joinPushout A B join→joinPushout (inl x) = inl x join→joinPushout (inr x) = inr x join→joinPushout (push a b i) = push (a , b) i joinPushout→join→joinPushout : ∀ x → join→joinPushout (joinPushout→join x) ≡ x joinPushout→join→joinPushout (inl x) = refl joinPushout→join→joinPushout (inr x) = refl joinPushout→join→joinPushout (push (a , b) j) = refl join→joinPushout→join : ∀ x → joinPushout→join (join→joinPushout x) ≡ x join→joinPushout→join (inl x) = refl join→joinPushout→join (inr x) = refl join→joinPushout→join (push a b j) = refl -- We will need both the equivalence and path version joinPushout≃join : (A : Type ℓ) → (B : Type ℓ') → joinPushout A B ≃ join A B joinPushout≃join A B = isoToEquiv (joinPushout-iso-join A B) joinPushout≡join : (A : Type ℓ) → (B : Type ℓ') → joinPushout A B ≡ join A B joinPushout≡join A B = isoToPath (joinPushout-iso-join A B) {- Proof of associativity of the join -} join-assoc : (A B C : Type₀) → join (join A B) C ≡ join A (join B C) join-assoc A B C = (joinPushout≡join (join A B) C) ⁻¹ ∙ (spanEquivToPushoutPath sp3≃sp4) ⁻¹ ∙ (3x3-span.3x3-lemma span) ⁻¹ ∙ (spanEquivToPushoutPath sp1≃sp2) ∙ (joinPushout≡join A (join B C)) where -- the meat of the proof is handled by the 3x3 lemma applied to this diagram span : 3x3-span span = record { A00 = A; A02 = A × B; A04 = B; A20 = A × C; A22 = A × B × C; A24 = B × C; A40 = A × C; A42 = A × C; A44 = C; f10 = proj₁; f12 = proj₁₂; f14 = proj₁; f30 = λ x → x; f32 = proj₁₃; f34 = proj₂; f01 = proj₁; f21 = proj₁₃; f41 = λ x → x; f03 = proj₂; f23 = proj₂; f43 = proj₂; H11 = H11; H13 = H13; H31 = H31; H33 = H33 } where proj₁₃ : A × B × C → A × C proj₁₃ (a , (b , c)) = a , c proj₁₂ : A × B × C → A × B proj₁₂ (a , (b , c)) = a , b H11 : (x : A × B × C) → proj₁ (proj₁₂ x) ≡ proj₁ (proj₁₃ x) H11 (a , (b , c)) = refl H13 : (x : A × B × C) → proj₂ (proj₁₂ x) ≡ proj₁ (proj₂ x) H13 (a , (b , c)) = refl H31 : (x : A × B × C) → proj₁₃ x ≡ proj₁₃ x H31 (a , (b , c)) = refl H33 : (x : A × B × C) → proj₂ (proj₁₃ x) ≡ proj₂ (proj₂ x) H33 (a , (b , c)) = refl -- the first pushout span appearing in the 3x3 lemma sp1 : 3-span sp1 = record { A0 = 3x3-span.A□0 span; A2 = 3x3-span.A□2 span; A4 = 3x3-span.A□4 span; f1 = 3x3-span.f□1 span; f3 = 3x3-span.f□3 span } -- the first span we are interested in sp2 : 3-span sp2 = record { A0 = A ; A2 = A × (join B C) ; A4 = join B C ; f1 = proj₁ ; f3 = proj₂ } -- proof that they are in fact equivalent sp1≃sp2 : 3-span-equiv sp1 sp2 sp1≃sp2 = record { e0 = A□0≃A; e2 = A□2≃A×join; e4 = joinPushout≃join B C; H1 = H1; H3 = H2 } where A×join : Type₀ A×join = A × (join B C) A□2→A×join : 3x3-span.A□2 span → A×join A□2→A×join (inl (a , b)) = a , inl b A□2→A×join (inr (a , c)) = a , inr c A□2→A×join (push (a , (b , c)) i) = a , push b c i A×join→A□2 : A×join → 3x3-span.A□2 span A×join→A□2 (a , inl b) = inl (a , b) A×join→A□2 (a , inr c) = inr (a , c) A×join→A□2 (a , push b c i) = push (a , (b , c)) i A×join→A□2→A×join : ∀ x → A×join→A□2 (A□2→A×join x) ≡ x A×join→A□2→A×join (inl (a , b)) = refl A×join→A□2→A×join (inr (a , c)) = refl A×join→A□2→A×join (push (a , (b , c)) i) = refl A□2→A×join→A□2 : ∀ x → A□2→A×join (A×join→A□2 x) ≡ x A□2→A×join→A□2 (a , inl b) = refl A□2→A×join→A□2 (a , inr c) = refl A□2→A×join→A□2 (a , push b c i) = refl A□2≃A×join : 3x3-span.A□2 span ≃ A×join A□2≃A×join = isoToEquiv (iso A□2→A×join A×join→A□2 A□2→A×join→A□2 A×join→A□2→A×join) A→A□0 : A → 3x3-span.A□0 span A→A□0 b = inl b A□0→A : 3x3-span.A□0 span → A A□0→A (inl b) = b A□0→A (inr a) = proj₁ a A□0→A (push a i) = proj₁ a A→A□0→A : ∀ x → A□0→A (A→A□0 x) ≡ x A→A□0→A x = refl A□0→A→A□0 : ∀ x → A→A□0 (A□0→A x) ≡ x A□0→A→A□0 (inl b) = refl A□0→A→A□0 (inr a) j = push a j A□0→A→A□0 (push a i) j = push a (j ∧ i) A□0≃A : 3x3-span.A□0 span ≃ A A□0≃A = isoToEquiv (iso A□0→A A→A□0 A→A□0→A A□0→A→A□0) H1 : (x : 3x3-span.A□2 span) → proj₁ (A□2→A×join x) ≡ A□0→A (3x3-span.f□1 span x) H1 (inl (a , b)) = refl H1 (inr (a , c)) = refl H1 (push (a , (b , c)) i) j = A□0→A (doubleCompPath-filler refl (λ i → push (a , c) i) refl i j) H2 : (x : 3x3-span.A□2 span) → proj₂ (A□2→A×join x) ≡ fst (joinPushout≃join _ _) (3x3-span.f□3 span x) H2 (inl (a , b)) = refl H2 (inr (a , c)) = refl H2 (push (a , (b , c)) i) j = fst (joinPushout≃join _ _) (doubleCompPath-filler refl (λ i → push (b , c) i) refl i j) -- the second span appearing in 3x3 lemma sp3 : 3-span sp3 = record { A0 = 3x3-span.A0□ span; A2 = 3x3-span.A2□ span; A4 = 3x3-span.A4□ span; f1 = 3x3-span.f1□ span; f3 = 3x3-span.f3□ span } -- the second span we are interested in sp4 : 3-span sp4 = record { A0 = join A B ; A2 = (join A B) × C ; A4 = C ; f1 = proj₁ ; f3 = proj₂ } -- proof that they are in fact equivalent sp3≃sp4 : 3-span-equiv sp3 sp4 sp3≃sp4 = record { e0 = joinPushout≃join A B; e2 = A2□≃join×C; e4 = A4□≃C; H1 = H4; H3 = H3 } where join×C : Type₀ join×C = (join A B) × C A2□→join×C : 3x3-span.A2□ span → join×C A2□→join×C (inl (a , c)) = (inl a) , c A2□→join×C (inr (b , c)) = (inr b) , c A2□→join×C (push (a , (b , c)) i) = push a b i , c join×C→A2□ : join×C → 3x3-span.A2□ span join×C→A2□ (inl a , c) = inl (a , c) join×C→A2□ (inr b , c) = inr (b , c) join×C→A2□ (push a b i , c) = push (a , (b , c)) i join×C→A2□→join×C : ∀ x → join×C→A2□ (A2□→join×C x) ≡ x join×C→A2□→join×C (inl (a , c)) = refl join×C→A2□→join×C (inr (b , c)) = refl join×C→A2□→join×C (push (a , (b , c)) j) = refl A2□→join×C→A2□ : ∀ x → A2□→join×C (join×C→A2□ x) ≡ x A2□→join×C→A2□ (inl a , c) = refl A2□→join×C→A2□ (inr b , c) = refl A2□→join×C→A2□ (push a b i , c) = refl A2□≃join×C : 3x3-span.A2□ span ≃ join×C A2□≃join×C = isoToEquiv (iso A2□→join×C join×C→A2□ A2□→join×C→A2□ join×C→A2□→join×C) C→A4□ : C → 3x3-span.A4□ span C→A4□ b = inr b A4□→C : 3x3-span.A4□ span → C A4□→C (inl x) = proj₂ x A4□→C (inr c) = c A4□→C (push x i) = proj₂ x C→A4□→C : ∀ x → A4□→C (C→A4□ x) ≡ x C→A4□→C x = refl A4□→C→A4□ : ∀ x → C→A4□ (A4□→C x) ≡ x A4□→C→A4□ (inl x) j = push x (~ j) A4□→C→A4□ (inr c) = refl A4□→C→A4□ (push x i) j = push x (~ j ∨ i) A4□≃C : 3x3-span.A4□ span ≃ C A4□≃C = isoToEquiv (iso A4□→C C→A4□ C→A4□→C A4□→C→A4□) H3 : (x : 3x3-span.A2□ span) → proj₂ (A2□→join×C x) ≡ A4□→C (3x3-span.f3□ span x) H3 (inl (a , c)) = refl H3 (inr (b , c)) = refl H3 (push (a , (b , c)) i) j = A4□→C (doubleCompPath-filler refl (λ i → push (a , c) i) refl i j) H4 : (x : 3x3-span.A2□ span) → proj₁ (A2□→join×C x) ≡ fst (joinPushout≃join _ _) (3x3-span.f1□ span x) H4 (inl (a , c)) = refl H4 (inr (b , c)) = refl H4 (push (a , (b , c)) i) j = fst (joinPushout≃join _ _) (doubleCompPath-filler refl (λ i → push (a , b) i) refl i j)
{ "alphanum_fraction": 0.5119375069, "avg_line_length": 33.4154411765, "ext": "agda", "hexsha": "86076564bbae6454cbeaae1e633f705d787284d9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cj-xu/cubical", "max_forks_repo_path": "Cubical/HITs/Join/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cj-xu/cubical", "max_issues_repo_path": "Cubical/HITs/Join/Properties.agda", "max_line_length": 125, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cj-xu/cubical", "max_stars_repo_path": "Cubical/HITs/Join/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4141, "size": 9089 }
module plantsigma where data Tree : Set where oak : Tree pine : Tree spruce : Tree data Flower : Set where rose : Flower lily : Flower data PlantGroup : Set where tree : PlantGroup flower : PlantGroup PlantsInGroup : PlantGroup -> Set PlantsInGroup tree = Tree PlantsInGroup flower = Flower data Plant : Set where plant : (g : PlantGroup) -> PlantsInGroup g -> Plant f : Plant -> PlantGroup f (plant g pg) = g
{ "alphanum_fraction": 0.6741071429, "avg_line_length": 15.4482758621, "ext": "agda", "hexsha": "df5abf9f90815fa57da1b8a9b3e4985afb379440", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andrejtokarcik/agda-semantics", "max_forks_repo_path": "tests/covered/plantsigma.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andrejtokarcik/agda-semantics", "max_issues_repo_path": "tests/covered/plantsigma.agda", "max_line_length": 54, "max_stars_count": 3, "max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andrejtokarcik/agda-semantics", "max_stars_repo_path": "tests/covered/plantsigma.agda", "max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z", "num_tokens": 133, "size": 448 }
{-# OPTIONS --without-K #-} module TNT.Base where open import Data.Nat open import Data.Nat.DivMod open import Data.Nat.Divisibility open import Data.Nat.Properties open import Agda.Builtin.Equality open import Relation.Nullary.Decidable open import Data.Empty -- defination of congruence modulo _≡_⟨mod_⟩ : ℕ → ℕ → (n : ℕ) → {≢0 : False (n ≟ 0)} → Set (a ≡ b ⟨mod 0 ⟩){} a ≡ b ⟨mod suc n ⟩ = a % suc n ≡ b % suc n -- commutative ≡-comm : ∀ {ℓ} {A : Set ℓ} {a b : A} → a ≡ b → b ≡ a ≡-comm refl = refl ≡-mod-comm : ∀ {a b n : ℕ} → a ≡ b ⟨mod suc n ⟩ → b ≡ a ⟨mod suc n ⟩ ≡-mod-comm refl₁ = ≡-comm refl₁ -- divisibility a≡b⟨modn⟩⇒a%n-b%n≡0 : ∀ {a b n : ℕ} → a ≡ b ⟨mod suc n ⟩ → ∣ a % suc n - b % suc n ∣ ≡ 0 a≡b⟨modn⟩⇒a%n-b%n≡0 refl₁ = n≡m⇒∣n-m∣≡0 refl₁ a%n-b%n≡0⇒⟨a-b⟩%n≡0 : ∀ {a b n : ℕ} → ∣ a % suc n - b % suc n ∣ ≡ 0 → ∣ a - b ∣ % suc n ≡ 0 a%n-b%n≡0⇒⟨a-b⟩%n≡0 = {!!} ≡-mod-div : ∀ {a b n : ℕ} → a ≡ b ⟨mod suc n ⟩ → suc n ∣ ∣ a - b ∣ ≡-mod-div {a} {b} {n} refl₁ = m%n≡0⇒n∣m ∣ a - b ∣ n (a%n-b%n≡0⇒⟨a-b⟩%n≡0 {a} {b} {n} (a≡b⟨modn⟩⇒a%n-b%n≡0 {a} {b} {n} refl₁)) -- transitivity ≡-trans : ∀ {ℓ} {A : Set ℓ} {a b c : A} → a ≡ b → b ≡ c → a ≡ c ≡-trans refl refl = refl ≡-mod-trans : ∀ {a b c n : ℕ} → a ≡ b ⟨mod suc n ⟩ → b ≡ c ⟨mod suc n ⟩ → a ≡ c ⟨mod suc n ⟩ ≡-mod-trans refl₁ refl₂ = ≡-trans refl₁ refl₂
{ "alphanum_fraction": 0.52, "avg_line_length": 28.8043478261, "ext": "agda", "hexsha": "2d87c486705056577593c06c89e1ab39648f2394", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "38976a5b58af67b004c387260cd07636c2a7567a", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "PragmaTwice/TNT", "max_forks_repo_path": "src/TNT/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "38976a5b58af67b004c387260cd07636c2a7567a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "PragmaTwice/TNT", "max_issues_repo_path": "src/TNT/Base.agda", "max_line_length": 125, "max_stars_count": 9, "max_stars_repo_head_hexsha": "38976a5b58af67b004c387260cd07636c2a7567a", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "PragmaTwice/TNT", "max_stars_repo_path": "src/TNT/Base.agda", "max_stars_repo_stars_event_max_datetime": "2018-12-17T05:52:34.000Z", "max_stars_repo_stars_event_min_datetime": "2018-12-16T14:33:09.000Z", "num_tokens": 687, "size": 1325 }
module x01-842Naturals-hc where data ℕ : Set where zero : ℕ suc : ℕ → ℕ one : ℕ one = suc zero two : ℕ two = suc (suc zero) seven : ℕ seven = suc (suc (suc (suc (suc (suc (suc zero)))))) {-# BUILTIN NATURAL ℕ #-} import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) _+_ : ℕ → ℕ → ℕ zero + n = n suc m + n = suc (m + n) _ : 2 + 3 ≡ 5 _ = refl _ : 2 + 3 ≡ 5 _ = begin 2 + 3 ≡⟨⟩ -- is shorthand for (suc (suc zero)) + (suc (suc (suc zero))) ≡⟨⟩ -- many steps condensed 5 ∎ _*_ : ℕ → ℕ → ℕ zero * n = 0 suc m * n = n + (m * n) _ = begin 2 * 3 ≡⟨⟩ -- many steps condensed 6 ∎ _^_ : ℕ → ℕ → ℕ m ^ zero = 1 m ^ suc n = m * (m ^ n) _ : 2 ^ 3 ≡ 8 _ = refl _ : 2 ^ 4 ≡ 16 _ = refl _ : 3 ^ 3 ≡ 27 _ = refl _ : 3 ^ 10 ≡ 59049 _ = refl -- Monus (subtraction for naturals, bottoms out at zero). _∸_ : ℕ → ℕ → ℕ zero ∸ n = zero m ∸ zero = m suc m ∸ suc n = m ∸ n _ = begin 3 ∸ 2 ≡⟨⟩ -- many steps condensed 1 ∎ _ = begin 2 ∸ 3 ≡⟨⟩ -- many steps condensed 0 ∎ _ = begin 5 ∸ 3 ≡⟨⟩ 2 ∎ _ = begin 3 ∸ 5 ≡⟨⟩ 0 ∎ infixl 6 _+_ _∸_ infixl 7 _*_ -- {-# BUILTIN NATPLUS _+_ #-} -- {-# BUILTIN NATTIMES _*_ #-} -- {-# BUILTIN NATMINUS _∸_ #-} -- Binary representation. -- Modified from PLFA exercise (thanks to David Darais). data Bin-ℕ : Set where bits : Bin-ℕ _x0 : Bin-ℕ → Bin-ℕ _x1 : Bin-ℕ → Bin-ℕ -- Our representation of zero is different from PLFA. -- We use the empty sequence of bits (more consistent). bin-zero : Bin-ℕ bin-zero = bits bin-one : Bin-ℕ bin-one = bits x1 -- 1 in binary bin-two : Bin-ℕ bin-two = bits x1 x0 -- 10 in binary -- 842 exercise: Increment (1 point) inc : Bin-ℕ → Bin-ℕ inc bits = bits x1 inc (m x0) = m x1 inc (m x1) = inc m x0 _ : inc (bits x1 x0 x1 x0) ≡ bits x1 x0 x1 x1 _ = refl _ : inc (bits x1 x0 x1 x1) ≡ bits x1 x1 x0 x0 _ = refl _ : inc (bits x1 x1 x1 x1) ≡ bits x1 x0 x0 x0 x0 _ = refl -- 842 exercise: To/From (2 points) -- Hint: avoid addition and multiplication. Use the provided dbl. dbl : ℕ → ℕ dbl zero = zero dbl (suc m) = suc (suc (dbl m)) tob : ℕ → Bin-ℕ tob zero = bits tob (suc m) = inc (tob m) fromb : Bin-ℕ → ℕ fromb bits = 0 fromb (n x0) = dbl (fromb n) fromb (n x1) = suc (dbl (fromb n)) _ : tob 6 ≡ bits x1 x1 x0 _ = refl _ : tob 7 ≡ bits x1 x1 x1 _ = refl _ : tob 8 ≡ bits x1 x0 x0 x0 _ = refl _ : fromb (bits x1 x1 x0) ≡ 6 _ = refl _ : fromb (bits x1 x1 x1) ≡ 7 _ = refl _ : fromb (bits x1 x0 x0 x0) ≡ 8 _ = refl -- 842 exercise: BinAdd (2 points) -- Write the addition function for binary notation. -- Do NOT use 'to' and 'from'. Work with Bin-ℕ as if ℕ did not exist. -- Hint: use recursion on both m and n. _bin-+_ : Bin-ℕ → Bin-ℕ → Bin-ℕ m bin-+ bits = m bits bin-+ n = n (m x0) bin-+ (n x0) = (m bin-+ n) x0 (m x0) bin-+ (n x1) = (m bin-+ n) x1 (m x1) bin-+ (n x0) = (m bin-+ n) x1 (m x1) bin-+ (n x1) = inc ((m bin-+ n) x1) -- Tests can use to/from, or write out binary constants as below. -- Again: write more tests! _ : (bits x1 x0) bin-+ (bits x1 x1) ≡ (bits x1 x0 x1) _ = refl _ : tob 0 bin-+ tob 0 ≡ tob 0 _ = refl _ : tob 7 bin-+ tob 7 ≡ tob 14 _ = refl _ : tob 3 bin-+ tob 4 ≡ tob 7 _ = refl {- -- Many definitions from above are also in the standard library. -- open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _^_; _∸_) -- Unicode used in this chapter: ℕ U+2115 DOUBLE-STRUCK CAPITAL N (\bN) → U+2192 RIGHTWARDS ARROW (\to, \r, \->) ∸ U+2238 DOT MINUS (\.-) ≡ U+2261 IDENTICAL TO (\==) ⟨ U+27E8 MATHEMATICAL LEFT ANGLE BRACKET (\<) ⟩ U+27E9 MATHEMATICAL RIGHT ANGLE BRACKET (\>) ∎ U+220E END OF PROOF (\qed) -}
{ "alphanum_fraction": 0.5461378953, "avg_line_length": 19.5837563452, "ext": "agda", "hexsha": "8a6199f41ab99b17e04f4076249896699f5eead2", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x01-842Naturals-hc.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x01-842Naturals-hc.agda", "max_line_length": 76, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x01-842Naturals-hc.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 1668, "size": 3858 }
import cedille-options open import general-util module spans (options : cedille-options.options) {mF : Set → Set} {{_ : monad mF}} where open import lib open import functions open import cedille-types open import constants open import conversion open import ctxt open import is-free open import syntax-util open import to-string options open import subst -------------------------------------------------- -- span datatype -------------------------------------------------- err-m : Set err-m = maybe string data span : Set where mk-span : string → posinfo → posinfo → 𝕃 tagged-val {- extra information for the span -} → err-m → span span-to-rope : span → rope span-to-rope (mk-span name start end extra nothing) = [[ "[\"" ^ name ^ "\"," ^ start ^ "," ^ end ^ ",{" ]] ⊹⊹ tagged-vals-to-rope 0 extra ⊹⊹ [[ "}]" ]] span-to-rope (mk-span name start end extra (just err)) = [[ "[\"" ^ name ^ "\"," ^ start ^ "," ^ end ^ ",{" ]] ⊹⊹ tagged-vals-to-rope 0 (("error" , [[ err ]] , []) :: extra) ⊹⊹ [[ "}]" ]] data error-span : Set where mk-error-span : string → posinfo → posinfo → 𝕃 tagged-val → string → error-span data spans : Set where regular-spans : maybe error-span → 𝕃 span → spans global-error : string {- error message -} → maybe span → spans is-error-span : span → 𝔹 is-error-span (mk-span _ _ _ _ err) = isJust err get-span-error : span → err-m get-span-error (mk-span _ _ _ _ err) = err get-tagged-vals : span → 𝕃 tagged-val get-tagged-vals (mk-span _ _ _ tvs _) = tvs spans-have-error : spans → 𝔹 spans-have-error (regular-spans es ss) = isJust es spans-have-error (global-error _ _) = tt empty-spans : spans empty-spans = regular-spans nothing [] 𝕃span-to-rope : 𝕃 span → rope 𝕃span-to-rope (s :: []) = span-to-rope s 𝕃span-to-rope (s :: ss) = span-to-rope s ⊹⊹ [[ "," ]] ⊹⊹ 𝕃span-to-rope ss 𝕃span-to-rope [] = [[]] spans-to-rope : spans → rope spans-to-rope (regular-spans _ ss) = [[ "{\"spans\":["]] ⊹⊹ 𝕃span-to-rope ss ⊹⊹ [[ "]}" ]] where spans-to-rope (global-error e s) = [[ global-error-string e ]] ⊹⊹ maybe-else [[]] (λ s → [[", \"global-error\":"]] ⊹⊹ span-to-rope s) s print-file-id-table : ctxt → 𝕃 tagged-val print-file-id-table (mk-ctxt mod (syms , mn-fn , mn-ps , fn-ids , id , id-fns) is os _) = h [] id-fns where h : ∀ {i} → 𝕃 tagged-val → 𝕍 string i → 𝕃 tagged-val h ts [] = ts h {i} ts (fn :: fns) = h (("fileid" , [[ fn ]] , []) :: ts) fns add-span : span → spans → spans add-span s@(mk-span dsc pi pi' tv nothing) (regular-spans es ss) = regular-spans es (s :: ss) add-span s@(mk-span dsc pi pi' tv (just err)) (regular-spans es ss) = regular-spans (just (mk-error-span dsc pi pi' tv err)) (s :: ss) add-span s (global-error e e') = global-error e e' -------------------------------------------------- -- spanM, a state monad for spans -------------------------------------------------- spanM : Set → Set spanM A = ctxt → spans → mF (A × ctxt × spans) -- return for the spanM monad spanMr : ∀{A : Set} → A → spanM A spanMr a Γ ss = returnM (a , Γ , ss) spanMok : spanM ⊤ spanMok = spanMr triv get-ctxt : ∀{A : Set} → (ctxt → spanM A) → spanM A get-ctxt m Γ ss = m Γ Γ ss set-ctxt : ctxt → spanM ⊤ set-ctxt Γ _ ss = returnM (triv , Γ , ss) get-error : ∀ {A : Set} → (maybe error-span → spanM A) → spanM A get-error m Γ ss@(global-error _ _) = m nothing Γ ss get-error m Γ ss@(regular-spans nothing _) = m nothing Γ ss get-error m Γ ss@(regular-spans (just es) _) = m (just es) Γ ss set-error : maybe (error-span) → spanM ⊤ set-error es Γ ss@(global-error _ _) = returnM (triv , Γ , ss) set-error es Γ (regular-spans _ ss) = returnM (triv , Γ , regular-spans es ss) restore-def : Set restore-def = maybe qualif-info × maybe sym-info spanM-set-params : params → spanM ⊤ spanM-set-params ps Γ ss = returnM (triv , (ctxt-params-def ps Γ) , ss) -- this returns the previous ctxt-info, if any, for the given variable spanM-push-term-decl : posinfo → var → type → spanM restore-def spanM-push-term-decl pi x t Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-term-decl pi x t Γ , ss) -- let bindings currently cannot be made opaque, so this is OpacTrans. -tony spanM-push-term-def : posinfo → var → term → type → spanM restore-def spanM-push-term-def pi x t T Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-term-def pi localScope OpacTrans x t T Γ , ss) spanM-push-term-udef : posinfo → var → term → spanM restore-def spanM-push-term-udef pi x t Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-term-udef pi localScope OpacTrans x t Γ , ss) -- return previous ctxt-info, if any spanM-push-type-decl : posinfo → var → kind → spanM restore-def spanM-push-type-decl pi x k Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-type-decl pi x k Γ , ss) spanM-push-type-def : posinfo → var → type → kind → spanM restore-def spanM-push-type-def pi x t T Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-type-def pi localScope OpacTrans x t T Γ , ss) -- returns the original sym-info. -- clarification is idempotent: if the definition was already clarified, -- then the operation succeeds, and returns (just sym-info). -- this only returns nothing in the case that the opening didnt make sense: -- you tried to open a term def, you tried to open an unknown def, etc... -- basically any situation where the def wasnt a "proper" type def spanM-clarify-def : var → spanM (maybe sym-info) spanM-clarify-def x Γ ss = returnM (result (ctxt-clarify-def Γ x)) where result : maybe (sym-info × ctxt) → (maybe sym-info × ctxt × spans) result (just (si , Γ')) = ( just si , Γ' , ss ) result nothing = ( nothing , Γ , ss ) spanM-restore-clarified-def : var → sym-info → spanM ⊤ spanM-restore-clarified-def x si Γ ss = returnM (triv , ctxt-set-sym-info Γ x si , ss) -- restore ctxt-info for the variable with given posinfo spanM-restore-info : var → restore-def → spanM ⊤ spanM-restore-info v rd Γ ss = returnM (triv , ctxt-restore-info Γ v (fst rd) (snd rd) , ss) _≫=span_ : ∀{A B : Set} → spanM A → (A → spanM B) → spanM B (m₁ ≫=span m₂) ss Γ = m₁ ss Γ ≫=monad λ where (v , Γ , ss) → m₂ v Γ ss _≫span_ : ∀{A B : Set} → spanM A → spanM B → spanM B (m₁ ≫span m₂) = m₁ ≫=span (λ _ → m₂) spanM-restore-info* : 𝕃 (var × restore-def) → spanM ⊤ spanM-restore-info* [] = spanMok spanM-restore-info* ((v , qi , m) :: s) = spanM-restore-info v (qi , m) ≫span spanM-restore-info* s infixl 2 _≫span_ _≫=span_ _≫=spanj_ _≫=spanm_ _≫=spanm'_ _≫=spanc_ _≫=spanc'_ _≫spanc_ _≫spanc'_ _≫=spanj_ : ∀{A : Set} → spanM (maybe A) → (A → spanM ⊤) → spanM ⊤ _≫=spanj_{A} m m' = m ≫=span cont where cont : maybe A → spanM ⊤ cont nothing = spanMok cont (just x) = m' x -- discard changes made by the first computation _≫=spand_ : ∀{A B : Set} → spanM A → (A → spanM B) → spanM B _≫=spand_{A} m m' Γ ss = m Γ ss ≫=monad λ where (v , _ , _) → m' v Γ ss -- discard *spans* generated by first computation _≫=spands_ : ∀ {A B : Set} → spanM A → (A → spanM B) → spanM B _≫=spands_ m f Γ ss = m Γ ss ≫=monad λ where (v , Γ , _ ) → f v Γ ss _≫=spanm_ : ∀{A : Set} → spanM (maybe A) → (A → spanM (maybe A)) → spanM (maybe A) _≫=spanm_{A} m m' = m ≫=span cont where cont : maybe A → spanM (maybe A) cont nothing = spanMr nothing cont (just a) = m' a _≫=spans'_ : ∀ {A B E : Set} → spanM (E ∨ A) → (A → spanM (E ∨ B)) → spanM (E ∨ B) _≫=spans'_ m f = m ≫=span λ where (inj₁ e) → spanMr (inj₁ e) (inj₂ a) → f a _≫=spanm'_ : ∀{A B : Set} → spanM (maybe A) → (A → spanM (maybe B)) → spanM (maybe B) _≫=spanm'_{A}{B} m m' = m ≫=span cont where cont : maybe A → spanM (maybe B) cont nothing = spanMr nothing cont (just a) = m' a -- Currying/uncurry span binding _≫=spanc_ : ∀{A B C} → spanM (A × B) → (A → B → spanM C) → spanM C (m ≫=spanc m') Γ ss = m Γ ss ≫=monad λ where ((a , b) , Γ' , ss') → m' a b Γ' ss' _≫=spanc'_ : ∀{A B C} → spanM (A × B) → (B → spanM C) → spanM C (m ≫=spanc' m') Γ ss = m Γ ss ≫=monad λ where ((a , b) , Γ' , ss') → m' b Γ' ss' _≫spanc'_ : ∀{A B} → spanM A → B → spanM (A × B) (m ≫spanc' b) = m ≫=span λ a → spanMr (a , b) _≫spanc_ : ∀{A B} → spanM A → spanM B → spanM (A × B) (ma ≫spanc mb) = ma ≫=span λ a → mb ≫=span λ b → spanMr (a , b) spanMok' : ∀{A} → A → spanM (⊤ × A) spanMok' a = spanMr (triv , a) _on-fail_≫=spanm'_ : ∀ {A B} → spanM (maybe A) → spanM B → (A → spanM B) → spanM B _on-fail_≫=spanm'_ {A}{B} m fail f = m ≫=span cont where cont : maybe A → spanM B cont nothing = fail cont (just x) = f x _on-fail_≫=spans'_ : ∀ {A B E} → spanM (E ∨ A) → (E → spanM B) → (A → spanM B) → spanM B _on-fail_≫=spans'_ {A}{B}{E} m fail f = m ≫=span cont where cont : E ∨ A → spanM B cont (inj₁ err) = fail err cont (inj₂ a) = f a _exit-early_≫=spans'_ = _on-fail_≫=spans'_ with-ctxt : ∀ {A} → ctxt → spanM A → spanM A with-ctxt Γ sm = get-ctxt λ Γ' → set-ctxt Γ ≫span sm ≫=span λ a → set-ctxt Γ' ≫span spanMr a sequence-spanM : ∀ {A} → 𝕃 (spanM A) → spanM (𝕃 A) sequence-spanM [] = spanMr [] sequence-spanM (sp :: sps) = sp ≫=span λ x → sequence-spanM sps ≫=span λ xs → spanMr (x :: xs) foldr-spanM : ∀ {A B} → (A → spanM B → spanM B) → spanM B → 𝕃 (spanM A) → spanM B foldr-spanM f n [] = n foldr-spanM f n (m :: ms) = m ≫=span λ a → f a (foldr-spanM f n ms) foldl-spanM : ∀ {A B} → (spanM B → A → spanM B) → spanM B → 𝕃 (spanM A) → spanM B foldl-spanM f m [] = m foldl-spanM f m (m' :: ms) = m' ≫=span λ a → foldl-spanM f (f m a) ms spanM-for_init_use_ : ∀ {A B} → 𝕃 (spanM A) → spanM B → (A → spanM B → spanM B) → spanM B spanM-for xs init acc use f = foldr-spanM f acc xs spanM-add : span → spanM ⊤ spanM-add s Γ ss = returnM (triv , Γ , add-span s ss) spanM-addl : 𝕃 span → spanM ⊤ spanM-addl [] = spanMok spanM-addl (s :: ss) = spanM-add s ≫span spanM-addl ss debug-span : posinfo → posinfo → 𝕃 tagged-val → span debug-span pi pi' tvs = mk-span "Debug" pi pi' tvs nothing spanM-debug : posinfo → posinfo → 𝕃 tagged-val → spanM ⊤ --spanM-debug pi pi' tvs = spanM-add (debug-span pi pi' tvs) spanM-debug pi pi' tvs = spanMok to-string-tag-tk : (tag : string) → ctxt → tk → tagged-val to-string-tag-tk t Γ (Tkt T) = to-string-tag t Γ T to-string-tag-tk t Γ (Tkk k) = to-string-tag t Γ k -------------------------------------------------- -- tagged-val constants -------------------------------------------------- location-data : location → tagged-val location-data (file-name , pi) = "location" , [[ file-name ]] ⊹⊹ [[ " - " ]] ⊹⊹ [[ pi ]] , [] var-location-data : ctxt → var → tagged-val var-location-data Γ @ (mk-ctxt _ _ i _ _) x = location-data (maybe-else ("missing" , "missing") snd (trie-lookup i x maybe-or trie-lookup i (qualif-var Γ x))) {- {-# TERMINATING #-} var-location-data : ctxt → var → maybe language-level → tagged-val var-location-data Γ x (just ll-term) with ctxt-var-location Γ x | qualif-term Γ (Var posinfo-gen x) ...| ("missing" , "missing") | (Var pi x') = location-data (ctxt-var-location Γ x') ...| loc | _ = location-data loc var-location-data Γ x (just ll-type) with ctxt-var-location Γ x | qualif-type Γ (TpVar posinfo-gen x) ...| ("missing" , "missing") | (TpVar pi x') = location-data (ctxt-var-location Γ x') ...| loc | _ = location-data loc var-location-data Γ x (just ll-kind) with ctxt-var-location Γ x | qualif-kind Γ (KndVar posinfo-gen x ArgsNil) ...| ("missing" , "missing") | (KndVar pi x' as) = location-data (ctxt-var-location Γ x') ...| loc | _ = location-data loc var-location-data Γ x nothing with ctxt-lookup-term-var Γ x | ctxt-lookup-type-var Γ x | ctxt-lookup-kind-var-def Γ x ...| just _ | _ | _ = var-location-data Γ x (just ll-term) ...| _ | just _ | _ = var-location-data Γ x (just ll-type) ...| _ | _ | just _ = var-location-data Γ x (just ll-kind) ...| _ | _ | _ = location-data ("missing" , "missing") -} explain : string → tagged-val explain s = "explanation" , [[ s ]] , [] reason : string → tagged-val reason s = "reason" , [[ s ]] , [] expected-type : ctxt → type → tagged-val expected-type = to-string-tag "expected-type" expected-type-subterm : ctxt → type → tagged-val expected-type-subterm = to-string-tag "expected-type of the subterm" missing-expected-type : tagged-val missing-expected-type = "expected-type" , [[ "[missing]" ]] , [] -- hnf-type : ctxt → type → tagged-val -- hnf-type Γ tp = to-string-tag "hnf of type" Γ (hnf-term-type Γ ff tp) -- hnf-expected-type : ctxt → type → tagged-val -- hnf-expected-type Γ tp = to-string-tag "hnf of expected type" Γ (hnf-term-type Γ ff tp) expected-kind : ctxt → kind → tagged-val expected-kind = to-string-tag "expected kind" expected-kind-if : ctxt → maybe kind → 𝕃 tagged-val expected-kind-if _ nothing = [] expected-kind-if Γ (just k) = [ expected-kind Γ k ] expected-type-if : ctxt → maybe type → 𝕃 tagged-val expected-type-if _ nothing = [] expected-type-if Γ (just tp) = [ expected-type Γ tp ] -- hnf-expected-type-if : ctxt → maybe type → 𝕃 tagged-val -- hnf-expected-type-if Γ nothing = [] -- hnf-expected-type-if Γ (just tp) = [ hnf-expected-type Γ tp ] type-data : ctxt → type → tagged-val type-data = to-string-tag "type" missing-type : tagged-val missing-type = "type" , [[ "[undeclared]" ]] , [] warning-data : string → tagged-val warning-data s = "warning" , [[ s ]] , [] check-for-type-mismatch : ctxt → string → type → type → 𝕃 tagged-val × err-m check-for-type-mismatch Γ s tp tp' = let tp'' = hnf Γ unfold-head tp' tt in expected-type Γ tp :: [ type-data Γ tp' ] , if conv-type Γ tp tp'' then nothing else just ("The expected type does not match the " ^ s ^ " type.") check-for-type-mismatch-if : ctxt → string → maybe type → type → 𝕃 tagged-val × err-m check-for-type-mismatch-if Γ s (just tp) = check-for-type-mismatch Γ s tp check-for-type-mismatch-if Γ s nothing tp = [ type-data Γ tp ] , nothing summary-data : {ed : exprd} → (name : string) → ctxt → ⟦ ed ⟧ → tagged-val summary-data name Γ t = strRunTag "summary" Γ (strVar name ≫str strAdd " : " ≫str to-stringh t) missing-kind : tagged-val missing-kind = "kind" , [[ "[undeclared]" ]] , [] head-kind : ctxt → kind → tagged-val head-kind = to-string-tag "the kind of the head" head-type : ctxt → type → tagged-val head-type = to-string-tag "the type of the head" arg-type : ctxt → type → tagged-val arg-type = to-string-tag "computed arg type" arg-exp-type : ctxt → type → tagged-val arg-exp-type = to-string-tag "expected arg type" type-app-head : ctxt → type → tagged-val type-app-head = to-string-tag "the head" term-app-head : ctxt → term → tagged-val term-app-head = to-string-tag "the head" term-argument : ctxt → term → tagged-val term-argument = to-string-tag "the argument" type-argument : ctxt → type → tagged-val type-argument = to-string-tag "the argument" contextual-type-argument : ctxt → type → tagged-val contextual-type-argument = to-string-tag "contextual type arg" arg-argument : ctxt → arg → tagged-val arg-argument Γ (TermArg me x) = term-argument Γ x arg-argument Γ (TypeArg x) = type-argument Γ x kind-data : ctxt → kind → tagged-val kind-data = to-string-tag "kind" liftingType-data : ctxt → liftingType → tagged-val liftingType-data = to-string-tag "lifting type" kind-data-if : ctxt → maybe kind → 𝕃 tagged-val kind-data-if Γ (just k) = [ kind-data Γ k ] kind-data-if _ nothing = [] super-kind-data : tagged-val super-kind-data = "superkind" , [[ "□" ]] , [] symbol-data : string → tagged-val symbol-data x = "symbol" , [[ x ]] , [] tk-data : ctxt → tk → tagged-val tk-data Γ (Tkk k) = kind-data Γ k tk-data Γ (Tkt t) = type-data Γ t checking-to-string : checking-mode → string checking-to-string checking = "checking" checking-to-string synthesizing = "synthesizing" checking-to-string untyped = "untyped" checking-data : checking-mode → tagged-val checking-data cm = "checking-mode" , [[ checking-to-string cm ]] , [] checked-meta-var : var → tagged-val checked-meta-var x = "checked meta-var" , [[ x ]] , [] ll-data : language-level → tagged-val ll-data x = "language-level" , [[ ll-to-string x ]] , [] ll-data-term = ll-data ll-term ll-data-type = ll-data ll-type ll-data-kind = ll-data ll-kind binder-data : ℕ → tagged-val binder-data n = "binder" , [[ ℕ-to-string n ]] , [] -- this is the subterm position in the parse tree (as determined by -- spans) for the bound variable of a binder binder-data-const : tagged-val binder-data-const = binder-data 0 bound-data : defTermOrType → ctxt → tagged-val bound-data (DefTerm pi v mtp t) Γ = to-string-tag "bound-value" Γ t bound-data (DefType pi v k tp) Γ = to-string-tag "bound-value" Γ tp punctuation-data : tagged-val punctuation-data = "punctuation" , [[ "true" ]] , [] not-for-navigation : tagged-val not-for-navigation = "not-for-navigation" , [[ "true" ]] , [] is-erased : type → 𝔹 is-erased (TpVar _ _ ) = tt is-erased _ = ff erased? = 𝔹 keywords = "keywords" keyword-erased = "erased" keyword-noterased = "noterased" keyword-application = "application" keyword-locale = "meta-var-locale" noterased : tagged-val noterased = keywords , [[ keyword-noterased ]] , [] keywords-data : 𝕃 string → tagged-val keywords-data kws = keywords , h kws , [] where h : 𝕃 string → rope h [] = [[]] h (k :: []) = [[ k ]] h (k :: ks) = [[ k ]] ⊹⊹ [[ " " ]] ⊹⊹ h ks keywords-data-var : erased? → tagged-val keywords-data-var e = keywords , [[ if e then keyword-erased else keyword-noterased ]] , [] keywords-app : (is-locale : 𝔹) → tagged-val keywords-app l = keywords-data ([ keyword-application ] ++ (if l then [ keyword-locale ] else [])) keywords-app-if-typed : checking-mode → (is-locale : 𝔹) → 𝕃 tagged-val keywords-app-if-typed untyped l = [] keywords-app-if-typed _ l = [ keywords-app l ] error-if-not-eq : ctxt → type → 𝕃 tagged-val → 𝕃 tagged-val × err-m error-if-not-eq Γ (TpEq pi t1 t2 pi') tvs = expected-type Γ (TpEq pi t1 t2 pi') :: tvs , nothing error-if-not-eq Γ tp tvs = expected-type Γ tp :: tvs , just "This term is being checked against the following type, but an equality type was expected" error-if-not-eq-maybe : ctxt → maybe type → 𝕃 tagged-val → 𝕃 tagged-val × err-m error-if-not-eq-maybe Γ (just tp) = error-if-not-eq Γ tp error-if-not-eq-maybe _ _ tvs = tvs , nothing params-data : ctxt → params → 𝕃 tagged-val params-data _ ParamsNil = [] params-data Γ ps = [ params-to-string-tag "parameters" Γ ps ] -------------------------------------------------- -- span-creating functions -------------------------------------------------- Star-name : string Star-name = "Star" parens-span : posinfo → posinfo → span parens-span pi pi' = mk-span "parentheses" pi pi' [] nothing data decl-class : Set where param : decl-class index : decl-class decl-class-name : decl-class → string decl-class-name param = "parameter" decl-class-name index = "index" Decl-span : decl-class → posinfo → var → tk → posinfo → span Decl-span dc pi v atk pi' = mk-span ((if tk-is-type atk then "Term " else "Type ") ^ (decl-class-name dc)) pi pi' [ binder-data-const ] nothing TpVar-span : ctxt → posinfo → string → checking-mode → 𝕃 tagged-val → err-m → span TpVar-span Γ pi v check tvs = mk-span "Type variable" pi (posinfo-plus-str pi (unqual-local v)) (checking-data check :: ll-data-type :: var-location-data Γ v :: symbol-data (unqual-local v) :: tvs) Var-span : ctxt → posinfo → string → checking-mode → 𝕃 tagged-val → err-m → span Var-span Γ pi v check tvs = mk-span "Term variable" pi (posinfo-plus-str pi (unqual-local v)) (checking-data check :: ll-data-term :: var-location-data Γ v :: symbol-data (unqual-local v) :: tvs) KndVar-span : ctxt → (posinfo × var) → (end-pi : posinfo) → params → checking-mode → 𝕃 tagged-val → err-m → span KndVar-span Γ (pi , v) pi' ps check tvs = mk-span "Kind variable" pi pi' (checking-data check :: ll-data-kind :: var-location-data Γ v :: symbol-data (unqual-local v) :: super-kind-data :: (params-data Γ ps ++ tvs)) var-span : erased? → ctxt → posinfo → string → checking-mode → tk → err-m → span var-span _ Γ pi x check (Tkk k) = TpVar-span Γ pi x check (keywords-data-var ff :: [ kind-data Γ k ]) var-span e Γ pi x check (Tkt t) = Var-span Γ pi x check (keywords-data-var e :: [ type-data Γ t ]) redefined-var-span : ctxt → posinfo → var → span redefined-var-span Γ pi x = mk-span "Variable definition" pi (posinfo-plus-str pi x) [ var-location-data Γ x ] (just "This symbol was defined already.") TpAppt-span : type → term → checking-mode → 𝕃 tagged-val → err-m → span TpAppt-span tp t check tvs = mk-span "Application of a type to a term" (type-start-pos tp) (term-end-pos t) (checking-data check :: ll-data-type :: tvs) TpApp-span : type → type → checking-mode → 𝕃 tagged-val → err-m → span TpApp-span tp tp' check tvs = mk-span "Application of a type to a type" (type-start-pos tp) (type-end-pos tp') (checking-data check :: ll-data-type :: tvs) App-span : (is-locale : 𝔹) → term → term → checking-mode → 𝕃 tagged-val → err-m → span App-span l t t' check tvs = mk-span "Application of a term to a term" (term-start-pos t) (term-end-pos t') (checking-data check :: ll-data-term :: keywords-app-if-typed check l ++ tvs) AppTp-span : term → type → checking-mode → 𝕃 tagged-val → err-m → span AppTp-span t tp check tvs = mk-span "Application of a term to a type" (term-start-pos t) (type-end-pos tp) (checking-data check :: ll-data-term :: keywords-app-if-typed check ff ++ tvs) TpQuant-e = 𝔹 is-pi : TpQuant-e is-pi = tt TpQuant-span : TpQuant-e → posinfo → var → tk → type → checking-mode → 𝕃 tagged-val → err-m → span TpQuant-span is-pi pi x atk body check tvs err = let err-if-type-pi = if ~ tk-is-type atk && is-pi then just "Π-types must bind a term, not a type (use ∀ instead)" else nothing in mk-span (if is-pi then "Dependent function type" else "Implicit dependent function type") pi (type-end-pos body) (checking-data check :: ll-data-type :: binder-data-const :: tvs) (if isJust err-if-type-pi then err-if-type-pi else err) TpLambda-span : posinfo → var → tk → type → checking-mode → 𝕃 tagged-val → err-m → span TpLambda-span pi x atk body check tvs = mk-span "Type-level lambda abstraction" pi (type-end-pos body) (checking-data check :: ll-data-type :: binder-data-const :: tvs) Iota-span : posinfo → type → checking-mode → 𝕃 tagged-val → err-m → span Iota-span pi t2 check tvs = mk-span "Iota-abstraction" pi (type-end-pos t2) (explain "A dependent intersection type" :: checking-data check :: binder-data-const :: ll-data-type :: tvs) TpArrow-span : type → type → checking-mode → 𝕃 tagged-val → err-m → span TpArrow-span t1 t2 check tvs = mk-span "Arrow type" (type-start-pos t1) (type-end-pos t2) (checking-data check :: ll-data-type :: tvs) TpEq-span : posinfo → term → term → posinfo → checking-mode → 𝕃 tagged-val → err-m → span TpEq-span pi t1 t2 pi' check tvs = mk-span "Equation" pi pi' (explain "Equation between terms" :: checking-data check :: ll-data-type :: tvs) Star-span : posinfo → checking-mode → err-m → span Star-span pi check = mk-span Star-name pi (posinfo-plus pi 1) (checking-data check :: [ ll-data-kind ]) KndPi-span : posinfo → var → tk → kind → checking-mode → err-m → span KndPi-span pi x atk k check = mk-span "Pi kind" pi (kind-end-pos k) (checking-data check :: ll-data-kind :: binder-data-const :: [ super-kind-data ]) KndArrow-span : kind → kind → checking-mode → err-m → span KndArrow-span k k' check = mk-span "Arrow kind" (kind-start-pos k) (kind-end-pos k') (checking-data check :: ll-data-kind :: [ super-kind-data ]) KndTpArrow-span : type → kind → checking-mode → err-m → span KndTpArrow-span t k check = mk-span "Arrow kind" (type-start-pos t) (kind-end-pos k) (checking-data check :: ll-data-kind :: [ super-kind-data ]) {- [[file:../cedille-mode.el::(defun%20cedille-mode-filter-out-special(data)][Frontend]] -} special-tags : 𝕃 string special-tags = "symbol" :: "location" :: "language-level" :: "checking-mode" :: "summary" :: "binder" :: "bound-value" :: "keywords" :: "erasure" :: [] error-span-filter-special : error-span → error-span error-span-filter-special (mk-error-span dsc pi pi' tvs msg) = mk-error-span dsc pi pi' tvs' msg where tvs' = (flip filter) tvs λ tag → list-any (_=string (fst tag)) special-tags erasure : ctxt → term → tagged-val erasure Γ t = to-string-tag "erasure" Γ (erase-term t) erased-marg-span : ctxt → term → maybe type → span erased-marg-span Γ t mtp = mk-span "Erased module parameter" (term-start-pos t) (term-end-pos t) (maybe-else [] (λ tp → [ type-data Γ tp ]) mtp) (just "An implicit module parameter variable occurs free in the erasure of the term.") Lam-span-erased : maybeErased → string Lam-span-erased Erased = "Erased lambda abstraction (term-level)" Lam-span-erased NotErased = "Lambda abstraction (term-level)" Lam-span : ctxt → checking-mode → posinfo → maybeErased → var → optClass → term → 𝕃 tagged-val → err-m → span Lam-span Γ c pi NotErased x (SomeClass (Tkk k)) t tvs e = mk-span (Lam-span-erased NotErased) pi (term-end-pos t) (ll-data-term :: binder-data-const :: checking-data c :: tvs) (e maybe-or just "λ-terms must bind a term, not a type (use Λ instead)") Lam-span _ c pi l x NoClass t tvs = mk-span (Lam-span-erased l) pi (term-end-pos t) (ll-data-term :: binder-data-const :: checking-data c :: tvs) Lam-span Γ c pi l x (SomeClass atk) t tvs = mk-span (Lam-span-erased l) pi (term-end-pos t) ((ll-data-term :: binder-data-const :: checking-data c :: tvs) ++ [ to-string-tag-tk "type of bound variable" Γ atk ]) compileFail-in : ctxt → term → 𝕃 tagged-val × err-m compileFail-in Γ t with is-free-in check-erased compileFail-qual | qualif-term Γ t ...| is-free | tₒ with erase-term tₒ | hnf Γ unfold-all tₒ ff ...| tₑ | tₙ with is-free tₒ ...| ff = [] , nothing ...| tt with is-free tₙ | is-free tₑ ...| tt | _ = [ to-string-tag "normalized term" Γ tₙ ] , just "compileFail occurs in the normalized term" ...| ff | ff = [ to-string-tag "the term" Γ tₒ ] , just "compileFail occurs in an erased position" ...| ff | tt = [] , nothing DefTerm-span : ctxt → posinfo → var → (checked : checking-mode) → maybe type → term → posinfo → 𝕃 tagged-val → span DefTerm-span Γ pi x checked tp t pi' tvs = h ((h-summary tp) ++ (erasure Γ t :: tvs)) pi x checked tp pi' where h : 𝕃 tagged-val → posinfo → var → (checked : checking-mode) → maybe type → posinfo → span h tvs pi x checking _ pi' = mk-span "Term-level definition (checking)" pi pi' tvs nothing h tvs pi x _ (just tp) pi' = mk-span "Term-level definition (synthesizing)" pi pi' (to-string-tag "synthesized type" Γ tp :: tvs) nothing h tvs pi x _ nothing pi' = mk-span "Term-level definition (synthesizing)" pi pi' (("synthesized type" , [[ "[nothing]" ]] , []) :: tvs) nothing h-summary : maybe type → 𝕃 tagged-val h-summary nothing = [(checking-data synthesizing)] h-summary (just tp) = (checking-data checking :: [ summary-data x Γ tp ]) CheckTerm-span : ctxt → (checked : checking-mode) → maybe type → term → posinfo → 𝕃 tagged-val → span CheckTerm-span Γ checked tp t pi' tvs = h (erasure Γ t :: tvs) checked tp (term-start-pos t) pi' where h : 𝕃 tagged-val → (checked : checking-mode) → maybe type → posinfo → posinfo → span h tvs checking _ pi pi' = mk-span "Checking a term" pi pi' (checking-data checking :: tvs) nothing h tvs _ (just tp) pi pi' = mk-span "Synthesizing a type for a term" pi pi' (checking-data synthesizing :: to-string-tag "synthesized type" Γ tp :: tvs) nothing h tvs _ nothing pi pi' = mk-span "Synthesizing a type for a term" pi pi' (checking-data synthesizing :: ("synthesized type" , [[ "[nothing]" ]] , []) :: tvs) nothing normalized-type : ctxt → type → tagged-val normalized-type = to-string-tag "normalized type" DefType-span : ctxt → posinfo → var → (checked : checking-mode) → maybe kind → type → posinfo → 𝕃 tagged-val → span DefType-span Γ pi x checked mk tp pi' tvs = h ((h-summary mk) ++ tvs) checked mk where h : 𝕃 tagged-val → checking-mode → maybe kind → span h tvs checking _ = mk-span "Type-level definition (checking)" pi pi' tvs nothing h tvs _ (just k) = mk-span "Type-level definition (synthesizing)" pi pi' (to-string-tag "synthesized kind" Γ k :: tvs) nothing h tvs _ nothing = mk-span "Type-level definition (synthesizing)" pi pi' ( ("synthesized kind" , [[ "[nothing]" ]] , []) :: tvs) nothing h-summary : maybe kind → 𝕃 tagged-val h-summary nothing = [(checking-data synthesizing)] h-summary (just k) = (checking-data checking :: [ summary-data x Γ k ]) DefKind-span : ctxt → posinfo → var → kind → posinfo → span DefKind-span Γ pi x k pi' = mk-span "Kind-level definition" pi pi' (kind-data Γ k :: [ summary-data x Γ (Var pi "□") ]) nothing {-unchecked-term-span : term → span unchecked-term-span t = mk-span "Unchecked term" (term-start-pos t) (term-end-pos t) (ll-data-term :: not-for-navigation :: [ explain "This term has not been type-checked."]) nothing-} Beta-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span Beta-span pi pi' check tvs = mk-span "Beta axiom" pi pi' (checking-data check :: ll-data-term :: explain "A term constant whose type states that β-equal terms are provably equal" :: tvs) hole-span : ctxt → posinfo → maybe type → 𝕃 tagged-val → span hole-span Γ pi tp tvs = mk-span "Hole" pi (posinfo-plus pi 1) (ll-data-term :: expected-type-if Γ tp ++ tvs) (just "This hole remains to be filled in") tp-hole-span : ctxt → posinfo → maybe kind → 𝕃 tagged-val → span tp-hole-span Γ pi k tvs = mk-span "Hole" pi (posinfo-plus pi 1) (ll-data-term :: expected-kind-if Γ k ++ tvs) (just "This hole remains to be filled in") expected-to-string : checking-mode → string expected-to-string checking = "expected" expected-to-string synthesizing = "synthesized" expected-to-string untyped = "untyped" Epsilon-span : posinfo → leftRight → maybeMinus → term → checking-mode → 𝕃 tagged-val → err-m → span Epsilon-span pi lr m t check tvs = mk-span "Epsilon" pi (term-end-pos t) (checking-data check :: ll-data-term :: tvs ++ [ explain ("Normalize " ^ side lr ^ " of the " ^ expected-to-string check ^ " equation, using " ^ maybeMinus-description m ^ " reduction." ) ]) where side : leftRight → string side Left = "the left-hand side" side Right = "the right-hand side" side Both = "both sides" maybeMinus-description : maybeMinus → string maybeMinus-description EpsHnf = "head" maybeMinus-description EpsHanf = "head-applicative" optGuide-spans : optGuide → checking-mode → spanM ⊤ optGuide-spans NoGuide _ = spanMok optGuide-spans (Guide pi x tp) expected = get-ctxt λ Γ → spanM-add (Var-span Γ pi x expected [] nothing) Rho-span : posinfo → term → term → checking-mode → optPlus → ℕ ⊎ var → 𝕃 tagged-val → err-m → span Rho-span pi t t' expected r (inj₂ x) tvs = mk-span "Rho" pi (term-end-pos t') (checking-data expected :: ll-data-term :: explain ("Rewrite all places where " ^ x ^ " occurs in the " ^ expected-to-string expected ^ " type, using an equation. ") :: tvs) Rho-span pi t t' expected r (inj₁ numrewrites) tvs err = mk-span "Rho" pi (term-end-pos t') (checking-data expected :: ll-data-term :: tvs ++ (explain ("Rewrite terms in the " ^ expected-to-string expected ^ " type, using an equation. " ^ (if (is-rho-plus r) then "" else "Do not ") ^ "Beta-reduce the type as we look for matches.") :: fst h)) (snd h) where h : 𝕃 tagged-val × err-m h = if isJust err then [] , err else if numrewrites =ℕ 0 then [] , just "No rewrites could be performed." else [ "Number of rewrites", [[ ℕ-to-string numrewrites ]] , [] ] , err Phi-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span Phi-span pi pi' expected tvs = mk-span "Phi" pi pi' (checking-data expected :: ll-data-term :: tvs) Chi-span : ctxt → posinfo → optType → term → checking-mode → 𝕃 tagged-val → err-m → span Chi-span Γ pi m t' check tvs = mk-span "Chi" pi (term-end-pos t') (ll-data-term :: checking-data check :: tvs ++ helper m) where helper : optType → 𝕃 tagged-val helper (SomeType T) = explain ("Check a term against an asserted type") :: [ to-string-tag "the asserted type" Γ T ] helper NoType = [ explain ("Change from checking mode (outside the term) to synthesizing (inside)") ] Sigma-span : posinfo → term → checking-mode → 𝕃 tagged-val → err-m → span Sigma-span pi t check tvs = mk-span "Sigma" pi (term-end-pos t) (ll-data-term :: checking-data check :: explain "Swap the sides of the equation synthesized for the body of this term" :: tvs) Delta-span : ctxt → posinfo → optType → term → checking-mode → 𝕃 tagged-val → err-m → span Delta-span Γ pi T t check tvs = mk-span "Delta" pi (term-end-pos t) (ll-data-term :: explain "Prove anything you want from a contradiction" :: checking-data check :: tvs) motive-label : string motive-label = "the motive" the-motive : ctxt → type → tagged-val the-motive = to-string-tag motive-label Theta-span : ctxt → posinfo → theta → term → lterms → checking-mode → 𝕃 tagged-val → err-m → span Theta-span Γ pi u t ls check tvs = mk-span "Theta" pi (lterms-end-pos ls) (ll-data-term :: checking-data check :: tvs ++ do-explain u) where do-explain : theta → 𝕃 tagged-val do-explain Abstract = [ explain ("Perform an elimination with the first term, after abstracting it from the expected type.") ] do-explain (AbstractVars vs) = [ strRunTag "explanation" Γ (strAdd "Perform an elimination with the first term, after abstracting the listed variables (" ≫str vars-to-string vs ≫str strAdd ") from the expected type.") ] do-explain AbstractEq = [ explain ("Perform an elimination with the first term, after abstracting it with an equation " ^ "from the expected type.") ] Lft-span : posinfo → var → term → checking-mode → 𝕃 tagged-val → err-m → span Lft-span pi X t check tvs = mk-span "Lift type" pi (term-end-pos t) (checking-data check :: ll-data-type :: binder-data-const :: tvs) File-span : ctxt → posinfo → posinfo → string → span File-span Γ pi pi' filename = mk-span ("Cedille source file (" ^ filename ^ ")") pi pi' (print-file-id-table Γ) nothing Module-span : posinfo → posinfo → span Module-span pi pi' = mk-span "Module declaration" pi pi' [ not-for-navigation ] nothing Module-header-span : posinfo → posinfo → span Module-header-span pi pi' = mk-span "Module header" pi pi' [ not-for-navigation ] nothing Import-span : posinfo → string → posinfo → 𝕃 tagged-val → err-m → span Import-span pi file pi' tvs = mk-span ("Import of another source file") pi pi' (location-data (file , first-position) :: tvs) Import-module-span : ctxt → (posinfo × var) → params → 𝕃 tagged-val → err-m → span Import-module-span Γ (pi , mn) ps tvs = mk-span "Imported module" pi (posinfo-plus-str pi mn) (params-data Γ ps ++ tvs) punctuation-span : string → posinfo → posinfo → span punctuation-span name pi pi' = mk-span name pi pi' ( punctuation-data :: not-for-navigation :: [] ) nothing whitespace-span : posinfo → posinfo → span whitespace-span pi pi' = mk-span "Whitespace" pi pi' [ not-for-navigation ] nothing comment-span : posinfo → posinfo → span comment-span pi pi' = mk-span "Comment" pi pi' [ not-for-navigation ] nothing IotaPair-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span IotaPair-span pi pi' c tvs = mk-span "Iota pair" pi pi' (explain "Inhabit a iota-type (dependent intersection type)." :: checking-data c :: ll-data-term :: tvs) IotaProj-span : term → posinfo → checking-mode → 𝕃 tagged-val → err-m → span IotaProj-span t pi' c tvs = mk-span "Iota projection" (term-start-pos t) pi' (checking-data c :: ll-data-term :: tvs) Let-span : ctxt → checking-mode → posinfo → defTermOrType → term → 𝕃 tagged-val → err-m → span Let-span Γ c pi d t' tvs = mk-span "Term Let" pi (term-end-pos t') (binder-data-const :: bound-data d Γ :: ll-data-term :: checking-data c :: tvs) TpLet-span : ctxt → checking-mode → posinfo → defTermOrType → type → 𝕃 tagged-val → err-m → span TpLet-span Γ c pi d t' tvs = mk-span "Type Let" pi (type-end-pos t') (binder-data-const :: bound-data d Γ :: ll-data-type :: checking-data c :: tvs) Mu'-span : term → 𝕃 tagged-val → err-m → span Mu'-span t tvs = mk-span "Mu' cases" (term-start-pos t) (term-end-pos t) tvs Mu-span : term → 𝕃 tagged-val → err-m → span Mu-span t tvs = mk-span "Mu fixpoint" (term-start-pos t) (term-end-pos t) tvs DefDatatype-span : posinfo → posinfo → var → posinfo → span DefDatatype-span pi _ x pi' = mk-span "Datatype definition" pi pi' [] nothing DefDataConst-span : posinfo → var → span DefDataConst-span pi c = mk-span "Datatype constructor" pi (posinfo-plus-str pi c) [] nothing
{ "alphanum_fraction": 0.634634821, "avg_line_length": 45.4082125604, "ext": "agda", "hexsha": "de4ec4d6dbce498d6a879586fbfc9be805a2749b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "xoltar/cedille", "max_forks_repo_path": "src/spans.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "xoltar/cedille", "max_issues_repo_path": "src/spans.agda", "max_line_length": 227, "max_stars_count": null, "max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "xoltar/cedille", "max_stars_repo_path": "src/spans.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 11597, "size": 37598 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Semirings.Definition open import Sets.CantorBijection.Order open import Orders.Total.Definition open import Orders.WellFounded.Induction module Sets.CantorBijection.Proofs where open Sets.CantorBijection.Order using (order ; totalOrder ; orderWellfounded) cantorInverseLemma : (ℕ && ℕ) → (ℕ && ℕ) cantorInverseLemma (0 ,, s) = (succ s) ,, 0 cantorInverseLemma (succ r ,, 0) = r ,, 1 cantorInverseLemma (succ r ,, succ s) = (r ,, succ (succ s)) cantorInverse : ℕ → (ℕ && ℕ) cantorInverse zero = (0 ,, 0) cantorInverse (succ z) = cantorInverseLemma (cantorInverse z) cantorInverseLemmaInjective : (a b : ℕ && ℕ) → cantorInverseLemma a ≡ cantorInverseLemma b → a ≡ b cantorInverseLemmaInjective (zero ,, b) (zero ,, .b) refl = refl cantorInverseLemmaInjective (zero ,, b) (succ c ,, zero) () cantorInverseLemmaInjective (zero ,, b) (succ c ,, succ d) () cantorInverseLemmaInjective (succ a ,, zero) (zero ,, d) () cantorInverseLemmaInjective (succ a ,, succ b) (zero ,, d) () cantorInverseLemmaInjective (succ a ,, zero) (succ .a ,, zero) refl = refl cantorInverseLemmaInjective (succ a ,, succ b) (succ .a ,, succ .b) refl = refl cantorInverseLemmaSurjective : (a : ℕ && ℕ) → (a ≡ (0 ,, 0)) || (Sg (ℕ && ℕ) (λ b → cantorInverseLemma b ≡ a)) cantorInverseLemmaSurjective (zero ,, zero) = inl refl cantorInverseLemmaSurjective (zero ,, succ zero) = inr ((1 ,, 0) , refl) cantorInverseLemmaSurjective (zero ,, succ (succ b)) = inr ((1 ,, succ b) , refl) cantorInverseLemmaSurjective (succ a ,, zero) = inr ((0 ,, a) , refl) cantorInverseLemmaSurjective (succ a ,, succ zero) = inr ((succ (succ a) ,, 0) , refl) cantorInverseLemmaSurjective (succ a ,, succ (succ b)) = inr ((succ (succ a) ,, succ b) , refl) cantorInverseLemmaNotZero : (a : ℕ && ℕ) → (cantorInverseLemma a ≡ (0 ,, 0)) → False cantorInverseLemmaNotZero (succ a ,, zero) () cantorInverseLemmaNotZero (succ a ,, succ b) () cantorInverseLemmaIncreases : (x : ℕ && ℕ) → order x (cantorInverseLemma x) cantorInverseLemmaIncreases (zero ,, b) = inl (identityOfIndiscernablesRight _<N_ (a<SuccA b) (applyEquality succ (equalityCommutative (Semiring.sumZeroRight ℕSemiring b)))) cantorInverseLemmaIncreases (succ a ,, zero) = inr (transitivity (applyEquality succ (Semiring.sumZeroRight ℕSemiring a)) (Semiring.commutative ℕSemiring 1 a) ,, (le 0 refl)) cantorInverseLemmaIncreases (succ a ,, succ b) = inr (transitivity (applyEquality succ (Semiring.commutative ℕSemiring a (succ b))) (Semiring.commutative ℕSemiring (succ (succ b)) a) ,, (le 0 refl)) cantorInverseOrderPreserving : (x y : ℕ) → (x <N y) → order (cantorInverse x) (cantorInverse y) cantorInverseOrderPreserving zero (succ y) x<y with TotalOrder.totality totalOrder (0 ,, 0) (cantorInverseLemma (cantorInverse y)) cantorInverseOrderPreserving zero (succ y) x<y | inl (inl bl) = bl cantorInverseOrderPreserving zero (succ y) x<y | inl (inr bl) = exFalso (leastElement bl) cantorInverseOrderPreserving zero (succ y) x<y | inr x = exFalso (leastElement {cantorInverse y} (identityOfIndiscernablesRight order (cantorInverseLemmaIncreases (cantorInverse y)) (equalityCommutative x))) cantorInverseOrderPreserving (succ x) (succ y) x<y with cantorInverseOrderPreserving x y (canRemoveSuccFrom<N x<y) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr with cantorInverse x cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | x1 ,, x2 with cantorInverse y cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, zero | zero ,, succ y2 = inl (succPreservesInequality (succIsPositive (y2 +N 0))) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, zero | succ y1 ,, zero with TotalOrder.totality ℕTotalOrder 1 (y1 +N 1) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, zero | succ y1 ,, zero | inl (inl pr1) = inl pr1 cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, zero | succ y1 ,, zero | inl (inr pr1) rewrite Semiring.commutative ℕSemiring y1 1 = exFalso (zeroNeverGreater (canRemoveSuccFrom<N pr1)) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, zero | succ y1 ,, zero | inr pr1 = inr (pr1 ,, le 0 refl) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, zero | succ y1 ,, succ y2 rewrite Semiring.commutative ℕSemiring y1 (succ (succ y2)) = inl (succPreservesInequality (succIsPositive (y2 +N y1))) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | succ x1 ,, zero | zero ,, succ y2 rewrite Semiring.commutative ℕSemiring x1 1 | Semiring.sumZeroRight ℕSemiring y2 | Semiring.sumZeroRight ℕSemiring x1 = inl (TotalOrder.<Transitive ℕTotalOrder pr (a<SuccA _)) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | succ x1 ,, zero | succ y1 ,, zero rewrite Semiring.commutative ℕSemiring x1 1 | Semiring.commutative ℕSemiring y1 1 | Semiring.sumZeroRight ℕSemiring x1 | Semiring.sumZeroRight ℕSemiring y1 = inl pr cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | succ x1 ,, zero | succ y1 ,, succ y2 rewrite Semiring.commutative ℕSemiring x1 1 | Semiring.sumZeroRight ℕSemiring x1 = inl (identityOfIndiscernablesRight _<N_ pr (transitivity (applyEquality succ (Semiring.commutative ℕSemiring y1 (succ y2))) (Semiring.commutative ℕSemiring (succ (succ y2)) y1))) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, succ x2 | zero ,, succ y2 rewrite Semiring.sumZeroRight ℕSemiring x2 | Semiring.sumZeroRight ℕSemiring y2 = inl (succPreservesInequality pr) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, succ x2 | succ y1 ,, zero rewrite Semiring.commutative ℕSemiring y1 1 | Semiring.sumZeroRight ℕSemiring y1 | Semiring.sumZeroRight ℕSemiring x2 = ans where ans : (succ (succ x2) <N succ y1) || (succ (succ x2) ≡ succ y1) && (zero <N 1) ans with TotalOrder.totality ℕTotalOrder (succ (succ x2)) (succ y1) ans | inl (inl x) = inl x ans | inl (inr x) = exFalso (noIntegersBetweenXAndSuccX (succ x2) pr x) ans | inr x = inr (x ,, le zero refl) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | zero ,, succ x2 | succ y1 ,, succ y2 rewrite Semiring.commutative ℕSemiring y1 1 | Semiring.sumZeroRight ℕSemiring y1 | Semiring.sumZeroRight ℕSemiring x2 = ans where ans : (succ (succ x2) <N y1 +N succ (succ y2)) || (succ (succ x2) ≡ y1 +N succ (succ y2)) && (zero <N succ (succ y2)) ans with TotalOrder.totality ℕTotalOrder (succ (succ x2)) (y1 +N succ (succ y2)) ans | inl (inl x) = inl x ans | inl (inr x) = exFalso (noIntegersBetweenXAndSuccX (succ x2) pr (identityOfIndiscernablesLeft _<N_ x (transitivity (Semiring.commutative ℕSemiring y1 (succ (succ y2))) (applyEquality succ (Semiring.commutative ℕSemiring (succ y2) y1))))) ans | inr x = inr (x ,, succIsPositive (succ y2)) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | succ x1 ,, succ x2 | zero ,, succ y2 rewrite Semiring.sumZeroRight ℕSemiring y2 = inl (TotalOrder.<Transitive ℕTotalOrder (identityOfIndiscernablesLeft _<N_ pr (transitivity (applyEquality succ (Semiring.commutative ℕSemiring x1 (succ x2))) (Semiring.commutative ℕSemiring (succ (succ x2)) x1))) (a<SuccA (succ y2))) cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | succ x1 ,, succ x2 | succ y1 ,, zero rewrite Semiring.commutative ℕSemiring y1 1 | Semiring.sumZeroRight ℕSemiring y1 | Semiring.commutative ℕSemiring x1 (succ x2) | Semiring.commutative ℕSemiring x1 (succ (succ x2)) = inl pr cantorInverseOrderPreserving (succ x) (succ y) x<y | inl pr | succ x1 ,, succ x2 | succ y1 ,, succ y2 rewrite Semiring.commutative ℕSemiring x1 (succ x2) | Semiring.commutative ℕSemiring y1 (succ y2) | Semiring.commutative ℕSemiring x1 (succ (succ x2)) | Semiring.commutative ℕSemiring y1 (succ (succ y2)) = inl pr cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, snd) with cantorInverse x cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, snd) | x1 ,, x2 with cantorInverse y cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, ()) | zero ,, zero | zero ,, zero cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (() ,, snd) | zero ,, zero | zero ,, succ y2 cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (refl ,, snd) | zero ,, succ .y2 | zero ,, succ y2 = exFalso (TotalOrder.irreflexive ℕTotalOrder snd) cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (refl ,, snd) | zero ,, succ .(y1 +N succ y2) | succ y1 ,, succ y2 = exFalso (TotalOrder.irreflexive ℕTotalOrder (TotalOrder.<Transitive ℕTotalOrder snd (identityOfIndiscernablesRight _<N_ (addingIncreases (succ y2) y1) (Semiring.commutative ℕSemiring (succ y2) (succ y1))))) cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, snd) | succ x1 ,, zero | zero ,, succ y2 rewrite Semiring.sumZeroRight ℕSemiring x1 | succInjective fst | Semiring.commutative ℕSemiring y2 1 | Semiring.sumZeroRight ℕSemiring y2 = inl (le zero refl) cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, snd) | succ x1 ,, zero | succ y1 ,, succ y2 rewrite Semiring.commutative ℕSemiring x1 1 | Semiring.sumZeroRight ℕSemiring x1 = inr (transitivity fst (transitivity (applyEquality succ (Semiring.commutative ℕSemiring y1 (succ y2))) (Semiring.commutative ℕSemiring (succ (succ y2)) y1)) ,, succPreservesInequality snd) cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, snd) | succ x1 ,, succ x2 | zero ,, succ y2 rewrite Semiring.sumZeroRight ℕSemiring y2 | Semiring.commutative ℕSemiring x1 (succ x2) | Semiring.commutative ℕSemiring (succ (succ x2)) x1 | fst = inl (succPreservesInequality (le zero refl)) cantorInverseOrderPreserving (succ x) (succ y) x<y | inr (fst ,, snd) | succ x1 ,, succ x2 | succ y1 ,, succ y2 = inr (transitivity (transitivity (Semiring.commutative ℕSemiring x1 (succ (succ x2))) (applyEquality succ (Semiring.commutative ℕSemiring (succ x2) x1))) (transitivity fst (transitivity (applyEquality succ (Semiring.commutative ℕSemiring y1 (succ y2))) (Semiring.commutative ℕSemiring (succ (succ y2)) y1))) ,, succPreservesInequality snd) cantorInverseInjective : (a b : ℕ) → cantorInverse a ≡ cantorInverse b → a ≡ b cantorInverseInjective zero zero pr = refl cantorInverseInjective zero (succ b) pr = exFalso (cantorInverseLemmaNotZero _ (equalityCommutative pr)) cantorInverseInjective (succ a) zero pr = exFalso (cantorInverseLemmaNotZero _ pr) cantorInverseInjective (succ a) (succ b) pr = applyEquality succ (cantorInverseInjective a b (cantorInverseLemmaInjective (cantorInverse a) (cantorInverse b) pr)) -- Some unnecessary things on the way to the final proof cantorInverseDiscrete : (a : ℕ) → (c : ℕ && ℕ) → order (cantorInverse a) c → order c (cantorInverse (succ a)) → False cantorInverseDiscrete zero (zero ,, zero) (inl ()) c<sa cantorInverseDiscrete zero (zero ,, zero) (inr ()) c<sa cantorInverseDiscrete zero (zero ,, succ c) a<c (inl x) = zeroNeverGreater (canRemoveSuccFrom<N x) cantorInverseDiscrete zero (succ b ,, zero) a<c (inl x) = zeroNeverGreater (canRemoveSuccFrom<N x) cantorInverseDiscrete zero (succ b ,, succ c) a<c (inl x) = zeroNeverGreater (canRemoveSuccFrom<N x) cantorInverseDiscrete (succ a) (b ,, c) a<c c<sa with cantorInverse a cantorInverseDiscrete (succ a) (zero ,, zero) (inl ()) (inl x) | zero ,, zero cantorInverseDiscrete (succ a) (zero ,, zero) (inr ()) (inl x) | zero ,, zero cantorInverseDiscrete (succ a) (zero ,, succ zero) a<c (inl x) | zero ,, zero = TotalOrder.irreflexive ℕTotalOrder x cantorInverseDiscrete (succ a) (zero ,, succ (succ c)) a<c (inl x) | zero ,, zero = zeroNeverGreater (canRemoveSuccFrom<N x) cantorInverseDiscrete (succ a) (succ b ,, c) a<c (inl x) | zero ,, zero = zeroNeverGreater (canRemoveSuccFrom<N x) cantorInverseDiscrete (succ a) (b ,, zero) (inl x) (inr (fst ,, snd)) | zero ,, zero = TotalOrder.irreflexive ℕTotalOrder (identityOfIndiscernablesRight _<N_ x fst) cantorInverseDiscrete (succ a) (b ,, succ c) a<c (inr (fst ,, snd)) | zero ,, zero = zeroNeverGreater (canRemoveSuccFrom<N snd) cantorInverseDiscrete (succ a) (b ,, c) (inl y) (inl x) | zero ,, succ snd rewrite Semiring.commutative ℕSemiring snd 1 | Semiring.sumZeroRight ℕSemiring snd = TotalOrder.irreflexive ℕTotalOrder (TotalOrder.<Transitive ℕTotalOrder x y) cantorInverseDiscrete (succ a) (b ,, succ c) (inr (fst ,, _)) (inl x) | zero ,, succ snd rewrite Semiring.commutative ℕSemiring snd 1 | Semiring.sumZeroRight ℕSemiring snd | fst = TotalOrder.irreflexive ℕTotalOrder x cantorInverseDiscrete (succ a) (b ,, zero) (inl x) (inr (fst ,, snd₁)) | zero ,, succ snd rewrite fst | Semiring.commutative ℕSemiring snd 1 | Semiring.sumZeroRight ℕSemiring snd = TotalOrder.irreflexive ℕTotalOrder x cantorInverseDiscrete (succ a) (b ,, succ c) (inl x) (inr (fst ,, snd1)) | zero ,, succ snd = zeroNeverGreater (canRemoveSuccFrom<N snd1) cantorInverseDiscrete (succ a) (b ,, succ zero) (inr (fst ,, _)) (inr (fst₁ ,, bad)) | zero ,, succ snd = TotalOrder.irreflexive ℕTotalOrder bad cantorInverseDiscrete (succ a) (b ,, succ (succ c)) (inr (fst ,, _)) (inr (fst₁ ,, bad)) | zero ,, succ snd = zeroNeverGreater (canRemoveSuccFrom<N bad) cantorInverseDiscrete (succ a) (b ,, c) (inl x1) (inl x) | succ zero ,, zero = noIntegersBetweenXAndSuccX 1 x1 x cantorInverseDiscrete (succ a) (zero ,, succ zero) (inr (fst ,, snd)) (inl x) | succ zero ,, zero = TotalOrder.irreflexive ℕTotalOrder snd cantorInverseDiscrete (succ a) (succ b ,, succ c) (inr (fst ,, snd)) (inl x) | succ zero ,, zero rewrite Semiring.commutative ℕSemiring b (succ c) = bad fst where bad : {a : ℕ} → 1 ≡ succ (succ a) → False bad () cantorInverseDiscrete (succ a) (b ,, c) (inl y) (inl x) | succ (succ fst) ,, zero rewrite Semiring.commutative ℕSemiring fst 2 | Semiring.commutative ℕSemiring fst 1 = TotalOrder.irreflexive ℕTotalOrder (TotalOrder.<Transitive ℕTotalOrder y x) cantorInverseDiscrete (succ a) (b ,, c) (inr (bad ,, _)) (inl x) | succ (succ fst) ,, zero rewrite Semiring.commutative ℕSemiring fst 2 | Semiring.commutative ℕSemiring fst 1 = TotalOrder.irreflexive ℕTotalOrder (identityOfIndiscernablesRight _<N_ x bad) cantorInverseDiscrete (succ a) (b ,, c) (inl x) (inr (bad ,, snd)) | succ (succ fst) ,, zero rewrite Semiring.commutative ℕSemiring fst 2 | Semiring.commutative ℕSemiring fst 1 = TotalOrder.irreflexive ℕTotalOrder (identityOfIndiscernablesRight _<N_ x bad) cantorInverseDiscrete (succ a) (b ,, c) (inr (_ ,, bad)) (inr (fst₁ ,, snd)) | succ (succ fst) ,, zero rewrite Semiring.commutative ℕSemiring fst 2 | Semiring.commutative ℕSemiring fst 1 = noIntegersBetweenXAndSuccX 1 bad snd cantorInverseDiscrete (succ a) (b ,, c) (inl x) (inl y) | succ zero ,, succ snd rewrite Semiring.sumZeroRight ℕSemiring snd = noIntegersBetweenXAndSuccX (succ (succ snd)) x y cantorInverseDiscrete (succ a) (zero ,, c) (inr (fst ,, snd1)) (inl y) | succ zero ,, succ snd rewrite Semiring.sumZeroRight ℕSemiring snd = noIntegersBetweenXAndSuccX (succ (succ snd)) snd1 y cantorInverseDiscrete (succ a) (succ b ,, c) (inr (fst ,, bad)) (inl y) | succ zero ,, succ snd rewrite Semiring.sumZeroRight ℕSemiring snd | fst = TotalOrder.irreflexive ℕTotalOrder (TotalOrder.<Transitive ℕTotalOrder bad (identityOfIndiscernablesRight _<N_ (addingIncreases c b) (Semiring.commutative ℕSemiring c (succ b)))) cantorInverseDiscrete (succ a) (b ,, c) (inl x) (inl y) | succ (succ fst) ,, succ snd rewrite Semiring.commutative ℕSemiring fst (succ (succ (succ snd))) | Semiring.commutative ℕSemiring (succ (succ snd)) fst = TotalOrder.irreflexive ℕTotalOrder (TotalOrder.<Transitive ℕTotalOrder y x) cantorInverseDiscrete (succ a) (b ,, c) (inl x) (inr (y ,, z)) | succ (succ fst) ,, succ snd rewrite y | Semiring.commutative ℕSemiring fst (succ (succ (succ snd))) | Semiring.commutative ℕSemiring (succ (succ snd)) fst = TotalOrder.irreflexive ℕTotalOrder x cantorInverseDiscrete (succ a) (b ,, c) (inr (x ,, y)) (inl z) | succ (succ fst) ,, succ snd rewrite equalityCommutative x | Semiring.commutative ℕSemiring fst (succ (succ (succ snd))) | Semiring.commutative ℕSemiring (succ (succ snd)) fst = TotalOrder.irreflexive ℕTotalOrder z cantorInverseDiscrete (succ a) (b ,, c) (inr (x ,, y)) (inr (m ,, n)) | succ (succ fst) ,, succ snd = noIntegersBetweenXAndSuccX (succ (succ snd)) y n boundedInversesExist : (a : ℕ && ℕ) (s : ℕ) → order a (cantorInverse s) → Sg ℕ (λ i → cantorInverse i ≡ a) boundedInversesExist a zero a<s = exFalso (leastElement a<s) boundedInversesExist a (succ s) a<s with TotalOrder.totality totalOrder a (cantorInverse s) boundedInversesExist a (succ s) _ | inl (inl a<s) = boundedInversesExist a s a<s boundedInversesExist a (succ s) a<s | inl (inr s<a) = exFalso (cantorInverseDiscrete s a s<a a<s) boundedInversesExist a (succ s) a<s | inr a=s = s , equalityCommutative a=s cantorInverseSurjective : (x : ℕ && ℕ) → Sg ℕ (λ i → (cantorInverse i) ≡ x) cantorInverseSurjective = rec orderWellfounded (λ z → Sg ℕ (λ z₁ → (cantorInverse z₁) ≡ z)) go where go : (a : ℕ && ℕ) → (pr : (x : ℕ && ℕ) (x₁ : order x a) → Sg ℕ (λ z → (cantorInverse z) ≡ x)) → Sg ℕ (λ i → (cantorInverse i) ≡ a) go a pr with cantorInverseLemmaSurjective a go .(0 ,, 0) pr | inl refl = 0 , refl go a ind | inr (decr , proof) with ind decr (identityOfIndiscernablesRight order (cantorInverseLemmaIncreases decr) proof) go a ind | inr (decr , proof) | boundForDecr , boundIsBound = succ boundForDecr , transitivity (applyEquality cantorInverseLemma boundIsBound) proof
{ "alphanum_fraction": 0.7241634418, "avg_line_length": 111.923566879, "ext": "agda", "hexsha": "611f2e4b3c8154c457e24f1ff5c05ff4aef09ed3", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Sets/CantorBijection/Proofs.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Sets/CantorBijection/Proofs.agda", "max_line_length": 452, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Sets/CantorBijection/Proofs.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 5796, "size": 17572 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Decidable semi-heterogeneous vector equality over setoids ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Data.Vec.Relation.Binary.Equality.DecSetoid {a ℓ} (DS : DecSetoid a ℓ) where open import Data.Nat using (ℕ) import Data.Vec.Relation.Binary.Equality.Setoid as Equality import Data.Vec.Relation.Binary.Pointwise.Inductive as PW open import Level using (_⊔_) open import Relation.Binary using (Decidable) open DecSetoid DS ------------------------------------------------------------------------ -- Make all definitions from equality available open Equality setoid public ------------------------------------------------------------------------ -- Additional properties infix 4 _≋?_ _≋?_ : ∀ {m n} → Decidable (_≋_ {m} {n}) _≋?_ = PW.decidable _≟_ ≋-isDecEquivalence : ∀ n → IsDecEquivalence (_≋_ {n}) ≋-isDecEquivalence = PW.isDecEquivalence isDecEquivalence ≋-decSetoid : ℕ → DecSetoid a (a ⊔ ℓ) ≋-decSetoid = PW.decSetoid DS
{ "alphanum_fraction": 0.5496515679, "avg_line_length": 28.7, "ext": "agda", "hexsha": "ea630b979b2a408e24e472443a79e6f8b0a4a5f7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Equality/DecSetoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Equality/DecSetoid.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Equality/DecSetoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 274, "size": 1148 }
-------------------------------------------------------------------------------- -- This is part of Agda Inference Systems open import Data.Nat open import Data.Fin module Examples.Lambda.Lambda where {- Terms & Values -} data Term (n : ℕ) : Set where var : Fin n → Term n lambda : Term (suc n) → Term n app : Term n → Term n → Term n data Value : Set where lambda : Term 1 → Value term : Value → Term 0 term (lambda x) = lambda x {- Substitution -} ext : ∀{n m} → (Fin n → Fin m) → (Fin (suc n) → Fin (suc m)) ext f zero = zero ext f (suc n) = suc (f n) rename : ∀{n m} → (Fin n → Fin m) → (Term n → Term m) rename f (var x) = var (f x) rename f (lambda t) = lambda (rename (ext f) t) rename f (app t t₁) = app (rename f t) (rename f t₁) exts : ∀{n m} → (Fin n → Term m) → (Fin (suc n) → Term (suc m)) exts _ zero = var zero exts f (suc n) = rename suc (f n) subst : ∀{n m} → (Fin n → Term m) → (Term n → Term m) subst f (var x) = f x subst f (lambda t) = lambda (subst (exts f) t) subst f (app t t₁) = app (subst f t) (subst f t₁) subst-0 : ∀{n} → Term (suc n) → Term n → Term n subst-0 {n} t t₁ = subst {suc n}{n} f t where f : Fin (suc n) → Term n f zero = t₁ f (suc n) = var n
{ "alphanum_fraction": 0.5186064925, "avg_line_length": 28.7045454545, "ext": "agda", "hexsha": "5ebdb4891aeba5ea2d542daf61544891a560bb7c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "LcicC/inference-systems-agda", "max_forks_repo_path": "Examples/Lambda/Lambda.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "LcicC/inference-systems-agda", "max_issues_repo_path": "Examples/Lambda/Lambda.agda", "max_line_length": 80, "max_stars_count": 3, "max_stars_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "LcicC/inference-systems-agda", "max_stars_repo_path": "Examples/Lambda/Lambda.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-25T15:48:52.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-10T15:53:47.000Z", "num_tokens": 463, "size": 1263 }
module Spire.Type where ---------------------------------------------------------------------- data ⊥ : Set where record ⊤ : Set where constructor tt data Bool : Set where true false : Bool data ℕ : Set where zero : ℕ suc : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public ---------------------------------------------------------------------- const : {A : Set₁} {B : Set} → A → B → A const a _ = a uncurry : {A : Set} {B : A → Set} {C : Σ A B → Set} → ((a : A) → (b : B a) → C (a , b)) → ((p : Σ A B) → C p) uncurry f (a , b) = f a b _∘_ : {A B C : Set₁} → (B → C) → (A → B) → A → C _∘_ g f x = g (f x) ---------------------------------------------------------------------- elim⊥ : {A : Set} → ⊥ → A elim⊥ () elimBool : (P : Bool → Set) (pt : P true) (pf : P false) (b : Bool) → P b elimBool P pt pf true = pt elimBool P pt pf false = pf if_then_else_ : {C : Set} → Bool → C → C → C if b then c₁ else c₂ = elimBool _ c₁ c₂ b elimℕ : (P : ℕ → Set) (pz : P zero) (ps : (n : ℕ) → P n → P (suc n)) (n : ℕ) → P n elimℕ P pz ps zero = pz elimℕ P pz ps (suc n) = ps n (elimℕ P pz ps n) ---------------------------------------------------------------------- record Universe : Set₁ where field Codes : Set Meaning : Codes → Set ---------------------------------------------------------------------- data DescForm (U : Universe) : Set where `⊤ `X : DescForm U `Π `Σ : (A : Universe.Codes U) (D : Universe.Meaning U A → DescForm U) → DescForm U ⟦_/_⟧ᵈ : (U : Universe) → DescForm U → Set → Set ⟦ U / `⊤ ⟧ᵈ X = ⊤ ⟦ U / `X ⟧ᵈ X = X ⟦ U / `Π A D ⟧ᵈ X = (a : Universe.Meaning U A) → ⟦ U / D a ⟧ᵈ X ⟦ U / `Σ A D ⟧ᵈ X = Σ (Universe.Meaning U A) (λ a → ⟦ U / D a ⟧ᵈ X) data μ {U : Universe} (D : DescForm U) : Set where con : ⟦ U / D ⟧ᵈ (μ D) → μ D ---------------------------------------------------------------------- data TypeForm (U : Universe) : Set ⟦_/_⟧ : (U : Universe) → TypeForm U → Set data TypeForm U where `⊥ `⊤ `Bool `ℕ `Desc `Type : TypeForm U `Π `Σ : (A : TypeForm U) (B : ⟦ U / A ⟧ → TypeForm U) → TypeForm U `⟦_⟧ : Universe.Codes U → TypeForm U `⟦_⟧ᵈ : DescForm U → TypeForm U → TypeForm U `μ : DescForm U → TypeForm U ⟦ U / `⊥ ⟧ = ⊥ ⟦ U / `⊤ ⟧ = ⊤ ⟦ U / `Bool ⟧ = Bool ⟦ U / `ℕ ⟧ = ℕ ⟦ U / `Π A B ⟧ = (a : ⟦ U / A ⟧) → ⟦ U / B a ⟧ ⟦ U / `Σ A B ⟧ = Σ ⟦ U / A ⟧ (λ a → ⟦ U / B a ⟧) ⟦ U / `Type ⟧ = Universe.Codes U ⟦ U / `⟦ A ⟧ ⟧ = Universe.Meaning U A ⟦ U / `Desc ⟧ = DescForm U ⟦ U / `⟦ D ⟧ᵈ X ⟧ = ⟦ U / D ⟧ᵈ ⟦ U / X ⟧ ⟦ U / `μ D ⟧ = μ D ---------------------------------------------------------------------- _`→_ : ∀{U} (A B : TypeForm U) → TypeForm U A `→ B = `Π A (λ _ → B) Level : (ℓ : ℕ) → Universe Level zero = record { Codes = ⊥ ; Meaning = λ() } Level (suc ℓ) = record { Codes = TypeForm (Level ℓ) ; Meaning = ⟦_/_⟧ (Level ℓ) } Type : ℕ → Set Type ℓ = TypeForm (Level ℓ) Desc : ℕ → Set Desc ℓ = DescForm (Level ℓ) infix 0 ⟦_∣_⟧ ⟦_∣_⟧ : (ℓ : ℕ) → Type ℓ → Set ⟦ ℓ ∣ A ⟧ = ⟦ Level ℓ / A ⟧ ⟦_∣_⟧ᵈ : (ℓ : ℕ) → Desc ℓ → Set → Set ⟦ ℓ ∣ D ⟧ᵈ X = ⟦ Level ℓ / D ⟧ᵈ X ---------------------------------------------------------------------- elimDesc : (P : (ℓ : ℕ) → Desc ℓ → Set) → ((ℓ : ℕ) → P ℓ `⊤) → ((ℓ : ℕ) → P ℓ `X) → ((ℓ : ℕ) (A : Type ℓ) (D : ⟦ ℓ ∣ A ⟧ → Desc (suc ℓ)) (rec : (a : ⟦ ℓ ∣ A ⟧) → P (suc ℓ) (D a)) → P (suc ℓ) (`Π A D)) → ((ℓ : ℕ) (A : Type ℓ) (D : ⟦ ℓ ∣ A ⟧ → Desc (suc ℓ)) (rec : (a : ⟦ ℓ ∣ A ⟧) → P (suc ℓ) (D a)) → P (suc ℓ) (`Σ A D)) → (ℓ : ℕ) (D : Desc ℓ) → P ℓ D elimDesc P p⊤ pX pΠ pΣ ℓ `⊤ = p⊤ ℓ elimDesc P p⊤ pX pΠ pΣ ℓ `X = pX ℓ elimDesc P p⊤ pX pΠ pΣ zero (`Π () D) elimDesc P p⊤ pX pΠ pΣ (suc ℓ) (`Π A D) = let f = elimDesc P p⊤ pX pΠ pΣ (suc ℓ) in pΠ ℓ A D (λ a → f (D a)) elimDesc P p⊤ pX pΠ pΣ zero (`Σ () D) elimDesc P p⊤ pX pΠ pΣ (suc ℓ) (`Σ A D) = let f = elimDesc P p⊤ pX pΠ pΣ (suc ℓ) in pΣ ℓ A D (λ a → f (D a)) des : ∀{ℓ} {D : Desc ℓ} → μ D → ⟦ ℓ ∣ D ⟧ᵈ (μ D) des (con x) = x ---------------------------------------------------------------------- elimType : (P : (ℓ : ℕ) → Type ℓ → Set) → ((ℓ : ℕ) → P ℓ `⊥) → ((ℓ : ℕ) → P ℓ `⊤) → ((ℓ : ℕ) → P ℓ `Bool) → ((ℓ : ℕ) → P ℓ `ℕ) → ((ℓ : ℕ) (A : Type ℓ) (B : ⟦ ℓ ∣ A ⟧ → Type ℓ) (rec₁ : P ℓ A) (rec₂ : (a : ⟦ ℓ ∣ A ⟧) → P ℓ (B a)) → P ℓ (`Π A B)) → ((ℓ : ℕ) (A : Type ℓ) (B : ⟦ ℓ ∣ A ⟧ → Type ℓ) (rec₁ : P ℓ A) (rec₂ : (a : ⟦ ℓ ∣ A ⟧) → P ℓ (B a)) → P ℓ (`Σ A B)) → ((ℓ : ℕ) → P ℓ `Desc) → ((ℓ : ℕ) (D : Desc ℓ) (X : Type ℓ) (rec : P ℓ X) → P ℓ (`⟦ D ⟧ᵈ X)) → ((ℓ : ℕ) (D : Desc ℓ) → P ℓ (`μ D)) → ((ℓ : ℕ) → P ℓ `Type) → ((ℓ : ℕ) (A : Type ℓ) (rec : P ℓ A) → P (suc ℓ) `⟦ A ⟧) → (ℓ : ℕ) (A : Type ℓ) → P ℓ A elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ `⊥ = p⊥ ℓ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ `⊤ = p⊤ ℓ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ `Bool = pBool ℓ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ `ℕ = pℕ ℓ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ (`Π A B) = let f = elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ in pΠ ℓ A B (f A) (λ a → f (B a)) elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ (`Σ A B) = let f = elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ in pΣ ℓ A B (f A) (λ a → f (B a)) elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ `Type = pType ℓ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ `Desc = pDesc ℓ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ (`⟦ D ⟧ᵈ X) = let f = elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ in p⟦D⟧ᵈ ℓ D X (f X) elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ (`μ D) = pμ ℓ D elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ zero `⟦ () ⟧ elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ (suc ℓ) `⟦ A ⟧ = let f = elimType P p⊥ p⊤ pBool pℕ pΠ pΣ pDesc p⟦D⟧ᵈ pμ pType p⟦A⟧ ℓ in p⟦A⟧ ℓ A (f A) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.4259349199, "avg_line_length": 28.8644859813, "ext": "agda", "hexsha": "6afb4a5f88f8c88f8ff8dbc3e0d3de0a876e8b74", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_forks_event_min_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "spire/spire", "max_forks_repo_path": "formalization/agda/Spire/Type.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "spire/spire", "max_issues_repo_path": "formalization/agda/Spire/Type.agda", "max_line_length": 71, "max_stars_count": 43, "max_stars_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "spire/spire", "max_stars_repo_path": "formalization/agda/Spire/Type.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z", "num_tokens": 3189, "size": 6177 }
module Thesis.Changes where open import Data.Product open import Data.Sum open import Data.Unit open import Relation.Binary.PropositionalEquality record IsChangeStructure (A : Set) (ChA : Set) (ch_from_to_ : (dv : ChA) → (v1 v2 : A) → Set) : Set₁ where infixl 6 _⊕_ _⊝_ field _⊕_ : A → ChA → A fromto→⊕ : ∀ dv v1 v2 → ch dv from v1 to v2 → v1 ⊕ dv ≡ v2 _⊝_ : A → A → ChA ⊝-fromto : ∀ (a b : A) → ch (b ⊝ a) from a to b update-diff : (b a : A) → a ⊕ (b ⊝ a) ≡ b update-diff b a = fromto→⊕ (b ⊝ a) a b (⊝-fromto a b) nil : A → ChA nil a = a ⊝ a nil-fromto : (a : A) → ch (nil a) from a to a nil-fromto a = ⊝-fromto a a update-nil : (a : A) → a ⊕ nil a ≡ a update-nil a = update-diff a a valid : ∀ (a : A) (da : ChA) → Set valid a da = ch da from a to (a ⊕ da) Δ₁ : (a : A) → Set Δ₁ a = Σ[ da ∈ ChA ] valid a da Δ₂ : (a1 : A) (a2 : A) → Set Δ₂ a1 a2 = Σ[ da ∈ ChA ] ch da from a1 to a2 _⊕'_ : (a1 : A) -> {a2 : A} -> (da : Δ₂ a1 a2) -> A a1 ⊕' (da , daa) = a1 ⊕ da record IsCompChangeStructure (A : Set) (ChA : Set) (ch_from_to_ : (dv : ChA) → (v1 v2 : A) → Set) : Set₁ where field isChangeStructure : IsChangeStructure A ChA ch_from_to_ _⊚_ : ChA → ChA → ChA ⊚-fromto : ∀ (a1 a2 a3 : A) (da1 da2 : ChA) → ch da1 from a1 to a2 → ch da2 from a2 to a3 → ch da1 ⊚ da2 from a1 to a3 open IsChangeStructure isChangeStructure public ⊚-correct : ∀ (a1 a2 a3 : A) (da1 da2 : ChA) → ch da1 from a1 to a2 → ch da2 from a2 to a3 → a1 ⊕ (da1 ⊚ da2) ≡ a3 ⊚-correct a1 a2 a3 da1 da2 daa1 daa2 = fromto→⊕ _ _ _ (⊚-fromto _ _ _ da1 da2 daa1 daa2) record ChangeStructure (A : Set) : Set₁ where field Ch : Set ch_from_to_ : (dv : Ch) → (v1 v2 : A) → Set isCompChangeStructure : IsCompChangeStructure A Ch ch_from_to_ open IsCompChangeStructure isCompChangeStructure public open ChangeStructure {{...}} public hiding (Ch) Ch : ∀ (A : Set) → {{CA : ChangeStructure A}} → Set Ch A {{CA}} = ChangeStructure.Ch CA -- infix 2 Σ-syntax -- Σ-syntax : ∀ {a b} (A : Set a) → (A → Set b) → Set (a ⊔ b) -- Σ-syntax = Σ -- syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B ⊚-syntax : ∀ (A : Set) → {{CA : ChangeStructure A}} → Ch A → Ch A → Ch A ⊚-syntax A {{CA}} da1 da2 = _⊚_ {{CA}} da1 da2 syntax ⊚-syntax A da1 da2 = da1 ⊚[ A ] da2 {-# DISPLAY IsChangeStructure._⊕_ x = _⊕_ #-} {-# DISPLAY ChangeStructure._⊕_ x = _⊕_ #-} {-# DISPLAY IsChangeStructure._⊝_ x = _⊝_ #-} {-# DISPLAY ChangeStructure._⊝_ x = _⊝_ #-} {-# DISPLAY IsChangeStructure.nil x = nil #-} {-# DISPLAY ChangeStructure.nil x = nil #-} {-# DISPLAY IsCompChangeStructure._⊚_ x = _⊚_ #-} {-# DISPLAY ChangeStructure._⊚_ x = _⊚_ #-} {-# DISPLAY ChangeStructure.ch_from_to_ x = ch_from_to_ #-} module _ {A B : Set} {{CA : ChangeStructure A}} {{CB : ChangeStructure B}} where -- In this module, given change structures CA and CB for A and B, we define -- change structures for A → B, A × B and A ⊎ B. open import Postulate.Extensionality -- Functions instance funCS : ChangeStructure (A → B) infixl 6 _f⊕_ _f⊝_ private fCh = A → Ch A → Ch B fCh_from_to_ : (df : fCh) → (f1 f2 : A → B) → Set fCh_from_to_ = λ df f1 f2 → ∀ da (a1 a2 : A) (daa : ch da from a1 to a2) → ch df a1 da from f1 a1 to f2 a2 _f⊕_ : (A → B) → fCh → A → B _f⊕_ = λ f df a → f a ⊕ df a (nil a) _f⊝_ : (g f : A → B) → fCh _f⊝_ = λ g f a da → g (a ⊕ da) ⊝ f a f⊝-fromto : ∀ (f1 f2 : A → B) → fCh (f2 f⊝ f1) from f1 to f2 f⊝-fromto f1 f2 da a1 a2 daa rewrite sym (fromto→⊕ da a1 a2 daa) = ⊝-fromto (f1 a1) (f2 (a1 ⊕ da)) _f⊚_ : fCh → fCh → fCh _f⊚_ df1 df2 = λ a da → df1 a (nil a) ⊚[ B ] df2 a da _f2⊚_ : fCh → fCh → fCh _f2⊚_ df1 df2 = λ a da → df1 a da ⊚[ B ] df2 (a ⊕ da) (nil (a ⊕ da)) f⊚-fromto : ∀ (f1 f2 f3 : A → B) (df1 df2 : fCh) → fCh df1 from f1 to f2 → fCh df2 from f2 to f3 → fCh df1 f⊚ df2 from f1 to f3 f⊚-fromto f1 f2 f3 df1 df2 dff1 dff2 da a1 a2 daa = ⊚-fromto (f1 a1) (f2 a1) (f3 a2) (df1 a1 (nil a1)) (df2 a1 da) (dff1 (nil a1) a1 a1 (nil-fromto a1)) (dff2 da a1 a2 daa) f⊚2-fromto : ∀ (f1 f2 f3 : A → B) (df1 df2 : fCh) → fCh df1 from f1 to f2 → fCh df2 from f2 to f3 → fCh df1 f2⊚ df2 from f1 to f3 f⊚2-fromto f1 f2 f3 df1 df2 dff1 dff2 da a1 a2 daa rewrite fromto→⊕ da a1 a2 daa = ⊚-fromto (f1 a1) (f2 a2) (f3 a2) (df1 a1 da) (df2 a2 (nil a2)) (dff1 da a1 a2 daa) (dff2 (nil a2) a2 a2 (nil-fromto a2)) funCS = record { Ch = fCh ; ch_from_to_ = λ df f1 f2 → ∀ da (a1 a2 : A) (daa : ch da from a1 to a2) → ch df a1 da from f1 a1 to f2 a2 ; isCompChangeStructure = record { isChangeStructure = record { _⊕_ = _f⊕_ ; fromto→⊕ = λ df f1 f2 dff → ext (λ v → fromto→⊕ (df v (nil v)) (f1 v) (f2 v) (dff (nil v) v v (nil-fromto v))) ; _⊝_ = _f⊝_ ; ⊝-fromto = f⊝-fromto } ; _⊚_ = _f⊚_ ; ⊚-fromto = f⊚-fromto } } -- Products private pCh = Ch A × Ch B _p⊕_ : A × B → Ch A × Ch B → A × B _p⊕_ (a , b) (da , db) = a ⊕ da , b ⊕ db _p⊝_ : A × B → A × B → pCh _p⊝_ (a2 , b2) (a1 , b1) = a2 ⊝ a1 , b2 ⊝ b1 pch_from_to_ : pCh → A × B → A × B → Set pch (da , db) from (a1 , b1) to (a2 , b2) = ch da from a1 to a2 × ch db from b1 to b2 _p⊚_ : pCh → pCh → pCh (da1 , db1) p⊚ (da2 , db2) = da1 ⊚[ A ] da2 , db1 ⊚[ B ] db2 pfromto→⊕ : ∀ dp p1 p2 → pch dp from p1 to p2 → p1 p⊕ dp ≡ p2 pfromto→⊕ (da , db) (a1 , b1) (a2 , b2) (daa , dbb) = cong₂ _,_ (fromto→⊕ _ _ _ daa) (fromto→⊕ _ _ _ dbb) p⊝-fromto : ∀ (p1 p2 : A × B) → pch p2 p⊝ p1 from p1 to p2 p⊝-fromto (a1 , b1) (a2 , b2) = ⊝-fromto a1 a2 , ⊝-fromto b1 b2 p⊚-fromto : ∀ p1 p2 p3 dp1 dp2 → pch dp1 from p1 to p2 → (pch dp2 from p2 to p3) → pch dp1 p⊚ dp2 from p1 to p3 p⊚-fromto (a1 , b1) (a2 , b2) (a3 , b3) (da1 , db1) (da2 , db2) (daa1 , dbb1) (daa2 , dbb2) = ⊚-fromto a1 a2 a3 da1 da2 daa1 daa2 , ⊚-fromto b1 b2 b3 db1 db2 dbb1 dbb2 instance pairCS : ChangeStructure (A × B) pairCS = record { Ch = pCh ; ch_from_to_ = pch_from_to_ ; isCompChangeStructure = record { isChangeStructure = record { _⊕_ = _p⊕_ ; fromto→⊕ = pfromto→⊕ ; _⊝_ = _p⊝_ ; ⊝-fromto = p⊝-fromto } ; _⊚_ = _p⊚_ ; ⊚-fromto = p⊚-fromto } } -- Sums private SumChange = (Ch A ⊎ Ch B) ⊎ (A ⊎ B) data SumChange2 : Set where ch₁ : (da : Ch A) → SumChange2 ch₂ : (db : Ch B) → SumChange2 rp : (s : A ⊎ B) → SumChange2 convert : SumChange → SumChange2 convert (inj₁ (inj₁ da)) = ch₁ da convert (inj₁ (inj₂ db)) = ch₂ db convert (inj₂ s) = rp s convert₁ : SumChange2 → SumChange convert₁ (ch₁ da) = inj₁ (inj₁ da) convert₁ (ch₂ db) = inj₁ (inj₂ db) convert₁ (rp s) = inj₂ s inv1 : ∀ ds → convert₁ (convert ds) ≡ ds inv1 (inj₁ (inj₁ da)) = refl inv1 (inj₁ (inj₂ db)) = refl inv1 (inj₂ s) = refl inv2 : ∀ ds → convert (convert₁ ds) ≡ ds inv2 (ch₁ da) = refl inv2 (ch₂ db) = refl inv2 (rp s) = refl private _s⊕2_ : A ⊎ B → SumChange2 → A ⊎ B _s⊕2_ s (rp s₁) = s₁ _s⊕2_ (inj₁ a) (ch₁ da) = inj₁ (a ⊕ da) _s⊕2_ (inj₂ b) (ch₂ db) = inj₂ (b ⊕ db) _s⊕2_ (inj₂ b) (ch₁ da) = inj₂ b -- invalid _s⊕2_ (inj₁ a) (ch₂ db) = inj₁ a -- invalid _s⊕_ : A ⊎ B → SumChange → A ⊎ B s s⊕ ds = s s⊕2 (convert ds) _s⊝2_ : A ⊎ B → A ⊎ B → SumChange2 _s⊝2_ (inj₁ x2) (inj₁ x1) = ch₁ (x2 ⊝ x1) _s⊝2_ (inj₂ y2) (inj₂ y1) = ch₂ (y2 ⊝ y1) _s⊝2_ s2 s1 = rp s2 _s⊝_ : A ⊎ B → A ⊎ B → SumChange s2 s⊝ s1 = convert₁ (s2 s⊝2 s1) data sch_from_to_ : SumChange → A ⊎ B → A ⊎ B → Set where -- sft = Sum From To sft₁ : ∀ {da a1 a2} (daa : ch da from a1 to a2) → sch (convert₁ (ch₁ da)) from (inj₁ a1) to (inj₁ a2) sft₂ : ∀ {db b1 b2} (dbb : ch db from b1 to b2) → sch (convert₁ (ch₂ db)) from (inj₂ b1) to (inj₂ b2) sftrp : ∀ s1 s2 → sch (convert₁ (rp s2)) from s1 to s2 sfromto→⊕2 : (ds : SumChange2) (s1 s2 : A ⊎ B) → sch convert₁ ds from s1 to s2 → s1 s⊕2 ds ≡ s2 sfromto→⊕2 (ch₁ da) (inj₁ a1) (inj₁ a2) (sft₁ daa) = cong inj₁ (fromto→⊕ _ _ _ daa) sfromto→⊕2 (ch₂ db) (inj₂ b1) (inj₂ b2) (sft₂ dbb) = cong inj₂ (fromto→⊕ _ _ _ dbb) sfromto→⊕2 (rp .s2) .s1 .s2 (sftrp s1 s2) = refl sfromto→⊕ : (ds : SumChange) (s1 s2 : A ⊎ B) → sch ds from s1 to s2 → s1 s⊕ ds ≡ s2 sfromto→⊕ ds s1 s2 dss = sfromto→⊕2 (convert ds) s1 s2 (subst (sch_from s1 to s2) (sym (inv1 ds)) dss) s⊝-fromto : (s1 s2 : A ⊎ B) → sch s2 s⊝ s1 from s1 to s2 s⊝-fromto (inj₁ a1) (inj₁ a2) = sft₁ (⊝-fromto a1 a2) s⊝-fromto (inj₂ b1) (inj₂ b2) = sft₂ (⊝-fromto b1 b2) s⊝-fromto s1@(inj₁ a1) s2@(inj₂ b2) = sftrp s1 s2 s⊝-fromto s1@(inj₂ b1) s2@(inj₁ a2) = sftrp s1 s2 _s⊚2_ : SumChange2 → SumChange2 → SumChange2 ds1 s⊚2 rp s3 = rp s3 ch₁ da1 s⊚2 ch₁ da2 = ch₁ (da1 ⊚[ A ] da2) rp (inj₁ a2) s⊚2 ch₁ da2 = rp (inj₁ (a2 ⊕ da2)) ch₂ db1 s⊚2 ch₂ db2 = ch₂ (db1 ⊚[ B ] db2) rp (inj₂ b2) s⊚2 ch₂ db2 = rp (inj₂ (b2 ⊕ db2)) -- Cases for invalid combinations of input changes. -- -- That is, whenever ds2 is a non-replacement change for outputs that ds1 -- can't produce. -- -- We can prove validity preservation *without* filling this in. ds1 s⊚2 ds2 = ds1 _s⊚_ : SumChange → SumChange → SumChange ds1 s⊚ ds2 = convert₁ (convert ds1 s⊚2 convert ds2) s⊚-fromto : (s1 s2 s3 : A ⊎ B) (ds1 ds2 : SumChange) → sch ds1 from s1 to s2 → sch ds2 from s2 to s3 → sch ds1 s⊚ ds2 from s1 to s3 s⊚-fromto (inj₁ a1) (inj₁ a2) (inj₁ a3) (inj₁ (inj₁ da1)) (inj₁ (inj₁ da2)) (sft₁ daa1) (sft₁ daa2) = sft₁ (⊚-fromto a1 a2 a3 _ _ daa1 daa2) s⊚-fromto (inj₂ b1) (inj₂ b2) (inj₂ b3) (inj₁ (inj₂ db1)) (inj₁ (inj₂ db2)) (sft₂ dbb1) (sft₂ dbb2) = sft₂ (⊚-fromto b1 b2 b3 _ _ dbb1 dbb2) s⊚-fromto s1 (inj₁ a2) (inj₁ a3) .(inj₂ (inj₁ _)) .(inj₁ (inj₁ _)) (sftrp .s1 .(inj₁ _)) (sft₁ daa) rewrite fromto→⊕ _ a2 a3 daa = sftrp _ _ s⊚-fromto s1 (inj₂ b2) (inj₂ b3) .(inj₂ (inj₂ _)) .(inj₁ (inj₂ _)) (sftrp .s1 .(inj₂ _)) (sft₂ dbb) rewrite fromto→⊕ _ b2 b3 dbb = sftrp _ _ s⊚-fromto s1 s2 s3 _ _ _ (sftrp .s2 .s3) = sftrp s1 s3 -- s⊚-fromto .(inj₂ b1) .(inj₁ a2) (inj₁ a3) .(inj₂ (inj₁ a2)) (inj₁ (inj₁ da2)) (sftrp (inj₂ b1) (inj₁ a2)) (sft₁ daa2) with sfromto→⊕ (inj₁ (inj₁ da2)) _ _ (sft₁ daa2) -- s⊚-fromto .(inj₂ b1) .(inj₁ a2) (inj₁ .(a2 ⊕ da2)) .(inj₂ (inj₁ a2)) (inj₁ (inj₁ da2)) (sftrp (inj₂ b1) (inj₁ a2)) (sft₁ daa2) | refl = sftrp (inj₂ b1) (inj₁ (a2 ⊕ da2)) -- s⊚-fromto .(inj₁ a1) .(inj₂ b2) (inj₂ b3) .(inj₂ (inj₂ b2)) (inj₁ (inj₂ db2)) (sftrp (inj₁ a1) (inj₂ b2)) (sft₂ dbb2) with sfromto→⊕ (inj₁ (inj₂ db2)) _ _ (sft₂ dbb2) -- s⊚-fromto .(inj₁ a1) .(inj₂ b2) (inj₂ .(b2 ⊕ db2)) .(inj₂ (inj₂ b2)) (inj₁ (inj₂ db2)) (sftrp (inj₁ a1) (inj₂ b2)) (sft₂ dbb2) | refl = sftrp (inj₁ a1) (inj₂ (b2 ⊕ db2)) instance sumCS : ChangeStructure (A ⊎ B) sumCS = record { Ch = SumChange ; ch_from_to_ = sch_from_to_ ; isCompChangeStructure = record { isChangeStructure = record { _⊕_ = _s⊕_ ; fromto→⊕ = sfromto→⊕ ; _⊝_ = _s⊝_ ; ⊝-fromto = s⊝-fromto } ; _⊚_ = _s⊚_ ; ⊚-fromto = s⊚-fromto } } instance unitCS : ChangeStructure ⊤ unitCS = record { Ch = ⊤ ; ch_from_to_ = λ dv v1 v2 → ⊤ ; isCompChangeStructure = record { isChangeStructure = record { _⊕_ = λ _ _ → tt ; fromto→⊕ = λ { _ _ tt _ → refl } ; _⊝_ = λ _ _ → tt ; ⊝-fromto = λ a b → tt } ; _⊚_ = λ da1 da2 → tt ; ⊚-fromto = λ a1 a2 a3 da1 da2 daa1 daa2 → tt } }
{ "alphanum_fraction": 0.5484035326, "avg_line_length": 35.5770392749, "ext": "agda", "hexsha": "c663828ade6d2c56cce057ec4a534aaeb9ac603a", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Thesis/Changes.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Thesis/Changes.agda", "max_line_length": 174, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Thesis/Changes.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 5812, "size": 11776 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae module Monoids.Definition where record Monoid {a : _} {A : Set a} (Zero : A) (_+_ : A → A → A) : Set a where field associative : (a b c : A) → a + (b + c) ≡ (a + b) + c idLeft : (a : A) → Zero + a ≡ a idRight : (a : A) → a + Zero ≡ a
{ "alphanum_fraction": 0.5363636364, "avg_line_length": 27.5, "ext": "agda", "hexsha": "f6f71aef9a3d4f0bced11863892a5a6e3e79235c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Monoids/Definition.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Monoids/Definition.agda", "max_line_length": 76, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Monoids/Definition.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 123, "size": 330 }
import Lvl open import Type module Structure.Logic.Classical.NaturalDeduction {ℓₗ} {Formula : Type{ℓₗ}} {ℓₘₗ} (Proof : Formula → Type{ℓₘₗ}) where open import Functional hiding (Domain) import Structure.Logic.Constructive.NaturalDeduction private module Constructive = Structure.Logic.Constructive.NaturalDeduction(Proof) -- TODO: Maybe it is worth to try and take a more minimal approach? (Less axioms? Is this more practical/impractical?) module Propositional where open Constructive.Propositional hiding (Theory) public -- A theory of classical propositional logic expressed using natural deduction rules record Theory ⦃ sign : Signature ⦄ : Type{ℓₘₗ Lvl.⊔ ℓₗ} where open Signature(sign) field instance ⦃ constructive ⦄ : Constructive.Propositional.Theory ⦃ sign ⦄ open Constructive.Propositional.Theory (constructive) public field excluded-middle : ∀{P} → Proof(P ∨ (¬ P)) module Domained = Constructive.Domained module MultiSorted = Constructive.MultiSorted {- Propositional-from-[∧][∨][⊥] : ∀{ℓₗ} → (_∧_ _∨_ : Formula → Formula → Formula) → (⊥ : Formula) → ([∧]-intro : ∀{X Y} → X → Y → (X ∧ Y)) → ([∧]-elimₗ : ∀{X Y} → (X ∧ Y) → X) → ([∧]-elimᵣ : ∀{X Y} → (X ∧ Y) → Y) → ([∨]-introₗ : ∀{X Y} → X → (X ∨ Y)) → ([∨]-introᵣ : ∀{X Y} → Y → (X ∨ Y)) → ([∨]-elim : ∀{X Y Z : Formula} → (X → Z) → (Y → Z) → (X ∨ Y) → Z) → ([⊥]-intro : ∀{X : Formula} → X → (X → ⊥) → ⊥) → ([⊥]-elim : ∀{X : Formula} → ⊥ → X) → Propositional{ℓₗ} Propositional-from-[∧][∨][⊥] (_∧_) (_∨_) (⊥) ([∧]-intro) ([∧]-elimₗ) ([∧]-elimᵣ) ([∨]-introₗ) ([∨]-introᵣ) ([∨]-elim) ([⊥]-intro) ([⊥]-elim) = record{ _∧_ = _∧_ ; _∨_ = _∨_ ; _⟶_ = (x ↦ y ↦ (x ∨ (¬ y))) ; _⟵_ = swap _⟶_ ; _⟷_ = (x ↦ y ↦ ((x ⟵ y)∧(x ⟶ y))) ; ¬_ = (x ↦ (x ⟶ ⊥)) ; ⊥ = ⊥ ; ⊤ = ¬ ⊥ } -} module _ {ℓₒ} (Domain : Type{ℓₒ}) where record ClassicalLogicSignature : Type{ℓₘₗ Lvl.⊔ (ℓₗ Lvl.⊔ ℓₒ)} where open Domained(Domain) field instance ⦃ propositionalSignature ⦄ : Propositional.Signature instance ⦃ predicateSignature ⦄ : Predicate.Signature instance ⦃ equalitySignature ⦄ : Equality.Signature constructiveLogicSignature : Constructive.ConstructiveLogicSignature(Domain) constructiveLogicSignature = record{ propositionalSignature = propositionalSignature ; predicateSignature = predicateSignature ; equalitySignature = equalitySignature } open Propositional.Signature(propositionalSignature) public open Predicate.Signature(predicateSignature) public open Equality.Signature(equalitySignature) public open Equality.PropositionallyDerivedSignature ⦃ propositionalSignature ⦄ ⦃ equalitySignature ⦄ public open Uniqueness.Signature ⦃ propositionalSignature ⦄ ⦃ predicateSignature ⦄ ⦃ equalitySignature ⦄ public -- A theory of classical predicate/(first-order) logic expressed using natural deduction rules record ClassicalLogic : Type{ℓₘₗ Lvl.⊔ (ℓₗ Lvl.⊔ ℓₒ)} where open Domained(Domain) field instance ⦃ classicalLogicSignature ⦄ : ClassicalLogicSignature open ClassicalLogicSignature(classicalLogicSignature) public field instance ⦃ propositionalTheory ⦄ : Propositional.Theory ⦃ propositionalSignature ⦄ instance ⦃ predicateTheory ⦄ : Predicate.Theory instance ⦃ equalityTheory ⦄ : Equality.Theory instance ⦃ existentialWitness ⦄ : Predicate.ExistentialWitness(∃ₗ) ⦃ nonEmptyDomain ⦄ : NonEmptyDomain constructivePropositionalTheory = Propositional.Theory.constructive(propositionalTheory) constructiveLogic : Constructive.ConstructiveLogic(Domain) constructiveLogic = record{ constructiveLogicSignature = constructiveLogicSignature ; propositionalTheory = constructivePropositionalTheory ; predicateTheory = predicateTheory ; equalityTheory = equalityTheory } open Propositional.Theory(propositionalTheory) public open Predicate.Theory(predicateTheory) public open Equality.Theory(equalityTheory) public open Predicate.ExistentialWitness(existentialWitness) public open Uniqueness.WitnessTheory ⦃ propositionalSignature ⦄ ⦃ predicateSignature ⦄ ⦃ equalitySignature ⦄ ⦃ constructivePropositionalTheory ⦄ ⦃ predicateTheory ⦄ ⦃ equalityTheory ⦄ ⦃ existentialWitness ⦄ public open NonEmptyDomain ⦃ nonEmptyDomain ⦄ public
{ "alphanum_fraction": 0.6541994751, "avg_line_length": 38.4201680672, "ext": "agda", "hexsha": "b981723bcf85ecb056f7903f6af45bed37ed1444", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "old/Structure/Logic/Classical/NaturalDeduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "old/Structure/Logic/Classical/NaturalDeduction.agda", "max_line_length": 210, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "old/Structure/Logic/Classical/NaturalDeduction.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 1452, "size": 4572 }
------------------------------------------------------------------------ -- Internal coding ------------------------------------------------------------------------ module Internal-coding where open import Equality.Propositional open import Prelude hiding (const) open import Tactic.By.Propositional -- To simplify the development, let's work with actual natural numbers -- as variables and constants (see -- Atom.one-can-restrict-attention-to-χ-ℕ-atoms). open import Atom open import Chi χ-ℕ-atoms open import Coding χ-ℕ-atoms open import Constants χ-ℕ-atoms open import Free-variables χ-ℕ-atoms open import Reasoning χ-ℕ-atoms open χ-atoms χ-ℕ-atoms import Coding.Instances.Nat abstract -- Some auxiliary definitions. private cd : Var → Exp cd x = apply (var v-internal-code) (var x) nullary-branch : Const → Br nullary-branch c = branch c [] ( const c-const (⌜ c ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ [])) unary-branch : Const → Br unary-branch c = branch c (v-x ∷ []) ( const c-const (⌜ c ⌝ ∷ const c-cons (cd v-x ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ [])) binary-branch : Const → Br binary-branch c = branch c (v-x ∷ v-y ∷ []) ( const c-const (⌜ c ⌝ ∷ const c-cons (cd v-x ∷ const c-cons (cd v-y ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ [])) trinary-branch : Const → Br trinary-branch c = branch c (v-x ∷ v-y ∷ v-z ∷ []) ( const c-const (⌜ c ⌝ ∷ const c-cons (cd v-x ∷ const c-cons (cd v-y ∷ const c-cons (cd v-z ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ [])) branches : List Br branches = nullary-branch c-zero ∷ unary-branch c-suc ∷ nullary-branch c-nil ∷ binary-branch c-cons ∷ binary-branch c-apply ∷ binary-branch c-lambda ∷ binary-branch c-case ∷ binary-branch c-rec ∷ unary-branch c-var ∷ binary-branch c-const ∷ trinary-branch c-branch ∷ [] -- Internal coding. internal-code : Exp internal-code = rec v-internal-code (lambda v-p (case (var v-p) branches)) internal-code-closed : Closed internal-code internal-code-closed = from-⊎ (closed? internal-code) -- The internal coder encodes natural numbers correctly. internal-code-correct-ℕ : (n : ℕ) → apply internal-code ⌜ n ⌝ ⇓ ⌜ ⌜ n ⌝ ⦂ Exp ⌝ internal-code-correct-ℕ n = apply internal-code ⌜ n ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep n) ⟩ case ⌜ n ⌝ branches′ ⇓⟨ lemma n ⟩■ ⌜ ⌜ n ⌝ ⦂ Exp ⌝ where branches′ : List Br branches′ = branches [ v-internal-code ← internal-code ]B⋆ lemma : (n : ℕ) → case ⌜ n ⌝ branches′ ⇓ ⌜ ⌜ n ⌝ ⦂ Exp ⌝ lemma zero = case ⌜ zero ⌝ branches′ ⇓⟨ case (rep⇓rep zero) here [] (rep⇓rep (⌜ zero ⌝ ⦂ Exp)) ⟩■ ⌜ ⌜ zero ⌝ ⦂ Exp ⌝ lemma (suc n) = case ⌜ suc n ⌝ branches′ ⟶⟨ case (rep⇓rep (suc n)) (there (λ ()) here) (∷ []) ⟩ const c-const (⌜ c-suc ⌝ ∷ const c-cons (apply internal-code ⌜ n ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-suc ∷ const (internal-code-correct-ℕ n ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ⟩■ ⌜ ⌜ suc n ⌝ ⦂ Exp ⌝ -- The internal coder encodes lists of variables correctly. internal-code-correct-Var⋆ : (xs : List Var) → apply internal-code ⌜ xs ⌝ ⇓ ⌜ ⌜ xs ⌝ ⦂ Exp ⌝ internal-code-correct-Var⋆ xs = apply internal-code ⌜ xs ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep xs) ⟩ case ⌜ xs ⌝ branches′ ⇓⟨ lemma xs ⟩■ ⌜ ⌜ xs ⌝ ⦂ Exp ⌝ where branches′ : List Br branches′ = branches [ v-internal-code ← internal-code ]B⋆ lemma : (xs : List Var) → case ⌜ xs ⌝ branches′ ⇓ ⌜ ⌜ xs ⌝ ⦂ Exp ⌝ lemma [] = case ⌜ [] ⦂ List Var ⌝ branches′ ⇓⟨ case (rep⇓rep ([] ⦂ List Var)) (there (λ ()) (there (λ ()) here)) [] (rep⇓rep (⌜ [] ⦂ List Var ⌝ ⦂ Exp)) ⟩■ ⌜ ⌜ [] ⦂ List Var ⌝ ⦂ Exp ⌝ lemma (x ∷ xs) = case ⌜ x List.∷ xs ⌝ branches′ ⟶⟨ case (rep⇓rep (x List.∷ xs)) (there (λ ()) (there (λ ()) (there (λ ()) here))) (∷ ∷ []) ⟩ const c-const (⌜ c-cons ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ xs ⌝ [ v-x ← ⌜ x ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep xs) ⟩⟶ const c-const (⌜ c-cons ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ const c-cons (apply internal-code ⌜ xs ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-cons ∷ const (internal-code-correct-ℕ x ∷ const (internal-code-correct-Var⋆ xs ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ x List.∷ xs ⌝ ⦂ Exp ⌝ mutual -- The internal coder encodes expressions correctly. internal-code-correct : (p : Exp) → apply internal-code ⌜ p ⌝ ⇓ ⌜ ⌜ p ⌝ ⦂ Exp ⌝ internal-code-correct p = apply internal-code ⌜ p ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep p) ⟩ case ⌜ p ⌝ branches′ ⇓⟨ lemma p ⟩■ ⌜ ⌜ p ⌝ ⦂ Exp ⌝ where branches′ : List Br branches′ = branches [ v-internal-code ← internal-code ]B⋆ lemma : (p : Exp) → case ⌜ p ⌝ branches′ ⇓ ⌜ ⌜ p ⌝ ⦂ Exp ⌝ lemma (apply p₁ p₂) = case ⌜ Exp.apply p₁ p₂ ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.apply p₁ p₂)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here)))) (∷ ∷ []) ⟩ const c-const (⌜ c-apply ⌝ ∷ const c-cons (apply internal-code ⌜ p₁ ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ p₂ ⌝ [ v-x ← ⌜ p₁ ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep p₂) ⟩⟶ const c-const (⌜ c-apply ⌝ ∷ const c-cons (apply internal-code ⌜ p₁ ⌝ ∷ const c-cons (apply internal-code ⌜ p₂ ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-apply ∷ const (internal-code-correct p₁ ∷ const (internal-code-correct p₂ ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ Exp.apply p₁ p₂ ⌝ ⦂ Exp ⌝ lemma (lambda x p) = case ⌜ Exp.lambda x p ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.lambda x p)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here))))) (∷ ∷ []) ⟩ const c-const (⌜ c-lambda ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ p ⌝ [ v-x ← ⌜ x ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep p) ⟩⟶ const c-const (⌜ c-lambda ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ const c-cons (apply internal-code ⌜ p ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-lambda ∷ const (internal-code-correct-ℕ x ∷ const (internal-code-correct p ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ Exp.lambda x p ⌝ ⦂ Exp ⌝ lemma (case p bs) = case ⌜ Exp.case p bs ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.case p bs)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here)))))) (∷ ∷ []) ⟩ const c-const (⌜ c-case ⌝ ∷ const c-cons (apply internal-code ⌜ p ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ bs ⌝ [ v-x ← ⌜ p ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep bs) ⟩⟶ const c-const (⌜ c-case ⌝ ∷ const c-cons (apply internal-code ⌜ p ⌝ ∷ const c-cons (apply internal-code ⌜ bs ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-case ∷ const (internal-code-correct p ∷ const (internal-code-correct-B⋆ bs ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ Exp.case p bs ⌝ ⦂ Exp ⌝ lemma (rec x p) = case ⌜ Exp.rec x p ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.rec x p)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here))))))) (∷ ∷ []) ⟩ const c-const (⌜ c-rec ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ p ⌝ [ v-x ← ⌜ x ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep p) ⟩⟶ const c-const (⌜ c-rec ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ const c-cons (apply internal-code ⌜ p ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-rec ∷ const (internal-code-correct-ℕ x ∷ const (internal-code-correct p ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ Exp.rec x p ⌝ ⦂ Exp ⌝ lemma (var x) = case ⌜ Exp.var x ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.var x)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here)))))))) (∷ []) ⟩ const c-const (⌜ c-var ⌝ ∷ const c-cons (apply internal-code ⌜ x ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-var ∷ const (internal-code-correct-ℕ x ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ⟩■ ⌜ ⌜ Exp.var x ⌝ ⦂ Exp ⌝ lemma (const c ps) = case ⌜ Exp.const c ps ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.const c ps)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here))))))))) (∷ ∷ []) ⟩ const c-const (⌜ c-const ⌝ ∷ const c-cons (apply internal-code ⌜ c ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ ps ⌝ [ v-x ← ⌜ c ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep ps) ⟩⟶ const c-const (⌜ c-const ⌝ ∷ const c-cons (apply internal-code ⌜ c ⌝ ∷ const c-cons (apply internal-code ⌜ ps ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-const ∷ const (internal-code-correct-ℕ c ∷ const (internal-code-correct-⋆ ps ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ Exp.const c ps ⌝ ⦂ Exp ⌝ -- The internal coder encodes branches correctly. internal-code-correct-B : (b : Br) → apply internal-code ⌜ b ⌝ ⇓ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ internal-code-correct-B (branch c xs e) = apply internal-code ⌜ branch c xs e ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep (branch c xs e)) ⟩ case ⌜ branch c xs e ⌝ branches′ ⟶⟨ case (rep⇓rep (branch c xs e)) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) here)))))))))) (∷ ∷ ∷ []) ⟩ const c-const (⌜ c-branch ⌝ ∷ const c-cons (apply internal-code ⌜ c ⌝ ∷ const c-cons (apply internal-code ⌜ xs ⌝ [ v-x ← ⌜ c ⌝ ] ∷ const c-cons (apply internal-code ⟨ ⌜ e ⌝ [ v-y ← ⌜ xs ⌝ ] [ v-x ← ⌜ c ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (substs-rep e ((v-x , ⌜ c ⌝) ∷ (v-y , ⌜ xs ⌝) ∷ [])) ⟩⟶ const c-const (⌜ c-branch ⌝ ∷ const c-cons (apply internal-code ⌜ c ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ xs ⌝ [ v-x ← ⌜ c ⌝ ] ⟩ ∷ const c-cons (apply internal-code ⌜ e ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep xs) ⟩⟶ const c-const (⌜ c-branch ⌝ ∷ const c-cons (apply internal-code ⌜ c ⌝ ∷ const c-cons (apply internal-code ⌜ xs ⌝ ∷ const c-cons (apply internal-code ⌜ e ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-branch ∷ const (internal-code-correct-ℕ c ∷ const (internal-code-correct-Var⋆ xs ∷ const (internal-code-correct e ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ branch c xs e ⌝ ⦂ Exp ⌝ where branches′ : List Br branches′ = branches [ v-internal-code ← internal-code ]B⋆ -- The internal coder encodes lists of expressions correctly. internal-code-correct-⋆ : (ps : List Exp) → apply internal-code ⌜ ps ⌝ ⇓ ⌜ ⌜ ps ⌝ ⦂ Exp ⌝ internal-code-correct-⋆ ps = apply internal-code ⌜ ps ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep ps) ⟩ case ⌜ ps ⌝ branches′ ⇓⟨ lemma ps ⟩■ ⌜ ⌜ ps ⌝ ⦂ Exp ⌝ where branches′ : List Br branches′ = branches [ v-internal-code ← internal-code ]B⋆ lemma : (ps : List Exp) → case ⌜ ps ⌝ branches′ ⇓ ⌜ ⌜ ps ⌝ ⦂ Exp ⌝ lemma [] = case ⌜ [] ⦂ List Exp ⌝ branches′ ⇓⟨ case (rep⇓rep ([] ⦂ List Exp)) (there (λ ()) (there (λ ()) here)) [] (rep⇓rep (⌜ [] ⦂ List Exp ⌝ ⦂ Exp)) ⟩■ ⌜ ⌜ [] ⦂ List Exp ⌝ ⦂ Exp ⌝ lemma (p ∷ ps) = case ⌜ p List.∷ ps ⌝ branches′ ⟶⟨ case (rep⇓rep (p List.∷ ps)) (there (λ ()) (there (λ ()) (there (λ ()) here))) (∷ ∷ []) ⟩ const c-const (⌜ c-cons ⌝ ∷ const c-cons (apply internal-code ⌜ p ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ ps ⌝ [ v-x ← ⌜ p ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep ps) ⟩⟶ const c-const (⌜ c-cons ⌝ ∷ const c-cons (apply internal-code ⌜ p ⌝ ∷ const c-cons (apply internal-code ⌜ ps ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-cons ∷ const (internal-code-correct p ∷ const (internal-code-correct-⋆ ps ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ p List.∷ ps ⌝ ⦂ Exp ⌝ -- The internal coder encodes lists of branches correctly. internal-code-correct-B⋆ : (bs : List Br) → apply internal-code ⌜ bs ⌝ ⇓ ⌜ ⌜ bs ⌝ ⦂ Exp ⌝ internal-code-correct-B⋆ bs = apply internal-code ⌜ bs ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep bs) ⟩ case ⌜ bs ⌝ branches′ ⇓⟨ lemma bs ⟩■ ⌜ ⌜ bs ⌝ ⦂ Exp ⌝ where branches′ : List Br branches′ = branches [ v-internal-code ← internal-code ]B⋆ lemma : (bs : List Br) → case ⌜ bs ⌝ branches′ ⇓ ⌜ ⌜ bs ⌝ ⦂ Exp ⌝ lemma [] = case ⌜ [] ⦂ List Br ⌝ branches′ ⇓⟨ case (rep⇓rep ([] ⦂ List Br)) (there (λ ()) (there (λ ()) here)) [] (rep⇓rep (⌜ [] ⦂ List Br ⌝ ⦂ Exp)) ⟩■ ⌜ ⌜ [] ⦂ List Br ⌝ ⦂ Exp ⌝ lemma (b ∷ bs) = case ⌜ b List.∷ bs ⌝ branches′ ⟶⟨ case (rep⇓rep (b List.∷ bs)) (there (λ ()) (there (λ ()) (there (λ ()) here))) (∷ ∷ []) ⟩ const c-const (⌜ c-cons ⌝ ∷ const c-cons (apply internal-code ⌜ b ⌝ ∷ const c-cons (apply internal-code ⟨ ⌜ bs ⌝ [ v-x ← ⌜ b ⌝ ] ⟩ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep bs) ⟩⟶ const c-const (⌜ c-cons ⌝ ∷ const c-cons (apply internal-code ⌜ b ⌝ ∷ const c-cons (apply internal-code ⌜ bs ⌝ ∷ ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-cons ∷ const (internal-code-correct-B b ∷ const (internal-code-correct-B⋆ bs ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■ ⌜ ⌜ b List.∷ bs ⌝ ⦂ Exp ⌝
{ "alphanum_fraction": 0.3418415206, "avg_line_length": 52.7473958333, "ext": "agda", "hexsha": "a891e27d58ceccb68bf9a26617dc884038e29194", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/chi", "max_forks_repo_path": "src/Internal-coding.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/chi", "max_issues_repo_path": "src/Internal-coding.agda", "max_line_length": 144, "max_stars_count": 2, "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/chi", "max_stars_repo_path": "src/Internal-coding.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "num_tokens": 6121, "size": 20255 }
module Everything where import Control.Category import Control.Category.Functor import Control.Category.Product import Control.Category.SetsAndFunctions import Control.Category.Slice import Control.Decoration import Control.Functor import Control.Functor.NaturalTransformation import Control.Functor.Product import Control.Kleisli import Control.Lens import Control.Monad import Control.Monad.Error import Control.Monad.KleisliTriple import Control.Comonad import Control.Comonad.Store import Dimension.PartialWeakening import Dimension.PartialWeakening.Model -- import Dimension.PartialWeakening.Soundness -- still broken
{ "alphanum_fraction": 0.8690095847, "avg_line_length": 26.0833333333, "ext": "agda", "hexsha": "ccf9e29db028a772de42469ac1dbc79839102017", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/cubical", "max_forks_repo_path": "src/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/cubical", "max_issues_repo_path": "src/Everything.agda", "max_line_length": 62, "max_stars_count": null, "max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/cubical", "max_stars_repo_path": "src/Everything.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 131, "size": 626 }
------------------------------------------------------------------------ -- The lens type in Lens.Non-dependent.Higher.Capriotti.Variant, but -- with erased "proofs" ------------------------------------------------------------------------ {-# OPTIONS --cubical #-} import Equality.Path as P module Lens.Non-dependent.Higher.Capriotti.Variant.Erased {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection equality-with-J using (_↔_) open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_) open import Equivalence.Erased.Cubical eq as EEq using (_≃ᴱ_) open import Equivalence.Erased.Contractible-preimages.Cubical eq as ECP using (_⁻¹ᴱ_) open import Erased.Cubical eq open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional eq as T using (∥_∥; ∣_∣) open import Preimage equality-with-J using (_⁻¹_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq import Lens.Non-dependent.Higher.Erased eq as Higher import Lens.Non-dependent.Higher.Capriotti.Variant eq as V private variable a b p : Level A B : Type a ------------------------------------------------------------------------ -- The lens type family -- Coherently constant type-valued functions. Coherently-constant : {A : Type a} → (A → Type p) → Type (a ⊔ lsuc p) Coherently-constant {p = p} {A = A} P = ∃ λ (Q : ∥ A ∥ → Type p) → ∀ x → P x ≃ᴱ Q ∣ x ∣ -- Higher lenses with erased "proofs". Lens : Type a → Type b → Type (lsuc (a ⊔ b)) Lens A B = ∃ λ (get : A → B) → Coherently-constant (get ⁻¹ᴱ_) -- In erased contexts Lens A B is equivalent to V.Lens A B. @0 Lens≃Variant-lens : Lens A B ≃ V.Lens A B Lens≃Variant-lens = (∃ λ get → ∃ λ Q → ∀ x → get ⁻¹ᴱ x ≃ᴱ Q ∣ x ∣) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → inverse EEq.≃≃≃ᴱ) ⟩ (∃ λ get → ∃ λ Q → ∀ x → get ⁻¹ᴱ x ≃ Q ∣ x ∣) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → Eq.≃-preserves ext (inverse ECP.⁻¹≃⁻¹ᴱ) F.id) ⟩□ (∃ λ get → ∃ λ Q → ∀ x → get ⁻¹ x ≃ Q ∣ x ∣) □ -- Some derived definitions. module Lens {A : Type a} {B : Type b} (l : Lens A B) where -- A getter. get : A → B get = proj₁ l -- A predicate. H : Pow a ∥ B ∥ H = proj₁ (proj₂ l) -- An equivalence (with erased proofs). get⁻¹ᴱ-≃ᴱ : ∀ b → get ⁻¹ᴱ b ≃ᴱ H ∣ b ∣ get⁻¹ᴱ-≃ᴱ = proj₂ (proj₂ l) -- All the getter's "preimages" are equivalent (with erased proofs). get⁻¹ᴱ-constant : (b₁ b₂ : B) → get ⁻¹ᴱ b₁ ≃ᴱ get ⁻¹ᴱ b₂ get⁻¹ᴱ-constant b₁ b₂ = get ⁻¹ᴱ b₁ ↝⟨ get⁻¹ᴱ-≃ᴱ b₁ ⟩ H ∣ b₁ ∣ ↔⟨ ≡⇒≃ $ cong H $ T.truncation-is-proposition _ _ ⟩ H ∣ b₂ ∣ ↝⟨ inverse $ get⁻¹ᴱ-≃ᴱ b₂ ⟩□ get ⁻¹ᴱ b₂ □ -- The two directions of get⁻¹ᴱ-constant. get⁻¹ᴱ-const : (b₁ b₂ : B) → get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂ get⁻¹ᴱ-const b₁ b₂ = _≃ᴱ_.to (get⁻¹ᴱ-constant b₁ b₂) get⁻¹ᴱ-const⁻¹ᴱ : (b₁ b₂ : B) → get ⁻¹ᴱ b₂ → get ⁻¹ᴱ b₁ get⁻¹ᴱ-const⁻¹ᴱ b₁ b₂ = _≃ᴱ_.from (get⁻¹ᴱ-constant b₁ b₂) -- Some coherence properties. @0 get⁻¹ᴱ-const-∘ : (b₁ b₂ b₃ : B) (p : get ⁻¹ᴱ b₁) → get⁻¹ᴱ-const b₂ b₃ (get⁻¹ᴱ-const b₁ b₂ p) ≡ get⁻¹ᴱ-const b₁ b₃ p get⁻¹ᴱ-const-∘ b₁ b₂ b₃ p = _≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ b₃) (≡⇒→ (cong H $ T.truncation-is-proposition _ _) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b₂) (_≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ b₂) (≡⇒→ (cong H $ T.truncation-is-proposition _ _) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b₁) p))))) ≡⟨ cong (_≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ _) ∘ ≡⇒→ _) $ _≃ᴱ_.right-inverse-of (get⁻¹ᴱ-≃ᴱ _) _ ⟩ _≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ b₃) (≡⇒→ (cong H $ T.truncation-is-proposition _ _) (≡⇒→ (cong H $ T.truncation-is-proposition _ _) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b₁) p))) ≡⟨ cong (λ eq → _≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ _) (_≃_.to eq (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ _) _))) $ sym $ ≡⇒≃-trans ext _ _ ⟩ _≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ b₃) (≡⇒→ (trans (cong H $ T.truncation-is-proposition _ _) (cong H $ T.truncation-is-proposition _ _)) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b₁) p)) ≡⟨ cong (λ eq → _≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ b₃) (≡⇒→ eq _)) $ trans (sym $ cong-trans _ _ _) $ cong (cong H) $ mono₁ 1 T.truncation-is-proposition _ _ ⟩∎ _≃ᴱ_.from (get⁻¹ᴱ-≃ᴱ b₃) (≡⇒→ (cong H $ T.truncation-is-proposition _ _) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b₁) p)) ∎ @0 get⁻¹ᴱ-const-id : (b : B) (p : get ⁻¹ᴱ b) → get⁻¹ᴱ-const b b p ≡ p get⁻¹ᴱ-const-id b p = get⁻¹ᴱ-const b b p ≡⟨ sym $ _≃ᴱ_.left-inverse-of (get⁻¹ᴱ-constant _ _) _ ⟩ get⁻¹ᴱ-const⁻¹ᴱ b b (get⁻¹ᴱ-const b b (get⁻¹ᴱ-const b b p)) ≡⟨ cong (get⁻¹ᴱ-const⁻¹ᴱ b b) $ get⁻¹ᴱ-const-∘ _ _ _ _ ⟩ get⁻¹ᴱ-const⁻¹ᴱ b b (get⁻¹ᴱ-const b b p) ≡⟨ _≃ᴱ_.left-inverse-of (get⁻¹ᴱ-constant _ _) _ ⟩∎ p ∎ @0 get⁻¹ᴱ-const-inverse : (b₁ b₂ : B) (p : get ⁻¹ᴱ b₁) → get⁻¹ᴱ-const b₁ b₂ p ≡ get⁻¹ᴱ-const⁻¹ᴱ b₂ b₁ p get⁻¹ᴱ-const-inverse b₁ b₂ p = sym $ _≃_.to-from (EEq.≃ᴱ→≃ (get⁻¹ᴱ-constant _ _)) ( get⁻¹ᴱ-const b₂ b₁ (get⁻¹ᴱ-const b₁ b₂ p) ≡⟨ get⁻¹ᴱ-const-∘ _ _ _ _ ⟩ get⁻¹ᴱ-const b₁ b₁ p ≡⟨ get⁻¹ᴱ-const-id _ _ ⟩∎ p ∎) -- A setter. set : A → B → A set a b = $⟨ get⁻¹ᴱ-const _ _ ⟩ (get ⁻¹ᴱ get a → get ⁻¹ᴱ b) ↝⟨ _$ (a , [ refl _ ]) ⟩ get ⁻¹ᴱ b ↝⟨ proj₁ ⟩□ A □ -- Lens laws. @0 get-set : ∀ a b → get (set a b) ≡ b get-set a b = get (proj₁ (get⁻¹ᴱ-const (get a) b (a , [ refl _ ]))) ≡⟨ erased (proj₂ (get⁻¹ᴱ-const (get a) b (a , [ refl _ ]))) ⟩∎ b ∎ @0 set-get : ∀ a → set a (get a) ≡ a set-get a = proj₁ (get⁻¹ᴱ-const (get a) (get a) (a , [ refl _ ])) ≡⟨ cong proj₁ $ get⁻¹ᴱ-const-id _ _ ⟩∎ a ∎ @0 set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ set-set a b₁ b₂ = proj₁ (get⁻¹ᴱ-const (get (set a b₁)) b₂ (set a b₁ , [ refl _ ])) ≡⟨ elim¹ (λ {b} eq → proj₁ (get⁻¹ᴱ-const (get (set a b₁)) b₂ (set a b₁ , [ refl _ ])) ≡ proj₁ (get⁻¹ᴱ-const b b₂ (set a b₁ , [ eq ]))) (refl _) (get-set a b₁) ⟩ proj₁ (get⁻¹ᴱ-const b₁ b₂ (set a b₁ , [ get-set a b₁ ])) ≡⟨⟩ proj₁ (get⁻¹ᴱ-const b₁ b₂ (get⁻¹ᴱ-const (get a) b₁ (a , [ refl _ ]))) ≡⟨ cong proj₁ $ get⁻¹ᴱ-const-∘ _ _ _ _ ⟩∎ proj₁ (get⁻¹ᴱ-const (get a) b₂ (a , [ refl _ ])) ∎ -- TODO: Can get-set-get and get-set-set be proved for the lens laws -- given above? instance -- The lenses defined above have getters and setters. has-getter-and-setter : Has-getter-and-setter (Lens {a = a} {b = b}) has-getter-and-setter = record { get = Lens.get ; set = Lens.set } ------------------------------------------------------------------------ -- Equality characterisation lemmas -- An equality characterisation lemma. @0 equality-characterisation₁ : {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → Block "equality-characterisation" → let open Lens in (l₁ ≡ l₂) ≃ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (h : H l₁ ≡ H l₂) → ∀ b p → subst (_$ ∣ b ∣) h (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym g) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) equality-characterisation₁ {a = a} {l₁ = l₁} {l₂ = l₂} ⊠ = l₁ ≡ l₂ ↝⟨ inverse $ Eq.≃-≡ Lens≃Variant-lens ⟩ l₁′ ≡ l₂′ ↝⟨ V.equality-characterisation₁ ⊠ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (h : H l₁ ≡ H l₂) → ∀ b p → subst (_$ ∣ b ∣) h (_≃_.to (V.Lens.get⁻¹-≃ l₁′ b) (subst (_⁻¹ b) (sym g) p)) ≡ _≃_.to (V.Lens.get⁻¹-≃ l₂′ b) p) ↝⟨ (∃-cong λ g → ∃-cong λ h → ∀-cong ext λ b → Π-cong ext ECP.⁻¹≃⁻¹ᴱ λ p → ≡⇒↝ _ $ cong (λ p′ → subst (_$ _) h (_≃_.to (V.Lens.get⁻¹-≃ l₁′ _) p′) ≡ _≃_.to (V.Lens.get⁻¹-≃ l₂′ _) p) ( subst (_⁻¹ b) (sym g) p ≡⟨ elim₁ (λ g → subst (_⁻¹ b) (sym g) p ≡ Σ-map id erased (subst (_⁻¹ᴱ b) (sym g) (Σ-map id [_]→ p))) ( subst (_⁻¹ b) (sym (refl _)) p ≡⟨ trans (cong (flip (subst (_⁻¹ b)) _) sym-refl) $ subst-refl _ _ ⟩ p ≡⟨ cong (Σ-map id erased) $ sym $ trans (cong (flip (subst (_⁻¹ᴱ b)) _) sym-refl) $ subst-refl _ _ ⟩∎ Σ-map id erased (subst (_⁻¹ᴱ b) (sym (refl _)) (Σ-map id [_]→ p)) ∎) _ ⟩ Σ-map id erased (subst (_⁻¹ᴱ b) (sym g) (Σ-map id [_]→ p)) ≡⟨⟩ _≃_.from ECP.⁻¹≃⁻¹ᴱ (subst (_⁻¹ᴱ b) (sym g) (_≃_.to ECP.⁻¹≃⁻¹ᴱ p)) ∎)) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (h : H l₁ ≡ H l₂) → ∀ b p → subst (_$ ∣ b ∣) h (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym g) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) □ where open Lens l₁′ = _≃_.to Lens≃Variant-lens l₁ l₂′ = _≃_.to Lens≃Variant-lens l₂ -- Another equality characterisation lemma. @0 equality-characterisation₂ : {l₁ l₂ : Lens A B} → Block "equality-characterisation" → let open Lens in (l₁ ≡ l₂) ≃ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) → ∀ b p → subst id (h ∣ b ∣) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} ⊠ = l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⊠ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (h : H l₁ ≡ H l₂) → ∀ b p → subst (_$ ∣ b ∣) h (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym g) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) ↝⟨ (Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ → Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ → F.id) ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) → ∀ b p → subst (_$ ∣ b ∣) (⟨ext⟩ h) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_≡ _) $ subst-ext _ _) ⟩□ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) → ∀ b p → subst id (h ∣ b ∣) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) □ where open Lens -- Yet another equality characterisation lemma. @0 equality-characterisation₃ : {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → Block "equality-characterisation" → Univalence (a ⊔ b) → let open Lens in (l₁ ≡ l₂) ≃ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) → ∀ b p → _≃_.to (h ∣ b ∣) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} ⊠ univ = l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⊠ ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) → ∀ b p → subst id (h ∣ b ∣) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) ↝⟨ (∃-cong λ _ → Σ-cong-contra (∀-cong ext λ _ → inverse $ ≡≃≃ univ) λ _ → F.id) ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) → ∀ b p → subst id (≃⇒≡ univ (h ∣ b ∣)) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_≡ _) $ trans (subst-id-in-terms-of-≡⇒↝ equivalence) $ cong (λ eq → _≃_.to eq _) $ _≃_.right-inverse-of (≡≃≃ univ) _) ⟩□ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) → ∀ b p → _≃_.to (h ∣ b ∣) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₁ b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ g)) p)) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ l₂ b) p) □ where open Lens ------------------------------------------------------------------------ -- Conversion functions -- The lenses defined above can be converted to and from the lenses -- defined in Higher. Lens⇔Higher-lens : Block "conversion" → Lens A B ⇔ Higher.Lens A B Lens⇔Higher-lens {A = A} {B = B} ⊠ = record { to = λ (g , H , eq) → record { R = Σ ∥ B ∥ H ; equiv = A ↝⟨ (inverse $ drop-⊤-right λ _ → _⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ Contractibleᴱ-Erased-other-singleton) ⟩ (∃ λ (a : A) → ∃ λ (b : B) → Erased (g a ≡ b)) ↔⟨ ∃-comm ⟩ (∃ λ (b : B) → g ⁻¹ᴱ b) ↝⟨ ∃-cong eq ⟩ (∃ λ (b : B) → H ∣ b ∣) ↔⟨ (Σ-cong (inverse T.∥∥×≃) λ _ → ≡⇒≃ $ cong H $ T.truncation-is-proposition _ _) ⟩ (∃ λ ((b , _) : ∥ B ∥ × B) → H b) ↔⟨ Σ-assoc F.∘ (∃-cong λ _ → ×-comm) F.∘ inverse Σ-assoc ⟩□ Σ ∥ B ∥ H × B □ ; inhabited = proj₁ } ; from = λ l → Higher.Lens.get l , (λ _ → Higher.Lens.R l) , (λ b → inverse (Higher.remainder≃ᴱget⁻¹ᴱ l b)) } -- The conversion preserves getters and setters. Lens⇔Higher-lens-preserves-getters-and-setters : (bl : Block "conversion") → Preserves-getters-and-setters-⇔ A B (Lens⇔Higher-lens bl) Lens⇔Higher-lens-preserves-getters-and-setters bl@⊠ = (λ l@(g , H , eq) → refl _ , ⟨ext⟩ λ a → ⟨ext⟩ λ b → let h₁ = _≃ᴱ_.to (eq (g a)) (a , [ refl _ ]) h₂ = _≃_.from (≡⇒≃ (cong H _)) (subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ _)) (≡⇒→ (cong H _) h₁)) h₃ = ≡⇒→ (cong H _) h₁ lemma = h₂ ≡⟨ sym $ subst-in-terms-of-inverse∘≡⇒↝ equivalence _ _ _ ⟩ subst H _ (subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ _)) (≡⇒→ (cong H _) h₁)) ≡⟨ cong (λ x → subst H (sym $ T.truncation-is-proposition _ _) (subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ (∣ g a ∣ , b))) x)) $ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩ subst H _ (subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ _)) (subst H _ h₁)) ≡⟨ cong (λ x → subst H (sym $ T.truncation-is-proposition _ _) x) $ subst-∘ _ _ _ ⟩ subst H _ (subst H _ (subst H _ h₁)) ≡⟨ cong (λ x → subst H (sym $ T.truncation-is-proposition _ _) x) $ subst-subst _ _ _ _ ⟩ subst H _ (subst H _ h₁) ≡⟨ subst-subst _ _ _ _ ⟩ subst H _ h₁ ≡⟨ cong (λ eq → subst H eq h₁) $ mono₁ 1 T.truncation-is-proposition _ _ ⟩ subst H _ h₁ ≡⟨ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩∎ ≡⇒→ (cong H _) h₁ ∎ in proj₁ (_≃ᴱ_.from (eq b) h₂) ≡⟨ cong (λ h → proj₁ (_≃ᴱ_.from (eq b) h)) lemma ⟩∎ proj₁ (_≃ᴱ_.from (eq b) h₃) ∎) , (λ l → refl _ , ⟨ext⟩ λ a → ⟨ext⟩ λ b → Lens.set (_⇔_.from (Lens⇔Higher-lens bl) l) a b ≡⟨⟩ _≃ᴱ_.from (Higher.Lens.equiv l) ( ≡⇒→ (cong (λ _ → Higher.Lens.R l) _) (Higher.Lens.remainder l a) , b ) ≡⟨ cong (λ eq → _≃ᴱ_.from (Higher.Lens.equiv l) (≡⇒→ eq _ , b)) $ cong-const _ ⟩ _≃ᴱ_.from (Higher.Lens.equiv l) (≡⇒→ (refl _) (Higher.Lens.remainder l a) , b) ≡⟨ cong (λ f → _≃ᴱ_.from (Higher.Lens.equiv l) (f _ , b)) $ ≡⇒→-refl ⟩ _≃ᴱ_.from (Higher.Lens.equiv l) (Higher.Lens.remainder l a , b) ≡⟨⟩ Higher.Lens.set l a b ∎) -- Lens A B is equivalent to Higher.Lens A B (with erased proofs, -- assuming univalence). Lens≃ᴱHigher-lens : {A : Type a} {B : Type b} → Block "conversion" → @0 Univalence (a ⊔ b) → Lens A B ≃ᴱ Higher.Lens A B Lens≃ᴱHigher-lens {A = A} {B = B} bl univ = EEq.↔→≃ᴱ (_⇔_.to (Lens⇔Higher-lens bl)) (_⇔_.from (Lens⇔Higher-lens bl)) (to∘from bl) (from∘to bl) where @0 to∘from : (bl : Block "conversion") → ∀ l → _⇔_.to (Lens⇔Higher-lens bl) (_⇔_.from (Lens⇔Higher-lens bl) l) ≡ l to∘from ⊠ l = _↔_.from (Higher.equality-characterisation₂ univ) ( (∥ B ∥ × R ↔⟨ (drop-⊤-left-× λ r → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible T.truncation-is-proposition (inhabited r)) ⟩□ R □) , (λ a → ≡⇒→ (cong (λ _ → R) (T.truncation-is-proposition _ _)) (remainder a) ≡⟨ cong (λ eq → ≡⇒→ eq _) $ cong-const _ ⟩ ≡⇒→ (refl _) (remainder a) ≡⟨ cong (_$ _) ≡⇒→-refl ⟩∎ remainder a ∎) , (λ _ → refl _) ) where open Higher.Lens l @0 from∘to : (bl : Block "conversion") → ∀ l → _⇔_.from (Lens⇔Higher-lens bl) (_⇔_.to (Lens⇔Higher-lens bl) l) ≡ l from∘to bl@⊠ l = _≃_.from (equality-characterisation₃ ⊠ univ) ( (λ _ → refl _) , Σ∥B∥H≃H , (λ b p@(a , [ get-a≡b ]) → _≃_.to (Σ∥B∥H≃H ∣ b ∣) (_≃ᴱ_.from (Higher.remainder≃ᴱget⁻¹ᴱ (_⇔_.to (Lens⇔Higher-lens bl) l) b) (subst (_⁻¹ᴱ b) (sym (⟨ext⟩ λ _ → refl _)) p)) ≡⟨ cong (_≃_.to (Σ∥B∥H≃H ∣ b ∣) ∘ _≃ᴱ_.from (Higher.remainder≃ᴱget⁻¹ᴱ (_⇔_.to (Lens⇔Higher-lens bl) l) b)) $ trans (cong (flip (subst (_⁻¹ᴱ b)) p) $ trans (cong sym ext-refl) $ sym-refl) $ subst-refl _ _ ⟩ _≃_.to (Σ∥B∥H≃H ∣ b ∣) (_≃ᴱ_.from (Higher.remainder≃ᴱget⁻¹ᴱ (_⇔_.to (Lens⇔Higher-lens bl) l) b) p) ≡⟨⟩ _≃_.to (Σ∥B∥H≃H ∣ b ∣) (Higher.Lens.remainder (_⇔_.to (Lens⇔Higher-lens bl) l) a) ≡⟨⟩ subst H _ (≡⇒→ (cong H _) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ]))) ≡⟨ cong (subst H _) $ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩ subst H _ (subst H _ (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ]))) ≡⟨ subst-subst _ _ _ _ ⟩ subst H _ (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ])) ≡⟨ cong (λ eq → subst H eq (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ]))) $ mono₁ 1 T.truncation-is-proposition _ _ ⟩ subst H (cong ∣_∣ get-a≡b) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ])) ≡⟨ elim¹ (λ {b} eq → subst H (cong ∣_∣ eq) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ])) ≡ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b) (a , [ eq ])) ( subst H (cong ∣_∣ (refl _)) (_≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ])) ≡⟨ trans (cong (flip (subst H) _) $ cong-refl _) $ subst-refl _ _ ⟩ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ (get a)) (a , [ refl _ ]) ∎) _ ⟩∎ _≃ᴱ_.to (get⁻¹ᴱ-≃ᴱ b) p ∎) ) where open Lens l Σ∥B∥H≃H = λ b → Σ ∥ B ∥ H ↔⟨ (drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible T.truncation-is-proposition b) ⟩□ H b □ -- The equivalence preserves getters and setters. Lens≃ᴱHigher-lens-preserves-getters-and-setters : {A : Type a} {B : Type b} (bl : Block "conversion") (@0 univ : Univalence (a ⊔ b)) → Preserves-getters-and-setters-⇔ A B (_≃ᴱ_.logical-equivalence (Lens≃ᴱHigher-lens bl univ)) Lens≃ᴱHigher-lens-preserves-getters-and-setters bl univ = Lens⇔Higher-lens-preserves-getters-and-setters bl
{ "alphanum_fraction": 0.3737036596, "avg_line_length": 45.5099457505, "ext": "agda", "hexsha": "d63953b699d8cc76850109506560e95ea2365d18", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z", "max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z", "max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/dependent-lenses", "max_forks_repo_path": "src/Lens/Non-dependent/Higher/Capriotti/Variant/Erased.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/dependent-lenses", "max_issues_repo_path": "src/Lens/Non-dependent/Higher/Capriotti/Variant/Erased.agda", "max_line_length": 150, "max_stars_count": 3, "max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/dependent-lenses", "max_stars_repo_path": "src/Lens/Non-dependent/Higher/Capriotti/Variant/Erased.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z", "num_tokens": 9229, "size": 25167 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Relation.Binary.Fiberwise where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Data.Sigma open import Cubical.Relation.Binary.Base private variable ℓA ℓA' ℓ≅A ℓ≅A' ℓB ℓ≅B ℓ≅B' ℓB' : Level -- given a type A, this is the type of relational families on A RelFamily : (A : Type ℓA) (ℓB ℓ≅B : Level) → Type (ℓ-max (ℓ-max ℓA (ℓ-suc ℓB)) (ℓ-suc ℓ≅B)) RelFamily A ℓB ℓ≅B = Σ[ B ∈ (A → Type ℓB) ] ({a : A} → Rel (B a) (B a) ℓ≅B) -- property for a relational family to be fiberwise reflexive isFiberwiseReflexive : {A : Type ℓA} {ℓB ℓ≅B : Level} (B : RelFamily A ℓB ℓ≅B) → Type (ℓ-max (ℓ-max ℓA ℓB) ℓ≅B) isFiberwiseReflexive {A = A} (B , _≅_) = {a : A} → isRefl (_≅_ {a = a}) -- property for a relational fiberwise reflexive family to be fiberwise univalent: isFiberwiseUnivalent : {A : Type ℓA} {ℓB ℓ≅B : Level} (B : RelFamily A ℓB ℓ≅B) (ρ : isFiberwiseReflexive B) → Type (ℓ-max (ℓ-max ℓA ℓB) ℓ≅B) isFiberwiseUnivalent {A = A} (B , _≅_) ρ = {a : A} → isUnivalent (_≅_ {a = a}) (ρ {a = a}) -- pulling back a relational family along a map ♭RelFamily : {A : Type ℓA} {A' : Type ℓA'} {ℓB ℓ≅B : Level} (B : RelFamily A' ℓB ℓ≅B) (f : A → A') → RelFamily A ℓB ℓ≅B ♭RelFamily (B , _) f .fst a = B (f a) ♭RelFamily (_ , _≅_) f .snd = _≅_ -- the type of relational isomorphisms over f ♭RelFiberIsoOver : {A : Type ℓA} {A' : Type ℓA'} (f : A → A') (B : RelFamily A ℓB ℓ≅B) (B' : RelFamily A' ℓB' ℓ≅B') → Type (ℓ-max ℓA (ℓ-max (ℓ-max ℓB ℓB') (ℓ-max ℓ≅B ℓ≅B'))) ♭RelFiberIsoOver {A = A} f B B' = (a : A) → RelIso (B .snd {a = a}) (♭B' .snd {a = a}) where ♭B' = ♭RelFamily B' f module _ {A : Type ℓA} {A' : Type ℓA'} (F : Iso A A') (ℬ : RelFamily A ℓB ℓ≅B) {ρ : isFiberwiseReflexive ℬ} (uni : isFiberwiseUnivalent ℬ ρ) (ℬ' : RelFamily A' ℓB' ℓ≅B') {ρ' : isFiberwiseReflexive ℬ'} (uni' : isFiberwiseUnivalent ℬ' ρ') where private f = Iso.fun F B = ℬ .fst B' = ℬ' .fst ♭B' = ♭RelFamily ℬ' f .fst ♭ℬ' = ♭RelFamily ℬ' f private RelFiberIsoOver→♭FiberIso : (e≅♭ : (a : A) → RelIso (ℬ .snd {a = a}) (♭ℬ' .snd {a = a})) → (a : A) → Iso (B a) (B' (f a)) RelFiberIsoOver→♭FiberIso e≅♭ a = RelIso→Iso (ℬ .snd {a = a}) (ℬ' .snd {a = f a}) uni uni' (e≅♭ a) RelFiberIsoOver→Iso : (e≅♭ : (a : A) → RelIso (ℬ .snd {a = a}) (♭ℬ' .snd {a = a})) → Iso (Σ A B) (Σ A' B') RelFiberIsoOver→Iso e≅♭ = Σ-cong-iso F (RelFiberIsoOver→♭FiberIso e≅♭)
{ "alphanum_fraction": 0.5175827928, "avg_line_length": 39.0533333333, "ext": "agda", "hexsha": "6e23858f31e9fb4269d1f81c1ab5df48c9f6b736", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_path": "Cubical/Relation/Binary/Fiberwise.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_path": "Cubical/Relation/Binary/Fiberwise.agda", "max_line_length": 110, "max_stars_count": null, "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_path": "Cubical/Relation/Binary/Fiberwise.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1217, "size": 2929 }
------------------------------------------------------------------------------ -- Type theory: The identity type ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- We can prove the properties of equality used in the formalization -- of FOTC, from refl and J. module FOT.Common.FOL.Relation.Binary.PropositionalEquality.TypeTheory where infix 7 _≡_ postulate D : Set _≡_ : D → D → Set refl : ∀ {x} → x ≡ x module TypeTheory where -- Using the type-theoretic eliminator for equality. postulate J : (C : ∀ x y → x ≡ y → Set) → (∀ x → (C x x refl)) → ∀ x y → (c : x ≡ y) → C x y c -- From Thorsten's slides: A short history of equality. sym : ∀ {x y} → x ≡ y → y ≡ x sym {x} {y} = J (λ x' y' _ → y' ≡ x') (λ x' → refl) x y -- From Thorsten's slides: A short history of equality. trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z trans {x} {y} {z} = J (λ x' y' _ → y' ≡ z → x' ≡ z) (λ x' pr → pr) x y subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y subst A {x} {y} x≡y = J (λ x' y' _ → A x' → A y') (λ x' pr → pr) x y x≡y module FOL where -- Using the usual elimination schema for predicate logic. postulate J : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y sym : ∀ {x y} → x ≡ y → y ≡ x sym {x} {y} x≡y = J (λ y' → y' ≡ x) x≡y refl trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z trans {x} {y} {z} x≡y = J (λ y' → y' ≡ z → x ≡ z) x≡y (λ pr → pr) subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y subst = J module ML where -- Using Martin-Löf elimination ("Hauptsatz ...", 1971). postulate J : (C : D → D → Set) → (∀ x → (C x x)) → ∀ x y → x ≡ y → C x y sym : ∀ {x y} → x ≡ y → y ≡ x sym {x} {y} = J (λ x' y' → y' ≡ x') (λ x' → refl) x y trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z trans {x} {y} {z} = J (λ x' y' → y' ≡ z → x' ≡ z) (λ x' pr → pr) x y subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y subst A {x} {y} x≡y = J (λ x' y' → A x' → A y') (λ x' pr → pr) x y x≡y
{ "alphanum_fraction": 0.4259846084, "avg_line_length": 30.6805555556, "ext": "agda", "hexsha": "c510fd50ecd34a8c867377889594335c9ed23f95", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PropositionalEquality/TypeTheory.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PropositionalEquality/TypeTheory.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PropositionalEquality/TypeTheory.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 877, "size": 2209 }
module Crash where data Nat : Set where zero : Nat suc : Nat -> Nat data Bool : Set where true : Bool false : Bool F : Bool -> Set F true = Nat F false = Bool not : Bool -> Bool not true = false not false = true h : ((x : F ?) -> F (not x)) -> Nat h g = g zero
{ "alphanum_fraction": 0.5698924731, "avg_line_length": 12.1304347826, "ext": "agda", "hexsha": "990d7bc99b4b71e29c9f3bacbfbf952fe32d0108", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "notes/talks/MetaVars/Crash.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "notes/talks/MetaVars/Crash.agda", "max_line_length": 35, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "notes/talks/MetaVars/Crash.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 97, "size": 279 }