Search is not available for this dataset
text
string
meta
dict
module Sets.PredicateSet.Listable where import Lvl open import Data.List as List using (List) open import Data.List.Functions renaming (_++_ to _∪ₗ_) using (singleton) open import Data.List.Relation.Membership renaming (_∈_ to _∈ₗ_ ; _∈!_ to _∈!ₗ_) using (use ; skip) open import Data.List.Relation.Permutation open import Data.List.Relation.Quantification using (∀ₗᵢₛₜ ; module AllElements ; ExistsElement ; ExistsElementEquivalence ; module ExistsElementEquivalence) open import Functional open import Lang.Instance open import Logic.Propositional open import Relator.Equals open import Relator.Equals.Proofs.Equiv open import Sets.PredicateSet using (PredSet ; _∈_ ; ∅ ; _∪_ ; •_) open Sets.PredicateSet.BoundedQuantifiers open import Type.Properties.Singleton open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable T : Type{ℓ} private variable S S₁ S₂ : PredSet{ℓ}(T) private variable x : T module _ (S : PredSet{ℓ}(T)) where record Listable : Type{Lvl.of(T) Lvl.⊔ ℓ} where field list : List(T) unique : ∀ₛ(S) (_∈!ₗ list) restrict : ∀ₗᵢₛₜ(list) (_∈ S) proof : ∀ₛ(S) (_∈ₗ list) proof = IsUnit.unit ∘ unique list = inst-fn Listable.list private variable l l₁ l₂ l₁₂ : Listable(S) ∅-listable : Listable{ℓ = ℓ}{T = T}(∅) Listable.list ∅-listable = List.∅ Listable.unique ∅-listable () Listable.restrict ∅-listable = AllElements.∅ singleton-listable : Listable(•_ ⦃ [≡]-equiv ⦄ x) Listable.list singleton-listable = singleton _ Listable.unique singleton-listable [≡]-intro = intro (use [≡]-intro) (\{ {ExistsElement.• x} → ExistsElementEquivalence.use}) Listable.restrict singleton-listable = [≡]-intro AllElements.⊰ AllElements.∅ {- TODO: Will not satisfy Listable because (_++_) may yield multiples which Listable does not allow, and therefore list-[∪] below is also incorrect. ∪-listable : ⦃ Listable(S₁) ⦄ → ⦃ Listable(S₂) ⦄ → Listable(S₁ ∪ S₂) Listable.list (∪-listable {S₁ = S₁} {S₂ = S₂}) = list(S₁) ∪ₗ list(S₂) Listable.unique ∪-listable = {!!} Listable.restrict ∪-listable = {!!}-} -- list-[∪] : ∀{Γ₁ : PredSet{ℓ₁}(Formula(P))}{Γ₂ : PredSet{ℓ₂}(Formula(P))}{l₁₂ : Listable(Γ₁ PredSet.∪ Γ₂)} → Logic.∃{Obj = Listable(Γ₁) ⨯ Listable(Γ₂)}(\(l₁ , l₂) → (list(Γ₁ PredSet.∪ Γ₂) ⦃ l₁₂ ⦄ ≡ (list Γ₁ ⦃ l₁ ⦄) ∪ (list Γ₂ ⦃ l₂ ⦄))) postulate list-[∪] : (list(S₁ ∪ S₂) ⦃ l₁₂ ⦄ permutes (list S₁ ⦃ l₁ ⦄) ∪ₗ (list S₂ ⦃ l₂ ⦄)) postulate list-[∪·] : (list(S ∪ (•_ ⦃ [≡]-equiv ⦄ x)) ⦃ l₁₂ ⦄ permutes (list S ⦃ l ⦄) ∪ₗ singleton(x))
{ "alphanum_fraction": 0.6748417722, "avg_line_length": 45.1428571429, "ext": "agda", "hexsha": "2a51bff46fae8dfca53f77a9504d640d77b5526b", "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": "Sets/PredicateSet/Listable.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": "Sets/PredicateSet/Listable.agda", "max_line_length": 237, "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": "Sets/PredicateSet/Listable.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": 944, "size": 2528 }
module SAcc where data Size : Set where s : Size -> Size data Acc ( A : Set ) ( Lt : A -> A -> Set) : Size -> A -> Set where acc : (i : Size) -> ( b : A ) -> ( ( a : A ) -> Lt a b -> Acc A Lt i a ) -> ( Acc A Lt (s i) b ) data Nat : Set where zero : Nat succ : Nat -> Nat data Lt : Nat -> Nat -> Set where ltzero : ( x : Nat ) -> Lt zero (succ x) ltsucc : ( x : Nat ) -> (y : Nat) -> Lt x y -> Lt (succ x) (succ y) notLt0 : ( x : Nat ) -> Lt x zero -> (C : Set) -> C notLt0 x () accLt : (i : Size ) -> ( x : Nat ) -> Acc Nat Lt i x accLt (s i) zero = acc i zero (\a -> \p -> notLt0 a p (Acc Nat Lt i a) ) accLt (s i) (succ x) = acc i (succ x) (\a -> \p -> (accLt i a))
{ "alphanum_fraction": 0.4607843137, "avg_line_length": 24.6206896552, "ext": "agda", "hexsha": "ee0afab1bcc46ed6570bc2ad44b87ca34bf113ef", "lang": "Agda", "max_forks_count": 5, "max_forks_repo_forks_event_max_datetime": "2021-08-16T07:47:36.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-30T00:17:04.000Z", "max_forks_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/miniagda", "max_forks_repo_path": "examples/SAcc.agda", "max_issues_count": 7, "max_issues_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08", "max_issues_repo_issues_event_max_datetime": "2020-03-17T08:09:01.000Z", "max_issues_repo_issues_event_min_datetime": "2016-12-16T15:48:25.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/miniagda", "max_issues_repo_path": "examples/SAcc.agda", "max_line_length": 72, "max_stars_count": 85, "max_stars_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/miniagda", "max_stars_repo_path": "examples/SAcc.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-12T16:54:56.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-16T15:53:24.000Z", "num_tokens": 274, "size": 714 }
module _ where open import Agda.Primitive postulate Equiv : ∀ {a b} → (A : Set a) (B : Set b) → Set (a ⊔ b) {-# BUILTIN EQUIV Equiv #-}
{ "alphanum_fraction": 0.5886524823, "avg_line_length": 15.6666666667, "ext": "agda", "hexsha": "7bd8e327c321e79483a83f11bc6330cf2705347d", "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/Issue2788.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/Issue2788.agda", "max_line_length": 57, "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/Issue2788.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": 52, "size": 141 }
module Oscar.Relation where open import Oscar.Level _⟨_⟩→_ : ∀ {a} {A : Set a} {b} → A → (A → Set b) → A → Set b m ⟨ B ⟩→ n = B m → B n Transitive : ∀ {a} {A : Set a} {b} (B : A → A → Set b) → Set (a ⊔ b) Transitive B = ∀ {y z} → B y z → ∀ {x} → B x y → B x z module _ {𝔬} {⋆ : Set 𝔬} {𝔪} {_↦_ : ⋆ → ⋆ → Set 𝔪} (_∙_ : Transitive _↦_) {𝔮} (_≞_ : ∀ {x} {y} → x ↦ y → x ↦ y → Set 𝔮) where Extensional : Set (𝔬 ⊔ 𝔪 ⊔ 𝔮) Extensional = ∀ {x y} {f₁ f₂ : x ↦ y} → f₁ ≞ f₂ → ∀ {z} {g₁ g₂ : y ↦ z} → g₁ ≞ g₂ → (g₁ ∙ f₁) ≞ (g₂ ∙ f₂) Associative : Set (𝔬 ⊔ 𝔪 ⊔ 𝔮) Associative = ∀ {w x} (f : w ↦ x) {y} (g : x ↦ y) {z} (h : y ↦ z) → ((h ∙ g) ∙ f) ≞ (h ∙ (g ∙ f))
{ "alphanum_fraction": 0.393006993, "avg_line_length": 23.8333333333, "ext": "agda", "hexsha": "b73f69edb93e6a65486d8667629aa089fc3e2a95", "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-2/Oscar/Relation.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-2/Oscar/Relation.agda", "max_line_length": 125, "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-2/Oscar/Relation.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 392, "size": 715 }
{-# OPTIONS --cubical --safe #-} module Data.Bits.Equatable where open import Data.Bits open import Prelude _≡ᴮ_ : Bits → Bits → Bool [] ≡ᴮ [] = true (0∷ xs) ≡ᴮ (0∷ ys) = xs ≡ᴮ ys (1∷ xs) ≡ᴮ (1∷ ys) = xs ≡ᴮ ys _ ≡ᴮ _ = false open import Relation.Nullary.Discrete.FromBoolean sound-== : ∀ n m → T (n ≡ᴮ m) → n ≡ m sound-== [] [] p i = [] sound-== (0∷ n) (0∷ m) p i = 0∷ sound-== n m p i sound-== (1∷ n) (1∷ m) p i = 1∷ sound-== n m p i complete-== : ∀ n → T (n ≡ᴮ n) complete-== [] = tt complete-== (0∷ n) = complete-== n complete-== (1∷ n) = complete-== n _≟_ : Discrete Bits _≟_ = from-bool-eq _≡ᴮ_ sound-== complete-==
{ "alphanum_fraction": 0.5253456221, "avg_line_length": 23.25, "ext": "agda", "hexsha": "326171ff9fa95af61165a273b700ae40aa79af44", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Data/Bits/Equatable.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Data/Bits/Equatable.agda", "max_line_length": 49, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Data/Bits/Equatable.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": 308, "size": 651 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Bool open import lib.types.Empty open import lib.types.Lift open import lib.types.Pointed module lib.types.Coproduct where module _ {i j} {A : Type i} {B : Type j} where ⊔-code : Coprod A B → Coprod A B → Type (lmax i j) ⊔-code (inl a₁) (inl a₂) = Lift {j = (lmax i j)} $ a₁ == a₂ ⊔-code (inl a₁) (inr b₂) = Lift Empty ⊔-code (inr b₁) (inl a₂) = Lift Empty ⊔-code (inr b₁) (inr b₂) = Lift {j = (lmax i j)} $ b₁ == b₂ ⊔-encode : {x y : Coprod A B} → (x == y) → ⊔-code x y ⊔-encode {inl a₁} {y} p = transport (⊔-code $ inl a₁) p (lift $ idp {a = a₁}) ⊔-encode {inr b₁} {y} p = transport (⊔-code $ inr b₁) p (lift $ idp {a = b₁}) ⊔-decode : {x y : Coprod A B} → ⊔-code x y → (x == y) ⊔-decode {inl _} {inl _} c = ap inl $ lower c ⊔-decode {inl _} {inr _} c = Empty-rec $ lower c ⊔-decode {inr _} {inl _} c = Empty-rec $ lower c ⊔-decode {inr _} {inr _} c = ap inr (lower c) ⊔-code-equiv : (x y : Coprod A B) → (x == y) ≃ ⊔-code x y ⊔-code-equiv x y = equiv ⊔-encode ⊔-decode (f-g x y) (g-f x y) where f-g : ∀ x' y' → ∀ c → ⊔-encode (⊔-decode {x'} {y'} c) == c f-g (inl a₁) (inl .a₁) (lift idp) = idp f-g (inl a₁) (inr b₂) b = Empty-rec $ lower b f-g (inr b₁) (inl a₂) b = Empty-rec $ lower b f-g (inr b₁) (inr .b₁) (lift idp) = idp g-f : ∀ x' y' → ∀ p → ⊔-decode (⊔-encode {x'} {y'} p) == p g-f (inl _) .(inl _) idp = idp g-f (inr _) .(inr _) idp = idp inl=inl-equiv : (a₁ a₂ : A) → (inl a₁ == inl a₂) ≃ (a₁ == a₂) inl=inl-equiv a₁ a₂ = lower-equiv ∘e ⊔-code-equiv (inl a₁) (inl a₂) inr=inr-equiv : (b₁ b₂ : B) → (inr b₁ == inr b₂) ≃ (b₁ == b₂) inr=inr-equiv b₁ b₂ = lower-equiv ∘e ⊔-code-equiv (inr b₁) (inr b₂) inl≠inr : (a₁ : A) (b₂ : B) → (inl a₁ ≠ inr b₂) inl≠inr a₁ b₂ p = lower $ ⊔-encode p inr≠inl : (b₁ : B) (a₂ : A) → (inr b₁ ≠ inl a₂) inr≠inl a₁ b₂ p = lower $ ⊔-encode p ⊔-level : ∀ {n} → has-level (S (S n)) A → has-level (S (S n)) B → has-level (S (S n)) (Coprod A B) ⊔-level pA _ (inl a₁) (inl a₂) = equiv-preserves-level ((inl=inl-equiv a₁ a₂)⁻¹) (pA a₁ a₂) ⊔-level _ _ (inl a₁) (inr b₂) = λ p → Empty-rec (inl≠inr a₁ b₂ p) ⊔-level _ _ (inr b₁) (inl a₂) = λ p → Empty-rec (inr≠inl b₁ a₂ p) ⊔-level _ pB (inr b₁) (inr b₂) = equiv-preserves-level ((inr=inr-equiv b₁ b₂)⁻¹) (pB b₁ b₂) infix 80 _⊙⊔_ _⊙⊔_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) X ⊙⊔ Y = ⊙[ Coprod (fst X) (fst Y) , inl (snd X) ] _⊔⊙_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) X ⊔⊙ Y = ⊙[ Coprod (fst X) (fst Y) , inr (snd Y) ] codiag : ∀ {i} {A : Type i} → A ⊔ A → A codiag (inl a) = a codiag (inr a) = a ⊙codiag : ∀ {i} {X : Ptd i} → fst (X ⊙⊔ X ⊙→ X) ⊙codiag = (codiag , idp) -- A binary sigma is a coproduct ΣBool-equiv-⊔ : ∀ {i} (Pick : Bool → Type i) → Σ _ Pick ≃ (Pick true ⊔ Pick false) ΣBool-equiv-⊔ Pick = equiv into out into-out out-into where into : Σ _ Pick → Pick true ⊔ Pick false into (true , a) = inl a into (false , b) = inr b out : (Pick true ⊔ Pick false) → Σ _ Pick out (inl a) = (true , a) out (inr b) = (false , b) into-out : ∀ c → into (out c) == c into-out (inl a) = idp into-out (inr b) = idp out-into : ∀ s → out (into s) == s out-into (true , a) = idp out-into (false , b) = idp
{ "alphanum_fraction": 0.5244192972, "avg_line_length": 34.9791666667, "ext": "agda", "hexsha": "e5d30196c58e8f9fde48a576c29b67399bb6f852", "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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "core/lib/types/Coproduct.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "cmknapp/HoTT-Agda", "max_issues_repo_path": "core/lib/types/Coproduct.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "core/lib/types/Coproduct.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1617, "size": 3358 }
{-# OPTIONS --without-K --rewriting #-} module Agda.Builtin.Equality.Rewrite where open import Agda.Builtin.Equality {-# BUILTIN REWRITE _≡_ #-}
{ "alphanum_fraction": 0.7162162162, "avg_line_length": 18.5, "ext": "agda", "hexsha": "4689c3a6305002e540ec47edd008f4cea8c72edb", "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": "f77b563d328513138d6c88bf0a3e350a9b91f8ed", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "bennn/agda", "max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Equality/Rewrite.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed", "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": "bennn/agda", "max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Equality/Rewrite.agda", "max_line_length": 42, "max_stars_count": null, "max_stars_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "bennn/agda", "max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Equality/Rewrite.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 40, "size": 148 }
------------------------------------------------------------------------ -- The Agda standard library -- -- The lifting of a non-strict order to incorporate a new supremum ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This module is designed to be used with -- Relation.Nullary.Construct.Add.Supremum open import Relation.Binary module Relation.Binary.Construct.Add.Supremum.NonStrict {a ℓ} {A : Set a} (_≤_ : Rel A ℓ) where open import Level using (_⊔_) open import Data.Sum as Sum open import Relation.Nullary import Relation.Nullary.Decidable as Dec import Relation.Binary.PropositionalEquality as P open import Relation.Nullary.Construct.Add.Supremum import Relation.Binary.Construct.Add.Supremum.Equality as Equality ------------------------------------------------------------------------ -- Definition data _≤⁺_ : Rel (A ⁺) (a ⊔ ℓ) where [_] : {k l : A} → k ≤ l → [ k ] ≤⁺ [ l ] _≤⊤⁺ : (k : A ⁺) → k ≤⁺ ⊤⁺ ------------------------------------------------------------------------ -- Properties [≤]-injective : ∀ {k l} → [ k ] ≤⁺ [ l ] → k ≤ l [≤]-injective [ p ] = p module _ {e} {_≈_ : Rel A e} where open Equality _≈_ ≤⁺-reflexive : (_≈_ ⇒ _≤_) → (_≈⁺_ ⇒ _≤⁺_) ≤⁺-reflexive ≤-reflexive [ p ] = [ ≤-reflexive p ] ≤⁺-reflexive ≤-reflexive ⊤⁺≈⊤⁺ = ⊤⁺ ≤⊤⁺ ≤⁺-antisym : Antisymmetric _≈_ _≤_ → Antisymmetric _≈⁺_ _≤⁺_ ≤⁺-antisym ≤-antisym [ p ] [ q ] = [ ≤-antisym p q ] ≤⁺-antisym ≤-antisym (⊤⁺ ≤⊤⁺) (⊤⁺ ≤⊤⁺) = ⊤⁺≈⊤⁺ ≤⁺-trans : Transitive _≤_ → Transitive _≤⁺_ ≤⁺-trans ≤-trans [ p ] [ q ] = [ ≤-trans p q ] ≤⁺-trans ≤-trans p (l ≤⊤⁺) = _ ≤⊤⁺ ≤⁺-maximum : Maximum _≤⁺_ ⊤⁺ ≤⁺-maximum = _≤⊤⁺ ≤⁺-dec : Decidable _≤_ → Decidable _≤⁺_ ≤⁺-dec _≤?_ k ⊤⁺ = yes (k ≤⊤⁺) ≤⁺-dec _≤?_ ⊤⁺ [ l ] = no (λ ()) ≤⁺-dec _≤?_ [ k ] [ l ] = Dec.map′ [_] [≤]-injective (k ≤? l) ≤⁺-total : Total _≤_ → Total _≤⁺_ ≤⁺-total ≤-total k ⊤⁺ = inj₁ (k ≤⊤⁺) ≤⁺-total ≤-total ⊤⁺ l = inj₂ (l ≤⊤⁺) ≤⁺-total ≤-total [ k ] [ l ] = Sum.map [_] [_] (≤-total k l) ≤⁺-irrelevant : Irrelevant _≤_ → Irrelevant _≤⁺_ ≤⁺-irrelevant ≤-irr [ p ] [ q ] = P.cong _ (≤-irr p q) ≤⁺-irrelevant ≤-irr (k ≤⊤⁺) (k ≤⊤⁺) = P.refl ------------------------------------------------------------------------ -- Structures module _ {e} {_≈_ : Rel A e} where open Equality _≈_ ≤⁺-isPreorder : IsPreorder _≈_ _≤_ → IsPreorder _≈⁺_ _≤⁺_ ≤⁺-isPreorder ≤-isPreorder = record { isEquivalence = ≈⁺-isEquivalence isEquivalence ; reflexive = ≤⁺-reflexive reflexive ; trans = ≤⁺-trans trans } where open IsPreorder ≤-isPreorder ≤⁺-isPartialOrder : IsPartialOrder _≈_ _≤_ → IsPartialOrder _≈⁺_ _≤⁺_ ≤⁺-isPartialOrder ≤-isPartialOrder = record { isPreorder = ≤⁺-isPreorder isPreorder ; antisym = ≤⁺-antisym antisym } where open IsPartialOrder ≤-isPartialOrder ≤⁺-isDecPartialOrder : IsDecPartialOrder _≈_ _≤_ → IsDecPartialOrder _≈⁺_ _≤⁺_ ≤⁺-isDecPartialOrder ≤-isDecPartialOrder = record { isPartialOrder = ≤⁺-isPartialOrder isPartialOrder ; _≟_ = ≈⁺-dec _≟_ ; _≤?_ = ≤⁺-dec _≤?_ } where open IsDecPartialOrder ≤-isDecPartialOrder ≤⁺-isTotalOrder : IsTotalOrder _≈_ _≤_ → IsTotalOrder _≈⁺_ _≤⁺_ ≤⁺-isTotalOrder ≤-isTotalOrder = record { isPartialOrder = ≤⁺-isPartialOrder isPartialOrder ; total = ≤⁺-total total } where open IsTotalOrder ≤-isTotalOrder ≤⁺-isDecTotalOrder : IsDecTotalOrder _≈_ _≤_ → IsDecTotalOrder _≈⁺_ _≤⁺_ ≤⁺-isDecTotalOrder ≤-isDecTotalOrder = record { isTotalOrder = ≤⁺-isTotalOrder isTotalOrder ; _≟_ = ≈⁺-dec _≟_ ; _≤?_ = ≤⁺-dec _≤?_ } where open IsDecTotalOrder ≤-isDecTotalOrder
{ "alphanum_fraction": 0.5318072931, "avg_line_length": 34.1545454545, "ext": "agda", "hexsha": "f74133fb54744965ce677c33a374ab6722ec9e24", "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/Relation/Binary/Construct/Add/Supremum/NonStrict.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Supremum/NonStrict.agda", "max_line_length": 80, "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/Relation/Binary/Construct/Add/Supremum/NonStrict.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1518, "size": 3757 }
-- (Γ ⇒ Δ ∪ · A) → (Γ ⇒ Δ ∪ · (A ∨ B)) -- The conclusion (A ∨ B) is the principal/major formula of the rule. -- The premiss A is the active/minor formula of the rule -- Γ, Δ is the side formulas of the rule. -- Γ ⇒ Δ -- LHS Γ is the antecedent of the sequent. -- RHS Γ is the consequent of the sequent.
{ "alphanum_fraction": 0.6295081967, "avg_line_length": 30.5, "ext": "agda", "hexsha": "9e907041c8b81d70ecc46e6c4588a83a2b259d07", "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": "Formalization/PredicateLogic/Minimal/SequentCalculus.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": "Formalization/PredicateLogic/Minimal/SequentCalculus.agda", "max_line_length": 69, "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": "Formalization/PredicateLogic/Minimal/SequentCalculus.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": 104, "size": 305 }
{-# OPTIONS --sized-types --show-implicit #-} module SizedNatAnnotated where open import Size data Nat : {i : Size} -> Set where zero : {i : Size} -> Nat {↑ i} suc : {i : Size} -> Nat {i} -> Nat {↑ i} -- subtraction is non size increasing sub : {i : Size} -> Nat {i} -> Nat {∞} -> Nat {i} sub .{↑ i} (zero {i}) n = zero {i} sub .{↑ i} (suc {i} m) zero = suc {i} m sub .{↑ i} (suc {i} m) (suc n) = sub {i} m n -- div' m n computes ceiling(m/(n+1)) div' : {i : Size} -> Nat {i} -> Nat -> Nat {i} div' .{↑ i} (zero {i}) n = zero {i} div' .{↑ i} (suc {i} m) n = suc {i} (div' {i} (sub {i} m n) n)
{ "alphanum_fraction": 0.4894991922, "avg_line_length": 28.1363636364, "ext": "agda", "hexsha": "76bde41a1bb83d9ad183c620adf14db6a88e9d36", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "examples/Termination/Sized/SizedNatAnnotated.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/Termination/Sized/SizedNatAnnotated.agda", "max_line_length": 63, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/Termination/Sized/SizedNatAnnotated.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": 260, "size": 619 }
{-# OPTIONS --no-positivity-check #-} module univ where open import Base open import Nat import Logic.ChainReasoning module Chain {A : Set}( _==_ : A -> A -> Set) (refl : {x : A} -> x == x) (trans : {x y z : A} -> x == y -> y == z -> x == z) = Logic.ChainReasoning.Mono.Homogenous _==_ (\x -> refl) (\x y z -> trans) -- mutual inductive recursive definition of S and the functions _=S_, El, eq, -- and all the proofs on these functions mutual infix 40 _==_ _=S_ _=Fam_ infixr 80 _<<_ infixl 80 _>>_ infixl 150 _!_ data S : Set where nat : S pi : (A : S)(F : Fam A) -> S sigma : (A : S)(F : Fam A) -> S data Fam (A : S) : Set where fam : (F : El A -> S) -> Map _==_ _=S_ F -> Fam A _=S'_ : rel S nat =S' pi _ _ = False nat =S' sigma _ _ = False pi _ _ =S' nat = False pi _ _ =S' sigma _ _ = False sigma _ _ =S' nat = False sigma _ _ =S' pi _ _ = False nat =S' nat = True pi A F =S' pi B G = (B =S A) * \ B=A -> F =Fam G >> B=A sigma A F =S' sigma B G = (A =S B) * \A=B -> F >> A=B =Fam G data _=S_ (A B : S) : Set where eqS : A =S' B -> A =S B El' : S -> Set El' nat = Nat El' (pi A F) = ((x : El A) -> El (F ! x)) * \f -> {x y : El A}(x=y : x == y) -> f x == pFam F x=y << f y El' (sigma A F) = El A * \x -> El (F ! x) data El (A : S) : Set where el : El' A -> El A _=='_ : {A : S} -> rel (El A) _=='_ {nat} (el x) (el y) = x =N y _=='_ {pi A F} (el < f , pf >) (el < g , pg >) = (x : El A) -> f x == g x _=='_ {sigma A F} (el < x , Fx >) (el < y , Fy >) = x == y * \x=y -> Fx == pFam F x=y << Fy data _==_ {A : S}(x y : El A) : Set where eq : x ==' y -> x == y _=Fam_ : {A : S} -> rel (Fam A) F =Fam G = (x : El _) -> F ! x =S G ! x _!_ : {A : S} -> Fam A -> El A -> S fam F _ ! x = F x pFam : {A : S}(F : Fam A) -> Map _==_ _=S_ (_!_ F) pFam (fam F pF) = pF -- Families are contravariant so they cast in the other direction. _>>_ : {A B : S} -> Fam A -> A =S B -> Fam B _>>_ {A}{B} F A=B = fam G pG where G : El B -> S G x = F ! (A=B << x) pG : Map _==_ _=S_ G pG x=y = pFam F (p<< A=B x=y) pfiFam : {A B : S}(p q : A =S B)(F : Fam A) -> F >> p =Fam F >> q pfiFam p q F x = pFam F (pfi p q x) _<<_ : {A B : S} -> A =S B -> El B -> El A _<<_ {nat }{pi _ _ } (eqS ()) _ _<<_ {nat }{sigma _ _ } (eqS ()) _ _<<_ {pi _ _ }{nat } (eqS ()) _ _<<_ {pi _ _ }{sigma _ _ } (eqS ()) _ _<<_ {sigma _ _ }{nat } (eqS ()) _ _<<_ {sigma _ _ }{pi _ _ } (eqS ()) _ _<<_ {nat }{nat } p x = x _<<_ {pi A F }{pi B G } (eqS < B=A , F=G >) (el < g , pg >) = el < f , (\{x}{y} -> pf x y) > where f : (x : El A) -> El (F ! x) f x = F=G x << g (B=A << x) pf : (x y : El A)(x=y : x == y) -> f x == pFam F x=y << f y pf x y x=y = chain> F=G x << g (B=A << x) === F=G x << _ << g (B=A << y) by p<< _ (pg (p<< B=A x=y)) === pFam F x=y << F=G y << g (B=A << y) by pfi2 _ _ _ _ _ where open module C = Chain _==_ (ref {_}) (trans {_}) _<<_ {sigma A F}{sigma B G} (eqS < A=B , F=G >) (el < y , Gy >) = el < A=B << y , F=G y << Gy > p<< : {A B : S}(A=B : A =S B) -> Map _==_ _==_ (_<<_ A=B) p<< {nat}{nat} _ x=y = x=y p<< {pi A F} {pi B G} (eqS < B=A , F=G >) {el < f , pf >} {el < g , pg >} (eq f=g) = eq cf=cg where cf=cg : (x : El A) -> F=G x << f (B=A << x) == F=G x << g (B=A << x) cf=cg x = p<< (F=G x) (f=g (B=A << x)) p<< {sigma A F}{sigma B G}(eqS < A=B , F=G >) {el < x , Gx >}{el < y , Gy >} (eq < x=y , Gx=Gy >) = eq < cx=cy , cGx=cGy > where cx=cy : A=B << x == A=B << y cx=cy = p<< A=B x=y cGx=cGy : F=G x << Gx == pFam F cx=cy << F=G y << Gy cGx=cGy = chain> F=G x << Gx === F=G x << pFam G x=y << Gy by p<< (F=G x) Gx=Gy === pFam F cx=cy << F=G y << Gy by pfi2 _ _ _ _ Gy where open module C = Chain _==_ (ref {_}) (trans {_}) p<< {nat }{pi _ _ } (eqS ()) _ p<< {nat }{sigma _ _} (eqS ()) _ p<< {pi _ _ }{nat } (eqS ()) _ p<< {pi _ _ }{sigma _ _} (eqS ()) _ p<< {sigma _ _}{nat } (eqS ()) _ p<< {sigma _ _}{pi _ _ } (eqS ()) _ refS : Refl _=S_ refS {nat} = eqS T refS {pi A F} = eqS < refS , (\x -> symS (pFam F (ref<< x))) > refS {sigma A F} = eqS < refS , (\x -> pFam F (ref<< x)) > transS : Trans _=S_ transS {nat }{nat }{pi _ _ } _ (eqS ()) transS {nat }{nat }{sigma _ _ } _ (eqS ()) transS {nat }{pi _ _ } (eqS ()) _ transS {nat }{sigma _ _ } (eqS ()) _ transS {pi _ _ }{nat } (eqS ()) _ transS {pi _ _ }{pi _ _ }{nat } _ (eqS ()) transS {pi _ _ }{pi _ _ }{sigma _ _ } _ (eqS ()) transS {pi _ _ }{sigma _ _ } (eqS ()) _ transS {sigma _ _ }{nat } (eqS ()) _ transS {sigma _ _ }{pi _ _ } (eqS ()) _ transS {sigma _ _ }{sigma _ _ }{nat } _ (eqS ()) transS {sigma _ _ }{sigma _ _ }{pi _ _ } _ (eqS ()) transS {nat}{nat}{nat} p q = p transS {pi A F}{pi B G}{pi C H} (eqS < B=A , F=G >) (eqS < C=B , G=H >) = eqS < C=A , F=H > where open module C = Chain _=S_ refS transS C=A = transS C=B B=A F=H : F =Fam H >> C=A F=H x = chain> F ! x === G ! (B=A << x) by F=G x === H ! (C=B << B=A << x) by G=H (B=A << x) === H ! (C=A << x) by pFam H (sym (trans<< C=B B=A x)) transS {sigma A F}{sigma B G}{sigma C H} (eqS < A=B , F=G >)(eqS < B=C , G=H >) = eqS < A=C , F=H > where open module C = Chain _=S_ refS transS A=C = transS A=B B=C F=H : F >> A=C =Fam H F=H x = chain> F ! (A=C << x) === F ! (A=B << B=C << x) by pFam F (trans<< A=B B=C x) === G ! (B=C << x) by F=G (B=C << x) === H ! x by G=H x symS : Sym _=S_ symS {nat }{pi _ _ } (eqS ()) symS {nat }{sigma _ _ } (eqS ()) symS {pi _ _ }{nat } (eqS ()) symS {pi _ _ }{sigma _ _ } (eqS ()) symS {sigma _ _ }{nat } (eqS ()) symS {sigma _ _ }{pi _ _ } (eqS ()) symS {nat}{nat} p = p symS {pi A F}{pi B G} (eqS < B=A , F=G >) = eqS < A=B , G=F > where open module C = Chain _=S_ refS transS A=B = symS B=A G=F : G =Fam F >> A=B G=F x = symS ( chain> F ! (A=B << x) === G ! (B=A << A=B << x) by F=G (A=B << x) === G ! (refS << x) by pFam G (casttrans B=A A=B refS x) === G ! x by pFam G (ref<< x) ) symS {sigma A F}{sigma B G}(eqS < A=B , F=G >) = eqS < B=A , G=F > where open module C = Chain _=S_ refS transS B=A = symS A=B G=F : G >> B=A =Fam F G=F x = chain> G ! (B=A << x) === F ! (A=B << B=A << x) by symS (F=G _) === F ! (refS << x) by pFam F (casttrans _ _ _ x) === F ! x by pFam F (castref _ x) pfi : {A B : S}(p q : A =S B)(x : El B) -> p << x == q << x pfi {nat }{pi _ _ } (eqS ()) _ _ pfi {nat }{sigma _ _ } (eqS ()) _ _ pfi {pi _ _ }{nat } (eqS ()) _ _ pfi {pi _ _ }{sigma _ _ } (eqS ()) _ _ pfi {sigma _ _ }{nat } (eqS ()) _ _ pfi {sigma _ _ }{pi _ _ } (eqS ()) _ _ pfi {nat}{nat} _ _ x = ref pfi {pi A F}{pi B G} (eqS < B=A1 , F=G1 >) (eqS < B=A2 , F=G2 >) (el < g , pg >) = eq g1=g2 where g1=g2 : (x : El A) -> F=G1 x << g (B=A1 << x) == F=G2 x << g (B=A2 << x) g1=g2 x = chain> F=G1 x << g (B=A1 << x) === F=G1 x << _ << g (B=A2 << x) by p<< _ (pg (pfi B=A1 B=A2 x)) === F=G2 x << g (B=A2 << x) by casttrans _ _ _ _ where open module C = Chain _==_ (ref {_}) (trans {_}) pfi {sigma A F}{sigma B G} (eqS < A=B1 , F=G1 >) (eqS < A=B2 , F=G2 >) (el < y , Gy >) = eq < x1=x2 , Fx1=Fx2 > where x1=x2 : A=B1 << y == A=B2 << y x1=x2 = pfi A=B1 A=B2 y Fx1=Fx2 : F=G1 y << Gy == pFam F x1=x2 << F=G2 y << Gy Fx1=Fx2 = sym (casttrans _ _ _ _) ref<< : {A : S}(x : El A) -> refS << x == x ref<< {nat} x = ref ref<< {sigma A F} (el < x , Fx >) = eq < ref<< x , pfi _ _ Fx > ref<< {pi A F } (el < f , pf >) = eq rf=f where rf=f : (x : El A) -> _ << f (refS << x) == f x rf=f x = chain> _ << f (refS << x) === _ << pFam F (ref<< x) << f x by p<< _ (pf (ref<< x)) === _ << f x by sym (trans<< _ _ (f x)) === f x by castref _ _ where open module C = Chain _==_ (ref {_}) (trans {_}) trans<< : {A B C : S}(A=B : A =S B)(B=C : B =S C)(x : El C) -> transS A=B B=C << x == A=B << B=C << x trans<< {nat }{nat }{pi _ _ } _ (eqS ()) _ trans<< {nat }{nat }{sigma _ _ } _ (eqS ()) _ trans<< {nat }{pi _ _ } (eqS ()) _ _ trans<< {nat }{sigma _ _ } (eqS ()) _ _ trans<< {pi _ _ }{nat } (eqS ()) _ _ trans<< {pi _ _ }{pi _ _ }{nat } _ (eqS ()) _ trans<< {pi _ _ }{pi _ _ }{sigma _ _ } _ (eqS ()) _ trans<< {pi _ _ }{sigma _ _ } (eqS ()) _ _ trans<< {sigma _ _ }{nat } (eqS ()) _ _ trans<< {sigma _ _ }{pi _ _ } (eqS ()) _ _ trans<< {sigma _ _ }{sigma _ _ }{nat } _ (eqS ()) _ trans<< {sigma _ _ }{sigma _ _ }{pi _ _ } _ (eqS ()) _ trans<< {nat}{nat}{nat} _ _ _ = ref trans<< {pi A F}{pi B G}{pi C H} (eqS < B=A , F=G >)(eqS < C=B , G=H >) (el < h , ph >) = eq prf where C=A = transS C=B B=A prf : (x : El A) -> _ prf x = chain> _ << h (C=A << x) === _ << _ << h (C=B << B=A << x) by p<< _ (ph (trans<< _ _ x)) === F=G x << G=H _ << h (_ << _ << x) by pfi2 _ _ _ _ _ where open module C' = Chain _==_ (ref {_}) (trans {_}) trans<< {sigma A F}{sigma B G}{sigma C H} (eqS < A=B , F=G >)(eqS < B=C , G=H >) (el < z , Hz >) = eq < trans<< A=B B=C z , prf > where prf = chain> _ << Hz === _ << Hz by pfi _ _ _ === _ << _ << Hz by trans<< _ _ _ === _ << F=G _ << G=H z << Hz by trans<< _ _ _ where open module C' = Chain _==_ (ref {_}) (trans {_}) -- we never need this one, but it feels like it should be here... sym<< : {A B : S}(A=B : A =S B)(x : El B) -> symS A=B << A=B << x == x sym<< A=B x = chain> symS A=B << A=B << x === refS << x by casttrans _ _ _ x === x by ref<< x where open module C' = Chain _==_ (ref {_}) (trans {_}) castref : {A : S}(p : A =S A)(x : El A) -> p << x == x castref A=A x = chain> A=A << x === refS << x by pfi A=A refS x === x by ref<< x where open module C = Chain _==_ (ref {_}) (trans {_}) casttrans : {A B C : S}(A=B : A =S B)(B=C : B =S C)(A=C : A =S C)(x : El C) -> A=B << B=C << x == A=C << x casttrans A=B B=C A=C x = chain> A=B << B=C << x === _ << x by sym (trans<< _ _ _) === A=C << x by pfi _ _ _ where open module C' = Chain _==_ (ref {_}) (trans {_}) pfi2 : {A B1 B2 C : S} (A=B1 : A =S B1)(A=B2 : A =S B2)(B1=C : B1 =S C)(B2=C : B2 =S C) (x : El C) -> A=B1 << B1=C << x == A=B2 << B2=C << x pfi2 A=B1 A=B2 B1=C B2=C x = chain> A=B1 << B1=C << x === _ << x by casttrans _ _ _ x === A=B2 << B2=C << x by trans<< _ _ x where open module C = Chain _==_ (ref {_}) (trans {_}) ref : {A : S} -> Refl {El A} _==_ ref {nat} {el n} = eq (refN {n}) ref {pi A F} {el < f , pf >} = eq \x -> ref ref {sigma A F} {el < x , Fx >} = eq < ref , sym (castref _ _) > trans : {A : S} -> Trans {El A} _==_ trans {nat}{el x}{el y}{el z} (eq p) (eq q) = eq (transN {x}{y}{z} p q) trans {pi A F}{el < f , pf >}{el < g , pg >}{el < h , ph >} (eq f=g)(eq g=h) = eq \x -> trans (f=g x) (g=h x) trans {sigma A F}{el < x , Fx >}{el < y , Fy >}{el < z , Fz >} (eq < x=y , Fx=Fy >)(eq < y=z , Fy=Fz >) = eq < x=z , Fx=Fz > where x=z = trans x=y y=z Fx=Fz = chain> Fx === pFam F x=y << Fy by Fx=Fy === pFam F x=y << pFam F y=z << Fz by p<< _ Fy=Fz === pFam F x=z << Fz by casttrans _ _ _ _ where open module C = Chain _==_ (ref {_}) (trans {_}) sym : {A : S} -> Sym {El A} _==_ sym {nat}{el x}{el y} (eq p) = eq (symN {x}{y} p) sym {pi A F}{el < f , pf >}{el < g , pg >} (eq f=g) = eq \x -> sym (f=g x) sym {sigma A F}{el < x , Fx >}{el < y , Fy >} (eq < x=y , Fx=Fy >) = eq < y=x , Fy=Fx > where y=x = sym x=y Fy=Fx = sym ( chain> pFam F y=x << Fx === pFam F y=x << pFam F x=y << Fy by p<< (pFam F y=x) Fx=Fy === refS << Fy by casttrans _ _ _ _ === Fy by castref _ _ ) where open module C = Chain _==_ (ref {_}) (trans {_}) refFam : {A : S} -> Refl (_=Fam_ {A}) refFam x = refS transFam : {A : S} -> Trans (_=Fam_ {A}) transFam F=G G=H x = transS (F=G x) (G=H x) symFam : {A : S} -> Sym (_=Fam_ {A}) symFam F=G x = symS (F=G x) castref2 : {A B : S}(A=B : A =S B)(B=A : B =S A)(x : El A) -> A=B << B=A << x == x castref2 A=B B=A x = trans (casttrans A=B B=A refS x) (ref<< x)
{ "alphanum_fraction": 0.3877112575, "avg_line_length": 36.7473684211, "ext": "agda", "hexsha": "0837007dbe45e51ec37224fd7e2a8d630fdc89c1", "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": "examples/outdated-and-incorrect/univ/univ.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/univ/univ.agda", "max_line_length": 80, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/outdated-and-incorrect/univ/univ.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": 5687, "size": 13964 }
{-# OPTIONS --rewriting #-} module Examples where import Examples.Syntax import Examples.OpSem import Examples.Run import Examples.Type
{ "alphanum_fraction": 0.795620438, "avg_line_length": 17.125, "ext": "agda", "hexsha": "212067b74910ba670b440a4993266af759ae9a39", "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/Examples.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/Examples.agda", "max_line_length": 27, "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/Examples.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": 27, "size": 137 }
------------------------------------------------------------------------ -- Untyped hereditary substitution in Fω with interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --exact-split --without-K #-} module FOmegaInt.Syntax.HereditarySubstitution where open import Data.Fin using (Fin; zero; suc) open import Data.Fin.Substitution open import Data.Fin.Substitution.ExtraLemmas open import Data.Nat using (zero; suc) open import Data.List using ([]; _∷_; _++_) open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε) open import Relation.Binary.PropositionalEquality as P hiding ([_]) open import FOmegaInt.Reduction.Full open import FOmegaInt.Syntax open import FOmegaInt.Syntax.SingleVariableSubstitution open Syntax ---------------------------------------------------------------------- -- Untyped hereditary substitution. infixl 9 _?∙∙⟨_⟩_ _∙∙⟨_⟩_ _⌜·⌝⟨_⟩_ _↓⌜·⌝_ infixl 8 _/⟨_⟩_ _//⟨_⟩_ _Kind/⟨_⟩_ _Asc/⟨_⟩_ -- TODO: explain why there are degenerate cases. mutual -- Apply a herediary substition to an elimination, kind or spine. _/⟨_⟩_ : ∀ {m n} → Elim m → SKind → SVSub m n → Elim n var x ∙ as /⟨ k ⟩ σ = lookupSV σ x ?∙∙⟨ k ⟩ (as //⟨ k ⟩ σ) ⊥ ∙ as /⟨ k ⟩ σ = ⊥ ∙ (as //⟨ k ⟩ σ) ⊤ ∙ as /⟨ k ⟩ σ = ⊤ ∙ (as //⟨ k ⟩ σ) Π j a ∙ as /⟨ k ⟩ σ = Π (j Kind/⟨ k ⟩ σ) (a /⟨ k ⟩ σ ↑) ∙ (as //⟨ k ⟩ σ) (a ⇒ b) ∙ as /⟨ k ⟩ σ = ((a /⟨ k ⟩ σ) ⇒ (b /⟨ k ⟩ σ)) ∙ (as //⟨ k ⟩ σ) Λ j a ∙ as /⟨ k ⟩ σ = Λ (j Kind/⟨ k ⟩ σ) (a /⟨ k ⟩ σ ↑) ∙ (as //⟨ k ⟩ σ) ƛ a b ∙ as /⟨ k ⟩ σ = ƛ (a /⟨ k ⟩ σ) (b /⟨ k ⟩ σ ↑) ∙ (as //⟨ k ⟩ σ) a ⊡ b ∙ as /⟨ k ⟩ σ = (a /⟨ k ⟩ σ) ⊡ (b /⟨ k ⟩ σ) ∙ (as //⟨ k ⟩ σ) _Kind/⟨_⟩_ : ∀ {m n} → Kind Elim m → SKind → SVSub m n → Kind Elim n (a ⋯ b) Kind/⟨ k ⟩ σ = (a /⟨ k ⟩ σ) ⋯ (b /⟨ k ⟩ σ) Π j₁ j₂ Kind/⟨ k ⟩ σ = Π (j₁ Kind/⟨ k ⟩ σ) (j₂ Kind/⟨ k ⟩ σ ↑) _//⟨_⟩_ : ∀ {m n} → Spine m → SKind → SVSub m n → Spine n [] //⟨ k ⟩ σ = [] (a ∷ as) //⟨ k ⟩ σ = a /⟨ k ⟩ σ ∷ as //⟨ k ⟩ σ -- Apply a lookup-result to a spine, performing β-reduction if possible. _?∙∙⟨_⟩_ : ∀ {n} → SVRes n → SKind → Spine n → Elim n hit a ?∙∙⟨ k ⟩ as = a ∙∙⟨ k ⟩ as miss y ?∙∙⟨ k ⟩ as = var y ∙ as -- Apply an elimination to a spine, performing β-reduction if possible. -- -- NOTE. Degenerate cases are marked "!". _∙∙⟨_⟩_ : ∀ {n} → Elim n → SKind → Spine n → Elim n a ∙∙⟨ k ⟩ [] = a a ∙∙⟨ ★ ⟩ (b ∷ bs) = a ∙∙ (b ∷ bs) -- ! a ill-kinded a ∙∙⟨ j ⇒ k ⟩ (b ∷ bs) = a ⌜·⌝⟨ j ⇒ k ⟩ b ∙∙⟨ k ⟩ bs -- Apply one elimination to another, performing β-reduction if possible. -- -- NOTE. Degenerate cases are marked "!". _⌜·⌝⟨_⟩_ : ∀ {n} → Elim n → SKind → Elim n → Elim n a ⌜·⌝⟨ ★ ⟩ b = a ⌜·⌝ b -- ! a ill-kinded (a ∙ (c ∷ cs)) ⌜·⌝⟨ j ⇒ k ⟩ b = a ∙ (c ∷ cs) ⌜·⌝ b -- ! unless a = var x (Λ l a ∙ []) ⌜·⌝⟨ j ⇒ k ⟩ b = a /⟨ j ⟩ (sub b) {-# CATCHALL #-} (a ∙ []) ⌜·⌝⟨ j ⇒ k ⟩ b = a ∙ (b ∷ []) -- ! unless a = var x -- Apply a herediary substition to a kind or type ascription. _Asc/⟨_⟩_ : ∀ {m n} → ElimAsc m → SKind → SVSub m n → ElimAsc n kd j Asc/⟨ k ⟩ σ = kd (j Kind/⟨ k ⟩ σ) tp a Asc/⟨ k ⟩ σ = tp (a /⟨ k ⟩ σ) -- Some shorthands. _[_∈_] : ∀ {n} → Elim (suc n) → Elim n → SKind → Elim n a [ b ∈ k ] = a /⟨ k ⟩ sub b _Kind[_∈_] : ∀ {n} → Kind Elim (suc n) → Elim n → SKind → Kind Elim n j Kind[ a ∈ k ] = j Kind/⟨ k ⟩ sub a -- A variant of application that is reducing (only) if the first -- argument is a type abstraction. _↓⌜·⌝_ : ∀ {n} → Elim n → Elim n → Elim n (a ∙ (b ∷ bs)) ↓⌜·⌝ c = (a ∙ (b ∷ bs)) ⌜·⌝ c (Λ k a ∙ []) ↓⌜·⌝ b = a [ b ∈ ⌊ k ⌋ ] {-# CATCHALL #-} (a ∙ []) ↓⌜·⌝ b = a ∙ (b ∷ []) ---------------------------------------------------------------------- -- Properties of (untyped) hereditary substitution. -- Some exact lemmas about hereditary substitutions (up to -- α-equality). module _ where open SimpleCtx using (⌊_⌋Asc; kd; tp) -- Simplified kinds are stable under application of hereditary -- substitutions. ⌊⌋-Kind/⟨⟩ : ∀ {m n} (j : Kind Elim m) {k} {σ : SVSub m n} → ⌊ j Kind/⟨ k ⟩ σ ⌋ ≡ ⌊ j ⌋ ⌊⌋-Kind/⟨⟩ (a ⋯ b) = refl ⌊⌋-Kind/⟨⟩ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind/⟨⟩ j) (⌊⌋-Kind/⟨⟩ k) ⌊⌋-Asc/⟨⟩ : ∀ {m n} (a : ElimAsc m) {k} {σ : SVSub m n} → ⌊ a Asc/⟨ k ⟩ σ ⌋Asc ≡ ⌊ a ⌋Asc ⌊⌋-Asc/⟨⟩ (kd k) = cong kd (⌊⌋-Kind/⟨⟩ k) ⌊⌋-Asc/⟨⟩ (tp a) = refl -- Hereditary substitutions in spines commute with concatenation. ++-//⟨⟩ : ∀ {k m n} (as bs : Spine m) {σ : SVSub m n} → (as ++ bs) //⟨ k ⟩ σ ≡ as //⟨ k ⟩ σ ++ bs //⟨ k ⟩ σ ++-//⟨⟩ [] bs = refl ++-//⟨⟩ (a ∷ as) bs {σ} = cong (a /⟨ _ ⟩ σ ∷_) (++-//⟨⟩ as bs) open Substitution using (_Elim/_; _Kind′/_; _//_) -- Hereditary substitutions and reducing applications at ★ -- degenerate to ordinary substitutions and applications. mutual /⟨★⟩-/ : ∀ {m n} (a : Elim m) {σ : SVSub m n} → a /⟨ ★ ⟩ σ ≡ a Elim/ toSub σ /⟨★⟩-/ (var x ∙ as) {σ} = begin lookupSV σ x ?∙∙⟨ ★ ⟩ (as //⟨ ★ ⟩ σ) ≡⟨ ?∙∙⟨★⟩-∙∙ (lookupSV σ x) ⟩ toElim (lookupSV σ x) ∙∙ (as //⟨ ★ ⟩ σ) ≡⟨ cong₂ _∙∙_ (sym (⌜⌝∘⌞⌟-id _)) (//⟨★⟩-// as) ⟩ ⌜ ⌞ toElim (lookupSV σ x) ⌟ ⌝ ∙∙ (as // toSub σ) ≡˘⟨ cong (_∙∙ _) (cong ⌜_⌝ (lookup-toSub σ x)) ⟩ var x ∙ as Elim/ toSub σ ∎ where open ≡-Reasoning /⟨★⟩-/ (⊥ ∙ as) = cong (⊥ ∙_) (//⟨★⟩-// as) /⟨★⟩-/ (⊤ ∙ as) = cong (⊤ ∙_) (//⟨★⟩-// as) /⟨★⟩-/ (Π k b ∙ as) = cong₂ _∙_ (cong₂ Π (Kind/⟨★⟩-/ k) (/⟨★⟩-/ b)) (//⟨★⟩-// as) /⟨★⟩-/ ((b ⇒ c) ∙ as) = cong₂ _∙_ (cong₂ _⇒_ (/⟨★⟩-/ b) (/⟨★⟩-/ c)) (//⟨★⟩-// as) /⟨★⟩-/ (Λ k b ∙ as) = cong₂ _∙_ (cong₂ Λ (Kind/⟨★⟩-/ k) (/⟨★⟩-/ b)) (//⟨★⟩-// as) /⟨★⟩-/ (ƛ b c ∙ as) = cong₂ _∙_ (cong₂ ƛ (/⟨★⟩-/ b) (/⟨★⟩-/ c)) (//⟨★⟩-// as) /⟨★⟩-/ (b ⊡ c ∙ as) = cong₂ _∙_ (cong₂ _⊡_ (/⟨★⟩-/ b) (/⟨★⟩-/ c)) (//⟨★⟩-// as) //⟨★⟩-// : ∀ {m n} (as : Spine m) {σ : SVSub m n} → as //⟨ ★ ⟩ σ ≡ as // toSub σ //⟨★⟩-// [] = refl //⟨★⟩-// (a ∷ as) = cong₂ _∷_ (/⟨★⟩-/ a) (//⟨★⟩-// as) Kind/⟨★⟩-/ : ∀ {m n} (k : Kind Elim m) {σ : SVSub m n} → k Kind/⟨ ★ ⟩ σ ≡ k Kind′/ toSub σ Kind/⟨★⟩-/ (a ⋯ b) = cong₂ _⋯_ (/⟨★⟩-/ a) (/⟨★⟩-/ b) Kind/⟨★⟩-/ (Π j k) = cong₂ Π (Kind/⟨★⟩-/ j) (Kind/⟨★⟩-/ k) ?∙∙⟨★⟩-∙∙ : ∀ {n} (r : SVRes n) {as} → r ?∙∙⟨ ★ ⟩ as ≡ toElim r ∙∙ as ?∙∙⟨★⟩-∙∙ (hit a) = ∙∙⟨★⟩-∙∙ a ?∙∙⟨★⟩-∙∙ (miss y) = refl ∙∙⟨★⟩-∙∙ : ∀ {n} (a : Elim n) {bs} → a ∙∙⟨ ★ ⟩ bs ≡ a ∙∙ bs ∙∙⟨★⟩-∙∙ a {[]} = sym (∙∙-[] a) ∙∙⟨★⟩-∙∙ a {b ∷ bs} = refl module RenamingCommutes where open Substitution hiding (_↑; _↑⋆_; sub; _/Var_) renaming (_Elim/Var_ to _/Var_) open P.≡-Reasoning private module S = Substitution module V = VarSubst mutual -- Hereditary substitution commutes with renaming. -- -- NOTE: this is a variant of the `sub-commutes' lemma from -- Data.Fin.Substitution.Lemmas adapted to hereditary -- substitutions and renaming. /⟨⟩-/Var-↑⋆ : ∀ i {m n} a k b {ρ : Sub Fin m n} → b /⟨ k ⟩ sub a ↑⋆ i /Var ρ V.↑⋆ i ≡ b /Var (ρ V.↑) V.↑⋆ i /⟨ k ⟩ sub (a /Var ρ) ↑⋆ i /⟨⟩-/Var-↑⋆ i a k (var x ∙ bs) {ρ} = begin var x ∙ bs /⟨ k ⟩ sub a ↑⋆ i /Var ρ V.↑⋆ i ≡⟨⟩ lookupSV (sub a ↑⋆ i) x ?∙∙⟨ k ⟩ (bs //⟨ k ⟩ sub a ↑⋆ i) /Var ρ V.↑⋆ i ≡⟨ ?∙∙⟨⟩-/Var (lookupSV (sub a ↑⋆ i) x) k (bs //⟨ k ⟩ sub a ↑⋆ i) ⟩ (lookupSV (sub a ↑⋆ i) x ?/Var ρ V.↑⋆ i) ?∙∙⟨ k ⟩ (bs //⟨ k ⟩ sub a ↑⋆ i //Var ρ V.↑⋆ i) ≡⟨ cong₂ _?∙∙⟨ k ⟩_ (lookup-sub-/Var-↑⋆ a i x) (//⟨⟩-/Var-↑⋆ i a k bs) ⟩ lookupSV (sub (a /Var ρ) ↑⋆ i) (x V./ (ρ V.↑) V.↑⋆ i) ?∙∙⟨ k ⟩ (bs //Var (ρ V.↑) V.↑⋆ i //⟨ k ⟩ sub (a /Var ρ) ↑⋆ i) ≡⟨⟩ var x ∙ bs /Var (ρ V.↑) V.↑⋆ i /⟨ k ⟩ sub (a /Var ρ) ↑⋆ i ∎ /⟨⟩-/Var-↑⋆ i a k (⊥ ∙ bs) = cong (⊥ ∙_) (//⟨⟩-/Var-↑⋆ i a k bs) /⟨⟩-/Var-↑⋆ i a k (⊤ ∙ bs) = cong (⊤ ∙_) (//⟨⟩-/Var-↑⋆ i a k bs) /⟨⟩-/Var-↑⋆ i a k (Π j b ∙ bs) = cong₂ _∙_ (cong₂ Π (Kind/⟨⟩-/Var-↑⋆ i a k j) (/⟨⟩-/Var-↑⋆ (suc i) a k b)) (//⟨⟩-/Var-↑⋆ i a k bs) /⟨⟩-/Var-↑⋆ i a k ((b ⇒ c) ∙ bs) = cong₂ _∙_ (cong₂ _⇒_ (/⟨⟩-/Var-↑⋆ i a k b) (/⟨⟩-/Var-↑⋆ i a k c)) (//⟨⟩-/Var-↑⋆ i a k bs) /⟨⟩-/Var-↑⋆ i a k (Λ j b ∙ bs) = cong₂ _∙_ (cong₂ Λ (Kind/⟨⟩-/Var-↑⋆ i a k j) (/⟨⟩-/Var-↑⋆ (suc i) a k b)) (//⟨⟩-/Var-↑⋆ i a k bs) /⟨⟩-/Var-↑⋆ i a k (ƛ b c ∙ bs) = cong₂ _∙_ (cong₂ ƛ (/⟨⟩-/Var-↑⋆ i a k b) (/⟨⟩-/Var-↑⋆ (suc i) a k c)) (//⟨⟩-/Var-↑⋆ i a k bs) /⟨⟩-/Var-↑⋆ i a k (b ⊡ c ∙ bs) = cong₂ _∙_ (cong₂ _⊡_ (/⟨⟩-/Var-↑⋆ i a k b) (/⟨⟩-/Var-↑⋆ i a k c)) (//⟨⟩-/Var-↑⋆ i a k bs) Kind/⟨⟩-/Var-↑⋆ : ∀ i {m n} a k j {ρ : Sub Fin m n} → j Kind/⟨ k ⟩ sub a ↑⋆ i Kind′/Var ρ V.↑⋆ i ≡ j Kind′/Var (ρ V.↑) V.↑⋆ i Kind/⟨ k ⟩ sub (a /Var ρ) ↑⋆ i Kind/⟨⟩-/Var-↑⋆ i a k (b ⋯ c) = cong₂ _⋯_ (/⟨⟩-/Var-↑⋆ i a k b) (/⟨⟩-/Var-↑⋆ i a k c) Kind/⟨⟩-/Var-↑⋆ i a k (Π j l) = cong₂ Π (Kind/⟨⟩-/Var-↑⋆ i a k j) (Kind/⟨⟩-/Var-↑⋆ (suc i) a k l) //⟨⟩-/Var-↑⋆ : ∀ i {n m} a k bs {ρ : Sub Fin m n} → bs //⟨ k ⟩ sub a ↑⋆ i //Var ρ V.↑⋆ i ≡ (bs //Var (ρ V.↑) V.↑⋆ i) //⟨ k ⟩ sub (a /Var ρ) ↑⋆ i //⟨⟩-/Var-↑⋆ i a k [] = refl //⟨⟩-/Var-↑⋆ i a k (b ∷ bs) = cong₂ _∷_ (/⟨⟩-/Var-↑⋆ i a k b) (//⟨⟩-/Var-↑⋆ i a k bs) -- Reducing applications commute with renaming. ?∙∙⟨⟩-/Var : ∀ {m n} r k bs {ρ : Sub Fin m n} → r ?∙∙⟨ k ⟩ bs /Var ρ ≡ (r ?/Var ρ) ?∙∙⟨ k ⟩ (bs //Var ρ) ?∙∙⟨⟩-/Var (hit a) k as = ∙∙⟨⟩-/Var a k as ?∙∙⟨⟩-/Var (miss y) k as = refl ∙∙⟨⟩-/Var : ∀ {m n} a k bs {ρ : Sub Fin m n} → a ∙∙⟨ k ⟩ bs /Var ρ ≡ (a /Var ρ) ∙∙⟨ k ⟩ (bs //Var ρ) ∙∙⟨⟩-/Var a k [] = refl ∙∙⟨⟩-/Var a ★ (b ∷ bs) = S.∙∙-/Var a (b ∷ bs) ∙∙⟨⟩-/Var a (j ⇒ k) (b ∷ bs) {ρ} = begin a ⌜·⌝⟨ j ⇒ k ⟩ b ∙∙⟨ k ⟩ bs /Var ρ ≡⟨ ∙∙⟨⟩-/Var (a ⌜·⌝⟨ j ⇒ k ⟩ b) k bs ⟩ (a ⌜·⌝⟨ j ⇒ k ⟩ b /Var ρ) ∙∙⟨ k ⟩ (bs //Var ρ) ≡⟨ cong (_∙∙⟨ k ⟩ (bs //Var ρ)) (⌜·⌝⟨⟩-/Var a (j ⇒ k) b) ⟩ (a /Var ρ) ⌜·⌝⟨ j ⇒ k ⟩ (b /Var ρ) ∙∙⟨ k ⟩ (bs //Var ρ) ∎ ⌜·⌝⟨⟩-/Var : ∀ {m n} a k b {ρ : Sub Fin m n} → a ⌜·⌝⟨ k ⟩ b /Var ρ ≡ (a /Var ρ) ⌜·⌝⟨ k ⟩ (b /Var ρ) ⌜·⌝⟨⟩-/Var a ★ b = S.⌜·⌝-/Var a b ⌜·⌝⟨⟩-/Var (a ∙ (c ∷ cs)) (j ⇒ k) b {ρ} = begin a ∙ (c ∷ cs) ⌜·⌝ b /Var ρ ≡⟨ S.⌜·⌝-/Var (a ∙ (c ∷ cs)) b ⟩ (a ∙ (c ∷ cs) /Var ρ) ⌜·⌝ (b /Var ρ) ≡˘⟨ cong (λ a → a ∙∙ _ ⌜·⌝ (b /Var ρ)) (S.Head/Var-∙ a) ⟩ (a Head/Var ρ) ∙ ((c ∷ cs) //Var ρ) ⌜·⌝⟨ j ⇒ k ⟩ (b /Var ρ) ≡⟨ cong (λ a → a ∙∙ _ ⌜·⌝⟨ j ⇒ k ⟩ (b /Var ρ)) (S.Head/Var-∙ a) ⟩ (a ∙ (c ∷ cs) /Var ρ) ⌜·⌝⟨ j ⇒ k ⟩ (b /Var ρ) ∎ ⌜·⌝⟨⟩-/Var (var x ∙ []) (j ⇒ k) b = refl ⌜·⌝⟨⟩-/Var (⊥ ∙ []) (j ⇒ k) b = refl ⌜·⌝⟨⟩-/Var (⊤ ∙ []) (j ⇒ k) b = refl ⌜·⌝⟨⟩-/Var (Π l a ∙ []) (j ⇒ k) b = refl ⌜·⌝⟨⟩-/Var ((a ⇒ b) ∙ []) (j ⇒ k) c = refl ⌜·⌝⟨⟩-/Var (Λ l a ∙ []) (j ⇒ k) b = /⟨⟩-/Var-↑⋆ 0 b j a ⌜·⌝⟨⟩-/Var (ƛ a b ∙ []) (j ⇒ k) c = refl ⌜·⌝⟨⟩-/Var (a ⊡ b ∙ []) (j ⇒ k) c = refl -- Some corollaries of the above. Asc/⟨⟩-/Var-↑⋆ : ∀ i {m n} a k b {ρ : Sub Fin m n} → b Asc/⟨ k ⟩ sub a ↑⋆ i ElimAsc/Var ρ V.↑⋆ i ≡ b ElimAsc/Var (ρ V.↑) V.↑⋆ i Asc/⟨ k ⟩ sub (a /Var ρ) ↑⋆ i Asc/⟨⟩-/Var-↑⋆ i a k (kd j) = cong kd (Kind/⟨⟩-/Var-↑⋆ i a k j) Asc/⟨⟩-/Var-↑⋆ i a k (tp b) = cong tp (/⟨⟩-/Var-↑⋆ i a k b) [∈⌊⌋]-/Var : ∀ {m n} a b k {ρ : Sub Fin m n} → a [ b ∈ ⌊ k ⌋ ] /Var ρ ≡ (a /Var ρ V.↑) [ b /Var ρ ∈ ⌊ k Kind′/Var ρ ⌋ ] [∈⌊⌋]-/Var a b k {ρ} = begin (a [ b ∈ ⌊ k ⌋ ] /Var ρ) ≡⟨ /⟨⟩-/Var-↑⋆ 0 b ⌊ k ⌋ a ⟩ ((a /Var ρ V.↑) [ b /Var ρ ∈ ⌊ k ⌋ ]) ≡˘⟨ cong (a /Var ρ V.↑ /⟨_⟩ sub (b /Var ρ)) (S.⌊⌋-Kind′/Var k) ⟩ ((a /Var ρ V.↑) [ b /Var ρ ∈ ⌊ k Kind′/Var ρ ⌋ ]) ∎ Kind[∈⌊⌋]-/Var : ∀ {m n} j a k {ρ : Sub Fin m n} → j Kind[ a ∈ ⌊ k ⌋ ] Kind′/Var ρ ≡ (j Kind′/Var ρ V.↑) Kind[ a /Var ρ ∈ ⌊ k Kind′/Var ρ ⌋ ] Kind[∈⌊⌋]-/Var j a k {ρ} = begin j Kind[ a ∈ ⌊ k ⌋ ] Kind′/Var ρ ≡⟨ Kind/⟨⟩-/Var-↑⋆ 0 a ⌊ k ⌋ j ⟩ (j Kind′/Var ρ V.↑) Kind[ a /Var ρ ∈ ⌊ k ⌋ ] ≡˘⟨ cong (j Kind′/Var ρ V.↑ Kind/⟨_⟩ sub (a /Var ρ)) (S.⌊⌋-Kind′/Var k) ⟩ (j Kind′/Var ρ V.↑) Kind[ a /Var ρ ∈ ⌊ k Kind′/Var ρ ⌋ ] ∎ -- Potentially reducing applications commute with renaming. ↓⌜·⌝-/Var : ∀ {m n} a b {ρ : Sub Fin m n} → a ↓⌜·⌝ b /Var ρ ≡ (a /Var ρ) ↓⌜·⌝ (b /Var ρ) ↓⌜·⌝-/Var (a ∙ (c ∷ cs)) b {ρ} = begin a ∙ (c ∷ cs) ⌜·⌝ b /Var ρ ≡⟨ S.⌜·⌝-/Var (a ∙ (c ∷ cs)) b ⟩ (a ∙ (c ∷ cs) /Var ρ) ⌜·⌝ (b /Var ρ) ≡˘⟨ cong (λ a → a ∙∙ _ ⌜·⌝ (b /Var ρ)) (S.Head/Var-∙ a) ⟩ (a Head/Var ρ) ∙ ((c ∷ cs) //Var ρ) ↓⌜·⌝ (b /Var ρ) ≡⟨ cong (λ a → a ∙∙ _ ↓⌜·⌝ (b /Var ρ)) (S.Head/Var-∙ a) ⟩ (a ∙ (c ∷ cs) /Var ρ) ↓⌜·⌝ (b /Var ρ) ∎ ↓⌜·⌝-/Var (var x ∙ []) b = refl ↓⌜·⌝-/Var (⊥ ∙ []) b = refl ↓⌜·⌝-/Var (⊤ ∙ []) b = refl ↓⌜·⌝-/Var (Π l a ∙ []) b = refl ↓⌜·⌝-/Var ((a ⇒ b) ∙ []) c = refl ↓⌜·⌝-/Var (Λ l a ∙ []) b = [∈⌊⌋]-/Var a b l ↓⌜·⌝-/Var (ƛ a b ∙ []) c = refl ↓⌜·⌝-/Var (a ⊡ b ∙ []) c = refl mutual -- Weakening commutes with application of lifted hereditary -- substitutions. -- -- NOTE: this is a variant of the `wk-commutes' lemma from -- Data.Fin.Substitution.Lemmas adapted to hereditary -- substitutions. wk-/⟨⟩-↑⋆ : ∀ i {k m n} a {σ : SVSub m n} → a /Var V.wk V.↑⋆ i /⟨ k ⟩ (σ ↑) ↑⋆ i ≡ a /⟨ k ⟩ σ ↑⋆ i /Var V.wk V.↑⋆ i wk-/⟨⟩-↑⋆ i {k} (var x ∙ as) {σ} = begin var x ∙ as /Var V.wk V.↑⋆ i /⟨ k ⟩ (σ ↑) ↑⋆ i ≡⟨⟩ lookupSV ((σ ↑) ↑⋆ i) (x V./ V.wk V.↑⋆ i) ?∙∙⟨ k ⟩ (as //Var V.wk V.↑⋆ i //⟨ k ⟩ ((σ ↑) ↑⋆ i)) ≡⟨ (cong₂ (_?∙∙⟨ k ⟩_)) (sym (lookup-/Var-wk-↑⋆ i x)) (wk-//⟨⟩-↑⋆ i as) ⟩ (lookupSV (σ ↑⋆ i) x ?/Var V.wk V.↑⋆ i) ?∙∙⟨ k ⟩ (as //⟨ k ⟩ (σ ↑⋆ i) //Var V.wk V.↑⋆ i) ≡˘⟨ ?∙∙⟨⟩-/Var (lookupSV (σ ↑⋆ i) x) k (as //⟨ k ⟩ (σ ↑⋆ i)) ⟩ lookupSV (σ ↑⋆ i) x ?∙∙⟨ k ⟩ (as //⟨ k ⟩ (σ ↑⋆ i)) /Var V.wk V.↑⋆ i ≡⟨⟩ var x ∙ as /⟨ k ⟩ σ ↑⋆ i /Var V.wk V.↑⋆ i ∎ wk-/⟨⟩-↑⋆ i (⊥ ∙ as) = cong (⊥ ∙_) (wk-//⟨⟩-↑⋆ i as) wk-/⟨⟩-↑⋆ i (⊤ ∙ as) = cong (⊤ ∙_) (wk-//⟨⟩-↑⋆ i as) wk-/⟨⟩-↑⋆ i (Π k a ∙ as) = cong₂ _∙_ (cong₂ Π (wk-Kind/⟨⟩-↑⋆ i k) (wk-/⟨⟩-↑⋆ (suc i) a)) (wk-//⟨⟩-↑⋆ i as) wk-/⟨⟩-↑⋆ i ((a ⇒ b) ∙ as) = cong₂ _∙_ (cong₂ _⇒_ (wk-/⟨⟩-↑⋆ i a) (wk-/⟨⟩-↑⋆ i b)) (wk-//⟨⟩-↑⋆ i as) wk-/⟨⟩-↑⋆ i (Λ k a ∙ as) = cong₂ _∙_ (cong₂ Λ (wk-Kind/⟨⟩-↑⋆ i k) (wk-/⟨⟩-↑⋆ (suc i) a)) (wk-//⟨⟩-↑⋆ i as) wk-/⟨⟩-↑⋆ i (ƛ a b ∙ as) = cong₂ _∙_ (cong₂ ƛ (wk-/⟨⟩-↑⋆ i a) (wk-/⟨⟩-↑⋆ (suc i) b)) (wk-//⟨⟩-↑⋆ i as) wk-/⟨⟩-↑⋆ i (a ⊡ b ∙ as) = cong₂ _∙_ (cong₂ _⊡_ (wk-/⟨⟩-↑⋆ i a) (wk-/⟨⟩-↑⋆ i b)) (wk-//⟨⟩-↑⋆ i as) wk-Kind/⟨⟩-↑⋆ : ∀ i {k m n} j {σ : SVSub m n} → j Kind′/Var V.wk V.↑⋆ i Kind/⟨ k ⟩ (σ ↑) ↑⋆ i ≡ j Kind/⟨ k ⟩ σ ↑⋆ i Kind′/Var V.wk V.↑⋆ i wk-Kind/⟨⟩-↑⋆ i (a ⋯ b) = cong₂ _⋯_ (wk-/⟨⟩-↑⋆ i a) (wk-/⟨⟩-↑⋆ i b) wk-Kind/⟨⟩-↑⋆ i (Π j k) = cong₂ Π (wk-Kind/⟨⟩-↑⋆ i j) (wk-Kind/⟨⟩-↑⋆ (suc i) k) wk-//⟨⟩-↑⋆ : ∀ i {k m n} as {σ : SVSub m n} → as //Var V.wk V.↑⋆ i //⟨ k ⟩ (σ ↑) ↑⋆ i ≡ as //⟨ k ⟩ σ ↑⋆ i //Var V.wk V.↑⋆ i wk-//⟨⟩-↑⋆ i [] = refl wk-//⟨⟩-↑⋆ i (a ∷ as) = cong₂ _∷_ (wk-/⟨⟩-↑⋆ i a) (wk-//⟨⟩-↑⋆ i as) -- A corollary of the above. wk-Asc/⟨⟩-↑⋆ : ∀ i {k m n} a {σ : SVSub m n} → a ElimAsc/Var V.wk V.↑⋆ i Asc/⟨ k ⟩ (σ ↑) ↑⋆ i ≡ a Asc/⟨ k ⟩ σ ↑⋆ i ElimAsc/Var V.wk V.↑⋆ i wk-Asc/⟨⟩-↑⋆ i (kd a) = cong kd (wk-Kind/⟨⟩-↑⋆ i a) wk-Asc/⟨⟩-↑⋆ i (tp a) = cong tp (wk-/⟨⟩-↑⋆ i a) mutual -- Weakening of a term followed by hereditary substitution of the -- newly introduced extra variable leaves the term unchanged. -- -- NOTE: this is a variant of the `wk-sub-vanishes' lemma from -- Data.Fin.Substitution.Lemmas adapted to hereditary -- substitutions. /Var-wk-↑⋆-hsub-vanishes : ∀ i {k m} a {b : Elim m} → a /Var V.wk V.↑⋆ i /⟨ k ⟩ sub b ↑⋆ i ≡ a /Var-wk-↑⋆-hsub-vanishes i {k} (var x ∙ as) {b} = begin var x ∙ as /Var V.wk V.↑⋆ i /⟨ k ⟩ sub b ↑⋆ i ≡⟨ cong₂ _?∙∙⟨ k ⟩_ (lookup-sub-wk-↑⋆ i x) (//Var-wk-↑⋆-hsub-vanishes i as) ⟩ var x ∙ as ∎ /Var-wk-↑⋆-hsub-vanishes i (⊥ ∙ as) = cong (⊥ ∙_) (//Var-wk-↑⋆-hsub-vanishes i as) /Var-wk-↑⋆-hsub-vanishes i (⊤ ∙ as) = cong (⊤ ∙_) (//Var-wk-↑⋆-hsub-vanishes i as) /Var-wk-↑⋆-hsub-vanishes i (Π k a ∙ as) = cong₂ _∙_ (cong₂ Π (Kind/Var-wk-↑⋆-hsub-vanishes i k) (/Var-wk-↑⋆-hsub-vanishes (suc i) a)) (//Var-wk-↑⋆-hsub-vanishes i as) /Var-wk-↑⋆-hsub-vanishes i ((a ⇒ b) ∙ as) = cong₂ _∙_ (cong₂ _⇒_ (/Var-wk-↑⋆-hsub-vanishes i a) (/Var-wk-↑⋆-hsub-vanishes i b)) (//Var-wk-↑⋆-hsub-vanishes i as) /Var-wk-↑⋆-hsub-vanishes i (Λ k a ∙ as) = cong₂ _∙_ (cong₂ Λ (Kind/Var-wk-↑⋆-hsub-vanishes i k) (/Var-wk-↑⋆-hsub-vanishes (suc i) a)) (//Var-wk-↑⋆-hsub-vanishes i as) /Var-wk-↑⋆-hsub-vanishes i (ƛ a b ∙ as) = cong₂ _∙_ (cong₂ ƛ (/Var-wk-↑⋆-hsub-vanishes i a) (/Var-wk-↑⋆-hsub-vanishes (suc i) b)) (//Var-wk-↑⋆-hsub-vanishes i as) /Var-wk-↑⋆-hsub-vanishes i (a ⊡ b ∙ as) = cong₂ _∙_ (cong₂ _⊡_ (/Var-wk-↑⋆-hsub-vanishes i a) (/Var-wk-↑⋆-hsub-vanishes i b)) (//Var-wk-↑⋆-hsub-vanishes i as) Kind/Var-wk-↑⋆-hsub-vanishes : ∀ i {k m} j {b : Elim m} → j Kind′/Var V.wk V.↑⋆ i Kind/⟨ k ⟩ sub b ↑⋆ i ≡ j Kind/Var-wk-↑⋆-hsub-vanishes i (a ⋯ b) = cong₂ _⋯_ (/Var-wk-↑⋆-hsub-vanishes i a) (/Var-wk-↑⋆-hsub-vanishes i b) Kind/Var-wk-↑⋆-hsub-vanishes i (Π j k) = cong₂ Π (Kind/Var-wk-↑⋆-hsub-vanishes i j) (Kind/Var-wk-↑⋆-hsub-vanishes (suc i) k) //Var-wk-↑⋆-hsub-vanishes : ∀ i {k m} as {b : Elim m} → as //Var V.wk V.↑⋆ i //⟨ k ⟩ sub b ↑⋆ i ≡ as //Var-wk-↑⋆-hsub-vanishes i [] = refl //Var-wk-↑⋆-hsub-vanishes i (a ∷ as) = cong₂ _∷_ (/Var-wk-↑⋆-hsub-vanishes i a) (//Var-wk-↑⋆-hsub-vanishes i as) -- A corollary of the above. Asc/Var-wk-↑⋆-hsub-vanishes : ∀ i {k m} a {b : Elim m} → a S.ElimAsc/Var V.wk V.↑⋆ i Asc/⟨ k ⟩ sub b ↑⋆ i ≡ a Asc/Var-wk-↑⋆-hsub-vanishes i (kd a) = cong kd (Kind/Var-wk-↑⋆-hsub-vanishes i a) Asc/Var-wk-↑⋆-hsub-vanishes i (tp a) = cong tp (/Var-wk-↑⋆-hsub-vanishes i a) open RenamingCommutes module _ where private module EL = TermLikeLemmas Substitution.termLikeLemmasElim module KL = TermLikeLemmas Substitution.termLikeLemmasKind′ open Substitution hiding (_↑; _↑⋆_; sub) open ≡-Reasoning -- Repeated weakening commutes with application of lifted hereditary -- substitutions. wk⋆-/⟨⟩-↑⋆ : ∀ i {k m n} a {σ : SVSub m n} → a Elim/ wk⋆ i /⟨ k ⟩ σ ↑⋆ i ≡ a /⟨ k ⟩ σ Elim/ wk⋆ i wk⋆-/⟨⟩-↑⋆ zero {k} a {σ} = begin a Elim/ id /⟨ k ⟩ σ ≡⟨ cong (_/⟨ k ⟩ σ) (EL.id-vanishes a) ⟩ a /⟨ k ⟩ σ ≡˘⟨ EL.id-vanishes (a /⟨ k ⟩ σ) ⟩ a /⟨ k ⟩ σ Elim/ id ∎ wk⋆-/⟨⟩-↑⋆ (suc i) {k} a {σ} = begin a Elim/ wk⋆ (suc i) /⟨ k ⟩ (σ ↑⋆ i) ↑ ≡⟨ cong (_/⟨ k ⟩ (σ ↑⋆ i) ↑) (EL./-weaken a) ⟩ a Elim/ wk⋆ i Elim/ wk /⟨ k ⟩ (σ ↑⋆ i) ↑ ≡⟨ cong (_/⟨ k ⟩ (σ ↑⋆ i) ↑) (EL./-wk {t = a Elim/ wk⋆ i}) ⟩ weakenElim (a Elim/ wk⋆ i) /⟨ k ⟩ (σ ↑⋆ i) ↑ ≡⟨ wk-/⟨⟩-↑⋆ zero (a Elim/ wk⋆ i) ⟩ weakenElim (a Elim/ wk⋆ i /⟨ k ⟩ σ ↑⋆ i) ≡⟨ cong weakenElim (wk⋆-/⟨⟩-↑⋆ i a) ⟩ weakenElim (a /⟨ k ⟩ σ Elim/ wk⋆ i) ≡˘⟨ (EL./-wk {t = a /⟨ k ⟩ σ Elim/ wk⋆ i}) ⟩ a /⟨ k ⟩ σ Elim/ wk⋆ i Elim/ wk ≡˘⟨ EL./-weaken (a /⟨ k ⟩ σ) ⟩ a /⟨ k ⟩ σ Elim/ wk⋆ (suc i) ∎ wk⋆-Kind/⟨⟩-↑⋆ : ∀ i {k m n} j {σ : SVSub m n} → j Kind′/ wk⋆ i Kind/⟨ k ⟩ σ ↑⋆ i ≡ j Kind/⟨ k ⟩ σ Kind′/ wk⋆ i wk⋆-Kind/⟨⟩-↑⋆ zero {k} j {σ} = begin j Kind′/ id Kind/⟨ k ⟩ σ ≡⟨ cong (_Kind/⟨ k ⟩ σ) (KL.id-vanishes j) ⟩ j Kind/⟨ k ⟩ σ ≡˘⟨ KL.id-vanishes (j Kind/⟨ k ⟩ σ) ⟩ j Kind/⟨ k ⟩ σ Kind′/ id ∎ wk⋆-Kind/⟨⟩-↑⋆ (suc i) {k} j {σ} = begin j Kind′/ wk⋆ (suc i) Kind/⟨ k ⟩ (σ ↑⋆ i) ↑ ≡⟨ cong (_Kind/⟨ k ⟩ (σ ↑⋆ i) ↑) (KL./-weaken j) ⟩ j Kind′/ wk⋆ i Kind′/ wk Kind/⟨ k ⟩ (σ ↑⋆ i) ↑ ≡⟨ cong (_Kind/⟨ k ⟩ (σ ↑⋆ i) ↑) (KL./-wk {t = j Kind′/ wk⋆ i}) ⟩ weakenKind′ (j Kind′/ wk⋆ i) Kind/⟨ k ⟩ (σ ↑⋆ i) ↑ ≡⟨ wk-Kind/⟨⟩-↑⋆ zero (j Kind′/ wk⋆ i) ⟩ weakenKind′ (j Kind′/ wk⋆ i Kind/⟨ k ⟩ σ ↑⋆ i) ≡⟨ cong weakenKind′ (wk⋆-Kind/⟨⟩-↑⋆ i j) ⟩ weakenKind′ (j Kind/⟨ k ⟩ σ Kind′/ wk⋆ i) ≡˘⟨ (KL./-wk {t = j Kind/⟨ k ⟩ σ Kind′/ wk⋆ i}) ⟩ j Kind/⟨ k ⟩ σ Kind′/ wk⋆ i Kind′/ wk ≡˘⟨ KL./-weaken (j Kind/⟨ k ⟩ σ) ⟩ j Kind/⟨ k ⟩ σ Kind′/ wk⋆ (suc i) ∎ -- A corollary of the above. weaken⋆-/⟨⟩-↑⋆ : ∀ i {k m n} a {σ : SVSub m n} → weakenElim⋆ i (a /⟨ k ⟩ σ) ≡ weakenElim⋆ i a /⟨ k ⟩ σ ↑⋆ i weaken⋆-/⟨⟩-↑⋆ i {k} a {σ} = begin weakenElim⋆ i (a /⟨ k ⟩ σ) ≡˘⟨ EL./-wk⋆ i ⟩ a /⟨ k ⟩ σ Elim/ wk⋆ i ≡˘⟨ wk⋆-/⟨⟩-↑⋆ i a ⟩ a Elim/ wk⋆ i /⟨ k ⟩ σ ↑⋆ i ≡⟨ cong (_/⟨ k ⟩ σ ↑⋆ i) (EL./-wk⋆ i) ⟩ weakenElim⋆ i a /⟨ k ⟩ σ ↑⋆ i ∎ -- NOTE. Unfortunately, we cannot prove that arbitrary untyped -- hereditary substitutions commute, because *untyped* hereditary -- substitutions need not commute with reducting applications in -- general. We will prove a weaker result, namely that well-kinded -- hereditary substitutions in well-kinded types commute, later. -- See e.g. `Nf∈-[]-/⟨⟩-↑⋆` etc. in module Kinding.Simple. -- Some commutation lemmas up to βη-equality. module _ where open →β*-Reasoning open Substitution hiding (_↑; _↑⋆_; sub) private module Kd = Kd→β*-Reasoning mutual -- Hereditary substitution commutes with ⌞_⌟ up to β-reduction. ⌞⌟-/⟨⟩-β : ∀ {m n} a {k} {σ : SVSub m n} → ⌞ a ⌟ / toSub σ →β* ⌞ a /⟨ k ⟩ σ ⌟ ⌞⌟-/⟨⟩-β (var x ∙ bs) {k} {σ} = begin ⌞ var x ∙ bs ⌟ / toSub σ ⟶⋆⟨ ⌞∙⌟-/⟨⟩-β (var x / toSub σ) (var x) bs ε ⟩ (var x / toSub σ) ⌞∙⌟ ⌞ bs //⟨ k ⟩ σ ⌟Sp ≡⟨ cong (_⌞∙⌟ ⌞ bs //⟨ k ⟩ σ ⌟Sp) (lookup-toSub σ x) ⟩ ⌞ toElim (lookupSV σ x) ⌟ ⌞∙⌟ ⌞ bs //⟨ k ⟩ σ ⌟Sp ⟶⋆⟨ ⌞⌟-?∙∙-β (lookupSV σ x) k (bs //⟨ k ⟩ σ) ⟩ ⌞ lookupSV σ x ?∙∙⟨ k ⟩ (bs //⟨ k ⟩ σ) ⌟ ∎ ⌞⌟-/⟨⟩-β (⊥ ∙ bs) = ⌞∙⌟-/⟨⟩-β ⊥ ⊥ bs ε ⌞⌟-/⟨⟩-β (⊤ ∙ bs) = ⌞∙⌟-/⟨⟩-β ⊤ ⊤ bs ε ⌞⌟-/⟨⟩-β (Π j b ∙ bs) {k} {σ} = ⌞∙⌟-/⟨⟩-β _ _ bs (begin ⌞ Π j b ⌟Hd / toSub σ ⟶⋆⟨ →β*-Π (⌞⌟Kd-/⟨⟩-β j) (⌞⌟-/⟨⟩-β b) ⟩ Π ⌞ j Kind/⟨ k ⟩ σ ⌟Kd ⌞ b /⟨ k ⟩ σ ↑ ⌟ ∎) ⌞⌟-/⟨⟩-β ((a ⇒ b) ∙ bs) {k} {σ} = ⌞∙⌟-/⟨⟩-β _ _ bs (begin ⌞ a ⇒ b ⌟Hd / toSub σ ⟶⋆⟨ →β*-⇒ (⌞⌟-/⟨⟩-β a) (⌞⌟-/⟨⟩-β b) ⟩ ⌞ a /⟨ k ⟩ σ ⌟ ⇒ ⌞ b /⟨ k ⟩ σ ⌟ ∎) ⌞⌟-/⟨⟩-β (Λ j b ∙ bs) {k} {σ} = ⌞∙⌟-/⟨⟩-β _ _ bs (begin ⌞ Λ j b ⌟Hd / toSub σ ⟶⋆⟨ →β*-Λ (⌞⌟Kd-/⟨⟩-β j) (⌞⌟-/⟨⟩-β b) ⟩ Λ ⌞ j Kind/⟨ k ⟩ σ ⌟Kd ⌞ b /⟨ k ⟩ σ ↑ ⌟ ∎) ⌞⌟-/⟨⟩-β (ƛ a b ∙ bs) {k} {σ} = ⌞∙⌟-/⟨⟩-β _ _ bs (begin ⌞ ƛ a b ⌟Hd / toSub σ ⟶⋆⟨ →β*-ƛ (⌞⌟-/⟨⟩-β a) (⌞⌟-/⟨⟩-β b) ⟩ ƛ ⌞ a /⟨ k ⟩ σ ⌟ ⌞ b /⟨ k ⟩ σ ↑ ⌟ ∎) ⌞⌟-/⟨⟩-β (a ⊡ b ∙ bs) {k} {σ} = ⌞∙⌟-/⟨⟩-β _ _ bs (begin ⌞ a ⊡ b ⌟Hd / toSub σ ⟶⋆⟨ →β*-⊡ (⌞⌟-/⟨⟩-β a) (⌞⌟-/⟨⟩-β b) ⟩ ⌞ a /⟨ k ⟩ σ ⌟ ⊡ ⌞ b /⟨ k ⟩ σ ⌟ ∎) ⌞⌟Kd-/⟨⟩-β : ∀ {m n} j {k} {σ : SVSub m n} → ⌞ j ⌟Kd Kind/ toSub σ Kd→β* ⌞ j Kind/⟨ k ⟩ σ ⌟Kd ⌞⌟Kd-/⟨⟩-β (a ⋯ b) {k} {σ} = Kd.begin (⌞ a ⋯ b ⌟Kd Kind/ toSub σ) Kd.⟶⋆⟨ Kd→β*-⋯ (⌞⌟-/⟨⟩-β a) (⌞⌟-/⟨⟩-β b) ⟩ ⌞ a /⟨ k ⟩ σ ⌟ ⋯ ⌞ b /⟨ k ⟩ σ ⌟ Kd.∎ ⌞⌟Kd-/⟨⟩-β (Π j l) {k} {σ} = Kd.begin (⌞ Π j l ⌟Kd Kind/ toSub σ) Kd.⟶⋆⟨ Kd→β*-Π (⌞⌟Kd-/⟨⟩-β j) (⌞⌟Kd-/⟨⟩-β l) ⟩ Π ⌞ j Kind/⟨ k ⟩ σ ⌟Kd ⌞ l Kind/⟨ k ⟩ σ ↑ ⌟Kd Kd.∎ ⌞∙⌟-/⟨⟩-β : ∀ {m n} a b bs {k} {σ : SVSub m n} → b / toSub σ →β* a → (b ⌞∙⌟ ⌞ bs ⌟Sp) / toSub σ →β* a ⌞∙⌟ ⌞ bs //⟨ k ⟩ σ ⌟Sp ⌞∙⌟-/⟨⟩-β a b [] hyp = hyp ⌞∙⌟-/⟨⟩-β a b (c ∷ cs) {k} {σ} hyp = ⌞∙⌟-/⟨⟩-β (a · ⌞ c /⟨ k ⟩ σ ⌟) (b · ⌞ c ⌟) cs (→β*-· hyp (⌞⌟-/⟨⟩-β c)) -- Reducing applications commute with ⌞_⌟ up to β-reduction. ⌞⌟-?∙∙-β : ∀ {n} (r : SVRes n) k bs → ⌞ toElim r ⌟ ⌞∙⌟ ⌞ bs ⌟Sp →β* ⌞ r ?∙∙⟨ k ⟩ bs ⌟ ⌞⌟-?∙∙-β (hit a) k bs = ⌞⌟-∙∙-β a k bs ⌞⌟-?∙∙-β (miss y) k bs = ε ⌞⌟-∙∙-β : ∀ {n} (a : Elim n) k bs → ⌞ a ⌟ ⌞∙⌟ ⌞ bs ⌟Sp →β* ⌞ a ∙∙⟨ k ⟩ bs ⌟ ⌞⌟-∙∙-β a k [] = ε ⌞⌟-∙∙-β a ★ (b ∷ bs) = begin ⌞ a ⌟ ⌞∙⌟ (⌞ b ⌟ ∷ ⌞ bs ⌟Sp) ≡˘⟨ ⌞⌟-∙∙ a (b ∷ bs) ⟩ ⌞ a ∙∙ (b ∷ bs) ⌟ ∎ ⌞⌟-∙∙-β a (j ⇒ k) (b ∷ bs) = begin ⌞ a ⌟ ⌞∙⌟ (⌞ b ⌟ ∷ ⌞ bs ⌟Sp) ⟶⋆⟨ →β*-⌞∙⌟₁ (⌞⌟-⌜·⌝-β a (j ⇒ k) b) ⌞ bs ⌟Sp ⟩ ⌞ a ⌜·⌝⟨ j ⇒ k ⟩ b ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ⟶⋆⟨ ⌞⌟-∙∙-β (a ⌜·⌝⟨ j ⇒ k ⟩ b) k bs ⟩ ⌞ a ⌜·⌝⟨ j ⇒ k ⟩ b ∙∙⟨ k ⟩ bs ⌟ ∎ ⌞⌟-⌜·⌝-β : ∀ {n} (a : Elim n) k b → ⌞ a ⌟ · ⌞ b ⌟ →β* ⌞ a ⌜·⌝⟨ k ⟩ b ⌟ ⌞⌟-⌜·⌝-β a ★ b = begin ⌞ a ⌟ · ⌞ b ⌟ ≡˘⟨ ⌞⌟-· a b ⟩ ⌞ a ⌜·⌝ b ⌟ ∎ ⌞⌟-⌜·⌝-β (a ∙ (c ∷ cs)) (j ⇒ k) b = begin ⌞ a ∙ (c ∷ cs) ⌟ · ⌞ b ⌟ ≡˘⟨ ⌞⌟-· (a ∙ (c ∷ cs)) b ⟩ ⌞ a ∙ (c ∷ cs) ⌜·⌝ b ⌟ ∎ ⌞⌟-⌜·⌝-β (var x ∙ []) (j ⇒ k) b = ε ⌞⌟-⌜·⌝-β (⊥ ∙ []) (j ⇒ k) b = ε ⌞⌟-⌜·⌝-β (⊤ ∙ []) (j ⇒ k) b = ε ⌞⌟-⌜·⌝-β (Π l a ∙ []) (j ⇒ k) b = ε ⌞⌟-⌜·⌝-β ((a ⇒ b) ∙ []) (j ⇒ k) c = ε ⌞⌟-⌜·⌝-β (Λ l a ∙ []) (j ⇒ k) b = begin Λ ⌞ l ⌟Kd ⌞ a ⌟ · ⌞ b ⌟ ⟶⟨ ⌈ cont-Tp· ⌞ l ⌟Kd ⌞ a ⌟ ⌞ b ⌟ ⌉ ⟩ ⌞ a ⌟ [ ⌞ b ⌟ ] ⟶⋆⟨ ⌞⌟-/⟨⟩-β a {j} {sub b} ⟩ ⌞ a [ b ∈ j ] ⌟ ∎ ⌞⌟-⌜·⌝-β (ƛ a b ∙ []) (j ⇒ k) c = ε ⌞⌟-⌜·⌝-β (a ⊡ b ∙ []) (j ⇒ k) c = ε -- Potentially reducing applications commute with ⌞_⌟ up to β-reduction. ⌞⌟-↓⌜·⌝-β : ∀ {n} (a : Elim n) b → ⌞ a ⌟ · ⌞ b ⌟ →β* ⌞ a ↓⌜·⌝ b ⌟ ⌞⌟-↓⌜·⌝-β (a ∙ (c ∷ cs)) b = begin ⌞ a ∙ (c ∷ cs) ⌟ · ⌞ b ⌟ ≡˘⟨ ⌞⌟-· (a ∙ (c ∷ cs)) b ⟩ ⌞ a ∙ (c ∷ cs) ⌜·⌝ b ⌟ ∎ ⌞⌟-↓⌜·⌝-β (var x ∙ []) b = ε ⌞⌟-↓⌜·⌝-β (⊥ ∙ []) b = ε ⌞⌟-↓⌜·⌝-β (⊤ ∙ []) b = ε ⌞⌟-↓⌜·⌝-β (Π l a ∙ []) b = ε ⌞⌟-↓⌜·⌝-β ((a ⇒ b) ∙ []) c = ε ⌞⌟-↓⌜·⌝-β (Λ l a ∙ []) b = begin Λ ⌞ l ⌟Kd ⌞ a ⌟ · ⌞ b ⌟ ⟶⟨ ⌈ cont-Tp· ⌞ l ⌟Kd ⌞ a ⌟ ⌞ b ⌟ ⌉ ⟩ ⌞ a ⌟ [ ⌞ b ⌟ ] ⟶⋆⟨ ⌞⌟-/⟨⟩-β a {⌊ l ⌋} {sub b} ⟩ ⌞ a [ b ∈ ⌊ l ⌋ ] ⌟ ∎ ⌞⌟-↓⌜·⌝-β (ƛ a b ∙ []) c = ε ⌞⌟-↓⌜·⌝-β (a ⊡ b ∙ []) c = ε
{ "alphanum_fraction": 0.3792146119, "avg_line_length": 41.1036036036, "ext": "agda", "hexsha": "953428d4c843901aee482d019e49181fdf3132da", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Syntax/HereditarySubstitution.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Syntax/HereditarySubstitution.agda", "max_line_length": 81, "max_stars_count": null, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Syntax/HereditarySubstitution.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 15840, "size": 27375 }
postulate A : Set postulate B : A → Set variable a : A foo : B a → Set foo x = {!a!} -- WAS: C-c C-c here reports "Not a variable: a" -- SHOULD instead introduce the hidden argument {a} {- C-c C-e reports a : A (not in scope) x : B a -}
{ "alphanum_fraction": 0.6099585062, "avg_line_length": 17.2142857143, "ext": "agda", "hexsha": "51db31b736d33c78331c13c7e0d24d611d8be937", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue3460.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue3460.agda", "max_line_length": 62, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue3460.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 82, "size": 241 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Definition module Numbers.Integers.Definition where data ℤ : Set where nonneg : ℕ → ℤ negSucc : ℕ → ℤ {-# BUILTIN INTEGER ℤ #-} {-# BUILTIN INTEGERPOS nonneg #-} {-# BUILTIN INTEGERNEGSUC negSucc #-} nonnegInjective : {a b : ℕ} → nonneg a ≡ nonneg b → a ≡ b nonnegInjective refl = refl negSuccInjective : {a b : ℕ} → negSucc a ≡ negSucc b → a ≡ b negSuccInjective refl = refl ℤDecideEquality : (a b : ℤ) → ((a ≡ b) || ((a ≡ b) → False)) ℤDecideEquality (nonneg x) (nonneg y) with ℕDecideEquality x y ℤDecideEquality (nonneg x) (nonneg y) | inl eq = inl (applyEquality nonneg eq) ℤDecideEquality (nonneg x) (nonneg y) | inr non = inr λ i → non (nonnegInjective i) ℤDecideEquality (nonneg x) (negSucc y) = inr λ () ℤDecideEquality (negSucc x) (nonneg x₁) = inr λ () ℤDecideEquality (negSucc x) (negSucc y) with ℕDecideEquality x y ℤDecideEquality (negSucc x) (negSucc y) | inl eq = inl (applyEquality negSucc eq) ℤDecideEquality (negSucc x) (negSucc y) | inr non = inr λ i → non (negSuccInjective i)
{ "alphanum_fraction": 0.6872791519, "avg_line_length": 37.7333333333, "ext": "agda", "hexsha": "5db7fe32675fac185ac2ea21663b28a11da49637", "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": "Numbers/Integers/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": "Numbers/Integers/Definition.agda", "max_line_length": 86, "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": "Numbers/Integers/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": 414, "size": 1132 }
-- This error never occurs. module ShouldBeASort where err = ShouldBeASort-Never-Occurs
{ "alphanum_fraction": 0.7802197802, "avg_line_length": 13, "ext": "agda", "hexsha": "6980a3658a2a43567e7dcba3be0c0a40c8d7ea2f", "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/ShouldBeASort.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/ShouldBeASort.agda", "max_line_length": 32, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/ShouldBeASort.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": 25, "size": 91 }
------------------------------------------------------------------------ -- Some theory of Erased, developed using the K rule and propositional -- equality ------------------------------------------------------------------------ -- This module instantiates and reexports code from Erased. {-# OPTIONS --with-K --safe #-} module Erased.With-K where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection equality-with-J using (_↔_) open import Embedding equality-with-J as Emb using (Is-embedding) open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) import Erased.Basics as EB import Erased.Level-1 equality-with-J as E open import H-level equality-with-J open import Injection equality-with-J using (Injective) private variable a b p : Level A : Type a ------------------------------------------------------------------------ -- Code related to the module Erased -- Given an erased proof of equality of x and y one can show that -- [ x ] is equal to [ y ]. []-cong : {@0 A : Type a} {@0 x y : A} → EB.Erased (x ≡ y) → EB.[ x ] ≡ EB.[ y ] []-cong EB.[ refl ] = refl -- []-cong is an equivalence. []-cong-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong {x = x} {y = y}) []-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence (Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = []-cong ; from = λ eq → EB.[ cong EB.erased eq ] } ; right-inverse-of = λ { refl → refl } } ; left-inverse-of = λ { EB.[ refl ] → refl } })) -- []-cong maps [ refl ] to refl (by definition). []-cong-[refl] : {@0 A : Type a} {@0 x : A} → []-cong EB.[ refl {x = x} ] ≡ refl {x = EB.[ x ]} []-cong-[refl] = refl -- The []-cong axioms can be instantiated. instance-of-[]-cong-axiomatisation : E.[]-cong-axiomatisation a instance-of-[]-cong-axiomatisation = λ where .E.[]-cong-axiomatisation.[]-cong → []-cong .E.[]-cong-axiomatisation.[]-cong-equivalence → []-cong-equivalence .E.[]-cong-axiomatisation.[]-cong-[refl] → []-cong-[refl] -- Some reexported definitions. open import Erased equality-with-J instance-of-[]-cong-axiomatisation public hiding ([]-cong; []-cong-equivalence; []-cong-[refl]; Injective-[]; Π-Erased≃Π0[]; Π-Erased≃Π0) ------------------------------------------------------------------------ -- Other code -- [_]→ is injective. Injective-[] : {@0 A : Type a} → Injective [ A ∣_]→ Injective-[] refl = refl -- [_]→ is an embedding. Is-embedding-[] : {@0 A : Type a} → Is-embedding [ A ∣_]→ Is-embedding-[] _ _ = (λ { refl → refl }) , (λ { refl → refl }) , (λ { refl → refl }) , (λ { refl → refl }) -- If Erased A is a proposition, then A is a proposition. Is-proposition-Erased→Is-proposition : {@0 A : Type a} → Is-proposition (Erased A) → Is-proposition A Is-proposition-Erased→Is-proposition prop x y = Injective-[] (prop [ x ] [ y ]) -- A variant of the previous result. H-level′-1-Erased→H-level′-1 : {@0 A : Type a} → H-level′ 1 (Erased A) → H-level′ 1 A H-level′-1-Erased→H-level′-1 prop x y with proj₁ (prop [ x ] [ y ]) ... | refl = refl , λ { refl → refl } -- Equality is always very stable. Very-stable-≡-trivial : Very-stable-≡ A Very-stable-≡-trivial = _⇔_.from (Very-stable-≡↔Is-embedding-[] _) Is-embedding-[] -- The following four results are inspired by a result in -- Mishra-Linger's PhD thesis (see Section 5.4.1). -- There is a bijection between (x : Erased A) → P x and -- (@0 x : A) → P [ x ]. Π-Erased↔Π0[] : {@0 A : Type a} {@0 P : Erased A → Type p} → ((x : Erased A) → P x) ↔ ((@0 x : A) → P [ x ]) Π-Erased↔Π0[] = record { surjection = record { logical-equivalence = Π-Erased⇔Π0 ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ _ → refl } -- There is an equivalence between (x : Erased A) → P x and -- (@0 x : A) → P [ x ]. -- -- This is not proved by converting Π-Erased↔Π0[] to an equivalence, -- because the type arguments of the conversion function in -- Equivalence are not erased, and P can only be used in erased -- contexts. -- -- This is a strengthening of E.Π-Erased≃Π0[]. Π-Erased≃Π0[] : {@0 A : Type a} {@0 P : Erased A → Type p} → ((x : Erased A) → P x) ≃ ((@0 x : A) → P [ x ]) Π-Erased≃Π0[] = record { to = λ f x → f [ x ] ; is-equivalence = (λ f ([ x ]) → f x) , (λ _ → refl) , (λ _ → refl) , (λ _ → refl) } -- There is a bijection between (x : Erased A) → P (erased x) and -- (@0 x : A) → P x. Π-Erased↔Π0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) ↔ ((@0 x : A) → P x) Π-Erased↔Π0 = Π-Erased↔Π0[] -- There is an equivalence between (x : Erased A) → P (erased x) and -- (@0 x : A) → P x. -- -- This is a strengthening of E.Π-Erased≃Π0. Π-Erased≃Π0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) ≃ ((@0 x : A) → P x) Π-Erased≃Π0 = Π-Erased≃Π0[] private -- As an aside it is possible to prove the four previous results -- without relying on eta-equality for Erased. However, the code -- makes use of extensionality, and it also makes use of -- eta-equality for Π. (The use of η-equality for Π could perhaps be -- avoided, but Agda does not, at the time of writing, provide a -- simple way to turn off this kind of η-equality.) data Erased-no-η (@0 A : Type a) : Type a where [_] : @0 A → Erased-no-η A @0 erased-no-η : Erased-no-η A → A erased-no-η [ x ] = x -- Some lemmas. Π-Erased-no-η→Π0[] : {@0 A : Type a} {@0 P : Erased-no-η A → Type p} → ((x : Erased-no-η A) → P x) → (@0 x : A) → P [ x ] Π-Erased-no-η→Π0[] f x = f [ x ] Π0[]→Π-Erased-no-η : {@0 A : Type a} (@0 P : Erased-no-η A → Type p) → ((@0 x : A) → P [ x ]) → (x : Erased-no-η A) → P x Π0[]→Π-Erased-no-η _ f [ x ] = f x Π0[]→Π-Erased-no-η-Π-Erased-no-η→Π0[] : {@0 A : Type a} {@0 P : Erased-no-η A → Type p} (f : (x : Erased-no-η A) → P x) (x : Erased-no-η A) → Π0[]→Π-Erased-no-η P (Π-Erased-no-η→Π0[] f) x ≡ f x Π0[]→Π-Erased-no-η-Π-Erased-no-η→Π0[] f [ x ] = refl -- There is a bijection between (x : Erased-no-η A) → P x and -- (@0 x : A) → P [ x ] (assuming extensionality). Π-Erased-no-η↔Π0[] : {@0 A : Type a} {@0 P : Erased-no-η A → Type p} → Extensionality′ (Erased-no-η A) P → ((x : Erased-no-η A) → P x) ↔ ((@0 x : A) → P [ x ]) Π-Erased-no-η↔Π0[] {P = P} ext = record { surjection = record { logical-equivalence = record { to = Π-Erased-no-η→Π0[] ; from = Π0[]→Π-Erased-no-η _ } ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ f → ext (Π0[]→Π-Erased-no-η-Π-Erased-no-η→Π0[] f) } -- There is an equivalence between (x : Erased-no-η A) → P x and -- (@0 x : A) → P [ x ] (assuming extensionality). -- -- This is not proved by converting Π-Erased-no-η↔Π0[] to an -- equivalence, because the type arguments of the conversion -- function in Equivalence are not erased, and A and P can only be -- used in erased contexts. Π-Erased-no-η≃Π0[] : {@0 A : Type a} {@0 P : Erased-no-η A → Type p} → Extensionality′ (Erased-no-η A) P → ((x : Erased-no-η A) → P x) ≃ ((@0 x : A) → P [ x ]) Π-Erased-no-η≃Π0[] {A = A} {P = P} ext = record { to = λ f x → f [ x ] ; is-equivalence = Π0[]→Π-Erased-no-η _ , (λ _ → refl) , (λ f → ext (Π0[]→Π-Erased-no-η-Π-Erased-no-η→Π0[] f)) , (λ _ → uip _ _) } where uip : {@0 B : Type b} {@0 x y : B} (@0 p q : x ≡ y) → p ≡ q uip refl refl = refl -- There is a bijection between -- (x : Erased-no-η A) → P (erased-no-η x) and (@0 x : A) → P x -- (assuming extensionality). Π-Erased-no-η↔Π0 : {@0 A : Type a} {@0 P : A → Type p} → Extensionality′ (Erased-no-η A) (P ∘ erased-no-η) → ((x : Erased-no-η A) → P (erased-no-η x)) ↔ ((@0 x : A) → P x) Π-Erased-no-η↔Π0 = Π-Erased-no-η↔Π0[] -- There is an equivalence between -- (x : Erased-no-η A) → P (erased-no-η x) and (@0 x : A) → P x -- (assuming extensionality). Π-Erased-no-η≃Π0 : {@0 A : Type a} {@0 P : A → Type p} → Extensionality′ (Erased-no-η A) (P ∘ erased-no-η) → ((x : Erased-no-η A) → P (erased-no-η x)) ≃ ((@0 x : A) → P x) Π-Erased-no-η≃Π0 = Π-Erased-no-η≃Π0[]
{ "alphanum_fraction": 0.5407169991, "avg_line_length": 31.0848708487, "ext": "agda", "hexsha": "50b0cc650606f6aee96363f53c15686e056303cd", "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": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Erased/With-K.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/equality", "max_issues_repo_path": "src/Erased/With-K.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Erased/With-K.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 3306, "size": 8424 }
-- Andreas, 2015-02-07 -- {-# OPTIONS -v tc.with:40 #-} open import Common.Prelude hiding (not) not : Bool → Bool not true = false not false = true T : Bool → Set → Set T true A = A → A T false A = Bool test : (b : Bool) → (A : Set) → T (not b) A test b with not b test b | true = λ A a → a test b | false = λ A → false -- should be able to abstract (not b) under Binder (A : Set) -- and succeed
{ "alphanum_fraction": 0.5935960591, "avg_line_length": 18.4545454545, "ext": "agda", "hexsha": "5e6fd3c1fb48600cd9b220fbb0c47573874653d8", "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/WithAbstractUnderBinder.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/WithAbstractUnderBinder.agda", "max_line_length": 60, "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/WithAbstractUnderBinder.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": 141, "size": 406 }
import Lvl open import Type module Data.List.Relation.Sublist {ℓ} {T : Type{ℓ}} where open import Data.List using (List ; ∅ ; _⊰_) open import Logic -- Whether a list's elements are contained in another list in order. -- Examples: -- [1,2,3] ⊑ [1,2,3] -- [1,2,3] ⊑ [1,2,3,4] -- [1,2,3] ⊑ [0,1,2,3] -- [1,2,3] ⊑ [0,1,10,2,20,3,30] -- [0,10,20,30] ⊑ [0,1,10,2,20,3,30] data _⊑_ : List(T) → List(T) → Stmt{ℓ} where empty : (∅ ⊑ ∅) use : ∀{x}{l₁ l₂} → (l₁ ⊑ l₂) → ((x ⊰ l₁) ⊑ (x ⊰ l₂)) skip : ∀{x}{l₁ l₂} → (l₁ ⊑ l₂) → (l₁ ⊑ (x ⊰ l₂)) -- Whether a list's elements are contained in another list in order while not containing the same sublist. -- Examples: -- [1,2,3] ⊏ [1,2,3,4] -- [1,2,3] ⊏ [0,1,2,3] -- [1,2,3] ⊏ [0,1,10,2,20,3,30] data _⊏_ : List(T) → List(T) → Stmt{ℓ} where use : ∀{x}{l₁ l₂} → (l₁ ⊏ l₂) → ((x ⊰ l₁) ⊏ (x ⊰ l₂)) skip : ∀{x}{l₁ l₂} → (l₁ ⊑ l₂) → (l₁ ⊏ (x ⊰ l₂))
{ "alphanum_fraction": 0.5032258065, "avg_line_length": 32.0689655172, "ext": "agda", "hexsha": "218d967f216cae2667e55d15e48ceadbdc8fde10", "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": "Data/List/Relation/Sublist.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": "Data/List/Relation/Sublist.agda", "max_line_length": 106, "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": "Data/List/Relation/Sublist.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": 472, "size": 930 }
-- Andreas, 2018-06-30, issue #3147 reported by bafain -- Pattern linearity ignored for as-patterns -- {-# OPTIONS -v tc.lhs.top:30 #-} -- {-# OPTIONS -v tc.lhs.linear:100 #-} open import Agda.Builtin.Equality open import Agda.Builtin.Nat f : Nat → Nat f zero = zero f x@(suc x) = x -- rhs context: -- x : Nat -- x : Nat -- Should fail during lhs-checking f-id-1 : f 1 ≡ 1 f-id-1 = refl f-pre-1 : f 1 ≡ 0 f-pre-1 = refl
{ "alphanum_fraction": 0.5699152542, "avg_line_length": 20.5217391304, "ext": "agda", "hexsha": "99a78440f69b387de1855ab0b4a60006f5cf1a3b", "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/Issue3147.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/Issue3147.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/Issue3147.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": 161, "size": 472 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Literals used in the reflection machinery ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Reflection.Literal where import Data.Char as Char import Data.Float as Float import Data.Nat as ℕ open import Data.String as String using (String) import Data.Word as Word import Reflection.Meta as Meta import Reflection.Name as Name open import Relation.Nullary import Relation.Nullary.Decidable as Dec open import Relation.Binary open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Re-exporting the builtin type and constructors open import Agda.Builtin.Reflection public using ( Literal ) open Literal public ------------------------------------------------------------------------ -- Decidable equality meta-injective : ∀ {x y} → meta x ≡ meta y → x ≡ y meta-injective refl = refl nat-injective : ∀ {x y} → nat x ≡ nat y → x ≡ y nat-injective refl = refl word64-injective : ∀ {x y} → word64 x ≡ word64 y → x ≡ y word64-injective refl = refl float-injective : ∀ {x y} → float x ≡ float y → x ≡ y float-injective refl = refl char-injective : ∀ {x y} → char x ≡ char y → x ≡ y char-injective refl = refl string-injective : ∀ {x y} → string x ≡ string y → x ≡ y string-injective refl = refl name-injective : ∀ {x y} → name x ≡ name y → x ≡ y name-injective refl = refl infix 4 _≟_ _≟_ : DecidableEquality Literal nat x ≟ nat x₁ = Dec.map′ (cong nat) nat-injective (x ℕ.≟ x₁) nat x ≟ word64 x₁ = no (λ ()) nat x ≟ float x₁ = no (λ ()) nat x ≟ char x₁ = no (λ ()) nat x ≟ string x₁ = no (λ ()) nat x ≟ name x₁ = no (λ ()) nat x ≟ meta x₁ = no (λ ()) word64 x ≟ word64 x₁ = Dec.map′ (cong word64) word64-injective (x Word.≟ x₁) word64 x ≟ nat x₁ = no (λ ()) word64 x ≟ float x₁ = no (λ ()) word64 x ≟ char x₁ = no (λ ()) word64 x ≟ string x₁ = no (λ ()) word64 x ≟ name x₁ = no (λ ()) word64 x ≟ meta x₁ = no (λ ()) float x ≟ nat x₁ = no (λ ()) float x ≟ word64 x₁ = no (λ ()) float x ≟ float x₁ = Dec.map′ (cong float) float-injective (x Float.≟ x₁) float x ≟ char x₁ = no (λ ()) float x ≟ string x₁ = no (λ ()) float x ≟ name x₁ = no (λ ()) float x ≟ meta x₁ = no (λ ()) char x ≟ nat x₁ = no (λ ()) char x ≟ word64 x₁ = no (λ ()) char x ≟ float x₁ = no (λ ()) char x ≟ char x₁ = Dec.map′ (cong char) char-injective (x Char.≟ x₁) char x ≟ string x₁ = no (λ ()) char x ≟ name x₁ = no (λ ()) char x ≟ meta x₁ = no (λ ()) string x ≟ nat x₁ = no (λ ()) string x ≟ word64 x₁ = no (λ ()) string x ≟ float x₁ = no (λ ()) string x ≟ char x₁ = no (λ ()) string x ≟ string x₁ = Dec.map′ (cong string) string-injective (x String.≟ x₁) string x ≟ name x₁ = no (λ ()) string x ≟ meta x₁ = no (λ ()) name x ≟ nat x₁ = no (λ ()) name x ≟ word64 x₁ = no (λ ()) name x ≟ float x₁ = no (λ ()) name x ≟ char x₁ = no (λ ()) name x ≟ string x₁ = no (λ ()) name x ≟ name x₁ = Dec.map′ (cong name) name-injective (x Name.≟ x₁) name x ≟ meta x₁ = no (λ ()) meta x ≟ nat x₁ = no (λ ()) meta x ≟ word64 x₁ = no (λ ()) meta x ≟ float x₁ = no (λ ()) meta x ≟ char x₁ = no (λ ()) meta x ≟ string x₁ = no (λ ()) meta x ≟ name x₁ = no (λ ()) meta x ≟ meta x₁ = Dec.map′ (cong meta) meta-injective (x Meta.≟ x₁)
{ "alphanum_fraction": 0.5637563756, "avg_line_length": 31.7428571429, "ext": "agda", "hexsha": "6d7cc492e2d2b138d6ccced331d97064d6d9c3da", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Reflection/Literal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Reflection/Literal.agda", "max_line_length": 78, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Reflection/Literal.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": 1089, "size": 3333 }
{-# OPTIONS --without-K --safe #-} module Cats.Category.Cat.Facts.Initial where open import Cats.Category open import Cats.Category.Cat using (Cat) open import Cats.Category.Zero using (Zero) open import Cats.Functor Absurd : ∀ {lo la l≈ lo′ la′ l≈′} (C : Category lo′ la′ l≈′) → Functor (Zero lo la l≈) C Absurd C = record { fobj = λ() ; fmap = λ{} ; fmap-resp = λ{} ; fmap-id = λ{} ; fmap-∘ = λ{} } instance hasInitial : ∀ {lo la l≈} → HasInitial (Cat lo la l≈) hasInitial {lo} {la} {l≈} = record { ⊥ = Zero lo la l≈ ; isInitial = λ X → record { arr = Absurd X ; unique = λ x → record { iso = λ{} ; forth-natural = λ{} } } }
{ "alphanum_fraction": 0.5511363636, "avg_line_length": 21.3333333333, "ext": "agda", "hexsha": "68ee6cef0f646649f66c39ba74220c49b511b89b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z", "max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/cats", "max_forks_repo_path": "Cats/Category/Cat/Facts/Initial.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "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/cats", "max_issues_repo_path": "Cats/Category/Cat/Facts/Initial.agda", "max_line_length": 60, "max_stars_count": 24, "max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/cats", "max_stars_repo_path": "Cats/Category/Cat/Facts/Initial.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z", "num_tokens": 240, "size": 704 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Bool open import lib.types.Coproduct open import lib.types.Truncation open import lib.types.Sigma open import lib.types.Pi open import lib.types.Fin open import lib.types.Nat open import lib.types.Empty open import lib.NConnected open import lib.NType2 open import lib.Equivalence2 {- Some miscellaneous lemmas about coproducts. -} module Util.Coproducts where ⊔-fmap-is-equiv : {i j i' j' : ULevel} {A : Type i} {B : Type j} {A' : Type i'} {B' : Type j'} (f : A → A') (g : B → B') (f-eq : is-equiv f) (g-eq : is-equiv g) → is-equiv (⊔-fmap f g) ⊔-fmap-is-equiv f g f-eq g-eq = record { g = ⊔-fmap Feq.g Geq.g ; f-g = Coprod-elim (λ a → ap inl (Feq.f-g a)) λ b → ap inr (Geq.f-g b) ; g-f = Coprod-elim (λ a → ap inl (Feq.g-f a)) (λ b → ap inr (Geq.g-f b)) ; adj = Coprod-elim (λ a → ∘-ap (⊔-fmap f g) inl _ ∙ ap-∘ _ _ _ ∙ ap (ap inl) (Feq.adj a)) λ b → ∘-ap (⊔-fmap f g) _ _ ∙ ap-∘ _ _ _ ∙ ap (ap inr) (Geq.adj b) } where module Feq = is-equiv f-eq module Geq = is-equiv g-eq ⊔-emap : {i i' j j' : ULevel} {A : Type i} {A' : Type i'} {B : Type j} {B' : Type j'} (e : A ≃ A') (e' : B ≃ B') → (A ⊔ B ≃ A' ⊔ B') ⊔-emap {A = A} {A' = A'} {B = B} {B' = B'} e e' = (f , record { g = g ; f-g = f-g ; g-f = g-f ; adj = adj }) where f : A ⊔ B → A' ⊔ B' f = ⊔-fmap (–> e) (–> e') g : A' ⊔ B' → A ⊔ B g = ⊔-fmap (<– e) (<– e') f-g : (z : A' ⊔ B') → (f (g z) == z) f-g (inl x) = ap inl (<–-inv-r e x) f-g (inr x) = ap inr (<–-inv-r e' x) g-f : (z : A ⊔ B) → (g (f z) == z) g-f (inl x) = ap inl (<–-inv-l e x) g-f (inr x) = ap inr (<–-inv-l e' x) adj : (a : A ⊔ B) → ap f (g-f a) == f-g (f a) adj (inl a) = ap f (g-f (inl a)) =⟨ idp ⟩ ap f (ap inl (<–-inv-l e a)) =⟨ ∘-ap f inl _ ⟩ ap (f ∘ inl) (<–-inv-l e a) =⟨ idp ⟩ ap (inl ∘ –> e) ((<–-inv-l e a)) =⟨ ap-∘ inl (–> e) _ ⟩ ap inl (ap (–> e) (<–-inv-l e a)) =⟨ ap (ap inl) (<–-inv-adj e a) ⟩ ap inl (<–-inv-r e (–> e a)) =⟨ idp ⟩ f-g (f (inl a)) =∎ adj (inr b) = ap f (g-f (inr b)) =⟨ idp ⟩ ap f (ap inr (<–-inv-l e' b)) =⟨ ∘-ap f inr _ ⟩ ap (f ∘ inr) (<–-inv-l e' b) =⟨ idp ⟩ ap (inr ∘ –> e') ((<–-inv-l e' b)) =⟨ ap-∘ inr (–> e') _ ⟩ ap inr (ap (–> e') (<–-inv-l e' b)) =⟨ ap (ap inr) (<–-inv-adj e' b) ⟩ ap inr (<–-inv-r e' (–> e' b)) =⟨ idp ⟩ f-g (f (inr b)) =∎ ⊔-cancel-l : {i j : ULevel} {A : Type i} {B : Type j} → (A ⊔ B) → (¬ A) → B ⊔-cancel-l (inl a) na = ⊥-elim (na a) ⊔-cancel-l (inr b) _ = b ⊔-cancel-r : {i j : ULevel} {A : Type i} {B : Type j} → (A ⊔ B) → (¬ B) → A ⊔-cancel-r (inl a) _ = a ⊔-cancel-r (inr b) nb = ⊥-elim (nb b) ⊔-assoc : {i j k : ULevel} {A : Type i} {B : Type j} {C : Type k} → (A ⊔ B) ⊔ C ≃ A ⊔ B ⊔ C ⊔-assoc {A = A} {B = B} {C = C} = f , record { g = g ; f-g = f-g ; g-f = g-f ; adj = adj } where f : (A ⊔ B) ⊔ C → A ⊔ B ⊔ C f (inl (inl x)) = inl x f (inl (inr x)) = inr (inl x) f (inr x) = inr (inr x) g : A ⊔ B ⊔ C → (A ⊔ B) ⊔ C g (inl x) = inl (inl x) g (inr (inl x)) = inl (inr x) g (inr (inr x)) = inr x f-g : (z : A ⊔ B ⊔ C) → (f (g z) == z) f-g (inl x) = idp f-g (inr (inl x)) = idp f-g (inr (inr x)) = idp g-f : (z : (A ⊔ B) ⊔ C) → (g (f z) == z) g-f (inl (inl x)) = idp g-f (inl (inr x)) = idp g-f (inr x) = idp adj : (a : (A ⊔ B) ⊔ C) → ap f (g-f a) == f-g (f a) adj (inl (inl x)) = idp adj (inl (inr x)) = idp adj (inr x) = idp ⊔-sym : {i j : ULevel} {A : Type i} {B : Type j} → (A ⊔ B) ≃ (B ⊔ A) ⊔-sym = (λ {(inl a) → inr a ; (inr b) → inl b} ) , record { g = λ { (inl b) → inr b ; (inr a) → inl a} ; f-g = λ { (inl x) → idp ; (inr x) → idp} ; g-f = λ { (inl x) → idp ; (inr x) → idp} ; adj = λ { (inl x) → idp ; (inr x) → idp} }
{ "alphanum_fraction": 0.4190994557, "avg_line_length": 32.336, "ext": "agda", "hexsha": "c6bfcd33a174cee7014748e799d641714a9aa5bb", "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": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "awswan/nielsenschreier-hott", "max_forks_repo_path": "main/Util/Coproducts.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": "awswan/nielsenschreier-hott", "max_issues_repo_path": "main/Util/Coproducts.agda", "max_line_length": 108, "max_stars_count": null, "max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "awswan/nielsenschreier-hott", "max_stars_repo_path": "main/Util/Coproducts.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1967, "size": 4042 }
module left-kan-extensions where open import functor -- The left-kan extension of G along J. record left-kan (G : Set → Set) (J : Set → Set) (pG : Functor G) (pJ : Functor J) : Set₁ where field lan : Set → Set pLan : Functor lan
{ "alphanum_fraction": 0.6356275304, "avg_line_length": 20.5833333333, "ext": "agda", "hexsha": "b392384d2770461ab63c346fbac1d0ecf0a0984d", "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": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "left-kan-extensions.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "heades/AUGL", "max_issues_repo_path": "left-kan-extensions.agda", "max_line_length": 94, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "left-kan-extensions.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 78, "size": 247 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Foundations.Powerset open import Cubical.Data.Sigma open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing.Base private variable ℓ : Level module Units (R' : CommRing ℓ) where open CommRingStr (snd R') open RingTheory (CommRing→Ring R') private R = fst R' inverseUniqueness : (r : R) → isProp (Σ[ r' ∈ R ] r · r' ≡ 1r) inverseUniqueness r (r' , rr'≡1) (r'' , rr''≡1) = Σ≡Prop (λ _ → is-set _ _) path where path : r' ≡ r'' path = r' ≡⟨ sym (·Rid _) ⟩ r' · 1r ≡⟨ cong (r' ·_) (sym rr''≡1) ⟩ r' · (r · r'') ≡⟨ ·Assoc _ _ _ ⟩ (r' · r) · r'' ≡⟨ cong (_· r'') (·Comm _ _) ⟩ (r · r') · r'' ≡⟨ cong (_· r'') rr'≡1 ⟩ 1r · r'' ≡⟨ ·Lid _ ⟩ r'' ∎ Rˣ : ℙ R Rˣ r = (Σ[ r' ∈ R ] r · r' ≡ 1r) , inverseUniqueness r -- some notation using instance arguments _⁻¹ : (r : R) → ⦃ r ∈ Rˣ ⦄ → R _⁻¹ r ⦃ r∈Rˣ ⦄ = r∈Rˣ .fst infix 9 _⁻¹ -- some results about inverses ·-rinv : (r : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r · r ⁻¹ ≡ 1r ·-rinv r ⦃ r∈Rˣ ⦄ = r∈Rˣ .snd ·-linv : (r : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r ⁻¹ · r ≡ 1r ·-linv r ⦃ r∈Rˣ ⦄ = ·Comm _ _ ∙ r∈Rˣ .snd RˣMultClosed : (r r' : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ → (r · r') ∈ Rˣ RˣMultClosed r r' = (r ⁻¹ · r' ⁻¹) , path where path : r · r' · (r ⁻¹ · r' ⁻¹) ≡ 1r path = r · r' · (r ⁻¹ · r' ⁻¹) ≡⟨ cong (_· (r ⁻¹ · r' ⁻¹)) (·Comm _ _) ⟩ r' · r · (r ⁻¹ · r' ⁻¹) ≡⟨ ·Assoc _ _ _ ⟩ r' · r · r ⁻¹ · r' ⁻¹ ≡⟨ cong (_· r' ⁻¹) (sym (·Assoc _ _ _)) ⟩ r' · (r · r ⁻¹) · r' ⁻¹ ≡⟨ cong (λ x → r' · x · r' ⁻¹) (·-rinv _) ⟩ r' · 1r · r' ⁻¹ ≡⟨ cong (_· r' ⁻¹) (·Rid _) ⟩ r' · r' ⁻¹ ≡⟨ ·-rinv _ ⟩ 1r ∎ RˣContainsOne : 1r ∈ Rˣ RˣContainsOne = 1r , ·Lid _ RˣInvClosed : (r : R) ⦃ _ : r ∈ Rˣ ⦄ → r ⁻¹ ∈ Rˣ RˣInvClosed r = r , ·-linv _ UnitsAreNotZeroDivisors : (r : R) ⦃ _ : r ∈ Rˣ ⦄ → ∀ r' → r' · r ≡ 0r → r' ≡ 0r UnitsAreNotZeroDivisors r r' p = r' ≡⟨ sym (·Rid _) ⟩ r' · 1r ≡⟨ cong (r' ·_) (sym (·-rinv _)) ⟩ r' · (r · r ⁻¹) ≡⟨ ·Assoc _ _ _ ⟩ r' · r · r ⁻¹ ≡⟨ cong (_· r ⁻¹) p ⟩ 0r · r ⁻¹ ≡⟨ 0LeftAnnihilates _ ⟩ 0r ∎ -- laws keeping the instance arguments 1⁻¹≡1 : ⦃ 1∈Rˣ' : 1r ∈ Rˣ ⦄ → 1r ⁻¹ ≡ 1r 1⁻¹≡1 ⦃ 1∈Rˣ' ⦄ = (sym (·Lid _)) ∙ 1∈Rˣ' .snd ⁻¹-dist-· : (r r' : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ ⦃ rr'∈Rˣ : (r · r') ∈ Rˣ ⦄ → (r · r') ⁻¹ ≡ r ⁻¹ · r' ⁻¹ ⁻¹-dist-· r r' ⦃ r∈Rˣ ⦄ ⦃ r'∈Rˣ ⦄ ⦃ rr'∈Rˣ ⦄ = sym path ∙∙ cong (r ⁻¹ · r' ⁻¹ ·_) (rr'∈Rˣ .snd) ∙∙ (·Rid _) where path : r ⁻¹ · r' ⁻¹ · (r · r' · (r · r') ⁻¹) ≡ (r · r') ⁻¹ path = r ⁻¹ · r' ⁻¹ · (r · r' · (r · r') ⁻¹) ≡⟨ ·Assoc _ _ _ ⟩ r ⁻¹ · r' ⁻¹ · (r · r') · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · r' ⁻¹ · x · (r · r') ⁻¹) (·Comm _ _) ⟩ r ⁻¹ · r' ⁻¹ · (r' · r) · (r · r') ⁻¹ ≡⟨ cong (_· (r · r') ⁻¹) (sym (·Assoc _ _ _)) ⟩ r ⁻¹ · (r' ⁻¹ · (r' · r)) · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · x · (r · r') ⁻¹) (·Assoc _ _ _) ⟩ r ⁻¹ · (r' ⁻¹ · r' · r) · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · (x · r) · (r · r') ⁻¹) (·-linv _) ⟩ r ⁻¹ · (1r · r) · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · x · (r · r') ⁻¹) (·Lid _) ⟩ r ⁻¹ · r · (r · r') ⁻¹ ≡⟨ cong (_· (r · r') ⁻¹) (·-linv _) ⟩ 1r · (r · r') ⁻¹ ≡⟨ ·Lid _ ⟩ (r · r') ⁻¹ ∎ unitCong : {r r' : R} → r ≡ r' → ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ → r ⁻¹ ≡ r' ⁻¹ unitCong {r = r} {r' = r'} p ⦃ r∈Rˣ ⦄ ⦃ r'∈Rˣ ⦄ = PathPΣ (inverseUniqueness r' (r ⁻¹ , subst (λ x → x · r ⁻¹ ≡ 1r) p (r∈Rˣ .snd)) r'∈Rˣ) .fst ⁻¹-eq-elim : {r r' r'' : R} ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r' ≡ r'' · r → r' · r ⁻¹ ≡ r'' ⁻¹-eq-elim {r = r} {r'' = r''} p = cong (_· r ⁻¹) p ∙ sym (·Assoc _ _ _) ∙ cong (r'' ·_) (·-rinv _) ∙ ·Rid _ -- some convenient notation _ˣ : (R' : CommRing ℓ) → ℙ (R' .fst) R' ˣ = Units.Rˣ R' module CommRingHoms where open RingHoms idCommRingHom : (R : CommRing ℓ) → CommRingHom R R idCommRingHom R = idRingHom (CommRing→Ring R) compCommRingHom : (R S T : CommRing ℓ) → CommRingHom R S → CommRingHom S T → CommRingHom R T compCommRingHom R S T = compRingHom {R = CommRing→Ring R} {CommRing→Ring S} {CommRing→Ring T} compIdCommRingHom : {R S : CommRing ℓ} (f : CommRingHom R S) → compCommRingHom R R S (idCommRingHom R) f ≡ f compIdCommRingHom = compIdRingHom idCompCommRingHom : {R S : CommRing ℓ} (f : CommRingHom R S) → compCommRingHom R S S f (idCommRingHom S) ≡ f idCompCommRingHom = idCompRingHom compAssocCommRingHom : {R S T U : CommRing ℓ} (f : CommRingHom R S) (g : CommRingHom S T) (h : CommRingHom T U) → compCommRingHom R T U (compCommRingHom R S T f g) h ≡ compCommRingHom R S U f (compCommRingHom S T U g h) compAssocCommRingHom = compAssocRingHom module CommRingHomTheory {A' B' : CommRing ℓ} (φ : CommRingHom A' B') where open Units A' renaming (Rˣ to Aˣ ; _⁻¹ to _⁻¹ᵃ ; ·-rinv to ·A-rinv ; ·-linv to ·A-linv) private A = fst A' open CommRingStr (snd A') renaming (_·_ to _·A_ ; 1r to 1a) open Units B' renaming (Rˣ to Bˣ ; _⁻¹ to _⁻¹ᵇ ; ·-rinv to ·B-rinv) open CommRingStr (snd B') renaming ( _·_ to _·B_ ; 1r to 1b ; ·Lid to ·B-lid ; ·Rid to ·B-rid ; ·Assoc to ·B-assoc) private f = fst φ open IsRingHom (φ .snd) RingHomRespInv : (r : A) ⦃ r∈Aˣ : r ∈ Aˣ ⦄ → f r ∈ Bˣ RingHomRespInv r = f (r ⁻¹ᵃ) , (sym (pres· r (r ⁻¹ᵃ)) ∙∙ cong (f) (·A-rinv r) ∙∙ pres1) φ[x⁻¹]≡φ[x]⁻¹ : (r : A) ⦃ r∈Aˣ : r ∈ Aˣ ⦄ ⦃ φr∈Bˣ : f r ∈ Bˣ ⦄ → f (r ⁻¹ᵃ) ≡ (f r) ⁻¹ᵇ φ[x⁻¹]≡φ[x]⁻¹ r ⦃ r∈Aˣ ⦄ ⦃ φr∈Bˣ ⦄ = f (r ⁻¹ᵃ) ≡⟨ sym (·B-rid _) ⟩ f (r ⁻¹ᵃ) ·B 1b ≡⟨ cong (f (r ⁻¹ᵃ) ·B_) (sym (·B-rinv _)) ⟩ f (r ⁻¹ᵃ) ·B ((f r) ·B (f r) ⁻¹ᵇ) ≡⟨ ·B-assoc _ _ _ ⟩ f (r ⁻¹ᵃ) ·B (f r) ·B (f r) ⁻¹ᵇ ≡⟨ cong (_·B (f r) ⁻¹ᵇ) (sym (pres· _ _)) ⟩ f (r ⁻¹ᵃ ·A r) ·B (f r) ⁻¹ᵇ ≡⟨ cong (λ x → f x ·B (f r) ⁻¹ᵇ) (·A-linv _) ⟩ f 1a ·B (f r) ⁻¹ᵇ ≡⟨ cong (_·B (f r) ⁻¹ᵇ) (pres1) ⟩ 1b ·B (f r) ⁻¹ᵇ ≡⟨ ·B-lid _ ⟩ (f r) ⁻¹ᵇ ∎ module Exponentiation (R' : CommRing ℓ) where open CommRingStr (snd R') private R = fst R' -- introduce exponentiation _^_ : R → ℕ → R f ^ zero = 1r f ^ suc n = f · (f ^ n) infix 9 _^_ -- and prove some laws 1ⁿ≡1 : (n : ℕ) → 1r ^ n ≡ 1r 1ⁿ≡1 zero = refl 1ⁿ≡1 (suc n) = ·Lid _ ∙ 1ⁿ≡1 n ·-of-^-is-^-of-+ : (f : R) (m n : ℕ) → (f ^ m) · (f ^ n) ≡ f ^ (m +ℕ n) ·-of-^-is-^-of-+ f zero n = ·Lid _ ·-of-^-is-^-of-+ f (suc m) n = sym (·Assoc _ _ _) ∙ cong (f ·_) (·-of-^-is-^-of-+ f m n) ^-ldist-· : (f g : R) (n : ℕ) → (f · g) ^ n ≡ (f ^ n) · (g ^ n) ^-ldist-· f g zero = sym (·Lid 1r) ^-ldist-· f g (suc n) = path where path : f · g · ((f · g) ^ n) ≡ f · (f ^ n) · (g · (g ^ n)) path = f · g · ((f · g) ^ n) ≡⟨ cong (f · g ·_) (^-ldist-· f g n) ⟩ f · g · ((f ^ n) · (g ^ n)) ≡⟨ ·Assoc _ _ _ ⟩ f · g · (f ^ n) · (g ^ n) ≡⟨ cong (_· (g ^ n)) (sym (·Assoc _ _ _)) ⟩ f · (g · (f ^ n)) · (g ^ n) ≡⟨ cong (λ r → (f · r) · (g ^ n)) (·Comm _ _) ⟩ f · ((f ^ n) · g) · (g ^ n) ≡⟨ cong (_· (g ^ n)) (·Assoc _ _ _) ⟩ f · (f ^ n) · g · (g ^ n) ≡⟨ sym (·Assoc _ _ _) ⟩ f · (f ^ n) · (g · (g ^ n)) ∎ ^-rdist-·ℕ : (f : R) (n m : ℕ) → f ^ (n ·ℕ m) ≡ (f ^ n) ^ m ^-rdist-·ℕ f zero m = sym (1ⁿ≡1 m) ^-rdist-·ℕ f (suc n) m = sym (·-of-^-is-^-of-+ f m (n ·ℕ m)) ∙∙ cong (f ^ m ·_) (^-rdist-·ℕ f n m) ∙∙ sym (^-ldist-· f (f ^ n) m) -- like in Ring.Properties we provide helpful lemmas here module CommRingTheory (R' : CommRing ℓ) where open CommRingStr (snd R') private R = fst R' ·CommAssocl : (x y z : R) → x · (y · z) ≡ y · (x · z) ·CommAssocl x y z = ·Assoc x y z ∙∙ cong (_· z) (·Comm x y) ∙∙ sym (·Assoc y x z) ·CommAssocr : (x y z : R) → x · y · z ≡ x · z · y ·CommAssocr x y z = sym (·Assoc x y z) ∙∙ cong (x ·_) (·Comm y z) ∙∙ ·Assoc x z y ·CommAssocr2 : (x y z : R) → x · y · z ≡ z · y · x ·CommAssocr2 x y z = ·CommAssocr _ _ _ ∙∙ cong (_· y) (·Comm _ _) ∙∙ ·CommAssocr _ _ _ ·CommAssocSwap : (x y z w : R) → (x · y) · (z · w) ≡ (x · z) · (y · w) ·CommAssocSwap x y z w = ·Assoc (x · y) z w ∙∙ cong (_· w) (·CommAssocr x y z) ∙∙ sym (·Assoc (x · z) y w)
{ "alphanum_fraction": 0.4493664258, "avg_line_length": 38.6599190283, "ext": "agda", "hexsha": "db4cc2df9f95ef00f758d574a044d3903ecf8194", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lpw25/cubical", "max_forks_repo_path": "Cubical/Algebra/CommRing/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "lpw25/cubical", "max_issues_repo_path": "Cubical/Algebra/CommRing/Properties.agda", "max_line_length": 115, "max_stars_count": null, "max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lpw25/cubical", "max_stars_repo_path": "Cubical/Algebra/CommRing/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4665, "size": 9549 }
------------------------------------------------------------------------ -- The Agda standard library -- -- An implementation of the ring solver that requires you to manually -- pass the equation you wish to solve. ------------------------------------------------------------------------ -- You'll probably want to use `Tactic.RingSolver` instead which uses -- reflection to automatically extract the equation. {-# OPTIONS --without-K --safe #-} open import Tactic.RingSolver.Core.AlmostCommutativeRing module Tactic.RingSolver.NonReflective {ℓ₁ ℓ₂} (ring : AlmostCommutativeRing ℓ₁ ℓ₂) (let open AlmostCommutativeRing ring) where open import Algebra.Morphism open import Function open import Data.Bool.Base using (Bool; true; false; T; if_then_else_) open import Data.Maybe.Base open import Data.Empty using (⊥-elim) open import Data.Nat.Base using (ℕ) open import Data.Product open import Data.Vec hiding (_⊛_) open import Data.Vec.N-ary open import Tactic.RingSolver.Core.Polynomial.Parameters open import Tactic.RingSolver.Core.Expression public module Ops where zero-homo : ∀ x → T (is-just (0≟ x)) → 0# ≈ x zero-homo x _ with 0≟ x zero-homo x _ | just p = p zero-homo x () | nothing homo : Homomorphism ℓ₁ ℓ₂ ℓ₁ ℓ₂ homo = record { from = record { rawRing = AlmostCommutativeRing.rawRing ring ; isZero = λ x → is-just (0≟ x) } ; to = record { isAlmostCommutativeRing = record { isCommutativeSemiring = isCommutativeSemiring ; -‿cong = -‿cong ; -‿*-distribˡ = -‿*-distribˡ ; -‿+-comm = -‿+-comm } } ; morphism = -raw-almostCommutative⟶ ring ; Zero-C⟶Zero-R = zero-homo } open Eval rawRing id public open import Tactic.RingSolver.Core.Polynomial.Base (Homomorphism.from homo) norm : ∀ {n} → Expr Carrier n → Poly n norm (Κ x) = κ x norm (Ι x) = ι x norm (x ⊕ y) = norm x ⊞ norm y norm (x ⊗ y) = norm x ⊠ norm y norm (⊝ x) = ⊟ norm x norm (x ⊛ i) = norm x ⊡ i ⟦_⇓⟧ : ∀ {n} → Expr Carrier n → Vec Carrier n → Carrier ⟦ expr ⇓⟧ = ⟦ norm expr ⟧ₚ where open import Tactic.RingSolver.Core.Polynomial.Semantics homo renaming (⟦_⟧ to ⟦_⟧ₚ) correct : ∀ {n} (expr : Expr Carrier n) ρ → ⟦ expr ⇓⟧ ρ ≈ ⟦ expr ⟧ ρ correct {n = n} = go where open import Tactic.RingSolver.Core.Polynomial.Homomorphism homo go : ∀ (expr : Expr Carrier n) ρ → ⟦ expr ⇓⟧ ρ ≈ ⟦ expr ⟧ ρ go (Κ x) ρ = κ-hom x ρ go (Ι x) ρ = ι-hom x ρ go (x ⊕ y) ρ = ⊞-hom (norm x) (norm y) ρ ⟨ trans ⟩ (go x ρ ⟨ +-cong ⟩ go y ρ) go (x ⊗ y) ρ = ⊠-hom (norm x) (norm y) ρ ⟨ trans ⟩ (go x ρ ⟨ *-cong ⟩ go y ρ) go (⊝ x) ρ = ⊟-hom (norm x) ρ ⟨ trans ⟩ -‿cong (go x ρ) go (x ⊛ i) ρ = ⊡-hom (norm x) i ρ ⟨ trans ⟩ pow-cong i (go x ρ) open import Relation.Binary.Reflection setoid Ι ⟦_⟧ ⟦_⇓⟧ correct public solve : ∀ (n : ℕ) → (f : N-ary n (Expr Carrier n) (Expr Carrier n × Expr Carrier n)) → Eqʰ n _≈_ (curryⁿ (Ops.⟦_⇓⟧ (proj₁ (Ops.close n f)))) (curryⁿ (Ops.⟦_⇓⟧ (proj₂ (Ops.close n f)))) → Eq n _≈_ (curryⁿ (Ops.⟦_⟧ (proj₁ (Ops.close n f)))) (curryⁿ (Ops.⟦_⟧ (proj₂ (Ops.close n f)))) solve = Ops.solve {-# INLINE solve #-} _⊜_ : ∀ (n : ℕ) → Expr Carrier n → Expr Carrier n → Expr Carrier n × Expr Carrier n _⊜_ _ = _,_ {-# INLINE _⊜_ #-}
{ "alphanum_fraction": 0.5777448071, "avg_line_length": 33.0392156863, "ext": "agda", "hexsha": "7ffe5d3dbe4093e3dfa4b1ff49300d26fa1d39bd", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Tactic/RingSolver/NonReflective.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Tactic/RingSolver/NonReflective.agda", "max_line_length": 107, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Tactic/RingSolver/NonReflective.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": 1229, "size": 3370 }
{-# OPTIONS --allow-unsolved-metas #-} module LiteralProblem where open import OscarPrelude open import Problem open import IsLiteralProblem record LiteralProblem : Set where constructor ⟨_⟩ field {problem} : Problem isLiteralProblem : IsLiteralProblem problem open LiteralProblem public instance EqLiteralProblem : Eq LiteralProblem EqLiteralProblem = {!!} open import 𝓐ssertion instance 𝓐ssertionLiteralProblem : 𝓐ssertion LiteralProblem 𝓐ssertionLiteralProblem = record {} open import HasSatisfaction instance HasSatisfactionLiteralProblem : HasSatisfaction LiteralProblem HasSatisfaction._⊨_ HasSatisfactionLiteralProblem I 𝔓 = I ⊨ problem 𝔓 open import HasDecidableValidation instance HasDecidableValidationLiteralProblem : HasDecidableValidation LiteralProblem HasDecidableValidationLiteralProblem = {!!}
{ "alphanum_fraction": 0.8285371703, "avg_line_length": 24.5294117647, "ext": "agda", "hexsha": "5b6941126834eb1f811d6118e188fc0ed94950e4", "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/LiteralProblem.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/LiteralProblem.agda", "max_line_length": 85, "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/LiteralProblem.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 200, "size": 834 }
module LC.Subst.Var where open import Data.Nat open import Data.Nat.Properties open import Relation.Nullary -------------------------------------------------------------------------------- -- variable binding data Binding : ℕ → ℕ → Set where Free : ∀ {n x} → (n≤x : n ≤ x) → Binding n x Bound : ∀ {n x} → (n>x : n > x) → Binding n x inspectBinding : ∀ n x → Binding n x inspectBinding n x with n ≤? x ... | yes p = Free p ... | no ¬p = Bound (≰⇒> ¬p) -------------------------------------------------------------------------------- -- lifiting variables lift-var : (n i x : ℕ) → ℕ lift-var n i x with inspectBinding n x ... | Free _ = i + x -- free ... | Bound _ = x -- bound -------------------------------------------------------------------------------- -- properties of lift-var open import Relation.Binary.PropositionalEquality hiding ([_]) module EQ where open ≡-Reasoning twist : ∀ l m n → l + (m + n) ≡ m + (l + n) twist l m n = begin l + (m + n) ≡⟨ sym (+-assoc l m n) ⟩ l + m + n ≡⟨ cong (_+ n) (+-comm l m) ⟩ m + l + n ≡⟨ +-assoc m l n ⟩ m + (l + n) ∎ l+m+n≡m+x : ∀ l m n x → l + n ≡ x → l + m + n ≡ m + x l+m+n≡m+x l m n x l+n≡x = begin l + m + n ≡⟨ +-assoc l m n ⟩ l + (m + n) ≡⟨ twist l m n ⟩ m + (l + n) ≡⟨ cong (m +_) l+n≡x ⟩ m + x ∎ module INEQ where open ≤-Reasoning m+n≰x+m : ∀ {m n x} → n ≰ x → m + n > x + m m+n≰x+m {m} {n} {x} n≰x = begin suc x + m ≡⟨ +-comm (suc x) m ⟩ m + suc x ≤⟨ +-monoʳ-≤ m (≰⇒> n≰x) ⟩ m + n ∎ m+n≤x+m : ∀ {m n x} → n ≤ x → m + n ≤ x + m m+n≤x+m {m} {n} {x} n≤x = begin m + n ≤⟨ +-monoʳ-≤ m n≤x ⟩ m + x ≡⟨ +-comm m x ⟩ x + m ∎ l+n≤n+i+x : ∀ l n i x → l ≤ x → l + n ≤ n + i + x l+n≤n+i+x l n i x l≤x = begin l + n ≤⟨ +-monoˡ-≤ n l≤x ⟩ x + n ≤⟨ m≤n+m (x + n) i ⟩ i + (x + n) ≡⟨ cong (i +_) (+-comm x n) ⟩ i + (n + x) ≡⟨ sym (+-assoc i n x) ⟩ i + n + x ≡⟨ cong (_+ x) (+-comm i n) ⟩ n + i + x ∎ l+m+n≤m+x : ∀ l m n x → l + n ≤ x → l + m + n ≤ m + x l+m+n≤m+x l m n x l+n≤x = begin l + m + n ≡⟨ +-assoc l m n ⟩ l + (m + n) ≡⟨ EQ.twist l m n ⟩ m + (l + n) ≤⟨ +-monoʳ-≤ m l+n≤x ⟩ m + x ∎ l+m+n>m+x : ∀ l m n x → l + n > x → l + m + n > m + x l+m+n>m+x l m n x l+n>x = begin suc m + x ≡⟨ sym (+-suc m x) ⟩ m + suc x ≤⟨ +-monoʳ-≤ m l+n>x ⟩ m + (l + n) ≡⟨ EQ.twist m l n ⟩ l + (m + n) ≡⟨ sym (+-assoc l m n) ⟩ l + m + n ∎ l+m+n>x : ∀ l m n x → l > x → l + m + n > x l+m+n>x l m n x l>x = begin suc x ≤⟨ l>x ⟩ l ≤⟨ m≤m+n l m ⟩ l + m ≤⟨ m≤m+n (l + m) n ⟩ l + m + n ∎ open import Relation.Nullary.Negation using (contradiction) open ≡-Reasoning lift-var-≤ : ∀ {n i x} → n ≤ x → lift-var n i x ≡ i + x lift-var-≤ {n} {i} {x} n≤x with inspectBinding n x ... | Free ≤x = refl ... | Bound >x = contradiction n≤x (<⇒≱ >x) lift-var-> : ∀ {n i x} → n > x → lift-var n i x ≡ x lift-var-> {n} {i} {x} n>x with inspectBinding n x ... | Free ≤x = contradiction n>x (≤⇒≯ ≤x) ... | Bound >x = refl -- lift-var-+ : ∀ n i x m → lift-var (m + n) i (x + m) ≡ lift-var n i x + m -- lift-var-+ n i x m with inspectBinding n x -- ... | Bound >x = -- lift-var (m + n) i (x + m) -- ≡⟨ lift-var-> (INEQ.m+n≰x+m (<⇒≱ >x)) ⟩ -- x + m -- ∎ -- ... | Free ≤x = -- lift-var (m + n) i (x + m) -- ≡⟨ lift-var-≤ {m + n} {i} {x + m} (INEQ.m+n≤x+m ≤x) ⟩ -- i + (x + m) -- ≡⟨ sym (+-assoc i x m) ⟩ -- i + x + m -- ∎ -- lift-var (l + n) i -- ∙ --------------------------> ∙ -- | | -- | | -- lift-var l m lift-var l m -- | | -- ∨ ∨ -- ∙ --------------------------> ∙ -- lift-var (l + m + n) i lift-var-lift-var : ∀ l m n i x → lift-var l m (lift-var (l + n) i x) ≡ lift-var (l + m + n) i (lift-var l m x) lift-var-lift-var l m n i x with inspectBinding l x | inspectBinding (l + n) x ... | Free l≤x | Free l+n≤x = lift-var l m (i + x) ≡⟨ lift-var-≤ (≤-trans l≤x (m≤n+m x i)) ⟩ m + (i + x) ≡⟨ EQ.twist m i x ⟩ i + (m + x) ≡⟨ sym (lift-var-≤ (INEQ.l+m+n≤m+x l m n x l+n≤x)) ⟩ lift-var (l + m + n) i (m + x) ∎ ... | Free l≤x | Bound l+n>x = lift-var l m x ≡⟨ lift-var-≤ l≤x ⟩ m + x ≡⟨ sym (lift-var-> (INEQ.l+m+n>m+x l m n x l+n>x)) ⟩ lift-var (l + m + n) i (m + x) ∎ ... | Bound l>x | Free l+n≤x = contradiction (≤-trans (m≤m+n l n) l+n≤x) (<⇒≱ l>x) ... | Bound l>x | Bound l+n>x = lift-var l m x ≡⟨ lift-var-> l>x ⟩ x ≡⟨ sym (lift-var-> (INEQ.l+m+n>x l m n x l>x)) ⟩ lift-var (l + m + n) i x ∎ -- lift-var l (n + i) -- ∙ --------------------------> ∙ -- | | -- | | -- lift-var l (n + m + i) lift-var (l + n) m -- | | -- ∨ ∨ -- ∙ --------------------------> ∙ -- lift-var-lemma : ∀ l m n i x → lift-var l (n + m + i) x ≡ lift-var (l + n) m (lift-var l (n + i) x) lift-var-lemma l m n i x with inspectBinding l x ... | Free n≤x = begin n + m + i + x ≡⟨ cong (λ w → w + i + x) (+-comm n m) ⟩ m + n + i + x ≡⟨ +-assoc (m + n) i x ⟩ m + n + (i + x) ≡⟨ +-assoc m n (i + x) ⟩ m + (n + (i + x)) ≡⟨ cong (m +_) (sym (+-assoc n i x)) ⟩ m + (n + i + x) ≡⟨ sym (lift-var-≤ {l + n} {m} {n + i + x} (INEQ.l+n≤n+i+x l n i x n≤x)) ⟩ lift-var (l + n) m (n + i + x) ∎ ... | Bound n>x = begin x ≡⟨ sym (lift-var-> {l + n} {m} {x} (≤-trans n>x (m≤m+n l n))) ⟩ lift-var (l + n) m x ∎
{ "alphanum_fraction": 0.3246972252, "avg_line_length": 27.5232067511, "ext": "agda", "hexsha": "e3d5709e4c8518c988ea309bf470085347abc9ce", "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": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "banacorn/bidirectional", "max_forks_repo_path": "LC/Subst/Var.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "banacorn/bidirectional", "max_issues_repo_path": "LC/Subst/Var.agda", "max_line_length": 111, "max_stars_count": 2, "max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "banacorn/bidirectional", "max_stars_repo_path": "LC/Subst/Var.agda", "max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z", "max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z", "num_tokens": 2581, "size": 6523 }
{-# OPTIONS --without-K #-} module WithoutK4 where data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x foo : (f : {A : Set} → A → A) {A : Set} (x y : A) → x ≡ f y → f y ≡ x foo f .(f y) y refl = refl
{ "alphanum_fraction": 0.4651162791, "avg_line_length": 19.5454545455, "ext": "agda", "hexsha": "c87e556126af524a02e4514a3f67882637b61277", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/fail/WithoutK4.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/fail/WithoutK4.agda", "max_line_length": 51, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/WithoutK4.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": 94, "size": 215 }
-- {-# OPTIONS --safe #-} module Time where open import Map open import Relation.Binary.PropositionalEquality open import Data.String using (String) open import Data.Nat open import Data.Nat.Base using (_≤_) open import Data.Bool using (true ; false) open import Data.Bool.Base using (if_then_else_) open import Data.Maybe using (Maybe; just; nothing) open import Agda.Builtin.Unit open import Data.Empty open import Relation.Nullary using (¬_) open import Data.Product using (_×_) open import Data.List open import Data.Nat.Properties open import Language open import Function.Base using (_$_) max : ∀ (m n : ℕ) → ℕ max m n with (m ≤? n) ... | false Relation.Nullary.because _ = m ... | true Relation.Nullary.because _ = n taeval : (Γ : (String → ℕ)) → (Aexp {ℕ}) → ℕ taeval Γ (a +` a₁) = taeval Γ a + taeval Γ a₁ + (Γ "+") taeval Γ (a -` a₁) = taeval Γ a + taeval Γ a₁ + (Γ "-") taeval Γ (a *` a₁) = taeval Γ a + taeval Γ a₁ + (Γ "*") taeval Γ (Avar x) = 1 -- Just look up in memory assuming 1 -- clock cycle taeval Γ (Anum x) = 1 -- Just look up in mem is 1 clock cycle tbeval : (Γ : (String → ℕ)) → (Bexp {ℕ}) → ℕ tbeval Γ TRUE = Γ "TRUE" tbeval Γ FALSE = Γ "FALSE" tbeval Γ (x1 <` x2) = aeval Γ x1 + aeval Γ x2 + (Γ "<") tbeval Γ (x1 >` x2) = aeval Γ x1 + aeval Γ x2 + (Γ ">") tbeval Γ (x1 ≤` x2) = aeval Γ x1 + aeval Γ x2 + (Γ "≤") tbeval Γ (x1 ≥` x2) = aeval Γ x1 + aeval Γ x2 + (Γ "≥") tbeval Γ (x1 ≡` x2) = aeval Γ x1 + aeval Γ x2 + (Γ "≡") tbeval Γ (¬` b) = tbeval Γ b + (Γ "NOT") tbeval Γ (b &&` b₁) = tbeval Γ b + tbeval Γ b₁ + (Γ "AND") tbeval Γ (b ||` b₁) = tbeval Γ b + tbeval Γ b₁ + (Γ "OR") -- Making the tuple type needed to hold the program data TProgTuple {A : Set} : Set where _,_,_,_ : (a : ATuple) → (r : RTuple) → (c : Cmd {A}) → (cmt : ℕ) → TProgTuple -- Getting stuff from the TProgTuple getProgCmdT : {A : Set} → (p : Maybe (TProgTuple {A})) → Cmd {A} getProgCmdT (just (_ , _ , c , _)) = c getProgCmdT nothing = SKIP -- Dangerous getProgArgsT : {A : Set} → (p : Maybe (TProgTuple {A})) → ATuple getProgArgsT (just (a , _ , _ , _)) = a getProgArgsT nothing = Arg "VOID" getProgRetsT : {A : Set} → (p : Maybe (TProgTuple {A})) → RTuple getProgRetsT (just (_ , r , _ , _)) = r getProgRetsT nothing = Ret "VOID" getProgTimeT : {A : Set} → (p : Maybe (TProgTuple {A})) → ℕ getProgTimeT (just (_ , _ , _ , t)) = t getProgTimeT nothing = 0 data _,_=[_]=>ᴬ_ (Γ : (String → ℕ)) : ℕ → (ATuple) → ℕ → Set where hd : ∀ (W : ℕ) → ∀ (v : String) → Γ , W =[ Arg v ]=>ᴬ (W + (Γ "arg-copy")) tl : (l r : ATuple) → (W W' W'' : ℕ) → (Γ , W =[ l ]=>ᴬ (W + W')) → (Γ , W + W' =[ r ]=>ᴬ (W + W' + W'')) → ----------------------------------------------------------- Γ , W =[ (l ,` r) ]=>ᴬ (W + W' + W'') numargs : ∀ (args : ATuple) → ℕ numargs (Arg v) = 1 numargs (args ,` args₁) = numargs args + numargs args₁ -- soundness theorem for arg copy args-sound : ∀ (Γ : (String → ℕ)) → ∀ (args : ATuple) → (W W' : ℕ) → (Γ , W =[ args ]=>ᴬ W') → (W + numargs args * (Γ "arg-copy")) ≡ W' args-sound Γ .(Arg v) W .(W + Γ "arg-copy") (hd .W v) rewrite +-comm (Γ "arg-copy") 0 = refl args-sound Γ .(l ,` r) W .(W + W' + W'') (tl l r .W W' W'' cmd cmd₁) with (Γ "arg-copy") in eq ... | u rewrite *-distribʳ-+ u (numargs l) (numargs r) | +-comm W (((numargs l) * u) + ((numargs r) * u)) | +-comm ((numargs l) * u) ((numargs r) * u) | +-assoc ((numargs r) * u) ((numargs l) * u) W | +-comm ((numargs l) * u) W | +-comm ((numargs r) * u) (W + ((numargs l) * u)) with args-sound Γ l W (W + W') cmd ... | j with args-sound Γ r (W + W') (W + W' + W'') cmd₁ ... | k with +-cancelˡ-≡ W j | +-cancelˡ-≡ (W + W') k | eq ... | refl | refl | refl = refl data _,_=[_]=>ᴿ_ (Γ : (String → ℕ)) : ℕ → RTuple → ℕ → Set where hd : ∀ (W : ℕ) → ∀ (v : String) → Γ , W =[ Ret v ]=>ᴿ (W + (Γ "ret-copy")) tl : (l r : RTuple) → (W W' W'' : ℕ) → (Γ , W =[ l ]=>ᴿ (W + W')) → (Γ , W + W' =[ r ]=>ᴿ (W + W' + W'')) → ----------------------------------------------------------- Γ , W =[ (l ,` r) ]=>ᴿ (W + W' + W'') numrets : ∀ (rets : RTuple) → ℕ numrets (Ret v) = 1 numrets (rets ,` rets₁) = numrets rets + numrets rets₁ -- soundness theorem for ret copy rets-sound : ∀ (Γ : (String → ℕ)) → ∀ (rets : RTuple) → (W W' : ℕ) → Γ , W =[ rets ]=>ᴿ W' → (W + numrets rets * (Γ "ret-copy")) ≡ W' rets-sound Γ .(Ret v) W .(W + Γ "ret-copy") (hd .W v) rewrite +-comm (Γ "ret-copy") 0 = refl rets-sound Γ .(l ,` r) W .(W + W' + W'') (tl l r .W W' W'' cmd cmd₁) with (Γ "ret-copy") in eq ... | u rewrite *-distribʳ-+ u (numrets l) (numrets r) | +-comm W (((numrets l) * u) + ((numrets r) * u)) | +-comm ((numrets l) * u) ((numrets r) * u) | +-assoc ((numrets r) * u) ((numrets l) * u) W | +-comm ((numrets l) * u) W | +-comm ((numrets r) * u) (W + ((numrets l) * u)) with rets-sound Γ l W (W + W') cmd ... | j with rets-sound Γ r (W + W') (W + W' + W'') cmd₁ ... | k with +-cancelˡ-≡ W j | +-cancelˡ-≡ (W + W') k | eq ... | refl | refl | refl = refl mutual -- Semantics of time from here data _,_,_=[_]=>_ (Γ : (String → Maybe (TProgTuple {ℕ}))) (st : String → ℕ) : ℕ → Cmd {ℕ} → ℕ → Set where TSKIP : ∀ (W : ℕ) → Γ , st , W =[ SKIP ]=> (W + 0) TASSIGN : ∀ (X : String) → ∀ (n : ℕ) → ∀ (e : Aexp {ℕ}) → ∀ (W : ℕ) → --------------------------------- Γ , st , W =[ (Var X := e) ]=> (W + (taeval st e) + (st "store")) TSEQ : ∀ (c1 c2 : Cmd {ℕ}) → ∀ (W W' W'' : ℕ) → Γ , st , W =[ c1 ]=> (W + W') → Γ , st , (W + W') =[ c2 ]=> (W + (W' + W'')) → -------------------------------------------- Γ , st , W =[ c1 ; c2 ]=> (W + (W' + W'')) -- XXX: Hack, st contains both exec time and state! TIFT : (n1 : ℕ) → (b : Bexp {ℕ}) → (t e : Cmd {ℕ}) → ∀ (W W' W'' : ℕ) → (beval st b ≡ true) → Γ , st , W =[ t ]=> (W + W') → Γ , st , W =[ e ]=> (W + W'') → Γ , st , W =[ (IF b THEN t ELSE e END) ]=> (W + W' + (tbeval st b)) TIFE : (n1 : ℕ) → (b : Bexp {ℕ}) → (t e : Cmd {ℕ}) → ∀ (W W' W'' : ℕ) → (beval st b ≡ false) → Γ , st , W =[ t ]=> (W + W') → Γ , st , W =[ e ]=> (W + W'') → Γ , st , W =[ (IF b THEN t ELSE e END) ]=> (W + W'' + (tbeval st b)) TLF : (b : Bexp {ℕ}) → (c : Cmd {ℕ}) → beval st b ≡ false → ∀ (W : ℕ) → ----------------------------------------------------------- Γ , st , W =[ (WHILE b DO c END) ]=> (W + 0 + (tbeval st b)) TLT : (b : Bexp {ℕ}) → (c : Cmd {ℕ}) → beval st b ≡ true → ∀ (W W' : ℕ) → ----------------------------------------------------------- Γ , st , W =[ c ]=> (W + W') → Γ , st , W =[ (WHILE b DO c END) ]=> (W + ((st "loop-count") * (W' + (tbeval st b))) + (tbeval st b)) -- CEX : ∀ (f : FuncCall {ℕ}) → ∀ (st st' : (String → ℕ)) -- → Γ , st =[ f ]=>ᶠ st' -- ----------------------------------------------------------- -- → Γ , st =[ EXEC f ]=> st' data _,_,_=[_]=>ᶠ_ (Γ : String → (Maybe (TProgTuple {ℕ}))) (st : String → ℕ) : ℕ → FuncCall {ℕ} → ℕ → Set where Base : ∀ (fname : String) → -- name of the function ∀ (W W' W'' W''' : ℕ) -- time to put args on function stack → st , W =[ getProgArgsT (Γ fname) ]=>ᴬ (W + W') -- Proof that WCET is what we have in the tuple → (wcet-is : (getProgTimeT (Γ fname)) ≡ W'') -- time to run the function → Γ , st , (W + W') =[ getProgCmdT (Γ fname) ]=> (W + W' + W'') -- copying ret values back on caller' stack → st , (W + W' + W'') =[ getProgRetsT (Γ fname) ]=>ᴿ (W + W' + W'' + W''') ----------------------------------------------------------- → Γ , st , W =[ < getProgRetsT (Γ fname) >:= fname < getProgArgsT (Γ fname) > ]=>ᶠ (W + W' + W'' + W''') PAR : ∀ (l r : FuncCall {ℕ}) → ∀ (W X1 X2 : ℕ) → Γ , st , W =[ l ]=>ᶠ (W + X1) → Γ , st , W =[ r ]=>ᶠ (W + X2) ----------------------------------------------------------- → Γ , st , W =[ l ||` r ]=>ᶠ (W + (max X1 X2) + ((2 * (st "fork")) + (2 * (st "join")))) -- Soundness theorem for SKIP WCET rule skip-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) -- map of labels to execution times → ∀ (W W' X : ℕ) → (cmd : Γ , Γᵗ , W =[ SKIP ]=> W') → (W ≡ X) → (W' ≡ X) skip-sound Γ Γᵗ W .(W + 0) .W (TSKIP .W) refl rewrite +-comm W 0 = refl -- Soundness theorem for Assign WCET rule assign-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : (String → ℕ)) → (S : String) → (e : Aexp {ℕ}) → (W W' : ℕ) → (cmd : Γ , Γᵗ , W =[ Var S := e ]=> W') → (W' ≡ W + (taeval Γᵗ e) + (Γᵗ "store")) assign-sound Γ Γᵗ S e W .(W + taeval Γᵗ e + Γᵗ "store") (TASSIGN .S n .e .W) = refl -- Deterministic exec Δ-exec : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (W W' W'' : ℕ) → (c1 : Cmd {ℕ}) → (Γ , Γᵗ , W =[ c1 ]=> W') → (Γ , Γᵗ , W =[ c1 ]=> W'') → W' ≡ W'' Δ-exec Γ Γᵗ W .(W + taeval Γᵗ e + Γᵗ "store") .(W + taeval Γᵗ e + Γᵗ "store") (Var X := e) (TASSIGN .X n₁ .e .W) (TASSIGN .X n .e .W) = refl Δ-exec Γ Γᵗ W .(W + 0) .(W + 0) .SKIP (TSKIP .W) (TSKIP .W) = refl Δ-exec Γ Γᵗ W .(W + (W' + W''')) .(W + (W'' + W'''')) .(c1 ; c2) (TSEQ c1 c2 .W W' W''' p1 p3) (TSEQ .c1 .c2 .W W'' W'''' p2 p4) with Δ-exec Γ Γᵗ W (W + W') (W + W'') c1 p1 p2 ... | r with +-cancelˡ-≡ W r ... | refl with Δ-exec Γ Γᵗ (W + W') (W + (W' + W''')) (W + (W' + W'''')) c2 p3 p4 ... | rr with +-cancelˡ-≡ W rr ... | rm with +-cancelˡ-≡ W' rm ... | refl = refl Δ-exec Γ Γᵗ W .(W + 0 + tbeval Γᵗ b) .(W + 0 + tbeval Γᵗ b) WHILE b DO c END (TLF .b .c x .W) (TLF .b .c x₁ .W) = refl Δ-exec Γ Γᵗ W .(W + Γᵗ "loop-count" * (W' + tbeval Γᵗ b) + _) .(W + 0 + tbeval Γᵗ b) WHILE b DO c END (TLT .b .c x .W W' x₂) (TLF .b .c x₁ .W) = ⊥-elim (contradiction-lemma b Γᵗ x x₁) Δ-exec Γ Γᵗ W .(W + 0 + tbeval Γᵗ b) .(W + Γᵗ "loop-count" * (W'' + tbeval Γᵗ b) + _) WHILE b DO c END (TLF .b .c x .W) (TLT .b .c x₁ .W W'' x₂) = ⊥-elim (contradiction-lemma b Γᵗ x₁ x) Δ-exec Γ Γᵗ W .(W + Γᵗ "loop-count" * (W' + tbeval Γᵗ b) + _) .(W + Γᵗ "loop-count" * (W'' + tbeval Γᵗ b) + _) WHILE b DO c END (TLT .b .c x .W W' x₃) (TLT .b .c x₁ .W W'' x₂) with Δ-exec Γ Γᵗ W (W + W') (W + W'') c x₃ x₂ ... | l with +-cancelˡ-≡ W l ... | refl = refl Δ-exec Γ Γᵗ W .(W + W' + tbeval Γᵗ b) .(W + W'' + tbeval Γᵗ b) IF b THEN t ELSE e END (TIFT n2 .b .t .e .W W' W'''' x x₄ x₅) (TIFT n1 .b .t .e .W W'' W''' x₁ x₂ x₃) with Δ-exec Γ Γᵗ W (W + W') (W + W'') t x₄ x₂ ... | y with +-cancelˡ-≡ W y ... | refl = refl Δ-exec Γ Γᵗ W .(W + W'''' + tbeval Γᵗ b) .(W + W'' + tbeval Γᵗ b) IF b THEN t ELSE e END (TIFE n2 .b .t .e .W W' W'''' x x₄ x₅) (TIFT n1 .b .t .e .W W'' W''' x₁ x₂ x₃) = ⊥-elim (contradiction-lemma b Γᵗ x₁ x) Δ-exec Γ Γᵗ W .(W + W' + tbeval Γᵗ b) .(W + W''' + tbeval Γᵗ b) IF b THEN t ELSE e END (TIFT n2 .b .t .e .W W' W'''' x x₄ x₅) (TIFE n1 .b .t .e .W W'' W''' x₁ x₂ x₃) = ⊥-elim (contradiction-lemma b Γᵗ x x₁) Δ-exec Γ Γᵗ W .(W + W'''' + tbeval Γᵗ b) .(W + W''' + tbeval Γᵗ b) IF b THEN t ELSE e END (TIFE n2 .b .t .e .W W' W'''' x x₄ x₅) (TIFE n1 .b .t .e .W W'' W''' x₁ x₂ x₃) with Δ-exec Γ Γᵗ W (W + W''') (W + W'''') e x₃ x₅ ... | y with +-cancelˡ-≡ W y ... | refl = refl -- Deterministic execution of a function Δ-exec-func : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → (l : FuncCall {ℕ}) → (W W' W'' : ℕ) → Γ , Γᵗ , W =[ l ]=>ᶠ W' → Γ , Γᵗ , W =[ l ]=>ᶠ W'' → W' ≡ W'' Δ-exec-func Γ Γᵗ .(< getProgRetsT (Γ fname) >:= fname < getProgArgsT (Γ fname) >) W .(W + W' + getProgTimeT (Γ fname) + W'''') .(W + W'' + getProgTimeT (Γ fname) + W'''''') (Base fname .W W' .(getProgTimeT (Γ fname)) W'''' x refl x₁ x₂) (Base .fname .W W'' .(getProgTimeT (Γ fname)) W'''''' x₃ refl x₄ x₅) with args-sound Γᵗ (getProgArgsT (Γ fname)) W (W + W') x | args-sound Γᵗ (getProgArgsT (Γ fname)) W (W + W'') x₃ | rets-sound Γᵗ (getProgRetsT (Γ fname)) (W + W' + getProgTimeT (Γ fname)) (W + W' + getProgTimeT (Γ fname) + W'''') x₂ | rets-sound Γᵗ (getProgRetsT (Γ fname)) (W + W'' + getProgTimeT (Γ fname)) (W + W'' + getProgTimeT (Γ fname) + W'''''') x₅ ... | l | l1 | r1 | r2 with +-cancelˡ-≡ W l | +-cancelˡ-≡ W l1 ... | refl | refl with +-cancelˡ-≡ (W + numargs (getProgArgsT (Γ fname)) * Γᵗ "arg-copy" + getProgTimeT (Γ fname)) r2 ... | refl with +-cancelˡ-≡ (W + numargs (getProgArgsT (Γ fname)) * Γᵗ "arg-copy" + getProgTimeT (Γ fname)) r1 ... | refl = refl Δ-exec-func Γ Γᵗ .(l ||` r) W .(W + max X1 X2 + (2 * Γᵗ "fork" + 2 * Γᵗ "join")) .(W + max X3 X4 + (2 * Γᵗ "fork" + 2 * Γᵗ "join")) (PAR l r .W X1 X2 e1 e3) (PAR .l .r .W X3 X4 e2 e4) with Δ-exec-func Γ Γᵗ l W (W + X1) (W + X3) e1 e2 | Δ-exec-func Γ Γᵗ r W (W + X2) (W + X4) e3 e4 ... | m | y with +-cancelˡ-≡ W m | +-cancelˡ-≡ W y ... | refl | refl = refl skip-cancel : ∀ (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (W1 W2 X1 X2 : ℕ) → (Γ , Γᵗ , W1 =[ SKIP ]=> (W1 + X1)) → (Γ , Γᵗ , W2 =[ SKIP ]=> (W2 + X2)) → X1 ≡ X2 skip-cancel Γ Γᵗ W1 W2 X1 X2 p1 p2 with (W1 + X1) in eq1 skip-cancel Γ Γᵗ W1 W2 X1 X2 (TSKIP .W1) p2 | .(W1 + 0) with +-cancelˡ-≡ W1 eq1 skip-cancel Γ Γᵗ W1 W2 X1 X2 (TSKIP .W1) p2 | .(W1 + 0) | refl with (W2 + X2) in eq2 skip-cancel Γ Γᵗ W1 W2 _ X2 (TSKIP .W1) (TSKIP .W2) | .(W1 + _) | refl | .(W2 + 0) with +-cancelˡ-≡ W2 eq2 ... | refl = refl assign-cancel : ∀ (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (W1 W2 X1 X2 : ℕ) → (S : String) → (e : Aexp {ℕ}) → (Γ , Γᵗ , W1 =[ Var S := e ]=> (W1 + X1)) → (Γ , Γᵗ , W2 =[ Var S := e ]=> (W2 + X2)) → X1 ≡ X2 assign-cancel Γ Γᵗ W1 W2 X1 X2 S e cmd1 cmd2 with (W1 + X1) in eq1 | (W2 + X2) in eq2 assign-cancel Γ Γᵗ W1 W2 X1 X2 S e (TASSIGN .S n .e .W1) (TASSIGN .S n₁ .e .W2) | .(W1 + taeval Γᵗ e + Γᵗ "store") | .(W2 + taeval Γᵗ e + Γᵗ "store") rewrite +-assoc W1 (taeval Γᵗ e) (Γᵗ "store") | +-assoc W2 (taeval Γᵗ e) (Γᵗ "store") with +-cancelˡ-≡ W1 eq1 | +-cancelˡ-≡ W2 eq2 ... | refl | refl = refl loop-cancel : ∀ (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (W1 W2 X1 X2 : ℕ) → (b : Bexp {ℕ}) → (c : Cmd {ℕ}) → (Γ , Γᵗ , W1 =[ (WHILE b DO c END) ]=> (W1 + X1)) → (Γ , Γᵗ , W2 =[ (WHILE b DO c END) ]=> (W2 + X2)) → X1 ≡ X2 ife-cancel : ∀ (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (W1 W2 X1 X2 : ℕ) → (b : Bexp {ℕ}) → (t e : Cmd {ℕ}) → (Γ , Γᵗ , W1 =[ ( IF b THEN t ELSE e END ) ]=> (W1 + X1)) → (Γ , Γᵗ , W2 =[ ( IF b THEN t ELSE e END ) ]=> (W2 + X2)) → X1 ≡ X2 seq-cancel : ∀ (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (W1 W2 X1 X2 : ℕ) → (c1 c2 : Cmd {ℕ}) → (Γ , Γᵗ , W1 =[ ( c1 ; c2) ]=> (W1 + X1)) → (Γ , Γᵗ , W2 =[ ( c1 ; c2) ]=> (W2 + X2)) → X1 ≡ X2 -- The general case of cancellation. eq-cancel : ∀ (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → ∀ (c : Cmd {ℕ}) → ∀ (W1 W2 X1 X2 : ℕ) → (Γ , Γᵗ , W1 =[ c ]=> (W1 + X1)) → (Γ , Γᵗ , W2 =[ c ]=> (W2 + X2)) → X1 ≡ X2 loop-cancel Γ Γᵗ W1 W2 X1 X2 b c cmd1 cmd2 with (W1 + X1) in eq1 | (W2 + X2) in eq2 loop-cancel Γ Γᵗ W1 W2 X1 X2 b c (TLF .b .c x .W1) (TLF .b .c x₁ .W2) | .(W1 + 0 + tbeval Γᵗ b) | .(W2 + 0 + tbeval Γᵗ b) rewrite +-assoc W1 0 (tbeval Γᵗ b) | +-assoc W2 0 (tbeval Γᵗ b) with +-cancelˡ-≡ W1 eq1 | +-cancelˡ-≡ W2 eq2 ... | refl | refl = refl loop-cancel Γ Γᵗ W1 W2 X1 X2 b c (TLF .b .c x .W1) (TLT .b .c x₁ .W2 W' cmd2) | .(W1 + 0 + tbeval Γᵗ b) | .(W2 + Γᵗ "loop-count" * (W' + tbeval Γᵗ b) + tbeval Γᵗ b) = ⊥-elim (contradiction-lemma b Γᵗ x₁ x) loop-cancel Γ Γᵗ W1 W2 X1 X2 b c (TLT .b .c x .W1 W' cmd1) (TLF .b .c x₁ .W2) | .(W1 + Γᵗ "loop-count" * (W' + tbeval Γᵗ b) + tbeval Γᵗ b) | .(W2 + 0 + tbeval Γᵗ b) = ⊥-elim (contradiction-lemma b Γᵗ x x₁) loop-cancel Γ Γᵗ W1 W2 X1 X2 b c (TLT .b .c x .W1 W' cmd1) (TLT .b .c x₁ .W2 W'' cmd2) | .(W1 + Γᵗ "loop-count" * (W' + tbeval Γᵗ b) + tbeval Γᵗ b) | .(W2 + Γᵗ "loop-count" * (W'' + tbeval Γᵗ b) + tbeval Γᵗ b) with eq-cancel Γ Γᵗ c W1 W2 W' W'' cmd1 cmd2 ... | refl with (Γᵗ "loop-count") | (tbeval Γᵗ b) ... | LC | BC rewrite +-assoc W2 (LC * (W' + BC)) BC | +-assoc W1 (LC * (W' + BC)) BC with +-cancelˡ-≡ W2 eq2 | +-cancelˡ-≡ W1 eq1 ... | refl | refl = refl ife-cancel Γ Γᵗ W1 W2 X1 X2 b t e p1 p2 with (W1 + X1) in eq1 | (W2 + X2) in eq2 ife-cancel Γ Γᵗ W1 W2 X1 X2 b t e (TIFT n1 .b .t .e .W1 W' W'' x p1 p3) (TIFT n2 .b .t .e .W2 W''' W'''' x₁ p2 p4) | .(W1 + W' + tbeval Γᵗ b) | .(W2 + W''' + tbeval Γᵗ b) with eq-cancel Γ Γᵗ t W1 W2 W' W''' p1 p2 ... | refl rewrite +-assoc W2 W' (tbeval Γᵗ b) | +-assoc W1 W' (tbeval Γᵗ b) with +-cancelˡ-≡ W2 eq2 | +-cancelˡ-≡ W1 eq1 ... | refl | refl = refl ife-cancel Γ Γᵗ W1 W2 X1 X2 b t e (TIFT n1 .b .t .e .W1 W' W'' x p1 p3) (TIFE n2 .b .t .e .W2 W''' W'''' x₁ p2 p4) | .(W1 + W' + tbeval Γᵗ b) | .(W2 + W'''' + tbeval Γᵗ b) = ⊥-elim (contradiction-lemma b Γᵗ x x₁) ife-cancel Γ Γᵗ W1 W2 X1 X2 b t e (TIFE n1 .b .t .e .W1 W' W'' x p1 p3) (TIFT n2 .b .t .e .W2 W''' W'''' x₁ p2 p4) | .(W1 + W'' + tbeval Γᵗ b) | .(W2 + W''' + tbeval Γᵗ b) = ⊥-elim (contradiction-lemma b Γᵗ x₁ x) ife-cancel Γ Γᵗ W1 W2 X1 X2 b t e (TIFE n1 .b .t .e .W1 W' W'' x p1 p3) (TIFE n2 .b .t .e .W2 W''' W'''' x₁ p2 p4) | .(W1 + W'' + tbeval Γᵗ b) | .(W2 + W'''' + tbeval Γᵗ b) rewrite +-assoc W1 W'' (tbeval Γᵗ b) | +-assoc W2 W'''' (tbeval Γᵗ b) with +-cancelˡ-≡ W2 eq2 | +-cancelˡ-≡ W1 eq1 | eq-cancel Γ Γᵗ e W1 W2 W'' W'''' p3 p4 ... | refl | refl | refl = refl seq-cancel Γ Γᵗ W1 W2 X1 X2 c1 c2 p1 p2 with (W1 + X1) in eq1 | (W2 + X2) in eq2 seq-cancel Γ Γᵗ W1 W2 X1 X2 c1 c2 (TSEQ .c1 .c2 .W1 W' W'' p1 p3) (TSEQ .c1 .c2 .W2 W''' W'''' p2 p4) | .(W1 + (W' + W'')) | .(W2 + (W''' + W'''')) rewrite +-cancelˡ-≡ W1 eq1 | +-cancelˡ-≡ W2 eq2 with eq-cancel Γ Γᵗ c1 W1 W2 W' W''' p1 p2 ... | refl rewrite +-comm W''' W'' | +-comm W1 (W'' + W''') | +-assoc W'' W''' W1 | +-comm W''' W1 | +-comm W'' (W1 + W''') | +-comm W''' W'''' | +-comm W2 (W'''' + W''') | +-assoc W'''' W''' W2 | +-comm W''' W2 | +-comm W'''' (W2 + W''') with (W1 + W''') | (W2 + W''') ... | l | m with eq-cancel Γ Γᵗ c2 l m W'' W'''' p3 p4 ... | refl = refl eq-cancel Γ Γᵗ SKIP W1 W2 X1 X2 p1 p2 = skip-cancel Γ Γᵗ W1 W2 X1 X2 p1 p2 eq-cancel Γ Γᵗ (Var x := r) W1 W2 X1 X2 p1 p2 = assign-cancel Γ Γᵗ W1 W2 X1 X2 x r p1 p2 eq-cancel Γ Γᵗ (c ; c₁) W1 W2 X1 X2 p1 p2 = seq-cancel Γ Γᵗ W1 W2 X1 X2 c c₁ p1 p2 eq-cancel Γ Γᵗ IF b THEN c ELSE c₁ END W1 W2 X1 X2 p1 p2 = ife-cancel Γ Γᵗ W1 W2 X1 X2 b c c₁ p1 p2 eq-cancel Γ Γᵗ WHILE b DO c END W1 W2 X1 X2 p1 p2 = loop-cancel Γ Γᵗ W1 W2 X1 X2 b c p1 p2 -- TODO: The function call case and concurrency cases will go here -- Soundness theorem for Seq WCET rule seq-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → (c1 c2 : Cmd {ℕ}) → (W X1 X2 W' : ℕ) → (cmd : Γ , Γᵗ , W =[ c1 ; c2 ]=> W') → (p1 : Γ , Γᵗ , W =[ c1 ]=> (W + X1)) → (p2 : Γ , Γᵗ , W =[ c2 ]=> (W + X2)) → (W' ≡ W + (X1 + X2)) seq-sound Γ Γᵗ c1 c2 W X1 X2 .(W + (W' + W'')) (TSEQ .c1 .c2 .W W' W'' cmd cmd₁) p1 p2 with Δ-exec Γ Γᵗ W (W + W') (W + X1) c1 cmd p1 ... | q with +-cancelˡ-≡ W q ... | refl rewrite +-comm W (X1 + W'') | +-comm X1 W'' | +-assoc W'' X1 W | +-comm X1 W | +-comm W'' (W + X1) | +-comm X1 X2 | +-comm W (X2 + X1) | +-assoc X2 X1 W | +-comm X2 (X1 + W) | +-comm X1 W with (W + X1) ... | rl with eq-cancel Γ Γᵗ c2 rl W W'' X2 cmd₁ p2 ... | refl = refl -- Helping lemma for ife plus-≤ : ∀ (m n p : ℕ) → (m ≤ n) → (m + p) ≤ (n + p) plus-≤ .zero n p z≤n = m≤n+m p n plus-≤ .(suc _) .(suc _) p (s≤s {m} {n} q) with plus-≤ m n p q ... | H0 = s≤s H0 ≤-rela1 : ∀ (m n : ℕ) → ¬ (m ≤ n) → (n < m) ≤-rela1 zero n p = ⊥-elim (p z≤n) ≤-rela1 (suc m) zero p = s≤s z≤n ≤-rela1 (suc m) (suc n) p = s≤s (≤-rela1 m n (λ z → p (s≤s z))) ≤-rela2 : ∀ (m n : ℕ) → (suc n ≤ m) → (n ≤ m) ≤-rela2 m n p with n≤1+n n ... | q = ≤-trans q p -- if-helper if-helper : ∀ (X1 X2 : ℕ) → (X1 ≤ max X1 X2) if-helper X1 X2 with (X1 ≤? X2) ... | false Relation.Nullary.because proof = ≤′⇒≤ ≤′-refl ... | true Relation.Nullary.because Relation.Nullary.ofʸ p = p if-helper2 : ∀ (X1 X2 : ℕ) → (X2 ≤ max X1 X2) if-helper2 X1 X2 with (X1 ≤? X2) if-helper2 X1 X2 | false Relation.Nullary.because Relation.Nullary.ofⁿ ¬p with ≤-rela1 X1 X2 (¬p) ... | q = ≤-rela2 X1 X2 q if-helper2 X1 X2 | true Relation.Nullary.because _ = ≤′⇒≤ ≤′-refl -- Soundness theorem for If-else WCET rule ife-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → (t e : Cmd {ℕ}) → (b : Bexp {ℕ}) → (W X1 X2 W' : ℕ) → (tcmd : Γ , Γᵗ , W =[ t ]=> (W + X1)) → (ecmd : Γ , Γᵗ , W =[ e ]=> (W + X2)) → (cmd : Γ , Γᵗ , W =[ (IF b THEN t ELSE e END) ]=> W') → (W' ≤ W + (max X1 X2) + (tbeval Γᵗ b)) ife-sound Γ Γᵗ t e b W X1 X2 .(W + W' + tbeval Γᵗ b) tcmd ecmd (TIFT n1 .b .t .e .W W' W'' x cmd cmd₁) with Δ-exec Γ Γᵗ W (W + W') (W + X1) t cmd tcmd ... | l with +-cancelˡ-≡ W l ... | refl rewrite +-assoc W X1 (tbeval Γᵗ b) | +-comm W (X1 + (tbeval Γᵗ b)) | +-assoc X1 (tbeval Γᵗ b) W with (tbeval Γᵗ b) ... | Y with max X1 X2 in eq ... | M rewrite +-assoc W M Y | +-comm W (M + Y) | +-assoc M Y W with (Y + W) ... | L with if-helper X1 X2 | eq ... | T | refl = plus-≤ X1 M L T ife-sound Γ Γᵗ t e b W X1 X2 .(W + W'' + tbeval Γᵗ b) tcmd ecmd (TIFE n1 .b .t .e .W W' W'' x cmd cmd₁) with (tbeval Γᵗ b) | Δ-exec Γ Γᵗ W (W + W'') (W + X2) e cmd₁ ecmd ... | Y | l with +-cancelˡ-≡ W l ... | refl with max X1 X2 in eq ... | M rewrite +-assoc W X2 Y | +-assoc W M Y | +-comm W (X2 + Y) | +-comm W (M + Y) | +-assoc X2 Y W | +-assoc M Y W with (Y + W) ... | L with if-helper2 X1 X2 | eq ... | T | refl = plus-≤ X2 M L T -- Helper for loop loop-helper : ∀ (l g : ℕ) → (l ≤′ (g + l)) loop-helper l zero = ≤′-refl loop-helper l (suc g) = ≤′-step (loop-helper l g) -- XXX: Using well founded recursion here loop-sound-≤′ : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → (c : Cmd {ℕ}) → (b : Bexp {ℕ}) → (W W' X1 : ℕ) → (Γ , Γᵗ , W =[ c ]=> (W + X1)) → (cmd : Γ , Γᵗ , W =[ (WHILE b DO c END) ]=> W') → W' ≤′ W + ((Γᵗ "loop-count") * (X1 + (tbeval Γᵗ b))) + (tbeval Γᵗ b) loop-sound-≤′ Γ Γᵗ c b W .(W + 0 + tbeval Γᵗ b) X1 cmd (TLF .b .c x .W) with (Γᵗ "loop-count") ... | zero = ≤′-refl ... | suc m rewrite +-comm W 0 with (tbeval Γᵗ b) ... | q with (X1 + q + m * (X1 + q)) ... | t rewrite +-comm W t | +-assoc t W q with (W + q) ... | l = loop-helper l t loop-sound-≤′ Γ Γᵗ c b W .(W + Γᵗ "loop-count" * (W' + tbeval Γᵗ b) + tbeval Γᵗ b) X1 cmd (TLT .b .c x .W W' cmd1) with Δ-exec Γ Γᵗ W (W + W') (W + X1) c cmd1 cmd ... | r with +-cancelˡ-≡ W r ... | refl = ≤′-refl -- The general case loop-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → (Γᵗ : String → ℕ) → (c : Cmd {ℕ}) → (b : Bexp {ℕ}) → (W W' X1 : ℕ) → (Γ , Γᵗ , W =[ c ]=> (W + X1)) → (cmd : Γ , Γᵗ , W =[ (WHILE b DO c END) ]=> W') → W' ≤ W + ((Γᵗ "loop-count") * (X1 + (tbeval Γᵗ b))) + (tbeval Γᵗ b) loop-sound Γ Γᵗ c b W W' X1 c2 cmd = ≤′⇒≤ (loop-sound-≤′ Γ Γᵗ c b W W' X1 c2 cmd) -- The soundness theorem for a single function call func-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → ∀ (Γᵗ : String → ℕ) → ∀ (fname : String) → ∀ (W W' : ℕ) → Γ , Γᵗ , W =[ < getProgRetsT (Γ fname) >:= fname < getProgArgsT (Γ fname) > ]=>ᶠ W' → W' ≡ (W + ((numargs $ getProgArgsT $ (Γ fname)) * (Γᵗ "arg-copy")) + (getProgTimeT (Γ fname)) + ((numrets $ getProgRetsT $ (Γ fname)) * (Γᵗ "ret-copy"))) func-sound Γ Γᵗ fname W .(W + W' + getProgTimeT (Γ fname) + W''') (Base .fname .W W' .(getProgTimeT (Γ fname)) W''' x refl x₁ x₂) with args-sound Γᵗ (getProgArgsT (Γ fname)) W (W + W') x | rets-sound Γᵗ (getProgRetsT (Γ fname)) (W + W' + getProgTimeT (Γ fname)) (W + W' + getProgTimeT (Γ fname) + W''') x₂ ... | l | m with +-cancelˡ-≡ W l ... | refl with +-cancelˡ-≡ (W + numargs (getProgArgsT (Γ fname)) * Γᵗ "arg-copy" + getProgTimeT (Γ fname)) m ... | refl = refl -- The soundness theorem for PAR (||`) execution of threads par-sound : (Γ : String → Maybe (TProgTuple {ℕ})) → ∀ (Γᵗ : String → ℕ) → (l r : FuncCall {ℕ}) → (W W' X1 X2 : ℕ) → Γ , Γᵗ , W =[ l ||` r ]=>ᶠ W' → Γ , Γᵗ , W =[ l ]=>ᶠ (W + X1) → Γ , Γᵗ , W =[ r ]=>ᶠ (W + X2) → W' ≡ W + (max X1 X2) + 2 * ((Γᵗ "fork") + (Γᵗ "join")) par-sound Γ Γᵗ l r W .(W + max X3 X4 + (2 * Γᵗ "fork" + 2 * Γᵗ "join")) X1 X2 (PAR .l .r .W X3 X4 pare pare₁) parl parr with (Γᵗ "fork") | (Γᵗ "join") ... | tf | tj rewrite *-distribˡ-+ 2 tf tj | +-assoc tf tj 0 | +-comm tj 0 | +-comm tf 0 | +-assoc tf tj (tf + tj) | +-comm tj (tf + tj) | +-assoc tf tj tj | +-comm tf (tf + (tj + tj)) | +-comm tf (tj + tj) with (tf + tf + (tj + tj)) ... | m with Δ-exec-func Γ Γᵗ l W (W + X1) (W + X3) parl pare ... | q with Δ-exec-func Γ Γᵗ r W (W + X2) (W + X4) parr pare₁ ... | q2 with +-cancelˡ-≡ W q | +-cancelˡ-≡ W q2 ... | refl | refl = refl
{ "alphanum_fraction": 0.4580715549, "avg_line_length": 41.3390357698, "ext": "agda", "hexsha": "89a79dd1c2738638cacabd05d09f0313bbae507e", "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": "bff8c271b54f55ceac550c603e468f68838a07ee", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "amal029/compositional-real-time-contracts", "max_forks_repo_path": "Time.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "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": "amal029/compositional-real-time-contracts", "max_issues_repo_path": "Time.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "amal029/compositional-real-time-contracts", "max_stars_repo_path": "Time.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 12032, "size": 26581 }
{-# OPTIONS --safe #-} module Cubical.Algebra.Lattice.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.Semilattice open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open import Cubical.Reflection.RecordEquiv open Iso private variable ℓ ℓ' : Level record IsLattice {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) : Type ℓ where constructor islattice field joinSemilattice : IsSemilattice 0l _∨l_ meetSemilattice : IsSemilattice 1l _∧l_ absorb : (x y : L) → (x ∨l (x ∧l y) ≡ x) × (x ∧l (x ∨l y) ≡ x) open IsSemilattice joinSemilattice public renaming ( assoc to ∨lAssoc ; identity to ∨lIdentity ; lid to ∨lLid ; rid to ∨lRid ; comm to ∨lComm ; idem to ∨lIdem ; isCommMonoid to ∨lIsCommMonoid ; isMonoid to ∨lIsMonoid ; isSemigroup to ∨lIsSemigroup ) open IsSemilattice meetSemilattice public renaming ( assoc to ∧lAssoc ; identity to ∧lIdentity ; lid to ∧lLid ; rid to ∧lRid ; comm to ∧lComm ; idem to ∧lIdem ; isCommMonoid to ∧lIsCommMonoid ; isMonoid to ∧lIsMonoid ; isSemigroup to ∧lIsSemigroup ) hiding ( is-set ) ∨lAbsorb∧l : (x y : L) → x ∨l (x ∧l y) ≡ x ∨lAbsorb∧l x y = absorb x y .fst ∧lAbsorb∨l : (x y : L) → x ∧l (x ∨l y) ≡ x ∧lAbsorb∨l x y = absorb x y .snd record LatticeStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor latticestr field 0l : A 1l : A _∨l_ : A → A → A _∧l_ : A → A → A isLattice : IsLattice 0l 1l _∨l_ _∧l_ infix 7 _∨l_ infix 6 _∧l_ open IsLattice isLattice public Lattice : ∀ ℓ → Type (ℓ-suc ℓ) Lattice ℓ = TypeWithStr ℓ LatticeStr isSetLattice : (L : Lattice ℓ) → isSet ⟨ L ⟩ isSetLattice L = L .snd .LatticeStr.is-set makeIsLattice : {L : Type ℓ} {0l 1l : L} {_∨l_ _∧l_ : L → L → L} (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-lid : (x : L) → 0l ∨l x ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-lid : (x : L) → 1l ∧l x ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) → IsLattice 0l 1l _∨l_ _∧l_ makeIsLattice {0l = 0l} {1l = 1l} {_∨l_ = _∨l_} {_∧l_ = _∧l_} is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l = islattice (makeIsSemilattice is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∨l-idem) (makeIsSemilattice is-setL ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∧l-idem) λ x y → ∨l-absorb-∧l x y , ∧l-absorb-∨l x y where ∨l-idem : ∀ x → x ∨l x ≡ x ∨l-idem x = cong (x ∨l_) (sym (∧l-rid _)) ∙ ∨l-absorb-∧l _ _ ∧l-idem : ∀ x → x ∧l x ≡ x ∧l-idem x = cong (x ∧l_) (sym (∨l-rid _)) ∙ ∧l-absorb-∨l _ _ makeLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-lid : (x : L) → 0l ∨l x ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∨l-idem : (x : L) → x ∨l x ≡ x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-lid : (x : L) → 1l ∧l x ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∧l-idem : (x : L) → x ∧l x ≡ x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) → Lattice ℓ makeLattice 0l 1l _∨l_ _∧l_ is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∨l-idem ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∧l-idem ∨l-absorb-∧l ∧l-absorb-∨l = _ , latticestr 0l 1l _∨l_ _∧l_ (makeIsLattice is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l) record IsLatticeHom {A : Type ℓ} {B : Type ℓ'} (L : LatticeStr A) (f : A → B) (M : LatticeStr B) : Type (ℓ-max ℓ ℓ') where -- Shorter qualified names private module L = LatticeStr L module M = LatticeStr M field pres0 : f L.0l ≡ M.0l pres1 : f L.1l ≡ M.1l pres∨l : (x y : A) → f (x L.∨l y) ≡ f x M.∨l f y pres∧l : (x y : A) → f (x L.∧l y) ≡ f x M.∧l f y unquoteDecl IsLatticeHomIsoΣ = declareRecordIsoΣ IsLatticeHomIsoΣ (quote IsLatticeHom) LatticeHom : (L : Lattice ℓ) (M : Lattice ℓ') → Type (ℓ-max ℓ ℓ') LatticeHom L M = Σ[ f ∈ (⟨ L ⟩ → ⟨ M ⟩) ] IsLatticeHom (L .snd) f (M .snd) IsLatticeEquiv : {A : Type ℓ} {B : Type ℓ'} (M : LatticeStr A) (e : A ≃ B) (N : LatticeStr B) → Type (ℓ-max ℓ ℓ') IsLatticeEquiv M e N = IsLatticeHom M (e .fst) N LatticeEquiv : (L : Lattice ℓ) (M : Lattice ℓ') → Type (ℓ-max ℓ ℓ') LatticeEquiv L M = Σ[ e ∈ (⟨ L ⟩ ≃ ⟨ M ⟩) ] IsLatticeEquiv (L .snd) e (M .snd) isPropIsLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) → isProp (IsLattice 0l 1l _∨l_ _∧l_) isPropIsLattice 0l 1l _∨l_ _∧l_ (islattice LJ LM LA) (islattice MJ MM MA) = λ i → islattice (isPropIsSemilattice _ _ LJ MJ i) (isPropIsSemilattice _ _ LM MM i) (isPropAbsorb LA MA i) where isSetL : isSet _ isSetL = LJ .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set isPropAbsorb : isProp ((x y : _) → (x ∨l (x ∧l y) ≡ x) × (x ∧l (x ∨l y) ≡ x)) isPropAbsorb = isPropΠ2 λ _ _ → isProp× (isSetL _ _) (isSetL _ _) isPropIsLatticeHom : {A : Type ℓ} {B : Type ℓ'} (R : LatticeStr A) (f : A → B) (S : LatticeStr B) → isProp (IsLatticeHom R f S) isPropIsLatticeHom R f S = isOfHLevelRetractFromIso 1 IsLatticeHomIsoΣ (isProp×3 (isSetLattice (_ , S) _ _) (isSetLattice (_ , S) _ _) (isPropΠ2 λ _ _ → isSetLattice (_ , S) _ _) (isPropΠ2 λ _ _ → isSetLattice (_ , S) _ _)) 𝒮ᴰ-Lattice : DUARel (𝒮-Univ ℓ) LatticeStr ℓ 𝒮ᴰ-Lattice = 𝒮ᴰ-Record (𝒮-Univ _) IsLatticeEquiv (fields: data[ 0l ∣ null ∣ pres0 ] data[ 1l ∣ null ∣ pres1 ] data[ _∨l_ ∣ bin ∣ pres∨l ] data[ _∧l_ ∣ bin ∣ pres∧l ] prop[ isLattice ∣ (λ _ _ → isPropIsLattice _ _ _ _) ]) where open LatticeStr open IsLatticeHom -- faster with some sharing null = autoDUARel (𝒮-Univ _) (λ A → A) bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A) LatticePath : (L M : Lattice ℓ) → LatticeEquiv L M ≃ (L ≡ M) LatticePath = ∫ 𝒮ᴰ-Lattice .UARel.ua Lattice→JoinSemilattice : Lattice ℓ → Semilattice ℓ Lattice→JoinSemilattice (A , latticestr _ _ _ _ L) = semilattice _ _ _ (L .IsLattice.joinSemilattice ) Lattice→MeetSemilattice : Lattice ℓ → Semilattice ℓ Lattice→MeetSemilattice (A , latticestr _ _ _ _ L) = semilattice _ _ _ (L .IsLattice.meetSemilattice )
{ "alphanum_fraction": 0.549476135, "avg_line_length": 34.36, "ext": "agda", "hexsha": "2904e8515aaacb415227f6aea515cb86db24066c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lpw25/cubical", "max_forks_repo_path": "Cubical/Algebra/Lattice/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "lpw25/cubical", "max_issues_repo_path": "Cubical/Algebra/Lattice/Base.agda", "max_line_length": 102, "max_stars_count": null, "max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lpw25/cubical", "max_stars_repo_path": "Cubical/Algebra/Lattice/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3316, "size": 7731 }
Extensionality of a function of two arguments \begin{code} extensionality2 : ∀ {A B C : Set} → {f g : A → B → C} → (∀ (x : A) (y : B) → f x y ≡ g x y) → f ≡ g extensionality2 fxy≡gxy = extensionality (λ x → extensionality (λ y → fxy≡gxy x y)) \end{code} Isomorphism of all and exists. \begin{code} ¬∃∀ : ∀ {A : Set} {B : A → Set} → (¬ ∃ (λ (x : A) → B x)) ≃ ∀ (x : A) → ¬ B x ¬∃∀ = record { to = λ { ¬∃bx x bx → ¬∃bx (x , bx) } ; fro = λ { ∀¬bx (x , bx) → ∀¬bx x bx } ; invˡ = λ { ¬∃bx → extensionality (λ { (x , bx) → refl }) } ; invʳ = λ { ∀¬bx → refl } } \end{code}
{ "alphanum_fraction": 0.4750830565, "avg_line_length": 31.6842105263, "ext": "agda", "hexsha": "c19bfe4ee0d44fbd5f928515486eddccedd81070", "lang": "Agda", "max_forks_count": 304, "max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z", "max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z", "max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "manikdv/plfa.github.io", "max_forks_repo_path": "extra/extra/Isomorphisms.agda", "max_issues_count": 323, "max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z", "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "manikdv/plfa.github.io", "max_issues_repo_path": "extra/extra/Isomorphisms.agda", "max_line_length": 99, "max_stars_count": 1003, "max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "manikdv/plfa.github.io", "max_stars_repo_path": "extra/extra/Isomorphisms.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z", "num_tokens": 272, "size": 602 }
open import Agda.Builtin.Nat open import Agda.Builtin.Equality _ : 10_000 * 100_000 ≡ 1_000_000_000 _ = refl
{ "alphanum_fraction": 0.7727272727, "avg_line_length": 18.3333333333, "ext": "agda", "hexsha": "874925a94d46631d1309026798d7c6f3a077f363", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-06-14T11:07:38.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-14T11:07: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/largenumber.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b", "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": "strake/agda", "max_issues_repo_path": "test/Succeed/largenumber.agda", "max_line_length": 36, "max_stars_count": 2, "max_stars_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "strake/agda", "max_stars_repo_path": "test/Succeed/largenumber.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": 44, "size": 110 }
{-# OPTIONS --cubical-compatible #-} module Common.Unit where open import Agda.Builtin.Unit public renaming (⊤ to Unit; tt to unit)
{ "alphanum_fraction": 0.7313432836, "avg_line_length": 22.3333333333, "ext": "agda", "hexsha": "784ddb1dcc623a68a1612678765762506d32e1b5", "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/Common/Unit.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/Common/Unit.agda", "max_line_length": 69, "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/Common/Unit.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 33, "size": 134 }
------------------------------------------------------------------------ -- Spheres ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} -- This module follows the HoTT book rather closely. import Equality.Path as P module Sphere {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq hiding (elim) open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection equality-with-J using (_↔_) open import Equality.Path.Isomorphisms eq open import Equality.Tactic equality-with-J import Equivalence equality-with-J as Equiv open import Function-universe equality-with-J as F hiding (_∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Nat equality-with-J as Nat open import Pointed-type equality-with-J open import Suspension eq as Suspension private variable a b : Level A B : Type a C : Pointed-type a x : A n : ℕ -- Spheres. 𝕊[_-1] : ℕ → Type 𝕊[ zero -1] = ⊥ 𝕊[ suc n -1] = Susp 𝕊[ n -1] -- Spheres with non-negative dimensions. 𝕊 : ℕ → Type 𝕊 n = 𝕊[ 1 + n -1] -- The booleans are isomorphic to the 0-dimensional sphere. Bool↔𝕊⁰ : Bool ↔ 𝕊 0 Bool↔𝕊⁰ = Bool↔Susp-⊥ -- Based maps from spheres with non-negative dimensions (using north -- as the point) are isomorphic to iterated loop spaces. 𝕊→ᴮ↔ : ∀ n → (𝕊 n , north) →ᴮ C ↔ proj₁ (Ω[ n ] C) 𝕊→ᴮ↔ {C = C} = lemma zero where lemma : ∀ m n → (𝕊 n , north) →ᴮ Ω[ m ] C ↔ proj₁ (Ω[ m + n ] C) lemma m zero = (𝕊 0 , north) →ᴮ Ω[ m ] C ↝⟨ Σ-cong (→-cong ext (inverse Bool↔𝕊⁰) F.id) (λ _ → F.id) ⟩ (Bool , true) →ᴮ Ω[ m ] C ↝⟨ Bool→ᴮ↔ ext ⟩ proj₁ (Ω[ m ] C) ↝⟨ ≡⇒↝ _ $ cong (λ n → proj₁ (Ω[ n ] C)) $ sym $ Nat.+-right-identity {n = m} ⟩□ proj₁ (Ω[ m + 0 ] C) □ lemma m (suc n) = (𝕊 (suc n) , north) →ᴮ Ω[ m ] C ↝⟨ Susp→ᴮ↔ ⟩ (𝕊 n , north) →ᴮ Ω[ suc m ] C ↝⟨ lemma (suc m) n ⟩ proj₁ (Ω[ suc m + n ] C) ↝⟨ ≡⇒↝ _ $ cong (λ n → proj₁ (Ω[ n ] C)) $ Nat.suc+≡+suc m ⟩□ proj₁ (Ω[ m + suc n ] C) □ -- A corollary. +↔∀contractible𝕊→ᴮ : H-level (1 + n) A ↔ (∀ x → Contractible ((𝕊 n , north) →ᴮ (A , x))) +↔∀contractible𝕊→ᴮ {n = n} {A = A} = H-level (1 + n) A ↔⟨ _↔_.to (Equiv.⇔↔≃ ext (H-level-propositional ext _) (Π-closure ext 1 λ _ → H-level-propositional ext _)) (+⇔∀contractible-Ω[] _) ⟩ (∀ x → Contractible (proj₁ $ Ω[ n ] (A , x))) ↝⟨ (∀-cong ext λ _ → H-level-cong ext 0 (inverse $ 𝕊→ᴮ↔ _)) ⟩□ (∀ x → Contractible ((𝕊 n , north) →ᴮ (A , x))) □
{ "alphanum_fraction": 0.5042164441, "avg_line_length": 33.4823529412, "ext": "agda", "hexsha": "22d96b16ee01b0ecde767f97499e680e7b06fa92", "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": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Sphere.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/equality", "max_issues_repo_path": "src/Sphere.agda", "max_line_length": 113, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Sphere.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 1067, "size": 2846 }
{-# OPTIONS --universe-polymorphism #-} -- Level suc is not a constructor, and doesn't behave as one -- for unification. module LevelUnification where open import Imports.Level data _≡_ {a}{A : Set a}(x : A) : ∀ {b}{B : Set b} → B → Set where refl : x ≡ x sym : ∀ a b (A : Set (suc a))(B : Set (suc b))(x : A)(y : B) → x ≡ y → y ≡ x sym a .a A .A x .x refl = refl
{ "alphanum_fraction": 0.5822102426, "avg_line_length": 24.7333333333, "ext": "agda", "hexsha": "a8152dbde65a76a1a38b83cef1a51f6bbdc1fc8e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/fail/LevelUnification.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/fail/LevelUnification.agda", "max_line_length": 76, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/LevelUnification.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": 136, "size": 371 }
{- Mathematical Foundations of Programming (G54FOP) Nicolai Kraus Lecture 6, 15 Feb 2018 -} module lec6FOP where {- We import everything we have done last week. "open" means we can use all definitions directly -} open import lec3FOP {- Hint: middle mouse click or alt-. [press alt/meta, then .] jumps to the definition that the cursor is on -} -- Reduce in one step -- (these are the simplification rules) data _→1_ : Expr → Expr → Set where izz : iz z →1 t izs : {e : Expr} → iz (s e) →1 f ift : {e₂ e₃ : Expr} → (if t then e₂ else e₃) →1 e₂ iff : {e₂ e₃ : Expr} → (if f then e₂ else e₃) →1 e₃ ps : {e : Expr} → p (s e) →1 e pz : p z →1 z -- include structural rules data _↝_ : Expr → Expr → Set where -- type: \leadsto from→1 : {e₁ e₂ : Expr} → (e₁ →1 e₂) → (e₁ ↝ e₂) inside-s : {e₁ e₂ : Expr} → (e₁ ↝ e₂) → (s e₁ ↝ s e₂) inside-p : {e₁ e₂ : Expr} → (e₁ ↝ e₂) → (p e₁ ↝ p e₂) inside-iz : ∀ {e₁} {e₂} → (e₁ ↝ e₂) → (iz e₁ ↝ iz e₂) inside-ite1 : ∀ {e₁ e₁' e₂ e₃} → (e₁ ↝ e₁') → (if e₁ then e₂ else e₃) ↝ (if e₁' then e₂ else e₃) inside-ite2 : ∀ {e₁ e₂ e₂' e₃} → (e₂ ↝ e₂') → (if e₁ then e₂ else e₃) ↝ (if e₁ then e₂' else e₃) inside-ite3 : ∀ {e₁ e₂ e₃ e₃'} → (e₃ ↝ e₃') → (if e₁ then e₂ else e₃) ↝ (if e₁ then e₂ else e₃') data _↝*_ : Expr → Expr → Set where start : ∀ {e} → e ↝* e step : ∀ {e₁ e₂ e₃} → (e₁ ↝ e₂) → (e₂ ↝* e₃) → (e₁ ↝* e₃) -- compose two reduction sequences compose : {e₁ e₂ e₃ : Expr} → (e₁ ↝* e₂) → (e₂ ↝* e₃) → (e₁ ↝* e₃) compose start s₂ = s₂ compose (step x s₁) s₂ = step x (compose s₁ s₂) open import Data.Empty renaming (⊥ to ∅) -- \emptyset -- define what it means to be a normal form is-normal : Expr → Set is-normal e = (e₁ : Expr) → (e →1 e₁) → ∅ {- Exercises: 1. (easy) Show that the expression "t" is in normal form. This means: fill the whole (replace the question mark) in t-nf : is-normal t t-nf = ? 2. (medium) Show that, if "e" is a normal form, then so is "s e". 3. (hard) Show that "is-normal" is a decidable predicate on Expr. This means writing a function which takes an expression and tells us whether the expression is a normal form or not. The naive version would be Expr → Bool but we can do much better: we can take an expression "e" and either return a *proof* that "e" is a normal form, or return an example of how it can be reduced. Such an example would consist of an expression "reduct" and a proof of "e ↝ reduct"; we will learn later how this can be expressed, but a good way of implementing it is as follows: -} record can-red (e : Expr) : Set where field reduct : Expr redstep : e ↝ reduct {- Ex 3, continued: We can import Data.Sum to get the definition of ⊎ (type: \u+), a disjoint sum (it's Either in Haskell). Check out how ⊎ is defined in the library, it's really simple! -} open import Data.Sum {- Ex3, continued: Now, fill in the ? in the following function; probably, you will want more auxiliary lemma. Caveat: I have not done this myself. decide-nf : (e : Expr) → (is-normal e) ⊎ can-red e decide-nf e = {!!} -}
{ "alphanum_fraction": 0.593721145, "avg_line_length": 30.9428571429, "ext": "agda", "hexsha": "6c9dcb836f8c73e6da9840a987c52dffc2fd560d", "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": "b65516ce0fdc5fc98604cbcff3ef8ae704d59049", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/FOP2018", "max_forks_repo_path": "agda/lec6FOP.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b65516ce0fdc5fc98604cbcff3ef8ae704d59049", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/FOP2018", "max_issues_repo_path": "agda/lec6FOP.agda", "max_line_length": 56, "max_stars_count": null, "max_stars_repo_head_hexsha": "b65516ce0fdc5fc98604cbcff3ef8ae704d59049", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nicolaikraus/FOP2018", "max_stars_repo_path": "agda/lec6FOP.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1205, "size": 3249 }
module Structure.Function.Ordering where import Lvl open import Logic open import Logic.Propositional open import Logic.Predicate open import Type module _ {ℓₒ₁ ℓₒ₂ ℓₗ₁ ℓₗ₂} {T₁ : Type{ℓₒ₁}} {T₂ : Type{ℓₒ₂}} (_≤₁_ : T₁ → T₁ → Type{ℓₗ₁}) (_≤₂_ : T₂ → T₂ → Type{ℓₗ₂}) where record Increasing (f : T₁ → T₂) : Stmt{ℓₒ₁ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂} where constructor intro field proof : ∀{a b : T₁} → (a ≤₁ b) → (f(a) ≤₂ f(b)) record Decreasing (f : T₁ → T₂) : Stmt{ℓₒ₁ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂} where constructor intro field proof : ∀{a b : T₁} → (a ≤₁ b) → (f(b) ≤₂ f(a)) Monotone : (T₁ → T₂) → Stmt Monotone(f) = (Increasing(f) ∨ Decreasing(f)) record UpperBoundPointOf (f : T₁ → T₂) (p : T₁) : Stmt{ℓₒ₁ Lvl.⊔ ℓₗ₂} where constructor intro field proof : ∀{x} → (f(x) ≤₂ f(p)) UpperBounded : (T₁ → T₂) → Stmt UpperBounded(f) = ∃(UpperBoundPointOf(f)) record LowerBoundPointOf (f : T₁ → T₂) (p : T₁) : Stmt{ℓₒ₁ Lvl.⊔ ℓₗ₂} where constructor intro field proof : ∀{x} → (f(p) ≤₂ f(x)) LowerBounded : (T₁ → T₂) → Stmt LowerBounded(f) = ∃(LowerBoundPointOf(f))
{ "alphanum_fraction": 0.6101541251, "avg_line_length": 32.4411764706, "ext": "agda", "hexsha": "82121d80e2dfa1db993e10d46958715b5c22a8ba", "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": "Structure/Function/Ordering.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": "Structure/Function/Ordering.agda", "max_line_length": 124, "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": "Structure/Function/Ordering.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": 503, "size": 1103 }
-- Issue498: Underapplied projection-like functions did not evaluate correctly. module Issue498 where data ⊤ : Set where tt : ⊤ data C : ⊤ → Set where c : C tt data C₂ : ⊤ → ⊤ → Set where c : C₂ tt tt module NoParams where f₁ : ∀ a → C a → ⊤ f₁ a x = tt f₁′ : ∀ a → C a → ⊤ f₁′ = f₁ check₁ : ∀ a x → C (f₁′ a x) check₁ s x = c f₂ : ∀ a b → C₂ a b → ⊤ f₂ a b x = tt f₂′ : ∀ a b → C₂ a b → ⊤ f₂′ a = f₂ a check₂ : ∀ a b x → C (f₂′ a b x) check₂ a b x = c f₃ : ∀ a {b} → C₂ a b → ⊤ f₃ a x = tt f₃′ : ∀ a {b} → C₂ a b → ⊤ f₃′ = f₃ data Is-f₃ : (∀ a {b} → C₂ a b → ⊤) → Set where is-f₃ : Is-f₃ (λ a {b} x → tt) check₃ : Is-f₃ f₃′ check₃ = is-f₃ module SomeParams (X Y : Set) where f₁ : ∀ a → C a → ⊤ f₁ a x = tt f₁′ : ∀ a → C a → ⊤ f₁′ = f₁ check₁ : ∀ a x → C (f₁′ a x) check₁ s x = c f₂ : ∀ a b → C₂ a b → ⊤ f₂ a b x = tt f₂′ : ∀ a b → C₂ a b → ⊤ f₂′ a = f₂ a check₂ : ∀ a b x → C (f₂′ a b x) check₂ a b x = c check₃ : ∀ {X Y} a x → C (SomeParams.f₁′ X Y a x) check₃ a x = c check₄ : ∀ {X Y} a b x → C (SomeParams.f₂′ X Y a b x) check₄ a b x = c
{ "alphanum_fraction": 0.4687774846, "avg_line_length": 16.2428571429, "ext": "agda", "hexsha": "f6a5b9d94e0c831adc14e7898cd37b19e3dbd177", "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/Issue498.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/Issue498.agda", "max_line_length": 79, "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/Issue498.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": 572, "size": 1137 }
module huffman-tree where open import lib data huffman-tree : Set where ht-leaf : string → ℕ → huffman-tree ht-node : ℕ → huffman-tree → huffman-tree → huffman-tree -- get the frequency out of a Huffman tree ht-frequency : huffman-tree → ℕ ht-frequency (ht-leaf _ f) = f ht-frequency (ht-node f _ _) = f -- lower frequency nodes are considered smaller ht-compare : huffman-tree → huffman-tree → 𝔹 ht-compare h1 h2 = (ht-frequency h1) < (ht-frequency h2) {- return (just s) if Huffman tree is an ht-leaf with string s; otherwise, return nothing (this is a constructor for the maybe type -- see maybe.agda in the IAL) -} ht-string : huffman-tree → maybe string ht-string (ht-leaf s f) = just s ht-string _ = nothing -- several helper functions for ht-to-string (defined at the bottom) private -- helper function for ht-to-stringh ht-declare-node : huffman-tree → ℕ → string × string ht-declare-node h n = let cur = "n" ^ (ℕ-to-string n) in cur , (cur ^ " [label = \"" ^ (help (ht-string h)) ^ (ℕ-to-string (ht-frequency h)) ^ "\"];\n") where help : maybe string → string help (just s) = s ^ " , " help nothing = "" -- helper function for ht-to-stringh ht-attach : maybe string → string → string ht-attach nothing _ = "" ht-attach (just c) c' = c ^ " -> " ^ c' ^ ";\n" ht-to-stringh : huffman-tree → ℕ → maybe string → ℕ × string ht-to-stringh h n prev with ht-declare-node h n ht-to-stringh (ht-leaf _ _) n prev | c , s = suc n , (ht-attach prev c) ^ s ht-to-stringh (ht-node _ h1 h2) n prev | c , s with ht-to-stringh h1 (suc n) (just c) ht-to-stringh (ht-node _ h1 h2) _ prev | c , s | n , s1 with ht-to-stringh h2 n (just c) ht-to-stringh (ht-node _ h1 h2) _ prev | c , s | _ , s1 | n , s2 = n , (ht-attach prev c) ^ s ^ s1 ^ s2 {- turn a Huffman tree into a string in Graphviz format (you can render the output .gv file at http://sandbox.kidstrythisathome.com/erdos/) -} ht-to-string : huffman-tree → string ht-to-string h with ht-to-stringh h 0 nothing ht-to-string h | _ , s = "digraph h {\nnode [shape = plaintext];\n" ^ s ^ "}"
{ "alphanum_fraction": 0.639321075, "avg_line_length": 40.7884615385, "ext": "agda", "hexsha": "65bee8682a59d199dbb7ecbd39927ec71a5769d6", "lang": "Agda", "max_forks_count": 17, "max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z", "max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rfindler/ial", "max_forks_repo_path": "huffman/huffman-tree.agda", "max_issues_count": 8, "max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "rfindler/ial", "max_issues_repo_path": "huffman/huffman-tree.agda", "max_line_length": 105, "max_stars_count": 29, "max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rfindler/ial", "max_stars_repo_path": "huffman/huffman-tree.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z", "max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z", "num_tokens": 676, "size": 2121 }
-- Andreas, 2014-12-02, issue reported by Jesper Cockx open import Common.Equality mutual Type : Set type : Type data Term : Type → Set where set : Term type Type = Term type type = set mutual weakenType : Type → Type → Type weaken : (ty ty' : Type) → Term ty → Term (weakenType ty' ty) weakenType ty ty' = subst Term {!!} (weaken type {!!} ty) weaken ty ty' t = {!!} data Test : Type → Set where test : Test (weakenType type type) -- Checking the constructor declaration was looping. -- Termination checker should complain.
{ "alphanum_fraction": 0.6636690647, "avg_line_length": 21.3846153846, "ext": "agda", "hexsha": "33e6d78b079f9072d07aaaf7a24cff94dcef97ee", "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/Issue1375-4.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/Issue1375-4.agda", "max_line_length": 63, "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/Issue1375-4.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": 162, "size": 556 }
-- Intuitionistic propositional logic, vector-based de Bruijn approach, initial encoding module Vi.Ip where open import Lib using (Nat; suc; _+_; Fin; fin; Vec; _,_; proj; VMem; mem) -- Types infixl 2 _&&_ infixl 1 _||_ infixr 0 _=>_ data Ty : Set where UNIT : Ty _=>_ : Ty -> Ty -> Ty _&&_ : Ty -> Ty -> Ty _||_ : Ty -> Ty -> Ty FALSE : Ty infixr 0 _<=>_ _<=>_ : Ty -> Ty -> Ty a <=> b = (a => b) && (b => a) NOT : Ty -> Ty NOT a = a => FALSE TRUE : Ty TRUE = FALSE => FALSE -- Context and truth judgement Cx : Nat -> Set Cx n = Vec Ty n isTrue : forall {tn} -> Ty -> Fin tn -> Cx tn -> Set isTrue a i tc = VMem a i tc -- Terms module Ip where infixl 1 _$_ infixr 0 lam=>_ data Tm {tn} (tc : Cx tn) : Ty -> Set where var : forall {a i} -> isTrue a i tc -> Tm tc a lam=>_ : forall {a b} -> Tm (tc , a) b -> Tm tc (a => b) _$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b) fst : forall {a b} -> Tm tc (a && b) -> Tm tc a snd : forall {a b} -> Tm tc (a && b) -> Tm tc b left : forall {a b} -> Tm tc a -> Tm tc (a || b) right : forall {a b} -> Tm tc b -> Tm tc (a || b) case' : forall {a b c} -> Tm tc (a || b) -> Tm (tc , a) c -> Tm (tc , b) c -> Tm tc c abort : forall {a} -> Tm tc FALSE -> Tm tc a syntax pair' x y = [ x , y ] syntax case' xy x y = case xy => x => y v : forall {tn} (k : Nat) {tc : Cx (suc (k + tn))} -> Tm tc (proj tc (fin k)) v i = var (mem i) Thm : Ty -> Set Thm a = forall {tn} {tc : Cx tn} -> Tm tc a open Ip public -- Example theorems t1 : forall {a b} -> Thm (a => NOT a => b) t1 = lam=> lam=> abort (v 0 $ v 1) t2 : forall {a b} -> Thm (NOT a => a => b) t2 = lam=> lam=> abort (v 1 $ v 0) t3 : forall {a} -> Thm (a => NOT (NOT a)) t3 = lam=> lam=> v 0 $ v 1 t4 : forall {a} -> Thm (NOT a <=> NOT (NOT (NOT a))) t4 = [ lam=> lam=> v 0 $ v 1 , lam=> lam=> v 1 $ (lam=> v 0 $ v 1) ]
{ "alphanum_fraction": 0.451954023, "avg_line_length": 23.6413043478, "ext": "agda", "hexsha": "cd4e21f59c08e4232b0f90386c7c216d82902737", "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": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/formal-logic", "max_forks_repo_path": "src/Vi/Ip.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_path": "src/Vi/Ip.agda", "max_line_length": 90, "max_stars_count": 26, "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_path": "src/Vi/Ip.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "num_tokens": 859, "size": 2175 }
module Selective.Libraries.ReceiveSublist where open import Selective.ActorMonad public open import Prelude accept-sublist-unwrapped : (xs ys zs : InboxShape) → ∀{MT} → MT ∈ (xs ++ ys ++ zs) → Bool accept-sublist-unwrapped [] [] zs p = false accept-sublist-unwrapped [] (y ∷ ys) zs Z = true accept-sublist-unwrapped [] (y ∷ ys) zs (S p) = accept-sublist-unwrapped [] ys zs p accept-sublist-unwrapped (x ∷ xs) ys zs Z = false accept-sublist-unwrapped (x ∷ xs) ys zs (S p) = accept-sublist-unwrapped xs ys zs p accept-sublist : (xs ys zs : InboxShape) → MessageFilter (xs ++ ys ++ zs) accept-sublist xs ys zs (Msg received-message-type received-fields) = accept-sublist-unwrapped xs ys zs received-message-type record AcceptSublistDependent (IS : InboxShape) (accepted-type : MessageType) : Set₁ where field accepted-which : accepted-type ∈ IS fields : All receive-field-content accepted-type receive-sublist : {i : Size} → {Γ : TypingContext} → (xs ys zs : InboxShape) → ∞ActorM i (xs ++ ys ++ zs) (Message ys) Γ (add-references Γ) receive-sublist xs ys zs = do record { msg = Msg {MT} p f ; msg-ok = msg-ok } ← selective-receive (accept-sublist xs ys zs) let record {accepted-which = aw ; fields = fields } = rewrap-message xs ys zs p f msg-ok return₁ (Msg {MT = MT} aw fields) where rewrap-message : ∀{MT} → (xs ys zs : InboxShape) → (p : MT ∈ (xs ++ ys ++ zs)) → All receive-field-content MT → (accept-sublist-unwrapped xs ys zs p) ≡ true → AcceptSublistDependent ys MT rewrap-message [] [] zs p f () rewrap-message [] (x ∷ ys) zs Z f q = record { accepted-which = Z ; fields = f } rewrap-message [] (x ∷ ys) zs (S p) f q = let rec = rewrap-message [] ys zs p f q open AcceptSublistDependent in record { accepted-which = S (rec .accepted-which) ; fields = rec .fields } rewrap-message (x ∷ xs) ys zs Z f () rewrap-message (x ∷ xs) ys zs (S p) f q = rewrap-message xs ys zs p f q
{ "alphanum_fraction": 0.5870353581, "avg_line_length": 45.0204081633, "ext": "agda", "hexsha": "4fb9e61bf941a8d30cfe6f09aed1154446259419", "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/Selective/Libraries/ReceiveSublist.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/Selective/Libraries/ReceiveSublist.agda", "max_line_length": 125, "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/Selective/Libraries/ReceiveSublist.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": 612, "size": 2206 }
module x where open import Level private variable a b c d e f ℓ p q r : Level A : Set a B : Set b C : Set c D : Set d E : Set e F : Set f ------------------------------------------------------------------------------ infixr 4 _,_ infixr 2 _^_ record _^_ (A : Set a) (B : Set b) : Set (a ⊔ b) where constructor _,_ field fst : A snd : B open _^_ swap : A ^ B → B ^ A swap (a , b) = b , a ------------------------------------------------------------------------------ infixr 1 _v_ data _v_ (A : Set a) (B : Set b) : Set (a ⊔ b) where inl : (x : A) → A v B inr : (y : B) → A v B cases : ∀ {A : Set a} {B : Set b} {C : Set c} → (A v B) → (A → C) → (B → C) → C cases (inl q) f g = f q cases (inr r) f g = g r ------------------------------------------------------------------------------ data ⊥ : Set where ⊥-elim : ∀ {A : Set a} → ⊥ → A ⊥-elim = λ () ------------------------------------------------------------------------------ ¬_ : Set → Set ¬ A = A → ⊥ ------------------------------------------------------------------------------ -- 4.1 assoc-^ : (A ^ B) ^ C → A ^ (B ^ C) assoc-^ ((a , b) , c) = a , (b , c) -- 4.2 e4-2 : (¬ A v B) → (A → B) e4-2 (inl ¬a) = λ a → ⊥-elim (¬a a) e4-2 (inr b) = λ _ → b {- not provable e4-2' : (A → B) → (¬ A v B) e4-2' a→b = {!!} -} -- 4.3 e4-3 : (A v ¬ A) → (¬ ¬ A → A) e4-3 (inl a) = λ _ → a e4-3 (inr ¬a) = λ ¬¬a → ⊥-elim (¬¬a ¬a) e4-3' : (A → ¬ ¬ A) e4-3' = λ a ¬¬a → ¬¬a a -- 4.4 -- this is similar to v elimination by cases e4-4 : ((A ^ B) → C) → A → (B → C) e4-4 a^b→c a = λ b → a^b→c (a , b) -- 4.5 e4-5 : (A → (B → C)) → ((A ^ B) → C) e4-5 a→b→c = λ (a , b) → a→b→c a b e4-5' : ((A ^ B) → C) → (A → (B → C)) e4-5' a^b→c = λ a → λ b → a^b→c (a , b) -- 4.6 e4-6 : A → (B v C) → ((A ^ B) v (A ^ C)) e4-6 a (inl b) = inl (a , b) e4-6 a (inr c) = inr (a , c) -- 4.7 e4-7 : (A → C) → (B → D) → ((A ^ B) → (C ^ D)) e4-7 a→c b→d = λ (a , b) → (a→c a , b→d b) -- section 4.5.2 -- function composition _∘_ : (B → C) → (A → B) → (A → C) _∘_ b→c a→b = λ a -> b→c (a→b a) srl : (A → B) → (¬ B → ¬ A) srl a→b = λ ¬b a → ¬b (a→b a) -- section 4.5.3 idA^A : (A ^ A) → (A ^ A) idA^A (a , a') = (a' , a) -- section 4.5.5 Conjunction and disjunction s455 : ((A v B) → C) → ((A → C) ^ (B → C)) s455 = λ avb→c → (avb→c ∘ inl , avb→c ∘ inr) s455' : ((A → C) ^ (B → C)) → ((A v B) → C) s455' (a→c , b→c) = λ { (inl a) → a→c a ; (inr b) → b→c b } dm : ¬ (A v B) → (¬ A ^ ¬ B) dm notAvB = (notAvB ∘ inl , notAvB ∘ inr) dm' : (¬ A v ¬ B) → ¬ (A ^ B) dm' (inl ¬a) = λ (a , _) → ¬a a dm' (inr ¬b) = λ (_ , b) → ¬b b -- 4.8 e4-8a : A → ¬ ¬ A e4-8a a = λ ¬a → ¬a a e4-8b : (B v C) → ¬ (¬ B ^ ¬ C) e4-8b (inl b) = λ (¬b , _) → ¬b b e4-8b (inr c) = λ ( _ , ¬c) → ¬c c e4-8c : (A → B) → ((A → C) → (A → (B ^ C))) e4-8c a→b = λ a→c → λ a → (a→b a , a→c a)
{ "alphanum_fraction": 0.3366747321, "avg_line_length": 20.5177304965, "ext": "agda", "hexsha": "9eec16e38a222d7045b941396a99282ab9253940", "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": "math-and-functional-programming/1999-Type_Theory_and_Functional_Programming-Simon_Thompson/x.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": "math-and-functional-programming/1999-Type_Theory_and_Functional_Programming-Simon_Thompson/x.agda", "max_line_length": 78, "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": "math-and-functional-programming/1999-Type_Theory_and_Functional_Programming-Simon_Thompson/x.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": 1379, "size": 2893 }
-- Andreas, 2021-04-22, issue #5339 -- Allow constructors of the same name in `constructor` block. module _ where module Works where interleaved mutual data Nat : Set data Fin : Nat → Set data _ where zero : Nat data _ where suc : Nat → Nat zero : ∀ {n} → Fin (suc n) data _ where suc : ∀ {n} (i : Fin n) → Fin (suc n) interleaved mutual data Nat : Set data Fin : Nat → Set data _ where zero : Nat suc : Nat → Nat zero : ∀ {n} → Fin (suc n) suc : ∀ {n} (i : Fin n) → Fin (suc n) -- `data _ where` block should be accepted despite duplicate constructor names. wkFin : ∀{n} → Fin n → Fin (suc n) wkFin zero = zero wkFin (suc i) = suc (wkFin i)
{ "alphanum_fraction": 0.58033241, "avg_line_length": 21.8787878788, "ext": "agda", "hexsha": "46795e9955d85b7ecaeedcee7642df164439f21f", "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/Issue5339.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/Issue5339.agda", "max_line_length": 79, "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/Issue5339.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": 243, "size": 722 }
------------------------------------------------------------------------ -- IO ------------------------------------------------------------------------ {-# OPTIONS --no-termination-check #-} module IO where open import Coinduction open import Data.Unit open import Data.String open import Data.Colist import Foreign.Haskell as Haskell import IO.Primitive as Prim ------------------------------------------------------------------------ -- The IO monad -- One cannot write "infinitely large" computations with the -- postulated IO monad in IO.Primitive without turning off the -- termination checker (or going via the FFI, or perhaps abusing -- something else). The following coinductive deep embedding is -- introduced to avoid this problem. Possible non-termination is -- isolated to the run function below. infixl 1 _>>=_ _>>_ data IO : Set → Set₁ where lift : ∀ {A} (m : Prim.IO A) → IO A return : ∀ {A} (x : A) → IO A _>>=_ : ∀ {A B} (m : ∞₁ (IO A)) (f : (x : A) → ∞₁ (IO B)) → IO B _>>_ : ∀ {A B} (m₁ : ∞₁ (IO A)) (m₂ : ∞₁ (IO B)) → IO B -- The use of abstract ensures that the run function will not be -- unfolded infinitely by the type checker. abstract run : ∀ {A} → IO A → Prim.IO A run (lift m) = m run (return x) = Prim.return x run (m >>= f) = Prim._>>=_ (run (♭₁ m )) λ x → run (♭₁ (f x)) run (m₁ >> m₂) = Prim._>>=_ (run (♭₁ m₁)) λ _ → run (♭₁ m₂) ------------------------------------------------------------------------ -- Utilities -- Because IO A lives in Set₁ I hesitate to define sequence, which -- would require defining a Set₁ variant of Colist. mapM : ∀ {A B} → (A → IO B) → Colist A → IO (Colist B) mapM f [] = return [] mapM f (x ∷ xs) = ♯₁ f x >>= λ y → ♯₁ (♯₁ mapM f (♭ xs) >>= λ ys → ♯₁ return (y ∷ ♯ ys)) -- The reason for not defining mapM′ in terms of mapM is efficiency -- (the unused results could cause unnecessary memory use). mapM′ : ∀ {A B} → (A → IO B) → Colist A → IO ⊤ mapM′ f [] = return _ mapM′ f (x ∷ xs) = ♯₁ f x >> ♯₁ mapM′ f (♭ xs) ------------------------------------------------------------------------ -- Simple lazy IO (UTF8-based) getContents : IO Costring getContents = ♯₁ lift Prim.getContents >>= λ s → ♯₁ return (Haskell.toColist s) readFile : String → IO Costring readFile f = ♯₁ lift (Prim.readFile f) >>= λ s → ♯₁ return (Haskell.toColist s) writeFile∞ : String → Costring → IO ⊤ writeFile∞ f s = ♯₁ lift (Prim.writeFile f (Haskell.fromColist s)) >> ♯₁ return _ writeFile : String → String → IO ⊤ writeFile f s = writeFile∞ f (toCostring s) putStr∞ : Costring → IO ⊤ putStr∞ s = ♯₁ lift (Prim.putStr (Haskell.fromColist s)) >> ♯₁ return _ putStr : String → IO ⊤ putStr s = putStr∞ (toCostring s) putStrLn∞ : Costring → IO ⊤ putStrLn∞ s = ♯₁ lift (Prim.putStrLn (Haskell.fromColist s)) >> ♯₁ return _ putStrLn : String → IO ⊤ putStrLn s = putStrLn∞ (toCostring s)
{ "alphanum_fraction": 0.5380968507, "avg_line_length": 29.53, "ext": "agda", "hexsha": "35ced987fe4f5b35503cb729de6251678718b39b", "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/IO.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/IO.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/IO.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": 906, "size": 2953 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Integers.RingStructure.Ring open import Rings.IntegralDomains.Definition module Numbers.Integers.RingStructure.IntegralDomain where intDom : (a b : ℤ) → a *Z b ≡ nonneg 0 → (a ≡ nonneg 0 → False) → (b ≡ nonneg 0) intDom (nonneg zero) (nonneg b) x a!=0 = exFalso (a!=0 x) intDom (nonneg (succ a)) (nonneg zero) a!=0 _ = refl intDom (nonneg zero) (negSucc b) pr a!=0 = exFalso (a!=0 pr) intDom (negSucc a) (nonneg zero) _ _ = refl ℤIntDom : IntegralDomain ℤRing IntegralDomain.intDom ℤIntDom {a} {b} = intDom a b IntegralDomain.nontrivial ℤIntDom ()
{ "alphanum_fraction": 0.7213352685, "avg_line_length": 36.2631578947, "ext": "agda", "hexsha": "d0a78cd19bbae1904734021270341ea54971243a", "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": "Numbers/Integers/RingStructure/IntegralDomain.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": "Numbers/Integers/RingStructure/IntegralDomain.agda", "max_line_length": 80, "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": "Numbers/Integers/RingStructure/IntegralDomain.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": 236, "size": 689 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types open import LibraBFT.Impl.OBM.Rust.Duration open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.ImplShared.Base.Types open import Optics.All open import Util.ByteString open import Util.Encode open import Util.Hash open import Util.KVMap as Map open import Util.PKCS open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) -- Defines the types that /DO NOT/ depend on an epoch config. -- TODO-3: update types to reflect more recent version of LibraBFT. This is -- a substantial undertaking that should probably be led by someone who can -- access our internal implementation. module LibraBFT.ImplShared.Consensus.Types.EpochIndep where -- Below here is incremental progress towards something -- that will eventually mirror the types in LBFT.Consensus.Types -- that /DO NOT/ depend on the set of active authors -- or safety rules, which we call the /EpochConfig/. Author : Set Author = NodeId AccountAddress : Set AccountAddress = Author AuthorName : Set AuthorName = Author aAuthorName : Lens Author AuthorName aAuthorName = mkLens' (λ x → x) (λ x → const x) HashValue : Set HashValue = Hash TX : Set TX = ByteString Instant : Set Instant = ℕ -- TODO-2: should eventually be a time stamp postulate -- TODO-1: implement/prove PK equality _≟-PK_ : (pk1 pk2 : PK) → Dec (pk1 ≡ pk2) instance Eq-PK : Eq PK Eq._≟_ Eq-PK = _≟-PK_ -- LBFT-OBM-DIFF: We do not have world state. We just count the Epoch/Round as the version. record Version : Set where constructor Version∙new field _vVE : Epoch _vVR : Round open Version public postulate instance enc-Version : Encoder Version postulate -- TODO-1: implement/prove Version equality _≟-Version_ : (v1 v2 : Version) → Dec (v1 ≡ v2) instance Eq-Version : Eq Version Eq._≟_ Eq-Version = _≟-Version_ _≤-Version_ : Version → Version → Set v1 ≤-Version v2 = _vVE v1 < _vVE v2 ⊎ _vVE v1 ≡ _vVE v2 × _vVR v1 ≤ _vVR v2 _≤?-Version_ : (v1 v2 : Version) → Dec (v1 ≤-Version v2) v1 ≤?-Version v2 with _vVE v1 <? _vVE v2 ...| yes prf = yes (inj₁ prf) ...| no ege with _vVE v1 ≟ _vVE v2 ...| no rneq = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (x , _)) → rneq x }) ...| yes refl with _vVR v1 ≤? _vVR v2 ...| yes rleq = yes (inj₂ (refl , rleq)) ...| no rgt = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (_ , x)) → rgt x }) _<-Version_ : Version → Version → Set v1 <-Version v2 = _vVE v1 < _vVE v2 ⊎ _vVE v1 ≡ _vVE v2 × _vVR v1 < _vVR v2 _<?-Version_ : (v1 v2 : Version) → Dec (v1 <-Version v2) v1 <?-Version v2 with _vVE v1 <? _vVE v2 ...| yes prf = yes (inj₁ prf) ...| no ege with _vVE v1 ≟ _vVE v2 ...| no rneq = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (x , _)) → rneq x }) ...| yes refl with _vVR v1 <? _vVR v2 ...| yes rleq = yes (inj₂ (refl , rleq)) ...| no rgt = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (_ , x)) → rgt x }) -- ------------------------------------------------------------------------------ record ValidatorSigner : Set where constructor ValidatorSigner∙new field _vsAuthor : AccountAddress _vsPrivateKey : SK -- Note that the SystemModel doesn't -- allow one node to examine another's -- state, so we don't model someone being -- able to impersonate someone else unless -- PK is "dishonest", which models the -- possibility that the corresponding secret -- key may have been leaked. open ValidatorSigner public unquoteDecl vsAuthor vsPrivateKey = mkLens (quote ValidatorSigner) (vsAuthor ∷ vsPrivateKey ∷ []) RawEncNetworkAddress = Author record ValidatorConfig : Set where constructor ValidatorConfig∙new field _vcConsensusPublicKey : PK _vcValidatorNetworkAddress : RawEncNetworkAddress open ValidatorConfig public unquoteDecl vcConsensusPublicKey vcValidatorNetworkAddress = mkLens (quote ValidatorConfig) (vcConsensusPublicKey ∷ vcValidatorNetworkAddress ∷ []) record ValidatorInfo : Set where constructor ValidatorInfo∙new field _viAccountAddress : AccountAddress _viConsensusVotingPower : U64 _viConfig : ValidatorConfig open ValidatorInfo public unquoteDecl viAccountAddress viConsensusVotingPower viConfig = mkLens (quote ValidatorInfo) (viAccountAddress ∷ viConsensusVotingPower ∷ viConfig ∷ []) -- getter only in Haskell -- key for validating signed messages from this validator viConsensusPublicKey : Lens ValidatorInfo PK viConsensusPublicKey = viConfig ∙ vcConsensusPublicKey record ValidatorConsensusInfo : Set where constructor ValidatorConsensusInfo∙new field _vciPublicKey : PK _vciVotingPower : U64 open ValidatorConsensusInfo public unquoteDecl vciPublicKey vciVotingPower = mkLens (quote ValidatorConsensusInfo) (vciPublicKey ∷ vciVotingPower ∷ []) record ValidatorVerifier : Set where constructor mkValidatorVerifier field _vvAddressToValidatorInfo : KVMap AccountAddress ValidatorConsensusInfo _vvQuorumVotingPower : ℕ -- TODO-2: see above; for now, this is QuorumSize _vvTotalVotingPower : ℕ -- TODO-2: see above; for now, this is number of peers in EpochConfig open ValidatorVerifier public unquoteDecl vvAddressToValidatorInfo vvQuorumVotingPower vvTotalVotingPower = mkLens (quote ValidatorVerifier) (vvAddressToValidatorInfo ∷ vvQuorumVotingPower ∷ vvTotalVotingPower ∷ []) -- getter only in Haskell vvObmAuthors : Lens ValidatorVerifier (List AccountAddress) vvObmAuthors = mkLens' g s where g : ValidatorVerifier → List AccountAddress g vv = Map.kvm-keys (vv ^∙ vvAddressToValidatorInfo) s : ValidatorVerifier → List AccountAddress → ValidatorVerifier s vv _ = vv -- TODO-1 : cannot be done: need a way to defined only getters data ConsensusScheme : Set where ConsensusScheme∙new : ConsensusScheme -- instance S.Serialize ConsensusScheme record ValidatorSet : Set where constructor ValidatorSet∙new field _vsScheme : ConsensusScheme _vsPayload : List ValidatorInfo -- instance S.Serialize ValidatorSet open ValidatorSet public unquoteDecl vsScheme vsPayload = mkLens (quote ValidatorSet) (vsScheme ∷ vsPayload ∷ []) record EpochState : Set where constructor EpochState∙new field _esEpoch : Epoch _esVerifier : ValidatorVerifier open EpochState public unquoteDecl esEpoch esVerifier = mkLens (quote EpochState) (esEpoch ∷ esVerifier ∷ []) postulate -- one valid assumption, one that can be proved using it instance Enc-EpochState : Encoder EpochState Enc-EpochStateMB : Encoder (Maybe EpochState) -- TODO-1: make combinator to build this -- ------------------------------------------------------------------------------ record BlockInfo : Set where constructor BlockInfo∙new field _biEpoch : Epoch _biRound : Round _biId : HashValue _biExecutedStateId : HashValue -- aka liTransactionAccumulatorHash _biVersion : Version --, _biTimestamp :: Instant _biNextEpochState : Maybe EpochState open BlockInfo public unquoteDecl biEpoch biRound biId biExecutedStateId biVersion biNextEpochState = mkLens (quote BlockInfo) (biEpoch ∷ biRound ∷ biId ∷ biExecutedStateId ∷ biVersion ∷ biNextEpochState ∷ []) postulate instance enc-BlockInfo : Encoder BlockInfo postulate _≟-BlockInfo_ : (bi1 bi2 : BlockInfo) → Dec (bi1 ≡ bi2) instance Eq-BlockInfo : Eq BlockInfo Eq._≟_ Eq-BlockInfo = _≟-BlockInfo_ BlockInfo-η : ∀{e1 e2 r1 r2 i1 i2 x1 x2 v1 v2 n1 n2} → e1 ≡ e2 → r1 ≡ r2 → i1 ≡ i2 → x1 ≡ x2 → v1 ≡ v2 → n1 ≡ n2 → BlockInfo∙new e1 r1 i1 x1 v1 n1 ≡ BlockInfo∙new e2 r2 i2 x2 v2 n2 BlockInfo-η refl refl refl refl refl refl = refl instance Eq-ByteString : Eq ByteString Eq._≟_ Eq-ByteString = _≟ByteString_ {- _≟BlockInfo_ : (b₁ b₂ : BlockInfo) → Dec (b₁ ≡ b₂) l ≟BlockInfo r with ((l ^∙ biEpoch) ≟ (r ^∙ biEpoch)) ...| no no-e = no λ where refl → no-e refl ...| yes refl with ((l ^∙ biRound) ≟ (r ^∙ biRound)) ...| no no-r = no λ where refl → no-r refl ...| yes refl with ((l ^∙ biId) ≟ (r ^∙ biId)) ...| no no-i = no λ where refl → no-i refl ...| yes refl = yes refl instance Eq-BlockInfo : Eq BlockInfo Eq._≟_ Eq-BlockInfo = _≟BlockInfo_ BlockInfo-η : ∀{e1 e2 r1 r2 i1 i2} → e1 ≡ e2 → r1 ≡ r2 → i1 ≡ i2 → BlockInfo∙new e1 r1 i1 ≡ BlockInfo∙new e2 r2 i2 BlockInfo-η refl refl refl = refl -} biNextBlockEpoch : Lens BlockInfo Epoch biNextBlockEpoch = mkLens' g s where g : BlockInfo → Epoch g bi = maybeS (bi ^∙ biNextEpochState) (bi ^∙ biEpoch) ( _^∙ esEpoch) s : BlockInfo → Epoch → BlockInfo s bi _ = bi -- TODO-1 : cannot be done: need a way to defined only getters -- ------------------------------------------------------------------------------ record LedgerInfo : Set where constructor LedgerInfo∙new field _liCommitInfo : BlockInfo _liConsensusDataHash : HashValue open LedgerInfo public unquoteDecl liCommitInfo liConsensusDataHash = mkLens (quote LedgerInfo) (liCommitInfo ∷ liConsensusDataHash ∷ []) postulate instance enc-LedgerInfo : Encoder LedgerInfo postulate instance ws-LedgerInfo : WithSig LedgerInfo -- GETTER only in Haskell liEpoch : Lens LedgerInfo Epoch liEpoch = liCommitInfo ∙ biEpoch -- GETTER only in Haskell liNextBlockEpoch : Lens LedgerInfo Epoch liNextBlockEpoch = liCommitInfo ∙ biNextBlockEpoch -- GETTER only in Haskell liConsensusBlockId : Lens LedgerInfo HashValue liConsensusBlockId = liCommitInfo ∙ biId -- GETTER only in Haskell liTransactionAccumulatorHash : Lens LedgerInfo HashValue liTransactionAccumulatorHash = liCommitInfo ∙ biExecutedStateId -- GETTER only in Haskell liVersion : Lens LedgerInfo Version liVersion = liCommitInfo ∙ biVersion -- GETTER only in Haskell liNextEpochState : Lens LedgerInfo (Maybe EpochState) liNextEpochState = mkLens' g s where g : LedgerInfo → Maybe EpochState g = (_^∙ liCommitInfo ∙ biNextEpochState) s : LedgerInfo → Maybe EpochState → LedgerInfo s l _ = l -- TODO-1 : cannot be done: need a way to defined only getters -- GETTER only in Haskell liEndsEpoch : Lens LedgerInfo Bool liEndsEpoch = mkLens' g s where g : LedgerInfo → Bool g = is-just ∘ (_^∙ liNextEpochState) s : LedgerInfo → Bool → LedgerInfo s l _ = l -- TODO-1 : cannot be done: need a way to defined only getters LedgerInfo-η : ∀ {ci1 ci2 : BlockInfo} {cdh1 cdh2 : Hash} → ci1 ≡ ci2 → cdh1 ≡ cdh2 → (LedgerInfo∙new ci1 cdh1) ≡ (LedgerInfo∙new ci2 cdh2) LedgerInfo-η refl refl = refl record LedgerInfoWithSignatures : Set where constructor LedgerInfoWithSignatures∙new field _liwsLedgerInfo : LedgerInfo _liwsSignatures : KVMap Author Signature open LedgerInfoWithSignatures public unquoteDecl liwsLedgerInfo liwsSignatures = mkLens (quote LedgerInfoWithSignatures) (liwsLedgerInfo ∷ liwsSignatures ∷ []) postulate instance enc-LedgerInfoWithSignatures : Encoder LedgerInfoWithSignatures -- GETTER only in Haskell liwsEpoch : Lens LedgerInfoWithSignatures Epoch liwsEpoch = liwsLedgerInfo ∙ liEpoch -- GETTER only in Haskell liwsVersion : Lens LedgerInfoWithSignatures Version liwsVersion = liwsLedgerInfo ∙ liVersion -- GETTER only in Haskell liwsNextEpochState : Lens LedgerInfoWithSignatures (Maybe EpochState) liwsNextEpochState = liwsLedgerInfo ∙ liNextEpochState -- ------------------------------------------------------------------------------ record Timeout : Set where constructor Timeout∙new field _toEpoch : Epoch _toRound : Round open Timeout public unquoteDecl toEpoch toRound = mkLens (quote Timeout) (toEpoch ∷ toRound ∷ []) postulate instance enc-Timeout : Encoder Timeout -- ------------------------------------------------------------------------------ record VoteData : Set where constructor VoteData∙new field _vdProposed : BlockInfo _vdParent : BlockInfo open VoteData public unquoteDecl vdProposed vdParent = mkLens (quote VoteData) (vdProposed ∷ vdParent ∷ []) postulate instance enc-VoteData : Encoder VoteData VoteData-η : ∀ {pr1 par1 pr2 par2 : BlockInfo} → pr1 ≡ pr2 → par1 ≡ par2 → (VoteData∙new pr1 par1) ≡ (VoteData∙new pr2 par2) VoteData-η refl refl = refl -- DESIGN NOTE: The _vAuthor field is included only to facilitate lookup of the public key against -- which to verify the signature. An alternative would be to use an index into the members of the -- epoch config, which would save message space and therefore bandwidth. record Vote : Set where constructor Vote∙new field _vVoteData : VoteData _vAuthor : Author _vLedgerInfo : LedgerInfo _vSignature : Signature _vTimeoutSignature : Maybe Signature open Vote public unquoteDecl vVoteData vAuthor vLedgerInfo vSignature vTimeoutSignature = mkLens (quote Vote) (vVoteData ∷ vAuthor ∷ vLedgerInfo ∷ vSignature ∷ vTimeoutSignature ∷ []) postulate instance enc-Vote : Encoder Vote -- not defined in Haskell vParent : Lens Vote BlockInfo vParent = vVoteData ∙ vdParent -- not defined in Haskell vProposed : Lens Vote BlockInfo vProposed = vVoteData ∙ vdProposed -- not defined in Haskell vParentId : Lens Vote Hash vParentId = vVoteData ∙ vdParent ∙ biId -- not defined in Haskell vParentRound : Lens Vote Round vParentRound = vVoteData ∙ vdParent ∙ biRound -- not defined in Haskell vProposedId : Lens Vote Hash vProposedId = vVoteData ∙ vdProposed ∙ biId -- getter only in Haskell vEpoch : Lens Vote Epoch vEpoch = vVoteData ∙ vdProposed ∙ biEpoch -- getter only in Haskell vRound : Lens Vote Round vRound = vVoteData ∙ vdProposed ∙ biRound -- ------------------------------------------------------------------------------ record QuorumCert : Set where constructor QuorumCert∙new field _qcVoteData : VoteData _qcSignedLedgerInfo : LedgerInfoWithSignatures open QuorumCert public unquoteDecl qcVoteData qcSignedLedgerInfo = mkLens (quote QuorumCert) (qcVoteData ∷ qcSignedLedgerInfo ∷ []) postulate instance enc-QuorumCert : Encoder QuorumCert -- Because QuorumCert has an injective encoding (postulated, for now), -- we can use it to determine equality of QuorumCerts. _≟QC_ : (q1 q2 : QuorumCert) → Dec (q1 ≡ q2) _≟QC_ = ≡-Encoder enc-QuorumCert _QCBoolEq_ : QuorumCert → QuorumCert → Bool _QCBoolEq_ q1 q2 = does (q1 ≟QC q2) -- getter only in Haskell qcCertifiedBlock : Lens QuorumCert BlockInfo qcCertifiedBlock = qcVoteData ∙ vdProposed -- getter only in Haskell qcParentBlock : Lens QuorumCert BlockInfo qcParentBlock = qcVoteData ∙ vdParent -- getter only in Haskell qcLedgerInfo : Lens QuorumCert LedgerInfoWithSignatures qcLedgerInfo = qcSignedLedgerInfo -- getter only in Haskell qcCommitInfo : Lens QuorumCert BlockInfo qcCommitInfo = qcSignedLedgerInfo ∙ liwsLedgerInfo ∙ liCommitInfo -- getter only in Haskell qcEndsEpoch : Lens QuorumCert Bool qcEndsEpoch = mkLens' g s where g : QuorumCert → Bool g q = is-just (q ^∙ qcSignedLedgerInfo ∙ liwsLedgerInfo ∙ liNextEpochState) s : QuorumCert → Bool → QuorumCert s q _ = q -- TODO-1 : cannot be done: need a way to defined only getters -- Constructs a 'vote' that was gathered in a QC. rebuildVote : QuorumCert → Author × Signature → Vote rebuildVote qc (α , sig) = record { _vVoteData = _qcVoteData qc ; _vAuthor = α ; _vLedgerInfo = qc ^∙ (qcSignedLedgerInfo ∙ liwsLedgerInfo) ; _vSignature = sig ; _vTimeoutSignature = nothing -- Is this correct? The original vote may have had a -- timeout signature, but we don't know. Does it -- matter? } -- Two votes are equivalent if they are identical except they may differ on timeout signature _≈Vote_ : (v1 v2 : Vote) → Set v1 ≈Vote v2 = v2 ≡ record v1 { _vTimeoutSignature = _vTimeoutSignature v2 } qcVotesKV : QuorumCert → KVMap Author Signature qcVotesKV = _liwsSignatures ∘ _qcSignedLedgerInfo qcVotes : QuorumCert → List (Author × Signature) qcVotes qc = kvm-toList (qcVotesKV qc) -- not defined in Haskell qcCertifies : Lens QuorumCert Hash qcCertifies = qcVoteData ∙ vdProposed ∙ biId -- not defined in Haskell qcRound : Lens QuorumCert Round qcRound = qcVoteData ∙ vdProposed ∙ biRound _qcCertifies : QuorumCert → Hash _qcCertifies q = q ^∙ qcCertifies _qcRound : QuorumCert → Round _qcRound q = q ^∙ qcRound -- ------------------------------------------------------------------------------ record TimeoutCertificate : Set where constructor mkTimeoutCertificate field _tcTimeout : Timeout _tcSignatures : KVMap Author Signature open TimeoutCertificate public unquoteDecl tcTimeout tcSignatures = mkLens (quote TimeoutCertificate) (tcTimeout ∷ tcSignatures ∷ []) TimeoutCertificate∙new : Timeout → TimeoutCertificate TimeoutCertificate∙new to = mkTimeoutCertificate to Map.empty -- getter only in haskell tcEpoch : Lens TimeoutCertificate Epoch tcEpoch = tcTimeout ∙ toEpoch -- getter only in haskell tcRound : Lens TimeoutCertificate Round tcRound = tcTimeout ∙ toRound -- ------------------------------------------------------------------------------ data BlockType : Set where Proposal : TX → Author → BlockType NilBlock : BlockType Genesis : BlockType postulate instance enc-BlockType : Encoder BlockType postulate -- Valid assumption, payloadIsEmpty -- TODO-1 : Need to decide what empty means. -- Only important on epoch change. payloadIsEmpty : TX → Bool _≟BlockType_ : (b₁ b₂ : BlockType) → Dec (b₁ ≡ b₂) Genesis ≟BlockType Genesis = true because ofʸ refl NilBlock ≟BlockType NilBlock = true because ofʸ refl (Proposal t₁ a₁) ≟BlockType (Proposal t₂ a₂) with t₁ ≟ t₂ ...| no no-t = no λ where refl → no-t refl ...| yes refl with a₁ ≟ a₂ ...| no no-a = no λ where refl → no-a refl ...| yes refl = yes refl Genesis ≟BlockType NilBlock = no (λ ()) Genesis ≟BlockType (Proposal _ _) = no (λ ()) NilBlock ≟BlockType Genesis = no (λ ()) NilBlock ≟BlockType (Proposal _ _) = no (λ ()) (Proposal _ _) ≟BlockType Genesis = no (λ ()) (Proposal _ _) ≟BlockType NilBlock = no (λ ()) instance Eq-BlockType : Eq BlockType Eq._≟_ Eq-BlockType = _≟BlockType_ record BlockData : Set where constructor BlockData∙new field _bdEpoch : Epoch _bdRound : Round -- QUESTION: How do we represent a block that extends the -- genesis block, which doesn't come with a QC. Maybe the -- genesis block has an associated QC established for the epoch? _bdQuorumCert : QuorumCert _bdBlockType : BlockType open BlockData public unquoteDecl bdEpoch bdRound bdQuorumCert bdBlockType = mkLens (quote BlockData) (bdEpoch ∷ bdRound ∷ bdQuorumCert ∷ bdBlockType ∷ []) postulate instance enc-BlockData : Encoder BlockData -- not defined in Haskell bdParentId : Lens BlockData Hash bdParentId = bdQuorumCert ∙ qcVoteData ∙ vdParent ∙ biId -- not defined in Haskell -- This is the id of a block bdBlockId : Lens BlockData Hash bdBlockId = bdQuorumCert ∙ qcVoteData ∙ vdProposed ∙ biId -- getter only in Haskell bdAuthor : Lens BlockData (Maybe Author) bdAuthor = mkLens' g s where g : BlockData → Maybe Author g bd = case (bd ^∙ bdBlockType) of λ where (Proposal _ author) → just author _ → nothing s : BlockData → Maybe Author → BlockData s bd nothing = bd s bd (just auth) = bd & bdBlockType %~ λ where (Proposal tx _) → Proposal tx auth bdt → bdt -- getter only in Haskell bdPayload : Lens BlockData (Maybe TX) bdPayload = mkLens' g s where g : BlockData → Maybe TX g bd = case bd ^∙ bdBlockType of λ where (Proposal a _) → just a _ → nothing s : BlockData → Maybe TX → BlockData s bd _ = bd -- TODO-1 : cannot be done: need a way to define only getters -- ------------------------------------------------------------------------------ -- The signature is a Maybe to allow us to use 'nothing' as the -- 'bSignature' when constructing a block to sign later. Also, -- "nil" blocks are not signed because they are produced -- independently by different validators. This is to enable -- committing after an epoch-changing command is processed: we -- cannot add more commands, but we need to add some quorum -- certificates in order to commit the epoch-changing command. record Block : Set where constructor Block∙new field _bId : HashValue _bBlockData : BlockData _bSignature : Maybe Signature open Block public unquoteDecl bId bBlockData bSignature = mkLens (quote Block) (bId ∷ bBlockData ∷ bSignature ∷ []) postulate instance enc : Encoder Block -- getter only in Haskell bAuthor : Lens Block (Maybe Author) bAuthor = bBlockData ∙ bdAuthor -- getter only in Haskell bEpoch : Lens Block Epoch bEpoch = bBlockData ∙ bdEpoch -- getter only in Haskell bRound : Lens Block Round bRound = bBlockData ∙ bdRound -- getter only in Haskell bQuorumCert : Lens Block QuorumCert bQuorumCert = bBlockData ∙ bdQuorumCert -- getter only in Haskell bParentId : Lens Block HashValue bParentId = bQuorumCert ∙ qcCertifiedBlock ∙ biId -- getter only in Haskell bPayload : Lens Block (Maybe TX) bPayload = bBlockData ∙ bdPayload bdQcSigs : Lens Block (KVMap Author Signature) bdQcSigs = bBlockData ∙ bdQuorumCert ∙ qcLedgerInfo ∙ liwsSignatures -- Equivalence of Blocks modulo signatures (both on the Block and in the QuorumCert it contains) infix 4 _≈Block_ _≈Block_ : (b₁ b₂ : Block) → Set b₁ ≈Block b₂ = b₁ ≡ (b₂ & bSignature ∙~ (b₁ ^∙ bSignature) & bdQcSigs ∙~ (b₁ ^∙ bdQcSigs)) sym≈Block : Symmetric _≈Block_ sym≈Block refl = refl -- ------------------------------------------------------------------------------ record AccumulatorExtensionProof : Set where constructor AccumulatorExtensionProof∙new field _aepObmNumLeaves : Version open AccumulatorExtensionProof public unquoteDecl aepObmNumLeaves = mkLens (quote AccumulatorExtensionProof) (aepObmNumLeaves ∷ []) record VoteProposal : Set where constructor VoteProposal∙new field _vpAccumulatorExtensionProof : AccumulatorExtensionProof _vpBlock : Block _vpNextEpochState : Maybe EpochState open VoteProposal public unquoteDecl vpAccumulatorExtensionProof vpBlock vpNextEpochState = mkLens (quote VoteProposal) (vpAccumulatorExtensionProof ∷ vpBlock ∷ vpNextEpochState ∷ []) record MaybeSignedVoteProposal : Set where constructor MaybeSignedVoteProposal∙new field _msvpVoteProposal : VoteProposal open MaybeSignedVoteProposal public unquoteDecl msvpVoteProposal = mkLens (quote MaybeSignedVoteProposal) (msvpVoteProposal ∷ []) -- ------------------------------------------------------------------------------ record LastVoteInfo : Set where constructor LastVoteInfo∙new field _lviLiDigest : HashValue _lviRound : Round _lviIsTimeout : Bool open LastVoteInfo public record PendingVotes : Set where constructor mkPendingVotes field _pvLiDigestToVotes : KVMap HashValue LedgerInfoWithSignatures _pvMaybePartialTC : Maybe TimeoutCertificate _pvAuthorToVote : KVMap Author Vote open PendingVotes public unquoteDecl pvLiDigestToVotes pvMaybePartialTC pvAuthorToVote = mkLens (quote PendingVotes) (pvLiDigestToVotes ∷ pvMaybePartialTC ∷ pvAuthorToVote ∷ []) PendingVotes∙new : PendingVotes PendingVotes∙new = mkPendingVotes Map.empty nothing Map.empty -- ------------------------------------------------------------------------------ record StateComputeResult : Set where constructor StateComputeResult∙new field _scrObmNumLeaves : Version _scrEpochState : Maybe EpochState open StateComputeResult public unquoteDecl scrObmNumLeaves scrEpochState = mkLens (quote StateComputeResult) (scrObmNumLeaves ∷ scrEpochState ∷ []) postulate -- TODO: eliminate after fully implementing executeBlockE stateComputeResult : StateComputeResult record ExecutedBlock : Set where constructor ExecutedBlock∙new field _ebBlock : Block _ebStateComputeResult : StateComputeResult open ExecutedBlock public unquoteDecl ebBlock ebStateComputeResult = mkLens (quote ExecutedBlock) (ebBlock ∷ ebStateComputeResult ∷ []) -- getter only in Haskell ebId : Lens ExecutedBlock HashValue ebId = ebBlock ∙ bId -- getter only in Haskell ebQuorumCert : Lens ExecutedBlock QuorumCert ebQuorumCert = ebBlock ∙ bQuorumCert -- getter only in Haskell ebParentId : Lens ExecutedBlock HashValue ebParentId = ebQuorumCert ∙ qcCertifiedBlock ∙ biId -- getter only in Haskell ebRound : Lens ExecutedBlock Round ebRound = ebBlock ∙ bRound -- ------------------------------------------------------------------------------ record LinkableBlock : Set where constructor LinkableBlock∙new field _lbExecutedBlock : ExecutedBlock -- _lbChildren : Set HashValue open LinkableBlock public unquoteDecl lbExecutedBlock = mkLens (quote LinkableBlock) (lbExecutedBlock ∷ []) -- getter only in Haskell lbId : Lens LinkableBlock HashValue lbId = lbExecutedBlock ∙ ebId -- ------------------------------------------------------------------------------ -- A block tree depends on a epoch config but works regardlesss of which -- EpochConfig we have. record BlockTree : Set where constructor mkBlockTree field _btIdToBlock : KVMap HashValue LinkableBlock _btRootId : HashValue _btHighestCertifiedBlockId : HashValue _btHighestQuorumCert : QuorumCert _btHighestTimeoutCert : Maybe TimeoutCertificate _btHighestCommitCert : QuorumCert _btIdToQuorumCert : KVMap HashValue QuorumCert _btPrunedBlockIds : VecDeque _btMaxPrunedBlocksInMem : ℕ open BlockTree public unquoteDecl btIdToBlock btRootId btHighestCertifiedBlockId btHighestQuorumCert btHighestTimeoutCert btHighestCommitCert btIdToQuorumCert btPrunedBlockIds btMaxPrunedBlocksInMem = mkLens (quote BlockTree) (btIdToBlock ∷ btRootId ∷ btHighestCertifiedBlockId ∷ btHighestQuorumCert ∷ btHighestTimeoutCert ∷ btHighestCommitCert ∷ btIdToQuorumCert ∷ btPrunedBlockIds ∷ btMaxPrunedBlocksInMem ∷ []) btGetLinkableBlock : HashValue → BlockTree → Maybe LinkableBlock btGetLinkableBlock hv bt = Map.lookup hv (bt ^∙ btIdToBlock) btGetBlock : HashValue → BlockTree → Maybe ExecutedBlock btGetBlock hv bt = (_^∙ lbExecutedBlock) <$> btGetLinkableBlock hv bt -- getter only in Haskell btRoot : Lens BlockTree (Maybe ExecutedBlock) btRoot = mkLens' g s where g : BlockTree → Maybe ExecutedBlock g bt = btGetBlock (bt ^∙ btRootId) bt -- TODO-1 : the setter is not needed/defined in Haskell -- Defining it just to make progress, but it can't be defined -- correctly in terms of type correctness (let alone setting a new root!) s : BlockTree → Maybe ExecutedBlock → BlockTree s bt _ = bt -- TODO-1 : cannot be done: need a way to defined only getters -- getter only in haskell btHighestCertifiedBlock : Lens BlockTree (Maybe ExecutedBlock) btHighestCertifiedBlock = mkLens' g s where g : BlockTree → (Maybe ExecutedBlock) g bt = btGetBlock (bt ^∙ btHighestCertifiedBlockId) bt s : BlockTree → (Maybe ExecutedBlock) → BlockTree s bt _ = bt -- TODO-1 : cannot be done: need a way to defined only getters -- ------------------------------------------------------------------------------ record LedgerStore : Set where constructor mkLedgerStore field _lsObmVersionToEpoch : Map.KVMap Version Epoch _lsObmEpochToLIWS : Map.KVMap Epoch LedgerInfoWithSignatures _lsLatestLedgerInfo : Maybe LedgerInfoWithSignatures open LedgerStore public unquoteDecl lsObmVersionToEpoch lsObmEpochToLIWS lsLatestLedgerInfo = mkLens (quote LedgerStore) (lsObmVersionToEpoch ∷ lsObmEpochToLIWS ∷ lsLatestLedgerInfo ∷ []) record DiemDB : Set where constructor DiemDB∙new field _ddbLedgerStore : LedgerStore open DiemDB public unquoteDecl ddbLedgerStore = mkLens (quote DiemDB) (ddbLedgerStore ∷ []) record LedgerRecoveryData : Set where constructor LedgerRecoveryData∙new field _lrdStorageLedger : LedgerInfo record MockSharedStorage : Set where constructor mkMockSharedStorage field -- Safety state _mssBlock : Map.KVMap HashValue Block _mssQc : Map.KVMap HashValue QuorumCert _mssLis : Map.KVMap Version LedgerInfoWithSignatures _mssLastVote : Maybe Vote -- Liveness state _mssHighestTimeoutCertificate : Maybe TimeoutCertificate _mssValidatorSet : ValidatorSet open MockSharedStorage public unquoteDecl mssBlock mssQc mssLis mssLastVote mssHighestTimeoutCertificate mssValidatorSet = mkLens (quote MockSharedStorage) (mssBlock ∷ mssQc ∷ mssLis ∷ mssLastVote ∷ mssHighestTimeoutCertificate ∷ mssValidatorSet ∷ []) record MockStorage : Set where constructor MockStorage∙new field _msSharedStorage : MockSharedStorage _msStorageLedger : LedgerInfo _msObmDiemDB : DiemDB open MockStorage public unquoteDecl msSharedStorage msStorageLedger msObmDiemDB = mkLens (quote MockStorage) (msSharedStorage ∷ msStorageLedger ∷ msObmDiemDB ∷ []) PersistentLivenessStorage = MockStorage -- IMPL-DIFF : This is defined without record fields in Haskell. -- The record fields below are never used. But RootInfo must be a record for pattern matching. record RootInfo : Set where constructor RootInfo∙new field _riBlock : Block _riQC1 : QuorumCert _riQC2 : QuorumCert -- ------------------------------------------------------------------------------ record SafetyData : Set where constructor SafetyData∙new field _sdEpoch : Epoch _sdLastVotedRound : Round _sdPreferredRound : Round _sdLastVote : Maybe Vote open SafetyData public unquoteDecl sdEpoch sdLastVotedRound sdPreferredRound sdLastVote = mkLens (quote SafetyData) (sdEpoch ∷ sdLastVotedRound ∷ sdPreferredRound ∷ sdLastVote ∷ []) record Waypoint : Set where constructor Waypoint∙new field _wVersion : Version _wValue : HashValue open Waypoint public unquoteDecl wVersion wValue = mkLens (quote Waypoint) (wVersion ∷ wValue ∷ []) postulate instance enc-Waypoint : Encoder Waypoint record PersistentSafetyStorage : Set where constructor mkPersistentSafetyStorage field _pssSafetyData : SafetyData _pssAuthor : Author _pssWaypoint : Waypoint _pssObmSK : Maybe SK open PersistentSafetyStorage public unquoteDecl pssSafetyData pssAuthor pssWaypoint pssObmSK = mkLens (quote PersistentSafetyStorage) (pssSafetyData ∷ pssAuthor ∷ pssWaypoint ∷ pssObmSK ∷ []) record OnChainConfigPayload : Set where constructor OnChainConfigPayload∙new field _occpEpoch : Epoch _occpObmValidatorSet : ValidatorSet open OnChainConfigPayload public unquoteDecl occpEpoch occpObmValidatorSet = mkLens (quote OnChainConfigPayload) (occpEpoch ∷ occpObmValidatorSet ∷ []) -- instance S.Serialize OnChainConfigPayload record ReconfigEventEpochChange : Set where constructor ReconfigEventEpochChange∙new field _reecOnChainConfigPayload : OnChainConfigPayload -- instance S.Serialize ReconfigEventEpochChange -- ------------------------------------------------------------------------------ -- IMPL-DIFF : Haskell StateComputer has pluggable functions. -- The Agda version just calls them directly record StateComputer : Set where constructor StateComputer∙new field _scObmVersion : Version open StateComputer public unquoteDecl scObmVersion = mkLens (quote StateComputer) (scObmVersion ∷ []) StateComputerComputeType = StateComputer → Block → HashValue → Either (List String) StateComputeResult StateComputerCommitType = StateComputer → DiemDB → ExecutedBlock → LedgerInfoWithSignatures → Either (List String) (StateComputer × DiemDB × Maybe ReconfigEventEpochChange) StateComputerSyncToType = LedgerInfoWithSignatures → Either (List String) ReconfigEventEpochChange -- ------------------------------------------------------------------------------ record BlockStore : Set where constructor BlockStore∙new field _bsInner : BlockTree _bsStateComputer : StateComputer _bsStorage : PersistentLivenessStorage open BlockStore public unquoteDecl bsInner bsStateComputer bsStorage = mkLens (quote BlockStore) (bsInner ∷ bsStateComputer ∷ bsStorage ∷ []) postulate -- TODO: stateComputer stateComputer : StateComputer -- getter only in Haskell bsRoot : Lens BlockStore (Maybe ExecutedBlock) bsRoot = bsInner ∙ btRoot -- getter only in Haskell bsHighestQuorumCert : Lens BlockStore QuorumCert bsHighestQuorumCert = bsInner ∙ btHighestQuorumCert -- getter only in Haskell bsHighestCommitCert : Lens BlockStore QuorumCert bsHighestCommitCert = bsInner ∙ btHighestCommitCert -- getter only in Haskell bsHighestTimeoutCert : Lens BlockStore (Maybe TimeoutCertificate) bsHighestTimeoutCert = bsInner ∙ btHighestTimeoutCert -- ------------------------------------------------------------------------------ data NewRoundReason : Set where QCReady : NewRoundReason TOReady : NewRoundReason record NewRoundEvent : Set where constructor NewRoundEvent∙new field _nreRound : Round _nreReason : NewRoundReason _nreTimeout : Duration unquoteDecl nreRound nreReason nreTimeout = mkLens (quote NewRoundEvent) (nreRound ∷ nreReason ∷ nreTimeout ∷ []) -- LibraBFT.ImplShared.Consensus.Types contains -- ExponentialTimeInterval, RoundState -- ------------------------------------------------------------------------------ record ProposalGenerator : Set where constructor ProposalGenerator∙new field _pgLastRoundGenerated : Round open ProposalGenerator unquoteDecl pgLastRoundGenerated = mkLens (quote ProposalGenerator) (pgLastRoundGenerated ∷ []) -- ------------------------------------------------------------------------------ data ObmNotValidProposerReason : Set where ProposalDoesNotHaveAnAuthor ProposerForBlockIsNotValidForThisRound NotValidProposer : ObmNotValidProposerReason record ProposerElection : Set where constructor ProposerElection∙new field _peProposers : List Author -- TODO-1 : this should be 'Set Author' -- _peObmLeaderOfRound : LeaderOfRoundFn -- _peObmNodesInOrder : NodesInOrder open ProposerElection -- ------------------------------------------------------------------------------ record SafetyRules : Set where constructor mkSafetyRules field _srPersistentStorage : PersistentSafetyStorage _srExportConsensusKey : Bool _srValidatorSigner : Maybe ValidatorSigner _srEpochState : Maybe EpochState open SafetyRules public unquoteDecl srPersistentStorage srExportConsensusKey srValidatorSigner srEpochState = mkLens (quote SafetyRules) (srPersistentStorage ∷ srExportConsensusKey ∷ srValidatorSigner ∷ srEpochState ∷ []) -- ------------------------------------------------------------------------------ record BlockRetrievalRequest : Set where constructor BlockRetrievalRequest∙new field _brqObmFrom : Author _brqBlockId : HashValue _brqNumBlocks : U64 open BlockRetrievalRequest public unquoteDecl brqObmFrom brqBlockId brqNumBlocks = mkLens (quote BlockRetrievalRequest) (brqObmFrom ∷ brqBlockId ∷ brqNumBlocks ∷ []) postulate instance enc-BlockRetrievalRequest : Encoder BlockRetrievalRequest data BlockRetrievalStatus : Set where BRSSucceeded BRSIdNotFound BRSNotEnoughBlocks : BlockRetrievalStatus open BlockRetrievalStatus public postulate instance enc-BlockRetrievalState : Encoder BlockRetrievalStatus brs-eq : (brs₁ brs₂ : BlockRetrievalStatus) → Dec (brs₁ ≡ brs₂) brs-eq BRSSucceeded BRSSucceeded = yes refl brs-eq BRSSucceeded BRSIdNotFound = no λ () brs-eq BRSSucceeded BRSNotEnoughBlocks = no λ () brs-eq BRSIdNotFound BRSSucceeded = no λ () brs-eq BRSIdNotFound BRSIdNotFound = yes refl brs-eq BRSIdNotFound BRSNotEnoughBlocks = no λ () brs-eq BRSNotEnoughBlocks BRSSucceeded = no λ () brs-eq BRSNotEnoughBlocks BRSIdNotFound = no λ () brs-eq BRSNotEnoughBlocks BRSNotEnoughBlocks = yes refl instance Eq-BlockRetrievalStatus : Eq BlockRetrievalStatus Eq._≟_ Eq-BlockRetrievalStatus = brs-eq record BlockRetrievalResponse : Set where constructor BlockRetrievalResponse∙new field _brpObmFrom : (Author × Epoch × Round) -- for logging _brpStatus : BlockRetrievalStatus _brpBlocks : List Block unquoteDecl brpObmFrom brpStatus brpBlocks = mkLens (quote BlockRetrievalResponse) (brpObmFrom ∷ brpStatus ∷ brpBlocks ∷ []) postulate instance enc-BlockRetrievalResponse : Encoder BlockRetrievalResponse -- ------------------------------------------------------------------------------ -- LibraBFT.ImplShared.Consensus.Types contains -- ObmNeedFetch, RoundManager -- ------------------------------------------------------------------------------ record BlockRetriever : Set where constructor BlockRetriever∙new field _brDeadline : Instant _brPreferredPeer : Author open BlockRetriever public unquoteDecl brDeadline brPreferredPeer = mkLens (quote BlockRetriever) (brDeadline ∷ brPreferredPeer ∷ []) -- ------------------------------------------------------------------------------ record SyncInfo : Set where constructor mkSyncInfo -- Bare constructor to enable pattern matching against SyncInfo; "smart" -- constructor SyncInfo∙new is below field _siHighestQuorumCert : QuorumCert _sixxxHighestCommitCert : Maybe QuorumCert _siHighestTimeoutCert : Maybe TimeoutCertificate open SyncInfo public -- Note that we do not automatically derive a lens for siHighestCommitCert; -- it is defined manually below. unquoteDecl siHighestQuorumCert sixxxHighestCommitCert siHighestTimeoutCert = mkLens (quote SyncInfo) (siHighestQuorumCert ∷ sixxxHighestCommitCert ∷ siHighestTimeoutCert ∷ []) postulate instance enc-SyncInfo : Encoder SyncInfo SyncInfo∙new : QuorumCert → QuorumCert → Maybe TimeoutCertificate → SyncInfo SyncInfo∙new highestQuorumCert highestCommitCert highestTimeoutCert = record { _siHighestQuorumCert = highestQuorumCert ; _sixxxHighestCommitCert = if highestQuorumCert QCBoolEq highestCommitCert then nothing else (just highestCommitCert) ; _siHighestTimeoutCert = highestTimeoutCert } -- getter only in Haskell siHighestCommitCert : Lens SyncInfo QuorumCert siHighestCommitCert = mkLens' (λ x → fromMaybe (x ^∙ siHighestQuorumCert) (x ^∙ sixxxHighestCommitCert)) (λ x qc → record x { _sixxxHighestCommitCert = just qc }) -- getter only in Haskell siHighestCertifiedRound : Lens SyncInfo Round siHighestCertifiedRound = siHighestQuorumCert ∙ qcCertifiedBlock ∙ biRound -- getter only in Haskell siHighestTimeoutRound : Lens SyncInfo Round siHighestTimeoutRound = mkLens' (maybe 0 (_^∙ tcRound) ∘ (_^∙ siHighestTimeoutCert)) (λ x _r → x) -- TODO-1 -- getter only in Haskell siHighestCommitRound : Lens SyncInfo Round siHighestCommitRound = siHighestCommitCert ∙ qcCommitInfo ∙ biRound -- getter only in Haskell siHighestRound : Lens SyncInfo Round siHighestRound = mkLens' (λ x → (x ^∙ siHighestCertifiedRound) ⊔ (x ^∙ siHighestTimeoutRound)) (λ x _r → x) -- TODO-1 -- getter only in Haskell siEpoch : Lens SyncInfo Epoch siEpoch = siHighestQuorumCert ∙ qcCertifiedBlock ∙ biEpoch -- getter only in Haskell siObmRound : Lens SyncInfo Round siObmRound = siHighestQuorumCert ∙ qcCertifiedBlock ∙ biRound -- ------------------------------------------------------------------------------ record ProposalMsg : Set where constructor ProposalMsg∙new field _pmProposal : Block _pmSyncInfo : SyncInfo open ProposalMsg public unquoteDecl pmProposal pmSyncInfo = mkLens (quote ProposalMsg) (pmProposal ∷ pmSyncInfo ∷ []) postulate instance enc-ProposalMsg : Encoder ProposalMsg -- getter only in Haskell pmEpoch : Lens ProposalMsg Epoch pmEpoch = pmProposal ∙ bEpoch -- getter only in Haskell pmRound : Lens ProposalMsg Round pmRound = pmProposal ∙ bRound -- getter only in Haskell pmProposer : Lens ProposalMsg (Maybe Author) pmProposer = pmProposal ∙ bAuthor -- ------------------------------------------------------------------------------ record VoteMsg : Set where constructor VoteMsg∙new field _vmVote : Vote _vmSyncInfo : SyncInfo open VoteMsg public unquoteDecl vmVote vmSyncInfo = mkLens (quote VoteMsg) (vmVote ∷ vmSyncInfo ∷ []) postulate instance enc-VoteMsg : Encoder VoteMsg -- not defined in Haskell vmProposed : Lens VoteMsg BlockInfo vmProposed = vmVote ∙ vVoteData ∙ vdProposed -- not defined in Haskell vmParent : Lens VoteMsg BlockInfo vmParent = vmVote ∙ vVoteData ∙ vdParent -- getter-only in Haskell vmEpoch : Lens VoteMsg Epoch vmEpoch = vmVote ∙ vEpoch -- getter-only in Haskell vmRound : Lens VoteMsg Round vmRound = vmVote ∙ vRound -- ------------------------------------------------------------------------------ -- This is a notification of a commit. It may not be explicitly included in an implementation, -- but we need something to be able to express correctness conditions. It will -- probably have something different in it, but will serve the purpose for now. record CommitMsg : Set where constructor CommitMsg∙new field _cmEpoch : Epoch _cmAuthor : NodeId _cmRound : Round _cmCert : QuorumCert -- We assume for now that a CommitMsg contains the QuorumCert of the head of the 3-chain _cmSigMB : Maybe Signature open CommitMsg public unquoteDecl cmEpoch cmAuthor cmRound cmCert cmSigMB = mkLens (quote CommitMsg) (cmEpoch ∷ cmAuthor ∷ cmRound ∷ cmCert ∷ cmSigMB ∷ []) postulate instance enc-CommitMsg : Encoder CommitMsg -- ------------------------------------------------------------------------------ data RootMetadata : Set where RootMetadata∙new : RootMetadata -- ------------------------------------------------------------------------------ record RecoveryData : Set where constructor mkRecoveryData field _rdLastVote : Maybe Vote _rdRoot : RootInfo _rdRootMetadata : RootMetadata _rdBlocks : List Block _rdQuorumCerts : List QuorumCert _rdBlocksToPrune : Maybe (List HashValue) _rdHighestTimeoutCertificate : Maybe TimeoutCertificate open RecoveryData public unquoteDecl rdLastVote rdRoot rdRootMetadata rdBlocks rdQuorumCerts rdBlocksToPrune rdHighestTimeoutCertificate = mkLens (quote RecoveryData) (rdLastVote ∷ rdRoot ∷ rdRootMetadata ∷ rdBlocks ∷ rdQuorumCerts ∷ rdBlocksToPrune ∷ rdHighestTimeoutCertificate ∷ []) ------------------------------------------------------------------------------ record EpochChangeProof : Set where constructor EpochChangeProof∙new field _ecpLedgerInfoWithSigs : List LedgerInfoWithSignatures _ecpMore : Bool open EpochChangeProof public unquoteDecl ecpLedgerInfoWithSigs ecpMore = mkLens (quote EpochChangeProof) (ecpLedgerInfoWithSigs ∷ ecpMore ∷ []) -- instance S.Serialize EpochChangeProof record Ledger2WaypointConverter : Set where constructor mkLedger2WaypointConverter field _l2wcEpoch : Epoch _l2wcRootHash : HashValue _l2wcVersion : Version --_l2wcTimestamp : Instant _l2wcNextEpochState : Maybe EpochState open Ledger2WaypointConverter public unquoteDecl l2wcEpoch 2wcRootHash 2wcVersion {-l2wcTimestamp-} l2wcNextEpochState = mkLens (quote Ledger2WaypointConverter) (l2wcEpoch ∷ 2wcRootHash ∷ 2wcVersion ∷ {-l2wcTimestamp-} l2wcNextEpochState ∷ []) record EpochRetrievalRequest : Set where constructor EpochRetrievalRequest∙new field _eprrqStartEpoch : Epoch _eprrqEndEpoch : Epoch unquoteDecl eprrqStartEpoch eprrqEndEpoch = mkLens (quote EpochRetrievalRequest) (eprrqStartEpoch ∷ eprrqEndEpoch ∷ []) -- instance S.Serialize EpochRetrievalRequest ------------------------------------------------------------------------------ record ConsensusState : Set where constructor ConsensusState∙new field _csSafetyData : SafetyData _csWaypoint : Waypoint --_csInValidatorSet : Bool -- LBFT-OBM-DIFF: only used in tests in Rust open ConsensusState public unquoteDecl csSafetyData csWaypoint {-csInValidatorSet-} = mkLens (quote ConsensusState) (csSafetyData ∷ csWaypoint {-∷ csInValidatorSet-} ∷ []) ------------------------------------------------------------------------------ data SafetyRulesWrapper : Set where SRWLocal : SafetyRules → SafetyRulesWrapper record SafetyRulesManager : Set where constructor mkSafetyRulesManager field _srmInternalSafetyRules : SafetyRulesWrapper open SafetyRulesWrapper public unquoteDecl srmInternalSafetyRules = mkLens (quote SafetyRulesManager) (srmInternalSafetyRules ∷ []) data SafetyRulesService : Set where SRSLocal : SafetyRulesService record SafetyRulesConfig : Set where constructor SafetyRulesConfig∙new field _srcService : SafetyRulesService _srcExportConsensusKey : Bool _srcObmGenesisWaypoint : Waypoint open SafetyRulesConfig public unquoteDecl srcService srcExportConsensusKey srcObmGenesisWaypoint = mkLens (quote SafetyRulesConfig) (srcService ∷ srcExportConsensusKey ∷ srcObmGenesisWaypoint ∷ []) record ConsensusConfig : Set where constructor ConsensusConfig∙new field _ccMaxPrunedBlocksInMem : Usize _ccRoundInitialTimeoutMS : U64 _ccSafetyRules : SafetyRulesConfig _ccSyncOnly : Bool open ConsensusConfig public unquoteDecl ccMaxPrunedBlocksInMem ccRoundInitialTimeoutMS ccSafetyRules ccSyncOnly = mkLens (quote ConsensusConfig) (ccMaxPrunedBlocksInMem ∷ ccRoundInitialTimeoutMS ∷ ccSafetyRules ∷ ccSyncOnly ∷ []) record NodeConfig : Set where constructor NodeConfig∙new field _ncObmMe : AuthorName _ncConsensus : ConsensusConfig open NodeConfig public unquoteDecl ncObmMe ncConsensus = mkLens (quote NodeConfig) (ncObmMe ∷ ncConsensus ∷ []) record RecoveryManager : Set where constructor RecoveryManager∙new field _rcmEpochState : EpochState _rcmStorage : PersistentLivenessStorage --_rcmStateComputer : StateComputer _rcmLastCommittedRound : Round open RecoveryManager public unquoteDecl rcmEpochState rcmStorage {- rcmStateComputer-} rcmLastCommittedRound = mkLens (quote RecoveryManager) (rcmEpochState ∷ rcmStorage {-∷ rcmStateComputer-} ∷ rcmLastCommittedRound ∷ []) -- RoundProcessor in EpochManagerTypes (because it depends on RoundManager) -- EpochManager in EpochManagerTypes (because it depends on RoundProcessor) -- ------------------------------------------------------------------------------ data VoteReceptionResult : Set where QCVoteAdded : U64 → VoteReceptionResult TCVoteAdded : U64 → VoteReceptionResult DuplicateVote : VoteReceptionResult EquivocateVote : VoteReceptionResult NewQuorumCertificate : QuorumCert → VoteReceptionResult NewTimeoutCertificate : TimeoutCertificate → VoteReceptionResult UnexpectedRound : Round → Round → VoteReceptionResult VRR_TODO : VoteReceptionResult -- ------------------------------------------------------------------------------ -- LibraBFT.ImplShared.Interface.Output contains -- Output -- ------------------------------------------------------------------------------ data VerifyError : Set where UnknownAuthor : AuthorName → VerifyError TooLittleVotingPower : U64 → U64 → VerifyError TooManySignatures : Usize → Usize → VerifyError InvalidSignature : VerifyError
{ "alphanum_fraction": 0.6474355254, "avg_line_length": 37.1848920863, "ext": "agda", "hexsha": "22af0cbd64cb6d3008b5502ec90f7456040d3afd", "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/ImplShared/Consensus/Types/EpochIndep.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/ImplShared/Consensus/Types/EpochIndep.agda", "max_line_length": 124, "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/ImplShared/Consensus/Types/EpochIndep.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 13850, "size": 51687 }
-- Actually, we're cheating (for expediency); this is -- Symmetric Rig, not just Rig. module Categories.RigCategory where open import Level open import Data.Fin renaming (zero to 0F; suc to sucF) open import Data.Product using (_,_) open import Categories.Category open import Categories.Functor open import Categories.Monoidal open import Categories.Monoidal.Braided open import Categories.Monoidal.Braided.Helpers open import Categories.Monoidal.Symmetric open import Categories.Monoidal.Helpers open import Categories.NaturalIsomorphism open import Categories.NaturalTransformation using (_∘₀_; _∘₁_; _∘ˡ_; _∘ʳ_; NaturalTransformation) renaming (_≡_ to _≡ⁿ_; id to idⁿ) -- first round of setting up, just for defining the NaturalIsomorphisms -- of Rig. Next one will be for the equalities. module BimonoidalHelperFunctors {o ℓ e} {C : Category o ℓ e} {M⊎ M× : Monoidal C} (B⊎ : Braided M⊎) (B× : Braided M×) where private module C = Category C module M⊎ = Monoidal M⊎ module M× = Monoidal M× module B⊎ = Braided B⊎ module B× = Braided B× module h⊎ = MonoidalHelperFunctors C M⊎.⊗ M⊎.id module h× = MonoidalHelperFunctors C M×.⊗ M×.id module b⊎ = BraidedHelperFunctors C M⊎.⊗ M⊎.id module b× = BraidedHelperFunctors C M×.⊗ M×.id module br⊎ = b⊎.Braiding M⊎.identityˡ M⊎.identityʳ M⊎.assoc B⊎.braid module br× = b×.Braiding M×.identityˡ M×.identityʳ M×.assoc B×.braid import Categories.Power.NaturalTransformation private module PowNat = Categories.Power.NaturalTransformation C open PowNat hiding (module C) -- for convenience of multiple of the larger equations, define -- shorthands for 3 and 4 variables x⊗z : Powerendo 3 x⊗z = select 0 h×.⊗₂ select 2 z⊗x : Powerendo 3 z⊗x = (select 2) h×.⊗₂ (select 0) z⊗y : Powerendo 3 z⊗y = select 2 h×.⊗₂ select 1 y⊗z : Powerendo 3 y⊗z = select 1 h×.⊗₂ select 2 x : Powerendo 4 x = select 0 y : Powerendo 4 y = select 1 z : Powerendo 4 z = select 2 w : Powerendo 4 w = select 3 -- combinations of 3 variables x⊗[y⊕z] : Powerendo 3 x⊗[y⊕z] = h×.x h×.⊗ (h⊎.x⊗y) x⊗[z⊕y] : Powerendo 3 x⊗[z⊕y] = h×.x h×.⊗ h⊎.y⊗x [x⊕y]⊗z : Powerendo 3 [x⊕y]⊗z = (h⊎.x⊗y) h×.⊗ h×.x z⊗[x⊕y] : Powerendo 3 z⊗[x⊕y] = (select 2) h×.⊗₂ ((select 0) h⊎.⊗₂ (select 1)) [x⊗y]⊕[x⊗z] : Powerendo 3 [x⊗y]⊕[x⊗z] = (select 0 h×.⊗₂ select 1) h⊎.⊗₂ (select 0 h×.⊗₂ select 2) [x⊗z]⊕[y⊗z] : Powerendo 3 [x⊗z]⊕[y⊗z] = (select 0 h×.⊗₂ select 2) h⊎.⊗₂ (select 1 h×.⊗₂ select 2) [z⊗x]⊕[z⊗y] : Powerendo 3 [z⊗x]⊕[z⊗y] = z⊗x h⊎.⊗₂ z⊗y [x⊗z]⊕[x⊗y] : Powerendo 3 [x⊗z]⊕[x⊗y] = x⊗z h⊎.⊗₂ (select 0 h×.⊗₂ select 1) x⊗0 : Powerendo 1 x⊗0 = h⊎.x h×.⊗ h⊎.id↑ 0⊗x : Powerendo 1 0⊗x = h⊎.id↑ h×.⊗ h⊎.x 0↑ : Powerendo 1 0↑ = widenˡ 1 h⊎.id↑ xy : Powerendo 4 xy = widenʳ 2 h×.x⊗y yz : Powerendo 4 yz = select 1 h×.⊗₂ select 2 xw : Powerendo 4 xw = select 0 h×.⊗₂ select 3 yw : Powerendo 4 yw = select 1 h×.⊗₂ select 3 zw : Powerendo 4 zw = select 2 h×.⊗₂ select 3 xz : Powerendo 4 xz = select 0 h×.⊗₂ select 2 z⊕w : Powerendo 4 z⊕w = widenˡ 2 h⊎.x⊗y -- for 2 variables x₂ : Powerendo 2 x₂ = widenʳ 1 h×.x y₂ : Powerendo 2 y₂ = widenˡ 1 h×.x -- 0 variables! 0₀ : Powerendo 0 0₀ = h⊎.id↑ 0⊗0 : Powerendo 0 0⊗0 = 0₀ h×.⊗ 0₀ 0⊕0 : Powerendo 0 0⊕0 = 0₀ h⊎.⊗ 0₀ 1₀ : Powerendo 0 1₀ = h×.id↑ -- 1 variable + 0 A0 : Powerendo 1 A0 = h×.x h×.⊗ 0₀ 0A : Powerendo 1 0A = 0₀ h×.⊗ h×.x -- 2 variables + 0 0₂ : Powerendo 2 0₂ = widenʳ 2 0₀ 0[A⊕B] : Powerendo 2 0[A⊕B] = 0₂ h×.⊗₂ h⊎.x⊗y 0[AB] : Powerendo 2 0[AB] = 0₀ h×.⊗ (h×.x⊗y) [0A]B : Powerendo 2 [0A]B = 0A h×.⊗ h×.x 0A₂ : Powerendo 2 0A₂ = 0₂ h×.⊗₂ select 0 0B : Powerendo 2 0B = 0₂ h×.⊗₂ (select 1) A0₂ : Powerendo 2 A0₂ = select 0 h×.⊗₂ 0₂ AB : Powerendo 2 AB = h×.x⊗y 0A⊕0B : Powerendo 2 0A⊕0B = 0A₂ h⊎.⊗₂ 0B A[0B] : Powerendo 2 A[0B] = (widenʳ 1 h×.x) h×.⊗₂ 0B [A0]B : Powerendo 2 [A0]B = A0 h×.⊗ h×.x A[0⊕B] : Powerendo 2 A[0⊕B] = h×.x h×.⊗ h⊎.id⊗x A0⊕AB : Powerendo 2 A0⊕AB = A0₂ h⊎.⊗₂ AB 0⊕AB : Powerendo 2 0⊕AB = 0₂ h⊎.⊗₂ AB -- 2 variables + 1 1₂ : Powerendo 2 1₂ = widenʳ 2 1₀ A⊕B : Powerendo 2 A⊕B = h⊎.x⊗y 1[A⊕B] : Powerendo 2 1[A⊕B] = 1₀ h×.⊗ A⊕B 1A⊕1B : Powerendo 2 1A⊕1B = h×.id⊗x h⊎.⊗ h×.id⊗x -- like Laplaza, use concatenation for ⊗ to make things easier to read -- also ⊗ binds more tightly, so skip those parens -- combinations of 4 variables [x⊕[y⊕z]]w : Powerendo 4 [x⊕[y⊕z]]w = h⊎.x⊗[y⊗z] h×.⊗ h⊎.x xw⊕[y⊕z]w : Powerendo 4 xw⊕[y⊕z]w = (x h×.⊗₂ w) h⊎.⊗₂ ((y h⊎.⊗₂ z) h×.⊗₂ w) xw⊕[yw⊕zw] : Powerendo 4 xw⊕[yw⊕zw] = (x h×.⊗₂ w) h⊎.⊗₂ ((y h×.⊗₂ w) h⊎.⊗₂ (z h×.⊗₂ w)) [xw⊕yw]⊕zw : Powerendo 4 [xw⊕yw]⊕zw = ((x h×.⊗₂ w) h⊎.⊗₂ (y h×.⊗₂ w)) h⊎.⊗₂ (z h×.⊗₂ w) [[x⊕y]⊕z]w : Powerendo 4 [[x⊕y]⊕z]w = h⊎.[x⊗y]⊗z h×.⊗ h⊎.x [x⊕y]w⊕zw : Powerendo 4 [x⊕y]w⊕zw = ((x h⊎.⊗₂ y) h×.⊗₂ w) h⊎.⊗₂ (z h×.⊗₂ w) x[y[z⊕w]] : Powerendo 4 x[y[z⊕w]] = x h×.⊗₂ (y h×.⊗₂ (z h⊎.⊗₂ w)) x[yz⊕yw] : Powerendo 4 x[yz⊕yw] = x h×.⊗₂ ((y h×.⊗₂ z) h⊎.⊗₂ (y h×.⊗₂ w)) x[yz]⊕x[yw] : Powerendo 4 x[yz]⊕x[yw] = (x h×.⊗₂ (y h×.⊗₂ z)) h⊎.⊗₂ (x h×.⊗₂ (y h×.⊗₂ w)) [xy][z⊕w] : Powerendo 4 [xy][z⊕w] = (x h×.⊗₂ y) h×.⊗₂ (z h⊎.⊗₂ w) [xy]z⊕[xy]w : Powerendo 4 [xy]z⊕[xy]w = let xy = (x h×.⊗₂ y) in (xy h×.⊗₂ z) h⊎.⊗₂ (xy h×.⊗₂ w) x⊕y : Powerendo 4 x⊕y = widenʳ 2 h⊎.x⊗y x[z⊕w] : Powerendo 4 x[z⊕w] = x h×.⊗₂ z⊕w y[z⊕w] : Powerendo 4 y[z⊕w] = y h×.⊗₂ z⊕w xz⊕xw : Powerendo 4 xz⊕xw = xz h⊎.⊗₂ xw yz⊕yw : Powerendo 4 yz⊕yw = yz h⊎.⊗₂ yw xz⊕yz : Powerendo 4 xz⊕yz = xz h⊎.⊗₂ yz xw⊕yw : Powerendo 4 xw⊕yw = xw h⊎.⊗₂ yw [x⊕y]z : Powerendo 4 [x⊕y]z = x⊕y h×.⊗₂ z [x⊕y]w : Powerendo 4 [x⊕y]w = x⊕y h×.⊗₂ w [x⊕y][z⊕w] : Powerendo 4 [x⊕y][z⊕w] = x⊕y h×.⊗₂ z⊕w [x⊕y]z⊕[x⊕y]w : Powerendo 4 [x⊕y]z⊕[x⊕y]w = [x⊕y]z h⊎.⊗₂ [x⊕y]w [xz⊕yz]⊕[xw⊕yw] : Powerendo 4 [xz⊕yz]⊕[xw⊕yw] = xz⊕yz h⊎.⊗₂ xw⊕yw [[xz⊕yz]⊕xw]⊕yw : Powerendo 4 [[xz⊕yz]⊕xw]⊕yw = (xz⊕yz h⊎.⊗₂ xw) h⊎.⊗₂ yw x[z⊕w]⊕y[z⊕w] : Powerendo 4 x[z⊕w]⊕y[z⊕w] = x[z⊕w] h⊎.⊗₂ y[z⊕w] [xz⊕xw]⊕[yz⊕yw] : Powerendo 4 [xz⊕xw]⊕[yz⊕yw] = xz⊕xw h⊎.⊗₂ yz⊕yw [[xz⊕xw]⊕yz]⊕yw : Powerendo 4 [[xz⊕xw]⊕yz]⊕yw = (xz⊕xw h⊎.⊗₂ yz) h⊎.⊗₂ yw [xz⊕[xw⊕yz]]⊕yw : Powerendo 4 [xz⊕[xw⊕yz]]⊕yw = (xz h⊎.⊗₂ (xw h⊎.⊗₂ yz)) h⊎.⊗₂ yw [xz⊕[yz⊕xw]]⊕yw : Powerendo 4 [xz⊕[yz⊕xw]]⊕yw = (xz h⊎.⊗₂ (yz h⊎.⊗₂ xw)) h⊎.⊗₂ yw module SRig (S⊎ : Symmetric B⊎) (S× : Symmetric B×) (distribₗ : NaturalIsomorphism x⊗[y⊕z] [x⊗y]⊕[x⊗z]) (distribᵣ : NaturalIsomorphism [x⊕y]⊗z [x⊗z]⊕[y⊗z]) (annₗ : NaturalIsomorphism 0⊗x 0↑) (annᵣ : NaturalIsomorphism x⊗0 0↑) where open NaturalIsomorphism distribₗ using () renaming (F⇒G to dₗ) open NaturalIsomorphism distribᵣ using () renaming (F⇒G to dᵣ) open NaturalIsomorphism annₗ using () renaming (F⇒G to aₗ) open NaturalIsomorphism annᵣ using () renaming (F⇒G to aᵣ) dₗ-over : ∀ {n} (F₁ F₂ F₃ : Powerendo n) → NaturalTransformation (F₁ h×.⊗₂ (F₂ h⊎.⊗₂ F₃)) ((F₁ h×.⊗₂ F₂) h⊎.⊗₂ (F₁ h×.⊗₂ F₃)) dₗ-over F₁ F₂ F₃ = dₗ ∘ʳ plex {3} F₁ F₂ F₃ dᵣ-over : ∀ {n} (F₁ F₂ F₃ : Powerendo n) → NaturalTransformation ((F₁ h⊎.⊗₂ F₂) h×.⊗₂ F₃) ((F₁ h×.⊗₂ F₃) h⊎.⊗₂ (F₂ h×.⊗₂ F₃)) dᵣ-over F₁ F₂ F₃ = dᵣ ∘ʳ plex {3} F₁ F₂ F₃ aₗ-over : ∀ {n} (F₁ : Powerendo n) → NaturalTransformation ((widenʳ n 0₀) h×.⊗₂ F₁) (widenʳ n 0₀) aₗ-over F₁ = aₗ ∘ʳ plex {1} F₁ aᵣ-over : ∀ {n} (F₁ : Powerendo n) → NaturalTransformation (F₁ h×.⊗₂ (widenʳ n 0₀)) (widenʳ n 0₀) aᵣ-over F₁ = aᵣ ∘ʳ plex {1} F₁ uₗ⊕-over : ∀ {n} (F₁ : Powerendo n) → NaturalTransformation ((widenʳ n 0₀) h⊎.⊗₂ F₁) F₁ uₗ⊕-over F₁ = (NaturalIsomorphism.F⇒G M⊎.identityˡ) ∘ʳ plex {1} F₁ uₗ⊗-over : ∀ {n} (F₁ : Powerendo n) → NaturalTransformation ((widenʳ n 1₀) h×.⊗₂ F₁) F₁ uₗ⊗-over F₁ = (NaturalIsomorphism.F⇒G M×.identityˡ) ∘ʳ plex {1} F₁ uᵣ⊗-over : ∀ {n} (F₁ : Powerendo n) → NaturalTransformation (F₁ h×.⊗₂ (widenʳ n 1₀)) F₁ uᵣ⊗-over F₁ = (NaturalIsomorphism.F⇒G M×.identityʳ) ∘ʳ plex {1} F₁ s⊕-over : ∀ {n} (F₁ F₂ : Powerendo n) → NaturalTransformation (F₁ h⊎.⊗₂ F₂) (F₂ h⊎.⊗₂ F₁) s⊕-over F₁ F₂ = (NaturalIsomorphism.F⇒G B⊎.braid) ∘ʳ plex {2} F₁ F₂ s⊗-over : ∀ {n} (F₁ F₂ : Powerendo n) → NaturalTransformation (F₁ h×.⊗₂ F₂) (F₂ h×.⊗₂ F₁) s⊗-over F₁ F₂ = (NaturalIsomorphism.F⇒G B×.braid) ∘ʳ plex {2} F₁ F₂ -- for 2 variables idx₂ : NaturalTransformation x₂ x₂ idx₂ = idⁿ idy₂ : NaturalTransformation y₂ y₂ idy₂ = idⁿ idxy : NaturalTransformation AB AB idxy = idⁿ -- these are all for 3 variables Bxz : NaturalTransformation x⊗z z⊗x Bxz = br×.B-over (select 0) (select 2) Byz : NaturalTransformation y⊗z z⊗y Byz = br×.B-over (select 1) (select 2) Bxz⊕Byz : NaturalTransformation [x⊗z]⊕[y⊗z] [z⊗x]⊕[z⊗y] Bxz⊕Byz = Bxz h⊎.⊗ⁿ′ Byz B[x⊕y]z : NaturalTransformation [x⊕y]⊗z z⊗[x⊕y] B[x⊕y]z = br×.B-over (widenʳ 1 h⊎.x⊗y) (select 2) dᵣABC : NaturalTransformation [x⊕y]⊗z [x⊗z]⊕[y⊗z] dᵣABC = dᵣ-over (select 0) (select 1) (select 2) dₗABC : NaturalTransformation x⊗[y⊕z] [x⊗y]⊕[x⊗z] dₗABC = dₗ-over (select 0) (select 1) (select 2) dₗACB : NaturalTransformation x⊗[z⊕y] [x⊗z]⊕[x⊗y] dₗACB = dₗ-over (select 0) (select 2) (select 1) dₗCAB : NaturalTransformation z⊗[x⊕y] [z⊗x]⊕[z⊗y] dₗCAB = dₗ-over (select 2) (select 0) (select 1) 1⊗Byz : NaturalTransformation x⊗[y⊕z] x⊗[z⊕y] 1⊗Byz = reduceN M×.⊗ h×.id₂ (br⊎.B-over (select 0) (select 1)) B[x⊗y][x⊗z] : NaturalTransformation [x⊗y]⊕[x⊗z] [x⊗z]⊕[x⊗y] B[x⊗y][x⊗z] = br⊎.B-over (widenʳ 1 h×.x⊗y) x⊗z -- these are all for 4 variables dᵣA[B⊕C]D : NaturalTransformation [x⊕[y⊕z]]w xw⊕[y⊕z]w dᵣA[B⊕C]D = dᵣ-over (select 0) (widenʳ 1 (widenˡ 1 h⊎.x⊗y)) (select 3) dᵣBCD : NaturalTransformation (widenˡ 1 [x⊕y]⊗z) (widenˡ 1 [x⊗z]⊕[y⊗z]) dᵣBCD = dᵣ-over (select 1) (select 2) (select 3) id03 : NaturalTransformation xw xw id03 = idⁿ id23 : NaturalTransformation zw zw id23 = idⁿ idx : NaturalTransformation x x idx = idⁿ idw : NaturalTransformation w w idw = idⁿ idyw : NaturalTransformation yw yw idyw = idⁿ idxz : NaturalTransformation xz xz idxz = idⁿ 1⊗dᵣBCD : NaturalTransformation xw⊕[y⊕z]w xw⊕[yw⊕zw] 1⊗dᵣBCD = overlapN M⊎.⊗ id03 dᵣBCD assocˡAD-BD-CD : NaturalTransformation xw⊕[yw⊕zw] [xw⊕yw]⊕zw assocˡAD-BD-CD = br⊎.α₂-over xw yw zw αˡABC⊗1 : NaturalTransformation [x⊕[y⊕z]]w [[x⊕y]⊕z]w αˡABC⊗1 = overlapN M×.⊗ (br⊎.α₂-over (select 0) (select 1) (select 2)) idw dᵣ[A⊕B]CD : NaturalTransformation [[x⊕y]⊕z]w [x⊕y]w⊕zw dᵣ[A⊕B]CD = dᵣ-over (widenʳ 2 h⊎.x⊗y) (select 2) (select 3) dᵣABD⊗1 : NaturalTransformation [x⊕y]w⊕zw [xw⊕yw]⊕zw dᵣABD⊗1 = overlapN M⊎.⊗ (dᵣ-over (select 0) (select 1) (select 3)) id23 1A⊗dₗBCD : NaturalTransformation x[y[z⊕w]] x[yz⊕yw] 1A⊗dₗBCD = overlapN M×.⊗ idx (dₗ-over y z w) dₗA[BC][BD] : NaturalTransformation x[yz⊕yw] x[yz]⊕x[yw] dₗA[BC][BD] = dₗ-over x yz yw αABC⊕αABD : NaturalTransformation x[yz]⊕x[yw] [xy]z⊕[xy]w αABC⊕αABD = overlapN M⊎.⊗ (br×.α₂-over x y z) (br×.α₂-over x y w) αAB[C⊕D] : NaturalTransformation x[y[z⊕w]] [xy][z⊕w] αAB[C⊕D] = br×.α₂-over x y z⊕w dₗ[AB]CD : NaturalTransformation [xy][z⊕w] [xy]z⊕[xy]w dₗ[AB]CD = dₗ-over xy z w dₗ0AB : NaturalTransformation 0[A⊕B] 0A⊕0B dₗ0AB = dₗ-over (widenʳ 2 0₀) (select 0) (select 1) aₗA⊕aₗB : NaturalTransformation 0A⊕0B (widenʳ 2 0⊕0) aₗA⊕aₗB = overlapN M⊎.⊗ (aₗ-over (select 0)) (aₗ-over (select 1)) -- a bit weird, but the widening is needed uˡ0 : NaturalTransformation (widenʳ 2 0⊕0) (widenʳ 2 0₀) uˡ0 = uₗ⊕-over (widenʳ 2 0₀) aᵣA : NaturalTransformation A0 0↑ aᵣA = aᵣ-over (select 0) aₗA : NaturalTransformation 0A (widenʳ 1 0₀) aₗA = aₗ-over (select 0) s⊗A0 : NaturalTransformation A0 0A s⊗A0 = s⊗-over (select 0) 0↑ α0AB : NaturalTransformation 0[AB] [0A]B α0AB = br×.α₂-over 0₂ (select 0) (select 1) aₗA⊗1B : NaturalTransformation [0A]B 0B aₗA⊗1B = overlapN M×.⊗ (aₗ-over (select 0)) idy₂ aₗAB : NaturalTransformation 0[AB] 0₂ aₗAB = aₗ-over h×.x⊗y aₗB : NaturalTransformation 0B 0₂ aₗB = aₗ-over y₂ αA0B : NaturalTransformation A[0B] [A0]B αA0B = br×.α₂-over (select 0) 0₂ (select 1) aᵣA⊗1B : NaturalTransformation [A0]B 0B aᵣA⊗1B = overlapN M×.⊗ (aᵣ-over (select 0)) idy₂ 1A⊗aₗB : NaturalTransformation A[0B] (widenʳ 1 A0) 1A⊗aₗB = overlapN M×.⊗ idx₂ aₗB aᵣA₂ : NaturalTransformation (widenʳ 1 A0) 0₂ aᵣA₂ = aᵣ-over (select 0) 1A⊗uₗB : NaturalTransformation A[0⊕B] AB 1A⊗uₗB = overlapN M×.⊗ idx₂ (uₗ⊕-over y₂) dₗA0B : NaturalTransformation A[0⊕B] A0⊕AB dₗA0B = dₗ-over x₂ 0₂ y₂ aᵣA⊕1AB : NaturalTransformation A0⊕AB 0⊕AB aᵣA⊕1AB = overlapN M⊎.⊗ (aᵣ-over x₂) idxy uₗAB : NaturalTransformation 0⊕AB AB uₗAB = uₗ⊕-over AB dₗ1AB : NaturalTransformation 1[A⊕B] 1A⊕1B dₗ1AB = dₗ-over 1₂ x₂ y₂ uₗA⊕B : NaturalTransformation 1[A⊕B] A⊕B uₗA⊕B = uₗ⊗-over h⊎.x⊗y uₗA⊕uₗB : NaturalTransformation 1A⊕1B A⊕B uₗA⊕uₗB = overlapN M⊎.⊗ (uₗ⊗-over x₂) (uₗ⊗-over y₂) -- the monster, aka diagram IX dₗ[A⊕B]CD : NaturalTransformation [x⊕y][z⊕w] [x⊕y]z⊕[x⊕y]w dₗ[A⊕B]CD = dₗ-over x⊕y z w dᵣABC⊕dᵣABD : NaturalTransformation [x⊕y]z⊕[x⊕y]w [xz⊕yz]⊕[xw⊕yw] dᵣABC⊕dᵣABD = overlapN M⊎.⊗ ( dᵣ-over x y z ) (dᵣ-over x y w) α[AC⊕BC][AD][BD] : NaturalTransformation [xz⊕yz]⊕[xw⊕yw] [[xz⊕yz]⊕xw]⊕yw α[AC⊕BC][AD][BD] = br⊎.α₂-over xz⊕yz xw yw dᵣAB[C⊕D] : NaturalTransformation [x⊕y][z⊕w] x[z⊕w]⊕y[z⊕w] dᵣAB[C⊕D] = dᵣ-over x y z⊕w dₗACD⊕dₗBCD : NaturalTransformation x[z⊕w]⊕y[z⊕w] [xz⊕xw]⊕[yz⊕yw] dₗACD⊕dₗBCD = overlapN M⊎.⊗ (dₗ-over x z w) (dₗ-over y z w) α[AC⊕AD][BC][BD] : NaturalTransformation [xz⊕xw]⊕[yz⊕yw] [[xz⊕xw]⊕yz]⊕yw α[AC⊕AD][BC][BD] = br⊎.α₂-over xz⊕xw yz yw α′[AC][AD][BC]⊕1BD : NaturalTransformation [[xz⊕xw]⊕yz]⊕yw [xz⊕[xw⊕yz]]⊕yw α′[AC][AD][BC]⊕1BD = overlapN M⊎.⊗ (br⊎.α-over xz xw yz) idyw [1AC⊕s[AD][BC]]⊕1BD : NaturalTransformation [xz⊕[xw⊕yz]]⊕yw [xz⊕[yz⊕xw]]⊕yw [1AC⊕s[AD][BC]]⊕1BD = overlapN M⊎.⊗ (overlapN M⊎.⊗ idxz (s⊕-over xw yz)) idyw α[AC][BC][AD]⊕1BD : NaturalTransformation [xz⊕[yz⊕xw]]⊕yw [[xz⊕yz]⊕xw]⊕yw α[AC][BC][AD]⊕1BD = overlapN M⊎.⊗ (br⊎.α₂-over xz yz xw) idyw record RigCategory {o ℓ e} {C : Category o ℓ e} {M⊎ M× : Monoidal C} {B⊎ : Braided M⊎} (S⊎ : Symmetric B⊎) {B× : Braided M×} (S× : Symmetric B×) : Set (o ⊔ ℓ ⊔ e) where open BimonoidalHelperFunctors B⊎ B× field distribₗ : NaturalIsomorphism x⊗[y⊕z] [x⊗y]⊕[x⊗z] distribᵣ : NaturalIsomorphism [x⊕y]⊗z [x⊗z]⊕[y⊗z] annₗ : NaturalIsomorphism 0⊗x 0↑ annᵣ : NaturalIsomorphism x⊗0 0↑ open SRig S⊎ S× distribₗ distribᵣ annₗ annᵣ -- need II, IX, X, XV -- choose I, IV, VI, XI, XIII, XIX, XXIII and (XVI, XVII) field .laplazaI : dₗACB ∘₁ 1⊗Byz ≡ⁿ B[x⊗y][x⊗z] ∘₁ dₗABC .laplazaII : Bxz⊕Byz ∘₁ dᵣABC ≡ⁿ dₗCAB ∘₁ B[x⊕y]z .laplazaIV : dᵣABD⊗1 ∘₁ (dᵣ[A⊕B]CD ∘₁ αˡABC⊗1) ≡ⁿ assocˡAD-BD-CD ∘₁ (1⊗dᵣBCD ∘₁ dᵣA[B⊕C]D) .laplazaVI : dₗ[AB]CD ∘₁ αAB[C⊕D] ≡ⁿ αABC⊕αABD ∘₁ (dₗA[BC][BD] ∘₁ 1A⊗dₗBCD) .laplazaIX : α[AC⊕BC][AD][BD] ∘₁ (dᵣABC⊕dᵣABD ∘₁ dₗ[A⊕B]CD) ≡ⁿ α[AC][BC][AD]⊕1BD ∘₁ ([1AC⊕s[AD][BC]]⊕1BD ∘₁ (α′[AC][AD][BC]⊕1BD ∘₁ (α[AC⊕AD][BC][BD] ∘₁ (dₗACD⊕dₗBCD ∘₁ dᵣAB[C⊕D])))) .laplazaX : aₗ-over 0₀ ≡ⁿ aᵣ-over 0₀ .laplazaXI : aₗ-over (h⊎.x⊗y) ≡ⁿ uˡ0 ∘₁ (aₗA⊕aₗB ∘₁ dₗ0AB) .laplazaXIII : uᵣ⊗-over 0₀ ≡ⁿ aₗ-over 1₀ .laplazaXV : aᵣA ≡ⁿ aₗA ∘₁ s⊗A0 .laplazaXVI : aₗAB ≡ⁿ aₗB ∘₁ (aₗA⊗1B ∘₁ α0AB) .laplazaXVII : aᵣA₂ ∘₁ 1A⊗aₗB ≡ⁿ aₗB ∘₁ (aᵣA⊗1B ∘₁ αA0B) .laplazaXIX : 1A⊗uₗB ≡ⁿ uₗAB ∘₁ (aᵣA⊕1AB ∘₁ dₗA0B) .laplazaXXIII : uₗA⊕B ≡ⁿ uₗA⊕uₗB ∘₁ dₗ1AB
{ "alphanum_fraction": 0.5623188406, "avg_line_length": 29.7307001795, "ext": "agda", "hexsha": "84064414620b2419414548c40b04e0b1eab742db", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "copumpkin/categories", "max_forks_repo_path": "Categories/RigCategory.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "copumpkin/categories", "max_issues_repo_path": "Categories/RigCategory.agda", "max_line_length": 133, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/RigCategory.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 9941, "size": 16560 }
module Properties.Step where open import Agda.Builtin.Equality using (_≡_; refl) open import FFI.Data.Maybe using (just; nothing) open import Luau.Heap using (Heap; lookup; alloc; ok; function_⟨_⟩_end) open import Luau.Syntax using (Block; Expr; nil; var; addr; function⟨_⟩_end; block_is_end; _$_; local_←_; function_⟨_⟩_end; return; done; _∙_) open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; app ; beta; function; block; return; done; local; subst) open import Luau.RuntimeError using (RuntimeErrorᴱ; RuntimeErrorᴮ; NilIsNotAFunction; UnboundVariable; SEGV; app; block; local; return) open import Luau.Substitution using (_[_/_]ᴮ) open import Luau.Value using (nil; addr; val) open import Properties.Remember using (remember; _,_) data StepResultᴮ (H : Heap) (B : Block) : Set data StepResultᴱ (H : Heap) (M : Expr) : Set data StepResultᴮ H B where step : ∀ H′ B′ → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → StepResultᴮ H B return : ∀ V {B′} → (B ≡ (return (val V) ∙ B′)) → StepResultᴮ H B done : (B ≡ done) → StepResultᴮ H B error : (RuntimeErrorᴮ H B) → StepResultᴮ H B data StepResultᴱ H M where step : ∀ H′ M′ → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → StepResultᴱ H M value : ∀ V → (M ≡ val V) → StepResultᴱ H M error : (RuntimeErrorᴱ H M) → StepResultᴱ H M stepᴱ : ∀ H M → StepResultᴱ H M stepᴮ : ∀ H B → StepResultᴮ H B stepᴱ H nil = value nil refl stepᴱ H (var x) = error (UnboundVariable x) stepᴱ H (addr a) = value (addr a) refl stepᴱ H (M $ N) with stepᴱ H M stepᴱ H (M $ N) | step H′ M′ D = step H′ (M′ $ N) (app D) stepᴱ H (nil $ N) | value nil refl = error NilIsNotAFunction stepᴱ H (addr a $ N) | value (addr a) refl with remember (lookup H a) stepᴱ H (addr a $ N) | value (addr a) refl | (nothing , p) = error (app (SEGV a p)) stepᴱ H (addr a $ N) | value (addr a) refl | (just(function f ⟨ x ⟩ B end) , p) = step H (block f is local x ← N ∙ B end) (beta p) stepᴱ H (M $ N) | error E = error (app E) stepᴱ H (function⟨ x ⟩ B end) with alloc H (function "anon" ⟨ x ⟩ B end) stepᴱ H (function⟨ x ⟩ B end) | ok a H′ p = step H′ (addr a) (function p) stepᴱ H (block b is B end) with stepᴮ H B stepᴱ H (block b is B end) | step H′ B′ D = step H′ (block b is B′ end) (block D) stepᴱ H (block b is (return _ ∙ B′) end) | return V refl = step H (val V) return stepᴱ H (block b is done end) | done refl = step H nil done stepᴱ H (block b is B end) | error E = error (block b E) stepᴮ H (function f ⟨ x ⟩ C end ∙ B) with alloc H (function f ⟨ x ⟩ C end) stepᴮ H (function f ⟨ x ⟩ C end ∙ B) | ok a H′ p = step H′ (B [ addr a / f ]ᴮ) (function p) stepᴮ H (local x ← M ∙ B) with stepᴱ H M stepᴮ H (local x ← M ∙ B) | step H′ M′ D = step H′ (local x ← M′ ∙ B) (local D) stepᴮ H (local x ← _ ∙ B) | value V refl = step H (B [ V / x ]ᴮ) subst stepᴮ H (local x ← M ∙ B) | error E = error (local x E) stepᴮ H (return M ∙ B) with stepᴱ H M stepᴮ H (return M ∙ B) | step H′ M′ D = step H′ (return M′ ∙ B) (return D) stepᴮ H (return _ ∙ B) | value V refl = return V refl stepᴮ H (return M ∙ B) | error E = error (return E) stepᴮ H done = done refl
{ "alphanum_fraction": 0.6352824579, "avg_line_length": 51.3050847458, "ext": "agda", "hexsha": "0eddd9fe0565b854e53c1f0ab82a46a20a5936ae", "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": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "FreakingBarbarians/luau", "max_forks_repo_path": "prototyping/Properties/Step.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "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": "FreakingBarbarians/luau", "max_issues_repo_path": "prototyping/Properties/Step.agda", "max_line_length": 142, "max_stars_count": 1, "max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FreakingBarbarians/luau", "max_stars_repo_path": "prototyping/Properties/Step.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z", "num_tokens": 1262, "size": 3027 }
-- The --no-coverage-check option has been removed. {-# OPTIONS --no-coverage-check #-} module Issue1918 where
{ "alphanum_fraction": 0.7079646018, "avg_line_length": 18.8333333333, "ext": "agda", "hexsha": "b66f6cc05e210e5371b82189967377a0af495c6a", "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/Issue1918.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/Issue1918.agda", "max_line_length": 51, "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/Issue1918.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": 26, "size": 113 }
module AllTests where import Issue14 import Issue65 import Issue73 import Fixities import LanguageConstructs import Numbers import Pragmas import Sections import Test import Tuples import Where import TypeSynonyms import Datatypes import Records import DefaultMethods import Vector {-# FOREIGN AGDA2HS import Issue14 import Issue65 import Issue73 import Fixities import LanguageConstructs import Numbers import Pragmas import Sections import Test import Tuples import Where import TypeSynonyms import Datatypes import Records import DefaultMethods import Vector #-}
{ "alphanum_fraction": 0.8594024605, "avg_line_length": 14.5897435897, "ext": "agda", "hexsha": "16d4d6daea2d2552664160f1921982e4aed676d1", "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": "703c66db29023f5538eaa841f38dc34e89473a3e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jespercockx/agda2hs", "max_forks_repo_path": "test/AllTests.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "703c66db29023f5538eaa841f38dc34e89473a3e", "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": "jespercockx/agda2hs", "max_issues_repo_path": "test/AllTests.agda", "max_line_length": 25, "max_stars_count": null, "max_stars_repo_head_hexsha": "703c66db29023f5538eaa841f38dc34e89473a3e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jespercockx/agda2hs", "max_stars_repo_path": "test/AllTests.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 138, "size": 569 }
module _ where postulate T U V : Set F G : Set → Set Sea : {A : Set} → (A → A → Set) → Set Seas : {I : Set} (As : I → Set) → ({i j : I} → As i → As j → Set) → Set _eq_ _to_ : T → T → Set record K : Set₁ where field A : Set B : A → A → Set C : Sea B record IK (I : Set) : Set₁ where field As : I → Set Bs : {i j : I} → As i → As j → Set Cs : Seas As Bs open K open IK record L (f t : K) : Set where field D : A f → A t E : ∀ {x y} → (B f x y) → B t (D x) (D y) record IL (f : K) (t : IK (A f)): Set where field Ds : (x : A f) → As t x Es : ∀ {x y} → (B f x y) → Bs t (Ds x) (Ds y) -- make Cs or E irrelevant and the last line turns yellow postulate blah : ∀ {a b c : K} → L a b → L b c → L a c foop : ∀ {a b c d : K} → L a b → L b c → L c d → L a d foop f g h = blah f (blah g h) postulate Equiv : Sea _eq_ Cat : K Cat = record { A = T ; B = _eq_ ; C = Equiv } record T2 : Set where constructor _,_ field fst snd : T open T2 record _eq2_ (a b : T2) : Set where constructor _∧_ field feq : (fst a) eq (fst b) seq : (snd a) eq (snd b) postulate Equiv2 : Sea _eq2_ Cat2 : K Cat2 = record { A = T2; B = _eq2_; C = Equiv2 } postulate Hm : T2 → Set _heq_ : {t t' : T2} → Hm t → Hm t' → Set HEquiv : Seas Hm _heq_ Hom : IK T2 Hom = record { As = Hm ; Bs = _heq_ ; Cs = HEquiv } _×_ : ∀ {U} → L U Cat → L U Cat → L U Cat2 X × Y = record { D = λ x → L.D X x , L.D Y x ; E = λ x' → L.E X x' ∧ L.E Y x' } postulate _∘_ : ∀ {a b c} → Hm (b , c) → Hm (a , b) → Hm (a , c) ∘cong : ∀ {a b c} {f f' : Hm (b , c)} {g g' : Hm (a , b)} → f heq f' → g heq g' → (f ∘ g) heq (f' ∘ g') _∘H_ : ∀ {a b c} → Hm (b , c) → Hm (a , b) → Hm (a , c) module Fool (Base : K) where Dust = L Base Cat promote : L Base Cat2 → IK (A Base) promote f = record { As = λ x → Hm (L.D f x) ; Bs = λ x y → x heq y ; Cs = my-Cs } where postulate my-Cs : Seas (λ x → Hm (L.D f x)) (λ {i} {j} x y → x heq y) Dance : Dust → Dust → Set Dance f t = IL Base (promote (f × t)) _⊚_ : ∀ {as bs cs} → Dance bs cs → Dance as bs → Dance as cs _⊚_ {as} {bs} {cs} fs gs = record { Ds = λ x → IL.Ds fs x ∘ IL.Ds gs x ; Es = my-Es } where postulate my-Es : ∀ {x y} → B Base x y → _ comp3 : ∀ {as bs cs ds} → Dance cs ds → Dance bs cs → Dance as bs → Dance as ds comp3 f g h = f ⊚ (g ⊚ h)
{ "alphanum_fraction": 0.4804446274, "avg_line_length": 21.4955752212, "ext": "agda", "hexsha": "849e4fedc99c87bcb0a599fc5ff32ebda6d71163", "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/Issue351b.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/Issue351b.agda", "max_line_length": 105, "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/Issue351b.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": 1076, "size": 2429 }
{-# OPTIONS --without-K --safe #-} module Categories.Diagram.End.Properties where open import Level open import Data.Product using (Σ; _,_) open import Function using (_$_) open import Categories.Category open import Categories.Category.Product open import Categories.Category.Construction.Functors open import Categories.Functor open import Categories.Functor.Bifunctor open import Categories.NaturalTransformation open import Categories.NaturalTransformation.Dinatural open import Categories.Diagram.End as ∫ import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D E : Category o ℓ e module _ {C : Category o ℓ e} (F : Functor E (Functors (Product (Category.op C) C) D)) where private module C = Category C module D = Category D module E = Category E module NT = NaturalTransformation open D open HomReasoning open MR D open Functor F open End hiding (E) open NT using (η) EndF : (∀ X → End (F₀ X)) → Functor E D EndF end = record { F₀ = λ X → End.E (end X) ; F₁ = F₁′ ; identity = λ {A} → unique (end A) (id-comm ○ ∘-resp-≈ˡ (⟺ identity)) ; homomorphism = λ {A B C} {f g} → unique (end C) $ λ {Z} → begin dinatural.α (end C) Z ∘ F₁′ g ∘ F₁′ f ≈⟨ pullˡ (universal (end C)) ⟩ (η (F₁ g) (Z , Z) ∘ dinatural.α (end B) Z) ∘ F₁′ f ≈⟨ pullʳ (universal (end B)) ⟩ η (F₁ g) (Z , Z) ∘ η (F₁ f) (Z , Z) ∘ dinatural.α (end A) Z ≈˘⟨ pushˡ homomorphism ⟩ η (F₁ (g E.∘ f)) (Z , Z) ∘ dinatural.α (end A) Z ∎ ; F-resp-≈ = λ {A B f g} eq → unique (end B) $ λ {Z} → begin dinatural.α (end B) Z ∘ F₁′ g ≈⟨ universal (end B) ⟩ η (F₁ g) (Z , Z) ∘ dinatural.α (end A) Z ≈˘⟨ F-resp-≈ eq ⟩∘⟨refl ⟩ η (F₁ f) (Z , Z) ∘ dinatural.α (end A) Z ∎ } where F₁′ : ∀ {X Y} → X E.⇒ Y → End.E (end X) ⇒ End.E (end Y) F₁′ {X} {Y} f = factor (end Y) $ record { E = End.E (end X) ; dinatural = F₁ f <∘ dinatural (end X) }
{ "alphanum_fraction": 0.5530516432, "avg_line_length": 35.5, "ext": "agda", "hexsha": "8cd46bfa289247bc044f2e90064d6f75210215af", "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/Diagram/End/Properties.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/Diagram/End/Properties.agda", "max_line_length": 96, "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/Diagram/End/Properties.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": 748, "size": 2130 }
{-# OPTIONS --without-K --safe #-} module Strict where open import Agda.Builtin.Strict open import Level infixr 0 _$!_ _$!_ : {A : Type a} {B : A → Type b} → (∀ x → B x) → ∀ x → B x f $! x = primForce x f {-# INLINE _$!_ #-}
{ "alphanum_fraction": 0.5657894737, "avg_line_length": 19, "ext": "agda", "hexsha": "571b1bffc0c367bf29f18b8fc829bdd191ae5b63", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Strict.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "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/combinatorics-paper", "max_issues_repo_path": "agda/Strict.agda", "max_line_length": 62, "max_stars_count": 4, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Strict.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z", "num_tokens": 81, "size": 228 }
------------------------------------------------------------------------ -- Identity and composition for traditional non-dependent lenses ------------------------------------------------------------------------ {-# OPTIONS --cubical #-} import Equality.Path as P module Lens.Non-dependent.Traditional.Combinators {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (module _⇔_) open import Prelude as P hiding (id) renaming (_∘_ to _⊚_) import Bi-invertibility open import Bijection equality-with-J as Bijection using (_↔_) open import Category equality-with-J as C using (Category; Precategory) open import Circle eq as Circle using (𝕊¹) open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Erased.Cubical eq as E using (Erased; [_]) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional eq as T using (∥_∥) import Integer equality-with-J as Int open import Preimage equality-with-J using (_⁻¹_) open import Surjection equality-with-J as Surjection using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent.Traditional eq private variable a b h o : Level A B C D : Type a l₁ l₂ : Lens A B ------------------------------------------------------------------------ -- Lens combinators -- If two types are isomorphic, then there is a lens between them. ↔→lens : {A : Type a} {B : Type b} → A ↔ B → Lens A B ↔→lens A↔B = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = left-inverse-of ; set-set = λ _ _ _ → refl _ } where open _↔_ A↔B -- If two types are equivalent, then there is a lens between them. ≃→lens : {A : Type a} {B : Type b} → A ≃ B → Lens A B ≃→lens = ↔→lens ⊚ _≃_.bijection -- Identity lens. id : Lens A A id = ↔→lens F.id -- Composition of lenses. infixr 9 _∘_ _∘_ : Lens B C → Lens A B → Lens A C l₁ ∘ l₂ = record { get = λ a → get l₁ (get l₂ a) ; set = λ a c → set l₂ a (set l₁ (get l₂ a) c) ; get-set = λ a c → get l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c))) ≡⟨ cong (get l₁) $ get-set l₂ _ _ ⟩ get l₁ (set l₁ (get l₂ a) c) ≡⟨ get-set l₁ _ _ ⟩∎ c ∎ ; set-get = λ a → set l₂ a (set l₁ (get l₂ a) (get l₁ (get l₂ a))) ≡⟨ cong (set l₂ _) $ set-get l₁ _ ⟩ set l₂ a (get l₂ a) ≡⟨ set-get l₂ _ ⟩∎ a ∎ ; set-set = λ a c₁ c₂ → set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ set-set l₂ _ _ _ ⟩ set l₂ a (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ cong (λ b → set l₂ _ (set l₁ b _)) $ get-set l₂ _ _ ⟩ set l₂ a (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ cong (set l₂ _) $ set-set l₁ _ _ _ ⟩∎ set l₂ a (set l₁ (get l₂ a) c₂) ∎ } where open Lens -- Note that composition can be defined in several different ways. -- Here are two alternative implementations. infixr 9 _∘′_ _∘″_ _∘′_ : Lens B C → Lens A B → Lens A C l₁ ∘′ l₂ = record (l₁ ∘ l₂) { set-set = λ a c₁ c₂ → set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ cong (λ b → set l₂ (set l₂ _ (set l₁ _ _)) (set l₁ b _)) $ get-set l₂ _ _ ⟩ set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ set-set l₂ _ _ _ ⟩ set l₂ a (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ cong (set l₂ _) $ set-set l₁ _ _ _ ⟩∎ set l₂ a (set l₁ (get l₂ a) c₂) ∎ } where open Lens _∘″_ : Lens B C → Lens A B → Lens A C l₁ ∘″ l₂ = record (l₁ ∘ l₂) { set-set = λ a c₁ c₂ → set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ cong (λ b → set l₂ (set l₂ _ (set l₁ _ _)) (set l₁ b _)) $ get-set l₂ _ _ ⟩ set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ cong (set l₂ _) $ set-set l₁ _ _ _ ⟩ set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ a) c₂) ≡⟨ set-set l₂ _ _ _ ⟩∎ set l₂ a (set l₁ (get l₂ a) c₂) ∎ } where open Lens -- These two implementations are pointwise equal to the other one. -- However, I don't know if there is some other definition that is -- distinct from these two (if we require that the definitions are -- polymorphic, that get and set are implemented in the same way as -- for _∘_, and that the three composition laws below hold). ∘≡∘′ : l₁ ∘ l₂ ≡ l₁ ∘′ l₂ ∘≡∘′ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡ (λ _ _ → refl _) (λ _ → refl _) (λ a c₁ c₂ → let b₁ = set l₁ (get l₂ a) c₁ b₂ = set l₁ b₁ c₂ a′ = set l₂ a b₁ b′ = set l₁ (get l₂ a′) c₂ in set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩ trans (set-set l₂ a b₁ b′) (trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (set-set l₂ a b₁ b′) (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁))) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ cong (flip trans _) $ elim₁ (λ eq → trans (set-set l₂ _ b₁ _) (cong (λ b → set l₂ _ (set l₁ b _)) eq) ≡ trans (cong (λ b → set l₂ _ (set l₁ b _)) eq) (set-set l₂ _ _ _)) ( trans (set-set l₂ a b₁ b₂) (cong (λ b → set l₂ a (set l₁ b c₂)) (refl _)) ≡⟨ trans (cong (trans _) $ cong-refl _) $ trans-reflʳ _ ⟩ set-set l₂ a b₁ b₂ ≡⟨ sym $ trans (cong (flip trans _) $ cong-refl _) $ trans-reflˡ _ ⟩∎ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (refl _)) (set-set l₂ a b₁ b₂) ∎) (get-set l₂ a b₁) ⟩ trans (trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (set-set l₂ a b₁ b₂)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ trans-assoc _ _ _ ⟩ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (trans (set-set l₂ a b₁ b₂) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨⟩ set-set (l₁ ∘′ l₂) a c₁ c₂ ∎) where open Lens ∘≡∘″ : l₁ ∘ l₂ ≡ l₁ ∘″ l₂ ∘≡∘″ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡ (λ _ _ → refl _) (λ _ → refl _) (λ a c₁ c₂ → let b₁ = set l₁ (get l₂ a) c₁ b₂ = set l₁ (get l₂ a) c₂ a′ = set l₂ a b₁ b′ = set l₁ (get l₂ a′) c₂ eq : b′ ≡ b₂ eq = trans (cong (λ b → set l₁ b c₂) (get-set l₂ a b₁)) (set-set l₁ (get l₂ a) c₁ c₂) in set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩ trans (set-set l₂ a b₁ b′) (trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ cong (trans (set-set l₂ a b₁ b′)) $ trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _ ⟩ trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡⟨ elim¹ (λ {b₂} eq → trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡ trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂)) ( trans (set-set l₂ a b₁ b′) (cong (set l₂ a) (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩ trans (set-set l₂ a b₁ b′) (refl _) ≡⟨ trans-reflʳ _ ⟩ set-set l₂ a b₁ b′ ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl _) (set-set l₂ a b₁ b′) ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩∎ trans (cong (set l₂ a′) (refl _)) (set-set l₂ a b₁ b′) ∎) eq ⟩ trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂) ≡⟨ trans (cong (flip trans _) $ trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _) $ trans-assoc _ _ _ ⟩ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (trans (cong (set l₂ a′) (set-set l₁ (get l₂ a) c₁ c₂)) (set-set l₂ a b₁ b₂)) ≡⟨⟩ set-set (l₁ ∘″ l₂) a c₁ c₂ ∎) where open Lens -- id is a left identity of _∘_. left-identity : (l : Lens A B) → id ∘ l ≡ l left-identity l = equal-laws→≡ (λ a b → trans (cong P.id (get-set a b)) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id (get-set a b) ≡⟨ sym $ cong-id _ ⟩∎ get-set a b ∎) (λ a → trans (cong (set a) (refl _)) (set-get a) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (set-get a) ≡⟨ trans-reflˡ _ ⟩∎ set-get a ∎) (λ a b₁ b₂ → trans (set-set a b₁ b₂) (trans (cong (λ _ → set a b₂) (get-set a b₁)) (cong (set a) (refl _))) ≡⟨ cong₂ (λ p q → trans _ (trans p q)) (cong-const _) (cong-refl _) ⟩ trans (set-set a b₁ b₂) (trans (refl _) (refl _)) ≡⟨ trans (cong (trans _) trans-refl-refl) $ trans-reflʳ _ ⟩∎ set-set a b₁ b₂ ∎) where open Lens l -- id is a right identity of _∘_. right-identity : (l : Lens A B) → l ∘ id ≡ l right-identity l = equal-laws→≡ (λ a b → trans (cong get (refl _)) (get-set a b) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (get-set a b) ≡⟨ trans-reflˡ _ ⟩∎ get-set a b ∎) (λ a → trans (cong P.id (set-get a)) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id (set-get a) ≡⟨ sym $ cong-id _ ⟩∎ set-get a ∎) (λ a b₁ b₂ → trans (refl _) (trans (cong (λ b → set b b₂) (refl _)) (cong P.id (set-set a b₁ b₂))) ≡⟨ trans-reflˡ _ ⟩ trans (cong (λ b → set b b₂) (refl _)) (cong P.id (set-set a b₁ b₂)) ≡⟨ cong₂ trans (cong-refl _) (sym $ cong-id _) ⟩ trans (refl _) (set-set a b₁ b₂) ≡⟨ trans-reflˡ _ ⟩∎ set-set a b₁ b₂ ∎) where open Lens l -- _∘_ is associative. associativity : (l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) → l₁ ∘ (l₂ ∘ l₃) ≡ (l₁ ∘ l₂) ∘ l₃ associativity l₁ l₂ l₃ = equal-laws→≡ lemma₁ lemma₂ lemma₃ where open Lens lemma₁ = λ a d → let f = get l₁ g = get l₂ b = get l₃ a c = g b c′ = set l₁ c d x = get-set l₃ a (set l₂ b c′) y = get-set l₂ b c′ z = get-set l₁ c d in trans (cong f $ trans (cong g x) y) z ≡⟨ cong (λ x → trans x z) (cong-trans f _ y) ⟩ trans (trans (cong f $ cong g x) (cong f y)) z ≡⟨ trans-assoc _ _ z ⟩ trans (cong f $ cong g x) (trans (cong f y) z) ≡⟨ cong (λ x → trans x (trans (cong f y) z)) (cong-∘ f g x) ⟩∎ trans (cong (f ⊚ g) x) (trans (cong f y) z) ∎ lemma₂ = λ a → let b = get l₃ a f = set l₃ a g = set l₂ b x = set-get l₁ (get l₂ b) y = set-get l₂ b z = set-get l₃ a in trans (cong (f ⊚ g) x) (trans (cong f y) z) ≡⟨ sym $ trans-assoc _ _ z ⟩ trans (trans (cong (f ⊚ g) x) (cong f y)) z ≡⟨ cong (λ x → trans (trans x (cong f y)) z) (sym $ cong-∘ f g x) ⟩ trans (trans (cong f (cong g x)) (cong f y)) z ≡⟨ cong (λ x → trans x z) (sym $ cong-trans f _ y) ⟩∎ trans (cong f $ trans (cong g x) y) z ∎ lemma₃ = λ a d₁ d₂ → let f = set l₃ a g = set l₂ (get l₃ a) h = λ x → set l₁ x d₂ i = get l₂ c₁ = set l₁ (get (l₂ ∘ l₃) a) d₁ c₂ = h (i (get l₃ a)) c₂′ = h (i (get l₃ (set (l₂ ∘ l₃) a c₁))) c₂″ = h (i (set l₂ (get l₃ a) c₁)) b₁ = g c₁ b₁′ = get l₃ (f b₁) x = set-set l₃ a b₁ (set l₂ b₁′ c₂′) y = get-set l₃ a b₁ z = set-set l₂ (get l₃ a) c₁ u = get-set l₂ (get l₃ a) c₁ v = set-set l₁ (get (l₂ ∘ l₃) a) d₁ d₂ c₂′≡c₂″ = c₂′ ≡⟨ cong (h ⊚ i) y ⟩∎ c₂″ ∎ lemma₁₀ = trans (sym (cong (h ⊚ i) y)) (cong h (cong i y)) ≡⟨ cong (trans _) (cong-∘ h i y) ⟩ trans (sym (cong (h ⊚ i) y)) (cong (h ⊚ i) y) ≡⟨ trans-symˡ (cong (h ⊚ i) y) ⟩∎ refl _ ∎ lemma₉ = trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″) ≡⟨ cong (trans (cong (λ x → set l₂ x c₂′) y)) (cong-∘ (set l₂ b₁) (h ⊚ i) y) ⟩ trans (cong (λ x → set l₂ x (h (i b₁′))) y) (cong (λ x → set l₂ b₁ (h (i x ))) y) ≡⟨ trans-cong-cong (λ x y → set l₂ x (h (i y))) y ⟩∎ cong (λ x → set l₂ x (h (i x))) y ∎ lemma₈ = sym (cong (set l₂ b₁) (sym c₂′≡c₂″)) ≡⟨ sym $ cong-sym (set l₂ b₁) (sym c₂′≡c₂″) ⟩ cong (set l₂ b₁) (sym (sym c₂′≡c₂″)) ≡⟨ cong (cong (set l₂ b₁)) (sym-sym c₂′≡c₂″) ⟩∎ cong (set l₂ b₁) c₂′≡c₂″ ∎ lemma₇ = trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y))) ≡⟨ sym $ cong-trans g _ (cong h (cong i y)) ⟩ cong g (trans (sym c₂′≡c₂″) (cong h (cong i y))) ≡⟨ cong (cong g) lemma₁₀ ⟩ cong g (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎ lemma₆ = trans (cong (λ x → set l₂ x c₂′) y) (trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) ≡⟨ sym $ trans-assoc _ _ (trans _ (cong g (sym c₂′≡c₂″))) ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″)) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₉ ⟩ trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ sym $ trans-assoc _ _ (cong g (sym c₂′≡c₂″)) ⟩∎ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (sym c₂′≡c₂″)) ∎ lemma₅ = z c₂′ ≡⟨ sym $ dcong z (sym c₂′≡c₂″) ⟩ subst (λ x → set l₂ b₁ x ≡ g x) (sym c₂′≡c₂″) (z c₂″) ≡⟨ subst-in-terms-of-trans-and-cong {f = set l₂ b₁} {g = g} {x≡y = sym c₂′≡c₂″} ⟩ trans (sym (cong (set l₂ b₁) (sym c₂′≡c₂″))) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₈ ⟩∎ trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ∎ lemma₄ = trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans (trans (cong (λ x → set l₂ x c₂′) y) e) (cong g (cong h (cong i y)))) lemma₅ ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″))))) (cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans e (cong g (cong h (cong i y)))) lemma₆ ⟩ trans (trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (sym c₂′≡c₂″))) (cong g (cong h (cong i y))) ≡⟨ trans-assoc _ _ (cong g (cong h (cong i y))) ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y)))) ≡⟨ cong (trans (trans _ (z c₂″))) lemma₇ ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (refl _) ≡⟨ trans-reflʳ _ ⟩∎ trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″) ∎ lemma₃ = cong g (trans (cong h (trans (cong i y) u)) v) ≡⟨ cong (λ e → cong g (trans e v)) (cong-trans h _ u) ⟩ cong g (trans (trans (cong h (cong i y)) (cong h u)) v) ≡⟨ cong (cong g) (trans-assoc _ _ v) ⟩ cong g (trans (cong h (cong i y)) (trans (cong h u) v)) ≡⟨ cong-trans g _ (trans _ v) ⟩∎ trans (cong g (cong h (cong i y))) (cong g (trans (cong h u) v)) ∎ lemma₂ = trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (trans (trans _ (z c₂′))) lemma₃ ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (trans (cong g (cong h (cong i y))) (cong g (trans (cong h u) v))) ≡⟨ sym $ trans-assoc _ _ (cong g (trans _ v)) ⟩ trans (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (cong h (cong i y)))) (cong g (trans (cong h u) v)) ≡⟨ cong (λ e → trans e (cong g (trans (cong h u) v))) lemma₄ ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (trans (cong h u) v)) ≡⟨ trans-assoc _ _ (cong g (trans _ v)) ⟩∎ trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (trans (cong h u) v))) ∎ lemma₁ = trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (λ e → trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) e) (sym $ cong-∘ f g (trans _ v)) ⟩ trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong f (cong g (trans (cong h (trans (cong i y) u)) v))) ≡⟨ sym $ cong-trans f (trans _ (z c₂′)) (cong g (trans _ v)) ⟩ cong f (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (cong f) lemma₂ ⟩ cong f (trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong-trans _ _ _ ⟩ trans (cong f (cong (λ x → set l₂ x (h (i x))) y)) (cong f (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong₂ (λ p q → trans p (cong f (trans (z c₂″) q))) (cong-∘ _ _ _) (trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _) ⟩∎ trans (cong (λ x → f (set l₂ x (h (i x)))) y) (cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v)))) ∎ in trans (trans x (trans (cong (λ x → f (set l₂ x c₂′)) y) (cong f (z c₂′)))) (trans (cong (f ⊚ g ⊚ h) (trans (cong i y) u)) (cong (f ⊚ g) v)) ≡⟨ cong₂ (λ p q → trans (trans x p) q) (trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _) (trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _) ⟩ trans (trans x (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ trans-assoc _ _ _ ⟩ trans x (trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (trans x) lemma₁ ⟩∎ trans x (trans (cong (λ x → f (set l₂ x (h (i x)))) y) (cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v))))) ∎ -- Every lens of type Lens A A that satisfies a certain right -- identity law is equal to the identity lens. id-unique : (id′ : Lens A A) → ((l : Lens A A) → l ∘ id′ ≡ l) → id′ ≡ id id-unique id′ right-identity = id′ ≡⟨ sym $ left-identity _ ⟩ id ∘ id′ ≡⟨ right-identity _ ⟩∎ id ∎ -- An equality characterisation lemma that can be used when one of -- the lenses is the identity. equality-characterisation-id : {l : Lens A A} → let open Lens l in l ≡ id ↔ ∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) equality-characterisation-id {l = l} = l ≡ id ↝⟨ equality-characterisation₄ ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡ refl _) × (∀ a → trans (sym (trans (s a (get a)) (cong P.id (g a)))) (set-get a) ≡ refl _) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (refl _))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → ∃-cong λ _ → (∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ eq → trans (sym (trans _ eq)) (set-get _) ≡ _) $ sym $ cong-id (g _)) ×-cong ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_ ≡_) $ trans-reflʳ _) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡ refl _) × (∀ a → trans (sym (trans (s a (get a)) (g a))) (set-get a) ≡ refl _) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) ↝⟨ (∃-cong λ g → ∃-cong λ s → (∀-cong ext λ _ → ∀-cong ext λ _ → ≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘ ≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm) ×-cong (∀-cong ext λ _ → ≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘ ≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm) ×-cong F.id) ⟩□ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) □ where open Lens l -- A lemma that can be used to show that a lens with a constant -- setter (such as the ones produced by getter-equivalence→lens -- below) is equal to the identity lens. constant-setter→≡id : {l′ : ∃ λ (get : A → A) → ∃ λ (set : A → A) → (A → ∀ a → get (set a) ≡ a) × (∀ a → set (get a) ≡ a) × (A → A → ∀ a → set a ≡ set a)} → let l = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′) set = proj₁ (proj₂ l′) open Lens l hiding (set) in (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _)) → l ≡ id constant-setter→≡id {A = A} {l′ = l′} = (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _)) ↝⟨ (Σ-map P.id $ Σ-map P.id λ {s} → Σ-map P.id $ Σ-map P.id λ hyp a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡⟨ cong (λ eq → trans eq (s a₂)) $ hyp _ _ _ ⟩ trans (refl _) (s a₂) ≡⟨ trans-reflˡ (s _) ⟩∎ s a₂ ∎) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ s a₂)) ↔⟨ (∃-cong λ _ → ∃-cong λ s → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ a₁ → ∀-cong ext λ a₂ → ≡⇒↝ equivalence $ cong (trans _ (s _) ≡_) ( s a₂ ≡⟨ sym $ cong-ext s ⟩ cong (λ set → set a₂) (⟨ext⟩ s) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ s) ⟩ cong (λ set → set (set a a₁) a₂) (cong const (⟨ext⟩ s)) ≡⟨ cong (cong (λ set → set (set a a₁) a₂)) $ sym $ ext-const (⟨ext⟩ s) ⟩∎ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s) ∎)) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s))) ↝⟨ Σ-map P.id (Σ-map const P.id) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : A → ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₁ a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a a₂) ≡ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) ↔⟨ inverse equality-characterisation-id ⟩□ l″ ≡ id □ where l″ = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′) set = proj₁ (proj₂ l′) open Lens l″ hiding (set) -- An identity function for lenses for which the forward direction -- is an equivalence. -- -- Note that the setter of the resulting lens is definitionally -- equal to a constant function returning the right-to-left -- direction of the equivalence. -- -- Note also that two proofs, set-get and set-set, have been -- "obfuscated". They could have been shorter, but then it might not -- have been possible to prove getter-equivalence→lens≡. getter-equivalence→lens : (l : Lens A B) → Is-equivalence (Lens.get l) → Lens A B getter-equivalence→lens l is-equiv = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = λ a → from (to a) ≡⟨ cong from (sym (get-set a (to a))) ⟩ from (get (set a (to a))) ≡⟨⟩ from (to (set a (get a))) ≡⟨ cong (from ⊚ to) (set-get a) ⟩ from (to a) ≡⟨ left-inverse-of _ ⟩∎ a ∎ ; set-set = λ a b₁ b₂ → let s = from≡set l is-equiv in from b₂ ≡⟨ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)) ⟩ set (set a b₁) b₂ ≡⟨ set-set a b₁ b₂ ⟩ set a b₂ ≡⟨ sym (s a b₂) ⟩∎ from b₂ ∎ } where A≃B = Eq.⟨ _ , is-equiv ⟩ open _≃_ A≃B open Lens l -- The function getter-equivalence→lens returns its input. getter-equivalence→lens≡ : ∀ (l : Lens A B) is-equiv → getter-equivalence→lens l is-equiv ≡ l getter-equivalence→lens≡ l is-equiv = _↔_.from equality-characterisation₄ ( g , s , lemma₁ , lemma₂ , lemma₃ ) where open Lens A≃B = Eq.⟨ get l , is-equiv ⟩ open _≃_ A≃B l′ = getter-equivalence→lens l is-equiv g = λ _ → refl _ s = from≡set l is-equiv lemma₁ = λ a b → let lem = cong (get l) (s a b) ≡⟨⟩ cong (get l) (trans (cong from (sym (get-set l a b))) (left-inverse-of _)) ≡⟨ cong-trans _ _ (left-inverse-of _) ⟩ trans (cong (get l) (cong from (sym (get-set l a b)))) (cong (get l) (left-inverse-of _)) ≡⟨ cong₂ trans (cong-∘ _ _ (sym (get-set l a b))) (left-right-lemma _) ⟩∎ trans (cong (get l ⊚ from) (sym (get-set l a b))) (right-inverse-of _) ∎ in trans (sym (trans (cong (get l) (s a b)) (g (set l a b)))) (get-set l′ a b) ≡⟨⟩ trans (sym (trans (cong (get l) (s a b)) (refl _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym eq) (right-inverse-of _)) $ trans-reflʳ _ ⟩ trans (sym (cong (get l) (s a b))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym eq) (right-inverse-of _)) lem ⟩ trans (sym (trans (cong (get l ⊚ from) (sym (get-set l a b))) (right-inverse-of _))) (right-inverse-of _) ≡⟨ elim¹ (λ eq → trans (sym (trans (cong (get l ⊚ from) (sym eq)) (right-inverse-of _))) (right-inverse-of _) ≡ eq) ( trans (sym (trans (cong (get l ⊚ from) (sym (refl _))) (right-inverse-of _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym (trans (cong (get l ⊚ from) eq) _)) _) sym-refl ⟩ trans (sym (trans (cong (get l ⊚ from) (refl _)) (right-inverse-of _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym (trans eq _)) _) $ cong-refl _ ⟩ trans (sym (trans (refl _) (right-inverse-of _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym eq) (right-inverse-of _)) $ trans-reflˡ (right-inverse-of _) ⟩ trans (sym (right-inverse-of _)) (right-inverse-of _) ≡⟨ trans-symˡ (right-inverse-of _) ⟩∎ refl _ ∎) _ ⟩∎ get-set l a b ∎ lemma₂ = λ a → trans (sym (trans (s a (get l a)) (cong (set l a) (g a)))) (set-get l′ a) ≡⟨⟩ trans (sym (trans (s a (get l a)) (cong (set l a) (refl _)))) (set-get l′ a) ≡⟨ cong (λ eq → trans (sym (trans (s a (get l a)) eq)) (set-get l′ a)) $ cong-refl _ ⟩ trans (sym (trans (s a (get l a)) (refl _))) (set-get l′ a) ≡⟨ cong (λ eq → trans (sym eq) (set-get l′ a)) $ trans-reflʳ _ ⟩ trans (sym (s a (get l a))) (set-get l′ a) ≡⟨⟩ trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (cong from (sym (get-set l a (get l a)))) (trans (cong (from ⊚ get l) (set-get l a)) (left-inverse-of _))) ≡⟨ cong (λ eq → trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (cong from (sym (get-set l a (get l a)))) eq)) $ elim¹ (λ eq → trans (cong (from ⊚ get l) eq) (left-inverse-of _) ≡ trans (left-inverse-of _) eq) ( trans (cong (from ⊚ get l) (refl _)) (left-inverse-of (set l a (get l a))) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (left-inverse-of (set l a (get l a))) ≡⟨ trans-reflˡ _ ⟩ left-inverse-of (set l a (get l a)) ≡⟨ sym $ trans-reflʳ _ ⟩∎ trans (left-inverse-of (set l a (get l a))) (refl _) ∎) (set-get l a) ⟩ trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (cong from (sym (get-set l a (get l a)))) (trans (left-inverse-of _) (set-get l a))) ≡⟨ cong (trans _) $ sym $ trans-assoc _ _ (set-get l a) ⟩ trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _)) (set-get l a)) ≡⟨ trans-sym-[trans] _ _ ⟩∎ set-get l a ∎ lemma₃ = λ a b₁ b₂ → trans (set-set l′ a b₁ b₂) (s a b₂) ≡⟨⟩ trans (trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (trans (set-set l a b₁ b₂) (sym (s a b₂)))) (s a b₂) ≡⟨ cong (λ eq → trans eq (s a b₂)) $ sym $ trans-assoc _ _ (sym (s a b₂)) ⟩ trans (trans (trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (set-set l a b₁ b₂)) (sym (s a b₂))) (s a b₂) ≡⟨ trans-[trans-sym]- _ (s a b₂) ⟩∎ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (set-set l a b₁ b₂) ∎ ------------------------------------------------------------------------ -- Some existence results -- The lenses bad a and id {A = ↑ a 𝕊¹} have equal setters, and their -- getters are equivalences, but they are not equal (assuming -- univalence). equal-setters-and-equivalences-as-getters-but-not-equal : Univalence lzero → let l₁ = bad a l₂ = id {A = ↑ a 𝕊¹} in Is-equivalence (Lens.get l₁) × Is-equivalence (Lens.get l₂) × Lens.set l₁ ≡ Lens.set l₂ × l₁ ≢ l₂ equal-setters-and-equivalences-as-getters-but-not-equal {a = ℓa} univ = let is-equiv , not-coherent , _ = getter-equivalence-but-not-coherent univ in is-equiv , _≃_.is-equivalence F.id , refl _ , (bad ℓa ≡ id ↝⟨ (λ eq → subst (λ l → ∀ a → cong (get l) (set-get l a) ≡ get-set l a (get l a)) (sym eq) (λ _ → cong-refl _)) ⟩ (∀ a → cong (get (bad ℓa)) (set-get (bad ℓa) a) ≡ get-set (bad ℓa) a (get (bad ℓa) a)) ↝⟨ not-coherent ⟩□ ⊥ □) where open Lens -- There is in general no split surjection from equivalences to lenses -- with getters that are equivalences, if the right-to-left direction -- of the split surjection is required to return the lens's getter -- plus some proof (assuming univalence). ¬-≃-↠-Σ-Lens-Is-equivalence-get : Univalence lzero → ¬ ∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p) ¬-≃-↠-Σ-Lens-Is-equivalence-get {a = a} univ = let is-equiv₁ , is-equiv₂ , _ , bad≢id = equal-setters-and-equivalences-as-getters-but-not-equal univ in λ (f , hyp) → $⟨ refl _ ⟩ Lens.get (bad a) ≡ Lens.get id ↝⟨ (λ eq → trans (hyp _) (trans eq (sym (hyp _)))) ⟩ _≃_.to (_↠_.from f (bad a , is-equiv₁)) ≡ _≃_.to (_↠_.from f (id , is-equiv₂)) ↝⟨ Eq.lift-equality ext ⟩ _↠_.from f (bad a , is-equiv₁) ≡ _↠_.from f (id , is-equiv₂) ↝⟨ _↠_.to (Surjection.↠-≡ f) ⟩ (bad a , is-equiv₁) ≡ (id , is-equiv₂) ↝⟨ cong proj₁ ⟩ bad a ≡ id ↝⟨ bad≢id ⟩□ ⊥ □ -- There is in general no equivalence from equivalences to lenses with -- getters that are equivalences, if the right-to-left direction of -- the equivalence is required to return the lens's getter plus some -- proof (assuming univalence). ¬-≃-≃-Σ-Lens-Is-equivalence-get : Univalence lzero → ¬ ∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_≃_.from f p) ≡ Lens.get (proj₁ p) ¬-≃-≃-Σ-Lens-Is-equivalence-get {a = a} univ = (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_≃_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map _≃_.surjection P.id ⟩ (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃-↠-Σ-Lens-Is-equivalence-get univ ⟩□ ⊥ □ -- The lemma ≃Σ∥set⁻¹∥× does not hold in general if the requirement -- that A is a set is dropped (assuming univalence). -- -- I proved this together with Paolo Capriotti. -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.𝕊¹≄𝕊¹×𝕊¹.) ≄Σ∥set⁻¹∥× : Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)) ≄Σ∥set⁻¹∥× {a = a} _ = ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)) ↝⟨ (λ hyp → hyp) ⟩ ((l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → ↑ a 𝕊¹ ≃ ((∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ Lens.set l ⁻¹ f ∥) × ↑ a 𝕊¹)) ↝⟨ _$ id ⟩ ↑ a 𝕊¹ ≃ ((∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ const P.id ⁻¹ f ∥) × ↑ a 𝕊¹) ↝⟨ lemma ⟩ 𝕊¹ ≃ (𝕊¹ × 𝕊¹) ↝⟨ 𝕊¹≄𝕊¹×𝕊¹ ⟩□ ⊥ □ where open Circle open Int lemma = λ hyp → 𝕊¹ ↔⟨ inverse Bijection.↑↔ ⟩ ↑ a 𝕊¹ ↝⟨ hyp ⟩ (∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ const P.id ⁻¹ f ∥) × ↑ a 𝕊¹ ↔⟨⟩ (∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ ↑ a 𝕊¹ × P.id ≡ f ∥) × ↑ a 𝕊¹ ↝⟨ (×-cong₁ λ _ → ∃-cong λ _ → T.∥∥-cong-⇔ $ record { to = proj₂; from = λ eq → lift base , eq }) ⟩ (∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ P.id ≡ f ∥) × ↑ a 𝕊¹ ↝⟨ (Σ-cong (→-cong ext Bijection.↑↔ Bijection.↑↔) λ _ → T.∥∥-cong $ inverse $ Eq.≃-≡ (Eq.↔⇒≃ $ →-cong ext Bijection.↑↔ Bijection.↑↔)) ×-cong Eq.↔⇒≃ Bijection.↑↔ ⟩ (∃ λ (f : 𝕊¹ → 𝕊¹) → ∥ P.id ≡ f ∥) × 𝕊¹ ↝⟨ (×-cong₁ λ _ → Σ-cong 𝕊¹→𝕊¹≃𝕊¹×ℤ λ f → T.∥∥-cong ( P.id ≡ f ↝⟨ inverse $ Eq.≃-≡ 𝕊¹→𝕊¹≃𝕊¹×ℤ ⟩ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ P.id ≡ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f ↝⟨ ≡⇒≃ $ cong (_≡ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f) 𝕊¹→𝕊¹≃𝕊¹×ℤ-id ⟩ (base , + 1) ≡ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f ↔⟨ ≡-comm ⟩□ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f ≡ (base , + 1) □)) ⟩ (∃ λ (p : 𝕊¹ × ℤ) → ∥ p ≡ (base , + 1) ∥) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → ∃-cong λ _ → inverse $ T.∥∥-cong ≡×≡↔≡ F.∘ T.∥∥×∥∥↔∥×∥) ⟩ (∃ λ ((x , i) : 𝕊¹ × ℤ) → ∥ x ≡ base ∥ × ∥ i ≡ + 1 ∥) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → Σ-assoc F.∘ (∃-cong λ _ → ∃-comm) F.∘ inverse Σ-assoc) ⟩ ((∃ λ x → ∥ x ≡ base ∥) × (∃ λ i → ∥ i ≡ + 1 ∥)) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → (drop-⊤-right λ _ → T.inhabited⇒∥∥↔⊤ $ all-points-on-the-circle-are-merely-equal _) ×-cong ∃-cong λ _ → T.∥∥↔ ℤ-set) ⟩ (𝕊¹ × (∃ λ i → i ≡ + 1)) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ⟩□ 𝕊¹ × 𝕊¹ □ ------------------------------------------------------------------------ -- Isomorphisms expressed using lens quasi-inverses private module B {a} = Bi-invertibility equality-with-J (Type a) Lens id _∘_ module BM {a} = B.More {a = a} left-identity right-identity associativity -- A form of isomorphism between types, expressed using lenses. open B public using () renaming (_≅_ to _≅_; Has-quasi-inverse to Has-quasi-inverse) -- An equality characterisation lemma for A ≅ B that applies when A is -- a set. equality-characterisation-for-sets-≅ : let open Lens in {f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≅ B} → Is-set A → f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂ equality-characterisation-for-sets-≅ {f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set = f₁ ≡ f₂ ↔⟨ BM.equality-characterisation-≅-domain (lens-preserves-h-level-of-domain 1 A-set) _ _ ⟩ l₁₁ ≡ l₁₂ ↝⟨ equality-characterisation-for-sets A-set ⟩□ set l₁₁ ≡ set l₁₂ □ where open Lens -- There is a split surjection from A ≅ B to A ≃ B. ≅↠≃ : (A ≅ B) ↠ (A ≃ B) ≅↠≃ {A = A} {B = B} = record { logical-equivalence = record { to = λ (l₁ , l₂ , eq₁ , eq₂) → Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = get l₁ ; from = get l₂ } ; right-inverse-of = ext⁻¹ $ getters-equal-if-setters-equal (l₁ ∘ l₂) id (cong set eq₁) } ; left-inverse-of = ext⁻¹ $ getters-equal-if-setters-equal (l₂ ∘ l₁) id (cong set eq₂) }) ; from = λ A≃B → ≃→lens A≃B , ≃→lens (inverse A≃B) , lemma A≃B , (≃→lens (inverse A≃B) ∘ ≃→lens A≃B ≡⟨ cong (λ A≃B′ → ≃→lens (inverse A≃B) ∘ ≃→lens A≃B′) $ sym $ Eq.inverse-involutive ext A≃B ⟩ ≃→lens (inverse A≃B) ∘ ≃→lens (inverse $ inverse A≃B) ≡⟨ lemma (inverse A≃B) ⟩∎ id ∎) } ; right-inverse-of = λ _ → Eq.lift-equality ext (refl _) } where open Lens lemma : (C≃D : C ≃ D) → ≃→lens C≃D ∘ ≃→lens (inverse C≃D) ≡ id lemma C≃D = _↔_.from equality-characterisation₂ ( ⟨ext⟩ (_≃_.right-inverse-of C≃D) , (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) , lemma₁ , lemma₂ , lemma₃ ) where lemma₁ = λ d₁ d₂ → let lemma = cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂)))) $ ext-const (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂))) (cong const $ ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₂))) (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (_≃_.to C≃D ⊚ _≃_.from C≃D) (cong (λ set → set d₂) (⟨ext⟩ $ _≃_.right-inverse-of C≃D)) ≡⟨ cong (cong (_≃_.to C≃D ⊚ _≃_.from C≃D)) $ cong-ext _ ⟩ cong (_≃_.to C≃D ⊚ _≃_.from C≃D) (_≃_.right-inverse-of C≃D _) ≡⟨ sym $ cong-∘ _ _ (_≃_.right-inverse-of C≃D _) ⟩ cong (_≃_.to C≃D) (cong (_≃_.from C≃D) (_≃_.right-inverse-of C≃D _)) ≡⟨ cong (cong (_≃_.to C≃D)) $ _≃_.right-left-lemma C≃D _ ⟩∎ cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _) ∎ in trans (sym (trans (cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D)) (cong (λ get → get d₂) (⟨ext⟩ $ _≃_.right-inverse-of C≃D)))) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _)) ≡⟨ cong₂ (λ p q → trans (sym (trans p q)) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _))) lemma (cong-ext _) ⟩ trans (sym (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _))) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃_.right-inverse-of C≃D _)) ⟩∎ refl _ ∎ lemma₂ = λ d → let lemma = cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d)))) $ ext-const (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d))) (cong const $ ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → set (_≃_.to C≃D (_≃_.from C≃D d))) (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong-ext _ ⟩∎ _≃_.right-inverse-of C≃D _ ∎ in trans (sym (trans (cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D)) (cong (λ get → get d) (⟨ext⟩ $ _≃_.right-inverse-of C≃D)))) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.left-inverse-of (inverse C≃D) _)) ≡⟨ cong₂ (λ p q → trans (sym p) q) (cong₂ trans lemma (cong-ext _)) (cong₂ trans (_≃_.left-right-lemma C≃D _) (Eq.left-inverse-of∘inverse C≃D)) ⟩ trans (sym (trans (_≃_.right-inverse-of C≃D _) (_≃_.right-inverse-of C≃D _))) (trans (_≃_.right-inverse-of C≃D _) (_≃_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃_.right-inverse-of C≃D _)) ⟩∎ refl _ ∎ lemma₃ = λ d d₁ d₂ → subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) (trans (refl _) (trans (cong (λ _ → _≃_.to C≃D (_≃_.from C≃D d₂)) (_≃_.right-inverse-of (inverse C≃D) (_≃_.from C≃D d₁))) (cong (_≃_.to C≃D) (refl _)))) ≡⟨ cong (subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D)) $ trans (trans-reflˡ _) $ trans (cong (flip trans _) $ cong-const _) $ trans (trans-reflˡ _) $ cong-refl _ ⟩ subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) (refl _) ≡⟨ cong (flip (subst (λ set → set (set d d₁) d₂ ≡ set d d₂)) _) $ ext-const (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (cong const $ ⟨ext⟩ $ _≃_.right-inverse-of C≃D) (refl _) ≡⟨ sym $ subst-∘ _ _ _ ⟩ subst (λ set → set d₂ ≡ set d₂) (⟨ext⟩ $ _≃_.right-inverse-of C≃D) (refl _) ≡⟨ subst-ext _ _ ⟩ subst (λ set → set ≡ set) (_≃_.right-inverse-of C≃D d₂) (refl _) ≡⟨ ≡⇒↝ _ (sym [subst≡]≡[trans≡trans]) ( trans (refl _) (_≃_.right-inverse-of C≃D d₂) ≡⟨ trans-reflˡ _ ⟩ _≃_.right-inverse-of C≃D d₂ ≡⟨ sym $ trans-reflʳ _ ⟩ trans (_≃_.right-inverse-of C≃D d₂) (refl _) ∎) ⟩ refl _ ∎ -- The right-to-left direction of ≅↠≃ maps identity to an isomorphism -- for which the first projection is the identity. ≅↠≃-id≡id : proj₁ (_↠_.from ≅↠≃ F.id) ≡ id {A = A} ≅↠≃-id≡id = equal-laws→≡ (λ _ _ → refl _) (λ a → _≃_.left-inverse-of F.id a ≡⟨ sym $ _≃_.right-left-lemma F.id _ ⟩ cong P.id (_≃_.right-inverse-of F.id a) ≡⟨⟩ cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎ refl _ ∎) (λ _ _ _ → refl _) -- If A is a set, then there is an equivalence between A ≃ B and A ≅ B. ≃≃≅ : Is-set A → (A ≃ B) ≃ (A ≅ B) ≃≃≅ {A = A} {B = B} A-set = Eq.↔⇒≃ $ inverse (record { surjection = ≅↠≃ ; left-inverse-of = λ (l₁ , l₂ , eq₁ , eq₂) → _↔_.from (equality-characterisation-for-sets-≅ A-set) $ ⟨ext⟩ λ a → ⟨ext⟩ λ b → get l₂ b ≡⟨ sym $ ext⁻¹ (ext⁻¹ (cong set eq₂) _) _ ⟩ set l₁ (set l₁ a b) (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ set-set l₁ _ _ _ ⟩ set l₁ a (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ cong (λ b′ → set l₁ a (set l₂ b′ (get l₂ b))) $ get-set l₁ _ _ ⟩ set l₁ a (set l₂ b (get l₂ b)) ≡⟨ cong (set l₁ a) $ set-get l₂ _ ⟩∎ set l₁ a b ∎ }) where open Lens -- The equivalence maps identity to an isomorphism for which the first -- projection is the identity. ≃≃≅-id≡id : (A-set : Is-set A) → proj₁ (_≃_.to (≃≃≅ A-set) F.id) ≡ id ≃≃≅-id≡id _ = ≅↠≃-id≡id -- The type Has-quasi-inverse id is not necessarily a proposition -- (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.¬-type-of-refl-propositional.) Has-quasi-inverse-id-not-proposition : Univalence lzero → ∃ λ (A : Type a) → ¬ Is-proposition (Has-quasi-inverse (id {A = A})) Has-quasi-inverse-id-not-proposition _ = X , (Is-proposition (Has-quasi-inverse id) ↝⟨ flip propositional⇒inhabited⇒contractible q ⟩ Contractible (Has-quasi-inverse id) ↝⟨ H-level-cong _ 0 lemma₁ ⟩ Contractible (∃ λ (g : (x : X) → x ≡ x) → _) ↝⟨ flip proj₁-closure 0 (λ g → (λ _ x → sym (g x)) , lemma₂ g , lemma₃ g , lemma₄ g) ⟩ Contractible ((x : X) → x ≡ x) ↝⟨ mono₁ 0 ⟩ Is-proposition ((x : X) → x ≡ x) ↝⟨ ¬-prop ⟩□ ⊥ □) where X = Erased (proj₁ Circle.¬-type-of-refl-propositional) ¬-prop = E.Stable-¬ [ Is-proposition ((x : X) → x ≡ x) ↝⟨ H-level-cong _ 1 (Π-cong ext (E.erased E.Erased↔) λ _ → inverse E.≡≃[]≡[]) ⟩ Is-proposition ((x : ↑ _ 𝕊¹) → x ≡ x) ↝⟨ proj₂ Circle.¬-type-of-refl-propositional ⟩□ ⊥ □ ] q = id , left-identity _ , right-identity _ lemma₁ = Has-quasi-inverse id ↝⟨ BM.Has-quasi-inverse≃id≡id-domain q ⟩ id ≡ id ↔⟨ equality-characterisation₄ ⟩□ (∃ λ (g : ∀ x → x ≡ x) → ∃ λ (s : X → ∀ x → x ≡ x) → (∀ x y → trans (sym (trans (cong P.id (s x y)) (g y))) (refl _) ≡ refl _) × (∀ x → trans (sym (trans (s x x) (cong P.id (g x)))) (refl _) ≡ refl _) × (∀ x y z → trans (refl _) (s x z) ≡ trans (cong (λ set → set (set x y) z) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (refl _))) □ lemma₂ : (g : ∀ x → x ≡ x) (x y : X) → _ lemma₂ g x y = trans (sym (trans (cong P.id (sym (g y))) (g y))) (refl _) ≡⟨ trans-reflʳ _ ⟩ sym (trans (cong P.id (sym (g y))) (g y)) ≡⟨ cong (λ eq → sym (trans eq (g y))) $ sym $ cong-id _ ⟩ sym (trans (sym (g y)) (g y)) ≡⟨ cong sym $ trans-symˡ (g y) ⟩ sym (refl _) ≡⟨ sym-refl ⟩∎ refl _ ∎ lemma₃ : (g : ∀ x → x ≡ x) (x : X) → _ lemma₃ g x = trans (sym (trans (sym (g x)) (cong P.id (g x)))) (refl _) ≡⟨ trans-reflʳ _ ⟩ sym (trans (sym (g x)) (cong P.id (g x))) ≡⟨ cong (λ eq → sym (trans (sym (g x)) eq)) $ sym $ cong-id (g x) ⟩ sym (trans (sym (g x)) (g x)) ≡⟨ cong sym $ trans-symˡ (g x) ⟩ sym (refl _) ≡⟨ sym-refl ⟩∎ refl _ ∎ lemma₄ : (g : ∀ x → x ≡ x) (x y z : X) → _ lemma₄ g x y z = trans (refl _) (sym (g z)) ≡⟨ trans-reflˡ (sym (g z)) ⟩ sym (g z) ≡⟨ sym $ cong-ext (sym ⊚ g) ⟩ cong (_$ z) (⟨ext⟩ (sym ⊚ g)) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ (sym ⊚ g)) ⟩ cong (λ set → set (set x y) z) (cong const (⟨ext⟩ (sym ⊚ g))) ≡⟨ cong (cong (λ set → set (set x y) z)) $ sym $ ext-const (⟨ext⟩ (sym ⊚ g)) ⟩ cong (λ set → set (set x y) z) (⟨ext⟩ λ _ → ⟨ext⟩ (sym ⊚ g)) ≡⟨ sym $ trans-reflʳ _ ⟩∎ trans (cong (λ set → set (set x y) z) (⟨ext⟩ λ _ → ⟨ext⟩ (sym ⊚ g))) (refl _) ∎ -- There is not necessarily a split surjection from -- Is-equivalence (Lens.get l) to Has-quasi-inverse l, if l is a lens -- between types in the same universe (assuming univalence). ¬Is-equivalence↠Has-quasi-inverse : Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → Is-equivalence (Lens.get l) ↠ Has-quasi-inverse l) ¬Is-equivalence↠Has-quasi-inverse univ surj = $⟨ mono₁ 0 ⊤-contractible ⟩ Is-proposition ⊤ ↝⟨ H-level.respects-surjection lemma 1 ⟩ Is-proposition (Has-quasi-inverse id) ↝⟨ proj₂ $ Has-quasi-inverse-id-not-proposition univ ⟩□ ⊥ □ where lemma = ⊤ ↔⟨ inverse $ _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Eq.propositional ext _) (_≃_.is-equivalence Eq.id) ⟩ Is-equivalence P.id ↝⟨ surj id ⟩□ Has-quasi-inverse id □ ------------------------------------------------------------------------ -- Isomorphisms expressed using bi-invertibility for lenses -- A form of isomorphism between types, expressed using lenses. open B public using () renaming (_≊_ to _≊_; Has-left-inverse to Has-left-inverse; Has-right-inverse to Has-right-inverse; Is-bi-invertible to Is-bi-invertible) open BM public using () renaming (Is-bi-invertible-propositional to Is-bi-invertible-propositional) -- An equality characterisation lemma for A ≊ B that applies when A is -- a set. equality-characterisation-for-sets-≊ : let open Lens in {f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≊ B} → Is-set A → f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂ equality-characterisation-for-sets-≊ {f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set = f₁ ≡ f₂ ↔⟨ BM.equality-characterisation-≊ _ _ ⟩ l₁₁ ≡ l₁₂ ↝⟨ equality-characterisation-for-sets A-set ⟩□ set l₁₁ ≡ set l₁₂ □ where open Lens -- There is a split surjection from A ≊ B to A ≃ B. ≊↠≃ : (A ≊ B) ↠ (A ≃ B) ≊↠≃ = record { logical-equivalence = record { to = _↠_.to ≅↠≃ ⊚ _↠_.from BM.≅↠≊ ; from = _↠_.to BM.≅↠≊ ⊚ _↠_.from ≅↠≃ } ; right-inverse-of = λ _ → Eq.lift-equality ext (refl _) } -- The right-to-left direction maps identity to an isomorphism for -- which the first projection is the identity. ≊↠≃-id≡id : proj₁ (_↠_.from ≊↠≃ F.id) ≡ id {A = A} ≊↠≃-id≡id = equal-laws→≡ (λ _ _ → refl _) (λ a → _≃_.left-inverse-of F.id a ≡⟨ sym $ _≃_.right-left-lemma F.id _ ⟩ cong P.id (_≃_.right-inverse-of F.id a) ≡⟨⟩ cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎ refl _ ∎) (λ _ _ _ → refl _) -- If A is a set, then there is an equivalence between A ≊ B and -- A ≃ B. ≃≃≊ : Is-set A → (A ≃ B) ≃ (A ≊ B) ≃≃≊ {A = A} {B = B} A-set = A ≃ B ↝⟨ ≃≃≅ A-set ⟩ A ≅ B ↝⟨ inverse $ BM.≊≃≅-domain (lens-preserves-h-level-of-domain 1 A-set) ⟩□ A ≊ B □ -- The equivalence ≃≃≊ maps identity to an isomorphism for which the -- first projection is the identity. ≃≃≊-id≡id : (A-set : Is-set A) → proj₁ (_≃_.to (≃≃≊ A-set) F.id) ≡ id ≃≃≊-id≡id _ = ≊↠≃-id≡id -- The right-to-left direction of ≃≃≊ maps bi-invertible lenses to -- their getter functions. to-from-≃≃≊≡get : (A-set : Is-set A) (A≊B@(l , _) : A ≊ B) → _≃_.to (_≃_.from (≃≃≊ A-set) A≊B) ≡ Lens.get l to-from-≃≃≊≡get _ _ = refl _ -- The getter function of a bi-invertible lens is an equivalence. Is-bi-invertible→Is-equivalence-get : (l : Lens A B) → Is-bi-invertible l → Is-equivalence (Lens.get l) Is-bi-invertible→Is-equivalence-get l is-bi-inv = _≃_.is-equivalence (_↠_.to ≊↠≃ (l , is-bi-inv)) -- If the getter function is an equivalence, then the lens is -- bi-invertible. Is-equivalence-get→Is-bi-invertible : (l : Lens A B) → Is-equivalence (Lens.get l) → Is-bi-invertible l Is-equivalence-get→Is-bi-invertible {A = A} {B = B} l′ is-equiv = block λ b → $⟨ l⁻¹′ b , l∘l⁻¹≡id b , l⁻¹∘l≡id b ⟩ Has-quasi-inverse l ↝⟨ B.Has-quasi-inverse→Is-bi-invertible l ⟩ Is-bi-invertible l ↝⟨ subst Is-bi-invertible (getter-equivalence→lens≡ l′ is-equiv) ⟩□ Is-bi-invertible l′ □ where open Lens -- A lens that is equal to l′. l : Lens A B l = getter-equivalence→lens l′ is-equiv A≃B = Eq.⟨ get l , is-equiv ⟩ open _≃_ A≃B -- An inverse of l. -- -- Note that the set-get and set-set proofs have been "obfuscated". -- They could have been shorter, but then it might not have been -- possible to prove l∘l⁻¹≡id and l⁻¹∘l≡id. l⁻¹ : Lens B A l⁻¹ = record { get = from ; set = λ _ → get l ; get-set = λ _ a → from (get l a) ≡⟨ left-inverse-of a ⟩∎ a ∎ ; set-get = λ b → get l (from b) ≡⟨ sym $ cong (get l) $ set-get l (from b) ⟩ get l (from (get l (from b))) ≡⟨ right-inverse-of (get l (from b)) ⟩ get l (from b) ≡⟨ right-inverse-of b ⟩∎ b ∎ ; set-set = λ b a₁ a₂ → get l a₂ ≡⟨ sym $ right-inverse-of _ ⟩ get l (from (get l a₂)) ≡⟨ sym $ cong (get l) (set-set l (from b) (get l a₁) (get l a₂)) ⟩ get l (from (get l a₂)) ≡⟨ right-inverse-of _ ⟩∎ get l a₂ ∎ } -- A blocked variant of l⁻¹. l⁻¹′ : Block "l⁻¹" → Lens B A l⁻¹′ ⊠ = l⁻¹ -- The lens l⁻¹ is a right inverse of l. l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹′ b ≡ id l∘l⁻¹≡id ⊠ = constant-setter→≡id ( right-inverse-of , right-inverse-of , (λ b₁ b₂ → get-set (l ∘ l⁻¹) b₁ b₂ ≡⟨⟩ trans (cong (get l) (get-set l⁻¹ b₁ (from b₂))) (get-set l (from b₁) b₂) ≡⟨⟩ trans (cong (get l) (left-inverse-of (from b₂))) (right-inverse-of b₂) ≡⟨ cong (λ eq → trans (cong (get l) eq) (right-inverse-of b₂)) $ sym $ right-left-lemma _ ⟩ trans (cong (get l) (cong from (right-inverse-of b₂))) (right-inverse-of b₂) ≡⟨ cong (λ eq → trans eq (right-inverse-of b₂)) $ cong-∘ _ _ (right-inverse-of b₂) ⟩ trans (cong (get l ⊚ from) (right-inverse-of b₂)) (right-inverse-of b₂) ≡⟨⟩ trans (cong (get (l ∘ l⁻¹)) (right-inverse-of b₂)) (right-inverse-of b₂) ∎) , (λ b → set-get (l ∘ l⁻¹) b ≡⟨⟩ trans (cong (get l) (set-get l (from b))) (set-get l⁻¹ b) ≡⟨⟩ trans (cong (get l) (set-get l (from b))) (trans (sym (cong (get l) (set-get l (from b)))) (trans (right-inverse-of (get l (from b))) (right-inverse-of b))) ≡⟨ trans--[trans-sym] _ _ ⟩ trans (right-inverse-of (get l (from b))) (right-inverse-of b) ≡⟨⟩ trans (right-inverse-of (get (l ∘ l⁻¹) b)) (right-inverse-of b) ∎) , (λ b b₁ b₂ → set-set (l ∘ l⁻¹) b b₁ b₂ ≡⟨⟩ trans (set-set l⁻¹ b (from b₁) (from b₂)) (trans (cong (λ _ → get l (from b₂)) (get-set l⁻¹ b (from b₁))) (cong (get l) (set-set l (from b) b₁ b₂))) ≡⟨ cong (trans _) $ trans (cong (flip trans _) $ cong-const _) $ trans-reflˡ _ ⟩ trans (set-set l⁻¹ b (from b₁) (from b₂)) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨⟩ trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) (get l (from b₁)) (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ b′ → trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) b′ (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂))) $ right-inverse-of _ ⟩ trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ f → trans (trans (sym (f _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (f _))) (cong (get l) (set-set l (from b) b₁ b₂))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) right-inverse-of ⟩ trans (trans (sym (ext⁻¹ (⟨ext⟩ right-inverse-of) _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (ext⁻¹ (⟨ext⟩ right-inverse-of) _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : ∀ b → f b ≡ f b) → trans (trans (sym (ext⁻¹ p (f b₂))) (trans (sym (q (f b₂))) (ext⁻¹ p (f b₂)))) (q b₂) ≡ refl _) (λ q → trans (trans (sym (ext⁻¹ (refl P.id) _)) (trans (sym (q _)) (ext⁻¹ (refl P.id) _))) (q _) ≡⟨ cong (λ eq → trans (trans (sym eq) (trans (sym (q _)) eq)) (q _)) $ ext⁻¹-refl _ ⟩ trans (trans (sym (refl _)) (trans (sym (q _)) (refl _))) (q _) ≡⟨ cong₂ (λ p r → trans (trans p r) (q _)) sym-refl (trans-reflʳ _) ⟩ trans (trans (refl _) (sym (q _))) (q _) ≡⟨ cong (λ eq → trans eq (q _)) $ trans-reflˡ (sym (q _)) ⟩ trans (sym (q _)) (q _) ≡⟨ trans-symˡ (q _) ⟩∎ refl _ ∎) (⟨ext⟩ right-inverse-of) (cong (get l) ⊚ set-set l (from b) b₁) ⟩ refl _ ∎) ) -- The lens l⁻¹ is a left inverse of l. l⁻¹∘l≡id : ∀ b → l⁻¹′ b ∘ l ≡ id l⁻¹∘l≡id ⊠ = constant-setter→≡id ( left-inverse-of , left-inverse-of , (λ a₁ a₂ → get-set (l⁻¹ ∘ l) a₁ a₂ ≡⟨⟩ trans (cong from (get-set l a₁ (to a₂))) (get-set l⁻¹ (get l a₁) a₂) ≡⟨⟩ trans (cong from (right-inverse-of (to a₂))) (left-inverse-of a₂) ≡⟨ cong (λ eq → trans (cong from eq) (left-inverse-of _)) $ sym $ left-right-lemma _ ⟩ trans (cong from (cong (get l) (left-inverse-of a₂))) (left-inverse-of a₂) ≡⟨ cong (λ eq → trans eq (left-inverse-of _)) $ cong-∘ _ _ (left-inverse-of _) ⟩ trans (cong (from ⊚ get l) (left-inverse-of a₂)) (left-inverse-of a₂) ≡⟨⟩ trans (cong (get (l⁻¹ ∘ l)) (left-inverse-of a₂)) (left-inverse-of a₂) ∎) , (λ a → let lemma₁ = cong from (trans (sym (cong (get l) (set-get l (from (get l a))))) (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong-trans _ _ (trans _ (right-inverse-of _)) ⟩ trans (cong from (sym (cong (get l) (set-get l (from (get l a)))))) (cong from (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong (λ eq → trans (cong from eq) (cong from (trans (right-inverse-of _) (right-inverse-of _)))) $ sym $ cong-sym _ (set-get l (from (get l a))) ⟩ trans (cong from (cong (get l) (sym (set-get l (from (get l a)))))) (cong from (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong₂ trans (cong-∘ _ _ (sym (set-get l (from (get l a))))) (cong-trans _ _ (right-inverse-of _)) ⟩ trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans (cong from (right-inverse-of _)) (cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p q → trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans p q)) (right-left-lemma _) (right-left-lemma _) ⟩∎ trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans (left-inverse-of _) (left-inverse-of _)) ∎ f = from ⊚ get l lemma₂ : ∀ _ → _ lemma₂ = λ a → trans (left-inverse-of (f a)) (left-inverse-of a) ≡⟨ cong (λ g → trans (g (f a)) (g a)) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) left-inverse-of ⟩∎ trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)) (ext⁻¹ (⟨ext⟩ left-inverse-of) a) ∎ lemma₃ = trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ≡⟨ cong₂ trans (ext⁻¹-refl _) (ext⁻¹-refl _) ⟩ trans (refl _) (refl _) ≡⟨ trans-refl-refl ⟩∎ refl _ ∎ in trans (cong from (set-get l⁻¹ (get l a))) (set-get l a) ≡⟨⟩ trans (cong from (trans (sym (cong (get l) (set-get l (from (get l a))))) (trans (right-inverse-of _) (right-inverse-of _)))) (set-get l a) ≡⟨ cong (λ eq → trans eq (set-get l a)) lemma₁ ⟩ trans (trans (cong f (sym (set-get l (f a)))) (trans (left-inverse-of (f (f a))) (left-inverse-of (f a)))) (set-get l a) ≡⟨ cong (λ eq → trans (trans (cong f (sym (set-get l (f a)))) eq) (set-get l a)) $ lemma₂ _ ⟩ trans (trans (cong f (sym (set-get l (f a)))) (trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f (f a))) (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)))) (set-get l a) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : ∀ a → f a ≡ a) → trans (trans (cong f (sym (q (f a)))) (trans (ext⁻¹ p (f (f a))) (ext⁻¹ p (f a)))) (q a) ≡ trans (ext⁻¹ p (f a)) (ext⁻¹ p a)) (λ q → trans (trans (cong P.id (sym (q a))) (trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a))) (q a) ≡⟨ cong₂ (λ p r → trans (trans p r) (q a)) (sym $ cong-id _) lemma₃ ⟩ trans (trans (sym (q a)) (refl _)) (q a) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩ trans (sym (q a)) (q a) ≡⟨ trans-symˡ (q a) ⟩ refl _ ≡⟨ sym lemma₃ ⟩∎ trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ∎) (⟨ext⟩ left-inverse-of) (set-get l) ⟩ trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)) (ext⁻¹ (⟨ext⟩ left-inverse-of) a) ≡⟨ sym $ lemma₂ _ ⟩ trans (left-inverse-of (f a)) (left-inverse-of a) ≡⟨⟩ trans (left-inverse-of (get (l⁻¹ ∘ l) a)) (left-inverse-of a) ∎) , (λ a a₁ a₂ → let q = set-set l a (get l a₁) (get l a₂) lemma = cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) q)) (right-inverse-of _))) ≡⟨ cong-trans _ _ (trans (sym (cong (get l) q)) (right-inverse-of _)) ⟩ trans (cong from (sym (right-inverse-of _))) (cong from (trans (sym (cong (get l) q)) (right-inverse-of _))) ≡⟨ cong₂ trans (cong-sym _ (right-inverse-of _)) (cong-trans _ _ (right-inverse-of _)) ⟩ trans (sym (cong from (right-inverse-of _))) (trans (cong from (sym (cong (get l) q))) (cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p r → trans (sym p) (trans (cong from (sym (cong (get l) q))) r)) (right-left-lemma _) (right-left-lemma _) ⟩ trans (sym (left-inverse-of _)) (trans (cong from (sym (cong (get l) q))) (left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _)) (trans eq (left-inverse-of _))) $ cong-sym _ (cong (get l) q) ⟩ trans (sym (left-inverse-of _)) (trans (sym (cong from (cong (get l) q))) (left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _)) (trans (sym eq) (left-inverse-of _))) $ cong-∘ _ _ q ⟩ trans (sym (left-inverse-of _)) (trans (sym (cong (from ⊚ get l) q)) (left-inverse-of _)) ≡⟨ cong (λ g → trans (sym (g _)) (trans (sym (cong (from ⊚ get l) q)) (g _))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) left-inverse-of ⟩∎ trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) _)) (trans (sym (cong (from ⊚ get l) q)) (ext⁻¹ (⟨ext⟩ left-inverse-of) _)) ∎ f = from ⊚ get l in set-set (l⁻¹ ∘ l) a a₁ a₂ ≡⟨⟩ trans (set-set l a (get l a₁) (get l a₂)) (trans (cong (λ _ → from (get l a₂)) (right-inverse-of (get l a₁))) (cong from (set-set l⁻¹ (get l a) a₁ a₂))) ≡⟨ cong (trans _) $ trans (cong (flip trans _) $ cong-const _) $ trans-reflˡ _ ⟩ trans (set-set l a (get l a₁) (get l a₂)) (cong from (set-set l⁻¹ (get l a) a₁ a₂)) ≡⟨⟩ trans (set-set l a (get l a₁) (get l a₂)) (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from (get l a)) (get l a₁) (get l a₂)))) (right-inverse-of _)))) ≡⟨ cong (λ a′ → trans q (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l a′ (get l a₁) (get l a₂)))) (right-inverse-of _))))) $ left-inverse-of _ ⟩ trans q (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) q)) (right-inverse-of _)))) ≡⟨ cong (trans q) lemma ⟩ trans q (trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂))) (trans (sym (cong f q)) (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : f a₂ ≡ f a₂) → trans q (trans (sym (ext⁻¹ p (f a₂))) (trans (sym (cong f q)) (ext⁻¹ p (f a₂)))) ≡ refl _) (λ q → trans q (trans (sym (ext⁻¹ (refl P.id) a₂)) (trans (sym (cong P.id q)) (ext⁻¹ (refl P.id) a₂))) ≡⟨ cong (λ eq → trans q (trans (sym eq) (trans (sym (cong P.id q)) eq))) $ ext⁻¹-refl _ ⟩ trans q (trans (sym (refl _)) (trans (sym (cong P.id q)) (refl _))) ≡⟨ cong₂ (λ p r → trans q (trans p r)) sym-refl (trans-reflʳ _) ⟩ trans q (trans (refl _) (sym (cong P.id q))) ≡⟨ cong (trans q) $ trans-reflˡ (sym (cong P.id q)) ⟩ trans q (sym (cong P.id q)) ≡⟨ cong (λ eq → trans q (sym eq)) $ sym $ cong-id q ⟩ trans q (sym q) ≡⟨ trans-symʳ q ⟩∎ refl _ ∎) (⟨ext⟩ left-inverse-of) q ⟩ refl _ ∎) ) -- There is an equivalence between "l is bi-invertible" and "the -- getter of l is an equivalence". Is-bi-invertible≃Is-equivalence-get : (l : Lens A B) → Is-bi-invertible l ≃ Is-equivalence (Lens.get l) Is-bi-invertible≃Is-equivalence-get l = Eq.⇔→≃ (BM.Is-bi-invertible-propositional l) (Eq.propositional ext _) (Is-bi-invertible→Is-equivalence-get l) (Is-equivalence-get→Is-bi-invertible l) -- There is in general no split surjection from equivalences to -- bi-invertible lenses, if the right-to-left direction of the split -- surjection is required to map bi-invertible lenses to their getter -- functions (assuming univalence). ¬≃↠≊ : Univalence lzero → ¬ ∃ λ (≃↠≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_↠_.from ≃↠≊ x) ≡ Lens.get l ¬≃↠≊ {a = a} univ = (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map ((∃-cong λ l → _≃_.surjection $ Is-bi-invertible≃Is-equivalence-get l) F.∘_) (λ hyp _ → hyp _) ⟩ (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃-↠-Σ-Lens-Is-equivalence-get univ ⟩□ ⊥ □ -- There is in general no equivalence between equivalences and -- bi-invertible lenses, if the right-to-left direction of the -- equivalence is required to map bi-invertible lenses to their getter -- functions (assuming univalence). ¬≃≃≊ : Univalence lzero → ¬ ∃ λ (≃≃≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_≃_.from ≃≃≊ x) ≡ Lens.get l ¬≃≃≊ {a = a} univ = (∃ λ (≃≃≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_≃_.from ≃≃≊ x) ≡ Lens.get l) ↝⟨ Σ-map _≃_.surjection P.id ⟩ (∃ λ (≃↠≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_↠_.from ≃↠≊ x) ≡ Lens.get l) ↝⟨ ¬≃↠≊ univ ⟩□ ⊥ □ ------------------------------------------------------------------------ -- A category -- Lenses between sets with the same universe level form a -- precategory. precategory : Precategory (lsuc a) a precategory {a = a} = record { precategory = Set a , (λ (A , A-set) (B , _) → Lens A B , lens-preserves-h-level-of-domain 1 A-set) , id , _∘_ , left-identity _ , right-identity _ , (λ {_ _ _ _ l₁ l₂ l₃} → associativity l₃ l₂ l₁) } -- Lenses between sets with the same universe level form a -- category (assuming univalence). category : Univalence a → Category (lsuc a) a category {a = a} univ = C.precategory-with-Set-to-category ext (λ _ _ → univ) (proj₂ Pre.precategory) (λ (_ , A-set) _ → ≃≃≅ A-set) (λ (_ , A-set) → ≃≃≅-id≡id A-set) where module Pre = C.Precategory precategory -- The following four results (up to and including ¬-univalent) are -- based on a suggestion by Paolo Capriotti, in response to a question -- from an anonymous reviewer. -- A "naive" notion of category. -- -- Note that the hom-sets are not required to be sets. Naive-category : (o h : Level) → Type (lsuc (o ⊔ h)) Naive-category o h = ∃ λ (Obj : Type o) → ∃ λ (Hom : Obj → Obj → Type h) → ∃ λ (id : {A : Obj} → Hom A A) → ∃ λ (_∘_ : {A B C : Obj} → Hom B C → Hom A B → Hom A C) → ({A B : Obj} (h : Hom A B) → id ∘ h ≡ h) × ({A B : Obj} (h : Hom A B) → h ∘ id ≡ h) × ({A B C D : Obj} (h₁ : Hom C D) (h₂ : Hom B C) (h₃ : Hom A B) → (h₁ ∘ (h₂ ∘ h₃)) ≡ ((h₁ ∘ h₂) ∘ h₃)) -- A notion of univalence for naive categories. Univalent : Naive-category o h → Type (o ⊔ h) Univalent (Obj , Hom , id , _∘_ , id-∘ , ∘-id , assoc) = Bi-invertibility.More.Univalence-≊ equality-with-J Obj Hom id _∘_ id-∘ ∘-id assoc -- Types in a fixed universe and traditional lenses between them form -- a naive category. naive-category : ∀ a → Naive-category (lsuc a) a naive-category a = Type a , Lens , id , _∘_ , left-identity , right-identity , associativity -- However, this category is not univalent (assuming univalence). ¬-univalent : Univalence lzero → Univalence a → ¬ Univalent (naive-category a) ¬-univalent {a = a} univ₀ univ u = ¬≃≃≊ univ₀ (equiv , lemma₂) where equiv : {A B : Type a} → (A ≃ B) ≃ (A ≊ B) equiv {A = A} {B = B} = (A ≃ B) ↝⟨ inverse $ ≡≃≃ univ ⟩ (A ≡ B) ↝⟨ Eq.⟨ _ , u ⟩ ⟩□ (A ≊ B) □ lemma₁ : (eq : ↑ a 𝕊¹ ≃ ↑ a 𝕊¹) → _≃_.to eq ≡ Lens.get (proj₁ (_≃_.to equiv eq)) lemma₁ = ≃-elim₁ univ (λ eq → _≃_.to eq ≡ Lens.get (proj₁ (_≃_.to equiv eq))) (P.id ≡⟨ cong (Lens.get ⊚ proj₁) $ sym $ elim-refl _ _ ⟩ Lens.get (proj₁ (BM.≡→≊ (refl _))) ≡⟨ cong (Lens.get ⊚ proj₁ ⊚ BM.≡→≊) $ sym $ ≃⇒≡-id univ ⟩ Lens.get (proj₁ (BM.≡→≊ (≃⇒≡ univ Eq.id))) ≡⟨⟩ Lens.get (proj₁ (_≃_.to equiv Eq.id)) ∎) lemma₂ : (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_≃_.from equiv x) ≡ Lens.get l lemma₂ x@(l , _) = _≃_.to (_≃_.from equiv x) ≡⟨ lemma₁ (_≃_.from equiv x) ⟩ Lens.get (proj₁ (_≃_.to equiv (_≃_.from equiv x))) ≡⟨ cong (Lens.get ⊚ proj₁) $ _≃_.right-inverse-of equiv _ ⟩ Lens.get (proj₁ x) ≡⟨⟩ Lens.get l ∎ -- There is in general no pointwise equivalence between equivalences -- and bi-invertible lenses (assuming univalence). ¬Π≃≃≊ : Univalence lzero → Univalence a → ¬ ({A B : Type a} → (A ≃ B) ≃ (A ≊ B)) ¬Π≃≃≊ {a = a} univ₀ univ = ({A B : Type a} → (A ≃ B) ≃ (A ≊ B)) ↝⟨ F._∘ ≡≃≃ univ ⟩ ({A B : Type a} → (A ≡ B) ≃ (A ≊ B)) ↝⟨ BM.≡≃≊→Univalence-≊ ⟩ Univalent (naive-category a) ↝⟨ ¬-univalent univ₀ univ ⟩□ ⊥ □ -- There is in general no pointwise equivalence between equivalences -- (between types in the same universe) and lenses with getters that -- are equivalences (assuming univalence). ¬Π≃-≃-Σ-Lens-Is-equivalence-get : Univalence lzero → Univalence a → ¬ ({A B : Type a} → (A ≃ B) ≃ ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) ¬Π≃-≃-Σ-Lens-Is-equivalence-get {a = a} univ₀ univ = ({A B : Type a} → (A ≃ B) ≃ ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) ↝⟨ inverse (∃-cong Is-bi-invertible≃Is-equivalence-get) F.∘_ ⟩ ({A B : Type a} → (A ≃ B) ≃ (A ≊ B)) ↝⟨ ¬Π≃≃≊ univ₀ univ ⟩□ ⊥ □
{ "alphanum_fraction": 0.3639894377, "avg_line_length": 48.8344204717, "ext": "agda", "hexsha": "5923bb70ee56aeaf446ba484c16f40e3026e35d9", "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/Traditional/Combinators.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/Traditional/Combinators.agda", "max_line_length": 152, "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/Traditional/Combinators.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": 30286, "size": 97327 }
{- Joseph Eremondi Utrecht University Capita Selecta UU# 4229924 July 22, 2015 -} module RETypes where open import Data.Char open import Data.List open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Data.Product --Tag for whether an RE can match the empty string or not data Null? : Set where NonNull : Null? MaybeNull : Null? --Equivalent of AND for Nullable data NullTop : Null? -> Null? -> Null? -> Set where BothNullT : NullTop MaybeNull MaybeNull MaybeNull LeftNullT : NullTop MaybeNull NonNull NonNull RightNullT : NullTop NonNull MaybeNull NonNull BothNonNullT : NullTop NonNull NonNull NonNull --Equivalent of OR for null data NullBottom : Null? -> Null? -> Null? -> Set where BothNullB : NullBottom NonNull NonNull NonNull LeftNullB : NullBottom MaybeNull NonNull MaybeNull RightNullB : NullBottom NonNull MaybeNull MaybeNull BothNonNullB : NullBottom MaybeNull MaybeNull MaybeNull --Standard definition of regular expressions --plus nullable tags. Star can only accept non-nullable REs. data RE : Null? -> Set where ε : RE MaybeNull ∅ : RE NonNull Lit : Char -> RE NonNull --Union is nullable if either input is nullable _+_ : {n1 n2 n3 : Null? } -> {nb : NullBottom n1 n2 n3} -> RE n1 -> RE n2 -> RE n3 --Concatenation is nullable only if both inputs are nullable _·_ : {n1 n2 n3 : Null? } -> {nt : NullTop n1 n2 n3} -> RE n1 -> RE n2 -> RE n3 --Star always matches the empty string _* : RE NonNull -> RE MaybeNull --Witness type, defining what it means for a word to match a regular expression data REMatch : {n : Null?} -> List Char -> RE n -> Set where EmptyMatch : REMatch [] ε LitMatch : (c : Char) -> REMatch (c ∷ []) (Lit c) LeftPlusMatch : {n1 n2 n3 : Null? } -> {nb : NullBottom n1 n2 n3} -> {s : List Char} {r1 : RE n1} -> (r2 : RE n2) -> REMatch s r1 -> REMatch {n3} s (_+_ {n1} {n2} {n3} {nb} r1 r2) RightPlusMatch : {n1 n2 n3 : Null? } -> {nb : NullBottom n1 n2 n3} -> {s : List Char} -> (r1 : RE n1) -> {r2 : RE n2} -> REMatch s r2 -> REMatch {n3} s (_+_ {n1} {n2} {n3} {nb} r1 r2) ConcatMatch : {n1 n2 n3 : Null? } -> {nt : NullTop n1 n2 n3} -> {s1 s2 s3 : List Char} {spf : s1 ++ s2 ≡ s3} {r1 : RE n1} {r2 : RE n2} -> REMatch s1 r1 -> REMatch s2 r2 -> REMatch {n3} s3 (_·_ {n1} {n2} {n3} {nt} r1 r2) EmptyStarMatch : {r : RE NonNull} -> REMatch [] (r *) StarMatch : {s1 s2 s3 : List Char} {spf : (s1 ++ s2) ≡ s3} {r : RE NonNull} -> REMatch s1 r -> REMatch s2 (r *) -> REMatch s3 (r *) extendRightNonNull : (s : List Char) -> (sRest : List Char) -> (∃ λ c -> ∃ λ t -> (s ≡ c ∷ t)) -> (∃ λ c1 -> ∃ λ t1 -> (s ++ sRest ≡ c1 ∷ t1)) extendRightNonNull .(c ∷ t) sRest (c , t , refl) = c , t ++ sRest , refl extendLeftNonNull : (s : List Char) -> (sRest : List Char) -> (∃ λ c -> ∃ λ t -> (s ≡ c ∷ t)) -> (∃ λ c1 -> ∃ λ t1 -> (sRest ++ s ≡ c1 ∷ t1)) extendLeftNonNull .(t ∷ c) [] (t , c , refl) = t , c , refl extendLeftNonNull .(t ∷ c) (x ∷ sRest) (t , c , refl) = x , sRest ++ t ∷ c , refl nullCorrect : (r : RE NonNull ) -> (s : List Char) -> REMatch s r -> ∃ λ c -> ∃ λ t -> (s ≡ c ∷ t) nullCorrect .(Lit c) .(c ∷ []) (LitMatch c) = c , [] , refl nullCorrect ._ s (LeftPlusMatch {nb = BothNullB} {r1 = r1} r2 match) = nullCorrect r1 s match nullCorrect ._ s (RightPlusMatch {nb = BothNullB} r1 {r2 = r2} match) = nullCorrect r2 s match nullCorrect (r1 · r2) s (ConcatMatch {nt = LeftNullT} {s2 = s2} match match₁) with nullCorrect r2 s2 match₁ nullCorrect (r1 · r2) .(s1 ++ c ∷ t) (ConcatMatch {.MaybeNull} {.NonNull} {.NonNull} {LeftNullT} {s1} {.(c ∷ t)} {.(s1 ++ c ∷ t)} {refl} match match₁) | c , t , refl = extendLeftNonNull (c ∷ t) s1 (c , t , refl) nullCorrect (r1 · r2) ._ (ConcatMatch {nt = RightNullT} {s1 = s1} {spf = refl} match match₁) with nullCorrect r1 s1 match nullCorrect (r1 · r2) .((c ∷ t) ++ s2) (ConcatMatch {.NonNull} {.MaybeNull} {.NonNull} {RightNullT} {.(c ∷ t)} {s2} {.((c ∷ t) ++ s2)} {refl} match match₁) | c , t , refl = extendRightNonNull (c ∷ t) s2 (c , t , refl) nullCorrect (r1 · r2) s (ConcatMatch {nt = BothNonNullT} {s1 = s1} {s2 = s2} match match₁) with nullCorrect r1 s1 match nullCorrect (r1 · r2) .(c ∷ t ++ s2) (ConcatMatch {.NonNull} {.NonNull} {.NonNull} {BothNonNullT} {.(c ∷ t)} {s2} {.(c ∷ t ++ s2)} {refl} match match₁) | c , t , refl = extendRightNonNull (c ∷ t) s2 (c , t , refl)
{ "alphanum_fraction": 0.6031076582, "avg_line_length": 40.5855855856, "ext": "agda", "hexsha": "ef4e331a5693e52a7f8251c359902efde5bd4e17", "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": "1e28103ff7dd1d4f3351ef21397833aa4490b7ea", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "JoeyEremondi/agda-parikh", "max_forks_repo_path": "RETypes.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1e28103ff7dd1d4f3351ef21397833aa4490b7ea", "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": "JoeyEremondi/agda-parikh", "max_issues_repo_path": "RETypes.agda", "max_line_length": 217, "max_stars_count": null, "max_stars_repo_head_hexsha": "1e28103ff7dd1d4f3351ef21397833aa4490b7ea", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "JoeyEremondi/agda-parikh", "max_stars_repo_path": "RETypes.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1704, "size": 4505 }
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.Surjection open import Oscar.Data.Proposequality module Oscar.Class.Smap where open import Oscar.Class.Hmap public module Smap {𝔵₁ 𝔵₁'} {𝔛₁ : Ø 𝔵₁} {𝔛₁' : Ø 𝔵₁'} {𝔵₂ 𝔵₂'} {𝔛₂ : Ø 𝔵₂} {𝔛₂' : Ø 𝔵₂'} {𝔯₁₂} {𝔯₁₂'} (ℜ₁₂ : 𝔛₁ → 𝔛₂ → Ø 𝔯₁₂) (ℜ₁₂' : 𝔛₁' → 𝔛₂' → Ø 𝔯₁₂') (p₁ : 𝔛₁ → 𝔛₁') (p₂ : 𝔛₂ → 𝔛₂') where class = Hmap.class ℜ₁₂ (λ x y → ℜ₁₂' (p₁ x) (p₂ y)) type = ∀ {x y} → ℜ₁₂ x y → ℜ₁₂' (p₁ x) (p₂ y) method : ⦃ _ : class ⦄ → type method = Hmap.method ℜ₁₂ (λ x y → ℜ₁₂' (p₁ x) (p₂ y)) _ _ module _ {𝔵₁ 𝔯₁ 𝔵₂ 𝔯₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} {_∼₁_ : 𝔛₁ → 𝔛₁ → Ø 𝔯₁} (_∼₂_ : 𝔛₂ → 𝔛₂ → Ø 𝔯₂) (μ₁ μ₂ : Surjection.type 𝔛₁ 𝔛₂) where open Smap _∼₁_ _∼₂_ μ₁ μ₂ smap⟦_/_/_⟧ : ⦃ _ : class ⦄ → type smap⟦_/_/_⟧ = smap module ≡-Smap {𝔵₁ 𝔯₁ 𝔵₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (∼₁ : 𝔛₁ → 𝔛₁ → Ø 𝔯₁) (μ₁ μ₂ : Surjection.type 𝔛₁ 𝔛₂) = Smap ∼₁ _≡_ μ₁ μ₂ module _ {𝔵₁ 𝔯₁ 𝔵₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} {_∼₁_ : 𝔛₁ → 𝔛₁ → Ø 𝔯₁} (μ₁ μ₂ : Surjection.type 𝔛₁ 𝔛₂) where open Smap _∼₁_ _≡_ μ₁ μ₂ ≡-smap⟦_⟧ : ⦃ _ : class ⦄ → type ≡-smap⟦_⟧ = smap module Smap! {𝔵₁ 𝔯₁ 𝔵₂ 𝔯₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (∼₁ : 𝔛₁ → 𝔛₁ → Ø 𝔯₁) (∼₂ : 𝔛₂ → 𝔛₂ → Ø 𝔯₂) ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ = Smap ∼₁ ∼₂ surjection surjection module Smaparrow {𝔵₁ 𝔵₂ 𝔯 𝔭₁ 𝔭₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (ℜ : 𝔛₁ → 𝔛₁ → Ø 𝔯) (𝔓₁ : 𝔛₂ → Ø 𝔭₁) (𝔓₂ : 𝔛₂ → Ø 𝔭₂) (surjection₁ surjection₂ : Surjection.type 𝔛₁ 𝔛₂) = Smap ℜ (Arrow 𝔓₁ 𝔓₂) surjection₁ surjection₂ module _ {𝔵₁ 𝔯 𝔭₁ 𝔭₂} {𝔛₁ : Ø 𝔵₁} {ℜ : 𝔛₁ → 𝔛₁ → Ø 𝔯} {𝔓₁ : 𝔛₁ → Ø 𝔭₁} {𝔓₂ : 𝔛₁ → Ø 𝔭₂} where smaparrow = Smaparrow.method ℜ 𝔓₁ 𝔓₂ ¡ ¡ infixr 10 _◃_ _◃_ = smaparrow smaparrow[]syntax = _◃_ syntax smaparrow[]syntax 𝔛₂ x∼y fx = x∼y ◃[ 𝔛₂ ] fx module Smaparrow! {𝔵₁ 𝔵₂ 𝔯 𝔭₁ 𝔭₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (ℜ : 𝔛₁ → 𝔛₁ → Ø 𝔯) (𝔓₁ : 𝔛₂ → Ø 𝔭₁) (𝔓₂ : 𝔛₂ → Ø 𝔭₂) ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ = Smaparrow ℜ 𝔓₁ 𝔓₂ surjection surjection module Smaphomarrow {𝔵₁ 𝔯₁ 𝔵₂ 𝔯₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (ℜ : 𝔛₁ → 𝔛₁ → Ø 𝔯₁) (𝔓 : 𝔛₂ → Ø 𝔯₂) (surjection : Surjection.type 𝔛₁ 𝔛₂) = Smaparrow ℜ 𝔓 𝔓 surjection surjection module Smaphomarrow! {𝔵₁ 𝔯₁ 𝔵₂ 𝔯₂} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (ℜ : 𝔛₁ → 𝔛₁ → Ø 𝔯₁) (𝔓 : 𝔛₂ → Ø 𝔯₂) ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ = Smaphomarrow ℜ 𝔓 surjection
{ "alphanum_fraction": 0.5557446809, "avg_line_length": 23.9795918367, "ext": "agda", "hexsha": "ed0e70a86b63d01c8de4f8ce3b65817f3e33d24e", "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/Smap.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/Smap.agda", "max_line_length": 59, "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/Smap.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1583, "size": 2350 }
{-# OPTIONS --without-K #-} module PathOperations where open import Types infixr 4 _·_ infix 9 _⁻¹ _⁻¹ : ∀ {a} {A : Set a} {x y : A} → x ≡ y → y ≡ x _⁻¹ = J (λ x y _ → y ≡ x) (λ _ → refl) _ _ _·_ : ∀ {a} {A : Set a} {x y z : A} → x ≡ y → y ≡ z → x ≡ z _·_ {z = z} = J (λ x y _ → y ≡ z → x ≡ z) (λ _ p′ → p′) _ _ tr : ∀ {a p} {A : Set a} (P : A → Set p) {x y : A} (p : x ≡ y) → P x → P y tr P = J (λ x y _ → P x → P y) (λ _ x → x) _ _ ap : ∀ {a b} {A : Set a} {B : Set b} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y ap f = J (λ x y _ → f x ≡ f y) (λ _ → refl) _ _ ap₂ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} {x x′ y y′} (f : A → B → C) (p : x ≡ x′) (q : y ≡ y′) → f x y ≡ f x′ y′ ap₂ f p q = ap (λ _ → f _ _) p · ap (f _) q apd : ∀ {a b} {A : Set a} {B : A → Set b} {x y : A} (f : ∀ a → B a) (p : x ≡ y) → tr B p (f x) ≡ f y apd {B = B} f = J (λ x y p → tr B p (f x) ≡ f y) (λ _ → refl) _ _ happly : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} → f ≡ g → ∀ x → f x ≡ g x happly p x = ap (λ f → f x) p
{ "alphanum_fraction": 0.3779677113, "avg_line_length": 26.325, "ext": "agda", "hexsha": "52ad02ddc85e80600e4f619e391d499ce986f5b7", "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/PathOperations.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/PathOperations.agda", "max_line_length": 68, "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/PathOperations.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 578, "size": 1053 }
a = b module M where private
{ "alphanum_fraction": 0.724137931, "avg_line_length": 14.5, "ext": "agda", "hexsha": "f0e6f2aa4ece3ea404160f3cf9061f056fa06119", "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/Issue4288.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/Issue4288.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/Issue4288.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": 8, "size": 29 }
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Rational where open import Cubical.HITs.Rational.Base public -- open import Cubical.HITs.Rational.Properties public
{ "alphanum_fraction": 0.7719298246, "avg_line_length": 24.4285714286, "ext": "agda", "hexsha": "4a5e17dcc95c39c065f9d631dc705d5b3b412cfc", "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": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/HITs/Rational.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "limemloh/cubical", "max_issues_repo_path": "Cubical/HITs/Rational.agda", "max_line_length": 54, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/HITs/Rational.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z", "max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z", "num_tokens": 44, "size": 171 }
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Implementation where module Data where module Empty where open import Light.Implementation.Data.Empty public module Either where open import Light.Implementation.Data.Either public module Natural where open import Light.Implementation.Data.Natural public module Unit where open import Light.Implementation.Data.Unit public module Integer where open import Light.Implementation.Data.Integer public module Boolean where open import Light.Implementation.Data.Boolean public module Product where open import Light.Implementation.Data.Product public module These where open import Light.Implementation.Data.These public module Relation where module Sets where open import Light.Implementation.Relation.Sets public module Boolean where open import Light.Implementation.Relation.Boolean public module Binary where module Equality where module Propositional where open import Light.Implementation.Relation.Binary.Equality.Propositional public module Decidable where open import Light.Implementation.Relation.Binary.Equality.Propositional.Decidable public module Decidable where open import Light.Implementation.Relation.Decidable public module Action where open import Light.Implementation.Action public
{ "alphanum_fraction": 0.7664587665, "avg_line_length": 55.5, "ext": "agda", "hexsha": "f54a6312cf371c0b7305edb872e0c9cf57ee164b", "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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "Zambonifofex/lightlib", "max_forks_repo_path": "Light/Implementation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "Zambonifofex/lightlib", "max_issues_repo_path": "Light/Implementation.agda", "max_line_length": 135, "max_stars_count": 1, "max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "zamfofex/lightlib", "max_stars_repo_path": "Light/Implementation.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z", "num_tokens": 249, "size": 1443 }
------------------------------------------------- -- Formalisation of the Z axioms of set theory. ------------------------------------------------- module sv20.assign2.SetTheory.ZAxioms where open import sv20.assign2.SetTheory.Logic infix 1 ∃ infix 5 _⊆_ _⊂_ infix 5 _∈_ _∉_ infix 4 _≡_ -- The universe of discourse (pure sets) and the membership -- relationship. (The letter 𝓢 is type by "\MCS") postulate 𝓢 : Set _∈_ : 𝓢 → 𝓢 → Set -- Existential quantifier data ∃ (A : 𝓢 → Set) : Set where _,_ : (t : 𝓢) → A t → ∃ A -- Sugar syntax for the existential quantifier. syntax ∃ (λ x → e) = ∃[ x ] e -- Existential projections. proj₁ : {A : 𝓢 → Set} → ∃ A → 𝓢 proj₁ (t , _) = t proj₂ : (A : 𝓢 → Set) → (foo : ∃ A) → A (proj₁ foo) proj₂ A (_ , Ax) = Ax -- Equivalence and non equivalence with some useful properties data _≡_ (x : 𝓢) : 𝓢 → Set where refl : x ≡ x _≢_ : 𝓢 → 𝓢 → Set x ≢ y = ¬ x ≡ y sym : (x y : 𝓢) → x ≡ y → y ≡ x sym x .x refl = refl cong : (f :  𝓢 → 𝓢) {x y : 𝓢} → x ≡ y → f x ≡ f y cong f refl = refl subs : (P : 𝓢 → Set) {x y : 𝓢} (p : x ≡ y) (h : P x) → P y subs P {x} {.x} refl h = h trans : {x y z : 𝓢} → x ≡ y → y ≡ z → x ≡ z trans refl refl = refl -- Property concerning bi-implication, needed in a proof. ⇔-p₂ : (z : 𝓢) → {A B C : Set} → A ⇔ (B ∧ C) → (C → B) → A ⇔ C ⇔-p₂ z (h₁ , h₂) h₃ = (λ a → ∧-proj₂ (h₁ a)) , (λ c → h₂ ((h₃ c) , c)) -- Definitions of subset and not-membership. _⊆_ : 𝓢 → 𝓢 → Set x ⊆ y = (t : 𝓢) → t ∈ x → t ∈ y _∉_ : 𝓢 → 𝓢 → Set x ∉ y = ¬ (x ∈ y) -- {-# ATP definition _∉_ #-} _⊂_ : 𝓢 → 𝓢 → Set x ⊂ y = x ⊆ y ∧ x ≢ y _⊂'_ : 𝓢 → 𝓢 → Set x ⊂' y = x ⊆ y ∧ ∃ (λ z → z ∈ y ∧ z ∉ x) ------------------------------------------- -- ZFC's axioms -- From (Suppes 1960, p. 56) -- ext (Extensionality) : If two sets have exactly the same members, -- they are equal. -- empt (Empty Set Axiom) : There is a set having no -- members. Allows us to define the empty set. -- pair (Pairing Axiom) : For any sets y and z, there is a set having -- as members just y and z. Allows to define a set which is just -- the pair of any two sets. -- pow (Power Set Axiom): For any x there is a set whose members are -- exactly the subsets of x. Allows us to define the power set -- operation. -- sub (Subset Axiom, or Specification Axiom): This axiom asserts the -- existence of a set B whose members are exactly those sets x in y -- such that they satisfy certain property. Allows us to define -- many operations like cartesian products and difference of sets. -- uni (Union Axiom) : For any set x, there exists a set A whose -- elements are exactly the members of x. Allows us to define the -- union of two sets. -- pem (Principle of the excluded middle) : To prove some things -- not valid in intuitionistic logic and valid in classical logic. Taken -- from the Standford Encyclopedia entry on Intuitionistic Logic. -- (https://plato.stanford.edu/entries/logic-intuitionistic/). -- The sum axioms allow us to define the union operation -- over a family of sets. postulate empt : ∃ (λ B → ∀ x → x ∉ B) ext : (x y : 𝓢) → ∀ {z} → z ∈ x ⇔ z ∈ y → x ≡ y union : (x y : 𝓢) → ∃ (λ B → {z : 𝓢} → z ∈ B ⇔ z ∈ x ∨ z ∈ y) pair : (x y : 𝓢) → ∃ (λ B → {z : 𝓢} → z ∈ B ⇔ (z ≡ x ∨ z ≡ y)) pow : (x : 𝓢) → ∃ (λ B → ∀ {y} → y ∈ B ⇔ y ⊆ x) sub : (A : 𝓢 → Set) → (y : 𝓢) → ∃ (λ B → {z : 𝓢} → (z ∈ B ⇔ (z ∈ y ∧ A z))) pem : (A : Set) → A ∨ ¬ A sum : (A : 𝓢) → ∃ (λ C → (x : 𝓢) → x ∈ C ⇔ ∃ (λ B → x ∈ B ∧ B ∈ A)) -- {-# ATP axioms empt ext union pair pow #-} -- sub not given to apia since it is an axiom schema and ATPs don't deal -- with that. -- pem isn't given either since ATP's use classical logic so it uses -- this principle by default. ∅ : 𝓢 ∅ = proj₁ empt -- {-# ATP definition ∅ #-} -- Axiom of regularity: Axiom that have two very intuitive consequences: -- ∀ A (A ∉ A) and ¬ ∀ A,B (A∈B ∧ B∈A). From Suppes, p. 56 (1960). postulate reg : (A : 𝓢) → A ≢ ∅ → ∃ (λ x → x ∈ A ∧ ∀ y → y ∈ x → y ∉ A) -- References -- -- Suppes, Patrick (1960). Axiomatic Set Theory. -- The University Series in Undergraduate Mathematics. -- D. Van Nostrand Company, inc. -- -- Enderton, Herbert B. (1977). Elements of Set Theory. -- Academic Press Inc.
{ "alphanum_fraction": 0.5610451306, "avg_line_length": 28.8356164384, "ext": "agda", "hexsha": "d8aa9eab10717168a24d8904973b37899e8b27be", "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/sv20/assign2/SetTheory/ZAxioms.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/sv20/assign2/SetTheory/ZAxioms.agda", "max_line_length": 78, "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/sv20/assign2/SetTheory/ZAxioms.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1612, "size": 4210 }
module Generic.Lib.Data.List where open import Data.List.Base hiding ([]) renaming (fromMaybe to maybeToList) public open List public open import Generic.Lib.Intro open import Generic.Lib.Equality.Propositional open import Generic.Lib.Decidable open import Generic.Lib.Category open import Generic.Lib.Data.Nat open import Generic.Lib.Data.Maybe open import Generic.Lib.Data.Sum open import Generic.Lib.Data.Product import Data.List.Categorical as List infix 4 _∈_ foldr₁ : ∀ {α} {A : Set α} -> (A -> A -> A) -> A -> List A -> A foldr₁ f z [] = z foldr₁ f z (x ∷ []) = x foldr₁ f z (x ∷ y ∷ xs) = f x (foldr₁ f z (y ∷ xs)) mapInd : ∀ {α β} {A : Set α} {B : Set β} -> (ℕ -> A -> B) -> List A -> List B mapInd f [] = [] mapInd f (x ∷ xs) = f 0 x ∷ mapInd (f ∘ suc) xs mapM : ∀ {α β} {A : Set α} {B : Set β} {M : Set β -> Set β} {{mMonad : RawMonad M}} -> (A -> M B) -> List A -> M (List B) mapM {{mMonad}} = List.TraversableM.mapM mMonad downFromTo : ℕ -> ℕ -> List ℕ downFromTo n m = map (m +_) (downFrom (n ∸ m)) Any : ∀ {α β} {A : Set α} -> (A -> Set β) -> List A -> Set β Any B [] = ⊥ Any B (x ∷ []) = B x Any B (x ∷ xs) = B x ⊎ Any B xs _∈_ : ∀ {α} {A : Set α} -> A -> List A -> Set x ∈ xs = Any (x ≡_) xs here : ∀ {α β} {A : Set α} {B : A -> Set β} {x} xs -> B x -> Any B (x ∷ xs) here [] y = y here (x ∷ xs) y = inj₁ y phere : ∀ {α} {A : Set α} {x : A} xs -> x ∈ x ∷ xs phere xs = here xs refl there : ∀ {α β} {A : Set α} {B : A -> Set β} {x} xs -> Any B xs -> Any B (x ∷ xs) there [] () there (x ∷ xs) a = inj₂ a mapAny : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : A -> Set γ} -> ∀ xs -> (∀ {x} -> B x -> C x) -> Any B xs -> Any C xs mapAny [] g () mapAny (x ∷ []) g y = g y mapAny (x ∷ x′ ∷ xs) g (inj₁ y) = inj₁ (g y) mapAny (x ∷ x′ ∷ xs) g (inj₂ r) = inj₂ (mapAny (x′ ∷ xs) g r) All : ∀ {α β} {A : Set α} -> (A -> Set β) -> List A -> Set β All B [] = ⊤ All B (x ∷ xs) = B x × All B xs allToList : ∀ {α β} {A : Set α} {B : Set β} {xs : List A} -> All (const B) xs -> List B allToList {xs = []} tt = [] allToList {xs = x ∷ xs} (y , ys) = y ∷ allToList ys allIn : ∀ {α β} {A : Set α} {B : A -> Set β} -> ∀ xs -> (∀ {x} -> x ∈ xs -> B x) -> All B xs allIn [] g = tt allIn (x ∷ xs) g = g (phere xs) , allIn xs (g ∘ there xs) mapAll : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : A -> Set γ} {xs : List A} -> (∀ {x} -> B x -> C x) -> All B xs -> All C xs mapAll {xs = []} g tt = tt mapAll {xs = x ∷ xs} g (y , ys) = g y , mapAll g ys unmap : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : Set γ} {xs : List A} -> (∀ {x} -> B x -> C) -> All B xs -> List C unmap g = allToList ∘ mapAll g mapAllInd : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : A -> Set γ} {xs} -> (∀ {x} -> ℕ -> B x -> C x) -> All B xs -> All C xs mapAllInd {xs = []} g tt = tt mapAllInd {xs = x ∷ xs} g (y , ys) = g 0 y , mapAllInd (g ∘ suc) ys traverseAll : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : A -> Set γ} {xs : List A} {F : Set γ -> Set γ} {{fFunctor : RawFunctor F}} {{fApplicative : RawApplicative F}} -> (∀ {x} -> B x -> F (C x)) -> All B xs -> F (All C xs) traverseAll {xs = []} g tt = pure tt traverseAll {xs = x ∷ xs} g (y , ys) = _,_ <$> g y <*> traverseAll g ys splitList : ∀ {α β} {A : Set α} {B : A -> Set β} -> List (Σ A B) -> Σ (List A) (All B) splitList [] = [] , tt splitList ((x , y) ∷ ps) = pmap (_∷_ x) (_,_ y) (splitList ps) lookupAllConst : ∀ {α β} {A : Set α} {B : Set β} {{bEq : Eq B}} {xs : List A} -> B -> All (const B) xs -> Maybe (∃ (_∈ xs)) lookupAllConst {xs = []} y tt = nothing lookupAllConst {xs = x ∷ xs} y (z , ys) = if y == z then just (_ , phere xs) else second (there xs) <$> lookupAllConst y ys
{ "alphanum_fraction": 0.4814237464, "avg_line_length": 37.3689320388, "ext": "agda", "hexsha": "ef6fe14c749923da92b8f5476e37948324a6da3c", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z", "max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z", "max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "turion/Generic", "max_forks_repo_path": "src/Generic/Lib/Data/List.agda", "max_issues_count": 9, "max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z", "max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "turion/Generic", "max_issues_repo_path": "src/Generic/Lib/Data/List.agda", "max_line_length": 100, "max_stars_count": 30, "max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "turion/Generic", "max_stars_repo_path": "src/Generic/Lib/Data/List.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z", "num_tokens": 1565, "size": 3849 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Optics.All open import LibraBFT.Prelude -- This module defines syntax and functionality modeling an RWST monad, -- which we use to define an implementation. -- TODO-2: this module is independent of any particular implementation -- and arguably belongs somewhere more general, such as next to Optics. module LibraBFT.Impl.Util.RWST (ℓ-State : Level) where ---------------- -- RWST Monad -- ---------------- -- 'Fake' RWST monad; fake in the sense -- we use the free monoid on the writer (aka. lists) -- instad of requiring it to be a monoid in a separate -- argument. RWST-Raw : Set → Set → Set ℓ-State → {ℓ-Result : Level} → Set ℓ-Result → Set (ℓ-State ℓ⊔ ℓ-Result) RWST-Raw Ev Wr St R = Ev → St → (R × St × List Wr) -- Wrap it in a type; prevents spurious evaluation and -- obliges us to 'run' the monad. data RWST (Ev Wr : Set) (St : Set ℓ-State) {ℓ-Result : Level} : Set ℓ-Result → Set (ℓ-State ℓ⊔ ℓ-Result) where rwst : ∀ {R : Set ℓ-Result} → RWST-Raw Ev Wr St {ℓ-Result} R → RWST Ev Wr St R private variable Ev Wr : Set ℓ-A ℓ-B : Level A : Set ℓ-A B : Set ℓ-B St : Set ℓ-State RWST-run : RWST Ev Wr St A → Ev → St → (A × St × List Wr) RWST-run (rwst f) = f RWST-bind : RWST Ev Wr St A → (A → RWST Ev Wr St B) → RWST Ev Wr St B RWST-bind x f = rwst (λ ev st → let (a , st' , wr₀) = RWST-run x ev st (b , st'' , wr₁) = RWST-run (f a) ev st' in b , st'' , wr₀ ++ wr₁) RWST-return : A → RWST Ev Wr St A RWST-return x = rwst (λ _ st → x , st , []) -- Functorial Functionality RWST-map : (A → B) → RWST Ev Wr St A → RWST Ev Wr St B RWST-map f x = rwst (λ ev st → let (a , st' , wr) = RWST-run x ev st in f a , st' , wr) -- Provided Functionality get : RWST Ev Wr St {ℓ-State} St get = rwst (λ _ st → st , st , []) gets : (St → A) → RWST Ev Wr St A gets f = RWST-bind get (RWST-return ∘ f) {- TODO-2: extend Lens to work with different levels and reinstate this Note that a preliminary exploration by @cwjnkins revealed this to be more painful than it's worth, at least until we have a compelling use case for St to be at a higher level. In the meantime, we have defined use and modify' specifically for our state type, which is in Set; see LibraBFT.Impl.Util.Util. use : Lens St A → RWST Ev Wr St A use f = RWST-bind get (RWST-return ∘ (_^∙ f)) -} modify : (St → St) → RWST Ev Wr St Unit modify f = rwst (λ _ st → unit , f st , []) {- TODO-2: extend Lens to work with different levels and reinstate this See comment above for use modify' : ∀ {A} → Lens St A → A → RWST Ev Wr St Unit modify' l val = modify λ x → x [ l := val ] syntax modify' l val = l ∙= val -} put : St → RWST Ev Wr St Unit put s = modify (λ _ → s) tell : List Wr → RWST Ev Wr St Unit tell wrs = rwst (λ _ st → unit , st , wrs) tell1 : Wr → RWST Ev Wr St Unit tell1 wr = tell (wr ∷ []) ask : RWST Ev Wr St Ev ask = rwst (λ ev st → (ev , st , [])) -- Easy to use do notation; i.e.; module RWST-do where infixl 1 _>>=_ _>>_ _>>=_ : RWST Ev Wr St A → (A → RWST Ev Wr St B) → RWST Ev Wr St B _>>=_ = RWST-bind _>>_ : RWST Ev Wr St A → RWST Ev Wr St B → RWST Ev Wr St B x >> y = x >>= λ _ → y return : A → RWST Ev Wr St A return = RWST-return pure : A → RWST Ev Wr St A pure = return infixr 4 _<$>_ _<$>_ : (A → B) → RWST Ev Wr St A → RWST Ev Wr St B _<$>_ = RWST-map private ex₀ : RWST ℕ Wr (Lift ℓ-State ℕ) ℕ ex₀ = do x₁ ← get x₂ ← ask return (lower x₁ + x₂) where open RWST-do -- Derived Functionality maybeMP : RWST Ev Wr St (Maybe A) → B → (A → RWST Ev Wr St B) → RWST Ev Wr St B maybeMP ma b f = do x ← ma case x of λ { (just r) → f r ; nothing → return b } where open RWST-do
{ "alphanum_fraction": 0.5916002896, "avg_line_length": 29.5928571429, "ext": "agda", "hexsha": "593702ff4b28b413f5850fa33ebfb3d45309f04f", "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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "cwjnkins/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Impl/Util/RWST.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "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": "cwjnkins/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Impl/Util/RWST.agda", "max_line_length": 112, "max_stars_count": null, "max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "cwjnkins/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Impl/Util/RWST.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1437, "size": 4143 }
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Irrelevance {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Typed open import Definition.LogicalRelation import Definition.LogicalRelation.Irrelevance as LR open import Definition.LogicalRelation.Substitution open import Tools.Product open import Tools.Unit import Tools.PropositionalEquality as PE -- Irrelevance of valid substitutions with different derivations of contexts irrelevanceSubst : ∀ {σ Γ Δ} ([Γ] [Γ]′ : ⊩ᵛ Γ) (⊢Δ ⊢Δ′ : ⊢ Δ) → Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ → Δ ⊩ˢ σ ∷ Γ / [Γ]′ / ⊢Δ′ irrelevanceSubst ε′ ε′ ⊢Δ ⊢Δ′ [σ] = tt irrelevanceSubst ([Γ] ∙′ [A]) ([Γ]′ ∙′ [A]′) ⊢Δ ⊢Δ′ ([tailσ] , [headσ]) = let [tailσ]′ = irrelevanceSubst [Γ] [Γ]′ ⊢Δ ⊢Δ′ [tailσ] in [tailσ]′ , LR.irrelevanceTerm (proj₁ ([A] ⊢Δ [tailσ])) (proj₁ ([A]′ ⊢Δ′ [tailσ]′)) [headσ] -- Irrelevance of valid substitutions with different contexts -- that are propositionally equal irrelevanceSubst′ : ∀ {σ Γ Δ Δ′} (eq : Δ PE.≡ Δ′) ([Γ] [Γ]′ : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′) → Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ → Δ′ ⊩ˢ σ ∷ Γ / [Γ]′ / ⊢Δ′ irrelevanceSubst′ PE.refl [Γ] [Γ]′ ⊢Δ ⊢Δ′ [σ] = irrelevanceSubst [Γ] [Γ]′ ⊢Δ ⊢Δ′ [σ] -- Irrelevance of valid substitution equality -- with different derivations of contexts irrelevanceSubstEq : ∀ {σ σ′ Γ Δ} ([Γ] [Γ]′ : ⊩ᵛ Γ) (⊢Δ ⊢Δ′ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ]′ : Δ ⊩ˢ σ ∷ Γ / [Γ]′ / ⊢Δ′) → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ]′ / ⊢Δ′ / [σ]′ irrelevanceSubstEq ε′ ε′ ⊢Δ ⊢Δ′ [σ] [σ]′ [σ≡σ′] = tt irrelevanceSubstEq ([Γ] ∙′ [A]) ([Γ]′ ∙′ [A]′) ⊢Δ ⊢Δ′ [σ] [σ]′ [σ≡σ′] = irrelevanceSubstEq [Γ] [Γ]′ ⊢Δ ⊢Δ′ (proj₁ [σ]) (proj₁ [σ]′) (proj₁ [σ≡σ′]) , LR.irrelevanceEqTerm (proj₁ ([A] ⊢Δ (proj₁ [σ]))) (proj₁ ([A]′ ⊢Δ′ (proj₁ [σ]′))) (proj₂ [σ≡σ′]) -- Irrelevance of valid types with different derivations of contexts irrelevance : ∀ {l A Γ} ([Γ] [Γ]′ : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ A / [Γ] → Γ ⊩ᵛ⟨ l ⟩ A / [Γ]′ irrelevance [Γ] [Γ]′ [A] ⊢Δ [σ] = let [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] in proj₁ ([A] ⊢Δ [σ]′) , λ [σ′] [σ≡σ′] → proj₂ ([A] ⊢Δ [σ]′) (irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ′]) (irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] [σ]′ [σ≡σ′]) open import Definition.LogicalRelation.Properties -- Irrelevance of valid types with different derivations of contexts -- with lifting of eqaul types irrelevanceLift : ∀ {l A F H Γ} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([H] : Γ ⊩ᵛ⟨ l ⟩ H / [Γ]) ([F≡H] : Γ ⊩ᵛ⟨ l ⟩ F ≡ H / [Γ] / [F]) → Γ ∙ F ⊩ᵛ⟨ l ⟩ A / (VPack _ _ (V∙ [Γ] [F])) → Γ ∙ H ⊩ᵛ⟨ l ⟩ A / (VPack _ _ (V∙ [Γ] [H])) irrelevanceLift [Γ] [F] [H] [F≡H] [A] ⊢Δ ([tailσ] , [headσ]) = let [σ]′ = [tailσ] , convTerm₂ (proj₁ ([F] ⊢Δ [tailσ])) (proj₁ ([H] ⊢Δ [tailσ])) ([F≡H] ⊢Δ [tailσ]) [headσ] in proj₁ ([A] ⊢Δ [σ]′) , (λ [σ′] x → let [σ′]′ = proj₁ [σ′] , convTerm₂ (proj₁ ([F] ⊢Δ (proj₁ [σ′]))) (proj₁ ([H] ⊢Δ (proj₁ [σ′]))) ([F≡H] ⊢Δ (proj₁ [σ′])) (proj₂ [σ′]) [tailσ′] = proj₁ [σ′] in proj₂ ([A] ⊢Δ [σ]′) [σ′]′ (proj₁ x , convEqTerm₂ (proj₁ ([F] ⊢Δ [tailσ])) (proj₁ ([H] ⊢Δ [tailσ])) ([F≡H] ⊢Δ [tailσ]) (proj₂ x))) -- Irrelevance of valid type equality with different derivations of -- contexts and types irrelevanceEq : ∀ {l l′ A B Γ} ([Γ] [Γ]′ : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([A]′ : Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ]′) → Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A] → Γ ⊩ᵛ⟨ l′ ⟩ A ≡ B / [Γ]′ / [A]′ irrelevanceEq [Γ] [Γ]′ [A] [A]′ [A≡B] ⊢Δ [σ] = let [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] in LR.irrelevanceEq (proj₁ ([A] ⊢Δ [σ]′)) (proj₁ ([A]′ ⊢Δ [σ])) ([A≡B] ⊢Δ [σ]′) -- Irrelevance of valid terms with different derivations of contexts and types irrelevanceTerm : ∀ {l l′ A t Γ} ([Γ] [Γ]′ : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([A]′ : Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ]′) → Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A] → Γ ⊩ᵛ⟨ l′ ⟩ t ∷ A / [Γ]′ / [A]′ irrelevanceTerm [Γ] [Γ]′ [A] [A]′ [t] ⊢Δ [σ]′ = let [σ] = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]′ [σA] = proj₁ ([A] ⊢Δ [σ]) [σA]′ = proj₁ ([A]′ ⊢Δ [σ]′) in LR.irrelevanceTerm [σA] [σA]′ (proj₁ ([t] ⊢Δ [σ])) , (λ [σ′] x → LR.irrelevanceEqTerm [σA] [σA]′ ((proj₂ ([t] ⊢Δ [σ])) (irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ′]) (irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]′ [σ] x))) -- Irrelevance of valid terms with different derivations of -- contexts and types which are propositionally equal irrelevanceTerm′ : ∀ {l l′ A A′ t Γ} (eq : A PE.≡ A′) ([Γ] [Γ]′ : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([A′] : Γ ⊩ᵛ⟨ l′ ⟩ A′ / [Γ]′) → Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A] → Γ ⊩ᵛ⟨ l′ ⟩ t ∷ A′ / [Γ]′ / [A′] irrelevanceTerm′ {A = A} {t = t} PE.refl [Γ] [Γ]′ [A] [A]′ [t] = irrelevanceTerm {A = A} {t = t} [Γ] [Γ]′ [A] [A]′ [t] -- Irrelevance of valid terms with different derivations of -- contexts and types with a lifting of equal types irrelevanceTermLift : ∀ {l A F H t Γ} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([H] : Γ ⊩ᵛ⟨ l ⟩ H / [Γ]) ([F≡H] : Γ ⊩ᵛ⟨ l ⟩ F ≡ H / [Γ] / [F]) ([A] : Γ ∙ F ⊩ᵛ⟨ l ⟩ A / (VPack _ _ (V∙ [Γ] [F]))) → Γ ∙ F ⊩ᵛ⟨ l ⟩ t ∷ A / (VPack _ _ (V∙ [Γ] [F])) / [A] → Γ ∙ H ⊩ᵛ⟨ l ⟩ t ∷ A / (VPack _ _ (V∙ [Γ] [H])) / irrelevanceLift {A = A} {F = F} {H = H} [Γ] [F] [H] [F≡H] [A] irrelevanceTermLift [Γ] [F] [H] [F≡H] [A] [t] ⊢Δ ([tailσ] , [headσ]) = let [σ]′ = [tailσ] , convTerm₂ (proj₁ ([F] ⊢Δ [tailσ])) (proj₁ ([H] ⊢Δ [tailσ])) ([F≡H] ⊢Δ [tailσ]) [headσ] in proj₁ ([t] ⊢Δ [σ]′) , (λ [σ′] x → let [σ′]′ = proj₁ [σ′] , convTerm₂ (proj₁ ([F] ⊢Δ (proj₁ [σ′]))) (proj₁ ([H] ⊢Δ (proj₁ [σ′]))) ([F≡H] ⊢Δ (proj₁ [σ′])) (proj₂ [σ′]) [tailσ′] = proj₁ [σ′] in proj₂ ([t] ⊢Δ [σ]′) [σ′]′ (proj₁ x , convEqTerm₂ (proj₁ ([F] ⊢Δ [tailσ])) (proj₁ ([H] ⊢Δ [tailσ])) ([F≡H] ⊢Δ [tailσ]) (proj₂ x))) -- Irrelevance of valid term equality with different derivations of -- contexts and types irrelevanceEqTerm : ∀ {l l′ A t u Γ} ([Γ] [Γ]′ : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([A]′ : Γ ⊩ᵛ⟨ l′ ⟩ A / [Γ]′) → Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A] → Γ ⊩ᵛ⟨ l′ ⟩ t ≡ u ∷ A / [Γ]′ / [A]′ irrelevanceEqTerm {A = A} {t = t} {u = u} [Γ] [Γ]′ [A] [A]′ [t≡u] ⊢Δ [σ] = let [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] in LR.irrelevanceEqTerm (proj₁ ([A] ⊢Δ [σ]′)) (proj₁ ([A]′ ⊢Δ [σ])) ([t≡u] ⊢Δ [σ]′)
{ "alphanum_fraction": 0.3831649002, "avg_line_length": 44.097826087, "ext": "agda", "hexsha": "a33526d2072c1d66d2a746b46985c057f735e986", "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/Substitution/Irrelevance.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/Substitution/Irrelevance.agda", "max_line_length": 85, "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/Substitution/Irrelevance.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3519, "size": 8114 }
module Array.Base where open import Data.Nat open import Data.Nat.DivMod --using (_div_ ; _mod_; _/_; m/n*n≤m) open import Data.Nat.Divisibility open import Data.Nat.Properties open import Data.Vec open import Data.Vec.Properties using (lookup∘tabulate) open import Data.Fin.Base hiding (_<_; _+_) open import Data.Fin.Properties hiding (_≟_; <-cmp; ≤-trans; <-trans) open import Function using (_$_; _∘_; case_of_) open import Data.Product using (Σ; _,_) open import Relation.Binary.PropositionalEquality --using (_≡_; _≢_; refl; subst; sym; cong; cong₂) open import Relation.Binary open import Relation.Binary.Core open import Relation.Nullary --using (Dec; yes; no) open import Relation.Nullary.Decidable --using (fromWitnessFalse; False) open import Relation.Nullary.Negation --using (contradiction) open import Data.Sum using (inj₁; inj₂) open import Data.Empty infixr 5 _∷_ data Ix : (d : ℕ) → (s : Vec ℕ d) → Set where [] : Ix 0 [] _∷_ : ∀ {d s x} → Fin x → (ix : Ix d s) → Ix (suc d) (x ∷ s) ix-lookup : ∀ {d s} → Ix d s → (i : Fin d) → Fin (lookup s i) ix-lookup [] () ix-lookup (x ∷ ix) zero = x ix-lookup (x ∷ ix) (suc i) = ix-lookup ix i ix-tabulate : ∀ {d s} → ((i : Fin d) → Fin (lookup s i)) → Ix d s ix-tabulate {s = []} f = [] ix-tabulate {s = x ∷ s} f = f zero ∷ ix-tabulate (f ∘ suc) ix→v : ∀ {d s} → Ix d s → Vec ℕ d ix→v [] = [] ix→v (x ∷ xs) = toℕ x ∷ ix→v xs --data Ar {a} (X : Set a) (d : ℕ) (s : Vec ℕ d) : Set a where -- imap : (Ix d s → X) → Ar X d s -- -- We used this type before `withReconstructed` was introduced, so that -- we could obtain the shape of arrays at each imap. Now we have switched -- to the record that gives us η-equality. -- --data Ar {a} (X : Set a) (d : ℕ) : (Vec ℕ d) → Set a where -- imap : ∀ {s} → (Ix d s → X) → Ar X d s record Ar {a} (X : Set a) (d : ℕ) (s : Vec ℕ d) : Set a where constructor imap field sel : Ix d s → X open Ar public unimap : ∀ {a}{X : Set a}{d s} → Ar X d s → Ix d s → X unimap (imap x) = x cst : ∀ {a}{X : Set a}{d s} → X → Ar X d s cst x = imap λ _ → x -- Promoting shapes into 1-dimensional array of integers -- and back. s→a : ∀ {n} → Vec ℕ n → Ar ℕ 1 (n ∷ []) s→a s = imap (λ iv → lookup s $ ix-lookup iv zero ) a→s : ∀ {s} → Ar ℕ 1 (s ∷ []) → Vec ℕ s a→s (imap x) = tabulate λ i → x (i ∷ []) -- Here we define < on shape-like objects and demonstrate that -- this relation is decideable. _<s_ : ∀ {n} → Vec ℕ n → Vec ℕ n → Set a <s b = ∀ i → lookup a i < lookup b i -- XXX This might be just equality _=s_ : ∀ {n} → Vec ℕ n → Vec ℕ n → Set a =s b = ∀ i → lookup a i ≡ lookup b i _<a_ : ∀ {d s} → Ar ℕ d s → Ar ℕ d s → Set imap f <a imap g = ∀ iv → f iv < g iv _≥a_ : ∀ {d s} → Ar ℕ d s → Ar ℕ d s → Set imap f ≥a imap g = ∀ iv → f iv ≥ g iv _=a_ : ∀ {a}{X : Set a}{d s} → Ar X d s → Ar X d s → Set a imap f =a imap g = ∀ iv → f iv ≡ g iv _=ix_ : ∀ {d s} → Ix d s → Ix d s → Set iv =ix jv = ∀ i → ix-lookup iv i ≡ ix-lookup jv i subst-ix : ∀ {n}{s s₁ : Vec ℕ n} → s =s s₁ → Ix n s → Ix n s₁ subst-ix {zero} {[]} {[]} pf [] = [] subst-ix {suc n} {x ∷ xs} {y ∷ ys} pf (i ∷ iv) rewrite (pf zero) = i ∷ subst-ix (pf ∘ suc) iv subst-ar : ∀ {a}{X : Set a}{n}{s s₁ : Vec ℕ n} → s =s s₁ → Ar X n s → Ar X n s₁ subst-ar pf (imap f) = imap λ iv → f $ subst-ix (sym ∘ pf) iv subst-ar-d : ∀ {a}{X : Set a}{n m}{s : Vec ℕ n}{s₁ : Vec ℕ m} → (n=m : n ≡ m) → s =s (subst (Vec ℕ) (sym n=m) s₁) → Ar X n s → Ar X m s₁ subst-ar-d refl pf a = subst-ar pf a -- If we have an index, produce a pair containing an array representation -- and the proof that the index is smaller than the shape. ix→a : ∀ {d}{s : Vec ℕ d} → (ix : Ix d s) → Σ (Ar ℕ 1 (d ∷ [])) λ ax → ax <a (s→a s) ix→a ix = imap (λ iv → toℕ $ ix-lookup ix (ix-lookup iv zero)) , λ iv → toℕ<n (ix-lookup ix (ix-lookup iv zero)) -- XXX we can do this via imap/lookup if we want to, so that it -- extracts to more efficient code. infixl 10 _ix++_ _ix++_ : ∀ {n m s s₁} → (iv : Ix n s) → (jv : Ix m s₁) → Ix (n + m) (s ++ s₁) _ix++_ {s = []} {s₁} iv jv = jv _ix++_ {s = s ∷ ss} {s₁} (i ∷ iv) jv = i ∷ iv ix++ jv nest : ∀ {a}{X : Set a}{n m s s₁} → Ar X (n + m) (s ++ s₁) → Ar (Ar X m s₁) n s nest (imap f) = imap (λ iv → imap (λ jv → f (iv ix++ jv))) -- Take and drop for indices take-ix-l : ∀ {n m} → (s : Vec ℕ n) (s₁ : Vec ℕ m) → Ix (n + m) (s ++ s₁) → Ix n s take-ix-l [] s₁ ix = [] take-ix-l (s ∷ ss) s₁ (x ∷ ix) = x ∷ take-ix-l ss s₁ ix take-ix-r : ∀ {n m} → (s : Vec ℕ n) (s₁ : Vec ℕ m) → Ix (n + m) (s ++ s₁) → Ix m s₁ take-ix-r [] s₁ ix = ix take-ix-r (x ∷ s) s₁ (x₁ ∷ ix) = take-ix-r s s₁ ix -- Flatten the first nesting of the Ar flatten : ∀ {a}{X : Set a}{n m}{s : Vec ℕ n}{s₁ : Vec ℕ m} → Ar (Ar X m s₁) n s → Ar X (n + m) (s ++ s₁) flatten (imap f) = imap λ iv → case f (take-ix-l _ _ iv) of λ where (imap g) → g (take-ix-r _ _ iv) prod : ∀ {n} → (Vec ℕ n) → ℕ prod s = foldr _ _*_ 1 s magic-fin : ∀ {a}{X : Set a} → Fin 0 → X magic-fin () a*b≢0⇒a≢0 : ∀ {a b} → a * b ≢ 0 → a ≢ 0 a*b≢0⇒a≢0 {zero} {b} 0≢0 0≡0 = 0≢0 0≡0 a*b≢0⇒a≢0 {(suc a)} {b} _ = λ () a*b≢0⇒b≢0 : ∀ {a b} → a * b ≢ 0 → b ≢ 0 a*b≢0⇒b≢0 {a} {b} rewrite (*-comm a b) = a*b≢0⇒a≢0 -- A basic fact about division that is not yet in the stdlib. /-mono-x : ∀ {a b c} → a < b * c → (c≢0 : False (c ≟ 0)) → (a / c) {≢0 = c≢0} < b /-mono-x {a}{b}{c} a<b*c c≢0 with <-cmp ((a / c) {≢0 = c≢0}) b /-mono-x {a} {b} {c} a<b*c c≢0 | tri< l< _ _ = l< /-mono-x {a} {b} {c} a<b*c c≢0 | tri≈ _ l≡ _ = let a<a/c*c = subst (a <_) (cong₂ _*_ (sym l≡) refl) a<b*c a/c*c≤a = m/n*n≤m a c {≢0 = c≢0} a<a = ≤-trans a<a/c*c a/c*c≤a in contradiction a<a (n≮n a) /-mono-x {a} {b} {suc c} a<b*c c≢0 | tri> _ _ l> = let b*c<a/c*c = *-monoˡ-< c l> a/c*c≤a = m/n*n≤m a (suc c) {≢0 = c≢0} b*c≤a = ≤-trans b*c<a/c*c a/c*c≤a a<a = <-trans a<b*c b*c≤a in contradiction a<a (n≮n a) /-mono-f : ∀ {a b c} → a < b * c → (b≢0 : False (b ≟ 0)) → (a / b) {≢0 = b≢0} < c /-mono-f {b = b}{c} a<b*c ≢0 rewrite *-comm b c = /-mono-x a<b*c ≢0 divmod-thm : ∀ {a b m n} → (n≢0 : n ≢ 0) → a ≡ (m % n) {≢0 = fromWitnessFalse n≢0} → b ≡ (m / n) {≢0 = fromWitnessFalse n≢0} * n → m ≡ a + b divmod-thm {n = zero} n≢0 _ _ = contradiction refl n≢0 divmod-thm {m = m}{n = suc n} n≢0 refl refl = m≡m%n+[m/n]*n m n -- XXX currently this is not efficient way to convert between indices and -- offsets, as we are doing it form left to right. Computing in reverse -- makes more sense. Something for later. off→idx : ∀ {n} → (sh : Vec ℕ n) → Ix 1 (prod sh ∷ []) → Ix n sh off→idx [] iv = [] off→idx (s ∷ sh) iv with prod (s ∷ sh) ≟ 0 off→idx (s ∷ sh) iv | yes p rewrite p = magic-fin $ ix-lookup iv zero off→idx (s ∷ sh) (off ∷ []) | no ¬p = let o = toℕ off tl = prod sh tl≢0 = fromWitnessFalse (a*b≢0⇒b≢0 {a = s} ¬p) in {- off / tl -} (fromℕ< (/-mono-x (toℕ<n off) tl≢0)) {- rec call -} ∷ (off→idx sh ((o mod tl) {tl≢0} ∷ [])) module test-oi where open import Data.Fin using (#_) test-oi₁ : off→idx (10 ∷ 5 ∷ []) (# 40 ∷ []) ≡ (# 8) ∷ (# 0) ∷ [] test-oi₁ = refl -- [x , y] < [a , b] ⇒ rowmaj [x , y] < a*b ⇒ x*b+y < a*b rm-thm : ∀ {a b} → (x : Fin a) → (b ≢ 0) → (y : Fin b) → ((toℕ y) + (toℕ x) * b < (a * b)) rm-thm {a} {ℕ.zero} x pf y = contradiction (refl {x = 0}) pf rm-thm {ℕ.zero} {ℕ.suc b₁} () pf y rm-thm {ℕ.suc a₁} {ℕ.suc b₁} x pf y = +-mono-≤ (toℕ<n y) $ *-monoˡ-≤ (ℕ.suc b₁) (≤-pred $ toℕ<n x) v-rm-thm : ∀ {a b x y b≢0} → (toℕ $ fromℕ< (rm-thm {a = a} {b = b} x b≢0 y)) ≡ (toℕ y) + (toℕ x) * b v-rm-thm {suc a} {suc b} {x} {y} {≢0} = toℕ-fromℕ< (rm-thm x ≢0 y) Πs≡0⇒Fin0 : ∀ {n} → (s : Vec ℕ n) → (Ix n s) → (prod s ≡ 0) → Fin 0 Πs≡0⇒Fin0 (x ∷ s) (i ∷ iv) Πxs≡0 with m*n≡0⇒m≡0∨n≡0 x Πxs≡0 Πs≡0⇒Fin0 (x ∷ s) (i ∷ iv) Πxs≡0 | inj₁ x≡0 rewrite x≡0 = i Πs≡0⇒Fin0 (x ∷ s) (i ∷ iv) Πxs≡0 | inj₂ Πs≡0 = Πs≡0⇒Fin0 s iv Πs≡0 idx→off : ∀ {n} → (s : Vec ℕ n) → (iv : Ix n s) → Ix 1 (prod s ∷ []) idx→off [] iv = zero ∷ iv idx→off (s ∷ sh) (i ∷ iv) with prod (s ∷ sh) ≟ 0 idx→off (s ∷ sh) (i ∷ iv) | yes p rewrite p = magic-fin $ Πs≡0⇒Fin0 (s ∷ sh) (i ∷ iv) p idx→off (s ∷ sh) (i ∷ iv) | no ¬p = fromℕ< (rm-thm i (a*b≢0⇒b≢0 {a = s} ¬p) (ix-lookup (idx→off sh iv) zero)) ∷ [] module test-io where open import Data.Fin using (#_) test-io₁ : idx→off (10 ∷ 5 ∷ []) (# 8 ∷ # 0 ∷ []) ≡ # 40 ∷ [] test-io₁ = refl mkempty : ∀ {a}{X : Set a}{n} → (s : Vec ℕ n) → (prod s ≡ 0) → Ar X n s mkempty {X = X} {n = n} s Πs≡0 = imap empty where empty : _ empty iv = magic-fin $ Πs≡0⇒Fin0 s iv Πs≡0 -- Fin fact: Fin1≡0 : (x : Fin 1) → x ≡ zero Fin1≡0 zero = refl -- XXX This should be moved to Properties io-oi : ∀ {n}{x : Vec _ n}{i : Fin (prod x)} → idx→off x (off→idx x (i ∷ [])) ≡ i ∷ [] io-oi {zero} {[]}{i} = cong (_∷ []) (sym (Fin1≡0 i)) io-oi {suc n} {x ∷ x₁}{i} with prod (x ∷ x₁) ≟ 0 ... | yes p = ⊥-elim $ ¬Fin0 (subst Fin p i) ... | no ¬p with prod (x ∷ x₁) ≟ 0 io-oi {suc n} {x ∷ x₁} {i} | no ¬p | yes q = contradiction q ¬p io-oi {suc n} {x ∷ x₁} {i} | no ¬p | no ¬q = cong (_∷ []) (toℕ-injective (trans (v-rm-thm {a = x} {b = prod x₁}) (sym (divmod-thm {a = toℕ (ix-lookup (idx→off x₁ (off→idx x₁ _)) zero)} (a*b≢0⇒b≢0 {a = x} ¬p) (trans (cong (λ x → toℕ (ix-lookup x zero)) (io-oi {x = x₁})) mod⇒%) (mono⇒/* {b = x} {c = prod x₁}))))) where mono⇒/* : ∀ {b c}{i : Fin (b * c)}{≢0 : False (c ≟ 0)} → toℕ {n = b} (fromℕ< (/-mono-x (toℕ<n i) (≢0))) * c ≡ (toℕ i / c) {≢0} * c mono⇒/* {b} {c} {i} {≢0} = cong (_* c) (toℕ-fromℕ< (/-mono-x (toℕ<n i) ≢0)) mod⇒% : ∀ {n}{i : Fin n}{a}{≢0 : False (a ≟ 0)} → toℕ ((toℕ i mod a){≢0}) ≡ (toℕ i % a) {≢0} mod⇒% {n} {i} {suc a} = trans (toℕ-fromℕ< (m%n<n (toℕ i) a)) refl m≡m+x⇒0≡x : ∀ {m x} → m ≡ m + x → 0 ≡ x m≡m+x⇒0≡x {m}{x} m≡m+x = +-cancelˡ-≡ m (trans (+-identityʳ m) m≡m+x) a*b≡0⇒b≢0⇒a≡0 : ∀ {a b} → a * b ≡ 0 → b ≢ 0 → a ≡ 0 a*b≡0⇒b≢0⇒a≡0 {a}{b} a*b≡0 b≢0 with (m*n≡0⇒m≡0∨n≡0 a a*b≡0) a*b≡0⇒b≢0⇒a≡0 {a} {b} a*b≡0 b≢0 | inj₁ x = x a*b≡0⇒b≢0⇒a≡0 {a} {b} a*b≡0 b≢0 | inj₂ y = contradiction y b≢0 -- m≤n⇒m%n≡m m<n⇒m/n≡0 : ∀ {m n} → (m<n : m < n) → ∀ {≢0} → (m / n) {≢0} ≡ 0 m<n⇒m/n≡0 {m} {n@(suc n-1)} m<n = let m%n≡m = m≤n⇒m%n≡m (≤-pred m<n) m≡m%n+m/n*n = (m≡m%n+[m/n]*n m n-1) m≡m+m/n*n = trans m≡m%n+m/n*n (cong₂ _+_ m%n≡m refl) m/n*n≡0 = sym (m≡m+x⇒0≡x m≡m+m/n*n) m/n≡0 = a*b≡0⇒b≢0⇒a≡0 {a = m / n} {b = n} m/n*n≡0 (m<n⇒n≢0 m<n) in m/n≡0 b≡0+c≡a⇒b+c≡a : ∀ {a b c} → b ≡ 0 → c ≡ a → b + c ≡ a b≡0+c≡a⇒b+c≡a refl refl = refl a<c⇒c|b⇒[a+b]%c≡a : ∀ {a b c} → a < c → (c ∣ b) → ∀ {≢0} → ((a + b) % c) {≢0} ≡ a a<c⇒c|b⇒[a+b]%c≡a {a} {b} {c@(suc c-1)} a<c c|b = trans (%-remove-+ʳ a c|b) (m≤n⇒m%n≡m (≤-pred a<c)) a<c⇒c|b⇒[a+b]mod[c]≡a : ∀ {b c} → (a : Fin c) → (c ∣ b) → ∀ {≢0} → ((toℕ a + b) mod c) {≢0} ≡ a a<c⇒c|b⇒[a+b]mod[c]≡a {b} {suc c-1} a c|b {≢0} = toℕ-injective (trans (toℕ-fromℕ< _) (a<c⇒c|b⇒[a+b]%c≡a (toℕ<n a) c|b)) ixl-cong : ∀ {s}{i : Ix 1 (s ∷ [])} → (ix-lookup i zero) ∷ [] ≡ i ixl-cong {i = i ∷ []} = refl --rm-thm : ∀ {a b} → (x : Fin a) → (b ≢ 0) → (y : Fin b) → ((toℕ y) + (toℕ x) * b < (a * b)) --v-rm-thm : ∀ {a b x y b≢0} → (toℕ $ fromℕ< (rm-thm {a = a} {b = b} x b≢0 y)) ≡ (toℕ y) + (toℕ x) * b oi-io : ∀ {n}{x : Vec _ n}{iv : Ix n x} → off→idx x (idx→off x iv) ≡ iv oi-io {x = []} {[]} = refl oi-io {x = x ∷ xs} {i ∷ iv} with prod (x ∷ xs) ≟ 0 ... | yes p = ⊥-elim $ ¬Fin0 $ Πs≡0⇒Fin0 (x ∷ xs) (i ∷ iv) p ... | no ¬p = cong₂ _∷_ -- Πiv + i * Πxs (toℕ-injective (trans (toℕ-fromℕ< _) (trans (cong (_/ prod xs) (toℕ-fromℕ< _)) (hlpr {n = prod xs} {a = toℕ (ix-lookup (idx→off xs iv) zero)} refl (toℕ<n _))))) (trans (cong (off→idx xs) (trans (cong (λ x → x mod (prod xs) ∷ []) (toℕ-fromℕ< _)) (trans (cong (_∷ []) (a<c⇒c|b⇒[a+b]mod[c]≡a _ (n∣m*n (toℕ i) {n = (prod xs)}))) ixl-cong))) oi-io) where hlpr : ∀ {m n a x}{≢0} → a + m * n ≡ x → a < n → (x / n) {≢0} ≡ m hlpr {m} {n} {a} {x} {≢0} refl a<n = trans (+-distrib-/-∣ʳ {m = a} (m * n) {d = n} {≢0} (n∣m*n m)) (b≡0+c≡a⇒b+c≡a (m<n⇒m/n≡0 a<n) (m*n/n≡m m n)) -- rewrite (v-rm-thm {a = x} {b = prod xs} {x = i} {y = (ix-lookup (idx→off xs iv) zero)} {b≢0 = (a*b≢0⇒b≢0 {a = x} ¬p)})
{ "alphanum_fraction": 0.4453349018, "avg_line_length": 37.8857938719, "ext": "agda", "hexsha": "05e429399deb78938ce20b10c29c15cf8edc8de2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-10-12T07:19:48.000Z", "max_forks_repo_forks_event_min_datetime": "2020-10-12T07:19:48.000Z", "max_forks_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "ashinkarov/agda-array", "max_forks_repo_path": "Array/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "ashinkarov/agda-array", "max_issues_repo_path": "Array/Base.agda", "max_line_length": 121, "max_stars_count": 6, "max_stars_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "ashinkarov/agda-array", "max_stars_repo_path": "Array/Base.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-15T14:21:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-09T13:53:46.000Z", "num_tokens": 6243, "size": 13601 }
module Everything where import BoolMatcher import Eq import Prelude import RegExps import Setoids import SimpleMatcher
{ "alphanum_fraction": 0.8666666667, "avg_line_length": 13.3333333333, "ext": "agda", "hexsha": "df20ced28adf78f2f5e4d9e4cf1bc6599b729ed5", "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": "examples/AIM6/RegExp/talk/Everything.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": "examples/AIM6/RegExp/talk/Everything.agda", "max_line_length": 23, "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": "examples/AIM6/RegExp/talk/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 27, "size": 120 }
{-# OPTIONS --cubical --safe #-} module Data.Functor where open import Prelude record Functor ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where field F : Type ℓ₁ → Type ℓ₂ map : (A → B) → F A → F B identity : map {A = A} id ≡ id compose : (f : B → C) (g : A → B) → map (f ∘ g) ≡ map f ∘ map g
{ "alphanum_fraction": 0.5364238411, "avg_line_length": 21.5714285714, "ext": "agda", "hexsha": "8fc1e00eb789ea6a96f5d7ef28c34ab1e0d359fd", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Data/Functor.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Data/Functor.agda", "max_line_length": 67, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Data/Functor.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": 129, "size": 302 }
module GUIgeneric.GUI where open import GUIgeneric.Prelude open import GUIgeneric.GUIDefinitions Frame : Set Frame = ComponentEls frame logOn : Bool logOn = true log : {A : Set} → String → (f : Unit → IO GuiLev1Interface ∞ A) → IO GuiLev1Interface ∞ A log s f = if logOn then (do (putStrLn s) λ x → f x) else f unit module _ where FFIcomponents : {c : Component}(e : ComponentEls c) → Set FFIcomponents {c} (add i e e' _) = FFIcomponents e × FFIcomponents e' FFIcomponents {frame} (createC tt) = FFIFrame FFIcomponents {atomicComp} (createC (button x)) = FFIButton FFIcomponents {atomicComp} (createC (txtbox y)) = FFITextCtrl ffiComponentsToFrame : (e : ComponentEls frame)(ffi : FFIcomponents e) → FFIFrame ffiComponentsToFrame (createC x) ffi = ffi ffiComponentsToFrame (add c'c e e₁ _) (ffie , ffie₁) = ffiComponentsToFrame e₁ ffie₁ FFIcomponentsReduce : {c c' : Component}(e : ComponentEls c)(e' : ComponentEls c') (ee' : e <c e') (ff1 : FFIcomponents e') → FFIcomponents e FFIcomponentsReduce e (add i .e e'' _) (addsub i' .e .e'' _) ffi1 = proj₁ ffi1 FFIcomponentsReduce e (add i e' .e _) (addlift i' .e' .e _) ffi1 = proj₂ ffi1 FFIcomponentsReduce+ : {c c' : Component}(e : ComponentEls c)(e' : ComponentEls c') (ee' : e <=c+ e') (ffi : FFIcomponents e') → FFIcomponents e FFIcomponentsReduce+ e .e (in0= .e) ffi1 = ffi1 FFIcomponentsReduce+ e e' (in2= .e e'₁ .e' x ee') ffi1 = FFIcomponentsReduce e e'₁ x (FFIcomponentsReduce+ e'₁ e' ee' ffi1) data SemiDec (A : Frame → Set) : Set where isEmpty : ((f : Frame) → A f → ⊥) → SemiDec A posNonEmpty : SemiDec A data MethodsStruct : Set where fficom : MethodsStruct ⊥^ : MethodsStruct _⊎^_ : (m m' : MethodsStruct) → MethodsStruct _⊎^unoptimized_ : (m m' : MethodsStruct) → MethodsStruct mutual methodsStruct2Method : (g : Frame)(m : MethodsStruct) → Set methodsStruct2Method g fficom = FFIcomponents g methodsStruct2Method g ⊥^ = ⊥ methodsStruct2Method g (m ⊎^ m₁) = methodsStruct2Methodaux g m m₁ (methodsUnivIsEmpty m) (methodsUnivIsEmpty m₁) methodsStruct2Method g (m ⊎^unoptimized m₁) = methodsStruct2Method g m ⊎ methodsStruct2Method g m₁ methodsStruct2Methodaux : (g : Frame) (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m)) (s' : SemiDec (λ g → methodsStruct2Method g m')) → Set methodsStruct2Methodaux g m m' s (isEmpty s') = methodsStruct2Method g m methodsStruct2Methodaux g m m' (isEmpty x) posNonEmpty = methodsStruct2Method g m' methodsStruct2Methodaux g m m' posNonEmpty posNonEmpty = methodsStruct2Method g m ⊎ methodsStruct2Method g m' methodsUnivIsEmpty : (m : MethodsStruct) → SemiDec (λ g → methodsStruct2Method g m) methodsUnivIsEmpty fficom = posNonEmpty methodsUnivIsEmpty ⊥^ = isEmpty (λ g → λ ()) methodsUnivIsEmpty (m ⊎^ m₁) = methodsUnivIsEmptyaux m m₁ (methodsUnivIsEmpty m) (methodsUnivIsEmpty m₁) methodsUnivIsEmpty (m ⊎^unoptimized m₁) = posNonEmpty methodsUnivIsEmptyaux : (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m )) (s' : SemiDec (λ g → methodsStruct2Method g m' )) → SemiDec (λ g → methodsStruct2Methodaux g m m' s s') methodsUnivIsEmptyaux m m' s (isEmpty s') = s methodsUnivIsEmptyaux m m' (isEmpty x) posNonEmpty = posNonEmpty methodsUnivIsEmptyaux m m' posNonEmpty posNonEmpty = posNonEmpty inj₁MUaux : (g : Frame) (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m )) (s' : SemiDec (λ g → methodsStruct2Method g m' )) (u : methodsStruct2Method g m) → methodsStruct2Methodaux g m m' s s' inj₁MUaux g m m' s (isEmpty x) u = u inj₁MUaux g m m' (isEmpty x) posNonEmpty u = ⊥-elim (x g u) inj₁MUaux g m m' posNonEmpty posNonEmpty u = inj₁ u inj₁MUoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m )-- (isOpt : Bool) → methodsStruct2Method g (m ⊎^ m') --isOpt inj₁MUoptimized g m m' u = inj₁MUaux g m m' (methodsUnivIsEmpty m) (methodsUnivIsEmpty m') u inj₁MUUnoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m )-- (isOpt : Bool) → methodsStruct2Method g (m ⊎^unoptimized m') --isOpt inj₁MUUnoptimized g m m' u = inj₁ u inj₂MUaux : (g : Frame) (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m)) (s' : SemiDec (λ g → methodsStruct2Method g m' )) (u : methodsStruct2Method g m') → methodsStruct2Methodaux g m m' s s' inj₂MUaux g m m' s (isEmpty x) u = ⊥-elim (x g u) inj₂MUaux g m m' (isEmpty x) posNonEmpty u = u inj₂MUaux g m m' posNonEmpty posNonEmpty u = inj₂ u inj₂MUoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m' ) → methodsStruct2Method g (m ⊎^ m') --isOpt inj₂MUoptimized g m m' u = inj₂MUaux g m m' (methodsUnivIsEmpty m) (methodsUnivIsEmpty m') u inj₂MUUnoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m' ) → methodsStruct2Method g (m ⊎^unoptimized m') --isOpt inj₂MUUnoptimized g m m' u = inj₂ u methodStruct : {c : Component}(e : ComponentEls c) → MethodsStruct methodStruct (add c'c x x₁ optimized) = methodStruct x ⊎^ methodStruct x₁ methodStruct (add c'c x x₁ notOptimized) = methodStruct x ⊎^unoptimized methodStruct x₁ methodStruct {atomicComp} (createC (button s)) = fficom methodStruct {atomicComp} (createC (txtbox s)) = ⊥^ methodStruct _ = ⊥^ methods : {c : Component}(e : ComponentEls c)(g : Frame) → Set methods e g = methodsStruct2Method g (methodStruct e) methodsG : (g : Frame) → Set methodsG g = methods g g methodLift : {c c'' : Component}(e : ComponentEls c)(e'₁ : ComponentEls c'') (g : Frame) (x : e <c e'₁) (m : methods e g ) → methods e'₁ g methodLift e .(add i e e₁ optimized) g (addsub i .e e₁ optimized) m = inj₁MUoptimized g (methodStruct e) (methodStruct e₁) m methodLift e .(add i e e₁ notOptimzed) g (addsub i .e e₁ notOptimzed) m = inj₁MUUnoptimized g (methodStruct e) (methodStruct e₁) m methodLift e .(add i e'₂ e optimized) g (addlift i e'₂ .e optimized) m = inj₂MUoptimized g (methodStruct e'₂) (methodStruct e) m methodLift e .(add i e'₂ e notOptimzed) g (addlift i e'₂ .e notOptimzed) m = inj₂MUUnoptimized g (methodStruct e'₂) (methodStruct e) m methodLift+ : {c c' : Component}(e : ComponentEls c)(e' : ComponentEls c') (g : Frame)(ee' : e <=c+ e') (m : methods e g) → methods e' g methodLift+ e .e g (in0= .e) m = m methodLift+ e e' g (in2= .e e'₁ .e' x ee'') m = methodLift+ e'₁ e' g ee'' (methodLift e e'₁ g x m) data returnType (f : Frame) : Set where noChange : returnType f changedAttributes : properties f → returnType f changedGUI : (fNew : Frame) → (properties fNew) → returnType f nextStateFrame : (f : Frame)(r : returnType f) → Frame nextStateFrame f noChange = f nextStateFrame f (changedAttributes x) = f nextStateFrame f (changedGUI fNew x) = fNew handlerInterface : Interfaceˢ handlerInterface .Stateˢ = Frame handlerInterface .Methodˢ f = methodsG f handlerInterface .Resultˢ f m = returnType f handlerInterface .nextˢ f m r = nextStateFrame f r HandlerObject : ∀ i → Frame → Set HandlerObject i g = IOObjectˢ GuiLev1Interface handlerInterface i g StateAndGuiObj : Set StateAndGuiObj = Σ[ g ∈ Frame ] (properties g) × (HandlerObject ∞ g) StateAndFFIComp : Set StateAndFFIComp = Σ[ g ∈ Frame ] FFIcomponents g -- -- Step 3 : create object of type HandlerObject -- SingleMVar : {A : Set} → (mvar : MVar A) → VarList SingleMVar {A} mvar = addVar mvar [] initHandlerMVar : (l : VarList) (g : Frame) (a : properties g) (f : HandlerObject ∞ g) → IOˢ GuiLev2Interface ∞ (λ s → Σ[ mvar ∈ MVar StateAndGuiObj ] s ≡ addVar mvar l ) l initHandlerMVar l g a f = doˢ (createVar {_}{StateAndGuiObj} (g , a , f)) λ mvar → returnˢ (mvar , refl) initFFIMVar : (g : Frame) → (comp : (FFIcomponents g)) → IOˢ GuiLev2Interface ∞ (λ s → Σ[ mvar ∈ MVar StateAndFFIComp ] s ≡ SingleMVar mvar ) [] initFFIMVar g comp = doˢ (createVar {_}{StateAndFFIComp} (g , comp)) λ mvar → returnˢ (mvar , refl) module _ where frameToEnclosing : (e : ComponentEls frame)(ffi : FFIcomponents e) → FFIFrame frameToEnclosing (createC x) ffi = ffi frameToEnclosing (add i e e₁ _) (proj₃ , proj₄) = frameToEnclosing e₁ proj₄ componentToEnclosingIndex : (c : Component) → Set componentToEnclosingIndex frame = ⊥ componentToEnclosingIndex atomicComp = ⊤ componentToEnclosings : (c : Component)(i : componentToEnclosingIndex c) → Set componentToEnclosings frame () componentToEnclosings atomicComp tt = FFIFrame createComp : {c : Component}{s : GuiLev2State}(e : ComponentEls c) (enclosings : (i : componentToEnclosingIndex c) → componentToEnclosings c i) → (existingFrame : Maybe FFIFrame) → IOₚˢ GuiLev2Interface ∞ (FFIcomponents e) s s createComp {frame} (createC fr) enc (just ffiFrame) = returnˢ (refl , ffiFrame) createComp {frame} (createC fr) enc nothing = doˢ (level1C createWxFrame) λ frFFI → returnˢ (refl , frFFI) createComp {frame} (add buttonFrame e frameEl _) enc maybeFr = createComp frameEl enc maybeFr >>=ₚˢ λ frameComp → createComp e (λ x → frameToEnclosing frameEl frameComp) maybeFr >>=ₚˢ λ buttonComp → returnˢ (refl , buttonComp , frameComp) createComp {atomicComp} (createC (button x)) enc maybeFr = doˢ (level1C (createButton (enc tt) x)) λ bt → returnˢ (refl , bt) createComp {atomicComp} (createC (txtbox x)) enc maybeFr = doˢ (level1C (createTextCtrl (enc tt) x)) λ txt → returnˢ (refl , txt) createComp {atomicComp} (add () e e₁ _) x y createFrame : (g : Frame) → IOₚˢ GuiLev2Interface ∞ (FFIcomponents g) [] [] createFrame g = createComp {frame} g (λ x → ⊥-elim x) nothing reCreateFrame : {s : GuiLev2State}(g : Frame)(f : FFIFrame) → IOₚˢ GuiLev2Interface ∞ (FFIcomponents g) s s reCreateFrame g fr = createComp {frame} g (λ x → ⊥-elim x) (just fr) module _ where ButtonComp : Set ButtonComp = ComponentEls atomicComp button2Frame : (bt : ButtonComp)(g : Frame)(ffi : FFIcomponents g) (rel : bt <=c+ g) → FFIFrame button2Frame bt g ffi (in2= {c' = frame} .bt .(add c'c bt e _) .g (addsub c'c .bt e _) rel) = ffiComponentsToFrame e (FFIcomponentsReduce+ e g aux ffi) where aux : e <=c+ g aux = in2= e (add c'c bt e _) g (addlift c'c bt e _) rel button2Frame bt g ffi (in2= {c' = atomicComp} .bt .(add _ bt e _) .g (addsub () .bt e _) rel) button2Frame bt g ffi (in2= .bt .(add _ e'₁ bt _) .g (addlift {frame} () e'₁ .bt _) (in2= .(add _ e'₁ bt _) e' .g x rel)) button2Frame bt g ffi (in2= .bt .(add _ e'₁ bt _) .g (addlift {atomicComp} () e'₁ .bt _) (in2= .(add _ e'₁ bt _) e' .g x rel)) buttonHandleraux2 : ∀{i} → (bt : ButtonComp) (g : Frame) (ffi : FFIcomponents g) (rel : bt <=c+ g) (m : methods bt g) (a : properties g) (obj : HandlerObject ∞ g) (r : returnType g) (obj' : IOObjectˢ GuiLev1Interface handlerInterface ∞ (nextStateFrame g r)) → IO GuiLev1Interface i StateAndGuiObj buttonHandleraux2 bt g ffi rel m a obj noChange obj' = return (g , a , obj') buttonHandleraux2 bt g ffi rel m a obj (changedAttributes a') obj' = log "Changing Attributes Directly" λ _ → return (g , a' , obj') buttonHandleraux2 (createC x) g ffi rel m a obj (changedGUI gNew a') obj' = log "Firing GUI change ----> SEND FIRE" λ _ → do (fireCustomEvent (button2Frame (createC x) g ffi rel)) λ _ → return (gNew , a' , obj') buttonHandleraux2 (add () bt bt₁ _) g ffi rel m a obj (changedGUI gNew a') obj' buttonHandleraux : ∀{i} → (bt : ButtonComp) (g : Frame) (ffi : FFIcomponents g) (rel : bt <=c+ g) (m : methods bt g) (gNew : Frame) (a : properties gNew) (obj : HandlerObject ∞ gNew) (dec : Dec (g ≡ gNew)) → IO GuiLev1Interface i StateAndGuiObj buttonHandleraux bt g ffi rel m .g a obj (Dec.yes refl) = method obj (methodLift+ bt g g rel m) >>= λ { (r , obj') → buttonHandleraux2 bt g ffi rel m a obj r obj'} buttonHandleraux bt g ffi rel m gNew a obj (Dec.no ¬p) = log "ERROR: button handler is called for wrong GUI !!" λ _ → return (gNew , a , obj) buttonHandler : ∀{i} → (bt : ButtonComp) (g : Frame) (ffi : FFIcomponents g) (rel : bt <=c+ g) (m : methods bt g) (obj : StateAndGuiObj) → IO GuiLev1Interface i StateAndGuiObj buttonHandler {i} bt g ffi rel m (gNew , a , obj) = buttonHandleraux {i} bt g ffi rel m gNew a obj (g ≟Comp gNew) setHandler : ∀{i} → (c : Component) (cels : ComponentEls c) (g : Frame) (ffiComp : FFIcomponents g) (rel : cels <=c+ g) (mvar : MVar StateAndGuiObj) (restList : VarList) → IOˢ GuiLev2Interface i (λ s' → s' ≡ addVar mvar restList × Unit) (addVar mvar restList) setHandler .frame (add buttonFrame cels cels₁ _) g ffi rel mvar restList = setHandler frame cels₁ g ffi (in2= cels₁ (add buttonFrame cels cels₁ _) g (addlift buttonFrame cels cels₁ _) rel) mvar restList >>=ₚˢ λ r → setHandler atomicComp cels g ffi (in2= cels (add buttonFrame cels cels₁ _) g (addsub buttonFrame cels cels₁ _) rel) mvar restList >>=ₚˢ λ r → returnˢ (refl , _) setHandler frame (createC tt) g ffi rel mvar restList = returnˢ (refl , _) setHandler atomicComp (createC (button x)) g ffi (in2= .(createC (button x)) e' .g x₁ rel) mvar restList = doˢ (setButtonHandler (FFIcomponentsReduce (createC (button x)) e' x₁ (FFIcomponentsReduce+ e' g rel ffi) ) [ (λ obj → buttonHandler (createC (button x)) g ffi (in2= (createC (button x)) e' g x₁ rel) ffi (varListProj₁ restList obj) >>= (λ { (g' , obj') → return (varListUpdateProj₁ restList ( g' , obj') obj)}))]) λ _ → returnˢ (refl , _) setHandler atomicComp (createC (txtbox x)) g ffi (in2= .(createC (txtbox x)) e' .g x₁ rel) mvar restList = returnˢ (refl , _) setHandlerG : ∀{i} → (g : Frame) (ffiComp : FFIcomponents g) (mvar : MVar StateAndGuiObj) (restList : VarList) → IOˢ GuiLev2Interface i (λ s → s ≡ addVar mvar restList × Unit) (addVar mvar restList) setHandlerG g ffi mvar restList = setHandler frame g g ffi (in0= g) mvar restList deleteComp : {c : Component}{s : GuiLev2State}(e : ComponentEls c)(ffi : FFIcomponents e) → IOₚˢ GuiLev2Interface ∞ Unit s s deleteComp {frame} (createC fr) _ = returnˢ (refl , _) deleteComp {frame} (add x be frameEl _) (ffi , ffis) = deleteComp be ffi >>=ₚˢ λ _ → deleteComp frameEl ffis >>=ₚˢ λ r → returnˢ (refl , _) deleteComp {atomicComp} (createC (button x)) ffiButton = doˢ (level1C (deleteButton ffiButton)) λ _ → returnˢ (refl , _) deleteComp {atomicComp} (createC (txtbox y)) ffiTextCtrl = doˢ (level1C (deleteTextCtrl ffiTextCtrl)) λ _ → returnˢ (refl , _) deleteComp {atomicComp} (add () a b _) y setAttributes : {c : Component}(i : Size)(e : ComponentEls c)(a : properties e) (ffi : FFIcomponents e) → IO GuiLev1Interface i ⊤ setAttributes {frame} i (createC fr) (a , b , c , d) x = log " setting properties for Frame " λ _ → do (setChildredLayout x a b c d) λ _ → return tt setAttributes {frame} i (add x be frameEl _) (a , as) (ffi , ffis) = setAttributes i be a ffi >>= λ _ → setAttributes i frameEl as ffis >>= λ r → return tt setAttributes {atomicComp} i (createC (button x)) propColor ffiButton = do (setAttribButton ffiButton propColor) λ _ → return tt setAttributes {atomicComp} i (createC (txtbox y)) propColor ffiTextCtrl = do (setAttribTextCtrl ffiTextCtrl propColor) λ _ → return tt setAttributes {atomicComp} i (add () a b _) y z getFrameGen : (g : Frame)(cp : FFIcomponents g) → FFIFrame getFrameGen (createC x) cp = cp getFrameGen (add buttonFrame g g₁ _) (compg , compg₁) = getFrameGen g₁ compg₁
{ "alphanum_fraction": 0.572032979, "avg_line_length": 38.3284823285, "ext": "agda", "hexsha": "2134515e985218329e90de5fc7acff0c5da980ec", "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": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "stephanadls/state-dependent-gui", "max_forks_repo_path": "examples/GUIgeneric/GUI.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "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": "stephanadls/state-dependent-gui", "max_issues_repo_path": "examples/GUIgeneric/GUI.agda", "max_line_length": 153, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "stephanadls/state-dependent-gui", "max_stars_repo_path": "examples/GUIgeneric/GUI.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z", "num_tokens": 5663, "size": 18436 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Equational.Theory module Fragment.Equational.Model.Properties (Θ : Theory) where open import Fragment.Equational.Model.Base Θ open import Fragment.Equational.Model.Synthetic Θ open import Fragment.Algebra.Homomorphism (Σ Θ) open import Fragment.Algebra.Free (Σ Θ) open import Fragment.Setoid.Morphism using (_↝_) open import Level using (Level) open import Function using (_∘_) open import Data.Nat using (ℕ; zero; suc) open import Data.Fin using (Fin; zero; suc; fromℕ) open import Data.Vec using (Vec; []; _∷_; map) open import Data.Product using (proj₁; proj₂) open import Data.Vec.Relation.Binary.Pointwise.Inductive using (Pointwise; []; _∷_) open import Relation.Binary using (Setoid) import Relation.Binary.Reasoning.Setoid as Reasoning private variable a ℓ : Level module _ {n} (A : Model {a} {ℓ}) (θ : Env ∥ A ∥ₐ n) where private module S = Setoid ∥ A ∥/≈ open Reasoning ∥ A ∥/≈ mutual map-∣interp∣-cong : ∀ {m} {xs ys : Vec ∥ J n ∥ m} → Pointwise ≈[ J n ] xs ys → Pointwise ≈[ A ] (map ∣ inst ∥ A ∥ₐ θ ∣ xs) (map ∣ inst ∥ A ∥ₐ θ ∣ ys) map-∣interp∣-cong [] = [] map-∣interp∣-cong (p ∷ ps) = ∣interp∣-cong p ∷ map-∣interp∣-cong ps ∣interp∣-cong : Congruent ≈[ J n ] ≈[ A ] ∣ inst ∥ A ∥ₐ θ ∣ ∣interp∣-cong refl = S.refl ∣interp∣-cong (sym p) = S.sym (∣interp∣-cong p) ∣interp∣-cong (trans p q) = S.trans (∣interp∣-cong p) (∣interp∣-cong q) ∣interp∣-cong (inherit p) = ∣ inst ∥ A ∥ₐ θ ∣-cong p ∣interp∣-cong (cong f {xs = xs} {ys = ys} ps) = begin ∣ inst ∥ A ∥ₐ θ ∣ (term f xs) ≈⟨ S.sym (∣ inst ∥ A ∥ₐ θ ∣-hom f xs) ⟩ A ⟦ f ⟧ (map ∣ inst ∥ A ∥ₐ θ ∣ xs) ≈⟨ (A ⟦ f ⟧-cong) (map-∣interp∣-cong ps) ⟩ A ⟦ f ⟧ (map ∣ inst ∥ A ∥ₐ θ ∣ ys) ≈⟨ ∣ inst ∥ A ∥ₐ θ ∣-hom f ys ⟩ ∣ inst ∥ A ∥ₐ θ ∣ (term f ys) ∎ ∣interp∣-cong (axiom eq θ') = begin ∣ inst ∥ A ∥ₐ θ ∣ (∣ inst (F n) θ' ∣ lhs) ≈⟨ inst-assoc (F n) θ' (inst ∥ A ∥ₐ θ) {x = lhs} ⟩ ∣ inst ∥ A ∥ₐ (∣ inst ∥ A ∥ₐ θ ∣ ∘ θ') ∣ lhs ≈⟨ ∥ A ∥ₐ-models eq _ ⟩ ∣ inst ∥ A ∥ₐ (∣ inst ∥ A ∥ₐ θ ∣ ∘ θ') ∣ rhs ≈⟨ S.sym (inst-assoc (F n) θ' (inst ∥ A ∥ₐ θ) {x = rhs}) ⟩ ∣ inst ∥ A ∥ₐ θ ∣ (∣ inst (F n) θ' ∣ rhs) ∎ where lhs = proj₁ (Θ ⟦ eq ⟧ₑ) rhs = proj₂ (Θ ⟦ eq ⟧ₑ) ∣interp∣⃗ : ∥ J n ∥/≈ ↝ ∥ A ∥/≈ ∣interp∣⃗ = record { ∣_∣ = ∣ inst ∥ A ∥ₐ θ ∣ ; ∣_∣-cong = ∣interp∣-cong } interp : ∥ J n ∥ₐ ⟿ ∥ A ∥ₐ interp = record { ∣_∣⃗ = ∣interp∣⃗ ; ∣_∣-hom = ∣ inst ∥ A ∥ₐ θ ∣-hom } atomise : (n : ℕ) → ∥ J (suc n) ∥ atomise n = atom (dyn (fromℕ n)) up : ∀ {n} → Fin n → Fin (suc n) up zero = zero up (suc n) = suc (up n) raise : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J (suc n) ∥ₐ raise {n} = interp (J (suc n)) (λ k → atom (dyn (up k))) step : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J (suc n) ∥ₐ step {n} = interp (J (suc n)) (λ k → atom (dyn (suc k))) mutual map-step-raise : ∀ {n m} → (xs : Vec ∥ J n ∥ m) → Pointwise ≈[ J (suc (suc n)) ] (map ∣ step {suc n} ⊙ raise {n} ∣ xs) (map ∣ raise {suc n} ⊙ step {n} ∣ xs) map-step-raise [] = [] map-step-raise (x ∷ xs) = step-raise {x = x} ∷ map-step-raise xs step-raise : ∀ {n} → step {suc n} ⊙ raise {n} ≗ raise {suc n} ⊙ step {n} step-raise {n} {atom (dyn k)} = refl step-raise {n} {term f xs} = begin ∣ step ⊙ raise ∣ (term f xs) ≈⟨ sym (∣ step ⊙ raise ∣-hom f xs) ⟩ term f (map ∣ step ⊙ raise ∣ xs) ≈⟨ cong f (map-step-raise xs) ⟩ term f (map ∣ raise ⊙ step ∣ xs) ≈⟨ ∣ raise ⊙ step ∣-hom f xs ⟩ ∣ raise ⊙ step ∣ (term f xs) ∎ where open Reasoning ∥ J (suc (suc n)) ∥/≈
{ "alphanum_fraction": 0.4809654143, "avg_line_length": 34.947826087, "ext": "agda", "hexsha": "eee8ace0a25a52cb2d3738acb48c02a11f701d39", "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/Properties.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/Properties.agda", "max_line_length": 79, "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/Properties.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": 1749, "size": 4019 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT module groups.KernelCstImageCst {i j k} (G : Group i) (H : Group j) (K : Group k) (H-ab : is-abelian H) where private module H = Group H open import groups.KernelImage {G = G} {H = H} {K = K} cst-hom cst-hom H-ab Ker-cst-quot-Im-cst : Ker/Im ≃ᴳ H Ker-cst-quot-Im-cst = ≃-to-≃ᴳ (equiv to from to-from from-to) to-pres-comp where to : Ker/Im.El → H.El to = SetQuot-rec H.El-level to' to-rel where to' : Ker.El (cst-hom {G = H} {H = K}) → H.El to' ker = fst ker abstract to-rel : ∀ {h₁ h₂} → ker/im-rel' h₁ h₂ → h₁ == h₂ to-rel {h₁} {h₂} = Trunc-rec (H.El-level _ _) λ{(_ , 0=h₁h₂⁻¹) → H.zero-diff-same h₁ h₂ (! 0=h₁h₂⁻¹)} from : H.El → Ker/Im.El from h = q[ h , idp ] abstract to-from : ∀ h → to (from h) == h to-from h = idp from-to : ∀ k/i → from (to k/i) == k/i from-to = SetQuot-elim (λ _ → =-preserves-set SetQuot-level) (λ _ → ap q[_] $ ker-El=-out idp) (λ _ → prop-has-all-paths-↓ (SetQuot-level _ _)) to-pres-comp : preserves-comp Ker/Im.comp H.comp to to-pres-comp = SetQuot-elim (λ _ → Π-is-set λ _ → =-preserves-set H.El-level) (λ _ → SetQuot-elim (λ _ → =-preserves-set H.El-level) (λ _ → idp) (λ _ → prop-has-all-paths-↓ (H.El-level _ _))) (λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → H.El-level _ _))
{ "alphanum_fraction": 0.5320600273, "avg_line_length": 31.8695652174, "ext": "agda", "hexsha": "fd843779b3a31507c9ec0f429c2e052aa48ca580", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_path": "theorems/groups/KernelCstImageCst.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_path": "theorems/groups/KernelCstImageCst.agda", "max_line_length": 82, "max_stars_count": null, "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_path": "theorems/groups/KernelCstImageCst.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 558, "size": 1466 }
{-# OPTIONS --cubical --safe #-} module HITs.PropositionalTruncation.Equivalence where open import Prelude open import Relation.Binary open import HITs.PropositionalTruncation open import HITs.PropositionalTruncation.Sugar trunc-equivalence : ∀ {a} {A : Type a} → Equivalence A a → Equivalence A a trunc-equivalence e .Equivalence._≋_ x y = ∥ Equivalence._≋_ e x y ∥ trunc-equivalence e .Equivalence.sym = _∥$∥_ (Equivalence.sym e) trunc-equivalence e .Equivalence.refl = ∣ Equivalence.refl e ∣ trunc-equivalence e .Equivalence.trans xy yz = ⦇ (Equivalence.trans e) xy yz ⦈
{ "alphanum_fraction": 0.7590987868, "avg_line_length": 38.4666666667, "ext": "agda", "hexsha": "8c7d60839d0853d7fd62b6d9e854f91b4ebc8f56", "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": "HITs/PropositionalTruncation/Equivalence.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": "HITs/PropositionalTruncation/Equivalence.agda", "max_line_length": 78, "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": "HITs/PropositionalTruncation/Equivalence.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": 184, "size": 577 }
{- Computable stuff constructed from the Combinatorics of Finite Sets -} {-# OPTIONS --safe #-} module Cubical.Experiments.Combinatorics where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Data.Nat open import Cubical.Data.Nat.Order open import Cubical.Data.Bool open import Cubical.Data.Sum open import Cubical.Data.Sigma open import Cubical.Data.Vec open import Cubical.Data.SumFin renaming (Fin to Fin') open import Cubical.Data.FinSet.Base open import Cubical.Data.FinSet.Properties open import Cubical.Data.FinSet.Constructors open import Cubical.Data.FinSet.Cardinality open import Cubical.Data.FinSet.DecidablePredicate open import Cubical.Data.FinSet.Quotients open import Cubical.HITs.PropositionalTruncation open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidablePropositions hiding (DecProp) renaming (DecProp' to DecProp) open import Cubical.Relation.Binary open import Cubical.Functions.Embedding open import Cubical.Functions.Surjection private variable ℓ ℓ' ℓ'' : Level -- convenient renaming Fin : ℕ → FinSet ℓ-zero Fin n = _ , isFinSetFin {n = n} -- explicit numbers s2 : card (_ , isFinSet≃ (Fin 2) (Fin 2)) ≡ 2 s2 = refl s3 : card (_ , isFinSet≃ (Fin 3) (Fin 3)) ≡ 6 s3 = refl a3,2 : card (_ , isFinSet↪ (Fin 2) (Fin 3)) ≡ 6 a3,2 = refl 2^4 : card (_ , isFinSet→ (Fin 4) (Fin 2)) ≡ 16 2^4 = refl -- construct numerical functions from list getFun : {n : ℕ} → Vec ℕ n → Fin n .fst → ℕ getFun {n = n} ns = fun n ns where fun : (n : ℕ) → Vec ℕ n → Fin' n → ℕ fun 0 _ _ = 0 fun (suc m) (n ∷ ns) (inl tt) = n fun (suc m) (n ∷ ns) (inr x) = fun m ns x -- an example function f = getFun (3 ∷ 1 ∷ 4 ∷ 1 ∷ 5 ∷ 9 ∷ 2 ∷ 6 ∷ []) -- the total sum s : sum (Fin _) f ≡ 31 s = refl -- the total product p : prod (Fin _) f ≡ 6480 p = refl -- the maximal value m : maxValue (Fin _) f ∣ fzero ∣ ≡ 9 m = refl -- the number of numeral 1 n1 : card (_ , isFinSetFiberDisc (Fin _) ℕ discreteℕ f 1) ≡ 2 n1 = refl -- a somewhat trivial equivalence relation making everything equivalent R : {n : ℕ} → Fin n .fst → Fin n .fst → Type R _ _ = Unit isDecR : {n : ℕ} → (x y : Fin n .fst) → isDecProp (R {n = n} x y) isDecR _ _ = true , idEquiv _ open BinaryRelation open isEquivRel isEquivRelR : {n : ℕ} → isEquivRel (R {n = n}) isEquivRelR {n = n} .reflexive _ = tt isEquivRelR {n = n} .symmetric _ _ tt = tt isEquivRelR {n = n} .transitive _ _ _ tt tt = tt collapsed : (n : ℕ) → FinSet ℓ-zero collapsed n = _ , isFinSetQuot (Fin n) R isEquivRelR isDecR -- this number should be 1 ≡1 : card (collapsed 2) ≡ 1 ≡1 = refl
{ "alphanum_fraction": 0.6834532374, "avg_line_length": 24.0090909091, "ext": "agda", "hexsha": "ecf9ab7646bd4997dcc81ec2fd6b01f49dc86622", "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/Experiments/Combinatorics.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/Experiments/Combinatorics.agda", "max_line_length": 71, "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/Experiments/Combinatorics.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": 946, "size": 2641 }
{-# OPTIONS --type-in-type #-} module NoUniverseCheck where data M : Set -> Set where return : forall {a} -> a -> M a _>>=_ : forall {a b} -> M a -> (a -> M b) -> M b record Cat : Set where field Obj : Set Mor : Obj -> Obj -> Set data _≡_ {a : Set} (x : a) : a -> Set where refl : x ≡ x CatOfCat : Cat CatOfCat = record { Obj = Cat ; Mor = _≡_ }
{ "alphanum_fraction": 0.5186170213, "avg_line_length": 17.0909090909, "ext": "agda", "hexsha": "473f3156808b62bb24e03fd054cd6247d3c20af1", "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/NoUniverseCheck.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/NoUniverseCheck.agda", "max_line_length": 51, "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/NoUniverseCheck.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": 141, "size": 376 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of binary relations ------------------------------------------------------------------------ -- The contents of this module should be accessed via `Relation.Binary`. {-# OPTIONS --without-K --safe #-} module Relation.Binary.Definitions where open import Agda.Builtin.Equality using (_≡_) open import Data.Maybe.Base using (Maybe) open import Data.Product using (_×_) open import Data.Sum.Base using (_⊎_) open import Function.Base using (_on_; flip) open import Level open import Relation.Binary.Core open import Relation.Nullary using (Dec; ¬_) private variable a b c ℓ ℓ₁ ℓ₂ ℓ₃ : Level A : Set a B : Set b C : Set c ------------------------------------------------------------------------ -- Definitions ------------------------------------------------------------------------ -- Reflexivity - defined without an underlying equality. It could -- alternatively be defined as `_≈_ ⇒ _∼_` for some equality `_≈_`. -- Confusingly the convention in the library is to use the name "refl" -- for proofs of Reflexive and `reflexive` for proofs of type `_≈_ ⇒ _∼_`, -- e.g. in the definition of `IsEquivalence` later in this file. This -- convention is a legacy from the early days of the library. Reflexive : Rel A ℓ → Set _ Reflexive _∼_ = ∀ {x} → x ∼ x -- Generalised symmetry. Sym : REL A B ℓ₁ → REL B A ℓ₂ → Set _ Sym P Q = P ⇒ flip Q -- Symmetry. Symmetric : Rel A ℓ → Set _ Symmetric _∼_ = Sym _∼_ _∼_ -- Generalised transitivity. Trans : REL A B ℓ₁ → REL B C ℓ₂ → REL A C ℓ₃ → Set _ Trans P Q R = ∀ {i j k} → P i j → Q j k → R i k -- A flipped variant of generalised transitivity. TransFlip : REL A B ℓ₁ → REL B C ℓ₂ → REL A C ℓ₃ → Set _ TransFlip P Q R = ∀ {i j k} → Q j k → P i j → R i k -- Transitivity. Transitive : Rel A ℓ → Set _ Transitive _∼_ = Trans _∼_ _∼_ _∼_ -- Generalised antisymmetry Antisym : REL A B ℓ₁ → REL B A ℓ₂ → REL A B ℓ₃ → Set _ Antisym R S E = ∀ {i j} → R i j → S j i → E i j -- Antisymmetry. Antisymmetric : Rel A ℓ₁ → Rel A ℓ₂ → Set _ Antisymmetric _≈_ _≤_ = Antisym _≤_ _≤_ _≈_ -- Irreflexivity - this is defined terms of the underlying equality. Irreflexive : REL A B ℓ₁ → REL A B ℓ₂ → Set _ Irreflexive _≈_ _<_ = ∀ {x y} → x ≈ y → ¬ (x < y) -- Asymmetry. Asymmetric : Rel A ℓ → Set _ Asymmetric _<_ = ∀ {x y} → x < y → ¬ (y < x) -- Generalised connex - exactly one of the two relations holds. Connex : REL A B ℓ₁ → REL B A ℓ₂ → Set _ Connex P Q = ∀ x y → P x y ⊎ Q y x -- Totality. Total : Rel A ℓ → Set _ Total _∼_ = Connex _∼_ _∼_ -- Generalised trichotomy - exactly one of three types has a witness. data Tri (A : Set a) (B : Set b) (C : Set c) : Set (a ⊔ b ⊔ c) where tri< : ( a : A) (¬b : ¬ B) (¬c : ¬ C) → Tri A B C tri≈ : (¬a : ¬ A) ( b : B) (¬c : ¬ C) → Tri A B C tri> : (¬a : ¬ A) (¬b : ¬ B) ( c : C) → Tri A B C -- Trichotomy. Trichotomous : Rel A ℓ₁ → Rel A ℓ₂ → Set _ Trichotomous _≈_ _<_ = ∀ x y → Tri (x < y) (x ≈ y) (x > y) where _>_ = flip _<_ -- Generalised maximum element. Max : REL A B ℓ → B → Set _ Max _≤_ T = ∀ x → x ≤ T -- Maximum element. Maximum : Rel A ℓ → A → Set _ Maximum = Max -- Generalised minimum element. Min : REL A B ℓ → A → Set _ Min R = Max (flip R) -- Minimum element. Minimum : Rel A ℓ → A → Set _ Minimum = Min -- Unary relations respecting a binary relation. _⟶_Respects_ : (A → Set ℓ₁) → (B → Set ℓ₂) → REL A B ℓ₃ → Set _ P ⟶ Q Respects _∼_ = ∀ {x y} → x ∼ y → P x → Q y -- Unary relation respects a binary relation. _Respects_ : (A → Set ℓ₁) → Rel A ℓ₂ → Set _ P Respects _∼_ = P ⟶ P Respects _∼_ -- Right respecting - relatedness is preserved on the right by equality. _Respectsʳ_ : REL A B ℓ₁ → Rel B ℓ₂ → Set _ _∼_ Respectsʳ _≈_ = ∀ {x} → (x ∼_) Respects _≈_ -- Left respecting - relatedness is preserved on the left by equality. _Respectsˡ_ : REL A B ℓ₁ → Rel A ℓ₂ → Set _ P Respectsˡ _∼_ = ∀ {y} → (flip P y) Respects _∼_ -- Respecting - relatedness is preserved on both sides by equality _Respects₂_ : Rel A ℓ₁ → Rel A ℓ₂ → Set _ P Respects₂ _∼_ = (P Respectsʳ _∼_) × (P Respectsˡ _∼_) -- Substitutivity - any two related elements satisfy exactly the same -- set of unary relations. Note that only the various derivatives -- of propositional equality can satisfy this property. Substitutive : Rel A ℓ₁ → (ℓ₂ : Level) → Set _ Substitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_ -- Decidability - it is possible to determine whether a given pair of -- elements are related. Decidable : REL A B ℓ → Set _ Decidable _∼_ = ∀ x y → Dec (x ∼ y) -- Weak decidability - it is sometimes possible to determine if a given -- pair of elements are related. WeaklyDecidable : REL A B ℓ → Set _ WeaklyDecidable _∼_ = ∀ x y → Maybe (x ∼ y) -- Propositional equality is decidable for the type. DecidableEquality : (A : Set a) → Set _ DecidableEquality A = Decidable {A = A} _≡_ -- Irrelevancy - all proofs that a given pair of elements are related -- are indistinguishable. Irrelevant : REL A B ℓ → Set _ Irrelevant _∼_ = ∀ {x y} (a b : x ∼ y) → a ≡ b -- Recomputability - we can rebuild a relevant proof given an -- irrelevant one. Recomputable : REL A B ℓ → Set _ Recomputable _∼_ = ∀ {x y} → .(x ∼ y) → x ∼ y -- Universal - all pairs of elements are related Universal : REL A B ℓ → Set _ Universal _∼_ = ∀ x y → x ∼ y -- Non-emptiness - at least one pair of elements are related. record NonEmpty {A : Set a} {B : Set b} (T : REL A B ℓ) : Set (a ⊔ b ⊔ ℓ) where constructor nonEmpty field {x} : A {y} : B proof : T x y ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 1.1 Conn = Connex {-# WARNING_ON_USAGE Conn "Warning: Conn was deprecated in v1.1. Please use Connex instead." #-}
{ "alphanum_fraction": 0.592482199, "avg_line_length": 26.9598214286, "ext": "agda", "hexsha": "9c29757cba64b74015116dceb3e2e2067578fcd2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Definitions.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Definitions.agda", "max_line_length": 74, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Definitions.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": 1968, "size": 6039 }
open import Nat open import Prelude open import List open import contexts open import core open import lemmas-general open import lemmas-env open import lemmas-progress open import results-checks open import decidability open import completeness open import preservation open import progress open import finality open import eval-checks
{ "alphanum_fraction": 0.8441176471, "avg_line_length": 17.8947368421, "ext": "agda", "hexsha": "bbb41a618244eab4d14d3d7134a41a933c4a5499", "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": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnat-myth-", "max_forks_repo_path": "all.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c", "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": "hazelgrove/hazelnat-myth-", "max_issues_repo_path": "all.agda", "max_line_length": 27, "max_stars_count": 1, "max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnat-myth-", "max_stars_repo_path": "all.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z", "num_tokens": 72, "size": 340 }
-- Andreas, 2011-04-14 -- {-# OPTIONS -v tc.cover:20 -v tc.lhs.unify:20 #-} module Issue291b where open import Common.Coinduction open import Common.Equality data RUnit : Set where runit : ∞ RUnit -> RUnit j : (u : RUnit) -> u ≡ runit (♯ u) -> Set j u () -- needs to fail because of a non strongly rigid occurrence -- ♯ does not count as a constructor, and that is good!
{ "alphanum_fraction": 0.6710875332, "avg_line_length": 23.5625, "ext": "agda", "hexsha": "11b8178e3cce95467171e0fa9cac42655f18c857", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue291b.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/Fail/Issue291b.agda", "max_line_length": 59, "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/Fail/Issue291b.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": 121, "size": 377 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Natural numbers ------------------------------------------------------------------------ module Data.Nat where open import Function open import Function.Equality as F using (_⟨$⟩_) open import Function.Injection using (_↣_) open import Data.Sum open import Data.Empty import Level open import Relation.Nullary import Relation.Nullary.Decidable as Dec open import Relation.Binary open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl) ------------------------------------------------------------------------ -- The types data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} infix 4 _≤_ _<_ _≥_ _>_ _≰_ _≮_ _≱_ _≯_ data _≤_ : Rel ℕ Level.zero where z≤n : ∀ {n} → zero ≤ n s≤s : ∀ {m n} (m≤n : m ≤ n) → suc m ≤ suc n _<_ : Rel ℕ Level.zero m < n = suc m ≤ n _≥_ : Rel ℕ Level.zero m ≥ n = n ≤ m _>_ : Rel ℕ Level.zero m > n = n < m _≰_ : Rel ℕ Level.zero a ≰ b = ¬ a ≤ b _≮_ : Rel ℕ Level.zero a ≮ b = ¬ a < b _≱_ : Rel ℕ Level.zero a ≱ b = ¬ a ≥ b _≯_ : Rel ℕ Level.zero a ≯ b = ¬ a > b -- The following, alternative definition of _≤_ is more suitable for -- well-founded induction (see Induction.Nat). infix 4 _≤′_ _<′_ _≥′_ _>′_ data _≤′_ (m : ℕ) : ℕ → Set where ≤′-refl : m ≤′ m ≤′-step : ∀ {n} (m≤′n : m ≤′ n) → m ≤′ suc n _<′_ : Rel ℕ Level.zero m <′ n = suc m ≤′ n _≥′_ : Rel ℕ Level.zero m ≥′ n = n ≤′ m _>′_ : Rel ℕ Level.zero m >′ n = n <′ m ------------------------------------------------------------------------ -- A generalisation of the arithmetic operations fold : {a : Set} → a → (a → a) → ℕ → a fold z s zero = z fold z s (suc n) = s (fold z s n) module GeneralisedArithmetic {a : Set} (0# : a) (1+ : a → a) where add : ℕ → a → a add n z = fold z 1+ n mul : (+ : a → a → a) → (ℕ → a → a) mul _+_ n x = fold 0# (λ s → x + s) n ------------------------------------------------------------------------ -- Arithmetic pred : ℕ → ℕ pred zero = zero pred (suc n) = n infixl 7 _*_ _⊓_ infixl 6 _+_ _+⋎_ _∸_ _⊔_ _+_ : ℕ → ℕ → ℕ zero + n = n suc m + n = suc (m + n) {-# BUILTIN NATPLUS _+_ #-} -- Argument-swapping addition. Used by Data.Vec._⋎_. _+⋎_ : ℕ → ℕ → ℕ zero +⋎ n = n suc m +⋎ n = suc (n +⋎ m) _∸_ : ℕ → ℕ → ℕ m ∸ zero = m zero ∸ suc n = zero suc m ∸ suc n = m ∸ n {-# BUILTIN NATMINUS _∸_ #-} _*_ : ℕ → ℕ → ℕ zero * n = zero suc m * n = n + m * n {-# BUILTIN NATTIMES _*_ #-} -- Max. _⊔_ : ℕ → ℕ → ℕ zero ⊔ n = n suc m ⊔ zero = suc m suc m ⊔ suc n = suc (m ⊔ n) -- Min. _⊓_ : ℕ → ℕ → ℕ zero ⊓ n = zero suc m ⊓ zero = zero suc m ⊓ suc n = suc (m ⊓ n) -- Division by 2, rounded downwards. ⌊_/2⌋ : ℕ → ℕ ⌊ 0 /2⌋ = 0 ⌊ 1 /2⌋ = 0 ⌊ suc (suc n) /2⌋ = suc ⌊ n /2⌋ -- Division by 2, rounded upwards. ⌈_/2⌉ : ℕ → ℕ ⌈ n /2⌉ = ⌊ suc n /2⌋ ------------------------------------------------------------------------ -- Queries infix 4 _≟_ _≟_ : Decidable {A = ℕ} _≡_ zero ≟ zero = yes refl suc m ≟ suc n with m ≟ n suc m ≟ suc .m | yes refl = yes refl suc m ≟ suc n | no prf = no (prf ∘ PropEq.cong pred) zero ≟ suc n = no λ() suc m ≟ zero = no λ() ≤-pred : ∀ {m n} → suc m ≤ suc n → m ≤ n ≤-pred (s≤s m≤n) = m≤n _≤?_ : Decidable _≤_ zero ≤? _ = yes z≤n suc m ≤? zero = no λ() suc m ≤? suc n with m ≤? n ... | yes m≤n = yes (s≤s m≤n) ... | no m≰n = no (m≰n ∘ ≤-pred) -- A comparison view. Taken from "View from the left" -- (McBride/McKinna); details may differ. data Ordering : Rel ℕ Level.zero where less : ∀ m k → Ordering m (suc (m + k)) equal : ∀ m → Ordering m m greater : ∀ m k → Ordering (suc (m + k)) m compare : ∀ m n → Ordering m n compare zero zero = equal zero compare (suc m) zero = greater zero m compare zero (suc n) = less zero n compare (suc m) (suc n) with compare m n compare (suc .m) (suc .(suc m + k)) | less m k = less (suc m) k compare (suc .m) (suc .m) | equal m = equal (suc m) compare (suc .(suc m + k)) (suc .m) | greater m k = greater (suc m) k -- If there is an injection from a type to ℕ, then the type has -- decidable equality. eq? : ∀ {a} {A : Set a} → A ↣ ℕ → Decidable {A = A} _≡_ eq? inj = Dec.via-injection inj _≟_ ------------------------------------------------------------------------ -- Some properties decTotalOrder : DecTotalOrder _ _ _ decTotalOrder = record { Carrier = ℕ ; _≈_ = _≡_ ; _≤_ = _≤_ ; isDecTotalOrder = record { isTotalOrder = record { isPartialOrder = record { isPreorder = record { isEquivalence = PropEq.isEquivalence ; reflexive = refl′ ; trans = trans } ; antisym = antisym } ; total = total } ; _≟_ = _≟_ ; _≤?_ = _≤?_ } } where refl′ : _≡_ ⇒ _≤_ refl′ {zero} refl = z≤n refl′ {suc m} refl = s≤s (refl′ refl) antisym : Antisymmetric _≡_ _≤_ antisym z≤n z≤n = refl antisym (s≤s m≤n) (s≤s n≤m) with antisym m≤n n≤m ... | refl = refl trans : Transitive _≤_ trans z≤n _ = z≤n trans (s≤s m≤n) (s≤s n≤o) = s≤s (trans m≤n n≤o) total : Total _≤_ total zero _ = inj₁ z≤n total _ zero = inj₂ z≤n total (suc m) (suc n) with total m n ... | inj₁ m≤n = inj₁ (s≤s m≤n) ... | inj₂ n≤m = inj₂ (s≤s n≤m) import Relation.Binary.PartialOrderReasoning as POR module ≤-Reasoning where open POR (DecTotalOrder.poset decTotalOrder) public renaming (_≈⟨_⟩_ to _≡⟨_⟩_) infixr 2 _<⟨_⟩_ _<⟨_⟩_ : ∀ x {y z} → x < y → y IsRelatedTo z → suc x IsRelatedTo z x <⟨ x<y ⟩ y≤z = suc x ≤⟨ x<y ⟩ y≤z
{ "alphanum_fraction": 0.4705882353, "avg_line_length": 23.7051792829, "ext": "agda", "hexsha": "485f95b65f7b0c56711ff06c5264639535f69ef6", "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/Nat.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/Nat.agda", "max_line_length": 79, "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/Nat.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": 2265, "size": 5950 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Base open import lib.PathGroupoid open import lib.PathOver open import lib.cubical.Square module lib.cubical.SquareOver where SquareOver : ∀ {i j} {A : Type i} (B : A → Type j) {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} (sq : Square p₀₋ p₋₀ p₋₁ p₁₋) {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} (q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]) (q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]) (q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]) (q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]) → Type j SquareOver B ids = Square apd-square : ∀ {i j} {A : Type i} {B : A → Type j} (f : Π A B) {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} (sq : Square p₀₋ p₋₀ p₋₁ p₁₋) → SquareOver B sq (apd f p₀₋) (apd f p₋₀) (apd f p₋₁) (apd f p₁₋) apd-square f ids = ids ↓-=-to-squareover : ∀ {i j} {A : Type i} {B : A → Type j} {f g : Π A B} {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} → u == v [ (λ z → f z == g z) ↓ p ] → SquareOver B vid-square u (apd f p) (apd g p) v ↓-=-to-squareover {p = idp} idp = hid-square ↓-=-from-squareover : ∀ {i j} {A : Type i} {B : A → Type j} {f g : Π A B} {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} → SquareOver B vid-square u (apd f p) (apd g p) v → u == v [ (λ z → f z == g z) ↓ p ] ↓-=-from-squareover {p = idp} sq = horiz-degen-path sq squareover-cst-in : ∀ {i j} {A : Type i} {B : Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ b₀₁ b₁₀ b₁₁ : B} {q₀₋ : b₀₀ == b₀₁} {q₋₀ : b₀₀ == b₁₀} {q₋₁ : b₀₁ == b₁₁} {q₁₋ : b₁₀ == b₁₁} (sq' : Square q₀₋ q₋₀ q₋₁ q₁₋) → SquareOver (λ _ → B) sq (↓-cst-in q₀₋) (↓-cst-in q₋₀) (↓-cst-in q₋₁) (↓-cst-in q₁₋) squareover-cst-in {sq = ids} sq' = sq' ↓↓-from-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)} {p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂} {α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]} → SquareOver B (natural-square p q) α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β → α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ] ↓↓-from-squareover {q = idp} sq = lemma sq where lemma : ∀ {i j} {A : Type i} {B : A → Type j} {x y : A} {u : B x} {v : B y} {p : x == y} {α β : u == v [ B ↓ p ]} → SquareOver B hid-square α idp idp β → α == β lemma {p = idp} sq = horiz-degen-path sq ↓↓-to-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)} {p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂} {α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]} → α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ] → SquareOver B (natural-square p q) α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β ↓↓-to-squareover {q = idp} r = lemma r where lemma : ∀ {i j} {A : Type i} {B : A → Type j} {x y : A} {u : B x} {v : B y} {p : x == y} {α β : u == v [ B ↓ p ]} → α == β → SquareOver B hid-square α idp idp β lemma {p = idp} r = horiz-degen-square r infixr 80 _∙v↓⊡_ _∙h↓⊡_ _↓⊡v∙_ _↓⊡h∙_ _∙h↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ q₀₋' : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → q₀₋ == q₀₋' → SquareOver B sq q₀₋' q₋₀ q₋₁ q₁₋ → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ _∙h↓⊡_ {sq = ids} = _∙h⊡_ _∙v↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ q₋₀' : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → q₋₀ == q₋₀' → SquareOver B sq q₀₋ q₋₀' q₋₁ q₁₋ → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ _∙v↓⊡_ {sq = ids} = _∙v⊡_ _↓⊡v∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ q₋₁' : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ → q₋₁ == q₋₁' → SquareOver B sq q₀₋ q₋₀ q₋₁' q₁₋ _↓⊡v∙_ {sq = ids} = _⊡v∙_ _↓⊡h∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ q₁₋' : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ → q₁₋ == q₁₋' → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋' _↓⊡h∙_ {sq = ids} = _⊡h∙_
{ "alphanum_fraction": 0.447519084, "avg_line_length": 41.2598425197, "ext": "agda", "hexsha": "439d235139ea839162478e6c8b49e6e37412370a", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_path": "core/lib/cubical/SquareOver.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_path": "core/lib/cubical/SquareOver.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_path": "core/lib/cubical/SquareOver.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3067, "size": 5240 }
module Star where data Star {A : Set}(R : A -> A -> Set) : A -> A -> Set where rf : {x : A} -> Star R x x _<>_ : forall {x y z} -> R x y -> Star R y z -> Star R x z
{ "alphanum_fraction": 0.4739884393, "avg_line_length": 24.7142857143, "ext": "agda", "hexsha": "da80e15d57293e4ab0d40fd0b240c591aa674e8e", "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": "examples/outdated-and-incorrect/cbs/Star.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": "examples/outdated-and-incorrect/cbs/Star.agda", "max_line_length": 60, "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": "examples/outdated-and-incorrect/cbs/Star.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": 69, "size": 173 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Base open import lib.Function open import lib.PathFunctor open import lib.PathGroupoid open import lib.path-seq.Concat module lib.path-seq.Split {i} {A : Type i} where point-from-start : (n : ℕ) {a a' : A} (s : a =-= a') → A point-from-start O {a} s = a point-from-start (S n) {a = a} [] = a point-from-start (S n) (p ◃∙ s) = point-from-start n s drop : (n : ℕ) {a a' : A} (s : a =-= a') → point-from-start n s =-= a' drop 0 s = s drop (S n) [] = [] drop (S n) (p ◃∙ s) = drop n s tail : {a a' : A} (s : a =-= a') → point-from-start 1 s =-= a' tail = drop 1 private last1 : {a a' : A} (s : a =-= a') → A last1 {a = a} [] = a last1 {a = a} (p ◃∙ []) = a last1 (p ◃∙ s@(_ ◃∙ _)) = last1 s strip : {a a' : A} (s : a =-= a') → a =-= last1 s strip [] = [] strip (p ◃∙ []) = [] strip (p ◃∙ s@(_ ◃∙ _)) = p ◃∙ strip s point-from-end : (n : ℕ) {a a' : A} (s : a =-= a') → A point-from-end O {a} {a'} s = a' point-from-end (S n) s = point-from-end n (strip s) !- : (n : ℕ) {a a' : A} (s : a =-= a') → a =-= point-from-end n s !- O s = s !- (S n) s = !- n (strip s) take : (n : ℕ) {a a' : A} (s : a =-= a') → a =-= point-from-start n s take O s = [] take (S n) [] = [] take (S n) (p ◃∙ s) = p ◃∙ take n s private take-drop-split' : {a a' : A} (n : ℕ) (s : a =-= a') → s == take n s ∙∙ drop n s take-drop-split' O s = idp take-drop-split' (S n) [] = idp take-drop-split' (S n) (p ◃∙ s) = ap (λ v → p ◃∙ v) (take-drop-split' n s) abstract take-drop-split : {a a' : A} (n : ℕ) (s : a =-= a') → ↯ s ◃∎ =ₛ ↯ (take n s) ◃∙ ↯ (drop n s) ◃∎ take-drop-split n s = =ₛ-in $ ↯ s =⟨ ap ↯ (take-drop-split' n s) ⟩ ↯ (take n s ∙∙ drop n s) =⟨ ↯-∙∙ (take n s) (drop n s) ⟩ ↯ (take n s) ∙ ↯ (drop n s) =∎ private split : {a a' : A} (s : a =-= a') → Σ A (λ a'' → Σ (a =-= a'') (λ _ → a'' == a')) split {a = a} [] = (a , ([] , idp)) split {a = a} (p ◃∙ []) = (a , ([] , p)) split (p ◃∙ s@(_ ◃∙ _)) = let (a'' , (t , q)) = split s in (a'' , (p ◃∙ t) , q) point-from-end' : (n : ℕ) {a a' : A} (s : a =-= a') → A point-from-end' n {a = a} [] = a point-from-end' O (p ◃∙ s) = point-from-end' O s point-from-end' (S n) (p ◃∙ s) = point-from-end' n (fst (snd (split (p ◃∙ s)))) #- : (n : ℕ) {a a' : A} (s : a =-= a') → point-from-end' n s =-= a' #- n [] = [] #- O (p ◃∙ s) = #- O s #- (S n) (p ◃∙ s) = let (a' , (t , q)) = split (p ◃∙ s) in #- n t ∙▹ q infix 120 _!0 _!1 _!2 _!3 _!4 _!5 _!0 = !- 0 _!1 = !- 1 _!2 = !- 2 _!3 = !- 3 _!4 = !- 4 _!5 = !- 5 0! = drop 0 1! = drop 1 2! = drop 2 3! = drop 3 4! = drop 4 5! = drop 5 infix 120 _#0 _#1 _#2 _#3 _#4 _#5 _#0 = #- 0 _#1 = #- 1 _#2 = #- 2 _#3 = #- 3 _#4 = #- 4 _#5 = #- 5 0# = take 0 1# = take 1 2# = take 2 3# = take 3 4# = take 4 5# = take 5
{ "alphanum_fraction": 0.4343220339, "avg_line_length": 24.8421052632, "ext": "agda", "hexsha": "d1f056b83640613577e3bf019b661484ac5835e3", "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": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_path": "core/lib/path-seq/Split.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "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": "AntoineAllioux/HoTT-Agda", "max_issues_repo_path": "core/lib/path-seq/Split.agda", "max_line_length": 81, "max_stars_count": 294, "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_path": "core/lib/path-seq/Split.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": 1398, "size": 2832 }
{-# OPTIONS --without-K #-} module Note where open import Data.Integer using (ℤ) open import Data.Nat using (ℕ; _*_) open import Pitch using (Pitch; transposePitch) data Duration : Set where duration : ℕ → Duration unduration : Duration → ℕ unduration (duration d) = d data Note : Set where tone : Duration → Pitch → Note rest : Duration → Note -- Note: If we inline duration here Agda can't figure out -- that noteDuration (tone d _) = unduration d noteDuration : Note → ℕ noteDuration (tone d _) = unduration d noteDuration (rest d) = unduration d transposeNote : ℤ → Note → Note transposeNote k (tone d p) = tone d (transposePitch k p) transposeNote k (rest d) = rest d -- duration in 16th notes -- assume duration of a 16th note is 1 16th 8th qtr half whole : Duration 16th = duration 1 8th = duration 2 dqtr = duration 3 qtr = duration 4 half = duration 8 dhalf = duration 12 whole = duration 16 dwhole = duration 24
{ "alphanum_fraction": 0.6878850103, "avg_line_length": 23.756097561, "ext": "agda", "hexsha": "f6bf98053321b639d552acc22f20ab598b0e4576", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z", "max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "halfaya/MusicTools", "max_forks_repo_path": "doc/icfp20/code/Note.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z", "max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "halfaya/MusicTools", "max_issues_repo_path": "doc/icfp20/code/Note.agda", "max_line_length": 57, "max_stars_count": 28, "max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "halfaya/MusicTools", "max_stars_repo_path": "doc/icfp20/code/Note.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z", "max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z", "num_tokens": 287, "size": 974 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Group.Construct.Unit where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Algebra.Group open import Cubical.Data.Prod using (_,_) open import Cubical.Data.Unit import Cubical.Algebra.Monoid.Construct.Unit as ⊤Monoid open ⊤Monoid public hiding (⊤-isMonoid; ⊤-Monoid) inv : Op₁ ⊤ inv _ = tt ⊤-inverseˡ : LeftInverse tt inv _◯_ ⊤-inverseˡ _ = refl ⊤-inverseʳ : RightInverse tt inv _◯_ ⊤-inverseʳ _ = refl ⊤-inverse : Inverse tt inv _◯_ ⊤-inverse = ⊤-inverseˡ , ⊤-inverseʳ ⊤-isGroup : IsGroup ⊤ _◯_ tt inv ⊤-isGroup = record { isMonoid = ⊤Monoid.⊤-isMonoid ; inverse = ⊤-inverse } ⊤-Group : Group ℓ-zero ⊤-Group = record { isGroup = ⊤-isGroup }
{ "alphanum_fraction": 0.709346991, "avg_line_length": 22.3142857143, "ext": "agda", "hexsha": "ee2cddc479c34b250eafdc9b1cd2607ebc6c2b8c", "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/Algebra/Group/Construct/Unit.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/Algebra/Group/Construct/Unit.agda", "max_line_length": 55, "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/Algebra/Group/Construct/Unit.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 294, "size": 781 }
{-# OPTIONS --without-K #-} module algebra.semigroup.core where open import level open import equality.core open import sum open import hott.level record IsSemigroup {i} (X : Set i) : Set i where field _*_ : X → X → X assoc : (x y z : X) → (x * y) * z ≡ x * (y * z) is-set : h 2 X Semigroup : ∀ i → Set (lsuc i) Semigroup i = Σ (Set i) IsSemigroup
{ "alphanum_fraction": 0.6103542234, "avg_line_length": 20.3888888889, "ext": "agda", "hexsha": "62cbef91c4eb8f626f90acc51b8012c63bc571ba", "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/algebra/semigroup/core.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/algebra/semigroup/core.agda", "max_line_length": 51, "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/algebra/semigroup/core.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": 125, "size": 367 }
------------------------------------------------------------------------ -- A wrapper that turns a representation of natural numbers (with a -- unique representative for every number) into a representation that -- computes roughly like the unary natural numbers (at least for some -- operations) ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} import Bijection open import Equality import Erased.Without-box-cong open import Prelude hiding (zero; suc; _+_; _*_; _^_) module Nat.Wrapper {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) -- The underlying representation of natural numbers. (Nat′ : Type) -- A bijection between this representation and the unary natural -- numbers. (open Bijection eq using (_↔_)) (Nat′↔ℕ : Nat′ ↔ ℕ) where open Derived-definitions-and-properties eq open import Dec import Erased.Level-1 eq as E₁ import Erased.Stability eq as ES open import Logical-equivalence using (_⇔_) open import Erased.Without-box-cong eq open import Function-universe eq as F hiding (_∘_) open import H-level eq open import H-level.Closure eq open import List eq open import List.All.Recursive eq open import Vec eq as Vec private module N where open import Nat eq public open Prelude public using (zero; suc; _+_; _*_; _^_) variable A : Type f f′ m n n′ hyp : A ------------------------------------------------------------------------ -- The wrapper private -- Converts from the underlying representation to unary natural -- numbers. to-ℕ : Nat′ → ℕ to-ℕ = _↔_.to Nat′↔ℕ -- Natural numbers built on top of Nat′, indexed by corresponding -- unary natural numbers. Nat-[_] : @0 ℕ → Type Nat-[ m ] = ∃ λ (n : Nat′) → Erased (to-ℕ n ≡ m) -- A non-indexed variant of Nat-[_]. Nat : Type Nat = ∃ λ (n : Erased ℕ) → Nat-[ erased n ] -- Returns the (erased) index. @0 ⌊_⌋ : Nat → ℕ ⌊ [ n ] , _ ⌋ = n ------------------------------------------------------------------------ -- Some conversion functions -- Nat-[ n ] is isomorphic to the type of natural numbers equal -- (with erased equality proofs) to n. Nat-[]↔Σℕ : {@0 n : ℕ} → Nat-[ n ] ↔ ∃ λ m → Erased (m ≡ n) Nat-[]↔Σℕ {n = n} = (∃ λ (m : Nat′) → Erased (to-ℕ m ≡ n)) ↝⟨ (Σ-cong Nat′↔ℕ λ _ → F.id) ⟩□ (∃ λ m → Erased (m ≡ n)) □ -- Nat is logically equivalent to the type of unary natural numbers. Nat⇔ℕ : Nat ⇔ ℕ Nat⇔ℕ = Nat ↔⟨⟩ (∃ λ (n : Erased ℕ) → Nat-[ erased n ]) ↔⟨ (∃-cong λ _ → Nat-[]↔Σℕ) ⟩ (∃ λ (n : Erased ℕ) → ∃ λ m → Erased (m ≡ erased n)) ↝⟨ Σ-Erased-Erased-singleton⇔ ⟩□ ℕ □ -- Converts from Nat to ℕ. Nat→ℕ : Nat → ℕ Nat→ℕ (_ , n′ , _) = to-ℕ n′ -- Nat→ℕ is definitionally equal to the forward direction of Nat⇔ℕ. _ : Nat→ℕ ≡ _⇔_.to Nat⇔ℕ _ = refl _ -- Converts from ℕ to Nat. ⌈_⌉ : ℕ → Nat ⌈_⌉ = _⇔_.from Nat⇔ℕ -- The index matches the result of Nat→ℕ. @0 ≡⌊⌋ : ∀ n → Nat→ℕ n ≡ ⌊ n ⌋ ≡⌊⌋ ([ m ] , n , eq) = Nat→ℕ ([ m ] , n , eq) ≡⟨⟩ to-ℕ n ≡⟨ erased eq ⟩∎ m ∎ ------------------------------------------------------------------------ -- Some operations for Nat-[_] -- A helper function that can be used to define constants. nullary-[] : {@0 n : ℕ} (n′ : Nat′) → @0 to-ℕ n′ ≡ n → Nat-[ n ] nullary-[] n′ hyp = n′ , [ hyp ] -- A helper function that can be used to define unary operators. unary-[] : {@0 n : ℕ} {@0 f : ℕ → ℕ} (f′ : Nat′ → Nat′) → @0 (∀ n → to-ℕ (f′ n) ≡ f (to-ℕ n)) → Nat-[ n ] → Nat-[ f n ] unary-[] {n = n} {f = f} f′ hyp (n′ , p) = f′ n′ , [ to-ℕ (f′ n′) ≡⟨ hyp _ ⟩ f (to-ℕ n′) ≡⟨ cong f (erased p) ⟩∎ f n ∎ ] -- A helper function that can be used to define n-ary operators. n-ary-[] : (n : ℕ) {@0 ms : Vec (Erased ℕ) n} (@0 f : Vec ℕ n → ℕ) (f′ : Vec Nat′ n → Nat′) → @0 (∀ ms → to-ℕ (f′ ms) ≡ f (Vec.map to-ℕ ms)) → All (λ m → Nat-[ erased m ]) (Vec.to-list ms) → Nat-[ f (Vec.map erased ms) ] n-ary-[] N.zero _ f′ hyp _ = nullary-[] (f′ _) (hyp _) n-ary-[] (N.suc n) {ms = ms} f f′ hyp ((m′ , p) , ms′) = n-ary-[] n (f ∘ (erased (Vec.head ms) ,_)) (λ ms′ → f′ (m′ , ms′)) (λ ms′ → to-ℕ (f′ (m′ , ms′)) ≡⟨ hyp (m′ , ms′) ⟩ f (to-ℕ m′ , Vec.map to-ℕ ms′) ≡⟨ cong (λ x → f (x , _)) (erased p) ⟩∎ f (erased (Vec.head ms) , Vec.map to-ℕ ms′) ∎) ms′ -- The function n-ary-[] should be normalised by the compiler. {-# STATIC n-ary-[] #-} -- A helper function that can be used to define binary -- operators. binary-[] : {@0 m n : ℕ} {@0 f : ℕ → ℕ → ℕ} (f′ : Nat′ → Nat′ → Nat′) → @0 (∀ m n → to-ℕ (f′ m n) ≡ f (to-ℕ m) (to-ℕ n)) → Nat-[ m ] → Nat-[ n ] → Nat-[ f m n ] binary-[] f′ hyp m n = n-ary-[] 2 _ (λ (m , n , _) → f′ m n) (λ (m , n , _) → hyp m n) (m , n , _) -- The code below is parametrised by implementations of (and -- correctness properties for) certain operations for Nat′. record Operations : Type where infixl 8 _*2^_ infixr 8 _^_ infixl 7 _*_ infixl 6 _+_ infix 4 _≟_ field zero : Nat′ to-ℕ-zero : to-ℕ zero ≡ N.zero suc : Nat′ → Nat′ to-ℕ-suc : ∀ n → to-ℕ (suc n) ≡ N.suc (to-ℕ n) _+_ : Nat′ → Nat′ → Nat′ to-ℕ-+ : ∀ m n → to-ℕ (m + n) ≡ to-ℕ m N.+ to-ℕ n _*_ : Nat′ → Nat′ → Nat′ to-ℕ-* : ∀ m n → to-ℕ (m * n) ≡ to-ℕ m N.* to-ℕ n _^_ : Nat′ → Nat′ → Nat′ to-ℕ-^ : ∀ m n → to-ℕ (m ^ n) ≡ to-ℕ m N.^ to-ℕ n ⌊_/2⌋ : Nat′ → Nat′ to-ℕ-⌊/2⌋ : ∀ n → to-ℕ ⌊ n /2⌋ ≡ N.⌊ to-ℕ n /2⌋ ⌈_/2⌉ : Nat′ → Nat′ to-ℕ-⌈/2⌉ : ∀ n → to-ℕ ⌈ n /2⌉ ≡ N.⌈ to-ℕ n /2⌉ _*2^_ : Nat′ → ℕ → Nat′ to-ℕ-*2^ : ∀ m n → to-ℕ (m *2^ n) ≡ to-ℕ m N.* 2 N.^ n _≟_ : ∀ m n → Dec (Erased (to-ℕ m ≡ to-ℕ n)) from-bits : List Bool → Nat′ to-ℕ-from-bits : ∀ bs → to-ℕ (from-bits bs) ≡ foldl (λ n b → (if b then 1 else 0) N.+ 2 N.* n) 0 bs to-bits : Nat′ → List Bool to-ℕ-from-bits-to-bits : ∀ n → to-ℕ (from-bits (to-bits n)) ≡ to-ℕ n -- If certain operations are defined for Nat′, then they can be -- defined for Nat-[_] as well. module Operations-for-Nat-[] (o : Operations) where private module O = Operations o -- Zero. zero : Nat-[ N.zero ] zero = nullary-[] O.zero O.to-ℕ-zero -- The number's successor. suc : {@0 n : ℕ} → Nat-[ n ] → Nat-[ N.suc n ] suc = unary-[] O.suc O.to-ℕ-suc -- Addition. infixl 6 _+_ _+_ : {@0 m n : ℕ} → Nat-[ m ] → Nat-[ n ] → Nat-[ m N.+ n ] _+_ = binary-[] O._+_ O.to-ℕ-+ -- Multiplication. infixl 7 _*_ _*_ : {@0 m n : ℕ} → Nat-[ m ] → Nat-[ n ] → Nat-[ m N.* n ] _*_ = binary-[] O._*_ O.to-ℕ-* -- Exponentiation. infixr 8 _^_ _^_ : {@0 m n : ℕ} → Nat-[ m ] → Nat-[ n ] → Nat-[ m N.^ n ] _^_ = binary-[] O._^_ O.to-ℕ-^ -- Division by two, rounded downwards. ⌊_/2⌋ : {@0 n : ℕ} → Nat-[ n ] → Nat-[ N.⌊ n /2⌋ ] ⌊_/2⌋ = unary-[] O.⌊_/2⌋ O.to-ℕ-⌊/2⌋ -- Division by two, rounded upwards. ⌈_/2⌉ : {@0 n : ℕ} → Nat-[ n ] → Nat-[ N.⌈ n /2⌉ ] ⌈_/2⌉ = unary-[] O.⌈_/2⌉ O.to-ℕ-⌈/2⌉ -- Left shift. infixl 8 _*2^_ _*2^_ : {@0 m : ℕ} → Nat-[ m ] → ∀ n → Nat-[ m N.* 2 N.^ n ] m *2^ n = unary-[] (O._*2^ n) (flip O.to-ℕ-*2^ n) m -- Equality is decidable (in a certain sense). infix 4 _≟_ _≟_ : {@0 m n : ℕ} → Nat-[ m ] → Nat-[ n ] → Dec (Erased (m ≡ n)) _≟_ {m = m} {n = n} (m′ , [ m≡m′ ]) (n′ , [ n≡n′ ]) = Dec-map (Erased-cong-⇔ ( to-ℕ m′ ≡ to-ℕ n′ ↝⟨ ≡⇒↝ _ (cong₂ _≡_ m≡m′ n≡n′) ⟩□ m ≡ n □)) (m′ O.≟ n′) -- Conversion from bits. (The most significant bit comes first.) from-bits : (bs : List Bool) → Nat-[ foldl (λ n b → (if b then 1 else 0) N.+ 2 N.* n) 0 bs ] from-bits bs = nullary-[] (O.from-bits bs) (O.to-ℕ-from-bits bs) -- Conversion to bits. (The most significant bit comes first.) to-bits : {@0 n : ℕ} → Nat-[ n ] → ∃ λ (bs : List Bool) → Erased (foldl (λ n b → (if b then 1 else 0) N.+ 2 N.* n) 0 bs ≡ n) to-bits {n = n} (n′ , [ n′≡n ]) = O.to-bits n′ , [ foldl (λ n b → (if b then 1 else 0) N.+ 2 N.* n) 0 (O.to-bits n′) ≡⟨ sym $ O.to-ℕ-from-bits _ ⟩ to-ℕ (O.from-bits (O.to-bits n′)) ≡⟨ O.to-ℕ-from-bits-to-bits _ ⟩ to-ℕ n′ ≡⟨ n′≡n ⟩∎ n ∎ ] ------------------------------------------------------------------------ -- Operations for Nat private -- Equality is stable for the natural numbers. Stable-≡-ℕ : Stable-≡ ℕ Stable-≡-ℕ m n = Dec→Stable (m N.≟ n) -- A helper function that can be used to define constants. nullary : (@0 n : ℕ) (n′ : Nat′) → @0 to-ℕ n′ ≡ n → Nat nullary n n′ hyp = [ n ] , nullary-[] n′ hyp -- A first correctness result for nullary. -- -- Note that this result holds by definition. private @0 nullary-correct′ : ⌊ nullary n n′ hyp ⌋ ≡ n nullary-correct′ = refl _ -- A second correctness result for nullary. nullary-correct : (@0 hyp : to-ℕ n′ ≡ n) → Nat→ℕ (nullary n n′ hyp) ≡ n nullary-correct {n′ = n′} {n = n} hyp = Stable-≡-ℕ _ _ [ Nat→ℕ (nullary n n′ hyp) ≡⟨ ≡⌊⌋ (nullary n n′ hyp) ⟩ ⌊ nullary n n′ hyp ⌋ ≡⟨⟩ n ∎ ] -- A helper function that can be used to define unary operators. unary : (@0 f : ℕ → ℕ) (f′ : Nat′ → Nat′) → @0 (∀ n → to-ℕ (f′ n) ≡ f (to-ℕ n)) → Nat → Nat unary f f′ hyp ([ n ] , n′) = ([ f n ] , unary-[] f′ hyp n′) -- A first correctness result for unary. -- -- Note that this result holds by definition. private @0 unary-correct′ : ⌊ unary f f′ hyp n ⌋ ≡ f ⌊ n ⌋ unary-correct′ = refl _ -- A second correctness result for unary. unary-correct : (f : ℕ → ℕ) (@0 hyp : ∀ n → to-ℕ (f′ n) ≡ f (to-ℕ n)) → ∀ n → Nat→ℕ (unary f f′ hyp n) ≡ f (Nat→ℕ n) unary-correct {f′ = f′} f hyp n = Stable-≡-ℕ _ _ [ Nat→ℕ (unary f f′ hyp n) ≡⟨ ≡⌊⌋ (unary f f′ hyp n) ⟩ ⌊ unary f f′ hyp n ⌋ ≡⟨⟩ f ⌊ n ⌋ ≡⟨ sym $ cong f $ ≡⌊⌋ n ⟩∎ f (Nat→ℕ n) ∎ ] -- A helper function that can be used to define n-ary operators. n-ary : (n : ℕ) (@0 f : Vec ℕ n → ℕ) (f′ : Vec Nat′ n → Nat′) → @0 (∀ ms → to-ℕ (f′ ms) ≡ f (Vec.map to-ℕ ms)) → Vec Nat n → Nat n-ary n f f′ hyp ms = [ f (Vec.map erased (proj₁ (_↔_.to Vec-Σ ms))) ] , n-ary-[] n f f′ hyp (proj₂ (_↔_.to Vec-Σ ms)) -- The function n-ary should be normalised by the compiler. {-# STATIC n-ary #-} -- The function n-ary is correct. n-ary-correct : ∀ (n : ℕ) f {f′} (@0 hyp : ∀ ms → to-ℕ (f′ ms) ≡ f (Vec.map to-ℕ ms)) → ∀ ms → Nat→ℕ (n-ary n f f′ hyp ms) ≡ f (Vec.map (Nat→ℕ) ms) n-ary-correct n f {f′ = f′} hyp ms = Stable-≡-ℕ _ _ [ Nat→ℕ (n-ary n f f′ hyp ms) ≡⟨ ≡⌊⌋ (n-ary n f f′ hyp ms) ⟩ ⌊ n-ary n f f′ hyp ms ⌋ ≡⟨⟩ f (Vec.map erased (proj₁ (_↔_.to Vec-Σ ms))) ≡⟨ cong (f ∘ Vec.map _) proj₁-Vec-Σ ⟩ f (Vec.map erased (Vec.map proj₁ ms)) ≡⟨ cong f $ sym Vec.map-∘ ⟩ f (Vec.map ⌊_⌋ ms) ≡⟨ cong f $ sym $ Vec.map-cong ≡⌊⌋ ⟩∎ f (Vec.map (Nat→ℕ) ms) ∎ ] -- A helper function that can be used to define binary operators binary : (@0 f : ℕ → ℕ → ℕ) (f′ : Nat′ → Nat′ → Nat′) → @0 (∀ m n → to-ℕ (f′ m n) ≡ f (to-ℕ m) (to-ℕ n)) → Nat → Nat → Nat binary f g hyp m n = n-ary 2 (λ (m , n , _) → f m n) (λ (m , n , _) → g m n) (λ (m , n , _) → hyp m n) (m , n , _) -- A first correctness result for binary. -- -- Note that this result holds by definition. private @0 binary-correct′ : ⌊ binary f f′ hyp m n ⌋ ≡ f ⌊ m ⌋ ⌊ n ⌋ binary-correct′ = refl _ -- A second correctness result for binary. binary-correct : (f : ℕ → ℕ → ℕ) (@0 hyp : ∀ m n → to-ℕ (f′ m n) ≡ f (to-ℕ m) (to-ℕ n)) → ∀ m n → Nat→ℕ (binary f f′ hyp m n) ≡ f (Nat→ℕ m) (Nat→ℕ n) binary-correct f hyp m n = n-ary-correct 2 (λ (m , n , _) → f m n) (λ (m , n , _) → hyp m n) (m , n , _) -- If certain operations are defined for Nat′, then they can be -- defined for Nat-[_] as well. module Operations-for-Nat (o : Operations) where private module O = Operations o module O-[] = Operations-for-Nat-[] o -- Zero. zero : Nat zero = nullary N.zero O.zero O.to-ℕ-zero to-ℕ-zero : Nat→ℕ zero ≡ N.zero to-ℕ-zero = nullary-correct O.to-ℕ-zero -- The number's successor. suc : Nat → Nat suc = unary N.suc O.suc O.to-ℕ-suc to-ℕ-suc : ∀ n → Nat→ℕ (suc n) ≡ N.suc (Nat→ℕ n) to-ℕ-suc = unary-correct N.suc O.to-ℕ-suc -- Addition. infixl 6 _+_ _+_ : Nat → Nat → Nat _+_ = binary N._+_ O._+_ O.to-ℕ-+ to-ℕ-+ : ∀ m n → Nat→ℕ (m + n) ≡ Nat→ℕ m N.+ Nat→ℕ n to-ℕ-+ = binary-correct N._+_ O.to-ℕ-+ -- Multiplication. infixl 7 _*_ _*_ : Nat → Nat → Nat _*_ = binary N._*_ O._*_ O.to-ℕ-* to-ℕ-* : ∀ m n → Nat→ℕ (m * n) ≡ Nat→ℕ m N.* Nat→ℕ n to-ℕ-* = binary-correct N._*_ O.to-ℕ-* -- Multiplication. infixr 8 _^_ _^_ : Nat → Nat → Nat _^_ = binary N._^_ O._^_ O.to-ℕ-^ to-ℕ-^ : ∀ m n → Nat→ℕ (m ^ n) ≡ Nat→ℕ m N.^ Nat→ℕ n to-ℕ-^ = binary-correct N._^_ O.to-ℕ-^ -- Division by two, rounded downwards. ⌊_/2⌋ : Nat → Nat ⌊_/2⌋ = unary N.⌊_/2⌋ O.⌊_/2⌋ O.to-ℕ-⌊/2⌋ to-ℕ-⌊/2⌋ : ∀ n → Nat→ℕ ⌊ n /2⌋ ≡ N.⌊ Nat→ℕ n /2⌋ to-ℕ-⌊/2⌋ = unary-correct N.⌊_/2⌋ O.to-ℕ-⌊/2⌋ -- Division by two, rounded upwards. ⌈_/2⌉ : Nat → Nat ⌈_/2⌉ = unary N.⌈_/2⌉ O.⌈_/2⌉ O.to-ℕ-⌈/2⌉ to-ℕ-⌈/2⌉ : ∀ n → Nat→ℕ ⌈ n /2⌉ ≡ N.⌈ Nat→ℕ n /2⌉ to-ℕ-⌈/2⌉ = unary-correct N.⌈_/2⌉ O.to-ℕ-⌈/2⌉ -- Left shift. infixl 8 _*2^_ _*2^_ : Nat → ℕ → Nat m *2^ n = unary (λ m → m N.* 2 N.^ n) (O._*2^ n) (flip O.to-ℕ-*2^ n) m to-ℕ-*2^ : ∀ m n → Nat→ℕ (m *2^ n) ≡ Nat→ℕ m N.* 2 N.^ n to-ℕ-*2^ m n = unary-correct (λ m → m N.* 2 N.^ n) (flip O.to-ℕ-*2^ n) m -- Equality is decidable (in a certain sense). infix 4 _≟_ _≟_ : (m n : Nat) → Dec (Erased (⌊ m ⌋ ≡ ⌊ n ⌋)) (_ , m′) ≟ (_ , n′) = m′ O-[].≟ n′ -- Conversion from bits. (The most significant bit comes first.) from-bits : List Bool → Nat from-bits bs = nullary (foldl (λ n b → (if b then 1 else 0) N.+ 2 N.* n) 0 bs) (O.from-bits bs) (O.to-ℕ-from-bits bs) to-ℕ-from-bits : ∀ bs → Nat→ℕ (from-bits bs) ≡ foldl (λ n b → (if b then 1 else 0) N.+ 2 N.* n) 0 bs to-ℕ-from-bits bs = nullary-correct (O.to-ℕ-from-bits bs) -- Conversion to bits. (The most significant bit comes first.) to-bits : Nat → List Bool to-bits (_ , n′) = proj₁ (O-[].to-bits n′) ------------------------------------------------------------------------ -- Results that make use of an instantiation of the []-cong axioms module []-cong (ax : []-cong-axiomatisation lzero) where open E₁.[]-cong₁ ax open E₁.Erased-cong ax ax open ES.[]-cong₁ ax open ES.[]-cong₂ ax ax ---------------------------------------------------------------------- -- Some lemmas private -- Equality is very stable for the natural numbers. Very-stable-≡-ℕ : Very-stable-≡ ℕ Very-stable-≡-ℕ = Decidable-equality→Very-stable-≡ N._≟_ -- Nat-[ n ] is a proposition. Nat-[]-propositional : {@0 n : ℕ} → Is-proposition Nat-[ n ] Nat-[]-propositional {n = n} = $⟨ Very-stable-≡-ℕ ⟩ Very-stable-≡ ℕ ↝⟨ Very-stable-congⁿ _ 1 (inverse Nat′↔ℕ) ⟩ Very-stable-≡ Nat′ ↝⟨ Very-stable→Very-stableᴱ 1 ⟩ Very-stableᴱ-≡ Nat′ ↝⟨ erased-singleton-with-erased-center-propositional ⟩ Is-proposition (∃ λ (m : Nat′) → Erased (m ≡ _↔_.from Nat′↔ℕ n)) ↝⟨ (H-level-cong _ 1 $ ∃-cong λ _ → Erased-cong-↔ (inverse $ from≡↔≡to (from-isomorphism $ inverse Nat′↔ℕ))) ⟩□ Is-proposition (∃ λ (m : Nat′) → Erased (to-ℕ m ≡ n)) □ -- There is a bijection between equality of two values of type Nat -- and erased equality of the corresponding unary natural number -- indices. ≡-for-indices↔≡ : {m n : Nat} → Erased (⌊ m ⌋ ≡ ⌊ n ⌋) ↔ m ≡ n ≡-for-indices↔≡ {m = m} {n = n} = Erased (⌊ m ⌋ ≡ ⌊ n ⌋) ↝⟨ Erased-≡↔[]≡[] ⟩ proj₁ m ≡ proj₁ n ↝⟨ ignore-propositional-component Nat-[]-propositional ⟩□ m ≡ n □ ---------------------------------------------------------------------- -- Another conversion function -- Nat is isomorphic to the type of unary natural numbers. Nat↔ℕ : Nat ↔ ℕ Nat↔ℕ = Nat ↔⟨⟩ (∃ λ (n : Erased ℕ) → Nat-[ erased n ]) ↝⟨ (∃-cong λ _ → Nat-[]↔Σℕ) ⟩ (∃ λ (n : Erased ℕ) → ∃ λ m → Erased (m ≡ erased n)) ↝⟨ Σ-Erased-Erased-singleton↔ ⟩□ ℕ □ -- The logical equivalence underlying Nat↔ℕ is definitionally equal -- to Nat⇔ℕ. _ : _↔_.logical-equivalence Nat↔ℕ ≡ Nat⇔ℕ _ = refl _ ---------------------------------------------------------------------- -- A correctness result related to the module Operations-for-Nat module Operations-for-Nat-correct (o : Operations) where private module O-[] = Operations-for-Nat-[] o open Operations-for-Nat o to-ℕ-from-bits-to-bits : ∀ n → Nat→ℕ (from-bits (to-bits n)) ≡ Nat→ℕ n to-ℕ-from-bits-to-bits n@(_ , n′) = cong Nat→ℕ $ _↔_.to (≡-for-indices↔≡ {m = from-bits (to-bits n)} {n = n}) [ ⌊ from-bits (to-bits n) ⌋ ≡⟨ erased (proj₂ (O-[].to-bits n′)) ⟩∎ ⌊ n ⌋ ∎ ] ---------------------------------------------------------------------- -- Some examples private module Nat-[]-examples (o : Operations) where open Operations-for-Nat-[] o -- Converts unary natural numbers to binary natural numbers. from-ℕ : ∀ n → Nat-[ n ] from-ℕ = proj₂ ∘ _↔_.from Nat↔ℕ -- Nat n is a proposition, so it is easy to prove that two -- values of this type are equal. example₁ : from-ℕ 4 + ⌊ from-ℕ 12 /2⌋ ≡ from-ℕ 10 example₁ = Nat-[]-propositional _ _ -- However, stating that two values of type Nat m and Nat n are -- equal, for equal natural numbers m and n, can be awkward. @0 example₂ : {@0 m n : ℕ} → (b : Nat-[ m ]) (c : Nat-[ n ]) → subst (λ n → Nat-[ n ]) (N.+-comm m) (b + c) ≡ c + b example₂ _ _ = Nat-[]-propositional _ _ module Nat-examples (o : Operations) where open Operations-for-Nat o -- If Nat is used instead of Nat-[_], then it can be easier to -- state that two values are equal. example₁ : ⌈ 4 ⌉ + ⌊ ⌈ 12 ⌉ /2⌋ ≡ ⌈ 10 ⌉ example₁ = _↔_.to ≡-for-indices↔≡ [ refl _ ] example₂ : ∀ m n → m + n ≡ n + m example₂ m n = _↔_.to ≡-for-indices↔≡ [ ⌊ m ⌋ N.+ ⌊ n ⌋ ≡⟨ N.+-comm ⌊ m ⌋ ⟩∎ ⌊ n ⌋ N.+ ⌊ m ⌋ ∎ ] -- One can construct a proof showing that ⌈ 5 ⌉ is either equal -- or not equal to ⌈ 2 ⌉ + ⌈ 3 ⌉, but the proof does not compute -- to "inj₁ something" at compile-time. example₃ : Dec (⌈ 5 ⌉ ≡ ⌈ 2 ⌉ + ⌈ 3 ⌉) example₃ = Dec-map (_↔_.logical-equivalence ≡-for-indices↔≡) (⌈ 5 ⌉ ≟ ⌈ 2 ⌉ + ⌈ 3 ⌉)
{ "alphanum_fraction": 0.474745935, "avg_line_length": 27.3333333333, "ext": "agda", "hexsha": "6870171f2a18c11af452a610453dbb0f208b28b5", "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": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Nat/Wrapper.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/equality", "max_issues_repo_path": "src/Nat/Wrapper.agda", "max_line_length": 130, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Nat/Wrapper.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 7985, "size": 19680 }
module Import where import Agda.Builtin.Bool as _ open import Agda.Builtin.Nat as _ import Agda.Builtin.Unit using (⊤; tt) A : Set A = Agda.Builtin.Unit.⊤
{ "alphanum_fraction": 0.6904761905, "avg_line_length": 11.2, "ext": "agda", "hexsha": "1cdcf9ee56470703548729fe19980a847ad4c6c8", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "msuperdock/agda-unused", "max_forks_repo_path": "data/declaration/Import.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "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": "msuperdock/agda-unused", "max_issues_repo_path": "data/declaration/Import.agda", "max_line_length": 28, "max_stars_count": 6, "max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "msuperdock/agda-unused", "max_stars_repo_path": "data/declaration/Import.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z", "num_tokens": 62, "size": 168 }
{-# OPTIONS --safe -W ignore #-} module Map where open import Data.String open import Data.String.Properties using (_==_) open import Data.Bool open import Relation.Binary.PropositionalEquality open import Agda.Builtin.Unit open import Data.Empty open import Relation.Nullary using (¬_) import Relation.Nullary.Decidable.Core import Data.List.Relation.Binary.Pointwise import Data.List.Relation.Binary.Pointwise.Properties import Agda.Builtin.Char.Properties import Agda.Builtin.Char import Data.Nat.Properties -- The empty map K : {A : Set} → (v : A) → (String → A) K v = (λ _ → v) -- Storing in map "m" with value "v" into key "k" Store : {A : Set} → (m : (String → A)) → (k : String) → (v : A) → (String → A) Store m k v = λ k' → if (k' == k) then v else m k' -- Unit tests open import Data.Nat -- Example of initialising the variable stack S : (String → ℕ) S = K 0 -- Example of adding values to a stack S1 : (String → ℕ) S1 = Store S "a" 10 -- Adding the second variable S2 : (String → ℕ) S2 = Store S1 "b" 11 -- Getting the value of a from stack S2 A : ℕ A = S2 "a" -- Getting the value of b from stack S2 B : ℕ B = S2 "b" -- Try to get a string that is not in stack, gives the default value C : ℕ C = S2 "c" -- Important properties -- Lemma needed to prove the side condition between stacks after -- function call lemma-stack-eq : {A : Set} → ∀ (stm stf : (String → A)) → (X Y : String) → (Store stm Y (stf X)) Y ≡ (stf X) lemma-stack-eq stm stf X Y with (Y Data.String.≟ Y) ... | .true Relation.Nullary.because Relation.Nullary.ofʸ p = refl ... | .false Relation.Nullary.because Relation.Nullary.ofⁿ ¬p = ⊥-elim (¬p refl) -- Now a very important property for proving the constancy rule t-update-neq : {A : Set} → ∀ (st : (String → A)) → (x1 x2 : String) → (v : A) → ((x2 ≡ x1) → ⊥) → (Store st x1 v) x2 ≡ (st x2) t-update-neq st x1 x2 v p with (Relation.Nullary.Decidable.Core.map′ (λ x → Data.String.Properties.toList-injective x2 x1 (Data.List.Relation.Binary.Pointwise.Pointwise-≡⇒≡ x)) (λ x → Data.List.Relation.Binary.Pointwise.≡⇒Pointwise-≡ (cong toList x)) (Data.List.Relation.Binary.Pointwise.Properties.decidable (λ x y → Relation.Nullary.Decidable.Core.map′ (Agda.Builtin.Char.Properties.primCharToNatInjective x y) (cong Agda.Builtin.Char.primCharToNat) (Relation.Nullary.Decidable.Core.map′ (Data.Nat.Properties.≡ᵇ⇒≡ (Agda.Builtin.Char.primCharToNat x) (Agda.Builtin.Char.primCharToNat y)) (Data.Nat.Properties.≡⇒≡ᵇ (Agda.Builtin.Char.primCharToNat x) (Agda.Builtin.Char.primCharToNat y)) (T? (Agda.Builtin.Char.primCharToNat x ≡ᵇ Agda.Builtin.Char.primCharToNat y)))) (toList x2) (toList x1))) ... | false Relation.Nullary.because Relation.Nullary.ofⁿ ¬p = refl ... | true Relation.Nullary.because Relation.Nullary.ofʸ refl = ⊥-elim (p refl) -- Testing lookup with nested stores test : {A : Set} → ∀ (x1 x2 y : String) → (st st' : (String → A)) → (v1 v2 : A) → (y ≡ x1 → ⊥) → (y ≡ x2 → ⊥) → (st' ≡ (Store (Store st x1 v1) x2 v2)) → st' y ≡ st y test x1 x2 y st st' v1 v2 p1 p2 q rewrite q | t-update-neq (Store st x1 v1) x2 y v2 p2 | t-update-neq st x1 y v1 p1 = refl -- Partial map open import Data.Maybe KP : {A : Set} → (String → Maybe A) KP = (λ _ → nothing) StoreP : {A : Set} → (st : (String → Maybe A)) → (x : String) → (v : A) → (String → Maybe A) StoreP st x v = λ x' → if x == x' then just v else st x'
{ "alphanum_fraction": 0.6152584085, "avg_line_length": 32.9459459459, "ext": "agda", "hexsha": "424da367552ff5b5e28a996d1db1305b308778c8", "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": "bff8c271b54f55ceac550c603e468f68838a07ee", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "amal029/compositional-real-time-contracts", "max_forks_repo_path": "Map.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "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": "amal029/compositional-real-time-contracts", "max_issues_repo_path": "Map.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "amal029/compositional-real-time-contracts", "max_stars_repo_path": "Map.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1187, "size": 3657 }
{-# OPTIONS --without-K #-} module 2DTypes where -- open import Level renaming (zero to lzero) open import Relation.Binary.PropositionalEquality open import Data.Unit open import Data.Sum open import Data.Empty using (⊥; ⊥-elim) open import Data.Product open import Function using (_∘_) open import Relation.Binary using (Setoid) open import Data.Nat using (ℕ) renaming (suc to ℕsuc; _+_ to _ℕ+_; _*_ to _ℕ*_) open import Data.Fin using (Fin; zero; suc) open import Data.Vec using (Vec; lookup; _∷_; []; zipWith) open import Data.Integer hiding (suc) open import VectorLemmas using (_!!_) open import PiU open import PiLevel0 hiding (!!) open import PiEquiv open import PiLevel1 open import Equiv open import EquivEquiv using (_≋_; module _≋_) open import Categories.Category open import Categories.Groupoid open import Categories.Equivalence.Strong -- This exists somewhere, but I can't find it ⊎-inj : ∀ {ℓ} {A B : Set ℓ} {a : A} {b : B} → inj₁ a ≡ inj₂ b → ⊥ ⊎-inj () -- should probably make this level-polymorphic record Typ : Set where constructor typ field carr : U len : ℕ -- number of non-trivial automorphisms auto : Vec (carr ⟷ carr) (ℕsuc len) -- the real magic goes here -- normally the stuff below is "global", but here -- we attach it to a type. id : id⟷ ⇔ (auto !! zero) _⊙_ : Fin (ℕsuc len) → Fin (ℕsuc len) → Fin (ℕsuc len) coh : ∀ (i j : Fin (ℕsuc len)) → -- note the flip !!! ((auto !! i) ◎ (auto !! j) ⇔ (auto !! (j ⊙ i))) -- to get groupoid, we need inverse knowledge, do later open Typ -- The above 'induces' a groupoid structure, which -- we need to show in detail. -- First, a useful container for the info we need: record Hm (t : Typ) (a b : ⟦ carr t ⟧) : Set where constructor hm field eq : carr t ⟷ carr t good : Σ (Fin (ℕsuc (len t))) (λ n → eq ⇔ (auto t !! n)) fwd : proj₁ (c2equiv eq) a ≡ b bwd : isqinv.g (proj₂ (c2equiv eq)) b ≡ a -- note how (auto t) is not actually used! -- also: not sure e₁ and e₂ always used coherently, as types are not enough -- to decide which one to use... induceCat : Typ → Category _ _ _ induceCat t = record { Obj = ⟦ carr t ⟧ ; _⇒_ = Hm t ; _≡_ = λ { (hm e₁ g₁ _ _) → λ { (hm e₂ g₂ _ _) → e₁ ⇔ e₂} } ; id = hm id⟷ (zero , id t) refl refl ; _∘_ = λ { {A} {B} {C} (hm e₁ (n₁ , p₁) fwd₁ bwd₁) (hm e₂ (n₂ , p₂) fwd₂ bwd₂) → let pf₁ = (begin ( proj₁ (c2equiv e₁ ● c2equiv e₂) A ≡⟨ β₁ A ⟩ (proj₁ (c2equiv e₁) ∘ (proj₁ (c2equiv e₂))) A ≡⟨ cong (proj₁ (c2equiv e₁)) fwd₂ ⟩ proj₁ (c2equiv e₁) B ≡⟨ fwd₁ ⟩ C ∎ )) -- same as above (in opposite direction), just compressed pf₂ = trans (β₂ C) (trans (cong (isqinv.g (proj₂ (c2equiv e₂))) bwd₁) bwd₂) n₃ = _⊙_ t n₁ n₂ compos = n₃ , trans⇔ (p₂ ⊡ p₁) (coh t n₂ n₁) in hm (e₂ ◎ e₁) compos pf₁ pf₂ } ; assoc = assoc◎l ; identityˡ = idr◎l ; identityʳ = idl◎l ; equiv = record { refl = id⇔ ; sym = 2! ; trans = trans⇔ } ; ∘-resp-≡ = λ f g → g ⊡ f } where open Typ open ≡-Reasoning {- -- to get the Groupoid structure, there is stuff in the type that is -- missing; see the hole. induceG : (t : Typ) → Groupoid (induceCat t) induceG t = record { _⁻¹ = λ { {A} {B} (hm e g fw bw) → hm (! e) {!!} (trans (f≡ (!≡sym≃ e) B) bw) (trans (g≡ (!≡sym≃ e) A) fw) } ; iso = record { isoˡ = linv◎l ; isoʳ = rinv◎l } } where open _≋_ -} -- some useful functions for defining the type 1T private mult : Fin 1 → Fin 1 → Fin 1 mult zero zero = zero mult _ (suc ()) mult (suc ()) _ triv : Vec (ONE ⟷ ONE) 1 triv = id⟷ ∷ [] mult-coh : ∀ (i j : Fin 1) → ((triv !! i) ◎ (triv !! j) ⇔ (triv !! (mult j i))) mult-coh zero zero = idl◎l -- note how this is non-trivial! mult-coh _ (suc ()) mult-coh (suc ()) _ 1T : Typ 1T = record { carr = ONE ; len = 0 ; auto = triv ; id = id⇔ ; _⊙_ = mult ; coh = mult-coh } BOOL : U BOOL = PLUS ONE ONE -- some useful functions for defining the type 1T′ private mult′ : Fin 2 → Fin 2 → Fin 2 mult′ zero zero = zero mult′ zero (suc zero) = suc zero mult′ _ (suc (suc ())) mult′ (suc zero) zero = suc zero mult′ (suc zero) (suc zero) = zero mult′ (suc (suc ())) _ sw : Vec (BOOL ⟷ BOOL) 2 sw = id⟷ ∷ swap₊ ∷ [] sw-coh : ∀ (i j : Fin 2) → ((sw !! i) ◎ (sw !! j) ⇔ (sw !! (mult′ j i))) sw-coh zero zero = idl◎l sw-coh zero (suc zero) = idl◎l sw-coh _ (suc (suc ())) sw-coh (suc zero) zero = idr◎l sw-coh (suc zero) (suc zero) = linv◎l sw-coh (suc (suc ())) _ 1T′ : Typ 1T′ = record { carr = BOOL ; len = 1 ; auto = sw ; id = id⇔ ; _⊙_ = mult′ ; coh = sw-coh } -- useful utilities private collapse : ⊤ ⊎ ⊤ → ⊤ collapse (inj₁ a) = a collapse (inj₂ b) = b collapse-coh : ∀ {A B : ⊤ ⊎ ⊤} → collapse A ≡ collapse B collapse-coh {inj₁ tt} {inj₁ tt} = refl collapse-coh {inj₁ tt} {inj₂ tt} = refl collapse-coh {inj₂ tt} {inj₁ tt} = refl collapse-coh {inj₂ tt} {inj₂ tt} = refl -- let's do it on categories only. -- The important thing here is that we only have -- access to id⟷ and (auto 1T′) as things of type -- (carr 1T′ ⟷ carr 1T′). 1T≃1T′ : StrongEquivalence (induceCat 1T) (induceCat 1T′) 1T≃1T′ = record -- from 1T to 1T′, we really do want to map down to id⟷ onto inj₁ { F = record { F₀ = inj₁ ; F₁ = λ { {tt} {tt} (hm e g fwd bwd) → hm id⟷ (zero , id⇔) refl refl} ; identity = id⇔ ; homomorphism = idl◎r ; F-resp-≡ = λ _ → id⇔ } -- and here, everything should be collapsed ; G = record { F₀ = collapse ; F₁ = λ { {A} {B} (hm e g fwd bwd) → hm id⟷ (zero , id⇔) (collapse-coh {A} {B}) (collapse-coh {B} {A})} ; identity = id⇔ ; homomorphism = idl◎r ; F-resp-≡ = λ _ → id⇔ } -- and here is where (auto 1T′) is needed, else this is false!! ; weak-inverse = record { F∘G≅id = record { F⇒G = record { η = λ { (inj₁ a) → hm id⟷ (zero , id⇔) refl refl; (inj₂ b) → hm swap₊ (suc zero , id⇔) refl refl } ; commute = λ { {inj₁ tt} {inj₁ tt} (hm c (zero , x) _ _) → trans⇔ idl◎l (trans⇔ (2! x) idl◎r) ; {inj₁ tt} {inj₁ tt} (hm c (suc zero , x) a b) → ⊥-elim (⊎-inj ( trans (sym a) ( trans (sym (lemma0 c (inj₁ tt))) (≋⇒≡ x (inj₁ tt))))) ; {inj₁ tt} {inj₁ tt} (hm c (suc (suc ()), _) _ _); {inj₁ tt} {inj₂ tt} (hm c (zero , x) a b) → ⊥-elim (⊎-inj ( trans (sym (≋⇒≡ x (inj₁ tt))) ( trans (lemma0 c (inj₁ tt)) a ) ) ); {inj₁ tt} {inj₂ tt} (hm c (suc zero , x) _ _) → trans⇔ idl◎l (trans⇔ (2! x) idl◎r) ; {inj₁ tt} {inj₂ tt} (hm c (suc (suc ()), _) _ _); {inj₂ tt} {inj₁ tt} (hm c (zero , x) a b) → ⊥-elim (⊎-inj ( trans (sym a) ( trans (sym (lemma0 c (inj₂ tt))) (≋⇒≡ x (inj₂ tt)) ) ) ); {inj₂ tt} {inj₁ tt} (hm c (suc (suc ()), _) _ _); {inj₂ tt} {inj₂ tt} (hm c (zero , x) _ _) → trans⇔ idl◎l (trans⇔ idr◎r (id⇔ ⊡ (2! x))); {inj₂ tt} {inj₁ tt} (hm c (suc zero , x) _ _) → trans⇔ idl◎l (trans⇔ linv◎r (id⇔ ⊡ (2! x))); {inj₂ tt} {inj₂ tt} (hm c (suc zero , x) a b) → ⊥-elim (⊎-inj ( trans (sym (≋⇒≡ x (inj₂ tt))) ( trans (lemma0 c (inj₂ tt)) a) ) ) ; {inj₂ tt} {inj₂ tt} (hm c (suc (suc ()), _) _ _) } } ; F⇐G = record { η = λ { (inj₁ a) → hm id⟷ (zero , id⇔) refl refl; (inj₂ b) → hm swap₊ ((suc zero , id⇔)) refl refl } ; commute = λ { {inj₁ tt} {inj₁ tt} (hm a (zero , e) c d) → e ⊡ id⇔ ; {inj₁ tt} {inj₂ tt} (hm a (zero , e) c d) → {!!} ; {inj₂ tt} {inj₁ tt} (hm a (zero , e) c d) → {!!} ; {inj₂ tt} {inj₂ tt} (hm a (zero , e) c d) → trans⇔ (e ⊡ id⇔) (trans⇔ idl◎l idr◎r) ; {inj₁ tt} {inj₁ tt} (hm a (suc zero , e) c d) → {!!} ; {inj₁ tt} {inj₂ tt} (hm a (suc zero , e) c d) → {!!} ; {inj₂ tt} {inj₁ tt} (hm a (suc zero , e) c d) → {!!} ; {inj₂ tt} {inj₂ tt} (hm a (suc zero , e) c d) → {!!} ; (hm a (suc (suc ()) , _) _ _) } } ; iso = λ { (inj₁ tt) → record { isoˡ = idl◎l ; isoʳ = idl◎l }; (inj₂ tt) → record { isoˡ = linv◎l ; isoʳ = linv◎l } } } ; G∘F≅id = record { F⇒G = record { η = λ {tt → hm id⟷ (zero , id⇔) refl refl} ; commute = λ { {tt} {tt} (hm eq (zero , e) _ _) → id⇔ ⊡ (2! e) ; {tt} {tt} (hm eq (suc () , _) _ _) } } ; F⇐G = record { η = λ {tt → hm id⟷ (zero , id⇔) refl refl} ; commute = λ { {tt} {tt} (hm c (zero , e) _ _) → e ⊡ id⇔ ; {tt} {tt} (hm c (suc () , _) _ _) } } ; iso = λ {tt → record { isoˡ = linv◎l ; isoʳ = linv◎l } } } } } -- And so 1T′ is equivalent to 1T. This can be interpreted to mean -- that swap₊ (perhaps more precisely, id⟷ ∷ swap₊ ∷ [] ) is the -- representation of a 'negative type'. --------------- -- Cardinality function card : Typ → ℤ card (typ carr len _ _ _ _) = (+ size carr) - (+ len) -- check card-1T : card 1T ≡ + 1 card-1T = refl card-1T′ : card 1T′ ≡ + 1 card-1T′ = refl -------------- -- Conjecture... -- to make this work, we're going to postulate another loop -- and that it is idempotent: postulate loop : ZERO ⟷ ZERO idemp : loop ◎ loop ⇔ loop private cc : Fin 2 → Fin 2 → Fin 2 cc zero zero = zero cc zero (suc zero) = suc zero cc (suc zero) zero = suc zero cc (suc zero) (suc zero) = suc zero cc (suc (suc ())) _ cc _ (suc (suc ())) two-loops : Vec (ZERO ⟷ ZERO) 2 two-loops = id⟷ ∷ loop ∷ [] tl-coh : ∀ (i j : Fin 2) → ((two-loops !! i) ◎ (two-loops !! j) ⇔ (two-loops !! (cc j i))) tl-coh zero zero = idl◎l tl-coh zero (suc zero) = idl◎l tl-coh (suc zero) zero = idr◎l tl-coh (suc zero) (suc zero) = {!idemp!} tl-coh (suc (suc ())) _ tl-coh _ (suc (suc ())) -1T : Typ -1T = typ ZERO 1 two-loops id⇔ cc tl-coh card--1T : card -1T ≡ -[1+ 0 ] -- indeed -1 ... card--1T = refl {-- Here is my current thinking: * A type is a package of: - a carrier (that comes with the trivial automorphism) - a collection of non-trivial automorphisms that have a groupoid structure Let’s denote this package by ‘R A (Auto A)' * The collection of non-trivial automorphisms could very well be missing (i.e., empty) and we then recover plain sets like Bool etc. * Now here is the interesting bit: the carrier itself could be missing, i.e., a parameter. In that case we get something like: A -> R A (Auto A) That thing could be treated as outside the universe of types but we are proposing to enlarge the universe of type to also include it as a fractional type. Of course we need a way to combine such a fractional type with a carrier to get a regular type so we need another operation _[_] to do the instantiation. * So to revise, a type is: T ::= R A (Auto A) | /\ A . T | T[A] To make sure this behaves like fractional types, we want /\ A. T and T[A] to behave like a product. It is a product of course but a dependent one. --} -- Parameterized type -- Frac supposed to 1/t -- instantiate Frac with u to get u/t -- make sure t/t is 1 -- define eta and epsilon and check axioms {-- Syntax of types --} Auto : (u : U) → Set Auto u = Σ[ n ∈ ℕ ] (Vec (u ⟷ u) n) trivA : (u : U) → Auto u trivA u = (1 , id⟷ ∷ []) data T : (u₁ : U) → {u₂ : U} → Auto u₂ → Set where UT : (u : U) → T u (trivA u) -- regular sets FT : (u₁ u₂ : U) → (auto₂ : Auto u₂) → T u₁ auto₂ -- Regular sets ZT : T ZERO (trivA ZERO) ZT = UT ZERO OT : T ONE (trivA ONE) OT = UT ONE -- one third 2U : U 2U = PLUS ONE ONE 3U : U 3U = PLUS ONE (PLUS ONE ONE) 3T : T 3U (trivA 3U) 3T = UT 3U -- could add the remaining two but these are sufficient I think all3A : Auto 3U all3A = (4 , id⟷ ∷ (id⟷ ⊕ swap₊) ∷ (assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊) ∷ ((id⟷ ⊕ swap₊) ◎ (assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊) ◎ (id⟷ ⊕ swap₊)) ∷ []) 1/3T : T ONE all3A 1/3T = FT ONE 3U all3A -- notice that a/b + c/b = (a+c) / b -- So 1/3T + 1/3T is 2/3T : T 2U all3A 2/3T = FT 2U 3U all3A -- one more 3/3T : T 3U all3A 3/3T = FT 3U 3U all3A -- Now eta applied to 3/3T should match the carrier with the autos and produce the plain OT
{ "alphanum_fraction": 0.5250707325, "avg_line_length": 29.7985948478, "ext": "agda", "hexsha": "dff214e975cae5f935d7c19b2ac44f99536b2965", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/2DTypes.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/2DTypes.agda", "max_line_length": 95, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/2DTypes.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 5054, "size": 12724 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category -- Defines the following properties of a Category: -- 1. BinaryProducts -- for when a Category has all Binary Products -- 2. Cartesian -- a Cartesian category is a category with all products module Categories.Category.Cartesian {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Data.Product using (Σ; _,_; uncurry) open Category 𝒞 open HomReasoning open import Categories.Object.Terminal 𝒞 open import Categories.Object.Product 𝒞 open import Categories.Morphism 𝒞 open import Categories.Morphism.Reasoning 𝒞 open import Categories.Category.Monoidal import Categories.Category.Monoidal.Symmetric as Sym open import Categories.Functor renaming (id to idF) open import Categories.Functor.Bifunctor open import Categories.NaturalTransformation using (ntHelper) open import Categories.NaturalTransformation.NaturalIsomorphism hiding (refl; sym; trans) private variable A B C D X Y Z : Obj f f′ g g′ h i : A ⇒ B record BinaryProducts : Set (levelOfTerm 𝒞) where infixr 7 _×_ infixr 8 _⁂_ infix 11 ⟨_,_⟩ field product : ∀ {A B} → Product A B module product {A} {B} = Product (product {A} {B}) _×_ : Obj → Obj → Obj A × B = Product.A×B (product {A} {B}) ×-comm : A × B ≅ B × A ×-comm = Commutative product product ×-assoc : X × Y × Z ≅ (X × Y) × Z ×-assoc = Associative product product product product open product hiding (⟨_,_⟩; ∘-distribʳ-⟨⟩) public -- define it like this instead of reexporting to redefine fixity ⟨_,_⟩ : X ⇒ A → X ⇒ B → X ⇒ A × B ⟨_,_⟩ = Product.⟨_,_⟩ product _⁂_ : A ⇒ B → C ⇒ D → A × C ⇒ B × D f ⁂ g = [ product ⇒ product ] f × g assocˡ : (A × B) × C ⇒ A × B × C assocˡ = _≅_.to ×-assoc assocʳ : A × B × C ⇒ (A × B) × C assocʳ = _≅_.from ×-assoc assocʳ∘assocˡ : assocʳ {A}{B}{C} ∘ assocˡ {A}{B}{C} ≈ id assocʳ∘assocˡ = Iso.isoʳ (_≅_.iso ×-assoc) assocˡ∘assocʳ : assocˡ {A}{B}{C} ∘ assocʳ {A}{B}{C} ≈ id assocˡ∘assocʳ = Iso.isoˡ (_≅_.iso ×-assoc) ⟨⟩-congʳ : f ≈ f′ → ⟨ f , g ⟩ ≈ ⟨ f′ , g ⟩ ⟨⟩-congʳ pf = ⟨⟩-cong₂ pf refl ⟨⟩-congˡ : g ≈ g′ → ⟨ f , g ⟩ ≈ ⟨ f , g′ ⟩ ⟨⟩-congˡ pf = ⟨⟩-cong₂ refl pf swap : A × B ⇒ B × A swap = ⟨ π₂ , π₁ ⟩ -- TODO: this is probably harder to use than necessary because of this definition. Maybe make a version -- that doesn't have an explicit id in it, too? first : A ⇒ B → A × C ⇒ B × C first f = f ⁂ id second : C ⇒ D → A × C ⇒ A × D second g = id ⁂ g -- Just to make this more obvious π₁∘⁂ : π₁ ∘ (f ⁂ g) ≈ f ∘ π₁ π₁∘⁂ {f = f} {g} = project₁ π₂∘⁂ : π₂ ∘ (f ⁂ g) ≈ g ∘ π₂ π₂∘⁂ {f = f} {g} = project₂ ⁂-cong₂ : f ≈ g → h ≈ i → f ⁂ h ≈ g ⁂ i ⁂-cong₂ = [ product ⇒ product ]×-cong₂ ⁂∘⟨⟩ : (f ⁂ g) ∘ ⟨ f′ , g′ ⟩ ≈ ⟨ f ∘ f′ , g ∘ g′ ⟩ ⁂∘⟨⟩ = [ product ⇒ product ]×∘⟨⟩ first∘⟨⟩ : first f ∘ ⟨ f′ , g′ ⟩ ≈ ⟨ f ∘ f′ , g′ ⟩ first∘⟨⟩ = [ product ⇒ product ]×id∘⟨⟩ second∘⟨⟩ : second g ∘ ⟨ f′ , g′ ⟩ ≈ ⟨ f′ , g ∘ g′ ⟩ second∘⟨⟩ = [ product ⇒ product ]id×∘⟨⟩ ⁂∘⁂ : (f ⁂ g) ∘ (f′ ⁂ g′) ≈ (f ∘ f′) ⁂ (g ∘ g′) ⁂∘⁂ = [ product ⇒ product ⇒ product ]×∘× ⟨⟩∘ : ⟨ f , g ⟩ ∘ h ≈ ⟨ f ∘ h , g ∘ h ⟩ ⟨⟩∘ = [ product ]⟨⟩∘ first∘first : ∀ {C} → first {C = C} f ∘ first g ≈ first (f ∘ g) first∘first = [ product ⇒ product ⇒ product ]×id∘×id second∘second : ∀ {A} → second {A = A} f ∘ second g ≈ second (f ∘ g) second∘second = [ product ⇒ product ⇒ product ]id×∘id× first↔second : first f ∘ second g ≈ second g ∘ first f first↔second = [ product ⇒ product , product ⇒ product ]first↔second firstid : ∀ {f : A ⇒ A} (g : A ⇒ C) → first {C = C} f ≈ id → f ≈ id firstid {f = f} g eq = begin f ≈˘⟨ elimʳ project₁ ⟩ f ∘ π₁ ∘ ⟨ id , g ⟩ ≈⟨ pullˡ fπ₁≈π₁ ⟩ π₁ ∘ ⟨ id , g ⟩ ≈⟨ project₁ ⟩ id ∎ where fπ₁≈π₁ = begin f ∘ π₁ ≈˘⟨ project₁ ⟩ π₁ ∘ first f ≈⟨ refl⟩∘⟨ eq ⟩ π₁ ∘ id ≈⟨ identityʳ ⟩ π₁ ∎ swap∘⟨⟩ : swap ∘ ⟨ f , g ⟩ ≈ ⟨ g , f ⟩ swap∘⟨⟩ {f = f} {g = g} = begin ⟨ π₂ , π₁ ⟩ ∘ ⟨ f , g ⟩ ≈⟨ ⟨⟩∘ ⟩ ⟨ π₂ ∘ ⟨ f , g ⟩ , π₁ ∘ ⟨ f , g ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ project₂ project₁ ⟩ ⟨ g , f ⟩ ∎ swap∘⁂ : swap ∘ (f ⁂ g) ≈ (g ⁂ f) ∘ swap swap∘⁂ {f = f} {g = g} = begin swap ∘ (f ⁂ g) ≈⟨ swap∘⟨⟩ ⟩ ⟨ g ∘ π₂ , f ∘ π₁ ⟩ ≈⟨ sym ⁂∘⟨⟩ ⟩ (g ⁂ f) ∘ swap ∎ swap∘swap : (swap {A}{B}) ∘ (swap {B}{A}) ≈ id swap∘swap = trans swap∘⟨⟩ η assocʳ∘⟨⟩ : assocʳ ∘ ⟨ f , ⟨ g , h ⟩ ⟩ ≈ ⟨ ⟨ f , g ⟩ , h ⟩ assocʳ∘⟨⟩ {f = f} {g = g} {h = h} = begin assocʳ ∘ ⟨ f , ⟨ g , h ⟩ ⟩ ≈⟨ ⟨⟩∘ ⟩ ⟨ ⟨ π₁ , π₁ ∘ π₂ ⟩ ∘ ⟨ f , ⟨ g , h ⟩ ⟩ , (π₂ ∘ π₂) ∘ ⟨ f , ⟨ g , h ⟩ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ ⟨⟩∘ (pullʳ project₂) ⟩ ⟨ ⟨ π₁ ∘ ⟨ f , ⟨ g , h ⟩ ⟩ , (π₁ ∘ π₂) ∘ ⟨ f , ⟨ g , h ⟩ ⟩ ⟩ , π₂ ∘ ⟨ g , h ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ (⟨⟩-cong₂ project₁ (trans (pullʳ project₂) project₁)) project₂ ⟩ ⟨ ⟨ f , g ⟩ , h ⟩ ∎ assocˡ∘⟨⟩ : assocˡ ∘ ⟨ ⟨ f , g ⟩ , h ⟩ ≈ ⟨ f , ⟨ g , h ⟩ ⟩ assocˡ∘⟨⟩ {f = f} {g = g} {h = h} = begin assocˡ ∘ ⟨ ⟨ f , g ⟩ , h ⟩ ≈⟨ sym (refl ⟩∘⟨ assocʳ∘⟨⟩) ⟩ assocˡ ∘ assocʳ ∘ ⟨ f , ⟨ g , h ⟩ ⟩ ≈⟨ cancelˡ assocˡ∘assocʳ ⟩ ⟨ f , ⟨ g , h ⟩ ⟩ ∎ assocʳ∘⁂ : assocʳ ∘ (f ⁂ (g ⁂ h)) ≈ ((f ⁂ g) ⁂ h) ∘ assocʳ assocʳ∘⁂ {f = f} {g = g} {h = h} = begin assocʳ ∘ (f ⁂ (g ⁂ h)) ≈⟨ refl⟩∘⟨ ⟨⟩-congˡ ⟨⟩∘ ⟩ assocʳ ∘ ⟨ f ∘ π₁ , ⟨ (g ∘ π₁) ∘ π₂ , (h ∘ π₂) ∘ π₂ ⟩ ⟩ ≈⟨ assocʳ∘⟨⟩ ⟩ ⟨ ⟨ f ∘ π₁ , (g ∘ π₁) ∘ π₂ ⟩ , (h ∘ π₂) ∘ π₂ ⟩ ≈⟨ ⟨⟩-cong₂ (⟨⟩-congˡ assoc) assoc ⟩ ⟨ ⟨ f ∘ π₁ , g ∘ π₁ ∘ π₂ ⟩ , h ∘ π₂ ∘ π₂ ⟩ ≈˘⟨ ⟨⟩-congʳ ⁂∘⟨⟩ ⟩ ⟨ (f ⁂ g) ∘ ⟨ π₁ , π₁ ∘ π₂ ⟩ , h ∘ π₂ ∘ π₂ ⟩ ≈˘⟨ ⁂∘⟨⟩ ⟩ ((f ⁂ g) ⁂ h) ∘ assocʳ ∎ assocˡ∘⁂ : assocˡ ∘ ((f ⁂ g) ⁂ h) ≈ (f ⁂ (g ⁂ h)) ∘ assocˡ assocˡ∘⁂ {f = f} {g = g} {h = h} = begin assocˡ ∘ ((f ⁂ g) ⁂ h) ≈⟨ refl⟩∘⟨ ⟨⟩-congʳ ⟨⟩∘ ⟩ assocˡ ∘ ⟨ ⟨ (f ∘ π₁) ∘ π₁ , (g ∘ π₂) ∘ π₁ ⟩ , h ∘ π₂ ⟩ ≈⟨ assocˡ∘⟨⟩ ⟩ ⟨ (f ∘ π₁) ∘ π₁ , ⟨ (g ∘ π₂) ∘ π₁ , h ∘ π₂ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ assoc (⟨⟩-congʳ assoc) ⟩ ⟨ f ∘ π₁ ∘ π₁ , ⟨ g ∘ π₂ ∘ π₁ , h ∘ π₂ ⟩ ⟩ ≈˘⟨ ⟨⟩-congˡ ⁂∘⟨⟩ ⟩ ⟨ f ∘ π₁ ∘ π₁ , (g ⁂ h) ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩ ⟩ ≈˘⟨ ⁂∘⟨⟩ ⟩ (f ⁂ (g ⁂ h)) ∘ assocˡ ∎ -×- : Bifunctor 𝒞 𝒞 𝒞 -×- = record { F₀ = uncurry _×_ ; F₁ = uncurry _⁂_ ; identity = id×id product ; homomorphism = sym ⁂∘⁂ ; F-resp-≈ = uncurry [ product ⇒ product ]×-cong₂ } -×_ : Obj → Functor 𝒞 𝒞 -×_ = appʳ -×- _×- : Obj → Functor 𝒞 𝒞 _×- = appˡ -×- -- Cartesian monoidal category record Cartesian : Set (levelOfTerm 𝒞) where field terminal : Terminal products : BinaryProducts module terminal = Terminal terminal module products = BinaryProducts products open terminal public open products public ⊤×A≅A : ⊤ × A ≅ A ⊤×A≅A = record { from = π₂ ; to = ⟨ ! , id ⟩ ; iso = record { isoˡ = begin ⟨ ! , id ⟩ ∘ π₂ ≈˘⟨ unique !-unique₂ (cancelˡ project₂) ⟩ ⟨ π₁ , π₂ ⟩ ≈⟨ η ⟩ id ∎ ; isoʳ = project₂ } } A×⊤≅A : A × ⊤ ≅ A A×⊤≅A = record { from = π₁ ; to = ⟨ id , ! ⟩ ; iso = record { isoˡ = begin ⟨ id , ! ⟩ ∘ π₁ ≈˘⟨ unique (cancelˡ project₁) !-unique₂ ⟩ ⟨ π₁ , π₂ ⟩ ≈⟨ η ⟩ id ∎ ; isoʳ = project₁ } } ⊤×--id : NaturalIsomorphism (⊤ ×-) idF ⊤×--id = record { F⇒G = ntHelper record { η = λ _ → π₂ ; commute = λ _ → project₂ } ; F⇐G = ntHelper record { η = λ _ → ⟨ ! , id ⟩ ; commute = λ f → begin ⟨ ! , id ⟩ ∘ f ≈⟨ ⟨⟩∘ ⟩ ⟨ ! ∘ f , id ∘ f ⟩ ≈⟨ ⟨⟩-cong₂ (sym (!-unique _)) identityˡ ⟩ ⟨ ! , f ⟩ ≈˘⟨ ⟨⟩-cong₂ identityˡ identityʳ ⟩ ⟨ id ∘ ! , f ∘ id ⟩ ≈˘⟨ ⟨⟩-cong₂ (pullʳ project₁) (pullʳ project₂) ⟩ ⟨ (id ∘ π₁) ∘ ⟨ ! , id ⟩ , (f ∘ π₂) ∘ ⟨ ! , id ⟩ ⟩ ≈˘⟨ ⟨⟩∘ ⟩ ⟨ id ∘ π₁ , f ∘ π₂ ⟩ ∘ ⟨ ! , id ⟩ ∎ } ; iso = λ _ → _≅_.iso ⊤×A≅A } -×⊤-id : NaturalIsomorphism (-× ⊤) idF -×⊤-id = record { F⇒G = ntHelper record { η = λ _ → π₁ ; commute = λ _ → project₁ } ; F⇐G = ntHelper record { η = λ _ → ⟨ id , ! ⟩ ; commute = λ f → begin ⟨ id , ! ⟩ ∘ f ≈⟨ ⟨⟩∘ ⟩ ⟨ id ∘ f , ! ∘ f ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ (sym (!-unique _)) ⟩ ⟨ f , ! ⟩ ≈˘⟨ ⟨⟩-cong₂ identityʳ identityˡ ⟩ ⟨ f ∘ id , id ∘ ! ⟩ ≈˘⟨ ⟨⟩-cong₂ (pullʳ project₁) (pullʳ project₂) ⟩ ⟨ (f ∘ π₁) ∘ ⟨ id , ! ⟩ , (id ∘ π₂) ∘ ⟨ id , ! ⟩ ⟩ ≈˘⟨ ⟨⟩∘ ⟩ ⟨ f ∘ π₁ , id ∘ π₂ ⟩ ∘ ⟨ id , ! ⟩ ∎ } ; iso = λ _ → _≅_.iso A×⊤≅A } monoidal : Monoidal 𝒞 monoidal = record { ⊗ = -×- ; unit = ⊤ ; unitorˡ = ⊤×A≅A ; unitorʳ = A×⊤≅A ; associator = ≅.sym ×-assoc ; unitorˡ-commute-from = project₂ ; unitorˡ-commute-to = let open NaturalIsomorphism ⊤×--id in ⇐.commute _ ; unitorʳ-commute-from = project₁ ; unitorʳ-commute-to = let open NaturalIsomorphism -×⊤-id in ⇐.commute _ ; assoc-commute-from = assocˡ∘⁂ ; assoc-commute-to = assocʳ∘⁂ ; triangle = begin (id ⁂ π₂) ∘ assocˡ ≈⟨ ⁂∘⟨⟩ ⟩ ⟨ id ∘ π₁ ∘ π₁ , π₂ ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ (pullˡ identityˡ) (project₂ ○ (⟺ identityˡ)) ⟩ π₁ ⁂ id ∎ ; pentagon = begin (id ⁂ assocˡ) ∘ assocˡ ∘ (assocˡ ⁂ id) ≈⟨ pullˡ [ product ⇒ product ]id×∘⟨⟩ ⟩ ⟨ π₁ ∘ π₁ , assocˡ ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩ ⟩ ∘ (assocˡ ⁂ id) ≈⟨ ⟨⟩∘ ⟩ ⟨ (π₁ ∘ π₁) ∘ (assocˡ ⁂ id) , (assocˡ ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩) ∘ (assocˡ ⁂ id) ⟩ ≈⟨ ⟨⟩-cong₂ (pullʳ project₁) (pullʳ ⟨⟩∘) ⟩ ⟨ π₁ ∘ assocˡ ∘ π₁ , assocˡ ∘ ⟨ (π₂ ∘ π₁) ∘ (assocˡ ⁂ id) , π₂ ∘ (assocˡ ⁂ id) ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ (pullˡ project₁) (∘-resp-≈ʳ (⟨⟩-cong₂ (pullʳ project₁) project₂)) ⟩ ⟨ (π₁ ∘ π₁) ∘ π₁ , assocˡ ∘ ⟨ π₂ ∘ assocˡ ∘ π₁ , id ∘ π₂ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ assoc (∘-resp-≈ʳ (⟨⟩-cong₂ (pullˡ project₂) identityˡ)) ⟩ ⟨ π₁ ∘ π₁ ∘ π₁ , assocˡ ∘ ⟨ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , π₂ ⟩ ⟩ ≈⟨ ⟨⟩-congˡ ⟨⟩∘ ⟩ ⟨ π₁ ∘ π₁ ∘ π₁ , ⟨ (π₁ ∘ π₁) ∘ ⟨ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , π₂ ⟩ , ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ ⟨ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , π₂ ⟩ ⟩ ⟩ ≈⟨ ⟨⟩-congˡ (⟨⟩-cong₂ (pullʳ project₁) ⟨⟩∘) ⟩ ⟨ π₁ ∘ π₁ ∘ π₁ , ⟨ π₁ ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , ⟨ (π₂ ∘ π₁) ∘ ⟨ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , π₂ ⟩ , π₂ ∘ ⟨ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , π₂ ⟩ ⟩ ⟩ ⟩ ≈⟨ ⟨⟩-congˡ (⟨⟩-cong₂ (pullˡ project₁) (⟨⟩-cong₂ (pullʳ project₁) project₂)) ⟩ ⟨ π₁ ∘ π₁ ∘ π₁ , ⟨ (π₂ ∘ π₁) ∘ π₁ , ⟨ π₂ ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ π₁ , π₂ ⟩ ⟩ ⟩ ≈⟨ ⟨⟩-congˡ (⟨⟩-cong₂ assoc (⟨⟩-congʳ (pullˡ project₂))) ⟩ ⟨ π₁ ∘ π₁ ∘ π₁ , ⟨ π₂ ∘ π₁ ∘ π₁ , ⟨ π₂ ∘ π₁ , π₂ ⟩ ⟩ ⟩ ≈˘⟨ ⟨⟩-congˡ (⟨⟩-cong₂ (pullʳ project₁) project₂) ⟩ ⟨ π₁ ∘ π₁ ∘ π₁ , ⟨ (π₂ ∘ π₁) ∘ assocˡ , π₂ ∘ assocˡ ⟩ ⟩ ≈˘⟨ ⟨⟩-cong₂ (pullʳ project₁) ⟨⟩∘ ⟩ ⟨ (π₁ ∘ π₁) ∘ assocˡ , ⟨ π₂ ∘ π₁ , π₂ ⟩ ∘ assocˡ ⟩ ≈˘⟨ ⟨⟩∘ ⟩ assocˡ ∘ assocˡ ∎ } module monoidal = Monoidal monoidal open monoidal using (_⊗₁_) open Sym monoidal symmetric : Symmetric symmetric = symmetricHelper record { braiding = record { F⇒G = ntHelper record { η = λ _ → swap ; commute = λ _ → swap∘⁂ } ; F⇐G = ntHelper record { η = λ _ → swap ; commute = λ _ → swap∘⁂ } ; iso = λ _ → record { isoˡ = swap∘swap ; isoʳ = swap∘swap } } ; commutative = swap∘swap ; hexagon = begin id ⊗₁ swap ∘ assocˡ ∘ swap ⊗₁ id ≈⟨ refl⟩∘⟨ refl⟩∘⟨ ⟨⟩-congʳ ⟨⟩∘ ⟩ id ⊗₁ swap ∘ assocˡ ∘ ⟨ ⟨ π₂ ∘ π₁ , π₁ ∘ π₁ ⟩ , id ∘ π₂ ⟩ ≈⟨ refl⟩∘⟨ assocˡ∘⟨⟩ ⟩ id ⊗₁ swap ∘ ⟨ π₂ ∘ π₁ , ⟨ π₁ ∘ π₁ , id ∘ π₂ ⟩ ⟩ ≈⟨ ⁂∘⟨⟩ ⟩ ⟨ id ∘ π₂ ∘ π₁ , swap ∘ ⟨ π₁ ∘ π₁ , id ∘ π₂ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ swap∘⟨⟩ ⟩ ⟨ π₂ ∘ π₁ , ⟨ id ∘ π₂ , π₁ ∘ π₁ ⟩ ⟩ ≈⟨ ⟨⟩-congˡ (⟨⟩-congʳ identityˡ) ⟩ ⟨ π₂ ∘ π₁ , ⟨ π₂ , π₁ ∘ π₁ ⟩ ⟩ ≈˘⟨ assocˡ∘⟨⟩ ⟩ assocˡ ∘ ⟨ ⟨ π₂ ∘ π₁ , π₂ ⟩ , π₁ ∘ π₁ ⟩ ≈˘⟨ refl ⟩∘⟨ swap∘⟨⟩ ⟩ assocˡ ∘ swap ∘ assocˡ ∎ } module symmetric = Symmetric symmetric open symmetric public
{ "alphanum_fraction": 0.4189680514, "avg_line_length": 34.2891246684, "ext": "agda", "hexsha": "0ec51501b863b3df2c4d4af0c2b76de06e6aab65", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Taneb/agda-categories", "max_forks_repo_path": "Categories/Category/Cartesian.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Taneb/agda-categories", "max_issues_repo_path": "Categories/Category/Cartesian.agda", "max_line_length": 142, "max_stars_count": null, "max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Taneb/agda-categories", "max_stars_repo_path": "Categories/Category/Cartesian.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6196, "size": 12927 }
open import Agda.Builtin.List open import Agda.Builtin.Char foo : Char → List Char foo c = c ∷ [] case-split-test : List Char → List Char case-split-test ('-' ∷ ls) with (foo '+') ... | foo-ls = {!foo-ls!} case-split-test ls = ls -- WAS: case splitting on foo-ls produces: -- case-split-test (.'-' ∷ ls) | [] = ? -- case-split-test (.'-' ∷ ls) | x ∷ foo-ls = ? -- SHOULD: not put dots in front of literal patterns: -- case-split-test ('-' ∷ ls) | [] = {!!} -- case-split-test ('-' ∷ ls) | x ∷ foo-ls = {!!}
{ "alphanum_fraction": 0.5617760618, "avg_line_length": 28.7777777778, "ext": "agda", "hexsha": "f73e05e9993d9e41128174e7d3f7231e4e8574e5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z", "max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "hborum/agda", "max_forks_repo_path": "test/interaction/Issue2872.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "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": "hborum/agda", "max_issues_repo_path": "test/interaction/Issue2872.agda", "max_line_length": 53, "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/interaction/Issue2872.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": 170, "size": 518 }
-- Jesper, Andreas, 2018-10-29, issue #3332 -- -- WAS: With-inlining failed in termination checker -- due to a DontCare protecting the clause bodies -- (introduced by Prop). {-# OPTIONS --prop #-} data _≡_ {A : Set} (a : A) : A → Prop where refl : a ≡ a {-# BUILTIN EQUALITY _≡_ #-} data List (A : Set) : Set where [] : List A _∷_ : A → List A → List A _++_ : {A : Set} → List A → List A → List A [] ++ l = l (x ∷ xs) ++ l = x ∷ (xs ++ l) test : {A : Set} (l : List A) → (l ++ []) ≡ l test [] = refl test (x ∷ xs) rewrite test xs = refl
{ "alphanum_fraction": 0.545620438, "avg_line_length": 22.8333333333, "ext": "agda", "hexsha": "bb950444708b50f01475237efebf245e590c3a2f", "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/Issue3332-rewrite.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/Issue3332-rewrite.agda", "max_line_length": 51, "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/Issue3332-rewrite.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": 205, "size": 548 }
module UniDB.Morph.Sum where open import UniDB.Spec -------------------------------------------------------------------------------- data Sum (Ξ Ζ : MOR) (γ₁ γ₂ : Dom) : Set where inl : Ξ γ₁ γ₂ → Sum Ξ Ζ γ₁ γ₂ inr : Ζ γ₁ γ₂ → Sum Ξ Ζ γ₁ γ₂ instance iUpSum : {Ξ Ζ : MOR} {{upΞ : Up Ξ}} {{upΖ : Up Ζ}} → Up (Sum Ξ Ζ) _↑₁ {{iUpSum}} (inl ξ) = inl (ξ ↑₁) _↑₁ {{iUpSum}} (inr ζ) = inr (ζ ↑₁) _↑_ {{iUpSum}} ξ 0 = ξ _↑_ {{iUpSum}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁ ↑-zero {{iUpSum}} ξ = refl ↑-suc {{iUpSum}} ξ δ⁺ = refl iLkSum : {T : STX} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} → Lk T (Sum Ξ Ζ) lk {{iLkSum {T} {Ξ} {Ζ}}} (inl ξ) i = lk {T} {Ξ} ξ i lk {{iLkSum {T} {Ξ} {Ζ}}} (inr ζ) i = lk {T} {Ζ} ζ i iLkUpSum : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} → LkUp T (Sum Ξ Ζ) lk-↑₁-zero {{iLkUpSum {T} {Ξ} {Ζ}}} (inl ξ) = lk-↑₁-zero {T} {Ξ} ξ lk-↑₁-zero {{iLkUpSum {T} {Ξ} {Ζ}}} (inr ζ) = lk-↑₁-zero {T} {Ζ} ζ lk-↑₁-suc {{iLkUpSum {T} {Ξ} {Ζ}}} (inl ξ) = lk-↑₁-suc {T} {Ξ} ξ lk-↑₁-suc {{iLkUpSum {T} {Ξ} {Ζ}}} (inr ζ) = lk-↑₁-suc {T} {Ζ} ζ module _ (Ξ Ζ : MOR) {{upΞ : Up Ξ}} {{upΖ : Up Ζ}} where inl-↑ : {γ₁ γ₂ : Dom} (ξ : Ξ γ₁ γ₂) (δ : Dom) → inl {Ξ} {Ζ} ξ ↑ δ ≡ inl (ξ ↑ δ) inl-↑ ξ zero rewrite ↑-zero ξ = refl inl-↑ ξ (suc δ) rewrite inl-↑ ξ δ | ↑-suc ξ δ = refl inr-↑ : {γ₁ γ₂ : Dom} (ζ : Ζ γ₁ γ₂) (δ : Dom) → inr {Ξ} {Ζ} ζ ↑ δ ≡ inr (ζ ↑ δ) inr-↑ ζ zero rewrite ↑-zero ζ = refl inr-↑ ζ (suc δ) rewrite inr-↑ ζ δ | ↑-suc ζ δ = refl --------------------------------------------------------------------------------
{ "alphanum_fraction": 0.4141812043, "avg_line_length": 32.9074074074, "ext": "agda", "hexsha": "470c62983105841313f027e7908e7d73b6f499a5", "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": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_path": "UniDB/Morph/Sum.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": "skeuchel/unidb-agda", "max_issues_repo_path": "UniDB/Morph/Sum.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_path": "UniDB/Morph/Sum.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 948, "size": 1777 }
------------------------------------------------------------------------ -- The Agda standard library -- -- An example of how Algebra.CommutativeMonoidSolver can be used ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Algebra.Solver.CommutativeMonoid.Example where open import Relation.Binary.PropositionalEquality using (_≡_) open import Data.Bool.Base using (_∨_) open import Data.Bool.Properties using (∨-commutativeMonoid) open import Data.Fin using (zero; suc) open import Data.Vec using ([]; _∷_) open import Algebra.Solver.CommutativeMonoid ∨-commutativeMonoid test : ∀ x y z → (x ∨ y) ∨ (x ∨ z) ≡ (z ∨ y) ∨ (x ∨ x) test a b c = let _∨_ = _⊕_ in prove 3 ((x ∨ y) ∨ (x ∨ z)) ((z ∨ y) ∨ (x ∨ x)) (a ∷ b ∷ c ∷ []) where x = var zero y = var (suc zero) z = var (suc (suc zero))
{ "alphanum_fraction": 0.5421965318, "avg_line_length": 30.8928571429, "ext": "agda", "hexsha": "99ea0fb4021f4d63dc04d90d8cbc5ef6362091d6", "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/Algebra/Solver/CommutativeMonoid/Example.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/Algebra/Solver/CommutativeMonoid/Example.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/Algebra/Solver/CommutativeMonoid/Example.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 259, "size": 865 }
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-} module Cubical.Data.Nat.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Data.Nat.Base open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Sigma open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq private variable l m n : ℕ min : ℕ → ℕ → ℕ min zero m = zero min (suc n) zero = zero min (suc n) (suc m) = suc (min n m) minComm : (n m : ℕ) → min n m ≡ min m n minComm zero zero = refl minComm zero (suc m) = refl minComm (suc n) zero = refl minComm (suc n) (suc m) = cong suc (minComm n m) max : ℕ → ℕ → ℕ max zero m = m max (suc n) zero = suc n max (suc n) (suc m) = suc (max n m) maxComm : (n m : ℕ) → max n m ≡ max m n maxComm zero zero = refl maxComm zero (suc m) = refl maxComm (suc n) zero = refl maxComm (suc n) (suc m) = cong suc (maxComm n m) znots : ¬ (0 ≡ suc n) znots eq = subst (caseNat ℕ ⊥) eq 0 snotz : ¬ (suc n ≡ 0) snotz eq = subst (caseNat ⊥ ℕ) eq 0 injSuc : suc m ≡ suc n → m ≡ n injSuc p = cong predℕ p discreteℕ : Discrete ℕ discreteℕ zero zero = yes refl discreteℕ zero (suc n) = no znots discreteℕ (suc m) zero = no snotz discreteℕ (suc m) (suc n) with discreteℕ m n ... | yes p = yes (cong suc p) ... | no p = no (λ x → p (injSuc x)) isSetℕ : isSet ℕ isSetℕ = Discrete→isSet discreteℕ -- Arithmetic facts about predℕ suc-predℕ : ∀ n → ¬ n ≡ 0 → n ≡ suc (predℕ n) suc-predℕ zero p = ⊥.rec (p refl) suc-predℕ (suc n) p = refl -- Arithmetic facts about + +-zero : ∀ m → m + 0 ≡ m +-zero zero = refl +-zero (suc m) = cong suc (+-zero m) +-suc : ∀ m n → m + suc n ≡ suc (m + n) +-suc zero n = refl +-suc (suc m) n = cong suc (+-suc m n) +-comm : ∀ m n → m + n ≡ n + m +-comm m zero = +-zero m +-comm m (suc n) = (+-suc m n) ∙ (cong suc (+-comm m n)) -- Addition is associative +-assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o +-assoc zero _ _ = refl +-assoc (suc m) n o = cong suc (+-assoc m n o) inj-m+ : m + l ≡ m + n → l ≡ n inj-m+ {zero} p = p inj-m+ {suc m} p = inj-m+ (injSuc p) inj-+m : l + m ≡ n + m → l ≡ n inj-+m {l} {m} {n} p = inj-m+ ((+-comm m l) ∙ (p ∙ (+-comm n m))) m+n≡n→m≡0 : m + n ≡ n → m ≡ 0 m+n≡n→m≡0 {n = zero} = λ p → (sym (+-zero _)) ∙ p m+n≡n→m≡0 {n = suc n} p = m+n≡n→m≡0 (injSuc ((sym (+-suc _ n)) ∙ p)) m+n≡0→m≡0×n≡0 : m + n ≡ 0 → (m ≡ 0) × (n ≡ 0) m+n≡0→m≡0×n≡0 {zero} = refl ,_ m+n≡0→m≡0×n≡0 {suc m} p = ⊥.rec (snotz p) -- Arithmetic facts about · 0≡m·0 : ∀ m → 0 ≡ m · 0 0≡m·0 zero = refl 0≡m·0 (suc m) = 0≡m·0 m ·-suc : ∀ m n → m · suc n ≡ m + m · n ·-suc zero n = refl ·-suc (suc m) n = cong suc ( n + m · suc n ≡⟨ cong (n +_) (·-suc m n) ⟩ n + (m + m · n) ≡⟨ +-assoc n m (m · n) ⟩ (n + m) + m · n ≡⟨ cong (_+ m · n) (+-comm n m) ⟩ (m + n) + m · n ≡⟨ sym (+-assoc m n (m · n)) ⟩ m + (n + m · n) ∎ ) ·-comm : ∀ m n → m · n ≡ n · m ·-comm zero n = 0≡m·0 n ·-comm (suc m) n = cong (n +_) (·-comm m n) ∙ sym (·-suc n m) ·-distribʳ : ∀ m n o → (m · o) + (n · o) ≡ (m + n) · o ·-distribʳ zero _ _ = refl ·-distribʳ (suc m) n o = sym (+-assoc o (m · o) (n · o)) ∙ cong (o +_) (·-distribʳ m n o) ·-distribˡ : ∀ o m n → (o · m) + (o · n) ≡ o · (m + n) ·-distribˡ o m n = (λ i → ·-comm o m i + ·-comm o n i) ∙ ·-distribʳ m n o ∙ ·-comm (m + n) o ·-assoc : ∀ m n o → m · (n · o) ≡ (m · n) · o ·-assoc zero _ _ = refl ·-assoc (suc m) n o = cong (n · o +_) (·-assoc m n o) ∙ ·-distribʳ n (m · n) o ·-identityˡ : ∀ m → 1 · m ≡ m ·-identityˡ m = +-zero m ·-identityʳ : ∀ m → m · 1 ≡ m ·-identityʳ zero = refl ·-identityʳ (suc m) = cong suc (·-identityʳ m) 0≡n·sm→0≡n : 0 ≡ n · suc m → 0 ≡ n 0≡n·sm→0≡n {n = zero} p = refl 0≡n·sm→0≡n {n = suc n} p = ⊥.rec (znots p) inj-·sm : l · suc m ≡ n · suc m → l ≡ n inj-·sm {zero} {m} {n} p = 0≡n·sm→0≡n p inj-·sm {l} {m} {zero} p = sym (0≡n·sm→0≡n (sym p)) inj-·sm {suc l} {m} {suc n} p = cong suc (inj-·sm (inj-m+ {m = suc m} p)) inj-sm· : suc m · l ≡ suc m · n → l ≡ n inj-sm· {m} {l} {n} p = inj-·sm (·-comm l (suc m) ∙ p ∙ ·-comm (suc m) n) -- Arithmetic facts about ∸ zero∸ : ∀ n → zero ∸ n ≡ zero zero∸ zero = refl zero∸ (suc _) = refl ∸-cancelˡ : ∀ k m n → (k + m) ∸ (k + n) ≡ m ∸ n ∸-cancelˡ zero = λ _ _ → refl ∸-cancelˡ (suc k) = ∸-cancelˡ k ∸-cancelʳ : ∀ m n k → (m + k) ∸ (n + k) ≡ m ∸ n ∸-cancelʳ m n k = (λ i → +-comm m k i ∸ +-comm n k i) ∙ ∸-cancelˡ k m n ∸-distribʳ : ∀ m n k → (m ∸ n) · k ≡ m · k ∸ n · k ∸-distribʳ m zero k = refl ∸-distribʳ zero (suc n) k = sym (zero∸ (k + n · k)) ∸-distribʳ (suc m) (suc n) k = ∸-distribʳ m n k ∙ sym (∸-cancelˡ k (m · k) (n · k))
{ "alphanum_fraction": 0.5207612457, "avg_line_length": 27.3609467456, "ext": "agda", "hexsha": "240871506b31493dc001d1cdca65527f46420e52", "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": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "L-TChen/cubical", "max_forks_repo_path": "Cubical/Data/Nat/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "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": "L-TChen/cubical", "max_issues_repo_path": "Cubical/Data/Nat/Properties.agda", "max_line_length": 92, "max_stars_count": null, "max_stars_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "L-TChen/cubical", "max_stars_repo_path": "Cubical/Data/Nat/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2293, "size": 4624 }
-- TODO: Move some of the proofs from Function.Iteration.Proofs to here so that (_^_) on functions, natural numbers and integers can be generalised. -- TODO: Maybe something like this record Iteration(f)(id)(repeat : I → Y) where field 𝟎 : I repeat-𝟎 : repeat 𝟎 ≡ id record Successor(𝐒 : I → I) where field proof : repeat(𝐒(i)) ≡ f(repeat(i)) record Predecessor(𝐏 : I → I) where field proof : f(repeat(𝐏(i))) ≡ repeat(i)
{ "alphanum_fraction": 0.66367713, "avg_line_length": 31.8571428571, "ext": "agda", "hexsha": "0a6e2463856b0613bd51295118393018b6e32be2", "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": "Structure/Operator/Iteration.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": "Structure/Operator/Iteration.agda", "max_line_length": 148, "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": "Structure/Operator/Iteration.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": 150, "size": 446 }
module #7 where {- Exercise 1.7. Give an alternative derivation of ind′=A from ind=A which avoids the use of universes. (This is easiest using concepts from later chapters.) -} open import Relation.Binary.PropositionalEquality ind'₌A : ∀{a}{A : Set a} → (C : (x y : A) → (x ≡ y) → Set) → ((x : A) → C x x refl) → (x y : A) → (p : x ≡ y) → C x y p ind'₌A = {!!}
{ "alphanum_fraction": 0.6054794521, "avg_line_length": 30.4166666667, "ext": "agda", "hexsha": "83329f6ae2679ac8773e5867d5c8872f6cc1f946", "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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CodaFi/HoTT-Exercises", "max_forks_repo_path": "Chapter1/#7.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "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": "CodaFi/HoTT-Exercises", "max_issues_repo_path": "Chapter1/#7.agda", "max_line_length": 119, "max_stars_count": null, "max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CodaFi/HoTT-Exercises", "max_stars_repo_path": "Chapter1/#7.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 131, "size": 365 }
module SemiLattice where open import Prelude open import PartialOrder as PO import Chain private module IsSemiLat {A : Set}(po : PartialOrder A)(_⊓_ : A -> A -> A) where private open module PO = PartialOrder po record IsSemiLattice : Set where field ⊓-lbL : forall {x y} -> (x ⊓ y) ≤ x ⊓-lbR : forall {x y} -> (x ⊓ y) ≤ y ⊓-glb : forall {x y z} -> z ≤ x -> z ≤ y -> z ≤ (x ⊓ y) open IsSemiLat public record SemiLattice (A : Set) : Set1 where field po : PartialOrder A _⊓_ : A -> A -> A prf : IsSemiLattice po _⊓_ module SemiLat {A : Set}(L : SemiLattice A) where private module SL = SemiLattice L private module SLPO = POrder SL.po private module IsSL = IsSemiLattice SL.po SL._⊓_ SL.prf open SLPO public open SL public hiding (prf) open IsSL public private open module C≤ = Chain _≤_ (\x -> ≤-refl) (\x y z -> ≤-trans) renaming (_===_ to _-≤-_; chain>_ to trans>_) ⊓-commute : forall {x y} -> (x ⊓ y) == (y ⊓ x) ⊓-commute = ≤-antisym lem lem where lem : forall {x y} -> (x ⊓ y) ≤ (y ⊓ x) lem = ⊓-glb ⊓-lbR ⊓-lbL ⊓-assoc : forall {x y z} -> (x ⊓ (y ⊓ z)) == ((x ⊓ y) ⊓ z) ⊓-assoc = ≤-antisym lem₁ lem₂ where lem₁ : forall {x y z} -> (x ⊓ (y ⊓ z)) ≤ ((x ⊓ y) ⊓ z) lem₁ = ⊓-glb (⊓-glb ⊓-lbL (≤-trans ⊓-lbR ⊓-lbL)) (≤-trans ⊓-lbR ⊓-lbR) lem₂ : forall {x y z} -> ((x ⊓ y) ⊓ z) ≤ (x ⊓ (y ⊓ z)) lem₂ = ⊓-glb (≤-trans ⊓-lbL ⊓-lbL) (⊓-glb (≤-trans ⊓-lbL ⊓-lbR) ⊓-lbR) ⊓-idem : forall {x} -> (x ⊓ x) == x ⊓-idem = ≤-antisym ⊓-lbL (⊓-glb ≤-refl ≤-refl) ≤⊓-L : forall {x y} -> (x ≤ y) ⇐⇒ ((x ⊓ y) == x) ≤⊓-L = (fwd , bwd) where fwd = \x≤y -> ≤-antisym ⊓-lbL (⊓-glb ≤-refl x≤y) bwd = \x⊓y=x -> ≤-trans (==≤-R x⊓y=x) ⊓-lbR ≤⊓-R : forall {x y} -> (y ≤ x) ⇐⇒ ((x ⊓ y) == y) ≤⊓-R {x}{y} = (fwd , bwd) where lem : (y ≤ x) ⇐⇒ ((y ⊓ x) == y) lem = ≤⊓-L fwd = \y≤x -> ==-trans ⊓-commute (fst lem y≤x) bwd = \x⊓y=y -> snd lem (==-trans ⊓-commute x⊓y=y) ⊓-monotone-R : forall {a} -> Monotone (\x -> a ⊓ x) ⊓-monotone-R x≤y = ⊓-glb ⊓-lbL (≤-trans ⊓-lbR x≤y) ⊓-monotone-L : forall {a} -> Monotone (\x -> x ⊓ a) ⊓-monotone-L {a}{x}{y} x≤y = trans> x ⊓ a -≤- a ⊓ x by ==≤-L ⊓-commute -≤- a ⊓ y by ⊓-monotone-R x≤y -≤- y ⊓ a by ==≤-L ⊓-commute ≤⊓-compat : forall {w x y z} -> w ≤ y -> x ≤ z -> (w ⊓ x) ≤ (y ⊓ z) ≤⊓-compat {w}{x}{y}{z} w≤y x≤z = trans> w ⊓ x -≤- w ⊓ z by ⊓-monotone-R x≤z -≤- y ⊓ z by ⊓-monotone-L w≤y ⊓-cong : forall {w x y z} -> w == y -> x == z -> (w ⊓ x) == (y ⊓ z) ⊓-cong wy xz = ≤-antisym (≤⊓-compat (==≤-L wy) (==≤-L xz)) (≤⊓-compat (==≤-R wy) (==≤-R xz)) ⊓-cong-L : forall {x y z} -> x == y -> (x ⊓ z) == (y ⊓ z) ⊓-cong-L xy = ⊓-cong xy ==-refl ⊓-cong-R : forall {x y z} -> x == y -> (z ⊓ x) == (z ⊓ y) ⊓-cong-R xy = ⊓-cong ==-refl xy
{ "alphanum_fraction": 0.452540107, "avg_line_length": 29.92, "ext": "agda", "hexsha": "1b05377a3f6d6dbe285aa9616964f13937efaea6", "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": "examples/outdated-and-incorrect/lattice/SemiLattice.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/lattice/SemiLattice.agda", "max_line_length": 71, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/outdated-and-incorrect/lattice/SemiLattice.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": 1475, "size": 2992 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.Kernel where open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRing.Base open import Cubical.Algebra.CommRing.Ideal using (IdealsIn; Ideal→CommIdeal) open import Cubical.Algebra.Ring.Kernel using () renaming (kernelIdeal to ringKernelIdeal) private variable ℓ : Level -- If R and S were implicit, their ·Comm component could (almost?) never be inferred. kernelIdeal : (R S : CommRing ℓ) (f : CommRingHom R S) → IdealsIn R kernelIdeal _ _ f = Ideal→CommIdeal (ringKernelIdeal f)
{ "alphanum_fraction": 0.7650176678, "avg_line_length": 31.4444444444, "ext": "agda", "hexsha": "c77ff6015c789e77c6ad09c27875a33f313d3e64", "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/Kernel.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/Kernel.agda", "max_line_length": 90, "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/CommRing/Kernel.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": 152, "size": 566 }
{-# OPTIONS --rewriting #-} module DualContractive where open import Data.Fin open import Data.Maybe open import Data.Nat hiding (_≤_ ; compare) renaming (_+_ to _+ℕ_) open import Data.Nat.Properties open import Data.Sum hiding (map) open import Data.Product open import Relation.Nullary open import Relation.Binary.PropositionalEquality hiding (Extensionality) open import Function open import Direction open import Extensionality open import Max hiding (n) ---------------------------------------------------------------------- -- see also https://github.com/zmthy/recursive-types/tree/ftfjp16 -- for encoding of recursive types variable m n : ℕ i i' j : Fin n ---------------------------------------------------------------------- -- lemmas for rewriting n+1=suc-n : n +ℕ 1 ≡ suc n n+1=suc-n {zero} = refl n+1=suc-n {suc n} = cong suc (n+1=suc-n {n}) n+0=n : n +ℕ 0 ≡ n n+0=n {zero} = refl n+0=n {suc n} = cong suc (n+0=n {n}) n+sucm=sucn+m : ∀ n m → n +ℕ suc m ≡ suc (n +ℕ m) n+sucm=sucn+m 0F m = refl n+sucm=sucn+m (suc n) m = cong suc (n+sucm=sucn+m n m) {-# REWRITE n+sucm=sucn+m #-} open import Agda.Builtin.Equality.Rewrite ---------------------------------------------------------------------- -- auxiliaries for automatic rewriting {- REWRITE n+1=suc-n #-} {-# REWRITE n+0=n #-} -- inject+0-x=x : {x : Fin m} → inject+ 0 x ≡ x -- inject+0-x=x {x = zero} = refl -- inject+0-x=x {x = suc x} = cong suc inject+0-x=x {- REWRITE inject+0-x=x #-} ---------------------------------------------------------------------- -- types and session types data TType (n : ℕ) : Set data SType (n : ℕ) : Set data TType n where TInt : TType n TChn : (S : SType n) → TType n data SType n where xmt : (d : Dir) (T : TType n) (S : SType n) → SType n end : SType n rec : (S : SType (suc n)) → SType n var : (x : Fin n) → SType n variable t T : TType n s s₀ S S₀ : SType n ---------------------------------------------------------------------- module Examples-Types where sint : SType n → SType n sint = xmt SND TInt -- μ X. !Int. X s1 : SType 0 s1 = rec (sint (var 0F)) -- μ X. μ Y. !Int. Y s2 : SType 0 s2 = rec (rec (sint (var 0F))) -- μ X. μ Y. !Int. X s2a : SType 0 s2a = rec (rec (sint (var 1F))) -- μ X. !Int. μ Y. X s3 : SType 0 s3 = rec (sint (rec (var 1F))) ---------------------------------------------------------------------- -- weakening increase : ∀ m → (x : Fin n) → Fin (n +ℕ m) increase 0F x = x increase (suc m) x = suc (increase m x) increaseS : ∀ m → SType n → SType (n +ℕ m) increaseT : ∀ m → TType n → TType (n +ℕ m) increaseS m (xmt d t s) = xmt d (increaseT m t) (increaseS m s) increaseS m (rec s) = rec (increaseS m s) increaseS m (var x) = var (inject+ m x) increaseS m end = end increaseT m TInt = TInt increaseT m (TChn s) = TChn (increaseS m s) weakenS : ∀ m → SType n → SType (n +ℕ m) weakenT : ∀ m → TType n → TType (n +ℕ m) weakenS m (xmt d t s) = xmt d (weakenT m t) (weakenS m s) weakenS m (rec s) = rec (weakenS m s) weakenS m (var x) = var (increase m x) weakenS m end = end weakenT m TInt = TInt weakenT m (TChn s) = TChn (weakenS m s) weaken1S : SType n → SType (suc n) weaken1S s = weakenS 1 s ---------------------------------------------------------------------- -- substitution ssubst : SType (suc n) → Fin (suc n) → SType 0 → SType n tsubst : TType (suc n) → Fin (suc n) → SType 0 → TType n ssubst (xmt d t s) i s0 = xmt d (tsubst t i s0) (ssubst s i s0) ssubst (rec s) i s0 = rec (ssubst s (suc i) s0) ssubst {n} (var 0F) 0F s0 = increaseS n s0 ssubst {suc n} (var 0F) (suc i) s0 = var 0F ssubst (var (suc x)) 0F s0 = var x ssubst {suc n} (var (suc x)) (suc i) s0 = increaseS 1 (ssubst (var x) i s0) ssubst end i s0 = end tsubst TInt i s₀ = TInt tsubst (TChn s) i s₀ = TChn (ssubst s i s₀) ---------------------------------------------------------------------- -- contractivity mutual data ContractiveT : TType n → Set where con-int : ContractiveT{n} TInt con-chn : Contractive 0F S → ContractiveT (TChn S) data Contractive (i : Fin (suc n)) : SType n → Set where con-xmt : ContractiveT t → Contractive 0F s → Contractive i (xmt d t s) con-end : Contractive i end con-rec : Contractive (suc i) S → Contractive i (rec S) con-var : i ≤ inject₁ j → Contractive i (var j) ---------------------------------------------------------------------- module Examples-Contractivity where open Examples-Types cn1 : ¬ Contractive {2} 1F (var 0F) cn1 (con-var ()) cp1 : Contractive {2} 0F (var 1F) cp1 = con-var z≤n cp0 : Contractive {2} 0F (var 0F) cp0 = con-var z≤n cs1 : Contractive 0F s1 cs1 = con-rec (con-xmt con-int (con-var z≤n)) cs2 : Contractive 0F s2 cs2 = con-rec (con-rec (con-xmt con-int (con-var z≤n))) cs2a : Contractive 0F s2a cs2a = con-rec (con-rec (con-xmt con-int (con-var z≤n))) sp2 : SType 0 sp2 = s3 cp2 : Contractive 0F sp2 cp2 = con-rec (con-xmt con-int (con-rec (con-var (s≤s z≤n)))) sn2 : SType 0 sn2 = (rec (xmt SND TInt (rec (var 0F)))) cn2 : ¬ Contractive 0F sn2 cn2 (con-rec (con-xmt con-int (con-rec (con-var ())))) ---------------------------------------------------------------------- -- unfolding to first non-rec constructor unfold : (s : SType n) (c : Contractive i s) (σ : SType n → SType 0) → SType 0 unfold (xmt d t s) (con-xmt ct c) σ = σ (xmt d t s) unfold end con-end σ = end unfold (rec s) (con-rec c) σ = unfold s c (σ ∘ λ sn' → ssubst sn' 0F (σ (rec s))) unfold {i = 0F} (var x) (con-var z≤n) σ = σ (var x) unfold {i = suc i} (var 0F) (con-var ()) σ unfold {i = suc i} (var (suc x)) (con-var (s≤s x₁)) σ = unfold (var x) (con-var x₁) (σ ∘ increaseS 1) unfold₀ : (S : SType 0) (c : Contractive 0F S) → SType 0 unfold₀ S c = unfold S c id ---------------------------------------------------------------------- module Examples-Unfold where open Examples-Types c1 : Contractive 0F s1 c1 = con-rec (con-xmt con-int (con-var z≤n)) s11 : SType 0 s11 = xmt SND TInt s1 u-s1=s11 : unfold s1 c1 id ≡ s11 u-s1=s11 = refl c2 : Contractive 0F s2 c2 = con-rec (con-rec (con-xmt con-int (con-var z≤n))) u-s2=s11 : unfold s2 c2 id ≡ s11 u-s2=s11 = cong (xmt SND TInt) (cong rec (cong (xmt SND TInt) refl)) ---------------------------------------------------------------------- -- contractivity is decidable infer-contractiveT : (t : TType n) → Dec (ContractiveT t) infer-contractive : (s : SType n) (i : Fin (suc n)) → Dec (Contractive i s) infer-contractiveT TInt = yes con-int infer-contractiveT (TChn s) with infer-contractive s 0F infer-contractiveT (TChn s) | yes p = yes (con-chn p) infer-contractiveT (TChn s) | no ¬p = no (λ { (con-chn cs) → ¬p cs }) infer-contractive (xmt d t s) i with infer-contractiveT t | infer-contractive s 0F infer-contractive (xmt d t s) i | yes p | yes p₁ = yes (con-xmt p p₁) infer-contractive (xmt d t s) i | yes p | no ¬p = no (λ { (con-xmt ct cs) → ¬p cs }) infer-contractive (xmt d t s) i | no ¬p | yes p = no (λ { (con-xmt ct cs) → ¬p ct }) infer-contractive (xmt d t s) i | no ¬p | no ¬p₁ = no (λ { (con-xmt ct cs) → ¬p₁ cs}) infer-contractive end i = yes con-end infer-contractive (rec s) i with infer-contractive s (suc i) infer-contractive (rec s) i | yes p = yes (con-rec p) infer-contractive (rec s) i | no ¬p = no (λ { (con-rec c) → ¬p c }) infer-contractive (var x) 0F = yes (con-var z≤n) infer-contractive (var 0F) (suc i) = no (λ { (con-var ()) }) infer-contractive (var (suc x)) (suc i) with infer-contractive (var x) i infer-contractive (var (suc x)) (suc i) | yes (con-var x₁) = yes (con-var (s≤s x₁)) infer-contractive (var (suc x)) (suc i) | no ¬p = no (λ { (con-var (s≤s y)) → ¬p (con-var y) }) ---------------------------------------------------------------------- module Examples-Inference where open Examples-Contractivity infer-p2 : infer-contractive sp2 0F ≡ yes cp2 infer-p2 = refl infer-n2 : infer-contractive sn2 0F ≡ no cn2 infer-n2 = cong no (ext (λ { (con-rec (con-xmt con-int (con-rec (con-var ())))) })) ---------------------------------------------------------------------- -- RT: if a type is contractive at level i, then it is also contractive at any smaller level c-weakenS : {S : SType n} (i' : Fin′ i) → Contractive i S → Contractive (inject i') S c-weakenS i' (con-rec cis) = con-rec (c-weakenS (suc i') cis) c-weakenS i' (con-xmt x cis) = con-xmt x cis c-weakenS i' con-end = con-end c-weakenS {i = suc i} i' (con-var {0F} ()) c-weakenS {i = suc i} 0F (con-var {suc n} (s≤s x)) = con-var z≤n c-weakenS {i = suc i} (suc i') (con-var {suc n} (s≤s x)) = con-var (s≤s (trans-< x)) c-weakenS₁ : {S : SType n} → Contractive (suc i) S → Contractive (inject₁ i) S c-weakenS₁ (con-rec cis) = con-rec (c-weakenS₁ cis) c-weakenS₁ (con-xmt x cis) = con-xmt x cis c-weakenS₁ con-end = con-end c-weakenS₁ {0F} {()} (con-var x) c-weakenS₁ {suc n} {0F} (con-var x) = con-var z≤n c-weakenS₁ {suc n} {suc i} (con-var x) = con-var (pred-≤ x) c-weakenS! : {S : SType n} → Contractive i S → Contractive 0F S c-weakenS! {i = 0F} (con-rec cis) = con-rec cis c-weakenS! {i = suc i} (con-rec cis) = con-rec (c-weakenS 1F cis) c-weakenS! {n} {i} (con-xmt x cis) = con-xmt x cis c-weakenS! {n} {i} con-end = con-end c-weakenS! {n} {i} (con-var x) = con-var z≤n ---------------------------------------------------------------------- -- single substitution of j ↦ Sj subst1T : (T : TType (suc n)) (j : Fin (suc n)) (Sj : SType n) → TType n subst1S : (S : SType (suc n)) (j : Fin (suc n)) (Sj : SType n) → SType n subst1T TInt j Sj = TInt subst1T (TChn S) j Sj = TChn (subst1S S j Sj) subst1S (xmt d T S) j Sj = xmt d (subst1T T j Sj) (subst1S S j Sj) subst1S end j Sj = end subst1S (rec S) j Sj = rec (subst1S S (suc j) (weaken1S Sj)) subst1S (var x) j Sj with compare x j subst1S (var .(inject least)) j Sj | less .j least = var (inject! least) subst1S (var x) .x Sj | equal .x = Sj subst1S (var (suc x)) .(inject least) Sj | greater .(suc x) least = var x {- the termination checker doesnt like this: subst1S (var 0F) 0F Sj = Sj subst1S {suc n} (var 0F) (suc j) Sj = var 0F subst1S (var (suc x)) 0F Sj = var x subst1S (var (suc x)) (suc j) Sj = subst1S (var (inject₁ x)) (inject₁ j) Sj -} unfold1S : (S : SType 0) → SType 0 unfold1S (xmt d T S) = xmt d T S unfold1S end = end unfold1S (rec S) = subst1S S 0F (rec S) unfoldSS : (S : SType n) → SType n unfoldSS (xmt d T S) = xmt d T S unfoldSS end = end unfoldSS (rec S) with unfoldSS S ... | ih = subst1S ih 0F (rec ih) unfoldSS (var x) = var x ---------------------------------------------------------------------- -- max index substitution subst-maxT : (Sm : SType n) (T : TType (suc n)) → TType n subst-maxS : (Sm : SType n) (S : SType (suc n)) → SType n subst-maxT Sm TInt = TInt subst-maxT Sm (TChn S) = TChn (subst-maxS Sm S) subst-maxS Sm (xmt d T S) = xmt d (subst-maxT Sm T) (subst-maxS Sm S) subst-maxS Sm end = end subst-maxS Sm (rec S) = rec (subst-maxS (weaken1S Sm) S) subst-maxS Sm (var x) with max? x subst-maxS Sm (var x) | yes p = Sm subst-maxS Sm (var x) | no ¬p = var (reduce ¬p) unfoldmS : (S : SType 0) → SType 0 unfoldmS (xmt d T S) = xmt d T S unfoldmS end = end unfoldmS (rec S) = subst-maxS (rec S) S ---------------------------------------------------------------------- -- max substitution preserves contractivity contr-weakenT : ContractiveT T → ContractiveT (weakenT 1 T) contr-weakenS : Contractive i S → Contractive (suc i) (weaken1S S) contr-weakenT con-int = con-int contr-weakenT (con-chn x) = con-chn (c-weakenS! (contr-weakenS x)) contr-weakenS (con-xmt x cs) = con-xmt (contr-weakenT x) (c-weakenS! (contr-weakenS cs)) contr-weakenS con-end = con-end contr-weakenS (con-rec cs) = con-rec (contr-weakenS cs) contr-weakenS {n}{i} {S = var j} (con-var x) = con-var (s≤s x) subst-contr-mT : {T : TType (suc n)} (c : ContractiveT T) {S' : SType n} (c' : Contractive i S') → ContractiveT (subst-maxT S' T) subst-contr-mS : -- {i : Fin (suc (suc n))} {S : SType (suc n)} (c : Contractive (inject₁ i) S) {S' : SType n} (c' : Contractive i S') → Contractive i (subst-maxS S' S) subst-contr-mT con-int csm = con-int subst-contr-mT (con-chn x) csm = con-chn (c-weakenS! (subst-contr-mS x (c-weakenS! csm))) subst-contr-mS (con-xmt x cs) csm = con-xmt (subst-contr-mT x csm) (subst-contr-mS cs (c-weakenS! csm)) subst-contr-mS con-end csm = con-end subst-contr-mS (con-rec cs) csm = con-rec (subst-contr-mS cs (contr-weakenS csm)) subst-contr-mS {S = var j} (con-var x) csm with max? j subst-contr-mS {i = _} {var j} (con-var x) csm | yes p = csm subst-contr-mS {i = _} {var j} (con-var x) csm | no ¬p = con-var (lemma-reduce x ¬p) -- one step unfolding preserves contractivity unfold-contr : Contractive i S → Contractive i (unfoldmS S) unfold-contr (con-xmt x c) = con-xmt x c unfold-contr con-end = con-end unfold-contr (con-rec c) = subst-contr-mS (c-weakenS₁ c) (con-rec c) -- multiple unfolding unfold! : (S : SType n) (σ : SType n → SType 0) → SType 0 unfold! (xmt d T S) σ = σ (xmt d T S) unfold! end σ = end unfold! (rec S) σ = unfold! S (σ ∘ subst-maxS (rec S)) unfold! (var x) σ = σ (var x) unfold!-contr : Contractive i S → Contractive i (unfold! S id) unfold!-contr (con-xmt x cs) = con-xmt x cs unfold!-contr con-end = con-end unfold!-contr (con-rec cs) = {!!} -- multiple unfolding preserves contractivity SCType : (n : ℕ) → Fin (suc n) → Set SCType n i = Σ (SType n) (Contractive i) unfold!! : (SC : SCType n i) → (SCType n i → SCType 0 0F) → SCType 0 0F unfold!! SC@(xmt d T S , con-xmt x cs) σ = σ SC unfold!! (end , con-end) σ = end , con-end unfold!! (rec S , con-rec cs) σ = unfold!! (S , cs) (σ ∘ λ{ (S' , c') → (subst-maxS (rec S) S') , (subst-contr-mS (c-weakenS₁ c') (con-rec cs)) }) unfold!! SC@(var x , con-var x₁) σ = σ SC ---------------------------------------------------------------------- -- equivalence requires multiple unfolding variable t₁ t₂ t₁' t₂' : TType n s₁ s₂ : SType n -- type equivalence data EquivT (R : SType n → SType n → Set) : TType n → TType n → Set where eq-int : EquivT R TInt TInt eq-chan : R s₁ s₂ → EquivT R (TChn s₁) (TChn s₂) -- session type equivalence data EquivS (R : SType n → SType n → Set) : SType n → SType n → Set where eq-xmt : (d : Dir) → EquivT R t₁ t₂ → R s₁ s₂ → EquivS R (xmt d t₁ s₁) (xmt d t₂ s₂) eq-end : EquivS R end end -- record Equiv (s₁ s₂ : SType 0) : Set where -- coinductive -- field force : EquivS Equiv (unfold s₁) (unfold s₂) -- open Equiv
{ "alphanum_fraction": 0.5713990636, "avg_line_length": 32.4196428571, "ext": "agda", "hexsha": "ddb7f819f65ac69660b9d551e9bb016924239120", "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": "cd41919582013e75463308c32750e2712cf2de86", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "kcaliban/dual-session", "max_forks_repo_path": "src/DualContractive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "kcaliban/dual-session", "max_issues_repo_path": "src/DualContractive.agda", "max_line_length": 114, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "kcaliban/dual-session", "max_stars_repo_path": "src/DualContractive.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5402, "size": 14524 }